From 673ade958caee1710c863f815fc10a3747378448 Mon Sep 17 00:00:00 2001 From: kyz Date: Wed, 17 Jun 2026 10:07:52 +0800 Subject: [PATCH 1/1] =?utf8?q?=E5=88=9D=E5=A7=8B=E7=89=88=E6=9C=AC?= =?utf8?q?=EF=BC=8C=E4=BB=8E=20=E5=8D=9A=E4=BF=A1=E8=80=81=E5=8C=96?= =?utf8?q?=E9=A1=B9=E7=9B=AE=E4=B8=BB=E6=8E=A7&=E9=87=87=E9=9B=86=E4=BB=A3?= =?utf8?q?=E7=A0=81.zip=20=E6=96=87=E4=BB=B6=E4=B8=AD=E6=8F=90=E5=8F=96?= =?utf8?q?=E7=9A=84=E4=B8=BB=E6=8E=A7=E6=9D=BF=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 1. 拿到的代码中屏蔽了大部分task创建,大概是为了调试临时关闭,这里手动给他打开了 2. 原始代码中带有git仓库,其wifi代码和commit的版本比较,修改了wifi初始化状态机的step到8,不确定是调试功能还是正式功能,先保留了。 --- .gitignore | 9 + Aging_app/freertos/IARProject/freertos.eww | 7 + Aging_app/freertos/inc/FreeRTOSConfig.h | 170 + Aging_app/freertos/inc/adc_collect.h | 11 + Aging_app/freertos/inc/dma_transfer.h | 17 + Aging_app/freertos/inc/main_common.h | 43 + Aging_app/freertos/inc/system_init.h | 13 + Aging_app/freertos/inc/task_lists.h | 9 + Aging_app/freertos/inc/uart_transfer.h | 12 + Aging_app/freertos/inc/wifi_transfer.h | 12 + Aging_app/freertos/readme.txt | 37 + Aging_app/freertos/src/adc_collect.c | 110 + Aging_app/freertos/src/dma_transfer.c | 178 + Aging_app/freertos/src/main.c | 160 + Aging_app/freertos/src/system_init.c | 154 + Aging_app/freertos/src/task_lists.c | 771 +++ Aging_app/freertos/src/uart_transfer.c | 228 + Aging_app/freertos/src/wifi_transfer.c | 192 + Platform/Core/arm_compat.h | 190 + Platform/Core/cmsis_armcc.h | 870 +++ Platform/Core/cmsis_armclang.h | 1877 ++++++ Platform/Core/cmsis_compiler.h | 266 + Platform/Core/cmsis_gcc.h | 2088 +++++++ Platform/Core/cmsis_iccarm.h | 913 +++ Platform/Core/cmsis_version.h | 39 + Platform/Core/core_cm0plus.h | 1025 ++++ Platform/Core/mpu_armv7.h | 197 + Platform/Devices/Z20K114M/Inc/Z20K114M.h | 4613 ++++++++++++++ .../Z20K114M/MakeRule/ARMC/Z20K114M_flash.scf | 27 + .../Z20K114M/MakeRule/ARMC/Z20K114M_sram.scf | 20 + .../Z20K114M/MakeRule/GCC/Z20K114M_flash.ld | 99 + .../Z20K114M/MakeRule/GCC/Z20K114M_sram.ld | 100 + .../Z20K114M/MakeRule/IAR/Z20K114M_flash.icf | 43 + .../Z20K114M/MakeRule/IAR/Z20K114M_sram.icf | 39 + .../Z20K114M/Startup/ARMC/Z20K114M_startup.s | 428 ++ .../Z20K114M/Startup/GCC/Z20K114M_startup.S | 518 ++ .../Z20K114M/Startup/IAR/Z20K114M_startup.s | 409 ++ Platform/Devices/Z20K116M/Inc/Z20K116M.h | 4613 ++++++++++++++ .../Z20K116M/MakeRule/ARMC/Z20K116M_flash.scf | 30 + .../Z20K116M/MakeRule/ARMC/Z20K116M_sram.scf | 20 + .../Z20K116M/MakeRule/GCC/Z20K116M_flash.ld | 100 + .../Z20K116M/MakeRule/GCC/Z20K116M_sram.ld | 100 + .../Z20K116M/MakeRule/IAR/Z20K116M_flash.icf | 47 + .../Z20K116M/MakeRule/IAR/Z20K116M_sram.icf | 39 + .../Z20K116M/Startup/ARMC/Z20K116M_startup.s | 428 ++ .../Z20K116M/Startup/GCC/Z20K116M_startup.S | 518 ++ .../Z20K116M/Startup/IAR/Z20K116M_startup.s | 409 ++ Platform/Devices/Z20K118M/Inc/Z20K118M.h | 4616 ++++++++++++++ .../Z20K118M/MakeRule/ARMC/Z20K118M_flash.scf | 39 + .../Z20K118M/MakeRule/ARMC/Z20K118M_sram.scf | 28 + .../Z20K118M/MakeRule/GCC/Z20K118M_flash.ld | 101 + .../Z20K118M/MakeRule/GCC/Z20K118M_sram.ld | 102 + .../Z20K118M/MakeRule/IAR/Z20K118M_flash.icf | 52 + .../Z20K118M/MakeRule/IAR/Z20K118M_sram.icf | 42 + .../Z20K118M/Startup/ARMC/Z20K118M_startup.s | 456 ++ .../Z20K118M/Startup/GCC/Z20K118M_startup.S | 554 ++ .../Z20K118M/Startup/IAR/Z20K118M_startup.s | 433 ++ Platform/Devices/device_regs.h | 26 + Platform/Z20K11xM_cfg.h | 44 + Platform/Z20K11xM_corecfg.h | 40 + RTOS/FreeRTOS/License/license.txt | 37 + RTOS/FreeRTOS/Source/croutine.c | 361 ++ RTOS/FreeRTOS/Source/event_groups.c | 771 +++ RTOS/FreeRTOS/Source/include/FreeRTOS.h | 1325 ++++ RTOS/FreeRTOS/Source/include/StackMacros.h | 32 + RTOS/FreeRTOS/Source/include/atomic.h | 417 ++ RTOS/FreeRTOS/Source/include/croutine.h | 751 +++ .../Source/include/deprecated_definitions.h | 279 + RTOS/FreeRTOS/Source/include/event_groups.h | 775 +++ RTOS/FreeRTOS/Source/include/list.h | 417 ++ RTOS/FreeRTOS/Source/include/message_buffer.h | 821 +++ RTOS/FreeRTOS/Source/include/mpu_prototypes.h | 263 + RTOS/FreeRTOS/Source/include/mpu_wrappers.h | 187 + RTOS/FreeRTOS/Source/include/portable.h | 216 + RTOS/FreeRTOS/Source/include/projdefs.h | 120 + RTOS/FreeRTOS/Source/include/queue.h | 1716 ++++++ RTOS/FreeRTOS/Source/include/semphr.h | 1173 ++++ RTOS/FreeRTOS/Source/include/stack_macros.h | 127 + RTOS/FreeRTOS/Source/include/stdint.readme | 27 + RTOS/FreeRTOS/Source/include/stream_buffer.h | 867 +++ RTOS/FreeRTOS/Source/include/task.h | 3037 ++++++++++ RTOS/FreeRTOS/Source/include/timers.h | 1351 +++++ RTOS/FreeRTOS/Source/lexicon.txt | 3082 ++++++++++ RTOS/FreeRTOS/Source/list.c | 210 + .../Source/portable/IAR/ARM_CM0/port.c | 431 ++ .../Source/portable/IAR/ARM_CM0/portasm.s | 131 + .../Source/portable/IAR/ARM_CM0/portmacro.h | 128 + .../Source/portable/MemMang/ReadMe.url | 5 + .../FreeRTOS/Source/portable/MemMang/heap_1.c | 144 + .../FreeRTOS/Source/portable/MemMang/heap_2.c | 274 + .../FreeRTOS/Source/portable/MemMang/heap_3.c | 94 + .../FreeRTOS/Source/portable/MemMang/heap_4.c | 494 ++ .../FreeRTOS/Source/portable/MemMang/heap_5.c | 550 ++ RTOS/FreeRTOS/Source/portable/readme.txt | 20 + RTOS/FreeRTOS/Source/queue.c | 3013 +++++++++ RTOS/FreeRTOS/Source/stream_buffer.c | 1326 ++++ RTOS/FreeRTOS/Source/tasks.c | 5379 +++++++++++++++++ RTOS/FreeRTOS/Source/timers.c | 1144 ++++ RTOS/FreeRTOS/z20k1xx.mk | 29 + StdDriver/Inc/Z20K11xM_adc.h | 645 ++ StdDriver/Inc/Z20K11xM_can.h | 1477 +++++ StdDriver/Inc/Z20K11xM_clock.h | 533 ++ StdDriver/Inc/Z20K11xM_cmp.h | 362 ++ StdDriver/Inc/Z20K11xM_crc.h | 158 + StdDriver/Inc/Z20K11xM_dma.h | 806 +++ StdDriver/Inc/Z20K11xM_drv.h | 169 + StdDriver/Inc/Z20K11xM_ewdt.h | 235 + StdDriver/Inc/Z20K11xM_flash.h | 533 ++ StdDriver/Inc/Z20K11xM_gpio.h | 1295 ++++ StdDriver/Inc/Z20K11xM_hwdiv.h | 357 ++ StdDriver/Inc/Z20K11xM_i2c.h | 971 +++ StdDriver/Inc/Z20K11xM_pmu.h | 130 + StdDriver/Inc/Z20K11xM_regfile.h | 80 + StdDriver/Inc/Z20K11xM_rtc.h | 420 ++ StdDriver/Inc/Z20K11xM_spi.h | 400 ++ StdDriver/Inc/Z20K11xM_srmc.h | 351 ++ StdDriver/Inc/Z20K11xM_stim.h | 291 + StdDriver/Inc/Z20K11xM_sysctrl.h | 369 ++ StdDriver/Inc/Z20K11xM_tdg.h | 509 ++ StdDriver/Inc/Z20K11xM_tim.h | 1097 ++++ StdDriver/Inc/Z20K11xM_tmu.h | 197 + StdDriver/Inc/Z20K11xM_uart.h | 702 +++ StdDriver/Inc/Z20K11xM_wdog.h | 426 ++ StdDriver/Src/Z20K11xM_adc.c | 684 +++ StdDriver/Src/Z20K11xM_can.c | 4591 ++++++++++++++ StdDriver/Src/Z20K11xM_clock.c | 1375 +++++ StdDriver/Src/Z20K11xM_cmp.c | 404 ++ StdDriver/Src/Z20K11xM_crc.c | 228 + StdDriver/Src/Z20K11xM_dma.c | 1221 ++++ StdDriver/Src/Z20K11xM_drv.c | 117 + StdDriver/Src/Z20K11xM_ewdt.c | 377 ++ StdDriver/Src/Z20K11xM_flash.c | 1216 ++++ StdDriver/Src/Z20K11xM_gpio.c | 1169 ++++ StdDriver/Src/Z20K11xM_hwdiv.c | 475 ++ StdDriver/Src/Z20K11xM_i2c.c | 1352 +++++ StdDriver/Src/Z20K11xM_pmu.c | 277 + StdDriver/Src/Z20K11xM_regfile.c | 135 + StdDriver/Src/Z20K11xM_rtc.c | 752 +++ StdDriver/Src/Z20K11xM_spi.c | 624 ++ StdDriver/Src/Z20K11xM_srmc.c | 567 ++ StdDriver/Src/Z20K11xM_stim.c | 302 + StdDriver/Src/Z20K11xM_sysctrl.c | 668 ++ StdDriver/Src/Z20K11xM_tdg.c | 892 +++ StdDriver/Src/Z20K11xM_tim.c | 2137 +++++++ StdDriver/Src/Z20K11xM_tmu.c | 149 + StdDriver/Src/Z20K11xM_uart.c | 1547 +++++ StdDriver/Src/Z20K11xM_wdog.c | 772 +++ 147 files changed, 94799 insertions(+) create mode 100644 .gitignore create mode 100644 Aging_app/freertos/IARProject/freertos.eww create mode 100644 Aging_app/freertos/inc/FreeRTOSConfig.h create mode 100644 Aging_app/freertos/inc/adc_collect.h create mode 100644 Aging_app/freertos/inc/dma_transfer.h create mode 100644 Aging_app/freertos/inc/main_common.h create mode 100644 Aging_app/freertos/inc/system_init.h create mode 100644 Aging_app/freertos/inc/task_lists.h create mode 100644 Aging_app/freertos/inc/uart_transfer.h create mode 100644 Aging_app/freertos/inc/wifi_transfer.h create mode 100644 Aging_app/freertos/readme.txt create mode 100644 Aging_app/freertos/src/adc_collect.c create mode 100644 Aging_app/freertos/src/dma_transfer.c create mode 100644 Aging_app/freertos/src/main.c create mode 100644 Aging_app/freertos/src/system_init.c create mode 100644 Aging_app/freertos/src/task_lists.c create mode 100644 Aging_app/freertos/src/uart_transfer.c create mode 100644 Aging_app/freertos/src/wifi_transfer.c create mode 100644 Platform/Core/arm_compat.h create mode 100644 Platform/Core/cmsis_armcc.h create mode 100644 Platform/Core/cmsis_armclang.h create mode 100644 Platform/Core/cmsis_compiler.h create mode 100644 Platform/Core/cmsis_gcc.h create mode 100644 Platform/Core/cmsis_iccarm.h create mode 100644 Platform/Core/cmsis_version.h create mode 100644 Platform/Core/core_cm0plus.h create mode 100644 Platform/Core/mpu_armv7.h create mode 100644 Platform/Devices/Z20K114M/Inc/Z20K114M.h create mode 100644 Platform/Devices/Z20K114M/MakeRule/ARMC/Z20K114M_flash.scf create mode 100644 Platform/Devices/Z20K114M/MakeRule/ARMC/Z20K114M_sram.scf create mode 100644 Platform/Devices/Z20K114M/MakeRule/GCC/Z20K114M_flash.ld create mode 100644 Platform/Devices/Z20K114M/MakeRule/GCC/Z20K114M_sram.ld create mode 100644 Platform/Devices/Z20K114M/MakeRule/IAR/Z20K114M_flash.icf create mode 100644 Platform/Devices/Z20K114M/MakeRule/IAR/Z20K114M_sram.icf create mode 100644 Platform/Devices/Z20K114M/Startup/ARMC/Z20K114M_startup.s create mode 100644 Platform/Devices/Z20K114M/Startup/GCC/Z20K114M_startup.S create mode 100644 Platform/Devices/Z20K114M/Startup/IAR/Z20K114M_startup.s create mode 100644 Platform/Devices/Z20K116M/Inc/Z20K116M.h create mode 100644 Platform/Devices/Z20K116M/MakeRule/ARMC/Z20K116M_flash.scf create mode 100644 Platform/Devices/Z20K116M/MakeRule/ARMC/Z20K116M_sram.scf create mode 100644 Platform/Devices/Z20K116M/MakeRule/GCC/Z20K116M_flash.ld create mode 100644 Platform/Devices/Z20K116M/MakeRule/GCC/Z20K116M_sram.ld create mode 100644 Platform/Devices/Z20K116M/MakeRule/IAR/Z20K116M_flash.icf create mode 100644 Platform/Devices/Z20K116M/MakeRule/IAR/Z20K116M_sram.icf create mode 100644 Platform/Devices/Z20K116M/Startup/ARMC/Z20K116M_startup.s create mode 100644 Platform/Devices/Z20K116M/Startup/GCC/Z20K116M_startup.S create mode 100644 Platform/Devices/Z20K116M/Startup/IAR/Z20K116M_startup.s create mode 100644 Platform/Devices/Z20K118M/Inc/Z20K118M.h create mode 100644 Platform/Devices/Z20K118M/MakeRule/ARMC/Z20K118M_flash.scf create mode 100644 Platform/Devices/Z20K118M/MakeRule/ARMC/Z20K118M_sram.scf create mode 100644 Platform/Devices/Z20K118M/MakeRule/GCC/Z20K118M_flash.ld create mode 100644 Platform/Devices/Z20K118M/MakeRule/GCC/Z20K118M_sram.ld create mode 100644 Platform/Devices/Z20K118M/MakeRule/IAR/Z20K118M_flash.icf create mode 100644 Platform/Devices/Z20K118M/MakeRule/IAR/Z20K118M_sram.icf create mode 100644 Platform/Devices/Z20K118M/Startup/ARMC/Z20K118M_startup.s create mode 100644 Platform/Devices/Z20K118M/Startup/GCC/Z20K118M_startup.S create mode 100644 Platform/Devices/Z20K118M/Startup/IAR/Z20K118M_startup.s create mode 100644 Platform/Devices/device_regs.h create mode 100644 Platform/Z20K11xM_cfg.h create mode 100644 Platform/Z20K11xM_corecfg.h create mode 100644 RTOS/FreeRTOS/License/license.txt create mode 100644 RTOS/FreeRTOS/Source/croutine.c create mode 100644 RTOS/FreeRTOS/Source/event_groups.c create mode 100644 RTOS/FreeRTOS/Source/include/FreeRTOS.h create mode 100644 RTOS/FreeRTOS/Source/include/StackMacros.h create mode 100644 RTOS/FreeRTOS/Source/include/atomic.h create mode 100644 RTOS/FreeRTOS/Source/include/croutine.h create mode 100644 RTOS/FreeRTOS/Source/include/deprecated_definitions.h create mode 100644 RTOS/FreeRTOS/Source/include/event_groups.h create mode 100644 RTOS/FreeRTOS/Source/include/list.h create mode 100644 RTOS/FreeRTOS/Source/include/message_buffer.h create mode 100644 RTOS/FreeRTOS/Source/include/mpu_prototypes.h create mode 100644 RTOS/FreeRTOS/Source/include/mpu_wrappers.h create mode 100644 RTOS/FreeRTOS/Source/include/portable.h create mode 100644 RTOS/FreeRTOS/Source/include/projdefs.h create mode 100644 RTOS/FreeRTOS/Source/include/queue.h create mode 100644 RTOS/FreeRTOS/Source/include/semphr.h create mode 100644 RTOS/FreeRTOS/Source/include/stack_macros.h create mode 100644 RTOS/FreeRTOS/Source/include/stdint.readme create mode 100644 RTOS/FreeRTOS/Source/include/stream_buffer.h create mode 100644 RTOS/FreeRTOS/Source/include/task.h create mode 100644 RTOS/FreeRTOS/Source/include/timers.h create mode 100644 RTOS/FreeRTOS/Source/lexicon.txt create mode 100644 RTOS/FreeRTOS/Source/list.c create mode 100644 RTOS/FreeRTOS/Source/portable/IAR/ARM_CM0/port.c create mode 100644 RTOS/FreeRTOS/Source/portable/IAR/ARM_CM0/portasm.s create mode 100644 RTOS/FreeRTOS/Source/portable/IAR/ARM_CM0/portmacro.h create mode 100644 RTOS/FreeRTOS/Source/portable/MemMang/ReadMe.url create mode 100644 RTOS/FreeRTOS/Source/portable/MemMang/heap_1.c create mode 100644 RTOS/FreeRTOS/Source/portable/MemMang/heap_2.c create mode 100644 RTOS/FreeRTOS/Source/portable/MemMang/heap_3.c create mode 100644 RTOS/FreeRTOS/Source/portable/MemMang/heap_4.c create mode 100644 RTOS/FreeRTOS/Source/portable/MemMang/heap_5.c create mode 100644 RTOS/FreeRTOS/Source/portable/readme.txt create mode 100644 RTOS/FreeRTOS/Source/queue.c create mode 100644 RTOS/FreeRTOS/Source/stream_buffer.c create mode 100644 RTOS/FreeRTOS/Source/tasks.c create mode 100644 RTOS/FreeRTOS/Source/timers.c create mode 100644 RTOS/FreeRTOS/z20k1xx.mk create mode 100644 StdDriver/Inc/Z20K11xM_adc.h create mode 100644 StdDriver/Inc/Z20K11xM_can.h create mode 100644 StdDriver/Inc/Z20K11xM_clock.h create mode 100644 StdDriver/Inc/Z20K11xM_cmp.h create mode 100644 StdDriver/Inc/Z20K11xM_crc.h create mode 100644 StdDriver/Inc/Z20K11xM_dma.h create mode 100644 StdDriver/Inc/Z20K11xM_drv.h create mode 100644 StdDriver/Inc/Z20K11xM_ewdt.h create mode 100644 StdDriver/Inc/Z20K11xM_flash.h create mode 100644 StdDriver/Inc/Z20K11xM_gpio.h create mode 100644 StdDriver/Inc/Z20K11xM_hwdiv.h create mode 100644 StdDriver/Inc/Z20K11xM_i2c.h create mode 100644 StdDriver/Inc/Z20K11xM_pmu.h create mode 100644 StdDriver/Inc/Z20K11xM_regfile.h create mode 100644 StdDriver/Inc/Z20K11xM_rtc.h create mode 100644 StdDriver/Inc/Z20K11xM_spi.h create mode 100644 StdDriver/Inc/Z20K11xM_srmc.h create mode 100644 StdDriver/Inc/Z20K11xM_stim.h create mode 100644 StdDriver/Inc/Z20K11xM_sysctrl.h create mode 100644 StdDriver/Inc/Z20K11xM_tdg.h create mode 100644 StdDriver/Inc/Z20K11xM_tim.h create mode 100644 StdDriver/Inc/Z20K11xM_tmu.h create mode 100644 StdDriver/Inc/Z20K11xM_uart.h create mode 100644 StdDriver/Inc/Z20K11xM_wdog.h create mode 100644 StdDriver/Src/Z20K11xM_adc.c create mode 100644 StdDriver/Src/Z20K11xM_can.c create mode 100644 StdDriver/Src/Z20K11xM_clock.c create mode 100644 StdDriver/Src/Z20K11xM_cmp.c create mode 100644 StdDriver/Src/Z20K11xM_crc.c create mode 100644 StdDriver/Src/Z20K11xM_dma.c create mode 100644 StdDriver/Src/Z20K11xM_drv.c create mode 100644 StdDriver/Src/Z20K11xM_ewdt.c create mode 100644 StdDriver/Src/Z20K11xM_flash.c create mode 100644 StdDriver/Src/Z20K11xM_gpio.c create mode 100644 StdDriver/Src/Z20K11xM_hwdiv.c create mode 100644 StdDriver/Src/Z20K11xM_i2c.c create mode 100644 StdDriver/Src/Z20K11xM_pmu.c create mode 100644 StdDriver/Src/Z20K11xM_regfile.c create mode 100644 StdDriver/Src/Z20K11xM_rtc.c create mode 100644 StdDriver/Src/Z20K11xM_spi.c create mode 100644 StdDriver/Src/Z20K11xM_srmc.c create mode 100644 StdDriver/Src/Z20K11xM_stim.c create mode 100644 StdDriver/Src/Z20K11xM_sysctrl.c create mode 100644 StdDriver/Src/Z20K11xM_tdg.c create mode 100644 StdDriver/Src/Z20K11xM_tim.c create mode 100644 StdDriver/Src/Z20K11xM_tmu.c create mode 100644 StdDriver/Src/Z20K11xM_uart.c create mode 100644 StdDriver/Src/Z20K11xM_wdog.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..84f4b98 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +*.o +*.dep +*.swp +*.ewd +*.ewp +*.ewt +Debug/ +*.log +settings/ \ No newline at end of file diff --git a/Aging_app/freertos/IARProject/freertos.eww b/Aging_app/freertos/IARProject/freertos.eww new file mode 100644 index 0000000..5b4a8b7 --- /dev/null +++ b/Aging_app/freertos/IARProject/freertos.eww @@ -0,0 +1,7 @@ + + + + $WS_DIR$\freertos.ewp + + + diff --git a/Aging_app/freertos/inc/FreeRTOSConfig.h b/Aging_app/freertos/inc/FreeRTOSConfig.h new file mode 100644 index 0000000..2eac637 --- /dev/null +++ b/Aging_app/freertos/inc/FreeRTOSConfig.h @@ -0,0 +1,170 @@ +/**************************************************************************************************/ +/** + * @file FreeRTOSConfig.h + * @brief FreeRtos Config header file. + * @version V1.0.0 + * @date 1-May-2020 + * @author Zhixin Semiconductor + * + * @note + * Copyright (C) 2020 Zhixin Semiconductor Ltd. All rights reserved. + * + **************************************************************************************************/ + +#ifndef FREERTOS_CONFIG_H +#define FREERTOS_CONFIG_H +/** +* @page misra_violations MISRA-C:2012 violations +* + * @section [global] +* Violates MISRA 2012 Advisory Directive 4.9, Function-like macro defined. +* The macro is used for development validation. +* +* @section [global] +* Violates MISRA 2012 Required Rule 3.1, C comment contains C++ comment. +* Detections are URL links from FreeRTOS header text. +* +* @section [global] +* Violates MISRA 2012 Advisory Rule 2.5, Global macro not referenced. +* The global macro will be used in function call of the module. +*/ + +/*----------------------------------------------------------- +* Application specific definitions. +* +* These definitions should be adjusted for your particular hardware and +* application requirements. +* +* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE +* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. +* +* See http://www.freertos.org/a00110.html. +*----------------------------------------------------------*/ + + +#define configCPU_CLOCK_HZ ( 40000000UL ) +#define configTICK_RATE_HZ ((TickType_t) 1000 ) +#define configMAX_PRIORITIES 5 +#define configMINIMAL_STACK_SIZE ((unsigned short) 90 ) +#define configMAX_TASK_NAME_LEN 12 +#define configUSE_16_BIT_TICKS 0 +#define configIDLE_SHOULD_YIELD 1 +#define configUSE_PREEMPTION 1 +#define configNUM_THREAD_LOCAL_STORAGE_POINTERS 0 +#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 +#define configUSE_TASK_NOTIFICATIONS 1 +#define configUSE_TIME_SLICING 1 +#define configUSE_NEWLIB_REENTRANT 0 +#define configENABLE_BACKWARD_COMPATIBILITY 1 +#define configUSE_POSIX_ERRNO 0 + +/* Definition assert() function. */ +#define configASSERT(x) if((x)==0) { taskDISABLE_INTERRUPTS(); for( ;; ); } + +/* The highest interrupt priority that can be used by any interrupt service +routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL +INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER +PRIORITY THAN THIS! (higher priorities are lower numeric values. */ +#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY ( 1 ) + +/* Memory allocation related definitions. */ +#define configSUPPORT_STATIC_ALLOCATION 0 +#define configSUPPORT_DYNAMIC_ALLOCATION 1 +#define configTOTAL_HEAP_SIZE (( size_t ) 12288) +#define configAPPLICATION_ALLOCATED_HEAP 0 + +/* Hook function related definitions. */ +#define configUSE_IDLE_HOOK 0 +#define configUSE_TICK_HOOK 0 +#define configUSE_MALLOC_FAILED_HOOK 0 +#define configCHECK_FOR_STACK_OVERFLOW 0 +#define configUSE_DAEMON_TASK_STARTUP_HOOK 0 + +/* Run time and task stats gathering related definitions. */ +#define configGENERATE_RUN_TIME_STATS 0 +#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() +#define portGET_RUN_TIME_COUNTER_VALUE() xTaskGetTickCount() +#define configUSE_TRACE_FACILITY 0 +#define configUSE_STATS_FORMATTING_FUNCTIONS 1 + +/* Co-routine related definitions. */ +#define configUSE_CO_ROUTINES 0 +#define configMAX_CO_ROUTINE_PRIORITIES 2 + +/* SEMAPHORES and MUTEXS */ +#define configUSE_MUTEXES 1 +#define configUSE_RECURSIVE_MUTEXES 1 +#define configUSE_COUNTING_SEMAPHORES 1 + +/* Software timer related definitions. */ +#define configUSE_TIMERS 1 +#define configTIMER_TASK_PRIORITY 2 +#define configTIMER_QUEUE_LENGTH 10 +#define configTIMER_TASK_STACK_DEPTH 180 + +/* Tickless Idle Mode */ +#define configUSE_TICKLESS_IDLE 0 + +/* QUEUE */ +#define configQUEUE_REGISTRY_SIZE 8 +#define configUSE_QUEUE_SETS 0 + +/* Optional functions - most linkers will remove unused functions anyway. */ +#define INCLUDE_vTaskPrioritySet 1 +#define INCLUDE_uxTaskPriorityGet 1 +#define INCLUDE_vTaskDelete 1 +#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_vTaskDelayUntil 1 +#define INCLUDE_vTaskDelay 1 +#define INCLUDE_xTaskGetSchedulerState 1 +#define INCLUDE_xTaskGetCurrentTaskHandle 1 +#define INCLUDE_uxTaskGetStackHighWaterMark 1 +#define INCLUDE_xTaskGetIdleTaskHandle 0 +#define INCLUDE_eTaskGetState 1 +#define INCLUDE_xEventGroupSetBitFromISR 1 +#define INCLUDE_xTimerPendFunctionCall 1 +#define INCLUDE_xTaskAbortDelay 1 +#define INCLUDE_xTaskGetHandle 1 +#define INCLUDE_xTaskResumeFromISR 1 +#define INCLUDE_xQueueGetMutexHolder 1 + + +/* Run time stats gathering definitions. */ +#ifdef __GNUC__ + /* The #ifdef just prevents this C specific syntax from being included in + assembly files. */ + void vMainConfigureTimerForRunTimeStats( void ); + unsigned long ulMainGetRunTimeCounterValue( void ); +#endif + +/* Cortex-M specific definitions. */ +#ifdef __NVIC_PRIO_BITS + #define configPRIO_BITS __NVIC_PRIO_BITS +#else + #define configPRIO_BITS 4 +#endif + +/* The lowest interrupt priority that can be used in a call to a "set priority" +function. */ +#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY (0x0F) + +/* Interrupt priorities used by the kernel port layer itself. These are generic +to all Cortex-M ports, and do not rely on any particular library functions. */ +#ifndef configKERNEL_INTERRUPT_PRIORITY + #define configKERNEL_INTERRUPT_PRIORITY (configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8-configPRIO_BITS)) +#endif + +/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!! +See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */ +#ifndef configMAX_SYSCALL_INTERRUPT_PRIORITY + #define configMAX_SYSCALL_INTERRUPT_PRIORITY (configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8-configPRIO_BITS)) +#endif + +/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS +standard names. */ +#define vPortSVCHandler SVC_Handler +#define xPortPendSVHandler PendSV_Handler +#define xPortSysTickHandler SysTick_Handler + +#endif /* FREERTOS_CONFIG_H */ + diff --git a/Aging_app/freertos/inc/adc_collect.h b/Aging_app/freertos/inc/adc_collect.h new file mode 100644 index 0000000..208b10e --- /dev/null +++ b/Aging_app/freertos/inc/adc_collect.h @@ -0,0 +1,11 @@ +#ifndef __ADC_COLLECT_H__ +#define __ADC_COLLECT_H__ + + +#include "main_common.h" + + +void ADC0_Init(void); +int16_t Adc_Collect_Temp(void); + +#endif \ No newline at end of file diff --git a/Aging_app/freertos/inc/dma_transfer.h b/Aging_app/freertos/inc/dma_transfer.h new file mode 100644 index 0000000..fb0ea4a --- /dev/null +++ b/Aging_app/freertos/inc/dma_transfer.h @@ -0,0 +1,17 @@ +#ifndef __DMA_TRANSFER_H__ +#define __DMA_TRANSFER_H__ + +#include "main_common.h" + + +/* Length of data transfered by DMA*/ +#define DMA_DATA_LEN (8U) + +extern uint8_t uart0TxBuff[]; + +extern QueueHandle_t xGatherQueue1; +extern QueueHandle_t xGatherQueue2; + +void DMA_TRANSFER_Init(void); + +#endif \ No newline at end of file diff --git a/Aging_app/freertos/inc/main_common.h b/Aging_app/freertos/inc/main_common.h new file mode 100644 index 0000000..d3fe0f7 --- /dev/null +++ b/Aging_app/freertos/inc/main_common.h @@ -0,0 +1,43 @@ +#ifndef __MAIN_COMMON_H__ +#define __MAIN_COMMON_H__ + +#include "Z20K11xM_drv.h" +#include "Z20K11xM_clock.h" +#include "Z20K11xM_sysctrl.h" +#include "Z20K11xM_wdog.h" +#include "Z20K11xM_gpio.h" +#include "Z20K11xM_stim.h" +#include "Z20k11xM_dma.h" +#include "Z20K11xM_uart.h" +#include "Z20K11xM_adc.h" +#include "Z20K11xM_tdg.h" + +/* Kernel includes. */ +#include "FreeRTOS.h" +#include "queue.h" +#include "semphr.h" +#include "timers.h" + +#include "stdio.h" +#include "string.h" + +#define __DEVICES_ID__ "BXLH06" + +#define SEND_DATA_LEN 50 +#define RECEIVE_DATA_LEN 48 + +typedef struct Data_format +{ + uint8_t id; + uint16_t current; + uint16_t voltage; + int16_t temperature; +} Dataformat_t; + +typedef struct UserDaemon_format +{ + SemaphoreHandle_t xUserSemaphore; // ִ���û��ػ����̵ļ����ź��� + uint8_t Open_PWM; +} UserDaemon_t; + +#endif \ No newline at end of file diff --git a/Aging_app/freertos/inc/system_init.h b/Aging_app/freertos/inc/system_init.h new file mode 100644 index 0000000..dc63881 --- /dev/null +++ b/Aging_app/freertos/inc/system_init.h @@ -0,0 +1,13 @@ +#ifndef __SYSTEM_INIT_H__ +#define __SYSTEM_INIT_H__ + + +#include "main_common.h" +#include "uart_transfer.h" +#include "dma_transfer.h" +#include "adc_collect.h" + + +void System_Init(void); + +#endif \ No newline at end of file diff --git a/Aging_app/freertos/inc/task_lists.h b/Aging_app/freertos/inc/task_lists.h new file mode 100644 index 0000000..b42f7f9 --- /dev/null +++ b/Aging_app/freertos/inc/task_lists.h @@ -0,0 +1,9 @@ +#ifndef __TASK_LISTS_H__ +#define __TASK_LISTS_H__ + + +#include "main_common.h" + +void Tasks_Create(void); + +#endif \ No newline at end of file diff --git a/Aging_app/freertos/inc/uart_transfer.h b/Aging_app/freertos/inc/uart_transfer.h new file mode 100644 index 0000000..afde834 --- /dev/null +++ b/Aging_app/freertos/inc/uart_transfer.h @@ -0,0 +1,12 @@ +#ifndef __UART_TRANSFER_H__ +#define __UART_TRANSFER_H__ + + +#include "main_common.h" + + +void Uart0_Init(void); +void Uart1_Init(void); +void Uart2_Init(void); + +#endif \ No newline at end of file diff --git a/Aging_app/freertos/inc/wifi_transfer.h b/Aging_app/freertos/inc/wifi_transfer.h new file mode 100644 index 0000000..1fa5bb9 --- /dev/null +++ b/Aging_app/freertos/inc/wifi_transfer.h @@ -0,0 +1,12 @@ +#ifndef __WIFI_TRANSFER_H__ +#define __WIFI_TRANSFER_H__ + + + +#include "main_common.h" + +void WIFI_Send_Data(void); +void WIFI_Connection(void); +void WIFI_Connection_Test(void); + +#endif \ No newline at end of file diff --git a/Aging_app/freertos/readme.txt b/Aging_app/freertos/readme.txt new file mode 100644 index 0000000..f72ebc7 --- /dev/null +++ b/Aging_app/freertos/readme.txt @@ -0,0 +1,37 @@ +About this example: + +The freertos example is to show how to use FreeRTOS tasks on this device. + +PTB4 is connected with the blue LED. + +Hardware requirements +===================== +- EVB-ARDO-ZC20K11 board +- Segger J-Link +- Power supply +- Personal Computer + + +Prepare the example +=================== +1. Provide power supply to ADRO board with 12V power; +2. Connect Segger Jlink to target board on J5; +3. Download the application to target board; +4. Run the example; + + +Example Result +=================== +As the example runs, you will see the D7 green led shrinks and the terminal shows: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Freertos example. +Sending queue. +Queue received. +Sending queue. +Queue received. +Sending queue. +Queue received. +...... +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + diff --git a/Aging_app/freertos/src/adc_collect.c b/Aging_app/freertos/src/adc_collect.c new file mode 100644 index 0000000..d015fb3 --- /dev/null +++ b/Aging_app/freertos/src/adc_collect.c @@ -0,0 +1,110 @@ +#include "adc_collect.h" + + +/*Interrupt complete flag*/ +uint8_t intflag = 0; + +ADC_Config_t adcCfg = +{ + ADC_RESOLUTION_12BIT, /* ADC 12-bit resolution */ + ADC_VREF_INTERNAL, /* Internal Vref_H to 5V, Vref_L to 0V reference */ + ADC_NORMAL_SW_TRIGGER, /* Software trigger select */ + ADC_CONVERSION_SINGLE, /* ADC single conversion */ + ADC_AVGS_16, /* 16 times average for each conversion*/ + 400 /* Set the time interval between two samples when average is enabled or + in continues mode. Please refer to STS definition in RM to see the constraint */ +}; + +ADC_ChannelConfig_t adcChannelCfg = +{ + ADC_SINGLE_MODE, /* Single-Ended Mode Selected */ + ADC_P_CH0, /* Single mode, channel[0] and vssa */ + ADC_N_NONE, /* Single mode, N-channel donn't need to configure */ +}; + + +void adc_tcomp_cb(void) +{ + intflag = 1; + ADC_IntClear(ADC0_ID, ADC_TCOMP_INT); +} + +void ADC0_Init(void) +{ + /* Select clock source for ADC. Selection of ADC functional clock is suggested to be the same with bus clock*/ + CLK_ModuleSrc(CLK_ADC0, CLK_SRC_FIRC64M); + /*set clock for ADC , make sure it is not greater than bus clock*/ + CLK_SetClkDivider(CLK_ADC0, CLK_DIV_2); + + /* Reset ADC */ + SYSCTRL_ResetModule(SYSCTRL_ADC0); + /* Enable ADC clock */ + SYSCTRL_EnableModule(SYSCTRL_ADC0); + /* Select clock source for PORTA and enable */ + CLK_ModuleSrc(CLK_PORTA, CLK_SRC_FIRC64M); + SYSCTRL_EnableModule(SYSCTRL_PORTA); + /* Configure PTA0 as adc channel0 */ + PORT_PinmuxConfig(PORT_A, GPIO_0, PTA0_ADC0_CH0); + + /* Register the callback function */ + ADC_InstallCallBackFunc(ADC0_ID, ADC_TCOMP_INT, adc_tcomp_cb); + /* Reset software */ + ADC_SoftwareReset(ADC0_ID); + /* Initialize ADC */ + ADC_Init(ADC0_ID, &adcCfg); + /* Channel configurate */ + ADC_ChannelConfig(ADC0_ID, &adcChannelCfg); + /* Only unmask TCOMP interrupt */ + ADC_IntMask(ADC0_ID, ADC_INT_ALL, MASK); + ADC_IntMask(ADC0_ID, ADC_TCOMP_INT, UNMASK); + /* Clear TCOMP interrupt */ + ADC_IntClear(ADC0_ID, ADC_TCOMP_INT); + /* Enable ADC */ + ADC_Enable(ADC0_ID); + /* Enable ADC interrupt */ + NVIC_EnableIRQ(ADC0_IRQn); +} + +/* -5¡ãC 0¡ãC 5¡ãC 10¡ãC ...... 85¡ãC 90¡ãC 95¡ãC 100¡ãC *//* -5°C 0°C 5°C 10°C ...... 85°C 90°C 95°C 100°C */ +uint16_t volt[22] = {1438, 1394, 1345, 1290, 1231, 1167, 1100, 1030, 960, 889, 818, + 749, 683, 621, 562, 509, 459, 413, 371, 334, 300, 269}; + +int16_t Adc_Collect_Temp(void) +{ + /*Sample result with channel information*/ + uint32_t adcResult = 0; + /*Sample data value */ + uint16_t dataResult = 0; + /*Sample channel value */ + //uint16_t chResult = 0; + uint32_t i; + uint16_t volt_now; + float scale; + int16_t Temp = 255; // ζȳËÒÔ10// ????10 + + /* Software trigger */ + ADC_SoftwareTrigger(ADC0_ID); + /* Wait TCOMP interrupt */ + while(intflag == 0); + intflag = 0; + + /*Get sample result, suggest to discard the first sampled data due to the instability of it*/ + adcResult = ADC_GetConversionResult(ADC0_ID); + dataResult = adcResult & 0xfff; + volt_now = (uint16_t)(dataResult * 0.830f); + + for(i = 0; i < 22; i++) + { + if((volt_now <= volt[i]) && (volt_now >= volt[i+1])) + break; + } + + if(i < 22) + { + scale = (volt[i] - volt[i+1]) / 20.0f; + Temp = (int16_t)(((5*i - 5) + ((volt[i] - volt_now) / scale) * 0.25f) * 10); + } + + //chResult = (adcResult >> 12) & 0x1f; + return Temp; +} \ No newline at end of file diff --git a/Aging_app/freertos/src/dma_transfer.c b/Aging_app/freertos/src/dma_transfer.c new file mode 100644 index 0000000..c214585 --- /dev/null +++ b/Aging_app/freertos/src/dma_transfer.c @@ -0,0 +1,178 @@ +#include "dma_transfer.h" + +static uint8_t uart1RxBuff[16]; +static uint8_t uart2RxBuff[16]; + +void DMA0_TransferConfig(void) +{ + DMA_TransferConfig_t gtDMATransferConfig0; + /* the channe0 used for dma transfer */ + gtDMATransferConfig0.channel = DMA_CHANNEL0; + /* DMA channel priority */ + gtDMATransferConfig0.channelPriority = DMA_CHN_PRIORITY0; + /* the source of the DMA request for this channe0 */ + gtDMATransferConfig0.source = DMA_REQ_UART0_TX; + /* done interrupt mask */ + gtDMATransferConfig0.doneIntMask = MASK; + /* error interrupt mask */ + gtDMATransferConfig0.errorIntMask = MASK; + + /* address pointing to the source data */ + gtDMATransferConfig0.srcAddr = (uint32_t)uart0TxBuff; + /* address pointing to the destination data */ + gtDMATransferConfig0.destAddr = (uint32_t)0x4006A000; + /* source address offset */ + gtDMATransferConfig0.minorLoopSrcOffset = 4; + /* destination address offset */ + gtDMATransferConfig0.minorLoopDestOffset = 0; + /* source address offset after a major loop done */ + gtDMATransferConfig0.majorLoopSrcOffset = 0; + /* destination address offset after a major loop done */ + gtDMATransferConfig0.majorLoopDestOffset = 0; + /* source data transfer size */ + gtDMATransferConfig0.srcTransferSize = DMA_TRANSFER_SIZE_4B; + /* destintion data transfer size, uart buffer is 8 bits, tramsfer size is better no larger than 1 byte */ + gtDMATransferConfig0.destTransferSize = DMA_TRANSFER_SIZE_1B; + /* transfer bytes number */ + gtDMATransferConfig0.transferByteNum = DMA_DATA_LEN; + /* number of minor loop in a major loop */ + gtDMATransferConfig0.minorLoopNum = 1; + /* disable request after done control */ + gtDMATransferConfig0.disableRequestAfterDoneCmd = ENABLE; + + /* dma transfer config Function */ + DMA_ConfigTransfer(>DMATransferConfig0); +} + +void DMA1_TransferConfig(void) +{ + DMA_TransferConfig_t gtDMATransferConfig1; + /* the channe0 used for dma transfer */ + gtDMATransferConfig1.channel = DMA_CHANNEL1; + /* DMA channel priority */ + gtDMATransferConfig1.channelPriority = DMA_CHN_PRIORITY0; + /* the source of the DMA request for this channe0 */ + gtDMATransferConfig1.source = DMA_REQ_UART1_RX; + /* done interrupt mask */ + gtDMATransferConfig1.doneIntMask = MASK; + /* error interrupt mask */ + gtDMATransferConfig1.errorIntMask = MASK; + + /* address pointing to the source data */ + gtDMATransferConfig1.srcAddr = (uint32_t)0x4006B000; + /* address pointing to the destination data */ + gtDMATransferConfig1.destAddr = (uint32_t)uart1RxBuff; + /* source address offset */ + gtDMATransferConfig1.minorLoopSrcOffset = 0; + /* destination address offset */ + gtDMATransferConfig1.minorLoopDestOffset = 1; + /* source address offset after a major loop done */ + gtDMATransferConfig1.majorLoopSrcOffset = 0; + /* destination address offset after a major loop done */ + gtDMATransferConfig1.majorLoopDestOffset = 0; + /* source data transfer size */ + gtDMATransferConfig1.srcTransferSize = DMA_TRANSFER_SIZE_1B; + /* destintion data transfer size, uart buffer is 8 bits, tramsfer size is better no larger than 1 byte */ + gtDMATransferConfig1.destTransferSize = DMA_TRANSFER_SIZE_1B; + /* transfer bytes number */ + gtDMATransferConfig1.transferByteNum = 14;//DMA_DATA_LEN; + /* number of minor loop in a major loop */ + gtDMATransferConfig1.minorLoopNum = 1; + /* disable request after done control */ + gtDMATransferConfig1.disableRequestAfterDoneCmd = DISABLE;//ENABLE; + + /* dma transfer config Function */ + DMA_ConfigTransfer(>DMATransferConfig1); +} + +void DMA2_TransferConfig(void) +{ + DMA_TransferConfig_t gtDMATransferConfig2; + /* the channe0 used for dma transfer */ + gtDMATransferConfig2.channel = DMA_CHANNEL2; + /* DMA channel priority */ + gtDMATransferConfig2.channelPriority = DMA_CHN_PRIORITY0; + /* the source of the DMA request for this channe0 */ + gtDMATransferConfig2.source = DMA_REQ_UART2_RX; + /* done interrupt mask */ + gtDMATransferConfig2.doneIntMask = MASK; + /* error interrupt mask */ + gtDMATransferConfig2.errorIntMask = MASK; + + /* address pointing to the source data */ + gtDMATransferConfig2.srcAddr = (uint32_t)0x4006C000; + /* address pointing to the destination data */ + gtDMATransferConfig2.destAddr = (uint32_t)uart2RxBuff; + /* source address offset */ + gtDMATransferConfig2.minorLoopSrcOffset = 0; + /* destination address offset */ + gtDMATransferConfig2.minorLoopDestOffset = 1; + /* source address offset after a major loop done */ + gtDMATransferConfig2.majorLoopSrcOffset = 0; + /* destination address offset after a major loop done */ + gtDMATransferConfig2.majorLoopDestOffset = 0; + /* source data transfer size */ + gtDMATransferConfig2.srcTransferSize = DMA_TRANSFER_SIZE_1B; + /* destintion data transfer size, uart buffer is 8 bits, tramsfer size is better no larger than 1 byte */ + gtDMATransferConfig2.destTransferSize = DMA_TRANSFER_SIZE_1B; + /* transfer bytes number */ + gtDMATransferConfig2.transferByteNum = 14;//DMA_DATA_LEN; + /* number of minor loop in a major loop */ + gtDMATransferConfig2.minorLoopNum = 1; + /* disable request after done control */ + gtDMATransferConfig2.disableRequestAfterDoneCmd = DISABLE;//ENABLE; + + /* dma transfer config Function */ + DMA_ConfigTransfer(>DMATransferConfig2); +} + +void Gather_Uart1(void) +{ + /* receive data */ + DMA_SetDestAddr(DMA_CHANNEL1, (uint32_t)uart1RxBuff); + + // дÈë¶ÓÁÐ + xQueueSendToBackFromISR(xGatherQueue1, uart1RxBuff, pdFALSE); +} + +void Gather_Uart2(void) +{ + /* receive data */ + DMA_SetDestAddr(DMA_CHANNEL2, (uint32_t)uart2RxBuff); + + // дÈë¶ÓÁÐ + xQueueSendToBackFromISR(xGatherQueue2, uart2RxBuff, pdFALSE); +} + +void DMA_TRANSFER_Init(void) +{ + DMA_Config_t gtDMAInitConfig; + + /* enable DMA */ + SYSCTRL_EnableModule(SYSCTRL_DMA); + SYSCTRL_EnableModule(SYSCTRL_DMAMUX); + + /* dma behavior in debiug mode */ + gtDMAInitConfig.dmaDebugBehavior = DMA_DEBUG_HALT; + /* dma behavior in error mode */ + gtDMAInitConfig.dmaErrorBehavior = DMA_ERROR_HALT; + /* dma priority arbitration */ + gtDMAInitConfig.dmaPriorityArbitration = DMA_ROUND_ROBIN_ARBITRATION; + /* initializes dma */ + DMA_Init(>DMAInitConfig); + + /* DMA transfer config */ + DMA0_TransferConfig(); + DMA1_TransferConfig(); + DMA2_TransferConfig(); + + DMA_ChannelRequestEnable(DMA_CHANNEL1); + DMA_ChannelRequestEnable(DMA_CHANNEL2); + + DMA_InstallCallBackFunc(DMA_CHANNEL1, DMA_INT_DONE, Gather_Uart1); + DMA_IntMask(DMA_CHANNEL1, DMA_INT_DONE, UNMASK); + DMA_InstallCallBackFunc(DMA_CHANNEL2, DMA_INT_DONE, Gather_Uart2); + DMA_IntMask(DMA_CHANNEL2, DMA_INT_DONE, UNMASK); + + NVIC_EnableIRQ(DMA0TO3_IRQn); +} diff --git a/Aging_app/freertos/src/main.c b/Aging_app/freertos/src/main.c new file mode 100644 index 0000000..9432621 --- /dev/null +++ b/Aging_app/freertos/src/main.c @@ -0,0 +1,160 @@ +/**************************************************************************************************/ +/** + * @file main.c + * @brief FREERTOS example file. + * @version V1.7.0 + * @date May-2020 + * @author Zhixin Semiconductor + * + * @note + * Copyright (C) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + * + **************************************************************************************************/ + +#include "main_common.h" + +/* Kernel includes. */ +#include "task.h" + +/* User includes. */ +#include "system_init.h" +#include "adc_collect.h" +#include "task_lists.h" + + +/* The number of items the queue can hold. */ +#define RECV_QUEUE_LENGTH (5U) +#define SEND_QUEUE_LENGTH (20U) + +/* Priorities at which the tasks are created. */ +#define QUEUE_RECEIVE_TASK_PRIORITY ( tskIDLE_PRIORITY + 2U ) +#define QUEUE_SEND_TASK_PRIORITY ( tskIDLE_PRIORITY + 1U ) + +/* The rate at which data is sent to the queue, specified in milliseconds */ +#define QUEUE_SEND_FREQUENCY_MS ( 1000U / portTICK_PERIOD_MS ) + +/* A block time of zero simply means "don't block". */ +#define DONT_BLOCK ( 0UL ) + + +/* The queue used by both tasks. */ +QueueHandle_t xRecvQueue = NULL; // ½ÓÊÕ·þÎñÆ÷Ö¸ÁîµÄ¶ÓÁÐ +QueueHandle_t xSendQueue = NULL; // ·¢ËÍÊý¾Ýµ½·þÎñÆ÷µÄ¶ÓÁÐ + +QueueHandle_t xGatherQueue1 = NULL; // ²É¼¯Êý¾ÝµÚ1·µÄ¶ÓÁÐ +QueueHandle_t xGatherQueue2 = NULL; // ²É¼¯Êý¾ÝµÚ2·µÄ¶ÓÁÐ + +TaskHandle_t Gather_Handler1; // ²É¼¯µÚһͨµÀµÄÈÎÎñ¾ä±ú +TaskHandle_t Gather_Handler2; // ²É¼¯µÚ¶þͨµÀµÄÈÎÎñ¾ä±ú +TaskHandle_t UserDaemon_Handler; // Óû§ÊØ»¤½ø³ÌµÄÈÎÎñ¾ä±ú + +SemaphoreHandle_t xStopSemaphore1 = NULL; // Í£Ö¹µÚһͨµÀ²É¼¯Ö¸ÁîµÄÐźÅÁ¿ +SemaphoreHandle_t xStopSemaphore2 = NULL; // Í£Ö¹µÚ¶þͨµÀ²É¼¯Ö¸ÁîµÄÐźÅÁ¿ + +SemaphoreHandle_t xSemaphoreTx; // ʹÓÃWiFiÄ£¿éµÄ»¥³âÁ¿ +SemaphoreHandle_t xSemaphoreUart; // ʹÓòɼ¯´®¿ÚµÄ»¥³âÁ¿ + +uint8_t uart0TxBuff[SEND_DATA_LEN]; // ·¢Ë͵½WiFiÄ£¿éµÄ×Ö·û´® + +UserDaemon_t UserDaemon; // ¼Ç¼Óû§ÊØ»¤½ø³ÌµÄ½á¹¹Ìå±äÁ¿ + +TimerHandle_t WorkTimeHandle; // ͨµç¶¨Ê±Æ÷ +TimerHandle_t RelaxTimeHandle; // ¶Ïµç¶¨Ê±Æ÷ +TimerHandle_t CollectTempHandle; // ζȲɼ¯¶¨Ê±Æ÷ + +void WorkCallBackTask(void); // ͨµç¶¨Ê±Æ÷»Øµ÷º¯Êý +void RelaxCallBackTask(void); // ¶Ïµç¶¨Ê±Æ÷»Øµ÷º¯Êý +void TempCallBackTask(void); // ζȲɼ¯¶¨Ê±Æ÷»Øµ÷º¯Êý + +void Control_ElectricRelay(bool bTurnOn); // ¿ØÖƼ̵çÆ÷ͨ¶Ïµç + +int16_t Temp_Now; // µ±Ç°ÎÂ¶È + +void main() +{ + /* System init */ + System_Init(); + + WorkTimeHandle = xTimerCreate((const char *)"WorkTime", (TickType_t)1000, pdFALSE, (void*)1, (TimerCallbackFunction_t)WorkCallBackTask); // ͨµçµÄ¶¨Ê±Æ÷ + RelaxTimeHandle = xTimerCreate((const char *)"RelaxTime", (TickType_t)2000, pdFALSE, (void*)2, (TimerCallbackFunction_t)RelaxCallBackTask); // ¶ÏµçµÄ¶¨Ê±Æ÷ + CollectTempHandle = xTimerCreate((const char *)"CollectTemp", (TickType_t)10000, pdTRUE, (void*)3, (TimerCallbackFunction_t)TempCallBackTask); // ζȲɼ¯¶¨Ê±Æ÷ + + xTimerStart(CollectTempHandle, 0); // Æô¶¯Î¶Ȳɼ¯¶¨Ê±Æ÷ + + xSemaphoreTx = xSemaphoreCreateMutex(); + xSemaphoreUart = xSemaphoreCreateMutex(); + /* Create the queue. */ + xRecvQueue = xQueueCreate(RECV_QUEUE_LENGTH, RECEIVE_DATA_LEN); + + xSendQueue = xQueueCreate(SEND_QUEUE_LENGTH, sizeof(Dataformat_t)); + + xGatherQueue1 = xQueueCreate(1, 14); // ½ÓÊÕµÚһͨµÀ²É¼¯µÄ14¸ö×Ö½ÚÊý¾Ý + xGatherQueue2 = xQueueCreate(1, 14); // ½ÓÊÕµÚ¶þͨµÀ²É¼¯µÄ14¸ö×Ö½ÚÊý¾Ý + + xStopSemaphore1 = xSemaphoreCreateBinary(); // Í£Ö¹²É¼¯Í¨µÀÒ»ÈÎÎñµÄÐźÅÁ¿ + xStopSemaphore2 = xSemaphoreCreateBinary(); // Í£Ö¹²É¼¯Í¨µÀ¶þÈÎÎñµÄÐźÅÁ¿ + + memset(&UserDaemon, 0x0, sizeof(UserDaemon)); + UserDaemon.xUserSemaphore = xSemaphoreCreateCounting(10, 0); + + if(xRecvQueue != NULL ) + { + Tasks_Create(); + /* Start the tasks and timer running. */ + vTaskStartScheduler(); + } + + + /* If all is well, the scheduler will now be running, and the following line + will never be reached.*/ + for( ;; ); +} +//WQE +/******** ¿ØÖƼ̵çÆ÷ͨ¶Ïµç *********/ +void Control_ElectricRelay(bool bTurnOn) +{ + if(bTurnOn) + { + // ¿ØÖƼ̵çÆ÷Éϵç + GPIO_WritePinOutput(PORT_D, GPIO_2, GPIO_HIGH); // À­¸ßPTD2¼ÌµçÆ÷ͨµç + vTaskDelay(200); // ±ÜÃâÁ½¸ö¼ÌµçÆ÷ͬʱ¹¤×÷ + GPIO_WritePinOutput(PORT_D, GPIO_3, GPIO_HIGH); // À­¸ßPTD3¼ÌµçÆ÷ͨµç + } + else + { + GPIO_WritePinOutput(PORT_D, GPIO_2, GPIO_LOW); // À­µÍPTD2¼ÌµçÆ÷¶Ïµç + vTaskDelay(200); // ±ÜÃâÁ½¸ö¼ÌµçÆ÷ͬʱ¹¤×÷ + GPIO_WritePinOutput(PORT_D, GPIO_3, GPIO_LOW); // À­µÍPTD3¼ÌµçÆ÷¶Ïµç + } +} + +/******** ͨµç¶¨Ê±Æ÷»Øµ÷º¯Êý **********/ +void WorkCallBackTask(void) +{ + // ¿ØÖƼ̵çÆ÷Éϵç + Control_ElectricRelay(1); + + // »Ö¸´²É¼¯ÈÎÎñ + vTaskResume(Gather_Handler1); + vTaskResume(Gather_Handler2); + + // Æô¶¯¶Ïµç¶¨Ê±Æ÷ + xTimerStart(RelaxTimeHandle, 0); +} + +/******** ¶Ïµç¶¨Ê±Æ÷»Øµ÷º¯Êý **********/ +void RelaxCallBackTask(void) +{ + // ֪ͨ²É¼¯ÈÎÎñ¹ÒÆð + xSemaphoreGive(xStopSemaphore1); + xSemaphoreGive(xStopSemaphore2); + + // Æô¶¯Í¨µç¶¨Ê±Æ÷ + xTimerStart(WorkTimeHandle, 0); +} + +/******** ζȲɼ¯¶¨Ê±Æ÷»Øµ÷º¯Êý **********/ +void TempCallBackTask(void) +{ + Temp_Now = Adc_Collect_Temp(); +} diff --git a/Aging_app/freertos/src/system_init.c b/Aging_app/freertos/src/system_init.c new file mode 100644 index 0000000..8269c4e --- /dev/null +++ b/Aging_app/freertos/src/system_init.c @@ -0,0 +1,154 @@ +#include "system_init.h" + + +extern uint8_t bBuzzer; +extern UserDaemon_t UserDaemon; // ¼Ç¼Óû§ÊØ»¤½ø³ÌµÄ½á¹¹Ìå±äÁ¿ + +void Press_key(PORT_ID_t portId, PORT_GPIONO_t gpioNo) +{ + static TickType_t TickCou_Pre; + static portBASE_TYPE xHigherPriorityTaskWoken; + + switch(portId) + { + case PORT_A: + if(gpioNo == GPIO_13) // ÊÖ¶¯¿ØÖƼ̵çÆ÷ + { + if(xTaskGetTickCountFromISR() - TickCou_Pre > 20) + { + GPIO_TogglePinOutput(PORT_D, GPIO_2); + GPIO_TogglePinOutput(PORT_D, GPIO_3); + TickCou_Pre = xTaskGetTickCountFromISR(); + + UserDaemon.Open_PWM = 1; + xSemaphoreGiveFromISR(UserDaemon.xUserSemaphore, &xHigherPriorityTaskWoken); // »½ÐÑÓû§ÊØ»¤½ø³Ì + } + } + break; + + case PORT_E: + if(gpioNo == GPIO_2) + { + + } + else if (gpioNo ==GPIO_6) + { + if(xTaskGetTickCountFromISR() - TickCou_Pre > 20) + { + // ¹Ø±Õ·äÃùÆ÷ + bBuzzer = 0; + GPIO_WritePinOutput(PORT_E, GPIO_7, GPIO_LOW); + } + } + break; + + default: + break; + } +} + +void GPIO_Init(void) +{ + /* ¿ØÖÆESP8266µÄ¸´Î»Òý½Å */ +/* PORT_PinmuxConfig(PORT_A, GPIO_7, PTA7_GPIO); + GPIO_SetPinDir(PORT_A, GPIO_7, GPIO_OUTPUT); + GPIO_SetPinOutput(PORT_A, GPIO_7); + GPIO_WritePinOutput(PORT_A, GPIO_7, GPIO_LOW);*/ // À­µÍPTA7½øÐи´Î» + + /* ÅäÖü̵çÆ÷µÄ¿ØÖÆÒý½Å */ + PORT_PinmuxConfig(PORT_D, GPIO_2, PTD2_GPIO); + GPIO_SetPinDir(PORT_D, GPIO_2, GPIO_OUTPUT); + GPIO_SetPinOutput(PORT_D, GPIO_2); + GPIO_WritePinOutput(PORT_D, GPIO_2, GPIO_LOW); // À­µÍPTD2¼ÌµçÆ÷¶Ïµç + + PORT_PinmuxConfig(PORT_D, GPIO_3, PTD3_GPIO); + GPIO_SetPinDir(PORT_D, GPIO_3, GPIO_OUTPUT); + GPIO_SetPinOutput(PORT_D, GPIO_3); + GPIO_WritePinOutput(PORT_D, GPIO_3, GPIO_LOW); // À­µÍPTD3¼ÌµçÆ÷¶Ïµç + + // Á¬½ÓÉÏWIFIָʾµÆ + PORT_PinmuxConfig(PORT_C, GPIO_6, PTC6_GPIO); + GPIO_SetPinDir(PORT_C, GPIO_6, GPIO_OUTPUT); + GPIO_SetPinOutput(PORT_C, GPIO_6); + GPIO_WritePinOutput(PORT_C, GPIO_6, GPIO_LOW); + + // Õý³£ÔËÐÐָʾµÆ + PORT_PinmuxConfig(PORT_C, GPIO_7, PTC7_GPIO); + GPIO_SetPinDir(PORT_C, GPIO_7, GPIO_OUTPUT); + GPIO_SetPinOutput(PORT_C, GPIO_7); + + /*PORT_PinmuxConfig(PORT_A, GPIO_13, PTA13_GPIO); + GPIO_SetPinDir(PORT_A, GPIO_13, GPIO_OUTPUT); + GPIO_SetPinOutput(PORT_A, GPIO_13); + GPIO_WritePinOutput(PORT_A, GPIO_13, GPIO_LOW);*/ + + /* Select clock for the PORTE module and enable it */ + CLK_ModuleSrc(CLK_PORTE, CLK_SRC_OSC40M); + SYSCTRL_EnableModule(SYSCTRL_PORTE); + + /* Install call back function */ + PORT_InstallCallBackFunc(Press_key); + /* Global config:PTA13 as GPIO(pull up),PTA13 as GPIO(pull up) */ + PORT_GlobalPinsConfig(PORT_A, 0x2000, 0x103); + /* Enable PTA13 interrupt:Press_key */ + PORT_GlobalPinsConfig(PORT_A, 0x2000, 0x80103); + + /* Global config:PTE2 as GPIO(pull up),PTE6 as GPIO(pull up) */ + PORT_GlobalPinsConfig(PORT_E, 0x44, 0x103); + /* Enable PTE2,PTE6 interrupt:Press_key */ + PORT_GlobalPinsConfig(PORT_E, 0x44, 0x80103); + + /* Enable PORTA,PORTB,PORTC,PORTD,PORTE IQR*/ + NVIC_EnableIRQ(PORTABC_IRQn); + NVIC_EnableIRQ(PORTDE_IRQn); + + /* ·äÃùÆ÷ */ + PORT_PinmuxConfig(PORT_E, GPIO_7, PTE7_GPIO); + GPIO_SetPinDir(PORT_E, GPIO_7, GPIO_OUTPUT); + GPIO_SetPinOutput(PORT_E, GPIO_7); + GPIO_WritePinOutput(PORT_E, GPIO_7, GPIO_LOW); + + // ÀÏ»¯¹ý³ÌָʾµÆ + PORT_PinmuxConfig(PORT_A, GPIO_2, PTA2_GPIO); + GPIO_SetPinDir(PORT_A, GPIO_2, GPIO_OUTPUT); + GPIO_SetPinOutput(PORT_A, GPIO_2); + GPIO_WritePinOutput(PORT_A, GPIO_2, GPIO_LOW); + + // Á¬ÉÏ·þÎñÆ÷ָʾµÆ + PORT_PinmuxConfig(PORT_A, GPIO_3, PTA3_GPIO); + GPIO_SetPinDir(PORT_A, GPIO_3, GPIO_OUTPUT); + GPIO_SetPinOutput(PORT_A, GPIO_3); + GPIO_WritePinOutput(PORT_A, GPIO_3, GPIO_LOW); +} + +void System_Init(void) +{ + /* Interrupt vector table redefinition*/ +// SCB->VTOR = ((uint32_t)&__vector_table) & 0xFFFFFF00U; +// __DSB(); + + /* Disable wdog */ + SYSCTRL_EnableModule(SYSCTRL_WDOG); + WDOG_Disable(); + + /* Select FIRC64M as system clock*/ +// CLK_SysClkSrc(CLK_SYS_FIRC64M); + /* clock init */ + CLK_OSC40MEnable2(CLK_OSC_FREQ_MODE_HIGH, ENABLE, CLK_OSC_XTAL); + /* Choose OSC40M as system clock*/ + while(CLK_SysClkSrc(CLK_SYS_OSC40M)); + /* Set Core and bus clock*/ + CLK_SetClkDivider(CLK_CORE, CLK_DIV_1); + CLK_SetClkDivider(CLK_BUS, CLK_DIV_1); + + /* Enable GPIO module */ + SYSCTRL_EnableModule(SYSCTRL_GPIO); + + Uart0_Init(); + Uart1_Init(); + Uart2_Init(); + DMA_TRANSFER_Init(); + ADC0_Init(); + GPIO_Init(); +} + diff --git a/Aging_app/freertos/src/task_lists.c b/Aging_app/freertos/src/task_lists.c new file mode 100644 index 0000000..d1bf0b3 --- /dev/null +++ b/Aging_app/freertos/src/task_lists.c @@ -0,0 +1,771 @@ +#include "task_lists.h" +#include "wifi_transfer.h" + + +extern QueueHandle_t xRecvQueue; // ½ÓÊÕ·þÎñÆ÷Ö¸ÁîµÄ¶ÓÁÐ +extern QueueHandle_t xSendQueue; // ·¢ËÍÊý¾Ýµ½·þÎñÆ÷µÄ¶ÓÁÐ + +extern TaskHandle_t Gather_Handler1; // ²É¼¯µÚһͨµÀµÄÈÎÎñ¾ä±ú +extern TaskHandle_t Gather_Handler2; // ²É¼¯µÚ¶þͨµÀµÄÈÎÎñ¾ä±ú +extern TaskHandle_t UserDaemon_Handler; // Óû§ÊØ»¤½ø³ÌµÄÈÎÎñ¾ä±ú + +extern UserDaemon_t UserDaemon; // ¼Ç¼Óû§ÊØ»¤½ø³ÌµÄ½á¹¹Ìå±äÁ¿ + +extern QueueHandle_t xGatherQueue1; // ²É¼¯Êý¾ÝµÚ1·µÄ¶ÓÁÐ +extern QueueHandle_t xGatherQueue2; // ²É¼¯Êý¾ÝµÚ2·µÄ¶ÓÁÐ + +extern SemaphoreHandle_t xSemaphoreTx; // ʹÓÃWiFiÄ£¿éµÄ»¥³âÁ¿ +extern SemaphoreHandle_t xSemaphoreUart; // ʹÓòɼ¯´®¿ÚµÄ»¥³âÁ¿ + +extern TimerHandle_t WorkTimeHandle; // ͨµç¶¨Ê±Æ÷ +extern TimerHandle_t RelaxTimeHandle; // ¶Ïµç¶¨Ê±Æ÷ + +extern SemaphoreHandle_t xStopSemaphore1; // Í£Ö¹µÚһͨµÀ²É¼¯Ö¸ÁîµÄÐźÅÁ¿ +extern SemaphoreHandle_t xStopSemaphore2; // Í£Ö¹µÚ¶þͨµÀ²É¼¯Ö¸ÁîµÄÐźÅÁ¿ + +extern int16_t Temp_Now; // µ±Ç°ÎÂ¶È + +extern void Control_ElectricRelay(bool bTurnOn); + +uint8_t Wifistep = 1; // WifiÄ£¿é͸´«µÄ²½Öè + +TaskHandle_t Command_Handler; // ½ÓÊÕ·þÎñÆ÷Ö¸ÁîµÄÈÎÎñ¾ä±ú +TaskHandle_t Send_Handler; // ²É¼¯µ½µÄÊý¾Ý·¢Ë͵½·þÎñÆ÷µÄÈÎÎñ¾ä±ú + +TaskHandle_t HeartBeat_Handler; // ¸ú·þÎñÆ÷½»»¥ÐÄÌø°üµÄÈÎÎñ¾ä±ú +TickType_t HeartCou_Last; // ×îºóÒ»´ÎÐÄÌø°üµÄʱ¼ä´Á + +extern uint8_t uart0TxBuff[]; + +uint32_t Delay_S = 0; // ÑÓʱʱ¼ä +uint32_t Work_time = 0; // ͨµçʱ¼ä +uint32_t Relax_time = 0; // ¶Ïµçʱ¼ä + +uint16_t MinCurrent = 0x00; // ×îСµçÁ÷ +uint16_t MaxCurrent = 0xFFFF; // ×î´óµçÁ÷ +uint32_t PWMRate = 0; // PWMƵÂÊ +uint16_t CurrVoltage = 0x00; // µ±Ç°µçѹ + +uint8_t bBuzzer = 1; + +uint16_t DataCrc[52] = {0x540B, 0x5438, 0x55E9, 0x545E, 0x558F, 0x55BC, 0x546D, 0x5492, \ + 0x5543, 0x5570, 0x54A1, 0x5516, 0x54C7, 0x54F4, 0x5525, 0x574A, \ + 0x569B, 0x56A8, 0x5779, 0x56CE, 0x571F, 0x572C, 0x56FD, 0x5602, \ + 0x57D3, 0x57E0, 0x5631, 0x5786, 0x5657, 0x5664, 0x57B5, 0x52BA, \ + 0x536B, 0x5358, 0x5289, 0x533E, 0x52EF, 0x52DC, 0x530D, 0x53F2, \ + 0x5223, 0x5210, 0x53C1, 0x5276, 0x53A7, 0x5394, 0x5245, 0x502A, \ + 0x51FB, 0x51C8, 0x5019, 0x51AE}; + + +/******* Á¬½ÓWiFiºÍ·þÎñÆ÷ *********/ +static void queueWifiTask(void *parames) +{ + while(Wifistep != 8) + WIFI_Connection(); // WIFI_Connection_Test WIFI_Connection + + vTaskResume(Command_Handler); + + vTaskSuspend(NULL); +} + + +/******* ¸ú·þÎñÆ÷½»»¥ÐÄÌø°ü *********/ +static void queueHeartBeatTask(void *parames) +{ + TickType_t xLastWakeTime; + + vTaskSuspend(NULL); + + xLastWakeTime = xTaskGetTickCount(); + HeartCou_Last = xTaskGetTickCount(); + + for( ;; ) + { + xSemaphoreTake(xSemaphoreTx, portMAX_DELAY); + strcpy((char *)uart0TxBuff, "$CMSGH,<"__DEVICES_ID__">,$#"); + + WIFI_Send_Data(); + xSemaphoreGive(xSemaphoreTx); + + if(xTaskGetTickCount() - HeartCou_Last >= 3*60*1000) // Èý·ÖÖÓÄÚûÊÕµ½·þÎñÆ÷µÄÐÄÌø°üÏìÓ¦ + { + // ÔÚÏßָʾµÆÏ¨Ãð + } + + vTaskDelayUntil(&xLastWakeTime, 15000); // ¼ä¸ô15s·¢ËÍÒ»´Î + } +} + +/******** ½ÓÊÕÀ´×Ô·þÎñÆ÷µÄÖ¸Áî *********/ +static void queueCommandTask(void *parames) +{ + char recv_mess[RECEIVE_DATA_LEN] = {0}; + uint8_t bResponse = 0; + uint32_t Min_Temp = 0; // ×îСµçÁ÷ + uint32_t Max_Temp = 0; // ×î´óµçÁ÷ + uint32_t PWM_Temp = 0; // PWMƵÂÊ + + vTaskSuspend(NULL); + + for( ;; ) + { + xQueueReceive(xRecvQueue, recv_mess, portMAX_DELAY); + + if(!strcmp(recv_mess, "$SMSG,<"__DEVICES_ID__">,,$#")) + { + xSemaphoreTake(xSemaphoreTx, portMAX_DELAY); + strcpy((char *)uart0TxBuff, recv_mess); + uart0TxBuff[1] = 'C'; + WIFI_Send_Data(); + xSemaphoreGive(xSemaphoreTx); + + // ¿ØÖƼ̵çÆ÷Éϵç + Control_ElectricRelay(1); + + // »Ö¸´²É¼¯ÈÎÎñ + vTaskResume(Gather_Handler1); + vTaskResume(Gather_Handler2); + + // ÉèÖÃͨ¶Ïµç¶¨Ê±Æ÷ (¶Ïµçʱ¼äÒ»µ½¾ÍÆô¶¯Í¨µç¶¨Ê±Æ÷£¬Í¨µçʱ¼äÒ»µ½¾ÍÆô¶¯¶Ïµç¶¨Ê±Æ÷) + xTimerChangePeriod(WorkTimeHandle, Relax_time*60*1000, 0); + xTimerChangePeriod(RelaxTimeHandle, Work_time*60*1000, 0); + + // µ÷ÓÃxTimerChangePeriodĬÈÏ¿ªÆô£¬Ðè¹Ø±Õͨµç¶¨Ê±Æ÷ + xTimerStop(WorkTimeHandle, 0); + + // ¿ªÆôÐÄÌø°ü½»»¥ + vTaskResume(HeartBeat_Handler); + + // ¹Ø±ÕÊÖ¶¯¿ØÖƼ̵çÆ÷ + NVIC_DisableIRQ(PORTABC_IRQn); + } + else if(!strcmp(recv_mess, "$SMSG,<"__DEVICES_ID__">,,$#")) + { + // ֪ͨ²É¼¯ÈÎÎñ¹ÒÆð + xSemaphoreGive(xStopSemaphore1); + xSemaphoreGive(xStopSemaphore2); + + // ¹Ø±Õͨ¶Ïµç¶¨Ê±Æ÷ + xTimerStop(WorkTimeHandle, 0); + xTimerStop(RelaxTimeHandle, 0); + + xSemaphoreTake(xSemaphoreTx, portMAX_DELAY); + bResponse = 1; + strcpy((char *)uart0TxBuff, recv_mess); + uart0TxBuff[1] = 'C'; + + // ¹Ø±ÕÐÄÌø°ü½»»¥ + //vTaskSuspend(HeartBeat_Handler); + + // ¿ªÆôÊÖ¶¯¿ØÖƼ̵çÆ÷ + NVIC_EnableIRQ(PORTABC_IRQn); + } + else if(!strcmp(recv_mess, "$SMSGB,<"__DEVICES_ID__">,,$#")) + { + // ¹Ø±Õ·äÃùÆ÷ + bBuzzer = 0; + GPIO_WritePinOutput(PORT_E, GPIO_7, GPIO_LOW); + + xSemaphoreTake(xSemaphoreTx, portMAX_DELAY); + bResponse = 1; + strcpy((char *)uart0TxBuff, recv_mess); + uart0TxBuff[1] = 'C'; + } + else if(!strcmp(recv_mess, "$SMSGH,<"__DEVICES_ID__">,$#")) + { + // ¸üÐÂʱ¼ä´Á + HeartCou_Last = xTaskGetTickCount(); + } + else + { + Min_Temp = 0; + Max_Temp = 0; + PWM_Temp = 0; + + // ×îСµçÁ÷¡¢×î´óµçÁ÷¡¢PWMƵÂÊ + sscanf(recv_mess, "$SMSGS,<"__DEVICES_ID__">,<%d>,<%d>,$#", &Min_Temp, &Max_Temp); + sscanf(recv_mess, "$SMSGP,<"__DEVICES_ID__">,<%d>,$#", &PWM_Temp); + + if(((Min_Temp > 0) && (Min_Temp < Max_Temp)) || (PWM_Temp > 0)) + { + if(Min_Temp > 0) + { + MinCurrent = Min_Temp; + MaxCurrent = Max_Temp; + Min_Temp = 0; + Max_Temp = 0; + } + else + { + PWMRate = PWM_Temp; + PWM_Temp = 0; + } + + xSemaphoreTake(xSemaphoreTx, portMAX_DELAY); + bResponse = 1; + strcpy((char *)uart0TxBuff, recv_mess); + uart0TxBuff[1] = 'C'; + } + } + + if(bResponse) + { + WIFI_Send_Data(); + xSemaphoreGive(xSemaphoreTx); + bResponse = 0; + } + } +} + + +static uint16_t getModbusCRC16(unsigned char *_pBuf, unsigned short int _usLen) +{ + uint16_t CRCValue = 0xFFFF; //³õʼ»¯CRC±äÁ¿¸÷λΪ1 + unsigned char i, j; + + for(i = 0; i <_usLen; ++i) + { + CRCValue ^= *(_pBuf+i); //µ±Ç°Êý¾ÝÒì»òCRCµÍ×Ö½Ú + for(j = 0; j < 8; ++j) //Ò»¸ö×Ö½ÚÖØ¸´ÓÒÒÆ8´Î + { + if((CRCValue & 0x01) == 0x01) //ÅжÏÓÒ񮂡×îµÍλÊÇ·ñΪ1 + { + CRCValue = (CRCValue >> 1)^0xA001; //Èç¹ûΪ1ÔòÓÒÒÆ²¢Òì»ò±í´ïʽ + } + else + { + CRCValue >>= 1; //·ñÔòÖ±½ÓÓÒÒÆÒ»Î» + } + } + } + + return CRCValue; +} + +/********* ²É¼¯µÚһͨµÀµçѹµçÁ÷ζȵÄÊý¾Ý *********/ +static void queueGatherTask1(void *params) +{ +// unsigned long ulReceivedValue; + + /* Casting params to void because it is unused */ + (void)params; + + TickType_t xLastWakeTime; + uint8_t idx = 0; + uint8_t i = 0; + Dataformat_t gatherdata; + uint8_t query_dev[8] = {0x01, 0x03, 0x00, 0x01, 0x00, 0x03, 0x54, 0x0B}; // 0x01ΪID£¬0x03Ϊ¶ÁÈ¡±£³Ö¼Ä´æÆ÷£¬0x00 0x01Ϊ²éѯÊý¾ÝµØÖ·£¬0x00 0x03Ϊ²éѯµØÖ·µÄ·¶Î§£¬0x54 0x0BΪCRC16УÑéÂë + uint8_t broadcast[8] = {0xFF, 0x10}; // 0xFFΪ¹ã²¥£¬0x10ΪдÈë¶à¼Ä´æÆ÷ + uint8_t query_data[14]; + uint16_t CheckValue; + uint8_t re_times = 0; + uint8_t bError = 0; + uint32_t bSample = 0; + uint8_t times = 0; + uint8_t instNotConn = 0;//ÅжϿÕÔØºó£¬ºóÐø´¦ÀíʹÓñê־λ + + vTaskSuspend(NULL); + GPIO_WritePinOutput(PORT_A, GPIO_2, GPIO_HIGH); + + if(MinCurrent < MaxCurrent) // ͨ¹ý¹ã²¥½«×î´ó×îСµçÁ÷·¢Ë͸ø²É¼¯¶Ë + { + broadcast[2] = MinCurrent >> 8; // ×îСµçÁ÷¸ßλ + broadcast[3] = MinCurrent & 0xFF; // ×îСµçÁ÷µÍλ + broadcast[4] = MaxCurrent >> 8; // ×î´óµçÁ÷¸ßλ + broadcast[5] = MaxCurrent & 0xFF; // ×î´óµçÁ÷µÍλ + CheckValue = getModbusCRC16(broadcast, 6); + broadcast[6] = CheckValue & 0xFF; + broadcast[7] = CheckValue >> 8; + + for(idx = 0; idx < 3; idx++) + { + xSemaphoreTake(xSemaphoreUart, portMAX_DELAY); + GPIO_WritePinOutput(PORT_B, GPIO_2, GPIO_HIGH); // À­¸ßPTB2·¢ËÍÊý¾Ý + + for(i = 0; i < 8; i++) + { + UART_SendByte(UART1_ID, broadcast[i]); + } + + while(RESET == UART_GetLineStatus(UART1_ID, UART_LINESTA_TEMT)); // µÈ´ýÈ«²¿Êý¾Ý·¢ËÍÍê³É + GPIO_WritePinOutput(PORT_B, GPIO_2, GPIO_LOW); // À­µÍPTB2½ÓÊÕÊý¾Ý + xSemaphoreGive(xSemaphoreUart); + + vTaskDelay(60); + } + } + + if(PWMRate > 0) // ͨ¹ý¹ã²¥½«PWMƵÂÊ·¢Ë͸ø²É¼¯¶Ë + { + broadcast[1] = 0x06; + broadcast[2] = PWMRate >> 8; // PWMƵÂʸßλ + broadcast[3] = PWMRate & 0xFF; // PWMƵÂʵÍλ + broadcast[4] = 0xFF; // Ìî³ä0xFF + broadcast[5] = 0xFF; // Ìî³ä0xFF + CheckValue = getModbusCRC16(broadcast, 6); + broadcast[6] = CheckValue & 0xFF; + broadcast[7] = CheckValue >> 8; + + for(idx = 0; idx < 3; idx++) + { + xSemaphoreTake(xSemaphoreUart, portMAX_DELAY); + GPIO_WritePinOutput(PORT_B, GPIO_2, GPIO_HIGH); // À­¸ßPTB2·¢ËÍÊý¾Ý + + for(i = 0; i < 8; i++) + { + UART_SendByte(UART1_ID, broadcast[i]); + } + + while(RESET == UART_GetLineStatus(UART1_ID, UART_LINESTA_TEMT)); // µÈ´ýÈ«²¿Êý¾Ý·¢ËÍÍê³É + GPIO_WritePinOutput(PORT_B, GPIO_2, GPIO_LOW); // À­µÍPTB2½ÓÊÕÊý¾Ý + xSemaphoreGive(xSemaphoreUart); + + vTaskDelay(60); + } + } + vTaskDelay(Delay_S*1000 - 400); // ÑÓʱʱ¼ä¼õÈ¥¹ã²¥´ó¸Åʱ¼ä(6*60 + 40)ms + + xLastWakeTime = xTaskGetTickCount(); + + UART_ResetRxFifo(UART1_ID); // ÖØÖÃRX Fifo + + for( ;; ) + { + for(idx = 1; idx <= 26;) + { + // Èç¹û²É¼¯3´ÎÒÔÉϲɼ¯Í·Ã»½ÓÉ豸£¬²»½øÐвɼ¯ + if((times >= 3) && (((bSample >> idx) & 0x1) == 0)) + { + idx++; + vTaskDelay(60); + continue; + } + + // ·¢ËͱéÀú±àºÅ + query_dev[0] = idx; + query_dev[6] = DataCrc[idx-1] >> 8; + query_dev[7] = DataCrc[idx-1] & 0xFF; + + xSemaphoreTake(xSemaphoreUart, portMAX_DELAY); + GPIO_WritePinOutput(PORT_B, GPIO_2, GPIO_HIGH); // À­¸ßPTB2·¢ËÍÊý¾Ý + + for(i = 0; i < 8; i++) + { + UART_SendByte(UART1_ID, query_dev[i]); + } + + while(RESET == UART_GetLineStatus(UART1_ID, UART_LINESTA_TEMT)); // µÈ´ýÈ«²¿Êý¾Ý·¢ËÍÍê³É + GPIO_WritePinOutput(PORT_B, GPIO_2, GPIO_LOW); // À­µÍPTB2½ÓÊÕÊý¾Ý + xSemaphoreGive(xSemaphoreUart); + + if(xQueueReceive(xGatherQueue1, query_data, /*portMAX_DELAY*/60) == pdPASS) // µÈ´ý½ÓÊÕ£¬×èÈûʱ¼ä60ms + { + if(query_data[0] == query_dev[0]) + { + CheckValue = (query_data[12]) | (query_data[13] << 8); + if(getModbusCRC16(query_data, 12) == CheckValue) + { + // д·¢Ë͵ĶÓÁÐ + gatherdata.id = idx; + gatherdata.current = (query_data[3] << 8) | (query_data[4]); + gatherdata.voltage = (query_data[5] << 8) | (query_data[6]); + gatherdata.temperature = Temp_Now; //(query_data[7] << 8) | (query_data[8]); + + if((times < 3) && (((bSample >> idx) & 0x1) == 0)) // ÅжÏǰÈý´ÎµÄµçÁ÷Öµ + { + if((idx == 1) && (gatherdata.voltage < 0xFDE8)) // ½«²É¼¯Í·1µÄµçѹÉèÖÃΪµ±Ç°µçѹ + CurrVoltage = gatherdata.voltage; + + if((gatherdata.current >= 0x1F40)|| (gatherdata.current == 0x0))// ÈôΪÂú³Ì»ò0ÔòÅжÏΪû½ÓÈëÉ豸 + { + #if 0 + idx++; //ÅжϿÕÔØ£¬Õâ¸ö´Ó»ú¾Í²»¸ø·þÎñÆ÷Éϱ¨Êý¾ÝÁË£¬½øÐÐÏÂÒ»¸ö + bError = 0; + + vTaskDelay(60); + continue; + #else + instNotConn = 1;//ÅжÏΪ¿ÕÔØ¸ø·þÎñÆ÷´«Öµ£¬ + #endif + } + else + { + bSample |= (1 << idx);//±£´æÕâÒ»×éÀïÄĸö´Ó»úÊÇ¿ÉÒÔÕý³£Í¨ÐÅÇÒ¿ÉÒÔ¶Áµ½Õý³£ÖµµÄ + } + } + + if(instNotConn) gatherdata.current = 0xffff;//ǰ¶ÎÅжϿÕÔØ£¬Ã»½ÓÈëÉ豸 + else gatherdata.current = (gatherdata.current >= 0x1F40)? 0 : gatherdata.current; + + gatherdata.voltage = (gatherdata.voltage >= 0xFDE8)? 0 : gatherdata.voltage; + + if(idx == 1) + CurrVoltage = gatherdata.voltage; + else + gatherdata.voltage = CurrVoltage; // ³ýÁ˲ɼ¯Í·1£¬ÆäËû²É¼¯Í·²»²É¼¯µçѹ + + + xQueueSendToBack(xSendQueue, &gatherdata, portMAX_DELAY); + + if(bBuzzer && !instNotConn) // ÊÇ·ñÆôÓ÷äÃùÆ÷±¨¾¯ Èç¹û°´Á˹رշäÃùÆ÷£¬¾Í²»½øÈëÕâ¸öÅÐ¶Ï ¿ÕÔØµÄʱºòÖµ²»¶Ô£¬²»½øÐб¨¾¯ + { + if((gatherdata.current < MinCurrent) || (gatherdata.current > MaxCurrent)) // ¸ù¾ÝÖµ¶Ô±È£¬½øÈë·äÃùÆ÷±¨¾¯£» + { + GPIO_WritePinOutput(PORT_E, GPIO_7, GPIO_HIGH); + } + } + + idx++; + bError = 0; + re_times = 0; + instNotConn = 0;//¿ÕÔØÅжϱêÖ¾Çå0 + } + else + { + bError = 1; // Êý¾Ý³ö´í + } + } + else + { + UART_ResetRxFifo(UART1_ID); // ÖØÖÃRX Fifo + bError = 1; // Êý¾Ý³ö´í + } + } + else // ÎÞÏìÓ¦ + { + bError = 1; + } + + if(bError) // ³ö´íÈý´Î¾Í½øÐÐÏÂÒ»¸ö + { + bError = 0; + re_times++; + if(re_times >= 3) + { + re_times = 0; + idx++; + } + } + + vTaskDelay(60); + } + + if(xSemaphoreTake(xStopSemaphore1, 0) == pdTRUE) // ½ÓÊÕµ½Í£Ö¹ + { + ulTaskNotifyTake(pdTRUE, portMAX_DELAY); // µÈ´ý½ÓÊղɼ¯Í¨µÀ¶þµÄ½áÊøÍ¨Öª + // ¿ØÖƼ̵çÆ÷¶Ïµç + Control_ElectricRelay(0); + GPIO_WritePinOutput(PORT_A, GPIO_2, GPIO_LOW); + + vTaskSuspend(NULL); + GPIO_WritePinOutput(PORT_A, GPIO_2, GPIO_HIGH); + vTaskDelay(Delay_S*1000); + xLastWakeTime = xTaskGetTickCount(); + + continue; + } + + vTaskDelayUntil(&xLastWakeTime, 5000); // ¼ä¸ô5s²É¼¯Ò»´Î + + if(times < 3) + times++; + } +} + +/********* ²É¼¯µÚ¶þͨµÀµçѹµçÁ÷ζȵÄÊý¾Ý *********/ +static void queueGatherTask2(void *params) +{ +// unsigned long ulReceivedValue; + + /* Casting params to void because it is unused */ + (void)params; + + TickType_t xLastWakeTime; + uint8_t idx = 0; + uint8_t i = 0; + Dataformat_t gatherdata; + uint8_t query_dev[8] = {0x01, 0x03, 0x00, 0x01, 0x00, 0x03, 0x54, 0x0B}; // 0x01ΪID£¬0x03Ϊ¶ÁÈ¡±£³Ö¼Ä´æÆ÷£¬0x00 0x01Ϊ²éѯÊý¾ÝµØÖ·£¬0x00 0x03Ϊ²éѯµØÖ·µÄ·¶Î§£¬0x54 0x0BΪCRC16УÑéÂë + uint8_t broadcast[8] = {0xFF, 0x10}; // 0xFFΪ¹ã²¥£¬0x10ΪдÈë¶à¼Ä´æÆ÷ + uint8_t query_data[14]; + uint16_t CheckValue; + uint8_t re_times = 0; + uint8_t bError = 0; + uint32_t bSample = 0; + uint8_t times = 0; + uint8_t instNotConn = 0;//ÅжϿÕÔØºó£¬ºóÐø´¦ÀíʹÓñê־λ + + vTaskSuspend(NULL); + + if(MinCurrent < MaxCurrent) // ͨ¹ý¹ã²¥½«×î´ó×îСµçÁ÷·¢Ë͸ø²É¼¯¶Ë + { + broadcast[2] = MinCurrent >> 8; // ×îСµçÁ÷¸ßλ + broadcast[3] = MinCurrent & 0xFF; // ×îСµçÁ÷µÍλ + broadcast[4] = MaxCurrent >> 8; // ×î´óµçÁ÷¸ßλ + broadcast[5] = MaxCurrent & 0xFF; // ×î´óµçÁ÷µÍλ + CheckValue = getModbusCRC16(broadcast, 6); + broadcast[6] = CheckValue & 0xFF; + broadcast[7] = CheckValue >> 8; + + for(idx = 0; idx < 3; idx++) + { + xSemaphoreTake(xSemaphoreUart, portMAX_DELAY); + GPIO_WritePinOutput(PORT_B, GPIO_3, GPIO_HIGH); // À­¸ßPTB3·¢ËÍÊý¾Ý + + for(i = 0; i < 8; i++) + { + UART_SendByte(UART2_ID, broadcast[i]); + } + + while(RESET == UART_GetLineStatus(UART2_ID, UART_LINESTA_TEMT)); // µÈ´ýÈ«²¿Êý¾Ý·¢ËÍÍê³É + GPIO_WritePinOutput(PORT_B, GPIO_3, GPIO_LOW); // À­µÍPTB3½ÓÊÕÊý¾Ý + xSemaphoreGive(xSemaphoreUart); + + vTaskDelay(60); + } + } + + if(PWMRate > 0) // ͨ¹ý¹ã²¥½«PWMƵÂÊ·¢Ë͸ø²É¼¯¶Ë + { + broadcast[1] = 0x06; + broadcast[2] = PWMRate >> 8; // PWMƵÂʸßλ + broadcast[3] = PWMRate & 0xFF; // PWMƵÂʵÍλ + broadcast[4] = 0xFF; // Ìî³ä0xFF + broadcast[5] = 0xFF; // Ìî³ä0xFF + CheckValue = getModbusCRC16(broadcast, 6); + broadcast[6] = CheckValue & 0xFF; + broadcast[7] = CheckValue >> 8; + + for(idx = 0; idx < 3; idx++) + { + xSemaphoreTake(xSemaphoreUart, portMAX_DELAY); + GPIO_WritePinOutput(PORT_B, GPIO_3, GPIO_HIGH); // À­¸ßPTB3·¢ËÍÊý¾Ý + + for(i = 0; i < 8; i++) + { + UART_SendByte(UART2_ID, broadcast[i]); + } + + while(RESET == UART_GetLineStatus(UART2_ID, UART_LINESTA_TEMT)); // µÈ´ýÈ«²¿Êý¾Ý·¢ËÍÍê³É + GPIO_WritePinOutput(PORT_B, GPIO_3, GPIO_LOW); // À­µÍPTB3½ÓÊÕÊý¾Ý + xSemaphoreGive(xSemaphoreUart); + + vTaskDelay(60); + } + } + vTaskDelay(Delay_S*1000 - 400); // ÑÓʱʱ¼ä¼õÈ¥¹ã²¥´ó¸Åʱ¼ä(6*60 + 40)ms + + xLastWakeTime = xTaskGetTickCount(); + + UART_ResetRxFifo(UART2_ID); // ÖØÖÃRX Fifo + + for( ;; ) + { + for(idx = 27; idx <= 52;) + { + // Èç¹û²É¼¯3´ÎÒÔÉϲɼ¯Í·Ã»½ÓÉ豸£¬²»½øÐвɼ¯ + if((times >= 3) && (((bSample >> (idx-26)) & 0x1) == 0)) + { + idx++; + vTaskDelay(60); + continue; + } + + // ·¢ËͱéÀú±àºÅ + query_dev[0] = idx; + query_dev[6] = DataCrc[idx-1] >> 8; + query_dev[7] = DataCrc[idx-1] & 0xFF; + + xSemaphoreTake(xSemaphoreUart, portMAX_DELAY); + GPIO_WritePinOutput(PORT_B, GPIO_3, GPIO_HIGH); // À­¸ßPTB3·¢ËÍÊý¾Ý + + for(i = 0; i < 8; i++) + { + UART_SendByte(UART2_ID, query_dev[i]); + } + + while(RESET == UART_GetLineStatus(UART2_ID, UART_LINESTA_TEMT)); // µÈ´ýÊý¾ÝÈ«²¿·¢ËÍÍê³É + GPIO_WritePinOutput(PORT_B, GPIO_3, GPIO_LOW); // À­µÍPTB3½ÓÊÕÊý¾Ý + xSemaphoreGive(xSemaphoreUart); + + if(xQueueReceive(xGatherQueue2, query_data, /*portMAX_DELAY*/60) == pdPASS) // µÈ´ý½ÓÊÕ£¬×èÈûʱ¼ä60ms + { + if(query_data[0] == query_dev[0]) + { + CheckValue = (query_data[12]) | (query_data[13] << 8); + if(getModbusCRC16(query_data, 12) == CheckValue) + { + // д·¢Ë͵½·þÎñÆ÷µÄ¶ÓÁÐ + gatherdata.id = idx; + gatherdata.current = (query_data[3] << 8) | (query_data[4]); + gatherdata.voltage = (query_data[5] << 8) | (query_data[6]); + gatherdata.temperature = Temp_Now; //(query_data[7] << 8) | (query_data[8]);; + + if((times < 3) && (((bSample >> (idx-26)) & 0x1) == 0)) // ÅжÏǰÈý´ÎµÄµçÁ÷Öµ + { + if((gatherdata.current >= 0x1F40)|| (gatherdata.current == 0x0))// ÈôΪÂú³Ì»ò0ÔòÅжÏΪû½ÓÈëÉ豸 + { + #if 0 + idx++; + bError = 0; + vTaskDelay(60); + continue; + #else + instNotConn = 1;//ÅжÏΪ¿ÕÔØ¸ø·þÎñÆ÷´«Öµ£¬ + #endif + } + else + { + bSample |= (1 << (idx-26)); + } + } + + if(instNotConn) gatherdata.current = 0xffff;//ǰ¶ÎÅжϿÕÔØ£¬Ã»½ÓÈëÉ豸 + else gatherdata.current = (gatherdata.current >= 0x1F40)? 0 : gatherdata.current; + + gatherdata.voltage = CurrVoltage; // ³ýÁ˲ɼ¯Í·1£¬ÆäËû²É¼¯Í·²»²É¼¯µçѹ + + xQueueSendToBack(xSendQueue, &gatherdata, portMAX_DELAY); + + if(bBuzzer && !instNotConn) // ÊÇ·ñÆôÓ÷äÃùÆ÷±¨¾¯ + { + if((gatherdata.current < MinCurrent) || (gatherdata.current > MaxCurrent)) // ½øÈë·äÃùÆ÷±¨¾¯ + { + GPIO_WritePinOutput(PORT_E, GPIO_7, GPIO_HIGH); + } + } + + idx++; + bError = 0; + re_times = 0; + instNotConn = 0;//¿ÕÔØÅжϱêÖ¾Çå0 + } + else + { + bError = 1; // Êý¾Ý³ö´í + } + } + else + { + UART_ResetRxFifo(UART2_ID); // ÖØÖÃRX Fifo + bError = 1; // Êý¾Ý³ö´í + } + } + else // ÎÞÏìÓ¦ + { + bError = 1; + } + + if(bError) // ³ö´íÈý´Î¾Í½øÐÐÏÂÒ»¸ö + { + bError = 0; + re_times++; + if(re_times >= 3) + { + re_times = 0; + idx++; + } + } + } + + if(xSemaphoreTake(xStopSemaphore2, 0) == pdTRUE) // ½ÓÊÕµ½Í£Ö¹ + { + xTaskNotifyGive(Gather_Handler1); // ֪ͨ²É¼¯Í¨µÀÒ» + + vTaskSuspend(NULL); + vTaskDelay(Delay_S*1000); + xLastWakeTime = xTaskGetTickCount(); + + continue; + } + + vTaskDelayUntil(&xLastWakeTime, 5000); // ¼ä¸ô5s²É¼¯Ò»´Î + + if(times < 3) + times++; + } +} + +/*********** ½«²É¼¯µ½µÄÊý¾Ý·¢Ë͵½·þÎñÆ÷ ***********/ +static void queueSendTask(void *parames) +{ + Dataformat_t senddata; + + for( ;; ) + { + xQueueReceive(xSendQueue, &senddata, portMAX_DELAY); // ¶ÁȡҪ·¢ËÍÊý¾ÝµÄ¶ÓÁÐ + + xSemaphoreTake(xSemaphoreTx, portMAX_DELAY); + sprintf((char *)uart0TxBuff, "$CMSGM,<"__DEVICES_ID__">,<%02d>,<%d>,<%d>,<%d>,$#", senddata.id, senddata.current, senddata.voltage, senddata.temperature); + WIFI_Send_Data(); + xSemaphoreGive(xSemaphoreTx); + } +} + +/*********** ´¦ÀíÖжϺÍÈí¼þ¶¨Ê±Æ÷ÏÂÎĵÄÈÎÎñ ***********/ +static void queueUserDaemonTask(void *parames) +{ + uint8_t idx = 0; + uint8_t i; + uint8_t broadcast[8] = {0xFF, 0x10}; // 0xFFΪ¹ã²¥£¬0x10ΪдÈë¶à¼Ä´æÆ÷ + uint16_t CheckValue; + + for( ;; ) + { + xSemaphoreTake(UserDaemon.xUserSemaphore, portMAX_DELAY); + + if(UserDaemon.Open_PWM) + { + UserDaemon.Open_PWM = 0; + + // ͨ¹ý¹ã²¥½«PWMƵÂÊ·¢Ë͸ø²É¼¯¶Ë + broadcast[1] = 0x06; + broadcast[2] = 100 >> 8; // PWMƵÂʸßλ + broadcast[3] = 100 & 0xFF; // PWMƵÂʵÍλ + broadcast[4] = 0xFF; // Ìî³ä0xFF + broadcast[5] = 0xFF; // Ìî³ä0xFF + CheckValue = getModbusCRC16(broadcast, 6); + broadcast[6] = CheckValue & 0xFF; + broadcast[7] = CheckValue >> 8; + + for(idx = 0; idx < 3; idx++) + { + // µÚһ·²É¼¯¶Ë + GPIO_WritePinOutput(PORT_B, GPIO_2, GPIO_HIGH); // À­¸ßPTB2·¢ËÍÊý¾Ý + + for(i = 0; i < 8; i++) + { + UART_SendByte(UART1_ID, broadcast[i]); + } + + while(RESET == UART_GetLineStatus(UART1_ID, UART_LINESTA_TEMT)); // µÈ´ýÈ«²¿Êý¾Ý·¢ËÍÍê³É + GPIO_WritePinOutput(PORT_B, GPIO_2, GPIO_LOW); // À­µÍPTB2½ÓÊÕÊý¾Ý + + // µÚ¶þ·²É¼¯¶Ë + GPIO_WritePinOutput(PORT_B, GPIO_3, GPIO_HIGH); // À­¸ßPTB3·¢ËÍÊý¾Ý + + for(i = 0; i < 8; i++) + { + UART_SendByte(UART2_ID, broadcast[i]); + } + + while(RESET == UART_GetLineStatus(UART2_ID, UART_LINESTA_TEMT)); // µÈ´ýÈ«²¿Êý¾Ý·¢ËÍÍê³É + GPIO_WritePinOutput(PORT_B, GPIO_3, GPIO_LOW); // À­µÍPTB3½ÓÊÕÊý¾Ý + + vTaskDelay(60); + } + } + } +} + +void Tasks_Create(void) +{ + /* ´´½¨Wifi£¬½ÓÊÕ·þÎñÆ÷ÃüÁ ²É¼¯£¬·¢Ë͸ø·þÎñÆ÷¡¢·¢ËÍÐÄÌø°ü¡¢Óû§ÊØ»¤½ø³ÌµÄÈÎÎñ */ + xTaskCreate(queueWifiTask, "Wifi", configMINIMAL_STACK_SIZE, NULL, 2, NULL); + xTaskCreate(queueCommandTask, "Command", configMINIMAL_STACK_SIZE, NULL, 1, &Command_Handler); + xTaskCreate(queueGatherTask1, "Gather1", configMINIMAL_STACK_SIZE+128, NULL, 1, &Gather_Handler1); + xTaskCreate(queueGatherTask2, "Gather2", configMINIMAL_STACK_SIZE+128, NULL, 1, &Gather_Handler2); + xTaskCreate(queueSendTask, "Senddata", configMINIMAL_STACK_SIZE, NULL, 1, &Send_Handler); + xTaskCreate(queueHeartBeatTask, "Heartbeat", configMINIMAL_STACK_SIZE, NULL, 1, &HeartBeat_Handler); + xTaskCreate(queueUserDaemonTask, "UserDaemon", configMINIMAL_STACK_SIZE, NULL, 1, &UserDaemon_Handler); +} + diff --git a/Aging_app/freertos/src/uart_transfer.c b/Aging_app/freertos/src/uart_transfer.c new file mode 100644 index 0000000..fb8f831 --- /dev/null +++ b/Aging_app/freertos/src/uart_transfer.c @@ -0,0 +1,228 @@ +#include "uart_transfer.h" + + +uint8_t i = 0; + +uint8_t recv_mess[RECEIVE_DATA_LEN] = {0}; +//extern char *pr; +extern QueueHandle_t xRecvQueue; + +void uart0_cbf() +{ + uint8_t ch; + + STIM_Disable(STIM_0); + + /* receive data */ + ch = UART_ReceiveByte(UART0_ID); + if (i < RECEIVE_DATA_LEN) + recv_mess[i++] = ch; + + STIM_Enable(STIM_0); +} + +static void STIM0_IntCallBack(void) +{ + /* toggle*/ + STIM_Disable(STIM_0); + //pr = (char *)recv_mess; + // д¶ÓÁÐ + xQueueSendToBackFromISR(xRecvQueue, recv_mess, pdFALSE); + i = 0; + memset(recv_mess, 0, RECEIVE_DATA_LEN); +// GPIO_TogglePinOutput(PORT_B, GPIO_5); +} + +/* STIM configuration */ +const STIM_Config_t stimConfig0 = +{ + .workMode = STIM_FREE_COUNT, + .compareValue = 40000, /*counter clock is 40M, compare value =40000, period = 1ms*/ + .countResetMode = STIM_INCREASE_FROM_0, + .clockSource = STIM_FUNCTION_CLOCK, +}; + +void STIM0_Init(void) +{ + /* Configure STIM function clock*/ + CLK_ModuleSrc(CLK_STIM, CLK_SRC_OSC40M); + + /* Enable STIM module */ + SYSCTRL_EnableModule(SYSCTRL_STIM); + + /* Init STIM_0*/ + STIM_Init(STIM_0, &stimConfig0); +} + +void Uart0_Init(void) +{ + UART_Config_t tUartCfgStruct = + { + 115200, /* buard rate */ + UART_DATABITS_8, /* data size */ + UART_PARITY_NONE, /* parity */ + UART_STOPBITS_1, /* stop bit */ + DISABLE, /* flow control */ + 40000000 /* function clock freq */ + }; + + /* choose osc clock as function clock of uart0 */ + CLK_ModuleSrc(CLK_UART0, CLK_SRC_OSC40M); + /* set divide ratio of uart0's function clock*/ + CLK_SetClkDivider(CLK_UART0, CLK_DIV_1); + /* enable clock for uart0 */ + SYSCTRL_EnableModule(SYSCTRL_UART0); + + /*When UART re-open after close, need to check and clear busy status*/ + while(ERR == UART_WaitBusyClear(UART0_ID, 7000)) + { + (void)UART_ReceiveByte(UART0_ID); + } + + /* initiate uart0 */ + UART_Init(UART0_ID, &tUartCfgStruct); + + /* fifo config */ + const UART_FIFOConfig_t fifoCfg = + { + ENABLE, ENABLE, ENABLE, UART_TX_FIFO_HALF, UART_RX_FIFO_CHAR_1 + }; + + UART_FIFOConfig(UART0_ID, &fifoCfg); + + /* choose osc clock as function clock of portd */ + CLK_ModuleSrc(CLK_PORTB, CLK_SRC_OSC40M); + /* enable clock for portd */ + SYSCTRL_EnableModule(SYSCTRL_PORTB); + + /* ptb1: , uart tx */ + PORT_PinmuxConfig(PORT_B, GPIO_1, PTB1_UART0_TX); + /* ptb0: uart rx */ + PORT_PinmuxConfig(PORT_B, GPIO_0, PTB0_UART0_RX); + + + /* callback function */ + UART_InstallCallBackFunc(UART0_ID, UART_INT_RBFI, uart0_cbf); + + /* enable received data available interrupt */ + UART_IntMask(UART0_ID, UART_INT_RBFI, UNMASK); + + /* enable IRQ */ + NVIC_EnableIRQ(UART0_IRQn); + + STIM0_Init(); + /* Install interrupt callback function */ + STIM_InstallCallBackFunc(STIM_0,STIM_INT,STIM0_IntCallBack); + /* Enable STIM_0 interrupt*/ + STIM_IntCmd(STIM_0, ENABLE); + + /*Enable STIM*/ + //STIM_Enable(STIM_0); + /* Enable STIM NVIC IRQ*/ + NVIC_EnableIRQ(STIM_IRQn); +} + +void Uart1_Init(void) +{ + UART_Config_t tUartCfgStruct = + { + 9600, /* buard rate */ + UART_DATABITS_8, /* data size */ + UART_PARITY_NONE, /* parity */ + UART_STOPBITS_1, /* stop bit */ + DISABLE, /* flow control */ + 40000000 /* function clock freq */ + }; + + /* choose osc clock as function clock of uart0 */ + CLK_ModuleSrc(CLK_UART1, CLK_SRC_OSC40M); + /* set divide ratio of uart0's function clock*/ + CLK_SetClkDivider(CLK_UART1, CLK_DIV_1); + /* enable clock for uart0 */ + SYSCTRL_EnableModule(SYSCTRL_UART1); + + /*When UART re-open after close, need to check and clear busy status*/ + while(SUCC !=UART_WaitBusyClear(UART1_ID, 7000)) + { + (void)UART_ReceiveByte(UART1_ID); + } + + /* initiate uart1 */ + UART_Init(UART1_ID, &tUartCfgStruct); + + /* fifo config */ + const UART_FIFOConfig_t fifoCfg = + { + ENABLE, ENABLE, ENABLE, UART_TX_FIFO_HALF, UART_RX_FIFO_LESS_2 + }; + + UART_FIFOConfig(UART1_ID, &fifoCfg); + + /* choose osc clock as function clock of portd */ + CLK_ModuleSrc(CLK_PORTC, CLK_SRC_OSC40M); + /* enable clock for portd */ + SYSCTRL_EnableModule(SYSCTRL_PORTC); + + /* ptc9: , uart tx */ + PORT_PinmuxConfig(PORT_C, GPIO_9, PTC9_UART1_TX); + /* ptc8: uart rx */ + PORT_PinmuxConfig(PORT_C, GPIO_8, PTC8_UART1_RX); + + /* rs485 re/de */ + PORT_PinmuxConfig(PORT_B, GPIO_2, PTB2_GPIO); + GPIO_SetPinDir(PORT_B, GPIO_2, GPIO_OUTPUT); + GPIO_SetPinOutput(PORT_B, GPIO_2); +} + +void Uart2_Init(void) +{ + UART_Config_t tUartCfgStruct = + { + 9600, /* buard rate */ + UART_DATABITS_8, /* data size */ + UART_PARITY_NONE, /* parity */ + UART_STOPBITS_1, /* stop bit */ + DISABLE, /* flow control */ + 40000000 /* function clock freq */ + }; + + /* choose osc clock as function clock of uart0 */ + CLK_ModuleSrc(CLK_UART2, CLK_SRC_OSC40M); + /* set divide ratio of uart2's function clock*/ + CLK_SetClkDivider(CLK_UART2, CLK_DIV_1); + /* enable clock for uart2 */ + SYSCTRL_EnableModule(SYSCTRL_UART2); + + /*When UART re-open after close, need to check and clear busy status*/ + while(SUCC !=UART_WaitBusyClear(UART2_ID, 7000)) + { + (void)UART_ReceiveByte(UART2_ID); + } + + /* initiate uart2 */ + UART_Init(UART2_ID, &tUartCfgStruct); + + /* fifo config */ + const UART_FIFOConfig_t fifoCfg = + { + ENABLE, ENABLE, ENABLE, UART_TX_FIFO_HALF, UART_RX_FIFO_LESS_2 + }; + + UART_FIFOConfig(UART2_ID, &fifoCfg); + + /* choose osc clock as function clock of portd */ + CLK_ModuleSrc(CLK_PORTD, CLK_SRC_OSC40M); + /* enable clock for portd */ + SYSCTRL_EnableModule(SYSCTRL_PORTD); + + /* ptd7: , uart tx */ + PORT_PinmuxConfig(PORT_D, GPIO_7, PTD7_UART2_TX); + /* ptcd6: uart rx */ + PORT_PinmuxConfig(PORT_D, GPIO_6, PTD6_UART2_RX); + + /* rs485 re/de */ + PORT_PinmuxConfig(PORT_B, GPIO_3, PTB3_GPIO); + GPIO_SetPinDir(PORT_B, GPIO_3, GPIO_OUTPUT); + GPIO_SetPinOutput(PORT_B, GPIO_3); +} + diff --git a/Aging_app/freertos/src/wifi_transfer.c b/Aging_app/freertos/src/wifi_transfer.c new file mode 100644 index 0000000..5e19642 --- /dev/null +++ b/Aging_app/freertos/src/wifi_transfer.c @@ -0,0 +1,192 @@ +#include "wifi_transfer.h" + +extern uint8_t uart0TxBuff[]; + +extern uint8_t Wifistep; +extern QueueHandle_t xRecvQueue; + +extern uint32_t Delay_S; // ÑÓʱʱ¼ä +extern uint32_t Work_time; // ͨµçʱ¼ä +extern uint32_t Relax_time; // ¶Ïµçʱ¼ä + +void WIFI_Send_Data(void) +{ + uint8_t idx = 0; + uint8_t total_length; + uint8_t dma_data_len = 0; + //uint32_t cou = 0; + + total_length = strlen((char *)uart0TxBuff); + dma_data_len = total_length / 4 * 4; + + uint8_t times; + uint8_t leave; + + times = dma_data_len / 16; + for(idx = 0; idx < times; idx++) + { + DMA_SetTransferByteNum(DMA_CHANNEL0, 16); + DMA_SetSrcAddr(DMA_CHANNEL0, (uint32_t)uart0TxBuff + idx*16); + DMA_ChannelRequestEnable(DMA_CHANNEL0); + + while (DMA_GetDoneStatus(DMA_CHANNEL0) != SET); + DMA_ClearDoneStatus(DMA_CHANNEL0); + } + + leave = dma_data_len - times*16; + if(leave > 0) + { + DMA_SetTransferByteNum(DMA_CHANNEL0, leave); + DMA_SetSrcAddr(DMA_CHANNEL0, (uint32_t)uart0TxBuff + times*16); + DMA_ChannelRequestEnable(DMA_CHANNEL0); + + while (DMA_GetDoneStatus(DMA_CHANNEL0) != SET); + DMA_ClearDoneStatus(DMA_CHANNEL0); + } + + /* Send remaining data*/ + while(RESET == UART_GetLineStatus(UART0_ID, UART_LINESTA_TEMT)); + for(idx = dma_data_len; idx < total_length; idx++) + { + UART_SendByte(UART0_ID, uart0TxBuff[idx]); + } + + vTaskDelay(60); // ÑÓʱ60ms£¬±ÜÃâ͸´«Êý¾ÝÁ¬°ü +} + +void WIFI_Connection(void) +{ + char recv_mess[RECEIVE_DATA_LEN] = {0}; + + switch(Wifistep) + { + case 1: + strcpy((char *)uart0TxBuff, "AT+CWMODE=1\r\n"); // ÉèÖÃSTAģʽ + break; + case 2: + strcpy((char *)uart0TxBuff, "AT+CWJAP=\"zjkj1688\",\"61888888\"\r\n"); // Á¬½ÓWifi + break; + case 3: + strcpy((char *)uart0TxBuff, "AT+CIFSR\r\n"); // »ñÈ¡IPµØÖ· + break; + case 4: + strcpy((char *)uart0TxBuff, "AT+CIPSTART=\"TCP\",\"192.168.1.25\",8080\r\n"); // Á¬½Ó·þÎñÆ÷ // 192.168.2.21 + //strcpy((char *)uart0TxBuff, "AT+CIPSTART=\"TCP\",\"47.122.26.54\",9190\r\n"); // Á¬½Ó·þÎñÆ÷ + //strcpy((char *)uart0TxBuff, "AT+CIPSTART=\"TCP\",\"192.168.2.30\",9190\r\n"); // Á¬½Ó×Ô¼ºµçÄÔ·þÎñÆ÷ + break; + case 5: + strcpy((char *)uart0TxBuff, "AT+CIPMODE=1\r\n"); // ʹÄÜÊý¾Ý͸´« + break; + case 6: + strcpy((char *)uart0TxBuff, "AT+CIPSEND\r\n"); // ·¢ËÍÊý¾Ý + break; + case 7: + strcpy((char *)uart0TxBuff, "$CMSGI,<"__DEVICES_ID__">,$#"); // ·¢ËÍÀÏ»¯³µ±àºÅ + break; + default: + break; + } + + WIFI_Send_Data(); + + if(xQueueReceive(xRecvQueue, recv_mess, 2000) == pdFAIL) + { + if(Wifistep == 1) // °´Ï¸´Î»°´¼üºóÏÈÍ˳ö͸´« + { + strcpy((char *)uart0TxBuff, "+++"); + WIFI_Send_Data(); + vTaskDelay(500); + } + + if(Wifistep == 7) // Éϱ¨ÀÏ»¯³µ±àºÅ5sÉϱ¨Ò»´Î + vTaskDelay(3000); + + return; + } + + switch(Wifistep) + { + case 1: + if((strstr(recv_mess, "+CIFSR:STAIP,") && !strstr(recv_mess, "0.0.0.0")) || strstr(recv_mess, "OK")) + { + GPIO_WritePinOutput(PORT_C, GPIO_6, GPIO_HIGH); + Wifistep++; + } + break; + case 2: + if(strstr(recv_mess, "CONNECT") || strstr(recv_mess, "ALRE")) + { + GPIO_WritePinOutput(PORT_A, GPIO_3, GPIO_HIGH); + Wifistep++; + } + break; + case 3: + strcpy((char *)uart0TxBuff, "+++"); + WIFI_Send_Data(); + vTaskDelay(500); + if(strstr(recv_mess, "OK")) + Wifistep++; + break; + case 4: + if(strstr(recv_mess, ">")) + Wifistep++; + break; + case 5: + if(strstr(recv_mess, "OK")) + Wifistep++; + break; + case 6: + if(strstr(recv_mess, ">")) + Wifistep++; + break; + case 7: + sscanf(recv_mess, "$SMSGD,<"__DEVICES_ID__">,<%d>,<%d>,<%d>,$#", &Delay_S, &Work_time, &Relax_time); + if((Delay_S != 0) && (Work_time != 0) && (Relax_time != 0)) + Wifistep++;; + break; + default: + break; + } + vTaskDelay(60); +} + +void WIFI_Connection_Test(void) +{ + char recv_mess[RECEIVE_DATA_LEN] = {0}; + + BaseType_t res; + res = xQueueReceive(xRecvQueue, recv_mess, 2000); + + if (res == pdFAIL) // pdFAIL pdPASS + { + if(!strcmp(recv_mess, "1\r\n")) + { + strcpy((char *)uart0TxBuff, "defg"); + //uart0TxBuff[1] = 'C'; + WIFI_Send_Data(); + + } + else + { + strcpy((char *)uart0TxBuff, "abcd"); + //uart0TxBuff[1] = 'C'; + WIFI_Send_Data(); + } + } + else if (res == pdPASS) + { + strcpy((char *)uart0TxBuff, "recv_mess"); + //uart0TxBuff[1] = 'C'; + WIFI_Send_Data(); + } + else if (res == errQUEUE_EMPTY) + { + strcpy((char *)uart0TxBuff, "errQUEUE_EMPTY"); + //uart0TxBuff[1] = 'C'; + WIFI_Send_Data(); + } + + + + vTaskDelay(60); +} diff --git a/Platform/Core/arm_compat.h b/Platform/Core/arm_compat.h new file mode 100644 index 0000000..d5b3ba3 --- /dev/null +++ b/Platform/Core/arm_compat.h @@ -0,0 +1,190 @@ +/* Modifications copyright (C) 2020 Arm Limited (or its affiliates). All rights reserved. */ +/* arm_compat.h - Compatibility header for ARM Compiler 5 intrinsics */ +/* Copyright (C) 2016 ARM Limited. All rights reserved. */ + +#ifndef __ARM_COMPAT_H +#define __ARM_COMPAT_H + +#include + +#ifdef __ARM_64BIT_STATE + #error arm_compat.h is not supported when compiling for the A64 instruction set +#else + +#if __ARM_ARCH >= 6 || (__ARM_ARCH == 5 && __ARM_ARCH_ISA_THUMB) +#define __breakpoint(v) __asm__ __volatile__ ("bkpt %0" : : "i"(v) ) +#else /* __ARM_ARCH < 6 && (__ARM_ARCH != 5 || !__ARM_ARCH_ISA_THUMB) */ +static __inline__ void __attribute__((unavailable( + "intrinsic not supported for this architecture"))) __breakpoint(int val); +#endif + +#define __current_pc() \ + __extension__({ \ + register unsigned int pc __asm__("pc"); \ + __asm__ __volatile__("" : "=r"(pc)); \ + pc; \ + }) + +#define __current_sp() \ + __extension__({ \ + register unsigned int sp __asm__("sp"); \ + __asm__ __volatile__("" : "=r"(sp)); \ + sp; \ + }) + +#if (defined(__ARM_ARCH_PROFILE) && __ARM_ARCH_PROFILE == 'M' && \ + __ARM_ARCH == 6) || __ARM_ARCH_8M_BASE__ +static __inline__ unsigned int __attribute__((unavailable( + "intrinsic not supported for this architecture"))) __disable_fiq(void); +#else // (!defined(__ARM_ARCH_PROFILE) || __ARM_ARCH_PROFILE != 'M' || + // __ARM_ARCH != 6) && !__ARM_ARCH_8M_BASE__ +static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__)) +__disable_fiq(void) { + unsigned int cpsr; +#if defined(__ARM_ARCH_PROFILE) && __ARM_ARCH_PROFILE == 'M' + __asm__ __volatile__("mrs %[cpsr], faultmask\n" + "cpsid f\n" + : [cpsr] "=r"(cpsr)); + return cpsr & 0x1; +#elif __ARM_ARCH >= 6 /* !defined(__ARM_ARCH_PROFILE) || __ARM_ARCH_PROFILE != 'M' */ + __asm__ __volatile__("mrs %[cpsr], cpsr\n" + "cpsid f\n" + : [cpsr] "=r"(cpsr)); + return cpsr & 0x40; +#else /* __ARM_ARCH < 6 && !defined(__ARM_ARCH_PROFILE) || __ARM_ARCH_PROFILE != 'M' */ + unsigned int tmp; + __asm__ __volatile__( + "mrs %[cpsr], CPSR\n" + "bic %[tmp], %[cpsr], #0x40\n" + "msr CPSR_c, %[tmp]\n" + : [tmp]"=r"(tmp), [cpsr]"=r"(cpsr)); + return cpsr & 0x40; +#endif +} +#endif + +static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__)) +__disable_irq(void) { + unsigned int cpsr; +#if __ARM_ARCH >= 6 +#if defined(__ARM_ARCH_PROFILE) && __ARM_ARCH_PROFILE == 'M' + __asm__ __volatile__("mrs %[cpsr], primask\n" + "cpsid i\n" + : [cpsr] "=r"(cpsr)); + return cpsr & 0x1; +#else /* !defined(__ARM_ARCH_PROFILE) || __ARM_ARCH_PROFILE != 'M' */ + __asm__ __volatile__("mrs %[cpsr], cpsr\n" + "cpsid i\n" + : [cpsr] "=r"(cpsr)); + return cpsr & 0x80; +#endif +#else /* __ARM_ARCH < 6 */ + unsigned int tmp; + __asm__ __volatile__( + "mrs %[cpsr], CPSR\n" + "bic %[tmp], %[cpsr], #0x80\n" + "msr CPSR_c, %[tmp]\n" + : [tmp]"=r"(tmp), [cpsr]"=r"(cpsr)); + return cpsr & 0x80; +#endif +} + +#if (defined(__ARM_ARCH_PROFILE) && __ARM_ARCH_PROFILE == 'M' && \ + __ARM_ARCH == 6) || __ARM_ARCH_8M_BASE__ +static __inline__ void __attribute__((unavailable( + "intrinsic not supported for this architecture"))) __enable_fiq(void); +#else // (!defined(__ARM_ARCH_PROFILE) || __ARM_ARCH_PROFILE != 'M' || + // __ARM_ARCH != 6) && !__ARM_ARCH_8M_BASE__ +static __inline__ void __attribute__((__always_inline__, __nodebug__)) +__enable_fiq(void) { +#if __ARM_ARCH >= 6 + __asm__ __volatile__("cpsie f"); +#else /* __ARM_ARCH < 6 */ + unsigned int tmp; + __asm__ __volatile__( + "mrs %[tmp], CPSR\n" + "bic %[tmp], %[tmp], #0x40\n" + "msr CPSR_c, %[tmp]\n" + : [tmp]"=r"(tmp)); +#endif +} +#endif + +static __inline__ void __attribute__((__always_inline__, __nodebug__)) +__enable_irq(void) { +#if __ARM_ARCH >= 6 + __asm__ __volatile__("cpsie i"); +#else /* __ARM_ARCH < 6 */ + unsigned int tmp; + __asm__ __volatile__( + "mrs %[tmp], CPSR\n" + "bic %[tmp], %[tmp], #0x80\n" + "msr CPSR_c, %[tmp]\n" + : [tmp]"=r"(tmp)); +#endif +} + +static __inline__ void __attribute__((__always_inline__, __nodebug__)) __force_stores(void) { + __asm__ __volatile__ ("" : : : "memory", "cc"); +} + +static void __attribute__((__always_inline__, __nodebug__)) __memory_changed(void) { + __asm__ __volatile__ ("" : : : "memory", "cc"); +} + +static void __attribute__((__always_inline__, __nodebug__)) __schedule_barrier(void) { + __asm__ __volatile__ ("" : : : "memory", "cc"); +} + +static __inline__ int __attribute__((__always_inline__, __nodebug__)) +__semihost(int val, const void *ptr) { + register int v __asm__("r0") = val; + register const void *p __asm__("r1") = ptr; + __asm__ __volatile__( +#if defined(__thumb__) +#if defined(__ARM_ARCH_PROFILE) && __ARM_ARCH_PROFILE == 'M' + "bkpt 0xab" +#else /* !defined(__ARM_ARCH_PROFILE) || __ARM_ARCH_PROFILE != 'M' */ +#if defined(__USE_HLT_SEMIHOSTING) + ".inst.n 0xbabc" +#else + "svc 0xab" +#endif +#endif +#else /* !defined(__thumb__) */ +#if defined(__USE_HLT_SEMIHOSTING) + ".inst 0xe10f0070" +#else + "svc 0x123456" +#endif +#endif + : "+r"(v), "+r"(p) + : + : "memory", "cc"); + return v; +} + +#if defined(__ARM_FP) +static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__)) +__vfp_status(unsigned int mask, unsigned int flags) { + unsigned int fpscr; + __asm__ __volatile__("vmrs %[fpscr], fpscr" : [fpscr] "=r"(fpscr)); + unsigned int set = mask & flags; + unsigned int clear = mask & ~flags; + unsigned int toggle = ~mask & flags; + fpscr |= set; + fpscr &= ~clear; + fpscr ^= toggle; + __asm__ __volatile__("vmsr fpscr, %[fpscr]" : : [fpscr] "r"(fpscr)); + return fpscr; +} +#else /* !defined(__ARM_FP) */ +static __inline__ unsigned int __attribute__(( + unavailable("intrinsic not supported for targets without floating point"))) +__vfp_status(unsigned int mask, unsigned int flags); +#endif + +#endif /* __ARM_64BIT_STATE */ + +#endif /* __ARM_COMPAT_H */ + diff --git a/Platform/Core/cmsis_armcc.h b/Platform/Core/cmsis_armcc.h new file mode 100644 index 0000000..093d35b --- /dev/null +++ b/Platform/Core/cmsis_armcc.h @@ -0,0 +1,870 @@ +/**************************************************************************//** + * @file cmsis_armcc.h + * @brief CMSIS compiler ARMCC (Arm Compiler 5) header file + * @version V5.0.4 + * @date 10. January 2018 + ******************************************************************************/ +/* + * Copyright (c) 2009-2018 Arm Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * 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 + * + * 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. + */ + +#ifndef __CMSIS_ARMCC_H +#define __CMSIS_ARMCC_H + + +#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 400677) + #error "Please use Arm Compiler Toolchain V4.0.677 or later!" +#endif + +/* CMSIS compiler control architecture macros */ +#if ((defined (__TARGET_ARCH_6_M ) && (__TARGET_ARCH_6_M == 1)) || \ + (defined (__TARGET_ARCH_6S_M ) && (__TARGET_ARCH_6S_M == 1)) ) + #define __ARM_ARCH_6M__ 1 +#endif + +#if (defined (__TARGET_ARCH_7_M ) && (__TARGET_ARCH_7_M == 1)) + #define __ARM_ARCH_7M__ 1 +#endif + +#if (defined (__TARGET_ARCH_7E_M) && (__TARGET_ARCH_7E_M == 1)) + #define __ARM_ARCH_7EM__ 1 +#endif + + /* __ARM_ARCH_8M_BASE__ not applicable */ + /* __ARM_ARCH_8M_MAIN__ not applicable */ + + +/* CMSIS compiler specific defines */ +#ifndef __ASM + #define __ASM __asm +#endif +#ifndef __INLINE + #define __INLINE __inline +#endif +#ifndef __STATIC_INLINE + #define __STATIC_INLINE static __inline +#endif +#ifndef __STATIC_FORCEINLINE + #define __STATIC_FORCEINLINE static __forceinline +#endif +#ifndef __NO_RETURN + #define __NO_RETURN __declspec(noreturn) +#endif +#ifndef __USED + #define __USED __attribute__((used)) +#endif +#ifndef __WEAK + #define __WEAK __attribute__((weak)) +#endif +#ifndef __PACKED + #define __PACKED __attribute__((packed)) +#endif +#ifndef __PACKED_STRUCT + #define __PACKED_STRUCT __packed struct +#endif +#ifndef __PACKED_UNION + #define __PACKED_UNION __packed union +#endif +#ifndef __UNALIGNED_UINT32 /* deprecated */ + #define __UNALIGNED_UINT32(x) (*((__packed uint32_t *)(x))) +#endif +#ifndef __UNALIGNED_UINT16_WRITE + #define __UNALIGNED_UINT16_WRITE(addr, val) ((*((__packed uint16_t *)(addr))) = (val)) +#endif +#ifndef __UNALIGNED_UINT16_READ + #define __UNALIGNED_UINT16_READ(addr) (*((const __packed uint16_t *)(addr))) +#endif +#ifndef __UNALIGNED_UINT32_WRITE + #define __UNALIGNED_UINT32_WRITE(addr, val) ((*((__packed uint32_t *)(addr))) = (val)) +#endif +#ifndef __UNALIGNED_UINT32_READ + #define __UNALIGNED_UINT32_READ(addr) (*((const __packed uint32_t *)(addr))) +#endif +#ifndef __ALIGNED + #define __ALIGNED(x) __attribute__((aligned(x))) +#endif +#ifndef __RESTRICT + #define __RESTRICT __restrict +#endif + +/* ########################### Core Function Access ########################### */ +/** \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions + @{ + */ + +/** + \brief Enable IRQ Interrupts + \details Enables IRQ interrupts by clearing the I-bit in the CPSR. + Can only be executed in Privileged modes. + */ +/* intrinsic void __enable_irq(); */ + + +/** + \brief Disable IRQ Interrupts + \details Disables IRQ interrupts by setting the I-bit in the CPSR. + Can only be executed in Privileged modes. + */ +/* intrinsic void __disable_irq(); */ + +/** + \brief Get Control Register + \details Returns the content of the Control Register. + \return Control Register value + */ +__STATIC_INLINE uint32_t __get_CONTROL(void) +{ + register uint32_t __regControl __ASM("control"); + return(__regControl); +} + + +/** + \brief Set Control Register + \details Writes the given value to the Control Register. + \param [in] control Control Register value to set + */ +__STATIC_INLINE void __set_CONTROL(uint32_t control) +{ + register uint32_t __regControl __ASM("control"); + __regControl = control; +} + + +/** + \brief Get IPSR Register + \details Returns the content of the IPSR Register. + \return IPSR Register value + */ +__STATIC_INLINE uint32_t __get_IPSR(void) +{ + register uint32_t __regIPSR __ASM("ipsr"); + return(__regIPSR); +} + + +/** + \brief Get APSR Register + \details Returns the content of the APSR Register. + \return APSR Register value + */ +__STATIC_INLINE uint32_t __get_APSR(void) +{ + register uint32_t __regAPSR __ASM("apsr"); + return(__regAPSR); +} + + +/** + \brief Get xPSR Register + \details Returns the content of the xPSR Register. + \return xPSR Register value + */ +__STATIC_INLINE uint32_t __get_xPSR(void) +{ + register uint32_t __regXPSR __ASM("xpsr"); + return(__regXPSR); +} + + +/** + \brief Get Process Stack Pointer + \details Returns the current value of the Process Stack Pointer (PSP). + \return PSP Register value + */ +__STATIC_INLINE uint32_t __get_PSP(void) +{ + register uint32_t __regProcessStackPointer __ASM("psp"); + return(__regProcessStackPointer); +} + + +/** + \brief Set Process Stack Pointer + \details Assigns the given value to the Process Stack Pointer (PSP). + \param [in] topOfProcStack Process Stack Pointer value to set + */ +__STATIC_INLINE void __set_PSP(uint32_t topOfProcStack) +{ + register uint32_t __regProcessStackPointer __ASM("psp"); + __regProcessStackPointer = topOfProcStack; +} + + +/** + \brief Get Main Stack Pointer + \details Returns the current value of the Main Stack Pointer (MSP). + \return MSP Register value + */ +__STATIC_INLINE uint32_t __get_MSP(void) +{ + register uint32_t __regMainStackPointer __ASM("msp"); + return(__regMainStackPointer); +} + + +/** + \brief Set Main Stack Pointer + \details Assigns the given value to the Main Stack Pointer (MSP). + \param [in] topOfMainStack Main Stack Pointer value to set + */ +__STATIC_INLINE void __set_MSP(uint32_t topOfMainStack) +{ + register uint32_t __regMainStackPointer __ASM("msp"); + __regMainStackPointer = topOfMainStack; +} + + +/** + \brief Get Priority Mask + \details Returns the current state of the priority mask bit from the Priority Mask Register. + \return Priority Mask value + */ +__STATIC_INLINE uint32_t __get_PRIMASK(void) +{ + register uint32_t __regPriMask __ASM("primask"); + return(__regPriMask); +} + + +/** + \brief Set Priority Mask + \details Assigns the given value to the Priority Mask Register. + \param [in] priMask Priority Mask + */ +__STATIC_INLINE void __set_PRIMASK(uint32_t priMask) +{ + register uint32_t __regPriMask __ASM("primask"); + __regPriMask = (priMask); +} + + +#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) + +/** + \brief Enable FIQ + \details Enables FIQ interrupts by clearing the F-bit in the CPSR. + Can only be executed in Privileged modes. + */ +#define __enable_fault_irq __enable_fiq + + +/** + \brief Disable FIQ + \details Disables FIQ interrupts by setting the F-bit in the CPSR. + Can only be executed in Privileged modes. + */ +#define __disable_fault_irq __disable_fiq + + +/** + \brief Get Base Priority + \details Returns the current value of the Base Priority register. + \return Base Priority register value + */ +__STATIC_INLINE uint32_t __get_BASEPRI(void) +{ + register uint32_t __regBasePri __ASM("basepri"); + return(__regBasePri); +} + + +/** + \brief Set Base Priority + \details Assigns the given value to the Base Priority register. + \param [in] basePri Base Priority value to set + */ +__STATIC_INLINE void __set_BASEPRI(uint32_t basePri) +{ + register uint32_t __regBasePri __ASM("basepri"); + __regBasePri = (basePri & 0xFFU); +} + + +/** + \brief Set Base Priority with condition + \details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled, + or the new value increases the BASEPRI priority level. + \param [in] basePri Base Priority value to set + */ +__STATIC_INLINE void __set_BASEPRI_MAX(uint32_t basePri) +{ + register uint32_t __regBasePriMax __ASM("basepri_max"); + __regBasePriMax = (basePri & 0xFFU); +} + + +/** + \brief Get Fault Mask + \details Returns the current value of the Fault Mask register. + \return Fault Mask register value + */ +__STATIC_INLINE uint32_t __get_FAULTMASK(void) +{ + register uint32_t __regFaultMask __ASM("faultmask"); + return(__regFaultMask); +} + + +/** + \brief Set Fault Mask + \details Assigns the given value to the Fault Mask register. + \param [in] faultMask Fault Mask value to set + */ +__STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask) +{ + register uint32_t __regFaultMask __ASM("faultmask"); + __regFaultMask = (faultMask & (uint32_t)1U); +} + +#endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) */ + + +#if ((defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) + +/** + \brief Get FPSCR + \details Returns the current value of the Floating Point Status/Control register. + \return Floating Point Status/Control register value + */ +__STATIC_INLINE uint32_t __get_FPSCR(void) +{ +#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ + (defined (__FPU_USED ) && (__FPU_USED == 1U)) ) + register uint32_t __regfpscr __ASM("fpscr"); + return(__regfpscr); +#else + return(0U); +#endif +} + + +/** + \brief Set FPSCR + \details Assigns the given value to the Floating Point Status/Control register. + \param [in] fpscr Floating Point Status/Control value to set + */ +__STATIC_INLINE void __set_FPSCR(uint32_t fpscr) +{ +#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ + (defined (__FPU_USED ) && (__FPU_USED == 1U)) ) + register uint32_t __regfpscr __ASM("fpscr"); + __regfpscr = (fpscr); +#else + (void)fpscr; +#endif +} + +#endif /* ((defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) */ + + + +/*@} end of CMSIS_Core_RegAccFunctions */ + + +/* ########################## Core Instruction Access ######################### */ +/** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface + Access to dedicated instructions + @{ +*/ + +/** + \brief No Operation + \details No Operation does nothing. This instruction can be used for code alignment purposes. + */ +#define __NOP __nop + + +/** + \brief Wait For Interrupt + \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs. + */ +#define __WFI __wfi + + +/** + \brief Wait For Event + \details Wait For Event is a hint instruction that permits the processor to enter + a low-power state until one of a number of events occurs. + */ +#define __WFE __wfe + + +/** + \brief Send Event + \details Send Event is a hint instruction. It causes an event to be signaled to the CPU. + */ +#define __SEV __sev + + +/** + \brief Instruction Synchronization Barrier + \details Instruction Synchronization Barrier flushes the pipeline in the processor, + so that all instructions following the ISB are fetched from cache or memory, + after the instruction has been completed. + */ +#define __ISB() do {\ + __schedule_barrier();\ + __isb(0xF);\ + __schedule_barrier();\ + } while (0U) + +/** + \brief Data Synchronization Barrier + \details Acts as a special kind of Data Memory Barrier. + It completes when all explicit memory accesses before this instruction complete. + */ +#define __DSB() do {\ + __schedule_barrier();\ + __dsb(0xF);\ + __schedule_barrier();\ + } while (0U) + +/** + \brief Data Memory Barrier + \details Ensures the apparent order of the explicit memory operations before + and after the instruction, without ensuring their completion. + */ +#define __DMB() do {\ + __schedule_barrier();\ + __dmb(0xF);\ + __schedule_barrier();\ + } while (0U) + + +/** + \brief Reverse byte order (32 bit) + \details Reverses the byte order in unsigned integer value. For example, 0x12345678 becomes 0x78563412. + \param [in] value Value to reverse + \return Reversed value + */ +#define __REV __rev + + +/** + \brief Reverse byte order (16 bit) + \details Reverses the byte order within each halfword of a word. For example, 0x12345678 becomes 0x34127856. + \param [in] value Value to reverse + \return Reversed value + */ +#ifndef __NO_EMBEDDED_ASM +__attribute__((section(".rev16_text"))) __STATIC_INLINE __ASM uint32_t __REV16(uint32_t value) +{ + rev16 r0, r0 + bx lr +} +#endif + + +/** + \brief Reverse byte order (16 bit) + \details Reverses the byte order in a 16-bit value and returns the signed 16-bit result. For example, 0x0080 becomes 0x8000. + \param [in] value Value to reverse + \return Reversed value + */ +#ifndef __NO_EMBEDDED_ASM +__attribute__((section(".revsh_text"))) __STATIC_INLINE __ASM int16_t __REVSH(int16_t value) +{ + revsh r0, r0 + bx lr +} +#endif + + +/** + \brief Rotate Right in unsigned value (32 bit) + \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits. + \param [in] op1 Value to rotate + \param [in] op2 Number of Bits to rotate + \return Rotated value + */ +#define __ROR __ror + + +/** + \brief Breakpoint + \details Causes the processor to enter Debug state. + Debug tools can use this to investigate system state when the instruction at a particular address is reached. + \param [in] value is ignored by the processor. + If required, a debugger can use it to store additional information about the breakpoint. + */ +#define __BKPT(value) __breakpoint(value) + + +/** + \brief Reverse bit order of value + \details Reverses the bit order of the given value. + \param [in] value Value to reverse + \return Reversed value + */ +#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) + #define __RBIT __rbit +#else +__attribute__((always_inline)) __STATIC_INLINE uint32_t __RBIT(uint32_t value) +{ + uint32_t result; + uint32_t s = (4U /*sizeof(v)*/ * 8U) - 1U; /* extra shift needed at end */ + + result = value; /* r will be reversed bits of v; first get LSB of v */ + for (value >>= 1U; value != 0U; value >>= 1U) + { + result <<= 1U; + result |= value & 1U; + s--; + } + result <<= s; /* shift when v's highest bits are zero */ + return result; +} +#endif + + +/** + \brief Count leading zeros + \details Counts the number of leading zeros of a data value. + \param [in] value Value to count the leading zeros + \return number of leading zeros in value + */ +#define __CLZ __clz + + +#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) + +/** + \brief LDR Exclusive (8 bit) + \details Executes a exclusive LDR instruction for 8 bit value. + \param [in] ptr Pointer to data + \return value of type uint8_t at (*ptr) + */ +#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020) + #define __LDREXB(ptr) ((uint8_t ) __ldrex(ptr)) +#else + #define __LDREXB(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint8_t ) __ldrex(ptr)) _Pragma("pop") +#endif + + +/** + \brief LDR Exclusive (16 bit) + \details Executes a exclusive LDR instruction for 16 bit values. + \param [in] ptr Pointer to data + \return value of type uint16_t at (*ptr) + */ +#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020) + #define __LDREXH(ptr) ((uint16_t) __ldrex(ptr)) +#else + #define __LDREXH(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint16_t) __ldrex(ptr)) _Pragma("pop") +#endif + + +/** + \brief LDR Exclusive (32 bit) + \details Executes a exclusive LDR instruction for 32 bit values. + \param [in] ptr Pointer to data + \return value of type uint32_t at (*ptr) + */ +#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020) + #define __LDREXW(ptr) ((uint32_t ) __ldrex(ptr)) +#else + #define __LDREXW(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint32_t ) __ldrex(ptr)) _Pragma("pop") +#endif + + +/** + \brief STR Exclusive (8 bit) + \details Executes a exclusive STR instruction for 8 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed + */ +#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020) + #define __STREXB(value, ptr) __strex(value, ptr) +#else + #define __STREXB(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop") +#endif + + +/** + \brief STR Exclusive (16 bit) + \details Executes a exclusive STR instruction for 16 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed + */ +#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020) + #define __STREXH(value, ptr) __strex(value, ptr) +#else + #define __STREXH(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop") +#endif + + +/** + \brief STR Exclusive (32 bit) + \details Executes a exclusive STR instruction for 32 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed + */ +#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020) + #define __STREXW(value, ptr) __strex(value, ptr) +#else + #define __STREXW(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop") +#endif + + +/** + \brief Remove the exclusive lock + \details Removes the exclusive lock which is created by LDREX. + */ +#define __CLREX __clrex + + +/** + \brief Signed Saturate + \details Saturates a signed value. + \param [in] value Value to be saturated + \param [in] sat Bit position to saturate to (1..32) + \return Saturated value + */ +#define __SSAT __ssat + + +/** + \brief Unsigned Saturate + \details Saturates an unsigned value. + \param [in] value Value to be saturated + \param [in] sat Bit position to saturate to (0..31) + \return Saturated value + */ +#define __USAT __usat + + +/** + \brief Rotate Right with Extend (32 bit) + \details Moves each bit of a bitstring right by one bit. + The carry input is shifted in at the left end of the bitstring. + \param [in] value Value to rotate + \return Rotated value + */ +#ifndef __NO_EMBEDDED_ASM +__attribute__((section(".rrx_text"))) __STATIC_INLINE __ASM uint32_t __RRX(uint32_t value) +{ + rrx r0, r0 + bx lr +} +#endif + + +/** + \brief LDRT Unprivileged (8 bit) + \details Executes a Unprivileged LDRT instruction for 8 bit value. + \param [in] ptr Pointer to data + \return value of type uint8_t at (*ptr) + */ +#define __LDRBT(ptr) ((uint8_t ) __ldrt(ptr)) + + +/** + \brief LDRT Unprivileged (16 bit) + \details Executes a Unprivileged LDRT instruction for 16 bit values. + \param [in] ptr Pointer to data + \return value of type uint16_t at (*ptr) + */ +#define __LDRHT(ptr) ((uint16_t) __ldrt(ptr)) + + +/** + \brief LDRT Unprivileged (32 bit) + \details Executes a Unprivileged LDRT instruction for 32 bit values. + \param [in] ptr Pointer to data + \return value of type uint32_t at (*ptr) + */ +#define __LDRT(ptr) ((uint32_t ) __ldrt(ptr)) + + +/** + \brief STRT Unprivileged (8 bit) + \details Executes a Unprivileged STRT instruction for 8 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + */ +#define __STRBT(value, ptr) __strt(value, ptr) + + +/** + \brief STRT Unprivileged (16 bit) + \details Executes a Unprivileged STRT instruction for 16 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + */ +#define __STRHT(value, ptr) __strt(value, ptr) + + +/** + \brief STRT Unprivileged (32 bit) + \details Executes a Unprivileged STRT instruction for 32 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + */ +#define __STRT(value, ptr) __strt(value, ptr) + +#else /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) */ + +/** + \brief Signed Saturate + \details Saturates a signed value. + \param [in] value Value to be saturated + \param [in] sat Bit position to saturate to (1..32) + \return Saturated value + */ +__attribute__((always_inline)) __STATIC_INLINE int32_t __SSAT(int32_t val, uint32_t sat) +{ + if ((sat >= 1U) && (sat <= 32U)) + { + const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U); + const int32_t min = -1 - max ; + if (val > max) + { + return max; + } + else if (val < min) + { + return min; + } + } + return val; +} + +/** + \brief Unsigned Saturate + \details Saturates an unsigned value. + \param [in] value Value to be saturated + \param [in] sat Bit position to saturate to (0..31) + \return Saturated value + */ +__attribute__((always_inline)) __STATIC_INLINE uint32_t __USAT(int32_t val, uint32_t sat) +{ + if (sat <= 31U) + { + const uint32_t max = ((1U << sat) - 1U); + if (val > (int32_t)max) + { + return max; + } + else if (val < 0) + { + return 0U; + } + } + return (uint32_t)val; +} + +#endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) */ + +/*@}*/ /* end of group CMSIS_Core_InstructionInterface */ + + +/* ################### Compiler specific Intrinsics ########################### */ +/** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics + Access to dedicated SIMD instructions + @{ +*/ + +#if ((defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) + +#define __SADD8 __sadd8 +#define __QADD8 __qadd8 +#define __SHADD8 __shadd8 +#define __UADD8 __uadd8 +#define __UQADD8 __uqadd8 +#define __UHADD8 __uhadd8 +#define __SSUB8 __ssub8 +#define __QSUB8 __qsub8 +#define __SHSUB8 __shsub8 +#define __USUB8 __usub8 +#define __UQSUB8 __uqsub8 +#define __UHSUB8 __uhsub8 +#define __SADD16 __sadd16 +#define __QADD16 __qadd16 +#define __SHADD16 __shadd16 +#define __UADD16 __uadd16 +#define __UQADD16 __uqadd16 +#define __UHADD16 __uhadd16 +#define __SSUB16 __ssub16 +#define __QSUB16 __qsub16 +#define __SHSUB16 __shsub16 +#define __USUB16 __usub16 +#define __UQSUB16 __uqsub16 +#define __UHSUB16 __uhsub16 +#define __SASX __sasx +#define __QASX __qasx +#define __SHASX __shasx +#define __UASX __uasx +#define __UQASX __uqasx +#define __UHASX __uhasx +#define __SSAX __ssax +#define __QSAX __qsax +#define __SHSAX __shsax +#define __USAX __usax +#define __UQSAX __uqsax +#define __UHSAX __uhsax +#define __USAD8 __usad8 +#define __USADA8 __usada8 +#define __SSAT16 __ssat16 +#define __USAT16 __usat16 +#define __UXTB16 __uxtb16 +#define __UXTAB16 __uxtab16 +#define __SXTB16 __sxtb16 +#define __SXTAB16 __sxtab16 +#define __SMUAD __smuad +#define __SMUADX __smuadx +#define __SMLAD __smlad +#define __SMLADX __smladx +#define __SMLALD __smlald +#define __SMLALDX __smlaldx +#define __SMUSD __smusd +#define __SMUSDX __smusdx +#define __SMLSD __smlsd +#define __SMLSDX __smlsdx +#define __SMLSLD __smlsld +#define __SMLSLDX __smlsldx +#define __SEL __sel +#define __QADD __qadd +#define __QSUB __qsub + +#define __PKHBT(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0x0000FFFFUL) | \ + ((((uint32_t)(ARG2)) << (ARG3)) & 0xFFFF0000UL) ) + +#define __PKHTB(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0xFFFF0000UL) | \ + ((((uint32_t)(ARG2)) >> (ARG3)) & 0x0000FFFFUL) ) + +#define __SMMLA(ARG1,ARG2,ARG3) ( (int32_t)((((int64_t)(ARG1) * (ARG2)) + \ + ((int64_t)(ARG3) << 32U) ) >> 32U)) + +#endif /* ((defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) */ +/*@} end of group CMSIS_SIMD_intrinsics */ + + +#endif /* __CMSIS_ARMCC_H */ diff --git a/Platform/Core/cmsis_armclang.h b/Platform/Core/cmsis_armclang.h new file mode 100644 index 0000000..5c4c20e --- /dev/null +++ b/Platform/Core/cmsis_armclang.h @@ -0,0 +1,1877 @@ +/**************************************************************************//** + * @file cmsis_armclang.h + * @brief CMSIS compiler armclang (Arm Compiler 6) header file + * @version V5.0.4 + * @date 10. January 2018 + ******************************************************************************/ +/* + * Copyright (c) 2009-2018 Arm Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * 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 + * + * 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. + */ + +/*lint -esym(9058, IRQn)*/ /* disable MISRA 2012 Rule 2.4 for IRQn */ + +#ifndef __CMSIS_ARMCLANG_H +#define __CMSIS_ARMCLANG_H + +#pragma clang system_header /* treat file as system include file */ + +#ifndef __ARM_COMPAT_H +#include /* Compatibility header for Arm Compiler 5 intrinsics */ +#endif + +/* CMSIS compiler specific defines */ +#ifndef __ASM + #define __ASM __asm +#endif +#ifndef __INLINE + #define __INLINE __inline +#endif +#ifndef __STATIC_INLINE + #define __STATIC_INLINE static __inline +#endif +#ifndef __STATIC_FORCEINLINE + #define __STATIC_FORCEINLINE __attribute__((always_inline)) static __inline +#endif +#ifndef __NO_RETURN + #define __NO_RETURN __attribute__((__noreturn__)) +#endif +#ifndef __USED + #define __USED __attribute__((used)) +#endif +#ifndef __WEAK + #define __WEAK __attribute__((weak)) +#endif +#ifndef __PACKED + #define __PACKED __attribute__((packed, aligned(1))) +#endif +#ifndef __PACKED_STRUCT + #define __PACKED_STRUCT struct __attribute__((packed, aligned(1))) +#endif +#ifndef __PACKED_UNION + #define __PACKED_UNION union __attribute__((packed, aligned(1))) +#endif +#ifndef __UNALIGNED_UINT32 /* deprecated */ + #pragma clang diagnostic push + #pragma clang diagnostic ignored "-Wpacked" +/*lint -esym(9058, T_UINT32)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT32 */ + struct __attribute__((packed)) T_UINT32 { uint32_t v; }; + #pragma clang diagnostic pop + #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) +#endif +#ifndef __UNALIGNED_UINT16_WRITE + #pragma clang diagnostic push + #pragma clang diagnostic ignored "-Wpacked" +/*lint -esym(9058, T_UINT16_WRITE)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT16_WRITE */ + __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; + #pragma clang diagnostic pop + #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val)) +#endif +#ifndef __UNALIGNED_UINT16_READ + #pragma clang diagnostic push + #pragma clang diagnostic ignored "-Wpacked" +/*lint -esym(9058, T_UINT16_READ)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT16_READ */ + __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; + #pragma clang diagnostic pop + #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) +#endif +#ifndef __UNALIGNED_UINT32_WRITE + #pragma clang diagnostic push + #pragma clang diagnostic ignored "-Wpacked" +/*lint -esym(9058, T_UINT32_WRITE)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT32_WRITE */ + __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; + #pragma clang diagnostic pop + #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) +#endif +#ifndef __UNALIGNED_UINT32_READ + #pragma clang diagnostic push + #pragma clang diagnostic ignored "-Wpacked" +/*lint -esym(9058, T_UINT32_READ)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT32_READ */ + __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; + #pragma clang diagnostic pop + #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) +#endif +#ifndef __ALIGNED + #define __ALIGNED(x) __attribute__((aligned(x))) +#endif +#ifndef __RESTRICT + #define __RESTRICT __restrict +#endif + + +/* ########################### Core Function Access ########################### */ +/** \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions + @{ + */ + +/** + \brief Enable IRQ Interrupts + \details Enables IRQ interrupts by clearing the I-bit in the CPSR. + Can only be executed in Privileged modes. + */ +/* intrinsic void __enable_irq(); see arm_compat.h */ + + +/** + \brief Disable IRQ Interrupts + \details Disables IRQ interrupts by setting the I-bit in the CPSR. + Can only be executed in Privileged modes. + */ +/* intrinsic void __disable_irq(); see arm_compat.h */ + + +/** + \brief Get Control Register + \details Returns the content of the Control Register. + \return Control Register value + */ +__STATIC_FORCEINLINE uint32_t __get_CONTROL(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, control" : "=r" (result) ); + return(result); +} + + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Get Control Register (non-secure) + \details Returns the content of the non-secure Control Register when in secure mode. + \return non-secure Control Register value + */ +__STATIC_FORCEINLINE uint32_t __TZ_get_CONTROL_NS(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, control_ns" : "=r" (result) ); + return(result); +} +#endif + + +/** + \brief Set Control Register + \details Writes the given value to the Control Register. + \param [in] control Control Register value to set + */ +__STATIC_FORCEINLINE void __set_CONTROL(uint32_t control) +{ + __ASM volatile ("MSR control, %0" : : "r" (control) : "memory"); +} + + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Set Control Register (non-secure) + \details Writes the given value to the non-secure Control Register when in secure state. + \param [in] control Control Register value to set + */ +__STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control) +{ + __ASM volatile ("MSR control_ns, %0" : : "r" (control) : "memory"); +} +#endif + + +/** + \brief Get IPSR Register + \details Returns the content of the IPSR Register. + \return IPSR Register value + */ +__STATIC_FORCEINLINE uint32_t __get_IPSR(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, ipsr" : "=r" (result) ); + return(result); +} + + +/** + \brief Get APSR Register + \details Returns the content of the APSR Register. + \return APSR Register value + */ +__STATIC_FORCEINLINE uint32_t __get_APSR(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, apsr" : "=r" (result) ); + return(result); +} + + +/** + \brief Get xPSR Register + \details Returns the content of the xPSR Register. + \return xPSR Register value + */ +__STATIC_FORCEINLINE uint32_t __get_xPSR(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, xpsr" : "=r" (result) ); + return(result); +} + + +/** + \brief Get Process Stack Pointer + \details Returns the current value of the Process Stack Pointer (PSP). + \return PSP Register value + */ +__STATIC_FORCEINLINE uint32_t __get_PSP(void) +{ + register uint32_t result; + + __ASM volatile ("MRS %0, psp" : "=r" (result) ); + return(result); +} + + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Get Process Stack Pointer (non-secure) + \details Returns the current value of the non-secure Process Stack Pointer (PSP) when in secure state. + \return PSP Register value + */ +__STATIC_FORCEINLINE uint32_t __TZ_get_PSP_NS(void) +{ + register uint32_t result; + + __ASM volatile ("MRS %0, psp_ns" : "=r" (result) ); + return(result); +} +#endif + + +/** + \brief Set Process Stack Pointer + \details Assigns the given value to the Process Stack Pointer (PSP). + \param [in] topOfProcStack Process Stack Pointer value to set + */ +__STATIC_FORCEINLINE void __set_PSP(uint32_t topOfProcStack) +{ + __ASM volatile ("MSR psp, %0" : : "r" (topOfProcStack) : ); +} + + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Set Process Stack Pointer (non-secure) + \details Assigns the given value to the non-secure Process Stack Pointer (PSP) when in secure state. + \param [in] topOfProcStack Process Stack Pointer value to set + */ +__STATIC_FORCEINLINE void __TZ_set_PSP_NS(uint32_t topOfProcStack) +{ + __ASM volatile ("MSR psp_ns, %0" : : "r" (topOfProcStack) : ); +} +#endif + + +/** + \brief Get Main Stack Pointer + \details Returns the current value of the Main Stack Pointer (MSP). + \return MSP Register value + */ +__STATIC_FORCEINLINE uint32_t __get_MSP(void) +{ + register uint32_t result; + + __ASM volatile ("MRS %0, msp" : "=r" (result) ); + return(result); +} + + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Get Main Stack Pointer (non-secure) + \details Returns the current value of the non-secure Main Stack Pointer (MSP) when in secure state. + \return MSP Register value + */ +__STATIC_FORCEINLINE uint32_t __TZ_get_MSP_NS(void) +{ + register uint32_t result; + + __ASM volatile ("MRS %0, msp_ns" : "=r" (result) ); + return(result); +} +#endif + + +/** + \brief Set Main Stack Pointer + \details Assigns the given value to the Main Stack Pointer (MSP). + \param [in] topOfMainStack Main Stack Pointer value to set + */ +__STATIC_FORCEINLINE void __set_MSP(uint32_t topOfMainStack) +{ + __ASM volatile ("MSR msp, %0" : : "r" (topOfMainStack) : ); +} + + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Set Main Stack Pointer (non-secure) + \details Assigns the given value to the non-secure Main Stack Pointer (MSP) when in secure state. + \param [in] topOfMainStack Main Stack Pointer value to set + */ +__STATIC_FORCEINLINE void __TZ_set_MSP_NS(uint32_t topOfMainStack) +{ + __ASM volatile ("MSR msp_ns, %0" : : "r" (topOfMainStack) : ); +} +#endif + + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Get Stack Pointer (non-secure) + \details Returns the current value of the non-secure Stack Pointer (SP) when in secure state. + \return SP Register value + */ +__STATIC_FORCEINLINE uint32_t __TZ_get_SP_NS(void) +{ + register uint32_t result; + + __ASM volatile ("MRS %0, sp_ns" : "=r" (result) ); + return(result); +} + + +/** + \brief Set Stack Pointer (non-secure) + \details Assigns the given value to the non-secure Stack Pointer (SP) when in secure state. + \param [in] topOfStack Stack Pointer value to set + */ +__STATIC_FORCEINLINE void __TZ_set_SP_NS(uint32_t topOfStack) +{ + __ASM volatile ("MSR sp_ns, %0" : : "r" (topOfStack) : ); +} +#endif + + +/** + \brief Get Priority Mask + \details Returns the current state of the priority mask bit from the Priority Mask Register. + \return Priority Mask value + */ +__STATIC_FORCEINLINE uint32_t __get_PRIMASK(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, primask" : "=r" (result) ); + return(result); +} + + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Get Priority Mask (non-secure) + \details Returns the current state of the non-secure priority mask bit from the Priority Mask Register when in secure state. + \return Priority Mask value + */ +__STATIC_FORCEINLINE uint32_t __TZ_get_PRIMASK_NS(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, primask_ns" : "=r" (result) ); + return(result); +} +#endif + + +/** + \brief Set Priority Mask + \details Assigns the given value to the Priority Mask Register. + \param [in] priMask Priority Mask + */ +__STATIC_FORCEINLINE void __set_PRIMASK(uint32_t priMask) +{ + __ASM volatile ("MSR primask, %0" : : "r" (priMask) : "memory"); +} + + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Set Priority Mask (non-secure) + \details Assigns the given value to the non-secure Priority Mask Register when in secure state. + \param [in] priMask Priority Mask + */ +__STATIC_FORCEINLINE void __TZ_set_PRIMASK_NS(uint32_t priMask) +{ + __ASM volatile ("MSR primask_ns, %0" : : "r" (priMask) : "memory"); +} +#endif + + +#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ + (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) +/** + \brief Enable FIQ + \details Enables FIQ interrupts by clearing the F-bit in the CPSR. + Can only be executed in Privileged modes. + */ +#define __enable_fault_irq __enable_fiq /* see arm_compat.h */ + + +/** + \brief Disable FIQ + \details Disables FIQ interrupts by setting the F-bit in the CPSR. + Can only be executed in Privileged modes. + */ +#define __disable_fault_irq __disable_fiq /* see arm_compat.h */ + + +/** + \brief Get Base Priority + \details Returns the current value of the Base Priority register. + \return Base Priority register value + */ +__STATIC_FORCEINLINE uint32_t __get_BASEPRI(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, basepri" : "=r" (result) ); + return(result); +} + + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Get Base Priority (non-secure) + \details Returns the current value of the non-secure Base Priority register when in secure state. + \return Base Priority register value + */ +__STATIC_FORCEINLINE uint32_t __TZ_get_BASEPRI_NS(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, basepri_ns" : "=r" (result) ); + return(result); +} +#endif + + +/** + \brief Set Base Priority + \details Assigns the given value to the Base Priority register. + \param [in] basePri Base Priority value to set + */ +__STATIC_FORCEINLINE void __set_BASEPRI(uint32_t basePri) +{ + __ASM volatile ("MSR basepri, %0" : : "r" (basePri) : "memory"); +} + + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Set Base Priority (non-secure) + \details Assigns the given value to the non-secure Base Priority register when in secure state. + \param [in] basePri Base Priority value to set + */ +__STATIC_FORCEINLINE void __TZ_set_BASEPRI_NS(uint32_t basePri) +{ + __ASM volatile ("MSR basepri_ns, %0" : : "r" (basePri) : "memory"); +} +#endif + + +/** + \brief Set Base Priority with condition + \details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled, + or the new value increases the BASEPRI priority level. + \param [in] basePri Base Priority value to set + */ +__STATIC_FORCEINLINE void __set_BASEPRI_MAX(uint32_t basePri) +{ + __ASM volatile ("MSR basepri_max, %0" : : "r" (basePri) : "memory"); +} + + +/** + \brief Get Fault Mask + \details Returns the current value of the Fault Mask register. + \return Fault Mask register value + */ +__STATIC_FORCEINLINE uint32_t __get_FAULTMASK(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, faultmask" : "=r" (result) ); + return(result); +} + + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Get Fault Mask (non-secure) + \details Returns the current value of the non-secure Fault Mask register when in secure state. + \return Fault Mask register value + */ +__STATIC_FORCEINLINE uint32_t __TZ_get_FAULTMASK_NS(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, faultmask_ns" : "=r" (result) ); + return(result); +} +#endif + + +/** + \brief Set Fault Mask + \details Assigns the given value to the Fault Mask register. + \param [in] faultMask Fault Mask value to set + */ +__STATIC_FORCEINLINE void __set_FAULTMASK(uint32_t faultMask) +{ + __ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) : "memory"); +} + + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Set Fault Mask (non-secure) + \details Assigns the given value to the non-secure Fault Mask register when in secure state. + \param [in] faultMask Fault Mask value to set + */ +__STATIC_FORCEINLINE void __TZ_set_FAULTMASK_NS(uint32_t faultMask) +{ + __ASM volatile ("MSR faultmask_ns, %0" : : "r" (faultMask) : "memory"); +} +#endif + +#endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ + (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */ + + +#if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) + +/** + \brief Get Process Stack Pointer Limit + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence zero is returned always in non-secure + mode. + + \details Returns the current value of the Process Stack Pointer Limit (PSPLIM). + \return PSPLIM Register value + */ +__STATIC_FORCEINLINE uint32_t __get_PSPLIM(void) +{ +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ + (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) + // without main extensions, the non-secure PSPLIM is RAZ/WI + return 0U; +#else + register uint32_t result; + __ASM volatile ("MRS %0, psplim" : "=r" (result) ); + return result; +#endif +} + +#if (defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Get Process Stack Pointer Limit (non-secure) + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence zero is returned always in non-secure + mode. + + \details Returns the current value of the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state. + \return PSPLIM Register value + */ +__STATIC_FORCEINLINE uint32_t __TZ_get_PSPLIM_NS(void) +{ +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))) + // without main extensions, the non-secure PSPLIM is RAZ/WI + return 0U; +#else + register uint32_t result; + __ASM volatile ("MRS %0, psplim_ns" : "=r" (result) ); + return result; +#endif +} +#endif + + +/** + \brief Set Process Stack Pointer Limit + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence the write is silently ignored in non-secure + mode. + + \details Assigns the given value to the Process Stack Pointer Limit (PSPLIM). + \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set + */ +__STATIC_FORCEINLINE void __set_PSPLIM(uint32_t ProcStackPtrLimit) +{ +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ + (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) + // without main extensions, the non-secure PSPLIM is RAZ/WI + (void)ProcStackPtrLimit; +#else + __ASM volatile ("MSR psplim, %0" : : "r" (ProcStackPtrLimit)); +#endif +} + + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Set Process Stack Pointer (non-secure) + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence the write is silently ignored in non-secure + mode. + + \details Assigns the given value to the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state. + \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set + */ +__STATIC_FORCEINLINE void __TZ_set_PSPLIM_NS(uint32_t ProcStackPtrLimit) +{ +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))) + // without main extensions, the non-secure PSPLIM is RAZ/WI + (void)ProcStackPtrLimit; +#else + __ASM volatile ("MSR psplim_ns, %0\n" : : "r" (ProcStackPtrLimit)); +#endif +} +#endif + + +/** + \brief Get Main Stack Pointer Limit + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence zero is returned always. + + \details Returns the current value of the Main Stack Pointer Limit (MSPLIM). + \return MSPLIM Register value + */ +__STATIC_FORCEINLINE uint32_t __get_MSPLIM(void) +{ +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ + (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) + // without main extensions, the non-secure MSPLIM is RAZ/WI + return 0U; +#else + register uint32_t result; + __ASM volatile ("MRS %0, msplim" : "=r" (result) ); + return result; +#endif +} + + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Get Main Stack Pointer Limit (non-secure) + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence zero is returned always. + + \details Returns the current value of the non-secure Main Stack Pointer Limit(MSPLIM) when in secure state. + \return MSPLIM Register value + */ +__STATIC_FORCEINLINE uint32_t __TZ_get_MSPLIM_NS(void) +{ +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))) + // without main extensions, the non-secure MSPLIM is RAZ/WI + return 0U; +#else + register uint32_t result; + __ASM volatile ("MRS %0, msplim_ns" : "=r" (result) ); + return result; +#endif +} +#endif + + +/** + \brief Set Main Stack Pointer Limit + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence the write is silently ignored. + + \details Assigns the given value to the Main Stack Pointer Limit (MSPLIM). + \param [in] MainStackPtrLimit Main Stack Pointer Limit value to set + */ +__STATIC_FORCEINLINE void __set_MSPLIM(uint32_t MainStackPtrLimit) +{ +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ + (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) + // without main extensions, the non-secure MSPLIM is RAZ/WI + (void)MainStackPtrLimit; +#else + __ASM volatile ("MSR msplim, %0" : : "r" (MainStackPtrLimit)); +#endif +} + + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Set Main Stack Pointer Limit (non-secure) + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence the write is silently ignored. + + \details Assigns the given value to the non-secure Main Stack Pointer Limit (MSPLIM) when in secure state. + \param [in] MainStackPtrLimit Main Stack Pointer value to set + */ +__STATIC_FORCEINLINE void __TZ_set_MSPLIM_NS(uint32_t MainStackPtrLimit) +{ +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))) + // without main extensions, the non-secure MSPLIM is RAZ/WI + (void)MainStackPtrLimit; +#else + __ASM volatile ("MSR msplim_ns, %0" : : "r" (MainStackPtrLimit)); +#endif +} +#endif + +#endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */ + + +#if ((defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ + (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) + +/** + \brief Get FPSCR + \details Returns the current value of the Floating Point Status/Control register. + \return Floating Point Status/Control register value + */ +#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ + (defined (__FPU_USED ) && (__FPU_USED == 1U)) ) +#define __get_FPSCR (uint32_t)__builtin_arm_get_fpscr +#else +#define __get_FPSCR() ((uint32_t)0U) +#endif + +/** + \brief Set FPSCR + \details Assigns the given value to the Floating Point Status/Control register. + \param [in] fpscr Floating Point Status/Control value to set + */ +#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ + (defined (__FPU_USED ) && (__FPU_USED == 1U)) ) +#define __set_FPSCR __builtin_arm_set_fpscr +#else +#define __set_FPSCR(x) ((void)(x)) +#endif + +#endif /* ((defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ + (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */ + + + +/*@} end of CMSIS_Core_RegAccFunctions */ + + +/* ########################## Core Instruction Access ######################### */ +/** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface + Access to dedicated instructions + @{ +*/ + +/* Define macros for porting to both thumb1 and thumb2. + * For thumb1, use low register (r0-r7), specified by constraint "l" + * Otherwise, use general registers, specified by constraint "r" */ +#if defined (__thumb__) && !defined (__thumb2__) +#define __CMSIS_GCC_OUT_REG(r) "=l" (r) +#define __CMSIS_GCC_USE_REG(r) "l" (r) +#else +#define __CMSIS_GCC_OUT_REG(r) "=r" (r) +#define __CMSIS_GCC_USE_REG(r) "r" (r) +#endif + +/** + \brief No Operation + \details No Operation does nothing. This instruction can be used for code alignment purposes. + */ +#define __NOP __builtin_arm_nop + +/** + \brief Wait For Interrupt + \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs. + */ +#define __WFI __builtin_arm_wfi + + +/** + \brief Wait For Event + \details Wait For Event is a hint instruction that permits the processor to enter + a low-power state until one of a number of events occurs. + */ +#define __WFE __builtin_arm_wfe + + +/** + \brief Send Event + \details Send Event is a hint instruction. It causes an event to be signaled to the CPU. + */ +#define __SEV __builtin_arm_sev + + +/** + \brief Instruction Synchronization Barrier + \details Instruction Synchronization Barrier flushes the pipeline in the processor, + so that all instructions following the ISB are fetched from cache or memory, + after the instruction has been completed. + */ +#define __ISB() __builtin_arm_isb(0xF); + +/** + \brief Data Synchronization Barrier + \details Acts as a special kind of Data Memory Barrier. + It completes when all explicit memory accesses before this instruction complete. + */ +#define __DSB() __builtin_arm_dsb(0xF); + + +/** + \brief Data Memory Barrier + \details Ensures the apparent order of the explicit memory operations before + and after the instruction, without ensuring their completion. + */ +#define __DMB() __builtin_arm_dmb(0xF); + + +/** + \brief Reverse byte order (32 bit) + \details Reverses the byte order in unsigned integer value. For example, 0x12345678 becomes 0x78563412. + \param [in] value Value to reverse + \return Reversed value + */ +#define __REV(value) __builtin_bswap32(value) + + +/** + \brief Reverse byte order (16 bit) + \details Reverses the byte order within each halfword of a word. For example, 0x12345678 becomes 0x34127856. + \param [in] value Value to reverse + \return Reversed value + */ +#define __REV16(value) __ROR(__REV(value), 16) + + +/** + \brief Reverse byte order (16 bit) + \details Reverses the byte order in a 16-bit value and returns the signed 16-bit result. For example, 0x0080 becomes 0x8000. + \param [in] value Value to reverse + \return Reversed value + */ +#define __REVSH(value) (int16_t)__builtin_bswap16(value) + + +/** + \brief Rotate Right in unsigned value (32 bit) + \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits. + \param [in] op1 Value to rotate + \param [in] op2 Number of Bits to rotate + \return Rotated value + */ +__STATIC_FORCEINLINE uint32_t __ROR(uint32_t op1, uint32_t op2) +{ + op2 %= 32U; + if (op2 == 0U) + { + return op1; + } + return (op1 >> op2) | (op1 << (32U - op2)); +} + + +/** + \brief Breakpoint + \details Causes the processor to enter Debug state. + Debug tools can use this to investigate system state when the instruction at a particular address is reached. + \param [in] value is ignored by the processor. + If required, a debugger can use it to store additional information about the breakpoint. + */ +#define __BKPT(value) __ASM volatile ("bkpt "#value) + + +/** + \brief Reverse bit order of value + \details Reverses the bit order of the given value. + \param [in] value Value to reverse + \return Reversed value + */ +#define __RBIT __builtin_arm_rbit + +/** + \brief Count leading zeros + \details Counts the number of leading zeros of a data value. + \param [in] value Value to count the leading zeros + \return number of leading zeros in value + */ +#define __CLZ (uint8_t)__builtin_clz + + +#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ + (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) +/** + \brief LDR Exclusive (8 bit) + \details Executes a exclusive LDR instruction for 8 bit value. + \param [in] ptr Pointer to data + \return value of type uint8_t at (*ptr) + */ +#define __LDREXB (uint8_t)__builtin_arm_ldrex + + +/** + \brief LDR Exclusive (16 bit) + \details Executes a exclusive LDR instruction for 16 bit values. + \param [in] ptr Pointer to data + \return value of type uint16_t at (*ptr) + */ +#define __LDREXH (uint16_t)__builtin_arm_ldrex + + +/** + \brief LDR Exclusive (32 bit) + \details Executes a exclusive LDR instruction for 32 bit values. + \param [in] ptr Pointer to data + \return value of type uint32_t at (*ptr) + */ +#define __LDREXW (uint32_t)__builtin_arm_ldrex + + +/** + \brief STR Exclusive (8 bit) + \details Executes a exclusive STR instruction for 8 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed + */ +#define __STREXB (uint32_t)__builtin_arm_strex + + +/** + \brief STR Exclusive (16 bit) + \details Executes a exclusive STR instruction for 16 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed + */ +#define __STREXH (uint32_t)__builtin_arm_strex + + +/** + \brief STR Exclusive (32 bit) + \details Executes a exclusive STR instruction for 32 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed + */ +#define __STREXW (uint32_t)__builtin_arm_strex + + +/** + \brief Remove the exclusive lock + \details Removes the exclusive lock which is created by LDREX. + */ +#define __CLREX __builtin_arm_clrex + +#endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ + (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */ + + +#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ + (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) + +/** + \brief Signed Saturate + \details Saturates a signed value. + \param [in] value Value to be saturated + \param [in] sat Bit position to saturate to (1..32) + \return Saturated value + */ +#define __SSAT __builtin_arm_ssat + + +/** + \brief Unsigned Saturate + \details Saturates an unsigned value. + \param [in] value Value to be saturated + \param [in] sat Bit position to saturate to (0..31) + \return Saturated value + */ +#define __USAT __builtin_arm_usat + + +/** + \brief Rotate Right with Extend (32 bit) + \details Moves each bit of a bitstring right by one bit. + The carry input is shifted in at the left end of the bitstring. + \param [in] value Value to rotate + \return Rotated value + */ +__STATIC_FORCEINLINE uint32_t __RRX(uint32_t value) +{ + uint32_t result; + + __ASM volatile ("rrx %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) ); + return(result); +} + + +/** + \brief LDRT Unprivileged (8 bit) + \details Executes a Unprivileged LDRT instruction for 8 bit value. + \param [in] ptr Pointer to data + \return value of type uint8_t at (*ptr) + */ +__STATIC_FORCEINLINE uint8_t __LDRBT(volatile uint8_t *ptr) +{ + uint32_t result; + + __ASM volatile ("ldrbt %0, %1" : "=r" (result) : "Q" (*ptr) ); + return ((uint8_t) result); /* Add explicit type cast here */ +} + + +/** + \brief LDRT Unprivileged (16 bit) + \details Executes a Unprivileged LDRT instruction for 16 bit values. + \param [in] ptr Pointer to data + \return value of type uint16_t at (*ptr) + */ +__STATIC_FORCEINLINE uint16_t __LDRHT(volatile uint16_t *ptr) +{ + uint32_t result; + + __ASM volatile ("ldrht %0, %1" : "=r" (result) : "Q" (*ptr) ); + return ((uint16_t) result); /* Add explicit type cast here */ +} + + +/** + \brief LDRT Unprivileged (32 bit) + \details Executes a Unprivileged LDRT instruction for 32 bit values. + \param [in] ptr Pointer to data + \return value of type uint32_t at (*ptr) + */ +__STATIC_FORCEINLINE uint32_t __LDRT(volatile uint32_t *ptr) +{ + uint32_t result; + + __ASM volatile ("ldrt %0, %1" : "=r" (result) : "Q" (*ptr) ); + return(result); +} + + +/** + \brief STRT Unprivileged (8 bit) + \details Executes a Unprivileged STRT instruction for 8 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + */ +__STATIC_FORCEINLINE void __STRBT(uint8_t value, volatile uint8_t *ptr) +{ + __ASM volatile ("strbt %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) ); +} + + +/** + \brief STRT Unprivileged (16 bit) + \details Executes a Unprivileged STRT instruction for 16 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + */ +__STATIC_FORCEINLINE void __STRHT(uint16_t value, volatile uint16_t *ptr) +{ + __ASM volatile ("strht %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) ); +} + + +/** + \brief STRT Unprivileged (32 bit) + \details Executes a Unprivileged STRT instruction for 32 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + */ +__STATIC_FORCEINLINE void __STRT(uint32_t value, volatile uint32_t *ptr) +{ + __ASM volatile ("strt %1, %0" : "=Q" (*ptr) : "r" (value) ); +} + +#else /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ + (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */ + +/** + \brief Signed Saturate + \details Saturates a signed value. + \param [in] value Value to be saturated + \param [in] sat Bit position to saturate to (1..32) + \return Saturated value + */ +__STATIC_FORCEINLINE int32_t __SSAT(int32_t val, uint32_t sat) +{ + if ((sat >= 1U) && (sat <= 32U)) + { + const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U); + const int32_t min = -1 - max ; + if (val > max) + { + return max; + } + else if (val < min) + { + return min; + } + } + return val; +} + +/** + \brief Unsigned Saturate + \details Saturates an unsigned value. + \param [in] value Value to be saturated + \param [in] sat Bit position to saturate to (0..31) + \return Saturated value + */ +__STATIC_FORCEINLINE uint32_t __USAT(int32_t val, uint32_t sat) +{ + if (sat <= 31U) + { + const uint32_t max = ((1U << sat) - 1U); + if (val > (int32_t)max) + { + return max; + } + else if (val < 0) + { + return 0U; + } + } + return (uint32_t)val; +} + +#endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ + (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */ + + +#if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) +/** + \brief Load-Acquire (8 bit) + \details Executes a LDAB instruction for 8 bit value. + \param [in] ptr Pointer to data + \return value of type uint8_t at (*ptr) + */ +__STATIC_FORCEINLINE uint8_t __LDAB(volatile uint8_t *ptr) +{ + uint32_t result; + + __ASM volatile ("ldab %0, %1" : "=r" (result) : "Q" (*ptr) ); + return ((uint8_t) result); +} + + +/** + \brief Load-Acquire (16 bit) + \details Executes a LDAH instruction for 16 bit values. + \param [in] ptr Pointer to data + \return value of type uint16_t at (*ptr) + */ +__STATIC_FORCEINLINE uint16_t __LDAH(volatile uint16_t *ptr) +{ + uint32_t result; + + __ASM volatile ("ldah %0, %1" : "=r" (result) : "Q" (*ptr) ); + return ((uint16_t) result); +} + + +/** + \brief Load-Acquire (32 bit) + \details Executes a LDA instruction for 32 bit values. + \param [in] ptr Pointer to data + \return value of type uint32_t at (*ptr) + */ +__STATIC_FORCEINLINE uint32_t __LDA(volatile uint32_t *ptr) +{ + uint32_t result; + + __ASM volatile ("lda %0, %1" : "=r" (result) : "Q" (*ptr) ); + return(result); +} + + +/** + \brief Store-Release (8 bit) + \details Executes a STLB instruction for 8 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + */ +__STATIC_FORCEINLINE void __STLB(uint8_t value, volatile uint8_t *ptr) +{ + __ASM volatile ("stlb %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) ); +} + + +/** + \brief Store-Release (16 bit) + \details Executes a STLH instruction for 16 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + */ +__STATIC_FORCEINLINE void __STLH(uint16_t value, volatile uint16_t *ptr) +{ + __ASM volatile ("stlh %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) ); +} + + +/** + \brief Store-Release (32 bit) + \details Executes a STL instruction for 32 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + */ +__STATIC_FORCEINLINE void __STL(uint32_t value, volatile uint32_t *ptr) +{ + __ASM volatile ("stl %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) ); +} + + +/** + \brief Load-Acquire Exclusive (8 bit) + \details Executes a LDAB exclusive instruction for 8 bit value. + \param [in] ptr Pointer to data + \return value of type uint8_t at (*ptr) + */ +#define __LDAEXB (uint8_t)__builtin_arm_ldaex + + +/** + \brief Load-Acquire Exclusive (16 bit) + \details Executes a LDAH exclusive instruction for 16 bit values. + \param [in] ptr Pointer to data + \return value of type uint16_t at (*ptr) + */ +#define __LDAEXH (uint16_t)__builtin_arm_ldaex + + +/** + \brief Load-Acquire Exclusive (32 bit) + \details Executes a LDA exclusive instruction for 32 bit values. + \param [in] ptr Pointer to data + \return value of type uint32_t at (*ptr) + */ +#define __LDAEX (uint32_t)__builtin_arm_ldaex + + +/** + \brief Store-Release Exclusive (8 bit) + \details Executes a STLB exclusive instruction for 8 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed + */ +#define __STLEXB (uint32_t)__builtin_arm_stlex + + +/** + \brief Store-Release Exclusive (16 bit) + \details Executes a STLH exclusive instruction for 16 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed + */ +#define __STLEXH (uint32_t)__builtin_arm_stlex + + +/** + \brief Store-Release Exclusive (32 bit) + \details Executes a STL exclusive instruction for 32 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed + */ +#define __STLEX (uint32_t)__builtin_arm_stlex + +#endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */ + +/*@}*/ /* end of group CMSIS_Core_InstructionInterface */ + + +/* ################### Compiler specific Intrinsics ########################### */ +/** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics + Access to dedicated SIMD instructions + @{ +*/ + +#if (defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1)) + +__STATIC_FORCEINLINE uint32_t __SADD8(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("sadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __QADD8(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("qadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __SHADD8(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("shadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __UADD8(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __UQADD8(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uqadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __UHADD8(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uhadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + + +__STATIC_FORCEINLINE uint32_t __SSUB8(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("ssub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __QSUB8(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("qsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __SHSUB8(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("shsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __USUB8(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("usub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __UQSUB8(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uqsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __UHSUB8(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uhsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + + +__STATIC_FORCEINLINE uint32_t __SADD16(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("sadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __QADD16(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("qadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __SHADD16(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("shadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __UADD16(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __UQADD16(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uqadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __UHADD16(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uhadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __SSUB16(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("ssub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __QSUB16(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("qsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __SHSUB16(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("shsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __USUB16(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("usub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __UQSUB16(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uqsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __UHSUB16(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uhsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __SASX(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("sasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __QASX(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("qasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __SHASX(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("shasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __UASX(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __UQASX(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uqasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __UHASX(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uhasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __SSAX(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("ssax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __QSAX(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("qsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __SHSAX(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("shsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __USAX(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("usax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __UQSAX(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uqsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __UHSAX(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uhsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __USAD8(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("usad8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __USADA8(uint32_t op1, uint32_t op2, uint32_t op3) +{ + uint32_t result; + + __ASM volatile ("usada8 %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) ); + return(result); +} + +#define __SSAT16(ARG1,ARG2) \ +({ \ + int32_t __RES, __ARG1 = (ARG1); \ + __ASM ("ssat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \ + __RES; \ + }) + +#define __USAT16(ARG1,ARG2) \ +({ \ + uint32_t __RES, __ARG1 = (ARG1); \ + __ASM ("usat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \ + __RES; \ + }) + +__STATIC_FORCEINLINE uint32_t __UXTB16(uint32_t op1) +{ + uint32_t result; + + __ASM volatile ("uxtb16 %0, %1" : "=r" (result) : "r" (op1)); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __UXTAB16(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __SXTB16(uint32_t op1) +{ + uint32_t result; + + __ASM volatile ("sxtb16 %0, %1" : "=r" (result) : "r" (op1)); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __SXTAB16(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("sxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __SMUAD (uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("smuad %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __SMUADX (uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("smuadx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __SMLAD (uint32_t op1, uint32_t op2, uint32_t op3) +{ + uint32_t result; + + __ASM volatile ("smlad %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __SMLADX (uint32_t op1, uint32_t op2, uint32_t op3) +{ + uint32_t result; + + __ASM volatile ("smladx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) ); + return(result); +} + +__STATIC_FORCEINLINE uint64_t __SMLALD (uint32_t op1, uint32_t op2, uint64_t acc) +{ + union llreg_u{ + uint32_t w32[2]; + uint64_t w64; + } llr; + llr.w64 = acc; + +#ifndef __ARMEB__ /* Little endian */ + __ASM volatile ("smlald %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) ); +#else /* Big endian */ + __ASM volatile ("smlald %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) ); +#endif + + return(llr.w64); +} + +__STATIC_FORCEINLINE uint64_t __SMLALDX (uint32_t op1, uint32_t op2, uint64_t acc) +{ + union llreg_u{ + uint32_t w32[2]; + uint64_t w64; + } llr; + llr.w64 = acc; + +#ifndef __ARMEB__ /* Little endian */ + __ASM volatile ("smlaldx %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) ); +#else /* Big endian */ + __ASM volatile ("smlaldx %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) ); +#endif + + return(llr.w64); +} + +__STATIC_FORCEINLINE uint32_t __SMUSD (uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("smusd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __SMUSDX (uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("smusdx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __SMLSD (uint32_t op1, uint32_t op2, uint32_t op3) +{ + uint32_t result; + + __ASM volatile ("smlsd %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __SMLSDX (uint32_t op1, uint32_t op2, uint32_t op3) +{ + uint32_t result; + + __ASM volatile ("smlsdx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) ); + return(result); +} + +__STATIC_FORCEINLINE uint64_t __SMLSLD (uint32_t op1, uint32_t op2, uint64_t acc) +{ + union llreg_u{ + uint32_t w32[2]; + uint64_t w64; + } llr; + llr.w64 = acc; + +#ifndef __ARMEB__ /* Little endian */ + __ASM volatile ("smlsld %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) ); +#else /* Big endian */ + __ASM volatile ("smlsld %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) ); +#endif + + return(llr.w64); +} + +__STATIC_FORCEINLINE uint64_t __SMLSLDX (uint32_t op1, uint32_t op2, uint64_t acc) +{ + union llreg_u{ + uint32_t w32[2]; + uint64_t w64; + } llr; + llr.w64 = acc; + +#ifndef __ARMEB__ /* Little endian */ + __ASM volatile ("smlsldx %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) ); +#else /* Big endian */ + __ASM volatile ("smlsldx %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) ); +#endif + + return(llr.w64); +} + +__STATIC_FORCEINLINE uint32_t __SEL (uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("sel %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE int32_t __QADD( int32_t op1, int32_t op2) +{ + int32_t result; + + __ASM volatile ("qadd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE int32_t __QSUB( int32_t op1, int32_t op2) +{ + int32_t result; + + __ASM volatile ("qsub %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +#if 0 +#define __PKHBT(ARG1,ARG2,ARG3) \ +({ \ + uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \ + __ASM ("pkhbt %0, %1, %2, lsl %3" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2), "I" (ARG3) ); \ + __RES; \ + }) + +#define __PKHTB(ARG1,ARG2,ARG3) \ +({ \ + uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \ + if (ARG3 == 0) \ + __ASM ("pkhtb %0, %1, %2" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2) ); \ + else \ + __ASM ("pkhtb %0, %1, %2, asr %3" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2), "I" (ARG3) ); \ + __RES; \ + }) +#endif + +#define __PKHBT(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0x0000FFFFUL) | \ + ((((uint32_t)(ARG2)) << (ARG3)) & 0xFFFF0000UL) ) + +#define __PKHTB(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0xFFFF0000UL) | \ + ((((uint32_t)(ARG2)) >> (ARG3)) & 0x0000FFFFUL) ) + +__STATIC_FORCEINLINE int32_t __SMMLA (int32_t op1, int32_t op2, int32_t op3) +{ + int32_t result; + + __ASM volatile ("smmla %0, %1, %2, %3" : "=r" (result): "r" (op1), "r" (op2), "r" (op3) ); + return(result); +} + +#endif /* (__ARM_FEATURE_DSP == 1) */ +/*@} end of group CMSIS_SIMD_intrinsics */ + + +#endif /* __CMSIS_ARMCLANG_H */ diff --git a/Platform/Core/cmsis_compiler.h b/Platform/Core/cmsis_compiler.h new file mode 100644 index 0000000..94212eb --- /dev/null +++ b/Platform/Core/cmsis_compiler.h @@ -0,0 +1,266 @@ +/**************************************************************************//** + * @file cmsis_compiler.h + * @brief CMSIS compiler generic header file + * @version V5.0.4 + * @date 10. January 2018 + ******************************************************************************/ +/* + * Copyright (c) 2009-2018 Arm Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * 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 + * + * 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. + */ + +#ifndef __CMSIS_COMPILER_H +#define __CMSIS_COMPILER_H + +#include + +/* + * Arm Compiler 4/5 + */ +#if defined ( __CC_ARM ) + #include "cmsis_armcc.h" + + +/* + * Arm Compiler 6 (armclang) + */ +#elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) + #include "cmsis_armclang.h" + + +/* + * GNU Compiler + */ +#elif defined ( __GNUC__ ) + #include "cmsis_gcc.h" + + +/* + * IAR Compiler + */ +#elif defined ( __ICCARM__ ) + #include + + +/* + * TI Arm Compiler + */ +#elif defined ( __TI_ARM__ ) + #include + + #ifndef __ASM + #define __ASM __asm + #endif + #ifndef __INLINE + #define __INLINE inline + #endif + #ifndef __STATIC_INLINE + #define __STATIC_INLINE static inline + #endif + #ifndef __STATIC_FORCEINLINE + #define __STATIC_FORCEINLINE __STATIC_INLINE + #endif + #ifndef __NO_RETURN + #define __NO_RETURN __attribute__((noreturn)) + #endif + #ifndef __USED + #define __USED __attribute__((used)) + #endif + #ifndef __WEAK + #define __WEAK __attribute__((weak)) + #endif + #ifndef __PACKED + #define __PACKED __attribute__((packed)) + #endif + #ifndef __PACKED_STRUCT + #define __PACKED_STRUCT struct __attribute__((packed)) + #endif + #ifndef __PACKED_UNION + #define __PACKED_UNION union __attribute__((packed)) + #endif + #ifndef __UNALIGNED_UINT32 /* deprecated */ + struct __attribute__((packed)) T_UINT32 { uint32_t v; }; + #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) + #endif + #ifndef __UNALIGNED_UINT16_WRITE + __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; + #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val)) + #endif + #ifndef __UNALIGNED_UINT16_READ + __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; + #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) + #endif + #ifndef __UNALIGNED_UINT32_WRITE + __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; + #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) + #endif + #ifndef __UNALIGNED_UINT32_READ + __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; + #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) + #endif + #ifndef __ALIGNED + #define __ALIGNED(x) __attribute__((aligned(x))) + #endif + #ifndef __RESTRICT + #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored. + #define __RESTRICT + #endif + + +/* + * TASKING Compiler + */ +#elif defined ( __TASKING__ ) + /* + * The CMSIS functions have been implemented as intrinsics in the compiler. + * Please use "carm -?i" to get an up to date list of all intrinsics, + * Including the CMSIS ones. + */ + + #ifndef __ASM + #define __ASM __asm + #endif + #ifndef __INLINE + #define __INLINE inline + #endif + #ifndef __STATIC_INLINE + #define __STATIC_INLINE static inline + #endif + #ifndef __STATIC_FORCEINLINE + #define __STATIC_FORCEINLINE __STATIC_INLINE + #endif + #ifndef __NO_RETURN + #define __NO_RETURN __attribute__((noreturn)) + #endif + #ifndef __USED + #define __USED __attribute__((used)) + #endif + #ifndef __WEAK + #define __WEAK __attribute__((weak)) + #endif + #ifndef __PACKED + #define __PACKED __packed__ + #endif + #ifndef __PACKED_STRUCT + #define __PACKED_STRUCT struct __packed__ + #endif + #ifndef __PACKED_UNION + #define __PACKED_UNION union __packed__ + #endif + #ifndef __UNALIGNED_UINT32 /* deprecated */ + struct __packed__ T_UINT32 { uint32_t v; }; + #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) + #endif + #ifndef __UNALIGNED_UINT16_WRITE + __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; + #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val)) + #endif + #ifndef __UNALIGNED_UINT16_READ + __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; + #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) + #endif + #ifndef __UNALIGNED_UINT32_WRITE + __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; + #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) + #endif + #ifndef __UNALIGNED_UINT32_READ + __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; + #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) + #endif + #ifndef __ALIGNED + #define __ALIGNED(x) __align(x) + #endif + #ifndef __RESTRICT + #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored. + #define __RESTRICT + #endif + + +/* + * COSMIC Compiler + */ +#elif defined ( __CSMC__ ) + #include + + #ifndef __ASM + #define __ASM _asm + #endif + #ifndef __INLINE + #define __INLINE inline + #endif + #ifndef __STATIC_INLINE + #define __STATIC_INLINE static inline + #endif + #ifndef __STATIC_FORCEINLINE + #define __STATIC_FORCEINLINE __STATIC_INLINE + #endif + #ifndef __NO_RETURN + // NO RETURN is automatically detected hence no warning here + #define __NO_RETURN + #endif + #ifndef __USED + #warning No compiler specific solution for __USED. __USED is ignored. + #define __USED + #endif + #ifndef __WEAK + #define __WEAK __weak + #endif + #ifndef __PACKED + #define __PACKED @packed + #endif + #ifndef __PACKED_STRUCT + #define __PACKED_STRUCT @packed struct + #endif + #ifndef __PACKED_UNION + #define __PACKED_UNION @packed union + #endif + #ifndef __UNALIGNED_UINT32 /* deprecated */ + @packed struct T_UINT32 { uint32_t v; }; + #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) + #endif + #ifndef __UNALIGNED_UINT16_WRITE + __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; + #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val)) + #endif + #ifndef __UNALIGNED_UINT16_READ + __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; + #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) + #endif + #ifndef __UNALIGNED_UINT32_WRITE + __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; + #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) + #endif + #ifndef __UNALIGNED_UINT32_READ + __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; + #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) + #endif + #ifndef __ALIGNED + #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored. + #define __ALIGNED(x) + #endif + #ifndef __RESTRICT + #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored. + #define __RESTRICT + #endif + + +#else + #error Unknown compiler. +#endif + + +#endif /* __CMSIS_COMPILER_H */ + diff --git a/Platform/Core/cmsis_gcc.h b/Platform/Core/cmsis_gcc.h new file mode 100644 index 0000000..5d0f07e --- /dev/null +++ b/Platform/Core/cmsis_gcc.h @@ -0,0 +1,2088 @@ +/**************************************************************************//** + * @file cmsis_gcc.h + * @brief CMSIS compiler GCC header file + * @version V5.0.3 + * @date 16. January 2018 + ******************************************************************************/ +/* + * Copyright (c) 2009-2017 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * 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 + * + * 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. + */ + +#ifndef __CMSIS_GCC_H +#define __CMSIS_GCC_H + +/* ignore some GCC warnings */ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wsign-conversion" +#pragma GCC diagnostic ignored "-Wconversion" +#pragma GCC diagnostic ignored "-Wunused-parameter" + +/* Fallback for __has_builtin */ +#ifndef __has_builtin + #define __has_builtin(x) (0) +#endif + +/* CMSIS compiler specific defines */ +#ifndef __ASM + #define __ASM __asm +#endif +#ifndef __INLINE + #define __INLINE inline +#endif +#ifndef __STATIC_INLINE + #define __STATIC_INLINE static inline +#endif +#ifndef __STATIC_FORCEINLINE + #define __STATIC_FORCEINLINE __attribute__((always_inline)) static inline +#endif +#ifndef __NO_RETURN + #define __NO_RETURN __attribute__((__noreturn__)) +#endif +#ifndef __USED + #define __USED __attribute__((used)) +#endif +#ifndef __WEAK + #define __WEAK __attribute__((weak)) +#endif +#ifndef __PACKED + #define __PACKED __attribute__((packed, aligned(1))) +#endif +#ifndef __PACKED_STRUCT + #define __PACKED_STRUCT struct __attribute__((packed, aligned(1))) +#endif +#ifndef __PACKED_UNION + #define __PACKED_UNION union __attribute__((packed, aligned(1))) +#endif +#ifndef __UNALIGNED_UINT32 /* deprecated */ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wpacked" + #pragma GCC diagnostic ignored "-Wattributes" + struct __attribute__((packed)) T_UINT32 { uint32_t v; }; + #pragma GCC diagnostic pop + #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) +#endif +#ifndef __UNALIGNED_UINT16_WRITE + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wpacked" + #pragma GCC diagnostic ignored "-Wattributes" + __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; + #pragma GCC diagnostic pop + #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val)) +#endif +#ifndef __UNALIGNED_UINT16_READ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wpacked" + #pragma GCC diagnostic ignored "-Wattributes" + __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; + #pragma GCC diagnostic pop + #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) +#endif +#ifndef __UNALIGNED_UINT32_WRITE + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wpacked" + #pragma GCC diagnostic ignored "-Wattributes" + __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; + #pragma GCC diagnostic pop + #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) +#endif +#ifndef __UNALIGNED_UINT32_READ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wpacked" + #pragma GCC diagnostic ignored "-Wattributes" + __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; + #pragma GCC diagnostic pop + #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) +#endif +#ifndef __ALIGNED + #define __ALIGNED(x) __attribute__((aligned(x))) +#endif +#ifndef __RESTRICT + #define __RESTRICT __restrict +#endif + + +/* ########################### Core Function Access ########################### */ +/** \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions + @{ + */ + +/** + \brief Enable IRQ Interrupts + \details Enables IRQ interrupts by clearing the I-bit in the CPSR. + Can only be executed in Privileged modes. + */ +__STATIC_FORCEINLINE void __enable_irq(void) +{ + __ASM volatile ("cpsie i" : : : "memory"); +} + + +/** + \brief Disable IRQ Interrupts + \details Disables IRQ interrupts by setting the I-bit in the CPSR. + Can only be executed in Privileged modes. + */ +__STATIC_FORCEINLINE void __disable_irq(void) +{ + __ASM volatile ("cpsid i" : : : "memory"); +} + + +/** + \brief Get Control Register + \details Returns the content of the Control Register. + \return Control Register value + */ +__STATIC_FORCEINLINE uint32_t __get_CONTROL(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, control" : "=r" (result) ); + return(result); +} + + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Get Control Register (non-secure) + \details Returns the content of the non-secure Control Register when in secure mode. + \return non-secure Control Register value + */ +__STATIC_FORCEINLINE uint32_t __TZ_get_CONTROL_NS(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, control_ns" : "=r" (result) ); + return(result); +} +#endif + + +/** + \brief Set Control Register + \details Writes the given value to the Control Register. + \param [in] control Control Register value to set + */ +__STATIC_FORCEINLINE void __set_CONTROL(uint32_t control) +{ + __ASM volatile ("MSR control, %0" : : "r" (control) : "memory"); +} + + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Set Control Register (non-secure) + \details Writes the given value to the non-secure Control Register when in secure state. + \param [in] control Control Register value to set + */ +__STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control) +{ + __ASM volatile ("MSR control_ns, %0" : : "r" (control) : "memory"); +} +#endif + + +/** + \brief Get IPSR Register + \details Returns the content of the IPSR Register. + \return IPSR Register value + */ +__STATIC_FORCEINLINE uint32_t __get_IPSR(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, ipsr" : "=r" (result) ); + return(result); +} + + +/** + \brief Get APSR Register + \details Returns the content of the APSR Register. + \return APSR Register value + */ +__STATIC_FORCEINLINE uint32_t __get_APSR(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, apsr" : "=r" (result) ); + return(result); +} + + +/** + \brief Get xPSR Register + \details Returns the content of the xPSR Register. + \return xPSR Register value + */ +__STATIC_FORCEINLINE uint32_t __get_xPSR(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, xpsr" : "=r" (result) ); + return(result); +} + + +/** + \brief Get Process Stack Pointer + \details Returns the current value of the Process Stack Pointer (PSP). + \return PSP Register value + */ +__STATIC_FORCEINLINE uint32_t __get_PSP(void) +{ + register uint32_t result; + + __ASM volatile ("MRS %0, psp" : "=r" (result) ); + return(result); +} + + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Get Process Stack Pointer (non-secure) + \details Returns the current value of the non-secure Process Stack Pointer (PSP) when in secure state. + \return PSP Register value + */ +__STATIC_FORCEINLINE uint32_t __TZ_get_PSP_NS(void) +{ + register uint32_t result; + + __ASM volatile ("MRS %0, psp_ns" : "=r" (result) ); + return(result); +} +#endif + + +/** + \brief Set Process Stack Pointer + \details Assigns the given value to the Process Stack Pointer (PSP). + \param [in] topOfProcStack Process Stack Pointer value to set + */ +__STATIC_FORCEINLINE void __set_PSP(uint32_t topOfProcStack) +{ + __ASM volatile ("MSR psp, %0" : : "r" (topOfProcStack) : ); +} + + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Set Process Stack Pointer (non-secure) + \details Assigns the given value to the non-secure Process Stack Pointer (PSP) when in secure state. + \param [in] topOfProcStack Process Stack Pointer value to set + */ +__STATIC_FORCEINLINE void __TZ_set_PSP_NS(uint32_t topOfProcStack) +{ + __ASM volatile ("MSR psp_ns, %0" : : "r" (topOfProcStack) : ); +} +#endif + + +/** + \brief Get Main Stack Pointer + \details Returns the current value of the Main Stack Pointer (MSP). + \return MSP Register value + */ +__STATIC_FORCEINLINE uint32_t __get_MSP(void) +{ + register uint32_t result; + + __ASM volatile ("MRS %0, msp" : "=r" (result) ); + return(result); +} + + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Get Main Stack Pointer (non-secure) + \details Returns the current value of the non-secure Main Stack Pointer (MSP) when in secure state. + \return MSP Register value + */ +__STATIC_FORCEINLINE uint32_t __TZ_get_MSP_NS(void) +{ + register uint32_t result; + + __ASM volatile ("MRS %0, msp_ns" : "=r" (result) ); + return(result); +} +#endif + + +/** + \brief Set Main Stack Pointer + \details Assigns the given value to the Main Stack Pointer (MSP). + \param [in] topOfMainStack Main Stack Pointer value to set + */ +__STATIC_FORCEINLINE void __set_MSP(uint32_t topOfMainStack) +{ + __ASM volatile ("MSR msp, %0" : : "r" (topOfMainStack) : ); +} + + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Set Main Stack Pointer (non-secure) + \details Assigns the given value to the non-secure Main Stack Pointer (MSP) when in secure state. + \param [in] topOfMainStack Main Stack Pointer value to set + */ +__STATIC_FORCEINLINE void __TZ_set_MSP_NS(uint32_t topOfMainStack) +{ + __ASM volatile ("MSR msp_ns, %0" : : "r" (topOfMainStack) : ); +} +#endif + + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Get Stack Pointer (non-secure) + \details Returns the current value of the non-secure Stack Pointer (SP) when in secure state. + \return SP Register value + */ +__STATIC_FORCEINLINE uint32_t __TZ_get_SP_NS(void) +{ + register uint32_t result; + + __ASM volatile ("MRS %0, sp_ns" : "=r" (result) ); + return(result); +} + + +/** + \brief Set Stack Pointer (non-secure) + \details Assigns the given value to the non-secure Stack Pointer (SP) when in secure state. + \param [in] topOfStack Stack Pointer value to set + */ +__STATIC_FORCEINLINE void __TZ_set_SP_NS(uint32_t topOfStack) +{ + __ASM volatile ("MSR sp_ns, %0" : : "r" (topOfStack) : ); +} +#endif + + +/** + \brief Get Priority Mask + \details Returns the current state of the priority mask bit from the Priority Mask Register. + \return Priority Mask value + */ +__STATIC_FORCEINLINE uint32_t __get_PRIMASK(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, primask" : "=r" (result) :: "memory"); + return(result); +} + + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Get Priority Mask (non-secure) + \details Returns the current state of the non-secure priority mask bit from the Priority Mask Register when in secure state. + \return Priority Mask value + */ +__STATIC_FORCEINLINE uint32_t __TZ_get_PRIMASK_NS(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, primask_ns" : "=r" (result) :: "memory"); + return(result); +} +#endif + + +/** + \brief Set Priority Mask + \details Assigns the given value to the Priority Mask Register. + \param [in] priMask Priority Mask + */ +__STATIC_FORCEINLINE void __set_PRIMASK(uint32_t priMask) +{ + __ASM volatile ("MSR primask, %0" : : "r" (priMask) : "memory"); +} + + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Set Priority Mask (non-secure) + \details Assigns the given value to the non-secure Priority Mask Register when in secure state. + \param [in] priMask Priority Mask + */ +__STATIC_FORCEINLINE void __TZ_set_PRIMASK_NS(uint32_t priMask) +{ + __ASM volatile ("MSR primask_ns, %0" : : "r" (priMask) : "memory"); +} +#endif + + +#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ + (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) +/** + \brief Enable FIQ + \details Enables FIQ interrupts by clearing the F-bit in the CPSR. + Can only be executed in Privileged modes. + */ +__STATIC_FORCEINLINE void __enable_fault_irq(void) +{ + __ASM volatile ("cpsie f" : : : "memory"); +} + + +/** + \brief Disable FIQ + \details Disables FIQ interrupts by setting the F-bit in the CPSR. + Can only be executed in Privileged modes. + */ +__STATIC_FORCEINLINE void __disable_fault_irq(void) +{ + __ASM volatile ("cpsid f" : : : "memory"); +} + + +/** + \brief Get Base Priority + \details Returns the current value of the Base Priority register. + \return Base Priority register value + */ +__STATIC_FORCEINLINE uint32_t __get_BASEPRI(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, basepri" : "=r" (result) ); + return(result); +} + + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Get Base Priority (non-secure) + \details Returns the current value of the non-secure Base Priority register when in secure state. + \return Base Priority register value + */ +__STATIC_FORCEINLINE uint32_t __TZ_get_BASEPRI_NS(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, basepri_ns" : "=r" (result) ); + return(result); +} +#endif + + +/** + \brief Set Base Priority + \details Assigns the given value to the Base Priority register. + \param [in] basePri Base Priority value to set + */ +__STATIC_FORCEINLINE void __set_BASEPRI(uint32_t basePri) +{ + __ASM volatile ("MSR basepri, %0" : : "r" (basePri) : "memory"); +} + + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Set Base Priority (non-secure) + \details Assigns the given value to the non-secure Base Priority register when in secure state. + \param [in] basePri Base Priority value to set + */ +__STATIC_FORCEINLINE void __TZ_set_BASEPRI_NS(uint32_t basePri) +{ + __ASM volatile ("MSR basepri_ns, %0" : : "r" (basePri) : "memory"); +} +#endif + + +/** + \brief Set Base Priority with condition + \details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled, + or the new value increases the BASEPRI priority level. + \param [in] basePri Base Priority value to set + */ +__STATIC_FORCEINLINE void __set_BASEPRI_MAX(uint32_t basePri) +{ + __ASM volatile ("MSR basepri_max, %0" : : "r" (basePri) : "memory"); +} + + +/** + \brief Get Fault Mask + \details Returns the current value of the Fault Mask register. + \return Fault Mask register value + */ +__STATIC_FORCEINLINE uint32_t __get_FAULTMASK(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, faultmask" : "=r" (result) ); + return(result); +} + + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Get Fault Mask (non-secure) + \details Returns the current value of the non-secure Fault Mask register when in secure state. + \return Fault Mask register value + */ +__STATIC_FORCEINLINE uint32_t __TZ_get_FAULTMASK_NS(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, faultmask_ns" : "=r" (result) ); + return(result); +} +#endif + + +/** + \brief Set Fault Mask + \details Assigns the given value to the Fault Mask register. + \param [in] faultMask Fault Mask value to set + */ +__STATIC_FORCEINLINE void __set_FAULTMASK(uint32_t faultMask) +{ + __ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) : "memory"); +} + + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Set Fault Mask (non-secure) + \details Assigns the given value to the non-secure Fault Mask register when in secure state. + \param [in] faultMask Fault Mask value to set + */ +__STATIC_FORCEINLINE void __TZ_set_FAULTMASK_NS(uint32_t faultMask) +{ + __ASM volatile ("MSR faultmask_ns, %0" : : "r" (faultMask) : "memory"); +} +#endif + +#endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ + (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */ + + +#if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) + +/** + \brief Get Process Stack Pointer Limit + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence zero is returned always in non-secure + mode. + + \details Returns the current value of the Process Stack Pointer Limit (PSPLIM). + \return PSPLIM Register value + */ +__STATIC_FORCEINLINE uint32_t __get_PSPLIM(void) +{ +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ + (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) + // without main extensions, the non-secure PSPLIM is RAZ/WI + return 0U; +#else + register uint32_t result; + __ASM volatile ("MRS %0, psplim" : "=r" (result) ); + return result; +#endif +} + +#if (defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Get Process Stack Pointer Limit (non-secure) + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence zero is returned always. + + \details Returns the current value of the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state. + \return PSPLIM Register value + */ +__STATIC_FORCEINLINE uint32_t __TZ_get_PSPLIM_NS(void) +{ +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))) + // without main extensions, the non-secure PSPLIM is RAZ/WI + return 0U; +#else + register uint32_t result; + __ASM volatile ("MRS %0, psplim_ns" : "=r" (result) ); + return result; +#endif +} +#endif + + +/** + \brief Set Process Stack Pointer Limit + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence the write is silently ignored in non-secure + mode. + + \details Assigns the given value to the Process Stack Pointer Limit (PSPLIM). + \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set + */ +__STATIC_FORCEINLINE void __set_PSPLIM(uint32_t ProcStackPtrLimit) +{ +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ + (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) + // without main extensions, the non-secure PSPLIM is RAZ/WI + (void)ProcStackPtrLimit; +#else + __ASM volatile ("MSR psplim, %0" : : "r" (ProcStackPtrLimit)); +#endif +} + + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Set Process Stack Pointer (non-secure) + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence the write is silently ignored. + + \details Assigns the given value to the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state. + \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set + */ +__STATIC_FORCEINLINE void __TZ_set_PSPLIM_NS(uint32_t ProcStackPtrLimit) +{ +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))) + // without main extensions, the non-secure PSPLIM is RAZ/WI + (void)ProcStackPtrLimit; +#else + __ASM volatile ("MSR psplim_ns, %0\n" : : "r" (ProcStackPtrLimit)); +#endif +} +#endif + + +/** + \brief Get Main Stack Pointer Limit + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence zero is returned always in non-secure + mode. + + \details Returns the current value of the Main Stack Pointer Limit (MSPLIM). + \return MSPLIM Register value + */ +__STATIC_FORCEINLINE uint32_t __get_MSPLIM(void) +{ +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ + (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) + // without main extensions, the non-secure MSPLIM is RAZ/WI + return 0U; +#else + register uint32_t result; + __ASM volatile ("MRS %0, msplim" : "=r" (result) ); + return result; +#endif +} + + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Get Main Stack Pointer Limit (non-secure) + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence zero is returned always. + + \details Returns the current value of the non-secure Main Stack Pointer Limit(MSPLIM) when in secure state. + \return MSPLIM Register value + */ +__STATIC_FORCEINLINE uint32_t __TZ_get_MSPLIM_NS(void) +{ +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))) + // without main extensions, the non-secure MSPLIM is RAZ/WI + return 0U; +#else + register uint32_t result; + __ASM volatile ("MRS %0, msplim_ns" : "=r" (result) ); + return result; +#endif +} +#endif + + +/** + \brief Set Main Stack Pointer Limit + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence the write is silently ignored in non-secure + mode. + + \details Assigns the given value to the Main Stack Pointer Limit (MSPLIM). + \param [in] MainStackPtrLimit Main Stack Pointer Limit value to set + */ +__STATIC_FORCEINLINE void __set_MSPLIM(uint32_t MainStackPtrLimit) +{ +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ + (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) + // without main extensions, the non-secure MSPLIM is RAZ/WI + (void)MainStackPtrLimit; +#else + __ASM volatile ("MSR msplim, %0" : : "r" (MainStackPtrLimit)); +#endif +} + + +#if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) +/** + \brief Set Main Stack Pointer Limit (non-secure) + Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure + Stack Pointer Limit register hence the write is silently ignored. + + \details Assigns the given value to the non-secure Main Stack Pointer Limit (MSPLIM) when in secure state. + \param [in] MainStackPtrLimit Main Stack Pointer value to set + */ +__STATIC_FORCEINLINE void __TZ_set_MSPLIM_NS(uint32_t MainStackPtrLimit) +{ +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))) + // without main extensions, the non-secure MSPLIM is RAZ/WI + (void)MainStackPtrLimit; +#else + __ASM volatile ("MSR msplim_ns, %0" : : "r" (MainStackPtrLimit)); +#endif +} +#endif + +#endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */ + + +#if ((defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ + (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) + +/** + \brief Get FPSCR + \details Returns the current value of the Floating Point Status/Control register. + \return Floating Point Status/Control register value + */ +__STATIC_FORCEINLINE uint32_t __get_FPSCR(void) +{ +#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ + (defined (__FPU_USED ) && (__FPU_USED == 1U)) ) +#if __has_builtin(__builtin_arm_get_fpscr) || (__GNUC__ > 7) || (__GNUC__ == 7 && __GNUC_MINOR__ >= 2) + /* see https://gcc.gnu.org/ml/gcc-patches/2017-04/msg00443.html */ + return __builtin_arm_get_fpscr(); +#else + uint32_t result; + + __ASM volatile ("VMRS %0, fpscr" : "=r" (result) ); + return(result); +#endif +#else + return(0U); +#endif +} + + +/** + \brief Set FPSCR + \details Assigns the given value to the Floating Point Status/Control register. + \param [in] fpscr Floating Point Status/Control value to set + */ +__STATIC_FORCEINLINE void __set_FPSCR(uint32_t fpscr) +{ +#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ + (defined (__FPU_USED ) && (__FPU_USED == 1U)) ) +#if __has_builtin(__builtin_arm_set_fpscr) || (__GNUC__ > 7) || (__GNUC__ == 7 && __GNUC_MINOR__ >= 2) + /* see https://gcc.gnu.org/ml/gcc-patches/2017-04/msg00443.html */ + __builtin_arm_set_fpscr(fpscr); +#else + __ASM volatile ("VMSR fpscr, %0" : : "r" (fpscr) : "vfpcc", "memory"); +#endif +#else + (void)fpscr; +#endif +} + +#endif /* ((defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ + (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */ + + + +/*@} end of CMSIS_Core_RegAccFunctions */ + + +/* ########################## Core Instruction Access ######################### */ +/** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface + Access to dedicated instructions + @{ +*/ + +/* Define macros for porting to both thumb1 and thumb2. + * For thumb1, use low register (r0-r7), specified by constraint "l" + * Otherwise, use general registers, specified by constraint "r" */ +#if defined (__thumb__) && !defined (__thumb2__) +#define __CMSIS_GCC_OUT_REG(r) "=l" (r) +#define __CMSIS_GCC_RW_REG(r) "+l" (r) +#define __CMSIS_GCC_USE_REG(r) "l" (r) +#else +#define __CMSIS_GCC_OUT_REG(r) "=r" (r) +#define __CMSIS_GCC_RW_REG(r) "+r" (r) +#define __CMSIS_GCC_USE_REG(r) "r" (r) +#endif + +/** + \brief No Operation + \details No Operation does nothing. This instruction can be used for code alignment purposes. + */ +#define __NOP() __ASM volatile ("nop") + +/** + \brief Wait For Interrupt + \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs. + */ +#define __WFI() __ASM volatile ("wfi") + + +/** + \brief Wait For Event + \details Wait For Event is a hint instruction that permits the processor to enter + a low-power state until one of a number of events occurs. + */ +#define __WFE() __ASM volatile ("wfe") + + +/** + \brief Send Event + \details Send Event is a hint instruction. It causes an event to be signaled to the CPU. + */ +#define __SEV() __ASM volatile ("sev") + + +/** + \brief Instruction Synchronization Barrier + \details Instruction Synchronization Barrier flushes the pipeline in the processor, + so that all instructions following the ISB are fetched from cache or memory, + after the instruction has been completed. + */ +__STATIC_FORCEINLINE void __ISB(void) +{ + __ASM volatile ("isb 0xF":::"memory"); +} + + +/** + \brief Data Synchronization Barrier + \details Acts as a special kind of Data Memory Barrier. + It completes when all explicit memory accesses before this instruction complete. + */ +__STATIC_FORCEINLINE void __DSB(void) +{ + __ASM volatile ("dsb 0xF":::"memory"); +} + + +/** + \brief Data Memory Barrier + \details Ensures the apparent order of the explicit memory operations before + and after the instruction, without ensuring their completion. + */ +__STATIC_FORCEINLINE void __DMB(void) +{ + __ASM volatile ("dmb 0xF":::"memory"); +} + + +/** + \brief Reverse byte order (32 bit) + \details Reverses the byte order in unsigned integer value. For example, 0x12345678 becomes 0x78563412. + \param [in] value Value to reverse + \return Reversed value + */ +__STATIC_FORCEINLINE uint32_t __REV(uint32_t value) +{ +#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) + return __builtin_bswap32(value); +#else + uint32_t result; + + __ASM volatile ("rev %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) ); + return result; +#endif +} + + +/** + \brief Reverse byte order (16 bit) + \details Reverses the byte order within each halfword of a word. For example, 0x12345678 becomes 0x34127856. + \param [in] value Value to reverse + \return Reversed value + */ +__STATIC_FORCEINLINE uint32_t __REV16(uint32_t value) +{ + uint32_t result; + + __ASM volatile ("rev16 %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) ); + return result; +} + + +/** + \brief Reverse byte order (16 bit) + \details Reverses the byte order in a 16-bit value and returns the signed 16-bit result. For example, 0x0080 becomes 0x8000. + \param [in] value Value to reverse + \return Reversed value + */ +__STATIC_FORCEINLINE int16_t __REVSH(int16_t value) +{ +#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) + return (int16_t)__builtin_bswap16(value); +#else + int16_t result; + + __ASM volatile ("revsh %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) ); + return result; +#endif +} + + +/** + \brief Rotate Right in unsigned value (32 bit) + \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits. + \param [in] op1 Value to rotate + \param [in] op2 Number of Bits to rotate + \return Rotated value + */ +__STATIC_FORCEINLINE uint32_t __ROR(uint32_t op1, uint32_t op2) +{ + op2 %= 32U; + if (op2 == 0U) + { + return op1; + } + return (op1 >> op2) | (op1 << (32U - op2)); +} + + +/** + \brief Breakpoint + \details Causes the processor to enter Debug state. + Debug tools can use this to investigate system state when the instruction at a particular address is reached. + \param [in] value is ignored by the processor. + If required, a debugger can use it to store additional information about the breakpoint. + */ +#define __BKPT(value) __ASM volatile ("bkpt "#value) + + +/** + \brief Reverse bit order of value + \details Reverses the bit order of the given value. + \param [in] value Value to reverse + \return Reversed value + */ +__STATIC_FORCEINLINE uint32_t __RBIT(uint32_t value) +{ + uint32_t result; + +#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ + (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) + __ASM volatile ("rbit %0, %1" : "=r" (result) : "r" (value) ); +#else + uint32_t s = (4U /*sizeof(v)*/ * 8U) - 1U; /* extra shift needed at end */ + + result = value; /* r will be reversed bits of v; first get LSB of v */ + for (value >>= 1U; value != 0U; value >>= 1U) + { + result <<= 1U; + result |= value & 1U; + s--; + } + result <<= s; /* shift when v's highest bits are zero */ +#endif + return result; +} + + +/** + \brief Count leading zeros + \details Counts the number of leading zeros of a data value. + \param [in] value Value to count the leading zeros + \return number of leading zeros in value + */ +#define __CLZ (uint8_t)__builtin_clz + + +#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ + (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) +/** + \brief LDR Exclusive (8 bit) + \details Executes a exclusive LDR instruction for 8 bit value. + \param [in] ptr Pointer to data + \return value of type uint8_t at (*ptr) + */ +__STATIC_FORCEINLINE uint8_t __LDREXB(volatile uint8_t *addr) +{ + uint32_t result; + +#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) + __ASM volatile ("ldrexb %0, %1" : "=r" (result) : "Q" (*addr) ); +#else + /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not + accepted by assembler. So has to use following less efficient pattern. + */ + __ASM volatile ("ldrexb %0, [%1]" : "=r" (result) : "r" (addr) : "memory" ); +#endif + return ((uint8_t) result); /* Add explicit type cast here */ +} + + +/** + \brief LDR Exclusive (16 bit) + \details Executes a exclusive LDR instruction for 16 bit values. + \param [in] ptr Pointer to data + \return value of type uint16_t at (*ptr) + */ +__STATIC_FORCEINLINE uint16_t __LDREXH(volatile uint16_t *addr) +{ + uint32_t result; + +#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) + __ASM volatile ("ldrexh %0, %1" : "=r" (result) : "Q" (*addr) ); +#else + /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not + accepted by assembler. So has to use following less efficient pattern. + */ + __ASM volatile ("ldrexh %0, [%1]" : "=r" (result) : "r" (addr) : "memory" ); +#endif + return ((uint16_t) result); /* Add explicit type cast here */ +} + + +/** + \brief LDR Exclusive (32 bit) + \details Executes a exclusive LDR instruction for 32 bit values. + \param [in] ptr Pointer to data + \return value of type uint32_t at (*ptr) + */ +__STATIC_FORCEINLINE uint32_t __LDREXW(volatile uint32_t *addr) +{ + uint32_t result; + + __ASM volatile ("ldrex %0, %1" : "=r" (result) : "Q" (*addr) ); + return(result); +} + + +/** + \brief STR Exclusive (8 bit) + \details Executes a exclusive STR instruction for 8 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed + */ +__STATIC_FORCEINLINE uint32_t __STREXB(uint8_t value, volatile uint8_t *addr) +{ + uint32_t result; + + __ASM volatile ("strexb %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) ); + return(result); +} + + +/** + \brief STR Exclusive (16 bit) + \details Executes a exclusive STR instruction for 16 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed + */ +__STATIC_FORCEINLINE uint32_t __STREXH(uint16_t value, volatile uint16_t *addr) +{ + uint32_t result; + + __ASM volatile ("strexh %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) ); + return(result); +} + + +/** + \brief STR Exclusive (32 bit) + \details Executes a exclusive STR instruction for 32 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed + */ +__STATIC_FORCEINLINE uint32_t __STREXW(uint32_t value, volatile uint32_t *addr) +{ + uint32_t result; + + __ASM volatile ("strex %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" (value) ); + return(result); +} + + +/** + \brief Remove the exclusive lock + \details Removes the exclusive lock which is created by LDREX. + */ +__STATIC_FORCEINLINE void __CLREX(void) +{ + __ASM volatile ("clrex" ::: "memory"); +} + +#endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ + (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */ + + +#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ + (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) +/** + \brief Signed Saturate + \details Saturates a signed value. + \param [in] ARG1 Value to be saturated + \param [in] ARG2 Bit position to saturate to (1..32) + \return Saturated value + */ +#define __SSAT(ARG1,ARG2) \ +__extension__ \ +({ \ + int32_t __RES, __ARG1 = (ARG1); \ + __ASM ("ssat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \ + __RES; \ + }) + + +/** + \brief Unsigned Saturate + \details Saturates an unsigned value. + \param [in] ARG1 Value to be saturated + \param [in] ARG2 Bit position to saturate to (0..31) + \return Saturated value + */ +#define __USAT(ARG1,ARG2) \ + __extension__ \ +({ \ + uint32_t __RES, __ARG1 = (ARG1); \ + __ASM ("usat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \ + __RES; \ + }) + + +/** + \brief Rotate Right with Extend (32 bit) + \details Moves each bit of a bitstring right by one bit. + The carry input is shifted in at the left end of the bitstring. + \param [in] value Value to rotate + \return Rotated value + */ +__STATIC_FORCEINLINE uint32_t __RRX(uint32_t value) +{ + uint32_t result; + + __ASM volatile ("rrx %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) ); + return(result); +} + + +/** + \brief LDRT Unprivileged (8 bit) + \details Executes a Unprivileged LDRT instruction for 8 bit value. + \param [in] ptr Pointer to data + \return value of type uint8_t at (*ptr) + */ +__STATIC_FORCEINLINE uint8_t __LDRBT(volatile uint8_t *ptr) +{ + uint32_t result; + +#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) + __ASM volatile ("ldrbt %0, %1" : "=r" (result) : "Q" (*ptr) ); +#else + /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not + accepted by assembler. So has to use following less efficient pattern. + */ + __ASM volatile ("ldrbt %0, [%1]" : "=r" (result) : "r" (ptr) : "memory" ); +#endif + return ((uint8_t) result); /* Add explicit type cast here */ +} + + +/** + \brief LDRT Unprivileged (16 bit) + \details Executes a Unprivileged LDRT instruction for 16 bit values. + \param [in] ptr Pointer to data + \return value of type uint16_t at (*ptr) + */ +__STATIC_FORCEINLINE uint16_t __LDRHT(volatile uint16_t *ptr) +{ + uint32_t result; + +#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) + __ASM volatile ("ldrht %0, %1" : "=r" (result) : "Q" (*ptr) ); +#else + /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not + accepted by assembler. So has to use following less efficient pattern. + */ + __ASM volatile ("ldrht %0, [%1]" : "=r" (result) : "r" (ptr) : "memory" ); +#endif + return ((uint16_t) result); /* Add explicit type cast here */ +} + + +/** + \brief LDRT Unprivileged (32 bit) + \details Executes a Unprivileged LDRT instruction for 32 bit values. + \param [in] ptr Pointer to data + \return value of type uint32_t at (*ptr) + */ +__STATIC_FORCEINLINE uint32_t __LDRT(volatile uint32_t *ptr) +{ + uint32_t result; + + __ASM volatile ("ldrt %0, %1" : "=r" (result) : "Q" (*ptr) ); + return(result); +} + + +/** + \brief STRT Unprivileged (8 bit) + \details Executes a Unprivileged STRT instruction for 8 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + */ +__STATIC_FORCEINLINE void __STRBT(uint8_t value, volatile uint8_t *ptr) +{ + __ASM volatile ("strbt %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) ); +} + + +/** + \brief STRT Unprivileged (16 bit) + \details Executes a Unprivileged STRT instruction for 16 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + */ +__STATIC_FORCEINLINE void __STRHT(uint16_t value, volatile uint16_t *ptr) +{ + __ASM volatile ("strht %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) ); +} + + +/** + \brief STRT Unprivileged (32 bit) + \details Executes a Unprivileged STRT instruction for 32 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + */ +__STATIC_FORCEINLINE void __STRT(uint32_t value, volatile uint32_t *ptr) +{ + __ASM volatile ("strt %1, %0" : "=Q" (*ptr) : "r" (value) ); +} + +#else /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ + (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */ + +/** + \brief Signed Saturate + \details Saturates a signed value. + \param [in] value Value to be saturated + \param [in] sat Bit position to saturate to (1..32) + \return Saturated value + */ +__STATIC_FORCEINLINE int32_t __SSAT(int32_t val, uint32_t sat) +{ + if ((sat >= 1U) && (sat <= 32U)) + { + const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U); + const int32_t min = -1 - max ; + if (val > max) + { + return max; + } + else if (val < min) + { + return min; + } + } + return val; +} + +/** + \brief Unsigned Saturate + \details Saturates an unsigned value. + \param [in] value Value to be saturated + \param [in] sat Bit position to saturate to (0..31) + \return Saturated value + */ +__STATIC_FORCEINLINE uint32_t __USAT(int32_t val, uint32_t sat) +{ + if (sat <= 31U) + { + const uint32_t max = ((1U << sat) - 1U); + if (val > (int32_t)max) + { + return max; + } + else if (val < 0) + { + return 0U; + } + } + return (uint32_t)val; +} + +#endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ + (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ + (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */ + + +#if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) +/** + \brief Load-Acquire (8 bit) + \details Executes a LDAB instruction for 8 bit value. + \param [in] ptr Pointer to data + \return value of type uint8_t at (*ptr) + */ +__STATIC_FORCEINLINE uint8_t __LDAB(volatile uint8_t *ptr) +{ + uint32_t result; + + __ASM volatile ("ldab %0, %1" : "=r" (result) : "Q" (*ptr) ); + return ((uint8_t) result); +} + + +/** + \brief Load-Acquire (16 bit) + \details Executes a LDAH instruction for 16 bit values. + \param [in] ptr Pointer to data + \return value of type uint16_t at (*ptr) + */ +__STATIC_FORCEINLINE uint16_t __LDAH(volatile uint16_t *ptr) +{ + uint32_t result; + + __ASM volatile ("ldah %0, %1" : "=r" (result) : "Q" (*ptr) ); + return ((uint16_t) result); +} + + +/** + \brief Load-Acquire (32 bit) + \details Executes a LDA instruction for 32 bit values. + \param [in] ptr Pointer to data + \return value of type uint32_t at (*ptr) + */ +__STATIC_FORCEINLINE uint32_t __LDA(volatile uint32_t *ptr) +{ + uint32_t result; + + __ASM volatile ("lda %0, %1" : "=r" (result) : "Q" (*ptr) ); + return(result); +} + + +/** + \brief Store-Release (8 bit) + \details Executes a STLB instruction for 8 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + */ +__STATIC_FORCEINLINE void __STLB(uint8_t value, volatile uint8_t *ptr) +{ + __ASM volatile ("stlb %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) ); +} + + +/** + \brief Store-Release (16 bit) + \details Executes a STLH instruction for 16 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + */ +__STATIC_FORCEINLINE void __STLH(uint16_t value, volatile uint16_t *ptr) +{ + __ASM volatile ("stlh %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) ); +} + + +/** + \brief Store-Release (32 bit) + \details Executes a STL instruction for 32 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + */ +__STATIC_FORCEINLINE void __STL(uint32_t value, volatile uint32_t *ptr) +{ + __ASM volatile ("stl %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) ); +} + + +/** + \brief Load-Acquire Exclusive (8 bit) + \details Executes a LDAB exclusive instruction for 8 bit value. + \param [in] ptr Pointer to data + \return value of type uint8_t at (*ptr) + */ +__STATIC_FORCEINLINE uint8_t __LDAEXB(volatile uint8_t *ptr) +{ + uint32_t result; + + __ASM volatile ("ldaexb %0, %1" : "=r" (result) : "Q" (*ptr) ); + return ((uint8_t) result); +} + + +/** + \brief Load-Acquire Exclusive (16 bit) + \details Executes a LDAH exclusive instruction for 16 bit values. + \param [in] ptr Pointer to data + \return value of type uint16_t at (*ptr) + */ +__STATIC_FORCEINLINE uint16_t __LDAEXH(volatile uint16_t *ptr) +{ + uint32_t result; + + __ASM volatile ("ldaexh %0, %1" : "=r" (result) : "Q" (*ptr) ); + return ((uint16_t) result); +} + + +/** + \brief Load-Acquire Exclusive (32 bit) + \details Executes a LDA exclusive instruction for 32 bit values. + \param [in] ptr Pointer to data + \return value of type uint32_t at (*ptr) + */ +__STATIC_FORCEINLINE uint32_t __LDAEX(volatile uint32_t *ptr) +{ + uint32_t result; + + __ASM volatile ("ldaex %0, %1" : "=r" (result) : "Q" (*ptr) ); + return(result); +} + + +/** + \brief Store-Release Exclusive (8 bit) + \details Executes a STLB exclusive instruction for 8 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed + */ +__STATIC_FORCEINLINE uint32_t __STLEXB(uint8_t value, volatile uint8_t *ptr) +{ + uint32_t result; + + __ASM volatile ("stlexb %0, %2, %1" : "=&r" (result), "=Q" (*ptr) : "r" ((uint32_t)value) ); + return(result); +} + + +/** + \brief Store-Release Exclusive (16 bit) + \details Executes a STLH exclusive instruction for 16 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed + */ +__STATIC_FORCEINLINE uint32_t __STLEXH(uint16_t value, volatile uint16_t *ptr) +{ + uint32_t result; + + __ASM volatile ("stlexh %0, %2, %1" : "=&r" (result), "=Q" (*ptr) : "r" ((uint32_t)value) ); + return(result); +} + + +/** + \brief Store-Release Exclusive (32 bit) + \details Executes a STL exclusive instruction for 32 bit values. + \param [in] value Value to store + \param [in] ptr Pointer to location + \return 0 Function succeeded + \return 1 Function failed + */ +__STATIC_FORCEINLINE uint32_t __STLEX(uint32_t value, volatile uint32_t *ptr) +{ + uint32_t result; + + __ASM volatile ("stlex %0, %2, %1" : "=&r" (result), "=Q" (*ptr) : "r" ((uint32_t)value) ); + return(result); +} + +#endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */ + +/*@}*/ /* end of group CMSIS_Core_InstructionInterface */ + + +/* ################### Compiler specific Intrinsics ########################### */ +/** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics + Access to dedicated SIMD instructions + @{ +*/ + +#if (defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1)) + +__STATIC_FORCEINLINE uint32_t __SADD8(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("sadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __QADD8(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("qadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __SHADD8(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("shadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __UADD8(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __UQADD8(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uqadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __UHADD8(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uhadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + + +__STATIC_FORCEINLINE uint32_t __SSUB8(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("ssub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __QSUB8(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("qsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __SHSUB8(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("shsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __USUB8(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("usub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __UQSUB8(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uqsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __UHSUB8(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uhsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + + +__STATIC_FORCEINLINE uint32_t __SADD16(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("sadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __QADD16(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("qadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __SHADD16(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("shadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __UADD16(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __UQADD16(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uqadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __UHADD16(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uhadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __SSUB16(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("ssub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __QSUB16(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("qsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __SHSUB16(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("shsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __USUB16(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("usub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __UQSUB16(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uqsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __UHSUB16(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uhsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __SASX(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("sasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __QASX(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("qasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __SHASX(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("shasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __UASX(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __UQASX(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uqasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __UHASX(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uhasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __SSAX(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("ssax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __QSAX(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("qsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __SHSAX(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("shsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __USAX(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("usax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __UQSAX(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uqsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __UHSAX(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uhsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __USAD8(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("usad8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __USADA8(uint32_t op1, uint32_t op2, uint32_t op3) +{ + uint32_t result; + + __ASM volatile ("usada8 %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) ); + return(result); +} + +#define __SSAT16(ARG1,ARG2) \ +({ \ + int32_t __RES, __ARG1 = (ARG1); \ + __ASM ("ssat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \ + __RES; \ + }) + +#define __USAT16(ARG1,ARG2) \ +({ \ + uint32_t __RES, __ARG1 = (ARG1); \ + __ASM ("usat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \ + __RES; \ + }) + +__STATIC_FORCEINLINE uint32_t __UXTB16(uint32_t op1) +{ + uint32_t result; + + __ASM volatile ("uxtb16 %0, %1" : "=r" (result) : "r" (op1)); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __UXTAB16(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __SXTB16(uint32_t op1) +{ + uint32_t result; + + __ASM volatile ("sxtb16 %0, %1" : "=r" (result) : "r" (op1)); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __SXTAB16(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("sxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __SMUAD (uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("smuad %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __SMUADX (uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("smuadx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __SMLAD (uint32_t op1, uint32_t op2, uint32_t op3) +{ + uint32_t result; + + __ASM volatile ("smlad %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __SMLADX (uint32_t op1, uint32_t op2, uint32_t op3) +{ + uint32_t result; + + __ASM volatile ("smladx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) ); + return(result); +} + +__STATIC_FORCEINLINE uint64_t __SMLALD (uint32_t op1, uint32_t op2, uint64_t acc) +{ + union llreg_u{ + uint32_t w32[2]; + uint64_t w64; + } llr; + llr.w64 = acc; + +#ifndef __ARMEB__ /* Little endian */ + __ASM volatile ("smlald %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) ); +#else /* Big endian */ + __ASM volatile ("smlald %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) ); +#endif + + return(llr.w64); +} + +__STATIC_FORCEINLINE uint64_t __SMLALDX (uint32_t op1, uint32_t op2, uint64_t acc) +{ + union llreg_u{ + uint32_t w32[2]; + uint64_t w64; + } llr; + llr.w64 = acc; + +#ifndef __ARMEB__ /* Little endian */ + __ASM volatile ("smlaldx %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) ); +#else /* Big endian */ + __ASM volatile ("smlaldx %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) ); +#endif + + return(llr.w64); +} + +__STATIC_FORCEINLINE uint32_t __SMUSD (uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("smusd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __SMUSDX (uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("smusdx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __SMLSD (uint32_t op1, uint32_t op2, uint32_t op3) +{ + uint32_t result; + + __ASM volatile ("smlsd %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) ); + return(result); +} + +__STATIC_FORCEINLINE uint32_t __SMLSDX (uint32_t op1, uint32_t op2, uint32_t op3) +{ + uint32_t result; + + __ASM volatile ("smlsdx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) ); + return(result); +} + +__STATIC_FORCEINLINE uint64_t __SMLSLD (uint32_t op1, uint32_t op2, uint64_t acc) +{ + union llreg_u{ + uint32_t w32[2]; + uint64_t w64; + } llr; + llr.w64 = acc; + +#ifndef __ARMEB__ /* Little endian */ + __ASM volatile ("smlsld %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) ); +#else /* Big endian */ + __ASM volatile ("smlsld %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) ); +#endif + + return(llr.w64); +} + +__STATIC_FORCEINLINE uint64_t __SMLSLDX (uint32_t op1, uint32_t op2, uint64_t acc) +{ + union llreg_u{ + uint32_t w32[2]; + uint64_t w64; + } llr; + llr.w64 = acc; + +#ifndef __ARMEB__ /* Little endian */ + __ASM volatile ("smlsldx %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) ); +#else /* Big endian */ + __ASM volatile ("smlsldx %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) ); +#endif + + return(llr.w64); +} + +__STATIC_FORCEINLINE uint32_t __SEL (uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("sel %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE int32_t __QADD( int32_t op1, int32_t op2) +{ + int32_t result; + + __ASM volatile ("qadd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__STATIC_FORCEINLINE int32_t __QSUB( int32_t op1, int32_t op2) +{ + int32_t result; + + __ASM volatile ("qsub %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +#if 0 +#define __PKHBT(ARG1,ARG2,ARG3) \ +({ \ + uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \ + __ASM ("pkhbt %0, %1, %2, lsl %3" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2), "I" (ARG3) ); \ + __RES; \ + }) + +#define __PKHTB(ARG1,ARG2,ARG3) \ +({ \ + uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \ + if (ARG3 == 0) \ + __ASM ("pkhtb %0, %1, %2" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2) ); \ + else \ + __ASM ("pkhtb %0, %1, %2, asr %3" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2), "I" (ARG3) ); \ + __RES; \ + }) +#endif + +#define __PKHBT(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0x0000FFFFUL) | \ + ((((uint32_t)(ARG2)) << (ARG3)) & 0xFFFF0000UL) ) + +#define __PKHTB(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0xFFFF0000UL) | \ + ((((uint32_t)(ARG2)) >> (ARG3)) & 0x0000FFFFUL) ) + +__STATIC_FORCEINLINE int32_t __SMMLA (int32_t op1, int32_t op2, int32_t op3) +{ + int32_t result; + + __ASM volatile ("smmla %0, %1, %2, %3" : "=r" (result): "r" (op1), "r" (op2), "r" (op3) ); + return(result); +} + +#endif /* (__ARM_FEATURE_DSP == 1) */ +/*@} end of group CMSIS_SIMD_intrinsics */ + + +#pragma GCC diagnostic pop + +#endif /* __CMSIS_GCC_H */ diff --git a/Platform/Core/cmsis_iccarm.h b/Platform/Core/cmsis_iccarm.h new file mode 100644 index 0000000..1bd201a --- /dev/null +++ b/Platform/Core/cmsis_iccarm.h @@ -0,0 +1,913 @@ +/**************************************************************************//** + * @file cmsis_iccarm.h + * @brief CMSIS compiler ICCARM (IAR Compiler for Arm) header file + * @version V5.0.5 + * @date 10. January 2018 + ******************************************************************************/ + +/*------------------------------------------------------------------------------ + + Copyright (c) 2017-2018 IAR Systems + +// 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. +// +------------------------------------------------------------------------------*/ + + +#ifndef __CMSIS_ICCARM_H__ +#define __CMSIS_ICCARM_H__ + +#ifndef __ICCARM__ + #error This file should only be compiled by ICCARM +#endif + +#pragma system_include + +#define __IAR_FT _Pragma("inline=forced") __intrinsic + +#if (__VER__ >= 8000000) + #define __ICCARM_V8 1 +#else + #define __ICCARM_V8 0 +#endif + +#ifndef __ALIGNED + #if __ICCARM_V8 + #define __ALIGNED(x) __attribute__((aligned(x))) + #elif (__VER__ >= 7080000) + /* Needs IAR language extensions */ + #define __ALIGNED(x) __attribute__((aligned(x))) + #else + #warning No compiler specific solution for __ALIGNED.__ALIGNED is ignored. + #define __ALIGNED(x) + #endif +#endif + + +/* Define compiler macros for CPU architecture, used in CMSIS 5. + */ +#if __ARM_ARCH_6M__ || __ARM_ARCH_7M__ || __ARM_ARCH_7EM__ || __ARM_ARCH_8M_BASE__ || __ARM_ARCH_8M_MAIN__ +/* Macros already defined */ +#else + #if defined(__ARM8M_MAINLINE__) || defined(__ARM8EM_MAINLINE__) + #define __ARM_ARCH_8M_MAIN__ 1 + #elif defined(__ARM8M_BASELINE__) + #define __ARM_ARCH_8M_BASE__ 1 + #elif defined(__ARM_ARCH_PROFILE) && __ARM_ARCH_PROFILE == 'M' + #if __ARM_ARCH == 6 + #define __ARM_ARCH_6M__ 1 + #elif __ARM_ARCH == 7 + #if __ARM_FEATURE_DSP + #define __ARM_ARCH_7EM__ 1 + #else + #define __ARM_ARCH_7M__ 1 + #endif + #endif /* __ARM_ARCH */ + #endif /* __ARM_ARCH_PROFILE == 'M' */ +#endif + +/* Alternativ core deduction for older ICCARM's */ +#if !defined(__ARM_ARCH_6M__) && !defined(__ARM_ARCH_7M__) && !defined(__ARM_ARCH_7EM__) && \ + !defined(__ARM_ARCH_8M_BASE__) && !defined(__ARM_ARCH_8M_MAIN__) + #if defined(__ARM6M__) && (__CORE__ == __ARM6M__) + #define __ARM_ARCH_6M__ 1 + #elif defined(__ARM7M__) && (__CORE__ == __ARM7M__) + #define __ARM_ARCH_7M__ 1 + #elif defined(__ARM7EM__) && (__CORE__ == __ARM7EM__) + #define __ARM_ARCH_7EM__ 1 + #elif defined(__ARM8M_BASELINE__) && (__CORE == __ARM8M_BASELINE__) + #define __ARM_ARCH_8M_BASE__ 1 + #elif defined(__ARM8M_MAINLINE__) && (__CORE == __ARM8M_MAINLINE__) + #define __ARM_ARCH_8M_MAIN__ 1 + #elif defined(__ARM8EM_MAINLINE__) && (__CORE == __ARM8EM_MAINLINE__) + #define __ARM_ARCH_8M_MAIN__ 1 + #else + #error "Unknown target." + #endif +#endif + + + +#if defined(__ARM_ARCH_6M__) && __ARM_ARCH_6M__==1 + #define __IAR_M0_FAMILY 1 +#elif defined(__ARM_ARCH_8M_BASE__) && __ARM_ARCH_8M_BASE__==1 + #define __IAR_M0_FAMILY 1 +#else + #define __IAR_M0_FAMILY 0 +#endif + + +#ifndef __ASM + #define __ASM __asm +#endif + +#ifndef __INLINE + #define __INLINE inline +#endif + +#ifndef __NO_RETURN + #if __ICCARM_V8 + #define __NO_RETURN __attribute__((__noreturn__)) + #else + #define __NO_RETURN _Pragma("object_attribute=__noreturn") + #endif +#endif + +#ifndef __PACKED + #if __ICCARM_V8 + #define __PACKED __attribute__((packed, aligned(1))) + #else + /* Needs IAR language extensions */ + #define __PACKED __packed + #endif +#endif + +#ifndef __PACKED_STRUCT + #if __ICCARM_V8 + #define __PACKED_STRUCT struct __attribute__((packed, aligned(1))) + #else + /* Needs IAR language extensions */ + #define __PACKED_STRUCT __packed struct + #endif +#endif + +#ifndef __PACKED_UNION + #if __ICCARM_V8 + #define __PACKED_UNION union __attribute__((packed, aligned(1))) + #else + /* Needs IAR language extensions */ + #define __PACKED_UNION __packed union + #endif +#endif + +#ifndef __RESTRICT +#define __RESTRICT __restrict +#endif + +#ifndef __STATIC_INLINE + #define __STATIC_INLINE static inline +#endif + +#ifndef __FORCEINLINE + #define __FORCEINLINE _Pragma("inline=forced") +#endif + +#ifndef __STATIC_FORCEINLINE + #define __STATIC_FORCEINLINE __FORCEINLINE __STATIC_INLINE +#endif + +#ifndef __UNALIGNED_UINT16_READ +#pragma language=save +#pragma language=extended +__IAR_FT uint16_t __iar_uint16_read(void const *ptr) +{ + return *(__packed uint16_t*)(ptr); +} +#pragma language=restore +#define __UNALIGNED_UINT16_READ(PTR) __iar_uint16_read(PTR) +#endif + + +#ifndef __UNALIGNED_UINT16_WRITE +#pragma language=save +#pragma language=extended +__IAR_FT void __iar_uint16_write(void const *ptr, uint16_t val) +{ + *(__packed uint16_t*)(ptr) = val;; +} +#pragma language=restore +#define __UNALIGNED_UINT16_WRITE(PTR,VAL) __iar_uint16_write(PTR,VAL) +#endif + +#ifndef __UNALIGNED_UINT32_READ +#pragma language=save +#pragma language=extended +__IAR_FT uint32_t __iar_uint32_read(void const *ptr) +{ + return *(__packed uint32_t*)(ptr); +} +#pragma language=restore +#define __UNALIGNED_UINT32_READ(PTR) __iar_uint32_read(PTR) +#endif + +#ifndef __UNALIGNED_UINT32_WRITE +#pragma language=save +#pragma language=extended +__IAR_FT void __iar_uint32_write(void const *ptr, uint32_t val) +{ + *(__packed uint32_t*)(ptr) = val;; +} +#pragma language=restore +#define __UNALIGNED_UINT32_WRITE(PTR,VAL) __iar_uint32_write(PTR,VAL) +#endif + +#ifndef __UNALIGNED_UINT32 /* deprecated */ +#pragma language=save +#pragma language=extended +__packed struct __iar_u32 { uint32_t v; }; +#pragma language=restore +#define __UNALIGNED_UINT32(PTR) (((struct __iar_u32 *)(PTR))->v) +#endif + +#ifndef __USED + #if __ICCARM_V8 + #define __USED __attribute__((used)) + #else + #define __USED _Pragma("__root") + #endif +#endif + +#ifndef __WEAK + #if __ICCARM_V8 + #define __WEAK __attribute__((weak)) + #else + #define __WEAK _Pragma("__weak") + #endif +#endif + + +#ifndef __ICCARM_INTRINSICS_VERSION__ + #define __ICCARM_INTRINSICS_VERSION__ 0 +#endif + +#if __ICCARM_INTRINSICS_VERSION__ == 2 + + #if defined(__CLZ) + #undef __CLZ + #endif + #if defined(__REVSH) + #undef __REVSH + #endif + #if defined(__RBIT) + #undef __RBIT + #endif + #if defined(__SSAT) + #undef __SSAT + #endif + #if defined(__USAT) + #undef __USAT + #endif + + #include "iccarm_builtin.h" + + #define __disable_fault_irq __iar_builtin_disable_fiq + #define __disable_irq __iar_builtin_disable_interrupt + #define __enable_fault_irq __iar_builtin_enable_fiq + #define __enable_irq __iar_builtin_enable_interrupt + #define __arm_rsr __iar_builtin_rsr + #define __arm_wsr __iar_builtin_wsr + + + #define __get_APSR() (__arm_rsr("APSR")) + #define __get_BASEPRI() (__arm_rsr("BASEPRI")) + #define __get_CONTROL() (__arm_rsr("CONTROL")) + #define __get_FAULTMASK() (__arm_rsr("FAULTMASK")) + + #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ + (defined (__FPU_USED ) && (__FPU_USED == 1U)) ) + #define __get_FPSCR() (__arm_rsr("FPSCR")) + #define __set_FPSCR(VALUE) (__arm_wsr("FPSCR", (VALUE))) + #else + #define __get_FPSCR() ( 0 ) + #define __set_FPSCR(VALUE) ((void)VALUE) + #endif + + #define __get_IPSR() (__arm_rsr("IPSR")) + #define __get_MSP() (__arm_rsr("MSP")) + #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ + (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) + // without main extensions, the non-secure MSPLIM is RAZ/WI + #define __get_MSPLIM() (0U) + #else + #define __get_MSPLIM() (__arm_rsr("MSPLIM")) + #endif + #define __get_PRIMASK() (__arm_rsr("PRIMASK")) + #define __get_PSP() (__arm_rsr("PSP")) + + #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ + (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) + // without main extensions, the non-secure PSPLIM is RAZ/WI + #define __get_PSPLIM() (0U) + #else + #define __get_PSPLIM() (__arm_rsr("PSPLIM")) + #endif + + #define __get_xPSR() (__arm_rsr("xPSR")) + + #define __set_BASEPRI(VALUE) (__arm_wsr("BASEPRI", (VALUE))) + #define __set_BASEPRI_MAX(VALUE) (__arm_wsr("BASEPRI_MAX", (VALUE))) + #define __set_CONTROL(VALUE) (__arm_wsr("CONTROL", (VALUE))) + #define __set_FAULTMASK(VALUE) (__arm_wsr("FAULTMASK", (VALUE))) + #define __set_MSP(VALUE) (__arm_wsr("MSP", (VALUE))) + + #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ + (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) + // without main extensions, the non-secure MSPLIM is RAZ/WI + #define __set_MSPLIM(VALUE) ((void)(VALUE)) + #else + #define __set_MSPLIM(VALUE) (__arm_wsr("MSPLIM", (VALUE))) + #endif + #define __set_PRIMASK(VALUE) (__arm_wsr("PRIMASK", (VALUE))) + #define __set_PSP(VALUE) (__arm_wsr("PSP", (VALUE))) + #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ + (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) + // without main extensions, the non-secure PSPLIM is RAZ/WI + #define __set_PSPLIM(VALUE) ((void)(VALUE)) + #else + #define __set_PSPLIM(VALUE) (__arm_wsr("PSPLIM", (VALUE))) + #endif + + #define __TZ_get_CONTROL_NS() (__arm_rsr("CONTROL_NS")) + #define __TZ_set_CONTROL_NS(VALUE) (__arm_wsr("CONTROL_NS", (VALUE))) + #define __TZ_get_PSP_NS() (__arm_rsr("PSP_NS")) + #define __TZ_set_PSP_NS(VALUE) (__arm_wsr("PSP_NS", (VALUE))) + #define __TZ_get_MSP_NS() (__arm_rsr("MSP_NS")) + #define __TZ_set_MSP_NS(VALUE) (__arm_wsr("MSP_NS", (VALUE))) + #define __TZ_get_SP_NS() (__arm_rsr("SP_NS")) + #define __TZ_set_SP_NS(VALUE) (__arm_wsr("SP_NS", (VALUE))) + #define __TZ_get_PRIMASK_NS() (__arm_rsr("PRIMASK_NS")) + #define __TZ_set_PRIMASK_NS(VALUE) (__arm_wsr("PRIMASK_NS", (VALUE))) + #define __TZ_get_BASEPRI_NS() (__arm_rsr("BASEPRI_NS")) + #define __TZ_set_BASEPRI_NS(VALUE) (__arm_wsr("BASEPRI_NS", (VALUE))) + #define __TZ_get_FAULTMASK_NS() (__arm_rsr("FAULTMASK_NS")) + #define __TZ_set_FAULTMASK_NS(VALUE)(__arm_wsr("FAULTMASK_NS", (VALUE))) + #define __TZ_get_PSPLIM_NS() (__arm_rsr("PSPLIM_NS")) + #define __TZ_set_PSPLIM_NS(VALUE) (__arm_wsr("PSPLIM_NS", (VALUE))) + #define __TZ_get_MSPLIM_NS() (__arm_rsr("MSPLIM_NS")) + #define __TZ_set_MSPLIM_NS(VALUE) (__arm_wsr("MSPLIM_NS", (VALUE))) + + #define __NOP __iar_builtin_no_operation + + #define __CLZ __iar_builtin_CLZ + #define __CLREX __iar_builtin_CLREX + + #define __DMB __iar_builtin_DMB + #define __DSB __iar_builtin_DSB + #define __ISB __iar_builtin_ISB + + #define __LDREXB __iar_builtin_LDREXB + #define __LDREXH __iar_builtin_LDREXH + #define __LDREXW __iar_builtin_LDREX + + #define __RBIT __iar_builtin_RBIT + #define __REV __iar_builtin_REV + #define __REV16 __iar_builtin_REV16 + + __IAR_FT int16_t __REVSH(int16_t val) + { + return (int16_t) __iar_builtin_REVSH(val); + } + + #define __ROR __iar_builtin_ROR + #define __RRX __iar_builtin_RRX + + #define __SEV __iar_builtin_SEV + + #if !__IAR_M0_FAMILY + #define __SSAT __iar_builtin_SSAT + #endif + + #define __STREXB __iar_builtin_STREXB + #define __STREXH __iar_builtin_STREXH + #define __STREXW __iar_builtin_STREX + + #if !__IAR_M0_FAMILY + #define __USAT __iar_builtin_USAT + #endif + + #define __WFE __iar_builtin_WFE + #define __WFI __iar_builtin_WFI + + #if __ARM_MEDIA__ + #define __SADD8 __iar_builtin_SADD8 + #define __QADD8 __iar_builtin_QADD8 + #define __SHADD8 __iar_builtin_SHADD8 + #define __UADD8 __iar_builtin_UADD8 + #define __UQADD8 __iar_builtin_UQADD8 + #define __UHADD8 __iar_builtin_UHADD8 + #define __SSUB8 __iar_builtin_SSUB8 + #define __QSUB8 __iar_builtin_QSUB8 + #define __SHSUB8 __iar_builtin_SHSUB8 + #define __USUB8 __iar_builtin_USUB8 + #define __UQSUB8 __iar_builtin_UQSUB8 + #define __UHSUB8 __iar_builtin_UHSUB8 + #define __SADD16 __iar_builtin_SADD16 + #define __QADD16 __iar_builtin_QADD16 + #define __SHADD16 __iar_builtin_SHADD16 + #define __UADD16 __iar_builtin_UADD16 + #define __UQADD16 __iar_builtin_UQADD16 + #define __UHADD16 __iar_builtin_UHADD16 + #define __SSUB16 __iar_builtin_SSUB16 + #define __QSUB16 __iar_builtin_QSUB16 + #define __SHSUB16 __iar_builtin_SHSUB16 + #define __USUB16 __iar_builtin_USUB16 + #define __UQSUB16 __iar_builtin_UQSUB16 + #define __UHSUB16 __iar_builtin_UHSUB16 + #define __SASX __iar_builtin_SASX + #define __QASX __iar_builtin_QASX + #define __SHASX __iar_builtin_SHASX + #define __UASX __iar_builtin_UASX + #define __UQASX __iar_builtin_UQASX + #define __UHASX __iar_builtin_UHASX + #define __SSAX __iar_builtin_SSAX + #define __QSAX __iar_builtin_QSAX + #define __SHSAX __iar_builtin_SHSAX + #define __USAX __iar_builtin_USAX + #define __UQSAX __iar_builtin_UQSAX + #define __UHSAX __iar_builtin_UHSAX + #define __USAD8 __iar_builtin_USAD8 + #define __USADA8 __iar_builtin_USADA8 + #define __SSAT16 __iar_builtin_SSAT16 + #define __USAT16 __iar_builtin_USAT16 + #define __UXTB16 __iar_builtin_UXTB16 + #define __UXTAB16 __iar_builtin_UXTAB16 + #define __SXTB16 __iar_builtin_SXTB16 + #define __SXTAB16 __iar_builtin_SXTAB16 + #define __SMUAD __iar_builtin_SMUAD + #define __SMUADX __iar_builtin_SMUADX + #define __SMMLA __iar_builtin_SMMLA + #define __SMLAD __iar_builtin_SMLAD + #define __SMLADX __iar_builtin_SMLADX + #define __SMLALD __iar_builtin_SMLALD + #define __SMLALDX __iar_builtin_SMLALDX + #define __SMUSD __iar_builtin_SMUSD + #define __SMUSDX __iar_builtin_SMUSDX + #define __SMLSD __iar_builtin_SMLSD + #define __SMLSDX __iar_builtin_SMLSDX + #define __SMLSLD __iar_builtin_SMLSLD + #define __SMLSLDX __iar_builtin_SMLSLDX + #define __SEL __iar_builtin_SEL + #define __QADD __iar_builtin_QADD + #define __QSUB __iar_builtin_QSUB + #define __PKHBT __iar_builtin_PKHBT + #define __PKHTB __iar_builtin_PKHTB + #endif + +#else /* __ICCARM_INTRINSICS_VERSION__ == 2 */ + + #if __IAR_M0_FAMILY + /* Avoid clash between intrinsics.h and arm_math.h when compiling for Cortex-M0. */ + #define __CLZ __cmsis_iar_clz_not_active + #define __SSAT __cmsis_iar_ssat_not_active + #define __USAT __cmsis_iar_usat_not_active + #define __RBIT __cmsis_iar_rbit_not_active + #define __get_APSR __cmsis_iar_get_APSR_not_active + #endif + + + #if (!((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ + (defined (__FPU_USED ) && (__FPU_USED == 1U)) )) + #define __get_FPSCR __cmsis_iar_get_FPSR_not_active + #define __set_FPSCR __cmsis_iar_set_FPSR_not_active + #endif + + #ifdef __INTRINSICS_INCLUDED + #error intrinsics.h is already included previously! + #endif + + #include + + #if __IAR_M0_FAMILY + /* Avoid clash between intrinsics.h and arm_math.h when compiling for Cortex-M0. */ + #undef __CLZ + #undef __SSAT + #undef __USAT + #undef __RBIT + #undef __get_APSR + + __STATIC_INLINE uint8_t __CLZ(uint32_t data) + { + if (data == 0U) { return 32U; } + + uint32_t count = 0U; + uint32_t mask = 0x80000000U; + + while ((data & mask) == 0U) + { + count += 1U; + mask = mask >> 1U; + } + return count; + } + + __STATIC_INLINE uint32_t __RBIT(uint32_t v) + { + uint8_t sc = 31U; + uint32_t r = v; + for (v >>= 1U; v; v >>= 1U) + { + r <<= 1U; + r |= v & 1U; + sc--; + } + return (r << sc); + } + + __STATIC_INLINE uint32_t __get_APSR(void) + { + uint32_t res; + __asm("MRS %0,APSR" : "=r" (res)); + return res; + } + + #endif + + #if (!((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ + (defined (__FPU_USED ) && (__FPU_USED == 1U)) )) + #undef __get_FPSCR + #undef __set_FPSCR + #define __get_FPSCR() (0) + #define __set_FPSCR(VALUE) ((void)VALUE) + #endif + + #pragma diag_suppress=Pe940 + #pragma diag_suppress=Pe177 + + #define __enable_irq __enable_interrupt + #define __disable_irq __disable_interrupt + #define __NOP __no_operation + + #define __get_xPSR __get_PSR + + #if (!defined(__ARM_ARCH_6M__) || __ARM_ARCH_6M__==0) + + __IAR_FT uint32_t __LDREXW(uint32_t volatile *ptr) + { + return __LDREX((unsigned long *)ptr); + } + + __IAR_FT uint32_t __STREXW(uint32_t value, uint32_t volatile *ptr) + { + return __STREX(value, (unsigned long *)ptr); + } + #endif + + + /* __CORTEX_M is defined in core_cm0.h, core_cm3.h and core_cm4.h. */ + #if (__CORTEX_M >= 0x03) + + __IAR_FT uint32_t __RRX(uint32_t value) + { + uint32_t result; + __ASM("RRX %0, %1" : "=r"(result) : "r" (value) : "cc"); + return(result); + } + + __IAR_FT void __set_BASEPRI_MAX(uint32_t value) + { + __asm volatile("MSR BASEPRI_MAX,%0"::"r" (value)); + } + + + #define __enable_fault_irq __enable_fiq + #define __disable_fault_irq __disable_fiq + + + #endif /* (__CORTEX_M >= 0x03) */ + + __IAR_FT uint32_t __ROR(uint32_t op1, uint32_t op2) + { + return (op1 >> op2) | (op1 << ((sizeof(op1)*8)-op2)); + } + + #if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) + + __IAR_FT uint32_t __get_MSPLIM(void) + { + uint32_t res; + #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ + (!defined (__ARM_FEATURE_CMSE ) || (__ARM_FEATURE_CMSE < 3))) + // without main extensions, the non-secure MSPLIM is RAZ/WI + res = 0U; + #else + __asm volatile("MRS %0,MSPLIM" : "=r" (res)); + #endif + return res; + } + + __IAR_FT void __set_MSPLIM(uint32_t value) + { + #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ + (!defined (__ARM_FEATURE_CMSE ) || (__ARM_FEATURE_CMSE < 3))) + // without main extensions, the non-secure MSPLIM is RAZ/WI + (void)value; + #else + __asm volatile("MSR MSPLIM,%0" :: "r" (value)); + #endif + } + + __IAR_FT uint32_t __get_PSPLIM(void) + { + uint32_t res; + #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ + (!defined (__ARM_FEATURE_CMSE ) || (__ARM_FEATURE_CMSE < 3))) + // without main extensions, the non-secure PSPLIM is RAZ/WI + res = 0U; + #else + __asm volatile("MRS %0,PSPLIM" : "=r" (res)); + #endif + return res; + } + + __IAR_FT void __set_PSPLIM(uint32_t value) + { + #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ + (!defined (__ARM_FEATURE_CMSE ) || (__ARM_FEATURE_CMSE < 3))) + // without main extensions, the non-secure PSPLIM is RAZ/WI + (void)value; + #else + __asm volatile("MSR PSPLIM,%0" :: "r" (value)); + #endif + } + + __IAR_FT uint32_t __TZ_get_CONTROL_NS(void) + { + uint32_t res; + __asm volatile("MRS %0,CONTROL_NS" : "=r" (res)); + return res; + } + + __IAR_FT void __TZ_set_CONTROL_NS(uint32_t value) + { + __asm volatile("MSR CONTROL_NS,%0" :: "r" (value)); + } + + __IAR_FT uint32_t __TZ_get_PSP_NS(void) + { + uint32_t res; + __asm volatile("MRS %0,PSP_NS" : "=r" (res)); + return res; + } + + __IAR_FT void __TZ_set_PSP_NS(uint32_t value) + { + __asm volatile("MSR PSP_NS,%0" :: "r" (value)); + } + + __IAR_FT uint32_t __TZ_get_MSP_NS(void) + { + uint32_t res; + __asm volatile("MRS %0,MSP_NS" : "=r" (res)); + return res; + } + + __IAR_FT void __TZ_set_MSP_NS(uint32_t value) + { + __asm volatile("MSR MSP_NS,%0" :: "r" (value)); + } + + __IAR_FT uint32_t __TZ_get_SP_NS(void) + { + uint32_t res; + __asm volatile("MRS %0,SP_NS" : "=r" (res)); + return res; + } + __IAR_FT void __TZ_set_SP_NS(uint32_t value) + { + __asm volatile("MSR SP_NS,%0" :: "r" (value)); + } + + __IAR_FT uint32_t __TZ_get_PRIMASK_NS(void) + { + uint32_t res; + __asm volatile("MRS %0,PRIMASK_NS" : "=r" (res)); + return res; + } + + __IAR_FT void __TZ_set_PRIMASK_NS(uint32_t value) + { + __asm volatile("MSR PRIMASK_NS,%0" :: "r" (value)); + } + + __IAR_FT uint32_t __TZ_get_BASEPRI_NS(void) + { + uint32_t res; + __asm volatile("MRS %0,BASEPRI_NS" : "=r" (res)); + return res; + } + + __IAR_FT void __TZ_set_BASEPRI_NS(uint32_t value) + { + __asm volatile("MSR BASEPRI_NS,%0" :: "r" (value)); + } + + __IAR_FT uint32_t __TZ_get_FAULTMASK_NS(void) + { + uint32_t res; + __asm volatile("MRS %0,FAULTMASK_NS" : "=r" (res)); + return res; + } + + __IAR_FT void __TZ_set_FAULTMASK_NS(uint32_t value) + { + __asm volatile("MSR FAULTMASK_NS,%0" :: "r" (value)); + } + + __IAR_FT uint32_t __TZ_get_PSPLIM_NS(void) + { + uint32_t res; + __asm volatile("MRS %0,PSPLIM_NS" : "=r" (res)); + return res; + } + __IAR_FT void __TZ_set_PSPLIM_NS(uint32_t value) + { + __asm volatile("MSR PSPLIM_NS,%0" :: "r" (value)); + } + + __IAR_FT uint32_t __TZ_get_MSPLIM_NS(void) + { + uint32_t res; + __asm volatile("MRS %0,MSPLIM_NS" : "=r" (res)); + return res; + } + + __IAR_FT void __TZ_set_MSPLIM_NS(uint32_t value) + { + __asm volatile("MSR MSPLIM_NS,%0" :: "r" (value)); + } + + #endif /* __ARM_ARCH_8M_MAIN__ or __ARM_ARCH_8M_BASE__ */ + +#endif /* __ICCARM_INTRINSICS_VERSION__ == 2 */ + +#define __BKPT(value) __asm volatile ("BKPT %0" : : "i"(value)) + +#if __IAR_M0_FAMILY + __STATIC_INLINE int32_t __SSAT(int32_t val, uint32_t sat) + { + if ((sat >= 1U) && (sat <= 32U)) + { + const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U); + const int32_t min = -1 - max ; + if (val > max) + { + return max; + } + else if (val < min) + { + return min; + } + } + return val; + } + + __STATIC_INLINE uint32_t __USAT(int32_t val, uint32_t sat) + { + if (sat <= 31U) + { + const uint32_t max = ((1U << sat) - 1U); + if (val > (int32_t)max) + { + return max; + } + else if (val < 0) + { + return 0U; + } + } + return (uint32_t)val; + } +#endif + +#if (__CORTEX_M >= 0x03) /* __CORTEX_M is defined in core_cm0.h, core_cm3.h and core_cm4.h. */ + + __IAR_FT uint8_t __LDRBT(volatile uint8_t *addr) + { + uint32_t res; + __ASM("LDRBT %0, [%1]" : "=r" (res) : "r" (addr) : "memory"); + return ((uint8_t)res); + } + + __IAR_FT uint16_t __LDRHT(volatile uint16_t *addr) + { + uint32_t res; + __ASM("LDRHT %0, [%1]" : "=r" (res) : "r" (addr) : "memory"); + return ((uint16_t)res); + } + + __IAR_FT uint32_t __LDRT(volatile uint32_t *addr) + { + uint32_t res; + __ASM("LDRT %0, [%1]" : "=r" (res) : "r" (addr) : "memory"); + return res; + } + + __IAR_FT void __STRBT(uint8_t value, volatile uint8_t *addr) + { + __ASM("STRBT %1, [%0]" : : "r" (addr), "r" ((uint32_t)value) : "memory"); + } + + __IAR_FT void __STRHT(uint16_t value, volatile uint16_t *addr) + { + __ASM("STRHT %1, [%0]" : : "r" (addr), "r" ((uint32_t)value) : "memory"); + } + + __IAR_FT void __STRT(uint32_t value, volatile uint32_t *addr) + { + __ASM("STRT %1, [%0]" : : "r" (addr), "r" (value) : "memory"); + } + +#endif /* (__CORTEX_M >= 0x03) */ + +#if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ + (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) + + + __IAR_FT uint8_t __LDAB(volatile uint8_t *ptr) + { + uint32_t res; + __ASM volatile ("LDAB %0, [%1]" : "=r" (res) : "r" (*ptr) : "memory"); + return ((uint8_t)res); + } + + __IAR_FT uint16_t __LDAH(volatile uint16_t *ptr) + { + uint32_t res; + __ASM volatile ("LDAH %0, [%1]" : "=r" (res) : "r" (*ptr) : "memory"); + return ((uint16_t)res); + } + + __IAR_FT uint32_t __LDA(volatile uint32_t *ptr) + { + uint32_t res; + __ASM volatile ("LDA %0, [%1]" : "=r" (res) : "r" (*ptr) : "memory"); + return res; + } + + __IAR_FT void __STLB(uint8_t value, volatile uint8_t *ptr) + { + __ASM volatile ("STLB %1, [%0]" :: "r" (*ptr), "r" (value) : "memory"); + } + + __IAR_FT void __STLH(uint16_t value, volatile uint16_t *ptr) + { + __ASM volatile ("STLH %1, [%0]" :: "r" (*ptr), "r" (value) : "memory"); + } + + __IAR_FT void __STL(uint32_t value, volatile uint32_t *ptr) + { + __ASM volatile ("STL %1, [%0]" :: "r" (*ptr), "r" (value) : "memory"); + } + + __IAR_FT uint8_t __LDAEXB(volatile uint8_t *ptr) + { + uint32_t res; + __ASM volatile ("LDAEXB %0, [%1]" : "=r" (res) : "r" (*ptr) : "memory"); + return ((uint8_t)res); + } + + __IAR_FT uint16_t __LDAEXH(volatile uint16_t *ptr) + { + uint32_t res; + __ASM volatile ("LDAEXH %0, [%1]" : "=r" (res) : "r" (*ptr) : "memory"); + return ((uint16_t)res); + } + + __IAR_FT uint32_t __LDAEX(volatile uint32_t *ptr) + { + uint32_t res; + __ASM volatile ("LDAEX %0, [%1]" : "=r" (res) : "r" (*ptr) : "memory"); + return res; + } + + __IAR_FT uint32_t __STLEXB(uint8_t value, volatile uint8_t *ptr) + { + uint32_t res; + __ASM volatile ("STLEXB %0, %2, [%1]" : "=r" (res) : "r" (*ptr), "r" (value) : "memory"); + return res; + } + + __IAR_FT uint32_t __STLEXH(uint16_t value, volatile uint16_t *ptr) + { + uint32_t res; + __ASM volatile ("STLEXH %0, %2, [%1]" : "=r" (res) : "r" (*ptr), "r" (value) : "memory"); + return res; + } + + __IAR_FT uint32_t __STLEX(uint32_t value, volatile uint32_t *ptr) + { + uint32_t res; + __ASM volatile ("STLEX %0, %2, [%1]" : "=r" (res) : "r" (*ptr), "r" (value) : "memory"); + return res; + } + +#endif /* __ARM_ARCH_8M_MAIN__ or __ARM_ARCH_8M_BASE__ */ + +#undef __IAR_FT +#undef __IAR_M0_FAMILY +#undef __ICCARM_V8 + +#pragma diag_default=Pe940 +#pragma diag_default=Pe177 + +#endif /* __CMSIS_ICCARM_H__ */ diff --git a/Platform/Core/cmsis_version.h b/Platform/Core/cmsis_version.h new file mode 100644 index 0000000..660f612 --- /dev/null +++ b/Platform/Core/cmsis_version.h @@ -0,0 +1,39 @@ +/**************************************************************************//** + * @file cmsis_version.h + * @brief CMSIS Core(M) Version definitions + * @version V5.0.2 + * @date 19. April 2017 + ******************************************************************************/ +/* + * Copyright (c) 2009-2017 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * 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 + * + * 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. + */ + +#if defined ( __ICCARM__ ) + #pragma system_include /* treat file as system include file for MISRA check */ +#elif defined (__clang__) + #pragma clang system_header /* treat file as system include file */ +#endif + +#ifndef __CMSIS_VERSION_H +#define __CMSIS_VERSION_H + +/* CMSIS Version definitions */ +#define __CM_CMSIS_VERSION_MAIN ( 5U) /*!< [31:16] CMSIS Core(M) main version */ +#define __CM_CMSIS_VERSION_SUB ( 1U) /*!< [15:0] CMSIS Core(M) sub version */ +#define __CM_CMSIS_VERSION ((__CM_CMSIS_VERSION_MAIN << 16U) | \ + __CM_CMSIS_VERSION_SUB ) /*!< CMSIS Core(M) version number */ +#endif diff --git a/Platform/Core/core_cm0plus.h b/Platform/Core/core_cm0plus.h new file mode 100644 index 0000000..831faf8 --- /dev/null +++ b/Platform/Core/core_cm0plus.h @@ -0,0 +1,1025 @@ +/**************************************************************************//** + * @file core_cm0plus.h + * @brief CMSIS Cortex-M0+ Core Peripheral Access Layer Header File + * @version V5.0.4 + * @date 10. January 2018 + ******************************************************************************/ +/* + * Copyright (c) 2009-2018 Arm Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * 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 + * + * 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. + */ + +#if defined ( __ICCARM__ ) + #pragma system_include /* treat file as system include file for MISRA check */ +#elif defined (__clang__) + #pragma clang system_header /* treat file as system include file */ +#endif + +#ifndef __CORE_CM0PLUS_H_GENERIC +#define __CORE_CM0PLUS_H_GENERIC + +#include + +#include "Z20K11xM_corecfg.h" + +#ifdef __cplusplus + extern "C" { +#endif + +/** + \page CMSIS_MISRA_Exceptions MISRA-C:2004 Compliance Exceptions + CMSIS violates the following MISRA-C:2004 rules: + + \li Required Rule 8.5, object/function definition in header file.
+ Function definitions in header files are used to allow 'inlining'. + + \li Required Rule 18.4, declaration of union type or object of union type: '{...}'.
+ Unions are used for effective representation of core registers. + + \li Advisory Rule 19.7, Function-like macro defined.
+ Function-like macros are used to allow more efficient code. + */ + + +/******************************************************************************* + * CMSIS definitions + ******************************************************************************/ +/** + \ingroup Cortex-M0+ + @{ + */ + +#include "cmsis_version.h" + +/* CMSIS CM0+ definitions */ +#define __CM0PLUS_CMSIS_VERSION_MAIN (__CM_CMSIS_VERSION_MAIN) /*!< \deprecated [31:16] CMSIS HAL main version */ +#define __CM0PLUS_CMSIS_VERSION_SUB (__CM_CMSIS_VERSION_SUB) /*!< \deprecated [15:0] CMSIS HAL sub version */ +#define __CM0PLUS_CMSIS_VERSION ((__CM0PLUS_CMSIS_VERSION_MAIN << 16U) | \ + __CM0PLUS_CMSIS_VERSION_SUB ) /*!< \deprecated CMSIS HAL version number */ + +#define __CORTEX_M (0U) /*!< Cortex-M Core */ + +/** __FPU_USED indicates whether an FPU is used or not. + This core does not support an FPU at all +*/ +#define __FPU_USED 0U + +#if defined ( __CC_ARM ) + #if defined __TARGET_FPU_VFP + #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" + #endif + +#elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) + #if defined __ARM_PCS_VFP + #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" + #endif + +#elif defined ( __GNUC__ ) + #if defined (__VFP_FP__) && !defined(__SOFTFP__) + #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" + #endif + +#elif defined ( __ICCARM__ ) + #if defined __ARMVFP__ + #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" + #endif + +#elif defined ( __TI_ARM__ ) + #if defined __TI_VFP_SUPPORT__ + #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" + #endif + +#elif defined ( __TASKING__ ) + #if defined __FPU_VFP__ + #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" + #endif + +#elif defined ( __CSMC__ ) + #if ( __CSMC__ & 0x400U) + #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" + #endif + +#endif + +#include "cmsis_compiler.h" /* CMSIS compiler specific defines */ + + +#ifdef __cplusplus +} +#endif + +#endif /* __CORE_CM0PLUS_H_GENERIC */ + +#ifndef __CMSIS_GENERIC + +#ifndef __CORE_CM0PLUS_H_DEPENDANT +#define __CORE_CM0PLUS_H_DEPENDANT + +#ifdef __cplusplus + extern "C" { +#endif + +/* check device defines and use defaults */ +#if defined __CHECK_DEVICE_DEFINES + #ifndef __CM0PLUS_REV + #define __CM0PLUS_REV 0x0000U + #warning "__CM0PLUS_REV not defined in device header file; using default!" + #endif + + #ifndef __MPU_PRESENT + #define __MPU_PRESENT 0U + #warning "__MPU_PRESENT not defined in device header file; using default!" + #endif + + #ifndef __VTOR_PRESENT + #define __VTOR_PRESENT 0U + #warning "__VTOR_PRESENT not defined in device header file; using default!" + #endif + + #ifndef __NVIC_PRIO_BITS + #define __NVIC_PRIO_BITS 2U + #warning "__NVIC_PRIO_BITS not defined in device header file; using default!" + #endif + + #ifndef __Vendor_SysTickConfig + #define __Vendor_SysTickConfig 0U + #warning "__Vendor_SysTickConfig not defined in device header file; using default!" + #endif +#endif + +/* IO definitions (access restrictions to peripheral registers) */ +/** + \defgroup CMSIS_glob_defs CMSIS Global Defines + + IO Type Qualifiers are used + \li to specify the access to peripheral variables. + \li for automatic generation of peripheral register debug information. +*/ +#ifdef __cplusplus + #define __I volatile /*!< Defines 'read only' permissions */ +#else + #define __I volatile const /*!< Defines 'read only' permissions */ +#endif +#define __O volatile /*!< Defines 'write only' permissions */ +#define __IO volatile /*!< Defines 'read / write' permissions */ + +/* following defines should be used for structure members */ +#define __IM volatile const /*! Defines 'read only' structure member permissions */ +#define __OM volatile /*! Defines 'write only' structure member permissions */ +#define __IOM volatile /*! Defines 'read / write' structure member permissions */ + +/** @} end of group Cortex-M0+ */ + + + +/******************************************************************************* + * Register Abstraction + Core Register contain: + - Core Register + - Core NVIC Register + - Core SCB Register + - Core SysTick Register + - Core MPU Register + ******************************************************************************/ +/** + \defgroup CMSIS_core_register Defines and Type Definitions + \brief Type definitions and defines for Cortex-M processor based devices. +*/ + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_CORE Status and Control Registers + \brief Core Register type definitions. + @{ + */ + +/** + \brief Union type to access the Application Program Status Register (APSR). + */ +typedef union +{ + struct + { + uint32_t _reserved0:28; /*!< bit: 0..27 Reserved */ + uint32_t V:1; /*!< bit: 28 Overflow condition code flag */ + uint32_t C:1; /*!< bit: 29 Carry condition code flag */ + uint32_t Z:1; /*!< bit: 30 Zero condition code flag */ + uint32_t N:1; /*!< bit: 31 Negative condition code flag */ + } b; /*!< Structure used for bit access */ + uint32_t w; /*!< Type used for word access */ +} APSR_Type; + +/* APSR Register Definitions */ +#define APSR_N_Pos 31U /*!< APSR: N Position */ +#define APSR_N_Msk (1UL << APSR_N_Pos) /*!< APSR: N Mask */ + +#define APSR_Z_Pos 30U /*!< APSR: Z Position */ +#define APSR_Z_Msk (1UL << APSR_Z_Pos) /*!< APSR: Z Mask */ + +#define APSR_C_Pos 29U /*!< APSR: C Position */ +#define APSR_C_Msk (1UL << APSR_C_Pos) /*!< APSR: C Mask */ + +#define APSR_V_Pos 28U /*!< APSR: V Position */ +#define APSR_V_Msk (1UL << APSR_V_Pos) /*!< APSR: V Mask */ + + +/** + \brief Union type to access the Interrupt Program Status Register (IPSR). + */ +typedef union +{ + struct + { + uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */ + uint32_t _reserved0:23; /*!< bit: 9..31 Reserved */ + } b; /*!< Structure used for bit access */ + uint32_t w; /*!< Type used for word access */ +} IPSR_Type; + +/* IPSR Register Definitions */ +#define IPSR_ISR_Pos 0U /*!< IPSR: ISR Position */ +#define IPSR_ISR_Msk (0x1FFUL /*<< IPSR_ISR_Pos*/) /*!< IPSR: ISR Mask */ + + +/** + \brief Union type to access the Special-Purpose Program Status Registers (xPSR). + */ +typedef union +{ + struct + { + uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */ + uint32_t _reserved0:15; /*!< bit: 9..23 Reserved */ + uint32_t T:1; /*!< bit: 24 Thumb bit (read 0) */ + uint32_t _reserved1:3; /*!< bit: 25..27 Reserved */ + uint32_t V:1; /*!< bit: 28 Overflow condition code flag */ + uint32_t C:1; /*!< bit: 29 Carry condition code flag */ + uint32_t Z:1; /*!< bit: 30 Zero condition code flag */ + uint32_t N:1; /*!< bit: 31 Negative condition code flag */ + } b; /*!< Structure used for bit access */ + uint32_t w; /*!< Type used for word access */ +} xPSR_Type; + +/* xPSR Register Definitions */ +#define xPSR_N_Pos 31U /*!< xPSR: N Position */ +#define xPSR_N_Msk (1UL << xPSR_N_Pos) /*!< xPSR: N Mask */ + +#define xPSR_Z_Pos 30U /*!< xPSR: Z Position */ +#define xPSR_Z_Msk (1UL << xPSR_Z_Pos) /*!< xPSR: Z Mask */ + +#define xPSR_C_Pos 29U /*!< xPSR: C Position */ +#define xPSR_C_Msk (1UL << xPSR_C_Pos) /*!< xPSR: C Mask */ + +#define xPSR_V_Pos 28U /*!< xPSR: V Position */ +#define xPSR_V_Msk (1UL << xPSR_V_Pos) /*!< xPSR: V Mask */ + +#define xPSR_T_Pos 24U /*!< xPSR: T Position */ +#define xPSR_T_Msk (1UL << xPSR_T_Pos) /*!< xPSR: T Mask */ + +#define xPSR_ISR_Pos 0U /*!< xPSR: ISR Position */ +#define xPSR_ISR_Msk (0x1FFUL /*<< xPSR_ISR_Pos*/) /*!< xPSR: ISR Mask */ + + +/** + \brief Union type to access the Control Registers (CONTROL). + */ +typedef union +{ + struct + { + uint32_t nPRIV:1; /*!< bit: 0 Execution privilege in Thread mode */ + uint32_t SPSEL:1; /*!< bit: 1 Stack to be used */ + uint32_t _reserved1:30; /*!< bit: 2..31 Reserved */ + } b; /*!< Structure used for bit access */ + uint32_t w; /*!< Type used for word access */ +} CONTROL_Type; + +/* CONTROL Register Definitions */ +#define CONTROL_SPSEL_Pos 1U /*!< CONTROL: SPSEL Position */ +#define CONTROL_SPSEL_Msk (1UL << CONTROL_SPSEL_Pos) /*!< CONTROL: SPSEL Mask */ + +#define CONTROL_nPRIV_Pos 0U /*!< CONTROL: nPRIV Position */ +#define CONTROL_nPRIV_Msk (1UL /*<< CONTROL_nPRIV_Pos*/) /*!< CONTROL: nPRIV Mask */ + +/** @} end of group CMSIS_CORE */ + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_NVIC Nested Vectored Interrupt Controller (NVIC) + \brief Type definitions for the NVIC Registers + @{ + */ + +/** + \brief Structure type to access the Nested Vectored Interrupt Controller (NVIC). + */ +typedef struct +{ + __IOM uint32_t ISER[1U]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */ + uint32_t RESERVED0[31U]; + __IOM uint32_t ICER[1U]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */ + uint32_t RSERVED1[31U]; + __IOM uint32_t ISPR[1U]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */ + uint32_t RESERVED2[31U]; + __IOM uint32_t ICPR[1U]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */ + uint32_t RESERVED3[31U]; + uint32_t RESERVED4[64U]; + __IOM uint32_t IP[8U]; /*!< Offset: 0x300 (R/W) Interrupt Priority Register */ +} NVIC_Type; + +/** @} end of group CMSIS_NVIC */ + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_SCB System Control Block (SCB) + \brief Type definitions for the System Control Block Registers + @{ + */ + +/** + \brief Structure type to access the System Control Block (SCB). + */ +typedef struct +{ + __IM uint32_t CPUID; /*!< Offset: 0x000 (R/ ) CPUID Base Register */ + __IOM uint32_t ICSR; /*!< Offset: 0x004 (R/W) Interrupt Control and State Register */ +#if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U) + __IOM uint32_t VTOR; /*!< Offset: 0x008 (R/W) Vector Table Offset Register */ +#else + uint32_t RESERVED0; +#endif + __IOM uint32_t AIRCR; /*!< Offset: 0x00C (R/W) Application Interrupt and Reset Control Register */ + __IOM uint32_t SCR; /*!< Offset: 0x010 (R/W) System Control Register */ + __IOM uint32_t CCR; /*!< Offset: 0x014 (R/W) Configuration Control Register */ + uint32_t RESERVED1; + __IOM uint32_t SHP[2U]; /*!< Offset: 0x01C (R/W) System Handlers Priority Registers. [0] is RESERVED */ + __IOM uint32_t SHCSR; /*!< Offset: 0x024 (R/W) System Handler Control and State Register */ +} SCB_Type; + +/* SCB CPUID Register Definitions */ +#define SCB_CPUID_IMPLEMENTER_Pos 24U /*!< SCB CPUID: IMPLEMENTER Position */ +#define SCB_CPUID_IMPLEMENTER_Msk (0xFFUL << SCB_CPUID_IMPLEMENTER_Pos) /*!< SCB CPUID: IMPLEMENTER Mask */ + +#define SCB_CPUID_VARIANT_Pos 20U /*!< SCB CPUID: VARIANT Position */ +#define SCB_CPUID_VARIANT_Msk (0xFUL << SCB_CPUID_VARIANT_Pos) /*!< SCB CPUID: VARIANT Mask */ + +#define SCB_CPUID_ARCHITECTURE_Pos 16U /*!< SCB CPUID: ARCHITECTURE Position */ +#define SCB_CPUID_ARCHITECTURE_Msk (0xFUL << SCB_CPUID_ARCHITECTURE_Pos) /*!< SCB CPUID: ARCHITECTURE Mask */ + +#define SCB_CPUID_PARTNO_Pos 4U /*!< SCB CPUID: PARTNO Position */ +#define SCB_CPUID_PARTNO_Msk (0xFFFUL << SCB_CPUID_PARTNO_Pos) /*!< SCB CPUID: PARTNO Mask */ + +#define SCB_CPUID_REVISION_Pos 0U /*!< SCB CPUID: REVISION Position */ +#define SCB_CPUID_REVISION_Msk (0xFUL /*<< SCB_CPUID_REVISION_Pos*/) /*!< SCB CPUID: REVISION Mask */ + +/* SCB Interrupt Control State Register Definitions */ +#define SCB_ICSR_NMIPENDSET_Pos 31U /*!< SCB ICSR: NMIPENDSET Position */ +#define SCB_ICSR_NMIPENDSET_Msk (1UL << SCB_ICSR_NMIPENDSET_Pos) /*!< SCB ICSR: NMIPENDSET Mask */ + +#define SCB_ICSR_PENDSVSET_Pos 28U /*!< SCB ICSR: PENDSVSET Position */ +#define SCB_ICSR_PENDSVSET_Msk (1UL << SCB_ICSR_PENDSVSET_Pos) /*!< SCB ICSR: PENDSVSET Mask */ + +#define SCB_ICSR_PENDSVCLR_Pos 27U /*!< SCB ICSR: PENDSVCLR Position */ +#define SCB_ICSR_PENDSVCLR_Msk (1UL << SCB_ICSR_PENDSVCLR_Pos) /*!< SCB ICSR: PENDSVCLR Mask */ + +#define SCB_ICSR_PENDSTSET_Pos 26U /*!< SCB ICSR: PENDSTSET Position */ +#define SCB_ICSR_PENDSTSET_Msk (1UL << SCB_ICSR_PENDSTSET_Pos) /*!< SCB ICSR: PENDSTSET Mask */ + +#define SCB_ICSR_PENDSTCLR_Pos 25U /*!< SCB ICSR: PENDSTCLR Position */ +#define SCB_ICSR_PENDSTCLR_Msk (1UL << SCB_ICSR_PENDSTCLR_Pos) /*!< SCB ICSR: PENDSTCLR Mask */ + +#define SCB_ICSR_ISRPREEMPT_Pos 23U /*!< SCB ICSR: ISRPREEMPT Position */ +#define SCB_ICSR_ISRPREEMPT_Msk (1UL << SCB_ICSR_ISRPREEMPT_Pos) /*!< SCB ICSR: ISRPREEMPT Mask */ + +#define SCB_ICSR_ISRPENDING_Pos 22U /*!< SCB ICSR: ISRPENDING Position */ +#define SCB_ICSR_ISRPENDING_Msk (1UL << SCB_ICSR_ISRPENDING_Pos) /*!< SCB ICSR: ISRPENDING Mask */ + +#define SCB_ICSR_VECTPENDING_Pos 12U /*!< SCB ICSR: VECTPENDING Position */ +#define SCB_ICSR_VECTPENDING_Msk (0x1FFUL << SCB_ICSR_VECTPENDING_Pos) /*!< SCB ICSR: VECTPENDING Mask */ + +#define SCB_ICSR_VECTACTIVE_Pos 0U /*!< SCB ICSR: VECTACTIVE Position */ +#define SCB_ICSR_VECTACTIVE_Msk (0x1FFUL /*<< SCB_ICSR_VECTACTIVE_Pos*/) /*!< SCB ICSR: VECTACTIVE Mask */ + +#if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U) +/* SCB Interrupt Control State Register Definitions */ +#define SCB_VTOR_TBLOFF_Pos 8U /*!< SCB VTOR: TBLOFF Position */ +#define SCB_VTOR_TBLOFF_Msk (0xFFFFFFUL << SCB_VTOR_TBLOFF_Pos) /*!< SCB VTOR: TBLOFF Mask */ +#endif + +/* SCB Application Interrupt and Reset Control Register Definitions */ +#define SCB_AIRCR_VECTKEY_Pos 16U /*!< SCB AIRCR: VECTKEY Position */ +#define SCB_AIRCR_VECTKEY_Msk (0xFFFFUL << SCB_AIRCR_VECTKEY_Pos) /*!< SCB AIRCR: VECTKEY Mask */ + +#define SCB_AIRCR_VECTKEYSTAT_Pos 16U /*!< SCB AIRCR: VECTKEYSTAT Position */ +#define SCB_AIRCR_VECTKEYSTAT_Msk (0xFFFFUL << SCB_AIRCR_VECTKEYSTAT_Pos) /*!< SCB AIRCR: VECTKEYSTAT Mask */ + +#define SCB_AIRCR_ENDIANESS_Pos 15U /*!< SCB AIRCR: ENDIANESS Position */ +#define SCB_AIRCR_ENDIANESS_Msk (1UL << SCB_AIRCR_ENDIANESS_Pos) /*!< SCB AIRCR: ENDIANESS Mask */ + +#define SCB_AIRCR_SYSRESETREQ_Pos 2U /*!< SCB AIRCR: SYSRESETREQ Position */ +#define SCB_AIRCR_SYSRESETREQ_Msk (1UL << SCB_AIRCR_SYSRESETREQ_Pos) /*!< SCB AIRCR: SYSRESETREQ Mask */ + +#define SCB_AIRCR_VECTCLRACTIVE_Pos 1U /*!< SCB AIRCR: VECTCLRACTIVE Position */ +#define SCB_AIRCR_VECTCLRACTIVE_Msk (1UL << SCB_AIRCR_VECTCLRACTIVE_Pos) /*!< SCB AIRCR: VECTCLRACTIVE Mask */ + +/* SCB System Control Register Definitions */ +#define SCB_SCR_SEVONPEND_Pos 4U /*!< SCB SCR: SEVONPEND Position */ +#define SCB_SCR_SEVONPEND_Msk (1UL << SCB_SCR_SEVONPEND_Pos) /*!< SCB SCR: SEVONPEND Mask */ + +#define SCB_SCR_SLEEPDEEP_Pos 2U /*!< SCB SCR: SLEEPDEEP Position */ +#define SCB_SCR_SLEEPDEEP_Msk (1UL << SCB_SCR_SLEEPDEEP_Pos) /*!< SCB SCR: SLEEPDEEP Mask */ + +#define SCB_SCR_SLEEPONEXIT_Pos 1U /*!< SCB SCR: SLEEPONEXIT Position */ +#define SCB_SCR_SLEEPONEXIT_Msk (1UL << SCB_SCR_SLEEPONEXIT_Pos) /*!< SCB SCR: SLEEPONEXIT Mask */ + +/* SCB Configuration Control Register Definitions */ +#define SCB_CCR_STKALIGN_Pos 9U /*!< SCB CCR: STKALIGN Position */ +#define SCB_CCR_STKALIGN_Msk (1UL << SCB_CCR_STKALIGN_Pos) /*!< SCB CCR: STKALIGN Mask */ + +#define SCB_CCR_UNALIGN_TRP_Pos 3U /*!< SCB CCR: UNALIGN_TRP Position */ +#define SCB_CCR_UNALIGN_TRP_Msk (1UL << SCB_CCR_UNALIGN_TRP_Pos) /*!< SCB CCR: UNALIGN_TRP Mask */ + +/* SCB System Handler Control and State Register Definitions */ +#define SCB_SHCSR_SVCALLPENDED_Pos 15U /*!< SCB SHCSR: SVCALLPENDED Position */ +#define SCB_SHCSR_SVCALLPENDED_Msk (1UL << SCB_SHCSR_SVCALLPENDED_Pos) /*!< SCB SHCSR: SVCALLPENDED Mask */ + +/** @} end of group CMSIS_SCB */ + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_SysTick System Tick Timer (SysTick) + \brief Type definitions for the System Timer Registers. + @{ + */ + +/** + \brief Structure type to access the System Timer (SysTick). + */ +typedef struct +{ + __IOM uint32_t CTRL; /*!< Offset: 0x000 (R/W) SysTick Control and Status Register */ + __IOM uint32_t LOAD; /*!< Offset: 0x004 (R/W) SysTick Reload Value Register */ + __IOM uint32_t VAL; /*!< Offset: 0x008 (R/W) SysTick Current Value Register */ + __IM uint32_t CALIB; /*!< Offset: 0x00C (R/ ) SysTick Calibration Register */ +} SysTick_Type; + +/* SysTick Control / Status Register Definitions */ +#define SysTick_CTRL_COUNTFLAG_Pos 16U /*!< SysTick CTRL: COUNTFLAG Position */ +#define SysTick_CTRL_COUNTFLAG_Msk (1UL << SysTick_CTRL_COUNTFLAG_Pos) /*!< SysTick CTRL: COUNTFLAG Mask */ + +#define SysTick_CTRL_CLKSOURCE_Pos 2U /*!< SysTick CTRL: CLKSOURCE Position */ +#define SysTick_CTRL_CLKSOURCE_Msk (1UL << SysTick_CTRL_CLKSOURCE_Pos) /*!< SysTick CTRL: CLKSOURCE Mask */ + +#define SysTick_CTRL_TICKINT_Pos 1U /*!< SysTick CTRL: TICKINT Position */ +#define SysTick_CTRL_TICKINT_Msk (1UL << SysTick_CTRL_TICKINT_Pos) /*!< SysTick CTRL: TICKINT Mask */ + +#define SysTick_CTRL_ENABLE_Pos 0U /*!< SysTick CTRL: ENABLE Position */ +#define SysTick_CTRL_ENABLE_Msk (1UL /*<< SysTick_CTRL_ENABLE_Pos*/) /*!< SysTick CTRL: ENABLE Mask */ + +/* SysTick Reload Register Definitions */ +#define SysTick_LOAD_RELOAD_Pos 0U /*!< SysTick LOAD: RELOAD Position */ +#define SysTick_LOAD_RELOAD_Msk (0xFFFFFFUL /*<< SysTick_LOAD_RELOAD_Pos*/) /*!< SysTick LOAD: RELOAD Mask */ + +/* SysTick Current Register Definitions */ +#define SysTick_VAL_CURRENT_Pos 0U /*!< SysTick VAL: CURRENT Position */ +#define SysTick_VAL_CURRENT_Msk (0xFFFFFFUL /*<< SysTick_VAL_CURRENT_Pos*/) /*!< SysTick VAL: CURRENT Mask */ + +/* SysTick Calibration Register Definitions */ +#define SysTick_CALIB_NOREF_Pos 31U /*!< SysTick CALIB: NOREF Position */ +#define SysTick_CALIB_NOREF_Msk (1UL << SysTick_CALIB_NOREF_Pos) /*!< SysTick CALIB: NOREF Mask */ + +#define SysTick_CALIB_SKEW_Pos 30U /*!< SysTick CALIB: SKEW Position */ +#define SysTick_CALIB_SKEW_Msk (1UL << SysTick_CALIB_SKEW_Pos) /*!< SysTick CALIB: SKEW Mask */ + +#define SysTick_CALIB_TENMS_Pos 0U /*!< SysTick CALIB: TENMS Position */ +#define SysTick_CALIB_TENMS_Msk (0xFFFFFFUL /*<< SysTick_CALIB_TENMS_Pos*/) /*!< SysTick CALIB: TENMS Mask */ + +/** @} end of group CMSIS_SysTick */ + +#if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U) +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_MPU Memory Protection Unit (MPU) + \brief Type definitions for the Memory Protection Unit (MPU) + @{ + */ + +/** + \brief Structure type to access the Memory Protection Unit (MPU). + */ +typedef struct +{ + __IM uint32_t TYPE; /*!< Offset: 0x000 (R/ ) MPU Type Register */ + __IOM uint32_t CTRL; /*!< Offset: 0x004 (R/W) MPU Control Register */ + __IOM uint32_t RNR; /*!< Offset: 0x008 (R/W) MPU Region RNRber Register */ + __IOM uint32_t RBAR; /*!< Offset: 0x00C (R/W) MPU Region Base Address Register */ + __IOM uint32_t RASR; /*!< Offset: 0x010 (R/W) MPU Region Attribute and Size Register */ +} MPU_Type; + +#define MPU_TYPE_RALIASES 1U + +/* MPU Type Register Definitions */ +#define MPU_TYPE_IREGION_Pos 16U /*!< MPU TYPE: IREGION Position */ +#define MPU_TYPE_IREGION_Msk (0xFFUL << MPU_TYPE_IREGION_Pos) /*!< MPU TYPE: IREGION Mask */ + +#define MPU_TYPE_DREGION_Pos 8U /*!< MPU TYPE: DREGION Position */ +#define MPU_TYPE_DREGION_Msk (0xFFUL << MPU_TYPE_DREGION_Pos) /*!< MPU TYPE: DREGION Mask */ + +#define MPU_TYPE_SEPARATE_Pos 0U /*!< MPU TYPE: SEPARATE Position */ +#define MPU_TYPE_SEPARATE_Msk (1UL /*<< MPU_TYPE_SEPARATE_Pos*/) /*!< MPU TYPE: SEPARATE Mask */ + +/* MPU Control Register Definitions */ +#define MPU_CTRL_PRIVDEFENA_Pos 2U /*!< MPU CTRL: PRIVDEFENA Position */ +#define MPU_CTRL_PRIVDEFENA_Msk (1UL << MPU_CTRL_PRIVDEFENA_Pos) /*!< MPU CTRL: PRIVDEFENA Mask */ + +#define MPU_CTRL_HFNMIENA_Pos 1U /*!< MPU CTRL: HFNMIENA Position */ +#define MPU_CTRL_HFNMIENA_Msk (1UL << MPU_CTRL_HFNMIENA_Pos) /*!< MPU CTRL: HFNMIENA Mask */ + +#define MPU_CTRL_ENABLE_Pos 0U /*!< MPU CTRL: ENABLE Position */ +#define MPU_CTRL_ENABLE_Msk (1UL /*<< MPU_CTRL_ENABLE_Pos*/) /*!< MPU CTRL: ENABLE Mask */ + +/* MPU Region Number Register Definitions */ +#define MPU_RNR_REGION_Pos 0U /*!< MPU RNR: REGION Position */ +#define MPU_RNR_REGION_Msk (0xFFUL /*<< MPU_RNR_REGION_Pos*/) /*!< MPU RNR: REGION Mask */ + +/* MPU Region Base Address Register Definitions */ +#define MPU_RBAR_ADDR_Pos 8U /*!< MPU RBAR: ADDR Position */ +#define MPU_RBAR_ADDR_Msk (0xFFFFFFUL << MPU_RBAR_ADDR_Pos) /*!< MPU RBAR: ADDR Mask */ + +#define MPU_RBAR_VALID_Pos 4U /*!< MPU RBAR: VALID Position */ +#define MPU_RBAR_VALID_Msk (1UL << MPU_RBAR_VALID_Pos) /*!< MPU RBAR: VALID Mask */ + +#define MPU_RBAR_REGION_Pos 0U /*!< MPU RBAR: REGION Position */ +#define MPU_RBAR_REGION_Msk (0xFUL /*<< MPU_RBAR_REGION_Pos*/) /*!< MPU RBAR: REGION Mask */ + +/* MPU Region Attribute and Size Register Definitions */ +#define MPU_RASR_ATTRS_Pos 16U /*!< MPU RASR: MPU Region Attribute field Position */ +#define MPU_RASR_ATTRS_Msk (0xFFFFUL << MPU_RASR_ATTRS_Pos) /*!< MPU RASR: MPU Region Attribute field Mask */ + +#define MPU_RASR_XN_Pos 28U /*!< MPU RASR: ATTRS.XN Position */ +#define MPU_RASR_XN_Msk (1UL << MPU_RASR_XN_Pos) /*!< MPU RASR: ATTRS.XN Mask */ + +#define MPU_RASR_AP_Pos 24U /*!< MPU RASR: ATTRS.AP Position */ +#define MPU_RASR_AP_Msk (0x7UL << MPU_RASR_AP_Pos) /*!< MPU RASR: ATTRS.AP Mask */ + +#define MPU_RASR_TEX_Pos 19U /*!< MPU RASR: ATTRS.TEX Position */ +#define MPU_RASR_TEX_Msk (0x7UL << MPU_RASR_TEX_Pos) /*!< MPU RASR: ATTRS.TEX Mask */ + +#define MPU_RASR_S_Pos 18U /*!< MPU RASR: ATTRS.S Position */ +#define MPU_RASR_S_Msk (1UL << MPU_RASR_S_Pos) /*!< MPU RASR: ATTRS.S Mask */ + +#define MPU_RASR_C_Pos 17U /*!< MPU RASR: ATTRS.C Position */ +#define MPU_RASR_C_Msk (1UL << MPU_RASR_C_Pos) /*!< MPU RASR: ATTRS.C Mask */ + +#define MPU_RASR_B_Pos 16U /*!< MPU RASR: ATTRS.B Position */ +#define MPU_RASR_B_Msk (1UL << MPU_RASR_B_Pos) /*!< MPU RASR: ATTRS.B Mask */ + +#define MPU_RASR_SRD_Pos 8U /*!< MPU RASR: Sub-Region Disable Position */ +#define MPU_RASR_SRD_Msk (0xFFUL << MPU_RASR_SRD_Pos) /*!< MPU RASR: Sub-Region Disable Mask */ + +#define MPU_RASR_SIZE_Pos 1U /*!< MPU RASR: Region Size Field Position */ +#define MPU_RASR_SIZE_Msk (0x1FUL << MPU_RASR_SIZE_Pos) /*!< MPU RASR: Region Size Field Mask */ + +#define MPU_RASR_ENABLE_Pos 0U /*!< MPU RASR: Region enable bit Position */ +#define MPU_RASR_ENABLE_Msk (1UL /*<< MPU_RASR_ENABLE_Pos*/) /*!< MPU RASR: Region enable bit Disable Mask */ + +/** @} end of group CMSIS_MPU */ +#endif + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_CoreDebug Core Debug Registers (CoreDebug) + \brief Cortex-M0+ Core Debug Registers (DCB registers, SHCSR, and DFSR) are only accessible over DAP and not via processor. + Therefore they are not covered by the Cortex-M0+ header file. + @{ + */ +/** @} end of group CMSIS_CoreDebug */ + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_core_bitfield Core register bit field macros + \brief Macros for use with bit field definitions (xxx_Pos, xxx_Msk). + @{ + */ + +/** + \brief Mask and shift a bit field value for use in a register bit range. + \param[in] field Name of the register bit field. + \param[in] value Value of the bit field. This parameter is interpreted as an uint32_t type. + \return Masked and shifted value. +*/ +#define _VAL2FLD(field, value) (((uint32_t)(value) << field ## _Pos) & field ## _Msk) + +/** + \brief Mask and shift a register value to extract a bit filed value. + \param[in] field Name of the register bit field. + \param[in] value Value of register. This parameter is interpreted as an uint32_t type. + \return Masked and shifted bit field value. +*/ +#define _FLD2VAL(field, value) (((uint32_t)(value) & field ## _Msk) >> field ## _Pos) + +/** @} end of group CMSIS_core_bitfield */ + + +/** + \ingroup CMSIS_core_register + \defgroup CMSIS_core_base Core Definitions + \brief Definitions for base addresses, unions, and structures. + @{ + */ + +/* Memory mapping of Core Hardware */ +#define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */ +#define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */ +#define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */ +#define SCB_BASE (SCS_BASE + 0x0D00UL) /*!< System Control Block Base Address */ + +#define SCB ((SCB_Type *) SCB_BASE ) /*!< SCB configuration struct */ +#define SysTick ((SysTick_Type *) SysTick_BASE ) /*!< SysTick configuration struct */ +#define NVIC ((NVIC_Type *) NVIC_BASE ) /*!< NVIC configuration struct */ + +#if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U) + #define MPU_BASE (SCS_BASE + 0x0D90UL) /*!< Memory Protection Unit */ + #define MPU ((MPU_Type *) MPU_BASE ) /*!< Memory Protection Unit */ +#endif + +/** @} */ + + + +/******************************************************************************* + * Hardware Abstraction Layer + Core Function Interface contains: + - Core NVIC Functions + - Core SysTick Functions + - Core Register Access Functions + ******************************************************************************/ +/** + \defgroup CMSIS_Core_FunctionInterface Functions and Instructions Reference +*/ + + + +/* ########################## NVIC functions #################################### */ +/** + \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_NVICFunctions NVIC Functions + \brief Functions that manage interrupts and exceptions via the NVIC. + @{ + */ + +#ifdef CMSIS_NVIC_VIRTUAL + #ifndef CMSIS_NVIC_VIRTUAL_HEADER_FILE + #define CMSIS_NVIC_VIRTUAL_HEADER_FILE "cmsis_nvic_virtual.h" + #endif + #include CMSIS_NVIC_VIRTUAL_HEADER_FILE +#else +/*#define NVIC_SetPriorityGrouping __NVIC_SetPriorityGrouping not available for Cortex-M0+ */ +/*#define NVIC_GetPriorityGrouping __NVIC_GetPriorityGrouping not available for Cortex-M0+ */ + #define NVIC_EnableIRQ __NVIC_EnableIRQ + #define NVIC_GetEnableIRQ __NVIC_GetEnableIRQ + #define NVIC_DisableIRQ __NVIC_DisableIRQ + #define NVIC_GetPendingIRQ __NVIC_GetPendingIRQ + #define NVIC_SetPendingIRQ __NVIC_SetPendingIRQ + #define NVIC_ClearPendingIRQ __NVIC_ClearPendingIRQ +/*#define NVIC_GetActive __NVIC_GetActive not available for Cortex-M0+ */ + #define NVIC_SetPriority __NVIC_SetPriority + #define NVIC_GetPriority __NVIC_GetPriority + #define NVIC_SystemReset __NVIC_SystemReset +#endif /* CMSIS_NVIC_VIRTUAL */ + +#ifdef CMSIS_VECTAB_VIRTUAL + #ifndef CMSIS_VECTAB_VIRTUAL_HEADER_FILE + #define CMSIS_VECTAB_VIRTUAL_HEADER_FILE "cmsis_vectab_virtual.h" + #endif + #include CMSIS_VECTAB_VIRTUAL_HEADER_FILE +#else + #define NVIC_SetVector __NVIC_SetVector + #define NVIC_GetVector __NVIC_GetVector +#endif /* (CMSIS_VECTAB_VIRTUAL) */ + +#define NVIC_USER_IRQ_OFFSET 16 + + +/* Interrupt Priorities are WORD accessible only under Armv6-M */ +/* The following MACROS handle generation of the register offset and byte masks */ +#define _BIT_SHIFT(IRQn) ( ((((uint32_t)(int32_t)(IRQn)) ) & 0x03UL) * 8UL) +#define _SHP_IDX(IRQn) ( (((((uint32_t)(int32_t)(IRQn)) & 0x0FUL)-8UL) >> 2UL) ) +#define _IP_IDX(IRQn) ( (((uint32_t)(int32_t)(IRQn)) >> 2UL) ) + + +/** + \brief Enable Interrupt + \details Enables a device specific interrupt in the NVIC interrupt controller. + \param [in] IRQn Device specific interrupt number. + \note IRQn must not be negative. + */ +__STATIC_INLINE void __NVIC_EnableIRQ(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + NVIC->ISER[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + } +} + + +/** + \brief Get Interrupt Enable status + \details Returns a device specific interrupt enable status from the NVIC interrupt controller. + \param [in] IRQn Device specific interrupt number. + \return 0 Interrupt is not enabled. + \return 1 Interrupt is enabled. + \note IRQn must not be negative. + */ +__STATIC_INLINE uint32_t __NVIC_GetEnableIRQ(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + return((uint32_t)(((NVIC->ISER[0U] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); + } + else + { + return(0U); + } +} + + +/** + \brief Disable Interrupt + \details Disables a device specific interrupt in the NVIC interrupt controller. + \param [in] IRQn Device specific interrupt number. + \note IRQn must not be negative. + */ +__STATIC_INLINE void __NVIC_DisableIRQ(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + NVIC->ICER[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + __DSB(); + __ISB(); + } +} + + +/** + \brief Get Pending Interrupt + \details Reads the NVIC pending register and returns the pending bit for the specified device specific interrupt. + \param [in] IRQn Device specific interrupt number. + \return 0 Interrupt status is not pending. + \return 1 Interrupt status is pending. + \note IRQn must not be negative. + */ +__STATIC_INLINE uint32_t __NVIC_GetPendingIRQ(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + return((uint32_t)(((NVIC->ISPR[0U] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); + } + else + { + return(0U); + } +} + + +/** + \brief Set Pending Interrupt + \details Sets the pending bit of a device specific interrupt in the NVIC pending register. + \param [in] IRQn Device specific interrupt number. + \note IRQn must not be negative. + */ +__STATIC_INLINE void __NVIC_SetPendingIRQ(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + NVIC->ISPR[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + } +} + + +/** + \brief Clear Pending Interrupt + \details Clears the pending bit of a device specific interrupt in the NVIC pending register. + \param [in] IRQn Device specific interrupt number. + \note IRQn must not be negative. + */ +__STATIC_INLINE void __NVIC_ClearPendingIRQ(IRQn_Type IRQn) +{ + if ((int32_t)(IRQn) >= 0) + { + NVIC->ICPR[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + } +} + + +/** + \brief Set Interrupt Priority + \details Sets the priority of a device specific interrupt or a processor exception. + The interrupt number can be positive to specify a device specific interrupt, + or negative to specify a processor exception. + \param [in] IRQn Interrupt number. + \param [in] priority Priority to set. + \note The priority cannot be set for every processor exception. + */ +__STATIC_INLINE void __NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority) +{ + if ((int32_t)(IRQn) >= 0) + { + NVIC->IP[_IP_IDX(IRQn)] = ((uint32_t)(NVIC->IP[_IP_IDX(IRQn)] & ~(0xFFUL << _BIT_SHIFT(IRQn))) | + (((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn))); + } + else + { + SCB->SHP[_SHP_IDX(IRQn)] = ((uint32_t)(SCB->SHP[_SHP_IDX(IRQn)] & ~(0xFFUL << _BIT_SHIFT(IRQn))) | + (((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn))); + } +} + + +/** + \brief Get Interrupt Priority + \details Reads the priority of a device specific interrupt or a processor exception. + The interrupt number can be positive to specify a device specific interrupt, + or negative to specify a processor exception. + \param [in] IRQn Interrupt number. + \return Interrupt Priority. + Value is aligned automatically to the implemented priority bits of the microcontroller. + */ +__STATIC_INLINE uint32_t __NVIC_GetPriority(IRQn_Type IRQn) +{ + + if ((int32_t)(IRQn) >= 0) + { + return((uint32_t)(((NVIC->IP[ _IP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8U - __NVIC_PRIO_BITS))); + } + else + { + return((uint32_t)(((SCB->SHP[_SHP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8U - __NVIC_PRIO_BITS))); + } +} + + +/** + \brief Set Interrupt Vector + \details Sets an interrupt vector in SRAM based interrupt vector table. + The interrupt number can be positive to specify a device specific interrupt, + or negative to specify a processor exception. + VTOR must been relocated to SRAM before. + If VTOR is not present address 0 must be mapped to SRAM. + \param [in] IRQn Interrupt number + \param [in] vector Address of interrupt handler function + */ +__STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) +{ +#if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U) + uint32_t *vectors = (uint32_t *)SCB->VTOR; +#else + uint32_t *vectors = (uint32_t *)0x0U; +#endif + vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET] = vector; +} + + +/** + \brief Get Interrupt Vector + \details Reads an interrupt vector from interrupt vector table. + The interrupt number can be positive to specify a device specific interrupt, + or negative to specify a processor exception. + \param [in] IRQn Interrupt number. + \return Address of interrupt handler function + */ +__STATIC_INLINE uint32_t __NVIC_GetVector(IRQn_Type IRQn) +{ +#if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U) + uint32_t *vectors = (uint32_t *)SCB->VTOR; +#else + uint32_t *vectors = (uint32_t *)0x0U; +#endif + return vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET]; + +} + + +/** + \brief System Reset + \details Initiates a system reset request to reset the MCU. + */ +__STATIC_INLINE void __NVIC_SystemReset(void) +{ + __DSB(); /* Ensure all outstanding memory accesses included + buffered write are completed before reset */ + SCB->AIRCR = ((0x5FAUL << SCB_AIRCR_VECTKEY_Pos) | + SCB_AIRCR_SYSRESETREQ_Msk); + __DSB(); /* Ensure completion of memory access */ + + for(;;) /* wait until reset */ + { + __NOP(); + } +} + +/** @} end of CMSIS_Core_NVICFunctions */ + +/* ########################## MPU functions #################################### */ + +#if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U) + +#include "mpu_armv7.h" + +#endif + +/* ########################## FPU functions #################################### */ +/** + \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_FpuFunctions FPU Functions + \brief Function that provides FPU type. + @{ + */ + +/** + \brief get FPU type + \details returns the FPU type + \returns + - \b 0: No FPU + - \b 1: Single precision FPU + - \b 2: Double + Single precision FPU + */ +__STATIC_INLINE uint32_t SCB_GetFPUType(void) +{ + return 0U; /* No FPU */ +} + + +/** @} end of CMSIS_Core_FpuFunctions */ + + + +/* ################################## SysTick function ############################################ */ +/** + \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_SysTickFunctions SysTick Functions + \brief Functions that configure the System. + @{ + */ + +#if defined (__Vendor_SysTickConfig) && (__Vendor_SysTickConfig == 0U) + +/** + \brief System Tick Configuration + \details Initializes the System Timer and its interrupt, and starts the System Tick Timer. + Counter is in free running mode to generate periodic interrupts. + \param [in] ticks Number of ticks between two interrupts. + \return 0 Function succeeded. + \return 1 Function failed. + \note When the variable __Vendor_SysTickConfig is set to 1, then the + function SysTick_Config is not included. In this case, the file device.h + must contain a vendor-specific implementation of this function. + */ +__STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks) +{ + if ((ticks - 1UL) > SysTick_LOAD_RELOAD_Msk) + { + return (1UL); /* Reload value impossible */ + } + + SysTick->LOAD = (uint32_t)(ticks - 1UL); /* set reload register */ + NVIC_SetPriority (SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL); /* set Priority for Systick Interrupt */ + SysTick->VAL = 0UL; /* Load the SysTick Counter Value */ + SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | + SysTick_CTRL_TICKINT_Msk | + SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */ + return (0UL); /* Function successful */ +} + +#endif + +/** @} end of CMSIS_Core_SysTickFunctions */ + + + + +#ifdef __cplusplus +} +#endif + +#endif /* __CORE_CM0PLUS_H_DEPENDANT */ + +#endif /* __CMSIS_GENERIC */ diff --git a/Platform/Core/mpu_armv7.h b/Platform/Core/mpu_armv7.h new file mode 100644 index 0000000..aa180c9 --- /dev/null +++ b/Platform/Core/mpu_armv7.h @@ -0,0 +1,197 @@ +/****************************************************************************** + * @file mpu_armv7.h + * @brief CMSIS MPU API for Armv7-M MPU + * @version V5.0.4 + * @date 10. January 2018 + ******************************************************************************/ +/* + * Copyright (c) 2017-2018 Arm Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * 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 + * + * 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. + */ + +#if defined ( __ICCARM__ ) + #pragma system_include /* treat file as system include file for MISRA check */ +#elif defined (__clang__) + #pragma clang system_header /* treat file as system include file */ +#endif + +#ifndef ARM_MPU_ARMV7_H +#define ARM_MPU_ARMV7_H + +#define ARM_MPU_REGION_SIZE_32B ((uint8_t)0x04U) +#define ARM_MPU_REGION_SIZE_64B ((uint8_t)0x05U) +#define ARM_MPU_REGION_SIZE_128B ((uint8_t)0x06U) +#define ARM_MPU_REGION_SIZE_256B ((uint8_t)0x07U) +#define ARM_MPU_REGION_SIZE_512B ((uint8_t)0x08U) +#define ARM_MPU_REGION_SIZE_1KB ((uint8_t)0x09U) +#define ARM_MPU_REGION_SIZE_2KB ((uint8_t)0x0AU) +#define ARM_MPU_REGION_SIZE_4KB ((uint8_t)0x0BU) +#define ARM_MPU_REGION_SIZE_8KB ((uint8_t)0x0CU) +#define ARM_MPU_REGION_SIZE_16KB ((uint8_t)0x0DU) +#define ARM_MPU_REGION_SIZE_32KB ((uint8_t)0x0EU) +#define ARM_MPU_REGION_SIZE_64KB ((uint8_t)0x0FU) +#define ARM_MPU_REGION_SIZE_128KB ((uint8_t)0x10U) +#define ARM_MPU_REGION_SIZE_256KB ((uint8_t)0x11U) +#define ARM_MPU_REGION_SIZE_512KB ((uint8_t)0x12U) +#define ARM_MPU_REGION_SIZE_1MB ((uint8_t)0x13U) +#define ARM_MPU_REGION_SIZE_2MB ((uint8_t)0x14U) +#define ARM_MPU_REGION_SIZE_4MB ((uint8_t)0x15U) +#define ARM_MPU_REGION_SIZE_8MB ((uint8_t)0x16U) +#define ARM_MPU_REGION_SIZE_16MB ((uint8_t)0x17U) +#define ARM_MPU_REGION_SIZE_32MB ((uint8_t)0x18U) +#define ARM_MPU_REGION_SIZE_64MB ((uint8_t)0x19U) +#define ARM_MPU_REGION_SIZE_128MB ((uint8_t)0x1AU) +#define ARM_MPU_REGION_SIZE_256MB ((uint8_t)0x1BU) +#define ARM_MPU_REGION_SIZE_512MB ((uint8_t)0x1CU) +#define ARM_MPU_REGION_SIZE_1GB ((uint8_t)0x1DU) +#define ARM_MPU_REGION_SIZE_2GB ((uint8_t)0x1EU) +#define ARM_MPU_REGION_SIZE_4GB ((uint8_t)0x1FU) + +#define ARM_MPU_AP_NONE 0U +#define ARM_MPU_AP_PRIV 1U +#define ARM_MPU_AP_URO 2U +#define ARM_MPU_AP_FULL 3U +#define ARM_MPU_AP_PRO 5U +#define ARM_MPU_AP_RO 6U + +/** MPU Region Base Address Register Value +* +* \param Region The region to be configured, number 0 to 15. +* \param BaseAddress The base address for the region. +*/ +#define ARM_MPU_RBAR(Region, BaseAddress) \ + (((BaseAddress) & MPU_RBAR_ADDR_Msk) | \ + ((Region) & MPU_RBAR_REGION_Msk) | \ + (MPU_RBAR_VALID_Msk)) + +/** +* MPU Region Attribute and Size Register Value +* +* \param DisableExec Instruction access disable bit, 1= disable instruction fetches. +* \param AccessPermission Data access permissions, allows you to configure read/write access for User and Privileged mode. +* \param TypeExtField Type extension field, allows you to configure memory access type, for example strongly ordered, peripheral. +* \param IsShareable Region is shareable between multiple bus masters. +* \param IsCacheable Region is cacheable, i.e. its value may be kept in cache. +* \param IsBufferable Region is bufferable, i.e. using write-back caching. Cacheable but non-bufferable regions use write-through policy. +* \param SubRegionDisable Sub-region disable field. +* \param Size Region size of the region to be configured, for example 4K, 8K. +*/ +#define ARM_MPU_RASR(DisableExec, AccessPermission, TypeExtField, IsShareable, IsCacheable, IsBufferable, SubRegionDisable, Size) \ + ((((DisableExec ) << MPU_RASR_XN_Pos) & MPU_RASR_XN_Msk) | \ + (((AccessPermission) << MPU_RASR_AP_Pos) & MPU_RASR_AP_Msk) | \ + (((TypeExtField ) << MPU_RASR_TEX_Pos) & MPU_RASR_TEX_Msk) | \ + (((IsShareable ) << MPU_RASR_S_Pos) & MPU_RASR_S_Msk) | \ + (((IsCacheable ) << MPU_RASR_C_Pos) & MPU_RASR_C_Msk) | \ + (((IsBufferable ) << MPU_RASR_B_Pos) & MPU_RASR_B_Msk) | \ + (((SubRegionDisable) << MPU_RASR_SRD_Pos) & MPU_RASR_SRD_Msk) | \ + (((Size ) << MPU_RASR_SIZE_Pos) & MPU_RASR_SIZE_Msk) | \ + (MPU_RASR_ENABLE_Msk)) + + +/** +* Struct for a single MPU Region +*/ +typedef struct { + uint32_t RBAR; //!< The region base address register value (RBAR) + uint32_t RASR; //!< The region attribute and size register value (RASR) \ref MPU_RASR +} ARM_MPU_Region_t; + +/** Enable the MPU. +* \param MPU_Control Default access permissions for unconfigured regions. +*/ +__STATIC_INLINE void ARM_MPU_Enable(uint32_t MPU_Control) +{ + __DSB(); + __ISB(); + MPU->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk; +#ifdef SCB_SHCSR_MEMFAULTENA_Msk + SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk; +#endif +} + +/** Disable the MPU. +*/ +__STATIC_INLINE void ARM_MPU_Disable(void) +{ + __DSB(); + __ISB(); +#ifdef SCB_SHCSR_MEMFAULTENA_Msk + SCB->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk; +#endif + MPU->CTRL &= ~MPU_CTRL_ENABLE_Msk; +} + +/** Clear and disable the given MPU region. +* \param rnr Region number to be cleared. +*/ +__STATIC_INLINE void ARM_MPU_ClrRegion(uint32_t rnr) +{ + MPU->RNR = rnr; + MPU->RASR = 0U; +} + +/** Configure an MPU region. +* \param rbar Value for RBAR register. +* \param rsar Value for RSAR register. +*/ +__STATIC_INLINE void ARM_MPU_SetRegion(uint32_t rbar, uint32_t rasr) +{ + MPU->RBAR = rbar; + MPU->RASR = rasr; +} + +/** Configure the given MPU region. +* \param rnr Region number to be configured. +* \param rbar Value for RBAR register. +* \param rsar Value for RSAR register. +*/ +__STATIC_INLINE void ARM_MPU_SetRegionEx(uint32_t rnr, uint32_t rbar, uint32_t rasr) +{ + MPU->RNR = rnr; + MPU->RBAR = rbar; + MPU->RASR = rasr; +} + +/** Memcopy with strictly ordered memory access, e.g. for register targets. +* \param dst Destination data is copied to. +* \param src Source data is copied from. +* \param len Amount of data words to be copied. +*/ +__STATIC_INLINE void orderedCpy(volatile uint32_t* dst, const uint32_t* __RESTRICT src, uint32_t len) +{ + uint32_t i; + for (i = 0U; i < len; ++i) + { + dst[i] = src[i]; + } +} + +/** Load the given number of MPU regions from a table. +* \param table Pointer to the MPU configuration table. +* \param cnt Amount of regions to be configured. +*/ +__STATIC_INLINE void ARM_MPU_Load(ARM_MPU_Region_t const* table, uint32_t cnt) +{ + const uint32_t rowWordSize = sizeof(ARM_MPU_Region_t)/4U; + while (cnt > MPU_TYPE_RALIASES) { + orderedCpy(&(MPU->RBAR), &(table->RBAR), MPU_TYPE_RALIASES*rowWordSize); + table += MPU_TYPE_RALIASES; + cnt -= MPU_TYPE_RALIASES; + } + orderedCpy(&(MPU->RBAR), &(table->RBAR), cnt*rowWordSize); +} + +#endif diff --git a/Platform/Devices/Z20K114M/Inc/Z20K114M.h b/Platform/Devices/Z20K114M/Inc/Z20K114M.h new file mode 100644 index 0000000..ec491d7 --- /dev/null +++ b/Platform/Devices/Z20K114M/Inc/Z20K114M.h @@ -0,0 +1,4613 @@ +/**************************************************************************************************/ +/** + * @file : Z20K114M.h + * @brief : Z20K114M device header file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ + +#ifndef Z20K114M_H +#define Z20K114M_H + +#include +#include +#include + +/** + * @brief Variant Peripheral Instance Information + */ +#define CAN_INSTANCE_NUM (1U) +#define SPI_INSTANCE_NUM (2U) +#define I2C_INSTANCE_NUM (1U) +#define UART_INSTANCE_NUM (3U) + +/** + * @brief Peripheral Base Address + */ +#define FLASH_CODE_BASE_ADDR ((uint32_t)0x00000000) /*!< Code flash base address */ +#define FLASH_DATA_BASE_ADDR ((uint32_t)0x01000000) /*!< Data flash base address */ +#define FLASH_IFR_BASE_ADDR ((uint32_t)0x02000000) /*!< flash IFR base address */ +#define SRAMU_BASE_ADDR ((uint32_t)0x20000000) /*!< SRAMU base address */ +#define PERIPHERAL_BASE_ADDR ((uint32_t)0x40000000) /*!< Peripheral area base address */ +#define AIPS0_BASE_ADDR ((uint32_t)0x40000000) /*!< AIPS0 base address */ + +#define PRI_PERI_BUS_BASE_ADDR ((uint32_t)0xE0000000) /*!< private Peripheral base address */ + +#define DMA_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x8000UL) /*!< DMA controller base address */ +#define FLASHC_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x20000UL) /*!< flash controller base address */ +#define DMAMUX_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x22000UL) /*!< DMA channel Multiplexer base address */ +#define CAN0_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x24000UL) /*!< CAN0 base address */ +#define ADC0_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x26000UL) /*!< ADC0 base address */ +#define RTC_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x28000UL) /*!< RTC base address */ +#define SPI0_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x2C000UL) /*!< SPI0 base address */ +#define SPI1_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x2D000UL) /*!< SPI1 base address */ +#define REGFILE_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x34000UL) /*!< REGFILE base address */ +#define TDG0_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x35000UL) /*!< TDG0 base address */ +#define TMU_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x36000UL) /*!< TMU base address */ +#define TIM0_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x38000UL) /*!< TIM0 base address */ +#define TIM1_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x39000UL) /*!< TIM1 base address */ +#define TIM2_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x3A000UL) /*!< TIM2 base address */ +#define STIM_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x40000UL) /*!< STIM base address */ +#define CRC_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x43000UL) /*!< CRC base address */ +#define SCM_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x48000UL) /*!< System Control base address */ +#define PORTA_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x49000UL) /*!< PORTA multiplexing base address */ +#define PORTB_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x4A000UL) /*!< PORTB multiplexing base address */ +#define PORTC_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x4B000UL) /*!< PORTC multiplexing base address */ +#define PORTD_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x4C000UL) /*!< PORTD multiplexing base address */ +#define PORTE_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x4D000UL) /*!< PORTE multiplexing base address */ +#define WDOG_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x52000UL) /*!< watchdog base address */ +#define EWDT_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x61000UL) /*!< External Watchdog Monitor base address */ +#define SCC_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x64000UL) /*!< System Clock Controller base address */ +#define PARCC_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x65000UL) /*!< Peripheral Clock Control base address */ +#define I2C0_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x66000UL) /*!< I2C0 base address */ +#define UART0_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x6A000UL) /*!< UART0 base address */ +#define UART1_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x6B000UL) /*!< UART1 base address */ +#define UART2_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x6C000UL) /*!< UART2 base address */ +#define CMP_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x73000UL) /*!< Analog comparator base address */ +#define PMU_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x7D000UL) /*!< Power management Unit base address */ +#define SRMC_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x7E000UL) /*!< system reset and mode controller base address */ +#define HWDIV_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0xFE000UL) /*!< HWDIV base address */ +#define GPIO_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0xFF000UL) /*!< GPIO controller base address */ +#define GPIOA_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0xFF000UL) /*!< GPIOA base address */ +#define GPIOB_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0xFF040UL) /*!< GPIOB base address */ +#define GPIOC_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0xFF080UL) /*!< GPIOC base address */ +#define GPIOD_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0xFF0C0UL) /*!< GPIOD base address */ +#define GPIOE_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0xFF100UL) /*!< GPIOE base address */ +#define RGPIO_BASE_ADDR 0xF8000000UL /*!< Fast GPIO controller base address */ +#define RGPIOA_BASE_ADDR (RGPIO_BASE_ADDR + 0x00000UL) /*!< Fast GPIOA controller base address */ +#define RGPIOB_BASE_ADDR (RGPIO_BASE_ADDR + 0x00040UL) /*!< Fast GPIOB controller base address */ +#define RGPIOC_BASE_ADDR (RGPIO_BASE_ADDR + 0x00080UL) /*!< Fast GPIOC controller base address */ +#define RGPIOD_BASE_ADDR (RGPIO_BASE_ADDR + 0x000C0UL) /*!< Fast GPIOD controller base address */ +#define RGPIOE_BASE_ADDR (RGPIO_BASE_ADDR + 0x00100UL) /*!< Fast GPIOE controller base address */ + +/** + * @brief IRQ Number Definition + */ +typedef enum IRQn +{ + /****** Cortex-M0+ Processor IRQ Numbers *******************************/ + NonMaskableInt_IRQn = -14, /*!< 2 Non Maskable Interrupt */ + HardFalut_IRQn = -13, /*!< 3 Hardfault Interrupt */ + SVCall_IRQn = -5, /*!< 11 Cortex-M0+ SV Call Interrupt */ + PendSV_IRQn = -2, /*!< 14 Cortex-M0+ Pend SV Interrupt */ + SysTick_IRQn = -1, /*!< 15 Cortex-M0+ System Tick Interrupt */ + + /****** specific IRQ Numbers *************************************/ + DMA0TO3_IRQn = 0, /*!< DMA channel 0-3 transfer complete Interrupt */ + DMA4TO7_IRQn = 1, /*!< DMA channel 4-7 transfer complete Interrupt */ + DMA8TO11_IRQn = 2, /*!< DMA channel 8-11 transfer complete Interrupt */ + DMA12TO15_IRQn = 3, /*!< DMA channel 12-15 transfer complete Interrupt */ + DMAERR_IRQn = 4, /*!< DMA error (channels 0-16) Interrupt */ + I2C0_IRQn = 5, /*!< I2C 0 Interrupt */ + Reserved6_IRQn = 6, /*!< Reserved Interrupt */ + SPI0_IRQn = 7, /*!< SPI 0 Interrupt */ + SPI1_IRQn = 8, /*!< SPI 1 Interrupt*/ + Reserved9_IRQn = 9, /*!< Reserved Interrupt */ + UART0_IRQn = 10, /*!< UART 0 Interrupt */ + UART1_IRQn = 11, /*!< UART 1 Interrupt */ + UART2_IRQn = 12, /*!< UART2 Interrupt */ + Reserved13_IRQn = 13, /*!< Reserved Interrupt*/ + ADC0_IRQn = 14, /*!< ADC0 Interrupt */ + FLASH_IRQn = 15, /*!< flash ISR */ + CMP_IRQn = 16, /*!< CMP Interrupt */ + TIM0_IRQn = 17, /*!< TIM 0 Interrupt */ + TIM1_IRQn = 18, /*!< TIM 1 Interrupt */ + TIM2_IRQn = 19, /*!< TIM 2 Interrupt */ + CAN0_IRQn = 20, /*!< CAN 0 Interrupt*/ + Reserved21_IRQn = 21, /*!< Reserved Interrupt */ + RTC_IRQn = 22, /*!< RTC Interrupt */ + PMU_IRQn = 23, /*!< PMU Interrupt */ + TDG0_IRQn = 24, /*!< TDG0 Interrupt */ + SCC_IRQn = 25, /*!< system clock controller Interrupt*/ + WDOG_IRQn = 26, /*!< watchdog Interrupt */ + EWDT_IRQn = 27, /*!< external watchdog monitor Interrupt*/ + STIM_IRQn = 28, /*!< STIM Interrupt */ + SRMC_IRQn = 29, /*!< system reset and mode control Interrupt*/ + PORTABC_IRQn = 30, /*!< port A B C Interrupt */ + PORTDE_IRQn = 31 /*!< port D E Interrupt */ +} IRQn_Type; + +/** + * Peripheral Register Defination + */ +struct adc_reg { + /* 0x000*/ + struct { + uint32_t DIFFEN : 1; /* [0] ro */ + uint32_t CALOFSI : 1; /* [1] ro */ + uint32_t RSVD_7_2 : 6; /* [7:2] ro */ + uint32_t FIFO_NUM : 8; /* [15:8] ro */ + uint32_t MINOR : 8; /* [23:16] ro */ + uint32_t MAJOR : 8; /* [31:24] ro */ + } ADC_VERID; + + /* 0x004*/ + struct { + uint32_t RSVD_7_0 : 8; /* [7:0] ro */ + uint32_t FIFO_SIZE : 8; /* [15:8] ro */ + uint32_t RSVD_31_16 :16; /* [31:16] ro */ + } ADC_PARAM; + + /* 0x008*/ + struct { + uint32_t ADC_EN : 1; /* [0] r/w */ + uint32_t CAL_REQ : 1; /* [1] r/w */ + uint32_t RST : 1; /* [2] r/w */ + uint32_t DOZEN : 1; /* [3] r/w */ + uint32_t TRIG_MODE_ENABLE : 1; /* [4] r/w */ + uint32_t TRIG_MODE : 1; /* [5] r/w */ + uint32_t MODE1_RST : 1; /* [6] r/w */ + uint32_t RSVD_31_7 :25; /* [31:7] ro */ + } ADC_CTRL; + + /* 0x00C*/ + struct { + uint32_t FWM_INT : 1; /* [0] r/w1c */ + uint32_t FOF : 1; /* [1] r/w1c */ + uint32_t TCOMP_INT : 1; /* [2] r/w1c */ + uint32_t CMP_INT : 1; /* [3] r/w1c */ + uint32_t DMA_REQ : 1; /* [4] ro */ + uint32_t RDY : 1; /* [5] ro */ + uint32_t CAL_RDY : 1; /* [6] ro */ + uint32_t ADC_ACTIVE : 1; /* [7] ro */ + uint32_t LSI : 1; /* [8] ro */ + uint32_t TC_ERR : 1; /* [9] ro */ + uint32_t RSVD_31_10 :22; /* [31:10] ro */ + } ADC_STAT; + + /* 0x010*/ + struct { + uint32_t FWM_IE : 1; /* [0] r/w */ + uint32_t FOF_IE : 1; /* [1] r/w */ + uint32_t TCOM_IE : 1; /* [2] r/w */ + uint32_t CMP_IE : 1; /* [3] r/w */ + uint32_t FWMDE : 1; /* [4] r/w */ + uint32_t ERR_INT_IE : 1; /* [5] r/w */ + uint32_t RSVD_31_6 :26; /* [31:6] ro */ + } ADC_IE; + + /* 0x014*/ + struct { + uint32_t DIFF_MODE : 1; /* [0] r/w */ + uint32_t CHSELP : 5; /* [5:1] r/w */ + uint32_t CHSELN : 2; /* [7:6] r/w */ + uint32_t RSVD_10_8 : 3; /* [10:8] ro */ + uint32_t CTYPE : 1; /* [11] r/w */ + uint32_t CMPS : 3; /* [14:12] r/w */ + uint32_t RSVD_15 : 1; /* [15] r/w */ + uint32_t REF_SEL : 1; /* [16] r/w */ + uint32_t RES : 2; /* [18:17] r/w */ + uint32_t AVGS : 3; /* [21:19] r/w */ + uint32_t STS :10; /* [31:22] r/w */ + } ADC_CFG; + + /* 0x018*/ + struct { + uint32_t CVL :12; /* [11:0] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] ro */ + uint32_t CVH :12; /* [27:16] r/w */ + uint32_t RSVD_31_28 : 4; /* [31:28] ro */ + } ADC_CV; + + /* 0x01C*/ + struct { + uint32_t RSVD_5_0 : 6; /* [5:0] ro */ + uint32_t RSVD_6 : 1; /* [6] ro */ + uint32_t RSVD_10_7 : 4; /* [10:7] ro */ + uint32_t RSVD_30_11 :20; /* [30:11] ro */ + uint32_t RSVD_31 : 1; /* [31] r/w */ + } ADC_RSVD; + + /* 0x020*/ + struct { + uint32_t ADC_DATA_RD :17; /* [16:0] ro */ + uint32_t RSVD_31_17 :15; /* [31:17] ro */ + } ADC_DATA_RD; + + /* 0x024*/ + struct { + uint32_t FCOUNT : 5; /* [4:0] ro */ + uint32_t RSVD_15_5 :11; /* [15:5] ro */ + uint32_t FWMARK : 4; /* [19:16] r/w */ + uint32_t FDRD : 5; /* [24:20] r/w */ + uint32_t RSVD_31_25 : 7; /* [31:25] ro */ + } ADC_FCTRL; + + /* 0x028*/ + struct { + uint32_t ADC_SWTRIG : 1; /* [0] r/w */ + uint32_t RSVD_31_1 :31; /* [31:1] ro */ + } ADC_SWTRIG; + + /* 0x02C*/ + struct { + uint32_t ADC_CAL_VAL :13; /* [12:0] ro */ + uint32_t RSVD_31_13 :19; /* [31:13] ro */ + } ADC_CAL_VAL; + + /* 0x030*/ + struct { + uint32_t CMD0 : 5; /* [4:0] r/w */ + uint32_t RSVD_7_5 : 3; /* [7:5] ro */ + uint32_t CMD1 : 5; /* [12:8] r/w */ + uint32_t RSVD_15_13 : 3; /* [15:13] ro */ + uint32_t CMD2 : 5; /* [20:16] r/w */ + uint32_t RSVD_23_21 : 3; /* [23:21] ro */ + uint32_t CMD3 : 5; /* [28:24] r/w */ + uint32_t RSVD_31_29 : 3; /* [31:29] ro */ + } ADC_CMD_BUFF0; + + /* 0x034*/ + struct { + uint32_t CMD4 : 5; /* [4:0] r/w */ + uint32_t RSVD_7_5 : 3; /* [7:5] ro */ + uint32_t CMD5 : 5; /* [12:8] r/w */ + uint32_t RSVD_31_13 :19; /* [31:13] ro */ + } ADC_CMD_BUFF1; + +}; /*adc_reg*/ + +struct adc_reg_w { + /* 0x000*/ + uint32_t ADC_VERID; + /* 0x004*/ + uint32_t ADC_PARAM; + /* 0x008*/ + uint32_t ADC_CTRL; + /* 0x00C*/ + uint32_t ADC_STAT; + /* 0x010*/ + uint32_t ADC_IE; + /* 0x014*/ + uint32_t ADC_CFG; + /* 0x018*/ + uint32_t ADC_CV; + /* 0x01C*/ + uint32_t ADC_RSVD; + /* 0x020*/ + uint32_t ADC_DATA_RD; + /* 0x024*/ + uint32_t ADC_FCTRL; + /* 0x028*/ + uint32_t ADC_SWTRIG; + /* 0x02C*/ + uint32_t ADC_CAL_VAL; + /* 0x030*/ + uint32_t ADC_CMD_BUFF0; + /* 0x034*/ + uint32_t ADC_CMD_BUFF1; +}; /*adc_reg*/ + +typedef volatile struct adc_reg adc_reg_t; +typedef volatile struct adc_reg_w adc_reg_w_t; + +struct can_reg { + /* 0x00*/ + struct { + uint32_t MAXMB : 7; /* [6:0] r/w */ + uint32_t RSVD_7 : 1; /* [7] reserve */ + uint32_t IDAM : 2; /* [9:8] r/w */ + uint32_t RSVD_10 : 1; /* [10] reserve */ + uint32_t FDEN : 1; /* [11] r/w */ + uint32_t AEN : 1; /* [12] r/w */ + uint32_t LPRIOEN : 1; /* [13] r/w */ + uint32_t PNET_EN : 1; /* [14] r/w */ + uint32_t DMAE : 1; /* [15] r/w */ + uint32_t IRMQ : 1; /* [16] r/w */ + uint32_t SRXDIS : 1; /* [17] r/w */ + uint32_t DOZE : 1; /* [18] r/w */ + uint32_t WAKSRC : 1; /* [19] r/w */ + uint32_t LPMACK : 1; /* [20] read only */ + uint32_t WRNEN : 1; /* [21] r/w */ + uint32_t SLFWAK : 1; /* [22] r/w */ + uint32_t SUPV : 1; /* [23] r/w */ + uint32_t FRZACK : 1; /* [24] read only */ + uint32_t SOFTRST : 1; /* [25] r/w */ + uint32_t WAKMSK : 1; /* [26] r/w */ + uint32_t NOTRDY : 1; /* [27] read only */ + uint32_t HALT : 1; /* [28] r/w */ + uint32_t RFEN : 1; /* [29] r/w */ + uint32_t FRZ : 1; /* [30] r/w */ + uint32_t MDIS : 1; /* [31] r/w */ + } CAN_MCR; + + /* 0x04*/ + struct { + uint32_t PROPSEG : 3; /* [2:0] r/w */ + uint32_t LOM : 1; /* [3] r/w */ + uint32_t LBUF : 1; /* [4] r/w */ + uint32_t TSYC : 1; /* [5] r/w */ + uint32_t BOFFREC : 1; /* [6] r/w */ + uint32_t SMP : 1; /* [7] r/w */ + uint32_t RSVD_9_8 : 2; /* [9:8] reserve */ + uint32_t RWRNMSK : 1; /* [10] r/w */ + uint32_t TWRNMSK : 1; /* [11] r/w */ + uint32_t LPB : 1; /* [12] r/w */ + uint32_t RSVD_13 : 1; /* [13] reserve */ + uint32_t ERRMSK : 1; /* [14] r/w */ + uint32_t BOFFMSK : 1; /* [15] r/w */ + uint32_t PSEG2 : 3; /* [18:16] r/w */ + uint32_t PSEG1 : 3; /* [21:19] r/w */ + uint32_t RJW : 2; /* [23:22] r/w */ + uint32_t PRESDIV : 8; /* [31:24] r/w */ + } CAN_CTRL1; + + /* 0x08*/ + struct { + uint32_t TIMER :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] reserve */ + } CAN_TIMER; + + uint8_t zResverd0x0C[4]; /*pad 0x0C - 0F*/ + + /* 0x10*/ + struct { + uint32_t MG :32; /* [31:0] r/w */ + } CAN_RXMGMSK; + + /* 0x14*/ + struct { + uint32_t RX14M :32; /* [31:0] r/w */ + } CAN_RX14MASK; + + /* 0x18*/ + struct { + uint32_t RX15M :32; /* [31:0] r/w */ + } CAN_RX15MASK; + + /* 0x1c*/ + struct { + uint32_t TXERRCNT : 8; /* [7:0] r/w */ + uint32_t RXERRCNT : 8; /* [15:8] r/w */ + uint32_t TX_ERRCNT_FAST : 8; /* [23:16] r/w */ + uint32_t RX_ERRCNT_FAST : 8; /* [31:24] r/w */ + } CAN_ECR; + + /* 0x20*/ + struct { + uint32_t WAKINT : 1; /* [0] r/w1c */ + uint32_t ERRINT : 1; /* [1] r/w1c */ + uint32_t BOFFINT : 1; /* [2] r/w1c */ + uint32_t RX : 1; /* [3] read only */ + uint32_t FLTCONF : 2; /* [5:4] read only */ + uint32_t TX : 1; /* [6] read only */ + uint32_t IDLE : 1; /* [7] read only */ + uint32_t RXWRN : 1; /* [8] read only */ + uint32_t TXWRN : 1; /* [9] read only */ + uint32_t STFERR : 1; /* [10] read only */ + uint32_t FRAMERR : 1; /* [11] read only */ + uint32_t CRCERR : 1; /* [12] read only */ + uint32_t ACKERR : 1; /* [13] read only */ + uint32_t BIT0ERR : 1; /* [14] read only */ + uint32_t BIT1ERR : 1; /* [15] read only */ + uint32_t RWRNINT : 1; /* [16] read only */ + uint32_t TWRNINT : 1; /* [17] read only */ + uint32_t SYNCH : 1; /* [18] read only */ + uint32_t BUSOFFDONEINT : 1; /* [19] r/w1c */ + uint32_t ERRINT_FAST : 1; /* [20] r/w1c */ + uint32_t ERROVR : 1; /* [21] r/w1c */ + uint32_t RSVD_25_22 : 4; /* [25:22] reserve */ + uint32_t STFERR_FAST : 1; /* [26] read only */ + uint32_t FRAMERR_FAST : 1; /* [27] read only */ + uint32_t CRCERR_FAST : 1; /* [28] read only */ + uint32_t RSVD_29 : 1; /* [29] reserve */ + uint32_t BIT0ERR_FAST : 1; /* [30] read only */ + uint32_t BIT1ERR_FAST : 1; /* [31] read only */ + } CAN_ESR1; + + /* 0x24*/ + struct { + uint32_t BUF63TO32M :32; /* [31:0] r/w */ + } CAN_IMASK2; + + /* 0x28*/ + struct { + uint32_t BUF31TO0M :32; /* [31:0] r/w */ + } CAN_IMASK1; + + /* 0x2c*/ + struct { + uint32_t BUF63TO32I :32; /* [31:0] r/w */ + } CAN_IFLAG2; + + /* 0x30*/ + struct { + uint32_t BUF0I : 1; /* [0] r/w1c */ + uint32_t BUF4TO1I : 4; /* [4:1] r/w1c */ + uint32_t BUF5I : 1; /* [5] r/w1c */ + uint32_t BUF6I : 1; /* [6] r/w1c */ + uint32_t BUF7I : 1; /* [7] r/w1c */ + uint32_t BUF31TO8I :24; /* [31:8] r/w1c */ + } CAN_IFLAG1; + + /* 0x34*/ + struct { + uint32_t RSVD_10_0 :11; /* [10:0] reserve */ + uint32_t EDFLTDIS : 1; /* [11] r/w */ + uint32_t ISOCANFDEN : 1; /* [12] r/w */ + uint32_t RSVD_13 : 1; /* [13] reserve */ + uint32_t PREXCEN : 1; /* [14] r/w */ + uint32_t TIMER_SRC : 1; /* [15] r/w */ + uint32_t EACEN : 1; /* [16] r/w */ + uint32_t RRS : 1; /* [17] r/w */ + uint32_t MRP : 1; /* [18] r/w */ + uint32_t TASD : 5; /* [23:19] r/w */ + uint32_t RFFN : 4; /* [27:24] r/w */ + uint32_t WRMFRZ : 1; /* [28] r/w */ + uint32_t ECRWRE : 1; /* [29] r/w */ + uint32_t BOFFDONEMSK : 1; /* [30] r/w */ + uint32_t ERRMASK_FAST : 1; /* [31] r/w */ + } CAN_CTRL2; + + /* 0x38*/ + struct { + uint32_t RSVD_12_0 :13; /* [12:0] reserve */ + uint32_t IMB : 1; /* [13] read only */ + uint32_t VPS : 1; /* [14] read only */ + uint32_t RSVD_15 : 1; /* [15] reserve */ + uint32_t LPTM : 7; /* [22:16] read only */ + uint32_t RSVD_31_23 : 9; /* [31:23] */ + } CAN_ESR2; + + uint8_t zResverd0x03C[8]; /*pad 0x03C - 043*/ + + /* 0x44*/ + struct { + uint32_t TXCRC :15; /* [14:0] read only */ + uint32_t RSVD_15 : 1; /* [15] reserve */ + uint32_t MBCRC : 7; /* [22:16] read only */ + uint32_t RSVD_31_23 : 9; /* [31:23] reserve */ + } CAN_CRCR; + + /* 0x48*/ + struct { + uint32_t FGM :32; /* [31:0] r/w */ + } CAN_RXFGMASK; + + /* 0x4c*/ + struct { + uint32_t IDHIT : 9; /* [8:0] read only */ + uint32_t RSVD_31_9 :23; /* [31:9] reserve */ + } CAN_RXFIR; + + /* 0x50*/ + struct { + uint32_t EPSEG2 : 5; /* [4:0] r/w */ + uint32_t EPSEG1 : 5; /* [9:5] r/w */ + uint32_t EPROPSEG : 6; /* [15:10] r/w */ + uint32_t ERJW : 5; /* [20:16] r/w */ + uint32_t EPRESDIV :10; /* [30:21] r/w */ + uint32_t BTF : 1; /* [31] r/w */ + } CAN_CBT; + + uint8_t zResverd0x054[20]; /*pad 0x054 - 067*/ + + /* 0x68*/ + struct { + uint32_t BUF127TO96M :32; /* [31:0] r/w */ + } CAN_IMASK4; + + /* 0x6c*/ + struct { + uint32_t BUF95TO64M :32; /* [31:0] r/w */ + } CAN_IMASK3; + + /* 0x70*/ + struct { + uint32_t BUF127TO96I :32; /* [31:0] r/w1c */ + } CAN_IFLAG4; + + /* 0x74*/ + struct { + uint32_t BUF95TO64I :32; /* [31:0] r/w1c */ + } CAN_IFLAG3; + + uint8_t zResverd0x078[8]; /*pad 0x078 - 07F*/ + + /* 0x80 */ + struct { + struct { + uint32_t TIME_STAMP :16; /* [15:0] */ + uint32_t DLC : 4; /* [19:16] */ + uint32_t RTR : 1; /* [20] */ + uint32_t IDE : 1; /* [21] */ + uint32_t SRR : 1; /* [22] */ + uint32_t RSVD_23 : 1; /* [23] */ + uint32_t CODE : 4; /* [27:24] */ + uint32_t RSVD_28 : 1; /* [28] */ + uint32_t ESI : 1; /* [29] */ + uint32_t BRS : 1; /* [30] */ + uint32_t EDL : 1; /* [31] */ + } MB0; + + /* 0x84*/ + struct { + uint32_t ID_EXTEND :18; /* [17:0] */ + uint32_t ID_STANDARD :11; /* [28:18] */ + uint32_t PRIO : 3; /* [31:29] */ + } MB1; + + /* 0x88*/ + struct { + uint32_t DATA_BYTE :32; /* [31:0] */ + } MB2; + + /* 0x8c*/ + struct { + uint32_t DATA_BYTE :32; /* [31:0] */ + } MB3; + } CAN_MB[64]; + uint8_t zResverd0x0480[0x400]; /*pad 0x0480 - 087F*/ + + /* 0x880*/ + struct { + uint32_t MI : 32; /* [1] */ + } CAN_RXIMR[64]; + + uint8_t zResverd0x0A80[352]; /*pad 0x0A80 - 0ADF, 64*4 + 96*/ + + /* 0xAE0*/ + struct { + uint32_t RSVD_6_0 : 7; /* [6:0] reserve */ + uint32_t NCEFAFRZ : 1; /* [7] r/w */ + uint32_t ECCDIS : 1; /* [8] r/w */ + uint32_t RERRDIS : 1; /* [9] r/w */ + uint32_t RSVD_12_10 : 3; /* [12:10] reserve */ + uint32_t EXTERRIE : 1; /* [13] r/w */ + uint32_t FAERRIE : 1; /* [14] r/w */ + uint32_t HAERRI : 1; /* [15] r/w */ + uint32_t CEI_MSK : 1; /* [16] r/w */ + uint32_t RSVD_17 : 1; /* [17] reserve */ + uint32_t FANCEI_MSK : 1; /* [18] r/w */ + uint32_t HANCEI_MSK : 1; /* [19] r/w */ + uint32_t RSVD_30_20 :11; /* [30:20] reserve */ + uint32_t ECRWRDIS : 1; /* [31] r/w */ + } CAN_MECR; + + /* 0xAE4*/ + struct { + uint32_t INJADDR_L : 2; /* [1:0] r/w */ + uint32_t INJADDR_H :12; /* [13:2] r/w */ + uint32_t RSVD_31_14 :18; /* [31:14] reserve */ + } CAN_ERRIAR; + + /* 0xAE8*/ + struct { + uint32_t DFLIP :32; /* [31:0] r/w */ + } CAN_ERRIDPR; + + /* 0xAEC*/ + struct { + uint32_t PFLIP0 : 5; /* [4:0] r/w */ + uint32_t RSVD_7_5 : 3; /* [7:5] reserve */ + uint32_t PFLIP1 : 5; /* [12:8] r/w */ + uint32_t RSVD_15_13 : 3; /* [15:13] reserve */ + uint32_t PFLIP2 : 5; /* [20:16] r/w */ + uint32_t RSVD_23_21 : 3; /* [23:21] reserve */ + uint32_t PFLIP3 : 5; /* [28:24] r/w */ + uint32_t RSVD_31_29 : 3; /* [31:29] reserve */ + } CAN_ERRIPPR; + + /* 0xAF0*/ + struct { + uint32_t ERRADDR :14; /* [13:0] read only */ + uint32_t RSVD_15_14 : 2; /* [15:14] reserve */ + uint32_t SAID : 3; /* [18:16] read only */ + uint32_t RSVD_23_19 : 5; /* [23:19] reserve */ + uint32_t NCE : 1; /* [24] read only */ + uint32_t RSVD_31_25 : 7; /* [31:25] reserve */ + } CAN_RERRAR; + + /* 0xAF4*/ + struct { + uint32_t RDATA :32; /* [31:0] read only */ + } CAN_RERRDR; + + /* 0xAF8*/ + struct { + uint32_t SYND0 : 5; /* [4:0] read only */ + uint32_t RSVD_6_5 : 2; /* [6:5] reserve */ + uint32_t BE0 : 1; /* [7] read only */ + uint32_t SYND1 : 5; /* [12:8] read only */ + uint32_t RSVD_14_13 : 2; /* [14:13] read only */ + uint32_t BE1 : 1; /* [15] read only */ + uint32_t SYND2 : 5; /* [20:16] read only */ + uint32_t RSVD_22_21 : 2; /* [22:21] reserve */ + uint32_t BE2 : 1; /* [23] read only */ + uint32_t SYND3 : 5; /* [28:24] read only */ + uint32_t RSVD_30_29 : 2; /* [30:29] reserve */ + uint32_t BE3 : 1; /* [31] read only */ + } CAN_RERRSYNR; + + /* 0xAFC*/ + struct { + uint32_t CEIOF : 1; /* [0] r/w1c */ + uint32_t RSVD_1 : 1; /* [1] reserve */ + uint32_t FANCEIOF : 1; /* [2] r/w1c */ + uint32_t HANCEIOF : 1; /* [3] r/w1c */ + uint32_t RSVD_15_4 :12; /* [15:4] reserve */ + uint32_t CEIF : 1; /* [16] r/w1c */ + uint32_t RSVD_17 : 1; /* [17] reserve */ + uint32_t FANCEIF : 1; /* [18] r/w1c */ + uint32_t HANCEIF : 1; /* [19] r/w1c */ + uint32_t RSVD_31_20 :12; /* [31:20] reserve */ + } CAN_ERRSR; + + /* 0xB00*/ + struct { + uint32_t FCS : 2; /* [1:0] r/w */ + uint32_t IDFS : 2; /* [3:2] r/w */ + uint32_t PLFS : 2; /* [5:4] r/w */ + uint32_t RSVD_7_6 : 2; /* [7:6] reserve */ + uint32_t NMATCH : 8; /* [15:8 ] r/w */ + uint32_t WUMF_MSK : 1; /* [16] r/w */ + uint32_t WTOF_MSK : 1; /* [17] r/w */ + uint32_t RSVD_31_18 :14; /* [31:18] */ + } CAN_CTRL1_PN; + + /* 0xB04*/ + struct { + uint32_t MATCHTO :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] reserve */ + } CAN_CTRL2_PN; + + /* 0xB08*/ + struct { + uint32_t RSVD_7_0 : 8; /* [7:0] reserve */ + uint32_t MCOUNTER : 8; /* [15:8] read only */ + uint32_t WUMF : 1; /* [16] r/w1c */ + uint32_t WTOF : 1; /* [17] r/w1c */ + uint32_t RSVD_31_18 :14; /* [31:18] reserve */ + } CAN_WU_MTC; + + /* 0xB0C*/ + struct { + uint32_t FLT_ID1 :29; /* [28:0] r/w */ + uint32_t FLT_RTR : 1; /* [29] r/w */ + uint32_t FLT_IDE : 1; /* [30] r/w */ + uint32_t RSVD_31 : 1; /* [31] reserve */ + } CAN_FLT_ID1; + + /* 0xB10*/ + struct { + uint32_t FLT_DLC_HI : 4; /* [3:0] */ + uint32_t RSVD_15_4 :12; /* [15:4] reserve */ + uint32_t FLT_DLC_LO : 4; /* [19:16] r/w */ + uint32_t RSVD_31_20 :12; /* [31:20] reserve */ + } CAN_FLT_DLC; + + /* 0xB14*/ + struct { + uint32_t DATA_BYTE_3 : 8; /* [7:0] r/w */ + uint32_t DATA_BYTE_2 : 8; /* [15:8] r/w */ + uint32_t DATA_BYTE_1 : 8; /* [23:16] r/w */ + uint32_t DATA_BYTE_0 : 8; /* [31:24] r/w */ + } CAN_PL1_LO; + + /* 0xB18*/ + struct { + uint32_t DATA_BYTE_7 : 8; /* [7:0] r/w */ + uint32_t DATA_BYTE_6 : 8; /* [15:8] r/w */ + uint32_t DATA_BYTE_5 : 8; /* [23:16] r/w */ + uint32_t DATA_BYTE_4 : 8; /* [31:24] r/w */ + } CAN_PL1_HI; + + /* 0xB1C*/ + struct { + uint32_t FLT_ID2_IDMASK :29; /* [28:0] r/w */ + uint32_t RTR_MSK : 1; /* [29] r/w */ + uint32_t IDE_MSK : 1; /* [30] r/w */ + uint32_t RSVD_31 : 1; /* [31] reserve */ + } CAN_FLT_ID2_IDMASK; + + /* 0xB20*/ + struct { + uint32_t DATA_BYTE_3 : 8; /* [7:0] r/w */ + uint32_t DATA_BYTE_2 : 8; /* [15:8] r/w */ + uint32_t DATA_BYTE_1 : 8; /* [23:16] r/w */ + uint32_t DATA_BYTE_0 : 8; /* [31:24] r/w */ + } CAN_PL2_PLMASK_LO; + + /* 0xB24*/ + struct { + uint32_t DATA_BYTE_7 : 8; /* [7:0] r/w */ + uint32_t DATA_BYTE_6 : 8; /* [15:8] r/w */ + uint32_t DATA_BYTE_5 : 8; /* [23:16] r/w */ + uint32_t DATA_BYTE_4 : 8; /* [31:24] r/w */ + } CAN_PL2_PLMASK_HI; + + uint8_t zResverd0x0B28[24]; /*pad 0x0B28 - 0B3F*/ + + struct { + /* 0xB40*/ + struct { + uint32_t RSVD_15_0 :16; /* [15:0] reserve */ + uint32_t DLC : 4; /* [19:16] read only */ + uint32_t RTR : 1; /* [20] read only */ + uint32_t IDE : 1; /* [21] read only */ + uint32_t SRR : 1; /* [22] read only */ + uint32_t RSVD_31_23 : 9; /* [31:23] reserve */ + } CS; + + /* 0xB44*/ + struct { + uint32_t ID :29; /* [28:0] read only */ + uint32_t RSVD_31_29 : 3; /* [31:29] reserve */ + } ID; + + /* 0xB48*/ + struct { + uint32_t DATA_BYTE_3 : 8; /* [7:0] read only */ + uint32_t DATA_BYTE_2 : 8; /* [15:8] read only */ + uint32_t DATA_BYTE_1 : 8; /* [23:16] read only */ + uint32_t DATA_BYTE_0 : 8; /* [31:24] read only */ + } D03; + + /* 0xB4C*/ + struct { + uint32_t DATA_BYTE_7 : 8; /* [7:0] read only */ + uint32_t DATA_BYTE_6 : 8; /* [15:8] read only */ + uint32_t DATA_BYTE_5 : 8; /* [23:16] read only */ + uint32_t DATA_BYTE_4 : 8; /* [31:24] read only */ + } D47; + } CAN_WMB[4]; + + uint8_t zResverd0x0B80[0x80]; /*pad 0x0B80 - 0BFF*/ + + /* 0xC00*/ + struct { + uint32_t TDCVAL : 6; /* [5:0] read only */ + uint32_t RSVD_7_6 : 2; /* [7:6] reserve */ + uint32_t TDCOFF : 5; /* [12:8] r/w */ + uint32_t RSVD_13 : 1; /* [13] reserve */ + uint32_t TDCFAIL : 1; /* [14] r/w1c */ + uint32_t TDCEN : 1; /* [15] r/w */ + uint32_t MBDSR0 : 2; /* [17:16] r/w */ + uint32_t RSVD_18 : 1; /* [18] reserve */ + uint32_t MBDSR1 : 2; /* [20:19] r/w */ + uint32_t RSVD_21 : 1; /* [21] reserve */ + uint32_t MBDSR2 : 2; /* [23:22] r/w */ + uint32_t RSVD_24 : 1; /* [24] reserve */ + uint32_t MBDSR3 : 2; /* [26:25] r/w */ + uint32_t RSVD_30_27 : 4; /* [30:27] reserve */ + uint32_t FD_RATE : 1; /* [31] r/w */ + } CAN_FDCTRL; + + /* 0xC04*/ + struct { + uint32_t FPSEG2 : 3; /* [2:0] r/w */ + uint32_t RSVD_4_3 : 2; /* [4:3] reserve */ + uint32_t FPSEG1 : 3; /* [7:5] r/w */ + uint32_t RSVD_9_8 : 2; /* [9:8] reserve */ + uint32_t FPROPSEG : 5; /* [14:10] r/w */ + uint32_t RSVD_15 : 1; /* [15] reserve */ + uint32_t FRJW : 3; /* [18:16] r/w */ + uint32_t RSVD_19 : 1; /* [19] reserve */ + uint32_t FPRESDIV :10; /* [29:20] r/w */ + uint32_t RSVD_31_30 : 2; /* [31:30] reserve */ + } CAN_FDCBT; + + /* 0xC08*/ + struct { + uint32_t FD_TXCRC :21; /* [20:0] read only */ + uint32_t RSVD_23_21 : 3; /* [23:21] reserve */ + uint32_t FD_MBCRC : 7; /* [30:24] read only */ + uint32_t RSVD_31 : 1; /* [31] reserve */ + } CAN_FDCRC; + +}; /*can_reg*/ + +struct can_reg_w { + /* 0x00*/ + uint32_t CAN_MCR; + /* 0x04*/ + uint32_t CAN_CTRL1; + /* 0x08*/ + uint32_t CAN_TIMER; + uint8_t zResverd0x0C[4]; /*pad 0x0C - 0F*/ + + /* 0x10*/ + uint32_t CAN_RXMGMSK; + /* 0x14*/ + uint32_t CAN_RX14MASK; + /* 0x18*/ + uint32_t CAN_RX15MASK; + /* 0x1c*/ + uint32_t CAN_ECR; + /* 0x20*/ + uint32_t CAN_ESR1; + /* 0x24*/ + uint32_t CAN_IMASK2; + /* 0x28*/ + uint32_t CAN_IMASK1; + /* 0x2c*/ + uint32_t CAN_IFLAG2; + /* 0x30*/ + uint32_t CAN_IFLAG1; + /* 0x34*/ + uint32_t CAN_CTRL2; + /* 0x38*/ + uint32_t CAN_ESR2; + uint8_t zResverd0x03C[8]; /*pad 0x03C - 043*/ + + /* 0x44*/ + uint32_t CAN_CRCR; + /* 0x48*/ + uint32_t CAN_RXFGMASK; + /* 0x4c*/ + uint32_t CAN_RXFIR; + /* 0x50*/ + uint32_t CAN_CBT; + uint8_t zResverd0x054[20]; /*pad 0x054 - 067*/ + + /* 0x68*/ + uint32_t CAN_IMASK4; + /* 0x6c*/ + uint32_t CAN_IMASK3; + /* 0x70*/ + uint32_t CAN_IFLAG4; + /* 0x74*/ + uint32_t CAN_IFLAG3; + uint8_t zResverd0x078[8]; /*pad 0x078 - 07F*/ + + struct { + /* 0x80 */ + uint32_t MB0; + /* 0x84*/ + uint32_t MB1; + /* 0x88*/ + uint32_t MB2; + /* 0x8c*/ + uint32_t MB3; + } CAN_MB[64]; + uint8_t zResverd0x0480[0x400]; /*pad 0x0480 - 087F*/ + + /* 0x880*/ + uint32_t CAN_RXIMR[64]; + uint8_t zResverd0x0A80[352]; /*pad 0x0A80 - 0ADF, 64*4 + 96*/ + + /* 0xAE0*/ + uint32_t CAN_MECR; + /* 0xAE4*/ + uint32_t CAN_ERRIAR; + /* 0xAE8*/ + uint32_t CAN_ERRIDPR; + /* 0xAEC*/ + uint32_t CAN_ERRIPPR; + /* 0xAF0*/ + uint32_t CAN_RERRAR; + /* 0xAF4*/ + uint32_t CAN_RERRDR; + /* 0xAF8*/ + uint32_t CAN_RERRSYNR; + /* 0xAFC*/ + uint32_t CAN_ERRSR; + /* 0xB00*/ + uint32_t CAN_CTRL1_PN; + /* 0xB04*/ + uint32_t CAN_CTRL2_PN; + /* 0xB08*/ + uint32_t CAN_WU_MTC; + /* 0xB0C*/ + uint32_t CAN_FLT_ID1; + /* 0xB10*/ + uint32_t CAN_FLT_DLC; + /* 0xB14*/ + uint32_t CAN_PL1_LO; + /* 0xB18*/ + uint32_t CAN_PL1_HI; + /* 0xB1C*/ + uint32_t CAN_FLT_ID2_IDMASK; + /* 0xB20*/ + uint32_t CAN_PL2_PLMASK_LO; + /* 0xB24*/ + uint32_t CAN_PL2_PLMASK_HI; + + uint8_t zResverd0x0B28[24]; /*pad 0x0B28 - 0B3F*/ + struct { + /* 0xB40*/ + uint32_t CS; + /* 0xB44*/ + uint32_t ID; + /* 0xB48*/ + uint32_t D03; + /* 0xB4C*/ + uint32_t D47; + } CAN_WMB[4]; + + uint8_t zResverd0x0B80[0x80]; /*pad 0x0B80 - 0BFF*/ + + /* 0xC00*/ + uint32_t CAN_FDCTRL; + /* 0xC04*/ + uint32_t CAN_FDCBT; + /* 0xC08*/ + uint32_t CAN_FDCRC; +}; /*can_reg*/ + +typedef volatile struct can_reg can_reg_t; +typedef volatile struct can_reg_w can_reg_w_t; + +struct cmp_reg { + /* 0x0*/ + struct { + uint32_t VERID :32; /* [31:0] ro */ + } CMP_VERID; + + /* 0x4*/ + struct { + uint32_t DAC_RES : 4; /* [3:0] ro */ + uint32_t RSVD_31_4 :28; /* [31:4] */ + } CMP_PARAM; + + /* 0x8*/ + struct { + uint32_t CMP_SEL : 1; /* [0] r/w */ + uint32_t CMP_EN : 1; /* [1] r/w */ + uint32_t SOC_TRG_EN : 1; /* [2] r/w */ + uint32_t STOP_EN : 1; /* [3] r/w */ + uint32_t RSVD_31_4 :28; /* [31:4] */ + } CMP_CCR0; + + /* 0xC*/ + struct { + uint32_t WINDOW_EN : 1; /* [0] r/w */ + uint32_t SAMPLE_EN : 1; /* [1] r/w */ + uint32_t DMA_EN : 1; /* [2] r/w */ + uint32_t COUT_INV : 1; /* [3] r/w */ + uint32_t COUT_SEL : 1; /* [4] r/w */ + uint32_t COUT_PEN : 1; /* [5] r/w */ + uint32_t COUT_OWE : 1; /* [6] r/w */ + uint32_t COUT_OW : 1; /* [7] r/w */ + uint32_t RSVD_15_8 : 8; /* [15:8] */ + uint32_t FILT_CNT : 3; /* [18:16] r/w */ + uint32_t RSVD_23_19 : 5; /* [23:19] */ + uint32_t FILT_PER : 8; /* [31:24] r/w */ + } CMP_CCR1; + + /* 0x10*/ + struct { + uint32_t HS_HSTCTR : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] */ + uint32_t LS_HSTCTR : 2; /* [5:4] r/w */ + uint32_t RSVD_15_6 :10; /* [15:6] */ + uint32_t HS_PSEL : 4; /* [19:16] r/w */ + uint32_t HS_MSEL : 4; /* [23:20] r/w */ + uint32_t LS_PSEL : 4; /* [27:24] r/w */ + uint32_t LS_MSEL : 4; /* [31:28] r/w */ + } CMP_CCR2; + + /* 0x14*/ + struct { + uint32_t DAC_EN : 1; /* [0] r/w */ + uint32_t RSVD_1 : 1; /* [1] */ + uint32_t RSVD_7_2 : 6; /* [7:2] */ + uint32_t VREF_SEL : 1; /* [8] r/w */ + uint32_t RSVD_15_9 : 7; /* [15:9] */ + uint32_t DAC_SEL : 8; /* [23:16] r/w */ + uint32_t RSVD_31_24 : 8; /* [31:24] */ + } CMP_DCR; + + /* 0x18*/ + struct { + uint32_t CFR_IE : 1; /* [0] r/w */ + uint32_t CFF_IE : 1; /* [1] r/w */ + uint32_t RSVD_31_2 :30; /* [31:2] */ + } CMP_IER; + + /* 0x1C*/ + struct { + uint32_t CFR : 1; /* [0] r/w1c */ + uint32_t CFF : 1; /* [1] r/w1c */ + uint32_t RSVD_7_2 : 6; /* [7:2] */ + uint32_t COUT : 1; /* [8] ro */ + uint32_t RSVD_31_9 :23; /* [31:9] */ + } CMP_CSR; + +}; /*cmp_reg*/ + +struct cmp_reg_w { + /* 0x0*/ + uint32_t CMP_VERID; + /* 0x4*/ + uint32_t CMP_PARAM; + /* 0x8*/ + uint32_t CMP_CCR0; + /* 0xC*/ + uint32_t CMP_CCR1; + /* 0x10*/ + uint32_t CMP_CCR2; + /* 0x14*/ + uint32_t CMP_DCR; + /* 0x18*/ + uint32_t CMP_IER; + /* 0x1C*/ + uint32_t CMP_CSR; +}; /*cmp_reg*/ + +typedef volatile struct cmp_reg cmp_reg_t; +typedef volatile struct cmp_reg_w cmp_reg_w_t; + +struct crc_reg { + /* 0x0*/ + struct { + uint32_t FEATURE :16; /* [15:0] r */ + uint32_t MINOR : 8; /* [23:16] r */ + uint32_t MAJOR : 8; /* [31:24] r */ + } CRC_VERID; + + /* 0x4*/ + struct { + uint32_t RSVD_31_0 :32; /* [31:0] r */ + } CRC_PARAM; + + /* 0x8*/ + struct { + uint32_t BYTE0 : 8; /* [7:0] r/w */ + uint32_t BYTE1 : 8; /* [15:8] r/w */ + uint32_t BYTE2 : 8; /* [23:16] r/w */ + uint32_t BYTE3 : 8; /* [31:24] r/w */ + } CRC_DATA; + + /* 0xC*/ + struct { + uint32_t LPHW :16; /* [15:0] r/w */ + uint32_t HPHW :16; /* [31:16] r/w */ + } CRC_POLY; + + /* 0x10*/ + struct { + uint32_t MODE : 1; /* [0] r/w */ + uint32_t WS : 1; /* [1] r/w */ + uint32_t CR : 1; /* [2] r/w */ + uint32_t RSVD_3 : 1; /* [3] r */ + uint32_t RT : 2; /* [5:4] r/w */ + uint32_t WT : 2; /* [7:6] r/w */ + uint32_t RSVD_31_8 :24; /* [31:8] r */ + } CRC_CTRL; + +}; /*crc_reg*/ + +struct crc_reg_w { + /* 0x0*/ + uint32_t CRC_VERID; + /* 0x4*/ + uint32_t CRC_PARAM; + /* 0x8*/ + uint32_t CRC_DATA; + /* 0xC*/ + uint32_t CRC_POLY; + /* 0x10*/ + uint32_t CRC_CTRL; +}; /*crc_reg*/ + +typedef volatile struct crc_reg crc_reg_t; +typedef volatile struct crc_reg_w crc_reg_w_t; + +struct dma_chmux_reg { + /* 0x00*/ + struct { + uint32_t ENABLE : 1; /* [0] r/w */ + uint32_t SRC_MUX : 6; /* [6:1] r/w */ + uint32_t RSVD_31_7 :25; /* [31:7] reserve */ + } DMA_MUX_CH_CFG[16]; + +}; /*dma_chmux_reg*/ + +struct dma_chmux_reg_w { + /* 0x00*/ + uint32_t DMA_MUX_CH_CFG[16]; +}; /*dma_chmux_reg*/ + +typedef volatile struct dma_chmux_reg dma_chmux_reg_t; +typedef volatile struct dma_chmux_reg_w dma_chmux_reg_w_t; + +struct dma_reg { + /* 0x00*/ + struct { + uint32_t HALT : 1; /* [0] r/w */ + uint32_t HOEE : 1; /* [1] r/w */ + uint32_t RRCAE : 1; /* [2] r/w */ + uint32_t DBGE : 1; /* [3] r/w */ + uint32_t RSVD_5_4 : 2; /* [5:4] */ + uint32_t BUSY : 1; /* [6] r/o */ + uint32_t RSVD_31_7 :25; /* [31:7] */ + } DMA_CONF; + + /* 0x04*/ + struct { + uint32_t DMAE0 : 1; /* [0] r/w */ + uint32_t DMAE1 : 1; /* [1] r/w */ + uint32_t DMAE2 : 1; /* [2] r/w */ + uint32_t DMAE3 : 1; /* [3] r/w */ + uint32_t DMAE4 : 1; /* [4] r/w */ + uint32_t DMAE5 : 1; /* [5] r/w */ + uint32_t DMAE6 : 1; /* [6] r/w */ + uint32_t DMAE7 : 1; /* [7] r/w */ + uint32_t DMAE8 : 1; /* [8] r/w */ + uint32_t DMAE9 : 1; /* [9] r/w */ + uint32_t DMAE10 : 1; /* [10] r/w */ + uint32_t DMAE11 : 1; /* [11] r/w */ + uint32_t DMAE12 : 1; /* [12] r/w */ + uint32_t DMAE13 : 1; /* [13] r/w */ + uint32_t DMAE14 : 1; /* [14] r/w */ + uint32_t DMAE15 : 1; /* [15] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } DMA_DMAE; + + uint8_t zResverd0x08[4]; /*pad 0x08 - 0B*/ + + /* 0x0C*/ + struct { + uint32_t EIE0 : 1; /* [0] r/w */ + uint32_t EIE1 : 1; /* [1] r/w */ + uint32_t EIE2 : 1; /* [2] r/w */ + uint32_t EIE3 : 1; /* [3] r/w */ + uint32_t EIE4 : 1; /* [4] r/w */ + uint32_t EIE5 : 1; /* [5] r/w */ + uint32_t EIE6 : 1; /* [6] r/w */ + uint32_t EIE7 : 1; /* [7] r/w */ + uint32_t EIE8 : 1; /* [8] r/w */ + uint32_t EIE9 : 1; /* [9] r/w */ + uint32_t EIE10 : 1; /* [10] r/w */ + uint32_t EIE11 : 1; /* [11] r/w */ + uint32_t EIE12 : 1; /* [12] r/w */ + uint32_t EIE13 : 1; /* [13] r/w */ + uint32_t EIE14 : 1; /* [14] r/w */ + uint32_t EIE15 : 1; /* [15] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } DMA_EIE; + + uint8_t zResverd0x010[4]; /*pad 0x010 - 013*/ + + /* 0x14*/ + struct { + uint32_t CCDONE : 4; /* [3:0] w/o */ + uint32_t RSVD_5_4 : 2; /* [5:4] */ + uint32_t CACDONE : 1; /* [6] w/o */ + uint32_t WPEN0 : 1; /* [7] w/o */ + uint32_t SCSTART : 4; /* [11:8] w/o */ + uint32_t RSVD_13_12 : 2; /* [13:12] */ + uint32_t SACSTART : 1; /* [14] w/o */ + uint32_t WPEN1 : 1; /* [15] w/o */ + uint32_t CCES : 4; /* [19:16] w/o */ + uint32_t RSVD_21_20 : 2; /* [21:20] */ + uint32_t CACES : 1; /* [22] w/o */ + uint32_t WPEN2 : 1; /* [23] w/o */ + uint32_t CCIS : 4; /* [27:24] w/o */ + uint32_t RSVD_29_28 : 2; /* [29:28] */ + uint32_t CACIS : 1; /* [30] w/o */ + uint32_t WPEN3 : 1; /* [31] w/o */ + } DMA_GCC; + + /* 0x18*/ + struct { + uint32_t DBEF : 1; /* [0] r/o */ + uint32_t SBEF : 1; /* [1] r/o */ + uint32_t RSVD_2 : 1; /* [2] */ + uint32_t NUMEF : 1; /* [3] r/o */ + uint32_t DOEF : 1; /* [4] r/o */ + uint32_t DAEF : 1; /* [5] r/o */ + uint32_t SOEF : 1; /* [6] r/o */ + uint32_t SAEF : 1; /* [7] r/o */ + uint32_t CHEF : 4; /* [11:8] r/o */ + uint32_t RSVD_12 : 1; /* [12] */ + uint32_t PRIEF : 1; /* [13] r/o */ + uint32_t RSVD_14 : 1; /* [14] */ + uint32_t ERRF : 1; /* [15] r/o */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } DMA_ES; + + /* 0x1C*/ + struct { + uint32_t ERR0 : 1; /* [0] r/o */ + uint32_t ERR1 : 1; /* [1] r/o */ + uint32_t ERR2 : 1; /* [2] r/o */ + uint32_t ERR3 : 1; /* [3] r/o */ + uint32_t ERR4 : 1; /* [4] r/o */ + uint32_t ERR5 : 1; /* [5] r/o */ + uint32_t ERR6 : 1; /* [6] r/o */ + uint32_t ERR7 : 1; /* [7] r/o */ + uint32_t ERR8 : 1; /* [8] r/o */ + uint32_t ERR9 : 1; /* [9] r/o */ + uint32_t ERR10 : 1; /* [10] r/o */ + uint32_t ERR11 : 1; /* [11] r/o */ + uint32_t ERR12 : 1; /* [12] r/o */ + uint32_t ERR13 : 1; /* [13] r/o */ + uint32_t ERR14 : 1; /* [14] r/o */ + uint32_t ERR15 : 1; /* [15] r/o */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } DMA_CES; + + /* 0x20*/ + struct { + uint32_t INT0 : 1; /* [0] r/o */ + uint32_t INT1 : 1; /* [1] r/o */ + uint32_t INT2 : 1; /* [2] r/o */ + uint32_t INT3 : 1; /* [3] r/o */ + uint32_t INT4 : 1; /* [4] r/o */ + uint32_t INT5 : 1; /* [5] r/o */ + uint32_t INT6 : 1; /* [6] r/o */ + uint32_t INT7 : 1; /* [7] r/o */ + uint32_t INT8 : 1; /* [8] r/o */ + uint32_t INT9 : 1; /* [9] r/o */ + uint32_t INT10 : 1; /* [10] r/o */ + uint32_t INT11 : 1; /* [11] r/o */ + uint32_t INT12 : 1; /* [12] r/o */ + uint32_t INT13 : 1; /* [13] r/o */ + uint32_t INT14 : 1; /* [14] r/o */ + uint32_t INT15 : 1; /* [15] r/o */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } DMA_CIS; + + /* 0x24*/ + struct { + uint32_t HRS0 : 1; /* [0] r/o */ + uint32_t HRS1 : 1; /* [1] r/o */ + uint32_t HRS2 : 1; /* [2] r/o */ + uint32_t HRS3 : 1; /* [3] r/o */ + uint32_t HRS4 : 1; /* [4] r/o */ + uint32_t HRS5 : 1; /* [5] r/o */ + uint32_t HRS6 : 1; /* [6] r/o */ + uint32_t HRS7 : 1; /* [7] r/o */ + uint32_t HRS8 : 1; /* [8] r/o */ + uint32_t HRS9 : 1; /* [9] r/o */ + uint32_t HRS10 : 1; /* [10] r/o */ + uint32_t HRS11 : 1; /* [11] r/o */ + uint32_t HRS12 : 1; /* [12] r/o */ + uint32_t HRS13 : 1; /* [13] r/o */ + uint32_t HRS14 : 1; /* [14] r/o */ + uint32_t HRS15 : 1; /* [15] r/o */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } DMA_CHRS; + + /* 0x28*/ + struct { + uint32_t CPRI3 : 4; /* [3:0] r/w */ + uint32_t RSVD_5_4 : 2; /* [5:4] */ + uint32_t CPDIS3 : 1; /* [6] r/w */ + uint32_t CSE3 : 1; /* [7] r/w */ + uint32_t CPRI2 : 4; /* [11:8] r/w */ + uint32_t RSVD_13_12 : 2; /* [13:12] */ + uint32_t CPDIS2 : 1; /* [14] r/w */ + uint32_t CSE2 : 1; /* [15] r/w */ + uint32_t CPRI1 : 4; /* [19:16] r/w */ + uint32_t RSVD_21_20 : 2; /* [21:20] */ + uint32_t CPDIS1 : 1; /* [22] r/w */ + uint32_t CSE1 : 1; /* [23] r/w */ + uint32_t CPRI0 : 4; /* [27:24] r/w */ + uint32_t RSVD_29_28 : 2; /* [29:28] */ + uint32_t CPDIS0 : 1; /* [30] r/w */ + uint32_t CSE0 : 1; /* [31] r/w */ + } DMA_CPRI0; + + /* 0x2C*/ + struct { + uint32_t CPRI7 : 4; /* [3:0] r/w */ + uint32_t RSVD_5_4 : 2; /* [5:4] */ + uint32_t CPDIS7 : 1; /* [6] r/w */ + uint32_t CSE7 : 1; /* [7] r/w */ + uint32_t CPRI6 : 4; /* [11:8] r/w */ + uint32_t RSVD_13_12 : 2; /* [13:12] */ + uint32_t CPDIS6 : 1; /* [14] r/w */ + uint32_t CSE6 : 1; /* [15] r/w */ + uint32_t CPRI5 : 4; /* [19:16] r/w */ + uint32_t RSVD_21_20 : 2; /* [21:20] */ + uint32_t CPDIS5 : 1; /* [22] r/w */ + uint32_t CSE5 : 1; /* [23] r/w */ + uint32_t CPRI4 : 4; /* [27:24] r/w */ + uint32_t RSVD_29_28 : 2; /* [29:28] */ + uint32_t CPDIS4 : 1; /* [30] r/w */ + uint32_t CSE4 : 1; /* [31] r/w */ + } DMA_CPRI1; + + /* 0x30*/ + struct { + uint32_t CPRI11 : 4; /* [3:0] r/w */ + uint32_t RSVD_5_4 : 2; /* [5:4] */ + uint32_t CPDIS11 : 1; /* [6] r/w */ + uint32_t CSE11 : 1; /* [7] r/w */ + uint32_t CPRI10 : 4; /* [11:8] r/w */ + uint32_t RSVD_13_12 : 2; /* [13:12] */ + uint32_t CPDIS10 : 1; /* [14] r/w */ + uint32_t CSE10 : 1; /* [15] r/w */ + uint32_t CPRI9 : 4; /* [19:16] r/w */ + uint32_t RSVD_21_20 : 2; /* [21:20] */ + uint32_t CPDIS9 : 1; /* [22] r/w */ + uint32_t CSE9 : 1; /* [23] r/w */ + uint32_t CPRI8 : 4; /* [27:24] r/w */ + uint32_t RSVD_29_28 : 2; /* [29:28] */ + uint32_t CPDIS8 : 1; /* [30] r/w */ + uint32_t CSE8 : 1; /* [31] r/w */ + } DMA_CPRI2; + + /* 0x34*/ + struct { + uint32_t CPRI15 : 4; /* [3:0] r/w */ + uint32_t RSVD_5_4 : 2; /* [5:4] */ + uint32_t CPDIS15 : 1; /* [6] r/w */ + uint32_t CSE15 : 1; /* [7] r/w */ + uint32_t CPRI14 : 4; /* [11:8] r/w */ + uint32_t RSVD_13_12 : 2; /* [13:12] */ + uint32_t CPDIS14 : 1; /* [14] r/w */ + uint32_t CSE14 : 1; /* [15] r/w */ + uint32_t CPRI13 : 4; /* [19:16] r/w */ + uint32_t RSVD_21_20 : 2; /* [21:20] */ + uint32_t CPDIS13 : 1; /* [22] r/w */ + uint32_t CSE13 : 1; /* [23] r/w */ + uint32_t CPRI12 : 4; /* [27:24] r/w */ + uint32_t RSVD_29_28 : 2; /* [29:28] */ + uint32_t CPDIS12 : 1; /* [30] r/w */ + uint32_t CSE12 : 1; /* [31] r/w */ + } DMA_CPRI3; + + uint8_t zResverd0x038[456]; /*pad 0x038 - 01FF*/ + + struct { + /* 0x200*/ + struct { + uint32_t SADDR : 32; /* [31:0] r/w */ + } DMA_SADDR; + + /* 0x204*/ + struct { + uint32_t DADDR : 32; /* [31:0] r/w */ + } DMA_DADDR; + + /* 0x208*/ + struct { + int32_t SAOFF : 16; /* [15:0] r/w */ + int32_t DAOFF : 16; /* [31:16] r/w */ + } DMA_AOFF; + + /* 0x20C*/ + struct { + int32_t MLSAOFF : 16; /* [15:0] r/w */ + int32_t MLDAOFF : 16; /* [31:16] r/w */ + } DMA_MLAOFF; + + /* 0x210*/ + struct { + uint32_t NUM : 32; /* [31:0] r/w */ + } DMA_NUM; + + /* 0x214*/ + struct { + uint32_t MLITER : 15; /* [14:0] r/w */ + uint32_t RSVD_15: 1 ; /* [15] */ + uint32_t MLSTA : 15; /* [30:16] r/o */ + uint32_t RSVD_31: 1 ; /* [31] */ + } DMA_ITER; + + /* 0x218*/ + struct { + uint32_t START : 1; /* [0] r/w */ + uint32_t INTE : 1; /* [1] r/w */ + uint32_t RSVD_2 : 1; /* [2] */ + uint32_t REQDIS : 1; /* [3] r/w */ + uint32_t RSVD_5_4 : 2; /* [5:4] */ + uint32_t BUSY : 1; /* [6] r/o */ + uint32_t DONE : 1; /* [7] r/w */ + uint32_t RSVD_15_8 : 8; /* [15:8] */ + uint32_t DSIZE : 2; /* [17:16] r/w */ + uint32_t RSVD_23_18 : 6; /* [23:18] */ + uint32_t SSIZE : 2; /* [25:24] r/w */ + uint32_t RSVD_31_26 : 6; /* [31:26] */ + } DMA_CS; + + uint8_t zResverd[4]; /*pad 4 bytes*/ + }DMA_CH_CONFIG[16]; +}; /*dma_reg*/ + +struct dma_reg_w { + /* 0x00*/ + uint32_t DMA_CONF; + /* 0x04*/ + uint32_t DMA_DMAE; + uint8_t zResverd0x08[4]; /*pad 0x08 - 0B*/ + + /* 0x0C*/ + uint32_t DMA_EIE; + uint8_t zResverd0x010[4]; /*pad 0x010 - 013*/ + + /* 0x14*/ + uint32_t DMA_GCC; + /* 0x18*/ + uint32_t DMA_ES; + /* 0x1C*/ + uint32_t DMA_CES; + /* 0x20*/ + uint32_t DMA_CIS; + /* 0x24*/ + uint32_t DMA_CHRS; + /* 0x28*/ + uint32_t DMA_CPRI0; + /* 0x2C*/ + uint32_t DMA_CPRI1; + /* 0x30*/ + uint32_t DMA_CPRI2; + /* 0x34*/ + uint32_t DMA_CPRI3; + uint8_t zResverd0x038[456]; /*pad 0x038 - 01FF*/ + + struct { + /* 0x200*/ + uint32_t DMA_SADDR; + /* 0x204*/ + uint32_t DMA_DADDR; + /* 0x208*/ + uint32_t DMA_AOFF; + /* 0x20C*/ + uint32_t DMA_MLAOFF; + /* 0x210*/ + uint32_t DMA_NUM; + /* 0x214*/ + uint32_t DMA_ITER; + /* 0x218*/ + uint32_t DMA_CS; + + uint8_t zResverd[4]; /*pad 4 bytes*/ + } DMA_CH_CONFIG[16]; +}; /*dma_reg*/ + +typedef volatile struct dma_reg dma_reg_t; +typedef volatile struct dma_reg_w dma_reg_w_t; + +struct ewdt_reg { + /* 0x0*/ + struct { + uint32_t MINOR : 4; /* [3:0] ro */ + uint32_t MAJOR : 4; /* [7:4] ro */ + uint32_t RSVD_31_8 :24; /* [31:8] ro */ + } EWDT_VERID; + + /* 0x4*/ + struct { + uint32_t RSVD_31_0 :32; /* [31:0] ro */ + } EWDT_PARAM; + + /* 0x8*/ + struct { + uint32_t EWDTE : 1; /* [0] r/w */ + uint32_t DEBUGE : 1; /* [1] r/w */ + uint32_t WAITE : 1; /* [2] r/w */ + uint32_t RSVD_3 : 1; /* [3] ro */ + uint32_t INTE : 1; /* [4] r/w */ + uint32_t INPE : 1; /* [5] r/w */ + uint32_t INPP : 1; /* [6] r/w */ + uint32_t RSVD_23_7 :17; /* [23:7] */ + uint32_t INTF : 1; /* [24] w1c */ + uint32_t RSVD_31_25 : 7; /* [31:25] ro */ + } EWDT_CS; + + /* 0xC*/ + struct { + uint32_t COMPH :32; /* [31:0] r/w */ + } EWDT_COMPH; + + /* 0x10*/ + struct { + uint32_t COMPL :32; /* [31:0] r/w */ + } EWDT_COMPL; + + /* 0x14*/ + struct { + uint32_t CNT :32; /* [31:0] r/w */ + } EWDT_CNT; + +}; /*ewdt_reg*/ + +struct ewdt_reg_w { + /* 0x0*/ + uint32_t EWDT_VERID; + /* 0x4*/ + uint32_t EWDT_PARAM; + /* 0x8*/ + uint32_t EWDT_CS; + /* 0xC*/ + uint32_t EWDT_COMPH; + /* 0x10*/ + uint32_t EWDT_COMPL; + /* 0x14*/ + uint32_t EWDT_CNT; +}; /*ewdt_reg*/ + +typedef volatile struct ewdt_reg ewdt_reg_t; +typedef volatile struct ewdt_reg_w ewdt_reg_w_t; + +struct flash_reg { + /* 0x0*/ + struct { + uint32_t FAIL : 1; /* [0] r */ + uint32_t RSVD_1 : 1; /* [1] r */ + uint32_t CMDABT : 1; /* [2] r/w1c */ + uint32_t RSVD_4_3 : 2; /* [4:3] r */ + uint32_t ACCERR : 1; /* [5] r/w1c */ + uint32_t PREABT : 1; /* [6] r/w1c */ + uint32_t CCIF : 1; /* [7] r/w1c */ + uint32_t RSVD_10_8 : 3; /* [10:8] r */ + uint32_t CMDWRF : 1; /* [11] r */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t DFDIF : 1; /* [16] r/w1c */ + uint32_t RSVD_29_17 :13; /* [29:17] r */ + uint32_t DBG_ERSALL_DIS : 1; /* [30] r */ + uint32_t FSEC : 1; /* [31] r */ + } FLASH_FSTAT; + + /* 0x4*/ + struct { + uint32_t RSVD_6_0 : 7; /* [6:0] r */ + uint32_t CCIE : 1; /* [7] r/w */ + uint32_t DBG_ERS_FLG : 1; /* [8] r */ + uint32_t RSVD_15_9 : 7; /* [15:9] r */ + uint32_t DFDIE : 1; /* [16] r/w */ + uint32_t RSVD_31_17 :15; /* [31:17] r */ + } FLASH_FCNFG; + + /* 0x8*/ + struct { + uint32_t RWSC : 4; /* [3:0] r/w */ + uint32_t RSVD_7_4 : 4; /* [7:4] r */ + uint32_t LSMODE : 1; /* [8] r/w */ + uint32_t RSVD_15_9 : 7; /* [15:9] r */ + uint32_t FECCF : 1; /* [16] r/w */ + uint32_t RSVD_23_17 : 7; /* [23:17] r */ + uint32_t ABTREQ : 1; /* [24] r */ + uint32_t RSVD_31_25 : 7; /* [31:25] r */ + } FLASH_FCTRL; + + uint8_t zResverd0x0C[4]; /*pad 0x0C - 0F*/ + + /* 0x10*/ + struct { + uint32_t CMDCODE : 8; /* [7:0] r/w */ + uint32_t RSVD_31_8 :24; /* [31:8] r */ + } FLASH_FCMD; + + /* 0x14*/ + struct { + uint32_t CMDOPT : 8; /* [7:0] r/w */ + uint32_t RSVD_31_8 :24; /* [31:8] r */ + } FLASH_FCMD_OPT; + + /* 0x18*/ + struct { + uint32_t CMDADDR :32; /* [31:0] r/w */ + } FLASH_FADDR; + + /* 0x1C*/ + struct { + uint32_t CMDADDRE :32; /* [31:0] r/w */ + } FLASH_FADDR_END; + + /* 0x20*/ + struct { + uint32_t CMDDATA0 :32; /* [31:0] r/w */ + } FLASH_FDATA0; + + /* 0x24*/ + struct { + uint32_t CMDDATA1 :32; /* [31:0] r/w */ + } FLASH_FDATA1; + + /* 0x28*/ + struct { + uint32_t CMDDATA2 :32; /* [31:0] r/w */ + } FLASH_FDATA2; + + /* 0x2C*/ + struct { + uint32_t CMDDATA3 :32; /* [31:0] r/w */ + } FLASH_FDATA3; + +}; /*flash_reg*/ + +struct flash_reg_w { + /* 0x0*/ + uint32_t FLASH_FSTAT; + /* 0x4*/ + uint32_t FLASH_FCNFG; + /* 0x8*/ + uint32_t FLASH_FCTRL; + uint8_t zResverd0x0C[4]; /*pad 0x0C - 0F*/ + + /* 0x10*/ + uint32_t FLASH_FCMD; + /* 0x14*/ + uint32_t FLASH_FCMD_OPT; + /* 0x18*/ + uint32_t FLASH_FADDR; + /* 0x1C*/ + uint32_t FLASH_FADDR_END; + /* 0x20*/ + uint32_t FLASH_FDATA0; + /* 0x24*/ + uint32_t FLASH_FDATA1; + /* 0x28*/ + uint32_t FLASH_FDATA2; + /* 0x2C*/ + uint32_t FLASH_FDATA3; +}; /*flash_reg*/ + +typedef volatile struct flash_reg flash_reg_t; +typedef volatile struct flash_reg_w flash_reg_w_t; + +struct gpio_reg { + /* 0x0*/ + struct { + uint32_t PDO :32; /* [31:0] r/w */ + } GPIOx_PDOR; + + /* 0x4*/ + struct { + uint32_t PSO :32; /* [31:0] wo */ + } GPIOx_PSOR; + + /* 0x8*/ + struct { + uint32_t PCO :32; /* [31:0] wo */ + } GPIOx_PCOR; + + /* 0xC*/ + struct { + uint32_t PTO :32; /* [31:0] wo */ + } GPIOx_PTOR; + + /* 0x10*/ + struct { + uint32_t PDI :32; /* [31:0] ro */ + } GPIOx_PDIR; + + /* 0x14*/ + struct { + uint32_t PDD :32; /* [31:0] r/w */ + } GPIOx_PDDR; + + /* 0x18*/ + struct { + uint32_t RSVD_31_0 :32; /* [31:0] ro */ + } GPIOx_PIDR; + + uint8_t zResverd[36]; /*pad 0x01C - 03F*/ +}; /*gpio_reg*/ + +struct gpio_reg_w { + /* 0x0 */ + uint32_t GPIOx_PDOR; + /* 0x4 */ + uint32_t GPIOx_PSOR; + /* 0x8 */ + uint32_t GPIOx_PCOR; + /* 0xC */ + uint32_t GPIOx_PTOR; + /* 0x10 */ + uint32_t GPIOx_PDIR; + /* 0x14 */ + uint32_t GPIOx_PDDR; + /* 0x18 */ + uint32_t GPIOx_PIDR; + /* 0x1C */ + uint8_t zResverd[36]; +}; /* gpio_reg */ + +typedef volatile struct gpio_reg gpio_reg_t; +typedef volatile struct gpio_reg_w gpio_reg_w_t; + +struct hwdiv_reg { + /* 0x0*/ + struct { + uint32_t VERSION :32; /* [31:0] ro */ + } HWDIV_VERSION; + + /* 0x4*/ + struct { + uint32_t PARAM :32; /* [31:0] ro */ + } HWDIV_PARAM; + + /* 0x8*/ + struct { + uint32_t DIVIDEND :32; /* [31:0] r/w */ + } HWDIV_DEND; + + /* 0xC*/ + struct { + uint32_t DIVISOR :32; /* [31:0] r/w */ + } HWDIV_DSOR; + + /* 0x10*/ + struct { + uint32_t DFS : 1; /* [0] r/w */ + uint32_t USGN : 1; /* [1] r/w */ + uint32_t DZE : 1; /* [2] r/w */ + uint32_t DZ : 1; /* [3] ro */ + uint32_t SQRT : 1; /* [4] ro */ + uint32_t DIV : 1; /* [5] ro */ + uint32_t BUSY : 1; /* [6] ro */ + uint32_t RSVD_31_7 :25; /* [31:7] ro */ + } HWDIV_CSR; + + /* 0x14*/ + struct { + uint32_t STRT : 1; /* [0] w */ + uint32_t RSVD_31_1 :31; /* [31:1] ro */ + } HWDIV_STRT; + + /* 0x18*/ + struct { + uint32_t RESULT :32; /* [31:0] ro */ + } HWDIV_RES; + + /* 0x1C*/ + struct { + uint32_t REMAINDER :32; /* [31:0] ro */ + } HWDIV_REM; + + /* 0x20*/ + struct { + uint32_t RADICAND :32; /* [31:0] r/w */ + } HWDIV_RCND; + +}; /*hwdiv_reg*/ + +struct hwdiv_reg_w { + /* 0x0*/ + uint32_t HWDIV_VERSION; + /* 0x4*/ + uint32_t HWDIV_PARAM; + /* 0x8*/ + uint32_t HWDIV_DEND; + /* 0xC*/ + uint32_t HWDIV_DSOR; + /* 0x10*/ + uint32_t HWDIV_CSR; + /* 0x14*/ + uint32_t HWDIV_STRT; + /* 0x18*/ + uint32_t HWDIV_RES; + /* 0x1C*/ + uint32_t HWDIV_REM; + /* 0x20*/ + uint32_t HWDIV_RCND; +}; /*hwdiv_reg*/ + +typedef volatile struct hwdiv_reg hwdiv_reg_t; +typedef volatile struct hwdiv_reg_w hwdiv_reg_w_t; + +struct i2c_reg { + /* 0x00*/ + struct { + uint32_t RSVD_31_0 :32; /* [31:0] ro */ + } I2C_VERID; + + /* 0x04*/ + struct { + uint32_t I2C_SUPPORT_SPEED : 2; /* [1:0] ro */ + uint32_t DMA_SUPPORT : 1; /* [2] ro */ + uint32_t TXFIFO_DEPTH : 4; /* [6:3] ro */ + uint32_t RXFIFO_DEPTH : 4; /* [10:7] ro */ + uint32_t RSVD_31_11 :21; /* [31:11] ro */ + } I2C_PARAMETER; + + /* 0x08*/ + struct { + uint32_t MODULE_EN : 1; /* [0] r/w */ + uint32_t SLAVE_ACK_GENCALL : 1; /* [1] r/w */ + uint32_t SLAVE_NACK : 1; /* [2] r/w */ + uint32_t SDA_RECOVER_EN : 1; /* [3] r/w */ + uint32_t MASTER_ABORT : 1; /* [4] r/w */ + uint32_t MASTER_BUS_RECOVER_EN : 1; /* [5] r/w */ + uint32_t MASTER_BLK_TXFIFO : 1; /* [6] r/w */ + uint32_t H_MCODE : 3; /* [9:7] r/w */ + uint32_t RSVD_31_10 :22; /* [31:10] ro */ + } I2C_CONFIG0; + + /* 0x0c*/ + struct { + uint32_t SLAVE_MODE_DIS : 1; /* [0] r/w */ + uint32_t MASTER_MODE_EN : 1; /* [1] r/w */ + uint32_t MASTER_RESTART_EN : 1; /* [2] r/w */ + uint32_t SLAVE_STOP_DET_EN : 1; /* [3] r/w */ + uint32_t MASTER_STOP_DET_EN : 1; /* [4] r/w */ + uint32_t TXFIFO_EMPTY_EN : 1; /* [5] r/w */ + uint32_t SPEED_SEL : 2; /* [7:6] r/w */ + uint32_t HOLD_EN_RXFIFO_FULL : 1; /* [8] r/w */ + uint32_t SLAVE_10BIT_ADDR_SEL : 1; /* [9] r/w */ + uint32_t MASTER_10BIT_ADDR_SEL : 1; /* [10] r/w */ + uint32_t RSVD_31_11 :21; /* [31:11] ro */ + } I2C_CONFIG1; + + /* 0x10*/ + struct { + uint32_t SDA_SETUP_TIMING : 8; /* [7:0] r/w */ + uint32_t RSVD_31_8 :24; /* [31:8] ro */ + } I2C_SDA_SETUP_TIMING; + + /* 0x14*/ + struct { + uint32_t SDA_TX_HOLD_TIMING :16; /* [15:0] r/w */ + uint32_t SDA_RX_HOLD_TIMING : 8; /* [23:16] r/w */ + uint32_t RSVD_31_24 : 8; /* [31:24] ro */ + } I2C_SDA_HOLD_TIMING; + + /* 0x18*/ + struct { + uint32_t RXFIFO_DMA_EN : 1; /* [0] r/w */ + uint32_t TXFIFO_DMA_EN : 1; /* [1] r/w */ + uint32_t DMA_TXFIFO_WATERMARK : 2; /* [3:2] r/w */ + uint32_t DMA_RXFIFO_WATERMARK : 2; /* [5:4] r/w */ + uint32_t RSVD_31_6 :26; /* [31:6] ro */ + } I2C_DMA_CTRL; + + /* 0x1c*/ + struct { + uint32_t I2C_CALL_IE : 1; /* [0] r/w */ + uint32_t I2C_TX_OVF_IE : 1; /* [1] r/w */ + uint32_t I2C_ERROR_ABORT_IE : 1; /* [2] r/w */ + uint32_t I2C_ACTIVITY_DET_IE : 1; /* [3] r/w */ + uint32_t I2C_STOP_DET_IE : 1; /* [4] r/w */ + uint32_t I2C_START_DET_IE : 1; /* [5] r/w */ + uint32_t RSVD_21_6 :16; /* [21:6] ro */ + uint32_t SLAVE_RD_REQ_IE : 1; /* [22] r/w */ + uint32_t RX_DONE_IE : 1; /* [23] r/w */ + uint32_t RX_UNDER_IE : 1; /* [24] r/w */ + uint32_t RX_OVF_IE : 1; /* [25] r/w */ + uint32_t RESTART_DET_IE : 1; /* [26] r/w */ + uint32_t SCL_STUCK_AT_LOW_IE : 1; /* [27] r/w */ + uint32_t RSVD_29_28 : 2; /* [29:28] ro */ + uint32_t RX_FULL_IE : 1; /* [30] r/w */ + uint32_t TX_EMPTY_IE : 1; /* [31] r/w */ + } I2C_INT_ENABLE; + + /* 0x20*/ + struct { + uint32_t DATA : 8; /* [7:0] r/w */ + uint32_t CMD_MASTER_DIRECTION : 1; /* [8] wo */ + uint32_t CMD_STOP : 1; /* [9] wo */ + uint32_t CMD_RESTART : 1; /* [10] wo */ + uint32_t RSVD_31_11 :21; /* [31:11] ro */ + } I2C_COMMAND_DATA; + + /* 0x24*/ + struct { + uint32_t DEST_ADDR :10; /* [9:0] r/w */ + uint32_t MASTER_CMD_SEL : 2; /* [11:10] r/w */ + uint32_t RSVD_31_12 :20; /* [31:12] ro */ + } I2C_DEST_ADDR; + + /* 0x28*/ + struct { + uint32_t SLV_ADDR :10; /* [9:0] r/w */ + uint32_t RSVD_31_10 :22; /* [31:10] ro */ + } I2C_SLAVE_ADDR; + + /* 0x2c*/ + struct { + uint32_t STD_SCL_HCNT :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] ro */ + } I2C_STD_SCL_HCNT; + + /* 0x30*/ + struct { + uint32_t STD_SCL_LCNT :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] ro */ + } I2C_STD_SCL_LCNT; + + /* 0x34*/ + struct { + uint32_t FST_SCL_HCNT :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] reserve */ + } I2C_FST_SCL_HCNT; + + /* 0x38*/ + struct { + uint32_t FST_SCL_LCNT :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] ro */ + } I2C_FST_SCL_LCNT; + + /* 0x3c*/ + struct { + uint32_t HS_SCL_HCNT :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] ro */ + } I2C_HS_SCL_HCNT; + + /* 0x40*/ + struct { + uint32_t HS_SCL_LCNT :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] ro */ + } I2C_HS_SCL_LCNT; + + /* 0x44*/ + struct { + uint32_t RXFIFO_WATER_MARK : 2; /* [1:0] r/w */ + uint32_t RSVD_31_2 :30; /* [31:2] ro */ + } I2C_RXFIFO_WATER_MARK; + + /* 0x48*/ + struct { + uint32_t TXFIFO_WATER_MARK : 2; /* [1:0] r/w */ + uint32_t RSVD_31_2 :30; /* [31:2] ro */ + } I2C_TXFIFO_WATER_MARK; + + /* 0x4c*/ + struct { + uint32_t TX_FIFO_CNT : 3; /* [2:0] ro */ + uint32_t RSVD_31_3 :29; /* [31:3] ro */ + } I2C_TX_FIFO_CNT; + + /* 0x50*/ + struct { + uint32_t RX_FIFO_CNT : 3; /* [2:0] ro */ + uint32_t RSVD_31_3 :29; /* [31:3] ro */ + } I2C_RX_FIFO_CNT; + + /* 0x54*/ + struct { + uint32_t FSTD_SPKLEN : 8; /* [7:0] r/w */ + uint32_t RSVD_31_8 :24; /* [31:8] ro */ + } I2C_FSTD_SPKCNT; + + /* 0x58*/ + struct { + uint32_t HS_SPKLEN : 8; /* [7:0] r/w */ + uint32_t RSVD_31_8 :24; /* [31:8] ro */ + } I2C_HS_SPKCNT; + + /* 0x5c*/ + struct { + uint32_t GENERAL_CALL : 1; /* [0] w1c */ + uint32_t TXFIFO_OVERUN : 1; /* [1] w1c */ + uint32_t ERROR_ABORT : 1; /* [2] w1c */ + uint32_t ACTIVITY : 1; /* [3] w1c */ + uint32_t STOP_DETECT : 1; /* [4] w1c */ + uint32_t START_DETECT : 1; /* [5] w1c */ + uint32_t RSVD_21_6 :16; /* [21:6] ro */ + uint32_t SLAVE_READ_REQ : 1; /* [22] w1c */ + uint32_t RXFIFO_DONE : 1; /* [23] w1c */ + uint32_t RXFIFO_UNDERUN : 1; /* [24] w1c */ + uint32_t RXFIFO_OVERUN : 1; /* [25] w1c */ + uint32_t RESTART_DET : 1; /* [26] w1c */ + uint32_t SCL_STUCK_AT_LOW : 1; /* [27] w1c */ + uint32_t RSVD_29_28 : 2; /* [29:28] ro */ + uint32_t RXFIFO_FULL : 1; /* [30] ro */ + uint32_t TXFIFO_EMPTY : 1; /* [31] ro */ + } I2C_STATUS0; + + /* 0x60*/ + struct { + uint32_t MASTER_IS_ACTIVE : 1; /* [0] ro */ + uint32_t SLAVE_IS_ACTIVE : 1; /* [1] ro */ + uint32_t TXFIFO_EMPTY_MASTER_HOLD: 1; /* [2] ro */ + uint32_t TXFIFO_EMPTY_SLAVE_HOLD : 1; /* [3] ro */ + uint32_t RXFIFO_FULL_MASTER_HOLD : 1; /* [4] ro */ + uint32_t RXFIFO_FULL_SLAVE_HOLD : 1; /* [5] ro */ + uint32_t TXFIFO_IS_NOT_FULL : 1; /* [6] ro */ + uint32_t TXFIFO_IS_EMPTY : 1; /* [7] ro */ + uint32_t RXFIFO_IS_NOT_EMPTY : 1; /* [8] ro */ + uint32_t RXFIFO_IS_FULL : 1; /* [9] ro */ + uint32_t SDA_ERR_RECOVER_STUCK_LOW: 1; /* [10] ro */ + uint32_t SLAVE_IS_DISABLED_UNDER_ACT: 1; /* [11] ro */ + uint32_t SLAVE_RX_DATA_DISCARD : 1; /* [12] ro */ + uint32_t I2C_IS_ENABLE : 1; /* [13] ro */ + uint32_t RSVD_31_14 :18; /* [31:14] ro */ + } I2C_STATUS1; + + /* 0x64*/ + struct { + uint32_t ERR_GEN_CALL_NO_ACK : 1; /* [0] ro */ + uint32_t ERR_GEN_CALL_READ : 1; /* [1] ro */ + uint32_t ERR_START_BYTE_ACK_DET : 1; /* [2] ro */ + uint32_t ERR_SBYTE_NORSTRT : 1; /* [3] ro */ + uint32_t ERR_H_NO_RSTRT : 1; /* [4] ro */ + uint32_t ERR_H_MCODE_ACK_DET : 1; /* [5] ro */ + uint32_t ERR_7BIT_ADDR_NO_ACK : 1; /* [6] ro */ + uint32_t ERR_10BIT_ADDR1_NO_ACK : 1; /* [7] ro */ + uint32_t ERR_10BIT_ADDR2_NO_ACK : 1; /* [8] ro */ + uint32_t ERR_10BIT_READ_NO_RSTRT : 1; /* [9] ro */ + uint32_t ERR_DATA_NO_ACK : 1; /* [10] ro */ + uint32_t ERR_MASTER_ABRT : 1; /* [11] ro */ + uint32_t ERR_MASTER_DIS : 1; /* [12] ro */ + uint32_t ERR_SLAVE_ARBLOST : 1; /* [13] ro */ + uint32_t ERR_MASTER_LOST : 1; /* [14] ro */ + uint32_t ERR_SLAVE_READ_REQ : 1; /* [15] ro */ + uint32_t ERR_SLAVE_FLUSH_TXFIFO : 1; /* [16] ro */ + uint32_t ERR_SDA_LOW_TIMEOUT : 1; /* [17] ro */ + uint32_t ERR_TXFIFO_FLUSH_CNT : 3; /* [20:18] ro */ + uint32_t RSVD_31_21 :11; /* [31:21] ro */ + } I2C_ERROR_STATUS; + + /* 0x68*/ + struct { + uint32_t SCL_LOW_TIMEOUT :32; /* [31:0] r/w */ + } I2C_SCL_LOW_TIMEOUT; + + /* 0x6c*/ + struct { + uint32_t SDA_LOW_TIMEOUT :32; /* [31:0] r/w */ + } I2C_SDA_LOW_TIMEOUT; + + /* 0x70*/ + struct { + uint32_t CLR_ERR : 1; /* [0] r */ + uint32_t RSVD_31_1 :31; /* [31:1] ro */ + } I2C_RD_CLR_ERR_STATUS; + +}; /*i2c_reg*/ + +struct i2c_reg_w { + /* 0x00*/ + uint32_t I2C_VERID; + /* 0x04*/ + uint32_t I2C_PARAMETER; + /* 0x08*/ + uint32_t I2C_CONFIG0; + /* 0x0c*/ + uint32_t I2C_CONFIG1; + /* 0x10*/ + uint32_t I2C_SDA_SETUP_TIMING; + /* 0x14*/ + uint32_t I2C_SDA_HOLD_TIMING; + /* 0x18*/ + uint32_t I2C_DMA_CTRL; + /* 0x1c*/ + uint32_t I2C_INT_ENABLE; + /* 0x20*/ + uint32_t I2C_COMMAND_DATA; + /* 0x24*/ + uint32_t I2C_DEST_ADDR; + /* 0x28*/ + uint32_t I2C_SLAVE_ADDR; + /* 0x2c*/ + uint32_t I2C_STD_SCL_HCNT; + /* 0x30*/ + uint32_t I2C_STD_SCL_LCNT; + /* 0x34*/ + uint32_t I2C_FST_SCL_HCNT; + /* 0x38*/ + uint32_t I2C_FST_CLK_LCNT; + /* 0x3c*/ + uint32_t I2C_HS_CLK_HCNT; + /* 0x40*/ + uint32_t I2C_HS_CLK_LCNT; + /* 0x44*/ + uint32_t I2C_RXFIFO_WATER_MARK; + /* 0x48*/ + uint32_t I2C_TXFIFO_WATER_MARK; + /* 0x4c*/ + uint32_t I2C_TX_FIFO_CNT; + /* 0x50*/ + uint32_t I2C_RX_FIFO_CNT; + /* 0x54*/ + uint32_t I2C_FSTD_SPKCNT; + /* 0x58*/ + uint32_t I2C_HS_SPKCNT; + /* 0x5c*/ + uint32_t I2C_STATUS0; + /* 0x60*/ + uint32_t I2C_STATUS1; + /* 0x64*/ + uint32_t I2C_ERROR_STATUS; + /* 0x68*/ + uint32_t I2C_SCL_LOW_TIMEOUT; + /* 0x6c*/ + uint32_t I2C_SDA_LOW_TIMEOUT; + /* 0x70*/ + uint32_t I2C_RD_CLR_ERR_STATUS; +}; /*i2c_reg*/ + +typedef volatile struct i2c_reg i2c_reg_t; +typedef volatile struct i2c_reg_w i2c_reg_w_t; + +struct parcc_reg { + /* 0x0*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_15_2 :14; /* [15:2] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_WDOG; + + /* 0x4*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_EWDT; + + /* 0x8*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_STIM; + + /* 0xC*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_PWMTIMER0; + + /* 0x10*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_PWMTIMER1; + + /* 0x14*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_PWMTIMER2; + + /* 0x18*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_TDG0; + + /* 0x1C*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_CAN0; + + /* 0x20*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_CAN1; + + /* 0x24*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_UART0; + + /* 0x28*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_UART1; + + /* 0x2C*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_UART2; + + /* 0x30*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_UART3; + + /* 0x34*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_SPI0; + + /* 0x38*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_SPI1; + + /* 0x3C*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_SPI2; + + /* 0x40*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_I2C0; + + /* 0x44*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_I2C1; + + /* 0x48*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_ADC0; + + /* 0x4C*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_15_2 :14; /* [15:2] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_CMP; + + /* 0x50*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_15_2 :14; /* [15:2] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_CRC; + + /* 0x54*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_15_2 :14; /* [15:2] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_FLASH; + + /* 0x58*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_15_2 :14; /* [15:2] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_DMA; + + /* 0x5C*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_15_2 :14; /* [15:2] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_DMAMUX; + + /* 0x60*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_PORTA; + + /* 0x64*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_PORTB; + + /* 0x68*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_PORTC; + + /* 0x6C*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_PORTD; + + /* 0x70*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_PORTE; + + /* 0x74*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_15_2 :14; /* [15:2] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_TMU; + + /* 0x78*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_15_2 :14; /* [15:2] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_REGFILE; + + /* 0x7C*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_15_2 :14; /* [15:2] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_GPIO; + + /* 0x80*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_15_2 :14; /* [15:2] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_HWDIV; + +}; /*parcc_reg*/ + +struct parcc_reg_w { + /* 0x0*/ + uint32_t PARCC_WDOG; + /* 0x4*/ + uint32_t PARCC_EWDT; + /* 0x8*/ + uint32_t PARCC_STIM; + /* 0xC*/ + uint32_t PARCC_PWMTIMER0; + /* 0x10*/ + uint32_t PARCC_PWMTIMER1; + /* 0x14*/ + uint32_t PARCC_PWMTIMER2; + /* 0x18*/ + uint32_t PARCC_TDG0; + /* 0x1C*/ + uint32_t PARCC_CAN0; + /* 0x20*/ + uint32_t PARCC_CAN1; + /* 0x24*/ + uint32_t PARCC_UART0; + /* 0x28*/ + uint32_t PARCC_UART1; + /* 0x2C*/ + uint32_t PARCC_UART2; + /* 0x30*/ + uint32_t PARCC_UART3; + /* 0x34*/ + uint32_t PARCC_SPI0; + /* 0x38*/ + uint32_t PARCC_SPI1; + /* 0x3C*/ + uint32_t PARCC_SPI2; + /* 0x40*/ + uint32_t PARCC_I2C0; + /* 0x44*/ + uint32_t PARCC_I2C1; + /* 0x48*/ + uint32_t PARCC_ADC0; + /* 0x4C*/ + uint32_t PARCC_CMP; + /* 0x50*/ + uint32_t PARCC_CRC; + /* 0x54*/ + uint32_t PARCC_FLASH; + /* 0x58*/ + uint32_t PARCC_DMA; + /* 0x5C*/ + uint32_t PARCC_DMAMUX; + /* 0x60*/ + uint32_t PARCC_PORTA; + /* 0x64*/ + uint32_t PARCC_PORTB; + /* 0x68*/ + uint32_t PARCC_PORTC; + /* 0x6C*/ + uint32_t PARCC_PORTD; + /* 0x70*/ + uint32_t PARCC_PORTE; + /* 0x74*/ + uint32_t PARCC_TMU; + /* 0x78*/ + uint32_t PARCC_REGFILE; + /* 0x7C*/ + uint32_t PARCC_GPIO; + /* 0x80*/ + uint32_t PARCC_HWDIV; +}; /*parcc_reg*/ + +typedef volatile struct parcc_reg parcc_reg_t; +typedef volatile struct parcc_reg_w parcc_reg_w_t; + +struct pmu_reg { + /* 0x00*/ + struct { + uint32_t RSVD_31_0 :32; /* [31:0] r */ + } PMU_VERID; + + /* 0x04*/ + struct { + uint32_t LPO_CLK_DIS : 1; /* [0] r/w */ + uint32_t LPO_CLK_SEL : 1; /* [1] r/w */ + uint32_t LPO_CLK_READY : 1; /* [2] r */ + uint32_t RSVD_31_3 :29; /* [31:3] ro */ + } PMU_LPO_32K_CFG; + + /* 0x08*/ + struct { + uint32_t LPO_32K_TRIM : 7; /* [6:0] r/w */ + uint32_t RSVD_31_7 :25; /* [31:7] ro */ + } PMU_LPO_32K_TRIM; + + /* 0x0c*/ + struct { + uint32_t ISO_CLR : 1; /* [0] w1c */ + uint32_t RSVD_31_1 :31; /* [31:1] ro */ + } PMU_ISO_CLR; + + /* 0x10*/ + struct { + uint32_t VDD_LVD_LP_EN : 1; /* [0] r/w */ + uint32_t VDD_LVD_ACT_EN : 1; /* [1] r/w */ + uint32_t VDD_LVD_IE : 1; /* [2] r/w */ + uint32_t VDD_LVD_RE : 1; /* [3] r/w */ + uint32_t VDD_LVW_EN : 1; /* [4] r/w */ + uint32_t VDD_LVW_IE : 1; /* [5] r/w */ + uint32_t LVWF_VDD : 1; /* [6] w1c */ + uint32_t LVDF_VDD : 1; /* [7] w1c */ + uint32_t REF_BUF_1V_EN : 1; /* [8] r/w */ + uint32_t LDO_LVD_ACT_EN : 1; /* [9] r/w */ + uint32_t LDO_LVD_LP_EN : 1; /* [10] r/w */ + uint32_t LDO_CLAMP_EN : 1; /* [11] r/w */ + uint32_t RSVD_31_12 :20; /* [31:12] ro */ + } PMU_VDD5V_CSR; + + /* 0x14*/ + struct { + uint32_t RSVD_30_0 :31; /* [30:0] ro */ + uint32_t LOCK : 1; /* [31] w/r */ + } PMU_LOCK; + +}; /*pmu_reg*/ + +struct pmu_reg_w { + /* 0x00*/ + uint32_t PMU_VERID; + /* 0x04*/ + uint32_t PMU_LPO_32K_CFG; + /* 0x08*/ + uint32_t PMU_LPO_32K_TRIM; + /* 0x0c*/ + uint32_t PMU_ISO_CLR; + /* 0x10*/ + uint32_t PMU_VDD5V_CSR; + /* 0x14*/ + uint32_t PMU_LOCK; + +}; /*pmu_reg_w*/ + +typedef volatile struct pmu_reg pmu_reg_t; +typedef volatile struct pmu_reg_w pmu_reg_w_t; + +struct port_reg { + /* 0x0*/ + struct { + uint32_t FEATURE :16; /* [15:0] ro */ + uint32_t MINOR : 8; /* [23:16] ro */ + uint32_t MAJOR : 8; /* [31:24] ro */ + } PORTx_VERID; + + /* 0x4*/ + struct { + uint32_t RSVD_31_0 :32; /* [31:0] ro */ + } PORTx_PARAM; + + /* 0x8*/ + struct { + uint32_t GPWD :32; /* [31:0] r/w */ + } PORTx_GLBDAT; + + /* 0xC*/ + struct { + uint32_t GPWE :32; /* [31:0] wo */ + } PORTx_GLBCTL; + + /* 0x10*/ + struct { + uint32_t PS : 1; /* [0] r/w */ + uint32_t PE : 1; /* [1] r/w */ + uint32_t RSVD_2 : 1; /* [2] ro */ + uint32_t SRE : 1; /* [3] r/w */ + uint32_t PFE : 1; /* [4] r/w */ + uint32_t ODE : 1; /* [5] r/w */ + uint32_t DSE : 1; /* [6] r/w */ + uint32_t RSVD_7 : 1; /* [7] ro */ + uint32_t MUX : 3; /* [10:8] r/w */ + uint32_t RSVD_14_11 : 4; /* [14:11] ro */ + uint32_t LK : 1; /* [15] r/w */ + uint32_t IRQC : 4; /* [19:16] r/w */ + uint32_t RSVD_22_20 : 3; /* [22:20] ro */ + uint32_t ISF : 1; /* [23] r/w */ + uint32_t FLT : 5; /* [28:24] r/w */ + uint32_t RSVD_30_29 : 2; /* [30:29] ro */ + uint32_t FLTEN : 1; /* [31] r/w */ + } PORTx_PCRn[32]; + + /* 0x90*/ + struct { + uint32_t ISF :32; /* [31:0] r/w */ + } PORTx_IRQFLG; +}; /*port_reg*/ + +struct port_reg_w { + /* 0x0*/ + uint32_t PORTx_VERID; + /* 0x4*/ + uint32_t PORTx_PARAM; + /* 0x8*/ + uint32_t PORTx_GLBDAT; + /* 0xC*/ + uint32_t PORTx_GLBCTL; + /* 0x10*/ + uint32_t PORTx_PCRn[32]; + /* 0x90*/ + uint32_t PORTx_IRQFLG; +}; /*port_reg*/ + +typedef volatile struct port_reg port_reg_t; +typedef volatile struct port_reg_w port_reg_w_t; + +struct regfile_reg { + /* 0x0*/ + struct { + uint32_t DATA :32; /* [31:0] rw */ + } REGFILE_REGn[32]; + +}; /*regfile_reg*/ + +struct regfile_reg_w { + /* 0x0*/ + uint32_t REGFILE_REGn[32]; +}; /*regfile_reg*/ + +typedef volatile struct regfile_reg regfile_reg_t; +typedef volatile struct regfile_reg_w regfile_reg_w_t; + +struct rtc_reg { + /* 0x00*/ + struct { + uint32_t CRYSTAL_EN : 1; /* [0] r/w */ + uint32_t CNT_CLK_SEL : 1; /* [1] r/w */ + uint32_t CLKOUT_SEL : 1; /* [2] r/w */ + uint32_t CLKOUT_PIN_EN : 1; /* [3] r/w */ + uint32_t SUP_EN : 1; /* [4] r/w */ + uint32_t SW_RST : 1; /* [5] r/w */ + uint32_t COUNT_EN : 1; /* [6] r/w */ + uint32_t OVF : 1; /* [7] ro */ + uint32_t ALARM_MATCHF : 1; /* [8] ro */ + uint32_t OSC_RDY : 1; /* [9] ro */ + uint32_t EXTAL_32K_EN : 1; /* [10] r/w */ + uint32_t SECONDS_INT_FLAG : 1; /* [11] w1c */ + uint32_t RSVD_31_12 :20; /* [31:12] ro */ + } RTC_CSR; + + /* 0x04*/ + struct { + uint32_t SECOND_INT_MUX_SEL : 3; /* [2:0] r/w */ + uint32_t OVFLOW_IE : 1; /* [3] r/w */ + uint32_t ALARM_IE : 1; /* [4] r/w */ + uint32_t SECONDS_IE : 1; /* [5] r/w */ + uint32_t RSVD_31_6 :26; /* [31:6] ro */ + } RTC_IER; + + /* 0x08*/ + struct { + uint32_t ALARM_CNT :32; /* [31:0] r/w */ + } RTC_ALARM_CNTR; + + /* 0x0c*/ + struct { + uint32_t ONE_SECOND_CNT :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] ro */ + } RTC_ONE_SECOND_CNTR; + + /* 0x10*/ + struct { + uint32_t MATCH_CNT :32; /* [31:0] r/w */ + } RTC_MATCH_CNTR; + + /* 0x14*/ + struct { + uint32_t COMP_CNT : 7; /* [6:0] r/w */ + uint32_t COMP_DIRECTION : 1; /* [7] r/w */ + uint32_t DLY : 8; /* [15:8] r/w */ + uint32_t CCOMP_CNT : 8; /* [23:16] ro */ + uint32_t CDLY : 8; /* [31:24] ro */ + } RTC_COMPENSATIONR; + + /* 0x18*/ + struct { + uint32_t RSVD_30_0 :31; /* [30:0] ro */ + uint32_t LOCK : 1; /* [31] r/w */ + } RTC_LOCKR; + + /* 0x1c*/ + struct { + uint32_t RSVD_31_0 :32; /* [31:0] ro */ + } RTC_VERID; + +}; /*rtc_reg*/ + +struct rtc_reg_w { + /* 0x00*/ + uint32_t RTC_CSR; + /* 0x04*/ + uint32_t RTC_IER; + /* 0x08*/ + uint32_t RTC_ALARM_CNTR; + /* 0x0c*/ + uint32_t RTC_ONE_SECOND_CNTR; + /* 0x10*/ + uint32_t RTC_MATCH_CNTR; + /* 0x14*/ + uint32_t RTC_COMPENSATIONR; + /* 0x18*/ + uint32_t RTC_LOCKR; + /* 0x1c*/ + uint32_t RTC_VERID; +}; /*rtc_reg*/ + +typedef volatile struct rtc_reg rtc_reg_t; +typedef volatile struct rtc_reg_w rtc_reg_w_t; + +struct scc_reg { + /* 0x0*/ + struct { + uint32_t RSVD_7_0 : 8; /* [7:0] r */ + uint32_t MINOR : 8; /* [15:8] r */ + uint32_t MAJOR : 8; /* [23:16] r */ + uint32_t RSVD_31_24 : 8; /* [31:24] r */ + } SCC_VERID; + + /* 0x4*/ + struct { + uint32_t CLKSPRES : 5; /* [4:0] r */ + uint32_t RSVD_27_5 :23; /* [27:5] r */ + uint32_t DIVPRES : 3; /* [30:28] r */ + uint32_t RSVD_31 : 1; /* [31] r */ + } SCC_PARAM; + + /* 0x8*/ + struct { + uint32_t DIVSLOW : 4; /* [3:0] r */ + uint32_t DIVBUS : 4; /* [7:4] r */ + uint32_t DIVCORE : 4; /* [11:8] r */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t SCS : 3; /* [18:16] r */ + uint32_t RSVD_31_19 :13; /* [31:19] r */ + } SCC_CST; + + /* 0xC*/ + struct { + uint32_t DIVSLOW : 4; /* [3:0] r/w */ + uint32_t DIVBUS : 4; /* [7:4] r/w */ + uint32_t DIVCORE : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t SCS : 3; /* [18:16] r/w */ + uint32_t RSVD_30_19 :12; /* [30:19] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } SCC_CFG; + + /* 0x10*/ + struct { + uint32_t RSVD_15_0 :16; /* [15:0] r */ + uint32_t CLKOUTSEL : 4; /* [19:16] r/w */ + uint32_t RSVD_31_20 :12; /* [31:20] */ + } SCC_CLKOUTCFG; + + /* 0x14*/ + struct { + uint32_t OSCEN : 1; /* [0] r/w */ + uint32_t OSCSTOPEN : 1; /* [1] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t OSCCMIE : 1; /* [4] r/w */ + uint32_t RSVD_8_5 : 4; /* [8:5] r */ + uint32_t OSCCME : 1; /* [9] r/w */ + uint32_t OSCCMRE : 1; /* [10] r/w */ + uint32_t RSVD_15_11 : 5; /* [15:11] r */ + uint32_t OSCRDY : 1; /* [16] r */ + uint32_t OSCSELD : 1; /* [17] r */ + uint32_t OSCLOC : 1; /* [18] r/w */ + uint32_t RSVD_30_19 :12; /* [30:19] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } SCC_OSCCS; + + /* 0x18*/ + struct { + uint32_t EXCLKS : 1; /* [0] r/w */ + uint32_t OLMEN : 1; /* [1] r/w */ + uint32_t HFREQ : 1; /* [2] r/w */ + uint32_t RSVD_7_3 : 5; /* [7:3] r */ + uint32_t RSVD_9_8 : 2; /* [9:8] r/w */ + uint32_t RSVD_31_10 :22; /* [31:10] r */ + } SCC_OSCCFG; + + /* 0x1C*/ + struct { + uint32_t FIRCEN : 1; /* [0] r/w */ + uint32_t FIRCSTOPEN : 1; /* [1] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t FIRCCMIE : 1; /* [4] r/w */ + uint32_t RSVD_8_5 : 4; /* [8:5] r */ + uint32_t FIRCCME : 1; /* [9] r/w */ + uint32_t FIRCCMRE : 1; /* [10] r/w */ + uint32_t RSVD_11 : 1; /* [11] r */ + uint32_t RSVD_12 : 1; /* [12] r/w */ + uint32_t RSVD_15_13 : 3; /* [15:13] r */ + uint32_t FIRCRDY : 1; /* [16] r */ + uint32_t FIRCSELD : 1; /* [17] r */ + uint32_t FIRCLOC : 1; /* [18] r/w */ + uint32_t RSVD_30_19 :12; /* [30:19] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } SCC_FIRCCS; + + /* 0x20*/ + struct { + uint32_t RSVD_1_0 : 2; /* [1:0] r/w */ + uint32_t RSVD_31_2 :30; /* [31:2] r */ + } SCC_FIRCCFG; + + /* 0x24*/ + struct { + uint32_t RSVD_5_0 : 6; /* [5:0] r/w */ + uint32_t RSVD_31_6 :26; /* [31:6] r */ + } SCC_FIRCTRIM; + +}; /*scc_reg*/ + +struct scc_reg_w { + /* 0x0*/ + uint32_t SCC_VERID; + /* 0x4*/ + uint32_t SCC_PARAM; + /* 0x8*/ + uint32_t SCC_CST; + /* 0xC*/ + uint32_t SCC_CFG; + /* 0x10*/ + uint32_t SCC_CLKOUTCFG; + /* 0x14*/ + uint32_t SCC_OSCCS; + /* 0x18*/ + uint32_t SCC_OSCCFG; + /* 0x1C*/ + uint32_t SCC_FIRCCS; + /* 0x20*/ + uint32_t SCC_FIRCCFG; + /* 0x24*/ + uint32_t SCC_FIRCTRIM; +}; /*scc_reg*/ + +typedef volatile struct scc_reg scc_reg_t; +typedef volatile struct scc_reg_w scc_reg_w_t; + +struct scm_reg { + /* 0x00*/ + struct { + uint32_t RSVD_3_0 : 4; /* [3:0] ro */ + uint32_t CLKOUTSEL : 2; /* [5:4] r/w */ + uint32_t RSVD_7_6 : 2; /* [7:6] ro */ + uint32_t CLKOUTDIV : 3; /* [10:8] r/w */ + uint32_t CLKOUTEN : 1; /* [11] r/w */ + uint32_t RSVD_31_12 :20; /* [31:12] ro */ + } SCM_CHIPCTL; + + /* 0x04*/ + struct { + uint32_t SWTRIG : 4; /* [3:0] r/w */ + uint32_t RSVD_31_4 :28; /* [31:4] ro */ + } SCM_MISCCTL; + + /* 0x08*/ + struct { + uint32_t TIM0_CLK_SEL : 2; /* [1:0] r/w */ + uint32_t RSVD_7_2 : 6; /* [7:2] ro */ + uint32_t TIM1_CLK_SEL : 2; /* [9:8] r/w */ + uint32_t RSVD_15_10 : 6; /* [15:10] ro */ + uint32_t TIM2_CLK_SEL : 2; /* [17:16] r/w */ + uint32_t RSVD_31_18 :14; /* [31:18] ro */ + } SCM_TIMOPT; + + /* 0x0C*/ + struct { + uint32_t SRAM0_ECCR_DIS : 1; /* [0] r/w */ + uint32_t SRAM0_ECCW_DIS : 1; /* [1] r/w */ + uint32_t SRAM0_ECCSB_DIS : 1; /* [2] r/w */ + uint32_t SRAM0_ECCMB_DIS : 1; /* [3] r/w */ + uint32_t RSVD_7_4 : 4; /* [7:4] ro */ + uint32_t SRAM1_ECCR_DIS : 1; /* [8] r/w */ + uint32_t SRAM1_ECCW_DIS : 1; /* [9] r/w */ + uint32_t SRAM1_ECCSB_DIS : 1; /* [10] r/w */ + uint32_t SRAM1_ECCMB_DIS : 1; /* [11] r/w */ + uint32_t RSVD_31_12 :20; /* [31:12] ro */ + } SCM_ECCOPT; + + /* 0x10*/ + struct { + uint32_t EFPROT : 4; /* [3:0] ro */ + uint32_t EFSIZE : 3; /* [6:4] ro */ + uint32_t EFW : 1; /* [7] ro */ + uint32_t EFMST : 4; /* [11:8] ro */ + uint32_t RSVD_28_12 :17; /* [28:12] ro */ + uint32_t SBERR : 1; /* [29] w1c */ + uint32_t MBERR : 1; /* [30] w1c */ + uint32_t OVERRUN : 1; /* [31] w1c */ + } SCM_ECC0ST; + + /* 0x14*/ + struct { + uint32_t EFADDR :32; /* [31:0] ro */ + } SCM_ECC0FADDR; + + /* 0x18*/ + struct { + uint32_t EFDATA :32; /* [31:0] ro */ + } SCM_ECC0FDATA; + + /* 0x1C*/ + struct { + uint32_t EFPROT : 4; /* [3:0] ro */ + uint32_t EFSIZE : 3; /* [6:4] ro */ + uint32_t EFW : 1; /* [7] ro */ + uint32_t EFMST : 4; /* [11:8] ro */ + uint32_t RSVD_28_12 :17; /* [28:12] ro */ + uint32_t SBERR : 1; /* [29] w1c */ + uint32_t MBERR : 1; /* [30] w1c */ + uint32_t OVERRUN : 1; /* [31] w1c */ + } SCM_ECC1ST; + + /* 0x20*/ + struct { + uint32_t EFADDR :32; /* [31:0] ro */ + } SCM_ECC1FADDR; + + /* 0x24*/ + struct { + uint32_t EFDATA :32; /* [31:0] ro */ + } SCM_ECC1FDATA; + + uint8_t zResverd0x028[216]; /*pad 0x028 - 0FF*/ + + /* 0x100*/ + struct { + uint32_t RSVD_31_0 :32; /* [31:0] ro */ + } SCM_CHIPOPT; + + /* 0x104*/ + struct { + uint32_t RSVD_23_0 :24; /* [23:0] ro */ + uint32_t PFSIZE : 4; /* [27:24] ro */ + uint32_t DFSIZE : 4; /* [31:28] ro */ + } SCM_FLSCFG; + + /* 0x108*/ + struct { + uint32_t RSVD_27_0 :28; /* [27:0] ro */ + uint32_t RAMSIZE : 4; /* [31:28] ro */ + } SCM_RAMCFG; + + uint8_t zResverd0x010C[16]; /*pad 0x010C - 011B*/ + + /* 0x11C*/ + struct { + uint32_t MEMSIZE_ID : 4; /* [3:0] ro */ + uint32_t SERIES_ID : 3; /* [6:4] ro */ + uint32_t SUBFAMILY_ID : 5; /* [11:7] ro */ + uint32_t FAMILY_ID : 4; /* [15:12] ro */ + uint32_t REV_ID : 4; /* [19:16] ro */ + uint32_t FEATURE_ID : 7; /* [26:20] ro */ + uint32_t PACKAGE_ID : 5; /* [31:27] ro */ + } SCM_DEVID; + + /* 0x120*/ + struct { + uint32_t UID_31_0 :32; /* [31:0] ro */ + } SCM_UNIQUE0; + + /* 0x124*/ + struct { + uint32_t UID_63_32 :32; /* [31:0] ro */ + } SCM_UNIQUE1; + + /* 0x128*/ + struct { + uint32_t UID_95_64 :32; /* [31:0] ro */ + } SCM_UNIQUE2; + + /* 0x12C*/ + struct { + uint32_t UID_127_96 :32; /* [31:0] ro */ + } SCM_UNIQUE3; + +}; /*scm_reg*/ + +struct scm_reg_w { + /* 0x00*/ + uint32_t SCM_CHIPCTL; + /* 0x04*/ + uint32_t SCM_MISCCTL; + /* 0x08*/ + uint32_t SCM_TIMOPT; + /* 0x0C*/ + uint32_t SCM_ECCOPT; + /* 0x10*/ + uint32_t SCM_ECC0ST; + /* 0x14*/ + uint32_t SCM_ECC0FADDR; + /* 0x18*/ + uint32_t SCM_ECC0FDATA; + /* 0x1C*/ + uint32_t SCM_ECC1ST; + /* 0x20*/ + uint32_t SCM_ECC1FADDR; + /* 0x24*/ + uint32_t SCM_ECC1FDATA; + uint8_t zResverd0x028[216]; /*pad 0x028 - 0FF*/ + + /* 0x100*/ + uint32_t SCM_CHIPOPT; + /* 0x104*/ + uint32_t SCM_FLSCFG; + /* 0x108*/ + uint32_t SCM_RAMCFG; + uint8_t zResverd0x010C[16]; /*pad 0x010C - 011B*/ + + /* 0x11C*/ + uint32_t SCM_DEVID; + /* 0x120*/ + uint32_t SCM_UNIQUE0; + /* 0x124*/ + uint32_t SCM_UNIQUE1; + /* 0x128*/ + uint32_t SCM_UNIQUE2; + /* 0x12C*/ + uint32_t SCM_UNIQUE3; +}; /*scm_reg*/ + +typedef volatile struct scm_reg scm_reg_t; +typedef volatile struct scm_reg_w scm_reg_w_t; + +struct spi_reg { + /* 0x0*/ + struct { + uint32_t DFS : 4; /* [3:0] r/w */ + uint32_t RSVD_5_4 : 2; /* [5:4] ro */ + uint32_t SCPH : 1; /* [6] r/w */ + uint32_t SCPOL : 1; /* [7] r/w */ + uint32_t TMOD : 2; /* [9:8] r/w */ + uint32_t RSVD_10 : 1; /* [10] r/w */ + uint32_t RSVD_11 : 1; /* [11] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r/w */ + uint32_t DFS_32 : 5; /* [20:16] r/w */ + uint32_t MST_MODE : 1; /* [21] r/w */ + uint32_t RSVD_22 : 1; /* [22] r/w */ + uint32_t RSVD_23 : 1; /* [23] r/w */ + uint32_t RSVD_24 : 1; /* [24] r/w */ + uint32_t RSVD_31_25 : 7; /* [31:25] ro */ + } SPI_CTRLR0; + + /* 0x4*/ + struct { + uint32_t NDF :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] ro */ + } SPI_CTRLR1; + + /* 0x8*/ + struct { + uint32_t SPI_EN : 1; /* [0] r/w */ + uint32_t RSVD_15_1 :15; /* [15:1] ro */ + uint32_t SER : 2; /* [17:16] r/w */ + uint32_t RSVD_31_18 :14; /* [31:18] ro */ + } SPI_SSENR; + + /* 0xC*/ + struct { + uint32_t SCKDV :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] ro */ + } SPI_BAUDR; + + /* 0x10*/ + struct { + uint32_t TFT : 2; /* [1:0] r/w */ + uint32_t RSVD_15_2 :14; /* [15:2] ro */ + uint32_t RFT : 2; /* [17:16] r/w */ + uint32_t RSVD_31_18 :14; /* [31:18] ro */ + } SPI_FTLR; + + /* 0x14*/ + struct { + uint32_t TXTFL : 3; /* [2:0] ro */ + uint32_t RSVD_15_3 :13; /* [15:3] ro */ + uint32_t RXTFL : 3; /* [18:16] ro */ + uint32_t RSVD_31_19 :13; /* [31:19] ro */ + } SPI_FLR; + + /* 0x18*/ + struct { + uint32_t BUSY : 1; /* [0] ro */ + uint32_t TFNF : 1; /* [1] ro */ + uint32_t TFE : 1; /* [2] ro */ + uint32_t RFNE : 1; /* [3] ro */ + uint32_t RFF : 1; /* [4] ro */ + uint32_t TXE : 1; /* [5] ro */ + uint32_t RSVD_31_6 :26; /* [31:6] ro */ + } SPI_SR; + + /* 0x1C*/ + struct { + uint32_t TXEIE : 1; /* [0] r/w */ + uint32_t TXOIE : 1; /* [1] r/w */ + uint32_t RXUIE : 1; /* [2] r/w */ + uint32_t RXOIE : 1; /* [3] r/w */ + uint32_t RXFIE : 1; /* [4] r/w */ + uint32_t RSVD_31_5 :27; /* [31:5] ro */ + } SPI_IER; + + /* 0x20*/ + struct { + uint32_t TXEIS : 1; /* [0] ro */ + uint32_t TXOIS : 1; /* [1] ro */ + uint32_t RXUIS : 1; /* [2] ro */ + uint32_t RXOIS : 1; /* [3] ro */ + uint32_t RXFIS : 1; /* [4] ro */ + uint32_t RSVD_15_5 :11; /* [15:5] ro */ + uint32_t TXEIR : 1; /* [16] ro */ + uint32_t TXOIR : 1; /* [17] ro */ + uint32_t RXUIR : 1; /* [18] ro */ + uint32_t RXOIR : 1; /* [19] ro */ + uint32_t RXFIR : 1; /* [20] ro */ + uint32_t RSVD_31_21 :11; /* [31:21] ro */ + } SPI_ISR; + + /* 0x24*/ + struct { + uint32_t TXOICR : 1; /* [0] ro */ + uint32_t RSVD_31_1 :31; /* [31:1] ro */ + } SPI_TXOICR; + + /* 0x28*/ + struct { + uint32_t RXOICR : 1; /* [0] ro */ + uint32_t RSVD_31_1 :31; /* [31:1] ro */ + } SPI_RXOICR; + + /* 0x2c*/ + struct { + uint32_t RXUICR : 1; /* [0] ro */ + uint32_t RSVD_31_1 :31; /* [31:1] ro */ + } SPI_RXUICR; + + uint8_t zResverd0x030[4]; /*pad 0x030 - 033*/ + + /* 0x34*/ + struct { + uint32_t ICR : 1; /* [0] ro */ + uint32_t RSVD_31_1 :31; /* [31:1] ro */ + } SPI_ICR; + + /* 0x38*/ + struct { + uint32_t RDMAE : 1; /* [0] r/w */ + uint32_t TDMAE : 1; /* [1] r/w */ + uint32_t RSVD_31_2 :30; /* [31:2] ro */ + } SPI_DMACR; + + /* 0x3C*/ + struct { + uint32_t DMATDL : 2; /* [1:0] r/w */ + uint32_t RSVD_31_2 :30; /* [31:2] ro */ + } SPI_DMATDLR; + + /* 0x40*/ + struct { + uint32_t DMARDL : 2; /* [1:0] r/w */ + uint32_t RSVD_31_2 :30; /* [31:2] ro */ + } SPI_DMARDLR; + + /* 0x44*/ + struct { + uint32_t RSVD_31_0 :32; /* [31:0] ro */ + } SPI_IDR; + + /* 0x48*/ + struct { + uint32_t RSVD_31_0 :32; /* [31:0] ro */ + } SPI_VIDR; + + uint8_t zResverd0x04C[20]; /*pad 0x04C - 05F*/ + + /* 0x60*/ + struct { + uint32_t DR :32; /* [31:0] r/w */ + } SPI_DR_LOW; + + uint8_t zResverd0x064[136]; /*pad 0x064 - 0EB*/ + + /* 0xEC*/ + struct { + uint32_t DR :32; /* [31:0] r/w */ + } SPI_DR_HIGH; + +}; /*spi_reg*/ + +struct spi_reg_w { + /* 0x0*/ + uint32_t SPI_CTRLR0; + /* 0x4*/ + uint32_t SPI_CTRLR1; + /* 0x8*/ + uint32_t SPI_SSENR; + /* 0xC*/ + uint32_t SPI_BAUDR; + /* 0x10*/ + uint32_t SPI_FTLR; + /* 0x14*/ + uint32_t SPI_FLR; + /* 0x18*/ + uint32_t SPI_SR; + /* 0x1C*/ + uint32_t SPI_IER; + /* 0x20*/ + uint32_t SPI_ISR; + /* 0x24*/ + uint32_t SPI_TXOICR; + /* 0x28*/ + uint32_t SPI_RXOICR; + /* 0x2c*/ + uint32_t SPI_RXUICR; + uint8_t zResverd0x030[4]; /*pad 0x030 - 033*/ + + /* 0x34*/ + uint32_t SPI_ICR; + /* 0x38*/ + uint32_t SPI_DMACR; + /* 0x3C*/ + uint32_t SPI_DMATDLR; + /* 0x40*/ + uint32_t SPI_DMARDLR; + /* 0x44*/ + uint32_t SPI_IDR; + /* 0x48*/ + uint32_t SPI_VIDR; + uint8_t zResverd0x04C[20]; /*pad 0x04C - 05F*/ + + /* 0x60*/ + uint32_t SPI_DR_LOW; + uint8_t zResverd0x064[136]; /*pad 0x064 - 0EB*/ + + /* 0xEC*/ + uint32_t SPI_DR_HIGH; +}; /*spi_reg*/ + +typedef volatile struct spi_reg spi_reg_t; +typedef volatile struct spi_reg_w spi_reg_w_t; + +struct srmc_reg { + /* 0x00*/ + struct { + uint32_t FEATURE :16; /* [15:0] ro */ + uint32_t MINOR : 8; /* [23:16] ro */ + uint32_t MAJOR : 8; /* [31:24] ro */ + } SRMC_VERID; + + /* 0x04*/ + struct { + uint32_t EWAKEUP : 1; /* [0] ro */ + uint32_t ELVD : 1; /* [1] ro */ + uint32_t ELOC : 1; /* [2] ro */ + uint32_t RSVD_3 : 1; /* [3] ro */ + uint32_t RSVD_4 : 1; /* [4] ro */ + uint32_t EWDOG : 1; /* [5] ro */ + uint32_t EPIN : 1; /* [6] ro */ + uint32_t EPOR : 1; /* [7] ro */ + uint32_t RSVD_8 : 1; /* [8] ro */ + uint32_t ELOCKUP : 1; /* [9] ro */ + uint32_t ESW : 1; /* [10] ro */ + uint32_t EMDM_AP : 1; /* [11] ro */ + uint32_t RSVD_12 : 1; /* [12] ro */ + uint32_t ESACKERR : 1; /* [13] ro */ + uint32_t RSVD_15_14 : 2; /* [15:14] ro */ + uint32_t EPDOWN : 1; /* [16] ro */ + uint32_t RSVD_31_17 :15; /* [31:17] ro */ + } SRMC_PARAM; + + /* 0x08*/ + struct { + uint32_t WAKEUP : 1; /* [0] ro */ + uint32_t LVD : 1; /* [1] w1c */ + uint32_t LOC : 1; /* [2] w1c */ + uint32_t RSVD_4_3 : 2; /* [4:3] ro */ + uint32_t WDOG : 1; /* [5] w1c */ + uint32_t PIN : 1; /* [6] w1c */ + uint32_t POR : 1; /* [7] w1c */ + uint32_t RSVD_8 : 1; /* [8] ro */ + uint32_t LOCKUP : 1; /* [9] w1c */ + uint32_t SW : 1; /* [10] w1c */ + uint32_t MDM_AP : 1; /* [11] w1c */ + uint32_t RSVD_14_12 : 3; /* [14:12] ro */ + uint32_t SACKERR : 1; /* [15] w1c */ + uint32_t RSVD_31_16 :16; /* [31:16] ro */ + } SRMC_SRS; + + /* 0x0C*/ + struct { + uint32_t RSTFLTSRW : 2; /* [1:0] r/w */ + uint32_t RSTFLTSS : 1; /* [2] r/w */ + uint32_t RSVD_7_3 : 5; /* [7:3] r/w */ + uint32_t RSTFLTSEL : 5; /* [12:8] r/w */ + uint32_t RSVD_30_13 :18; /* [30:13] r */ + uint32_t LOCKUP_RST_EN : 1; /* [31] r/w */ + } SRMC_CTRL; + + /* 0x10*/ + struct { + uint32_t RSVD_31_0 :32; /* [31:0] ro */ + } SRMC_MR; + + /* 0x14*/ + struct { + uint32_t RSVD_31_0 :32; /* [31:0] ro */ + } SRMC_FM; + + /* 0x18*/ + struct { + uint32_t WAKEUP : 1; /* [0] ro */ + uint32_t SLVD : 1; /* [1] ro */ + uint32_t SLOC : 1; /* [2] ro */ + uint32_t RSVD_4_3 : 2; /* [4:3] ro */ + uint32_t SWDOG : 1; /* [5] ro */ + uint32_t SPIN : 1; /* [6] ro */ + uint32_t SPOR : 1; /* [7] ro */ + uint32_t RSVD_8 : 1; /* [8] ro */ + uint32_t SLOCKUP : 1; /* [9] ro */ + uint32_t SSW : 1; /* [10] ro */ + uint32_t SMDM_AP : 1; /* [11] ro */ + uint32_t RSVD_14_12 : 3; /* [14:12] ro */ + uint32_t SSACKERR : 1; /* [15] ro */ + uint32_t RSVD_31_16 :16; /* [31:16] ro */ + } SRMC_SSRS; + + /* 0x1C*/ + struct { + uint32_t DELAY : 2; /* [1:0] r/w */ + uint32_t LOC : 1; /* [2] r/w */ + uint32_t RSVD_4_3 : 2; /* [4:3] ro */ + uint32_t WDOG : 1; /* [5] r/w */ + uint32_t PIN : 1; /* [6] r/w */ + uint32_t GIE : 1; /* [7] r/w */ + uint32_t RSVD_8 : 1; /* [8] ro */ + uint32_t LOCKUP : 1; /* [9] r/w */ + uint32_t SW : 1; /* [10] r/w */ + uint32_t RSVD_14_11 : 4; /* [14:11] ro */ + uint32_t SACKERR : 1; /* [15] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] ro */ + } SRMC_SRIE; + + /* 0x20*/ + struct { + uint32_t APD : 1; /* [0] r/w */ + uint32_t RSVD_31_1 :31; /* [31:1] ro */ + } SRMC_PMPORT; + + /* 0x24*/ + struct { + uint32_t DSMC : 2; /* [1:0] r/w */ + uint32_t RSVD_7_2 : 6; /* [7:2] ro */ + uint32_t DSMACKTMO : 8; /* [15:8] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] ro */ + } SRMC_PMCTRL; + + /* 0x28*/ + struct { + uint32_t PMSTAT : 4; /* [3:0] ro */ + uint32_t RSVD_7_4 : 4; /* [7:4] ro */ + uint32_t DSMABORT : 1; /* [8] ro */ + uint32_t RSVD_31_9 :23; /* [31:9] ro */ + } SRMC_PMSTAT; + + /* 0x2C*/ + struct { + uint32_t WUPSRC_EN0 : 3; /* [2:0] r/w */ + uint32_t RSVD_3 : 1; /* [3] ro */ + uint32_t WUPSRC_EN1 : 8; /* [11:4] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] ro */ + uint32_t WUPSRC_PL0 : 3; /* [18:16] r/w */ + uint32_t RSVD_19 : 1; /* [19] ro */ + uint32_t WUPSRC_PL1 : 8; /* [27:20] r/w */ + uint32_t RSVD_31_28 : 4; /* [31:28] ro */ + } SRMC_DSMWUPC; + + /* 0x30*/ + struct { + uint32_t WUPS0 : 3; /* [2:0] w1c */ + uint32_t RSVD_3 : 1; /* [3] ro */ + uint32_t WUPS1 : 8; /* [11:4] w1c */ + uint32_t RSVD_31_28 : 4; /* [31:28] ro */ + } SRMC_DSMWUPS; + +}; /*srmc_reg*/ + +struct srmc_reg_w { + /* 0x00*/ + uint32_t SRMC_VERID; + /* 0x04*/ + uint32_t SRMC_PARAM; + /* 0x08*/ + uint32_t SRMC_SRS; + /* 0x0C*/ + uint32_t SRMC_CTRL; + /* 0x10*/ + uint32_t SRMC_MR; + /* 0x14*/ + uint32_t SRMC_FM; + /* 0x18*/ + uint32_t SRMC_SSRS; + /* 0x1C*/ + uint32_t SRMC_SRIE; + /* 0x20*/ + uint32_t SRMC_PMPORT; + /* 0x24*/ + uint32_t SRMC_PMCTRL; + /* 0x28*/ + uint32_t SRMC_PMSTAT; + /* 0x2C*/ + uint32_t SRMC_DSMWUPC; + /* 0x30*/ + uint32_t SRMC_DSMWUPS; +}; /*srmc_reg*/ + +typedef volatile struct srmc_reg srmc_reg_t; +typedef volatile struct srmc_reg_w srmc_reg_w_t; + +struct stim_reg { + /* 0x00*/ + struct { + uint32_t VERID :32; /* [31:0] ro */ + } STIM_VERID; + + /* 0x04*/ + struct { + uint32_t CNT :32; /* [31:0] ro */ + } STIM_CNTn[4]; + + /* 0x14*/ + struct { + uint32_t CV :32; /* [31:0] r/w */ + } STIM_CVn[4]; + + /* 0x24*/ + struct { + uint32_t CLKS : 2; /* [1:0] r/w */ + uint32_t PSDIV : 4; /* [5:2] r/w */ + uint32_t PSEN : 1; /* [6] r/w */ + uint32_t POL : 1; /* [7] r/w */ + uint32_t PSRC : 2; /* [9:8] r/w */ + uint32_t MODE : 1; /* [10] r/w */ + uint32_t RSTDIS : 1; /* [11] r/w */ + uint32_t DMAE : 1; /* [12] r/w */ + uint32_t IE : 1; /* [13] r/w */ + uint32_t EN : 1; /* [14] r/w */ + uint32_t FLAG : 1; /* [15] w1c */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } STIM_SCn[4]; + +}; /*stim_reg*/ + +struct stim_reg_w { + /* 0x00*/ + uint32_t STIM_VERID; + /* 0x04*/ + uint32_t STIM_CNTn[4]; + /* 0x14*/ + uint32_t STIM_CVn[4]; + /* 0x24*/ + uint32_t STIM_SCn[4]; +}; /*stim_reg*/ + +typedef volatile struct stim_reg stim_reg_t; +typedef volatile struct stim_reg_w stim_reg_w_t; + +struct tdg_reg { + /* 0x0*/ + struct { + uint32_t MINOR : 4; /* [3:0] r */ + uint32_t MAJOR : 4; /* [7:4] r */ + uint32_t RSVD_31_8 :24; /* [31:8] r */ + } TDG_VERID; + + /* 0x4*/ + struct { + uint32_t DOPNUM : 4; /* [3:0] r */ + uint32_t CHNUM : 4; /* [7:4] r */ + uint32_t RSVD_31_8 :24; /* [31:8] r */ + } TDG_PARAM; + + /* 0x8*/ + struct { + uint32_t TDGEN : 1; /* [0] r/w */ + uint32_t RSVD_3_1 : 3; /* [3:1] */ + uint32_t TRIGS : 1; /* [4] r/w */ + uint32_t CNTMD : 1; /* [5] r/w */ + uint32_t CLRMD : 1; /* [6] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t PRES : 3; /* [10:8] r/w */ + uint32_t RSVD_15_11 : 5; /* [15:11] r */ + uint32_t CFGUP : 1; /* [16] r/w */ + uint32_t SWTRG : 1; /* [17] r/w */ + uint32_t RSVD_19_18 : 2; /* [19:18] */ + uint32_t UPMD : 2; /* [21:20] r */ + uint32_t RSVD_31_22 :10; /* [31:22] r */ + } TDG_CTRL1; + + /* 0xC*/ + struct { + uint32_t CDO0IE : 1; /* [0] r/w */ + uint32_t CDO1IE : 1; /* [1] r/w */ + uint32_t CDO2IE : 1; /* [2] r/w */ + uint32_t CDO3IE : 1; /* [3] r/w */ + uint32_t CDO4IE : 1; /* [4] r/w */ + uint32_t CDO5IE : 1; /* [5] r/w */ + uint32_t RSVD_7_6 : 2; /* [7:6] r */ + uint32_t ERRIE : 1; /* [8] r/w */ + uint32_t RSVD_15_9 : 7; /* [15:9] r */ + uint32_t CH0E : 1; /* [16] r/w */ + uint32_t CH1E : 1; /* [17] r/w */ + uint32_t CH2E : 1; /* [18] r/w */ + uint32_t CH3E : 1; /* [19] r/w */ + uint32_t CH4E : 1; /* [20] r/w */ + uint32_t CH5E : 1; /* [21] r/w */ + uint32_t RSVD_31_22 :10; /* [31:22] r */ + } TDG_CTRL2; + + /* 0x10*/ + struct { + uint32_t CDO0IF : 1; /* [0] r/w */ + uint32_t CDO1IF : 1; /* [1] r/w */ + uint32_t CDO2IF : 1; /* [2] r/w */ + uint32_t CDO3IF : 1; /* [3] r/w */ + uint32_t CDO4IF : 1; /* [4] r/w */ + uint32_t CDO5IF : 1; /* [5] r/w */ + uint32_t RSVD_7_6 : 2; /* [7:6] */ + uint32_t ERRIF : 1; /* [8] r/w */ + uint32_t RSVD_31_9 :23; /* [31:9] */ + } TDG_STAT; + + /* 0x14*/ + struct { + uint32_t MOD :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] r */ + } TDG_MOD; + + /* 0x18*/ + struct { + uint32_t CNT :16; /* [15:0] r */ + uint32_t RSVD_31_16 :16; /* [31:16] r */ + } TDG_CNT; + + /* 0x1C*/ + struct { + struct { + uint32_t RSVD_7_0 : 8; /* [7:0] */ + uint32_t DO0E : 1; /* [8] r/w */ + uint32_t DO1E : 1; /* [9] r/w */ + uint32_t DO2E : 1; /* [10] r/w */ + uint32_t DO3E : 1; /* [11] r/w */ + uint32_t DO4E : 1; /* [12] r/w */ + uint32_t DO5E : 1; /* [13] r/w */ + uint32_t DO6E : 1; /* [14] r/w */ + uint32_t DO7E : 1; /* [15] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } TDG_CHCTRL; + + /* 0x20 - 0x3F*/ + struct { + uint32_t DO0OFS :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] r */ + } TDG_CHDOOFS[8]; + + /* 0x40*/ + struct { + uint32_t CDOINTDLY :10; /* [9:0] r/w */ + uint32_t RSVD_15_10 : 6; /* [15:10] r */ + uint32_t LDCO : 1; /* [16] r/w */ + uint32_t RSVD_31_17 :15; /* [31:17] r */ + } TDG_CHDOCINTDLY; + + } TDG_CHCFG[6]; +}; /*tdg_reg*/ + +struct tdg_reg_w { + /* 0x0*/ + uint32_t TDG_VERID; + /* 0x4*/ + uint32_t TDG_PARAM; + /* 0x8*/ + uint32_t TDG_CTRL1; + /* 0xC*/ + uint32_t TDG_CTRL2; + /* 0x10*/ + uint32_t TDG_STAT; + /* 0x14*/ + uint32_t TDG_MOD; + /* 0x18*/ + uint32_t TDG_CNT; + + struct { + /* 0x1C */ + uint32_t TDG_CHCTRL; + /* 0x20 - 0x3F*/ + uint32_t TDG_CHDOOFS[8]; + /* 0x40*/ + uint32_t TDG_CHDOCINTDLY; + }TDG_CHCFG[6]; + +}; /*tdg_reg*/ + +typedef volatile struct tdg_reg tdg_reg_t; +typedef volatile struct tdg_reg_w tdg_reg_w_t; + +struct tim_reg { + /* 0x00*/ + struct { + uint32_t CKSRC : 2; /* [1:0] r/w */ + uint32_t PSDIV : 3; /* [4:2] r/w */ + uint32_t DBGM : 2; /* [6:5] r/w */ + uint32_t RSVD_31_7 :25; /* [31:7] */ + } TIM_TIMEBASE; + + /* 0x04*/ + struct { + uint32_t CNT :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } TIM_CNT; + + /* 0x08*/ + struct { + uint32_t CNTINIT :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } TIM_CNTINIT; + + /* 0x0C*/ + struct { + uint32_t MOD :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } TIM_MOD; + + /* 0x10*/ + struct { + uint32_t CHOE0 : 1; /* [0] r/w */ + uint32_t CHOE1 : 1; /* [1] r/w */ + uint32_t CHOE2 : 1; /* [2] r/w */ + uint32_t CHOE3 : 1; /* [3] r/w */ + uint32_t CHOE4 : 1; /* [4] r/w */ + uint32_t CHOE5 : 1; /* [5] r/w */ + uint32_t CHOE6 : 1; /* [6] r/w */ + uint32_t CHOE7 : 1; /* [7] r/w */ + uint32_t RLDIE : 1; /* [8] r/w */ + uint32_t TOIE : 1; /* [9] r/w */ + uint32_t CNTMODE : 1; /* [10] r/w */ + uint32_t INIT : 1; /* [11] w/o */ + uint32_t RSVD_31_12 :20; /* [31:12] */ + } TIM_GLBCR; + + /* 0x14*/ + struct { + uint32_t CH0F : 1; /* [0] r/o */ + uint32_t CH1F : 1; /* [1] r/o */ + uint32_t CH2F : 1; /* [2] r/o */ + uint32_t CH3F : 1; /* [3] r/o */ + uint32_t CH4F : 1; /* [4] r/o */ + uint32_t CH5F : 1; /* [5] r/o */ + uint32_t CH6F : 1; /* [6] r/o */ + uint32_t CH7F : 1; /* [7] r/o */ + uint32_t RLDF : 1; /* [8] r/o */ + uint32_t TOF : 1; /* [9] r/o */ + uint32_t WPDIS : 1; /* [10] r/w */ + uint32_t RSVD_31_11 :21; /* [31:11] */ + } TIM_GLBSR; + + /* 0x18*/ + struct { + uint32_t ELS : 2; /* [1:0] r/w */ + uint32_t CMS : 2; /* [3:2] r/w */ + uint32_t CHIE : 1; /* [4] r/w */ + uint32_t CHF : 1; /* [5] r/o */ + uint32_t DMAEN : 1; /* [6] r/w */ + uint32_t ICRST : 1; /* [7] r/w */ + uint32_t RSVD_31_8 :24; /* [31:8] */ + } TIM_CMCn[8]; + + /* 0x38*/ + struct { + uint32_t CCV :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } TIM_CCVn[8]; + + /* 0x58*/ + struct { + uint32_t INIT0 : 1; /* [0] r/w */ + uint32_t INIT1 : 1; /* [1] r/w */ + uint32_t INIT2 : 1; /* [2] r/w */ + uint32_t INIT3 : 1; /* [3] r/w */ + uint32_t INIT4 : 1; /* [4] r/w */ + uint32_t INIT5 : 1; /* [5] r/w */ + uint32_t INIT6 : 1; /* [6] r/w */ + uint32_t INIT7 : 1; /* [7] r/w */ + uint32_t POL0 : 1; /* [8] r/w */ + uint32_t POL1 : 1; /* [9] r/w */ + uint32_t POL2 : 1; /* [10] r/w */ + uint32_t POL3 : 1; /* [11] r/w */ + uint32_t POL4 : 1; /* [12] r/w */ + uint32_t POL5 : 1; /* [13] r/w */ + uint32_t POL6 : 1; /* [14] r/w */ + uint32_t POL7 : 1; /* [15] r/w */ + uint32_t TRIGE0 : 1; /* [16] r/w */ + uint32_t TRIGE1 : 1; /* [17] r/w */ + uint32_t TRIGE2 : 1; /* [18] r/w */ + uint32_t TRIGE3 : 1; /* [19] r/w */ + uint32_t TRIGE4 : 1; /* [20] r/w */ + uint32_t TRIGE5 : 1; /* [21] r/w */ + uint32_t TRIGE6 : 1; /* [22] r/w */ + uint32_t TRIGE7 : 1; /* [23] r/w */ + uint32_t INITRIGE : 1; /* [24] r/w */ + uint32_t TRIGF : 1; /* [25] r/o */ + uint32_t RSVD_31_26 : 6; /* [31:26] */ + } TIM_OUTCR; + + /* 0x5C*/ + struct { + uint32_t CH0OC : 1; /* [0] r/w */ + uint32_t CH1OC : 1; /* [1] r/w */ + uint32_t CH2OC : 1; /* [2] r/w */ + uint32_t CH3OC : 1; /* [3] r/w */ + uint32_t CH4OC : 1; /* [4] r/w */ + uint32_t CH5OC : 1; /* [5] r/w */ + uint32_t CH6OC : 1; /* [6] r/w */ + uint32_t CH7OC : 1; /* [7] r/w */ + uint32_t CH0OCV : 1; /* [8] r/w */ + uint32_t CH1OCV : 1; /* [9] r/w */ + uint32_t CH2OCV : 1; /* [10] r/w */ + uint32_t CH3OCV : 1; /* [11] r/w */ + uint32_t CH4OCV : 1; /* [12] r/w */ + uint32_t CH5OCV : 1; /* [13] r/w */ + uint32_t CH6OCV : 1; /* [14] r/w */ + uint32_t CH7OCV : 1; /* [15] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } TIM_OUTSWCR; + + /* 0x60*/ + struct { + uint32_t FCTLEN0 : 1; /* [0] r/w */ + uint32_t DTEN0 : 1; /* [1] r/w */ + uint32_t COMB0 : 1; /* [2] r/w */ + uint32_t SYNCEN0 : 1; /* [3] r/w */ + uint32_t DECAPEN0 : 1; /* [4] r/w */ + uint32_t DECAP0 : 1; /* [5] r/w */ + uint32_t RSVD_7_6 : 2; /* [7:6] */ + uint32_t FCTLEN1 : 1; /* [8] r/w */ + uint32_t DTEN1 : 1; /* [9] r/w */ + uint32_t COMB1 : 1; /* [10] r/w */ + uint32_t SYNCEN1 : 1; /* [11] r/w */ + uint32_t DECAPEN1 : 1; /* [12] r/w */ + uint32_t DECAP1 : 1; /* [13] r/w */ + uint32_t RSVD_15_14 : 2; /* [15:14] */ + uint32_t FCTLEN2 : 1; /* [16] r/w */ + uint32_t DTEN2 : 1; /* [17] r/w */ + uint32_t COMB2 : 1; /* [18] r/w */ + uint32_t SYNCEN2 : 1; /* [19] r/w */ + uint32_t DECAPEN2 : 1; /* [20] r/w */ + uint32_t DECAP2 : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] */ + uint32_t FCTLEN3 : 1; /* [24] r/w */ + uint32_t DTEN3 : 1; /* [25] r/w */ + uint32_t COMB3 : 1; /* [26] r/w */ + uint32_t SYNCEN3 : 1; /* [27] r/w */ + uint32_t DECAPEN3 : 1; /* [28] r/w */ + uint32_t DECAP3 : 1; /* [29] r/w */ + uint32_t RSVD_31_30 : 2; /* [31:30] */ + } TIM_PCR; + + /* 0x64*/ + struct { + uint32_t FILVAL0 : 4; /* [3:0] r/w */ + uint32_t FILVAL1 : 4; /* [7:4] r/w */ + uint32_t FILVAL2 : 4; /* [11:8] r/w */ + uint32_t FILVAL3 : 4; /* [15:12] r/w */ + uint32_t DTPS : 2; /* [17:16] r/w */ + uint32_t DTVAL : 6; /* [23:18] r/w */ + uint32_t RSVD_31_24 : 8; /* [31:24] */ + } TIM_FILTER; + + /* 0x68*/ + struct { + uint32_t FAULTEN0 : 1; /* [0] r/w */ + uint32_t FIFEN0 : 1; /* [1] r/w */ + uint32_t FLTPOL0 : 1; /* [2] r/w */ + uint32_t FAULTEN1 : 1; /* [3] r/w */ + uint32_t FIFEN1 : 1; /* [4] r/w */ + uint32_t FLTPOL1 : 1; /* [5] r/w */ + uint32_t FLTIE : 1; /* [6] r/w */ + uint32_t FLTCEN : 1; /* [7] r/w */ + uint32_t FLTCM : 1; /* [8] r/w */ + uint32_t RSVD_10_9 : 2; /* [10:9] */ + uint32_t FIFVAL : 4; /* [14:11] r/w */ + uint32_t FSTATE : 1; /* [15] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } TIM_FLTCR; + + /* 0x6C*/ + struct { + uint32_t FAULTF0 : 1; /* [0] r/o */ + uint32_t FAULTF1 : 1; /* [1] r/o */ + uint32_t RSVD_3_2 : 2; /* [3:2] */ + uint32_t FAULTF : 1; /* [4] r/o */ + uint32_t FAULTIN : 1; /* [5] r/o */ + uint32_t WPEN : 1; /* [6] r/w */ + uint32_t RSVD_31_7 :25; /* [31:7] */ + } TIM_FLTSR; + + /* 0x70*/ + struct { + uint32_t SWTRIG : 1; /* [0] r/w */ + uint32_t RSVD_7_1 : 7; /* [7:1] */ + uint32_t SYNCINIT : 1; /* [8] r/w */ + uint32_t SYNCOSWC : 1; /* [9] r/w */ + uint32_t RSVD_17_10 : 8; /* [17:10] */ + uint32_t SWWRBUF : 1; /* [18] r/w */ + uint32_t SWRSTCNT : 1; /* [19] r/w */ + uint32_t RSVD_31_20 :12; /* [31:20] */ + } TIM_SYNC; + + /* 0x74*/ + struct { + uint32_t CH0SEL : 1; /* [0] r/w */ + uint32_t CH1SEL : 1; /* [1] r/w */ + uint32_t CH2SEL : 1; /* [2] r/w */ + uint32_t CH3SEL : 1; /* [3] r/w */ + uint32_t CH4SEL : 1; /* [4] r/w */ + uint32_t CH5SEL : 1; /* [5] r/w */ + uint32_t CH6SEL : 1; /* [6] r/w */ + uint32_t CH7SEL : 1; /* [7] r/w */ + uint32_t LOADEN : 1; /* [8] r/w */ + uint32_t RSVD_10_9 : 2; /* [10:9] */ + uint32_t HCSEL : 1; /* [11] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] */ + uint32_t LDFREQ : 5; /* [20:16] r/w */ + uint32_t RSVD_31_21 :11; /* [31:21] */ + } TIM_RELOAD; + + /* 0x78*/ + struct { + uint32_t HCV :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } TIM_HCV; + +}; /*tim_reg*/ + +struct tim_reg_w { + /* 0x00*/ + uint32_t TIM_TIMEBASE; + /* 0x04*/ + uint32_t TIM_CNT; + /* 0x08*/ + uint32_t TIM_CNTINIT; + /* 0x0C*/ + uint32_t TIM_MOD; + /* 0x10*/ + uint32_t TIM_GLBCR; + /* 0x14*/ + uint32_t TIM_GLBSR; + /* 0x18*/ + uint32_t TIM_CMCn[8]; + /* 0x38*/ + uint32_t TIM_CCVn[8]; + /* 0x58*/ + uint32_t TIM_OUTCR; + /* 0x5C*/ + uint32_t TIM_OUTSWCR; + /* 0x60*/ + uint32_t TIM_PCR; + /* 0x64*/ + uint32_t TIM_FILTER; + /* 0x68*/ + uint32_t TIM_FLTCR; + /* 0x6C*/ + uint32_t TIM_FLTSR; + /* 0x70*/ + uint32_t TIM_SYNC; + /* 0x74*/ + uint32_t TIM_RELOAD; + /* 0x78*/ + uint32_t TIM_HCV; +}; /*tim_reg*/ + +typedef volatile struct tim_reg tim_reg_t; +typedef volatile struct tim_reg_w tim_reg_w_t; + +struct tmu_reg { + /* 0x0*/ + struct { + uint32_t SEL : 6; /* [5:0] r/w */ + uint32_t RSVD_6 : 1; /* [6] ro */ + uint32_t EN : 1; /* [7] r/w */ + uint32_t RSVD_30_8 :23; /* [30:8] ro */ + uint32_t LOCK : 1; /* [31] r/w */ + } TMU_CFGn[40]; + +}; /*tmu_reg*/ + +struct tmu_reg_w { + /* 0x0*/ + uint32_t TMU_CFGn[40]; +}; /*tmu_reg*/ + +typedef volatile struct tmu_reg tmu_reg_t; +typedef volatile struct tmu_reg_w tmu_reg_w_t; + +struct uart_reg { + /* 0x0*/ + union { + struct { + uint32_t RBR_LSB : 8; /* [7:0] ro */ + uint32_t RBR_MSB : 1; /* [8] ro */ + uint32_t RSVD_31_9 :23; /* [31:9] */ + } UART_RBR; + struct { + uint32_t THR_LSB : 8; /* [7:0] wo */ + uint32_t THR_MSB : 1; /* [8] wo */ + uint32_t RSVD_31_9 :23; /* [31:9] */ + } UART_THR; + struct { + uint32_t DL_L : 8; /* [7:0] r/w */ + uint32_t RSVD_31_8 :24; /* [31:8] */ + } UART_DLL; + } UART_RBR_THR_DLL; + + /* 0x4*/ + union { + struct { + uint32_t DL_H : 8; /* [7:0] r/w */ + uint32_t RSVD_31_8 :24; /* [31:8] */ + } UART_DLH; + struct { + uint32_t ERBFI : 1; /* [0] r/w */ + uint32_t ETBEI : 1; /* [1] r/w */ + uint32_t ELSI : 1; /* [2] r/w */ + uint32_t RSVD_6_3 : 4; /* [6:3] r/w */ + uint32_t PTIME : 1; /* [7] r/w */ + uint32_t HEADER_DONE_INT_EN : 1; /* [8] r/w */ + uint32_t RSP_DONE_INT_EN : 1; /* [9] r/w */ + uint32_t ASYNC_INT_EN : 1; /* [10] r/w */ + uint32_t RSVD_31_11 :21; /* [31:11] */ + } UART_IER; + } UART_DLH_IER; + + /* 0x8*/ + union { + struct { + uint32_t IID : 4; /* [3:0] ro */ + uint32_t RSVD_5_4 : 2; /* [5:4] */ + uint32_t FIFOSE : 2; /* [7:6] ro */ + uint32_t RSVD_31_8 :24; /* [31:8] */ + } UART_IIR; + struct { + uint32_t FIFOE : 1; /* [0] wo */ + uint32_t RFIFOR : 1; /* [1] wo */ + uint32_t XFIFOR : 1; /* [2] wo */ + uint32_t RSVD_3 : 1; /* [3] wo */ + uint32_t TET : 2; /* [5:4] wo */ + uint32_t RCVR : 2; /* [7:6] wo */ + uint32_t RSVD_31_8 :24; /* [31:8] */ + } UART_FCR; + } UART_IIR_FCR; + + /* 0xC*/ + struct { + uint32_t DLS : 2; /* [1:0] r/w */ + uint32_t STOP : 1; /* [2] r/w */ + uint32_t PEN : 1; /* [3 ] r/w */ + uint32_t EPS : 1; /* [4] r/w */ + uint32_t STP : 1; /* [5 ] r/w */ + uint32_t BC : 1; /* [6] r/w */ + uint32_t DLAB : 1; /* [7] r/w */ + uint32_t LBKEN : 1; /* [8] r/w */ + uint32_t LBKM : 5; /* [13:9] r/w */ + uint32_t IDLE_DET_LENGTH : 3; /* [16:14] r/w */ + uint32_t IDLE_DET_EN : 1; /* [17] r/w */ + uint32_t AUTO_SYNC_EN : 1; /* [18] r/w */ + uint32_t DEBUG_EN : 1; /* [19] r/w */ + uint32_t RSVD_31_20 :12; /* [31:20] */ + } UART_LCR; + + /* 0x10*/ + struct { + uint32_t RSVD_0 : 1; /* [0] */ + uint32_t RTS : 1; /* [1] r/w */ + uint32_t RSVD_2 : 1; /* [2] */ + uint32_t RSVD_3 : 1; /* [3 ] */ + uint32_t LB : 1; /* [4] r/w */ + uint32_t AFCE : 1; /* [5 ] r/w */ + uint32_t RSVD_6 : 1; /* [6] r/w */ + uint32_t RSVD_31_7 :25; /* [31:7] */ + } UART_AFCR; + + /* 0x14*/ + struct { + uint32_t DR : 1; /* [0] ro */ + uint32_t OE : 1; /* [1] ro */ + uint32_t PE : 1; /* [2] ro */ + uint32_t FE : 1; /* [3 ] ro */ + uint32_t BI : 1; /* [4] ro */ + uint32_t THRE : 1; /* [5 ] ro */ + uint32_t TEMT : 1; /* [6] ro */ + uint32_t RFE : 1; /* [7] ro */ + uint32_t ADDR_RCVD : 1; /* [8] ro */ + uint32_t ASYNC_INT : 1; /* [9] ro */ + uint32_t SYNC_FIELD_ERROR : 1; /* [10] ro */ + uint32_t PID_ERR : 1; /* [11] ro */ + uint32_t CHECKSUM_ERROR : 1; /* [12] ro */ + uint32_t TO_ERROR : 1; /* [13] ro */ + uint32_t HEADER_OP_DONE : 1; /* [14] ro */ + uint32_t RSP_OP_DONE : 1; /* [15] ro */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } UART_LSR; + + uint8_t zResverd0x018[100]; /*pad 0x018 - 07B*/ + + /* 0x7C*/ + struct { + uint32_t BUSY : 1; /* [0] ro */ + uint32_t RSVD_4_1 : 4; /* [4:1] */ + uint32_t RSVD_31_5 :27; /* [31:5] */ + } UART_USR; + + uint8_t zResverd0x080[40]; /*pad 0x080 - 0A7*/ + + /* 0xA8*/ + struct { + uint32_t RSVD_0 : 1; /* [0] wo */ + uint32_t RSVD_31_1 :31; /* [31:1] */ + } UART_DMA_SA; + + uint8_t zResverd0x0AC[20]; /*pad 0x0AC - 0BF*/ + + /* 0xC0*/ + struct { + uint32_t FD : 4; /* [3:0] r/w */ + uint32_t RSVD_31_4 :28; /* [31:4] */ + } UART_FD; + + /* 0xC4*/ + struct { + uint32_t RAR : 8; /* [7:0] r/w */ + uint32_t RSVD_31_8 :24; /* [31:8] */ + } UART_RAR; + + /* 0xC8*/ + struct { + uint32_t TAR : 8; /* [7:0] r/w */ + uint32_t RSVD_31_8 :24; /* [31:8] */ + } UART_TAR; + + /* 0xCC*/ + struct { + uint32_t DLS_E : 1; /* [0] r/w */ + uint32_t ADDR_MATCH : 1; /* [1] r/w */ + uint32_t SEND_ADDR : 1; /* [2] r/w */ + uint32_t TRANSMIST_MODE : 1; /* [3] r/w */ + uint32_t RSVD_31_4 :28; /* [31:4] */ + } UART_LCR_EXT; + + uint8_t zResverd0x0D0[48]; /*pad 0x0D0 - 0FF*/ + + /* 0x100*/ + struct { + uint32_t LIN_MODE : 1; /* [0] r/w */ + uint32_t MASTER_MODE : 1; /* [1] r/w */ + uint32_t HEADER_OP_START : 1; /* [2] r/w */ + uint32_t RSP_OP_START : 1; /* [3 ] r/w */ + uint32_t RSP_DIR : 1; /* [4] r/w */ + uint32_t RSVD_31_5 :27; /* [31:5] */ + } UART_LIN_CTL; + + /* 0x104*/ + struct { + uint32_t RSP_LENGTH : 4; /* [3:0] r/w */ + uint32_t RSVD_31_4 :28; /* [31:4] */ + } UART_LIN_RSP_LENGTH; + + /* 0x108*/ + struct { + uint32_t PID : 6; /* [5:0] r/w */ + uint32_t RSVD_31_6 :26; /* [31:6] */ + } UART_LIN_PID_VALUE; + + /* 0x10C*/ + struct { + uint32_t CHECKSUM_TYPE : 1; /* [0] r/w */ + uint32_t RSVD_7_1 : 7; /* [7:1] */ + uint32_t RSVD_31_8 :24; /* [31:8] */ + } UART_LIN_CHECKSUM; + + /* 0x110*/ + struct { + uint32_t LIN_DEL_LENGTH : 3; /* [2:0] r/w */ + uint32_t RSVD_31_3 :29; /* [31:3] */ + } UART_LIN_DEL_LENGTH; + + uint8_t zResverd0x114[24]; /* pad 0x114 - 12B */ + +}; /*uart_reg*/ + +struct uart_reg_w { + /* 0x0*/ + union { + uint32_t UART_RBR; + uint32_t UART_THR; + uint32_t UART_DLL; + }UART_RBR_THR_DLL; + /* 0x4*/ + union { + uint32_t UART_DLH; + uint32_t UART_IER; + }UART_DLH_IER; + /* 0x8*/ + union { + uint32_t UART_IIR; + uint32_t UART_FCR; + }UART_IIR_FCR; + /* 0xC*/ + uint32_t UART_LCR; + /* 0x10*/ + uint32_t UART_AFCR; + /* 0x14*/ + uint32_t UART_LSR; + /* 0x18*/ + uint32_t UART_MSR; + uint8_t zResverd0x01C[96]; /*pad 0x01C - 07B*/ + + /* 0x7C*/ + uint32_t UART_USR; + uint8_t zResverd0x080[40]; /*pad 0x080 - 0A7*/ + + /* 0xA8*/ + uint32_t UART_DMA_SA; + uint8_t zResverd0x0AC[20]; /*pad 0x0AC - 0BF*/ + + /* 0xC0*/ + uint32_t UART_FD; + /* 0xC4*/ + uint32_t UART_RAR; + /* 0xC8*/ + uint32_t UART_TAR; + /* 0xCC*/ + uint32_t UART_LCR_EXT; + uint8_t zResverd0x0D0[48]; /*pad 0x0D0 - 0FF*/ + + /* 0x100*/ + uint32_t UART_LIN_CTL; + /* 0x104*/ + uint32_t UART_LIN_RSP_LENGTH; + /* 0x108*/ + uint32_t UART_LIN_PID_VALUE; + /* 0x10C*/ + uint32_t UART_LIN_CHECKSUM; + /* 0x110*/ + uint32_t UART_LIN_DEL_LENGTH; + + uint8_t zResverd0x114[24]; /* pad 0x114 - 12B */ + +}; /*uart_reg*/ + +typedef volatile struct uart_reg uart_reg_t; +typedef volatile struct uart_reg_w uart_reg_w_t; + +struct wdog_reg { + /* 0x0*/ + struct { + uint32_t MINOR : 4; /* [3:0] ro */ + uint32_t MAJOR : 4; /* [7:4] ro */ + uint32_t RSVD_31_8 :24; /* [31:8] ro */ + } WDOG_VERID; + + /* 0x4*/ + struct { + uint32_t INT_PRESENT : 1; /* [0] ro */ + uint32_t RSVD_31_1 :31; /* [31:1] ro */ + } WDOG_PARAM; + + /* 0x8*/ + struct { + uint32_t WDOGE : 1; /* [0] r/w */ + uint32_t DEBUGE : 1; /* [1] r/w */ + uint32_t WAITE : 1; /* [2] r/w */ + uint32_t STOPE : 1; /* [3] r/w */ + uint32_t INTE : 1; /* [4] r/w */ + uint32_t WINE : 1; /* [5] r/w */ + uint32_t CFGUA : 1; /* [6] r/w */ + uint32_t RSVD_7 : 1; /* [7] ro */ + uint32_t CLKS : 2; /* [9:8] r/w */ + uint32_t RSVD_15_10 : 6; /* [15:10] ro */ + uint32_t TSTM : 3; /* [18:16] r/w */ + uint32_t RSVD_23_19 : 5; /* [23:19] ro */ + uint32_t CFGUF : 1; /* [24] ro */ + uint32_t UNLKF : 1; /* [25] ro */ + uint32_t INTF : 1; /* [26] r/w */ + uint32_t RSVD_31_27 : 5; /* [31:27] ro */ + } WDOG_CS; + + /* 0xC*/ + struct { + uint32_t TMO :32; /* [31:0] r/w */ + } WDOG_TMO; + + /* 0x10*/ + struct { + uint32_t WIN :32; /* [31:0] r/w */ + } WDOG_WIN; + + /* 0x14*/ + struct { + uint32_t CNT :32; /* [31:0] r/w */ + } WDOG_CNT; + +}; /*wdog_reg*/ + +struct wdog_reg_w { + /* 0x0*/ + uint32_t WDOG_VERID; + /* 0x4*/ + uint32_t WDOG_PARAM; + /* 0x8*/ + uint32_t WDOG_CS; + /* 0xC*/ + uint32_t WDOG_TMO; + /* 0x10*/ + uint32_t WDOG_WIN; + /* 0x14*/ + uint32_t WDOG_CNT; +}; /*wdog_reg*/ + +typedef volatile struct wdog_reg wdog_reg_t; +typedef volatile struct wdog_reg_w wdog_reg_w_t; +#endif /*Z20K114M_H*/ diff --git a/Platform/Devices/Z20K114M/MakeRule/ARMC/Z20K114M_flash.scf b/Platform/Devices/Z20K114M/MakeRule/ARMC/Z20K114M_flash.scf new file mode 100644 index 0000000..728bd10 --- /dev/null +++ b/Platform/Devices/Z20K114M/MakeRule/ARMC/Z20K114M_flash.scf @@ -0,0 +1,27 @@ +#! armclang --target=arm-arm-none-eabi -mcpu=cortex-m0plus -xc -E +; ************************************************************* +; *** Scatter-Loading Description File *** +; ************************************************************* + +#define pflash_start 0x00000000 +#define pflash_size 0x00010000 /* 64KB */ + +#define ram0_start 0x20000000 +#define ram0_size 0x00002000 /* 8KB */ +#define ram0_end ram0_start + ram0_size + +LR_IROM1 pflash_start pflash_size { ; load region size_region + ER_IROM1 pflash_start pflash_size { ; load address = execution address + *.o (.intvec, +First) + *(InRoot$$Sections) + .ANY (+RO) + } + + RAM_START ram0_start ram0_size { ; code execution in ram + .ANY (.code_ram) + .ANY (+RW +ZI) + } + + ARM_LIB_STACK ram0_end EMPTY -0x400 {}; Stack region growing down + ARM_LIB_HEAP ImageBase(ARM_LIB_STACK) EMPTY -0x200 {} ; heap region +} diff --git a/Platform/Devices/Z20K114M/MakeRule/ARMC/Z20K114M_sram.scf b/Platform/Devices/Z20K114M/MakeRule/ARMC/Z20K114M_sram.scf new file mode 100644 index 0000000..404d78a --- /dev/null +++ b/Platform/Devices/Z20K114M/MakeRule/ARMC/Z20K114M_sram.scf @@ -0,0 +1,20 @@ +#! armclang --target=arm-arm-none-eabi -mcpu=cortex-m0plus -xc -E +; ************************************************************* +; *** Scatter-Loading Description File *** +; ************************************************************* + +#define ram0_start 0x20000000 +#define ram0_size 0x00002000 /* 8KB */ +#define ram0_end ram0_start + ram0_size + +LR_IROM1 ram0_start ram0_size { ; load region size_region + RAM_START ram0_start ram0_size { ; load address = execution address + *.o (.intvec, +First) + *(InRoot$$Sections) + .ANY (+RO +RW +ZI) + } + + ARM_LIB_STACK ram0_end EMPTY -0x400 {}; Stack region growing down + ARM_LIB_HEAP ImageBase(ARM_LIB_STACK) EMPTY -0x200 {} ; heap region +} + diff --git a/Platform/Devices/Z20K114M/MakeRule/GCC/Z20K114M_flash.ld b/Platform/Devices/Z20K114M/MakeRule/GCC/Z20K114M_flash.ld new file mode 100644 index 0000000..5728e8b --- /dev/null +++ b/Platform/Devices/Z20K114M/MakeRule/GCC/Z20K114M_flash.ld @@ -0,0 +1,99 @@ +VECTOR_BASE = 0x00000000; + +HEAP_SIZE = DEFINED(__heap_size__) ? __heap_size__ : 0x00000200; +CSTACK_SIZE = DEFINED(__stack_size__) ? __stack_size__ : 0x00000400; + +MEMORY +{ + FLASH (xr) : ORIGIN = 0x00000000, LENGTH = 0x00010000 + RAM1 (xrw) : ORIGIN = 0x20000000, LENGTH = 0x00002000 +} + +/* Entry Point */ +ENTRY(Reset_Handler) + + +/* Sections Definitions */ + +SECTIONS +{ + .isr_vector : + { + . = ALIGN(4); + KEEP(*(.intvec)) /* Startup code */ + . = ALIGN(4); + } > FLASH + + .rom : ALIGN(4) + { + . = ALIGN(4); + *(.text) /* .text sections (code) */ + *(.text*) /* .text* sections (code) */ + *(.rodata) /* .rodata sections (constants, strings, etc.) */ + *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ + *(.glue_7) /* glue arm to thumb code */ + *(.glue_7t) /* glue thumb to arm code */ + *(.eh_frame) + KEEP (*(.init)) + KEEP (*(.fini)) + . = ALIGN(4); + } > FLASH + + __TEXT_END = .; /* global symbol at end of code */ + __DATA_ROM = .; /* Symbol used for startup for data initialization */ + + .data : AT(__DATA_ROM) + { + . = ALIGN(4); + __DATA_RAM = .; + __data_start__ = .; /* create a global symbol at data start */ + *(.data) /* .data sections */ + *(.data*) /* .data* sections */ + *(.code_ram) /*Custom section for storing code in SRAM*/ + KEEP(*(.jcr*)) + . = ALIGN(4); + __data_end__ = .; /* define a global symbol at data end */ + } > RAM1 + + __DATA_END = __DATA_ROM + SIZEOF(.data); + + .bss : + { + /* This is used by the startup in order to initialize the .bss section */ + . = ALIGN(4); + __START_BSS = .; + __bss_start__ = .; + *(.bss) + *(.bss*) + *(COMMON) + . = ALIGN(4); + __bss_end__ = .; + __END_BSS = .; + } > RAM1 + + .heap : + { + . = ALIGN(8); + __end__ = .; + PROVIDE(end = .); + __HeapBase = .; + . += HEAP_SIZE; + __HeapLimit = .; + } > RAM1 + + /* Initializes stack on the end of block */ + __StackTop = ORIGIN(RAM1) + LENGTH(RAM1); + __StackLimit = __StackTop - CSTACK_SIZE; + PROVIDE(CSTACK = __StackTop); + + .stack __StackLimit : + { + . = ALIGN(8); + __stack_start__ = .; + . += CSTACK_SIZE; + __stack_end__ = .; + } > RAM1 + + __RAM_START = ORIGIN(RAM1); + __RAM_END = __StackTop - 1; +} diff --git a/Platform/Devices/Z20K114M/MakeRule/GCC/Z20K114M_sram.ld b/Platform/Devices/Z20K114M/MakeRule/GCC/Z20K114M_sram.ld new file mode 100644 index 0000000..e66ce1c --- /dev/null +++ b/Platform/Devices/Z20K114M/MakeRule/GCC/Z20K114M_sram.ld @@ -0,0 +1,100 @@ +VECTOR_BASE = 0x20000000; + +HEAP_SIZE = DEFINED(__heap_size__) ? __heap_size__ : 0x00000200; +CSTACK_SIZE = DEFINED(__stack_size__) ? __stack_size__ : 0x00000400; + +MEMORY +{ + RAM1 (xrw) : ORIGIN = 0x20000000, LENGTH = 0x00002000 +} + +/* Entry Point */ +ENTRY(Reset_Handler) + + +/* Sections Definitions */ + +SECTIONS +{ + + /* The startup code goes first into internal RAM */ + .isr_vector : + { + . = ALIGN(4); + KEEP(*(.intvec)) /* Startup code */ + . = ALIGN(4); + } > RAM1 + + + .rom : ALIGN(4) + { + . = ALIGN(4); + *(.text) /* .text sections (code) */ + *(.text*) /* .text* sections (code) */ + *(.rodata) /* .rodata sections (constants, strings, etc.) */ + *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ + *(.glue_7) /* glue arm to thumb code */ + *(.glue_7t) /* glue thumb to arm code */ + *(.eh_frame) + KEEP (*(.init)) + KEEP (*(.fini)) + . = ALIGN(4); + } > RAM1 + + __TEXT_END = .; /* global symbol at end of code */ + __DATA_ROM = .; /* Symbol used for startup for data initialization */ + + + .data : AT(__DATA_ROM) + { + . = ALIGN(4); + __DATA_RAM = .; + __data_start__ = .; /* create a global symbol at data start */ + *(.data) /* .data sections */ + *(.data*) /* .data* sections */ + KEEP(*(.jcr*)) + . = ALIGN(4); + __data_end__ = .; /* define a global symbol at data end */ + } > RAM1 + + __DATA_END = __DATA_ROM + SIZEOF(.data); + + .bss : + { + /* This is used by the startup in order to initialize the .bss section */ + . = ALIGN(4); + __START_BSS = .; + __bss_start__ = .; + *(.bss) + *(.bss*) + *(COMMON) + . = ALIGN(4); + __bss_end__ = .; + __END_BSS = .; + } > RAM1 + + .heap : + { + . = ALIGN(8); + __end__ = .; + PROVIDE(end = .); + __HeapBase = .; + . += HEAP_SIZE; + __HeapLimit = .; + __heap_limit = .; + } > RAM1 + + /* Initializes stack on the end of block */ + __StackTop = ORIGIN(RAM1) + LENGTH(RAM1); + __StackLimit = __StackTop - CSTACK_SIZE; + PROVIDE(CSTACK = __StackTop); + + .stack __StackLimit : + { + . = ALIGN(8); + . += CSTACK_SIZE; + } > RAM1 + + __RAM_START = ORIGIN(RAM1); + __RAM_END = __StackTop - 1; +} diff --git a/Platform/Devices/Z20K114M/MakeRule/IAR/Z20K114M_flash.icf b/Platform/Devices/Z20K114M/MakeRule/IAR/Z20K114M_flash.icf new file mode 100644 index 0000000..aa50242 --- /dev/null +++ b/Platform/Devices/Z20K114M/MakeRule/IAR/Z20K114M_flash.icf @@ -0,0 +1,43 @@ +/*###ICF### Section handled by ICF editor, don't touch! ****/ +/*-Editor annotation file-*/ +/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */ +/*-Specials-*/ +define symbol __ICFEDIT_intvec_start__ = 0x00000000; +/*-Memory Regions-*/ +define symbol __ICFEDIT_region_ROM_start__ = 0x00000000; +define symbol __ICFEDIT_region_ROM_end__ = 0x0000FFFF; /* 64KB */ + +define symbol __ICFEDIT_region_RAM_start__ = 0x20000000; +define symbol __ICFEDIT_region_RAM_end__ = 0x20001FFF; /* 8KB */ + +define symbol __ICFEDIT_size_cstack__ = 0x00000400; +define symbol __ICFEDIT_size_heap__ = 0x00000200; + +/**** End of ICF editor section. ###ICF###*/ + +define exported symbol __RAM_START = __ICFEDIT_region_RAM_start__; +define exported symbol __RAM_END = __ICFEDIT_region_RAM_end__; + +/* memory range */ +define memory mem with size = 4G; + +define region PFLASH_region = mem:[from __ICFEDIT_region_ROM_start__ to __ICFEDIT_region_ROM_end__]; +define region RAM1_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFEDIT_region_RAM_end__]; + +/* definition of RAM blocks */ +define block CSTACK with size = __ICFEDIT_size_cstack__, alignment = 8 { }; +define block HEAP with size = __ICFEDIT_size_heap__, alignment = 8 { }; + +initialize by copy { readwrite }; +do not initialize { section .noinit }; + +place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec }; + +place in PFLASH_region { readonly }; + +place in RAM1_region { section .textrw}; + +place at end of RAM1_region { block HEAP, + block CSTACK }; + +place in RAM1_region { readwrite }; diff --git a/Platform/Devices/Z20K114M/MakeRule/IAR/Z20K114M_sram.icf b/Platform/Devices/Z20K114M/MakeRule/IAR/Z20K114M_sram.icf new file mode 100644 index 0000000..1c7a22e --- /dev/null +++ b/Platform/Devices/Z20K114M/MakeRule/IAR/Z20K114M_sram.icf @@ -0,0 +1,39 @@ +/*###ICF### Section handled by ICF editor, don't touch! ****/ +/*-Editor annotation file-*/ +/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */ +/*-Specials-*/ +define symbol __ICFEDIT_intvec_start__ = 0x20000000; + +define symbol __ICFEDIT_region_RAM_start__ = 0x20000000; +define symbol __ICFEDIT_region_RAM_end__ = 0x20001FFF; /* 8KB */ + +define symbol __ICFEDIT_size_cstack__ = 0x00000400; +define symbol __ICFEDIT_size_heap__ = 0x00000200; + +/**** End of ICF editor section. ###ICF###*/ + +define exported symbol __RAM_START = __ICFEDIT_region_RAM_start__; +define exported symbol __RAM_END = __ICFEDIT_region_RAM_end__; + +/* memory range */ +define memory mem with size = 4G; + +define region RAM1_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFEDIT_region_RAM_end__]; + +/* definition of RAM blocks */ +define block CSTACK with size = __ICFEDIT_size_cstack__, alignment = 8 { }; +define block HEAP with size = __ICFEDIT_size_heap__, alignment = 8 { }; + +initialize by copy { readwrite }; +do not initialize { section .noinit }; + +place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec }; + +place in RAM1_region { readonly }; + +place in RAM1_region { section .textrw}; + +place at end of RAM1_region { block HEAP, + block CSTACK }; + +place in RAM1_region { readwrite }; diff --git a/Platform/Devices/Z20K114M/Startup/ARMC/Z20K114M_startup.s b/Platform/Devices/Z20K114M/Startup/ARMC/Z20K114M_startup.s new file mode 100644 index 0000000..9124453 --- /dev/null +++ b/Platform/Devices/Z20K114M/Startup/ARMC/Z20K114M_startup.s @@ -0,0 +1,428 @@ +; --------------------------------------------------------------------------- +; @file: : Z20K114M_startup.s +; @brief: : Z20K114M startup and Vector Table Source File for ARM Compiler +; @version : V1.8.0 +; @date : May-2020 +; @author : Zhixin Semiconductor +; +; @note +; @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. +; --------------------------------------------------------------------------- + + + PRESERVE8 + THUMB + + + AREA |.text|, CODE, READONLY + EXPORT __vector_table + EXPORT __Vectors_End + EXPORT __Vectors_Size + + IMPORT __main + + IMPORT |Image$$ARM_LIB_STACK$$ZI$$Limit| + + + IF :LNOT: :DEF:START_FROM_SRAM + IMPORT |Image$$RAM_START$$Base| +__RAM_START DCD |Image$$RAM_START$$Base| +__RAM_END DCD |Image$$ARM_LIB_STACK$$ZI$$Limit| + ENDIF + + + AREA |.intvec|, DATA, READONLY +__vector_table + DCD |Image$$ARM_LIB_STACK$$ZI$$Limit| ; Top of Stack + DCD Reset_Handler ; POR Reset Entry + DCD NMI_Handler ; Non Maskable handler + DCD HardFault_Handler ; SV Hard Fault handler + DCD 0 + DCD 0 + DCD 0 + DCD 0 + DCD 0 + DCD 0 + DCD 0 + DCD SVC_Handler ; SV Call handler + DCD 0 + DCD 0 + DCD PendSV_Handler ; Pend SV handler + DCD SysTick_Handler ; System Tick handler + + + DCD DMA0TO3_IRQHandler ; irq 0 : DMA channel 0 - 3 transfer complete IRQHandler + DCD DMA4TO7_IRQHandler ; irq 1 : DMA channel 4 - 7 transfer complete IRQHandler + DCD DMA8TO11_IRQHandler ; irq 2 : DMA channel 8 - 11 transfer complete IRQHandler + DCD DMA12TO15_IRQHandler ; irq 3 : DMA channel 12 - 15 transfer complete IRQHandler + DCD DMAERR_IRQHandler ; irq 4 : DMA error interrupt channels 0-7 IRQHandler + DCD I2C0_IRQHandler ; irq 5 : I2C 0 IRQHandler + DCD Reserved6_IRQHandler ; irq 6 : Reserved Interrupt + DCD SPI0_IRQHandler ; irq 7 : SPI 0 IRQHandler + DCD SPI1_IRQHandler ; irq 8 : SPI 1 IRQHandler + DCD Reserved9_IRQHandler ; irq 9 : Reserved Interrupt + DCD UART0_IRQHandler ; irq 10 : UART 0 IRQHandler + DCD UART1_IRQHandler ; irq 11 : UART 1 IRQHandler + DCD UART2_IRQHandler ; irq 12 : UART2 IRQHandler + DCD Reserved13_IRQHandler ; irq 13 : Reserved Interrupt + DCD ADC0_IRQHandler ; irq 14 : ADC0 IRQHandler + DCD FLASH_IRQHandler ; irq 15 : flash memory IRQHandler + DCD CMP_IRQHandler ; irq 16 : CMP IRQHandler + DCD TIM0_IRQHandler ; irq 17 : TIM 0 IRQHandler + DCD TIM1_IRQHandler ; irq 18 : TIM 1 IRQHandler + DCD TIM2_IRQHandler ; irq 19 : TIM 2 IRQHandler + DCD CAN0_IRQHandler ; irq 20 : CAN 0 IRQHandler + DCD Reserved21_IRQHandler ; irq 21 : Reserved Interrupt + DCD RTC_IRQHandler ; irq 22 : RTC IRQHandler + DCD PMU_IRQHandler ; irq 23 : PMU IRQHandler + DCD TDG0_IRQHandler ; irq 24 : TDG0 IRQHandler + DCD SCC_IRQHandler ; irq 25 : system clock controller IRQHandler + DCD WDOG_IRQHandler ; irq 26 : watchdog IRQHandler + DCD EWDT_IRQHandler ; irq 27 : external watchdog monitor IRQHandler + DCD STIM_IRQHandler ; irq 28 : STIM IRQHandler + DCD SRMC_IRQHandler ; irq 29 : system reset and mode control IRQHandler + DCD PORTABC_IRQHandler ; irq 30 : port A B C IRQHandler + DCD PORTDE_IRQHandler ; irq 31 : port D E IRQHandler +__Vectors_End + +__Vectors_Size EQU __Vectors_End - __vector_table + + + AREA |.text|, CODE, READONLY + +Reset_Handler PROC + ALIGN 4 + EXPORT Reset_Handler [WEAK] + + CPSID I ; Mask interrupts + + IF :LNOT: :DEF:START_FROM_SRAM + ; Init ECC RAM + LDR R1, =__RAM_START + LDR R1, [R1] + LDR R2, =__RAM_END + LDR R2, [R2] + SUBS R2, R1 + SUBS R2, #1 + BLE LC2 + + MOVS R0, #0 + MOVS R3, #4 +LC1 + STR R0, [R1] + ADD R1, R1, R3 + SUBS R2, #4 + BGE LC1 +LC2 + NOP + ENDIF + + LDR R0, =0xE000ED08 + LDR R1, =__vector_table + STR R1, [R0] + LDR R2, [R1] + MSR MSP, R2 + CPSIE i ; Unmask interrupts + LDR R0, =__main + BLX R0 + ENDP + +NMI_Handler\ + PROC + EXPORT NMI_Handler [WEAK] + B . + ENDP + +HardFault_Handler\ + PROC + EXPORT HardFault_Handler [WEAK] + B . + ENDP + +SVC_Handler\ + PROC + EXPORT SVC_Handler [WEAK] + B . + ENDP + +PendSV_Handler\ + PROC + EXPORT PendSV_Handler [WEAK] + B . + ENDP + +SysTick_Handler\ + PROC + EXPORT SysTick_Handler [WEAK] + B . + ENDP + +DMA0TO3_IRQHandler\ + PROC + EXPORT DMA0TO3_IRQHandler [WEAK] + LDR R0, =DMA0TO3_DriverIRQHandler + BX R0 + ENDP + +DMA4TO7_IRQHandler\ + PROC + EXPORT DMA4TO7_IRQHandler [WEAK] + LDR R0, =DMA4TO7_DriverIRQHandler + BX R0 + ENDP + +DMA8TO11_IRQHandler\ + PROC + EXPORT DMA8TO11_IRQHandler [WEAK] + LDR R0, =DMA8TO11_DriverIRQHandler + BX R0 + ENDP + +DMA12TO15_IRQHandler\ + PROC + EXPORT DMA12TO15_IRQHandler [WEAK] + LDR R0, =DMA12TO15_DriverIRQHandler + BX R0 + ENDP + +DMAERR_IRQHandler\ + PROC + EXPORT DMAERR_IRQHandler [WEAK] + LDR R0, =DMAERR_DriverIRQHandler + BX R0 + ENDP + +I2C0_IRQHandler\ + PROC + EXPORT I2C0_IRQHandler [WEAK] + LDR R0, =I2C0_DriverIRQHandler + BX R0 + ENDP + +SPI0_IRQHandler\ + PROC + EXPORT SPI0_IRQHandler [WEAK] + LDR R0, =SPI0_DriverIRQHandler + BX R0 + ENDP + +SPI1_IRQHandler\ + PROC + EXPORT SPI1_IRQHandler [WEAK] + LDR R0, =SPI1_DriverIRQHandler + BX R0 + ENDP + +UART0_IRQHandler\ + PROC + EXPORT UART0_IRQHandler [WEAK] + LDR R0, =UART0_DriverIRQHandler + BX R0 + ENDP + +UART1_IRQHandler\ + PROC + EXPORT UART1_IRQHandler [WEAK] + LDR R0, =UART1_DriverIRQHandler + BX R0 + ENDP + +UART2_IRQHandler\ + PROC + EXPORT UART2_IRQHandler [WEAK] + LDR R0, =UART2_DriverIRQHandler + BX R0 + ENDP + +ADC0_IRQHandler\ + PROC + EXPORT ADC0_IRQHandler [WEAK] + LDR R0, =ADC0_DriverIRQHandler + BX R0 + ENDP + +FLASH_IRQHandler\ + PROC + EXPORT FLASH_IRQHandler [WEAK] + LDR R0, =FLASH_DriverIRQHandler + BX R0 + ENDP + +CMP_IRQHandler\ + PROC + EXPORT CMP_IRQHandler [WEAK] + LDR R0, =CMP_DriverIRQHandler + BX R0 + ENDP + +TIM0_IRQHandler\ + PROC + EXPORT TIM0_IRQHandler [WEAK] + LDR R0, =TIM0_DriverIRQHandler + BX R0 + ENDP + +TIM1_IRQHandler\ + PROC + EXPORT TIM1_IRQHandler [WEAK] + LDR R0, =TIM1_DriverIRQHandler + BX R0 + ENDP + +TIM2_IRQHandler\ + PROC + EXPORT TIM2_IRQHandler [WEAK] + LDR R0, =TIM2_DriverIRQHandler + BX R0 + ENDP + +CAN0_IRQHandler\ + PROC + EXPORT CAN0_IRQHandler [WEAK] + LDR R0, =CAN0_DriverIRQHandler + BX R0 + ENDP + +RTC_IRQHandler\ + PROC + EXPORT RTC_IRQHandler [WEAK] + LDR R0, =RTC_DriverIRQHandler + BX R0 + ENDP + +PMU_IRQHandler\ + PROC + EXPORT PMU_IRQHandler [WEAK] + LDR R0, =PMU_DriverIRQHandler + BX R0 + ENDP + +TDG0_IRQHandler\ + PROC + EXPORT TDG0_IRQHandler [WEAK] + LDR R0, =TDG0_DriverIRQHandler + BX R0 + ENDP + +SCC_IRQHandler\ + PROC + EXPORT SCC_IRQHandler [WEAK] + LDR R0, =SCC_DriverIRQHandler + BX R0 + ENDP + +WDOG_IRQHandler\ + PROC + EXPORT WDOG_IRQHandler [WEAK] + LDR R0, =WDOG_DriverIRQHandler + BX R0 + ENDP + +EWDT_IRQHandler\ + PROC + EXPORT EWDT_IRQHandler [WEAK] + LDR R0, =EWDT_DriverIRQHandler + BX R0 + ENDP + +STIM_IRQHandler\ + PROC + EXPORT STIM_IRQHandler [WEAK] + LDR R0, =STIM_DriverIRQHandler + BX R0 + ENDP + +SRMC_IRQHandler\ + PROC + EXPORT SRMC_IRQHandler [WEAK] + LDR R0, =SRMC_DriverIRQHandler + BX R0 + ENDP + +PORTABC_IRQHandler\ + PROC + EXPORT PORTABC_IRQHandler [WEAK] + LDR R0, =PORTABC_DriverIRQHandler + BX R0 + ENDP + +PORTDE_IRQHandler\ + PROC + EXPORT PORTDE_IRQHandler [WEAK] + LDR R0, =PORTDE_DriverIRQHandler + BX R0 + ENDP + +Default_Handler PROC + EXPORT DMA0TO3_DriverIRQHandler [WEAK] + EXPORT DMA4TO7_DriverIRQHandler [WEAK] + EXPORT DMA8TO11_DriverIRQHandler [WEAK] + EXPORT DMA12TO15_DriverIRQHandler [WEAK] + EXPORT DMAERR_DriverIRQHandler [WEAK] + EXPORT I2C0_DriverIRQHandler [WEAK] + EXPORT Reserved6_IRQHandler [WEAK] + EXPORT SPI0_DriverIRQHandler [WEAK] + EXPORT SPI1_DriverIRQHandler [WEAK] + EXPORT Reserved9_IRQHandler [WEAK] + EXPORT UART0_DriverIRQHandler [WEAK] + EXPORT UART1_DriverIRQHandler [WEAK] + EXPORT UART2_DriverIRQHandler [WEAK] + EXPORT Reserved13_IRQHandler [WEAK] + EXPORT ADC0_DriverIRQHandler [WEAK] + EXPORT FLASH_DriverIRQHandler [WEAK] + EXPORT CMP_DriverIRQHandler [WEAK] + EXPORT TIM0_DriverIRQHandler [WEAK] + EXPORT TIM1_DriverIRQHandler [WEAK] + EXPORT TIM2_DriverIRQHandler [WEAK] + EXPORT CAN0_DriverIRQHandler [WEAK] + EXPORT Reserved21_IRQHandler [WEAK] + EXPORT RTC_DriverIRQHandler [WEAK] + EXPORT PMU_DriverIRQHandler [WEAK] + EXPORT TDG0_DriverIRQHandler [WEAK] + EXPORT SCC_DriverIRQHandler [WEAK] + EXPORT WDOG_DriverIRQHandler [WEAK] + EXPORT EWDT_DriverIRQHandler [WEAK] + EXPORT STIM_DriverIRQHandler [WEAK] + EXPORT SRMC_DriverIRQHandler [WEAK] + EXPORT PORTABC_DriverIRQHandler [WEAK] + EXPORT PORTDE_DriverIRQHandler [WEAK] + +DMA0TO3_DriverIRQHandler +DMA4TO7_DriverIRQHandler +DMA8TO11_DriverIRQHandler +DMA12TO15_DriverIRQHandler +DMAERR_DriverIRQHandler +I2C0_DriverIRQHandler +Reserved6_IRQHandler +SPI0_DriverIRQHandler +SPI1_DriverIRQHandler +Reserved9_IRQHandler +UART0_DriverIRQHandler +UART1_DriverIRQHandler +UART2_DriverIRQHandler +Reserved13_IRQHandler +ADC0_DriverIRQHandler +FLASH_DriverIRQHandler +CMP_DriverIRQHandler +TIM0_DriverIRQHandler +TIM1_DriverIRQHandler +TIM2_DriverIRQHandler +CAN0_DriverIRQHandler +Reserved21_IRQHandler +RTC_DriverIRQHandler +PMU_DriverIRQHandler +TDG0_DriverIRQHandler +SCC_DriverIRQHandler +WDOG_DriverIRQHandler +EWDT_DriverIRQHandler +STIM_DriverIRQHandler +SRMC_DriverIRQHandler +PORTABC_DriverIRQHandler +PORTDE_DriverIRQHandler + + B . + + ENDP + + ALIGN + END \ No newline at end of file diff --git a/Platform/Devices/Z20K114M/Startup/GCC/Z20K114M_startup.S b/Platform/Devices/Z20K114M/Startup/GCC/Z20K114M_startup.S new file mode 100644 index 0000000..8e9daa7 --- /dev/null +++ b/Platform/Devices/Z20K114M/Startup/GCC/Z20K114M_startup.S @@ -0,0 +1,518 @@ +/****************************************************************************************/ +/* @file : Z20K114M_startup.s */ +/* @brief : Z20K114M Device Vector Table Source File. */ +/* @version : V1.8.0 */ +/* @date : May-2020 */ +/* @author : Zhixin Semiconductor */ +/* */ +/* @note */ +/* @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. */ +/****************************************************************************************/ + .syntax unified + .arch armv6-m + + .section .isr_vector, "a" + .align 2 + .globl __isr_vector +__isr_vector: + .long __StackTop /* Stack */ + .long Reset_Handler /*!< POR Reset Entry */ + .long NMI_Handler /*!< NMI handler */ + .long HardFault_Handler /*!< Hard Fault Handler */ + .long 0 + .long 0 + .long 0 + .long 0 + .long 0 + .long 0 + .long 0 /*!< Reserved 7 Handler */ + .long SVC_Handler /*!< SVC Handler */ + .long 0 + .long 0 /*!< Reserved 2 Handler */ + .long PendSV_Handler /*!< PendSV Handler */ + .long SysTick_Handler /*!< SysTick Handler */ + + /* Zhixin specific interrupt */ + .long DMA0TO3_IRQHandler /*!< irq 0 : DMA channel 0 - 3 transfer complete ISR */ + .long DMA4TO7_IRQHandler /*!< irq 1 : DMA channel 4 - 7 transfer complete ISR */ + .long DMA8TO11_IRQHandler /*!< irq 2 : DMA channel 8 - 11 transfer complete ISR */ + .long DMA12TO15_IRQHandler /*!< irq 3 : DMA channel 12 - 15 transfer complete ISR */ + .long DMAERR_IRQHandler /*!< irq 4 : DMA error interrupt channels 0-7 ISR */ + .long I2C0_IRQHandler /*!< irq 5 : I2C 0 ISR */ + .long Reserved6_IRQHandler /*!< irq 6 : Reserved Interrupt */ + .long SPI0_IRQHandler /*!< irq 7 : SPI 0 ISR */ + .long SPI1_IRQHandler /*!< irq 8 : SPI 1 ISR */ + .long Reserved9_IRQHandler /*!< irq 9 : Reserved Interrupt */ + .long UART0_IRQHandler /*!< irq 10 : UART 0 ISR */ + .long UART1_IRQHandler /*!< irq 11 : UART 1 ISR */ + .long UART2_IRQHandler /*!< irq 12 : UART2 ISR */ + .long Reserved13_IRQHandler /*!< irq 13 : Reserved Interrupt */ + .long ADC0_IRQHandler /*!< irq 14 : ADC0 ISR */ + .long FLASH_IRQHandler /*!< irq 15 : flash memory ISR */ + .long CMP_IRQHandler /*!< irq 16 : CMP ISR */ + .long TIM0_IRQHandler /*!< irq 17 : TIM 0 ISR */ + .long TIM1_IRQHandler /*!< irq 18 : TIM 1 ISR */ + .long TIM2_IRQHandler /*!< irq 19 : TIM 2 ISR */ + .long CAN0_IRQHandler /*!< irq 20 : CAN 0 ISR */ + .long Reserved21_IRQHandler /*!< irq 21 : Reserved Interrupt */ + .long RTC_IRQHandler /*!< irq 22 : RTC ISR */ + .long PMU_IRQHandler /*!< irq 23 : PMU ISR */ + .long TDG0_IRQHandler /*!< irq 24 : TDG0 ISR */ + .long SCC_IRQHandler /*!< irq 25 : system clock controller ISR */ + .long WDOG_IRQHandler /*!< irq 26 : watchdog ISR */ + .long EWDT_IRQHandler /*!< irq 27 : external watchdog monitor ISR */ + .long STIM_IRQHandler /*!< irq 28 : STIM ISR */ + .long SRMC_IRQHandler /*!< irq 29 : system reset and mode control ISR */ + .long PORTABC_IRQHandler /*!< irq 30 : port A B C ISR */ + .long PORTDE_IRQHandler /*!< irq 31 : port D E ISR */ + + .size __isr_vector, . - __isr_vector + + .text + .thumb + +/* Reset_Handler Entry */ + .thumb_func + .align 2 + .globl Reset_Handler + .weak Reset_Handler + .type Reset_Handler, %function +Reset_Handler: + cpsid i /* Mask interrupts */ + .equ VTOR, 0xE000ED08 + ldr r0, =VTOR + ldr r1, =__isr_vector + str r1, [r0] + ldr r2, [r1] + msr msp, r2 + +#ifndef START_FROM_SRAM + /* Clean SRAM ECC */ + ldr r1, =__RAM_START + ldr r2, =__RAM_END + + subs r2, r1 + subs r2, #1 + ble .LB2 + + movs r0, 0 + movs r3, #4 +.LB1: + str r0, [r1] + add r1, r1, r3 + subs r2, 4 + bge .LB1 +.LB2: +#endif + + + ldr r1, =__DATA_ROM + ldr r2, =__data_start__ + ldr r3, =__data_end__ + +/* Copy data from flash to SRAM.*/ +.DATA_LOOP: + cmp r2, r3 + bge .DATA_LOOP_DONE + ldr r0, [r1] + adds r1, #4 + str r0, [r2] + adds r2, #4 + b .DATA_LOOP + +.DATA_LOOP_DONE: +/* Copy bss from flash to SRAM.*/ + ldr r1, =__bss_start__ + ldr r2, =__bss_end__ + + movs r0, 0 +.BSS_LOOP: + cmp r1, r2 + bge .BSS_LOOP_DONE + str r0, [r1] + adds r1, #4 + b .BSS_LOOP + +.BSS_LOOP_DONE: + cpsie i /* Unmask interrupts */ + + ldr r0,=main + bx r0 + + .pool + .size Reset_Handler, . - Reset_Handler + + .align 1 + .thumb_func + .weak JumpToSelf + .type JumpToSelf, %function +JumpToSelf: + b JumpToSelf + .size JumpToSelf, . - JumpToSelf + + .align 1 + .thumb_func + .weak NMI_Handler + .type NMI_Handler, %function +NMI_Handler: + b . + .size NMI_Handler, . - NMI_Handler + + .align 1 + .thumb_func + .weak HardFault_Handler + .type HardFault_Handler, %function +HardFault_Handler: + b . + .size HardFault_Handler, . - HardFault_Handler + + .align 1 + .thumb_func + .weak HardFault_Handler + .type HardFault_Handler, %function +MemManageFault_Handler: + b . + .size MemManageFault_Handler, . - MemManageFault_Handler + + .align 1 + .thumb_func + .weak HardFault_Handler + .type HardFault_Handler, %function +BusFault_Handler: + b . + .size BusFault_Handler, . - BusFault_Handler + + .align 1 + .thumb_func + .weak HardFault_Handler + .type HardFault_Handler, %function +UsageFault_Handler: + b . + .size UsageFault_Handler, . - UsageFault_Handler + + .align 1 + .thumb_func + .weak SVC_Handler + .type SVC_Handler, %function +SVC_Handler: + b . + .size SVC_Handler, . - SVC_Handler + + .align 1 + .thumb_func + .weak SVC_Handler + .type SVC_Handler, %function +DebugMonitor_Handler: + b . + .size DebugMonitor_Handler, . - DebugMonitor_Handler + + .align 1 + .thumb_func + .weak PendSV_Handler + .type PendSV_Handler, %function +PendSV_Handler: + b . + .size PendSV_Handler, . - PendSV_Handler + + .align 1 + .thumb_func + .weak SysTick_Handler + .type SysTick_Handler, %function +SysTick_Handler: + b . + .size SysTick_Handler, . - SysTick_Handler + + .align 1 + .thumb_func + .weak DMA0TO3_IRQHandler + .type DMA0TO3_IRQHandler, %function +DMA0TO3_IRQHandler: + ldr r0,=DMA0TO3_DriverIRQHandler + bx r0 + .size DMA0TO3_IRQHandler, . - DMA0TO3_IRQHandler + + .align 1 + .thumb_func + .weak DMA4TO7_IRQHandler + .type DMA4TO7_IRQHandler, %function +DMA4TO7_IRQHandler: + ldr r0,=DMA4TO7_DriverIRQHandler + bx r0 + .size DMA4TO7_IRQHandler, . - DMA4TO7_IRQHandler + + .align 1 + .thumb_func + .weak DMA8TO11_IRQHandler + .type DMA8TO11_IRQHandler, %function +DMA8TO11_IRQHandler: + ldr r0,=DMA8TO11_DriverIRQHandler + bx r0 + .size DMA8TO11_IRQHandler, . - DMA8TO11_IRQHandler + + .align 1 + .thumb_func + .weak DMA12TO15_IRQHandler + .type DMA12TO15_IRQHandler, %function +DMA12TO15_IRQHandler: + ldr r0,=DMA12TO15_DriverIRQHandler + bx r0 + .size DMA12TO15_IRQHandler, . - DMA12TO15_IRQHandler + + .align 1 + .thumb_func + .weak DMAERR_IRQHandler + .type DMAERR_IRQHandler, %function +DMAERR_IRQHandler: + ldr r0,=DMAERR_DriverIRQHandler + bx r0 + .size DMAERR_IRQHandler, . - DMAERR_IRQHandler + + .align 1 + .thumb_func + .weak I2C0_IRQHandler + .type I2C0_IRQHandler, %function +I2C0_IRQHandler: + ldr r0,=I2C0_DriverIRQHandler + bx r0 + .size I2C0_IRQHandler, . - I2C0_IRQHandler + + .align 1 + .thumb_func + .weak SPI0_IRQHandler + .type SPI0_IRQHandler, %function +SPI0_IRQHandler: + ldr r0,=SPI0_DriverIRQHandler + bx r0 + .size SPI0_IRQHandler, . - SPI0_IRQHandler + + .align 1 + .thumb_func + .weak SPI1_IRQHandler + .type SPI1_IRQHandler, %function +SPI1_IRQHandler: + ldr r0,=SPI1_DriverIRQHandler + bx r0 + .size SPI1_IRQHandler, . - SPI1_IRQHandler + + .align 1 + .thumb_func + .weak UART0_IRQHandler + .type UART0_IRQHandler, %function +UART0_IRQHandler: + ldr r0,=UART0_DriverIRQHandler + bx r0 + .size UART0_IRQHandler, . - UART0_IRQHandler + + .align 1 + .thumb_func + .weak UART1_IRQHandler + .type UART1_IRQHandler, %function +UART1_IRQHandler: + ldr r0,=UART1_DriverIRQHandler + bx r0 + .size UART1_IRQHandler, . - UART1_IRQHandler + + .align 1 + .thumb_func + .weak UART2_IRQHandler + .type UART2_IRQHandler, %function +UART2_IRQHandler: + ldr r0,=UART2_DriverIRQHandler + bx r0 + .size UART2_IRQHandler, . - UART2_IRQHandler + + .align 1 + .thumb_func + .weak ADC0_IRQHandler + .type ADC0_IRQHandler, %function +ADC0_IRQHandler: + ldr r0,=ADC0_DriverIRQHandler + bx r0 + .size ADC0_IRQHandler, . - ADC0_IRQHandler + + .align 1 + .thumb_func + .weak FLASH_IRQHandler + .type FLASH_IRQHandler, %function +FLASH_IRQHandler: + ldr r0,=FLASH_DriverIRQHandler + bx r0 + .size FLASH_IRQHandler, . - FLASH_IRQHandler + + .align 1 + .thumb_func + .weak CMP_IRQHandler + .type CMP_IRQHandler, %function +CMP_IRQHandler: + ldr r0,=CMP_DriverIRQHandler + bx r0 + .size CMP_IRQHandler, . - CMP_IRQHandler + + .align 1 + .thumb_func + .weak TIM0_IRQHandler + .type TIM0_IRQHandler, %function +TIM0_IRQHandler: + ldr r0,=TIM0_DriverIRQHandler + bx r0 + .size TIM0_IRQHandler, . - TIM0_IRQHandler + + .align 1 + .thumb_func + .weak TIM1_IRQHandler + .type TIM1_IRQHandler, %function +TIM1_IRQHandler: + ldr r0,=TIM1_DriverIRQHandler + bx r0 + .size TIM1_IRQHandler, . - TIM1_IRQHandler + + .align 1 + .thumb_func + .weak TIM2_IRQHandler + .type TIM2_IRQHandler, %function +TIM2_IRQHandler: + ldr r0,=TIM2_DriverIRQHandler + bx r0 + .size TIM2_IRQHandler, . - TIM2_IRQHandler + + .align 1 + .thumb_func + .weak CAN0_IRQHandler + .type CAN0_IRQHandler, %function +CAN0_IRQHandler: + ldr r0,=CAN0_DriverIRQHandler + bx r0 + .size CAN0_IRQHandler, . - CAN0_IRQHandler + + .align 1 + .thumb_func + .weak RTC_IRQHandler + .type RTC_IRQHandler, %function +RTC_IRQHandler: + ldr r0,=RTC_DriverIRQHandler + bx r0 + .size RTC_IRQHandler, . - RTC_IRQHandler + + .align 1 + .thumb_func + .weak PMU_IRQHandler + .type PMU_IRQHandler, %function +PMU_IRQHandler: + ldr r0,=PMU_DriverIRQHandler + bx r0 + .size PMU_IRQHandler, . - PMU_IRQHandler + + .align 1 + .thumb_func + .weak TDG0_IRQHandler + .type TDG0_IRQHandler, %function +TDG0_IRQHandler: + ldr r0,=TDG0_DriverIRQHandler + bx r0 + .size TDG0_IRQHandler, . - TDG0_IRQHandler + + .align 1 + .thumb_func + .weak SCC_IRQHandler + .type SCC_IRQHandler, %function +SCC_IRQHandler: + ldr r0,=SCC_DriverIRQHandler + bx r0 + .size SCC_IRQHandler, . - SCC_IRQHandler + + .align 1 + .thumb_func + .weak WDOG_IRQHandler + .type WDOG_IRQHandler, %function +WDOG_IRQHandler: + ldr r0,=WDOG_DriverIRQHandler + bx r0 + .size WDOG_IRQHandler, . - WDOG_IRQHandler + + .align 1 + .thumb_func + .weak EWDT_IRQHandler + .type EWDT_IRQHandler, %function +EWDT_IRQHandler: + ldr r0,=EWDT_DriverIRQHandler + bx r0 + .size EWDT_IRQHandler, . - EWDT_IRQHandler + + .align 1 + .thumb_func + .weak STIM_IRQHandler + .type STIM_IRQHandler, %function +STIM_IRQHandler: + ldr r0,=STIM_DriverIRQHandler + bx r0 + .size STIM_IRQHandler, . - STIM_IRQHandler + + .align 1 + .thumb_func + .weak SRMC_IRQHandler + .type SRMC_IRQHandler, %function +SRMC_IRQHandler: + ldr r0,=SRMC_DriverIRQHandler + bx r0 + .size SRMC_IRQHandler, . - SRMC_IRQHandler + + .align 1 + .thumb_func + .weak PORTABC_IRQHandler + .type PORTABC_IRQHandler, %function +PORTABC_IRQHandler: + ldr r0,=PORTABC_DriverIRQHandler + bx r0 + .size PORTABC_IRQHandler, . - PORTABC_IRQHandler + + .align 1 + .thumb_func + .weak PORTDE_IRQHandler + .type PORTDE_IRQHandler, %function +PORTDE_IRQHandler: + ldr r0,=PORTDE_DriverIRQHandler + bx r0 + .size PORTDE_IRQHandler, . - PORTDE_IRQHandler + +/* Define default handlers */ + .macro def_irq_handler handler_name + .weak \handler_name + .set \handler_name, JumpToSelf + .endm + +/* Zhixin specific interrupt */ + def_irq_handler DMA0TO3_DriverIRQHandler + def_irq_handler DMA4TO7_DriverIRQHandler + def_irq_handler DMA8TO11_DriverIRQHandler + def_irq_handler DMA12TO15_DriverIRQHandler + def_irq_handler DMAERR_DriverIRQHandler + def_irq_handler I2C0_DriverIRQHandler + def_irq_handler Reserved6_IRQHandler + def_irq_handler SPI0_DriverIRQHandler + def_irq_handler SPI1_DriverIRQHandler + def_irq_handler Reserved9_IRQHandler + def_irq_handler UART0_DriverIRQHandler + def_irq_handler UART1_DriverIRQHandler + def_irq_handler UART2_DriverIRQHandler + def_irq_handler Reserved13_IRQHandler + def_irq_handler ADC0_DriverIRQHandler + def_irq_handler FLASH_DriverIRQHandler + def_irq_handler CMP_DriverIRQHandler + def_irq_handler TIM0_DriverIRQHandler + def_irq_handler TIM1_DriverIRQHandler + def_irq_handler TIM2_DriverIRQHandler + def_irq_handler CAN0_DriverIRQHandler + def_irq_handler Reserved21_IRQHandler + def_irq_handler RTC_DriverIRQHandler + def_irq_handler PMU_DriverIRQHandler + def_irq_handler TDG0_DriverIRQHandler + def_irq_handler SCC_DriverIRQHandler + def_irq_handler WDOG_DriverIRQHandler + def_irq_handler EWDT_DriverIRQHandler + def_irq_handler STIM_DriverIRQHandler + def_irq_handler SRMC_DriverIRQHandler + def_irq_handler PORTABC_DriverIRQHandler + def_irq_handler PORTDE_DriverIRQHandler + + + .end \ No newline at end of file diff --git a/Platform/Devices/Z20K114M/Startup/IAR/Z20K114M_startup.s b/Platform/Devices/Z20K114M/Startup/IAR/Z20K114M_startup.s new file mode 100644 index 0000000..3da99ee --- /dev/null +++ b/Platform/Devices/Z20K114M/Startup/IAR/Z20K114M_startup.s @@ -0,0 +1,409 @@ +; ----------------------------------------------------------------------------- +; @file : Z20K114M_startup.s +; @brief : Z20K114M startup and Vector Table Source File for IAR. +; @version : V1.8.0 +; @date : May-2020 +; @author : Zhixin Semiconductor +; +; @note +; @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. +; ----------------------------------------------------------------------------- + + + MODULE ?cstartup + + ;; Forward declaration of sections. + SECTION CSTACK:DATA:NOROOT(3) + + SECTION .intvec:CODE:ROOT(2) + + EXTERN __iar_program_start + PUBLIC __vector_table + PUBLIC __Vectors_End + PUBLIC __Vectors_Size + + DATA + +__vector_table + DCD sfe(CSTACK) + DCD Reset_Handler ; POR Reset Entry + DCD NMI_Handler ; Non Maskable handler + DCD HardFault_Handler ; SV Hard Fault handler + DCD 0 + DCD 0 + DCD 0 + DCD 0 + DCD 0 + DCD 0 + DCD 0 + DCD SVC_Handler ; SV Call handler + DCD 0 + DCD 0 + DCD PendSV_Handler ; Pend SV handler + DCD SysTick_Handler ; System Tick handler + + + DCD DMA0TO3_IRQHandler ; irq 0 : DMA channel 0 - 3 transfer complete IRQHandler + DCD DMA4TO7_IRQHandler ; irq 1 : DMA channel 4 - 7 transfer complete IRQHandler + DCD DMA8TO11_IRQHandler ; irq 2 : DMA channel 8 - 11 transfer complete IRQHandler + DCD DMA12TO15_IRQHandler ; irq 3 : DMA channel 12 - 15 transfer complete IRQHandler + DCD DMAERR_IRQHandler ; irq 4 : DMA error interrupt channels 0-7 IRQHandler + DCD I2C0_IRQHandler ; irq 5 : I2C 0 IRQHandler + DCD Reserved6_IRQHandler ; irq 6 : Reserved Interrupt + DCD SPI0_IRQHandler ; irq 7 : SPI 0 IRQHandler + DCD SPI1_IRQHandler ; irq 8 : SPI 1 IRQHandler + DCD Reserved9_IRQHandler ; irq 9 : Reserved Interrupt + DCD UART0_IRQHandler ; irq 10 : UART 0 IRQHandler + DCD UART1_IRQHandler ; irq 11 : UART 1 IRQHandler + DCD UART2_IRQHandler ; irq 12 : UART2 IRQHandler + DCD Reserved13_IRQHandler ; irq 13 : Reserved Interrupt + DCD ADC0_IRQHandler ; irq 14 : ADC0 IRQHandler + DCD FLASH_IRQHandler ; irq 15 : flash memory IRQHandler + DCD CMP_IRQHandler ; irq 16 : CMP IRQHandler + DCD TIM0_IRQHandler ; irq 17 : TIM 0 IRQHandler + DCD TIM1_IRQHandler ; irq 18 : TIM 1 IRQHandler + DCD TIM2_IRQHandler ; irq 19 : TIM 2 IRQHandler + DCD CAN0_IRQHandler ; irq 20 : CAN 0 IRQHandler + DCD Reserved21_IRQHandler ; irq 21 : Reserved Interrupt + DCD RTC_IRQHandler ; irq 22 : RTC IRQHandler + DCD PMU_IRQHandler ; irq 23 : PMU IRQHandler + DCD TDG0_IRQHandler ; irq 24 : TDG0 IRQHandler + DCD SCC_IRQHandler ; irq 25 : system clock controller IRQHandler + DCD WDOG_IRQHandler ; irq 26 : watchdog IRQHandler + DCD EWDT_IRQHandler ; irq 27 : external watchdog monitor IRQHandler + DCD STIM_IRQHandler ; irq 28 : STIM IRQHandler + DCD SRMC_IRQHandler ; irq 29 : system reset and mode control IRQHandler + DCD PORTABC_IRQHandler ; irq 30 : port A B C IRQHandler + DCD PORTDE_IRQHandler ; irq 31 : port D E IRQHandler +__Vectors_End + + +__Vectors_Size EQU __Vectors_End - __vector_table + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;; Default interrupt handlers. +;; + THUMB + + PUBWEAK Reset_Handler + SECTION .text:CODE:REORDER:NOROOT(2) +Reset_Handler + CPSID I ; Mask interrupts + ;; Init the registers + LDR R1,=0 + LDR R2,=0 + LDR R3,=0 + LDR R4,=0 + LDR R5,=0 + LDR R6,=0 + LDR R7,=0 + MOV R8,R7 + MOV R9,R7 + MOV R10,R7 + MOV R11,R7 + MOV R12,R7 + + ; vector table relocation + LDR R0, =0xE000ED08 + LDR R1, =__vector_table + STR R1, [R0] + +#ifndef START_FROM_SRAM + IMPORT __RAM_START, __RAM_END + ;; INIT ECC RAM + + LDR R1, =__RAM_START + LDR R2, =__RAM_END + + SUBS R2, R2, R1 + SUBS R2, #1 + BLE LB2 + + MOVS R0, #0 + MOVS R3, #4 + LB1: + STR R0, [R1] + ADD R1, R1, R3 + SUBS R2, #4 + BGE LB1 + LB2: +#endif + ;; Initialize the stack pointer + LDR R0, =sfe(CSTACK) + MOV R13,R0 + + CPSIE I ; Unmask interrupts + + LDR R0, =__iar_program_start + BX R0 + +JumpToSelf + B JumpToSelf + + PUBWEAK NMI_Handler + SECTION .text:CODE:REORDER:NOROOT(1) +NMI_Handler + B . + + PUBWEAK HardFault_Handler + SECTION .text:CODE:REORDER:NOROOT(1) +HardFault_Handler + B . + + + PUBWEAK SVC_Handler + SECTION .text:CODE:REORDER:NOROOT(1) +SVC_Handler + B . + + PUBWEAK PendSV_Handler + SECTION .text:CODE:REORDER:NOROOT(1) +PendSV_Handler + B . + + PUBWEAK SysTick_Handler + SECTION .text:CODE:REORDER:NOROOT(1) +SysTick_Handler + B . + + + PUBWEAK DMA0TO3_IRQHandler + PUBWEAK DMA0TO3_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +DMA0TO3_IRQHandler + LDR R0, =DMA0TO3_DriverIRQHandler + BX R0 + + PUBWEAK DMA4TO7_IRQHandler + PUBWEAK DMA4TO7_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +DMA4TO7_IRQHandler + LDR R0, =DMA4TO7_DriverIRQHandler + BX R0 + + PUBWEAK DMA8TO11_IRQHandler + PUBWEAK DMA8TO11_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +DMA8TO11_IRQHandler + LDR R0, =DMA8TO11_DriverIRQHandler + BX R0 + + PUBWEAK DMA12TO15_IRQHandler + PUBWEAK DMA12TO15_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +DMA12TO15_IRQHandler + LDR R0, =DMA12TO15_DriverIRQHandler + BX R0 + + PUBWEAK DMAERR_IRQHandler + PUBWEAK DMAERR_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +DMAERR_IRQHandler + LDR R0, =DMAERR_DriverIRQHandler + BX R0 + + PUBWEAK I2C0_IRQHandler + PUBWEAK I2C0_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +I2C0_IRQHandler + LDR R0, =I2C0_DriverIRQHandler + BX R0 + + PUBWEAK Reserved6_IRQHandler + PUBWEAK SPI0_IRQHandler + PUBWEAK SPI0_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +SPI0_IRQHandler + LDR R0, =SPI0_DriverIRQHandler + BX R0 + + PUBWEAK SPI1_IRQHandler + PUBWEAK SPI1_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +SPI1_IRQHandler + LDR R0, =SPI1_DriverIRQHandler + BX R0 + + PUBWEAK Reserved9_IRQHandler + PUBWEAK UART0_IRQHandler + PUBWEAK UART0_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +UART0_IRQHandler + LDR R0, =UART0_DriverIRQHandler + BX R0 + + PUBWEAK UART1_IRQHandler + PUBWEAK UART1_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +UART1_IRQHandler + LDR R0, =UART1_DriverIRQHandler + BX R0 + + PUBWEAK UART2_IRQHandler + PUBWEAK UART2_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +UART2_IRQHandler + LDR R0, =UART2_DriverIRQHandler + BX R0 + + PUBWEAK Reserved13_IRQHandler + PUBWEAK ADC0_IRQHandler + PUBWEAK ADC0_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +ADC0_IRQHandler + LDR R0, =ADC0_DriverIRQHandler + BX R0 + + PUBWEAK FLASH_IRQHandler + PUBWEAK FLASH_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +FLASH_IRQHandler + LDR R0, =FLASH_DriverIRQHandler + BX R0 + + PUBWEAK CMP_IRQHandler + PUBWEAK CMP_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +CMP_IRQHandler + LDR R0, =CMP_DriverIRQHandler + BX R0 + + PUBWEAK TIM0_IRQHandler + PUBWEAK TIM0_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +TIM0_IRQHandler + LDR R0, =TIM0_DriverIRQHandler + BX R0 + + PUBWEAK TIM1_IRQHandler + PUBWEAK TIM1_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +TIM1_IRQHandler + LDR R0, =TIM1_DriverIRQHandler + BX R0 + + PUBWEAK TIM2_IRQHandler + PUBWEAK TIM2_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +TIM2_IRQHandler + LDR R0, =TIM2_DriverIRQHandler + BX R0 + + PUBWEAK CAN0_IRQHandler + PUBWEAK CAN0_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +CAN0_IRQHandler + LDR R0, =CAN0_DriverIRQHandler + BX R0 + + PUBWEAK Reserved21_IRQHandler + PUBWEAK RTC_IRQHandler + PUBWEAK RTC_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +RTC_IRQHandler + LDR R0, =RTC_DriverIRQHandler + BX R0 + + PUBWEAK PMU_IRQHandler + PUBWEAK PMU_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +PMU_IRQHandler + LDR R0, =PMU_DriverIRQHandler + BX R0 + + PUBWEAK TDG0_IRQHandler + PUBWEAK TDG0_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +TDG0_IRQHandler + LDR R0, =TDG0_DriverIRQHandler + BX R0 + + PUBWEAK SCC_IRQHandler + PUBWEAK SCC_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +SCC_IRQHandler + LDR R0, =SCC_DriverIRQHandler + BX R0 + + PUBWEAK WDOG_IRQHandler + PUBWEAK WDOG_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +WDOG_IRQHandler + LDR R0, =WDOG_DriverIRQHandler + BX R0 + + PUBWEAK EWDT_IRQHandler + PUBWEAK EWDT_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +EWDT_IRQHandler + LDR R0, =EWDT_DriverIRQHandler + BX R0 + + PUBWEAK STIM_IRQHandler + PUBWEAK STIM_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +STIM_IRQHandler + LDR R0, =STIM_DriverIRQHandler + BX R0 + + PUBWEAK SRMC_IRQHandler + PUBWEAK SRMC_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +SRMC_IRQHandler + LDR R0, =SRMC_DriverIRQHandler + BX R0 + + PUBWEAK PORTABC_IRQHandler + PUBWEAK PORTABC_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +PORTABC_IRQHandler + LDR R0, =PORTABC_DriverIRQHandler + BX R0 + + PUBWEAK PORTDE_IRQHandler + PUBWEAK PORTDE_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +PORTDE_IRQHandler + LDR R0, =PORTDE_DriverIRQHandler + BX R0 + + PUBWEAK DefaultISR + SECTION .text:CODE:REORDER:NOROOT(1) +DMA0TO3_DriverIRQHandler +DMA4TO7_DriverIRQHandler +DMA8TO11_DriverIRQHandler +DMA12TO15_DriverIRQHandler +DMAERR_DriverIRQHandler +I2C0_DriverIRQHandler +Reserved6_IRQHandler +SPI0_DriverIRQHandler +SPI1_DriverIRQHandler +Reserved9_IRQHandler +UART0_DriverIRQHandler +UART1_DriverIRQHandler +UART2_DriverIRQHandler +Reserved13_IRQHandler +ADC0_DriverIRQHandler +FLASH_DriverIRQHandler +CMP_DriverIRQHandler +TIM0_DriverIRQHandler +TIM1_DriverIRQHandler +TIM2_DriverIRQHandler +CAN0_DriverIRQHandler +Reserved21_IRQHandler +RTC_DriverIRQHandler +PMU_DriverIRQHandler +TDG0_DriverIRQHandler +SCC_DriverIRQHandler +WDOG_DriverIRQHandler +EWDT_DriverIRQHandler +STIM_DriverIRQHandler +SRMC_DriverIRQHandler +PORTABC_DriverIRQHandler +PORTDE_DriverIRQHandler +DefaultISR + B DefaultISR + + END diff --git a/Platform/Devices/Z20K116M/Inc/Z20K116M.h b/Platform/Devices/Z20K116M/Inc/Z20K116M.h new file mode 100644 index 0000000..ce40637 --- /dev/null +++ b/Platform/Devices/Z20K116M/Inc/Z20K116M.h @@ -0,0 +1,4613 @@ +/**************************************************************************************************/ +/** + * @file : Z20K116M.h + * @brief : Z20K116M device header file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ + +#ifndef Z20K116M_H +#define Z20K116M_H + +#include +#include +#include + +/** + * @brief Variant Peripheral Instance Information + */ +#define CAN_INSTANCE_NUM (1U) +#define SPI_INSTANCE_NUM (2U) +#define I2C_INSTANCE_NUM (1U) +#define UART_INSTANCE_NUM (3U) + +/** + * @brief Peripheral Base Address + */ +#define FLASH_CODE_BASE_ADDR ((uint32_t)0x00000000) /*!< Code flash base address */ +#define FLASH_DATA_BASE_ADDR ((uint32_t)0x01000000) /*!< Data flash base address */ +#define FLASH_IFR_BASE_ADDR ((uint32_t)0x02000000) /*!< flash IFR base address */ +#define SRAMU_BASE_ADDR ((uint32_t)0x20000000) /*!< SRAMU base address */ +#define PERIPHERAL_BASE_ADDR ((uint32_t)0x40000000) /*!< Peripheral area base address */ +#define AIPS0_BASE_ADDR ((uint32_t)0x40000000) /*!< AIPS0 base address */ + +#define PRI_PERI_BUS_BASE_ADDR ((uint32_t)0xE0000000) /*!< private Peripheral base address */ + +#define DMA_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x8000UL) /*!< DMA controller base address */ +#define FLASHC_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x20000UL) /*!< flash controller base address */ +#define DMAMUX_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x22000UL) /*!< DMA channel Multiplexer base address */ +#define CAN0_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x24000UL) /*!< CAN0 base address */ +#define ADC0_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x26000UL) /*!< ADC0 base address */ +#define RTC_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x28000UL) /*!< RTC base address */ +#define SPI0_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x2C000UL) /*!< SPI0 base address */ +#define SPI1_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x2D000UL) /*!< SPI1 base address */ +#define REGFILE_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x34000UL) /*!< REGFILE base address */ +#define TDG0_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x35000UL) /*!< TDG0 base address */ +#define TMU_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x36000UL) /*!< TMU base address */ +#define TIM0_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x38000UL) /*!< TIM0 base address */ +#define TIM1_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x39000UL) /*!< TIM1 base address */ +#define TIM2_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x3A000UL) /*!< TIM2 base address */ +#define STIM_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x40000UL) /*!< STIM base address */ +#define CRC_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x43000UL) /*!< CRC base address */ +#define SCM_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x48000UL) /*!< System Control base address */ +#define PORTA_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x49000UL) /*!< PORTA multiplexing base address */ +#define PORTB_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x4A000UL) /*!< PORTB multiplexing base address */ +#define PORTC_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x4B000UL) /*!< PORTC multiplexing base address */ +#define PORTD_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x4C000UL) /*!< PORTD multiplexing base address */ +#define PORTE_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x4D000UL) /*!< PORTE multiplexing base address */ +#define WDOG_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x52000UL) /*!< watchdog base address */ +#define EWDT_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x61000UL) /*!< External Watchdog Monitor base address */ +#define SCC_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x64000UL) /*!< System Clock Controller base address */ +#define PARCC_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x65000UL) /*!< Peripheral Clock Control base address */ +#define I2C0_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x66000UL) /*!< I2C0 base address */ +#define UART0_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x6A000UL) /*!< UART0 base address */ +#define UART1_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x6B000UL) /*!< UART1 base address */ +#define UART2_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x6C000UL) /*!< UART2 base address */ +#define CMP_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x73000UL) /*!< Analog comparator base address */ +#define PMU_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x7D000UL) /*!< Power management Unit base address */ +#define SRMC_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x7E000UL) /*!< system reset and mode controller base address */ +#define HWDIV_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0xFE000UL) /*!< HWDIV base address */ +#define GPIO_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0xFF000UL) /*!< GPIO controller base address */ +#define GPIOA_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0xFF000UL) /*!< GPIOA base address */ +#define GPIOB_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0xFF040UL) /*!< GPIOB base address */ +#define GPIOC_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0xFF080UL) /*!< GPIOC base address */ +#define GPIOD_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0xFF0C0UL) /*!< GPIOD base address */ +#define GPIOE_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0xFF100UL) /*!< GPIOE base address */ +#define RGPIO_BASE_ADDR 0xF8000000UL /*!< Fast GPIO controller base address */ +#define RGPIOA_BASE_ADDR (RGPIO_BASE_ADDR + 0x00000UL) /*!< Fast GPIOA controller base address */ +#define RGPIOB_BASE_ADDR (RGPIO_BASE_ADDR + 0x00040UL) /*!< Fast GPIOB controller base address */ +#define RGPIOC_BASE_ADDR (RGPIO_BASE_ADDR + 0x00080UL) /*!< Fast GPIOC controller base address */ +#define RGPIOD_BASE_ADDR (RGPIO_BASE_ADDR + 0x000C0UL) /*!< Fast GPIOD controller base address */ +#define RGPIOE_BASE_ADDR (RGPIO_BASE_ADDR + 0x00100UL) /*!< Fast GPIOE controller base address */ + +/** + * @brief IRQ Number Definition + */ +typedef enum IRQn +{ + /****** Cortex-M0+ Processor IRQ Numbers *******************************/ + NonMaskableInt_IRQn = -14, /*!< 2 Non Maskable Interrupt */ + HardFalut_IRQn = -13, /*!< 3 Hardfault Interrupt */ + SVCall_IRQn = -5, /*!< 11 Cortex-M0+ SV Call Interrupt */ + PendSV_IRQn = -2, /*!< 14 Cortex-M0+ Pend SV Interrupt */ + SysTick_IRQn = -1, /*!< 15 Cortex-M0+ System Tick Interrupt */ + + /****** specific IRQ Numbers *************************************/ + DMA0TO3_IRQn = 0, /*!< DMA channel 0-3 transfer complete Interrupt */ + DMA4TO7_IRQn = 1, /*!< DMA channel 4-7 transfer complete Interrupt */ + DMA8TO11_IRQn = 2, /*!< DMA channel 8-11 transfer complete Interrupt */ + DMA12TO15_IRQn = 3, /*!< DMA channel 12-15 transfer complete Interrupt */ + DMAERR_IRQn = 4, /*!< DMA error (channels 0-16) Interrupt */ + I2C0_IRQn = 5, /*!< I2C 0 Interrupt */ + Reserved6_IRQn = 6, /*!< Reserved Interrupt */ + SPI0_IRQn = 7, /*!< SPI 0 Interrupt */ + SPI1_IRQn = 8, /*!< SPI 1 Interrupt*/ + Reserved9_IRQn = 9, /*!< Reserved Interrupt */ + UART0_IRQn = 10, /*!< UART 0 Interrupt */ + UART1_IRQn = 11, /*!< UART 1 Interrupt */ + UART2_IRQn = 12, /*!< UART2 Interrupt */ + Reserved13_IRQn = 13, /*!< Reserved Interrupt*/ + ADC0_IRQn = 14, /*!< ADC0 Interrupt */ + FLASH_IRQn = 15, /*!< flash ISR */ + CMP_IRQn = 16, /*!< CMP Interrupt */ + TIM0_IRQn = 17, /*!< TIM 0 Interrupt */ + TIM1_IRQn = 18, /*!< TIM 1 Interrupt */ + TIM2_IRQn = 19, /*!< TIM 2 Interrupt */ + CAN0_IRQn = 20, /*!< CAN 0 Interrupt*/ + Reserved21_IRQn = 21, /*!< Reserved Interrupt */ + RTC_IRQn = 22, /*!< RTC Interrupt */ + PMU_IRQn = 23, /*!< PMU Interrupt */ + TDG0_IRQn = 24, /*!< TDG0 Interrupt */ + SCC_IRQn = 25, /*!< system clock controller Interrupt*/ + WDOG_IRQn = 26, /*!< watchdog Interrupt */ + EWDT_IRQn = 27, /*!< external watchdog monitor Interrupt*/ + STIM_IRQn = 28, /*!< STIM Interrupt */ + SRMC_IRQn = 29, /*!< system reset and mode control Interrupt*/ + PORTABC_IRQn = 30, /*!< port A B C Interrupt */ + PORTDE_IRQn = 31 /*!< port D E Interrupt */ +} IRQn_Type; + +/** + * Peripheral Register Defination + */ +struct adc_reg { + /* 0x000*/ + struct { + uint32_t DIFFEN : 1; /* [0] ro */ + uint32_t CALOFSI : 1; /* [1] ro */ + uint32_t RSVD_7_2 : 6; /* [7:2] ro */ + uint32_t FIFO_NUM : 8; /* [15:8] ro */ + uint32_t MINOR : 8; /* [23:16] ro */ + uint32_t MAJOR : 8; /* [31:24] ro */ + } ADC_VERID; + + /* 0x004*/ + struct { + uint32_t RSVD_7_0 : 8; /* [7:0] ro */ + uint32_t FIFO_SIZE : 8; /* [15:8] ro */ + uint32_t RSVD_31_16 :16; /* [31:16] ro */ + } ADC_PARAM; + + /* 0x008*/ + struct { + uint32_t ADC_EN : 1; /* [0] r/w */ + uint32_t CAL_REQ : 1; /* [1] r/w */ + uint32_t RST : 1; /* [2] r/w */ + uint32_t DOZEN : 1; /* [3] r/w */ + uint32_t TRIG_MODE_ENABLE : 1; /* [4] r/w */ + uint32_t TRIG_MODE : 1; /* [5] r/w */ + uint32_t MODE1_RST : 1; /* [6] r/w */ + uint32_t RSVD_31_7 :25; /* [31:7] ro */ + } ADC_CTRL; + + /* 0x00C*/ + struct { + uint32_t FWM_INT : 1; /* [0] r/w1c */ + uint32_t FOF : 1; /* [1] r/w1c */ + uint32_t TCOMP_INT : 1; /* [2] r/w1c */ + uint32_t CMP_INT : 1; /* [3] r/w1c */ + uint32_t DMA_REQ : 1; /* [4] ro */ + uint32_t RDY : 1; /* [5] ro */ + uint32_t CAL_RDY : 1; /* [6] ro */ + uint32_t ADC_ACTIVE : 1; /* [7] ro */ + uint32_t LSI : 1; /* [8] ro */ + uint32_t TC_ERR : 1; /* [9] ro */ + uint32_t RSVD_31_10 :22; /* [31:10] ro */ + } ADC_STAT; + + /* 0x010*/ + struct { + uint32_t FWM_IE : 1; /* [0] r/w */ + uint32_t FOF_IE : 1; /* [1] r/w */ + uint32_t TCOM_IE : 1; /* [2] r/w */ + uint32_t CMP_IE : 1; /* [3] r/w */ + uint32_t FWMDE : 1; /* [4] r/w */ + uint32_t ERR_INT_IE : 1; /* [5] r/w */ + uint32_t RSVD_31_6 :26; /* [31:6] ro */ + } ADC_IE; + + /* 0x014*/ + struct { + uint32_t DIFF_MODE : 1; /* [0] r/w */ + uint32_t CHSELP : 5; /* [5:1] r/w */ + uint32_t CHSELN : 2; /* [7:6] r/w */ + uint32_t RSVD_10_8 : 3; /* [10:8] ro */ + uint32_t CTYPE : 1; /* [11] r/w */ + uint32_t CMPS : 3; /* [14:12] r/w */ + uint32_t RSVD_15 : 1; /* [15] r/w */ + uint32_t REF_SEL : 1; /* [16] r/w */ + uint32_t RES : 2; /* [18:17] r/w */ + uint32_t AVGS : 3; /* [21:19] r/w */ + uint32_t STS :10; /* [31:22] r/w */ + } ADC_CFG; + + /* 0x018*/ + struct { + uint32_t CVL :12; /* [11:0] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] ro */ + uint32_t CVH :12; /* [27:16] r/w */ + uint32_t RSVD_31_28 : 4; /* [31:28] ro */ + } ADC_CV; + + /* 0x01C*/ + struct { + uint32_t RSVD_5_0 : 6; /* [5:0] ro */ + uint32_t RSVD_6 : 1; /* [6] ro */ + uint32_t RSVD_10_7 : 4; /* [10:7] ro */ + uint32_t RSVD_30_11 :20; /* [30:11] ro */ + uint32_t RSVD_31 : 1; /* [31] r/w */ + } ADC_RSVD; + + /* 0x020*/ + struct { + uint32_t ADC_DATA_RD :17; /* [16:0] ro */ + uint32_t RSVD_31_17 :15; /* [31:17] ro */ + } ADC_DATA_RD; + + /* 0x024*/ + struct { + uint32_t FCOUNT : 5; /* [4:0] ro */ + uint32_t RSVD_15_5 :11; /* [15:5] ro */ + uint32_t FWMARK : 4; /* [19:16] r/w */ + uint32_t FDRD : 5; /* [24:20] r/w */ + uint32_t RSVD_31_25 : 7; /* [31:25] ro */ + } ADC_FCTRL; + + /* 0x028*/ + struct { + uint32_t ADC_SWTRIG : 1; /* [0] r/w */ + uint32_t RSVD_31_1 :31; /* [31:1] ro */ + } ADC_SWTRIG; + + /* 0x02C*/ + struct { + uint32_t ADC_CAL_VAL :13; /* [12:0] ro */ + uint32_t RSVD_31_13 :19; /* [31:13] ro */ + } ADC_CAL_VAL; + + /* 0x030*/ + struct { + uint32_t CMD0 : 5; /* [4:0] r/w */ + uint32_t RSVD_7_5 : 3; /* [7:5] ro */ + uint32_t CMD1 : 5; /* [12:8] r/w */ + uint32_t RSVD_15_13 : 3; /* [15:13] ro */ + uint32_t CMD2 : 5; /* [20:16] r/w */ + uint32_t RSVD_23_21 : 3; /* [23:21] ro */ + uint32_t CMD3 : 5; /* [28:24] r/w */ + uint32_t RSVD_31_29 : 3; /* [31:29] ro */ + } ADC_CMD_BUFF0; + + /* 0x034*/ + struct { + uint32_t CMD4 : 5; /* [4:0] r/w */ + uint32_t RSVD_7_5 : 3; /* [7:5] ro */ + uint32_t CMD5 : 5; /* [12:8] r/w */ + uint32_t RSVD_31_13 :19; /* [31:13] ro */ + } ADC_CMD_BUFF1; + +}; /*adc_reg*/ + +struct adc_reg_w { + /* 0x000*/ + uint32_t ADC_VERID; + /* 0x004*/ + uint32_t ADC_PARAM; + /* 0x008*/ + uint32_t ADC_CTRL; + /* 0x00C*/ + uint32_t ADC_STAT; + /* 0x010*/ + uint32_t ADC_IE; + /* 0x014*/ + uint32_t ADC_CFG; + /* 0x018*/ + uint32_t ADC_CV; + /* 0x01C*/ + uint32_t ADC_RSVD; + /* 0x020*/ + uint32_t ADC_DATA_RD; + /* 0x024*/ + uint32_t ADC_FCTRL; + /* 0x028*/ + uint32_t ADC_SWTRIG; + /* 0x02C*/ + uint32_t ADC_CAL_VAL; + /* 0x030*/ + uint32_t ADC_CMD_BUFF0; + /* 0x034*/ + uint32_t ADC_CMD_BUFF1; +}; /*adc_reg*/ + +typedef volatile struct adc_reg adc_reg_t; +typedef volatile struct adc_reg_w adc_reg_w_t; + +struct can_reg { + /* 0x00*/ + struct { + uint32_t MAXMB : 7; /* [6:0] r/w */ + uint32_t RSVD_7 : 1; /* [7] reserve */ + uint32_t IDAM : 2; /* [9:8] r/w */ + uint32_t RSVD_10 : 1; /* [10] reserve */ + uint32_t FDEN : 1; /* [11] r/w */ + uint32_t AEN : 1; /* [12] r/w */ + uint32_t LPRIOEN : 1; /* [13] r/w */ + uint32_t PNET_EN : 1; /* [14] r/w */ + uint32_t DMAE : 1; /* [15] r/w */ + uint32_t IRMQ : 1; /* [16] r/w */ + uint32_t SRXDIS : 1; /* [17] r/w */ + uint32_t DOZE : 1; /* [18] r/w */ + uint32_t WAKSRC : 1; /* [19] r/w */ + uint32_t LPMACK : 1; /* [20] read only */ + uint32_t WRNEN : 1; /* [21] r/w */ + uint32_t SLFWAK : 1; /* [22] r/w */ + uint32_t SUPV : 1; /* [23] r/w */ + uint32_t FRZACK : 1; /* [24] read only */ + uint32_t SOFTRST : 1; /* [25] r/w */ + uint32_t WAKMSK : 1; /* [26] r/w */ + uint32_t NOTRDY : 1; /* [27] read only */ + uint32_t HALT : 1; /* [28] r/w */ + uint32_t RFEN : 1; /* [29] r/w */ + uint32_t FRZ : 1; /* [30] r/w */ + uint32_t MDIS : 1; /* [31] r/w */ + } CAN_MCR; + + /* 0x04*/ + struct { + uint32_t PROPSEG : 3; /* [2:0] r/w */ + uint32_t LOM : 1; /* [3] r/w */ + uint32_t LBUF : 1; /* [4] r/w */ + uint32_t TSYC : 1; /* [5] r/w */ + uint32_t BOFFREC : 1; /* [6] r/w */ + uint32_t SMP : 1; /* [7] r/w */ + uint32_t RSVD_9_8 : 2; /* [9:8] reserve */ + uint32_t RWRNMSK : 1; /* [10] r/w */ + uint32_t TWRNMSK : 1; /* [11] r/w */ + uint32_t LPB : 1; /* [12] r/w */ + uint32_t RSVD_13 : 1; /* [13] reserve */ + uint32_t ERRMSK : 1; /* [14] r/w */ + uint32_t BOFFMSK : 1; /* [15] r/w */ + uint32_t PSEG2 : 3; /* [18:16] r/w */ + uint32_t PSEG1 : 3; /* [21:19] r/w */ + uint32_t RJW : 2; /* [23:22] r/w */ + uint32_t PRESDIV : 8; /* [31:24] r/w */ + } CAN_CTRL1; + + /* 0x08*/ + struct { + uint32_t TIMER :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] reserve */ + } CAN_TIMER; + + uint8_t zResverd0x0C[4]; /*pad 0x0C - 0F*/ + + /* 0x10*/ + struct { + uint32_t MG :32; /* [31:0] r/w */ + } CAN_RXMGMSK; + + /* 0x14*/ + struct { + uint32_t RX14M :32; /* [31:0] r/w */ + } CAN_RX14MASK; + + /* 0x18*/ + struct { + uint32_t RX15M :32; /* [31:0] r/w */ + } CAN_RX15MASK; + + /* 0x1c*/ + struct { + uint32_t TXERRCNT : 8; /* [7:0] r/w */ + uint32_t RXERRCNT : 8; /* [15:8] r/w */ + uint32_t TX_ERRCNT_FAST : 8; /* [23:16] r/w */ + uint32_t RX_ERRCNT_FAST : 8; /* [31:24] r/w */ + } CAN_ECR; + + /* 0x20*/ + struct { + uint32_t WAKINT : 1; /* [0] r/w1c */ + uint32_t ERRINT : 1; /* [1] r/w1c */ + uint32_t BOFFINT : 1; /* [2] r/w1c */ + uint32_t RX : 1; /* [3] read only */ + uint32_t FLTCONF : 2; /* [5:4] read only */ + uint32_t TX : 1; /* [6] read only */ + uint32_t IDLE : 1; /* [7] read only */ + uint32_t RXWRN : 1; /* [8] read only */ + uint32_t TXWRN : 1; /* [9] read only */ + uint32_t STFERR : 1; /* [10] read only */ + uint32_t FRAMERR : 1; /* [11] read only */ + uint32_t CRCERR : 1; /* [12] read only */ + uint32_t ACKERR : 1; /* [13] read only */ + uint32_t BIT0ERR : 1; /* [14] read only */ + uint32_t BIT1ERR : 1; /* [15] read only */ + uint32_t RWRNINT : 1; /* [16] read only */ + uint32_t TWRNINT : 1; /* [17] read only */ + uint32_t SYNCH : 1; /* [18] read only */ + uint32_t BUSOFFDONEINT : 1; /* [19] r/w1c */ + uint32_t ERRINT_FAST : 1; /* [20] r/w1c */ + uint32_t ERROVR : 1; /* [21] r/w1c */ + uint32_t RSVD_25_22 : 4; /* [25:22] reserve */ + uint32_t STFERR_FAST : 1; /* [26] read only */ + uint32_t FRAMERR_FAST : 1; /* [27] read only */ + uint32_t CRCERR_FAST : 1; /* [28] read only */ + uint32_t RSVD_29 : 1; /* [29] reserve */ + uint32_t BIT0ERR_FAST : 1; /* [30] read only */ + uint32_t BIT1ERR_FAST : 1; /* [31] read only */ + } CAN_ESR1; + + /* 0x24*/ + struct { + uint32_t BUF63TO32M :32; /* [31:0] r/w */ + } CAN_IMASK2; + + /* 0x28*/ + struct { + uint32_t BUF31TO0M :32; /* [31:0] r/w */ + } CAN_IMASK1; + + /* 0x2c*/ + struct { + uint32_t BUF63TO32I :32; /* [31:0] r/w */ + } CAN_IFLAG2; + + /* 0x30*/ + struct { + uint32_t BUF0I : 1; /* [0] r/w1c */ + uint32_t BUF4TO1I : 4; /* [4:1] r/w1c */ + uint32_t BUF5I : 1; /* [5] r/w1c */ + uint32_t BUF6I : 1; /* [6] r/w1c */ + uint32_t BUF7I : 1; /* [7] r/w1c */ + uint32_t BUF31TO8I :24; /* [31:8] r/w1c */ + } CAN_IFLAG1; + + /* 0x34*/ + struct { + uint32_t RSVD_10_0 :11; /* [10:0] reserve */ + uint32_t EDFLTDIS : 1; /* [11] r/w */ + uint32_t ISOCANFDEN : 1; /* [12] r/w */ + uint32_t RSVD_13 : 1; /* [13] reserve */ + uint32_t PREXCEN : 1; /* [14] r/w */ + uint32_t TIMER_SRC : 1; /* [15] r/w */ + uint32_t EACEN : 1; /* [16] r/w */ + uint32_t RRS : 1; /* [17] r/w */ + uint32_t MRP : 1; /* [18] r/w */ + uint32_t TASD : 5; /* [23:19] r/w */ + uint32_t RFFN : 4; /* [27:24] r/w */ + uint32_t WRMFRZ : 1; /* [28] r/w */ + uint32_t ECRWRE : 1; /* [29] r/w */ + uint32_t BOFFDONEMSK : 1; /* [30] r/w */ + uint32_t ERRMASK_FAST : 1; /* [31] r/w */ + } CAN_CTRL2; + + /* 0x38*/ + struct { + uint32_t RSVD_12_0 :13; /* [12:0] reserve */ + uint32_t IMB : 1; /* [13] read only */ + uint32_t VPS : 1; /* [14] read only */ + uint32_t RSVD_15 : 1; /* [15] reserve */ + uint32_t LPTM : 7; /* [22:16] read only */ + uint32_t RSVD_31_23 : 9; /* [31:23] */ + } CAN_ESR2; + + uint8_t zResverd0x03C[8]; /*pad 0x03C - 043*/ + + /* 0x44*/ + struct { + uint32_t TXCRC :15; /* [14:0] read only */ + uint32_t RSVD_15 : 1; /* [15] reserve */ + uint32_t MBCRC : 7; /* [22:16] read only */ + uint32_t RSVD_31_23 : 9; /* [31:23] reserve */ + } CAN_CRCR; + + /* 0x48*/ + struct { + uint32_t FGM :32; /* [31:0] r/w */ + } CAN_RXFGMASK; + + /* 0x4c*/ + struct { + uint32_t IDHIT : 9; /* [8:0] read only */ + uint32_t RSVD_31_9 :23; /* [31:9] reserve */ + } CAN_RXFIR; + + /* 0x50*/ + struct { + uint32_t EPSEG2 : 5; /* [4:0] r/w */ + uint32_t EPSEG1 : 5; /* [9:5] r/w */ + uint32_t EPROPSEG : 6; /* [15:10] r/w */ + uint32_t ERJW : 5; /* [20:16] r/w */ + uint32_t EPRESDIV :10; /* [30:21] r/w */ + uint32_t BTF : 1; /* [31] r/w */ + } CAN_CBT; + + uint8_t zResverd0x054[20]; /*pad 0x054 - 067*/ + + /* 0x68*/ + struct { + uint32_t BUF127TO96M :32; /* [31:0] r/w */ + } CAN_IMASK4; + + /* 0x6c*/ + struct { + uint32_t BUF95TO64M :32; /* [31:0] r/w */ + } CAN_IMASK3; + + /* 0x70*/ + struct { + uint32_t BUF127TO96I :32; /* [31:0] r/w1c */ + } CAN_IFLAG4; + + /* 0x74*/ + struct { + uint32_t BUF95TO64I :32; /* [31:0] r/w1c */ + } CAN_IFLAG3; + + uint8_t zResverd0x078[8]; /*pad 0x078 - 07F*/ + + /* 0x80 */ + struct { + struct { + uint32_t TIME_STAMP :16; /* [15:0] */ + uint32_t DLC : 4; /* [19:16] */ + uint32_t RTR : 1; /* [20] */ + uint32_t IDE : 1; /* [21] */ + uint32_t SRR : 1; /* [22] */ + uint32_t RSVD_23 : 1; /* [23] */ + uint32_t CODE : 4; /* [27:24] */ + uint32_t RSVD_28 : 1; /* [28] */ + uint32_t ESI : 1; /* [29] */ + uint32_t BRS : 1; /* [30] */ + uint32_t EDL : 1; /* [31] */ + } MB0; + + /* 0x84*/ + struct { + uint32_t ID_EXTEND :18; /* [17:0] */ + uint32_t ID_STANDARD :11; /* [28:18] */ + uint32_t PRIO : 3; /* [31:29] */ + } MB1; + + /* 0x88*/ + struct { + uint32_t DATA_BYTE :32; /* [31:0] */ + } MB2; + + /* 0x8c*/ + struct { + uint32_t DATA_BYTE :32; /* [31:0] */ + } MB3; + } CAN_MB[64]; + uint8_t zResverd0x0480[0x400]; /*pad 0x0480 - 087F*/ + + /* 0x880*/ + struct { + uint32_t MI : 32; /* [1] */ + } CAN_RXIMR[64]; + + uint8_t zResverd0x0A80[352]; /*pad 0x0A80 - 0ADF, 64*4 + 96*/ + + /* 0xAE0*/ + struct { + uint32_t RSVD_6_0 : 7; /* [6:0] reserve */ + uint32_t NCEFAFRZ : 1; /* [7] r/w */ + uint32_t ECCDIS : 1; /* [8] r/w */ + uint32_t RERRDIS : 1; /* [9] r/w */ + uint32_t RSVD_12_10 : 3; /* [12:10] reserve */ + uint32_t EXTERRIE : 1; /* [13] r/w */ + uint32_t FAERRIE : 1; /* [14] r/w */ + uint32_t HAERRI : 1; /* [15] r/w */ + uint32_t CEI_MSK : 1; /* [16] r/w */ + uint32_t RSVD_17 : 1; /* [17] reserve */ + uint32_t FANCEI_MSK : 1; /* [18] r/w */ + uint32_t HANCEI_MSK : 1; /* [19] r/w */ + uint32_t RSVD_30_20 :11; /* [30:20] reserve */ + uint32_t ECRWRDIS : 1; /* [31] r/w */ + } CAN_MECR; + + /* 0xAE4*/ + struct { + uint32_t INJADDR_L : 2; /* [1:0] r/w */ + uint32_t INJADDR_H :12; /* [13:2] r/w */ + uint32_t RSVD_31_14 :18; /* [31:14] reserve */ + } CAN_ERRIAR; + + /* 0xAE8*/ + struct { + uint32_t DFLIP :32; /* [31:0] r/w */ + } CAN_ERRIDPR; + + /* 0xAEC*/ + struct { + uint32_t PFLIP0 : 5; /* [4:0] r/w */ + uint32_t RSVD_7_5 : 3; /* [7:5] reserve */ + uint32_t PFLIP1 : 5; /* [12:8] r/w */ + uint32_t RSVD_15_13 : 3; /* [15:13] reserve */ + uint32_t PFLIP2 : 5; /* [20:16] r/w */ + uint32_t RSVD_23_21 : 3; /* [23:21] reserve */ + uint32_t PFLIP3 : 5; /* [28:24] r/w */ + uint32_t RSVD_31_29 : 3; /* [31:29] reserve */ + } CAN_ERRIPPR; + + /* 0xAF0*/ + struct { + uint32_t ERRADDR :14; /* [13:0] read only */ + uint32_t RSVD_15_14 : 2; /* [15:14] reserve */ + uint32_t SAID : 3; /* [18:16] read only */ + uint32_t RSVD_23_19 : 5; /* [23:19] reserve */ + uint32_t NCE : 1; /* [24] read only */ + uint32_t RSVD_31_25 : 7; /* [31:25] reserve */ + } CAN_RERRAR; + + /* 0xAF4*/ + struct { + uint32_t RDATA :32; /* [31:0] read only */ + } CAN_RERRDR; + + /* 0xAF8*/ + struct { + uint32_t SYND0 : 5; /* [4:0] read only */ + uint32_t RSVD_6_5 : 2; /* [6:5] reserve */ + uint32_t BE0 : 1; /* [7] read only */ + uint32_t SYND1 : 5; /* [12:8] read only */ + uint32_t RSVD_14_13 : 2; /* [14:13] read only */ + uint32_t BE1 : 1; /* [15] read only */ + uint32_t SYND2 : 5; /* [20:16] read only */ + uint32_t RSVD_22_21 : 2; /* [22:21] reserve */ + uint32_t BE2 : 1; /* [23] read only */ + uint32_t SYND3 : 5; /* [28:24] read only */ + uint32_t RSVD_30_29 : 2; /* [30:29] reserve */ + uint32_t BE3 : 1; /* [31] read only */ + } CAN_RERRSYNR; + + /* 0xAFC*/ + struct { + uint32_t CEIOF : 1; /* [0] r/w1c */ + uint32_t RSVD_1 : 1; /* [1] reserve */ + uint32_t FANCEIOF : 1; /* [2] r/w1c */ + uint32_t HANCEIOF : 1; /* [3] r/w1c */ + uint32_t RSVD_15_4 :12; /* [15:4] reserve */ + uint32_t CEIF : 1; /* [16] r/w1c */ + uint32_t RSVD_17 : 1; /* [17] reserve */ + uint32_t FANCEIF : 1; /* [18] r/w1c */ + uint32_t HANCEIF : 1; /* [19] r/w1c */ + uint32_t RSVD_31_20 :12; /* [31:20] reserve */ + } CAN_ERRSR; + + /* 0xB00*/ + struct { + uint32_t FCS : 2; /* [1:0] r/w */ + uint32_t IDFS : 2; /* [3:2] r/w */ + uint32_t PLFS : 2; /* [5:4] r/w */ + uint32_t RSVD_7_6 : 2; /* [7:6] reserve */ + uint32_t NMATCH : 8; /* [15:8 ] r/w */ + uint32_t WUMF_MSK : 1; /* [16] r/w */ + uint32_t WTOF_MSK : 1; /* [17] r/w */ + uint32_t RSVD_31_18 :14; /* [31:18] */ + } CAN_CTRL1_PN; + + /* 0xB04*/ + struct { + uint32_t MATCHTO :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] reserve */ + } CAN_CTRL2_PN; + + /* 0xB08*/ + struct { + uint32_t RSVD_7_0 : 8; /* [7:0] reserve */ + uint32_t MCOUNTER : 8; /* [15:8] read only */ + uint32_t WUMF : 1; /* [16] r/w1c */ + uint32_t WTOF : 1; /* [17] r/w1c */ + uint32_t RSVD_31_18 :14; /* [31:18] reserve */ + } CAN_WU_MTC; + + /* 0xB0C*/ + struct { + uint32_t FLT_ID1 :29; /* [28:0] r/w */ + uint32_t FLT_RTR : 1; /* [29] r/w */ + uint32_t FLT_IDE : 1; /* [30] r/w */ + uint32_t RSVD_31 : 1; /* [31] reserve */ + } CAN_FLT_ID1; + + /* 0xB10*/ + struct { + uint32_t FLT_DLC_HI : 4; /* [3:0] */ + uint32_t RSVD_15_4 :12; /* [15:4] reserve */ + uint32_t FLT_DLC_LO : 4; /* [19:16] r/w */ + uint32_t RSVD_31_20 :12; /* [31:20] reserve */ + } CAN_FLT_DLC; + + /* 0xB14*/ + struct { + uint32_t DATA_BYTE_3 : 8; /* [7:0] r/w */ + uint32_t DATA_BYTE_2 : 8; /* [15:8] r/w */ + uint32_t DATA_BYTE_1 : 8; /* [23:16] r/w */ + uint32_t DATA_BYTE_0 : 8; /* [31:24] r/w */ + } CAN_PL1_LO; + + /* 0xB18*/ + struct { + uint32_t DATA_BYTE_7 : 8; /* [7:0] r/w */ + uint32_t DATA_BYTE_6 : 8; /* [15:8] r/w */ + uint32_t DATA_BYTE_5 : 8; /* [23:16] r/w */ + uint32_t DATA_BYTE_4 : 8; /* [31:24] r/w */ + } CAN_PL1_HI; + + /* 0xB1C*/ + struct { + uint32_t FLT_ID2_IDMASK :29; /* [28:0] r/w */ + uint32_t RTR_MSK : 1; /* [29] r/w */ + uint32_t IDE_MSK : 1; /* [30] r/w */ + uint32_t RSVD_31 : 1; /* [31] reserve */ + } CAN_FLT_ID2_IDMASK; + + /* 0xB20*/ + struct { + uint32_t DATA_BYTE_3 : 8; /* [7:0] r/w */ + uint32_t DATA_BYTE_2 : 8; /* [15:8] r/w */ + uint32_t DATA_BYTE_1 : 8; /* [23:16] r/w */ + uint32_t DATA_BYTE_0 : 8; /* [31:24] r/w */ + } CAN_PL2_PLMASK_LO; + + /* 0xB24*/ + struct { + uint32_t DATA_BYTE_7 : 8; /* [7:0] r/w */ + uint32_t DATA_BYTE_6 : 8; /* [15:8] r/w */ + uint32_t DATA_BYTE_5 : 8; /* [23:16] r/w */ + uint32_t DATA_BYTE_4 : 8; /* [31:24] r/w */ + } CAN_PL2_PLMASK_HI; + + uint8_t zResverd0x0B28[24]; /*pad 0x0B28 - 0B3F*/ + + struct { + /* 0xB40*/ + struct { + uint32_t RSVD_15_0 :16; /* [15:0] reserve */ + uint32_t DLC : 4; /* [19:16] read only */ + uint32_t RTR : 1; /* [20] read only */ + uint32_t IDE : 1; /* [21] read only */ + uint32_t SRR : 1; /* [22] read only */ + uint32_t RSVD_31_23 : 9; /* [31:23] reserve */ + } CS; + + /* 0xB44*/ + struct { + uint32_t ID :29; /* [28:0] read only */ + uint32_t RSVD_31_29 : 3; /* [31:29] reserve */ + } ID; + + /* 0xB48*/ + struct { + uint32_t DATA_BYTE_3 : 8; /* [7:0] read only */ + uint32_t DATA_BYTE_2 : 8; /* [15:8] read only */ + uint32_t DATA_BYTE_1 : 8; /* [23:16] read only */ + uint32_t DATA_BYTE_0 : 8; /* [31:24] read only */ + } D03; + + /* 0xB4C*/ + struct { + uint32_t DATA_BYTE_7 : 8; /* [7:0] read only */ + uint32_t DATA_BYTE_6 : 8; /* [15:8] read only */ + uint32_t DATA_BYTE_5 : 8; /* [23:16] read only */ + uint32_t DATA_BYTE_4 : 8; /* [31:24] read only */ + } D47; + } CAN_WMB[4]; + + uint8_t zResverd0x0B80[0x80]; /*pad 0x0B80 - 0BFF*/ + + /* 0xC00*/ + struct { + uint32_t TDCVAL : 6; /* [5:0] read only */ + uint32_t RSVD_7_6 : 2; /* [7:6] reserve */ + uint32_t TDCOFF : 5; /* [12:8] r/w */ + uint32_t RSVD_13 : 1; /* [13] reserve */ + uint32_t TDCFAIL : 1; /* [14] r/w1c */ + uint32_t TDCEN : 1; /* [15] r/w */ + uint32_t MBDSR0 : 2; /* [17:16] r/w */ + uint32_t RSVD_18 : 1; /* [18] reserve */ + uint32_t MBDSR1 : 2; /* [20:19] r/w */ + uint32_t RSVD_21 : 1; /* [21] reserve */ + uint32_t MBDSR2 : 2; /* [23:22] r/w */ + uint32_t RSVD_24 : 1; /* [24] reserve */ + uint32_t MBDSR3 : 2; /* [26:25] r/w */ + uint32_t RSVD_30_27 : 4; /* [30:27] reserve */ + uint32_t FD_RATE : 1; /* [31] r/w */ + } CAN_FDCTRL; + + /* 0xC04*/ + struct { + uint32_t FPSEG2 : 3; /* [2:0] r/w */ + uint32_t RSVD_4_3 : 2; /* [4:3] reserve */ + uint32_t FPSEG1 : 3; /* [7:5] r/w */ + uint32_t RSVD_9_8 : 2; /* [9:8] reserve */ + uint32_t FPROPSEG : 5; /* [14:10] r/w */ + uint32_t RSVD_15 : 1; /* [15] reserve */ + uint32_t FRJW : 3; /* [18:16] r/w */ + uint32_t RSVD_19 : 1; /* [19] reserve */ + uint32_t FPRESDIV :10; /* [29:20] r/w */ + uint32_t RSVD_31_30 : 2; /* [31:30] reserve */ + } CAN_FDCBT; + + /* 0xC08*/ + struct { + uint32_t FD_TXCRC :21; /* [20:0] read only */ + uint32_t RSVD_23_21 : 3; /* [23:21] reserve */ + uint32_t FD_MBCRC : 7; /* [30:24] read only */ + uint32_t RSVD_31 : 1; /* [31] reserve */ + } CAN_FDCRC; + +}; /*can_reg*/ + +struct can_reg_w { + /* 0x00*/ + uint32_t CAN_MCR; + /* 0x04*/ + uint32_t CAN_CTRL1; + /* 0x08*/ + uint32_t CAN_TIMER; + uint8_t zResverd0x0C[4]; /*pad 0x0C - 0F*/ + + /* 0x10*/ + uint32_t CAN_RXMGMSK; + /* 0x14*/ + uint32_t CAN_RX14MASK; + /* 0x18*/ + uint32_t CAN_RX15MASK; + /* 0x1c*/ + uint32_t CAN_ECR; + /* 0x20*/ + uint32_t CAN_ESR1; + /* 0x24*/ + uint32_t CAN_IMASK2; + /* 0x28*/ + uint32_t CAN_IMASK1; + /* 0x2c*/ + uint32_t CAN_IFLAG2; + /* 0x30*/ + uint32_t CAN_IFLAG1; + /* 0x34*/ + uint32_t CAN_CTRL2; + /* 0x38*/ + uint32_t CAN_ESR2; + uint8_t zResverd0x03C[8]; /*pad 0x03C - 043*/ + + /* 0x44*/ + uint32_t CAN_CRCR; + /* 0x48*/ + uint32_t CAN_RXFGMASK; + /* 0x4c*/ + uint32_t CAN_RXFIR; + /* 0x50*/ + uint32_t CAN_CBT; + uint8_t zResverd0x054[20]; /*pad 0x054 - 067*/ + + /* 0x68*/ + uint32_t CAN_IMASK4; + /* 0x6c*/ + uint32_t CAN_IMASK3; + /* 0x70*/ + uint32_t CAN_IFLAG4; + /* 0x74*/ + uint32_t CAN_IFLAG3; + uint8_t zResverd0x078[8]; /*pad 0x078 - 07F*/ + + struct { + /* 0x80 */ + uint32_t MB0; + /* 0x84*/ + uint32_t MB1; + /* 0x88*/ + uint32_t MB2; + /* 0x8c*/ + uint32_t MB3; + } CAN_MB[64]; + uint8_t zResverd0x0480[0x400]; /*pad 0x0480 - 087F*/ + + /* 0x880*/ + uint32_t CAN_RXIMR[64]; + uint8_t zResverd0x0A80[352]; /*pad 0x0A80 - 0ADF, 64*4 + 96*/ + + /* 0xAE0*/ + uint32_t CAN_MECR; + /* 0xAE4*/ + uint32_t CAN_ERRIAR; + /* 0xAE8*/ + uint32_t CAN_ERRIDPR; + /* 0xAEC*/ + uint32_t CAN_ERRIPPR; + /* 0xAF0*/ + uint32_t CAN_RERRAR; + /* 0xAF4*/ + uint32_t CAN_RERRDR; + /* 0xAF8*/ + uint32_t CAN_RERRSYNR; + /* 0xAFC*/ + uint32_t CAN_ERRSR; + /* 0xB00*/ + uint32_t CAN_CTRL1_PN; + /* 0xB04*/ + uint32_t CAN_CTRL2_PN; + /* 0xB08*/ + uint32_t CAN_WU_MTC; + /* 0xB0C*/ + uint32_t CAN_FLT_ID1; + /* 0xB10*/ + uint32_t CAN_FLT_DLC; + /* 0xB14*/ + uint32_t CAN_PL1_LO; + /* 0xB18*/ + uint32_t CAN_PL1_HI; + /* 0xB1C*/ + uint32_t CAN_FLT_ID2_IDMASK; + /* 0xB20*/ + uint32_t CAN_PL2_PLMASK_LO; + /* 0xB24*/ + uint32_t CAN_PL2_PLMASK_HI; + + uint8_t zResverd0x0B28[24]; /*pad 0x0B28 - 0B3F*/ + struct { + /* 0xB40*/ + uint32_t CS; + /* 0xB44*/ + uint32_t ID; + /* 0xB48*/ + uint32_t D03; + /* 0xB4C*/ + uint32_t D47; + } CAN_WMB[4]; + + uint8_t zResverd0x0B80[0x80]; /*pad 0x0B80 - 0BFF*/ + + /* 0xC00*/ + uint32_t CAN_FDCTRL; + /* 0xC04*/ + uint32_t CAN_FDCBT; + /* 0xC08*/ + uint32_t CAN_FDCRC; +}; /*can_reg*/ + +typedef volatile struct can_reg can_reg_t; +typedef volatile struct can_reg_w can_reg_w_t; + +struct cmp_reg { + /* 0x0*/ + struct { + uint32_t VERID :32; /* [31:0] ro */ + } CMP_VERID; + + /* 0x4*/ + struct { + uint32_t DAC_RES : 4; /* [3:0] ro */ + uint32_t RSVD_31_4 :28; /* [31:4] */ + } CMP_PARAM; + + /* 0x8*/ + struct { + uint32_t CMP_SEL : 1; /* [0] r/w */ + uint32_t CMP_EN : 1; /* [1] r/w */ + uint32_t SOC_TRG_EN : 1; /* [2] r/w */ + uint32_t STOP_EN : 1; /* [3] r/w */ + uint32_t RSVD_31_4 :28; /* [31:4] */ + } CMP_CCR0; + + /* 0xC*/ + struct { + uint32_t WINDOW_EN : 1; /* [0] r/w */ + uint32_t SAMPLE_EN : 1; /* [1] r/w */ + uint32_t DMA_EN : 1; /* [2] r/w */ + uint32_t COUT_INV : 1; /* [3] r/w */ + uint32_t COUT_SEL : 1; /* [4] r/w */ + uint32_t COUT_PEN : 1; /* [5] r/w */ + uint32_t COUT_OWE : 1; /* [6] r/w */ + uint32_t COUT_OW : 1; /* [7] r/w */ + uint32_t RSVD_15_8 : 8; /* [15:8] */ + uint32_t FILT_CNT : 3; /* [18:16] r/w */ + uint32_t RSVD_23_19 : 5; /* [23:19] */ + uint32_t FILT_PER : 8; /* [31:24] r/w */ + } CMP_CCR1; + + /* 0x10*/ + struct { + uint32_t HS_HSTCTR : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] */ + uint32_t LS_HSTCTR : 2; /* [5:4] r/w */ + uint32_t RSVD_15_6 :10; /* [15:6] */ + uint32_t HS_PSEL : 4; /* [19:16] r/w */ + uint32_t HS_MSEL : 4; /* [23:20] r/w */ + uint32_t LS_PSEL : 4; /* [27:24] r/w */ + uint32_t LS_MSEL : 4; /* [31:28] r/w */ + } CMP_CCR2; + + /* 0x14*/ + struct { + uint32_t DAC_EN : 1; /* [0] r/w */ + uint32_t RSVD_1 : 1; /* [1] */ + uint32_t RSVD_7_2 : 6; /* [7:2] */ + uint32_t VREF_SEL : 1; /* [8] r/w */ + uint32_t RSVD_15_9 : 7; /* [15:9] */ + uint32_t DAC_SEL : 8; /* [23:16] r/w */ + uint32_t RSVD_31_24 : 8; /* [31:24] */ + } CMP_DCR; + + /* 0x18*/ + struct { + uint32_t CFR_IE : 1; /* [0] r/w */ + uint32_t CFF_IE : 1; /* [1] r/w */ + uint32_t RSVD_31_2 :30; /* [31:2] */ + } CMP_IER; + + /* 0x1C*/ + struct { + uint32_t CFR : 1; /* [0] r/w1c */ + uint32_t CFF : 1; /* [1] r/w1c */ + uint32_t RSVD_7_2 : 6; /* [7:2] */ + uint32_t COUT : 1; /* [8] ro */ + uint32_t RSVD_31_9 :23; /* [31:9] */ + } CMP_CSR; + +}; /*cmp_reg*/ + +struct cmp_reg_w { + /* 0x0*/ + uint32_t CMP_VERID; + /* 0x4*/ + uint32_t CMP_PARAM; + /* 0x8*/ + uint32_t CMP_CCR0; + /* 0xC*/ + uint32_t CMP_CCR1; + /* 0x10*/ + uint32_t CMP_CCR2; + /* 0x14*/ + uint32_t CMP_DCR; + /* 0x18*/ + uint32_t CMP_IER; + /* 0x1C*/ + uint32_t CMP_CSR; +}; /*cmp_reg*/ + +typedef volatile struct cmp_reg cmp_reg_t; +typedef volatile struct cmp_reg_w cmp_reg_w_t; + +struct crc_reg { + /* 0x0*/ + struct { + uint32_t FEATURE :16; /* [15:0] r */ + uint32_t MINOR : 8; /* [23:16] r */ + uint32_t MAJOR : 8; /* [31:24] r */ + } CRC_VERID; + + /* 0x4*/ + struct { + uint32_t RSVD_31_0 :32; /* [31:0] r */ + } CRC_PARAM; + + /* 0x8*/ + struct { + uint32_t BYTE0 : 8; /* [7:0] r/w */ + uint32_t BYTE1 : 8; /* [15:8] r/w */ + uint32_t BYTE2 : 8; /* [23:16] r/w */ + uint32_t BYTE3 : 8; /* [31:24] r/w */ + } CRC_DATA; + + /* 0xC*/ + struct { + uint32_t LPHW :16; /* [15:0] r/w */ + uint32_t HPHW :16; /* [31:16] r/w */ + } CRC_POLY; + + /* 0x10*/ + struct { + uint32_t MODE : 1; /* [0] r/w */ + uint32_t WS : 1; /* [1] r/w */ + uint32_t CR : 1; /* [2] r/w */ + uint32_t RSVD_3 : 1; /* [3] r */ + uint32_t RT : 2; /* [5:4] r/w */ + uint32_t WT : 2; /* [7:6] r/w */ + uint32_t RSVD_31_8 :24; /* [31:8] r */ + } CRC_CTRL; + +}; /*crc_reg*/ + +struct crc_reg_w { + /* 0x0*/ + uint32_t CRC_VERID; + /* 0x4*/ + uint32_t CRC_PARAM; + /* 0x8*/ + uint32_t CRC_DATA; + /* 0xC*/ + uint32_t CRC_POLY; + /* 0x10*/ + uint32_t CRC_CTRL; +}; /*crc_reg*/ + +typedef volatile struct crc_reg crc_reg_t; +typedef volatile struct crc_reg_w crc_reg_w_t; + +struct dma_chmux_reg { + /* 0x00*/ + struct { + uint32_t ENABLE : 1; /* [0] r/w */ + uint32_t SRC_MUX : 6; /* [6:1] r/w */ + uint32_t RSVD_31_7 :25; /* [31:7] reserve */ + } DMA_MUX_CH_CFG[16]; + +}; /*dma_chmux_reg*/ + +struct dma_chmux_reg_w { + /* 0x00*/ + uint32_t DMA_MUX_CH_CFG[16]; +}; /*dma_chmux_reg*/ + +typedef volatile struct dma_chmux_reg dma_chmux_reg_t; +typedef volatile struct dma_chmux_reg_w dma_chmux_reg_w_t; + +struct dma_reg { + /* 0x00*/ + struct { + uint32_t HALT : 1; /* [0] r/w */ + uint32_t HOEE : 1; /* [1] r/w */ + uint32_t RRCAE : 1; /* [2] r/w */ + uint32_t DBGE : 1; /* [3] r/w */ + uint32_t RSVD_5_4 : 2; /* [5:4] */ + uint32_t BUSY : 1; /* [6] r/o */ + uint32_t RSVD_31_7 :25; /* [31:7] */ + } DMA_CONF; + + /* 0x04*/ + struct { + uint32_t DMAE0 : 1; /* [0] r/w */ + uint32_t DMAE1 : 1; /* [1] r/w */ + uint32_t DMAE2 : 1; /* [2] r/w */ + uint32_t DMAE3 : 1; /* [3] r/w */ + uint32_t DMAE4 : 1; /* [4] r/w */ + uint32_t DMAE5 : 1; /* [5] r/w */ + uint32_t DMAE6 : 1; /* [6] r/w */ + uint32_t DMAE7 : 1; /* [7] r/w */ + uint32_t DMAE8 : 1; /* [8] r/w */ + uint32_t DMAE9 : 1; /* [9] r/w */ + uint32_t DMAE10 : 1; /* [10] r/w */ + uint32_t DMAE11 : 1; /* [11] r/w */ + uint32_t DMAE12 : 1; /* [12] r/w */ + uint32_t DMAE13 : 1; /* [13] r/w */ + uint32_t DMAE14 : 1; /* [14] r/w */ + uint32_t DMAE15 : 1; /* [15] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } DMA_DMAE; + + uint8_t zResverd0x08[4]; /*pad 0x08 - 0B*/ + + /* 0x0C*/ + struct { + uint32_t EIE0 : 1; /* [0] r/w */ + uint32_t EIE1 : 1; /* [1] r/w */ + uint32_t EIE2 : 1; /* [2] r/w */ + uint32_t EIE3 : 1; /* [3] r/w */ + uint32_t EIE4 : 1; /* [4] r/w */ + uint32_t EIE5 : 1; /* [5] r/w */ + uint32_t EIE6 : 1; /* [6] r/w */ + uint32_t EIE7 : 1; /* [7] r/w */ + uint32_t EIE8 : 1; /* [8] r/w */ + uint32_t EIE9 : 1; /* [9] r/w */ + uint32_t EIE10 : 1; /* [10] r/w */ + uint32_t EIE11 : 1; /* [11] r/w */ + uint32_t EIE12 : 1; /* [12] r/w */ + uint32_t EIE13 : 1; /* [13] r/w */ + uint32_t EIE14 : 1; /* [14] r/w */ + uint32_t EIE15 : 1; /* [15] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } DMA_EIE; + + uint8_t zResverd0x010[4]; /*pad 0x010 - 013*/ + + /* 0x14*/ + struct { + uint32_t CCDONE : 4; /* [3:0] w/o */ + uint32_t RSVD_5_4 : 2; /* [5:4] */ + uint32_t CACDONE : 1; /* [6] w/o */ + uint32_t WPEN0 : 1; /* [7] w/o */ + uint32_t SCSTART : 4; /* [11:8] w/o */ + uint32_t RSVD_13_12 : 2; /* [13:12] */ + uint32_t SACSTART : 1; /* [14] w/o */ + uint32_t WPEN1 : 1; /* [15] w/o */ + uint32_t CCES : 4; /* [19:16] w/o */ + uint32_t RSVD_21_20 : 2; /* [21:20] */ + uint32_t CACES : 1; /* [22] w/o */ + uint32_t WPEN2 : 1; /* [23] w/o */ + uint32_t CCIS : 4; /* [27:24] w/o */ + uint32_t RSVD_29_28 : 2; /* [29:28] */ + uint32_t CACIS : 1; /* [30] w/o */ + uint32_t WPEN3 : 1; /* [31] w/o */ + } DMA_GCC; + + /* 0x18*/ + struct { + uint32_t DBEF : 1; /* [0] r/o */ + uint32_t SBEF : 1; /* [1] r/o */ + uint32_t RSVD_2 : 1; /* [2] */ + uint32_t NUMEF : 1; /* [3] r/o */ + uint32_t DOEF : 1; /* [4] r/o */ + uint32_t DAEF : 1; /* [5] r/o */ + uint32_t SOEF : 1; /* [6] r/o */ + uint32_t SAEF : 1; /* [7] r/o */ + uint32_t CHEF : 4; /* [11:8] r/o */ + uint32_t RSVD_12 : 1; /* [12] */ + uint32_t PRIEF : 1; /* [13] r/o */ + uint32_t RSVD_14 : 1; /* [14] */ + uint32_t ERRF : 1; /* [15] r/o */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } DMA_ES; + + /* 0x1C*/ + struct { + uint32_t ERR0 : 1; /* [0] r/o */ + uint32_t ERR1 : 1; /* [1] r/o */ + uint32_t ERR2 : 1; /* [2] r/o */ + uint32_t ERR3 : 1; /* [3] r/o */ + uint32_t ERR4 : 1; /* [4] r/o */ + uint32_t ERR5 : 1; /* [5] r/o */ + uint32_t ERR6 : 1; /* [6] r/o */ + uint32_t ERR7 : 1; /* [7] r/o */ + uint32_t ERR8 : 1; /* [8] r/o */ + uint32_t ERR9 : 1; /* [9] r/o */ + uint32_t ERR10 : 1; /* [10] r/o */ + uint32_t ERR11 : 1; /* [11] r/o */ + uint32_t ERR12 : 1; /* [12] r/o */ + uint32_t ERR13 : 1; /* [13] r/o */ + uint32_t ERR14 : 1; /* [14] r/o */ + uint32_t ERR15 : 1; /* [15] r/o */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } DMA_CES; + + /* 0x20*/ + struct { + uint32_t INT0 : 1; /* [0] r/o */ + uint32_t INT1 : 1; /* [1] r/o */ + uint32_t INT2 : 1; /* [2] r/o */ + uint32_t INT3 : 1; /* [3] r/o */ + uint32_t INT4 : 1; /* [4] r/o */ + uint32_t INT5 : 1; /* [5] r/o */ + uint32_t INT6 : 1; /* [6] r/o */ + uint32_t INT7 : 1; /* [7] r/o */ + uint32_t INT8 : 1; /* [8] r/o */ + uint32_t INT9 : 1; /* [9] r/o */ + uint32_t INT10 : 1; /* [10] r/o */ + uint32_t INT11 : 1; /* [11] r/o */ + uint32_t INT12 : 1; /* [12] r/o */ + uint32_t INT13 : 1; /* [13] r/o */ + uint32_t INT14 : 1; /* [14] r/o */ + uint32_t INT15 : 1; /* [15] r/o */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } DMA_CIS; + + /* 0x24*/ + struct { + uint32_t HRS0 : 1; /* [0] r/o */ + uint32_t HRS1 : 1; /* [1] r/o */ + uint32_t HRS2 : 1; /* [2] r/o */ + uint32_t HRS3 : 1; /* [3] r/o */ + uint32_t HRS4 : 1; /* [4] r/o */ + uint32_t HRS5 : 1; /* [5] r/o */ + uint32_t HRS6 : 1; /* [6] r/o */ + uint32_t HRS7 : 1; /* [7] r/o */ + uint32_t HRS8 : 1; /* [8] r/o */ + uint32_t HRS9 : 1; /* [9] r/o */ + uint32_t HRS10 : 1; /* [10] r/o */ + uint32_t HRS11 : 1; /* [11] r/o */ + uint32_t HRS12 : 1; /* [12] r/o */ + uint32_t HRS13 : 1; /* [13] r/o */ + uint32_t HRS14 : 1; /* [14] r/o */ + uint32_t HRS15 : 1; /* [15] r/o */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } DMA_CHRS; + + /* 0x28*/ + struct { + uint32_t CPRI3 : 4; /* [3:0] r/w */ + uint32_t RSVD_5_4 : 2; /* [5:4] */ + uint32_t CPDIS3 : 1; /* [6] r/w */ + uint32_t CSE3 : 1; /* [7] r/w */ + uint32_t CPRI2 : 4; /* [11:8] r/w */ + uint32_t RSVD_13_12 : 2; /* [13:12] */ + uint32_t CPDIS2 : 1; /* [14] r/w */ + uint32_t CSE2 : 1; /* [15] r/w */ + uint32_t CPRI1 : 4; /* [19:16] r/w */ + uint32_t RSVD_21_20 : 2; /* [21:20] */ + uint32_t CPDIS1 : 1; /* [22] r/w */ + uint32_t CSE1 : 1; /* [23] r/w */ + uint32_t CPRI0 : 4; /* [27:24] r/w */ + uint32_t RSVD_29_28 : 2; /* [29:28] */ + uint32_t CPDIS0 : 1; /* [30] r/w */ + uint32_t CSE0 : 1; /* [31] r/w */ + } DMA_CPRI0; + + /* 0x2C*/ + struct { + uint32_t CPRI7 : 4; /* [3:0] r/w */ + uint32_t RSVD_5_4 : 2; /* [5:4] */ + uint32_t CPDIS7 : 1; /* [6] r/w */ + uint32_t CSE7 : 1; /* [7] r/w */ + uint32_t CPRI6 : 4; /* [11:8] r/w */ + uint32_t RSVD_13_12 : 2; /* [13:12] */ + uint32_t CPDIS6 : 1; /* [14] r/w */ + uint32_t CSE6 : 1; /* [15] r/w */ + uint32_t CPRI5 : 4; /* [19:16] r/w */ + uint32_t RSVD_21_20 : 2; /* [21:20] */ + uint32_t CPDIS5 : 1; /* [22] r/w */ + uint32_t CSE5 : 1; /* [23] r/w */ + uint32_t CPRI4 : 4; /* [27:24] r/w */ + uint32_t RSVD_29_28 : 2; /* [29:28] */ + uint32_t CPDIS4 : 1; /* [30] r/w */ + uint32_t CSE4 : 1; /* [31] r/w */ + } DMA_CPRI1; + + /* 0x30*/ + struct { + uint32_t CPRI11 : 4; /* [3:0] r/w */ + uint32_t RSVD_5_4 : 2; /* [5:4] */ + uint32_t CPDIS11 : 1; /* [6] r/w */ + uint32_t CSE11 : 1; /* [7] r/w */ + uint32_t CPRI10 : 4; /* [11:8] r/w */ + uint32_t RSVD_13_12 : 2; /* [13:12] */ + uint32_t CPDIS10 : 1; /* [14] r/w */ + uint32_t CSE10 : 1; /* [15] r/w */ + uint32_t CPRI9 : 4; /* [19:16] r/w */ + uint32_t RSVD_21_20 : 2; /* [21:20] */ + uint32_t CPDIS9 : 1; /* [22] r/w */ + uint32_t CSE9 : 1; /* [23] r/w */ + uint32_t CPRI8 : 4; /* [27:24] r/w */ + uint32_t RSVD_29_28 : 2; /* [29:28] */ + uint32_t CPDIS8 : 1; /* [30] r/w */ + uint32_t CSE8 : 1; /* [31] r/w */ + } DMA_CPRI2; + + /* 0x34*/ + struct { + uint32_t CPRI15 : 4; /* [3:0] r/w */ + uint32_t RSVD_5_4 : 2; /* [5:4] */ + uint32_t CPDIS15 : 1; /* [6] r/w */ + uint32_t CSE15 : 1; /* [7] r/w */ + uint32_t CPRI14 : 4; /* [11:8] r/w */ + uint32_t RSVD_13_12 : 2; /* [13:12] */ + uint32_t CPDIS14 : 1; /* [14] r/w */ + uint32_t CSE14 : 1; /* [15] r/w */ + uint32_t CPRI13 : 4; /* [19:16] r/w */ + uint32_t RSVD_21_20 : 2; /* [21:20] */ + uint32_t CPDIS13 : 1; /* [22] r/w */ + uint32_t CSE13 : 1; /* [23] r/w */ + uint32_t CPRI12 : 4; /* [27:24] r/w */ + uint32_t RSVD_29_28 : 2; /* [29:28] */ + uint32_t CPDIS12 : 1; /* [30] r/w */ + uint32_t CSE12 : 1; /* [31] r/w */ + } DMA_CPRI3; + + uint8_t zResverd0x038[456]; /*pad 0x038 - 01FF*/ + + struct { + /* 0x200*/ + struct { + uint32_t SADDR : 32; /* [31:0] r/w */ + } DMA_SADDR; + + /* 0x204*/ + struct { + uint32_t DADDR : 32; /* [31:0] r/w */ + } DMA_DADDR; + + /* 0x208*/ + struct { + int32_t SAOFF : 16; /* [15:0] r/w */ + int32_t DAOFF : 16; /* [31:16] r/w */ + } DMA_AOFF; + + /* 0x20C*/ + struct { + int32_t MLSAOFF : 16; /* [15:0] r/w */ + int32_t MLDAOFF : 16; /* [31:16] r/w */ + } DMA_MLAOFF; + + /* 0x210*/ + struct { + uint32_t NUM : 32; /* [31:0] r/w */ + } DMA_NUM; + + /* 0x214*/ + struct { + uint32_t MLITER : 15; /* [14:0] r/w */ + uint32_t RSVD_15: 1 ; /* [15] */ + uint32_t MLSTA : 15; /* [30:16] r/o */ + uint32_t RSVD_31: 1 ; /* [31] */ + } DMA_ITER; + + /* 0x218*/ + struct { + uint32_t START : 1; /* [0] r/w */ + uint32_t INTE : 1; /* [1] r/w */ + uint32_t RSVD_2 : 1; /* [2] */ + uint32_t REQDIS : 1; /* [3] r/w */ + uint32_t RSVD_5_4 : 2; /* [5:4] */ + uint32_t BUSY : 1; /* [6] r/o */ + uint32_t DONE : 1; /* [7] r/w */ + uint32_t RSVD_15_8 : 8; /* [15:8] */ + uint32_t DSIZE : 2; /* [17:16] r/w */ + uint32_t RSVD_23_18 : 6; /* [23:18] */ + uint32_t SSIZE : 2; /* [25:24] r/w */ + uint32_t RSVD_31_26 : 6; /* [31:26] */ + } DMA_CS; + + uint8_t zResverd[4]; /*pad 4 bytes*/ + }DMA_CH_CONFIG[16]; +}; /*dma_reg*/ + +struct dma_reg_w { + /* 0x00*/ + uint32_t DMA_CONF; + /* 0x04*/ + uint32_t DMA_DMAE; + uint8_t zResverd0x08[4]; /*pad 0x08 - 0B*/ + + /* 0x0C*/ + uint32_t DMA_EIE; + uint8_t zResverd0x010[4]; /*pad 0x010 - 013*/ + + /* 0x14*/ + uint32_t DMA_GCC; + /* 0x18*/ + uint32_t DMA_ES; + /* 0x1C*/ + uint32_t DMA_CES; + /* 0x20*/ + uint32_t DMA_CIS; + /* 0x24*/ + uint32_t DMA_CHRS; + /* 0x28*/ + uint32_t DMA_CPRI0; + /* 0x2C*/ + uint32_t DMA_CPRI1; + /* 0x30*/ + uint32_t DMA_CPRI2; + /* 0x34*/ + uint32_t DMA_CPRI3; + uint8_t zResverd0x038[456]; /*pad 0x038 - 01FF*/ + + struct { + /* 0x200*/ + uint32_t DMA_SADDR; + /* 0x204*/ + uint32_t DMA_DADDR; + /* 0x208*/ + uint32_t DMA_AOFF; + /* 0x20C*/ + uint32_t DMA_MLAOFF; + /* 0x210*/ + uint32_t DMA_NUM; + /* 0x214*/ + uint32_t DMA_ITER; + /* 0x218*/ + uint32_t DMA_CS; + + uint8_t zResverd[4]; /*pad 4 bytes*/ + } DMA_CH_CONFIG[16]; +}; /*dma_reg*/ + +typedef volatile struct dma_reg dma_reg_t; +typedef volatile struct dma_reg_w dma_reg_w_t; + +struct ewdt_reg { + /* 0x0*/ + struct { + uint32_t MINOR : 4; /* [3:0] ro */ + uint32_t MAJOR : 4; /* [7:4] ro */ + uint32_t RSVD_31_8 :24; /* [31:8] ro */ + } EWDT_VERID; + + /* 0x4*/ + struct { + uint32_t RSVD_31_0 :32; /* [31:0] ro */ + } EWDT_PARAM; + + /* 0x8*/ + struct { + uint32_t EWDTE : 1; /* [0] r/w */ + uint32_t DEBUGE : 1; /* [1] r/w */ + uint32_t WAITE : 1; /* [2] r/w */ + uint32_t RSVD_3 : 1; /* [3] ro */ + uint32_t INTE : 1; /* [4] r/w */ + uint32_t INPE : 1; /* [5] r/w */ + uint32_t INPP : 1; /* [6] r/w */ + uint32_t RSVD_23_7 :17; /* [23:7] */ + uint32_t INTF : 1; /* [24] w1c */ + uint32_t RSVD_31_25 : 7; /* [31:25] ro */ + } EWDT_CS; + + /* 0xC*/ + struct { + uint32_t COMPH :32; /* [31:0] r/w */ + } EWDT_COMPH; + + /* 0x10*/ + struct { + uint32_t COMPL :32; /* [31:0] r/w */ + } EWDT_COMPL; + + /* 0x14*/ + struct { + uint32_t CNT :32; /* [31:0] r/w */ + } EWDT_CNT; + +}; /*ewdt_reg*/ + +struct ewdt_reg_w { + /* 0x0*/ + uint32_t EWDT_VERID; + /* 0x4*/ + uint32_t EWDT_PARAM; + /* 0x8*/ + uint32_t EWDT_CS; + /* 0xC*/ + uint32_t EWDT_COMPH; + /* 0x10*/ + uint32_t EWDT_COMPL; + /* 0x14*/ + uint32_t EWDT_CNT; +}; /*ewdt_reg*/ + +typedef volatile struct ewdt_reg ewdt_reg_t; +typedef volatile struct ewdt_reg_w ewdt_reg_w_t; + +struct flash_reg { + /* 0x0*/ + struct { + uint32_t FAIL : 1; /* [0] r */ + uint32_t RSVD_1 : 1; /* [1] r */ + uint32_t CMDABT : 1; /* [2] r/w1c */ + uint32_t RSVD_4_3 : 2; /* [4:3] r */ + uint32_t ACCERR : 1; /* [5] r/w1c */ + uint32_t PREABT : 1; /* [6] r/w1c */ + uint32_t CCIF : 1; /* [7] r/w1c */ + uint32_t RSVD_10_8 : 3; /* [10:8] r */ + uint32_t CMDWRF : 1; /* [11] r */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t DFDIF : 1; /* [16] r/w1c */ + uint32_t RSVD_29_17 :13; /* [29:17] r */ + uint32_t DBG_ERSALL_DIS : 1; /* [30] r */ + uint32_t FSEC : 1; /* [31] r */ + } FLASH_FSTAT; + + /* 0x4*/ + struct { + uint32_t RSVD_6_0 : 7; /* [6:0] r */ + uint32_t CCIE : 1; /* [7] r/w */ + uint32_t DBG_ERS_FLG : 1; /* [8] r */ + uint32_t RSVD_15_9 : 7; /* [15:9] r */ + uint32_t DFDIE : 1; /* [16] r/w */ + uint32_t RSVD_31_17 :15; /* [31:17] r */ + } FLASH_FCNFG; + + /* 0x8*/ + struct { + uint32_t RWSC : 4; /* [3:0] r/w */ + uint32_t RSVD_7_4 : 4; /* [7:4] r */ + uint32_t LSMODE : 1; /* [8] r/w */ + uint32_t RSVD_15_9 : 7; /* [15:9] r */ + uint32_t FECCF : 1; /* [16] r/w */ + uint32_t RSVD_23_17 : 7; /* [23:17] r */ + uint32_t ABTREQ : 1; /* [24] r */ + uint32_t RSVD_31_25 : 7; /* [31:25] r */ + } FLASH_FCTRL; + + uint8_t zResverd0x0C[4]; /*pad 0x0C - 0F*/ + + /* 0x10*/ + struct { + uint32_t CMDCODE : 8; /* [7:0] r/w */ + uint32_t RSVD_31_8 :24; /* [31:8] r */ + } FLASH_FCMD; + + /* 0x14*/ + struct { + uint32_t CMDOPT : 8; /* [7:0] r/w */ + uint32_t RSVD_31_8 :24; /* [31:8] r */ + } FLASH_FCMD_OPT; + + /* 0x18*/ + struct { + uint32_t CMDADDR :32; /* [31:0] r/w */ + } FLASH_FADDR; + + /* 0x1C*/ + struct { + uint32_t CMDADDRE :32; /* [31:0] r/w */ + } FLASH_FADDR_END; + + /* 0x20*/ + struct { + uint32_t CMDDATA0 :32; /* [31:0] r/w */ + } FLASH_FDATA0; + + /* 0x24*/ + struct { + uint32_t CMDDATA1 :32; /* [31:0] r/w */ + } FLASH_FDATA1; + + /* 0x28*/ + struct { + uint32_t CMDDATA2 :32; /* [31:0] r/w */ + } FLASH_FDATA2; + + /* 0x2C*/ + struct { + uint32_t CMDDATA3 :32; /* [31:0] r/w */ + } FLASH_FDATA3; + +}; /*flash_reg*/ + +struct flash_reg_w { + /* 0x0*/ + uint32_t FLASH_FSTAT; + /* 0x4*/ + uint32_t FLASH_FCNFG; + /* 0x8*/ + uint32_t FLASH_FCTRL; + uint8_t zResverd0x0C[4]; /*pad 0x0C - 0F*/ + + /* 0x10*/ + uint32_t FLASH_FCMD; + /* 0x14*/ + uint32_t FLASH_FCMD_OPT; + /* 0x18*/ + uint32_t FLASH_FADDR; + /* 0x1C*/ + uint32_t FLASH_FADDR_END; + /* 0x20*/ + uint32_t FLASH_FDATA0; + /* 0x24*/ + uint32_t FLASH_FDATA1; + /* 0x28*/ + uint32_t FLASH_FDATA2; + /* 0x2C*/ + uint32_t FLASH_FDATA3; +}; /*flash_reg*/ + +typedef volatile struct flash_reg flash_reg_t; +typedef volatile struct flash_reg_w flash_reg_w_t; + +struct gpio_reg { + /* 0x0*/ + struct { + uint32_t PDO :32; /* [31:0] r/w */ + } GPIOx_PDOR; + + /* 0x4*/ + struct { + uint32_t PSO :32; /* [31:0] wo */ + } GPIOx_PSOR; + + /* 0x8*/ + struct { + uint32_t PCO :32; /* [31:0] wo */ + } GPIOx_PCOR; + + /* 0xC*/ + struct { + uint32_t PTO :32; /* [31:0] wo */ + } GPIOx_PTOR; + + /* 0x10*/ + struct { + uint32_t PDI :32; /* [31:0] ro */ + } GPIOx_PDIR; + + /* 0x14*/ + struct { + uint32_t PDD :32; /* [31:0] r/w */ + } GPIOx_PDDR; + + /* 0x18*/ + struct { + uint32_t RSVD_31_0 :32; /* [31:0] ro */ + } GPIOx_PIDR; + + uint8_t zResverd[36]; /*pad 0x01C - 03F*/ +}; /*gpio_reg*/ + +struct gpio_reg_w { + /* 0x0 */ + uint32_t GPIOx_PDOR; + /* 0x4 */ + uint32_t GPIOx_PSOR; + /* 0x8 */ + uint32_t GPIOx_PCOR; + /* 0xC */ + uint32_t GPIOx_PTOR; + /* 0x10 */ + uint32_t GPIOx_PDIR; + /* 0x14 */ + uint32_t GPIOx_PDDR; + /* 0x18 */ + uint32_t GPIOx_PIDR; + /* 0x1C */ + uint8_t zResverd[36]; +}; /* gpio_reg */ + +typedef volatile struct gpio_reg gpio_reg_t; +typedef volatile struct gpio_reg_w gpio_reg_w_t; + +struct hwdiv_reg { + /* 0x0*/ + struct { + uint32_t VERSION :32; /* [31:0] ro */ + } HWDIV_VERSION; + + /* 0x4*/ + struct { + uint32_t PARAM :32; /* [31:0] ro */ + } HWDIV_PARAM; + + /* 0x8*/ + struct { + uint32_t DIVIDEND :32; /* [31:0] r/w */ + } HWDIV_DEND; + + /* 0xC*/ + struct { + uint32_t DIVISOR :32; /* [31:0] r/w */ + } HWDIV_DSOR; + + /* 0x10*/ + struct { + uint32_t DFS : 1; /* [0] r/w */ + uint32_t USGN : 1; /* [1] r/w */ + uint32_t DZE : 1; /* [2] r/w */ + uint32_t DZ : 1; /* [3] ro */ + uint32_t SQRT : 1; /* [4] ro */ + uint32_t DIV : 1; /* [5] ro */ + uint32_t BUSY : 1; /* [6] ro */ + uint32_t RSVD_31_7 :25; /* [31:7] ro */ + } HWDIV_CSR; + + /* 0x14*/ + struct { + uint32_t STRT : 1; /* [0] w */ + uint32_t RSVD_31_1 :31; /* [31:1] ro */ + } HWDIV_STRT; + + /* 0x18*/ + struct { + uint32_t RESULT :32; /* [31:0] ro */ + } HWDIV_RES; + + /* 0x1C*/ + struct { + uint32_t REMAINDER :32; /* [31:0] ro */ + } HWDIV_REM; + + /* 0x20*/ + struct { + uint32_t RADICAND :32; /* [31:0] r/w */ + } HWDIV_RCND; + +}; /*hwdiv_reg*/ + +struct hwdiv_reg_w { + /* 0x0*/ + uint32_t HWDIV_VERSION; + /* 0x4*/ + uint32_t HWDIV_PARAM; + /* 0x8*/ + uint32_t HWDIV_DEND; + /* 0xC*/ + uint32_t HWDIV_DSOR; + /* 0x10*/ + uint32_t HWDIV_CSR; + /* 0x14*/ + uint32_t HWDIV_STRT; + /* 0x18*/ + uint32_t HWDIV_RES; + /* 0x1C*/ + uint32_t HWDIV_REM; + /* 0x20*/ + uint32_t HWDIV_RCND; +}; /*hwdiv_reg*/ + +typedef volatile struct hwdiv_reg hwdiv_reg_t; +typedef volatile struct hwdiv_reg_w hwdiv_reg_w_t; + +struct i2c_reg { + /* 0x00*/ + struct { + uint32_t RSVD_31_0 :32; /* [31:0] ro */ + } I2C_VERID; + + /* 0x04*/ + struct { + uint32_t I2C_SUPPORT_SPEED : 2; /* [1:0] ro */ + uint32_t DMA_SUPPORT : 1; /* [2] ro */ + uint32_t TXFIFO_DEPTH : 4; /* [6:3] ro */ + uint32_t RXFIFO_DEPTH : 4; /* [10:7] ro */ + uint32_t RSVD_31_11 :21; /* [31:11] ro */ + } I2C_PARAMETER; + + /* 0x08*/ + struct { + uint32_t MODULE_EN : 1; /* [0] r/w */ + uint32_t SLAVE_ACK_GENCALL : 1; /* [1] r/w */ + uint32_t SLAVE_NACK : 1; /* [2] r/w */ + uint32_t SDA_RECOVER_EN : 1; /* [3] r/w */ + uint32_t MASTER_ABORT : 1; /* [4] r/w */ + uint32_t MASTER_BUS_RECOVER_EN : 1; /* [5] r/w */ + uint32_t MASTER_BLK_TXFIFO : 1; /* [6] r/w */ + uint32_t H_MCODE : 3; /* [9:7] r/w */ + uint32_t RSVD_31_10 :22; /* [31:10] ro */ + } I2C_CONFIG0; + + /* 0x0c*/ + struct { + uint32_t SLAVE_MODE_DIS : 1; /* [0] r/w */ + uint32_t MASTER_MODE_EN : 1; /* [1] r/w */ + uint32_t MASTER_RESTART_EN : 1; /* [2] r/w */ + uint32_t SLAVE_STOP_DET_EN : 1; /* [3] r/w */ + uint32_t MASTER_STOP_DET_EN : 1; /* [4] r/w */ + uint32_t TXFIFO_EMPTY_EN : 1; /* [5] r/w */ + uint32_t SPEED_SEL : 2; /* [7:6] r/w */ + uint32_t HOLD_EN_RXFIFO_FULL : 1; /* [8] r/w */ + uint32_t SLAVE_10BIT_ADDR_SEL : 1; /* [9] r/w */ + uint32_t MASTER_10BIT_ADDR_SEL : 1; /* [10] r/w */ + uint32_t RSVD_31_11 :21; /* [31:11] ro */ + } I2C_CONFIG1; + + /* 0x10*/ + struct { + uint32_t SDA_SETUP_TIMING : 8; /* [7:0] r/w */ + uint32_t RSVD_31_8 :24; /* [31:8] ro */ + } I2C_SDA_SETUP_TIMING; + + /* 0x14*/ + struct { + uint32_t SDA_TX_HOLD_TIMING :16; /* [15:0] r/w */ + uint32_t SDA_RX_HOLD_TIMING : 8; /* [23:16] r/w */ + uint32_t RSVD_31_24 : 8; /* [31:24] ro */ + } I2C_SDA_HOLD_TIMING; + + /* 0x18*/ + struct { + uint32_t RXFIFO_DMA_EN : 1; /* [0] r/w */ + uint32_t TXFIFO_DMA_EN : 1; /* [1] r/w */ + uint32_t DMA_TXFIFO_WATERMARK : 2; /* [3:2] r/w */ + uint32_t DMA_RXFIFO_WATERMARK : 2; /* [5:4] r/w */ + uint32_t RSVD_31_6 :26; /* [31:6] ro */ + } I2C_DMA_CTRL; + + /* 0x1c*/ + struct { + uint32_t I2C_CALL_IE : 1; /* [0] r/w */ + uint32_t I2C_TX_OVF_IE : 1; /* [1] r/w */ + uint32_t I2C_ERROR_ABORT_IE : 1; /* [2] r/w */ + uint32_t I2C_ACTIVITY_DET_IE : 1; /* [3] r/w */ + uint32_t I2C_STOP_DET_IE : 1; /* [4] r/w */ + uint32_t I2C_START_DET_IE : 1; /* [5] r/w */ + uint32_t RSVD_21_6 :16; /* [21:6] ro */ + uint32_t SLAVE_RD_REQ_IE : 1; /* [22] r/w */ + uint32_t RX_DONE_IE : 1; /* [23] r/w */ + uint32_t RX_UNDER_IE : 1; /* [24] r/w */ + uint32_t RX_OVF_IE : 1; /* [25] r/w */ + uint32_t RESTART_DET_IE : 1; /* [26] r/w */ + uint32_t SCL_STUCK_AT_LOW_IE : 1; /* [27] r/w */ + uint32_t RSVD_29_28 : 2; /* [29:28] ro */ + uint32_t RX_FULL_IE : 1; /* [30] r/w */ + uint32_t TX_EMPTY_IE : 1; /* [31] r/w */ + } I2C_INT_ENABLE; + + /* 0x20*/ + struct { + uint32_t DATA : 8; /* [7:0] r/w */ + uint32_t CMD_MASTER_DIRECTION : 1; /* [8] wo */ + uint32_t CMD_STOP : 1; /* [9] wo */ + uint32_t CMD_RESTART : 1; /* [10] wo */ + uint32_t RSVD_31_11 :21; /* [31:11] ro */ + } I2C_COMMAND_DATA; + + /* 0x24*/ + struct { + uint32_t DEST_ADDR :10; /* [9:0] r/w */ + uint32_t MASTER_CMD_SEL : 2; /* [11:10] r/w */ + uint32_t RSVD_31_12 :20; /* [31:12] ro */ + } I2C_DEST_ADDR; + + /* 0x28*/ + struct { + uint32_t SLV_ADDR :10; /* [9:0] r/w */ + uint32_t RSVD_31_10 :22; /* [31:10] ro */ + } I2C_SLAVE_ADDR; + + /* 0x2c*/ + struct { + uint32_t STD_SCL_HCNT :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] ro */ + } I2C_STD_SCL_HCNT; + + /* 0x30*/ + struct { + uint32_t STD_SCL_LCNT :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] ro */ + } I2C_STD_SCL_LCNT; + + /* 0x34*/ + struct { + uint32_t FST_SCL_HCNT :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] reserve */ + } I2C_FST_SCL_HCNT; + + /* 0x38*/ + struct { + uint32_t FST_SCL_LCNT :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] ro */ + } I2C_FST_SCL_LCNT; + + /* 0x3c*/ + struct { + uint32_t HS_SCL_HCNT :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] ro */ + } I2C_HS_SCL_HCNT; + + /* 0x40*/ + struct { + uint32_t HS_SCL_LCNT :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] ro */ + } I2C_HS_SCL_LCNT; + + /* 0x44*/ + struct { + uint32_t RXFIFO_WATER_MARK : 2; /* [1:0] r/w */ + uint32_t RSVD_31_2 :30; /* [31:2] ro */ + } I2C_RXFIFO_WATER_MARK; + + /* 0x48*/ + struct { + uint32_t TXFIFO_WATER_MARK : 2; /* [1:0] r/w */ + uint32_t RSVD_31_2 :30; /* [31:2] ro */ + } I2C_TXFIFO_WATER_MARK; + + /* 0x4c*/ + struct { + uint32_t TX_FIFO_CNT : 3; /* [2:0] ro */ + uint32_t RSVD_31_3 :29; /* [31:3] ro */ + } I2C_TX_FIFO_CNT; + + /* 0x50*/ + struct { + uint32_t RX_FIFO_CNT : 3; /* [2:0] ro */ + uint32_t RSVD_31_3 :29; /* [31:3] ro */ + } I2C_RX_FIFO_CNT; + + /* 0x54*/ + struct { + uint32_t FSTD_SPKLEN : 8; /* [7:0] r/w */ + uint32_t RSVD_31_8 :24; /* [31:8] ro */ + } I2C_FSTD_SPKCNT; + + /* 0x58*/ + struct { + uint32_t HS_SPKLEN : 8; /* [7:0] r/w */ + uint32_t RSVD_31_8 :24; /* [31:8] ro */ + } I2C_HS_SPKCNT; + + /* 0x5c*/ + struct { + uint32_t GENERAL_CALL : 1; /* [0] w1c */ + uint32_t TXFIFO_OVERUN : 1; /* [1] w1c */ + uint32_t ERROR_ABORT : 1; /* [2] w1c */ + uint32_t ACTIVITY : 1; /* [3] w1c */ + uint32_t STOP_DETECT : 1; /* [4] w1c */ + uint32_t START_DETECT : 1; /* [5] w1c */ + uint32_t RSVD_21_6 :16; /* [21:6] ro */ + uint32_t SLAVE_READ_REQ : 1; /* [22] w1c */ + uint32_t RXFIFO_DONE : 1; /* [23] w1c */ + uint32_t RXFIFO_UNDERUN : 1; /* [24] w1c */ + uint32_t RXFIFO_OVERUN : 1; /* [25] w1c */ + uint32_t RESTART_DET : 1; /* [26] w1c */ + uint32_t SCL_STUCK_AT_LOW : 1; /* [27] w1c */ + uint32_t RSVD_29_28 : 2; /* [29:28] ro */ + uint32_t RXFIFO_FULL : 1; /* [30] ro */ + uint32_t TXFIFO_EMPTY : 1; /* [31] ro */ + } I2C_STATUS0; + + /* 0x60*/ + struct { + uint32_t MASTER_IS_ACTIVE : 1; /* [0] ro */ + uint32_t SLAVE_IS_ACTIVE : 1; /* [1] ro */ + uint32_t TXFIFO_EMPTY_MASTER_HOLD: 1; /* [2] ro */ + uint32_t TXFIFO_EMPTY_SLAVE_HOLD : 1; /* [3] ro */ + uint32_t RXFIFO_FULL_MASTER_HOLD : 1; /* [4] ro */ + uint32_t RXFIFO_FULL_SLAVE_HOLD : 1; /* [5] ro */ + uint32_t TXFIFO_IS_NOT_FULL : 1; /* [6] ro */ + uint32_t TXFIFO_IS_EMPTY : 1; /* [7] ro */ + uint32_t RXFIFO_IS_NOT_EMPTY : 1; /* [8] ro */ + uint32_t RXFIFO_IS_FULL : 1; /* [9] ro */ + uint32_t SDA_ERR_RECOVER_STUCK_LOW: 1; /* [10] ro */ + uint32_t SLAVE_IS_DISABLED_UNDER_ACT: 1; /* [11] ro */ + uint32_t SLAVE_RX_DATA_DISCARD : 1; /* [12] ro */ + uint32_t I2C_IS_ENABLE : 1; /* [13] ro */ + uint32_t RSVD_31_14 :18; /* [31:14] ro */ + } I2C_STATUS1; + + /* 0x64*/ + struct { + uint32_t ERR_GEN_CALL_NO_ACK : 1; /* [0] ro */ + uint32_t ERR_GEN_CALL_READ : 1; /* [1] ro */ + uint32_t ERR_START_BYTE_ACK_DET : 1; /* [2] ro */ + uint32_t ERR_SBYTE_NORSTRT : 1; /* [3] ro */ + uint32_t ERR_H_NO_RSTRT : 1; /* [4] ro */ + uint32_t ERR_H_MCODE_ACK_DET : 1; /* [5] ro */ + uint32_t ERR_7BIT_ADDR_NO_ACK : 1; /* [6] ro */ + uint32_t ERR_10BIT_ADDR1_NO_ACK : 1; /* [7] ro */ + uint32_t ERR_10BIT_ADDR2_NO_ACK : 1; /* [8] ro */ + uint32_t ERR_10BIT_READ_NO_RSTRT : 1; /* [9] ro */ + uint32_t ERR_DATA_NO_ACK : 1; /* [10] ro */ + uint32_t ERR_MASTER_ABRT : 1; /* [11] ro */ + uint32_t ERR_MASTER_DIS : 1; /* [12] ro */ + uint32_t ERR_SLAVE_ARBLOST : 1; /* [13] ro */ + uint32_t ERR_MASTER_LOST : 1; /* [14] ro */ + uint32_t ERR_SLAVE_READ_REQ : 1; /* [15] ro */ + uint32_t ERR_SLAVE_FLUSH_TXFIFO : 1; /* [16] ro */ + uint32_t ERR_SDA_LOW_TIMEOUT : 1; /* [17] ro */ + uint32_t ERR_TXFIFO_FLUSH_CNT : 3; /* [20:18] ro */ + uint32_t RSVD_31_21 :11; /* [31:21] ro */ + } I2C_ERROR_STATUS; + + /* 0x68*/ + struct { + uint32_t SCL_LOW_TIMEOUT :32; /* [31:0] r/w */ + } I2C_SCL_LOW_TIMEOUT; + + /* 0x6c*/ + struct { + uint32_t SDA_LOW_TIMEOUT :32; /* [31:0] r/w */ + } I2C_SDA_LOW_TIMEOUT; + + /* 0x70*/ + struct { + uint32_t CLR_ERR : 1; /* [0] r */ + uint32_t RSVD_31_1 :31; /* [31:1] ro */ + } I2C_RD_CLR_ERR_STATUS; + +}; /*i2c_reg*/ + +struct i2c_reg_w { + /* 0x00*/ + uint32_t I2C_VERID; + /* 0x04*/ + uint32_t I2C_PARAMETER; + /* 0x08*/ + uint32_t I2C_CONFIG0; + /* 0x0c*/ + uint32_t I2C_CONFIG1; + /* 0x10*/ + uint32_t I2C_SDA_SETUP_TIMING; + /* 0x14*/ + uint32_t I2C_SDA_HOLD_TIMING; + /* 0x18*/ + uint32_t I2C_DMA_CTRL; + /* 0x1c*/ + uint32_t I2C_INT_ENABLE; + /* 0x20*/ + uint32_t I2C_COMMAND_DATA; + /* 0x24*/ + uint32_t I2C_DEST_ADDR; + /* 0x28*/ + uint32_t I2C_SLAVE_ADDR; + /* 0x2c*/ + uint32_t I2C_STD_SCL_HCNT; + /* 0x30*/ + uint32_t I2C_STD_SCL_LCNT; + /* 0x34*/ + uint32_t I2C_FST_SCL_HCNT; + /* 0x38*/ + uint32_t I2C_FST_CLK_LCNT; + /* 0x3c*/ + uint32_t I2C_HS_CLK_HCNT; + /* 0x40*/ + uint32_t I2C_HS_CLK_LCNT; + /* 0x44*/ + uint32_t I2C_RXFIFO_WATER_MARK; + /* 0x48*/ + uint32_t I2C_TXFIFO_WATER_MARK; + /* 0x4c*/ + uint32_t I2C_TX_FIFO_CNT; + /* 0x50*/ + uint32_t I2C_RX_FIFO_CNT; + /* 0x54*/ + uint32_t I2C_FSTD_SPKCNT; + /* 0x58*/ + uint32_t I2C_HS_SPKCNT; + /* 0x5c*/ + uint32_t I2C_STATUS0; + /* 0x60*/ + uint32_t I2C_STATUS1; + /* 0x64*/ + uint32_t I2C_ERROR_STATUS; + /* 0x68*/ + uint32_t I2C_SCL_LOW_TIMEOUT; + /* 0x6c*/ + uint32_t I2C_SDA_LOW_TIMEOUT; + /* 0x70*/ + uint32_t I2C_RD_CLR_ERR_STATUS; +}; /*i2c_reg*/ + +typedef volatile struct i2c_reg i2c_reg_t; +typedef volatile struct i2c_reg_w i2c_reg_w_t; + +struct parcc_reg { + /* 0x0*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_15_2 :14; /* [15:2] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_WDOG; + + /* 0x4*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_EWDT; + + /* 0x8*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_STIM; + + /* 0xC*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_PWMTIMER0; + + /* 0x10*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_PWMTIMER1; + + /* 0x14*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_PWMTIMER2; + + /* 0x18*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_TDG0; + + /* 0x1C*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_CAN0; + + /* 0x20*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_CAN1; + + /* 0x24*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_UART0; + + /* 0x28*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_UART1; + + /* 0x2C*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_UART2; + + /* 0x30*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_UART3; + + /* 0x34*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_SPI0; + + /* 0x38*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_SPI1; + + /* 0x3C*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_SPI2; + + /* 0x40*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_I2C0; + + /* 0x44*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_I2C1; + + /* 0x48*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_ADC0; + + /* 0x4C*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_15_2 :14; /* [15:2] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_CMP; + + /* 0x50*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_15_2 :14; /* [15:2] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_CRC; + + /* 0x54*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_15_2 :14; /* [15:2] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_FLASH; + + /* 0x58*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_15_2 :14; /* [15:2] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_DMA; + + /* 0x5C*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_15_2 :14; /* [15:2] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_DMAMUX; + + /* 0x60*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_PORTA; + + /* 0x64*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_PORTB; + + /* 0x68*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_PORTC; + + /* 0x6C*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_PORTD; + + /* 0x70*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_PORTE; + + /* 0x74*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_15_2 :14; /* [15:2] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_TMU; + + /* 0x78*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_15_2 :14; /* [15:2] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_REGFILE; + + /* 0x7C*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_15_2 :14; /* [15:2] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_GPIO; + + /* 0x80*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_15_2 :14; /* [15:2] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_HWDIV; + +}; /*parcc_reg*/ + +struct parcc_reg_w { + /* 0x0*/ + uint32_t PARCC_WDOG; + /* 0x4*/ + uint32_t PARCC_EWDT; + /* 0x8*/ + uint32_t PARCC_STIM; + /* 0xC*/ + uint32_t PARCC_PWMTIMER0; + /* 0x10*/ + uint32_t PARCC_PWMTIMER1; + /* 0x14*/ + uint32_t PARCC_PWMTIMER2; + /* 0x18*/ + uint32_t PARCC_TDG0; + /* 0x1C*/ + uint32_t PARCC_CAN0; + /* 0x20*/ + uint32_t PARCC_CAN1; + /* 0x24*/ + uint32_t PARCC_UART0; + /* 0x28*/ + uint32_t PARCC_UART1; + /* 0x2C*/ + uint32_t PARCC_UART2; + /* 0x30*/ + uint32_t PARCC_UART3; + /* 0x34*/ + uint32_t PARCC_SPI0; + /* 0x38*/ + uint32_t PARCC_SPI1; + /* 0x3C*/ + uint32_t PARCC_SPI2; + /* 0x40*/ + uint32_t PARCC_I2C0; + /* 0x44*/ + uint32_t PARCC_I2C1; + /* 0x48*/ + uint32_t PARCC_ADC0; + /* 0x4C*/ + uint32_t PARCC_CMP; + /* 0x50*/ + uint32_t PARCC_CRC; + /* 0x54*/ + uint32_t PARCC_FLASH; + /* 0x58*/ + uint32_t PARCC_DMA; + /* 0x5C*/ + uint32_t PARCC_DMAMUX; + /* 0x60*/ + uint32_t PARCC_PORTA; + /* 0x64*/ + uint32_t PARCC_PORTB; + /* 0x68*/ + uint32_t PARCC_PORTC; + /* 0x6C*/ + uint32_t PARCC_PORTD; + /* 0x70*/ + uint32_t PARCC_PORTE; + /* 0x74*/ + uint32_t PARCC_TMU; + /* 0x78*/ + uint32_t PARCC_REGFILE; + /* 0x7C*/ + uint32_t PARCC_GPIO; + /* 0x80*/ + uint32_t PARCC_HWDIV; +}; /*parcc_reg*/ + +typedef volatile struct parcc_reg parcc_reg_t; +typedef volatile struct parcc_reg_w parcc_reg_w_t; + +struct pmu_reg { + /* 0x00*/ + struct { + uint32_t RSVD_31_0 :32; /* [31:0] r */ + } PMU_VERID; + + /* 0x04*/ + struct { + uint32_t LPO_CLK_DIS : 1; /* [0] r/w */ + uint32_t LPO_CLK_SEL : 1; /* [1] r/w */ + uint32_t LPO_CLK_READY : 1; /* [2] r */ + uint32_t RSVD_31_3 :29; /* [31:3] ro */ + } PMU_LPO_32K_CFG; + + /* 0x08*/ + struct { + uint32_t LPO_32K_TRIM : 7; /* [6:0] r/w */ + uint32_t RSVD_31_7 :25; /* [31:7] ro */ + } PMU_LPO_32K_TRIM; + + /* 0x0c*/ + struct { + uint32_t ISO_CLR : 1; /* [0] w1c */ + uint32_t RSVD_31_1 :31; /* [31:1] ro */ + } PMU_ISO_CLR; + + /* 0x10*/ + struct { + uint32_t VDD_LVD_LP_EN : 1; /* [0] r/w */ + uint32_t VDD_LVD_ACT_EN : 1; /* [1] r/w */ + uint32_t VDD_LVD_IE : 1; /* [2] r/w */ + uint32_t VDD_LVD_RE : 1; /* [3] r/w */ + uint32_t VDD_LVW_EN : 1; /* [4] r/w */ + uint32_t VDD_LVW_IE : 1; /* [5] r/w */ + uint32_t LVWF_VDD : 1; /* [6] w1c */ + uint32_t LVDF_VDD : 1; /* [7] w1c */ + uint32_t REF_BUF_1V_EN : 1; /* [8] r/w */ + uint32_t LDO_LVD_ACT_EN : 1; /* [9] r/w */ + uint32_t LDO_LVD_LP_EN : 1; /* [10] r/w */ + uint32_t LDO_CLAMP_EN : 1; /* [11] r/w */ + uint32_t RSVD_31_12 :20; /* [31:12] ro */ + } PMU_VDD5V_CSR; + + /* 0x14*/ + struct { + uint32_t RSVD_30_0 :31; /* [30:0] ro */ + uint32_t LOCK : 1; /* [31] w/r */ + } PMU_LOCK; + +}; /*pmu_reg*/ + +struct pmu_reg_w { + /* 0x00*/ + uint32_t PMU_VERID; + /* 0x04*/ + uint32_t PMU_LPO_32K_CFG; + /* 0x08*/ + uint32_t PMU_LPO_32K_TRIM; + /* 0x0c*/ + uint32_t PMU_ISO_CLR; + /* 0x10*/ + uint32_t PMU_VDD5V_CSR; + /* 0x14*/ + uint32_t PMU_LOCK; + +}; /*pmu_reg_w*/ + +typedef volatile struct pmu_reg pmu_reg_t; +typedef volatile struct pmu_reg_w pmu_reg_w_t; + +struct port_reg { + /* 0x0*/ + struct { + uint32_t FEATURE :16; /* [15:0] ro */ + uint32_t MINOR : 8; /* [23:16] ro */ + uint32_t MAJOR : 8; /* [31:24] ro */ + } PORTx_VERID; + + /* 0x4*/ + struct { + uint32_t RSVD_31_0 :32; /* [31:0] ro */ + } PORTx_PARAM; + + /* 0x8*/ + struct { + uint32_t GPWD :32; /* [31:0] r/w */ + } PORTx_GLBDAT; + + /* 0xC*/ + struct { + uint32_t GPWE :32; /* [31:0] wo */ + } PORTx_GLBCTL; + + /* 0x10*/ + struct { + uint32_t PS : 1; /* [0] r/w */ + uint32_t PE : 1; /* [1] r/w */ + uint32_t RSVD_2 : 1; /* [2] ro */ + uint32_t SRE : 1; /* [3] r/w */ + uint32_t PFE : 1; /* [4] r/w */ + uint32_t ODE : 1; /* [5] r/w */ + uint32_t DSE : 1; /* [6] r/w */ + uint32_t RSVD_7 : 1; /* [7] ro */ + uint32_t MUX : 3; /* [10:8] r/w */ + uint32_t RSVD_14_11 : 4; /* [14:11] ro */ + uint32_t LK : 1; /* [15] r/w */ + uint32_t IRQC : 4; /* [19:16] r/w */ + uint32_t RSVD_22_20 : 3; /* [22:20] ro */ + uint32_t ISF : 1; /* [23] r/w */ + uint32_t FLT : 5; /* [28:24] r/w */ + uint32_t RSVD_30_29 : 2; /* [30:29] ro */ + uint32_t FLTEN : 1; /* [31] r/w */ + } PORTx_PCRn[32]; + + /* 0x90*/ + struct { + uint32_t ISF :32; /* [31:0] r/w */ + } PORTx_IRQFLG; +}; /*port_reg*/ + +struct port_reg_w { + /* 0x0*/ + uint32_t PORTx_VERID; + /* 0x4*/ + uint32_t PORTx_PARAM; + /* 0x8*/ + uint32_t PORTx_GLBDAT; + /* 0xC*/ + uint32_t PORTx_GLBCTL; + /* 0x10*/ + uint32_t PORTx_PCRn[32]; + /* 0x90*/ + uint32_t PORTx_IRQFLG; +}; /*port_reg*/ + +typedef volatile struct port_reg port_reg_t; +typedef volatile struct port_reg_w port_reg_w_t; + +struct regfile_reg { + /* 0x0*/ + struct { + uint32_t DATA :32; /* [31:0] rw */ + } REGFILE_REGn[32]; + +}; /*regfile_reg*/ + +struct regfile_reg_w { + /* 0x0*/ + uint32_t REGFILE_REGn[32]; +}; /*regfile_reg*/ + +typedef volatile struct regfile_reg regfile_reg_t; +typedef volatile struct regfile_reg_w regfile_reg_w_t; + +struct rtc_reg { + /* 0x00*/ + struct { + uint32_t CRYSTAL_EN : 1; /* [0] r/w */ + uint32_t CNT_CLK_SEL : 1; /* [1] r/w */ + uint32_t CLKOUT_SEL : 1; /* [2] r/w */ + uint32_t CLKOUT_PIN_EN : 1; /* [3] r/w */ + uint32_t SUP_EN : 1; /* [4] r/w */ + uint32_t SW_RST : 1; /* [5] r/w */ + uint32_t COUNT_EN : 1; /* [6] r/w */ + uint32_t OVF : 1; /* [7] ro */ + uint32_t ALARM_MATCHF : 1; /* [8] ro */ + uint32_t OSC_RDY : 1; /* [9] ro */ + uint32_t EXTAL_32K_EN : 1; /* [10] r/w */ + uint32_t SECONDS_INT_FLAG : 1; /* [11] w1c */ + uint32_t RSVD_31_12 :20; /* [31:12] ro */ + } RTC_CSR; + + /* 0x04*/ + struct { + uint32_t SECOND_INT_MUX_SEL : 3; /* [2:0] r/w */ + uint32_t OVFLOW_IE : 1; /* [3] r/w */ + uint32_t ALARM_IE : 1; /* [4] r/w */ + uint32_t SECONDS_IE : 1; /* [5] r/w */ + uint32_t RSVD_31_6 :26; /* [31:6] ro */ + } RTC_IER; + + /* 0x08*/ + struct { + uint32_t ALARM_CNT :32; /* [31:0] r/w */ + } RTC_ALARM_CNTR; + + /* 0x0c*/ + struct { + uint32_t ONE_SECOND_CNT :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] ro */ + } RTC_ONE_SECOND_CNTR; + + /* 0x10*/ + struct { + uint32_t MATCH_CNT :32; /* [31:0] r/w */ + } RTC_MATCH_CNTR; + + /* 0x14*/ + struct { + uint32_t COMP_CNT : 7; /* [6:0] r/w */ + uint32_t COMP_DIRECTION : 1; /* [7] r/w */ + uint32_t DLY : 8; /* [15:8] r/w */ + uint32_t CCOMP_CNT : 8; /* [23:16] ro */ + uint32_t CDLY : 8; /* [31:24] ro */ + } RTC_COMPENSATIONR; + + /* 0x18*/ + struct { + uint32_t RSVD_30_0 :31; /* [30:0] ro */ + uint32_t LOCK : 1; /* [31] r/w */ + } RTC_LOCKR; + + /* 0x1c*/ + struct { + uint32_t RSVD_31_0 :32; /* [31:0] ro */ + } RTC_VERID; + +}; /*rtc_reg*/ + +struct rtc_reg_w { + /* 0x00*/ + uint32_t RTC_CSR; + /* 0x04*/ + uint32_t RTC_IER; + /* 0x08*/ + uint32_t RTC_ALARM_CNTR; + /* 0x0c*/ + uint32_t RTC_ONE_SECOND_CNTR; + /* 0x10*/ + uint32_t RTC_MATCH_CNTR; + /* 0x14*/ + uint32_t RTC_COMPENSATIONR; + /* 0x18*/ + uint32_t RTC_LOCKR; + /* 0x1c*/ + uint32_t RTC_VERID; +}; /*rtc_reg*/ + +typedef volatile struct rtc_reg rtc_reg_t; +typedef volatile struct rtc_reg_w rtc_reg_w_t; + +struct scc_reg { + /* 0x0*/ + struct { + uint32_t RSVD_7_0 : 8; /* [7:0] r */ + uint32_t MINOR : 8; /* [15:8] r */ + uint32_t MAJOR : 8; /* [23:16] r */ + uint32_t RSVD_31_24 : 8; /* [31:24] r */ + } SCC_VERID; + + /* 0x4*/ + struct { + uint32_t CLKSPRES : 5; /* [4:0] r */ + uint32_t RSVD_27_5 :23; /* [27:5] r */ + uint32_t DIVPRES : 3; /* [30:28] r */ + uint32_t RSVD_31 : 1; /* [31] r */ + } SCC_PARAM; + + /* 0x8*/ + struct { + uint32_t DIVSLOW : 4; /* [3:0] r */ + uint32_t DIVBUS : 4; /* [7:4] r */ + uint32_t DIVCORE : 4; /* [11:8] r */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t SCS : 3; /* [18:16] r */ + uint32_t RSVD_31_19 :13; /* [31:19] r */ + } SCC_CST; + + /* 0xC*/ + struct { + uint32_t DIVSLOW : 4; /* [3:0] r/w */ + uint32_t DIVBUS : 4; /* [7:4] r/w */ + uint32_t DIVCORE : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t SCS : 3; /* [18:16] r/w */ + uint32_t RSVD_30_19 :12; /* [30:19] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } SCC_CFG; + + /* 0x10*/ + struct { + uint32_t RSVD_15_0 :16; /* [15:0] r */ + uint32_t CLKOUTSEL : 4; /* [19:16] r/w */ + uint32_t RSVD_31_20 :12; /* [31:20] */ + } SCC_CLKOUTCFG; + + /* 0x14*/ + struct { + uint32_t OSCEN : 1; /* [0] r/w */ + uint32_t OSCSTOPEN : 1; /* [1] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t OSCCMIE : 1; /* [4] r/w */ + uint32_t RSVD_8_5 : 4; /* [8:5] r */ + uint32_t OSCCME : 1; /* [9] r/w */ + uint32_t OSCCMRE : 1; /* [10] r/w */ + uint32_t RSVD_15_11 : 5; /* [15:11] r */ + uint32_t OSCRDY : 1; /* [16] r */ + uint32_t OSCSELD : 1; /* [17] r */ + uint32_t OSCLOC : 1; /* [18] r/w */ + uint32_t RSVD_30_19 :12; /* [30:19] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } SCC_OSCCS; + + /* 0x18*/ + struct { + uint32_t EXCLKS : 1; /* [0] r/w */ + uint32_t OLMEN : 1; /* [1] r/w */ + uint32_t HFREQ : 1; /* [2] r/w */ + uint32_t RSVD_7_3 : 5; /* [7:3] r */ + uint32_t RSVD_9_8 : 2; /* [9:8] r/w */ + uint32_t RSVD_31_10 :22; /* [31:10] r */ + } SCC_OSCCFG; + + /* 0x1C*/ + struct { + uint32_t FIRCEN : 1; /* [0] r/w */ + uint32_t FIRCSTOPEN : 1; /* [1] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t FIRCCMIE : 1; /* [4] r/w */ + uint32_t RSVD_8_5 : 4; /* [8:5] r */ + uint32_t FIRCCME : 1; /* [9] r/w */ + uint32_t FIRCCMRE : 1; /* [10] r/w */ + uint32_t RSVD_11 : 1; /* [11] r */ + uint32_t RSVD_12 : 1; /* [12] r/w */ + uint32_t RSVD_15_13 : 3; /* [15:13] r */ + uint32_t FIRCRDY : 1; /* [16] r */ + uint32_t FIRCSELD : 1; /* [17] r */ + uint32_t FIRCLOC : 1; /* [18] r/w */ + uint32_t RSVD_30_19 :12; /* [30:19] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } SCC_FIRCCS; + + /* 0x20*/ + struct { + uint32_t RSVD_1_0 : 2; /* [1:0] r/w */ + uint32_t RSVD_31_2 :30; /* [31:2] r */ + } SCC_FIRCCFG; + + /* 0x24*/ + struct { + uint32_t RSVD_5_0 : 6; /* [5:0] r/w */ + uint32_t RSVD_31_6 :26; /* [31:6] r */ + } SCC_FIRCTRIM; + +}; /*scc_reg*/ + +struct scc_reg_w { + /* 0x0*/ + uint32_t SCC_VERID; + /* 0x4*/ + uint32_t SCC_PARAM; + /* 0x8*/ + uint32_t SCC_CST; + /* 0xC*/ + uint32_t SCC_CFG; + /* 0x10*/ + uint32_t SCC_CLKOUTCFG; + /* 0x14*/ + uint32_t SCC_OSCCS; + /* 0x18*/ + uint32_t SCC_OSCCFG; + /* 0x1C*/ + uint32_t SCC_FIRCCS; + /* 0x20*/ + uint32_t SCC_FIRCCFG; + /* 0x24*/ + uint32_t SCC_FIRCTRIM; +}; /*scc_reg*/ + +typedef volatile struct scc_reg scc_reg_t; +typedef volatile struct scc_reg_w scc_reg_w_t; + +struct scm_reg { + /* 0x00*/ + struct { + uint32_t RSVD_3_0 : 4; /* [3:0] ro */ + uint32_t CLKOUTSEL : 2; /* [5:4] r/w */ + uint32_t RSVD_7_6 : 2; /* [7:6] ro */ + uint32_t CLKOUTDIV : 3; /* [10:8] r/w */ + uint32_t CLKOUTEN : 1; /* [11] r/w */ + uint32_t RSVD_31_12 :20; /* [31:12] ro */ + } SCM_CHIPCTL; + + /* 0x04*/ + struct { + uint32_t SWTRIG : 4; /* [3:0] r/w */ + uint32_t RSVD_31_4 :28; /* [31:4] ro */ + } SCM_MISCCTL; + + /* 0x08*/ + struct { + uint32_t TIM0_CLK_SEL : 2; /* [1:0] r/w */ + uint32_t RSVD_7_2 : 6; /* [7:2] ro */ + uint32_t TIM1_CLK_SEL : 2; /* [9:8] r/w */ + uint32_t RSVD_15_10 : 6; /* [15:10] ro */ + uint32_t TIM2_CLK_SEL : 2; /* [17:16] r/w */ + uint32_t RSVD_31_18 :14; /* [31:18] ro */ + } SCM_TIMOPT; + + /* 0x0C*/ + struct { + uint32_t SRAM0_ECCR_DIS : 1; /* [0] r/w */ + uint32_t SRAM0_ECCW_DIS : 1; /* [1] r/w */ + uint32_t SRAM0_ECCSB_DIS : 1; /* [2] r/w */ + uint32_t SRAM0_ECCMB_DIS : 1; /* [3] r/w */ + uint32_t RSVD_7_4 : 4; /* [7:4] ro */ + uint32_t SRAM1_ECCR_DIS : 1; /* [8] r/w */ + uint32_t SRAM1_ECCW_DIS : 1; /* [9] r/w */ + uint32_t SRAM1_ECCSB_DIS : 1; /* [10] r/w */ + uint32_t SRAM1_ECCMB_DIS : 1; /* [11] r/w */ + uint32_t RSVD_31_12 :20; /* [31:12] ro */ + } SCM_ECCOPT; + + /* 0x10*/ + struct { + uint32_t EFPROT : 4; /* [3:0] ro */ + uint32_t EFSIZE : 3; /* [6:4] ro */ + uint32_t EFW : 1; /* [7] ro */ + uint32_t EFMST : 4; /* [11:8] ro */ + uint32_t RSVD_28_12 :17; /* [28:12] ro */ + uint32_t SBERR : 1; /* [29] w1c */ + uint32_t MBERR : 1; /* [30] w1c */ + uint32_t OVERRUN : 1; /* [31] w1c */ + } SCM_ECC0ST; + + /* 0x14*/ + struct { + uint32_t EFADDR :32; /* [31:0] ro */ + } SCM_ECC0FADDR; + + /* 0x18*/ + struct { + uint32_t EFDATA :32; /* [31:0] ro */ + } SCM_ECC0FDATA; + + /* 0x1C*/ + struct { + uint32_t EFPROT : 4; /* [3:0] ro */ + uint32_t EFSIZE : 3; /* [6:4] ro */ + uint32_t EFW : 1; /* [7] ro */ + uint32_t EFMST : 4; /* [11:8] ro */ + uint32_t RSVD_28_12 :17; /* [28:12] ro */ + uint32_t SBERR : 1; /* [29] w1c */ + uint32_t MBERR : 1; /* [30] w1c */ + uint32_t OVERRUN : 1; /* [31] w1c */ + } SCM_ECC1ST; + + /* 0x20*/ + struct { + uint32_t EFADDR :32; /* [31:0] ro */ + } SCM_ECC1FADDR; + + /* 0x24*/ + struct { + uint32_t EFDATA :32; /* [31:0] ro */ + } SCM_ECC1FDATA; + + uint8_t zResverd0x028[216]; /*pad 0x028 - 0FF*/ + + /* 0x100*/ + struct { + uint32_t RSVD_31_0 :32; /* [31:0] ro */ + } SCM_CHIPOPT; + + /* 0x104*/ + struct { + uint32_t RSVD_23_0 :24; /* [23:0] ro */ + uint32_t PFSIZE : 4; /* [27:24] ro */ + uint32_t DFSIZE : 4; /* [31:28] ro */ + } SCM_FLSCFG; + + /* 0x108*/ + struct { + uint32_t RSVD_27_0 :28; /* [27:0] ro */ + uint32_t RAMSIZE : 4; /* [31:28] ro */ + } SCM_RAMCFG; + + uint8_t zResverd0x010C[16]; /*pad 0x010C - 011B*/ + + /* 0x11C*/ + struct { + uint32_t MEMSIZE_ID : 4; /* [3:0] ro */ + uint32_t SERIES_ID : 3; /* [6:4] ro */ + uint32_t SUBFAMILY_ID : 5; /* [11:7] ro */ + uint32_t FAMILY_ID : 4; /* [15:12] ro */ + uint32_t REV_ID : 4; /* [19:16] ro */ + uint32_t FEATURE_ID : 7; /* [26:20] ro */ + uint32_t PACKAGE_ID : 5; /* [31:27] ro */ + } SCM_DEVID; + + /* 0x120*/ + struct { + uint32_t UID_31_0 :32; /* [31:0] ro */ + } SCM_UNIQUE0; + + /* 0x124*/ + struct { + uint32_t UID_63_32 :32; /* [31:0] ro */ + } SCM_UNIQUE1; + + /* 0x128*/ + struct { + uint32_t UID_95_64 :32; /* [31:0] ro */ + } SCM_UNIQUE2; + + /* 0x12C*/ + struct { + uint32_t UID_127_96 :32; /* [31:0] ro */ + } SCM_UNIQUE3; + +}; /*scm_reg*/ + +struct scm_reg_w { + /* 0x00*/ + uint32_t SCM_CHIPCTL; + /* 0x04*/ + uint32_t SCM_MISCCTL; + /* 0x08*/ + uint32_t SCM_TIMOPT; + /* 0x0C*/ + uint32_t SCM_ECCOPT; + /* 0x10*/ + uint32_t SCM_ECC0ST; + /* 0x14*/ + uint32_t SCM_ECC0FADDR; + /* 0x18*/ + uint32_t SCM_ECC0FDATA; + /* 0x1C*/ + uint32_t SCM_ECC1ST; + /* 0x20*/ + uint32_t SCM_ECC1FADDR; + /* 0x24*/ + uint32_t SCM_ECC1FDATA; + uint8_t zResverd0x028[216]; /*pad 0x028 - 0FF*/ + + /* 0x100*/ + uint32_t SCM_CHIPOPT; + /* 0x104*/ + uint32_t SCM_FLSCFG; + /* 0x108*/ + uint32_t SCM_RAMCFG; + uint8_t zResverd0x010C[16]; /*pad 0x010C - 011B*/ + + /* 0x11C*/ + uint32_t SCM_DEVID; + /* 0x120*/ + uint32_t SCM_UNIQUE0; + /* 0x124*/ + uint32_t SCM_UNIQUE1; + /* 0x128*/ + uint32_t SCM_UNIQUE2; + /* 0x12C*/ + uint32_t SCM_UNIQUE3; +}; /*scm_reg*/ + +typedef volatile struct scm_reg scm_reg_t; +typedef volatile struct scm_reg_w scm_reg_w_t; + +struct spi_reg { + /* 0x0*/ + struct { + uint32_t DFS : 4; /* [3:0] r/w */ + uint32_t RSVD_5_4 : 2; /* [5:4] ro */ + uint32_t SCPH : 1; /* [6] r/w */ + uint32_t SCPOL : 1; /* [7] r/w */ + uint32_t TMOD : 2; /* [9:8] r/w */ + uint32_t RSVD_10 : 1; /* [10] r/w */ + uint32_t RSVD_11 : 1; /* [11] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r/w */ + uint32_t DFS_32 : 5; /* [20:16] r/w */ + uint32_t MST_MODE : 1; /* [21] r/w */ + uint32_t RSVD_22 : 1; /* [22] r/w */ + uint32_t RSVD_23 : 1; /* [23] r/w */ + uint32_t RSVD_24 : 1; /* [24] r/w */ + uint32_t RSVD_31_25 : 7; /* [31:25] ro */ + } SPI_CTRLR0; + + /* 0x4*/ + struct { + uint32_t NDF :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] ro */ + } SPI_CTRLR1; + + /* 0x8*/ + struct { + uint32_t SPI_EN : 1; /* [0] r/w */ + uint32_t RSVD_15_1 :15; /* [15:1] ro */ + uint32_t SER : 2; /* [17:16] r/w */ + uint32_t RSVD_31_18 :14; /* [31:18] ro */ + } SPI_SSENR; + + /* 0xC*/ + struct { + uint32_t SCKDV :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] ro */ + } SPI_BAUDR; + + /* 0x10*/ + struct { + uint32_t TFT : 2; /* [1:0] r/w */ + uint32_t RSVD_15_2 :14; /* [15:2] ro */ + uint32_t RFT : 2; /* [17:16] r/w */ + uint32_t RSVD_31_18 :14; /* [31:18] ro */ + } SPI_FTLR; + + /* 0x14*/ + struct { + uint32_t TXTFL : 3; /* [2:0] ro */ + uint32_t RSVD_15_3 :13; /* [15:3] ro */ + uint32_t RXTFL : 3; /* [18:16] ro */ + uint32_t RSVD_31_19 :13; /* [31:19] ro */ + } SPI_FLR; + + /* 0x18*/ + struct { + uint32_t BUSY : 1; /* [0] ro */ + uint32_t TFNF : 1; /* [1] ro */ + uint32_t TFE : 1; /* [2] ro */ + uint32_t RFNE : 1; /* [3] ro */ + uint32_t RFF : 1; /* [4] ro */ + uint32_t TXE : 1; /* [5] ro */ + uint32_t RSVD_31_6 :26; /* [31:6] ro */ + } SPI_SR; + + /* 0x1C*/ + struct { + uint32_t TXEIE : 1; /* [0] r/w */ + uint32_t TXOIE : 1; /* [1] r/w */ + uint32_t RXUIE : 1; /* [2] r/w */ + uint32_t RXOIE : 1; /* [3] r/w */ + uint32_t RXFIE : 1; /* [4] r/w */ + uint32_t RSVD_31_5 :27; /* [31:5] ro */ + } SPI_IER; + + /* 0x20*/ + struct { + uint32_t TXEIS : 1; /* [0] ro */ + uint32_t TXOIS : 1; /* [1] ro */ + uint32_t RXUIS : 1; /* [2] ro */ + uint32_t RXOIS : 1; /* [3] ro */ + uint32_t RXFIS : 1; /* [4] ro */ + uint32_t RSVD_15_5 :11; /* [15:5] ro */ + uint32_t TXEIR : 1; /* [16] ro */ + uint32_t TXOIR : 1; /* [17] ro */ + uint32_t RXUIR : 1; /* [18] ro */ + uint32_t RXOIR : 1; /* [19] ro */ + uint32_t RXFIR : 1; /* [20] ro */ + uint32_t RSVD_31_21 :11; /* [31:21] ro */ + } SPI_ISR; + + /* 0x24*/ + struct { + uint32_t TXOICR : 1; /* [0] ro */ + uint32_t RSVD_31_1 :31; /* [31:1] ro */ + } SPI_TXOICR; + + /* 0x28*/ + struct { + uint32_t RXOICR : 1; /* [0] ro */ + uint32_t RSVD_31_1 :31; /* [31:1] ro */ + } SPI_RXOICR; + + /* 0x2c*/ + struct { + uint32_t RXUICR : 1; /* [0] ro */ + uint32_t RSVD_31_1 :31; /* [31:1] ro */ + } SPI_RXUICR; + + uint8_t zResverd0x030[4]; /*pad 0x030 - 033*/ + + /* 0x34*/ + struct { + uint32_t ICR : 1; /* [0] ro */ + uint32_t RSVD_31_1 :31; /* [31:1] ro */ + } SPI_ICR; + + /* 0x38*/ + struct { + uint32_t RDMAE : 1; /* [0] r/w */ + uint32_t TDMAE : 1; /* [1] r/w */ + uint32_t RSVD_31_2 :30; /* [31:2] ro */ + } SPI_DMACR; + + /* 0x3C*/ + struct { + uint32_t DMATDL : 2; /* [1:0] r/w */ + uint32_t RSVD_31_2 :30; /* [31:2] ro */ + } SPI_DMATDLR; + + /* 0x40*/ + struct { + uint32_t DMARDL : 2; /* [1:0] r/w */ + uint32_t RSVD_31_2 :30; /* [31:2] ro */ + } SPI_DMARDLR; + + /* 0x44*/ + struct { + uint32_t RSVD_31_0 :32; /* [31:0] ro */ + } SPI_IDR; + + /* 0x48*/ + struct { + uint32_t RSVD_31_0 :32; /* [31:0] ro */ + } SPI_VIDR; + + uint8_t zResverd0x04C[20]; /*pad 0x04C - 05F*/ + + /* 0x60*/ + struct { + uint32_t DR :32; /* [31:0] r/w */ + } SPI_DR_LOW; + + uint8_t zResverd0x064[136]; /*pad 0x064 - 0EB*/ + + /* 0xEC*/ + struct { + uint32_t DR :32; /* [31:0] r/w */ + } SPI_DR_HIGH; + +}; /*spi_reg*/ + +struct spi_reg_w { + /* 0x0*/ + uint32_t SPI_CTRLR0; + /* 0x4*/ + uint32_t SPI_CTRLR1; + /* 0x8*/ + uint32_t SPI_SSENR; + /* 0xC*/ + uint32_t SPI_BAUDR; + /* 0x10*/ + uint32_t SPI_FTLR; + /* 0x14*/ + uint32_t SPI_FLR; + /* 0x18*/ + uint32_t SPI_SR; + /* 0x1C*/ + uint32_t SPI_IER; + /* 0x20*/ + uint32_t SPI_ISR; + /* 0x24*/ + uint32_t SPI_TXOICR; + /* 0x28*/ + uint32_t SPI_RXOICR; + /* 0x2c*/ + uint32_t SPI_RXUICR; + uint8_t zResverd0x030[4]; /*pad 0x030 - 033*/ + + /* 0x34*/ + uint32_t SPI_ICR; + /* 0x38*/ + uint32_t SPI_DMACR; + /* 0x3C*/ + uint32_t SPI_DMATDLR; + /* 0x40*/ + uint32_t SPI_DMARDLR; + /* 0x44*/ + uint32_t SPI_IDR; + /* 0x48*/ + uint32_t SPI_VIDR; + uint8_t zResverd0x04C[20]; /*pad 0x04C - 05F*/ + + /* 0x60*/ + uint32_t SPI_DR_LOW; + uint8_t zResverd0x064[136]; /*pad 0x064 - 0EB*/ + + /* 0xEC*/ + uint32_t SPI_DR_HIGH; +}; /*spi_reg*/ + +typedef volatile struct spi_reg spi_reg_t; +typedef volatile struct spi_reg_w spi_reg_w_t; + +struct srmc_reg { + /* 0x00*/ + struct { + uint32_t FEATURE :16; /* [15:0] ro */ + uint32_t MINOR : 8; /* [23:16] ro */ + uint32_t MAJOR : 8; /* [31:24] ro */ + } SRMC_VERID; + + /* 0x04*/ + struct { + uint32_t EWAKEUP : 1; /* [0] ro */ + uint32_t ELVD : 1; /* [1] ro */ + uint32_t ELOC : 1; /* [2] ro */ + uint32_t RSVD_3 : 1; /* [3] ro */ + uint32_t RSVD_4 : 1; /* [4] ro */ + uint32_t EWDOG : 1; /* [5] ro */ + uint32_t EPIN : 1; /* [6] ro */ + uint32_t EPOR : 1; /* [7] ro */ + uint32_t RSVD_8 : 1; /* [8] ro */ + uint32_t ELOCKUP : 1; /* [9] ro */ + uint32_t ESW : 1; /* [10] ro */ + uint32_t EMDM_AP : 1; /* [11] ro */ + uint32_t RSVD_12 : 1; /* [12] ro */ + uint32_t ESACKERR : 1; /* [13] ro */ + uint32_t RSVD_15_14 : 2; /* [15:14] ro */ + uint32_t EPDOWN : 1; /* [16] ro */ + uint32_t RSVD_31_17 :15; /* [31:17] ro */ + } SRMC_PARAM; + + /* 0x08*/ + struct { + uint32_t WAKEUP : 1; /* [0] ro */ + uint32_t LVD : 1; /* [1] w1c */ + uint32_t LOC : 1; /* [2] w1c */ + uint32_t RSVD_4_3 : 2; /* [4:3] ro */ + uint32_t WDOG : 1; /* [5] w1c */ + uint32_t PIN : 1; /* [6] w1c */ + uint32_t POR : 1; /* [7] w1c */ + uint32_t RSVD_8 : 1; /* [8] ro */ + uint32_t LOCKUP : 1; /* [9] w1c */ + uint32_t SW : 1; /* [10] w1c */ + uint32_t MDM_AP : 1; /* [11] w1c */ + uint32_t RSVD_14_12 : 3; /* [14:12] ro */ + uint32_t SACKERR : 1; /* [15] w1c */ + uint32_t RSVD_31_16 :16; /* [31:16] ro */ + } SRMC_SRS; + + /* 0x0C*/ + struct { + uint32_t RSTFLTSRW : 2; /* [1:0] r/w */ + uint32_t RSTFLTSS : 1; /* [2] r/w */ + uint32_t RSVD_7_3 : 5; /* [7:3] r/w */ + uint32_t RSTFLTSEL : 5; /* [12:8] r/w */ + uint32_t RSVD_30_13 :18; /* [30:13] r */ + uint32_t LOCKUP_RST_EN : 1; /* [31] r/w */ + } SRMC_CTRL; + + /* 0x10*/ + struct { + uint32_t RSVD_31_0 :32; /* [31:0] ro */ + } SRMC_MR; + + /* 0x14*/ + struct { + uint32_t RSVD_31_0 :32; /* [31:0] ro */ + } SRMC_FM; + + /* 0x18*/ + struct { + uint32_t WAKEUP : 1; /* [0] ro */ + uint32_t SLVD : 1; /* [1] ro */ + uint32_t SLOC : 1; /* [2] ro */ + uint32_t RSVD_4_3 : 2; /* [4:3] ro */ + uint32_t SWDOG : 1; /* [5] ro */ + uint32_t SPIN : 1; /* [6] ro */ + uint32_t SPOR : 1; /* [7] ro */ + uint32_t RSVD_8 : 1; /* [8] ro */ + uint32_t SLOCKUP : 1; /* [9] ro */ + uint32_t SSW : 1; /* [10] ro */ + uint32_t SMDM_AP : 1; /* [11] ro */ + uint32_t RSVD_14_12 : 3; /* [14:12] ro */ + uint32_t SSACKERR : 1; /* [15] ro */ + uint32_t RSVD_31_16 :16; /* [31:16] ro */ + } SRMC_SSRS; + + /* 0x1C*/ + struct { + uint32_t DELAY : 2; /* [1:0] r/w */ + uint32_t LOC : 1; /* [2] r/w */ + uint32_t RSVD_4_3 : 2; /* [4:3] ro */ + uint32_t WDOG : 1; /* [5] r/w */ + uint32_t PIN : 1; /* [6] r/w */ + uint32_t GIE : 1; /* [7] r/w */ + uint32_t RSVD_8 : 1; /* [8] ro */ + uint32_t LOCKUP : 1; /* [9] r/w */ + uint32_t SW : 1; /* [10] r/w */ + uint32_t RSVD_14_11 : 4; /* [14:11] ro */ + uint32_t SACKERR : 1; /* [15] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] ro */ + } SRMC_SRIE; + + /* 0x20*/ + struct { + uint32_t APD : 1; /* [0] r/w */ + uint32_t RSVD_31_1 :31; /* [31:1] ro */ + } SRMC_PMPORT; + + /* 0x24*/ + struct { + uint32_t DSMC : 2; /* [1:0] r/w */ + uint32_t RSVD_7_2 : 6; /* [7:2] ro */ + uint32_t DSMACKTMO : 8; /* [15:8] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] ro */ + } SRMC_PMCTRL; + + /* 0x28*/ + struct { + uint32_t PMSTAT : 4; /* [3:0] ro */ + uint32_t RSVD_7_4 : 4; /* [7:4] ro */ + uint32_t DSMABORT : 1; /* [8] ro */ + uint32_t RSVD_31_9 :23; /* [31:9] ro */ + } SRMC_PMSTAT; + + /* 0x2C*/ + struct { + uint32_t WUPSRC_EN0 : 3; /* [2:0] r/w */ + uint32_t RSVD_3 : 1; /* [3] ro */ + uint32_t WUPSRC_EN1 : 8; /* [11:4] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] ro */ + uint32_t WUPSRC_PL0 : 3; /* [18:16] r/w */ + uint32_t RSVD_19 : 1; /* [19] ro */ + uint32_t WUPSRC_PL1 : 8; /* [27:20] r/w */ + uint32_t RSVD_31_28 : 4; /* [31:28] ro */ + } SRMC_DSMWUPC; + + /* 0x30*/ + struct { + uint32_t WUPS0 : 3; /* [2:0] w1c */ + uint32_t RSVD_3 : 1; /* [3] ro */ + uint32_t WUPS1 : 8; /* [11:4] w1c */ + uint32_t RSVD_31_28 : 4; /* [31:28] ro */ + } SRMC_DSMWUPS; + +}; /*srmc_reg*/ + +struct srmc_reg_w { + /* 0x00*/ + uint32_t SRMC_VERID; + /* 0x04*/ + uint32_t SRMC_PARAM; + /* 0x08*/ + uint32_t SRMC_SRS; + /* 0x0C*/ + uint32_t SRMC_CTRL; + /* 0x10*/ + uint32_t SRMC_MR; + /* 0x14*/ + uint32_t SRMC_FM; + /* 0x18*/ + uint32_t SRMC_SSRS; + /* 0x1C*/ + uint32_t SRMC_SRIE; + /* 0x20*/ + uint32_t SRMC_PMPORT; + /* 0x24*/ + uint32_t SRMC_PMCTRL; + /* 0x28*/ + uint32_t SRMC_PMSTAT; + /* 0x2C*/ + uint32_t SRMC_DSMWUPC; + /* 0x30*/ + uint32_t SRMC_DSMWUPS; +}; /*srmc_reg*/ + +typedef volatile struct srmc_reg srmc_reg_t; +typedef volatile struct srmc_reg_w srmc_reg_w_t; + +struct stim_reg { + /* 0x00*/ + struct { + uint32_t VERID :32; /* [31:0] ro */ + } STIM_VERID; + + /* 0x04*/ + struct { + uint32_t CNT :32; /* [31:0] ro */ + } STIM_CNTn[4]; + + /* 0x14*/ + struct { + uint32_t CV :32; /* [31:0] r/w */ + } STIM_CVn[4]; + + /* 0x24*/ + struct { + uint32_t CLKS : 2; /* [1:0] r/w */ + uint32_t PSDIV : 4; /* [5:2] r/w */ + uint32_t PSEN : 1; /* [6] r/w */ + uint32_t POL : 1; /* [7] r/w */ + uint32_t PSRC : 2; /* [9:8] r/w */ + uint32_t MODE : 1; /* [10] r/w */ + uint32_t RSTDIS : 1; /* [11] r/w */ + uint32_t DMAE : 1; /* [12] r/w */ + uint32_t IE : 1; /* [13] r/w */ + uint32_t EN : 1; /* [14] r/w */ + uint32_t FLAG : 1; /* [15] w1c */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } STIM_SCn[4]; + +}; /*stim_reg*/ + +struct stim_reg_w { + /* 0x00*/ + uint32_t STIM_VERID; + /* 0x04*/ + uint32_t STIM_CNTn[4]; + /* 0x14*/ + uint32_t STIM_CVn[4]; + /* 0x24*/ + uint32_t STIM_SCn[4]; +}; /*stim_reg*/ + +typedef volatile struct stim_reg stim_reg_t; +typedef volatile struct stim_reg_w stim_reg_w_t; + +struct tdg_reg { + /* 0x0*/ + struct { + uint32_t MINOR : 4; /* [3:0] r */ + uint32_t MAJOR : 4; /* [7:4] r */ + uint32_t RSVD_31_8 :24; /* [31:8] r */ + } TDG_VERID; + + /* 0x4*/ + struct { + uint32_t DOPNUM : 4; /* [3:0] r */ + uint32_t CHNUM : 4; /* [7:4] r */ + uint32_t RSVD_31_8 :24; /* [31:8] r */ + } TDG_PARAM; + + /* 0x8*/ + struct { + uint32_t TDGEN : 1; /* [0] r/w */ + uint32_t RSVD_3_1 : 3; /* [3:1] */ + uint32_t TRIGS : 1; /* [4] r/w */ + uint32_t CNTMD : 1; /* [5] r/w */ + uint32_t CLRMD : 1; /* [6] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t PRES : 3; /* [10:8] r/w */ + uint32_t RSVD_15_11 : 5; /* [15:11] r */ + uint32_t CFGUP : 1; /* [16] r/w */ + uint32_t SWTRG : 1; /* [17] r/w */ + uint32_t RSVD_19_18 : 2; /* [19:18] */ + uint32_t UPMD : 2; /* [21:20] r */ + uint32_t RSVD_31_22 :10; /* [31:22] r */ + } TDG_CTRL1; + + /* 0xC*/ + struct { + uint32_t CDO0IE : 1; /* [0] r/w */ + uint32_t CDO1IE : 1; /* [1] r/w */ + uint32_t CDO2IE : 1; /* [2] r/w */ + uint32_t CDO3IE : 1; /* [3] r/w */ + uint32_t CDO4IE : 1; /* [4] r/w */ + uint32_t CDO5IE : 1; /* [5] r/w */ + uint32_t RSVD_7_6 : 2; /* [7:6] r */ + uint32_t ERRIE : 1; /* [8] r/w */ + uint32_t RSVD_15_9 : 7; /* [15:9] r */ + uint32_t CH0E : 1; /* [16] r/w */ + uint32_t CH1E : 1; /* [17] r/w */ + uint32_t CH2E : 1; /* [18] r/w */ + uint32_t CH3E : 1; /* [19] r/w */ + uint32_t CH4E : 1; /* [20] r/w */ + uint32_t CH5E : 1; /* [21] r/w */ + uint32_t RSVD_31_22 :10; /* [31:22] r */ + } TDG_CTRL2; + + /* 0x10*/ + struct { + uint32_t CDO0IF : 1; /* [0] r/w */ + uint32_t CDO1IF : 1; /* [1] r/w */ + uint32_t CDO2IF : 1; /* [2] r/w */ + uint32_t CDO3IF : 1; /* [3] r/w */ + uint32_t CDO4IF : 1; /* [4] r/w */ + uint32_t CDO5IF : 1; /* [5] r/w */ + uint32_t RSVD_7_6 : 2; /* [7:6] */ + uint32_t ERRIF : 1; /* [8] r/w */ + uint32_t RSVD_31_9 :23; /* [31:9] */ + } TDG_STAT; + + /* 0x14*/ + struct { + uint32_t MOD :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] r */ + } TDG_MOD; + + /* 0x18*/ + struct { + uint32_t CNT :16; /* [15:0] r */ + uint32_t RSVD_31_16 :16; /* [31:16] r */ + } TDG_CNT; + + /* 0x1C*/ + struct { + struct { + uint32_t RSVD_7_0 : 8; /* [7:0] */ + uint32_t DO0E : 1; /* [8] r/w */ + uint32_t DO1E : 1; /* [9] r/w */ + uint32_t DO2E : 1; /* [10] r/w */ + uint32_t DO3E : 1; /* [11] r/w */ + uint32_t DO4E : 1; /* [12] r/w */ + uint32_t DO5E : 1; /* [13] r/w */ + uint32_t DO6E : 1; /* [14] r/w */ + uint32_t DO7E : 1; /* [15] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } TDG_CHCTRL; + + /* 0x20 - 0x3F*/ + struct { + uint32_t DO0OFS :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] r */ + } TDG_CHDOOFS[8]; + + /* 0x40*/ + struct { + uint32_t CDOINTDLY :10; /* [9:0] r/w */ + uint32_t RSVD_15_10 : 6; /* [15:10] r */ + uint32_t LDCO : 1; /* [16] r/w */ + uint32_t RSVD_31_17 :15; /* [31:17] r */ + } TDG_CHDOCINTDLY; + + } TDG_CHCFG[6]; +}; /*tdg_reg*/ + +struct tdg_reg_w { + /* 0x0*/ + uint32_t TDG_VERID; + /* 0x4*/ + uint32_t TDG_PARAM; + /* 0x8*/ + uint32_t TDG_CTRL1; + /* 0xC*/ + uint32_t TDG_CTRL2; + /* 0x10*/ + uint32_t TDG_STAT; + /* 0x14*/ + uint32_t TDG_MOD; + /* 0x18*/ + uint32_t TDG_CNT; + + struct { + /* 0x1C */ + uint32_t TDG_CHCTRL; + /* 0x20 - 0x3F*/ + uint32_t TDG_CHDOOFS[8]; + /* 0x40*/ + uint32_t TDG_CHDOCINTDLY; + }TDG_CHCFG[6]; + +}; /*tdg_reg*/ + +typedef volatile struct tdg_reg tdg_reg_t; +typedef volatile struct tdg_reg_w tdg_reg_w_t; + +struct tim_reg { + /* 0x00*/ + struct { + uint32_t CKSRC : 2; /* [1:0] r/w */ + uint32_t PSDIV : 3; /* [4:2] r/w */ + uint32_t DBGM : 2; /* [6:5] r/w */ + uint32_t RSVD_31_7 :25; /* [31:7] */ + } TIM_TIMEBASE; + + /* 0x04*/ + struct { + uint32_t CNT :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } TIM_CNT; + + /* 0x08*/ + struct { + uint32_t CNTINIT :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } TIM_CNTINIT; + + /* 0x0C*/ + struct { + uint32_t MOD :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } TIM_MOD; + + /* 0x10*/ + struct { + uint32_t CHOE0 : 1; /* [0] r/w */ + uint32_t CHOE1 : 1; /* [1] r/w */ + uint32_t CHOE2 : 1; /* [2] r/w */ + uint32_t CHOE3 : 1; /* [3] r/w */ + uint32_t CHOE4 : 1; /* [4] r/w */ + uint32_t CHOE5 : 1; /* [5] r/w */ + uint32_t CHOE6 : 1; /* [6] r/w */ + uint32_t CHOE7 : 1; /* [7] r/w */ + uint32_t RLDIE : 1; /* [8] r/w */ + uint32_t TOIE : 1; /* [9] r/w */ + uint32_t CNTMODE : 1; /* [10] r/w */ + uint32_t INIT : 1; /* [11] w/o */ + uint32_t RSVD_31_12 :20; /* [31:12] */ + } TIM_GLBCR; + + /* 0x14*/ + struct { + uint32_t CH0F : 1; /* [0] r/o */ + uint32_t CH1F : 1; /* [1] r/o */ + uint32_t CH2F : 1; /* [2] r/o */ + uint32_t CH3F : 1; /* [3] r/o */ + uint32_t CH4F : 1; /* [4] r/o */ + uint32_t CH5F : 1; /* [5] r/o */ + uint32_t CH6F : 1; /* [6] r/o */ + uint32_t CH7F : 1; /* [7] r/o */ + uint32_t RLDF : 1; /* [8] r/o */ + uint32_t TOF : 1; /* [9] r/o */ + uint32_t WPDIS : 1; /* [10] r/w */ + uint32_t RSVD_31_11 :21; /* [31:11] */ + } TIM_GLBSR; + + /* 0x18*/ + struct { + uint32_t ELS : 2; /* [1:0] r/w */ + uint32_t CMS : 2; /* [3:2] r/w */ + uint32_t CHIE : 1; /* [4] r/w */ + uint32_t CHF : 1; /* [5] r/o */ + uint32_t DMAEN : 1; /* [6] r/w */ + uint32_t ICRST : 1; /* [7] r/w */ + uint32_t RSVD_31_8 :24; /* [31:8] */ + } TIM_CMCn[8]; + + /* 0x38*/ + struct { + uint32_t CCV :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } TIM_CCVn[8]; + + /* 0x58*/ + struct { + uint32_t INIT0 : 1; /* [0] r/w */ + uint32_t INIT1 : 1; /* [1] r/w */ + uint32_t INIT2 : 1; /* [2] r/w */ + uint32_t INIT3 : 1; /* [3] r/w */ + uint32_t INIT4 : 1; /* [4] r/w */ + uint32_t INIT5 : 1; /* [5] r/w */ + uint32_t INIT6 : 1; /* [6] r/w */ + uint32_t INIT7 : 1; /* [7] r/w */ + uint32_t POL0 : 1; /* [8] r/w */ + uint32_t POL1 : 1; /* [9] r/w */ + uint32_t POL2 : 1; /* [10] r/w */ + uint32_t POL3 : 1; /* [11] r/w */ + uint32_t POL4 : 1; /* [12] r/w */ + uint32_t POL5 : 1; /* [13] r/w */ + uint32_t POL6 : 1; /* [14] r/w */ + uint32_t POL7 : 1; /* [15] r/w */ + uint32_t TRIGE0 : 1; /* [16] r/w */ + uint32_t TRIGE1 : 1; /* [17] r/w */ + uint32_t TRIGE2 : 1; /* [18] r/w */ + uint32_t TRIGE3 : 1; /* [19] r/w */ + uint32_t TRIGE4 : 1; /* [20] r/w */ + uint32_t TRIGE5 : 1; /* [21] r/w */ + uint32_t TRIGE6 : 1; /* [22] r/w */ + uint32_t TRIGE7 : 1; /* [23] r/w */ + uint32_t INITRIGE : 1; /* [24] r/w */ + uint32_t TRIGF : 1; /* [25] r/o */ + uint32_t RSVD_31_26 : 6; /* [31:26] */ + } TIM_OUTCR; + + /* 0x5C*/ + struct { + uint32_t CH0OC : 1; /* [0] r/w */ + uint32_t CH1OC : 1; /* [1] r/w */ + uint32_t CH2OC : 1; /* [2] r/w */ + uint32_t CH3OC : 1; /* [3] r/w */ + uint32_t CH4OC : 1; /* [4] r/w */ + uint32_t CH5OC : 1; /* [5] r/w */ + uint32_t CH6OC : 1; /* [6] r/w */ + uint32_t CH7OC : 1; /* [7] r/w */ + uint32_t CH0OCV : 1; /* [8] r/w */ + uint32_t CH1OCV : 1; /* [9] r/w */ + uint32_t CH2OCV : 1; /* [10] r/w */ + uint32_t CH3OCV : 1; /* [11] r/w */ + uint32_t CH4OCV : 1; /* [12] r/w */ + uint32_t CH5OCV : 1; /* [13] r/w */ + uint32_t CH6OCV : 1; /* [14] r/w */ + uint32_t CH7OCV : 1; /* [15] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } TIM_OUTSWCR; + + /* 0x60*/ + struct { + uint32_t FCTLEN0 : 1; /* [0] r/w */ + uint32_t DTEN0 : 1; /* [1] r/w */ + uint32_t COMB0 : 1; /* [2] r/w */ + uint32_t SYNCEN0 : 1; /* [3] r/w */ + uint32_t DECAPEN0 : 1; /* [4] r/w */ + uint32_t DECAP0 : 1; /* [5] r/w */ + uint32_t RSVD_7_6 : 2; /* [7:6] */ + uint32_t FCTLEN1 : 1; /* [8] r/w */ + uint32_t DTEN1 : 1; /* [9] r/w */ + uint32_t COMB1 : 1; /* [10] r/w */ + uint32_t SYNCEN1 : 1; /* [11] r/w */ + uint32_t DECAPEN1 : 1; /* [12] r/w */ + uint32_t DECAP1 : 1; /* [13] r/w */ + uint32_t RSVD_15_14 : 2; /* [15:14] */ + uint32_t FCTLEN2 : 1; /* [16] r/w */ + uint32_t DTEN2 : 1; /* [17] r/w */ + uint32_t COMB2 : 1; /* [18] r/w */ + uint32_t SYNCEN2 : 1; /* [19] r/w */ + uint32_t DECAPEN2 : 1; /* [20] r/w */ + uint32_t DECAP2 : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] */ + uint32_t FCTLEN3 : 1; /* [24] r/w */ + uint32_t DTEN3 : 1; /* [25] r/w */ + uint32_t COMB3 : 1; /* [26] r/w */ + uint32_t SYNCEN3 : 1; /* [27] r/w */ + uint32_t DECAPEN3 : 1; /* [28] r/w */ + uint32_t DECAP3 : 1; /* [29] r/w */ + uint32_t RSVD_31_30 : 2; /* [31:30] */ + } TIM_PCR; + + /* 0x64*/ + struct { + uint32_t FILVAL0 : 4; /* [3:0] r/w */ + uint32_t FILVAL1 : 4; /* [7:4] r/w */ + uint32_t FILVAL2 : 4; /* [11:8] r/w */ + uint32_t FILVAL3 : 4; /* [15:12] r/w */ + uint32_t DTPS : 2; /* [17:16] r/w */ + uint32_t DTVAL : 6; /* [23:18] r/w */ + uint32_t RSVD_31_24 : 8; /* [31:24] */ + } TIM_FILTER; + + /* 0x68*/ + struct { + uint32_t FAULTEN0 : 1; /* [0] r/w */ + uint32_t FIFEN0 : 1; /* [1] r/w */ + uint32_t FLTPOL0 : 1; /* [2] r/w */ + uint32_t FAULTEN1 : 1; /* [3] r/w */ + uint32_t FIFEN1 : 1; /* [4] r/w */ + uint32_t FLTPOL1 : 1; /* [5] r/w */ + uint32_t FLTIE : 1; /* [6] r/w */ + uint32_t FLTCEN : 1; /* [7] r/w */ + uint32_t FLTCM : 1; /* [8] r/w */ + uint32_t RSVD_10_9 : 2; /* [10:9] */ + uint32_t FIFVAL : 4; /* [14:11] r/w */ + uint32_t FSTATE : 1; /* [15] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } TIM_FLTCR; + + /* 0x6C*/ + struct { + uint32_t FAULTF0 : 1; /* [0] r/o */ + uint32_t FAULTF1 : 1; /* [1] r/o */ + uint32_t RSVD_3_2 : 2; /* [3:2] */ + uint32_t FAULTF : 1; /* [4] r/o */ + uint32_t FAULTIN : 1; /* [5] r/o */ + uint32_t WPEN : 1; /* [6] r/w */ + uint32_t RSVD_31_7 :25; /* [31:7] */ + } TIM_FLTSR; + + /* 0x70*/ + struct { + uint32_t SWTRIG : 1; /* [0] r/w */ + uint32_t RSVD_7_1 : 7; /* [7:1] */ + uint32_t SYNCINIT : 1; /* [8] r/w */ + uint32_t SYNCOSWC : 1; /* [9] r/w */ + uint32_t RSVD_17_10 : 8; /* [17:10] */ + uint32_t SWWRBUF : 1; /* [18] r/w */ + uint32_t SWRSTCNT : 1; /* [19] r/w */ + uint32_t RSVD_31_20 :12; /* [31:20] */ + } TIM_SYNC; + + /* 0x74*/ + struct { + uint32_t CH0SEL : 1; /* [0] r/w */ + uint32_t CH1SEL : 1; /* [1] r/w */ + uint32_t CH2SEL : 1; /* [2] r/w */ + uint32_t CH3SEL : 1; /* [3] r/w */ + uint32_t CH4SEL : 1; /* [4] r/w */ + uint32_t CH5SEL : 1; /* [5] r/w */ + uint32_t CH6SEL : 1; /* [6] r/w */ + uint32_t CH7SEL : 1; /* [7] r/w */ + uint32_t LOADEN : 1; /* [8] r/w */ + uint32_t RSVD_10_9 : 2; /* [10:9] */ + uint32_t HCSEL : 1; /* [11] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] */ + uint32_t LDFREQ : 5; /* [20:16] r/w */ + uint32_t RSVD_31_21 :11; /* [31:21] */ + } TIM_RELOAD; + + /* 0x78*/ + struct { + uint32_t HCV :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } TIM_HCV; + +}; /*tim_reg*/ + +struct tim_reg_w { + /* 0x00*/ + uint32_t TIM_TIMEBASE; + /* 0x04*/ + uint32_t TIM_CNT; + /* 0x08*/ + uint32_t TIM_CNTINIT; + /* 0x0C*/ + uint32_t TIM_MOD; + /* 0x10*/ + uint32_t TIM_GLBCR; + /* 0x14*/ + uint32_t TIM_GLBSR; + /* 0x18*/ + uint32_t TIM_CMCn[8]; + /* 0x38*/ + uint32_t TIM_CCVn[8]; + /* 0x58*/ + uint32_t TIM_OUTCR; + /* 0x5C*/ + uint32_t TIM_OUTSWCR; + /* 0x60*/ + uint32_t TIM_PCR; + /* 0x64*/ + uint32_t TIM_FILTER; + /* 0x68*/ + uint32_t TIM_FLTCR; + /* 0x6C*/ + uint32_t TIM_FLTSR; + /* 0x70*/ + uint32_t TIM_SYNC; + /* 0x74*/ + uint32_t TIM_RELOAD; + /* 0x78*/ + uint32_t TIM_HCV; +}; /*tim_reg*/ + +typedef volatile struct tim_reg tim_reg_t; +typedef volatile struct tim_reg_w tim_reg_w_t; + +struct tmu_reg { + /* 0x0*/ + struct { + uint32_t SEL : 6; /* [5:0] r/w */ + uint32_t RSVD_6 : 1; /* [6] ro */ + uint32_t EN : 1; /* [7] r/w */ + uint32_t RSVD_30_8 :23; /* [30:8] ro */ + uint32_t LOCK : 1; /* [31] r/w */ + } TMU_CFGn[40]; + +}; /*tmu_reg*/ + +struct tmu_reg_w { + /* 0x0*/ + uint32_t TMU_CFGn[40]; +}; /*tmu_reg*/ + +typedef volatile struct tmu_reg tmu_reg_t; +typedef volatile struct tmu_reg_w tmu_reg_w_t; + +struct uart_reg { + /* 0x0*/ + union { + struct { + uint32_t RBR_LSB : 8; /* [7:0] ro */ + uint32_t RBR_MSB : 1; /* [8] ro */ + uint32_t RSVD_31_9 :23; /* [31:9] */ + } UART_RBR; + struct { + uint32_t THR_LSB : 8; /* [7:0] wo */ + uint32_t THR_MSB : 1; /* [8] wo */ + uint32_t RSVD_31_9 :23; /* [31:9] */ + } UART_THR; + struct { + uint32_t DL_L : 8; /* [7:0] r/w */ + uint32_t RSVD_31_8 :24; /* [31:8] */ + } UART_DLL; + } UART_RBR_THR_DLL; + + /* 0x4*/ + union { + struct { + uint32_t DL_H : 8; /* [7:0] r/w */ + uint32_t RSVD_31_8 :24; /* [31:8] */ + } UART_DLH; + struct { + uint32_t ERBFI : 1; /* [0] r/w */ + uint32_t ETBEI : 1; /* [1] r/w */ + uint32_t ELSI : 1; /* [2] r/w */ + uint32_t RSVD_6_3 : 4; /* [6:3] r/w */ + uint32_t PTIME : 1; /* [7] r/w */ + uint32_t HEADER_DONE_INT_EN : 1; /* [8] r/w */ + uint32_t RSP_DONE_INT_EN : 1; /* [9] r/w */ + uint32_t ASYNC_INT_EN : 1; /* [10] r/w */ + uint32_t RSVD_31_11 :21; /* [31:11] */ + } UART_IER; + } UART_DLH_IER; + + /* 0x8*/ + union { + struct { + uint32_t IID : 4; /* [3:0] ro */ + uint32_t RSVD_5_4 : 2; /* [5:4] */ + uint32_t FIFOSE : 2; /* [7:6] ro */ + uint32_t RSVD_31_8 :24; /* [31:8] */ + } UART_IIR; + struct { + uint32_t FIFOE : 1; /* [0] wo */ + uint32_t RFIFOR : 1; /* [1] wo */ + uint32_t XFIFOR : 1; /* [2] wo */ + uint32_t RSVD_3 : 1; /* [3] wo */ + uint32_t TET : 2; /* [5:4] wo */ + uint32_t RCVR : 2; /* [7:6] wo */ + uint32_t RSVD_31_8 :24; /* [31:8] */ + } UART_FCR; + } UART_IIR_FCR; + + /* 0xC*/ + struct { + uint32_t DLS : 2; /* [1:0] r/w */ + uint32_t STOP : 1; /* [2] r/w */ + uint32_t PEN : 1; /* [3 ] r/w */ + uint32_t EPS : 1; /* [4] r/w */ + uint32_t STP : 1; /* [5 ] r/w */ + uint32_t BC : 1; /* [6] r/w */ + uint32_t DLAB : 1; /* [7] r/w */ + uint32_t LBKEN : 1; /* [8] r/w */ + uint32_t LBKM : 5; /* [13:9] r/w */ + uint32_t IDLE_DET_LENGTH : 3; /* [16:14] r/w */ + uint32_t IDLE_DET_EN : 1; /* [17] r/w */ + uint32_t AUTO_SYNC_EN : 1; /* [18] r/w */ + uint32_t DEBUG_EN : 1; /* [19] r/w */ + uint32_t RSVD_31_20 :12; /* [31:20] */ + } UART_LCR; + + /* 0x10*/ + struct { + uint32_t RSVD_0 : 1; /* [0] */ + uint32_t RTS : 1; /* [1] r/w */ + uint32_t RSVD_2 : 1; /* [2] */ + uint32_t RSVD_3 : 1; /* [3 ] */ + uint32_t LB : 1; /* [4] r/w */ + uint32_t AFCE : 1; /* [5 ] r/w */ + uint32_t RSVD_6 : 1; /* [6] r/w */ + uint32_t RSVD_31_7 :25; /* [31:7] */ + } UART_AFCR; + + /* 0x14*/ + struct { + uint32_t DR : 1; /* [0] ro */ + uint32_t OE : 1; /* [1] ro */ + uint32_t PE : 1; /* [2] ro */ + uint32_t FE : 1; /* [3 ] ro */ + uint32_t BI : 1; /* [4] ro */ + uint32_t THRE : 1; /* [5 ] ro */ + uint32_t TEMT : 1; /* [6] ro */ + uint32_t RFE : 1; /* [7] ro */ + uint32_t ADDR_RCVD : 1; /* [8] ro */ + uint32_t ASYNC_INT : 1; /* [9] ro */ + uint32_t SYNC_FIELD_ERROR : 1; /* [10] ro */ + uint32_t PID_ERR : 1; /* [11] ro */ + uint32_t CHECKSUM_ERROR : 1; /* [12] ro */ + uint32_t TO_ERROR : 1; /* [13] ro */ + uint32_t HEADER_OP_DONE : 1; /* [14] ro */ + uint32_t RSP_OP_DONE : 1; /* [15] ro */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } UART_LSR; + + uint8_t zResverd0x018[100]; /*pad 0x018 - 07B*/ + + /* 0x7C*/ + struct { + uint32_t BUSY : 1; /* [0] ro */ + uint32_t RSVD_4_1 : 4; /* [4:1] */ + uint32_t RSVD_31_5 :27; /* [31:5] */ + } UART_USR; + + uint8_t zResverd0x080[40]; /*pad 0x080 - 0A7*/ + + /* 0xA8*/ + struct { + uint32_t RSVD_0 : 1; /* [0] wo */ + uint32_t RSVD_31_1 :31; /* [31:1] */ + } UART_DMA_SA; + + uint8_t zResverd0x0AC[20]; /*pad 0x0AC - 0BF*/ + + /* 0xC0*/ + struct { + uint32_t FD : 4; /* [3:0] r/w */ + uint32_t RSVD_31_4 :28; /* [31:4] */ + } UART_FD; + + /* 0xC4*/ + struct { + uint32_t RAR : 8; /* [7:0] r/w */ + uint32_t RSVD_31_8 :24; /* [31:8] */ + } UART_RAR; + + /* 0xC8*/ + struct { + uint32_t TAR : 8; /* [7:0] r/w */ + uint32_t RSVD_31_8 :24; /* [31:8] */ + } UART_TAR; + + /* 0xCC*/ + struct { + uint32_t DLS_E : 1; /* [0] r/w */ + uint32_t ADDR_MATCH : 1; /* [1] r/w */ + uint32_t SEND_ADDR : 1; /* [2] r/w */ + uint32_t TRANSMIST_MODE : 1; /* [3] r/w */ + uint32_t RSVD_31_4 :28; /* [31:4] */ + } UART_LCR_EXT; + + uint8_t zResverd0x0D0[48]; /*pad 0x0D0 - 0FF*/ + + /* 0x100*/ + struct { + uint32_t LIN_MODE : 1; /* [0] r/w */ + uint32_t MASTER_MODE : 1; /* [1] r/w */ + uint32_t HEADER_OP_START : 1; /* [2] r/w */ + uint32_t RSP_OP_START : 1; /* [3 ] r/w */ + uint32_t RSP_DIR : 1; /* [4] r/w */ + uint32_t RSVD_31_5 :27; /* [31:5] */ + } UART_LIN_CTL; + + /* 0x104*/ + struct { + uint32_t RSP_LENGTH : 4; /* [3:0] r/w */ + uint32_t RSVD_31_4 :28; /* [31:4] */ + } UART_LIN_RSP_LENGTH; + + /* 0x108*/ + struct { + uint32_t PID : 6; /* [5:0] r/w */ + uint32_t RSVD_31_6 :26; /* [31:6] */ + } UART_LIN_PID_VALUE; + + /* 0x10C*/ + struct { + uint32_t CHECKSUM_TYPE : 1; /* [0] r/w */ + uint32_t RSVD_7_1 : 7; /* [7:1] */ + uint32_t RSVD_31_8 :24; /* [31:8] */ + } UART_LIN_CHECKSUM; + + /* 0x110*/ + struct { + uint32_t LIN_DEL_LENGTH : 3; /* [2:0] r/w */ + uint32_t RSVD_31_3 :29; /* [31:3] */ + } UART_LIN_DEL_LENGTH; + + uint8_t zResverd0x114[24]; /* pad 0x114 - 12B */ + +}; /*uart_reg*/ + +struct uart_reg_w { + /* 0x0*/ + union { + uint32_t UART_RBR; + uint32_t UART_THR; + uint32_t UART_DLL; + }UART_RBR_THR_DLL; + /* 0x4*/ + union { + uint32_t UART_DLH; + uint32_t UART_IER; + }UART_DLH_IER; + /* 0x8*/ + union { + uint32_t UART_IIR; + uint32_t UART_FCR; + }UART_IIR_FCR; + /* 0xC*/ + uint32_t UART_LCR; + /* 0x10*/ + uint32_t UART_AFCR; + /* 0x14*/ + uint32_t UART_LSR; + /* 0x18*/ + uint32_t UART_MSR; + uint8_t zResverd0x01C[96]; /*pad 0x01C - 07B*/ + + /* 0x7C*/ + uint32_t UART_USR; + uint8_t zResverd0x080[40]; /*pad 0x080 - 0A7*/ + + /* 0xA8*/ + uint32_t UART_DMA_SA; + uint8_t zResverd0x0AC[20]; /*pad 0x0AC - 0BF*/ + + /* 0xC0*/ + uint32_t UART_FD; + /* 0xC4*/ + uint32_t UART_RAR; + /* 0xC8*/ + uint32_t UART_TAR; + /* 0xCC*/ + uint32_t UART_LCR_EXT; + uint8_t zResverd0x0D0[48]; /*pad 0x0D0 - 0FF*/ + + /* 0x100*/ + uint32_t UART_LIN_CTL; + /* 0x104*/ + uint32_t UART_LIN_RSP_LENGTH; + /* 0x108*/ + uint32_t UART_LIN_PID_VALUE; + /* 0x10C*/ + uint32_t UART_LIN_CHECKSUM; + /* 0x110*/ + uint32_t UART_LIN_DEL_LENGTH; + + uint8_t zResverd0x114[24]; /* pad 0x114 - 12B */ + +}; /*uart_reg*/ + +typedef volatile struct uart_reg uart_reg_t; +typedef volatile struct uart_reg_w uart_reg_w_t; + +struct wdog_reg { + /* 0x0*/ + struct { + uint32_t MINOR : 4; /* [3:0] ro */ + uint32_t MAJOR : 4; /* [7:4] ro */ + uint32_t RSVD_31_8 :24; /* [31:8] ro */ + } WDOG_VERID; + + /* 0x4*/ + struct { + uint32_t INT_PRESENT : 1; /* [0] ro */ + uint32_t RSVD_31_1 :31; /* [31:1] ro */ + } WDOG_PARAM; + + /* 0x8*/ + struct { + uint32_t WDOGE : 1; /* [0] r/w */ + uint32_t DEBUGE : 1; /* [1] r/w */ + uint32_t WAITE : 1; /* [2] r/w */ + uint32_t STOPE : 1; /* [3] r/w */ + uint32_t INTE : 1; /* [4] r/w */ + uint32_t WINE : 1; /* [5] r/w */ + uint32_t CFGUA : 1; /* [6] r/w */ + uint32_t RSVD_7 : 1; /* [7] ro */ + uint32_t CLKS : 2; /* [9:8] r/w */ + uint32_t RSVD_15_10 : 6; /* [15:10] ro */ + uint32_t TSTM : 3; /* [18:16] r/w */ + uint32_t RSVD_23_19 : 5; /* [23:19] ro */ + uint32_t CFGUF : 1; /* [24] ro */ + uint32_t UNLKF : 1; /* [25] ro */ + uint32_t INTF : 1; /* [26] r/w */ + uint32_t RSVD_31_27 : 5; /* [31:27] ro */ + } WDOG_CS; + + /* 0xC*/ + struct { + uint32_t TMO :32; /* [31:0] r/w */ + } WDOG_TMO; + + /* 0x10*/ + struct { + uint32_t WIN :32; /* [31:0] r/w */ + } WDOG_WIN; + + /* 0x14*/ + struct { + uint32_t CNT :32; /* [31:0] r/w */ + } WDOG_CNT; + +}; /*wdog_reg*/ + +struct wdog_reg_w { + /* 0x0*/ + uint32_t WDOG_VERID; + /* 0x4*/ + uint32_t WDOG_PARAM; + /* 0x8*/ + uint32_t WDOG_CS; + /* 0xC*/ + uint32_t WDOG_TMO; + /* 0x10*/ + uint32_t WDOG_WIN; + /* 0x14*/ + uint32_t WDOG_CNT; +}; /*wdog_reg*/ + +typedef volatile struct wdog_reg wdog_reg_t; +typedef volatile struct wdog_reg_w wdog_reg_w_t; +#endif /*Z20K116M_H*/ diff --git a/Platform/Devices/Z20K116M/MakeRule/ARMC/Z20K116M_flash.scf b/Platform/Devices/Z20K116M/MakeRule/ARMC/Z20K116M_flash.scf new file mode 100644 index 0000000..97418f6 --- /dev/null +++ b/Platform/Devices/Z20K116M/MakeRule/ARMC/Z20K116M_flash.scf @@ -0,0 +1,30 @@ +#! armclang --target=arm-arm-none-eabi -mcpu=cortex-m0plus -xc -E +; ************************************************************* +; *** Scatter-Loading Description File *** +; ************************************************************* + +#define pflash_start 0x00000000 +#define pflash_size 0x00020000 /* 128KB */ + +#define dflash_start 0x01000000 +#define dflash_size 0x00020000 /* 128KB */ + +#define ram0_start 0x20000000 +#define ram0_size 0x00004000 /* 16KB */ +#define ram0_end ram0_start + ram0_size + +LR_IROM1 pflash_start pflash_size { ; load region size_region + ER_IROM1 pflash_start pflash_size { ; load address = execution address + *.o (.intvec, +First) + *(InRoot$$Sections) + .ANY (+RO) + } + + RAM_START ram0_start ram0_size { ; code execution in ram + .ANY (.code_ram) + .ANY (+RW +ZI) + } + + ARM_LIB_STACK ram0_end EMPTY -0x400 {}; Stack region growing down + ARM_LIB_HEAP ImageBase(ARM_LIB_STACK) EMPTY -0x200 {} ; heap region +} diff --git a/Platform/Devices/Z20K116M/MakeRule/ARMC/Z20K116M_sram.scf b/Platform/Devices/Z20K116M/MakeRule/ARMC/Z20K116M_sram.scf new file mode 100644 index 0000000..64b8b33 --- /dev/null +++ b/Platform/Devices/Z20K116M/MakeRule/ARMC/Z20K116M_sram.scf @@ -0,0 +1,20 @@ +#! armclang --target=arm-arm-none-eabi -mcpu=cortex-m0plus -xc -E +; ************************************************************* +; *** Scatter-Loading Description File *** +; ************************************************************* + +#define ram0_start 0x20000000 +#define ram0_size 0x00004000 /* 16KB */ +#define ram0_end ram0_start + ram0_size + +LR_IROM1 ram0_start ram0_size { ; load region size_region + RAM_START ram0_start ram0_size { ; load address = execution address + *.o (.intvec, +First) + *(InRoot$$Sections) + .ANY (+RO +RW +ZI) + } + + ARM_LIB_STACK ram0_end EMPTY -0x400 {}; Stack region growing down + ARM_LIB_HEAP ImageBase(ARM_LIB_STACK) EMPTY -0x200 {} ; heap region +} + diff --git a/Platform/Devices/Z20K116M/MakeRule/GCC/Z20K116M_flash.ld b/Platform/Devices/Z20K116M/MakeRule/GCC/Z20K116M_flash.ld new file mode 100644 index 0000000..01afe21 --- /dev/null +++ b/Platform/Devices/Z20K116M/MakeRule/GCC/Z20K116M_flash.ld @@ -0,0 +1,100 @@ +VECTOR_BASE = 0x00000000; + +HEAP_SIZE = DEFINED(__heap_size__) ? __heap_size__ : 0x00000200; +CSTACK_SIZE = DEFINED(__stack_size__) ? __stack_size__ : 0x00000400; + +MEMORY +{ + FLASH (xr) : ORIGIN = 0x00000000, LENGTH = 0x00020000 + RAM1 (xrw) : ORIGIN = 0x20000000, LENGTH = 0x00004000 + +} + +/* Entry Point */ +ENTRY(Reset_Handler) + + +/* Sections Definitions */ + +SECTIONS +{ + .isr_vector : + { + . = ALIGN(4); + KEEP(*(.intvec)) /* Startup code */ + . = ALIGN(4); + } > FLASH + + .rom : ALIGN(4) + { + . = ALIGN(4); + *(.text) /* .text sections (code) */ + *(.text*) /* .text* sections (code) */ + *(.rodata) /* .rodata sections (constants, strings, etc.) */ + *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ + *(.glue_7) /* glue arm to thumb code */ + *(.glue_7t) /* glue thumb to arm code */ + *(.eh_frame) + KEEP (*(.init)) + KEEP (*(.fini)) + . = ALIGN(4); + } > FLASH + + __TEXT_END = .; /* global symbol at end of code */ + __DATA_ROM = .; /* Symbol used for startup for data initialization */ + + .data : AT(__DATA_ROM) + { + . = ALIGN(4); + __DATA_RAM = .; + __data_start__ = .; /* create a global symbol at data start */ + *(.data) /* .data sections */ + *(.data*) /* .data* sections */ + *(.code_ram) /*Custom section for storing code in SRAM*/ + KEEP(*(.jcr*)) + . = ALIGN(4); + __data_end__ = .; /* define a global symbol at data end */ + } > RAM1 + + __DATA_END = __DATA_ROM + SIZEOF(.data); + + .bss : + { + /* This is used by the startup in order to initialize the .bss section */ + . = ALIGN(4); + __START_BSS = .; + __bss_start__ = .; + *(.bss) + *(.bss*) + *(COMMON) + . = ALIGN(4); + __bss_end__ = .; + __END_BSS = .; + } > RAM1 + + .heap : + { + . = ALIGN(8); + __end__ = .; + PROVIDE(end = .); + __HeapBase = .; + . += HEAP_SIZE; + __HeapLimit = .; + } > RAM1 + + /* Initializes stack on the end of block */ + __StackTop = ORIGIN(RAM1) + LENGTH(RAM1); + __StackLimit = __StackTop - CSTACK_SIZE; + PROVIDE(CSTACK = __StackTop); + + .stack __StackLimit : + { + . = ALIGN(8); + __stack_start__ = .; + . += CSTACK_SIZE; + __stack_end__ = .; + } > RAM1 + + __RAM_START = ORIGIN(RAM1); + __RAM_END = __StackTop - 1; +} diff --git a/Platform/Devices/Z20K116M/MakeRule/GCC/Z20K116M_sram.ld b/Platform/Devices/Z20K116M/MakeRule/GCC/Z20K116M_sram.ld new file mode 100644 index 0000000..59db6ff --- /dev/null +++ b/Platform/Devices/Z20K116M/MakeRule/GCC/Z20K116M_sram.ld @@ -0,0 +1,100 @@ +VECTOR_BASE = 0x20000000; + +HEAP_SIZE = DEFINED(__heap_size__) ? __heap_size__ : 0x00000200; +CSTACK_SIZE = DEFINED(__stack_size__) ? __stack_size__ : 0x00000400; + +MEMORY +{ + RAM1 (xrw) : ORIGIN = 0x20000000, LENGTH = 0x00004000 +} + +/* Entry Point */ +ENTRY(Reset_Handler) + + +/* Sections Definitions */ + +SECTIONS +{ + + /* The startup code goes first into internal RAM */ + .isr_vector : + { + . = ALIGN(4); + KEEP(*(.intvec)) /* Startup code */ + . = ALIGN(4); + } > RAM1 + + + .rom : ALIGN(4) + { + . = ALIGN(4); + *(.text) /* .text sections (code) */ + *(.text*) /* .text* sections (code) */ + *(.rodata) /* .rodata sections (constants, strings, etc.) */ + *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ + *(.glue_7) /* glue arm to thumb code */ + *(.glue_7t) /* glue thumb to arm code */ + *(.eh_frame) + KEEP (*(.init)) + KEEP (*(.fini)) + . = ALIGN(4); + } > RAM1 + + __TEXT_END = .; /* global symbol at end of code */ + __DATA_ROM = .; /* Symbol used for startup for data initialization */ + + + .data : AT(__DATA_ROM) + { + . = ALIGN(4); + __DATA_RAM = .; + __data_start__ = .; /* create a global symbol at data start */ + *(.data) /* .data sections */ + *(.data*) /* .data* sections */ + KEEP(*(.jcr*)) + . = ALIGN(4); + __data_end__ = .; /* define a global symbol at data end */ + } > RAM1 + + __DATA_END = __DATA_ROM + SIZEOF(.data); + + .bss : + { + /* This is used by the startup in order to initialize the .bss section */ + . = ALIGN(4); + __START_BSS = .; + __bss_start__ = .; + *(.bss) + *(.bss*) + *(COMMON) + . = ALIGN(4); + __bss_end__ = .; + __END_BSS = .; + } > RAM1 + + .heap : + { + . = ALIGN(8); + __end__ = .; + PROVIDE(end = .); + __HeapBase = .; + . += HEAP_SIZE; + __HeapLimit = .; + __heap_limit = .; + } > RAM1 + + /* Initializes stack on the end of block */ + __StackTop = ORIGIN(RAM1) + LENGTH(RAM1); + __StackLimit = __StackTop - CSTACK_SIZE; + PROVIDE(CSTACK = __StackTop); + + .stack __StackLimit : + { + . = ALIGN(8); + . += CSTACK_SIZE; + } > RAM1 + + __RAM_START = ORIGIN(RAM1); + __RAM_END = __StackTop - 1; +} diff --git a/Platform/Devices/Z20K116M/MakeRule/IAR/Z20K116M_flash.icf b/Platform/Devices/Z20K116M/MakeRule/IAR/Z20K116M_flash.icf new file mode 100644 index 0000000..1b518f9 --- /dev/null +++ b/Platform/Devices/Z20K116M/MakeRule/IAR/Z20K116M_flash.icf @@ -0,0 +1,47 @@ +/*###ICF### Section handled by ICF editor, don't touch! ****/ +/*-Editor annotation file-*/ +/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */ +/*-Specials-*/ +define symbol __ICFEDIT_intvec_start__ = 0x00000000; +/*-Memory Regions-*/ +define symbol __ICFEDIT_region_ROM_start__ = 0x00000000; +define symbol __ICFEDIT_region_ROM_end__ = 0x0001FFFF; /* 128KB */ + +define symbol DFLASH_BASE = 0x01000000; +define symbol DFLASH_SIZE = 0x00020000; /* 128KB */ + +define symbol __ICFEDIT_region_RAM_start__ = 0x20000000; +define symbol __ICFEDIT_region_RAM_end__ = 0x20003FFF; /* 16KB */ + +define symbol __ICFEDIT_size_cstack__ = 0x00000400; +define symbol __ICFEDIT_size_heap__ = 0x00000200; + +/**** End of ICF editor section. ###ICF###*/ + +define exported symbol __RAM_START = __ICFEDIT_region_RAM_start__; +define exported symbol __RAM_END = __ICFEDIT_region_RAM_end__; + +/* memory range */ +define memory mem with size = 4G; + +define region PFLASH_region = mem:[from __ICFEDIT_region_ROM_start__ to __ICFEDIT_region_ROM_end__]; +define region DFLASH_region = mem:[from DFLASH_BASE size DFLASH_SIZE]; +define region RAM1_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFEDIT_region_RAM_end__]; + +/* definition of RAM blocks */ +define block CSTACK with size = __ICFEDIT_size_cstack__, alignment = 8 { }; +define block HEAP with size = __ICFEDIT_size_heap__, alignment = 8 { }; + +initialize by copy { readwrite }; +do not initialize { section .noinit }; + +place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec }; + +place in PFLASH_region { readonly }; + +place in RAM1_region { section .textrw}; + +place at end of RAM1_region { block HEAP, + block CSTACK }; + +place in RAM1_region { readwrite }; diff --git a/Platform/Devices/Z20K116M/MakeRule/IAR/Z20K116M_sram.icf b/Platform/Devices/Z20K116M/MakeRule/IAR/Z20K116M_sram.icf new file mode 100644 index 0000000..bb31146 --- /dev/null +++ b/Platform/Devices/Z20K116M/MakeRule/IAR/Z20K116M_sram.icf @@ -0,0 +1,39 @@ +/*###ICF### Section handled by ICF editor, don't touch! ****/ +/*-Editor annotation file-*/ +/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */ +/*-Specials-*/ +define symbol __ICFEDIT_intvec_start__ = 0x20000000; + +define symbol __ICFEDIT_region_RAM_start__ = 0x20000000; +define symbol __ICFEDIT_region_RAM_end__ = 0x20003FFF; /* 16KB */ + +define symbol __ICFEDIT_size_cstack__ = 0x00000400; +define symbol __ICFEDIT_size_heap__ = 0x00000200; + +/**** End of ICF editor section. ###ICF###*/ + +define exported symbol __RAM_START = __ICFEDIT_region_RAM_start__; +define exported symbol __RAM_END = __ICFEDIT_region_RAM_end__; + +/* memory range */ +define memory mem with size = 4G; + +define region RAM1_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFEDIT_region_RAM_end__]; + +/* definition of RAM blocks */ +define block CSTACK with size = __ICFEDIT_size_cstack__, alignment = 8 { }; +define block HEAP with size = __ICFEDIT_size_heap__, alignment = 8 { }; + +initialize by copy { readwrite }; +do not initialize { section .noinit }; + +place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec }; + +place in RAM1_region { readonly }; + +place in RAM1_region { section .textrw}; + +place at end of RAM1_region { block HEAP, + block CSTACK }; + +place in RAM1_region { readwrite }; diff --git a/Platform/Devices/Z20K116M/Startup/ARMC/Z20K116M_startup.s b/Platform/Devices/Z20K116M/Startup/ARMC/Z20K116M_startup.s new file mode 100644 index 0000000..afe54eb --- /dev/null +++ b/Platform/Devices/Z20K116M/Startup/ARMC/Z20K116M_startup.s @@ -0,0 +1,428 @@ +; --------------------------------------------------------------------------- +; @file: : Z20K116M_startup.s +; @brief: : Z20K116M startup and Vector Table Source File for ARM Compiler +; @version : V1.8.0 +; @date : May-2020 +; @author : Zhixin Semiconductor +; +; @note +; @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. +; --------------------------------------------------------------------------- + + + PRESERVE8 + THUMB + + + AREA |.text|, CODE, READONLY + EXPORT __vector_table + EXPORT __Vectors_End + EXPORT __Vectors_Size + + IMPORT __main + + IMPORT |Image$$ARM_LIB_STACK$$ZI$$Limit| + + + IF :LNOT: :DEF:START_FROM_SRAM + IMPORT |Image$$RAM_START$$Base| +__RAM_START DCD |Image$$RAM_START$$Base| +__RAM_END DCD |Image$$ARM_LIB_STACK$$ZI$$Limit| + ENDIF + + + AREA |.intvec|, DATA, READONLY +__vector_table + DCD |Image$$ARM_LIB_STACK$$ZI$$Limit| ; Top of Stack + DCD Reset_Handler ; POR Reset Entry + DCD NMI_Handler ; Non Maskable handler + DCD HardFault_Handler ; SV Hard Fault handler + DCD 0 + DCD 0 + DCD 0 + DCD 0 + DCD 0 + DCD 0 + DCD 0 + DCD SVC_Handler ; SV Call handler + DCD 0 + DCD 0 + DCD PendSV_Handler ; Pend SV handler + DCD SysTick_Handler ; System Tick handler + + + DCD DMA0TO3_IRQHandler ; irq 0 : DMA channel 0 - 3 transfer complete IRQHandler + DCD DMA4TO7_IRQHandler ; irq 1 : DMA channel 4 - 7 transfer complete IRQHandler + DCD DMA8TO11_IRQHandler ; irq 2 : DMA channel 8 - 11 transfer complete IRQHandler + DCD DMA12TO15_IRQHandler ; irq 3 : DMA channel 12 - 15 transfer complete IRQHandler + DCD DMAERR_IRQHandler ; irq 4 : DMA error interrupt channels 0-7 IRQHandler + DCD I2C0_IRQHandler ; irq 5 : I2C 0 IRQHandler + DCD Reserved6_IRQHandler ; irq 6 : Reserved Interrupt + DCD SPI0_IRQHandler ; irq 7 : SPI 0 IRQHandler + DCD SPI1_IRQHandler ; irq 8 : SPI 1 IRQHandler + DCD Reserved9_IRQHandler ; irq 9 : Reserved Interrupt + DCD UART0_IRQHandler ; irq 10 : UART 0 IRQHandler + DCD UART1_IRQHandler ; irq 11 : UART 1 IRQHandler + DCD UART2_IRQHandler ; irq 12 : UART2 IRQHandler + DCD Reserved13_IRQHandler ; irq 13 : Reserved Interrupt + DCD ADC0_IRQHandler ; irq 14 : ADC0 IRQHandler + DCD FLASH_IRQHandler ; irq 15 : flash memory IRQHandler + DCD CMP_IRQHandler ; irq 16 : CMP IRQHandler + DCD TIM0_IRQHandler ; irq 17 : TIM 0 IRQHandler + DCD TIM1_IRQHandler ; irq 18 : TIM 1 IRQHandler + DCD TIM2_IRQHandler ; irq 19 : TIM 2 IRQHandler + DCD CAN0_IRQHandler ; irq 20 : CAN 0 IRQHandler + DCD Reserved21_IRQHandler ; irq 21 : Reserved Interrupt + DCD RTC_IRQHandler ; irq 22 : RTC IRQHandler + DCD PMU_IRQHandler ; irq 23 : PMU IRQHandler + DCD TDG0_IRQHandler ; irq 24 : TDG0 IRQHandler + DCD SCC_IRQHandler ; irq 25 : system clock controller IRQHandler + DCD WDOG_IRQHandler ; irq 26 : watchdog IRQHandler + DCD EWDT_IRQHandler ; irq 27 : external watchdog monitor IRQHandler + DCD STIM_IRQHandler ; irq 28 : STIM IRQHandler + DCD SRMC_IRQHandler ; irq 29 : system reset and mode control IRQHandler + DCD PORTABC_IRQHandler ; irq 30 : port A B C IRQHandler + DCD PORTDE_IRQHandler ; irq 31 : port D E IRQHandler +__Vectors_End + +__Vectors_Size EQU __Vectors_End - __vector_table + + + AREA |.text|, CODE, READONLY + +Reset_Handler PROC + ALIGN 4 + EXPORT Reset_Handler [WEAK] + + CPSID I ; Mask interrupts + + IF :LNOT: :DEF:START_FROM_SRAM + ; Init ECC RAM + LDR R1, =__RAM_START + LDR R1, [R1] + LDR R2, =__RAM_END + LDR R2, [R2] + SUBS R2, R1 + SUBS R2, #1 + BLE LC2 + + MOVS R0, #0 + MOVS R3, #4 +LC1 + STR R0, [R1] + ADD R1, R1, R3 + SUBS R2, #4 + BGE LC1 +LC2 + NOP + ENDIF + + LDR R0, =0xE000ED08 + LDR R1, =__vector_table + STR R1, [R0] + LDR R2, [R1] + MSR MSP, R2 + CPSIE i ; Unmask interrupts + LDR R0, =__main + BLX R0 + ENDP + +NMI_Handler\ + PROC + EXPORT NMI_Handler [WEAK] + B . + ENDP + +HardFault_Handler\ + PROC + EXPORT HardFault_Handler [WEAK] + B . + ENDP + +SVC_Handler\ + PROC + EXPORT SVC_Handler [WEAK] + B . + ENDP + +PendSV_Handler\ + PROC + EXPORT PendSV_Handler [WEAK] + B . + ENDP + +SysTick_Handler\ + PROC + EXPORT SysTick_Handler [WEAK] + B . + ENDP + +DMA0TO3_IRQHandler\ + PROC + EXPORT DMA0TO3_IRQHandler [WEAK] + LDR R0, =DMA0TO3_DriverIRQHandler + BX R0 + ENDP + +DMA4TO7_IRQHandler\ + PROC + EXPORT DMA4TO7_IRQHandler [WEAK] + LDR R0, =DMA4TO7_DriverIRQHandler + BX R0 + ENDP + +DMA8TO11_IRQHandler\ + PROC + EXPORT DMA8TO11_IRQHandler [WEAK] + LDR R0, =DMA8TO11_DriverIRQHandler + BX R0 + ENDP + +DMA12TO15_IRQHandler\ + PROC + EXPORT DMA12TO15_IRQHandler [WEAK] + LDR R0, =DMA12TO15_DriverIRQHandler + BX R0 + ENDP + +DMAERR_IRQHandler\ + PROC + EXPORT DMAERR_IRQHandler [WEAK] + LDR R0, =DMAERR_DriverIRQHandler + BX R0 + ENDP + +I2C0_IRQHandler\ + PROC + EXPORT I2C0_IRQHandler [WEAK] + LDR R0, =I2C0_DriverIRQHandler + BX R0 + ENDP + +SPI0_IRQHandler\ + PROC + EXPORT SPI0_IRQHandler [WEAK] + LDR R0, =SPI0_DriverIRQHandler + BX R0 + ENDP + +SPI1_IRQHandler\ + PROC + EXPORT SPI1_IRQHandler [WEAK] + LDR R0, =SPI1_DriverIRQHandler + BX R0 + ENDP + +UART0_IRQHandler\ + PROC + EXPORT UART0_IRQHandler [WEAK] + LDR R0, =UART0_DriverIRQHandler + BX R0 + ENDP + +UART1_IRQHandler\ + PROC + EXPORT UART1_IRQHandler [WEAK] + LDR R0, =UART1_DriverIRQHandler + BX R0 + ENDP + +UART2_IRQHandler\ + PROC + EXPORT UART2_IRQHandler [WEAK] + LDR R0, =UART2_DriverIRQHandler + BX R0 + ENDP + +ADC0_IRQHandler\ + PROC + EXPORT ADC0_IRQHandler [WEAK] + LDR R0, =ADC0_DriverIRQHandler + BX R0 + ENDP + +FLASH_IRQHandler\ + PROC + EXPORT FLASH_IRQHandler [WEAK] + LDR R0, =FLASH_DriverIRQHandler + BX R0 + ENDP + +CMP_IRQHandler\ + PROC + EXPORT CMP_IRQHandler [WEAK] + LDR R0, =CMP_DriverIRQHandler + BX R0 + ENDP + +TIM0_IRQHandler\ + PROC + EXPORT TIM0_IRQHandler [WEAK] + LDR R0, =TIM0_DriverIRQHandler + BX R0 + ENDP + +TIM1_IRQHandler\ + PROC + EXPORT TIM1_IRQHandler [WEAK] + LDR R0, =TIM1_DriverIRQHandler + BX R0 + ENDP + +TIM2_IRQHandler\ + PROC + EXPORT TIM2_IRQHandler [WEAK] + LDR R0, =TIM2_DriverIRQHandler + BX R0 + ENDP + +CAN0_IRQHandler\ + PROC + EXPORT CAN0_IRQHandler [WEAK] + LDR R0, =CAN0_DriverIRQHandler + BX R0 + ENDP + +RTC_IRQHandler\ + PROC + EXPORT RTC_IRQHandler [WEAK] + LDR R0, =RTC_DriverIRQHandler + BX R0 + ENDP + +PMU_IRQHandler\ + PROC + EXPORT PMU_IRQHandler [WEAK] + LDR R0, =PMU_DriverIRQHandler + BX R0 + ENDP + +TDG0_IRQHandler\ + PROC + EXPORT TDG0_IRQHandler [WEAK] + LDR R0, =TDG0_DriverIRQHandler + BX R0 + ENDP + +SCC_IRQHandler\ + PROC + EXPORT SCC_IRQHandler [WEAK] + LDR R0, =SCC_DriverIRQHandler + BX R0 + ENDP + +WDOG_IRQHandler\ + PROC + EXPORT WDOG_IRQHandler [WEAK] + LDR R0, =WDOG_DriverIRQHandler + BX R0 + ENDP + +EWDT_IRQHandler\ + PROC + EXPORT EWDT_IRQHandler [WEAK] + LDR R0, =EWDT_DriverIRQHandler + BX R0 + ENDP + +STIM_IRQHandler\ + PROC + EXPORT STIM_IRQHandler [WEAK] + LDR R0, =STIM_DriverIRQHandler + BX R0 + ENDP + +SRMC_IRQHandler\ + PROC + EXPORT SRMC_IRQHandler [WEAK] + LDR R0, =SRMC_DriverIRQHandler + BX R0 + ENDP + +PORTABC_IRQHandler\ + PROC + EXPORT PORTABC_IRQHandler [WEAK] + LDR R0, =PORTABC_DriverIRQHandler + BX R0 + ENDP + +PORTDE_IRQHandler\ + PROC + EXPORT PORTDE_IRQHandler [WEAK] + LDR R0, =PORTDE_DriverIRQHandler + BX R0 + ENDP + +Default_Handler PROC + EXPORT DMA0TO3_DriverIRQHandler [WEAK] + EXPORT DMA4TO7_DriverIRQHandler [WEAK] + EXPORT DMA8TO11_DriverIRQHandler [WEAK] + EXPORT DMA12TO15_DriverIRQHandler [WEAK] + EXPORT DMAERR_DriverIRQHandler [WEAK] + EXPORT I2C0_DriverIRQHandler [WEAK] + EXPORT Reserved6_IRQHandler [WEAK] + EXPORT SPI0_DriverIRQHandler [WEAK] + EXPORT SPI1_DriverIRQHandler [WEAK] + EXPORT Reserved9_IRQHandler [WEAK] + EXPORT UART0_DriverIRQHandler [WEAK] + EXPORT UART1_DriverIRQHandler [WEAK] + EXPORT UART2_DriverIRQHandler [WEAK] + EXPORT Reserved13_IRQHandler [WEAK] + EXPORT ADC0_DriverIRQHandler [WEAK] + EXPORT FLASH_DriverIRQHandler [WEAK] + EXPORT CMP_DriverIRQHandler [WEAK] + EXPORT TIM0_DriverIRQHandler [WEAK] + EXPORT TIM1_DriverIRQHandler [WEAK] + EXPORT TIM2_DriverIRQHandler [WEAK] + EXPORT CAN0_DriverIRQHandler [WEAK] + EXPORT Reserved21_IRQHandler [WEAK] + EXPORT RTC_DriverIRQHandler [WEAK] + EXPORT PMU_DriverIRQHandler [WEAK] + EXPORT TDG0_DriverIRQHandler [WEAK] + EXPORT SCC_DriverIRQHandler [WEAK] + EXPORT WDOG_DriverIRQHandler [WEAK] + EXPORT EWDT_DriverIRQHandler [WEAK] + EXPORT STIM_DriverIRQHandler [WEAK] + EXPORT SRMC_DriverIRQHandler [WEAK] + EXPORT PORTABC_DriverIRQHandler [WEAK] + EXPORT PORTDE_DriverIRQHandler [WEAK] + +DMA0TO3_DriverIRQHandler +DMA4TO7_DriverIRQHandler +DMA8TO11_DriverIRQHandler +DMA12TO15_DriverIRQHandler +DMAERR_DriverIRQHandler +I2C0_DriverIRQHandler +Reserved6_IRQHandler +SPI0_DriverIRQHandler +SPI1_DriverIRQHandler +Reserved9_IRQHandler +UART0_DriverIRQHandler +UART1_DriverIRQHandler +UART2_DriverIRQHandler +Reserved13_IRQHandler +ADC0_DriverIRQHandler +FLASH_DriverIRQHandler +CMP_DriverIRQHandler +TIM0_DriverIRQHandler +TIM1_DriverIRQHandler +TIM2_DriverIRQHandler +CAN0_DriverIRQHandler +Reserved21_IRQHandler +RTC_DriverIRQHandler +PMU_DriverIRQHandler +TDG0_DriverIRQHandler +SCC_DriverIRQHandler +WDOG_DriverIRQHandler +EWDT_DriverIRQHandler +STIM_DriverIRQHandler +SRMC_DriverIRQHandler +PORTABC_DriverIRQHandler +PORTDE_DriverIRQHandler + + B . + + ENDP + + ALIGN + END \ No newline at end of file diff --git a/Platform/Devices/Z20K116M/Startup/GCC/Z20K116M_startup.S b/Platform/Devices/Z20K116M/Startup/GCC/Z20K116M_startup.S new file mode 100644 index 0000000..6adfa16 --- /dev/null +++ b/Platform/Devices/Z20K116M/Startup/GCC/Z20K116M_startup.S @@ -0,0 +1,518 @@ +/****************************************************************************************/ +/* @file : Z20K116M_startup.s */ +/* @brief : Z20K116M Device Vector Table Source File. */ +/* @version : V1.8.0 */ +/* @date : May-2020 */ +/* @author : Zhixin Semiconductor */ +/* */ +/* @note */ +/* @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. */ +/****************************************************************************************/ + .syntax unified + .arch armv6-m + + .section .isr_vector, "a" + .align 2 + .globl __isr_vector +__isr_vector: + .long __StackTop /* Stack */ + .long Reset_Handler /*!< POR Reset Entry */ + .long NMI_Handler /*!< NMI handler */ + .long HardFault_Handler /*!< Hard Fault Handler */ + .long 0 + .long 0 + .long 0 + .long 0 + .long 0 + .long 0 + .long 0 /*!< Reserved 7 Handler */ + .long SVC_Handler /*!< SVC Handler */ + .long 0 + .long 0 /*!< Reserved 2 Handler */ + .long PendSV_Handler /*!< PendSV Handler */ + .long SysTick_Handler /*!< SysTick Handler */ + + /* Zhixin specific interrupt */ + .long DMA0TO3_IRQHandler /*!< irq 0 : DMA channel 0 - 3 transfer complete ISR */ + .long DMA4TO7_IRQHandler /*!< irq 1 : DMA channel 4 - 7 transfer complete ISR */ + .long DMA8TO11_IRQHandler /*!< irq 2 : DMA channel 8 - 11 transfer complete ISR */ + .long DMA12TO15_IRQHandler /*!< irq 3 : DMA channel 12 - 15 transfer complete ISR */ + .long DMAERR_IRQHandler /*!< irq 4 : DMA error interrupt channels 0-7 ISR */ + .long I2C0_IRQHandler /*!< irq 5 : I2C 0 ISR */ + .long Reserved6_IRQHandler /*!< irq 6 : Reserved Interrupt */ + .long SPI0_IRQHandler /*!< irq 7 : SPI 0 ISR */ + .long SPI1_IRQHandler /*!< irq 8 : SPI 1 ISR */ + .long Reserved9_IRQHandler /*!< irq 9 : Reserved Interrupt */ + .long UART0_IRQHandler /*!< irq 10 : UART 0 ISR */ + .long UART1_IRQHandler /*!< irq 11 : UART 1 ISR */ + .long UART2_IRQHandler /*!< irq 12 : UART2 ISR */ + .long Reserved13_IRQHandler /*!< irq 13 : Reserved Interrupt */ + .long ADC0_IRQHandler /*!< irq 14 : ADC0 ISR */ + .long FLASH_IRQHandler /*!< irq 15 : flash memory ISR */ + .long CMP_IRQHandler /*!< irq 16 : CMP ISR */ + .long TIM0_IRQHandler /*!< irq 17 : TIM 0 ISR */ + .long TIM1_IRQHandler /*!< irq 18 : TIM 1 ISR */ + .long TIM2_IRQHandler /*!< irq 19 : TIM 2 ISR */ + .long CAN0_IRQHandler /*!< irq 20 : CAN 0 ISR */ + .long Reserved21_IRQHandler /*!< irq 21 : Reserved Interrupt */ + .long RTC_IRQHandler /*!< irq 22 : RTC ISR */ + .long PMU_IRQHandler /*!< irq 23 : PMU ISR */ + .long TDG0_IRQHandler /*!< irq 24 : TDG0 ISR */ + .long SCC_IRQHandler /*!< irq 25 : system clock controller ISR */ + .long WDOG_IRQHandler /*!< irq 26 : watchdog ISR */ + .long EWDT_IRQHandler /*!< irq 27 : external watchdog monitor ISR */ + .long STIM_IRQHandler /*!< irq 28 : STIM ISR */ + .long SRMC_IRQHandler /*!< irq 29 : system reset and mode control ISR */ + .long PORTABC_IRQHandler /*!< irq 30 : port A B C ISR */ + .long PORTDE_IRQHandler /*!< irq 31 : port D E ISR */ + + .size __isr_vector, . - __isr_vector + + .text + .thumb + +/* Reset_Handler Entry */ + .thumb_func + .align 2 + .globl Reset_Handler + .weak Reset_Handler + .type Reset_Handler, %function +Reset_Handler: + cpsid i /* Mask interrupts */ + .equ VTOR, 0xE000ED08 + ldr r0, =VTOR + ldr r1, =__isr_vector + str r1, [r0] + ldr r2, [r1] + msr msp, r2 + +#ifndef START_FROM_SRAM + /* Clean SRAM ECC */ + ldr r1, =__RAM_START + ldr r2, =__RAM_END + + subs r2, r1 + subs r2, #1 + ble .LB2 + + movs r0, 0 + movs r3, #4 +.LB1: + str r0, [r1] + add r1, r1, r3 + subs r2, 4 + bge .LB1 +.LB2: +#endif + + + ldr r1, =__DATA_ROM + ldr r2, =__data_start__ + ldr r3, =__data_end__ + +/* Copy data from flash to SRAM.*/ +.DATA_LOOP: + cmp r2, r3 + bge .DATA_LOOP_DONE + ldr r0, [r1] + adds r1, #4 + str r0, [r2] + adds r2, #4 + b .DATA_LOOP + +.DATA_LOOP_DONE: +/* Copy bss from flash to SRAM.*/ + ldr r1, =__bss_start__ + ldr r2, =__bss_end__ + + movs r0, 0 +.BSS_LOOP: + cmp r1, r2 + bge .BSS_LOOP_DONE + str r0, [r1] + adds r1, #4 + b .BSS_LOOP + +.BSS_LOOP_DONE: + cpsie i /* Unmask interrupts */ + + ldr r0,=main + bx r0 + + .pool + .size Reset_Handler, . - Reset_Handler + + .align 1 + .thumb_func + .weak JumpToSelf + .type JumpToSelf, %function +JumpToSelf: + b JumpToSelf + .size JumpToSelf, . - JumpToSelf + + .align 1 + .thumb_func + .weak NMI_Handler + .type NMI_Handler, %function +NMI_Handler: + b . + .size NMI_Handler, . - NMI_Handler + + .align 1 + .thumb_func + .weak HardFault_Handler + .type HardFault_Handler, %function +HardFault_Handler: + b . + .size HardFault_Handler, . - HardFault_Handler + + .align 1 + .thumb_func + .weak HardFault_Handler + .type HardFault_Handler, %function +MemManageFault_Handler: + b . + .size MemManageFault_Handler, . - MemManageFault_Handler + + .align 1 + .thumb_func + .weak HardFault_Handler + .type HardFault_Handler, %function +BusFault_Handler: + b . + .size BusFault_Handler, . - BusFault_Handler + + .align 1 + .thumb_func + .weak HardFault_Handler + .type HardFault_Handler, %function +UsageFault_Handler: + b . + .size UsageFault_Handler, . - UsageFault_Handler + + .align 1 + .thumb_func + .weak SVC_Handler + .type SVC_Handler, %function +SVC_Handler: + b . + .size SVC_Handler, . - SVC_Handler + + .align 1 + .thumb_func + .weak SVC_Handler + .type SVC_Handler, %function +DebugMonitor_Handler: + b . + .size DebugMonitor_Handler, . - DebugMonitor_Handler + + .align 1 + .thumb_func + .weak PendSV_Handler + .type PendSV_Handler, %function +PendSV_Handler: + b . + .size PendSV_Handler, . - PendSV_Handler + + .align 1 + .thumb_func + .weak SysTick_Handler + .type SysTick_Handler, %function +SysTick_Handler: + b . + .size SysTick_Handler, . - SysTick_Handler + + .align 1 + .thumb_func + .weak DMA0TO3_IRQHandler + .type DMA0TO3_IRQHandler, %function +DMA0TO3_IRQHandler: + ldr r0,=DMA0TO3_DriverIRQHandler + bx r0 + .size DMA0TO3_IRQHandler, . - DMA0TO3_IRQHandler + + .align 1 + .thumb_func + .weak DMA4TO7_IRQHandler + .type DMA4TO7_IRQHandler, %function +DMA4TO7_IRQHandler: + ldr r0,=DMA4TO7_DriverIRQHandler + bx r0 + .size DMA4TO7_IRQHandler, . - DMA4TO7_IRQHandler + + .align 1 + .thumb_func + .weak DMA8TO11_IRQHandler + .type DMA8TO11_IRQHandler, %function +DMA8TO11_IRQHandler: + ldr r0,=DMA8TO11_DriverIRQHandler + bx r0 + .size DMA8TO11_IRQHandler, . - DMA8TO11_IRQHandler + + .align 1 + .thumb_func + .weak DMA12TO15_IRQHandler + .type DMA12TO15_IRQHandler, %function +DMA12TO15_IRQHandler: + ldr r0,=DMA12TO15_DriverIRQHandler + bx r0 + .size DMA12TO15_IRQHandler, . - DMA12TO15_IRQHandler + + .align 1 + .thumb_func + .weak DMAERR_IRQHandler + .type DMAERR_IRQHandler, %function +DMAERR_IRQHandler: + ldr r0,=DMAERR_DriverIRQHandler + bx r0 + .size DMAERR_IRQHandler, . - DMAERR_IRQHandler + + .align 1 + .thumb_func + .weak I2C0_IRQHandler + .type I2C0_IRQHandler, %function +I2C0_IRQHandler: + ldr r0,=I2C0_DriverIRQHandler + bx r0 + .size I2C0_IRQHandler, . - I2C0_IRQHandler + + .align 1 + .thumb_func + .weak SPI0_IRQHandler + .type SPI0_IRQHandler, %function +SPI0_IRQHandler: + ldr r0,=SPI0_DriverIRQHandler + bx r0 + .size SPI0_IRQHandler, . - SPI0_IRQHandler + + .align 1 + .thumb_func + .weak SPI1_IRQHandler + .type SPI1_IRQHandler, %function +SPI1_IRQHandler: + ldr r0,=SPI1_DriverIRQHandler + bx r0 + .size SPI1_IRQHandler, . - SPI1_IRQHandler + + .align 1 + .thumb_func + .weak UART0_IRQHandler + .type UART0_IRQHandler, %function +UART0_IRQHandler: + ldr r0,=UART0_DriverIRQHandler + bx r0 + .size UART0_IRQHandler, . - UART0_IRQHandler + + .align 1 + .thumb_func + .weak UART1_IRQHandler + .type UART1_IRQHandler, %function +UART1_IRQHandler: + ldr r0,=UART1_DriverIRQHandler + bx r0 + .size UART1_IRQHandler, . - UART1_IRQHandler + + .align 1 + .thumb_func + .weak UART2_IRQHandler + .type UART2_IRQHandler, %function +UART2_IRQHandler: + ldr r0,=UART2_DriverIRQHandler + bx r0 + .size UART2_IRQHandler, . - UART2_IRQHandler + + .align 1 + .thumb_func + .weak ADC0_IRQHandler + .type ADC0_IRQHandler, %function +ADC0_IRQHandler: + ldr r0,=ADC0_DriverIRQHandler + bx r0 + .size ADC0_IRQHandler, . - ADC0_IRQHandler + + .align 1 + .thumb_func + .weak FLASH_IRQHandler + .type FLASH_IRQHandler, %function +FLASH_IRQHandler: + ldr r0,=FLASH_DriverIRQHandler + bx r0 + .size FLASH_IRQHandler, . - FLASH_IRQHandler + + .align 1 + .thumb_func + .weak CMP_IRQHandler + .type CMP_IRQHandler, %function +CMP_IRQHandler: + ldr r0,=CMP_DriverIRQHandler + bx r0 + .size CMP_IRQHandler, . - CMP_IRQHandler + + .align 1 + .thumb_func + .weak TIM0_IRQHandler + .type TIM0_IRQHandler, %function +TIM0_IRQHandler: + ldr r0,=TIM0_DriverIRQHandler + bx r0 + .size TIM0_IRQHandler, . - TIM0_IRQHandler + + .align 1 + .thumb_func + .weak TIM1_IRQHandler + .type TIM1_IRQHandler, %function +TIM1_IRQHandler: + ldr r0,=TIM1_DriverIRQHandler + bx r0 + .size TIM1_IRQHandler, . - TIM1_IRQHandler + + .align 1 + .thumb_func + .weak TIM2_IRQHandler + .type TIM2_IRQHandler, %function +TIM2_IRQHandler: + ldr r0,=TIM2_DriverIRQHandler + bx r0 + .size TIM2_IRQHandler, . - TIM2_IRQHandler + + .align 1 + .thumb_func + .weak CAN0_IRQHandler + .type CAN0_IRQHandler, %function +CAN0_IRQHandler: + ldr r0,=CAN0_DriverIRQHandler + bx r0 + .size CAN0_IRQHandler, . - CAN0_IRQHandler + + .align 1 + .thumb_func + .weak RTC_IRQHandler + .type RTC_IRQHandler, %function +RTC_IRQHandler: + ldr r0,=RTC_DriverIRQHandler + bx r0 + .size RTC_IRQHandler, . - RTC_IRQHandler + + .align 1 + .thumb_func + .weak PMU_IRQHandler + .type PMU_IRQHandler, %function +PMU_IRQHandler: + ldr r0,=PMU_DriverIRQHandler + bx r0 + .size PMU_IRQHandler, . - PMU_IRQHandler + + .align 1 + .thumb_func + .weak TDG0_IRQHandler + .type TDG0_IRQHandler, %function +TDG0_IRQHandler: + ldr r0,=TDG0_DriverIRQHandler + bx r0 + .size TDG0_IRQHandler, . - TDG0_IRQHandler + + .align 1 + .thumb_func + .weak SCC_IRQHandler + .type SCC_IRQHandler, %function +SCC_IRQHandler: + ldr r0,=SCC_DriverIRQHandler + bx r0 + .size SCC_IRQHandler, . - SCC_IRQHandler + + .align 1 + .thumb_func + .weak WDOG_IRQHandler + .type WDOG_IRQHandler, %function +WDOG_IRQHandler: + ldr r0,=WDOG_DriverIRQHandler + bx r0 + .size WDOG_IRQHandler, . - WDOG_IRQHandler + + .align 1 + .thumb_func + .weak EWDT_IRQHandler + .type EWDT_IRQHandler, %function +EWDT_IRQHandler: + ldr r0,=EWDT_DriverIRQHandler + bx r0 + .size EWDT_IRQHandler, . - EWDT_IRQHandler + + .align 1 + .thumb_func + .weak STIM_IRQHandler + .type STIM_IRQHandler, %function +STIM_IRQHandler: + ldr r0,=STIM_DriverIRQHandler + bx r0 + .size STIM_IRQHandler, . - STIM_IRQHandler + + .align 1 + .thumb_func + .weak SRMC_IRQHandler + .type SRMC_IRQHandler, %function +SRMC_IRQHandler: + ldr r0,=SRMC_DriverIRQHandler + bx r0 + .size SRMC_IRQHandler, . - SRMC_IRQHandler + + .align 1 + .thumb_func + .weak PORTABC_IRQHandler + .type PORTABC_IRQHandler, %function +PORTABC_IRQHandler: + ldr r0,=PORTABC_DriverIRQHandler + bx r0 + .size PORTABC_IRQHandler, . - PORTABC_IRQHandler + + .align 1 + .thumb_func + .weak PORTDE_IRQHandler + .type PORTDE_IRQHandler, %function +PORTDE_IRQHandler: + ldr r0,=PORTDE_DriverIRQHandler + bx r0 + .size PORTDE_IRQHandler, . - PORTDE_IRQHandler + +/* Define default handlers */ + .macro def_irq_handler handler_name + .weak \handler_name + .set \handler_name, JumpToSelf + .endm + +/* Zhixin specific interrupt */ + def_irq_handler DMA0TO3_DriverIRQHandler + def_irq_handler DMA4TO7_DriverIRQHandler + def_irq_handler DMA8TO11_DriverIRQHandler + def_irq_handler DMA12TO15_DriverIRQHandler + def_irq_handler DMAERR_DriverIRQHandler + def_irq_handler I2C0_DriverIRQHandler + def_irq_handler Reserved6_IRQHandler + def_irq_handler SPI0_DriverIRQHandler + def_irq_handler SPI1_DriverIRQHandler + def_irq_handler Reserved9_IRQHandler + def_irq_handler UART0_DriverIRQHandler + def_irq_handler UART1_DriverIRQHandler + def_irq_handler UART2_DriverIRQHandler + def_irq_handler Reserved13_IRQHandler + def_irq_handler ADC0_DriverIRQHandler + def_irq_handler FLASH_DriverIRQHandler + def_irq_handler CMP_DriverIRQHandler + def_irq_handler TIM0_DriverIRQHandler + def_irq_handler TIM1_DriverIRQHandler + def_irq_handler TIM2_DriverIRQHandler + def_irq_handler CAN0_DriverIRQHandler + def_irq_handler Reserved21_IRQHandler + def_irq_handler RTC_DriverIRQHandler + def_irq_handler PMU_DriverIRQHandler + def_irq_handler TDG0_DriverIRQHandler + def_irq_handler SCC_DriverIRQHandler + def_irq_handler WDOG_DriverIRQHandler + def_irq_handler EWDT_DriverIRQHandler + def_irq_handler STIM_DriverIRQHandler + def_irq_handler SRMC_DriverIRQHandler + def_irq_handler PORTABC_DriverIRQHandler + def_irq_handler PORTDE_DriverIRQHandler + + + .end \ No newline at end of file diff --git a/Platform/Devices/Z20K116M/Startup/IAR/Z20K116M_startup.s b/Platform/Devices/Z20K116M/Startup/IAR/Z20K116M_startup.s new file mode 100644 index 0000000..451ecbc --- /dev/null +++ b/Platform/Devices/Z20K116M/Startup/IAR/Z20K116M_startup.s @@ -0,0 +1,409 @@ +; ----------------------------------------------------------------------------- +; @file : Z20K116M_startup.s +; @brief : Z20K116M startup and Vector Table Source File for IAR. +; @version : V1.8.0 +; @date : May-2020 +; @author : Zhixin Semiconductor +; +; @note +; @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. +; ----------------------------------------------------------------------------- + + + MODULE ?cstartup + + ;; Forward declaration of sections. + SECTION CSTACK:DATA:NOROOT(3) + + SECTION .intvec:CODE:ROOT(2) + + EXTERN __iar_program_start + PUBLIC __vector_table + PUBLIC __Vectors_End + PUBLIC __Vectors_Size + + DATA + +__vector_table + DCD sfe(CSTACK) + DCD Reset_Handler ; POR Reset Entry + DCD NMI_Handler ; Non Maskable handler + DCD HardFault_Handler ; SV Hard Fault handler + DCD 0 + DCD 0 + DCD 0 + DCD 0 + DCD 0 + DCD 0 + DCD 0 + DCD SVC_Handler ; SV Call handler + DCD 0 + DCD 0 + DCD PendSV_Handler ; Pend SV handler + DCD SysTick_Handler ; System Tick handler + + + DCD DMA0TO3_IRQHandler ; irq 0 : DMA channel 0 - 3 transfer complete IRQHandler + DCD DMA4TO7_IRQHandler ; irq 1 : DMA channel 4 - 7 transfer complete IRQHandler + DCD DMA8TO11_IRQHandler ; irq 2 : DMA channel 8 - 11 transfer complete IRQHandler + DCD DMA12TO15_IRQHandler ; irq 3 : DMA channel 12 - 15 transfer complete IRQHandler + DCD DMAERR_IRQHandler ; irq 4 : DMA error interrupt channels 0-7 IRQHandler + DCD I2C0_IRQHandler ; irq 5 : I2C 0 IRQHandler + DCD Reserved6_IRQHandler ; irq 6 : Reserved Interrupt + DCD SPI0_IRQHandler ; irq 7 : SPI 0 IRQHandler + DCD SPI1_IRQHandler ; irq 8 : SPI 1 IRQHandler + DCD Reserved9_IRQHandler ; irq 9 : Reserved Interrupt + DCD UART0_IRQHandler ; irq 10 : UART 0 IRQHandler + DCD UART1_IRQHandler ; irq 11 : UART 1 IRQHandler + DCD UART2_IRQHandler ; irq 12 : UART2 IRQHandler + DCD Reserved13_IRQHandler ; irq 13 : Reserved Interrupt + DCD ADC0_IRQHandler ; irq 14 : ADC0 IRQHandler + DCD FLASH_IRQHandler ; irq 15 : flash memory IRQHandler + DCD CMP_IRQHandler ; irq 16 : CMP IRQHandler + DCD TIM0_IRQHandler ; irq 17 : TIM 0 IRQHandler + DCD TIM1_IRQHandler ; irq 18 : TIM 1 IRQHandler + DCD TIM2_IRQHandler ; irq 19 : TIM 2 IRQHandler + DCD CAN0_IRQHandler ; irq 20 : CAN 0 IRQHandler + DCD Reserved21_IRQHandler ; irq 21 : Reserved Interrupt + DCD RTC_IRQHandler ; irq 22 : RTC IRQHandler + DCD PMU_IRQHandler ; irq 23 : PMU IRQHandler + DCD TDG0_IRQHandler ; irq 24 : TDG0 IRQHandler + DCD SCC_IRQHandler ; irq 25 : system clock controller IRQHandler + DCD WDOG_IRQHandler ; irq 26 : watchdog IRQHandler + DCD EWDT_IRQHandler ; irq 27 : external watchdog monitor IRQHandler + DCD STIM_IRQHandler ; irq 28 : STIM IRQHandler + DCD SRMC_IRQHandler ; irq 29 : system reset and mode control IRQHandler + DCD PORTABC_IRQHandler ; irq 30 : port A B C IRQHandler + DCD PORTDE_IRQHandler ; irq 31 : port D E IRQHandler +__Vectors_End + + +__Vectors_Size EQU __Vectors_End - __vector_table + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;; Default interrupt handlers. +;; + THUMB + + PUBWEAK Reset_Handler + SECTION .text:CODE:REORDER:NOROOT(2) +Reset_Handler + CPSID I ; Mask interrupts + ;; Init the registers + LDR R1,=0 + LDR R2,=0 + LDR R3,=0 + LDR R4,=0 + LDR R5,=0 + LDR R6,=0 + LDR R7,=0 + MOV R8,R7 + MOV R9,R7 + MOV R10,R7 + MOV R11,R7 + MOV R12,R7 + + ; vector table relocation + LDR R0, =0xE000ED08 + LDR R1, =__vector_table + STR R1, [R0] + +#ifndef START_FROM_SRAM + IMPORT __RAM_START, __RAM_END + ;; INIT ECC RAM + + LDR R1, =__RAM_START + LDR R2, =__RAM_END + + SUBS R2, R2, R1 + SUBS R2, #1 + BLE LB2 + + MOVS R0, #0 + MOVS R3, #4 + LB1: + STR R0, [R1] + ADD R1, R1, R3 + SUBS R2, #4 + BGE LB1 + LB2: +#endif + ;; Initialize the stack pointer + LDR R0, =sfe(CSTACK) + MOV R13,R0 + + CPSIE I ; Unmask interrupts + + LDR R0, =__iar_program_start + BX R0 + +JumpToSelf + B JumpToSelf + + PUBWEAK NMI_Handler + SECTION .text:CODE:REORDER:NOROOT(1) +NMI_Handler + B . + + PUBWEAK HardFault_Handler + SECTION .text:CODE:REORDER:NOROOT(1) +HardFault_Handler + B . + + + PUBWEAK SVC_Handler + SECTION .text:CODE:REORDER:NOROOT(1) +SVC_Handler + B . + + PUBWEAK PendSV_Handler + SECTION .text:CODE:REORDER:NOROOT(1) +PendSV_Handler + B . + + PUBWEAK SysTick_Handler + SECTION .text:CODE:REORDER:NOROOT(1) +SysTick_Handler + B . + + + PUBWEAK DMA0TO3_IRQHandler + PUBWEAK DMA0TO3_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +DMA0TO3_IRQHandler + LDR R0, =DMA0TO3_DriverIRQHandler + BX R0 + + PUBWEAK DMA4TO7_IRQHandler + PUBWEAK DMA4TO7_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +DMA4TO7_IRQHandler + LDR R0, =DMA4TO7_DriverIRQHandler + BX R0 + + PUBWEAK DMA8TO11_IRQHandler + PUBWEAK DMA8TO11_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +DMA8TO11_IRQHandler + LDR R0, =DMA8TO11_DriverIRQHandler + BX R0 + + PUBWEAK DMA12TO15_IRQHandler + PUBWEAK DMA12TO15_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +DMA12TO15_IRQHandler + LDR R0, =DMA12TO15_DriverIRQHandler + BX R0 + + PUBWEAK DMAERR_IRQHandler + PUBWEAK DMAERR_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +DMAERR_IRQHandler + LDR R0, =DMAERR_DriverIRQHandler + BX R0 + + PUBWEAK I2C0_IRQHandler + PUBWEAK I2C0_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +I2C0_IRQHandler + LDR R0, =I2C0_DriverIRQHandler + BX R0 + + PUBWEAK Reserved6_IRQHandler + PUBWEAK SPI0_IRQHandler + PUBWEAK SPI0_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +SPI0_IRQHandler + LDR R0, =SPI0_DriverIRQHandler + BX R0 + + PUBWEAK SPI1_IRQHandler + PUBWEAK SPI1_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +SPI1_IRQHandler + LDR R0, =SPI1_DriverIRQHandler + BX R0 + + PUBWEAK Reserved9_IRQHandler + PUBWEAK UART0_IRQHandler + PUBWEAK UART0_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +UART0_IRQHandler + LDR R0, =UART0_DriverIRQHandler + BX R0 + + PUBWEAK UART1_IRQHandler + PUBWEAK UART1_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +UART1_IRQHandler + LDR R0, =UART1_DriverIRQHandler + BX R0 + + PUBWEAK UART2_IRQHandler + PUBWEAK UART2_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +UART2_IRQHandler + LDR R0, =UART2_DriverIRQHandler + BX R0 + + PUBWEAK Reserved13_IRQHandler + PUBWEAK ADC0_IRQHandler + PUBWEAK ADC0_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +ADC0_IRQHandler + LDR R0, =ADC0_DriverIRQHandler + BX R0 + + PUBWEAK FLASH_IRQHandler + PUBWEAK FLASH_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +FLASH_IRQHandler + LDR R0, =FLASH_DriverIRQHandler + BX R0 + + PUBWEAK CMP_IRQHandler + PUBWEAK CMP_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +CMP_IRQHandler + LDR R0, =CMP_DriverIRQHandler + BX R0 + + PUBWEAK TIM0_IRQHandler + PUBWEAK TIM0_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +TIM0_IRQHandler + LDR R0, =TIM0_DriverIRQHandler + BX R0 + + PUBWEAK TIM1_IRQHandler + PUBWEAK TIM1_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +TIM1_IRQHandler + LDR R0, =TIM1_DriverIRQHandler + BX R0 + + PUBWEAK TIM2_IRQHandler + PUBWEAK TIM2_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +TIM2_IRQHandler + LDR R0, =TIM2_DriverIRQHandler + BX R0 + + PUBWEAK CAN0_IRQHandler + PUBWEAK CAN0_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +CAN0_IRQHandler + LDR R0, =CAN0_DriverIRQHandler + BX R0 + + PUBWEAK Reserved21_IRQHandler + PUBWEAK RTC_IRQHandler + PUBWEAK RTC_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +RTC_IRQHandler + LDR R0, =RTC_DriverIRQHandler + BX R0 + + PUBWEAK PMU_IRQHandler + PUBWEAK PMU_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +PMU_IRQHandler + LDR R0, =PMU_DriverIRQHandler + BX R0 + + PUBWEAK TDG0_IRQHandler + PUBWEAK TDG0_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +TDG0_IRQHandler + LDR R0, =TDG0_DriverIRQHandler + BX R0 + + PUBWEAK SCC_IRQHandler + PUBWEAK SCC_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +SCC_IRQHandler + LDR R0, =SCC_DriverIRQHandler + BX R0 + + PUBWEAK WDOG_IRQHandler + PUBWEAK WDOG_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +WDOG_IRQHandler + LDR R0, =WDOG_DriverIRQHandler + BX R0 + + PUBWEAK EWDT_IRQHandler + PUBWEAK EWDT_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +EWDT_IRQHandler + LDR R0, =EWDT_DriverIRQHandler + BX R0 + + PUBWEAK STIM_IRQHandler + PUBWEAK STIM_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +STIM_IRQHandler + LDR R0, =STIM_DriverIRQHandler + BX R0 + + PUBWEAK SRMC_IRQHandler + PUBWEAK SRMC_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +SRMC_IRQHandler + LDR R0, =SRMC_DriverIRQHandler + BX R0 + + PUBWEAK PORTABC_IRQHandler + PUBWEAK PORTABC_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +PORTABC_IRQHandler + LDR R0, =PORTABC_DriverIRQHandler + BX R0 + + PUBWEAK PORTDE_IRQHandler + PUBWEAK PORTDE_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +PORTDE_IRQHandler + LDR R0, =PORTDE_DriverIRQHandler + BX R0 + + PUBWEAK DefaultISR + SECTION .text:CODE:REORDER:NOROOT(1) +DMA0TO3_DriverIRQHandler +DMA4TO7_DriverIRQHandler +DMA8TO11_DriverIRQHandler +DMA12TO15_DriverIRQHandler +DMAERR_DriverIRQHandler +I2C0_DriverIRQHandler +Reserved6_IRQHandler +SPI0_DriverIRQHandler +SPI1_DriverIRQHandler +Reserved9_IRQHandler +UART0_DriverIRQHandler +UART1_DriverIRQHandler +UART2_DriverIRQHandler +Reserved13_IRQHandler +ADC0_DriverIRQHandler +FLASH_DriverIRQHandler +CMP_DriverIRQHandler +TIM0_DriverIRQHandler +TIM1_DriverIRQHandler +TIM2_DriverIRQHandler +CAN0_DriverIRQHandler +Reserved21_IRQHandler +RTC_DriverIRQHandler +PMU_DriverIRQHandler +TDG0_DriverIRQHandler +SCC_DriverIRQHandler +WDOG_DriverIRQHandler +EWDT_DriverIRQHandler +STIM_DriverIRQHandler +SRMC_DriverIRQHandler +PORTABC_DriverIRQHandler +PORTDE_DriverIRQHandler +DefaultISR + B DefaultISR + + END diff --git a/Platform/Devices/Z20K118M/Inc/Z20K118M.h b/Platform/Devices/Z20K118M/Inc/Z20K118M.h new file mode 100644 index 0000000..1ed473d --- /dev/null +++ b/Platform/Devices/Z20K118M/Inc/Z20K118M.h @@ -0,0 +1,4616 @@ +/**************************************************************************************************/ +/** + * @file : Z20K118M.h + * @brief : Z20K118M device header file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ + +#ifndef Z20K118M_H +#define Z20K118M_H + +#include +#include +#include + +/** + * @brief Variant Peripheral Instance Information + */ +#define CAN_INSTANCE_NUM (2U) +#define SPI_INSTANCE_NUM (3U) +#define I2C_INSTANCE_NUM (2U) +#define UART_INSTANCE_NUM (4U) + +/** + * @brief Peripheral Base Address + */ +#define FLASH_CODE_BASE_ADDR ((uint32_t)0x00000000) /*!< Code flash base address */ +#define FLASH_DATA_BASE_ADDR ((uint32_t)0x01000000) /*!< Data flash base address */ +#define FLASH_IFR_BASE_ADDR ((uint32_t)0x02000000) /*!< flash IFR base address */ +#define SRAML_BASE_ADDR ((uint32_t)0x1FFFC000) /*!< SRAML base address */ +#define SRAMU_BASE_ADDR ((uint32_t)0x20000000) /*!< SRAMU0(SRAM_U) base address */ +#define PERIPHERAL_BASE_ADDR ((uint32_t)0x40000000) /*!< Peripheral area base address */ +#define AIPS0_BASE_ADDR ((uint32_t)0x40000000) /*!< AIPS0 base address */ + +#define PRI_PERI_BUS_BASE_ADDR ((uint32_t)0xE0000000) /*!< private Peripheral base address */ + +#define DMA_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x8000UL) /*!< DMA controller base address */ +#define FLASHC_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x20000UL) /*!< flash controller base address */ +#define DMAMUX_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x22000UL) /*!< DMA channel Multiplexer base address */ +#define CAN0_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x24000UL) /*!< CAN0 base address */ +#define ADC0_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x26000UL) /*!< ADC0 base address */ +#define RTC_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x28000UL) /*!< RTC base address */ +#define CAN1_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x2A000UL) /*!< CAN1 base address */ +#define SPI0_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x2C000UL) /*!< SPI0 base address */ +#define SPI1_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x2D000UL) /*!< SPI1 base address */ +#define SPI2_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x2E000UL) /*!< SPI2 base address */ +#define REGFILE_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x34000UL) /*!< REGFILE base address */ +#define TDG0_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x35000UL) /*!< TDG0 base address */ +#define TMU_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x36000UL) /*!< TMU base address */ +#define TIM0_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x38000UL) /*!< TIM0 base address */ +#define TIM1_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x39000UL) /*!< TIM1 base address */ +#define TIM2_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x3A000UL) /*!< TIM2 base address */ +#define STIM_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x40000UL) /*!< STIM base address */ +#define CRC_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x43000UL) /*!< CRC base address */ +#define SCM_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x48000UL) /*!< System Control base address */ +#define PORTA_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x49000UL) /*!< PORTA multiplexing base address */ +#define PORTB_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x4A000UL) /*!< PORTB multiplexing base address */ +#define PORTC_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x4B000UL) /*!< PORTC multiplexing base address */ +#define PORTD_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x4C000UL) /*!< PORTD multiplexing base address */ +#define PORTE_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x4D000UL) /*!< PORTE multiplexing base address */ +#define WDOG_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x52000UL) /*!< watchdog base address */ +#define EWDT_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x61000UL) /*!< External Watchdog Monitor base address */ +#define SCC_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x64000UL) /*!< System Clock Controller base address */ +#define PARCC_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x65000UL) /*!< Peripheral Clock Control base address */ +#define I2C0_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x66000UL) /*!< I2C0 base address */ +#define I2C1_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x67000UL) /*!< I2C1 base address */ +#define UART0_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x6A000UL) /*!< UART0 base address */ +#define UART1_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x6B000UL) /*!< UART1 base address */ +#define UART2_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x6C000UL) /*!< UART2 base address */ +#define UART3_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x6D000UL) /*!< UART3 base address */ +#define CMP_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x73000UL) /*!< Analog comparator base address */ +#define PMU_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x7D000UL) /*!< Power management Unit base address */ +#define SRMC_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0x7E000UL) /*!< system reset and mode controller base address */ +#define HWDIV_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0xFE000UL) /*!< HWDIV base address */ +#define GPIO_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0xFF000UL) /*!< GPIO controller base address */ +#define GPIOA_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0xFF000UL) /*!< GPIOA base address */ +#define GPIOB_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0xFF040UL) /*!< GPIOB base address */ +#define GPIOC_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0xFF080UL) /*!< GPIOC base address */ +#define GPIOD_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0xFF0C0UL) /*!< GPIOD base address */ +#define GPIOE_BASE_ADDR (PERIPHERAL_BASE_ADDR + 0xFF100UL) /*!< GPIOE base address */ +#define RGPIO_BASE_ADDR 0xF8000000UL /*!< Fast GPIO controller base address */ +#define RGPIOA_BASE_ADDR (RGPIO_BASE_ADDR + 0x00000UL) /*!< Fast GPIOA controller base address */ +#define RGPIOB_BASE_ADDR (RGPIO_BASE_ADDR + 0x00040UL) /*!< Fast GPIOB controller base address */ +#define RGPIOC_BASE_ADDR (RGPIO_BASE_ADDR + 0x00080UL) /*!< Fast GPIOC controller base address */ +#define RGPIOD_BASE_ADDR (RGPIO_BASE_ADDR + 0x000C0UL) /*!< Fast GPIOD controller base address */ +#define RGPIOE_BASE_ADDR (RGPIO_BASE_ADDR + 0x00100UL) /*!< Fast GPIOE controller base address */ + +/** + * @brief IRQ Number Definition + */ +typedef enum IRQn +{ + /****** Cortex-M0+ Processor IRQ Numbers *******************************/ + NonMaskableInt_IRQn = -14, /*!< 2 Non Maskable Interrupt */ + HardFalut_IRQn = -13, /*!< 3 Hardfault Interrupt */ + SVCall_IRQn = -5, /*!< 11 Cortex-M0+ SV Call Interrupt */ + PendSV_IRQn = -2, /*!< 14 Cortex-M0+ Pend SV Interrupt */ + SysTick_IRQn = -1, /*!< 15 Cortex-M0+ System Tick Interrupt */ + + /****** specific IRQ Numbers *************************************/ + DMA0TO3_IRQn = 0, /*!< DMA channel 0-3 transfer complete Interrupt */ + DMA4TO7_IRQn = 1, /*!< DMA channel 4-7 transfer complete Interrupt */ + DMA8TO11_IRQn = 2, /*!< DMA channel 8-11 transfer complete Interrupt */ + DMA12TO15_IRQn = 3, /*!< DMA channel 12-15 transfer complete Interrupt */ + DMAERR_IRQn = 4, /*!< DMA error (channels 0-16) Interrupt */ + I2C0_IRQn = 5, /*!< I2C 0 Interrupt */ + I2C1_IRQn = 6, /*!< I2C 1 Interrupt */ + SPI0_IRQn = 7, /*!< SPI 0 Interrupt */ + SPI1_IRQn = 8, /*!< SPI 1 Interrupt*/ + SPI2_IRQn = 9, /*!< SPI 2 Interrupt */ + UART0_IRQn = 10, /*!< UART 0 Interrupt */ + UART1_IRQn = 11, /*!< UART 1 Interrupt */ + UART2_IRQn = 12, /*!< UART2 Interrupt */ + UART3_IRQn = 13, /*!< UART3 Interrupt*/ + ADC0_IRQn = 14, /*!< ADC0 Interrupt */ + FLASH_IRQn = 15, /*!< flash ISR */ + CMP_IRQn = 16, /*!< CMP Interrupt */ + TIM0_IRQn = 17, /*!< TIM 0 Interrupt */ + TIM1_IRQn = 18, /*!< TIM 1 Interrupt */ + TIM2_IRQn = 19, /*!< TIM 2 Interrupt */ + CAN0_IRQn = 20, /*!< CAN 0 Interrupt*/ + CAN1_IRQn = 21, /*!< CAN 1 Interrupt */ + RTC_IRQn = 22, /*!< RTC Interrupt */ + PMU_IRQn = 23, /*!< PMU Interrupt */ + TDG0_IRQn = 24, /*!< TDG0 Interrupt */ + SCC_IRQn = 25, /*!< system clock controller Interrupt*/ + WDOG_IRQn = 26, /*!< watchdog Interrupt */ + EWDT_IRQn = 27, /*!< external watchdog monitor Interrupt*/ + STIM_IRQn = 28, /*!< STIM Interrupt */ + SRMC_IRQn = 29, /*!< system reset and mode control Interrupt*/ + PORTABC_IRQn = 30, /*!< port A B C Interrupt */ + PORTDE_IRQn = 31 /*!< port D E Interrupt */ +} IRQn_Type; + +/** + * Peripheral Register Defination + */ +struct adc_reg { + /* 0x000*/ + struct { + uint32_t DIFFEN : 1; /* [0] ro */ + uint32_t CALOFSI : 1; /* [1] ro */ + uint32_t RSVD_7_2 : 6; /* [7:2] ro */ + uint32_t FIFO_NUM : 8; /* [15:8] ro */ + uint32_t MINOR : 8; /* [23:16] ro */ + uint32_t MAJOR : 8; /* [31:24] ro */ + } ADC_VERID; + + /* 0x004*/ + struct { + uint32_t RSVD_7_0 : 8; /* [7:0] ro */ + uint32_t FIFO_SIZE : 8; /* [15:8] ro */ + uint32_t RSVD_31_16 :16; /* [31:16] ro */ + } ADC_PARAM; + + /* 0x008*/ + struct { + uint32_t ADC_EN : 1; /* [0] r/w */ + uint32_t CAL_REQ : 1; /* [1] r/w */ + uint32_t RST : 1; /* [2] r/w */ + uint32_t DOZEN : 1; /* [3] r/w */ + uint32_t TRIG_MODE_ENABLE : 1; /* [4] r/w */ + uint32_t TRIG_MODE : 1; /* [5] r/w */ + uint32_t MODE1_RST : 1; /* [6] r/w */ + uint32_t RSVD_31_7 :25; /* [31:7] ro */ + } ADC_CTRL; + + /* 0x00C*/ + struct { + uint32_t FWM_INT : 1; /* [0] r/w1c */ + uint32_t FOF : 1; /* [1] r/w1c */ + uint32_t TCOMP_INT : 1; /* [2] r/w1c */ + uint32_t CMP_INT : 1; /* [3] r/w1c */ + uint32_t DMA_REQ : 1; /* [4] ro */ + uint32_t RDY : 1; /* [5] ro */ + uint32_t CAL_RDY : 1; /* [6] ro */ + uint32_t ADC_ACTIVE : 1; /* [7] ro */ + uint32_t LSI : 1; /* [8] ro */ + uint32_t TC_ERR : 1; /* [9] ro */ + uint32_t RSVD_31_10 :22; /* [31:10] ro */ + } ADC_STAT; + + /* 0x010*/ + struct { + uint32_t FWM_IE : 1; /* [0] r/w */ + uint32_t FOF_IE : 1; /* [1] r/w */ + uint32_t TCOM_IE : 1; /* [2] r/w */ + uint32_t CMP_IE : 1; /* [3] r/w */ + uint32_t FWMDE : 1; /* [4] r/w */ + uint32_t ERR_INT_IE : 1; /* [5] r/w */ + uint32_t RSVD_31_6 :26; /* [31:6] ro */ + } ADC_IE; + + /* 0x014*/ + struct { + uint32_t DIFF_MODE : 1; /* [0] r/w */ + uint32_t CHSELP : 5; /* [5:1] r/w */ + uint32_t CHSELN : 2; /* [7:6] r/w */ + uint32_t RSVD_10_8 : 3; /* [10:8] ro */ + uint32_t CTYPE : 1; /* [11] r/w */ + uint32_t CMPS : 3; /* [14:12] r/w */ + uint32_t RSVD_15 : 1; /* [15] r/w */ + uint32_t REF_SEL : 1; /* [16] r/w */ + uint32_t RES : 2; /* [18:17] r/w */ + uint32_t AVGS : 3; /* [21:19] r/w */ + uint32_t STS :10; /* [31:22] r/w */ + } ADC_CFG; + + /* 0x018*/ + struct { + uint32_t CVL :12; /* [11:0] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] ro */ + uint32_t CVH :12; /* [27:16] r/w */ + uint32_t RSVD_31_28 : 4; /* [31:28] ro */ + } ADC_CV; + + /* 0x01C*/ + struct { + uint32_t RSVD_5_0 : 6; /* [5:0] ro */ + uint32_t RSVD_6 : 1; /* [6] ro */ + uint32_t RSVD_10_7 : 4; /* [10:7] ro */ + uint32_t RSVD_30_11 :20; /* [30:11] ro */ + uint32_t RSVD_31 : 1; /* [31] r/w */ + } ADC_RSVD; + + /* 0x020*/ + struct { + uint32_t ADC_DATA_RD :17; /* [16:0] ro */ + uint32_t RSVD_31_17 :15; /* [31:17] ro */ + } ADC_DATA_RD; + + /* 0x024*/ + struct { + uint32_t FCOUNT : 5; /* [4:0] ro */ + uint32_t RSVD_15_5 :11; /* [15:5] ro */ + uint32_t FWMARK : 4; /* [19:16] r/w */ + uint32_t FDRD : 5; /* [24:20] r/w */ + uint32_t RSVD_31_25 : 7; /* [31:25] ro */ + } ADC_FCTRL; + + /* 0x028*/ + struct { + uint32_t ADC_SWTRIG : 1; /* [0] r/w */ + uint32_t RSVD_31_1 :31; /* [31:1] ro */ + } ADC_SWTRIG; + + /* 0x02C*/ + struct { + uint32_t ADC_CAL_VAL :13; /* [12:0] ro */ + uint32_t RSVD_31_13 :19; /* [31:13] ro */ + } ADC_CAL_VAL; + + /* 0x030*/ + struct { + uint32_t CMD0 : 5; /* [4:0] r/w */ + uint32_t RSVD_7_5 : 3; /* [7:5] ro */ + uint32_t CMD1 : 5; /* [12:8] r/w */ + uint32_t RSVD_15_13 : 3; /* [15:13] ro */ + uint32_t CMD2 : 5; /* [20:16] r/w */ + uint32_t RSVD_23_21 : 3; /* [23:21] ro */ + uint32_t CMD3 : 5; /* [28:24] r/w */ + uint32_t RSVD_31_29 : 3; /* [31:29] ro */ + } ADC_CMD_BUFF0; + + /* 0x034*/ + struct { + uint32_t CMD4 : 5; /* [4:0] r/w */ + uint32_t RSVD_7_5 : 3; /* [7:5] ro */ + uint32_t CMD5 : 5; /* [12:8] r/w */ + uint32_t RSVD_31_13 :19; /* [31:13] ro */ + } ADC_CMD_BUFF1; + +}; /*adc_reg*/ + +struct adc_reg_w { + /* 0x000*/ + uint32_t ADC_VERID; + /* 0x004*/ + uint32_t ADC_PARAM; + /* 0x008*/ + uint32_t ADC_CTRL; + /* 0x00C*/ + uint32_t ADC_STAT; + /* 0x010*/ + uint32_t ADC_IE; + /* 0x014*/ + uint32_t ADC_CFG; + /* 0x018*/ + uint32_t ADC_CV; + /* 0x01C*/ + uint32_t ADC_RSVD; + /* 0x020*/ + uint32_t ADC_DATA_RD; + /* 0x024*/ + uint32_t ADC_FCTRL; + /* 0x028*/ + uint32_t ADC_SWTRIG; + /* 0x02C*/ + uint32_t ADC_CAL_VAL; + /* 0x030*/ + uint32_t ADC_CMD_BUFF0; + /* 0x034*/ + uint32_t ADC_CMD_BUFF1; +}; /*adc_reg*/ + +typedef volatile struct adc_reg adc_reg_t; +typedef volatile struct adc_reg_w adc_reg_w_t; + +struct can_reg { + /* 0x00*/ + struct { + uint32_t MAXMB : 7; /* [6:0] r/w */ + uint32_t RSVD_7 : 1; /* [7] reserve */ + uint32_t IDAM : 2; /* [9:8] r/w */ + uint32_t RSVD_10 : 1; /* [10] reserve */ + uint32_t FDEN : 1; /* [11] r/w */ + uint32_t AEN : 1; /* [12] r/w */ + uint32_t LPRIOEN : 1; /* [13] r/w */ + uint32_t PNET_EN : 1; /* [14] r/w */ + uint32_t DMAE : 1; /* [15] r/w */ + uint32_t IRMQ : 1; /* [16] r/w */ + uint32_t SRXDIS : 1; /* [17] r/w */ + uint32_t DOZE : 1; /* [18] r/w */ + uint32_t WAKSRC : 1; /* [19] r/w */ + uint32_t LPMACK : 1; /* [20] read only */ + uint32_t WRNEN : 1; /* [21] r/w */ + uint32_t SLFWAK : 1; /* [22] r/w */ + uint32_t SUPV : 1; /* [23] r/w */ + uint32_t FRZACK : 1; /* [24] read only */ + uint32_t SOFTRST : 1; /* [25] r/w */ + uint32_t WAKMSK : 1; /* [26] r/w */ + uint32_t NOTRDY : 1; /* [27] read only */ + uint32_t HALT : 1; /* [28] r/w */ + uint32_t RFEN : 1; /* [29] r/w */ + uint32_t FRZ : 1; /* [30] r/w */ + uint32_t MDIS : 1; /* [31] r/w */ + } CAN_MCR; + + /* 0x04*/ + struct { + uint32_t PROPSEG : 3; /* [2:0] r/w */ + uint32_t LOM : 1; /* [3] r/w */ + uint32_t LBUF : 1; /* [4] r/w */ + uint32_t TSYC : 1; /* [5] r/w */ + uint32_t BOFFREC : 1; /* [6] r/w */ + uint32_t SMP : 1; /* [7] r/w */ + uint32_t RSVD_9_8 : 2; /* [9:8] reserve */ + uint32_t RWRNMSK : 1; /* [10] r/w */ + uint32_t TWRNMSK : 1; /* [11] r/w */ + uint32_t LPB : 1; /* [12] r/w */ + uint32_t RSVD_13 : 1; /* [13] reserve */ + uint32_t ERRMSK : 1; /* [14] r/w */ + uint32_t BOFFMSK : 1; /* [15] r/w */ + uint32_t PSEG2 : 3; /* [18:16] r/w */ + uint32_t PSEG1 : 3; /* [21:19] r/w */ + uint32_t RJW : 2; /* [23:22] r/w */ + uint32_t PRESDIV : 8; /* [31:24] r/w */ + } CAN_CTRL1; + + /* 0x08*/ + struct { + uint32_t TIMER :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] reserve */ + } CAN_TIMER; + + uint8_t zResverd0x0C[4]; /*pad 0x0C - 0F*/ + + /* 0x10*/ + struct { + uint32_t MG :32; /* [31:0] r/w */ + } CAN_RXMGMSK; + + /* 0x14*/ + struct { + uint32_t RX14M :32; /* [31:0] r/w */ + } CAN_RX14MASK; + + /* 0x18*/ + struct { + uint32_t RX15M :32; /* [31:0] r/w */ + } CAN_RX15MASK; + + /* 0x1c*/ + struct { + uint32_t TXERRCNT : 8; /* [7:0] r/w */ + uint32_t RXERRCNT : 8; /* [15:8] r/w */ + uint32_t TX_ERRCNT_FAST : 8; /* [23:16] r/w */ + uint32_t RX_ERRCNT_FAST : 8; /* [31:24] r/w */ + } CAN_ECR; + + /* 0x20*/ + struct { + uint32_t WAKINT : 1; /* [0] r/w1c */ + uint32_t ERRINT : 1; /* [1] r/w1c */ + uint32_t BOFFINT : 1; /* [2] r/w1c */ + uint32_t RX : 1; /* [3] read only */ + uint32_t FLTCONF : 2; /* [5:4] read only */ + uint32_t TX : 1; /* [6] read only */ + uint32_t IDLE : 1; /* [7] read only */ + uint32_t RXWRN : 1; /* [8] read only */ + uint32_t TXWRN : 1; /* [9] read only */ + uint32_t STFERR : 1; /* [10] read only */ + uint32_t FRAMERR : 1; /* [11] read only */ + uint32_t CRCERR : 1; /* [12] read only */ + uint32_t ACKERR : 1; /* [13] read only */ + uint32_t BIT0ERR : 1; /* [14] read only */ + uint32_t BIT1ERR : 1; /* [15] read only */ + uint32_t RWRNINT : 1; /* [16] read only */ + uint32_t TWRNINT : 1; /* [17] read only */ + uint32_t SYNCH : 1; /* [18] read only */ + uint32_t BUSOFFDONEINT : 1; /* [19] r/w1c */ + uint32_t ERRINT_FAST : 1; /* [20] r/w1c */ + uint32_t ERROVR : 1; /* [21] r/w1c */ + uint32_t RSVD_25_22 : 4; /* [25:22] reserve */ + uint32_t STFERR_FAST : 1; /* [26] read only */ + uint32_t FRAMERR_FAST : 1; /* [27] read only */ + uint32_t CRCERR_FAST : 1; /* [28] read only */ + uint32_t RSVD_29 : 1; /* [29] reserve */ + uint32_t BIT0ERR_FAST : 1; /* [30] read only */ + uint32_t BIT1ERR_FAST : 1; /* [31] read only */ + } CAN_ESR1; + + /* 0x24*/ + struct { + uint32_t BUF63TO32M :32; /* [31:0] r/w */ + } CAN_IMASK2; + + /* 0x28*/ + struct { + uint32_t BUF31TO0M :32; /* [31:0] r/w */ + } CAN_IMASK1; + + /* 0x2c*/ + struct { + uint32_t BUF63TO32I :32; /* [31:0] r/w */ + } CAN_IFLAG2; + + /* 0x30*/ + struct { + uint32_t BUF0I : 1; /* [0] r/w1c */ + uint32_t BUF4TO1I : 4; /* [4:1] r/w1c */ + uint32_t BUF5I : 1; /* [5] r/w1c */ + uint32_t BUF6I : 1; /* [6] r/w1c */ + uint32_t BUF7I : 1; /* [7] r/w1c */ + uint32_t BUF31TO8I :24; /* [31:8] r/w1c */ + } CAN_IFLAG1; + + /* 0x34*/ + struct { + uint32_t RSVD_10_0 :11; /* [10:0] reserve */ + uint32_t EDFLTDIS : 1; /* [11] r/w */ + uint32_t ISOCANFDEN : 1; /* [12] r/w */ + uint32_t RSVD_13 : 1; /* [13] reserve */ + uint32_t PREXCEN : 1; /* [14] r/w */ + uint32_t TIMER_SRC : 1; /* [15] r/w */ + uint32_t EACEN : 1; /* [16] r/w */ + uint32_t RRS : 1; /* [17] r/w */ + uint32_t MRP : 1; /* [18] r/w */ + uint32_t TASD : 5; /* [23:19] r/w */ + uint32_t RFFN : 4; /* [27:24] r/w */ + uint32_t WRMFRZ : 1; /* [28] r/w */ + uint32_t ECRWRE : 1; /* [29] r/w */ + uint32_t BOFFDONEMSK : 1; /* [30] r/w */ + uint32_t ERRMASK_FAST : 1; /* [31] r/w */ + } CAN_CTRL2; + + /* 0x38*/ + struct { + uint32_t RSVD_12_0 :13; /* [12:0] reserve */ + uint32_t IMB : 1; /* [13] read only */ + uint32_t VPS : 1; /* [14] read only */ + uint32_t RSVD_15 : 1; /* [15] reserve */ + uint32_t LPTM : 7; /* [22:16] read only */ + uint32_t RSVD_31_23 : 9; /* [31:23] */ + } CAN_ESR2; + + uint8_t zResverd0x03C[8]; /*pad 0x03C - 043*/ + + /* 0x44*/ + struct { + uint32_t TXCRC :15; /* [14:0] read only */ + uint32_t RSVD_15 : 1; /* [15] reserve */ + uint32_t MBCRC : 7; /* [22:16] read only */ + uint32_t RSVD_31_23 : 9; /* [31:23] reserve */ + } CAN_CRCR; + + /* 0x48*/ + struct { + uint32_t FGM :32; /* [31:0] r/w */ + } CAN_RXFGMASK; + + /* 0x4c*/ + struct { + uint32_t IDHIT : 9; /* [8:0] read only */ + uint32_t RSVD_31_9 :23; /* [31:9] reserve */ + } CAN_RXFIR; + + /* 0x50*/ + struct { + uint32_t EPSEG2 : 5; /* [4:0] r/w */ + uint32_t EPSEG1 : 5; /* [9:5] r/w */ + uint32_t EPROPSEG : 6; /* [15:10] r/w */ + uint32_t ERJW : 5; /* [20:16] r/w */ + uint32_t EPRESDIV :10; /* [30:21] r/w */ + uint32_t BTF : 1; /* [31] r/w */ + } CAN_CBT; + + uint8_t zResverd0x054[20]; /*pad 0x054 - 067*/ + + /* 0x68*/ + struct { + uint32_t BUF127TO96M :32; /* [31:0] r/w */ + } CAN_IMASK4; + + /* 0x6c*/ + struct { + uint32_t BUF95TO64M :32; /* [31:0] r/w */ + } CAN_IMASK3; + + /* 0x70*/ + struct { + uint32_t BUF127TO96I :32; /* [31:0] r/w1c */ + } CAN_IFLAG4; + + /* 0x74*/ + struct { + uint32_t BUF95TO64I :32; /* [31:0] r/w1c */ + } CAN_IFLAG3; + + uint8_t zResverd0x078[8]; /*pad 0x078 - 07F*/ + + /* 0x80 */ + struct { + struct { + uint32_t TIME_STAMP :16; /* [15:0] */ + uint32_t DLC : 4; /* [19:16] */ + uint32_t RTR : 1; /* [20] */ + uint32_t IDE : 1; /* [21] */ + uint32_t SRR : 1; /* [22] */ + uint32_t RSVD_23 : 1; /* [23] */ + uint32_t CODE : 4; /* [27:24] */ + uint32_t RSVD_28 : 1; /* [28] */ + uint32_t ESI : 1; /* [29] */ + uint32_t BRS : 1; /* [30] */ + uint32_t EDL : 1; /* [31] */ + } MB0; + + /* 0x84*/ + struct { + uint32_t ID_EXTEND :18; /* [17:0] */ + uint32_t ID_STANDARD :11; /* [28:18] */ + uint32_t PRIO : 3; /* [31:29] */ + } MB1; + + /* 0x88*/ + struct { + uint32_t DATA_BYTE :32; /* [31:0] */ + } MB2; + + /* 0x8c*/ + struct { + uint32_t DATA_BYTE :32; /* [31:0] */ + } MB3; + } CAN_MB[64]; + uint8_t zResverd0x0480[0x400]; /*pad 0x0480 - 087F*/ + + /* 0x880*/ + struct { + uint32_t MI : 32; /* [1] */ + } CAN_RXIMR[64]; + + uint8_t zResverd0x0A80[352]; /*pad 0x0A80 - 0ADF, 64*4 + 96*/ + + /* 0xAE0*/ + struct { + uint32_t RSVD_6_0 : 7; /* [6:0] reserve */ + uint32_t NCEFAFRZ : 1; /* [7] r/w */ + uint32_t ECCDIS : 1; /* [8] r/w */ + uint32_t RERRDIS : 1; /* [9] r/w */ + uint32_t RSVD_12_10 : 3; /* [12:10] reserve */ + uint32_t EXTERRIE : 1; /* [13] r/w */ + uint32_t FAERRIE : 1; /* [14] r/w */ + uint32_t HAERRI : 1; /* [15] r/w */ + uint32_t CEI_MSK : 1; /* [16] r/w */ + uint32_t RSVD_17 : 1; /* [17] reserve */ + uint32_t FANCEI_MSK : 1; /* [18] r/w */ + uint32_t HANCEI_MSK : 1; /* [19] r/w */ + uint32_t RSVD_30_20 :11; /* [30:20] reserve */ + uint32_t ECRWRDIS : 1; /* [31] r/w */ + } CAN_MECR; + + /* 0xAE4*/ + struct { + uint32_t INJADDR_L : 2; /* [1:0] r/w */ + uint32_t INJADDR_H :12; /* [13:2] r/w */ + uint32_t RSVD_31_14 :18; /* [31:14] reserve */ + } CAN_ERRIAR; + + /* 0xAE8*/ + struct { + uint32_t DFLIP :32; /* [31:0] r/w */ + } CAN_ERRIDPR; + + /* 0xAEC*/ + struct { + uint32_t PFLIP0 : 5; /* [4:0] r/w */ + uint32_t RSVD_7_5 : 3; /* [7:5] reserve */ + uint32_t PFLIP1 : 5; /* [12:8] r/w */ + uint32_t RSVD_15_13 : 3; /* [15:13] reserve */ + uint32_t PFLIP2 : 5; /* [20:16] r/w */ + uint32_t RSVD_23_21 : 3; /* [23:21] reserve */ + uint32_t PFLIP3 : 5; /* [28:24] r/w */ + uint32_t RSVD_31_29 : 3; /* [31:29] reserve */ + } CAN_ERRIPPR; + + /* 0xAF0*/ + struct { + uint32_t ERRADDR :14; /* [13:0] read only */ + uint32_t RSVD_15_14 : 2; /* [15:14] reserve */ + uint32_t SAID : 3; /* [18:16] read only */ + uint32_t RSVD_23_19 : 5; /* [23:19] reserve */ + uint32_t NCE : 1; /* [24] read only */ + uint32_t RSVD_31_25 : 7; /* [31:25] reserve */ + } CAN_RERRAR; + + /* 0xAF4*/ + struct { + uint32_t RDATA :32; /* [31:0] read only */ + } CAN_RERRDR; + + /* 0xAF8*/ + struct { + uint32_t SYND0 : 5; /* [4:0] read only */ + uint32_t RSVD_6_5 : 2; /* [6:5] reserve */ + uint32_t BE0 : 1; /* [7] read only */ + uint32_t SYND1 : 5; /* [12:8] read only */ + uint32_t RSVD_14_13 : 2; /* [14:13] read only */ + uint32_t BE1 : 1; /* [15] read only */ + uint32_t SYND2 : 5; /* [20:16] read only */ + uint32_t RSVD_22_21 : 2; /* [22:21] reserve */ + uint32_t BE2 : 1; /* [23] read only */ + uint32_t SYND3 : 5; /* [28:24] read only */ + uint32_t RSVD_30_29 : 2; /* [30:29] reserve */ + uint32_t BE3 : 1; /* [31] read only */ + } CAN_RERRSYNR; + + /* 0xAFC*/ + struct { + uint32_t CEIOF : 1; /* [0] r/w1c */ + uint32_t RSVD_1 : 1; /* [1] reserve */ + uint32_t FANCEIOF : 1; /* [2] r/w1c */ + uint32_t HANCEIOF : 1; /* [3] r/w1c */ + uint32_t RSVD_15_4 :12; /* [15:4] reserve */ + uint32_t CEIF : 1; /* [16] r/w1c */ + uint32_t RSVD_17 : 1; /* [17] reserve */ + uint32_t FANCEIF : 1; /* [18] r/w1c */ + uint32_t HANCEIF : 1; /* [19] r/w1c */ + uint32_t RSVD_31_20 :12; /* [31:20] reserve */ + } CAN_ERRSR; + + /* 0xB00*/ + struct { + uint32_t FCS : 2; /* [1:0] r/w */ + uint32_t IDFS : 2; /* [3:2] r/w */ + uint32_t PLFS : 2; /* [5:4] r/w */ + uint32_t RSVD_7_6 : 2; /* [7:6] reserve */ + uint32_t NMATCH : 8; /* [15:8 ] r/w */ + uint32_t WUMF_MSK : 1; /* [16] r/w */ + uint32_t WTOF_MSK : 1; /* [17] r/w */ + uint32_t RSVD_31_18 :14; /* [31:18] */ + } CAN_CTRL1_PN; + + /* 0xB04*/ + struct { + uint32_t MATCHTO :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] reserve */ + } CAN_CTRL2_PN; + + /* 0xB08*/ + struct { + uint32_t RSVD_7_0 : 8; /* [7:0] reserve */ + uint32_t MCOUNTER : 8; /* [15:8] read only */ + uint32_t WUMF : 1; /* [16] r/w1c */ + uint32_t WTOF : 1; /* [17] r/w1c */ + uint32_t RSVD_31_18 :14; /* [31:18] reserve */ + } CAN_WU_MTC; + + /* 0xB0C*/ + struct { + uint32_t FLT_ID1 :29; /* [28:0] r/w */ + uint32_t FLT_RTR : 1; /* [29] r/w */ + uint32_t FLT_IDE : 1; /* [30] r/w */ + uint32_t RSVD_31 : 1; /* [31] reserve */ + } CAN_FLT_ID1; + + /* 0xB10*/ + struct { + uint32_t FLT_DLC_HI : 4; /* [3:0] */ + uint32_t RSVD_15_4 :12; /* [15:4] reserve */ + uint32_t FLT_DLC_LO : 4; /* [19:16] r/w */ + uint32_t RSVD_31_20 :12; /* [31:20] reserve */ + } CAN_FLT_DLC; + + /* 0xB14*/ + struct { + uint32_t DATA_BYTE_3 : 8; /* [7:0] r/w */ + uint32_t DATA_BYTE_2 : 8; /* [15:8] r/w */ + uint32_t DATA_BYTE_1 : 8; /* [23:16] r/w */ + uint32_t DATA_BYTE_0 : 8; /* [31:24] r/w */ + } CAN_PL1_LO; + + /* 0xB18*/ + struct { + uint32_t DATA_BYTE_7 : 8; /* [7:0] r/w */ + uint32_t DATA_BYTE_6 : 8; /* [15:8] r/w */ + uint32_t DATA_BYTE_5 : 8; /* [23:16] r/w */ + uint32_t DATA_BYTE_4 : 8; /* [31:24] r/w */ + } CAN_PL1_HI; + + /* 0xB1C*/ + struct { + uint32_t FLT_ID2_IDMASK :29; /* [28:0] r/w */ + uint32_t RTR_MSK : 1; /* [29] r/w */ + uint32_t IDE_MSK : 1; /* [30] r/w */ + uint32_t RSVD_31 : 1; /* [31] reserve */ + } CAN_FLT_ID2_IDMASK; + + /* 0xB20*/ + struct { + uint32_t DATA_BYTE_3 : 8; /* [7:0] r/w */ + uint32_t DATA_BYTE_2 : 8; /* [15:8] r/w */ + uint32_t DATA_BYTE_1 : 8; /* [23:16] r/w */ + uint32_t DATA_BYTE_0 : 8; /* [31:24] r/w */ + } CAN_PL2_PLMASK_LO; + + /* 0xB24*/ + struct { + uint32_t DATA_BYTE_7 : 8; /* [7:0] r/w */ + uint32_t DATA_BYTE_6 : 8; /* [15:8] r/w */ + uint32_t DATA_BYTE_5 : 8; /* [23:16] r/w */ + uint32_t DATA_BYTE_4 : 8; /* [31:24] r/w */ + } CAN_PL2_PLMASK_HI; + + uint8_t zResverd0x0B28[24]; /*pad 0x0B28 - 0B3F*/ + + struct { + /* 0xB40*/ + struct { + uint32_t RSVD_15_0 :16; /* [15:0] reserve */ + uint32_t DLC : 4; /* [19:16] read only */ + uint32_t RTR : 1; /* [20] read only */ + uint32_t IDE : 1; /* [21] read only */ + uint32_t SRR : 1; /* [22] read only */ + uint32_t RSVD_31_23 : 9; /* [31:23] reserve */ + } CS; + + /* 0xB44*/ + struct { + uint32_t ID :29; /* [28:0] read only */ + uint32_t RSVD_31_29 : 3; /* [31:29] reserve */ + } ID; + + /* 0xB48*/ + struct { + uint32_t DATA_BYTE_3 : 8; /* [7:0] read only */ + uint32_t DATA_BYTE_2 : 8; /* [15:8] read only */ + uint32_t DATA_BYTE_1 : 8; /* [23:16] read only */ + uint32_t DATA_BYTE_0 : 8; /* [31:24] read only */ + } D03; + + /* 0xB4C*/ + struct { + uint32_t DATA_BYTE_7 : 8; /* [7:0] read only */ + uint32_t DATA_BYTE_6 : 8; /* [15:8] read only */ + uint32_t DATA_BYTE_5 : 8; /* [23:16] read only */ + uint32_t DATA_BYTE_4 : 8; /* [31:24] read only */ + } D47; + } CAN_WMB[4]; + + uint8_t zResverd0x0B80[0x80]; /*pad 0x0B80 - 0BFF*/ + + /* 0xC00*/ + struct { + uint32_t TDCVAL : 6; /* [5:0] read only */ + uint32_t RSVD_7_6 : 2; /* [7:6] reserve */ + uint32_t TDCOFF : 5; /* [12:8] r/w */ + uint32_t RSVD_13 : 1; /* [13] reserve */ + uint32_t TDCFAIL : 1; /* [14] r/w1c */ + uint32_t TDCEN : 1; /* [15] r/w */ + uint32_t MBDSR0 : 2; /* [17:16] r/w */ + uint32_t RSVD_18 : 1; /* [18] reserve */ + uint32_t MBDSR1 : 2; /* [20:19] r/w */ + uint32_t RSVD_21 : 1; /* [21] reserve */ + uint32_t MBDSR2 : 2; /* [23:22] r/w */ + uint32_t RSVD_24 : 1; /* [24] reserve */ + uint32_t MBDSR3 : 2; /* [26:25] r/w */ + uint32_t RSVD_30_27 : 4; /* [30:27] reserve */ + uint32_t FD_RATE : 1; /* [31] r/w */ + } CAN_FDCTRL; + + /* 0xC04*/ + struct { + uint32_t FPSEG2 : 3; /* [2:0] r/w */ + uint32_t RSVD_4_3 : 2; /* [4:3] reserve */ + uint32_t FPSEG1 : 3; /* [7:5] r/w */ + uint32_t RSVD_9_8 : 2; /* [9:8] reserve */ + uint32_t FPROPSEG : 5; /* [14:10] r/w */ + uint32_t RSVD_15 : 1; /* [15] reserve */ + uint32_t FRJW : 3; /* [18:16] r/w */ + uint32_t RSVD_19 : 1; /* [19] reserve */ + uint32_t FPRESDIV :10; /* [29:20] r/w */ + uint32_t RSVD_31_30 : 2; /* [31:30] reserve */ + } CAN_FDCBT; + + /* 0xC08*/ + struct { + uint32_t FD_TXCRC :21; /* [20:0] read only */ + uint32_t RSVD_23_21 : 3; /* [23:21] reserve */ + uint32_t FD_MBCRC : 7; /* [30:24] read only */ + uint32_t RSVD_31 : 1; /* [31] reserve */ + } CAN_FDCRC; + +}; /*can_reg*/ + +struct can_reg_w { + /* 0x00*/ + uint32_t CAN_MCR; + /* 0x04*/ + uint32_t CAN_CTRL1; + /* 0x08*/ + uint32_t CAN_TIMER; + uint8_t zResverd0x0C[4]; /*pad 0x0C - 0F*/ + + /* 0x10*/ + uint32_t CAN_RXMGMSK; + /* 0x14*/ + uint32_t CAN_RX14MASK; + /* 0x18*/ + uint32_t CAN_RX15MASK; + /* 0x1c*/ + uint32_t CAN_ECR; + /* 0x20*/ + uint32_t CAN_ESR1; + /* 0x24*/ + uint32_t CAN_IMASK2; + /* 0x28*/ + uint32_t CAN_IMASK1; + /* 0x2c*/ + uint32_t CAN_IFLAG2; + /* 0x30*/ + uint32_t CAN_IFLAG1; + /* 0x34*/ + uint32_t CAN_CTRL2; + /* 0x38*/ + uint32_t CAN_ESR2; + uint8_t zResverd0x03C[8]; /*pad 0x03C - 043*/ + + /* 0x44*/ + uint32_t CAN_CRCR; + /* 0x48*/ + uint32_t CAN_RXFGMASK; + /* 0x4c*/ + uint32_t CAN_RXFIR; + /* 0x50*/ + uint32_t CAN_CBT; + uint8_t zResverd0x054[20]; /*pad 0x054 - 067*/ + + /* 0x68*/ + uint32_t CAN_IMASK4; + /* 0x6c*/ + uint32_t CAN_IMASK3; + /* 0x70*/ + uint32_t CAN_IFLAG4; + /* 0x74*/ + uint32_t CAN_IFLAG3; + uint8_t zResverd0x078[8]; /*pad 0x078 - 07F*/ + + struct { + /* 0x80 */ + uint32_t MB0; + /* 0x84*/ + uint32_t MB1; + /* 0x88*/ + uint32_t MB2; + /* 0x8c*/ + uint32_t MB3; + } CAN_MB[64]; + uint8_t zResverd0x0480[0x400]; /*pad 0x0480 - 087F*/ + + /* 0x880*/ + uint32_t CAN_RXIMR[64]; + uint8_t zResverd0x0A80[352]; /*pad 0x0A80 - 0ADF, 64*4 + 96*/ + + /* 0xAE0*/ + uint32_t CAN_MECR; + /* 0xAE4*/ + uint32_t CAN_ERRIAR; + /* 0xAE8*/ + uint32_t CAN_ERRIDPR; + /* 0xAEC*/ + uint32_t CAN_ERRIPPR; + /* 0xAF0*/ + uint32_t CAN_RERRAR; + /* 0xAF4*/ + uint32_t CAN_RERRDR; + /* 0xAF8*/ + uint32_t CAN_RERRSYNR; + /* 0xAFC*/ + uint32_t CAN_ERRSR; + /* 0xB00*/ + uint32_t CAN_CTRL1_PN; + /* 0xB04*/ + uint32_t CAN_CTRL2_PN; + /* 0xB08*/ + uint32_t CAN_WU_MTC; + /* 0xB0C*/ + uint32_t CAN_FLT_ID1; + /* 0xB10*/ + uint32_t CAN_FLT_DLC; + /* 0xB14*/ + uint32_t CAN_PL1_LO; + /* 0xB18*/ + uint32_t CAN_PL1_HI; + /* 0xB1C*/ + uint32_t CAN_FLT_ID2_IDMASK; + /* 0xB20*/ + uint32_t CAN_PL2_PLMASK_LO; + /* 0xB24*/ + uint32_t CAN_PL2_PLMASK_HI; + + uint8_t zResverd0x0B28[24]; /*pad 0x0B28 - 0B3F*/ + struct { + /* 0xB40*/ + uint32_t CS; + /* 0xB44*/ + uint32_t ID; + /* 0xB48*/ + uint32_t D03; + /* 0xB4C*/ + uint32_t D47; + } CAN_WMB[4]; + + uint8_t zResverd0x0B80[0x80]; /*pad 0x0B80 - 0BFF*/ + + /* 0xC00*/ + uint32_t CAN_FDCTRL; + /* 0xC04*/ + uint32_t CAN_FDCBT; + /* 0xC08*/ + uint32_t CAN_FDCRC; +}; /*can_reg*/ + +typedef volatile struct can_reg can_reg_t; +typedef volatile struct can_reg_w can_reg_w_t; + +struct cmp_reg { + /* 0x0*/ + struct { + uint32_t VERID :32; /* [31:0] ro */ + } CMP_VERID; + + /* 0x4*/ + struct { + uint32_t DAC_RES : 4; /* [3:0] ro */ + uint32_t RSVD_31_4 :28; /* [31:4] */ + } CMP_PARAM; + + /* 0x8*/ + struct { + uint32_t CMP_SEL : 1; /* [0] r/w */ + uint32_t CMP_EN : 1; /* [1] r/w */ + uint32_t SOC_TRG_EN : 1; /* [2] r/w */ + uint32_t STOP_EN : 1; /* [3] r/w */ + uint32_t RSVD_31_4 :28; /* [31:4] */ + } CMP_CCR0; + + /* 0xC*/ + struct { + uint32_t WINDOW_EN : 1; /* [0] r/w */ + uint32_t SAMPLE_EN : 1; /* [1] r/w */ + uint32_t DMA_EN : 1; /* [2] r/w */ + uint32_t COUT_INV : 1; /* [3] r/w */ + uint32_t COUT_SEL : 1; /* [4] r/w */ + uint32_t COUT_PEN : 1; /* [5] r/w */ + uint32_t COUT_OWE : 1; /* [6] r/w */ + uint32_t COUT_OW : 1; /* [7] r/w */ + uint32_t RSVD_15_8 : 8; /* [15:8] */ + uint32_t FILT_CNT : 3; /* [18:16] r/w */ + uint32_t RSVD_23_19 : 5; /* [23:19] */ + uint32_t FILT_PER : 8; /* [31:24] r/w */ + } CMP_CCR1; + + /* 0x10*/ + struct { + uint32_t HS_HSTCTR : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] */ + uint32_t LS_HSTCTR : 2; /* [5:4] r/w */ + uint32_t RSVD_15_6 :10; /* [15:6] */ + uint32_t HS_PSEL : 4; /* [19:16] r/w */ + uint32_t HS_MSEL : 4; /* [23:20] r/w */ + uint32_t LS_PSEL : 4; /* [27:24] r/w */ + uint32_t LS_MSEL : 4; /* [31:28] r/w */ + } CMP_CCR2; + + /* 0x14*/ + struct { + uint32_t DAC_EN : 1; /* [0] r/w */ + uint32_t RSVD_1 : 1; /* [1] */ + uint32_t RSVD_7_2 : 6; /* [7:2] */ + uint32_t VREF_SEL : 1; /* [8] r/w */ + uint32_t RSVD_15_9 : 7; /* [15:9] */ + uint32_t DAC_SEL : 8; /* [23:16] r/w */ + uint32_t RSVD_31_24 : 8; /* [31:24] */ + } CMP_DCR; + + /* 0x18*/ + struct { + uint32_t CFR_IE : 1; /* [0] r/w */ + uint32_t CFF_IE : 1; /* [1] r/w */ + uint32_t RSVD_31_2 :30; /* [31:2] */ + } CMP_IER; + + /* 0x1C*/ + struct { + uint32_t CFR : 1; /* [0] r/w1c */ + uint32_t CFF : 1; /* [1] r/w1c */ + uint32_t RSVD_7_2 : 6; /* [7:2] */ + uint32_t COUT : 1; /* [8] ro */ + uint32_t RSVD_31_9 :23; /* [31:9] */ + } CMP_CSR; + +}; /*cmp_reg*/ + +struct cmp_reg_w { + /* 0x0*/ + uint32_t CMP_VERID; + /* 0x4*/ + uint32_t CMP_PARAM; + /* 0x8*/ + uint32_t CMP_CCR0; + /* 0xC*/ + uint32_t CMP_CCR1; + /* 0x10*/ + uint32_t CMP_CCR2; + /* 0x14*/ + uint32_t CMP_DCR; + /* 0x18*/ + uint32_t CMP_IER; + /* 0x1C*/ + uint32_t CMP_CSR; +}; /*cmp_reg*/ + +typedef volatile struct cmp_reg cmp_reg_t; +typedef volatile struct cmp_reg_w cmp_reg_w_t; + +struct crc_reg { + /* 0x0*/ + struct { + uint32_t FEATURE :16; /* [15:0] r */ + uint32_t MINOR : 8; /* [23:16] r */ + uint32_t MAJOR : 8; /* [31:24] r */ + } CRC_VERID; + + /* 0x4*/ + struct { + uint32_t RSVD_31_0 :32; /* [31:0] r */ + } CRC_PARAM; + + /* 0x8*/ + struct { + uint32_t BYTE0 : 8; /* [7:0] r/w */ + uint32_t BYTE1 : 8; /* [15:8] r/w */ + uint32_t BYTE2 : 8; /* [23:16] r/w */ + uint32_t BYTE3 : 8; /* [31:24] r/w */ + } CRC_DATA; + + /* 0xC*/ + struct { + uint32_t LPHW :16; /* [15:0] r/w */ + uint32_t HPHW :16; /* [31:16] r/w */ + } CRC_POLY; + + /* 0x10*/ + struct { + uint32_t MODE : 1; /* [0] r/w */ + uint32_t WS : 1; /* [1] r/w */ + uint32_t CR : 1; /* [2] r/w */ + uint32_t RSVD_3 : 1; /* [3] r */ + uint32_t RT : 2; /* [5:4] r/w */ + uint32_t WT : 2; /* [7:6] r/w */ + uint32_t RSVD_31_8 :24; /* [31:8] r */ + } CRC_CTRL; + +}; /*crc_reg*/ + +struct crc_reg_w { + /* 0x0*/ + uint32_t CRC_VERID; + /* 0x4*/ + uint32_t CRC_PARAM; + /* 0x8*/ + uint32_t CRC_DATA; + /* 0xC*/ + uint32_t CRC_POLY; + /* 0x10*/ + uint32_t CRC_CTRL; +}; /*crc_reg*/ + +typedef volatile struct crc_reg crc_reg_t; +typedef volatile struct crc_reg_w crc_reg_w_t; + +struct dma_chmux_reg { + /* 0x00*/ + struct { + uint32_t ENABLE : 1; /* [0] r/w */ + uint32_t SRC_MUX : 6; /* [6:1] r/w */ + uint32_t RSVD_31_7 :25; /* [31:7] reserve */ + } DMA_MUX_CH_CFG[16]; + +}; /*dma_chmux_reg*/ + +struct dma_chmux_reg_w { + /* 0x00*/ + uint32_t DMA_MUX_CH_CFG[16]; +}; /*dma_chmux_reg*/ + +typedef volatile struct dma_chmux_reg dma_chmux_reg_t; +typedef volatile struct dma_chmux_reg_w dma_chmux_reg_w_t; + +struct dma_reg { + /* 0x00*/ + struct { + uint32_t HALT : 1; /* [0] r/w */ + uint32_t HOEE : 1; /* [1] r/w */ + uint32_t RRCAE : 1; /* [2] r/w */ + uint32_t DBGE : 1; /* [3] r/w */ + uint32_t RSVD_5_4 : 2; /* [5:4] */ + uint32_t BUSY : 1; /* [6] r/o */ + uint32_t RSVD_31_7 :25; /* [31:7] */ + } DMA_CONF; + + /* 0x04*/ + struct { + uint32_t DMAE0 : 1; /* [0] r/w */ + uint32_t DMAE1 : 1; /* [1] r/w */ + uint32_t DMAE2 : 1; /* [2] r/w */ + uint32_t DMAE3 : 1; /* [3] r/w */ + uint32_t DMAE4 : 1; /* [4] r/w */ + uint32_t DMAE5 : 1; /* [5] r/w */ + uint32_t DMAE6 : 1; /* [6] r/w */ + uint32_t DMAE7 : 1; /* [7] r/w */ + uint32_t DMAE8 : 1; /* [8] r/w */ + uint32_t DMAE9 : 1; /* [9] r/w */ + uint32_t DMAE10 : 1; /* [10] r/w */ + uint32_t DMAE11 : 1; /* [11] r/w */ + uint32_t DMAE12 : 1; /* [12] r/w */ + uint32_t DMAE13 : 1; /* [13] r/w */ + uint32_t DMAE14 : 1; /* [14] r/w */ + uint32_t DMAE15 : 1; /* [15] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } DMA_DMAE; + + uint8_t zResverd0x08[4]; /*pad 0x08 - 0B*/ + + /* 0x0C*/ + struct { + uint32_t EIE0 : 1; /* [0] r/w */ + uint32_t EIE1 : 1; /* [1] r/w */ + uint32_t EIE2 : 1; /* [2] r/w */ + uint32_t EIE3 : 1; /* [3] r/w */ + uint32_t EIE4 : 1; /* [4] r/w */ + uint32_t EIE5 : 1; /* [5] r/w */ + uint32_t EIE6 : 1; /* [6] r/w */ + uint32_t EIE7 : 1; /* [7] r/w */ + uint32_t EIE8 : 1; /* [8] r/w */ + uint32_t EIE9 : 1; /* [9] r/w */ + uint32_t EIE10 : 1; /* [10] r/w */ + uint32_t EIE11 : 1; /* [11] r/w */ + uint32_t EIE12 : 1; /* [12] r/w */ + uint32_t EIE13 : 1; /* [13] r/w */ + uint32_t EIE14 : 1; /* [14] r/w */ + uint32_t EIE15 : 1; /* [15] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } DMA_EIE; + + uint8_t zResverd0x010[4]; /*pad 0x010 - 013*/ + + /* 0x14*/ + struct { + uint32_t CCDONE : 4; /* [3:0] w/o */ + uint32_t RSVD_5_4 : 2; /* [5:4] */ + uint32_t CACDONE : 1; /* [6] w/o */ + uint32_t WPEN0 : 1; /* [7] w/o */ + uint32_t SCSTART : 4; /* [11:8] w/o */ + uint32_t RSVD_13_12 : 2; /* [13:12] */ + uint32_t SACSTART : 1; /* [14] w/o */ + uint32_t WPEN1 : 1; /* [15] w/o */ + uint32_t CCES : 4; /* [19:16] w/o */ + uint32_t RSVD_21_20 : 2; /* [21:20] */ + uint32_t CACES : 1; /* [22] w/o */ + uint32_t WPEN2 : 1; /* [23] w/o */ + uint32_t CCIS : 4; /* [27:24] w/o */ + uint32_t RSVD_29_28 : 2; /* [29:28] */ + uint32_t CACIS : 1; /* [30] w/o */ + uint32_t WPEN3 : 1; /* [31] w/o */ + } DMA_GCC; + + /* 0x18*/ + struct { + uint32_t DBEF : 1; /* [0] r/o */ + uint32_t SBEF : 1; /* [1] r/o */ + uint32_t RSVD_2 : 1; /* [2] */ + uint32_t NUMEF : 1; /* [3] r/o */ + uint32_t DOEF : 1; /* [4] r/o */ + uint32_t DAEF : 1; /* [5] r/o */ + uint32_t SOEF : 1; /* [6] r/o */ + uint32_t SAEF : 1; /* [7] r/o */ + uint32_t CHEF : 4; /* [11:8] r/o */ + uint32_t RSVD_12 : 1; /* [12] */ + uint32_t PRIEF : 1; /* [13] r/o */ + uint32_t RSVD_14 : 1; /* [14] */ + uint32_t ERRF : 1; /* [15] r/o */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } DMA_ES; + + /* 0x1C*/ + struct { + uint32_t ERR0 : 1; /* [0] r/o */ + uint32_t ERR1 : 1; /* [1] r/o */ + uint32_t ERR2 : 1; /* [2] r/o */ + uint32_t ERR3 : 1; /* [3] r/o */ + uint32_t ERR4 : 1; /* [4] r/o */ + uint32_t ERR5 : 1; /* [5] r/o */ + uint32_t ERR6 : 1; /* [6] r/o */ + uint32_t ERR7 : 1; /* [7] r/o */ + uint32_t ERR8 : 1; /* [8] r/o */ + uint32_t ERR9 : 1; /* [9] r/o */ + uint32_t ERR10 : 1; /* [10] r/o */ + uint32_t ERR11 : 1; /* [11] r/o */ + uint32_t ERR12 : 1; /* [12] r/o */ + uint32_t ERR13 : 1; /* [13] r/o */ + uint32_t ERR14 : 1; /* [14] r/o */ + uint32_t ERR15 : 1; /* [15] r/o */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } DMA_CES; + + /* 0x20*/ + struct { + uint32_t INT0 : 1; /* [0] r/o */ + uint32_t INT1 : 1; /* [1] r/o */ + uint32_t INT2 : 1; /* [2] r/o */ + uint32_t INT3 : 1; /* [3] r/o */ + uint32_t INT4 : 1; /* [4] r/o */ + uint32_t INT5 : 1; /* [5] r/o */ + uint32_t INT6 : 1; /* [6] r/o */ + uint32_t INT7 : 1; /* [7] r/o */ + uint32_t INT8 : 1; /* [8] r/o */ + uint32_t INT9 : 1; /* [9] r/o */ + uint32_t INT10 : 1; /* [10] r/o */ + uint32_t INT11 : 1; /* [11] r/o */ + uint32_t INT12 : 1; /* [12] r/o */ + uint32_t INT13 : 1; /* [13] r/o */ + uint32_t INT14 : 1; /* [14] r/o */ + uint32_t INT15 : 1; /* [15] r/o */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } DMA_CIS; + + /* 0x24*/ + struct { + uint32_t HRS0 : 1; /* [0] r/o */ + uint32_t HRS1 : 1; /* [1] r/o */ + uint32_t HRS2 : 1; /* [2] r/o */ + uint32_t HRS3 : 1; /* [3] r/o */ + uint32_t HRS4 : 1; /* [4] r/o */ + uint32_t HRS5 : 1; /* [5] r/o */ + uint32_t HRS6 : 1; /* [6] r/o */ + uint32_t HRS7 : 1; /* [7] r/o */ + uint32_t HRS8 : 1; /* [8] r/o */ + uint32_t HRS9 : 1; /* [9] r/o */ + uint32_t HRS10 : 1; /* [10] r/o */ + uint32_t HRS11 : 1; /* [11] r/o */ + uint32_t HRS12 : 1; /* [12] r/o */ + uint32_t HRS13 : 1; /* [13] r/o */ + uint32_t HRS14 : 1; /* [14] r/o */ + uint32_t HRS15 : 1; /* [15] r/o */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } DMA_CHRS; + + /* 0x28*/ + struct { + uint32_t CPRI3 : 4; /* [3:0] r/w */ + uint32_t RSVD_5_4 : 2; /* [5:4] */ + uint32_t CPDIS3 : 1; /* [6] r/w */ + uint32_t CSE3 : 1; /* [7] r/w */ + uint32_t CPRI2 : 4; /* [11:8] r/w */ + uint32_t RSVD_13_12 : 2; /* [13:12] */ + uint32_t CPDIS2 : 1; /* [14] r/w */ + uint32_t CSE2 : 1; /* [15] r/w */ + uint32_t CPRI1 : 4; /* [19:16] r/w */ + uint32_t RSVD_21_20 : 2; /* [21:20] */ + uint32_t CPDIS1 : 1; /* [22] r/w */ + uint32_t CSE1 : 1; /* [23] r/w */ + uint32_t CPRI0 : 4; /* [27:24] r/w */ + uint32_t RSVD_29_28 : 2; /* [29:28] */ + uint32_t CPDIS0 : 1; /* [30] r/w */ + uint32_t CSE0 : 1; /* [31] r/w */ + } DMA_CPRI0; + + /* 0x2C*/ + struct { + uint32_t CPRI7 : 4; /* [3:0] r/w */ + uint32_t RSVD_5_4 : 2; /* [5:4] */ + uint32_t CPDIS7 : 1; /* [6] r/w */ + uint32_t CSE7 : 1; /* [7] r/w */ + uint32_t CPRI6 : 4; /* [11:8] r/w */ + uint32_t RSVD_13_12 : 2; /* [13:12] */ + uint32_t CPDIS6 : 1; /* [14] r/w */ + uint32_t CSE6 : 1; /* [15] r/w */ + uint32_t CPRI5 : 4; /* [19:16] r/w */ + uint32_t RSVD_21_20 : 2; /* [21:20] */ + uint32_t CPDIS5 : 1; /* [22] r/w */ + uint32_t CSE5 : 1; /* [23] r/w */ + uint32_t CPRI4 : 4; /* [27:24] r/w */ + uint32_t RSVD_29_28 : 2; /* [29:28] */ + uint32_t CPDIS4 : 1; /* [30] r/w */ + uint32_t CSE4 : 1; /* [31] r/w */ + } DMA_CPRI1; + + /* 0x30*/ + struct { + uint32_t CPRI11 : 4; /* [3:0] r/w */ + uint32_t RSVD_5_4 : 2; /* [5:4] */ + uint32_t CPDIS11 : 1; /* [6] r/w */ + uint32_t CSE11 : 1; /* [7] r/w */ + uint32_t CPRI10 : 4; /* [11:8] r/w */ + uint32_t RSVD_13_12 : 2; /* [13:12] */ + uint32_t CPDIS10 : 1; /* [14] r/w */ + uint32_t CSE10 : 1; /* [15] r/w */ + uint32_t CPRI9 : 4; /* [19:16] r/w */ + uint32_t RSVD_21_20 : 2; /* [21:20] */ + uint32_t CPDIS9 : 1; /* [22] r/w */ + uint32_t CSE9 : 1; /* [23] r/w */ + uint32_t CPRI8 : 4; /* [27:24] r/w */ + uint32_t RSVD_29_28 : 2; /* [29:28] */ + uint32_t CPDIS8 : 1; /* [30] r/w */ + uint32_t CSE8 : 1; /* [31] r/w */ + } DMA_CPRI2; + + /* 0x34*/ + struct { + uint32_t CPRI15 : 4; /* [3:0] r/w */ + uint32_t RSVD_5_4 : 2; /* [5:4] */ + uint32_t CPDIS15 : 1; /* [6] r/w */ + uint32_t CSE15 : 1; /* [7] r/w */ + uint32_t CPRI14 : 4; /* [11:8] r/w */ + uint32_t RSVD_13_12 : 2; /* [13:12] */ + uint32_t CPDIS14 : 1; /* [14] r/w */ + uint32_t CSE14 : 1; /* [15] r/w */ + uint32_t CPRI13 : 4; /* [19:16] r/w */ + uint32_t RSVD_21_20 : 2; /* [21:20] */ + uint32_t CPDIS13 : 1; /* [22] r/w */ + uint32_t CSE13 : 1; /* [23] r/w */ + uint32_t CPRI12 : 4; /* [27:24] r/w */ + uint32_t RSVD_29_28 : 2; /* [29:28] */ + uint32_t CPDIS12 : 1; /* [30] r/w */ + uint32_t CSE12 : 1; /* [31] r/w */ + } DMA_CPRI3; + + uint8_t zResverd0x038[456]; /*pad 0x038 - 01FF*/ + + struct { + /* 0x200*/ + struct { + uint32_t SADDR : 32; /* [31:0] r/w */ + } DMA_SADDR; + + /* 0x204*/ + struct { + uint32_t DADDR : 32; /* [31:0] r/w */ + } DMA_DADDR; + + /* 0x208*/ + struct { + int32_t SAOFF : 16; /* [15:0] r/w */ + int32_t DAOFF : 16; /* [31:16] r/w */ + } DMA_AOFF; + + /* 0x20C*/ + struct { + int32_t MLSAOFF : 16; /* [15:0] r/w */ + int32_t MLDAOFF : 16; /* [31:16] r/w */ + } DMA_MLAOFF; + + /* 0x210*/ + struct { + uint32_t NUM : 32; /* [31:0] r/w */ + } DMA_NUM; + + /* 0x214*/ + struct { + uint32_t MLITER : 15; /* [14:0] r/w */ + uint32_t RSVD_15: 1 ; /* [15] */ + uint32_t MLSTA : 15; /* [30:16] r/o */ + uint32_t RSVD_31: 1 ; /* [31] */ + } DMA_ITER; + + /* 0x218*/ + struct { + uint32_t START : 1; /* [0] r/w */ + uint32_t INTE : 1; /* [1] r/w */ + uint32_t RSVD_2 : 1; /* [2] */ + uint32_t REQDIS : 1; /* [3] r/w */ + uint32_t RSVD_5_4 : 2; /* [5:4] */ + uint32_t BUSY : 1; /* [6] r/o */ + uint32_t DONE : 1; /* [7] r/w */ + uint32_t RSVD_15_8 : 8; /* [15:8] */ + uint32_t DSIZE : 2; /* [17:16] r/w */ + uint32_t RSVD_23_18 : 6; /* [23:18] */ + uint32_t SSIZE : 2; /* [25:24] r/w */ + uint32_t RSVD_31_26 : 6; /* [31:26] */ + } DMA_CS; + + uint8_t zResverd[4]; /*pad 4 bytes*/ + }DMA_CH_CONFIG[16]; +}; /*dma_reg*/ + +struct dma_reg_w { + /* 0x00*/ + uint32_t DMA_CONF; + /* 0x04*/ + uint32_t DMA_DMAE; + uint8_t zResverd0x08[4]; /*pad 0x08 - 0B*/ + + /* 0x0C*/ + uint32_t DMA_EIE; + uint8_t zResverd0x010[4]; /*pad 0x010 - 013*/ + + /* 0x14*/ + uint32_t DMA_GCC; + /* 0x18*/ + uint32_t DMA_ES; + /* 0x1C*/ + uint32_t DMA_CES; + /* 0x20*/ + uint32_t DMA_CIS; + /* 0x24*/ + uint32_t DMA_CHRS; + /* 0x28*/ + uint32_t DMA_CPRI0; + /* 0x2C*/ + uint32_t DMA_CPRI1; + /* 0x30*/ + uint32_t DMA_CPRI2; + /* 0x34*/ + uint32_t DMA_CPRI3; + uint8_t zResverd0x038[456]; /*pad 0x038 - 01FF*/ + + struct { + /* 0x200*/ + uint32_t DMA_SADDR; + /* 0x204*/ + uint32_t DMA_DADDR; + /* 0x208*/ + uint32_t DMA_AOFF; + /* 0x20C*/ + uint32_t DMA_MLAOFF; + /* 0x210*/ + uint32_t DMA_NUM; + /* 0x214*/ + uint32_t DMA_ITER; + /* 0x218*/ + uint32_t DMA_CS; + + uint8_t zResverd[4]; /*pad 4 bytes*/ + } DMA_CH_CONFIG[16]; +}; /*dma_reg*/ + +typedef volatile struct dma_reg dma_reg_t; +typedef volatile struct dma_reg_w dma_reg_w_t; + +struct ewdt_reg { + /* 0x0*/ + struct { + uint32_t MINOR : 4; /* [3:0] ro */ + uint32_t MAJOR : 4; /* [7:4] ro */ + uint32_t RSVD_31_8 :24; /* [31:8] ro */ + } EWDT_VERID; + + /* 0x4*/ + struct { + uint32_t RSVD_31_0 :32; /* [31:0] ro */ + } EWDT_PARAM; + + /* 0x8*/ + struct { + uint32_t EWDTE : 1; /* [0] r/w */ + uint32_t DEBUGE : 1; /* [1] r/w */ + uint32_t WAITE : 1; /* [2] r/w */ + uint32_t RSVD_3 : 1; /* [3] ro */ + uint32_t INTE : 1; /* [4] r/w */ + uint32_t INPE : 1; /* [5] r/w */ + uint32_t INPP : 1; /* [6] r/w */ + uint32_t RSVD_23_7 :17; /* [23:7] */ + uint32_t INTF : 1; /* [24] w1c */ + uint32_t RSVD_31_25 : 7; /* [31:25] ro */ + } EWDT_CS; + + /* 0xC*/ + struct { + uint32_t COMPH :32; /* [31:0] r/w */ + } EWDT_COMPH; + + /* 0x10*/ + struct { + uint32_t COMPL :32; /* [31:0] r/w */ + } EWDT_COMPL; + + /* 0x14*/ + struct { + uint32_t CNT :32; /* [31:0] r/w */ + } EWDT_CNT; + +}; /*ewdt_reg*/ + +struct ewdt_reg_w { + /* 0x0*/ + uint32_t EWDT_VERID; + /* 0x4*/ + uint32_t EWDT_PARAM; + /* 0x8*/ + uint32_t EWDT_CS; + /* 0xC*/ + uint32_t EWDT_COMPH; + /* 0x10*/ + uint32_t EWDT_COMPL; + /* 0x14*/ + uint32_t EWDT_CNT; +}; /*ewdt_reg*/ + +typedef volatile struct ewdt_reg ewdt_reg_t; +typedef volatile struct ewdt_reg_w ewdt_reg_w_t; + +struct flash_reg { + /* 0x0*/ + struct { + uint32_t FAIL : 1; /* [0] r */ + uint32_t RSVD_1 : 1; /* [1] r */ + uint32_t CMDABT : 1; /* [2] r/w1c */ + uint32_t RSVD_4_3 : 2; /* [4:3] r */ + uint32_t ACCERR : 1; /* [5] r/w1c */ + uint32_t PREABT : 1; /* [6] r/w1c */ + uint32_t CCIF : 1; /* [7] r/w1c */ + uint32_t RSVD_10_8 : 3; /* [10:8] r */ + uint32_t CMDWRF : 1; /* [11] r */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t DFDIF : 1; /* [16] r/w1c */ + uint32_t RSVD_29_17 :13; /* [29:17] r */ + uint32_t DBG_ERSALL_DIS : 1; /* [30] r */ + uint32_t FSEC : 1; /* [31] r */ + } FLASH_FSTAT; + + /* 0x4*/ + struct { + uint32_t RSVD_6_0 : 7; /* [6:0] r */ + uint32_t CCIE : 1; /* [7] r/w */ + uint32_t DBG_ERS_FLG : 1; /* [8] r */ + uint32_t RSVD_15_9 : 7; /* [15:9] r */ + uint32_t DFDIE : 1; /* [16] r/w */ + uint32_t RSVD_31_17 :15; /* [31:17] r */ + } FLASH_FCNFG; + + /* 0x8*/ + struct { + uint32_t RWSC : 4; /* [3:0] r/w */ + uint32_t RSVD_7_4 : 4; /* [7:4] r */ + uint32_t LSMODE : 1; /* [8] r/w */ + uint32_t RSVD_15_9 : 7; /* [15:9] r */ + uint32_t FECCF : 1; /* [16] r/w */ + uint32_t RSVD_23_17 : 7; /* [23:17] r */ + uint32_t ABTREQ : 1; /* [24] r */ + uint32_t RSVD_31_25 : 7; /* [31:25] r */ + } FLASH_FCTRL; + + uint8_t zResverd0x0C[4]; /*pad 0x0C - 0F*/ + + /* 0x10*/ + struct { + uint32_t CMDCODE : 8; /* [7:0] r/w */ + uint32_t RSVD_31_8 :24; /* [31:8] r */ + } FLASH_FCMD; + + /* 0x14*/ + uint8_t zResverd0x14[4]; /*pad 0x14 - 0x18*/ + + /* 0x18*/ + struct { + uint32_t CMDADDR :32; /* [31:0] r/w */ + } FLASH_FADDR; + + /* 0x1C*/ + struct { + uint32_t CMDADDRE :32; /* [31:0] r/w */ + } FLASH_FADDR_END; + + /* 0x20*/ + struct { + uint32_t CMDDATA0 :32; /* [31:0] r/w */ + } FLASH_FDATA0; + + /* 0x24*/ + struct { + uint32_t CMDDATA1 :32; /* [31:0] r/w */ + } FLASH_FDATA1; + + /* 0x28*/ + struct { + uint32_t CMDDATA2 :32; /* [31:0] r/w */ + } FLASH_FDATA2; + + /* 0x2C*/ + struct { + uint32_t CMDDATA3 :32; /* [31:0] r/w */ + } FLASH_FDATA3; + +}; /*flash_reg*/ + +struct flash_reg_w { + /* 0x0*/ + uint32_t FLASH_FSTAT; + /* 0x4*/ + uint32_t FLASH_FCNFG; + /* 0x8*/ + uint32_t FLASH_FCTRL; + uint8_t zResverd0x0C[4]; /*pad 0x0C - 0F*/ + + /* 0x10*/ + uint32_t FLASH_FCMD; + /* 0x14*/ + uint8_t zResverd0x14[4]; + /* 0x18*/ + uint32_t FLASH_FADDR; + /* 0x1C*/ + uint32_t FLASH_FADDR_END; + /* 0x20*/ + uint32_t FLASH_FDATA0; + /* 0x24*/ + uint32_t FLASH_FDATA1; + /* 0x28*/ + uint32_t FLASH_FDATA2; + /* 0x2C*/ + uint32_t FLASH_FDATA3; +}; /*flash_reg*/ + +typedef volatile struct flash_reg flash_reg_t; +typedef volatile struct flash_reg_w flash_reg_w_t; + +struct gpio_reg { + /* 0x0*/ + struct { + uint32_t PDO :32; /* [31:0] r/w */ + } GPIOx_PDOR; + + /* 0x4*/ + struct { + uint32_t PSO :32; /* [31:0] wo */ + } GPIOx_PSOR; + + /* 0x8*/ + struct { + uint32_t PCO :32; /* [31:0] wo */ + } GPIOx_PCOR; + + /* 0xC*/ + struct { + uint32_t PTO :32; /* [31:0] wo */ + } GPIOx_PTOR; + + /* 0x10*/ + struct { + uint32_t PDI :32; /* [31:0] ro */ + } GPIOx_PDIR; + + /* 0x14*/ + struct { + uint32_t PDD :32; /* [31:0] r/w */ + } GPIOx_PDDR; + + /* 0x18*/ + struct { + uint32_t RSVD_31_0 :32; /* [31:0] ro */ + } GPIOx_PIDR; + + uint8_t zResverd[36]; /*pad 0x01C - 03F*/ +}; /*gpio_reg*/ + +struct gpio_reg_w { + /* 0x0 */ + uint32_t GPIOx_PDOR; + /* 0x4 */ + uint32_t GPIOx_PSOR; + /* 0x8 */ + uint32_t GPIOx_PCOR; + /* 0xC */ + uint32_t GPIOx_PTOR; + /* 0x10 */ + uint32_t GPIOx_PDIR; + /* 0x14 */ + uint32_t GPIOx_PDDR; + /* 0x18 */ + uint32_t GPIOx_PIDR; + /* 0x1C */ + uint8_t zResverd[36]; +}; /* gpio_reg */ + +typedef volatile struct gpio_reg gpio_reg_t; +typedef volatile struct gpio_reg_w gpio_reg_w_t; + +struct hwdiv_reg { + /* 0x0*/ + struct { + uint32_t VERSION :32; /* [31:0] ro */ + } HWDIV_VERSION; + + /* 0x4*/ + struct { + uint32_t PARAM :32; /* [31:0] ro */ + } HWDIV_PARAM; + + /* 0x8*/ + struct { + uint32_t DIVIDEND :32; /* [31:0] r/w */ + } HWDIV_DEND; + + /* 0xC*/ + struct { + uint32_t DIVISOR :32; /* [31:0] r/w */ + } HWDIV_DSOR; + + /* 0x10*/ + struct { + uint32_t DFS : 1; /* [0] r/w */ + uint32_t USGN : 1; /* [1] r/w */ + uint32_t DZE : 1; /* [2] r/w */ + uint32_t DZ : 1; /* [3] ro */ + uint32_t SQRT : 1; /* [4] ro */ + uint32_t DIV : 1; /* [5] ro */ + uint32_t BUSY : 1; /* [6] ro */ + uint32_t RSVD_31_7 :25; /* [31:7] ro */ + } HWDIV_CSR; + + /* 0x14*/ + struct { + uint32_t STRT : 1; /* [0] w */ + uint32_t RSVD_31_1 :31; /* [31:1] ro */ + } HWDIV_STRT; + + /* 0x18*/ + struct { + uint32_t RESULT :32; /* [31:0] ro */ + } HWDIV_RES; + + /* 0x1C*/ + struct { + uint32_t REMAINDER :32; /* [31:0] ro */ + } HWDIV_REM; + + /* 0x20*/ + struct { + uint32_t RADICAND :32; /* [31:0] r/w */ + } HWDIV_RCND; + +}; /*hwdiv_reg*/ + +struct hwdiv_reg_w { + /* 0x0*/ + uint32_t HWDIV_VERSION; + /* 0x4*/ + uint32_t HWDIV_PARAM; + /* 0x8*/ + uint32_t HWDIV_DEND; + /* 0xC*/ + uint32_t HWDIV_DSOR; + /* 0x10*/ + uint32_t HWDIV_CSR; + /* 0x14*/ + uint32_t HWDIV_STRT; + /* 0x18*/ + uint32_t HWDIV_RES; + /* 0x1C*/ + uint32_t HWDIV_REM; + /* 0x20*/ + uint32_t HWDIV_RCND; +}; /*hwdiv_reg*/ + +typedef volatile struct hwdiv_reg hwdiv_reg_t; +typedef volatile struct hwdiv_reg_w hwdiv_reg_w_t; + +struct i2c_reg { + /* 0x00*/ + struct { + uint32_t RSVD_31_0 :32; /* [31:0] ro */ + } I2C_VERID; + + /* 0x04*/ + struct { + uint32_t I2C_SUPPORT_SPEED : 2; /* [1:0] ro */ + uint32_t DMA_SUPPORT : 1; /* [2] ro */ + uint32_t TXFIFO_DEPTH : 4; /* [6:3] ro */ + uint32_t RXFIFO_DEPTH : 4; /* [10:7] ro */ + uint32_t RSVD_31_11 :21; /* [31:11] ro */ + } I2C_PARAMETER; + + /* 0x08*/ + struct { + uint32_t MODULE_EN : 1; /* [0] r/w */ + uint32_t SLAVE_ACK_GENCALL : 1; /* [1] r/w */ + uint32_t SLAVE_NACK : 1; /* [2] r/w */ + uint32_t SDA_RECOVER_EN : 1; /* [3] r/w */ + uint32_t MASTER_ABORT : 1; /* [4] r/w */ + uint32_t MASTER_BUS_RECOVER_EN : 1; /* [5] r/w */ + uint32_t MASTER_BLK_TXFIFO : 1; /* [6] r/w */ + uint32_t H_MCODE : 3; /* [9:7] r/w */ + uint32_t RSVD_31_10 :22; /* [31:10] ro */ + } I2C_CONFIG0; + + /* 0x0c*/ + struct { + uint32_t SLAVE_MODE_DIS : 1; /* [0] r/w */ + uint32_t MASTER_MODE_EN : 1; /* [1] r/w */ + uint32_t MASTER_RESTART_EN : 1; /* [2] r/w */ + uint32_t SLAVE_STOP_DET_EN : 1; /* [3] r/w */ + uint32_t MASTER_STOP_DET_EN : 1; /* [4] r/w */ + uint32_t TXFIFO_EMPTY_EN : 1; /* [5] r/w */ + uint32_t SPEED_SEL : 2; /* [7:6] r/w */ + uint32_t HOLD_EN_RXFIFO_FULL : 1; /* [8] r/w */ + uint32_t SLAVE_10BIT_ADDR_SEL : 1; /* [9] r/w */ + uint32_t MASTER_10BIT_ADDR_SEL : 1; /* [10] r/w */ + uint32_t RSVD_31_11 :21; /* [31:11] ro */ + } I2C_CONFIG1; + + /* 0x10*/ + struct { + uint32_t SDA_SETUP_TIMING : 8; /* [7:0] r/w */ + uint32_t RSVD_31_8 :24; /* [31:8] ro */ + } I2C_SDA_SETUP_TIMING; + + /* 0x14*/ + struct { + uint32_t SDA_TX_HOLD_TIMING :16; /* [15:0] r/w */ + uint32_t SDA_RX_HOLD_TIMING : 8; /* [23:16] r/w */ + uint32_t RSVD_31_24 : 8; /* [31:24] ro */ + } I2C_SDA_HOLD_TIMING; + + /* 0x18*/ + struct { + uint32_t RXFIFO_DMA_EN : 1; /* [0] r/w */ + uint32_t TXFIFO_DMA_EN : 1; /* [1] r/w */ + uint32_t DMA_TXFIFO_WATERMARK : 2; /* [3:2] r/w */ + uint32_t DMA_RXFIFO_WATERMARK : 2; /* [5:4] r/w */ + uint32_t RSVD_31_6 :26; /* [31:6] ro */ + } I2C_DMA_CTRL; + + /* 0x1c*/ + struct { + uint32_t I2C_CALL_IE : 1; /* [0] r/w */ + uint32_t I2C_TX_OVF_IE : 1; /* [1] r/w */ + uint32_t I2C_ERROR_ABORT_IE : 1; /* [2] r/w */ + uint32_t I2C_ACTIVITY_DET_IE : 1; /* [3] r/w */ + uint32_t I2C_STOP_DET_IE : 1; /* [4] r/w */ + uint32_t I2C_START_DET_IE : 1; /* [5] r/w */ + uint32_t RSVD_21_6 :16; /* [21:6] ro */ + uint32_t SLAVE_RD_REQ_IE : 1; /* [22] r/w */ + uint32_t RX_DONE_IE : 1; /* [23] r/w */ + uint32_t RX_UNDER_IE : 1; /* [24] r/w */ + uint32_t RX_OVF_IE : 1; /* [25] r/w */ + uint32_t RESTART_DET_IE : 1; /* [26] r/w */ + uint32_t SCL_STUCK_AT_LOW_IE : 1; /* [27] r/w */ + uint32_t RSVD_29_28 : 2; /* [29:28] ro */ + uint32_t RX_FULL_IE : 1; /* [30] r/w */ + uint32_t TX_EMPTY_IE : 1; /* [31] r/w */ + } I2C_INT_ENABLE; + + /* 0x20*/ + struct { + uint32_t DATA : 8; /* [7:0] r/w */ + uint32_t CMD_MASTER_DIRECTION : 1; /* [8] wo */ + uint32_t CMD_STOP : 1; /* [9] wo */ + uint32_t CMD_RESTART : 1; /* [10] wo */ + uint32_t RSVD_31_11 :21; /* [31:11] ro */ + } I2C_COMMAND_DATA; + + /* 0x24*/ + struct { + uint32_t DEST_ADDR :10; /* [9:0] r/w */ + uint32_t MASTER_CMD_SEL : 2; /* [11:10] r/w */ + uint32_t RSVD_31_12 :20; /* [31:12] ro */ + } I2C_DEST_ADDR; + + /* 0x28*/ + struct { + uint32_t SLV_ADDR :10; /* [9:0] r/w */ + uint32_t RSVD_31_10 :22; /* [31:10] ro */ + } I2C_SLAVE_ADDR; + + /* 0x2c*/ + struct { + uint32_t STD_SCL_HCNT :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] ro */ + } I2C_STD_SCL_HCNT; + + /* 0x30*/ + struct { + uint32_t STD_SCL_LCNT :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] ro */ + } I2C_STD_SCL_LCNT; + + /* 0x34*/ + struct { + uint32_t FST_SCL_HCNT :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] reserve */ + } I2C_FST_SCL_HCNT; + + /* 0x38*/ + struct { + uint32_t FST_SCL_LCNT :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] ro */ + } I2C_FST_SCL_LCNT; + + /* 0x3c*/ + struct { + uint32_t HS_SCL_HCNT :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] ro */ + } I2C_HS_SCL_HCNT; + + /* 0x40*/ + struct { + uint32_t HS_SCL_LCNT :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] ro */ + } I2C_HS_SCL_LCNT; + + /* 0x44*/ + struct { + uint32_t RXFIFO_WATER_MARK : 2; /* [1:0] r/w */ + uint32_t RSVD_31_2 :30; /* [31:2] ro */ + } I2C_RXFIFO_WATER_MARK; + + /* 0x48*/ + struct { + uint32_t TXFIFO_WATER_MARK : 2; /* [1:0] r/w */ + uint32_t RSVD_31_2 :30; /* [31:2] ro */ + } I2C_TXFIFO_WATER_MARK; + + /* 0x4c*/ + struct { + uint32_t TX_FIFO_CNT : 3; /* [2:0] ro */ + uint32_t RSVD_31_3 :29; /* [31:3] ro */ + } I2C_TX_FIFO_CNT; + + /* 0x50*/ + struct { + uint32_t RX_FIFO_CNT : 3; /* [2:0] ro */ + uint32_t RSVD_31_3 :29; /* [31:3] ro */ + } I2C_RX_FIFO_CNT; + + /* 0x54*/ + struct { + uint32_t FSTD_SPKLEN : 8; /* [7:0] r/w */ + uint32_t RSVD_31_8 :24; /* [31:8] ro */ + } I2C_FSTD_SPKCNT; + + /* 0x58*/ + struct { + uint32_t HS_SPKLEN : 8; /* [7:0] r/w */ + uint32_t RSVD_31_8 :24; /* [31:8] ro */ + } I2C_HS_SPKCNT; + + /* 0x5c*/ + struct { + uint32_t GENERAL_CALL : 1; /* [0] w1c */ + uint32_t TXFIFO_OVERUN : 1; /* [1] w1c */ + uint32_t ERROR_ABORT : 1; /* [2] w1c */ + uint32_t ACTIVITY : 1; /* [3] w1c */ + uint32_t STOP_DETECT : 1; /* [4] w1c */ + uint32_t START_DETECT : 1; /* [5] w1c */ + uint32_t RSVD_21_6 :16; /* [21:6] ro */ + uint32_t SLAVE_READ_REQ : 1; /* [22] w1c */ + uint32_t RXFIFO_DONE : 1; /* [23] w1c */ + uint32_t RXFIFO_UNDERUN : 1; /* [24] w1c */ + uint32_t RXFIFO_OVERUN : 1; /* [25] w1c */ + uint32_t RESTART_DET : 1; /* [26] w1c */ + uint32_t SCL_STUCK_AT_LOW : 1; /* [27] w1c */ + uint32_t RSVD_29_28 : 2; /* [29:28] ro */ + uint32_t RXFIFO_FULL : 1; /* [30] ro */ + uint32_t TXFIFO_EMPTY : 1; /* [31] ro */ + } I2C_STATUS0; + + /* 0x60*/ + struct { + uint32_t MASTER_IS_ACTIVE : 1; /* [0] ro */ + uint32_t SLAVE_IS_ACTIVE : 1; /* [1] ro */ + uint32_t TXFIFO_EMPTY_MASTER_HOLD: 1; /* [2] ro */ + uint32_t TXFIFO_EMPTY_SLAVE_HOLD : 1; /* [3] ro */ + uint32_t RXFIFO_FULL_MASTER_HOLD : 1; /* [4] ro */ + uint32_t RXFIFO_FULL_SLAVE_HOLD : 1; /* [5] ro */ + uint32_t TXFIFO_IS_NOT_FULL : 1; /* [6] ro */ + uint32_t TXFIFO_IS_EMPTY : 1; /* [7] ro */ + uint32_t RXFIFO_IS_NOT_EMPTY : 1; /* [8] ro */ + uint32_t RXFIFO_IS_FULL : 1; /* [9] ro */ + uint32_t SDA_ERR_RECOVER_STUCK_LOW: 1; /* [10] ro */ + uint32_t SLAVE_IS_DISABLED_UNDER_ACT: 1; /* [11] ro */ + uint32_t SLAVE_RX_DATA_DISCARD : 1; /* [12] ro */ + uint32_t I2C_IS_ENABLE : 1; /* [13] ro */ + uint32_t RSVD_31_14 :18; /* [31:14] ro */ + } I2C_STATUS1; + + /* 0x64*/ + struct { + uint32_t ERR_GEN_CALL_NO_ACK : 1; /* [0] ro */ + uint32_t ERR_GEN_CALL_READ : 1; /* [1] ro */ + uint32_t ERR_START_BYTE_ACK_DET : 1; /* [2] ro */ + uint32_t ERR_SBYTE_NORSTRT : 1; /* [3] ro */ + uint32_t ERR_H_NO_RSTRT : 1; /* [4] ro */ + uint32_t ERR_H_MCODE_ACK_DET : 1; /* [5] ro */ + uint32_t ERR_7BIT_ADDR_NO_ACK : 1; /* [6] ro */ + uint32_t ERR_10BIT_ADDR1_NO_ACK : 1; /* [7] ro */ + uint32_t ERR_10BIT_ADDR2_NO_ACK : 1; /* [8] ro */ + uint32_t ERR_10BIT_READ_NO_RSTRT : 1; /* [9] ro */ + uint32_t ERR_DATA_NO_ACK : 1; /* [10] ro */ + uint32_t ERR_MASTER_ABRT : 1; /* [11] ro */ + uint32_t ERR_MASTER_DIS : 1; /* [12] ro */ + uint32_t ERR_SLAVE_ARBLOST : 1; /* [13] ro */ + uint32_t ERR_MASTER_LOST : 1; /* [14] ro */ + uint32_t ERR_SLAVE_READ_REQ : 1; /* [15] ro */ + uint32_t ERR_SLAVE_FLUSH_TXFIFO : 1; /* [16] ro */ + uint32_t ERR_SDA_LOW_TIMEOUT : 1; /* [17] ro */ + uint32_t ERR_TXFIFO_FLUSH_CNT : 3; /* [20:18] ro */ + uint32_t RSVD_31_21 :11; /* [31:21] ro */ + } I2C_ERROR_STATUS; + + /* 0x68*/ + struct { + uint32_t SCL_LOW_TIMEOUT :32; /* [31:0] r/w */ + } I2C_SCL_LOW_TIMEOUT; + + /* 0x6c*/ + struct { + uint32_t SDA_LOW_TIMEOUT :32; /* [31:0] r/w */ + } I2C_SDA_LOW_TIMEOUT; + + /* 0x70*/ + struct { + uint32_t CLR_ERR : 1; /* [0] r */ + uint32_t RSVD_31_1 :31; /* [31:1] ro */ + } I2C_RD_CLR_ERR_STATUS; + +}; /*i2c_reg*/ + +struct i2c_reg_w { + /* 0x00*/ + uint32_t I2C_VERID; + /* 0x04*/ + uint32_t I2C_PARAMETER; + /* 0x08*/ + uint32_t I2C_CONFIG0; + /* 0x0c*/ + uint32_t I2C_CONFIG1; + /* 0x10*/ + uint32_t I2C_SDA_SETUP_TIMING; + /* 0x14*/ + uint32_t I2C_SDA_HOLD_TIMING; + /* 0x18*/ + uint32_t I2C_DMA_CTRL; + /* 0x1c*/ + uint32_t I2C_INT_ENABLE; + /* 0x20*/ + uint32_t I2C_COMMAND_DATA; + /* 0x24*/ + uint32_t I2C_DEST_ADDR; + /* 0x28*/ + uint32_t I2C_SLAVE_ADDR; + /* 0x2c*/ + uint32_t I2C_STD_SCL_HCNT; + /* 0x30*/ + uint32_t I2C_STD_SCL_LCNT; + /* 0x34*/ + uint32_t I2C_FST_SCL_HCNT; + /* 0x38*/ + uint32_t I2C_FST_CLK_LCNT; + /* 0x3c*/ + uint32_t I2C_HS_CLK_HCNT; + /* 0x40*/ + uint32_t I2C_HS_CLK_LCNT; + /* 0x44*/ + uint32_t I2C_RXFIFO_WATER_MARK; + /* 0x48*/ + uint32_t I2C_TXFIFO_WATER_MARK; + /* 0x4c*/ + uint32_t I2C_TX_FIFO_CNT; + /* 0x50*/ + uint32_t I2C_RX_FIFO_CNT; + /* 0x54*/ + uint32_t I2C_FSTD_SPKCNT; + /* 0x58*/ + uint32_t I2C_HS_SPKCNT; + /* 0x5c*/ + uint32_t I2C_STATUS0; + /* 0x60*/ + uint32_t I2C_STATUS1; + /* 0x64*/ + uint32_t I2C_ERROR_STATUS; + /* 0x68*/ + uint32_t I2C_SCL_LOW_TIMEOUT; + /* 0x6c*/ + uint32_t I2C_SDA_LOW_TIMEOUT; + /* 0x70*/ + uint32_t I2C_RD_CLR_ERR_STATUS; +}; /*i2c_reg*/ + +typedef volatile struct i2c_reg i2c_reg_t; +typedef volatile struct i2c_reg_w i2c_reg_w_t; + +struct parcc_reg { + /* 0x0*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_15_2 :14; /* [15:2] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_WDOG; + + /* 0x4*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_EWDT; + + /* 0x8*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_STIM; + + /* 0xC*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_PWMTIMER0; + + /* 0x10*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_PWMTIMER1; + + /* 0x14*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_PWMTIMER2; + + /* 0x18*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_TDG0; + + /* 0x1C*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_CAN0; + + /* 0x20*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_CAN1; + + /* 0x24*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_UART0; + + /* 0x28*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_UART1; + + /* 0x2C*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_UART2; + + /* 0x30*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_UART3; + + /* 0x34*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_SPI0; + + /* 0x38*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_SPI1; + + /* 0x3C*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_SPI2; + + /* 0x40*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_I2C0; + + /* 0x44*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_I2C1; + + /* 0x48*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_ADC0; + + /* 0x4C*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_15_2 :14; /* [15:2] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_CMP; + + /* 0x50*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_15_2 :14; /* [15:2] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_CRC; + + /* 0x54*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_15_2 :14; /* [15:2] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_FLASH; + + /* 0x58*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_15_2 :14; /* [15:2] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_DMA; + + /* 0x5C*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_15_2 :14; /* [15:2] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_DMAMUX; + + /* 0x60*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_PORTA; + + /* 0x64*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_PORTB; + + /* 0x68*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_PORTC; + + /* 0x6C*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_PORTD; + + /* 0x70*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_PORTE; + + /* 0x74*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_15_2 :14; /* [15:2] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_TMU; + + /* 0x78*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_15_2 :14; /* [15:2] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_REGFILE; + + /* 0x7C*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_15_2 :14; /* [15:2] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_GPIO; + + /* 0x80*/ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_15_2 :14; /* [15:2] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } PARCC_HWDIV; + +}; /*parcc_reg*/ + +struct parcc_reg_w { + /* 0x0*/ + uint32_t PARCC_WDOG; + /* 0x4*/ + uint32_t PARCC_EWDT; + /* 0x8*/ + uint32_t PARCC_STIM; + /* 0xC*/ + uint32_t PARCC_PWMTIMER0; + /* 0x10*/ + uint32_t PARCC_PWMTIMER1; + /* 0x14*/ + uint32_t PARCC_PWMTIMER2; + /* 0x18*/ + uint32_t PARCC_TDG0; + /* 0x1C*/ + uint32_t PARCC_CAN0; + /* 0x20*/ + uint32_t PARCC_CAN1; + /* 0x24*/ + uint32_t PARCC_UART0; + /* 0x28*/ + uint32_t PARCC_UART1; + /* 0x2C*/ + uint32_t PARCC_UART2; + /* 0x30*/ + uint32_t PARCC_UART3; + /* 0x34*/ + uint32_t PARCC_SPI0; + /* 0x38*/ + uint32_t PARCC_SPI1; + /* 0x3C*/ + uint32_t PARCC_SPI2; + /* 0x40*/ + uint32_t PARCC_I2C0; + /* 0x44*/ + uint32_t PARCC_I2C1; + /* 0x48*/ + uint32_t PARCC_ADC0; + /* 0x4C*/ + uint32_t PARCC_CMP; + /* 0x50*/ + uint32_t PARCC_CRC; + /* 0x54*/ + uint32_t PARCC_FLASH; + /* 0x58*/ + uint32_t PARCC_DMA; + /* 0x5C*/ + uint32_t PARCC_DMAMUX; + /* 0x60*/ + uint32_t PARCC_PORTA; + /* 0x64*/ + uint32_t PARCC_PORTB; + /* 0x68*/ + uint32_t PARCC_PORTC; + /* 0x6C*/ + uint32_t PARCC_PORTD; + /* 0x70*/ + uint32_t PARCC_PORTE; + /* 0x74*/ + uint32_t PARCC_TMU; + /* 0x78*/ + uint32_t PARCC_REGFILE; + /* 0x7C*/ + uint32_t PARCC_GPIO; + /* 0x80*/ + uint32_t PARCC_HWDIV; +}; /*parcc_reg*/ + +typedef volatile struct parcc_reg parcc_reg_t; +typedef volatile struct parcc_reg_w parcc_reg_w_t; + +struct pmu_reg { + /* 0x00*/ + struct { + uint32_t RSVD_31_0 :32; /* [31:0] r */ + } PMU_VERID; + + /* 0x04*/ + struct { + uint32_t LPO_CLK_DIS : 1; /* [0] r/w */ + uint32_t LPO_CLK_SEL : 1; /* [1] r/w */ + uint32_t LPO_CLK_READY : 1; /* [2] r */ + uint32_t RSVD_31_3 :29; /* [31:3] ro */ + } PMU_LPO_32K_CFG; + + /* 0x08*/ + struct { + uint32_t LPO_32K_TRIM : 7; /* [6:0] r/w */ + uint32_t RSVD_31_7 :25; /* [31:7] ro */ + } PMU_LPO_32K_TRIM; + + /* 0x0c*/ + struct { + uint32_t ISO_CLR : 1; /* [0] w1c */ + uint32_t RSVD_31_1 :31; /* [31:1] ro */ + } PMU_ISO_CLR; + + /* 0x10*/ + struct { + uint32_t VDD_LVD_LP_EN : 1; /* [0] r/w */ + uint32_t VDD_LVD_ACT_EN : 1; /* [1] r/w */ + uint32_t VDD_LVD_IE : 1; /* [2] r/w */ + uint32_t VDD_LVD_RE : 1; /* [3] r/w */ + uint32_t VDD_LVW_EN : 1; /* [4] r/w */ + uint32_t VDD_LVW_IE : 1; /* [5] r/w */ + uint32_t LVWF_VDD : 1; /* [6] w1c */ + uint32_t LVDF_VDD : 1; /* [7] w1c */ + uint32_t REF_BUF_1V_EN : 1; /* [8] r/w */ + uint32_t LDO_LVD_ACT_EN : 1; /* [9] r/w */ + uint32_t LDO_LVD_LP_EN : 1; /* [10] r/w */ + uint32_t LDO_CLAMP_EN : 1; /* [11] r/w */ + uint32_t RSVD_31_12 :20; /* [31:12] ro */ + } PMU_VDD5V_CSR; + + /* 0x14*/ + struct { + uint32_t RSVD_30_0 :31; /* [30:0] ro */ + uint32_t LOCK : 1; /* [31] w/r */ + } PMU_LOCK; + +}; /*pmu_reg*/ + +struct pmu_reg_w { + /* 0x00*/ + uint32_t PMU_VERID; + /* 0x04*/ + uint32_t PMU_LPO_32K_CFG; + /* 0x08*/ + uint32_t PMU_LPO_32K_TRIM; + /* 0x0c*/ + uint32_t PMU_ISO_CLR; + /* 0x10*/ + uint32_t PMU_VDD5V_CSR; + /* 0x14*/ + uint32_t PMU_LOCK; + +}; /*pmu_reg_w*/ + +typedef volatile struct pmu_reg pmu_reg_t; +typedef volatile struct pmu_reg_w pmu_reg_w_t; + +struct port_reg { + /* 0x0*/ + struct { + uint32_t FEATURE :16; /* [15:0] ro */ + uint32_t MINOR : 8; /* [23:16] ro */ + uint32_t MAJOR : 8; /* [31:24] ro */ + } PORTx_VERID; + + /* 0x4*/ + struct { + uint32_t RSVD_31_0 :32; /* [31:0] ro */ + } PORTx_PARAM; + + /* 0x8*/ + struct { + uint32_t GPWD :32; /* [31:0] r/w */ + } PORTx_GLBDAT; + + /* 0xC*/ + struct { + uint32_t GPWE :32; /* [31:0] wo */ + } PORTx_GLBCTL; + + /* 0x10*/ + struct { + uint32_t PS : 1; /* [0] r/w */ + uint32_t PE : 1; /* [1] r/w */ + uint32_t RSVD_2 : 1; /* [2] ro */ + uint32_t SRE : 1; /* [3] r/w */ + uint32_t PFE : 1; /* [4] r/w */ + uint32_t ODE : 1; /* [5] r/w */ + uint32_t DSE : 1; /* [6] r/w */ + uint32_t RSVD_7 : 1; /* [7] ro */ + uint32_t MUX : 3; /* [10:8] r/w */ + uint32_t RSVD_14_11 : 4; /* [14:11] ro */ + uint32_t LK : 1; /* [15] r/w */ + uint32_t IRQC : 4; /* [19:16] r/w */ + uint32_t RSVD_22_20 : 3; /* [22:20] ro */ + uint32_t ISF : 1; /* [23] r/w */ + uint32_t FLT : 5; /* [28:24] r/w */ + uint32_t RSVD_30_29 : 2; /* [30:29] ro */ + uint32_t FLTEN : 1; /* [31] r/w */ + } PORTx_PCRn[32]; + + /* 0x90*/ + struct { + uint32_t ISF :32; /* [31:0] r/w */ + } PORTx_IRQFLG; +}; /*port_reg*/ + +struct port_reg_w { + /* 0x0*/ + uint32_t PORTx_VERID; + /* 0x4*/ + uint32_t PORTx_PARAM; + /* 0x8*/ + uint32_t PORTx_GLBDAT; + /* 0xC*/ + uint32_t PORTx_GLBCTL; + /* 0x10*/ + uint32_t PORTx_PCRn[32]; + /* 0x90*/ + uint32_t PORTx_IRQFLG; +}; /*port_reg*/ + +typedef volatile struct port_reg port_reg_t; +typedef volatile struct port_reg_w port_reg_w_t; + +struct regfile_reg { + /* 0x0*/ + struct { + uint32_t DATA :32; /* [31:0] rw */ + } REGFILE_REGn[32]; + +}; /*regfile_reg*/ + +struct regfile_reg_w { + /* 0x0*/ + uint32_t REGFILE_REGn[32]; +}; /*regfile_reg*/ + +typedef volatile struct regfile_reg regfile_reg_t; +typedef volatile struct regfile_reg_w regfile_reg_w_t; + +struct rtc_reg { + /* 0x00*/ + struct { + uint32_t CRYSTAL_EN : 1; /* [0] r/w */ + uint32_t CNT_CLK_SEL : 1; /* [1] r/w */ + uint32_t CLKOUT_SEL : 1; /* [2] r/w */ + uint32_t CLKOUT_PIN_EN : 1; /* [3] r/w */ + uint32_t SUP_EN : 1; /* [4] r/w */ + uint32_t SW_RST : 1; /* [5] r/w */ + uint32_t COUNT_EN : 1; /* [6] r/w */ + uint32_t OVF : 1; /* [7] ro */ + uint32_t ALARM_MATCHF : 1; /* [8] ro */ + uint32_t OSC_RDY : 1; /* [9] ro */ + uint32_t EXTAL_32K_EN : 1; /* [10] r/w */ + uint32_t SECONDS_INT_FLAG : 1; /* [11] w1c */ + uint32_t RSVD_31_12 :20; /* [31:12] ro */ + } RTC_CSR; + + /* 0x04*/ + struct { + uint32_t SECOND_INT_MUX_SEL : 3; /* [2:0] r/w */ + uint32_t OVFLOW_IE : 1; /* [3] r/w */ + uint32_t ALARM_IE : 1; /* [4] r/w */ + uint32_t SECONDS_IE : 1; /* [5] r/w */ + uint32_t RSVD_31_6 :26; /* [31:6] ro */ + } RTC_IER; + + /* 0x08*/ + struct { + uint32_t ALARM_CNT :32; /* [31:0] r/w */ + } RTC_ALARM_CNTR; + + /* 0x0c*/ + struct { + uint32_t ONE_SECOND_CNT :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] ro */ + } RTC_ONE_SECOND_CNTR; + + /* 0x10*/ + struct { + uint32_t MATCH_CNT :32; /* [31:0] r/w */ + } RTC_MATCH_CNTR; + + /* 0x14*/ + struct { + uint32_t COMP_CNT : 7; /* [6:0] r/w */ + uint32_t COMP_DIRECTION : 1; /* [7] r/w */ + uint32_t DLY : 8; /* [15:8] r/w */ + uint32_t CCOMP_CNT : 8; /* [23:16] ro */ + uint32_t CDLY : 8; /* [31:24] ro */ + } RTC_COMPENSATIONR; + + /* 0x18*/ + struct { + uint32_t RSVD_30_0 :31; /* [30:0] ro */ + uint32_t LOCK : 1; /* [31] r/w */ + } RTC_LOCKR; + + /* 0x1c*/ + struct { + uint32_t RSVD_31_0 :32; /* [31:0] ro */ + } RTC_VERID; + +}; /*rtc_reg*/ + +struct rtc_reg_w { + /* 0x00*/ + uint32_t RTC_CSR; + /* 0x04*/ + uint32_t RTC_IER; + /* 0x08*/ + uint32_t RTC_ALARM_CNTR; + /* 0x0c*/ + uint32_t RTC_ONE_SECOND_CNTR; + /* 0x10*/ + uint32_t RTC_MATCH_CNTR; + /* 0x14*/ + uint32_t RTC_COMPENSATIONR; + /* 0x18*/ + uint32_t RTC_LOCKR; + /* 0x1c*/ + uint32_t RTC_VERID; +}; /*rtc_reg*/ + +typedef volatile struct rtc_reg rtc_reg_t; +typedef volatile struct rtc_reg_w rtc_reg_w_t; + +struct scc_reg { + /* 0x0*/ + struct { + uint32_t RSVD_7_0 : 8; /* [7:0] r */ + uint32_t MINOR : 8; /* [15:8] r */ + uint32_t MAJOR : 8; /* [23:16] r */ + uint32_t RSVD_31_24 : 8; /* [31:24] r */ + } SCC_VERID; + + /* 0x4*/ + struct { + uint32_t CLKSPRES : 5; /* [4:0] r */ + uint32_t RSVD_27_5 :23; /* [27:5] r */ + uint32_t DIVPRES : 3; /* [30:28] r */ + uint32_t RSVD_31 : 1; /* [31] r */ + } SCC_PARAM; + + /* 0x8*/ + struct { + uint32_t DIVSLOW : 4; /* [3:0] r */ + uint32_t DIVBUS : 4; /* [7:4] r */ + uint32_t DIVCORE : 4; /* [11:8] r */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t SCS : 3; /* [18:16] r */ + uint32_t RSVD_31_19 :13; /* [31:19] r */ + } SCC_CST; + + /* 0xC*/ + struct { + uint32_t DIVSLOW : 4; /* [3:0] r/w */ + uint32_t DIVBUS : 4; /* [7:4] r/w */ + uint32_t DIVCORE : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t SCS : 3; /* [18:16] r/w */ + uint32_t RSVD_30_19 :12; /* [30:19] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } SCC_CFG; + + /* 0x10*/ + struct { + uint32_t RSVD_15_0 :16; /* [15:0] r */ + uint32_t CLKOUTSEL : 4; /* [19:16] r/w */ + uint32_t RSVD_31_20 :12; /* [31:20] */ + } SCC_CLKOUTCFG; + + /* 0x14*/ + struct { + uint32_t OSCEN : 1; /* [0] r/w */ + uint32_t OSCSTOPEN : 1; /* [1] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t OSCCMIE : 1; /* [4] r/w */ + uint32_t RSVD_8_5 : 4; /* [8:5] r */ + uint32_t OSCCME : 1; /* [9] r/w */ + uint32_t OSCCMRE : 1; /* [10] r/w */ + uint32_t RSVD_15_11 : 5; /* [15:11] r */ + uint32_t OSCRDY : 1; /* [16] r */ + uint32_t OSCSELD : 1; /* [17] r */ + uint32_t OSCLOC : 1; /* [18] r/w */ + uint32_t RSVD_30_19 :12; /* [30:19] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } SCC_OSCCS; + + /* 0x18*/ + struct { + uint32_t EXCLKS : 1; /* [0] r/w */ + uint32_t OLMEN : 1; /* [1] r/w */ + uint32_t HFREQ : 1; /* [2] r/w */ + uint32_t RSVD_7_3 : 5; /* [7:3] r */ + uint32_t RSVD_9_8 : 2; /* [9:8] r/w */ + uint32_t RSVD_31_10 :22; /* [31:10] r */ + } SCC_OSCCFG; + + /* 0x1C*/ + struct { + uint32_t FIRCEN : 1; /* [0] r/w */ + uint32_t FIRCSTOPEN : 1; /* [1] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t FIRCCMIE : 1; /* [4] r/w */ + uint32_t RSVD_8_5 : 4; /* [8:5] r */ + uint32_t FIRCCME : 1; /* [9] r/w */ + uint32_t FIRCCMRE : 1; /* [10] r/w */ + uint32_t RSVD_11 : 1; /* [11] r */ + uint32_t RSVD_12 : 1; /* [12] r/w */ + uint32_t RSVD_15_13 : 3; /* [15:13] r */ + uint32_t FIRCRDY : 1; /* [16] r */ + uint32_t FIRCSELD : 1; /* [17] r */ + uint32_t FIRCLOC : 1; /* [18] r/w */ + uint32_t RSVD_30_19 :12; /* [30:19] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } SCC_FIRCCS; + + /* 0x20*/ + struct { + uint32_t RSVD_1_0 : 2; /* [1:0] r/w */ + uint32_t RSVD_31_2 :30; /* [31:2] r */ + } SCC_FIRCCFG; + + /* 0x24*/ + struct { + uint32_t RSVD_5_0 : 6; /* [5:0] r/w */ + uint32_t RSVD_31_6 :26; /* [31:6] r */ + } SCC_FIRCTRIM; + +}; /*scc_reg*/ + +struct scc_reg_w { + /* 0x0*/ + uint32_t SCC_VERID; + /* 0x4*/ + uint32_t SCC_PARAM; + /* 0x8*/ + uint32_t SCC_CST; + /* 0xC*/ + uint32_t SCC_CFG; + /* 0x10*/ + uint32_t SCC_CLKOUTCFG; + /* 0x14*/ + uint32_t SCC_OSCCS; + /* 0x18*/ + uint32_t SCC_OSCCFG; + /* 0x1C*/ + uint32_t SCC_FIRCCS; + /* 0x20*/ + uint32_t SCC_FIRCCFG; + /* 0x24*/ + uint32_t SCC_FIRCTRIM; +}; /*scc_reg*/ + +typedef volatile struct scc_reg scc_reg_t; +typedef volatile struct scc_reg_w scc_reg_w_t; + +struct scm_reg { + /* 0x00*/ + struct { + uint32_t RSVD_3_0 : 4; /* [3:0] ro */ + uint32_t CLKOUTSEL : 2; /* [5:4] r/w */ + uint32_t RSVD_7_6 : 2; /* [7:6] ro */ + uint32_t CLKOUTDIV : 3; /* [10:8] r/w */ + uint32_t CLKOUTEN : 1; /* [11] r/w */ + uint32_t RSVD_31_12 :20; /* [31:12] ro */ + } SCM_CHIPCTL; + + /* 0x04*/ + struct { + uint32_t SWTRIG : 4; /* [3:0] r/w */ + uint32_t RSVD_31_4 :28; /* [31:4] ro */ + } SCM_MISCCTL; + + /* 0x08*/ + struct { + uint32_t TIM0_CLK_SEL : 2; /* [1:0] r/w */ + uint32_t RSVD_7_2 : 6; /* [7:2] ro */ + uint32_t TIM1_CLK_SEL : 2; /* [9:8] r/w */ + uint32_t RSVD_15_10 : 6; /* [15:10] ro */ + uint32_t TIM2_CLK_SEL : 2; /* [17:16] r/w */ + uint32_t RSVD_31_18 :14; /* [31:18] ro */ + } SCM_TIMOPT; + + /* 0x0C*/ + struct { + uint32_t SRAM0_ECCR_DIS : 1; /* [0] r/w */ + uint32_t SRAM0_ECCW_DIS : 1; /* [1] r/w */ + uint32_t SRAM0_ECCSB_DIS : 1; /* [2] r/w */ + uint32_t SRAM0_ECCMB_DIS : 1; /* [3] r/w */ + uint32_t RSVD_7_4 : 4; /* [7:4] ro */ + uint32_t SRAM1_ECCR_DIS : 1; /* [8] r/w */ + uint32_t SRAM1_ECCW_DIS : 1; /* [9] r/w */ + uint32_t SRAM1_ECCSB_DIS : 1; /* [10] r/w */ + uint32_t SRAM1_ECCMB_DIS : 1; /* [11] r/w */ + uint32_t RSVD_31_12 :20; /* [31:12] ro */ + } SCM_ECCOPT; + + /* 0x10*/ + struct { + uint32_t EFPROT : 4; /* [3:0] ro */ + uint32_t EFSIZE : 3; /* [6:4] ro */ + uint32_t EFW : 1; /* [7] ro */ + uint32_t EFMST : 4; /* [11:8] ro */ + uint32_t RSVD_28_12 :17; /* [28:12] ro */ + uint32_t SBERR : 1; /* [29] w1c */ + uint32_t MBERR : 1; /* [30] w1c */ + uint32_t OVERRUN : 1; /* [31] w1c */ + } SCM_ECC0ST; + + /* 0x14*/ + struct { + uint32_t EFADDR :32; /* [31:0] ro */ + } SCM_ECC0FADDR; + + /* 0x18*/ + struct { + uint32_t EFDATA :32; /* [31:0] ro */ + } SCM_ECC0FDATA; + + /* 0x1C*/ + struct { + uint32_t EFPROT : 4; /* [3:0] ro */ + uint32_t EFSIZE : 3; /* [6:4] ro */ + uint32_t EFW : 1; /* [7] ro */ + uint32_t EFMST : 4; /* [11:8] ro */ + uint32_t RSVD_28_12 :17; /* [28:12] ro */ + uint32_t SBERR : 1; /* [29] w1c */ + uint32_t MBERR : 1; /* [30] w1c */ + uint32_t OVERRUN : 1; /* [31] w1c */ + } SCM_ECC1ST; + + /* 0x20*/ + struct { + uint32_t EFADDR :32; /* [31:0] ro */ + } SCM_ECC1FADDR; + + /* 0x24*/ + struct { + uint32_t EFDATA :32; /* [31:0] ro */ + } SCM_ECC1FDATA; + + uint8_t zResverd0x028[216]; /*pad 0x028 - 0FF*/ + + /* 0x100*/ + struct { + uint32_t RSVD_31_0 :32; /* [31:0] ro */ + } SCM_CHIPOPT; + + /* 0x104*/ + struct { + uint32_t RSVD_23_0 :24; /* [23:0] ro */ + uint32_t PFSIZE : 4; /* [27:24] ro */ + uint32_t DFSIZE : 4; /* [31:28] ro */ + } SCM_FLSCFG; + + /* 0x108*/ + struct { + uint32_t RSVD_27_0 :28; /* [27:0] ro */ + uint32_t RAMSIZE : 4; /* [31:28] ro */ + } SCM_RAMCFG; + + uint8_t zResverd0x010C[16]; /*pad 0x010C - 011B*/ + + /* 0x11C*/ + struct { + uint32_t MEMSIZE_ID : 4; /* [3:0] ro */ + uint32_t SERIES_ID : 3; /* [6:4] ro */ + uint32_t SUBFAMILY_ID : 5; /* [11:7] ro */ + uint32_t FAMILY_ID : 4; /* [15:12] ro */ + uint32_t REV_ID : 4; /* [19:16] ro */ + uint32_t FEATURE_ID : 7; /* [26:20] ro */ + uint32_t PACKAGE_ID : 5; /* [31:27] ro */ + } SCM_DEVID; + + /* 0x120*/ + struct { + uint32_t UID_31_0 :32; /* [31:0] ro */ + } SCM_UNIQUE0; + + /* 0x124*/ + struct { + uint32_t UID_63_32 :32; /* [31:0] ro */ + } SCM_UNIQUE1; + + /* 0x128*/ + struct { + uint32_t UID_95_64 :32; /* [31:0] ro */ + } SCM_UNIQUE2; + + /* 0x12C*/ + struct { + uint32_t UID_127_96 :32; /* [31:0] ro */ + } SCM_UNIQUE3; + +}; /*scm_reg*/ + +struct scm_reg_w { + /* 0x00*/ + uint32_t SCM_CHIPCTL; + /* 0x04*/ + uint32_t SCM_MISCCTL; + /* 0x08*/ + uint32_t SCM_TIMOPT; + /* 0x0C*/ + uint32_t SCM_ECCOPT; + /* 0x10*/ + uint32_t SCM_ECC0ST; + /* 0x14*/ + uint32_t SCM_ECC0FADDR; + /* 0x18*/ + uint32_t SCM_ECC0FDATA; + /* 0x1C*/ + uint32_t SCM_ECC1ST; + /* 0x20*/ + uint32_t SCM_ECC1FADDR; + /* 0x24*/ + uint32_t SCM_ECC1FDATA; + uint8_t zResverd0x028[216]; /*pad 0x028 - 0FF*/ + + /* 0x100*/ + uint32_t SCM_CHIPOPT; + /* 0x104*/ + uint32_t SCM_FLSCFG; + /* 0x108*/ + uint32_t SCM_RAMCFG; + uint8_t zResverd0x010C[16]; /*pad 0x010C - 011B*/ + + /* 0x11C*/ + uint32_t SCM_DEVID; + /* 0x120*/ + uint32_t SCM_UNIQUE0; + /* 0x124*/ + uint32_t SCM_UNIQUE1; + /* 0x128*/ + uint32_t SCM_UNIQUE2; + /* 0x12C*/ + uint32_t SCM_UNIQUE3; +}; /*scm_reg*/ + +typedef volatile struct scm_reg scm_reg_t; +typedef volatile struct scm_reg_w scm_reg_w_t; + +struct spi_reg { + /* 0x0*/ + struct { + uint32_t DFS : 4; /* [3:0] r/w */ + uint32_t RSVD_5_4 : 2; /* [5:4] ro */ + uint32_t SCPH : 1; /* [6] r/w */ + uint32_t SCPOL : 1; /* [7] r/w */ + uint32_t TMOD : 2; /* [9:8] r/w */ + uint32_t RSVD_10 : 1; /* [10] r/w */ + uint32_t RSVD_11 : 1; /* [11] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r/w */ + uint32_t DFS_32 : 5; /* [20:16] r/w */ + uint32_t MST_MODE : 1; /* [21] r/w */ + uint32_t RSVD_22 : 1; /* [22] r/w */ + uint32_t RSVD_23 : 1; /* [23] r/w */ + uint32_t RSVD_24 : 1; /* [24] r/w */ + uint32_t RSVD_31_25 : 7; /* [31:25] ro */ + } SPI_CTRLR0; + + /* 0x4*/ + struct { + uint32_t NDF :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] ro */ + } SPI_CTRLR1; + + /* 0x8*/ + struct { + uint32_t SPI_EN : 1; /* [0] r/w */ + uint32_t RSVD_15_1 :15; /* [15:1] ro */ + uint32_t SER : 2; /* [17:16] r/w */ + uint32_t RSVD_31_18 :14; /* [31:18] ro */ + } SPI_SSENR; + + /* 0xC*/ + struct { + uint32_t SCKDV :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] ro */ + } SPI_BAUDR; + + /* 0x10*/ + struct { + uint32_t TFT : 2; /* [1:0] r/w */ + uint32_t RSVD_15_2 :14; /* [15:2] ro */ + uint32_t RFT : 2; /* [17:16] r/w */ + uint32_t RSVD_31_18 :14; /* [31:18] ro */ + } SPI_FTLR; + + /* 0x14*/ + struct { + uint32_t TXTFL : 3; /* [2:0] ro */ + uint32_t RSVD_15_3 :13; /* [15:3] ro */ + uint32_t RXTFL : 3; /* [18:16] ro */ + uint32_t RSVD_31_19 :13; /* [31:19] ro */ + } SPI_FLR; + + /* 0x18*/ + struct { + uint32_t BUSY : 1; /* [0] ro */ + uint32_t TFNF : 1; /* [1] ro */ + uint32_t TFE : 1; /* [2] ro */ + uint32_t RFNE : 1; /* [3] ro */ + uint32_t RFF : 1; /* [4] ro */ + uint32_t TXE : 1; /* [5] ro */ + uint32_t RSVD_31_6 :26; /* [31:6] ro */ + } SPI_SR; + + /* 0x1C*/ + struct { + uint32_t TXEIE : 1; /* [0] r/w */ + uint32_t TXOIE : 1; /* [1] r/w */ + uint32_t RXUIE : 1; /* [2] r/w */ + uint32_t RXOIE : 1; /* [3] r/w */ + uint32_t RXFIE : 1; /* [4] r/w */ + uint32_t RSVD_31_5 :27; /* [31:5] ro */ + } SPI_IER; + + /* 0x20*/ + struct { + uint32_t TXEIS : 1; /* [0] ro */ + uint32_t TXOIS : 1; /* [1] ro */ + uint32_t RXUIS : 1; /* [2] ro */ + uint32_t RXOIS : 1; /* [3] ro */ + uint32_t RXFIS : 1; /* [4] ro */ + uint32_t RSVD_15_5 :11; /* [15:5] ro */ + uint32_t TXEIR : 1; /* [16] ro */ + uint32_t TXOIR : 1; /* [17] ro */ + uint32_t RXUIR : 1; /* [18] ro */ + uint32_t RXOIR : 1; /* [19] ro */ + uint32_t RXFIR : 1; /* [20] ro */ + uint32_t RSVD_31_21 :11; /* [31:21] ro */ + } SPI_ISR; + + /* 0x24*/ + struct { + uint32_t TXOICR : 1; /* [0] ro */ + uint32_t RSVD_31_1 :31; /* [31:1] ro */ + } SPI_TXOICR; + + /* 0x28*/ + struct { + uint32_t RXOICR : 1; /* [0] ro */ + uint32_t RSVD_31_1 :31; /* [31:1] ro */ + } SPI_RXOICR; + + /* 0x2c*/ + struct { + uint32_t RXUICR : 1; /* [0] ro */ + uint32_t RSVD_31_1 :31; /* [31:1] ro */ + } SPI_RXUICR; + + uint8_t zResverd0x030[4]; /*pad 0x030 - 033*/ + + /* 0x34*/ + struct { + uint32_t ICR : 1; /* [0] ro */ + uint32_t RSVD_31_1 :31; /* [31:1] ro */ + } SPI_ICR; + + /* 0x38*/ + struct { + uint32_t RDMAE : 1; /* [0] r/w */ + uint32_t TDMAE : 1; /* [1] r/w */ + uint32_t RSVD_31_2 :30; /* [31:2] ro */ + } SPI_DMACR; + + /* 0x3C*/ + struct { + uint32_t DMATDL : 2; /* [1:0] r/w */ + uint32_t RSVD_31_2 :30; /* [31:2] ro */ + } SPI_DMATDLR; + + /* 0x40*/ + struct { + uint32_t DMARDL : 2; /* [1:0] r/w */ + uint32_t RSVD_31_2 :30; /* [31:2] ro */ + } SPI_DMARDLR; + + /* 0x44*/ + struct { + uint32_t RSVD_31_0 :32; /* [31:0] ro */ + } SPI_IDR; + + /* 0x48*/ + struct { + uint32_t RSVD_31_0 :32; /* [31:0] ro */ + } SPI_VIDR; + + uint8_t zResverd0x04C[20]; /*pad 0x04C - 05F*/ + + /* 0x60*/ + struct { + uint32_t DR :32; /* [31:0] r/w */ + } SPI_DR_LOW; + + uint8_t zResverd0x064[136]; /*pad 0x064 - 0EB*/ + + /* 0xEC*/ + struct { + uint32_t DR :32; /* [31:0] r/w */ + } SPI_DR_HIGH; + +}; /*spi_reg*/ + +struct spi_reg_w { + /* 0x0*/ + uint32_t SPI_CTRLR0; + /* 0x4*/ + uint32_t SPI_CTRLR1; + /* 0x8*/ + uint32_t SPI_SSENR; + /* 0xC*/ + uint32_t SPI_BAUDR; + /* 0x10*/ + uint32_t SPI_FTLR; + /* 0x14*/ + uint32_t SPI_FLR; + /* 0x18*/ + uint32_t SPI_SR; + /* 0x1C*/ + uint32_t SPI_IER; + /* 0x20*/ + uint32_t SPI_ISR; + /* 0x24*/ + uint32_t SPI_TXOICR; + /* 0x28*/ + uint32_t SPI_RXOICR; + /* 0x2c*/ + uint32_t SPI_RXUICR; + uint8_t zResverd0x030[4]; /*pad 0x030 - 033*/ + + /* 0x34*/ + uint32_t SPI_ICR; + /* 0x38*/ + uint32_t SPI_DMACR; + /* 0x3C*/ + uint32_t SPI_DMATDLR; + /* 0x40*/ + uint32_t SPI_DMARDLR; + /* 0x44*/ + uint32_t SPI_IDR; + /* 0x48*/ + uint32_t SPI_VIDR; + uint8_t zResverd0x04C[20]; /*pad 0x04C - 05F*/ + + /* 0x60*/ + uint32_t SPI_DR_LOW; + uint8_t zResverd0x064[136]; /*pad 0x064 - 0EB*/ + + /* 0xEC*/ + uint32_t SPI_DR_HIGH; +}; /*spi_reg*/ + +typedef volatile struct spi_reg spi_reg_t; +typedef volatile struct spi_reg_w spi_reg_w_t; + +struct srmc_reg { + /* 0x00*/ + struct { + uint32_t FEATURE :16; /* [15:0] ro */ + uint32_t MINOR : 8; /* [23:16] ro */ + uint32_t MAJOR : 8; /* [31:24] ro */ + } SRMC_VERID; + + /* 0x04*/ + struct { + uint32_t EWAKEUP : 1; /* [0] ro */ + uint32_t ELVD : 1; /* [1] ro */ + uint32_t ELOC : 1; /* [2] ro */ + uint32_t RSVD_3 : 1; /* [3] ro */ + uint32_t RSVD_4 : 1; /* [4] ro */ + uint32_t EWDOG : 1; /* [5] ro */ + uint32_t EPIN : 1; /* [6] ro */ + uint32_t EPOR : 1; /* [7] ro */ + uint32_t RSVD_8 : 1; /* [8] ro */ + uint32_t ELOCKUP : 1; /* [9] ro */ + uint32_t ESW : 1; /* [10] ro */ + uint32_t EMDM_AP : 1; /* [11] ro */ + uint32_t RSVD_12 : 1; /* [12] ro */ + uint32_t ESACKERR : 1; /* [13] ro */ + uint32_t RSVD_15_14 : 2; /* [15:14] ro */ + uint32_t EPDOWN : 1; /* [16] ro */ + uint32_t RSVD_31_17 :15; /* [31:17] ro */ + } SRMC_PARAM; + + /* 0x08*/ + struct { + uint32_t WAKEUP : 1; /* [0] ro */ + uint32_t LVD : 1; /* [1] w1c */ + uint32_t LOC : 1; /* [2] w1c */ + uint32_t RSVD_4_3 : 2; /* [4:3] ro */ + uint32_t WDOG : 1; /* [5] w1c */ + uint32_t PIN : 1; /* [6] w1c */ + uint32_t POR : 1; /* [7] w1c */ + uint32_t RSVD_8 : 1; /* [8] ro */ + uint32_t LOCKUP : 1; /* [9] w1c */ + uint32_t SW : 1; /* [10] w1c */ + uint32_t MDM_AP : 1; /* [11] w1c */ + uint32_t RSVD_14_12 : 3; /* [14:12] ro */ + uint32_t SACKERR : 1; /* [15] w1c */ + uint32_t RSVD_31_16 :16; /* [31:16] ro */ + } SRMC_SRS; + + /* 0x0C*/ + struct { + uint32_t RSTFLTSRW : 2; /* [1:0] r/w */ + uint32_t RSTFLTSS : 1; /* [2] r/w */ + uint32_t RSVD_7_3 : 5; /* [7:3] r/w */ + uint32_t RSTFLTSEL : 5; /* [12:8] r/w */ + uint32_t RSVD_30_13 :18; /* [30:13] r */ + uint32_t LOCKUP_RST_EN : 1; /* [31] r/w */ + } SRMC_CTRL; + + /* 0x10*/ + struct { + uint32_t RSVD_31_0 :32; /* [31:0] ro */ + } SRMC_MR; + + /* 0x14*/ + struct { + uint32_t RSVD_31_0 :32; /* [31:0] ro */ + } SRMC_FM; + + /* 0x18*/ + struct { + uint32_t WAKEUP : 1; /* [0] ro */ + uint32_t SLVD : 1; /* [1] ro */ + uint32_t SLOC : 1; /* [2] ro */ + uint32_t RSVD_4_3 : 2; /* [4:3] ro */ + uint32_t SWDOG : 1; /* [5] ro */ + uint32_t SPIN : 1; /* [6] ro */ + uint32_t SPOR : 1; /* [7] ro */ + uint32_t RSVD_8 : 1; /* [8] ro */ + uint32_t SLOCKUP : 1; /* [9] ro */ + uint32_t SSW : 1; /* [10] ro */ + uint32_t SMDM_AP : 1; /* [11] ro */ + uint32_t RSVD_14_12 : 3; /* [14:12] ro */ + uint32_t SSACKERR : 1; /* [15] ro */ + uint32_t RSVD_31_16 :16; /* [31:16] ro */ + } SRMC_SSRS; + + /* 0x1C*/ + struct { + uint32_t DELAY : 2; /* [1:0] r/w */ + uint32_t LOC : 1; /* [2] r/w */ + uint32_t RSVD_4_3 : 2; /* [4:3] ro */ + uint32_t WDOG : 1; /* [5] r/w */ + uint32_t PIN : 1; /* [6] r/w */ + uint32_t GIE : 1; /* [7] r/w */ + uint32_t RSVD_8 : 1; /* [8] ro */ + uint32_t LOCKUP : 1; /* [9] r/w */ + uint32_t SW : 1; /* [10] r/w */ + uint32_t RSVD_14_11 : 4; /* [14:11] ro */ + uint32_t SACKERR : 1; /* [15] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] ro */ + } SRMC_SRIE; + + /* 0x20*/ + struct { + uint32_t APD : 1; /* [0] r/w */ + uint32_t RSVD_31_1 :31; /* [31:1] ro */ + } SRMC_PMPORT; + + /* 0x24*/ + struct { + uint32_t DSMC : 2; /* [1:0] r/w */ + uint32_t RSVD_7_2 : 6; /* [7:2] ro */ + uint32_t DSMACKTMO : 8; /* [15:8] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] ro */ + } SRMC_PMCTRL; + + /* 0x28*/ + struct { + uint32_t PMSTAT : 4; /* [3:0] ro */ + uint32_t RSVD_7_4 : 4; /* [7:4] ro */ + uint32_t DSMABORT : 1; /* [8] ro */ + uint32_t RSVD_31_9 :23; /* [31:9] ro */ + } SRMC_PMSTAT; + + /* 0x2C*/ + struct { + uint32_t WUPSRC_EN0 : 3; /* [2:0] r/w */ + uint32_t RSVD_3 : 1; /* [3] ro */ + uint32_t WUPSRC_EN1 : 8; /* [11:4] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] ro */ + uint32_t WUPSRC_PL0 : 3; /* [18:16] r/w */ + uint32_t RSVD_19 : 1; /* [19] ro */ + uint32_t WUPSRC_PL1 : 8; /* [27:20] r/w */ + uint32_t RSVD_31_28 : 4; /* [31:28] ro */ + } SRMC_DSMWUPC; + + /* 0x30*/ + struct { + uint32_t WUPS0 : 3; /* [2:0] w1c */ + uint32_t RSVD_3 : 1; /* [3] ro */ + uint32_t WUPS1 : 8; /* [11:4] w1c */ + uint32_t RSVD_31_28 : 4; /* [31:28] ro */ + } SRMC_DSMWUPS; + +}; /*srmc_reg*/ + +struct srmc_reg_w { + /* 0x00*/ + uint32_t SRMC_VERID; + /* 0x04*/ + uint32_t SRMC_PARAM; + /* 0x08*/ + uint32_t SRMC_SRS; + /* 0x0C*/ + uint32_t SRMC_CTRL; + /* 0x10*/ + uint32_t SRMC_MR; + /* 0x14*/ + uint32_t SRMC_FM; + /* 0x18*/ + uint32_t SRMC_SSRS; + /* 0x1C*/ + uint32_t SRMC_SRIE; + /* 0x20*/ + uint32_t SRMC_PMPORT; + /* 0x24*/ + uint32_t SRMC_PMCTRL; + /* 0x28*/ + uint32_t SRMC_PMSTAT; + /* 0x2C*/ + uint32_t SRMC_DSMWUPC; + /* 0x30*/ + uint32_t SRMC_DSMWUPS; +}; /*srmc_reg*/ + +typedef volatile struct srmc_reg srmc_reg_t; +typedef volatile struct srmc_reg_w srmc_reg_w_t; + +struct stim_reg { + /* 0x00*/ + struct { + uint32_t VERID :32; /* [31:0] ro */ + } STIM_VERID; + + /* 0x04*/ + struct { + uint32_t CNT :32; /* [31:0] ro */ + } STIM_CNTn[4]; + + /* 0x14*/ + struct { + uint32_t CV :32; /* [31:0] r/w */ + } STIM_CVn[4]; + + /* 0x24*/ + struct { + uint32_t CLKS : 2; /* [1:0] r/w */ + uint32_t PSDIV : 4; /* [5:2] r/w */ + uint32_t PSEN : 1; /* [6] r/w */ + uint32_t POL : 1; /* [7] r/w */ + uint32_t PSRC : 2; /* [9:8] r/w */ + uint32_t MODE : 1; /* [10] r/w */ + uint32_t RSTDIS : 1; /* [11] r/w */ + uint32_t DMAE : 1; /* [12] r/w */ + uint32_t IE : 1; /* [13] r/w */ + uint32_t EN : 1; /* [14] r/w */ + uint32_t FLAG : 1; /* [15] w1c */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } STIM_SCn[4]; + +}; /*stim_reg*/ + +struct stim_reg_w { + /* 0x00*/ + uint32_t STIM_VERID; + /* 0x04*/ + uint32_t STIM_CNTn[4]; + /* 0x14*/ + uint32_t STIM_CVn[4]; + /* 0x24*/ + uint32_t STIM_SCn[4]; +}; /*stim_reg*/ + +typedef volatile struct stim_reg stim_reg_t; +typedef volatile struct stim_reg_w stim_reg_w_t; + +struct tdg_reg { + /* 0x0*/ + struct { + uint32_t MINOR : 4; /* [3:0] r */ + uint32_t MAJOR : 4; /* [7:4] r */ + uint32_t RSVD_31_8 :24; /* [31:8] r */ + } TDG_VERID; + + /* 0x4*/ + struct { + uint32_t DOPNUM : 4; /* [3:0] r */ + uint32_t CHNUM : 4; /* [7:4] r */ + uint32_t RSVD_31_8 :24; /* [31:8] r */ + } TDG_PARAM; + + /* 0x8*/ + struct { + uint32_t TDGEN : 1; /* [0] r/w */ + uint32_t RSVD_3_1 : 3; /* [3:1] */ + uint32_t TRIGS : 1; /* [4] r/w */ + uint32_t CNTMD : 1; /* [5] r/w */ + uint32_t CLRMD : 1; /* [6] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t PRES : 3; /* [10:8] r/w */ + uint32_t RSVD_15_11 : 5; /* [15:11] r */ + uint32_t CFGUP : 1; /* [16] r/w */ + uint32_t SWTRG : 1; /* [17] r/w */ + uint32_t RSVD_19_18 : 2; /* [19:18] */ + uint32_t UPMD : 2; /* [21:20] r */ + uint32_t RSVD_31_22 :10; /* [31:22] r */ + } TDG_CTRL1; + + /* 0xC*/ + struct { + uint32_t CDO0IE : 1; /* [0] r/w */ + uint32_t CDO1IE : 1; /* [1] r/w */ + uint32_t CDO2IE : 1; /* [2] r/w */ + uint32_t CDO3IE : 1; /* [3] r/w */ + uint32_t CDO4IE : 1; /* [4] r/w */ + uint32_t CDO5IE : 1; /* [5] r/w */ + uint32_t RSVD_7_6 : 2; /* [7:6] r */ + uint32_t ERRIE : 1; /* [8] r/w */ + uint32_t RSVD_15_9 : 7; /* [15:9] r */ + uint32_t CH0E : 1; /* [16] r/w */ + uint32_t CH1E : 1; /* [17] r/w */ + uint32_t CH2E : 1; /* [18] r/w */ + uint32_t CH3E : 1; /* [19] r/w */ + uint32_t CH4E : 1; /* [20] r/w */ + uint32_t CH5E : 1; /* [21] r/w */ + uint32_t RSVD_31_22 :10; /* [31:22] r */ + } TDG_CTRL2; + + /* 0x10*/ + struct { + uint32_t CDO0IF : 1; /* [0] r/w */ + uint32_t CDO1IF : 1; /* [1] r/w */ + uint32_t CDO2IF : 1; /* [2] r/w */ + uint32_t CDO3IF : 1; /* [3] r/w */ + uint32_t CDO4IF : 1; /* [4] r/w */ + uint32_t CDO5IF : 1; /* [5] r/w */ + uint32_t RSVD_7_6 : 2; /* [7:6] */ + uint32_t ERRIF : 1; /* [8] r/w */ + uint32_t RSVD_31_9 :23; /* [31:9] */ + } TDG_STAT; + + /* 0x14*/ + struct { + uint32_t MOD :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] r */ + } TDG_MOD; + + /* 0x18*/ + struct { + uint32_t CNT :16; /* [15:0] r */ + uint32_t RSVD_31_16 :16; /* [31:16] r */ + } TDG_CNT; + + /* 0x1C*/ + struct { + struct { + uint32_t RSVD_7_0 : 8; /* [7:0] */ + uint32_t DO0E : 1; /* [8] r/w */ + uint32_t DO1E : 1; /* [9] r/w */ + uint32_t DO2E : 1; /* [10] r/w */ + uint32_t DO3E : 1; /* [11] r/w */ + uint32_t DO4E : 1; /* [12] r/w */ + uint32_t DO5E : 1; /* [13] r/w */ + uint32_t DO6E : 1; /* [14] r/w */ + uint32_t DO7E : 1; /* [15] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } TDG_CHCTRL; + + /* 0x20 - 0x3F*/ + struct { + uint32_t DO0OFS :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] r */ + } TDG_CHDOOFS[8]; + + /* 0x40*/ + struct { + uint32_t CDOINTDLY :10; /* [9:0] r/w */ + uint32_t RSVD_15_10 : 6; /* [15:10] r */ + uint32_t LDCO : 1; /* [16] r/w */ + uint32_t RSVD_31_17 :15; /* [31:17] r */ + } TDG_CHDOCINTDLY; + + } TDG_CHCFG[6]; +}; /*tdg_reg*/ + +struct tdg_reg_w { + /* 0x0*/ + uint32_t TDG_VERID; + /* 0x4*/ + uint32_t TDG_PARAM; + /* 0x8*/ + uint32_t TDG_CTRL1; + /* 0xC*/ + uint32_t TDG_CTRL2; + /* 0x10*/ + uint32_t TDG_STAT; + /* 0x14*/ + uint32_t TDG_MOD; + /* 0x18*/ + uint32_t TDG_CNT; + + struct { + /* 0x1C */ + uint32_t TDG_CHCTRL; + /* 0x20 - 0x3F*/ + uint32_t TDG_CHDOOFS[8]; + /* 0x40*/ + uint32_t TDG_CHDOCINTDLY; + }TDG_CHCFG[6]; + +}; /*tdg_reg*/ + +typedef volatile struct tdg_reg tdg_reg_t; +typedef volatile struct tdg_reg_w tdg_reg_w_t; + +struct tim_reg { + /* 0x00*/ + struct { + uint32_t CKSRC : 2; /* [1:0] r/w */ + uint32_t PSDIV : 3; /* [4:2] r/w */ + uint32_t DBGM : 2; /* [6:5] r/w */ + uint32_t RSVD_31_7 :25; /* [31:7] */ + } TIM_TIMEBASE; + + /* 0x04*/ + struct { + uint32_t CNT :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } TIM_CNT; + + /* 0x08*/ + struct { + uint32_t CNTINIT :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } TIM_CNTINIT; + + /* 0x0C*/ + struct { + uint32_t MOD :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } TIM_MOD; + + /* 0x10*/ + struct { + uint32_t CHOE0 : 1; /* [0] r/w */ + uint32_t CHOE1 : 1; /* [1] r/w */ + uint32_t CHOE2 : 1; /* [2] r/w */ + uint32_t CHOE3 : 1; /* [3] r/w */ + uint32_t CHOE4 : 1; /* [4] r/w */ + uint32_t CHOE5 : 1; /* [5] r/w */ + uint32_t CHOE6 : 1; /* [6] r/w */ + uint32_t CHOE7 : 1; /* [7] r/w */ + uint32_t RLDIE : 1; /* [8] r/w */ + uint32_t TOIE : 1; /* [9] r/w */ + uint32_t CNTMODE : 1; /* [10] r/w */ + uint32_t INIT : 1; /* [11] w/o */ + uint32_t RSVD_31_12 :20; /* [31:12] */ + } TIM_GLBCR; + + /* 0x14*/ + struct { + uint32_t CH0F : 1; /* [0] r/o */ + uint32_t CH1F : 1; /* [1] r/o */ + uint32_t CH2F : 1; /* [2] r/o */ + uint32_t CH3F : 1; /* [3] r/o */ + uint32_t CH4F : 1; /* [4] r/o */ + uint32_t CH5F : 1; /* [5] r/o */ + uint32_t CH6F : 1; /* [6] r/o */ + uint32_t CH7F : 1; /* [7] r/o */ + uint32_t RLDF : 1; /* [8] r/o */ + uint32_t TOF : 1; /* [9] r/o */ + uint32_t WPDIS : 1; /* [10] r/w */ + uint32_t RSVD_31_11 :21; /* [31:11] */ + } TIM_GLBSR; + + /* 0x18*/ + struct { + uint32_t ELS : 2; /* [1:0] r/w */ + uint32_t CMS : 2; /* [3:2] r/w */ + uint32_t CHIE : 1; /* [4] r/w */ + uint32_t CHF : 1; /* [5] r/o */ + uint32_t DMAEN : 1; /* [6] r/w */ + uint32_t ICRST : 1; /* [7] r/w */ + uint32_t RSVD_31_8 :24; /* [31:8] */ + } TIM_CMCn[8]; + + /* 0x38*/ + struct { + uint32_t CCV :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } TIM_CCVn[8]; + + /* 0x58*/ + struct { + uint32_t INIT0 : 1; /* [0] r/w */ + uint32_t INIT1 : 1; /* [1] r/w */ + uint32_t INIT2 : 1; /* [2] r/w */ + uint32_t INIT3 : 1; /* [3] r/w */ + uint32_t INIT4 : 1; /* [4] r/w */ + uint32_t INIT5 : 1; /* [5] r/w */ + uint32_t INIT6 : 1; /* [6] r/w */ + uint32_t INIT7 : 1; /* [7] r/w */ + uint32_t POL0 : 1; /* [8] r/w */ + uint32_t POL1 : 1; /* [9] r/w */ + uint32_t POL2 : 1; /* [10] r/w */ + uint32_t POL3 : 1; /* [11] r/w */ + uint32_t POL4 : 1; /* [12] r/w */ + uint32_t POL5 : 1; /* [13] r/w */ + uint32_t POL6 : 1; /* [14] r/w */ + uint32_t POL7 : 1; /* [15] r/w */ + uint32_t TRIGE0 : 1; /* [16] r/w */ + uint32_t TRIGE1 : 1; /* [17] r/w */ + uint32_t TRIGE2 : 1; /* [18] r/w */ + uint32_t TRIGE3 : 1; /* [19] r/w */ + uint32_t TRIGE4 : 1; /* [20] r/w */ + uint32_t TRIGE5 : 1; /* [21] r/w */ + uint32_t TRIGE6 : 1; /* [22] r/w */ + uint32_t TRIGE7 : 1; /* [23] r/w */ + uint32_t INITRIGE : 1; /* [24] r/w */ + uint32_t TRIGF : 1; /* [25] r/o */ + uint32_t RSVD_31_26 : 6; /* [31:26] */ + } TIM_OUTCR; + + /* 0x5C*/ + struct { + uint32_t CH0OC : 1; /* [0] r/w */ + uint32_t CH1OC : 1; /* [1] r/w */ + uint32_t CH2OC : 1; /* [2] r/w */ + uint32_t CH3OC : 1; /* [3] r/w */ + uint32_t CH4OC : 1; /* [4] r/w */ + uint32_t CH5OC : 1; /* [5] r/w */ + uint32_t CH6OC : 1; /* [6] r/w */ + uint32_t CH7OC : 1; /* [7] r/w */ + uint32_t CH0OCV : 1; /* [8] r/w */ + uint32_t CH1OCV : 1; /* [9] r/w */ + uint32_t CH2OCV : 1; /* [10] r/w */ + uint32_t CH3OCV : 1; /* [11] r/w */ + uint32_t CH4OCV : 1; /* [12] r/w */ + uint32_t CH5OCV : 1; /* [13] r/w */ + uint32_t CH6OCV : 1; /* [14] r/w */ + uint32_t CH7OCV : 1; /* [15] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } TIM_OUTSWCR; + + /* 0x60*/ + struct { + uint32_t FCTLEN0 : 1; /* [0] r/w */ + uint32_t DTEN0 : 1; /* [1] r/w */ + uint32_t COMB0 : 1; /* [2] r/w */ + uint32_t SYNCEN0 : 1; /* [3] r/w */ + uint32_t DECAPEN0 : 1; /* [4] r/w */ + uint32_t DECAP0 : 1; /* [5] r/w */ + uint32_t RSVD_7_6 : 2; /* [7:6] */ + uint32_t FCTLEN1 : 1; /* [8] r/w */ + uint32_t DTEN1 : 1; /* [9] r/w */ + uint32_t COMB1 : 1; /* [10] r/w */ + uint32_t SYNCEN1 : 1; /* [11] r/w */ + uint32_t DECAPEN1 : 1; /* [12] r/w */ + uint32_t DECAP1 : 1; /* [13] r/w */ + uint32_t RSVD_15_14 : 2; /* [15:14] */ + uint32_t FCTLEN2 : 1; /* [16] r/w */ + uint32_t DTEN2 : 1; /* [17] r/w */ + uint32_t COMB2 : 1; /* [18] r/w */ + uint32_t SYNCEN2 : 1; /* [19] r/w */ + uint32_t DECAPEN2 : 1; /* [20] r/w */ + uint32_t DECAP2 : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] */ + uint32_t FCTLEN3 : 1; /* [24] r/w */ + uint32_t DTEN3 : 1; /* [25] r/w */ + uint32_t COMB3 : 1; /* [26] r/w */ + uint32_t SYNCEN3 : 1; /* [27] r/w */ + uint32_t DECAPEN3 : 1; /* [28] r/w */ + uint32_t DECAP3 : 1; /* [29] r/w */ + uint32_t RSVD_31_30 : 2; /* [31:30] */ + } TIM_PCR; + + /* 0x64*/ + struct { + uint32_t FILVAL0 : 4; /* [3:0] r/w */ + uint32_t FILVAL1 : 4; /* [7:4] r/w */ + uint32_t FILVAL2 : 4; /* [11:8] r/w */ + uint32_t FILVAL3 : 4; /* [15:12] r/w */ + uint32_t DTPS : 2; /* [17:16] r/w */ + uint32_t DTVAL : 6; /* [23:18] r/w */ + uint32_t RSVD_31_24 : 8; /* [31:24] */ + } TIM_FILTER; + + /* 0x68*/ + struct { + uint32_t FAULTEN0 : 1; /* [0] r/w */ + uint32_t FIFEN0 : 1; /* [1] r/w */ + uint32_t FLTPOL0 : 1; /* [2] r/w */ + uint32_t FAULTEN1 : 1; /* [3] r/w */ + uint32_t FIFEN1 : 1; /* [4] r/w */ + uint32_t FLTPOL1 : 1; /* [5] r/w */ + uint32_t FLTIE : 1; /* [6] r/w */ + uint32_t FLTCEN : 1; /* [7] r/w */ + uint32_t FLTCM : 1; /* [8] r/w */ + uint32_t RSVD_10_9 : 2; /* [10:9] */ + uint32_t FIFVAL : 4; /* [14:11] r/w */ + uint32_t FSTATE : 1; /* [15] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } TIM_FLTCR; + + /* 0x6C*/ + struct { + uint32_t FAULTF0 : 1; /* [0] r/o */ + uint32_t FAULTF1 : 1; /* [1] r/o */ + uint32_t RSVD_3_2 : 2; /* [3:2] */ + uint32_t FAULTF : 1; /* [4] r/o */ + uint32_t FAULTIN : 1; /* [5] r/o */ + uint32_t WPEN : 1; /* [6] r/w */ + uint32_t RSVD_31_7 :25; /* [31:7] */ + } TIM_FLTSR; + + /* 0x70*/ + struct { + uint32_t SWTRIG : 1; /* [0] r/w */ + uint32_t RSVD_7_1 : 7; /* [7:1] */ + uint32_t SYNCINIT : 1; /* [8] r/w */ + uint32_t SYNCOSWC : 1; /* [9] r/w */ + uint32_t RSVD_17_10 : 8; /* [17:10] */ + uint32_t SWWRBUF : 1; /* [18] r/w */ + uint32_t SWRSTCNT : 1; /* [19] r/w */ + uint32_t RSVD_31_20 :12; /* [31:20] */ + } TIM_SYNC; + + /* 0x74*/ + struct { + uint32_t CH0SEL : 1; /* [0] r/w */ + uint32_t CH1SEL : 1; /* [1] r/w */ + uint32_t CH2SEL : 1; /* [2] r/w */ + uint32_t CH3SEL : 1; /* [3] r/w */ + uint32_t CH4SEL : 1; /* [4] r/w */ + uint32_t CH5SEL : 1; /* [5] r/w */ + uint32_t CH6SEL : 1; /* [6] r/w */ + uint32_t CH7SEL : 1; /* [7] r/w */ + uint32_t LOADEN : 1; /* [8] r/w */ + uint32_t RSVD_10_9 : 2; /* [10:9] */ + uint32_t HCSEL : 1; /* [11] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] */ + uint32_t LDFREQ : 5; /* [20:16] r/w */ + uint32_t RSVD_31_21 :11; /* [31:21] */ + } TIM_RELOAD; + + /* 0x78*/ + struct { + uint32_t HCV :16; /* [15:0] r/w */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } TIM_HCV; + +}; /*tim_reg*/ + +struct tim_reg_w { + /* 0x00*/ + uint32_t TIM_TIMEBASE; + /* 0x04*/ + uint32_t TIM_CNT; + /* 0x08*/ + uint32_t TIM_CNTINIT; + /* 0x0C*/ + uint32_t TIM_MOD; + /* 0x10*/ + uint32_t TIM_GLBCR; + /* 0x14*/ + uint32_t TIM_GLBSR; + /* 0x18*/ + uint32_t TIM_CMCn[8]; + /* 0x38*/ + uint32_t TIM_CCVn[8]; + /* 0x58*/ + uint32_t TIM_OUTCR; + /* 0x5C*/ + uint32_t TIM_OUTSWCR; + /* 0x60*/ + uint32_t TIM_PCR; + /* 0x64*/ + uint32_t TIM_FILTER; + /* 0x68*/ + uint32_t TIM_FLTCR; + /* 0x6C*/ + uint32_t TIM_FLTSR; + /* 0x70*/ + uint32_t TIM_SYNC; + /* 0x74*/ + uint32_t TIM_RELOAD; + /* 0x78*/ + uint32_t TIM_HCV; +}; /*tim_reg*/ + +typedef volatile struct tim_reg tim_reg_t; +typedef volatile struct tim_reg_w tim_reg_w_t; + +struct tmu_reg { + /* 0x0*/ + struct { + uint32_t SEL : 6; /* [5:0] r/w */ + uint32_t RSVD_6 : 1; /* [6] ro */ + uint32_t EN : 1; /* [7] r/w */ + uint32_t RSVD_30_8 :23; /* [30:8] ro */ + uint32_t LOCK : 1; /* [31] r/w */ + } TMU_CFGn[40]; + +}; /*tmu_reg*/ + +struct tmu_reg_w { + /* 0x0*/ + uint32_t TMU_CFGn[40]; +}; /*tmu_reg*/ + +typedef volatile struct tmu_reg tmu_reg_t; +typedef volatile struct tmu_reg_w tmu_reg_w_t; + +struct uart_reg { + /* 0x0*/ + union { + struct { + uint32_t RBR_LSB : 8; /* [7:0] ro */ + uint32_t RBR_MSB : 1; /* [8] ro */ + uint32_t RSVD_31_9 :23; /* [31:9] */ + } UART_RBR; + struct { + uint32_t THR_LSB : 8; /* [7:0] wo */ + uint32_t THR_MSB : 1; /* [8] wo */ + uint32_t RSVD_31_9 :23; /* [31:9] */ + } UART_THR; + struct { + uint32_t DL_L : 8; /* [7:0] r/w */ + uint32_t RSVD_31_8 :24; /* [31:8] */ + } UART_DLL; + } UART_RBR_THR_DLL; + + /* 0x4*/ + union { + struct { + uint32_t DL_H : 8; /* [7:0] r/w */ + uint32_t RSVD_31_8 :24; /* [31:8] */ + } UART_DLH; + struct { + uint32_t ERBFI : 1; /* [0] r/w */ + uint32_t ETBEI : 1; /* [1] r/w */ + uint32_t ELSI : 1; /* [2] r/w */ + uint32_t RSVD_6_3 : 4; /* [6:3] r/w */ + uint32_t PTIME : 1; /* [7] r/w */ + uint32_t HEADER_DONE_INT_EN : 1; /* [8] r/w */ + uint32_t RSP_DONE_INT_EN : 1; /* [9] r/w */ + uint32_t ASYNC_INT_EN : 1; /* [10] r/w */ + uint32_t RSVD_31_11 :21; /* [31:11] */ + } UART_IER; + } UART_DLH_IER; + + /* 0x8*/ + union { + struct { + uint32_t IID : 4; /* [3:0] ro */ + uint32_t RSVD_5_4 : 2; /* [5:4] */ + uint32_t FIFOSE : 2; /* [7:6] ro */ + uint32_t RSVD_31_8 :24; /* [31:8] */ + } UART_IIR; + struct { + uint32_t FIFOE : 1; /* [0] wo */ + uint32_t RFIFOR : 1; /* [1] wo */ + uint32_t XFIFOR : 1; /* [2] wo */ + uint32_t RSVD_3 : 1; /* [3] wo */ + uint32_t TET : 2; /* [5:4] wo */ + uint32_t RCVR : 2; /* [7:6] wo */ + uint32_t RSVD_31_8 :24; /* [31:8] */ + } UART_FCR; + } UART_IIR_FCR; + + /* 0xC*/ + struct { + uint32_t DLS : 2; /* [1:0] r/w */ + uint32_t STOP : 1; /* [2] r/w */ + uint32_t PEN : 1; /* [3 ] r/w */ + uint32_t EPS : 1; /* [4] r/w */ + uint32_t STP : 1; /* [5 ] r/w */ + uint32_t BC : 1; /* [6] r/w */ + uint32_t DLAB : 1; /* [7] r/w */ + uint32_t LBKEN : 1; /* [8] r/w */ + uint32_t LBKM : 5; /* [13:9] r/w */ + uint32_t IDLE_DET_LENGTH : 3; /* [16:14] r/w */ + uint32_t IDLE_DET_EN : 1; /* [17] r/w */ + uint32_t AUTO_SYNC_EN : 1; /* [18] r/w */ + uint32_t DEBUG_EN : 1; /* [19] r/w */ + uint32_t RSVD_31_20 :12; /* [31:20] */ + } UART_LCR; + + /* 0x10*/ + struct { + uint32_t RSVD_0 : 1; /* [0] */ + uint32_t RTS : 1; /* [1] r/w */ + uint32_t RSVD_2 : 1; /* [2] */ + uint32_t RSVD_3 : 1; /* [3 ] */ + uint32_t LB : 1; /* [4] r/w */ + uint32_t AFCE : 1; /* [5 ] r/w */ + uint32_t RSVD_6 : 1; /* [6] r/w */ + uint32_t RSVD_31_7 :25; /* [31:7] */ + } UART_AFCR; + + /* 0x14*/ + struct { + uint32_t DR : 1; /* [0] ro */ + uint32_t OE : 1; /* [1] ro */ + uint32_t PE : 1; /* [2] ro */ + uint32_t FE : 1; /* [3 ] ro */ + uint32_t BI : 1; /* [4] ro */ + uint32_t THRE : 1; /* [5 ] ro */ + uint32_t TEMT : 1; /* [6] ro */ + uint32_t RFE : 1; /* [7] ro */ + uint32_t ADDR_RCVD : 1; /* [8] ro */ + uint32_t ASYNC_INT : 1; /* [9] ro */ + uint32_t SYNC_FIELD_ERROR : 1; /* [10] ro */ + uint32_t PID_ERR : 1; /* [11] ro */ + uint32_t CHECKSUM_ERROR : 1; /* [12] ro */ + uint32_t TO_ERROR : 1; /* [13] ro */ + uint32_t HEADER_OP_DONE : 1; /* [14] ro */ + uint32_t RSP_OP_DONE : 1; /* [15] ro */ + uint32_t RSVD_31_16 :16; /* [31:16] */ + } UART_LSR; + + uint8_t zResverd0x018[100]; /*pad 0x018 - 07B*/ + + /* 0x7C*/ + struct { + uint32_t BUSY : 1; /* [0] ro */ + uint32_t RSVD_4_1 : 4; /* [4:1] */ + uint32_t RSVD_31_5 :27; /* [31:5] */ + } UART_USR; + + uint8_t zResverd0x080[40]; /*pad 0x080 - 0A7*/ + + /* 0xA8*/ + struct { + uint32_t RSVD_0 : 1; /* [0] wo */ + uint32_t RSVD_31_1 :31; /* [31:1] */ + } UART_DMA_SA; + + uint8_t zResverd0x0AC[20]; /*pad 0x0AC - 0BF*/ + + /* 0xC0*/ + struct { + uint32_t FD : 4; /* [3:0] r/w */ + uint32_t RSVD_31_4 :28; /* [31:4] */ + } UART_FD; + + /* 0xC4*/ + struct { + uint32_t RAR : 8; /* [7:0] r/w */ + uint32_t RSVD_31_8 :24; /* [31:8] */ + } UART_RAR; + + /* 0xC8*/ + struct { + uint32_t TAR : 8; /* [7:0] r/w */ + uint32_t RSVD_31_8 :24; /* [31:8] */ + } UART_TAR; + + /* 0xCC*/ + struct { + uint32_t DLS_E : 1; /* [0] r/w */ + uint32_t ADDR_MATCH : 1; /* [1] r/w */ + uint32_t SEND_ADDR : 1; /* [2] r/w */ + uint32_t TRANSMIST_MODE : 1; /* [3] r/w */ + uint32_t RSVD_31_4 :28; /* [31:4] */ + } UART_LCR_EXT; + + uint8_t zResverd0x0D0[48]; /*pad 0x0D0 - 0FF*/ + + /* 0x100*/ + struct { + uint32_t LIN_MODE : 1; /* [0] r/w */ + uint32_t MASTER_MODE : 1; /* [1] r/w */ + uint32_t HEADER_OP_START : 1; /* [2] r/w */ + uint32_t RSP_OP_START : 1; /* [3 ] r/w */ + uint32_t RSP_DIR : 1; /* [4] r/w */ + uint32_t RSVD_31_5 :27; /* [31:5] */ + } UART_LIN_CTL; + + /* 0x104*/ + struct { + uint32_t RSP_LENGTH : 4; /* [3:0] r/w */ + uint32_t RSVD_31_4 :28; /* [31:4] */ + } UART_LIN_RSP_LENGTH; + + /* 0x108*/ + struct { + uint32_t PID : 6; /* [5:0] r/w */ + uint32_t RSVD_31_6 :26; /* [31:6] */ + } UART_LIN_PID_VALUE; + + /* 0x10C*/ + struct { + uint32_t CHECKSUM_TYPE : 1; /* [0] r/w */ + uint32_t RSVD_7_1 : 7; /* [7:1] */ + uint32_t RSVD_31_8 :24; /* [31:8] */ + } UART_LIN_CHECKSUM; + + /* 0x110*/ + struct { + uint32_t LIN_DEL_LENGTH : 3; /* [2:0] r/w */ + uint32_t RSVD_31_3 :29; /* [31:3] */ + } UART_LIN_DEL_LENGTH; + + uint8_t zResverd0x114[24]; /* pad 0x114 - 12B */ + +}; /*uart_reg*/ + +struct uart_reg_w { + /* 0x0*/ + union { + uint32_t UART_RBR; + uint32_t UART_THR; + uint32_t UART_DLL; + }UART_RBR_THR_DLL; + /* 0x4*/ + union { + uint32_t UART_DLH; + uint32_t UART_IER; + }UART_DLH_IER; + /* 0x8*/ + union { + uint32_t UART_IIR; + uint32_t UART_FCR; + }UART_IIR_FCR; + /* 0xC*/ + uint32_t UART_LCR; + /* 0x10*/ + uint32_t UART_AFCR; + /* 0x14*/ + uint32_t UART_LSR; + /* 0x18*/ + uint32_t UART_MSR; + uint8_t zResverd0x01C[96]; /*pad 0x01C - 07B*/ + + /* 0x7C*/ + uint32_t UART_USR; + uint8_t zResverd0x080[40]; /*pad 0x080 - 0A7*/ + + /* 0xA8*/ + uint32_t UART_DMA_SA; + uint8_t zResverd0x0AC[20]; /*pad 0x0AC - 0BF*/ + + /* 0xC0*/ + uint32_t UART_FD; + /* 0xC4*/ + uint32_t UART_RAR; + /* 0xC8*/ + uint32_t UART_TAR; + /* 0xCC*/ + uint32_t UART_LCR_EXT; + uint8_t zResverd0x0D0[48]; /*pad 0x0D0 - 0FF*/ + + /* 0x100*/ + uint32_t UART_LIN_CTL; + /* 0x104*/ + uint32_t UART_LIN_RSP_LENGTH; + /* 0x108*/ + uint32_t UART_LIN_PID_VALUE; + /* 0x10C*/ + uint32_t UART_LIN_CHECKSUM; + /* 0x110*/ + uint32_t UART_LIN_DEL_LENGTH; + + uint8_t zResverd0x114[24]; /* pad 0x114 - 12B */ + +}; /*uart_reg*/ + +typedef volatile struct uart_reg uart_reg_t; +typedef volatile struct uart_reg_w uart_reg_w_t; + +struct wdog_reg { + /* 0x0*/ + struct { + uint32_t MINOR : 4; /* [3:0] ro */ + uint32_t MAJOR : 4; /* [7:4] ro */ + uint32_t RSVD_31_8 :24; /* [31:8] ro */ + } WDOG_VERID; + + /* 0x4*/ + struct { + uint32_t INT_PRESENT : 1; /* [0] ro */ + uint32_t RSVD_31_1 :31; /* [31:1] ro */ + } WDOG_PARAM; + + /* 0x8*/ + struct { + uint32_t WDOGE : 1; /* [0] r/w */ + uint32_t DEBUGE : 1; /* [1] r/w */ + uint32_t WAITE : 1; /* [2] r/w */ + uint32_t STOPE : 1; /* [3] r/w */ + uint32_t INTE : 1; /* [4] r/w */ + uint32_t WINE : 1; /* [5] r/w */ + uint32_t CFGUA : 1; /* [6] r/w */ + uint32_t RSVD_7 : 1; /* [7] ro */ + uint32_t CLKS : 2; /* [9:8] r/w */ + uint32_t RSVD_15_10 : 6; /* [15:10] ro */ + uint32_t TSTM : 3; /* [18:16] r/w */ + uint32_t RSVD_23_19 : 5; /* [23:19] ro */ + uint32_t CFGUF : 1; /* [24] ro */ + uint32_t UNLKF : 1; /* [25] ro */ + uint32_t INTF : 1; /* [26] r/w */ + uint32_t RSVD_31_27 : 5; /* [31:27] ro */ + } WDOG_CS; + + /* 0xC*/ + struct { + uint32_t TMO :32; /* [31:0] r/w */ + } WDOG_TMO; + + /* 0x10*/ + struct { + uint32_t WIN :32; /* [31:0] r/w */ + } WDOG_WIN; + + /* 0x14*/ + struct { + uint32_t CNT :32; /* [31:0] r/w */ + } WDOG_CNT; + +}; /*wdog_reg*/ + +struct wdog_reg_w { + /* 0x0*/ + uint32_t WDOG_VERID; + /* 0x4*/ + uint32_t WDOG_PARAM; + /* 0x8*/ + uint32_t WDOG_CS; + /* 0xC*/ + uint32_t WDOG_TMO; + /* 0x10*/ + uint32_t WDOG_WIN; + /* 0x14*/ + uint32_t WDOG_CNT; +}; /*wdog_reg*/ + +typedef volatile struct wdog_reg wdog_reg_t; +typedef volatile struct wdog_reg_w wdog_reg_w_t; + +#endif /*Z20K118M_H*/ diff --git a/Platform/Devices/Z20K118M/MakeRule/ARMC/Z20K118M_flash.scf b/Platform/Devices/Z20K118M/MakeRule/ARMC/Z20K118M_flash.scf new file mode 100644 index 0000000..b6f0c1f --- /dev/null +++ b/Platform/Devices/Z20K118M/MakeRule/ARMC/Z20K118M_flash.scf @@ -0,0 +1,39 @@ +#! armclang --target=arm-arm-none-eabi -mcpu=cortex-m0plus -xc -E +; ************************************************************* +; *** Scatter-Loading Description File *** +; ************************************************************* + +#define pflash_start 0x00000000 +#define pflash_size 0x00040000 /* 256KB */ + +#define dflash_start 0x01000000 +#define dflash_size 0x00020000 /* 128KB */ + + +#define ram0_start 0x1fffc000 +#define ram0_size 0x00004000 /* 16KB */ +#define ram0_end ram0_start + ram0_size + +#define ram1_start 0x20000000 +#define ram1_size 0x00004000 /* 16KB */ +#define ram1_end ram1_start + ram1_size + +LR_IROM1 pflash_start pflash_size { ; load region size_region + ER_IROM1 pflash_start pflash_size { ; load address = execution address + *.o (.intvec, +First) + *(InRoot$$Sections) + .ANY (+RO) + } + + RAM_START ram0_start ram0_size { ; code execution in ram + .ANY (.code_ram) + } + + RW_IRAM1 ram1_start ram1_size { ; RW data + .ANY (+RW +ZI) + } + + ARM_LIB_STACK ram1_end EMPTY -0x400 {}; Stack region growing down + ARM_LIB_HEAP ImageBase(ARM_LIB_STACK) EMPTY -0x200 {} ; heap region +} + diff --git a/Platform/Devices/Z20K118M/MakeRule/ARMC/Z20K118M_sram.scf b/Platform/Devices/Z20K118M/MakeRule/ARMC/Z20K118M_sram.scf new file mode 100644 index 0000000..20fd023 --- /dev/null +++ b/Platform/Devices/Z20K118M/MakeRule/ARMC/Z20K118M_sram.scf @@ -0,0 +1,28 @@ +#! armclang --target=arm-arm-none-eabi -mcpu=cortex-m0plus -xc -E +; ************************************************************* +; *** Scatter-Loading Description File *** +; ************************************************************* + +#define ram0_start 0x1fffc000 +#define ram0_size 0x00004000 /* 16KB */ +#define ram0_end ram0_start + ram0_size + +#define ram1_start 0x20000000 +#define ram1_size 0x00004000 /* 16KB */ +#define ram1_end ram1_start + ram1_size + +LR_IROM1 ram0_start ram0_size { ; load region size_region + ER_IROM1 ram0_start ram0_size { ; load address = execution address + *.o (.intvec, +First) + *(InRoot$$Sections) + .ANY (+RO) + } + + RAM_START ram1_start ram1_size { ; RW data + .ANY (+RW +ZI) + } + + ARM_LIB_STACK ram1_end EMPTY -0x400 {}; Stack region growing down + ARM_LIB_HEAP ImageBase(ARM_LIB_STACK) EMPTY -0x200 {} ; heap region +} + diff --git a/Platform/Devices/Z20K118M/MakeRule/GCC/Z20K118M_flash.ld b/Platform/Devices/Z20K118M/MakeRule/GCC/Z20K118M_flash.ld new file mode 100644 index 0000000..1b9be7b --- /dev/null +++ b/Platform/Devices/Z20K118M/MakeRule/GCC/Z20K118M_flash.ld @@ -0,0 +1,101 @@ +VECTOR_BASE = 0x00000000; + +HEAP_SIZE = DEFINED(__heap_size__) ? __heap_size__ : 0x00000200; +CSTACK_SIZE = DEFINED(__stack_size__) ? __stack_size__ : 0x00000400; + +MEMORY +{ + FLASH (xr) : ORIGIN = 0x00000000, LENGTH = 0x00040000 + RAM0 (xrw) : ORIGIN = 0x1fffc000, LENGTH = 0x00004000 + RAM1 (xrw) : ORIGIN = 0x20000000, LENGTH = 0x00004000 + +} + +/* Entry Point */ +ENTRY(Reset_Handler) + + +/* Sections Definitions */ + +SECTIONS +{ + .isr_vector : + { + . = ALIGN(4); + KEEP(*(.intvec)) /* Startup code */ + . = ALIGN(4); + } > FLASH + + .rom : ALIGN(4) + { + . = ALIGN(4); + *(.text) /* .text sections (code) */ + *(.text*) /* .text* sections (code) */ + *(.rodata) /* .rodata sections (constants, strings, etc.) */ + *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ + *(.glue_7) /* glue arm to thumb code */ + *(.glue_7t) /* glue thumb to arm code */ + *(.eh_frame) + KEEP (*(.init)) + KEEP (*(.fini)) + . = ALIGN(4); + } > FLASH + + __TEXT_END = .; /* global symbol at end of code */ + __DATA_ROM = .; /* Symbol used for startup for data initialization */ + + .data : AT(__DATA_ROM) + { + . = ALIGN(4); + __DATA_RAM = .; + __data_start__ = .; /* create a global symbol at data start */ + *(.data) /* .data sections */ + *(.data*) /* .data* sections */ + *(.code_ram) /*Custom section for storing code in SRAM*/ + KEEP(*(.jcr*)) + . = ALIGN(4); + __data_end__ = .; /* define a global symbol at data end */ + } > RAM1 + + __DATA_END = __DATA_ROM + SIZEOF(.data); + + .bss : + { + /* This is used by the startup in order to initialize the .bss section */ + . = ALIGN(4); + __START_BSS = .; + __bss_start__ = .; + *(.bss) + *(.bss*) + *(COMMON) + . = ALIGN(4); + __bss_end__ = .; + __END_BSS = .; + } > RAM1 + + .heap : + { + . = ALIGN(8); + __end__ = .; + PROVIDE(end = .); + __HeapBase = .; + . += HEAP_SIZE; + __HeapLimit = .; + } > RAM1 + + /* Initializes stack on the end of block */ + __StackTop = ORIGIN(RAM1) + LENGTH(RAM1); + __StackLimit = __StackTop - CSTACK_SIZE; + PROVIDE(CSTACK = __StackTop); + + .stack __StackLimit : + { + . = ALIGN(8); + __stack_start__ = .; + . += CSTACK_SIZE; + __stack_end__ = .; + } > RAM1 + + __RAM_START = ORIGIN(RAM0); + __RAM_END = __StackTop - 1; +} diff --git a/Platform/Devices/Z20K118M/MakeRule/GCC/Z20K118M_sram.ld b/Platform/Devices/Z20K118M/MakeRule/GCC/Z20K118M_sram.ld new file mode 100644 index 0000000..60f9c08 --- /dev/null +++ b/Platform/Devices/Z20K118M/MakeRule/GCC/Z20K118M_sram.ld @@ -0,0 +1,102 @@ +VECTOR_BASE = 0x1fffc000; + +HEAP_SIZE = DEFINED(__heap_size__) ? __heap_size__ : 0x00000200; +CSTACK_SIZE = DEFINED(__stack_size__) ? __stack_size__ : 0x00000400; + +MEMORY +{ + RAM0 (xr) : ORIGIN = 0x1fffc000, LENGTH = 0x00004000 + RAM1 (xrw) : ORIGIN = 0x20000000, LENGTH = 0x00004000 + +} + +/* Entry Point */ +ENTRY(Reset_Handler) + + +/* Sections Definitions */ + +SECTIONS +{ + + /* The startup code goes first into internal RAM */ + .isr_vector : + { + . = ALIGN(4); + KEEP(*(.intvec)) /* Startup code */ + . = ALIGN(4); + } > RAM0 + + + .rom : ALIGN(4) + { + . = ALIGN(4); + *(.text) /* .text sections (code) */ + *(.text*) /* .text* sections (code) */ + *(.rodata) /* .rodata sections (constants, strings, etc.) */ + *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ + *(.glue_7) /* glue arm to thumb code */ + *(.glue_7t) /* glue thumb to arm code */ + *(.eh_frame) + KEEP (*(.init)) + KEEP (*(.fini)) + . = ALIGN(4); + } > RAM0 + + __TEXT_END = .; /* global symbol at end of code */ + __DATA_ROM = .; /* Symbol used for startup for data initialization */ + + + .data : AT(__DATA_ROM) + { + . = ALIGN(4); + __DATA_RAM = .; + __data_start__ = .; /* create a global symbol at data start */ + *(.data) /* .data sections */ + *(.data*) /* .data* sections */ + KEEP(*(.jcr*)) + . = ALIGN(4); + __data_end__ = .; /* define a global symbol at data end */ + } > RAM1 + + __DATA_END = __DATA_ROM + SIZEOF(.data); + + .bss : + { + /* This is used by the startup in order to initialize the .bss section */ + . = ALIGN(4); + __START_BSS = .; + __bss_start__ = .; + *(.bss) + *(.bss*) + *(COMMON) + . = ALIGN(4); + __bss_end__ = .; + __END_BSS = .; + } > RAM1 + + .heap : + { + . = ALIGN(8); + __end__ = .; + PROVIDE(end = .); + __HeapBase = .; + . += HEAP_SIZE; + __HeapLimit = .; + __heap_limit = .; + } > RAM1 + + /* Initializes stack on the end of block */ + __StackTop = ORIGIN(RAM1) + LENGTH(RAM1); + __StackLimit = __StackTop - CSTACK_SIZE; + PROVIDE(CSTACK = __StackTop); + + .stack __StackLimit : + { + . = ALIGN(8); + . += CSTACK_SIZE; + } > RAM1 + + __RAM_START = ORIGIN(RAM0); + __RAM_END = __StackTop - 1; +} diff --git a/Platform/Devices/Z20K118M/MakeRule/IAR/Z20K118M_flash.icf b/Platform/Devices/Z20K118M/MakeRule/IAR/Z20K118M_flash.icf new file mode 100644 index 0000000..dedce12 --- /dev/null +++ b/Platform/Devices/Z20K118M/MakeRule/IAR/Z20K118M_flash.icf @@ -0,0 +1,52 @@ +/*###ICF### Section handled by ICF editor, don't touch! ****/ +/*-Editor annotation file-*/ +/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */ +/*-Specials-*/ +define symbol __ICFEDIT_intvec_start__ = 0x00000000; +/*-Memory Regions-*/ +define symbol __ICFEDIT_region_ROM_start__ = 0x00000000; +define symbol __ICFEDIT_region_ROM_end__ = 0x0003FFFF; /* 256KB */ + +define symbol DFLASH_BASE = 0x01000000; +define symbol DFLASH_SIZE = 0x00020000; /* 128KB */ + +define symbol __ICFEDIT_region_RAM_start__ = 0x1fffc000; +define symbol __ICFEDIT_region_RAM_end__ = 0x1FFFFFFF; /* 16KB */ + +define symbol RAM1_BASE = 0x20000000; +define symbol RAM1_SIZE = 0x00004000; /* 16KB */ +define symbol RAM1_END = RAM1_BASE + RAM1_SIZE - 1; + +define symbol __ICFEDIT_size_cstack__ = 0x00000400; +define symbol __ICFEDIT_size_heap__ = 0x00000200; + +/**** End of ICF editor section. ###ICF###*/ + +define exported symbol __RAM_START = __ICFEDIT_region_RAM_start__; +define exported symbol __RAM_END = RAM1_END; + +/* memory range */ +define memory mem with size = 4G; + +define region PFLASH_region = mem:[from __ICFEDIT_region_ROM_start__ to __ICFEDIT_region_ROM_end__]; +define region DFLASH_region = mem:[from DFLASH_BASE size DFLASH_SIZE]; +define region RAM0_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFEDIT_region_RAM_end__]; +define region RAM1_region = mem:[from RAM1_BASE size RAM1_SIZE]; + +/* definition of RAM blocks */ +define block CSTACK with size = __ICFEDIT_size_cstack__, alignment = 8 { }; +define block HEAP with size = __ICFEDIT_size_heap__, alignment = 8 { }; + +initialize by copy { readwrite }; +do not initialize { section .noinit }; + +place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec }; + +place in PFLASH_region { readonly }; + +place in RAM0_region { section .textrw}; + +place at end of RAM1_region { block HEAP, + block CSTACK }; + +place in RAM1_region { readwrite }; diff --git a/Platform/Devices/Z20K118M/MakeRule/IAR/Z20K118M_sram.icf b/Platform/Devices/Z20K118M/MakeRule/IAR/Z20K118M_sram.icf new file mode 100644 index 0000000..76f7751 --- /dev/null +++ b/Platform/Devices/Z20K118M/MakeRule/IAR/Z20K118M_sram.icf @@ -0,0 +1,42 @@ +/*###ICF### Section handled by ICF editor, don't touch! ****/ +/*-Editor annotation file-*/ +/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */ +/*-Specials-*/ +define symbol __ICFEDIT_intvec_start__ = 0x1fffc000; +/*-Memory Regions-*/ +define symbol __ICFEDIT_region_RAM_start__ = 0x1fffc000; +define symbol __ICFEDIT_region_RAM_end__ = 0x1FFFFFFF; /* 16KB */ + +define symbol RAM1_BASE = 0x20000000; +define symbol RAM1_SIZE = 0x00004000; /* 16KB */ +define symbol RAM1_END = RAM1_BASE + RAM1_SIZE - 1; + +define symbol __ICFEDIT_size_cstack__ = 0x00000400; +define symbol __ICFEDIT_size_heap__ = 0x00000200; + +/**** End of ICF editor section. ###ICF###*/ + +define exported symbol __RAM_START = __ICFEDIT_region_RAM_start__; +define exported symbol __RAM_END = RAM1_END; + +/* memory range */ +define memory mem with size = 4G; + +define region RAM0_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFEDIT_region_RAM_end__]; +define region RAM1_region = mem:[from RAM1_BASE size RAM1_SIZE]; + +/* definition of RAM blocks */ +define block CSTACK with size = __ICFEDIT_size_cstack__, alignment = 8 { }; +define block HEAP with size = __ICFEDIT_size_heap__, alignment = 8 { }; + +initialize by copy { readwrite }; +do not initialize { section .noinit }; + +place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec }; + +place in RAM0_region { readonly }; + +place at end of RAM1_region { block HEAP, + block CSTACK }; + +place in RAM1_region { readwrite }; diff --git a/Platform/Devices/Z20K118M/Startup/ARMC/Z20K118M_startup.s b/Platform/Devices/Z20K118M/Startup/ARMC/Z20K118M_startup.s new file mode 100644 index 0000000..1f3ebef --- /dev/null +++ b/Platform/Devices/Z20K118M/Startup/ARMC/Z20K118M_startup.s @@ -0,0 +1,456 @@ +; --------------------------------------------------------------------------- +; @file: : Z20K118M_startup.s +; @brief: : Z20K118M startup and Vector Table Source File for ARM Compiler +; @version : V1.8.0 +; @date : May-2020 +; @author : Zhixin Semiconductor +; +; @note +; @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. +; --------------------------------------------------------------------------- + + + PRESERVE8 + THUMB + + + AREA |.text|, CODE, READONLY + EXPORT __vector_table + EXPORT __Vectors_End + EXPORT __Vectors_Size + + IMPORT __main + + IMPORT |Image$$ARM_LIB_STACK$$ZI$$Limit| + + + IF :LNOT: :DEF:START_FROM_SRAM + IMPORT |Image$$RAM_START$$Base| +__RAM_START DCD |Image$$RAM_START$$Base| +__RAM_END DCD |Image$$ARM_LIB_STACK$$ZI$$Limit| + ENDIF + + + AREA |.intvec|, DATA, READONLY +__vector_table + DCD |Image$$ARM_LIB_STACK$$ZI$$Limit| ; Top of Stack + DCD Reset_Handler ; POR Reset Entry + DCD NMI_Handler ; Non Maskable handler + DCD HardFault_Handler ; SV Hard Fault handler + DCD 0 + DCD 0 + DCD 0 + DCD 0 + DCD 0 + DCD 0 + DCD 0 + DCD SVC_Handler ; SV Call handler + DCD 0 + DCD 0 + DCD PendSV_Handler ; Pend SV handler + DCD SysTick_Handler ; System Tick handler + + + DCD DMA0TO3_IRQHandler ; irq 0 : DMA channel 0 - 3 transfer complete IRQHandler + DCD DMA4TO7_IRQHandler ; irq 1 : DMA channel 4 - 7 transfer complete IRQHandler + DCD DMA8TO11_IRQHandler ; irq 2 : DMA channel 8 - 11 transfer complete IRQHandler + DCD DMA12TO15_IRQHandler ; irq 3 : DMA channel 12 - 15 transfer complete IRQHandler + DCD DMAERR_IRQHandler ; irq 4 : DMA error interrupt channels 0-7 IRQHandler + DCD I2C0_IRQHandler ; irq 5 : I2C 0 IRQHandler + DCD I2C1_IRQHandler ; irq 6 : I2C 1 IRQHandler + DCD SPI0_IRQHandler ; irq 7 : SPI 0 IRQHandler + DCD SPI1_IRQHandler ; irq 8 : SPI 1 IRQHandler + DCD SPI2_IRQHandler ; irq 9 : SPI 2 IRQHandler + DCD UART0_IRQHandler ; irq 10 : UART 0 IRQHandler + DCD UART1_IRQHandler ; irq 11 : UART 1 IRQHandler + DCD UART2_IRQHandler ; irq 12 : UART2 IRQHandler + DCD UART3_IRQHandler ; irq 13 : UART3 IRQHandler + DCD ADC0_IRQHandler ; irq 14 : ADC0 IRQHandler + DCD FLASH_IRQHandler ; irq 15 : flash memory IRQHandler + DCD CMP_IRQHandler ; irq 16 : CMP IRQHandler + DCD TIM0_IRQHandler ; irq 17 : TIM 0 IRQHandler + DCD TIM1_IRQHandler ; irq 18 : TIM 1 IRQHandler + DCD TIM2_IRQHandler ; irq 19 : TIM 2 IRQHandler + DCD CAN0_IRQHandler ; irq 20 : CAN 0 IRQHandler + DCD CAN1_IRQHandler ; irq 21 : CAN 1 IRQHandler + DCD RTC_IRQHandler ; irq 22 : RTC IRQHandler + DCD PMU_IRQHandler ; irq 23 : PMU IRQHandler + DCD TDG0_IRQHandler ; irq 24 : TDG0 IRQHandler + DCD SCC_IRQHandler ; irq 25 : system clock controller IRQHandler + DCD WDOG_IRQHandler ; irq 26 : watchdog IRQHandler + DCD EWDT_IRQHandler ; irq 27 : external watchdog monitor IRQHandler + DCD STIM_IRQHandler ; irq 28 : STIM IRQHandler + DCD SRMC_IRQHandler ; irq 29 : system reset and mode control IRQHandler + DCD PORTABC_IRQHandler ; irq 30 : port A B C IRQHandler + DCD PORTDE_IRQHandler ; irq 31 : port D E IRQHandler +__Vectors_End + +__Vectors_Size EQU __Vectors_End - __vector_table + + + AREA |.text|, CODE, READONLY + +Reset_Handler PROC + ALIGN 4 + EXPORT Reset_Handler [WEAK] + + CPSID I ; Mask interrupts + + IF :LNOT: :DEF:START_FROM_SRAM + ; Init ECC RAM + LDR R1, =__RAM_START + LDR R1, [R1] + LDR R2, =__RAM_END + LDR R2, [R2] + SUBS R2, R1 + SUBS R2, #1 + BLE LC2 + + MOVS R0, #0 + MOVS R3, #4 +LC1 + STR R0, [R1] + ADD R1, R1, R3 + SUBS R2, #4 + BGE LC1 +LC2 + NOP + ENDIF + + LDR R0, =0xE000ED08 + LDR R1, =__vector_table + STR R1, [R0] + LDR R2, [R1] + MSR MSP, R2 + CPSIE i ; Unmask interrupts + LDR R0, =__main + BLX R0 + ENDP + +NMI_Handler\ + PROC + EXPORT NMI_Handler [WEAK] + B . + ENDP + +HardFault_Handler\ + PROC + EXPORT HardFault_Handler [WEAK] + B . + ENDP + +SVC_Handler\ + PROC + EXPORT SVC_Handler [WEAK] + B . + ENDP + +PendSV_Handler\ + PROC + EXPORT PendSV_Handler [WEAK] + B . + ENDP + +SysTick_Handler\ + PROC + EXPORT SysTick_Handler [WEAK] + B . + ENDP + +DMA0TO3_IRQHandler\ + PROC + EXPORT DMA0TO3_IRQHandler [WEAK] + LDR R0, =DMA0TO3_DriverIRQHandler + BX R0 + ENDP + +DMA4TO7_IRQHandler\ + PROC + EXPORT DMA4TO7_IRQHandler [WEAK] + LDR R0, =DMA4TO7_DriverIRQHandler + BX R0 + ENDP + +DMA8TO11_IRQHandler\ + PROC + EXPORT DMA8TO11_IRQHandler [WEAK] + LDR R0, =DMA8TO11_DriverIRQHandler + BX R0 + ENDP + +DMA12TO15_IRQHandler\ + PROC + EXPORT DMA12TO15_IRQHandler [WEAK] + LDR R0, =DMA12TO15_DriverIRQHandler + BX R0 + ENDP + +DMAERR_IRQHandler\ + PROC + EXPORT DMAERR_IRQHandler [WEAK] + LDR R0, =DMAERR_DriverIRQHandler + BX R0 + ENDP + +I2C0_IRQHandler\ + PROC + EXPORT I2C0_IRQHandler [WEAK] + LDR R0, =I2C0_DriverIRQHandler + BX R0 + ENDP + +I2C1_IRQHandler\ + PROC + EXPORT I2C1_IRQHandler [WEAK] + LDR R0, =I2C1_DriverIRQHandler + BX R0 + ENDP + +SPI0_IRQHandler\ + PROC + EXPORT SPI0_IRQHandler [WEAK] + LDR R0, =SPI0_DriverIRQHandler + BX R0 + ENDP + +SPI1_IRQHandler\ + PROC + EXPORT SPI1_IRQHandler [WEAK] + LDR R0, =SPI1_DriverIRQHandler + BX R0 + ENDP + +SPI2_IRQHandler\ + PROC + EXPORT SPI2_IRQHandler [WEAK] + LDR R0, =SPI2_DriverIRQHandler + BX R0 + ENDP + +UART0_IRQHandler\ + PROC + EXPORT UART0_IRQHandler [WEAK] + LDR R0, =UART0_DriverIRQHandler + BX R0 + ENDP + +UART1_IRQHandler\ + PROC + EXPORT UART1_IRQHandler [WEAK] + LDR R0, =UART1_DriverIRQHandler + BX R0 + ENDP + +UART2_IRQHandler\ + PROC + EXPORT UART2_IRQHandler [WEAK] + LDR R0, =UART2_DriverIRQHandler + BX R0 + ENDP + +UART3_IRQHandler\ + PROC + EXPORT UART3_IRQHandler [WEAK] + LDR R0, =UART3_DriverIRQHandler + BX R0 + ENDP + +ADC0_IRQHandler\ + PROC + EXPORT ADC0_IRQHandler [WEAK] + LDR R0, =ADC0_DriverIRQHandler + BX R0 + ENDP + +FLASH_IRQHandler\ + PROC + EXPORT FLASH_IRQHandler [WEAK] + LDR R0, =FLASH_DriverIRQHandler + BX R0 + ENDP + +CMP_IRQHandler\ + PROC + EXPORT CMP_IRQHandler [WEAK] + LDR R0, =CMP_DriverIRQHandler + BX R0 + ENDP + +TIM0_IRQHandler\ + PROC + EXPORT TIM0_IRQHandler [WEAK] + LDR R0, =TIM0_DriverIRQHandler + BX R0 + ENDP + +TIM1_IRQHandler\ + PROC + EXPORT TIM1_IRQHandler [WEAK] + LDR R0, =TIM1_DriverIRQHandler + BX R0 + ENDP + +TIM2_IRQHandler\ + PROC + EXPORT TIM2_IRQHandler [WEAK] + LDR R0, =TIM2_DriverIRQHandler + BX R0 + ENDP + +CAN0_IRQHandler\ + PROC + EXPORT CAN0_IRQHandler [WEAK] + LDR R0, =CAN0_DriverIRQHandler + BX R0 + ENDP + +CAN1_IRQHandler\ + PROC + EXPORT CAN1_IRQHandler [WEAK] + LDR R0, =CAN1_DriverIRQHandler + BX R0 + ENDP + +RTC_IRQHandler\ + PROC + EXPORT RTC_IRQHandler [WEAK] + LDR R0, =RTC_DriverIRQHandler + BX R0 + ENDP + +PMU_IRQHandler\ + PROC + EXPORT PMU_IRQHandler [WEAK] + LDR R0, =PMU_DriverIRQHandler + BX R0 + ENDP + +TDG0_IRQHandler\ + PROC + EXPORT TDG0_IRQHandler [WEAK] + LDR R0, =TDG0_DriverIRQHandler + BX R0 + ENDP + +SCC_IRQHandler\ + PROC + EXPORT SCC_IRQHandler [WEAK] + LDR R0, =SCC_DriverIRQHandler + BX R0 + ENDP + +WDOG_IRQHandler\ + PROC + EXPORT WDOG_IRQHandler [WEAK] + LDR R0, =WDOG_DriverIRQHandler + BX R0 + ENDP + +EWDT_IRQHandler\ + PROC + EXPORT EWDT_IRQHandler [WEAK] + LDR R0, =EWDT_DriverIRQHandler + BX R0 + ENDP + +STIM_IRQHandler\ + PROC + EXPORT STIM_IRQHandler [WEAK] + LDR R0, =STIM_DriverIRQHandler + BX R0 + ENDP + +SRMC_IRQHandler\ + PROC + EXPORT SRMC_IRQHandler [WEAK] + LDR R0, =SRMC_DriverIRQHandler + BX R0 + ENDP + +PORTABC_IRQHandler\ + PROC + EXPORT PORTABC_IRQHandler [WEAK] + LDR R0, =PORTABC_DriverIRQHandler + BX R0 + ENDP + +PORTDE_IRQHandler\ + PROC + EXPORT PORTDE_IRQHandler [WEAK] + LDR R0, =PORTDE_DriverIRQHandler + BX R0 + ENDP + +Default_Handler PROC + EXPORT DMA0TO3_DriverIRQHandler [WEAK] + EXPORT DMA4TO7_DriverIRQHandler [WEAK] + EXPORT DMA8TO11_DriverIRQHandler [WEAK] + EXPORT DMA12TO15_DriverIRQHandler [WEAK] + EXPORT DMAERR_DriverIRQHandler [WEAK] + EXPORT I2C0_DriverIRQHandler [WEAK] + EXPORT I2C1_DriverIRQHandler [WEAK] + EXPORT SPI0_DriverIRQHandler [WEAK] + EXPORT SPI1_DriverIRQHandler [WEAK] + EXPORT SPI2_DriverIRQHandler [WEAK] + EXPORT UART0_DriverIRQHandler [WEAK] + EXPORT UART1_DriverIRQHandler [WEAK] + EXPORT UART2_DriverIRQHandler [WEAK] + EXPORT UART3_DriverIRQHandler [WEAK] + EXPORT ADC0_DriverIRQHandler [WEAK] + EXPORT FLASH_DriverIRQHandler [WEAK] + EXPORT CMP_DriverIRQHandler [WEAK] + EXPORT TIM0_DriverIRQHandler [WEAK] + EXPORT TIM1_DriverIRQHandler [WEAK] + EXPORT TIM2_DriverIRQHandler [WEAK] + EXPORT CAN0_DriverIRQHandler [WEAK] + EXPORT CAN1_DriverIRQHandler [WEAK] + EXPORT RTC_DriverIRQHandler [WEAK] + EXPORT PMU_DriverIRQHandler [WEAK] + EXPORT TDG0_DriverIRQHandler [WEAK] + EXPORT SCC_DriverIRQHandler [WEAK] + EXPORT WDOG_DriverIRQHandler [WEAK] + EXPORT EWDT_DriverIRQHandler [WEAK] + EXPORT STIM_DriverIRQHandler [WEAK] + EXPORT SRMC_DriverIRQHandler [WEAK] + EXPORT PORTABC_DriverIRQHandler [WEAK] + EXPORT PORTDE_DriverIRQHandler [WEAK] + +DMA0TO3_DriverIRQHandler +DMA4TO7_DriverIRQHandler +DMA8TO11_DriverIRQHandler +DMA12TO15_DriverIRQHandler +DMAERR_DriverIRQHandler +I2C0_DriverIRQHandler +I2C1_DriverIRQHandler +SPI0_DriverIRQHandler +SPI1_DriverIRQHandler +SPI2_DriverIRQHandler +UART0_DriverIRQHandler +UART1_DriverIRQHandler +UART2_DriverIRQHandler +UART3_DriverIRQHandler +ADC0_DriverIRQHandler +FLASH_DriverIRQHandler +CMP_DriverIRQHandler +TIM0_DriverIRQHandler +TIM1_DriverIRQHandler +TIM2_DriverIRQHandler +CAN0_DriverIRQHandler +CAN1_DriverIRQHandler +RTC_DriverIRQHandler +PMU_DriverIRQHandler +TDG0_DriverIRQHandler +SCC_DriverIRQHandler +WDOG_DriverIRQHandler +EWDT_DriverIRQHandler +STIM_DriverIRQHandler +SRMC_DriverIRQHandler +PORTABC_DriverIRQHandler +PORTDE_DriverIRQHandler + + B . + + ENDP + + ALIGN + END \ No newline at end of file diff --git a/Platform/Devices/Z20K118M/Startup/GCC/Z20K118M_startup.S b/Platform/Devices/Z20K118M/Startup/GCC/Z20K118M_startup.S new file mode 100644 index 0000000..5f9d893 --- /dev/null +++ b/Platform/Devices/Z20K118M/Startup/GCC/Z20K118M_startup.S @@ -0,0 +1,554 @@ +/****************************************************************************************/ +/* @file : Z20K118M_startup.s */ +/* @brief : Z20K118M Device Vector Table Source File. */ +/* @version : V1.8.0 */ +/* @date : May-2020 */ +/* @author : Zhixin Semiconductor */ +/* */ +/* @note */ +/* @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. */ +/****************************************************************************************/ + .syntax unified + .arch armv6-m + + .section .isr_vector, "a" + .align 2 + .globl __isr_vector +__isr_vector: + .long __StackTop /* Stack */ + .long Reset_Handler /*!< POR Reset Entry */ + .long NMI_Handler /*!< NMI handler */ + .long HardFault_Handler /*!< Hard Fault Handler */ + .long 0 + .long 0 + .long 0 + .long 0 + .long 0 + .long 0 + .long 0 /*!< Reserved 7 Handlers */ + .long SVC_Handler /*!< SVC Handler */ + .long 0 + .long 0 /*!< Reserved 2 Handler */ + .long PendSV_Handler /*!< PendSV Handler */ + .long SysTick_Handler /*!< SysTick Handler */ + + /* Zhixin specific interrupt */ + .long DMA0TO3_IRQHandler /*!< irq 0 : DMA channel 0 - 3 transfer complete ISR */ + .long DMA4TO7_IRQHandler /*!< irq 1 : DMA channel 4 - 7 transfer complete ISR */ + .long DMA8TO11_IRQHandler /*!< irq 2 : DMA channel 8 - 11 transfer complete ISR */ + .long DMA12TO15_IRQHandler /*!< irq 3 : DMA channel 12 - 15 transfer complete ISR */ + .long DMAERR_IRQHandler /*!< irq 4 : DMA error interrupt channels 0-7 ISR */ + .long I2C0_IRQHandler /*!< irq 5 : I2C 0 ISR */ + .long I2C1_IRQHandler /*!< irq 6 : I2C 1 ISR */ + .long SPI0_IRQHandler /*!< irq 7 : SPI 0 ISR */ + .long SPI1_IRQHandler /*!< irq 8 : SPI 1 ISR */ + .long SPI2_IRQHandler /*!< irq 9 : SPI 2 ISR */ + .long UART0_IRQHandler /*!< irq 10 : UART 0 ISR */ + .long UART1_IRQHandler /*!< irq 11 : UART 1 ISR */ + .long UART2_IRQHandler /*!< irq 12 : UART2 ISR */ + .long UART3_IRQHandler /*!< irq 13 : UART3 ISR */ + .long ADC0_IRQHandler /*!< irq 14 : ADC0 ISR */ + .long FLASH_IRQHandler /*!< irq 15 : flash memory ISR */ + .long CMP_IRQHandler /*!< irq 16 : CMP ISR */ + .long TIM0_IRQHandler /*!< irq 17 : TIM 0 ISR */ + .long TIM1_IRQHandler /*!< irq 18 : TIM 1 ISR */ + .long TIM2_IRQHandler /*!< irq 19 : TIM 2 ISR */ + .long CAN0_IRQHandler /*!< irq 20 : CAN 0 ISR */ + .long CAN1_IRQHandler /*!< irq 21 : CAN 1 ISR */ + .long RTC_IRQHandler /*!< irq 22 : RTC ISR */ + .long PMU_IRQHandler /*!< irq 23 : PMU ISR */ + .long TDG0_IRQHandler /*!< irq 24 : TDG0 ISR */ + .long SCC_IRQHandler /*!< irq 25 : system clock controller ISR */ + .long WDOG_IRQHandler /*!< irq 26 : watchdog ISR */ + .long EWDT_IRQHandler /*!< irq 27 : external watchdog monitor ISR */ + .long STIM_IRQHandler /*!< irq 28 : STIM ISR */ + .long SRMC_IRQHandler /*!< irq 29 : system reset and mode control ISR */ + .long PORTABC_IRQHandler /*!< irq 30 : port A B C ISR */ + .long PORTDE_IRQHandler /*!< irq 31 : port D E ISR */ + + .size __isr_vector, . - __isr_vector + + .text + .thumb + +/* Reset_Handler Entry */ + .thumb_func + .align 2 + .globl Reset_Handler + .weak Reset_Handler + .type Reset_Handler, %function +Reset_Handler: + cpsid i /* Mask interrupts */ + .equ VTOR, 0xE000ED08 + ldr r0, =VTOR + ldr r1, =__isr_vector + str r1, [r0] + ldr r2, [r1] + msr msp, r2 + +#ifndef START_FROM_SRAM + /* Clean SRAM ECC */ + ldr r1, =__RAM_START + ldr r2, =__RAM_END + + subs r2, r1 + subs r2, #1 + ble .LB2 + + movs r0, 0 + movs r3, #4 +.LB1: + str r0, [r1] + add r1, r1, r3 + subs r2, 4 + bge .LB1 +.LB2: +#endif + + + ldr r1, =__DATA_ROM + ldr r2, =__data_start__ + ldr r3, =__data_end__ + +/* Copy data from flash to SRAM.*/ +.DATA_LOOP: + cmp r2, r3 + bge .DATA_LOOP_DONE + ldr r0, [r1] + adds r1, #4 + str r0, [r2] + adds r2, #4 + b .DATA_LOOP + +.DATA_LOOP_DONE: +/* Copy bss from flash to SRAM.*/ + ldr r1, =__bss_start__ + ldr r2, =__bss_end__ + + movs r0, 0 +.BSS_LOOP: + cmp r1, r2 + bge .BSS_LOOP_DONE + str r0, [r1] + adds r1, #4 + b .BSS_LOOP + +.BSS_LOOP_DONE: + cpsie i /* Unmask interrupts */ + + ldr r0,=main + bx r0 + + .pool + .size Reset_Handler, . - Reset_Handler + + .align 1 + .thumb_func + .weak JumpToSelf + .type JumpToSelf, %function +JumpToSelf: + b JumpToSelf + .size JumpToSelf, . - JumpToSelf + + .align 1 + .thumb_func + .weak NMI_Handler + .type NMI_Handler, %function +NMI_Handler: + b . + .size NMI_Handler, . - NMI_Handler + + .align 1 + .thumb_func + .weak HardFault_Handler + .type HardFault_Handler, %function +HardFault_Handler: + b . + .size HardFault_Handler, . - HardFault_Handler + + .align 1 + .thumb_func + .weak HardFault_Handler + .type HardFault_Handler, %function +MemManageFault_Handler: + b . + .size MemManageFault_Handler, . - MemManageFault_Handler + + .align 1 + .thumb_func + .weak HardFault_Handler + .type HardFault_Handler, %function +BusFault_Handler: + b . + .size BusFault_Handler, . - BusFault_Handler + + .align 1 + .thumb_func + .weak HardFault_Handler + .type HardFault_Handler, %function +UsageFault_Handler: + b . + .size UsageFault_Handler, . - UsageFault_Handler + + .align 1 + .thumb_func + .weak SVC_Handler + .type SVC_Handler, %function +SVC_Handler: + b . + .size SVC_Handler, . - SVC_Handler + + .align 1 + .thumb_func + .weak SVC_Handler + .type SVC_Handler, %function +DebugMonitor_Handler: + b . + .size DebugMonitor_Handler, . - DebugMonitor_Handler + + .align 1 + .thumb_func + .weak PendSV_Handler + .type PendSV_Handler, %function +PendSV_Handler: + b . + .size PendSV_Handler, . - PendSV_Handler + + .align 1 + .thumb_func + .weak SysTick_Handler + .type SysTick_Handler, %function +SysTick_Handler: + b . + .size SysTick_Handler, . - SysTick_Handler + + .align 1 + .thumb_func + .weak DMA0TO3_IRQHandler + .type DMA0TO3_IRQHandler, %function +DMA0TO3_IRQHandler: + ldr r0,=DMA0TO3_DriverIRQHandler + bx r0 + .size DMA0TO3_IRQHandler, . - DMA0TO3_IRQHandler + + .align 1 + .thumb_func + .weak DMA4TO7_IRQHandler + .type DMA4TO7_IRQHandler, %function +DMA4TO7_IRQHandler: + ldr r0,=DMA4TO7_DriverIRQHandler + bx r0 + .size DMA4TO7_IRQHandler, . - DMA4TO7_IRQHandler + + .align 1 + .thumb_func + .weak DMA8TO11_IRQHandler + .type DMA8TO11_IRQHandler, %function +DMA8TO11_IRQHandler: + ldr r0,=DMA8TO11_DriverIRQHandler + bx r0 + .size DMA8TO11_IRQHandler, . - DMA8TO11_IRQHandler + + .align 1 + .thumb_func + .weak DMA12TO15_IRQHandler + .type DMA12TO15_IRQHandler, %function +DMA12TO15_IRQHandler: + ldr r0,=DMA12TO15_DriverIRQHandler + bx r0 + .size DMA12TO15_IRQHandler, . - DMA12TO15_IRQHandler + + .align 1 + .thumb_func + .weak DMAERR_IRQHandler + .type DMAERR_IRQHandler, %function +DMAERR_IRQHandler: + ldr r0,=DMAERR_DriverIRQHandler + bx r0 + .size DMAERR_IRQHandler, . - DMAERR_IRQHandler + + .align 1 + .thumb_func + .weak I2C0_IRQHandler + .type I2C0_IRQHandler, %function +I2C0_IRQHandler: + ldr r0,=I2C0_DriverIRQHandler + bx r0 + .size I2C0_IRQHandler, . - I2C0_IRQHandler + + .align 1 + .thumb_func + .weak I2C1_IRQHandler + .type I2C1_IRQHandler, %function +I2C1_IRQHandler: + ldr r0,=I2C1_DriverIRQHandler + bx r0 + .size I2C1_IRQHandler, . - I2C1_IRQHandler + + .align 1 + .thumb_func + .weak SPI0_IRQHandler + .type SPI0_IRQHandler, %function +SPI0_IRQHandler: + ldr r0,=SPI0_DriverIRQHandler + bx r0 + .size SPI0_IRQHandler, . - SPI0_IRQHandler + + .align 1 + .thumb_func + .weak SPI1_IRQHandler + .type SPI1_IRQHandler, %function +SPI1_IRQHandler: + ldr r0,=SPI1_DriverIRQHandler + bx r0 + .size SPI1_IRQHandler, . - SPI1_IRQHandler + + .align 1 + .thumb_func + .weak SPI2_IRQHandler + .type SPI2_IRQHandler, %function +SPI2_IRQHandler: + ldr r0,=SPI2_DriverIRQHandler + bx r0 + .size SPI2_IRQHandler, . - SPI2_IRQHandler + + .align 1 + .thumb_func + .weak UART0_IRQHandler + .type UART0_IRQHandler, %function +UART0_IRQHandler: + ldr r0,=UART0_DriverIRQHandler + bx r0 + .size UART0_IRQHandler, . - UART0_IRQHandler + + .align 1 + .thumb_func + .weak UART1_IRQHandler + .type UART1_IRQHandler, %function +UART1_IRQHandler: + ldr r0,=UART1_DriverIRQHandler + bx r0 + .size UART1_IRQHandler, . - UART1_IRQHandler + + .align 1 + .thumb_func + .weak UART2_IRQHandler + .type UART2_IRQHandler, %function +UART2_IRQHandler: + ldr r0,=UART2_DriverIRQHandler + bx r0 + .size UART2_IRQHandler, . - UART2_IRQHandler + + .align 1 + .thumb_func + .weak UART3_IRQHandler + .type UART3_IRQHandler, %function +UART3_IRQHandler: + ldr r0,=UART3_DriverIRQHandler + bx r0 + .size UART3_IRQHandler, . - UART3_IRQHandler + + .align 1 + .thumb_func + .weak ADC0_IRQHandler + .type ADC0_IRQHandler, %function +ADC0_IRQHandler: + ldr r0,=ADC0_DriverIRQHandler + bx r0 + .size ADC0_IRQHandler, . - ADC0_IRQHandler + + .align 1 + .thumb_func + .weak FLASH_IRQHandler + .type FLASH_IRQHandler, %function +FLASH_IRQHandler: + ldr r0,=FLASH_DriverIRQHandler + bx r0 + .size FLASH_IRQHandler, . - FLASH_IRQHandler + + .align 1 + .thumb_func + .weak CMP_IRQHandler + .type CMP_IRQHandler, %function +CMP_IRQHandler: + ldr r0,=CMP_DriverIRQHandler + bx r0 + .size CMP_IRQHandler, . - CMP_IRQHandler + + .align 1 + .thumb_func + .weak TIM0_IRQHandler + .type TIM0_IRQHandler, %function +TIM0_IRQHandler: + ldr r0,=TIM0_DriverIRQHandler + bx r0 + .size TIM0_IRQHandler, . - TIM0_IRQHandler + + .align 1 + .thumb_func + .weak TIM1_IRQHandler + .type TIM1_IRQHandler, %function +TIM1_IRQHandler: + ldr r0,=TIM1_DriverIRQHandler + bx r0 + .size TIM1_IRQHandler, . - TIM1_IRQHandler + + .align 1 + .thumb_func + .weak TIM2_IRQHandler + .type TIM2_IRQHandler, %function +TIM2_IRQHandler: + ldr r0,=TIM2_DriverIRQHandler + bx r0 + .size TIM2_IRQHandler, . - TIM2_IRQHandler + + .align 1 + .thumb_func + .weak CAN0_IRQHandler + .type CAN0_IRQHandler, %function +CAN0_IRQHandler: + ldr r0,=CAN0_DriverIRQHandler + bx r0 + .size CAN0_IRQHandler, . - CAN0_IRQHandler + + .align 1 + .thumb_func + .weak CAN1_IRQHandler + .type CAN1_IRQHandler, %function +CAN1_IRQHandler: + ldr r0,=CAN1_DriverIRQHandler + bx r0 + .size CAN1_IRQHandler, . - CAN1_IRQHandler + + .align 1 + .thumb_func + .weak RTC_IRQHandler + .type RTC_IRQHandler, %function +RTC_IRQHandler: + ldr r0,=RTC_DriverIRQHandler + bx r0 + .size RTC_IRQHandler, . - RTC_IRQHandler + + .align 1 + .thumb_func + .weak PMU_IRQHandler + .type PMU_IRQHandler, %function +PMU_IRQHandler: + ldr r0,=PMU_DriverIRQHandler + bx r0 + .size PMU_IRQHandler, . - PMU_IRQHandler + + .align 1 + .thumb_func + .weak TDG0_IRQHandler + .type TDG0_IRQHandler, %function +TDG0_IRQHandler: + ldr r0,=TDG0_DriverIRQHandler + bx r0 + .size TDG0_IRQHandler, . - TDG0_IRQHandler + + .align 1 + .thumb_func + .weak SCC_IRQHandler + .type SCC_IRQHandler, %function +SCC_IRQHandler: + ldr r0,=SCC_DriverIRQHandler + bx r0 + .size SCC_IRQHandler, . - SCC_IRQHandler + + .align 1 + .thumb_func + .weak WDOG_IRQHandler + .type WDOG_IRQHandler, %function +WDOG_IRQHandler: + ldr r0,=WDOG_DriverIRQHandler + bx r0 + .size WDOG_IRQHandler, . - WDOG_IRQHandler + + .align 1 + .thumb_func + .weak EWDT_IRQHandler + .type EWDT_IRQHandler, %function +EWDT_IRQHandler: + ldr r0,=EWDT_DriverIRQHandler + bx r0 + .size EWDT_IRQHandler, . - EWDT_IRQHandler + + .align 1 + .thumb_func + .weak STIM_IRQHandler + .type STIM_IRQHandler, %function +STIM_IRQHandler: + ldr r0,=STIM_DriverIRQHandler + bx r0 + .size STIM_IRQHandler, . - STIM_IRQHandler + + .align 1 + .thumb_func + .weak SRMC_IRQHandler + .type SRMC_IRQHandler, %function +SRMC_IRQHandler: + ldr r0,=SRMC_DriverIRQHandler + bx r0 + .size SRMC_IRQHandler, . - SRMC_IRQHandler + + .align 1 + .thumb_func + .weak PORTABC_IRQHandler + .type PORTABC_IRQHandler, %function +PORTABC_IRQHandler: + ldr r0,=PORTABC_DriverIRQHandler + bx r0 + .size PORTABC_IRQHandler, . - PORTABC_IRQHandler + + .align 1 + .thumb_func + .weak PORTDE_IRQHandler + .type PORTDE_IRQHandler, %function +PORTDE_IRQHandler: + ldr r0,=PORTDE_DriverIRQHandler + bx r0 + .size PORTDE_IRQHandler, . - PORTDE_IRQHandler + +/* Define default handlers */ + .macro def_irq_handler handler_name + .weak \handler_name + .set \handler_name, JumpToSelf + .endm + +/* Zhixin specific interrupt */ + def_irq_handler DMA0TO3_DriverIRQHandler + def_irq_handler DMA4TO7_DriverIRQHandler + def_irq_handler DMA8TO11_DriverIRQHandler + def_irq_handler DMA12TO15_DriverIRQHandler + def_irq_handler DMAERR_DriverIRQHandler + def_irq_handler I2C0_DriverIRQHandler + def_irq_handler I2C1_DriverIRQHandler + def_irq_handler SPI0_DriverIRQHandler + def_irq_handler SPI1_DriverIRQHandler + def_irq_handler SPI2_DriverIRQHandler + def_irq_handler UART0_DriverIRQHandler + def_irq_handler UART1_DriverIRQHandler + def_irq_handler UART2_DriverIRQHandler + def_irq_handler UART3_DriverIRQHandler + def_irq_handler ADC0_DriverIRQHandler + def_irq_handler FLASH_DriverIRQHandler + def_irq_handler CMP_DriverIRQHandler + def_irq_handler TIM0_DriverIRQHandler + def_irq_handler TIM1_DriverIRQHandler + def_irq_handler TIM2_DriverIRQHandler + def_irq_handler CAN0_DriverIRQHandler + def_irq_handler CAN1_DriverIRQHandler + def_irq_handler RTC_DriverIRQHandler + def_irq_handler PMU_DriverIRQHandler + def_irq_handler TDG0_DriverIRQHandler + def_irq_handler SCC_DriverIRQHandler + def_irq_handler WDOG_DriverIRQHandler + def_irq_handler EWDT_DriverIRQHandler + def_irq_handler STIM_DriverIRQHandler + def_irq_handler SRMC_DriverIRQHandler + def_irq_handler PORTABC_DriverIRQHandler + def_irq_handler PORTDE_DriverIRQHandler + + + .end \ No newline at end of file diff --git a/Platform/Devices/Z20K118M/Startup/IAR/Z20K118M_startup.s b/Platform/Devices/Z20K118M/Startup/IAR/Z20K118M_startup.s new file mode 100644 index 0000000..369ca01 --- /dev/null +++ b/Platform/Devices/Z20K118M/Startup/IAR/Z20K118M_startup.s @@ -0,0 +1,433 @@ +; ----------------------------------------------------------------------------- +; @file : Z20K118M_startup.s +; @brief : Z20K118M startup and Vector Table Source File for IAR. +; @version : V1.8.0 +; @date : May-2020 +; @author : Zhixin Semiconductor +; +; @note +; @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. +; ----------------------------------------------------------------------------- + + + MODULE ?cstartup + + ;; Forward declaration of sections. + SECTION CSTACK:DATA:NOROOT(3) + + SECTION .intvec:CODE:ROOT(2) + + EXTERN __iar_program_start + PUBLIC __vector_table + PUBLIC __Vectors_End + PUBLIC __Vectors_Size + + DATA + +__vector_table + DCD sfe(CSTACK) + DCD Reset_Handler ; POR Reset Entry + DCD NMI_Handler ; Non Maskable handler + DCD HardFault_Handler ; SV Hard Fault handler + DCD 0 + DCD 0 + DCD 0 + DCD 0 + DCD 0 + DCD 0 + DCD 0 + DCD SVC_Handler ; SV Call handler + DCD 0 + DCD 0 + DCD PendSV_Handler ; Pend SV handler + DCD SysTick_Handler ; System Tick handler + + + DCD DMA0TO3_IRQHandler ; irq 0 : DMA channel 0 - 3 transfer complete IRQHandler + DCD DMA4TO7_IRQHandler ; irq 1 : DMA channel 4 - 7 transfer complete IRQHandler + DCD DMA8TO11_IRQHandler ; irq 2 : DMA channel 8 - 11 transfer complete IRQHandler + DCD DMA12TO15_IRQHandler ; irq 3 : DMA channel 12 - 15 transfer complete IRQHandler + DCD DMAERR_IRQHandler ; irq 4 : DMA error interrupt channels 0-7 IRQHandler + DCD I2C0_IRQHandler ; irq 5 : I2C 0 IRQHandler + DCD I2C1_IRQHandler ; irq 6 : I2C 1 IRQHandler + DCD SPI0_IRQHandler ; irq 7 : SPI 0 IRQHandler + DCD SPI1_IRQHandler ; irq 8 : SPI 1 IRQHandler + DCD SPI2_IRQHandler ; irq 9 : SPI 2 IRQHandler + DCD UART0_IRQHandler ; irq 10 : UART 0 IRQHandler + DCD UART1_IRQHandler ; irq 11 : UART 1 IRQHandler + DCD UART2_IRQHandler ; irq 12 : UART2 IRQHandler + DCD UART3_IRQHandler ; irq 13 : UART3 IRQHandler + DCD ADC0_IRQHandler ; irq 14 : ADC0 IRQHandler + DCD FLASH_IRQHandler ; irq 15 : flash memory IRQHandler + DCD CMP_IRQHandler ; irq 16 : CMP IRQHandler + DCD TIM0_IRQHandler ; irq 17 : TIM 0 IRQHandler + DCD TIM1_IRQHandler ; irq 18 : TIM 1 IRQHandler + DCD TIM2_IRQHandler ; irq 19 : TIM 2 IRQHandler + DCD CAN0_IRQHandler ; irq 20 : CAN 0 IRQHandler + DCD CAN1_IRQHandler ; irq 21 : CAN 1 IRQHandler + DCD RTC_IRQHandler ; irq 22 : RTC IRQHandler + DCD PMU_IRQHandler ; irq 23 : PMU IRQHandler + DCD TDG0_IRQHandler ; irq 24 : TDG0 IRQHandler + DCD SCC_IRQHandler ; irq 25 : system clock controller IRQHandler + DCD WDOG_IRQHandler ; irq 26 : watchdog IRQHandler + DCD EWDT_IRQHandler ; irq 27 : external watchdog monitor IRQHandler + DCD STIM_IRQHandler ; irq 28 : STIM IRQHandler + DCD SRMC_IRQHandler ; irq 29 : system reset and mode control IRQHandler + DCD PORTABC_IRQHandler ; irq 30 : port A B C IRQHandler + DCD PORTDE_IRQHandler ; irq 31 : port D E IRQHandler +__Vectors_End + + +__Vectors_Size EQU __Vectors_End - __vector_table + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;; Default interrupt handlers. +;; + THUMB + + PUBWEAK Reset_Handler + SECTION .text:CODE:REORDER:NOROOT(2) +Reset_Handler + CPSID I ; Mask interrupts + ;; Init the registers + LDR R1,=0 + LDR R2,=0 + LDR R3,=0 + LDR R4,=0 + LDR R5,=0 + LDR R6,=0 + LDR R7,=0 + MOV R8,R7 + MOV R9,R7 + MOV R10,R7 + MOV R11,R7 + MOV R12,R7 + + ; vector table relocation + LDR R0, =0xE000ED08 + LDR R1, =__vector_table + STR R1, [R0] + +#ifndef START_FROM_SRAM + IMPORT __RAM_START, __RAM_END + ;; INIT ECC RAM + + LDR R1, =__RAM_START + LDR R2, =__RAM_END + + SUBS R2, R2, R1 + SUBS R2, #1 + BLE LB2 + + MOVS R0, #0 + MOVS R3, #4 + LB1: + STR R0, [R1] + ADD R1, R1, R3 + SUBS R2, #4 + BGE LB1 + LB2: +#endif + ;; Initialize the stack pointer + LDR R0, =sfe(CSTACK) + MOV R13,R0 + + CPSIE I ; Unmask interrupts + + LDR R0, =__iar_program_start + BX R0 + +JumpToSelf + B JumpToSelf + + PUBWEAK NMI_Handler + SECTION .text:CODE:REORDER:NOROOT(1) +NMI_Handler + B . + + PUBWEAK HardFault_Handler + SECTION .text:CODE:REORDER:NOROOT(1) +HardFault_Handler + B . + + + PUBWEAK SVC_Handler + SECTION .text:CODE:REORDER:NOROOT(1) +SVC_Handler + B . + + PUBWEAK PendSV_Handler + SECTION .text:CODE:REORDER:NOROOT(1) +PendSV_Handler + B . + + PUBWEAK SysTick_Handler + SECTION .text:CODE:REORDER:NOROOT(1) +SysTick_Handler + B . + + + PUBWEAK DMA0TO3_IRQHandler + PUBWEAK DMA0TO3_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +DMA0TO3_IRQHandler + LDR R0, =DMA0TO3_DriverIRQHandler + BX R0 + + PUBWEAK DMA4TO7_IRQHandler + PUBWEAK DMA4TO7_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +DMA4TO7_IRQHandler + LDR R0, =DMA4TO7_DriverIRQHandler + BX R0 + + PUBWEAK DMA8TO11_IRQHandler + PUBWEAK DMA8TO11_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +DMA8TO11_IRQHandler + LDR R0, =DMA8TO11_DriverIRQHandler + BX R0 + + PUBWEAK DMA12TO15_IRQHandler + PUBWEAK DMA12TO15_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +DMA12TO15_IRQHandler + LDR R0, =DMA12TO15_DriverIRQHandler + BX R0 + + PUBWEAK DMAERR_IRQHandler + PUBWEAK DMAERR_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +DMAERR_IRQHandler + LDR R0, =DMAERR_DriverIRQHandler + BX R0 + + PUBWEAK I2C0_IRQHandler + PUBWEAK I2C0_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +I2C0_IRQHandler + LDR R0, =I2C0_DriverIRQHandler + BX R0 + + PUBWEAK I2C1_IRQHandler + PUBWEAK I2C1_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +I2C1_IRQHandler + LDR R0, =I2C1_DriverIRQHandler + BX R0 + + PUBWEAK SPI0_IRQHandler + PUBWEAK SPI0_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +SPI0_IRQHandler + LDR R0, =SPI0_DriverIRQHandler + BX R0 + + PUBWEAK SPI1_IRQHandler + PUBWEAK SPI1_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +SPI1_IRQHandler + LDR R0, =SPI1_DriverIRQHandler + BX R0 + + PUBWEAK SPI2_IRQHandler + PUBWEAK SPI2_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +SPI2_IRQHandler + LDR R0, =SPI2_DriverIRQHandler + BX R0 + + PUBWEAK UART0_IRQHandler + PUBWEAK UART0_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +UART0_IRQHandler + LDR R0, =UART0_DriverIRQHandler + BX R0 + + PUBWEAK UART1_IRQHandler + PUBWEAK UART1_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +UART1_IRQHandler + LDR R0, =UART1_DriverIRQHandler + BX R0 + + PUBWEAK UART2_IRQHandler + PUBWEAK UART2_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +UART2_IRQHandler + LDR R0, =UART2_DriverIRQHandler + BX R0 + + PUBWEAK UART3_IRQHandler + PUBWEAK UART3_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +UART3_IRQHandler + LDR R0, =UART3_DriverIRQHandler + BX R0 + + PUBWEAK ADC0_IRQHandler + PUBWEAK ADC0_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +ADC0_IRQHandler + LDR R0, =ADC0_DriverIRQHandler + BX R0 + + PUBWEAK FLASH_IRQHandler + PUBWEAK FLASH_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +FLASH_IRQHandler + LDR R0, =FLASH_DriverIRQHandler + BX R0 + + PUBWEAK CMP_IRQHandler + PUBWEAK CMP_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +CMP_IRQHandler + LDR R0, =CMP_DriverIRQHandler + BX R0 + + PUBWEAK TIM0_IRQHandler + PUBWEAK TIM0_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +TIM0_IRQHandler + LDR R0, =TIM0_DriverIRQHandler + BX R0 + + PUBWEAK TIM1_IRQHandler + PUBWEAK TIM1_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +TIM1_IRQHandler + LDR R0, =TIM1_DriverIRQHandler + BX R0 + + PUBWEAK TIM2_IRQHandler + PUBWEAK TIM2_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +TIM2_IRQHandler + LDR R0, =TIM2_DriverIRQHandler + BX R0 + + PUBWEAK CAN0_IRQHandler + PUBWEAK CAN0_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +CAN0_IRQHandler + LDR R0, =CAN0_DriverIRQHandler + BX R0 + + PUBWEAK CAN1_IRQHandler + PUBWEAK CAN1_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +CAN1_IRQHandler + LDR R0, =CAN1_DriverIRQHandler + BX R0 + + PUBWEAK RTC_IRQHandler + PUBWEAK RTC_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +RTC_IRQHandler + LDR R0, =RTC_DriverIRQHandler + BX R0 + + PUBWEAK PMU_IRQHandler + PUBWEAK PMU_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +PMU_IRQHandler + LDR R0, =PMU_DriverIRQHandler + BX R0 + + PUBWEAK TDG0_IRQHandler + PUBWEAK TDG0_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +TDG0_IRQHandler + LDR R0, =TDG0_DriverIRQHandler + BX R0 + + PUBWEAK SCC_IRQHandler + PUBWEAK SCC_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +SCC_IRQHandler + LDR R0, =SCC_DriverIRQHandler + BX R0 + + PUBWEAK WDOG_IRQHandler + PUBWEAK WDOG_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +WDOG_IRQHandler + LDR R0, =WDOG_DriverIRQHandler + BX R0 + + PUBWEAK EWDT_IRQHandler + PUBWEAK EWDT_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +EWDT_IRQHandler + LDR R0, =EWDT_DriverIRQHandler + BX R0 + + PUBWEAK STIM_IRQHandler + PUBWEAK STIM_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +STIM_IRQHandler + LDR R0, =STIM_DriverIRQHandler + BX R0 + + PUBWEAK SRMC_IRQHandler + PUBWEAK SRMC_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +SRMC_IRQHandler + LDR R0, =SRMC_DriverIRQHandler + BX R0 + + PUBWEAK PORTABC_IRQHandler + PUBWEAK PORTABC_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +PORTABC_IRQHandler + LDR R0, =PORTABC_DriverIRQHandler + BX R0 + + PUBWEAK PORTDE_IRQHandler + PUBWEAK PORTDE_DriverIRQHandler + SECTION .text:CODE:REORDER:NOROOT(2) +PORTDE_IRQHandler + LDR R0, =PORTDE_DriverIRQHandler + BX R0 + + PUBWEAK DefaultISR + SECTION .text:CODE:REORDER:NOROOT(1) +DMA0TO3_DriverIRQHandler +DMA4TO7_DriverIRQHandler +DMA8TO11_DriverIRQHandler +DMA12TO15_DriverIRQHandler +DMAERR_DriverIRQHandler +I2C0_DriverIRQHandler +I2C1_DriverIRQHandler +SPI0_DriverIRQHandler +SPI1_DriverIRQHandler +SPI2_DriverIRQHandler +UART0_DriverIRQHandler +UART1_DriverIRQHandler +UART2_DriverIRQHandler +UART3_DriverIRQHandler +ADC0_DriverIRQHandler +FLASH_DriverIRQHandler +CMP_DriverIRQHandler +TIM0_DriverIRQHandler +TIM1_DriverIRQHandler +TIM2_DriverIRQHandler +CAN0_DriverIRQHandler +CAN1_DriverIRQHandler +RTC_DriverIRQHandler +PMU_DriverIRQHandler +TDG0_DriverIRQHandler +SCC_DriverIRQHandler +WDOG_DriverIRQHandler +EWDT_DriverIRQHandler +STIM_DriverIRQHandler +SRMC_DriverIRQHandler +PORTABC_DriverIRQHandler +PORTDE_DriverIRQHandler +DefaultISR + B DefaultISR + + END diff --git a/Platform/Devices/device_regs.h b/Platform/Devices/device_regs.h new file mode 100644 index 0000000..46b5a61 --- /dev/null +++ b/Platform/Devices/device_regs.h @@ -0,0 +1,26 @@ +/**************************************************************************************************/ +/** + * @file : device_regs.h + * @brief : Z20K11xM device reg resource file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ + +#ifndef DEVICE_REGS_H +#define DEVICE_REGS_H + +#if (defined(DEV_Z20K118M)) + #include "Z20K118M.h" +#elif (defined(DEV_Z20K116M)) + #include "Z20K116M.h" +#elif (defined(DEV_Z20K114M)) + #include "Z20K114M.h" +#else + #error "No valid device defined!" +#endif + +#endif /* DEVICE_REGS_H */ diff --git a/Platform/Z20K11xM_cfg.h b/Platform/Z20K11xM_cfg.h new file mode 100644 index 0000000..5ae368f --- /dev/null +++ b/Platform/Z20K11xM_cfg.h @@ -0,0 +1,44 @@ +/**************************************************************************************************/ +/** + * @file : platform_cfg.h + * @brief : Z20K11xM Platform Config Header File. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ + +#ifndef PLATFORM_CFG_H +#define PLATFORM_CFG_H + +/** \mainpage Z20K11xM configuration + +*/ +/** \brief Configuration of Z20K11xM +*/ +#define FLASH_CMD_FUNC_IN_RAM 1 /* Flash cmd functions are RAM functions */ +#define DRV_DELAY_FUNC_IN_RAM 1 /* DRV_Delay function is RAM function */ + +#define ADC_TIMEOUT_WAIT_CNT_SWRST 10U /* ADC software reset timeout value*/ + +#define CAN_TIMEOUT_WAIT_CNT_1 5000000U /* CAN timeout value1*/ +#define CAN_TIMEOUT_WAIT_CNT_2 10000U /* CAN timeout value2*/ +#define CAN_TIMEOUT_WAIT_CNT_3 1000000U /* CAN timeout value3*/ + +#define CLK_WAITCONFIG_CNT 3500U /* Clock config counter value*/ +#define CLK_TIMEOUT_WAIT_CNT 100000U /* Clock timeout value*/ +#define CLK_TIMEOUT_WAIT_CNT_OSC32K 5000000U /* OSC32K timeout value*/ + +#define FLASH_TIMEOUT_WAIT_CNT 100000U /* Flash timeout value*/ +#define FLASH_TIMEOUT_WAIT_CNT_ERASE_ALL 10000000U /* Flash erase timeout value*/ +#define FLASH_TIMEOUT_ABORT_WAIT_CNT 100U /* Flash abort timeout value*/ + +#define HWDIV_TIMEOUT_WAIT_CNT 10000U /* HWDIV timeout value*/ + +#define WDOG_WAITCONFIG_GOING_CNT 0xFFFFFU /* WDOG config timeout value*/ + +#define TDG_TIMEOUT_WAIT_CNT 10000U + +#endif /* DEVICE_CFG_H */ diff --git a/Platform/Z20K11xM_corecfg.h b/Platform/Z20K11xM_corecfg.h new file mode 100644 index 0000000..b3476eb --- /dev/null +++ b/Platform/Z20K11xM_corecfg.h @@ -0,0 +1,40 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_corecfg.h + * @brief : Z20K11xM Device core config Header File. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ + +#ifndef Z20K11XM_CORECFG_H +#define Z20K11XM_CORECFG_H + +/** \mainpage Z20K11X Core configuration + +*/ + +/** \defgroup Core_configuration Configuration of the Cortex-M0+ Processor and Core Peripherals + + @{ + */ + +/*PRQA S 0603,0602 ++*/ +#define __CHECK_DEVICE_DEFINES /*!< check device definition */ +#define __CM0PLUS_REV 0x0000U /*!< core version */ +#define __VTOR_PRESENT 1U /*!< VTOR present or not*/ +#define __MPU_PRESENT 1U /*!< MPU present or not*/ +#define __NVIC_PRIO_BITS 2U /*!< Number of Bits used for Priority Levels */ +#define __Vendor_SysTickConfig 0U /*!< Set to 1 if different SysTick Config is used*/ +/*PRQA S 0603,0602 --*/ + +/** @} end of group Core_configuration Configuration of the Cortex-M0+ Processor and Core Peripherals */ + +#endif /* __Z20K11XM_CORECFG_H */ + +/******************* (C) COPYRIGHT 2020 Zhixin Semiconductor *****END OF FILE****/ + + diff --git a/RTOS/FreeRTOS/License/license.txt b/RTOS/FreeRTOS/License/license.txt new file mode 100644 index 0000000..f784bc2 --- /dev/null +++ b/RTOS/FreeRTOS/License/license.txt @@ -0,0 +1,37 @@ +The FreeRTOS kernel is released under the MIT open source license, the text of +which is provided below. + +This license covers the FreeRTOS kernel source files, which are located in the +/FreeRTOS/Source directory of the official FreeRTOS kernel download. It also +covers most of the source files in the demo application projects, which are +located in the /FreeRTOS/Demo directory of the official FreeRTOS download. The +demo projects may also include third party software that is not part of FreeRTOS +and is licensed separately to FreeRTOS. Examples of third party software +includes header files provided by chip or tools vendors, linker scripts, +peripheral drivers, etc. All the software in subdirectories of the /FreeRTOS +directory is either open source or distributed with permission, and is free for +use. For the avoidance of doubt, refer to the comments at the top of each +source file. + + +License text: +------------- + +Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + diff --git a/RTOS/FreeRTOS/Source/croutine.c b/RTOS/FreeRTOS/Source/croutine.c new file mode 100644 index 0000000..4f10873 --- /dev/null +++ b/RTOS/FreeRTOS/Source/croutine.c @@ -0,0 +1,361 @@ +/* + * FreeRTOS Kernel V10.4.1 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * https://www.FreeRTOS.org + * https://github.com/FreeRTOS + * + */ + +#include "FreeRTOS.h" +#include "task.h" +#include "croutine.h" + +/* Remove the whole file is co-routines are not being used. */ +#if ( configUSE_CO_ROUTINES != 0 ) + +/* + * Some kernel aware debuggers require data to be viewed to be global, rather + * than file scope. + */ + #ifdef portREMOVE_STATIC_QUALIFIER + #define static + #endif + + +/* Lists for ready and blocked co-routines. --------------------*/ + static List_t pxReadyCoRoutineLists[ configMAX_CO_ROUTINE_PRIORITIES ]; /*< Prioritised ready co-routines. */ + static List_t xDelayedCoRoutineList1; /*< Delayed co-routines. */ + static List_t xDelayedCoRoutineList2; /*< Delayed co-routines (two lists are used - one for delays that have overflowed the current tick count. */ + static List_t * pxDelayedCoRoutineList = NULL; /*< Points to the delayed co-routine list currently being used. */ + static List_t * pxOverflowDelayedCoRoutineList = NULL; /*< Points to the delayed co-routine list currently being used to hold co-routines that have overflowed the current tick count. */ + static List_t xPendingReadyCoRoutineList; /*< Holds co-routines that have been readied by an external event. They cannot be added directly to the ready lists as the ready lists cannot be accessed by interrupts. */ + +/* Other file private variables. --------------------------------*/ + CRCB_t * pxCurrentCoRoutine = NULL; + static UBaseType_t uxTopCoRoutineReadyPriority = 0; + static TickType_t xCoRoutineTickCount = 0, xLastTickCount = 0, xPassedTicks = 0; + +/* The initial state of the co-routine when it is created. */ + #define corINITIAL_STATE ( 0 ) + +/* + * Place the co-routine represented by pxCRCB into the appropriate ready queue + * for the priority. It is inserted at the end of the list. + * + * This macro accesses the co-routine ready lists and therefore must not be + * used from within an ISR. + */ + #define prvAddCoRoutineToReadyQueue( pxCRCB ) \ + { \ + if( pxCRCB->uxPriority > uxTopCoRoutineReadyPriority ) \ + { \ + uxTopCoRoutineReadyPriority = pxCRCB->uxPriority; \ + } \ + vListInsertEnd( ( List_t * ) &( pxReadyCoRoutineLists[ pxCRCB->uxPriority ] ), &( pxCRCB->xGenericListItem ) ); \ + } + +/* + * Utility to ready all the lists used by the scheduler. This is called + * automatically upon the creation of the first co-routine. + */ + static void prvInitialiseCoRoutineLists( void ); + +/* + * Co-routines that are readied by an interrupt cannot be placed directly into + * the ready lists (there is no mutual exclusion). Instead they are placed in + * in the pending ready list in order that they can later be moved to the ready + * list by the co-routine scheduler. + */ + static void prvCheckPendingReadyList( void ); + +/* + * Macro that looks at the list of co-routines that are currently delayed to + * see if any require waking. + * + * Co-routines are stored in the queue in the order of their wake time - + * meaning once one co-routine has been found whose timer has not expired + * we need not look any further down the list. + */ + static void prvCheckDelayedList( void ); + +/*-----------------------------------------------------------*/ + + BaseType_t xCoRoutineCreate( crCOROUTINE_CODE pxCoRoutineCode, + UBaseType_t uxPriority, + UBaseType_t uxIndex ) + { + BaseType_t xReturn; + CRCB_t * pxCoRoutine; + + /* Allocate the memory that will store the co-routine control block. */ + pxCoRoutine = ( CRCB_t * ) pvPortMalloc( sizeof( CRCB_t ) ); + + if( pxCoRoutine ) + { + /* If pxCurrentCoRoutine is NULL then this is the first co-routine to + * be created and the co-routine data structures need initialising. */ + if( pxCurrentCoRoutine == NULL ) + { + pxCurrentCoRoutine = pxCoRoutine; + prvInitialiseCoRoutineLists(); + } + + /* Check the priority is within limits. */ + if( uxPriority >= configMAX_CO_ROUTINE_PRIORITIES ) + { + uxPriority = configMAX_CO_ROUTINE_PRIORITIES - 1; + } + + /* Fill out the co-routine control block from the function parameters. */ + pxCoRoutine->uxState = corINITIAL_STATE; + pxCoRoutine->uxPriority = uxPriority; + pxCoRoutine->uxIndex = uxIndex; + pxCoRoutine->pxCoRoutineFunction = pxCoRoutineCode; + + /* Initialise all the other co-routine control block parameters. */ + vListInitialiseItem( &( pxCoRoutine->xGenericListItem ) ); + vListInitialiseItem( &( pxCoRoutine->xEventListItem ) ); + + /* Set the co-routine control block as a link back from the ListItem_t. + * This is so we can get back to the containing CRCB from a generic item + * in a list. */ + listSET_LIST_ITEM_OWNER( &( pxCoRoutine->xGenericListItem ), pxCoRoutine ); + listSET_LIST_ITEM_OWNER( &( pxCoRoutine->xEventListItem ), pxCoRoutine ); + + /* Event lists are always in priority order. */ + listSET_LIST_ITEM_VALUE( &( pxCoRoutine->xEventListItem ), ( ( TickType_t ) configMAX_CO_ROUTINE_PRIORITIES - ( TickType_t ) uxPriority ) ); + + /* Now the co-routine has been initialised it can be added to the ready + * list at the correct priority. */ + prvAddCoRoutineToReadyQueue( pxCoRoutine ); + + xReturn = pdPASS; + } + else + { + xReturn = errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY; + } + + return xReturn; + } +/*-----------------------------------------------------------*/ + + void vCoRoutineAddToDelayedList( TickType_t xTicksToDelay, + List_t * pxEventList ) + { + TickType_t xTimeToWake; + + /* Calculate the time to wake - this may overflow but this is + * not a problem. */ + xTimeToWake = xCoRoutineTickCount + xTicksToDelay; + + /* We must remove ourselves from the ready list before adding + * ourselves to the blocked list as the same list item is used for + * both lists. */ + ( void ) uxListRemove( ( ListItem_t * ) &( pxCurrentCoRoutine->xGenericListItem ) ); + + /* The list item will be inserted in wake time order. */ + listSET_LIST_ITEM_VALUE( &( pxCurrentCoRoutine->xGenericListItem ), xTimeToWake ); + + if( xTimeToWake < xCoRoutineTickCount ) + { + /* Wake time has overflowed. Place this item in the + * overflow list. */ + vListInsert( ( List_t * ) pxOverflowDelayedCoRoutineList, ( ListItem_t * ) &( pxCurrentCoRoutine->xGenericListItem ) ); + } + else + { + /* The wake time has not overflowed, so we can use the + * current block list. */ + vListInsert( ( List_t * ) pxDelayedCoRoutineList, ( ListItem_t * ) &( pxCurrentCoRoutine->xGenericListItem ) ); + } + + if( pxEventList ) + { + /* Also add the co-routine to an event list. If this is done then the + * function must be called with interrupts disabled. */ + vListInsert( pxEventList, &( pxCurrentCoRoutine->xEventListItem ) ); + } + } +/*-----------------------------------------------------------*/ + + static void prvCheckPendingReadyList( void ) + { + /* Are there any co-routines waiting to get moved to the ready list? These + * are co-routines that have been readied by an ISR. The ISR cannot access + * the ready lists itself. */ + while( listLIST_IS_EMPTY( &xPendingReadyCoRoutineList ) == pdFALSE ) + { + CRCB_t * pxUnblockedCRCB; + + /* The pending ready list can be accessed by an ISR. */ + portDISABLE_INTERRUPTS(); + { + pxUnblockedCRCB = ( CRCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( ( &xPendingReadyCoRoutineList ) ); + ( void ) uxListRemove( &( pxUnblockedCRCB->xEventListItem ) ); + } + portENABLE_INTERRUPTS(); + + ( void ) uxListRemove( &( pxUnblockedCRCB->xGenericListItem ) ); + prvAddCoRoutineToReadyQueue( pxUnblockedCRCB ); + } + } +/*-----------------------------------------------------------*/ + + static void prvCheckDelayedList( void ) + { + CRCB_t * pxCRCB; + + xPassedTicks = xTaskGetTickCount() - xLastTickCount; + + while( xPassedTicks ) + { + xCoRoutineTickCount++; + xPassedTicks--; + + /* If the tick count has overflowed we need to swap the ready lists. */ + if( xCoRoutineTickCount == 0 ) + { + List_t * pxTemp; + + /* Tick count has overflowed so we need to swap the delay lists. If there are + * any items in pxDelayedCoRoutineList here then there is an error! */ + pxTemp = pxDelayedCoRoutineList; + pxDelayedCoRoutineList = pxOverflowDelayedCoRoutineList; + pxOverflowDelayedCoRoutineList = pxTemp; + } + + /* See if this tick has made a timeout expire. */ + while( listLIST_IS_EMPTY( pxDelayedCoRoutineList ) == pdFALSE ) + { + pxCRCB = ( CRCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxDelayedCoRoutineList ); + + if( xCoRoutineTickCount < listGET_LIST_ITEM_VALUE( &( pxCRCB->xGenericListItem ) ) ) + { + /* Timeout not yet expired. */ + break; + } + + portDISABLE_INTERRUPTS(); + { + /* The event could have occurred just before this critical + * section. If this is the case then the generic list item will + * have been moved to the pending ready list and the following + * line is still valid. Also the pvContainer parameter will have + * been set to NULL so the following lines are also valid. */ + ( void ) uxListRemove( &( pxCRCB->xGenericListItem ) ); + + /* Is the co-routine waiting on an event also? */ + if( pxCRCB->xEventListItem.pxContainer ) + { + ( void ) uxListRemove( &( pxCRCB->xEventListItem ) ); + } + } + portENABLE_INTERRUPTS(); + + prvAddCoRoutineToReadyQueue( pxCRCB ); + } + } + + xLastTickCount = xCoRoutineTickCount; + } +/*-----------------------------------------------------------*/ + + void vCoRoutineSchedule( void ) + { + /* Only run a co-routine after prvInitialiseCoRoutineLists() has been + * called. prvInitialiseCoRoutineLists() is called automatically when a + * co-routine is created. */ + if( pxDelayedCoRoutineList != NULL ) + { + /* See if any co-routines readied by events need moving to the ready lists. */ + prvCheckPendingReadyList(); + + /* See if any delayed co-routines have timed out. */ + prvCheckDelayedList(); + + /* Find the highest priority queue that contains ready co-routines. */ + while( listLIST_IS_EMPTY( &( pxReadyCoRoutineLists[ uxTopCoRoutineReadyPriority ] ) ) ) + { + if( uxTopCoRoutineReadyPriority == 0 ) + { + /* No more co-routines to check. */ + return; + } + + --uxTopCoRoutineReadyPriority; + } + + /* listGET_OWNER_OF_NEXT_ENTRY walks through the list, so the co-routines + * of the same priority get an equal share of the processor time. */ + listGET_OWNER_OF_NEXT_ENTRY( pxCurrentCoRoutine, &( pxReadyCoRoutineLists[ uxTopCoRoutineReadyPriority ] ) ); + + /* Call the co-routine. */ + ( pxCurrentCoRoutine->pxCoRoutineFunction )( pxCurrentCoRoutine, pxCurrentCoRoutine->uxIndex ); + } + } +/*-----------------------------------------------------------*/ + + static void prvInitialiseCoRoutineLists( void ) + { + UBaseType_t uxPriority; + + for( uxPriority = 0; uxPriority < configMAX_CO_ROUTINE_PRIORITIES; uxPriority++ ) + { + vListInitialise( ( List_t * ) &( pxReadyCoRoutineLists[ uxPriority ] ) ); + } + + vListInitialise( ( List_t * ) &xDelayedCoRoutineList1 ); + vListInitialise( ( List_t * ) &xDelayedCoRoutineList2 ); + vListInitialise( ( List_t * ) &xPendingReadyCoRoutineList ); + + /* Start with pxDelayedCoRoutineList using list1 and the + * pxOverflowDelayedCoRoutineList using list2. */ + pxDelayedCoRoutineList = &xDelayedCoRoutineList1; + pxOverflowDelayedCoRoutineList = &xDelayedCoRoutineList2; + } +/*-----------------------------------------------------------*/ + + BaseType_t xCoRoutineRemoveFromEventList( const List_t * pxEventList ) + { + CRCB_t * pxUnblockedCRCB; + BaseType_t xReturn; + + /* This function is called from within an interrupt. It can only access + * event lists and the pending ready list. This function assumes that a + * check has already been made to ensure pxEventList is not empty. */ + pxUnblockedCRCB = ( CRCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxEventList ); + ( void ) uxListRemove( &( pxUnblockedCRCB->xEventListItem ) ); + vListInsertEnd( ( List_t * ) &( xPendingReadyCoRoutineList ), &( pxUnblockedCRCB->xEventListItem ) ); + + if( pxUnblockedCRCB->uxPriority >= pxCurrentCoRoutine->uxPriority ) + { + xReturn = pdTRUE; + } + else + { + xReturn = pdFALSE; + } + + return xReturn; + } + +#endif /* configUSE_CO_ROUTINES == 0 */ diff --git a/RTOS/FreeRTOS/Source/event_groups.c b/RTOS/FreeRTOS/Source/event_groups.c new file mode 100644 index 0000000..decb352 --- /dev/null +++ b/RTOS/FreeRTOS/Source/event_groups.c @@ -0,0 +1,771 @@ +/* + * FreeRTOS Kernel V10.4.1 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * https://www.FreeRTOS.org + * https://github.com/FreeRTOS + * + */ + +/* Standard includes. */ +#include + +/* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining + * all the API functions to use the MPU wrappers. That should only be done when + * task.h is included from an application file. */ +#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE + +/* FreeRTOS includes. */ +#include "FreeRTOS.h" +#include "task.h" +#include "timers.h" +#include "event_groups.h" + +/* Lint e961, e750 and e9021 are suppressed as a MISRA exception justified + * because the MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be defined + * for the header files above, but not in this file, in order to generate the + * correct privileged Vs unprivileged linkage and placement. */ +#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE /*lint !e961 !e750 !e9021 See comment above. */ + +/* The following bit fields convey control information in a task's event list + * item value. It is important they don't clash with the + * taskEVENT_LIST_ITEM_VALUE_IN_USE definition. */ +#if configUSE_16_BIT_TICKS == 1 + #define eventCLEAR_EVENTS_ON_EXIT_BIT 0x0100U + #define eventUNBLOCKED_DUE_TO_BIT_SET 0x0200U + #define eventWAIT_FOR_ALL_BITS 0x0400U + #define eventEVENT_BITS_CONTROL_BYTES 0xff00U +#else + #define eventCLEAR_EVENTS_ON_EXIT_BIT 0x01000000UL + #define eventUNBLOCKED_DUE_TO_BIT_SET 0x02000000UL + #define eventWAIT_FOR_ALL_BITS 0x04000000UL + #define eventEVENT_BITS_CONTROL_BYTES 0xff000000UL +#endif + +typedef struct EventGroupDef_t +{ + EventBits_t uxEventBits; + List_t xTasksWaitingForBits; /*< List of tasks waiting for a bit to be set. */ + + #if ( configUSE_TRACE_FACILITY == 1 ) + UBaseType_t uxEventGroupNumber; + #endif + + #if ( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) + uint8_t ucStaticallyAllocated; /*< Set to pdTRUE if the event group is statically allocated to ensure no attempt is made to free the memory. */ + #endif +} EventGroup_t; + +/*-----------------------------------------------------------*/ + +/* + * Test the bits set in uxCurrentEventBits to see if the wait condition is met. + * The wait condition is defined by xWaitForAllBits. If xWaitForAllBits is + * pdTRUE then the wait condition is met if all the bits set in uxBitsToWaitFor + * are also set in uxCurrentEventBits. If xWaitForAllBits is pdFALSE then the + * wait condition is met if any of the bits set in uxBitsToWait for are also set + * in uxCurrentEventBits. + */ +static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits, + const EventBits_t uxBitsToWaitFor, + const BaseType_t xWaitForAllBits ) PRIVILEGED_FUNCTION; + +/*-----------------------------------------------------------*/ + +#if ( configSUPPORT_STATIC_ALLOCATION == 1 ) + + EventGroupHandle_t xEventGroupCreateStatic( StaticEventGroup_t * pxEventGroupBuffer ) + { + EventGroup_t * pxEventBits; + + /* A StaticEventGroup_t object must be provided. */ + configASSERT( pxEventGroupBuffer ); + + #if ( configASSERT_DEFINED == 1 ) + { + /* Sanity check that the size of the structure used to declare a + * variable of type StaticEventGroup_t equals the size of the real + * event group structure. */ + volatile size_t xSize = sizeof( StaticEventGroup_t ); + configASSERT( xSize == sizeof( EventGroup_t ) ); + } /*lint !e529 xSize is referenced if configASSERT() is defined. */ + #endif /* configASSERT_DEFINED */ + + /* The user has provided a statically allocated event group - use it. */ + pxEventBits = ( EventGroup_t * ) pxEventGroupBuffer; /*lint !e740 !e9087 EventGroup_t and StaticEventGroup_t are deliberately aliased for data hiding purposes and guaranteed to have the same size and alignment requirement - checked by configASSERT(). */ + + if( pxEventBits != NULL ) + { + pxEventBits->uxEventBits = 0; + vListInitialise( &( pxEventBits->xTasksWaitingForBits ) ); + + #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + { + /* Both static and dynamic allocation can be used, so note that + * this event group was created statically in case the event group + * is later deleted. */ + pxEventBits->ucStaticallyAllocated = pdTRUE; + } + #endif /* configSUPPORT_DYNAMIC_ALLOCATION */ + + traceEVENT_GROUP_CREATE( pxEventBits ); + } + else + { + /* xEventGroupCreateStatic should only ever be called with + * pxEventGroupBuffer pointing to a pre-allocated (compile time + * allocated) StaticEventGroup_t variable. */ + traceEVENT_GROUP_CREATE_FAILED(); + } + + return pxEventBits; + } + +#endif /* configSUPPORT_STATIC_ALLOCATION */ +/*-----------------------------------------------------------*/ + +#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + + EventGroupHandle_t xEventGroupCreate( void ) + { + EventGroup_t * pxEventBits; + + /* Allocate the event group. Justification for MISRA deviation as + * follows: pvPortMalloc() always ensures returned memory blocks are + * aligned per the requirements of the MCU stack. In this case + * pvPortMalloc() must return a pointer that is guaranteed to meet the + * alignment requirements of the EventGroup_t structure - which (if you + * follow it through) is the alignment requirements of the TickType_t type + * (EventBits_t being of TickType_t itself). Therefore, whenever the + * stack alignment requirements are greater than or equal to the + * TickType_t alignment requirements the cast is safe. In other cases, + * where the natural word size of the architecture is less than + * sizeof( TickType_t ), the TickType_t variables will be accessed in two + * or more reads operations, and the alignment requirements is only that + * of each individual read. */ + pxEventBits = ( EventGroup_t * ) pvPortMalloc( sizeof( EventGroup_t ) ); /*lint !e9087 !e9079 see comment above. */ + + if( pxEventBits != NULL ) + { + pxEventBits->uxEventBits = 0; + vListInitialise( &( pxEventBits->xTasksWaitingForBits ) ); + + #if ( configSUPPORT_STATIC_ALLOCATION == 1 ) + { + /* Both static and dynamic allocation can be used, so note this + * event group was allocated statically in case the event group is + * later deleted. */ + pxEventBits->ucStaticallyAllocated = pdFALSE; + } + #endif /* configSUPPORT_STATIC_ALLOCATION */ + + traceEVENT_GROUP_CREATE( pxEventBits ); + } + else + { + traceEVENT_GROUP_CREATE_FAILED(); /*lint !e9063 Else branch only exists to allow tracing and does not generate code if trace macros are not defined. */ + } + + return pxEventBits; + } + +#endif /* configSUPPORT_DYNAMIC_ALLOCATION */ +/*-----------------------------------------------------------*/ + +EventBits_t xEventGroupSync( EventGroupHandle_t xEventGroup, + const EventBits_t uxBitsToSet, + const EventBits_t uxBitsToWaitFor, + TickType_t xTicksToWait ) +{ + EventBits_t uxOriginalBitValue, uxReturn; + EventGroup_t * pxEventBits = xEventGroup; + BaseType_t xAlreadyYielded; + BaseType_t xTimeoutOccurred = pdFALSE; + + configASSERT( ( uxBitsToWaitFor & eventEVENT_BITS_CONTROL_BYTES ) == 0 ); + configASSERT( uxBitsToWaitFor != 0 ); + #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) ) + { + configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) ); + } + #endif + + vTaskSuspendAll(); + { + uxOriginalBitValue = pxEventBits->uxEventBits; + + ( void ) xEventGroupSetBits( xEventGroup, uxBitsToSet ); + + if( ( ( uxOriginalBitValue | uxBitsToSet ) & uxBitsToWaitFor ) == uxBitsToWaitFor ) + { + /* All the rendezvous bits are now set - no need to block. */ + uxReturn = ( uxOriginalBitValue | uxBitsToSet ); + + /* Rendezvous always clear the bits. They will have been cleared + * already unless this is the only task in the rendezvous. */ + pxEventBits->uxEventBits &= ~uxBitsToWaitFor; + + xTicksToWait = 0; + } + else + { + if( xTicksToWait != ( TickType_t ) 0 ) + { + traceEVENT_GROUP_SYNC_BLOCK( xEventGroup, uxBitsToSet, uxBitsToWaitFor ); + + /* Store the bits that the calling task is waiting for in the + * task's event list item so the kernel knows when a match is + * found. Then enter the blocked state. */ + vTaskPlaceOnUnorderedEventList( &( pxEventBits->xTasksWaitingForBits ), ( uxBitsToWaitFor | eventCLEAR_EVENTS_ON_EXIT_BIT | eventWAIT_FOR_ALL_BITS ), xTicksToWait ); + + /* This assignment is obsolete as uxReturn will get set after + * the task unblocks, but some compilers mistakenly generate a + * warning about uxReturn being returned without being set if the + * assignment is omitted. */ + uxReturn = 0; + } + else + { + /* The rendezvous bits were not set, but no block time was + * specified - just return the current event bit value. */ + uxReturn = pxEventBits->uxEventBits; + xTimeoutOccurred = pdTRUE; + } + } + } + xAlreadyYielded = xTaskResumeAll(); + + if( xTicksToWait != ( TickType_t ) 0 ) + { + if( xAlreadyYielded == pdFALSE ) + { + portYIELD_WITHIN_API(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* The task blocked to wait for its required bits to be set - at this + * point either the required bits were set or the block time expired. If + * the required bits were set they will have been stored in the task's + * event list item, and they should now be retrieved then cleared. */ + uxReturn = uxTaskResetEventItemValue(); + + if( ( uxReturn & eventUNBLOCKED_DUE_TO_BIT_SET ) == ( EventBits_t ) 0 ) + { + /* The task timed out, just return the current event bit value. */ + taskENTER_CRITICAL(); + { + uxReturn = pxEventBits->uxEventBits; + + /* Although the task got here because it timed out before the + * bits it was waiting for were set, it is possible that since it + * unblocked another task has set the bits. If this is the case + * then it needs to clear the bits before exiting. */ + if( ( uxReturn & uxBitsToWaitFor ) == uxBitsToWaitFor ) + { + pxEventBits->uxEventBits &= ~uxBitsToWaitFor; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + taskEXIT_CRITICAL(); + + xTimeoutOccurred = pdTRUE; + } + else + { + /* The task unblocked because the bits were set. */ + } + + /* Control bits might be set as the task had blocked should not be + * returned. */ + uxReturn &= ~eventEVENT_BITS_CONTROL_BYTES; + } + + traceEVENT_GROUP_SYNC_END( xEventGroup, uxBitsToSet, uxBitsToWaitFor, xTimeoutOccurred ); + + /* Prevent compiler warnings when trace macros are not used. */ + ( void ) xTimeoutOccurred; + + return uxReturn; +} +/*-----------------------------------------------------------*/ + +EventBits_t xEventGroupWaitBits( EventGroupHandle_t xEventGroup, + const EventBits_t uxBitsToWaitFor, + const BaseType_t xClearOnExit, + const BaseType_t xWaitForAllBits, + TickType_t xTicksToWait ) +{ + EventGroup_t * pxEventBits = xEventGroup; + EventBits_t uxReturn, uxControlBits = 0; + BaseType_t xWaitConditionMet, xAlreadyYielded; + BaseType_t xTimeoutOccurred = pdFALSE; + + /* Check the user is not attempting to wait on the bits used by the kernel + * itself, and that at least one bit is being requested. */ + configASSERT( xEventGroup ); + configASSERT( ( uxBitsToWaitFor & eventEVENT_BITS_CONTROL_BYTES ) == 0 ); + configASSERT( uxBitsToWaitFor != 0 ); + #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) ) + { + configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) ); + } + #endif + + vTaskSuspendAll(); + { + const EventBits_t uxCurrentEventBits = pxEventBits->uxEventBits; + + /* Check to see if the wait condition is already met or not. */ + xWaitConditionMet = prvTestWaitCondition( uxCurrentEventBits, uxBitsToWaitFor, xWaitForAllBits ); + + if( xWaitConditionMet != pdFALSE ) + { + /* The wait condition has already been met so there is no need to + * block. */ + uxReturn = uxCurrentEventBits; + xTicksToWait = ( TickType_t ) 0; + + /* Clear the wait bits if requested to do so. */ + if( xClearOnExit != pdFALSE ) + { + pxEventBits->uxEventBits &= ~uxBitsToWaitFor; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else if( xTicksToWait == ( TickType_t ) 0 ) + { + /* The wait condition has not been met, but no block time was + * specified, so just return the current value. */ + uxReturn = uxCurrentEventBits; + xTimeoutOccurred = pdTRUE; + } + else + { + /* The task is going to block to wait for its required bits to be + * set. uxControlBits are used to remember the specified behaviour of + * this call to xEventGroupWaitBits() - for use when the event bits + * unblock the task. */ + if( xClearOnExit != pdFALSE ) + { + uxControlBits |= eventCLEAR_EVENTS_ON_EXIT_BIT; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + if( xWaitForAllBits != pdFALSE ) + { + uxControlBits |= eventWAIT_FOR_ALL_BITS; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* Store the bits that the calling task is waiting for in the + * task's event list item so the kernel knows when a match is + * found. Then enter the blocked state. */ + vTaskPlaceOnUnorderedEventList( &( pxEventBits->xTasksWaitingForBits ), ( uxBitsToWaitFor | uxControlBits ), xTicksToWait ); + + /* This is obsolete as it will get set after the task unblocks, but + * some compilers mistakenly generate a warning about the variable + * being returned without being set if it is not done. */ + uxReturn = 0; + + traceEVENT_GROUP_WAIT_BITS_BLOCK( xEventGroup, uxBitsToWaitFor ); + } + } + xAlreadyYielded = xTaskResumeAll(); + + if( xTicksToWait != ( TickType_t ) 0 ) + { + if( xAlreadyYielded == pdFALSE ) + { + portYIELD_WITHIN_API(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* The task blocked to wait for its required bits to be set - at this + * point either the required bits were set or the block time expired. If + * the required bits were set they will have been stored in the task's + * event list item, and they should now be retrieved then cleared. */ + uxReturn = uxTaskResetEventItemValue(); + + if( ( uxReturn & eventUNBLOCKED_DUE_TO_BIT_SET ) == ( EventBits_t ) 0 ) + { + taskENTER_CRITICAL(); + { + /* The task timed out, just return the current event bit value. */ + uxReturn = pxEventBits->uxEventBits; + + /* It is possible that the event bits were updated between this + * task leaving the Blocked state and running again. */ + if( prvTestWaitCondition( uxReturn, uxBitsToWaitFor, xWaitForAllBits ) != pdFALSE ) + { + if( xClearOnExit != pdFALSE ) + { + pxEventBits->uxEventBits &= ~uxBitsToWaitFor; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + xTimeoutOccurred = pdTRUE; + } + taskEXIT_CRITICAL(); + } + else + { + /* The task unblocked because the bits were set. */ + } + + /* The task blocked so control bits may have been set. */ + uxReturn &= ~eventEVENT_BITS_CONTROL_BYTES; + } + + traceEVENT_GROUP_WAIT_BITS_END( xEventGroup, uxBitsToWaitFor, xTimeoutOccurred ); + + /* Prevent compiler warnings when trace macros are not used. */ + ( void ) xTimeoutOccurred; + + return uxReturn; +} +/*-----------------------------------------------------------*/ + +EventBits_t xEventGroupClearBits( EventGroupHandle_t xEventGroup, + const EventBits_t uxBitsToClear ) +{ + EventGroup_t * pxEventBits = xEventGroup; + EventBits_t uxReturn; + + /* Check the user is not attempting to clear the bits used by the kernel + * itself. */ + configASSERT( xEventGroup ); + configASSERT( ( uxBitsToClear & eventEVENT_BITS_CONTROL_BYTES ) == 0 ); + + taskENTER_CRITICAL(); + { + traceEVENT_GROUP_CLEAR_BITS( xEventGroup, uxBitsToClear ); + + /* The value returned is the event group value prior to the bits being + * cleared. */ + uxReturn = pxEventBits->uxEventBits; + + /* Clear the bits. */ + pxEventBits->uxEventBits &= ~uxBitsToClear; + } + taskEXIT_CRITICAL(); + + return uxReturn; +} +/*-----------------------------------------------------------*/ + +#if ( ( configUSE_TRACE_FACILITY == 1 ) && ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) ) + + BaseType_t xEventGroupClearBitsFromISR( EventGroupHandle_t xEventGroup, + const EventBits_t uxBitsToClear ) + { + BaseType_t xReturn; + + traceEVENT_GROUP_CLEAR_BITS_FROM_ISR( xEventGroup, uxBitsToClear ); + xReturn = xTimerPendFunctionCallFromISR( vEventGroupClearBitsCallback, ( void * ) xEventGroup, ( uint32_t ) uxBitsToClear, NULL ); /*lint !e9087 Can't avoid cast to void* as a generic callback function not specific to this use case. Callback casts back to original type so safe. */ + + return xReturn; + } + +#endif /* if ( ( configUSE_TRACE_FACILITY == 1 ) && ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) ) */ +/*-----------------------------------------------------------*/ + +EventBits_t xEventGroupGetBitsFromISR( EventGroupHandle_t xEventGroup ) +{ + UBaseType_t uxSavedInterruptStatus; + EventGroup_t const * const pxEventBits = xEventGroup; + EventBits_t uxReturn; + + uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR(); + { + uxReturn = pxEventBits->uxEventBits; + } + portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); + + return uxReturn; +} /*lint !e818 EventGroupHandle_t is a typedef used in other functions to so can't be pointer to const. */ +/*-----------------------------------------------------------*/ + +EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup, + const EventBits_t uxBitsToSet ) +{ + ListItem_t * pxListItem, * pxNext; + ListItem_t const * pxListEnd; + List_t const * pxList; + EventBits_t uxBitsToClear = 0, uxBitsWaitedFor, uxControlBits; + EventGroup_t * pxEventBits = xEventGroup; + BaseType_t xMatchFound = pdFALSE; + + /* Check the user is not attempting to set the bits used by the kernel + * itself. */ + configASSERT( xEventGroup ); + configASSERT( ( uxBitsToSet & eventEVENT_BITS_CONTROL_BYTES ) == 0 ); + + pxList = &( pxEventBits->xTasksWaitingForBits ); + pxListEnd = listGET_END_MARKER( pxList ); /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. */ + vTaskSuspendAll(); + { + traceEVENT_GROUP_SET_BITS( xEventGroup, uxBitsToSet ); + + pxListItem = listGET_HEAD_ENTRY( pxList ); + + /* Set the bits. */ + pxEventBits->uxEventBits |= uxBitsToSet; + + /* See if the new bit value should unblock any tasks. */ + while( pxListItem != pxListEnd ) + { + pxNext = listGET_NEXT( pxListItem ); + uxBitsWaitedFor = listGET_LIST_ITEM_VALUE( pxListItem ); + xMatchFound = pdFALSE; + + /* Split the bits waited for from the control bits. */ + uxControlBits = uxBitsWaitedFor & eventEVENT_BITS_CONTROL_BYTES; + uxBitsWaitedFor &= ~eventEVENT_BITS_CONTROL_BYTES; + + if( ( uxControlBits & eventWAIT_FOR_ALL_BITS ) == ( EventBits_t ) 0 ) + { + /* Just looking for single bit being set. */ + if( ( uxBitsWaitedFor & pxEventBits->uxEventBits ) != ( EventBits_t ) 0 ) + { + xMatchFound = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else if( ( uxBitsWaitedFor & pxEventBits->uxEventBits ) == uxBitsWaitedFor ) + { + /* All bits are set. */ + xMatchFound = pdTRUE; + } + else + { + /* Need all bits to be set, but not all the bits were set. */ + } + + if( xMatchFound != pdFALSE ) + { + /* The bits match. Should the bits be cleared on exit? */ + if( ( uxControlBits & eventCLEAR_EVENTS_ON_EXIT_BIT ) != ( EventBits_t ) 0 ) + { + uxBitsToClear |= uxBitsWaitedFor; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* Store the actual event flag value in the task's event list + * item before removing the task from the event list. The + * eventUNBLOCKED_DUE_TO_BIT_SET bit is set so the task knows + * that is was unblocked due to its required bits matching, rather + * than because it timed out. */ + vTaskRemoveFromUnorderedEventList( pxListItem, pxEventBits->uxEventBits | eventUNBLOCKED_DUE_TO_BIT_SET ); + } + + /* Move onto the next list item. Note pxListItem->pxNext is not + * used here as the list item may have been removed from the event list + * and inserted into the ready/pending reading list. */ + pxListItem = pxNext; + } + + /* Clear any bits that matched when the eventCLEAR_EVENTS_ON_EXIT_BIT + * bit was set in the control word. */ + pxEventBits->uxEventBits &= ~uxBitsToClear; + } + ( void ) xTaskResumeAll(); + + return pxEventBits->uxEventBits; +} +/*-----------------------------------------------------------*/ + +void vEventGroupDelete( EventGroupHandle_t xEventGroup ) +{ + EventGroup_t * pxEventBits = xEventGroup; + const List_t * pxTasksWaitingForBits = &( pxEventBits->xTasksWaitingForBits ); + + vTaskSuspendAll(); + { + traceEVENT_GROUP_DELETE( xEventGroup ); + + while( listCURRENT_LIST_LENGTH( pxTasksWaitingForBits ) > ( UBaseType_t ) 0 ) + { + /* Unblock the task, returning 0 as the event list is being deleted + * and cannot therefore have any bits set. */ + configASSERT( pxTasksWaitingForBits->xListEnd.pxNext != ( const ListItem_t * ) &( pxTasksWaitingForBits->xListEnd ) ); + vTaskRemoveFromUnorderedEventList( pxTasksWaitingForBits->xListEnd.pxNext, eventUNBLOCKED_DUE_TO_BIT_SET ); + } + + #if ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 0 ) ) + { + /* The event group can only have been allocated dynamically - free + * it again. */ + vPortFree( pxEventBits ); + } + #elif ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) ) + { + /* The event group could have been allocated statically or + * dynamically, so check before attempting to free the memory. */ + if( pxEventBits->ucStaticallyAllocated == ( uint8_t ) pdFALSE ) + { + vPortFree( pxEventBits ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + #endif /* configSUPPORT_DYNAMIC_ALLOCATION */ + } + ( void ) xTaskResumeAll(); +} +/*-----------------------------------------------------------*/ + +/* For internal use only - execute a 'set bits' command that was pended from + * an interrupt. */ +void vEventGroupSetBitsCallback( void * pvEventGroup, + const uint32_t ulBitsToSet ) +{ + ( void ) xEventGroupSetBits( pvEventGroup, ( EventBits_t ) ulBitsToSet ); /*lint !e9079 Can't avoid cast to void* as a generic timer callback prototype. Callback casts back to original type so safe. */ +} +/*-----------------------------------------------------------*/ + +/* For internal use only - execute a 'clear bits' command that was pended from + * an interrupt. */ +void vEventGroupClearBitsCallback( void * pvEventGroup, + const uint32_t ulBitsToClear ) +{ + ( void ) xEventGroupClearBits( pvEventGroup, ( EventBits_t ) ulBitsToClear ); /*lint !e9079 Can't avoid cast to void* as a generic timer callback prototype. Callback casts back to original type so safe. */ +} +/*-----------------------------------------------------------*/ + +static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits, + const EventBits_t uxBitsToWaitFor, + const BaseType_t xWaitForAllBits ) +{ + BaseType_t xWaitConditionMet = pdFALSE; + + if( xWaitForAllBits == pdFALSE ) + { + /* Task only has to wait for one bit within uxBitsToWaitFor to be + * set. Is one already set? */ + if( ( uxCurrentEventBits & uxBitsToWaitFor ) != ( EventBits_t ) 0 ) + { + xWaitConditionMet = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + /* Task has to wait for all the bits in uxBitsToWaitFor to be set. + * Are they set already? */ + if( ( uxCurrentEventBits & uxBitsToWaitFor ) == uxBitsToWaitFor ) + { + xWaitConditionMet = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + + return xWaitConditionMet; +} +/*-----------------------------------------------------------*/ + +#if ( ( configUSE_TRACE_FACILITY == 1 ) && ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) ) + + BaseType_t xEventGroupSetBitsFromISR( EventGroupHandle_t xEventGroup, + const EventBits_t uxBitsToSet, + BaseType_t * pxHigherPriorityTaskWoken ) + { + BaseType_t xReturn; + + traceEVENT_GROUP_SET_BITS_FROM_ISR( xEventGroup, uxBitsToSet ); + xReturn = xTimerPendFunctionCallFromISR( vEventGroupSetBitsCallback, ( void * ) xEventGroup, ( uint32_t ) uxBitsToSet, pxHigherPriorityTaskWoken ); /*lint !e9087 Can't avoid cast to void* as a generic callback function not specific to this use case. Callback casts back to original type so safe. */ + + return xReturn; + } + +#endif /* if ( ( configUSE_TRACE_FACILITY == 1 ) && ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) ) */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_TRACE_FACILITY == 1 ) + + UBaseType_t uxEventGroupGetNumber( void * xEventGroup ) + { + UBaseType_t xReturn; + EventGroup_t const * pxEventBits = ( EventGroup_t * ) xEventGroup; /*lint !e9087 !e9079 EventGroupHandle_t is a pointer to an EventGroup_t, but EventGroupHandle_t is kept opaque outside of this file for data hiding purposes. */ + + if( xEventGroup == NULL ) + { + xReturn = 0; + } + else + { + xReturn = pxEventBits->uxEventGroupNumber; + } + + return xReturn; + } + +#endif /* configUSE_TRACE_FACILITY */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_TRACE_FACILITY == 1 ) + + void vEventGroupSetNumber( void * xEventGroup, + UBaseType_t uxEventGroupNumber ) + { + ( ( EventGroup_t * ) xEventGroup )->uxEventGroupNumber = uxEventGroupNumber; /*lint !e9087 !e9079 EventGroupHandle_t is a pointer to an EventGroup_t, but EventGroupHandle_t is kept opaque outside of this file for data hiding purposes. */ + } + +#endif /* configUSE_TRACE_FACILITY */ +/*-----------------------------------------------------------*/ diff --git a/RTOS/FreeRTOS/Source/include/FreeRTOS.h b/RTOS/FreeRTOS/Source/include/FreeRTOS.h new file mode 100644 index 0000000..6814df4 --- /dev/null +++ b/RTOS/FreeRTOS/Source/include/FreeRTOS.h @@ -0,0 +1,1325 @@ +/* + * FreeRTOS Kernel V10.4.1 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * https://www.FreeRTOS.org + * https://github.com/FreeRTOS + * + */ + +#ifndef INC_FREERTOS_H +#define INC_FREERTOS_H + +/* + * Include the generic headers required for the FreeRTOS port being used. + */ +#include + +/* + * If stdint.h cannot be located then: + * + If using GCC ensure the -nostdint options is *not* being used. + * + Ensure the project's include path includes the directory in which your + * compiler stores stdint.h. + * + Set any compiler options necessary for it to support C99, as technically + * stdint.h is only mandatory with C99 (FreeRTOS does not require C99 in any + * other way). + * + The FreeRTOS download includes a simple stdint.h definition that can be + * used in cases where none is provided by the compiler. The files only + * contains the typedefs required to build FreeRTOS. Read the instructions + * in FreeRTOS/source/stdint.readme for more information. + */ +#include /* READ COMMENT ABOVE. */ + +/* *INDENT-OFF* */ +#ifdef __cplusplus + extern "C" { +#endif +/* *INDENT-ON* */ + +/* Application specific configuration options. */ +#include "FreeRTOSConfig.h" + +/* Basic FreeRTOS definitions. */ +#include "projdefs.h" + +/* Definitions specific to the port being used. */ +#include "portable.h" + +/* Must be defaulted before configUSE_NEWLIB_REENTRANT is used below. */ +#ifndef configUSE_NEWLIB_REENTRANT + #define configUSE_NEWLIB_REENTRANT 0 +#endif + +/* Required if struct _reent is used. */ +#if ( configUSE_NEWLIB_REENTRANT == 1 ) + #include +#endif + +/* + * Check all the required application specific macros have been defined. + * These macros are application specific and (as downloaded) are defined + * within FreeRTOSConfig.h. + */ + +#ifndef configMINIMAL_STACK_SIZE + #error Missing definition: configMINIMAL_STACK_SIZE must be defined in FreeRTOSConfig.h. configMINIMAL_STACK_SIZE defines the size (in words) of the stack allocated to the idle task. Refer to the demo project provided for your port for a suitable value. +#endif + +#ifndef configMAX_PRIORITIES + #error Missing definition: configMAX_PRIORITIES must be defined in FreeRTOSConfig.h. See the Configuration section of the FreeRTOS API documentation for details. +#endif + +#if configMAX_PRIORITIES < 1 + #error configMAX_PRIORITIES must be defined to be greater than or equal to 1. +#endif + +#ifndef configUSE_PREEMPTION + #error Missing definition: configUSE_PREEMPTION must be defined in FreeRTOSConfig.h as either 1 or 0. See the Configuration section of the FreeRTOS API documentation for details. +#endif + +#ifndef configUSE_IDLE_HOOK + #error Missing definition: configUSE_IDLE_HOOK must be defined in FreeRTOSConfig.h as either 1 or 0. See the Configuration section of the FreeRTOS API documentation for details. +#endif + +#ifndef configUSE_TICK_HOOK + #error Missing definition: configUSE_TICK_HOOK must be defined in FreeRTOSConfig.h as either 1 or 0. See the Configuration section of the FreeRTOS API documentation for details. +#endif + +#ifndef configUSE_16_BIT_TICKS + #error Missing definition: configUSE_16_BIT_TICKS must be defined in FreeRTOSConfig.h as either 1 or 0. See the Configuration section of the FreeRTOS API documentation for details. +#endif + +#ifndef configUSE_CO_ROUTINES + #define configUSE_CO_ROUTINES 0 +#endif + +#ifndef INCLUDE_vTaskPrioritySet + #define INCLUDE_vTaskPrioritySet 0 +#endif + +#ifndef INCLUDE_uxTaskPriorityGet + #define INCLUDE_uxTaskPriorityGet 0 +#endif + +#ifndef INCLUDE_vTaskDelete + #define INCLUDE_vTaskDelete 0 +#endif + +#ifndef INCLUDE_vTaskSuspend + #define INCLUDE_vTaskSuspend 0 +#endif + +#ifndef INCLUDE_vTaskDelayUntil + #define INCLUDE_vTaskDelayUntil 0 +#endif + +#ifndef INCLUDE_vTaskDelay + #define INCLUDE_vTaskDelay 0 +#endif + +#ifndef INCLUDE_xTaskGetIdleTaskHandle + #define INCLUDE_xTaskGetIdleTaskHandle 0 +#endif + +#ifndef INCLUDE_xTaskAbortDelay + #define INCLUDE_xTaskAbortDelay 0 +#endif + +#ifndef INCLUDE_xQueueGetMutexHolder + #define INCLUDE_xQueueGetMutexHolder 0 +#endif + +#ifndef INCLUDE_xSemaphoreGetMutexHolder + #define INCLUDE_xSemaphoreGetMutexHolder INCLUDE_xQueueGetMutexHolder +#endif + +#ifndef INCLUDE_xTaskGetHandle + #define INCLUDE_xTaskGetHandle 0 +#endif + +#ifndef INCLUDE_uxTaskGetStackHighWaterMark + #define INCLUDE_uxTaskGetStackHighWaterMark 0 +#endif + +#ifndef INCLUDE_uxTaskGetStackHighWaterMark2 + #define INCLUDE_uxTaskGetStackHighWaterMark2 0 +#endif + +#ifndef INCLUDE_eTaskGetState + #define INCLUDE_eTaskGetState 0 +#endif + +#ifndef INCLUDE_xTaskResumeFromISR + #define INCLUDE_xTaskResumeFromISR 1 +#endif + +#ifndef INCLUDE_xTimerPendFunctionCall + #define INCLUDE_xTimerPendFunctionCall 0 +#endif + +#ifndef INCLUDE_xTaskGetSchedulerState + #define INCLUDE_xTaskGetSchedulerState 0 +#endif + +#ifndef INCLUDE_xTaskGetCurrentTaskHandle + #define INCLUDE_xTaskGetCurrentTaskHandle 0 +#endif + +#if configUSE_CO_ROUTINES != 0 + #ifndef configMAX_CO_ROUTINE_PRIORITIES + #error configMAX_CO_ROUTINE_PRIORITIES must be greater than or equal to 1. + #endif +#endif + +#ifndef configUSE_DAEMON_TASK_STARTUP_HOOK + #define configUSE_DAEMON_TASK_STARTUP_HOOK 0 +#endif + +#ifndef configUSE_APPLICATION_TASK_TAG + #define configUSE_APPLICATION_TASK_TAG 0 +#endif + +#ifndef configNUM_THREAD_LOCAL_STORAGE_POINTERS + #define configNUM_THREAD_LOCAL_STORAGE_POINTERS 0 +#endif + +#ifndef configUSE_RECURSIVE_MUTEXES + #define configUSE_RECURSIVE_MUTEXES 0 +#endif + +#ifndef configUSE_MUTEXES + #define configUSE_MUTEXES 0 +#endif + +#ifndef configUSE_TIMERS + #define configUSE_TIMERS 0 +#endif + +#ifndef configUSE_COUNTING_SEMAPHORES + #define configUSE_COUNTING_SEMAPHORES 0 +#endif + +#ifndef configUSE_ALTERNATIVE_API + #define configUSE_ALTERNATIVE_API 0 +#endif + +#ifndef portCRITICAL_NESTING_IN_TCB + #define portCRITICAL_NESTING_IN_TCB 0 +#endif + +#ifndef configMAX_TASK_NAME_LEN + #define configMAX_TASK_NAME_LEN 16 +#endif + +#ifndef configIDLE_SHOULD_YIELD + #define configIDLE_SHOULD_YIELD 1 +#endif + +#if configMAX_TASK_NAME_LEN < 1 + #error configMAX_TASK_NAME_LEN must be set to a minimum of 1 in FreeRTOSConfig.h +#endif + +#ifndef configASSERT + #define configASSERT( x ) + #define configASSERT_DEFINED 0 +#else + #define configASSERT_DEFINED 1 +#endif + +/* configPRECONDITION should be defined as configASSERT. + * The CBMC proofs need a way to track assumptions and assertions. + * A configPRECONDITION statement should express an implicit invariant or + * assumption made. A configASSERT statement should express an invariant that must + * hold explicit before calling the code. */ +#ifndef configPRECONDITION + #define configPRECONDITION( X ) configASSERT( X ) + #define configPRECONDITION_DEFINED 0 +#else + #define configPRECONDITION_DEFINED 1 +#endif + +#ifndef portMEMORY_BARRIER + #define portMEMORY_BARRIER() +#endif + +#ifndef portSOFTWARE_BARRIER + #define portSOFTWARE_BARRIER() +#endif + +/* The timers module relies on xTaskGetSchedulerState(). */ +#if configUSE_TIMERS == 1 + + #ifndef configTIMER_TASK_PRIORITY + #error If configUSE_TIMERS is set to 1 then configTIMER_TASK_PRIORITY must also be defined. + #endif /* configTIMER_TASK_PRIORITY */ + + #ifndef configTIMER_QUEUE_LENGTH + #error If configUSE_TIMERS is set to 1 then configTIMER_QUEUE_LENGTH must also be defined. + #endif /* configTIMER_QUEUE_LENGTH */ + + #ifndef configTIMER_TASK_STACK_DEPTH + #error If configUSE_TIMERS is set to 1 then configTIMER_TASK_STACK_DEPTH must also be defined. + #endif /* configTIMER_TASK_STACK_DEPTH */ + +#endif /* configUSE_TIMERS */ + +#ifndef portSET_INTERRUPT_MASK_FROM_ISR + #define portSET_INTERRUPT_MASK_FROM_ISR() 0 +#endif + +#ifndef portCLEAR_INTERRUPT_MASK_FROM_ISR + #define portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedStatusValue ) ( void ) uxSavedStatusValue +#endif + +#ifndef portCLEAN_UP_TCB + #define portCLEAN_UP_TCB( pxTCB ) ( void ) pxTCB +#endif + +#ifndef portPRE_TASK_DELETE_HOOK + #define portPRE_TASK_DELETE_HOOK( pvTaskToDelete, pxYieldPending ) +#endif + +#ifndef portSETUP_TCB + #define portSETUP_TCB( pxTCB ) ( void ) pxTCB +#endif + +#ifndef configQUEUE_REGISTRY_SIZE + #define configQUEUE_REGISTRY_SIZE 0U +#endif + +#if ( configQUEUE_REGISTRY_SIZE < 1 ) + #define vQueueAddToRegistry( xQueue, pcName ) + #define vQueueUnregisterQueue( xQueue ) + #define pcQueueGetName( xQueue ) +#endif + +#ifndef portPOINTER_SIZE_TYPE + #define portPOINTER_SIZE_TYPE uint32_t +#endif + +/* Remove any unused trace macros. */ +#ifndef traceSTART + +/* Used to perform any necessary initialisation - for example, open a file + * into which trace is to be written. */ + #define traceSTART() +#endif + +#ifndef traceEND + +/* Use to close a trace, for example close a file into which trace has been + * written. */ + #define traceEND() +#endif + +#ifndef traceTASK_SWITCHED_IN + +/* Called after a task has been selected to run. pxCurrentTCB holds a pointer + * to the task control block of the selected task. */ + #define traceTASK_SWITCHED_IN() +#endif + +#ifndef traceINCREASE_TICK_COUNT + +/* Called before stepping the tick count after waking from tickless idle + * sleep. */ + #define traceINCREASE_TICK_COUNT( x ) +#endif + +#ifndef traceLOW_POWER_IDLE_BEGIN + /* Called immediately before entering tickless idle. */ + #define traceLOW_POWER_IDLE_BEGIN() +#endif + +#ifndef traceLOW_POWER_IDLE_END + /* Called when returning to the Idle task after a tickless idle. */ + #define traceLOW_POWER_IDLE_END() +#endif + +#ifndef traceTASK_SWITCHED_OUT + +/* Called before a task has been selected to run. pxCurrentTCB holds a pointer + * to the task control block of the task being switched out. */ + #define traceTASK_SWITCHED_OUT() +#endif + +#ifndef traceTASK_PRIORITY_INHERIT + +/* Called when a task attempts to take a mutex that is already held by a + * lower priority task. pxTCBOfMutexHolder is a pointer to the TCB of the task + * that holds the mutex. uxInheritedPriority is the priority the mutex holder + * will inherit (the priority of the task that is attempting to obtain the + * muted. */ + #define traceTASK_PRIORITY_INHERIT( pxTCBOfMutexHolder, uxInheritedPriority ) +#endif + +#ifndef traceTASK_PRIORITY_DISINHERIT + +/* Called when a task releases a mutex, the holding of which had resulted in + * the task inheriting the priority of a higher priority task. + * pxTCBOfMutexHolder is a pointer to the TCB of the task that is releasing the + * mutex. uxOriginalPriority is the task's configured (base) priority. */ + #define traceTASK_PRIORITY_DISINHERIT( pxTCBOfMutexHolder, uxOriginalPriority ) +#endif + +#ifndef traceBLOCKING_ON_QUEUE_RECEIVE + +/* Task is about to block because it cannot read from a + * queue/mutex/semaphore. pxQueue is a pointer to the queue/mutex/semaphore + * upon which the read was attempted. pxCurrentTCB points to the TCB of the + * task that attempted the read. */ + #define traceBLOCKING_ON_QUEUE_RECEIVE( pxQueue ) +#endif + +#ifndef traceBLOCKING_ON_QUEUE_PEEK + +/* Task is about to block because it cannot read from a + * queue/mutex/semaphore. pxQueue is a pointer to the queue/mutex/semaphore + * upon which the read was attempted. pxCurrentTCB points to the TCB of the + * task that attempted the read. */ + #define traceBLOCKING_ON_QUEUE_PEEK( pxQueue ) +#endif + +#ifndef traceBLOCKING_ON_QUEUE_SEND + +/* Task is about to block because it cannot write to a + * queue/mutex/semaphore. pxQueue is a pointer to the queue/mutex/semaphore + * upon which the write was attempted. pxCurrentTCB points to the TCB of the + * task that attempted the write. */ + #define traceBLOCKING_ON_QUEUE_SEND( pxQueue ) +#endif + +#ifndef configCHECK_FOR_STACK_OVERFLOW + #define configCHECK_FOR_STACK_OVERFLOW 0 +#endif + +#ifndef configRECORD_STACK_HIGH_ADDRESS + #define configRECORD_STACK_HIGH_ADDRESS 0 +#endif + +#ifndef configINCLUDE_FREERTOS_TASK_C_ADDITIONS_H + #define configINCLUDE_FREERTOS_TASK_C_ADDITIONS_H 0 +#endif + +/* The following event macros are embedded in the kernel API calls. */ + +#ifndef traceMOVED_TASK_TO_READY_STATE + #define traceMOVED_TASK_TO_READY_STATE( pxTCB ) +#endif + +#ifndef tracePOST_MOVED_TASK_TO_READY_STATE + #define tracePOST_MOVED_TASK_TO_READY_STATE( pxTCB ) +#endif + +#ifndef traceQUEUE_CREATE + #define traceQUEUE_CREATE( pxNewQueue ) +#endif + +#ifndef traceQUEUE_CREATE_FAILED + #define traceQUEUE_CREATE_FAILED( ucQueueType ) +#endif + +#ifndef traceCREATE_MUTEX + #define traceCREATE_MUTEX( pxNewQueue ) +#endif + +#ifndef traceCREATE_MUTEX_FAILED + #define traceCREATE_MUTEX_FAILED() +#endif + +#ifndef traceGIVE_MUTEX_RECURSIVE + #define traceGIVE_MUTEX_RECURSIVE( pxMutex ) +#endif + +#ifndef traceGIVE_MUTEX_RECURSIVE_FAILED + #define traceGIVE_MUTEX_RECURSIVE_FAILED( pxMutex ) +#endif + +#ifndef traceTAKE_MUTEX_RECURSIVE + #define traceTAKE_MUTEX_RECURSIVE( pxMutex ) +#endif + +#ifndef traceTAKE_MUTEX_RECURSIVE_FAILED + #define traceTAKE_MUTEX_RECURSIVE_FAILED( pxMutex ) +#endif + +#ifndef traceCREATE_COUNTING_SEMAPHORE + #define traceCREATE_COUNTING_SEMAPHORE() +#endif + +#ifndef traceCREATE_COUNTING_SEMAPHORE_FAILED + #define traceCREATE_COUNTING_SEMAPHORE_FAILED() +#endif + +#ifndef traceQUEUE_SET_SEND + #define traceQUEUE_SET_SEND traceQUEUE_SEND +#endif + +#ifndef traceQUEUE_SEND + #define traceQUEUE_SEND( pxQueue ) +#endif + +#ifndef traceQUEUE_SEND_FAILED + #define traceQUEUE_SEND_FAILED( pxQueue ) +#endif + +#ifndef traceQUEUE_RECEIVE + #define traceQUEUE_RECEIVE( pxQueue ) +#endif + +#ifndef traceQUEUE_PEEK + #define traceQUEUE_PEEK( pxQueue ) +#endif + +#ifndef traceQUEUE_PEEK_FAILED + #define traceQUEUE_PEEK_FAILED( pxQueue ) +#endif + +#ifndef traceQUEUE_PEEK_FROM_ISR + #define traceQUEUE_PEEK_FROM_ISR( pxQueue ) +#endif + +#ifndef traceQUEUE_RECEIVE_FAILED + #define traceQUEUE_RECEIVE_FAILED( pxQueue ) +#endif + +#ifndef traceQUEUE_SEND_FROM_ISR + #define traceQUEUE_SEND_FROM_ISR( pxQueue ) +#endif + +#ifndef traceQUEUE_SEND_FROM_ISR_FAILED + #define traceQUEUE_SEND_FROM_ISR_FAILED( pxQueue ) +#endif + +#ifndef traceQUEUE_RECEIVE_FROM_ISR + #define traceQUEUE_RECEIVE_FROM_ISR( pxQueue ) +#endif + +#ifndef traceQUEUE_RECEIVE_FROM_ISR_FAILED + #define traceQUEUE_RECEIVE_FROM_ISR_FAILED( pxQueue ) +#endif + +#ifndef traceQUEUE_PEEK_FROM_ISR_FAILED + #define traceQUEUE_PEEK_FROM_ISR_FAILED( pxQueue ) +#endif + +#ifndef traceQUEUE_DELETE + #define traceQUEUE_DELETE( pxQueue ) +#endif + +#ifndef traceTASK_CREATE + #define traceTASK_CREATE( pxNewTCB ) +#endif + +#ifndef traceTASK_CREATE_FAILED + #define traceTASK_CREATE_FAILED() +#endif + +#ifndef traceTASK_DELETE + #define traceTASK_DELETE( pxTaskToDelete ) +#endif + +#ifndef traceTASK_DELAY_UNTIL + #define traceTASK_DELAY_UNTIL( x ) +#endif + +#ifndef traceTASK_DELAY + #define traceTASK_DELAY() +#endif + +#ifndef traceTASK_PRIORITY_SET + #define traceTASK_PRIORITY_SET( pxTask, uxNewPriority ) +#endif + +#ifndef traceTASK_SUSPEND + #define traceTASK_SUSPEND( pxTaskToSuspend ) +#endif + +#ifndef traceTASK_RESUME + #define traceTASK_RESUME( pxTaskToResume ) +#endif + +#ifndef traceTASK_RESUME_FROM_ISR + #define traceTASK_RESUME_FROM_ISR( pxTaskToResume ) +#endif + +#ifndef traceTASK_INCREMENT_TICK + #define traceTASK_INCREMENT_TICK( xTickCount ) +#endif + +#ifndef traceTIMER_CREATE + #define traceTIMER_CREATE( pxNewTimer ) +#endif + +#ifndef traceTIMER_CREATE_FAILED + #define traceTIMER_CREATE_FAILED() +#endif + +#ifndef traceTIMER_COMMAND_SEND + #define traceTIMER_COMMAND_SEND( xTimer, xMessageID, xMessageValueValue, xReturn ) +#endif + +#ifndef traceTIMER_EXPIRED + #define traceTIMER_EXPIRED( pxTimer ) +#endif + +#ifndef traceTIMER_COMMAND_RECEIVED + #define traceTIMER_COMMAND_RECEIVED( pxTimer, xMessageID, xMessageValue ) +#endif + +#ifndef traceMALLOC + #define traceMALLOC( pvAddress, uiSize ) +#endif + +#ifndef traceFREE + #define traceFREE( pvAddress, uiSize ) +#endif + +#ifndef traceEVENT_GROUP_CREATE + #define traceEVENT_GROUP_CREATE( xEventGroup ) +#endif + +#ifndef traceEVENT_GROUP_CREATE_FAILED + #define traceEVENT_GROUP_CREATE_FAILED() +#endif + +#ifndef traceEVENT_GROUP_SYNC_BLOCK + #define traceEVENT_GROUP_SYNC_BLOCK( xEventGroup, uxBitsToSet, uxBitsToWaitFor ) +#endif + +#ifndef traceEVENT_GROUP_SYNC_END + #define traceEVENT_GROUP_SYNC_END( xEventGroup, uxBitsToSet, uxBitsToWaitFor, xTimeoutOccurred ) ( void ) xTimeoutOccurred +#endif + +#ifndef traceEVENT_GROUP_WAIT_BITS_BLOCK + #define traceEVENT_GROUP_WAIT_BITS_BLOCK( xEventGroup, uxBitsToWaitFor ) +#endif + +#ifndef traceEVENT_GROUP_WAIT_BITS_END + #define traceEVENT_GROUP_WAIT_BITS_END( xEventGroup, uxBitsToWaitFor, xTimeoutOccurred ) ( void ) xTimeoutOccurred +#endif + +#ifndef traceEVENT_GROUP_CLEAR_BITS + #define traceEVENT_GROUP_CLEAR_BITS( xEventGroup, uxBitsToClear ) +#endif + +#ifndef traceEVENT_GROUP_CLEAR_BITS_FROM_ISR + #define traceEVENT_GROUP_CLEAR_BITS_FROM_ISR( xEventGroup, uxBitsToClear ) +#endif + +#ifndef traceEVENT_GROUP_SET_BITS + #define traceEVENT_GROUP_SET_BITS( xEventGroup, uxBitsToSet ) +#endif + +#ifndef traceEVENT_GROUP_SET_BITS_FROM_ISR + #define traceEVENT_GROUP_SET_BITS_FROM_ISR( xEventGroup, uxBitsToSet ) +#endif + +#ifndef traceEVENT_GROUP_DELETE + #define traceEVENT_GROUP_DELETE( xEventGroup ) +#endif + +#ifndef tracePEND_FUNC_CALL + #define tracePEND_FUNC_CALL( xFunctionToPend, pvParameter1, ulParameter2, ret ) +#endif + +#ifndef tracePEND_FUNC_CALL_FROM_ISR + #define tracePEND_FUNC_CALL_FROM_ISR( xFunctionToPend, pvParameter1, ulParameter2, ret ) +#endif + +#ifndef traceQUEUE_REGISTRY_ADD + #define traceQUEUE_REGISTRY_ADD( xQueue, pcQueueName ) +#endif + +#ifndef traceTASK_NOTIFY_TAKE_BLOCK + #define traceTASK_NOTIFY_TAKE_BLOCK( uxIndexToWait ) +#endif + +#ifndef traceTASK_NOTIFY_TAKE + #define traceTASK_NOTIFY_TAKE( uxIndexToWait ) +#endif + +#ifndef traceTASK_NOTIFY_WAIT_BLOCK + #define traceTASK_NOTIFY_WAIT_BLOCK( uxIndexToWait ) +#endif + +#ifndef traceTASK_NOTIFY_WAIT + #define traceTASK_NOTIFY_WAIT( uxIndexToWait ) +#endif + +#ifndef traceTASK_NOTIFY + #define traceTASK_NOTIFY( uxIndexToNotify ) +#endif + +#ifndef traceTASK_NOTIFY_FROM_ISR + #define traceTASK_NOTIFY_FROM_ISR( uxIndexToNotify ) +#endif + +#ifndef traceTASK_NOTIFY_GIVE_FROM_ISR + #define traceTASK_NOTIFY_GIVE_FROM_ISR( uxIndexToNotify ) +#endif + +#ifndef traceSTREAM_BUFFER_CREATE_FAILED + #define traceSTREAM_BUFFER_CREATE_FAILED( xIsMessageBuffer ) +#endif + +#ifndef traceSTREAM_BUFFER_CREATE_STATIC_FAILED + #define traceSTREAM_BUFFER_CREATE_STATIC_FAILED( xReturn, xIsMessageBuffer ) +#endif + +#ifndef traceSTREAM_BUFFER_CREATE + #define traceSTREAM_BUFFER_CREATE( pxStreamBuffer, xIsMessageBuffer ) +#endif + +#ifndef traceSTREAM_BUFFER_DELETE + #define traceSTREAM_BUFFER_DELETE( xStreamBuffer ) +#endif + +#ifndef traceSTREAM_BUFFER_RESET + #define traceSTREAM_BUFFER_RESET( xStreamBuffer ) +#endif + +#ifndef traceBLOCKING_ON_STREAM_BUFFER_SEND + #define traceBLOCKING_ON_STREAM_BUFFER_SEND( xStreamBuffer ) +#endif + +#ifndef traceSTREAM_BUFFER_SEND + #define traceSTREAM_BUFFER_SEND( xStreamBuffer, xBytesSent ) +#endif + +#ifndef traceSTREAM_BUFFER_SEND_FAILED + #define traceSTREAM_BUFFER_SEND_FAILED( xStreamBuffer ) +#endif + +#ifndef traceSTREAM_BUFFER_SEND_FROM_ISR + #define traceSTREAM_BUFFER_SEND_FROM_ISR( xStreamBuffer, xBytesSent ) +#endif + +#ifndef traceBLOCKING_ON_STREAM_BUFFER_RECEIVE + #define traceBLOCKING_ON_STREAM_BUFFER_RECEIVE( xStreamBuffer ) +#endif + +#ifndef traceSTREAM_BUFFER_RECEIVE + #define traceSTREAM_BUFFER_RECEIVE( xStreamBuffer, xReceivedLength ) +#endif + +#ifndef traceSTREAM_BUFFER_RECEIVE_FAILED + #define traceSTREAM_BUFFER_RECEIVE_FAILED( xStreamBuffer ) +#endif + +#ifndef traceSTREAM_BUFFER_RECEIVE_FROM_ISR + #define traceSTREAM_BUFFER_RECEIVE_FROM_ISR( xStreamBuffer, xReceivedLength ) +#endif + +#ifndef configGENERATE_RUN_TIME_STATS + #define configGENERATE_RUN_TIME_STATS 0 +#endif + +#if ( configGENERATE_RUN_TIME_STATS == 1 ) + + #ifndef portCONFIGURE_TIMER_FOR_RUN_TIME_STATS + #error If configGENERATE_RUN_TIME_STATS is defined then portCONFIGURE_TIMER_FOR_RUN_TIME_STATS must also be defined. portCONFIGURE_TIMER_FOR_RUN_TIME_STATS should call a port layer function to setup a peripheral timer/counter that can then be used as the run time counter time base. + #endif /* portCONFIGURE_TIMER_FOR_RUN_TIME_STATS */ + + #ifndef portGET_RUN_TIME_COUNTER_VALUE + #ifndef portALT_GET_RUN_TIME_COUNTER_VALUE + #error If configGENERATE_RUN_TIME_STATS is defined then either portGET_RUN_TIME_COUNTER_VALUE or portALT_GET_RUN_TIME_COUNTER_VALUE must also be defined. See the examples provided and the FreeRTOS web site for more information. + #endif /* portALT_GET_RUN_TIME_COUNTER_VALUE */ + #endif /* portGET_RUN_TIME_COUNTER_VALUE */ + +#endif /* configGENERATE_RUN_TIME_STATS */ + +#ifndef portCONFIGURE_TIMER_FOR_RUN_TIME_STATS + #define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() +#endif + +#ifndef configUSE_MALLOC_FAILED_HOOK + #define configUSE_MALLOC_FAILED_HOOK 0 +#endif + +#ifndef portPRIVILEGE_BIT + #define portPRIVILEGE_BIT ( ( UBaseType_t ) 0x00 ) +#endif + +#ifndef portYIELD_WITHIN_API + #define portYIELD_WITHIN_API portYIELD +#endif + +#ifndef portSUPPRESS_TICKS_AND_SLEEP + #define portSUPPRESS_TICKS_AND_SLEEP( xExpectedIdleTime ) +#endif + +#ifndef configEXPECTED_IDLE_TIME_BEFORE_SLEEP + #define configEXPECTED_IDLE_TIME_BEFORE_SLEEP 2 +#endif + +#if configEXPECTED_IDLE_TIME_BEFORE_SLEEP < 2 + #error configEXPECTED_IDLE_TIME_BEFORE_SLEEP must not be less than 2 +#endif + +#ifndef configUSE_TICKLESS_IDLE + #define configUSE_TICKLESS_IDLE 0 +#endif + +#ifndef configPRE_SUPPRESS_TICKS_AND_SLEEP_PROCESSING + #define configPRE_SUPPRESS_TICKS_AND_SLEEP_PROCESSING( x ) +#endif + +#ifndef configPRE_SLEEP_PROCESSING + #define configPRE_SLEEP_PROCESSING( x ) +#endif + +#ifndef configPOST_SLEEP_PROCESSING + #define configPOST_SLEEP_PROCESSING( x ) +#endif + +#ifndef configUSE_QUEUE_SETS + #define configUSE_QUEUE_SETS 0 +#endif + +#ifndef portTASK_USES_FLOATING_POINT + #define portTASK_USES_FLOATING_POINT() +#endif + +#ifndef portALLOCATE_SECURE_CONTEXT + #define portALLOCATE_SECURE_CONTEXT( ulSecureStackSize ) +#endif + +#ifndef portDONT_DISCARD + #define portDONT_DISCARD +#endif + +#ifndef configUSE_TIME_SLICING + #define configUSE_TIME_SLICING 1 +#endif + +#ifndef configINCLUDE_APPLICATION_DEFINED_PRIVILEGED_FUNCTIONS + #define configINCLUDE_APPLICATION_DEFINED_PRIVILEGED_FUNCTIONS 0 +#endif + +#ifndef configUSE_STATS_FORMATTING_FUNCTIONS + #define configUSE_STATS_FORMATTING_FUNCTIONS 0 +#endif + +#ifndef portASSERT_IF_INTERRUPT_PRIORITY_INVALID + #define portASSERT_IF_INTERRUPT_PRIORITY_INVALID() +#endif + +#ifndef configUSE_TRACE_FACILITY + #define configUSE_TRACE_FACILITY 0 +#endif + +#ifndef mtCOVERAGE_TEST_MARKER + #define mtCOVERAGE_TEST_MARKER() +#endif + +#ifndef mtCOVERAGE_TEST_DELAY + #define mtCOVERAGE_TEST_DELAY() +#endif + +#ifndef portASSERT_IF_IN_ISR + #define portASSERT_IF_IN_ISR() +#endif + +#ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION + #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 +#endif + +#ifndef configAPPLICATION_ALLOCATED_HEAP + #define configAPPLICATION_ALLOCATED_HEAP 0 +#endif + +#ifndef configUSE_TASK_NOTIFICATIONS + #define configUSE_TASK_NOTIFICATIONS 1 +#endif + +#ifndef configTASK_NOTIFICATION_ARRAY_ENTRIES + #define configTASK_NOTIFICATION_ARRAY_ENTRIES 1 +#endif + +#if configTASK_NOTIFICATION_ARRAY_ENTRIES < 1 + #error configTASK_NOTIFICATION_ARRAY_ENTRIES must be at least 1 +#endif + +#ifndef configUSE_POSIX_ERRNO + #define configUSE_POSIX_ERRNO 0 +#endif + +#ifndef portTICK_TYPE_IS_ATOMIC + #define portTICK_TYPE_IS_ATOMIC 0 +#endif + +#ifndef configSUPPORT_STATIC_ALLOCATION + /* Defaults to 0 for backward compatibility. */ + #define configSUPPORT_STATIC_ALLOCATION 0 +#endif + +#ifndef configSUPPORT_DYNAMIC_ALLOCATION + /* Defaults to 1 for backward compatibility. */ + #define configSUPPORT_DYNAMIC_ALLOCATION 1 +#endif + +#ifndef configSTACK_DEPTH_TYPE + +/* Defaults to uint16_t for backward compatibility, but can be overridden + * in FreeRTOSConfig.h if uint16_t is too restrictive. */ + #define configSTACK_DEPTH_TYPE uint16_t +#endif + +#ifndef configMESSAGE_BUFFER_LENGTH_TYPE + +/* Defaults to size_t for backward compatibility, but can be overridden + * in FreeRTOSConfig.h if lengths will always be less than the number of bytes + * in a size_t. */ + #define configMESSAGE_BUFFER_LENGTH_TYPE size_t +#endif + +/* Sanity check the configuration. */ +#if ( configUSE_TICKLESS_IDLE != 0 ) + #if ( INCLUDE_vTaskSuspend != 1 ) + #error INCLUDE_vTaskSuspend must be set to 1 if configUSE_TICKLESS_IDLE is not set to 0 + #endif /* INCLUDE_vTaskSuspend */ +#endif /* configUSE_TICKLESS_IDLE */ + +#if ( ( configSUPPORT_STATIC_ALLOCATION == 0 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 0 ) ) + #error configSUPPORT_STATIC_ALLOCATION and configSUPPORT_DYNAMIC_ALLOCATION cannot both be 0, but can both be 1. +#endif + +#if ( ( configUSE_RECURSIVE_MUTEXES == 1 ) && ( configUSE_MUTEXES != 1 ) ) + #error configUSE_MUTEXES must be set to 1 to use recursive mutexes +#endif + +#ifndef configINITIAL_TICK_COUNT + #define configINITIAL_TICK_COUNT 0 +#endif + +#if ( portTICK_TYPE_IS_ATOMIC == 0 ) + +/* Either variables of tick type cannot be read atomically, or + * portTICK_TYPE_IS_ATOMIC was not set - map the critical sections used when + * the tick count is returned to the standard critical section macros. */ + #define portTICK_TYPE_ENTER_CRITICAL() portENTER_CRITICAL() + #define portTICK_TYPE_EXIT_CRITICAL() portEXIT_CRITICAL() + #define portTICK_TYPE_SET_INTERRUPT_MASK_FROM_ISR() portSET_INTERRUPT_MASK_FROM_ISR() + #define portTICK_TYPE_CLEAR_INTERRUPT_MASK_FROM_ISR( x ) portCLEAR_INTERRUPT_MASK_FROM_ISR( ( x ) ) +#else + +/* The tick type can be read atomically, so critical sections used when the + * tick count is returned can be defined away. */ + #define portTICK_TYPE_ENTER_CRITICAL() + #define portTICK_TYPE_EXIT_CRITICAL() + #define portTICK_TYPE_SET_INTERRUPT_MASK_FROM_ISR() 0 + #define portTICK_TYPE_CLEAR_INTERRUPT_MASK_FROM_ISR( x ) ( void ) x +#endif /* if ( portTICK_TYPE_IS_ATOMIC == 0 ) */ + +/* Definitions to allow backward compatibility with FreeRTOS versions prior to + * V8 if desired. */ +#ifndef configENABLE_BACKWARD_COMPATIBILITY + #define configENABLE_BACKWARD_COMPATIBILITY 1 +#endif + +#ifndef configPRINTF + +/* configPRINTF() was not defined, so define it away to nothing. To use + * configPRINTF() then define it as follows (where MyPrintFunction() is + * provided by the application writer): + * + * void MyPrintFunction(const char *pcFormat, ... ); + #define configPRINTF( X ) MyPrintFunction X + * + * Then call like a standard printf() function, but placing brackets around + * all parameters so they are passed as a single parameter. For example: + * configPRINTF( ("Value = %d", MyVariable) ); */ + #define configPRINTF( X ) +#endif + +#ifndef configMAX + +/* The application writer has not provided their own MAX macro, so define + * the following generic implementation. */ + #define configMAX( a, b ) ( ( ( a ) > ( b ) ) ? ( a ) : ( b ) ) +#endif + +#ifndef configMIN + +/* The application writer has not provided their own MAX macro, so define + * the following generic implementation. */ + #define configMIN( a, b ) ( ( ( a ) < ( b ) ) ? ( a ) : ( b ) ) +#endif + +#if configENABLE_BACKWARD_COMPATIBILITY == 1 + #define eTaskStateGet eTaskGetState + #define portTickType TickType_t + #define xTaskHandle TaskHandle_t + #define xQueueHandle QueueHandle_t + #define xSemaphoreHandle SemaphoreHandle_t + #define xQueueSetHandle QueueSetHandle_t + #define xQueueSetMemberHandle QueueSetMemberHandle_t + #define xTimeOutType TimeOut_t + #define xMemoryRegion MemoryRegion_t + #define xTaskParameters TaskParameters_t + #define xTaskStatusType TaskStatus_t + #define xTimerHandle TimerHandle_t + #define xCoRoutineHandle CoRoutineHandle_t + #define pdTASK_HOOK_CODE TaskHookFunction_t + #define portTICK_RATE_MS portTICK_PERIOD_MS + #define pcTaskGetTaskName pcTaskGetName + #define pcTimerGetTimerName pcTimerGetName + #define pcQueueGetQueueName pcQueueGetName + #define vTaskGetTaskInfo vTaskGetInfo + #define xTaskGetIdleRunTimeCounter ulTaskGetIdleRunTimeCounter + +/* Backward compatibility within the scheduler code only - these definitions + * are not really required but are included for completeness. */ + #define tmrTIMER_CALLBACK TimerCallbackFunction_t + #define pdTASK_CODE TaskFunction_t + #define xListItem ListItem_t + #define xList List_t + +/* For libraries that break the list data hiding, and access list structure + * members directly (which is not supposed to be done). */ + #define pxContainer pvContainer +#endif /* configENABLE_BACKWARD_COMPATIBILITY */ + +#if ( configUSE_ALTERNATIVE_API != 0 ) + #error The alternative API was deprecated some time ago, and was removed in FreeRTOS V9.0 0 +#endif + +/* Set configUSE_TASK_FPU_SUPPORT to 0 to omit floating point support even + * if floating point hardware is otherwise supported by the FreeRTOS port in use. + * This constant is not supported by all FreeRTOS ports that include floating + * point support. */ +#ifndef configUSE_TASK_FPU_SUPPORT + #define configUSE_TASK_FPU_SUPPORT 1 +#endif + +/* Set configENABLE_MPU to 1 to enable MPU support and 0 to disable it. This is + * currently used in ARMv8M ports. */ +#ifndef configENABLE_MPU + #define configENABLE_MPU 0 +#endif + +/* Set configENABLE_FPU to 1 to enable FPU support and 0 to disable it. This is + * currently used in ARMv8M ports. */ +#ifndef configENABLE_FPU + #define configENABLE_FPU 1 +#endif + +/* Set configENABLE_TRUSTZONE to 1 enable TrustZone support and 0 to disable it. + * This is currently used in ARMv8M ports. */ +#ifndef configENABLE_TRUSTZONE + #define configENABLE_TRUSTZONE 1 +#endif + +/* Set configRUN_FREERTOS_SECURE_ONLY to 1 to run the FreeRTOS ARMv8M port on + * the Secure Side only. */ +#ifndef configRUN_FREERTOS_SECURE_ONLY + #define configRUN_FREERTOS_SECURE_ONLY 0 +#endif + +/* Sometimes the FreeRTOSConfig.h settings only allow a task to be created using + * dynamically allocated RAM, in which case when any task is deleted it is known + * that both the task's stack and TCB need to be freed. Sometimes the + * FreeRTOSConfig.h settings only allow a task to be created using statically + * allocated RAM, in which case when any task is deleted it is known that neither + * the task's stack or TCB should be freed. Sometimes the FreeRTOSConfig.h + * settings allow a task to be created using either statically or dynamically + * allocated RAM, in which case a member of the TCB is used to record whether the + * stack and/or TCB were allocated statically or dynamically, so when a task is + * deleted the RAM that was allocated dynamically is freed again and no attempt is + * made to free the RAM that was allocated statically. + * tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE is only true if it is possible for a + * task to be created using either statically or dynamically allocated RAM. Note + * that if portUSING_MPU_WRAPPERS is 1 then a protected task can be created with + * a statically allocated stack and a dynamically allocated TCB. + * + * The following table lists various combinations of portUSING_MPU_WRAPPERS, + * configSUPPORT_DYNAMIC_ALLOCATION and configSUPPORT_STATIC_ALLOCATION and + * when it is possible to have both static and dynamic allocation: + * +-----+---------+--------+-----------------------------+-----------------------------------+------------------+-----------+ + * | MPU | Dynamic | Static | Available Functions | Possible Allocations | Both Dynamic and | Need Free | + * | | | | | | Static Possible | | + * +-----+---------+--------+-----------------------------+-----------------------------------+------------------+-----------+ + * | 0 | 0 | 1 | xTaskCreateStatic | TCB - Static, Stack - Static | No | No | + * +-----|---------|--------|-----------------------------|-----------------------------------|------------------|-----------| + * | 0 | 1 | 0 | xTaskCreate | TCB - Dynamic, Stack - Dynamic | No | Yes | + * +-----|---------|--------|-----------------------------|-----------------------------------|------------------|-----------| + * | 0 | 1 | 1 | xTaskCreate, | 1. TCB - Dynamic, Stack - Dynamic | Yes | Yes | + * | | | | xTaskCreateStatic | 2. TCB - Static, Stack - Static | | | + * +-----|---------|--------|-----------------------------|-----------------------------------|------------------|-----------| + * | 1 | 0 | 1 | xTaskCreateStatic, | TCB - Static, Stack - Static | No | No | + * | | | | xTaskCreateRestrictedStatic | | | | + * +-----|---------|--------|-----------------------------|-----------------------------------|------------------|-----------| + * | 1 | 1 | 0 | xTaskCreate, | 1. TCB - Dynamic, Stack - Dynamic | Yes | Yes | + * | | | | xTaskCreateRestricted | 2. TCB - Dynamic, Stack - Static | | | + * +-----|---------|--------|-----------------------------|-----------------------------------|------------------|-----------| + * | 1 | 1 | 1 | xTaskCreate, | 1. TCB - Dynamic, Stack - Dynamic | Yes | Yes | + * | | | | xTaskCreateStatic, | 2. TCB - Dynamic, Stack - Static | | | + * | | | | xTaskCreateRestricted, | 3. TCB - Static, Stack - Static | | | + * | | | | xTaskCreateRestrictedStatic | | | | + * +-----+---------+--------+-----------------------------+-----------------------------------+------------------+-----------+ + */ +#define tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE \ + ( ( ( portUSING_MPU_WRAPPERS == 0 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) ) || \ + ( ( portUSING_MPU_WRAPPERS == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) ) + +/* + * In line with software engineering best practice, FreeRTOS implements a strict + * data hiding policy, so the real structures used by FreeRTOS to maintain the + * state of tasks, queues, semaphores, etc. are not accessible to the application + * code. However, if the application writer wants to statically allocate such + * an object then the size of the object needs to be know. Dummy structures + * that are guaranteed to have the same size and alignment requirements of the + * real objects are used for this purpose. The dummy list and list item + * structures below are used for inclusion in such a dummy structure. + */ +struct xSTATIC_LIST_ITEM +{ + #if ( configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES == 1 ) + TickType_t xDummy1; + #endif + TickType_t xDummy2; + void * pvDummy3[ 4 ]; + #if ( configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES == 1 ) + TickType_t xDummy4; + #endif +}; +typedef struct xSTATIC_LIST_ITEM StaticListItem_t; + +/* See the comments above the struct xSTATIC_LIST_ITEM definition. */ +struct xSTATIC_MINI_LIST_ITEM +{ + #if ( configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES == 1 ) + TickType_t xDummy1; + #endif + TickType_t xDummy2; + void * pvDummy3[ 2 ]; +}; +typedef struct xSTATIC_MINI_LIST_ITEM StaticMiniListItem_t; + +/* See the comments above the struct xSTATIC_LIST_ITEM definition. */ +typedef struct xSTATIC_LIST +{ + #if ( configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES == 1 ) + TickType_t xDummy1; + #endif + UBaseType_t uxDummy2; + void * pvDummy3; + StaticMiniListItem_t xDummy4; + #if ( configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES == 1 ) + TickType_t xDummy5; + #endif +} StaticList_t; + +/* + * In line with software engineering best practice, especially when supplying a + * library that is likely to change in future versions, FreeRTOS implements a + * strict data hiding policy. This means the Task structure used internally by + * FreeRTOS is not accessible to application code. However, if the application + * writer wants to statically allocate the memory required to create a task then + * the size of the task object needs to be know. The StaticTask_t structure + * below is provided for this purpose. Its sizes and alignment requirements are + * guaranteed to match those of the genuine structure, no matter which + * architecture is being used, and no matter how the values in FreeRTOSConfig.h + * are set. Its contents are somewhat obfuscated in the hope users will + * recognise that it would be unwise to make direct use of the structure members. + */ +typedef struct xSTATIC_TCB +{ + void * pxDummy1; + #if ( portUSING_MPU_WRAPPERS == 1 ) + xMPU_SETTINGS xDummy2; + #endif + StaticListItem_t xDummy3[ 2 ]; + UBaseType_t uxDummy5; + void * pxDummy6; + uint8_t ucDummy7[ configMAX_TASK_NAME_LEN ]; + #if ( ( portSTACK_GROWTH > 0 ) || ( configRECORD_STACK_HIGH_ADDRESS == 1 ) ) + void * pxDummy8; + #endif + #if ( portCRITICAL_NESTING_IN_TCB == 1 ) + UBaseType_t uxDummy9; + #endif + #if ( configUSE_TRACE_FACILITY == 1 ) + UBaseType_t uxDummy10[ 2 ]; + #endif + #if ( configUSE_MUTEXES == 1 ) + UBaseType_t uxDummy12[ 2 ]; + #endif + #if ( configUSE_APPLICATION_TASK_TAG == 1 ) + void * pxDummy14; + #endif + #if ( configNUM_THREAD_LOCAL_STORAGE_POINTERS > 0 ) + void * pvDummy15[ configNUM_THREAD_LOCAL_STORAGE_POINTERS ]; + #endif + #if ( configGENERATE_RUN_TIME_STATS == 1 ) + uint32_t ulDummy16; + #endif + #if ( configUSE_NEWLIB_REENTRANT == 1 ) + struct _reent xDummy17; + #endif + #if ( configUSE_TASK_NOTIFICATIONS == 1 ) + uint32_t ulDummy18[ configTASK_NOTIFICATION_ARRAY_ENTRIES ]; + uint8_t ucDummy19[ configTASK_NOTIFICATION_ARRAY_ENTRIES ]; + #endif + #if ( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 ) + uint8_t uxDummy20; + #endif + + #if ( INCLUDE_xTaskAbortDelay == 1 ) + uint8_t ucDummy21; + #endif + #if ( configUSE_POSIX_ERRNO == 1 ) + int iDummy22; + #endif +} StaticTask_t; + +/* + * In line with software engineering best practice, especially when supplying a + * library that is likely to change in future versions, FreeRTOS implements a + * strict data hiding policy. This means the Queue structure used internally by + * FreeRTOS is not accessible to application code. However, if the application + * writer wants to statically allocate the memory required to create a queue + * then the size of the queue object needs to be know. The StaticQueue_t + * structure below is provided for this purpose. Its sizes and alignment + * requirements are guaranteed to match those of the genuine structure, no + * matter which architecture is being used, and no matter how the values in + * FreeRTOSConfig.h are set. Its contents are somewhat obfuscated in the hope + * users will recognise that it would be unwise to make direct use of the + * structure members. + */ +typedef struct xSTATIC_QUEUE +{ + void * pvDummy1[ 3 ]; + + union + { + void * pvDummy2; + UBaseType_t uxDummy2; + } u; + + StaticList_t xDummy3[ 2 ]; + UBaseType_t uxDummy4[ 3 ]; + uint8_t ucDummy5[ 2 ]; + + #if ( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) + uint8_t ucDummy6; + #endif + + #if ( configUSE_QUEUE_SETS == 1 ) + void * pvDummy7; + #endif + + #if ( configUSE_TRACE_FACILITY == 1 ) + UBaseType_t uxDummy8; + uint8_t ucDummy9; + #endif +} StaticQueue_t; +typedef StaticQueue_t StaticSemaphore_t; + +/* + * In line with software engineering best practice, especially when supplying a + * library that is likely to change in future versions, FreeRTOS implements a + * strict data hiding policy. This means the event group structure used + * internally by FreeRTOS is not accessible to application code. However, if + * the application writer wants to statically allocate the memory required to + * create an event group then the size of the event group object needs to be + * know. The StaticEventGroup_t structure below is provided for this purpose. + * Its sizes and alignment requirements are guaranteed to match those of the + * genuine structure, no matter which architecture is being used, and no matter + * how the values in FreeRTOSConfig.h are set. Its contents are somewhat + * obfuscated in the hope users will recognise that it would be unwise to make + * direct use of the structure members. + */ +typedef struct xSTATIC_EVENT_GROUP +{ + TickType_t xDummy1; + StaticList_t xDummy2; + + #if ( configUSE_TRACE_FACILITY == 1 ) + UBaseType_t uxDummy3; + #endif + + #if ( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) + uint8_t ucDummy4; + #endif +} StaticEventGroup_t; + +/* + * In line with software engineering best practice, especially when supplying a + * library that is likely to change in future versions, FreeRTOS implements a + * strict data hiding policy. This means the software timer structure used + * internally by FreeRTOS is not accessible to application code. However, if + * the application writer wants to statically allocate the memory required to + * create a software timer then the size of the queue object needs to be know. + * The StaticTimer_t structure below is provided for this purpose. Its sizes + * and alignment requirements are guaranteed to match those of the genuine + * structure, no matter which architecture is being used, and no matter how the + * values in FreeRTOSConfig.h are set. Its contents are somewhat obfuscated in + * the hope users will recognise that it would be unwise to make direct use of + * the structure members. + */ +typedef struct xSTATIC_TIMER +{ + void * pvDummy1; + StaticListItem_t xDummy2; + TickType_t xDummy3; + void * pvDummy5; + TaskFunction_t pvDummy6; + #if ( configUSE_TRACE_FACILITY == 1 ) + UBaseType_t uxDummy7; + #endif + uint8_t ucDummy8; +} StaticTimer_t; + +/* + * In line with software engineering best practice, especially when supplying a + * library that is likely to change in future versions, FreeRTOS implements a + * strict data hiding policy. This means the stream buffer structure used + * internally by FreeRTOS is not accessible to application code. However, if + * the application writer wants to statically allocate the memory required to + * create a stream buffer then the size of the stream buffer object needs to be + * know. The StaticStreamBuffer_t structure below is provided for this purpose. + * Its size and alignment requirements are guaranteed to match those of the + * genuine structure, no matter which architecture is being used, and no matter + * how the values in FreeRTOSConfig.h are set. Its contents are somewhat + * obfuscated in the hope users will recognise that it would be unwise to make + * direct use of the structure members. + */ +typedef struct xSTATIC_STREAM_BUFFER +{ + size_t uxDummy1[ 4 ]; + void * pvDummy2[ 3 ]; + uint8_t ucDummy3; + #if ( configUSE_TRACE_FACILITY == 1 ) + UBaseType_t uxDummy4; + #endif +} StaticStreamBuffer_t; + +/* Message buffers are built on stream buffers. */ +typedef StaticStreamBuffer_t StaticMessageBuffer_t; + +/* *INDENT-OFF* */ +#ifdef __cplusplus + } +#endif +/* *INDENT-ON* */ + +#endif /* INC_FREERTOS_H */ diff --git a/RTOS/FreeRTOS/Source/include/StackMacros.h b/RTOS/FreeRTOS/Source/include/StackMacros.h new file mode 100644 index 0000000..4652f30 --- /dev/null +++ b/RTOS/FreeRTOS/Source/include/StackMacros.h @@ -0,0 +1,32 @@ +/* + * FreeRTOS Kernel V10.4.1 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * https://www.FreeRTOS.org + * https://github.com/FreeRTOS + * + */ + + +#ifndef _MSC_VER /* Visual Studio doesn't support #warning. */ + #warning The name of this file has changed to stack_macros.h. Please update your code accordingly. This source file (which has the original name) will be removed in future released. +#endif + +#include "stack_macros.h" diff --git a/RTOS/FreeRTOS/Source/include/atomic.h b/RTOS/FreeRTOS/Source/include/atomic.h new file mode 100644 index 0000000..f0c42a3 --- /dev/null +++ b/RTOS/FreeRTOS/Source/include/atomic.h @@ -0,0 +1,417 @@ +/* + * FreeRTOS Kernel V10.4.1 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * https://www.FreeRTOS.org + * https://github.com/FreeRTOS + * + */ + +/** + * @file atomic.h + * @brief FreeRTOS atomic operation support. + * + * This file implements atomic functions by disabling interrupts globally. + * Implementations with architecture specific atomic instructions can be + * provided under each compiler directory. + */ + +#ifndef ATOMIC_H +#define ATOMIC_H + +#ifndef INC_FREERTOS_H + #error "include FreeRTOS.h must appear in source files before include atomic.h" +#endif + +/* Standard includes. */ +#include + +/* *INDENT-OFF* */ +#ifdef __cplusplus + extern "C" { +#endif +/* *INDENT-ON* */ + +/* + * Port specific definitions -- entering/exiting critical section. + * Refer template -- ./lib/FreeRTOS/portable/Compiler/Arch/portmacro.h + * + * Every call to ATOMIC_EXIT_CRITICAL() must be closely paired with + * ATOMIC_ENTER_CRITICAL(). + * + */ +#if defined( portSET_INTERRUPT_MASK_FROM_ISR ) + +/* Nested interrupt scheme is supported in this port. */ + #define ATOMIC_ENTER_CRITICAL() \ + UBaseType_t uxCriticalSectionType = portSET_INTERRUPT_MASK_FROM_ISR() + + #define ATOMIC_EXIT_CRITICAL() \ + portCLEAR_INTERRUPT_MASK_FROM_ISR( uxCriticalSectionType ) + +#else + +/* Nested interrupt scheme is NOT supported in this port. */ + #define ATOMIC_ENTER_CRITICAL() portENTER_CRITICAL() + #define ATOMIC_EXIT_CRITICAL() portEXIT_CRITICAL() + +#endif /* portSET_INTERRUPT_MASK_FROM_ISR() */ + +/* + * Port specific definition -- "always inline". + * Inline is compiler specific, and may not always get inlined depending on your + * optimization level. Also, inline is considered as performance optimization + * for atomic. Thus, if portFORCE_INLINE is not provided by portmacro.h, + * instead of resulting error, simply define it away. + */ +#ifndef portFORCE_INLINE + #define portFORCE_INLINE +#endif + +#define ATOMIC_COMPARE_AND_SWAP_SUCCESS 0x1U /**< Compare and swap succeeded, swapped. */ +#define ATOMIC_COMPARE_AND_SWAP_FAILURE 0x0U /**< Compare and swap failed, did not swap. */ + +/*----------------------------- Swap && CAS ------------------------------*/ + +/** + * Atomic compare-and-swap + * + * @brief Performs an atomic compare-and-swap operation on the specified values. + * + * @param[in, out] pulDestination Pointer to memory location from where value is + * to be loaded and checked. + * @param[in] ulExchange If condition meets, write this value to memory. + * @param[in] ulComparand Swap condition. + * + * @return Unsigned integer of value 1 or 0. 1 for swapped, 0 for not swapped. + * + * @note This function only swaps *pulDestination with ulExchange, if previous + * *pulDestination value equals ulComparand. + */ +static portFORCE_INLINE uint32_t Atomic_CompareAndSwap_u32( uint32_t volatile * pulDestination, + uint32_t ulExchange, + uint32_t ulComparand ) +{ + uint32_t ulReturnValue; + + ATOMIC_ENTER_CRITICAL(); + { + if( *pulDestination == ulComparand ) + { + *pulDestination = ulExchange; + ulReturnValue = ATOMIC_COMPARE_AND_SWAP_SUCCESS; + } + else + { + ulReturnValue = ATOMIC_COMPARE_AND_SWAP_FAILURE; + } + } + ATOMIC_EXIT_CRITICAL(); + + return ulReturnValue; +} +/*-----------------------------------------------------------*/ + +/** + * Atomic swap (pointers) + * + * @brief Atomically sets the address pointed to by *ppvDestination to the value + * of *pvExchange. + * + * @param[in, out] ppvDestination Pointer to memory location from where a pointer + * value is to be loaded and written back to. + * @param[in] pvExchange Pointer value to be written to *ppvDestination. + * + * @return The initial value of *ppvDestination. + */ +static portFORCE_INLINE void * Atomic_SwapPointers_p32( void * volatile * ppvDestination, + void * pvExchange ) +{ + void * pReturnValue; + + ATOMIC_ENTER_CRITICAL(); + { + pReturnValue = *ppvDestination; + *ppvDestination = pvExchange; + } + ATOMIC_EXIT_CRITICAL(); + + return pReturnValue; +} +/*-----------------------------------------------------------*/ + +/** + * Atomic compare-and-swap (pointers) + * + * @brief Performs an atomic compare-and-swap operation on the specified pointer + * values. + * + * @param[in, out] ppvDestination Pointer to memory location from where a pointer + * value is to be loaded and checked. + * @param[in] pvExchange If condition meets, write this value to memory. + * @param[in] pvComparand Swap condition. + * + * @return Unsigned integer of value 1 or 0. 1 for swapped, 0 for not swapped. + * + * @note This function only swaps *ppvDestination with pvExchange, if previous + * *ppvDestination value equals pvComparand. + */ +static portFORCE_INLINE uint32_t Atomic_CompareAndSwapPointers_p32( void * volatile * ppvDestination, + void * pvExchange, + void * pvComparand ) +{ + uint32_t ulReturnValue = ATOMIC_COMPARE_AND_SWAP_FAILURE; + + ATOMIC_ENTER_CRITICAL(); + { + if( *ppvDestination == pvComparand ) + { + *ppvDestination = pvExchange; + ulReturnValue = ATOMIC_COMPARE_AND_SWAP_SUCCESS; + } + } + ATOMIC_EXIT_CRITICAL(); + + return ulReturnValue; +} + + +/*----------------------------- Arithmetic ------------------------------*/ + +/** + * Atomic add + * + * @brief Atomically adds count to the value of the specified pointer points to. + * + * @param[in,out] pulAddend Pointer to memory location from where value is to be + * loaded and written back to. + * @param[in] ulCount Value to be added to *pulAddend. + * + * @return previous *pulAddend value. + */ +static portFORCE_INLINE uint32_t Atomic_Add_u32( uint32_t volatile * pulAddend, + uint32_t ulCount ) +{ + uint32_t ulCurrent; + + ATOMIC_ENTER_CRITICAL(); + { + ulCurrent = *pulAddend; + *pulAddend += ulCount; + } + ATOMIC_EXIT_CRITICAL(); + + return ulCurrent; +} +/*-----------------------------------------------------------*/ + +/** + * Atomic subtract + * + * @brief Atomically subtracts count from the value of the specified pointer + * pointers to. + * + * @param[in,out] pulAddend Pointer to memory location from where value is to be + * loaded and written back to. + * @param[in] ulCount Value to be subtract from *pulAddend. + * + * @return previous *pulAddend value. + */ +static portFORCE_INLINE uint32_t Atomic_Subtract_u32( uint32_t volatile * pulAddend, + uint32_t ulCount ) +{ + uint32_t ulCurrent; + + ATOMIC_ENTER_CRITICAL(); + { + ulCurrent = *pulAddend; + *pulAddend -= ulCount; + } + ATOMIC_EXIT_CRITICAL(); + + return ulCurrent; +} +/*-----------------------------------------------------------*/ + +/** + * Atomic increment + * + * @brief Atomically increments the value of the specified pointer points to. + * + * @param[in,out] pulAddend Pointer to memory location from where value is to be + * loaded and written back to. + * + * @return *pulAddend value before increment. + */ +static portFORCE_INLINE uint32_t Atomic_Increment_u32( uint32_t volatile * pulAddend ) +{ + uint32_t ulCurrent; + + ATOMIC_ENTER_CRITICAL(); + { + ulCurrent = *pulAddend; + *pulAddend += 1; + } + ATOMIC_EXIT_CRITICAL(); + + return ulCurrent; +} +/*-----------------------------------------------------------*/ + +/** + * Atomic decrement + * + * @brief Atomically decrements the value of the specified pointer points to + * + * @param[in,out] pulAddend Pointer to memory location from where value is to be + * loaded and written back to. + * + * @return *pulAddend value before decrement. + */ +static portFORCE_INLINE uint32_t Atomic_Decrement_u32( uint32_t volatile * pulAddend ) +{ + uint32_t ulCurrent; + + ATOMIC_ENTER_CRITICAL(); + { + ulCurrent = *pulAddend; + *pulAddend -= 1; + } + ATOMIC_EXIT_CRITICAL(); + + return ulCurrent; +} + +/*----------------------------- Bitwise Logical ------------------------------*/ + +/** + * Atomic OR + * + * @brief Performs an atomic OR operation on the specified values. + * + * @param [in, out] pulDestination Pointer to memory location from where value is + * to be loaded and written back to. + * @param [in] ulValue Value to be ORed with *pulDestination. + * + * @return The original value of *pulDestination. + */ +static portFORCE_INLINE uint32_t Atomic_OR_u32( uint32_t volatile * pulDestination, + uint32_t ulValue ) +{ + uint32_t ulCurrent; + + ATOMIC_ENTER_CRITICAL(); + { + ulCurrent = *pulDestination; + *pulDestination |= ulValue; + } + ATOMIC_EXIT_CRITICAL(); + + return ulCurrent; +} +/*-----------------------------------------------------------*/ + +/** + * Atomic AND + * + * @brief Performs an atomic AND operation on the specified values. + * + * @param [in, out] pulDestination Pointer to memory location from where value is + * to be loaded and written back to. + * @param [in] ulValue Value to be ANDed with *pulDestination. + * + * @return The original value of *pulDestination. + */ +static portFORCE_INLINE uint32_t Atomic_AND_u32( uint32_t volatile * pulDestination, + uint32_t ulValue ) +{ + uint32_t ulCurrent; + + ATOMIC_ENTER_CRITICAL(); + { + ulCurrent = *pulDestination; + *pulDestination &= ulValue; + } + ATOMIC_EXIT_CRITICAL(); + + return ulCurrent; +} +/*-----------------------------------------------------------*/ + +/** + * Atomic NAND + * + * @brief Performs an atomic NAND operation on the specified values. + * + * @param [in, out] pulDestination Pointer to memory location from where value is + * to be loaded and written back to. + * @param [in] ulValue Value to be NANDed with *pulDestination. + * + * @return The original value of *pulDestination. + */ +static portFORCE_INLINE uint32_t Atomic_NAND_u32( uint32_t volatile * pulDestination, + uint32_t ulValue ) +{ + uint32_t ulCurrent; + + ATOMIC_ENTER_CRITICAL(); + { + ulCurrent = *pulDestination; + *pulDestination = ~( ulCurrent & ulValue ); + } + ATOMIC_EXIT_CRITICAL(); + + return ulCurrent; +} +/*-----------------------------------------------------------*/ + +/** + * Atomic XOR + * + * @brief Performs an atomic XOR operation on the specified values. + * + * @param [in, out] pulDestination Pointer to memory location from where value is + * to be loaded and written back to. + * @param [in] ulValue Value to be XORed with *pulDestination. + * + * @return The original value of *pulDestination. + */ +static portFORCE_INLINE uint32_t Atomic_XOR_u32( uint32_t volatile * pulDestination, + uint32_t ulValue ) +{ + uint32_t ulCurrent; + + ATOMIC_ENTER_CRITICAL(); + { + ulCurrent = *pulDestination; + *pulDestination ^= ulValue; + } + ATOMIC_EXIT_CRITICAL(); + + return ulCurrent; +} + +/* *INDENT-OFF* */ +#ifdef __cplusplus + } +#endif +/* *INDENT-ON* */ + +#endif /* ATOMIC_H */ diff --git a/RTOS/FreeRTOS/Source/include/croutine.h b/RTOS/FreeRTOS/Source/include/croutine.h new file mode 100644 index 0000000..438d0fd --- /dev/null +++ b/RTOS/FreeRTOS/Source/include/croutine.h @@ -0,0 +1,751 @@ +/* + * FreeRTOS Kernel V10.4.1 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * https://www.FreeRTOS.org + * https://github.com/FreeRTOS + * + */ + +#ifndef CO_ROUTINE_H +#define CO_ROUTINE_H + +#ifndef INC_FREERTOS_H + #error "include FreeRTOS.h must appear in source files before include croutine.h" +#endif + +#include "list.h" + +/* *INDENT-OFF* */ +#ifdef __cplusplus + extern "C" { +#endif +/* *INDENT-ON* */ + +/* Used to hide the implementation of the co-routine control block. The + * control block structure however has to be included in the header due to + * the macro implementation of the co-routine functionality. */ +typedef void * CoRoutineHandle_t; + +/* Defines the prototype to which co-routine functions must conform. */ +typedef void (* crCOROUTINE_CODE)( CoRoutineHandle_t, + UBaseType_t ); + +typedef struct corCoRoutineControlBlock +{ + crCOROUTINE_CODE pxCoRoutineFunction; + ListItem_t xGenericListItem; /*< List item used to place the CRCB in ready and blocked queues. */ + ListItem_t xEventListItem; /*< List item used to place the CRCB in event lists. */ + UBaseType_t uxPriority; /*< The priority of the co-routine in relation to other co-routines. */ + UBaseType_t uxIndex; /*< Used to distinguish between co-routines when multiple co-routines use the same co-routine function. */ + uint16_t uxState; /*< Used internally by the co-routine implementation. */ +} CRCB_t; /* Co-routine control block. Note must be identical in size down to uxPriority with TCB_t. */ + +/** + * croutine. h + *
+ * BaseType_t xCoRoutineCreate(
+ *                               crCOROUTINE_CODE pxCoRoutineCode,
+ *                               UBaseType_t uxPriority,
+ *                               UBaseType_t uxIndex
+ *                             ); 
+ * 
+ * + * Create a new co-routine and add it to the list of co-routines that are + * ready to run. + * + * @param pxCoRoutineCode Pointer to the co-routine function. Co-routine + * functions require special syntax - see the co-routine section of the WEB + * documentation for more information. + * + * @param uxPriority The priority with respect to other co-routines at which + * the co-routine will run. + * + * @param uxIndex Used to distinguish between different co-routines that + * execute the same function. See the example below and the co-routine section + * of the WEB documentation for further information. + * + * @return pdPASS if the co-routine was successfully created and added to a ready + * list, otherwise an error code defined with ProjDefs.h. + * + * Example usage: + *
+ * // Co-routine to be created.
+ * void vFlashCoRoutine( CoRoutineHandle_t xHandle, UBaseType_t uxIndex )
+ * {
+ * // Variables in co-routines must be declared static if they must maintain value across a blocking call.
+ * // This may not be necessary for const variables.
+ * static const char cLedToFlash[ 2 ] = { 5, 6 };
+ * static const TickType_t uxFlashRates[ 2 ] = { 200, 400 };
+ *
+ *   // Must start every co-routine with a call to crSTART();
+ *   crSTART( xHandle );
+ *
+ *   for( ;; )
+ *   {
+ *       // This co-routine just delays for a fixed period, then toggles
+ *       // an LED.  Two co-routines are created using this function, so
+ *       // the uxIndex parameter is used to tell the co-routine which
+ *       // LED to flash and how int32_t to delay.  This assumes xQueue has
+ *       // already been created.
+ *       vParTestToggleLED( cLedToFlash[ uxIndex ] );
+ *       crDELAY( xHandle, uxFlashRates[ uxIndex ] );
+ *   }
+ *
+ *   // Must end every co-routine with a call to crEND();
+ *   crEND();
+ * }
+ *
+ * // Function that creates two co-routines.
+ * void vOtherFunction( void )
+ * {
+ * uint8_t ucParameterToPass;
+ * TaskHandle_t xHandle;
+ *
+ *   // Create two co-routines at priority 0.  The first is given index 0
+ *   // so (from the code above) toggles LED 5 every 200 ticks.  The second
+ *   // is given index 1 so toggles LED 6 every 400 ticks.
+ *   for( uxIndex = 0; uxIndex < 2; uxIndex++ )
+ *   {
+ *       xCoRoutineCreate( vFlashCoRoutine, 0, uxIndex );
+ *   }
+ * }
+ * 
+ * \defgroup xCoRoutineCreate xCoRoutineCreate + * \ingroup Tasks + */ +BaseType_t xCoRoutineCreate( crCOROUTINE_CODE pxCoRoutineCode, + UBaseType_t uxPriority, + UBaseType_t uxIndex ); + + +/** + * croutine. h + *
+ * void vCoRoutineSchedule( void );
+ * 
+ * + * Run a co-routine. + * + * vCoRoutineSchedule() executes the highest priority co-routine that is able + * to run. The co-routine will execute until it either blocks, yields or is + * preempted by a task. Co-routines execute cooperatively so one + * co-routine cannot be preempted by another, but can be preempted by a task. + * + * If an application comprises of both tasks and co-routines then + * vCoRoutineSchedule should be called from the idle task (in an idle task + * hook). + * + * Example usage: + *
+ * // This idle task hook will schedule a co-routine each time it is called.
+ * // The rest of the idle task will execute between co-routine calls.
+ * void vApplicationIdleHook( void )
+ * {
+ *  vCoRoutineSchedule();
+ * }
+ *
+ * // Alternatively, if you do not require any other part of the idle task to
+ * // execute, the idle task hook can call vCoRoutineSchedule() within an
+ * // infinite loop.
+ * void vApplicationIdleHook( void )
+ * {
+ *  for( ;; )
+ *  {
+ *      vCoRoutineSchedule();
+ *  }
+ * }
+ * 
+ * \defgroup vCoRoutineSchedule vCoRoutineSchedule + * \ingroup Tasks + */ +void vCoRoutineSchedule( void ); + +/** + * croutine. h + *
+ * crSTART( CoRoutineHandle_t xHandle );
+ * 
+ * + * This macro MUST always be called at the start of a co-routine function. + * + * Example usage: + *
+ * // Co-routine to be created.
+ * void vACoRoutine( CoRoutineHandle_t xHandle, UBaseType_t uxIndex )
+ * {
+ * // Variables in co-routines must be declared static if they must maintain value across a blocking call.
+ * static int32_t ulAVariable;
+ *
+ *   // Must start every co-routine with a call to crSTART();
+ *   crSTART( xHandle );
+ *
+ *   for( ;; )
+ *   {
+ *        // Co-routine functionality goes here.
+ *   }
+ *
+ *   // Must end every co-routine with a call to crEND();
+ *   crEND();
+ * }
+ * 
+ * \defgroup crSTART crSTART + * \ingroup Tasks + */ +#define crSTART( pxCRCB ) \ + switch( ( ( CRCB_t * ) ( pxCRCB ) )->uxState ) { \ + case 0: + +/** + * croutine. h + *
+ * crEND();
+ * 
+ * + * This macro MUST always be called at the end of a co-routine function. + * + * Example usage: + *
+ * // Co-routine to be created.
+ * void vACoRoutine( CoRoutineHandle_t xHandle, UBaseType_t uxIndex )
+ * {
+ * // Variables in co-routines must be declared static if they must maintain value across a blocking call.
+ * static int32_t ulAVariable;
+ *
+ *   // Must start every co-routine with a call to crSTART();
+ *   crSTART( xHandle );
+ *
+ *   for( ;; )
+ *   {
+ *        // Co-routine functionality goes here.
+ *   }
+ *
+ *   // Must end every co-routine with a call to crEND();
+ *   crEND();
+ * }
+ * 
+ * \defgroup crSTART crSTART + * \ingroup Tasks + */ +#define crEND() } + +/* + * These macros are intended for internal use by the co-routine implementation + * only. The macros should not be used directly by application writers. + */ +#define crSET_STATE0( xHandle ) \ + ( ( CRCB_t * ) ( xHandle ) )->uxState = ( __LINE__ * 2 ); return; \ + case ( __LINE__ * 2 ): +#define crSET_STATE1( xHandle ) \ + ( ( CRCB_t * ) ( xHandle ) )->uxState = ( ( __LINE__ * 2 ) + 1 ); return; \ + case ( ( __LINE__ * 2 ) + 1 ): + +/** + * croutine. h + *
+ * crDELAY( CoRoutineHandle_t xHandle, TickType_t xTicksToDelay );
+ * 
+ * + * Delay a co-routine for a fixed period of time. + * + * crDELAY can only be called from the co-routine function itself - not + * from within a function called by the co-routine function. This is because + * co-routines do not maintain their own stack. + * + * @param xHandle The handle of the co-routine to delay. This is the xHandle + * parameter of the co-routine function. + * + * @param xTickToDelay The number of ticks that the co-routine should delay + * for. The actual amount of time this equates to is defined by + * configTICK_RATE_HZ (set in FreeRTOSConfig.h). The constant portTICK_PERIOD_MS + * can be used to convert ticks to milliseconds. + * + * Example usage: + *
+ * // Co-routine to be created.
+ * void vACoRoutine( CoRoutineHandle_t xHandle, UBaseType_t uxIndex )
+ * {
+ * // Variables in co-routines must be declared static if they must maintain value across a blocking call.
+ * // This may not be necessary for const variables.
+ * // We are to delay for 200ms.
+ * static const xTickType xDelayTime = 200 / portTICK_PERIOD_MS;
+ *
+ *   // Must start every co-routine with a call to crSTART();
+ *   crSTART( xHandle );
+ *
+ *   for( ;; )
+ *   {
+ *      // Delay for 200ms.
+ *      crDELAY( xHandle, xDelayTime );
+ *
+ *      // Do something here.
+ *   }
+ *
+ *   // Must end every co-routine with a call to crEND();
+ *   crEND();
+ * }
+ * 
+ * \defgroup crDELAY crDELAY + * \ingroup Tasks + */ +#define crDELAY( xHandle, xTicksToDelay ) \ + if( ( xTicksToDelay ) > 0 ) \ + { \ + vCoRoutineAddToDelayedList( ( xTicksToDelay ), NULL ); \ + } \ + crSET_STATE0( ( xHandle ) ); + +/** + *
+ * crQUEUE_SEND(
+ *                CoRoutineHandle_t xHandle,
+ *                QueueHandle_t pxQueue,
+ *                void *pvItemToQueue,
+ *                TickType_t xTicksToWait,
+ *                BaseType_t *pxResult
+ *           )
+ * 
+ * + * The macro's crQUEUE_SEND() and crQUEUE_RECEIVE() are the co-routine + * equivalent to the xQueueSend() and xQueueReceive() functions used by tasks. + * + * crQUEUE_SEND and crQUEUE_RECEIVE can only be used from a co-routine whereas + * xQueueSend() and xQueueReceive() can only be used from tasks. + * + * crQUEUE_SEND can only be called from the co-routine function itself - not + * from within a function called by the co-routine function. This is because + * co-routines do not maintain their own stack. + * + * See the co-routine section of the WEB documentation for information on + * passing data between tasks and co-routines and between ISR's and + * co-routines. + * + * @param xHandle The handle of the calling co-routine. This is the xHandle + * parameter of the co-routine function. + * + * @param pxQueue The handle of the queue on which the data will be posted. + * The handle is obtained as the return value when the queue is created using + * the xQueueCreate() API function. + * + * @param pvItemToQueue A pointer to the data being posted onto the queue. + * The number of bytes of each queued item is specified when the queue is + * created. This number of bytes is copied from pvItemToQueue into the queue + * itself. + * + * @param xTickToDelay The number of ticks that the co-routine should block + * to wait for space to become available on the queue, should space not be + * available immediately. The actual amount of time this equates to is defined + * by configTICK_RATE_HZ (set in FreeRTOSConfig.h). The constant + * portTICK_PERIOD_MS can be used to convert ticks to milliseconds (see example + * below). + * + * @param pxResult The variable pointed to by pxResult will be set to pdPASS if + * data was successfully posted onto the queue, otherwise it will be set to an + * error defined within ProjDefs.h. + * + * Example usage: + *
+ * // Co-routine function that blocks for a fixed period then posts a number onto
+ * // a queue.
+ * static void prvCoRoutineFlashTask( CoRoutineHandle_t xHandle, UBaseType_t uxIndex )
+ * {
+ * // Variables in co-routines must be declared static if they must maintain value across a blocking call.
+ * static BaseType_t xNumberToPost = 0;
+ * static BaseType_t xResult;
+ *
+ *  // Co-routines must begin with a call to crSTART().
+ *  crSTART( xHandle );
+ *
+ *  for( ;; )
+ *  {
+ *      // This assumes the queue has already been created.
+ *      crQUEUE_SEND( xHandle, xCoRoutineQueue, &xNumberToPost, NO_DELAY, &xResult );
+ *
+ *      if( xResult != pdPASS )
+ *      {
+ *          // The message was not posted!
+ *      }
+ *
+ *      // Increment the number to be posted onto the queue.
+ *      xNumberToPost++;
+ *
+ *      // Delay for 100 ticks.
+ *      crDELAY( xHandle, 100 );
+ *  }
+ *
+ *  // Co-routines must end with a call to crEND().
+ *  crEND();
+ * }
+ * 
+ * \defgroup crQUEUE_SEND crQUEUE_SEND + * \ingroup Tasks + */ +#define crQUEUE_SEND( xHandle, pxQueue, pvItemToQueue, xTicksToWait, pxResult ) \ + { \ + *( pxResult ) = xQueueCRSend( ( pxQueue ), ( pvItemToQueue ), ( xTicksToWait ) ); \ + if( *( pxResult ) == errQUEUE_BLOCKED ) \ + { \ + crSET_STATE0( ( xHandle ) ); \ + *pxResult = xQueueCRSend( ( pxQueue ), ( pvItemToQueue ), 0 ); \ + } \ + if( *pxResult == errQUEUE_YIELD ) \ + { \ + crSET_STATE1( ( xHandle ) ); \ + *pxResult = pdPASS; \ + } \ + } + +/** + * croutine. h + *
+ * crQUEUE_RECEIVE(
+ *                   CoRoutineHandle_t xHandle,
+ *                   QueueHandle_t pxQueue,
+ *                   void *pvBuffer,
+ *                   TickType_t xTicksToWait,
+ *                   BaseType_t *pxResult
+ *               )
+ * 
+ * + * The macro's crQUEUE_SEND() and crQUEUE_RECEIVE() are the co-routine + * equivalent to the xQueueSend() and xQueueReceive() functions used by tasks. + * + * crQUEUE_SEND and crQUEUE_RECEIVE can only be used from a co-routine whereas + * xQueueSend() and xQueueReceive() can only be used from tasks. + * + * crQUEUE_RECEIVE can only be called from the co-routine function itself - not + * from within a function called by the co-routine function. This is because + * co-routines do not maintain their own stack. + * + * See the co-routine section of the WEB documentation for information on + * passing data between tasks and co-routines and between ISR's and + * co-routines. + * + * @param xHandle The handle of the calling co-routine. This is the xHandle + * parameter of the co-routine function. + * + * @param pxQueue The handle of the queue from which the data will be received. + * The handle is obtained as the return value when the queue is created using + * the xQueueCreate() API function. + * + * @param pvBuffer The buffer into which the received item is to be copied. + * The number of bytes of each queued item is specified when the queue is + * created. This number of bytes is copied into pvBuffer. + * + * @param xTickToDelay The number of ticks that the co-routine should block + * to wait for data to become available from the queue, should data not be + * available immediately. The actual amount of time this equates to is defined + * by configTICK_RATE_HZ (set in FreeRTOSConfig.h). The constant + * portTICK_PERIOD_MS can be used to convert ticks to milliseconds (see the + * crQUEUE_SEND example). + * + * @param pxResult The variable pointed to by pxResult will be set to pdPASS if + * data was successfully retrieved from the queue, otherwise it will be set to + * an error code as defined within ProjDefs.h. + * + * Example usage: + *
+ * // A co-routine receives the number of an LED to flash from a queue.  It
+ * // blocks on the queue until the number is received.
+ * static void prvCoRoutineFlashWorkTask( CoRoutineHandle_t xHandle, UBaseType_t uxIndex )
+ * {
+ * // Variables in co-routines must be declared static if they must maintain value across a blocking call.
+ * static BaseType_t xResult;
+ * static UBaseType_t uxLEDToFlash;
+ *
+ *  // All co-routines must start with a call to crSTART().
+ *  crSTART( xHandle );
+ *
+ *  for( ;; )
+ *  {
+ *      // Wait for data to become available on the queue.
+ *      crQUEUE_RECEIVE( xHandle, xCoRoutineQueue, &uxLEDToFlash, portMAX_DELAY, &xResult );
+ *
+ *      if( xResult == pdPASS )
+ *      {
+ *          // We received the LED to flash - flash it!
+ *          vParTestToggleLED( uxLEDToFlash );
+ *      }
+ *  }
+ *
+ *  crEND();
+ * }
+ * 
+ * \defgroup crQUEUE_RECEIVE crQUEUE_RECEIVE + * \ingroup Tasks + */ +#define crQUEUE_RECEIVE( xHandle, pxQueue, pvBuffer, xTicksToWait, pxResult ) \ + { \ + *( pxResult ) = xQueueCRReceive( ( pxQueue ), ( pvBuffer ), ( xTicksToWait ) ); \ + if( *( pxResult ) == errQUEUE_BLOCKED ) \ + { \ + crSET_STATE0( ( xHandle ) ); \ + *( pxResult ) = xQueueCRReceive( ( pxQueue ), ( pvBuffer ), 0 ); \ + } \ + if( *( pxResult ) == errQUEUE_YIELD ) \ + { \ + crSET_STATE1( ( xHandle ) ); \ + *( pxResult ) = pdPASS; \ + } \ + } + +/** + * croutine. h + *
+ * crQUEUE_SEND_FROM_ISR(
+ *                          QueueHandle_t pxQueue,
+ *                          void *pvItemToQueue,
+ *                          BaseType_t xCoRoutinePreviouslyWoken
+ *                     )
+ * 
+ * + * The macro's crQUEUE_SEND_FROM_ISR() and crQUEUE_RECEIVE_FROM_ISR() are the + * co-routine equivalent to the xQueueSendFromISR() and xQueueReceiveFromISR() + * functions used by tasks. + * + * crQUEUE_SEND_FROM_ISR() and crQUEUE_RECEIVE_FROM_ISR() can only be used to + * pass data between a co-routine and and ISR, whereas xQueueSendFromISR() and + * xQueueReceiveFromISR() can only be used to pass data between a task and and + * ISR. + * + * crQUEUE_SEND_FROM_ISR can only be called from an ISR to send data to a queue + * that is being used from within a co-routine. + * + * See the co-routine section of the WEB documentation for information on + * passing data between tasks and co-routines and between ISR's and + * co-routines. + * + * @param xQueue The handle to the queue on which the item is to be posted. + * + * @param pvItemToQueue A pointer to the item that is to be placed on the + * queue. The size of the items the queue will hold was defined when the + * queue was created, so this many bytes will be copied from pvItemToQueue + * into the queue storage area. + * + * @param xCoRoutinePreviouslyWoken This is included so an ISR can post onto + * the same queue multiple times from a single interrupt. The first call + * should always pass in pdFALSE. Subsequent calls should pass in + * the value returned from the previous call. + * + * @return pdTRUE if a co-routine was woken by posting onto the queue. This is + * used by the ISR to determine if a context switch may be required following + * the ISR. + * + * Example usage: + *
+ * // A co-routine that blocks on a queue waiting for characters to be received.
+ * static void vReceivingCoRoutine( CoRoutineHandle_t xHandle, UBaseType_t uxIndex )
+ * {
+ * char cRxedChar;
+ * BaseType_t xResult;
+ *
+ *   // All co-routines must start with a call to crSTART().
+ *   crSTART( xHandle );
+ *
+ *   for( ;; )
+ *   {
+ *       // Wait for data to become available on the queue.  This assumes the
+ *       // queue xCommsRxQueue has already been created!
+ *       crQUEUE_RECEIVE( xHandle, xCommsRxQueue, &uxLEDToFlash, portMAX_DELAY, &xResult );
+ *
+ *       // Was a character received?
+ *       if( xResult == pdPASS )
+ *       {
+ *           // Process the character here.
+ *       }
+ *   }
+ *
+ *   // All co-routines must end with a call to crEND().
+ *   crEND();
+ * }
+ *
+ * // An ISR that uses a queue to send characters received on a serial port to
+ * // a co-routine.
+ * void vUART_ISR( void )
+ * {
+ * char cRxedChar;
+ * BaseType_t xCRWokenByPost = pdFALSE;
+ *
+ *   // We loop around reading characters until there are none left in the UART.
+ *   while( UART_RX_REG_NOT_EMPTY() )
+ *   {
+ *       // Obtain the character from the UART.
+ *       cRxedChar = UART_RX_REG;
+ *
+ *       // Post the character onto a queue.  xCRWokenByPost will be pdFALSE
+ *       // the first time around the loop.  If the post causes a co-routine
+ *       // to be woken (unblocked) then xCRWokenByPost will be set to pdTRUE.
+ *       // In this manner we can ensure that if more than one co-routine is
+ *       // blocked on the queue only one is woken by this ISR no matter how
+ *       // many characters are posted to the queue.
+ *       xCRWokenByPost = crQUEUE_SEND_FROM_ISR( xCommsRxQueue, &cRxedChar, xCRWokenByPost );
+ *   }
+ * }
+ * 
+ * \defgroup crQUEUE_SEND_FROM_ISR crQUEUE_SEND_FROM_ISR + * \ingroup Tasks + */ +#define crQUEUE_SEND_FROM_ISR( pxQueue, pvItemToQueue, xCoRoutinePreviouslyWoken ) \ + xQueueCRSendFromISR( ( pxQueue ), ( pvItemToQueue ), ( xCoRoutinePreviouslyWoken ) ) + + +/** + * croutine. h + *
+ * crQUEUE_SEND_FROM_ISR(
+ *                          QueueHandle_t pxQueue,
+ *                          void *pvBuffer,
+ *                          BaseType_t * pxCoRoutineWoken
+ *                     )
+ * 
+ * + * The macro's crQUEUE_SEND_FROM_ISR() and crQUEUE_RECEIVE_FROM_ISR() are the + * co-routine equivalent to the xQueueSendFromISR() and xQueueReceiveFromISR() + * functions used by tasks. + * + * crQUEUE_SEND_FROM_ISR() and crQUEUE_RECEIVE_FROM_ISR() can only be used to + * pass data between a co-routine and and ISR, whereas xQueueSendFromISR() and + * xQueueReceiveFromISR() can only be used to pass data between a task and and + * ISR. + * + * crQUEUE_RECEIVE_FROM_ISR can only be called from an ISR to receive data + * from a queue that is being used from within a co-routine (a co-routine + * posted to the queue). + * + * See the co-routine section of the WEB documentation for information on + * passing data between tasks and co-routines and between ISR's and + * co-routines. + * + * @param xQueue The handle to the queue on which the item is to be posted. + * + * @param pvBuffer A pointer to a buffer into which the received item will be + * placed. The size of the items the queue will hold was defined when the + * queue was created, so this many bytes will be copied from the queue into + * pvBuffer. + * + * @param pxCoRoutineWoken A co-routine may be blocked waiting for space to become + * available on the queue. If crQUEUE_RECEIVE_FROM_ISR causes such a + * co-routine to unblock *pxCoRoutineWoken will get set to pdTRUE, otherwise + * *pxCoRoutineWoken will remain unchanged. + * + * @return pdTRUE an item was successfully received from the queue, otherwise + * pdFALSE. + * + * Example usage: + *
+ * // A co-routine that posts a character to a queue then blocks for a fixed
+ * // period.  The character is incremented each time.
+ * static void vSendingCoRoutine( CoRoutineHandle_t xHandle, UBaseType_t uxIndex )
+ * {
+ * // cChar holds its value while this co-routine is blocked and must therefore
+ * // be declared static.
+ * static char cCharToTx = 'a';
+ * BaseType_t xResult;
+ *
+ *   // All co-routines must start with a call to crSTART().
+ *   crSTART( xHandle );
+ *
+ *   for( ;; )
+ *   {
+ *       // Send the next character to the queue.
+ *       crQUEUE_SEND( xHandle, xCoRoutineQueue, &cCharToTx, NO_DELAY, &xResult );
+ *
+ *       if( xResult == pdPASS )
+ *       {
+ *           // The character was successfully posted to the queue.
+ *       }
+ *       else
+ *       {
+ *          // Could not post the character to the queue.
+ *       }
+ *
+ *       // Enable the UART Tx interrupt to cause an interrupt in this
+ *       // hypothetical UART.  The interrupt will obtain the character
+ *       // from the queue and send it.
+ *       ENABLE_RX_INTERRUPT();
+ *
+ *       // Increment to the next character then block for a fixed period.
+ *       // cCharToTx will maintain its value across the delay as it is
+ *       // declared static.
+ *       cCharToTx++;
+ *       if( cCharToTx > 'x' )
+ *       {
+ *          cCharToTx = 'a';
+ *       }
+ *       crDELAY( 100 );
+ *   }
+ *
+ *   // All co-routines must end with a call to crEND().
+ *   crEND();
+ * }
+ *
+ * // An ISR that uses a queue to receive characters to send on a UART.
+ * void vUART_ISR( void )
+ * {
+ * char cCharToTx;
+ * BaseType_t xCRWokenByPost = pdFALSE;
+ *
+ *   while( UART_TX_REG_EMPTY() )
+ *   {
+ *       // Are there any characters in the queue waiting to be sent?
+ *       // xCRWokenByPost will automatically be set to pdTRUE if a co-routine
+ *       // is woken by the post - ensuring that only a single co-routine is
+ *       // woken no matter how many times we go around this loop.
+ *       if( crQUEUE_RECEIVE_FROM_ISR( pxQueue, &cCharToTx, &xCRWokenByPost ) )
+ *       {
+ *           SEND_CHARACTER( cCharToTx );
+ *       }
+ *   }
+ * }
+ * 
+ * \defgroup crQUEUE_RECEIVE_FROM_ISR crQUEUE_RECEIVE_FROM_ISR + * \ingroup Tasks + */ +#define crQUEUE_RECEIVE_FROM_ISR( pxQueue, pvBuffer, pxCoRoutineWoken ) \ + xQueueCRReceiveFromISR( ( pxQueue ), ( pvBuffer ), ( pxCoRoutineWoken ) ) + +/* + * This function is intended for internal use by the co-routine macros only. + * The macro nature of the co-routine implementation requires that the + * prototype appears here. The function should not be used by application + * writers. + * + * Removes the current co-routine from its ready list and places it in the + * appropriate delayed list. + */ +void vCoRoutineAddToDelayedList( TickType_t xTicksToDelay, + List_t * pxEventList ); + +/* + * This function is intended for internal use by the queue implementation only. + * The function should not be used by application writers. + * + * Removes the highest priority co-routine from the event list and places it in + * the pending ready list. + */ +BaseType_t xCoRoutineRemoveFromEventList( const List_t * pxEventList ); + +/* *INDENT-OFF* */ +#ifdef __cplusplus + } +#endif +/* *INDENT-ON* */ + +#endif /* CO_ROUTINE_H */ diff --git a/RTOS/FreeRTOS/Source/include/deprecated_definitions.h b/RTOS/FreeRTOS/Source/include/deprecated_definitions.h new file mode 100644 index 0000000..24c1259 --- /dev/null +++ b/RTOS/FreeRTOS/Source/include/deprecated_definitions.h @@ -0,0 +1,279 @@ +/* + * FreeRTOS Kernel V10.4.1 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * https://www.FreeRTOS.org + * https://github.com/FreeRTOS + * + */ + +#ifndef DEPRECATED_DEFINITIONS_H +#define DEPRECATED_DEFINITIONS_H + + +/* Each FreeRTOS port has a unique portmacro.h header file. Originally a + * pre-processor definition was used to ensure the pre-processor found the correct + * portmacro.h file for the port being used. That scheme was deprecated in favour + * of setting the compiler's include path such that it found the correct + * portmacro.h file - removing the need for the constant and allowing the + * portmacro.h file to be located anywhere in relation to the port being used. The + * definitions below remain in the code for backward compatibility only. New + * projects should not use them. */ + +#ifdef OPEN_WATCOM_INDUSTRIAL_PC_PORT + #include "..\..\Source\portable\owatcom\16bitdos\pc\portmacro.h" + typedef void ( __interrupt __far * pxISR )(); +#endif + +#ifdef OPEN_WATCOM_FLASH_LITE_186_PORT + #include "..\..\Source\portable\owatcom\16bitdos\flsh186\portmacro.h" + typedef void ( __interrupt __far * pxISR )(); +#endif + +#ifdef GCC_MEGA_AVR + #include "../portable/GCC/ATMega323/portmacro.h" +#endif + +#ifdef IAR_MEGA_AVR + #include "../portable/IAR/ATMega323/portmacro.h" +#endif + +#ifdef MPLAB_PIC24_PORT + #include "../../Source/portable/MPLAB/PIC24_dsPIC/portmacro.h" +#endif + +#ifdef MPLAB_DSPIC_PORT + #include "../../Source/portable/MPLAB/PIC24_dsPIC/portmacro.h" +#endif + +#ifdef MPLAB_PIC18F_PORT + #include "../../Source/portable/MPLAB/PIC18F/portmacro.h" +#endif + +#ifdef MPLAB_PIC32MX_PORT + #include "../../Source/portable/MPLAB/PIC32MX/portmacro.h" +#endif + +#ifdef _FEDPICC + #include "libFreeRTOS/Include/portmacro.h" +#endif + +#ifdef SDCC_CYGNAL + #include "../../Source/portable/SDCC/Cygnal/portmacro.h" +#endif + +#ifdef GCC_ARM7 + #include "../../Source/portable/GCC/ARM7_LPC2000/portmacro.h" +#endif + +#ifdef GCC_ARM7_ECLIPSE + #include "portmacro.h" +#endif + +#ifdef ROWLEY_LPC23xx + #include "../../Source/portable/GCC/ARM7_LPC23xx/portmacro.h" +#endif + +#ifdef IAR_MSP430 + #include "..\..\Source\portable\IAR\MSP430\portmacro.h" +#endif + +#ifdef GCC_MSP430 + #include "../../Source/portable/GCC/MSP430F449/portmacro.h" +#endif + +#ifdef ROWLEY_MSP430 + #include "../../Source/portable/Rowley/MSP430F449/portmacro.h" +#endif + +#ifdef ARM7_LPC21xx_KEIL_RVDS + #include "..\..\Source\portable\RVDS\ARM7_LPC21xx\portmacro.h" +#endif + +#ifdef SAM7_GCC + #include "../../Source/portable/GCC/ARM7_AT91SAM7S/portmacro.h" +#endif + +#ifdef SAM7_IAR + #include "..\..\Source\portable\IAR\AtmelSAM7S64\portmacro.h" +#endif + +#ifdef SAM9XE_IAR + #include "..\..\Source\portable\IAR\AtmelSAM9XE\portmacro.h" +#endif + +#ifdef LPC2000_IAR + #include "..\..\Source\portable\IAR\LPC2000\portmacro.h" +#endif + +#ifdef STR71X_IAR + #include "..\..\Source\portable\IAR\STR71x\portmacro.h" +#endif + +#ifdef STR75X_IAR + #include "..\..\Source\portable\IAR\STR75x\portmacro.h" +#endif + +#ifdef STR75X_GCC + #include "..\..\Source\portable\GCC\STR75x\portmacro.h" +#endif + +#ifdef STR91X_IAR + #include "..\..\Source\portable\IAR\STR91x\portmacro.h" +#endif + +#ifdef GCC_H8S + #include "../../Source/portable/GCC/H8S2329/portmacro.h" +#endif + +#ifdef GCC_AT91FR40008 + #include "../../Source/portable/GCC/ARM7_AT91FR40008/portmacro.h" +#endif + +#ifdef RVDS_ARMCM3_LM3S102 + #include "../../Source/portable/RVDS/ARM_CM3/portmacro.h" +#endif + +#ifdef GCC_ARMCM3_LM3S102 + #include "../../Source/portable/GCC/ARM_CM3/portmacro.h" +#endif + +#ifdef GCC_ARMCM3 + #include "../../Source/portable/GCC/ARM_CM3/portmacro.h" +#endif + +#ifdef IAR_ARM_CM3 + #include "../../Source/portable/IAR/ARM_CM3/portmacro.h" +#endif + +#ifdef IAR_ARMCM3_LM + #include "../../Source/portable/IAR/ARM_CM3/portmacro.h" +#endif + +#ifdef HCS12_CODE_WARRIOR + #include "../../Source/portable/CodeWarrior/HCS12/portmacro.h" +#endif + +#ifdef MICROBLAZE_GCC + #include "../../Source/portable/GCC/MicroBlaze/portmacro.h" +#endif + +#ifdef TERN_EE + #include "..\..\Source\portable\Paradigm\Tern_EE\small\portmacro.h" +#endif + +#ifdef GCC_HCS12 + #include "../../Source/portable/GCC/HCS12/portmacro.h" +#endif + +#ifdef GCC_MCF5235 + #include "../../Source/portable/GCC/MCF5235/portmacro.h" +#endif + +#ifdef COLDFIRE_V2_GCC + #include "../../../Source/portable/GCC/ColdFire_V2/portmacro.h" +#endif + +#ifdef COLDFIRE_V2_CODEWARRIOR + #include "../../Source/portable/CodeWarrior/ColdFire_V2/portmacro.h" +#endif + +#ifdef GCC_PPC405 + #include "../../Source/portable/GCC/PPC405_Xilinx/portmacro.h" +#endif + +#ifdef GCC_PPC440 + #include "../../Source/portable/GCC/PPC440_Xilinx/portmacro.h" +#endif + +#ifdef _16FX_SOFTUNE + #include "..\..\Source\portable\Softune\MB96340\portmacro.h" +#endif + +#ifdef BCC_INDUSTRIAL_PC_PORT + +/* A short file name has to be used in place of the normal + * FreeRTOSConfig.h when using the Borland compiler. */ + #include "frconfig.h" + #include "..\portable\BCC\16BitDOS\PC\prtmacro.h" + typedef void ( __interrupt __far * pxISR )(); +#endif + +#ifdef BCC_FLASH_LITE_186_PORT + +/* A short file name has to be used in place of the normal + * FreeRTOSConfig.h when using the Borland compiler. */ + #include "frconfig.h" + #include "..\portable\BCC\16BitDOS\flsh186\prtmacro.h" + typedef void ( __interrupt __far * pxISR )(); +#endif + +#ifdef __GNUC__ + #ifdef __AVR32_AVR32A__ + #include "portmacro.h" + #endif +#endif + +#ifdef __ICCAVR32__ + #ifdef __CORE__ + #if __CORE__ == __AVR32A__ + #include "portmacro.h" + #endif + #endif +#endif + +#ifdef __91467D + #include "portmacro.h" +#endif + +#ifdef __96340 + #include "portmacro.h" +#endif + + +#ifdef __IAR_V850ES_Fx3__ + #include "../../Source/portable/IAR/V850ES/portmacro.h" +#endif + +#ifdef __IAR_V850ES_Jx3__ + #include "../../Source/portable/IAR/V850ES/portmacro.h" +#endif + +#ifdef __IAR_V850ES_Jx3_L__ + #include "../../Source/portable/IAR/V850ES/portmacro.h" +#endif + +#ifdef __IAR_V850ES_Jx2__ + #include "../../Source/portable/IAR/V850ES/portmacro.h" +#endif + +#ifdef __IAR_V850ES_Hx2__ + #include "../../Source/portable/IAR/V850ES/portmacro.h" +#endif + +#ifdef __IAR_78K0R_Kx3__ + #include "../../Source/portable/IAR/78K0R/portmacro.h" +#endif + +#ifdef __IAR_78K0R_Kx3L__ + #include "../../Source/portable/IAR/78K0R/portmacro.h" +#endif + +#endif /* DEPRECATED_DEFINITIONS_H */ diff --git a/RTOS/FreeRTOS/Source/include/event_groups.h b/RTOS/FreeRTOS/Source/include/event_groups.h new file mode 100644 index 0000000..e03b70d --- /dev/null +++ b/RTOS/FreeRTOS/Source/include/event_groups.h @@ -0,0 +1,775 @@ +/* + * FreeRTOS Kernel V10.4.1 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * https://www.FreeRTOS.org + * https://github.com/FreeRTOS + * + */ + +#ifndef EVENT_GROUPS_H +#define EVENT_GROUPS_H + +#ifndef INC_FREERTOS_H + #error "include FreeRTOS.h" must appear in source files before "include event_groups.h" +#endif + +/* FreeRTOS includes. */ +#include "timers.h" + +/* *INDENT-OFF* */ +#ifdef __cplusplus + extern "C" { +#endif +/* *INDENT-ON* */ + +/** + * An event group is a collection of bits to which an application can assign a + * meaning. For example, an application may create an event group to convey + * the status of various CAN bus related events in which bit 0 might mean "A CAN + * message has been received and is ready for processing", bit 1 might mean "The + * application has queued a message that is ready for sending onto the CAN + * network", and bit 2 might mean "It is time to send a SYNC message onto the + * CAN network" etc. A task can then test the bit values to see which events + * are active, and optionally enter the Blocked state to wait for a specified + * bit or a group of specified bits to be active. To continue the CAN bus + * example, a CAN controlling task can enter the Blocked state (and therefore + * not consume any processing time) until either bit 0, bit 1 or bit 2 are + * active, at which time the bit that was actually active would inform the task + * which action it had to take (process a received message, send a message, or + * send a SYNC). + * + * The event groups implementation contains intelligence to avoid race + * conditions that would otherwise occur were an application to use a simple + * variable for the same purpose. This is particularly important with respect + * to when a bit within an event group is to be cleared, and when bits have to + * be set and then tested atomically - as is the case where event groups are + * used to create a synchronisation point between multiple tasks (a + * 'rendezvous'). + * + * \defgroup EventGroup + */ + + + +/** + * event_groups.h + * + * Type by which event groups are referenced. For example, a call to + * xEventGroupCreate() returns an EventGroupHandle_t variable that can then + * be used as a parameter to other event group functions. + * + * \defgroup EventGroupHandle_t EventGroupHandle_t + * \ingroup EventGroup + */ +struct EventGroupDef_t; +typedef struct EventGroupDef_t * EventGroupHandle_t; + +/* + * The type that holds event bits always matches TickType_t - therefore the + * number of bits it holds is set by configUSE_16_BIT_TICKS (16 bits if set to 1, + * 32 bits if set to 0. + * + * \defgroup EventBits_t EventBits_t + * \ingroup EventGroup + */ +typedef TickType_t EventBits_t; + +/** + * event_groups.h + *
+ * EventGroupHandle_t xEventGroupCreate( void );
+ * 
+ * + * Create a new event group. + * + * Internally, within the FreeRTOS implementation, event groups use a [small] + * block of memory, in which the event group's structure is stored. If an event + * groups is created using xEventGropuCreate() then the required memory is + * automatically dynamically allocated inside the xEventGroupCreate() function. + * (see https://www.FreeRTOS.org/a00111.html). If an event group is created + * using xEventGropuCreateStatic() then the application writer must instead + * provide the memory that will get used by the event group. + * xEventGroupCreateStatic() therefore allows an event group to be created + * without using any dynamic memory allocation. + * + * Although event groups are not related to ticks, for internal implementation + * reasons the number of bits available for use in an event group is dependent + * on the configUSE_16_BIT_TICKS setting in FreeRTOSConfig.h. If + * configUSE_16_BIT_TICKS is 1 then each event group contains 8 usable bits (bit + * 0 to bit 7). If configUSE_16_BIT_TICKS is set to 0 then each event group has + * 24 usable bits (bit 0 to bit 23). The EventBits_t type is used to store + * event bits within an event group. + * + * @return If the event group was created then a handle to the event group is + * returned. If there was insufficient FreeRTOS heap available to create the + * event group then NULL is returned. See https://www.FreeRTOS.org/a00111.html + * + * Example usage: + *
+ *  // Declare a variable to hold the created event group.
+ *  EventGroupHandle_t xCreatedEventGroup;
+ *
+ *  // Attempt to create the event group.
+ *  xCreatedEventGroup = xEventGroupCreate();
+ *
+ *  // Was the event group created successfully?
+ *  if( xCreatedEventGroup == NULL )
+ *  {
+ *      // The event group was not created because there was insufficient
+ *      // FreeRTOS heap available.
+ *  }
+ *  else
+ *  {
+ *      // The event group was created.
+ *  }
+ * 
+ * \defgroup xEventGroupCreate xEventGroupCreate + * \ingroup EventGroup + */ +#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + EventGroupHandle_t xEventGroupCreate( void ) PRIVILEGED_FUNCTION; +#endif + +/** + * event_groups.h + *
+ * EventGroupHandle_t xEventGroupCreateStatic( EventGroupHandle_t * pxEventGroupBuffer );
+ * 
+ * + * Create a new event group. + * + * Internally, within the FreeRTOS implementation, event groups use a [small] + * block of memory, in which the event group's structure is stored. If an event + * groups is created using xEventGropuCreate() then the required memory is + * automatically dynamically allocated inside the xEventGroupCreate() function. + * (see https://www.FreeRTOS.org/a00111.html). If an event group is created + * using xEventGropuCreateStatic() then the application writer must instead + * provide the memory that will get used by the event group. + * xEventGroupCreateStatic() therefore allows an event group to be created + * without using any dynamic memory allocation. + * + * Although event groups are not related to ticks, for internal implementation + * reasons the number of bits available for use in an event group is dependent + * on the configUSE_16_BIT_TICKS setting in FreeRTOSConfig.h. If + * configUSE_16_BIT_TICKS is 1 then each event group contains 8 usable bits (bit + * 0 to bit 7). If configUSE_16_BIT_TICKS is set to 0 then each event group has + * 24 usable bits (bit 0 to bit 23). The EventBits_t type is used to store + * event bits within an event group. + * + * @param pxEventGroupBuffer pxEventGroupBuffer must point to a variable of type + * StaticEventGroup_t, which will be then be used to hold the event group's data + * structures, removing the need for the memory to be allocated dynamically. + * + * @return If the event group was created then a handle to the event group is + * returned. If pxEventGroupBuffer was NULL then NULL is returned. + * + * Example usage: + *
+ *  // StaticEventGroup_t is a publicly accessible structure that has the same
+ *  // size and alignment requirements as the real event group structure.  It is
+ *  // provided as a mechanism for applications to know the size of the event
+ *  // group (which is dependent on the architecture and configuration file
+ *  // settings) without breaking the strict data hiding policy by exposing the
+ *  // real event group internals.  This StaticEventGroup_t variable is passed
+ *  // into the xSemaphoreCreateEventGroupStatic() function and is used to store
+ *  // the event group's data structures
+ *  StaticEventGroup_t xEventGroupBuffer;
+ *
+ *  // Create the event group without dynamically allocating any memory.
+ *  xEventGroup = xEventGroupCreateStatic( &xEventGroupBuffer );
+ * 
+ */ +#if ( configSUPPORT_STATIC_ALLOCATION == 1 ) + EventGroupHandle_t xEventGroupCreateStatic( StaticEventGroup_t * pxEventGroupBuffer ) PRIVILEGED_FUNCTION; +#endif + +/** + * event_groups.h + *
+ *  EventBits_t xEventGroupWaitBits(    EventGroupHandle_t xEventGroup,
+ *                                      const EventBits_t uxBitsToWaitFor,
+ *                                      const BaseType_t xClearOnExit,
+ *                                      const BaseType_t xWaitForAllBits,
+ *                                      const TickType_t xTicksToWait );
+ * 
+ * + * [Potentially] block to wait for one or more bits to be set within a + * previously created event group. + * + * This function cannot be called from an interrupt. + * + * @param xEventGroup The event group in which the bits are being tested. The + * event group must have previously been created using a call to + * xEventGroupCreate(). + * + * @param uxBitsToWaitFor A bitwise value that indicates the bit or bits to test + * inside the event group. For example, to wait for bit 0 and/or bit 2 set + * uxBitsToWaitFor to 0x05. To wait for bits 0 and/or bit 1 and/or bit 2 set + * uxBitsToWaitFor to 0x07. Etc. + * + * @param xClearOnExit If xClearOnExit is set to pdTRUE then any bits within + * uxBitsToWaitFor that are set within the event group will be cleared before + * xEventGroupWaitBits() returns if the wait condition was met (if the function + * returns for a reason other than a timeout). If xClearOnExit is set to + * pdFALSE then the bits set in the event group are not altered when the call to + * xEventGroupWaitBits() returns. + * + * @param xWaitForAllBits If xWaitForAllBits is set to pdTRUE then + * xEventGroupWaitBits() will return when either all the bits in uxBitsToWaitFor + * are set or the specified block time expires. If xWaitForAllBits is set to + * pdFALSE then xEventGroupWaitBits() will return when any one of the bits set + * in uxBitsToWaitFor is set or the specified block time expires. The block + * time is specified by the xTicksToWait parameter. + * + * @param xTicksToWait The maximum amount of time (specified in 'ticks') to wait + * for one/all (depending on the xWaitForAllBits value) of the bits specified by + * uxBitsToWaitFor to become set. + * + * @return The value of the event group at the time either the bits being waited + * for became set, or the block time expired. Test the return value to know + * which bits were set. If xEventGroupWaitBits() returned because its timeout + * expired then not all the bits being waited for will be set. If + * xEventGroupWaitBits() returned because the bits it was waiting for were set + * then the returned value is the event group value before any bits were + * automatically cleared in the case that xClearOnExit parameter was set to + * pdTRUE. + * + * Example usage: + *
+ #define BIT_0 ( 1 << 0 )
+ #define BIT_4 ( 1 << 4 )
+ *
+ * void aFunction( EventGroupHandle_t xEventGroup )
+ * {
+ * EventBits_t uxBits;
+ * const TickType_t xTicksToWait = 100 / portTICK_PERIOD_MS;
+ *
+ *      // Wait a maximum of 100ms for either bit 0 or bit 4 to be set within
+ *      // the event group.  Clear the bits before exiting.
+ *      uxBits = xEventGroupWaitBits(
+ *                  xEventGroup,    // The event group being tested.
+ *                  BIT_0 | BIT_4,  // The bits within the event group to wait for.
+ *                  pdTRUE,         // BIT_0 and BIT_4 should be cleared before returning.
+ *                  pdFALSE,        // Don't wait for both bits, either bit will do.
+ *                  xTicksToWait ); // Wait a maximum of 100ms for either bit to be set.
+ *
+ *      if( ( uxBits & ( BIT_0 | BIT_4 ) ) == ( BIT_0 | BIT_4 ) )
+ *      {
+ *          // xEventGroupWaitBits() returned because both bits were set.
+ *      }
+ *      else if( ( uxBits & BIT_0 ) != 0 )
+ *      {
+ *          // xEventGroupWaitBits() returned because just BIT_0 was set.
+ *      }
+ *      else if( ( uxBits & BIT_4 ) != 0 )
+ *      {
+ *          // xEventGroupWaitBits() returned because just BIT_4 was set.
+ *      }
+ *      else
+ *      {
+ *          // xEventGroupWaitBits() returned because xTicksToWait ticks passed
+ *          // without either BIT_0 or BIT_4 becoming set.
+ *      }
+ * }
+ * 
+ * \defgroup xEventGroupWaitBits xEventGroupWaitBits + * \ingroup EventGroup + */ +EventBits_t xEventGroupWaitBits( EventGroupHandle_t xEventGroup, + const EventBits_t uxBitsToWaitFor, + const BaseType_t xClearOnExit, + const BaseType_t xWaitForAllBits, + TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; + +/** + * event_groups.h + *
+ *  EventBits_t xEventGroupClearBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToClear );
+ * 
+ * + * Clear bits within an event group. This function cannot be called from an + * interrupt. + * + * @param xEventGroup The event group in which the bits are to be cleared. + * + * @param uxBitsToClear A bitwise value that indicates the bit or bits to clear + * in the event group. For example, to clear bit 3 only, set uxBitsToClear to + * 0x08. To clear bit 3 and bit 0 set uxBitsToClear to 0x09. + * + * @return The value of the event group before the specified bits were cleared. + * + * Example usage: + *
+ #define BIT_0 ( 1 << 0 )
+ #define BIT_4 ( 1 << 4 )
+ *
+ * void aFunction( EventGroupHandle_t xEventGroup )
+ * {
+ * EventBits_t uxBits;
+ *
+ *      // Clear bit 0 and bit 4 in xEventGroup.
+ *      uxBits = xEventGroupClearBits(
+ *                              xEventGroup,    // The event group being updated.
+ *                              BIT_0 | BIT_4 );// The bits being cleared.
+ *
+ *      if( ( uxBits & ( BIT_0 | BIT_4 ) ) == ( BIT_0 | BIT_4 ) )
+ *      {
+ *          // Both bit 0 and bit 4 were set before xEventGroupClearBits() was
+ *          // called.  Both will now be clear (not set).
+ *      }
+ *      else if( ( uxBits & BIT_0 ) != 0 )
+ *      {
+ *          // Bit 0 was set before xEventGroupClearBits() was called.  It will
+ *          // now be clear.
+ *      }
+ *      else if( ( uxBits & BIT_4 ) != 0 )
+ *      {
+ *          // Bit 4 was set before xEventGroupClearBits() was called.  It will
+ *          // now be clear.
+ *      }
+ *      else
+ *      {
+ *          // Neither bit 0 nor bit 4 were set in the first place.
+ *      }
+ * }
+ * 
+ * \defgroup xEventGroupClearBits xEventGroupClearBits + * \ingroup EventGroup + */ +EventBits_t xEventGroupClearBits( EventGroupHandle_t xEventGroup, + const EventBits_t uxBitsToClear ) PRIVILEGED_FUNCTION; + +/** + * event_groups.h + *
+ *  BaseType_t xEventGroupClearBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet );
+ * 
+ * + * A version of xEventGroupClearBits() that can be called from an interrupt. + * + * Setting bits in an event group is not a deterministic operation because there + * are an unknown number of tasks that may be waiting for the bit or bits being + * set. FreeRTOS does not allow nondeterministic operations to be performed + * while interrupts are disabled, so protects event groups that are accessed + * from tasks by suspending the scheduler rather than disabling interrupts. As + * a result event groups cannot be accessed directly from an interrupt service + * routine. Therefore xEventGroupClearBitsFromISR() sends a message to the + * timer task to have the clear operation performed in the context of the timer + * task. + * + * @param xEventGroup The event group in which the bits are to be cleared. + * + * @param uxBitsToClear A bitwise value that indicates the bit or bits to clear. + * For example, to clear bit 3 only, set uxBitsToClear to 0x08. To clear bit 3 + * and bit 0 set uxBitsToClear to 0x09. + * + * @return If the request to execute the function was posted successfully then + * pdPASS is returned, otherwise pdFALSE is returned. pdFALSE will be returned + * if the timer service queue was full. + * + * Example usage: + *
+ #define BIT_0 ( 1 << 0 )
+ #define BIT_4 ( 1 << 4 )
+ *
+ * // An event group which it is assumed has already been created by a call to
+ * // xEventGroupCreate().
+ * EventGroupHandle_t xEventGroup;
+ *
+ * void anInterruptHandler( void )
+ * {
+ *      // Clear bit 0 and bit 4 in xEventGroup.
+ *      xResult = xEventGroupClearBitsFromISR(
+ *                          xEventGroup,     // The event group being updated.
+ *                          BIT_0 | BIT_4 ); // The bits being set.
+ *
+ *      if( xResult == pdPASS )
+ *      {
+ *          // The message was posted successfully.
+ *      }
+ * }
+ * 
+ * \defgroup xEventGroupClearBitsFromISR xEventGroupClearBitsFromISR + * \ingroup EventGroup + */ +#if ( configUSE_TRACE_FACILITY == 1 ) + BaseType_t xEventGroupClearBitsFromISR( EventGroupHandle_t xEventGroup, + const EventBits_t uxBitsToClear ) PRIVILEGED_FUNCTION; +#else + #define xEventGroupClearBitsFromISR( xEventGroup, uxBitsToClear ) \ + xTimerPendFunctionCallFromISR( vEventGroupClearBitsCallback, ( void * ) xEventGroup, ( uint32_t ) uxBitsToClear, NULL ) +#endif + +/** + * event_groups.h + *
+ *  EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet );
+ * 
+ * + * Set bits within an event group. + * This function cannot be called from an interrupt. xEventGroupSetBitsFromISR() + * is a version that can be called from an interrupt. + * + * Setting bits in an event group will automatically unblock tasks that are + * blocked waiting for the bits. + * + * @param xEventGroup The event group in which the bits are to be set. + * + * @param uxBitsToSet A bitwise value that indicates the bit or bits to set. + * For example, to set bit 3 only, set uxBitsToSet to 0x08. To set bit 3 + * and bit 0 set uxBitsToSet to 0x09. + * + * @return The value of the event group at the time the call to + * xEventGroupSetBits() returns. There are two reasons why the returned value + * might have the bits specified by the uxBitsToSet parameter cleared. First, + * if setting a bit results in a task that was waiting for the bit leaving the + * blocked state then it is possible the bit will be cleared automatically + * (see the xClearBitOnExit parameter of xEventGroupWaitBits()). Second, any + * unblocked (or otherwise Ready state) task that has a priority above that of + * the task that called xEventGroupSetBits() will execute and may change the + * event group value before the call to xEventGroupSetBits() returns. + * + * Example usage: + *
+ #define BIT_0 ( 1 << 0 )
+ #define BIT_4 ( 1 << 4 )
+ *
+ * void aFunction( EventGroupHandle_t xEventGroup )
+ * {
+ * EventBits_t uxBits;
+ *
+ *      // Set bit 0 and bit 4 in xEventGroup.
+ *      uxBits = xEventGroupSetBits(
+ *                          xEventGroup,    // The event group being updated.
+ *                          BIT_0 | BIT_4 );// The bits being set.
+ *
+ *      if( ( uxBits & ( BIT_0 | BIT_4 ) ) == ( BIT_0 | BIT_4 ) )
+ *      {
+ *          // Both bit 0 and bit 4 remained set when the function returned.
+ *      }
+ *      else if( ( uxBits & BIT_0 ) != 0 )
+ *      {
+ *          // Bit 0 remained set when the function returned, but bit 4 was
+ *          // cleared.  It might be that bit 4 was cleared automatically as a
+ *          // task that was waiting for bit 4 was removed from the Blocked
+ *          // state.
+ *      }
+ *      else if( ( uxBits & BIT_4 ) != 0 )
+ *      {
+ *          // Bit 4 remained set when the function returned, but bit 0 was
+ *          // cleared.  It might be that bit 0 was cleared automatically as a
+ *          // task that was waiting for bit 0 was removed from the Blocked
+ *          // state.
+ *      }
+ *      else
+ *      {
+ *          // Neither bit 0 nor bit 4 remained set.  It might be that a task
+ *          // was waiting for both of the bits to be set, and the bits were
+ *          // cleared as the task left the Blocked state.
+ *      }
+ * }
+ * 
+ * \defgroup xEventGroupSetBits xEventGroupSetBits + * \ingroup EventGroup + */ +EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup, + const EventBits_t uxBitsToSet ) PRIVILEGED_FUNCTION; + +/** + * event_groups.h + *
+ *  BaseType_t xEventGroupSetBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet, BaseType_t *pxHigherPriorityTaskWoken );
+ * 
+ * + * A version of xEventGroupSetBits() that can be called from an interrupt. + * + * Setting bits in an event group is not a deterministic operation because there + * are an unknown number of tasks that may be waiting for the bit or bits being + * set. FreeRTOS does not allow nondeterministic operations to be performed in + * interrupts or from critical sections. Therefore xEventGroupSetBitsFromISR() + * sends a message to the timer task to have the set operation performed in the + * context of the timer task - where a scheduler lock is used in place of a + * critical section. + * + * @param xEventGroup The event group in which the bits are to be set. + * + * @param uxBitsToSet A bitwise value that indicates the bit or bits to set. + * For example, to set bit 3 only, set uxBitsToSet to 0x08. To set bit 3 + * and bit 0 set uxBitsToSet to 0x09. + * + * @param pxHigherPriorityTaskWoken As mentioned above, calling this function + * will result in a message being sent to the timer daemon task. If the + * priority of the timer daemon task is higher than the priority of the + * currently running task (the task the interrupt interrupted) then + * *pxHigherPriorityTaskWoken will be set to pdTRUE by + * xEventGroupSetBitsFromISR(), indicating that a context switch should be + * requested before the interrupt exits. For that reason + * *pxHigherPriorityTaskWoken must be initialised to pdFALSE. See the + * example code below. + * + * @return If the request to execute the function was posted successfully then + * pdPASS is returned, otherwise pdFALSE is returned. pdFALSE will be returned + * if the timer service queue was full. + * + * Example usage: + *
+ #define BIT_0 ( 1 << 0 )
+ #define BIT_4 ( 1 << 4 )
+ *
+ * // An event group which it is assumed has already been created by a call to
+ * // xEventGroupCreate().
+ * EventGroupHandle_t xEventGroup;
+ *
+ * void anInterruptHandler( void )
+ * {
+ * BaseType_t xHigherPriorityTaskWoken, xResult;
+ *
+ *      // xHigherPriorityTaskWoken must be initialised to pdFALSE.
+ *      xHigherPriorityTaskWoken = pdFALSE;
+ *
+ *      // Set bit 0 and bit 4 in xEventGroup.
+ *      xResult = xEventGroupSetBitsFromISR(
+ *                          xEventGroup,    // The event group being updated.
+ *                          BIT_0 | BIT_4   // The bits being set.
+ *                          &xHigherPriorityTaskWoken );
+ *
+ *      // Was the message posted successfully?
+ *      if( xResult == pdPASS )
+ *      {
+ *          // If xHigherPriorityTaskWoken is now set to pdTRUE then a context
+ *          // switch should be requested.  The macro used is port specific and
+ *          // will be either portYIELD_FROM_ISR() or portEND_SWITCHING_ISR() -
+ *          // refer to the documentation page for the port being used.
+ *          portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
+ *      }
+ * }
+ * 
+ * \defgroup xEventGroupSetBitsFromISR xEventGroupSetBitsFromISR + * \ingroup EventGroup + */ +#if ( configUSE_TRACE_FACILITY == 1 ) + BaseType_t xEventGroupSetBitsFromISR( EventGroupHandle_t xEventGroup, + const EventBits_t uxBitsToSet, + BaseType_t * pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION; +#else + #define xEventGroupSetBitsFromISR( xEventGroup, uxBitsToSet, pxHigherPriorityTaskWoken ) \ + xTimerPendFunctionCallFromISR( vEventGroupSetBitsCallback, ( void * ) xEventGroup, ( uint32_t ) uxBitsToSet, pxHigherPriorityTaskWoken ) +#endif + +/** + * event_groups.h + *
+ *  EventBits_t xEventGroupSync(    EventGroupHandle_t xEventGroup,
+ *                                  const EventBits_t uxBitsToSet,
+ *                                  const EventBits_t uxBitsToWaitFor,
+ *                                  TickType_t xTicksToWait );
+ * 
+ * + * Atomically set bits within an event group, then wait for a combination of + * bits to be set within the same event group. This functionality is typically + * used to synchronise multiple tasks, where each task has to wait for the other + * tasks to reach a synchronisation point before proceeding. + * + * This function cannot be used from an interrupt. + * + * The function will return before its block time expires if the bits specified + * by the uxBitsToWait parameter are set, or become set within that time. In + * this case all the bits specified by uxBitsToWait will be automatically + * cleared before the function returns. + * + * @param xEventGroup The event group in which the bits are being tested. The + * event group must have previously been created using a call to + * xEventGroupCreate(). + * + * @param uxBitsToSet The bits to set in the event group before determining + * if, and possibly waiting for, all the bits specified by the uxBitsToWait + * parameter are set. + * + * @param uxBitsToWaitFor A bitwise value that indicates the bit or bits to test + * inside the event group. For example, to wait for bit 0 and bit 2 set + * uxBitsToWaitFor to 0x05. To wait for bits 0 and bit 1 and bit 2 set + * uxBitsToWaitFor to 0x07. Etc. + * + * @param xTicksToWait The maximum amount of time (specified in 'ticks') to wait + * for all of the bits specified by uxBitsToWaitFor to become set. + * + * @return The value of the event group at the time either the bits being waited + * for became set, or the block time expired. Test the return value to know + * which bits were set. If xEventGroupSync() returned because its timeout + * expired then not all the bits being waited for will be set. If + * xEventGroupSync() returned because all the bits it was waiting for were + * set then the returned value is the event group value before any bits were + * automatically cleared. + * + * Example usage: + *
+ * // Bits used by the three tasks.
+ #define TASK_0_BIT     ( 1 << 0 )
+ #define TASK_1_BIT     ( 1 << 1 )
+ #define TASK_2_BIT     ( 1 << 2 )
+ *
+ #define ALL_SYNC_BITS ( TASK_0_BIT | TASK_1_BIT | TASK_2_BIT )
+ *
+ * // Use an event group to synchronise three tasks.  It is assumed this event
+ * // group has already been created elsewhere.
+ * EventGroupHandle_t xEventBits;
+ *
+ * void vTask0( void *pvParameters )
+ * {
+ * EventBits_t uxReturn;
+ * TickType_t xTicksToWait = 100 / portTICK_PERIOD_MS;
+ *
+ *   for( ;; )
+ *   {
+ *      // Perform task functionality here.
+ *
+ *      // Set bit 0 in the event flag to note this task has reached the
+ *      // sync point.  The other two tasks will set the other two bits defined
+ *      // by ALL_SYNC_BITS.  All three tasks have reached the synchronisation
+ *      // point when all the ALL_SYNC_BITS are set.  Wait a maximum of 100ms
+ *      // for this to happen.
+ *      uxReturn = xEventGroupSync( xEventBits, TASK_0_BIT, ALL_SYNC_BITS, xTicksToWait );
+ *
+ *      if( ( uxReturn & ALL_SYNC_BITS ) == ALL_SYNC_BITS )
+ *      {
+ *          // All three tasks reached the synchronisation point before the call
+ *          // to xEventGroupSync() timed out.
+ *      }
+ *  }
+ * }
+ *
+ * void vTask1( void *pvParameters )
+ * {
+ *   for( ;; )
+ *   {
+ *      // Perform task functionality here.
+ *
+ *      // Set bit 1 in the event flag to note this task has reached the
+ *      // synchronisation point.  The other two tasks will set the other two
+ *      // bits defined by ALL_SYNC_BITS.  All three tasks have reached the
+ *      // synchronisation point when all the ALL_SYNC_BITS are set.  Wait
+ *      // indefinitely for this to happen.
+ *      xEventGroupSync( xEventBits, TASK_1_BIT, ALL_SYNC_BITS, portMAX_DELAY );
+ *
+ *      // xEventGroupSync() was called with an indefinite block time, so
+ *      // this task will only reach here if the synchronisation was made by all
+ *      // three tasks, so there is no need to test the return value.
+ *   }
+ * }
+ *
+ * void vTask2( void *pvParameters )
+ * {
+ *   for( ;; )
+ *   {
+ *      // Perform task functionality here.
+ *
+ *      // Set bit 2 in the event flag to note this task has reached the
+ *      // synchronisation point.  The other two tasks will set the other two
+ *      // bits defined by ALL_SYNC_BITS.  All three tasks have reached the
+ *      // synchronisation point when all the ALL_SYNC_BITS are set.  Wait
+ *      // indefinitely for this to happen.
+ *      xEventGroupSync( xEventBits, TASK_2_BIT, ALL_SYNC_BITS, portMAX_DELAY );
+ *
+ *      // xEventGroupSync() was called with an indefinite block time, so
+ *      // this task will only reach here if the synchronisation was made by all
+ *      // three tasks, so there is no need to test the return value.
+ *  }
+ * }
+ *
+ * 
+ * \defgroup xEventGroupSync xEventGroupSync + * \ingroup EventGroup + */ +EventBits_t xEventGroupSync( EventGroupHandle_t xEventGroup, + const EventBits_t uxBitsToSet, + const EventBits_t uxBitsToWaitFor, + TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; + + +/** + * event_groups.h + *
+ *  EventBits_t xEventGroupGetBits( EventGroupHandle_t xEventGroup );
+ * 
+ * + * Returns the current value of the bits in an event group. This function + * cannot be used from an interrupt. + * + * @param xEventGroup The event group being queried. + * + * @return The event group bits at the time xEventGroupGetBits() was called. + * + * \defgroup xEventGroupGetBits xEventGroupGetBits + * \ingroup EventGroup + */ +#define xEventGroupGetBits( xEventGroup ) xEventGroupClearBits( xEventGroup, 0 ) + +/** + * event_groups.h + *
+ *  EventBits_t xEventGroupGetBitsFromISR( EventGroupHandle_t xEventGroup );
+ * 
+ * + * A version of xEventGroupGetBits() that can be called from an ISR. + * + * @param xEventGroup The event group being queried. + * + * @return The event group bits at the time xEventGroupGetBitsFromISR() was called. + * + * \defgroup xEventGroupGetBitsFromISR xEventGroupGetBitsFromISR + * \ingroup EventGroup + */ +EventBits_t xEventGroupGetBitsFromISR( EventGroupHandle_t xEventGroup ) PRIVILEGED_FUNCTION; + +/** + * event_groups.h + *
+ *  void xEventGroupDelete( EventGroupHandle_t xEventGroup );
+ * 
+ * + * Delete an event group that was previously created by a call to + * xEventGroupCreate(). Tasks that are blocked on the event group will be + * unblocked and obtain 0 as the event group's value. + * + * @param xEventGroup The event group being deleted. + */ +void vEventGroupDelete( EventGroupHandle_t xEventGroup ) PRIVILEGED_FUNCTION; + +/* For internal use only. */ +void vEventGroupSetBitsCallback( void * pvEventGroup, + const uint32_t ulBitsToSet ) PRIVILEGED_FUNCTION; +void vEventGroupClearBitsCallback( void * pvEventGroup, + const uint32_t ulBitsToClear ) PRIVILEGED_FUNCTION; + + +#if ( configUSE_TRACE_FACILITY == 1 ) + UBaseType_t uxEventGroupGetNumber( void * xEventGroup ) PRIVILEGED_FUNCTION; + void vEventGroupSetNumber( void * xEventGroup, + UBaseType_t uxEventGroupNumber ) PRIVILEGED_FUNCTION; +#endif + +/* *INDENT-OFF* */ +#ifdef __cplusplus + } +#endif +/* *INDENT-ON* */ + +#endif /* EVENT_GROUPS_H */ diff --git a/RTOS/FreeRTOS/Source/include/list.h b/RTOS/FreeRTOS/Source/include/list.h new file mode 100644 index 0000000..da76393 --- /dev/null +++ b/RTOS/FreeRTOS/Source/include/list.h @@ -0,0 +1,417 @@ +/* + * FreeRTOS Kernel V10.4.1 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * https://www.FreeRTOS.org + * https://github.com/FreeRTOS + * + */ + +/* + * This is the list implementation used by the scheduler. While it is tailored + * heavily for the schedulers needs, it is also available for use by + * application code. + * + * list_ts can only store pointers to list_item_ts. Each ListItem_t contains a + * numeric value (xItemValue). Most of the time the lists are sorted in + * descending item value order. + * + * Lists are created already containing one list item. The value of this + * item is the maximum possible that can be stored, it is therefore always at + * the end of the list and acts as a marker. The list member pxHead always + * points to this marker - even though it is at the tail of the list. This + * is because the tail contains a wrap back pointer to the true head of + * the list. + * + * In addition to it's value, each list item contains a pointer to the next + * item in the list (pxNext), a pointer to the list it is in (pxContainer) + * and a pointer to back to the object that contains it. These later two + * pointers are included for efficiency of list manipulation. There is + * effectively a two way link between the object containing the list item and + * the list item itself. + * + * + * \page ListIntroduction List Implementation + * \ingroup FreeRTOSIntro + */ + + +#ifndef LIST_H +#define LIST_H + +#ifndef INC_FREERTOS_H + #error "FreeRTOS.h must be included before list.h" +#endif + +/* + * The list structure members are modified from within interrupts, and therefore + * by rights should be declared volatile. However, they are only modified in a + * functionally atomic way (within critical sections of with the scheduler + * suspended) and are either passed by reference into a function or indexed via + * a volatile variable. Therefore, in all use cases tested so far, the volatile + * qualifier can be omitted in order to provide a moderate performance + * improvement without adversely affecting functional behaviour. The assembly + * instructions generated by the IAR, ARM and GCC compilers when the respective + * compiler's options were set for maximum optimisation has been inspected and + * deemed to be as intended. That said, as compiler technology advances, and + * especially if aggressive cross module optimisation is used (a use case that + * has not been exercised to any great extend) then it is feasible that the + * volatile qualifier will be needed for correct optimisation. It is expected + * that a compiler removing essential code because, without the volatile + * qualifier on the list structure members and with aggressive cross module + * optimisation, the compiler deemed the code unnecessary will result in + * complete and obvious failure of the scheduler. If this is ever experienced + * then the volatile qualifier can be inserted in the relevant places within the + * list structures by simply defining configLIST_VOLATILE to volatile in + * FreeRTOSConfig.h (as per the example at the bottom of this comment block). + * If configLIST_VOLATILE is not defined then the preprocessor directives below + * will simply #define configLIST_VOLATILE away completely. + * + * To use volatile list structure members then add the following line to + * FreeRTOSConfig.h (without the quotes): + * "#define configLIST_VOLATILE volatile" + */ +#ifndef configLIST_VOLATILE + #define configLIST_VOLATILE +#endif /* configSUPPORT_CROSS_MODULE_OPTIMISATION */ + +/* *INDENT-OFF* */ +#ifdef __cplusplus + extern "C" { +#endif +/* *INDENT-ON* */ + +/* Macros that can be used to place known values within the list structures, + * then check that the known values do not get corrupted during the execution of + * the application. These may catch the list data structures being overwritten in + * memory. They will not catch data errors caused by incorrect configuration or + * use of FreeRTOS.*/ +#if ( configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES == 0 ) + /* Define the macros to do nothing. */ + #define listFIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE + #define listSECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE + #define listFIRST_LIST_INTEGRITY_CHECK_VALUE + #define listSECOND_LIST_INTEGRITY_CHECK_VALUE + #define listSET_FIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem ) + #define listSET_SECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem ) + #define listSET_LIST_INTEGRITY_CHECK_1_VALUE( pxList ) + #define listSET_LIST_INTEGRITY_CHECK_2_VALUE( pxList ) + #define listTEST_LIST_ITEM_INTEGRITY( pxItem ) + #define listTEST_LIST_INTEGRITY( pxList ) +#else /* if ( configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES == 0 ) */ + /* Define macros that add new members into the list structures. */ + #define listFIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE TickType_t xListItemIntegrityValue1; + #define listSECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE TickType_t xListItemIntegrityValue2; + #define listFIRST_LIST_INTEGRITY_CHECK_VALUE TickType_t xListIntegrityValue1; + #define listSECOND_LIST_INTEGRITY_CHECK_VALUE TickType_t xListIntegrityValue2; + +/* Define macros that set the new structure members to known values. */ + #define listSET_FIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem ) ( pxItem )->xListItemIntegrityValue1 = pdINTEGRITY_CHECK_VALUE + #define listSET_SECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem ) ( pxItem )->xListItemIntegrityValue2 = pdINTEGRITY_CHECK_VALUE + #define listSET_LIST_INTEGRITY_CHECK_1_VALUE( pxList ) ( pxList )->xListIntegrityValue1 = pdINTEGRITY_CHECK_VALUE + #define listSET_LIST_INTEGRITY_CHECK_2_VALUE( pxList ) ( pxList )->xListIntegrityValue2 = pdINTEGRITY_CHECK_VALUE + +/* Define macros that will assert if one of the structure members does not + * contain its expected value. */ + #define listTEST_LIST_ITEM_INTEGRITY( pxItem ) configASSERT( ( ( pxItem )->xListItemIntegrityValue1 == pdINTEGRITY_CHECK_VALUE ) && ( ( pxItem )->xListItemIntegrityValue2 == pdINTEGRITY_CHECK_VALUE ) ) + #define listTEST_LIST_INTEGRITY( pxList ) configASSERT( ( ( pxList )->xListIntegrityValue1 == pdINTEGRITY_CHECK_VALUE ) && ( ( pxList )->xListIntegrityValue2 == pdINTEGRITY_CHECK_VALUE ) ) +#endif /* configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES */ + + +/* + * Definition of the only type of object that a list can contain. + */ +struct xLIST; +struct xLIST_ITEM +{ + listFIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE /*< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */ + configLIST_VOLATILE TickType_t xItemValue; /*< The value being listed. In most cases this is used to sort the list in descending order. */ + struct xLIST_ITEM * configLIST_VOLATILE pxNext; /*< Pointer to the next ListItem_t in the list. */ + struct xLIST_ITEM * configLIST_VOLATILE pxPrevious; /*< Pointer to the previous ListItem_t in the list. */ + void * pvOwner; /*< Pointer to the object (normally a TCB) that contains the list item. There is therefore a two way link between the object containing the list item and the list item itself. */ + struct xLIST * configLIST_VOLATILE pxContainer; /*< Pointer to the list in which this list item is placed (if any). */ + listSECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE /*< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */ +}; +typedef struct xLIST_ITEM ListItem_t; /* For some reason lint wants this as two separate definitions. */ + +struct xMINI_LIST_ITEM +{ + listFIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE /*< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */ + configLIST_VOLATILE TickType_t xItemValue; + struct xLIST_ITEM * configLIST_VOLATILE pxNext; + struct xLIST_ITEM * configLIST_VOLATILE pxPrevious; +}; +typedef struct xMINI_LIST_ITEM MiniListItem_t; + +/* + * Definition of the type of queue used by the scheduler. + */ +typedef struct xLIST +{ + listFIRST_LIST_INTEGRITY_CHECK_VALUE /*< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */ + volatile UBaseType_t uxNumberOfItems; + ListItem_t * configLIST_VOLATILE pxIndex; /*< Used to walk through the list. Points to the last item returned by a call to listGET_OWNER_OF_NEXT_ENTRY (). */ + MiniListItem_t xListEnd; /*< List item that contains the maximum possible item value meaning it is always at the end of the list and is therefore used as a marker. */ + listSECOND_LIST_INTEGRITY_CHECK_VALUE /*< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */ +} List_t; + +/* + * Access macro to set the owner of a list item. The owner of a list item + * is the object (usually a TCB) that contains the list item. + * + * \page listSET_LIST_ITEM_OWNER listSET_LIST_ITEM_OWNER + * \ingroup LinkedList + */ +#define listSET_LIST_ITEM_OWNER( pxListItem, pxOwner ) ( ( pxListItem )->pvOwner = ( void * ) ( pxOwner ) ) + +/* + * Access macro to get the owner of a list item. The owner of a list item + * is the object (usually a TCB) that contains the list item. + * + * \page listGET_LIST_ITEM_OWNER listSET_LIST_ITEM_OWNER + * \ingroup LinkedList + */ +#define listGET_LIST_ITEM_OWNER( pxListItem ) ( ( pxListItem )->pvOwner ) + +/* + * Access macro to set the value of the list item. In most cases the value is + * used to sort the list in descending order. + * + * \page listSET_LIST_ITEM_VALUE listSET_LIST_ITEM_VALUE + * \ingroup LinkedList + */ +#define listSET_LIST_ITEM_VALUE( pxListItem, xValue ) ( ( pxListItem )->xItemValue = ( xValue ) ) + +/* + * Access macro to retrieve the value of the list item. The value can + * represent anything - for example the priority of a task, or the time at + * which a task should be unblocked. + * + * \page listGET_LIST_ITEM_VALUE listGET_LIST_ITEM_VALUE + * \ingroup LinkedList + */ +#define listGET_LIST_ITEM_VALUE( pxListItem ) ( ( pxListItem )->xItemValue ) + +/* + * Access macro to retrieve the value of the list item at the head of a given + * list. + * + * \page listGET_LIST_ITEM_VALUE listGET_LIST_ITEM_VALUE + * \ingroup LinkedList + */ +#define listGET_ITEM_VALUE_OF_HEAD_ENTRY( pxList ) ( ( ( pxList )->xListEnd ).pxNext->xItemValue ) + +/* + * Return the list item at the head of the list. + * + * \page listGET_HEAD_ENTRY listGET_HEAD_ENTRY + * \ingroup LinkedList + */ +#define listGET_HEAD_ENTRY( pxList ) ( ( ( pxList )->xListEnd ).pxNext ) + +/* + * Return the next list item. + * + * \page listGET_NEXT listGET_NEXT + * \ingroup LinkedList + */ +#define listGET_NEXT( pxListItem ) ( ( pxListItem )->pxNext ) + +/* + * Return the list item that marks the end of the list + * + * \page listGET_END_MARKER listGET_END_MARKER + * \ingroup LinkedList + */ +#define listGET_END_MARKER( pxList ) ( ( ListItem_t const * ) ( &( ( pxList )->xListEnd ) ) ) + +/* + * Access macro to determine if a list contains any items. The macro will + * only have the value true if the list is empty. + * + * \page listLIST_IS_EMPTY listLIST_IS_EMPTY + * \ingroup LinkedList + */ +#define listLIST_IS_EMPTY( pxList ) ( ( ( pxList )->uxNumberOfItems == ( UBaseType_t ) 0 ) ? pdTRUE : pdFALSE ) + +/* + * Access macro to return the number of items in the list. + */ +#define listCURRENT_LIST_LENGTH( pxList ) ( ( pxList )->uxNumberOfItems ) + +/* + * Access function to obtain the owner of the next entry in a list. + * + * The list member pxIndex is used to walk through a list. Calling + * listGET_OWNER_OF_NEXT_ENTRY increments pxIndex to the next item in the list + * and returns that entry's pxOwner parameter. Using multiple calls to this + * function it is therefore possible to move through every item contained in + * a list. + * + * The pxOwner parameter of a list item is a pointer to the object that owns + * the list item. In the scheduler this is normally a task control block. + * The pxOwner parameter effectively creates a two way link between the list + * item and its owner. + * + * @param pxTCB pxTCB is set to the address of the owner of the next list item. + * @param pxList The list from which the next item owner is to be returned. + * + * \page listGET_OWNER_OF_NEXT_ENTRY listGET_OWNER_OF_NEXT_ENTRY + * \ingroup LinkedList + */ +#define listGET_OWNER_OF_NEXT_ENTRY( pxTCB, pxList ) \ + { \ + List_t * const pxConstList = ( pxList ); \ + /* Increment the index to the next item and return the item, ensuring */ \ + /* we don't return the marker used at the end of the list. */ \ + ( pxConstList )->pxIndex = ( pxConstList )->pxIndex->pxNext; \ + if( ( void * ) ( pxConstList )->pxIndex == ( void * ) &( ( pxConstList )->xListEnd ) ) \ + { \ + ( pxConstList )->pxIndex = ( pxConstList )->pxIndex->pxNext; \ + } \ + ( pxTCB ) = ( pxConstList )->pxIndex->pvOwner; \ + } + + +/* + * Access function to obtain the owner of the first entry in a list. Lists + * are normally sorted in ascending item value order. + * + * This function returns the pxOwner member of the first item in the list. + * The pxOwner parameter of a list item is a pointer to the object that owns + * the list item. In the scheduler this is normally a task control block. + * The pxOwner parameter effectively creates a two way link between the list + * item and its owner. + * + * @param pxList The list from which the owner of the head item is to be + * returned. + * + * \page listGET_OWNER_OF_HEAD_ENTRY listGET_OWNER_OF_HEAD_ENTRY + * \ingroup LinkedList + */ +#define listGET_OWNER_OF_HEAD_ENTRY( pxList ) ( ( &( ( pxList )->xListEnd ) )->pxNext->pvOwner ) + +/* + * Check to see if a list item is within a list. The list item maintains a + * "container" pointer that points to the list it is in. All this macro does + * is check to see if the container and the list match. + * + * @param pxList The list we want to know if the list item is within. + * @param pxListItem The list item we want to know if is in the list. + * @return pdTRUE if the list item is in the list, otherwise pdFALSE. + */ +#define listIS_CONTAINED_WITHIN( pxList, pxListItem ) ( ( ( pxListItem )->pxContainer == ( pxList ) ) ? ( pdTRUE ) : ( pdFALSE ) ) + +/* + * Return the list a list item is contained within (referenced from). + * + * @param pxListItem The list item being queried. + * @return A pointer to the List_t object that references the pxListItem + */ +#define listLIST_ITEM_CONTAINER( pxListItem ) ( ( pxListItem )->pxContainer ) + +/* + * This provides a crude means of knowing if a list has been initialised, as + * pxList->xListEnd.xItemValue is set to portMAX_DELAY by the vListInitialise() + * function. + */ +#define listLIST_IS_INITIALISED( pxList ) ( ( pxList )->xListEnd.xItemValue == portMAX_DELAY ) + +/* + * Must be called before a list is used! This initialises all the members + * of the list structure and inserts the xListEnd item into the list as a + * marker to the back of the list. + * + * @param pxList Pointer to the list being initialised. + * + * \page vListInitialise vListInitialise + * \ingroup LinkedList + */ +void vListInitialise( List_t * const pxList ) PRIVILEGED_FUNCTION; + +/* + * Must be called before a list item is used. This sets the list container to + * null so the item does not think that it is already contained in a list. + * + * @param pxItem Pointer to the list item being initialised. + * + * \page vListInitialiseItem vListInitialiseItem + * \ingroup LinkedList + */ +void vListInitialiseItem( ListItem_t * const pxItem ) PRIVILEGED_FUNCTION; + +/* + * Insert a list item into a list. The item will be inserted into the list in + * a position determined by its item value (descending item value order). + * + * @param pxList The list into which the item is to be inserted. + * + * @param pxNewListItem The item that is to be placed in the list. + * + * \page vListInsert vListInsert + * \ingroup LinkedList + */ +void vListInsert( List_t * const pxList, + ListItem_t * const pxNewListItem ) PRIVILEGED_FUNCTION; + +/* + * Insert a list item into a list. The item will be inserted in a position + * such that it will be the last item within the list returned by multiple + * calls to listGET_OWNER_OF_NEXT_ENTRY. + * + * The list member pxIndex is used to walk through a list. Calling + * listGET_OWNER_OF_NEXT_ENTRY increments pxIndex to the next item in the list. + * Placing an item in a list using vListInsertEnd effectively places the item + * in the list position pointed to by pxIndex. This means that every other + * item within the list will be returned by listGET_OWNER_OF_NEXT_ENTRY before + * the pxIndex parameter again points to the item being inserted. + * + * @param pxList The list into which the item is to be inserted. + * + * @param pxNewListItem The list item to be inserted into the list. + * + * \page vListInsertEnd vListInsertEnd + * \ingroup LinkedList + */ +void vListInsertEnd( List_t * const pxList, + ListItem_t * const pxNewListItem ) PRIVILEGED_FUNCTION; + +/* + * Remove an item from a list. The list item has a pointer to the list that + * it is in, so only the list item need be passed into the function. + * + * @param uxListRemove The item to be removed. The item will remove itself from + * the list pointed to by it's pxContainer parameter. + * + * @return The number of items that remain in the list after the list item has + * been removed. + * + * \page uxListRemove uxListRemove + * \ingroup LinkedList + */ +UBaseType_t uxListRemove( ListItem_t * const pxItemToRemove ) PRIVILEGED_FUNCTION; + +/* *INDENT-OFF* */ +#ifdef __cplusplus + } +#endif +/* *INDENT-ON* */ + +#endif /* ifndef LIST_H */ diff --git a/RTOS/FreeRTOS/Source/include/message_buffer.h b/RTOS/FreeRTOS/Source/include/message_buffer.h new file mode 100644 index 0000000..eab0061 --- /dev/null +++ b/RTOS/FreeRTOS/Source/include/message_buffer.h @@ -0,0 +1,821 @@ +/* + * FreeRTOS Kernel V10.4.1 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * https://www.FreeRTOS.org + * https://github.com/FreeRTOS + * + */ + + +/* + * Message buffers build functionality on top of FreeRTOS stream buffers. + * Whereas stream buffers are used to send a continuous stream of data from one + * task or interrupt to another, message buffers are used to send variable + * length discrete messages from one task or interrupt to another. Their + * implementation is light weight, making them particularly suited for interrupt + * to task and core to core communication scenarios. + * + * ***NOTE***: Uniquely among FreeRTOS objects, the stream buffer + * implementation (so also the message buffer implementation, as message buffers + * are built on top of stream buffers) assumes there is only one task or + * interrupt that will write to the buffer (the writer), and only one task or + * interrupt that will read from the buffer (the reader). It is safe for the + * writer and reader to be different tasks or interrupts, but, unlike other + * FreeRTOS objects, it is not safe to have multiple different writers or + * multiple different readers. If there are to be multiple different writers + * then the application writer must place each call to a writing API function + * (such as xMessageBufferSend()) inside a critical section and set the send + * block time to 0. Likewise, if there are to be multiple different readers + * then the application writer must place each call to a reading API function + * (such as xMessageBufferRead()) inside a critical section and set the receive + * timeout to 0. + * + * Message buffers hold variable length messages. To enable that, when a + * message is written to the message buffer an additional sizeof( size_t ) bytes + * are also written to store the message's length (that happens internally, with + * the API function). sizeof( size_t ) is typically 4 bytes on a 32-bit + * architecture, so writing a 10 byte message to a message buffer on a 32-bit + * architecture will actually reduce the available space in the message buffer + * by 14 bytes (10 byte are used by the message, and 4 bytes to hold the length + * of the message). + */ + +#ifndef FREERTOS_MESSAGE_BUFFER_H +#define FREERTOS_MESSAGE_BUFFER_H + +#ifndef INC_FREERTOS_H + #error "include FreeRTOS.h must appear in source files before include message_buffer.h" +#endif + +/* Message buffers are built onto of stream buffers. */ +#include "stream_buffer.h" + +/* *INDENT-OFF* */ +#if defined( __cplusplus ) + extern "C" { +#endif +/* *INDENT-ON* */ + +/** + * Type by which message buffers are referenced. For example, a call to + * xMessageBufferCreate() returns an MessageBufferHandle_t variable that can + * then be used as a parameter to xMessageBufferSend(), xMessageBufferReceive(), + * etc. + */ +typedef void * MessageBufferHandle_t; + +/*-----------------------------------------------------------*/ + +/** + * message_buffer.h + * + *
+ * MessageBufferHandle_t xMessageBufferCreate( size_t xBufferSizeBytes );
+ * 
+ * + * Creates a new message buffer using dynamically allocated memory. See + * xMessageBufferCreateStatic() for a version that uses statically allocated + * memory (memory that is allocated at compile time). + * + * configSUPPORT_DYNAMIC_ALLOCATION must be set to 1 or left undefined in + * FreeRTOSConfig.h for xMessageBufferCreate() to be available. + * + * @param xBufferSizeBytes The total number of bytes (not messages) the message + * buffer will be able to hold at any one time. When a message is written to + * the message buffer an additional sizeof( size_t ) bytes are also written to + * store the message's length. sizeof( size_t ) is typically 4 bytes on a + * 32-bit architecture, so on most 32-bit architectures a 10 byte message will + * take up 14 bytes of message buffer space. + * + * @return If NULL is returned, then the message buffer cannot be created + * because there is insufficient heap memory available for FreeRTOS to allocate + * the message buffer data structures and storage area. A non-NULL value being + * returned indicates that the message buffer has been created successfully - + * the returned value should be stored as the handle to the created message + * buffer. + * + * Example use: + *
+ *
+ * void vAFunction( void )
+ * {
+ * MessageBufferHandle_t xMessageBuffer;
+ * const size_t xMessageBufferSizeBytes = 100;
+ *
+ *  // Create a message buffer that can hold 100 bytes.  The memory used to hold
+ *  // both the message buffer structure and the messages themselves is allocated
+ *  // dynamically.  Each message added to the buffer consumes an additional 4
+ *  // bytes which are used to hold the lengh of the message.
+ *  xMessageBuffer = xMessageBufferCreate( xMessageBufferSizeBytes );
+ *
+ *  if( xMessageBuffer == NULL )
+ *  {
+ *      // There was not enough heap memory space available to create the
+ *      // message buffer.
+ *  }
+ *  else
+ *  {
+ *      // The message buffer was created successfully and can now be used.
+ *  }
+ *
+ * 
+ * \defgroup xMessageBufferCreate xMessageBufferCreate + * \ingroup MessageBufferManagement + */ +#define xMessageBufferCreate( xBufferSizeBytes ) \ + ( MessageBufferHandle_t ) xStreamBufferGenericCreate( xBufferSizeBytes, ( size_t ) 0, pdTRUE ) + +/** + * message_buffer.h + * + *
+ * MessageBufferHandle_t xMessageBufferCreateStatic( size_t xBufferSizeBytes,
+ *                                                uint8_t *pucMessageBufferStorageArea,
+ *                                                StaticMessageBuffer_t *pxStaticMessageBuffer );
+ * 
+ * Creates a new message buffer using statically allocated memory. See + * xMessageBufferCreate() for a version that uses dynamically allocated memory. + * + * @param xBufferSizeBytes The size, in bytes, of the buffer pointed to by the + * pucMessageBufferStorageArea parameter. When a message is written to the + * message buffer an additional sizeof( size_t ) bytes are also written to store + * the message's length. sizeof( size_t ) is typically 4 bytes on a 32-bit + * architecture, so on most 32-bit architecture a 10 byte message will take up + * 14 bytes of message buffer space. The maximum number of bytes that can be + * stored in the message buffer is actually (xBufferSizeBytes - 1). + * + * @param pucMessageBufferStorageArea Must point to a uint8_t array that is at + * least xBufferSizeBytes + 1 big. This is the array to which messages are + * copied when they are written to the message buffer. + * + * @param pxStaticMessageBuffer Must point to a variable of type + * StaticMessageBuffer_t, which will be used to hold the message buffer's data + * structure. + * + * @return If the message buffer is created successfully then a handle to the + * created message buffer is returned. If either pucMessageBufferStorageArea or + * pxStaticmessageBuffer are NULL then NULL is returned. + * + * Example use: + *
+ *
+ * // Used to dimension the array used to hold the messages.  The available space
+ * // will actually be one less than this, so 999.
+ #define STORAGE_SIZE_BYTES 1000
+ *
+ * // Defines the memory that will actually hold the messages within the message
+ * // buffer.
+ * static uint8_t ucStorageBuffer[ STORAGE_SIZE_BYTES ];
+ *
+ * // The variable used to hold the message buffer structure.
+ * StaticMessageBuffer_t xMessageBufferStruct;
+ *
+ * void MyFunction( void )
+ * {
+ * MessageBufferHandle_t xMessageBuffer;
+ *
+ *  xMessageBuffer = xMessageBufferCreateStatic( sizeof( ucBufferStorage ),
+ *                                               ucBufferStorage,
+ *                                               &xMessageBufferStruct );
+ *
+ *  // As neither the pucMessageBufferStorageArea or pxStaticMessageBuffer
+ *  // parameters were NULL, xMessageBuffer will not be NULL, and can be used to
+ *  // reference the created message buffer in other message buffer API calls.
+ *
+ *  // Other code that uses the message buffer can go here.
+ * }
+ *
+ * 
+ * \defgroup xMessageBufferCreateStatic xMessageBufferCreateStatic + * \ingroup MessageBufferManagement + */ +#define xMessageBufferCreateStatic( xBufferSizeBytes, pucMessageBufferStorageArea, pxStaticMessageBuffer ) \ + ( MessageBufferHandle_t ) xStreamBufferGenericCreateStatic( xBufferSizeBytes, 0, pdTRUE, pucMessageBufferStorageArea, pxStaticMessageBuffer ) + +/** + * message_buffer.h + * + *
+ * size_t xMessageBufferSend( MessageBufferHandle_t xMessageBuffer,
+ *                         const void *pvTxData,
+ *                         size_t xDataLengthBytes,
+ *                         TickType_t xTicksToWait );
+ * 
+ * + * Sends a discrete message to the message buffer. The message can be any + * length that fits within the buffer's free space, and is copied into the + * buffer. + * + * ***NOTE***: Uniquely among FreeRTOS objects, the stream buffer + * implementation (so also the message buffer implementation, as message buffers + * are built on top of stream buffers) assumes there is only one task or + * interrupt that will write to the buffer (the writer), and only one task or + * interrupt that will read from the buffer (the reader). It is safe for the + * writer and reader to be different tasks or interrupts, but, unlike other + * FreeRTOS objects, it is not safe to have multiple different writers or + * multiple different readers. If there are to be multiple different writers + * then the application writer must place each call to a writing API function + * (such as xMessageBufferSend()) inside a critical section and set the send + * block time to 0. Likewise, if there are to be multiple different readers + * then the application writer must place each call to a reading API function + * (such as xMessageBufferRead()) inside a critical section and set the receive + * block time to 0. + * + * Use xMessageBufferSend() to write to a message buffer from a task. Use + * xMessageBufferSendFromISR() to write to a message buffer from an interrupt + * service routine (ISR). + * + * @param xMessageBuffer The handle of the message buffer to which a message is + * being sent. + * + * @param pvTxData A pointer to the message that is to be copied into the + * message buffer. + * + * @param xDataLengthBytes The length of the message. That is, the number of + * bytes to copy from pvTxData into the message buffer. When a message is + * written to the message buffer an additional sizeof( size_t ) bytes are also + * written to store the message's length. sizeof( size_t ) is typically 4 bytes + * on a 32-bit architecture, so on most 32-bit architecture setting + * xDataLengthBytes to 20 will reduce the free space in the message buffer by 24 + * bytes (20 bytes of message data and 4 bytes to hold the message length). + * + * @param xTicksToWait The maximum amount of time the calling task should remain + * in the Blocked state to wait for enough space to become available in the + * message buffer, should the message buffer have insufficient space when + * xMessageBufferSend() is called. The calling task will never block if + * xTicksToWait is zero. The block time is specified in tick periods, so the + * absolute time it represents is dependent on the tick frequency. The macro + * pdMS_TO_TICKS() can be used to convert a time specified in milliseconds into + * a time specified in ticks. Setting xTicksToWait to portMAX_DELAY will cause + * the task to wait indefinitely (without timing out), provided + * INCLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h. Tasks do not use any + * CPU time when they are in the Blocked state. + * + * @return The number of bytes written to the message buffer. If the call to + * xMessageBufferSend() times out before there was enough space to write the + * message into the message buffer then zero is returned. If the call did not + * time out then xDataLengthBytes is returned. + * + * Example use: + *
+ * void vAFunction( MessageBufferHandle_t xMessageBuffer )
+ * {
+ * size_t xBytesSent;
+ * uint8_t ucArrayToSend[] = { 0, 1, 2, 3 };
+ * char *pcStringToSend = "String to send";
+ * const TickType_t x100ms = pdMS_TO_TICKS( 100 );
+ *
+ *  // Send an array to the message buffer, blocking for a maximum of 100ms to
+ *  // wait for enough space to be available in the message buffer.
+ *  xBytesSent = xMessageBufferSend( xMessageBuffer, ( void * ) ucArrayToSend, sizeof( ucArrayToSend ), x100ms );
+ *
+ *  if( xBytesSent != sizeof( ucArrayToSend ) )
+ *  {
+ *      // The call to xMessageBufferSend() times out before there was enough
+ *      // space in the buffer for the data to be written.
+ *  }
+ *
+ *  // Send the string to the message buffer.  Return immediately if there is
+ *  // not enough space in the buffer.
+ *  xBytesSent = xMessageBufferSend( xMessageBuffer, ( void * ) pcStringToSend, strlen( pcStringToSend ), 0 );
+ *
+ *  if( xBytesSent != strlen( pcStringToSend ) )
+ *  {
+ *      // The string could not be added to the message buffer because there was
+ *      // not enough free space in the buffer.
+ *  }
+ * }
+ * 
+ * \defgroup xMessageBufferSend xMessageBufferSend + * \ingroup MessageBufferManagement + */ +#define xMessageBufferSend( xMessageBuffer, pvTxData, xDataLengthBytes, xTicksToWait ) \ + xStreamBufferSend( ( StreamBufferHandle_t ) xMessageBuffer, pvTxData, xDataLengthBytes, xTicksToWait ) + +/** + * message_buffer.h + * + *
+ * size_t xMessageBufferSendFromISR( MessageBufferHandle_t xMessageBuffer,
+ *                                const void *pvTxData,
+ *                                size_t xDataLengthBytes,
+ *                                BaseType_t *pxHigherPriorityTaskWoken );
+ * 
+ * + * Interrupt safe version of the API function that sends a discrete message to + * the message buffer. The message can be any length that fits within the + * buffer's free space, and is copied into the buffer. + * + * ***NOTE***: Uniquely among FreeRTOS objects, the stream buffer + * implementation (so also the message buffer implementation, as message buffers + * are built on top of stream buffers) assumes there is only one task or + * interrupt that will write to the buffer (the writer), and only one task or + * interrupt that will read from the buffer (the reader). It is safe for the + * writer and reader to be different tasks or interrupts, but, unlike other + * FreeRTOS objects, it is not safe to have multiple different writers or + * multiple different readers. If there are to be multiple different writers + * then the application writer must place each call to a writing API function + * (such as xMessageBufferSend()) inside a critical section and set the send + * block time to 0. Likewise, if there are to be multiple different readers + * then the application writer must place each call to a reading API function + * (such as xMessageBufferRead()) inside a critical section and set the receive + * block time to 0. + * + * Use xMessageBufferSend() to write to a message buffer from a task. Use + * xMessageBufferSendFromISR() to write to a message buffer from an interrupt + * service routine (ISR). + * + * @param xMessageBuffer The handle of the message buffer to which a message is + * being sent. + * + * @param pvTxData A pointer to the message that is to be copied into the + * message buffer. + * + * @param xDataLengthBytes The length of the message. That is, the number of + * bytes to copy from pvTxData into the message buffer. When a message is + * written to the message buffer an additional sizeof( size_t ) bytes are also + * written to store the message's length. sizeof( size_t ) is typically 4 bytes + * on a 32-bit architecture, so on most 32-bit architecture setting + * xDataLengthBytes to 20 will reduce the free space in the message buffer by 24 + * bytes (20 bytes of message data and 4 bytes to hold the message length). + * + * @param pxHigherPriorityTaskWoken It is possible that a message buffer will + * have a task blocked on it waiting for data. Calling + * xMessageBufferSendFromISR() can make data available, and so cause a task that + * was waiting for data to leave the Blocked state. If calling + * xMessageBufferSendFromISR() causes a task to leave the Blocked state, and the + * unblocked task has a priority higher than the currently executing task (the + * task that was interrupted), then, internally, xMessageBufferSendFromISR() + * will set *pxHigherPriorityTaskWoken to pdTRUE. If + * xMessageBufferSendFromISR() sets this value to pdTRUE, then normally a + * context switch should be performed before the interrupt is exited. This will + * ensure that the interrupt returns directly to the highest priority Ready + * state task. *pxHigherPriorityTaskWoken should be set to pdFALSE before it + * is passed into the function. See the code example below for an example. + * + * @return The number of bytes actually written to the message buffer. If the + * message buffer didn't have enough free space for the message to be stored + * then 0 is returned, otherwise xDataLengthBytes is returned. + * + * Example use: + *
+ * // A message buffer that has already been created.
+ * MessageBufferHandle_t xMessageBuffer;
+ *
+ * void vAnInterruptServiceRoutine( void )
+ * {
+ * size_t xBytesSent;
+ * char *pcStringToSend = "String to send";
+ * BaseType_t xHigherPriorityTaskWoken = pdFALSE; // Initialised to pdFALSE.
+ *
+ *  // Attempt to send the string to the message buffer.
+ *  xBytesSent = xMessageBufferSendFromISR( xMessageBuffer,
+ *                                          ( void * ) pcStringToSend,
+ *                                          strlen( pcStringToSend ),
+ *                                          &xHigherPriorityTaskWoken );
+ *
+ *  if( xBytesSent != strlen( pcStringToSend ) )
+ *  {
+ *      // The string could not be added to the message buffer because there was
+ *      // not enough free space in the buffer.
+ *  }
+ *
+ *  // If xHigherPriorityTaskWoken was set to pdTRUE inside
+ *  // xMessageBufferSendFromISR() then a task that has a priority above the
+ *  // priority of the currently executing task was unblocked and a context
+ *  // switch should be performed to ensure the ISR returns to the unblocked
+ *  // task.  In most FreeRTOS ports this is done by simply passing
+ *  // xHigherPriorityTaskWoken into portYIELD_FROM_ISR(), which will test the
+ *  // variables value, and perform the context switch if necessary.  Check the
+ *  // documentation for the port in use for port specific instructions.
+ *  portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
+ * }
+ * 
+ * \defgroup xMessageBufferSendFromISR xMessageBufferSendFromISR + * \ingroup MessageBufferManagement + */ +#define xMessageBufferSendFromISR( xMessageBuffer, pvTxData, xDataLengthBytes, pxHigherPriorityTaskWoken ) \ + xStreamBufferSendFromISR( ( StreamBufferHandle_t ) xMessageBuffer, pvTxData, xDataLengthBytes, pxHigherPriorityTaskWoken ) + +/** + * message_buffer.h + * + *
+ * size_t xMessageBufferReceive( MessageBufferHandle_t xMessageBuffer,
+ *                            void *pvRxData,
+ *                            size_t xBufferLengthBytes,
+ *                            TickType_t xTicksToWait );
+ * 
+ * + * Receives a discrete message from a message buffer. Messages can be of + * variable length and are copied out of the buffer. + * + * ***NOTE***: Uniquely among FreeRTOS objects, the stream buffer + * implementation (so also the message buffer implementation, as message buffers + * are built on top of stream buffers) assumes there is only one task or + * interrupt that will write to the buffer (the writer), and only one task or + * interrupt that will read from the buffer (the reader). It is safe for the + * writer and reader to be different tasks or interrupts, but, unlike other + * FreeRTOS objects, it is not safe to have multiple different writers or + * multiple different readers. If there are to be multiple different writers + * then the application writer must place each call to a writing API function + * (such as xMessageBufferSend()) inside a critical section and set the send + * block time to 0. Likewise, if there are to be multiple different readers + * then the application writer must place each call to a reading API function + * (such as xMessageBufferRead()) inside a critical section and set the receive + * block time to 0. + * + * Use xMessageBufferReceive() to read from a message buffer from a task. Use + * xMessageBufferReceiveFromISR() to read from a message buffer from an + * interrupt service routine (ISR). + * + * @param xMessageBuffer The handle of the message buffer from which a message + * is being received. + * + * @param pvRxData A pointer to the buffer into which the received message is + * to be copied. + * + * @param xBufferLengthBytes The length of the buffer pointed to by the pvRxData + * parameter. This sets the maximum length of the message that can be received. + * If xBufferLengthBytes is too small to hold the next message then the message + * will be left in the message buffer and 0 will be returned. + * + * @param xTicksToWait The maximum amount of time the task should remain in the + * Blocked state to wait for a message, should the message buffer be empty. + * xMessageBufferReceive() will return immediately if xTicksToWait is zero and + * the message buffer is empty. The block time is specified in tick periods, so + * the absolute time it represents is dependent on the tick frequency. The + * macro pdMS_TO_TICKS() can be used to convert a time specified in milliseconds + * into a time specified in ticks. Setting xTicksToWait to portMAX_DELAY will + * cause the task to wait indefinitely (without timing out), provided + * INCLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h. Tasks do not use any + * CPU time when they are in the Blocked state. + * + * @return The length, in bytes, of the message read from the message buffer, if + * any. If xMessageBufferReceive() times out before a message became available + * then zero is returned. If the length of the message is greater than + * xBufferLengthBytes then the message will be left in the message buffer and + * zero is returned. + * + * Example use: + *
+ * void vAFunction( MessageBuffer_t xMessageBuffer )
+ * {
+ * uint8_t ucRxData[ 20 ];
+ * size_t xReceivedBytes;
+ * const TickType_t xBlockTime = pdMS_TO_TICKS( 20 );
+ *
+ *  // Receive the next message from the message buffer.  Wait in the Blocked
+ *  // state (so not using any CPU processing time) for a maximum of 100ms for
+ *  // a message to become available.
+ *  xReceivedBytes = xMessageBufferReceive( xMessageBuffer,
+ *                                          ( void * ) ucRxData,
+ *                                          sizeof( ucRxData ),
+ *                                          xBlockTime );
+ *
+ *  if( xReceivedBytes > 0 )
+ *  {
+ *      // A ucRxData contains a message that is xReceivedBytes long.  Process
+ *      // the message here....
+ *  }
+ * }
+ * 
+ * \defgroup xMessageBufferReceive xMessageBufferReceive + * \ingroup MessageBufferManagement + */ +#define xMessageBufferReceive( xMessageBuffer, pvRxData, xBufferLengthBytes, xTicksToWait ) \ + xStreamBufferReceive( ( StreamBufferHandle_t ) xMessageBuffer, pvRxData, xBufferLengthBytes, xTicksToWait ) + + +/** + * message_buffer.h + * + *
+ * size_t xMessageBufferReceiveFromISR( MessageBufferHandle_t xMessageBuffer,
+ *                                   void *pvRxData,
+ *                                   size_t xBufferLengthBytes,
+ *                                   BaseType_t *pxHigherPriorityTaskWoken );
+ * 
+ * + * An interrupt safe version of the API function that receives a discrete + * message from a message buffer. Messages can be of variable length and are + * copied out of the buffer. + * + * ***NOTE***: Uniquely among FreeRTOS objects, the stream buffer + * implementation (so also the message buffer implementation, as message buffers + * are built on top of stream buffers) assumes there is only one task or + * interrupt that will write to the buffer (the writer), and only one task or + * interrupt that will read from the buffer (the reader). It is safe for the + * writer and reader to be different tasks or interrupts, but, unlike other + * FreeRTOS objects, it is not safe to have multiple different writers or + * multiple different readers. If there are to be multiple different writers + * then the application writer must place each call to a writing API function + * (such as xMessageBufferSend()) inside a critical section and set the send + * block time to 0. Likewise, if there are to be multiple different readers + * then the application writer must place each call to a reading API function + * (such as xMessageBufferRead()) inside a critical section and set the receive + * block time to 0. + * + * Use xMessageBufferReceive() to read from a message buffer from a task. Use + * xMessageBufferReceiveFromISR() to read from a message buffer from an + * interrupt service routine (ISR). + * + * @param xMessageBuffer The handle of the message buffer from which a message + * is being received. + * + * @param pvRxData A pointer to the buffer into which the received message is + * to be copied. + * + * @param xBufferLengthBytes The length of the buffer pointed to by the pvRxData + * parameter. This sets the maximum length of the message that can be received. + * If xBufferLengthBytes is too small to hold the next message then the message + * will be left in the message buffer and 0 will be returned. + * + * @param pxHigherPriorityTaskWoken It is possible that a message buffer will + * have a task blocked on it waiting for space to become available. Calling + * xMessageBufferReceiveFromISR() can make space available, and so cause a task + * that is waiting for space to leave the Blocked state. If calling + * xMessageBufferReceiveFromISR() causes a task to leave the Blocked state, and + * the unblocked task has a priority higher than the currently executing task + * (the task that was interrupted), then, internally, + * xMessageBufferReceiveFromISR() will set *pxHigherPriorityTaskWoken to pdTRUE. + * If xMessageBufferReceiveFromISR() sets this value to pdTRUE, then normally a + * context switch should be performed before the interrupt is exited. That will + * ensure the interrupt returns directly to the highest priority Ready state + * task. *pxHigherPriorityTaskWoken should be set to pdFALSE before it is + * passed into the function. See the code example below for an example. + * + * @return The length, in bytes, of the message read from the message buffer, if + * any. + * + * Example use: + *
+ * // A message buffer that has already been created.
+ * MessageBuffer_t xMessageBuffer;
+ *
+ * void vAnInterruptServiceRoutine( void )
+ * {
+ * uint8_t ucRxData[ 20 ];
+ * size_t xReceivedBytes;
+ * BaseType_t xHigherPriorityTaskWoken = pdFALSE;  // Initialised to pdFALSE.
+ *
+ *  // Receive the next message from the message buffer.
+ *  xReceivedBytes = xMessageBufferReceiveFromISR( xMessageBuffer,
+ *                                                ( void * ) ucRxData,
+ *                                                sizeof( ucRxData ),
+ *                                                &xHigherPriorityTaskWoken );
+ *
+ *  if( xReceivedBytes > 0 )
+ *  {
+ *      // A ucRxData contains a message that is xReceivedBytes long.  Process
+ *      // the message here....
+ *  }
+ *
+ *  // If xHigherPriorityTaskWoken was set to pdTRUE inside
+ *  // xMessageBufferReceiveFromISR() then a task that has a priority above the
+ *  // priority of the currently executing task was unblocked and a context
+ *  // switch should be performed to ensure the ISR returns to the unblocked
+ *  // task.  In most FreeRTOS ports this is done by simply passing
+ *  // xHigherPriorityTaskWoken into portYIELD_FROM_ISR(), which will test the
+ *  // variables value, and perform the context switch if necessary.  Check the
+ *  // documentation for the port in use for port specific instructions.
+ *  portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
+ * }
+ * 
+ * \defgroup xMessageBufferReceiveFromISR xMessageBufferReceiveFromISR + * \ingroup MessageBufferManagement + */ +#define xMessageBufferReceiveFromISR( xMessageBuffer, pvRxData, xBufferLengthBytes, pxHigherPriorityTaskWoken ) \ + xStreamBufferReceiveFromISR( ( StreamBufferHandle_t ) xMessageBuffer, pvRxData, xBufferLengthBytes, pxHigherPriorityTaskWoken ) + +/** + * message_buffer.h + * + *
+ * void vMessageBufferDelete( MessageBufferHandle_t xMessageBuffer );
+ * 
+ * + * Deletes a message buffer that was previously created using a call to + * xMessageBufferCreate() or xMessageBufferCreateStatic(). If the message + * buffer was created using dynamic memory (that is, by xMessageBufferCreate()), + * then the allocated memory is freed. + * + * A message buffer handle must not be used after the message buffer has been + * deleted. + * + * @param xMessageBuffer The handle of the message buffer to be deleted. + * + */ +#define vMessageBufferDelete( xMessageBuffer ) \ + vStreamBufferDelete( ( StreamBufferHandle_t ) xMessageBuffer ) + +/** + * message_buffer.h + *
+ * BaseType_t xMessageBufferIsFull( MessageBufferHandle_t xMessageBuffer ) );
+ * 
+ * + * Tests to see if a message buffer is full. A message buffer is full if it + * cannot accept any more messages, of any size, until space is made available + * by a message being removed from the message buffer. + * + * @param xMessageBuffer The handle of the message buffer being queried. + * + * @return If the message buffer referenced by xMessageBuffer is full then + * pdTRUE is returned. Otherwise pdFALSE is returned. + */ +#define xMessageBufferIsFull( xMessageBuffer ) \ + xStreamBufferIsFull( ( StreamBufferHandle_t ) xMessageBuffer ) + +/** + * message_buffer.h + *
+ * BaseType_t xMessageBufferIsEmpty( MessageBufferHandle_t xMessageBuffer ) );
+ * 
+ * + * Tests to see if a message buffer is empty (does not contain any messages). + * + * @param xMessageBuffer The handle of the message buffer being queried. + * + * @return If the message buffer referenced by xMessageBuffer is empty then + * pdTRUE is returned. Otherwise pdFALSE is returned. + * + */ +#define xMessageBufferIsEmpty( xMessageBuffer ) \ + xStreamBufferIsEmpty( ( StreamBufferHandle_t ) xMessageBuffer ) + +/** + * message_buffer.h + *
+ * BaseType_t xMessageBufferReset( MessageBufferHandle_t xMessageBuffer );
+ * 
+ * + * Resets a message buffer to its initial empty state, discarding any message it + * contained. + * + * A message buffer can only be reset if there are no tasks blocked on it. + * + * @param xMessageBuffer The handle of the message buffer being reset. + * + * @return If the message buffer was reset then pdPASS is returned. If the + * message buffer could not be reset because either there was a task blocked on + * the message queue to wait for space to become available, or to wait for a + * a message to be available, then pdFAIL is returned. + * + * \defgroup xMessageBufferReset xMessageBufferReset + * \ingroup MessageBufferManagement + */ +#define xMessageBufferReset( xMessageBuffer ) \ + xStreamBufferReset( ( StreamBufferHandle_t ) xMessageBuffer ) + + +/** + * message_buffer.h + *
+ * size_t xMessageBufferSpaceAvailable( MessageBufferHandle_t xMessageBuffer ) );
+ * 
+ * Returns the number of bytes of free space in the message buffer. + * + * @param xMessageBuffer The handle of the message buffer being queried. + * + * @return The number of bytes that can be written to the message buffer before + * the message buffer would be full. When a message is written to the message + * buffer an additional sizeof( size_t ) bytes are also written to store the + * message's length. sizeof( size_t ) is typically 4 bytes on a 32-bit + * architecture, so if xMessageBufferSpacesAvailable() returns 10, then the size + * of the largest message that can be written to the message buffer is 6 bytes. + * + * \defgroup xMessageBufferSpaceAvailable xMessageBufferSpaceAvailable + * \ingroup MessageBufferManagement + */ +#define xMessageBufferSpaceAvailable( xMessageBuffer ) \ + xStreamBufferSpacesAvailable( ( StreamBufferHandle_t ) xMessageBuffer ) +#define xMessageBufferSpacesAvailable( xMessageBuffer ) \ + xStreamBufferSpacesAvailable( ( StreamBufferHandle_t ) xMessageBuffer ) /* Corrects typo in original macro name. */ + +/** + * message_buffer.h + *
+ * size_t xMessageBufferNextLengthBytes( MessageBufferHandle_t xMessageBuffer ) );
+ * 
+ * Returns the length (in bytes) of the next message in a message buffer. + * Useful if xMessageBufferReceive() returned 0 because the size of the buffer + * passed into xMessageBufferReceive() was too small to hold the next message. + * + * @param xMessageBuffer The handle of the message buffer being queried. + * + * @return The length (in bytes) of the next message in the message buffer, or 0 + * if the message buffer is empty. + * + * \defgroup xMessageBufferNextLengthBytes xMessageBufferNextLengthBytes + * \ingroup MessageBufferManagement + */ +#define xMessageBufferNextLengthBytes( xMessageBuffer ) \ + xStreamBufferNextMessageLengthBytes( ( StreamBufferHandle_t ) xMessageBuffer ) PRIVILEGED_FUNCTION; + +/** + * message_buffer.h + * + *
+ * BaseType_t xMessageBufferSendCompletedFromISR( MessageBufferHandle_t xStreamBuffer, BaseType_t *pxHigherPriorityTaskWoken );
+ * 
+ * + * For advanced users only. + * + * The sbSEND_COMPLETED() macro is called from within the FreeRTOS APIs when + * data is sent to a message buffer or stream buffer. If there was a task that + * was blocked on the message or stream buffer waiting for data to arrive then + * the sbSEND_COMPLETED() macro sends a notification to the task to remove it + * from the Blocked state. xMessageBufferSendCompletedFromISR() does the same + * thing. It is provided to enable application writers to implement their own + * version of sbSEND_COMPLETED(), and MUST NOT BE USED AT ANY OTHER TIME. + * + * See the example implemented in FreeRTOS/Demo/Minimal/MessageBufferAMP.c for + * additional information. + * + * @param xStreamBuffer The handle of the stream buffer to which data was + * written. + * + * @param pxHigherPriorityTaskWoken *pxHigherPriorityTaskWoken should be + * initialised to pdFALSE before it is passed into + * xMessageBufferSendCompletedFromISR(). If calling + * xMessageBufferSendCompletedFromISR() removes a task from the Blocked state, + * and the task has a priority above the priority of the currently running task, + * then *pxHigherPriorityTaskWoken will get set to pdTRUE indicating that a + * context switch should be performed before exiting the ISR. + * + * @return If a task was removed from the Blocked state then pdTRUE is returned. + * Otherwise pdFALSE is returned. + * + * \defgroup xMessageBufferSendCompletedFromISR xMessageBufferSendCompletedFromISR + * \ingroup StreamBufferManagement + */ +#define xMessageBufferSendCompletedFromISR( xMessageBuffer, pxHigherPriorityTaskWoken ) \ + xStreamBufferSendCompletedFromISR( ( StreamBufferHandle_t ) xMessageBuffer, pxHigherPriorityTaskWoken ) + +/** + * message_buffer.h + * + *
+ * BaseType_t xMessageBufferReceiveCompletedFromISR( MessageBufferHandle_t xStreamBuffer, BaseType_t *pxHigherPriorityTaskWoken );
+ * 
+ * + * For advanced users only. + * + * The sbRECEIVE_COMPLETED() macro is called from within the FreeRTOS APIs when + * data is read out of a message buffer or stream buffer. If there was a task + * that was blocked on the message or stream buffer waiting for data to arrive + * then the sbRECEIVE_COMPLETED() macro sends a notification to the task to + * remove it from the Blocked state. xMessageBufferReceiveCompletedFromISR() + * does the same thing. It is provided to enable application writers to + * implement their own version of sbRECEIVE_COMPLETED(), and MUST NOT BE USED AT + * ANY OTHER TIME. + * + * See the example implemented in FreeRTOS/Demo/Minimal/MessageBufferAMP.c for + * additional information. + * + * @param xStreamBuffer The handle of the stream buffer from which data was + * read. + * + * @param pxHigherPriorityTaskWoken *pxHigherPriorityTaskWoken should be + * initialised to pdFALSE before it is passed into + * xMessageBufferReceiveCompletedFromISR(). If calling + * xMessageBufferReceiveCompletedFromISR() removes a task from the Blocked state, + * and the task has a priority above the priority of the currently running task, + * then *pxHigherPriorityTaskWoken will get set to pdTRUE indicating that a + * context switch should be performed before exiting the ISR. + * + * @return If a task was removed from the Blocked state then pdTRUE is returned. + * Otherwise pdFALSE is returned. + * + * \defgroup xMessageBufferReceiveCompletedFromISR xMessageBufferReceiveCompletedFromISR + * \ingroup StreamBufferManagement + */ +#define xMessageBufferReceiveCompletedFromISR( xMessageBuffer, pxHigherPriorityTaskWoken ) \ + xStreamBufferReceiveCompletedFromISR( ( StreamBufferHandle_t ) xMessageBuffer, pxHigherPriorityTaskWoken ) + +/* *INDENT-OFF* */ +#if defined( __cplusplus ) + } /* extern "C" */ +#endif +/* *INDENT-ON* */ + +#endif /* !defined( FREERTOS_MESSAGE_BUFFER_H ) */ diff --git a/RTOS/FreeRTOS/Source/include/mpu_prototypes.h b/RTOS/FreeRTOS/Source/include/mpu_prototypes.h new file mode 100644 index 0000000..1fc5dd3 --- /dev/null +++ b/RTOS/FreeRTOS/Source/include/mpu_prototypes.h @@ -0,0 +1,263 @@ +/* + * FreeRTOS Kernel V10.4.1 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * https://www.FreeRTOS.org + * https://github.com/FreeRTOS + * + */ + +/* + * When the MPU is used the standard (non MPU) API functions are mapped to + * equivalents that start "MPU_", the prototypes for which are defined in this + * header files. This will cause the application code to call the MPU_ version + * which wraps the non-MPU version with privilege promoting then demoting code, + * so the kernel code always runs will full privileges. + */ + + +#ifndef MPU_PROTOTYPES_H +#define MPU_PROTOTYPES_H + +/* MPU versions of tasks.h API functions. */ +BaseType_t MPU_xTaskCreate( TaskFunction_t pxTaskCode, + const char * const pcName, + const uint16_t usStackDepth, + void * const pvParameters, + UBaseType_t uxPriority, + TaskHandle_t * const pxCreatedTask ) FREERTOS_SYSTEM_CALL; +TaskHandle_t MPU_xTaskCreateStatic( TaskFunction_t pxTaskCode, + const char * const pcName, + const uint32_t ulStackDepth, + void * const pvParameters, + UBaseType_t uxPriority, + StackType_t * const puxStackBuffer, + StaticTask_t * const pxTaskBuffer ) FREERTOS_SYSTEM_CALL; +BaseType_t MPU_xTaskCreateRestricted( const TaskParameters_t * const pxTaskDefinition, + TaskHandle_t * pxCreatedTask ) FREERTOS_SYSTEM_CALL; +BaseType_t MPU_xTaskCreateRestrictedStatic( const TaskParameters_t * const pxTaskDefinition, + TaskHandle_t * pxCreatedTask ) FREERTOS_SYSTEM_CALL; +void MPU_vTaskAllocateMPURegions( TaskHandle_t xTask, + const MemoryRegion_t * const pxRegions ) FREERTOS_SYSTEM_CALL; +void MPU_vTaskDelete( TaskHandle_t xTaskToDelete ) FREERTOS_SYSTEM_CALL; +void MPU_vTaskDelay( const TickType_t xTicksToDelay ) FREERTOS_SYSTEM_CALL; +void MPU_vTaskDelayUntil( TickType_t * const pxPreviousWakeTime, + const TickType_t xTimeIncrement ) FREERTOS_SYSTEM_CALL; +BaseType_t MPU_xTaskAbortDelay( TaskHandle_t xTask ) FREERTOS_SYSTEM_CALL; +UBaseType_t MPU_uxTaskPriorityGet( const TaskHandle_t xTask ) FREERTOS_SYSTEM_CALL; +eTaskState MPU_eTaskGetState( TaskHandle_t xTask ) FREERTOS_SYSTEM_CALL; +void MPU_vTaskGetInfo( TaskHandle_t xTask, + TaskStatus_t * pxTaskStatus, + BaseType_t xGetFreeStackSpace, + eTaskState eState ) FREERTOS_SYSTEM_CALL; +void MPU_vTaskPrioritySet( TaskHandle_t xTask, + UBaseType_t uxNewPriority ) FREERTOS_SYSTEM_CALL; +void MPU_vTaskSuspend( TaskHandle_t xTaskToSuspend ) FREERTOS_SYSTEM_CALL; +void MPU_vTaskResume( TaskHandle_t xTaskToResume ) FREERTOS_SYSTEM_CALL; +void MPU_vTaskStartScheduler( void ) FREERTOS_SYSTEM_CALL; +void MPU_vTaskSuspendAll( void ) FREERTOS_SYSTEM_CALL; +BaseType_t MPU_xTaskResumeAll( void ) FREERTOS_SYSTEM_CALL; +TickType_t MPU_xTaskGetTickCount( void ) FREERTOS_SYSTEM_CALL; +UBaseType_t MPU_uxTaskGetNumberOfTasks( void ) FREERTOS_SYSTEM_CALL; +char * MPU_pcTaskGetName( TaskHandle_t xTaskToQuery ) FREERTOS_SYSTEM_CALL; +TaskHandle_t MPU_xTaskGetHandle( const char * pcNameToQuery ) FREERTOS_SYSTEM_CALL; +UBaseType_t MPU_uxTaskGetStackHighWaterMark( TaskHandle_t xTask ) FREERTOS_SYSTEM_CALL; +configSTACK_DEPTH_TYPE MPU_uxTaskGetStackHighWaterMark2( TaskHandle_t xTask ) FREERTOS_SYSTEM_CALL; +void MPU_vTaskSetApplicationTaskTag( TaskHandle_t xTask, + TaskHookFunction_t pxHookFunction ) FREERTOS_SYSTEM_CALL; +TaskHookFunction_t MPU_xTaskGetApplicationTaskTag( TaskHandle_t xTask ) FREERTOS_SYSTEM_CALL; +void MPU_vTaskSetThreadLocalStoragePointer( TaskHandle_t xTaskToSet, + BaseType_t xIndex, + void * pvValue ) FREERTOS_SYSTEM_CALL; +void * MPU_pvTaskGetThreadLocalStoragePointer( TaskHandle_t xTaskToQuery, + BaseType_t xIndex ) FREERTOS_SYSTEM_CALL; +BaseType_t MPU_xTaskCallApplicationTaskHook( TaskHandle_t xTask, + void * pvParameter ) FREERTOS_SYSTEM_CALL; +TaskHandle_t MPU_xTaskGetIdleTaskHandle( void ) FREERTOS_SYSTEM_CALL; +UBaseType_t MPU_uxTaskGetSystemState( TaskStatus_t * const pxTaskStatusArray, + const UBaseType_t uxArraySize, + uint32_t * const pulTotalRunTime ) FREERTOS_SYSTEM_CALL; +uint32_t MPU_ulTaskGetIdleRunTimeCounter( void ) FREERTOS_SYSTEM_CALL; +void MPU_vTaskList( char * pcWriteBuffer ) FREERTOS_SYSTEM_CALL; +void MPU_vTaskGetRunTimeStats( char * pcWriteBuffer ) FREERTOS_SYSTEM_CALL; +BaseType_t MPU_xTaskGenericNotify( TaskHandle_t xTaskToNotify, + UBaseType_t uxIndexToNotify, + uint32_t ulValue, + eNotifyAction eAction, + uint32_t * pulPreviousNotificationValue ) FREERTOS_SYSTEM_CALL; +BaseType_t MPU_xTaskGenericNotifyWait( UBaseType_t uxIndexToWaitOn, + uint32_t ulBitsToClearOnEntry, + uint32_t ulBitsToClearOnExit, + uint32_t * pulNotificationValue, + TickType_t xTicksToWait ) FREERTOS_SYSTEM_CALL; +uint32_t MPU_ulTaskGenericNotifyTake( UBaseType_t uxIndexToWaitOn, + BaseType_t xClearCountOnExit, + TickType_t xTicksToWait ) FREERTOS_SYSTEM_CALL; +BaseType_t MPU_xTaskGenericNotifyStateClear( TaskHandle_t xTask, + UBaseType_t uxIndexToClear ) FREERTOS_SYSTEM_CALL; +uint32_t MPU_ulTaskGenericNotifyValueClear( TaskHandle_t xTask, + UBaseType_t uxIndexToClear, + uint32_t ulBitsToClear ) FREERTOS_SYSTEM_CALL; +BaseType_t MPU_xTaskIncrementTick( void ) FREERTOS_SYSTEM_CALL; +TaskHandle_t MPU_xTaskGetCurrentTaskHandle( void ) FREERTOS_SYSTEM_CALL; +void MPU_vTaskSetTimeOutState( TimeOut_t * const pxTimeOut ) FREERTOS_SYSTEM_CALL; +BaseType_t MPU_xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut, + TickType_t * const pxTicksToWait ) FREERTOS_SYSTEM_CALL; +void MPU_vTaskMissedYield( void ) FREERTOS_SYSTEM_CALL; +BaseType_t MPU_xTaskGetSchedulerState( void ) FREERTOS_SYSTEM_CALL; +BaseType_t MPU_xTaskCatchUpTicks( TickType_t xTicksToCatchUp ) FREERTOS_SYSTEM_CALL; + +/* MPU versions of queue.h API functions. */ +BaseType_t MPU_xQueueGenericSend( QueueHandle_t xQueue, + const void * const pvItemToQueue, + TickType_t xTicksToWait, + const BaseType_t xCopyPosition ) FREERTOS_SYSTEM_CALL; +BaseType_t MPU_xQueueReceive( QueueHandle_t xQueue, + void * const pvBuffer, + TickType_t xTicksToWait ) FREERTOS_SYSTEM_CALL; +BaseType_t MPU_xQueuePeek( QueueHandle_t xQueue, + void * const pvBuffer, + TickType_t xTicksToWait ) FREERTOS_SYSTEM_CALL; +BaseType_t MPU_xQueueSemaphoreTake( QueueHandle_t xQueue, + TickType_t xTicksToWait ) FREERTOS_SYSTEM_CALL; +UBaseType_t MPU_uxQueueMessagesWaiting( const QueueHandle_t xQueue ) FREERTOS_SYSTEM_CALL; +UBaseType_t MPU_uxQueueSpacesAvailable( const QueueHandle_t xQueue ) FREERTOS_SYSTEM_CALL; +void MPU_vQueueDelete( QueueHandle_t xQueue ) FREERTOS_SYSTEM_CALL; +QueueHandle_t MPU_xQueueCreateMutex( const uint8_t ucQueueType ) FREERTOS_SYSTEM_CALL; +QueueHandle_t MPU_xQueueCreateMutexStatic( const uint8_t ucQueueType, + StaticQueue_t * pxStaticQueue ) FREERTOS_SYSTEM_CALL; +QueueHandle_t MPU_xQueueCreateCountingSemaphore( const UBaseType_t uxMaxCount, + const UBaseType_t uxInitialCount ) FREERTOS_SYSTEM_CALL; +QueueHandle_t MPU_xQueueCreateCountingSemaphoreStatic( const UBaseType_t uxMaxCount, + const UBaseType_t uxInitialCount, + StaticQueue_t * pxStaticQueue ) FREERTOS_SYSTEM_CALL; +TaskHandle_t MPU_xQueueGetMutexHolder( QueueHandle_t xSemaphore ) FREERTOS_SYSTEM_CALL; +BaseType_t MPU_xQueueTakeMutexRecursive( QueueHandle_t xMutex, + TickType_t xTicksToWait ) FREERTOS_SYSTEM_CALL; +BaseType_t MPU_xQueueGiveMutexRecursive( QueueHandle_t pxMutex ) FREERTOS_SYSTEM_CALL; +void MPU_vQueueAddToRegistry( QueueHandle_t xQueue, + const char * pcName ) FREERTOS_SYSTEM_CALL; +void MPU_vQueueUnregisterQueue( QueueHandle_t xQueue ) FREERTOS_SYSTEM_CALL; +const char * MPU_pcQueueGetName( QueueHandle_t xQueue ) FREERTOS_SYSTEM_CALL; +QueueHandle_t MPU_xQueueGenericCreate( const UBaseType_t uxQueueLength, + const UBaseType_t uxItemSize, + const uint8_t ucQueueType ) FREERTOS_SYSTEM_CALL; +QueueHandle_t MPU_xQueueGenericCreateStatic( const UBaseType_t uxQueueLength, + const UBaseType_t uxItemSize, + uint8_t * pucQueueStorage, + StaticQueue_t * pxStaticQueue, + const uint8_t ucQueueType ) FREERTOS_SYSTEM_CALL; +QueueSetHandle_t MPU_xQueueCreateSet( const UBaseType_t uxEventQueueLength ) FREERTOS_SYSTEM_CALL; +BaseType_t MPU_xQueueAddToSet( QueueSetMemberHandle_t xQueueOrSemaphore, + QueueSetHandle_t xQueueSet ) FREERTOS_SYSTEM_CALL; +BaseType_t MPU_xQueueRemoveFromSet( QueueSetMemberHandle_t xQueueOrSemaphore, + QueueSetHandle_t xQueueSet ) FREERTOS_SYSTEM_CALL; +QueueSetMemberHandle_t MPU_xQueueSelectFromSet( QueueSetHandle_t xQueueSet, + const TickType_t xTicksToWait ) FREERTOS_SYSTEM_CALL; +BaseType_t MPU_xQueueGenericReset( QueueHandle_t xQueue, + BaseType_t xNewQueue ) FREERTOS_SYSTEM_CALL; +void MPU_vQueueSetQueueNumber( QueueHandle_t xQueue, + UBaseType_t uxQueueNumber ) FREERTOS_SYSTEM_CALL; +UBaseType_t MPU_uxQueueGetQueueNumber( QueueHandle_t xQueue ) FREERTOS_SYSTEM_CALL; +uint8_t MPU_ucQueueGetQueueType( QueueHandle_t xQueue ) FREERTOS_SYSTEM_CALL; + +/* MPU versions of timers.h API functions. */ +TimerHandle_t MPU_xTimerCreate( const char * const pcTimerName, + const TickType_t xTimerPeriodInTicks, + const UBaseType_t uxAutoReload, + void * const pvTimerID, + TimerCallbackFunction_t pxCallbackFunction ) FREERTOS_SYSTEM_CALL; +TimerHandle_t MPU_xTimerCreateStatic( const char * const pcTimerName, + const TickType_t xTimerPeriodInTicks, + const UBaseType_t uxAutoReload, + void * const pvTimerID, + TimerCallbackFunction_t pxCallbackFunction, + StaticTimer_t * pxTimerBuffer ) FREERTOS_SYSTEM_CALL; +void * MPU_pvTimerGetTimerID( const TimerHandle_t xTimer ) FREERTOS_SYSTEM_CALL; +void MPU_vTimerSetTimerID( TimerHandle_t xTimer, + void * pvNewID ) FREERTOS_SYSTEM_CALL; +BaseType_t MPU_xTimerIsTimerActive( TimerHandle_t xTimer ) FREERTOS_SYSTEM_CALL; +TaskHandle_t MPU_xTimerGetTimerDaemonTaskHandle( void ) FREERTOS_SYSTEM_CALL; +BaseType_t MPU_xTimerPendFunctionCall( PendedFunction_t xFunctionToPend, + void * pvParameter1, + uint32_t ulParameter2, + TickType_t xTicksToWait ) FREERTOS_SYSTEM_CALL; +const char * MPU_pcTimerGetName( TimerHandle_t xTimer ) FREERTOS_SYSTEM_CALL; +void MPU_vTimerSetReloadMode( TimerHandle_t xTimer, + const UBaseType_t uxAutoReload ) FREERTOS_SYSTEM_CALL; +UBaseType_t MPU_uxTimerGetReloadMode( TimerHandle_t xTimer ) FREERTOS_SYSTEM_CALL; +TickType_t MPU_xTimerGetPeriod( TimerHandle_t xTimer ) FREERTOS_SYSTEM_CALL; +TickType_t MPU_xTimerGetExpiryTime( TimerHandle_t xTimer ) FREERTOS_SYSTEM_CALL; +BaseType_t MPU_xTimerCreateTimerTask( void ) FREERTOS_SYSTEM_CALL; +BaseType_t MPU_xTimerGenericCommand( TimerHandle_t xTimer, + const BaseType_t xCommandID, + const TickType_t xOptionalValue, + BaseType_t * const pxHigherPriorityTaskWoken, + const TickType_t xTicksToWait ) FREERTOS_SYSTEM_CALL; + +/* MPU versions of event_group.h API functions. */ +EventGroupHandle_t MPU_xEventGroupCreate( void ) FREERTOS_SYSTEM_CALL; +EventGroupHandle_t MPU_xEventGroupCreateStatic( StaticEventGroup_t * pxEventGroupBuffer ) FREERTOS_SYSTEM_CALL; +EventBits_t MPU_xEventGroupWaitBits( EventGroupHandle_t xEventGroup, + const EventBits_t uxBitsToWaitFor, + const BaseType_t xClearOnExit, + const BaseType_t xWaitForAllBits, + TickType_t xTicksToWait ) FREERTOS_SYSTEM_CALL; +EventBits_t MPU_xEventGroupClearBits( EventGroupHandle_t xEventGroup, + const EventBits_t uxBitsToClear ) FREERTOS_SYSTEM_CALL; +EventBits_t MPU_xEventGroupSetBits( EventGroupHandle_t xEventGroup, + const EventBits_t uxBitsToSet ) FREERTOS_SYSTEM_CALL; +EventBits_t MPU_xEventGroupSync( EventGroupHandle_t xEventGroup, + const EventBits_t uxBitsToSet, + const EventBits_t uxBitsToWaitFor, + TickType_t xTicksToWait ) FREERTOS_SYSTEM_CALL; +void MPU_vEventGroupDelete( EventGroupHandle_t xEventGroup ) FREERTOS_SYSTEM_CALL; +UBaseType_t MPU_uxEventGroupGetNumber( void * xEventGroup ) FREERTOS_SYSTEM_CALL; + +/* MPU versions of message/stream_buffer.h API functions. */ +size_t MPU_xStreamBufferSend( StreamBufferHandle_t xStreamBuffer, + const void * pvTxData, + size_t xDataLengthBytes, + TickType_t xTicksToWait ) FREERTOS_SYSTEM_CALL; +size_t MPU_xStreamBufferReceive( StreamBufferHandle_t xStreamBuffer, + void * pvRxData, + size_t xBufferLengthBytes, + TickType_t xTicksToWait ) FREERTOS_SYSTEM_CALL; +size_t MPU_xStreamBufferNextMessageLengthBytes( StreamBufferHandle_t xStreamBuffer ) FREERTOS_SYSTEM_CALL; +void MPU_vStreamBufferDelete( StreamBufferHandle_t xStreamBuffer ) FREERTOS_SYSTEM_CALL; +BaseType_t MPU_xStreamBufferIsFull( StreamBufferHandle_t xStreamBuffer ) FREERTOS_SYSTEM_CALL; +BaseType_t MPU_xStreamBufferIsEmpty( StreamBufferHandle_t xStreamBuffer ) FREERTOS_SYSTEM_CALL; +BaseType_t MPU_xStreamBufferReset( StreamBufferHandle_t xStreamBuffer ) FREERTOS_SYSTEM_CALL; +size_t MPU_xStreamBufferSpacesAvailable( StreamBufferHandle_t xStreamBuffer ) FREERTOS_SYSTEM_CALL; +size_t MPU_xStreamBufferBytesAvailable( StreamBufferHandle_t xStreamBuffer ) FREERTOS_SYSTEM_CALL; +BaseType_t MPU_xStreamBufferSetTriggerLevel( StreamBufferHandle_t xStreamBuffer, + size_t xTriggerLevel ) FREERTOS_SYSTEM_CALL; +StreamBufferHandle_t MPU_xStreamBufferGenericCreate( size_t xBufferSizeBytes, + size_t xTriggerLevelBytes, + BaseType_t xIsMessageBuffer ) FREERTOS_SYSTEM_CALL; +StreamBufferHandle_t MPU_xStreamBufferGenericCreateStatic( size_t xBufferSizeBytes, + size_t xTriggerLevelBytes, + BaseType_t xIsMessageBuffer, + uint8_t * const pucStreamBufferStorageArea, + StaticStreamBuffer_t * const pxStaticStreamBuffer ) FREERTOS_SYSTEM_CALL; + + + +#endif /* MPU_PROTOTYPES_H */ diff --git a/RTOS/FreeRTOS/Source/include/mpu_wrappers.h b/RTOS/FreeRTOS/Source/include/mpu_wrappers.h new file mode 100644 index 0000000..54e7384 --- /dev/null +++ b/RTOS/FreeRTOS/Source/include/mpu_wrappers.h @@ -0,0 +1,187 @@ +/* + * FreeRTOS Kernel V10.4.1 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * https://www.FreeRTOS.org + * https://github.com/FreeRTOS + * + */ + +#ifndef MPU_WRAPPERS_H +#define MPU_WRAPPERS_H + +/* This file redefines API functions to be called through a wrapper macro, but + * only for ports that are using the MPU. */ +#ifdef portUSING_MPU_WRAPPERS + +/* MPU_WRAPPERS_INCLUDED_FROM_API_FILE will be defined when this file is + * included from queue.c or task.c to prevent it from having an effect within + * those files. */ + #ifndef MPU_WRAPPERS_INCLUDED_FROM_API_FILE + +/* + * Map standard (non MPU) API functions to equivalents that start + * "MPU_". This will cause the application code to call the MPU_ + * version, which wraps the non-MPU version with privilege promoting + * then demoting code, so the kernel code always runs will full + * privileges. + */ + +/* Map standard tasks.h API functions to the MPU equivalents. */ + #define xTaskCreate MPU_xTaskCreate + #define xTaskCreateStatic MPU_xTaskCreateStatic + #define xTaskCreateRestricted MPU_xTaskCreateRestricted + #define vTaskAllocateMPURegions MPU_vTaskAllocateMPURegions + #define vTaskDelete MPU_vTaskDelete + #define vTaskDelay MPU_vTaskDelay + #define vTaskDelayUntil MPU_vTaskDelayUntil + #define xTaskAbortDelay MPU_xTaskAbortDelay + #define uxTaskPriorityGet MPU_uxTaskPriorityGet + #define eTaskGetState MPU_eTaskGetState + #define vTaskGetInfo MPU_vTaskGetInfo + #define vTaskPrioritySet MPU_vTaskPrioritySet + #define vTaskSuspend MPU_vTaskSuspend + #define vTaskResume MPU_vTaskResume + #define vTaskSuspendAll MPU_vTaskSuspendAll + #define xTaskResumeAll MPU_xTaskResumeAll + #define xTaskGetTickCount MPU_xTaskGetTickCount + #define uxTaskGetNumberOfTasks MPU_uxTaskGetNumberOfTasks + #define pcTaskGetName MPU_pcTaskGetName + #define xTaskGetHandle MPU_xTaskGetHandle + #define uxTaskGetStackHighWaterMark MPU_uxTaskGetStackHighWaterMark + #define uxTaskGetStackHighWaterMark2 MPU_uxTaskGetStackHighWaterMark2 + #define vTaskSetApplicationTaskTag MPU_vTaskSetApplicationTaskTag + #define xTaskGetApplicationTaskTag MPU_xTaskGetApplicationTaskTag + #define vTaskSetThreadLocalStoragePointer MPU_vTaskSetThreadLocalStoragePointer + #define pvTaskGetThreadLocalStoragePointer MPU_pvTaskGetThreadLocalStoragePointer + #define xTaskCallApplicationTaskHook MPU_xTaskCallApplicationTaskHook + #define xTaskGetIdleTaskHandle MPU_xTaskGetIdleTaskHandle + #define uxTaskGetSystemState MPU_uxTaskGetSystemState + #define vTaskList MPU_vTaskList + #define vTaskGetRunTimeStats MPU_vTaskGetRunTimeStats + #define ulTaskGetIdleRunTimeCounter MPU_ulTaskGetIdleRunTimeCounter + #define xTaskGenericNotify MPU_xTaskGenericNotify + #define xTaskGenericNotifyWait MPU_xTaskGenericNotifyWait + #define ulTaskGenericNotifyTake MPU_ulTaskGenericNotifyTake + #define xTaskGenericNotifyStateClear MPU_xTaskGenericNotifyStateClear + #define ulTaskGenericNotifyValueClear MPU_ulTaskGenericNotifyValueClear + #define xTaskCatchUpTicks MPU_xTaskCatchUpTicks + + #define xTaskGetCurrentTaskHandle MPU_xTaskGetCurrentTaskHandle + #define vTaskSetTimeOutState MPU_vTaskSetTimeOutState + #define xTaskCheckForTimeOut MPU_xTaskCheckForTimeOut + #define xTaskGetSchedulerState MPU_xTaskGetSchedulerState + +/* Map standard queue.h API functions to the MPU equivalents. */ + #define xQueueGenericSend MPU_xQueueGenericSend + #define xQueueReceive MPU_xQueueReceive + #define xQueuePeek MPU_xQueuePeek + #define xQueueSemaphoreTake MPU_xQueueSemaphoreTake + #define uxQueueMessagesWaiting MPU_uxQueueMessagesWaiting + #define uxQueueSpacesAvailable MPU_uxQueueSpacesAvailable + #define vQueueDelete MPU_vQueueDelete + #define xQueueCreateMutex MPU_xQueueCreateMutex + #define xQueueCreateMutexStatic MPU_xQueueCreateMutexStatic + #define xQueueCreateCountingSemaphore MPU_xQueueCreateCountingSemaphore + #define xQueueCreateCountingSemaphoreStatic MPU_xQueueCreateCountingSemaphoreStatic + #define xQueueGetMutexHolder MPU_xQueueGetMutexHolder + #define xQueueTakeMutexRecursive MPU_xQueueTakeMutexRecursive + #define xQueueGiveMutexRecursive MPU_xQueueGiveMutexRecursive + #define xQueueGenericCreate MPU_xQueueGenericCreate + #define xQueueGenericCreateStatic MPU_xQueueGenericCreateStatic + #define xQueueCreateSet MPU_xQueueCreateSet + #define xQueueAddToSet MPU_xQueueAddToSet + #define xQueueRemoveFromSet MPU_xQueueRemoveFromSet + #define xQueueSelectFromSet MPU_xQueueSelectFromSet + #define xQueueGenericReset MPU_xQueueGenericReset + + #if ( configQUEUE_REGISTRY_SIZE > 0 ) + #define vQueueAddToRegistry MPU_vQueueAddToRegistry + #define vQueueUnregisterQueue MPU_vQueueUnregisterQueue + #define pcQueueGetName MPU_pcQueueGetName + #endif + +/* Map standard timer.h API functions to the MPU equivalents. */ + #define xTimerCreate MPU_xTimerCreate + #define xTimerCreateStatic MPU_xTimerCreateStatic + #define pvTimerGetTimerID MPU_pvTimerGetTimerID + #define vTimerSetTimerID MPU_vTimerSetTimerID + #define xTimerIsTimerActive MPU_xTimerIsTimerActive + #define xTimerGetTimerDaemonTaskHandle MPU_xTimerGetTimerDaemonTaskHandle + #define xTimerPendFunctionCall MPU_xTimerPendFunctionCall + #define pcTimerGetName MPU_pcTimerGetName + #define vTimerSetReloadMode MPU_vTimerSetReloadMode + #define uxTimerGetReloadMode MPU_uxTimerGetReloadMode + #define xTimerGetPeriod MPU_xTimerGetPeriod + #define xTimerGetExpiryTime MPU_xTimerGetExpiryTime + #define xTimerGenericCommand MPU_xTimerGenericCommand + +/* Map standard event_group.h API functions to the MPU equivalents. */ + #define xEventGroupCreate MPU_xEventGroupCreate + #define xEventGroupCreateStatic MPU_xEventGroupCreateStatic + #define xEventGroupWaitBits MPU_xEventGroupWaitBits + #define xEventGroupClearBits MPU_xEventGroupClearBits + #define xEventGroupSetBits MPU_xEventGroupSetBits + #define xEventGroupSync MPU_xEventGroupSync + #define vEventGroupDelete MPU_vEventGroupDelete + +/* Map standard message/stream_buffer.h API functions to the MPU + * equivalents. */ + #define xStreamBufferSend MPU_xStreamBufferSend + #define xStreamBufferReceive MPU_xStreamBufferReceive + #define xStreamBufferNextMessageLengthBytes MPU_xStreamBufferNextMessageLengthBytes + #define vStreamBufferDelete MPU_vStreamBufferDelete + #define xStreamBufferIsFull MPU_xStreamBufferIsFull + #define xStreamBufferIsEmpty MPU_xStreamBufferIsEmpty + #define xStreamBufferReset MPU_xStreamBufferReset + #define xStreamBufferSpacesAvailable MPU_xStreamBufferSpacesAvailable + #define xStreamBufferBytesAvailable MPU_xStreamBufferBytesAvailable + #define xStreamBufferSetTriggerLevel MPU_xStreamBufferSetTriggerLevel + #define xStreamBufferGenericCreate MPU_xStreamBufferGenericCreate + #define xStreamBufferGenericCreateStatic MPU_xStreamBufferGenericCreateStatic + + +/* Remove the privileged function macro, but keep the PRIVILEGED_DATA + * macro so applications can place data in privileged access sections + * (useful when using statically allocated objects). */ + #define PRIVILEGED_FUNCTION + #define PRIVILEGED_DATA __attribute__( ( section( "privileged_data" ) ) ) + #define FREERTOS_SYSTEM_CALL + + #else /* MPU_WRAPPERS_INCLUDED_FROM_API_FILE */ + +/* Ensure API functions go in the privileged execution section. */ + #define PRIVILEGED_FUNCTION __attribute__( ( section( "privileged_functions" ) ) ) + #define PRIVILEGED_DATA __attribute__( ( section( "privileged_data" ) ) ) + #define FREERTOS_SYSTEM_CALL __attribute__( ( section( "freertos_system_calls" ) ) ) + + #endif /* MPU_WRAPPERS_INCLUDED_FROM_API_FILE */ + +#else /* portUSING_MPU_WRAPPERS */ + + #define PRIVILEGED_FUNCTION + #define PRIVILEGED_DATA + #define FREERTOS_SYSTEM_CALL + #define portUSING_MPU_WRAPPERS 0 + +#endif /* portUSING_MPU_WRAPPERS */ + + +#endif /* MPU_WRAPPERS_H */ diff --git a/RTOS/FreeRTOS/Source/include/portable.h b/RTOS/FreeRTOS/Source/include/portable.h new file mode 100644 index 0000000..d3b0bd1 --- /dev/null +++ b/RTOS/FreeRTOS/Source/include/portable.h @@ -0,0 +1,216 @@ +/* + * FreeRTOS Kernel V10.4.1 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * https://www.FreeRTOS.org + * https://github.com/FreeRTOS + * + */ + +/*----------------------------------------------------------- +* Portable layer API. Each function must be defined for each port. +*----------------------------------------------------------*/ + +#ifndef PORTABLE_H +#define PORTABLE_H + +/* Each FreeRTOS port has a unique portmacro.h header file. Originally a + * pre-processor definition was used to ensure the pre-processor found the correct + * portmacro.h file for the port being used. That scheme was deprecated in favour + * of setting the compiler's include path such that it found the correct + * portmacro.h file - removing the need for the constant and allowing the + * portmacro.h file to be located anywhere in relation to the port being used. + * Purely for reasons of backward compatibility the old method is still valid, but + * to make it clear that new projects should not use it, support for the port + * specific constants has been moved into the deprecated_definitions.h header + * file. */ +#include "deprecated_definitions.h" + +/* If portENTER_CRITICAL is not defined then including deprecated_definitions.h + * did not result in a portmacro.h header file being included - and it should be + * included here. In this case the path to the correct portmacro.h header file + * must be set in the compiler's include path. */ +#ifndef portENTER_CRITICAL + #include "portmacro.h" +#endif + +#if portBYTE_ALIGNMENT == 32 + #define portBYTE_ALIGNMENT_MASK ( 0x001f ) +#endif + +#if portBYTE_ALIGNMENT == 16 + #define portBYTE_ALIGNMENT_MASK ( 0x000f ) +#endif + +#if portBYTE_ALIGNMENT == 8 + #define portBYTE_ALIGNMENT_MASK ( 0x0007 ) +#endif + +#if portBYTE_ALIGNMENT == 4 + #define portBYTE_ALIGNMENT_MASK ( 0x0003 ) +#endif + +#if portBYTE_ALIGNMENT == 2 + #define portBYTE_ALIGNMENT_MASK ( 0x0001 ) +#endif + +#if portBYTE_ALIGNMENT == 1 + #define portBYTE_ALIGNMENT_MASK ( 0x0000 ) +#endif + +#ifndef portBYTE_ALIGNMENT_MASK + #error "Invalid portBYTE_ALIGNMENT definition" +#endif + +#ifndef portNUM_CONFIGURABLE_REGIONS + #define portNUM_CONFIGURABLE_REGIONS 1 +#endif + +#ifndef portHAS_STACK_OVERFLOW_CHECKING + #define portHAS_STACK_OVERFLOW_CHECKING 0 +#endif + +#ifndef portARCH_NAME + #define portARCH_NAME NULL +#endif + +/* *INDENT-OFF* */ +#ifdef __cplusplus + extern "C" { +#endif +/* *INDENT-ON* */ + +#include "mpu_wrappers.h" + +/* + * Setup the stack of a new task so it is ready to be placed under the + * scheduler control. The registers have to be placed on the stack in + * the order that the port expects to find them. + * + */ +#if ( portUSING_MPU_WRAPPERS == 1 ) + #if ( portHAS_STACK_OVERFLOW_CHECKING == 1 ) + StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack, + StackType_t * pxEndOfStack, + TaskFunction_t pxCode, + void * pvParameters, + BaseType_t xRunPrivileged ) PRIVILEGED_FUNCTION; + #else + StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack, + TaskFunction_t pxCode, + void * pvParameters, + BaseType_t xRunPrivileged ) PRIVILEGED_FUNCTION; + #endif +#else /* if ( portUSING_MPU_WRAPPERS == 1 ) */ + #if ( portHAS_STACK_OVERFLOW_CHECKING == 1 ) + StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack, + StackType_t * pxEndOfStack, + TaskFunction_t pxCode, + void * pvParameters ) PRIVILEGED_FUNCTION; + #else + StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack, + TaskFunction_t pxCode, + void * pvParameters ) PRIVILEGED_FUNCTION; + #endif +#endif /* if ( portUSING_MPU_WRAPPERS == 1 ) */ + +/* Used by heap_5.c to define the start address and size of each memory region + * that together comprise the total FreeRTOS heap space. */ +typedef struct HeapRegion +{ + uint8_t * pucStartAddress; + size_t xSizeInBytes; +} HeapRegion_t; + +/* Used to pass information about the heap out of vPortGetHeapStats(). */ +typedef struct xHeapStats +{ + size_t xAvailableHeapSpaceInBytes; /* The total heap size currently available - this is the sum of all the free blocks, not the largest block that can be allocated. */ + size_t xSizeOfLargestFreeBlockInBytes; /* The maximum size, in bytes, of all the free blocks within the heap at the time vPortGetHeapStats() is called. */ + size_t xSizeOfSmallestFreeBlockInBytes; /* The minimum size, in bytes, of all the free blocks within the heap at the time vPortGetHeapStats() is called. */ + size_t xNumberOfFreeBlocks; /* The number of free memory blocks within the heap at the time vPortGetHeapStats() is called. */ + size_t xMinimumEverFreeBytesRemaining; /* The minimum amount of total free memory (sum of all free blocks) there has been in the heap since the system booted. */ + size_t xNumberOfSuccessfulAllocations; /* The number of calls to pvPortMalloc() that have returned a valid memory block. */ + size_t xNumberOfSuccessfulFrees; /* The number of calls to vPortFree() that has successfully freed a block of memory. */ +} HeapStats_t; + +/* + * Used to define multiple heap regions for use by heap_5.c. This function + * must be called before any calls to pvPortMalloc() - not creating a task, + * queue, semaphore, mutex, software timer, event group, etc. will result in + * pvPortMalloc being called. + * + * pxHeapRegions passes in an array of HeapRegion_t structures - each of which + * defines a region of memory that can be used as the heap. The array is + * terminated by a HeapRegions_t structure that has a size of 0. The region + * with the lowest start address must appear first in the array. + */ +void vPortDefineHeapRegions( const HeapRegion_t * const pxHeapRegions ) PRIVILEGED_FUNCTION; + +/* + * Returns a HeapStats_t structure filled with information about the current + * heap state. + */ +void vPortGetHeapStats( HeapStats_t * pxHeapStats ); + +/* + * Map to the memory management routines required for the port. + */ +void * pvPortMalloc( size_t xSize ) PRIVILEGED_FUNCTION; +void vPortFree( void * pv ) PRIVILEGED_FUNCTION; +void vPortInitialiseBlocks( void ) PRIVILEGED_FUNCTION; +size_t xPortGetFreeHeapSize( void ) PRIVILEGED_FUNCTION; +size_t xPortGetMinimumEverFreeHeapSize( void ) PRIVILEGED_FUNCTION; + +/* + * Setup the hardware ready for the scheduler to take control. This generally + * sets up a tick interrupt and sets timers for the correct tick frequency. + */ +BaseType_t xPortStartScheduler( void ) PRIVILEGED_FUNCTION; + +/* + * Undo any hardware/ISR setup that was performed by xPortStartScheduler() so + * the hardware is left in its original condition after the scheduler stops + * executing. + */ +void vPortEndScheduler( void ) PRIVILEGED_FUNCTION; + +/* + * The structures and methods of manipulating the MPU are contained within the + * port layer. + * + * Fills the xMPUSettings structure with the memory region information + * contained in xRegions. + */ +#if ( portUSING_MPU_WRAPPERS == 1 ) + struct xMEMORY_REGION; + void vPortStoreTaskMPUSettings( xMPU_SETTINGS * xMPUSettings, + const struct xMEMORY_REGION * const xRegions, + StackType_t * pxBottomOfStack, + uint32_t ulStackDepth ) PRIVILEGED_FUNCTION; +#endif + +/* *INDENT-OFF* */ +#ifdef __cplusplus + } +#endif +/* *INDENT-ON* */ + +#endif /* PORTABLE_H */ diff --git a/RTOS/FreeRTOS/Source/include/projdefs.h b/RTOS/FreeRTOS/Source/include/projdefs.h new file mode 100644 index 0000000..7a620a0 --- /dev/null +++ b/RTOS/FreeRTOS/Source/include/projdefs.h @@ -0,0 +1,120 @@ +/* + * FreeRTOS Kernel V10.4.1 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * https://www.FreeRTOS.org + * https://github.com/FreeRTOS + * + */ + +#ifndef PROJDEFS_H +#define PROJDEFS_H + +/* + * Defines the prototype to which task functions must conform. Defined in this + * file to ensure the type is known before portable.h is included. + */ +typedef void (* TaskFunction_t)( void * ); + +/* Converts a time in milliseconds to a time in ticks. This macro can be + * overridden by a macro of the same name defined in FreeRTOSConfig.h in case the + * definition here is not suitable for your application. */ +#ifndef pdMS_TO_TICKS + #define pdMS_TO_TICKS( xTimeInMs ) ( ( TickType_t ) ( ( ( TickType_t ) ( xTimeInMs ) * ( TickType_t ) configTICK_RATE_HZ ) / ( TickType_t ) 1000U ) ) +#endif + +#define pdFALSE ( ( BaseType_t ) 0 ) +#define pdTRUE ( ( BaseType_t ) 1 ) + +#define pdPASS ( pdTRUE ) +#define pdFAIL ( pdFALSE ) +#define errQUEUE_EMPTY ( ( BaseType_t ) 0 ) +#define errQUEUE_FULL ( ( BaseType_t ) 0 ) + +/* FreeRTOS error definitions. */ +#define errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY ( -1 ) +#define errQUEUE_BLOCKED ( -4 ) +#define errQUEUE_YIELD ( -5 ) + +/* Macros used for basic data corruption checks. */ +#ifndef configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES + #define configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES 0 +#endif + +#if ( configUSE_16_BIT_TICKS == 1 ) + #define pdINTEGRITY_CHECK_VALUE 0x5a5a +#else + #define pdINTEGRITY_CHECK_VALUE 0x5a5a5a5aUL +#endif + +/* The following errno values are used by FreeRTOS+ components, not FreeRTOS + * itself. */ +#define pdFREERTOS_ERRNO_NONE 0 /* No errors */ +#define pdFREERTOS_ERRNO_ENOENT 2 /* No such file or directory */ +#define pdFREERTOS_ERRNO_EINTR 4 /* Interrupted system call */ +#define pdFREERTOS_ERRNO_EIO 5 /* I/O error */ +#define pdFREERTOS_ERRNO_ENXIO 6 /* No such device or address */ +#define pdFREERTOS_ERRNO_EBADF 9 /* Bad file number */ +#define pdFREERTOS_ERRNO_EAGAIN 11 /* No more processes */ +#define pdFREERTOS_ERRNO_EWOULDBLOCK 11 /* Operation would block */ +#define pdFREERTOS_ERRNO_ENOMEM 12 /* Not enough memory */ +#define pdFREERTOS_ERRNO_EACCES 13 /* Permission denied */ +#define pdFREERTOS_ERRNO_EFAULT 14 /* Bad address */ +#define pdFREERTOS_ERRNO_EBUSY 16 /* Mount device busy */ +#define pdFREERTOS_ERRNO_EEXIST 17 /* File exists */ +#define pdFREERTOS_ERRNO_EXDEV 18 /* Cross-device link */ +#define pdFREERTOS_ERRNO_ENODEV 19 /* No such device */ +#define pdFREERTOS_ERRNO_ENOTDIR 20 /* Not a directory */ +#define pdFREERTOS_ERRNO_EISDIR 21 /* Is a directory */ +#define pdFREERTOS_ERRNO_EINVAL 22 /* Invalid argument */ +#define pdFREERTOS_ERRNO_ENOSPC 28 /* No space left on device */ +#define pdFREERTOS_ERRNO_ESPIPE 29 /* Illegal seek */ +#define pdFREERTOS_ERRNO_EROFS 30 /* Read only file system */ +#define pdFREERTOS_ERRNO_EUNATCH 42 /* Protocol driver not attached */ +#define pdFREERTOS_ERRNO_EBADE 50 /* Invalid exchange */ +#define pdFREERTOS_ERRNO_EFTYPE 79 /* Inappropriate file type or format */ +#define pdFREERTOS_ERRNO_ENMFILE 89 /* No more files */ +#define pdFREERTOS_ERRNO_ENOTEMPTY 90 /* Directory not empty */ +#define pdFREERTOS_ERRNO_ENAMETOOLONG 91 /* File or path name too long */ +#define pdFREERTOS_ERRNO_EOPNOTSUPP 95 /* Operation not supported on transport endpoint */ +#define pdFREERTOS_ERRNO_ENOBUFS 105 /* No buffer space available */ +#define pdFREERTOS_ERRNO_ENOPROTOOPT 109 /* Protocol not available */ +#define pdFREERTOS_ERRNO_EADDRINUSE 112 /* Address already in use */ +#define pdFREERTOS_ERRNO_ETIMEDOUT 116 /* Connection timed out */ +#define pdFREERTOS_ERRNO_EINPROGRESS 119 /* Connection already in progress */ +#define pdFREERTOS_ERRNO_EALREADY 120 /* Socket already connected */ +#define pdFREERTOS_ERRNO_EADDRNOTAVAIL 125 /* Address not available */ +#define pdFREERTOS_ERRNO_EISCONN 127 /* Socket is already connected */ +#define pdFREERTOS_ERRNO_ENOTCONN 128 /* Socket is not connected */ +#define pdFREERTOS_ERRNO_ENOMEDIUM 135 /* No medium inserted */ +#define pdFREERTOS_ERRNO_EILSEQ 138 /* An invalid UTF-16 sequence was encountered. */ +#define pdFREERTOS_ERRNO_ECANCELED 140 /* Operation canceled. */ + +/* The following endian values are used by FreeRTOS+ components, not FreeRTOS + * itself. */ +#define pdFREERTOS_LITTLE_ENDIAN 0 +#define pdFREERTOS_BIG_ENDIAN 1 + +/* Re-defining endian values for generic naming. */ +#define pdLITTLE_ENDIAN pdFREERTOS_LITTLE_ENDIAN +#define pdBIG_ENDIAN pdFREERTOS_BIG_ENDIAN + + +#endif /* PROJDEFS_H */ diff --git a/RTOS/FreeRTOS/Source/include/queue.h b/RTOS/FreeRTOS/Source/include/queue.h new file mode 100644 index 0000000..d2ea2ae --- /dev/null +++ b/RTOS/FreeRTOS/Source/include/queue.h @@ -0,0 +1,1716 @@ +/* + * FreeRTOS Kernel V10.4.1 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * https://www.FreeRTOS.org + * https://github.com/FreeRTOS + * + */ + + +#ifndef QUEUE_H +#define QUEUE_H + +#ifndef INC_FREERTOS_H + #error "include FreeRTOS.h" must appear in source files before "include queue.h" +#endif + +/* *INDENT-OFF* */ +#ifdef __cplusplus + extern "C" { +#endif +/* *INDENT-ON* */ + +#include "task.h" + +/** + * Type by which queues are referenced. For example, a call to xQueueCreate() + * returns an QueueHandle_t variable that can then be used as a parameter to + * xQueueSend(), xQueueReceive(), etc. + */ +struct QueueDefinition; /* Using old naming convention so as not to break kernel aware debuggers. */ +typedef struct QueueDefinition * QueueHandle_t; + +/** + * Type by which queue sets are referenced. For example, a call to + * xQueueCreateSet() returns an xQueueSet variable that can then be used as a + * parameter to xQueueSelectFromSet(), xQueueAddToSet(), etc. + */ +typedef struct QueueDefinition * QueueSetHandle_t; + +/** + * Queue sets can contain both queues and semaphores, so the + * QueueSetMemberHandle_t is defined as a type to be used where a parameter or + * return value can be either an QueueHandle_t or an SemaphoreHandle_t. + */ +typedef struct QueueDefinition * QueueSetMemberHandle_t; + +/* For internal use only. */ +#define queueSEND_TO_BACK ( ( BaseType_t ) 0 ) +#define queueSEND_TO_FRONT ( ( BaseType_t ) 1 ) +#define queueOVERWRITE ( ( BaseType_t ) 2 ) + +/* For internal use only. These definitions *must* match those in queue.c. */ +#define queueQUEUE_TYPE_BASE ( ( uint8_t ) 0U ) +#define queueQUEUE_TYPE_SET ( ( uint8_t ) 0U ) +#define queueQUEUE_TYPE_MUTEX ( ( uint8_t ) 1U ) +#define queueQUEUE_TYPE_COUNTING_SEMAPHORE ( ( uint8_t ) 2U ) +#define queueQUEUE_TYPE_BINARY_SEMAPHORE ( ( uint8_t ) 3U ) +#define queueQUEUE_TYPE_RECURSIVE_MUTEX ( ( uint8_t ) 4U ) + +/** + * queue. h + *
+ * QueueHandle_t xQueueCreate(
+ *                            UBaseType_t uxQueueLength,
+ *                            UBaseType_t uxItemSize
+ *                        );
+ * 
+ * + * Creates a new queue instance, and returns a handle by which the new queue + * can be referenced. + * + * Internally, within the FreeRTOS implementation, queues use two blocks of + * memory. The first block is used to hold the queue's data structures. The + * second block is used to hold items placed into the queue. If a queue is + * created using xQueueCreate() then both blocks of memory are automatically + * dynamically allocated inside the xQueueCreate() function. (see + * https://www.FreeRTOS.org/a00111.html). If a queue is created using + * xQueueCreateStatic() then the application writer must provide the memory that + * will get used by the queue. xQueueCreateStatic() therefore allows a queue to + * be created without using any dynamic memory allocation. + * + * https://www.FreeRTOS.org/Embedded-RTOS-Queues.html + * + * @param uxQueueLength The maximum number of items that the queue can contain. + * + * @param uxItemSize The number of bytes each item in the queue will require. + * Items are queued by copy, not by reference, so this is the number of bytes + * that will be copied for each posted item. Each item on the queue must be + * the same size. + * + * @return If the queue is successfully create then a handle to the newly + * created queue is returned. If the queue cannot be created then 0 is + * returned. + * + * Example usage: + *
+ * struct AMessage
+ * {
+ *  char ucMessageID;
+ *  char ucData[ 20 ];
+ * };
+ *
+ * void vATask( void *pvParameters )
+ * {
+ * QueueHandle_t xQueue1, xQueue2;
+ *
+ *  // Create a queue capable of containing 10 uint32_t values.
+ *  xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
+ *  if( xQueue1 == 0 )
+ *  {
+ *      // Queue was not created and must not be used.
+ *  }
+ *
+ *  // Create a queue capable of containing 10 pointers to AMessage structures.
+ *  // These should be passed by pointer as they contain a lot of data.
+ *  xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
+ *  if( xQueue2 == 0 )
+ *  {
+ *      // Queue was not created and must not be used.
+ *  }
+ *
+ *  // ... Rest of task code.
+ * }
+ * 
+ * \defgroup xQueueCreate xQueueCreate + * \ingroup QueueManagement + */ +#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + #define xQueueCreate( uxQueueLength, uxItemSize ) xQueueGenericCreate( ( uxQueueLength ), ( uxItemSize ), ( queueQUEUE_TYPE_BASE ) ) +#endif + +/** + * queue. h + *
+ * QueueHandle_t xQueueCreateStatic(
+ *                            UBaseType_t uxQueueLength,
+ *                            UBaseType_t uxItemSize,
+ *                            uint8_t *pucQueueStorageBuffer,
+ *                            StaticQueue_t *pxQueueBuffer
+ *                        );
+ * 
+ * + * Creates a new queue instance, and returns a handle by which the new queue + * can be referenced. + * + * Internally, within the FreeRTOS implementation, queues use two blocks of + * memory. The first block is used to hold the queue's data structures. The + * second block is used to hold items placed into the queue. If a queue is + * created using xQueueCreate() then both blocks of memory are automatically + * dynamically allocated inside the xQueueCreate() function. (see + * https://www.FreeRTOS.org/a00111.html). If a queue is created using + * xQueueCreateStatic() then the application writer must provide the memory that + * will get used by the queue. xQueueCreateStatic() therefore allows a queue to + * be created without using any dynamic memory allocation. + * + * https://www.FreeRTOS.org/Embedded-RTOS-Queues.html + * + * @param uxQueueLength The maximum number of items that the queue can contain. + * + * @param uxItemSize The number of bytes each item in the queue will require. + * Items are queued by copy, not by reference, so this is the number of bytes + * that will be copied for each posted item. Each item on the queue must be + * the same size. + * + * @param pucQueueStorageBuffer If uxItemSize is not zero then + * pucQueueStorageBuffer must point to a uint8_t array that is at least large + * enough to hold the maximum number of items that can be in the queue at any + * one time - which is ( uxQueueLength * uxItemsSize ) bytes. If uxItemSize is + * zero then pucQueueStorageBuffer can be NULL. + * + * @param pxQueueBuffer Must point to a variable of type StaticQueue_t, which + * will be used to hold the queue's data structure. + * + * @return If the queue is created then a handle to the created queue is + * returned. If pxQueueBuffer is NULL then NULL is returned. + * + * Example usage: + *
+ * struct AMessage
+ * {
+ *  char ucMessageID;
+ *  char ucData[ 20 ];
+ * };
+ *
+ #define QUEUE_LENGTH 10
+ #define ITEM_SIZE sizeof( uint32_t )
+ *
+ * // xQueueBuffer will hold the queue structure.
+ * StaticQueue_t xQueueBuffer;
+ *
+ * // ucQueueStorage will hold the items posted to the queue.  Must be at least
+ * // [(queue length) * ( queue item size)] bytes long.
+ * uint8_t ucQueueStorage[ QUEUE_LENGTH * ITEM_SIZE ];
+ *
+ * void vATask( void *pvParameters )
+ * {
+ * QueueHandle_t xQueue1;
+ *
+ *  // Create a queue capable of containing 10 uint32_t values.
+ *  xQueue1 = xQueueCreate( QUEUE_LENGTH, // The number of items the queue can hold.
+ *                          ITEM_SIZE     // The size of each item in the queue
+ *                          &( ucQueueStorage[ 0 ] ), // The buffer that will hold the items in the queue.
+ *                          &xQueueBuffer ); // The buffer that will hold the queue structure.
+ *
+ *  // The queue is guaranteed to be created successfully as no dynamic memory
+ *  // allocation is used.  Therefore xQueue1 is now a handle to a valid queue.
+ *
+ *  // ... Rest of task code.
+ * }
+ * 
+ * \defgroup xQueueCreateStatic xQueueCreateStatic + * \ingroup QueueManagement + */ +#if ( configSUPPORT_STATIC_ALLOCATION == 1 ) + #define xQueueCreateStatic( uxQueueLength, uxItemSize, pucQueueStorage, pxQueueBuffer ) xQueueGenericCreateStatic( ( uxQueueLength ), ( uxItemSize ), ( pucQueueStorage ), ( pxQueueBuffer ), ( queueQUEUE_TYPE_BASE ) ) +#endif /* configSUPPORT_STATIC_ALLOCATION */ + +/** + * queue. h + *
+ * BaseType_t xQueueSendToToFront(
+ *                                 QueueHandle_t    xQueue,
+ *                                 const void       *pvItemToQueue,
+ *                                 TickType_t       xTicksToWait
+ *                             );
+ * 
+ * + * Post an item to the front of a queue. The item is queued by copy, not by + * reference. This function must not be called from an interrupt service + * routine. See xQueueSendFromISR () for an alternative which may be used + * in an ISR. + * + * @param xQueue The handle to the queue on which the item is to be posted. + * + * @param pvItemToQueue A pointer to the item that is to be placed on the + * queue. The size of the items the queue will hold was defined when the + * queue was created, so this many bytes will be copied from pvItemToQueue + * into the queue storage area. + * + * @param xTicksToWait The maximum amount of time the task should block + * waiting for space to become available on the queue, should it already + * be full. The call will return immediately if this is set to 0 and the + * queue is full. The time is defined in tick periods so the constant + * portTICK_PERIOD_MS should be used to convert to real time if this is required. + * + * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL. + * + * Example usage: + *
+ * struct AMessage
+ * {
+ *  char ucMessageID;
+ *  char ucData[ 20 ];
+ * } xMessage;
+ *
+ * uint32_t ulVar = 10UL;
+ *
+ * void vATask( void *pvParameters )
+ * {
+ * QueueHandle_t xQueue1, xQueue2;
+ * struct AMessage *pxMessage;
+ *
+ *  // Create a queue capable of containing 10 uint32_t values.
+ *  xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
+ *
+ *  // Create a queue capable of containing 10 pointers to AMessage structures.
+ *  // These should be passed by pointer as they contain a lot of data.
+ *  xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
+ *
+ *  // ...
+ *
+ *  if( xQueue1 != 0 )
+ *  {
+ *      // Send an uint32_t.  Wait for 10 ticks for space to become
+ *      // available if necessary.
+ *      if( xQueueSendToFront( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10 ) != pdPASS )
+ *      {
+ *          // Failed to post the message, even after 10 ticks.
+ *      }
+ *  }
+ *
+ *  if( xQueue2 != 0 )
+ *  {
+ *      // Send a pointer to a struct AMessage object.  Don't block if the
+ *      // queue is already full.
+ *      pxMessage = & xMessage;
+ *      xQueueSendToFront( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0 );
+ *  }
+ *
+ *  // ... Rest of task code.
+ * }
+ * 
+ * \defgroup xQueueSend xQueueSend + * \ingroup QueueManagement + */ +#define xQueueSendToFront( xQueue, pvItemToQueue, xTicksToWait ) \ + xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_FRONT ) + +/** + * queue. h + *
+ * BaseType_t xQueueSendToBack(
+ *                                 QueueHandle_t    xQueue,
+ *                                 const void       *pvItemToQueue,
+ *                                 TickType_t       xTicksToWait
+ *                             );
+ * 
+ * + * This is a macro that calls xQueueGenericSend(). + * + * Post an item to the back of a queue. The item is queued by copy, not by + * reference. This function must not be called from an interrupt service + * routine. See xQueueSendFromISR () for an alternative which may be used + * in an ISR. + * + * @param xQueue The handle to the queue on which the item is to be posted. + * + * @param pvItemToQueue A pointer to the item that is to be placed on the + * queue. The size of the items the queue will hold was defined when the + * queue was created, so this many bytes will be copied from pvItemToQueue + * into the queue storage area. + * + * @param xTicksToWait The maximum amount of time the task should block + * waiting for space to become available on the queue, should it already + * be full. The call will return immediately if this is set to 0 and the queue + * is full. The time is defined in tick periods so the constant + * portTICK_PERIOD_MS should be used to convert to real time if this is required. + * + * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL. + * + * Example usage: + *
+ * struct AMessage
+ * {
+ *  char ucMessageID;
+ *  char ucData[ 20 ];
+ * } xMessage;
+ *
+ * uint32_t ulVar = 10UL;
+ *
+ * void vATask( void *pvParameters )
+ * {
+ * QueueHandle_t xQueue1, xQueue2;
+ * struct AMessage *pxMessage;
+ *
+ *  // Create a queue capable of containing 10 uint32_t values.
+ *  xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
+ *
+ *  // Create a queue capable of containing 10 pointers to AMessage structures.
+ *  // These should be passed by pointer as they contain a lot of data.
+ *  xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
+ *
+ *  // ...
+ *
+ *  if( xQueue1 != 0 )
+ *  {
+ *      // Send an uint32_t.  Wait for 10 ticks for space to become
+ *      // available if necessary.
+ *      if( xQueueSendToBack( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10 ) != pdPASS )
+ *      {
+ *          // Failed to post the message, even after 10 ticks.
+ *      }
+ *  }
+ *
+ *  if( xQueue2 != 0 )
+ *  {
+ *      // Send a pointer to a struct AMessage object.  Don't block if the
+ *      // queue is already full.
+ *      pxMessage = & xMessage;
+ *      xQueueSendToBack( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0 );
+ *  }
+ *
+ *  // ... Rest of task code.
+ * }
+ * 
+ * \defgroup xQueueSend xQueueSend + * \ingroup QueueManagement + */ +#define xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait ) \ + xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK ) + +/** + * queue. h + *
+ * BaseType_t xQueueSend(
+ *                            QueueHandle_t xQueue,
+ *                            const void * pvItemToQueue,
+ *                            TickType_t xTicksToWait
+ *                       );
+ * 
+ * + * This is a macro that calls xQueueGenericSend(). It is included for + * backward compatibility with versions of FreeRTOS.org that did not + * include the xQueueSendToFront() and xQueueSendToBack() macros. It is + * equivalent to xQueueSendToBack(). + * + * Post an item on a queue. The item is queued by copy, not by reference. + * This function must not be called from an interrupt service routine. + * See xQueueSendFromISR () for an alternative which may be used in an ISR. + * + * @param xQueue The handle to the queue on which the item is to be posted. + * + * @param pvItemToQueue A pointer to the item that is to be placed on the + * queue. The size of the items the queue will hold was defined when the + * queue was created, so this many bytes will be copied from pvItemToQueue + * into the queue storage area. + * + * @param xTicksToWait The maximum amount of time the task should block + * waiting for space to become available on the queue, should it already + * be full. The call will return immediately if this is set to 0 and the + * queue is full. The time is defined in tick periods so the constant + * portTICK_PERIOD_MS should be used to convert to real time if this is required. + * + * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL. + * + * Example usage: + *
+ * struct AMessage
+ * {
+ *  char ucMessageID;
+ *  char ucData[ 20 ];
+ * } xMessage;
+ *
+ * uint32_t ulVar = 10UL;
+ *
+ * void vATask( void *pvParameters )
+ * {
+ * QueueHandle_t xQueue1, xQueue2;
+ * struct AMessage *pxMessage;
+ *
+ *  // Create a queue capable of containing 10 uint32_t values.
+ *  xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
+ *
+ *  // Create a queue capable of containing 10 pointers to AMessage structures.
+ *  // These should be passed by pointer as they contain a lot of data.
+ *  xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
+ *
+ *  // ...
+ *
+ *  if( xQueue1 != 0 )
+ *  {
+ *      // Send an uint32_t.  Wait for 10 ticks for space to become
+ *      // available if necessary.
+ *      if( xQueueSend( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10 ) != pdPASS )
+ *      {
+ *          // Failed to post the message, even after 10 ticks.
+ *      }
+ *  }
+ *
+ *  if( xQueue2 != 0 )
+ *  {
+ *      // Send a pointer to a struct AMessage object.  Don't block if the
+ *      // queue is already full.
+ *      pxMessage = & xMessage;
+ *      xQueueSend( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0 );
+ *  }
+ *
+ *  // ... Rest of task code.
+ * }
+ * 
+ * \defgroup xQueueSend xQueueSend + * \ingroup QueueManagement + */ +#define xQueueSend( xQueue, pvItemToQueue, xTicksToWait ) \ + xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK ) + +/** + * queue. h + *
+ * BaseType_t xQueueOverwrite(
+ *                            QueueHandle_t xQueue,
+ *                            const void * pvItemToQueue
+ *                       );
+ * 
+ * + * Only for use with queues that have a length of one - so the queue is either + * empty or full. + * + * Post an item on a queue. If the queue is already full then overwrite the + * value held in the queue. The item is queued by copy, not by reference. + * + * This function must not be called from an interrupt service routine. + * See xQueueOverwriteFromISR () for an alternative which may be used in an ISR. + * + * @param xQueue The handle of the queue to which the data is being sent. + * + * @param pvItemToQueue A pointer to the item that is to be placed on the + * queue. The size of the items the queue will hold was defined when the + * queue was created, so this many bytes will be copied from pvItemToQueue + * into the queue storage area. + * + * @return xQueueOverwrite() is a macro that calls xQueueGenericSend(), and + * therefore has the same return values as xQueueSendToFront(). However, pdPASS + * is the only value that can be returned because xQueueOverwrite() will write + * to the queue even when the queue is already full. + * + * Example usage: + *
+ *
+ * void vFunction( void *pvParameters )
+ * {
+ * QueueHandle_t xQueue;
+ * uint32_t ulVarToSend, ulValReceived;
+ *
+ *  // Create a queue to hold one uint32_t value.  It is strongly
+ *  // recommended *not* to use xQueueOverwrite() on queues that can
+ *  // contain more than one value, and doing so will trigger an assertion
+ *  // if configASSERT() is defined.
+ *  xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
+ *
+ *  // Write the value 10 to the queue using xQueueOverwrite().
+ *  ulVarToSend = 10;
+ *  xQueueOverwrite( xQueue, &ulVarToSend );
+ *
+ *  // Peeking the queue should now return 10, but leave the value 10 in
+ *  // the queue.  A block time of zero is used as it is known that the
+ *  // queue holds a value.
+ *  ulValReceived = 0;
+ *  xQueuePeek( xQueue, &ulValReceived, 0 );
+ *
+ *  if( ulValReceived != 10 )
+ *  {
+ *      // Error unless the item was removed by a different task.
+ *  }
+ *
+ *  // The queue is still full.  Use xQueueOverwrite() to overwrite the
+ *  // value held in the queue with 100.
+ *  ulVarToSend = 100;
+ *  xQueueOverwrite( xQueue, &ulVarToSend );
+ *
+ *  // This time read from the queue, leaving the queue empty once more.
+ *  // A block time of 0 is used again.
+ *  xQueueReceive( xQueue, &ulValReceived, 0 );
+ *
+ *  // The value read should be the last value written, even though the
+ *  // queue was already full when the value was written.
+ *  if( ulValReceived != 100 )
+ *  {
+ *      // Error!
+ *  }
+ *
+ *  // ...
+ * }
+ * 
+ * \defgroup xQueueOverwrite xQueueOverwrite + * \ingroup QueueManagement + */ +#define xQueueOverwrite( xQueue, pvItemToQueue ) \ + xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), 0, queueOVERWRITE ) + + +/** + * queue. h + *
+ * BaseType_t xQueueGenericSend(
+ *                                  QueueHandle_t xQueue,
+ *                                  const void * pvItemToQueue,
+ *                                  TickType_t xTicksToWait
+ *                                  BaseType_t xCopyPosition
+ *                              );
+ * 
+ * + * It is preferred that the macros xQueueSend(), xQueueSendToFront() and + * xQueueSendToBack() are used in place of calling this function directly. + * + * Post an item on a queue. The item is queued by copy, not by reference. + * This function must not be called from an interrupt service routine. + * See xQueueSendFromISR () for an alternative which may be used in an ISR. + * + * @param xQueue The handle to the queue on which the item is to be posted. + * + * @param pvItemToQueue A pointer to the item that is to be placed on the + * queue. The size of the items the queue will hold was defined when the + * queue was created, so this many bytes will be copied from pvItemToQueue + * into the queue storage area. + * + * @param xTicksToWait The maximum amount of time the task should block + * waiting for space to become available on the queue, should it already + * be full. The call will return immediately if this is set to 0 and the + * queue is full. The time is defined in tick periods so the constant + * portTICK_PERIOD_MS should be used to convert to real time if this is required. + * + * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the + * item at the back of the queue, or queueSEND_TO_FRONT to place the item + * at the front of the queue (for high priority messages). + * + * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL. + * + * Example usage: + *
+ * struct AMessage
+ * {
+ *  char ucMessageID;
+ *  char ucData[ 20 ];
+ * } xMessage;
+ *
+ * uint32_t ulVar = 10UL;
+ *
+ * void vATask( void *pvParameters )
+ * {
+ * QueueHandle_t xQueue1, xQueue2;
+ * struct AMessage *pxMessage;
+ *
+ *  // Create a queue capable of containing 10 uint32_t values.
+ *  xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
+ *
+ *  // Create a queue capable of containing 10 pointers to AMessage structures.
+ *  // These should be passed by pointer as they contain a lot of data.
+ *  xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
+ *
+ *  // ...
+ *
+ *  if( xQueue1 != 0 )
+ *  {
+ *      // Send an uint32_t.  Wait for 10 ticks for space to become
+ *      // available if necessary.
+ *      if( xQueueGenericSend( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10, queueSEND_TO_BACK ) != pdPASS )
+ *      {
+ *          // Failed to post the message, even after 10 ticks.
+ *      }
+ *  }
+ *
+ *  if( xQueue2 != 0 )
+ *  {
+ *      // Send a pointer to a struct AMessage object.  Don't block if the
+ *      // queue is already full.
+ *      pxMessage = & xMessage;
+ *      xQueueGenericSend( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0, queueSEND_TO_BACK );
+ *  }
+ *
+ *  // ... Rest of task code.
+ * }
+ * 
+ * \defgroup xQueueSend xQueueSend + * \ingroup QueueManagement + */ +BaseType_t xQueueGenericSend( QueueHandle_t xQueue, + const void * const pvItemToQueue, + TickType_t xTicksToWait, + const BaseType_t xCopyPosition ) PRIVILEGED_FUNCTION; + +/** + * queue. h + *
+ * BaseType_t xQueuePeek(
+ *                           QueueHandle_t xQueue,
+ *                           void * const pvBuffer,
+ *                           TickType_t xTicksToWait
+ *                       );
+ * 
+ * + * Receive an item from a queue without removing the item from the queue. + * The item is received by copy so a buffer of adequate size must be + * provided. The number of bytes copied into the buffer was defined when + * the queue was created. + * + * Successfully received items remain on the queue so will be returned again + * by the next call, or a call to xQueueReceive(). + * + * This macro must not be used in an interrupt service routine. See + * xQueuePeekFromISR() for an alternative that can be called from an interrupt + * service routine. + * + * @param xQueue The handle to the queue from which the item is to be + * received. + * + * @param pvBuffer Pointer to the buffer into which the received item will + * be copied. + * + * @param xTicksToWait The maximum amount of time the task should block + * waiting for an item to receive should the queue be empty at the time + * of the call. The time is defined in tick periods so the constant + * portTICK_PERIOD_MS should be used to convert to real time if this is required. + * xQueuePeek() will return immediately if xTicksToWait is 0 and the queue + * is empty. + * + * @return pdTRUE if an item was successfully received from the queue, + * otherwise pdFALSE. + * + * Example usage: + *
+ * struct AMessage
+ * {
+ *  char ucMessageID;
+ *  char ucData[ 20 ];
+ * } xMessage;
+ *
+ * QueueHandle_t xQueue;
+ *
+ * // Task to create a queue and post a value.
+ * void vATask( void *pvParameters )
+ * {
+ * struct AMessage *pxMessage;
+ *
+ *  // Create a queue capable of containing 10 pointers to AMessage structures.
+ *  // These should be passed by pointer as they contain a lot of data.
+ *  xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
+ *  if( xQueue == 0 )
+ *  {
+ *      // Failed to create the queue.
+ *  }
+ *
+ *  // ...
+ *
+ *  // Send a pointer to a struct AMessage object.  Don't block if the
+ *  // queue is already full.
+ *  pxMessage = & xMessage;
+ *  xQueueSend( xQueue, ( void * ) &pxMessage, ( TickType_t ) 0 );
+ *
+ *  // ... Rest of task code.
+ * }
+ *
+ * // Task to peek the data from the queue.
+ * void vADifferentTask( void *pvParameters )
+ * {
+ * struct AMessage *pxRxedMessage;
+ *
+ *  if( xQueue != 0 )
+ *  {
+ *      // Peek a message on the created queue.  Block for 10 ticks if a
+ *      // message is not immediately available.
+ *      if( xQueuePeek( xQueue, &( pxRxedMessage ), ( TickType_t ) 10 ) )
+ *      {
+ *          // pcRxedMessage now points to the struct AMessage variable posted
+ *          // by vATask, but the item still remains on the queue.
+ *      }
+ *  }
+ *
+ *  // ... Rest of task code.
+ * }
+ * 
+ * \defgroup xQueuePeek xQueuePeek + * \ingroup QueueManagement + */ +BaseType_t xQueuePeek( QueueHandle_t xQueue, + void * const pvBuffer, + TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; + +/** + * queue. h + *
+ * BaseType_t xQueuePeekFromISR(
+ *                                  QueueHandle_t xQueue,
+ *                                  void *pvBuffer,
+ *                              );
+ * 
+ * + * A version of xQueuePeek() that can be called from an interrupt service + * routine (ISR). + * + * Receive an item from a queue without removing the item from the queue. + * The item is received by copy so a buffer of adequate size must be + * provided. The number of bytes copied into the buffer was defined when + * the queue was created. + * + * Successfully received items remain on the queue so will be returned again + * by the next call, or a call to xQueueReceive(). + * + * @param xQueue The handle to the queue from which the item is to be + * received. + * + * @param pvBuffer Pointer to the buffer into which the received item will + * be copied. + * + * @return pdTRUE if an item was successfully received from the queue, + * otherwise pdFALSE. + * + * \defgroup xQueuePeekFromISR xQueuePeekFromISR + * \ingroup QueueManagement + */ +BaseType_t xQueuePeekFromISR( QueueHandle_t xQueue, + void * const pvBuffer ) PRIVILEGED_FUNCTION; + +/** + * queue. h + *
+ * BaseType_t xQueueReceive(
+ *                               QueueHandle_t xQueue,
+ *                               void *pvBuffer,
+ *                               TickType_t xTicksToWait
+ *                          );
+ * 
+ * + * Receive an item from a queue. The item is received by copy so a buffer of + * adequate size must be provided. The number of bytes copied into the buffer + * was defined when the queue was created. + * + * Successfully received items are removed from the queue. + * + * This function must not be used in an interrupt service routine. See + * xQueueReceiveFromISR for an alternative that can. + * + * @param xQueue The handle to the queue from which the item is to be + * received. + * + * @param pvBuffer Pointer to the buffer into which the received item will + * be copied. + * + * @param xTicksToWait The maximum amount of time the task should block + * waiting for an item to receive should the queue be empty at the time + * of the call. xQueueReceive() will return immediately if xTicksToWait + * is zero and the queue is empty. The time is defined in tick periods so the + * constant portTICK_PERIOD_MS should be used to convert to real time if this is + * required. + * + * @return pdTRUE if an item was successfully received from the queue, + * otherwise pdFALSE. + * + * Example usage: + *
+ * struct AMessage
+ * {
+ *  char ucMessageID;
+ *  char ucData[ 20 ];
+ * } xMessage;
+ *
+ * QueueHandle_t xQueue;
+ *
+ * // Task to create a queue and post a value.
+ * void vATask( void *pvParameters )
+ * {
+ * struct AMessage *pxMessage;
+ *
+ *  // Create a queue capable of containing 10 pointers to AMessage structures.
+ *  // These should be passed by pointer as they contain a lot of data.
+ *  xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
+ *  if( xQueue == 0 )
+ *  {
+ *      // Failed to create the queue.
+ *  }
+ *
+ *  // ...
+ *
+ *  // Send a pointer to a struct AMessage object.  Don't block if the
+ *  // queue is already full.
+ *  pxMessage = & xMessage;
+ *  xQueueSend( xQueue, ( void * ) &pxMessage, ( TickType_t ) 0 );
+ *
+ *  // ... Rest of task code.
+ * }
+ *
+ * // Task to receive from the queue.
+ * void vADifferentTask( void *pvParameters )
+ * {
+ * struct AMessage *pxRxedMessage;
+ *
+ *  if( xQueue != 0 )
+ *  {
+ *      // Receive a message on the created queue.  Block for 10 ticks if a
+ *      // message is not immediately available.
+ *      if( xQueueReceive( xQueue, &( pxRxedMessage ), ( TickType_t ) 10 ) )
+ *      {
+ *          // pcRxedMessage now points to the struct AMessage variable posted
+ *          // by vATask.
+ *      }
+ *  }
+ *
+ *  // ... Rest of task code.
+ * }
+ * 
+ * \defgroup xQueueReceive xQueueReceive + * \ingroup QueueManagement + */ +BaseType_t xQueueReceive( QueueHandle_t xQueue, + void * const pvBuffer, + TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; + +/** + * queue. h + *
+ * UBaseType_t uxQueueMessagesWaiting( const QueueHandle_t xQueue );
+ * 
+ * + * Return the number of messages stored in a queue. + * + * @param xQueue A handle to the queue being queried. + * + * @return The number of messages available in the queue. + * + * \defgroup uxQueueMessagesWaiting uxQueueMessagesWaiting + * \ingroup QueueManagement + */ +UBaseType_t uxQueueMessagesWaiting( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION; + +/** + * queue. h + *
+ * UBaseType_t uxQueueSpacesAvailable( const QueueHandle_t xQueue );
+ * 
+ * + * Return the number of free spaces available in a queue. This is equal to the + * number of items that can be sent to the queue before the queue becomes full + * if no items are removed. + * + * @param xQueue A handle to the queue being queried. + * + * @return The number of spaces available in the queue. + * + * \defgroup uxQueueMessagesWaiting uxQueueMessagesWaiting + * \ingroup QueueManagement + */ +UBaseType_t uxQueueSpacesAvailable( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION; + +/** + * queue. h + *
+ * void vQueueDelete( QueueHandle_t xQueue );
+ * 
+ * + * Delete a queue - freeing all the memory allocated for storing of items + * placed on the queue. + * + * @param xQueue A handle to the queue to be deleted. + * + * \defgroup vQueueDelete vQueueDelete + * \ingroup QueueManagement + */ +void vQueueDelete( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION; + +/** + * queue. h + *
+ * BaseType_t xQueueSendToFrontFromISR(
+ *                                       QueueHandle_t xQueue,
+ *                                       const void *pvItemToQueue,
+ *                                       BaseType_t *pxHigherPriorityTaskWoken
+ *                                    );
+ * 
+ * + * This is a macro that calls xQueueGenericSendFromISR(). + * + * Post an item to the front of a queue. It is safe to use this macro from + * within an interrupt service routine. + * + * Items are queued by copy not reference so it is preferable to only + * queue small items, especially when called from an ISR. In most cases + * it would be preferable to store a pointer to the item being queued. + * + * @param xQueue The handle to the queue on which the item is to be posted. + * + * @param pvItemToQueue A pointer to the item that is to be placed on the + * queue. The size of the items the queue will hold was defined when the + * queue was created, so this many bytes will be copied from pvItemToQueue + * into the queue storage area. + * + * @param pxHigherPriorityTaskWoken xQueueSendToFrontFromISR() will set + * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task + * to unblock, and the unblocked task has a priority higher than the currently + * running task. If xQueueSendToFromFromISR() sets this value to pdTRUE then + * a context switch should be requested before the interrupt is exited. + * + * @return pdTRUE if the data was successfully sent to the queue, otherwise + * errQUEUE_FULL. + * + * Example usage for buffered IO (where the ISR can obtain more than one value + * per call): + *
+ * void vBufferISR( void )
+ * {
+ * char cIn;
+ * BaseType_t xHigherPrioritTaskWoken;
+ *
+ *  // We have not woken a task at the start of the ISR.
+ *  xHigherPriorityTaskWoken = pdFALSE;
+ *
+ *  // Loop until the buffer is empty.
+ *  do
+ *  {
+ *      // Obtain a byte from the buffer.
+ *      cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
+ *
+ *      // Post the byte.
+ *      xQueueSendToFrontFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
+ *
+ *  } while( portINPUT_BYTE( BUFFER_COUNT ) );
+ *
+ *  // Now the buffer is empty we can switch context if necessary.
+ *  if( xHigherPriorityTaskWoken )
+ *  {
+ *      taskYIELD ();
+ *  }
+ * }
+ * 
+ * + * \defgroup xQueueSendFromISR xQueueSendFromISR + * \ingroup QueueManagement + */ +#define xQueueSendToFrontFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) \ + xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_FRONT ) + + +/** + * queue. h + *
+ * BaseType_t xQueueSendToBackFromISR(
+ *                                       QueueHandle_t xQueue,
+ *                                       const void *pvItemToQueue,
+ *                                       BaseType_t *pxHigherPriorityTaskWoken
+ *                                    );
+ * 
+ * + * This is a macro that calls xQueueGenericSendFromISR(). + * + * Post an item to the back of a queue. It is safe to use this macro from + * within an interrupt service routine. + * + * Items are queued by copy not reference so it is preferable to only + * queue small items, especially when called from an ISR. In most cases + * it would be preferable to store a pointer to the item being queued. + * + * @param xQueue The handle to the queue on which the item is to be posted. + * + * @param pvItemToQueue A pointer to the item that is to be placed on the + * queue. The size of the items the queue will hold was defined when the + * queue was created, so this many bytes will be copied from pvItemToQueue + * into the queue storage area. + * + * @param pxHigherPriorityTaskWoken xQueueSendToBackFromISR() will set + * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task + * to unblock, and the unblocked task has a priority higher than the currently + * running task. If xQueueSendToBackFromISR() sets this value to pdTRUE then + * a context switch should be requested before the interrupt is exited. + * + * @return pdTRUE if the data was successfully sent to the queue, otherwise + * errQUEUE_FULL. + * + * Example usage for buffered IO (where the ISR can obtain more than one value + * per call): + *
+ * void vBufferISR( void )
+ * {
+ * char cIn;
+ * BaseType_t xHigherPriorityTaskWoken;
+ *
+ *  // We have not woken a task at the start of the ISR.
+ *  xHigherPriorityTaskWoken = pdFALSE;
+ *
+ *  // Loop until the buffer is empty.
+ *  do
+ *  {
+ *      // Obtain a byte from the buffer.
+ *      cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
+ *
+ *      // Post the byte.
+ *      xQueueSendToBackFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
+ *
+ *  } while( portINPUT_BYTE( BUFFER_COUNT ) );
+ *
+ *  // Now the buffer is empty we can switch context if necessary.
+ *  if( xHigherPriorityTaskWoken )
+ *  {
+ *      taskYIELD ();
+ *  }
+ * }
+ * 
+ * + * \defgroup xQueueSendFromISR xQueueSendFromISR + * \ingroup QueueManagement + */ +#define xQueueSendToBackFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) \ + xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK ) + +/** + * queue. h + *
+ * BaseType_t xQueueOverwriteFromISR(
+ *                            QueueHandle_t xQueue,
+ *                            const void * pvItemToQueue,
+ *                            BaseType_t *pxHigherPriorityTaskWoken
+ *                       );
+ * 
+ * + * A version of xQueueOverwrite() that can be used in an interrupt service + * routine (ISR). + * + * Only for use with queues that can hold a single item - so the queue is either + * empty or full. + * + * Post an item on a queue. If the queue is already full then overwrite the + * value held in the queue. The item is queued by copy, not by reference. + * + * @param xQueue The handle to the queue on which the item is to be posted. + * + * @param pvItemToQueue A pointer to the item that is to be placed on the + * queue. The size of the items the queue will hold was defined when the + * queue was created, so this many bytes will be copied from pvItemToQueue + * into the queue storage area. + * + * @param pxHigherPriorityTaskWoken xQueueOverwriteFromISR() will set + * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task + * to unblock, and the unblocked task has a priority higher than the currently + * running task. If xQueueOverwriteFromISR() sets this value to pdTRUE then + * a context switch should be requested before the interrupt is exited. + * + * @return xQueueOverwriteFromISR() is a macro that calls + * xQueueGenericSendFromISR(), and therefore has the same return values as + * xQueueSendToFrontFromISR(). However, pdPASS is the only value that can be + * returned because xQueueOverwriteFromISR() will write to the queue even when + * the queue is already full. + * + * Example usage: + *
+ *
+ * QueueHandle_t xQueue;
+ *
+ * void vFunction( void *pvParameters )
+ * {
+ *  // Create a queue to hold one uint32_t value.  It is strongly
+ *  // recommended *not* to use xQueueOverwriteFromISR() on queues that can
+ *  // contain more than one value, and doing so will trigger an assertion
+ *  // if configASSERT() is defined.
+ *  xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
+ * }
+ *
+ * void vAnInterruptHandler( void )
+ * {
+ * // xHigherPriorityTaskWoken must be set to pdFALSE before it is used.
+ * BaseType_t xHigherPriorityTaskWoken = pdFALSE;
+ * uint32_t ulVarToSend, ulValReceived;
+ *
+ *  // Write the value 10 to the queue using xQueueOverwriteFromISR().
+ *  ulVarToSend = 10;
+ *  xQueueOverwriteFromISR( xQueue, &ulVarToSend, &xHigherPriorityTaskWoken );
+ *
+ *  // The queue is full, but calling xQueueOverwriteFromISR() again will still
+ *  // pass because the value held in the queue will be overwritten with the
+ *  // new value.
+ *  ulVarToSend = 100;
+ *  xQueueOverwriteFromISR( xQueue, &ulVarToSend, &xHigherPriorityTaskWoken );
+ *
+ *  // Reading from the queue will now return 100.
+ *
+ *  // ...
+ *
+ *  if( xHigherPrioritytaskWoken == pdTRUE )
+ *  {
+ *      // Writing to the queue caused a task to unblock and the unblocked task
+ *      // has a priority higher than or equal to the priority of the currently
+ *      // executing task (the task this interrupt interrupted).  Perform a context
+ *      // switch so this interrupt returns directly to the unblocked task.
+ *      portYIELD_FROM_ISR(); // or portEND_SWITCHING_ISR() depending on the port.
+ *  }
+ * }
+ * 
+ * \defgroup xQueueOverwriteFromISR xQueueOverwriteFromISR + * \ingroup QueueManagement + */ +#define xQueueOverwriteFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) \ + xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueOVERWRITE ) + +/** + * queue. h + *
+ * BaseType_t xQueueSendFromISR(
+ *                                   QueueHandle_t xQueue,
+ *                                   const void *pvItemToQueue,
+ *                                   BaseType_t *pxHigherPriorityTaskWoken
+ *                              );
+ * 
+ * + * This is a macro that calls xQueueGenericSendFromISR(). It is included + * for backward compatibility with versions of FreeRTOS.org that did not + * include the xQueueSendToBackFromISR() and xQueueSendToFrontFromISR() + * macros. + * + * Post an item to the back of a queue. It is safe to use this function from + * within an interrupt service routine. + * + * Items are queued by copy not reference so it is preferable to only + * queue small items, especially when called from an ISR. In most cases + * it would be preferable to store a pointer to the item being queued. + * + * @param xQueue The handle to the queue on which the item is to be posted. + * + * @param pvItemToQueue A pointer to the item that is to be placed on the + * queue. The size of the items the queue will hold was defined when the + * queue was created, so this many bytes will be copied from pvItemToQueue + * into the queue storage area. + * + * @param pxHigherPriorityTaskWoken xQueueSendFromISR() will set + * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task + * to unblock, and the unblocked task has a priority higher than the currently + * running task. If xQueueSendFromISR() sets this value to pdTRUE then + * a context switch should be requested before the interrupt is exited. + * + * @return pdTRUE if the data was successfully sent to the queue, otherwise + * errQUEUE_FULL. + * + * Example usage for buffered IO (where the ISR can obtain more than one value + * per call): + *
+ * void vBufferISR( void )
+ * {
+ * char cIn;
+ * BaseType_t xHigherPriorityTaskWoken;
+ *
+ *  // We have not woken a task at the start of the ISR.
+ *  xHigherPriorityTaskWoken = pdFALSE;
+ *
+ *  // Loop until the buffer is empty.
+ *  do
+ *  {
+ *      // Obtain a byte from the buffer.
+ *      cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
+ *
+ *      // Post the byte.
+ *      xQueueSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
+ *
+ *  } while( portINPUT_BYTE( BUFFER_COUNT ) );
+ *
+ *  // Now the buffer is empty we can switch context if necessary.
+ *  if( xHigherPriorityTaskWoken )
+ *  {
+ *      // Actual macro used here is port specific.
+ *      portYIELD_FROM_ISR ();
+ *  }
+ * }
+ * 
+ * + * \defgroup xQueueSendFromISR xQueueSendFromISR + * \ingroup QueueManagement + */ +#define xQueueSendFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) \ + xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK ) + +/** + * queue. h + *
+ * BaseType_t xQueueGenericSendFromISR(
+ *                                         QueueHandle_t    xQueue,
+ *                                         const    void    *pvItemToQueue,
+ *                                         BaseType_t  *pxHigherPriorityTaskWoken,
+ *                                         BaseType_t  xCopyPosition
+ *                                     );
+ * 
+ * + * It is preferred that the macros xQueueSendFromISR(), + * xQueueSendToFrontFromISR() and xQueueSendToBackFromISR() be used in place + * of calling this function directly. xQueueGiveFromISR() is an + * equivalent for use by semaphores that don't actually copy any data. + * + * Post an item on a queue. It is safe to use this function from within an + * interrupt service routine. + * + * Items are queued by copy not reference so it is preferable to only + * queue small items, especially when called from an ISR. In most cases + * it would be preferable to store a pointer to the item being queued. + * + * @param xQueue The handle to the queue on which the item is to be posted. + * + * @param pvItemToQueue A pointer to the item that is to be placed on the + * queue. The size of the items the queue will hold was defined when the + * queue was created, so this many bytes will be copied from pvItemToQueue + * into the queue storage area. + * + * @param pxHigherPriorityTaskWoken xQueueGenericSendFromISR() will set + * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task + * to unblock, and the unblocked task has a priority higher than the currently + * running task. If xQueueGenericSendFromISR() sets this value to pdTRUE then + * a context switch should be requested before the interrupt is exited. + * + * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the + * item at the back of the queue, or queueSEND_TO_FRONT to place the item + * at the front of the queue (for high priority messages). + * + * @return pdTRUE if the data was successfully sent to the queue, otherwise + * errQUEUE_FULL. + * + * Example usage for buffered IO (where the ISR can obtain more than one value + * per call): + *
+ * void vBufferISR( void )
+ * {
+ * char cIn;
+ * BaseType_t xHigherPriorityTaskWokenByPost;
+ *
+ *  // We have not woken a task at the start of the ISR.
+ *  xHigherPriorityTaskWokenByPost = pdFALSE;
+ *
+ *  // Loop until the buffer is empty.
+ *  do
+ *  {
+ *      // Obtain a byte from the buffer.
+ *      cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
+ *
+ *      // Post each byte.
+ *      xQueueGenericSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWokenByPost, queueSEND_TO_BACK );
+ *
+ *  } while( portINPUT_BYTE( BUFFER_COUNT ) );
+ *
+ *  // Now the buffer is empty we can switch context if necessary.  Note that the
+ *  // name of the yield function required is port specific.
+ *  if( xHigherPriorityTaskWokenByPost )
+ *  {
+ *      portYIELD_FROM_ISR();
+ *  }
+ * }
+ * 
+ * + * \defgroup xQueueSendFromISR xQueueSendFromISR + * \ingroup QueueManagement + */ +BaseType_t xQueueGenericSendFromISR( QueueHandle_t xQueue, + const void * const pvItemToQueue, + BaseType_t * const pxHigherPriorityTaskWoken, + const BaseType_t xCopyPosition ) PRIVILEGED_FUNCTION; +BaseType_t xQueueGiveFromISR( QueueHandle_t xQueue, + BaseType_t * const pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION; + +/** + * queue. h + *
+ * BaseType_t xQueueReceiveFromISR(
+ *                                     QueueHandle_t    xQueue,
+ *                                     void             *pvBuffer,
+ *                                     BaseType_t       *pxTaskWoken
+ *                                 );
+ * 
+ * + * Receive an item from a queue. It is safe to use this function from within an + * interrupt service routine. + * + * @param xQueue The handle to the queue from which the item is to be + * received. + * + * @param pvBuffer Pointer to the buffer into which the received item will + * be copied. + * + * @param pxTaskWoken A task may be blocked waiting for space to become + * available on the queue. If xQueueReceiveFromISR causes such a task to + * unblock *pxTaskWoken will get set to pdTRUE, otherwise *pxTaskWoken will + * remain unchanged. + * + * @return pdTRUE if an item was successfully received from the queue, + * otherwise pdFALSE. + * + * Example usage: + *
+ *
+ * QueueHandle_t xQueue;
+ *
+ * // Function to create a queue and post some values.
+ * void vAFunction( void *pvParameters )
+ * {
+ * char cValueToPost;
+ * const TickType_t xTicksToWait = ( TickType_t )0xff;
+ *
+ *  // Create a queue capable of containing 10 characters.
+ *  xQueue = xQueueCreate( 10, sizeof( char ) );
+ *  if( xQueue == 0 )
+ *  {
+ *      // Failed to create the queue.
+ *  }
+ *
+ *  // ...
+ *
+ *  // Post some characters that will be used within an ISR.  If the queue
+ *  // is full then this task will block for xTicksToWait ticks.
+ *  cValueToPost = 'a';
+ *  xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );
+ *  cValueToPost = 'b';
+ *  xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );
+ *
+ *  // ... keep posting characters ... this task may block when the queue
+ *  // becomes full.
+ *
+ *  cValueToPost = 'c';
+ *  xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );
+ * }
+ *
+ * // ISR that outputs all the characters received on the queue.
+ * void vISR_Routine( void )
+ * {
+ * BaseType_t xTaskWokenByReceive = pdFALSE;
+ * char cRxedChar;
+ *
+ *  while( xQueueReceiveFromISR( xQueue, ( void * ) &cRxedChar, &xTaskWokenByReceive) )
+ *  {
+ *      // A character was received.  Output the character now.
+ *      vOutputCharacter( cRxedChar );
+ *
+ *      // If removing the character from the queue woke the task that was
+ *      // posting onto the queue cTaskWokenByReceive will have been set to
+ *      // pdTRUE.  No matter how many times this loop iterates only one
+ *      // task will be woken.
+ *  }
+ *
+ *  if( cTaskWokenByPost != ( char ) pdFALSE;
+ *  {
+ *      taskYIELD ();
+ *  }
+ * }
+ * 
+ * \defgroup xQueueReceiveFromISR xQueueReceiveFromISR + * \ingroup QueueManagement + */ +BaseType_t xQueueReceiveFromISR( QueueHandle_t xQueue, + void * const pvBuffer, + BaseType_t * const pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION; + +/* + * Utilities to query queues that are safe to use from an ISR. These utilities + * should be used only from witin an ISR, or within a critical section. + */ +BaseType_t xQueueIsQueueEmptyFromISR( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION; +BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION; +UBaseType_t uxQueueMessagesWaitingFromISR( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION; + +/* + * The functions defined above are for passing data to and from tasks. The + * functions below are the equivalents for passing data to and from + * co-routines. + * + * These functions are called from the co-routine macro implementation and + * should not be called directly from application code. Instead use the macro + * wrappers defined within croutine.h. + */ +BaseType_t xQueueCRSendFromISR( QueueHandle_t xQueue, + const void * pvItemToQueue, + BaseType_t xCoRoutinePreviouslyWoken ); +BaseType_t xQueueCRReceiveFromISR( QueueHandle_t xQueue, + void * pvBuffer, + BaseType_t * pxTaskWoken ); +BaseType_t xQueueCRSend( QueueHandle_t xQueue, + const void * pvItemToQueue, + TickType_t xTicksToWait ); +BaseType_t xQueueCRReceive( QueueHandle_t xQueue, + void * pvBuffer, + TickType_t xTicksToWait ); + +/* + * For internal use only. Use xSemaphoreCreateMutex(), + * xSemaphoreCreateCounting() or xSemaphoreGetMutexHolder() instead of calling + * these functions directly. + */ +QueueHandle_t xQueueCreateMutex( const uint8_t ucQueueType ) PRIVILEGED_FUNCTION; +QueueHandle_t xQueueCreateMutexStatic( const uint8_t ucQueueType, + StaticQueue_t * pxStaticQueue ) PRIVILEGED_FUNCTION; +QueueHandle_t xQueueCreateCountingSemaphore( const UBaseType_t uxMaxCount, + const UBaseType_t uxInitialCount ) PRIVILEGED_FUNCTION; +QueueHandle_t xQueueCreateCountingSemaphoreStatic( const UBaseType_t uxMaxCount, + const UBaseType_t uxInitialCount, + StaticQueue_t * pxStaticQueue ) PRIVILEGED_FUNCTION; +BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue, + TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; +TaskHandle_t xQueueGetMutexHolder( QueueHandle_t xSemaphore ) PRIVILEGED_FUNCTION; +TaskHandle_t xQueueGetMutexHolderFromISR( QueueHandle_t xSemaphore ) PRIVILEGED_FUNCTION; + +/* + * For internal use only. Use xSemaphoreTakeMutexRecursive() or + * xSemaphoreGiveMutexRecursive() instead of calling these functions directly. + */ +BaseType_t xQueueTakeMutexRecursive( QueueHandle_t xMutex, + TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; +BaseType_t xQueueGiveMutexRecursive( QueueHandle_t xMutex ) PRIVILEGED_FUNCTION; + +/* + * Reset a queue back to its original empty state. The return value is now + * obsolete and is always set to pdPASS. + */ +#define xQueueReset( xQueue ) xQueueGenericReset( xQueue, pdFALSE ) + +/* + * The registry is provided as a means for kernel aware debuggers to + * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add + * a queue, semaphore or mutex handle to the registry if you want the handle + * to be available to a kernel aware debugger. If you are not using a kernel + * aware debugger then this function can be ignored. + * + * configQUEUE_REGISTRY_SIZE defines the maximum number of handles the + * registry can hold. configQUEUE_REGISTRY_SIZE must be greater than 0 + * within FreeRTOSConfig.h for the registry to be available. Its value + * does not effect the number of queues, semaphores and mutexes that can be + * created - just the number that the registry can hold. + * + * @param xQueue The handle of the queue being added to the registry. This + * is the handle returned by a call to xQueueCreate(). Semaphore and mutex + * handles can also be passed in here. + * + * @param pcName The name to be associated with the handle. This is the + * name that the kernel aware debugger will display. The queue registry only + * stores a pointer to the string - so the string must be persistent (global or + * preferably in ROM/Flash), not on the stack. + */ +#if ( configQUEUE_REGISTRY_SIZE > 0 ) + void vQueueAddToRegistry( QueueHandle_t xQueue, + const char * pcQueueName ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ +#endif + +/* + * The registry is provided as a means for kernel aware debuggers to + * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add + * a queue, semaphore or mutex handle to the registry if you want the handle + * to be available to a kernel aware debugger, and vQueueUnregisterQueue() to + * remove the queue, semaphore or mutex from the register. If you are not using + * a kernel aware debugger then this function can be ignored. + * + * @param xQueue The handle of the queue being removed from the registry. + */ +#if ( configQUEUE_REGISTRY_SIZE > 0 ) + void vQueueUnregisterQueue( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION; +#endif + +/* + * The queue registry is provided as a means for kernel aware debuggers to + * locate queues, semaphores and mutexes. Call pcQueueGetName() to look + * up and return the name of a queue in the queue registry from the queue's + * handle. + * + * @param xQueue The handle of the queue the name of which will be returned. + * @return If the queue is in the registry then a pointer to the name of the + * queue is returned. If the queue is not in the registry then NULL is + * returned. + */ +#if ( configQUEUE_REGISTRY_SIZE > 0 ) + const char * pcQueueGetName( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ +#endif + +/* + * Generic version of the function used to create a queue using dynamic memory + * allocation. This is called by other functions and macros that create other + * RTOS objects that use the queue structure as their base. + */ +#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + QueueHandle_t xQueueGenericCreate( const UBaseType_t uxQueueLength, + const UBaseType_t uxItemSize, + const uint8_t ucQueueType ) PRIVILEGED_FUNCTION; +#endif + +/* + * Generic version of the function used to create a queue using dynamic memory + * allocation. This is called by other functions and macros that create other + * RTOS objects that use the queue structure as their base. + */ +#if ( configSUPPORT_STATIC_ALLOCATION == 1 ) + QueueHandle_t xQueueGenericCreateStatic( const UBaseType_t uxQueueLength, + const UBaseType_t uxItemSize, + uint8_t * pucQueueStorage, + StaticQueue_t * pxStaticQueue, + const uint8_t ucQueueType ) PRIVILEGED_FUNCTION; +#endif + +/* + * Queue sets provide a mechanism to allow a task to block (pend) on a read + * operation from multiple queues or semaphores simultaneously. + * + * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this + * function. + * + * A queue set must be explicitly created using a call to xQueueCreateSet() + * before it can be used. Once created, standard FreeRTOS queues and semaphores + * can be added to the set using calls to xQueueAddToSet(). + * xQueueSelectFromSet() is then used to determine which, if any, of the queues + * or semaphores contained in the set is in a state where a queue read or + * semaphore take operation would be successful. + * + * Note 1: See the documentation on http://wwwFreeRTOS.org/RTOS-queue-sets.html + * for reasons why queue sets are very rarely needed in practice as there are + * simpler methods of blocking on multiple objects. + * + * Note 2: Blocking on a queue set that contains a mutex will not cause the + * mutex holder to inherit the priority of the blocked task. + * + * Note 3: An additional 4 bytes of RAM is required for each space in a every + * queue added to a queue set. Therefore counting semaphores that have a high + * maximum count value should not be added to a queue set. + * + * Note 4: A receive (in the case of a queue) or take (in the case of a + * semaphore) operation must not be performed on a member of a queue set unless + * a call to xQueueSelectFromSet() has first returned a handle to that set member. + * + * @param uxEventQueueLength Queue sets store events that occur on + * the queues and semaphores contained in the set. uxEventQueueLength specifies + * the maximum number of events that can be queued at once. To be absolutely + * certain that events are not lost uxEventQueueLength should be set to the + * total sum of the length of the queues added to the set, where binary + * semaphores and mutexes have a length of 1, and counting semaphores have a + * length set by their maximum count value. Examples: + * + If a queue set is to hold a queue of length 5, another queue of length 12, + * and a binary semaphore, then uxEventQueueLength should be set to + * (5 + 12 + 1), or 18. + * + If a queue set is to hold three binary semaphores then uxEventQueueLength + * should be set to (1 + 1 + 1 ), or 3. + * + If a queue set is to hold a counting semaphore that has a maximum count of + * 5, and a counting semaphore that has a maximum count of 3, then + * uxEventQueueLength should be set to (5 + 3), or 8. + * + * @return If the queue set is created successfully then a handle to the created + * queue set is returned. Otherwise NULL is returned. + */ +QueueSetHandle_t xQueueCreateSet( const UBaseType_t uxEventQueueLength ) PRIVILEGED_FUNCTION; + +/* + * Adds a queue or semaphore to a queue set that was previously created by a + * call to xQueueCreateSet(). + * + * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this + * function. + * + * Note 1: A receive (in the case of a queue) or take (in the case of a + * semaphore) operation must not be performed on a member of a queue set unless + * a call to xQueueSelectFromSet() has first returned a handle to that set member. + * + * @param xQueueOrSemaphore The handle of the queue or semaphore being added to + * the queue set (cast to an QueueSetMemberHandle_t type). + * + * @param xQueueSet The handle of the queue set to which the queue or semaphore + * is being added. + * + * @return If the queue or semaphore was successfully added to the queue set + * then pdPASS is returned. If the queue could not be successfully added to the + * queue set because it is already a member of a different queue set then pdFAIL + * is returned. + */ +BaseType_t xQueueAddToSet( QueueSetMemberHandle_t xQueueOrSemaphore, + QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION; + +/* + * Removes a queue or semaphore from a queue set. A queue or semaphore can only + * be removed from a set if the queue or semaphore is empty. + * + * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this + * function. + * + * @param xQueueOrSemaphore The handle of the queue or semaphore being removed + * from the queue set (cast to an QueueSetMemberHandle_t type). + * + * @param xQueueSet The handle of the queue set in which the queue or semaphore + * is included. + * + * @return If the queue or semaphore was successfully removed from the queue set + * then pdPASS is returned. If the queue was not in the queue set, or the + * queue (or semaphore) was not empty, then pdFAIL is returned. + */ +BaseType_t xQueueRemoveFromSet( QueueSetMemberHandle_t xQueueOrSemaphore, + QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION; + +/* + * xQueueSelectFromSet() selects from the members of a queue set a queue or + * semaphore that either contains data (in the case of a queue) or is available + * to take (in the case of a semaphore). xQueueSelectFromSet() effectively + * allows a task to block (pend) on a read operation on all the queues and + * semaphores in a queue set simultaneously. + * + * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this + * function. + * + * Note 1: See the documentation on http://wwwFreeRTOS.org/RTOS-queue-sets.html + * for reasons why queue sets are very rarely needed in practice as there are + * simpler methods of blocking on multiple objects. + * + * Note 2: Blocking on a queue set that contains a mutex will not cause the + * mutex holder to inherit the priority of the blocked task. + * + * Note 3: A receive (in the case of a queue) or take (in the case of a + * semaphore) operation must not be performed on a member of a queue set unless + * a call to xQueueSelectFromSet() has first returned a handle to that set member. + * + * @param xQueueSet The queue set on which the task will (potentially) block. + * + * @param xTicksToWait The maximum time, in ticks, that the calling task will + * remain in the Blocked state (with other tasks executing) to wait for a member + * of the queue set to be ready for a successful queue read or semaphore take + * operation. + * + * @return xQueueSelectFromSet() will return the handle of a queue (cast to + * a QueueSetMemberHandle_t type) contained in the queue set that contains data, + * or the handle of a semaphore (cast to a QueueSetMemberHandle_t type) contained + * in the queue set that is available, or NULL if no such queue or semaphore + * exists before before the specified block time expires. + */ +QueueSetMemberHandle_t xQueueSelectFromSet( QueueSetHandle_t xQueueSet, + const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; + +/* + * A version of xQueueSelectFromSet() that can be used from an ISR. + */ +QueueSetMemberHandle_t xQueueSelectFromSetFromISR( QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION; + +/* Not public API functions. */ +void vQueueWaitForMessageRestricted( QueueHandle_t xQueue, + TickType_t xTicksToWait, + const BaseType_t xWaitIndefinitely ) PRIVILEGED_FUNCTION; +BaseType_t xQueueGenericReset( QueueHandle_t xQueue, + BaseType_t xNewQueue ) PRIVILEGED_FUNCTION; +void vQueueSetQueueNumber( QueueHandle_t xQueue, + UBaseType_t uxQueueNumber ) PRIVILEGED_FUNCTION; +UBaseType_t uxQueueGetQueueNumber( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION; +uint8_t ucQueueGetQueueType( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION; + + +/* *INDENT-OFF* */ +#ifdef __cplusplus + } +#endif +/* *INDENT-ON* */ + +#endif /* QUEUE_H */ diff --git a/RTOS/FreeRTOS/Source/include/semphr.h b/RTOS/FreeRTOS/Source/include/semphr.h new file mode 100644 index 0000000..06e248b --- /dev/null +++ b/RTOS/FreeRTOS/Source/include/semphr.h @@ -0,0 +1,1173 @@ +/* + * FreeRTOS Kernel V10.4.1 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * https://www.FreeRTOS.org + * https://github.com/FreeRTOS + * + */ + +#ifndef SEMAPHORE_H +#define SEMAPHORE_H + +#ifndef INC_FREERTOS_H + #error "include FreeRTOS.h" must appear in source files before "include semphr.h" +#endif + +#include "queue.h" + +typedef QueueHandle_t SemaphoreHandle_t; + +#define semBINARY_SEMAPHORE_QUEUE_LENGTH ( ( uint8_t ) 1U ) +#define semSEMAPHORE_QUEUE_ITEM_LENGTH ( ( uint8_t ) 0U ) +#define semGIVE_BLOCK_TIME ( ( TickType_t ) 0U ) + + +/** + * semphr. h + *
+ * vSemaphoreCreateBinary( SemaphoreHandle_t xSemaphore );
+ * 
+ * + * In many usage scenarios it is faster and more memory efficient to use a + * direct to task notification in place of a binary semaphore! + * https://www.FreeRTOS.org/RTOS-task-notifications.html + * + * This old vSemaphoreCreateBinary() macro is now deprecated in favour of the + * xSemaphoreCreateBinary() function. Note that binary semaphores created using + * the vSemaphoreCreateBinary() macro are created in a state such that the + * first call to 'take' the semaphore would pass, whereas binary semaphores + * created using xSemaphoreCreateBinary() are created in a state such that the + * the semaphore must first be 'given' before it can be 'taken'. + * + * Macro that implements a semaphore by using the existing queue mechanism. + * The queue length is 1 as this is a binary semaphore. The data size is 0 + * as we don't want to actually store any data - we just want to know if the + * queue is empty or full. + * + * This type of semaphore can be used for pure synchronisation between tasks or + * between an interrupt and a task. The semaphore need not be given back once + * obtained, so one task/interrupt can continuously 'give' the semaphore while + * another continuously 'takes' the semaphore. For this reason this type of + * semaphore does not use a priority inheritance mechanism. For an alternative + * that does use priority inheritance see xSemaphoreCreateMutex(). + * + * @param xSemaphore Handle to the created semaphore. Should be of type SemaphoreHandle_t. + * + * Example usage: + *
+ * SemaphoreHandle_t xSemaphore = NULL;
+ *
+ * void vATask( void * pvParameters )
+ * {
+ *  // Semaphore cannot be used before a call to vSemaphoreCreateBinary ().
+ *  // This is a macro so pass the variable in directly.
+ *  vSemaphoreCreateBinary( xSemaphore );
+ *
+ *  if( xSemaphore != NULL )
+ *  {
+ *      // The semaphore was created successfully.
+ *      // The semaphore can now be used.
+ *  }
+ * }
+ * 
+ * \defgroup vSemaphoreCreateBinary vSemaphoreCreateBinary + * \ingroup Semaphores + */ +#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + #define vSemaphoreCreateBinary( xSemaphore ) \ + { \ + ( xSemaphore ) = xQueueGenericCreate( ( UBaseType_t ) 1, semSEMAPHORE_QUEUE_ITEM_LENGTH, queueQUEUE_TYPE_BINARY_SEMAPHORE ); \ + if( ( xSemaphore ) != NULL ) \ + { \ + ( void ) xSemaphoreGive( ( xSemaphore ) ); \ + } \ + } +#endif + +/** + * semphr. h + *
+ * SemaphoreHandle_t xSemaphoreCreateBinary( void );
+ * 
+ * + * Creates a new binary semaphore instance, and returns a handle by which the + * new semaphore can be referenced. + * + * In many usage scenarios it is faster and more memory efficient to use a + * direct to task notification in place of a binary semaphore! + * https://www.FreeRTOS.org/RTOS-task-notifications.html + * + * Internally, within the FreeRTOS implementation, binary semaphores use a block + * of memory, in which the semaphore structure is stored. If a binary semaphore + * is created using xSemaphoreCreateBinary() then the required memory is + * automatically dynamically allocated inside the xSemaphoreCreateBinary() + * function. (see https://www.FreeRTOS.org/a00111.html). If a binary semaphore + * is created using xSemaphoreCreateBinaryStatic() then the application writer + * must provide the memory. xSemaphoreCreateBinaryStatic() therefore allows a + * binary semaphore to be created without using any dynamic memory allocation. + * + * The old vSemaphoreCreateBinary() macro is now deprecated in favour of this + * xSemaphoreCreateBinary() function. Note that binary semaphores created using + * the vSemaphoreCreateBinary() macro are created in a state such that the + * first call to 'take' the semaphore would pass, whereas binary semaphores + * created using xSemaphoreCreateBinary() are created in a state such that the + * the semaphore must first be 'given' before it can be 'taken'. + * + * This type of semaphore can be used for pure synchronisation between tasks or + * between an interrupt and a task. The semaphore need not be given back once + * obtained, so one task/interrupt can continuously 'give' the semaphore while + * another continuously 'takes' the semaphore. For this reason this type of + * semaphore does not use a priority inheritance mechanism. For an alternative + * that does use priority inheritance see xSemaphoreCreateMutex(). + * + * @return Handle to the created semaphore, or NULL if the memory required to + * hold the semaphore's data structures could not be allocated. + * + * Example usage: + *
+ * SemaphoreHandle_t xSemaphore = NULL;
+ *
+ * void vATask( void * pvParameters )
+ * {
+ *  // Semaphore cannot be used before a call to xSemaphoreCreateBinary().
+ *  // This is a macro so pass the variable in directly.
+ *  xSemaphore = xSemaphoreCreateBinary();
+ *
+ *  if( xSemaphore != NULL )
+ *  {
+ *      // The semaphore was created successfully.
+ *      // The semaphore can now be used.
+ *  }
+ * }
+ * 
+ * \defgroup xSemaphoreCreateBinary xSemaphoreCreateBinary + * \ingroup Semaphores + */ +#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + #define xSemaphoreCreateBinary() xQueueGenericCreate( ( UBaseType_t ) 1, semSEMAPHORE_QUEUE_ITEM_LENGTH, queueQUEUE_TYPE_BINARY_SEMAPHORE ) +#endif + +/** + * semphr. h + *
+ * SemaphoreHandle_t xSemaphoreCreateBinaryStatic( StaticSemaphore_t *pxSemaphoreBuffer );
+ * 
+ * + * Creates a new binary semaphore instance, and returns a handle by which the + * new semaphore can be referenced. + * + * NOTE: In many usage scenarios it is faster and more memory efficient to use a + * direct to task notification in place of a binary semaphore! + * https://www.FreeRTOS.org/RTOS-task-notifications.html + * + * Internally, within the FreeRTOS implementation, binary semaphores use a block + * of memory, in which the semaphore structure is stored. If a binary semaphore + * is created using xSemaphoreCreateBinary() then the required memory is + * automatically dynamically allocated inside the xSemaphoreCreateBinary() + * function. (see https://www.FreeRTOS.org/a00111.html). If a binary semaphore + * is created using xSemaphoreCreateBinaryStatic() then the application writer + * must provide the memory. xSemaphoreCreateBinaryStatic() therefore allows a + * binary semaphore to be created without using any dynamic memory allocation. + * + * This type of semaphore can be used for pure synchronisation between tasks or + * between an interrupt and a task. The semaphore need not be given back once + * obtained, so one task/interrupt can continuously 'give' the semaphore while + * another continuously 'takes' the semaphore. For this reason this type of + * semaphore does not use a priority inheritance mechanism. For an alternative + * that does use priority inheritance see xSemaphoreCreateMutex(). + * + * @param pxSemaphoreBuffer Must point to a variable of type StaticSemaphore_t, + * which will then be used to hold the semaphore's data structure, removing the + * need for the memory to be allocated dynamically. + * + * @return If the semaphore is created then a handle to the created semaphore is + * returned. If pxSemaphoreBuffer is NULL then NULL is returned. + * + * Example usage: + *
+ * SemaphoreHandle_t xSemaphore = NULL;
+ * StaticSemaphore_t xSemaphoreBuffer;
+ *
+ * void vATask( void * pvParameters )
+ * {
+ *  // Semaphore cannot be used before a call to xSemaphoreCreateBinary().
+ *  // The semaphore's data structures will be placed in the xSemaphoreBuffer
+ *  // variable, the address of which is passed into the function.  The
+ *  // function's parameter is not NULL, so the function will not attempt any
+ *  // dynamic memory allocation, and therefore the function will not return
+ *  // return NULL.
+ *  xSemaphore = xSemaphoreCreateBinary( &xSemaphoreBuffer );
+ *
+ *  // Rest of task code goes here.
+ * }
+ * 
+ * \defgroup xSemaphoreCreateBinaryStatic xSemaphoreCreateBinaryStatic + * \ingroup Semaphores + */ +#if ( configSUPPORT_STATIC_ALLOCATION == 1 ) + #define xSemaphoreCreateBinaryStatic( pxStaticSemaphore ) xQueueGenericCreateStatic( ( UBaseType_t ) 1, semSEMAPHORE_QUEUE_ITEM_LENGTH, NULL, pxStaticSemaphore, queueQUEUE_TYPE_BINARY_SEMAPHORE ) +#endif /* configSUPPORT_STATIC_ALLOCATION */ + +/** + * semphr. h + *
+ * xSemaphoreTake(
+ *                   SemaphoreHandle_t xSemaphore,
+ *                   TickType_t xBlockTime
+ *               );
+ * 
+ * + * Macro to obtain a semaphore. The semaphore must have previously been + * created with a call to xSemaphoreCreateBinary(), xSemaphoreCreateMutex() or + * xSemaphoreCreateCounting(). + * + * @param xSemaphore A handle to the semaphore being taken - obtained when + * the semaphore was created. + * + * @param xBlockTime The time in ticks to wait for the semaphore to become + * available. The macro portTICK_PERIOD_MS can be used to convert this to a + * real time. A block time of zero can be used to poll the semaphore. A block + * time of portMAX_DELAY can be used to block indefinitely (provided + * INCLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h). + * + * @return pdTRUE if the semaphore was obtained. pdFALSE + * if xBlockTime expired without the semaphore becoming available. + * + * Example usage: + *
+ * SemaphoreHandle_t xSemaphore = NULL;
+ *
+ * // A task that creates a semaphore.
+ * void vATask( void * pvParameters )
+ * {
+ *  // Create the semaphore to guard a shared resource.
+ *  xSemaphore = xSemaphoreCreateBinary();
+ * }
+ *
+ * // A task that uses the semaphore.
+ * void vAnotherTask( void * pvParameters )
+ * {
+ *  // ... Do other things.
+ *
+ *  if( xSemaphore != NULL )
+ *  {
+ *      // See if we can obtain the semaphore.  If the semaphore is not available
+ *      // wait 10 ticks to see if it becomes free.
+ *      if( xSemaphoreTake( xSemaphore, ( TickType_t ) 10 ) == pdTRUE )
+ *      {
+ *          // We were able to obtain the semaphore and can now access the
+ *          // shared resource.
+ *
+ *          // ...
+ *
+ *          // We have finished accessing the shared resource.  Release the
+ *          // semaphore.
+ *          xSemaphoreGive( xSemaphore );
+ *      }
+ *      else
+ *      {
+ *          // We could not obtain the semaphore and can therefore not access
+ *          // the shared resource safely.
+ *      }
+ *  }
+ * }
+ * 
+ * \defgroup xSemaphoreTake xSemaphoreTake + * \ingroup Semaphores + */ +#define xSemaphoreTake( xSemaphore, xBlockTime ) xQueueSemaphoreTake( ( xSemaphore ), ( xBlockTime ) ) + +/** + * semphr. h + *
+ * xSemaphoreTakeRecursive(
+ *                          SemaphoreHandle_t xMutex,
+ *                          TickType_t xBlockTime
+ *                        );
+ * 
+ * + * Macro to recursively obtain, or 'take', a mutex type semaphore. + * The mutex must have previously been created using a call to + * xSemaphoreCreateRecursiveMutex(); + * + * configUSE_RECURSIVE_MUTEXES must be set to 1 in FreeRTOSConfig.h for this + * macro to be available. + * + * This macro must not be used on mutexes created using xSemaphoreCreateMutex(). + * + * A mutex used recursively can be 'taken' repeatedly by the owner. The mutex + * doesn't become available again until the owner has called + * xSemaphoreGiveRecursive() for each successful 'take' request. For example, + * if a task successfully 'takes' the same mutex 5 times then the mutex will + * not be available to any other task until it has also 'given' the mutex back + * exactly five times. + * + * @param xMutex A handle to the mutex being obtained. This is the + * handle returned by xSemaphoreCreateRecursiveMutex(); + * + * @param xBlockTime The time in ticks to wait for the semaphore to become + * available. The macro portTICK_PERIOD_MS can be used to convert this to a + * real time. A block time of zero can be used to poll the semaphore. If + * the task already owns the semaphore then xSemaphoreTakeRecursive() will + * return immediately no matter what the value of xBlockTime. + * + * @return pdTRUE if the semaphore was obtained. pdFALSE if xBlockTime + * expired without the semaphore becoming available. + * + * Example usage: + *
+ * SemaphoreHandle_t xMutex = NULL;
+ *
+ * // A task that creates a mutex.
+ * void vATask( void * pvParameters )
+ * {
+ *  // Create the mutex to guard a shared resource.
+ *  xMutex = xSemaphoreCreateRecursiveMutex();
+ * }
+ *
+ * // A task that uses the mutex.
+ * void vAnotherTask( void * pvParameters )
+ * {
+ *  // ... Do other things.
+ *
+ *  if( xMutex != NULL )
+ *  {
+ *      // See if we can obtain the mutex.  If the mutex is not available
+ *      // wait 10 ticks to see if it becomes free.
+ *      if( xSemaphoreTakeRecursive( xSemaphore, ( TickType_t ) 10 ) == pdTRUE )
+ *      {
+ *          // We were able to obtain the mutex and can now access the
+ *          // shared resource.
+ *
+ *          // ...
+ *          // For some reason due to the nature of the code further calls to
+ *          // xSemaphoreTakeRecursive() are made on the same mutex.  In real
+ *          // code these would not be just sequential calls as this would make
+ *          // no sense.  Instead the calls are likely to be buried inside
+ *          // a more complex call structure.
+ *          xSemaphoreTakeRecursive( xMutex, ( TickType_t ) 10 );
+ *          xSemaphoreTakeRecursive( xMutex, ( TickType_t ) 10 );
+ *
+ *          // The mutex has now been 'taken' three times, so will not be
+ *          // available to another task until it has also been given back
+ *          // three times.  Again it is unlikely that real code would have
+ *          // these calls sequentially, but instead buried in a more complex
+ *          // call structure.  This is just for illustrative purposes.
+ *          xSemaphoreGiveRecursive( xMutex );
+ *          xSemaphoreGiveRecursive( xMutex );
+ *          xSemaphoreGiveRecursive( xMutex );
+ *
+ *          // Now the mutex can be taken by other tasks.
+ *      }
+ *      else
+ *      {
+ *          // We could not obtain the mutex and can therefore not access
+ *          // the shared resource safely.
+ *      }
+ *  }
+ * }
+ * 
+ * \defgroup xSemaphoreTakeRecursive xSemaphoreTakeRecursive + * \ingroup Semaphores + */ +#if ( configUSE_RECURSIVE_MUTEXES == 1 ) + #define xSemaphoreTakeRecursive( xMutex, xBlockTime ) xQueueTakeMutexRecursive( ( xMutex ), ( xBlockTime ) ) +#endif + +/** + * semphr. h + *
+ * xSemaphoreGive( SemaphoreHandle_t xSemaphore );
+ * 
+ * + * Macro to release a semaphore. The semaphore must have previously been + * created with a call to xSemaphoreCreateBinary(), xSemaphoreCreateMutex() or + * xSemaphoreCreateCounting(). and obtained using sSemaphoreTake(). + * + * This macro must not be used from an ISR. See xSemaphoreGiveFromISR () for + * an alternative which can be used from an ISR. + * + * This macro must also not be used on semaphores created using + * xSemaphoreCreateRecursiveMutex(). + * + * @param xSemaphore A handle to the semaphore being released. This is the + * handle returned when the semaphore was created. + * + * @return pdTRUE if the semaphore was released. pdFALSE if an error occurred. + * Semaphores are implemented using queues. An error can occur if there is + * no space on the queue to post a message - indicating that the + * semaphore was not first obtained correctly. + * + * Example usage: + *
+ * SemaphoreHandle_t xSemaphore = NULL;
+ *
+ * void vATask( void * pvParameters )
+ * {
+ *  // Create the semaphore to guard a shared resource.
+ *  xSemaphore = vSemaphoreCreateBinary();
+ *
+ *  if( xSemaphore != NULL )
+ *  {
+ *      if( xSemaphoreGive( xSemaphore ) != pdTRUE )
+ *      {
+ *          // We would expect this call to fail because we cannot give
+ *          // a semaphore without first "taking" it!
+ *      }
+ *
+ *      // Obtain the semaphore - don't block if the semaphore is not
+ *      // immediately available.
+ *      if( xSemaphoreTake( xSemaphore, ( TickType_t ) 0 ) )
+ *      {
+ *          // We now have the semaphore and can access the shared resource.
+ *
+ *          // ...
+ *
+ *          // We have finished accessing the shared resource so can free the
+ *          // semaphore.
+ *          if( xSemaphoreGive( xSemaphore ) != pdTRUE )
+ *          {
+ *              // We would not expect this call to fail because we must have
+ *              // obtained the semaphore to get here.
+ *          }
+ *      }
+ *  }
+ * }
+ * 
+ * \defgroup xSemaphoreGive xSemaphoreGive + * \ingroup Semaphores + */ +#define xSemaphoreGive( xSemaphore ) xQueueGenericSend( ( QueueHandle_t ) ( xSemaphore ), NULL, semGIVE_BLOCK_TIME, queueSEND_TO_BACK ) + +/** + * semphr. h + *
+ * xSemaphoreGiveRecursive( SemaphoreHandle_t xMutex );
+ * 
+ * + * Macro to recursively release, or 'give', a mutex type semaphore. + * The mutex must have previously been created using a call to + * xSemaphoreCreateRecursiveMutex(); + * + * configUSE_RECURSIVE_MUTEXES must be set to 1 in FreeRTOSConfig.h for this + * macro to be available. + * + * This macro must not be used on mutexes created using xSemaphoreCreateMutex(). + * + * A mutex used recursively can be 'taken' repeatedly by the owner. The mutex + * doesn't become available again until the owner has called + * xSemaphoreGiveRecursive() for each successful 'take' request. For example, + * if a task successfully 'takes' the same mutex 5 times then the mutex will + * not be available to any other task until it has also 'given' the mutex back + * exactly five times. + * + * @param xMutex A handle to the mutex being released, or 'given'. This is the + * handle returned by xSemaphoreCreateMutex(); + * + * @return pdTRUE if the semaphore was given. + * + * Example usage: + *
+ * SemaphoreHandle_t xMutex = NULL;
+ *
+ * // A task that creates a mutex.
+ * void vATask( void * pvParameters )
+ * {
+ *  // Create the mutex to guard a shared resource.
+ *  xMutex = xSemaphoreCreateRecursiveMutex();
+ * }
+ *
+ * // A task that uses the mutex.
+ * void vAnotherTask( void * pvParameters )
+ * {
+ *  // ... Do other things.
+ *
+ *  if( xMutex != NULL )
+ *  {
+ *      // See if we can obtain the mutex.  If the mutex is not available
+ *      // wait 10 ticks to see if it becomes free.
+ *      if( xSemaphoreTakeRecursive( xMutex, ( TickType_t ) 10 ) == pdTRUE )
+ *      {
+ *          // We were able to obtain the mutex and can now access the
+ *          // shared resource.
+ *
+ *          // ...
+ *          // For some reason due to the nature of the code further calls to
+ *          // xSemaphoreTakeRecursive() are made on the same mutex.  In real
+ *          // code these would not be just sequential calls as this would make
+ *          // no sense.  Instead the calls are likely to be buried inside
+ *          // a more complex call structure.
+ *          xSemaphoreTakeRecursive( xMutex, ( TickType_t ) 10 );
+ *          xSemaphoreTakeRecursive( xMutex, ( TickType_t ) 10 );
+ *
+ *          // The mutex has now been 'taken' three times, so will not be
+ *          // available to another task until it has also been given back
+ *          // three times.  Again it is unlikely that real code would have
+ *          // these calls sequentially, it would be more likely that the calls
+ *          // to xSemaphoreGiveRecursive() would be called as a call stack
+ *          // unwound.  This is just for demonstrative purposes.
+ *          xSemaphoreGiveRecursive( xMutex );
+ *          xSemaphoreGiveRecursive( xMutex );
+ *          xSemaphoreGiveRecursive( xMutex );
+ *
+ *          // Now the mutex can be taken by other tasks.
+ *      }
+ *      else
+ *      {
+ *          // We could not obtain the mutex and can therefore not access
+ *          // the shared resource safely.
+ *      }
+ *  }
+ * }
+ * 
+ * \defgroup xSemaphoreGiveRecursive xSemaphoreGiveRecursive + * \ingroup Semaphores + */ +#if ( configUSE_RECURSIVE_MUTEXES == 1 ) + #define xSemaphoreGiveRecursive( xMutex ) xQueueGiveMutexRecursive( ( xMutex ) ) +#endif + +/** + * semphr. h + *
+ * xSemaphoreGiveFromISR(
+ *                        SemaphoreHandle_t xSemaphore,
+ *                        BaseType_t *pxHigherPriorityTaskWoken
+ *                    );
+ * 
+ * + * Macro to release a semaphore. The semaphore must have previously been + * created with a call to xSemaphoreCreateBinary() or xSemaphoreCreateCounting(). + * + * Mutex type semaphores (those created using a call to xSemaphoreCreateMutex()) + * must not be used with this macro. + * + * This macro can be used from an ISR. + * + * @param xSemaphore A handle to the semaphore being released. This is the + * handle returned when the semaphore was created. + * + * @param pxHigherPriorityTaskWoken xSemaphoreGiveFromISR() will set + * *pxHigherPriorityTaskWoken to pdTRUE if giving the semaphore caused a task + * to unblock, and the unblocked task has a priority higher than the currently + * running task. If xSemaphoreGiveFromISR() sets this value to pdTRUE then + * a context switch should be requested before the interrupt is exited. + * + * @return pdTRUE if the semaphore was successfully given, otherwise errQUEUE_FULL. + * + * Example usage: + *
+ \#define LONG_TIME 0xffff
+ \#define TICKS_TO_WAIT 10
+ * SemaphoreHandle_t xSemaphore = NULL;
+ *
+ * // Repetitive task.
+ * void vATask( void * pvParameters )
+ * {
+ *  for( ;; )
+ *  {
+ *      // We want this task to run every 10 ticks of a timer.  The semaphore
+ *      // was created before this task was started.
+ *
+ *      // Block waiting for the semaphore to become available.
+ *      if( xSemaphoreTake( xSemaphore, LONG_TIME ) == pdTRUE )
+ *      {
+ *          // It is time to execute.
+ *
+ *          // ...
+ *
+ *          // We have finished our task.  Return to the top of the loop where
+ *          // we will block on the semaphore until it is time to execute
+ *          // again.  Note when using the semaphore for synchronisation with an
+ *          // ISR in this manner there is no need to 'give' the semaphore back.
+ *      }
+ *  }
+ * }
+ *
+ * // Timer ISR
+ * void vTimerISR( void * pvParameters )
+ * {
+ * static uint8_t ucLocalTickCount = 0;
+ * static BaseType_t xHigherPriorityTaskWoken;
+ *
+ *  // A timer tick has occurred.
+ *
+ *  // ... Do other time functions.
+ *
+ *  // Is it time for vATask () to run?
+ *  xHigherPriorityTaskWoken = pdFALSE;
+ *  ucLocalTickCount++;
+ *  if( ucLocalTickCount >= TICKS_TO_WAIT )
+ *  {
+ *      // Unblock the task by releasing the semaphore.
+ *      xSemaphoreGiveFromISR( xSemaphore, &xHigherPriorityTaskWoken );
+ *
+ *      // Reset the count so we release the semaphore again in 10 ticks time.
+ *      ucLocalTickCount = 0;
+ *  }
+ *
+ *  if( xHigherPriorityTaskWoken != pdFALSE )
+ *  {
+ *      // We can force a context switch here.  Context switching from an
+ *      // ISR uses port specific syntax.  Check the demo task for your port
+ *      // to find the syntax required.
+ *  }
+ * }
+ * 
+ * \defgroup xSemaphoreGiveFromISR xSemaphoreGiveFromISR + * \ingroup Semaphores + */ +#define xSemaphoreGiveFromISR( xSemaphore, pxHigherPriorityTaskWoken ) xQueueGiveFromISR( ( QueueHandle_t ) ( xSemaphore ), ( pxHigherPriorityTaskWoken ) ) + +/** + * semphr. h + *
+ * xSemaphoreTakeFromISR(
+ *                        SemaphoreHandle_t xSemaphore,
+ *                        BaseType_t *pxHigherPriorityTaskWoken
+ *                    );
+ * 
+ * + * Macro to take a semaphore from an ISR. The semaphore must have + * previously been created with a call to xSemaphoreCreateBinary() or + * xSemaphoreCreateCounting(). + * + * Mutex type semaphores (those created using a call to xSemaphoreCreateMutex()) + * must not be used with this macro. + * + * This macro can be used from an ISR, however taking a semaphore from an ISR + * is not a common operation. It is likely to only be useful when taking a + * counting semaphore when an interrupt is obtaining an object from a resource + * pool (when the semaphore count indicates the number of resources available). + * + * @param xSemaphore A handle to the semaphore being taken. This is the + * handle returned when the semaphore was created. + * + * @param pxHigherPriorityTaskWoken xSemaphoreTakeFromISR() will set + * *pxHigherPriorityTaskWoken to pdTRUE if taking the semaphore caused a task + * to unblock, and the unblocked task has a priority higher than the currently + * running task. If xSemaphoreTakeFromISR() sets this value to pdTRUE then + * a context switch should be requested before the interrupt is exited. + * + * @return pdTRUE if the semaphore was successfully taken, otherwise + * pdFALSE + */ +#define xSemaphoreTakeFromISR( xSemaphore, pxHigherPriorityTaskWoken ) xQueueReceiveFromISR( ( QueueHandle_t ) ( xSemaphore ), NULL, ( pxHigherPriorityTaskWoken ) ) + +/** + * semphr. h + *
+ * SemaphoreHandle_t xSemaphoreCreateMutex( void );
+ * 
+ * + * Creates a new mutex type semaphore instance, and returns a handle by which + * the new mutex can be referenced. + * + * Internally, within the FreeRTOS implementation, mutex semaphores use a block + * of memory, in which the mutex structure is stored. If a mutex is created + * using xSemaphoreCreateMutex() then the required memory is automatically + * dynamically allocated inside the xSemaphoreCreateMutex() function. (see + * https://www.FreeRTOS.org/a00111.html). If a mutex is created using + * xSemaphoreCreateMutexStatic() then the application writer must provided the + * memory. xSemaphoreCreateMutexStatic() therefore allows a mutex to be created + * without using any dynamic memory allocation. + * + * Mutexes created using this function can be accessed using the xSemaphoreTake() + * and xSemaphoreGive() macros. The xSemaphoreTakeRecursive() and + * xSemaphoreGiveRecursive() macros must not be used. + * + * This type of semaphore uses a priority inheritance mechanism so a task + * 'taking' a semaphore MUST ALWAYS 'give' the semaphore back once the + * semaphore it is no longer required. + * + * Mutex type semaphores cannot be used from within interrupt service routines. + * + * See xSemaphoreCreateBinary() for an alternative implementation that can be + * used for pure synchronisation (where one task or interrupt always 'gives' the + * semaphore and another always 'takes' the semaphore) and from within interrupt + * service routines. + * + * @return If the mutex was successfully created then a handle to the created + * semaphore is returned. If there was not enough heap to allocate the mutex + * data structures then NULL is returned. + * + * Example usage: + *
+ * SemaphoreHandle_t xSemaphore;
+ *
+ * void vATask( void * pvParameters )
+ * {
+ *  // Semaphore cannot be used before a call to xSemaphoreCreateMutex().
+ *  // This is a macro so pass the variable in directly.
+ *  xSemaphore = xSemaphoreCreateMutex();
+ *
+ *  if( xSemaphore != NULL )
+ *  {
+ *      // The semaphore was created successfully.
+ *      // The semaphore can now be used.
+ *  }
+ * }
+ * 
+ * \defgroup xSemaphoreCreateMutex xSemaphoreCreateMutex + * \ingroup Semaphores + */ +#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + #define xSemaphoreCreateMutex() xQueueCreateMutex( queueQUEUE_TYPE_MUTEX ) +#endif + +/** + * semphr. h + *
+ * SemaphoreHandle_t xSemaphoreCreateMutexStatic( StaticSemaphore_t *pxMutexBuffer );
+ * 
+ * + * Creates a new mutex type semaphore instance, and returns a handle by which + * the new mutex can be referenced. + * + * Internally, within the FreeRTOS implementation, mutex semaphores use a block + * of memory, in which the mutex structure is stored. If a mutex is created + * using xSemaphoreCreateMutex() then the required memory is automatically + * dynamically allocated inside the xSemaphoreCreateMutex() function. (see + * https://www.FreeRTOS.org/a00111.html). If a mutex is created using + * xSemaphoreCreateMutexStatic() then the application writer must provided the + * memory. xSemaphoreCreateMutexStatic() therefore allows a mutex to be created + * without using any dynamic memory allocation. + * + * Mutexes created using this function can be accessed using the xSemaphoreTake() + * and xSemaphoreGive() macros. The xSemaphoreTakeRecursive() and + * xSemaphoreGiveRecursive() macros must not be used. + * + * This type of semaphore uses a priority inheritance mechanism so a task + * 'taking' a semaphore MUST ALWAYS 'give' the semaphore back once the + * semaphore it is no longer required. + * + * Mutex type semaphores cannot be used from within interrupt service routines. + * + * See xSemaphoreCreateBinary() for an alternative implementation that can be + * used for pure synchronisation (where one task or interrupt always 'gives' the + * semaphore and another always 'takes' the semaphore) and from within interrupt + * service routines. + * + * @param pxMutexBuffer Must point to a variable of type StaticSemaphore_t, + * which will be used to hold the mutex's data structure, removing the need for + * the memory to be allocated dynamically. + * + * @return If the mutex was successfully created then a handle to the created + * mutex is returned. If pxMutexBuffer was NULL then NULL is returned. + * + * Example usage: + *
+ * SemaphoreHandle_t xSemaphore;
+ * StaticSemaphore_t xMutexBuffer;
+ *
+ * void vATask( void * pvParameters )
+ * {
+ *  // A mutex cannot be used before it has been created.  xMutexBuffer is
+ *  // into xSemaphoreCreateMutexStatic() so no dynamic memory allocation is
+ *  // attempted.
+ *  xSemaphore = xSemaphoreCreateMutexStatic( &xMutexBuffer );
+ *
+ *  // As no dynamic memory allocation was performed, xSemaphore cannot be NULL,
+ *  // so there is no need to check it.
+ * }
+ * 
+ * \defgroup xSemaphoreCreateMutexStatic xSemaphoreCreateMutexStatic + * \ingroup Semaphores + */ +#if ( configSUPPORT_STATIC_ALLOCATION == 1 ) + #define xSemaphoreCreateMutexStatic( pxMutexBuffer ) xQueueCreateMutexStatic( queueQUEUE_TYPE_MUTEX, ( pxMutexBuffer ) ) +#endif /* configSUPPORT_STATIC_ALLOCATION */ + + +/** + * semphr. h + *
+ * SemaphoreHandle_t xSemaphoreCreateRecursiveMutex( void );
+ * 
+ * + * Creates a new recursive mutex type semaphore instance, and returns a handle + * by which the new recursive mutex can be referenced. + * + * Internally, within the FreeRTOS implementation, recursive mutexs use a block + * of memory, in which the mutex structure is stored. If a recursive mutex is + * created using xSemaphoreCreateRecursiveMutex() then the required memory is + * automatically dynamically allocated inside the + * xSemaphoreCreateRecursiveMutex() function. (see + * https://www.FreeRTOS.org/a00111.html). If a recursive mutex is created using + * xSemaphoreCreateRecursiveMutexStatic() then the application writer must + * provide the memory that will get used by the mutex. + * xSemaphoreCreateRecursiveMutexStatic() therefore allows a recursive mutex to + * be created without using any dynamic memory allocation. + * + * Mutexes created using this macro can be accessed using the + * xSemaphoreTakeRecursive() and xSemaphoreGiveRecursive() macros. The + * xSemaphoreTake() and xSemaphoreGive() macros must not be used. + * + * A mutex used recursively can be 'taken' repeatedly by the owner. The mutex + * doesn't become available again until the owner has called + * xSemaphoreGiveRecursive() for each successful 'take' request. For example, + * if a task successfully 'takes' the same mutex 5 times then the mutex will + * not be available to any other task until it has also 'given' the mutex back + * exactly five times. + * + * This type of semaphore uses a priority inheritance mechanism so a task + * 'taking' a semaphore MUST ALWAYS 'give' the semaphore back once the + * semaphore it is no longer required. + * + * Mutex type semaphores cannot be used from within interrupt service routines. + * + * See xSemaphoreCreateBinary() for an alternative implementation that can be + * used for pure synchronisation (where one task or interrupt always 'gives' the + * semaphore and another always 'takes' the semaphore) and from within interrupt + * service routines. + * + * @return xSemaphore Handle to the created mutex semaphore. Should be of type + * SemaphoreHandle_t. + * + * Example usage: + *
+ * SemaphoreHandle_t xSemaphore;
+ *
+ * void vATask( void * pvParameters )
+ * {
+ *  // Semaphore cannot be used before a call to xSemaphoreCreateMutex().
+ *  // This is a macro so pass the variable in directly.
+ *  xSemaphore = xSemaphoreCreateRecursiveMutex();
+ *
+ *  if( xSemaphore != NULL )
+ *  {
+ *      // The semaphore was created successfully.
+ *      // The semaphore can now be used.
+ *  }
+ * }
+ * 
+ * \defgroup xSemaphoreCreateRecursiveMutex xSemaphoreCreateRecursiveMutex + * \ingroup Semaphores + */ +#if ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configUSE_RECURSIVE_MUTEXES == 1 ) ) + #define xSemaphoreCreateRecursiveMutex() xQueueCreateMutex( queueQUEUE_TYPE_RECURSIVE_MUTEX ) +#endif + +/** + * semphr. h + *
+ * SemaphoreHandle_t xSemaphoreCreateRecursiveMutexStatic( StaticSemaphore_t *pxMutexBuffer );
+ * 
+ * + * Creates a new recursive mutex type semaphore instance, and returns a handle + * by which the new recursive mutex can be referenced. + * + * Internally, within the FreeRTOS implementation, recursive mutexs use a block + * of memory, in which the mutex structure is stored. If a recursive mutex is + * created using xSemaphoreCreateRecursiveMutex() then the required memory is + * automatically dynamically allocated inside the + * xSemaphoreCreateRecursiveMutex() function. (see + * https://www.FreeRTOS.org/a00111.html). If a recursive mutex is created using + * xSemaphoreCreateRecursiveMutexStatic() then the application writer must + * provide the memory that will get used by the mutex. + * xSemaphoreCreateRecursiveMutexStatic() therefore allows a recursive mutex to + * be created without using any dynamic memory allocation. + * + * Mutexes created using this macro can be accessed using the + * xSemaphoreTakeRecursive() and xSemaphoreGiveRecursive() macros. The + * xSemaphoreTake() and xSemaphoreGive() macros must not be used. + * + * A mutex used recursively can be 'taken' repeatedly by the owner. The mutex + * doesn't become available again until the owner has called + * xSemaphoreGiveRecursive() for each successful 'take' request. For example, + * if a task successfully 'takes' the same mutex 5 times then the mutex will + * not be available to any other task until it has also 'given' the mutex back + * exactly five times. + * + * This type of semaphore uses a priority inheritance mechanism so a task + * 'taking' a semaphore MUST ALWAYS 'give' the semaphore back once the + * semaphore it is no longer required. + * + * Mutex type semaphores cannot be used from within interrupt service routines. + * + * See xSemaphoreCreateBinary() for an alternative implementation that can be + * used for pure synchronisation (where one task or interrupt always 'gives' the + * semaphore and another always 'takes' the semaphore) and from within interrupt + * service routines. + * + * @param pxMutexBuffer Must point to a variable of type StaticSemaphore_t, + * which will then be used to hold the recursive mutex's data structure, + * removing the need for the memory to be allocated dynamically. + * + * @return If the recursive mutex was successfully created then a handle to the + * created recursive mutex is returned. If pxMutexBuffer was NULL then NULL is + * returned. + * + * Example usage: + *
+ * SemaphoreHandle_t xSemaphore;
+ * StaticSemaphore_t xMutexBuffer;
+ *
+ * void vATask( void * pvParameters )
+ * {
+ *  // A recursive semaphore cannot be used before it is created.  Here a
+ *  // recursive mutex is created using xSemaphoreCreateRecursiveMutexStatic().
+ *  // The address of xMutexBuffer is passed into the function, and will hold
+ *  // the mutexes data structures - so no dynamic memory allocation will be
+ *  // attempted.
+ *  xSemaphore = xSemaphoreCreateRecursiveMutexStatic( &xMutexBuffer );
+ *
+ *  // As no dynamic memory allocation was performed, xSemaphore cannot be NULL,
+ *  // so there is no need to check it.
+ * }
+ * 
+ * \defgroup xSemaphoreCreateRecursiveMutexStatic xSemaphoreCreateRecursiveMutexStatic + * \ingroup Semaphores + */ +#if ( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configUSE_RECURSIVE_MUTEXES == 1 ) ) + #define xSemaphoreCreateRecursiveMutexStatic( pxStaticSemaphore ) xQueueCreateMutexStatic( queueQUEUE_TYPE_RECURSIVE_MUTEX, pxStaticSemaphore ) +#endif /* configSUPPORT_STATIC_ALLOCATION */ + +/** + * semphr. h + *
+ * SemaphoreHandle_t xSemaphoreCreateCounting( UBaseType_t uxMaxCount, UBaseType_t uxInitialCount );
+ * 
+ * + * Creates a new counting semaphore instance, and returns a handle by which the + * new counting semaphore can be referenced. + * + * In many usage scenarios it is faster and more memory efficient to use a + * direct to task notification in place of a counting semaphore! + * https://www.FreeRTOS.org/RTOS-task-notifications.html + * + * Internally, within the FreeRTOS implementation, counting semaphores use a + * block of memory, in which the counting semaphore structure is stored. If a + * counting semaphore is created using xSemaphoreCreateCounting() then the + * required memory is automatically dynamically allocated inside the + * xSemaphoreCreateCounting() function. (see + * https://www.FreeRTOS.org/a00111.html). If a counting semaphore is created + * using xSemaphoreCreateCountingStatic() then the application writer can + * instead optionally provide the memory that will get used by the counting + * semaphore. xSemaphoreCreateCountingStatic() therefore allows a counting + * semaphore to be created without using any dynamic memory allocation. + * + * Counting semaphores are typically used for two things: + * + * 1) Counting events. + * + * In this usage scenario an event handler will 'give' a semaphore each time + * an event occurs (incrementing the semaphore count value), and a handler + * task will 'take' a semaphore each time it processes an event + * (decrementing the semaphore count value). The count value is therefore + * the difference between the number of events that have occurred and the + * number that have been processed. In this case it is desirable for the + * initial count value to be zero. + * + * 2) Resource management. + * + * In this usage scenario the count value indicates the number of resources + * available. To obtain control of a resource a task must first obtain a + * semaphore - decrementing the semaphore count value. When the count value + * reaches zero there are no free resources. When a task finishes with the + * resource it 'gives' the semaphore back - incrementing the semaphore count + * value. In this case it is desirable for the initial count value to be + * equal to the maximum count value, indicating that all resources are free. + * + * @param uxMaxCount The maximum count value that can be reached. When the + * semaphore reaches this value it can no longer be 'given'. + * + * @param uxInitialCount The count value assigned to the semaphore when it is + * created. + * + * @return Handle to the created semaphore. Null if the semaphore could not be + * created. + * + * Example usage: + *
+ * SemaphoreHandle_t xSemaphore;
+ *
+ * void vATask( void * pvParameters )
+ * {
+ * SemaphoreHandle_t xSemaphore = NULL;
+ *
+ *  // Semaphore cannot be used before a call to xSemaphoreCreateCounting().
+ *  // The max value to which the semaphore can count should be 10, and the
+ *  // initial value assigned to the count should be 0.
+ *  xSemaphore = xSemaphoreCreateCounting( 10, 0 );
+ *
+ *  if( xSemaphore != NULL )
+ *  {
+ *      // The semaphore was created successfully.
+ *      // The semaphore can now be used.
+ *  }
+ * }
+ * 
+ * \defgroup xSemaphoreCreateCounting xSemaphoreCreateCounting + * \ingroup Semaphores + */ +#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + #define xSemaphoreCreateCounting( uxMaxCount, uxInitialCount ) xQueueCreateCountingSemaphore( ( uxMaxCount ), ( uxInitialCount ) ) +#endif + +/** + * semphr. h + *
+ * SemaphoreHandle_t xSemaphoreCreateCountingStatic( UBaseType_t uxMaxCount, UBaseType_t uxInitialCount, StaticSemaphore_t *pxSemaphoreBuffer );
+ * 
+ * + * Creates a new counting semaphore instance, and returns a handle by which the + * new counting semaphore can be referenced. + * + * In many usage scenarios it is faster and more memory efficient to use a + * direct to task notification in place of a counting semaphore! + * https://www.FreeRTOS.org/RTOS-task-notifications.html + * + * Internally, within the FreeRTOS implementation, counting semaphores use a + * block of memory, in which the counting semaphore structure is stored. If a + * counting semaphore is created using xSemaphoreCreateCounting() then the + * required memory is automatically dynamically allocated inside the + * xSemaphoreCreateCounting() function. (see + * https://www.FreeRTOS.org/a00111.html). If a counting semaphore is created + * using xSemaphoreCreateCountingStatic() then the application writer must + * provide the memory. xSemaphoreCreateCountingStatic() therefore allows a + * counting semaphore to be created without using any dynamic memory allocation. + * + * Counting semaphores are typically used for two things: + * + * 1) Counting events. + * + * In this usage scenario an event handler will 'give' a semaphore each time + * an event occurs (incrementing the semaphore count value), and a handler + * task will 'take' a semaphore each time it processes an event + * (decrementing the semaphore count value). The count value is therefore + * the difference between the number of events that have occurred and the + * number that have been processed. In this case it is desirable for the + * initial count value to be zero. + * + * 2) Resource management. + * + * In this usage scenario the count value indicates the number of resources + * available. To obtain control of a resource a task must first obtain a + * semaphore - decrementing the semaphore count value. When the count value + * reaches zero there are no free resources. When a task finishes with the + * resource it 'gives' the semaphore back - incrementing the semaphore count + * value. In this case it is desirable for the initial count value to be + * equal to the maximum count value, indicating that all resources are free. + * + * @param uxMaxCount The maximum count value that can be reached. When the + * semaphore reaches this value it can no longer be 'given'. + * + * @param uxInitialCount The count value assigned to the semaphore when it is + * created. + * + * @param pxSemaphoreBuffer Must point to a variable of type StaticSemaphore_t, + * which will then be used to hold the semaphore's data structure, removing the + * need for the memory to be allocated dynamically. + * + * @return If the counting semaphore was successfully created then a handle to + * the created counting semaphore is returned. If pxSemaphoreBuffer was NULL + * then NULL is returned. + * + * Example usage: + *
+ * SemaphoreHandle_t xSemaphore;
+ * StaticSemaphore_t xSemaphoreBuffer;
+ *
+ * void vATask( void * pvParameters )
+ * {
+ * SemaphoreHandle_t xSemaphore = NULL;
+ *
+ *  // Counting semaphore cannot be used before they have been created.  Create
+ *  // a counting semaphore using xSemaphoreCreateCountingStatic().  The max
+ *  // value to which the semaphore can count is 10, and the initial value
+ *  // assigned to the count will be 0.  The address of xSemaphoreBuffer is
+ *  // passed in and will be used to hold the semaphore structure, so no dynamic
+ *  // memory allocation will be used.
+ *  xSemaphore = xSemaphoreCreateCounting( 10, 0, &xSemaphoreBuffer );
+ *
+ *  // No memory allocation was attempted so xSemaphore cannot be NULL, so there
+ *  // is no need to check its value.
+ * }
+ * 
+ * \defgroup xSemaphoreCreateCountingStatic xSemaphoreCreateCountingStatic + * \ingroup Semaphores + */ +#if ( configSUPPORT_STATIC_ALLOCATION == 1 ) + #define xSemaphoreCreateCountingStatic( uxMaxCount, uxInitialCount, pxSemaphoreBuffer ) xQueueCreateCountingSemaphoreStatic( ( uxMaxCount ), ( uxInitialCount ), ( pxSemaphoreBuffer ) ) +#endif /* configSUPPORT_STATIC_ALLOCATION */ + +/** + * semphr. h + *
+ * void vSemaphoreDelete( SemaphoreHandle_t xSemaphore );
+ * 
+ * + * Delete a semaphore. This function must be used with care. For example, + * do not delete a mutex type semaphore if the mutex is held by a task. + * + * @param xSemaphore A handle to the semaphore to be deleted. + * + * \defgroup vSemaphoreDelete vSemaphoreDelete + * \ingroup Semaphores + */ +#define vSemaphoreDelete( xSemaphore ) vQueueDelete( ( QueueHandle_t ) ( xSemaphore ) ) + +/** + * semphr.h + *
+ * TaskHandle_t xSemaphoreGetMutexHolder( SemaphoreHandle_t xMutex );
+ * 
+ * + * If xMutex is indeed a mutex type semaphore, return the current mutex holder. + * If xMutex is not a mutex type semaphore, or the mutex is available (not held + * by a task), return NULL. + * + * Note: This is a good way of determining if the calling task is the mutex + * holder, but not a good way of determining the identity of the mutex holder as + * the holder may change between the function exiting and the returned value + * being tested. + */ +#define xSemaphoreGetMutexHolder( xSemaphore ) xQueueGetMutexHolder( ( xSemaphore ) ) + +/** + * semphr.h + *
+ * TaskHandle_t xSemaphoreGetMutexHolderFromISR( SemaphoreHandle_t xMutex );
+ * 
+ * + * If xMutex is indeed a mutex type semaphore, return the current mutex holder. + * If xMutex is not a mutex type semaphore, or the mutex is available (not held + * by a task), return NULL. + * + */ +#define xSemaphoreGetMutexHolderFromISR( xSemaphore ) xQueueGetMutexHolderFromISR( ( xSemaphore ) ) + +/** + * semphr.h + *
+ * UBaseType_t uxSemaphoreGetCount( SemaphoreHandle_t xSemaphore );
+ * 
+ * + * If the semaphore is a counting semaphore then uxSemaphoreGetCount() returns + * its current count value. If the semaphore is a binary semaphore then + * uxSemaphoreGetCount() returns 1 if the semaphore is available, and 0 if the + * semaphore is not available. + * + */ +#define uxSemaphoreGetCount( xSemaphore ) uxQueueMessagesWaiting( ( QueueHandle_t ) ( xSemaphore ) ) + +#endif /* SEMAPHORE_H */ diff --git a/RTOS/FreeRTOS/Source/include/stack_macros.h b/RTOS/FreeRTOS/Source/include/stack_macros.h new file mode 100644 index 0000000..0b1744f --- /dev/null +++ b/RTOS/FreeRTOS/Source/include/stack_macros.h @@ -0,0 +1,127 @@ +/* + * FreeRTOS Kernel V10.4.1 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * https://www.FreeRTOS.org + * https://github.com/FreeRTOS + * + */ + +#ifndef STACK_MACROS_H +#define STACK_MACROS_H + +/* + * Call the stack overflow hook function if the stack of the task being swapped + * out is currently overflowed, or looks like it might have overflowed in the + * past. + * + * Setting configCHECK_FOR_STACK_OVERFLOW to 1 will cause the macro to check + * the current stack state only - comparing the current top of stack value to + * the stack limit. Setting configCHECK_FOR_STACK_OVERFLOW to greater than 1 + * will also cause the last few stack bytes to be checked to ensure the value + * to which the bytes were set when the task was created have not been + * overwritten. Note this second test does not guarantee that an overflowed + * stack will always be recognised. + */ + +/*-----------------------------------------------------------*/ + +#if ( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH < 0 ) ) + +/* Only the current stack state is to be checked. */ + #define taskCHECK_FOR_STACK_OVERFLOW() \ + { \ + /* Is the currently saved stack pointer within the stack limit? */ \ + if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack ) \ + { \ + vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ + } \ + } + +#endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */ +/*-----------------------------------------------------------*/ + +#if ( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH > 0 ) ) + +/* Only the current stack state is to be checked. */ + #define taskCHECK_FOR_STACK_OVERFLOW() \ + { \ + \ + /* Is the currently saved stack pointer within the stack limit? */ \ + if( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack ) \ + { \ + vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ + } \ + } + +#endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */ +/*-----------------------------------------------------------*/ + +#if ( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH < 0 ) ) + + #define taskCHECK_FOR_STACK_OVERFLOW() \ + { \ + const uint32_t * const pulStack = ( uint32_t * ) pxCurrentTCB->pxStack; \ + const uint32_t ulCheckValue = ( uint32_t ) 0xa5a5a5a5; \ + \ + if( ( pulStack[ 0 ] != ulCheckValue ) || \ + ( pulStack[ 1 ] != ulCheckValue ) || \ + ( pulStack[ 2 ] != ulCheckValue ) || \ + ( pulStack[ 3 ] != ulCheckValue ) ) \ + { \ + vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ + } \ + } + +#endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */ +/*-----------------------------------------------------------*/ + +#if ( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH > 0 ) ) + + #define taskCHECK_FOR_STACK_OVERFLOW() \ + { \ + int8_t * pcEndOfStack = ( int8_t * ) pxCurrentTCB->pxEndOfStack; \ + static const uint8_t ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ + tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ + tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ + tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ + tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \ + \ + \ + pcEndOfStack -= sizeof( ucExpectedStackBytes ); \ + \ + /* Has the extremity of the task stack ever been written over? */ \ + if( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) \ + { \ + vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ + } \ + } + +#endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */ +/*-----------------------------------------------------------*/ + +/* Remove stack overflow macro if not being used. */ +#ifndef taskCHECK_FOR_STACK_OVERFLOW + #define taskCHECK_FOR_STACK_OVERFLOW() +#endif + + + +#endif /* STACK_MACROS_H */ diff --git a/RTOS/FreeRTOS/Source/include/stdint.readme b/RTOS/FreeRTOS/Source/include/stdint.readme new file mode 100644 index 0000000..4414c29 --- /dev/null +++ b/RTOS/FreeRTOS/Source/include/stdint.readme @@ -0,0 +1,27 @@ + +#ifndef FREERTOS_STDINT +#define FREERTOS_STDINT + +/******************************************************************************* + * THIS IS NOT A FULL stdint.h IMPLEMENTATION - It only contains the definitions + * necessary to build the FreeRTOS code. It is provided to allow FreeRTOS to be + * built using compilers that do not provide their own stdint.h definition. + * + * To use this file: + * + * 1) Copy this file into the directory that contains your FreeRTOSConfig.h + * header file, as that directory will already be in the compilers include + * path. + * + * 2) Rename the copied file stdint.h. + * + */ + +typedef signed char int8_t; +typedef unsigned char uint8_t; +typedef short int16_t; +typedef unsigned short uint16_t; +typedef long int32_t; +typedef unsigned long uint32_t; + +#endif /* FREERTOS_STDINT */ diff --git a/RTOS/FreeRTOS/Source/include/stream_buffer.h b/RTOS/FreeRTOS/Source/include/stream_buffer.h new file mode 100644 index 0000000..4da9fa9 --- /dev/null +++ b/RTOS/FreeRTOS/Source/include/stream_buffer.h @@ -0,0 +1,867 @@ +/* + * FreeRTOS Kernel V10.4.1 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * https://www.FreeRTOS.org + * https://github.com/FreeRTOS + * + */ + +/* + * Stream buffers are used to send a continuous stream of data from one task or + * interrupt to another. Their implementation is light weight, making them + * particularly suited for interrupt to task and core to core communication + * scenarios. + * + * ***NOTE***: Uniquely among FreeRTOS objects, the stream buffer + * implementation (so also the message buffer implementation, as message buffers + * are built on top of stream buffers) assumes there is only one task or + * interrupt that will write to the buffer (the writer), and only one task or + * interrupt that will read from the buffer (the reader). It is safe for the + * writer and reader to be different tasks or interrupts, but, unlike other + * FreeRTOS objects, it is not safe to have multiple different writers or + * multiple different readers. If there are to be multiple different writers + * then the application writer must place each call to a writing API function + * (such as xStreamBufferSend()) inside a critical section and set the send + * block time to 0. Likewise, if there are to be multiple different readers + * then the application writer must place each call to a reading API function + * (such as xStreamBufferReceive()) inside a critical section section and set the + * receive block time to 0. + * + */ + +#ifndef STREAM_BUFFER_H +#define STREAM_BUFFER_H + +#ifndef INC_FREERTOS_H + #error "include FreeRTOS.h must appear in source files before include stream_buffer.h" +#endif + +/* *INDENT-OFF* */ +#if defined( __cplusplus ) + extern "C" { +#endif +/* *INDENT-ON* */ + +/** + * Type by which stream buffers are referenced. For example, a call to + * xStreamBufferCreate() returns an StreamBufferHandle_t variable that can + * then be used as a parameter to xStreamBufferSend(), xStreamBufferReceive(), + * etc. + */ +struct StreamBufferDef_t; +typedef struct StreamBufferDef_t * StreamBufferHandle_t; + + +/** + * message_buffer.h + * + *
+ * StreamBufferHandle_t xStreamBufferCreate( size_t xBufferSizeBytes, size_t xTriggerLevelBytes );
+ * 
+ * + * Creates a new stream buffer using dynamically allocated memory. See + * xStreamBufferCreateStatic() for a version that uses statically allocated + * memory (memory that is allocated at compile time). + * + * configSUPPORT_DYNAMIC_ALLOCATION must be set to 1 or left undefined in + * FreeRTOSConfig.h for xStreamBufferCreate() to be available. + * + * @param xBufferSizeBytes The total number of bytes the stream buffer will be + * able to hold at any one time. + * + * @param xTriggerLevelBytes The number of bytes that must be in the stream + * buffer before a task that is blocked on the stream buffer to wait for data is + * moved out of the blocked state. For example, if a task is blocked on a read + * of an empty stream buffer that has a trigger level of 1 then the task will be + * unblocked when a single byte is written to the buffer or the task's block + * time expires. As another example, if a task is blocked on a read of an empty + * stream buffer that has a trigger level of 10 then the task will not be + * unblocked until the stream buffer contains at least 10 bytes or the task's + * block time expires. If a reading task's block time expires before the + * trigger level is reached then the task will still receive however many bytes + * are actually available. Setting a trigger level of 0 will result in a + * trigger level of 1 being used. It is not valid to specify a trigger level + * that is greater than the buffer size. + * + * @return If NULL is returned, then the stream buffer cannot be created + * because there is insufficient heap memory available for FreeRTOS to allocate + * the stream buffer data structures and storage area. A non-NULL value being + * returned indicates that the stream buffer has been created successfully - + * the returned value should be stored as the handle to the created stream + * buffer. + * + * Example use: + *
+ *
+ * void vAFunction( void )
+ * {
+ * StreamBufferHandle_t xStreamBuffer;
+ * const size_t xStreamBufferSizeBytes = 100, xTriggerLevel = 10;
+ *
+ *  // Create a stream buffer that can hold 100 bytes.  The memory used to hold
+ *  // both the stream buffer structure and the data in the stream buffer is
+ *  // allocated dynamically.
+ *  xStreamBuffer = xStreamBufferCreate( xStreamBufferSizeBytes, xTriggerLevel );
+ *
+ *  if( xStreamBuffer == NULL )
+ *  {
+ *      // There was not enough heap memory space available to create the
+ *      // stream buffer.
+ *  }
+ *  else
+ *  {
+ *      // The stream buffer was created successfully and can now be used.
+ *  }
+ * }
+ * 
+ * \defgroup xStreamBufferCreate xStreamBufferCreate + * \ingroup StreamBufferManagement + */ +#define xStreamBufferCreate( xBufferSizeBytes, xTriggerLevelBytes ) xStreamBufferGenericCreate( xBufferSizeBytes, xTriggerLevelBytes, pdFALSE ) + +/** + * stream_buffer.h + * + *
+ * StreamBufferHandle_t xStreamBufferCreateStatic( size_t xBufferSizeBytes,
+ *                                              size_t xTriggerLevelBytes,
+ *                                              uint8_t *pucStreamBufferStorageArea,
+ *                                              StaticStreamBuffer_t *pxStaticStreamBuffer );
+ * 
+ * Creates a new stream buffer using statically allocated memory. See + * xStreamBufferCreate() for a version that uses dynamically allocated memory. + * + * configSUPPORT_STATIC_ALLOCATION must be set to 1 in FreeRTOSConfig.h for + * xStreamBufferCreateStatic() to be available. + * + * @param xBufferSizeBytes The size, in bytes, of the buffer pointed to by the + * pucStreamBufferStorageArea parameter. + * + * @param xTriggerLevelBytes The number of bytes that must be in the stream + * buffer before a task that is blocked on the stream buffer to wait for data is + * moved out of the blocked state. For example, if a task is blocked on a read + * of an empty stream buffer that has a trigger level of 1 then the task will be + * unblocked when a single byte is written to the buffer or the task's block + * time expires. As another example, if a task is blocked on a read of an empty + * stream buffer that has a trigger level of 10 then the task will not be + * unblocked until the stream buffer contains at least 10 bytes or the task's + * block time expires. If a reading task's block time expires before the + * trigger level is reached then the task will still receive however many bytes + * are actually available. Setting a trigger level of 0 will result in a + * trigger level of 1 being used. It is not valid to specify a trigger level + * that is greater than the buffer size. + * + * @param pucStreamBufferStorageArea Must point to a uint8_t array that is at + * least xBufferSizeBytes + 1 big. This is the array to which streams are + * copied when they are written to the stream buffer. + * + * @param pxStaticStreamBuffer Must point to a variable of type + * StaticStreamBuffer_t, which will be used to hold the stream buffer's data + * structure. + * + * @return If the stream buffer is created successfully then a handle to the + * created stream buffer is returned. If either pucStreamBufferStorageArea or + * pxStaticstreamBuffer are NULL then NULL is returned. + * + * Example use: + *
+ *
+ * // Used to dimension the array used to hold the streams.  The available space
+ * // will actually be one less than this, so 999.
+ #define STORAGE_SIZE_BYTES 1000
+ *
+ * // Defines the memory that will actually hold the streams within the stream
+ * // buffer.
+ * static uint8_t ucStorageBuffer[ STORAGE_SIZE_BYTES ];
+ *
+ * // The variable used to hold the stream buffer structure.
+ * StaticStreamBuffer_t xStreamBufferStruct;
+ *
+ * void MyFunction( void )
+ * {
+ * StreamBufferHandle_t xStreamBuffer;
+ * const size_t xTriggerLevel = 1;
+ *
+ *  xStreamBuffer = xStreamBufferCreateStatic( sizeof( ucBufferStorage ),
+ *                                             xTriggerLevel,
+ *                                             ucBufferStorage,
+ *                                             &xStreamBufferStruct );
+ *
+ *  // As neither the pucStreamBufferStorageArea or pxStaticStreamBuffer
+ *  // parameters were NULL, xStreamBuffer will not be NULL, and can be used to
+ *  // reference the created stream buffer in other stream buffer API calls.
+ *
+ *  // Other code that uses the stream buffer can go here.
+ * }
+ *
+ * 
+ * \defgroup xStreamBufferCreateStatic xStreamBufferCreateStatic + * \ingroup StreamBufferManagement + */ +#define xStreamBufferCreateStatic( xBufferSizeBytes, xTriggerLevelBytes, pucStreamBufferStorageArea, pxStaticStreamBuffer ) \ + xStreamBufferGenericCreateStatic( xBufferSizeBytes, xTriggerLevelBytes, pdFALSE, pucStreamBufferStorageArea, pxStaticStreamBuffer ) + +/** + * stream_buffer.h + * + *
+ * size_t xStreamBufferSend( StreamBufferHandle_t xStreamBuffer,
+ *                        const void *pvTxData,
+ *                        size_t xDataLengthBytes,
+ *                        TickType_t xTicksToWait );
+ * 
+ * + * Sends bytes to a stream buffer. The bytes are copied into the stream buffer. + * + * ***NOTE***: Uniquely among FreeRTOS objects, the stream buffer + * implementation (so also the message buffer implementation, as message buffers + * are built on top of stream buffers) assumes there is only one task or + * interrupt that will write to the buffer (the writer), and only one task or + * interrupt that will read from the buffer (the reader). It is safe for the + * writer and reader to be different tasks or interrupts, but, unlike other + * FreeRTOS objects, it is not safe to have multiple different writers or + * multiple different readers. If there are to be multiple different writers + * then the application writer must place each call to a writing API function + * (such as xStreamBufferSend()) inside a critical section and set the send + * block time to 0. Likewise, if there are to be multiple different readers + * then the application writer must place each call to a reading API function + * (such as xStreamBufferReceive()) inside a critical section and set the receive + * block time to 0. + * + * Use xStreamBufferSend() to write to a stream buffer from a task. Use + * xStreamBufferSendFromISR() to write to a stream buffer from an interrupt + * service routine (ISR). + * + * @param xStreamBuffer The handle of the stream buffer to which a stream is + * being sent. + * + * @param pvTxData A pointer to the buffer that holds the bytes to be copied + * into the stream buffer. + * + * @param xDataLengthBytes The maximum number of bytes to copy from pvTxData + * into the stream buffer. + * + * @param xTicksToWait The maximum amount of time the task should remain in the + * Blocked state to wait for enough space to become available in the stream + * buffer, should the stream buffer contain too little space to hold the + * another xDataLengthBytes bytes. The block time is specified in tick periods, + * so the absolute time it represents is dependent on the tick frequency. The + * macro pdMS_TO_TICKS() can be used to convert a time specified in milliseconds + * into a time specified in ticks. Setting xTicksToWait to portMAX_DELAY will + * cause the task to wait indefinitely (without timing out), provided + * INCLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h. If a task times out + * before it can write all xDataLengthBytes into the buffer it will still write + * as many bytes as possible. A task does not use any CPU time when it is in + * the blocked state. + * + * @return The number of bytes written to the stream buffer. If a task times + * out before it can write all xDataLengthBytes into the buffer it will still + * write as many bytes as possible. + * + * Example use: + *
+ * void vAFunction( StreamBufferHandle_t xStreamBuffer )
+ * {
+ * size_t xBytesSent;
+ * uint8_t ucArrayToSend[] = { 0, 1, 2, 3 };
+ * char *pcStringToSend = "String to send";
+ * const TickType_t x100ms = pdMS_TO_TICKS( 100 );
+ *
+ *  // Send an array to the stream buffer, blocking for a maximum of 100ms to
+ *  // wait for enough space to be available in the stream buffer.
+ *  xBytesSent = xStreamBufferSend( xStreamBuffer, ( void * ) ucArrayToSend, sizeof( ucArrayToSend ), x100ms );
+ *
+ *  if( xBytesSent != sizeof( ucArrayToSend ) )
+ *  {
+ *      // The call to xStreamBufferSend() times out before there was enough
+ *      // space in the buffer for the data to be written, but it did
+ *      // successfully write xBytesSent bytes.
+ *  }
+ *
+ *  // Send the string to the stream buffer.  Return immediately if there is not
+ *  // enough space in the buffer.
+ *  xBytesSent = xStreamBufferSend( xStreamBuffer, ( void * ) pcStringToSend, strlen( pcStringToSend ), 0 );
+ *
+ *  if( xBytesSent != strlen( pcStringToSend ) )
+ *  {
+ *      // The entire string could not be added to the stream buffer because
+ *      // there was not enough free space in the buffer, but xBytesSent bytes
+ *      // were sent.  Could try again to send the remaining bytes.
+ *  }
+ * }
+ * 
+ * \defgroup xStreamBufferSend xStreamBufferSend + * \ingroup StreamBufferManagement + */ +size_t xStreamBufferSend( StreamBufferHandle_t xStreamBuffer, + const void * pvTxData, + size_t xDataLengthBytes, + TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; + +/** + * stream_buffer.h + * + *
+ * size_t xStreamBufferSendFromISR( StreamBufferHandle_t xStreamBuffer,
+ *                               const void *pvTxData,
+ *                               size_t xDataLengthBytes,
+ *                               BaseType_t *pxHigherPriorityTaskWoken );
+ * 
+ * + * Interrupt safe version of the API function that sends a stream of bytes to + * the stream buffer. + * + * ***NOTE***: Uniquely among FreeRTOS objects, the stream buffer + * implementation (so also the message buffer implementation, as message buffers + * are built on top of stream buffers) assumes there is only one task or + * interrupt that will write to the buffer (the writer), and only one task or + * interrupt that will read from the buffer (the reader). It is safe for the + * writer and reader to be different tasks or interrupts, but, unlike other + * FreeRTOS objects, it is not safe to have multiple different writers or + * multiple different readers. If there are to be multiple different writers + * then the application writer must place each call to a writing API function + * (such as xStreamBufferSend()) inside a critical section and set the send + * block time to 0. Likewise, if there are to be multiple different readers + * then the application writer must place each call to a reading API function + * (such as xStreamBufferReceive()) inside a critical section and set the receive + * block time to 0. + * + * Use xStreamBufferSend() to write to a stream buffer from a task. Use + * xStreamBufferSendFromISR() to write to a stream buffer from an interrupt + * service routine (ISR). + * + * @param xStreamBuffer The handle of the stream buffer to which a stream is + * being sent. + * + * @param pvTxData A pointer to the data that is to be copied into the stream + * buffer. + * + * @param xDataLengthBytes The maximum number of bytes to copy from pvTxData + * into the stream buffer. + * + * @param pxHigherPriorityTaskWoken It is possible that a stream buffer will + * have a task blocked on it waiting for data. Calling + * xStreamBufferSendFromISR() can make data available, and so cause a task that + * was waiting for data to leave the Blocked state. If calling + * xStreamBufferSendFromISR() causes a task to leave the Blocked state, and the + * unblocked task has a priority higher than the currently executing task (the + * task that was interrupted), then, internally, xStreamBufferSendFromISR() + * will set *pxHigherPriorityTaskWoken to pdTRUE. If + * xStreamBufferSendFromISR() sets this value to pdTRUE, then normally a + * context switch should be performed before the interrupt is exited. This will + * ensure that the interrupt returns directly to the highest priority Ready + * state task. *pxHigherPriorityTaskWoken should be set to pdFALSE before it + * is passed into the function. See the example code below for an example. + * + * @return The number of bytes actually written to the stream buffer, which will + * be less than xDataLengthBytes if the stream buffer didn't have enough free + * space for all the bytes to be written. + * + * Example use: + *
+ * // A stream buffer that has already been created.
+ * StreamBufferHandle_t xStreamBuffer;
+ *
+ * void vAnInterruptServiceRoutine( void )
+ * {
+ * size_t xBytesSent;
+ * char *pcStringToSend = "String to send";
+ * BaseType_t xHigherPriorityTaskWoken = pdFALSE; // Initialised to pdFALSE.
+ *
+ *  // Attempt to send the string to the stream buffer.
+ *  xBytesSent = xStreamBufferSendFromISR( xStreamBuffer,
+ *                                         ( void * ) pcStringToSend,
+ *                                         strlen( pcStringToSend ),
+ *                                         &xHigherPriorityTaskWoken );
+ *
+ *  if( xBytesSent != strlen( pcStringToSend ) )
+ *  {
+ *      // There was not enough free space in the stream buffer for the entire
+ *      // string to be written, ut xBytesSent bytes were written.
+ *  }
+ *
+ *  // If xHigherPriorityTaskWoken was set to pdTRUE inside
+ *  // xStreamBufferSendFromISR() then a task that has a priority above the
+ *  // priority of the currently executing task was unblocked and a context
+ *  // switch should be performed to ensure the ISR returns to the unblocked
+ *  // task.  In most FreeRTOS ports this is done by simply passing
+ *  // xHigherPriorityTaskWoken into taskYIELD_FROM_ISR(), which will test the
+ *  // variables value, and perform the context switch if necessary.  Check the
+ *  // documentation for the port in use for port specific instructions.
+ *  taskYIELD_FROM_ISR( xHigherPriorityTaskWoken );
+ * }
+ * 
+ * \defgroup xStreamBufferSendFromISR xStreamBufferSendFromISR + * \ingroup StreamBufferManagement + */ +size_t xStreamBufferSendFromISR( StreamBufferHandle_t xStreamBuffer, + const void * pvTxData, + size_t xDataLengthBytes, + BaseType_t * const pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION; + +/** + * stream_buffer.h + * + *
+ * size_t xStreamBufferReceive( StreamBufferHandle_t xStreamBuffer,
+ *                           void *pvRxData,
+ *                           size_t xBufferLengthBytes,
+ *                           TickType_t xTicksToWait );
+ * 
+ * + * Receives bytes from a stream buffer. + * + * ***NOTE***: Uniquely among FreeRTOS objects, the stream buffer + * implementation (so also the message buffer implementation, as message buffers + * are built on top of stream buffers) assumes there is only one task or + * interrupt that will write to the buffer (the writer), and only one task or + * interrupt that will read from the buffer (the reader). It is safe for the + * writer and reader to be different tasks or interrupts, but, unlike other + * FreeRTOS objects, it is not safe to have multiple different writers or + * multiple different readers. If there are to be multiple different writers + * then the application writer must place each call to a writing API function + * (such as xStreamBufferSend()) inside a critical section and set the send + * block time to 0. Likewise, if there are to be multiple different readers + * then the application writer must place each call to a reading API function + * (such as xStreamBufferReceive()) inside a critical section and set the receive + * block time to 0. + * + * Use xStreamBufferReceive() to read from a stream buffer from a task. Use + * xStreamBufferReceiveFromISR() to read from a stream buffer from an + * interrupt service routine (ISR). + * + * @param xStreamBuffer The handle of the stream buffer from which bytes are to + * be received. + * + * @param pvRxData A pointer to the buffer into which the received bytes will be + * copied. + * + * @param xBufferLengthBytes The length of the buffer pointed to by the + * pvRxData parameter. This sets the maximum number of bytes to receive in one + * call. xStreamBufferReceive will return as many bytes as possible up to a + * maximum set by xBufferLengthBytes. + * + * @param xTicksToWait The maximum amount of time the task should remain in the + * Blocked state to wait for data to become available if the stream buffer is + * empty. xStreamBufferReceive() will return immediately if xTicksToWait is + * zero. The block time is specified in tick periods, so the absolute time it + * represents is dependent on the tick frequency. The macro pdMS_TO_TICKS() can + * be used to convert a time specified in milliseconds into a time specified in + * ticks. Setting xTicksToWait to portMAX_DELAY will cause the task to wait + * indefinitely (without timing out), provided INCLUDE_vTaskSuspend is set to 1 + * in FreeRTOSConfig.h. A task does not use any CPU time when it is in the + * Blocked state. + * + * @return The number of bytes actually read from the stream buffer, which will + * be less than xBufferLengthBytes if the call to xStreamBufferReceive() timed + * out before xBufferLengthBytes were available. + * + * Example use: + *
+ * void vAFunction( StreamBuffer_t xStreamBuffer )
+ * {
+ * uint8_t ucRxData[ 20 ];
+ * size_t xReceivedBytes;
+ * const TickType_t xBlockTime = pdMS_TO_TICKS( 20 );
+ *
+ *  // Receive up to another sizeof( ucRxData ) bytes from the stream buffer.
+ *  // Wait in the Blocked state (so not using any CPU processing time) for a
+ *  // maximum of 100ms for the full sizeof( ucRxData ) number of bytes to be
+ *  // available.
+ *  xReceivedBytes = xStreamBufferReceive( xStreamBuffer,
+ *                                         ( void * ) ucRxData,
+ *                                         sizeof( ucRxData ),
+ *                                         xBlockTime );
+ *
+ *  if( xReceivedBytes > 0 )
+ *  {
+ *      // A ucRxData contains another xRecievedBytes bytes of data, which can
+ *      // be processed here....
+ *  }
+ * }
+ * 
+ * \defgroup xStreamBufferReceive xStreamBufferReceive + * \ingroup StreamBufferManagement + */ +size_t xStreamBufferReceive( StreamBufferHandle_t xStreamBuffer, + void * pvRxData, + size_t xBufferLengthBytes, + TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; + +/** + * stream_buffer.h + * + *
+ * size_t xStreamBufferReceiveFromISR( StreamBufferHandle_t xStreamBuffer,
+ *                                  void *pvRxData,
+ *                                  size_t xBufferLengthBytes,
+ *                                  BaseType_t *pxHigherPriorityTaskWoken );
+ * 
+ * + * An interrupt safe version of the API function that receives bytes from a + * stream buffer. + * + * Use xStreamBufferReceive() to read bytes from a stream buffer from a task. + * Use xStreamBufferReceiveFromISR() to read bytes from a stream buffer from an + * interrupt service routine (ISR). + * + * @param xStreamBuffer The handle of the stream buffer from which a stream + * is being received. + * + * @param pvRxData A pointer to the buffer into which the received bytes are + * copied. + * + * @param xBufferLengthBytes The length of the buffer pointed to by the + * pvRxData parameter. This sets the maximum number of bytes to receive in one + * call. xStreamBufferReceive will return as many bytes as possible up to a + * maximum set by xBufferLengthBytes. + * + * @param pxHigherPriorityTaskWoken It is possible that a stream buffer will + * have a task blocked on it waiting for space to become available. Calling + * xStreamBufferReceiveFromISR() can make space available, and so cause a task + * that is waiting for space to leave the Blocked state. If calling + * xStreamBufferReceiveFromISR() causes a task to leave the Blocked state, and + * the unblocked task has a priority higher than the currently executing task + * (the task that was interrupted), then, internally, + * xStreamBufferReceiveFromISR() will set *pxHigherPriorityTaskWoken to pdTRUE. + * If xStreamBufferReceiveFromISR() sets this value to pdTRUE, then normally a + * context switch should be performed before the interrupt is exited. That will + * ensure the interrupt returns directly to the highest priority Ready state + * task. *pxHigherPriorityTaskWoken should be set to pdFALSE before it is + * passed into the function. See the code example below for an example. + * + * @return The number of bytes read from the stream buffer, if any. + * + * Example use: + *
+ * // A stream buffer that has already been created.
+ * StreamBuffer_t xStreamBuffer;
+ *
+ * void vAnInterruptServiceRoutine( void )
+ * {
+ * uint8_t ucRxData[ 20 ];
+ * size_t xReceivedBytes;
+ * BaseType_t xHigherPriorityTaskWoken = pdFALSE;  // Initialised to pdFALSE.
+ *
+ *  // Receive the next stream from the stream buffer.
+ *  xReceivedBytes = xStreamBufferReceiveFromISR( xStreamBuffer,
+ *                                                ( void * ) ucRxData,
+ *                                                sizeof( ucRxData ),
+ *                                                &xHigherPriorityTaskWoken );
+ *
+ *  if( xReceivedBytes > 0 )
+ *  {
+ *      // ucRxData contains xReceivedBytes read from the stream buffer.
+ *      // Process the stream here....
+ *  }
+ *
+ *  // If xHigherPriorityTaskWoken was set to pdTRUE inside
+ *  // xStreamBufferReceiveFromISR() then a task that has a priority above the
+ *  // priority of the currently executing task was unblocked and a context
+ *  // switch should be performed to ensure the ISR returns to the unblocked
+ *  // task.  In most FreeRTOS ports this is done by simply passing
+ *  // xHigherPriorityTaskWoken into taskYIELD_FROM_ISR(), which will test the
+ *  // variables value, and perform the context switch if necessary.  Check the
+ *  // documentation for the port in use for port specific instructions.
+ *  taskYIELD_FROM_ISR( xHigherPriorityTaskWoken );
+ * }
+ * 
+ * \defgroup xStreamBufferReceiveFromISR xStreamBufferReceiveFromISR + * \ingroup StreamBufferManagement + */ +size_t xStreamBufferReceiveFromISR( StreamBufferHandle_t xStreamBuffer, + void * pvRxData, + size_t xBufferLengthBytes, + BaseType_t * const pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION; + +/** + * stream_buffer.h + * + *
+ * void vStreamBufferDelete( StreamBufferHandle_t xStreamBuffer );
+ * 
+ * + * Deletes a stream buffer that was previously created using a call to + * xStreamBufferCreate() or xStreamBufferCreateStatic(). If the stream + * buffer was created using dynamic memory (that is, by xStreamBufferCreate()), + * then the allocated memory is freed. + * + * A stream buffer handle must not be used after the stream buffer has been + * deleted. + * + * @param xStreamBuffer The handle of the stream buffer to be deleted. + * + * \defgroup vStreamBufferDelete vStreamBufferDelete + * \ingroup StreamBufferManagement + */ +void vStreamBufferDelete( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION; + +/** + * stream_buffer.h + * + *
+ * BaseType_t xStreamBufferIsFull( StreamBufferHandle_t xStreamBuffer );
+ * 
+ * + * Queries a stream buffer to see if it is full. A stream buffer is full if it + * does not have any free space, and therefore cannot accept any more data. + * + * @param xStreamBuffer The handle of the stream buffer being queried. + * + * @return If the stream buffer is full then pdTRUE is returned. Otherwise + * pdFALSE is returned. + * + * \defgroup xStreamBufferIsFull xStreamBufferIsFull + * \ingroup StreamBufferManagement + */ +BaseType_t xStreamBufferIsFull( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION; + +/** + * stream_buffer.h + * + *
+ * BaseType_t xStreamBufferIsEmpty( StreamBufferHandle_t xStreamBuffer );
+ * 
+ * + * Queries a stream buffer to see if it is empty. A stream buffer is empty if + * it does not contain any data. + * + * @param xStreamBuffer The handle of the stream buffer being queried. + * + * @return If the stream buffer is empty then pdTRUE is returned. Otherwise + * pdFALSE is returned. + * + * \defgroup xStreamBufferIsEmpty xStreamBufferIsEmpty + * \ingroup StreamBufferManagement + */ +BaseType_t xStreamBufferIsEmpty( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION; + +/** + * stream_buffer.h + * + *
+ * BaseType_t xStreamBufferReset( StreamBufferHandle_t xStreamBuffer );
+ * 
+ * + * Resets a stream buffer to its initial, empty, state. Any data that was in + * the stream buffer is discarded. A stream buffer can only be reset if there + * are no tasks blocked waiting to either send to or receive from the stream + * buffer. + * + * @param xStreamBuffer The handle of the stream buffer being reset. + * + * @return If the stream buffer is reset then pdPASS is returned. If there was + * a task blocked waiting to send to or read from the stream buffer then the + * stream buffer is not reset and pdFAIL is returned. + * + * \defgroup xStreamBufferReset xStreamBufferReset + * \ingroup StreamBufferManagement + */ +BaseType_t xStreamBufferReset( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION; + +/** + * stream_buffer.h + * + *
+ * size_t xStreamBufferSpacesAvailable( StreamBufferHandle_t xStreamBuffer );
+ * 
+ * + * Queries a stream buffer to see how much free space it contains, which is + * equal to the amount of data that can be sent to the stream buffer before it + * is full. + * + * @param xStreamBuffer The handle of the stream buffer being queried. + * + * @return The number of bytes that can be written to the stream buffer before + * the stream buffer would be full. + * + * \defgroup xStreamBufferSpacesAvailable xStreamBufferSpacesAvailable + * \ingroup StreamBufferManagement + */ +size_t xStreamBufferSpacesAvailable( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION; + +/** + * stream_buffer.h + * + *
+ * size_t xStreamBufferBytesAvailable( StreamBufferHandle_t xStreamBuffer );
+ * 
+ * + * Queries a stream buffer to see how much data it contains, which is equal to + * the number of bytes that can be read from the stream buffer before the stream + * buffer would be empty. + * + * @param xStreamBuffer The handle of the stream buffer being queried. + * + * @return The number of bytes that can be read from the stream buffer before + * the stream buffer would be empty. + * + * \defgroup xStreamBufferBytesAvailable xStreamBufferBytesAvailable + * \ingroup StreamBufferManagement + */ +size_t xStreamBufferBytesAvailable( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION; + +/** + * stream_buffer.h + * + *
+ * BaseType_t xStreamBufferSetTriggerLevel( StreamBufferHandle_t xStreamBuffer, size_t xTriggerLevel );
+ * 
+ * + * A stream buffer's trigger level is the number of bytes that must be in the + * stream buffer before a task that is blocked on the stream buffer to + * wait for data is moved out of the blocked state. For example, if a task is + * blocked on a read of an empty stream buffer that has a trigger level of 1 + * then the task will be unblocked when a single byte is written to the buffer + * or the task's block time expires. As another example, if a task is blocked + * on a read of an empty stream buffer that has a trigger level of 10 then the + * task will not be unblocked until the stream buffer contains at least 10 bytes + * or the task's block time expires. If a reading task's block time expires + * before the trigger level is reached then the task will still receive however + * many bytes are actually available. Setting a trigger level of 0 will result + * in a trigger level of 1 being used. It is not valid to specify a trigger + * level that is greater than the buffer size. + * + * A trigger level is set when the stream buffer is created, and can be modified + * using xStreamBufferSetTriggerLevel(). + * + * @param xStreamBuffer The handle of the stream buffer being updated. + * + * @param xTriggerLevel The new trigger level for the stream buffer. + * + * @return If xTriggerLevel was less than or equal to the stream buffer's length + * then the trigger level will be updated and pdTRUE is returned. Otherwise + * pdFALSE is returned. + * + * \defgroup xStreamBufferSetTriggerLevel xStreamBufferSetTriggerLevel + * \ingroup StreamBufferManagement + */ +BaseType_t xStreamBufferSetTriggerLevel( StreamBufferHandle_t xStreamBuffer, + size_t xTriggerLevel ) PRIVILEGED_FUNCTION; + +/** + * stream_buffer.h + * + *
+ * BaseType_t xStreamBufferSendCompletedFromISR( StreamBufferHandle_t xStreamBuffer, BaseType_t *pxHigherPriorityTaskWoken );
+ * 
+ * + * For advanced users only. + * + * The sbSEND_COMPLETED() macro is called from within the FreeRTOS APIs when + * data is sent to a message buffer or stream buffer. If there was a task that + * was blocked on the message or stream buffer waiting for data to arrive then + * the sbSEND_COMPLETED() macro sends a notification to the task to remove it + * from the Blocked state. xStreamBufferSendCompletedFromISR() does the same + * thing. It is provided to enable application writers to implement their own + * version of sbSEND_COMPLETED(), and MUST NOT BE USED AT ANY OTHER TIME. + * + * See the example implemented in FreeRTOS/Demo/Minimal/MessageBufferAMP.c for + * additional information. + * + * @param xStreamBuffer The handle of the stream buffer to which data was + * written. + * + * @param pxHigherPriorityTaskWoken *pxHigherPriorityTaskWoken should be + * initialised to pdFALSE before it is passed into + * xStreamBufferSendCompletedFromISR(). If calling + * xStreamBufferSendCompletedFromISR() removes a task from the Blocked state, + * and the task has a priority above the priority of the currently running task, + * then *pxHigherPriorityTaskWoken will get set to pdTRUE indicating that a + * context switch should be performed before exiting the ISR. + * + * @return If a task was removed from the Blocked state then pdTRUE is returned. + * Otherwise pdFALSE is returned. + * + * \defgroup xStreamBufferSendCompletedFromISR xStreamBufferSendCompletedFromISR + * \ingroup StreamBufferManagement + */ +BaseType_t xStreamBufferSendCompletedFromISR( StreamBufferHandle_t xStreamBuffer, + BaseType_t * pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION; + +/** + * stream_buffer.h + * + *
+ * BaseType_t xStreamBufferReceiveCompletedFromISR( StreamBufferHandle_t xStreamBuffer, BaseType_t *pxHigherPriorityTaskWoken );
+ * 
+ * + * For advanced users only. + * + * The sbRECEIVE_COMPLETED() macro is called from within the FreeRTOS APIs when + * data is read out of a message buffer or stream buffer. If there was a task + * that was blocked on the message or stream buffer waiting for data to arrive + * then the sbRECEIVE_COMPLETED() macro sends a notification to the task to + * remove it from the Blocked state. xStreamBufferReceiveCompletedFromISR() + * does the same thing. It is provided to enable application writers to + * implement their own version of sbRECEIVE_COMPLETED(), and MUST NOT BE USED AT + * ANY OTHER TIME. + * + * See the example implemented in FreeRTOS/Demo/Minimal/MessageBufferAMP.c for + * additional information. + * + * @param xStreamBuffer The handle of the stream buffer from which data was + * read. + * + * @param pxHigherPriorityTaskWoken *pxHigherPriorityTaskWoken should be + * initialised to pdFALSE before it is passed into + * xStreamBufferReceiveCompletedFromISR(). If calling + * xStreamBufferReceiveCompletedFromISR() removes a task from the Blocked state, + * and the task has a priority above the priority of the currently running task, + * then *pxHigherPriorityTaskWoken will get set to pdTRUE indicating that a + * context switch should be performed before exiting the ISR. + * + * @return If a task was removed from the Blocked state then pdTRUE is returned. + * Otherwise pdFALSE is returned. + * + * \defgroup xStreamBufferReceiveCompletedFromISR xStreamBufferReceiveCompletedFromISR + * \ingroup StreamBufferManagement + */ +BaseType_t xStreamBufferReceiveCompletedFromISR( StreamBufferHandle_t xStreamBuffer, + BaseType_t * pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION; + +/* Functions below here are not part of the public API. */ +StreamBufferHandle_t xStreamBufferGenericCreate( size_t xBufferSizeBytes, + size_t xTriggerLevelBytes, + BaseType_t xIsMessageBuffer ) PRIVILEGED_FUNCTION; + +StreamBufferHandle_t xStreamBufferGenericCreateStatic( size_t xBufferSizeBytes, + size_t xTriggerLevelBytes, + BaseType_t xIsMessageBuffer, + uint8_t * const pucStreamBufferStorageArea, + StaticStreamBuffer_t * const pxStaticStreamBuffer ) PRIVILEGED_FUNCTION; + +size_t xStreamBufferNextMessageLengthBytes( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION; + +#if ( configUSE_TRACE_FACILITY == 1 ) + void vStreamBufferSetStreamBufferNumber( StreamBufferHandle_t xStreamBuffer, + UBaseType_t uxStreamBufferNumber ) PRIVILEGED_FUNCTION; + UBaseType_t uxStreamBufferGetStreamBufferNumber( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION; + uint8_t ucStreamBufferGetStreamBufferType( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION; +#endif + +/* *INDENT-OFF* */ +#if defined( __cplusplus ) + } +#endif +/* *INDENT-ON* */ + +#endif /* !defined( STREAM_BUFFER_H ) */ diff --git a/RTOS/FreeRTOS/Source/include/task.h b/RTOS/FreeRTOS/Source/include/task.h new file mode 100644 index 0000000..730deec --- /dev/null +++ b/RTOS/FreeRTOS/Source/include/task.h @@ -0,0 +1,3037 @@ +/* + * FreeRTOS Kernel V10.4.1 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * https://www.FreeRTOS.org + * https://github.com/FreeRTOS + * + */ + + +#ifndef INC_TASK_H +#define INC_TASK_H + +#ifndef INC_FREERTOS_H + #error "include FreeRTOS.h must appear in source files before include task.h" +#endif + +#include "list.h" + +/* *INDENT-OFF* */ +#ifdef __cplusplus + extern "C" { +#endif +/* *INDENT-ON* */ + +/*----------------------------------------------------------- +* MACROS AND DEFINITIONS +*----------------------------------------------------------*/ + +#define tskKERNEL_VERSION_NUMBER "V10.4.1" +#define tskKERNEL_VERSION_MAJOR 10 +#define tskKERNEL_VERSION_MINOR 4 +#define tskKERNEL_VERSION_BUILD 1 + +/* MPU region parameters passed in ulParameters + * of MemoryRegion_t struct. */ +#define tskMPU_REGION_READ_ONLY ( 1UL << 0UL ) +#define tskMPU_REGION_READ_WRITE ( 1UL << 1UL ) +#define tskMPU_REGION_EXECUTE_NEVER ( 1UL << 2UL ) +#define tskMPU_REGION_NORMAL_MEMORY ( 1UL << 3UL ) +#define tskMPU_REGION_DEVICE_MEMORY ( 1UL << 4UL ) + +/* The direct to task notification feature used to have only a single notification + * per task. Now there is an array of notifications per task that is dimensioned by + * configTASK_NOTIFICATION_ARRAY_ENTRIES. For backward compatibility, any use of the + * original direct to task notification defaults to using the first index in the + * array. */ +#define tskDEFAULT_INDEX_TO_NOTIFY ( 0 ) + +/** + * task. h + * + * Type by which tasks are referenced. For example, a call to xTaskCreate + * returns (via a pointer parameter) an TaskHandle_t variable that can then + * be used as a parameter to vTaskDelete to delete the task. + * + * \defgroup TaskHandle_t TaskHandle_t + * \ingroup Tasks + */ +struct tskTaskControlBlock; /* The old naming convention is used to prevent breaking kernel aware debuggers. */ +typedef struct tskTaskControlBlock * TaskHandle_t; + +/* + * Defines the prototype to which the application task hook function must + * conform. + */ +typedef BaseType_t (* TaskHookFunction_t)( void * ); + +/* Task states returned by eTaskGetState. */ +typedef enum +{ + eRunning = 0, /* A task is querying the state of itself, so must be running. */ + eReady, /* The task being queried is in a read or pending ready list. */ + eBlocked, /* The task being queried is in the Blocked state. */ + eSuspended, /* The task being queried is in the Suspended state, or is in the Blocked state with an infinite time out. */ + eDeleted, /* The task being queried has been deleted, but its TCB has not yet been freed. */ + eInvalid /* Used as an 'invalid state' value. */ +} eTaskState; + +/* Actions that can be performed when vTaskNotify() is called. */ +typedef enum +{ + eNoAction = 0, /* Notify the task without updating its notify value. */ + eSetBits, /* Set bits in the task's notification value. */ + eIncrement, /* Increment the task's notification value. */ + eSetValueWithOverwrite, /* Set the task's notification value to a specific value even if the previous value has not yet been read by the task. */ + eSetValueWithoutOverwrite /* Set the task's notification value if the previous value has been read by the task. */ +} eNotifyAction; + +/* + * Used internally only. + */ +typedef struct xTIME_OUT +{ + BaseType_t xOverflowCount; + TickType_t xTimeOnEntering; +} TimeOut_t; + +/* + * Defines the memory ranges allocated to the task when an MPU is used. + */ +typedef struct xMEMORY_REGION +{ + void * pvBaseAddress; + uint32_t ulLengthInBytes; + uint32_t ulParameters; +} MemoryRegion_t; + +/* + * Parameters required to create an MPU protected task. + */ +typedef struct xTASK_PARAMETERS +{ + TaskFunction_t pvTaskCode; + const char * const pcName; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + configSTACK_DEPTH_TYPE usStackDepth; + void * pvParameters; + UBaseType_t uxPriority; + StackType_t * puxStackBuffer; + MemoryRegion_t xRegions[ portNUM_CONFIGURABLE_REGIONS ]; + #if ( ( portUSING_MPU_WRAPPERS == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) ) + StaticTask_t * const pxTaskBuffer; + #endif +} TaskParameters_t; + +/* Used with the uxTaskGetSystemState() function to return the state of each task + * in the system. */ +typedef struct xTASK_STATUS +{ + TaskHandle_t xHandle; /* The handle of the task to which the rest of the information in the structure relates. */ + const char * pcTaskName; /* A pointer to the task's name. This value will be invalid if the task was deleted since the structure was populated! */ /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + UBaseType_t xTaskNumber; /* A number unique to the task. */ + eTaskState eCurrentState; /* The state in which the task existed when the structure was populated. */ + UBaseType_t uxCurrentPriority; /* The priority at which the task was running (may be inherited) when the structure was populated. */ + UBaseType_t uxBasePriority; /* The priority to which the task will return if the task's current priority has been inherited to avoid unbounded priority inversion when obtaining a mutex. Only valid if configUSE_MUTEXES is defined as 1 in FreeRTOSConfig.h. */ + uint32_t ulRunTimeCounter; /* The total run time allocated to the task so far, as defined by the run time stats clock. See https://www.FreeRTOS.org/rtos-run-time-stats.html. Only valid when configGENERATE_RUN_TIME_STATS is defined as 1 in FreeRTOSConfig.h. */ + StackType_t * pxStackBase; /* Points to the lowest address of the task's stack area. */ + configSTACK_DEPTH_TYPE usStackHighWaterMark; /* The minimum amount of stack space that has remained for the task since the task was created. The closer this value is to zero the closer the task has come to overflowing its stack. */ +} TaskStatus_t; + +/* Possible return values for eTaskConfirmSleepModeStatus(). */ +typedef enum +{ + eAbortSleep = 0, /* A task has been made ready or a context switch pended since portSUPPORESS_TICKS_AND_SLEEP() was called - abort entering a sleep mode. */ + eStandardSleep, /* Enter a sleep mode that will not last any longer than the expected idle time. */ + eNoTasksWaitingTimeout /* No tasks are waiting for a timeout so it is safe to enter a sleep mode that can only be exited by an external interrupt. */ +} eSleepModeStatus; + +/** + * Defines the priority used by the idle task. This must not be modified. + * + * \ingroup TaskUtils + */ +#define tskIDLE_PRIORITY ( ( UBaseType_t ) 0U ) + +/** + * task. h + * + * Macro for forcing a context switch. + * + * \defgroup taskYIELD taskYIELD + * \ingroup SchedulerControl + */ +#define taskYIELD() portYIELD() + +/** + * task. h + * + * Macro to mark the start of a critical code region. Preemptive context + * switches cannot occur when in a critical region. + * + * NOTE: This may alter the stack (depending on the portable implementation) + * so must be used with care! + * + * \defgroup taskENTER_CRITICAL taskENTER_CRITICAL + * \ingroup SchedulerControl + */ +#define taskENTER_CRITICAL() portENTER_CRITICAL() +#define taskENTER_CRITICAL_FROM_ISR() portSET_INTERRUPT_MASK_FROM_ISR() + +/** + * task. h + * + * Macro to mark the end of a critical code region. Preemptive context + * switches cannot occur when in a critical region. + * + * NOTE: This may alter the stack (depending on the portable implementation) + * so must be used with care! + * + * \defgroup taskEXIT_CRITICAL taskEXIT_CRITICAL + * \ingroup SchedulerControl + */ +#define taskEXIT_CRITICAL() portEXIT_CRITICAL() +#define taskEXIT_CRITICAL_FROM_ISR( x ) portCLEAR_INTERRUPT_MASK_FROM_ISR( x ) + +/** + * task. h + * + * Macro to disable all maskable interrupts. + * + * \defgroup taskDISABLE_INTERRUPTS taskDISABLE_INTERRUPTS + * \ingroup SchedulerControl + */ +#define taskDISABLE_INTERRUPTS() portDISABLE_INTERRUPTS() + +/** + * task. h + * + * Macro to enable microcontroller interrupts. + * + * \defgroup taskENABLE_INTERRUPTS taskENABLE_INTERRUPTS + * \ingroup SchedulerControl + */ +#define taskENABLE_INTERRUPTS() portENABLE_INTERRUPTS() + +/* Definitions returned by xTaskGetSchedulerState(). taskSCHEDULER_SUSPENDED is + * 0 to generate more optimal code when configASSERT() is defined as the constant + * is used in assert() statements. */ +#define taskSCHEDULER_SUSPENDED ( ( BaseType_t ) 0 ) +#define taskSCHEDULER_NOT_STARTED ( ( BaseType_t ) 1 ) +#define taskSCHEDULER_RUNNING ( ( BaseType_t ) 2 ) + + +/*----------------------------------------------------------- +* TASK CREATION API +*----------------------------------------------------------*/ + +/** + * task. h + *
+ * BaseType_t xTaskCreate(
+ *                            TaskFunction_t pvTaskCode,
+ *                            const char * const pcName,
+ *                            configSTACK_DEPTH_TYPE usStackDepth,
+ *                            void *pvParameters,
+ *                            UBaseType_t uxPriority,
+ *                            TaskHandle_t *pvCreatedTask
+ *                        );
+ * 
+ * + * Create a new task and add it to the list of tasks that are ready to run. + * + * Internally, within the FreeRTOS implementation, tasks use two blocks of + * memory. The first block is used to hold the task's data structures. The + * second block is used by the task as its stack. If a task is created using + * xTaskCreate() then both blocks of memory are automatically dynamically + * allocated inside the xTaskCreate() function. (see + * https://www.FreeRTOS.org/a00111.html). If a task is created using + * xTaskCreateStatic() then the application writer must provide the required + * memory. xTaskCreateStatic() therefore allows a task to be created without + * using any dynamic memory allocation. + * + * See xTaskCreateStatic() for a version that does not use any dynamic memory + * allocation. + * + * xTaskCreate() can only be used to create a task that has unrestricted + * access to the entire microcontroller memory map. Systems that include MPU + * support can alternatively create an MPU constrained task using + * xTaskCreateRestricted(). + * + * @param pvTaskCode Pointer to the task entry function. Tasks + * must be implemented to never return (i.e. continuous loop). + * + * @param pcName A descriptive name for the task. This is mainly used to + * facilitate debugging. Max length defined by configMAX_TASK_NAME_LEN - default + * is 16. + * + * @param usStackDepth The size of the task stack specified as the number of + * variables the stack can hold - not the number of bytes. For example, if + * the stack is 16 bits wide and usStackDepth is defined as 100, 200 bytes + * will be allocated for stack storage. + * + * @param pvParameters Pointer that will be used as the parameter for the task + * being created. + * + * @param uxPriority The priority at which the task should run. Systems that + * include MPU support can optionally create tasks in a privileged (system) + * mode by setting bit portPRIVILEGE_BIT of the priority parameter. For + * example, to create a privileged task at priority 2 the uxPriority parameter + * should be set to ( 2 | portPRIVILEGE_BIT ). + * + * @param pvCreatedTask Used to pass back a handle by which the created task + * can be referenced. + * + * @return pdPASS if the task was successfully created and added to a ready + * list, otherwise an error code defined in the file projdefs.h + * + * Example usage: + *
+ * // Task to be created.
+ * void vTaskCode( void * pvParameters )
+ * {
+ *   for( ;; )
+ *   {
+ *       // Task code goes here.
+ *   }
+ * }
+ *
+ * // Function that creates a task.
+ * void vOtherFunction( void )
+ * {
+ * static uint8_t ucParameterToPass;
+ * TaskHandle_t xHandle = NULL;
+ *
+ *   // Create the task, storing the handle.  Note that the passed parameter ucParameterToPass
+ *   // must exist for the lifetime of the task, so in this case is declared static.  If it was just an
+ *   // an automatic stack variable it might no longer exist, or at least have been corrupted, by the time
+ *   // the new task attempts to access it.
+ *   xTaskCreate( vTaskCode, "NAME", STACK_SIZE, &ucParameterToPass, tskIDLE_PRIORITY, &xHandle );
+ *   configASSERT( xHandle );
+ *
+ *   // Use the handle to delete the task.
+ *   if( xHandle != NULL )
+ *   {
+ *      vTaskDelete( xHandle );
+ *   }
+ * }
+ * 
+ * \defgroup xTaskCreate xTaskCreate + * \ingroup Tasks + */ +#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + BaseType_t xTaskCreate( TaskFunction_t pxTaskCode, + const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + const configSTACK_DEPTH_TYPE usStackDepth, + void * const pvParameters, + UBaseType_t uxPriority, + TaskHandle_t * const pxCreatedTask ) PRIVILEGED_FUNCTION; +#endif + +/** + * task. h + *
+ * TaskHandle_t xTaskCreateStatic( TaskFunction_t pvTaskCode,
+ *                               const char * const pcName,
+ *                               uint32_t ulStackDepth,
+ *                               void *pvParameters,
+ *                               UBaseType_t uxPriority,
+ *                               StackType_t *pxStackBuffer,
+ *                               StaticTask_t *pxTaskBuffer );
+ * 
+ * + * Create a new task and add it to the list of tasks that are ready to run. + * + * Internally, within the FreeRTOS implementation, tasks use two blocks of + * memory. The first block is used to hold the task's data structures. The + * second block is used by the task as its stack. If a task is created using + * xTaskCreate() then both blocks of memory are automatically dynamically + * allocated inside the xTaskCreate() function. (see + * https://www.FreeRTOS.org/a00111.html). If a task is created using + * xTaskCreateStatic() then the application writer must provide the required + * memory. xTaskCreateStatic() therefore allows a task to be created without + * using any dynamic memory allocation. + * + * @param pvTaskCode Pointer to the task entry function. Tasks + * must be implemented to never return (i.e. continuous loop). + * + * @param pcName A descriptive name for the task. This is mainly used to + * facilitate debugging. The maximum length of the string is defined by + * configMAX_TASK_NAME_LEN in FreeRTOSConfig.h. + * + * @param ulStackDepth The size of the task stack specified as the number of + * variables the stack can hold - not the number of bytes. For example, if + * the stack is 32-bits wide and ulStackDepth is defined as 100 then 400 bytes + * will be allocated for stack storage. + * + * @param pvParameters Pointer that will be used as the parameter for the task + * being created. + * + * @param uxPriority The priority at which the task will run. + * + * @param pxStackBuffer Must point to a StackType_t array that has at least + * ulStackDepth indexes - the array will then be used as the task's stack, + * removing the need for the stack to be allocated dynamically. + * + * @param pxTaskBuffer Must point to a variable of type StaticTask_t, which will + * then be used to hold the task's data structures, removing the need for the + * memory to be allocated dynamically. + * + * @return If neither pxStackBuffer or pxTaskBuffer are NULL, then the task will + * be created and a handle to the created task is returned. If either + * pxStackBuffer or pxTaskBuffer are NULL then the task will not be created and + * NULL is returned. + * + * Example usage: + *
+ *
+ *  // Dimensions the buffer that the task being created will use as its stack.
+ *  // NOTE:  This is the number of words the stack will hold, not the number of
+ *  // bytes.  For example, if each stack item is 32-bits, and this is set to 100,
+ *  // then 400 bytes (100 * 32-bits) will be allocated.
+ #define STACK_SIZE 200
+ *
+ *  // Structure that will hold the TCB of the task being created.
+ *  StaticTask_t xTaskBuffer;
+ *
+ *  // Buffer that the task being created will use as its stack.  Note this is
+ *  // an array of StackType_t variables.  The size of StackType_t is dependent on
+ *  // the RTOS port.
+ *  StackType_t xStack[ STACK_SIZE ];
+ *
+ *  // Function that implements the task being created.
+ *  void vTaskCode( void * pvParameters )
+ *  {
+ *      // The parameter value is expected to be 1 as 1 is passed in the
+ *      // pvParameters value in the call to xTaskCreateStatic().
+ *      configASSERT( ( uint32_t ) pvParameters == 1UL );
+ *
+ *      for( ;; )
+ *      {
+ *          // Task code goes here.
+ *      }
+ *  }
+ *
+ *  // Function that creates a task.
+ *  void vOtherFunction( void )
+ *  {
+ *      TaskHandle_t xHandle = NULL;
+ *
+ *      // Create the task without using any dynamic memory allocation.
+ *      xHandle = xTaskCreateStatic(
+ *                    vTaskCode,       // Function that implements the task.
+ *                    "NAME",          // Text name for the task.
+ *                    STACK_SIZE,      // Stack size in words, not bytes.
+ *                    ( void * ) 1,    // Parameter passed into the task.
+ *                    tskIDLE_PRIORITY,// Priority at which the task is created.
+ *                    xStack,          // Array to use as the task's stack.
+ *                    &xTaskBuffer );  // Variable to hold the task's data structure.
+ *
+ *      // puxStackBuffer and pxTaskBuffer were not NULL, so the task will have
+ *      // been created, and xHandle will be the task's handle.  Use the handle
+ *      // to suspend the task.
+ *      vTaskSuspend( xHandle );
+ *  }
+ * 
+ * \defgroup xTaskCreateStatic xTaskCreateStatic + * \ingroup Tasks + */ +#if ( configSUPPORT_STATIC_ALLOCATION == 1 ) + TaskHandle_t xTaskCreateStatic( TaskFunction_t pxTaskCode, + const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + const uint32_t ulStackDepth, + void * const pvParameters, + UBaseType_t uxPriority, + StackType_t * const puxStackBuffer, + StaticTask_t * const pxTaskBuffer ) PRIVILEGED_FUNCTION; +#endif /* configSUPPORT_STATIC_ALLOCATION */ + +/** + * task. h + *
+ * BaseType_t xTaskCreateRestricted( TaskParameters_t *pxTaskDefinition, TaskHandle_t *pxCreatedTask );
+ * 
+ * + * Only available when configSUPPORT_DYNAMIC_ALLOCATION is set to 1. + * + * xTaskCreateRestricted() should only be used in systems that include an MPU + * implementation. + * + * Create a new task and add it to the list of tasks that are ready to run. + * The function parameters define the memory regions and associated access + * permissions allocated to the task. + * + * See xTaskCreateRestrictedStatic() for a version that does not use any + * dynamic memory allocation. + * + * @param pxTaskDefinition Pointer to a structure that contains a member + * for each of the normal xTaskCreate() parameters (see the xTaskCreate() API + * documentation) plus an optional stack buffer and the memory region + * definitions. + * + * @param pxCreatedTask Used to pass back a handle by which the created task + * can be referenced. + * + * @return pdPASS if the task was successfully created and added to a ready + * list, otherwise an error code defined in the file projdefs.h + * + * Example usage: + *
+ * // Create an TaskParameters_t structure that defines the task to be created.
+ * static const TaskParameters_t xCheckTaskParameters =
+ * {
+ *  vATask,     // pvTaskCode - the function that implements the task.
+ *  "ATask",    // pcName - just a text name for the task to assist debugging.
+ *  100,        // usStackDepth - the stack size DEFINED IN WORDS.
+ *  NULL,       // pvParameters - passed into the task function as the function parameters.
+ *  ( 1UL | portPRIVILEGE_BIT ),// uxPriority - task priority, set the portPRIVILEGE_BIT if the task should run in a privileged state.
+ *  cStackBuffer,// puxStackBuffer - the buffer to be used as the task stack.
+ *
+ *  // xRegions - Allocate up to three separate memory regions for access by
+ *  // the task, with appropriate access permissions.  Different processors have
+ *  // different memory alignment requirements - refer to the FreeRTOS documentation
+ *  // for full information.
+ *  {
+ *      // Base address                 Length  Parameters
+ *      { cReadWriteArray,              32,     portMPU_REGION_READ_WRITE },
+ *      { cReadOnlyArray,               32,     portMPU_REGION_READ_ONLY },
+ *      { cPrivilegedOnlyAccessArray,   128,    portMPU_REGION_PRIVILEGED_READ_WRITE }
+ *  }
+ * };
+ *
+ * int main( void )
+ * {
+ * TaskHandle_t xHandle;
+ *
+ *  // Create a task from the const structure defined above.  The task handle
+ *  // is requested (the second parameter is not NULL) but in this case just for
+ *  // demonstration purposes as its not actually used.
+ *  xTaskCreateRestricted( &xRegTest1Parameters, &xHandle );
+ *
+ *  // Start the scheduler.
+ *  vTaskStartScheduler();
+ *
+ *  // Will only get here if there was insufficient memory to create the idle
+ *  // and/or timer task.
+ *  for( ;; );
+ * }
+ * 
+ * \defgroup xTaskCreateRestricted xTaskCreateRestricted + * \ingroup Tasks + */ +#if ( portUSING_MPU_WRAPPERS == 1 ) + BaseType_t xTaskCreateRestricted( const TaskParameters_t * const pxTaskDefinition, + TaskHandle_t * pxCreatedTask ) PRIVILEGED_FUNCTION; +#endif + +/** + * task. h + *
+ * BaseType_t xTaskCreateRestrictedStatic( TaskParameters_t *pxTaskDefinition, TaskHandle_t *pxCreatedTask );
+ * 
+ * + * Only available when configSUPPORT_STATIC_ALLOCATION is set to 1. + * + * xTaskCreateRestrictedStatic() should only be used in systems that include an + * MPU implementation. + * + * Internally, within the FreeRTOS implementation, tasks use two blocks of + * memory. The first block is used to hold the task's data structures. The + * second block is used by the task as its stack. If a task is created using + * xTaskCreateRestricted() then the stack is provided by the application writer, + * and the memory used to hold the task's data structure is automatically + * dynamically allocated inside the xTaskCreateRestricted() function. If a task + * is created using xTaskCreateRestrictedStatic() then the application writer + * must provide the memory used to hold the task's data structures too. + * xTaskCreateRestrictedStatic() therefore allows a memory protected task to be + * created without using any dynamic memory allocation. + * + * @param pxTaskDefinition Pointer to a structure that contains a member + * for each of the normal xTaskCreate() parameters (see the xTaskCreate() API + * documentation) plus an optional stack buffer and the memory region + * definitions. If configSUPPORT_STATIC_ALLOCATION is set to 1 the structure + * contains an additional member, which is used to point to a variable of type + * StaticTask_t - which is then used to hold the task's data structure. + * + * @param pxCreatedTask Used to pass back a handle by which the created task + * can be referenced. + * + * @return pdPASS if the task was successfully created and added to a ready + * list, otherwise an error code defined in the file projdefs.h + * + * Example usage: + *
+ * // Create an TaskParameters_t structure that defines the task to be created.
+ * // The StaticTask_t variable is only included in the structure when
+ * // configSUPPORT_STATIC_ALLOCATION is set to 1.  The PRIVILEGED_DATA macro can
+ * // be used to force the variable into the RTOS kernel's privileged data area.
+ * static PRIVILEGED_DATA StaticTask_t xTaskBuffer;
+ * static const TaskParameters_t xCheckTaskParameters =
+ * {
+ *  vATask,     // pvTaskCode - the function that implements the task.
+ *  "ATask",    // pcName - just a text name for the task to assist debugging.
+ *  100,        // usStackDepth - the stack size DEFINED IN WORDS.
+ *  NULL,       // pvParameters - passed into the task function as the function parameters.
+ *  ( 1UL | portPRIVILEGE_BIT ),// uxPriority - task priority, set the portPRIVILEGE_BIT if the task should run in a privileged state.
+ *  cStackBuffer,// puxStackBuffer - the buffer to be used as the task stack.
+ *
+ *  // xRegions - Allocate up to three separate memory regions for access by
+ *  // the task, with appropriate access permissions.  Different processors have
+ *  // different memory alignment requirements - refer to the FreeRTOS documentation
+ *  // for full information.
+ *  {
+ *      // Base address                 Length  Parameters
+ *      { cReadWriteArray,              32,     portMPU_REGION_READ_WRITE },
+ *      { cReadOnlyArray,               32,     portMPU_REGION_READ_ONLY },
+ *      { cPrivilegedOnlyAccessArray,   128,    portMPU_REGION_PRIVILEGED_READ_WRITE }
+ *  }
+ *
+ *  &xTaskBuffer; // Holds the task's data structure.
+ * };
+ *
+ * int main( void )
+ * {
+ * TaskHandle_t xHandle;
+ *
+ *  // Create a task from the const structure defined above.  The task handle
+ *  // is requested (the second parameter is not NULL) but in this case just for
+ *  // demonstration purposes as its not actually used.
+ *  xTaskCreateRestricted( &xRegTest1Parameters, &xHandle );
+ *
+ *  // Start the scheduler.
+ *  vTaskStartScheduler();
+ *
+ *  // Will only get here if there was insufficient memory to create the idle
+ *  // and/or timer task.
+ *  for( ;; );
+ * }
+ * 
+ * \defgroup xTaskCreateRestrictedStatic xTaskCreateRestrictedStatic + * \ingroup Tasks + */ +#if ( ( portUSING_MPU_WRAPPERS == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) ) + BaseType_t xTaskCreateRestrictedStatic( const TaskParameters_t * const pxTaskDefinition, + TaskHandle_t * pxCreatedTask ) PRIVILEGED_FUNCTION; +#endif + +/** + * task. h + *
+ * void vTaskAllocateMPURegions( TaskHandle_t xTask, const MemoryRegion_t * const pxRegions );
+ * 
+ * + * Memory regions are assigned to a restricted task when the task is created by + * a call to xTaskCreateRestricted(). These regions can be redefined using + * vTaskAllocateMPURegions(). + * + * @param xTask The handle of the task being updated. + * + * @param xRegions A pointer to an MemoryRegion_t structure that contains the + * new memory region definitions. + * + * Example usage: + *
+ * // Define an array of MemoryRegion_t structures that configures an MPU region
+ * // allowing read/write access for 1024 bytes starting at the beginning of the
+ * // ucOneKByte array.  The other two of the maximum 3 definable regions are
+ * // unused so set to zero.
+ * static const MemoryRegion_t xAltRegions[ portNUM_CONFIGURABLE_REGIONS ] =
+ * {
+ *  // Base address     Length      Parameters
+ *  { ucOneKByte,       1024,       portMPU_REGION_READ_WRITE },
+ *  { 0,                0,          0 },
+ *  { 0,                0,          0 }
+ * };
+ *
+ * void vATask( void *pvParameters )
+ * {
+ *  // This task was created such that it has access to certain regions of
+ *  // memory as defined by the MPU configuration.  At some point it is
+ *  // desired that these MPU regions are replaced with that defined in the
+ *  // xAltRegions const struct above.  Use a call to vTaskAllocateMPURegions()
+ *  // for this purpose.  NULL is used as the task handle to indicate that this
+ *  // function should modify the MPU regions of the calling task.
+ *  vTaskAllocateMPURegions( NULL, xAltRegions );
+ *
+ *  // Now the task can continue its function, but from this point on can only
+ *  // access its stack and the ucOneKByte array (unless any other statically
+ *  // defined or shared regions have been declared elsewhere).
+ * }
+ * 
+ * \defgroup xTaskCreateRestricted xTaskCreateRestricted + * \ingroup Tasks + */ +void vTaskAllocateMPURegions( TaskHandle_t xTask, + const MemoryRegion_t * const pxRegions ) PRIVILEGED_FUNCTION; + +/** + * task. h + *
+ * void vTaskDelete( TaskHandle_t xTask );
+ * 
+ * + * INCLUDE_vTaskDelete must be defined as 1 for this function to be available. + * See the configuration section for more information. + * + * Remove a task from the RTOS real time kernel's management. The task being + * deleted will be removed from all ready, blocked, suspended and event lists. + * + * NOTE: The idle task is responsible for freeing the kernel allocated + * memory from tasks that have been deleted. It is therefore important that + * the idle task is not starved of microcontroller processing time if your + * application makes any calls to vTaskDelete (). Memory allocated by the + * task code is not automatically freed, and should be freed before the task + * is deleted. + * + * See the demo application file death.c for sample code that utilises + * vTaskDelete (). + * + * @param xTask The handle of the task to be deleted. Passing NULL will + * cause the calling task to be deleted. + * + * Example usage: + *
+ * void vOtherFunction( void )
+ * {
+ * TaskHandle_t xHandle;
+ *
+ *   // Create the task, storing the handle.
+ *   xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
+ *
+ *   // Use the handle to delete the task.
+ *   vTaskDelete( xHandle );
+ * }
+ * 
+ * \defgroup vTaskDelete vTaskDelete + * \ingroup Tasks + */ +void vTaskDelete( TaskHandle_t xTaskToDelete ) PRIVILEGED_FUNCTION; + +/*----------------------------------------------------------- +* TASK CONTROL API +*----------------------------------------------------------*/ + +/** + * task. h + *
+ * void vTaskDelay( const TickType_t xTicksToDelay );
+ * 
+ * + * Delay a task for a given number of ticks. The actual time that the + * task remains blocked depends on the tick rate. The constant + * portTICK_PERIOD_MS can be used to calculate real time from the tick + * rate - with the resolution of one tick period. + * + * INCLUDE_vTaskDelay must be defined as 1 for this function to be available. + * See the configuration section for more information. + * + * + * vTaskDelay() specifies a time at which the task wishes to unblock relative to + * the time at which vTaskDelay() is called. For example, specifying a block + * period of 100 ticks will cause the task to unblock 100 ticks after + * vTaskDelay() is called. vTaskDelay() does not therefore provide a good method + * of controlling the frequency of a periodic task as the path taken through the + * code, as well as other task and interrupt activity, will effect the frequency + * at which vTaskDelay() gets called and therefore the time at which the task + * next executes. See vTaskDelayUntil() for an alternative API function designed + * to facilitate fixed frequency execution. It does this by specifying an + * absolute time (rather than a relative time) at which the calling task should + * unblock. + * + * @param xTicksToDelay The amount of time, in tick periods, that + * the calling task should block. + * + * Example usage: + * + * void vTaskFunction( void * pvParameters ) + * { + * // Block for 500ms. + * const TickType_t xDelay = 500 / portTICK_PERIOD_MS; + * + * for( ;; ) + * { + * // Simply toggle the LED every 500ms, blocking between each toggle. + * vToggleLED(); + * vTaskDelay( xDelay ); + * } + * } + * + * \defgroup vTaskDelay vTaskDelay + * \ingroup TaskCtrl + */ +void vTaskDelay( const TickType_t xTicksToDelay ) PRIVILEGED_FUNCTION; + +/** + * task. h + *
+ * void vTaskDelayUntil( TickType_t *pxPreviousWakeTime, const TickType_t xTimeIncrement );
+ * 
+ * + * INCLUDE_vTaskDelayUntil must be defined as 1 for this function to be available. + * See the configuration section for more information. + * + * Delay a task until a specified time. This function can be used by periodic + * tasks to ensure a constant execution frequency. + * + * This function differs from vTaskDelay () in one important aspect: vTaskDelay () will + * cause a task to block for the specified number of ticks from the time vTaskDelay () is + * called. It is therefore difficult to use vTaskDelay () by itself to generate a fixed + * execution frequency as the time between a task starting to execute and that task + * calling vTaskDelay () may not be fixed [the task may take a different path though the + * code between calls, or may get interrupted or preempted a different number of times + * each time it executes]. + * + * Whereas vTaskDelay () specifies a wake time relative to the time at which the function + * is called, vTaskDelayUntil () specifies the absolute (exact) time at which it wishes to + * unblock. + * + * The constant portTICK_PERIOD_MS can be used to calculate real time from the tick + * rate - with the resolution of one tick period. + * + * @param pxPreviousWakeTime Pointer to a variable that holds the time at which the + * task was last unblocked. The variable must be initialised with the current time + * prior to its first use (see the example below). Following this the variable is + * automatically updated within vTaskDelayUntil (). + * + * @param xTimeIncrement The cycle time period. The task will be unblocked at + * time *pxPreviousWakeTime + xTimeIncrement. Calling vTaskDelayUntil with the + * same xTimeIncrement parameter value will cause the task to execute with + * a fixed interface period. + * + * Example usage: + *
+ * // Perform an action every 10 ticks.
+ * void vTaskFunction( void * pvParameters )
+ * {
+ * TickType_t xLastWakeTime;
+ * const TickType_t xFrequency = 10;
+ *
+ *   // Initialise the xLastWakeTime variable with the current time.
+ *   xLastWakeTime = xTaskGetTickCount ();
+ *   for( ;; )
+ *   {
+ *       // Wait for the next cycle.
+ *       vTaskDelayUntil( &xLastWakeTime, xFrequency );
+ *
+ *       // Perform action here.
+ *   }
+ * }
+ * 
+ * \defgroup vTaskDelayUntil vTaskDelayUntil + * \ingroup TaskCtrl + */ +void vTaskDelayUntil( TickType_t * const pxPreviousWakeTime, + const TickType_t xTimeIncrement ) PRIVILEGED_FUNCTION; + +/** + * task. h + *
+ * BaseType_t xTaskAbortDelay( TaskHandle_t xTask );
+ * 
+ * + * INCLUDE_xTaskAbortDelay must be defined as 1 in FreeRTOSConfig.h for this + * function to be available. + * + * A task will enter the Blocked state when it is waiting for an event. The + * event it is waiting for can be a temporal event (waiting for a time), such + * as when vTaskDelay() is called, or an event on an object, such as when + * xQueueReceive() or ulTaskNotifyTake() is called. If the handle of a task + * that is in the Blocked state is used in a call to xTaskAbortDelay() then the + * task will leave the Blocked state, and return from whichever function call + * placed the task into the Blocked state. + * + * There is no 'FromISR' version of this function as an interrupt would need to + * know which object a task was blocked on in order to know which actions to + * take. For example, if the task was blocked on a queue the interrupt handler + * would then need to know if the queue was locked. + * + * @param xTask The handle of the task to remove from the Blocked state. + * + * @return If the task referenced by xTask was not in the Blocked state then + * pdFAIL is returned. Otherwise pdPASS is returned. + * + * \defgroup xTaskAbortDelay xTaskAbortDelay + * \ingroup TaskCtrl + */ +BaseType_t xTaskAbortDelay( TaskHandle_t xTask ) PRIVILEGED_FUNCTION; + +/** + * task. h + *
+ * UBaseType_t uxTaskPriorityGet( const TaskHandle_t xTask );
+ * 
+ * + * INCLUDE_uxTaskPriorityGet must be defined as 1 for this function to be available. + * See the configuration section for more information. + * + * Obtain the priority of any task. + * + * @param xTask Handle of the task to be queried. Passing a NULL + * handle results in the priority of the calling task being returned. + * + * @return The priority of xTask. + * + * Example usage: + *
+ * void vAFunction( void )
+ * {
+ * TaskHandle_t xHandle;
+ *
+ *   // Create a task, storing the handle.
+ *   xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
+ *
+ *   // ...
+ *
+ *   // Use the handle to obtain the priority of the created task.
+ *   // It was created with tskIDLE_PRIORITY, but may have changed
+ *   // it itself.
+ *   if( uxTaskPriorityGet( xHandle ) != tskIDLE_PRIORITY )
+ *   {
+ *       // The task has changed it's priority.
+ *   }
+ *
+ *   // ...
+ *
+ *   // Is our priority higher than the created task?
+ *   if( uxTaskPriorityGet( xHandle ) < uxTaskPriorityGet( NULL ) )
+ *   {
+ *       // Our priority (obtained using NULL handle) is higher.
+ *   }
+ * }
+ * 
+ * \defgroup uxTaskPriorityGet uxTaskPriorityGet + * \ingroup TaskCtrl + */ +UBaseType_t uxTaskPriorityGet( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION; + +/** + * task. h + *
+ * UBaseType_t uxTaskPriorityGetFromISR( const TaskHandle_t xTask );
+ * 
+ * + * A version of uxTaskPriorityGet() that can be used from an ISR. + */ +UBaseType_t uxTaskPriorityGetFromISR( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION; + +/** + * task. h + *
+ * eTaskState eTaskGetState( TaskHandle_t xTask );
+ * 
+ * + * INCLUDE_eTaskGetState must be defined as 1 for this function to be available. + * See the configuration section for more information. + * + * Obtain the state of any task. States are encoded by the eTaskState + * enumerated type. + * + * @param xTask Handle of the task to be queried. + * + * @return The state of xTask at the time the function was called. Note the + * state of the task might change between the function being called, and the + * functions return value being tested by the calling task. + */ +eTaskState eTaskGetState( TaskHandle_t xTask ) PRIVILEGED_FUNCTION; + +/** + * task. h + *
+ * void vTaskGetInfo( TaskHandle_t xTask, TaskStatus_t *pxTaskStatus, BaseType_t xGetFreeStackSpace, eTaskState eState );
+ * 
+ * + * configUSE_TRACE_FACILITY must be defined as 1 for this function to be + * available. See the configuration section for more information. + * + * Populates a TaskStatus_t structure with information about a task. + * + * @param xTask Handle of the task being queried. If xTask is NULL then + * information will be returned about the calling task. + * + * @param pxTaskStatus A pointer to the TaskStatus_t structure that will be + * filled with information about the task referenced by the handle passed using + * the xTask parameter. + * + * @xGetFreeStackSpace The TaskStatus_t structure contains a member to report + * the stack high water mark of the task being queried. Calculating the stack + * high water mark takes a relatively long time, and can make the system + * temporarily unresponsive - so the xGetFreeStackSpace parameter is provided to + * allow the high water mark checking to be skipped. The high watermark value + * will only be written to the TaskStatus_t structure if xGetFreeStackSpace is + * not set to pdFALSE; + * + * @param eState The TaskStatus_t structure contains a member to report the + * state of the task being queried. Obtaining the task state is not as fast as + * a simple assignment - so the eState parameter is provided to allow the state + * information to be omitted from the TaskStatus_t structure. To obtain state + * information then set eState to eInvalid - otherwise the value passed in + * eState will be reported as the task state in the TaskStatus_t structure. + * + * Example usage: + *
+ * void vAFunction( void )
+ * {
+ * TaskHandle_t xHandle;
+ * TaskStatus_t xTaskDetails;
+ *
+ *  // Obtain the handle of a task from its name.
+ *  xHandle = xTaskGetHandle( "Task_Name" );
+ *
+ *  // Check the handle is not NULL.
+ *  configASSERT( xHandle );
+ *
+ *  // Use the handle to obtain further information about the task.
+ *  vTaskGetInfo( xHandle,
+ *                &xTaskDetails,
+ *                pdTRUE, // Include the high water mark in xTaskDetails.
+ *                eInvalid ); // Include the task state in xTaskDetails.
+ * }
+ * 
+ * \defgroup vTaskGetInfo vTaskGetInfo + * \ingroup TaskCtrl + */ +void vTaskGetInfo( TaskHandle_t xTask, + TaskStatus_t * pxTaskStatus, + BaseType_t xGetFreeStackSpace, + eTaskState eState ) PRIVILEGED_FUNCTION; + +/** + * task. h + *
+ * void vTaskPrioritySet( TaskHandle_t xTask, UBaseType_t uxNewPriority );
+ * 
+ * + * INCLUDE_vTaskPrioritySet must be defined as 1 for this function to be available. + * See the configuration section for more information. + * + * Set the priority of any task. + * + * A context switch will occur before the function returns if the priority + * being set is higher than the currently executing task. + * + * @param xTask Handle to the task for which the priority is being set. + * Passing a NULL handle results in the priority of the calling task being set. + * + * @param uxNewPriority The priority to which the task will be set. + * + * Example usage: + *
+ * void vAFunction( void )
+ * {
+ * TaskHandle_t xHandle;
+ *
+ *   // Create a task, storing the handle.
+ *   xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
+ *
+ *   // ...
+ *
+ *   // Use the handle to raise the priority of the created task.
+ *   vTaskPrioritySet( xHandle, tskIDLE_PRIORITY + 1 );
+ *
+ *   // ...
+ *
+ *   // Use a NULL handle to raise our priority to the same value.
+ *   vTaskPrioritySet( NULL, tskIDLE_PRIORITY + 1 );
+ * }
+ * 
+ * \defgroup vTaskPrioritySet vTaskPrioritySet + * \ingroup TaskCtrl + */ +void vTaskPrioritySet( TaskHandle_t xTask, + UBaseType_t uxNewPriority ) PRIVILEGED_FUNCTION; + +/** + * task. h + *
+ * void vTaskSuspend( TaskHandle_t xTaskToSuspend );
+ * 
+ * + * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available. + * See the configuration section for more information. + * + * Suspend any task. When suspended a task will never get any microcontroller + * processing time, no matter what its priority. + * + * Calls to vTaskSuspend are not accumulative - + * i.e. calling vTaskSuspend () twice on the same task still only requires one + * call to vTaskResume () to ready the suspended task. + * + * @param xTaskToSuspend Handle to the task being suspended. Passing a NULL + * handle will cause the calling task to be suspended. + * + * Example usage: + *
+ * void vAFunction( void )
+ * {
+ * TaskHandle_t xHandle;
+ *
+ *   // Create a task, storing the handle.
+ *   xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
+ *
+ *   // ...
+ *
+ *   // Use the handle to suspend the created task.
+ *   vTaskSuspend( xHandle );
+ *
+ *   // ...
+ *
+ *   // The created task will not run during this period, unless
+ *   // another task calls vTaskResume( xHandle ).
+ *
+ *   //...
+ *
+ *
+ *   // Suspend ourselves.
+ *   vTaskSuspend( NULL );
+ *
+ *   // We cannot get here unless another task calls vTaskResume
+ *   // with our handle as the parameter.
+ * }
+ * 
+ * \defgroup vTaskSuspend vTaskSuspend + * \ingroup TaskCtrl + */ +void vTaskSuspend( TaskHandle_t xTaskToSuspend ) PRIVILEGED_FUNCTION; + +/** + * task. h + *
+ * void vTaskResume( TaskHandle_t xTaskToResume );
+ * 
+ * + * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available. + * See the configuration section for more information. + * + * Resumes a suspended task. + * + * A task that has been suspended by one or more calls to vTaskSuspend () + * will be made available for running again by a single call to + * vTaskResume (). + * + * @param xTaskToResume Handle to the task being readied. + * + * Example usage: + *
+ * void vAFunction( void )
+ * {
+ * TaskHandle_t xHandle;
+ *
+ *   // Create a task, storing the handle.
+ *   xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
+ *
+ *   // ...
+ *
+ *   // Use the handle to suspend the created task.
+ *   vTaskSuspend( xHandle );
+ *
+ *   // ...
+ *
+ *   // The created task will not run during this period, unless
+ *   // another task calls vTaskResume( xHandle ).
+ *
+ *   //...
+ *
+ *
+ *   // Resume the suspended task ourselves.
+ *   vTaskResume( xHandle );
+ *
+ *   // The created task will once again get microcontroller processing
+ *   // time in accordance with its priority within the system.
+ * }
+ * 
+ * \defgroup vTaskResume vTaskResume + * \ingroup TaskCtrl + */ +void vTaskResume( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION; + +/** + * task. h + *
+ * void xTaskResumeFromISR( TaskHandle_t xTaskToResume );
+ * 
+ * + * INCLUDE_xTaskResumeFromISR must be defined as 1 for this function to be + * available. See the configuration section for more information. + * + * An implementation of vTaskResume() that can be called from within an ISR. + * + * A task that has been suspended by one or more calls to vTaskSuspend () + * will be made available for running again by a single call to + * xTaskResumeFromISR (). + * + * xTaskResumeFromISR() should not be used to synchronise a task with an + * interrupt if there is a chance that the interrupt could arrive prior to the + * task being suspended - as this can lead to interrupts being missed. Use of a + * semaphore as a synchronisation mechanism would avoid this eventuality. + * + * @param xTaskToResume Handle to the task being readied. + * + * @return pdTRUE if resuming the task should result in a context switch, + * otherwise pdFALSE. This is used by the ISR to determine if a context switch + * may be required following the ISR. + * + * \defgroup vTaskResumeFromISR vTaskResumeFromISR + * \ingroup TaskCtrl + */ +BaseType_t xTaskResumeFromISR( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION; + +/*----------------------------------------------------------- +* SCHEDULER CONTROL +*----------------------------------------------------------*/ + +/** + * task. h + *
+ * void vTaskStartScheduler( void );
+ * 
+ * + * Starts the real time kernel tick processing. After calling the kernel + * has control over which tasks are executed and when. + * + * See the demo application file main.c for an example of creating + * tasks and starting the kernel. + * + * Example usage: + *
+ * void vAFunction( void )
+ * {
+ *   // Create at least one task before starting the kernel.
+ *   xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
+ *
+ *   // Start the real time kernel with preemption.
+ *   vTaskStartScheduler ();
+ *
+ *   // Will not get here unless a task calls vTaskEndScheduler ()
+ * }
+ * 
+ * + * \defgroup vTaskStartScheduler vTaskStartScheduler + * \ingroup SchedulerControl + */ +void vTaskStartScheduler( void ) PRIVILEGED_FUNCTION; + +/** + * task. h + *
+ * void vTaskEndScheduler( void );
+ * 
+ * + * NOTE: At the time of writing only the x86 real mode port, which runs on a PC + * in place of DOS, implements this function. + * + * Stops the real time kernel tick. All created tasks will be automatically + * deleted and multitasking (either preemptive or cooperative) will + * stop. Execution then resumes from the point where vTaskStartScheduler () + * was called, as if vTaskStartScheduler () had just returned. + * + * See the demo application file main. c in the demo/PC directory for an + * example that uses vTaskEndScheduler (). + * + * vTaskEndScheduler () requires an exit function to be defined within the + * portable layer (see vPortEndScheduler () in port. c for the PC port). This + * performs hardware specific operations such as stopping the kernel tick. + * + * vTaskEndScheduler () will cause all of the resources allocated by the + * kernel to be freed - but will not free resources allocated by application + * tasks. + * + * Example usage: + *
+ * void vTaskCode( void * pvParameters )
+ * {
+ *   for( ;; )
+ *   {
+ *       // Task code goes here.
+ *
+ *       // At some point we want to end the real time kernel processing
+ *       // so call ...
+ *       vTaskEndScheduler ();
+ *   }
+ * }
+ *
+ * void vAFunction( void )
+ * {
+ *   // Create at least one task before starting the kernel.
+ *   xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
+ *
+ *   // Start the real time kernel with preemption.
+ *   vTaskStartScheduler ();
+ *
+ *   // Will only get here when the vTaskCode () task has called
+ *   // vTaskEndScheduler ().  When we get here we are back to single task
+ *   // execution.
+ * }
+ * 
+ * + * \defgroup vTaskEndScheduler vTaskEndScheduler + * \ingroup SchedulerControl + */ +void vTaskEndScheduler( void ) PRIVILEGED_FUNCTION; + +/** + * task. h + *
+ * void vTaskSuspendAll( void );
+ * 
+ * + * Suspends the scheduler without disabling interrupts. Context switches will + * not occur while the scheduler is suspended. + * + * After calling vTaskSuspendAll () the calling task will continue to execute + * without risk of being swapped out until a call to xTaskResumeAll () has been + * made. + * + * API functions that have the potential to cause a context switch (for example, + * vTaskDelayUntil(), xQueueSend(), etc.) must not be called while the scheduler + * is suspended. + * + * Example usage: + *
+ * void vTask1( void * pvParameters )
+ * {
+ *   for( ;; )
+ *   {
+ *       // Task code goes here.
+ *
+ *       // ...
+ *
+ *       // At some point the task wants to perform a long operation during
+ *       // which it does not want to get swapped out.  It cannot use
+ *       // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
+ *       // operation may cause interrupts to be missed - including the
+ *       // ticks.
+ *
+ *       // Prevent the real time kernel swapping out the task.
+ *       vTaskSuspendAll ();
+ *
+ *       // Perform the operation here.  There is no need to use critical
+ *       // sections as we have all the microcontroller processing time.
+ *       // During this time interrupts will still operate and the kernel
+ *       // tick count will be maintained.
+ *
+ *       // ...
+ *
+ *       // The operation is complete.  Restart the kernel.
+ *       xTaskResumeAll ();
+ *   }
+ * }
+ * 
+ * \defgroup vTaskSuspendAll vTaskSuspendAll + * \ingroup SchedulerControl + */ +void vTaskSuspendAll( void ) PRIVILEGED_FUNCTION; + +/** + * task. h + *
+ * BaseType_t xTaskResumeAll( void );
+ * 
+ * + * Resumes scheduler activity after it was suspended by a call to + * vTaskSuspendAll(). + * + * xTaskResumeAll() only resumes the scheduler. It does not unsuspend tasks + * that were previously suspended by a call to vTaskSuspend(). + * + * @return If resuming the scheduler caused a context switch then pdTRUE is + * returned, otherwise pdFALSE is returned. + * + * Example usage: + *
+ * void vTask1( void * pvParameters )
+ * {
+ *   for( ;; )
+ *   {
+ *       // Task code goes here.
+ *
+ *       // ...
+ *
+ *       // At some point the task wants to perform a long operation during
+ *       // which it does not want to get swapped out.  It cannot use
+ *       // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
+ *       // operation may cause interrupts to be missed - including the
+ *       // ticks.
+ *
+ *       // Prevent the real time kernel swapping out the task.
+ *       vTaskSuspendAll ();
+ *
+ *       // Perform the operation here.  There is no need to use critical
+ *       // sections as we have all the microcontroller processing time.
+ *       // During this time interrupts will still operate and the real
+ *       // time kernel tick count will be maintained.
+ *
+ *       // ...
+ *
+ *       // The operation is complete.  Restart the kernel.  We want to force
+ *       // a context switch - but there is no point if resuming the scheduler
+ *       // caused a context switch already.
+ *       if( !xTaskResumeAll () )
+ *       {
+ *            taskYIELD ();
+ *       }
+ *   }
+ * }
+ * 
+ * \defgroup xTaskResumeAll xTaskResumeAll + * \ingroup SchedulerControl + */ +BaseType_t xTaskResumeAll( void ) PRIVILEGED_FUNCTION; + +/*----------------------------------------------------------- +* TASK UTILITIES +*----------------------------------------------------------*/ + +/** + * task. h + *
TickType_t xTaskGetTickCount( void );
+ * + * @return The count of ticks since vTaskStartScheduler was called. + * + * \defgroup xTaskGetTickCount xTaskGetTickCount + * \ingroup TaskUtils + */ +TickType_t xTaskGetTickCount( void ) PRIVILEGED_FUNCTION; + +/** + * task. h + *
TickType_t xTaskGetTickCountFromISR( void );
+ * + * @return The count of ticks since vTaskStartScheduler was called. + * + * This is a version of xTaskGetTickCount() that is safe to be called from an + * ISR - provided that TickType_t is the natural word size of the + * microcontroller being used or interrupt nesting is either not supported or + * not being used. + * + * \defgroup xTaskGetTickCountFromISR xTaskGetTickCountFromISR + * \ingroup TaskUtils + */ +TickType_t xTaskGetTickCountFromISR( void ) PRIVILEGED_FUNCTION; + +/** + * task. h + *
uint16_t uxTaskGetNumberOfTasks( void );
+ * + * @return The number of tasks that the real time kernel is currently managing. + * This includes all ready, blocked and suspended tasks. A task that + * has been deleted but not yet freed by the idle task will also be + * included in the count. + * + * \defgroup uxTaskGetNumberOfTasks uxTaskGetNumberOfTasks + * \ingroup TaskUtils + */ +UBaseType_t uxTaskGetNumberOfTasks( void ) PRIVILEGED_FUNCTION; + +/** + * task. h + *
char *pcTaskGetName( TaskHandle_t xTaskToQuery );
+ * + * @return The text (human readable) name of the task referenced by the handle + * xTaskToQuery. A task can query its own name by either passing in its own + * handle, or by setting xTaskToQuery to NULL. + * + * \defgroup pcTaskGetName pcTaskGetName + * \ingroup TaskUtils + */ +char * pcTaskGetName( TaskHandle_t xTaskToQuery ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + +/** + * task. h + *
TaskHandle_t xTaskGetHandle( const char *pcNameToQuery );
+ * + * NOTE: This function takes a relatively long time to complete and should be + * used sparingly. + * + * @return The handle of the task that has the human readable name pcNameToQuery. + * NULL is returned if no matching name is found. INCLUDE_xTaskGetHandle + * must be set to 1 in FreeRTOSConfig.h for pcTaskGetHandle() to be available. + * + * \defgroup pcTaskGetHandle pcTaskGetHandle + * \ingroup TaskUtils + */ +TaskHandle_t xTaskGetHandle( const char * pcNameToQuery ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + +/** + * task.h + *
UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask );
+ * + * INCLUDE_uxTaskGetStackHighWaterMark must be set to 1 in FreeRTOSConfig.h for + * this function to be available. + * + * Returns the high water mark of the stack associated with xTask. That is, + * the minimum free stack space there has been (in words, so on a 32 bit machine + * a value of 1 means 4 bytes) since the task started. The smaller the returned + * number the closer the task has come to overflowing its stack. + * + * uxTaskGetStackHighWaterMark() and uxTaskGetStackHighWaterMark2() are the + * same except for their return type. Using configSTACK_DEPTH_TYPE allows the + * user to determine the return type. It gets around the problem of the value + * overflowing on 8-bit types without breaking backward compatibility for + * applications that expect an 8-bit return type. + * + * @param xTask Handle of the task associated with the stack to be checked. + * Set xTask to NULL to check the stack of the calling task. + * + * @return The smallest amount of free stack space there has been (in words, so + * actual spaces on the stack rather than bytes) since the task referenced by + * xTask was created. + */ +UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask ) PRIVILEGED_FUNCTION; + +/** + * task.h + *
configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask );
+ * + * INCLUDE_uxTaskGetStackHighWaterMark2 must be set to 1 in FreeRTOSConfig.h for + * this function to be available. + * + * Returns the high water mark of the stack associated with xTask. That is, + * the minimum free stack space there has been (in words, so on a 32 bit machine + * a value of 1 means 4 bytes) since the task started. The smaller the returned + * number the closer the task has come to overflowing its stack. + * + * uxTaskGetStackHighWaterMark() and uxTaskGetStackHighWaterMark2() are the + * same except for their return type. Using configSTACK_DEPTH_TYPE allows the + * user to determine the return type. It gets around the problem of the value + * overflowing on 8-bit types without breaking backward compatibility for + * applications that expect an 8-bit return type. + * + * @param xTask Handle of the task associated with the stack to be checked. + * Set xTask to NULL to check the stack of the calling task. + * + * @return The smallest amount of free stack space there has been (in words, so + * actual spaces on the stack rather than bytes) since the task referenced by + * xTask was created. + */ +configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask ) PRIVILEGED_FUNCTION; + +/* When using trace macros it is sometimes necessary to include task.h before + * FreeRTOS.h. When this is done TaskHookFunction_t will not yet have been defined, + * so the following two prototypes will cause a compilation error. This can be + * fixed by simply guarding against the inclusion of these two prototypes unless + * they are explicitly required by the configUSE_APPLICATION_TASK_TAG configuration + * constant. */ +#ifdef configUSE_APPLICATION_TASK_TAG + #if configUSE_APPLICATION_TASK_TAG == 1 + +/** + * task.h + *
+ * void vTaskSetApplicationTaskTag( TaskHandle_t xTask, TaskHookFunction_t pxHookFunction );
+ * 
+ * + * Sets pxHookFunction to be the task hook function used by the task xTask. + * Passing xTask as NULL has the effect of setting the calling tasks hook + * function. + */ + void vTaskSetApplicationTaskTag( TaskHandle_t xTask, + TaskHookFunction_t pxHookFunction ) PRIVILEGED_FUNCTION; + +/** + * task.h + *
+ * void xTaskGetApplicationTaskTag( TaskHandle_t xTask );
+ * 
+ * + * Returns the pxHookFunction value assigned to the task xTask. Do not + * call from an interrupt service routine - call + * xTaskGetApplicationTaskTagFromISR() instead. + */ + TaskHookFunction_t xTaskGetApplicationTaskTag( TaskHandle_t xTask ) PRIVILEGED_FUNCTION; + +/** + * task.h + *
+ * void xTaskGetApplicationTaskTagFromISR( TaskHandle_t xTask );
+ * 
+ * + * Returns the pxHookFunction value assigned to the task xTask. Can + * be called from an interrupt service routine. + */ + TaskHookFunction_t xTaskGetApplicationTaskTagFromISR( TaskHandle_t xTask ) PRIVILEGED_FUNCTION; + #endif /* configUSE_APPLICATION_TASK_TAG ==1 */ +#endif /* ifdef configUSE_APPLICATION_TASK_TAG */ + +#if ( configNUM_THREAD_LOCAL_STORAGE_POINTERS > 0 ) + +/* Each task contains an array of pointers that is dimensioned by the + * configNUM_THREAD_LOCAL_STORAGE_POINTERS setting in FreeRTOSConfig.h. The + * kernel does not use the pointers itself, so the application writer can use + * the pointers for any purpose they wish. The following two functions are + * used to set and query a pointer respectively. */ + void vTaskSetThreadLocalStoragePointer( TaskHandle_t xTaskToSet, + BaseType_t xIndex, + void * pvValue ) PRIVILEGED_FUNCTION; + void * pvTaskGetThreadLocalStoragePointer( TaskHandle_t xTaskToQuery, + BaseType_t xIndex ) PRIVILEGED_FUNCTION; + +#endif + +#if ( configCHECK_FOR_STACK_OVERFLOW > 0 ) + + /** + * task.h + *
void vApplicationStackOverflowHook( TaskHandle_t xTask char *pcTaskName); 
+ * + * The application stack overflow hook is called when a stack overflow is detected for a task. + * + * Details on stack overflow detection can be found here: https://www.FreeRTOS.org/Stacks-and-stack-overflow-checking.html + * + * @param xTask the task that just exceeded its stack boundaries. + * @param pcTaskName A character string containing the name of the offending task. + */ + void vApplicationStackOverflowHook( TaskHandle_t xTask, + char * pcTaskName ); + +#endif + +#if ( configUSE_TICK_HOOK > 0 ) + /** + * task.h + *
void vApplicationTickHook( void ); 
+ * + * This hook function is called in the system tick handler after any OS work is completed. + */ + void vApplicationTickHook( void ); /*lint !e526 Symbol not defined as it is an application callback. */ + +#endif + +#if ( configSUPPORT_STATIC_ALLOCATION == 1 ) + /** + * task.h + *
void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer, StackType_t ** ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize ) 
+ * + * This function is used to provide a statically allocated block of memory to FreeRTOS to hold the Idle Task TCB. This function is required when + * configSUPPORT_STATIC_ALLOCATION is set. For more information see this URI: https://www.FreeRTOS.org/a00110.html#configSUPPORT_STATIC_ALLOCATION + * + * @param ppxIdleTaskTCBBuffer A handle to a statically allocated TCB buffer + * @param ppxIdleTaskStackBuffer A handle to a statically allocated Stack buffer for thie idle task + * @param pulIdleTaskStackSize A pointer to the number of elements that will fit in the allocated stack buffer + */ + void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer, + StackType_t ** ppxIdleTaskStackBuffer, + uint32_t * pulIdleTaskStackSize ); /*lint !e526 Symbol not defined as it is an application callback. */ +#endif + +/** + * task.h + *
+ * BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask, void *pvParameter );
+ * 
+ * + * Calls the hook function associated with xTask. Passing xTask as NULL has + * the effect of calling the Running tasks (the calling task) hook function. + * + * pvParameter is passed to the hook function for the task to interpret as it + * wants. The return value is the value returned by the task hook function + * registered by the user. + */ +BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask, + void * pvParameter ) PRIVILEGED_FUNCTION; + +/** + * xTaskGetIdleTaskHandle() is only available if + * INCLUDE_xTaskGetIdleTaskHandle is set to 1 in FreeRTOSConfig.h. + * + * Simply returns the handle of the idle task. It is not valid to call + * xTaskGetIdleTaskHandle() before the scheduler has been started. + */ +TaskHandle_t xTaskGetIdleTaskHandle( void ) PRIVILEGED_FUNCTION; + +/** + * configUSE_TRACE_FACILITY must be defined as 1 in FreeRTOSConfig.h for + * uxTaskGetSystemState() to be available. + * + * uxTaskGetSystemState() populates an TaskStatus_t structure for each task in + * the system. TaskStatus_t structures contain, among other things, members + * for the task handle, task name, task priority, task state, and total amount + * of run time consumed by the task. See the TaskStatus_t structure + * definition in this file for the full member list. + * + * NOTE: This function is intended for debugging use only as its use results in + * the scheduler remaining suspended for an extended period. + * + * @param pxTaskStatusArray A pointer to an array of TaskStatus_t structures. + * The array must contain at least one TaskStatus_t structure for each task + * that is under the control of the RTOS. The number of tasks under the control + * of the RTOS can be determined using the uxTaskGetNumberOfTasks() API function. + * + * @param uxArraySize The size of the array pointed to by the pxTaskStatusArray + * parameter. The size is specified as the number of indexes in the array, or + * the number of TaskStatus_t structures contained in the array, not by the + * number of bytes in the array. + * + * @param pulTotalRunTime If configGENERATE_RUN_TIME_STATS is set to 1 in + * FreeRTOSConfig.h then *pulTotalRunTime is set by uxTaskGetSystemState() to the + * total run time (as defined by the run time stats clock, see + * https://www.FreeRTOS.org/rtos-run-time-stats.html) since the target booted. + * pulTotalRunTime can be set to NULL to omit the total run time information. + * + * @return The number of TaskStatus_t structures that were populated by + * uxTaskGetSystemState(). This should equal the number returned by the + * uxTaskGetNumberOfTasks() API function, but will be zero if the value passed + * in the uxArraySize parameter was too small. + * + * Example usage: + *
+ *  // This example demonstrates how a human readable table of run time stats
+ *  // information is generated from raw data provided by uxTaskGetSystemState().
+ *  // The human readable table is written to pcWriteBuffer
+ *  void vTaskGetRunTimeStats( char *pcWriteBuffer )
+ *  {
+ *  TaskStatus_t *pxTaskStatusArray;
+ *  volatile UBaseType_t uxArraySize, x;
+ *  uint32_t ulTotalRunTime, ulStatsAsPercentage;
+ *
+ *      // Make sure the write buffer does not contain a string.
+ * pcWriteBuffer = 0x00;
+ *
+ *      // Take a snapshot of the number of tasks in case it changes while this
+ *      // function is executing.
+ *      uxArraySize = uxTaskGetNumberOfTasks();
+ *
+ *      // Allocate a TaskStatus_t structure for each task.  An array could be
+ *      // allocated statically at compile time.
+ *      pxTaskStatusArray = pvPortMalloc( uxArraySize * sizeof( TaskStatus_t ) );
+ *
+ *      if( pxTaskStatusArray != NULL )
+ *      {
+ *          // Generate raw status information about each task.
+ *          uxArraySize = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, &ulTotalRunTime );
+ *
+ *          // For percentage calculations.
+ *          ulTotalRunTime /= 100UL;
+ *
+ *          // Avoid divide by zero errors.
+ *          if( ulTotalRunTime > 0 )
+ *          {
+ *              // For each populated position in the pxTaskStatusArray array,
+ *              // format the raw data as human readable ASCII data
+ *              for( x = 0; x < uxArraySize; x++ )
+ *              {
+ *                  // What percentage of the total run time has the task used?
+ *                  // This will always be rounded down to the nearest integer.
+ *                  // ulTotalRunTimeDiv100 has already been divided by 100.
+ *                  ulStatsAsPercentage = pxTaskStatusArray[ x ].ulRunTimeCounter / ulTotalRunTime;
+ *
+ *                  if( ulStatsAsPercentage > 0UL )
+ *                  {
+ *                      sprintf( pcWriteBuffer, "%s\t\t%lu\t\t%lu%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter, ulStatsAsPercentage );
+ *                  }
+ *                  else
+ *                  {
+ *                      // If the percentage is zero here then the task has
+ *                      // consumed less than 1% of the total run time.
+ *                      sprintf( pcWriteBuffer, "%s\t\t%lu\t\t<1%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter );
+ *                  }
+ *
+ *                  pcWriteBuffer += strlen( ( char * ) pcWriteBuffer );
+ *              }
+ *          }
+ *
+ *          // The array is no longer needed, free the memory it consumes.
+ *          vPortFree( pxTaskStatusArray );
+ *      }
+ *  }
+ *  
+ */ +UBaseType_t uxTaskGetSystemState( TaskStatus_t * const pxTaskStatusArray, + const UBaseType_t uxArraySize, + uint32_t * const pulTotalRunTime ) PRIVILEGED_FUNCTION; + +/** + * task. h + *
void vTaskList( char *pcWriteBuffer );
+ * + * configUSE_TRACE_FACILITY and configUSE_STATS_FORMATTING_FUNCTIONS must + * both be defined as 1 for this function to be available. See the + * configuration section of the FreeRTOS.org website for more information. + * + * NOTE 1: This function will disable interrupts for its duration. It is + * not intended for normal application runtime use but as a debug aid. + * + * Lists all the current tasks, along with their current state and stack + * usage high water mark. + * + * Tasks are reported as blocked ('B'), ready ('R'), deleted ('D') or + * suspended ('S'). + * + * PLEASE NOTE: + * + * This function is provided for convenience only, and is used by many of the + * demo applications. Do not consider it to be part of the scheduler. + * + * vTaskList() calls uxTaskGetSystemState(), then formats part of the + * uxTaskGetSystemState() output into a human readable table that displays task + * names, states and stack usage. + * + * vTaskList() has a dependency on the sprintf() C library function that might + * bloat the code size, use a lot of stack, and provide different results on + * different platforms. An alternative, tiny, third party, and limited + * functionality implementation of sprintf() is provided in many of the + * FreeRTOS/Demo sub-directories in a file called printf-stdarg.c (note + * printf-stdarg.c does not provide a full snprintf() implementation!). + * + * It is recommended that production systems call uxTaskGetSystemState() + * directly to get access to raw stats data, rather than indirectly through a + * call to vTaskList(). + * + * @param pcWriteBuffer A buffer into which the above mentioned details + * will be written, in ASCII form. This buffer is assumed to be large + * enough to contain the generated report. Approximately 40 bytes per + * task should be sufficient. + * + * \defgroup vTaskList vTaskList + * \ingroup TaskUtils + */ +void vTaskList( char * pcWriteBuffer ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + +/** + * task. h + *
void vTaskGetRunTimeStats( char *pcWriteBuffer );
+ * + * configGENERATE_RUN_TIME_STATS and configUSE_STATS_FORMATTING_FUNCTIONS + * must both be defined as 1 for this function to be available. The application + * must also then provide definitions for + * portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and portGET_RUN_TIME_COUNTER_VALUE() + * to configure a peripheral timer/counter and return the timers current count + * value respectively. The counter should be at least 10 times the frequency of + * the tick count. + * + * NOTE 1: This function will disable interrupts for its duration. It is + * not intended for normal application runtime use but as a debug aid. + * + * Setting configGENERATE_RUN_TIME_STATS to 1 will result in a total + * accumulated execution time being stored for each task. The resolution + * of the accumulated time value depends on the frequency of the timer + * configured by the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() macro. + * Calling vTaskGetRunTimeStats() writes the total execution time of each + * task into a buffer, both as an absolute count value and as a percentage + * of the total system execution time. + * + * NOTE 2: + * + * This function is provided for convenience only, and is used by many of the + * demo applications. Do not consider it to be part of the scheduler. + * + * vTaskGetRunTimeStats() calls uxTaskGetSystemState(), then formats part of the + * uxTaskGetSystemState() output into a human readable table that displays the + * amount of time each task has spent in the Running state in both absolute and + * percentage terms. + * + * vTaskGetRunTimeStats() has a dependency on the sprintf() C library function + * that might bloat the code size, use a lot of stack, and provide different + * results on different platforms. An alternative, tiny, third party, and + * limited functionality implementation of sprintf() is provided in many of the + * FreeRTOS/Demo sub-directories in a file called printf-stdarg.c (note + * printf-stdarg.c does not provide a full snprintf() implementation!). + * + * It is recommended that production systems call uxTaskGetSystemState() directly + * to get access to raw stats data, rather than indirectly through a call to + * vTaskGetRunTimeStats(). + * + * @param pcWriteBuffer A buffer into which the execution times will be + * written, in ASCII form. This buffer is assumed to be large enough to + * contain the generated report. Approximately 40 bytes per task should + * be sufficient. + * + * \defgroup vTaskGetRunTimeStats vTaskGetRunTimeStats + * \ingroup TaskUtils + */ +void vTaskGetRunTimeStats( char * pcWriteBuffer ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + +/** + * task. h + *
uint32_t ulTaskGetIdleRunTimeCounter( void );
+ * + * configGENERATE_RUN_TIME_STATS and configUSE_STATS_FORMATTING_FUNCTIONS + * must both be defined as 1 for this function to be available. The application + * must also then provide definitions for + * portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and portGET_RUN_TIME_COUNTER_VALUE() + * to configure a peripheral timer/counter and return the timers current count + * value respectively. The counter should be at least 10 times the frequency of + * the tick count. + * + * Setting configGENERATE_RUN_TIME_STATS to 1 will result in a total + * accumulated execution time being stored for each task. The resolution + * of the accumulated time value depends on the frequency of the timer + * configured by the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() macro. + * While uxTaskGetSystemState() and vTaskGetRunTimeStats() writes the total + * execution time of each task into a buffer, ulTaskGetIdleRunTimeCounter() + * returns the total execution time of just the idle task. + * + * @return The total run time of the idle task. This is the amount of time the + * idle task has actually been executing. The unit of time is dependent on the + * frequency configured using the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and + * portGET_RUN_TIME_COUNTER_VALUE() macros. + * + * \defgroup ulTaskGetIdleRunTimeCounter ulTaskGetIdleRunTimeCounter + * \ingroup TaskUtils + */ +uint32_t ulTaskGetIdleRunTimeCounter( void ) PRIVILEGED_FUNCTION; + +/** + * task. h + *
BaseType_t xTaskNotifyIndexed( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction );
+ *
BaseType_t xTaskNotify( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction );
+ * + * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details. + * + * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these + * functions to be available. + * + * Sends a direct to task notification to a task, with an optional value and + * action. + * + * Each task has a private array of "notification values" (or 'notifications'), + * each of which is a 32-bit unsigned integer (uint32_t). The constant + * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the + * array, and (for backward compatibility) defaults to 1 if left undefined. + * Prior to FreeRTOS V10.4.0 there was only one notification value per task. + * + * Events can be sent to a task using an intermediary object. Examples of such + * objects are queues, semaphores, mutexes and event groups. Task notifications + * are a method of sending an event directly to a task without the need for such + * an intermediary object. + * + * A notification sent to a task can optionally perform an action, such as + * update, overwrite or increment one of the task's notification values. In + * that way task notifications can be used to send data to a task, or be used as + * light weight and fast binary or counting semaphores. + * + * A task can use xTaskNotifyWaitIndexed() to [optionally] block to wait for a + * notification to be pending, or ulTaskNotifyTakeIndexed() to [optionally] block + * to wait for a notification value to have a non-zero value. The task does + * not consume any CPU time while it is in the Blocked state. + * + * A notification sent to a task will remain pending until it is cleared by the + * task calling xTaskNotifyWaitIndexed() or ulTaskNotifyTakeIndexed() (or their + * un-indexed equivalents). If the task was already in the Blocked state to + * wait for a notification when the notification arrives then the task will + * automatically be removed from the Blocked state (unblocked) and the + * notification cleared. + * + * **NOTE** Each notification within the array operates independently - a task + * can only block on one notification within the array at a time and will not be + * unblocked by a notification sent to any other array index. + * + * Backward compatibility information: + * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and + * all task notification API functions operated on that value. Replacing the + * single notification value with an array of notification values necessitated a + * new set of API functions that could address specific notifications within the + * array. xTaskNotify() is the original API function, and remains backward + * compatible by always operating on the notification value at index 0 in the + * array. Calling xTaskNotify() is equivalent to calling xTaskNotifyIndexed() + * with the uxIndexToNotify parameter set to 0. + * + * @param xTaskToNotify The handle of the task being notified. The handle to a + * task can be returned from the xTaskCreate() API function used to create the + * task, and the handle of the currently running task can be obtained by calling + * xTaskGetCurrentTaskHandle(). + * + * @param uxIndexToNotify The index within the target task's array of + * notification values to which the notification is to be sent. uxIndexToNotify + * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES. xTaskNotify() does + * not have this parameter and always sends notifications to index 0. + * + * @param ulValue Data that can be sent with the notification. How the data is + * used depends on the value of the eAction parameter. + * + * @param eAction Specifies how the notification updates the task's notification + * value, if at all. Valid values for eAction are as follows: + * + * eSetBits - + * The target notification value is bitwise ORed with ulValue. + * xTaskNofifyIndexed() always returns pdPASS in this case. + * + * eIncrement - + * The target notification value is incremented. ulValue is not used and + * xTaskNotifyIndexed() always returns pdPASS in this case. + * + * eSetValueWithOverwrite - + * The target notification value is set to the value of ulValue, even if the + * task being notified had not yet processed the previous notification at the + * same array index (the task already had a notification pending at that index). + * xTaskNotifyIndexed() always returns pdPASS in this case. + * + * eSetValueWithoutOverwrite - + * If the task being notified did not already have a notification pending at the + * same array index then the target notification value is set to ulValue and + * xTaskNotifyIndexed() will return pdPASS. If the task being notified already + * had a notification pending at the same array index then no action is + * performed and pdFAIL is returned. + * + * eNoAction - + * The task receives a notification at the specified array index without the + * notification value at that index being updated. ulValue is not used and + * xTaskNotifyIndexed() always returns pdPASS in this case. + * + * pulPreviousNotificationValue - + * Can be used to pass out the subject task's notification value before any + * bits are modified by the notify function. + * + * @return Dependent on the value of eAction. See the description of the + * eAction parameter. + * + * \defgroup xTaskNotifyIndexed xTaskNotifyIndexed + * \ingroup TaskNotifications + */ +BaseType_t xTaskGenericNotify( TaskHandle_t xTaskToNotify, + UBaseType_t uxIndexToNotify, + uint32_t ulValue, + eNotifyAction eAction, + uint32_t * pulPreviousNotificationValue ) PRIVILEGED_FUNCTION; +#define xTaskNotify( xTaskToNotify, ulValue, eAction ) \ + xTaskGenericNotify( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulValue ), ( eAction ), NULL ) +#define xTaskNotifyIndexed( xTaskToNotify, uxIndexToNotify, ulValue, eAction ) \ + xTaskGenericNotify( ( xTaskToNotify ), ( uxIndexToNotify ), ( ulValue ), ( eAction ), NULL ) + +/** + * task. h + *
BaseType_t xTaskNotifyAndQueryIndexed( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotifyValue );
+ *
BaseType_t xTaskNotifyAndQuery( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotifyValue );
+ * + * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details. + * + * xTaskNotifyAndQueryIndexed() performs the same operation as + * xTaskNotifyIndexed() with the addition that it also returns the subject + * task's prior notification value (the notification value at the time the + * function is called rather than when the function returns) in the additional + * pulPreviousNotifyValue parameter. + * + * xTaskNotifyAndQuery() performs the same operation as xTaskNotify() with the + * addition that it also returns the subject task's prior notification value + * (the notification value as it was at the time the function is called, rather + * than when the function returns) in the additional pulPreviousNotifyValue + * parameter. + * + * \defgroup xTaskNotifyAndQueryIndexed xTaskNotifyAndQueryIndexed + * \ingroup TaskNotifications + */ +#define xTaskNotifyAndQuery( xTaskToNotify, ulValue, eAction, pulPreviousNotifyValue ) \ + xTaskGenericNotify( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulValue ), ( eAction ), ( pulPreviousNotifyValue ) ) +#define xTaskNotifyAndQueryIndexed( xTaskToNotify, uxIndexToNotify, ulValue, eAction, pulPreviousNotifyValue ) \ + xTaskGenericNotify( ( xTaskToNotify ), ( uxIndexToNotify ), ( ulValue ), ( eAction ), ( pulPreviousNotifyValue ) ) + +/** + * task. h + *
BaseType_t xTaskNotifyIndexedFromISR( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, BaseType_t *pxHigherPriorityTaskWoken );
+ *
BaseType_t xTaskNotifyFromISR( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, BaseType_t *pxHigherPriorityTaskWoken );
+ * + * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details. + * + * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these + * functions to be available. + * + * A version of xTaskNotifyIndexed() that can be used from an interrupt service + * routine (ISR). + * + * Each task has a private array of "notification values" (or 'notifications'), + * each of which is a 32-bit unsigned integer (uint32_t). The constant + * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the + * array, and (for backward compatibility) defaults to 1 if left undefined. + * Prior to FreeRTOS V10.4.0 there was only one notification value per task. + * + * Events can be sent to a task using an intermediary object. Examples of such + * objects are queues, semaphores, mutexes and event groups. Task notifications + * are a method of sending an event directly to a task without the need for such + * an intermediary object. + * + * A notification sent to a task can optionally perform an action, such as + * update, overwrite or increment one of the task's notification values. In + * that way task notifications can be used to send data to a task, or be used as + * light weight and fast binary or counting semaphores. + * + * A task can use xTaskNotifyWaitIndexed() to [optionally] block to wait for a + * notification to be pending, or ulTaskNotifyTakeIndexed() to [optionally] block + * to wait for a notification value to have a non-zero value. The task does + * not consume any CPU time while it is in the Blocked state. + * + * A notification sent to a task will remain pending until it is cleared by the + * task calling xTaskNotifyWaitIndexed() or ulTaskNotifyTakeIndexed() (or their + * un-indexed equivalents). If the task was already in the Blocked state to + * wait for a notification when the notification arrives then the task will + * automatically be removed from the Blocked state (unblocked) and the + * notification cleared. + * + * **NOTE** Each notification within the array operates independently - a task + * can only block on one notification within the array at a time and will not be + * unblocked by a notification sent to any other array index. + * + * Backward compatibility information: + * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and + * all task notification API functions operated on that value. Replacing the + * single notification value with an array of notification values necessitated a + * new set of API functions that could address specific notifications within the + * array. xTaskNotifyFromISR() is the original API function, and remains + * backward compatible by always operating on the notification value at index 0 + * within the array. Calling xTaskNotifyFromISR() is equivalent to calling + * xTaskNotifyIndexedFromISR() with the uxIndexToNotify parameter set to 0. + * + * @param uxIndexToNotify The index within the target task's array of + * notification values to which the notification is to be sent. uxIndexToNotify + * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES. xTaskNotifyFromISR() + * does not have this parameter and always sends notifications to index 0. + * + * @param xTaskToNotify The handle of the task being notified. The handle to a + * task can be returned from the xTaskCreate() API function used to create the + * task, and the handle of the currently running task can be obtained by calling + * xTaskGetCurrentTaskHandle(). + * + * @param ulValue Data that can be sent with the notification. How the data is + * used depends on the value of the eAction parameter. + * + * @param eAction Specifies how the notification updates the task's notification + * value, if at all. Valid values for eAction are as follows: + * + * eSetBits - + * The task's notification value is bitwise ORed with ulValue. xTaskNofify() + * always returns pdPASS in this case. + * + * eIncrement - + * The task's notification value is incremented. ulValue is not used and + * xTaskNotify() always returns pdPASS in this case. + * + * eSetValueWithOverwrite - + * The task's notification value is set to the value of ulValue, even if the + * task being notified had not yet processed the previous notification (the + * task already had a notification pending). xTaskNotify() always returns + * pdPASS in this case. + * + * eSetValueWithoutOverwrite - + * If the task being notified did not already have a notification pending then + * the task's notification value is set to ulValue and xTaskNotify() will + * return pdPASS. If the task being notified already had a notification + * pending then no action is performed and pdFAIL is returned. + * + * eNoAction - + * The task receives a notification without its notification value being + * updated. ulValue is not used and xTaskNotify() always returns pdPASS in + * this case. + * + * @param pxHigherPriorityTaskWoken xTaskNotifyFromISR() will set + * *pxHigherPriorityTaskWoken to pdTRUE if sending the notification caused the + * task to which the notification was sent to leave the Blocked state, and the + * unblocked task has a priority higher than the currently running task. If + * xTaskNotifyFromISR() sets this value to pdTRUE then a context switch should + * be requested before the interrupt is exited. How a context switch is + * requested from an ISR is dependent on the port - see the documentation page + * for the port in use. + * + * @return Dependent on the value of eAction. See the description of the + * eAction parameter. + * + * \defgroup xTaskNotifyIndexedFromISR xTaskNotifyIndexedFromISR + * \ingroup TaskNotifications + */ +BaseType_t xTaskGenericNotifyFromISR( TaskHandle_t xTaskToNotify, + UBaseType_t uxIndexToNotify, + uint32_t ulValue, + eNotifyAction eAction, + uint32_t * pulPreviousNotificationValue, + BaseType_t * pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION; +#define xTaskNotifyFromISR( xTaskToNotify, ulValue, eAction, pxHigherPriorityTaskWoken ) \ + xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulValue ), ( eAction ), NULL, ( pxHigherPriorityTaskWoken ) ) +#define xTaskNotifyIndexedFromISR( xTaskToNotify, uxIndexToNotify, ulValue, eAction, pxHigherPriorityTaskWoken ) \ + xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( uxIndexToNotify ), ( ulValue ), ( eAction ), NULL, ( pxHigherPriorityTaskWoken ) ) + +/** + * task. h + *
BaseType_t xTaskNotifyAndQueryIndexedFromISR( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue, BaseType_t *pxHigherPriorityTaskWoken );
+ *
BaseType_t xTaskNotifyAndQueryFromISR( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue, BaseType_t *pxHigherPriorityTaskWoken );
+ * + * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details. + * + * xTaskNotifyAndQueryIndexedFromISR() performs the same operation as + * xTaskNotifyIndexedFromISR() with the addition that it also returns the + * subject task's prior notification value (the notification value at the time + * the function is called rather than at the time the function returns) in the + * additional pulPreviousNotifyValue parameter. + * + * xTaskNotifyAndQueryFromISR() performs the same operation as + * xTaskNotifyFromISR() with the addition that it also returns the subject + * task's prior notification value (the notification value at the time the + * function is called rather than at the time the function returns) in the + * additional pulPreviousNotifyValue parameter. + * + * \defgroup xTaskNotifyAndQueryIndexedFromISR xTaskNotifyAndQueryIndexedFromISR + * \ingroup TaskNotifications + */ +#define xTaskNotifyAndQueryIndexedFromISR( xTaskToNotify, uxIndexToNotify, ulValue, eAction, pulPreviousNotificationValue, pxHigherPriorityTaskWoken ) \ + xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( uxIndexToNotify ), ( ulValue ), ( eAction ), ( pulPreviousNotificationValue ), ( pxHigherPriorityTaskWoken ) ) +#define xTaskNotifyAndQueryFromISR( xTaskToNotify, ulValue, eAction, pulPreviousNotificationValue, pxHigherPriorityTaskWoken ) \ + xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulValue ), ( eAction ), ( pulPreviousNotificationValue ), ( pxHigherPriorityTaskWoken ) ) + +/** + * task. h + *
+ * BaseType_t xTaskNotifyWaitIndexed( UBaseType_t uxIndexToWaitOn, uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait );
+ *
+ * BaseType_t xTaskNotifyWait( uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait );
+ * 
+ * + * Waits for a direct to task notification to be pending at a given index within + * an array of direct to task notifications. + * + * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details. + * + * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this + * function to be available. + * + * Each task has a private array of "notification values" (or 'notifications'), + * each of which is a 32-bit unsigned integer (uint32_t). The constant + * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the + * array, and (for backward compatibility) defaults to 1 if left undefined. + * Prior to FreeRTOS V10.4.0 there was only one notification value per task. + * + * Events can be sent to a task using an intermediary object. Examples of such + * objects are queues, semaphores, mutexes and event groups. Task notifications + * are a method of sending an event directly to a task without the need for such + * an intermediary object. + * + * A notification sent to a task can optionally perform an action, such as + * update, overwrite or increment one of the task's notification values. In + * that way task notifications can be used to send data to a task, or be used as + * light weight and fast binary or counting semaphores. + * + * A notification sent to a task will remain pending until it is cleared by the + * task calling xTaskNotifyWaitIndexed() or ulTaskNotifyTakeIndexed() (or their + * un-indexed equivalents). If the task was already in the Blocked state to + * wait for a notification when the notification arrives then the task will + * automatically be removed from the Blocked state (unblocked) and the + * notification cleared. + * + * A task can use xTaskNotifyWaitIndexed() to [optionally] block to wait for a + * notification to be pending, or ulTaskNotifyTakeIndexed() to [optionally] block + * to wait for a notification value to have a non-zero value. The task does + * not consume any CPU time while it is in the Blocked state. + * + * **NOTE** Each notification within the array operates independently - a task + * can only block on one notification within the array at a time and will not be + * unblocked by a notification sent to any other array index. + * + * Backward compatibility information: + * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and + * all task notification API functions operated on that value. Replacing the + * single notification value with an array of notification values necessitated a + * new set of API functions that could address specific notifications within the + * array. xTaskNotifyWait() is the original API function, and remains backward + * compatible by always operating on the notification value at index 0 in the + * array. Calling xTaskNotifyWait() is equivalent to calling + * xTaskNotifyWaitIndexed() with the uxIndexToWaitOn parameter set to 0. + * + * @param uxIndexToWaitOn The index within the calling task's array of + * notification values on which the calling task will wait for a notification to + * be received. uxIndexToWaitOn must be less than + * configTASK_NOTIFICATION_ARRAY_ENTRIES. xTaskNotifyWait() does + * not have this parameter and always waits for notifications on index 0. + * + * @param ulBitsToClearOnEntry Bits that are set in ulBitsToClearOnEntry value + * will be cleared in the calling task's notification value before the task + * checks to see if any notifications are pending, and optionally blocks if no + * notifications are pending. Setting ulBitsToClearOnEntry to ULONG_MAX (if + * limits.h is included) or 0xffffffffUL (if limits.h is not included) will have + * the effect of resetting the task's notification value to 0. Setting + * ulBitsToClearOnEntry to 0 will leave the task's notification value unchanged. + * + * @param ulBitsToClearOnExit If a notification is pending or received before + * the calling task exits the xTaskNotifyWait() function then the task's + * notification value (see the xTaskNotify() API function) is passed out using + * the pulNotificationValue parameter. Then any bits that are set in + * ulBitsToClearOnExit will be cleared in the task's notification value (note + * *pulNotificationValue is set before any bits are cleared). Setting + * ulBitsToClearOnExit to ULONG_MAX (if limits.h is included) or 0xffffffffUL + * (if limits.h is not included) will have the effect of resetting the task's + * notification value to 0 before the function exits. Setting + * ulBitsToClearOnExit to 0 will leave the task's notification value unchanged + * when the function exits (in which case the value passed out in + * pulNotificationValue will match the task's notification value). + * + * @param pulNotificationValue Used to pass the task's notification value out + * of the function. Note the value passed out will not be effected by the + * clearing of any bits caused by ulBitsToClearOnExit being non-zero. + * + * @param xTicksToWait The maximum amount of time that the task should wait in + * the Blocked state for a notification to be received, should a notification + * not already be pending when xTaskNotifyWait() was called. The task + * will not consume any processing time while it is in the Blocked state. This + * is specified in kernel ticks, the macro pdMS_TO_TICSK( value_in_ms ) can be + * used to convert a time specified in milliseconds to a time specified in + * ticks. + * + * @return If a notification was received (including notifications that were + * already pending when xTaskNotifyWait was called) then pdPASS is + * returned. Otherwise pdFAIL is returned. + * + * \defgroup xTaskNotifyWaitIndexed xTaskNotifyWaitIndexed + * \ingroup TaskNotifications + */ +BaseType_t xTaskGenericNotifyWait( UBaseType_t uxIndexToWaitOn, + uint32_t ulBitsToClearOnEntry, + uint32_t ulBitsToClearOnExit, + uint32_t * pulNotificationValue, + TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; +#define xTaskNotifyWait( ulBitsToClearOnEntry, ulBitsToClearOnExit, pulNotificationValue, xTicksToWait ) \ + xTaskGenericNotifyWait( tskDEFAULT_INDEX_TO_NOTIFY, ( ulBitsToClearOnEntry ), ( ulBitsToClearOnExit ), ( pulNotificationValue ), ( xTicksToWait ) ) +#define xTaskNotifyWaitIndexed( uxIndexToWaitOn, ulBitsToClearOnEntry, ulBitsToClearOnExit, pulNotificationValue, xTicksToWait ) \ + xTaskGenericNotifyWait( ( uxIndexToWaitOn ), ( ulBitsToClearOnEntry ), ( ulBitsToClearOnExit ), ( pulNotificationValue ), ( xTicksToWait ) ) + +/** + * task. h + *
BaseType_t xTaskNotifyGiveIndexed( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify );
+ *
BaseType_t xTaskNotifyGive( TaskHandle_t xTaskToNotify );
+ * + * Sends a direct to task notification to a particular index in the target + * task's notification array in a manner similar to giving a counting semaphore. + * + * See https://www.FreeRTOS.org/RTOS-task-notifications.html for more details. + * + * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these + * macros to be available. + * + * Each task has a private array of "notification values" (or 'notifications'), + * each of which is a 32-bit unsigned integer (uint32_t). The constant + * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the + * array, and (for backward compatibility) defaults to 1 if left undefined. + * Prior to FreeRTOS V10.4.0 there was only one notification value per task. + * + * Events can be sent to a task using an intermediary object. Examples of such + * objects are queues, semaphores, mutexes and event groups. Task notifications + * are a method of sending an event directly to a task without the need for such + * an intermediary object. + * + * A notification sent to a task can optionally perform an action, such as + * update, overwrite or increment one of the task's notification values. In + * that way task notifications can be used to send data to a task, or be used as + * light weight and fast binary or counting semaphores. + * + * xTaskNotifyGiveIndexed() is a helper macro intended for use when task + * notifications are used as light weight and faster binary or counting + * semaphore equivalents. Actual FreeRTOS semaphores are given using the + * xSemaphoreGive() API function, the equivalent action that instead uses a task + * notification is xTaskNotifyGiveIndexed(). + * + * When task notifications are being used as a binary or counting semaphore + * equivalent then the task being notified should wait for the notification + * using the ulTaskNotificationTakeIndexed() API function rather than the + * xTaskNotifyWaitIndexed() API function. + * + * **NOTE** Each notification within the array operates independently - a task + * can only block on one notification within the array at a time and will not be + * unblocked by a notification sent to any other array index. + * + * Backward compatibility information: + * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and + * all task notification API functions operated on that value. Replacing the + * single notification value with an array of notification values necessitated a + * new set of API functions that could address specific notifications within the + * array. xTaskNotifyGive() is the original API function, and remains backward + * compatible by always operating on the notification value at index 0 in the + * array. Calling xTaskNotifyGive() is equivalent to calling + * xTaskNotifyGiveIndexed() with the uxIndexToNotify parameter set to 0. + * + * @param xTaskToNotify The handle of the task being notified. The handle to a + * task can be returned from the xTaskCreate() API function used to create the + * task, and the handle of the currently running task can be obtained by calling + * xTaskGetCurrentTaskHandle(). + * + * @param uxIndexToNotify The index within the target task's array of + * notification values to which the notification is to be sent. uxIndexToNotify + * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES. xTaskNotifyGive() + * does not have this parameter and always sends notifications to index 0. + * + * @return xTaskNotifyGive() is a macro that calls xTaskNotify() with the + * eAction parameter set to eIncrement - so pdPASS is always returned. + * + * \defgroup xTaskNotifyGiveIndexed xTaskNotifyGiveIndexed + * \ingroup TaskNotifications + */ +#define xTaskNotifyGive( xTaskToNotify ) \ + xTaskGenericNotify( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( 0 ), eIncrement, NULL ) +#define xTaskNotifyGiveIndexed( xTaskToNotify, uxIndexToNotify ) \ + xTaskGenericNotify( ( xTaskToNotify ), ( uxIndexToNotify ), ( 0 ), eIncrement, NULL ) + +/** + * task. h + *
void vTaskNotifyGiveIndexedFromISR( TaskHandle_t xTaskHandle, UBaseType_t uxIndexToNotify, BaseType_t *pxHigherPriorityTaskWoken );
+ *
void vTaskNotifyGiveFromISR( TaskHandle_t xTaskHandle, BaseType_t *pxHigherPriorityTaskWoken );
+ * + * A version of xTaskNotifyGiveIndexed() that can be called from an interrupt + * service routine (ISR). + * + * See https://www.FreeRTOS.org/RTOS-task-notifications.html for more details. + * + * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this macro + * to be available. + * + * Each task has a private array of "notification values" (or 'notifications'), + * each of which is a 32-bit unsigned integer (uint32_t). The constant + * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the + * array, and (for backward compatibility) defaults to 1 if left undefined. + * Prior to FreeRTOS V10.4.0 there was only one notification value per task. + * + * Events can be sent to a task using an intermediary object. Examples of such + * objects are queues, semaphores, mutexes and event groups. Task notifications + * are a method of sending an event directly to a task without the need for such + * an intermediary object. + * + * A notification sent to a task can optionally perform an action, such as + * update, overwrite or increment one of the task's notification values. In + * that way task notifications can be used to send data to a task, or be used as + * light weight and fast binary or counting semaphores. + * + * vTaskNotifyGiveIndexedFromISR() is intended for use when task notifications + * are used as light weight and faster binary or counting semaphore equivalents. + * Actual FreeRTOS semaphores are given from an ISR using the + * xSemaphoreGiveFromISR() API function, the equivalent action that instead uses + * a task notification is vTaskNotifyGiveIndexedFromISR(). + * + * When task notifications are being used as a binary or counting semaphore + * equivalent then the task being notified should wait for the notification + * using the ulTaskNotificationTakeIndexed() API function rather than the + * xTaskNotifyWaitIndexed() API function. + * + * **NOTE** Each notification within the array operates independently - a task + * can only block on one notification within the array at a time and will not be + * unblocked by a notification sent to any other array index. + * + * Backward compatibility information: + * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and + * all task notification API functions operated on that value. Replacing the + * single notification value with an array of notification values necessitated a + * new set of API functions that could address specific notifications within the + * array. xTaskNotifyFromISR() is the original API function, and remains + * backward compatible by always operating on the notification value at index 0 + * within the array. Calling xTaskNotifyGiveFromISR() is equivalent to calling + * xTaskNotifyGiveIndexedFromISR() with the uxIndexToNotify parameter set to 0. + * + * @param xTaskToNotify The handle of the task being notified. The handle to a + * task can be returned from the xTaskCreate() API function used to create the + * task, and the handle of the currently running task can be obtained by calling + * xTaskGetCurrentTaskHandle(). + * + * @param uxIndexToNotify The index within the target task's array of + * notification values to which the notification is to be sent. uxIndexToNotify + * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES. + * xTaskNotifyGiveFromISR() does not have this parameter and always sends + * notifications to index 0. + * + * @param pxHigherPriorityTaskWoken vTaskNotifyGiveFromISR() will set + * *pxHigherPriorityTaskWoken to pdTRUE if sending the notification caused the + * task to which the notification was sent to leave the Blocked state, and the + * unblocked task has a priority higher than the currently running task. If + * vTaskNotifyGiveFromISR() sets this value to pdTRUE then a context switch + * should be requested before the interrupt is exited. How a context switch is + * requested from an ISR is dependent on the port - see the documentation page + * for the port in use. + * + * \defgroup vTaskNotifyGiveIndexedFromISR vTaskNotifyGiveIndexedFromISR + * \ingroup TaskNotifications + */ +void vTaskGenericNotifyGiveFromISR( TaskHandle_t xTaskToNotify, + UBaseType_t uxIndexToNotify, + BaseType_t * pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION; +#define vTaskNotifyGiveFromISR( xTaskToNotify, pxHigherPriorityTaskWoken ) \ + vTaskGenericNotifyGiveFromISR( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( pxHigherPriorityTaskWoken ) ); +#define vTaskNotifyGiveIndexedFromISR( xTaskToNotify, uxIndexToNotify, pxHigherPriorityTaskWoken ) \ + vTaskGenericNotifyGiveFromISR( ( xTaskToNotify ), ( uxIndexToNotify ), ( pxHigherPriorityTaskWoken ) ); + +/** + * task. h + *
+ * uint32_t ulTaskNotifyTakeIndexed( UBaseType_t uxIndexToWaitOn, BaseType_t xClearCountOnExit, TickType_t xTicksToWait );
+ * 
+ * uint32_t ulTaskNotifyTake( BaseType_t xClearCountOnExit, TickType_t xTicksToWait );
+ * 
+ * + * Waits for a direct to task notification on a particular index in the calling + * task's notification array in a manner similar to taking a counting semaphore. + * + * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details. + * + * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this + * function to be available. + * + * Each task has a private array of "notification values" (or 'notifications'), + * each of which is a 32-bit unsigned integer (uint32_t). The constant + * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the + * array, and (for backward compatibility) defaults to 1 if left undefined. + * Prior to FreeRTOS V10.4.0 there was only one notification value per task. + * + * Events can be sent to a task using an intermediary object. Examples of such + * objects are queues, semaphores, mutexes and event groups. Task notifications + * are a method of sending an event directly to a task without the need for such + * an intermediary object. + * + * A notification sent to a task can optionally perform an action, such as + * update, overwrite or increment one of the task's notification values. In + * that way task notifications can be used to send data to a task, or be used as + * light weight and fast binary or counting semaphores. + * + * ulTaskNotifyTakeIndexed() is intended for use when a task notification is + * used as a faster and lighter weight binary or counting semaphore alternative. + * Actual FreeRTOS semaphores are taken using the xSemaphoreTake() API function, + * the equivalent action that instead uses a task notification is + * ulTaskNotifyTakeIndexed(). + * + * When a task is using its notification value as a binary or counting semaphore + * other tasks should send notifications to it using the xTaskNotifyGiveIndexed() + * macro, or xTaskNotifyIndex() function with the eAction parameter set to + * eIncrement. + * + * ulTaskNotifyTakeIndexed() can either clear the task's notification value at + * the array index specified by the uxIndexToWaitOn parameter to zero on exit, + * in which case the notification value acts like a binary semaphore, or + * decrement the notification value on exit, in which case the notification + * value acts like a counting semaphore. + * + * A task can use ulTaskNotifyTakeIndexed() to [optionally] block to wait for + * the task's notification value to be non-zero. The task does not consume any + * CPU time while it is in the Blocked state. + * + * Where as xTaskNotifyWaitIndexed() will return when a notification is pending, + * ulTaskNotifyTakeIndexed() will return when the task's notification value is + * not zero. + * + * **NOTE** Each notification within the array operates independently - a task + * can only block on one notification within the array at a time and will not be + * unblocked by a notification sent to any other array index. + * + * Backward compatibility information: + * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and + * all task notification API functions operated on that value. Replacing the + * single notification value with an array of notification values necessitated a + * new set of API functions that could address specific notifications within the + * array. ulTaskNotifyTake() is the original API function, and remains backward + * compatible by always operating on the notification value at index 0 in the + * array. Calling ulTaskNotifyTake() is equivalent to calling + * ulTaskNotifyTakeIndexed() with the uxIndexToWaitOn parameter set to 0. + * + * @param uxIndexToWaitOn The index within the calling task's array of + * notification values on which the calling task will wait for a notification to + * be non-zero. uxIndexToWaitOn must be less than + * configTASK_NOTIFICATION_ARRAY_ENTRIES. xTaskNotifyTake() does + * not have this parameter and always waits for notifications on index 0. + * + * @param xClearCountOnExit if xClearCountOnExit is pdFALSE then the task's + * notification value is decremented when the function exits. In this way the + * notification value acts like a counting semaphore. If xClearCountOnExit is + * not pdFALSE then the task's notification value is cleared to zero when the + * function exits. In this way the notification value acts like a binary + * semaphore. + * + * @param xTicksToWait The maximum amount of time that the task should wait in + * the Blocked state for the task's notification value to be greater than zero, + * should the count not already be greater than zero when + * ulTaskNotifyTake() was called. The task will not consume any processing + * time while it is in the Blocked state. This is specified in kernel ticks, + * the macro pdMS_TO_TICSK( value_in_ms ) can be used to convert a time + * specified in milliseconds to a time specified in ticks. + * + * @return The task's notification count before it is either cleared to zero or + * decremented (see the xClearCountOnExit parameter). + * + * \defgroup ulTaskNotifyTakeIndexed ulTaskNotifyTakeIndexed + * \ingroup TaskNotifications + */ +uint32_t ulTaskGenericNotifyTake( UBaseType_t uxIndexToWaitOn, + BaseType_t xClearCountOnExit, + TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; +#define ulTaskNotifyTake( xClearCountOnExit, xTicksToWait ) \ + ulTaskGenericNotifyTake( ( tskDEFAULT_INDEX_TO_NOTIFY ), ( xClearCountOnExit ), ( xTicksToWait ) ) +#define ulTaskNotifyTakeIndexed( uxIndexToWaitOn, xClearCountOnExit, xTicksToWait ) \ + ulTaskGenericNotifyTake( ( uxIndexToWaitOn ), ( xClearCountOnExit ), ( xTicksToWait ) ) + +/** + * task. h + *
+ * BaseType_t xTaskNotifyStateClearIndexed( TaskHandle_t xTask, UBaseType_t uxIndexToCLear );
+ * 
+ * BaseType_t xTaskNotifyStateClear( TaskHandle_t xTask );
+ * 
+ * + * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details. + * + * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these + * functions to be available. + * + * Each task has a private array of "notification values" (or 'notifications'), + * each of which is a 32-bit unsigned integer (uint32_t). The constant + * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the + * array, and (for backward compatibility) defaults to 1 if left undefined. + * Prior to FreeRTOS V10.4.0 there was only one notification value per task. + * + * If a notification is sent to an index within the array of notifications then + * the notification at that index is said to be 'pending' until it is read or + * explicitly cleared by the receiving task. xTaskNotifyStateClearIndexed() + * is the function that clears a pending notification without reading the + * notification value. The notification value at the same array index is not + * altered. Set xTask to NULL to clear the notification state of the calling + * task. + * + * Backward compatibility information: + * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and + * all task notification API functions operated on that value. Replacing the + * single notification value with an array of notification values necessitated a + * new set of API functions that could address specific notifications within the + * array. xTaskNotifyStateClear() is the original API function, and remains + * backward compatible by always operating on the notification value at index 0 + * within the array. Calling xTaskNotifyStateClear() is equivalent to calling + * xTaskNotifyStateClearIndexed() with the uxIndexToNotify parameter set to 0. + * + * @param xTask The handle of the RTOS task that will have a notification state + * cleared. Set xTask to NULL to clear a notification state in the calling + * task. To obtain a task's handle create the task using xTaskCreate() and + * make use of the pxCreatedTask parameter, or create the task using + * xTaskCreateStatic() and store the returned value, or use the task's name in + * a call to xTaskGetHandle(). + * + * @param uxIndexToClear The index within the target task's array of + * notification values to act upon. For example, setting uxIndexToClear to 1 + * will clear the state of the notification at index 1 within the array. + * uxIndexToClear must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES. + * ulTaskNotifyStateClear() does not have this parameter and always acts on the + * notification at index 0. + * + * @return pdTRUE if the task's notification state was set to + * eNotWaitingNotification, otherwise pdFALSE. + * + * \defgroup xTaskNotifyStateClearIndexed xTaskNotifyStateClearIndexed + * \ingroup TaskNotifications + */ +BaseType_t xTaskGenericNotifyStateClear( TaskHandle_t xTask, + UBaseType_t uxIndexToClear ) PRIVILEGED_FUNCTION; +#define xTaskNotifyStateClear( xTask ) \ + xTaskGenericNotifyStateClear( ( xTask ), ( tskDEFAULT_INDEX_TO_NOTIFY ) ) +#define xTaskNotifyStateClearIndexed( xTask, uxIndexToClear ) \ + xTaskGenericNotifyStateClear( ( xTask ), ( uxIndexToClear ) ) + +/** + * task. h + *
+ * uint32_t ulTaskNotifyValueClearIndexed( TaskHandle_t xTask, UBaseType_t uxIndexToClear, uint32_t ulBitsToClear );
+ * 
+ * uint32_t ulTaskNotifyValueClear( TaskHandle_t xTask, uint32_t ulBitsToClear );
+ * 
+ * + * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details. + * + * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these + * functions to be available. + * + * Each task has a private array of "notification values" (or 'notifications'), + * each of which is a 32-bit unsigned integer (uint32_t). The constant + * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the + * array, and (for backward compatibility) defaults to 1 if left undefined. + * Prior to FreeRTOS V10.4.0 there was only one notification value per task. + * + * ulTaskNotifyValueClearIndexed() clears the bits specified by the + * ulBitsToClear bit mask in the notification value at array index uxIndexToClear + * of the task referenced by xTask. + * + * Backward compatibility information: + * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and + * all task notification API functions operated on that value. Replacing the + * single notification value with an array of notification values necessitated a + * new set of API functions that could address specific notifications within the + * array. ulTaskNotifyValueClear() is the original API function, and remains + * backward compatible by always operating on the notification value at index 0 + * within the array. Calling ulTaskNotifyValueClear() is equivalent to calling + * ulTaskNotifyValueClearIndexed() with the uxIndexToClear parameter set to 0. + * + * @param xTask The handle of the RTOS task that will have bits in one of its + * notification values cleared. Set xTask to NULL to clear bits in a + * notification value of the calling task. To obtain a task's handle create the + * task using xTaskCreate() and make use of the pxCreatedTask parameter, or + * create the task using xTaskCreateStatic() and store the returned value, or + * use the task's name in a call to xTaskGetHandle(). + * + * @param uxIndexToClear The index within the target task's array of + * notification values in which to clear the bits. uxIndexToClear + * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES. + * ulTaskNotifyValueClear() does not have this parameter and always clears bits + * in the notification value at index 0. + * + * @param ulBitsToClear Bit mask of the bits to clear in the notification value of + * xTask. Set a bit to 1 to clear the corresponding bits in the task's notification + * value. Set ulBitsToClear to 0xffffffff (UINT_MAX on 32-bit architectures) to clear + * the notification value to 0. Set ulBitsToClear to 0 to query the task's + * notification value without clearing any bits. + * + * + * @return The value of the target task's notification value before the bits + * specified by ulBitsToClear were cleared. + * \defgroup ulTaskNotifyValueClear ulTaskNotifyValueClear + * \ingroup TaskNotifications + */ +uint32_t ulTaskGenericNotifyValueClear( TaskHandle_t xTask, + UBaseType_t uxIndexToClear, + uint32_t ulBitsToClear ) PRIVILEGED_FUNCTION; +#define ulTaskNotifyValueClear( xTask, ulBitsToClear ) \ + ulTaskGenericNotifyValueClear( ( xTask ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulBitsToClear ) ) +#define ulTaskNotifyValueClearIndexed( xTask, uxIndexToClear, ulBitsToClear ) \ + ulTaskGenericNotifyValueClear( ( xTask ), ( uxIndexToClear ), ( ulBitsToClear ) ) + +/** + * task.h + *
+ * void vTaskSetTimeOutState( TimeOut_t * const pxTimeOut );
+ * 
+ * + * Capture the current time for future use with xTaskCheckForTimeOut(). + * + * @param pxTimeOut Pointer to a timeout object into which the current time + * is to be captured. The captured time includes the tick count and the number + * of times the tick count has overflowed since the system first booted. + * \defgroup vTaskSetTimeOutState vTaskSetTimeOutState + * \ingroup TaskCtrl + */ +void vTaskSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNCTION; + +/** + * task.h + *
+ * BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut, TickType_t * const pxTicksToWait );
+ * 
+ * + * Determines if pxTicksToWait ticks has passed since a time was captured + * using a call to vTaskSetTimeOutState(). The captured time includes the tick + * count and the number of times the tick count has overflowed. + * + * @param pxTimeOut The time status as captured previously using + * vTaskSetTimeOutState. If the timeout has not yet occurred, it is updated + * to reflect the current time status. + * @param pxTicksToWait The number of ticks to check for timeout i.e. if + * pxTicksToWait ticks have passed since pxTimeOut was last updated (either by + * vTaskSetTimeOutState() or xTaskCheckForTimeOut()), the timeout has occurred. + * If the timeout has not occurred, pxTIcksToWait is updated to reflect the + * number of remaining ticks. + * + * @return If timeout has occurred, pdTRUE is returned. Otherwise pdFALSE is + * returned and pxTicksToWait is updated to reflect the number of remaining + * ticks. + * + * @see https://www.FreeRTOS.org/xTaskCheckForTimeOut.html + * + * Example Usage: + *
+ *  // Driver library function used to receive uxWantedBytes from an Rx buffer
+ *  // that is filled by a UART interrupt. If there are not enough bytes in the
+ *  // Rx buffer then the task enters the Blocked state until it is notified that
+ *  // more data has been placed into the buffer. If there is still not enough
+ *  // data then the task re-enters the Blocked state, and xTaskCheckForTimeOut()
+ *  // is used to re-calculate the Block time to ensure the total amount of time
+ *  // spent in the Blocked state does not exceed MAX_TIME_TO_WAIT. This
+ *  // continues until either the buffer contains at least uxWantedBytes bytes,
+ *  // or the total amount of time spent in the Blocked state reaches
+ *  // MAX_TIME_TO_WAIT – at which point the task reads however many bytes are
+ *  // available up to a maximum of uxWantedBytes.
+ *
+ *  size_t xUART_Receive( uint8_t *pucBuffer, size_t uxWantedBytes )
+ *  {
+ *  size_t uxReceived = 0;
+ *  TickType_t xTicksToWait = MAX_TIME_TO_WAIT;
+ *  TimeOut_t xTimeOut;
+ *
+ *      // Initialize xTimeOut.  This records the time at which this function
+ *      // was entered.
+ *      vTaskSetTimeOutState( &xTimeOut );
+ *
+ *      // Loop until the buffer contains the wanted number of bytes, or a
+ *      // timeout occurs.
+ *      while( UART_bytes_in_rx_buffer( pxUARTInstance ) < uxWantedBytes )
+ *      {
+ *          // The buffer didn't contain enough data so this task is going to
+ *          // enter the Blocked state. Adjusting xTicksToWait to account for
+ *          // any time that has been spent in the Blocked state within this
+ *          // function so far to ensure the total amount of time spent in the
+ *          // Blocked state does not exceed MAX_TIME_TO_WAIT.
+ *          if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) != pdFALSE )
+ *          {
+ *              //Timed out before the wanted number of bytes were available,
+ *              // exit the loop.
+ *              break;
+ *          }
+ *
+ *          // Wait for a maximum of xTicksToWait ticks to be notified that the
+ *          // receive interrupt has placed more data into the buffer.
+ *          ulTaskNotifyTake( pdTRUE, xTicksToWait );
+ *      }
+ *
+ *      // Attempt to read uxWantedBytes from the receive buffer into pucBuffer.
+ *      // The actual number of bytes read (which might be less than
+ *      // uxWantedBytes) is returned.
+ *      uxReceived = UART_read_from_receive_buffer( pxUARTInstance,
+ *                                                  pucBuffer,
+ *                                                  uxWantedBytes );
+ *
+ *      return uxReceived;
+ *  }
+ * 
+ * \defgroup xTaskCheckForTimeOut xTaskCheckForTimeOut + * \ingroup TaskCtrl + */ +BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut, + TickType_t * const pxTicksToWait ) PRIVILEGED_FUNCTION; + +/** + * task.h + *
+ * BaseType_t xTaskCatchUpTicks( TickType_t xTicksToCatchUp );
+ * 
+ * + * This function corrects the tick count value after the application code has held + * interrupts disabled for an extended period resulting in tick interrupts having + * been missed. + * + * This function is similar to vTaskStepTick(), however, unlike + * vTaskStepTick(), xTaskCatchUpTicks() may move the tick count forward past a + * time at which a task should be removed from the blocked state. That means + * tasks may have to be removed from the blocked state as the tick count is + * moved. + * + * @param xTicksToCatchUp The number of tick interrupts that have been missed due to + * interrupts being disabled. Its value is not computed automatically, so must be + * computed by the application writer. + * + * @return pdTRUE if moving the tick count forward resulted in a task leaving the + * blocked state and a context switch being performed. Otherwise pdFALSE. + * + * \defgroup xTaskCatchUpTicks xTaskCatchUpTicks + * \ingroup TaskCtrl + */ +BaseType_t xTaskCatchUpTicks( TickType_t xTicksToCatchUp ) PRIVILEGED_FUNCTION; + + +/*----------------------------------------------------------- +* SCHEDULER INTERNALS AVAILABLE FOR PORTING PURPOSES +*----------------------------------------------------------*/ + +/* + * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY + * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS + * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER. + * + * Called from the real time kernel tick (either preemptive or cooperative), + * this increments the tick count and checks if any tasks that are blocked + * for a finite period required removing from a blocked list and placing on + * a ready list. If a non-zero value is returned then a context switch is + * required because either: + * + A task was removed from a blocked list because its timeout had expired, + * or + * + Time slicing is in use and there is a task of equal priority to the + * currently running task. + */ +BaseType_t xTaskIncrementTick( void ) PRIVILEGED_FUNCTION; + +/* + * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN + * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER. + * + * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED. + * + * Removes the calling task from the ready list and places it both + * on the list of tasks waiting for a particular event, and the + * list of delayed tasks. The task will be removed from both lists + * and replaced on the ready list should either the event occur (and + * there be no higher priority tasks waiting on the same event) or + * the delay period expires. + * + * The 'unordered' version replaces the event list item value with the + * xItemValue value, and inserts the list item at the end of the list. + * + * The 'ordered' version uses the existing event list item value (which is the + * owning tasks priority) to insert the list item into the event list is task + * priority order. + * + * @param pxEventList The list containing tasks that are blocked waiting + * for the event to occur. + * + * @param xItemValue The item value to use for the event list item when the + * event list is not ordered by task priority. + * + * @param xTicksToWait The maximum amount of time that the task should wait + * for the event to occur. This is specified in kernel ticks,the constant + * portTICK_PERIOD_MS can be used to convert kernel ticks into a real time + * period. + */ +void vTaskPlaceOnEventList( List_t * const pxEventList, + const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; +void vTaskPlaceOnUnorderedEventList( List_t * pxEventList, + const TickType_t xItemValue, + const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; + +/* + * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN + * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER. + * + * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED. + * + * This function performs nearly the same function as vTaskPlaceOnEventList(). + * The difference being that this function does not permit tasks to block + * indefinitely, whereas vTaskPlaceOnEventList() does. + * + */ +void vTaskPlaceOnEventListRestricted( List_t * const pxEventList, + TickType_t xTicksToWait, + const BaseType_t xWaitIndefinitely ) PRIVILEGED_FUNCTION; + +/* + * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN + * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER. + * + * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED. + * + * Removes a task from both the specified event list and the list of blocked + * tasks, and places it on a ready queue. + * + * xTaskRemoveFromEventList()/vTaskRemoveFromUnorderedEventList() will be called + * if either an event occurs to unblock a task, or the block timeout period + * expires. + * + * xTaskRemoveFromEventList() is used when the event list is in task priority + * order. It removes the list item from the head of the event list as that will + * have the highest priority owning task of all the tasks on the event list. + * vTaskRemoveFromUnorderedEventList() is used when the event list is not + * ordered and the event list items hold something other than the owning tasks + * priority. In this case the event list item value is updated to the value + * passed in the xItemValue parameter. + * + * @return pdTRUE if the task being removed has a higher priority than the task + * making the call, otherwise pdFALSE. + */ +BaseType_t xTaskRemoveFromEventList( const List_t * const pxEventList ) PRIVILEGED_FUNCTION; +void vTaskRemoveFromUnorderedEventList( ListItem_t * pxEventListItem, + const TickType_t xItemValue ) PRIVILEGED_FUNCTION; + +/* + * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY + * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS + * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER. + * + * Sets the pointer to the current TCB to the TCB of the highest priority task + * that is ready to run. + */ +portDONT_DISCARD void vTaskSwitchContext( void ) PRIVILEGED_FUNCTION; + +/* + * THESE FUNCTIONS MUST NOT BE USED FROM APPLICATION CODE. THEY ARE USED BY + * THE EVENT BITS MODULE. + */ +TickType_t uxTaskResetEventItemValue( void ) PRIVILEGED_FUNCTION; + +/* + * Return the handle of the calling task. + */ +TaskHandle_t xTaskGetCurrentTaskHandle( void ) PRIVILEGED_FUNCTION; + +/* + * Shortcut used by the queue implementation to prevent unnecessary call to + * taskYIELD(); + */ +void vTaskMissedYield( void ) PRIVILEGED_FUNCTION; + +/* + * Returns the scheduler state as taskSCHEDULER_RUNNING, + * taskSCHEDULER_NOT_STARTED or taskSCHEDULER_SUSPENDED. + */ +BaseType_t xTaskGetSchedulerState( void ) PRIVILEGED_FUNCTION; + +/* + * Raises the priority of the mutex holder to that of the calling task should + * the mutex holder have a priority less than the calling task. + */ +BaseType_t xTaskPriorityInherit( TaskHandle_t const pxMutexHolder ) PRIVILEGED_FUNCTION; + +/* + * Set the priority of a task back to its proper priority in the case that it + * inherited a higher priority while it was holding a semaphore. + */ +BaseType_t xTaskPriorityDisinherit( TaskHandle_t const pxMutexHolder ) PRIVILEGED_FUNCTION; + +/* + * If a higher priority task attempting to obtain a mutex caused a lower + * priority task to inherit the higher priority task's priority - but the higher + * priority task then timed out without obtaining the mutex, then the lower + * priority task will disinherit the priority again - but only down as far as + * the highest priority task that is still waiting for the mutex (if there were + * more than one task waiting for the mutex). + */ +void vTaskPriorityDisinheritAfterTimeout( TaskHandle_t const pxMutexHolder, + UBaseType_t uxHighestPriorityWaitingTask ) PRIVILEGED_FUNCTION; + +/* + * Get the uxTCBNumber assigned to the task referenced by the xTask parameter. + */ +UBaseType_t uxTaskGetTaskNumber( TaskHandle_t xTask ) PRIVILEGED_FUNCTION; + +/* + * Set the uxTaskNumber of the task referenced by the xTask parameter to + * uxHandle. + */ +void vTaskSetTaskNumber( TaskHandle_t xTask, + const UBaseType_t uxHandle ) PRIVILEGED_FUNCTION; + +/* + * Only available when configUSE_TICKLESS_IDLE is set to 1. + * If tickless mode is being used, or a low power mode is implemented, then + * the tick interrupt will not execute during idle periods. When this is the + * case, the tick count value maintained by the scheduler needs to be kept up + * to date with the actual execution time by being skipped forward by a time + * equal to the idle period. + */ +void vTaskStepTick( const TickType_t xTicksToJump ) PRIVILEGED_FUNCTION; + +/* + * Only available when configUSE_TICKLESS_IDLE is set to 1. + * Provided for use within portSUPPRESS_TICKS_AND_SLEEP() to allow the port + * specific sleep function to determine if it is ok to proceed with the sleep, + * and if it is ok to proceed, if it is ok to sleep indefinitely. + * + * This function is necessary because portSUPPRESS_TICKS_AND_SLEEP() is only + * called with the scheduler suspended, not from within a critical section. It + * is therefore possible for an interrupt to request a context switch between + * portSUPPRESS_TICKS_AND_SLEEP() and the low power mode actually being + * entered. eTaskConfirmSleepModeStatus() should be called from a short + * critical section between the timer being stopped and the sleep mode being + * entered to ensure it is ok to proceed into the sleep mode. + */ +eSleepModeStatus eTaskConfirmSleepModeStatus( void ) PRIVILEGED_FUNCTION; + +/* + * For internal use only. Increment the mutex held count when a mutex is + * taken and return the handle of the task that has taken the mutex. + */ +TaskHandle_t pvTaskIncrementMutexHeldCount( void ) PRIVILEGED_FUNCTION; + +/* + * For internal use only. Same as vTaskSetTimeOutState(), but without a critical + * section. + */ +void vTaskInternalSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNCTION; + + +/* *INDENT-OFF* */ +#ifdef __cplusplus + } +#endif +/* *INDENT-ON* */ +#endif /* INC_TASK_H */ diff --git a/RTOS/FreeRTOS/Source/include/timers.h b/RTOS/FreeRTOS/Source/include/timers.h new file mode 100644 index 0000000..ba5c413 --- /dev/null +++ b/RTOS/FreeRTOS/Source/include/timers.h @@ -0,0 +1,1351 @@ +/* + * FreeRTOS Kernel V10.4.1 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * https://www.FreeRTOS.org + * https://github.com/FreeRTOS + * + */ + + +#ifndef TIMERS_H +#define TIMERS_H + +#ifndef INC_FREERTOS_H + #error "include FreeRTOS.h must appear in source files before include timers.h" +#endif + +/*lint -save -e537 This headers are only multiply included if the application code + * happens to also be including task.h. */ +#include "task.h" +/*lint -restore */ + +/* *INDENT-OFF* */ +#ifdef __cplusplus + extern "C" { +#endif +/* *INDENT-ON* */ + +/*----------------------------------------------------------- +* MACROS AND DEFINITIONS +*----------------------------------------------------------*/ + +/* IDs for commands that can be sent/received on the timer queue. These are to + * be used solely through the macros that make up the public software timer API, + * as defined below. The commands that are sent from interrupts must use the + * highest numbers as tmrFIRST_FROM_ISR_COMMAND is used to determine if the task + * or interrupt version of the queue send function should be used. */ +#define tmrCOMMAND_EXECUTE_CALLBACK_FROM_ISR ( ( BaseType_t ) -2 ) +#define tmrCOMMAND_EXECUTE_CALLBACK ( ( BaseType_t ) -1 ) +#define tmrCOMMAND_START_DONT_TRACE ( ( BaseType_t ) 0 ) +#define tmrCOMMAND_START ( ( BaseType_t ) 1 ) +#define tmrCOMMAND_RESET ( ( BaseType_t ) 2 ) +#define tmrCOMMAND_STOP ( ( BaseType_t ) 3 ) +#define tmrCOMMAND_CHANGE_PERIOD ( ( BaseType_t ) 4 ) +#define tmrCOMMAND_DELETE ( ( BaseType_t ) 5 ) + +#define tmrFIRST_FROM_ISR_COMMAND ( ( BaseType_t ) 6 ) +#define tmrCOMMAND_START_FROM_ISR ( ( BaseType_t ) 6 ) +#define tmrCOMMAND_RESET_FROM_ISR ( ( BaseType_t ) 7 ) +#define tmrCOMMAND_STOP_FROM_ISR ( ( BaseType_t ) 8 ) +#define tmrCOMMAND_CHANGE_PERIOD_FROM_ISR ( ( BaseType_t ) 9 ) + + +/** + * Type by which software timers are referenced. For example, a call to + * xTimerCreate() returns an TimerHandle_t variable that can then be used to + * reference the subject timer in calls to other software timer API functions + * (for example, xTimerStart(), xTimerReset(), etc.). + */ +struct tmrTimerControl; /* The old naming convention is used to prevent breaking kernel aware debuggers. */ +typedef struct tmrTimerControl * TimerHandle_t; + +/* + * Defines the prototype to which timer callback functions must conform. + */ +typedef void (* TimerCallbackFunction_t)( TimerHandle_t xTimer ); + +/* + * Defines the prototype to which functions used with the + * xTimerPendFunctionCallFromISR() function must conform. + */ +typedef void (* PendedFunction_t)( void *, + uint32_t ); + +/** + * TimerHandle_t xTimerCreate( const char * const pcTimerName, + * TickType_t xTimerPeriodInTicks, + * UBaseType_t uxAutoReload, + * void * pvTimerID, + * TimerCallbackFunction_t pxCallbackFunction ); + * + * Creates a new software timer instance, and returns a handle by which the + * created software timer can be referenced. + * + * Internally, within the FreeRTOS implementation, software timers use a block + * of memory, in which the timer data structure is stored. If a software timer + * is created using xTimerCreate() then the required memory is automatically + * dynamically allocated inside the xTimerCreate() function. (see + * https://www.FreeRTOS.org/a00111.html). If a software timer is created using + * xTimerCreateStatic() then the application writer must provide the memory that + * will get used by the software timer. xTimerCreateStatic() therefore allows a + * software timer to be created without using any dynamic memory allocation. + * + * Timers are created in the dormant state. The xTimerStart(), xTimerReset(), + * xTimerStartFromISR(), xTimerResetFromISR(), xTimerChangePeriod() and + * xTimerChangePeriodFromISR() API functions can all be used to transition a + * timer into the active state. + * + * @param pcTimerName A text name that is assigned to the timer. This is done + * purely to assist debugging. The kernel itself only ever references a timer + * by its handle, and never by its name. + * + * @param xTimerPeriodInTicks The timer period. The time is defined in tick + * periods so the constant portTICK_PERIOD_MS can be used to convert a time that + * has been specified in milliseconds. For example, if the timer must expire + * after 100 ticks, then xTimerPeriodInTicks should be set to 100. + * Alternatively, if the timer must expire after 500ms, then xPeriod can be set + * to ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than or + * equal to 1000. Time timer period must be greater than 0. + * + * @param uxAutoReload If uxAutoReload is set to pdTRUE then the timer will + * expire repeatedly with a frequency set by the xTimerPeriodInTicks parameter. + * If uxAutoReload is set to pdFALSE then the timer will be a one-shot timer and + * enter the dormant state after it expires. + * + * @param pvTimerID An identifier that is assigned to the timer being created. + * Typically this would be used in the timer callback function to identify which + * timer expired when the same callback function is assigned to more than one + * timer. + * + * @param pxCallbackFunction The function to call when the timer expires. + * Callback functions must have the prototype defined by TimerCallbackFunction_t, + * which is "void vCallbackFunction( TimerHandle_t xTimer );". + * + * @return If the timer is successfully created then a handle to the newly + * created timer is returned. If the timer cannot be created because there is + * insufficient FreeRTOS heap remaining to allocate the timer + * structures then NULL is returned. + * + * Example usage: + * @verbatim + * #define NUM_TIMERS 5 + * + * // An array to hold handles to the created timers. + * TimerHandle_t xTimers[ NUM_TIMERS ]; + * + * // An array to hold a count of the number of times each timer expires. + * int32_t lExpireCounters[ NUM_TIMERS ] = { 0 }; + * + * // Define a callback function that will be used by multiple timer instances. + * // The callback function does nothing but count the number of times the + * // associated timer expires, and stop the timer once the timer has expired + * // 10 times. + * void vTimerCallback( TimerHandle_t pxTimer ) + * { + * int32_t lArrayIndex; + * const int32_t xMaxExpiryCountBeforeStopping = 10; + * + * // Optionally do something if the pxTimer parameter is NULL. + * configASSERT( pxTimer ); + * + * // Which timer expired? + * lArrayIndex = ( int32_t ) pvTimerGetTimerID( pxTimer ); + * + * // Increment the number of times that pxTimer has expired. + * lExpireCounters[ lArrayIndex ] += 1; + * + * // If the timer has expired 10 times then stop it from running. + * if( lExpireCounters[ lArrayIndex ] == xMaxExpiryCountBeforeStopping ) + * { + * // Do not use a block time if calling a timer API function from a + * // timer callback function, as doing so could cause a deadlock! + * xTimerStop( pxTimer, 0 ); + * } + * } + * + * void main( void ) + * { + * int32_t x; + * + * // Create then start some timers. Starting the timers before the scheduler + * // has been started means the timers will start running immediately that + * // the scheduler starts. + * for( x = 0; x < NUM_TIMERS; x++ ) + * { + * xTimers[ x ] = xTimerCreate( "Timer", // Just a text name, not used by the kernel. + * ( 100 * x ), // The timer period in ticks. + * pdTRUE, // The timers will auto-reload themselves when they expire. + * ( void * ) x, // Assign each timer a unique id equal to its array index. + * vTimerCallback // Each timer calls the same callback when it expires. + * ); + * + * if( xTimers[ x ] == NULL ) + * { + * // The timer was not created. + * } + * else + * { + * // Start the timer. No block time is specified, and even if one was + * // it would be ignored because the scheduler has not yet been + * // started. + * if( xTimerStart( xTimers[ x ], 0 ) != pdPASS ) + * { + * // The timer could not be set into the Active state. + * } + * } + * } + * + * // ... + * // Create tasks here. + * // ... + * + * // Starting the scheduler will start the timers running as they have already + * // been set into the active state. + * vTaskStartScheduler(); + * + * // Should not reach here. + * for( ;; ); + * } + * @endverbatim + */ +#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + TimerHandle_t xTimerCreate( const char * const pcTimerName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + const TickType_t xTimerPeriodInTicks, + const UBaseType_t uxAutoReload, + void * const pvTimerID, + TimerCallbackFunction_t pxCallbackFunction ) PRIVILEGED_FUNCTION; +#endif + +/** + * TimerHandle_t xTimerCreateStatic(const char * const pcTimerName, + * TickType_t xTimerPeriodInTicks, + * UBaseType_t uxAutoReload, + * void * pvTimerID, + * TimerCallbackFunction_t pxCallbackFunction, + * StaticTimer_t *pxTimerBuffer ); + * + * Creates a new software timer instance, and returns a handle by which the + * created software timer can be referenced. + * + * Internally, within the FreeRTOS implementation, software timers use a block + * of memory, in which the timer data structure is stored. If a software timer + * is created using xTimerCreate() then the required memory is automatically + * dynamically allocated inside the xTimerCreate() function. (see + * https://www.FreeRTOS.org/a00111.html). If a software timer is created using + * xTimerCreateStatic() then the application writer must provide the memory that + * will get used by the software timer. xTimerCreateStatic() therefore allows a + * software timer to be created without using any dynamic memory allocation. + * + * Timers are created in the dormant state. The xTimerStart(), xTimerReset(), + * xTimerStartFromISR(), xTimerResetFromISR(), xTimerChangePeriod() and + * xTimerChangePeriodFromISR() API functions can all be used to transition a + * timer into the active state. + * + * @param pcTimerName A text name that is assigned to the timer. This is done + * purely to assist debugging. The kernel itself only ever references a timer + * by its handle, and never by its name. + * + * @param xTimerPeriodInTicks The timer period. The time is defined in tick + * periods so the constant portTICK_PERIOD_MS can be used to convert a time that + * has been specified in milliseconds. For example, if the timer must expire + * after 100 ticks, then xTimerPeriodInTicks should be set to 100. + * Alternatively, if the timer must expire after 500ms, then xPeriod can be set + * to ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than or + * equal to 1000. The timer period must be greater than 0. + * + * @param uxAutoReload If uxAutoReload is set to pdTRUE then the timer will + * expire repeatedly with a frequency set by the xTimerPeriodInTicks parameter. + * If uxAutoReload is set to pdFALSE then the timer will be a one-shot timer and + * enter the dormant state after it expires. + * + * @param pvTimerID An identifier that is assigned to the timer being created. + * Typically this would be used in the timer callback function to identify which + * timer expired when the same callback function is assigned to more than one + * timer. + * + * @param pxCallbackFunction The function to call when the timer expires. + * Callback functions must have the prototype defined by TimerCallbackFunction_t, + * which is "void vCallbackFunction( TimerHandle_t xTimer );". + * + * @param pxTimerBuffer Must point to a variable of type StaticTimer_t, which + * will be then be used to hold the software timer's data structures, removing + * the need for the memory to be allocated dynamically. + * + * @return If the timer is created then a handle to the created timer is + * returned. If pxTimerBuffer was NULL then NULL is returned. + * + * Example usage: + * @verbatim + * + * // The buffer used to hold the software timer's data structure. + * static StaticTimer_t xTimerBuffer; + * + * // A variable that will be incremented by the software timer's callback + * // function. + * UBaseType_t uxVariableToIncrement = 0; + * + * // A software timer callback function that increments a variable passed to + * // it when the software timer was created. After the 5th increment the + * // callback function stops the software timer. + * static void prvTimerCallback( TimerHandle_t xExpiredTimer ) + * { + * UBaseType_t *puxVariableToIncrement; + * BaseType_t xReturned; + * + * // Obtain the address of the variable to increment from the timer ID. + * puxVariableToIncrement = ( UBaseType_t * ) pvTimerGetTimerID( xExpiredTimer ); + * + * // Increment the variable to show the timer callback has executed. + * ( *puxVariableToIncrement )++; + * + * // If this callback has executed the required number of times, stop the + * // timer. + * if( *puxVariableToIncrement == 5 ) + * { + * // This is called from a timer callback so must not block. + * xTimerStop( xExpiredTimer, staticDONT_BLOCK ); + * } + * } + * + * + * void main( void ) + * { + * // Create the software time. xTimerCreateStatic() has an extra parameter + * // than the normal xTimerCreate() API function. The parameter is a pointer + * // to the StaticTimer_t structure that will hold the software timer + * // structure. If the parameter is passed as NULL then the structure will be + * // allocated dynamically, just as if xTimerCreate() had been called. + * xTimer = xTimerCreateStatic( "T1", // Text name for the task. Helps debugging only. Not used by FreeRTOS. + * xTimerPeriod, // The period of the timer in ticks. + * pdTRUE, // This is an auto-reload timer. + * ( void * ) &uxVariableToIncrement, // A variable incremented by the software timer's callback function + * prvTimerCallback, // The function to execute when the timer expires. + * &xTimerBuffer ); // The buffer that will hold the software timer structure. + * + * // The scheduler has not started yet so a block time is not used. + * xReturned = xTimerStart( xTimer, 0 ); + * + * // ... + * // Create tasks here. + * // ... + * + * // Starting the scheduler will start the timers running as they have already + * // been set into the active state. + * vTaskStartScheduler(); + * + * // Should not reach here. + * for( ;; ); + * } + * @endverbatim + */ +#if ( configSUPPORT_STATIC_ALLOCATION == 1 ) + TimerHandle_t xTimerCreateStatic( const char * const pcTimerName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + const TickType_t xTimerPeriodInTicks, + const UBaseType_t uxAutoReload, + void * const pvTimerID, + TimerCallbackFunction_t pxCallbackFunction, + StaticTimer_t * pxTimerBuffer ) PRIVILEGED_FUNCTION; +#endif /* configSUPPORT_STATIC_ALLOCATION */ + +/** + * void *pvTimerGetTimerID( TimerHandle_t xTimer ); + * + * Returns the ID assigned to the timer. + * + * IDs are assigned to timers using the pvTimerID parameter of the call to + * xTimerCreated() that was used to create the timer, and by calling the + * vTimerSetTimerID() API function. + * + * If the same callback function is assigned to multiple timers then the timer + * ID can be used as time specific (timer local) storage. + * + * @param xTimer The timer being queried. + * + * @return The ID assigned to the timer being queried. + * + * Example usage: + * + * See the xTimerCreate() API function example usage scenario. + */ +void * pvTimerGetTimerID( const TimerHandle_t xTimer ) PRIVILEGED_FUNCTION; + +/** + * void vTimerSetTimerID( TimerHandle_t xTimer, void *pvNewID ); + * + * Sets the ID assigned to the timer. + * + * IDs are assigned to timers using the pvTimerID parameter of the call to + * xTimerCreated() that was used to create the timer. + * + * If the same callback function is assigned to multiple timers then the timer + * ID can be used as time specific (timer local) storage. + * + * @param xTimer The timer being updated. + * + * @param pvNewID The ID to assign to the timer. + * + * Example usage: + * + * See the xTimerCreate() API function example usage scenario. + */ +void vTimerSetTimerID( TimerHandle_t xTimer, + void * pvNewID ) PRIVILEGED_FUNCTION; + +/** + * BaseType_t xTimerIsTimerActive( TimerHandle_t xTimer ); + * + * Queries a timer to see if it is active or dormant. + * + * A timer will be dormant if: + * 1) It has been created but not started, or + * 2) It is an expired one-shot timer that has not been restarted. + * + * Timers are created in the dormant state. The xTimerStart(), xTimerReset(), + * xTimerStartFromISR(), xTimerResetFromISR(), xTimerChangePeriod() and + * xTimerChangePeriodFromISR() API functions can all be used to transition a timer into the + * active state. + * + * @param xTimer The timer being queried. + * + * @return pdFALSE will be returned if the timer is dormant. A value other than + * pdFALSE will be returned if the timer is active. + * + * Example usage: + * @verbatim + * // This function assumes xTimer has already been created. + * void vAFunction( TimerHandle_t xTimer ) + * { + * if( xTimerIsTimerActive( xTimer ) != pdFALSE ) // or more simply and equivalently "if( xTimerIsTimerActive( xTimer ) )" + * { + * // xTimer is active, do something. + * } + * else + * { + * // xTimer is not active, do something else. + * } + * } + * @endverbatim + */ +BaseType_t xTimerIsTimerActive( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION; + +/** + * TaskHandle_t xTimerGetTimerDaemonTaskHandle( void ); + * + * Simply returns the handle of the timer service/daemon task. It it not valid + * to call xTimerGetTimerDaemonTaskHandle() before the scheduler has been started. + */ +TaskHandle_t xTimerGetTimerDaemonTaskHandle( void ) PRIVILEGED_FUNCTION; + +/** + * BaseType_t xTimerStart( TimerHandle_t xTimer, TickType_t xTicksToWait ); + * + * Timer functionality is provided by a timer service/daemon task. Many of the + * public FreeRTOS timer API functions send commands to the timer service task + * through a queue called the timer command queue. The timer command queue is + * private to the kernel itself and is not directly accessible to application + * code. The length of the timer command queue is set by the + * configTIMER_QUEUE_LENGTH configuration constant. + * + * xTimerStart() starts a timer that was previously created using the + * xTimerCreate() API function. If the timer had already been started and was + * already in the active state, then xTimerStart() has equivalent functionality + * to the xTimerReset() API function. + * + * Starting a timer ensures the timer is in the active state. If the timer + * is not stopped, deleted, or reset in the mean time, the callback function + * associated with the timer will get called 'n' ticks after xTimerStart() was + * called, where 'n' is the timers defined period. + * + * It is valid to call xTimerStart() before the scheduler has been started, but + * when this is done the timer will not actually start until the scheduler is + * started, and the timers expiry time will be relative to when the scheduler is + * started, not relative to when xTimerStart() was called. + * + * The configUSE_TIMERS configuration constant must be set to 1 for xTimerStart() + * to be available. + * + * @param xTimer The handle of the timer being started/restarted. + * + * @param xTicksToWait Specifies the time, in ticks, that the calling task should + * be held in the Blocked state to wait for the start command to be successfully + * sent to the timer command queue, should the queue already be full when + * xTimerStart() was called. xTicksToWait is ignored if xTimerStart() is called + * before the scheduler is started. + * + * @return pdFAIL will be returned if the start command could not be sent to + * the timer command queue even after xTicksToWait ticks had passed. pdPASS will + * be returned if the command was successfully sent to the timer command queue. + * When the command is actually processed will depend on the priority of the + * timer service/daemon task relative to other tasks in the system, although the + * timers expiry time is relative to when xTimerStart() is actually called. The + * timer service/daemon task priority is set by the configTIMER_TASK_PRIORITY + * configuration constant. + * + * Example usage: + * + * See the xTimerCreate() API function example usage scenario. + * + */ +#define xTimerStart( xTimer, xTicksToWait ) \ + xTimerGenericCommand( ( xTimer ), tmrCOMMAND_START, ( xTaskGetTickCount() ), NULL, ( xTicksToWait ) ) + +/** + * BaseType_t xTimerStop( TimerHandle_t xTimer, TickType_t xTicksToWait ); + * + * Timer functionality is provided by a timer service/daemon task. Many of the + * public FreeRTOS timer API functions send commands to the timer service task + * through a queue called the timer command queue. The timer command queue is + * private to the kernel itself and is not directly accessible to application + * code. The length of the timer command queue is set by the + * configTIMER_QUEUE_LENGTH configuration constant. + * + * xTimerStop() stops a timer that was previously started using either of the + * The xTimerStart(), xTimerReset(), xTimerStartFromISR(), xTimerResetFromISR(), + * xTimerChangePeriod() or xTimerChangePeriodFromISR() API functions. + * + * Stopping a timer ensures the timer is not in the active state. + * + * The configUSE_TIMERS configuration constant must be set to 1 for xTimerStop() + * to be available. + * + * @param xTimer The handle of the timer being stopped. + * + * @param xTicksToWait Specifies the time, in ticks, that the calling task should + * be held in the Blocked state to wait for the stop command to be successfully + * sent to the timer command queue, should the queue already be full when + * xTimerStop() was called. xTicksToWait is ignored if xTimerStop() is called + * before the scheduler is started. + * + * @return pdFAIL will be returned if the stop command could not be sent to + * the timer command queue even after xTicksToWait ticks had passed. pdPASS will + * be returned if the command was successfully sent to the timer command queue. + * When the command is actually processed will depend on the priority of the + * timer service/daemon task relative to other tasks in the system. The timer + * service/daemon task priority is set by the configTIMER_TASK_PRIORITY + * configuration constant. + * + * Example usage: + * + * See the xTimerCreate() API function example usage scenario. + * + */ +#define xTimerStop( xTimer, xTicksToWait ) \ + xTimerGenericCommand( ( xTimer ), tmrCOMMAND_STOP, 0U, NULL, ( xTicksToWait ) ) + +/** + * BaseType_t xTimerChangePeriod( TimerHandle_t xTimer, + * TickType_t xNewPeriod, + * TickType_t xTicksToWait ); + * + * Timer functionality is provided by a timer service/daemon task. Many of the + * public FreeRTOS timer API functions send commands to the timer service task + * through a queue called the timer command queue. The timer command queue is + * private to the kernel itself and is not directly accessible to application + * code. The length of the timer command queue is set by the + * configTIMER_QUEUE_LENGTH configuration constant. + * + * xTimerChangePeriod() changes the period of a timer that was previously + * created using the xTimerCreate() API function. + * + * xTimerChangePeriod() can be called to change the period of an active or + * dormant state timer. + * + * The configUSE_TIMERS configuration constant must be set to 1 for + * xTimerChangePeriod() to be available. + * + * @param xTimer The handle of the timer that is having its period changed. + * + * @param xNewPeriod The new period for xTimer. Timer periods are specified in + * tick periods, so the constant portTICK_PERIOD_MS can be used to convert a time + * that has been specified in milliseconds. For example, if the timer must + * expire after 100 ticks, then xNewPeriod should be set to 100. Alternatively, + * if the timer must expire after 500ms, then xNewPeriod can be set to + * ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than + * or equal to 1000. + * + * @param xTicksToWait Specifies the time, in ticks, that the calling task should + * be held in the Blocked state to wait for the change period command to be + * successfully sent to the timer command queue, should the queue already be + * full when xTimerChangePeriod() was called. xTicksToWait is ignored if + * xTimerChangePeriod() is called before the scheduler is started. + * + * @return pdFAIL will be returned if the change period command could not be + * sent to the timer command queue even after xTicksToWait ticks had passed. + * pdPASS will be returned if the command was successfully sent to the timer + * command queue. When the command is actually processed will depend on the + * priority of the timer service/daemon task relative to other tasks in the + * system. The timer service/daemon task priority is set by the + * configTIMER_TASK_PRIORITY configuration constant. + * + * Example usage: + * @verbatim + * // This function assumes xTimer has already been created. If the timer + * // referenced by xTimer is already active when it is called, then the timer + * // is deleted. If the timer referenced by xTimer is not active when it is + * // called, then the period of the timer is set to 500ms and the timer is + * // started. + * void vAFunction( TimerHandle_t xTimer ) + * { + * if( xTimerIsTimerActive( xTimer ) != pdFALSE ) // or more simply and equivalently "if( xTimerIsTimerActive( xTimer ) )" + * { + * // xTimer is already active - delete it. + * xTimerDelete( xTimer ); + * } + * else + * { + * // xTimer is not active, change its period to 500ms. This will also + * // cause the timer to start. Block for a maximum of 100 ticks if the + * // change period command cannot immediately be sent to the timer + * // command queue. + * if( xTimerChangePeriod( xTimer, 500 / portTICK_PERIOD_MS, 100 ) == pdPASS ) + * { + * // The command was successfully sent. + * } + * else + * { + * // The command could not be sent, even after waiting for 100 ticks + * // to pass. Take appropriate action here. + * } + * } + * } + * @endverbatim + */ +#define xTimerChangePeriod( xTimer, xNewPeriod, xTicksToWait ) \ + xTimerGenericCommand( ( xTimer ), tmrCOMMAND_CHANGE_PERIOD, ( xNewPeriod ), NULL, ( xTicksToWait ) ) + +/** + * BaseType_t xTimerDelete( TimerHandle_t xTimer, TickType_t xTicksToWait ); + * + * Timer functionality is provided by a timer service/daemon task. Many of the + * public FreeRTOS timer API functions send commands to the timer service task + * through a queue called the timer command queue. The timer command queue is + * private to the kernel itself and is not directly accessible to application + * code. The length of the timer command queue is set by the + * configTIMER_QUEUE_LENGTH configuration constant. + * + * xTimerDelete() deletes a timer that was previously created using the + * xTimerCreate() API function. + * + * The configUSE_TIMERS configuration constant must be set to 1 for + * xTimerDelete() to be available. + * + * @param xTimer The handle of the timer being deleted. + * + * @param xTicksToWait Specifies the time, in ticks, that the calling task should + * be held in the Blocked state to wait for the delete command to be + * successfully sent to the timer command queue, should the queue already be + * full when xTimerDelete() was called. xTicksToWait is ignored if xTimerDelete() + * is called before the scheduler is started. + * + * @return pdFAIL will be returned if the delete command could not be sent to + * the timer command queue even after xTicksToWait ticks had passed. pdPASS will + * be returned if the command was successfully sent to the timer command queue. + * When the command is actually processed will depend on the priority of the + * timer service/daemon task relative to other tasks in the system. The timer + * service/daemon task priority is set by the configTIMER_TASK_PRIORITY + * configuration constant. + * + * Example usage: + * + * See the xTimerChangePeriod() API function example usage scenario. + */ +#define xTimerDelete( xTimer, xTicksToWait ) \ + xTimerGenericCommand( ( xTimer ), tmrCOMMAND_DELETE, 0U, NULL, ( xTicksToWait ) ) + +/** + * BaseType_t xTimerReset( TimerHandle_t xTimer, TickType_t xTicksToWait ); + * + * Timer functionality is provided by a timer service/daemon task. Many of the + * public FreeRTOS timer API functions send commands to the timer service task + * through a queue called the timer command queue. The timer command queue is + * private to the kernel itself and is not directly accessible to application + * code. The length of the timer command queue is set by the + * configTIMER_QUEUE_LENGTH configuration constant. + * + * xTimerReset() re-starts a timer that was previously created using the + * xTimerCreate() API function. If the timer had already been started and was + * already in the active state, then xTimerReset() will cause the timer to + * re-evaluate its expiry time so that it is relative to when xTimerReset() was + * called. If the timer was in the dormant state then xTimerReset() has + * equivalent functionality to the xTimerStart() API function. + * + * Resetting a timer ensures the timer is in the active state. If the timer + * is not stopped, deleted, or reset in the mean time, the callback function + * associated with the timer will get called 'n' ticks after xTimerReset() was + * called, where 'n' is the timers defined period. + * + * It is valid to call xTimerReset() before the scheduler has been started, but + * when this is done the timer will not actually start until the scheduler is + * started, and the timers expiry time will be relative to when the scheduler is + * started, not relative to when xTimerReset() was called. + * + * The configUSE_TIMERS configuration constant must be set to 1 for xTimerReset() + * to be available. + * + * @param xTimer The handle of the timer being reset/started/restarted. + * + * @param xTicksToWait Specifies the time, in ticks, that the calling task should + * be held in the Blocked state to wait for the reset command to be successfully + * sent to the timer command queue, should the queue already be full when + * xTimerReset() was called. xTicksToWait is ignored if xTimerReset() is called + * before the scheduler is started. + * + * @return pdFAIL will be returned if the reset command could not be sent to + * the timer command queue even after xTicksToWait ticks had passed. pdPASS will + * be returned if the command was successfully sent to the timer command queue. + * When the command is actually processed will depend on the priority of the + * timer service/daemon task relative to other tasks in the system, although the + * timers expiry time is relative to when xTimerStart() is actually called. The + * timer service/daemon task priority is set by the configTIMER_TASK_PRIORITY + * configuration constant. + * + * Example usage: + * @verbatim + * // When a key is pressed, an LCD back-light is switched on. If 5 seconds pass + * // without a key being pressed, then the LCD back-light is switched off. In + * // this case, the timer is a one-shot timer. + * + * TimerHandle_t xBacklightTimer = NULL; + * + * // The callback function assigned to the one-shot timer. In this case the + * // parameter is not used. + * void vBacklightTimerCallback( TimerHandle_t pxTimer ) + * { + * // The timer expired, therefore 5 seconds must have passed since a key + * // was pressed. Switch off the LCD back-light. + * vSetBacklightState( BACKLIGHT_OFF ); + * } + * + * // The key press event handler. + * void vKeyPressEventHandler( char cKey ) + * { + * // Ensure the LCD back-light is on, then reset the timer that is + * // responsible for turning the back-light off after 5 seconds of + * // key inactivity. Wait 10 ticks for the command to be successfully sent + * // if it cannot be sent immediately. + * vSetBacklightState( BACKLIGHT_ON ); + * if( xTimerReset( xBacklightTimer, 100 ) != pdPASS ) + * { + * // The reset command was not executed successfully. Take appropriate + * // action here. + * } + * + * // Perform the rest of the key processing here. + * } + * + * void main( void ) + * { + * int32_t x; + * + * // Create then start the one-shot timer that is responsible for turning + * // the back-light off if no keys are pressed within a 5 second period. + * xBacklightTimer = xTimerCreate( "BacklightTimer", // Just a text name, not used by the kernel. + * ( 5000 / portTICK_PERIOD_MS), // The timer period in ticks. + * pdFALSE, // The timer is a one-shot timer. + * 0, // The id is not used by the callback so can take any value. + * vBacklightTimerCallback // The callback function that switches the LCD back-light off. + * ); + * + * if( xBacklightTimer == NULL ) + * { + * // The timer was not created. + * } + * else + * { + * // Start the timer. No block time is specified, and even if one was + * // it would be ignored because the scheduler has not yet been + * // started. + * if( xTimerStart( xBacklightTimer, 0 ) != pdPASS ) + * { + * // The timer could not be set into the Active state. + * } + * } + * + * // ... + * // Create tasks here. + * // ... + * + * // Starting the scheduler will start the timer running as it has already + * // been set into the active state. + * vTaskStartScheduler(); + * + * // Should not reach here. + * for( ;; ); + * } + * @endverbatim + */ +#define xTimerReset( xTimer, xTicksToWait ) \ + xTimerGenericCommand( ( xTimer ), tmrCOMMAND_RESET, ( xTaskGetTickCount() ), NULL, ( xTicksToWait ) ) + +/** + * BaseType_t xTimerStartFromISR( TimerHandle_t xTimer, + * BaseType_t *pxHigherPriorityTaskWoken ); + * + * A version of xTimerStart() that can be called from an interrupt service + * routine. + * + * @param xTimer The handle of the timer being started/restarted. + * + * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most + * of its time in the Blocked state, waiting for messages to arrive on the timer + * command queue. Calling xTimerStartFromISR() writes a message to the timer + * command queue, so has the potential to transition the timer service/daemon + * task out of the Blocked state. If calling xTimerStartFromISR() causes the + * timer service/daemon task to leave the Blocked state, and the timer service/ + * daemon task has a priority equal to or greater than the currently executing + * task (the task that was interrupted), then *pxHigherPriorityTaskWoken will + * get set to pdTRUE internally within the xTimerStartFromISR() function. If + * xTimerStartFromISR() sets this value to pdTRUE then a context switch should + * be performed before the interrupt exits. + * + * @return pdFAIL will be returned if the start command could not be sent to + * the timer command queue. pdPASS will be returned if the command was + * successfully sent to the timer command queue. When the command is actually + * processed will depend on the priority of the timer service/daemon task + * relative to other tasks in the system, although the timers expiry time is + * relative to when xTimerStartFromISR() is actually called. The timer + * service/daemon task priority is set by the configTIMER_TASK_PRIORITY + * configuration constant. + * + * Example usage: + * @verbatim + * // This scenario assumes xBacklightTimer has already been created. When a + * // key is pressed, an LCD back-light is switched on. If 5 seconds pass + * // without a key being pressed, then the LCD back-light is switched off. In + * // this case, the timer is a one-shot timer, and unlike the example given for + * // the xTimerReset() function, the key press event handler is an interrupt + * // service routine. + * + * // The callback function assigned to the one-shot timer. In this case the + * // parameter is not used. + * void vBacklightTimerCallback( TimerHandle_t pxTimer ) + * { + * // The timer expired, therefore 5 seconds must have passed since a key + * // was pressed. Switch off the LCD back-light. + * vSetBacklightState( BACKLIGHT_OFF ); + * } + * + * // The key press interrupt service routine. + * void vKeyPressEventInterruptHandler( void ) + * { + * BaseType_t xHigherPriorityTaskWoken = pdFALSE; + * + * // Ensure the LCD back-light is on, then restart the timer that is + * // responsible for turning the back-light off after 5 seconds of + * // key inactivity. This is an interrupt service routine so can only + * // call FreeRTOS API functions that end in "FromISR". + * vSetBacklightState( BACKLIGHT_ON ); + * + * // xTimerStartFromISR() or xTimerResetFromISR() could be called here + * // as both cause the timer to re-calculate its expiry time. + * // xHigherPriorityTaskWoken was initialised to pdFALSE when it was + * // declared (in this function). + * if( xTimerStartFromISR( xBacklightTimer, &xHigherPriorityTaskWoken ) != pdPASS ) + * { + * // The start command was not executed successfully. Take appropriate + * // action here. + * } + * + * // Perform the rest of the key processing here. + * + * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch + * // should be performed. The syntax required to perform a context switch + * // from inside an ISR varies from port to port, and from compiler to + * // compiler. Inspect the demos for the port you are using to find the + * // actual syntax required. + * if( xHigherPriorityTaskWoken != pdFALSE ) + * { + * // Call the interrupt safe yield function here (actual function + * // depends on the FreeRTOS port being used). + * } + * } + * @endverbatim + */ +#define xTimerStartFromISR( xTimer, pxHigherPriorityTaskWoken ) \ + xTimerGenericCommand( ( xTimer ), tmrCOMMAND_START_FROM_ISR, ( xTaskGetTickCountFromISR() ), ( pxHigherPriorityTaskWoken ), 0U ) + +/** + * BaseType_t xTimerStopFromISR( TimerHandle_t xTimer, + * BaseType_t *pxHigherPriorityTaskWoken ); + * + * A version of xTimerStop() that can be called from an interrupt service + * routine. + * + * @param xTimer The handle of the timer being stopped. + * + * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most + * of its time in the Blocked state, waiting for messages to arrive on the timer + * command queue. Calling xTimerStopFromISR() writes a message to the timer + * command queue, so has the potential to transition the timer service/daemon + * task out of the Blocked state. If calling xTimerStopFromISR() causes the + * timer service/daemon task to leave the Blocked state, and the timer service/ + * daemon task has a priority equal to or greater than the currently executing + * task (the task that was interrupted), then *pxHigherPriorityTaskWoken will + * get set to pdTRUE internally within the xTimerStopFromISR() function. If + * xTimerStopFromISR() sets this value to pdTRUE then a context switch should + * be performed before the interrupt exits. + * + * @return pdFAIL will be returned if the stop command could not be sent to + * the timer command queue. pdPASS will be returned if the command was + * successfully sent to the timer command queue. When the command is actually + * processed will depend on the priority of the timer service/daemon task + * relative to other tasks in the system. The timer service/daemon task + * priority is set by the configTIMER_TASK_PRIORITY configuration constant. + * + * Example usage: + * @verbatim + * // This scenario assumes xTimer has already been created and started. When + * // an interrupt occurs, the timer should be simply stopped. + * + * // The interrupt service routine that stops the timer. + * void vAnExampleInterruptServiceRoutine( void ) + * { + * BaseType_t xHigherPriorityTaskWoken = pdFALSE; + * + * // The interrupt has occurred - simply stop the timer. + * // xHigherPriorityTaskWoken was set to pdFALSE where it was defined + * // (within this function). As this is an interrupt service routine, only + * // FreeRTOS API functions that end in "FromISR" can be used. + * if( xTimerStopFromISR( xTimer, &xHigherPriorityTaskWoken ) != pdPASS ) + * { + * // The stop command was not executed successfully. Take appropriate + * // action here. + * } + * + * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch + * // should be performed. The syntax required to perform a context switch + * // from inside an ISR varies from port to port, and from compiler to + * // compiler. Inspect the demos for the port you are using to find the + * // actual syntax required. + * if( xHigherPriorityTaskWoken != pdFALSE ) + * { + * // Call the interrupt safe yield function here (actual function + * // depends on the FreeRTOS port being used). + * } + * } + * @endverbatim + */ +#define xTimerStopFromISR( xTimer, pxHigherPriorityTaskWoken ) \ + xTimerGenericCommand( ( xTimer ), tmrCOMMAND_STOP_FROM_ISR, 0, ( pxHigherPriorityTaskWoken ), 0U ) + +/** + * BaseType_t xTimerChangePeriodFromISR( TimerHandle_t xTimer, + * TickType_t xNewPeriod, + * BaseType_t *pxHigherPriorityTaskWoken ); + * + * A version of xTimerChangePeriod() that can be called from an interrupt + * service routine. + * + * @param xTimer The handle of the timer that is having its period changed. + * + * @param xNewPeriod The new period for xTimer. Timer periods are specified in + * tick periods, so the constant portTICK_PERIOD_MS can be used to convert a time + * that has been specified in milliseconds. For example, if the timer must + * expire after 100 ticks, then xNewPeriod should be set to 100. Alternatively, + * if the timer must expire after 500ms, then xNewPeriod can be set to + * ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than + * or equal to 1000. + * + * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most + * of its time in the Blocked state, waiting for messages to arrive on the timer + * command queue. Calling xTimerChangePeriodFromISR() writes a message to the + * timer command queue, so has the potential to transition the timer service/ + * daemon task out of the Blocked state. If calling xTimerChangePeriodFromISR() + * causes the timer service/daemon task to leave the Blocked state, and the + * timer service/daemon task has a priority equal to or greater than the + * currently executing task (the task that was interrupted), then + * *pxHigherPriorityTaskWoken will get set to pdTRUE internally within the + * xTimerChangePeriodFromISR() function. If xTimerChangePeriodFromISR() sets + * this value to pdTRUE then a context switch should be performed before the + * interrupt exits. + * + * @return pdFAIL will be returned if the command to change the timers period + * could not be sent to the timer command queue. pdPASS will be returned if the + * command was successfully sent to the timer command queue. When the command + * is actually processed will depend on the priority of the timer service/daemon + * task relative to other tasks in the system. The timer service/daemon task + * priority is set by the configTIMER_TASK_PRIORITY configuration constant. + * + * Example usage: + * @verbatim + * // This scenario assumes xTimer has already been created and started. When + * // an interrupt occurs, the period of xTimer should be changed to 500ms. + * + * // The interrupt service routine that changes the period of xTimer. + * void vAnExampleInterruptServiceRoutine( void ) + * { + * BaseType_t xHigherPriorityTaskWoken = pdFALSE; + * + * // The interrupt has occurred - change the period of xTimer to 500ms. + * // xHigherPriorityTaskWoken was set to pdFALSE where it was defined + * // (within this function). As this is an interrupt service routine, only + * // FreeRTOS API functions that end in "FromISR" can be used. + * if( xTimerChangePeriodFromISR( xTimer, &xHigherPriorityTaskWoken ) != pdPASS ) + * { + * // The command to change the timers period was not executed + * // successfully. Take appropriate action here. + * } + * + * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch + * // should be performed. The syntax required to perform a context switch + * // from inside an ISR varies from port to port, and from compiler to + * // compiler. Inspect the demos for the port you are using to find the + * // actual syntax required. + * if( xHigherPriorityTaskWoken != pdFALSE ) + * { + * // Call the interrupt safe yield function here (actual function + * // depends on the FreeRTOS port being used). + * } + * } + * @endverbatim + */ +#define xTimerChangePeriodFromISR( xTimer, xNewPeriod, pxHigherPriorityTaskWoken ) \ + xTimerGenericCommand( ( xTimer ), tmrCOMMAND_CHANGE_PERIOD_FROM_ISR, ( xNewPeriod ), ( pxHigherPriorityTaskWoken ), 0U ) + +/** + * BaseType_t xTimerResetFromISR( TimerHandle_t xTimer, + * BaseType_t *pxHigherPriorityTaskWoken ); + * + * A version of xTimerReset() that can be called from an interrupt service + * routine. + * + * @param xTimer The handle of the timer that is to be started, reset, or + * restarted. + * + * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most + * of its time in the Blocked state, waiting for messages to arrive on the timer + * command queue. Calling xTimerResetFromISR() writes a message to the timer + * command queue, so has the potential to transition the timer service/daemon + * task out of the Blocked state. If calling xTimerResetFromISR() causes the + * timer service/daemon task to leave the Blocked state, and the timer service/ + * daemon task has a priority equal to or greater than the currently executing + * task (the task that was interrupted), then *pxHigherPriorityTaskWoken will + * get set to pdTRUE internally within the xTimerResetFromISR() function. If + * xTimerResetFromISR() sets this value to pdTRUE then a context switch should + * be performed before the interrupt exits. + * + * @return pdFAIL will be returned if the reset command could not be sent to + * the timer command queue. pdPASS will be returned if the command was + * successfully sent to the timer command queue. When the command is actually + * processed will depend on the priority of the timer service/daemon task + * relative to other tasks in the system, although the timers expiry time is + * relative to when xTimerResetFromISR() is actually called. The timer service/daemon + * task priority is set by the configTIMER_TASK_PRIORITY configuration constant. + * + * Example usage: + * @verbatim + * // This scenario assumes xBacklightTimer has already been created. When a + * // key is pressed, an LCD back-light is switched on. If 5 seconds pass + * // without a key being pressed, then the LCD back-light is switched off. In + * // this case, the timer is a one-shot timer, and unlike the example given for + * // the xTimerReset() function, the key press event handler is an interrupt + * // service routine. + * + * // The callback function assigned to the one-shot timer. In this case the + * // parameter is not used. + * void vBacklightTimerCallback( TimerHandle_t pxTimer ) + * { + * // The timer expired, therefore 5 seconds must have passed since a key + * // was pressed. Switch off the LCD back-light. + * vSetBacklightState( BACKLIGHT_OFF ); + * } + * + * // The key press interrupt service routine. + * void vKeyPressEventInterruptHandler( void ) + * { + * BaseType_t xHigherPriorityTaskWoken = pdFALSE; + * + * // Ensure the LCD back-light is on, then reset the timer that is + * // responsible for turning the back-light off after 5 seconds of + * // key inactivity. This is an interrupt service routine so can only + * // call FreeRTOS API functions that end in "FromISR". + * vSetBacklightState( BACKLIGHT_ON ); + * + * // xTimerStartFromISR() or xTimerResetFromISR() could be called here + * // as both cause the timer to re-calculate its expiry time. + * // xHigherPriorityTaskWoken was initialised to pdFALSE when it was + * // declared (in this function). + * if( xTimerResetFromISR( xBacklightTimer, &xHigherPriorityTaskWoken ) != pdPASS ) + * { + * // The reset command was not executed successfully. Take appropriate + * // action here. + * } + * + * // Perform the rest of the key processing here. + * + * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch + * // should be performed. The syntax required to perform a context switch + * // from inside an ISR varies from port to port, and from compiler to + * // compiler. Inspect the demos for the port you are using to find the + * // actual syntax required. + * if( xHigherPriorityTaskWoken != pdFALSE ) + * { + * // Call the interrupt safe yield function here (actual function + * // depends on the FreeRTOS port being used). + * } + * } + * @endverbatim + */ +#define xTimerResetFromISR( xTimer, pxHigherPriorityTaskWoken ) \ + xTimerGenericCommand( ( xTimer ), tmrCOMMAND_RESET_FROM_ISR, ( xTaskGetTickCountFromISR() ), ( pxHigherPriorityTaskWoken ), 0U ) + + +/** + * BaseType_t xTimerPendFunctionCallFromISR( PendedFunction_t xFunctionToPend, + * void *pvParameter1, + * uint32_t ulParameter2, + * BaseType_t *pxHigherPriorityTaskWoken ); + * + * + * Used from application interrupt service routines to defer the execution of a + * function to the RTOS daemon task (the timer service task, hence this function + * is implemented in timers.c and is prefixed with 'Timer'). + * + * Ideally an interrupt service routine (ISR) is kept as short as possible, but + * sometimes an ISR either has a lot of processing to do, or needs to perform + * processing that is not deterministic. In these cases + * xTimerPendFunctionCallFromISR() can be used to defer processing of a function + * to the RTOS daemon task. + * + * A mechanism is provided that allows the interrupt to return directly to the + * task that will subsequently execute the pended callback function. This + * allows the callback function to execute contiguously in time with the + * interrupt - just as if the callback had executed in the interrupt itself. + * + * @param xFunctionToPend The function to execute from the timer service/ + * daemon task. The function must conform to the PendedFunction_t + * prototype. + * + * @param pvParameter1 The value of the callback function's first parameter. + * The parameter has a void * type to allow it to be used to pass any type. + * For example, unsigned longs can be cast to a void *, or the void * can be + * used to point to a structure. + * + * @param ulParameter2 The value of the callback function's second parameter. + * + * @param pxHigherPriorityTaskWoken As mentioned above, calling this function + * will result in a message being sent to the timer daemon task. If the + * priority of the timer daemon task (which is set using + * configTIMER_TASK_PRIORITY in FreeRTOSConfig.h) is higher than the priority of + * the currently running task (the task the interrupt interrupted) then + * *pxHigherPriorityTaskWoken will be set to pdTRUE within + * xTimerPendFunctionCallFromISR(), indicating that a context switch should be + * requested before the interrupt exits. For that reason + * *pxHigherPriorityTaskWoken must be initialised to pdFALSE. See the + * example code below. + * + * @return pdPASS is returned if the message was successfully sent to the + * timer daemon task, otherwise pdFALSE is returned. + * + * Example usage: + * @verbatim + * + * // The callback function that will execute in the context of the daemon task. + * // Note callback functions must all use this same prototype. + * void vProcessInterface( void *pvParameter1, uint32_t ulParameter2 ) + * { + * BaseType_t xInterfaceToService; + * + * // The interface that requires servicing is passed in the second + * // parameter. The first parameter is not used in this case. + * xInterfaceToService = ( BaseType_t ) ulParameter2; + * + * // ...Perform the processing here... + * } + * + * // An ISR that receives data packets from multiple interfaces + * void vAnISR( void ) + * { + * BaseType_t xInterfaceToService, xHigherPriorityTaskWoken; + * + * // Query the hardware to determine which interface needs processing. + * xInterfaceToService = prvCheckInterfaces(); + * + * // The actual processing is to be deferred to a task. Request the + * // vProcessInterface() callback function is executed, passing in the + * // number of the interface that needs processing. The interface to + * // service is passed in the second parameter. The first parameter is + * // not used in this case. + * xHigherPriorityTaskWoken = pdFALSE; + * xTimerPendFunctionCallFromISR( vProcessInterface, NULL, ( uint32_t ) xInterfaceToService, &xHigherPriorityTaskWoken ); + * + * // If xHigherPriorityTaskWoken is now set to pdTRUE then a context + * // switch should be requested. The macro used is port specific and will + * // be either portYIELD_FROM_ISR() or portEND_SWITCHING_ISR() - refer to + * // the documentation page for the port being used. + * portYIELD_FROM_ISR( xHigherPriorityTaskWoken ); + * + * } + * @endverbatim + */ +BaseType_t xTimerPendFunctionCallFromISR( PendedFunction_t xFunctionToPend, + void * pvParameter1, + uint32_t ulParameter2, + BaseType_t * pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION; + +/** + * BaseType_t xTimerPendFunctionCall( PendedFunction_t xFunctionToPend, + * void *pvParameter1, + * uint32_t ulParameter2, + * TickType_t xTicksToWait ); + * + * + * Used to defer the execution of a function to the RTOS daemon task (the timer + * service task, hence this function is implemented in timers.c and is prefixed + * with 'Timer'). + * + * @param xFunctionToPend The function to execute from the timer service/ + * daemon task. The function must conform to the PendedFunction_t + * prototype. + * + * @param pvParameter1 The value of the callback function's first parameter. + * The parameter has a void * type to allow it to be used to pass any type. + * For example, unsigned longs can be cast to a void *, or the void * can be + * used to point to a structure. + * + * @param ulParameter2 The value of the callback function's second parameter. + * + * @param xTicksToWait Calling this function will result in a message being + * sent to the timer daemon task on a queue. xTicksToWait is the amount of + * time the calling task should remain in the Blocked state (so not using any + * processing time) for space to become available on the timer queue if the + * queue is found to be full. + * + * @return pdPASS is returned if the message was successfully sent to the + * timer daemon task, otherwise pdFALSE is returned. + * + */ +BaseType_t xTimerPendFunctionCall( PendedFunction_t xFunctionToPend, + void * pvParameter1, + uint32_t ulParameter2, + TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; + +/** + * const char * const pcTimerGetName( TimerHandle_t xTimer ); + * + * Returns the name that was assigned to a timer when the timer was created. + * + * @param xTimer The handle of the timer being queried. + * + * @return The name assigned to the timer specified by the xTimer parameter. + */ +const char * pcTimerGetName( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + +/** + * void vTimerSetReloadMode( TimerHandle_t xTimer, const UBaseType_t uxAutoReload ); + * + * Updates a timer to be either an auto-reload timer, in which case the timer + * automatically resets itself each time it expires, or a one-shot timer, in + * which case the timer will only expire once unless it is manually restarted. + * + * @param xTimer The handle of the timer being updated. + * + * @param uxAutoReload If uxAutoReload is set to pdTRUE then the timer will + * expire repeatedly with a frequency set by the timer's period (see the + * xTimerPeriodInTicks parameter of the xTimerCreate() API function). If + * uxAutoReload is set to pdFALSE then the timer will be a one-shot timer and + * enter the dormant state after it expires. + */ +void vTimerSetReloadMode( TimerHandle_t xTimer, + const UBaseType_t uxAutoReload ) PRIVILEGED_FUNCTION; + +/** + * UBaseType_t uxTimerGetReloadMode( TimerHandle_t xTimer ); + * + * Queries a timer to determine if it is an auto-reload timer, in which case the timer + * automatically resets itself each time it expires, or a one-shot timer, in + * which case the timer will only expire once unless it is manually restarted. + * + * @param xTimer The handle of the timer being queried. + * + * @return If the timer is an auto-reload timer then pdTRUE is returned, otherwise + * pdFALSE is returned. + */ +UBaseType_t uxTimerGetReloadMode( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION; + +/** + * TickType_t xTimerGetPeriod( TimerHandle_t xTimer ); + * + * Returns the period of a timer. + * + * @param xTimer The handle of the timer being queried. + * + * @return The period of the timer in ticks. + */ +TickType_t xTimerGetPeriod( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION; + +/** + * TickType_t xTimerGetExpiryTime( TimerHandle_t xTimer ); + * + * Returns the time in ticks at which the timer will expire. If this is less + * than the current tick count then the expiry time has overflowed from the + * current time. + * + * @param xTimer The handle of the timer being queried. + * + * @return If the timer is running then the time in ticks at which the timer + * will next expire is returned. If the timer is not running then the return + * value is undefined. + */ +TickType_t xTimerGetExpiryTime( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION; + +/* + * Functions beyond this part are not part of the public API and are intended + * for use by the kernel only. + */ +BaseType_t xTimerCreateTimerTask( void ) PRIVILEGED_FUNCTION; +BaseType_t xTimerGenericCommand( TimerHandle_t xTimer, + const BaseType_t xCommandID, + const TickType_t xOptionalValue, + BaseType_t * const pxHigherPriorityTaskWoken, + const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; + +#if ( configUSE_TRACE_FACILITY == 1 ) + void vTimerSetTimerNumber( TimerHandle_t xTimer, + UBaseType_t uxTimerNumber ) PRIVILEGED_FUNCTION; + UBaseType_t uxTimerGetTimerNumber( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION; +#endif + +#if ( configSUPPORT_STATIC_ALLOCATION == 1 ) + + /** + * task.h + *
void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer, StackType_t ** ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize ) 
+ * + * This function is used to provide a statically allocated block of memory to FreeRTOS to hold the Timer Task TCB. This function is required when + * configSUPPORT_STATIC_ALLOCATION is set. For more information see this URI: https://www.FreeRTOS.org/a00110.html#configSUPPORT_STATIC_ALLOCATION + * + * @param ppxTimerTaskTCBBuffer A handle to a statically allocated TCB buffer + * @param ppxTimerTaskStackBuffer A handle to a statically allocated Stack buffer for thie idle task + * @param pulTimerTaskStackSize A pointer to the number of elements that will fit in the allocated stack buffer + */ + void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer, + StackType_t ** ppxTimerTaskStackBuffer, + uint32_t * pulTimerTaskStackSize ); + +#endif + +/* *INDENT-OFF* */ +#ifdef __cplusplus + } +#endif +/* *INDENT-ON* */ +#endif /* TIMERS_H */ diff --git a/RTOS/FreeRTOS/Source/lexicon.txt b/RTOS/FreeRTOS/Source/lexicon.txt new file mode 100644 index 0000000..8cb6e9f --- /dev/null +++ b/RTOS/FreeRTOS/Source/lexicon.txt @@ -0,0 +1,3082 @@ +aa +aaaa +aarch +aasr +ab +abetrg +abi +abis +abm +absr +abtsz +abttyp +ac +acc +accah +accal +accau +accbh +accbl +accbu +aclk +acpa +acpc +acr +adb +adc +addi +addr +adtrg +aeevt +aerr +aes +afunction +aic +aircr +aka +al +almien +almv +alt +altera +amd +amessage +aninterrupthandler +ansi +api +apic +apis +app +appnote +apr +apsr +arblst +aren +arg +armcc +armv +arp +asa +ascii +asm +asmlanguage +asr +aswtrg +asy +async +atask +atmega +atmel +attr +attrib +aug +autobaud +avioid +avr +aws +axi +backchain +backlight +backlighttimer +backtrace +backtraces +barry +basepri +basetype +baudrate +bb +bbbb +bc +bcpb +bcpc +bcr +beene +beevt +behaviour +beq +berr +bex +bfextu +bgie +bic +bics +bisr +bitfields +bitmask +bitmasks +bitscanreverse +bk +bl +blocklink +bmr +bna +bodien +bodsts +boff +borland +boston +bp +bpl +br +brd +brgr +brp +bsp +bspiy +bsr +bswtrg +bt +btmr +btr +bufferable +bx +cacheability +cacheable +caf +calg +callinc +callout +callouts +callreturn +callsv +cambridge +canen +canrx +cantx +cas +cbc +cbmc +cbz +cc +cccc +cchar +cchartotx +ccnt +ccntr +ccount +ccp +ccpn +ccr +cdc +cdr +cdt +cdty +cdtyr +ce +cee +ceo +cerr +cf +cfb +cfbs +cfg +cfgbaudratereg +cfgchannel +cfgcs +cfgdirectdrive +cfginput +cfginputfilter +cfgmainoscillatorreg +cfgmainoscstartuptime +cfgmckreg +cfgmessageacceptancemaskreg +cfgmessagectrl +cfgmessagectrlreg +cfgmessagedatahigh +cfgmessagedatalow +cfgmessageidreg +cfgmessagemodereg +cfgmode +cfgmodereg +cfgopendrain +cfgoutput +cfgpcs +cfgperiph +cfgpio +cfgpmc +cfgpullup +cfgsysclkdisablereg +cfgsysclkenablereg +cfgtimings +ch +channelid +chdiv +chdr +cher +chid +chmode +christian +chrl +chsr +cidr +cin +cisr +ckdiv +ckey +ckg +ckgr +cki +cklo +cko +ckps +cks +cldiv +clearalarmint +clearit +clearoutput +clearrttincint +cledtoflash +clib +clint +clk +clka +clkb +clkdis +clken +clki +clkp +clks +clksta +clkx +closk +clr +clrstat +cmcon +cmd +cmp +cmr +cmsis +cmt +cnte +co +coalescences +codan +codr +col +coldfire +com +comm +comp +compiletime +compsel +computefmcn +conbits +cond +confg +config +configapic +configapplication +configassert +configbenchmark +configcall +configcheck +configclear +configclint +configcpu +configdata +configdbg +configenable +configenforce +configgenerate +configidle +configinclude +configinstall +configinterrupt +configinttimer +configisr +configkernel +configlist +configmax +configmemmodel +configminimal +configmtime +configmtimecmp +confignum +configoverride +configpre +configprecondition +configprintf +configqueue +configrecord +configrun +configsetup +configstack +configsupport +configtask +configtick +configtimer +configtotal +configunique +configurator +configureit +configuse +configxt +configyield +conifgassert +conifgsupport +const +coproc +coprocessor +coprocessors +coreid +coroutinehandle +covfs +cp +cpacr +cpas +cpbs +cpcdis +cpcs +cpcstop +cpctrg +cpd +cpenable +cpiv +cpol +cpp +cprd +cprdr +cpre +cprivilegedonlyaccessarray +cpsid +cpsie +cpsr +cpstored +cpu +cr +crc +crcb +crcoroutine +crdelay +creadonlyarray +creadwritearray +createevent +crend +crgint +croutine +crqueue +crstart +crt +crtv +crxedchar +crxlock +csa +csaat +csas +cse +csl +csr +csrr +csrs +css +cstackbuffer +cstart +cstatus +ctaskwokenbypost +ctaskwokenbyreceive +ctcr +ctor +ctr +ctrl +cts +ctsic +ctx +ctxlock +ctype +cupd +cupdr +cv +cvaluetopost +cvs +cwgr +cx +cy +cygnal +dadr +daemontaskmessage +daif +dat +datar +datas +datasheet +dataw +datdef +datlen +datnb +datproc +datrdy +dbgu +dc +dcd +dcdic +dcmr +dcount +dcr +dddd +de +decnt +deedmed +defaulthandler +defgroup +denormal +des +devblogs +di +didn +dir +directdrive +disablecan +disablechannel +disableep +disableit +disablemainoscillator +disablepck +disableperiphclock +disablerx +disabletx +div +divb +dlybcs +dlybct +dlybs +dma +dmb +docount +doendh +doendl +doesn +dohigh +dolow +dont +dostarth +dostartl +downgrowing +doxygen +dpfpu +dph +dpl +dplb +dpr +dpsw +dptr +dr +drdy +drfcs +drived +drpt +drxd +ds +dsb +dsnack +dsp +dspcontrol +dspic +dsr +dsric +dsync +dtb +dtf +dtgle +dtr +dtrdis +dtren +dtxd +dx +dxt +eabi +eabortsleep +eacces +eaction +eaddrinuse +eaddrnotavail +eae +eagain +ealready +eax +ebade +ebadf +eblocked +ebook +ebp +ebusy +ebx +ec +ecanceled +ecb +ecol +ecr +ecrs +ecrsdv +ecurrentstate +edc +edeleted +edi +eds +edx +ee +eeee +eevt +eevtedg +eexist +ef +efault +efc +effecti +eflags +efrhd +eftype +eg +eic +eilseq +eincrement +eind +einprogress +eintr +einval +einvalid +eio +eisconn +eisdir +ele +elif +emac +emacb +emaclite +embarc +emdc +emdio +empted +emption +emptive +en +ena +enablecan +enablechannel +enableep +enableit +enablemainoscillator +enablepck +enableperiphclock +enablerx +enabletx +enametoolong +endbusres +endian +endif +endinit +endint +endrx +endtx +endverbatim +enetrg +enmfile +enoaction +enobufs +enodev +enoent +enomedium +enomem +enoprotoopt +enospc +enotaskswaitingtimeout +enotconn +enotdir +enotempty +enotifyaction +enotwaitingnotification +entrypoint +enums +enxio +eoc +eoi +eoicr +eopnotsupp +ep +epage +epc +epclear +epeds +ependofwr +epint +epread +epset +epstall +epstatus +eptype +epwrite +eq +eqif +eqmk +er +eready +erefck +erl +erofs +erra +errno +errp +errqueue +erstl +erunning +erx +erxck +erxdv +erxer +esetbits +esetvaluewithoutoverwrite +esetvaluewithoverwrite +esi +esp +espeche +espipe +espressif +esr +estandardsleep +esuspended +etaskconfirmsleepmodestatus +etaskgetstate +etaskstate +ethernet +etimedout +etrcs +etrgedg +etrgs +etx +etxck +etxen +etxer +eunatch +europe +eventbits +eventclear +eventgroup +eventgrouphandle +eventunblocked +evt +ewavr +ewouldblock +exc +exccause +excm +exdev +exid +exl +ext +extrsm +extrst +fadd +fadden +faddr +faq +faqhelp +favour +fc +fcmd +fcr +fcs +fcse +fcx +fd +fdiv +fdr +feb +fedc +ferr +ff +ffdr +ffer +fff +ffff +ffffff +ffsr +fful +fi +fidi +fifo +fina +fiq +fiqhandler +firq +fixme +flashlite +fmcn +fmr +fn +fnsave +fntr +forceoutput +forcestall +fp +fpccr +fpga +fpi +fpr +fpscr +fpsr +fpsw +fpu +fpul +fputs +frameless +framepointer +frdy +freertos +freertosconfig +freertosintro +freq +fri +frm +frmsz +fromisr +fron +frxt +fsave +fsden +fsedge +fsl +fslen +fsos +fsr +fto +fujitsu +functionname +functionparameter +functionpointers +fvr +fws +fx +gbr +gc +gcacc +gcc +gdb +genration +gens +getalarmvalue +getbaudrate +getcfgpullup +getchannelstatus +getchar +getconverteddatach +geterrorcounter +getfamilyid +getinput +getinputfilterstatus +getinternalcounter +getinterruptmaskstatus +getinterruptstatus +getlastconverteddata +getmainclock +getmainclockfreqreg +getmainoscillatorreg +getmasterclock +getmckreg +getmessageacceptancemaskreg +getmessagedatahigh +getmessagedatalow +getmessageidreg +getmessagemodereg +getmessagestatus +getmodereg +getmultidriverstatus +getoutputdata +getoutputdatastatus +getoutputstatus +getoutputwritestatus +getperiphclock +getstate +getstatus +getsysclkstatusreg +gettimestamp +gic +gics +girq +girqn +github +gl +glb +glbstate +gm +gmbh +gmsk +gnuc +govre +gp +gpio +gpl +gpnvm +gpta +gre +hackery +hal +hardwware +hartid +hclk +hcs +heapregion +heapregions +heapstats +heep +hl +hrb +hresp +hrt +html +http +https +hw +hwhsh +hword +hz +iadr +iadrsz +iar +ic +iccarm +iccbpr +iccpmr +iccr +icerst +icr +icsr +idataxr +idcr +idf +idr +idt +idva +idvb +ie +iecr +ier +ifdef +ifdr +ifer +iff +iflash +ifndef +ifsr +ilm +impl +imr +inack +inb +inc +incstat +indata +ingroup +init +initabortrequest +initialisation +initialise +initialised +initialises +initialising +initmailboxregisters +inittransferrequest +initvector +inlined +inputdata +inputenable +inputfilter +inputfilterdisable +inputfilterenable +inpw +instate +int +intc +intcon +inte +interrpts +interruptcall +interruptdisable +interruptee +interruptenable +interruptnesting +interruptpriorities +interruptsources +interruptstatus +interwork +intexc +intfrcl +inti +intit +intlevel +intno +intr +inttm +io +iodefine +ip +ipl +iplb +ipr +ipsr +ir +irda +iret +irq +irqhandler +irqs +irxfcs +isa +isab +isactive +isb +iscfgpullupstatusset +iscr +isfeasible +isinputfilterset +isinputset +isinterruptmasked +isinterruptset +ismultidriverset +isnextrxempty +isnexttxempty +iso +isoerror +isouputset +isoutputdatastatusset +isoutputset +isoutputwriteset +ispending +isr +isram +isrcode +isrs +isrtick +isrxempty +isset +isstatusset +istxempty +iter +itmc +itu +ivr +ivxr +jan +javier +jefferson +jframe +jtag +jtvic +jul +jun +kbyte +kbytes +keil +keymod +keywxr +khz +konw +ky +lan +lapic +larrayindex +lastxfer +lcd +lcdr +lcol +lcx +lcycles +ld +ldaa +ldata +ldbdis +ldbstop +ldd +ldflags +ldm +ldmia +ldr +ldra +ldras +ldrb +ldrbs +ldub +len +lengh +les +lexpirecounters +libc +linkedlist +linkr +listcurrent +listfirst +listget +listintroduction +listis +listitem +listlist +listsecond +listset +llb +llio +lly +loadcontext +loadnewseed +loadseed +locke +locopt +locoptsize +lod +loopback +lovrs +lowpowermode +lowres +lowtext +lpm +lpstart +lr +lsls +lspen +lspens +ltd +lu +lw +mabt +mac +mach +macl +macr +mag +mainclock +mainf +mainrdy +mair +malloc +mam +mame +maskable +maxlocoptsize +mbits +mc +mcf +mcfr +mchp +mck +mcka +mckb +mckr +mckrdy +mclk +mconfigintcoresw +mcr +mcu +mddr +mder +mdh +mdio +mdl +mdlc +mdsr +mec +mem +memcpy +memmang +memoryregion +memset +messagebuffer +messagebufferamp +messagebufferhandle +messagebuffermanagement +messsage +mfcr +mfd +mfid +mhz +microblaze +microcontroller +microelectronics +microsoft +microsystems +mide +midva +midvb +mie +mii +mikroc +min +mingw +minilistitem +mips +misadd +misc +misconfiguration +miso +misra +mmcr +mmi +mmr +mmu +mno +modereg +moderegister +modf +modfdis +mon +mor +mosc +moscen +moscs +mosi +mot +motorola +mov +moveq +movff +movhi +movne +movs +movw +mpe +mplab +mpu +mpuregionsettings +mr +mrdy +mread +mrs +mrtr +msb +msbf +msc +msdis +msen +msp +mspgcc +msr +mst +mstr +msvc +mtcr +mti +mtime +mtimecmp +mtimemark +mtimestamp +mtioa +mtiob +mtvec +mul +muldiv +multidriver +multidriverdisable +multidriverenable +multidrvenable +mutex +mutexes +mutexs +mux +muxes +mv +mvfaclo +mvtacgu +mvtachi +mvtaclo +mvtc +mw +mx +myfunction +myprintfunction +myvariable +mz +nack +nadler +nand +nanded +nb +nbc +nbstop +ncfgr +ncpha +ncr +nebp +ner +newhandler +newlib +newlibandfreertos +nfiq +ngnre +ngnrne +ngre +nios +nirq +nmi +noblock +nomatter +noninfringement +nonsecure +noop +nosavereg +nostdint +nov +npcs +nrst +nrstl +ns +nsr +nssr +ntrst +num +nvic +nvm +nw +ocr +oct +odataxr +odr +odsr +oer +ofb +ok +oldhandler +oldnewthing +oldvector +op +opb +openocd +openrtos +opmod +ops +optimisation +optimisations +optimised +ored +org +orr +orrs +os +osc +oscbypass +oscen +oscount +osr +othercoreid +othewise +outb +outputdisable +outputenable +outputwrite +outputwritedisable +outputwriteenable +overheadpage +overheadstorage +ovl +ovly +ovr +ovre +ovres +ovrun +owdr +ower +owsr +padc +pae +paes +pagen +paic +param +partref +pb +pbuffer +pc +pcan +pcb +pcdr +pcer +pcformat +pchead +pck +pckgr +pckr +pclath +pclatu +pclk +pcname +pcnametoquery +pcp +pcqueuegetname +pcqueuename +pcreadfrom +pcreturn +pcrxedmessage +pcs +pcsdec +pcsr +pcstringtosend +pctail +pctaskgethandle +pctaskgetname +pctaskname +pctimergetname +pctimername +pcwritebuffer +pcwriteto +pcx +pcxi +pdbgu +pdc +pdfail +pdfalse +pdfreertos +pdms +pdpass +pdr +pdsr +pdtrue +pe +peformed +pendedfunction +pendsv +perf +performcmd +periph +periphaenable +periphbenable +periphids +perrst +pfr +pfre +philips +phy +phya +pic +picnt +pien +piir +pimr +pio +pioa +piob +pioenable +pisr +pitc +pitdisableint +piten +pitenableint +pitgetmode +pitgetpiir +pitgetpivr +pitgetstatus +pitien +pitinit +pitsetpiv +piv +pivr +pl +pll +pllb +pllcount +plldivider +pllmultiplier +pllr +pls +pm +pmc +pmu +pnextbuffer +pong +popa +popm +portallocate +portalt +portasm +portasmadditional +portassert +portbase +portbenchmark +portbit +portbyte +portccpn +portclear +portcompiler +portconfigure +portcopy +portcpacr +portcpu +portcritical +portcsa +portcu +portdelete +portdisable +portdont +porten +portenable +portenter +portexit +portexpected +portforce +portfpccr +portfr +portfreertos +portget +portglobal +porthardware +porthas +portinital +portinitial +portinput +portinstruction +portipl +portisr +portitu +portkernel +portmacro +portmax +portminimal +portmpu +portmux +portmx +portno +portnop +portnum +portnvic +portpointer +portpre +portpreload +portprivilege +portpsw +portreset +portrestore +portsave +portscheduler +portset +portsofrware +portstack +portstart +portsupporess +portsuppress +portsvc +portswitch +portsystem +porttask +porttick +porttickisr +porttimer +porttotal +porttrace +porttracestamp +porttrap +portuse +portusing +portword +portyield +posix +powerup +ppage +ppc +ppdc +ppio +ppitc +ppmc +ppudr +ppuer +ppusr +ppvdestination +ppwm +ppxidletaskstackbuffer +ppxidletasktcbbuffer +ppxtimertaskstackbuffer +ppxtimertasktcbbuffer +pr +pragma +pre +prea +preb +preemtion +preinc +pres +prescal +prescalar +prescale +prescaled +prescaler +prid +primask +printf +prio +prioritised +proc +procdly +procrst +procs +prodh +prodl +prog +proge +programmation +projdefs +propag +prot +protectmode +proto +prstc +prttc +prv +prvaddcurrenttasktodelayedlist +prvcheckinterfaces +prvcopydatatoqueue +prvcoroutineflashtask +prvcoroutineflashworktask +prvexitfunction +prvgettimens +prvheapinit +prvidletask +prvinitialisecoroutinelists +prvinitialisemutex +prvinitialisenewstreambuffer +prvinitialisenewtimer +prvinsertblockintofreelist +prvlockqueue +prvportmalloc +prvportresetpic +prvprocesssimulatedinterrupts +prvreadbytesfrombuffer +prvsampletimenow +prvsettickfrequencydefault +prvsetupfpu +prvsetupmpu +prvsetuptimerinterrupt +prvsleep +prvstarttimens +prvtaskexiterror +prvtickcount +prvtimercallback +prvwritebytestobuffer +prvwritemessagetobuffer +prvyieldhandler +ps +psp +pspi +psplim +psr +pssc +pstdby +psw +ptc +ptcr +ptdes +pte +pthread +pthreads +ptr +ptsr +ptwi +ptz +pucallocatedmemory +pucbuffer +puccurrentstackpointer +pucdata +pucmessagebufferstoragearea +pucporttaskfpucontextbuffer +pucqueuestorage +pucqueuestoragebuffer +pucstacklimit +pucstackstart +pucstartaddress +pucstreambufferstoragearea +pudp +puladdend +pulcallerstackaddress +puldestination +pulidletaskstacksize +pullowercsa +pullup +pullupenable +pulnotificationvalue +pulparam +pulpino +pulpreviousnotificationvalue +pulpreviousnotifyvalue +pultcb +pultimehigh +pultimertaskstacksize +pultotalruntime +puluppercsa +puon +pusart +pusha +putchar +puxstackbuffer +puxvariabletoincrement +pv +pvbuffer +pvcallbackref +pvcomparand +pvcontainer +pvcreatedtask +pvector +pveventgroup +pvexchange +pvinterruptevent +pvinterrupteventmutex +pvitemtoqueue +pvnewid +pvowner +pvparameter +pvparameters +pvportmalloc +pvportrealloc +pvreg +pvrxdata +pvtaskcode +pvthread +pvtimergettimerid +pvtimerid +pvtxdata +pvvalue +pvyieldevent +pwdtc +pwm +pwmc +pxblock +pxblocktoinsert +pxcallbackfunction +pxcode +pxcontainer +pxcoroutinecode +pxcoroutinewoken +pxcrcb +pxcreatedtask +pxcurrentcoroutine +pxcurrenttcb +pxcurrenttcbconst +pxcurrenttimerlist +pxdelayedcoroutinelist +pxdelayedtasklist +pxend +pxendofstack +pxeventbits +pxeventgroupbuffer +pxeventlist +pxeventlistitem +pxfirsttcb +pxhandler +pxhead +pxheapregions +pxhigherprioritytaskwoken +pxhookfunction +pxidletasktcbbuffer +pxindex +pxitem +pxiterator +pxlist +pxlistend +pxlistitem +pxlistwasempty +pxmessage +pxmutexbuffer +pxmutexholder +pxmutexholdertcb +pxnewlistitem +pxnewqueue +pxnewtcb +pxnewtimer +pxnext +pxnextfreeblock +pxnexttcb +pxoriginalsp +pxoriginaltos +pxoverflowdelayedcoroutinelist +pxoverflowdelayedtasklist +pxowner +pxportinitialisestack +pxprevious +pxpreviouswaketime +pxqueue +pxqueuebuffer +pxramstack +pxreadycoroutinelists +pxreadytaskslists +pxregions +pxresult +pxrxedmessage +pxsemaphorebuffer +pxstack +pxstackbase +pxstackbuffer +pxstaticmessagebuffer +pxstaticqueue +pxstaticstreambuffer +pxstreambuffer +pxstreambuffercreate +pxstreambuffercreatestatic +pxtagvalue +pxtask +pxtaskbuffer +pxtaskdefinition +pxtaskstatus +pxtaskstatusarray +pxtasktag +pxtasktodelete +pxtasktoresume +pxtasktosuspend +pxtaskwoken +pxtcb +pxtcbofmutexholder +pxthreadstate +pxtickstowait +pxtimeout +pxtimer +pxtimerbuffer +pxtimerlistswereswitched +pxtopofstack +pxuartinstance +pxunblockedtcb +pxxramstack +queuedefinition +queuehandle +queuemanagement +queuepointers +queuequeue +queueregistryitem +queuesend +queueset +queuesethandle +queuesetmemberhandle +queueunlocked +ra +ramarea +rampz +rasr +rb +rbar +rbof +rbqp +rbsy +rc +rcb +rcmr +rcomp +rcount +rcr +rdc +rdr +rdrf +rdy +readbit +readme +readvalue +realise +realloc +rec +receiveframe +recognise +recognised +reent +refcount +reg +rega +regieters +registerr +registerselection +registerset +registerstatus +regs +regsiter +reld +repurpose +reqflg +resetep +resetrx +resettx +ressetting +ret +reti +rets +retto +revref +rf +rfe +rfmr +rhr +ri +richard +riic +ripl +risc +rja +rk +rl +rlar +rlce +rle +rles +rlex +rlt +rm +rmc +rmii +rmr +rmwupe +rncr +rnpr +rnr +ro +rom +rousset +rov +rovr +rp +rpcs +rpr +rre +rse +rshr +rslcx +rsminpr +rsr +rst +rstc +rstep +rstgetmode +rstgetstatus +rstissoftrstactive +rstit +rstnack +rstrx +rstsetmode +rstsoftreset +rststa +rsttx +rsttyp +rsvd +rtar +rtc +rte +rti +rtictl +rtie +rtifrc +rtmr +rtor +rtos +rtpres +rts +rtsdis +rtsen +rtsr +rtt +rttc +rttclearalarmint +rttclearrttincint +rttgetalarmvalue +rttgetstatus +rttinc +rttincien +rttreadvalue +rttrestart +rttrst +rttsetalarmint +rttsetalarmvalue +rttsetprescaler +rttsetrttincint +rttsettimebase +rtvr +rty +rv +rw +rx +rxbrk +rxbuff +rxbytecnt +rxd +rxdis +rxen +rxena +rxoverwrite +rxrdy +rxready +rxrsm +rxsetup +rxsusp +rxsyn +rxtdis +rxten +rxubr +rxv +sa +sadr +safertos +sam +saveall +sbbytes +sbflags +sbreceive +sbrk +sbsend +scall +scb +scbr +scdr +scer +scf +schedulercontrol +sck +scople +scratchspace +scsr +sda +sec +secureconfiguse +securecontext +securecontextno +secureinitfpccr +secureinitnsacr +secureinitscb +seg +sel +semaphoredata +semaphorehandle +semphr +senda +sendframe +serr +setaddress +setalarmint +setalarmvalue +setbaudrate +setcryptokey +setexceptionvector +setinitializationvector +setirdafilter +setnextrx +setnexttx +setoutput +setprioritygrouping +setrtt +setrttincint +setrx +setstate +settimeguard +settx +sfr +shtim +si +sig +sigalrm +sigalrms +sigint +sigmask +signalled +sigwait +sil +sizeof +slowclock +smod +smp +smr +snprintf +sodr +sof +sofint +softregs +softreset +sp +spck +spd +sph +spi +spidis +spien +spiens +spinlock +spinlocks +spiram +spl +sprintf +spsr +spu +spurioushandler +sqe +sr +sram +src +srcmp +srctype +srl +srr +ssc +ssemaphoretake +staa +stackpointer +stacksize +stackspace +stacktype +startchannel +startconversion +startprocessing +stat +staticdont +staticeventgroup +staticmessagebuffer +staticqueue +staticsemaphore +staticstreambuffer +statictask +statictimer +stb +std +stdarg +stderr +stdin +stdint +stdout +ste +stk +stm +stmdb +stmia +stmicroelectronics +stopchannel +stpbrk +str +streambuffer +streambufferdef +streambufferhandle +streambuffermanagement +strlen +struct +sttbrk +sttdly +sttout +sttto +subkey +sublicense +supervisorcall +susingpreemption +suspendthread +svacc +svc +svcne +svdis +sven +svmst +svr +svread +sw +swhsh +swi +swinr +swintr +swrst +swtich +swtrg +sxx +synchro +synchronisation +synchronise +synopsys +sys +sysc +syscall +syscalls +syscon +syst +systemclock +systick +sysview +sz +szbuffer +sznextbuffer +tablat +taskcode +taskctrl +taskdisable +taskenable +taskenter +taskevent +taskexit +taskfunction +taskhandle +taskhookfunction +tasknot +tasknotifications +taskparameters +taskrecord +taskreset +taskscheduler +taskselect +taskstamp +taskstampcount +taskstatus +taskutils +taskyield +tblpag +tblptrh +tblptrl +tblptru +tblptruh +tblptrul +tbqp +tbr +tbsy +tc +tcb +tcbs +tcclks +tclk +tcmr +tcomp +tcp +tcr +td +tdes +tdesmod +tdr +tdre +te +tec +tempdata +tempregister +teof +terminatethread +tex +tf +tfmr +tgo +thalt +therad +thie +thr +threadstate +thu +tiao +tickless +tickrate +tickrates +ticktype +ticsk +tid +tim +timebase +timebeginperiod +timeendperiod +timeguard +timemark +timercallbackfunction +timerhandle +timeslice +timesliced +timestp +timfrz +timrst +tioa +tiob +tk +tls +tm +tmcsr +tmm +tmp +tmpdata +tmr +tmrctr +tmrfirst +tmrno +tmrtimercontrol +tncr +tnpr +tod +todo +toolchain +tos +tosh +tosl +tosu +tovf +tpcs +tpf +tpfr +tpq +tpr +tpu +traceevent +transfert +transmikt +trapa +tregister +trg +trgen +trgsel +tricore +trmtimer +trustzone +tshr +tskidle +tskset +tskstatic +tsktaskcontrolblock +tsktcb +tsr +tst +tstart +tstp +ttgr +ttm +tue +tund +tundr +tv +twck +twd +twi +tx +txbufe +txcomp +txd +txdis +txempty +txen +txena +txerr +txpktrdy +txrdy +txready +txsyn +txtdis +txten +txubr +txvc +txvdis +typedefed +tzq +uart +uartlite +ubasetype +ubr +uc +ucarraytosend +ucbufferstorage +uccritialnesting +uccriticalnesting +ucdata +ucdelayaborted +ucflags +ucforcedinterruptflags +ucheap +ucinterruptid +uclocaltickcount +ucmaxpriorityvalue +ucmessageid +ucnotifystate +ucnotifyvalue +uconekbyte +ucparametertopass +ucqueuestorage +ucqueuetype +ucrxdata +ucstaticallyallocated +ucstatictimerqueuestorage +ucstatus +ucstoragebuffer +uctasksdeleted +uctempfpubuffer +uczero +udp +uf +uint +ul +uladdress +ulapsr +ulavariable +ulbitstoclear +ulbitstoclearonentry +ulbitstoclearonexit +ulbitstoset +ulcomparand +ulcount +ulcriticalnesting +ulcurrentinterrupt +ulcycles +uldummy +ulexchange +ulhartid +ulicr +ulinterruptmask +ulinterruptnesting +ulistaskprivileged +ull +ullcriticalnesting +ullnexttime +ullporttaskhasfpucontext +ulmair +ulmask +ulmatchvalueforonetick +ulong +ulparameter +ulparameters +ulpendinginterrupts +ulporttaskhasdpfpucontext +ulporttaskhasfpucontext +ulportyieldpending +ulr +ulrbar +ulreg +ulreload +ulreloadvalue +ulreturnvalue +ulrlar +ulruntimecounter +ulsecurestacksize +ulsetinterruptmask +ulstackdepth +ulstatsaspercentage +ulstoppedtimercompensation +ultablebase +ultaskgetidleruntimecounter +ultaskhasfpucontext +ultasknotificationtakeindexed +ultasknotifystateclear +ultasknotifytake +ultasknotifytakeindexed +ultasknotifyvalueclear +ultasknotifyvalueclearindexed +ultaskswitchedintime +ultaskswitchrequested +ultotalruntime +ultotalruntimediv +ulusingfpu +ulvalreceived +ulvalue +ulvar +ulvartosend +un +und +undadd +undef +underrun +unhandled +uni +unicast +unicore +unre +unsuspend +updatechannel +updown +uppercontext +upto +urad +urat +uri +ursten +urstien +ursts +usa +usart +usb +usbdiv +usclockhz +uscriticalnesting +uselib +usf +usisrhigh +usisrlow +usmode +usp +usportcheckfreestackspace +usprg +usrio +ussegmentselector +usstackdepth +usstackhighwatermark +ut +utf +utilised +utilises +uxarraysize +uxautoreload +uxbasepriority +uxbits +uxbitstoclear +uxbitstoset +uxbitstowait +uxbitstowaitfor +uxcontrolbits +uxcriticalnesting +uxcurrenteventbits +uxcurrentnumberoftasks +uxcurrentpriority +uxdeletedtaskswaitingcleanup +uxeventgroupnumber +uxeventqueuelength +uxflashrates +uxhandle +uxhigherpriorityreadytasks +uxindex +uxindextoclear +uxindextonotify +uxindextowaiton +uxinheritedpriority +uxinitialcount +uxitemsize +uxitemssize +uxledtoflash +uxlength +uxlistremove +uxmaxcount +uxmessageswaiting +uxnewpriority +uxoriginalpriority +uxportcomparesetextram +uxpriority +uxprioritytouse +uxqueue +uxqueuelength +uxqueuemessageswaiting +uxqueuespacesavailable +uxqueuetype +uxreceived +uxrecursivecallcount +uxreturn +uxsavedmaskvalue +uxsavedtaskstackpointer +uxschedulersuspended +uxsemaphoregetcount +uxstate +uxstreambuffernumber +uxtaskgetnumberoftasks +uxtaskgetstackhighwatermark +uxtaskgetsystemstate +uxtasknumber +uxtaskpriorityget +uxtaskprioritygetfromisr +uxtcbnumber +uxtimergetreloadmode +uxtimerincrementsforonetick +uxtimernumber +uxtopreadypriority +uxtopusedpriority +uxvariabletoincrement +uxwantedbytes +vacoroutine +vadifferenttask +vafunction +val +vanexampleinterruptserviceroutine +vaninterrupthandler +vaninterruptserviceroutine +vanisr +vanothertask +vapplicationcleartimerinterrupt +vapplicationexceptionregisterdump +vapplicationfpusafeirqhandler +vapplicationgetidletaskmemory +vapplicationgettimertaskmemory +vapplicationidlehook +vapplicationirqhandler +vapplicationsetuptickinterrupt +vapplicationsetupticktimerinterrupt +vapplicationsetuptimerinterrupt +vapplicationstackoverflowhook +vapplicationtickhook +var +vatask +vbacklighttimercallback +vbr +vbufferisr +vcallbackfunction +vclearinterruptmask +vcoroutineschedule +vddcore +vec +vectactive +vega +vely +ver +veventgroupclearbitscallback +veventgroupdelete +veventgroupsetbitscallback +vflashcoroutine +vfp +vfunction +vic +vicvectaddr +visr +vkeypresseventhandler +vkeypresseventinterrupthandler +vldmia +vldmiaeq +vlistinitialise +vlistinitialiseitem +vlistinsert +vlistinsertend +vlisttask +vmessagebufferdelete +vnonpreemptivetick +votherfunction +voutputcharacter +vpartesttoggleled +vportallocatesecurecontext +vportcloserunningthread +vportcpuacquiremutex +vportcpuacquiremutexintsdisabled +vportcpuacquiremutexintsdisabledextram +vportcpuacquiremutexintsdisabledinternal +vportcpuacquiremutextimeout +vportcpureleasemutex +vportcpureleasemutexintsdisabled +vportcpureleasemutexintsdisabledextram +vportcpureleasemutexintsdisabledinternal +vportdefineheapregions +vportdeletethread +vportendscheduler +vportentercritical +vportexceptionhandler +vportexceptionhanlderentry +vportexceptionsinstallhandlers +vportexitcritical +vportfree +vportfreesecurecontext +vportgetheapstats +vportinitialiseblocks +vportisrstartfirststask +vportraisebasepri +vportresetprivilege +vportsetmpuregistersetone +vportsetuptimerinterrupt +vportstartfirststask +vportsvchandler +vporttaskentrypoint +vporttaskusesdpfpu +vporttaskusesfpu +vporttickisr +vportvalidateinterruptpriority +vportyield +vportyieldfromtick +vportyieldprocessor +vprocessinterface +vqueueaddtoregistry +vqueuedelete +vqueueunregisterqueue +vr +vraiseprivilege +vreceivingcoroutine +vreg +vresetprivilege +vrestorecontextoffirsttask +vrpm +vsemaphorecreatebinary +vsemaphoredelete +vsendingcoroutine +vsetbacklightstate +vsoftwareinterruptentry +vstartfirsttask +vstmdb +vstmdbeq +vstreambufferdelete +vtask +vtaskallocatempuregions +vtaskcode +vtaskdelay +vtaskdelayuntil +vtaskdelete +vtaskendscheduler +vtaskentercritical +vtaskexitcritical +vtaskfunction +vtaskgetinfo +vtaskgetruntimestats +vtasklist +vtasknotify +vtasknotifygivefromisr +vtasknotifygiveindexedfromisr +vtaskplaceoneventlist +vtaskpriorityset +vtaskremovefromunorderedeventlist +vtaskresume +vtaskresumefromisr +vtasksetapplicationtasktag +vtasksettimeout +vtasksettimeoutstate +vtaskstartscheduler +vtasksteptick +vtasksuspend +vtasksuspendall +vtaskswitchcontext +vtaskusesdpfpu +vtickisr +vtimercallback +vtimerisr +vtimersetreloadmode +vtimersettimerid +vtoggleled +vtor +vuart +walter +wasn +watchpoint +wavesel +wavsel +wdcr +wdd +wddbghlt +wddis +wde +wderr +wdfien +wdg +wdidlehlt +wdie +wdif +wdmr +wdp +wdrproc +wdrsten +wdrstt +wdsr +wdt +wdtc +wdtgetperiod +wdto +wdtrestart +wdtsetmode +wdtsgettatus +wdunf +wdv +westat +wfi +winavr +witin +wizc +wl +wo +wol +wperiodmin +wreg +writebit +writting +wu +www +wwwfreertos +wxr +xa +xaa +xaaaa +xaaaaaaaa +xabab +xabac +xactivetimerlist +xaltregions +xavailableheapspaceinbytes +xb +xbacklighttimer +xbankedstartscheduler +xbb +xbbbb +xblocks +xblocksize +xblocktime +xblocktimeticks +xbufferlengthbytes +xbuffersizebytes +xbytesavailable +xbytessent +xbytestostoremessagelength +xc +xcallbackparameters +xcallbackparameterstype +xcalls +xcc +xcccc +xcdcd +xcdce +xchal +xchecktaskparameters +xclearbitonexit +xclearcountonexit +xclearonexit +xclib +xcommandtime +xcommsrxqueue +xconsttickcount +xcopyposition +xcoroutinecreate +xcoroutinepreviouslywoken +xcoroutinequeue +xcount +xcreatedeventgroup +xcrwokenbypost +xd +xdatalengthbytes +xdd +xdddd +xdeadbeef +xdelay +xdelayedcoroutinelist +xdelayedtasklist +xdelaytime +xe +xea +xeb +xed +xee +xeeee +xeeeeeeee +xelapsedtime +xend +xer +xeventbits +xeventgropucreate +xeventgropucreatestatic +xeventgroup +xeventgroupbuffer +xeventgroupclearbits +xeventgroupclearbitsfromisr +xeventgroupcreate +xeventgroupcreatestatic +xeventgroupdelete +xeventgroupgetbits +xeventgroupgetbitsfromisr +xeventgroupsetbits +xeventgroupsetbitsfromisr +xeventgroupsync +xeventgroupwaitbits +xeventlistitem +xexpectedidletime +xexpectedticks +xexpiredtimer +xf +xfc +xff +xfff +xfffa +xfffb +xfffc +xfffcc +xfffd +xfffdc +xfffe +xffff +xfffff +xfffffc +xfffffd +xffffff +xffffffe +xfffffffd +xfffffffel +xffffffff +xfffffffful +xfirstlength +xfrequency +xfunctiontopend +xgenericlistitem +xgetfreestackspace +xhandle +xhead +xheapregions +xhigherpriorittaskwoken +xhigherprioritytaskwoken +xhigherprioritytaskwokenbypost +xidletaskhandle +xilinx +xindex +xinheritanceoccurred +xinsideinterrupt +xintc +xinterfacetoservice +xinterruptcontroller +xinterruptdescriptortable +xisfeasable +xisfeasible +xismessagebuffer +xisprivileged +xitemvalue +xlasttime +xlastwaketime +xlength +xlist +xlistend +xmair +xmaxcount +xmaxexpirycountbeforestopping +xmaxsize +xmc +xmessage +xmessagebuffer +xmessagebuffercreate +xmessagebuffercreatestatic +xmessagebufferisempty +xmessagebufferisfull +xmessagebuffernextlengthbytes +xmessagebufferread +xmessagebufferreceive +xmessagebufferreceivecompletedfromisr +xmessagebufferreceivefromisr +xmessagebufferreset +xmessagebuffersend +xmessagebuffersendcompletedfromisr +xmessagebuffersendfromisr +xmessagebuffersizebytes +xmessagebufferspaceavailable +xmessagebufferspacesavailable +xmessagebufferstruct +xmessageid +xmessagevalue +xminimumeverfreebytesremaining +xminsize +xmpu +xmpuctrlconst +xmpusettings +xmutex +xmutexbuffer +xmutexholder +xn +xnearstartscheduler +xnewperiod +xnewqueue +xnextexpiretime +xnextfreebyte +xnexthead +xnextmessagelength +xnexttail +xnexttaskunblocktime +xnumberoffreeblocks +xnumberofsuccessfulallocations +xnumberofsuccessfulfrees +xnumbertopost +xnumofoverflows +xoff +xon +xor +xored +xoverflowcount +xpar +xparameters +xpendedcounts +xpendedticks +xpendingreadycoroutinelist +xpendingreadylist +xperiod +xportgetcoreid +xportgetfreeheapsize +xportinstallinterrupthandler +xportraiseprivilege +xportregistercinterrupthandler +xportregisterdump +xportstartfirsttask +xportstartscheduler +xpsr +xqueue +xqueueaddtoset +xqueuebuffer +xqueuecreate +xqueuecreatemutex +xqueuecreateset +xqueuecreatestatic +xqueuegenericsend +xqueuegenericsendfromisr +xqueuegetmutexholder +xqueuegivefromisr +xqueuegivemutexrecursive +xqueueorsemaphore +xqueueoverwrite +xqueueoverwritefromisr +xqueuepeek +xqueuepeekfromisr +xqueuereceive +xqueuereceivefromisr +xqueueregistryitem +xqueueselectfromset +xqueuesend +xqueuesendfromisr +xqueuesendtoback +xqueuesendtobackfromisr +xqueuesendtofromfromisr +xqueuesendtofront +xqueuesendtofrontfromisr +xqueuesendtotofront +xqueueset +xqueuesizeinbytes +xram +xrbarconst +xreceivedbytes +xreceivedlength +xrecievedbytes +xregion +xregions +xregionssettings +xregtest +xrequiredspace +xresult +xreturn +xreturned +xrnrconst +xrunningprivileged +xrunprivileged +xrxqueue +xschedulerrunning +xsecurecontext +xsecurecontextconst +xsecurecontexthandle +xsemaphore +xsemaphorebuffer +xsemaphorecreatebinary +xsemaphorecreatebinarystatic +xsemaphorecreatecounting +xsemaphorecreatecountingstatic +xsemaphorecreateeventgroupstatic +xsemaphorecreatemutex +xsemaphorecreatemutexstatic +xsemaphorecreaterecursivemutex +xsemaphorecreaterecursivemutexstatic +xsemaphoregetmutexholder +xsemaphoregetmutexholderfromisr +xsemaphoregive +xsemaphoregivefromisr +xsemaphoregivemutexrecursive +xsemaphoregiverecursive +xsemaphoretake +xsemaphoretakefromisr +xsemaphoretakemutexrecursive +xsemaphoretakerecursive +xshal +xsize +xsizeinbytes +xsizeoflargestfreeblockinbytes +xsizeofsmallestfreeblockinbytes +xspace +xstack +xstacksize +xstart +xstatelistitem +xstatic +xstatictimerqueue +xstreambuffer +xstreambufferbytesavailable +xstreambuffercreate +xstreambuffercreatestatic +xstreambufferisempty +xstreambufferisfull +xstreambuffernextmessagelengthbytes +xstreambufferreceive +xstreambufferreceivecompletedfromisr +xstreambufferreceivefromisr +xstreambufferreset +xstreambuffersend +xstreambuffersendcompletedfromisr +xstreambuffersendfromisr +xstreambuffersettriggerlevel +xstreambuffersizebytes +xstreambufferspacesavailable +xstreambufferstruct +xsuspendedtasklist +xswithcrequired +xt +xtail +xtal +xtask +xtaskabortdelay +xtaskbuffer +xtaskcallapplicationtaskhook +xtaskcatchupticks +xtaskcheckfortimeout +xtaskcreate +xtaskcreaterestricted +xtaskcreaterestrictedstatic +xtaskcreatestatic +xtaskdetails +xtaskendscheduler +xtaskgetapplicationtasktag +xtaskgetapplicationtasktagfromisr +xtaskgetcurrenttaskhandle +xtaskgethandle +xtaskgetidletaskhandle +xtaskgetschedulerstate +xtaskgettickcount +xtaskgettickcountfromisr +xtaskhandle +xtaskincrementtick +xtasknofify +xtasknofifyindexed +xtasknotify +xtasknotifyandquery +xtasknotifyandqueryfromisr +xtasknotifyandqueryindexed +xtasknotifyandqueryindexedfromisr +xtasknotifyfromisr +xtasknotifygive +xtasknotifygivefromisr +xtasknotifygiveindexed +xtasknotifygiveindexedfromisr +xtasknotifyindex +xtasknotifyindexed +xtasknotifyindexedfromisr +xtasknotifystateclear +xtasknotifystateclearindexed +xtasknotifytake +xtasknotifywait +xtasknotifywaitindexed +xtasknumber +xtaskremovefromeventlist +xtaskresumeall +xtaskresumefromisr +xtaskswaitingforbits +xtaskswaitingtermination +xtaskswaitingtoreceive +xtaskswaitingtosend +xtasktonotify +xtasktoquery +xtasktoresume +xtasktosuspend +xtaskwaitingtoreceive +xtaskwaitingtosend +xtaskwokenbyreceive +xtbsp +xtensa +xtexcframe +xthal +xthreadstate +xtickcount +xtickstocatchup +xtickstodelay +xtickstowait +xticktodelay +xticktype +xtimecaps +xtimeincrement +xtimenow +xtimeonentering +xtimeout +xtimer +xtimerbuffer +xtimerchangeperiod +xtimerchangeperiodfromisr +xtimercreate +xtimercreated +xtimercreatestatic +xtimerdelete +xtimergetexpirytime +xtimergetperiod +xtimergettimerdaemontaskhandle +xtimeristimeractive +xtimerlistitem +xtimerlistswereswitched +xtimerparameters +xtimerparameterstype +xtimerpendfunctioncall +xtimerpendfunctioncallfromisr +xtimerperiod +xtimerperiodinticks +xtimerqueue +xtimerreset +xtimerresetfromisr +xtimers +xtimerstart +xtimerstartfromisr +xtimerstop +xtimerstopfromisr +xtimertaskhandle +xtos +xtriggerlevel +xtriggerlevelbytes +xuart +xvalueofinsertion +xvtorconst +xwaitforallbits +xwantedsize +xwritevalue +xxr +xyieldpending +xzr diff --git a/RTOS/FreeRTOS/Source/list.c b/RTOS/FreeRTOS/Source/list.c new file mode 100644 index 0000000..e785767 --- /dev/null +++ b/RTOS/FreeRTOS/Source/list.c @@ -0,0 +1,210 @@ +/* + * FreeRTOS Kernel V10.4.1 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * https://www.FreeRTOS.org + * https://github.com/FreeRTOS + * + */ + + +#include + +/* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining + * all the API functions to use the MPU wrappers. That should only be done when + * task.h is included from an application file. */ +#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE + +#include "FreeRTOS.h" +#include "list.h" + +/* Lint e9021, e961 and e750 are suppressed as a MISRA exception justified + * because the MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be + * defined for the header files above, but not in this file, in order to + * generate the correct privileged Vs unprivileged linkage and placement. */ +#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE /*lint !e961 !e750 !e9021. */ + +/*----------------------------------------------------------- +* PUBLIC LIST API documented in list.h +*----------------------------------------------------------*/ + +void vListInitialise( List_t * const pxList ) +{ + /* The list structure contains a list item which is used to mark the + * end of the list. To initialise the list the list end is inserted + * as the only list entry. */ + pxList->pxIndex = ( ListItem_t * ) &( pxList->xListEnd ); /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. */ + + /* The list end value is the highest possible value in the list to + * ensure it remains at the end of the list. */ + pxList->xListEnd.xItemValue = portMAX_DELAY; + + /* The list end next and previous pointers point to itself so we know + * when the list is empty. */ + pxList->xListEnd.pxNext = ( ListItem_t * ) &( pxList->xListEnd ); /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. */ + pxList->xListEnd.pxPrevious = ( ListItem_t * ) &( pxList->xListEnd ); /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. */ + + pxList->uxNumberOfItems = ( UBaseType_t ) 0U; + + /* Write known values into the list if + * configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */ + listSET_LIST_INTEGRITY_CHECK_1_VALUE( pxList ); + listSET_LIST_INTEGRITY_CHECK_2_VALUE( pxList ); +} +/*-----------------------------------------------------------*/ + +void vListInitialiseItem( ListItem_t * const pxItem ) +{ + /* Make sure the list item is not recorded as being on a list. */ + pxItem->pxContainer = NULL; + + /* Write known values into the list item if + * configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */ + listSET_FIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem ); + listSET_SECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem ); +} +/*-----------------------------------------------------------*/ + +void vListInsertEnd( List_t * const pxList, + ListItem_t * const pxNewListItem ) +{ + ListItem_t * const pxIndex = pxList->pxIndex; + + /* Only effective when configASSERT() is also defined, these tests may catch + * the list data structures being overwritten in memory. They will not catch + * data errors caused by incorrect configuration or use of FreeRTOS. */ + listTEST_LIST_INTEGRITY( pxList ); + listTEST_LIST_ITEM_INTEGRITY( pxNewListItem ); + + /* Insert a new list item into pxList, but rather than sort the list, + * makes the new list item the last item to be removed by a call to + * listGET_OWNER_OF_NEXT_ENTRY(). */ + pxNewListItem->pxNext = pxIndex; + pxNewListItem->pxPrevious = pxIndex->pxPrevious; + + /* Only used during decision coverage testing. */ + mtCOVERAGE_TEST_DELAY(); + + pxIndex->pxPrevious->pxNext = pxNewListItem; + pxIndex->pxPrevious = pxNewListItem; + + /* Remember which list the item is in. */ + pxNewListItem->pxContainer = pxList; + + ( pxList->uxNumberOfItems )++; +} +/*-----------------------------------------------------------*/ + +void vListInsert( List_t * const pxList, + ListItem_t * const pxNewListItem ) +{ + ListItem_t * pxIterator; + const TickType_t xValueOfInsertion = pxNewListItem->xItemValue; + + /* Only effective when configASSERT() is also defined, these tests may catch + * the list data structures being overwritten in memory. They will not catch + * data errors caused by incorrect configuration or use of FreeRTOS. */ + listTEST_LIST_INTEGRITY( pxList ); + listTEST_LIST_ITEM_INTEGRITY( pxNewListItem ); + + /* Insert the new list item into the list, sorted in xItemValue order. + * + * If the list already contains a list item with the same item value then the + * new list item should be placed after it. This ensures that TCBs which are + * stored in ready lists (all of which have the same xItemValue value) get a + * share of the CPU. However, if the xItemValue is the same as the back marker + * the iteration loop below will not end. Therefore the value is checked + * first, and the algorithm slightly modified if necessary. */ + if( xValueOfInsertion == portMAX_DELAY ) + { + pxIterator = pxList->xListEnd.pxPrevious; + } + else + { + /* *** NOTE *********************************************************** + * If you find your application is crashing here then likely causes are + * listed below. In addition see https://www.FreeRTOS.org/FAQHelp.html for + * more tips, and ensure configASSERT() is defined! + * https://www.FreeRTOS.org/a00110.html#configASSERT + * + * 1) Stack overflow - + * see https://www.FreeRTOS.org/Stacks-and-stack-overflow-checking.html + * 2) Incorrect interrupt priority assignment, especially on Cortex-M + * parts where numerically high priority values denote low actual + * interrupt priorities, which can seem counter intuitive. See + * https://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html and the definition + * of configMAX_SYSCALL_INTERRUPT_PRIORITY on + * https://www.FreeRTOS.org/a00110.html + * 3) Calling an API function from within a critical section or when + * the scheduler is suspended, or calling an API function that does + * not end in "FromISR" from an interrupt. + * 4) Using a queue or semaphore before it has been initialised or + * before the scheduler has been started (are interrupts firing + * before vTaskStartScheduler() has been called?). + **********************************************************************/ + + for( pxIterator = ( ListItem_t * ) &( pxList->xListEnd ); pxIterator->pxNext->xItemValue <= xValueOfInsertion; pxIterator = pxIterator->pxNext ) /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. *//*lint !e440 The iterator moves to a different value, not xValueOfInsertion. */ + { + /* There is nothing to do here, just iterating to the wanted + * insertion position. */ + } + } + + pxNewListItem->pxNext = pxIterator->pxNext; + pxNewListItem->pxNext->pxPrevious = pxNewListItem; + pxNewListItem->pxPrevious = pxIterator; + pxIterator->pxNext = pxNewListItem; + + /* Remember which list the item is in. This allows fast removal of the + * item later. */ + pxNewListItem->pxContainer = pxList; + + ( pxList->uxNumberOfItems )++; +} +/*-----------------------------------------------------------*/ + +UBaseType_t uxListRemove( ListItem_t * const pxItemToRemove ) +{ +/* The list item knows which list it is in. Obtain the list from the list + * item. */ + List_t * const pxList = pxItemToRemove->pxContainer; + + pxItemToRemove->pxNext->pxPrevious = pxItemToRemove->pxPrevious; + pxItemToRemove->pxPrevious->pxNext = pxItemToRemove->pxNext; + + /* Only used during decision coverage testing. */ + mtCOVERAGE_TEST_DELAY(); + + /* Make sure the index is left pointing to a valid item. */ + if( pxList->pxIndex == pxItemToRemove ) + { + pxList->pxIndex = pxItemToRemove->pxPrevious; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + pxItemToRemove->pxContainer = NULL; + ( pxList->uxNumberOfItems )--; + + return pxList->uxNumberOfItems; +} +/*-----------------------------------------------------------*/ diff --git a/RTOS/FreeRTOS/Source/portable/IAR/ARM_CM0/port.c b/RTOS/FreeRTOS/Source/portable/IAR/ARM_CM0/port.c new file mode 100644 index 0000000..d6bb692 --- /dev/null +++ b/RTOS/FreeRTOS/Source/portable/IAR/ARM_CM0/port.c @@ -0,0 +1,431 @@ +/* + * FreeRTOS Kernel V10.4.1 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * https://www.FreeRTOS.org + * https://github.com/FreeRTOS + * + */ + +/*----------------------------------------------------------- +* Implementation of functions defined in portable.h for the ARM CM0 port. +*----------------------------------------------------------*/ + +/* IAR includes. */ +#include "intrinsics.h" + +/* Scheduler includes. */ +#include "FreeRTOS.h" +#include "task.h" + +/* Constants required to manipulate the NVIC. */ +#define portNVIC_SYSTICK_CTRL_REG ( *( ( volatile uint32_t * ) 0xe000e010 ) ) +#define portNVIC_SYSTICK_LOAD_REG ( *( ( volatile uint32_t * ) 0xe000e014 ) ) +#define portNVIC_SYSTICK_CURRENT_VALUE_REG ( *( ( volatile uint32_t * ) 0xe000e018 ) ) +#define portNVIC_INT_CTRL_REG ( *( ( volatile uint32_t * ) 0xe000ed04 ) ) +#define portNVIC_SHPR3_REG ( *( ( volatile uint32_t * ) 0xe000ed20 ) ) +#define portNVIC_SYSTICK_CLK_BIT ( 1UL << 2UL ) +#define portNVIC_SYSTICK_INT_BIT ( 1UL << 1UL ) +#define portNVIC_SYSTICK_ENABLE_BIT ( 1UL << 0UL ) +#define portNVIC_SYSTICK_COUNT_FLAG_BIT ( 1UL << 16UL ) +#define portMIN_INTERRUPT_PRIORITY ( 255UL ) +#define portNVIC_PENDSV_PRI ( portMIN_INTERRUPT_PRIORITY << 16UL ) +#define portNVIC_SYSTICK_PRI ( portMIN_INTERRUPT_PRIORITY << 24UL ) + +/* Constants required to set up the initial stack. */ +#define portINITIAL_XPSR ( 0x01000000 ) + +/* For backward compatibility, ensure configKERNEL_INTERRUPT_PRIORITY is + * defined. The value 255 should also ensure backward compatibility. + * FreeRTOS.org versions prior to V4.3.0 did not include this definition. */ +#ifndef configKERNEL_INTERRUPT_PRIORITY + #define configKERNEL_INTERRUPT_PRIORITY 0 +#endif + +/* Each task maintains its own interrupt status in the critical nesting + * variable. */ +static UBaseType_t uxCriticalNesting = 0xaaaaaaaa; + +/* The systick is a 24-bit counter. */ +#define portMAX_24_BIT_NUMBER ( 0xffffffUL ) + +/* A fiddle factor to estimate the number of SysTick counts that would have + * occurred while the SysTick counter is stopped during tickless idle + * calculations. */ +#ifndef portMISSED_COUNTS_FACTOR + #define portMISSED_COUNTS_FACTOR ( 45UL ) +#endif + +/* The number of SysTick increments that make up one tick period. */ +#if ( configUSE_TICKLESS_IDLE == 1 ) + static uint32_t ulTimerCountsForOneTick = 0; +#endif /* configUSE_TICKLESS_IDLE */ + +/* The maximum number of tick periods that can be suppressed is limited by the + * 24 bit resolution of the SysTick timer. */ +#if ( configUSE_TICKLESS_IDLE == 1 ) + static uint32_t xMaximumPossibleSuppressedTicks = 0; +#endif /* configUSE_TICKLESS_IDLE */ + +/* Compensate for the CPU cycles that pass while the SysTick is stopped (low + * power functionality only. */ +#if ( configUSE_TICKLESS_IDLE == 1 ) + static uint32_t ulStoppedTimerCompensation = 0; +#endif /* configUSE_TICKLESS_IDLE */ + +/* + * Setup the timer to generate the tick interrupts. The implementation in this + * file is weak to allow application writers to change the timer used to + * generate the tick interrupt. + */ +void vPortSetupTimerInterrupt( void ); + +/* + * Exception handlers. + */ +void xPortSysTickHandler( void ); + +/* + * Start first task is a separate function so it can be tested in isolation. + */ +extern void vPortStartFirstTask( void ); + +/* + * Used to catch tasks that attempt to return from their implementing function. + */ +static void prvTaskExitError( void ); + +/*-----------------------------------------------------------*/ + +/* + * See header file for description. + */ +StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack, + TaskFunction_t pxCode, + void * pvParameters ) +{ + /* Simulate the stack frame as it would be created by a context switch + * interrupt. */ + pxTopOfStack--; /* Offset added to account for the way the MCU uses the stack on entry/exit of interrupts. */ + *pxTopOfStack = portINITIAL_XPSR; /* xPSR */ + pxTopOfStack--; + *pxTopOfStack = ( StackType_t ) pxCode; /* PC */ + pxTopOfStack--; + *pxTopOfStack = ( StackType_t ) prvTaskExitError; /* LR */ + pxTopOfStack -= 5; /* R12, R3, R2 and R1. */ + *pxTopOfStack = ( StackType_t ) pvParameters; /* R0 */ + pxTopOfStack -= 8; /* R11..R4. */ + + return pxTopOfStack; +} +/*-----------------------------------------------------------*/ + +static void prvTaskExitError( void ) +{ + /* A function that implements a task must not exit or attempt to return to + * its caller as there is nothing to return to. If a task wants to exit it + * should instead call vTaskDelete( NULL ). + * + * Artificially force an assert() to be triggered if configASSERT() is + * defined, then stop here so application writers can catch the error. */ + configASSERT( uxCriticalNesting == ~0UL ); + portDISABLE_INTERRUPTS(); + + for( ; ; ) + { + } +} +/*-----------------------------------------------------------*/ + +/* + * See header file for description. + */ +BaseType_t xPortStartScheduler( void ) +{ + /* Make PendSV and SysTick the lowest priority interrupts. */ + portNVIC_SHPR3_REG |= portNVIC_PENDSV_PRI; + portNVIC_SHPR3_REG |= portNVIC_SYSTICK_PRI; + + /* Start the timer that generates the tick ISR. Interrupts are disabled + * here already. */ + vPortSetupTimerInterrupt(); + + /* Initialise the critical nesting count ready for the first task. */ + uxCriticalNesting = 0; + + /* Start the first task. */ + vPortStartFirstTask(); + + /* Should not get here! */ + return 0; +} +/*-----------------------------------------------------------*/ + +void vPortEndScheduler( void ) +{ + /* Not implemented in ports where there is nothing to return to. + * Artificially force an assert. */ + configASSERT( uxCriticalNesting == 1000UL ); +} +/*-----------------------------------------------------------*/ + +void vPortYield( void ) +{ + /* Set a PendSV to request a context switch. */ + portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET; + + /* Barriers are normally not required but do ensure the code is completely + * within the specified behaviour for the architecture. */ + __DSB(); + __ISB(); +} +/*-----------------------------------------------------------*/ + +void vPortEnterCritical( void ) +{ + portDISABLE_INTERRUPTS(); + uxCriticalNesting++; + __DSB(); + __ISB(); +} +/*-----------------------------------------------------------*/ + +void vPortExitCritical( void ) +{ + configASSERT( uxCriticalNesting ); + uxCriticalNesting--; + + if( uxCriticalNesting == 0 ) + { + portENABLE_INTERRUPTS(); + } +} +/*-----------------------------------------------------------*/ + +void xPortSysTickHandler( void ) +{ + uint32_t ulPreviousMask; + + ulPreviousMask = portSET_INTERRUPT_MASK_FROM_ISR(); + { + /* Increment the RTOS tick. */ + if( xTaskIncrementTick() != pdFALSE ) + { + /* Pend a context switch. */ + portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET; + } + } + portCLEAR_INTERRUPT_MASK_FROM_ISR( ulPreviousMask ); +} +/*-----------------------------------------------------------*/ + +/* + * Setup the systick timer to generate the tick interrupts at the required + * frequency. + */ +__weak void vPortSetupTimerInterrupt( void ) +{ + /* Calculate the constants required to configure the tick interrupt. */ + #if ( configUSE_TICKLESS_IDLE == 1 ) + { + ulTimerCountsForOneTick = ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ); + xMaximumPossibleSuppressedTicks = portMAX_24_BIT_NUMBER / ulTimerCountsForOneTick; + ulStoppedTimerCompensation = portMISSED_COUNTS_FACTOR; + } + #endif /* configUSE_TICKLESS_IDLE */ + + /* Stop and reset the SysTick. */ + portNVIC_SYSTICK_CTRL_REG = 0UL; + portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL; + + /* Configure SysTick to interrupt at the requested rate. */ + portNVIC_SYSTICK_LOAD_REG = ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) - 1UL; + portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT; +} +/*-----------------------------------------------------------*/ + +#if ( configUSE_TICKLESS_IDLE == 1 ) + + __weak void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime ) + { + uint32_t ulReloadValue, ulCompleteTickPeriods, ulCompletedSysTickDecrements; + TickType_t xModifiableIdleTime; + + /* Make sure the SysTick reload value does not overflow the counter. */ + if( xExpectedIdleTime > xMaximumPossibleSuppressedTicks ) + { + xExpectedIdleTime = xMaximumPossibleSuppressedTicks; + } + + /* Stop the SysTick momentarily. The time the SysTick is stopped for + * is accounted for as best it can be, but using the tickless mode will + * inevitably result in some tiny drift of the time maintained by the + * kernel with respect to calendar time. */ + portNVIC_SYSTICK_CTRL_REG &= ~portNVIC_SYSTICK_ENABLE_BIT; + + /* Calculate the reload value required to wait xExpectedIdleTime + * tick periods. -1 is used because this code will execute part way + * through one of the tick periods. */ + ulReloadValue = portNVIC_SYSTICK_CURRENT_VALUE_REG + ( ulTimerCountsForOneTick * ( xExpectedIdleTime - 1UL ) ); + + if( ulReloadValue > ulStoppedTimerCompensation ) + { + ulReloadValue -= ulStoppedTimerCompensation; + } + + /* Enter a critical section but don't use the taskENTER_CRITICAL() + * method as that will mask interrupts that should exit sleep mode. */ + __disable_interrupt(); + __DSB(); + __ISB(); + + /* If a context switch is pending or a task is waiting for the scheduler + * to be unsuspended then abandon the low power entry. */ + if( eTaskConfirmSleepModeStatus() == eAbortSleep ) + { + /* Restart from whatever is left in the count register to complete + * this tick period. */ + portNVIC_SYSTICK_LOAD_REG = portNVIC_SYSTICK_CURRENT_VALUE_REG; + + /* Restart SysTick. */ + portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT; + + /* Reset the reload register to the value required for normal tick + * periods. */ + portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL; + + /* Re-enable interrupts - see comments above __disable_interrupt() + * call above. */ + __enable_interrupt(); + } + else + { + /* Set the new reload value. */ + portNVIC_SYSTICK_LOAD_REG = ulReloadValue; + + /* Clear the SysTick count flag and set the count value back to + * zero. */ + portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL; + + /* Restart SysTick. */ + portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT; + + /* Sleep until something happens. configPRE_SLEEP_PROCESSING() can + * set its parameter to 0 to indicate that its implementation contains + * its own wait for interrupt or wait for event instruction, and so wfi + * should not be executed again. However, the original expected idle + * time variable must remain unmodified, so a copy is taken. */ + xModifiableIdleTime = xExpectedIdleTime; + configPRE_SLEEP_PROCESSING( xModifiableIdleTime ); + + if( xModifiableIdleTime > 0 ) + { + __DSB(); + __WFI(); + __ISB(); + } + + configPOST_SLEEP_PROCESSING( xExpectedIdleTime ); + + /* Re-enable interrupts to allow the interrupt that brought the MCU + * out of sleep mode to execute immediately. see comments above + * __disable_interrupt() call above. */ + __enable_interrupt(); + __DSB(); + __ISB(); + + /* Disable interrupts again because the clock is about to be stopped + * and interrupts that execute while the clock is stopped will increase + * any slippage between the time maintained by the RTOS and calendar + * time. */ + __disable_interrupt(); + __DSB(); + __ISB(); + + /* Disable the SysTick clock without reading the + * portNVIC_SYSTICK_CTRL_REG register to ensure the + * portNVIC_SYSTICK_COUNT_FLAG_BIT is not cleared if it is set. Again, + * the time the SysTick is stopped for is accounted for as best it can + * be, but using the tickless mode will inevitably result in some tiny + * drift of the time maintained by the kernel with respect to calendar + * time*/ + portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT ); + + /* Determine if the SysTick clock has already counted to zero and + * been set back to the current reload value (the reload back being + * correct for the entire expected idle time) or if the SysTick is yet + * to count to zero (in which case an interrupt other than the SysTick + * must have brought the system out of sleep mode). */ + if( ( portNVIC_SYSTICK_CTRL_REG & portNVIC_SYSTICK_COUNT_FLAG_BIT ) != 0 ) + { + uint32_t ulCalculatedLoadValue; + + /* The tick interrupt is already pending, and the SysTick count + * reloaded with ulReloadValue. Reset the + * portNVIC_SYSTICK_LOAD_REG with whatever remains of this tick + * period. */ + ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL ) - ( ulReloadValue - portNVIC_SYSTICK_CURRENT_VALUE_REG ); + + /* Don't allow a tiny value, or values that have somehow + * underflowed because the post sleep hook did something + * that took too long. */ + if( ( ulCalculatedLoadValue < ulStoppedTimerCompensation ) || ( ulCalculatedLoadValue > ulTimerCountsForOneTick ) ) + { + ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL ); + } + + portNVIC_SYSTICK_LOAD_REG = ulCalculatedLoadValue; + + /* As the pending tick will be processed as soon as this + * function exits, the tick value maintained by the tick is stepped + * forward by one less than the time spent waiting. */ + ulCompleteTickPeriods = xExpectedIdleTime - 1UL; + } + else + { + /* Something other than the tick interrupt ended the sleep. + * Work out how long the sleep lasted rounded to complete tick + * periods (not the ulReload value which accounted for part + * ticks). */ + ulCompletedSysTickDecrements = ( xExpectedIdleTime * ulTimerCountsForOneTick ) - portNVIC_SYSTICK_CURRENT_VALUE_REG; + + /* How many complete tick periods passed while the processor + * was waiting? */ + ulCompleteTickPeriods = ulCompletedSysTickDecrements / ulTimerCountsForOneTick; + + /* The reload value is set to whatever fraction of a single tick + * period remains. */ + portNVIC_SYSTICK_LOAD_REG = ( ( ulCompleteTickPeriods + 1UL ) * ulTimerCountsForOneTick ) - ulCompletedSysTickDecrements; + } + + /* Restart SysTick so it runs from portNVIC_SYSTICK_LOAD_REG + * again, then set portNVIC_SYSTICK_LOAD_REG back to its standard + * value. */ + portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL; + portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT; + vTaskStepTick( ulCompleteTickPeriods ); + portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL; + + /* Exit with interrpts enabled. */ + __enable_interrupt(); + } + } + +#endif /* configUSE_TICKLESS_IDLE */ diff --git a/RTOS/FreeRTOS/Source/portable/IAR/ARM_CM0/portasm.s b/RTOS/FreeRTOS/Source/portable/IAR/ARM_CM0/portasm.s new file mode 100644 index 0000000..0d3fca2 --- /dev/null +++ b/RTOS/FreeRTOS/Source/portable/IAR/ARM_CM0/portasm.s @@ -0,0 +1,131 @@ +/* + * FreeRTOS Kernel V10.4.1 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * https://www.FreeRTOS.org + * https://github.com/FreeRTOS + * + * 1 tab == 4 spaces! + */ + +#include + + RSEG CODE:CODE(2) + thumb + + EXTERN vPortYieldFromISR + EXTERN pxCurrentTCB + EXTERN vTaskSwitchContext + + PUBLIC vSetMSP + PUBLIC xPortPendSVHandler + PUBLIC vPortSVCHandler + PUBLIC vPortStartFirstTask + PUBLIC ulSetInterruptMaskFromISR + PUBLIC vClearInterruptMaskFromISR + +/*-----------------------------------------------------------*/ + +vSetMSP + msr msp, r0 + bx lr + +/*-----------------------------------------------------------*/ + +xPortPendSVHandler: + mrs r0, psp + + ldr r3, =pxCurrentTCB /* Get the location of the current TCB. */ + ldr r2, [r3] + + subs r0, r0, #32 /* Make space for the remaining low registers. */ + str r0, [r2] /* Save the new top of stack. */ + stmia r0!, {r4-r7} /* Store the low registers that are not saved automatically. */ + mov r4, r8 /* Store the high registers. */ + mov r5, r9 + mov r6, r10 + mov r7, r11 + stmia r0!, {r4-r7} + + push {r3, r14} + cpsid i + bl vTaskSwitchContext + cpsie i + pop {r2, r3} /* lr goes in r3. r2 now holds tcb pointer. */ + + ldr r1, [r2] + ldr r0, [r1] /* The first item in pxCurrentTCB is the task top of stack. */ + adds r0, r0, #16 /* Move to the high registers. */ + ldmia r0!, {r4-r7} /* Pop the high registers. */ + mov r8, r4 + mov r9, r5 + mov r10, r6 + mov r11, r7 + + msr psp, r0 /* Remember the new top of stack for the task. */ + + subs r0, r0, #32 /* Go back for the low registers that are not automatically restored. */ + ldmia r0!, {r4-r7} /* Pop low registers. */ + + bx r3 + +/*-----------------------------------------------------------*/ + +vPortSVCHandler; + /* This function is no longer used, but retained for backward + compatibility. */ + bx lr + +/*-----------------------------------------------------------*/ + +vPortStartFirstTask + /* The MSP stack is not reset as, unlike on M3/4 parts, there is no vector + table offset register that can be used to locate the initial stack value. + Not all M0 parts have the application vector table at address 0. */ + + ldr r3, =pxCurrentTCB /* Obtain location of pxCurrentTCB. */ + ldr r1, [r3] + ldr r0, [r1] /* The first item in pxCurrentTCB is the task top of stack. */ + adds r0, #32 /* Discard everything up to r0. */ + msr psp, r0 /* This is now the new top of stack to use in the task. */ + movs r0, #2 /* Switch to the psp stack. */ + msr CONTROL, r0 + isb + pop {r0-r5} /* Pop the registers that are saved automatically. */ + mov lr, r5 /* lr is now in r5. */ + pop {r3} /* The return address is now in r3. */ + pop {r2} /* Pop and discard the XPSR. */ + cpsie i /* The first task has its context and interrupts can be enabled. */ + bx r3 /* Jump to the user defined task code. */ + +/*-----------------------------------------------------------*/ + +ulSetInterruptMaskFromISR + mrs r0, PRIMASK + cpsid i + bx lr + +/*-----------------------------------------------------------*/ + +vClearInterruptMaskFromISR + msr PRIMASK, r0 + bx lr + + END diff --git a/RTOS/FreeRTOS/Source/portable/IAR/ARM_CM0/portmacro.h b/RTOS/FreeRTOS/Source/portable/IAR/ARM_CM0/portmacro.h new file mode 100644 index 0000000..1feb439 --- /dev/null +++ b/RTOS/FreeRTOS/Source/portable/IAR/ARM_CM0/portmacro.h @@ -0,0 +1,128 @@ +/* + * FreeRTOS Kernel V10.4.1 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * https://www.FreeRTOS.org + * https://github.com/FreeRTOS + * + * 1 tab == 4 spaces! + */ + + +#ifndef PORTMACRO_H + #define PORTMACRO_H + + #ifdef __cplusplus + extern "C" { + #endif + +/*----------------------------------------------------------- + * Port specific definitions. + * + * The settings in this file configure FreeRTOS correctly for the + * given hardware and compiler. + * + * These settings should not be altered. + *----------------------------------------------------------- + */ + +/* Type definitions. */ + #define portCHAR char + #define portFLOAT float + #define portDOUBLE double + #define portLONG long + #define portSHORT short + #define portSTACK_TYPE uint32_t + #define portBASE_TYPE long + + typedef portSTACK_TYPE StackType_t; + typedef long BaseType_t; + typedef unsigned long UBaseType_t; + + + #if ( configUSE_16_BIT_TICKS == 1 ) + typedef uint16_t TickType_t; + #define portMAX_DELAY ( TickType_t ) 0xffff + #else + typedef uint32_t TickType_t; + #define portMAX_DELAY ( TickType_t ) 0xffffffffUL + +/* 32-bit tick type on a 32-bit architecture, so reads of the tick count do + * not need to be guarded with a critical section. */ + #define portTICK_TYPE_IS_ATOMIC 1 + #endif +/*-----------------------------------------------------------*/ + +/* Architecture specifics. */ + #define portSTACK_GROWTH ( -1 ) + #define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ ) + #define portBYTE_ALIGNMENT 8 +/*-----------------------------------------------------------*/ + + +/* Scheduler utilities. */ + extern void vPortYield( void ); + #define portNVIC_INT_CTRL ( ( volatile uint32_t * ) 0xe000ed04 ) + #define portNVIC_PENDSVSET 0x10000000 + #define portYIELD() vPortYield() + #define portEND_SWITCHING_ISR( xSwitchRequired ) if( xSwitchRequired ) *( portNVIC_INT_CTRL ) = portNVIC_PENDSVSET + #define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x ) +/*-----------------------------------------------------------*/ + + +/* Critical section management. */ + + extern void vPortEnterCritical( void ); + extern void vPortExitCritical( void ); + extern uint32_t ulSetInterruptMaskFromISR( void ); + extern void vClearInterruptMaskFromISR( uint32_t ulMask ); + + #define portDISABLE_INTERRUPTS() __asm volatile ( "cpsid i" ) + #define portENABLE_INTERRUPTS() __asm volatile ( "cpsie i" ) + #define portENTER_CRITICAL() vPortEnterCritical() + #define portEXIT_CRITICAL() vPortExitCritical() + #define portSET_INTERRUPT_MASK_FROM_ISR() ulSetInterruptMaskFromISR() + #define portCLEAR_INTERRUPT_MASK_FROM_ISR( x ) vClearInterruptMaskFromISR( x ) + +/*-----------------------------------------------------------*/ + +/* Tickless idle/low power functionality. */ + #ifndef portSUPPRESS_TICKS_AND_SLEEP + extern void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime ); + #define portSUPPRESS_TICKS_AND_SLEEP( xExpectedIdleTime ) vPortSuppressTicksAndSleep( xExpectedIdleTime ) + #endif +/*-----------------------------------------------------------*/ + +/* Task function macros as described on the FreeRTOS.org WEB site. */ + #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void * pvParameters ) + #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void * pvParameters ) + + #define portNOP() + +/* Suppress warnings that are generated by the IAR tools, but cannot be fixed in + * the source code because to do so would cause other compilers to generate + * warnings. */ + #pragma diag_suppress=Pa082 + + #ifdef __cplusplus + } + #endif + +#endif /* PORTMACRO_H */ diff --git a/RTOS/FreeRTOS/Source/portable/MemMang/ReadMe.url b/RTOS/FreeRTOS/Source/portable/MemMang/ReadMe.url new file mode 100644 index 0000000..28c9937 --- /dev/null +++ b/RTOS/FreeRTOS/Source/portable/MemMang/ReadMe.url @@ -0,0 +1,5 @@ +[{000214A0-0000-0000-C000-000000000046}] +Prop3=19,2 +[InternetShortcut] +URL=https://www.FreeRTOS.org/a00111.html +IDList= diff --git a/RTOS/FreeRTOS/Source/portable/MemMang/heap_1.c b/RTOS/FreeRTOS/Source/portable/MemMang/heap_1.c new file mode 100644 index 0000000..d9b0171 --- /dev/null +++ b/RTOS/FreeRTOS/Source/portable/MemMang/heap_1.c @@ -0,0 +1,144 @@ +/* + * FreeRTOS Kernel V10.4.1 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * https://www.FreeRTOS.org + * https://github.com/FreeRTOS + * + * 1 tab == 4 spaces! + */ + + +/* + * The simplest possible implementation of pvPortMalloc(). Note that this + * implementation does NOT allow allocated memory to be freed again. + * + * See heap_2.c, heap_3.c and heap_4.c for alternative implementations, and the + * memory management pages of https://www.FreeRTOS.org for more information. + */ +#include + +/* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining + * all the API functions to use the MPU wrappers. That should only be done when + * task.h is included from an application file. */ +#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE + +#include "FreeRTOS.h" +#include "task.h" + +#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE + +#if ( configSUPPORT_DYNAMIC_ALLOCATION == 0 ) + #error This file must not be used if configSUPPORT_DYNAMIC_ALLOCATION is 0 +#endif + +/* A few bytes might be lost to byte aligning the heap start address. */ +#define configADJUSTED_HEAP_SIZE ( configTOTAL_HEAP_SIZE - portBYTE_ALIGNMENT ) + +/* Allocate the memory for the heap. */ +#if ( configAPPLICATION_ALLOCATED_HEAP == 1 ) + +/* The application writer has already defined the array used for the RTOS +* heap - probably so it can be placed in a special segment or address. */ + extern uint8_t ucHeap[ configTOTAL_HEAP_SIZE ]; +#else + static uint8_t ucHeap[ configTOTAL_HEAP_SIZE ]; +#endif /* configAPPLICATION_ALLOCATED_HEAP */ + +/* Index into the ucHeap array. */ +static size_t xNextFreeByte = ( size_t ) 0; + +/*-----------------------------------------------------------*/ + +void * pvPortMalloc( size_t xWantedSize ) +{ + void * pvReturn = NULL; + static uint8_t * pucAlignedHeap = NULL; + + /* Ensure that blocks are always aligned to the required number of bytes. */ + #if ( portBYTE_ALIGNMENT != 1 ) + { + if( xWantedSize & portBYTE_ALIGNMENT_MASK ) + { + /* Byte alignment required. */ + xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) ); + } + } + #endif + + vTaskSuspendAll(); + { + if( pucAlignedHeap == NULL ) + { + /* Ensure the heap starts on a correctly aligned boundary. */ + pucAlignedHeap = ( uint8_t * ) ( ( ( portPOINTER_SIZE_TYPE ) & ucHeap[ portBYTE_ALIGNMENT ] ) & ( ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) ) ); + } + + /* Check there is enough room left for the allocation. */ + if( ( ( xNextFreeByte + xWantedSize ) < configADJUSTED_HEAP_SIZE ) && + ( ( xNextFreeByte + xWantedSize ) > xNextFreeByte ) ) /* Check for overflow. */ + { + /* Return the next free byte then increment the index past this + * block. */ + pvReturn = pucAlignedHeap + xNextFreeByte; + xNextFreeByte += xWantedSize; + } + + traceMALLOC( pvReturn, xWantedSize ); + } + ( void ) xTaskResumeAll(); + + #if ( configUSE_MALLOC_FAILED_HOOK == 1 ) + { + if( pvReturn == NULL ) + { + extern void vApplicationMallocFailedHook( void ); + vApplicationMallocFailedHook(); + } + } + #endif + + return pvReturn; +} +/*-----------------------------------------------------------*/ + +void vPortFree( void * pv ) +{ + /* Memory cannot be freed using this scheme. See heap_2.c, heap_3.c and + * heap_4.c for alternative implementations, and the memory management pages of + * https://www.FreeRTOS.org for more information. */ + ( void ) pv; + + /* Force an assert as it is invalid to call this function. */ + configASSERT( pv == NULL ); +} +/*-----------------------------------------------------------*/ + +void vPortInitialiseBlocks( void ) +{ + /* Only required when static memory is not cleared. */ + xNextFreeByte = ( size_t ) 0; +} +/*-----------------------------------------------------------*/ + +size_t xPortGetFreeHeapSize( void ) +{ + return( configADJUSTED_HEAP_SIZE - xNextFreeByte ); +} diff --git a/RTOS/FreeRTOS/Source/portable/MemMang/heap_2.c b/RTOS/FreeRTOS/Source/portable/MemMang/heap_2.c new file mode 100644 index 0000000..0f248a5 --- /dev/null +++ b/RTOS/FreeRTOS/Source/portable/MemMang/heap_2.c @@ -0,0 +1,274 @@ +/* + * FreeRTOS Kernel V10.4.1 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * https://www.FreeRTOS.org + * https://github.com/FreeRTOS + * + * 1 tab == 4 spaces! + */ + +/* + * A sample implementation of pvPortMalloc() and vPortFree() that permits + * allocated blocks to be freed, but does not combine adjacent free blocks + * into a single larger block (and so will fragment memory). See heap_4.c for + * an equivalent that does combine adjacent blocks into single larger blocks. + * + * See heap_1.c, heap_3.c and heap_4.c for alternative implementations, and the + * memory management pages of https://www.FreeRTOS.org for more information. + */ +#include + +/* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining + * all the API functions to use the MPU wrappers. That should only be done when + * task.h is included from an application file. */ +#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE + +#include "FreeRTOS.h" +#include "task.h" + +#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE + +#if ( configSUPPORT_DYNAMIC_ALLOCATION == 0 ) + #error This file must not be used if configSUPPORT_DYNAMIC_ALLOCATION is 0 +#endif + +/* A few bytes might be lost to byte aligning the heap start address. */ +#define configADJUSTED_HEAP_SIZE ( configTOTAL_HEAP_SIZE - portBYTE_ALIGNMENT ) + +/* + * Initialises the heap structures before their first use. + */ +static void prvHeapInit( void ); + +/* Allocate the memory for the heap. */ +#if ( configAPPLICATION_ALLOCATED_HEAP == 1 ) + +/* The application writer has already defined the array used for the RTOS +* heap - probably so it can be placed in a special segment or address. */ + extern uint8_t ucHeap[ configTOTAL_HEAP_SIZE ]; +#else + static uint8_t ucHeap[ configTOTAL_HEAP_SIZE ]; +#endif /* configAPPLICATION_ALLOCATED_HEAP */ + + +/* Define the linked list structure. This is used to link free blocks in order + * of their size. */ +typedef struct A_BLOCK_LINK +{ + struct A_BLOCK_LINK * pxNextFreeBlock; /*<< The next free block in the list. */ + size_t xBlockSize; /*<< The size of the free block. */ +} BlockLink_t; + + +static const uint16_t heapSTRUCT_SIZE = ( ( sizeof( BlockLink_t ) + ( portBYTE_ALIGNMENT - 1 ) ) & ~portBYTE_ALIGNMENT_MASK ); +#define heapMINIMUM_BLOCK_SIZE ( ( size_t ) ( heapSTRUCT_SIZE * 2 ) ) + +/* Create a couple of list links to mark the start and end of the list. */ +static BlockLink_t xStart, xEnd; + +/* Keeps track of the number of free bytes remaining, but says nothing about + * fragmentation. */ +static size_t xFreeBytesRemaining = configADJUSTED_HEAP_SIZE; + +/* STATIC FUNCTIONS ARE DEFINED AS MACROS TO MINIMIZE THE FUNCTION CALL DEPTH. */ + +/* + * Insert a block into the list of free blocks - which is ordered by size of + * the block. Small blocks at the start of the list and large blocks at the end + * of the list. + */ +#define prvInsertBlockIntoFreeList( pxBlockToInsert ) \ + { \ + BlockLink_t * pxIterator; \ + size_t xBlockSize; \ + \ + xBlockSize = pxBlockToInsert->xBlockSize; \ + \ + /* Iterate through the list until a block is found that has a larger size */ \ + /* than the block we are inserting. */ \ + for( pxIterator = &xStart; pxIterator->pxNextFreeBlock->xBlockSize < xBlockSize; pxIterator = pxIterator->pxNextFreeBlock ) \ + { \ + /* There is nothing to do here - just iterate to the correct position. */ \ + } \ + \ + /* Update the list to include the block being inserted in the correct */ \ + /* position. */ \ + pxBlockToInsert->pxNextFreeBlock = pxIterator->pxNextFreeBlock; \ + pxIterator->pxNextFreeBlock = pxBlockToInsert; \ + } +/*-----------------------------------------------------------*/ + +void * pvPortMalloc( size_t xWantedSize ) +{ + BlockLink_t * pxBlock, * pxPreviousBlock, * pxNewBlockLink; + static BaseType_t xHeapHasBeenInitialised = pdFALSE; + void * pvReturn = NULL; + + vTaskSuspendAll(); + { + /* If this is the first call to malloc then the heap will require + * initialisation to setup the list of free blocks. */ + if( xHeapHasBeenInitialised == pdFALSE ) + { + prvHeapInit(); + xHeapHasBeenInitialised = pdTRUE; + } + + /* The wanted size is increased so it can contain a BlockLink_t + * structure in addition to the requested amount of bytes. */ + if( xWantedSize > 0 ) + { + xWantedSize += heapSTRUCT_SIZE; + + /* Ensure that blocks are always aligned to the required number of bytes. */ + if( ( xWantedSize & portBYTE_ALIGNMENT_MASK ) != 0 ) + { + /* Byte alignment required. */ + xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) ); + } + } + + if( ( xWantedSize > 0 ) && ( xWantedSize < configADJUSTED_HEAP_SIZE ) ) + { + /* Blocks are stored in byte order - traverse the list from the start + * (smallest) block until one of adequate size is found. */ + pxPreviousBlock = &xStart; + pxBlock = xStart.pxNextFreeBlock; + + while( ( pxBlock->xBlockSize < xWantedSize ) && ( pxBlock->pxNextFreeBlock != NULL ) ) + { + pxPreviousBlock = pxBlock; + pxBlock = pxBlock->pxNextFreeBlock; + } + + /* If we found the end marker then a block of adequate size was not found. */ + if( pxBlock != &xEnd ) + { + /* Return the memory space - jumping over the BlockLink_t structure + * at its start. */ + pvReturn = ( void * ) ( ( ( uint8_t * ) pxPreviousBlock->pxNextFreeBlock ) + heapSTRUCT_SIZE ); + + /* This block is being returned for use so must be taken out of the + * list of free blocks. */ + pxPreviousBlock->pxNextFreeBlock = pxBlock->pxNextFreeBlock; + + /* If the block is larger than required it can be split into two. */ + if( ( pxBlock->xBlockSize - xWantedSize ) > heapMINIMUM_BLOCK_SIZE ) + { + /* This block is to be split into two. Create a new block + * following the number of bytes requested. The void cast is + * used to prevent byte alignment warnings from the compiler. */ + pxNewBlockLink = ( void * ) ( ( ( uint8_t * ) pxBlock ) + xWantedSize ); + + /* Calculate the sizes of two blocks split from the single + * block. */ + pxNewBlockLink->xBlockSize = pxBlock->xBlockSize - xWantedSize; + pxBlock->xBlockSize = xWantedSize; + + /* Insert the new block into the list of free blocks. */ + prvInsertBlockIntoFreeList( ( pxNewBlockLink ) ); + } + + xFreeBytesRemaining -= pxBlock->xBlockSize; + } + } + + traceMALLOC( pvReturn, xWantedSize ); + } + ( void ) xTaskResumeAll(); + + #if ( configUSE_MALLOC_FAILED_HOOK == 1 ) + { + if( pvReturn == NULL ) + { + extern void vApplicationMallocFailedHook( void ); + vApplicationMallocFailedHook(); + } + } + #endif + + return pvReturn; +} +/*-----------------------------------------------------------*/ + +void vPortFree( void * pv ) +{ + uint8_t * puc = ( uint8_t * ) pv; + BlockLink_t * pxLink; + + if( pv != NULL ) + { + /* The memory being freed will have an BlockLink_t structure immediately + * before it. */ + puc -= heapSTRUCT_SIZE; + + /* This unexpected casting is to keep some compilers from issuing + * byte alignment warnings. */ + pxLink = ( void * ) puc; + + vTaskSuspendAll(); + { + /* Add this block to the list of free blocks. */ + prvInsertBlockIntoFreeList( ( ( BlockLink_t * ) pxLink ) ); + xFreeBytesRemaining += pxLink->xBlockSize; + traceFREE( pv, pxLink->xBlockSize ); + } + ( void ) xTaskResumeAll(); + } +} +/*-----------------------------------------------------------*/ + +size_t xPortGetFreeHeapSize( void ) +{ + return xFreeBytesRemaining; +} +/*-----------------------------------------------------------*/ + +void vPortInitialiseBlocks( void ) +{ + /* This just exists to keep the linker quiet. */ +} +/*-----------------------------------------------------------*/ + +static void prvHeapInit( void ) +{ + BlockLink_t * pxFirstFreeBlock; + uint8_t * pucAlignedHeap; + + /* Ensure the heap starts on a correctly aligned boundary. */ + pucAlignedHeap = ( uint8_t * ) ( ( ( portPOINTER_SIZE_TYPE ) & ucHeap[ portBYTE_ALIGNMENT ] ) & ( ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) ) ); + + /* xStart is used to hold a pointer to the first item in the list of free + * blocks. The void cast is used to prevent compiler warnings. */ + xStart.pxNextFreeBlock = ( void * ) pucAlignedHeap; + xStart.xBlockSize = ( size_t ) 0; + + /* xEnd is used to mark the end of the list of free blocks. */ + xEnd.xBlockSize = configADJUSTED_HEAP_SIZE; + xEnd.pxNextFreeBlock = NULL; + + /* To start with there is a single free block that is sized to take up the + * entire heap space. */ + pxFirstFreeBlock = ( void * ) pucAlignedHeap; + pxFirstFreeBlock->xBlockSize = configADJUSTED_HEAP_SIZE; + pxFirstFreeBlock->pxNextFreeBlock = &xEnd; +} +/*-----------------------------------------------------------*/ diff --git a/RTOS/FreeRTOS/Source/portable/MemMang/heap_3.c b/RTOS/FreeRTOS/Source/portable/MemMang/heap_3.c new file mode 100644 index 0000000..8dd422c --- /dev/null +++ b/RTOS/FreeRTOS/Source/portable/MemMang/heap_3.c @@ -0,0 +1,94 @@ +/* + * FreeRTOS Kernel V10.4.1 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * https://www.FreeRTOS.org + * https://github.com/FreeRTOS + * + * 1 tab == 4 spaces! + */ + + +/* + * Implementation of pvPortMalloc() and vPortFree() that relies on the + * compilers own malloc() and free() implementations. + * + * This file can only be used if the linker is configured to to generate + * a heap memory area. + * + * See heap_1.c, heap_2.c and heap_4.c for alternative implementations, and the + * memory management pages of https://www.FreeRTOS.org for more information. + */ + +#include + +/* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining + * all the API functions to use the MPU wrappers. That should only be done when + * task.h is included from an application file. */ +#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE + +#include "FreeRTOS.h" +#include "task.h" + +#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE + +#if ( configSUPPORT_DYNAMIC_ALLOCATION == 0 ) + #error This file must not be used if configSUPPORT_DYNAMIC_ALLOCATION is 0 +#endif + +/*-----------------------------------------------------------*/ + +void * pvPortMalloc( size_t xWantedSize ) +{ + void * pvReturn; + + vTaskSuspendAll(); + { + pvReturn = malloc( xWantedSize ); + traceMALLOC( pvReturn, xWantedSize ); + } + ( void ) xTaskResumeAll(); + + #if ( configUSE_MALLOC_FAILED_HOOK == 1 ) + { + if( pvReturn == NULL ) + { + extern void vApplicationMallocFailedHook( void ); + vApplicationMallocFailedHook(); + } + } + #endif + + return pvReturn; +} +/*-----------------------------------------------------------*/ + +void vPortFree( void * pv ) +{ + if( pv ) + { + vTaskSuspendAll(); + { + free( pv ); + traceFREE( pv, 0 ); + } + ( void ) xTaskResumeAll(); + } +} diff --git a/RTOS/FreeRTOS/Source/portable/MemMang/heap_4.c b/RTOS/FreeRTOS/Source/portable/MemMang/heap_4.c new file mode 100644 index 0000000..946faf0 --- /dev/null +++ b/RTOS/FreeRTOS/Source/portable/MemMang/heap_4.c @@ -0,0 +1,494 @@ +/* + * FreeRTOS Kernel V10.4.1 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * https://www.FreeRTOS.org + * https://github.com/FreeRTOS + * + */ + +/* + * A sample implementation of pvPortMalloc() and vPortFree() that combines + * (coalescences) adjacent memory blocks as they are freed, and in so doing + * limits memory fragmentation. + * + * See heap_1.c, heap_2.c and heap_3.c for alternative implementations, and the + * memory management pages of https://www.FreeRTOS.org for more information. + */ +#include + +/* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining + * all the API functions to use the MPU wrappers. That should only be done when + * task.h is included from an application file. */ +#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE + +#include "FreeRTOS.h" +#include "task.h" + +#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE + +#if ( configSUPPORT_DYNAMIC_ALLOCATION == 0 ) + #error This file must not be used if configSUPPORT_DYNAMIC_ALLOCATION is 0 +#endif + +/* Block sizes must not get too small. */ +#define heapMINIMUM_BLOCK_SIZE ( ( size_t ) ( xHeapStructSize << 1 ) ) + +/* Assumes 8bit bytes! */ +#define heapBITS_PER_BYTE ( ( size_t ) 8 ) + +/* Allocate the memory for the heap. */ +#if ( configAPPLICATION_ALLOCATED_HEAP == 1 ) + +/* The application writer has already defined the array used for the RTOS +* heap - probably so it can be placed in a special segment or address. */ + extern uint8_t ucHeap[ configTOTAL_HEAP_SIZE ]; +#else + PRIVILEGED_DATA static uint8_t ucHeap[ configTOTAL_HEAP_SIZE ]; +#endif /* configAPPLICATION_ALLOCATED_HEAP */ + +/* Define the linked list structure. This is used to link free blocks in order + * of their memory address. */ +typedef struct A_BLOCK_LINK +{ + struct A_BLOCK_LINK * pxNextFreeBlock; /*<< The next free block in the list. */ + size_t xBlockSize; /*<< The size of the free block. */ +} BlockLink_t; + +/*-----------------------------------------------------------*/ + +/* + * Inserts a block of memory that is being freed into the correct position in + * the list of free memory blocks. The block being freed will be merged with + * the block in front it and/or the block behind it if the memory blocks are + * adjacent to each other. + */ +static void prvInsertBlockIntoFreeList( BlockLink_t * pxBlockToInsert ) PRIVILEGED_FUNCTION; + +/* + * Called automatically to setup the required heap structures the first time + * pvPortMalloc() is called. + */ +static void prvHeapInit( void ) PRIVILEGED_FUNCTION; + +/*-----------------------------------------------------------*/ + +/* The size of the structure placed at the beginning of each allocated memory + * block must by correctly byte aligned. */ +static const size_t xHeapStructSize = ( sizeof( BlockLink_t ) + ( ( size_t ) ( portBYTE_ALIGNMENT - 1 ) ) ) & ~( ( size_t ) portBYTE_ALIGNMENT_MASK ); + +/* Create a couple of list links to mark the start and end of the list. */ +PRIVILEGED_DATA static BlockLink_t xStart, * pxEnd = NULL; + +/* Keeps track of the number of calls to allocate and free memory as well as the + * number of free bytes remaining, but says nothing about fragmentation. */ +PRIVILEGED_DATA static size_t xFreeBytesRemaining = 0U; +PRIVILEGED_DATA static size_t xMinimumEverFreeBytesRemaining = 0U; +PRIVILEGED_DATA static size_t xNumberOfSuccessfulAllocations = 0; +PRIVILEGED_DATA static size_t xNumberOfSuccessfulFrees = 0; + +/* Gets set to the top bit of an size_t type. When this bit in the xBlockSize + * member of an BlockLink_t structure is set then the block belongs to the + * application. When the bit is free the block is still part of the free heap + * space. */ +PRIVILEGED_DATA static size_t xBlockAllocatedBit = 0; + +/*-----------------------------------------------------------*/ + +void * pvPortMalloc( size_t xWantedSize ) +{ + BlockLink_t * pxBlock, * pxPreviousBlock, * pxNewBlockLink; + void * pvReturn = NULL; + + vTaskSuspendAll(); + { + /* If this is the first call to malloc then the heap will require + * initialisation to setup the list of free blocks. */ + if( pxEnd == NULL ) + { + prvHeapInit(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* Check the requested block size is not so large that the top bit is + * set. The top bit of the block size member of the BlockLink_t structure + * is used to determine who owns the block - the application or the + * kernel, so it must be free. */ + if( ( xWantedSize & xBlockAllocatedBit ) == 0 ) + { + /* The wanted size is increased so it can contain a BlockLink_t + * structure in addition to the requested amount of bytes. */ + if( xWantedSize > 0 ) + { + xWantedSize += xHeapStructSize; + + /* Ensure that blocks are always aligned to the required number + * of bytes. */ + if( ( xWantedSize & portBYTE_ALIGNMENT_MASK ) != 0x00 ) + { + /* Byte alignment required. */ + xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) ); + configASSERT( ( xWantedSize & portBYTE_ALIGNMENT_MASK ) == 0 ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + if( ( xWantedSize > 0 ) && ( xWantedSize <= xFreeBytesRemaining ) ) + { + /* Traverse the list from the start (lowest address) block until + * one of adequate size is found. */ + pxPreviousBlock = &xStart; + pxBlock = xStart.pxNextFreeBlock; + + while( ( pxBlock->xBlockSize < xWantedSize ) && ( pxBlock->pxNextFreeBlock != NULL ) ) + { + pxPreviousBlock = pxBlock; + pxBlock = pxBlock->pxNextFreeBlock; + } + + /* If the end marker was reached then a block of adequate size + * was not found. */ + if( pxBlock != pxEnd ) + { + /* Return the memory space pointed to - jumping over the + * BlockLink_t structure at its start. */ + pvReturn = ( void * ) ( ( ( uint8_t * ) pxPreviousBlock->pxNextFreeBlock ) + xHeapStructSize ); + + /* This block is being returned for use so must be taken out + * of the list of free blocks. */ + pxPreviousBlock->pxNextFreeBlock = pxBlock->pxNextFreeBlock; + + /* If the block is larger than required it can be split into + * two. */ + if( ( pxBlock->xBlockSize - xWantedSize ) > heapMINIMUM_BLOCK_SIZE ) + { + /* This block is to be split into two. Create a new + * block following the number of bytes requested. The void + * cast is used to prevent byte alignment warnings from the + * compiler. */ + pxNewBlockLink = ( void * ) ( ( ( uint8_t * ) pxBlock ) + xWantedSize ); + configASSERT( ( ( ( size_t ) pxNewBlockLink ) & portBYTE_ALIGNMENT_MASK ) == 0 ); + + /* Calculate the sizes of two blocks split from the + * single block. */ + pxNewBlockLink->xBlockSize = pxBlock->xBlockSize - xWantedSize; + pxBlock->xBlockSize = xWantedSize; + + /* Insert the new block into the list of free blocks. */ + prvInsertBlockIntoFreeList( pxNewBlockLink ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + xFreeBytesRemaining -= pxBlock->xBlockSize; + + if( xFreeBytesRemaining < xMinimumEverFreeBytesRemaining ) + { + xMinimumEverFreeBytesRemaining = xFreeBytesRemaining; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* The block is being returned - it is allocated and owned + * by the application and has no "next" block. */ + pxBlock->xBlockSize |= xBlockAllocatedBit; + pxBlock->pxNextFreeBlock = NULL; + xNumberOfSuccessfulAllocations++; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + traceMALLOC( pvReturn, xWantedSize ); + } + ( void ) xTaskResumeAll(); + + #if ( configUSE_MALLOC_FAILED_HOOK == 1 ) + { + if( pvReturn == NULL ) + { + extern void vApplicationMallocFailedHook( void ); + vApplicationMallocFailedHook(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + #endif /* if ( configUSE_MALLOC_FAILED_HOOK == 1 ) */ + + configASSERT( ( ( ( size_t ) pvReturn ) & ( size_t ) portBYTE_ALIGNMENT_MASK ) == 0 ); + return pvReturn; +} +/*-----------------------------------------------------------*/ + +void vPortFree( void * pv ) +{ + uint8_t * puc = ( uint8_t * ) pv; + BlockLink_t * pxLink; + + if( pv != NULL ) + { + /* The memory being freed will have an BlockLink_t structure immediately + * before it. */ + puc -= xHeapStructSize; + + /* This casting is to keep the compiler from issuing warnings. */ + pxLink = ( void * ) puc; + + /* Check the block is actually allocated. */ + configASSERT( ( pxLink->xBlockSize & xBlockAllocatedBit ) != 0 ); + configASSERT( pxLink->pxNextFreeBlock == NULL ); + + if( ( pxLink->xBlockSize & xBlockAllocatedBit ) != 0 ) + { + if( pxLink->pxNextFreeBlock == NULL ) + { + /* The block is being returned to the heap - it is no longer + * allocated. */ + pxLink->xBlockSize &= ~xBlockAllocatedBit; + + vTaskSuspendAll(); + { + /* Add this block to the list of free blocks. */ + xFreeBytesRemaining += pxLink->xBlockSize; + traceFREE( pv, pxLink->xBlockSize ); + prvInsertBlockIntoFreeList( ( ( BlockLink_t * ) pxLink ) ); + xNumberOfSuccessfulFrees++; + } + ( void ) xTaskResumeAll(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } +} +/*-----------------------------------------------------------*/ + +size_t xPortGetFreeHeapSize( void ) +{ + return xFreeBytesRemaining; +} +/*-----------------------------------------------------------*/ + +size_t xPortGetMinimumEverFreeHeapSize( void ) +{ + return xMinimumEverFreeBytesRemaining; +} +/*-----------------------------------------------------------*/ + +void vPortInitialiseBlocks( void ) +{ + /* This just exists to keep the linker quiet. */ +} +/*-----------------------------------------------------------*/ + +static void prvHeapInit( void ) /* PRIVILEGED_FUNCTION */ +{ + BlockLink_t * pxFirstFreeBlock; + uint8_t * pucAlignedHeap; + size_t uxAddress; + size_t xTotalHeapSize = configTOTAL_HEAP_SIZE; + + /* Ensure the heap starts on a correctly aligned boundary. */ + uxAddress = ( size_t ) ucHeap; + + if( ( uxAddress & portBYTE_ALIGNMENT_MASK ) != 0 ) + { + uxAddress += ( portBYTE_ALIGNMENT - 1 ); + uxAddress &= ~( ( size_t ) portBYTE_ALIGNMENT_MASK ); + xTotalHeapSize -= uxAddress - ( size_t ) ucHeap; + } + + pucAlignedHeap = ( uint8_t * ) uxAddress; + + /* xStart is used to hold a pointer to the first item in the list of free + * blocks. The void cast is used to prevent compiler warnings. */ + xStart.pxNextFreeBlock = ( void * ) pucAlignedHeap; + xStart.xBlockSize = ( size_t ) 0; + + /* pxEnd is used to mark the end of the list of free blocks and is inserted + * at the end of the heap space. */ + uxAddress = ( ( size_t ) pucAlignedHeap ) + xTotalHeapSize; + uxAddress -= xHeapStructSize; + uxAddress &= ~( ( size_t ) portBYTE_ALIGNMENT_MASK ); + pxEnd = ( void * ) uxAddress; + pxEnd->xBlockSize = 0; + pxEnd->pxNextFreeBlock = NULL; + + /* To start with there is a single free block that is sized to take up the + * entire heap space, minus the space taken by pxEnd. */ + pxFirstFreeBlock = ( void * ) pucAlignedHeap; + pxFirstFreeBlock->xBlockSize = uxAddress - ( size_t ) pxFirstFreeBlock; + pxFirstFreeBlock->pxNextFreeBlock = pxEnd; + + /* Only one block exists - and it covers the entire usable heap space. */ + xMinimumEverFreeBytesRemaining = pxFirstFreeBlock->xBlockSize; + xFreeBytesRemaining = pxFirstFreeBlock->xBlockSize; + + /* Work out the position of the top bit in a size_t variable. */ + xBlockAllocatedBit = ( ( size_t ) 1 ) << ( ( sizeof( size_t ) * heapBITS_PER_BYTE ) - 1 ); +} +/*-----------------------------------------------------------*/ + +static void prvInsertBlockIntoFreeList( BlockLink_t * pxBlockToInsert ) /* PRIVILEGED_FUNCTION */ +{ + BlockLink_t * pxIterator; + uint8_t * puc; + + /* Iterate through the list until a block is found that has a higher address + * than the block being inserted. */ + for( pxIterator = &xStart; pxIterator->pxNextFreeBlock < pxBlockToInsert; pxIterator = pxIterator->pxNextFreeBlock ) + { + /* Nothing to do here, just iterate to the right position. */ + } + + /* Do the block being inserted, and the block it is being inserted after + * make a contiguous block of memory? */ + puc = ( uint8_t * ) pxIterator; + + if( ( puc + pxIterator->xBlockSize ) == ( uint8_t * ) pxBlockToInsert ) + { + pxIterator->xBlockSize += pxBlockToInsert->xBlockSize; + pxBlockToInsert = pxIterator; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* Do the block being inserted, and the block it is being inserted before + * make a contiguous block of memory? */ + puc = ( uint8_t * ) pxBlockToInsert; + + if( ( puc + pxBlockToInsert->xBlockSize ) == ( uint8_t * ) pxIterator->pxNextFreeBlock ) + { + if( pxIterator->pxNextFreeBlock != pxEnd ) + { + /* Form one big block from the two blocks. */ + pxBlockToInsert->xBlockSize += pxIterator->pxNextFreeBlock->xBlockSize; + pxBlockToInsert->pxNextFreeBlock = pxIterator->pxNextFreeBlock->pxNextFreeBlock; + } + else + { + pxBlockToInsert->pxNextFreeBlock = pxEnd; + } + } + else + { + pxBlockToInsert->pxNextFreeBlock = pxIterator->pxNextFreeBlock; + } + + /* If the block being inserted plugged a gab, so was merged with the block + * before and the block after, then it's pxNextFreeBlock pointer will have + * already been set, and should not be set here as that would make it point + * to itself. */ + if( pxIterator != pxBlockToInsert ) + { + pxIterator->pxNextFreeBlock = pxBlockToInsert; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } +} +/*-----------------------------------------------------------*/ + +void vPortGetHeapStats( HeapStats_t * pxHeapStats ) +{ + BlockLink_t * pxBlock; + size_t xBlocks = 0, xMaxSize = 0, xMinSize = portMAX_DELAY; /* portMAX_DELAY used as a portable way of getting the maximum value. */ + + vTaskSuspendAll(); + { + pxBlock = xStart.pxNextFreeBlock; + + /* pxBlock will be NULL if the heap has not been initialised. The heap + * is initialised automatically when the first allocation is made. */ + if( pxBlock != NULL ) + { + do + { + /* Increment the number of blocks and record the largest block seen + * so far. */ + xBlocks++; + + if( pxBlock->xBlockSize > xMaxSize ) + { + xMaxSize = pxBlock->xBlockSize; + } + + if( pxBlock->xBlockSize < xMinSize ) + { + xMinSize = pxBlock->xBlockSize; + } + + /* Move to the next block in the chain until the last block is + * reached. */ + pxBlock = pxBlock->pxNextFreeBlock; + } while( pxBlock != pxEnd ); + } + } + ( void ) xTaskResumeAll(); + + pxHeapStats->xSizeOfLargestFreeBlockInBytes = xMaxSize; + pxHeapStats->xSizeOfSmallestFreeBlockInBytes = xMinSize; + pxHeapStats->xNumberOfFreeBlocks = xBlocks; + + taskENTER_CRITICAL(); + { + pxHeapStats->xAvailableHeapSpaceInBytes = xFreeBytesRemaining; + pxHeapStats->xNumberOfSuccessfulAllocations = xNumberOfSuccessfulAllocations; + pxHeapStats->xNumberOfSuccessfulFrees = xNumberOfSuccessfulFrees; + pxHeapStats->xMinimumEverFreeBytesRemaining = xMinimumEverFreeBytesRemaining; + } + taskEXIT_CRITICAL(); +} diff --git a/RTOS/FreeRTOS/Source/portable/MemMang/heap_5.c b/RTOS/FreeRTOS/Source/portable/MemMang/heap_5.c new file mode 100644 index 0000000..da30f53 --- /dev/null +++ b/RTOS/FreeRTOS/Source/portable/MemMang/heap_5.c @@ -0,0 +1,550 @@ +/* + * FreeRTOS Kernel V10.4.1 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * https://www.FreeRTOS.org + * https://github.com/FreeRTOS + * + * 1 tab == 4 spaces! + */ + +/* + * A sample implementation of pvPortMalloc() that allows the heap to be defined + * across multiple non-contigous blocks and combines (coalescences) adjacent + * memory blocks as they are freed. + * + * See heap_1.c, heap_2.c, heap_3.c and heap_4.c for alternative + * implementations, and the memory management pages of https://www.FreeRTOS.org + * for more information. + * + * Usage notes: + * + * vPortDefineHeapRegions() ***must*** be called before pvPortMalloc(). + * pvPortMalloc() will be called if any task objects (tasks, queues, event + * groups, etc.) are created, therefore vPortDefineHeapRegions() ***must*** be + * called before any other objects are defined. + * + * vPortDefineHeapRegions() takes a single parameter. The parameter is an array + * of HeapRegion_t structures. HeapRegion_t is defined in portable.h as + * + * typedef struct HeapRegion + * { + * uint8_t *pucStartAddress; << Start address of a block of memory that will be part of the heap. + * size_t xSizeInBytes; << Size of the block of memory. + * } HeapRegion_t; + * + * The array is terminated using a NULL zero sized region definition, and the + * memory regions defined in the array ***must*** appear in address order from + * low address to high address. So the following is a valid example of how + * to use the function. + * + * HeapRegion_t xHeapRegions[] = + * { + * { ( uint8_t * ) 0x80000000UL, 0x10000 }, << Defines a block of 0x10000 bytes starting at address 0x80000000 + * { ( uint8_t * ) 0x90000000UL, 0xa0000 }, << Defines a block of 0xa0000 bytes starting at address of 0x90000000 + * { NULL, 0 } << Terminates the array. + * }; + * + * vPortDefineHeapRegions( xHeapRegions ); << Pass the array into vPortDefineHeapRegions(). + * + * Note 0x80000000 is the lower address so appears in the array first. + * + */ +#include + +/* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining + * all the API functions to use the MPU wrappers. That should only be done when + * task.h is included from an application file. */ +#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE + +#include "FreeRTOS.h" +#include "task.h" + +#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE + +#if ( configSUPPORT_DYNAMIC_ALLOCATION == 0 ) + #error This file must not be used if configSUPPORT_DYNAMIC_ALLOCATION is 0 +#endif + +/* Block sizes must not get too small. */ +#define heapMINIMUM_BLOCK_SIZE ( ( size_t ) ( xHeapStructSize << 1 ) ) + +/* Assumes 8bit bytes! */ +#define heapBITS_PER_BYTE ( ( size_t ) 8 ) + +/* Define the linked list structure. This is used to link free blocks in order + * of their memory address. */ +typedef struct A_BLOCK_LINK +{ + struct A_BLOCK_LINK * pxNextFreeBlock; /*<< The next free block in the list. */ + size_t xBlockSize; /*<< The size of the free block. */ +} BlockLink_t; + +/*-----------------------------------------------------------*/ + +/* + * Inserts a block of memory that is being freed into the correct position in + * the list of free memory blocks. The block being freed will be merged with + * the block in front it and/or the block behind it if the memory blocks are + * adjacent to each other. + */ +static void prvInsertBlockIntoFreeList( BlockLink_t * pxBlockToInsert ); + +/*-----------------------------------------------------------*/ + +/* The size of the structure placed at the beginning of each allocated memory + * block must by correctly byte aligned. */ +static const size_t xHeapStructSize = ( sizeof( BlockLink_t ) + ( ( size_t ) ( portBYTE_ALIGNMENT - 1 ) ) ) & ~( ( size_t ) portBYTE_ALIGNMENT_MASK ); + +/* Create a couple of list links to mark the start and end of the list. */ +static BlockLink_t xStart, * pxEnd = NULL; + +/* Keeps track of the number of calls to allocate and free memory as well as the + * number of free bytes remaining, but says nothing about fragmentation. */ +static size_t xFreeBytesRemaining = 0U; +static size_t xMinimumEverFreeBytesRemaining = 0U; +static size_t xNumberOfSuccessfulAllocations = 0; +static size_t xNumberOfSuccessfulFrees = 0; + +/* Gets set to the top bit of an size_t type. When this bit in the xBlockSize + * member of an BlockLink_t structure is set then the block belongs to the + * application. When the bit is free the block is still part of the free heap + * space. */ +static size_t xBlockAllocatedBit = 0; + +/*-----------------------------------------------------------*/ + +void * pvPortMalloc( size_t xWantedSize ) +{ + BlockLink_t * pxBlock, * pxPreviousBlock, * pxNewBlockLink; + void * pvReturn = NULL; + + /* The heap must be initialised before the first call to + * prvPortMalloc(). */ + configASSERT( pxEnd ); + + vTaskSuspendAll(); + { + /* Check the requested block size is not so large that the top bit is + * set. The top bit of the block size member of the BlockLink_t structure + * is used to determine who owns the block - the application or the + * kernel, so it must be free. */ + if( ( xWantedSize & xBlockAllocatedBit ) == 0 ) + { + /* The wanted size is increased so it can contain a BlockLink_t + * structure in addition to the requested amount of bytes. */ + if( xWantedSize > 0 ) + { + xWantedSize += xHeapStructSize; + + /* Ensure that blocks are always aligned to the required number + * of bytes. */ + if( ( xWantedSize & portBYTE_ALIGNMENT_MASK ) != 0x00 ) + { + /* Byte alignment required. */ + xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + if( ( xWantedSize > 0 ) && ( xWantedSize <= xFreeBytesRemaining ) ) + { + /* Traverse the list from the start (lowest address) block until + * one of adequate size is found. */ + pxPreviousBlock = &xStart; + pxBlock = xStart.pxNextFreeBlock; + + while( ( pxBlock->xBlockSize < xWantedSize ) && ( pxBlock->pxNextFreeBlock != NULL ) ) + { + pxPreviousBlock = pxBlock; + pxBlock = pxBlock->pxNextFreeBlock; + } + + /* If the end marker was reached then a block of adequate size + * was not found. */ + if( pxBlock != pxEnd ) + { + /* Return the memory space pointed to - jumping over the + * BlockLink_t structure at its start. */ + pvReturn = ( void * ) ( ( ( uint8_t * ) pxPreviousBlock->pxNextFreeBlock ) + xHeapStructSize ); + + /* This block is being returned for use so must be taken out + * of the list of free blocks. */ + pxPreviousBlock->pxNextFreeBlock = pxBlock->pxNextFreeBlock; + + /* If the block is larger than required it can be split into + * two. */ + if( ( pxBlock->xBlockSize - xWantedSize ) > heapMINIMUM_BLOCK_SIZE ) + { + /* This block is to be split into two. Create a new + * block following the number of bytes requested. The void + * cast is used to prevent byte alignment warnings from the + * compiler. */ + pxNewBlockLink = ( void * ) ( ( ( uint8_t * ) pxBlock ) + xWantedSize ); + + /* Calculate the sizes of two blocks split from the + * single block. */ + pxNewBlockLink->xBlockSize = pxBlock->xBlockSize - xWantedSize; + pxBlock->xBlockSize = xWantedSize; + + /* Insert the new block into the list of free blocks. */ + prvInsertBlockIntoFreeList( ( pxNewBlockLink ) ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + xFreeBytesRemaining -= pxBlock->xBlockSize; + + if( xFreeBytesRemaining < xMinimumEverFreeBytesRemaining ) + { + xMinimumEverFreeBytesRemaining = xFreeBytesRemaining; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* The block is being returned - it is allocated and owned + * by the application and has no "next" block. */ + pxBlock->xBlockSize |= xBlockAllocatedBit; + pxBlock->pxNextFreeBlock = NULL; + xNumberOfSuccessfulAllocations++; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + traceMALLOC( pvReturn, xWantedSize ); + } + ( void ) xTaskResumeAll(); + + #if ( configUSE_MALLOC_FAILED_HOOK == 1 ) + { + if( pvReturn == NULL ) + { + extern void vApplicationMallocFailedHook( void ); + vApplicationMallocFailedHook(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + #endif /* if ( configUSE_MALLOC_FAILED_HOOK == 1 ) */ + + return pvReturn; +} +/*-----------------------------------------------------------*/ + +void vPortFree( void * pv ) +{ + uint8_t * puc = ( uint8_t * ) pv; + BlockLink_t * pxLink; + + if( pv != NULL ) + { + /* The memory being freed will have an BlockLink_t structure immediately + * before it. */ + puc -= xHeapStructSize; + + /* This casting is to keep the compiler from issuing warnings. */ + pxLink = ( void * ) puc; + + /* Check the block is actually allocated. */ + configASSERT( ( pxLink->xBlockSize & xBlockAllocatedBit ) != 0 ); + configASSERT( pxLink->pxNextFreeBlock == NULL ); + + if( ( pxLink->xBlockSize & xBlockAllocatedBit ) != 0 ) + { + if( pxLink->pxNextFreeBlock == NULL ) + { + /* The block is being returned to the heap - it is no longer + * allocated. */ + pxLink->xBlockSize &= ~xBlockAllocatedBit; + + vTaskSuspendAll(); + { + /* Add this block to the list of free blocks. */ + xFreeBytesRemaining += pxLink->xBlockSize; + traceFREE( pv, pxLink->xBlockSize ); + prvInsertBlockIntoFreeList( ( ( BlockLink_t * ) pxLink ) ); + xNumberOfSuccessfulFrees++; + } + ( void ) xTaskResumeAll(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } +} +/*-----------------------------------------------------------*/ + +size_t xPortGetFreeHeapSize( void ) +{ + return xFreeBytesRemaining; +} +/*-----------------------------------------------------------*/ + +size_t xPortGetMinimumEverFreeHeapSize( void ) +{ + return xMinimumEverFreeBytesRemaining; +} +/*-----------------------------------------------------------*/ + +static void prvInsertBlockIntoFreeList( BlockLink_t * pxBlockToInsert ) +{ + BlockLink_t * pxIterator; + uint8_t * puc; + + /* Iterate through the list until a block is found that has a higher address + * than the block being inserted. */ + for( pxIterator = &xStart; pxIterator->pxNextFreeBlock < pxBlockToInsert; pxIterator = pxIterator->pxNextFreeBlock ) + { + /* Nothing to do here, just iterate to the right position. */ + } + + /* Do the block being inserted, and the block it is being inserted after + * make a contiguous block of memory? */ + puc = ( uint8_t * ) pxIterator; + + if( ( puc + pxIterator->xBlockSize ) == ( uint8_t * ) pxBlockToInsert ) + { + pxIterator->xBlockSize += pxBlockToInsert->xBlockSize; + pxBlockToInsert = pxIterator; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* Do the block being inserted, and the block it is being inserted before + * make a contiguous block of memory? */ + puc = ( uint8_t * ) pxBlockToInsert; + + if( ( puc + pxBlockToInsert->xBlockSize ) == ( uint8_t * ) pxIterator->pxNextFreeBlock ) + { + if( pxIterator->pxNextFreeBlock != pxEnd ) + { + /* Form one big block from the two blocks. */ + pxBlockToInsert->xBlockSize += pxIterator->pxNextFreeBlock->xBlockSize; + pxBlockToInsert->pxNextFreeBlock = pxIterator->pxNextFreeBlock->pxNextFreeBlock; + } + else + { + pxBlockToInsert->pxNextFreeBlock = pxEnd; + } + } + else + { + pxBlockToInsert->pxNextFreeBlock = pxIterator->pxNextFreeBlock; + } + + /* If the block being inserted plugged a gab, so was merged with the block + * before and the block after, then it's pxNextFreeBlock pointer will have + * already been set, and should not be set here as that would make it point + * to itself. */ + if( pxIterator != pxBlockToInsert ) + { + pxIterator->pxNextFreeBlock = pxBlockToInsert; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } +} +/*-----------------------------------------------------------*/ + +void vPortDefineHeapRegions( const HeapRegion_t * const pxHeapRegions ) +{ + BlockLink_t * pxFirstFreeBlockInRegion = NULL, * pxPreviousFreeBlock; + size_t xAlignedHeap; + size_t xTotalRegionSize, xTotalHeapSize = 0; + BaseType_t xDefinedRegions = 0; + size_t xAddress; + const HeapRegion_t * pxHeapRegion; + + /* Can only call once! */ + configASSERT( pxEnd == NULL ); + + pxHeapRegion = &( pxHeapRegions[ xDefinedRegions ] ); + + while( pxHeapRegion->xSizeInBytes > 0 ) + { + xTotalRegionSize = pxHeapRegion->xSizeInBytes; + + /* Ensure the heap region starts on a correctly aligned boundary. */ + xAddress = ( size_t ) pxHeapRegion->pucStartAddress; + + if( ( xAddress & portBYTE_ALIGNMENT_MASK ) != 0 ) + { + xAddress += ( portBYTE_ALIGNMENT - 1 ); + xAddress &= ~portBYTE_ALIGNMENT_MASK; + + /* Adjust the size for the bytes lost to alignment. */ + xTotalRegionSize -= xAddress - ( size_t ) pxHeapRegion->pucStartAddress; + } + + xAlignedHeap = xAddress; + + /* Set xStart if it has not already been set. */ + if( xDefinedRegions == 0 ) + { + /* xStart is used to hold a pointer to the first item in the list of + * free blocks. The void cast is used to prevent compiler warnings. */ + xStart.pxNextFreeBlock = ( BlockLink_t * ) xAlignedHeap; + xStart.xBlockSize = ( size_t ) 0; + } + else + { + /* Should only get here if one region has already been added to the + * heap. */ + configASSERT( pxEnd != NULL ); + + /* Check blocks are passed in with increasing start addresses. */ + configASSERT( xAddress > ( size_t ) pxEnd ); + } + + /* Remember the location of the end marker in the previous region, if + * any. */ + pxPreviousFreeBlock = pxEnd; + + /* pxEnd is used to mark the end of the list of free blocks and is + * inserted at the end of the region space. */ + xAddress = xAlignedHeap + xTotalRegionSize; + xAddress -= xHeapStructSize; + xAddress &= ~portBYTE_ALIGNMENT_MASK; + pxEnd = ( BlockLink_t * ) xAddress; + pxEnd->xBlockSize = 0; + pxEnd->pxNextFreeBlock = NULL; + + /* To start with there is a single free block in this region that is + * sized to take up the entire heap region minus the space taken by the + * free block structure. */ + pxFirstFreeBlockInRegion = ( BlockLink_t * ) xAlignedHeap; + pxFirstFreeBlockInRegion->xBlockSize = xAddress - ( size_t ) pxFirstFreeBlockInRegion; + pxFirstFreeBlockInRegion->pxNextFreeBlock = pxEnd; + + /* If this is not the first region that makes up the entire heap space + * then link the previous region to this region. */ + if( pxPreviousFreeBlock != NULL ) + { + pxPreviousFreeBlock->pxNextFreeBlock = pxFirstFreeBlockInRegion; + } + + xTotalHeapSize += pxFirstFreeBlockInRegion->xBlockSize; + + /* Move onto the next HeapRegion_t structure. */ + xDefinedRegions++; + pxHeapRegion = &( pxHeapRegions[ xDefinedRegions ] ); + } + + xMinimumEverFreeBytesRemaining = xTotalHeapSize; + xFreeBytesRemaining = xTotalHeapSize; + + /* Check something was actually defined before it is accessed. */ + configASSERT( xTotalHeapSize ); + + /* Work out the position of the top bit in a size_t variable. */ + xBlockAllocatedBit = ( ( size_t ) 1 ) << ( ( sizeof( size_t ) * heapBITS_PER_BYTE ) - 1 ); +} +/*-----------------------------------------------------------*/ + +void vPortGetHeapStats( HeapStats_t * pxHeapStats ) +{ + BlockLink_t * pxBlock; + size_t xBlocks = 0, xMaxSize = 0, xMinSize = portMAX_DELAY; /* portMAX_DELAY used as a portable way of getting the maximum value. */ + + vTaskSuspendAll(); + { + pxBlock = xStart.pxNextFreeBlock; + + /* pxBlock will be NULL if the heap has not been initialised. The heap + * is initialised automatically when the first allocation is made. */ + if( pxBlock != NULL ) + { + do + { + /* Increment the number of blocks and record the largest block seen + * so far. */ + xBlocks++; + + if( pxBlock->xBlockSize > xMaxSize ) + { + xMaxSize = pxBlock->xBlockSize; + } + + /* Heap five will have a zero sized block at the end of each + * each region - the block is only used to link to the next + * heap region so it not a real block. */ + if( pxBlock->xBlockSize != 0 ) + { + if( pxBlock->xBlockSize < xMinSize ) + { + xMinSize = pxBlock->xBlockSize; + } + } + + /* Move to the next block in the chain until the last block is + * reached. */ + pxBlock = pxBlock->pxNextFreeBlock; + } while( pxBlock != pxEnd ); + } + } + ( void ) xTaskResumeAll(); + + pxHeapStats->xSizeOfLargestFreeBlockInBytes = xMaxSize; + pxHeapStats->xSizeOfSmallestFreeBlockInBytes = xMinSize; + pxHeapStats->xNumberOfFreeBlocks = xBlocks; + + taskENTER_CRITICAL(); + { + pxHeapStats->xAvailableHeapSpaceInBytes = xFreeBytesRemaining; + pxHeapStats->xNumberOfSuccessfulAllocations = xNumberOfSuccessfulAllocations; + pxHeapStats->xNumberOfSuccessfulFrees = xNumberOfSuccessfulFrees; + pxHeapStats->xMinimumEverFreeBytesRemaining = xMinimumEverFreeBytesRemaining; + } + taskEXIT_CRITICAL(); +} diff --git a/RTOS/FreeRTOS/Source/portable/readme.txt b/RTOS/FreeRTOS/Source/portable/readme.txt new file mode 100644 index 0000000..89f6b09 --- /dev/null +++ b/RTOS/FreeRTOS/Source/portable/readme.txt @@ -0,0 +1,20 @@ +Each real time kernel port consists of three files that contain the core kernel +components and are common to every port, and one or more files that are +specific to a particular microcontroller and/or compiler. + + ++ The FreeRTOS/Source/Portable/MemMang directory contains the five sample +memory allocators as described on the https://www.FreeRTOS.org WEB site. + ++ The other directories each contain files specific to a particular +microcontroller or compiler, where the directory name denotes the compiler +specific files the directory contains. + + + +For example, if you are interested in the [compiler] port for the [architecture] +microcontroller, then the port specific files are contained in +FreeRTOS/Source/Portable/[compiler]/[architecture] directory. If this is the +only port you are interested in then all the other directories can be +ignored. + diff --git a/RTOS/FreeRTOS/Source/queue.c b/RTOS/FreeRTOS/Source/queue.c new file mode 100644 index 0000000..fd09777 --- /dev/null +++ b/RTOS/FreeRTOS/Source/queue.c @@ -0,0 +1,3013 @@ +/* + * FreeRTOS Kernel V10.4.1 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * https://www.FreeRTOS.org + * https://github.com/FreeRTOS + * + */ + +#include +#include + +/* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining + * all the API functions to use the MPU wrappers. That should only be done when + * task.h is included from an application file. */ +#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE + +#include "FreeRTOS.h" +#include "task.h" +#include "queue.h" + +#if ( configUSE_CO_ROUTINES == 1 ) + #include "croutine.h" +#endif + +/* Lint e9021, e961 and e750 are suppressed as a MISRA exception justified + * because the MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be defined + * for the header files above, but not in this file, in order to generate the + * correct privileged Vs unprivileged linkage and placement. */ +#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE /*lint !e961 !e750 !e9021. */ + + +/* Constants used with the cRxLock and cTxLock structure members. */ +#define queueUNLOCKED ( ( int8_t ) -1 ) +#define queueLOCKED_UNMODIFIED ( ( int8_t ) 0 ) +#define queueINT8_MAX ( ( int8_t ) 127 ) + +/* When the Queue_t structure is used to represent a base queue its pcHead and + * pcTail members are used as pointers into the queue storage area. When the + * Queue_t structure is used to represent a mutex pcHead and pcTail pointers are + * not necessary, and the pcHead pointer is set to NULL to indicate that the + * structure instead holds a pointer to the mutex holder (if any). Map alternative + * names to the pcHead and structure member to ensure the readability of the code + * is maintained. The QueuePointers_t and SemaphoreData_t types are used to form + * a union as their usage is mutually exclusive dependent on what the queue is + * being used for. */ +#define uxQueueType pcHead +#define queueQUEUE_IS_MUTEX NULL + +typedef struct QueuePointers +{ + int8_t * pcTail; /*< Points to the byte at the end of the queue storage area. Once more byte is allocated than necessary to store the queue items, this is used as a marker. */ + int8_t * pcReadFrom; /*< Points to the last place that a queued item was read from when the structure is used as a queue. */ +} QueuePointers_t; + +typedef struct SemaphoreData +{ + TaskHandle_t xMutexHolder; /*< The handle of the task that holds the mutex. */ + UBaseType_t uxRecursiveCallCount; /*< Maintains a count of the number of times a recursive mutex has been recursively 'taken' when the structure is used as a mutex. */ +} SemaphoreData_t; + +/* Semaphores do not actually store or copy data, so have an item size of + * zero. */ +#define queueSEMAPHORE_QUEUE_ITEM_LENGTH ( ( UBaseType_t ) 0 ) +#define queueMUTEX_GIVE_BLOCK_TIME ( ( TickType_t ) 0U ) + +#if ( configUSE_PREEMPTION == 0 ) + +/* If the cooperative scheduler is being used then a yield should not be + * performed just because a higher priority task has been woken. */ + #define queueYIELD_IF_USING_PREEMPTION() +#else + #define queueYIELD_IF_USING_PREEMPTION() portYIELD_WITHIN_API() +#endif + +/* + * Definition of the queue used by the scheduler. + * Items are queued by copy, not reference. See the following link for the + * rationale: https://www.FreeRTOS.org/Embedded-RTOS-Queues.html + */ +typedef struct QueueDefinition /* The old naming convention is used to prevent breaking kernel aware debuggers. */ +{ + int8_t * pcHead; /*< Points to the beginning of the queue storage area. */ + int8_t * pcWriteTo; /*< Points to the free next place in the storage area. */ + + union + { + QueuePointers_t xQueue; /*< Data required exclusively when this structure is used as a queue. */ + SemaphoreData_t xSemaphore; /*< Data required exclusively when this structure is used as a semaphore. */ + } u; + + List_t xTasksWaitingToSend; /*< List of tasks that are blocked waiting to post onto this queue. Stored in priority order. */ + List_t xTasksWaitingToReceive; /*< List of tasks that are blocked waiting to read from this queue. Stored in priority order. */ + + volatile UBaseType_t uxMessagesWaiting; /*< The number of items currently in the queue. */ + UBaseType_t uxLength; /*< The length of the queue defined as the number of items it will hold, not the number of bytes. */ + UBaseType_t uxItemSize; /*< The size of each items that the queue will hold. */ + + volatile int8_t cRxLock; /*< Stores the number of items received from the queue (removed from the queue) while the queue was locked. Set to queueUNLOCKED when the queue is not locked. */ + volatile int8_t cTxLock; /*< Stores the number of items transmitted to the queue (added to the queue) while the queue was locked. Set to queueUNLOCKED when the queue is not locked. */ + + #if ( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) + uint8_t ucStaticallyAllocated; /*< Set to pdTRUE if the memory used by the queue was statically allocated to ensure no attempt is made to free the memory. */ + #endif + + #if ( configUSE_QUEUE_SETS == 1 ) + struct QueueDefinition * pxQueueSetContainer; + #endif + + #if ( configUSE_TRACE_FACILITY == 1 ) + UBaseType_t uxQueueNumber; + uint8_t ucQueueType; + #endif +} xQUEUE; + +/* The old xQUEUE name is maintained above then typedefed to the new Queue_t + * name below to enable the use of older kernel aware debuggers. */ +typedef xQUEUE Queue_t; + +/*-----------------------------------------------------------*/ + +/* + * The queue registry is just a means for kernel aware debuggers to locate + * queue structures. It has no other purpose so is an optional component. + */ +#if ( configQUEUE_REGISTRY_SIZE > 0 ) + +/* The type stored within the queue registry array. This allows a name + * to be assigned to each queue making kernel aware debugging a little + * more user friendly. */ + typedef struct QUEUE_REGISTRY_ITEM + { + const char * pcQueueName; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + QueueHandle_t xHandle; + } xQueueRegistryItem; + +/* The old xQueueRegistryItem name is maintained above then typedefed to the + * new xQueueRegistryItem name below to enable the use of older kernel aware + * debuggers. */ + typedef xQueueRegistryItem QueueRegistryItem_t; + +/* The queue registry is simply an array of QueueRegistryItem_t structures. + * The pcQueueName member of a structure being NULL is indicative of the + * array position being vacant. */ + PRIVILEGED_DATA QueueRegistryItem_t xQueueRegistry[ configQUEUE_REGISTRY_SIZE ]; + +#endif /* configQUEUE_REGISTRY_SIZE */ + +/* + * Unlocks a queue locked by a call to prvLockQueue. Locking a queue does not + * prevent an ISR from adding or removing items to the queue, but does prevent + * an ISR from removing tasks from the queue event lists. If an ISR finds a + * queue is locked it will instead increment the appropriate queue lock count + * to indicate that a task may require unblocking. When the queue in unlocked + * these lock counts are inspected, and the appropriate action taken. + */ +static void prvUnlockQueue( Queue_t * const pxQueue ) PRIVILEGED_FUNCTION; + +/* + * Uses a critical section to determine if there is any data in a queue. + * + * @return pdTRUE if the queue contains no items, otherwise pdFALSE. + */ +static BaseType_t prvIsQueueEmpty( const Queue_t * pxQueue ) PRIVILEGED_FUNCTION; + +/* + * Uses a critical section to determine if there is any space in a queue. + * + * @return pdTRUE if there is no space, otherwise pdFALSE; + */ +static BaseType_t prvIsQueueFull( const Queue_t * pxQueue ) PRIVILEGED_FUNCTION; + +/* + * Copies an item into the queue, either at the front of the queue or the + * back of the queue. + */ +static BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue, + const void * pvItemToQueue, + const BaseType_t xPosition ) PRIVILEGED_FUNCTION; + +/* + * Copies an item out of a queue. + */ +static void prvCopyDataFromQueue( Queue_t * const pxQueue, + void * const pvBuffer ) PRIVILEGED_FUNCTION; + +#if ( configUSE_QUEUE_SETS == 1 ) + +/* + * Checks to see if a queue is a member of a queue set, and if so, notifies + * the queue set that the queue contains data. + */ + static BaseType_t prvNotifyQueueSetContainer( const Queue_t * const pxQueue ) PRIVILEGED_FUNCTION; +#endif + +/* + * Called after a Queue_t structure has been allocated either statically or + * dynamically to fill in the structure's members. + */ +static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength, + const UBaseType_t uxItemSize, + uint8_t * pucQueueStorage, + const uint8_t ucQueueType, + Queue_t * pxNewQueue ) PRIVILEGED_FUNCTION; + +/* + * Mutexes are a special type of queue. When a mutex is created, first the + * queue is created, then prvInitialiseMutex() is called to configure the queue + * as a mutex. + */ +#if ( configUSE_MUTEXES == 1 ) + static void prvInitialiseMutex( Queue_t * pxNewQueue ) PRIVILEGED_FUNCTION; +#endif + +#if ( configUSE_MUTEXES == 1 ) + +/* + * If a task waiting for a mutex causes the mutex holder to inherit a + * priority, but the waiting task times out, then the holder should + * disinherit the priority - but only down to the highest priority of any + * other tasks that are waiting for the same mutex. This function returns + * that priority. + */ + static UBaseType_t prvGetDisinheritPriorityAfterTimeout( const Queue_t * const pxQueue ) PRIVILEGED_FUNCTION; +#endif +/*-----------------------------------------------------------*/ + +/* + * Macro to mark a queue as locked. Locking a queue prevents an ISR from + * accessing the queue event lists. + */ +#define prvLockQueue( pxQueue ) \ + taskENTER_CRITICAL(); \ + { \ + if( ( pxQueue )->cRxLock == queueUNLOCKED ) \ + { \ + ( pxQueue )->cRxLock = queueLOCKED_UNMODIFIED; \ + } \ + if( ( pxQueue )->cTxLock == queueUNLOCKED ) \ + { \ + ( pxQueue )->cTxLock = queueLOCKED_UNMODIFIED; \ + } \ + } \ + taskEXIT_CRITICAL() +/*-----------------------------------------------------------*/ + +BaseType_t xQueueGenericReset( QueueHandle_t xQueue, + BaseType_t xNewQueue ) +{ + Queue_t * const pxQueue = xQueue; + + configASSERT( pxQueue ); + + taskENTER_CRITICAL(); + { + pxQueue->u.xQueue.pcTail = pxQueue->pcHead + ( pxQueue->uxLength * pxQueue->uxItemSize ); /*lint !e9016 Pointer arithmetic allowed on char types, especially when it assists conveying intent. */ + pxQueue->uxMessagesWaiting = ( UBaseType_t ) 0U; + pxQueue->pcWriteTo = pxQueue->pcHead; + pxQueue->u.xQueue.pcReadFrom = pxQueue->pcHead + ( ( pxQueue->uxLength - 1U ) * pxQueue->uxItemSize ); /*lint !e9016 Pointer arithmetic allowed on char types, especially when it assists conveying intent. */ + pxQueue->cRxLock = queueUNLOCKED; + pxQueue->cTxLock = queueUNLOCKED; + + if( xNewQueue == pdFALSE ) + { + /* If there are tasks blocked waiting to read from the queue, then + * the tasks will remain blocked as after this function exits the queue + * will still be empty. If there are tasks blocked waiting to write to + * the queue, then one should be unblocked as after this function exits + * it will be possible to write to it. */ + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE ) + { + if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE ) + { + queueYIELD_IF_USING_PREEMPTION(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + /* Ensure the event queues start in the correct state. */ + vListInitialise( &( pxQueue->xTasksWaitingToSend ) ); + vListInitialise( &( pxQueue->xTasksWaitingToReceive ) ); + } + } + taskEXIT_CRITICAL(); + + /* A value is returned for calling semantic consistency with previous + * versions. */ + return pdPASS; +} +/*-----------------------------------------------------------*/ + +#if ( configSUPPORT_STATIC_ALLOCATION == 1 ) + + QueueHandle_t xQueueGenericCreateStatic( const UBaseType_t uxQueueLength, + const UBaseType_t uxItemSize, + uint8_t * pucQueueStorage, + StaticQueue_t * pxStaticQueue, + const uint8_t ucQueueType ) + { + Queue_t * pxNewQueue; + + configASSERT( uxQueueLength > ( UBaseType_t ) 0 ); + + /* The StaticQueue_t structure and the queue storage area must be + * supplied. */ + configASSERT( pxStaticQueue != NULL ); + + /* A queue storage area should be provided if the item size is not 0, and + * should not be provided if the item size is 0. */ + configASSERT( !( ( pucQueueStorage != NULL ) && ( uxItemSize == 0 ) ) ); + configASSERT( !( ( pucQueueStorage == NULL ) && ( uxItemSize != 0 ) ) ); + + #if ( configASSERT_DEFINED == 1 ) + { + /* Sanity check that the size of the structure used to declare a + * variable of type StaticQueue_t or StaticSemaphore_t equals the size of + * the real queue and semaphore structures. */ + volatile size_t xSize = sizeof( StaticQueue_t ); + configASSERT( xSize == sizeof( Queue_t ) ); + ( void ) xSize; /* Keeps lint quiet when configASSERT() is not defined. */ + } + #endif /* configASSERT_DEFINED */ + + /* The address of a statically allocated queue was passed in, use it. + * The address of a statically allocated storage area was also passed in + * but is already set. */ + pxNewQueue = ( Queue_t * ) pxStaticQueue; /*lint !e740 !e9087 Unusual cast is ok as the structures are designed to have the same alignment, and the size is checked by an assert. */ + + if( pxNewQueue != NULL ) + { + #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + { + /* Queues can be allocated wither statically or dynamically, so + * note this queue was allocated statically in case the queue is + * later deleted. */ + pxNewQueue->ucStaticallyAllocated = pdTRUE; + } + #endif /* configSUPPORT_DYNAMIC_ALLOCATION */ + + prvInitialiseNewQueue( uxQueueLength, uxItemSize, pucQueueStorage, ucQueueType, pxNewQueue ); + } + else + { + traceQUEUE_CREATE_FAILED( ucQueueType ); + mtCOVERAGE_TEST_MARKER(); + } + + return pxNewQueue; + } + +#endif /* configSUPPORT_STATIC_ALLOCATION */ +/*-----------------------------------------------------------*/ + +#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + + QueueHandle_t xQueueGenericCreate( const UBaseType_t uxQueueLength, + const UBaseType_t uxItemSize, + const uint8_t ucQueueType ) + { + Queue_t * pxNewQueue; + size_t xQueueSizeInBytes; + uint8_t * pucQueueStorage; + + configASSERT( uxQueueLength > ( UBaseType_t ) 0 ); + + /* Allocate enough space to hold the maximum number of items that + * can be in the queue at any time. It is valid for uxItemSize to be + * zero in the case the queue is used as a semaphore. */ + xQueueSizeInBytes = ( size_t ) ( uxQueueLength * uxItemSize ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */ + + /* Check for multiplication overflow. */ + configASSERT( ( uxItemSize == 0 ) || ( uxQueueLength == ( xQueueSizeInBytes / uxItemSize ) ) ); + + /* Allocate the queue and storage area. Justification for MISRA + * deviation as follows: pvPortMalloc() always ensures returned memory + * blocks are aligned per the requirements of the MCU stack. In this case + * pvPortMalloc() must return a pointer that is guaranteed to meet the + * alignment requirements of the Queue_t structure - which in this case + * is an int8_t *. Therefore, whenever the stack alignment requirements + * are greater than or equal to the pointer to char requirements the cast + * is safe. In other cases alignment requirements are not strict (one or + * two bytes). */ + pxNewQueue = ( Queue_t * ) pvPortMalloc( sizeof( Queue_t ) + xQueueSizeInBytes ); /*lint !e9087 !e9079 see comment above. */ + + if( pxNewQueue != NULL ) + { + /* Jump past the queue structure to find the location of the queue + * storage area. */ + pucQueueStorage = ( uint8_t * ) pxNewQueue; + pucQueueStorage += sizeof( Queue_t ); /*lint !e9016 Pointer arithmetic allowed on char types, especially when it assists conveying intent. */ + + #if ( configSUPPORT_STATIC_ALLOCATION == 1 ) + { + /* Queues can be created either statically or dynamically, so + * note this task was created dynamically in case it is later + * deleted. */ + pxNewQueue->ucStaticallyAllocated = pdFALSE; + } + #endif /* configSUPPORT_STATIC_ALLOCATION */ + + prvInitialiseNewQueue( uxQueueLength, uxItemSize, pucQueueStorage, ucQueueType, pxNewQueue ); + } + else + { + traceQUEUE_CREATE_FAILED( ucQueueType ); + mtCOVERAGE_TEST_MARKER(); + } + + return pxNewQueue; + } + +#endif /* configSUPPORT_STATIC_ALLOCATION */ +/*-----------------------------------------------------------*/ + +static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength, + const UBaseType_t uxItemSize, + uint8_t * pucQueueStorage, + const uint8_t ucQueueType, + Queue_t * pxNewQueue ) +{ + /* Remove compiler warnings about unused parameters should + * configUSE_TRACE_FACILITY not be set to 1. */ + ( void ) ucQueueType; + + if( uxItemSize == ( UBaseType_t ) 0 ) + { + /* No RAM was allocated for the queue storage area, but PC head cannot + * be set to NULL because NULL is used as a key to say the queue is used as + * a mutex. Therefore just set pcHead to point to the queue as a benign + * value that is known to be within the memory map. */ + pxNewQueue->pcHead = ( int8_t * ) pxNewQueue; + } + else + { + /* Set the head to the start of the queue storage area. */ + pxNewQueue->pcHead = ( int8_t * ) pucQueueStorage; + } + + /* Initialise the queue members as described where the queue type is + * defined. */ + pxNewQueue->uxLength = uxQueueLength; + pxNewQueue->uxItemSize = uxItemSize; + ( void ) xQueueGenericReset( pxNewQueue, pdTRUE ); + + #if ( configUSE_TRACE_FACILITY == 1 ) + { + pxNewQueue->ucQueueType = ucQueueType; + } + #endif /* configUSE_TRACE_FACILITY */ + + #if ( configUSE_QUEUE_SETS == 1 ) + { + pxNewQueue->pxQueueSetContainer = NULL; + } + #endif /* configUSE_QUEUE_SETS */ + + traceQUEUE_CREATE( pxNewQueue ); +} +/*-----------------------------------------------------------*/ + +#if ( configUSE_MUTEXES == 1 ) + + static void prvInitialiseMutex( Queue_t * pxNewQueue ) + { + if( pxNewQueue != NULL ) + { + /* The queue create function will set all the queue structure members + * correctly for a generic queue, but this function is creating a + * mutex. Overwrite those members that need to be set differently - + * in particular the information required for priority inheritance. */ + pxNewQueue->u.xSemaphore.xMutexHolder = NULL; + pxNewQueue->uxQueueType = queueQUEUE_IS_MUTEX; + + /* In case this is a recursive mutex. */ + pxNewQueue->u.xSemaphore.uxRecursiveCallCount = 0; + + traceCREATE_MUTEX( pxNewQueue ); + + /* Start with the semaphore in the expected state. */ + ( void ) xQueueGenericSend( pxNewQueue, NULL, ( TickType_t ) 0U, queueSEND_TO_BACK ); + } + else + { + traceCREATE_MUTEX_FAILED(); + } + } + +#endif /* configUSE_MUTEXES */ +/*-----------------------------------------------------------*/ + +#if ( ( configUSE_MUTEXES == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) + + QueueHandle_t xQueueCreateMutex( const uint8_t ucQueueType ) + { + QueueHandle_t xNewQueue; + const UBaseType_t uxMutexLength = ( UBaseType_t ) 1, uxMutexSize = ( UBaseType_t ) 0; + + xNewQueue = xQueueGenericCreate( uxMutexLength, uxMutexSize, ucQueueType ); + prvInitialiseMutex( ( Queue_t * ) xNewQueue ); + + return xNewQueue; + } + +#endif /* configUSE_MUTEXES */ +/*-----------------------------------------------------------*/ + +#if ( ( configUSE_MUTEXES == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) ) + + QueueHandle_t xQueueCreateMutexStatic( const uint8_t ucQueueType, + StaticQueue_t * pxStaticQueue ) + { + QueueHandle_t xNewQueue; + const UBaseType_t uxMutexLength = ( UBaseType_t ) 1, uxMutexSize = ( UBaseType_t ) 0; + + /* Prevent compiler warnings about unused parameters if + * configUSE_TRACE_FACILITY does not equal 1. */ + ( void ) ucQueueType; + + xNewQueue = xQueueGenericCreateStatic( uxMutexLength, uxMutexSize, NULL, pxStaticQueue, ucQueueType ); + prvInitialiseMutex( ( Queue_t * ) xNewQueue ); + + return xNewQueue; + } + +#endif /* configUSE_MUTEXES */ +/*-----------------------------------------------------------*/ + +#if ( ( configUSE_MUTEXES == 1 ) && ( INCLUDE_xSemaphoreGetMutexHolder == 1 ) ) + + TaskHandle_t xQueueGetMutexHolder( QueueHandle_t xSemaphore ) + { + TaskHandle_t pxReturn; + Queue_t * const pxSemaphore = ( Queue_t * ) xSemaphore; + + /* This function is called by xSemaphoreGetMutexHolder(), and should not + * be called directly. Note: This is a good way of determining if the + * calling task is the mutex holder, but not a good way of determining the + * identity of the mutex holder, as the holder may change between the + * following critical section exiting and the function returning. */ + taskENTER_CRITICAL(); + { + if( pxSemaphore->uxQueueType == queueQUEUE_IS_MUTEX ) + { + pxReturn = pxSemaphore->u.xSemaphore.xMutexHolder; + } + else + { + pxReturn = NULL; + } + } + taskEXIT_CRITICAL(); + + return pxReturn; + } /*lint !e818 xSemaphore cannot be a pointer to const because it is a typedef. */ + +#endif /* if ( ( configUSE_MUTEXES == 1 ) && ( INCLUDE_xSemaphoreGetMutexHolder == 1 ) ) */ +/*-----------------------------------------------------------*/ + +#if ( ( configUSE_MUTEXES == 1 ) && ( INCLUDE_xSemaphoreGetMutexHolder == 1 ) ) + + TaskHandle_t xQueueGetMutexHolderFromISR( QueueHandle_t xSemaphore ) + { + TaskHandle_t pxReturn; + + configASSERT( xSemaphore ); + + /* Mutexes cannot be used in interrupt service routines, so the mutex + * holder should not change in an ISR, and therefore a critical section is + * not required here. */ + if( ( ( Queue_t * ) xSemaphore )->uxQueueType == queueQUEUE_IS_MUTEX ) + { + pxReturn = ( ( Queue_t * ) xSemaphore )->u.xSemaphore.xMutexHolder; + } + else + { + pxReturn = NULL; + } + + return pxReturn; + } /*lint !e818 xSemaphore cannot be a pointer to const because it is a typedef. */ + +#endif /* if ( ( configUSE_MUTEXES == 1 ) && ( INCLUDE_xSemaphoreGetMutexHolder == 1 ) ) */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_RECURSIVE_MUTEXES == 1 ) + + BaseType_t xQueueGiveMutexRecursive( QueueHandle_t xMutex ) + { + BaseType_t xReturn; + Queue_t * const pxMutex = ( Queue_t * ) xMutex; + + configASSERT( pxMutex ); + + /* If this is the task that holds the mutex then xMutexHolder will not + * change outside of this task. If this task does not hold the mutex then + * pxMutexHolder can never coincidentally equal the tasks handle, and as + * this is the only condition we are interested in it does not matter if + * pxMutexHolder is accessed simultaneously by another task. Therefore no + * mutual exclusion is required to test the pxMutexHolder variable. */ + if( pxMutex->u.xSemaphore.xMutexHolder == xTaskGetCurrentTaskHandle() ) + { + traceGIVE_MUTEX_RECURSIVE( pxMutex ); + + /* uxRecursiveCallCount cannot be zero if xMutexHolder is equal to + * the task handle, therefore no underflow check is required. Also, + * uxRecursiveCallCount is only modified by the mutex holder, and as + * there can only be one, no mutual exclusion is required to modify the + * uxRecursiveCallCount member. */ + ( pxMutex->u.xSemaphore.uxRecursiveCallCount )--; + + /* Has the recursive call count unwound to 0? */ + if( pxMutex->u.xSemaphore.uxRecursiveCallCount == ( UBaseType_t ) 0 ) + { + /* Return the mutex. This will automatically unblock any other + * task that might be waiting to access the mutex. */ + ( void ) xQueueGenericSend( pxMutex, NULL, queueMUTEX_GIVE_BLOCK_TIME, queueSEND_TO_BACK ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + xReturn = pdPASS; + } + else + { + /* The mutex cannot be given because the calling task is not the + * holder. */ + xReturn = pdFAIL; + + traceGIVE_MUTEX_RECURSIVE_FAILED( pxMutex ); + } + + return xReturn; + } + +#endif /* configUSE_RECURSIVE_MUTEXES */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_RECURSIVE_MUTEXES == 1 ) + + BaseType_t xQueueTakeMutexRecursive( QueueHandle_t xMutex, + TickType_t xTicksToWait ) + { + BaseType_t xReturn; + Queue_t * const pxMutex = ( Queue_t * ) xMutex; + + configASSERT( pxMutex ); + + /* Comments regarding mutual exclusion as per those within + * xQueueGiveMutexRecursive(). */ + + traceTAKE_MUTEX_RECURSIVE( pxMutex ); + + if( pxMutex->u.xSemaphore.xMutexHolder == xTaskGetCurrentTaskHandle() ) + { + ( pxMutex->u.xSemaphore.uxRecursiveCallCount )++; + xReturn = pdPASS; + } + else + { + xReturn = xQueueSemaphoreTake( pxMutex, xTicksToWait ); + + /* pdPASS will only be returned if the mutex was successfully + * obtained. The calling task may have entered the Blocked state + * before reaching here. */ + if( xReturn != pdFAIL ) + { + ( pxMutex->u.xSemaphore.uxRecursiveCallCount )++; + } + else + { + traceTAKE_MUTEX_RECURSIVE_FAILED( pxMutex ); + } + } + + return xReturn; + } + +#endif /* configUSE_RECURSIVE_MUTEXES */ +/*-----------------------------------------------------------*/ + +#if ( ( configUSE_COUNTING_SEMAPHORES == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) ) + + QueueHandle_t xQueueCreateCountingSemaphoreStatic( const UBaseType_t uxMaxCount, + const UBaseType_t uxInitialCount, + StaticQueue_t * pxStaticQueue ) + { + QueueHandle_t xHandle; + + configASSERT( uxMaxCount != 0 ); + configASSERT( uxInitialCount <= uxMaxCount ); + + xHandle = xQueueGenericCreateStatic( uxMaxCount, queueSEMAPHORE_QUEUE_ITEM_LENGTH, NULL, pxStaticQueue, queueQUEUE_TYPE_COUNTING_SEMAPHORE ); + + if( xHandle != NULL ) + { + ( ( Queue_t * ) xHandle )->uxMessagesWaiting = uxInitialCount; + + traceCREATE_COUNTING_SEMAPHORE(); + } + else + { + traceCREATE_COUNTING_SEMAPHORE_FAILED(); + } + + return xHandle; + } + +#endif /* ( ( configUSE_COUNTING_SEMAPHORES == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) */ +/*-----------------------------------------------------------*/ + +#if ( ( configUSE_COUNTING_SEMAPHORES == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) + + QueueHandle_t xQueueCreateCountingSemaphore( const UBaseType_t uxMaxCount, + const UBaseType_t uxInitialCount ) + { + QueueHandle_t xHandle; + + configASSERT( uxMaxCount != 0 ); + configASSERT( uxInitialCount <= uxMaxCount ); + + xHandle = xQueueGenericCreate( uxMaxCount, queueSEMAPHORE_QUEUE_ITEM_LENGTH, queueQUEUE_TYPE_COUNTING_SEMAPHORE ); + + if( xHandle != NULL ) + { + ( ( Queue_t * ) xHandle )->uxMessagesWaiting = uxInitialCount; + + traceCREATE_COUNTING_SEMAPHORE(); + } + else + { + traceCREATE_COUNTING_SEMAPHORE_FAILED(); + } + + return xHandle; + } + +#endif /* ( ( configUSE_COUNTING_SEMAPHORES == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) */ +/*-----------------------------------------------------------*/ + +BaseType_t xQueueGenericSend( QueueHandle_t xQueue, + const void * const pvItemToQueue, + TickType_t xTicksToWait, + const BaseType_t xCopyPosition ) +{ + BaseType_t xEntryTimeSet = pdFALSE, xYieldRequired; + TimeOut_t xTimeOut; + Queue_t * const pxQueue = xQueue; + + configASSERT( pxQueue ); + configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( UBaseType_t ) 0U ) ) ); + configASSERT( !( ( xCopyPosition == queueOVERWRITE ) && ( pxQueue->uxLength != 1 ) ) ); + #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) ) + { + configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) ); + } + #endif + + /*lint -save -e904 This function relaxes the coding standard somewhat to + * allow return statements within the function itself. This is done in the + * interest of execution time efficiency. */ + for( ; ; ) + { + taskENTER_CRITICAL(); + { + /* Is there room on the queue now? The running task must be the + * highest priority task wanting to access the queue. If the head item + * in the queue is to be overwritten then it does not matter if the + * queue is full. */ + if( ( pxQueue->uxMessagesWaiting < pxQueue->uxLength ) || ( xCopyPosition == queueOVERWRITE ) ) + { + traceQUEUE_SEND( pxQueue ); + + #if ( configUSE_QUEUE_SETS == 1 ) + { + const UBaseType_t uxPreviousMessagesWaiting = pxQueue->uxMessagesWaiting; + + xYieldRequired = prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition ); + + if( pxQueue->pxQueueSetContainer != NULL ) + { + if( ( xCopyPosition == queueOVERWRITE ) && ( uxPreviousMessagesWaiting != ( UBaseType_t ) 0 ) ) + { + /* Do not notify the queue set as an existing item + * was overwritten in the queue so the number of items + * in the queue has not changed. */ + mtCOVERAGE_TEST_MARKER(); + } + else if( prvNotifyQueueSetContainer( pxQueue ) != pdFALSE ) + { + /* The queue is a member of a queue set, and posting + * to the queue set caused a higher priority task to + * unblock. A context switch is required. */ + queueYIELD_IF_USING_PREEMPTION(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + /* If there was a task waiting for data to arrive on the + * queue then unblock it now. */ + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE ) + { + if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE ) + { + /* The unblocked task has a priority higher than + * our own so yield immediately. Yes it is ok to + * do this from within the critical section - the + * kernel takes care of that. */ + queueYIELD_IF_USING_PREEMPTION(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else if( xYieldRequired != pdFALSE ) + { + /* This path is a special case that will only get + * executed if the task was holding multiple mutexes + * and the mutexes were given back in an order that is + * different to that in which they were taken. */ + queueYIELD_IF_USING_PREEMPTION(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + } + #else /* configUSE_QUEUE_SETS */ + { + xYieldRequired = prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition ); + + /* If there was a task waiting for data to arrive on the + * queue then unblock it now. */ + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE ) + { + if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE ) + { + /* The unblocked task has a priority higher than + * our own so yield immediately. Yes it is ok to do + * this from within the critical section - the kernel + * takes care of that. */ + queueYIELD_IF_USING_PREEMPTION(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else if( xYieldRequired != pdFALSE ) + { + /* This path is a special case that will only get + * executed if the task was holding multiple mutexes and + * the mutexes were given back in an order that is + * different to that in which they were taken. */ + queueYIELD_IF_USING_PREEMPTION(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + #endif /* configUSE_QUEUE_SETS */ + + taskEXIT_CRITICAL(); + return pdPASS; + } + else + { + if( xTicksToWait == ( TickType_t ) 0 ) + { + /* The queue was full and no block time is specified (or + * the block time has expired) so leave now. */ + taskEXIT_CRITICAL(); + + /* Return to the original privilege level before exiting + * the function. */ + traceQUEUE_SEND_FAILED( pxQueue ); + return errQUEUE_FULL; + } + else if( xEntryTimeSet == pdFALSE ) + { + /* The queue was full and a block time was specified so + * configure the timeout structure. */ + vTaskInternalSetTimeOutState( &xTimeOut ); + xEntryTimeSet = pdTRUE; + } + else + { + /* Entry time was already set. */ + mtCOVERAGE_TEST_MARKER(); + } + } + } + taskEXIT_CRITICAL(); + + /* Interrupts and other tasks can send to and receive from the queue + * now the critical section has been exited. */ + + vTaskSuspendAll(); + prvLockQueue( pxQueue ); + + /* Update the timeout state to see if it has expired yet. */ + if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE ) + { + if( prvIsQueueFull( pxQueue ) != pdFALSE ) + { + traceBLOCKING_ON_QUEUE_SEND( pxQueue ); + vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToSend ), xTicksToWait ); + + /* Unlocking the queue means queue events can effect the + * event list. It is possible that interrupts occurring now + * remove this task from the event list again - but as the + * scheduler is suspended the task will go onto the pending + * ready last instead of the actual ready list. */ + prvUnlockQueue( pxQueue ); + + /* Resuming the scheduler will move tasks from the pending + * ready list into the ready list - so it is feasible that this + * task is already in a ready list before it yields - in which + * case the yield will not cause a context switch unless there + * is also a higher priority task in the pending ready list. */ + if( xTaskResumeAll() == pdFALSE ) + { + portYIELD_WITHIN_API(); + } + } + else + { + /* Try again. */ + prvUnlockQueue( pxQueue ); + ( void ) xTaskResumeAll(); + } + } + else + { + /* The timeout has expired. */ + prvUnlockQueue( pxQueue ); + ( void ) xTaskResumeAll(); + + traceQUEUE_SEND_FAILED( pxQueue ); + return errQUEUE_FULL; + } + } /*lint -restore */ +} +/*-----------------------------------------------------------*/ + +BaseType_t xQueueGenericSendFromISR( QueueHandle_t xQueue, + const void * const pvItemToQueue, + BaseType_t * const pxHigherPriorityTaskWoken, + const BaseType_t xCopyPosition ) +{ + BaseType_t xReturn; + UBaseType_t uxSavedInterruptStatus; + Queue_t * const pxQueue = xQueue; + + configASSERT( pxQueue ); + configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( UBaseType_t ) 0U ) ) ); + configASSERT( !( ( xCopyPosition == queueOVERWRITE ) && ( pxQueue->uxLength != 1 ) ) ); + + /* RTOS ports that support interrupt nesting have the concept of a maximum + * system call (or maximum API call) interrupt priority. Interrupts that are + * above the maximum system call priority are kept permanently enabled, even + * when the RTOS kernel is in a critical section, but cannot make any calls to + * FreeRTOS API functions. If configASSERT() is defined in FreeRTOSConfig.h + * then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion + * failure if a FreeRTOS API function is called from an interrupt that has been + * assigned a priority above the configured maximum system call priority. + * Only FreeRTOS functions that end in FromISR can be called from interrupts + * that have been assigned a priority at or (logically) below the maximum + * system call interrupt priority. FreeRTOS maintains a separate interrupt + * safe API to ensure interrupt entry is as fast and as simple as possible. + * More information (albeit Cortex-M specific) is provided on the following + * link: https://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html */ + portASSERT_IF_INTERRUPT_PRIORITY_INVALID(); + + /* Similar to xQueueGenericSend, except without blocking if there is no room + * in the queue. Also don't directly wake a task that was blocked on a queue + * read, instead return a flag to say whether a context switch is required or + * not (i.e. has a task with a higher priority than us been woken by this + * post). */ + uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR(); + { + if( ( pxQueue->uxMessagesWaiting < pxQueue->uxLength ) || ( xCopyPosition == queueOVERWRITE ) ) + { + const int8_t cTxLock = pxQueue->cTxLock; + const UBaseType_t uxPreviousMessagesWaiting = pxQueue->uxMessagesWaiting; + + traceQUEUE_SEND_FROM_ISR( pxQueue ); + + /* Semaphores use xQueueGiveFromISR(), so pxQueue will not be a + * semaphore or mutex. That means prvCopyDataToQueue() cannot result + * in a task disinheriting a priority and prvCopyDataToQueue() can be + * called here even though the disinherit function does not check if + * the scheduler is suspended before accessing the ready lists. */ + ( void ) prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition ); + + /* The event list is not altered if the queue is locked. This will + * be done when the queue is unlocked later. */ + if( cTxLock == queueUNLOCKED ) + { + #if ( configUSE_QUEUE_SETS == 1 ) + { + if( pxQueue->pxQueueSetContainer != NULL ) + { + if( ( xCopyPosition == queueOVERWRITE ) && ( uxPreviousMessagesWaiting != ( UBaseType_t ) 0 ) ) + { + /* Do not notify the queue set as an existing item + * was overwritten in the queue so the number of items + * in the queue has not changed. */ + mtCOVERAGE_TEST_MARKER(); + } + else if( prvNotifyQueueSetContainer( pxQueue ) != pdFALSE ) + { + /* The queue is a member of a queue set, and posting + * to the queue set caused a higher priority task to + * unblock. A context switch is required. */ + if( pxHigherPriorityTaskWoken != NULL ) + { + *pxHigherPriorityTaskWoken = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE ) + { + if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE ) + { + /* The task waiting has a higher priority so + * record that a context switch is required. */ + if( pxHigherPriorityTaskWoken != NULL ) + { + *pxHigherPriorityTaskWoken = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + } + #else /* configUSE_QUEUE_SETS */ + { + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE ) + { + if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE ) + { + /* The task waiting has a higher priority so record that a + * context switch is required. */ + if( pxHigherPriorityTaskWoken != NULL ) + { + *pxHigherPriorityTaskWoken = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* Not used in this path. */ + ( void ) uxPreviousMessagesWaiting; + } + #endif /* configUSE_QUEUE_SETS */ + } + else + { + /* Increment the lock count so the task that unlocks the queue + * knows that data was posted while it was locked. */ + configASSERT( cTxLock != queueINT8_MAX ); + + pxQueue->cTxLock = ( int8_t ) ( cTxLock + 1 ); + } + + xReturn = pdPASS; + } + else + { + traceQUEUE_SEND_FROM_ISR_FAILED( pxQueue ); + xReturn = errQUEUE_FULL; + } + } + portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); + + return xReturn; +} +/*-----------------------------------------------------------*/ + +BaseType_t xQueueGiveFromISR( QueueHandle_t xQueue, + BaseType_t * const pxHigherPriorityTaskWoken ) +{ + BaseType_t xReturn; + UBaseType_t uxSavedInterruptStatus; + Queue_t * const pxQueue = xQueue; + + /* Similar to xQueueGenericSendFromISR() but used with semaphores where the + * item size is 0. Don't directly wake a task that was blocked on a queue + * read, instead return a flag to say whether a context switch is required or + * not (i.e. has a task with a higher priority than us been woken by this + * post). */ + + configASSERT( pxQueue ); + + /* xQueueGenericSendFromISR() should be used instead of xQueueGiveFromISR() + * if the item size is not 0. */ + configASSERT( pxQueue->uxItemSize == 0 ); + + /* Normally a mutex would not be given from an interrupt, especially if + * there is a mutex holder, as priority inheritance makes no sense for an + * interrupts, only tasks. */ + configASSERT( !( ( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX ) && ( pxQueue->u.xSemaphore.xMutexHolder != NULL ) ) ); + + /* RTOS ports that support interrupt nesting have the concept of a maximum + * system call (or maximum API call) interrupt priority. Interrupts that are + * above the maximum system call priority are kept permanently enabled, even + * when the RTOS kernel is in a critical section, but cannot make any calls to + * FreeRTOS API functions. If configASSERT() is defined in FreeRTOSConfig.h + * then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion + * failure if a FreeRTOS API function is called from an interrupt that has been + * assigned a priority above the configured maximum system call priority. + * Only FreeRTOS functions that end in FromISR can be called from interrupts + * that have been assigned a priority at or (logically) below the maximum + * system call interrupt priority. FreeRTOS maintains a separate interrupt + * safe API to ensure interrupt entry is as fast and as simple as possible. + * More information (albeit Cortex-M specific) is provided on the following + * link: https://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html */ + portASSERT_IF_INTERRUPT_PRIORITY_INVALID(); + + uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR(); + { + const UBaseType_t uxMessagesWaiting = pxQueue->uxMessagesWaiting; + + /* When the queue is used to implement a semaphore no data is ever + * moved through the queue but it is still valid to see if the queue 'has + * space'. */ + if( uxMessagesWaiting < pxQueue->uxLength ) + { + const int8_t cTxLock = pxQueue->cTxLock; + + traceQUEUE_SEND_FROM_ISR( pxQueue ); + + /* A task can only have an inherited priority if it is a mutex + * holder - and if there is a mutex holder then the mutex cannot be + * given from an ISR. As this is the ISR version of the function it + * can be assumed there is no mutex holder and no need to determine if + * priority disinheritance is needed. Simply increase the count of + * messages (semaphores) available. */ + pxQueue->uxMessagesWaiting = uxMessagesWaiting + ( UBaseType_t ) 1; + + /* The event list is not altered if the queue is locked. This will + * be done when the queue is unlocked later. */ + if( cTxLock == queueUNLOCKED ) + { + #if ( configUSE_QUEUE_SETS == 1 ) + { + if( pxQueue->pxQueueSetContainer != NULL ) + { + if( prvNotifyQueueSetContainer( pxQueue ) != pdFALSE ) + { + /* The semaphore is a member of a queue set, and + * posting to the queue set caused a higher priority + * task to unblock. A context switch is required. */ + if( pxHigherPriorityTaskWoken != NULL ) + { + *pxHigherPriorityTaskWoken = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE ) + { + if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE ) + { + /* The task waiting has a higher priority so + * record that a context switch is required. */ + if( pxHigherPriorityTaskWoken != NULL ) + { + *pxHigherPriorityTaskWoken = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + } + #else /* configUSE_QUEUE_SETS */ + { + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE ) + { + if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE ) + { + /* The task waiting has a higher priority so record that a + * context switch is required. */ + if( pxHigherPriorityTaskWoken != NULL ) + { + *pxHigherPriorityTaskWoken = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + #endif /* configUSE_QUEUE_SETS */ + } + else + { + /* Increment the lock count so the task that unlocks the queue + * knows that data was posted while it was locked. */ + configASSERT( cTxLock != queueINT8_MAX ); + + pxQueue->cTxLock = ( int8_t ) ( cTxLock + 1 ); + } + + xReturn = pdPASS; + } + else + { + traceQUEUE_SEND_FROM_ISR_FAILED( pxQueue ); + xReturn = errQUEUE_FULL; + } + } + portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); + + return xReturn; +} +/*-----------------------------------------------------------*/ + +BaseType_t xQueueReceive( QueueHandle_t xQueue, + void * const pvBuffer, + TickType_t xTicksToWait ) +{ + BaseType_t xEntryTimeSet = pdFALSE; + TimeOut_t xTimeOut; + Queue_t * const pxQueue = xQueue; + + /* Check the pointer is not NULL. */ + configASSERT( ( pxQueue ) ); + + /* The buffer into which data is received can only be NULL if the data size + * is zero (so no data is copied into the buffer). */ + configASSERT( !( ( ( pvBuffer ) == NULL ) && ( ( pxQueue )->uxItemSize != ( UBaseType_t ) 0U ) ) ); + + /* Cannot block if the scheduler is suspended. */ + #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) ) + { + configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) ); + } + #endif + + /*lint -save -e904 This function relaxes the coding standard somewhat to + * allow return statements within the function itself. This is done in the + * interest of execution time efficiency. */ + for( ; ; ) + { + taskENTER_CRITICAL(); + { + const UBaseType_t uxMessagesWaiting = pxQueue->uxMessagesWaiting; + + /* Is there data in the queue now? To be running the calling task + * must be the highest priority task wanting to access the queue. */ + if( uxMessagesWaiting > ( UBaseType_t ) 0 ) + { + /* Data available, remove one item. */ + prvCopyDataFromQueue( pxQueue, pvBuffer ); + traceQUEUE_RECEIVE( pxQueue ); + pxQueue->uxMessagesWaiting = uxMessagesWaiting - ( UBaseType_t ) 1; + + /* There is now space in the queue, were any tasks waiting to + * post to the queue? If so, unblock the highest priority waiting + * task. */ + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE ) + { + if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE ) + { + queueYIELD_IF_USING_PREEMPTION(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + taskEXIT_CRITICAL(); + return pdPASS; + } + else + { + if( xTicksToWait == ( TickType_t ) 0 ) + { + /* The queue was empty and no block time is specified (or + * the block time has expired) so leave now. */ + taskEXIT_CRITICAL(); + traceQUEUE_RECEIVE_FAILED( pxQueue ); + return errQUEUE_EMPTY; + } + else if( xEntryTimeSet == pdFALSE ) + { + /* The queue was empty and a block time was specified so + * configure the timeout structure. */ + vTaskInternalSetTimeOutState( &xTimeOut ); + xEntryTimeSet = pdTRUE; + } + else + { + /* Entry time was already set. */ + mtCOVERAGE_TEST_MARKER(); + } + } + } + taskEXIT_CRITICAL(); + + /* Interrupts and other tasks can send to and receive from the queue + * now the critical section has been exited. */ + + vTaskSuspendAll(); + prvLockQueue( pxQueue ); + + /* Update the timeout state to see if it has expired yet. */ + if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE ) + { + /* The timeout has not expired. If the queue is still empty place + * the task on the list of tasks waiting to receive from the queue. */ + if( prvIsQueueEmpty( pxQueue ) != pdFALSE ) + { + traceBLOCKING_ON_QUEUE_RECEIVE( pxQueue ); + vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait ); + prvUnlockQueue( pxQueue ); + + if( xTaskResumeAll() == pdFALSE ) + { + portYIELD_WITHIN_API(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + /* The queue contains data again. Loop back to try and read the + * data. */ + prvUnlockQueue( pxQueue ); + ( void ) xTaskResumeAll(); + } + } + else + { + /* Timed out. If there is no data in the queue exit, otherwise loop + * back and attempt to read the data. */ + prvUnlockQueue( pxQueue ); + ( void ) xTaskResumeAll(); + + if( prvIsQueueEmpty( pxQueue ) != pdFALSE ) + { + traceQUEUE_RECEIVE_FAILED( pxQueue ); + return errQUEUE_EMPTY; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + } /*lint -restore */ +} +/*-----------------------------------------------------------*/ + +BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue, + TickType_t xTicksToWait ) +{ + BaseType_t xEntryTimeSet = pdFALSE; + TimeOut_t xTimeOut; + Queue_t * const pxQueue = xQueue; + + #if ( configUSE_MUTEXES == 1 ) + BaseType_t xInheritanceOccurred = pdFALSE; + #endif + + /* Check the queue pointer is not NULL. */ + configASSERT( ( pxQueue ) ); + + /* Check this really is a semaphore, in which case the item size will be + * 0. */ + configASSERT( pxQueue->uxItemSize == 0 ); + + /* Cannot block if the scheduler is suspended. */ + #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) ) + { + configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) ); + } + #endif + + /*lint -save -e904 This function relaxes the coding standard somewhat to allow return + * statements within the function itself. This is done in the interest + * of execution time efficiency. */ + for( ; ; ) + { + taskENTER_CRITICAL(); + { + /* Semaphores are queues with an item size of 0, and where the + * number of messages in the queue is the semaphore's count value. */ + const UBaseType_t uxSemaphoreCount = pxQueue->uxMessagesWaiting; + + /* Is there data in the queue now? To be running the calling task + * must be the highest priority task wanting to access the queue. */ + if( uxSemaphoreCount > ( UBaseType_t ) 0 ) + { + traceQUEUE_RECEIVE( pxQueue ); + + /* Semaphores are queues with a data size of zero and where the + * messages waiting is the semaphore's count. Reduce the count. */ + pxQueue->uxMessagesWaiting = uxSemaphoreCount - ( UBaseType_t ) 1; + + #if ( configUSE_MUTEXES == 1 ) + { + if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX ) + { + /* Record the information required to implement + * priority inheritance should it become necessary. */ + pxQueue->u.xSemaphore.xMutexHolder = pvTaskIncrementMutexHeldCount(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + #endif /* configUSE_MUTEXES */ + + /* Check to see if other tasks are blocked waiting to give the + * semaphore, and if so, unblock the highest priority such task. */ + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE ) + { + if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE ) + { + queueYIELD_IF_USING_PREEMPTION(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + taskEXIT_CRITICAL(); + return pdPASS; + } + else + { + if( xTicksToWait == ( TickType_t ) 0 ) + { + /* For inheritance to have occurred there must have been an + * initial timeout, and an adjusted timeout cannot become 0, as + * if it were 0 the function would have exited. */ + #if ( configUSE_MUTEXES == 1 ) + { + configASSERT( xInheritanceOccurred == pdFALSE ); + } + #endif /* configUSE_MUTEXES */ + + /* The semaphore count was 0 and no block time is specified + * (or the block time has expired) so exit now. */ + taskEXIT_CRITICAL(); + traceQUEUE_RECEIVE_FAILED( pxQueue ); + return errQUEUE_EMPTY; + } + else if( xEntryTimeSet == pdFALSE ) + { + /* The semaphore count was 0 and a block time was specified + * so configure the timeout structure ready to block. */ + vTaskInternalSetTimeOutState( &xTimeOut ); + xEntryTimeSet = pdTRUE; + } + else + { + /* Entry time was already set. */ + mtCOVERAGE_TEST_MARKER(); + } + } + } + taskEXIT_CRITICAL(); + + /* Interrupts and other tasks can give to and take from the semaphore + * now the critical section has been exited. */ + + vTaskSuspendAll(); + prvLockQueue( pxQueue ); + + /* Update the timeout state to see if it has expired yet. */ + if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE ) + { + /* A block time is specified and not expired. If the semaphore + * count is 0 then enter the Blocked state to wait for a semaphore to + * become available. As semaphores are implemented with queues the + * queue being empty is equivalent to the semaphore count being 0. */ + if( prvIsQueueEmpty( pxQueue ) != pdFALSE ) + { + traceBLOCKING_ON_QUEUE_RECEIVE( pxQueue ); + + #if ( configUSE_MUTEXES == 1 ) + { + if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX ) + { + taskENTER_CRITICAL(); + { + xInheritanceOccurred = xTaskPriorityInherit( pxQueue->u.xSemaphore.xMutexHolder ); + } + taskEXIT_CRITICAL(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + #endif /* if ( configUSE_MUTEXES == 1 ) */ + + vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait ); + prvUnlockQueue( pxQueue ); + + if( xTaskResumeAll() == pdFALSE ) + { + portYIELD_WITHIN_API(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + /* There was no timeout and the semaphore count was not 0, so + * attempt to take the semaphore again. */ + prvUnlockQueue( pxQueue ); + ( void ) xTaskResumeAll(); + } + } + else + { + /* Timed out. */ + prvUnlockQueue( pxQueue ); + ( void ) xTaskResumeAll(); + + /* If the semaphore count is 0 exit now as the timeout has + * expired. Otherwise return to attempt to take the semaphore that is + * known to be available. As semaphores are implemented by queues the + * queue being empty is equivalent to the semaphore count being 0. */ + if( prvIsQueueEmpty( pxQueue ) != pdFALSE ) + { + #if ( configUSE_MUTEXES == 1 ) + { + /* xInheritanceOccurred could only have be set if + * pxQueue->uxQueueType == queueQUEUE_IS_MUTEX so no need to + * test the mutex type again to check it is actually a mutex. */ + if( xInheritanceOccurred != pdFALSE ) + { + taskENTER_CRITICAL(); + { + UBaseType_t uxHighestWaitingPriority; + + /* This task blocking on the mutex caused another + * task to inherit this task's priority. Now this task + * has timed out the priority should be disinherited + * again, but only as low as the next highest priority + * task that is waiting for the same mutex. */ + uxHighestWaitingPriority = prvGetDisinheritPriorityAfterTimeout( pxQueue ); + vTaskPriorityDisinheritAfterTimeout( pxQueue->u.xSemaphore.xMutexHolder, uxHighestWaitingPriority ); + } + taskEXIT_CRITICAL(); + } + } + #endif /* configUSE_MUTEXES */ + + traceQUEUE_RECEIVE_FAILED( pxQueue ); + return errQUEUE_EMPTY; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + } /*lint -restore */ +} +/*-----------------------------------------------------------*/ + +BaseType_t xQueuePeek( QueueHandle_t xQueue, + void * const pvBuffer, + TickType_t xTicksToWait ) +{ + BaseType_t xEntryTimeSet = pdFALSE; + TimeOut_t xTimeOut; + int8_t * pcOriginalReadPosition; + Queue_t * const pxQueue = xQueue; + + /* Check the pointer is not NULL. */ + configASSERT( ( pxQueue ) ); + + /* The buffer into which data is received can only be NULL if the data size + * is zero (so no data is copied into the buffer. */ + configASSERT( !( ( ( pvBuffer ) == NULL ) && ( ( pxQueue )->uxItemSize != ( UBaseType_t ) 0U ) ) ); + + /* Cannot block if the scheduler is suspended. */ + #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) ) + { + configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) ); + } + #endif + + /*lint -save -e904 This function relaxes the coding standard somewhat to + * allow return statements within the function itself. This is done in the + * interest of execution time efficiency. */ + for( ; ; ) + { + taskENTER_CRITICAL(); + { + const UBaseType_t uxMessagesWaiting = pxQueue->uxMessagesWaiting; + + /* Is there data in the queue now? To be running the calling task + * must be the highest priority task wanting to access the queue. */ + if( uxMessagesWaiting > ( UBaseType_t ) 0 ) + { + /* Remember the read position so it can be reset after the data + * is read from the queue as this function is only peeking the + * data, not removing it. */ + pcOriginalReadPosition = pxQueue->u.xQueue.pcReadFrom; + + prvCopyDataFromQueue( pxQueue, pvBuffer ); + traceQUEUE_PEEK( pxQueue ); + + /* The data is not being removed, so reset the read pointer. */ + pxQueue->u.xQueue.pcReadFrom = pcOriginalReadPosition; + + /* The data is being left in the queue, so see if there are + * any other tasks waiting for the data. */ + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE ) + { + if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE ) + { + /* The task waiting has a higher priority than this task. */ + queueYIELD_IF_USING_PREEMPTION(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + taskEXIT_CRITICAL(); + return pdPASS; + } + else + { + if( xTicksToWait == ( TickType_t ) 0 ) + { + /* The queue was empty and no block time is specified (or + * the block time has expired) so leave now. */ + taskEXIT_CRITICAL(); + traceQUEUE_PEEK_FAILED( pxQueue ); + return errQUEUE_EMPTY; + } + else if( xEntryTimeSet == pdFALSE ) + { + /* The queue was empty and a block time was specified so + * configure the timeout structure ready to enter the blocked + * state. */ + vTaskInternalSetTimeOutState( &xTimeOut ); + xEntryTimeSet = pdTRUE; + } + else + { + /* Entry time was already set. */ + mtCOVERAGE_TEST_MARKER(); + } + } + } + taskEXIT_CRITICAL(); + + /* Interrupts and other tasks can send to and receive from the queue + * now the critical section has been exited. */ + + vTaskSuspendAll(); + prvLockQueue( pxQueue ); + + /* Update the timeout state to see if it has expired yet. */ + if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE ) + { + /* Timeout has not expired yet, check to see if there is data in the + * queue now, and if not enter the Blocked state to wait for data. */ + if( prvIsQueueEmpty( pxQueue ) != pdFALSE ) + { + traceBLOCKING_ON_QUEUE_PEEK( pxQueue ); + vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait ); + prvUnlockQueue( pxQueue ); + + if( xTaskResumeAll() == pdFALSE ) + { + portYIELD_WITHIN_API(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + /* There is data in the queue now, so don't enter the blocked + * state, instead return to try and obtain the data. */ + prvUnlockQueue( pxQueue ); + ( void ) xTaskResumeAll(); + } + } + else + { + /* The timeout has expired. If there is still no data in the queue + * exit, otherwise go back and try to read the data again. */ + prvUnlockQueue( pxQueue ); + ( void ) xTaskResumeAll(); + + if( prvIsQueueEmpty( pxQueue ) != pdFALSE ) + { + traceQUEUE_PEEK_FAILED( pxQueue ); + return errQUEUE_EMPTY; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + } /*lint -restore */ +} +/*-----------------------------------------------------------*/ + +BaseType_t xQueueReceiveFromISR( QueueHandle_t xQueue, + void * const pvBuffer, + BaseType_t * const pxHigherPriorityTaskWoken ) +{ + BaseType_t xReturn; + UBaseType_t uxSavedInterruptStatus; + Queue_t * const pxQueue = xQueue; + + configASSERT( pxQueue ); + configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( UBaseType_t ) 0U ) ) ); + + /* RTOS ports that support interrupt nesting have the concept of a maximum + * system call (or maximum API call) interrupt priority. Interrupts that are + * above the maximum system call priority are kept permanently enabled, even + * when the RTOS kernel is in a critical section, but cannot make any calls to + * FreeRTOS API functions. If configASSERT() is defined in FreeRTOSConfig.h + * then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion + * failure if a FreeRTOS API function is called from an interrupt that has been + * assigned a priority above the configured maximum system call priority. + * Only FreeRTOS functions that end in FromISR can be called from interrupts + * that have been assigned a priority at or (logically) below the maximum + * system call interrupt priority. FreeRTOS maintains a separate interrupt + * safe API to ensure interrupt entry is as fast and as simple as possible. + * More information (albeit Cortex-M specific) is provided on the following + * link: https://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html */ + portASSERT_IF_INTERRUPT_PRIORITY_INVALID(); + + uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR(); + { + const UBaseType_t uxMessagesWaiting = pxQueue->uxMessagesWaiting; + + /* Cannot block in an ISR, so check there is data available. */ + if( uxMessagesWaiting > ( UBaseType_t ) 0 ) + { + const int8_t cRxLock = pxQueue->cRxLock; + + traceQUEUE_RECEIVE_FROM_ISR( pxQueue ); + + prvCopyDataFromQueue( pxQueue, pvBuffer ); + pxQueue->uxMessagesWaiting = uxMessagesWaiting - ( UBaseType_t ) 1; + + /* If the queue is locked the event list will not be modified. + * Instead update the lock count so the task that unlocks the queue + * will know that an ISR has removed data while the queue was + * locked. */ + if( cRxLock == queueUNLOCKED ) + { + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE ) + { + if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE ) + { + /* The task waiting has a higher priority than us so + * force a context switch. */ + if( pxHigherPriorityTaskWoken != NULL ) + { + *pxHigherPriorityTaskWoken = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + /* Increment the lock count so the task that unlocks the queue + * knows that data was removed while it was locked. */ + configASSERT( cRxLock != queueINT8_MAX ); + + pxQueue->cRxLock = ( int8_t ) ( cRxLock + 1 ); + } + + xReturn = pdPASS; + } + else + { + xReturn = pdFAIL; + traceQUEUE_RECEIVE_FROM_ISR_FAILED( pxQueue ); + } + } + portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); + + return xReturn; +} +/*-----------------------------------------------------------*/ + +BaseType_t xQueuePeekFromISR( QueueHandle_t xQueue, + void * const pvBuffer ) +{ + BaseType_t xReturn; + UBaseType_t uxSavedInterruptStatus; + int8_t * pcOriginalReadPosition; + Queue_t * const pxQueue = xQueue; + + configASSERT( pxQueue ); + configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( UBaseType_t ) 0U ) ) ); + configASSERT( pxQueue->uxItemSize != 0 ); /* Can't peek a semaphore. */ + + /* RTOS ports that support interrupt nesting have the concept of a maximum + * system call (or maximum API call) interrupt priority. Interrupts that are + * above the maximum system call priority are kept permanently enabled, even + * when the RTOS kernel is in a critical section, but cannot make any calls to + * FreeRTOS API functions. If configASSERT() is defined in FreeRTOSConfig.h + * then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion + * failure if a FreeRTOS API function is called from an interrupt that has been + * assigned a priority above the configured maximum system call priority. + * Only FreeRTOS functions that end in FromISR can be called from interrupts + * that have been assigned a priority at or (logically) below the maximum + * system call interrupt priority. FreeRTOS maintains a separate interrupt + * safe API to ensure interrupt entry is as fast and as simple as possible. + * More information (albeit Cortex-M specific) is provided on the following + * link: https://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html */ + portASSERT_IF_INTERRUPT_PRIORITY_INVALID(); + + uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR(); + { + /* Cannot block in an ISR, so check there is data available. */ + if( pxQueue->uxMessagesWaiting > ( UBaseType_t ) 0 ) + { + traceQUEUE_PEEK_FROM_ISR( pxQueue ); + + /* Remember the read position so it can be reset as nothing is + * actually being removed from the queue. */ + pcOriginalReadPosition = pxQueue->u.xQueue.pcReadFrom; + prvCopyDataFromQueue( pxQueue, pvBuffer ); + pxQueue->u.xQueue.pcReadFrom = pcOriginalReadPosition; + + xReturn = pdPASS; + } + else + { + xReturn = pdFAIL; + traceQUEUE_PEEK_FROM_ISR_FAILED( pxQueue ); + } + } + portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); + + return xReturn; +} +/*-----------------------------------------------------------*/ + +UBaseType_t uxQueueMessagesWaiting( const QueueHandle_t xQueue ) +{ + UBaseType_t uxReturn; + + configASSERT( xQueue ); + + taskENTER_CRITICAL(); + { + uxReturn = ( ( Queue_t * ) xQueue )->uxMessagesWaiting; + } + taskEXIT_CRITICAL(); + + return uxReturn; +} /*lint !e818 Pointer cannot be declared const as xQueue is a typedef not pointer. */ +/*-----------------------------------------------------------*/ + +UBaseType_t uxQueueSpacesAvailable( const QueueHandle_t xQueue ) +{ + UBaseType_t uxReturn; + Queue_t * const pxQueue = xQueue; + + configASSERT( pxQueue ); + + taskENTER_CRITICAL(); + { + uxReturn = pxQueue->uxLength - pxQueue->uxMessagesWaiting; + } + taskEXIT_CRITICAL(); + + return uxReturn; +} /*lint !e818 Pointer cannot be declared const as xQueue is a typedef not pointer. */ +/*-----------------------------------------------------------*/ + +UBaseType_t uxQueueMessagesWaitingFromISR( const QueueHandle_t xQueue ) +{ + UBaseType_t uxReturn; + Queue_t * const pxQueue = xQueue; + + configASSERT( pxQueue ); + uxReturn = pxQueue->uxMessagesWaiting; + + return uxReturn; +} /*lint !e818 Pointer cannot be declared const as xQueue is a typedef not pointer. */ +/*-----------------------------------------------------------*/ + +void vQueueDelete( QueueHandle_t xQueue ) +{ + Queue_t * const pxQueue = xQueue; + + configASSERT( pxQueue ); + traceQUEUE_DELETE( pxQueue ); + + #if ( configQUEUE_REGISTRY_SIZE > 0 ) + { + vQueueUnregisterQueue( pxQueue ); + } + #endif + + #if ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 0 ) ) + { + /* The queue can only have been allocated dynamically - free it + * again. */ + vPortFree( pxQueue ); + } + #elif ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) ) + { + /* The queue could have been allocated statically or dynamically, so + * check before attempting to free the memory. */ + if( pxQueue->ucStaticallyAllocated == ( uint8_t ) pdFALSE ) + { + vPortFree( pxQueue ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + #else /* if ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 0 ) ) */ + { + /* The queue must have been statically allocated, so is not going to be + * deleted. Avoid compiler warnings about the unused parameter. */ + ( void ) pxQueue; + } + #endif /* configSUPPORT_DYNAMIC_ALLOCATION */ +} +/*-----------------------------------------------------------*/ + +#if ( configUSE_TRACE_FACILITY == 1 ) + + UBaseType_t uxQueueGetQueueNumber( QueueHandle_t xQueue ) + { + return ( ( Queue_t * ) xQueue )->uxQueueNumber; + } + +#endif /* configUSE_TRACE_FACILITY */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_TRACE_FACILITY == 1 ) + + void vQueueSetQueueNumber( QueueHandle_t xQueue, + UBaseType_t uxQueueNumber ) + { + ( ( Queue_t * ) xQueue )->uxQueueNumber = uxQueueNumber; + } + +#endif /* configUSE_TRACE_FACILITY */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_TRACE_FACILITY == 1 ) + + uint8_t ucQueueGetQueueType( QueueHandle_t xQueue ) + { + return ( ( Queue_t * ) xQueue )->ucQueueType; + } + +#endif /* configUSE_TRACE_FACILITY */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_MUTEXES == 1 ) + + static UBaseType_t prvGetDisinheritPriorityAfterTimeout( const Queue_t * const pxQueue ) + { + UBaseType_t uxHighestPriorityOfWaitingTasks; + + /* If a task waiting for a mutex causes the mutex holder to inherit a + * priority, but the waiting task times out, then the holder should + * disinherit the priority - but only down to the highest priority of any + * other tasks that are waiting for the same mutex. For this purpose, + * return the priority of the highest priority task that is waiting for the + * mutex. */ + if( listCURRENT_LIST_LENGTH( &( pxQueue->xTasksWaitingToReceive ) ) > 0U ) + { + uxHighestPriorityOfWaitingTasks = ( UBaseType_t ) configMAX_PRIORITIES - ( UBaseType_t ) listGET_ITEM_VALUE_OF_HEAD_ENTRY( &( pxQueue->xTasksWaitingToReceive ) ); + } + else + { + uxHighestPriorityOfWaitingTasks = tskIDLE_PRIORITY; + } + + return uxHighestPriorityOfWaitingTasks; + } + +#endif /* configUSE_MUTEXES */ +/*-----------------------------------------------------------*/ + +static BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue, + const void * pvItemToQueue, + const BaseType_t xPosition ) +{ + BaseType_t xReturn = pdFALSE; + UBaseType_t uxMessagesWaiting; + + /* This function is called from a critical section. */ + + uxMessagesWaiting = pxQueue->uxMessagesWaiting; + + if( pxQueue->uxItemSize == ( UBaseType_t ) 0 ) + { + #if ( configUSE_MUTEXES == 1 ) + { + if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX ) + { + /* The mutex is no longer being held. */ + xReturn = xTaskPriorityDisinherit( pxQueue->u.xSemaphore.xMutexHolder ); + pxQueue->u.xSemaphore.xMutexHolder = NULL; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + #endif /* configUSE_MUTEXES */ + } + else if( xPosition == queueSEND_TO_BACK ) + { + ( void ) memcpy( ( void * ) pxQueue->pcWriteTo, pvItemToQueue, ( size_t ) pxQueue->uxItemSize ); /*lint !e961 !e418 !e9087 MISRA exception as the casts are only redundant for some ports, plus previous logic ensures a null pointer can only be passed to memcpy() if the copy size is 0. Cast to void required by function signature and safe as no alignment requirement and copy length specified in bytes. */ + pxQueue->pcWriteTo += pxQueue->uxItemSize; /*lint !e9016 Pointer arithmetic on char types ok, especially in this use case where it is the clearest way of conveying intent. */ + + if( pxQueue->pcWriteTo >= pxQueue->u.xQueue.pcTail ) /*lint !e946 MISRA exception justified as comparison of pointers is the cleanest solution. */ + { + pxQueue->pcWriteTo = pxQueue->pcHead; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + ( void ) memcpy( ( void * ) pxQueue->u.xQueue.pcReadFrom, pvItemToQueue, ( size_t ) pxQueue->uxItemSize ); /*lint !e961 !e9087 !e418 MISRA exception as the casts are only redundant for some ports. Cast to void required by function signature and safe as no alignment requirement and copy length specified in bytes. Assert checks null pointer only used when length is 0. */ + pxQueue->u.xQueue.pcReadFrom -= pxQueue->uxItemSize; + + if( pxQueue->u.xQueue.pcReadFrom < pxQueue->pcHead ) /*lint !e946 MISRA exception justified as comparison of pointers is the cleanest solution. */ + { + pxQueue->u.xQueue.pcReadFrom = ( pxQueue->u.xQueue.pcTail - pxQueue->uxItemSize ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + if( xPosition == queueOVERWRITE ) + { + if( uxMessagesWaiting > ( UBaseType_t ) 0 ) + { + /* An item is not being added but overwritten, so subtract + * one from the recorded number of items in the queue so when + * one is added again below the number of recorded items remains + * correct. */ + --uxMessagesWaiting; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + + pxQueue->uxMessagesWaiting = uxMessagesWaiting + ( UBaseType_t ) 1; + + return xReturn; +} +/*-----------------------------------------------------------*/ + +static void prvCopyDataFromQueue( Queue_t * const pxQueue, + void * const pvBuffer ) +{ + if( pxQueue->uxItemSize != ( UBaseType_t ) 0 ) + { + pxQueue->u.xQueue.pcReadFrom += pxQueue->uxItemSize; /*lint !e9016 Pointer arithmetic on char types ok, especially in this use case where it is the clearest way of conveying intent. */ + + if( pxQueue->u.xQueue.pcReadFrom >= pxQueue->u.xQueue.pcTail ) /*lint !e946 MISRA exception justified as use of the relational operator is the cleanest solutions. */ + { + pxQueue->u.xQueue.pcReadFrom = pxQueue->pcHead; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + ( void ) memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->u.xQueue.pcReadFrom, ( size_t ) pxQueue->uxItemSize ); /*lint !e961 !e418 !e9087 MISRA exception as the casts are only redundant for some ports. Also previous logic ensures a null pointer can only be passed to memcpy() when the count is 0. Cast to void required by function signature and safe as no alignment requirement and copy length specified in bytes. */ + } +} +/*-----------------------------------------------------------*/ + +static void prvUnlockQueue( Queue_t * const pxQueue ) +{ + /* THIS FUNCTION MUST BE CALLED WITH THE SCHEDULER SUSPENDED. */ + + /* The lock counts contains the number of extra data items placed or + * removed from the queue while the queue was locked. When a queue is + * locked items can be added or removed, but the event lists cannot be + * updated. */ + taskENTER_CRITICAL(); + { + int8_t cTxLock = pxQueue->cTxLock; + + /* See if data was added to the queue while it was locked. */ + while( cTxLock > queueLOCKED_UNMODIFIED ) + { + /* Data was posted while the queue was locked. Are any tasks + * blocked waiting for data to become available? */ + #if ( configUSE_QUEUE_SETS == 1 ) + { + if( pxQueue->pxQueueSetContainer != NULL ) + { + if( prvNotifyQueueSetContainer( pxQueue ) != pdFALSE ) + { + /* The queue is a member of a queue set, and posting to + * the queue set caused a higher priority task to unblock. + * A context switch is required. */ + vTaskMissedYield(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + /* Tasks that are removed from the event list will get + * added to the pending ready list as the scheduler is still + * suspended. */ + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE ) + { + if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE ) + { + /* The task waiting has a higher priority so record that a + * context switch is required. */ + vTaskMissedYield(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + break; + } + } + } + #else /* configUSE_QUEUE_SETS */ + { + /* Tasks that are removed from the event list will get added to + * the pending ready list as the scheduler is still suspended. */ + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE ) + { + if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE ) + { + /* The task waiting has a higher priority so record that + * a context switch is required. */ + vTaskMissedYield(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + break; + } + } + #endif /* configUSE_QUEUE_SETS */ + + --cTxLock; + } + + pxQueue->cTxLock = queueUNLOCKED; + } + taskEXIT_CRITICAL(); + + /* Do the same for the Rx lock. */ + taskENTER_CRITICAL(); + { + int8_t cRxLock = pxQueue->cRxLock; + + while( cRxLock > queueLOCKED_UNMODIFIED ) + { + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE ) + { + if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE ) + { + vTaskMissedYield(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + --cRxLock; + } + else + { + break; + } + } + + pxQueue->cRxLock = queueUNLOCKED; + } + taskEXIT_CRITICAL(); +} +/*-----------------------------------------------------------*/ + +static BaseType_t prvIsQueueEmpty( const Queue_t * pxQueue ) +{ + BaseType_t xReturn; + + taskENTER_CRITICAL(); + { + if( pxQueue->uxMessagesWaiting == ( UBaseType_t ) 0 ) + { + xReturn = pdTRUE; + } + else + { + xReturn = pdFALSE; + } + } + taskEXIT_CRITICAL(); + + return xReturn; +} +/*-----------------------------------------------------------*/ + +BaseType_t xQueueIsQueueEmptyFromISR( const QueueHandle_t xQueue ) +{ + BaseType_t xReturn; + Queue_t * const pxQueue = xQueue; + + configASSERT( pxQueue ); + + if( pxQueue->uxMessagesWaiting == ( UBaseType_t ) 0 ) + { + xReturn = pdTRUE; + } + else + { + xReturn = pdFALSE; + } + + return xReturn; +} /*lint !e818 xQueue could not be pointer to const because it is a typedef. */ +/*-----------------------------------------------------------*/ + +static BaseType_t prvIsQueueFull( const Queue_t * pxQueue ) +{ + BaseType_t xReturn; + + taskENTER_CRITICAL(); + { + if( pxQueue->uxMessagesWaiting == pxQueue->uxLength ) + { + xReturn = pdTRUE; + } + else + { + xReturn = pdFALSE; + } + } + taskEXIT_CRITICAL(); + + return xReturn; +} +/*-----------------------------------------------------------*/ + +BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue ) +{ + BaseType_t xReturn; + Queue_t * const pxQueue = xQueue; + + configASSERT( pxQueue ); + + if( pxQueue->uxMessagesWaiting == pxQueue->uxLength ) + { + xReturn = pdTRUE; + } + else + { + xReturn = pdFALSE; + } + + return xReturn; +} /*lint !e818 xQueue could not be pointer to const because it is a typedef. */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_CO_ROUTINES == 1 ) + + BaseType_t xQueueCRSend( QueueHandle_t xQueue, + const void * pvItemToQueue, + TickType_t xTicksToWait ) + { + BaseType_t xReturn; + Queue_t * const pxQueue = xQueue; + + /* If the queue is already full we may have to block. A critical section + * is required to prevent an interrupt removing something from the queue + * between the check to see if the queue is full and blocking on the queue. */ + portDISABLE_INTERRUPTS(); + { + if( prvIsQueueFull( pxQueue ) != pdFALSE ) + { + /* The queue is full - do we want to block or just leave without + * posting? */ + if( xTicksToWait > ( TickType_t ) 0 ) + { + /* As this is called from a coroutine we cannot block directly, but + * return indicating that we need to block. */ + vCoRoutineAddToDelayedList( xTicksToWait, &( pxQueue->xTasksWaitingToSend ) ); + portENABLE_INTERRUPTS(); + return errQUEUE_BLOCKED; + } + else + { + portENABLE_INTERRUPTS(); + return errQUEUE_FULL; + } + } + } + portENABLE_INTERRUPTS(); + + portDISABLE_INTERRUPTS(); + { + if( pxQueue->uxMessagesWaiting < pxQueue->uxLength ) + { + /* There is room in the queue, copy the data into the queue. */ + prvCopyDataToQueue( pxQueue, pvItemToQueue, queueSEND_TO_BACK ); + xReturn = pdPASS; + + /* Were any co-routines waiting for data to become available? */ + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE ) + { + /* In this instance the co-routine could be placed directly + * into the ready list as we are within a critical section. + * Instead the same pending ready list mechanism is used as if + * the event were caused from within an interrupt. */ + if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE ) + { + /* The co-routine waiting has a higher priority so record + * that a yield might be appropriate. */ + xReturn = errQUEUE_YIELD; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + xReturn = errQUEUE_FULL; + } + } + portENABLE_INTERRUPTS(); + + return xReturn; + } + +#endif /* configUSE_CO_ROUTINES */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_CO_ROUTINES == 1 ) + + BaseType_t xQueueCRReceive( QueueHandle_t xQueue, + void * pvBuffer, + TickType_t xTicksToWait ) + { + BaseType_t xReturn; + Queue_t * const pxQueue = xQueue; + + /* If the queue is already empty we may have to block. A critical section + * is required to prevent an interrupt adding something to the queue + * between the check to see if the queue is empty and blocking on the queue. */ + portDISABLE_INTERRUPTS(); + { + if( pxQueue->uxMessagesWaiting == ( UBaseType_t ) 0 ) + { + /* There are no messages in the queue, do we want to block or just + * leave with nothing? */ + if( xTicksToWait > ( TickType_t ) 0 ) + { + /* As this is a co-routine we cannot block directly, but return + * indicating that we need to block. */ + vCoRoutineAddToDelayedList( xTicksToWait, &( pxQueue->xTasksWaitingToReceive ) ); + portENABLE_INTERRUPTS(); + return errQUEUE_BLOCKED; + } + else + { + portENABLE_INTERRUPTS(); + return errQUEUE_FULL; + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + portENABLE_INTERRUPTS(); + + portDISABLE_INTERRUPTS(); + { + if( pxQueue->uxMessagesWaiting > ( UBaseType_t ) 0 ) + { + /* Data is available from the queue. */ + pxQueue->u.xQueue.pcReadFrom += pxQueue->uxItemSize; + + if( pxQueue->u.xQueue.pcReadFrom >= pxQueue->u.xQueue.pcTail ) + { + pxQueue->u.xQueue.pcReadFrom = pxQueue->pcHead; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + --( pxQueue->uxMessagesWaiting ); + ( void ) memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->u.xQueue.pcReadFrom, ( unsigned ) pxQueue->uxItemSize ); + + xReturn = pdPASS; + + /* Were any co-routines waiting for space to become available? */ + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE ) + { + /* In this instance the co-routine could be placed directly + * into the ready list as we are within a critical section. + * Instead the same pending ready list mechanism is used as if + * the event were caused from within an interrupt. */ + if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE ) + { + xReturn = errQUEUE_YIELD; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + xReturn = pdFAIL; + } + } + portENABLE_INTERRUPTS(); + + return xReturn; + } + +#endif /* configUSE_CO_ROUTINES */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_CO_ROUTINES == 1 ) + + BaseType_t xQueueCRSendFromISR( QueueHandle_t xQueue, + const void * pvItemToQueue, + BaseType_t xCoRoutinePreviouslyWoken ) + { + Queue_t * const pxQueue = xQueue; + + /* Cannot block within an ISR so if there is no space on the queue then + * exit without doing anything. */ + if( pxQueue->uxMessagesWaiting < pxQueue->uxLength ) + { + prvCopyDataToQueue( pxQueue, pvItemToQueue, queueSEND_TO_BACK ); + + /* We only want to wake one co-routine per ISR, so check that a + * co-routine has not already been woken. */ + if( xCoRoutinePreviouslyWoken == pdFALSE ) + { + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE ) + { + if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE ) + { + return pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + return xCoRoutinePreviouslyWoken; + } + +#endif /* configUSE_CO_ROUTINES */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_CO_ROUTINES == 1 ) + + BaseType_t xQueueCRReceiveFromISR( QueueHandle_t xQueue, + void * pvBuffer, + BaseType_t * pxCoRoutineWoken ) + { + BaseType_t xReturn; + Queue_t * const pxQueue = xQueue; + + /* We cannot block from an ISR, so check there is data available. If + * not then just leave without doing anything. */ + if( pxQueue->uxMessagesWaiting > ( UBaseType_t ) 0 ) + { + /* Copy the data from the queue. */ + pxQueue->u.xQueue.pcReadFrom += pxQueue->uxItemSize; + + if( pxQueue->u.xQueue.pcReadFrom >= pxQueue->u.xQueue.pcTail ) + { + pxQueue->u.xQueue.pcReadFrom = pxQueue->pcHead; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + --( pxQueue->uxMessagesWaiting ); + ( void ) memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->u.xQueue.pcReadFrom, ( unsigned ) pxQueue->uxItemSize ); + + if( ( *pxCoRoutineWoken ) == pdFALSE ) + { + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE ) + { + if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE ) + { + *pxCoRoutineWoken = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + xReturn = pdPASS; + } + else + { + xReturn = pdFAIL; + } + + return xReturn; + } + +#endif /* configUSE_CO_ROUTINES */ +/*-----------------------------------------------------------*/ + +#if ( configQUEUE_REGISTRY_SIZE > 0 ) + + void vQueueAddToRegistry( QueueHandle_t xQueue, + const char * pcQueueName ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + { + UBaseType_t ux; + + /* See if there is an empty space in the registry. A NULL name denotes + * a free slot. */ + for( ux = ( UBaseType_t ) 0U; ux < ( UBaseType_t ) configQUEUE_REGISTRY_SIZE; ux++ ) + { + if( xQueueRegistry[ ux ].pcQueueName == NULL ) + { + /* Store the information on this queue. */ + xQueueRegistry[ ux ].pcQueueName = pcQueueName; + xQueueRegistry[ ux ].xHandle = xQueue; + + traceQUEUE_REGISTRY_ADD( xQueue, pcQueueName ); + break; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + } + +#endif /* configQUEUE_REGISTRY_SIZE */ +/*-----------------------------------------------------------*/ + +#if ( configQUEUE_REGISTRY_SIZE > 0 ) + + const char * pcQueueGetName( QueueHandle_t xQueue ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + { + UBaseType_t ux; + const char * pcReturn = NULL; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + + /* Note there is nothing here to protect against another task adding or + * removing entries from the registry while it is being searched. */ + + for( ux = ( UBaseType_t ) 0U; ux < ( UBaseType_t ) configQUEUE_REGISTRY_SIZE; ux++ ) + { + if( xQueueRegistry[ ux ].xHandle == xQueue ) + { + pcReturn = xQueueRegistry[ ux ].pcQueueName; + break; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + + return pcReturn; + } /*lint !e818 xQueue cannot be a pointer to const because it is a typedef. */ + +#endif /* configQUEUE_REGISTRY_SIZE */ +/*-----------------------------------------------------------*/ + +#if ( configQUEUE_REGISTRY_SIZE > 0 ) + + void vQueueUnregisterQueue( QueueHandle_t xQueue ) + { + UBaseType_t ux; + + /* See if the handle of the queue being unregistered in actually in the + * registry. */ + for( ux = ( UBaseType_t ) 0U; ux < ( UBaseType_t ) configQUEUE_REGISTRY_SIZE; ux++ ) + { + if( xQueueRegistry[ ux ].xHandle == xQueue ) + { + /* Set the name to NULL to show that this slot if free again. */ + xQueueRegistry[ ux ].pcQueueName = NULL; + + /* Set the handle to NULL to ensure the same queue handle cannot + * appear in the registry twice if it is added, removed, then + * added again. */ + xQueueRegistry[ ux ].xHandle = ( QueueHandle_t ) 0; + break; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + } /*lint !e818 xQueue could not be pointer to const because it is a typedef. */ + +#endif /* configQUEUE_REGISTRY_SIZE */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_TIMERS == 1 ) + + void vQueueWaitForMessageRestricted( QueueHandle_t xQueue, + TickType_t xTicksToWait, + const BaseType_t xWaitIndefinitely ) + { + Queue_t * const pxQueue = xQueue; + + /* This function should not be called by application code hence the + * 'Restricted' in its name. It is not part of the public API. It is + * designed for use by kernel code, and has special calling requirements. + * It can result in vListInsert() being called on a list that can only + * possibly ever have one item in it, so the list will be fast, but even + * so it should be called with the scheduler locked and not from a critical + * section. */ + + /* Only do anything if there are no messages in the queue. This function + * will not actually cause the task to block, just place it on a blocked + * list. It will not block until the scheduler is unlocked - at which + * time a yield will be performed. If an item is added to the queue while + * the queue is locked, and the calling task blocks on the queue, then the + * calling task will be immediately unblocked when the queue is unlocked. */ + prvLockQueue( pxQueue ); + + if( pxQueue->uxMessagesWaiting == ( UBaseType_t ) 0U ) + { + /* There is nothing in the queue, block for the specified period. */ + vTaskPlaceOnEventListRestricted( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait, xWaitIndefinitely ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + prvUnlockQueue( pxQueue ); + } + +#endif /* configUSE_TIMERS */ +/*-----------------------------------------------------------*/ + +#if ( ( configUSE_QUEUE_SETS == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) + + QueueSetHandle_t xQueueCreateSet( const UBaseType_t uxEventQueueLength ) + { + QueueSetHandle_t pxQueue; + + pxQueue = xQueueGenericCreate( uxEventQueueLength, ( UBaseType_t ) sizeof( Queue_t * ), queueQUEUE_TYPE_SET ); + + return pxQueue; + } + +#endif /* configUSE_QUEUE_SETS */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_QUEUE_SETS == 1 ) + + BaseType_t xQueueAddToSet( QueueSetMemberHandle_t xQueueOrSemaphore, + QueueSetHandle_t xQueueSet ) + { + BaseType_t xReturn; + + taskENTER_CRITICAL(); + { + if( ( ( Queue_t * ) xQueueOrSemaphore )->pxQueueSetContainer != NULL ) + { + /* Cannot add a queue/semaphore to more than one queue set. */ + xReturn = pdFAIL; + } + else if( ( ( Queue_t * ) xQueueOrSemaphore )->uxMessagesWaiting != ( UBaseType_t ) 0 ) + { + /* Cannot add a queue/semaphore to a queue set if there are already + * items in the queue/semaphore. */ + xReturn = pdFAIL; + } + else + { + ( ( Queue_t * ) xQueueOrSemaphore )->pxQueueSetContainer = xQueueSet; + xReturn = pdPASS; + } + } + taskEXIT_CRITICAL(); + + return xReturn; + } + +#endif /* configUSE_QUEUE_SETS */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_QUEUE_SETS == 1 ) + + BaseType_t xQueueRemoveFromSet( QueueSetMemberHandle_t xQueueOrSemaphore, + QueueSetHandle_t xQueueSet ) + { + BaseType_t xReturn; + Queue_t * const pxQueueOrSemaphore = ( Queue_t * ) xQueueOrSemaphore; + + if( pxQueueOrSemaphore->pxQueueSetContainer != xQueueSet ) + { + /* The queue was not a member of the set. */ + xReturn = pdFAIL; + } + else if( pxQueueOrSemaphore->uxMessagesWaiting != ( UBaseType_t ) 0 ) + { + /* It is dangerous to remove a queue from a set when the queue is + * not empty because the queue set will still hold pending events for + * the queue. */ + xReturn = pdFAIL; + } + else + { + taskENTER_CRITICAL(); + { + /* The queue is no longer contained in the set. */ + pxQueueOrSemaphore->pxQueueSetContainer = NULL; + } + taskEXIT_CRITICAL(); + xReturn = pdPASS; + } + + return xReturn; + } /*lint !e818 xQueueSet could not be declared as pointing to const as it is a typedef. */ + +#endif /* configUSE_QUEUE_SETS */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_QUEUE_SETS == 1 ) + + QueueSetMemberHandle_t xQueueSelectFromSet( QueueSetHandle_t xQueueSet, + TickType_t const xTicksToWait ) + { + QueueSetMemberHandle_t xReturn = NULL; + + ( void ) xQueueReceive( ( QueueHandle_t ) xQueueSet, &xReturn, xTicksToWait ); /*lint !e961 Casting from one typedef to another is not redundant. */ + return xReturn; + } + +#endif /* configUSE_QUEUE_SETS */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_QUEUE_SETS == 1 ) + + QueueSetMemberHandle_t xQueueSelectFromSetFromISR( QueueSetHandle_t xQueueSet ) + { + QueueSetMemberHandle_t xReturn = NULL; + + ( void ) xQueueReceiveFromISR( ( QueueHandle_t ) xQueueSet, &xReturn, NULL ); /*lint !e961 Casting from one typedef to another is not redundant. */ + return xReturn; + } + +#endif /* configUSE_QUEUE_SETS */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_QUEUE_SETS == 1 ) + + static BaseType_t prvNotifyQueueSetContainer( const Queue_t * const pxQueue ) + { + Queue_t * pxQueueSetContainer = pxQueue->pxQueueSetContainer; + BaseType_t xReturn = pdFALSE; + + /* This function must be called form a critical section. */ + + configASSERT( pxQueueSetContainer ); + configASSERT( pxQueueSetContainer->uxMessagesWaiting < pxQueueSetContainer->uxLength ); + + if( pxQueueSetContainer->uxMessagesWaiting < pxQueueSetContainer->uxLength ) + { + const int8_t cTxLock = pxQueueSetContainer->cTxLock; + + traceQUEUE_SET_SEND( pxQueueSetContainer ); + + /* The data copied is the handle of the queue that contains data. */ + xReturn = prvCopyDataToQueue( pxQueueSetContainer, &pxQueue, queueSEND_TO_BACK ); + + if( cTxLock == queueUNLOCKED ) + { + if( listLIST_IS_EMPTY( &( pxQueueSetContainer->xTasksWaitingToReceive ) ) == pdFALSE ) + { + if( xTaskRemoveFromEventList( &( pxQueueSetContainer->xTasksWaitingToReceive ) ) != pdFALSE ) + { + /* The task waiting has a higher priority. */ + xReturn = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + configASSERT( cTxLock != queueINT8_MAX ); + + pxQueueSetContainer->cTxLock = ( int8_t ) ( cTxLock + 1 ); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + return xReturn; + } + +#endif /* configUSE_QUEUE_SETS */ diff --git a/RTOS/FreeRTOS/Source/stream_buffer.c b/RTOS/FreeRTOS/Source/stream_buffer.c new file mode 100644 index 0000000..eb15bc3 --- /dev/null +++ b/RTOS/FreeRTOS/Source/stream_buffer.c @@ -0,0 +1,1326 @@ +/* + * FreeRTOS Kernel V10.4.1 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * https://www.FreeRTOS.org + * https://github.com/FreeRTOS + * + */ + +/* Standard includes. */ +#include +#include + +/* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining + * all the API functions to use the MPU wrappers. That should only be done when + * task.h is included from an application file. */ +#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE + +/* FreeRTOS includes. */ +#include "FreeRTOS.h" +#include "task.h" +#include "stream_buffer.h" + +#if ( configUSE_TASK_NOTIFICATIONS != 1 ) + #error configUSE_TASK_NOTIFICATIONS must be set to 1 to build stream_buffer.c +#endif + +/* Lint e961, e9021 and e750 are suppressed as a MISRA exception justified + * because the MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be defined + * for the header files above, but not in this file, in order to generate the + * correct privileged Vs unprivileged linkage and placement. */ +#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE /*lint !e961 !e750 !e9021. */ + +/* If the user has not provided application specific Rx notification macros, + * or #defined the notification macros away, them provide default implementations + * that uses task notifications. */ +/*lint -save -e9026 Function like macros allowed and needed here so they can be overridden. */ +#ifndef sbRECEIVE_COMPLETED + #define sbRECEIVE_COMPLETED( pxStreamBuffer ) \ + vTaskSuspendAll(); \ + { \ + if( ( pxStreamBuffer )->xTaskWaitingToSend != NULL ) \ + { \ + ( void ) xTaskNotify( ( pxStreamBuffer )->xTaskWaitingToSend, \ + ( uint32_t ) 0, \ + eNoAction ); \ + ( pxStreamBuffer )->xTaskWaitingToSend = NULL; \ + } \ + } \ + ( void ) xTaskResumeAll(); +#endif /* sbRECEIVE_COMPLETED */ + +#ifndef sbRECEIVE_COMPLETED_FROM_ISR + #define sbRECEIVE_COMPLETED_FROM_ISR( pxStreamBuffer, \ + pxHigherPriorityTaskWoken ) \ + { \ + UBaseType_t uxSavedInterruptStatus; \ + \ + uxSavedInterruptStatus = ( UBaseType_t ) portSET_INTERRUPT_MASK_FROM_ISR(); \ + { \ + if( ( pxStreamBuffer )->xTaskWaitingToSend != NULL ) \ + { \ + ( void ) xTaskNotifyFromISR( ( pxStreamBuffer )->xTaskWaitingToSend, \ + ( uint32_t ) 0, \ + eNoAction, \ + pxHigherPriorityTaskWoken ); \ + ( pxStreamBuffer )->xTaskWaitingToSend = NULL; \ + } \ + } \ + portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); \ + } +#endif /* sbRECEIVE_COMPLETED_FROM_ISR */ + +/* If the user has not provided an application specific Tx notification macro, + * or #defined the notification macro away, them provide a default implementation + * that uses task notifications. */ +#ifndef sbSEND_COMPLETED + #define sbSEND_COMPLETED( pxStreamBuffer ) \ + vTaskSuspendAll(); \ + { \ + if( ( pxStreamBuffer )->xTaskWaitingToReceive != NULL ) \ + { \ + ( void ) xTaskNotify( ( pxStreamBuffer )->xTaskWaitingToReceive, \ + ( uint32_t ) 0, \ + eNoAction ); \ + ( pxStreamBuffer )->xTaskWaitingToReceive = NULL; \ + } \ + } \ + ( void ) xTaskResumeAll(); +#endif /* sbSEND_COMPLETED */ + +#ifndef sbSEND_COMPLETE_FROM_ISR + #define sbSEND_COMPLETE_FROM_ISR( pxStreamBuffer, pxHigherPriorityTaskWoken ) \ + { \ + UBaseType_t uxSavedInterruptStatus; \ + \ + uxSavedInterruptStatus = ( UBaseType_t ) portSET_INTERRUPT_MASK_FROM_ISR(); \ + { \ + if( ( pxStreamBuffer )->xTaskWaitingToReceive != NULL ) \ + { \ + ( void ) xTaskNotifyFromISR( ( pxStreamBuffer )->xTaskWaitingToReceive, \ + ( uint32_t ) 0, \ + eNoAction, \ + pxHigherPriorityTaskWoken ); \ + ( pxStreamBuffer )->xTaskWaitingToReceive = NULL; \ + } \ + } \ + portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); \ + } +#endif /* sbSEND_COMPLETE_FROM_ISR */ +/*lint -restore (9026) */ + +/* The number of bytes used to hold the length of a message in the buffer. */ +#define sbBYTES_TO_STORE_MESSAGE_LENGTH ( sizeof( configMESSAGE_BUFFER_LENGTH_TYPE ) ) + +/* Bits stored in the ucFlags field of the stream buffer. */ +#define sbFLAGS_IS_MESSAGE_BUFFER ( ( uint8_t ) 1 ) /* Set if the stream buffer was created as a message buffer, in which case it holds discrete messages rather than a stream. */ +#define sbFLAGS_IS_STATICALLY_ALLOCATED ( ( uint8_t ) 2 ) /* Set if the stream buffer was created using statically allocated memory. */ + +/*-----------------------------------------------------------*/ + +/* Structure that hold state information on the buffer. */ +typedef struct StreamBufferDef_t /*lint !e9058 Style convention uses tag. */ +{ + volatile size_t xTail; /* Index to the next item to read within the buffer. */ + volatile size_t xHead; /* Index to the next item to write within the buffer. */ + size_t xLength; /* The length of the buffer pointed to by pucBuffer. */ + size_t xTriggerLevelBytes; /* The number of bytes that must be in the stream buffer before a task that is waiting for data is unblocked. */ + volatile TaskHandle_t xTaskWaitingToReceive; /* Holds the handle of a task waiting for data, or NULL if no tasks are waiting. */ + volatile TaskHandle_t xTaskWaitingToSend; /* Holds the handle of a task waiting to send data to a message buffer that is full. */ + uint8_t * pucBuffer; /* Points to the buffer itself - that is - the RAM that stores the data passed through the buffer. */ + uint8_t ucFlags; + + #if ( configUSE_TRACE_FACILITY == 1 ) + UBaseType_t uxStreamBufferNumber; /* Used for tracing purposes. */ + #endif +} StreamBuffer_t; + +/* + * The number of bytes available to be read from the buffer. + */ +static size_t prvBytesInBuffer( const StreamBuffer_t * const pxStreamBuffer ) PRIVILEGED_FUNCTION; + +/* + * Add xCount bytes from pucData into the pxStreamBuffer message buffer. + * Returns the number of bytes written, which will either equal xCount in the + * success case, or 0 if there was not enough space in the buffer (in which case + * no data is written into the buffer). + */ +static size_t prvWriteBytesToBuffer( StreamBuffer_t * const pxStreamBuffer, + const uint8_t * pucData, + size_t xCount ) PRIVILEGED_FUNCTION; + +/* + * If the stream buffer is being used as a message buffer, then reads an entire + * message out of the buffer. If the stream buffer is being used as a stream + * buffer then read as many bytes as possible from the buffer. + * prvReadBytesFromBuffer() is called to actually extract the bytes from the + * buffer's data storage area. + */ +static size_t prvReadMessageFromBuffer( StreamBuffer_t * pxStreamBuffer, + void * pvRxData, + size_t xBufferLengthBytes, + size_t xBytesAvailable, + size_t xBytesToStoreMessageLength ) PRIVILEGED_FUNCTION; + +/* + * If the stream buffer is being used as a message buffer, then writes an entire + * message to the buffer. If the stream buffer is being used as a stream + * buffer then write as many bytes as possible to the buffer. + * prvWriteBytestoBuffer() is called to actually send the bytes to the buffer's + * data storage area. + */ +static size_t prvWriteMessageToBuffer( StreamBuffer_t * const pxStreamBuffer, + const void * pvTxData, + size_t xDataLengthBytes, + size_t xSpace, + size_t xRequiredSpace ) PRIVILEGED_FUNCTION; + +/* + * Read xMaxCount bytes from the pxStreamBuffer message buffer and write them + * to pucData. + */ +static size_t prvReadBytesFromBuffer( StreamBuffer_t * pxStreamBuffer, + uint8_t * pucData, + size_t xMaxCount, + size_t xBytesAvailable ) PRIVILEGED_FUNCTION; + +/* + * Called by both pxStreamBufferCreate() and pxStreamBufferCreateStatic() to + * initialise the members of the newly created stream buffer structure. + */ +static void prvInitialiseNewStreamBuffer( StreamBuffer_t * const pxStreamBuffer, + uint8_t * const pucBuffer, + size_t xBufferSizeBytes, + size_t xTriggerLevelBytes, + uint8_t ucFlags ) PRIVILEGED_FUNCTION; + +/*-----------------------------------------------------------*/ + +#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + + StreamBufferHandle_t xStreamBufferGenericCreate( size_t xBufferSizeBytes, + size_t xTriggerLevelBytes, + BaseType_t xIsMessageBuffer ) + { + uint8_t * pucAllocatedMemory; + uint8_t ucFlags; + + /* In case the stream buffer is going to be used as a message buffer + * (that is, it will hold discrete messages with a little meta data that + * says how big the next message is) check the buffer will be large enough + * to hold at least one message. */ + if( xIsMessageBuffer == pdTRUE ) + { + /* Is a message buffer but not statically allocated. */ + ucFlags = sbFLAGS_IS_MESSAGE_BUFFER; + configASSERT( xBufferSizeBytes > sbBYTES_TO_STORE_MESSAGE_LENGTH ); + } + else + { + /* Not a message buffer and not statically allocated. */ + ucFlags = 0; + configASSERT( xBufferSizeBytes > 0 ); + } + + configASSERT( xTriggerLevelBytes <= xBufferSizeBytes ); + + /* A trigger level of 0 would cause a waiting task to unblock even when + * the buffer was empty. */ + if( xTriggerLevelBytes == ( size_t ) 0 ) + { + xTriggerLevelBytes = ( size_t ) 1; + } + + /* A stream buffer requires a StreamBuffer_t structure and a buffer. + * Both are allocated in a single call to pvPortMalloc(). The + * StreamBuffer_t structure is placed at the start of the allocated memory + * and the buffer follows immediately after. The requested size is + * incremented so the free space is returned as the user would expect - + * this is a quirk of the implementation that means otherwise the free + * space would be reported as one byte smaller than would be logically + * expected. */ + xBufferSizeBytes++; + pucAllocatedMemory = ( uint8_t * ) pvPortMalloc( xBufferSizeBytes + sizeof( StreamBuffer_t ) ); /*lint !e9079 malloc() only returns void*. */ + + if( pucAllocatedMemory != NULL ) + { + prvInitialiseNewStreamBuffer( ( StreamBuffer_t * ) pucAllocatedMemory, /* Structure at the start of the allocated memory. */ /*lint !e9087 Safe cast as allocated memory is aligned. */ /*lint !e826 Area is not too small and alignment is guaranteed provided malloc() behaves as expected and returns aligned buffer. */ + pucAllocatedMemory + sizeof( StreamBuffer_t ), /* Storage area follows. */ /*lint !e9016 Indexing past structure valid for uint8_t pointer, also storage area has no alignment requirement. */ + xBufferSizeBytes, + xTriggerLevelBytes, + ucFlags ); + + traceSTREAM_BUFFER_CREATE( ( ( StreamBuffer_t * ) pucAllocatedMemory ), xIsMessageBuffer ); + } + else + { + traceSTREAM_BUFFER_CREATE_FAILED( xIsMessageBuffer ); + } + + return ( StreamBufferHandle_t ) pucAllocatedMemory; /*lint !e9087 !e826 Safe cast as allocated memory is aligned. */ + } + +#endif /* configSUPPORT_DYNAMIC_ALLOCATION */ +/*-----------------------------------------------------------*/ + +#if ( configSUPPORT_STATIC_ALLOCATION == 1 ) + + StreamBufferHandle_t xStreamBufferGenericCreateStatic( size_t xBufferSizeBytes, + size_t xTriggerLevelBytes, + BaseType_t xIsMessageBuffer, + uint8_t * const pucStreamBufferStorageArea, + StaticStreamBuffer_t * const pxStaticStreamBuffer ) + { + StreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) pxStaticStreamBuffer; /*lint !e740 !e9087 Safe cast as StaticStreamBuffer_t is opaque Streambuffer_t. */ + StreamBufferHandle_t xReturn; + uint8_t ucFlags; + + configASSERT( pucStreamBufferStorageArea ); + configASSERT( pxStaticStreamBuffer ); + configASSERT( xTriggerLevelBytes <= xBufferSizeBytes ); + + /* A trigger level of 0 would cause a waiting task to unblock even when + * the buffer was empty. */ + if( xTriggerLevelBytes == ( size_t ) 0 ) + { + xTriggerLevelBytes = ( size_t ) 1; + } + + if( xIsMessageBuffer != pdFALSE ) + { + /* Statically allocated message buffer. */ + ucFlags = sbFLAGS_IS_MESSAGE_BUFFER | sbFLAGS_IS_STATICALLY_ALLOCATED; + } + else + { + /* Statically allocated stream buffer. */ + ucFlags = sbFLAGS_IS_STATICALLY_ALLOCATED; + } + + /* In case the stream buffer is going to be used as a message buffer + * (that is, it will hold discrete messages with a little meta data that + * says how big the next message is) check the buffer will be large enough + * to hold at least one message. */ + configASSERT( xBufferSizeBytes > sbBYTES_TO_STORE_MESSAGE_LENGTH ); + + #if ( configASSERT_DEFINED == 1 ) + { + /* Sanity check that the size of the structure used to declare a + * variable of type StaticStreamBuffer_t equals the size of the real + * message buffer structure. */ + volatile size_t xSize = sizeof( StaticStreamBuffer_t ); + configASSERT( xSize == sizeof( StreamBuffer_t ) ); + } /*lint !e529 xSize is referenced is configASSERT() is defined. */ + #endif /* configASSERT_DEFINED */ + + if( ( pucStreamBufferStorageArea != NULL ) && ( pxStaticStreamBuffer != NULL ) ) + { + prvInitialiseNewStreamBuffer( pxStreamBuffer, + pucStreamBufferStorageArea, + xBufferSizeBytes, + xTriggerLevelBytes, + ucFlags ); + + /* Remember this was statically allocated in case it is ever deleted + * again. */ + pxStreamBuffer->ucFlags |= sbFLAGS_IS_STATICALLY_ALLOCATED; + + traceSTREAM_BUFFER_CREATE( pxStreamBuffer, xIsMessageBuffer ); + + xReturn = ( StreamBufferHandle_t ) pxStaticStreamBuffer; /*lint !e9087 Data hiding requires cast to opaque type. */ + } + else + { + xReturn = NULL; + traceSTREAM_BUFFER_CREATE_STATIC_FAILED( xReturn, xIsMessageBuffer ); + } + + return xReturn; + } + +#endif /* ( configSUPPORT_STATIC_ALLOCATION == 1 ) */ +/*-----------------------------------------------------------*/ + +void vStreamBufferDelete( StreamBufferHandle_t xStreamBuffer ) +{ + StreamBuffer_t * pxStreamBuffer = xStreamBuffer; + + configASSERT( pxStreamBuffer ); + + traceSTREAM_BUFFER_DELETE( xStreamBuffer ); + + if( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_STATICALLY_ALLOCATED ) == ( uint8_t ) pdFALSE ) + { + #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + { + /* Both the structure and the buffer were allocated using a single call + * to pvPortMalloc(), hence only one call to vPortFree() is required. */ + vPortFree( ( void * ) pxStreamBuffer ); /*lint !e9087 Standard free() semantics require void *, plus pxStreamBuffer was allocated by pvPortMalloc(). */ + } + #else + { + /* Should not be possible to get here, ucFlags must be corrupt. + * Force an assert. */ + configASSERT( xStreamBuffer == ( StreamBufferHandle_t ) ~0 ); + } + #endif + } + else + { + /* The structure and buffer were not allocated dynamically and cannot be + * freed - just scrub the structure so future use will assert. */ + ( void ) memset( pxStreamBuffer, 0x00, sizeof( StreamBuffer_t ) ); + } +} +/*-----------------------------------------------------------*/ + +BaseType_t xStreamBufferReset( StreamBufferHandle_t xStreamBuffer ) +{ + StreamBuffer_t * const pxStreamBuffer = xStreamBuffer; + BaseType_t xReturn = pdFAIL; + + #if ( configUSE_TRACE_FACILITY == 1 ) + UBaseType_t uxStreamBufferNumber; + #endif + + configASSERT( pxStreamBuffer ); + + #if ( configUSE_TRACE_FACILITY == 1 ) + { + /* Store the stream buffer number so it can be restored after the + * reset. */ + uxStreamBufferNumber = pxStreamBuffer->uxStreamBufferNumber; + } + #endif + + /* Can only reset a message buffer if there are no tasks blocked on it. */ + taskENTER_CRITICAL(); + { + if( pxStreamBuffer->xTaskWaitingToReceive == NULL ) + { + if( pxStreamBuffer->xTaskWaitingToSend == NULL ) + { + prvInitialiseNewStreamBuffer( pxStreamBuffer, + pxStreamBuffer->pucBuffer, + pxStreamBuffer->xLength, + pxStreamBuffer->xTriggerLevelBytes, + pxStreamBuffer->ucFlags ); + xReturn = pdPASS; + + #if ( configUSE_TRACE_FACILITY == 1 ) + { + pxStreamBuffer->uxStreamBufferNumber = uxStreamBufferNumber; + } + #endif + + traceSTREAM_BUFFER_RESET( xStreamBuffer ); + } + } + } + taskEXIT_CRITICAL(); + + return xReturn; +} +/*-----------------------------------------------------------*/ + +BaseType_t xStreamBufferSetTriggerLevel( StreamBufferHandle_t xStreamBuffer, + size_t xTriggerLevel ) +{ + StreamBuffer_t * const pxStreamBuffer = xStreamBuffer; + BaseType_t xReturn; + + configASSERT( pxStreamBuffer ); + + /* It is not valid for the trigger level to be 0. */ + if( xTriggerLevel == ( size_t ) 0 ) + { + xTriggerLevel = ( size_t ) 1; + } + + /* The trigger level is the number of bytes that must be in the stream + * buffer before a task that is waiting for data is unblocked. */ + if( xTriggerLevel <= pxStreamBuffer->xLength ) + { + pxStreamBuffer->xTriggerLevelBytes = xTriggerLevel; + xReturn = pdPASS; + } + else + { + xReturn = pdFALSE; + } + + return xReturn; +} +/*-----------------------------------------------------------*/ + +size_t xStreamBufferSpacesAvailable( StreamBufferHandle_t xStreamBuffer ) +{ + const StreamBuffer_t * const pxStreamBuffer = xStreamBuffer; + size_t xSpace; + + configASSERT( pxStreamBuffer ); + + xSpace = pxStreamBuffer->xLength + pxStreamBuffer->xTail; + xSpace -= pxStreamBuffer->xHead; + xSpace -= ( size_t ) 1; + + if( xSpace >= pxStreamBuffer->xLength ) + { + xSpace -= pxStreamBuffer->xLength; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + return xSpace; +} +/*-----------------------------------------------------------*/ + +size_t xStreamBufferBytesAvailable( StreamBufferHandle_t xStreamBuffer ) +{ + const StreamBuffer_t * const pxStreamBuffer = xStreamBuffer; + size_t xReturn; + + configASSERT( pxStreamBuffer ); + + xReturn = prvBytesInBuffer( pxStreamBuffer ); + return xReturn; +} +/*-----------------------------------------------------------*/ + +size_t xStreamBufferSend( StreamBufferHandle_t xStreamBuffer, + const void * pvTxData, + size_t xDataLengthBytes, + TickType_t xTicksToWait ) +{ + StreamBuffer_t * const pxStreamBuffer = xStreamBuffer; + size_t xReturn, xSpace = 0; + size_t xRequiredSpace = xDataLengthBytes; + TimeOut_t xTimeOut; + + /* Having a 'isFeasible' variable allows to respect the convention that there is only a return statement at the end. Othewise, return + * could be done as soon as we realise the send cannot happen. We will let the call to 'prvWriteMessageToBuffer' dealing with this scenario. */ + BaseType_t xIsFeasible; + + configASSERT( pvTxData ); + configASSERT( pxStreamBuffer ); + + /* This send function is used to write to both message buffers and stream + * buffers. If this is a message buffer then the space needed must be + * increased by the amount of bytes needed to store the length of the + * message. */ + if( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_MESSAGE_BUFFER ) != ( uint8_t ) 0 ) + { + xRequiredSpace += sbBYTES_TO_STORE_MESSAGE_LENGTH; + + /* Overflow? */ + configASSERT( xRequiredSpace > xDataLengthBytes ); + + /* In the case of the message buffer, one has to be able to write the complete message as opposed to + * a stream buffer for semantic reasons. Check if it is physically possible to write the message given + * the length of the buffer. */ + if( xRequiredSpace > pxStreamBuffer->xLength ) + { + /* The message could never be written because it is greater than the buffer length. + * By setting xIsFeasable to FALSE, we skip over the following do..while loop, thus avoiding + * a deadlock. The call to 'prvWriteMessageToBuffer' toward the end of this function with + * xRequiredSpace greater than xSpace will suffice in not writing anything to the internal buffer. + * Now, the function will return 0 because the message could not be written. Should an error code be + * returned instead ??? In my opinion, probably.. But the return type doesn't allow for negative + * values to be returned. A confusion could exist to the caller. Returning 0 because a timeout occurred + * and a subsequent send attempts could eventually succeed, and returning 0 because a write could never + * happen because of the size are two scenarios to me :/ */ + xIsFeasible = pdFALSE; + } + else + { + /* It is possible to write the message completely in the buffer. This is the intended route. + * Let's continue with the regular timeout logic. */ + xIsFeasible = pdTRUE; + } + } + else + { + /* In the case of the stream buffer, not being able to completely write the message in the buffer + * is an acceptable scenario, but it has to be dealt with properly */ + if( xRequiredSpace > pxStreamBuffer->xLength ) + { + /* Not enough buffer space. We will attempt to write as much as we can in this run + * so that the caller can send the remaining in subsequent calls. We avoid a deadlock by + * offering the possibility to take the 'else' branch in the 'if( xSpace < xRequiredSpace )' + * condition inside the following do..while loop */ + xRequiredSpace = pxStreamBuffer->xLength; + + /* TODO FIXME: Is there a check we should do with the xTriggerLevelBytes value ? */ + + /* With the adjustment to 'xRequiredSpace', the deadlock is avoided, thus it's now feasible. */ + xIsFeasible = pdTRUE; + } + else + { + /* It is possible to write the message completely in the buffer. */ + xIsFeasible = pdTRUE; + } + } + + /* Added check against xIsFeasible. If it's not feasible, don't even wait for notification, let the call to 'prvWriteMessageToBuffer' do nothing and return 0 */ + if( ( xTicksToWait != ( TickType_t ) 0 ) && ( xIsFeasible == pdTRUE ) ) + { + vTaskSetTimeOutState( &xTimeOut ); + + do + { + /* Wait until the required number of bytes are free in the message + * buffer. */ + taskENTER_CRITICAL(); + { + xSpace = xStreamBufferSpacesAvailable( pxStreamBuffer ); + + if( xSpace < xRequiredSpace ) + { + /* Clear notification state as going to wait for space. */ + ( void ) xTaskNotifyStateClear( NULL ); + + /* Should only be one writer. */ + configASSERT( pxStreamBuffer->xTaskWaitingToSend == NULL ); + pxStreamBuffer->xTaskWaitingToSend = xTaskGetCurrentTaskHandle(); + } + else + { + taskEXIT_CRITICAL(); + break; + } + } + taskEXIT_CRITICAL(); + + traceBLOCKING_ON_STREAM_BUFFER_SEND( xStreamBuffer ); + ( void ) xTaskNotifyWait( ( uint32_t ) 0, ( uint32_t ) 0, NULL, xTicksToWait ); + pxStreamBuffer->xTaskWaitingToSend = NULL; + } while( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + if( xSpace == ( size_t ) 0 ) + { + xSpace = xStreamBufferSpacesAvailable( pxStreamBuffer ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + xReturn = prvWriteMessageToBuffer( pxStreamBuffer, pvTxData, xDataLengthBytes, xSpace, xRequiredSpace ); + + if( xReturn > ( size_t ) 0 ) + { + traceSTREAM_BUFFER_SEND( xStreamBuffer, xReturn ); + + /* Was a task waiting for the data? */ + if( prvBytesInBuffer( pxStreamBuffer ) >= pxStreamBuffer->xTriggerLevelBytes ) + { + sbSEND_COMPLETED( pxStreamBuffer ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + traceSTREAM_BUFFER_SEND_FAILED( xStreamBuffer ); + } + + return xReturn; +} +/*-----------------------------------------------------------*/ + +size_t xStreamBufferSendFromISR( StreamBufferHandle_t xStreamBuffer, + const void * pvTxData, + size_t xDataLengthBytes, + BaseType_t * const pxHigherPriorityTaskWoken ) +{ + StreamBuffer_t * const pxStreamBuffer = xStreamBuffer; + size_t xReturn, xSpace; + size_t xRequiredSpace = xDataLengthBytes; + + configASSERT( pvTxData ); + configASSERT( pxStreamBuffer ); + + /* This send function is used to write to both message buffers and stream + * buffers. If this is a message buffer then the space needed must be + * increased by the amount of bytes needed to store the length of the + * message. */ + if( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_MESSAGE_BUFFER ) != ( uint8_t ) 0 ) + { + xRequiredSpace += sbBYTES_TO_STORE_MESSAGE_LENGTH; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + xSpace = xStreamBufferSpacesAvailable( pxStreamBuffer ); + xReturn = prvWriteMessageToBuffer( pxStreamBuffer, pvTxData, xDataLengthBytes, xSpace, xRequiredSpace ); + + if( xReturn > ( size_t ) 0 ) + { + /* Was a task waiting for the data? */ + if( prvBytesInBuffer( pxStreamBuffer ) >= pxStreamBuffer->xTriggerLevelBytes ) + { + sbSEND_COMPLETE_FROM_ISR( pxStreamBuffer, pxHigherPriorityTaskWoken ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + traceSTREAM_BUFFER_SEND_FROM_ISR( xStreamBuffer, xReturn ); + + return xReturn; +} +/*-----------------------------------------------------------*/ + +static size_t prvWriteMessageToBuffer( StreamBuffer_t * const pxStreamBuffer, + const void * pvTxData, + size_t xDataLengthBytes, + size_t xSpace, + size_t xRequiredSpace ) +{ + BaseType_t xShouldWrite; + size_t xReturn; + + if( xSpace == ( size_t ) 0 ) + { + /* Doesn't matter if this is a stream buffer or a message buffer, there + * is no space to write. */ + xShouldWrite = pdFALSE; + } + else if( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_MESSAGE_BUFFER ) == ( uint8_t ) 0 ) + { + /* This is a stream buffer, as opposed to a message buffer, so writing a + * stream of bytes rather than discrete messages. Write as many bytes as + * possible. */ + xShouldWrite = pdTRUE; + xDataLengthBytes = configMIN( xDataLengthBytes, xSpace ); + } + else if( xSpace >= xRequiredSpace ) + { + /* This is a message buffer, as opposed to a stream buffer, and there + * is enough space to write both the message length and the message itself + * into the buffer. Start by writing the length of the data, the data + * itself will be written later in this function. */ + xShouldWrite = pdTRUE; + ( void ) prvWriteBytesToBuffer( pxStreamBuffer, ( const uint8_t * ) &( xDataLengthBytes ), sbBYTES_TO_STORE_MESSAGE_LENGTH ); + } + else + { + /* There is space available, but not enough space. */ + xShouldWrite = pdFALSE; + } + + if( xShouldWrite != pdFALSE ) + { + /* Writes the data itself. */ + xReturn = prvWriteBytesToBuffer( pxStreamBuffer, ( const uint8_t * ) pvTxData, xDataLengthBytes ); /*lint !e9079 Storage buffer is implemented as uint8_t for ease of sizing, alignment and access. */ + } + else + { + xReturn = 0; + } + + return xReturn; +} +/*-----------------------------------------------------------*/ + +size_t xStreamBufferReceive( StreamBufferHandle_t xStreamBuffer, + void * pvRxData, + size_t xBufferLengthBytes, + TickType_t xTicksToWait ) +{ + StreamBuffer_t * const pxStreamBuffer = xStreamBuffer; + size_t xReceivedLength = 0, xBytesAvailable, xBytesToStoreMessageLength; + + configASSERT( pvRxData ); + configASSERT( pxStreamBuffer ); + + /* This receive function is used by both message buffers, which store + * discrete messages, and stream buffers, which store a continuous stream of + * bytes. Discrete messages include an additional + * sbBYTES_TO_STORE_MESSAGE_LENGTH bytes that hold the length of the + * message. */ + if( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_MESSAGE_BUFFER ) != ( uint8_t ) 0 ) + { + xBytesToStoreMessageLength = sbBYTES_TO_STORE_MESSAGE_LENGTH; + } + else + { + xBytesToStoreMessageLength = 0; + } + + if( xTicksToWait != ( TickType_t ) 0 ) + { + /* Checking if there is data and clearing the notification state must be + * performed atomically. */ + taskENTER_CRITICAL(); + { + xBytesAvailable = prvBytesInBuffer( pxStreamBuffer ); + + /* If this function was invoked by a message buffer read then + * xBytesToStoreMessageLength holds the number of bytes used to hold + * the length of the next discrete message. If this function was + * invoked by a stream buffer read then xBytesToStoreMessageLength will + * be 0. */ + if( xBytesAvailable <= xBytesToStoreMessageLength ) + { + /* Clear notification state as going to wait for data. */ + ( void ) xTaskNotifyStateClear( NULL ); + + /* Should only be one reader. */ + configASSERT( pxStreamBuffer->xTaskWaitingToReceive == NULL ); + pxStreamBuffer->xTaskWaitingToReceive = xTaskGetCurrentTaskHandle(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + taskEXIT_CRITICAL(); + + if( xBytesAvailable <= xBytesToStoreMessageLength ) + { + /* Wait for data to be available. */ + traceBLOCKING_ON_STREAM_BUFFER_RECEIVE( xStreamBuffer ); + ( void ) xTaskNotifyWait( ( uint32_t ) 0, ( uint32_t ) 0, NULL, xTicksToWait ); + pxStreamBuffer->xTaskWaitingToReceive = NULL; + + /* Recheck the data available after blocking. */ + xBytesAvailable = prvBytesInBuffer( pxStreamBuffer ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + xBytesAvailable = prvBytesInBuffer( pxStreamBuffer ); + } + + /* Whether receiving a discrete message (where xBytesToStoreMessageLength + * holds the number of bytes used to store the message length) or a stream of + * bytes (where xBytesToStoreMessageLength is zero), the number of bytes + * available must be greater than xBytesToStoreMessageLength to be able to + * read bytes from the buffer. */ + if( xBytesAvailable > xBytesToStoreMessageLength ) + { + xReceivedLength = prvReadMessageFromBuffer( pxStreamBuffer, pvRxData, xBufferLengthBytes, xBytesAvailable, xBytesToStoreMessageLength ); + + /* Was a task waiting for space in the buffer? */ + if( xReceivedLength != ( size_t ) 0 ) + { + traceSTREAM_BUFFER_RECEIVE( xStreamBuffer, xReceivedLength ); + sbRECEIVE_COMPLETED( pxStreamBuffer ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + traceSTREAM_BUFFER_RECEIVE_FAILED( xStreamBuffer ); + mtCOVERAGE_TEST_MARKER(); + } + + return xReceivedLength; +} +/*-----------------------------------------------------------*/ + +size_t xStreamBufferNextMessageLengthBytes( StreamBufferHandle_t xStreamBuffer ) +{ + StreamBuffer_t * const pxStreamBuffer = xStreamBuffer; + size_t xReturn, xBytesAvailable, xOriginalTail; + configMESSAGE_BUFFER_LENGTH_TYPE xTempReturn; + + configASSERT( pxStreamBuffer ); + + /* Ensure the stream buffer is being used as a message buffer. */ + if( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_MESSAGE_BUFFER ) != ( uint8_t ) 0 ) + { + xBytesAvailable = prvBytesInBuffer( pxStreamBuffer ); + + if( xBytesAvailable > sbBYTES_TO_STORE_MESSAGE_LENGTH ) + { + /* The number of bytes available is greater than the number of bytes + * required to hold the length of the next message, so another message + * is available. Return its length without removing the length bytes + * from the buffer. A copy of the tail is stored so the buffer can be + * returned to its prior state as the message is not actually being + * removed from the buffer. */ + xOriginalTail = pxStreamBuffer->xTail; + ( void ) prvReadBytesFromBuffer( pxStreamBuffer, ( uint8_t * ) &xTempReturn, sbBYTES_TO_STORE_MESSAGE_LENGTH, xBytesAvailable ); + xReturn = ( size_t ) xTempReturn; + pxStreamBuffer->xTail = xOriginalTail; + } + else + { + /* The minimum amount of bytes in a message buffer is + * ( sbBYTES_TO_STORE_MESSAGE_LENGTH + 1 ), so if xBytesAvailable is + * less than sbBYTES_TO_STORE_MESSAGE_LENGTH the only other valid + * value is 0. */ + configASSERT( xBytesAvailable == 0 ); + xReturn = 0; + } + } + else + { + xReturn = 0; + } + + return xReturn; +} +/*-----------------------------------------------------------*/ + +size_t xStreamBufferReceiveFromISR( StreamBufferHandle_t xStreamBuffer, + void * pvRxData, + size_t xBufferLengthBytes, + BaseType_t * const pxHigherPriorityTaskWoken ) +{ + StreamBuffer_t * const pxStreamBuffer = xStreamBuffer; + size_t xReceivedLength = 0, xBytesAvailable, xBytesToStoreMessageLength; + + configASSERT( pvRxData ); + configASSERT( pxStreamBuffer ); + + /* This receive function is used by both message buffers, which store + * discrete messages, and stream buffers, which store a continuous stream of + * bytes. Discrete messages include an additional + * sbBYTES_TO_STORE_MESSAGE_LENGTH bytes that hold the length of the + * message. */ + if( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_MESSAGE_BUFFER ) != ( uint8_t ) 0 ) + { + xBytesToStoreMessageLength = sbBYTES_TO_STORE_MESSAGE_LENGTH; + } + else + { + xBytesToStoreMessageLength = 0; + } + + xBytesAvailable = prvBytesInBuffer( pxStreamBuffer ); + + /* Whether receiving a discrete message (where xBytesToStoreMessageLength + * holds the number of bytes used to store the message length) or a stream of + * bytes (where xBytesToStoreMessageLength is zero), the number of bytes + * available must be greater than xBytesToStoreMessageLength to be able to + * read bytes from the buffer. */ + if( xBytesAvailable > xBytesToStoreMessageLength ) + { + xReceivedLength = prvReadMessageFromBuffer( pxStreamBuffer, pvRxData, xBufferLengthBytes, xBytesAvailable, xBytesToStoreMessageLength ); + + /* Was a task waiting for space in the buffer? */ + if( xReceivedLength != ( size_t ) 0 ) + { + sbRECEIVE_COMPLETED_FROM_ISR( pxStreamBuffer, pxHigherPriorityTaskWoken ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + traceSTREAM_BUFFER_RECEIVE_FROM_ISR( xStreamBuffer, xReceivedLength ); + + return xReceivedLength; +} +/*-----------------------------------------------------------*/ + +static size_t prvReadMessageFromBuffer( StreamBuffer_t * pxStreamBuffer, + void * pvRxData, + size_t xBufferLengthBytes, + size_t xBytesAvailable, + size_t xBytesToStoreMessageLength ) +{ + size_t xOriginalTail, xReceivedLength, xNextMessageLength; + configMESSAGE_BUFFER_LENGTH_TYPE xTempNextMessageLength; + + if( xBytesToStoreMessageLength != ( size_t ) 0 ) + { + /* A discrete message is being received. First receive the length + * of the message. A copy of the tail is stored so the buffer can be + * returned to its prior state if the length of the message is too + * large for the provided buffer. */ + xOriginalTail = pxStreamBuffer->xTail; + ( void ) prvReadBytesFromBuffer( pxStreamBuffer, ( uint8_t * ) &xTempNextMessageLength, xBytesToStoreMessageLength, xBytesAvailable ); + xNextMessageLength = ( size_t ) xTempNextMessageLength; + + /* Reduce the number of bytes available by the number of bytes just + * read out. */ + xBytesAvailable -= xBytesToStoreMessageLength; + + /* Check there is enough space in the buffer provided by the + * user. */ + if( xNextMessageLength > xBufferLengthBytes ) + { + /* The user has provided insufficient space to read the message + * so return the buffer to its previous state (so the length of + * the message is in the buffer again). */ + pxStreamBuffer->xTail = xOriginalTail; + xNextMessageLength = 0; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + /* A stream of bytes is being received (as opposed to a discrete + * message), so read as many bytes as possible. */ + xNextMessageLength = xBufferLengthBytes; + } + + /* Read the actual data. */ + xReceivedLength = prvReadBytesFromBuffer( pxStreamBuffer, ( uint8_t * ) pvRxData, xNextMessageLength, xBytesAvailable ); /*lint !e9079 Data storage area is implemented as uint8_t array for ease of sizing, indexing and alignment. */ + + return xReceivedLength; +} +/*-----------------------------------------------------------*/ + +BaseType_t xStreamBufferIsEmpty( StreamBufferHandle_t xStreamBuffer ) +{ + const StreamBuffer_t * const pxStreamBuffer = xStreamBuffer; + BaseType_t xReturn; + size_t xTail; + + configASSERT( pxStreamBuffer ); + + /* True if no bytes are available. */ + xTail = pxStreamBuffer->xTail; + + if( pxStreamBuffer->xHead == xTail ) + { + xReturn = pdTRUE; + } + else + { + xReturn = pdFALSE; + } + + return xReturn; +} +/*-----------------------------------------------------------*/ + +BaseType_t xStreamBufferIsFull( StreamBufferHandle_t xStreamBuffer ) +{ + BaseType_t xReturn; + size_t xBytesToStoreMessageLength; + const StreamBuffer_t * const pxStreamBuffer = xStreamBuffer; + + configASSERT( pxStreamBuffer ); + + /* This generic version of the receive function is used by both message + * buffers, which store discrete messages, and stream buffers, which store a + * continuous stream of bytes. Discrete messages include an additional + * sbBYTES_TO_STORE_MESSAGE_LENGTH bytes that hold the length of the message. */ + if( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_MESSAGE_BUFFER ) != ( uint8_t ) 0 ) + { + xBytesToStoreMessageLength = sbBYTES_TO_STORE_MESSAGE_LENGTH; + } + else + { + xBytesToStoreMessageLength = 0; + } + + /* True if the available space equals zero. */ + if( xStreamBufferSpacesAvailable( xStreamBuffer ) <= xBytesToStoreMessageLength ) + { + xReturn = pdTRUE; + } + else + { + xReturn = pdFALSE; + } + + return xReturn; +} +/*-----------------------------------------------------------*/ + +BaseType_t xStreamBufferSendCompletedFromISR( StreamBufferHandle_t xStreamBuffer, + BaseType_t * pxHigherPriorityTaskWoken ) +{ + StreamBuffer_t * const pxStreamBuffer = xStreamBuffer; + BaseType_t xReturn; + UBaseType_t uxSavedInterruptStatus; + + configASSERT( pxStreamBuffer ); + + uxSavedInterruptStatus = ( UBaseType_t ) portSET_INTERRUPT_MASK_FROM_ISR(); + { + if( ( pxStreamBuffer )->xTaskWaitingToReceive != NULL ) + { + ( void ) xTaskNotifyFromISR( ( pxStreamBuffer )->xTaskWaitingToReceive, + ( uint32_t ) 0, + eNoAction, + pxHigherPriorityTaskWoken ); + ( pxStreamBuffer )->xTaskWaitingToReceive = NULL; + xReturn = pdTRUE; + } + else + { + xReturn = pdFALSE; + } + } + portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); + + return xReturn; +} +/*-----------------------------------------------------------*/ + +BaseType_t xStreamBufferReceiveCompletedFromISR( StreamBufferHandle_t xStreamBuffer, + BaseType_t * pxHigherPriorityTaskWoken ) +{ + StreamBuffer_t * const pxStreamBuffer = xStreamBuffer; + BaseType_t xReturn; + UBaseType_t uxSavedInterruptStatus; + + configASSERT( pxStreamBuffer ); + + uxSavedInterruptStatus = ( UBaseType_t ) portSET_INTERRUPT_MASK_FROM_ISR(); + { + if( ( pxStreamBuffer )->xTaskWaitingToSend != NULL ) + { + ( void ) xTaskNotifyFromISR( ( pxStreamBuffer )->xTaskWaitingToSend, + ( uint32_t ) 0, + eNoAction, + pxHigherPriorityTaskWoken ); + ( pxStreamBuffer )->xTaskWaitingToSend = NULL; + xReturn = pdTRUE; + } + else + { + xReturn = pdFALSE; + } + } + portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); + + return xReturn; +} +/*-----------------------------------------------------------*/ + +static size_t prvWriteBytesToBuffer( StreamBuffer_t * const pxStreamBuffer, + const uint8_t * pucData, + size_t xCount ) +{ + size_t xNextHead, xFirstLength; + + configASSERT( xCount > ( size_t ) 0 ); + + xNextHead = pxStreamBuffer->xHead; + + /* Calculate the number of bytes that can be added in the first write - + * which may be less than the total number of bytes that need to be added if + * the buffer will wrap back to the beginning. */ + xFirstLength = configMIN( pxStreamBuffer->xLength - xNextHead, xCount ); + + /* Write as many bytes as can be written in the first write. */ + configASSERT( ( xNextHead + xFirstLength ) <= pxStreamBuffer->xLength ); + ( void ) memcpy( ( void * ) ( &( pxStreamBuffer->pucBuffer[ xNextHead ] ) ), ( const void * ) pucData, xFirstLength ); /*lint !e9087 memcpy() requires void *. */ + + /* If the number of bytes written was less than the number that could be + * written in the first write... */ + if( xCount > xFirstLength ) + { + /* ...then write the remaining bytes to the start of the buffer. */ + configASSERT( ( xCount - xFirstLength ) <= pxStreamBuffer->xLength ); + ( void ) memcpy( ( void * ) pxStreamBuffer->pucBuffer, ( const void * ) &( pucData[ xFirstLength ] ), xCount - xFirstLength ); /*lint !e9087 memcpy() requires void *. */ + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + xNextHead += xCount; + + if( xNextHead >= pxStreamBuffer->xLength ) + { + xNextHead -= pxStreamBuffer->xLength; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + pxStreamBuffer->xHead = xNextHead; + + return xCount; +} +/*-----------------------------------------------------------*/ + +static size_t prvReadBytesFromBuffer( StreamBuffer_t * pxStreamBuffer, + uint8_t * pucData, + size_t xMaxCount, + size_t xBytesAvailable ) +{ + size_t xCount, xFirstLength, xNextTail; + + /* Use the minimum of the wanted bytes and the available bytes. */ + xCount = configMIN( xBytesAvailable, xMaxCount ); + + if( xCount > ( size_t ) 0 ) + { + xNextTail = pxStreamBuffer->xTail; + + /* Calculate the number of bytes that can be read - which may be + * less than the number wanted if the data wraps around to the start of + * the buffer. */ + xFirstLength = configMIN( pxStreamBuffer->xLength - xNextTail, xCount ); + + /* Obtain the number of bytes it is possible to obtain in the first + * read. Asserts check bounds of read and write. */ + configASSERT( xFirstLength <= xMaxCount ); + configASSERT( ( xNextTail + xFirstLength ) <= pxStreamBuffer->xLength ); + ( void ) memcpy( ( void * ) pucData, ( const void * ) &( pxStreamBuffer->pucBuffer[ xNextTail ] ), xFirstLength ); /*lint !e9087 memcpy() requires void *. */ + + /* If the total number of wanted bytes is greater than the number + * that could be read in the first read... */ + if( xCount > xFirstLength ) + { + /*...then read the remaining bytes from the start of the buffer. */ + configASSERT( xCount <= xMaxCount ); + ( void ) memcpy( ( void * ) &( pucData[ xFirstLength ] ), ( void * ) ( pxStreamBuffer->pucBuffer ), xCount - xFirstLength ); /*lint !e9087 memcpy() requires void *. */ + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* Move the tail pointer to effectively remove the data read from + * the buffer. */ + xNextTail += xCount; + + if( xNextTail >= pxStreamBuffer->xLength ) + { + xNextTail -= pxStreamBuffer->xLength; + } + + pxStreamBuffer->xTail = xNextTail; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + return xCount; +} +/*-----------------------------------------------------------*/ + +static size_t prvBytesInBuffer( const StreamBuffer_t * const pxStreamBuffer ) +{ +/* Returns the distance between xTail and xHead. */ + size_t xCount; + + xCount = pxStreamBuffer->xLength + pxStreamBuffer->xHead; + xCount -= pxStreamBuffer->xTail; + + if( xCount >= pxStreamBuffer->xLength ) + { + xCount -= pxStreamBuffer->xLength; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + return xCount; +} +/*-----------------------------------------------------------*/ + +static void prvInitialiseNewStreamBuffer( StreamBuffer_t * const pxStreamBuffer, + uint8_t * const pucBuffer, + size_t xBufferSizeBytes, + size_t xTriggerLevelBytes, + uint8_t ucFlags ) +{ + /* Assert here is deliberately writing to the entire buffer to ensure it can + * be written to without generating exceptions, and is setting the buffer to a + * known value to assist in development/debugging. */ + #if ( configASSERT_DEFINED == 1 ) + { + /* The value written just has to be identifiable when looking at the + * memory. Don't use 0xA5 as that is the stack fill value and could + * result in confusion as to what is actually being observed. */ + const BaseType_t xWriteValue = 0x55; + configASSERT( memset( pucBuffer, ( int ) xWriteValue, xBufferSizeBytes ) == pucBuffer ); + } /*lint !e529 !e438 xWriteValue is only used if configASSERT() is defined. */ + #endif + + ( void ) memset( ( void * ) pxStreamBuffer, 0x00, sizeof( StreamBuffer_t ) ); /*lint !e9087 memset() requires void *. */ + pxStreamBuffer->pucBuffer = pucBuffer; + pxStreamBuffer->xLength = xBufferSizeBytes; + pxStreamBuffer->xTriggerLevelBytes = xTriggerLevelBytes; + pxStreamBuffer->ucFlags = ucFlags; +} + +#if ( configUSE_TRACE_FACILITY == 1 ) + + UBaseType_t uxStreamBufferGetStreamBufferNumber( StreamBufferHandle_t xStreamBuffer ) + { + return xStreamBuffer->uxStreamBufferNumber; + } + +#endif /* configUSE_TRACE_FACILITY */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_TRACE_FACILITY == 1 ) + + void vStreamBufferSetStreamBufferNumber( StreamBufferHandle_t xStreamBuffer, + UBaseType_t uxStreamBufferNumber ) + { + xStreamBuffer->uxStreamBufferNumber = uxStreamBufferNumber; + } + +#endif /* configUSE_TRACE_FACILITY */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_TRACE_FACILITY == 1 ) + + uint8_t ucStreamBufferGetStreamBufferType( StreamBufferHandle_t xStreamBuffer ) + { + return( xStreamBuffer->ucFlags & sbFLAGS_IS_MESSAGE_BUFFER ); + } + +#endif /* configUSE_TRACE_FACILITY */ +/*-----------------------------------------------------------*/ diff --git a/RTOS/FreeRTOS/Source/tasks.c b/RTOS/FreeRTOS/Source/tasks.c new file mode 100644 index 0000000..91c4f37 --- /dev/null +++ b/RTOS/FreeRTOS/Source/tasks.c @@ -0,0 +1,5379 @@ +/* + * FreeRTOS Kernel V10.4.1 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * https://www.FreeRTOS.org + * https://github.com/FreeRTOS + * + */ + +/* Standard includes. */ +#include +#include + +/* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining + * all the API functions to use the MPU wrappers. That should only be done when + * task.h is included from an application file. */ +#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE + +/* FreeRTOS includes. */ +#include "FreeRTOS.h" +#include "task.h" +#include "timers.h" +#include "stack_macros.h" + +/* Lint e9021, e961 and e750 are suppressed as a MISRA exception justified + * because the MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be defined + * for the header files above, but not in this file, in order to generate the + * correct privileged Vs unprivileged linkage and placement. */ +#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE /*lint !e961 !e750 !e9021. */ + +/* Set configUSE_STATS_FORMATTING_FUNCTIONS to 2 to include the stats formatting + * functions but without including stdio.h here. */ +#if ( configUSE_STATS_FORMATTING_FUNCTIONS == 1 ) + +/* At the bottom of this file are two optional functions that can be used + * to generate human readable text from the raw data generated by the + * uxTaskGetSystemState() function. Note the formatting functions are provided + * for convenience only, and are NOT considered part of the kernel. */ + #include +#endif /* configUSE_STATS_FORMATTING_FUNCTIONS == 1 ) */ + +#if ( configUSE_PREEMPTION == 0 ) + +/* If the cooperative scheduler is being used then a yield should not be + * performed just because a higher priority task has been woken. */ + #define taskYIELD_IF_USING_PREEMPTION() +#else + #define taskYIELD_IF_USING_PREEMPTION() portYIELD_WITHIN_API() +#endif + +/* Values that can be assigned to the ucNotifyState member of the TCB. */ +#define taskNOT_WAITING_NOTIFICATION ( ( uint8_t ) 0 ) /* Must be zero as it is the initialised value. */ +#define taskWAITING_NOTIFICATION ( ( uint8_t ) 1 ) +#define taskNOTIFICATION_RECEIVED ( ( uint8_t ) 2 ) + +/* + * The value used to fill the stack of a task when the task is created. This + * is used purely for checking the high water mark for tasks. + */ +#define tskSTACK_FILL_BYTE ( 0xa5U ) + +/* Bits used to recored how a task's stack and TCB were allocated. */ +#define tskDYNAMICALLY_ALLOCATED_STACK_AND_TCB ( ( uint8_t ) 0 ) +#define tskSTATICALLY_ALLOCATED_STACK_ONLY ( ( uint8_t ) 1 ) +#define tskSTATICALLY_ALLOCATED_STACK_AND_TCB ( ( uint8_t ) 2 ) + +/* If any of the following are set then task stacks are filled with a known + * value so the high water mark can be determined. If none of the following are + * set then don't fill the stack so there is no unnecessary dependency on memset. */ +#if ( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) || ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark2 == 1 ) ) + #define tskSET_NEW_STACKS_TO_KNOWN_VALUE 1 +#else + #define tskSET_NEW_STACKS_TO_KNOWN_VALUE 0 +#endif + +/* + * Macros used by vListTask to indicate which state a task is in. + */ +#define tskRUNNING_CHAR ( 'X' ) +#define tskBLOCKED_CHAR ( 'B' ) +#define tskREADY_CHAR ( 'R' ) +#define tskDELETED_CHAR ( 'D' ) +#define tskSUSPENDED_CHAR ( 'S' ) + +/* + * Some kernel aware debuggers require the data the debugger needs access to be + * global, rather than file scope. + */ +#ifdef portREMOVE_STATIC_QUALIFIER + #define static +#endif + +/* The name allocated to the Idle task. This can be overridden by defining + * configIDLE_TASK_NAME in FreeRTOSConfig.h. */ +#ifndef configIDLE_TASK_NAME + #define configIDLE_TASK_NAME "IDLE" +#endif + +#if ( configUSE_PORT_OPTIMISED_TASK_SELECTION == 0 ) + +/* If configUSE_PORT_OPTIMISED_TASK_SELECTION is 0 then task selection is + * performed in a generic way that is not optimised to any particular + * microcontroller architecture. */ + +/* uxTopReadyPriority holds the priority of the highest priority ready + * state task. */ + #define taskRECORD_READY_PRIORITY( uxPriority ) \ + { \ + if( ( uxPriority ) > uxTopReadyPriority ) \ + { \ + uxTopReadyPriority = ( uxPriority ); \ + } \ + } /* taskRECORD_READY_PRIORITY */ + +/*-----------------------------------------------------------*/ + + #define taskSELECT_HIGHEST_PRIORITY_TASK() \ + { \ + UBaseType_t uxTopPriority = uxTopReadyPriority; \ + \ + /* Find the highest priority queue that contains ready tasks. */ \ + while( listLIST_IS_EMPTY( &( pxReadyTasksLists[ uxTopPriority ] ) ) ) \ + { \ + configASSERT( uxTopPriority ); \ + --uxTopPriority; \ + } \ + \ + /* listGET_OWNER_OF_NEXT_ENTRY indexes through the list, so the tasks of \ + * the same priority get an equal share of the processor time. */ \ + listGET_OWNER_OF_NEXT_ENTRY( pxCurrentTCB, &( pxReadyTasksLists[ uxTopPriority ] ) ); \ + uxTopReadyPriority = uxTopPriority; \ + } /* taskSELECT_HIGHEST_PRIORITY_TASK */ + +/*-----------------------------------------------------------*/ + +/* Define away taskRESET_READY_PRIORITY() and portRESET_READY_PRIORITY() as + * they are only required when a port optimised method of task selection is + * being used. */ + #define taskRESET_READY_PRIORITY( uxPriority ) + #define portRESET_READY_PRIORITY( uxPriority, uxTopReadyPriority ) + +#else /* configUSE_PORT_OPTIMISED_TASK_SELECTION */ + +/* If configUSE_PORT_OPTIMISED_TASK_SELECTION is 1 then task selection is + * performed in a way that is tailored to the particular microcontroller + * architecture being used. */ + +/* A port optimised version is provided. Call the port defined macros. */ + #define taskRECORD_READY_PRIORITY( uxPriority ) portRECORD_READY_PRIORITY( uxPriority, uxTopReadyPriority ) + +/*-----------------------------------------------------------*/ + + #define taskSELECT_HIGHEST_PRIORITY_TASK() \ + { \ + UBaseType_t uxTopPriority; \ + \ + /* Find the highest priority list that contains ready tasks. */ \ + portGET_HIGHEST_PRIORITY( uxTopPriority, uxTopReadyPriority ); \ + configASSERT( listCURRENT_LIST_LENGTH( &( pxReadyTasksLists[ uxTopPriority ] ) ) > 0 ); \ + listGET_OWNER_OF_NEXT_ENTRY( pxCurrentTCB, &( pxReadyTasksLists[ uxTopPriority ] ) ); \ + } /* taskSELECT_HIGHEST_PRIORITY_TASK() */ + +/*-----------------------------------------------------------*/ + +/* A port optimised version is provided, call it only if the TCB being reset + * is being referenced from a ready list. If it is referenced from a delayed + * or suspended list then it won't be in a ready list. */ + #define taskRESET_READY_PRIORITY( uxPriority ) \ + { \ + if( listCURRENT_LIST_LENGTH( &( pxReadyTasksLists[ ( uxPriority ) ] ) ) == ( UBaseType_t ) 0 ) \ + { \ + portRESET_READY_PRIORITY( ( uxPriority ), ( uxTopReadyPriority ) ); \ + } \ + } + +#endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */ + +/*-----------------------------------------------------------*/ + +/* pxDelayedTaskList and pxOverflowDelayedTaskList are switched when the tick + * count overflows. */ +#define taskSWITCH_DELAYED_LISTS() \ + { \ + List_t * pxTemp; \ + \ + /* The delayed tasks list should be empty when the lists are switched. */ \ + configASSERT( ( listLIST_IS_EMPTY( pxDelayedTaskList ) ) ); \ + \ + pxTemp = pxDelayedTaskList; \ + pxDelayedTaskList = pxOverflowDelayedTaskList; \ + pxOverflowDelayedTaskList = pxTemp; \ + xNumOfOverflows++; \ + prvResetNextTaskUnblockTime(); \ + } + +/*-----------------------------------------------------------*/ + +/* + * Place the task represented by pxTCB into the appropriate ready list for + * the task. It is inserted at the end of the list. + */ +#define prvAddTaskToReadyList( pxTCB ) \ + traceMOVED_TASK_TO_READY_STATE( pxTCB ); \ + taskRECORD_READY_PRIORITY( ( pxTCB )->uxPriority ); \ + vListInsertEnd( &( pxReadyTasksLists[ ( pxTCB )->uxPriority ] ), &( ( pxTCB )->xStateListItem ) ); \ + tracePOST_MOVED_TASK_TO_READY_STATE( pxTCB ) +/*-----------------------------------------------------------*/ + +/* + * Several functions take an TaskHandle_t parameter that can optionally be NULL, + * where NULL is used to indicate that the handle of the currently executing + * task should be used in place of the parameter. This macro simply checks to + * see if the parameter is NULL and returns a pointer to the appropriate TCB. + */ +#define prvGetTCBFromHandle( pxHandle ) ( ( ( pxHandle ) == NULL ) ? pxCurrentTCB : ( pxHandle ) ) + +/* The item value of the event list item is normally used to hold the priority + * of the task to which it belongs (coded to allow it to be held in reverse + * priority order). However, it is occasionally borrowed for other purposes. It + * is important its value is not updated due to a task priority change while it is + * being used for another purpose. The following bit definition is used to inform + * the scheduler that the value should not be changed - in which case it is the + * responsibility of whichever module is using the value to ensure it gets set back + * to its original value when it is released. */ +#if ( configUSE_16_BIT_TICKS == 1 ) + #define taskEVENT_LIST_ITEM_VALUE_IN_USE 0x8000U +#else + #define taskEVENT_LIST_ITEM_VALUE_IN_USE 0x80000000UL +#endif + +/* + * Task control block. A task control block (TCB) is allocated for each task, + * and stores task state information, including a pointer to the task's context + * (the task's run time environment, including register values) + */ +typedef struct tskTaskControlBlock /* The old naming convention is used to prevent breaking kernel aware debuggers. */ +{ + volatile StackType_t * pxTopOfStack; /*< Points to the location of the last item placed on the tasks stack. THIS MUST BE THE FIRST MEMBER OF THE TCB STRUCT. */ + + #if ( portUSING_MPU_WRAPPERS == 1 ) + xMPU_SETTINGS xMPUSettings; /*< The MPU settings are defined as part of the port layer. THIS MUST BE THE SECOND MEMBER OF THE TCB STRUCT. */ + #endif + + ListItem_t xStateListItem; /*< The list that the state list item of a task is reference from denotes the state of that task (Ready, Blocked, Suspended ). */ + ListItem_t xEventListItem; /*< Used to reference a task from an event list. */ + UBaseType_t uxPriority; /*< The priority of the task. 0 is the lowest priority. */ + StackType_t * pxStack; /*< Points to the start of the stack. */ + char pcTaskName[ configMAX_TASK_NAME_LEN ]; /*< Descriptive name given to the task when created. Facilitates debugging only. */ /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + + #if ( ( portSTACK_GROWTH > 0 ) || ( configRECORD_STACK_HIGH_ADDRESS == 1 ) ) + StackType_t * pxEndOfStack; /*< Points to the highest valid address for the stack. */ + #endif + + #if ( portCRITICAL_NESTING_IN_TCB == 1 ) + UBaseType_t uxCriticalNesting; /*< Holds the critical section nesting depth for ports that do not maintain their own count in the port layer. */ + #endif + + #if ( configUSE_TRACE_FACILITY == 1 ) + UBaseType_t uxTCBNumber; /*< Stores a number that increments each time a TCB is created. It allows debuggers to determine when a task has been deleted and then recreated. */ + UBaseType_t uxTaskNumber; /*< Stores a number specifically for use by third party trace code. */ + #endif + + #if ( configUSE_MUTEXES == 1 ) + UBaseType_t uxBasePriority; /*< The priority last assigned to the task - used by the priority inheritance mechanism. */ + UBaseType_t uxMutexesHeld; + #endif + + #if ( configUSE_APPLICATION_TASK_TAG == 1 ) + TaskHookFunction_t pxTaskTag; + #endif + + #if ( configNUM_THREAD_LOCAL_STORAGE_POINTERS > 0 ) + void * pvThreadLocalStoragePointers[ configNUM_THREAD_LOCAL_STORAGE_POINTERS ]; + #endif + + #if ( configGENERATE_RUN_TIME_STATS == 1 ) + uint32_t ulRunTimeCounter; /*< Stores the amount of time the task has spent in the Running state. */ + #endif + + #if ( configUSE_NEWLIB_REENTRANT == 1 ) + + /* Allocate a Newlib reent structure that is specific to this task. + * Note Newlib support has been included by popular demand, but is not + * used by the FreeRTOS maintainers themselves. FreeRTOS is not + * responsible for resulting newlib operation. User must be familiar with + * newlib and must provide system-wide implementations of the necessary + * stubs. Be warned that (at the time of writing) the current newlib design + * implements a system-wide malloc() that must be provided with locks. + * + * See the third party link http://www.nadler.com/embedded/newlibAndFreeRTOS.html + * for additional information. */ + struct _reent xNewLib_reent; + #endif + + #if ( configUSE_TASK_NOTIFICATIONS == 1 ) + volatile uint32_t ulNotifiedValue[ configTASK_NOTIFICATION_ARRAY_ENTRIES ]; + volatile uint8_t ucNotifyState[ configTASK_NOTIFICATION_ARRAY_ENTRIES ]; + #endif + + /* See the comments in FreeRTOS.h with the definition of + * tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE. */ + #if ( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 ) /*lint !e731 !e9029 Macro has been consolidated for readability reasons. */ + uint8_t ucStaticallyAllocated; /*< Set to pdTRUE if the task is a statically allocated to ensure no attempt is made to free the memory. */ + #endif + + #if ( INCLUDE_xTaskAbortDelay == 1 ) + uint8_t ucDelayAborted; + #endif + + #if ( configUSE_POSIX_ERRNO == 1 ) + int iTaskErrno; + #endif +} tskTCB; + +/* The old tskTCB name is maintained above then typedefed to the new TCB_t name + * below to enable the use of older kernel aware debuggers. */ +typedef tskTCB TCB_t; + +/*lint -save -e956 A manual analysis and inspection has been used to determine + * which static variables must be declared volatile. */ +PRIVILEGED_DATA TCB_t * volatile pxCurrentTCB = NULL; + +/* Lists for ready and blocked tasks. -------------------- + * xDelayedTaskList1 and xDelayedTaskList2 could be move to function scople but + * doing so breaks some kernel aware debuggers and debuggers that rely on removing + * the static qualifier. */ +PRIVILEGED_DATA static List_t pxReadyTasksLists[ configMAX_PRIORITIES ]; /*< Prioritised ready tasks. */ +PRIVILEGED_DATA static List_t xDelayedTaskList1; /*< Delayed tasks. */ +PRIVILEGED_DATA static List_t xDelayedTaskList2; /*< Delayed tasks (two lists are used - one for delays that have overflowed the current tick count. */ +PRIVILEGED_DATA static List_t * volatile pxDelayedTaskList; /*< Points to the delayed task list currently being used. */ +PRIVILEGED_DATA static List_t * volatile pxOverflowDelayedTaskList; /*< Points to the delayed task list currently being used to hold tasks that have overflowed the current tick count. */ +PRIVILEGED_DATA static List_t xPendingReadyList; /*< Tasks that have been readied while the scheduler was suspended. They will be moved to the ready list when the scheduler is resumed. */ + +#if ( INCLUDE_vTaskDelete == 1 ) + + PRIVILEGED_DATA static List_t xTasksWaitingTermination; /*< Tasks that have been deleted - but their memory not yet freed. */ + PRIVILEGED_DATA static volatile UBaseType_t uxDeletedTasksWaitingCleanUp = ( UBaseType_t ) 0U; + +#endif + +#if ( INCLUDE_vTaskSuspend == 1 ) + + PRIVILEGED_DATA static List_t xSuspendedTaskList; /*< Tasks that are currently suspended. */ + +#endif + +/* Global POSIX errno. Its value is changed upon context switching to match + * the errno of the currently running task. */ +#if ( configUSE_POSIX_ERRNO == 1 ) + int FreeRTOS_errno = 0; +#endif + +/* Other file private variables. --------------------------------*/ +PRIVILEGED_DATA static volatile UBaseType_t uxCurrentNumberOfTasks = ( UBaseType_t ) 0U; +PRIVILEGED_DATA static volatile TickType_t xTickCount = ( TickType_t ) configINITIAL_TICK_COUNT; +PRIVILEGED_DATA static volatile UBaseType_t uxTopReadyPriority = tskIDLE_PRIORITY; +PRIVILEGED_DATA static volatile BaseType_t xSchedulerRunning = pdFALSE; +PRIVILEGED_DATA static volatile TickType_t xPendedTicks = ( TickType_t ) 0U; +PRIVILEGED_DATA static volatile BaseType_t xYieldPending = pdFALSE; +PRIVILEGED_DATA static volatile BaseType_t xNumOfOverflows = ( BaseType_t ) 0; +PRIVILEGED_DATA static UBaseType_t uxTaskNumber = ( UBaseType_t ) 0U; +PRIVILEGED_DATA static volatile TickType_t xNextTaskUnblockTime = ( TickType_t ) 0U; /* Initialised to portMAX_DELAY before the scheduler starts. */ +PRIVILEGED_DATA static TaskHandle_t xIdleTaskHandle = NULL; /*< Holds the handle of the idle task. The idle task is created automatically when the scheduler is started. */ + +/* Context switches are held pending while the scheduler is suspended. Also, + * interrupts must not manipulate the xStateListItem of a TCB, or any of the + * lists the xStateListItem can be referenced from, if the scheduler is suspended. + * If an interrupt needs to unblock a task while the scheduler is suspended then it + * moves the task's event list item into the xPendingReadyList, ready for the + * kernel to move the task from the pending ready list into the real ready list + * when the scheduler is unsuspended. The pending ready list itself can only be + * accessed from a critical section. */ +PRIVILEGED_DATA static volatile UBaseType_t uxSchedulerSuspended = ( UBaseType_t ) pdFALSE; + +#if ( configGENERATE_RUN_TIME_STATS == 1 ) + +/* Do not move these variables to function scope as doing so prevents the + * code working with debuggers that need to remove the static qualifier. */ + PRIVILEGED_DATA static uint32_t ulTaskSwitchedInTime = 0UL; /*< Holds the value of a timer/counter the last time a task was switched in. */ + PRIVILEGED_DATA static volatile uint32_t ulTotalRunTime = 0UL; /*< Holds the total amount of execution time as defined by the run time counter clock. */ + +#endif + +/*lint -restore */ + +/*-----------------------------------------------------------*/ + +/* File private functions. --------------------------------*/ + +/** + * Utility task that simply returns pdTRUE if the task referenced by xTask is + * currently in the Suspended state, or pdFALSE if the task referenced by xTask + * is in any other state. + */ +#if ( INCLUDE_vTaskSuspend == 1 ) + + static BaseType_t prvTaskIsTaskSuspended( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION; + +#endif /* INCLUDE_vTaskSuspend */ + +/* + * Utility to ready all the lists used by the scheduler. This is called + * automatically upon the creation of the first task. + */ +static void prvInitialiseTaskLists( void ) PRIVILEGED_FUNCTION; + +/* + * The idle task, which as all tasks is implemented as a never ending loop. + * The idle task is automatically created and added to the ready lists upon + * creation of the first user task. + * + * The portTASK_FUNCTION_PROTO() macro is used to allow port/compiler specific + * language extensions. The equivalent prototype for this function is: + * + * void prvIdleTask( void *pvParameters ); + * + */ +static portTASK_FUNCTION_PROTO( prvIdleTask, pvParameters ) PRIVILEGED_FUNCTION; + +/* + * Utility to free all memory allocated by the scheduler to hold a TCB, + * including the stack pointed to by the TCB. + * + * This does not free memory allocated by the task itself (i.e. memory + * allocated by calls to pvPortMalloc from within the tasks application code). + */ +#if ( INCLUDE_vTaskDelete == 1 ) + + static void prvDeleteTCB( TCB_t * pxTCB ) PRIVILEGED_FUNCTION; + +#endif + +/* + * Used only by the idle task. This checks to see if anything has been placed + * in the list of tasks waiting to be deleted. If so the task is cleaned up + * and its TCB deleted. + */ +static void prvCheckTasksWaitingTermination( void ) PRIVILEGED_FUNCTION; + +/* + * The currently executing task is entering the Blocked state. Add the task to + * either the current or the overflow delayed task list. + */ +static void prvAddCurrentTaskToDelayedList( TickType_t xTicksToWait, + const BaseType_t xCanBlockIndefinitely ) PRIVILEGED_FUNCTION; + +/* + * Fills an TaskStatus_t structure with information on each task that is + * referenced from the pxList list (which may be a ready list, a delayed list, + * a suspended list, etc.). + * + * THIS FUNCTION IS INTENDED FOR DEBUGGING ONLY, AND SHOULD NOT BE CALLED FROM + * NORMAL APPLICATION CODE. + */ +#if ( configUSE_TRACE_FACILITY == 1 ) + + static UBaseType_t prvListTasksWithinSingleList( TaskStatus_t * pxTaskStatusArray, + List_t * pxList, + eTaskState eState ) PRIVILEGED_FUNCTION; + +#endif + +/* + * Searches pxList for a task with name pcNameToQuery - returning a handle to + * the task if it is found, or NULL if the task is not found. + */ +#if ( INCLUDE_xTaskGetHandle == 1 ) + + static TCB_t * prvSearchForNameWithinSingleList( List_t * pxList, + const char pcNameToQuery[] ) PRIVILEGED_FUNCTION; + +#endif + +/* + * When a task is created, the stack of the task is filled with a known value. + * This function determines the 'high water mark' of the task stack by + * determining how much of the stack remains at the original preset value. + */ +#if ( ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark2 == 1 ) ) + + static configSTACK_DEPTH_TYPE prvTaskCheckFreeStackSpace( const uint8_t * pucStackByte ) PRIVILEGED_FUNCTION; + +#endif + +/* + * Return the amount of time, in ticks, that will pass before the kernel will + * next move a task from the Blocked state to the Running state. + * + * This conditional compilation should use inequality to 0, not equality to 1. + * This is to ensure portSUPPRESS_TICKS_AND_SLEEP() can be called when user + * defined low power mode implementations require configUSE_TICKLESS_IDLE to be + * set to a value other than 1. + */ +#if ( configUSE_TICKLESS_IDLE != 0 ) + + static TickType_t prvGetExpectedIdleTime( void ) PRIVILEGED_FUNCTION; + +#endif + +/* + * Set xNextTaskUnblockTime to the time at which the next Blocked state task + * will exit the Blocked state. + */ +static void prvResetNextTaskUnblockTime( void ) PRIVILEGED_FUNCTION; + +#if ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) ) + +/* + * Helper function used to pad task names with spaces when printing out + * human readable tables of task information. + */ + static char * prvWriteNameToBuffer( char * pcBuffer, + const char * pcTaskName ) PRIVILEGED_FUNCTION; + +#endif + +/* + * Called after a Task_t structure has been allocated either statically or + * dynamically to fill in the structure's members. + */ +static void prvInitialiseNewTask( TaskFunction_t pxTaskCode, + const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + const uint32_t ulStackDepth, + void * const pvParameters, + UBaseType_t uxPriority, + TaskHandle_t * const pxCreatedTask, + TCB_t * pxNewTCB, + const MemoryRegion_t * const xRegions ) PRIVILEGED_FUNCTION; + +/* + * Called after a new task has been created and initialised to place the task + * under the control of the scheduler. + */ +static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION; + +/* + * freertos_tasks_c_additions_init() should only be called if the user definable + * macro FREERTOS_TASKS_C_ADDITIONS_INIT() is defined, as that is the only macro + * called by the function. + */ +#ifdef FREERTOS_TASKS_C_ADDITIONS_INIT + + static void freertos_tasks_c_additions_init( void ) PRIVILEGED_FUNCTION; + +#endif + +/*-----------------------------------------------------------*/ + +#if ( configSUPPORT_STATIC_ALLOCATION == 1 ) + + TaskHandle_t xTaskCreateStatic( TaskFunction_t pxTaskCode, + const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + const uint32_t ulStackDepth, + void * const pvParameters, + UBaseType_t uxPriority, + StackType_t * const puxStackBuffer, + StaticTask_t * const pxTaskBuffer ) + { + TCB_t * pxNewTCB; + TaskHandle_t xReturn; + + configASSERT( puxStackBuffer != NULL ); + configASSERT( pxTaskBuffer != NULL ); + + #if ( configASSERT_DEFINED == 1 ) + { + /* Sanity check that the size of the structure used to declare a + * variable of type StaticTask_t equals the size of the real task + * structure. */ + volatile size_t xSize = sizeof( StaticTask_t ); + configASSERT( xSize == sizeof( TCB_t ) ); + ( void ) xSize; /* Prevent lint warning when configASSERT() is not used. */ + } + #endif /* configASSERT_DEFINED */ + + if( ( pxTaskBuffer != NULL ) && ( puxStackBuffer != NULL ) ) + { + /* The memory used for the task's TCB and stack are passed into this + * function - use them. */ + pxNewTCB = ( TCB_t * ) pxTaskBuffer; /*lint !e740 !e9087 Unusual cast is ok as the structures are designed to have the same alignment, and the size is checked by an assert. */ + pxNewTCB->pxStack = ( StackType_t * ) puxStackBuffer; + + #if ( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 ) /*lint !e731 !e9029 Macro has been consolidated for readability reasons. */ + { + /* Tasks can be created statically or dynamically, so note this + * task was created statically in case the task is later deleted. */ + pxNewTCB->ucStaticallyAllocated = tskSTATICALLY_ALLOCATED_STACK_AND_TCB; + } + #endif /* tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE */ + + prvInitialiseNewTask( pxTaskCode, pcName, ulStackDepth, pvParameters, uxPriority, &xReturn, pxNewTCB, NULL ); + prvAddNewTaskToReadyList( pxNewTCB ); + } + else + { + xReturn = NULL; + } + + return xReturn; + } + +#endif /* SUPPORT_STATIC_ALLOCATION */ +/*-----------------------------------------------------------*/ + +#if ( ( portUSING_MPU_WRAPPERS == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) ) + + BaseType_t xTaskCreateRestrictedStatic( const TaskParameters_t * const pxTaskDefinition, + TaskHandle_t * pxCreatedTask ) + { + TCB_t * pxNewTCB; + BaseType_t xReturn = errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY; + + configASSERT( pxTaskDefinition->puxStackBuffer != NULL ); + configASSERT( pxTaskDefinition->pxTaskBuffer != NULL ); + + if( ( pxTaskDefinition->puxStackBuffer != NULL ) && ( pxTaskDefinition->pxTaskBuffer != NULL ) ) + { + /* Allocate space for the TCB. Where the memory comes from depends + * on the implementation of the port malloc function and whether or + * not static allocation is being used. */ + pxNewTCB = ( TCB_t * ) pxTaskDefinition->pxTaskBuffer; + + /* Store the stack location in the TCB. */ + pxNewTCB->pxStack = pxTaskDefinition->puxStackBuffer; + + #if ( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 ) + { + /* Tasks can be created statically or dynamically, so note this + * task was created statically in case the task is later deleted. */ + pxNewTCB->ucStaticallyAllocated = tskSTATICALLY_ALLOCATED_STACK_AND_TCB; + } + #endif /* tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE */ + + prvInitialiseNewTask( pxTaskDefinition->pvTaskCode, + pxTaskDefinition->pcName, + ( uint32_t ) pxTaskDefinition->usStackDepth, + pxTaskDefinition->pvParameters, + pxTaskDefinition->uxPriority, + pxCreatedTask, pxNewTCB, + pxTaskDefinition->xRegions ); + + prvAddNewTaskToReadyList( pxNewTCB ); + xReturn = pdPASS; + } + + return xReturn; + } + +#endif /* ( portUSING_MPU_WRAPPERS == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) */ +/*-----------------------------------------------------------*/ + +#if ( ( portUSING_MPU_WRAPPERS == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) + + BaseType_t xTaskCreateRestricted( const TaskParameters_t * const pxTaskDefinition, + TaskHandle_t * pxCreatedTask ) + { + TCB_t * pxNewTCB; + BaseType_t xReturn = errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY; + + configASSERT( pxTaskDefinition->puxStackBuffer ); + + if( pxTaskDefinition->puxStackBuffer != NULL ) + { + /* Allocate space for the TCB. Where the memory comes from depends + * on the implementation of the port malloc function and whether or + * not static allocation is being used. */ + pxNewTCB = ( TCB_t * ) pvPortMalloc( sizeof( TCB_t ) ); + + if( pxNewTCB != NULL ) + { + /* Store the stack location in the TCB. */ + pxNewTCB->pxStack = pxTaskDefinition->puxStackBuffer; + + #if ( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 ) + { + /* Tasks can be created statically or dynamically, so note + * this task had a statically allocated stack in case it is + * later deleted. The TCB was allocated dynamically. */ + pxNewTCB->ucStaticallyAllocated = tskSTATICALLY_ALLOCATED_STACK_ONLY; + } + #endif /* tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE */ + + prvInitialiseNewTask( pxTaskDefinition->pvTaskCode, + pxTaskDefinition->pcName, + ( uint32_t ) pxTaskDefinition->usStackDepth, + pxTaskDefinition->pvParameters, + pxTaskDefinition->uxPriority, + pxCreatedTask, pxNewTCB, + pxTaskDefinition->xRegions ); + + prvAddNewTaskToReadyList( pxNewTCB ); + xReturn = pdPASS; + } + } + + return xReturn; + } + +#endif /* portUSING_MPU_WRAPPERS */ +/*-----------------------------------------------------------*/ + +#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + + BaseType_t xTaskCreate( TaskFunction_t pxTaskCode, + const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + const configSTACK_DEPTH_TYPE usStackDepth, + void * const pvParameters, + UBaseType_t uxPriority, + TaskHandle_t * const pxCreatedTask ) + { + TCB_t * pxNewTCB; + BaseType_t xReturn; + + /* If the stack grows down then allocate the stack then the TCB so the stack + * does not grow into the TCB. Likewise if the stack grows up then allocate + * the TCB then the stack. */ + #if ( portSTACK_GROWTH > 0 ) + { + /* Allocate space for the TCB. Where the memory comes from depends on + * the implementation of the port malloc function and whether or not static + * allocation is being used. */ + pxNewTCB = ( TCB_t * ) pvPortMalloc( sizeof( TCB_t ) ); + + if( pxNewTCB != NULL ) + { + /* Allocate space for the stack used by the task being created. + * The base of the stack memory stored in the TCB so the task can + * be deleted later if required. */ + pxNewTCB->pxStack = ( StackType_t * ) pvPortMalloc( ( ( ( size_t ) usStackDepth ) * sizeof( StackType_t ) ) ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */ + + if( pxNewTCB->pxStack == NULL ) + { + /* Could not allocate the stack. Delete the allocated TCB. */ + vPortFree( pxNewTCB ); + pxNewTCB = NULL; + } + } + } + #else /* portSTACK_GROWTH */ + { + StackType_t * pxStack; + + /* Allocate space for the stack used by the task being created. */ + pxStack = pvPortMalloc( ( ( ( size_t ) usStackDepth ) * sizeof( StackType_t ) ) ); /*lint !e9079 All values returned by pvPortMalloc() have at least the alignment required by the MCU's stack and this allocation is the stack. */ + + if( pxStack != NULL ) + { + /* Allocate space for the TCB. */ + pxNewTCB = ( TCB_t * ) pvPortMalloc( sizeof( TCB_t ) ); /*lint !e9087 !e9079 All values returned by pvPortMalloc() have at least the alignment required by the MCU's stack, and the first member of TCB_t is always a pointer to the task's stack. */ + + if( pxNewTCB != NULL ) + { + /* Store the stack location in the TCB. */ + pxNewTCB->pxStack = pxStack; + } + else + { + /* The stack cannot be used as the TCB was not created. Free + * it again. */ + vPortFree( pxStack ); + } + } + else + { + pxNewTCB = NULL; + } + } + #endif /* portSTACK_GROWTH */ + + if( pxNewTCB != NULL ) + { + #if ( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 ) /*lint !e9029 !e731 Macro has been consolidated for readability reasons. */ + { + /* Tasks can be created statically or dynamically, so note this + * task was created dynamically in case it is later deleted. */ + pxNewTCB->ucStaticallyAllocated = tskDYNAMICALLY_ALLOCATED_STACK_AND_TCB; + } + #endif /* tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE */ + + prvInitialiseNewTask( pxTaskCode, pcName, ( uint32_t ) usStackDepth, pvParameters, uxPriority, pxCreatedTask, pxNewTCB, NULL ); + prvAddNewTaskToReadyList( pxNewTCB ); + xReturn = pdPASS; + } + else + { + xReturn = errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY; + } + + return xReturn; + } + +#endif /* configSUPPORT_DYNAMIC_ALLOCATION */ +/*-----------------------------------------------------------*/ + +static void prvInitialiseNewTask( TaskFunction_t pxTaskCode, + const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + const uint32_t ulStackDepth, + void * const pvParameters, + UBaseType_t uxPriority, + TaskHandle_t * const pxCreatedTask, + TCB_t * pxNewTCB, + const MemoryRegion_t * const xRegions ) +{ + StackType_t * pxTopOfStack; + UBaseType_t x; + + #if ( portUSING_MPU_WRAPPERS == 1 ) + /* Should the task be created in privileged mode? */ + BaseType_t xRunPrivileged; + + if( ( uxPriority & portPRIVILEGE_BIT ) != 0U ) + { + xRunPrivileged = pdTRUE; + } + else + { + xRunPrivileged = pdFALSE; + } + uxPriority &= ~portPRIVILEGE_BIT; + #endif /* portUSING_MPU_WRAPPERS == 1 */ + + /* Avoid dependency on memset() if it is not required. */ + #if ( tskSET_NEW_STACKS_TO_KNOWN_VALUE == 1 ) + { + /* Fill the stack with a known value to assist debugging. */ + ( void ) memset( pxNewTCB->pxStack, ( int ) tskSTACK_FILL_BYTE, ( size_t ) ulStackDepth * sizeof( StackType_t ) ); + } + #endif /* tskSET_NEW_STACKS_TO_KNOWN_VALUE */ + + /* Calculate the top of stack address. This depends on whether the stack + * grows from high memory to low (as per the 80x86) or vice versa. + * portSTACK_GROWTH is used to make the result positive or negative as required + * by the port. */ + #if ( portSTACK_GROWTH < 0 ) + { + pxTopOfStack = &( pxNewTCB->pxStack[ ulStackDepth - ( uint32_t ) 1 ] ); + pxTopOfStack = ( StackType_t * ) ( ( ( portPOINTER_SIZE_TYPE ) pxTopOfStack ) & ( ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) ) ); /*lint !e923 !e9033 !e9078 MISRA exception. Avoiding casts between pointers and integers is not practical. Size differences accounted for using portPOINTER_SIZE_TYPE type. Checked by assert(). */ + + /* Check the alignment of the calculated top of stack is correct. */ + configASSERT( ( ( ( portPOINTER_SIZE_TYPE ) pxTopOfStack & ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) == 0UL ) ); + + #if ( configRECORD_STACK_HIGH_ADDRESS == 1 ) + { + /* Also record the stack's high address, which may assist + * debugging. */ + pxNewTCB->pxEndOfStack = pxTopOfStack; + } + #endif /* configRECORD_STACK_HIGH_ADDRESS */ + } + #else /* portSTACK_GROWTH */ + { + pxTopOfStack = pxNewTCB->pxStack; + + /* Check the alignment of the stack buffer is correct. */ + configASSERT( ( ( ( portPOINTER_SIZE_TYPE ) pxNewTCB->pxStack & ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) == 0UL ) ); + + /* The other extreme of the stack space is required if stack checking is + * performed. */ + pxNewTCB->pxEndOfStack = pxNewTCB->pxStack + ( ulStackDepth - ( uint32_t ) 1 ); + } + #endif /* portSTACK_GROWTH */ + + /* Store the task name in the TCB. */ + if( pcName != NULL ) + { + for( x = ( UBaseType_t ) 0; x < ( UBaseType_t ) configMAX_TASK_NAME_LEN; x++ ) + { + pxNewTCB->pcTaskName[ x ] = pcName[ x ]; + + /* Don't copy all configMAX_TASK_NAME_LEN if the string is shorter than + * configMAX_TASK_NAME_LEN characters just in case the memory after the + * string is not accessible (extremely unlikely). */ + if( pcName[ x ] == ( char ) 0x00 ) + { + break; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + + /* Ensure the name string is terminated in the case that the string length + * was greater or equal to configMAX_TASK_NAME_LEN. */ + pxNewTCB->pcTaskName[ configMAX_TASK_NAME_LEN - 1 ] = '\0'; + } + else + { + /* The task has not been given a name, so just ensure there is a NULL + * terminator when it is read out. */ + pxNewTCB->pcTaskName[ 0 ] = 0x00; + } + + /* This is used as an array index so must ensure it's not too large. First + * remove the privilege bit if one is present. */ + if( uxPriority >= ( UBaseType_t ) configMAX_PRIORITIES ) + { + uxPriority = ( UBaseType_t ) configMAX_PRIORITIES - ( UBaseType_t ) 1U; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + pxNewTCB->uxPriority = uxPriority; + #if ( configUSE_MUTEXES == 1 ) + { + pxNewTCB->uxBasePriority = uxPriority; + pxNewTCB->uxMutexesHeld = 0; + } + #endif /* configUSE_MUTEXES */ + + vListInitialiseItem( &( pxNewTCB->xStateListItem ) ); + vListInitialiseItem( &( pxNewTCB->xEventListItem ) ); + + /* Set the pxNewTCB as a link back from the ListItem_t. This is so we can get + * back to the containing TCB from a generic item in a list. */ + listSET_LIST_ITEM_OWNER( &( pxNewTCB->xStateListItem ), pxNewTCB ); + + /* Event lists are always in priority order. */ + listSET_LIST_ITEM_VALUE( &( pxNewTCB->xEventListItem ), ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) uxPriority ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */ + listSET_LIST_ITEM_OWNER( &( pxNewTCB->xEventListItem ), pxNewTCB ); + + #if ( portCRITICAL_NESTING_IN_TCB == 1 ) + { + pxNewTCB->uxCriticalNesting = ( UBaseType_t ) 0U; + } + #endif /* portCRITICAL_NESTING_IN_TCB */ + + #if ( configUSE_APPLICATION_TASK_TAG == 1 ) + { + pxNewTCB->pxTaskTag = NULL; + } + #endif /* configUSE_APPLICATION_TASK_TAG */ + + #if ( configGENERATE_RUN_TIME_STATS == 1 ) + { + pxNewTCB->ulRunTimeCounter = 0UL; + } + #endif /* configGENERATE_RUN_TIME_STATS */ + + #if ( portUSING_MPU_WRAPPERS == 1 ) + { + vPortStoreTaskMPUSettings( &( pxNewTCB->xMPUSettings ), xRegions, pxNewTCB->pxStack, ulStackDepth ); + } + #else + { + /* Avoid compiler warning about unreferenced parameter. */ + ( void ) xRegions; + } + #endif + + #if ( configNUM_THREAD_LOCAL_STORAGE_POINTERS != 0 ) + { + memset( ( void * ) &( pxNewTCB->pvThreadLocalStoragePointers[ 0 ] ), 0x00, sizeof( pxNewTCB->pvThreadLocalStoragePointers ) ); + } + #endif + + #if ( configUSE_TASK_NOTIFICATIONS == 1 ) + { + memset( ( void * ) &( pxNewTCB->ulNotifiedValue[ 0 ] ), 0x00, sizeof( pxNewTCB->ulNotifiedValue ) ); + memset( ( void * ) &( pxNewTCB->ucNotifyState[ 0 ] ), 0x00, sizeof( pxNewTCB->ucNotifyState ) ); + } + #endif + + #if ( configUSE_NEWLIB_REENTRANT == 1 ) + { + /* Initialise this task's Newlib reent structure. + * See the third party link http://www.nadler.com/embedded/newlibAndFreeRTOS.html + * for additional information. */ + _REENT_INIT_PTR( ( &( pxNewTCB->xNewLib_reent ) ) ); + } + #endif + + #if ( INCLUDE_xTaskAbortDelay == 1 ) + { + pxNewTCB->ucDelayAborted = pdFALSE; + } + #endif + + /* Initialize the TCB stack to look as if the task was already running, + * but had been interrupted by the scheduler. The return address is set + * to the start of the task function. Once the stack has been initialised + * the top of stack variable is updated. */ + #if ( portUSING_MPU_WRAPPERS == 1 ) + { + /* If the port has capability to detect stack overflow, + * pass the stack end address to the stack initialization + * function as well. */ + #if ( portHAS_STACK_OVERFLOW_CHECKING == 1 ) + { + #if ( portSTACK_GROWTH < 0 ) + { + pxNewTCB->pxTopOfStack = pxPortInitialiseStack( pxTopOfStack, pxNewTCB->pxStack, pxTaskCode, pvParameters, xRunPrivileged ); + } + #else /* portSTACK_GROWTH */ + { + pxNewTCB->pxTopOfStack = pxPortInitialiseStack( pxTopOfStack, pxNewTCB->pxEndOfStack, pxTaskCode, pvParameters, xRunPrivileged ); + } + #endif /* portSTACK_GROWTH */ + } + #else /* portHAS_STACK_OVERFLOW_CHECKING */ + { + pxNewTCB->pxTopOfStack = pxPortInitialiseStack( pxTopOfStack, pxTaskCode, pvParameters, xRunPrivileged ); + } + #endif /* portHAS_STACK_OVERFLOW_CHECKING */ + } + #else /* portUSING_MPU_WRAPPERS */ + { + /* If the port has capability to detect stack overflow, + * pass the stack end address to the stack initialization + * function as well. */ + #if ( portHAS_STACK_OVERFLOW_CHECKING == 1 ) + { + #if ( portSTACK_GROWTH < 0 ) + { + pxNewTCB->pxTopOfStack = pxPortInitialiseStack( pxTopOfStack, pxNewTCB->pxStack, pxTaskCode, pvParameters ); + } + #else /* portSTACK_GROWTH */ + { + pxNewTCB->pxTopOfStack = pxPortInitialiseStack( pxTopOfStack, pxNewTCB->pxEndOfStack, pxTaskCode, pvParameters ); + } + #endif /* portSTACK_GROWTH */ + } + #else /* portHAS_STACK_OVERFLOW_CHECKING */ + { + pxNewTCB->pxTopOfStack = pxPortInitialiseStack( pxTopOfStack, pxTaskCode, pvParameters ); + } + #endif /* portHAS_STACK_OVERFLOW_CHECKING */ + } + #endif /* portUSING_MPU_WRAPPERS */ + + if( pxCreatedTask != NULL ) + { + /* Pass the handle out in an anonymous way. The handle can be used to + * change the created task's priority, delete the created task, etc.*/ + *pxCreatedTask = ( TaskHandle_t ) pxNewTCB; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } +} +/*-----------------------------------------------------------*/ + +static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) +{ + /* Ensure interrupts don't access the task lists while the lists are being + * updated. */ + taskENTER_CRITICAL(); + { + uxCurrentNumberOfTasks++; + + if( pxCurrentTCB == NULL ) + { + /* There are no other tasks, or all the other tasks are in + * the suspended state - make this the current task. */ + pxCurrentTCB = pxNewTCB; + + if( uxCurrentNumberOfTasks == ( UBaseType_t ) 1 ) + { + /* This is the first task to be created so do the preliminary + * initialisation required. We will not recover if this call + * fails, but we will report the failure. */ + prvInitialiseTaskLists(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + /* If the scheduler is not already running, make this task the + * current task if it is the highest priority task to be created + * so far. */ + if( xSchedulerRunning == pdFALSE ) + { + if( pxCurrentTCB->uxPriority <= pxNewTCB->uxPriority ) + { + pxCurrentTCB = pxNewTCB; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + + uxTaskNumber++; + + #if ( configUSE_TRACE_FACILITY == 1 ) + { + /* Add a counter into the TCB for tracing only. */ + pxNewTCB->uxTCBNumber = uxTaskNumber; + } + #endif /* configUSE_TRACE_FACILITY */ + traceTASK_CREATE( pxNewTCB ); + + prvAddTaskToReadyList( pxNewTCB ); + + portSETUP_TCB( pxNewTCB ); + } + taskEXIT_CRITICAL(); + + if( xSchedulerRunning != pdFALSE ) + { + /* If the created task is of a higher priority than the current task + * then it should run now. */ + if( pxCurrentTCB->uxPriority < pxNewTCB->uxPriority ) + { + taskYIELD_IF_USING_PREEMPTION(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } +} +/*-----------------------------------------------------------*/ + +#if ( INCLUDE_vTaskDelete == 1 ) + + void vTaskDelete( TaskHandle_t xTaskToDelete ) + { + TCB_t * pxTCB; + + taskENTER_CRITICAL(); + { + /* If null is passed in here then it is the calling task that is + * being deleted. */ + pxTCB = prvGetTCBFromHandle( xTaskToDelete ); + + /* Remove task from the ready/delayed list. */ + if( uxListRemove( &( pxTCB->xStateListItem ) ) == ( UBaseType_t ) 0 ) + { + taskRESET_READY_PRIORITY( pxTCB->uxPriority ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* Is the task waiting on an event also? */ + if( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) != NULL ) + { + ( void ) uxListRemove( &( pxTCB->xEventListItem ) ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* Increment the uxTaskNumber also so kernel aware debuggers can + * detect that the task lists need re-generating. This is done before + * portPRE_TASK_DELETE_HOOK() as in the Windows port that macro will + * not return. */ + uxTaskNumber++; + + if( pxTCB == pxCurrentTCB ) + { + /* A task is deleting itself. This cannot complete within the + * task itself, as a context switch to another task is required. + * Place the task in the termination list. The idle task will + * check the termination list and free up any memory allocated by + * the scheduler for the TCB and stack of the deleted task. */ + vListInsertEnd( &xTasksWaitingTermination, &( pxTCB->xStateListItem ) ); + + /* Increment the ucTasksDeleted variable so the idle task knows + * there is a task that has been deleted and that it should therefore + * check the xTasksWaitingTermination list. */ + ++uxDeletedTasksWaitingCleanUp; + + /* Call the delete hook before portPRE_TASK_DELETE_HOOK() as + * portPRE_TASK_DELETE_HOOK() does not return in the Win32 port. */ + traceTASK_DELETE( pxTCB ); + + /* The pre-delete hook is primarily for the Windows simulator, + * in which Windows specific clean up operations are performed, + * after which it is not possible to yield away from this task - + * hence xYieldPending is used to latch that a context switch is + * required. */ + portPRE_TASK_DELETE_HOOK( pxTCB, &xYieldPending ); + } + else + { + --uxCurrentNumberOfTasks; + traceTASK_DELETE( pxTCB ); + prvDeleteTCB( pxTCB ); + + /* Reset the next expected unblock time in case it referred to + * the task that has just been deleted. */ + prvResetNextTaskUnblockTime(); + } + } + taskEXIT_CRITICAL(); + + /* Force a reschedule if it is the currently running task that has just + * been deleted. */ + if( xSchedulerRunning != pdFALSE ) + { + if( pxTCB == pxCurrentTCB ) + { + configASSERT( uxSchedulerSuspended == 0 ); + portYIELD_WITHIN_API(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + } + +#endif /* INCLUDE_vTaskDelete */ +/*-----------------------------------------------------------*/ + +#if ( INCLUDE_vTaskDelayUntil == 1 ) + + void vTaskDelayUntil( TickType_t * const pxPreviousWakeTime, + const TickType_t xTimeIncrement ) + { + TickType_t xTimeToWake; + BaseType_t xAlreadyYielded, xShouldDelay = pdFALSE; + + configASSERT( pxPreviousWakeTime ); + configASSERT( ( xTimeIncrement > 0U ) ); + configASSERT( uxSchedulerSuspended == 0 ); + + vTaskSuspendAll(); + { + /* Minor optimisation. The tick count cannot change in this + * block. */ + const TickType_t xConstTickCount = xTickCount; + + /* Generate the tick time at which the task wants to wake. */ + xTimeToWake = *pxPreviousWakeTime + xTimeIncrement; + + if( xConstTickCount < *pxPreviousWakeTime ) + { + /* The tick count has overflowed since this function was + * lasted called. In this case the only time we should ever + * actually delay is if the wake time has also overflowed, + * and the wake time is greater than the tick time. When this + * is the case it is as if neither time had overflowed. */ + if( ( xTimeToWake < *pxPreviousWakeTime ) && ( xTimeToWake > xConstTickCount ) ) + { + xShouldDelay = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + /* The tick time has not overflowed. In this case we will + * delay if either the wake time has overflowed, and/or the + * tick time is less than the wake time. */ + if( ( xTimeToWake < *pxPreviousWakeTime ) || ( xTimeToWake > xConstTickCount ) ) + { + xShouldDelay = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + + /* Update the wake time ready for the next call. */ + *pxPreviousWakeTime = xTimeToWake; + + if( xShouldDelay != pdFALSE ) + { + traceTASK_DELAY_UNTIL( xTimeToWake ); + + /* prvAddCurrentTaskToDelayedList() needs the block time, not + * the time to wake, so subtract the current tick count. */ + prvAddCurrentTaskToDelayedList( xTimeToWake - xConstTickCount, pdFALSE ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + xAlreadyYielded = xTaskResumeAll(); + + /* Force a reschedule if xTaskResumeAll has not already done so, we may + * have put ourselves to sleep. */ + if( xAlreadyYielded == pdFALSE ) + { + portYIELD_WITHIN_API(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + +#endif /* INCLUDE_vTaskDelayUntil */ +/*-----------------------------------------------------------*/ + +#if ( INCLUDE_vTaskDelay == 1 ) + + void vTaskDelay( const TickType_t xTicksToDelay ) + { + BaseType_t xAlreadyYielded = pdFALSE; + + /* A delay time of zero just forces a reschedule. */ + if( xTicksToDelay > ( TickType_t ) 0U ) + { + configASSERT( uxSchedulerSuspended == 0 ); + vTaskSuspendAll(); + { + traceTASK_DELAY(); + + /* A task that is removed from the event list while the + * scheduler is suspended will not get placed in the ready + * list or removed from the blocked list until the scheduler + * is resumed. + * + * This task cannot be in an event list as it is the currently + * executing task. */ + prvAddCurrentTaskToDelayedList( xTicksToDelay, pdFALSE ); + } + xAlreadyYielded = xTaskResumeAll(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* Force a reschedule if xTaskResumeAll has not already done so, we may + * have put ourselves to sleep. */ + if( xAlreadyYielded == pdFALSE ) + { + portYIELD_WITHIN_API(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + +#endif /* INCLUDE_vTaskDelay */ +/*-----------------------------------------------------------*/ + +#if ( ( INCLUDE_eTaskGetState == 1 ) || ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_xTaskAbortDelay == 1 ) ) + + eTaskState eTaskGetState( TaskHandle_t xTask ) + { + eTaskState eReturn; + List_t const * pxStateList, * pxDelayedList, * pxOverflowedDelayedList; + const TCB_t * const pxTCB = xTask; + + configASSERT( pxTCB ); + + if( pxTCB == pxCurrentTCB ) + { + /* The task calling this function is querying its own state. */ + eReturn = eRunning; + } + else + { + taskENTER_CRITICAL(); + { + pxStateList = listLIST_ITEM_CONTAINER( &( pxTCB->xStateListItem ) ); + pxDelayedList = pxDelayedTaskList; + pxOverflowedDelayedList = pxOverflowDelayedTaskList; + } + taskEXIT_CRITICAL(); + + if( ( pxStateList == pxDelayedList ) || ( pxStateList == pxOverflowedDelayedList ) ) + { + /* The task being queried is referenced from one of the Blocked + * lists. */ + eReturn = eBlocked; + } + + #if ( INCLUDE_vTaskSuspend == 1 ) + else if( pxStateList == &xSuspendedTaskList ) + { + /* The task being queried is referenced from the suspended + * list. Is it genuinely suspended or is it blocked + * indefinitely? */ + if( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) == NULL ) + { + #if ( configUSE_TASK_NOTIFICATIONS == 1 ) + { + BaseType_t x; + + /* The task does not appear on the event list item of + * and of the RTOS objects, but could still be in the + * blocked state if it is waiting on its notification + * rather than waiting on an object. If not, is + * suspended. */ + eReturn = eSuspended; + + for( x = 0; x < configTASK_NOTIFICATION_ARRAY_ENTRIES; x++ ) + { + if( pxTCB->ucNotifyState[ x ] == taskWAITING_NOTIFICATION ) + { + eReturn = eBlocked; + break; + } + } + } + #else /* if ( configUSE_TASK_NOTIFICATIONS == 1 ) */ + { + eReturn = eSuspended; + } + #endif /* if ( configUSE_TASK_NOTIFICATIONS == 1 ) */ + } + else + { + eReturn = eBlocked; + } + } + #endif /* if ( INCLUDE_vTaskSuspend == 1 ) */ + + #if ( INCLUDE_vTaskDelete == 1 ) + else if( ( pxStateList == &xTasksWaitingTermination ) || ( pxStateList == NULL ) ) + { + /* The task being queried is referenced from the deleted + * tasks list, or it is not referenced from any lists at + * all. */ + eReturn = eDeleted; + } + #endif + + else /*lint !e525 Negative indentation is intended to make use of pre-processor clearer. */ + { + /* If the task is not in any other state, it must be in the + * Ready (including pending ready) state. */ + eReturn = eReady; + } + } + + return eReturn; + } /*lint !e818 xTask cannot be a pointer to const because it is a typedef. */ + +#endif /* INCLUDE_eTaskGetState */ +/*-----------------------------------------------------------*/ + +#if ( INCLUDE_uxTaskPriorityGet == 1 ) + + UBaseType_t uxTaskPriorityGet( const TaskHandle_t xTask ) + { + TCB_t const * pxTCB; + UBaseType_t uxReturn; + + taskENTER_CRITICAL(); + { + /* If null is passed in here then it is the priority of the task + * that called uxTaskPriorityGet() that is being queried. */ + pxTCB = prvGetTCBFromHandle( xTask ); + uxReturn = pxTCB->uxPriority; + } + taskEXIT_CRITICAL(); + + return uxReturn; + } + +#endif /* INCLUDE_uxTaskPriorityGet */ +/*-----------------------------------------------------------*/ + +#if ( INCLUDE_uxTaskPriorityGet == 1 ) + + UBaseType_t uxTaskPriorityGetFromISR( const TaskHandle_t xTask ) + { + TCB_t const * pxTCB; + UBaseType_t uxReturn, uxSavedInterruptState; + + /* RTOS ports that support interrupt nesting have the concept of a + * maximum system call (or maximum API call) interrupt priority. + * Interrupts that are above the maximum system call priority are keep + * permanently enabled, even when the RTOS kernel is in a critical section, + * but cannot make any calls to FreeRTOS API functions. If configASSERT() + * is defined in FreeRTOSConfig.h then + * portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion + * failure if a FreeRTOS API function is called from an interrupt that has + * been assigned a priority above the configured maximum system call + * priority. Only FreeRTOS functions that end in FromISR can be called + * from interrupts that have been assigned a priority at or (logically) + * below the maximum system call interrupt priority. FreeRTOS maintains a + * separate interrupt safe API to ensure interrupt entry is as fast and as + * simple as possible. More information (albeit Cortex-M specific) is + * provided on the following link: + * https://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html */ + portASSERT_IF_INTERRUPT_PRIORITY_INVALID(); + + uxSavedInterruptState = portSET_INTERRUPT_MASK_FROM_ISR(); + { + /* If null is passed in here then it is the priority of the calling + * task that is being queried. */ + pxTCB = prvGetTCBFromHandle( xTask ); + uxReturn = pxTCB->uxPriority; + } + portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptState ); + + return uxReturn; + } + +#endif /* INCLUDE_uxTaskPriorityGet */ +/*-----------------------------------------------------------*/ + +#if ( INCLUDE_vTaskPrioritySet == 1 ) + + void vTaskPrioritySet( TaskHandle_t xTask, + UBaseType_t uxNewPriority ) + { + TCB_t * pxTCB; + UBaseType_t uxCurrentBasePriority, uxPriorityUsedOnEntry; + BaseType_t xYieldRequired = pdFALSE; + + configASSERT( ( uxNewPriority < configMAX_PRIORITIES ) ); + + /* Ensure the new priority is valid. */ + if( uxNewPriority >= ( UBaseType_t ) configMAX_PRIORITIES ) + { + uxNewPriority = ( UBaseType_t ) configMAX_PRIORITIES - ( UBaseType_t ) 1U; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + taskENTER_CRITICAL(); + { + /* If null is passed in here then it is the priority of the calling + * task that is being changed. */ + pxTCB = prvGetTCBFromHandle( xTask ); + + traceTASK_PRIORITY_SET( pxTCB, uxNewPriority ); + + #if ( configUSE_MUTEXES == 1 ) + { + uxCurrentBasePriority = pxTCB->uxBasePriority; + } + #else + { + uxCurrentBasePriority = pxTCB->uxPriority; + } + #endif + + if( uxCurrentBasePriority != uxNewPriority ) + { + /* The priority change may have readied a task of higher + * priority than the calling task. */ + if( uxNewPriority > uxCurrentBasePriority ) + { + if( pxTCB != pxCurrentTCB ) + { + /* The priority of a task other than the currently + * running task is being raised. Is the priority being + * raised above that of the running task? */ + if( uxNewPriority >= pxCurrentTCB->uxPriority ) + { + xYieldRequired = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + /* The priority of the running task is being raised, + * but the running task must already be the highest + * priority task able to run so no yield is required. */ + } + } + else if( pxTCB == pxCurrentTCB ) + { + /* Setting the priority of the running task down means + * there may now be another task of higher priority that + * is ready to execute. */ + xYieldRequired = pdTRUE; + } + else + { + /* Setting the priority of any other task down does not + * require a yield as the running task must be above the + * new priority of the task being modified. */ + } + + /* Remember the ready list the task might be referenced from + * before its uxPriority member is changed so the + * taskRESET_READY_PRIORITY() macro can function correctly. */ + uxPriorityUsedOnEntry = pxTCB->uxPriority; + + #if ( configUSE_MUTEXES == 1 ) + { + /* Only change the priority being used if the task is not + * currently using an inherited priority. */ + if( pxTCB->uxBasePriority == pxTCB->uxPriority ) + { + pxTCB->uxPriority = uxNewPriority; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* The base priority gets set whatever. */ + pxTCB->uxBasePriority = uxNewPriority; + } + #else /* if ( configUSE_MUTEXES == 1 ) */ + { + pxTCB->uxPriority = uxNewPriority; + } + #endif /* if ( configUSE_MUTEXES == 1 ) */ + + /* Only reset the event list item value if the value is not + * being used for anything else. */ + if( ( listGET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ) ) & taskEVENT_LIST_ITEM_VALUE_IN_USE ) == 0UL ) + { + listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) uxNewPriority ) ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */ + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* If the task is in the blocked or suspended list we need do + * nothing more than change its priority variable. However, if + * the task is in a ready list it needs to be removed and placed + * in the list appropriate to its new priority. */ + if( listIS_CONTAINED_WITHIN( &( pxReadyTasksLists[ uxPriorityUsedOnEntry ] ), &( pxTCB->xStateListItem ) ) != pdFALSE ) + { + /* The task is currently in its ready list - remove before + * adding it to it's new ready list. As we are in a critical + * section we can do this even if the scheduler is suspended. */ + if( uxListRemove( &( pxTCB->xStateListItem ) ) == ( UBaseType_t ) 0 ) + { + /* It is known that the task is in its ready list so + * there is no need to check again and the port level + * reset macro can be called directly. */ + portRESET_READY_PRIORITY( uxPriorityUsedOnEntry, uxTopReadyPriority ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + prvAddTaskToReadyList( pxTCB ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + if( xYieldRequired != pdFALSE ) + { + taskYIELD_IF_USING_PREEMPTION(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* Remove compiler warning about unused variables when the port + * optimised task selection is not being used. */ + ( void ) uxPriorityUsedOnEntry; + } + } + taskEXIT_CRITICAL(); + } + +#endif /* INCLUDE_vTaskPrioritySet */ +/*-----------------------------------------------------------*/ + +#if ( INCLUDE_vTaskSuspend == 1 ) + + void vTaskSuspend( TaskHandle_t xTaskToSuspend ) + { + TCB_t * pxTCB; + + taskENTER_CRITICAL(); + { + /* If null is passed in here then it is the running task that is + * being suspended. */ + pxTCB = prvGetTCBFromHandle( xTaskToSuspend ); + + traceTASK_SUSPEND( pxTCB ); + + /* Remove task from the ready/delayed list and place in the + * suspended list. */ + if( uxListRemove( &( pxTCB->xStateListItem ) ) == ( UBaseType_t ) 0 ) + { + taskRESET_READY_PRIORITY( pxTCB->uxPriority ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* Is the task waiting on an event also? */ + if( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) != NULL ) + { + ( void ) uxListRemove( &( pxTCB->xEventListItem ) ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + vListInsertEnd( &xSuspendedTaskList, &( pxTCB->xStateListItem ) ); + + #if ( configUSE_TASK_NOTIFICATIONS == 1 ) + { + BaseType_t x; + + for( x = 0; x < configTASK_NOTIFICATION_ARRAY_ENTRIES; x++ ) + { + if( pxTCB->ucNotifyState[ x ] == taskWAITING_NOTIFICATION ) + { + /* The task was blocked to wait for a notification, but is + * now suspended, so no notification was received. */ + pxTCB->ucNotifyState[ x ] = taskNOT_WAITING_NOTIFICATION; + } + } + } + #endif /* if ( configUSE_TASK_NOTIFICATIONS == 1 ) */ + } + taskEXIT_CRITICAL(); + + if( xSchedulerRunning != pdFALSE ) + { + /* Reset the next expected unblock time in case it referred to the + * task that is now in the Suspended state. */ + taskENTER_CRITICAL(); + { + prvResetNextTaskUnblockTime(); + } + taskEXIT_CRITICAL(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + if( pxTCB == pxCurrentTCB ) + { + if( xSchedulerRunning != pdFALSE ) + { + /* The current task has just been suspended. */ + configASSERT( uxSchedulerSuspended == 0 ); + portYIELD_WITHIN_API(); + } + else + { + /* The scheduler is not running, but the task that was pointed + * to by pxCurrentTCB has just been suspended and pxCurrentTCB + * must be adjusted to point to a different task. */ + if( listCURRENT_LIST_LENGTH( &xSuspendedTaskList ) == uxCurrentNumberOfTasks ) /*lint !e931 Right has no side effect, just volatile. */ + { + /* No other tasks are ready, so set pxCurrentTCB back to + * NULL so when the next task is created pxCurrentTCB will + * be set to point to it no matter what its relative priority + * is. */ + pxCurrentTCB = NULL; + } + else + { + vTaskSwitchContext(); + } + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + +#endif /* INCLUDE_vTaskSuspend */ +/*-----------------------------------------------------------*/ + +#if ( INCLUDE_vTaskSuspend == 1 ) + + static BaseType_t prvTaskIsTaskSuspended( const TaskHandle_t xTask ) + { + BaseType_t xReturn = pdFALSE; + const TCB_t * const pxTCB = xTask; + + /* Accesses xPendingReadyList so must be called from a critical + * section. */ + + /* It does not make sense to check if the calling task is suspended. */ + configASSERT( xTask ); + + /* Is the task being resumed actually in the suspended list? */ + if( listIS_CONTAINED_WITHIN( &xSuspendedTaskList, &( pxTCB->xStateListItem ) ) != pdFALSE ) + { + /* Has the task already been resumed from within an ISR? */ + if( listIS_CONTAINED_WITHIN( &xPendingReadyList, &( pxTCB->xEventListItem ) ) == pdFALSE ) + { + /* Is it in the suspended list because it is in the Suspended + * state, or because is is blocked with no timeout? */ + if( listIS_CONTAINED_WITHIN( NULL, &( pxTCB->xEventListItem ) ) != pdFALSE ) /*lint !e961. The cast is only redundant when NULL is used. */ + { + xReturn = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + return xReturn; + } /*lint !e818 xTask cannot be a pointer to const because it is a typedef. */ + +#endif /* INCLUDE_vTaskSuspend */ +/*-----------------------------------------------------------*/ + +#if ( INCLUDE_vTaskSuspend == 1 ) + + void vTaskResume( TaskHandle_t xTaskToResume ) + { + TCB_t * const pxTCB = xTaskToResume; + + /* It does not make sense to resume the calling task. */ + configASSERT( xTaskToResume ); + + /* The parameter cannot be NULL as it is impossible to resume the + * currently executing task. */ + if( ( pxTCB != pxCurrentTCB ) && ( pxTCB != NULL ) ) + { + taskENTER_CRITICAL(); + { + if( prvTaskIsTaskSuspended( pxTCB ) != pdFALSE ) + { + traceTASK_RESUME( pxTCB ); + + /* The ready list can be accessed even if the scheduler is + * suspended because this is inside a critical section. */ + ( void ) uxListRemove( &( pxTCB->xStateListItem ) ); + prvAddTaskToReadyList( pxTCB ); + + /* A higher priority task may have just been resumed. */ + if( pxTCB->uxPriority >= pxCurrentTCB->uxPriority ) + { + /* This yield may not cause the task just resumed to run, + * but will leave the lists in the correct state for the + * next yield. */ + taskYIELD_IF_USING_PREEMPTION(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + taskEXIT_CRITICAL(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + +#endif /* INCLUDE_vTaskSuspend */ + +/*-----------------------------------------------------------*/ + +#if ( ( INCLUDE_xTaskResumeFromISR == 1 ) && ( INCLUDE_vTaskSuspend == 1 ) ) + + BaseType_t xTaskResumeFromISR( TaskHandle_t xTaskToResume ) + { + BaseType_t xYieldRequired = pdFALSE; + TCB_t * const pxTCB = xTaskToResume; + UBaseType_t uxSavedInterruptStatus; + + configASSERT( xTaskToResume ); + + /* RTOS ports that support interrupt nesting have the concept of a + * maximum system call (or maximum API call) interrupt priority. + * Interrupts that are above the maximum system call priority are keep + * permanently enabled, even when the RTOS kernel is in a critical section, + * but cannot make any calls to FreeRTOS API functions. If configASSERT() + * is defined in FreeRTOSConfig.h then + * portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion + * failure if a FreeRTOS API function is called from an interrupt that has + * been assigned a priority above the configured maximum system call + * priority. Only FreeRTOS functions that end in FromISR can be called + * from interrupts that have been assigned a priority at or (logically) + * below the maximum system call interrupt priority. FreeRTOS maintains a + * separate interrupt safe API to ensure interrupt entry is as fast and as + * simple as possible. More information (albeit Cortex-M specific) is + * provided on the following link: + * https://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html */ + portASSERT_IF_INTERRUPT_PRIORITY_INVALID(); + + uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR(); + { + if( prvTaskIsTaskSuspended( pxTCB ) != pdFALSE ) + { + traceTASK_RESUME_FROM_ISR( pxTCB ); + + /* Check the ready lists can be accessed. */ + if( uxSchedulerSuspended == ( UBaseType_t ) pdFALSE ) + { + /* Ready lists can be accessed so move the task from the + * suspended list to the ready list directly. */ + if( pxTCB->uxPriority >= pxCurrentTCB->uxPriority ) + { + xYieldRequired = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + ( void ) uxListRemove( &( pxTCB->xStateListItem ) ); + prvAddTaskToReadyList( pxTCB ); + } + else + { + /* The delayed or ready lists cannot be accessed so the task + * is held in the pending ready list until the scheduler is + * unsuspended. */ + vListInsertEnd( &( xPendingReadyList ), &( pxTCB->xEventListItem ) ); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); + + return xYieldRequired; + } + +#endif /* ( ( INCLUDE_xTaskResumeFromISR == 1 ) && ( INCLUDE_vTaskSuspend == 1 ) ) */ +/*-----------------------------------------------------------*/ + +void vTaskStartScheduler( void ) +{ + BaseType_t xReturn; + + /* Add the idle task at the lowest priority. */ + #if ( configSUPPORT_STATIC_ALLOCATION == 1 ) + { + StaticTask_t * pxIdleTaskTCBBuffer = NULL; + StackType_t * pxIdleTaskStackBuffer = NULL; + uint32_t ulIdleTaskStackSize; + + /* The Idle task is created using user provided RAM - obtain the + * address of the RAM then create the idle task. */ + vApplicationGetIdleTaskMemory( &pxIdleTaskTCBBuffer, &pxIdleTaskStackBuffer, &ulIdleTaskStackSize ); + xIdleTaskHandle = xTaskCreateStatic( prvIdleTask, + configIDLE_TASK_NAME, + ulIdleTaskStackSize, + ( void * ) NULL, /*lint !e961. The cast is not redundant for all compilers. */ + portPRIVILEGE_BIT, /* In effect ( tskIDLE_PRIORITY | portPRIVILEGE_BIT ), but tskIDLE_PRIORITY is zero. */ + pxIdleTaskStackBuffer, + pxIdleTaskTCBBuffer ); /*lint !e961 MISRA exception, justified as it is not a redundant explicit cast to all supported compilers. */ + + if( xIdleTaskHandle != NULL ) + { + xReturn = pdPASS; + } + else + { + xReturn = pdFAIL; + } + } + #else /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */ + { + /* The Idle task is being created using dynamically allocated RAM. */ + xReturn = xTaskCreate( prvIdleTask, + configIDLE_TASK_NAME, + configMINIMAL_STACK_SIZE, + ( void * ) NULL, + portPRIVILEGE_BIT, /* In effect ( tskIDLE_PRIORITY | portPRIVILEGE_BIT ), but tskIDLE_PRIORITY is zero. */ + &xIdleTaskHandle ); /*lint !e961 MISRA exception, justified as it is not a redundant explicit cast to all supported compilers. */ + } + #endif /* configSUPPORT_STATIC_ALLOCATION */ + + #if ( configUSE_TIMERS == 1 ) + { + if( xReturn == pdPASS ) + { + xReturn = xTimerCreateTimerTask(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + #endif /* configUSE_TIMERS */ + + if( xReturn == pdPASS ) + { + /* freertos_tasks_c_additions_init() should only be called if the user + * definable macro FREERTOS_TASKS_C_ADDITIONS_INIT() is defined, as that is + * the only macro called by the function. */ + #ifdef FREERTOS_TASKS_C_ADDITIONS_INIT + { + freertos_tasks_c_additions_init(); + } + #endif + + /* Interrupts are turned off here, to ensure a tick does not occur + * before or during the call to xPortStartScheduler(). The stacks of + * the created tasks contain a status word with interrupts switched on + * so interrupts will automatically get re-enabled when the first task + * starts to run. */ + portDISABLE_INTERRUPTS(); + + #if ( configUSE_NEWLIB_REENTRANT == 1 ) + { + /* Switch Newlib's _impure_ptr variable to point to the _reent + * structure specific to the task that will run first. + * See the third party link http://www.nadler.com/embedded/newlibAndFreeRTOS.html + * for additional information. */ + _impure_ptr = &( pxCurrentTCB->xNewLib_reent ); + } + #endif /* configUSE_NEWLIB_REENTRANT */ + + xNextTaskUnblockTime = portMAX_DELAY; + xSchedulerRunning = pdTRUE; + xTickCount = ( TickType_t ) configINITIAL_TICK_COUNT; + + /* If configGENERATE_RUN_TIME_STATS is defined then the following + * macro must be defined to configure the timer/counter used to generate + * the run time counter time base. NOTE: If configGENERATE_RUN_TIME_STATS + * is set to 0 and the following line fails to build then ensure you do not + * have portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() defined in your + * FreeRTOSConfig.h file. */ + portCONFIGURE_TIMER_FOR_RUN_TIME_STATS(); + + traceTASK_SWITCHED_IN(); + + /* Setting up the timer tick is hardware specific and thus in the + * portable interface. */ + if( xPortStartScheduler() != pdFALSE ) + { + /* Should not reach here as if the scheduler is running the + * function will not return. */ + } + else + { + /* Should only reach here if a task calls xTaskEndScheduler(). */ + } + } + else + { + /* This line will only be reached if the kernel could not be started, + * because there was not enough FreeRTOS heap to create the idle task + * or the timer task. */ + configASSERT( xReturn != errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY ); + } + + /* Prevent compiler warnings if INCLUDE_xTaskGetIdleTaskHandle is set to 0, + * meaning xIdleTaskHandle is not used anywhere else. */ + ( void ) xIdleTaskHandle; +} +/*-----------------------------------------------------------*/ + +void vTaskEndScheduler( void ) +{ + /* Stop the scheduler interrupts and call the portable scheduler end + * routine so the original ISRs can be restored if necessary. The port + * layer must ensure interrupts enable bit is left in the correct state. */ + portDISABLE_INTERRUPTS(); + xSchedulerRunning = pdFALSE; + vPortEndScheduler(); +} +/*----------------------------------------------------------*/ + +void vTaskSuspendAll( void ) +{ + /* A critical section is not required as the variable is of type + * BaseType_t. Please read Richard Barry's reply in the following link to a + * post in the FreeRTOS support forum before reporting this as a bug! - + * http://goo.gl/wu4acr */ + + /* portSOFRWARE_BARRIER() is only implemented for emulated/simulated ports that + * do not otherwise exhibit real time behaviour. */ + portSOFTWARE_BARRIER(); + + /* The scheduler is suspended if uxSchedulerSuspended is non-zero. An increment + * is used to allow calls to vTaskSuspendAll() to nest. */ + ++uxSchedulerSuspended; + + /* Enforces ordering for ports and optimised compilers that may otherwise place + * the above increment elsewhere. */ + portMEMORY_BARRIER(); +} +/*----------------------------------------------------------*/ + +#if ( configUSE_TICKLESS_IDLE != 0 ) + + static TickType_t prvGetExpectedIdleTime( void ) + { + TickType_t xReturn; + UBaseType_t uxHigherPriorityReadyTasks = pdFALSE; + + /* uxHigherPriorityReadyTasks takes care of the case where + * configUSE_PREEMPTION is 0, so there may be tasks above the idle priority + * task that are in the Ready state, even though the idle task is + * running. */ + #if ( configUSE_PORT_OPTIMISED_TASK_SELECTION == 0 ) + { + if( uxTopReadyPriority > tskIDLE_PRIORITY ) + { + uxHigherPriorityReadyTasks = pdTRUE; + } + } + #else + { + const UBaseType_t uxLeastSignificantBit = ( UBaseType_t ) 0x01; + + /* When port optimised task selection is used the uxTopReadyPriority + * variable is used as a bit map. If bits other than the least + * significant bit are set then there are tasks that have a priority + * above the idle priority that are in the Ready state. This takes + * care of the case where the co-operative scheduler is in use. */ + if( uxTopReadyPriority > uxLeastSignificantBit ) + { + uxHigherPriorityReadyTasks = pdTRUE; + } + } + #endif /* if ( configUSE_PORT_OPTIMISED_TASK_SELECTION == 0 ) */ + + if( pxCurrentTCB->uxPriority > tskIDLE_PRIORITY ) + { + xReturn = 0; + } + else if( listCURRENT_LIST_LENGTH( &( pxReadyTasksLists[ tskIDLE_PRIORITY ] ) ) > 1 ) + { + /* There are other idle priority tasks in the ready state. If + * time slicing is used then the very next tick interrupt must be + * processed. */ + xReturn = 0; + } + else if( uxHigherPriorityReadyTasks != pdFALSE ) + { + /* There are tasks in the Ready state that have a priority above the + * idle priority. This path can only be reached if + * configUSE_PREEMPTION is 0. */ + xReturn = 0; + } + else + { + xReturn = xNextTaskUnblockTime - xTickCount; + } + + return xReturn; + } + +#endif /* configUSE_TICKLESS_IDLE */ +/*----------------------------------------------------------*/ + +BaseType_t xTaskResumeAll( void ) +{ + TCB_t * pxTCB = NULL; + BaseType_t xAlreadyYielded = pdFALSE; + + /* If uxSchedulerSuspended is zero then this function does not match a + * previous call to vTaskSuspendAll(). */ + configASSERT( uxSchedulerSuspended ); + + /* It is possible that an ISR caused a task to be removed from an event + * list while the scheduler was suspended. If this was the case then the + * removed task will have been added to the xPendingReadyList. Once the + * scheduler has been resumed it is safe to move all the pending ready + * tasks from this list into their appropriate ready list. */ + taskENTER_CRITICAL(); + { + --uxSchedulerSuspended; + + if( uxSchedulerSuspended == ( UBaseType_t ) pdFALSE ) + { + if( uxCurrentNumberOfTasks > ( UBaseType_t ) 0U ) + { + /* Move any readied tasks from the pending list into the + * appropriate ready list. */ + while( listLIST_IS_EMPTY( &xPendingReadyList ) == pdFALSE ) + { + pxTCB = listGET_OWNER_OF_HEAD_ENTRY( ( &xPendingReadyList ) ); /*lint !e9079 void * is used as this macro is used with timers and co-routines too. Alignment is known to be fine as the type of the pointer stored and retrieved is the same. */ + ( void ) uxListRemove( &( pxTCB->xEventListItem ) ); + ( void ) uxListRemove( &( pxTCB->xStateListItem ) ); + prvAddTaskToReadyList( pxTCB ); + + /* If the moved task has a priority higher than the current + * task then a yield must be performed. */ + if( pxTCB->uxPriority >= pxCurrentTCB->uxPriority ) + { + xYieldPending = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + + if( pxTCB != NULL ) + { + /* A task was unblocked while the scheduler was suspended, + * which may have prevented the next unblock time from being + * re-calculated, in which case re-calculate it now. Mainly + * important for low power tickless implementations, where + * this can prevent an unnecessary exit from low power + * state. */ + prvResetNextTaskUnblockTime(); + } + + /* If any ticks occurred while the scheduler was suspended then + * they should be processed now. This ensures the tick count does + * not slip, and that any delayed tasks are resumed at the correct + * time. */ + { + TickType_t xPendedCounts = xPendedTicks; /* Non-volatile copy. */ + + if( xPendedCounts > ( TickType_t ) 0U ) + { + do + { + if( xTaskIncrementTick() != pdFALSE ) + { + xYieldPending = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + --xPendedCounts; + } while( xPendedCounts > ( TickType_t ) 0U ); + + xPendedTicks = 0; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + + if( xYieldPending != pdFALSE ) + { + #if ( configUSE_PREEMPTION != 0 ) + { + xAlreadyYielded = pdTRUE; + } + #endif + taskYIELD_IF_USING_PREEMPTION(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + taskEXIT_CRITICAL(); + + return xAlreadyYielded; +} +/*-----------------------------------------------------------*/ + +TickType_t xTaskGetTickCount( void ) +{ + TickType_t xTicks; + + /* Critical section required if running on a 16 bit processor. */ + portTICK_TYPE_ENTER_CRITICAL(); + { + xTicks = xTickCount; + } + portTICK_TYPE_EXIT_CRITICAL(); + + return xTicks; +} +/*-----------------------------------------------------------*/ + +TickType_t xTaskGetTickCountFromISR( void ) +{ + TickType_t xReturn; + UBaseType_t uxSavedInterruptStatus; + + /* RTOS ports that support interrupt nesting have the concept of a maximum + * system call (or maximum API call) interrupt priority. Interrupts that are + * above the maximum system call priority are kept permanently enabled, even + * when the RTOS kernel is in a critical section, but cannot make any calls to + * FreeRTOS API functions. If configASSERT() is defined in FreeRTOSConfig.h + * then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion + * failure if a FreeRTOS API function is called from an interrupt that has been + * assigned a priority above the configured maximum system call priority. + * Only FreeRTOS functions that end in FromISR can be called from interrupts + * that have been assigned a priority at or (logically) below the maximum + * system call interrupt priority. FreeRTOS maintains a separate interrupt + * safe API to ensure interrupt entry is as fast and as simple as possible. + * More information (albeit Cortex-M specific) is provided on the following + * link: https://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html */ + portASSERT_IF_INTERRUPT_PRIORITY_INVALID(); + + uxSavedInterruptStatus = portTICK_TYPE_SET_INTERRUPT_MASK_FROM_ISR(); + { + xReturn = xTickCount; + } + portTICK_TYPE_CLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); + + return xReturn; +} +/*-----------------------------------------------------------*/ + +UBaseType_t uxTaskGetNumberOfTasks( void ) +{ + /* A critical section is not required because the variables are of type + * BaseType_t. */ + return uxCurrentNumberOfTasks; +} +/*-----------------------------------------------------------*/ + +char * pcTaskGetName( TaskHandle_t xTaskToQuery ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ +{ + TCB_t * pxTCB; + + /* If null is passed in here then the name of the calling task is being + * queried. */ + pxTCB = prvGetTCBFromHandle( xTaskToQuery ); + configASSERT( pxTCB ); + return &( pxTCB->pcTaskName[ 0 ] ); +} +/*-----------------------------------------------------------*/ + +#if ( INCLUDE_xTaskGetHandle == 1 ) + + static TCB_t * prvSearchForNameWithinSingleList( List_t * pxList, + const char pcNameToQuery[] ) + { + TCB_t * pxNextTCB, * pxFirstTCB, * pxReturn = NULL; + UBaseType_t x; + char cNextChar; + BaseType_t xBreakLoop; + + /* This function is called with the scheduler suspended. */ + + if( listCURRENT_LIST_LENGTH( pxList ) > ( UBaseType_t ) 0 ) + { + listGET_OWNER_OF_NEXT_ENTRY( pxFirstTCB, pxList ); /*lint !e9079 void * is used as this macro is used with timers and co-routines too. Alignment is known to be fine as the type of the pointer stored and retrieved is the same. */ + + do + { + listGET_OWNER_OF_NEXT_ENTRY( pxNextTCB, pxList ); /*lint !e9079 void * is used as this macro is used with timers and co-routines too. Alignment is known to be fine as the type of the pointer stored and retrieved is the same. */ + + /* Check each character in the name looking for a match or + * mismatch. */ + xBreakLoop = pdFALSE; + + for( x = ( UBaseType_t ) 0; x < ( UBaseType_t ) configMAX_TASK_NAME_LEN; x++ ) + { + cNextChar = pxNextTCB->pcTaskName[ x ]; + + if( cNextChar != pcNameToQuery[ x ] ) + { + /* Characters didn't match. */ + xBreakLoop = pdTRUE; + } + else if( cNextChar == ( char ) 0x00 ) + { + /* Both strings terminated, a match must have been + * found. */ + pxReturn = pxNextTCB; + xBreakLoop = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + if( xBreakLoop != pdFALSE ) + { + break; + } + } + + if( pxReturn != NULL ) + { + /* The handle has been found. */ + break; + } + } while( pxNextTCB != pxFirstTCB ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + return pxReturn; + } + +#endif /* INCLUDE_xTaskGetHandle */ +/*-----------------------------------------------------------*/ + +#if ( INCLUDE_xTaskGetHandle == 1 ) + + TaskHandle_t xTaskGetHandle( const char * pcNameToQuery ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + { + UBaseType_t uxQueue = configMAX_PRIORITIES; + TCB_t * pxTCB; + + /* Task names will be truncated to configMAX_TASK_NAME_LEN - 1 bytes. */ + configASSERT( strlen( pcNameToQuery ) < configMAX_TASK_NAME_LEN ); + + vTaskSuspendAll(); + { + /* Search the ready lists. */ + do + { + uxQueue--; + pxTCB = prvSearchForNameWithinSingleList( ( List_t * ) &( pxReadyTasksLists[ uxQueue ] ), pcNameToQuery ); + + if( pxTCB != NULL ) + { + /* Found the handle. */ + break; + } + } while( uxQueue > ( UBaseType_t ) tskIDLE_PRIORITY ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */ + + /* Search the delayed lists. */ + if( pxTCB == NULL ) + { + pxTCB = prvSearchForNameWithinSingleList( ( List_t * ) pxDelayedTaskList, pcNameToQuery ); + } + + if( pxTCB == NULL ) + { + pxTCB = prvSearchForNameWithinSingleList( ( List_t * ) pxOverflowDelayedTaskList, pcNameToQuery ); + } + + #if ( INCLUDE_vTaskSuspend == 1 ) + { + if( pxTCB == NULL ) + { + /* Search the suspended list. */ + pxTCB = prvSearchForNameWithinSingleList( &xSuspendedTaskList, pcNameToQuery ); + } + } + #endif + + #if ( INCLUDE_vTaskDelete == 1 ) + { + if( pxTCB == NULL ) + { + /* Search the deleted list. */ + pxTCB = prvSearchForNameWithinSingleList( &xTasksWaitingTermination, pcNameToQuery ); + } + } + #endif + } + ( void ) xTaskResumeAll(); + + return pxTCB; + } + +#endif /* INCLUDE_xTaskGetHandle */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_TRACE_FACILITY == 1 ) + + UBaseType_t uxTaskGetSystemState( TaskStatus_t * const pxTaskStatusArray, + const UBaseType_t uxArraySize, + uint32_t * const pulTotalRunTime ) + { + UBaseType_t uxTask = 0, uxQueue = configMAX_PRIORITIES; + + vTaskSuspendAll(); + { + /* Is there a space in the array for each task in the system? */ + if( uxArraySize >= uxCurrentNumberOfTasks ) + { + /* Fill in an TaskStatus_t structure with information on each + * task in the Ready state. */ + do + { + uxQueue--; + uxTask += prvListTasksWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), &( pxReadyTasksLists[ uxQueue ] ), eReady ); + } while( uxQueue > ( UBaseType_t ) tskIDLE_PRIORITY ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */ + + /* Fill in an TaskStatus_t structure with information on each + * task in the Blocked state. */ + uxTask += prvListTasksWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), ( List_t * ) pxDelayedTaskList, eBlocked ); + uxTask += prvListTasksWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), ( List_t * ) pxOverflowDelayedTaskList, eBlocked ); + + #if ( INCLUDE_vTaskDelete == 1 ) + { + /* Fill in an TaskStatus_t structure with information on + * each task that has been deleted but not yet cleaned up. */ + uxTask += prvListTasksWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), &xTasksWaitingTermination, eDeleted ); + } + #endif + + #if ( INCLUDE_vTaskSuspend == 1 ) + { + /* Fill in an TaskStatus_t structure with information on + * each task in the Suspended state. */ + uxTask += prvListTasksWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), &xSuspendedTaskList, eSuspended ); + } + #endif + + #if ( configGENERATE_RUN_TIME_STATS == 1 ) + { + if( pulTotalRunTime != NULL ) + { + #ifdef portALT_GET_RUN_TIME_COUNTER_VALUE + portALT_GET_RUN_TIME_COUNTER_VALUE( ( *pulTotalRunTime ) ); + #else + *pulTotalRunTime = portGET_RUN_TIME_COUNTER_VALUE(); + #endif + } + } + #else /* if ( configGENERATE_RUN_TIME_STATS == 1 ) */ + { + if( pulTotalRunTime != NULL ) + { + *pulTotalRunTime = 0; + } + } + #endif /* if ( configGENERATE_RUN_TIME_STATS == 1 ) */ + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + ( void ) xTaskResumeAll(); + + return uxTask; + } + +#endif /* configUSE_TRACE_FACILITY */ +/*----------------------------------------------------------*/ + +#if ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) + + TaskHandle_t xTaskGetIdleTaskHandle( void ) + { + /* If xTaskGetIdleTaskHandle() is called before the scheduler has been + * started, then xIdleTaskHandle will be NULL. */ + configASSERT( ( xIdleTaskHandle != NULL ) ); + return xIdleTaskHandle; + } + +#endif /* INCLUDE_xTaskGetIdleTaskHandle */ +/*----------------------------------------------------------*/ + +/* This conditional compilation should use inequality to 0, not equality to 1. + * This is to ensure vTaskStepTick() is available when user defined low power mode + * implementations require configUSE_TICKLESS_IDLE to be set to a value other than + * 1. */ +#if ( configUSE_TICKLESS_IDLE != 0 ) + + void vTaskStepTick( const TickType_t xTicksToJump ) + { + /* Correct the tick count value after a period during which the tick + * was suppressed. Note this does *not* call the tick hook function for + * each stepped tick. */ + configASSERT( ( xTickCount + xTicksToJump ) <= xNextTaskUnblockTime ); + xTickCount += xTicksToJump; + traceINCREASE_TICK_COUNT( xTicksToJump ); + } + +#endif /* configUSE_TICKLESS_IDLE */ +/*----------------------------------------------------------*/ + +BaseType_t xTaskCatchUpTicks( TickType_t xTicksToCatchUp ) +{ + BaseType_t xYieldOccurred; + + /* Must not be called with the scheduler suspended as the implementation + * relies on xPendedTicks being wound down to 0 in xTaskResumeAll(). */ + configASSERT( uxSchedulerSuspended == 0 ); + + /* Use xPendedTicks to mimic xTicksToCatchUp number of ticks occurring when + * the scheduler is suspended so the ticks are executed in xTaskResumeAll(). */ + vTaskSuspendAll(); + xPendedTicks += xTicksToCatchUp; + xYieldOccurred = xTaskResumeAll(); + + return xYieldOccurred; +} +/*----------------------------------------------------------*/ + +#if ( INCLUDE_xTaskAbortDelay == 1 ) + + BaseType_t xTaskAbortDelay( TaskHandle_t xTask ) + { + TCB_t * pxTCB = xTask; + BaseType_t xReturn; + + configASSERT( pxTCB ); + + vTaskSuspendAll(); + { + /* A task can only be prematurely removed from the Blocked state if + * it is actually in the Blocked state. */ + if( eTaskGetState( xTask ) == eBlocked ) + { + xReturn = pdPASS; + + /* Remove the reference to the task from the blocked list. An + * interrupt won't touch the xStateListItem because the + * scheduler is suspended. */ + ( void ) uxListRemove( &( pxTCB->xStateListItem ) ); + + /* Is the task waiting on an event also? If so remove it from + * the event list too. Interrupts can touch the event list item, + * even though the scheduler is suspended, so a critical section + * is used. */ + taskENTER_CRITICAL(); + { + if( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) != NULL ) + { + ( void ) uxListRemove( &( pxTCB->xEventListItem ) ); + + /* This lets the task know it was forcibly removed from the + * blocked state so it should not re-evaluate its block time and + * then block again. */ + pxTCB->ucDelayAborted = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + taskEXIT_CRITICAL(); + + /* Place the unblocked task into the appropriate ready list. */ + prvAddTaskToReadyList( pxTCB ); + + /* A task being unblocked cannot cause an immediate context + * switch if preemption is turned off. */ + #if ( configUSE_PREEMPTION == 1 ) + { + /* Preemption is on, but a context switch should only be + * performed if the unblocked task has a priority that is + * equal to or higher than the currently executing task. */ + if( pxTCB->uxPriority > pxCurrentTCB->uxPriority ) + { + /* Pend the yield to be performed when the scheduler + * is unsuspended. */ + xYieldPending = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + #endif /* configUSE_PREEMPTION */ + } + else + { + xReturn = pdFAIL; + } + } + ( void ) xTaskResumeAll(); + + return xReturn; + } + +#endif /* INCLUDE_xTaskAbortDelay */ +/*----------------------------------------------------------*/ + +BaseType_t xTaskIncrementTick( void ) +{ + TCB_t * pxTCB; + TickType_t xItemValue; + BaseType_t xSwitchRequired = pdFALSE; + + /* Called by the portable layer each time a tick interrupt occurs. + * Increments the tick then checks to see if the new tick value will cause any + * tasks to be unblocked. */ + traceTASK_INCREMENT_TICK( xTickCount ); + + if( uxSchedulerSuspended == ( UBaseType_t ) pdFALSE ) + { + /* Minor optimisation. The tick count cannot change in this + * block. */ + const TickType_t xConstTickCount = xTickCount + ( TickType_t ) 1; + + /* Increment the RTOS tick, switching the delayed and overflowed + * delayed lists if it wraps to 0. */ + xTickCount = xConstTickCount; + + if( xConstTickCount == ( TickType_t ) 0U ) /*lint !e774 'if' does not always evaluate to false as it is looking for an overflow. */ + { + taskSWITCH_DELAYED_LISTS(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* See if this tick has made a timeout expire. Tasks are stored in + * the queue in the order of their wake time - meaning once one task + * has been found whose block time has not expired there is no need to + * look any further down the list. */ + if( xConstTickCount >= xNextTaskUnblockTime ) + { + for( ; ; ) + { + if( listLIST_IS_EMPTY( pxDelayedTaskList ) != pdFALSE ) + { + /* The delayed list is empty. Set xNextTaskUnblockTime + * to the maximum possible value so it is extremely + * unlikely that the + * if( xTickCount >= xNextTaskUnblockTime ) test will pass + * next time through. */ + xNextTaskUnblockTime = portMAX_DELAY; /*lint !e961 MISRA exception as the casts are only redundant for some ports. */ + break; + } + else + { + /* The delayed list is not empty, get the value of the + * item at the head of the delayed list. This is the time + * at which the task at the head of the delayed list must + * be removed from the Blocked state. */ + pxTCB = listGET_OWNER_OF_HEAD_ENTRY( pxDelayedTaskList ); /*lint !e9079 void * is used as this macro is used with timers and co-routines too. Alignment is known to be fine as the type of the pointer stored and retrieved is the same. */ + xItemValue = listGET_LIST_ITEM_VALUE( &( pxTCB->xStateListItem ) ); + + if( xConstTickCount < xItemValue ) + { + /* It is not time to unblock this item yet, but the + * item value is the time at which the task at the head + * of the blocked list must be removed from the Blocked + * state - so record the item value in + * xNextTaskUnblockTime. */ + xNextTaskUnblockTime = xItemValue; + break; /*lint !e9011 Code structure here is deedmed easier to understand with multiple breaks. */ + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* It is time to remove the item from the Blocked state. */ + ( void ) uxListRemove( &( pxTCB->xStateListItem ) ); + + /* Is the task waiting on an event also? If so remove + * it from the event list. */ + if( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) != NULL ) + { + ( void ) uxListRemove( &( pxTCB->xEventListItem ) ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* Place the unblocked task into the appropriate ready + * list. */ + prvAddTaskToReadyList( pxTCB ); + + /* A task being unblocked cannot cause an immediate + * context switch if preemption is turned off. */ + #if ( configUSE_PREEMPTION == 1 ) + { + /* Preemption is on, but a context switch should + * only be performed if the unblocked task has a + * priority that is equal to or higher than the + * currently executing task. */ + if( pxTCB->uxPriority >= pxCurrentTCB->uxPriority ) + { + xSwitchRequired = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + #endif /* configUSE_PREEMPTION */ + } + } + } + + /* Tasks of equal priority to the currently running task will share + * processing time (time slice) if preemption is on, and the application + * writer has not explicitly turned time slicing off. */ + #if ( ( configUSE_PREEMPTION == 1 ) && ( configUSE_TIME_SLICING == 1 ) ) + { + if( listCURRENT_LIST_LENGTH( &( pxReadyTasksLists[ pxCurrentTCB->uxPriority ] ) ) > ( UBaseType_t ) 1 ) + { + xSwitchRequired = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + #endif /* ( ( configUSE_PREEMPTION == 1 ) && ( configUSE_TIME_SLICING == 1 ) ) */ + + #if ( configUSE_TICK_HOOK == 1 ) + { + /* Guard against the tick hook being called when the pended tick + * count is being unwound (when the scheduler is being unlocked). */ + if( xPendedTicks == ( TickType_t ) 0 ) + { + vApplicationTickHook(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + #endif /* configUSE_TICK_HOOK */ + + #if ( configUSE_PREEMPTION == 1 ) + { + if( xYieldPending != pdFALSE ) + { + xSwitchRequired = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + #endif /* configUSE_PREEMPTION */ + } + else + { + ++xPendedTicks; + + /* The tick hook gets called at regular intervals, even if the + * scheduler is locked. */ + #if ( configUSE_TICK_HOOK == 1 ) + { + vApplicationTickHook(); + } + #endif + } + + return xSwitchRequired; +} +/*-----------------------------------------------------------*/ + +#if ( configUSE_APPLICATION_TASK_TAG == 1 ) + + void vTaskSetApplicationTaskTag( TaskHandle_t xTask, + TaskHookFunction_t pxHookFunction ) + { + TCB_t * xTCB; + + /* If xTask is NULL then it is the task hook of the calling task that is + * getting set. */ + if( xTask == NULL ) + { + xTCB = ( TCB_t * ) pxCurrentTCB; + } + else + { + xTCB = xTask; + } + + /* Save the hook function in the TCB. A critical section is required as + * the value can be accessed from an interrupt. */ + taskENTER_CRITICAL(); + { + xTCB->pxTaskTag = pxHookFunction; + } + taskEXIT_CRITICAL(); + } + +#endif /* configUSE_APPLICATION_TASK_TAG */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_APPLICATION_TASK_TAG == 1 ) + + TaskHookFunction_t xTaskGetApplicationTaskTag( TaskHandle_t xTask ) + { + TCB_t * pxTCB; + TaskHookFunction_t xReturn; + + /* If xTask is NULL then set the calling task's hook. */ + pxTCB = prvGetTCBFromHandle( xTask ); + + /* Save the hook function in the TCB. A critical section is required as + * the value can be accessed from an interrupt. */ + taskENTER_CRITICAL(); + { + xReturn = pxTCB->pxTaskTag; + } + taskEXIT_CRITICAL(); + + return xReturn; + } + +#endif /* configUSE_APPLICATION_TASK_TAG */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_APPLICATION_TASK_TAG == 1 ) + + TaskHookFunction_t xTaskGetApplicationTaskTagFromISR( TaskHandle_t xTask ) + { + TCB_t * pxTCB; + TaskHookFunction_t xReturn; + UBaseType_t uxSavedInterruptStatus; + + /* If xTask is NULL then set the calling task's hook. */ + pxTCB = prvGetTCBFromHandle( xTask ); + + /* Save the hook function in the TCB. A critical section is required as + * the value can be accessed from an interrupt. */ + uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR(); + { + xReturn = pxTCB->pxTaskTag; + } + portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); + + return xReturn; + } + +#endif /* configUSE_APPLICATION_TASK_TAG */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_APPLICATION_TASK_TAG == 1 ) + + BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask, + void * pvParameter ) + { + TCB_t * xTCB; + BaseType_t xReturn; + + /* If xTask is NULL then we are calling our own task hook. */ + if( xTask == NULL ) + { + xTCB = pxCurrentTCB; + } + else + { + xTCB = xTask; + } + + if( xTCB->pxTaskTag != NULL ) + { + xReturn = xTCB->pxTaskTag( pvParameter ); + } + else + { + xReturn = pdFAIL; + } + + return xReturn; + } + +#endif /* configUSE_APPLICATION_TASK_TAG */ +/*-----------------------------------------------------------*/ + +void vTaskSwitchContext( void ) +{ + if( uxSchedulerSuspended != ( UBaseType_t ) pdFALSE ) + { + /* The scheduler is currently suspended - do not allow a context + * switch. */ + xYieldPending = pdTRUE; + } + else + { + xYieldPending = pdFALSE; + traceTASK_SWITCHED_OUT(); + + #if ( configGENERATE_RUN_TIME_STATS == 1 ) + { + #ifdef portALT_GET_RUN_TIME_COUNTER_VALUE + portALT_GET_RUN_TIME_COUNTER_VALUE( ulTotalRunTime ); + #else + ulTotalRunTime = portGET_RUN_TIME_COUNTER_VALUE(); + #endif + + /* Add the amount of time the task has been running to the + * accumulated time so far. The time the task started running was + * stored in ulTaskSwitchedInTime. Note that there is no overflow + * protection here so count values are only valid until the timer + * overflows. The guard against negative values is to protect + * against suspect run time stat counter implementations - which + * are provided by the application, not the kernel. */ + if( ulTotalRunTime > ulTaskSwitchedInTime ) + { + pxCurrentTCB->ulRunTimeCounter += ( ulTotalRunTime - ulTaskSwitchedInTime ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + ulTaskSwitchedInTime = ulTotalRunTime; + } + #endif /* configGENERATE_RUN_TIME_STATS */ + + /* Check for stack overflow, if configured. */ + taskCHECK_FOR_STACK_OVERFLOW(); + + /* Before the currently running task is switched out, save its errno. */ + #if ( configUSE_POSIX_ERRNO == 1 ) + { + pxCurrentTCB->iTaskErrno = FreeRTOS_errno; + } + #endif + + /* Select a new task to run using either the generic C or port + * optimised asm code. */ + taskSELECT_HIGHEST_PRIORITY_TASK(); /*lint !e9079 void * is used as this macro is used with timers and co-routines too. Alignment is known to be fine as the type of the pointer stored and retrieved is the same. */ + traceTASK_SWITCHED_IN(); + + /* After the new task is switched in, update the global errno. */ + #if ( configUSE_POSIX_ERRNO == 1 ) + { + FreeRTOS_errno = pxCurrentTCB->iTaskErrno; + } + #endif + + #if ( configUSE_NEWLIB_REENTRANT == 1 ) + { + /* Switch Newlib's _impure_ptr variable to point to the _reent + * structure specific to this task. + * See the third party link http://www.nadler.com/embedded/newlibAndFreeRTOS.html + * for additional information. */ + _impure_ptr = &( pxCurrentTCB->xNewLib_reent ); + } + #endif /* configUSE_NEWLIB_REENTRANT */ + } +} +/*-----------------------------------------------------------*/ + +void vTaskPlaceOnEventList( List_t * const pxEventList, + const TickType_t xTicksToWait ) +{ + configASSERT( pxEventList ); + + /* THIS FUNCTION MUST BE CALLED WITH EITHER INTERRUPTS DISABLED OR THE + * SCHEDULER SUSPENDED AND THE QUEUE BEING ACCESSED LOCKED. */ + + /* Place the event list item of the TCB in the appropriate event list. + * This is placed in the list in priority order so the highest priority task + * is the first to be woken by the event. The queue that contains the event + * list is locked, preventing simultaneous access from interrupts. */ + vListInsert( pxEventList, &( pxCurrentTCB->xEventListItem ) ); + + prvAddCurrentTaskToDelayedList( xTicksToWait, pdTRUE ); +} +/*-----------------------------------------------------------*/ + +void vTaskPlaceOnUnorderedEventList( List_t * pxEventList, + const TickType_t xItemValue, + const TickType_t xTicksToWait ) +{ + configASSERT( pxEventList ); + + /* THIS FUNCTION MUST BE CALLED WITH THE SCHEDULER SUSPENDED. It is used by + * the event groups implementation. */ + configASSERT( uxSchedulerSuspended != 0 ); + + /* Store the item value in the event list item. It is safe to access the + * event list item here as interrupts won't access the event list item of a + * task that is not in the Blocked state. */ + listSET_LIST_ITEM_VALUE( &( pxCurrentTCB->xEventListItem ), xItemValue | taskEVENT_LIST_ITEM_VALUE_IN_USE ); + + /* Place the event list item of the TCB at the end of the appropriate event + * list. It is safe to access the event list here because it is part of an + * event group implementation - and interrupts don't access event groups + * directly (instead they access them indirectly by pending function calls to + * the task level). */ + vListInsertEnd( pxEventList, &( pxCurrentTCB->xEventListItem ) ); + + prvAddCurrentTaskToDelayedList( xTicksToWait, pdTRUE ); +} +/*-----------------------------------------------------------*/ + +#if ( configUSE_TIMERS == 1 ) + + void vTaskPlaceOnEventListRestricted( List_t * const pxEventList, + TickType_t xTicksToWait, + const BaseType_t xWaitIndefinitely ) + { + configASSERT( pxEventList ); + + /* This function should not be called by application code hence the + * 'Restricted' in its name. It is not part of the public API. It is + * designed for use by kernel code, and has special calling requirements - + * it should be called with the scheduler suspended. */ + + + /* Place the event list item of the TCB in the appropriate event list. + * In this case it is assume that this is the only task that is going to + * be waiting on this event list, so the faster vListInsertEnd() function + * can be used in place of vListInsert. */ + vListInsertEnd( pxEventList, &( pxCurrentTCB->xEventListItem ) ); + + /* If the task should block indefinitely then set the block time to a + * value that will be recognised as an indefinite delay inside the + * prvAddCurrentTaskToDelayedList() function. */ + if( xWaitIndefinitely != pdFALSE ) + { + xTicksToWait = portMAX_DELAY; + } + + traceTASK_DELAY_UNTIL( ( xTickCount + xTicksToWait ) ); + prvAddCurrentTaskToDelayedList( xTicksToWait, xWaitIndefinitely ); + } + +#endif /* configUSE_TIMERS */ +/*-----------------------------------------------------------*/ + +BaseType_t xTaskRemoveFromEventList( const List_t * const pxEventList ) +{ + TCB_t * pxUnblockedTCB; + BaseType_t xReturn; + + /* THIS FUNCTION MUST BE CALLED FROM A CRITICAL SECTION. It can also be + * called from a critical section within an ISR. */ + + /* The event list is sorted in priority order, so the first in the list can + * be removed as it is known to be the highest priority. Remove the TCB from + * the delayed list, and add it to the ready list. + * + * If an event is for a queue that is locked then this function will never + * get called - the lock count on the queue will get modified instead. This + * means exclusive access to the event list is guaranteed here. + * + * This function assumes that a check has already been made to ensure that + * pxEventList is not empty. */ + pxUnblockedTCB = listGET_OWNER_OF_HEAD_ENTRY( pxEventList ); /*lint !e9079 void * is used as this macro is used with timers and co-routines too. Alignment is known to be fine as the type of the pointer stored and retrieved is the same. */ + configASSERT( pxUnblockedTCB ); + ( void ) uxListRemove( &( pxUnblockedTCB->xEventListItem ) ); + + if( uxSchedulerSuspended == ( UBaseType_t ) pdFALSE ) + { + ( void ) uxListRemove( &( pxUnblockedTCB->xStateListItem ) ); + prvAddTaskToReadyList( pxUnblockedTCB ); + + #if ( configUSE_TICKLESS_IDLE != 0 ) + { + /* If a task is blocked on a kernel object then xNextTaskUnblockTime + * might be set to the blocked task's time out time. If the task is + * unblocked for a reason other than a timeout xNextTaskUnblockTime is + * normally left unchanged, because it is automatically reset to a new + * value when the tick count equals xNextTaskUnblockTime. However if + * tickless idling is used it might be more important to enter sleep mode + * at the earliest possible time - so reset xNextTaskUnblockTime here to + * ensure it is updated at the earliest possible time. */ + prvResetNextTaskUnblockTime(); + } + #endif + } + else + { + /* The delayed and ready lists cannot be accessed, so hold this task + * pending until the scheduler is resumed. */ + vListInsertEnd( &( xPendingReadyList ), &( pxUnblockedTCB->xEventListItem ) ); + } + + if( pxUnblockedTCB->uxPriority > pxCurrentTCB->uxPriority ) + { + /* Return true if the task removed from the event list has a higher + * priority than the calling task. This allows the calling task to know if + * it should force a context switch now. */ + xReturn = pdTRUE; + + /* Mark that a yield is pending in case the user is not using the + * "xHigherPriorityTaskWoken" parameter to an ISR safe FreeRTOS function. */ + xYieldPending = pdTRUE; + } + else + { + xReturn = pdFALSE; + } + + return xReturn; +} +/*-----------------------------------------------------------*/ + +void vTaskRemoveFromUnorderedEventList( ListItem_t * pxEventListItem, + const TickType_t xItemValue ) +{ + TCB_t * pxUnblockedTCB; + + /* THIS FUNCTION MUST BE CALLED WITH THE SCHEDULER SUSPENDED. It is used by + * the event flags implementation. */ + configASSERT( uxSchedulerSuspended != pdFALSE ); + + /* Store the new item value in the event list. */ + listSET_LIST_ITEM_VALUE( pxEventListItem, xItemValue | taskEVENT_LIST_ITEM_VALUE_IN_USE ); + + /* Remove the event list form the event flag. Interrupts do not access + * event flags. */ + pxUnblockedTCB = listGET_LIST_ITEM_OWNER( pxEventListItem ); /*lint !e9079 void * is used as this macro is used with timers and co-routines too. Alignment is known to be fine as the type of the pointer stored and retrieved is the same. */ + configASSERT( pxUnblockedTCB ); + ( void ) uxListRemove( pxEventListItem ); + + #if ( configUSE_TICKLESS_IDLE != 0 ) + { + /* If a task is blocked on a kernel object then xNextTaskUnblockTime + * might be set to the blocked task's time out time. If the task is + * unblocked for a reason other than a timeout xNextTaskUnblockTime is + * normally left unchanged, because it is automatically reset to a new + * value when the tick count equals xNextTaskUnblockTime. However if + * tickless idling is used it might be more important to enter sleep mode + * at the earliest possible time - so reset xNextTaskUnblockTime here to + * ensure it is updated at the earliest possible time. */ + prvResetNextTaskUnblockTime(); + } + #endif + + /* Remove the task from the delayed list and add it to the ready list. The + * scheduler is suspended so interrupts will not be accessing the ready + * lists. */ + ( void ) uxListRemove( &( pxUnblockedTCB->xStateListItem ) ); + prvAddTaskToReadyList( pxUnblockedTCB ); + + if( pxUnblockedTCB->uxPriority > pxCurrentTCB->uxPriority ) + { + /* The unblocked task has a priority above that of the calling task, so + * a context switch is required. This function is called with the + * scheduler suspended so xYieldPending is set so the context switch + * occurs immediately that the scheduler is resumed (unsuspended). */ + xYieldPending = pdTRUE; + } +} +/*-----------------------------------------------------------*/ + +void vTaskSetTimeOutState( TimeOut_t * const pxTimeOut ) +{ + configASSERT( pxTimeOut ); + taskENTER_CRITICAL(); + { + pxTimeOut->xOverflowCount = xNumOfOverflows; + pxTimeOut->xTimeOnEntering = xTickCount; + } + taskEXIT_CRITICAL(); +} +/*-----------------------------------------------------------*/ + +void vTaskInternalSetTimeOutState( TimeOut_t * const pxTimeOut ) +{ + /* For internal use only as it does not use a critical section. */ + pxTimeOut->xOverflowCount = xNumOfOverflows; + pxTimeOut->xTimeOnEntering = xTickCount; +} +/*-----------------------------------------------------------*/ + +BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut, + TickType_t * const pxTicksToWait ) +{ + BaseType_t xReturn; + + configASSERT( pxTimeOut ); + configASSERT( pxTicksToWait ); + + taskENTER_CRITICAL(); + { + /* Minor optimisation. The tick count cannot change in this block. */ + const TickType_t xConstTickCount = xTickCount; + const TickType_t xElapsedTime = xConstTickCount - pxTimeOut->xTimeOnEntering; + + #if ( INCLUDE_xTaskAbortDelay == 1 ) + if( pxCurrentTCB->ucDelayAborted != ( uint8_t ) pdFALSE ) + { + /* The delay was aborted, which is not the same as a time out, + * but has the same result. */ + pxCurrentTCB->ucDelayAborted = pdFALSE; + xReturn = pdTRUE; + } + else + #endif + + #if ( INCLUDE_vTaskSuspend == 1 ) + if( *pxTicksToWait == portMAX_DELAY ) + { + /* If INCLUDE_vTaskSuspend is set to 1 and the block time + * specified is the maximum block time then the task should block + * indefinitely, and therefore never time out. */ + xReturn = pdFALSE; + } + else + #endif + + if( ( xNumOfOverflows != pxTimeOut->xOverflowCount ) && ( xConstTickCount >= pxTimeOut->xTimeOnEntering ) ) /*lint !e525 Indentation preferred as is to make code within pre-processor directives clearer. */ + { + /* The tick count is greater than the time at which + * vTaskSetTimeout() was called, but has also overflowed since + * vTaskSetTimeOut() was called. It must have wrapped all the way + * around and gone past again. This passed since vTaskSetTimeout() + * was called. */ + xReturn = pdTRUE; + *pxTicksToWait = ( TickType_t ) 0; + } + else if( xElapsedTime < *pxTicksToWait ) /*lint !e961 Explicit casting is only redundant with some compilers, whereas others require it to prevent integer conversion errors. */ + { + /* Not a genuine timeout. Adjust parameters for time remaining. */ + *pxTicksToWait -= xElapsedTime; + vTaskInternalSetTimeOutState( pxTimeOut ); + xReturn = pdFALSE; + } + else + { + *pxTicksToWait = ( TickType_t ) 0; + xReturn = pdTRUE; + } + } + taskEXIT_CRITICAL(); + + return xReturn; +} +/*-----------------------------------------------------------*/ + +void vTaskMissedYield( void ) +{ + xYieldPending = pdTRUE; +} +/*-----------------------------------------------------------*/ + +#if ( configUSE_TRACE_FACILITY == 1 ) + + UBaseType_t uxTaskGetTaskNumber( TaskHandle_t xTask ) + { + UBaseType_t uxReturn; + TCB_t const * pxTCB; + + if( xTask != NULL ) + { + pxTCB = xTask; + uxReturn = pxTCB->uxTaskNumber; + } + else + { + uxReturn = 0U; + } + + return uxReturn; + } + +#endif /* configUSE_TRACE_FACILITY */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_TRACE_FACILITY == 1 ) + + void vTaskSetTaskNumber( TaskHandle_t xTask, + const UBaseType_t uxHandle ) + { + TCB_t * pxTCB; + + if( xTask != NULL ) + { + pxTCB = xTask; + pxTCB->uxTaskNumber = uxHandle; + } + } + +#endif /* configUSE_TRACE_FACILITY */ + +/* + * ----------------------------------------------------------- + * The Idle task. + * ---------------------------------------------------------- + * + * The portTASK_FUNCTION() macro is used to allow port/compiler specific + * language extensions. The equivalent prototype for this function is: + * + * void prvIdleTask( void *pvParameters ); + * + */ +static portTASK_FUNCTION( prvIdleTask, pvParameters ) +{ + /* Stop warnings. */ + ( void ) pvParameters; + + /** THIS IS THE RTOS IDLE TASK - WHICH IS CREATED AUTOMATICALLY WHEN THE + * SCHEDULER IS STARTED. **/ + + /* In case a task that has a secure context deletes itself, in which case + * the idle task is responsible for deleting the task's secure context, if + * any. */ + portALLOCATE_SECURE_CONTEXT( configMINIMAL_SECURE_STACK_SIZE ); + + for( ; ; ) + { + /* See if any tasks have deleted themselves - if so then the idle task + * is responsible for freeing the deleted task's TCB and stack. */ + prvCheckTasksWaitingTermination(); + + #if ( configUSE_PREEMPTION == 0 ) + { + /* If we are not using preemption we keep forcing a task switch to + * see if any other task has become available. If we are using + * preemption we don't need to do this as any task becoming available + * will automatically get the processor anyway. */ + taskYIELD(); + } + #endif /* configUSE_PREEMPTION */ + + #if ( ( configUSE_PREEMPTION == 1 ) && ( configIDLE_SHOULD_YIELD == 1 ) ) + { + /* When using preemption tasks of equal priority will be + * timesliced. If a task that is sharing the idle priority is ready + * to run then the idle task should yield before the end of the + * timeslice. + * + * A critical region is not required here as we are just reading from + * the list, and an occasional incorrect value will not matter. If + * the ready list at the idle priority contains more than one task + * then a task other than the idle task is ready to execute. */ + if( listCURRENT_LIST_LENGTH( &( pxReadyTasksLists[ tskIDLE_PRIORITY ] ) ) > ( UBaseType_t ) 1 ) + { + taskYIELD(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + #endif /* ( ( configUSE_PREEMPTION == 1 ) && ( configIDLE_SHOULD_YIELD == 1 ) ) */ + + #if ( configUSE_IDLE_HOOK == 1 ) + { + extern void vApplicationIdleHook( void ); + + /* Call the user defined function from within the idle task. This + * allows the application designer to add background functionality + * without the overhead of a separate task. + * NOTE: vApplicationIdleHook() MUST NOT, UNDER ANY CIRCUMSTANCES, + * CALL A FUNCTION THAT MIGHT BLOCK. */ + vApplicationIdleHook(); + } + #endif /* configUSE_IDLE_HOOK */ + + /* This conditional compilation should use inequality to 0, not equality + * to 1. This is to ensure portSUPPRESS_TICKS_AND_SLEEP() is called when + * user defined low power mode implementations require + * configUSE_TICKLESS_IDLE to be set to a value other than 1. */ + #if ( configUSE_TICKLESS_IDLE != 0 ) + { + TickType_t xExpectedIdleTime; + + /* It is not desirable to suspend then resume the scheduler on + * each iteration of the idle task. Therefore, a preliminary + * test of the expected idle time is performed without the + * scheduler suspended. The result here is not necessarily + * valid. */ + xExpectedIdleTime = prvGetExpectedIdleTime(); + + if( xExpectedIdleTime >= configEXPECTED_IDLE_TIME_BEFORE_SLEEP ) + { + vTaskSuspendAll(); + { + /* Now the scheduler is suspended, the expected idle + * time can be sampled again, and this time its value can + * be used. */ + configASSERT( xNextTaskUnblockTime >= xTickCount ); + xExpectedIdleTime = prvGetExpectedIdleTime(); + + /* Define the following macro to set xExpectedIdleTime to 0 + * if the application does not want + * portSUPPRESS_TICKS_AND_SLEEP() to be called. */ + configPRE_SUPPRESS_TICKS_AND_SLEEP_PROCESSING( xExpectedIdleTime ); + + if( xExpectedIdleTime >= configEXPECTED_IDLE_TIME_BEFORE_SLEEP ) + { + traceLOW_POWER_IDLE_BEGIN(); + portSUPPRESS_TICKS_AND_SLEEP( xExpectedIdleTime ); + traceLOW_POWER_IDLE_END(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + ( void ) xTaskResumeAll(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + #endif /* configUSE_TICKLESS_IDLE */ + } +} +/*-----------------------------------------------------------*/ + +#if ( configUSE_TICKLESS_IDLE != 0 ) + + eSleepModeStatus eTaskConfirmSleepModeStatus( void ) + { + /* The idle task exists in addition to the application tasks. */ + const UBaseType_t uxNonApplicationTasks = 1; + eSleepModeStatus eReturn = eStandardSleep; + + /* This function must be called from a critical section. */ + + if( listCURRENT_LIST_LENGTH( &xPendingReadyList ) != 0 ) + { + /* A task was made ready while the scheduler was suspended. */ + eReturn = eAbortSleep; + } + else if( xYieldPending != pdFALSE ) + { + /* A yield was pended while the scheduler was suspended. */ + eReturn = eAbortSleep; + } + else if( xPendedTicks != 0 ) + { + /* A tick interrupt has already occurred but was held pending + * because the scheduler is suspended. */ + eReturn = eAbortSleep; + } + else + { + /* If all the tasks are in the suspended list (which might mean they + * have an infinite block time rather than actually being suspended) + * then it is safe to turn all clocks off and just wait for external + * interrupts. */ + if( listCURRENT_LIST_LENGTH( &xSuspendedTaskList ) == ( uxCurrentNumberOfTasks - uxNonApplicationTasks ) ) + { + eReturn = eNoTasksWaitingTimeout; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + + return eReturn; + } + +#endif /* configUSE_TICKLESS_IDLE */ +/*-----------------------------------------------------------*/ + +#if ( configNUM_THREAD_LOCAL_STORAGE_POINTERS != 0 ) + + void vTaskSetThreadLocalStoragePointer( TaskHandle_t xTaskToSet, + BaseType_t xIndex, + void * pvValue ) + { + TCB_t * pxTCB; + + if( xIndex < configNUM_THREAD_LOCAL_STORAGE_POINTERS ) + { + pxTCB = prvGetTCBFromHandle( xTaskToSet ); + configASSERT( pxTCB != NULL ); + pxTCB->pvThreadLocalStoragePointers[ xIndex ] = pvValue; + } + } + +#endif /* configNUM_THREAD_LOCAL_STORAGE_POINTERS */ +/*-----------------------------------------------------------*/ + +#if ( configNUM_THREAD_LOCAL_STORAGE_POINTERS != 0 ) + + void * pvTaskGetThreadLocalStoragePointer( TaskHandle_t xTaskToQuery, + BaseType_t xIndex ) + { + void * pvReturn = NULL; + TCB_t * pxTCB; + + if( xIndex < configNUM_THREAD_LOCAL_STORAGE_POINTERS ) + { + pxTCB = prvGetTCBFromHandle( xTaskToQuery ); + pvReturn = pxTCB->pvThreadLocalStoragePointers[ xIndex ]; + } + else + { + pvReturn = NULL; + } + + return pvReturn; + } + +#endif /* configNUM_THREAD_LOCAL_STORAGE_POINTERS */ +/*-----------------------------------------------------------*/ + +#if ( portUSING_MPU_WRAPPERS == 1 ) + + void vTaskAllocateMPURegions( TaskHandle_t xTaskToModify, + const MemoryRegion_t * const xRegions ) + { + TCB_t * pxTCB; + + /* If null is passed in here then we are modifying the MPU settings of + * the calling task. */ + pxTCB = prvGetTCBFromHandle( xTaskToModify ); + + vPortStoreTaskMPUSettings( &( pxTCB->xMPUSettings ), xRegions, NULL, 0 ); + } + +#endif /* portUSING_MPU_WRAPPERS */ +/*-----------------------------------------------------------*/ + +static void prvInitialiseTaskLists( void ) +{ + UBaseType_t uxPriority; + + for( uxPriority = ( UBaseType_t ) 0U; uxPriority < ( UBaseType_t ) configMAX_PRIORITIES; uxPriority++ ) + { + vListInitialise( &( pxReadyTasksLists[ uxPriority ] ) ); + } + + vListInitialise( &xDelayedTaskList1 ); + vListInitialise( &xDelayedTaskList2 ); + vListInitialise( &xPendingReadyList ); + + #if ( INCLUDE_vTaskDelete == 1 ) + { + vListInitialise( &xTasksWaitingTermination ); + } + #endif /* INCLUDE_vTaskDelete */ + + #if ( INCLUDE_vTaskSuspend == 1 ) + { + vListInitialise( &xSuspendedTaskList ); + } + #endif /* INCLUDE_vTaskSuspend */ + + /* Start with pxDelayedTaskList using list1 and the pxOverflowDelayedTaskList + * using list2. */ + pxDelayedTaskList = &xDelayedTaskList1; + pxOverflowDelayedTaskList = &xDelayedTaskList2; +} +/*-----------------------------------------------------------*/ + +static void prvCheckTasksWaitingTermination( void ) +{ + /** THIS FUNCTION IS CALLED FROM THE RTOS IDLE TASK **/ + + #if ( INCLUDE_vTaskDelete == 1 ) + { + TCB_t * pxTCB; + + /* uxDeletedTasksWaitingCleanUp is used to prevent taskENTER_CRITICAL() + * being called too often in the idle task. */ + while( uxDeletedTasksWaitingCleanUp > ( UBaseType_t ) 0U ) + { + taskENTER_CRITICAL(); + { + pxTCB = listGET_OWNER_OF_HEAD_ENTRY( ( &xTasksWaitingTermination ) ); /*lint !e9079 void * is used as this macro is used with timers and co-routines too. Alignment is known to be fine as the type of the pointer stored and retrieved is the same. */ + ( void ) uxListRemove( &( pxTCB->xStateListItem ) ); + --uxCurrentNumberOfTasks; + --uxDeletedTasksWaitingCleanUp; + } + taskEXIT_CRITICAL(); + + prvDeleteTCB( pxTCB ); + } + } + #endif /* INCLUDE_vTaskDelete */ +} +/*-----------------------------------------------------------*/ + +#if ( configUSE_TRACE_FACILITY == 1 ) + + void vTaskGetInfo( TaskHandle_t xTask, + TaskStatus_t * pxTaskStatus, + BaseType_t xGetFreeStackSpace, + eTaskState eState ) + { + TCB_t * pxTCB; + + /* xTask is NULL then get the state of the calling task. */ + pxTCB = prvGetTCBFromHandle( xTask ); + + pxTaskStatus->xHandle = ( TaskHandle_t ) pxTCB; + pxTaskStatus->pcTaskName = ( const char * ) &( pxTCB->pcTaskName[ 0 ] ); + pxTaskStatus->uxCurrentPriority = pxTCB->uxPriority; + pxTaskStatus->pxStackBase = pxTCB->pxStack; + pxTaskStatus->xTaskNumber = pxTCB->uxTCBNumber; + + #if ( configUSE_MUTEXES == 1 ) + { + pxTaskStatus->uxBasePriority = pxTCB->uxBasePriority; + } + #else + { + pxTaskStatus->uxBasePriority = 0; + } + #endif + + #if ( configGENERATE_RUN_TIME_STATS == 1 ) + { + pxTaskStatus->ulRunTimeCounter = pxTCB->ulRunTimeCounter; + } + #else + { + pxTaskStatus->ulRunTimeCounter = 0; + } + #endif + + /* Obtaining the task state is a little fiddly, so is only done if the + * value of eState passed into this function is eInvalid - otherwise the + * state is just set to whatever is passed in. */ + if( eState != eInvalid ) + { + if( pxTCB == pxCurrentTCB ) + { + pxTaskStatus->eCurrentState = eRunning; + } + else + { + pxTaskStatus->eCurrentState = eState; + + #if ( INCLUDE_vTaskSuspend == 1 ) + { + /* If the task is in the suspended list then there is a + * chance it is actually just blocked indefinitely - so really + * it should be reported as being in the Blocked state. */ + if( eState == eSuspended ) + { + vTaskSuspendAll(); + { + if( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) != NULL ) + { + pxTaskStatus->eCurrentState = eBlocked; + } + } + ( void ) xTaskResumeAll(); + } + } + #endif /* INCLUDE_vTaskSuspend */ + } + } + else + { + pxTaskStatus->eCurrentState = eTaskGetState( pxTCB ); + } + + /* Obtaining the stack space takes some time, so the xGetFreeStackSpace + * parameter is provided to allow it to be skipped. */ + if( xGetFreeStackSpace != pdFALSE ) + { + #if ( portSTACK_GROWTH > 0 ) + { + pxTaskStatus->usStackHighWaterMark = prvTaskCheckFreeStackSpace( ( uint8_t * ) pxTCB->pxEndOfStack ); + } + #else + { + pxTaskStatus->usStackHighWaterMark = prvTaskCheckFreeStackSpace( ( uint8_t * ) pxTCB->pxStack ); + } + #endif + } + else + { + pxTaskStatus->usStackHighWaterMark = 0; + } + } + +#endif /* configUSE_TRACE_FACILITY */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_TRACE_FACILITY == 1 ) + + static UBaseType_t prvListTasksWithinSingleList( TaskStatus_t * pxTaskStatusArray, + List_t * pxList, + eTaskState eState ) + { + configLIST_VOLATILE TCB_t * pxNextTCB, * pxFirstTCB; + UBaseType_t uxTask = 0; + + if( listCURRENT_LIST_LENGTH( pxList ) > ( UBaseType_t ) 0 ) + { + listGET_OWNER_OF_NEXT_ENTRY( pxFirstTCB, pxList ); /*lint !e9079 void * is used as this macro is used with timers and co-routines too. Alignment is known to be fine as the type of the pointer stored and retrieved is the same. */ + + /* Populate an TaskStatus_t structure within the + * pxTaskStatusArray array for each task that is referenced from + * pxList. See the definition of TaskStatus_t in task.h for the + * meaning of each TaskStatus_t structure member. */ + do + { + listGET_OWNER_OF_NEXT_ENTRY( pxNextTCB, pxList ); /*lint !e9079 void * is used as this macro is used with timers and co-routines too. Alignment is known to be fine as the type of the pointer stored and retrieved is the same. */ + vTaskGetInfo( ( TaskHandle_t ) pxNextTCB, &( pxTaskStatusArray[ uxTask ] ), pdTRUE, eState ); + uxTask++; + } while( pxNextTCB != pxFirstTCB ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + return uxTask; + } + +#endif /* configUSE_TRACE_FACILITY */ +/*-----------------------------------------------------------*/ + +#if ( ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark2 == 1 ) ) + + static configSTACK_DEPTH_TYPE prvTaskCheckFreeStackSpace( const uint8_t * pucStackByte ) + { + uint32_t ulCount = 0U; + + while( *pucStackByte == ( uint8_t ) tskSTACK_FILL_BYTE ) + { + pucStackByte -= portSTACK_GROWTH; + ulCount++; + } + + ulCount /= ( uint32_t ) sizeof( StackType_t ); /*lint !e961 Casting is not redundant on smaller architectures. */ + + return ( configSTACK_DEPTH_TYPE ) ulCount; + } + +#endif /* ( ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark2 == 1 ) ) */ +/*-----------------------------------------------------------*/ + +#if ( INCLUDE_uxTaskGetStackHighWaterMark2 == 1 ) + +/* uxTaskGetStackHighWaterMark() and uxTaskGetStackHighWaterMark2() are the + * same except for their return type. Using configSTACK_DEPTH_TYPE allows the + * user to determine the return type. It gets around the problem of the value + * overflowing on 8-bit types without breaking backward compatibility for + * applications that expect an 8-bit return type. */ + configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask ) + { + TCB_t * pxTCB; + uint8_t * pucEndOfStack; + configSTACK_DEPTH_TYPE uxReturn; + + /* uxTaskGetStackHighWaterMark() and uxTaskGetStackHighWaterMark2() are + * the same except for their return type. Using configSTACK_DEPTH_TYPE + * allows the user to determine the return type. It gets around the + * problem of the value overflowing on 8-bit types without breaking + * backward compatibility for applications that expect an 8-bit return + * type. */ + + pxTCB = prvGetTCBFromHandle( xTask ); + + #if portSTACK_GROWTH < 0 + { + pucEndOfStack = ( uint8_t * ) pxTCB->pxStack; + } + #else + { + pucEndOfStack = ( uint8_t * ) pxTCB->pxEndOfStack; + } + #endif + + uxReturn = prvTaskCheckFreeStackSpace( pucEndOfStack ); + + return uxReturn; + } + +#endif /* INCLUDE_uxTaskGetStackHighWaterMark2 */ +/*-----------------------------------------------------------*/ + +#if ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) + + UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask ) + { + TCB_t * pxTCB; + uint8_t * pucEndOfStack; + UBaseType_t uxReturn; + + pxTCB = prvGetTCBFromHandle( xTask ); + + #if portSTACK_GROWTH < 0 + { + pucEndOfStack = ( uint8_t * ) pxTCB->pxStack; + } + #else + { + pucEndOfStack = ( uint8_t * ) pxTCB->pxEndOfStack; + } + #endif + + uxReturn = ( UBaseType_t ) prvTaskCheckFreeStackSpace( pucEndOfStack ); + + return uxReturn; + } + +#endif /* INCLUDE_uxTaskGetStackHighWaterMark */ +/*-----------------------------------------------------------*/ + +#if ( INCLUDE_vTaskDelete == 1 ) + + static void prvDeleteTCB( TCB_t * pxTCB ) + { + /* This call is required specifically for the TriCore port. It must be + * above the vPortFree() calls. The call is also used by ports/demos that + * want to allocate and clean RAM statically. */ + portCLEAN_UP_TCB( pxTCB ); + + /* Free up the memory allocated by the scheduler for the task. It is up + * to the task to free any memory allocated at the application level. + * See the third party link http://www.nadler.com/embedded/newlibAndFreeRTOS.html + * for additional information. */ + #if ( configUSE_NEWLIB_REENTRANT == 1 ) + { + _reclaim_reent( &( pxTCB->xNewLib_reent ) ); + } + #endif /* configUSE_NEWLIB_REENTRANT */ + + #if ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 0 ) && ( portUSING_MPU_WRAPPERS == 0 ) ) + { + /* The task can only have been allocated dynamically - free both + * the stack and TCB. */ + vPortFree( pxTCB->pxStack ); + vPortFree( pxTCB ); + } + #elif ( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 ) /*lint !e731 !e9029 Macro has been consolidated for readability reasons. */ + { + /* The task could have been allocated statically or dynamically, so + * check what was statically allocated before trying to free the + * memory. */ + if( pxTCB->ucStaticallyAllocated == tskDYNAMICALLY_ALLOCATED_STACK_AND_TCB ) + { + /* Both the stack and TCB were allocated dynamically, so both + * must be freed. */ + vPortFree( pxTCB->pxStack ); + vPortFree( pxTCB ); + } + else if( pxTCB->ucStaticallyAllocated == tskSTATICALLY_ALLOCATED_STACK_ONLY ) + { + /* Only the stack was statically allocated, so the TCB is the + * only memory that must be freed. */ + vPortFree( pxTCB ); + } + else + { + /* Neither the stack nor the TCB were allocated dynamically, so + * nothing needs to be freed. */ + configASSERT( pxTCB->ucStaticallyAllocated == tskSTATICALLY_ALLOCATED_STACK_AND_TCB ); + mtCOVERAGE_TEST_MARKER(); + } + } + #endif /* configSUPPORT_DYNAMIC_ALLOCATION */ + } + +#endif /* INCLUDE_vTaskDelete */ +/*-----------------------------------------------------------*/ + +static void prvResetNextTaskUnblockTime( void ) +{ + if( listLIST_IS_EMPTY( pxDelayedTaskList ) != pdFALSE ) + { + /* The new current delayed list is empty. Set xNextTaskUnblockTime to + * the maximum possible value so it is extremely unlikely that the + * if( xTickCount >= xNextTaskUnblockTime ) test will pass until + * there is an item in the delayed list. */ + xNextTaskUnblockTime = portMAX_DELAY; + } + else + { + /* The new current delayed list is not empty, get the value of + * the item at the head of the delayed list. This is the time at + * which the task at the head of the delayed list should be removed + * from the Blocked state. */ + xNextTaskUnblockTime = listGET_ITEM_VALUE_OF_HEAD_ENTRY( pxDelayedTaskList ); + } +} +/*-----------------------------------------------------------*/ + +#if ( ( INCLUDE_xTaskGetCurrentTaskHandle == 1 ) || ( configUSE_MUTEXES == 1 ) ) + + TaskHandle_t xTaskGetCurrentTaskHandle( void ) + { + TaskHandle_t xReturn; + + /* A critical section is not required as this is not called from + * an interrupt and the current TCB will always be the same for any + * individual execution thread. */ + xReturn = pxCurrentTCB; + + return xReturn; + } + +#endif /* ( ( INCLUDE_xTaskGetCurrentTaskHandle == 1 ) || ( configUSE_MUTEXES == 1 ) ) */ +/*-----------------------------------------------------------*/ + +#if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) ) + + BaseType_t xTaskGetSchedulerState( void ) + { + BaseType_t xReturn; + + if( xSchedulerRunning == pdFALSE ) + { + xReturn = taskSCHEDULER_NOT_STARTED; + } + else + { + if( uxSchedulerSuspended == ( UBaseType_t ) pdFALSE ) + { + xReturn = taskSCHEDULER_RUNNING; + } + else + { + xReturn = taskSCHEDULER_SUSPENDED; + } + } + + return xReturn; + } + +#endif /* ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) ) */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_MUTEXES == 1 ) + + BaseType_t xTaskPriorityInherit( TaskHandle_t const pxMutexHolder ) + { + TCB_t * const pxMutexHolderTCB = pxMutexHolder; + BaseType_t xReturn = pdFALSE; + + /* If the mutex was given back by an interrupt while the queue was + * locked then the mutex holder might now be NULL. _RB_ Is this still + * needed as interrupts can no longer use mutexes? */ + if( pxMutexHolder != NULL ) + { + /* If the holder of the mutex has a priority below the priority of + * the task attempting to obtain the mutex then it will temporarily + * inherit the priority of the task attempting to obtain the mutex. */ + if( pxMutexHolderTCB->uxPriority < pxCurrentTCB->uxPriority ) + { + /* Adjust the mutex holder state to account for its new + * priority. Only reset the event list item value if the value is + * not being used for anything else. */ + if( ( listGET_LIST_ITEM_VALUE( &( pxMutexHolderTCB->xEventListItem ) ) & taskEVENT_LIST_ITEM_VALUE_IN_USE ) == 0UL ) + { + listSET_LIST_ITEM_VALUE( &( pxMutexHolderTCB->xEventListItem ), ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) pxCurrentTCB->uxPriority ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */ + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* If the task being modified is in the ready state it will need + * to be moved into a new list. */ + if( listIS_CONTAINED_WITHIN( &( pxReadyTasksLists[ pxMutexHolderTCB->uxPriority ] ), &( pxMutexHolderTCB->xStateListItem ) ) != pdFALSE ) + { + if( uxListRemove( &( pxMutexHolderTCB->xStateListItem ) ) == ( UBaseType_t ) 0 ) + { + /* It is known that the task is in its ready list so + * there is no need to check again and the port level + * reset macro can be called directly. */ + portRESET_READY_PRIORITY( pxMutexHolderTCB->uxPriority, uxTopReadyPriority ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* Inherit the priority before being moved into the new list. */ + pxMutexHolderTCB->uxPriority = pxCurrentTCB->uxPriority; + prvAddTaskToReadyList( pxMutexHolderTCB ); + } + else + { + /* Just inherit the priority. */ + pxMutexHolderTCB->uxPriority = pxCurrentTCB->uxPriority; + } + + traceTASK_PRIORITY_INHERIT( pxMutexHolderTCB, pxCurrentTCB->uxPriority ); + + /* Inheritance occurred. */ + xReturn = pdTRUE; + } + else + { + if( pxMutexHolderTCB->uxBasePriority < pxCurrentTCB->uxPriority ) + { + /* The base priority of the mutex holder is lower than the + * priority of the task attempting to take the mutex, but the + * current priority of the mutex holder is not lower than the + * priority of the task attempting to take the mutex. + * Therefore the mutex holder must have already inherited a + * priority, but inheritance would have occurred if that had + * not been the case. */ + xReturn = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + return xReturn; + } + +#endif /* configUSE_MUTEXES */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_MUTEXES == 1 ) + + BaseType_t xTaskPriorityDisinherit( TaskHandle_t const pxMutexHolder ) + { + TCB_t * const pxTCB = pxMutexHolder; + BaseType_t xReturn = pdFALSE; + + if( pxMutexHolder != NULL ) + { + /* A task can only have an inherited priority if it holds the mutex. + * If the mutex is held by a task then it cannot be given from an + * interrupt, and if a mutex is given by the holding task then it must + * be the running state task. */ + configASSERT( pxTCB == pxCurrentTCB ); + configASSERT( pxTCB->uxMutexesHeld ); + ( pxTCB->uxMutexesHeld )--; + + /* Has the holder of the mutex inherited the priority of another + * task? */ + if( pxTCB->uxPriority != pxTCB->uxBasePriority ) + { + /* Only disinherit if no other mutexes are held. */ + if( pxTCB->uxMutexesHeld == ( UBaseType_t ) 0 ) + { + /* A task can only have an inherited priority if it holds + * the mutex. If the mutex is held by a task then it cannot be + * given from an interrupt, and if a mutex is given by the + * holding task then it must be the running state task. Remove + * the holding task from the ready list. */ + if( uxListRemove( &( pxTCB->xStateListItem ) ) == ( UBaseType_t ) 0 ) + { + portRESET_READY_PRIORITY( pxTCB->uxPriority, uxTopReadyPriority ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* Disinherit the priority before adding the task into the + * new ready list. */ + traceTASK_PRIORITY_DISINHERIT( pxTCB, pxTCB->uxBasePriority ); + pxTCB->uxPriority = pxTCB->uxBasePriority; + + /* Reset the event list item value. It cannot be in use for + * any other purpose if this task is running, and it must be + * running to give back the mutex. */ + listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) pxTCB->uxPriority ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */ + prvAddTaskToReadyList( pxTCB ); + + /* Return true to indicate that a context switch is required. + * This is only actually required in the corner case whereby + * multiple mutexes were held and the mutexes were given back + * in an order different to that in which they were taken. + * If a context switch did not occur when the first mutex was + * returned, even if a task was waiting on it, then a context + * switch should occur when the last mutex is returned whether + * a task is waiting on it or not. */ + xReturn = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + return xReturn; + } + +#endif /* configUSE_MUTEXES */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_MUTEXES == 1 ) + + void vTaskPriorityDisinheritAfterTimeout( TaskHandle_t const pxMutexHolder, + UBaseType_t uxHighestPriorityWaitingTask ) + { + TCB_t * const pxTCB = pxMutexHolder; + UBaseType_t uxPriorityUsedOnEntry, uxPriorityToUse; + const UBaseType_t uxOnlyOneMutexHeld = ( UBaseType_t ) 1; + + if( pxMutexHolder != NULL ) + { + /* If pxMutexHolder is not NULL then the holder must hold at least + * one mutex. */ + configASSERT( pxTCB->uxMutexesHeld ); + + /* Determine the priority to which the priority of the task that + * holds the mutex should be set. This will be the greater of the + * holding task's base priority and the priority of the highest + * priority task that is waiting to obtain the mutex. */ + if( pxTCB->uxBasePriority < uxHighestPriorityWaitingTask ) + { + uxPriorityToUse = uxHighestPriorityWaitingTask; + } + else + { + uxPriorityToUse = pxTCB->uxBasePriority; + } + + /* Does the priority need to change? */ + if( pxTCB->uxPriority != uxPriorityToUse ) + { + /* Only disinherit if no other mutexes are held. This is a + * simplification in the priority inheritance implementation. If + * the task that holds the mutex is also holding other mutexes then + * the other mutexes may have caused the priority inheritance. */ + if( pxTCB->uxMutexesHeld == uxOnlyOneMutexHeld ) + { + /* If a task has timed out because it already holds the + * mutex it was trying to obtain then it cannot of inherited + * its own priority. */ + configASSERT( pxTCB != pxCurrentTCB ); + + /* Disinherit the priority, remembering the previous + * priority to facilitate determining the subject task's + * state. */ + traceTASK_PRIORITY_DISINHERIT( pxTCB, uxPriorityToUse ); + uxPriorityUsedOnEntry = pxTCB->uxPriority; + pxTCB->uxPriority = uxPriorityToUse; + + /* Only reset the event list item value if the value is not + * being used for anything else. */ + if( ( listGET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ) ) & taskEVENT_LIST_ITEM_VALUE_IN_USE ) == 0UL ) + { + listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) uxPriorityToUse ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */ + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* If the running task is not the task that holds the mutex + * then the task that holds the mutex could be in either the + * Ready, Blocked or Suspended states. Only remove the task + * from its current state list if it is in the Ready state as + * the task's priority is going to change and there is one + * Ready list per priority. */ + if( listIS_CONTAINED_WITHIN( &( pxReadyTasksLists[ uxPriorityUsedOnEntry ] ), &( pxTCB->xStateListItem ) ) != pdFALSE ) + { + if( uxListRemove( &( pxTCB->xStateListItem ) ) == ( UBaseType_t ) 0 ) + { + /* It is known that the task is in its ready list so + * there is no need to check again and the port level + * reset macro can be called directly. */ + portRESET_READY_PRIORITY( pxTCB->uxPriority, uxTopReadyPriority ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + prvAddTaskToReadyList( pxTCB ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + +#endif /* configUSE_MUTEXES */ +/*-----------------------------------------------------------*/ + +#if ( portCRITICAL_NESTING_IN_TCB == 1 ) + + void vTaskEnterCritical( void ) + { + portDISABLE_INTERRUPTS(); + + if( xSchedulerRunning != pdFALSE ) + { + ( pxCurrentTCB->uxCriticalNesting )++; + + /* This is not the interrupt safe version of the enter critical + * function so assert() if it is being called from an interrupt + * context. Only API functions that end in "FromISR" can be used in an + * interrupt. Only assert if the critical nesting count is 1 to + * protect against recursive calls if the assert function also uses a + * critical section. */ + if( pxCurrentTCB->uxCriticalNesting == 1 ) + { + portASSERT_IF_IN_ISR(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + +#endif /* portCRITICAL_NESTING_IN_TCB */ +/*-----------------------------------------------------------*/ + +#if ( portCRITICAL_NESTING_IN_TCB == 1 ) + + void vTaskExitCritical( void ) + { + if( xSchedulerRunning != pdFALSE ) + { + if( pxCurrentTCB->uxCriticalNesting > 0U ) + { + ( pxCurrentTCB->uxCriticalNesting )--; + + if( pxCurrentTCB->uxCriticalNesting == 0U ) + { + portENABLE_INTERRUPTS(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + +#endif /* portCRITICAL_NESTING_IN_TCB */ +/*-----------------------------------------------------------*/ + +#if ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) ) + + static char * prvWriteNameToBuffer( char * pcBuffer, + const char * pcTaskName ) + { + size_t x; + + /* Start by copying the entire string. */ + strcpy( pcBuffer, pcTaskName ); + + /* Pad the end of the string with spaces to ensure columns line up when + * printed out. */ + for( x = strlen( pcBuffer ); x < ( size_t ) ( configMAX_TASK_NAME_LEN - 1 ); x++ ) + { + pcBuffer[ x ] = ' '; + } + + /* Terminate. */ + pcBuffer[ x ] = ( char ) 0x00; + + /* Return the new end of string. */ + return &( pcBuffer[ x ] ); + } + +#endif /* ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) */ +/*-----------------------------------------------------------*/ + +#if ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) + + void vTaskList( char * pcWriteBuffer ) + { + TaskStatus_t * pxTaskStatusArray; + UBaseType_t uxArraySize, x; + char cStatus; + + /* + * PLEASE NOTE: + * + * This function is provided for convenience only, and is used by many + * of the demo applications. Do not consider it to be part of the + * scheduler. + * + * vTaskList() calls uxTaskGetSystemState(), then formats part of the + * uxTaskGetSystemState() output into a human readable table that + * displays task names, states and stack usage. + * + * vTaskList() has a dependency on the sprintf() C library function that + * might bloat the code size, use a lot of stack, and provide different + * results on different platforms. An alternative, tiny, third party, + * and limited functionality implementation of sprintf() is provided in + * many of the FreeRTOS/Demo sub-directories in a file called + * printf-stdarg.c (note printf-stdarg.c does not provide a full + * snprintf() implementation!). + * + * It is recommended that production systems call uxTaskGetSystemState() + * directly to get access to raw stats data, rather than indirectly + * through a call to vTaskList(). + */ + + + /* Make sure the write buffer does not contain a string. */ + *pcWriteBuffer = ( char ) 0x00; + + /* Take a snapshot of the number of tasks in case it changes while this + * function is executing. */ + uxArraySize = uxCurrentNumberOfTasks; + + /* Allocate an array index for each task. NOTE! if + * configSUPPORT_DYNAMIC_ALLOCATION is set to 0 then pvPortMalloc() will + * equate to NULL. */ + pxTaskStatusArray = pvPortMalloc( uxCurrentNumberOfTasks * sizeof( TaskStatus_t ) ); /*lint !e9079 All values returned by pvPortMalloc() have at least the alignment required by the MCU's stack and this allocation allocates a struct that has the alignment requirements of a pointer. */ + + if( pxTaskStatusArray != NULL ) + { + /* Generate the (binary) data. */ + uxArraySize = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, NULL ); + + /* Create a human readable table from the binary data. */ + for( x = 0; x < uxArraySize; x++ ) + { + switch( pxTaskStatusArray[ x ].eCurrentState ) + { + case eRunning: + cStatus = tskRUNNING_CHAR; + break; + + case eReady: + cStatus = tskREADY_CHAR; + break; + + case eBlocked: + cStatus = tskBLOCKED_CHAR; + break; + + case eSuspended: + cStatus = tskSUSPENDED_CHAR; + break; + + case eDeleted: + cStatus = tskDELETED_CHAR; + break; + + case eInvalid: /* Fall through. */ + default: /* Should not get here, but it is included + * to prevent static checking errors. */ + cStatus = ( char ) 0x00; + break; + } + + /* Write the task name to the string, padding with spaces so it + * can be printed in tabular form more easily. */ + pcWriteBuffer = prvWriteNameToBuffer( pcWriteBuffer, pxTaskStatusArray[ x ].pcTaskName ); + + /* Write the rest of the string. */ + sprintf( pcWriteBuffer, "\t%c\t%u\t%u\t%u\r\n", cStatus, ( unsigned int ) pxTaskStatusArray[ x ].uxCurrentPriority, ( unsigned int ) pxTaskStatusArray[ x ].usStackHighWaterMark, ( unsigned int ) pxTaskStatusArray[ x ].xTaskNumber ); /*lint !e586 sprintf() allowed as this is compiled with many compilers and this is a utility function only - not part of the core kernel implementation. */ + pcWriteBuffer += strlen( pcWriteBuffer ); /*lint !e9016 Pointer arithmetic ok on char pointers especially as in this case where it best denotes the intent of the code. */ + } + + /* Free the array again. NOTE! If configSUPPORT_DYNAMIC_ALLOCATION + * is 0 then vPortFree() will be #defined to nothing. */ + vPortFree( pxTaskStatusArray ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + +#endif /* ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) */ +/*----------------------------------------------------------*/ + +#if ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) + + void vTaskGetRunTimeStats( char * pcWriteBuffer ) + { + TaskStatus_t * pxTaskStatusArray; + UBaseType_t uxArraySize, x; + uint32_t ulTotalTime, ulStatsAsPercentage; + + #if ( configUSE_TRACE_FACILITY != 1 ) + { + #error configUSE_TRACE_FACILITY must also be set to 1 in FreeRTOSConfig.h to use vTaskGetRunTimeStats(). + } + #endif + + /* + * PLEASE NOTE: + * + * This function is provided for convenience only, and is used by many + * of the demo applications. Do not consider it to be part of the + * scheduler. + * + * vTaskGetRunTimeStats() calls uxTaskGetSystemState(), then formats part + * of the uxTaskGetSystemState() output into a human readable table that + * displays the amount of time each task has spent in the Running state + * in both absolute and percentage terms. + * + * vTaskGetRunTimeStats() has a dependency on the sprintf() C library + * function that might bloat the code size, use a lot of stack, and + * provide different results on different platforms. An alternative, + * tiny, third party, and limited functionality implementation of + * sprintf() is provided in many of the FreeRTOS/Demo sub-directories in + * a file called printf-stdarg.c (note printf-stdarg.c does not provide + * a full snprintf() implementation!). + * + * It is recommended that production systems call uxTaskGetSystemState() + * directly to get access to raw stats data, rather than indirectly + * through a call to vTaskGetRunTimeStats(). + */ + + /* Make sure the write buffer does not contain a string. */ + *pcWriteBuffer = ( char ) 0x00; + + /* Take a snapshot of the number of tasks in case it changes while this + * function is executing. */ + uxArraySize = uxCurrentNumberOfTasks; + + /* Allocate an array index for each task. NOTE! If + * configSUPPORT_DYNAMIC_ALLOCATION is set to 0 then pvPortMalloc() will + * equate to NULL. */ + pxTaskStatusArray = pvPortMalloc( uxCurrentNumberOfTasks * sizeof( TaskStatus_t ) ); /*lint !e9079 All values returned by pvPortMalloc() have at least the alignment required by the MCU's stack and this allocation allocates a struct that has the alignment requirements of a pointer. */ + + if( pxTaskStatusArray != NULL ) + { + /* Generate the (binary) data. */ + uxArraySize = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, &ulTotalTime ); + + /* For percentage calculations. */ + ulTotalTime /= 100UL; + + /* Avoid divide by zero errors. */ + if( ulTotalTime > 0UL ) + { + /* Create a human readable table from the binary data. */ + for( x = 0; x < uxArraySize; x++ ) + { + /* What percentage of the total run time has the task used? + * This will always be rounded down to the nearest integer. + * ulTotalRunTimeDiv100 has already been divided by 100. */ + ulStatsAsPercentage = pxTaskStatusArray[ x ].ulRunTimeCounter / ulTotalTime; + + /* Write the task name to the string, padding with + * spaces so it can be printed in tabular form more + * easily. */ + pcWriteBuffer = prvWriteNameToBuffer( pcWriteBuffer, pxTaskStatusArray[ x ].pcTaskName ); + + if( ulStatsAsPercentage > 0UL ) + { + #ifdef portLU_PRINTF_SPECIFIER_REQUIRED + { + sprintf( pcWriteBuffer, "\t%lu\t\t%lu%%\r\n", pxTaskStatusArray[ x ].ulRunTimeCounter, ulStatsAsPercentage ); + } + #else + { + /* sizeof( int ) == sizeof( long ) so a smaller + * printf() library can be used. */ + sprintf( pcWriteBuffer, "\t%u\t\t%u%%\r\n", ( unsigned int ) pxTaskStatusArray[ x ].ulRunTimeCounter, ( unsigned int ) ulStatsAsPercentage ); /*lint !e586 sprintf() allowed as this is compiled with many compilers and this is a utility function only - not part of the core kernel implementation. */ + } + #endif + } + else + { + /* If the percentage is zero here then the task has + * consumed less than 1% of the total run time. */ + #ifdef portLU_PRINTF_SPECIFIER_REQUIRED + { + sprintf( pcWriteBuffer, "\t%lu\t\t<1%%\r\n", pxTaskStatusArray[ x ].ulRunTimeCounter ); + } + #else + { + /* sizeof( int ) == sizeof( long ) so a smaller + * printf() library can be used. */ + sprintf( pcWriteBuffer, "\t%u\t\t<1%%\r\n", ( unsigned int ) pxTaskStatusArray[ x ].ulRunTimeCounter ); /*lint !e586 sprintf() allowed as this is compiled with many compilers and this is a utility function only - not part of the core kernel implementation. */ + } + #endif + } + + pcWriteBuffer += strlen( pcWriteBuffer ); /*lint !e9016 Pointer arithmetic ok on char pointers especially as in this case where it best denotes the intent of the code. */ + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + /* Free the array again. NOTE! If configSUPPORT_DYNAMIC_ALLOCATION + * is 0 then vPortFree() will be #defined to nothing. */ + vPortFree( pxTaskStatusArray ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + +#endif /* ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) ) */ +/*-----------------------------------------------------------*/ + +TickType_t uxTaskResetEventItemValue( void ) +{ + TickType_t uxReturn; + + uxReturn = listGET_LIST_ITEM_VALUE( &( pxCurrentTCB->xEventListItem ) ); + + /* Reset the event list item to its normal value - so it can be used with + * queues and semaphores. */ + listSET_LIST_ITEM_VALUE( &( pxCurrentTCB->xEventListItem ), ( ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) pxCurrentTCB->uxPriority ) ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */ + + return uxReturn; +} +/*-----------------------------------------------------------*/ + +#if ( configUSE_MUTEXES == 1 ) + + TaskHandle_t pvTaskIncrementMutexHeldCount( void ) + { + /* If xSemaphoreCreateMutex() is called before any tasks have been created + * then pxCurrentTCB will be NULL. */ + if( pxCurrentTCB != NULL ) + { + ( pxCurrentTCB->uxMutexesHeld )++; + } + + return pxCurrentTCB; + } + +#endif /* configUSE_MUTEXES */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_TASK_NOTIFICATIONS == 1 ) + + uint32_t ulTaskGenericNotifyTake( UBaseType_t uxIndexToWait, + BaseType_t xClearCountOnExit, + TickType_t xTicksToWait ) + { + uint32_t ulReturn; + + configASSERT( uxIndexToWait < configTASK_NOTIFICATION_ARRAY_ENTRIES ); + + taskENTER_CRITICAL(); + { + /* Only block if the notification count is not already non-zero. */ + if( pxCurrentTCB->ulNotifiedValue[ uxIndexToWait ] == 0UL ) + { + /* Mark this task as waiting for a notification. */ + pxCurrentTCB->ucNotifyState[ uxIndexToWait ] = taskWAITING_NOTIFICATION; + + if( xTicksToWait > ( TickType_t ) 0 ) + { + prvAddCurrentTaskToDelayedList( xTicksToWait, pdTRUE ); + traceTASK_NOTIFY_TAKE_BLOCK( uxIndexToWait ); + + /* All ports are written to allow a yield in a critical + * section (some will yield immediately, others wait until the + * critical section exits) - but it is not something that + * application code should ever do. */ + portYIELD_WITHIN_API(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + taskEXIT_CRITICAL(); + + taskENTER_CRITICAL(); + { + traceTASK_NOTIFY_TAKE( uxIndexToWait ); + ulReturn = pxCurrentTCB->ulNotifiedValue[ uxIndexToWait ]; + + if( ulReturn != 0UL ) + { + if( xClearCountOnExit != pdFALSE ) + { + pxCurrentTCB->ulNotifiedValue[ uxIndexToWait ] = 0UL; + } + else + { + pxCurrentTCB->ulNotifiedValue[ uxIndexToWait ] = ulReturn - ( uint32_t ) 1; + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + pxCurrentTCB->ucNotifyState[ uxIndexToWait ] = taskNOT_WAITING_NOTIFICATION; + } + taskEXIT_CRITICAL(); + + return ulReturn; + } + +#endif /* configUSE_TASK_NOTIFICATIONS */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_TASK_NOTIFICATIONS == 1 ) + + BaseType_t xTaskGenericNotifyWait( UBaseType_t uxIndexToWait, + uint32_t ulBitsToClearOnEntry, + uint32_t ulBitsToClearOnExit, + uint32_t * pulNotificationValue, + TickType_t xTicksToWait ) + { + BaseType_t xReturn; + + configASSERT( uxIndexToWait < configTASK_NOTIFICATION_ARRAY_ENTRIES ); + + taskENTER_CRITICAL(); + { + /* Only block if a notification is not already pending. */ + if( pxCurrentTCB->ucNotifyState[ uxIndexToWait ] != taskNOTIFICATION_RECEIVED ) + { + /* Clear bits in the task's notification value as bits may get + * set by the notifying task or interrupt. This can be used to + * clear the value to zero. */ + pxCurrentTCB->ulNotifiedValue[ uxIndexToWait ] &= ~ulBitsToClearOnEntry; + + /* Mark this task as waiting for a notification. */ + pxCurrentTCB->ucNotifyState[ uxIndexToWait ] = taskWAITING_NOTIFICATION; + + if( xTicksToWait > ( TickType_t ) 0 ) + { + prvAddCurrentTaskToDelayedList( xTicksToWait, pdTRUE ); + traceTASK_NOTIFY_WAIT_BLOCK( uxIndexToWait ); + + /* All ports are written to allow a yield in a critical + * section (some will yield immediately, others wait until the + * critical section exits) - but it is not something that + * application code should ever do. */ + portYIELD_WITHIN_API(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + taskEXIT_CRITICAL(); + + taskENTER_CRITICAL(); + { + traceTASK_NOTIFY_WAIT( uxIndexToWait ); + + if( pulNotificationValue != NULL ) + { + /* Output the current notification value, which may or may not + * have changed. */ + *pulNotificationValue = pxCurrentTCB->ulNotifiedValue[ uxIndexToWait ]; + } + + /* If ucNotifyValue is set then either the task never entered the + * blocked state (because a notification was already pending) or the + * task unblocked because of a notification. Otherwise the task + * unblocked because of a timeout. */ + if( pxCurrentTCB->ucNotifyState[ uxIndexToWait ] != taskNOTIFICATION_RECEIVED ) + { + /* A notification was not received. */ + xReturn = pdFALSE; + } + else + { + /* A notification was already pending or a notification was + * received while the task was waiting. */ + pxCurrentTCB->ulNotifiedValue[ uxIndexToWait ] &= ~ulBitsToClearOnExit; + xReturn = pdTRUE; + } + + pxCurrentTCB->ucNotifyState[ uxIndexToWait ] = taskNOT_WAITING_NOTIFICATION; + } + taskEXIT_CRITICAL(); + + return xReturn; + } + +#endif /* configUSE_TASK_NOTIFICATIONS */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_TASK_NOTIFICATIONS == 1 ) + + BaseType_t xTaskGenericNotify( TaskHandle_t xTaskToNotify, + UBaseType_t uxIndexToNotify, + uint32_t ulValue, + eNotifyAction eAction, + uint32_t * pulPreviousNotificationValue ) + { + TCB_t * pxTCB; + BaseType_t xReturn = pdPASS; + uint8_t ucOriginalNotifyState; + + configASSERT( uxIndexToNotify < configTASK_NOTIFICATION_ARRAY_ENTRIES ); + configASSERT( xTaskToNotify ); + pxTCB = xTaskToNotify; + + taskENTER_CRITICAL(); + { + if( pulPreviousNotificationValue != NULL ) + { + *pulPreviousNotificationValue = pxTCB->ulNotifiedValue[ uxIndexToNotify ]; + } + + ucOriginalNotifyState = pxTCB->ucNotifyState[ uxIndexToNotify ]; + + pxTCB->ucNotifyState[ uxIndexToNotify ] = taskNOTIFICATION_RECEIVED; + + switch( eAction ) + { + case eSetBits: + pxTCB->ulNotifiedValue[ uxIndexToNotify ] |= ulValue; + break; + + case eIncrement: + ( pxTCB->ulNotifiedValue[ uxIndexToNotify ] )++; + break; + + case eSetValueWithOverwrite: + pxTCB->ulNotifiedValue[ uxIndexToNotify ] = ulValue; + break; + + case eSetValueWithoutOverwrite: + + if( ucOriginalNotifyState != taskNOTIFICATION_RECEIVED ) + { + pxTCB->ulNotifiedValue[ uxIndexToNotify ] = ulValue; + } + else + { + /* The value could not be written to the task. */ + xReturn = pdFAIL; + } + + break; + + case eNoAction: + + /* The task is being notified without its notify value being + * updated. */ + break; + + default: + + /* Should not get here if all enums are handled. + * Artificially force an assert by testing a value the + * compiler can't assume is const. */ + configASSERT( xTickCount == ( TickType_t ) 0 ); + + break; + } + + traceTASK_NOTIFY( uxIndexToNotify ); + + /* If the task is in the blocked state specifically to wait for a + * notification then unblock it now. */ + if( ucOriginalNotifyState == taskWAITING_NOTIFICATION ) + { + ( void ) uxListRemove( &( pxTCB->xStateListItem ) ); + prvAddTaskToReadyList( pxTCB ); + + /* The task should not have been on an event list. */ + configASSERT( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) == NULL ); + + #if ( configUSE_TICKLESS_IDLE != 0 ) + { + /* If a task is blocked waiting for a notification then + * xNextTaskUnblockTime might be set to the blocked task's time + * out time. If the task is unblocked for a reason other than + * a timeout xNextTaskUnblockTime is normally left unchanged, + * because it will automatically get reset to a new value when + * the tick count equals xNextTaskUnblockTime. However if + * tickless idling is used it might be more important to enter + * sleep mode at the earliest possible time - so reset + * xNextTaskUnblockTime here to ensure it is updated at the + * earliest possible time. */ + prvResetNextTaskUnblockTime(); + } + #endif + + if( pxTCB->uxPriority > pxCurrentTCB->uxPriority ) + { + /* The notified task has a priority above the currently + * executing task so a yield is required. */ + taskYIELD_IF_USING_PREEMPTION(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + taskEXIT_CRITICAL(); + + return xReturn; + } + +#endif /* configUSE_TASK_NOTIFICATIONS */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_TASK_NOTIFICATIONS == 1 ) + + BaseType_t xTaskGenericNotifyFromISR( TaskHandle_t xTaskToNotify, + UBaseType_t uxIndexToNotify, + uint32_t ulValue, + eNotifyAction eAction, + uint32_t * pulPreviousNotificationValue, + BaseType_t * pxHigherPriorityTaskWoken ) + { + TCB_t * pxTCB; + uint8_t ucOriginalNotifyState; + BaseType_t xReturn = pdPASS; + UBaseType_t uxSavedInterruptStatus; + + configASSERT( xTaskToNotify ); + configASSERT( uxIndexToNotify < configTASK_NOTIFICATION_ARRAY_ENTRIES ); + + /* RTOS ports that support interrupt nesting have the concept of a + * maximum system call (or maximum API call) interrupt priority. + * Interrupts that are above the maximum system call priority are keep + * permanently enabled, even when the RTOS kernel is in a critical section, + * but cannot make any calls to FreeRTOS API functions. If configASSERT() + * is defined in FreeRTOSConfig.h then + * portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion + * failure if a FreeRTOS API function is called from an interrupt that has + * been assigned a priority above the configured maximum system call + * priority. Only FreeRTOS functions that end in FromISR can be called + * from interrupts that have been assigned a priority at or (logically) + * below the maximum system call interrupt priority. FreeRTOS maintains a + * separate interrupt safe API to ensure interrupt entry is as fast and as + * simple as possible. More information (albeit Cortex-M specific) is + * provided on the following link: + * https://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html */ + portASSERT_IF_INTERRUPT_PRIORITY_INVALID(); + + pxTCB = xTaskToNotify; + + uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR(); + { + if( pulPreviousNotificationValue != NULL ) + { + *pulPreviousNotificationValue = pxTCB->ulNotifiedValue[ uxIndexToNotify ]; + } + + ucOriginalNotifyState = pxTCB->ucNotifyState[ uxIndexToNotify ]; + pxTCB->ucNotifyState[ uxIndexToNotify ] = taskNOTIFICATION_RECEIVED; + + switch( eAction ) + { + case eSetBits: + pxTCB->ulNotifiedValue[ uxIndexToNotify ] |= ulValue; + break; + + case eIncrement: + ( pxTCB->ulNotifiedValue[ uxIndexToNotify ] )++; + break; + + case eSetValueWithOverwrite: + pxTCB->ulNotifiedValue[ uxIndexToNotify ] = ulValue; + break; + + case eSetValueWithoutOverwrite: + + if( ucOriginalNotifyState != taskNOTIFICATION_RECEIVED ) + { + pxTCB->ulNotifiedValue[ uxIndexToNotify ] = ulValue; + } + else + { + /* The value could not be written to the task. */ + xReturn = pdFAIL; + } + + break; + + case eNoAction: + + /* The task is being notified without its notify value being + * updated. */ + break; + + default: + + /* Should not get here if all enums are handled. + * Artificially force an assert by testing a value the + * compiler can't assume is const. */ + configASSERT( xTickCount == ( TickType_t ) 0 ); + break; + } + + traceTASK_NOTIFY_FROM_ISR( uxIndexToNotify ); + + /* If the task is in the blocked state specifically to wait for a + * notification then unblock it now. */ + if( ucOriginalNotifyState == taskWAITING_NOTIFICATION ) + { + /* The task should not have been on an event list. */ + configASSERT( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) == NULL ); + + if( uxSchedulerSuspended == ( UBaseType_t ) pdFALSE ) + { + ( void ) uxListRemove( &( pxTCB->xStateListItem ) ); + prvAddTaskToReadyList( pxTCB ); + } + else + { + /* The delayed and ready lists cannot be accessed, so hold + * this task pending until the scheduler is resumed. */ + vListInsertEnd( &( xPendingReadyList ), &( pxTCB->xEventListItem ) ); + } + + if( pxTCB->uxPriority > pxCurrentTCB->uxPriority ) + { + /* The notified task has a priority above the currently + * executing task so a yield is required. */ + if( pxHigherPriorityTaskWoken != NULL ) + { + *pxHigherPriorityTaskWoken = pdTRUE; + } + + /* Mark that a yield is pending in case the user is not + * using the "xHigherPriorityTaskWoken" parameter to an ISR + * safe FreeRTOS function. */ + xYieldPending = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + } + portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); + + return xReturn; + } + +#endif /* configUSE_TASK_NOTIFICATIONS */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_TASK_NOTIFICATIONS == 1 ) + + void vTaskGenericNotifyGiveFromISR( TaskHandle_t xTaskToNotify, + UBaseType_t uxIndexToNotify, + BaseType_t * pxHigherPriorityTaskWoken ) + { + TCB_t * pxTCB; + uint8_t ucOriginalNotifyState; + UBaseType_t uxSavedInterruptStatus; + + configASSERT( xTaskToNotify ); + configASSERT( uxIndexToNotify < configTASK_NOTIFICATION_ARRAY_ENTRIES ); + + /* RTOS ports that support interrupt nesting have the concept of a + * maximum system call (or maximum API call) interrupt priority. + * Interrupts that are above the maximum system call priority are keep + * permanently enabled, even when the RTOS kernel is in a critical section, + * but cannot make any calls to FreeRTOS API functions. If configASSERT() + * is defined in FreeRTOSConfig.h then + * portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion + * failure if a FreeRTOS API function is called from an interrupt that has + * been assigned a priority above the configured maximum system call + * priority. Only FreeRTOS functions that end in FromISR can be called + * from interrupts that have been assigned a priority at or (logically) + * below the maximum system call interrupt priority. FreeRTOS maintains a + * separate interrupt safe API to ensure interrupt entry is as fast and as + * simple as possible. More information (albeit Cortex-M specific) is + * provided on the following link: + * https://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html */ + portASSERT_IF_INTERRUPT_PRIORITY_INVALID(); + + pxTCB = xTaskToNotify; + + uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR(); + { + ucOriginalNotifyState = pxTCB->ucNotifyState[ uxIndexToNotify ]; + pxTCB->ucNotifyState[ uxIndexToNotify ] = taskNOTIFICATION_RECEIVED; + + /* 'Giving' is equivalent to incrementing a count in a counting + * semaphore. */ + ( pxTCB->ulNotifiedValue[ uxIndexToNotify ] )++; + + traceTASK_NOTIFY_GIVE_FROM_ISR( uxIndexToNotify ); + + /* If the task is in the blocked state specifically to wait for a + * notification then unblock it now. */ + if( ucOriginalNotifyState == taskWAITING_NOTIFICATION ) + { + /* The task should not have been on an event list. */ + configASSERT( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) == NULL ); + + if( uxSchedulerSuspended == ( UBaseType_t ) pdFALSE ) + { + ( void ) uxListRemove( &( pxTCB->xStateListItem ) ); + prvAddTaskToReadyList( pxTCB ); + } + else + { + /* The delayed and ready lists cannot be accessed, so hold + * this task pending until the scheduler is resumed. */ + vListInsertEnd( &( xPendingReadyList ), &( pxTCB->xEventListItem ) ); + } + + if( pxTCB->uxPriority > pxCurrentTCB->uxPriority ) + { + /* The notified task has a priority above the currently + * executing task so a yield is required. */ + if( pxHigherPriorityTaskWoken != NULL ) + { + *pxHigherPriorityTaskWoken = pdTRUE; + } + + /* Mark that a yield is pending in case the user is not + * using the "xHigherPriorityTaskWoken" parameter in an ISR + * safe FreeRTOS function. */ + xYieldPending = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + } + portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); + } + +#endif /* configUSE_TASK_NOTIFICATIONS */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_TASK_NOTIFICATIONS == 1 ) + + BaseType_t xTaskGenericNotifyStateClear( TaskHandle_t xTask, + UBaseType_t uxIndexToClear ) + { + TCB_t * pxTCB; + BaseType_t xReturn; + + configASSERT( uxIndexToClear < configTASK_NOTIFICATION_ARRAY_ENTRIES ); + + /* If null is passed in here then it is the calling task that is having + * its notification state cleared. */ + pxTCB = prvGetTCBFromHandle( xTask ); + + taskENTER_CRITICAL(); + { + if( pxTCB->ucNotifyState[ uxIndexToClear ] == taskNOTIFICATION_RECEIVED ) + { + pxTCB->ucNotifyState[ uxIndexToClear ] = taskNOT_WAITING_NOTIFICATION; + xReturn = pdPASS; + } + else + { + xReturn = pdFAIL; + } + } + taskEXIT_CRITICAL(); + + return xReturn; + } + +#endif /* configUSE_TASK_NOTIFICATIONS */ +/*-----------------------------------------------------------*/ + +#if ( configUSE_TASK_NOTIFICATIONS == 1 ) + + uint32_t ulTaskGenericNotifyValueClear( TaskHandle_t xTask, + UBaseType_t uxIndexToClear, + uint32_t ulBitsToClear ) + { + TCB_t * pxTCB; + uint32_t ulReturn; + + /* If null is passed in here then it is the calling task that is having + * its notification state cleared. */ + pxTCB = prvGetTCBFromHandle( xTask ); + + taskENTER_CRITICAL(); + { + /* Return the notification as it was before the bits were cleared, + * then clear the bit mask. */ + ulReturn = pxTCB->ulNotifiedValue[ uxIndexToClear ]; + pxTCB->ulNotifiedValue[ uxIndexToClear ] &= ~ulBitsToClear; + } + taskEXIT_CRITICAL(); + + return ulReturn; + } + +#endif /* configUSE_TASK_NOTIFICATIONS */ +/*-----------------------------------------------------------*/ + +#if ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) ) + + uint32_t ulTaskGetIdleRunTimeCounter( void ) + { + return xIdleTaskHandle->ulRunTimeCounter; + } + +#endif +/*-----------------------------------------------------------*/ + +static void prvAddCurrentTaskToDelayedList( TickType_t xTicksToWait, + const BaseType_t xCanBlockIndefinitely ) +{ + TickType_t xTimeToWake; + const TickType_t xConstTickCount = xTickCount; + + #if ( INCLUDE_xTaskAbortDelay == 1 ) + { + /* About to enter a delayed list, so ensure the ucDelayAborted flag is + * reset to pdFALSE so it can be detected as having been set to pdTRUE + * when the task leaves the Blocked state. */ + pxCurrentTCB->ucDelayAborted = pdFALSE; + } + #endif + + /* Remove the task from the ready list before adding it to the blocked list + * as the same list item is used for both lists. */ + if( uxListRemove( &( pxCurrentTCB->xStateListItem ) ) == ( UBaseType_t ) 0 ) + { + /* The current task must be in a ready list, so there is no need to + * check, and the port reset macro can be called directly. */ + portRESET_READY_PRIORITY( pxCurrentTCB->uxPriority, uxTopReadyPriority ); /*lint !e931 pxCurrentTCB cannot change as it is the calling task. pxCurrentTCB->uxPriority and uxTopReadyPriority cannot change as called with scheduler suspended or in a critical section. */ + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + #if ( INCLUDE_vTaskSuspend == 1 ) + { + if( ( xTicksToWait == portMAX_DELAY ) && ( xCanBlockIndefinitely != pdFALSE ) ) + { + /* Add the task to the suspended task list instead of a delayed task + * list to ensure it is not woken by a timing event. It will block + * indefinitely. */ + vListInsertEnd( &xSuspendedTaskList, &( pxCurrentTCB->xStateListItem ) ); + } + else + { + /* Calculate the time at which the task should be woken if the event + * does not occur. This may overflow but this doesn't matter, the + * kernel will manage it correctly. */ + xTimeToWake = xConstTickCount + xTicksToWait; + + /* The list item will be inserted in wake time order. */ + listSET_LIST_ITEM_VALUE( &( pxCurrentTCB->xStateListItem ), xTimeToWake ); + + if( xTimeToWake < xConstTickCount ) + { + /* Wake time has overflowed. Place this item in the overflow + * list. */ + vListInsert( pxOverflowDelayedTaskList, &( pxCurrentTCB->xStateListItem ) ); + } + else + { + /* The wake time has not overflowed, so the current block list + * is used. */ + vListInsert( pxDelayedTaskList, &( pxCurrentTCB->xStateListItem ) ); + + /* If the task entering the blocked state was placed at the + * head of the list of blocked tasks then xNextTaskUnblockTime + * needs to be updated too. */ + if( xTimeToWake < xNextTaskUnblockTime ) + { + xNextTaskUnblockTime = xTimeToWake; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + } + } + #else /* INCLUDE_vTaskSuspend */ + { + /* Calculate the time at which the task should be woken if the event + * does not occur. This may overflow but this doesn't matter, the kernel + * will manage it correctly. */ + xTimeToWake = xConstTickCount + xTicksToWait; + + /* The list item will be inserted in wake time order. */ + listSET_LIST_ITEM_VALUE( &( pxCurrentTCB->xStateListItem ), xTimeToWake ); + + if( xTimeToWake < xConstTickCount ) + { + /* Wake time has overflowed. Place this item in the overflow list. */ + vListInsert( pxOverflowDelayedTaskList, &( pxCurrentTCB->xStateListItem ) ); + } + else + { + /* The wake time has not overflowed, so the current block list is used. */ + vListInsert( pxDelayedTaskList, &( pxCurrentTCB->xStateListItem ) ); + + /* If the task entering the blocked state was placed at the head of the + * list of blocked tasks then xNextTaskUnblockTime needs to be updated + * too. */ + if( xTimeToWake < xNextTaskUnblockTime ) + { + xNextTaskUnblockTime = xTimeToWake; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + + /* Avoid compiler warning when INCLUDE_vTaskSuspend is not 1. */ + ( void ) xCanBlockIndefinitely; + } + #endif /* INCLUDE_vTaskSuspend */ +} + +/* Code below here allows additional code to be inserted into this source file, + * especially where access to file scope functions and data is needed (for example + * when performing module tests). */ + +#ifdef FREERTOS_MODULE_TEST + #include "tasks_test_access_functions.h" +#endif + + +#if ( configINCLUDE_FREERTOS_TASK_C_ADDITIONS_H == 1 ) + + #include "freertos_tasks_c_additions.h" + + #ifdef FREERTOS_TASKS_C_ADDITIONS_INIT + static void freertos_tasks_c_additions_init( void ) + { + FREERTOS_TASKS_C_ADDITIONS_INIT(); + } + #endif + +#endif /* if ( configINCLUDE_FREERTOS_TASK_C_ADDITIONS_H == 1 ) */ diff --git a/RTOS/FreeRTOS/Source/timers.c b/RTOS/FreeRTOS/Source/timers.c new file mode 100644 index 0000000..d2e4f1c --- /dev/null +++ b/RTOS/FreeRTOS/Source/timers.c @@ -0,0 +1,1144 @@ +/* + * FreeRTOS Kernel V10.4.1 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * https://www.FreeRTOS.org + * https://github.com/FreeRTOS + * + */ + +/* Standard includes. */ +#include + +/* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining + * all the API functions to use the MPU wrappers. That should only be done when + * task.h is included from an application file. */ +#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE + +#include "FreeRTOS.h" +#include "task.h" +#include "queue.h" +#include "timers.h" + +#if ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 0 ) + #error configUSE_TIMERS must be set to 1 to make the xTimerPendFunctionCall() function available. +#endif + +/* Lint e9021, e961 and e750 are suppressed as a MISRA exception justified + * because the MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be defined + * for the header files above, but not in this file, in order to generate the + * correct privileged Vs unprivileged linkage and placement. */ +#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE /*lint !e9021 !e961 !e750. */ + + +/* This entire source file will be skipped if the application is not configured + * to include software timer functionality. This #if is closed at the very bottom + * of this file. If you want to include software timer functionality then ensure + * configUSE_TIMERS is set to 1 in FreeRTOSConfig.h. */ +#if ( configUSE_TIMERS == 1 ) + +/* Misc definitions. */ + #define tmrNO_DELAY ( TickType_t ) 0U + +/* The name assigned to the timer service task. This can be overridden by + * defining trmTIMER_SERVICE_TASK_NAME in FreeRTOSConfig.h. */ + #ifndef configTIMER_SERVICE_TASK_NAME + #define configTIMER_SERVICE_TASK_NAME "Tmr Svc" + #endif + +/* Bit definitions used in the ucStatus member of a timer structure. */ + #define tmrSTATUS_IS_ACTIVE ( ( uint8_t ) 0x01 ) + #define tmrSTATUS_IS_STATICALLY_ALLOCATED ( ( uint8_t ) 0x02 ) + #define tmrSTATUS_IS_AUTORELOAD ( ( uint8_t ) 0x04 ) + +/* The definition of the timers themselves. */ + typedef struct tmrTimerControl /* The old naming convention is used to prevent breaking kernel aware debuggers. */ + { + const char * pcTimerName; /*<< Text name. This is not used by the kernel, it is included simply to make debugging easier. */ /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + ListItem_t xTimerListItem; /*<< Standard linked list item as used by all kernel features for event management. */ + TickType_t xTimerPeriodInTicks; /*<< How quickly and often the timer expires. */ + void * pvTimerID; /*<< An ID to identify the timer. This allows the timer to be identified when the same callback is used for multiple timers. */ + TimerCallbackFunction_t pxCallbackFunction; /*<< The function that will be called when the timer expires. */ + #if ( configUSE_TRACE_FACILITY == 1 ) + UBaseType_t uxTimerNumber; /*<< An ID assigned by trace tools such as FreeRTOS+Trace */ + #endif + uint8_t ucStatus; /*<< Holds bits to say if the timer was statically allocated or not, and if it is active or not. */ + } xTIMER; + +/* The old xTIMER name is maintained above then typedefed to the new Timer_t + * name below to enable the use of older kernel aware debuggers. */ + typedef xTIMER Timer_t; + +/* The definition of messages that can be sent and received on the timer queue. + * Two types of message can be queued - messages that manipulate a software timer, + * and messages that request the execution of a non-timer related callback. The + * two message types are defined in two separate structures, xTimerParametersType + * and xCallbackParametersType respectively. */ + typedef struct tmrTimerParameters + { + TickType_t xMessageValue; /*<< An optional value used by a subset of commands, for example, when changing the period of a timer. */ + Timer_t * pxTimer; /*<< The timer to which the command will be applied. */ + } TimerParameter_t; + + + typedef struct tmrCallbackParameters + { + PendedFunction_t pxCallbackFunction; /* << The callback function to execute. */ + void * pvParameter1; /* << The value that will be used as the callback functions first parameter. */ + uint32_t ulParameter2; /* << The value that will be used as the callback functions second parameter. */ + } CallbackParameters_t; + +/* The structure that contains the two message types, along with an identifier + * that is used to determine which message type is valid. */ + typedef struct tmrTimerQueueMessage + { + BaseType_t xMessageID; /*<< The command being sent to the timer service task. */ + union + { + TimerParameter_t xTimerParameters; + + /* Don't include xCallbackParameters if it is not going to be used as + * it makes the structure (and therefore the timer queue) larger. */ + #if ( INCLUDE_xTimerPendFunctionCall == 1 ) + CallbackParameters_t xCallbackParameters; + #endif /* INCLUDE_xTimerPendFunctionCall */ + } u; + } DaemonTaskMessage_t; + +/*lint -save -e956 A manual analysis and inspection has been used to determine + * which static variables must be declared volatile. */ + +/* The list in which active timers are stored. Timers are referenced in expire + * time order, with the nearest expiry time at the front of the list. Only the + * timer service task is allowed to access these lists. + * xActiveTimerList1 and xActiveTimerList2 could be at function scope but that + * breaks some kernel aware debuggers, and debuggers that reply on removing the + * static qualifier. */ + PRIVILEGED_DATA static List_t xActiveTimerList1; + PRIVILEGED_DATA static List_t xActiveTimerList2; + PRIVILEGED_DATA static List_t * pxCurrentTimerList; + PRIVILEGED_DATA static List_t * pxOverflowTimerList; + +/* A queue that is used to send commands to the timer service task. */ + PRIVILEGED_DATA static QueueHandle_t xTimerQueue = NULL; + PRIVILEGED_DATA static TaskHandle_t xTimerTaskHandle = NULL; + +/*lint -restore */ + +/*-----------------------------------------------------------*/ + +/* + * Initialise the infrastructure used by the timer service task if it has not + * been initialised already. + */ + static void prvCheckForValidListAndQueue( void ) PRIVILEGED_FUNCTION; + +/* + * The timer service task (daemon). Timer functionality is controlled by this + * task. Other tasks communicate with the timer service task using the + * xTimerQueue queue. + */ + static portTASK_FUNCTION_PROTO( prvTimerTask, pvParameters ) PRIVILEGED_FUNCTION; + +/* + * Called by the timer service task to interpret and process a command it + * received on the timer queue. + */ + static void prvProcessReceivedCommands( void ) PRIVILEGED_FUNCTION; + +/* + * Insert the timer into either xActiveTimerList1, or xActiveTimerList2, + * depending on if the expire time causes a timer counter overflow. + */ + static BaseType_t prvInsertTimerInActiveList( Timer_t * const pxTimer, + const TickType_t xNextExpiryTime, + const TickType_t xTimeNow, + const TickType_t xCommandTime ) PRIVILEGED_FUNCTION; + +/* + * An active timer has reached its expire time. Reload the timer if it is an + * auto-reload timer, then call its callback. + */ + static void prvProcessExpiredTimer( const TickType_t xNextExpireTime, + const TickType_t xTimeNow ) PRIVILEGED_FUNCTION; + +/* + * The tick count has overflowed. Switch the timer lists after ensuring the + * current timer list does not still reference some timers. + */ + static void prvSwitchTimerLists( void ) PRIVILEGED_FUNCTION; + +/* + * Obtain the current tick count, setting *pxTimerListsWereSwitched to pdTRUE + * if a tick count overflow occurred since prvSampleTimeNow() was last called. + */ + static TickType_t prvSampleTimeNow( BaseType_t * const pxTimerListsWereSwitched ) PRIVILEGED_FUNCTION; + +/* + * If the timer list contains any active timers then return the expire time of + * the timer that will expire first and set *pxListWasEmpty to false. If the + * timer list does not contain any timers then return 0 and set *pxListWasEmpty + * to pdTRUE. + */ + static TickType_t prvGetNextExpireTime( BaseType_t * const pxListWasEmpty ) PRIVILEGED_FUNCTION; + +/* + * If a timer has expired, process it. Otherwise, block the timer service task + * until either a timer does expire or a command is received. + */ + static void prvProcessTimerOrBlockTask( const TickType_t xNextExpireTime, + BaseType_t xListWasEmpty ) PRIVILEGED_FUNCTION; + +/* + * Called after a Timer_t structure has been allocated either statically or + * dynamically to fill in the structure's members. + */ + static void prvInitialiseNewTimer( const char * const pcTimerName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + const TickType_t xTimerPeriodInTicks, + const UBaseType_t uxAutoReload, + void * const pvTimerID, + TimerCallbackFunction_t pxCallbackFunction, + Timer_t * pxNewTimer ) PRIVILEGED_FUNCTION; +/*-----------------------------------------------------------*/ + + BaseType_t xTimerCreateTimerTask( void ) + { + BaseType_t xReturn = pdFAIL; + + /* This function is called when the scheduler is started if + * configUSE_TIMERS is set to 1. Check that the infrastructure used by the + * timer service task has been created/initialised. If timers have already + * been created then the initialisation will already have been performed. */ + prvCheckForValidListAndQueue(); + + if( xTimerQueue != NULL ) + { + #if ( configSUPPORT_STATIC_ALLOCATION == 1 ) + { + StaticTask_t * pxTimerTaskTCBBuffer = NULL; + StackType_t * pxTimerTaskStackBuffer = NULL; + uint32_t ulTimerTaskStackSize; + + vApplicationGetTimerTaskMemory( &pxTimerTaskTCBBuffer, &pxTimerTaskStackBuffer, &ulTimerTaskStackSize ); + xTimerTaskHandle = xTaskCreateStatic( prvTimerTask, + configTIMER_SERVICE_TASK_NAME, + ulTimerTaskStackSize, + NULL, + ( ( UBaseType_t ) configTIMER_TASK_PRIORITY ) | portPRIVILEGE_BIT, + pxTimerTaskStackBuffer, + pxTimerTaskTCBBuffer ); + + if( xTimerTaskHandle != NULL ) + { + xReturn = pdPASS; + } + } + #else /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */ + { + xReturn = xTaskCreate( prvTimerTask, + configTIMER_SERVICE_TASK_NAME, + configTIMER_TASK_STACK_DEPTH, + NULL, + ( ( UBaseType_t ) configTIMER_TASK_PRIORITY ) | portPRIVILEGE_BIT, + &xTimerTaskHandle ); + } + #endif /* configSUPPORT_STATIC_ALLOCATION */ + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + configASSERT( xReturn ); + return xReturn; + } +/*-----------------------------------------------------------*/ + + #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + + TimerHandle_t xTimerCreate( const char * const pcTimerName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + const TickType_t xTimerPeriodInTicks, + const UBaseType_t uxAutoReload, + void * const pvTimerID, + TimerCallbackFunction_t pxCallbackFunction ) + { + Timer_t * pxNewTimer; + + pxNewTimer = ( Timer_t * ) pvPortMalloc( sizeof( Timer_t ) ); /*lint !e9087 !e9079 All values returned by pvPortMalloc() have at least the alignment required by the MCU's stack, and the first member of Timer_t is always a pointer to the timer's mame. */ + + if( pxNewTimer != NULL ) + { + /* Status is thus far zero as the timer is not created statically + * and has not been started. The auto-reload bit may get set in + * prvInitialiseNewTimer. */ + pxNewTimer->ucStatus = 0x00; + prvInitialiseNewTimer( pcTimerName, xTimerPeriodInTicks, uxAutoReload, pvTimerID, pxCallbackFunction, pxNewTimer ); + } + + return pxNewTimer; + } + + #endif /* configSUPPORT_DYNAMIC_ALLOCATION */ +/*-----------------------------------------------------------*/ + + #if ( configSUPPORT_STATIC_ALLOCATION == 1 ) + + TimerHandle_t xTimerCreateStatic( const char * const pcTimerName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + const TickType_t xTimerPeriodInTicks, + const UBaseType_t uxAutoReload, + void * const pvTimerID, + TimerCallbackFunction_t pxCallbackFunction, + StaticTimer_t * pxTimerBuffer ) + { + Timer_t * pxNewTimer; + + #if ( configASSERT_DEFINED == 1 ) + { + /* Sanity check that the size of the structure used to declare a + * variable of type StaticTimer_t equals the size of the real timer + * structure. */ + volatile size_t xSize = sizeof( StaticTimer_t ); + configASSERT( xSize == sizeof( Timer_t ) ); + ( void ) xSize; /* Keeps lint quiet when configASSERT() is not defined. */ + } + #endif /* configASSERT_DEFINED */ + + /* A pointer to a StaticTimer_t structure MUST be provided, use it. */ + configASSERT( pxTimerBuffer ); + pxNewTimer = ( Timer_t * ) pxTimerBuffer; /*lint !e740 !e9087 StaticTimer_t is a pointer to a Timer_t, so guaranteed to be aligned and sized correctly (checked by an assert()), so this is safe. */ + + if( pxNewTimer != NULL ) + { + /* Timers can be created statically or dynamically so note this + * timer was created statically in case it is later deleted. The + * auto-reload bit may get set in prvInitialiseNewTimer(). */ + pxNewTimer->ucStatus = tmrSTATUS_IS_STATICALLY_ALLOCATED; + + prvInitialiseNewTimer( pcTimerName, xTimerPeriodInTicks, uxAutoReload, pvTimerID, pxCallbackFunction, pxNewTimer ); + } + + return pxNewTimer; + } + + #endif /* configSUPPORT_STATIC_ALLOCATION */ +/*-----------------------------------------------------------*/ + + static void prvInitialiseNewTimer( const char * const pcTimerName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + const TickType_t xTimerPeriodInTicks, + const UBaseType_t uxAutoReload, + void * const pvTimerID, + TimerCallbackFunction_t pxCallbackFunction, + Timer_t * pxNewTimer ) + { + /* 0 is not a valid value for xTimerPeriodInTicks. */ + configASSERT( ( xTimerPeriodInTicks > 0 ) ); + + if( pxNewTimer != NULL ) + { + /* Ensure the infrastructure used by the timer service task has been + * created/initialised. */ + prvCheckForValidListAndQueue(); + + /* Initialise the timer structure members using the function + * parameters. */ + pxNewTimer->pcTimerName = pcTimerName; + pxNewTimer->xTimerPeriodInTicks = xTimerPeriodInTicks; + pxNewTimer->pvTimerID = pvTimerID; + pxNewTimer->pxCallbackFunction = pxCallbackFunction; + vListInitialiseItem( &( pxNewTimer->xTimerListItem ) ); + + if( uxAutoReload != pdFALSE ) + { + pxNewTimer->ucStatus |= tmrSTATUS_IS_AUTORELOAD; + } + + traceTIMER_CREATE( pxNewTimer ); + } + } +/*-----------------------------------------------------------*/ + + BaseType_t xTimerGenericCommand( TimerHandle_t xTimer, + const BaseType_t xCommandID, + const TickType_t xOptionalValue, + BaseType_t * const pxHigherPriorityTaskWoken, + const TickType_t xTicksToWait ) + { + BaseType_t xReturn = pdFAIL; + DaemonTaskMessage_t xMessage; + + configASSERT( xTimer ); + + /* Send a message to the timer service task to perform a particular action + * on a particular timer definition. */ + if( xTimerQueue != NULL ) + { + /* Send a command to the timer service task to start the xTimer timer. */ + xMessage.xMessageID = xCommandID; + xMessage.u.xTimerParameters.xMessageValue = xOptionalValue; + xMessage.u.xTimerParameters.pxTimer = xTimer; + + if( xCommandID < tmrFIRST_FROM_ISR_COMMAND ) + { + if( xTaskGetSchedulerState() == taskSCHEDULER_RUNNING ) + { + xReturn = xQueueSendToBack( xTimerQueue, &xMessage, xTicksToWait ); + } + else + { + xReturn = xQueueSendToBack( xTimerQueue, &xMessage, tmrNO_DELAY ); + } + } + else + { + xReturn = xQueueSendToBackFromISR( xTimerQueue, &xMessage, pxHigherPriorityTaskWoken ); + } + + traceTIMER_COMMAND_SEND( xTimer, xCommandID, xOptionalValue, xReturn ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + return xReturn; + } +/*-----------------------------------------------------------*/ + + TaskHandle_t xTimerGetTimerDaemonTaskHandle( void ) + { + /* If xTimerGetTimerDaemonTaskHandle() is called before the scheduler has been + * started, then xTimerTaskHandle will be NULL. */ + configASSERT( ( xTimerTaskHandle != NULL ) ); + return xTimerTaskHandle; + } +/*-----------------------------------------------------------*/ + + TickType_t xTimerGetPeriod( TimerHandle_t xTimer ) + { + Timer_t * pxTimer = xTimer; + + configASSERT( xTimer ); + return pxTimer->xTimerPeriodInTicks; + } +/*-----------------------------------------------------------*/ + + void vTimerSetReloadMode( TimerHandle_t xTimer, + const UBaseType_t uxAutoReload ) + { + Timer_t * pxTimer = xTimer; + + configASSERT( xTimer ); + taskENTER_CRITICAL(); + { + if( uxAutoReload != pdFALSE ) + { + pxTimer->ucStatus |= tmrSTATUS_IS_AUTORELOAD; + } + else + { + pxTimer->ucStatus &= ~tmrSTATUS_IS_AUTORELOAD; + } + } + taskEXIT_CRITICAL(); + } +/*-----------------------------------------------------------*/ + + UBaseType_t uxTimerGetReloadMode( TimerHandle_t xTimer ) + { + Timer_t * pxTimer = xTimer; + UBaseType_t uxReturn; + + configASSERT( xTimer ); + taskENTER_CRITICAL(); + { + if( ( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) == 0 ) + { + /* Not an auto-reload timer. */ + uxReturn = ( UBaseType_t ) pdFALSE; + } + else + { + /* Is an auto-reload timer. */ + uxReturn = ( UBaseType_t ) pdTRUE; + } + } + taskEXIT_CRITICAL(); + + return uxReturn; + } +/*-----------------------------------------------------------*/ + + TickType_t xTimerGetExpiryTime( TimerHandle_t xTimer ) + { + Timer_t * pxTimer = xTimer; + TickType_t xReturn; + + configASSERT( xTimer ); + xReturn = listGET_LIST_ITEM_VALUE( &( pxTimer->xTimerListItem ) ); + return xReturn; + } +/*-----------------------------------------------------------*/ + + const char * pcTimerGetName( TimerHandle_t xTimer ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ + { + Timer_t * pxTimer = xTimer; + + configASSERT( xTimer ); + return pxTimer->pcTimerName; + } +/*-----------------------------------------------------------*/ + + static void prvProcessExpiredTimer( const TickType_t xNextExpireTime, + const TickType_t xTimeNow ) + { + BaseType_t xResult; + Timer_t * const pxTimer = ( Timer_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxCurrentTimerList ); /*lint !e9087 !e9079 void * is used as this macro is used with tasks and co-routines too. Alignment is known to be fine as the type of the pointer stored and retrieved is the same. */ + + /* Remove the timer from the list of active timers. A check has already + * been performed to ensure the list is not empty. */ + + ( void ) uxListRemove( &( pxTimer->xTimerListItem ) ); + traceTIMER_EXPIRED( pxTimer ); + + /* If the timer is an auto-reload timer then calculate the next + * expiry time and re-insert the timer in the list of active timers. */ + if( ( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) != 0 ) + { + /* The timer is inserted into a list using a time relative to anything + * other than the current time. It will therefore be inserted into the + * correct list relative to the time this task thinks it is now. */ + if( prvInsertTimerInActiveList( pxTimer, ( xNextExpireTime + pxTimer->xTimerPeriodInTicks ), xTimeNow, xNextExpireTime ) != pdFALSE ) + { + /* The timer expired before it was added to the active timer + * list. Reload it now. */ + xResult = xTimerGenericCommand( pxTimer, tmrCOMMAND_START_DONT_TRACE, xNextExpireTime, NULL, tmrNO_DELAY ); + configASSERT( xResult ); + ( void ) xResult; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + pxTimer->ucStatus &= ~tmrSTATUS_IS_ACTIVE; + mtCOVERAGE_TEST_MARKER(); + } + + /* Call the timer callback. */ + pxTimer->pxCallbackFunction( ( TimerHandle_t ) pxTimer ); + } +/*-----------------------------------------------------------*/ + + static portTASK_FUNCTION( prvTimerTask, pvParameters ) + { + TickType_t xNextExpireTime; + BaseType_t xListWasEmpty; + + /* Just to avoid compiler warnings. */ + ( void ) pvParameters; + + #if ( configUSE_DAEMON_TASK_STARTUP_HOOK == 1 ) + { + extern void vApplicationDaemonTaskStartupHook( void ); + + /* Allow the application writer to execute some code in the context of + * this task at the point the task starts executing. This is useful if the + * application includes initialisation code that would benefit from + * executing after the scheduler has been started. */ + vApplicationDaemonTaskStartupHook(); + } + #endif /* configUSE_DAEMON_TASK_STARTUP_HOOK */ + + for( ; ; ) + { + /* Query the timers list to see if it contains any timers, and if so, + * obtain the time at which the next timer will expire. */ + xNextExpireTime = prvGetNextExpireTime( &xListWasEmpty ); + + /* If a timer has expired, process it. Otherwise, block this task + * until either a timer does expire, or a command is received. */ + prvProcessTimerOrBlockTask( xNextExpireTime, xListWasEmpty ); + + /* Empty the command queue. */ + prvProcessReceivedCommands(); + } + } +/*-----------------------------------------------------------*/ + + static void prvProcessTimerOrBlockTask( const TickType_t xNextExpireTime, + BaseType_t xListWasEmpty ) + { + TickType_t xTimeNow; + BaseType_t xTimerListsWereSwitched; + + vTaskSuspendAll(); + { + /* Obtain the time now to make an assessment as to whether the timer + * has expired or not. If obtaining the time causes the lists to switch + * then don't process this timer as any timers that remained in the list + * when the lists were switched will have been processed within the + * prvSampleTimeNow() function. */ + xTimeNow = prvSampleTimeNow( &xTimerListsWereSwitched ); + + if( xTimerListsWereSwitched == pdFALSE ) + { + /* The tick count has not overflowed, has the timer expired? */ + if( ( xListWasEmpty == pdFALSE ) && ( xNextExpireTime <= xTimeNow ) ) + { + ( void ) xTaskResumeAll(); + prvProcessExpiredTimer( xNextExpireTime, xTimeNow ); + } + else + { + /* The tick count has not overflowed, and the next expire + * time has not been reached yet. This task should therefore + * block to wait for the next expire time or a command to be + * received - whichever comes first. The following line cannot + * be reached unless xNextExpireTime > xTimeNow, except in the + * case when the current timer list is empty. */ + if( xListWasEmpty != pdFALSE ) + { + /* The current timer list is empty - is the overflow list + * also empty? */ + xListWasEmpty = listLIST_IS_EMPTY( pxOverflowTimerList ); + } + + vQueueWaitForMessageRestricted( xTimerQueue, ( xNextExpireTime - xTimeNow ), xListWasEmpty ); + + if( xTaskResumeAll() == pdFALSE ) + { + /* Yield to wait for either a command to arrive, or the + * block time to expire. If a command arrived between the + * critical section being exited and this yield then the yield + * will not cause the task to block. */ + portYIELD_WITHIN_API(); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + } + else + { + ( void ) xTaskResumeAll(); + } + } + } +/*-----------------------------------------------------------*/ + + static TickType_t prvGetNextExpireTime( BaseType_t * const pxListWasEmpty ) + { + TickType_t xNextExpireTime; + + /* Timers are listed in expiry time order, with the head of the list + * referencing the task that will expire first. Obtain the time at which + * the timer with the nearest expiry time will expire. If there are no + * active timers then just set the next expire time to 0. That will cause + * this task to unblock when the tick count overflows, at which point the + * timer lists will be switched and the next expiry time can be + * re-assessed. */ + *pxListWasEmpty = listLIST_IS_EMPTY( pxCurrentTimerList ); + + if( *pxListWasEmpty == pdFALSE ) + { + xNextExpireTime = listGET_ITEM_VALUE_OF_HEAD_ENTRY( pxCurrentTimerList ); + } + else + { + /* Ensure the task unblocks when the tick count rolls over. */ + xNextExpireTime = ( TickType_t ) 0U; + } + + return xNextExpireTime; + } +/*-----------------------------------------------------------*/ + + static TickType_t prvSampleTimeNow( BaseType_t * const pxTimerListsWereSwitched ) + { + TickType_t xTimeNow; + PRIVILEGED_DATA static TickType_t xLastTime = ( TickType_t ) 0U; /*lint !e956 Variable is only accessible to one task. */ + + xTimeNow = xTaskGetTickCount(); + + if( xTimeNow < xLastTime ) + { + prvSwitchTimerLists(); + *pxTimerListsWereSwitched = pdTRUE; + } + else + { + *pxTimerListsWereSwitched = pdFALSE; + } + + xLastTime = xTimeNow; + + return xTimeNow; + } +/*-----------------------------------------------------------*/ + + static BaseType_t prvInsertTimerInActiveList( Timer_t * const pxTimer, + const TickType_t xNextExpiryTime, + const TickType_t xTimeNow, + const TickType_t xCommandTime ) + { + BaseType_t xProcessTimerNow = pdFALSE; + + listSET_LIST_ITEM_VALUE( &( pxTimer->xTimerListItem ), xNextExpiryTime ); + listSET_LIST_ITEM_OWNER( &( pxTimer->xTimerListItem ), pxTimer ); + + if( xNextExpiryTime <= xTimeNow ) + { + /* Has the expiry time elapsed between the command to start/reset a + * timer was issued, and the time the command was processed? */ + if( ( ( TickType_t ) ( xTimeNow - xCommandTime ) ) >= pxTimer->xTimerPeriodInTicks ) /*lint !e961 MISRA exception as the casts are only redundant for some ports. */ + { + /* The time between a command being issued and the command being + * processed actually exceeds the timers period. */ + xProcessTimerNow = pdTRUE; + } + else + { + vListInsert( pxOverflowTimerList, &( pxTimer->xTimerListItem ) ); + } + } + else + { + if( ( xTimeNow < xCommandTime ) && ( xNextExpiryTime >= xCommandTime ) ) + { + /* If, since the command was issued, the tick count has overflowed + * but the expiry time has not, then the timer must have already passed + * its expiry time and should be processed immediately. */ + xProcessTimerNow = pdTRUE; + } + else + { + vListInsert( pxCurrentTimerList, &( pxTimer->xTimerListItem ) ); + } + } + + return xProcessTimerNow; + } +/*-----------------------------------------------------------*/ + + static void prvProcessReceivedCommands( void ) + { + DaemonTaskMessage_t xMessage; + Timer_t * pxTimer; + BaseType_t xTimerListsWereSwitched, xResult; + TickType_t xTimeNow; + + while( xQueueReceive( xTimerQueue, &xMessage, tmrNO_DELAY ) != pdFAIL ) /*lint !e603 xMessage does not have to be initialised as it is passed out, not in, and it is not used unless xQueueReceive() returns pdTRUE. */ + { + #if ( INCLUDE_xTimerPendFunctionCall == 1 ) + { + /* Negative commands are pended function calls rather than timer + * commands. */ + if( xMessage.xMessageID < ( BaseType_t ) 0 ) + { + const CallbackParameters_t * const pxCallback = &( xMessage.u.xCallbackParameters ); + + /* The timer uses the xCallbackParameters member to request a + * callback be executed. Check the callback is not NULL. */ + configASSERT( pxCallback ); + + /* Call the function. */ + pxCallback->pxCallbackFunction( pxCallback->pvParameter1, pxCallback->ulParameter2 ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + #endif /* INCLUDE_xTimerPendFunctionCall */ + + /* Commands that are positive are timer commands rather than pended + * function calls. */ + if( xMessage.xMessageID >= ( BaseType_t ) 0 ) + { + /* The messages uses the xTimerParameters member to work on a + * software timer. */ + pxTimer = xMessage.u.xTimerParameters.pxTimer; + + if( listIS_CONTAINED_WITHIN( NULL, &( pxTimer->xTimerListItem ) ) == pdFALSE ) /*lint !e961. The cast is only redundant when NULL is passed into the macro. */ + { + /* The timer is in a list, remove it. */ + ( void ) uxListRemove( &( pxTimer->xTimerListItem ) ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + traceTIMER_COMMAND_RECEIVED( pxTimer, xMessage.xMessageID, xMessage.u.xTimerParameters.xMessageValue ); + + /* In this case the xTimerListsWereSwitched parameter is not used, but + * it must be present in the function call. prvSampleTimeNow() must be + * called after the message is received from xTimerQueue so there is no + * possibility of a higher priority task adding a message to the message + * queue with a time that is ahead of the timer daemon task (because it + * pre-empted the timer daemon task after the xTimeNow value was set). */ + xTimeNow = prvSampleTimeNow( &xTimerListsWereSwitched ); + + switch( xMessage.xMessageID ) + { + case tmrCOMMAND_START: + case tmrCOMMAND_START_FROM_ISR: + case tmrCOMMAND_RESET: + case tmrCOMMAND_RESET_FROM_ISR: + case tmrCOMMAND_START_DONT_TRACE: + /* Start or restart a timer. */ + pxTimer->ucStatus |= tmrSTATUS_IS_ACTIVE; + + if( prvInsertTimerInActiveList( pxTimer, xMessage.u.xTimerParameters.xMessageValue + pxTimer->xTimerPeriodInTicks, xTimeNow, xMessage.u.xTimerParameters.xMessageValue ) != pdFALSE ) + { + /* The timer expired before it was added to the active + * timer list. Process it now. */ + pxTimer->pxCallbackFunction( ( TimerHandle_t ) pxTimer ); + traceTIMER_EXPIRED( pxTimer ); + + if( ( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) != 0 ) + { + xResult = xTimerGenericCommand( pxTimer, tmrCOMMAND_START_DONT_TRACE, xMessage.u.xTimerParameters.xMessageValue + pxTimer->xTimerPeriodInTicks, NULL, tmrNO_DELAY ); + configASSERT( xResult ); + ( void ) xResult; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + + break; + + case tmrCOMMAND_STOP: + case tmrCOMMAND_STOP_FROM_ISR: + /* The timer has already been removed from the active list. */ + pxTimer->ucStatus &= ~tmrSTATUS_IS_ACTIVE; + break; + + case tmrCOMMAND_CHANGE_PERIOD: + case tmrCOMMAND_CHANGE_PERIOD_FROM_ISR: + pxTimer->ucStatus |= tmrSTATUS_IS_ACTIVE; + pxTimer->xTimerPeriodInTicks = xMessage.u.xTimerParameters.xMessageValue; + configASSERT( ( pxTimer->xTimerPeriodInTicks > 0 ) ); + + /* The new period does not really have a reference, and can + * be longer or shorter than the old one. The command time is + * therefore set to the current time, and as the period cannot + * be zero the next expiry time can only be in the future, + * meaning (unlike for the xTimerStart() case above) there is + * no fail case that needs to be handled here. */ + ( void ) prvInsertTimerInActiveList( pxTimer, ( xTimeNow + pxTimer->xTimerPeriodInTicks ), xTimeNow, xTimeNow ); + break; + + case tmrCOMMAND_DELETE: + #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + { + /* The timer has already been removed from the active list, + * just free up the memory if the memory was dynamically + * allocated. */ + if( ( pxTimer->ucStatus & tmrSTATUS_IS_STATICALLY_ALLOCATED ) == ( uint8_t ) 0 ) + { + vPortFree( pxTimer ); + } + else + { + pxTimer->ucStatus &= ~tmrSTATUS_IS_ACTIVE; + } + } + #else /* if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) */ + { + /* If dynamic allocation is not enabled, the memory + * could not have been dynamically allocated. So there is + * no need to free the memory - just mark the timer as + * "not active". */ + pxTimer->ucStatus &= ~tmrSTATUS_IS_ACTIVE; + } + #endif /* configSUPPORT_DYNAMIC_ALLOCATION */ + break; + + default: + /* Don't expect to get here. */ + break; + } + } + } + } +/*-----------------------------------------------------------*/ + + static void prvSwitchTimerLists( void ) + { + TickType_t xNextExpireTime, xReloadTime; + List_t * pxTemp; + Timer_t * pxTimer; + BaseType_t xResult; + + /* The tick count has overflowed. The timer lists must be switched. + * If there are any timers still referenced from the current timer list + * then they must have expired and should be processed before the lists + * are switched. */ + while( listLIST_IS_EMPTY( pxCurrentTimerList ) == pdFALSE ) + { + xNextExpireTime = listGET_ITEM_VALUE_OF_HEAD_ENTRY( pxCurrentTimerList ); + + /* Remove the timer from the list. */ + pxTimer = ( Timer_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxCurrentTimerList ); /*lint !e9087 !e9079 void * is used as this macro is used with tasks and co-routines too. Alignment is known to be fine as the type of the pointer stored and retrieved is the same. */ + ( void ) uxListRemove( &( pxTimer->xTimerListItem ) ); + traceTIMER_EXPIRED( pxTimer ); + + /* Execute its callback, then send a command to restart the timer if + * it is an auto-reload timer. It cannot be restarted here as the lists + * have not yet been switched. */ + pxTimer->pxCallbackFunction( ( TimerHandle_t ) pxTimer ); + + if( ( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) != 0 ) + { + /* Calculate the reload value, and if the reload value results in + * the timer going into the same timer list then it has already expired + * and the timer should be re-inserted into the current list so it is + * processed again within this loop. Otherwise a command should be sent + * to restart the timer to ensure it is only inserted into a list after + * the lists have been swapped. */ + xReloadTime = ( xNextExpireTime + pxTimer->xTimerPeriodInTicks ); + + if( xReloadTime > xNextExpireTime ) + { + listSET_LIST_ITEM_VALUE( &( pxTimer->xTimerListItem ), xReloadTime ); + listSET_LIST_ITEM_OWNER( &( pxTimer->xTimerListItem ), pxTimer ); + vListInsert( pxCurrentTimerList, &( pxTimer->xTimerListItem ) ); + } + else + { + xResult = xTimerGenericCommand( pxTimer, tmrCOMMAND_START_DONT_TRACE, xNextExpireTime, NULL, tmrNO_DELAY ); + configASSERT( xResult ); + ( void ) xResult; + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + + pxTemp = pxCurrentTimerList; + pxCurrentTimerList = pxOverflowTimerList; + pxOverflowTimerList = pxTemp; + } +/*-----------------------------------------------------------*/ + + static void prvCheckForValidListAndQueue( void ) + { + /* Check that the list from which active timers are referenced, and the + * queue used to communicate with the timer service, have been + * initialised. */ + taskENTER_CRITICAL(); + { + if( xTimerQueue == NULL ) + { + vListInitialise( &xActiveTimerList1 ); + vListInitialise( &xActiveTimerList2 ); + pxCurrentTimerList = &xActiveTimerList1; + pxOverflowTimerList = &xActiveTimerList2; + + #if ( configSUPPORT_STATIC_ALLOCATION == 1 ) + { + /* The timer queue is allocated statically in case + * configSUPPORT_DYNAMIC_ALLOCATION is 0. */ + PRIVILEGED_DATA static StaticQueue_t xStaticTimerQueue; /*lint !e956 Ok to declare in this manner to prevent additional conditional compilation guards in other locations. */ + PRIVILEGED_DATA static uint8_t ucStaticTimerQueueStorage[ ( size_t ) configTIMER_QUEUE_LENGTH * sizeof( DaemonTaskMessage_t ) ]; /*lint !e956 Ok to declare in this manner to prevent additional conditional compilation guards in other locations. */ + + xTimerQueue = xQueueCreateStatic( ( UBaseType_t ) configTIMER_QUEUE_LENGTH, ( UBaseType_t ) sizeof( DaemonTaskMessage_t ), &( ucStaticTimerQueueStorage[ 0 ] ), &xStaticTimerQueue ); + } + #else + { + xTimerQueue = xQueueCreate( ( UBaseType_t ) configTIMER_QUEUE_LENGTH, sizeof( DaemonTaskMessage_t ) ); + } + #endif /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */ + + #if ( configQUEUE_REGISTRY_SIZE > 0 ) + { + if( xTimerQueue != NULL ) + { + vQueueAddToRegistry( xTimerQueue, "TmrQ" ); + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + #endif /* configQUEUE_REGISTRY_SIZE */ + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + taskEXIT_CRITICAL(); + } +/*-----------------------------------------------------------*/ + + BaseType_t xTimerIsTimerActive( TimerHandle_t xTimer ) + { + BaseType_t xReturn; + Timer_t * pxTimer = xTimer; + + configASSERT( xTimer ); + + /* Is the timer in the list of active timers? */ + taskENTER_CRITICAL(); + { + if( ( pxTimer->ucStatus & tmrSTATUS_IS_ACTIVE ) == 0 ) + { + xReturn = pdFALSE; + } + else + { + xReturn = pdTRUE; + } + } + taskEXIT_CRITICAL(); + + return xReturn; + } /*lint !e818 Can't be pointer to const due to the typedef. */ +/*-----------------------------------------------------------*/ + + void * pvTimerGetTimerID( const TimerHandle_t xTimer ) + { + Timer_t * const pxTimer = xTimer; + void * pvReturn; + + configASSERT( xTimer ); + + taskENTER_CRITICAL(); + { + pvReturn = pxTimer->pvTimerID; + } + taskEXIT_CRITICAL(); + + return pvReturn; + } +/*-----------------------------------------------------------*/ + + void vTimerSetTimerID( TimerHandle_t xTimer, + void * pvNewID ) + { + Timer_t * const pxTimer = xTimer; + + configASSERT( xTimer ); + + taskENTER_CRITICAL(); + { + pxTimer->pvTimerID = pvNewID; + } + taskEXIT_CRITICAL(); + } +/*-----------------------------------------------------------*/ + + #if ( INCLUDE_xTimerPendFunctionCall == 1 ) + + BaseType_t xTimerPendFunctionCallFromISR( PendedFunction_t xFunctionToPend, + void * pvParameter1, + uint32_t ulParameter2, + BaseType_t * pxHigherPriorityTaskWoken ) + { + DaemonTaskMessage_t xMessage; + BaseType_t xReturn; + + /* Complete the message with the function parameters and post it to the + * daemon task. */ + xMessage.xMessageID = tmrCOMMAND_EXECUTE_CALLBACK_FROM_ISR; + xMessage.u.xCallbackParameters.pxCallbackFunction = xFunctionToPend; + xMessage.u.xCallbackParameters.pvParameter1 = pvParameter1; + xMessage.u.xCallbackParameters.ulParameter2 = ulParameter2; + + xReturn = xQueueSendFromISR( xTimerQueue, &xMessage, pxHigherPriorityTaskWoken ); + + tracePEND_FUNC_CALL_FROM_ISR( xFunctionToPend, pvParameter1, ulParameter2, xReturn ); + + return xReturn; + } + + #endif /* INCLUDE_xTimerPendFunctionCall */ +/*-----------------------------------------------------------*/ + + #if ( INCLUDE_xTimerPendFunctionCall == 1 ) + + BaseType_t xTimerPendFunctionCall( PendedFunction_t xFunctionToPend, + void * pvParameter1, + uint32_t ulParameter2, + TickType_t xTicksToWait ) + { + DaemonTaskMessage_t xMessage; + BaseType_t xReturn; + + /* This function can only be called after a timer has been created or + * after the scheduler has been started because, until then, the timer + * queue does not exist. */ + configASSERT( xTimerQueue ); + + /* Complete the message with the function parameters and post it to the + * daemon task. */ + xMessage.xMessageID = tmrCOMMAND_EXECUTE_CALLBACK; + xMessage.u.xCallbackParameters.pxCallbackFunction = xFunctionToPend; + xMessage.u.xCallbackParameters.pvParameter1 = pvParameter1; + xMessage.u.xCallbackParameters.ulParameter2 = ulParameter2; + + xReturn = xQueueSendToBack( xTimerQueue, &xMessage, xTicksToWait ); + + tracePEND_FUNC_CALL( xFunctionToPend, pvParameter1, ulParameter2, xReturn ); + + return xReturn; + } + + #endif /* INCLUDE_xTimerPendFunctionCall */ +/*-----------------------------------------------------------*/ + + #if ( configUSE_TRACE_FACILITY == 1 ) + + UBaseType_t uxTimerGetTimerNumber( TimerHandle_t xTimer ) + { + return ( ( Timer_t * ) xTimer )->uxTimerNumber; + } + + #endif /* configUSE_TRACE_FACILITY */ +/*-----------------------------------------------------------*/ + + #if ( configUSE_TRACE_FACILITY == 1 ) + + void vTimerSetTimerNumber( TimerHandle_t xTimer, + UBaseType_t uxTimerNumber ) + { + ( ( Timer_t * ) xTimer )->uxTimerNumber = uxTimerNumber; + } + + #endif /* configUSE_TRACE_FACILITY */ +/*-----------------------------------------------------------*/ + +/* This entire source file will be skipped if the application is not configured + * to include software timer functionality. If you want to include software timer + * functionality then ensure configUSE_TIMERS is set to 1 in FreeRTOSConfig.h. */ +#endif /* configUSE_TIMERS == 1 */ diff --git a/RTOS/FreeRTOS/z20k1xx.mk b/RTOS/FreeRTOS/z20k1xx.mk new file mode 100644 index 0000000..e872bf8 --- /dev/null +++ b/RTOS/FreeRTOS/z20k1xx.mk @@ -0,0 +1,29 @@ + +# Component Makefile +# +COMPONENT_ADD_INCLUDEDIRS += Source/include Source/portable/GCC/ARM_CM0 + +## This component's src +COMPONENT_SRCS := Source/croutine.c \ + Source/event_groups.c \ + Source/list.c \ + Source/queue.c \ + Source/stream_buffer.c \ + Source/tasks.c \ + Source/timers.c \ + Source/portable/GCC/ARM_CM0/port.c \ + Source/portable/MemMang/heap_4.c + +COMPONENT_OBJS := $(patsubst %.c,%.o, $(COMPONENT_SRCS)) +COMPONENT_OBJS := $(patsubst %.cpp,%.o, $(COMPONENT_OBJS)) + +COMPONENT_SRCDIRS := Source Source/portable/GCC/ARM_CM0 Source/portable/MemMang + +OPT_FLAG_G := $(findstring -Og, $(CFLAGS)) +ifeq ($(strip $(OPT_FLAG_G)),-Og) +CFLAGS := $(patsubst -Og,-O2,$(CFLAGS)) +endif +OPT_FLAG_S := $(findstring -Os, $(CFLAGS)) +ifeq ($(strip $(OPT_FLAG_S)),-Os) +CFLAGS := $(patsubst -Os,-O2,$(CFLAGS)) +endif diff --git a/StdDriver/Inc/Z20K11xM_adc.h b/StdDriver/Inc/Z20K11xM_adc.h new file mode 100644 index 0000000..37c72a7 --- /dev/null +++ b/StdDriver/Inc/Z20K11xM_adc.h @@ -0,0 +1,645 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_adc.h + * @brief : ADC module driver header file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ + +#ifndef Z20K11XM_ADC_H +#define Z20K11XM_ADC_H + +#include "Z20K11xM_drv.h" + +/** @addtogroup Z20K11X_Peripheral_Driver + * @{ + */ + +/** @addtogroup ADC + * @{ + */ + +/** @defgroup ADC_Public_Types + * @{ + */ + +/** + * @brief ADC ID type definition + */ +typedef enum +{ + ADC0_ID = 0U /*!< ADC0 */ +} ADC_ID_t; + +/** + * @brief ADC differential type definition + */ +typedef enum +{ + ADC_SINGLE_MODE = 0U, /*!< Single-Ended Mode Selected */ + ADC_DIFF_MODE /*!< Differential Mode Selected */ +} ADC_Differential_t; + +/** + * @brief ADC resolution type definition + */ +typedef enum +{ + ADC_RESOLUTION_12BIT = 0U, /*!< ADC 12-bit resolution */ + ADC_RESOLUTION_10BIT, /*!< ADC 10-bit resolution */ + ADC_RESOLUTION_8BIT /*!< ADC 8-bit resolution */ +} ADC_Resolution_t; + +/** + * @brief ADC voltage reference source type definition + */ +typedef enum +{ + ADC_VREF_EXTERNAL = 0U, /*!< External Vref_H, Vref_L reference */ + ADC_VREF_INTERNAL /*!< Internal Vref_H to 5V, + Vref_L to 0V reference */ +} ADC_VrefSource_t; + +/** + * @brief ADC trigger type definition + */ +typedef enum +{ + ADC_NORMAL_SW_TRIGGER = 0U, /*!< ADC normal software trigger mode*/ + ADC_TDG_TRIGGER = 2U /*!< ADC TDG trigger, need config cmd buf*/ +} ADC_TriggerMode_t; + +/** + * @brief ADC TDG trigger mode type definition + */ +typedef enum +{ + ADC_LOOP_MODE = 0U, /*!< Loop mode for TDG trigger, loop conversion + from CMD0 to CMD5*/ + ADC_MAPPING_MODE /*!< Mapping mode for TDG trigger, one trigger + triggers one cmd buff*/ +} ADC_TDGTriggerMode_t; + +/** + * @brief ADC conversion type definition + */ +typedef enum +{ + ADC_CONVERSION_SINGLE = 0U, /*!< ADC single conversion */ + ADC_CONVERSION_CONTINUOUS /*!< ADC continuous conversions */ +} ADC_Conversion_t; + +/** + * @brief ADC Positive channel selection definition + */ +typedef enum +{ + ADC_P_CH0 = 0U, /*!< Single mode, channel[0] and vssa */ + ADC_P_CH1, /*!< Single mode, channel[1] and vssa */ + ADC_P_CH2, /*!< Single mode, channel[2] and vssa */ + ADC_P_CH3, /*!< Single mode, channel[3] and vssa */ + ADC_P_CH4, /*!< Single mode, channel[4] and vssa */ + ADC_P_CH5, /*!< Single mode, channel[5] and vssa */ + ADC_P_CH6, /*!< Single mode, channel[6] and vssa */ + ADC_P_CH7, /*!< Single mode, channel[7] and vssa */ + ADC_P_CH8, /*!< Single mode, channel[8] and vss */ + ADC_P_CH9, /*!< Single mode, channel[9] and vss */ + ADC_P_CH10, /*!< Single mode, channel[10] and vss */ + ADC_P_CH11, /*!< Single mode, channel[11] and vss */ + ADC_P_CH12, /*!< Single mode, channel[12] and vss */ + ADC_P_CH13, /*!< Single mode, channel[13] and vss */ + ADC_P_CH14, /*!< Single mode, channel[14] and vss */ + ADC_P_CH15, /*!< Single mode, channel[15] and vss */ + ADC_P_CH16, /*!< Single mode, channel[16] and vss */ + ADC_P_CH17, /*!< Single mode, channel[17] and vss */ + ADC_P_CH20 = 20U /*!< internal channel bandgap */ +} ADC_P_Channel_t; + +/** + * @brief ADC Negtive channel selection definition + */ +typedef enum +{ + ADC_N_CH0 = 0U, /*!< Differential mode, P-channel[0] and N-channel[0] */ + ADC_N_CH1, /*!< Differential mode, P-channel[1] and N-channel[1] */ + ADC_N_CH2, /*!< Differential mode, P-channel[2] and N-channel[2] */ + ADC_N_VSS, /*!< Differential mode, P-channel[3] and N-channel[3] */ + ADC_N_NONE /*!< Single mode, N-channel donn't need to configure */ +} ADC_N_Channel_t; + +/** + * @brief ADC conversion average number type definition + */ +typedef enum +{ + ADC_AVGS_DISABLED = 0U, /*!< ADC average function is disabled,the number + of ADC conversions is 1*/ + ADC_AVGS_4, /*!< the number of ADC conversions which are + averaged is 4 */ + ADC_AVGS_8, /*!< the number of ADC conversions which are + averaged is 8 */ + ADC_AVGS_16, /*!< the number of ADC conversions which are + averaged is 16 */ + ADC_AVGS_32 /*!< the number of ADC conversions which are + averaged is 32 */ +} ADC_Average_t; + +/** + * @brief ADC compare mode type definition + */ +typedef enum +{ + ADC_COMPARE_MODE_DISABLED = 0U, /*!< ADC compare disabled */ + ADC_COMPARE_MODE_LESS_CVL, /*!< ADC compare less than CVL */ + ADC_COMPARE_MODE_GREATER_CVL, /*!< ADC compare greater than CVL */ + ADC_COMPARE_MODE_EQUAL_CVL, /*!< ADC compare equal to CVL */ + ADC_COMPARE_MODE_WITHIN_CVL_CVH, /*!< ADC compare winthin + range [CVL,CVH] */ + ADC_COMPARE_MODE_OUT_OF_RANGE_CVL_CVH /*!< ADC compare out of + range[0,CVL) U (CVH,FULL] */ +} ADC_Compare_t; + +/** + * @brief ADC interrupt type definition + */ +typedef enum +{ + ADC_FWM_INT = 0U, /*!< ADC fifo watermark interrupt */ + ADC_FOF_INT, /*!< ADC fifo overflow interrupt */ + ADC_TCOMP_INT, /*!< ADC complete interrupt */ + ADC_CMP_INT, /*!< ADC compare interrupt */ + ADC_TC_ERR_INT, /*!< ADC trigger confict error interrupt*/ + ADC_INT_ALL /*!< All ADC interrupt flags */ +} ADC_INT_t; + +/** + * @brief ADC status type definition + */ +typedef enum +{ + ADC_STATUS_FWM_INT = 0U, /*!< ADC fifo watermark status */ + ADC_STATUS_FOF_INT, /*!< ADC fifo overflow status */ + ADC_STATUS_TCOMP_INT, /*!< ADC complete interrupt status */ + ADC_STATUS_CMP_INT, /*!< ADC compare interrupt status */ + ADC_STATUS_DMA_REQ, /*!< ADC dma request status */ + ADC_STATUS_FIFO_RDY, /*!< ADC result fifo ready status */ + ADC_STATUS_CAL_RDY, /*!< ADC calibration ready status */ + ADC_STATUS_ACTIVE, /*!< ADC active status, 0: idle; + 1: processing a conversion */ + ADC_STATUS_LOOP_IDLE, /*!< ADC loop mode state machine return + to idle state */ + ADC_STATUS_TC_ERR_INT /*!< ADC trigger confict error */ +} ADC_Status_t; + + +/** + * @brief ADC configure type definition + */ +typedef struct +{ + ADC_Resolution_t adcResolution; + /*!< Configure ADC resolution + - ADC_RESOLUTION_12BIT (0): ADC 12-bit resolution + - ADC_RESOLUTION_10BIT (1): ADC 10-bit resolution + - ADC_RESOLUTION_8BIT (2): ADC 8-bit resolution + */ + + ADC_VrefSource_t adcVrefSource; + /*!< Configure ADC voltage reference source + - ADC_VREF_EXTERNAL (0): External Vref_H, Vref_L reference + - ADC_VREF_INTERNAL (1): Internal Vref_H to 5V, Vref_L to 0V reference + */ + + ADC_TriggerMode_t adcTriggerMode; + /*!< Configure ADC trigger mode + - ADC_NORMAL_SW_TRIGGER (0): Normal software trigger + - ADC_TDG_TRIGGER (2): TDG trigger + */ + + ADC_Conversion_t adcConversionMode; + /*!< Configure ADC conversion mode + - ADC_CONVERSION_SINGLE (0): single conversion + - ADC_CONVERSION_CONTINUOUS (1): continuous conversion + */ + + ADC_Average_t adcAvgsSelect; + /*!< Configure ADC averages + - ADC_AVGS_DISABLED (0): average function is disabled, the number of + ADC coversions which are averaged is 1 + - ADC_AVGS_4 (1): the number of ADC coversions which are averaged is 4 + - ADC_AVGS_8 (2): the number of ADC coversions which are averaged is 8 + - ADC_AVGS_16(3): the number of ADC coversions which are averaged is 16 + - ADC_AVGS_32(4): the number of ADC coversions which are averaged is 32 + */ + + uint32_t adcSampleTime; + /*!< Set the time interval between two samples when average is enabled or in continues mode. + Please refer to STS definition in RM to see the constraint */ +} ADC_Config_t; + +/** + * @brief ADC channel configure type definition + */ +typedef struct +{ + ADC_Differential_t adcDifferentialMode; + /*!< Configure ADC differential mode + - ADC_SINGLE_MODE (0): ADC single mode + - ADC_DIFF_MODE (1): ADC differential mode */ + + ADC_P_Channel_t adcChannelP; + /*!< Configure ADC positive channel + - ADC_P_CH0 (0): ADC Positive channel 0 + - ...... + - ADC_P_CH20 (20): ADC Positive channel 20 */ + + ADC_N_Channel_t adcChannelN; + /*!< Configure ADC negtive channel + - ADC_N_CH0 (0): ADC Negtive channel 0 + - ADC_N_CH1 (1): ADC Negtive channel 1 + - ADC_N_CH2 (2): ADC Negtive channel 2 + - ADC_N_VSS (3): ADC Negtive connected with VSS + */ +} ADC_ChannelConfig_t; + + +/** + * @brief ADC compare configure type definition + */ +typedef struct +{ + ADC_Compare_t adcCompareMode; + /*!< Configure ADC Compare mode + - ADC_COMPARE_MODE_DISABLED (0): ADC compare mode disabled + - ADC_COMPARE_MODE_LESS_CVL (1): ADC compare mode less then cvl + - ADC_COMPARE_MODE_GREATER_CVL (2): ADC compare mode greater than cvl + - ADC_COMPARE_MODE_EQUAL_CVL (3): ADC compare mode equal to cvl + - ADC_COMPARE_MODE_WITHIN_CVL_CVH (4): ADC compare mode within cvl + and cvh + - ADC_COMPARE_MODE_OUT_OF_RANGE_CVL_CVH (5): ADC compare mode out of + range cvl and cvh + */ + + uint16_t adcCvl; + /*!< Configure ADC Compare Value Low, which is used in below modes: + - ADC_COMPARE_MODE_LESS_CVL (1) + - ADC_COMPARE_MODE_GREATER_CVL (2) + - ADC_COMPARE_MODE_EQUAL_CVL (3) + - ADC_COMPARE_MODE_WITHIN_CVL_CVH (4) + - ADC_COMPARE_MODE_OUT_OF_RANGE_CVL_CVH (5) + */ + + uint16_t adcCvh; + /*!< Configure ADC Compare Value High, which is used in below modes: + - ADC_COMPARE_MODE_WITHIN_CVL_CVH (4) + - ADC_COMPARE_MODE_OUT_OF_RANGE_CVL_CVH (5) + */ +} ADC_CompareConfig_t; + +/** + * @brief ADC TDG Trigger configure struct definition + */ +typedef struct +{ + ADC_TDGTriggerMode_t adcTDGTrigMode; + /*!< Configure ADC TDG Trigger Mode, which is used in below modes: + - ADC_LOOP_MODE (0) + - ADC_MAPPING_MODE (1) + */ + + ADC_P_Channel_t adcCmd0; + /*!< Configure ADC CMD 0 buff, which is P_channel value: + - ADC_P_CH0 (0): ADC Positive channel 0 + - ...... + - ADC_P_CH20 (20): ADC Positive channel 20 + */ + + ADC_P_Channel_t adcCmd1; + /*!< Configure ADC CMD 1 buff, which is P_channel value. See adcCmd0*/ + + ADC_P_Channel_t adcCmd2; + /*!< Configure ADC CMD 2 buff, which is P_channel value. See adcCmd0*/ + + ADC_P_Channel_t adcCmd3; + /*!< Configure ADC CMD 3 buff, which is P_channel value. See adcCmd0*/ + + ADC_P_Channel_t adcCmd4; + /*!< Configure ADC CMD 4 buff, which is P_channel value. See adcCmd0*/ + + ADC_P_Channel_t adcCmd5; + /*!< Configure ADC CMD 5 buff, which is P_channel value. See adcCmd0*/ +} ADC_TDGTriggerConfig_t; + +/** + * @brief ADC conversion result struct definition + */ +typedef union +{ + struct + { + uint32_t data :12; /*!<[11:0] Sample result of the conversion*/ + uint32_t channel :5; /*!<[16:12] Channel number of the + conversion result*/ + uint32_t reserved :15; /*!<[31:17] Reserved*/ + }bf; + + uint32_t adcResult; /*!< Adc conversion result register*/ +} ADC_Conversion_Result_t; + +/** @} end of group ADC_Public_Types*/ + + +/** @defgroup ADC_Public_FunctionDeclaration + * @brief ADC functions statement + * @{ + */ + +/** + * @brief Adc Software Reset Function + * + * @param[in] adcId: Select the ADC ID: ADC0_ID,.... + * + * @return none + * + */ +void ADC_SoftwareReset(ADC_ID_t adcId); + +/** + * @brief Adc Initializes Function + * + * @param[in] adcId: Select the ADC ID: ADC0_ID,.... + * @param[in] adcConfigSet: Pointer to a ADC configuration structure. + * + * @return none + * + */ +void ADC_Init(ADC_ID_t adcId, const ADC_Config_t* adcConfigSet); + +/** + * @brief Adc Enable Function + * + * @param[in] adcId: Select the ADC ID: ADC0_ID,.... + * + * @return none + * + */ +void ADC_Enable(ADC_ID_t adcId); + +/** + * @brief Adc Disable Function + * + * @param[in] adcId: Select the ADC ID: ADC0_ID,.... + * + * @return none + * + */ +void ADC_Disable(ADC_ID_t adcId); + +/** + * @brief Adc Channel Configurate Function + * + * @param[in] adcId: Select the ADC ID: ADC0_ID,.... + * @param[in] channelConfig: Pointer to a ADC channel configuration structure. + * + * @return none + * + */ +void ADC_ChannelConfig(ADC_ID_t adcId, + const ADC_ChannelConfig_t* channelConfig); + +/** + * @brief Adc TDG Trigger Configurate Function + * + * @param[in] adcId: Select the ADC ID: ADC0_ID,.... + * @param[in] triggerConfig: Pointer to a ADC TDG trigger configuration + structure. + * + * @return none + * + */ +void ADC_TDGTriggerConfig(ADC_ID_t adcId, + const ADC_TDGTriggerConfig_t* triggerConfig); + +/** + * @brief Adc Reset(Terminate) Loop Mode for TDG Trigger Function + * + * @param[in] adcId: Select the ADC ID: ADC0_ID,.... + * + * @return none + * + */ +void ADC_ResetLoopMode(ADC_ID_t adcId); + +/** + * @brief Adc Dozen Control Function + * + * @param[in] adcId: Select the ADC ID: ADC0_ID,.... + * + * @param[in] cmd: Enable/Disable. + * + * @return none + * + */ +void ADC_DozeControl(ADC_ID_t adcId, ControlState_t cmd); + +/** + * @brief Adc Compare Configurate Function + * + * @param[in] adcId: Select the ADC ID: ADC0_ID,.... + * @param[in] compareConfig: Pointer to a ADC compare configuration structure. + * adcCompareMode: Compare Mode + * - ADC_COMPARE_MODE_DISABLED + * - ADC_COMPARE_MODE_LESS_CVL + * - ADC_COMPARE_MODE_GREATER_CVL + * - ADC_COMPARE_MODE_EQUAL_CVL + * - ADC_COMPARE_MODE_WITHIN_CVL_CVH + * - ADC_COMPARE_MODE_OUT_OF_RANGE_CVL_CVH. + * cvl: Compare Value Low, which is used in below modes: + * - ADC_COMPARE_MODE_LESS_CVL + * - ADC_COMPARE_MODE_GREATER_CVL + * - ADC_COMPARE_MODE_EQUAL_CVL + * - ADC_COMPARE_MODE_WITHIN_CVL_CVH + * - ADC_COMPARE_MODE_OUT_OF_RANGE_CVL_CVH + * cvh: Compare Value High, which is used in below modes: + * - ADC_COMPARE_MODE_WITHIN_CVL_CVH + * - ADC_COMPARE_MODE_OUT_OF_RANGE_CVL_CVH + * + * @return none + * + */ +void ADC_CompareConfig(ADC_ID_t adcId, + const ADC_CompareConfig_t* compareConfig); + +/** + * @brief Adc FIFO Depth Redefine Function + * + * @param[in] adcId: Select the ADC ID: ADC0_ID,.... + * @param[in] fifoDepth: FIFO depth Configuration. + * + * @return none + * + */ +void ADC_FifoDepthRedefine(ADC_ID_t adcId, uint8_t fifoDepth); + +/** + * @brief Adc FIFO Watermark Configurate Function + * + * @param[in] adcId: Select the ADC ID: ADC0_ID,.... + * @param[in] fwmark: FIFO watermark configration. + * + * @return none + * + */ +void ADC_FifoWatermarkConfig(ADC_ID_t adcId, uint8_t fwmark); + +/** + * @brief Adc Get FIFO size Function + * + * @param[in] adcId: Select the ADC ID: ADC0_ID,.... + * + * @return FIFO size. + * + */ +uint32_t ADC_GetFifoSize(ADC_ID_t adcId); + +/** + * @brief Adc Get data size in FIFO Function + * + * @param[in] adcId: Select the ADC ID: ADC0_ID,.... + * + * @return Data size in FIFO. + * + */ +uint32_t ADC_GetNumOfFifoData(ADC_ID_t adcId); + +/** + * @brief Adc Dma Request Command Function + * + * @param[in] adcId: Select the ADC ID: ADC0_ID,.... + * @param[in] cmd: Enable/Disable. + * + * @return none + * + */ +void ADC_DmaRequestCmd(ADC_ID_t adcId, ControlState_t cmd); + +/** + * @brief Adc Software Trigger Control Function + * + * @param[in] adcId: Select the ADC ID: ADC0_ID,.... + * + * @return none + * + */ +void ADC_SoftwareTrigger(ADC_ID_t adcId); + +/** + * @brief Adc Get Conversion Result Function + * + * @param[in] adcId: Select the ADC ID: ADC0_ID,.... + * + * @return Conversion Result. + * + */ +uint32_t ADC_GetConversionResult(ADC_ID_t adcId); + +/** + * @brief Adc Get Status Function + * + * @param[in] adcId: Select the ADC ID: ADC0_ID,.... + * @param[in] statusType: Status Type + * - ADC_STATUS_FWM_INT + * - ADC_STATUS_FOF_INT + * - ADC_STATUS_TCOMP_INT + * - ADC_STATUS_CMP_INT + * - ADC_STATUS_DMA_REQ + * - ADC_STATUS_FIFO_RDY + * - ADC_STATUS_CAL_RDY + * - ADC_STATUS_ACTIVE + * - ADC_STATUS_TC_ERR_INT + * + * @return status: RESET, SET + * + */ +FlagStatus_t ADC_GetStatus(ADC_ID_t adcId, ADC_Status_t statusType); + +/** + * @brief Adc Interrupt Mask Function + * + * @param[in] adcId: Select the ADC ID: ADC0_ID,.... + * @param[in] intType: Interrupt Type + * - ADC_FWM_INT. + * - ADC_FOF_INT + * - ADC_TCOMP_INT + * - ADC_CMP_INT + * - ADC_TC_ERR_INT + * @param[in] intMask: Mask Type + * - UNMASK + * - MASK + * + * @return none. + * + */ +void ADC_IntMask(ADC_ID_t adcId, ADC_INT_t intType, IntMask_t intMask); + +/** + * @brief Adc Interrupt Clear Status Function + * + * @param[in] adcId: Select the ADC ID: ADC0_ID,.... + * @param[in] intType: Interrupt Type + * - ADC_FWM_INT. + * - ADC_FOF_INT + * - ADC_TCOMP_INT + * - ADC_CMP_INT + * - ADC_TC_ERR_INT + * + * @return none. + * + */ +void ADC_IntClear(ADC_ID_t adcId, ADC_INT_t intType); + +/** + * @brief Adc Get Interrupt Status Function + * + * @param[in] adcId: Select the ADC ID: ADC0_ID,.... + * @param[in] intType: Interrupt Type + * - ADC_FWM_INT. + * - ADC_FOF_INT + * - ADC_TCOMP_INT + * - ADC_CMP_INT + * - ADC_TC_ERR_INT + * + * @return status: RESET, SET + * + */ +FlagStatus_t ADC_GetIntStatus(ADC_ID_t adcId, ADC_INT_t intType); + +/** + * @brief install call back function + * + * @param[in] adcId: Select the ADC ID: ADC0_ID,.... + * @param[in] intType: select the interrupt + * - ADC_FWM_INT. + * - ADC_FOF_INT + * - ADC_TCOMP_INT + * - ADC_CMP_INT + * - ADC_TC_ERR_INT + * @param[in] cbFun: pointer to callback function + * + * @return none + * + */ +void ADC_InstallCallBackFunc(ADC_ID_t adcId, ADC_INT_t intType, + isr_cb_t * cbFun); + + +/** @} end of group ADC_Public_FunctionDeclaration */ + +/** @} end of group ADC */ + +/** @} end of group Z20K11X_Peripheral_Driver */ +#endif /* Z20K11XM_ADC_H */ diff --git a/StdDriver/Inc/Z20K11xM_can.h b/StdDriver/Inc/Z20K11xM_can.h new file mode 100644 index 0000000..01fa57d --- /dev/null +++ b/StdDriver/Inc/Z20K11xM_can.h @@ -0,0 +1,1477 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_can.h + * @brief : CAN driver module header file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ +#ifndef Z20K11XM_CAN_H +#define Z20K11XM_CAN_H + +#include "Z20K11xM_drv.h" + +/** @addtogroup Z20K11X_Peripheral_Driver + * @{ + */ + +/** @addtogroup CAN + * @{ + */ + +/** @defgroup CAN_Public_Types + * @{ + */ + +/** + * @brief CAN ID type definition + */ +typedef enum +{ + CAN_ID_0 = 0U, /*!< CAN0 */ +#if ( 2U == CAN_INSTANCE_NUM ) + CAN_ID_1 /*!< CAN1 */ +#endif +} CAN_Id_t; + +/** + * @brief RxFIFO transfer type definition + */ +typedef enum +{ + CAN_RXFIFO_INTERRUPTS = 0U, /*!< Use interrupts for RxFIFO. */ + CAN_RXFIFO_DMA /*!< Use DMA for RxFIFO. */ +} CAN_RxfifoTransfer_t; + + +/** + * @brief CAN Message ID type definition + */ +typedef enum +{ + CAN_MSG_ID_STD = 0U, /*!< Standard ID*/ + CAN_MSG_ID_EXT /*!< Extended ID*/ +} CAN_MsgId_t; + + +/** + * @brief CAN Rx mask type definition + */ +typedef enum +{ + CAN_RX_MASK_GLOBAL = 0U, /*!< Rx global mask*/ + CAN_RX_MASK_INDIVIDUAL /*!< Rx individual mask*/ +} CAN_RxMask_t; + +/** + * @brief ID filter formats for Rx FIFO type definition + */ +typedef enum +{ + CAN_RX_FIFO_ID_FORMAT_A = 0U, /*!< One full ID (standard and extended)*/ + CAN_RX_FIFO_ID_FORMAT_B, /*!< Two full standard IDs or two partial + 14-bit extended IDs*/ + CAN_RX_FIFO_ID_FORMAT_C, /*!< Four partial 8-bit Standard,extended IDs */ + CAN_RX_FIFO_ID_FORMAT_D /*!< All frames rejected.*/ +} CAN_RxFifoIdFormat_t; + +/** + * @brief CAN operation mode type definition + */ +typedef enum +{ + CAN_MODE_NORMAL = 0U, /*!< Normal mode or user mode */ + CAN_MODE_LISTEN_ONLY, /*!< Listen-only mode */ + CAN_MODE_LOOPBACK, /*!< Loop-back mode */ + CAN_MODE_FREEZE, /*!< Freeze mode */ + CAN_MODE_DISABLE /*!< Module disable mode */ +} CAN_Mode_t; + + + +/** + * @brief CAN Rx FIFO ID filters number type definition + */ +typedef enum +{ + CAN_RX_FIFO_ID_FILTERS_8 = 0x0, /*!< 8 Rx FIFO Filters */ + CAN_RX_FIFO_ID_FILTERS_16 = 0x1, /*!< 16 Rx FIFO Filters */ + CAN_RX_FIFO_ID_FILTERS_24 = 0x2, /*!< 24 Rx FIFO Filters */ + CAN_RX_FIFO_ID_FILTERS_32 = 0x3, /*!< 32 Rx FIFO Filters */ + CAN_RX_FIFO_ID_FILTERS_40 = 0x4, /*!< 40 Rx FIFO Filters */ + CAN_RX_FIFO_ID_FILTERS_48 = 0x5, /*!< 48 Rx FIFO Filters */ + CAN_RX_FIFO_ID_FILTERS_56 = 0x6, /*!< 56 Rx FIFO Filters */ + CAN_RX_FIFO_ID_FILTERS_64 = 0x7, /*!< 64 Rx FIFO Filters */ + CAN_RX_FIFO_ID_FILTERS_72 = 0x8, /*!< 72 Rx FIFO Filters */ + CAN_RX_FIFO_ID_FILTERS_80 = 0x9, /*!< 80 Rx FIFO Filters */ + CAN_RX_FIFO_ID_FILTERS_88 = 0xA, /*!< 88 Rx FIFO Filters */ + CAN_RX_FIFO_ID_FILTERS_96 = 0xB, /*!< 96 Rx FIFO Filters */ + CAN_RX_FIFO_ID_FILTERS_104 = 0xC, /*!< 104 Rx FIFO Filters */ + CAN_RX_FIFO_ID_FILTERS_112 = 0xD, /*!< 112 Rx FIFO Filters */ + CAN_RX_FIFO_ID_FILTERS_120 = 0xE, /*!< 120 Rx FIFO Filters */ + CAN_RX_FIFO_ID_FILTERS_128 = 0xF /*!< 128 Rx FIFO Filters */ +} CAN_RxFifoIdFilterNum_t; + + + +/** + * @brief CAN FD payload size definition + */ +typedef enum +{ + CAN_PAYLOAD_SIZE_8 = 0U, /*!< CAN FD message buffer payload size in bytes*/ + CAN_PAYLOAD_SIZE_16 , /*!< CAN FD message buffer payload size in bytes*/ + CAN_PAYLOAD_SIZE_32 , /*!< CAN FD message buffer payload size in bytes*/ + CAN_PAYLOAD_SIZE_64 /*!< CAN FD message buffer payload size in bytes*/ +} CAN_FdPayloadSize_t; + +/** + * @brief CAN tx priority type definition + */ +typedef enum +{ + CAN_TX_PRI_HIGH_PRI_FIRST = 0U, /*!< highest-priority mailbox first, + the priority is decided by the + CAN frame. The lower value has an + higher priority */ + CAN_TX_PRI_LOW_NUM_MB_FIRST, /*!< lowest-number mailbox first */ + CAN_TX_PRI_LOCAL_PRI_EN, /*!< local priority is enabled. The + priority is decided by the local + priority field which is not part + of CAN frame*/ +} CAN_TxPriMode_t; + +/** + * @brief CAN MB code type definition + */ +typedef enum +{ + CAN_MB_RX_INACTIVE = 0x0, /*!< MB is not active.*/ + CAN_MB_RX_FULL = 0x2, /*!< MB is full.*/ + CAN_MB_RX_EMPTY = 0x4, /*!< MB is active and empty.*/ + CAN_MB_RX_OVERRUN = 0x6, /*!< MB is overwritten into a full buffer.*/ + CAN_MB_RX_RANSWER = 0xA, /*!< A frame was configured to recognize a + Remote Request Frame and transmit a Response + Frame in return.*/ + CAN_MB_TX_INACTIVE = 0x08, /*!< MB is not active.*/ + CAN_MB_TX_ABORT = 0x09, /*!< MB is aborted.*/ + CAN_MB_TX_DATA_REMOTE = 0x0C, /*!< MB is a TX Data Frame(MB RTR = 0). or a + remote request frame (MB RTR = 1)*/ + CAN_MB_TX_TANSWER = 0x0E, /*!< MB is a Tx Response frame from an + incoming Remote Request frame. */ +}CAN_MbCode_t; + + +/** + * @brief CAN interrupt type definition + */ +typedef enum +{ + CAN_INT_BUS_OFF = 0U, /*!< CAN interrupt: bus off */ + CAN_INT_ERR = 1U, /*!< CAN interrupt: error */ + CAN_INT_TXW = 2U, /*!< CAN interrupt: TX warning */ + CAN_INT_RXW = 3U, /*!< CAN interrupt: RX warning */ + CAN_INT_BUS_OFF_DONE = 4U, /*!< CAN interrupt: bus off done*/ + CAN_INT_ERR_FAST = 5U, /*!< CAN interrupt: error detected in Data + Phase of CAN FD frames with BRS bit + set*/ + CAN_INT_SELF_WAKEUP = 6U, /*!< CAN interrupt: self wake up */ + CAN_INT_RXFIFO_FRAME = 7U, /*!< CAN interrupt: RX FIFO frame available */ + CAN_INT_RXFIFO_WARNING = 8U, /*!< CAN interrupt: RX FIFO warning */ + CAN_INT_RXFIFO_OVERFLOW = 9U, /*!< CAN interrupt: RX FIFO overflow */ + CAN_INT_HOST_MEM_ERR = 10U, /*!< CAN interrupt: non-correctable errors + detected in memory reads issued by + the CPU */ + CAN_INT_CAN_MEM_ERR = 11U, /*!< CAN interrupt: non-correctable errors + detected in memory reads issued by + the CAN */ + CAN_INT_COR_MEM_ERR = 12U, /*!< CAN interrupt: correctable errors + detected in memory reads */ + CAN_INT_PN_WAKEUP_MATCH = 13U, /*!< CAN interrupt: wakeup by match */ + CAN_INT_PN_WAKEUP_TIMEOUT = 14U, /*!< CAN interrupt: wakeup by timeout */ + CAN_INT_MB = 15U, /*!< CAN interrupt: MB transmission/reception + completed or RX FIFO related interrupt */ + CAN_INT_ALL =16U /*!< CAN all interrupts */ +} CAN_Int_t; + +/** + * @brief CAN Pretended Networking matching schemes + */ +typedef enum +{ + CAN_PN_MATCH_EXACT, /*!< Match an exact target value. */ + CAN_PN_MATCH_GEQ, /*!< Match greater than or equal to a specified + target value. */ + CAN_PN_MATCH_LEQ, /*!< Match less than or equal to a specified target + value. */ + CAN_PN_MATCH_RANGE /*!< Match inside a range, greater than or equal to a + specified lower limit and smaller than or + equal to a specified upper limit. */ +} CAN_PnFilterMatch_t; + +/** + * @brief CAN Pretended Networking filtering combinations + */ +typedef enum +{ + CAN_FILTER_ID, /*!< Message ID filtering only */ + CAN_FILTER_ID_PAYLOAD, /*!< Message ID and payload filtering */ + CAN_FILTER_ID_NTIMES, /*!< Message ID filtering occurring a + specified number of times */ + CAN_FILTER_ID_PAYLOAD_NTIMES /*!< Message ID and payload filtering + occurring a specified number of times */ +} CAN_PnFilterCombination_t; + +/** + * @brief CAN error status type definition + */ +typedef enum +{ + CAN_STATUS_RXWRN = 8U, /*!< CAN status: Rx Error Warning */ + CAN_STATUS_TXWRN = 9U, /*!< CAN status: Tx Error Warning */ + CAN_STATUS_STUFF_ERR = 10U, /*!< CAN status: stuff error */ + CAN_STATUS_FORM_ERR = 11U, /*!< CAN status: form error */ + CAN_STATUS_CRC_ERR = 12U, /*!< CAN status: CRC error */ + CAN_STATUS_ACK_ERR = 13U, /*!< CAN status: ACK error */ + CAN_STATUS_BIT0_ERR = 14U, /*!< CAN status: bit0 error */ + CAN_STATUS_BIT1_ERR = 15U, /*!< CAN status: bit1 error */ + CAN_STATUS_ERROVR = 21U, /*!< CAN status: error overrun */ + CAN_STATUS_STUFF_ERR_FAST = 26U, /*!< CAN status: stuff error in FD frame + with the BRS bit set */ + CAN_STATUS_FORM_ERR_FAST = 27U, /*!< CAN status: form error in FD frame + with the BRS bit set */ + CAN_STATUS_CRC_ERR_FAST = 28U, /*!< CAN status: CRC error in FD frame + with the BRS bit set */ + CAN_STATUS_ACK_ERR_FAST = 29U, /*!< CAN status: ACK error in FD frame + with the BRS bit set */ + CAN_STATUS_BIT0_ERR_FAST = 30U, /*!< CAN status: bit0 error in FD frame + with the BRS bit set*/ + CAN_STATUS_BIT1_ERR_FAST = 31U, /*!< CAN status: bit1 error in FD frame + with the BRS bit set*/ + CAN_STATUS_ALL = 32U /*!< CAN all status */ +} CAN_Status_t; + +/** + * @brief CAN State type definition + */ +typedef enum +{ + CAN_STATE_NOT_SYNC = 0U, /*!< it is not synchronized to CAN bus*/ + CAN_STATE_IDLE, /*!< CAN bus is in idle state */ + CAN_STATE_TX, /*!< CAN is transmitting */ + CAN_STATE_RX, /*!< CAN is receiving */ + CAN_STATE_INVALID, /*!< this is not a valid state */ +} CAN_State_t; + +/** + * @brief CAN Fault Confinement State definition + */ +typedef enum +{ + CAN_FAULT_CONF_STATE_ERROR_ACTIVE = 0U, /*!< CAN Fault Confinement + State: error active*/ + CAN_FAULT_CONF_STATE_ERROR_PASSIVE, /*!< CAN Fault Confinement + State: error passive */ + CAN_FAULT_CONF_STATE_BUS_OFF, /*!< CAN Fault Confinement + State: bus off */ + +} CAN_FaultConfState_t; + +/** + * @brief CAN bus off recovery scheme type definition + */ +typedef enum +{ + CAN_BUS_OFF_RECOV_AUTO = 0U, /*!< automatic recovering from Bus Off + state occurs according to the CAN + Specification */ + CAN_BUS_OFF_RECOV_MANUAL = 1U, /*!< recover from bus off manually */ +} CAN_BusOffRecovery_t; + +/** + * @brief CAN bit timing configuration structures + */ +typedef struct +{ + uint32_t propSeg; /*!< Propagation segment*/ + uint32_t phaseSeg1; /*!< Phase segment 1*/ + uint32_t phaseSeg2; /*!< Phase segment 2*/ + uint32_t preDivider; /*!< Clock prescaler division factor*/ + uint32_t rJumpwidth; /*!< Resync jump width*/ +} CAN_BitTiming_t; + +/** + * @brief CAN RX FIFO ID filter table element structure + */ +typedef struct +{ + FlagStatus_t isRemoteFrame; /*!< Remote frame*/ + FlagStatus_t isExtendedFrame; /*!< Extended frame*/ + uint32_t id; /*!< Rx FIFO ID filter element*/ +} CAN_IdFilter_t; + +/** + * @brief CAN massage info structure + */ +typedef struct +{ + CAN_MsgId_t idType; /*!< Type of message ID (standard or extended)*/ + uint8_t dataLen; /*!< Length of Data in Bytes*/ + FlagStatus_t remoteFlag; /*!< Specifies if the frame is standard or remote */ + ControlState_t fdEn; /*!< Enable or disable FD*/ + uint8_t fdPadding; /*!< Set a value for padding. It will be used + when the data length code (DLC) specifies + a bigger data size than data_length to + fill the MB */ + ControlState_t brsEn; /*!< Enable bit rate switch inside a CAN FD + format frame*/ +} CAN_MessageInfo_t; + +/** + * @brief CAN message buffer structure + */ +typedef struct +{ + uint32_t cs; /*!< Code and Status*/ + uint32_t msgId; /*!< Message ID*/ + uint8_t data[64]; /*!< Data bytes of the CAN message*/ + uint8_t dataLen; /*!< Length of data in bytes */ +} CAN_MsgBuf_t; + +/** + * @brief CAN configuration + */ +typedef struct +{ + uint32_t mbMaxNum; /*!< The maximum number of + Message Buffers */ + ControlState_t rxFifoEn; /*!< select if use RX FIFO */ + CAN_RxFifoIdFilterNum_t rxFifoIdFilterNum; /*!< The number of RX FIFO ID + filters needed. It is only valid + when RXFIFO is enabled */ + CAN_RxfifoTransfer_t transferType; /*!< Specifies if the Rx FIFO + uses interrupts or DMA. It is + only valid when RXFIFO is enabled */ + CAN_Mode_t mode; /*!< CAN operation modes */ + CAN_BitTiming_t bitTiming; /*!< The bitrate used for + standard frames or for the + arbitration phase of FD frames. */ + ControlState_t fdEn; /*!< Enable/Disable the + Flexible Data Rate feature. */ + CAN_FdPayloadSize_t payload0; /*!< The payload size of the + mailboxes in region0 specified + in bytes. It is only valid when + Flexible data rate feature is enabled*/ + CAN_FdPayloadSize_t payload1; /*!< The payload size of the + mailboxes in region1 specified in bytes. + It is only valid when Flexible + data rate feature is enabled */ + CAN_BitTiming_t bitTimingFdData; /*!< The bitrate used for the + data phase of FD frames. It is + only valid when Flexible data + rate feature is enabled */ +}CAN_Config_t; + +/** + * @brief CAN Pretended Networking ID filter + */ +typedef struct +{ + CAN_MsgId_t idType; /*!< Specifies if the ID is standard or extended. */ + FlagStatus_t remoteFlag; /*!< Specifies if the frame is data or remote frame. */ + uint32_t id; /*!< Specifies the ID value. */ +} CAN_PnIdFilter_t; + +/** + * @brief CAN Pretended Networking payload filter + */ +typedef struct +{ + uint8_t dlcLow; /*!< Specifies the lower limit of the payload size. */ + uint8_t dlcHigh; /*!< Specifies the upper limit of the payload size. */ + uint8_t payload1[8U]; /*!< Specifies the payload to be matched (for MATCH_EXACT), + the lower limit (for MATCH_GEQ and MATCH_RANGE) or + the upper limit (for MATCH_LEQ). */ + uint8_t payload2[8U]; /*!< Specifies the mask (for MATCH_EXACT) or the upper + limit (for MATCH_RANGE). */ +} CAN_PnPayloadFilter_t; + +/** + * @brief CAN Pretended Networking configuration structure + */ +typedef struct +{ + CAN_PnFilterCombination_t matchScheme; /*!< Defines the filtering scheme used. */ + uint16_t numMatches; /*!< The number of matches needed + before generating an wake up event. */ + CAN_PnFilterMatch_t idFilterType; /*!< Defines the ID filtering scheme. */ + CAN_PnIdFilter_t idFilter1; /*!< The configuration of the first + ID filter (match exact / lower + limit / upper limit). */ + CAN_PnIdFilter_t idFilter2; /*!< The configuration of the second + ID filter (mask / upper limit). */ + CAN_PnFilterMatch_t payloadFilterType; /*!< Defines the payload filtering scheme. */ + CAN_PnPayloadFilter_t payloadFilter; /*!< The configuration of the payload filter. */ +} CAN_PnMatchConfig_t; + + +/** + * @brief CAN Pretended Networking configuration structure + */ +typedef struct +{ + ControlState_t wakeUpTimeout; /*!< Specifies if an wake up event is + triggered on timeout. */ + uint16_t timeout; /*!< Defines a timeout value that + generates an wake up event if + wakeUpTimeout is true. */ + ControlState_t wakeUpMatch; /*!< Specifies if an wake up event is + triggered on match. */ + CAN_PnMatchConfig_t matchConfig; /*!< configuration for match wakeup event. */ +} CAN_PnConfig_t; + +/** + * @brief CAN MB callback function type + */ +typedef void (*can_mb_cb_t)(uint32_t mbIdx); + +/** @} end of group CAN_Public_Types */ + +/** @defgroup CAN_Public_Constants + * @{ + */ +#define CAN_MAX_MB_NUM 64U +#define CAN_RAM_SIZE_IN_BYTE 1024 +#define CAN_RAM_SIZE_IN_WORD (CAN_RAM_SIZE_IN_BYTE/4) +#define CAN_ABORT_EN 1U + +/** @} end of group CAN_Public_Constants */ + +/** @defgroup CAN_Public_Macro + * @{ + */ + +/** @} end of group CAN_Public_Macro */ + +/** @defgroup CAN_Public_FunctionDeclaration + * @brief CAN functions declaration + * @{ + */ + +/** + * @brief Initializes the CAN peripheral. This function will do soft reset + * for CAN module, and initialize CAN with provided parameters. This + * function needs to be called first before other config functions. + * + * @param[in] id: select the CAN ID + * @param[in] config: points to the configuration struct + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_Init(CAN_Id_t id, const CAN_Config_t *config); + +/** + * @brief Deinit the CAN peripheral. This function disables all CAN + interrupts, and disable the CAN + * + * @param[in] id: select the CAN ID + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_Deinit(CAN_Id_t id); + +/** + * @brief Set operation mode. + * + * @param[in] id: select the CAN ID + * @param[in] mode: select the CAN operation mode + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_SetOperationMode(CAN_Id_t id, CAN_Mode_t mode); + +/** + * @brief Disable/Enable self reception. + * + * @param[in] id: select the CAN ID + * @param[in] ctrl: ENABLE/DISABLE + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_SetSelfRec(CAN_Id_t id, ControlState_t ctrl); + +/** + * @brief Select TX Priority mode. + * + * @param[in] id: select the CAN ID + * @param[in] mode: select the CAN TX priority mode + * + * @return status + * - SUCC -- successful + * - ERR -- some error + */ +ResultStatus_t CAN_SelectTxPriorityMode(CAN_Id_t id, CAN_TxPriMode_t mode); + +/** + * @brief Enable CAN. + * + * @param[in] id: select the CAN ID + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_Enable(CAN_Id_t id); + +/** + * @brief Disable CAN. + * + * @param[in] id: select the CAN ID + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_Disable(CAN_Id_t id); + +/** + * @brief Sets the CAN bit timing for standard frames or the arbitration + * phase of FD frames. + * + * @param[in] id: select the CAN ID + * @param[in] timeSeg: A pointer to the CAN bit timing settings + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_SetStdBitTiming(CAN_Id_t id, const CAN_BitTiming_t *timeSeg); + +/** + * @brief Sets the CAN bit timing for the arbitration phase of FD frames of + * CAN. + * + * @param[in] id: select the CAN ID + * @param[in] timeSeg: A pointer to the CAN bit timing settings + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_SetFdArbBitTiming(CAN_Id_t id, const CAN_BitTiming_t *timeSeg); + +/** + * @brief Sets the CAN bit timing for the data phase of FD frames. + * Those time segment values are passed in by the user and are based + * on the required baudrate. + * + * @param[in] id: select the CAN ID + * @param[in] timeSeg: A pointer to the CAN bit timing settings + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_SetFdDataBitTiming(CAN_Id_t id, + const CAN_BitTiming_t *timeSeg); + +/** + * @brief Configure transmit message buffer. + * + * @param[in] id: select the CAN ID + * @param[in] mbIdx: MB index + * @param[in] txInfo: TX MB info + * @param[in] msgId: message ID + * @param[in] localPrio: the local priority field, if the TX priority mode is + * CAN_TX_PRI_LOCAL_PRI_EN, this parameter indicates the + * local priority. + * + * @return status + * + * + */ +ResultStatus_t CAN_ConfigTxMb(CAN_Id_t id, uint8_t mbIdx, + const CAN_MessageInfo_t *txInfo, + uint32_t msgId, uint8_t localPrio); + +/** + * @brief Configures a transmit message buffer for remote frame response + * + * @param[in] id: select the CAN ID + * @param[in] mbIdx: MB index + * @param[in] txInfo: TX MB info + * @param[in] msgId: message ID + * @param[in] msgData: data of the message + * @param[in] localPrio: the local priority field, if the TX priority mode is + * CAN_TX_PRI_LOCAL_PRI_EN, this parameter indicates the + * local priority + * + * @return status + * + * + */ +ResultStatus_t CAN_ConfigRemoteResponseMb(CAN_Id_t id, uint8_t mbIdx, + const CAN_MessageInfo_t *txInfo, + uint32_t msgId, const uint8_t *msgData, + uint8_t localPrio); + +/** + * @brief sends a CAN frame. This function sends a CAN frame using + * a configured message buffer. Before calling this function, + * user needs to make sure that the MB to be configured is inactive, + * otherwise, it will return BUSY. + * + * @param[in] id: select the CAN ID + * @param[in] mbIdx: MB index + * @param[in] txInfo: TX MB info + * @param[in] msgId: message ID + * @param[in] msgData: data of the message + * + * @return status + * - SUCC + * - ERR: mbIdx is invalid + * - BUSY: the MB to be configured is not in inactive status + * + */ +ResultStatus_t CAN_Send(CAN_Id_t id, uint8_t mbIdx, + const CAN_MessageInfo_t *txInfo, + uint32_t msgId, const uint8_t *msgData); + +/** + * @brief sends a CAN frame when the TX priority mode is CAN_TX_PRI_LOCAL_PRI_EN + * This function sends a CAN frame using a configured message buffer. + * It also configures the local priority. Before calling this + * function, user needs to make sure that the MB to be configured + * is inactive, otherwise, it will return BUSY. + * + * + * @param[in] id: select the CAN ID + * @param[in] mbIdx: MB index + * @param[in] txInfo: TX MB info + * @param[in] msgId: message ID + * @param[in] msgData: data of the message + * @param[in] localPrio: the local priority field for the MB + * + * @return status + * - SUCC + * - ERR: mbIdx is invalid + * - BUSY: the MB to be configured is not in inactive status + * + */ +ResultStatus_t CAN_SendwithLocalPrio(CAN_Id_t id, uint8_t mbIdx, + const CAN_MessageInfo_t *txInfo, + uint32_t msgId, const uint8_t *msgData, + uint8_t localPrio); + +/** + * @brief Receive a CAN frame into a configured MB. Before calling this + * function, user needs to make sure that the MB to be configured + * is inactive, otherwise, it will return BUSY. + * + * @param[in] id: select the CAN ID + * @param[in] mbIdx: MB index + * @param[in] rxInfo: RX MB info + * @param[in] msgId: message ID + * + * @return status + * - SUCC + * - ERR: mbIdx is invalid + * - BUSY: the MB to be configured is not in inactive status + * + */ +ResultStatus_t CAN_MbReceive(CAN_Id_t id, uint8_t mbIdx, + const CAN_MessageInfo_t *rxInfo, uint32_t msgId); + +/** + * @brief Configure a Rx message buffer. + * + * @param[in] id: select the CAN ID + * @param[in] mbIdx: MB index + * @param[in] rxInfo: RX MB info + * @param[in] msgId: message ID + * + * @return status + * + * + */ +ResultStatus_t CAN_ConfigRxMb(CAN_Id_t id, uint8_t mbIdx, + const CAN_MessageInfo_t *rxInfo, uint32_t msgId); + +/** + * @brief Configure RX FIFO ID filter table elements + * + * @param[in] id: select the CAN ID + * @param[in] format: the ID filter format + * @param[in] idFilterTable: points to the ID filter table + * + * @note + * The number of elements in the ID filter table is defined by the + * following formula: + * - for format A: the number of Rx FIFO ID filters + * - for format B: twice the number of Rx FIFO ID filters + * - for format C: four times the number of Rx FIFO ID filters + * The user must provide the exact number of elements in order to avoid + * any misconfiguration. + * + * Each element in the ID filter table specifies an ID to be used as + * acceptance criteria for the FIFO as follows: + * - for format A: In the standard frame format, bits 10 to 0 of the ID + * are used for frame identification. In the extended frame format, bits + * 28 to 0 are used. + * - for format B: In the standard frame format, bits 10 to 0 of the ID + * are used for frame identification. In the extended frame format, only + * the 14 most significant bits (28 to 15) of the ID are compared to the + * 14 most significant bits (28 to 15) of the received ID. + * - for format C: In both standard and extended frame formats, only the 8 + * most significant bits(10 to 3 for standard, 28 to 21 for extended) of + * the ID are compared to the 8 most significant bits (10 to 3 for + * standard, 28 to 21 for extended) of the received ID. + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_ConfigRxFifo(CAN_Id_t id, CAN_RxFifoIdFormat_t format, + const CAN_IdFilter_t *idFilterTable); + +/** + * @brief Get a message buffer field values. + * + * @param[in] id: select the CAN ID + * @param[in] mbIdx: MB index + * @param[in] msgBuff: point to the address where the message buffer will be stored + * + * @return status + * + * + */ +ResultStatus_t CAN_GetMsgBuff(CAN_Id_t id, uint32_t mbIdx, CAN_MsgBuf_t *msgBuff); + +/** + * @brief Read a frame in RX FIFO. + * + * @param[in] id: select the CAN ID + * @param[in-out] msgBuff: point to the address where the message buffer will + * be stored + * + * @return none + * + * + */ +void CAN_ReadRxFifo(CAN_Id_t id, CAN_MsgBuf_t *msgBuff); + +/** + * @brief Sets the Rx masking type. + * + * @param[in] id: select the CAN ID + * @param[in] type: select RX mask type + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_SetRxMaskType(CAN_Id_t id, CAN_RxMask_t type); + +/** + * @brief Sets Rx FIFO global mask. It masks the Rx FIFO ID Filter Table + * elements that do not have a corresponding individual mask. + * + * @param[in] id: select the CAN ID + * @param[in] mask:Mask Value. Its format depends on the RX FIFO id filter format. + It should be set as follows: + + Format A ID mask: + bit31 | bit30 | bit29 ... 1 | bit0 + RTR | IDE(0)| IDmask(std:29-19, ext:29-1) | reserved + + Format B ID mask: + bit31 | bit30 | bit29 ... 16 | bit 15 | bit 14 | bit13 ... 0 + RTR | IDE | ID0(std:29-19, ext:29-16) | RTR | IDE | ID1 + (std:13-3, ext:13-0) + + Format C ID mask: + bit31...bit 24 | bit23...bit16 | bit15 ...bit8 | bit7 ... bit0 + IDmask0 | IDmask1 | IDmask2 | IDmask3 + + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_SetRxFifoGlobalMask(CAN_Id_t id, uint32_t mask); + +/** + * @brief Sets Rx FIFO individual mask for the specific ID filter table + * element + * + * @param[in] id: select the CAN ID + * @param[in] elementIdx: ID filter table element index. It indicates which + * filter table element the mask is corresponding to. + * It should not exceeds the MB number that is occupied + * by Rx FIFO. + * @param[in] mask:Mask Value. Its format depends on the RX FIFO id filter format. + It should be set as follows: + + Format A ID mask: + bit31 | bit30 | bit29 ... 1 | bit0 + RTR | IDE(0)| IDmask(std:29-19, ext:29-1) | reserved + + Format B ID mask: + bit31 | bit30 | bit29 ... 16 | bit 15 | bit 14 | bit13 ... 0 + RTR | IDE | IDmask0(std:29-19, ext:29-16)| RTR | IDE | IDmask1 + (std:13-3, ext:13-0) + In the extended frame format B, IDmask0/IDmask1 corresponds to + the 14 most significant bits of the received ID + + Format C ID mask: + bit31...bit 24 | bit23...bit16 | bit15 ...bit8 | bit7 ... bit0 + IDmask0 | IDmask1 | IDmask2 | IDmask3 + For format C IDmask corresponds to the 8 most significant bits of the + received ID + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_SetRxFifoIndividualMask(CAN_Id_t id, uint32_t elementIdx, + uint32_t mask); + +/** + * @brief Sets the CAN Rx MB global mask (standard or extended) + * + * @param[in] id: select the CAN ID + * @param[in] idType: Standard ID or extended ID + * @param[in] mask:Mask Value. 11-bit standard mask or 29-bit extended mask + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_SetRxMbGlobalMask(CAN_Id_t id, CAN_MsgId_t idType, + uint32_t mask); + +/** + * @brief Set Rx Message Buffer 14 mask (standard or extended) + * + * @param[in] id: select the CAN ID + * @param[in] idType: Standard ID or extended ID + * @param[in] mask:Mask Value. 11-bit standard mask or 29-bit extended mask + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_SetRxMb14Mask(CAN_Id_t id, CAN_MsgId_t idType, + uint32_t mask); + +/** + * @brief Set Rx Message Buffer 15 mask (standard or extended) + * + * @param[in] id: select the CAN ID + * @param[in] idType: Standard ID or extended ID + * @param[in] mask:Mask Value. 11-bit standard mask or 29-bit extended mask + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_SetRxMb15Mask(CAN_Id_t id, CAN_MsgId_t idType, uint32_t mask); + +/** + * @brief Sets Rx MB individual mask + * + * @param[in] id: select the CAN ID + * @param[in] idType: Standard ID or extended ID + * @param[in] mbIdx: MB index. The MB should not be occupied by RX FIFO if RX + * FIFO is enabled, otherwise, it will return ERR. + * @param[in] mask:Mask Value. 11-bit standard mask or 29-bit extended mask + * + * @return ResultStatus_t + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_SetRxMbIndividualMask(CAN_Id_t id, CAN_MsgId_t idType, + uint32_t mbIdx, uint32_t mask); + +/** + * @brief Enables the Transceiver Delay Compensation feature in CAN FD mode + * and sets the Transceiver Delay Compensation Offset (offset value + * to be added to the measured transceiver's loop delay in order to + * define the position of the delayed comparison point when bit rate + * switching is active). + * + * @param[in] id: select the CAN ID + * @param[in] offset: Transceiver Delay Compensation Offset + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_FdTdcEnable(CAN_Id_t id, uint8_t offset); + +/** + * @brief Disables the Transceiver Delay Compensation feature in CAN FD mode + * + * @param[in] id: select the CAN ID + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_FdTdcDisable(CAN_Id_t id); + +/** + * @brief Gets the value of the Transceiver Delay Compensation. + * + * @param[in] id: select the CAN ID + * + * @return The value of the transceiver loop delay measured from the transmitted + * EDL to R0 transition edge to the respective received one added to + * the TDCOFF value. + */ +uint8_t CAN_GetTdcValue(CAN_Id_t id); + +/** + * @brief Gets the value of the TDC Fail flag. + * + * @param[in] id: select the CAN ID + * + * @return If SET, indicates that the TDC mechanism is out of range, unable to + * compensate the transceiver's loop delay and successfully compare the + * delayed received bits to the transmitted ones. + */ +FlagStatus_t CAN_GetTdcFail(CAN_Id_t id); + +/** + * @brief Clears the TDC Fail flag. + * + * @param[in] id: select the CAN ID + * + * @return none + * + */ +void CAN_ClearTdcFail(CAN_Id_t id); + +/** + * @brief Set the code of a message buffer + * + * @param[in] id: select the CAN ID + * @param[in] mbIdx: Index of the message buffer. It should not be occupied by + * RX FIFO if RX FIFO is enabled, otherwise, it will return + * ERR. + * @param[in] code: the code to be set + * + * return status + * - ERR mbIdx is invalid, can not find the MB + * - SUCC + */ +ResultStatus_t CAN_SetMbCode(CAN_Id_t id, uint32_t mbIdx, CAN_MbCode_t code); + +/** + * @brief Get the code of a message buffer. + * + * @param[in] id: select the CAN ID + * @param[in] mbIdx: Index of the message buffer. It should not be occupied by + * RX FIFO if RX FIFO is enabled, otherwise, it will return + * ERR. + * @param[in] code: the code will be stored in the memory that pointed by this + * pointer + * + * @return status + * + * + */ +ResultStatus_t CAN_GetMbCode(CAN_Id_t id, uint32_t mbIdx, uint32_t *code); + +#if(CAN_ABORT_EN == 1U) +/** + * @brief Writes the abort code into the CODE field of the requested Tx message + * buffer to abort transmission. User needs to check if MB transmission + * is aborted or not after this function. It is suggested to use + * CAN_InactiveMb() to abort MB transmission instead of this function. + * + * @param[in] id: select the CAN ID + * @param[in] mbIdx: Index of the message buffer.It should not be occupied by + * RX FIFO if RX FIFO is enabled, otherwise, it will return + * ERR. + * + * @note This function is available only when CAN_ABORT_EN = 1U + * @return status + * - ERR mbIdx is invalid + * - SUCC + */ +ResultStatus_t CAN_AbortTxMb(CAN_Id_t id, uint32_t mbIdx); +#endif + +/** + * @brief if a message is received by RX FIFO, this function can get the number + * of the ID filter which the received message hit. It is only valid, + * when CAN_IFLAG1[BUF5I] is asserted. + * + * @param[in] id: select the CAN ID + * + * @return The number of the ID filter + */ +uint32_t CAN_GetRxFifoIdHit(CAN_Id_t id); + +/** + * @brief Enable/Disable global network time mechanism. If enabled, it resets + * the free running timer each time a message is received in message + * buffer 0. This feature provides means to synchronize multiple + * CAN stations with a special "SYNC" message, that is, global + * network time. If Rx FIFO is enabled, the first available mailbox, + * according to CAN_CTRL2[RFFN] setting, is used for timer + * synchronization instead of MB0. + * + * @param[in] id: select the CAN ID + * @param[in] state: ENABLE/DISABLE + * + * @return status + * - SUCC -- successful + * - ERR -- some error + */ +ResultStatus_t CAN_ControlGlobalNetworkTime(CAN_Id_t id, ControlState_t state); + +/** + * @brief Get the lowest number inactive MB + * + * @param[in] id: select the CAN ID + * + * @return the lowest number inactive MB. + * - 0 - 63: the lowest number inactive MB + * - 0xFF: it means that there is no inactive MB or it can not be read + * at this moment. + * + */ +uint8_t CAN_GetInactiveMb(CAN_Id_t id); + +/** + * @brief Enable timeout to be a wakeup source for Pretended Networking. + * + * @param[in] id: select the CAN ID + * @param[in] timeout: timeout value. + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_EnablePnTimeoutWakeup(CAN_Id_t id, uint16_t timeout); + +/** + * @brief Disable timeout to be a wakeup source for Pretended Networking. + * + * @param[in] id: select the CAN ID + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_DisablePnTimeoutWakeup(CAN_Id_t id); + +/** + * @brief Enable and config the wakeup source of receiving matched messages + * for Pretended Networking. + * + * @param[in] id: select the CAN ID + * @param[in] config: match wakeup config. + * + * @return none + * + */ +ResultStatus_t CAN_EnablePnMatchWakeup(CAN_Id_t id, + const CAN_PnMatchConfig_t *config); + +/** + * @brief Disable the wakeup source of receiving matched messages + * for Pretended Networking. + * + * @param[in] id: select the CAN ID + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_DisablePnMatchWakeup(CAN_Id_t id); + +/** + * @brief Enable and Configures Pretended Networking settings. + * + * @param[in] id: select the CAN ID + * @param[in] pnConfig: Points to the Pretended Networking configuration + * structure. + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_EnablePn(CAN_Id_t id, const CAN_PnConfig_t *pnConfig); + +/** + * @brief Disable Pretended Networking settings. + * + * @param[in] id: select the CAN ID + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_DisablePn(CAN_Id_t id); + +/** + * @brief Get a wakeup message buffer field values. + * + * @param[in] id: select the CAN ID + * @param[in] wmbIdx: wakeup MB index. Its range is 0-3. + * @param[in] msgBuff: point to the address where the message buffer will be + * stored. The size is 8 at least. + * + * @return status + * + * + */ +ResultStatus_t CAN_GetWakeupMsgBuff(CAN_Id_t id, uint32_t wmbIdx, + CAN_MsgBuf_t *msgBuff); + +/** + * @brief Enable self wakeup function. + * + * @param[in] id: select the CAN ID + * @param[in] intEn: it indicates if the self wakeup interrupt is enabled. + * If it is required to wake up the chip from stop mode + * through self wakeup. intEn has to be set to ENABLE. + * @param[in] filterEn: it indicates if the low-pass filter is enabled to + * protect the Rx CAN input from spurious wake up + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_EnableSelfWakeup(CAN_Id_t id, ControlState_t intEn, + ControlState_t filterEn); + +/** + * @brief Disable self wakeup function. + * + * @param[in] id: select the CAN ID + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_DisableSelfWakeup(CAN_Id_t id); + +/** + * @brief Enable enter into doze mode when received entering into wait mode + * request. + * + * @param[in] id: select the CAN ID + * + * @return none + * + */ +void CAN_EnableDozeMode(CAN_Id_t id); + +/** + * @brief Disable enter into doze mode when received entering into wait mode + * request. + * + * @param[in] id: select the CAN ID + * + * @return none + * + */ +void CAN_DisableDozeMode(CAN_Id_t id); + +/** + * @brief config the action when received a remote request frame + * + * @param[in] id: select the CAN ID + * @param[in] autoResponse: config if remote response frame is transmitted + * automatically after receiving a remote request frame. + * - ENABLE: The received remote request frame is not + * stored and remote response frame, which is + * configured through function + * CAN_ConfigRemoteResponseMb() is transmitted + * automatically + * - DISABLE: remote request frame is stored in the + * same fashion of a data frame in a RX message + * buffer, configured through function CAN_MbReceive(), + * no automatic remote response is transmitted. + * if RXFIFO is enabled and used to receive remote + * request, remote request frame is stored and no + * automatic remote response is transmitted. + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_RemoteFrameConfig(CAN_Id_t id, ControlState_t autoResponse); + + +/** + * @brief Install callback function for CAN_INT_BUS_OFF, CAN_INT_ERR, + CAN_INT_TXW, CAN_INT_RXW, CAN_INT_BUS_OFF_DONE, CAN_INT_ERR_FAST, + CAN_INT_WAKEUP, CAN_INT_RXFIFO_FRAME, CAN_INT_RXFIFO_WARNING, + CAN_INT_RXFIFO_OVERFLOW, CAN_INT_HOST_MEM_ERR, CAN_INT_CAN_MEM_ERR, + CAN_INT_COR_MEM_ERR + * + * @param[in] id: select the CAN ID + * @param[in] intType: select interrupt type + * @param[in] cbFun: indicate callback function + * + * @return none + * + */ +void CAN_InstallCallBackFunc(CAN_Id_t id, CAN_Int_t intType, isr_cb_t * cbFun); + +/** + * @brief Install callback function for MB interrupt + * + * @param[in] id: select the CAN ID + * @param[in] mbCbf: indicate callback function + * + * @return none + * + */ +void CAN_InstallMbCallBackFunc(CAN_Id_t id, can_mb_cb_t mbCbf); + +/** + * @brief Interrupt mask/unmask + * + * @param[in] id: select the CAN ID + * @param[in] intType: interrupt to be masked/unmasked + * @param[in] intMask: MASK/UNMASK + * @param[in] mb0t31: if intType is CAN_INT_MB, this parameter selects the MBs + * (MB0-MB31) to be configured. Each bit corresponds a MB + * (bit0 - MB0, bit1 - MB1, ... ,bit31 - MB31). If a bit + * is 1,it means the corresponding MB to be configured. + * @param[in] mb32t63: if intType is CAN_INT_MB, this parameter selects the MBs + * (MB32-MB63) to be configured. Each bit corresponds a MB + * (bit0 - MB32, bit1 - MB33, ... ,bit31 - MB63). If a bit + * is 1,it means the corresponding MB to be configured. + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_IntMask(CAN_Id_t id, CAN_Int_t intType, IntMask_t intMask, + uint32_t mb0t31, uint32_t mb32t63); + +/** + * @brief MB Interrupt mask/unmask + * + * @param[in] id: select the CAN ID + * @param[in] mbIdx: the MB index + * @param[in] intMask: MASK/UNMASK + * + * @return status + * -ERR + * -SUCC + * + */ +ResultStatus_t CAN_MbIntMask(CAN_Id_t id, uint32_t mbIdx,IntMask_t intMask); + +/** + * @brief Clear interrupt + * + * @param[in] id: select the CAN ID + * @param[in] intType: select interrupt type +* @param[in] mb0t31: if intType is CAN_INT_MB, this parameter selects the MBs + * (MB0-MB31) to be configured. Each bit corresponds a MB + * (bit0 - MB0, bit1 - MB1, ... ,bit31 - MB31). If a bit + * is 1,it means the corresponding MB to be configured. + * For other interrupt type, this parameter can be ignored. + * @param[in] mb32t63: if intType is CAN_INT_MB, this parameter selects the MBs + * (MB32-MB63) to be configured. Each bit corresponds a MB + * (bit0 - MB32, bit1 - MB33, ... ,bit31 - MB63). If a bit + * is 1,it means the corresponding MB to be configured. + * For other interrupt type, this parameter can be ignored. + * + * @return none + * + */ +void CAN_IntClear(CAN_Id_t id, CAN_Int_t intType, uint32_t mb0t31, + uint32_t mb32t63); + +/** + * @brief Get ESR1 buffer in interrupt call back functions. The ESR1 + * will be stored into ESR1 buffer in CAN_IntHandler. + * If the call back functions which are installed through + * CAN_InstallCallBackFunc() needs to get the ESR1 , please use + * this function instead of CAN_GetIntStatus or CAN_GetStatus. + * + * @param[in] id: Select the CAN port,should be CAN0_ID , CAN1_ID + * + * @return ESR1 Buff Value + * + */ +uint32_t CAN_GetESR1BufForCbf(CAN_Id_t id); + +/** + * @brief Get CAN status from ESR1 Buff + * + * @param[in] id: select the CAN ID + * @param[in] status: the status to be get + * + * @return status + * - SET + * - RESET + * + */ +FlagStatus_t CAN_GetStatusFromESR1Buf(CAN_Id_t id, CAN_Status_t status); + +/** + * @brief Get interrupt status + * + * @param[in] id: select the CAN ID + * @param[in] intType: select interrupt type + * @param[in] mbId: if intType is CAN_INT_MB, this parameter selects the MB + * (MB0-MB63) status to be get + * + * @return status + * - SET + * - RESET + * + */ +IntStatus_t CAN_GetIntStatus(CAN_Id_t id, CAN_Int_t intType, uint32_t mbId); + +/** + * @brief Get CAN state + * + * @param[in] id: select the CAN ID + * + * @return CAN state + * + */ +CAN_State_t CAN_GetState(CAN_Id_t id); + +/** + * @brief Get CAN status + * + * @param[in] id: select the CAN ID + * @param[in] status: the status to be get + * + * @return status + * - SET + * - RESET + * + */ +FlagStatus_t CAN_GetStatus(CAN_Id_t id, CAN_Status_t status); + +/** + * @brief Clear CAN status + * + * @param[in] id: select the CAN ID + * @param[in] status: the status to clear + * + * @return none + * + */ +void CAN_ClearStatus(CAN_Id_t id, CAN_Status_t status); + +/** + * @brief Get CAN Fault Confinement State + * + * @param[in] id: select the CAN ID + * + * @return CAN Fault Confinement State + * + */ +CAN_FaultConfState_t CAN_GetFaultConfinementState(CAN_Id_t id); + +/** + * @brief make the MB to inactive status and disable the interrupt of this + * MB. The MBs occupied by RX FIFO can not be handle by this function. + * If MB is RX MB, it will become CAN_MB_RX_INACTIVE after + * this function; if MB is TX MB, it will become CAN_MB_TX_INACTIVE + * or CAN_MB_TX_ABORT after this function. + * + * @param[in] id: select the CAN ID + * @param[in] mbIdx: MB index + * + * @return status + * + * + */ +ResultStatus_t CAN_InactiveMb(CAN_Id_t id, uint8_t mbIdx); + +/** + * @brief It selects How CAN recovers from bus off state. If + * CAN_BUS_OFF_RECOV_AUTO is selected, automatic recovering from Bus + * Off state occurs according to the CAN Specification. If + * CAN_BUS_OFF_RECOV_MANUAL is selected, user can call + * CAN_RecoverFromBusOffManually() to recover from bus off state. + * + * @param[in] id: select the CAN ID + * @param[in] recov: It selects how to recover from bus off. + + * @note this function shall be called before entering bus off state. If CAN + * recovers from bus off manually through CAN_RecoverFromBusOffManually(), + * and user need to select CAN_BUS_OFF_RECOV_MANUAL for the next time, + * this function shall be called again. + * + * @return none + * + * + */ +void CAN_BusOffRecoveryScheme(CAN_Id_t id, CAN_BusOffRecovery_t recov); + +/** + * @brief Once CAN is in bus off state and bus off recovery scheme is + * CAN_BUS_OFF_RECOV_MANUAL, which is selected through + * CAN_BusOffRecoveryScheme(), call this function can recover from + * bus off state manually. + * + * @param[in] id: select the CAN ID + * + * @return none + * + * + */ +void CAN_RecoverFromBusOffManually(CAN_Id_t id); + +/** @} end of group CAN_Public_FunctionDeclaration */ + +/** @} end of group CAN */ + +/** @} end of group Z20K11X_Peripheral_Driver */ +#endif /* Z20K11XM_CAN_H */ diff --git a/StdDriver/Inc/Z20K11xM_clock.h b/StdDriver/Inc/Z20K11xM_clock.h new file mode 100644 index 0000000..beea9a8 --- /dev/null +++ b/StdDriver/Inc/Z20K11xM_clock.h @@ -0,0 +1,533 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_clock.h + * @brief : Clock driver module header file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (C) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + * + **************************************************************************************************/ + +#ifndef Z20K11XM_CLOCK_H +#define Z20K11XM_CLOCK_H + +#include "Z20K11xM_drv.h" + +/** @addtogroup Z20K11X_Peripheral_Driver + * @{ + */ + +/** @addtogroup Clock + * @{ + */ + +/** @defgroup Clock_Public_Types + * @{ + */ + +/** + * @brief clock source option + */ +typedef enum +{ + CLK_SRC_NO = 0U, /*!< none is selected */ + CLK_SRC_LPO32K, /*!< LPO32K */ + CLK_SRC_OSC32K, /*!< OSC32K */ + CLK_SRC_FIRC64M, /*!< FIRC64M */ + CLK_SRC_OSC40M /*!< OSC40M */ +}CLK_Src_t; + +/** + * @brief system clock source option + */ +typedef enum +{ + CLK_SYS_OSC40M = 0U, /*!< OSC40M System Clock */ + CLK_SYS_FIRC64M /*!< FIRC64M System Clock */ +}CLK_System_t; + +/** + * @brief OSC40M/OSC32K mode option + */ +typedef enum +{ + CLK_OSC_XTAL = 0U, /*!< crystal: OSC clock comes from crystal oscillator */ + CLK_OSC_EXT_SRC /*!< external source: OSC clock comes from a external + square wave clock source */ +}CLK_OscMode_t; + +/** + * @brief OSC40M frequency mode option + */ +typedef enum +{ + CLK_OSC_FREQ_MODE_LOW = 0U, /*!< OSC40M clock works in low frequency mode */ + CLK_OSC_FREQ_MODE_HIGH /*!< OSC40M clock works in high frequency mode */ +}CLK_OscFreqMode_t; + +/** + * @brief The action option if lock of clock is detected + */ +typedef enum +{ + CLK_MON_INT = 0U, /*!< Generat interrupt if loss of + clock is detected */ + CLK_MON_RST /*!< reset if loss of clock is detected */ +}CLK_MonitorAct_t; + +/** + * @brief clock divider type + */ +typedef enum +{ + CLK_DIV_1 = 0U, /*!< clock divided by 1 */ + CLK_DIV_2, /*!< clock divided by 2 */ + CLK_DIV_3, /*!< clock divided by 3 */ + CLK_DIV_4, /*!< clock divided by 4 */ + CLK_DIV_5, /*!< clock divided by 5 */ + CLK_DIV_6, /*!< clock divided by 6 */ + CLK_DIV_7, /*!< clock divided by 7 */ + CLK_DIV_8, /*!< clock divided by 8 */ + CLK_DIV_9, /*!< clock divided by 9 */ + CLK_DIV_10, /*!< clock divided by 10 */ + CLK_DIV_11, /*!< clock divided by 11 */ + CLK_DIV_12, /*!< clock divided by 12 */ + CLK_DIV_13, /*!< clock divided by 13 */ + CLK_DIV_14, /*!< clock divided by 14 */ + CLK_DIV_15, /*!< clock divided by 15 */ + CLK_DIV_16, /*!< clock divided by 16 */ +}CLK_Divider_t; + +typedef enum +{ + CLK_OUT_DIV_1 = 0U, /*!< clock divided by 1 */ + CLK_OUT_DIV_2 = 1U, /*!< clock divided by 2 */ + CLK_OUT_DIV_4 = 2U, /*!< clock divided by 4 */ + CLK_OUT_DIV_8 = 3U /*!< clock divided by 8 */ +}CLK_OutDiv_t; + +/** + * @brief output clock source option + */ +typedef enum +{ + CLK_OUT_FIRC64M = 1U, /*!< FIRC64M Clock */ + CLK_OUT_OSC40M = 2U, /*!< OSC40M Clock */ + CLK_OUT_SLOW = 8U, /*!< SLOW Clock */ + CLK_OUT_BUS = 9U, /*!< BUS Clock */ + CLK_OUT_CORE = 10U, /*!< CORE Clock */ + CLK_OUT_OSC32K = 11U, /*!< OSC32K Clock */ + CLK_OUT_LPO32K =12U /*!< LPO32K Clock */ +}CLK_OutSrc_t; + + +/** + * @brief TIM External clock source option + */ +typedef enum +{ + CLK_TIM_PTB1 = 0U, /*!< PTB1 pin */ + CLK_TIM_PTE1_PTA5, /*!< PTE1/PTA5 pin */ + CLK_TIM_PTE8 /*!< PTE8 pin*/ +}CLK_TIMExtClk_t; + +/** + * @brief TIM ID for clock selction + */ +typedef enum +{ + CLK_TIM0_ID = 0U, /*!< TIM0 pin */ + CLK_TIM1_ID, /*!< TIM1 pin */ + CLK_TIM2_ID /*!< TIM2 pin*/ +}CLK_TIM_t; + + +/** + * @brief clock interrupt type definition + */ +typedef enum +{ + CLK_INT_OSCLOC = 0U, /*!< OSC40M loss of clock interrupt */ + CLK_INT_FIRCLOC = 1U, /*!< FIRC64M loss of clock interrupt */ + CLK_INT_ALL /*!< all interrupt */ +}CLK_Int_t; + +/** + * @brief clock module type definition + */ +typedef enum +{ + CLK_EWDT = 0x04U, /*!< EWDT */ + CLK_STIM = 0x08U, /*!< STIM */ + CLK_TIM0 = 0x0CU, /*!< TIM0 */ + CLK_TIM1 = 0x10U, /*!< TIM1 */ + CLK_TIM2 = 0x14U, /*!< TIM2 */ + CLK_TDG0 = 0x18U, /*!< TDG0 */ + CLK_CAN0 = 0x1CU, /*!< CAN0 */ + CLK_CAN1 = 0x20U, /*!< CAN1 */ + CLK_UART0 = 0x24U, /*!< UART0 */ + CLK_UART1 = 0x28U, /*!< UART1 */ + CLK_UART2 = 0x2CU, /*!< UART2 */ + CLK_UART3 = 0x30U, /*!< UART3 */ + CLK_SPI0 = 0x34U, /*!< SPI0 */ + CLK_SPI1 = 0x38U, /*!< SPI1 */ + CLK_SPI2 = 0x3CU, /*!< SPI2 */ + CLK_I2C0 = 0x40U, /*!< I2C0 */ + CLK_I2C1 = 0x44U, /*!< I2C1 */ + CLK_ADC0 = 0x48U, /*!< ADC0 */ + CLK_CMP = 0x4cU, /*!< CMP */ + CLK_CRC = 0x50U, /*!< CRC */ + CLK_FLASH = 0x54U, /*!< FLASH */ + CLK_DMA = 0x58U, /*!< DMA */ + CLK_DMAMUX = 0x5CU, /*!< DMAMUX */ + CLK_PORTA = 0x60U, /*!< PORTA */ + CLK_PORTB = 0x64U, /*!< PORTB */ + CLK_PORTC = 0x68U, /*!< PORTC */ + CLK_PORTD = 0x6cU, /*!< PORTD */ + CLK_PORTE = 0x70U, /*!< PORTE */ + + /* below define are only used for CLK_SetClkDivider */ + CLK_CORE = 0x85U, /*!< Core */ + CLK_BUS = 0x86U, /*!< Bus */ + CLK_SLOW = 0x87U /*!< Slow */ + +}CLK_Module_t; + + +/** @} end of group Clock_Public_Types */ + +/** @defgroup Clock_Public_Constants + * @{ + */ + +/** @} end of group Clock_Public_Constants */ + +/** @defgroup Clock_Public_Macro + * @{ + */ + +/** @} end of group Clock_Public_Macro */ + +/** @defgroup Clock_Public_FunctionDeclaration + * @brief Clock functions declaration + * @{ + */ + +/** + * @brief Enable FIRC64M clock and set enablement in stop mode + * + * @param[in] stopModeEn: Enable/Disable FIRC64M in stop mode. + * + * @return none + * + */ +void CLK_FIRC64MEnable(ControlState_t stopModeEn); + +/** + * @brief Get system clock source. + * + * @param[in] none. + * + * @return + * -CLK_SYS_FIRC64M + * -CLK_SYS_OSC40M + * + */ +CLK_System_t CLK_GetSysClkSrc(void); + +/** + * @brief Disable FIRC64M clock + * + * @param[in] none. + * + * @return none + * + */ +void CLK_FIRC64MDisable(void); + +/** + * @brief It is suggested to use CLK_OSC40MEnable2() instead of this + * function. It Configures and enables OSC40M clock. The frequency + * mode is selected according to the 'freq' parameter. However, the + * selection may be not accurate. + * + * @param[in] freq: the frequency of OSC40M, unit/MHz. The value should be + * between 4 and 40. If 4<= freq <= 24, CLK_OSC_FREQ_MODE_LOW + * is selected for the frequency mode; if 24< freq <= 40, + * CLK_OSC_FREQ_MODE_HIGH is selected for the frequency mode. + * @param[in] stopModeEn: Enable/Disable OSC40M in stop mode. + * @param[in] mode: select OSC mode. It selects from crystal oscillator or + * external square wave clock source. + * + * @note It is suggested to use CLK_OSC40MEnable2() instead of this function. + * + * + * @return status + * - ERR - some error. + * - SUCC - successful + * + */ +ResultStatus_t CLK_OSC40MEnable(uint32_t freq, ControlState_t stopModeEn, + CLK_OscMode_t mode); + +/** + * @brief Configure and enable OSC40M clock + * + * @param[in] freqMode: It selects the frequency mode of OSC40M + * @param[in] stopModeEn: Enable/Disable OSC40M in stop mode. + * @param[in] mode: select OSC mode. It selects from crystal oscillator or + * external square wave clock source. + + * + * @return status + * - ERR - some error. + * - SUCC - successful + * + */ +ResultStatus_t CLK_OSC40MEnable2(CLK_OscFreqMode_t freqMode, + ControlState_t stopModeEn, + CLK_OscMode_t mode); + +/** + * @brief Disable OSC40M clock + * + * @param[in] none. + * + * @return none + * + */ +void CLK_OSC40MDisable(void); + +/** + * @brief Select system clock. + * + * @param[in] clk: select the clock source + * + * @return + * - SUCC: the system clock is selected successfully + * - ERR: fail + * @note The selected clock source has to be ready + * before call this function. + * + */ +ResultStatus_t CLK_SysClkSrc(CLK_System_t clk); + +/** + * @brief Config and Enable OSC40M loss of clock monitor + * + * @param[in] act: select the action when loss of clock is detected. + * + * @return none + * + */ +void CLK_OSC40MMonitorEnable(CLK_MonitorAct_t act); + +/** + * @brief Disable OSC40M loss of clock monitor + * + * @param[in] none. + * + * @return none + * + */ +void CLK_OSC40MMonitorDisable(void); + +/** + * @brief Config and Enable FIRC64M loss of clock monitor + * + * @param[in] act: select the action when loss of clock is detected. + * + * @return none + * + */ +void CLK_FIRC64MMonitorEnable(CLK_MonitorAct_t act); + +/** + * @brief Config and Enable FIRC64M loss of clock monitor + * + * @param[in] none + * + * @return none + * + */ +void CLK_FIRC64MMonitorDisable(void); + +/** + * @brief Config and Enable LPO32K clock + * + * @param[in] none + * + * @return none + * + */ +void CLK_LPO32KEnable(void); + +/** + * @brief Disable LPO32K clock + * + * @param[in] none. + * + * @return none + * + */ +void CLK_LPO32KDisable(void); + +/** + * @brief Config and Enable OSC32K clock + * + * @param[in] mode: select OSC mode. It selects from crystal oscillator or + * external square wave clock source. + * @return none + * + */ +void CLK_OSC32KEnable(CLK_OscMode_t mode); + +/** + * @brief Disable OSC32K clock + * + * @param[in] none + * + * @return none + * + */ +void CLK_OSC32KDisable(void); + +/** + * @brief Set clock divider + * + * @param[in] module: select which module clock to set divider. + * It selects from CLK_EWDT, CLK_STIM, CLK_TIM0, + * CLK_TIM1, CLK_TIM2, CLK_TDG0, CLK_CAN0, CLK_CAN1, + * CLK_UART0, CLK_UART1, CLK_UART2, CLK_UART3, + * CLK_SPI0, CLK_SPI1, CLK_SPI2, CLK_I2C0, CLK_I2C1, + * CLK_ADC0, CLK_PORTA,CLK_PORTB, CLK_PORTC, CLK_PORTD, + * CLK_PORTE CLK_CORE, CLK_BUS, CLK_SLOW + * + * @param[in] divider: clock divider + * @return none + * + */ +void CLK_SetClkDivider(CLK_Module_t module, CLK_Divider_t divider); + +/** + * @brief Select clock source for module + * + * @param[in] module: select which module to set clock source. + * It selects from CLK_EWDT, CLK_STIM, CLK_TIM0, CLK_TIM1, + * CLK_TIM2, CLK_TDG0, CLK_CAN0, CLK_CAN1, CLK_UART0, + * CLK_UART1, CLK_UART2, CLK_UART3, CLK_SPI0, CLK_SPI1, + * CLK_SPI2, CLK_I2C0, CLK_I2C1, CLK_ADC0, CLK_PORTA, + * CLK_PORTB, CLK_PORTC, CLK_PORTD, CLK_PORTE + * + * @param[in] clockSource: select clock source + * @note For CAN0 CAN1, the clock source can only select from CLK_SRC_FIRC64M + * CLK_SRC_OSC40M,CLK_SRC_NO. + * For ADC0, the clock source can only select from CLK_SRC_FIRC64M, + * CLK_SRC_NO. + * This function should only be called when the module is not working, + * otherwise, the clock source will not change. + * @return + * - SUCC + * - ERR: the input parameter is unreasonable. + * + */ +ResultStatus_t CLK_ModuleSrc(CLK_Module_t module, CLK_Src_t clockSource); + +/** + * @brief Select TIM external clock source. If TIM is configured to use + * external clock source, this function can select a external clock + * source from a pin. + * + * @param[in] timId: it indicates which TIM to config + * @param[in] clockSrc: select the external TIM clock source + * + * @return None + * + */ +void CLK_TimExternalClkSrc(CLK_TIM_t timId, CLK_TIMExtClk_t clockSrc); + +/** + * @brief Config and Enable clock output + * + * @param[in] outSrc: Select the clock source to be output. + * @param[in] divider: output clock divider + * + * @return none + * + */ +void CLK_ClkOutEnable(CLK_OutSrc_t outSrc, CLK_OutDiv_t divider); + +/** + * @brief Disable clock output + * + * @param[in] none + * + * @return none + * + */ +void CLK_ClkOutDisable(void); + +/** + * @brief get module clock frequency before divider + * + * @param[in] module: select the module + * @param[in] oscFreq: frequency of the OSC clock + * + * @return The clock frequency. If return 0, there is some error. + * + */ +uint32_t CLK_GetModuleClkFreq(CLK_Module_t module,uint32_t oscFreq); + +/** + * @brief Get the clock source status + * + * @param[in] clockSource: it can get status of CLK_OUT_LPO32K,CLK_OUT_FIRC64M, + * CLK_OUT_OSC32K,CLK_OUT_OSC40M + * + * @return The clock source status + * + */ +FlagStatus_t CLK_GetClkStatus(CLK_Src_t clockSource); + +/** + * @brief Wait the clock source status until it is ready + * + * @param[in] clockSource: the clock source to be waited + * + * @return + * - SUCC -- the clock is ready + * - ERR -- time out + * + */ +ResultStatus_t CLK_WaitClkReady(CLK_Src_t clockSource); + +/** + * @brief install call back function + * + * @param[in] intId: select the interrupt + * @param[in] cbFun: pointer to callback function + * + * @return none + * + */ +void SCC_InstallCallBackFunc(CLK_Int_t intId,isr_cb_t * cbFun); + +/** + * @brief Clear Interrupt status + * + * @param[in] intId: select the interrupt + * + * @return none + * + */ +void SCC_IntClear(CLK_Int_t intId); + +/** @} end of group Clock_Public_FunctionDeclaration */ + +/** @} end of group Clock */ + +/** @} end of group Z20K11X_Peripheral_Driver */ +#endif /* Z20K11XM_CLOCK_H */ diff --git a/StdDriver/Inc/Z20K11xM_cmp.h b/StdDriver/Inc/Z20K11xM_cmp.h new file mode 100644 index 0000000..8b8a153 --- /dev/null +++ b/StdDriver/Inc/Z20K11xM_cmp.h @@ -0,0 +1,362 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_cmp.h + * @brief : CMP module driver header file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ + +#ifndef Z20K11XM_CMP_H +#define Z20K11XM_CMP_H + +#include "Z20K11xM_drv.h" + +/** @addtogroup Z20K11X_Peripheral_Driver + * @{ + */ + +/** @addtogroup CMP + * @{ + */ + +/** @defgroup CMP_Public_Types + * @{ + */ + +/** + * @brief CMP trigger type definition + */ +typedef enum +{ + CMP_SW_TRIGGER = 0U, /*!< software trigger */ + CMP_HW_TRIGGER /*!< hardware trigger by trigger signal from TMU*/ +}CMP_Trigger_t; + +/** + * @brief CMP speed type definition + */ +typedef enum +{ + CMP_SPEED_LOW = 0U, /*!< speed: low */ + CMP_SPEED_HIGH /*!< speed: high */ +}CMP_Speed_t; + +/** + * @brief CMP hysteresis in low-speed mode type definition + */ +typedef enum +{ + CMP_HYST_L_NO = 0U, /*!< hysteresis in low-speed mode: no hysteresis */ + CMP_HYST_L_16MV, /*!< hysteresis in low-speed mode: 16mv */ + CMP_HYST_L_25MV, /*!< hysteresis in low-speed mode: 25mv */ + CMP_HYST_L_32MV /*!< hysteresis in low-speed mode: 32mv */ +}CMP_HystLowSpeed_t; + +/** + * @brief CMP hysteresis in high-speed mode type definition + */ +typedef enum +{ + CMP_HYST_H_NO = 0U, /*!< hysteresis in high-speed mode: no hysteresis */ + CMP_HYST_H_21MV, /*!< hysteresis in high-speed mode: 21mv */ + CMP_HYST_H_34MV, /*!< hysteresis in high-speed mode: 34mv */ + CMP_HYST_H_45MV /*!< hysteresis in high-speed mode: 45mv */ +}CMP_HystHighSpeed_t; + +/** + * @brief CMP output selection type definition + */ +typedef enum +{ + CMP_OUT_FILTER_SAMPLE = 0U, /*!< output after filter/sample */ + CMP_OUT_WINDOW /*!< output after window */ +}CMP_Output_t; + +/** + * @brief CMP input selection type definition + */ +typedef enum +{ + CMP_IN_0 = 0U, /*!< CMP0_IN0 pin*/ + CMP_IN_1, /*!< CMP0_IN1 pin*/ + CMP_IN_2, /*!< CMP0_IN2 pin */ + CMP_IN_3, /*!< CMP0_IN3 pin */ + CMP_IN_4, /*!< CMP0_IN4 pin*/ + CMP_IN_5, /*!< CMP0_IN5 pin*/ + CMP_IN_6, /*!< CMP0_IN6 pin*/ + CMP_IN_7, /*!< CMP0_IN7 pin*/ + CMP_IN_8, /*!< CMP0_IN8 pin*/ + CMP_IN_9, /*!< CMP0_IN9 pin*/ + CMP_IN_10, /*!< CMP0_IN10 pin*/ + CMP_IN_11, /*!< CMP0_IN11 pin*/ + CMP_IN_12, /*!< CMP0_IN12 pin*/ + CMP_IN_13, /*!< CMP0_IN13 pin*/ + CMP_IN_DACOUT = 15U /*!< DAC Output */ +}CMP_In_t; + +/** + * @brief CMP output level when window is closed type definition + */ +typedef enum +{ + CMP_WIN_OUT_LVL_LAST = 0U, /*!< COUTA hold the value of the last sample */ + CMP_WIN_OUT_LVL_0, /*!< COUTA is 0 when window is closed */ + CMP_WIN_OUT_LVL_1 /*!< COUTA is 1 when window is closed */ +}CMP_WinOutLvl_t; + +/** + * @brief CMP working mode type definition + */ +typedef enum +{ + CMP_MODE_BASIC = 0U, /*!< basic mode: the analog output is not handled by + window/filter/sample */ + CMP_MODE_WINDOW, /*!< window mode: the analog output is processed + by window signal from TMU */ + CMP_MODE_FILTER, /*!< filter mode: the analog output is processed + by filter*/ + CMP_MODE_SAMPLE, /*!< sample mode: the analog output is sampled by + signal from TMU */ + CMP_MODE_WINDOW_FILTER /*!< window + filter mode: the analog output is + first processed by window signal from TMU, + then it is processed by filter */ +}CMP_Mode_t; + +/** + * @brief CMP interrupt/DMA request option type definition + */ +typedef enum +{ + CMP_REQ_INT = 0U, /*!< generate interrupt request on rising/falling edge + of output */ + CMP_REQ_DMA /*!< generate DMA request on rising/falling edge of output*/ +}CMP_Request_t; + +/** + * @brief CMP interrupt type definition + */ +typedef enum +{ + CMP_INT_RAISE = 0U, /*!< output raising edge interrupt */ + CMP_INT_FALL, /*!< output falling edge interrupt */ + CMP_INT_ALL /*!< all interrupt */ +}CMP_Int_t; + +/** + * @brief DAC reference voltage type definition + */ +typedef enum +{ + CMP_DAC_VREF_VDDA = 0U, /*!< VDDA */ + CMP_DAC_VREF_VREFH /*!< VREFH */ +}CMP_DACVref_t; + + +/** + * @brief CMP configuration structure type definition + */ +typedef struct +{ + CMP_Speed_t speed; /*!< speed */ + union + { + CMP_HystLowSpeed_t ls; + CMP_HystHighSpeed_t hs; + }hyst; /*!< hysteresis */ + CMP_In_t pIn; /*!< positive input selection */ + CMP_In_t nIn; /*!< Negative input selection */ + CMP_Mode_t mode; /*!< select working mode */ + CMP_Request_t req; /*!< generate Interrupt or DMA request on + rising/falling edge of output */ + ControlState_t invertEn; /*!< whether invert cout + - ENABLE: invert + - DISABLE: not invert */ + ControlState_t outToPad; /*!< whether output to pad + - ENABLE: output to pad + - DISABLE: do not output to pad */ + ControlState_t stopReqEn; /*!< whether generate interrupt/DMA in stop + mode */ +}CMP_Config_t; + + + +/** @} end of group CMP_Public_Types */ + +/** @defgroup CMP_Public_Constants + * @{ + */ + +/** @} end of group CMP_Public_Constants */ + +/** @defgroup CMP_Public_Macro + * @{ + */ + +/** @} end of group CMP_Public_Macro */ + +/** @defgroup CMP_Public_FunctionDeclaration + * @brief CMP functions declaration + * @{ + */ + +/** + * @brief Initialize CMP + * + * @param[in] cfg: the configuration parameters. + * if cfg->mode == CMP_MODE_WINDOW or CMP_MODE_WINDOW_FILTER, + * CMP_WindowConfig() need to be called to config window para. + * if cfg->mode == CMP_MODE_FILTER or CMP_MODE_WINDOW_FILTER, + * CMP_FilterConfig() need to be called to config filter para. + * + * @return none + * + */ +void CMP_Init(const CMP_Config_t * cfg); + +/** + * @brief Config filter parameters + * + * @param[in] cnt: the consecutive sample count number that agree the output + * value to be changed. The range is 1 - 7. If it is 0, the + * filter is bypassed. + * @param[in] period: the sampling period in bus clock of the output filter. + * The range is 1-0xff. If it is 0, filter is bypassed + * + * @return None + * + */ +void CMP_FilterConfig(uint32_t cnt, uint32_t period); + +/** + * @brief Config window mode parameter + * + * @param[in] closedLvl: Select the output level when window is closed + * + * @return None + * + */ +void CMP_WindowConfig(CMP_WinOutLvl_t closedLvl); + +/** + * @brief select the output + * + * @param[in] out: select the output + * + * @return None + * + */ +void CMP_SelectOutput(CMP_Output_t out); + +/** + * @brief Initialize DAC + * + * @param[in] vref: Select the reference voltage + * + * @return None + * + */ +void CMP_DacInit(CMP_DACVref_t vref); + +/** + * @brief Enable DAC + * + * @param[in] None + * + * @return None + * + */ +void CMP_DacEnable(void); + +/** + * @brief Disable DAC + * + * @param[in] None + * + * @return None + * + */ +void CMP_DacDisable(void); + +/** + * @brief set DAC output value + * + * @param[in] data: the data to be converted. The range is 0 - 0xFF. + * + * @return None + * + */ +void CMP_DacSetValue(uint8_t data); + +/** + * @brief Trigger CMP + * + * @param[in] type: select how to trigger the CMP + * + * @return none + * + */ +void CMP_Trigger(CMP_Trigger_t type); + +/** + * @brief Clear CMP trigger + * + * @param[in] none + * + * @return none + * + */ +void CMP_TriggerClear(void); + +/** + * @brief Get CMP output value + * + * @param[in] none + * + * @return 0 -- low level + * 1 -- high level + * + */ +uint32_t CMP_GetOutput(void); + +/** + * @brief Install callback function + * + * @param[in] intType: select interrrupt type + * @param[in] cbFun: indicate callback function + * + * @return none + * + */ +void CMP_InstallCallBackFunc(CMP_Int_t intType, isr_cb_t * cbFun); + +/** + * @brief Mask/Unmask interrupt + * + * @param[in] intType: select interrrupt type + * @param[in] intMask: MASK/UNMASK + * + * @return none + * + */ +void CMP_IntMask(CMP_Int_t intType, IntMask_t intMask); + +/** + * @brief Clear interrupt + * + * @param[in] intType: select interrrupt type + * + * @return none + * + */ +void CMP_IntClear(CMP_Int_t intType); + +/** @} end of group CMP_Public_FunctionDeclaration */ + +/** @} end of group CMP */ + +/** @} end of group Z20K11X_Peripheral_Driver */ +#endif /* Z20K11XM_CMP_H__ */ diff --git a/StdDriver/Inc/Z20K11xM_crc.h b/StdDriver/Inc/Z20K11xM_crc.h new file mode 100644 index 0000000..56b75bf --- /dev/null +++ b/StdDriver/Inc/Z20K11xM_crc.h @@ -0,0 +1,158 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_crc.h + * @brief : CRC driver module header file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ + +#ifndef Z20K11XM_CRC_H +#define Z20K11XM_CRC_H + +#include "Z20K11xM_drv.h" + +/** @addtogroup Z20K11X_Peripheral_Driver + * @{ + */ + +/** @addtogroup CRC + * @{ + */ + +/** @defgroup CRC_Public_Types + * @{ + */ + +/** + * @brief CRC mode type definition + */ + +typedef enum +{ + CRC_MODE_16BIT = 0U, /*!< 16-bit CRC protocol mode */ + CRC_MODE_32BIT /*!< 32-bit CRC protocol mode */ +} CRC_Mode_t; + +/** + * @brief CRC complement read type definition + */ +typedef enum +{ + CRC_COMPREAD_NO_XOR = 0U, /*!< No XOR on reading */ + CRC_COMPREAD_INVERT_COMP /*!< Invert or complement the read value of the CRC Data register */ +} CRC_CompRead_t; + +/** + * @brief CRC read type Of transpose type definition + */ +typedef enum +{ + CRC_READ_NO = 0U, /*!< No transposition */ + CRC_READ_BIT_Y_BYTE_N, /*!< Bits in bytes are transposed;bytes are not transposed */ + CRC_READ_BIT_Y_BYTE_Y, /*!< Both bits in bytes and bytes are transposed */ + CRC_READ_BIT_N_BYTE_Y /*!< Only bytes are transposed;no bits in a byte are transposed */ +} CRC_TransposeRead_t; + +/** + * @brief CRC write type Of transpose type definition + */ +typedef enum +{ + CRC_WRITE_NO = 0U, /*!< No transposition */ + CRC_WRITE_BIT_Y_BYTE_N /*!< Bits in bytes are transposed; bytes are not transposed */ +} CRC_TransposeWrite_t; + +/** + * @brief CRC Configuration Structure type definition + */ +typedef struct +{ + uint32_t seedValue; /*!< Write seed values */ + uint32_t poly; /*!< Polynomial */ + CRC_CompRead_t complementRead; /*!< CRC complement read + - CRC_COMPREAD_NO_XOR: No XOR on reading + - CRC_COMPREAD_INVERT_COMP: Invert or complement the read value of the CRC Data register */ + CRC_Mode_t dataMode; /*!< CRC protocol mode + - CRC_MODE_16BIT: 16-bit CRC protocol mode + - CRC_MODE_32BIT: 32-bit CRC protocol mode */ + CRC_TransposeRead_t readType; /*!< CRC read type Of transpose + - CRC_READ_NO: No transposition + - CRC_READ_BIT_Y_BYTE_N: Bits in bytes are transposed; bytes are not transposed + - CRC_READ_BIT_Y_BYTE_Y: Both bits in bytes and bytes are transposed + - CRC_READ_BIT_N_BYTE_Y: Only bytes are transposed; no bits in a byte are transposed */ + CRC_TransposeWrite_t writeType; /*!< CRC write type Of transpose + - CRC_WRITE_NO: No transposition + - CRC_WRITE_BIT_Y_BYTE_N: Bits in bytes are transposed; bytes are not transposed + - CRC_WRITE_BIT_Y_BYTE_Y: Both bits in bytes and bytes are transposed + - CRC_WRITE_BIT_N_BYTE_Y: Only bytes are transposed; no bits in a byte are transposed */ +} CRC_Config_t; + +/** @} end of group CRC_Public_Types */ + + +/** @defgroup CRC_Public_FunctionDeclaration + * @{ + */ + +/** + * @brief Initialization of CRC. + * In this version of the CRC, user configuration write type is CRC_WRITE_NO + * (No Transposition),the actual configuration is: bit no transposed, BYTE + * transposed. + * User configuration write type is CRC_WRITE_BIT_Y_BYTE_N (Bits in bytes are + * transposed; bytes are not transposed),the actual configuration is: both bits + * in bytes and bytes are transposed. + * + * @param[in] crcCfgStruct: Pointer to a CRC configuration structure. + * + * @return none. + * + */ +void CRC_Init(const CRC_Config_t *crcCfgStruct); + +/** + * @brief CRC calculation of 16 bits. + * + * + * @param[in] dataValue: 8 bits of calculated data + * @param[in] length: the length of the array + * @param[in] newSeed: Sets new CRC calculations + * - ENABLE: New seed sets and used for new calculation + * - DISABLE:Seed argument ignored, continues old calculation + * @param[in] seedValue: new seed if newSeed is enabled,else ignored + * + * @return 16-bit calculation results + * + */ +uint16_t CRC_CalcCRC16bit(uint8_t dataValue[], uint32_t length, + ControlState_t newSeed, uint32_t seedValue); + +/** + * @brief CRC calculation of 32 bits + * + * + * @param[in] dataValue: 8 bits of calculated data + * @param[in] length: the length of the array + * @param[in] newSeed: Sets new CRC calculations + * - ENABLE: New seed sets and used for new calculation + * - DISABLE:Seed argument ignored, continues old calculation + * @param[in] seedValue: new seed if newSeed is enabled,else ignored + * + * @return 32-bit calculation results + * + */ +uint32_t CRC_CalcCRC32bit(uint8_t dataValue[], uint32_t length, + ControlState_t newSeed, uint32_t seedValue); + +/** @} end of group CRC_Public_FunctionDeclaration */ + + +/** @} end of group CRC */ + +/** @} end of group Z20K11X_Peripheral_Driver */ + +#endif /* Z20K11X_CRC_H */ diff --git a/StdDriver/Inc/Z20K11xM_dma.h b/StdDriver/Inc/Z20K11xM_dma.h new file mode 100644 index 0000000..3d3a0b5 --- /dev/null +++ b/StdDriver/Inc/Z20K11xM_dma.h @@ -0,0 +1,806 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_dma.h + * @brief : DMA driver module header file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ +#ifndef Z20K11XM_DMA_H +#define Z20K11XM_DMA_H + +#include "Z20K11xM_drv.h" + +/** @addtogroup Z20K11XM_Peripheral_Driver + * @{ + */ + +/** @addtogroup DMA + * @{ + */ + +/** @defgroup DMA_Public_Types + * @{ + */ + +/** + * @brief DMA channel priority type definition + */ +typedef enum +{ + DMA_CHN_PRIORITY0 = 0U, /*!< dma channel priority 0, the lowest */ + DMA_CHN_PRIORITY1, /*!< dma channel priority 1 */ + DMA_CHN_PRIORITY2, /*!< dma channel priority 2 */ + DMA_CHN_PRIORITY3, /*!< dma channel priority 3 */ + DMA_CHN_PRIORITY4, /*!< dma channel priority 4 */ + DMA_CHN_PRIORITY5, /*!< dma channel priority 5 */ + DMA_CHN_PRIORITY6, /*!< dma channel priority 6 */ + DMA_CHN_PRIORITY7, /*!< dma channel priority 7 */ + DMA_CHN_PRIORITY8, /*!< dma channel priority 8 */ + DMA_CHN_PRIORITY9, /*!< dma channel priority 9 */ + DMA_CHN_PRIORITY10, /*!< dma channel priority 10 */ + DMA_CHN_PRIORITY11, /*!< dma channel priority 11 */ + DMA_CHN_PRIORITY12, /*!< dma channel priority 12 */ + DMA_CHN_PRIORITY13, /*!< dma channel priority 13 */ + DMA_CHN_PRIORITY14, /*!< dma channel priority 14 */ + DMA_CHN_PRIORITY15 /*!< dma channel priority 15, the highest*/ +} DMA_ChannelPriority_t; + +/** + * @brief DMA channel id type definition + */ +typedef enum +{ + DMA_CHANNEL0 = 0U, /*!< dma channel 0 */ + DMA_CHANNEL1, /*!< dma channel 1 */ + DMA_CHANNEL2, /*!< dma channel 2 */ + DMA_CHANNEL3, /*!< dma channel 3 */ + DMA_CHANNEL4, /*!< dma channel 4 */ + DMA_CHANNEL5, /*!< dma channel 5 */ + DMA_CHANNEL6, /*!< dma channel 6 */ + DMA_CHANNEL7, /*!< dma channel 7 */ + DMA_CHANNEL8, /*!< dma channel 8 */ + DMA_CHANNEL9, /*!< dma channel 9 */ + DMA_CHANNEL10, /*!< dma channel 10 */ + DMA_CHANNEL11, /*!< dma channel 11 */ + DMA_CHANNEL12, /*!< dma channel 12 */ + DMA_CHANNEL13, /*!< dma channel 13 */ + DMA_CHANNEL14, /*!< dma channel 14 */ + DMA_CHANNEL15 /*!< dma channel 15 */ +} DMA_Channel_t; + +/** + * @brief DMA transfer size type definition + */ +typedef enum +{ + DMA_TRANSFER_SIZE_1B = 0U, /*!< dma once transfer size: 1 byte */ + DMA_TRANSFER_SIZE_2B, /*!< dma once transfer size: 2 bytes */ + DMA_TRANSFER_SIZE_4B /*!< dma once transfer size: 4 bytes */ +} DMA_TransferSize_t; + +/** + * @brief Structure for the DMA hardware request source + */ +typedef enum +{ + DMA_REQ_SOFTWARE = 0U, /*!< TMU/software trigger to DMA channel */ + + DMA_REQ_UART0_TX = 2U, /*!< dma input source: uart0 tx */ + DMA_REQ_UART0_RX = 3U, /*!< dma input source: uart0 rx */ + DMA_REQ_UART1_TX = 4U, /*!< dma input source: uart1 tx */ + DMA_REQ_UART1_RX = 5U, /*!< dma input source: uart1 rx */ + DMA_REQ_UART2_TX = 6U, /*!< dma input source: uart2 tx */ + DMA_REQ_UART2_RX = 7U, /*!< dma input source: uart2 rx */ +#if (4U == UART_INSTANCE_NUM) + DMA_REQ_UART3_TX = 8U, /*!< dma input source: uart3 tx */ + DMA_REQ_UART3_RX = 9U, /*!< dma input source: uart3 rx */ +#endif + DMA_REQ_SPI0_TX = 10U, /*!< dma input source: spi0 tx */ + DMA_REQ_SPI0_RX = 11U, /*!< dma input source: spi0 rx */ + DMA_REQ_SPI1_TX = 12U, /*!< dma input source: spi1 tx */ + DMA_REQ_SPI1_RX = 13U, /*!< dma input source: spi1 rx */ +#if (3U == SPI_INSTANCE_NUM) + DMA_REQ_SPI2_TX = 14U, /*!< dma input source: spi2 tx */ + DMA_REQ_SPI2_RX = 15U, /*!< dma input source: spi2 rx */ +#endif + DMA_REQ_STIM0 = 16U, /*!< dma input source: STIM0 */ + DMA_REQ_STIM1 = 17U, /*!< dma input source: STIM1 */ + DMA_REQ_STIM2 = 18U, /*!< dma input source: STIM2 */ + DMA_REQ_STIM3 = 19U, /*!< dma input source: STIM3 */ + + DMA_REQ_I2C0_TX = 20U, /*!< dma input source: i2c0 tx */ + DMA_REQ_I2C0_RX = 21U, /*!< dma input source: i2c0 rx */ +#if (2U == I2C_INSTANCE_NUM) + DMA_REQ_I2C1_TX = 22U, /*!< dma input source: i2c1 tx */ + DMA_REQ_I2C1_RX = 23U, /*!< dma input source: i2c1 rx */ +#endif + + DMA_REQ_CAN0 = 24U, /*!< dma input source: can0 */ +#if (2U == CAN_INSTANCE_NUM) + DMA_REQ_CAN1 = 25U, /*!< dma input source: can1 */ +#endif + DMA_REQ_ADC0 = 28U, /*!< dma input source: adc0 */ + + DMA_REQ_CMP = 30U, /*!< dma input source: cmp */ + + DMA_REQ_TIM0_CHANNEL0 = 32U, /*!< dma input source: tim0-channel0 */ + DMA_REQ_TIM0_CHANNEL1 = 33U, /*!< dma input source: tim0-channel1 */ + DMA_REQ_TIM0_CHANNEL2 = 34U, /*!< dma input source: tim0-channel2 */ + DMA_REQ_TIM0_CHANNEL3 = 35U, /*!< dma input source: tim0-channel3 */ + DMA_REQ_TIM0_CHANNEL4 = 36U, /*!< dma input source: tim0-channel4 */ + DMA_REQ_TIM0_CHANNEL5 = 37U, /*!< dma input source: tim0-channel5 */ + DMA_REQ_TIM0_CHANNEL6 = 38U, /*!< dma input source: tim0-channel6 */ + DMA_REQ_TIM0_CHANNEL7 = 39U, /*!< dma input source: tim0-channel7 */ + DMA_REQ_TIM1_CHANNEL0 = 40U, /*!< dma input source: tim1-channel0 */ + DMA_REQ_TIM1_CHANNEL1 = 41U, /*!< dma input source: tim1-channel1 */ + DMA_REQ_TIM1_CHANNEL2 = 42U, /*!< dma input source: tim1-channel2 */ + DMA_REQ_TIM1_CHANNEL3 = 43U, /*!< dma input source: tim1-channel3 */ + DMA_REQ_TIM1_CHANNEL4 = 44U, /*!< dma input source: tim1-channel4 */ + DMA_REQ_TIM1_CHANNEL5 = 45U, /*!< dma input source: tim1-channel5 */ + DMA_REQ_TIM1_CHANNEL6 = 46U, /*!< dma input source: tim1-channel6 */ + DMA_REQ_TIM1_CHANNEL7 = 47U, /*!< dma input source: tim1-channel7 */ + DMA_REQ_TIM2_CHANNEL0 = 48U, /*!< dma input source: tim2-channel0 */ + DMA_REQ_TIM2_CHANNEL1 = 49U, /*!< dma input source: tim2-channel1 */ + DMA_REQ_TIM2_CHANNEL2 = 50U, /*!< dma input source: tim2-channel2 */ + DMA_REQ_TIM2_CHANNEL3 = 51U, /*!< dma input source: tim2-channel3 */ + DMA_REQ_TIM2_CHANNEL4 = 52U, /*!< dma input source: tim2-channel4 */ + DMA_REQ_TIM2_CHANNEL5 = 53U, /*!< dma input source: tim2-channel5 */ + DMA_REQ_TIM2_CHANNEL6 = 54U, /*!< dma input source: tim2-channel6 */ + DMA_REQ_TIM2_CHANNEL7 = 55U, /*!< dma input source: tim2-channel7 */ + DMA_REQ_PORTA = 56U, /*!< dma input source: PORTA */ + DMA_REQ_PORTB = 57U, /*!< dma input source: PORTB */ + DMA_REQ_PORTC = 58U, /*!< dma input source: PORTC */ + DMA_REQ_PORTD = 59U, /*!< dma input source: PORTD */ + DMA_REQ_PORTE = 60U, /*!< dma input source: PORTE */ + + DMA_REQ_DMAMUX_ALWAYS_ENABLED0 = 62U, /*!< dma input source: always on channel 0 */ + DMA_REQ_DMAMUX_ALWAYS_ENABLED1 = 63U /*!< dma input source: always on channel 1 */ +} DMA_RequestSource_t; + +/** + * @brief DMA behavior in debug mode type definition + */ +typedef enum +{ + DMA_DEBUG_CONTINUE = 0U, /*!< continue transfer in debug mode */ + DMA_DEBUG_HALT /*!< halt next transfer in debug mode */ +} DMA_DebugBehavior_t; + +/** + * @brief DMA priority arbitration type definition + */ +typedef enum +{ + DMA_FIXED_PRIORITY_ARBITRATION = 0U, /*!< fixed priority */ + DMA_ROUND_ROBIN_ARBITRATION /*!< round-robin priority */ +} DMA_PriorityArbitration_t; + +/** + * @brief DMA channel preempt type definition, Defines the behavior of this channel and other channels in concurrency: + * When channel DMA request is servicing and a higher priority channel's DMA request assert: + * - NO SUSPEND: channel DMA service can not be suspended by other channel + * - SUSPEND: channel DMA service can be suspended by other channel + * When channel DMA request assert but a lower priority channel's DMA is servicing: + * - NO PREEMPT: channel DMA request can not preempt a lower priority channel's service + * - PREEMPT: channel DMA request can preempt a lower priority channel's service + */ +typedef enum +{ + DMA_NOSUSPEND_PREEMPT = 0U, /*!< NO SUSPEND and PREEMPT */ + DMA_NOSUSPEND_NOPREEMPT = 1U, /*!< NO SUSPEND and NO PREEMPT */ + DMA_SUSPEND_PREEMPT = 2U, /*!< SUSPEND and PREEMPT */ + DMA_SUSPEND_NOPREEMPT = 3U /*!< SUSPEND and NO PREEMPT */ +} DMA_ChannelPreempt_t; + +/** + * @brief DMA behavior type definition when error occur + */ +typedef enum +{ + DMA_ERROR_CONTINUE = 0U, /*!< continue transfer when error occur */ + DMA_ERROR_HALT /*!< halt next transfer when error occur */ +} DMA_ErrorBehavior_t; + +/** + * @brief DMA init config type definition + */ +typedef struct +{ + DMA_DebugBehavior_t dmaDebugBehavior; /*!< dma behavior in debiug mode */ + DMA_PriorityArbitration_t dmaPriorityArbitration; /*!< dma priority arbitration */ + DMA_ErrorBehavior_t dmaErrorBehavior; /*!< dma behavior in error mode */ +} DMA_Config_t; + +/** + * @brief DMA interrupt type definition + */ +typedef enum +{ + DMA_INT_ERROR = 0U, /*!< dma error interrupt */ + DMA_INT_DONE, /*!< dma done interrupt */ + DMA_INT_ALL /*!< dma all interrupt */ +} DMA_INT_t; + +/** + * @brief DMA error type definition + */ +typedef enum +{ + DMA_ERROR_PRIORITY = 0U, /*!< dma priority error */ + DMA_ERROR_SRCADDR, /*!< dma src addr unalign error */ + DMA_ERROR_SRCOFFSET, /*!< dma src offset unalign error */ + DMA_ERROR_DESTADDR, /*!< dma dest addr unalign error */ + DMA_ERROR_DESTOFFSET, /*!< dma dest addr unalign error */ + DMA_ERROR_TRANSFERNUM, /*!< dma transfer size unalign error */ + DMA_ERROR_SRCBUS, /*!< dma src bus error */ + DMA_ERROR_DESTBUS, /*!< dma dest bus error */ + DMA_ERROR_ALL /*!< dma all error type */ +} DMA_ERROR_t; + +/** + * @brief DMA transfer configuration. + * + * This structure configures the basic source/destination transfer attribute. + * Implements : DMA_TransferConfig_t_Class + */ +typedef struct +{ + DMA_Channel_t channel; /*!< specifies the channel used for dma transfer */ + DMA_ChannelPriority_t channelPriority; /*!< dma channel priority - only used Fixed priority mode */ + DMA_ChannelPreempt_t channelPreempt; /*!< the behavior of this channel and other channels in concurrency */ + DMA_RequestSource_t source; /*!< selects the source of the DMA request for this channel */ + IntMask_t doneIntMask; /*!< done interrupt mask + - UNMASK: enable done interrupt + - MASK: disable done interrupt */ + IntMask_t errorIntMask; /*!< error interrupt mask + - UNMASK: enable error interrupt + - MASK: disable error interrupt */ + uint16_t minorLoopNum; /*!< number of minor loop in a major loop */ + uint32_t srcAddr; /*!< address pointing to the source data */ + uint32_t destAddr; /*!< address pointing to the destination data */ + int16_t minorLoopSrcOffset; /*!< source address offset in minor loop */ + int16_t minorLoopDestOffset; /*!< destination address offset in minor loop */ + int16_t majorLoopSrcOffset; /*!< source address offset after a major loop done */ + int16_t majorLoopDestOffset; /*!< destination address offset after a major loop done */ + uint32_t transferByteNum; /*!< transfer bytes number in a minor loop */ + DMA_TransferSize_t srcTransferSize; /*!< source data transfer size */ + DMA_TransferSize_t destTransferSize; /*!< destination data transfer size */ + ControlState_t disableRequestAfterDoneCmd; /*!< disable request after done control + - ENABLE: disable channel request after done + - DISABLE: enable channel request after done */ +} DMA_TransferConfig_t; + +/** @} end of group DMA_Public_Types */ + +/** @defgroup DMA_Public_Constants + * @{ + */ + +/** @} end of group DMA_Public_Constants */ + +/** @defgroup DMA_Public_Macro + * @{ + */ + +/** @} end of group DMA_Public_Macro */ + + +/** @defgroup DMA_Public_FunctionDeclaration + * @brief DMA functions declaration + * @{ + */ + +/** + * @brief Select dmamux input source Function + * + * @param[in] outChannel: output channel id. + * @param[in] questSource: inpout source. + * + * @return none + * + */ +void DMAMUX_SelChannelSource(DMA_Channel_t outChannel, + DMA_RequestSource_t questSource); + +/** + * @brief Enable dmamux output channel Function + * + * @param[in] outChannel: output channel id. + * + * @return none + * + */ +void DMAMUX_OutputChannelEnable(DMA_Channel_t outChannel); + +/** + * @brief Disable dmamux output channel Function + * + * @param[in] outChannel: output channel id. + * + * @return none + * + */ +void DMAMUX_OutputChannelDisable(DMA_Channel_t outChannel); + +/** + * @brief Dma Initializes Function + * + * @param[in] ptDMAInitConfig: Pointer to a DMA configuration structure. + * + * @return none + * + */ +void DMA_Init(const DMA_Config_t * ptDMAInitConfig); + +/** + * @brief Get dma busy status Function + * + * @param[in] none + * + * @return busy status. + * + */ +FlagStatus_t DMA_GetDmaBusyStatus(void); + +/** + * @brief Halt dma Function + * + * @param[in] cmd: halt control + * - ENABLE: stall the dma start a new channels for transfer + * - DISABLE: dma is not stall + * + * @return none. + * + */ +void DMA_HaltControl(ControlState_t cmd); + +/** + * @brief Get dma halt status Function + * + * @param[in] none + * + * @return whether dma halt is asserted or not. + * + */ +FlagStatus_t DMA_GetHaltStatus(void); + +/** + * @brief Set dma priority arbitration mode Function + * + * @param[in] channelArbitration: arbitration mode + * + * @return none. + * + */ +void DMA_SetPriorityArbitrationMode(DMA_PriorityArbitration_t arbitration); + +/** + * @brief Get dma current priority arbitration mode Function + * + * @param[in] none + * + * @return current priority arbitration mode. + * + */ +DMA_PriorityArbitration_t DMA_GetPriorityArbitrationMode(void); + +/** + * @brief Enable dma channel request Function + * + * @param[in] channel: dma channel id + * + * @return none. + * + */ +void DMA_ChannelRequestEnable(DMA_Channel_t channel); + +/** + * @brief Disable dma channel request Function + * + * @param[in] channel: dma channel id + * + * @return none. + * + */ +void DMA_ChannelRequestDisable(DMA_Channel_t channel); + +/** + * @brief Get dma channel request status Function + * + * @param[in] channel: dma channel id + * + * @return whether dma channel request enable bit is asserted or not. + * + */ +FlagStatus_t DMA_GetChannelRequestStatus(DMA_Channel_t channel); + +/** + * @brief Set dma channel priority Function + * + * @param[in] channel: dma channel id + * @param[in] priority: channel priority + * + * @return none. + * + */ +void DMA_SetChannelPriority(DMA_Channel_t channel, + DMA_ChannelPriority_t priority); + +/** + * @brief Get dma channel priority Function + * + * @param[in] channel: dma channel id + * + * @return channel priority. + * + */ +DMA_ChannelPriority_t DMA_GetChannelPriority(DMA_Channel_t channel); + +/** + * @brief Set dma channel preempt type Function + * + * @param[in] channel: dma channel id + * @param[in] preempt: channel preempt type + * + * @return none. + * + */ +void DMA_SetChannelPreempt(DMA_Channel_t channel, + DMA_ChannelPreempt_t preempt); + +/** + * @brief Get dma channel preempt type Function + * + * @param[in] channel: dma channel id + * + * @return channel preempt type. + * + */ +DMA_ChannelPreempt_t DMA_GetChannelPreempt(DMA_Channel_t channel); + +/** + * @brief Set dma source address Function + * + * @param[in] channel: dma channel id + * @param[in] address: dma transfer source address + * + * @return none. + * + */ +void DMA_SetSrcAddr(DMA_Channel_t channel, uint32_t address); + +/** + * @brief Get dma source address Function + * + * @param[in] channel: dma channel id + * + * @return dma source address. + * + */ +uint32_t DMA_GetSrcAddr(DMA_Channel_t channel); + +/** + * @brief Set dma destination address Function + * + * @param[in] channel: dma channel id + * @param[in] address: dma transfer destination address + * + * @return none. + * + */ +void DMA_SetDestAddr(DMA_Channel_t channel, uint32_t address); + +/** + * @brief Get dma destination address Function + * + * @param[in] channel: dma channel id + * + * @return dma destination address. + * + */ +uint32_t DMA_GetDestAddr(DMA_Channel_t channel); + +/** + * @brief Set dma source address offset in minor loop Function + * + * @param[in] channel: dma channel id + * @param[in] offest: dma source address offset in minor loop + * + * @return none. + * + */ +void DMA_SetMinorLoopSrcOffest(DMA_Channel_t channel, int16_t offest); + +/** + * @brief Set dma destination address offset in minor loop Function + * + * @param[in] channel: dma channel id + * @param[in] offest: dma destination address offset in minor loop + * + * @return none. + * + */ +void DMA_SetMinorLoopDestOffest(DMA_Channel_t channel, int16_t offest); + +/** + * @brief Set dma source address offset after a major loop done Function + * + * @param[in] channel: dma channel id + * @param[in] offest: dma source address offset after a major loop done + * + * @return none. + * + */ +void DMA_SetMajorLoopSrcOffest(DMA_Channel_t channel, int16_t offest); + +/** + * @brief Set dma destination address offset after a major loop done Function + * + * @param[in] channel: dma channel id + * @param[in] offest: dma destination address offset after a major loop done + * + * @return none. + * + */ +void DMA_SetMajorLoopDestOffest(DMA_Channel_t channel, int16_t offest); + +/** + * @brief Set total number of minor loop in a major loop Function + * + * @param[in] channel: dma channel id + * @param[in] num: number of minor loop in a major loop + * + * @return none. + * + */ +void DMA_SetMinorLoopNum(DMA_Channel_t channel, uint16_t num); + +/** + * @brief Get total number of minor loop in one major loop Function + * + * @param[in] channel: dma channel id + * + * @return number of minor loop in a major loop. + * + */ +uint16_t DMA_GetMinorLoopNum(DMA_Channel_t channel); + +/** + * @brief Get number of minor loop that not finished in one major loop Function + * + * @param[in] channel: dma channel id + * + * @return number of rest minor loop in a major loop. + * + */ +uint16_t DMA_GetRestMinorLoopNum(DMA_Channel_t channel); + +/** + * @brief Set dma source transfer size Function + * + * @param[in] channel: dma channel id + * @param[in] size: dma source transfer size + * + * @return none. + * + */ +void DMA_SetSrcTransferSize(DMA_Channel_t channel, DMA_TransferSize_t size); + +/** + * @brief Set dma destination transfer size Function + * + * @param[in] channel: dma channel id + * @param[in] size: dma destination transfer size + * + * @return none. + * + */ +void DMA_SetDestTransferSize(DMA_Channel_t channel, DMA_TransferSize_t size); + +/** + * @brief Set dma transfer num of bytes in a minor loop Function + * + * @param[in] channel: dma channel id + * @param[in] num: dma transfer num of bytes in a minor loop + * + * @return none. + * + */ +void DMA_SetTransferByteNum(DMA_Channel_t channel, uint32_t num); + +/** + * @brief Disables/enables the DMA request after the transfer complete Function + * + * @param[in] channel: dma channel id + * @param[in] cmd: disable request after done + * - ENABLE: disables the DMA request after the transfer complete + * - DISABLE: enables the DMA request after the transfer complete + * + * @return none. + * + */ +void DMA_SetDisableRequestAfterDone(DMA_Channel_t channel, ControlState_t cmd); + +/** + * @brief Software trigger one channel dma transfer Function + * + * @param[in] channel: dma channel id + * + * @return none. + * + */ +void DMA_TriggerChannelStart(DMA_Channel_t channel); + +/** + * @brief Software trigger all channel dma transfer Function + * + * @param[in] none + * + * @return none. + * + */ +void DMA_TriggerAllChannelStart(void); + +/** + * @brief Get one channel hardware DMA request status Function + * + * @param[in] channel: dma channel id + * + * @return whether a channel hardware DMA request is asserted or not. + * + */ +FlagStatus_t DMA_GetHwRequestStatus(DMA_Channel_t channel); + +/** + * @brief Get dma last error status Function + * + * @param[in] error: error type + * + * @return whether a dma error is asserted or not. + * + */ +FlagStatus_t DMA_GetLastErrorStatus(DMA_ERROR_t error); + +/** + * @brief Get last error channel id Function + * + * @param[in] none + * + * @return channel which occur the last error + * + */ +DMA_Channel_t DMA_GetLastErrorChannel(void); + +/** + * @brief Get channel int flag Function + * + * @param[in] channel: dma channel id + * @param[in] intType: int type + * - DMA_INT_ERROR: error interrupt + * - DMA_INT_DONE: done interrupt + * - DMA_INT_ALL: all interrupt + * + * @return whether a channel int is asserted or not. + * + */ +IntStatus_t DMA_GetIntStatus(DMA_Channel_t channel, DMA_INT_t intType); + +/** + * @brief Clear channel int flag Function + * + * @param[in] channel: dma channel id + * @param[in] intType: int type + * - DMA_INT_ERROR: error interrupt + * - DMA_INT_DONE: done interrupt + * - DMA_INT_ALL: all interrupt + * + * @return none. + * + */ +void DMA_ClearIntStatus(DMA_Channel_t channel, DMA_INT_t intType); + +/** + * @brief Clear all channels int flag Function + * + * @param[in] intType: int type + * - DMA_INT_ERROR: error interrupt + * - DMA_INT_DONE: done interrupt + * - DMA_INT_ALL: all interrupt + * + * @return none. + * + */ +void DMA_ClearAllChannelsIntStatus(DMA_INT_t intType); + +/** + * @brief Get channel done flag Function + * + * @param[in] channel: dma channel id + * + * @return whether a channel done flag is asserted or not. + * + */ +FlagStatus_t DMA_GetDoneStatus(DMA_Channel_t channel); + +/** + * @brief Clear channel done flag Function + * + * @param[in] channel: dma channel id + * + * @return none. + * + */ +void DMA_ClearDoneStatus(DMA_Channel_t channel); + +/** + * @brief Clear all channels done flag Function + * + * @param[in] none + * + * @return none. + * + */ +void DMA_ClearAllChannelsDoneStatus(void); + +/** + * @brief Get channel busy status Function + * + * @param[in] channel: dma channel id + * + * @return whether a channel is busy or not. + * + */ +FlagStatus_t DMA_GetChannelBusyStatus(DMA_Channel_t channel); + +/** + * @brief Set channel int mask Function + * + * @param[in] channel: dma channel id + * @param[in] intType: int type + * - DMA_INT_ERROR: error interrupt + * - DMA_INT_DONE: done interrupt + * - DMA_INT_ALL: all interrupt + * @param[in] intMask: int mask + * + * @return none. + * + */ +void DMA_IntMask(DMA_Channel_t channel, DMA_INT_t intType, IntMask_t intMask); + +/** + * @brief Install callback function + * + * @param[in] channel: dma channel id + * @param[in] intType: select interrrupt type + * - DMA_INT_ERROR: error interrupt + * - DMA_INT_DONE: done interrupt + * @param[in] cbFun: indicate callback function + * + * @return none + * + */ +void DMA_InstallCallBackFunc(DMA_Channel_t channel, DMA_INT_t intType, + isr_cb_t * cbFun); + +/** + * @brief Dma transfer config Function + * + * @param[in] config: Pointer to dma transfer configuration structure. + * + * @return function execution result + * + */ +ResultStatus_t DMA_ConfigTransfer(const DMA_TransferConfig_t * config); + +/** @} end of group DMA_Public_FunctionDeclaration */ + +/** @} end of group DMA */ + +/** @} end of group Z20K11XM_Peripheral_Driver */ + +#endif /* Z20K11XM_DMA_H */ + diff --git a/StdDriver/Inc/Z20K11xM_drv.h b/StdDriver/Inc/Z20K11xM_drv.h new file mode 100644 index 0000000..205b59d --- /dev/null +++ b/StdDriver/Inc/Z20K11xM_drv.h @@ -0,0 +1,169 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_drv.h + * @brief : Drv common module header file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ +#ifndef Z20K11XM_DRV_H +#define Z20K11XM_DRV_H + +#include "device_regs.h" +#include "Z20K11xM_cfg.h" + +/** @addtogroup Z20K11X_Periph_Drv + * @{ + */ + +/** @addtogroup DRV_COMMON + * @{ + */ + +/** @defgroup DRV_Public_Types + * @brief DRV type definition + * @{ + */ + +/* Core_definition Processor and Core Peripheral definition */ +#include "core_cm0plus.h" /*!< Cortex-M0+ processor and core peripherals */ + +#if defined ( __ICCARM__ ) + #define START_FUNCTION_DECLARATION_RAMSECTION __ramfunc + #define END_FUNCTION_DECLARATION_RAMSECTION ; +#elif defined (__ARMCC_VERSION) + #define START_FUNCTION_DECLARATION_RAMSECTION + #define END_FUNCTION_DECLARATION_RAMSECTION __attribute__((section (".code_ram"))); +#elif defined (__GNUC__) + #define START_FUNCTION_DECLARATION_RAMSECTION + #define END_FUNCTION_DECLARATION_RAMSECTION __attribute__((section (".code_ram"))); +#else + #define START_FUNCTION_DECLARATION_RAMSECTION + #define END_FUNCTION_DECLARATION_RAMSECTION ; +#endif + +#if defined (__ICCARM__) + #define DISABLE_CHECK_RAMSECTION_FUNCTION_CALL _Pragma("diag_suppress=Ta022") + #define ENABLE_CHECK_RAMSECTION_FUNCTION_CALL _Pragma("diag_default=Ta022") +#else + #define DISABLE_CHECK_RAMSECTION_FUNCTION_CALL + #define ENABLE_CHECK_RAMSECTION_FUNCTION_CALL +#endif + +/** + * @brief Control State Type Definition + */ +typedef enum +{ + DISABLE = 0U, + ENABLE = 1U +}ControlState_t; + +/** + * @brief Result status Type definition + */ +typedef enum +{ + SUCC = 0U, + ERR = 1U, + BUSY = 2U +}ResultStatus_t; + +/** + * @brief Flag/Int status Type definition + */ +typedef enum +{ + RESET = 0, + SET = 1 +}FlagStatus_t, IntStatus_t; + +/** + * @brief interrupt mask Type definition + */ +typedef enum +{ + UNMASK = 0, + MASK = 1 +}IntMask_t; + + + +/** + * @brief ISR callback function type + */ +typedef void (isr_cb_t)(void); + + +/** @} end of group DRV_Public_Types */ + + +/** @defgroup DRV_Public_Constants + * @{ + */ + +/** @} end of group DRV_Public_Constants */ + +/** @defgroup DRV_Public_Macro + * @{ + */ + +#ifdef DEBUG +/** + * @brief The CHECK_PARAM macro is used for function's parameters check. + * It is used only if the library is compiled in DEBUG mode. + * @param[in] expr: - If expr is false, it calls check_failed() function + * which reports the name of the source file and the source + * line number of the call that failed. + * - If expr is true, it returns no value. + * @return none + */ +void check_failed(uint8_t *file, uint32_t line); +#define CHECK_PARAM(expr) ((expr) ? (void)0 : check_failed((uint8_t *)__FILE__, __LINE__)) +#else +#define CHECK_PARAM(expr) ((void)0) +#endif /* DEBUG */ + +/** + * @brief Reverse byte order in a word + */ +#if defined (__ICCARM__) +#define REV_BYTES_32(a, b) __asm volatile ("rev %0, %1" : "=r" (b) : "r" (a)) +#else +#define REV_BYTES_32(a, b) (b = ((a & 0xFF000000U) >> 24U) | ((a & 0xFF0000U) >> 8U) \ + | ((a & 0xFF00U) << 8U) | ((a & 0xFFU) << 24U)) +#endif + +/** @} end of group DRV_Public_Macro */ + +/** @defgroup DRV_Public_FunctionDeclaration + * @brief DRV functions declaration + * @{ + */ + +/** + * @brief Delay for some cycles + * + * @param[in] delayCount: the cycles to delay + * + * @return None + * + */ +#if( DRV_DELAY_FUNC_IN_RAM == 1) +START_FUNCTION_DECLARATION_RAMSECTION +void Drv_Delay(uint32_t delayCount) +END_FUNCTION_DECLARATION_RAMSECTION /*PRQA S 0605*/ +#else +void Drv_Delay(uint32_t delayCount); +#endif + +/** @} end of group DRV_Public_FunctionDeclaration */ + +/** @} end of group DRV_COMMON */ + +/** @} end of group Z20K11X_Periph_Drv */ + +#endif /* Z20K11XM_DRV_H */ diff --git a/StdDriver/Inc/Z20K11xM_ewdt.h b/StdDriver/Inc/Z20K11xM_ewdt.h new file mode 100644 index 0000000..a1b6d77 --- /dev/null +++ b/StdDriver/Inc/Z20K11xM_ewdt.h @@ -0,0 +1,235 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_ewdt.h + * @brief : EWDT driver module header file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ +#ifndef Z20K11XM_EWDT_H +#define Z20K11XM_EWDT_H + +#include "Z20K11xM_drv.h" + +/** @addtogroup Z20K11X_Peripheral_Driver + * @{ + */ + +/** @addtogroup EWDT + * @{ + */ + +/** @defgroup EWDT_Public_Types + * @{ + */ + +/*! + * @brief EWDT input pin configuration definition. + * Implements : EWDT_Input_Status_t_Class + */ +typedef enum +{ + EWM_INPUT_DISABLED = 0U, /*!< Input pin disabled */ + EWM_INPUT_ASSERT_LOW = 1U, /*!< Input pin asserts when on low level */ + EWM_INPUT_ASSERT_HIGH = 3U /*!< Input pin asserts when on high level */ +} EWDT_InputStatus_t; + +/*! + * @brief EWDT operate mode configuration structure. + * + * This structure configures the wdog operation mode. + * Implements : EWDT_OperationMode_t_Class + */ +typedef struct +{ + ControlState_t wait; /*!< Wait mode control + - ENABLE: counter countinue + - DISABLE: counter halt */ + ControlState_t debug; /*!< debug mode control + - ENABLE: counter countinue + - DISABLE: counter halt */ +} EWDT_OperationMode_t; + +/*! + * @brief EWDT configuration structure. + * + * This structure configures the basic attribute. + * Implements : EWDT_Config_t_Class + */ +typedef struct +{ + EWDT_InputStatus_t input; /*!< input config */ + ControlState_t wait; /*!< Wait mode control + - ENABLE: counter countinue + - DISABLE: counter halt */ + ControlState_t debug; /*!< debug mode control + - ENABLE: counter countinue + - DISABLE: counter halt */ + IntMask_t intMask; /*!< int mask */ + uint32_t cmpLowValue; /*!< The window value: 32 bits */ + uint32_t cmpHighValue; /*!< The timeout value: 32 bits */ + ControlState_t enable; /*!< ewdt control + - ENABLE: enable ewdt + - DISABLE: disable ewdt */ +} EWDT_Config_t; + +/** + * @brief EWDT interrupt type definition + */ +typedef enum +{ + EWDT_INT_OUTPUTASSERT = 0U, /*!< ewdt output assert interrupt */ + EWDT_INT_ALL /*!< all interrupt */ +} EWDT_INT_t; + +/** @} end of group EWDT_Public_Types */ + +/** @defgroup EWDT_Public_Constants + * @{ + */ + +/** @} end of group EWDT_Public_Constants */ + +/** @defgroup EWDT_Public_Macro + * @{ + */ + +/** @} end of group EWDT_Public_Macro */ + +/** @defgroup EWDT_Public_FunctionDeclaration + * @brief EWDT functions declaration + * @{ + */ + +/** + * @brief ewdt Initializes Function + * + * @param[in] ptEWDTInitConfig: Pointer to a EWDT configuration structure. + * + * @return Initializes operate flag + * + */ +ResultStatus_t EWDT_Init(const EWDT_Config_t *ptEWDTInitConfig); + +/** + * @brief refresh ewdt count Function + * + * @param[in] none + * + * @note If user has no need to enable irq, in next step user should + * disable_irq after calling this function. + * + * @return none. + * + */ +void EWDT_Refresh(void); + +/** + * @brief get ewdt input pin assertion config Function + * + * @param[in] none + * + * @return input pin assertion config status. + * + */ +EWDT_InputStatus_t EWDT_GetInputAssertConfig(void); + +/** + * @brief get ewdt compare low reg value Function + * + * @param[in] none + * + * @return compare low reg value. + * + */ +uint32_t EWDT_GetCompareLowValue(void); + +/** + * @brief get ewdt compare high reg value Function + * + * @param[in] none + * + * @return compare high reg value. + * + */ +uint32_t EWDT_GetCompareHighValue(void); + +/** + * @brief get ewdt counter current value Function + * + * @param[in] none + * + * @return current counter count value. + * + */ +uint32_t EWDT_GetCounter(void); + +/** + * @brief get flag indcates ewdt is enable/disable Function + * + * @param[in] none + * + * @return ewdt enable status. + * + */ +FlagStatus_t EWDT_GetEnableStatus(void); + +/** + * @brief get interrupt mask Function + * + * @param[in] intType: int type + * - EWDT_INT_OUTPUTASSERT: ewdt out assert int + * - EWDT_INT_ALL: all int type + * + * @return interrupt mask. + * + */ +IntMask_t EWDT_GetIntMaskStatus(EWDT_INT_t intType); + +/** + * @brief clear ewdt interrupt flag Function + * + * @param[in] intType: int type + * - EWDT_INT_OUTPUTASSERT: ewdt out assert int + * - EWDT_INT_ALL: all int type + * + * @return none. + * + */ +void EWDT_ClearIntStatus(EWDT_INT_t intType); + +/** + * @brief get ewdt int flag Function + * + * @param[in] intType: int type + * - EWDT_INT_OUTPUTASSERT: ewdt out assert int + * - EWDT_INT_ALL: all int type + * + * @return whether a int is asserted or not. + * + */ +IntStatus_t EWDT_GetIntStatus(EWDT_INT_t intType); + +/** + * @brief Install callback function + * + * @param[in] intType: select interrrupt type + * - EWDT_INT_OUTPUTASSERT: ewdt out assert int + * - EWDT_INT_ALL: all int type + * @param[in] cbFun: indicate callback function + * + * @return none + * + */ +void EWDT_InstallCallBackFunc(EWDT_INT_t intType, isr_cb_t *cbFun); + +/** @} end of group EWDT_Public_FunctionDeclaration */ + +/** @} end of group EWDT */ + +/** @} end of group Z20K11X_Peripheral_Driver */ + +#endif /* Z20K11XM_EWDT_H */ diff --git a/StdDriver/Inc/Z20K11xM_flash.h b/StdDriver/Inc/Z20K11xM_flash.h new file mode 100644 index 0000000..2b90d9a --- /dev/null +++ b/StdDriver/Inc/Z20K11xM_flash.h @@ -0,0 +1,533 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_flash.h + * @brief : FLASH module driver header file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ + +#ifndef Z20K11XM_FLASH_H__ +#define Z20K11XM_FLASH_H__ + +#include "Z20K11xM_drv.h" + +/** @addtogroup Z20K11X_Peripheral_Driver + * @{ + */ + +/** @addtogroup FLASH + * @{ + */ + +/** @defgroup FLASH_Public_Types + * @{ + */ + +/** + * @brief FLASH status mask definition + */ + +#define FLASH_STATUS_FAIL_MASK 0x00000001U /*!< command fail */ +#define FLASH_STATUS_CMDABT_MASK 0x00000004U /*!< Command Abort */ +#define FLASH_STATUS_ACCERR_MASK 0x00000020U /*!< Access Error */ +#define FLASH_STATUS_PREABT_MASK 0x00000040U /*!< Write Sequence Abort */ +#define FLASH_STATUS_CCIF_MASK 0x00000080U /*!< Command Complete */ +#define FLASH_STATUS_CMDWRF_MASK 0x00000800U /*!< Flash command registers written */ +#define FLASH_STATUS_DFDIF_MASK 0x00010000U /*!< Multi-bit ECC fault */ +#define FLASH_STATUS_SFDIF_MASK 0x00020000U /*!< Single-bit ECC fault */ +#define FLASH_STATUS_DBG_ERSALL_DIS_MASK 0x40000000U /*!< debug erase all request disable */ +#define FLASH_STATUS_FSEC_MASK 0x80000000U /*!< Flash secure state */ + +/** + * @brief FLASH interrupt type definition + */ +typedef enum +{ + FLASH_INT_CCIF = 0U, /*!< command complete */ + FLASH_INT_DFDIF, /*!< Double bit fault */ + FLASH_INT_ALL /*!< all interrupt */ +}FLASH_Int_t; + +/** + * @brief FLASH user actions when execute a command type definition + */ +typedef enum +{ + FLASH_CMD_ACT_WAIT = 0U, /*!< wait until a command is completed */ + FLASH_CMD_ACT_INT /*!< enable interrupt and use interrupt to infom + when the command is completed */ +}FLASH_CmdAct_t; + + +/** + * @brief FLASH abort command result type definition + */ +typedef enum +{ + FLASH_ABORT_OK = 0U, /*!< abort flash command succeeded */ + FLASH_ABORT_FINISHED, /*!< abort failed, but flash command has been finished */ + FLASH_ABORT_TIMEOUT, /*!< abort flash command timeout */ +}FLASH_AbortResult_t; + +/** + * @brief Call back function pointer data type + * If using callback in the application, any code reachable from this function + * must not be placed in a Flash block targeted for a program/erase operation. + * Functions can be placed in RAM section. + */ +typedef void (* flash_cb_t)(void); + +/** + * @brief Flash command Configuration Structure + */ +typedef struct +{ + FLASH_CmdAct_t act; /*!< define the actions when the command is executing + - FLASH_CMD_ACT_WAIT: wait until a command is completed + - FLASH_CMD_ACT_INT: enable interrupt and use interrupt to infom + when the command is completed */ + flash_cb_t callBack; /*!< Call back function to service the time critical + events. Any code reachable from this function + must not be placed in a Flash block targeted for + a program/erase operation. if "act" paramenter is + set to FLASH_CMD_ACT_WAIT, this callBack is called + when waiting for the completion of command. If + FLASH_CMD_ACT_INT is selected, this paramter can + be ignored a interrupt call back function can be + installed through FLASH_InstallCallBackFunc() */ +} FLASH_CmdConfig_t; + +/** @} end of group FLASH_Public_Types */ + +/** @defgroup FLASH_Public_Constants + * @{ + */ + +/** @} end of group FLASH_Public_Constants */ + +/** @defgroup FLASH_Public_Macro + * @{ + */ + +/** @} end of group FLASH_Public_Macro */ + +/** @defgroup FLASH_Public_FunctionDeclaration + * @brief FLASH functions declaration + * @{ + */ + + +/** + * @brief Verify all flash and IFR space are in the erased state + * + * @param[in] config: config the action when the command is executing + * + * @note if config->callBack is not NULL, it has to point to a funtion + * that is not in flash memory + * + * @return + * - SUCC -- successful + * - ERR -- some error + * - BUSY -- flash is executing last command. It can not execute this + * new command now. + * + */ +ResultStatus_t FLASH_VerifyAll(const FLASH_CmdConfig_t *config); + + +/** + * @brief Verify that a flash block is erased + * + * @param[in] addr: block start address + * @param[in] config: config the action when the command is executing + * + * @note if config->callBack is not NULL, it has to point to a funtion + * that is not in the flash memory that flash commands is executing + * in. + * + * @return - SUCC -- successful + * - ERR -- some error + * - BUSY -- flash is executing last command. It can not execute this + * new command now. + * + */ +ResultStatus_t FLASH_VerifyBlock(uint32_t addr, + const FLASH_CmdConfig_t *config); + +/** + * @brief Verify that a flash sector is erased + * + * @param[in] addr: sector start address + * @param[in] config: config the action when the command is executing + * + * @note if config->callBack is not NULL, it has to point to a funtion + * that is not in the flash memory that flash commands is executing + * in. + * + * @return - SUCC -- successful + * - ERR -- some error + * - BUSY -- flash is executing last command. It can not execute this + * new command now. + * + */ +ResultStatus_t FLASH_VerifySector(uint32_t addr, + const FLASH_CmdConfig_t *config); + +/** + * @brief Verify that a flash page is erased + * + * @param[in] addr: page start address + * @param[in] config: config the action when the command is executing + * + * @note if config->callBack is not NULL, it has to point to a funtion + * that is not in the flash memory that flash commands is executing + * in. + * + * @return - SUCC -- successful + * - ERR -- some error + * - BUSY -- flash is executing last command. It can not execute this + * new command now. + * + */ +ResultStatus_t FLASH_VerifyPage(uint32_t addr, + const FLASH_CmdConfig_t *config); + +/** + * @brief Verify that a flash phrase is erased + * + * @param[in] addr: phrase start address + * @param[in] config: config the action when the command is executing + * + * @note if config->callBack is not NULL, it has to point to a funtion + * that is not in the flash memory that flash commands is executing + * in. + * + * @return - SUCC -- successful + * - ERR -- some error + * - BUSY -- flash is executing last command. It can not execute this + * new command now. + * + */ +ResultStatus_t FLASH_VerifyPhrase(uint32_t addr, + const FLASH_CmdConfig_t *config); + +/** + * @brief Generate MISR signature for flash pages + * + * @param[in] startAddr: page start address + * @param[in] endAddr: Ending phrase address. It must be the last phrase in a page. + * @param[in] seed: the pointer that points to the 4-word seed + * @param[in] signature: the pointer that points the memory that the 128-bit + * singnature result that will be stored through this function. + * it is only valid when config->act == FLASH_CMD_ACT_WAIT. + * If config->act == FLASH_CMD_ACT_WAIT, the result is not stored + * @param[in] config: config the action when the command is executing. If + * FLASH_CMD_ACT_WAIT is selected, the result is stored in + * signature[4]. If FLASH_CMD_ACT_INT is selected, the result + * is not selected. user can get the result in the interrupt + * call back function + * + * @note if config->callBack is not NULL, it has to point to a funtion + * that is not in the flash memory that flash commands is executing + * in. + * + * @return - SUCC -- successful + * - ERR -- some error + * - BUSY -- flash is executing last command. It can not execute this + * new command now. + * + */ +ResultStatus_t FLASH_PagesMircSignature(uint32_t startAddr, uint32_t endAddr, + uint32_t seed[4], uint32_t signature[4], + const FLASH_CmdConfig_t *config); + +/** + * @brief Verify that a flash IFR sector is erased + * + * @param[in] addr: sector start address. + * @param[in] config: config the action when the command is executing + * + * @note if config->callBack is not NULL, it has to point to a funtion + * that is not in the flash memory that flash commands is executing + * in. + * + * @return - SUCC -- successful + * - ERR -- some error + * - BUSY -- flash is executing last command. It can not execute this + * new command now. + * + */ +ResultStatus_t FLASH_VerifyIfrSector(uint32_t addr, + const FLASH_CmdConfig_t *config); + +/** + * @brief Verify that a flash IFR page is erased + * + * @param[in] addr: IFR page start address + * @param[in] config: config the action when the command is executing + * + * @note if config->callBack is not NULL, it has to point to a funtion + * that is not in the flash memory that flash commands is executing + * in. + * + * @return - SUCC -- successful + * - ERR -- some error + * - BUSY -- flash is executing last command. It can not execute this + * new command now. + * + */ +ResultStatus_t FLASH_VerifyIfrPage(uint32_t addr, + const FLASH_CmdConfig_t *config); + +/** + * @brief Verify that a flash IFR phrase is erased + * + * @param[in] addr: IFR phrase start address + * @param[in] config: config the action when the command is executing + * + * @note if config->callBack is not NULL, it has to point to a funtion + * that is not in the flash memory that flash commands is executing + * in. + * + * @return - SUCC -- successful + * - ERR -- some error + * - BUSY -- flash is executing last command. It can not execute this + * new command now. + * + */ +ResultStatus_t FLASH_VerifyIfrPhrase(uint32_t addr, + const FLASH_CmdConfig_t *config); + +/** + * @brief Generate MISR signature for flash IFR pages + * + * @param[in] startAddr: page start address + * @param[in] endAddr: Ending phrase address. It must be the last phrase in a page. + * @param[in] seed: the pointer that points to the 4-word seed + * @param[in] signature: the pointer that points the memory that the 128-bit + * singnature result that will be stored through this function. + * it is only valid when config->act == FLASH_CMD_ACT_WAIT. + * If config->act == FLASH_CMD_ACT_WAIT, the result is not stored + * @param[in] config: config the action when the command is executing. If + * FLASH_CMD_ACT_WAIT is selected, the result is stored in + * signature[4]. If FLASH_CMD_ACT_INT is selected, the result + * is not selected. user can get the result in the interrupt + * call back function + * + * @note if config->callBack is not NULL, it has to point to a funtion + * that is not in the flash memory that flash commands is executing + * in. + * + * @return - SUCC -- successful + * - ERR -- some error + * - BUSY -- flash is executing last command. It can not execute this + * new command now. + * + */ +ResultStatus_t FLASH_IfrPagesMircSignature(uint32_t startAddr, uint32_t endAddr, + uint32_t seed[4], uint32_t signature[4], + const FLASH_CmdConfig_t *config); + +/** + * @brief program a flash phrase + * + * @param[in] flashAddr: phrase start address to be programmed + * @param[in] dataP: points to data to be programmed into flash + * @param[in] config: config the action when the command is executing + * + * @note if config->callBack is not NULL, it has to point to a funtion + * that is not in the flash memory that flash commands is executing + * in. + * + * @return - SUCC -- successful + * - ERR -- some error + * - BUSY -- flash is executing last command. It can not execute this + * new command now. + * + */ +ResultStatus_t FLASH_ProgramPhrase(uint32_t flashAddr, const uint8_t *dataP, + const FLASH_CmdConfig_t *config); + +/** + * @brief program flash memory + * + * @param[in] flashAddr: start address of flash memory. It is the start address of + * a phrase. This address should be aligned to 4 words(16 bytes) + * @param[in] len: length in byte to be programmed. + * This length should be aligned to 4 words(16 bytes). + * @param[in] dataP: points to the source buffer from which data is taken + * for program operation. + * @param[in] callBack: the callBack function when waiting for command executing + * + * @note if callBack is not NULL, it has to point to a funtion + * that is not in the flash memory that flash commands is executing + * in. + * + * @return - SUCC -- successful + * - ERR -- some error + * - BUSY -- flash is executing last command. It can not execute this + * new command now. + * + */ +ResultStatus_t FLASH_Program(uint32_t flashAddr, uint32_t len, const uint8_t *dataP, + flash_cb_t callBack); + + +/** + * @brief Erase all flash and IFR space + * + * @param[in] config: config the action when the command is executing + * + * @note if config->callBack is not NULL, it has to point to a funtion + * that is not in the flash memory + * + * @return - SUCC -- successful + * - ERR -- some error + * - BUSY -- flash is executing last command. It can not execute this + * new command now. + * + */ +ResultStatus_t FLASH_EraseAll(const FLASH_CmdConfig_t *config); + +/** + * @brief Erase a flash sector + * + * @param[in] addr: sector start address + * @param[in] config: config the action when the command is executing + * + * @note if config->callBack is not NULL, it has to point to a funtion + * that is not in the flash memory that flash commands is executing + * in. + * + * @return - SUCC -- successful + * - ERR -- some error + * - BUSY -- flash is executing last command. It can not execute this + * new command now. + * + */ +ResultStatus_t FLASH_EraseSector(uint32_t addr, const FLASH_CmdConfig_t *config); + +/** + * @brief Flash enters security mode. In this mdoe, debug Port is prevented + * to read any AHB-AP memory-map addresses + * + * @param[in] debugEraseAllEn: Enable/Disable debug erase-all. + * - ENABLE: debug erase all request is allowed to + * erase flash + * - DIABLE: debug erase all request cannot erase flash + * @param[in] config: config the action when the command is executing + * + * @note if config->callBack is not NULL, it has to point to a funtion + * that is not in the flash memory that flash commands is executing + * in. + * + * @return - SUCC -- successful + * - ERR -- some error + * - BUSY -- flash is executing last command. It can not execute this + * new command now. + * + */ +ResultStatus_t FLASH_EnterSecurityMode(ControlState_t debugEraseAllEn, + const FLASH_CmdConfig_t *config); + +/** + * @brief Set wait state. If the system clock frequency is higher than + * flash clock, some wait-states are required to be added to wait + * for flash data ready. + * + * @param[in] cycle: number of additional wait-state is added. + * Its range is 0-15. + * + * @return none + * + */ +void FLASH_SetWaitState(uint8_t cycle); + +/** + * @brief Get FLASHC status + * + * @param[in] statMask: the status to be get + * + * @return the status + * + */ +FlagStatus_t FLASH_GetStatus(uint32_t statMask); + +/** + * @brief This function will wait until command is completed + * + * @param[in] none + * + * @return none + * + */ +void FLASH_WaitUntilCmdComplete(void); + +/** + * @brief Request to abort a command write sequence + * + * @param[in] none + * + * @note none + * + * @return - FLASH_ABORT_OK -- abort flash command succeeded + * - FLASH_ABORT_FINISHED -- abort failed, but flash command has been finished + * - FLASH_ABORT_TIMEOUT -- abort flash command timeout + * + */ +FLASH_AbortResult_t FLASH_AbortCommand(void); + +/** + * @brief Install callback function + * + * @param[in] intType: select interrrupt type + * @param[in] cbFun: indicate callback function + * + * @return none + * + */ +void FLASH_InstallCallBackFunc(FLASH_Int_t intType, isr_cb_t * cbFun); + +/** + * @brief Mask/Unmask interrupt + * + * @param[in] intType: select interrrupt type + * @param[in] intMask: MASK/UNMASK + * + * @return none + * + */ +void FLASH_IntMask(FLASH_Int_t intType, IntMask_t intMask); + +/** + * @brief Clear interrupt + * + * @param[in] intType: select interrrupt type + * + * @return none + * + */ +void FLASH_IntClear(FLASH_Int_t intType); + + +/** + * @brief flash module init + * + * @param[in] none + * + * @return - SUCC -- Initialization succeeded. + * - ERR -- Initialization failed. + * + */ +ResultStatus_t Flash_Init(void); + +/** @} end of group FLASH_Public_FunctionDeclaration */ + +/** @} end of group FLASH */ + +/** @} end of group Z20K11X_Peripheral_Driver */ +#endif /* Z20K11XM_FLASH_H__ */ diff --git a/StdDriver/Inc/Z20K11xM_gpio.h b/StdDriver/Inc/Z20K11xM_gpio.h new file mode 100644 index 0000000..e20ee7f --- /dev/null +++ b/StdDriver/Inc/Z20K11xM_gpio.h @@ -0,0 +1,1295 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_gpio.h + * @brief : GPIO driver module header file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ + +#ifndef Z20K11XM_GPIO_H +#define Z20K11XM_GPIO_H + +#include "Z20K11xM_drv.h" + +/** @addtogroup Z20K11X_Peripheral_Driver + * @{ + */ + +/** @addtogroup GPIO + * @{ + */ + +/** @defgroup PORT_Public_Types + * @{ + */ + +/** + * @brief PORT ID type definition + */ +typedef enum +{ + PORT_A = 0U, /*!< PORT_A */ + PORT_B, /*!< PORT_B */ + PORT_C, /*!< PORT_C */ + PORT_D, /*!< PORT_D */ + PORT_E /*!< PORT_E */ +} PORT_ID_t; + +/** + * @brief PORT GPIO Number type definition + */ +typedef enum +{ + GPIO_0 = 0U, /*!< GPIO0 Pin */ + GPIO_1, /*!< GPIO1 Pin */ + GPIO_2, /*!< GPIO2 Pin */ + GPIO_3, /*!< GPIO3 Pin */ + GPIO_4, /*!< GPIO4 Pin */ + GPIO_5, /*!< GPIO5 Pin */ + GPIO_6, /*!< GPIO6 Pin */ + GPIO_7, /*!< GPIO7 Pin */ + GPIO_8, /*!< GPIO8 Pin */ + GPIO_9, /*!< GPIO9 Pin */ + GPIO_10, /*!< GPIO10 Pin */ + GPIO_11, /*!< GPIO11 Pin */ + GPIO_12, /*!< GPIO12 Pin */ + GPIO_13, /*!< GPIO13 Pin */ + GPIO_14, /*!< GPIO14 Pin */ + GPIO_15, /*!< GPIO15 Pin */ + GPIO_16, /*!< GPIO16 Pin */ + GPIO_17, /*!< GPIO17 Pin */ + GPIO_18, /*!< GPIO18 Pin */ + GPIO_19, /*!< GPIO19 Pin */ + GPIO_20, /*!< GPIO20 Pin */ + GPIO_21, /*!< GPIO21 Pin */ + GPIO_22, /*!< GPIO22 Pin */ + GPIO_23, /*!< GPIO23 Pin */ + GPIO_24, /*!< GPIO24 Pin */ + GPIO_25, /*!< GPIO25 Pin */ + GPIO_26, /*!< GPIO26 Pin */ + GPIO_27, /*!< GPIO27 Pin */ + GPIO_28, /*!< GPIO28 Pin */ + GPIO_29, /*!< GPIO29 Pin */ + GPIO_30, /*!< GPIO30 Pin */ + GPIO_31 /*!< GPIO31 Pin */ +} PORT_GPIONO_t; + +/** + * @brief PORT half pins type definition + */ +typedef enum +{ + PORT_LOW_HALF_PINS = 0U, /*!< PORT low half pins */ + PORT_HIGH_HALF_PINS /*!< PORT high half pins */ +} PORT_GlobalPinsControl_t; + +/** + * @brief PORT pull type definition + */ +typedef enum +{ + PORT_PULL_DISABLED = 0U, /*!< PORT pull none */ + PORT_PULL_DOWN = 2U, /*!< PORT pull down */ + PORT_PULL_UP = 3U /*!< PORT pull up */ +} PORT_PullConfig_t; + +/** + * @brief PORT slew rate type definition + */ +typedef enum +{ + PORT_FAST_RATE = 0U, /*!< PORT fast rate */ + PORT_SLOW_RATE /*!< PORT slow rate */ +} PORT_SlewRate_t; + +/** + * @brief PORT interrupt configuration type definition + */ +typedef enum +{ + PORT_ISF_DISABLED = 0U, /*!< PORT isf disabled */ + PORT_ISF_DMA_RISING_EDGE = 1U, /*!< PORT isf dma rising */ + PORT_ISF_DMA_FALLING_EDGE = 2U, /*!< PORT isf dma falling */ + PORT_ISF_DMA_BOTH_EDGE = 3U, /*!< PORT isf dma both */ + PORT_ISF_INT_LOGIC_0 = 8U, /*!< PORT isf interrupt logic 0 */ + PORT_ISF_INT_RISING_EDGE = 9U, /*!< PORT isf interrupt rising */ + PORT_ISF_INT_FALLING_EDGE = 10U, /*!< PORT isf interrupt falling */ + PORT_ISF_INT_BOTH_EDGE = 11U, /*!< PORT isf interrupt both */ + PORT_ISF_INT_LOGIC_1 = 12U /*!< PORT isf interrupt logic 1 */ +} PORT_IntConfig_t; + +/** + * @brief PORT driver strength type definition + */ +typedef enum +{ + PORT_LOW_DRIVE_STRENGTH = 0U, /*!< PORT low drive strength */ + PORT_HIGH_DRIVE_STRENGTH /*!< PORT high drive strength */ +} PORT_DriveStrength_t; + +/** + * @brief PORT pin configuration struct definition + */ +typedef struct +{ + PORT_PullConfig_t pullConfig; /*!< Configure pull type: + - PORT_PULL_NONE(0) + - PORT_PULL_DOWN(2) + - PORT_PULL_UP(3) + */ + PORT_SlewRate_t slewRateConfig; /*!< Configure slew rate type + - PORT_FAST_RATE(0) + - PORT_SLOW_RATE(1) + */ + ControlState_t + passiveFilterConfig; /*!< Configure the enable of the passive filter, + - DISABLE + - ENABLE + */ + ControlState_t openDrainConfig; /*!< Configure the enable of the open drain, + - DISABLE + - ENABLE + */ + PORT_DriveStrength_t + driveStrengthConfig; /*!< Configure drive strength type, + - PORT_LOW_DRIVE_STRENGTH(0) + - PORT_HIGH_DRIVE_STRENGTH(1) + */ + ControlState_t filterEnable; /*!< Configure the enable of the filter, + - DISABLE + - ENABLE + */ + uint8_t filterConfig; /*!< Configure filter:0x0-0x1F */ +} PORT_PinConfig_t; + +/** @} end of group PORT_Public_Types */ + +/** @defgroup GPIO_Public_Types + * @{ + */ +/** + * @brief GPIO data direction type definition + */ +typedef enum +{ + GPIO_INPUT = 0U, /*!< Set GPIO port data direction as input */ + GPIO_OUTPUT /*!< Set GPIO port data direction as output */ +} GPIO_Dir_t; + +/** + * @brief GPIO data Input/Output type definition + */ +typedef enum +{ + GPIO_LOW = 0U, /*!< Input/Output low level(0) */ + GPIO_HIGH /*!< Input/Output low level(1) */ +} GPIO_LVL_t; + +/** @} end of group GPIO_Public_Types */ + +/** @defgroup PORT_Pinmux + * @{ + */ + +/** + * @brief PORT Pinmux function type definition + */ +typedef enum +{ + PINMUX_FUNCTION_0 = 0U, /*!< PORT pin mux function 0 */ + PINMUX_FUNCTION_1, /*!< PORT pin mux function 1 */ + PINMUX_FUNCTION_2, /*!< PORT pin mux function 2 */ + PINMUX_FUNCTION_3, /*!< PORT pin mux function 3 */ + PINMUX_FUNCTION_4, /*!< PORT pin mux function 4 */ + PINMUX_FUNCTION_5, /*!< PORT pin mux function 5 */ + PINMUX_FUNCTION_6, /*!< PORT pin mux function 6 */ + PINMUX_FUNCTION_7 /*!< PORT pin mux function 7 */ +} PORT_PinMuxFunc_t; + +/* PTA0 pinmux function */ +#define PTA0_ADC0_CH0 PINMUX_FUNCTION_0 +#define PTA0_CMP0_IN0 PINMUX_FUNCTION_0 +#define PTA0_GPIO PINMUX_FUNCTION_1 +#define PTA0_TIM2_CH1 PINMUX_FUNCTION_2 +#define PTA0_I2C1_SCL PINMUX_FUNCTION_5 +#define PTA0_UART0_CTS PINMUX_FUNCTION_6 +#define PTA0_TMU_OUT3 PINMUX_FUNCTION_7 + +/* PTA1 pinmux function */ +#define PTA1_ADC0_CH1 PINMUX_FUNCTION_0 +#define PTA1_ADC0_N_CH0 PINMUX_FUNCTION_0 +#define PTA1_CMP0_IN1 PINMUX_FUNCTION_0 +#define PTA1_GPIO PINMUX_FUNCTION_1 +#define PTA1_TIM1_CH1 PINMUX_FUNCTION_2 +#define PTA1_I2C1_SDA PINMUX_FUNCTION_5 +#define PTA1_UART0_RTS PINMUX_FUNCTION_6 +#define PTA1_TMU_OUT0 PINMUX_FUNCTION_7 + +/* PTA2 pinmux function */ +#define PTA2_GPIO PINMUX_FUNCTION_1 +#define PTA2_TIM0_CH0 PINMUX_FUNCTION_2 +#define PTA2_I2C0_SDA PINMUX_FUNCTION_3 +#define PTA2_EWDT_OUT_b PINMUX_FUNCTION_4 +#define PTA2_UART0_RX PINMUX_FUNCTION_6 + +/* PTA3 pinmux function */ +#define PTA3_GPIO PINMUX_FUNCTION_1 +#define PTA3_TIM0_CH1 PINMUX_FUNCTION_2 +#define PTA3_I2C0_SCL PINMUX_FUNCTION_3 +#define PTA3_EWDT_IN PINMUX_FUNCTION_4 +#define PTA3_SPI1_SIN PINMUX_FUNCTION_5 +#define PTA3_UART0_TX PINMUX_FUNCTION_6 + +/* PTA4 pinmux function */ +#define PTA4_GPIO PINMUX_FUNCTION_1 +#define PTA4_CAN0_RX PINMUX_FUNCTION_3 +#define PTA4_CMP0_OUT PINMUX_FUNCTION_4 +#define PTA4_EWDT_OUT_b PINMUX_FUNCTION_5 +#define PTA4_SWD_DIO PINMUX_FUNCTION_7 + +/* PTA5 pinmux function */ +#define PTA5_GPIO PINMUX_FUNCTION_1 +#define PTA5_TCLK1 PINMUX_FUNCTION_3 +#define PTA5_RESET_b PINMUX_FUNCTION_7 + +/* PTA6 pinmux function */ +#define PTA6_ADC0_CH2 PINMUX_FUNCTION_0 +#define PTA6_GPIO PINMUX_FUNCTION_1 +#define PTA6_TIM0_FLT1 PINMUX_FUNCTION_2 +#define PTA6_SPI1_PCS1 PINMUX_FUNCTION_3 +#define PTA6_UART3_RX PINMUX_FUNCTION_5 +#define PTA6_UART1_CTS PINMUX_FUNCTION_6 + +/* PTA7 pinmux function */ +#define PTA7_TM1 PINMUX_FUNCTION_0 +#define PTA7_ADC0_CH3 PINMUX_FUNCTION_0 +#define PTA7_ADC0_N_CH1 PINMUX_FUNCTION_0 +#define PTA7_GPIO PINMUX_FUNCTION_1 +#define PTA7_UART3_TX PINMUX_FUNCTION_5 +#define PTA7_UART1_RTS PINMUX_FUNCTION_6 + +/* PTA10 pinmux function */ +#define PTA10_XTAL32 PINMUX_FUNCTION_0 +#define PTA10_GPIO PINMUX_FUNCTION_1 +#define PTA10_TIM1_CH4 PINMUX_FUNCTION_2 +#define PTA10_UART0_RX PINMUX_FUNCTION_3 +#define PTA10_CAN0_RX PINMUX_FUNCTION_4 +#define PTA10_SPI1_SCK PINMUX_FUNCTION_5 +#define PTA10_UART3_RX PINMUX_FUNCTION_6 + +/* PTA11 pinmux function */ +#define PTA11_EXTAL32 PINMUX_FUNCTION_0 +#define PTA11_GPIO PINMUX_FUNCTION_1 +#define PTA11_TIM1_CH5 PINMUX_FUNCTION_2 +#define PTA11_UART0_TX PINMUX_FUNCTION_3 +#define PTA11_CAN0_TX PINMUX_FUNCTION_4 +#define PTA11_UART3_TX PINMUX_FUNCTION_6 + +/* PTA12 pinmux function */ +#define PTA12_SENSE_BUS PINMUX_FUNCTION_0 +#define PTA12_GPIO PINMUX_FUNCTION_1 +#define PTA12_TIM1_CH6 PINMUX_FUNCTION_2 +#define PTA12_CAN1_RX PINMUX_FUNCTION_3 +#define PTA12_UART0_RX PINMUX_FUNCTION_4 +#define PTA12_TIM2_CH2 PINMUX_FUNCTION_5 + +/* PTA13 pinmux function */ +#define PTA13_FORCE_BUS PINMUX_FUNCTION_0 +#define PTA13_GPIO PINMUX_FUNCTION_1 +#define PTA13_TIM1_CH7 PINMUX_FUNCTION_2 +#define PTA13_CAN1_TX PINMUX_FUNCTION_3 +#define PTA13_UART0_TX PINMUX_FUNCTION_4 +#define PTA13_TIM2_CH3 PINMUX_FUNCTION_5 + +/* PTA15 pinmux function */ +#define PTA15_GPIO PINMUX_FUNCTION_1 +#define PTA15_TIM1_CH2 PINMUX_FUNCTION_2 +#define PTA15_SPI2_PCS0 PINMUX_FUNCTION_5 + +/* PTA16 pinmux function */ +#define PTA16_GPIO PINMUX_FUNCTION_1 +#define PTA16_TIM1_CH3 PINMUX_FUNCTION_2 +#define PTA16_SPI1_PCS1 PINMUX_FUNCTION_5 + +/* PTB0 pinmux function */ +#define PTB0_ADC0_CH4 PINMUX_FUNCTION_0 +#define PTB0_GPIO PINMUX_FUNCTION_1 +#define PTB0_UART0_RX PINMUX_FUNCTION_2 +#define PTB0_SPI0_PCS0 PINMUX_FUNCTION_3 +#define PTB0_STIM0_ALT3 PINMUX_FUNCTION_4 +#define PTB0_CAN0_RX PINMUX_FUNCTION_5 + +/* PTB1 pinmux function */ +#define PTB1_ADC0_CH5 PINMUX_FUNCTION_0 +#define PTB1_ADC0_N_CH2 PINMUX_FUNCTION_0 +#define PTB1_GPIO PINMUX_FUNCTION_1 +#define PTB1_UART0_TX PINMUX_FUNCTION_2 +#define PTB1_SPI0_SOUT PINMUX_FUNCTION_3 +#define PTB1_TCLK0 PINMUX_FUNCTION_4 +#define PTB1_CAN0_TX PINMUX_FUNCTION_5 + +/* PTB2 pinmux function */ +#define PTB2_ADC0_CH6 PINMUX_FUNCTION_0 +#define PTB2_GPIO PINMUX_FUNCTION_1 +#define PTB2_TIM1_CH0 PINMUX_FUNCTION_2 +#define PTB2_SPI0_SCK PINMUX_FUNCTION_3 +#define PTB2_TMU_IN3 PINMUX_FUNCTION_6 + +/* PTB3 pinmux function */ +#define PTB3_ADC0_CH7 PINMUX_FUNCTION_0 +#define PTB3_GPIO PINMUX_FUNCTION_1 +#define PTB3_TIM1_CH1 PINMUX_FUNCTION_2 +#define PTB3_SPI0_SIN PINMUX_FUNCTION_3 +#define PTB3_TMU_IN2 PINMUX_FUNCTION_6 + +/* PTB4 pinmux function */ +#define PTB4_ADC0_CH16 PINMUX_FUNCTION_0 +#define PTB4_GPIO PINMUX_FUNCTION_1 +#define PTB4_TIM0_CH4 PINMUX_FUNCTION_2 +#define PTB4_SPI0_SOUT PINMUX_FUNCTION_3 +#define PTB4_TMU_IN1 PINMUX_FUNCTION_6 + +/* PTB5 pinmux function */ +#define PTB5_ADC0_CH17 PINMUX_FUNCTION_0 +#define PTB5_GPIO PINMUX_FUNCTION_1 +#define PTB5_TIM0_CH5 PINMUX_FUNCTION_2 +#define PTB5_SPI0_PCS1 PINMUX_FUNCTION_3 +#define PTB5_SPI0_PCS0 PINMUX_FUNCTION_4 +#define PTB5_CLKOUT PINMUX_FUNCTION_5 +#define PTB5_TMU_IN0 PINMUX_FUNCTION_6 +#define PTB5_EWDT_OUT_b PINMUX_FUNCTION_7 + +/* PTB6 pinmux function */ +#define PTB6_XTAL PINMUX_FUNCTION_0 +#define PTB6_GPIO PINMUX_FUNCTION_1 +#define PTB6_I2C0_SDA PINMUX_FUNCTION_2 + +/* PTB7 pinmux function */ +#define PTB7_EXTAL PINMUX_FUNCTION_0 +#define PTB7_GPIO PINMUX_FUNCTION_1 +#define PTB7_I2C0_SCL PINMUX_FUNCTION_2 + +/* PTB12 pinmux function */ +#define PTB12_GPIO PINMUX_FUNCTION_1 +#define PTB12_TIM0_CH0 PINMUX_FUNCTION_2 +#define PTB12_I2C1_SCL PINMUX_FUNCTION_5 + +/* PTB13 pinmux function */ +#define PTB13_TM0 PINMUX_FUNCTION_0 +#define PTB13_GPIO PINMUX_FUNCTION_1 +#define PTB13_TIM0_CH1 PINMUX_FUNCTION_2 +#define PTB13_TIM0_FLT1 PINMUX_FUNCTION_3 +#define PTB13_CAN1_TX PINMUX_FUNCTION_4 +#define PTB13_I2C1_SDA PINMUX_FUNCTION_5 + +/* PTB14 pinmux function */ +#define PTB14_GPIO PINMUX_FUNCTION_1 +#define PTB14_TIM0_CH2 PINMUX_FUNCTION_2 +#define PTB14_SPI1_SCK PINMUX_FUNCTION_3 + +/* PTB15 pinmux function */ +#define PTB15_GPIO PINMUX_FUNCTION_1 +#define PTB15_TIM0_CH3 PINMUX_FUNCTION_2 +#define PTB15_SPI1_SIN PINMUX_FUNCTION_3 +#define PTB15_UART2_RX PINMUX_FUNCTION_4 + +/* PTB16 pinmux function */ +#define PTB16_GPIO PINMUX_FUNCTION_1 +#define PTB16_TIM0_CH4 PINMUX_FUNCTION_2 +#define PTB16_SPI1_SOUT PINMUX_FUNCTION_3 +#define PTB16_UART2_TX PINMUX_FUNCTION_4 + +/* PTB17 pinmux function */ +#define PTB17_GPIO PINMUX_FUNCTION_1 +#define PTB17_TIM0_CH5 PINMUX_FUNCTION_2 +#define PTB17_SPI1_PCS0 PINMUX_FUNCTION_5 + +/* PTC0 pinmux function */ +#define PTC0_ADC0_CH8 PINMUX_FUNCTION_0 +#define PTC0_GPIO PINMUX_FUNCTION_1 +#define PTC0_TIM0_CH0 PINMUX_FUNCTION_2 +#define PTC0_SPI2_SIN PINMUX_FUNCTION_3 +#define PTC0_UART2_RX PINMUX_FUNCTION_5 +#define PTC0_TIM1_CH6 PINMUX_FUNCTION_6 + +/* PTC1 pinmux function */ +#define PTC1_ADC0_CH9 PINMUX_FUNCTION_0 +#define PTC1_GPIO PINMUX_FUNCTION_1 +#define PTC1_TIM0_CH1 PINMUX_FUNCTION_2 +#define PTC1_SPI2_SOUT PINMUX_FUNCTION_3 +#define PTC1_UART2_TX PINMUX_FUNCTION_5 +#define PTC1_TIM1_CH7 PINMUX_FUNCTION_6 + +/* PTC2 pinmux function */ +#define PTC2_ADC0_CH10 PINMUX_FUNCTION_0 +#define PTC2_CMP0_IN5 PINMUX_FUNCTION_0 +#define PTC2_GPIO PINMUX_FUNCTION_1 +#define PTC2_TIM0_CH2 PINMUX_FUNCTION_2 +#define PTC2_CAN0_RX PINMUX_FUNCTION_3 +#define PTC2_UART0_RX PINMUX_FUNCTION_4 + +/* PTC3 pinmux function */ +#define PTC3_ADC0_CH11 PINMUX_FUNCTION_0 +#define PTC3_CMP0_IN4 PINMUX_FUNCTION_0 +#define PTC3_GPIO PINMUX_FUNCTION_1 +#define PTC3_TIM0_CH3 PINMUX_FUNCTION_2 +#define PTC3_CAN0_TX PINMUX_FUNCTION_3 +#define PTC3_UART0_TX PINMUX_FUNCTION_4 + +/* PTC4 pinmux function */ +#define PTC4_CMP0_IN2 PINMUX_FUNCTION_0 +#define PTC4_GPIO PINMUX_FUNCTION_1 +#define PTC4_TIM1_CH0 PINMUX_FUNCTION_2 +#define PTC4_EWDT_IN PINMUX_FUNCTION_5 +#define PTC4_SWD_CLK PINMUX_FUNCTION_7 + +/* PTC5 pinmux function */ +#define PTC5_GPIO PINMUX_FUNCTION_1 +#define PTC5_TIM2_CH0 PINMUX_FUNCTION_2 +#define PTC5_SPI1_SIN PINMUX_FUNCTION_5 +#define PTC5_NMI_b PINMUX_FUNCTION_7 + +/* PTC6 pinmux function */ +#define PTC6_GPIO PINMUX_FUNCTION_1 +#define PTC6_UART1_RX PINMUX_FUNCTION_2 +#define PTC6_CAN1_RX PINMUX_FUNCTION_3 +#define PTC6_TIM0_CH2 PINMUX_FUNCTION_4 + +/* PTC7 pinmux function */ +#define PTC7_GPIO PINMUX_FUNCTION_1 +#define PTC7_UART1_TX PINMUX_FUNCTION_2 +#define PTC7_CAN1_TX PINMUX_FUNCTION_3 +#define PTC7_TIM0_CH3 PINMUX_FUNCTION_4 + +/* PTC8 pinmux function */ +#define PTC8_TM2 PINMUX_FUNCTION_0 +#define PTC8_GPIO PINMUX_FUNCTION_1 +#define PTC8_UART1_RX PINMUX_FUNCTION_2 +#define PTC8_TIM1_FLT0 PINMUX_FUNCTION_3 +#define PTC8_CAN1_RX PINMUX_FUNCTION_5 +#define PTC8_UART0_CTS PINMUX_FUNCTION_6 + +/* PTC9 pinmux function */ +#define PTC9_TM3 PINMUX_FUNCTION_0 +#define PTC9_GPIO PINMUX_FUNCTION_1 +#define PTC9_UART1_TX PINMUX_FUNCTION_2 +#define PTC9_TIM1_FLT1 PINMUX_FUNCTION_3 +#define PTC9_CAN1_TX PINMUX_FUNCTION_5 +#define PTC9_UART0_RTS PINMUX_FUNCTION_6 + +/* PTC14 pinmux function */ +#define PTC14_ADC0_CH12 PINMUX_FUNCTION_0 +#define PTC14_GPIO PINMUX_FUNCTION_1 +#define PTC14_TIM1_CH2 PINMUX_FUNCTION_2 +#define PTC14_SPI2_PCS0 PINMUX_FUNCTION_3 +#define PTC14_TIM2_CH4 PINMUX_FUNCTION_4 +#define PTC14_SPI0_PCS0 PINMUX_FUNCTION_5 +#define PTC14_TMU_IN9 PINMUX_FUNCTION_6 + +/* PTC15 pinmux function */ +#define PTC15_ADC0_CH13 PINMUX_FUNCTION_0 +#define PTC15_GPIO PINMUX_FUNCTION_1 +#define PTC15_TIM1_CH3 PINMUX_FUNCTION_2 +#define PTC15_SPI2_SCK PINMUX_FUNCTION_3 +#define PTC15_SPI0_SOUT PINMUX_FUNCTION_5 +#define PTC15_TMU_IN8 PINMUX_FUNCTION_6 + +/* PTC16 pinmux function */ +#define PTC16_ADC0_CH14 PINMUX_FUNCTION_0 +#define PTC16_GPIO PINMUX_FUNCTION_1 +#define PTC16_CAN0_RX PINMUX_FUNCTION_3 +#define PTC16_SPI0_SCK PINMUX_FUNCTION_4 +#define PTC16_TIM0_CH0 PINMUX_FUNCTION_5 + +/* PTC17 pinmux function */ +#define PTC17_ADC0_CH15 PINMUX_FUNCTION_0 +#define PTC17_GPIO PINMUX_FUNCTION_1 +#define PTC17_CAN0_TX PINMUX_FUNCTION_3 +#define PTC17_SPI0_SIN PINMUX_FUNCTION_4 +#define PTC17_TIM0_CH1 PINMUX_FUNCTION_5 +#define PTC17_SPI2_SIN PINMUX_FUNCTION_6 + +/* PTD0 pinmux function */ +#define PTD0_CMP0_IN9 PINMUX_FUNCTION_0 +#define PTD0_GPIO PINMUX_FUNCTION_1 +#define PTD0_TIM0_CH2 PINMUX_FUNCTION_2 +#define PTD0_SPI1_SCK PINMUX_FUNCTION_3 +#define PTD0_TIM2_CH0 PINMUX_FUNCTION_4 +#define PTD0_CAN0_RX PINMUX_FUNCTION_5 + +/* PTD1 pinmux function */ +#define PTD1_CMP0_IN8 PINMUX_FUNCTION_0 +#define PTD1_GPIO PINMUX_FUNCTION_1 +#define PTD1_TIM0_CH3 PINMUX_FUNCTION_2 +#define PTD1_SPI1_SIN PINMUX_FUNCTION_3 +#define PTD1_TIM2_CH1 PINMUX_FUNCTION_4 +#define PTD1_CAN0_TX PINMUX_FUNCTION_5 +#define PTD1_PMU_req PINMUX_FUNCTION_6 +#define PTD1_TMU_OUT2 PINMUX_FUNCTION_7 + +/* PTD2 pinmux function */ +#define PTD2_GPIO PINMUX_FUNCTION_1 +#define PTD2_TIM1_CH4 PINMUX_FUNCTION_2 +#define PTD2_SPI1_SOUT PINMUX_FUNCTION_3 +#define PTD2_UART1_RX PINMUX_FUNCTION_5 +#define PTD2_TMU_IN5 PINMUX_FUNCTION_6 + +/* PTD3 pinmux function */ +#define PTD3_GPIO PINMUX_FUNCTION_1 +#define PTD3_TIM1_CH5 PINMUX_FUNCTION_2 +#define PTD3_SPI1_PCS0 PINMUX_FUNCTION_3 +#define PTD3_CAN1_RX PINMUX_FUNCTION_4 +#define PTD3_UART1_TX PINMUX_FUNCTION_5 +#define PTD3_TMU_IN4 PINMUX_FUNCTION_6 +#define PTD3_NMI_b PINMUX_FUNCTION_7 + +/* PTD4 pinmux function */ +#define PTD4_GPIO PINMUX_FUNCTION_1 + +/* PTD5 pinmux function */ +#define PTD5_GPIO PINMUX_FUNCTION_1 +#define PTD5_TIM2_CH3 PINMUX_FUNCTION_2 +#define PTD5_STIM0_ALT2 PINMUX_FUNCTION_3 +#define PTD5_TIM2_FLT1 PINMUX_FUNCTION_4 +#define PTD5_UART2_RX PINMUX_FUNCTION_5 +#define PTD5_TMU_IN7 PINMUX_FUNCTION_6 + +/* PTD6 pinmux function */ +#define PTD6_CMP0_IN7 PINMUX_FUNCTION_0 +#define PTD6_GPIO PINMUX_FUNCTION_1 +#define PTD6_UART2_RX PINMUX_FUNCTION_2 +#define PTD6_TIM0_CH6 PINMUX_FUNCTION_5 + +/* PTD7 pinmux function */ +#define PTD7_CMP0_IN6 PINMUX_FUNCTION_0 +#define PTD7_GPIO PINMUX_FUNCTION_1 +#define PTD7_UART2_TX PINMUX_FUNCTION_2 +#define PTD7_TIM0_CH7 PINMUX_FUNCTION_5 +#define PTD7_TIM0_CH0 PINMUX_FUNCTION_6 + +/* PTD10 pinmux function */ +#define PTD10_CMP0_IN13 PINMUX_FUNCTION_0 +#define PTD10_GPIO PINMUX_FUNCTION_1 +#define PTD10_TIM2_CH0 PINMUX_FUNCTION_2 +#define PTD10_TIM1_CH6 PINMUX_FUNCTION_6 + +/* PTD11 pinmux function */ +#define PTD11_CMP0_IN12 PINMUX_FUNCTION_0 +#define PTD11_GPIO PINMUX_FUNCTION_1 +#define PTD11_TIM2_CH1 PINMUX_FUNCTION_2 +#define PTD11_UART2_RX PINMUX_FUNCTION_5 +#define PTD11_UART2_CTS PINMUX_FUNCTION_6 + +/* PTD15 pinmux function */ +#define PTD15_GPIO PINMUX_FUNCTION_1 +#define PTD15_TIM0_CH0 PINMUX_FUNCTION_2 +#define PTD15_UART0_RX PINMUX_FUNCTION_3 +#define PTD15_SPI0_SCK PINMUX_FUNCTION_4 +#define PTD15_SPI2_SCK PINMUX_FUNCTION_5 +#define PTD15_TMU_OUT1 PINMUX_FUNCTION_7 + +/* PTD16 pinmux function */ +#define PTD16_GPIO PINMUX_FUNCTION_1 +#define PTD16_TIM0_CH1 PINMUX_FUNCTION_2 +#define PTD16_UART0_TX PINMUX_FUNCTION_3 +#define PTD16_SPI0_SIN PINMUX_FUNCTION_4 +#define PTD16_SPI2_SIN PINMUX_FUNCTION_5 + +/* PTD17 pinmux function */ +#define PTD17_GPIO PINMUX_FUNCTION_1 +#define PTD17_UART2_RX PINMUX_FUNCTION_3 +#define PTD17_SPI2_SCK PINMUX_FUNCTION_5 + +/* PTE0 pinmux function */ +#define PTE0_GPIO PINMUX_FUNCTION_1 +#define PTE0_SPI0_SCK PINMUX_FUNCTION_2 +#define PTE0_TCLK1 PINMUX_FUNCTION_3 +#define PTE0_UART3_RX PINMUX_FUNCTION_4 +#define PTE0_SPI1_SOUT PINMUX_FUNCTION_5 + +/* PTE1 pinmux function */ +#define PTE1_GPIO PINMUX_FUNCTION_1 +#define PTE1_SPI0_SIN PINMUX_FUNCTION_2 +#define PTE1_UART3_TX PINMUX_FUNCTION_4 +#define PTE1_SPI1_PCS0 PINMUX_FUNCTION_5 +#define PTE1_TIM1_FLT1 PINMUX_FUNCTION_6 + +/* PTE2 pinmux function */ +#define PTE2_GPIO PINMUX_FUNCTION_1 +#define PTE2_SPI0_SOUT PINMUX_FUNCTION_2 +#define PTE2_STIM0_ALT3 PINMUX_FUNCTION_3 +#define PTE2_TIM2_CH6 PINMUX_FUNCTION_4 +#define PTE2_UART1_RX PINMUX_FUNCTION_5 +#define PTE2_UART1_CTS PINMUX_FUNCTION_6 + +/* PTE3 pinmux function */ +#define PTE3_GPIO PINMUX_FUNCTION_1 +#define PTE3_TIM0_FLT0 PINMUX_FUNCTION_2 +#define PTE3_UART2_RTS PINMUX_FUNCTION_3 +#define PTE3_TIM2_FLT0 PINMUX_FUNCTION_4 +#define PTE3_SPI2_SOUT PINMUX_FUNCTION_5 +#define PTE3_TMU_IN6 PINMUX_FUNCTION_6 +#define PTE3_CMP0_OUT PINMUX_FUNCTION_7 + +/* PTE6 pinmux function */ +#define PTE6_GPIO PINMUX_FUNCTION_1 +#define PTE6_SPI0_PCS0 PINMUX_FUNCTION_2 +#define PTE6_TIM2_CH7 PINMUX_FUNCTION_4 +#define PTE6_UART1_TX PINMUX_FUNCTION_5 +#define PTE6_UART1_RTS PINMUX_FUNCTION_6 + +/* PTE7 pinmux function */ +#define PTE7_GPIO PINMUX_FUNCTION_1 +#define PTE7_TIM0_CH7 PINMUX_FUNCTION_2 +#define PTE7_TIM0_FLT0 PINMUX_FUNCTION_3 + +/* PTE8 pinmux function */ +#define PTE8_CMP0_IN3 PINMUX_FUNCTION_0 +#define PTE8_GPIO PINMUX_FUNCTION_1 +#define PTE8_TIM0_CH6 PINMUX_FUNCTION_2 +#define PTE8_TCLK2 PINMUX_FUNCTION_5 +#define PTE8_EWDT_IN PINMUX_FUNCTION_7 + +/* PTE9 pinmux function */ +#define PTE9_GPIO PINMUX_FUNCTION_1 +#define PTE9_TIM0_CH7 PINMUX_FUNCTION_2 +#define PTE9_UART2_CTS PINMUX_FUNCTION_3 +#define PTE9_TIM2_FLT0 PINMUX_FUNCTION_4 +#define PTE9_SPI2_PCS1 PINMUX_FUNCTION_5 + +/* PTE10 pinmux function */ +#define PTE10_CMP0_IN11 PINMUX_FUNCTION_0 +#define PTE10_GPIO PINMUX_FUNCTION_1 +#define PTE10_CLKOUT PINMUX_FUNCTION_2 +#define PTE10_SPI2_PCS0 PINMUX_FUNCTION_3 +#define PTE10_TIM2_CH4 PINMUX_FUNCTION_4 +#define PTE10_TIM0_CH2 PINMUX_FUNCTION_5 +#define PTE10_TIM2_CH0 PINMUX_FUNCTION_6 +#define PTE10_TMU_OUT4 PINMUX_FUNCTION_7 + +/* PTE11 pinmux function */ +#define PTE11_CMP0_IN10 PINMUX_FUNCTION_0 +#define PTE11_GPIO PINMUX_FUNCTION_1 +#define PTE11_SPI2_PCS1 PINMUX_FUNCTION_2 +#define PTE11_STIM0_ALT1 PINMUX_FUNCTION_3 +#define PTE11_TIM2_CH5 PINMUX_FUNCTION_4 +#define PTE11_SPI1_SCK PINMUX_FUNCTION_5 +#define PTE11_CAN0_RX PINMUX_FUNCTION_6 +#define PTE11_TMU_OUT5 PINMUX_FUNCTION_7 + +/* PTE12 pinmux function */ +#define PTE12_GPIO PINMUX_FUNCTION_1 +#define PTE12_UART2_TX PINMUX_FUNCTION_3 +#define PTE12_SPI2_SIN PINMUX_FUNCTION_5 +/** @} end of group PORT_Pinmux */ + +/** @defgroup PORT_Public_FunctionDeclaration + * @brief PORT functions declaration + * @{ + */ +/** + * @brief PORT a-e,GPIO 0-31 callback function type + */ +typedef void (*port_cb_t)(PORT_ID_t portId, PORT_GPIONO_t gpioNo); +/** + * @brief Configure pins with the same global configuration + * If a pin is locked, global control will not work on it + * + * @param[in] portId: Select the PORT id,such as PORT_A,PORT_B,PORT_C, + * PORT_D,PORT_E. + * @param[in] pins: Select the GPIO pins. + * @param[in] value: Set GPIO pin global value. + * + * @return none. + * + */ +void PORT_GlobalPinsConfig(PORT_ID_t portId, uint32_t pins, uint32_t value); + +/** + * @brief Initialize seleted pin with the given configuration structure. + * + * + * @param[in] portId: Select the PORT id,such as PORT_A,PORT_B,PORT_C, + * PORT_D,PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * @param[in] pinConfig: Pin configuration struct. + * + * @return none. + * + */ +void PORT_PinInit(PORT_ID_t portId, PORT_GPIONO_t gpioNo, + const PORT_PinConfig_t *pinConfig); + +/** + * @brief Configure the pin mux function. + * + * + * @param[in] portId: Select the PORT id,such as PORT_A,PORT_B,PORT_C, + * PORT_D,PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * @param[in] pinMuxFunc: Pin mux function. + * + * @return none. + * + */ +void PORT_PinmuxConfig(PORT_ID_t portId, PORT_GPIONO_t gpioNo, + PORT_PinMuxFunc_t pinMuxFunc); + +/** + * @brief Configure the pin interrupt + * + * @param[in] portId: Select the PORT id,such as PORT_A,PORT_B,PORT_C, + * PORT_D,PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * @param[in] intConfig: Pin interrupt configuration. + * - PORT_ISF_DISABLED(0) + * - PORT_ISF_DMA_RISING_EDGE(1) + * - PORT_ISF_DMA_FALLING_EDGE(2) + * - PORT_ISF_DMA_BOTH_EDGE(3) + * - PORT_ISF_INT_LOGIC_0(8) + * - PORT_ISF_INT_RISING_EDGE(9) + * - PORT_ISF_INT_FALLING_EDGE(10) + * - PORT_ISF_INT_BOTH_EDGE(11) + * - PORT_ISF_INT_LOGIC_1(12) + * + * @return none. + * + */ +void PORT_PinIntConfig(PORT_ID_t portId, PORT_GPIONO_t gpioNo, + PORT_IntConfig_t intConfig); + +/** + * @brief Configure the pin pull configuration. + * + * + * @param[in] portId: Select the PORT id,such as PORT_A,PORT_B,PORT_C, + * PORT_D,PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * @param[in] pullConfig: Pin pull configuration, should be + * PORT_PULL_NONE, PORT_PULL_DOWN and PORT_PULL_UP. + * + * @return none. + * + */ +void PORT_PullConfig(PORT_ID_t portId, PORT_GPIONO_t gpioNo, + PORT_PullConfig_t pullConfig); + +/** + * @brief Configure the pin slew rate configuration. + * + * + * @param[in] portId: Select the PORT id,such as PORT_A,PORT_B,PORT_C, + * PORT_D,PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * @param[in] slewRateConfig: Pin slew rate configuration, should be + * PORT_FAST_RATE and PORT_SLOW_RATE. + * + * @return none. + * + */ +void PORT_SlewRateConfig(PORT_ID_t portId, PORT_GPIONO_t gpioNo, + PORT_SlewRate_t slewRateConfig); + +/** + * @brief Configure the pin passive filter configuration. + * + * + * @param[in] portId: Select the PORT id,such as PORT_A,PORT_B,PORT_C, + * PORT_D,PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * @param[in] passiveFilterConfig: Pin passive filter configuration, should be + * DISABLE and ENABLE. + * + * @return none. + * + */ +void PORT_PassiveFilterConfig(PORT_ID_t portId, PORT_GPIONO_t gpioNo, + ControlState_t passiveFilterConfig); + +/** + * @brief Configure the pin open drain configuration. + * + * + * @param[in] portId: Select the PORT id,such as PORT_A,PORT_B,PORT_C, + * PORT_D,PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * @param[in] openDrainConfig: Pin open drain configuration, should be + * DISABLE and ENABLE. + * + * @return none. + * + */ +void PORT_OpenDrainConfig(PORT_ID_t portId, PORT_GPIONO_t gpioNo, + ControlState_t openDrainConfig); + +/** + * @brief Configure the pin drive strength configuration. + * + * + * @param[in] portId: Select the PORT id,such as PORT_A,PORT_B,PORT_C, + * PORT_D,PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * @param[in] driveStrengthConfig: Pin drive strength configuration, should + * be PORT_LOW_DRIVE_STRENGTH and + * PORT_HIGH_DRIVE_STRENGTH. + * + * @return none. + * + */ +void PORT_DriveStrengthConfig(PORT_ID_t portId, PORT_GPIONO_t gpioNo, + PORT_DriveStrength_t driveStrengthConfig); + +/** + * @brief Enable/Disable the pin filter . + * + * This function enables/disables the pin filter. + * + * @param[in] portId: Select the PORT id,such as PORT_A,PORT_B,PORT_C, + * PORT_D,PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * @param[in] filterEnable: pin filter configuration, should be + DISABLE and ENABLE. + * + * @return none. + * + */ +void PORT_FilterCmd(PORT_ID_t portId, PORT_GPIONO_t gpioNo, + ControlState_t filterEnable); + +/** + * @brief Configure the pin filter configuration. + * + * @param[in] portId: Select the PORT id,such as PORT_A,PORT_B,PORT_C, + * PORT_D,PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * @param[in] filterConfig: pin filter configuration, the value is 0x0 - 0x1F. + * + * @return none. + * + */ +void PORT_FilterConfig(PORT_ID_t portId, PORT_GPIONO_t gpioNo, + uint8_t filterConfig); + +/** + * @brief Port install call back function + * + * @param[in] cbFun: pointer to callback function. + * + * @return none + * + */ +void PORT_InstallCallBackFunc(port_cb_t cbFun); + +/** + * @brief Get pin interrupt status function + * + * + * @param[in] portId: Select the PORT id,such as PORT_A,PORT_B,PORT_C, + * PORT_D,PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * + * @return Interrupt status of a pin. + * + */ +FlagStatus_t PORT_GetIntStatus(PORT_ID_t portId, PORT_GPIONO_t gpioNo); + +/** + * @brief Get all pins interrupt status of a Port. + * + * + * @param[in] portId: Select the PORT id,such as PORT_A,PORT_B,PORT_C, + * PORT_D,PORT_E. + * + * @return All Pins interrupt status of a Port. + * + */ +uint32_t PORT_GetIntStatusAll(PORT_ID_t portId); + +/** + * @brief Clear the pin interrupt status function. + * + * + * @param[in] portId: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * + * @return none. + * + */ +void PORT_ClearPinInt(PORT_ID_t portId, PORT_GPIONO_t gpioNo); + +/** + * @brief Clear all pins interrupt status function. + * + * + * @param[in] portId: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] clrPins: Select pins no, a bit is a pin, bit0-gpio0,... + * + * @return none. + * + */ +void PORT_ClearPinsInt(PORT_ID_t portId, uint32_t clrPins); + +/** @} end of group PORT_Public_FunctionDeclaration */ + +/** @defgroup GPIO_Public_FunctionDeclaration + * @brief GPIO functions declaration + * @{ + */ + +/** + * @brief GPIO functions + */ + +/** + * @brief Set the pin direction configuration. + * + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * @param[in] dir: Select I/O direction of a pin. + * - 0: corresponding pin is set to input + * - 1: corresponding pin is set to output + * + * @return none. + * + */ +void GPIO_SetPinDir(PORT_ID_t port, PORT_GPIONO_t gpioNo, GPIO_Dir_t dir); + +/** + * @brief Set the direction configuration for all pins. + * + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] dataDir: Select I/O directions. + * - 0: corresponding pin is set to input + * - 1: corresponding pin is set to output + * + * @return none. + * + */ +void GPIO_SetPinsDir(PORT_ID_t port, uint32_t dataDir); + +/** + * @brief Write a pin with a given value. + * + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * @param[in] val: Pin value. + * - 0: corresponding pin is set to LOW + * - 1: corresponding pin is set to HIGH + * + * @return none. + * + */ +void GPIO_WritePinOutput(PORT_ID_t port, PORT_GPIONO_t gpioNo, GPIO_LVL_t val); + +/** + * @brief Write pins with the given value. + * + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] val: Pin value. + * - 0: corresponding pin is set to LOW + * - 1: corresponding pin is set to HIGH + * + * @return none. + * + */ +void GPIO_WritePinsOutput(PORT_ID_t port, uint32_t val); + +/** + * @brief Write a pin to 'Clear' value. + * + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * + * @return none. + * + */ +void GPIO_ClearPinOutput(PORT_ID_t port, PORT_GPIONO_t gpioNo); + +/** + * @brief Write pins to 'Clear' value + * + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] pins: Clean the GPIO pins. + * + * @return none. + * + */ +void GPIO_ClearPinsOutput(PORT_ID_t port, uint32_t pins); + +/** + * @brief Write a pin with 'Set' value. + * + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * + * @return none. + * + */ +void GPIO_SetPinOutput(PORT_ID_t port, PORT_GPIONO_t gpioNo); + +/** + * @brief Write pins with 'Set' value. + * + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] pins: Set the GPIO pins. + * + * @return none. + * + */ +void GPIO_SetPinsOutput(PORT_ID_t port, uint32_t pins); + +/** + * @brief Toggle a pin value. + * + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * + * @return none. + * + */ +void GPIO_TogglePinOutput(PORT_ID_t port, PORT_GPIONO_t gpioNo); + +/** + * @brief Toggle pins value. + * + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] pins: Toggle the GPIO pins. + * + * @return none. + * + */ +void GPIO_TogglePinsOutput(PORT_ID_t port, uint32_t pins); + +/** + * @brief Read a pin value. + * + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * + * @return GPIO_HIGH or GPIO_LOW. + * + */ +GPIO_LVL_t GPIO_ReadPinLevel(PORT_ID_t port, PORT_GPIONO_t gpioNo); + +/** + * @brief Read pins value. + * + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * + * @return Pins value. + * + */ +uint32_t GPIO_ReadPinsLevel(PORT_ID_t port); + +/** @} end of group GPIO_Public_FunctionDeclaration */ + +/** @defgroup RGPIO_Public_FunctionDeclaration + * @brief RGPIO functions declaration + * @{ + */ +/** + * @brief RGPIO functions + */ + +/** + * @brief Set the pin direction configuration. + * + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * @param[in] dir: Select I/O direction of a pin. + * - 0: corresponding pin is set to input + * - 1: corresponding pin is set to output + * + * @return none. + * + */ +void RGPIO_SetPinDir(PORT_ID_t port, PORT_GPIONO_t gpioNo, GPIO_Dir_t dir); + +/** + * @brief Set the direction configuration for all pins. + * + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] dataDir: Select I/O directions. + * - 0: corresponding pin is set to input + * - 1: corresponding pin is set to output + * + * @return none. + * + */ +void RGPIO_SetPinsDir(PORT_ID_t port, uint32_t dataDir); + +/** + * @brief Write a pin with a given value. + * + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] gpioNo: Select the RGPIO pin,such as GPIO_0~GPIO_31. + * @param[in] val: Pin value. + * - 0: corresponding pin is set to LOW + * - 1: corresponding pin is set to HIGH + * + * @return none. + * + */ +void RGPIO_WritePinOutput(PORT_ID_t port, PORT_GPIONO_t gpioNo, GPIO_LVL_t val); + +/** + * @brief Write pins with the given value. + * + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] val: Pin value. + * - 0: corresponding pin is set to LOW + * - 1: corresponding pin is set to HIGH + * + * @return none. + * + */ +void RGPIO_WritePinsOutput(PORT_ID_t port, uint32_t val); + +/** + * @brief Write a pin to 'Clear' value. + * + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * + * @return none. + * + */ +void RGPIO_ClearPinOutput(PORT_ID_t port, PORT_GPIONO_t gpioNo); + +/** + * @brief Write pins to 'Clear' value + * + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] pins: Clean the GPIO pins. + * + * @return none. + * + */ +void RGPIO_ClearPinsOutput(PORT_ID_t port, uint32_t pins); + +/** + * @brief Write a pin with 'Set' value. + * + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * + * @return none. + * + */ +void RGPIO_SetPinOutput(PORT_ID_t port, PORT_GPIONO_t gpioNo); + +/** + * @brief Write pins with 'Set' value. + * + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] pins: Set the GPIO pins. + * + * @return none. + * + */ + +void RGPIO_SetPinsOutput(PORT_ID_t port, uint32_t pins); + +/** + * @brief Toggle a pin value. + * + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * + * @return none. + * + */ +void RGPIO_TogglePinOutput(PORT_ID_t port, PORT_GPIONO_t gpioNo); + +/** + * @brief Toggle pins value. + * + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] pins: Toggle the GPIO pins. + * + * @return none. + * + */ +void RGPIO_TogglePinsOutput(PORT_ID_t port, uint32_t pins); + +/** + * @brief Read a pin value. + * + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * + * @return GPIO_HIGH or GPIO_LOW. + * + */ +GPIO_LVL_t RGPIO_ReadPinLevel(PORT_ID_t port, PORT_GPIONO_t gpioNo); + +/** + * @brief Read pins value. + * + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * + * @return Pins value. + * + */ +uint32_t RGPIO_ReadPinsLevel(PORT_ID_t port); + +/** @} end of group RGPIO_Public_FunctionDeclaration */ + +/** @} end of group GPIO */ + +/** @} end of group Z20K11X_Peripheral_Driver */ +#endif /* Z20K11XM_GPIO_H */ diff --git a/StdDriver/Inc/Z20K11xM_hwdiv.h b/StdDriver/Inc/Z20K11xM_hwdiv.h new file mode 100644 index 0000000..344f2ad --- /dev/null +++ b/StdDriver/Inc/Z20K11xM_hwdiv.h @@ -0,0 +1,357 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_hwdiv.h + * @brief : HWDIV driver module header file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ + +#ifndef Z20K11XM_HWDIV_H +#define Z20K11XM_HWDIV_H + +#include +#include "Z20K11xM_drv.h" + +/** @addtogroup Z20K11X_Peripheral_Driver + * @{ + */ + +/** @addtogroup HWDIV + * @{ + */ + +/** @defgroup HWDIV_Private_Defines + * @{ + */ +#define HWDIV_TIMEOUT_CNT (100U) +/** @}end of group HWDIV_Private_Defines */ +/** @defgroup HWDIV_Private_Variables + * @{ + */ +/** + * @brief HWDIV address array + */ +/*PRQA S 0303 ++*/ +static hwdiv_reg_w_t *const hwdivRegWPtr = (hwdiv_reg_w_t *)HWDIV_BASE_ADDR; +static hwdiv_reg_t *const hwdivRegPtr = (hwdiv_reg_t *)HWDIV_BASE_ADDR; +/*PRQA S 0303 --*/ +/** @}end of group HWDIV_Private_Variables */ +/** @defgroup HWDIV_Public_Types + * @{ + */ + +/** @}end of group HWDIV_Public_Types */ + +/** @defgroup HWDIV_Public_Constants + * @{ + */ + +/** @}end of group HWDIV_Public_Constants */ + +/** @defgroup HWDIV_Private_Func + * @{ + */ +/** + * @brief Perform the square root calculation + * Note: Ensure input is valid + * @param[in] radicand: the radicand + * @param[out] result_addr: the result of square root calculation + * @param[out] remainder_addr: the remainder of the square root calculation + * + * @return + * - SUCC: Operation is successful + * - ERR: Operation fails + */ + +static inline ResultStatus_t HWDIV_SqrtFast(uint32_t radicand, + uint32_t *result_addr,uint32_t *remainder_addr) +{ + volatile uint32_t i = 0U; + ResultStatus_t ret = ERR; + hwdivRegWPtr->HWDIV_RCND = (uint32_t)(radicand); + while (i < HWDIV_TIMEOUT_CNT) + { + if (hwdivRegPtr->HWDIV_CSR.BUSY != 1U) + { + ret = SUCC; + break; + } + i++; + } + *(result_addr) = (uint32_t)hwdivRegWPtr->HWDIV_RES; + *(remainder_addr) = (uint32_t)hwdivRegWPtr->HWDIV_REM; + return ret; +} +/** + * @brief Perform the fast unsigned division + * Note: Ensure input is valid + * @param[in] dividend: dividend operand + * @param[in] divisor: divisor operand + * @param[out] result_addr: the result of division + * @param[out] remainder_addr: the remainder of the division + * + * @return + * - SUCC: Operation is successful + * - ERR: Operation fails + */ +static inline ResultStatus_t HWDIV_UnsignedDivFast(uint32_t dividend, + uint32_t divisor,uint32_t *result_addr,uint32_t *remainder_addr) +{ + volatile uint32_t i = 0U; + ResultStatus_t ret = ERR; + hwdivRegPtr->HWDIV_CSR.USGN = 1U; + hwdivRegWPtr->HWDIV_DEND = (uint32_t)(dividend); + hwdivRegWPtr->HWDIV_DSOR = (uint32_t)(divisor); + hwdivRegPtr->HWDIV_STRT.STRT = + (hwdivRegPtr->HWDIV_CSR.DFS == 1U) ? 1U : 0U; + while (i < HWDIV_TIMEOUT_CNT) + { + if (hwdivRegPtr->HWDIV_CSR.BUSY != 1U) + { + ret = SUCC; + break; + } + i++; + } + *(result_addr) = (uint32_t)hwdivRegWPtr->HWDIV_RES; + *(remainder_addr) = (uint32_t)hwdivRegWPtr->HWDIV_REM; + return ret; +} +/** + * @brief Perform the fast signed division + * Note: Ensure input is valid + * @param[in] dividend: dividend operand + * @param[in] divisor: divisor operand + * @param[out] result_addr: the result of division + * @param[out] remainder_addr: the remainder of the division + * + * @return + * - SUCC: Operation is successful + * - ERR: Operation fails + */ +static inline ResultStatus_t HWDIV_SignedDivFast(int32_t dividend, + int32_t divisor, int32_t *result_addr,int32_t *remainder_addr) +{ + volatile uint32_t i = 0U; + ResultStatus_t ret = ERR; + while (i < HWDIV_TIMEOUT_CNT) + { + if (hwdivRegPtr->HWDIV_CSR.BUSY != 1U) + { + ret = SUCC; + break; + } + i++; + } + i = 0U; + ret = ERR; + hwdivRegPtr->HWDIV_CSR.USGN = 0U; + hwdivRegWPtr->HWDIV_DEND = (uint32_t)(dividend); + hwdivRegWPtr->HWDIV_DSOR = (uint32_t)(divisor); + hwdivRegPtr->HWDIV_STRT.STRT = + (hwdivRegPtr->HWDIV_CSR.DFS == 1U) ? 1U : 0U; + while (i < HWDIV_TIMEOUT_CNT) + { + if (hwdivRegPtr->HWDIV_CSR.BUSY != 1U) + { + ret = SUCC; + break; + } + i++; + } + *(result_addr) = (int32_t)hwdivRegWPtr->HWDIV_RES; + *(remainder_addr) = (int32_t)hwdivRegWPtr->HWDIV_REM; + return ret; +} + +/** @}end of group HWDIV_Private_Func */ + +/** @defgroup HWDIV_Public_FunctionDeclaration + * @brief HWDIV functions declaration + * @{ + */ + +/** + * @brief Initializes the HWDIV + * @param[in] none + * + * @return + * - SUCC: Operation is successful + * - BUSY: Operation fails, the module is busy calculating + */ +ResultStatus_t HWDIV_Init(void); + +/** + * @brief Enable/disable divided by zero + * @param[in] newState: divided by zero enable/disable + * -DISABLE: If divisor is 0,the quotient result and remainder are + * forced to 0x0000_0000,else reads of the RES register + * return the register contents. + * -ENABLE: If divisor is 0,an attempted read of RES register will + * generate hardfault interrupt,else the register contents + * are returned + * + */ +void HWDIV_DivZeroCmd(ControlState_t newState); + +/** + * @brief Perform the unsigned division with non-blocking call + * @param[in] dividend: dividend operand + * @param[in] divisor: divisor operand + * + * @return + * - SUCC: Operation is successful + * - BUSY: Operation fails, the module is busy calculating + */ +ResultStatus_t HWDIV_UnsignedDiv(uint32_t dividend, uint32_t divisor); + +/** + * @brief Get the result of unsigned division + * @param[out] result: the result of division + * @param[out] rem: the remainder of the division + * + * @return + * - SUCC: Operation is successful + * - BUSY: Operation fails, the module is busy calculating + * - ERR: Operation fails, the last operation is not a division or + * divided by 0 + */ +ResultStatus_t HWDIV_GetResultUnsignedDiv(uint32_t *result, + uint32_t *rem); + +/** + * @brief Perform the unsigned division with blocking call + * @param[in] dividend: dividend operand + * @param[in] divisor: divisor operand + * @param[out] result: the result of division + * @param[out] rem: the remainder of the division + * + * @return + * - SUCC: Operation is successful + * - BUSY: Operation fails, the module is busy calculating + * - ERR: Operation fails, the operation is not a division or + * divided by 0 + */ +ResultStatus_t HWDIV_UnsignedDivBlocking(uint32_t dividend, uint32_t divisor, + uint32_t *result, uint32_t *rem); + +/** + * @brief Perform the signed division with non-blocking call + * @param[in] dividend: dividend operand + * @param[in] divisor: divisor operand + * + * @return + * - SUCC: Operation is successful + * - BUSY: Operation fails, the module is busy calculating + */ +ResultStatus_t HWDIV_SignedDiv(int32_t dividend, int32_t divisor); + +/** + * @brief Get the result of signed division + * @param[out] result: the result of division + * @param[out] rem: the remainder of the division + * + * @return + * - SUCC: Operation is successful + * - BUSY: Operation fails, the module is busy calculating + * - ERR: Operation fails, the last operation is not a division or + * divided by 0 + */ +ResultStatus_t HWDIV_GetResultSignedDiv(int32_t *result, int32_t *rem); + +/** + * @brief Perform the signed division with blocking call + * @param[in] dividend: dividend operand + * @param[in] divisor: divisor operand + * @param[out] result: the result of division + * @param[out] rem: the remainder of the division + * + * @return + * - SUCC: Operation is successful + * - BUSY: Operation fails, the module is busy calculating + * - ERR: Operation fails, the operation is not a division or + * divided by 0 + */ +ResultStatus_t HWDIV_SignedDivBlocking(int32_t dividend, int32_t divisor, + int32_t *result, int32_t *rem); + +/** + * @brief Perform the square root calculation with non-blocking call + * @param[in] radicand: the radicand + * + * @return + * - SUCC: Operation is successful + * - BUSY: Operation fails, the module is busy calculating + */ +ResultStatus_t HWDIV_SquareRoot(uint32_t radicand); + +/** + * @brief Get the result of the square root calculation + * @param[out] result: the result of square root calculation + * @param[out] rem: the remainder of the square root calculation + * + * @return + * - SUCC: Operation is successful + * - BUSY: Operation fails, the module is busy calculating + * - ERR: Operation fails, the last operation is not a square root + * calculation + */ +ResultStatus_t HWDIV_GetResultSquareRoot(uint32_t *result, uint32_t *rem); + +/** + * @brief Perform the square root calculation with blocking call + * @param[in] radicand: the radicand + * @param[out] result: the result of square root calculation + * @param[out] rem: the remainder of the square root calculation + * + * @return + * - SUCC: Operation is successful + * - BUSY: Operation fails, the module is busy calculating + * - ERR: Operation fails, the operation is not a square root + * calculation + */ +ResultStatus_t HWDIV_SquareRootBlocking(uint32_t radicand, uint32_t *result, + uint32_t *rem); +/** + * @brief Disable/Enable the Divider Fast Start Mode + * @param[in] disableDivFastStart: + * - ture: Disable the Fast Start Mode + * - false: Enable the Fast Start Mode + * @return + * - SUCC: Operation is successful + * - BUSY: Operation fails, the module is busy calculating + */ +ResultStatus_t HWDIV_DisableDivFastStart(ControlState_t disableDivFastStart); + +/** + * @brief Get the HWDIV IP Version + * @param[out] version: the version of the IP + * + * + * @return + * - SUCC: Operation is successful + * + */ +ResultStatus_t HWDIV_GetIPVersion(uint32_t *version); +/** + * @brief Get the HWDIV IP Params + * @param[out] param: the Params of the IP + * + * + * @return + * - SUCC: Operation is successful + * + */ +ResultStatus_t HWDIV_GetIPParam(uint32_t *param); + +/** @}end of group HWDIV_Public_FunctionDeclaration */ + +/** @}end of group HWDIV */ + +/** @}end of group Z20K11X_Peripheral_Driver */ + +#endif /* Z20K11XM_HWDIV_H */ diff --git a/StdDriver/Inc/Z20K11xM_i2c.h b/StdDriver/Inc/Z20K11xM_i2c.h new file mode 100644 index 0000000..4bb6bdb --- /dev/null +++ b/StdDriver/Inc/Z20K11xM_i2c.h @@ -0,0 +1,971 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_i2c.h + * @brief : I2C module driver header file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ + +#ifndef Z20K11XM_I2C_H +#define Z20K11XM_I2C_H + +#include "Z20K11xM_drv.h" + +/** @addtogroup Z20K11X_Peripheral_Driver + * @{ + */ + +/** @addtogroup I2C + * @{ + */ + +/** @defgroup I2C_Public_Types + * @{ + */ + +/** + * @brief I2C master and slave type definition + */ +typedef enum +{ + I2C_MASTER = 0U, /*!< I2C master mode define.*/ + I2C_SLAVE /*!< I2C slave mode define.*/ +} I2C_Mode_t; + +/** + * @brief I2C speed type definition + */ +typedef enum +{ + I2C_SPEED_STANDARD = 1U, /*!< I2C standard speed define.(0 to 100 Kb/s)*/ + I2C_SPEED_FAST = 2U, /*!< I2C fast speed define.(up to 400 Kb/s)*/ + I2C_SPEED_HIGH = 3U, /*!< I2C high speed define.(up to 1.6 Mb/s)*/ + I2C_SPEED_FAST_PLUS = 6U /*!< I2C fast mode plus define.(up to 1000 Kb/s)*/ +} I2C_Speed_t; + +/** + * @brief I2C address type definition + */ +typedef enum +{ + I2C_ADDR_BITS_7 = 0U, /*!< I2C 7 bits address mode define.*/ + I2C_ADDR_BITS_10 /*!< I2C 10 bits address mode define.*/ +} I2C_Addr_t; + +/** + * @brief I2C restart and stop type definition + */ +typedef enum +{ + I2C_RESTART_AND_STOP_DISABLE = 0U, /*!< No RESTART and STOP signals are generated. */ + I2C_STOP_EN, /*!< A STOP is issued after the byte is sent or received. */ + I2C_RESTART_EN /*!< A RESTART is issued before the byte is sent or + received.*/ +} I2C_RestartStop_t; + +/** + * @brief I2C stop_detect if addressed type definition + */ +typedef enum +{ + I2C_SLV_STOP_DET_WHE_ADDRESSED = 0U, /*!< In slave mode:I2C generates the STOP_DETECT interrupt + flag no matter slave address match or not. */ + I2C_SLV_STOP_DET_ADDRESSED /*!< In slave mode:I2C generates the STOP_DETECT interrupt + flag only slave address matches*/ +} I2C_StopDetAddressed_t; + +/** + * @brief I2C stop_detect if master active type definition + */ +typedef enum +{ + I2C_MST_STOP_DET_WHE_ACTIVE = 0U, /*!< In master mode:I2C generates the STOP_DETECT interrupt + flag no matter master's state. */ + I2C_MST_STOP_DET_ACTIVE /*!< In master mode:I2C generates the STOP_DETECT interrupt + flag only when I2C master is active.*/ +} I2C_StopDetActive_t; + +/** + * @brief I2C generates slave data nack type definition + */ +typedef enum +{ + I2C_GEN_NACK_OR_ACK_NORMAL = 0U, /*!< I2C generates NACK/ACK normally.*/ + I2C_GEN_NACK_AFTER_RCV /*!< I2C generates NACK after data byte is received. + Then this data will be aborted, not pushed into RX FIFO. */ +} I2C_GenSlvDataNack_t; + +/** + * @brief I2C choose different transfer address type definition + */ +typedef enum +{ + I2C_DEST_ADDR = 0U, /*!< I2C transfers DEST_ADDR normally.*/ + I2C_GEN_CALL_ADDR = 2U, /*!< I2C will launch a General Call (transfer data is 0x00), only writes + may be performed.Any read option will result asserting ERROR_ABORT flag. */ + I2C_START_BYTE = 3U, /*!< I2C transfers START BYTE (transfer data is 0x01), + should no slave ack. */ +} I2C_MstCmdSelect_t; + +/** + * @brief I2C generation of the TXFIFO_EMPTY interrupt type definition + */ +typedef enum +{ + I2C_TX_BUFFER = 0U, /*!< When TXFIFO_EMPTY_EN = 0: This bit is set to 1 when the transmit buffer + is at or below the threshold value set in the I2C_TXFIFO_WATER_MARK register.*/ + I2C_TX_DATA_PATH /*!< When TXFIFO_EMPTY_EN = 1: This bit is set to 1 when the transmit buffer + is at or below the threshold value set in the I2C_TXFIFO_WATER_MARK register + and the transmission of the address/data from the internal shift register + for the most recently popped command is completed. */ +} I2C_TxEmptyCtrl_t; + +/** + * @brief I2C interrupt type definition + */ +typedef enum +{ + I2C_INT_GEN_CALL = 0U, /*!< A General Call address is received and it is acknowledged. */ + I2C_INT_TX_OVER, /*!< Transmit FIFO above TX FIFO depth and CPU attempts to issue another + I2C command by writing to the I2C_COMMAND_DATA register. */ + I2C_INT_ERROR_ABORT, /*!< Error abort interrupt. */ + I2C_INT_ACTIVITY, /*!< I2C activity interrupt. There are four ways to clear it: + - Disabling the I2C module + - Writing 1 to the I2C_STATUS0[ACTIVITY] + - Writing 0 to the I2C_INT_ENABLE[I2C_ACTIVITY_DET_IE] + - System reset */ + I2C_INT_STOP_DET, /*!< A STOP signal generated interrupt. */ + I2C_INT_START_DET, /*!< A START or RESTART signal generated interrupt. */ + I2C_INT_RD_REQ, /*!< Slave read request interrupt. */ + I2C_INT_RX_DONE, /*!< The transmission done interrupt, + only valid for I2C as a slave transmitter. */ + I2C_INT_RX_UNDER, /*!< Receive FIFO underflow interrupt. */ + I2C_INT_RX_OVER, /*!< Received FIFO overflow interrupt. */ + I2C_INT_RESTART_DET, /*!< A RESTART signal generated interrupt, operating in slave mode and + the slave is the addressed slave. */ + I2C_SCL_STUCK_AT_LOW, /*!< SCL stuck at low interrupt. */ + I2C_INT_RX_FULL, /*!< Received FIFO full interrupt. */ + I2C_INT_TX_EMPTY, /*!< Transmit FIFO empty interrupt. + - When TXFIFO_EMPTY_EN = 0: + This bit is set to 1 when the transmit buffer is at or below the + threshold value set in the I2C_TXFIFO_WATER_MARK register. + - When TXFIFO_EMPTY_EN = 1: + This bit is set to 1 when the transmit buffer is at or below the + threshold value set in the I2C_TXFIFO_WATER_MARK register and the + transmission of the address/data from the internal shift register for + the most recently popped command is completed. */ + I2C_INT_ALL /*!< All the interrupt. */ +} I2C_INT_t; + +/** + * @brief I2C status type definition + */ +typedef enum +{ + I2C_MST_ACTIVITY = 0U, /*!< When master is not under idle bit, this bit will be set 1. + - 0: means MASTER FSM is idle + - 1: means MASTER FSM is not idle */ + I2C_SLV_ACTIVITY, /*!< When slave is not under idle bit, this bit will be set 1. + - 0: means SLAVE FSM is idle + - 1: means SLAVE FSM is not idle */ + I2C_TXFIFO_EMPTY_MASTER_HOLD, /*!< This bit indicates Tx FIFO is empty, and the the previous + transferred command does not have Stop bit, so master hold the bus. */ + I2C_TXFIFO_EMPTY_SLAVE_HOLD, /*!< This bit indicates when the Tx FIFO is empty, slave will + hold the bus until slave TX FIFO has data to Transmit for the read request. */ + I2C_RXFIFO_FULL_MASTER_HOLD, /*!< This bit indicates RX FIFO is full and receive new data, + so master will hold the bus. */ + I2C_RXFIFO_FULL_SLAVE_HOLD, /*!< This bit indicates RX FIFO is full and receive new data, + so slave will hold the bus. */ + I2C_STATUS_TFNF, /*!< Transmit FIFO not full, means TX FIFO still has one or + more empty locations. */ + I2C_STATUS_TFE, /*!< Transmit FIFO empty,means TX FIFO is completely empty. */ + I2C_STATUS_RFNE, /*!< Receive FIFO not empty. When RX FIFO has one or more + entries already. This bit will be set to 1. */ + I2C_STATUS_RFF, /*!< Receive FIFO full.When RX FIFO is completely full, + this bit will be set 1. */ + I2C_SDA_ERR_RECOVER_STUCK_LOW, /*!< SDA error recover from stucking at low phase.This bit is + set when SDA fail to recover, and still stuck at low phase. */ + I2C_SLAVE_IS_DISABLED_UNDER_ACT, /*!< Slave is disabled under active state.When read as 1, + it means slave is potentially disabled during slave transfer phase. */ + I2C_SLAVE_RX_DATA_DISCARD, /*!< Slave receive data discard.When read as 1, it means I2C + slave is aborted with at least one data byte from I2C transfer + due to MODULE_EN from 1 to 0. */ + I2C_ENABLE, /*!< I2C enable flag. + - 0: means I2C is disable + - 1: means I2C is enabled */ + I2C_STATUS_ALL /*!< All the status. */ +} I2C_Status_t; + +/** + * @brief I2C tx abort Source type definition + */ +typedef enum +{ + ERR_GEN_CALL_NO_ACK = 0U, /*!< I2C in master mode sent a General Call and no slave on the bus + acknowledged the General Call. */ + ERR_GEN_CALL_READ, /*!< I2C in master mode sent a General Call but the user programmed + the byte following the General Call to be a read from the bus */ + ERR_START_BYTE_ACK_DET, /*!< Master has sent a START Byte and the START Byte was acknowledged + (wrong behavior) */ + ERR_SBYTE_NORSTRT, /*!< The start is disabled and the user is trying to + send a START Byte */ + ERR_H_NO_RSTRT, /*!< The restart is disabled and the user is trying to use the master + to transfer data in high speed mode. */ + ERR_H_MCODE_ACK_DET, /*!< Master is in High Speed mode and the High Speed Master code was + acknowledged (wrong behavior). */ + ERR_7BIT_ADDR_NO_ACK, /*!< Master is in 7-bit addressing mode and the address sent was not + acknowledged by any slave */ + ERR_10BIT_ADDR1_NO_ACK, /*!< Master is in 10-bit address mode and the first 10-bit address + byte was not acknowledged by any slave. */ + ERR_10BIT_ADDR2_NO_ACK, /*!< Master is in 10-bit address mode and the second address byte of + the 10-bit address was not acknowledged by any slave. */ + ERR_10BIT_READ_NO_RSTRT, /*!< Will assert 1 when read 10 bit under EN_RESTART = 0. */ + ERR_DATA_NO_ACK, /*!< This is a master-mode only bit. Master has received an + acknowledgement for the address, but when it sent data byte(s) + following the address, it did not receive an acknowledge from the + remote slave(s). */ + ERR_MASTER_ABRT, /*!< This is a master-mode-only bit. Master has detected the transfer + abort. */ + ERR_MASTER_DIS, /*!< User tries to initiate a Master operation with the Master mode + disabled */ + ERR_SLAVE_ARBLOST, /*!< Slave lost the bus while transmitting data to a remote master. + I2C_ERROR_STATUS[14] is set at the same time. */ + ERR_MASTER_LOST, /*!< Master has lost arbitration, or if I2C_ERROR_STATUS[13] is also + set, then the slave transmitter has lost arbitration. */ + ERR_SLAVE_READ_REQ, /*!< When the processor side responds to a slave mode request for data + to be transmitted to a remote master and user writes a 1 in + CMD_MASTER_DIRECTION (bit 8) of I2C_COMMAND_REG register. */ + ERR_SLAVE_FLUSH_TXFIFO, /*!< Slave has received a read command and some data exists in the + TX FIFO so the slave issues a ERROR_ABORT interrupt to flush old data + in TX FIFO. */ + ERR_SDA_LOW_TIMEOUT, /*!< SDA stuck at low and timeout error. */ + ERR_STATUS_ALL +} I2C_ErrorStatus_t; + +/** + * @brief I2C No. type definition + */ +typedef enum +{ + I2C0_ID = 0U, /*!< I2C0 port define */ +#if (2U == I2C_INSTANCE_NUM) + I2C1_ID /*!< I2C1 port define */ +#endif +} I2C_Id_t; + +/** + * @brief I2C Configuration Structure type definition + */ +typedef struct +{ + I2C_Mode_t masterSlaveMode; /*!< Specifies the I2C mode. + - I2C_MASTER: I2C master enable + - I2C_SLAVE: I2C slave enable*/ + I2C_Speed_t speedMode; /*!< Specifies the I2C speed mode. + - I2C_SPEED_STANDARD: standard speed (0 to 100 Kb/s) + - I2C_SPEED_FAST: fast speed (up to 400 Kb/s) + - I2C_SPEED_HIGH: high speed (up to 1.6 Mb/s) + - I2C_SPEED_FAST_PLUS: fast plus speed(up to 1000 Kb/s) */ + I2C_Addr_t addrBitMode; /*!< I2C start its transfer in 7 or 10 bits address mode + - I2C_ADDR_BITS_7: 7 bits address mode + - I2C_ADDR_BITS_10: 10 bits address mode */ + uint32_t ownSlaveAddr; /*!< Slave address when the I2C is operating as a slave. + This parameter can be a 7-bit or 10-bit address. */ + ControlState_t restart; /*!< Determines whether RESTART conditions may be sent when acting + as a master. + - ENABLE: enable RESTART condition + - DISABLE: disable RESTART condition + When the RESTART is disabled, the I2C module master is incapable of + performing the following functions: + - Sending a START BYTE + - Performing any high-speed mode operation + - Performing direction changes in combined format mode + - Performing a read operation with a 10-bit address */ +} I2C_Config_t; + +/** + * @brief I2C FIFO threshold level type definition + */ +typedef struct +{ + uint32_t recvFifoThr; /*!< Receive FIFO threshold level,the valid range is 0 - 3. */ + uint32_t transmitFifoThr; /*!< Transmit FIFO threshold level,the valid range is 0 - 3. */ +} I2C_FifoConfig_t; + +/** + * @brief I2C SDA hold time type definition + */ +typedef struct +{ + uint32_t sdaReceiveHoldTime; /*!< Sets the required SDA hold time in units of I2C function + clock period, when I2C module acts as a reciever. SDA data hold time after SCL negedge. */ + uint32_t sdaTransmitHoldTime; /*!< Sets the required SDA hold time in units of I2C function + clock period, when I2C module acts as a transmitter. SDA data hold time after SCL negedge. */ +} I2C_SdaHoldTime_t; + +/** + * @brief I2C DMA request FIFO level type definition + */ +typedef struct +{ + uint32_t I2C_DMA_TransmitReqLevel; /*!< DMA transmit data level, the valid range is 0 - 3 */ + uint32_t I2C_DMA_RecvReqLevel; /*!< DMA Receive data level, the valid range is 0 - 3 */ +} I2C_DmaConfig_t; + +/** @} end of group I2C_Public_Types definitions */ + +/** @defgroup I2C_Public_Constants + * @{ + */ + +/** @} end of group I2C_Public_Constants definitions*/ + + +/** @defgroup I2C_Public_Macro + * @{ + */ + +/** @} end of group I2C_Public_Macro */ + +/** @defgroup I2C_Public_FunctionDeclaration + * @brief I2C function statement + * @{ + */ +/** + * @brief Install call back function + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C0_ID. + * @param[in] intId: Specified interrupt type. + * - I2C_INT_GEN_CALL + * - I2C_INT_TX_OVER + * - I2C_INT_ERROR_ABORT + * - I2C_INT_ACTIVITY + * - I2C_INT_STOP_DET + * - I2C_INT_START_DET + * - I2C_INT_RD_REQ + * - I2C_INT_RX_DONE + * - I2C_INT_RX_UNDER + * - I2C_INT_RX_OVER + * - I2C_INT_RESTART_DET + * - I2C_SCL_STUCK_AT_LOW + * - I2C_INT_RX_FULL + * - I2C_INT_TX_EMPTY + * - I2C_INT_ALL + * + * @param[in] cbFun: Pointer to callback function. + * + * @return none + * + */ +void I2C_InstallCallBackFunc(I2C_Id_t i2cId, I2C_INT_t intId, + isr_cb_t * cbFun); + +/** + * @brief Initializes the I2C + * Under the premise that the crystal oscillator is OSC40M, speed mode selects + * standard speed and the default data transfer rate is 100 Kb/s. Speed mode + * selects fast speed and the default data transfer rate is 400 Kb/s.Speed mode + * selects fast plus speed and the default data transfer rate is 1 Mb/s. + * + * Under the premise that the crystal oscillator is FIRC64M,speed mode selects + * high speed and the default data transfer rate is 1.6 Mb/s. + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] i2cConfigStruct: Pointer to a I2C configuration structure. + * + * @return none + * + */ +void I2C_Init(I2C_Id_t i2cId, const I2C_Config_t* i2cConfigStruct); + +/** + * @brief Configure SCL High Count + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] speedMode: Speed mode types. + * - I2C_SPEED_STANDARD:I2C standard speed define.(0 to 100 Kb/s) + * - I2C_SPEED_FAST:I2C fast speed define.(up to 400 Kb/s) + * - I2C_SPEED_HIGH:I2C high speed define.(up to 1.6 Mb/s) + * - I2C_SPEED_FAST_PLUS:I2C fast mode plus define.(up to 1000 Kb/s) + * + * @return none + * + */ +void I2C_SclHighCount(I2C_Id_t i2cId, I2C_Speed_t speedMode); + +/** + * @brief Configure SCL Low Count + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] speedMode: Speed mode types. + * - I2C_SPEED_STANDARD:I2C standard speed define.(0 to 100 Kb/s) + * - I2C_SPEED_FAST:I2C fast speed define.(up to 400 Kb/s) + * - I2C_SPEED_HIGH:I2C high speed define.(up to 1.6 Mb/s) + * - I2C_SPEED_FAST_PLUS:I2C fast mode plus define.(up to 1000 Kb/s) + * + * @return none + * + */ +void I2C_SclLowCount(I2C_Id_t i2cId, I2C_Speed_t speedMode); + +/** + * @brief Configure Spike Suppression Limit + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] speedMode: Speed mode types. + * - I2C_SPEED_STANDARD:I2C standard speed define.(0 to 100 Kb/s) + * - I2C_SPEED_FAST:I2C fast speed define.(up to 400 Kb/s) + * - I2C_SPEED_HIGH:I2C high speed define.(up to 1.6 Mb/s) + * - I2C_SPEED_FAST_PLUS:I2C fast mode plus define.(up to 1000 Kb/s) + * + * @return none + * + */ +void I2C_LimitSpikeSuppression(I2C_Id_t i2cId, I2C_Speed_t speedMode); + +/** + * @brief Set the target address . + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] targetAddr: The target address for any master transaction. + * + * @return none + * + */ +void I2C_SetTargetAddr(I2C_Id_t i2cId, uint32_t targetAddr); + +/** + * @brief Set the value of the I2C high speed mode master code + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] value: High speed mode master code. + * + * @return none + * + */ +void I2C_SetMasterModeCodeAddr(I2C_Id_t i2cId, uint32_t value); + +/** + * @brief Issues the STOP_DETECT interrupt if addressed in slave mode + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] stopDetAddressedType: Specified types. + * - I2C_SLV_STOP_DET_WHE_ADDRESSED:I2C issues the STOP_DETECT + * irrespective of whether it is addressed or not. + * - I2C_SLV_STOP_DEF_ADDRESSED:I2C issues the STOP_DETECT interrupt + * only when it is addressed. + * + * @return none + * + */ +void I2C_StopDetIfAddressed(I2C_Id_t i2cId, + I2C_StopDetAddressed_t stopDetAddressedType); + +/** + * @brief Issues the STOP_DETECT interrupt if master active + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] stopDetMstActiveType: Specified types. + * - I2C_MST_STOP_DET_WHE_ACTIVE:I2C issues the STOP_DETECT + * irrespective of whether the master is active. + * - I2C_MST_STOP_DEF_ACTIVE:I2C issues the STOP_DETECT interrupt + * only when the master is active. + * + * @return none + * + */ +void I2C_StopDetIfMstActive(I2C_Id_t i2cId, + I2C_StopDetActive_t stopDetMstActiveType); + +/** + * @brief Control the generation of the TXFIFO_EMPTY interrupt, + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] txEmptyType: Specified tx empty type. + * - I2C_TX_BUFFER:transmit buffer is at or below the threshold + * value set in the TXFIFO_WATER_MARK register. + * - I2C_TX_DATA_PATH:transmit buffer is at or below the threshold + * value set in the TXFIFO_WATER_MARK register and the transmission + * of the address/data from the internal shift register for the + * most recently popped command is completed. + * + * @return none + * + */ +void I2C_TxEmptyCtrl(I2C_Id_t i2cId, I2C_TxEmptyCtrl_t txEmptyType); + +/** + * @brief Control whether I2C module should hold the bus when the Rx FIFO + * is physically full to its RXFIFO_DEPTH + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] newState: Enable/Disable function state. + * - ENABLE: Hold the bus when the Rx FIFO is physically full to its + * RXFIFO_DEPTH. + * - DISABLE: When Rx FIFO's RXFIFO_DEPTH is physically full, + * the bus is not hold. + * + * @return none + * + */ +void I2C_HoldBusCmd(I2C_Id_t i2cId, ControlState_t newState); + +/** + * @brief Initializes the I2C DMA + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] i2cDmaConfig: Pointer to a I2C DMA configuration structure. + * + * @return none + * + */ +void I2C_DmaConfig(I2C_Id_t i2cId, const I2C_DmaConfig_t* i2cDmaConfig); + +/** + * @brief Enable/disable I2C DMA function. + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] transmitDmaCtrl: Transmit DMA Enable/Disable function state. + * @param[in] rcvDmaCtrl: Receive DMA Enable/Disable function state. + * + * @return none + * + */ +void I2C_DmaCmd(I2C_Id_t i2cId, ControlState_t transmitDmaCtrl, + ControlState_t rcvDmaCtrl); + +/** + * @brief Set I2C SDA Transmit hold time + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] i2cSdaTxHoldTime: Pointer to a I2C SDA Tx hold time structure. + * + * @return none + * + */ +void I2C_SetSdaTxHoldTime(I2C_Id_t i2cId, + const I2C_SdaHoldTime_t* i2cSdaTxHoldTime); + +/** + * @brief Set I2C SDA Receive hold time + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] i2cSdaRxHoldTime: Pointer to a I2C SDA Rx hold time structure. + * + * @return none + * + */ +void I2C_SetSdaRxHoldTime(I2C_Id_t i2cId, + const I2C_SdaHoldTime_t* i2cSdaRxHoldTime); + +/** + * @brief SCL stuck at low timeout + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] time: SCL stuck at low time of duration. + * I2C module generates the SCL_STUCK_AT_LOW interrupt to indicate + * SCL stuck at low if it detects the SCL stuck at low for the + * I2C_SCL_LOW_TIMEOUT in units of I2C function clock period. + * + * @return none + * + */ +void I2C_SetSclHoldLowTimeout(I2C_Id_t i2cId, uint32_t timeOut); + +/** + * @brief SDA stuck at low timeout + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] time: SDA stuck at low time of duration. + * I2C module initiates the recovery of SDA line through enabling + * the SDA_RECOVER_EN bit if it detects the SDA stuck at low for the + * I2C_SDA_LOW_TIMEOUT in units of I2C function clock period. + * + * @return none + * + */ +void I2C_SetSdaHoldLowTimeout(I2C_Id_t i2cId, uint32_t timeOut); + +/** + * @brief Enable I2C . + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * + * @return none + * + */ +void I2C_Enable(I2C_Id_t i2cId); + +/** + * @brief Disable I2C . + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * + * @return none + * + */ +void I2C_Disable(I2C_Id_t i2cId); + +/** + * @brief I2C bus recover feature in master mode + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] newState: Enable/Disable function state. + * - ENABLE: Means bus recover feature is enable. + * - DISABLE: Means bus recover feature is disabled. + * + * @return none + * + */ +void I2C_MstBusRecover(I2C_Id_t i2cId, ControlState_t newState); + +/** + * @brief I2C SDA recover feature + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] newState: Enable/Disable function state. + * - ENABLE: Means SDA recover feature is enable. + * - DISABLE: Means SDA recover feature is disabled. + * + * @return none + * + */ +void I2C_SdaRecover(I2C_Id_t i2cId, ControlState_t newState); + +/** + * @brief Block or not block the transmission of data on I2C bus + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] newState: Enable/Disable function state + * - ENABLE: Blocks the transmission of data on I2C bus even if + * Tx FIFO has data to transmit. + * - DISABLE: The transmission of data starts on I2C bus automatically, + * as soon as the first data is available in the Tx FIFO. + * + * @return none + * + */ +void I2C_TxCmdBlock(I2C_Id_t i2cId, ControlState_t newState); + +/** + * @brief Enable/Disable transfer abort . + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] newState: Enable/Disable function state + * - ENABLE: ABORT operation in progress. + * - DISABLE: ABORT not initiated or ABORT done. + * + * @return none + * + */ +void I2C_TxAbortCmd(I2C_Id_t i2cId, ControlState_t newState); + +/** + * @brief Configurate the FIFO threshold level. + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] fifoConfig: Pointer to FIFO type structure. + * + * @return none + * + */ +void I2C_FIFOConfig(I2C_Id_t i2cId, const I2C_FifoConfig_t* fifoConfig); + +/** + * @brief Get transmit FIFO level + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * + * @return The number of valid data entries in the transmit FIFO memory. + * + */ +uint32_t I2C_GetTxFifoLevel(I2C_Id_t i2cId); + +/** + * @brief Get receive FIFO level + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * + * @return The number of valid data entries in the receive FIFO memory. + * + */ +uint32_t I2C_GetRxFifoLevel(I2C_Id_t i2cId); + +/** + * @brief I2C master selects transfer address function. + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] transAddrType:transfer address types + * - I2C_DEST_ADDR + * - I2C_GEN_CALL_ADDR + * - I2C_START_BYTE + * + * @return none + * + */ +void I2C_MstCmdSelect(I2C_Id_t i2cId, I2C_MstCmdSelect_t transAddrType); + +/** + * @brief Enable/disable I2C general call ACK function. + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] newState: Enable/Disable function state + * - ENABLE: I2C responses with a ACK when it receives a general call. + * - Disable: No ACK the general call and doesn't generate general + * call interrupt. + * + * @return none + * + */ +void I2C_GeneralCallAckCmd(I2C_Id_t i2cId, ControlState_t newState); + +/** + * @brief Generate a NACK for the data part of a transfer when i2c is + * acting as a slave receiver + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] genNack: general call ACK/NACK type. + * - I2C_GEN_NACK_AFTER_RCV:I2C generates NACK after data byte received. + * - I2C_GEN_NACK_OR_ACK_NORMAL:I2C generates NACK/ACK normally. + * + * @return none + * + */ +void I2C_SlvDataNackGen(I2C_Id_t i2cId, I2C_GenSlvDataNack_t genNack); + +/** + * @brief Send one byte when i2c as a master. + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] restartStopType: Specified restart,Stop type. + * - I2C_RESTART_AND_STOP_DISABLE + * - I2C_STOP_EN + * - I2C_RESTART_EN + * @param[in] data: The data to be send. + * + * @return none + * + */ +void I2C_MasterSendByte(I2C_Id_t i2cId, I2C_RestartStop_t restartStopType, + uint8_t data); + +/** + * @brief Send one byte when i2c as a slave. + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * + * @param[in] data: The data to be send. + * + * @return none + * + */ +void I2C_SlaveSendByte(I2C_Id_t i2cId, uint8_t data); + +/** + * @brief Master read/write request. + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] restartStopType: Specified restart,Stop type. + * - I2C_RESTART_AND_STOP_DISABLE + * - I2C_STOP_EN + * - I2C_RESTART_EN + * + * @return none + * + */ +void I2C_MasterReadCmd(I2C_Id_t i2cId, I2C_RestartStop_t restartStopType); + +/** + * @brief I2C read one byte . + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * + * @return The received data + * + */ +uint8_t I2C_ReceiveByte(I2C_Id_t i2cId); + +/** + * @brief Set sda setup time when i2c is acting as a slave receiver. + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] length: The length of setup time is calculated using + * [(SDA_SETUP_TIMING - 1) * (i2c function clock period)]. + * + * @return none + * + */ +void I2C_SetSdaSetupTime(I2C_Id_t i2cId, uint8_t length); + +/** + * @brief Enable/Disable specified interrupt type + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] intType: Specified interrupt type. + * - I2C_INT_GEN_CALL + * - I2C_INT_TX_OVER + * - I2C_INT_ERROR_ABORT + * - I2C_INT_ACTIVITY + * - I2C_INT_STOP_DET + * - I2C_INT_START_DET + * - I2C_INT_RD_REQ + * - I2C_INT_RX_DONE + * - I2C_INT_RX_UNDER + * - I2C_INT_RX_OVER + * - I2C_INT_RESTART_DET + * - I2C_SCL_STUCK_AT_LOW + * - I2C_INT_RX_FULL + * - I2C_INT_TX_EMPTY + * - I2C_INT_ALL + * + * @param[in] newState: Interrupt enable/disable type. + * - ENABLE: enable interrupt + * - DISABLE: disable interrupt + * + * @return none + * + */ +void I2C_IntCmd(I2C_Id_t i2cId, I2C_INT_t intType, ControlState_t newState); + +/** + * @brief Check whether interrupt status flag is set or not for given + * interrupt type + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] intType: Specified interrupt type. + * - I2C_INT_GEN_CALL + * - I2C_INT_TX_OVER + * - I2C_INT_ERROR_ABORT + * - I2C_INT_ACTIVITY + * - I2C_INT_STOP_DET + * - I2C_INT_START_DET + * - I2C_INT_RD_REQ + * - I2C_INT_RX_DONE + * - I2C_INT_RX_UNDER + * - I2C_INT_RX_OVER + * - I2C_INT_RESTART_DET + * - I2C_SCL_STUCK_AT_LOW + * - I2C_INT_RX_FULL + * - I2C_INT_TX_EMPTY + * + * @return The status flag of interrupt status register. + * - SET + * - RESET + * + */ +FlagStatus_t I2C_GetIntStatus(I2C_Id_t i2cId, I2C_INT_t intType); + +/** + * @brief Check whether error status flag is set or not + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] errorType: Specified abort type. + * - ERR_GEN_CALL_NO_ACK + * - ERR_GEN_CALL_READ + * - ERR_START_BYTE_ACK_DET + * - ERR_SBYTE_NORSTRT + * - ERR_H_NO_RSTRT + * - ERR_H_MCODE_ACK_DET + * - ERR_7BIT_ADDR_NO_ACK + * - ERR_10BIT_ADDR1_NO_ACK + * - ERR_10BIT_ADDR2_NO_ACK + * - ERR_10BIT_READ_NO_RSTRT + * - ERR_DATA_NO_ACK + * - ERR_MASTER_ABRT + * - ERR_MASTER_DIS + * - ERR_SLAVE_ARBLOST + * - ERR_MASTER_LOST + * - ERR_SLAVE_READ_REQ + * - ERR_SLAVE_FLUSH_TXFIFO + * - ERR_SDA_LOW_TIMEOUT + * + * @return The status flag of error status register. + * - SET + * - RESET + * + */ +FlagStatus_t I2C_GetErrorStatus(I2C_Id_t i2cId, I2C_ErrorStatus_t errorType); + +/** + * @brief Clear specified interrupt type + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] intType: Specified interrupt type. + * - I2C_INT_GEN_CALL + * - I2C_INT_TX_OVER + * - I2C_INT_ERROR_ABORT + * - I2C_INT_ACTIVITY + * - I2C_INT_STOP_DET + * - I2C_INT_START_DET + * - I2C_INT_RD_REQ + * - I2C_INT_RX_DONE + * - I2C_INT_RX_UNDER + * - I2C_INT_RX_OVER + * - I2C_INT_RESTART_DET + * - I2C_SCL_STUCK_AT_LOW + * - I2C_INT_ALL + * + * @return none + * + */ +void I2C_ClearInt(I2C_Id_t i2cId, I2C_INT_t intType); + +/** + * @brief Clear all error status . + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * + * @return none + * + */ +void I2C_ClearErrorStatusAll(I2C_Id_t i2cId); + +/** + * @brief The number of Tx FIFO data Master Transmitter commands that + * are flushed due to ERROR_ABORT or Slave Transmitter interrupt. + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * + * @return none + * + */ +uint32_t I2C_ErrorFlushCount(I2C_Id_t i2cId); + +/** + * @brief Check whether status flag is set or not for given status type + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] statusType: Specified status type. + * - I2C_MST_ACTIVITY + * - I2C_SLV_ACTIVITY + * - I2C_TXFIFO_EMPTY_MASTER_HOLD + * - I2C_TXFIFO_EMPTY_SLAVE_HOLD + * - I2C_RXFIFO_FULL_MASTER_HOLD + * - I2C_RXFIFO_FULL_SLAVE_HOLD + * - I2C_STATUS_TFNF + * - I2C_STATUS_TFE, + * - I2C_STATUS_RFNE, + * - I2C_STATUS_RFF, + * - I2C_SDA_ERR_RECOVER_STUCK_LOW, + * - I2C_SLAVE_IS_DISABLED_UNDER_ACT + * - I2C_SLAVE_RX_DATA_DISCARD + * - I2C_ENABLE + * + * @return The status flag of spi status register. + * - SET + * - RESET + * + */ +FlagStatus_t I2C_GetStatus(I2C_Id_t i2cId, I2C_Status_t statusType); + +/** @} end of group I2C_Public_FunctionDeclaration */ + +/** @} end of group I2C */ + +/** @} end of group Z20K11X_Peripheral_Driver */ + +#endif /* End of Z20K11XM_I2C_H*/ diff --git a/StdDriver/Inc/Z20K11xM_pmu.h b/StdDriver/Inc/Z20K11xM_pmu.h new file mode 100644 index 0000000..3ac9684 --- /dev/null +++ b/StdDriver/Inc/Z20K11xM_pmu.h @@ -0,0 +1,130 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_pmu.h + * @brief : PMU module driver header file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ + +#ifndef Z20K11XM_PMU_H +#define Z20K11XM_PMU_H + +#include "Z20K11xM_drv.h" + +/** @addtogroup Z20K11X_Peripheral_Driver + * @{ + */ + +/** @addtogroup PMU + * @{ + */ + +/** @defgroup PMU_Public_Types + * @{ + */ + +/** + * @brief PMU voltage of LVD and LVW type definition + */ +typedef enum +{ + PMU_VDD_LVD_LP = 0U, /*!< PMU VDD 5V LVD(detecting) detect enable/disable under low power mode */ + PMU_VDD_LVD_ACT = 1U, /*!< PMU VDD 5V LVD(detecting) detect enable/disable under active mode*/ + PMU_VDD_LVD_RE = 3U, /*!< PMU VDD 5V LVD(detecting) reset enable/disable */ + PMU_VDD_LVW = 4U, /*!< PMU VDD 5V LVW(warning) detect control */ + PMU_REF_BUF_1V = 8U, /*!< PMU Reference 1V output enable with buf control */ + PMU_LDO_LVD_ACT = 9U, /*!< PMU LDO LVD detect enable/disable for active mode */ + PMU_LDO_LVD_LP = 10U, /*!< PMU LDO LVD detect enable/disable for low power mode */ + PMU_LDO_CLAMP = 11U /*!< PMU LDO clamp enable/disable */ +} PMU_Ctrl_t; + + +/** + * @brief PMU int type definition + */ +typedef enum +{ + PMU_VDD_LVW_INT = 0U, /*!< PMU VDD 5V LVW INT */ + PMU_VDD_LVD_INT, /*!< PMU VDD 5V LVD INT */ + PMU_INT_ALL +} PMU_Int_t; + +/** @} end of group PMU_Public_Types */ + +/** @defgroup PMU_Public_FunctionDeclaration + * @brief PMU functions declaration + * @{ + */ + +/** + * @brief Clear Isolation status + * + * @return none + * + */ +void PMU_IsoClr(void); + +/** + * @brief Enable/Disable PMU Relevant Voltage's Function + * + * @param[in] ctrlType: Select the PMU Control type defined in PMU_Ctrl_t. + * @param[in] cmd: Enable or Disable. + * + * @return none + * + */ +void PMU_Ctrl(PMU_Ctrl_t ctrlType, ControlState_t cmd); + +/** + * @brief Pmu Get Status Function + * + * @param[in] intType: Int Type. + * + * @return status. + * + */ +FlagStatus_t PMU_GetIntStatus(PMU_Int_t intType); + +/** + * @brief Mask/Unmask the Relevant Interrupt Function + * + * @param[in] intType: Select the interrupt type. + * @param[in] intMask: UNMASK or MASK. + * + * @return none + * + */ +void PMU_IntMask(PMU_Int_t intType, IntMask_t intMask); + +/** + * @brief Clear the Relevant Interrupt Status + * + * @param[in] intType: Select the interrupt type. + * + * @return none + * + */ +void PMU_IntClr(PMU_Int_t intType); + +/** + * @brief install call back function + * + * @param[in] intId: select the interrupt type + * @param[in] cbFun: pointer to callback function + * + * @return none + * + */ +void PMU_InstallCallBackFunc(PMU_Int_t intType,isr_cb_t * cbFun); + + +/** @} end of group PMU_Public_FunctionDeclaration */ + +/** @} end of group PMU */ + +/** @} end of group Z20K11X_Peripheral_Driver */ +#endif /* Z20K11XM_PMU_H */ diff --git a/StdDriver/Inc/Z20K11xM_regfile.h b/StdDriver/Inc/Z20K11xM_regfile.h new file mode 100644 index 0000000..291fca4 --- /dev/null +++ b/StdDriver/Inc/Z20K11xM_regfile.h @@ -0,0 +1,80 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_regfile.h + * @brief : REGFILE module header file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ + +#ifndef Z20K11XM_REGFILE_H +#define Z20K11XM_REGFILE_H + +#include "Z20K11xM_drv.h" + +/** @addtogroup Z20K11X_Peripheral_Driver + * @{ + */ + +/** @addtogroup REGFILE + * @{ + */ + +/** @defgroup REGFILE_Public_Types + * @{ + */ + +/** @}end of group REGFILE_Public_Types */ + +/** @defgroup REGFILE_Public_Constants + * @{ + */ + +/** @}end of group REGFILE_Public_Constants */ + +/** @defgroup REGFILE_Public_Macro + * @{ + */ + +/** @}end of group REGFILE_Public_Macro */ + +/** @defgroup REGFILE_Public_FunctionDeclaration + * @brief REGFILE functions declaration + * @{ + */ + +/** + * @brief Write into the REGFILE by regID + * @param[in] regID: the regID of the regfile, the scope is [0-31] + * @param[in] data: the data to be written + * + * @return Write into the REGFILE Status: + * - SUCC: Operation is successful + * - ERR: Operation fails, input param is invalid + * + */ +ResultStatus_t REGFILE_WriteByRegID(uint8_t regID, uint32_t const * data); + +/** + * @brief Read from the REGFILE by regID + * @param[in] regID: the regID of the regfile, the scope is [0-31] + * @param[inout] data: the data to be read + * + * + * @return Read from the REGFILE Status: + * - SUCC: Operation is successful + * - ERR: Operation fails, input param is invalid + * + */ +ResultStatus_t REGFILE_ReadByRegID(uint8_t regID, uint32_t *data); + +/** @}end of group REGFILE_Public_FunctionDeclaration */ + +/** @}end of group REGFILE */ + +/** @}end of group Z20K11X_Peripheral_Driver */ + +#endif /* Z20K11XM_REGFILE_H */ diff --git a/StdDriver/Inc/Z20K11xM_rtc.h b/StdDriver/Inc/Z20K11xM_rtc.h new file mode 100644 index 0000000..eb17d66 --- /dev/null +++ b/StdDriver/Inc/Z20K11xM_rtc.h @@ -0,0 +1,420 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_rtc.h + * @brief : RTC module driver header file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ + +#ifndef Z20K11XM_RTC_H__ +#define Z20K11XM_RTC_H__ + +#include "Z20K11xM_drv.h" + +/** @addtogroup Z20K11X_Peripheral_Driver + * @{ + */ + +/** @addtogroup RTC + * @{ + */ + +/** @defgroup RTC_Public_Types + * @{ + */ + +/** + * @brief output clock type definition + */ +typedef enum +{ + RTC_SECONDS = 0U, /*!< rtc internal seconds counter */ + RTC_32K_CLK /*!< RTC osc32k/lpo32k */ +}RTC_ClkOut_t; + +/** + * @brief RTC source type definition + */ +typedef enum +{ + RTC_CLK_DISABLE = 0U, /*!< clock source disable */ + RTC_CLK_OSC32K_INT, /*!< crystal: OSC clock comes + from crystal oscillator */ + RTC_CLK_LPO32K, /*!< lpo32k */ + RTC_CLK_OSC32K_EXT /*!< external source: OSC clock comes + from a external square wave clock source */ +}RTC_Clk_t; + +/** + * @brief RTC status type definition,second interrupt has no flag bit + */ +typedef enum +{ + RTC_STATUS_OVF = 0U, /*!< RTC overflow flag*/ + RTC_STATUS_ALARM_MATCH, /*!< RTC alarm match flag*/ + RTC_STATUS_SECONGD /*!< RTC seconds interrupt flag */ +}RTC_Status_t; + +/** + * @brief RTC interrupt type definition + */ +typedef enum +{ + RTC_INT_OVERFLOW = 0U, /*!< RTC overflow interrupt*/ + RTC_INT_ALARM, /*!< RTC alarm interrupt */ + RTC_INT_SECOND, /*!< RTC second interrupt */ + RTC_INT_ALL +}RTC_Int_t; + +/** + * @brief RTC second interrupt mux type definition + */ +typedef enum +{ + RTC_SECOND_1 = 0U, /*!< RTC select 1Hz to generate second interrupt */ + RTC_SECOND_64, /*!< RTC select 64Hz to generate second interrupt */ + RTC_SECOND_32, /*!< RTC select 32Hz to generate second interrupt */ + RTC_SECOND_16, /*!< RTC select 16Hz to generate second interrupt */ + RTC_SECOND_8, /*!< RTC select 8Hz to generate second interrupt */ + RTC_SECOND_4, /*!< RTC select 4Hz to generate second interrupt */ + RTC_SECOND_2, /*!< RTC select 2Hz to generate second interrupt */ + RTC_SECOND_128 /*!< RTC select 128Hz to generate second interrupt*/ +}RTC_SecondIntMuxSel_t; + +/** + * @brief RTC frequency compensation direction type definition + */ +typedef enum +{ + RTC_COMP_UP = 0U, /*!< compensation direction up, + seconds frequency faster */ + RTC_COMP_DOWN /*!< compensation direction down, + seconds frequency slower */ +}RTC_CompDirection_t; + +/** + * @brief RTC compensation config struct definition + */ +typedef struct +{ + uint8_t delayVal; /*!< compensation delay value can be [1:256] + how frequently RTC adjust its number of 32.768KHz + in each second*/ + uint8_t compVal; /*!< cempensation counter value, + can be effect till DLY be 0 */ + RTC_CompDirection_t dir; /*!< frequency compensation direction */ +}RTC_CompConfig_t; + +/** + * @brief RTC output config struct definition + */ +typedef struct +{ + RTC_SecondIntMuxSel_t freqSel; + RTC_ClkOut_t clkOutput; +}RTC_OutputConfig_t; + +/** @} end of group RTC_Public_Types*/ + + +/** @defgroup RTC_Public_FunctionDeclaration + * @brief RTC functions statement + * @{ + */ + +/** + * @brief RTC enable functioin + * + * @param[in] none + * + * @return none + */ +void RTC_Enable(void); + +/** + * @brief RTC disable functioin + * + * @param[in] none + * + * @return none + */ +void RTC_Disable(void); + + /** + * @brief RTC OSC clock disable functioin + * + * @param[in] none + * + * @return none + * + */ +void RTC_OSCDisable(void); + +/** + * @brief Software reset all rtc registers except sw_rst bit + * + * @param[in] none + * + * @return none + * + */ +void RTC_SWRest(void); + +/** + * @brief config whether write access to RTC in non-supervisor + * + * @param[in] cmd: ENABLE/DISABLE + * + * @return none + * + */ +void RTC_SupModeConfig(ControlState_t cmd); + +/** + * @brief config second interrupt mux function + * + * @param[in] muxSel: select frequency to generate second frequency + * + * @return none + * + */ +void RTC_FreqMuxConfig(RTC_SecondIntMuxSel_t muxSel); + +/** + * @brief Config RTC clcok source + * + * @param[in] config:config clock output + * + * @return none + * + */ +void RTC_OutputConfig(RTC_OutputConfig_t const * config); + +/** + * @brief Enable RTC output clock function after output config + * + * @param[in] none + * + * @return none + * + */ +void RTC_OutputEnable(void); + +/** + * @brief Disable RTC output clock function + * + * @param[in] none + * + * @return none + * + */ +void RTC_OutputDisable(void); + +/** + * @brief Select RTC clock source function, + * suggest select clock source before enable RTC clock + * + * @param[in] clockSource:RTC clock source + * + * @return + * -SUCC:clock config is success + * -ERR:clock config is fail + * + */ +ResultStatus_t RTC_ClkConfig(RTC_Clk_t clockSource); + +/** + * @brief Set match counter register which also can clear alarm interrupt + * + * @param[in] counterValue:set the counter value + * + * @return none + * + *****************************************************************************/ +void RTC_SetMatchCounter(uint32_t counterValue); + +/** + * @brief Get match counter register + * + * @param[in] none + * + * @return match counter + * + *****************************************************************************/ +uint32_t RTC_GetMatchCounter(void); + +/** + * @brief Mask/Unmask the RTC interrupt funtion + * + * @param[in] intType: select interrupt + * @param[in] intMask:Enable/Disable interrupt + * + * @return none + * + *****************************************************************************/ +void RTC_IntMask(RTC_Int_t intType, IntMask_t intMask); + +/** + * @brief RTC Get alarm match status Function + * + * @param[in] none + * + * @return intstatus + * + */ +IntStatus_t RTC_GetAlarmMatchStatus(void); + +/** + * @brief Get second interrupt status Function + * + * @param[in] none + * + * @return intstatus + * + */ +IntStatus_t RTC_GetSecondStatus(void); + +/** + * @brief RTC Get alarm overflow status Function + * + * @param[in] none + * + * @return intstatus + * + */ +IntStatus_t RTC_GetAlarmOVFStatus(void); + +/** + * @brief Clear RTC overflow interrupt function after disable RTC + * + * @param[in] countVal: set alarm counter value + * + * @return none + * + *****************************************************************************/ +void RTC_ClearOVF(uint32_t countVal); + +/** + * @brief Clear RTC seconds interrupt flag function + * + * @param[in] none + * + * @return none + * + *****************************************************************************/ +void RTC_ClearSecondsFlag(void); + +/** + * @brief Read the current alarm counter function + * + * @param[in] none + * + * @return current alarm counter + * + *****************************************************************************/ +uint32_t RTC_GetAlarmCounter(void); + +/** + * @brief Get the current compensation delay value function + * + * @param[in] none + * + * @return current compensation delay value + * + *****************************************************************************/ +uint8_t RTC_GetCurrentCompDelayCVal(void); + +/** + * @brief Get current compensation counter value function + * + * @param[in] none + * + * @return current compensation value + * + *****************************************************************************/ +uint8_t RTC_GetCurrentCompVal(void); + +/** + * @brief Set compensation delay value function + * + * @param[in] delayVal: compensation delay value + * + * @return none + * + *****************************************************************************/ +void RTC_SetCompDelayVal(uint8_t delayVal); + +/** + * @brief Set frequency compensation direction function + * + * @param[in] freqComp : select frequency compensation direction + * + * @return none + * + *****************************************************************************/ +void RTC_SetCompDirection(RTC_CompDirection_t freqComp); + +/** + * @brief Set compensation counter value function + * + * @param[in] Val: compensation counter value + * + * @return none + * + *****************************************************************************/ +void RTC_SetCompVal(uint8_t Val); + +/** + * @brief Get the current one second counter function + * + * @param[in] none + * + * @return current one second counter + * + *****************************************************************************/ +uint16_t RTC_GetSecondCounter(void); + +/** + * @brief Config the compensation function + * + * @param[in] config: compensation config + * + * @return none + * + *****************************************************************************/ +void RTC_CompConfig(RTC_CompConfig_t const *config); + +/** + * @brief Disable the compensation function + * + * @param[in] none + * + * @return none + * + *****************************************************************************/ +void RTC_CompDisable(void); + +/** + * @brief install call back function + * + * @param[in] intId: select the interrupt + * @param[in] cbFun: pointer to callback function + * + * @return none + * + */ +void RTC_InstallCallBackFunc(RTC_Int_t intId,isr_cb_t * cbFun); + + + +/** @} end of group RTC_Public_FunctionDeclaration */ + +/** @} end of group RTC */ + +/** @} end of group Z20K11X_Peripheral_Driver */ + +#endif /* __Z20K11XM_RTC_H__ */ diff --git a/StdDriver/Inc/Z20K11xM_spi.h b/StdDriver/Inc/Z20K11xM_spi.h new file mode 100644 index 0000000..9fd6d8c --- /dev/null +++ b/StdDriver/Inc/Z20K11xM_spi.h @@ -0,0 +1,400 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_spi.h + * @brief : SPI module driver header file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ + +#ifndef Z20K11XM_SPI_H +#define Z20K11XM_SPI_H + +#include "Z20K11xM_drv.h" + +/** @addtogroup Z20K11X_Peripheral_Driver + * @{ + */ + +/** @addtogroup SPI + * @{ + */ + +/** @defgroup SPI_Public_Types + * @{ + */ +/** + * @brief Serial spi mode define + */ +typedef enum +{ + SPI_MODE_SLAVE = 0U, /*!< Slave mode */ + SPI_MODE_MASTER /*!< Master mode */ +} SPI_Mode_t; + +/** + * @brief Serial clock phase type define + */ +typedef enum +{ + SPI_CLK_PHASE_FIRST = 0U, /*!< Serial clock toggles at the first edge */ + SPI_CLK_PHASE_SECOND /*!< Serial clock toggles at the second edge */ +} SPI_ClkPhase_t; + +/** + * @brief Serial clock polarity type define + */ +typedef enum +{ + SPI_CLK_INACTIVE_LOW = 0U, /*!< Inactive state of serial clock is low */ + SPI_CLK_INACTIVE_HIGH /*!< Inactive state of serial clock is high */ +} SPI_ClkPolar_t; + +/** + * @brief Transfer mode type define + */ +typedef enum +{ + SPI_TMOD_TR = 0U, /*!< Transmit & receive */ + SPI_TMOD_TO, /*!< Transmit only */ + SPI_TMOD_RO /*!< Receive only */ +} SPI_TransMode_t; + +/** + * @brief SPI status bit type definition + */ +typedef enum +{ + SPI_STATUS_BUSY = 0U, /*!< SPI busy flag */ + SPI_STATUS_TFNF, /*!< Transmit FIFO not full */ + SPI_STATUS_TFE, /*!< Transmit FIFO empty */ + SPI_STATUS_RFNE, /*!< Receive FIFO not empty */ + SPI_STATUS_RFF, /*!< Receive FIFO full */ + SPI_STATUS_TXE, /*!< Transmission Error */ + SPI_STATUS_ALL /*!< All the Status */ +} SPI_Status_t; + +/** + * @brief SPI interrupt definition + */ +typedef enum +{ + SPI_INT_TXE = 0U, /*!< Transmit FIFO empty interrupt */ + SPI_INT_TXO, /*!< Transmit FIFO overflow interrupt*/ + SPI_INT_RXU, /*!< Receive FIFO underflow interrupt */ + SPI_INT_RXO, /*!< Received FIFO overflow interrupt */ + SPI_INT_RXF, /*!< Received FIFO full interrupt */ + SPI_INT_ALL /*!< All the interrupt */ +} SPI_Int_t; + +/** + * @brief SPI raw interrupt definition + */ +typedef enum +{ + SPI_RAW_INT_TXE = 0U, /*!< Transmit FIFO empty interrupt */ + SPI_RAW_INT_TXO, /*!< Transmit FIFO overflow interrupt*/ + SPI_RAW_INT_RXU, /*!< Receive FIFO underflow interrupt */ + SPI_RAW_INT_RXO, /*!< Received FIFO overflow interrupt */ + SPI_RAW_INT_RXF, /*!< Received FIFO full interrupt */ + SPI_RAW_INT_ALL /*!< All the interrupt */ +} SPI_RawInt_t; + +/** + * @brief SPI slave select type definition + */ +typedef enum +{ + SPI_SS_DISABLE = 0U, /*!< Disable slave select */ + SPI_SS_PCS0, /*!< Select PCS0 */ + SPI_SS_PCS1, /*!< Select PCS1 */ + SPI_SS_ALL /*!< Select all */ +} SPI_SelectSlave_t; + +/** + * @brief SPI all ID type definition + */ +typedef enum +{ + SPI0_ID = 0U, /*!< SPI0 ID define */ + SPI1_ID, /*!< SPI1 ID define */ +#if (SPI_INSTANCE_NUM == 3) + SPI2_ID /*!< SPI2 ID define */ +#endif +} SPI_ID_t; + +/** + * @brief SPI Master Configuration Structure type definition + */ +typedef struct +{ + SPI_Mode_t mode; /*!< SPI mode + - SPI_MODE_SLAVE:slave mode + - SPI_MODE_MASTER:master mode */ + uint32_t dataSize; /*!< Configures data frame size + - Size of 4 to 32 bits */ + SPI_ClkPhase_t clkPhase; /*!< Serial clock phase + - SPI_CLK_PHASE_FIRST: first edge + - SPI_CLK_PHASE_SECOND: second edge */ + SPI_ClkPolar_t clkPolarity; /*!< Serial clock polarity + - SPI_CLK_INACTIVE_LOW: low inactive + - SPI_CLK_INACTIVE_HIGH: high inactive */ + SPI_TransMode_t transMode; /*!< Transfer mode + - SPI_TMOD_TR: transmit & receive + - SPI_TMOD_TO: transmit only + - SPI_TMOD_RO: receive only */ + uint16_t clkDivider; /*!< Clock Divider.The frequency of the sclk_out is + derived from the following equation: Fsclk_out = + Fssi_clk/SCKDV */ + uint32_t transFifoThr; /*!< Transmit FIFO threshold level, the valid range + is 0 - 3 */ + uint32_t recvFifoThr; /*!< Receive FIFO threshold level, the valid range is + 0 - 3 */ +} SPI_Config_t; + +/** + * @brief SPI DMA request FIFO level Configuration Structure type definition + */ +typedef struct +{ + uint32_t + dmaTransReqLevel; /*!< Transmit data level,the valid range is 0 - 3 */ + uint32_t + dmaRecvReqLevel; /*!< Receive data level,the valid range is 0 - 3 */ +} SPI_DmaLvl_t; +/** @} end of group SPI_Public_Types */ + +/** @defgroup SPI_Public_FunctionDeclaration + * @brief SPI functions declaration + * @{ + */ + +/** + * @brief Enable the SPI. + * + * @param[in] spiNo: Select the SPI port,should be SPI0_ID,SPI1_ID, SPI2_ID. + * + * @return none. + * + */ +void SPI_Enable(SPI_ID_t spiNo); + +/** + * @brief Disable the SPI. + * + * @param[in] spiNo: Select the SPI id, should be SPI0_ID,SPI1_ID, SPI2_ID. + * + * @return none. + * + */ +void SPI_Disable(SPI_ID_t spiNo); + +/** + * @brief Enable or disable the SPI DMA function. + * + * @param[in] spiNo: Select the SPI id, should be SPI1_ID,SPI1_ID, SPI2_ID. + * @param[in] transmitDmaCtrl: Transmit DMA Enable/Disable function state + * @param[in] rcvDmaCtrl: Receive DMA Enable/Disable function state + * + * @return none. + * + */ +void SPI_DmaCmd(SPI_ID_t spiNo, ControlState_t transmitDmaCtrl, + ControlState_t rcvDmaCtrl); + +/** + * @brief Clear all interrupt status flags. + * + * @param[in] spiNo: Select the SPI id, should be SPI0_ID,SPI1_ID, SPI2_ID. + * @param[in] intType: Specified interrupt type. + * - SPI_INT_TXO + * - SPI_INT_RXU + * - SPI_INT_RXO + * - SPI_INT_ALL + * + * @return none. + * + */ +uint32_t SPI_ClearInt(SPI_ID_t spiNo, SPI_Int_t intType); + +/** + * @brief Initializes the SPI . + * + * @param[in] spiNo: Select the SPI id, should be SPI0_ID, SPI1_ID, SPI2_ID. + * @param[in] spiCfgStruct: Pointer to a SPI configuration structure. + * + * @return none. + * + */ +void SPI_Init(SPI_ID_t spiNo, const SPI_Config_t *spiCfgStruct); +/** + * @brief Initializes the SPI DMA. + * + * @param[in] spiNo: Select the SPI id, should be SPI0_ID, SPI1_ID, SPI2_ID. + * @param[in] dmaCfgStruct: Pointer to a SPI Master DMA configuration + * structure. + * + * @return none. + * + */ +void SPI_DmaConfig(SPI_ID_t spiNo, SPI_DmaLvl_t *dmaCfgStruct); + +/** + * @brief Select SPI slave. + * + * @param[in] spiNo: Select the SPI id, should be SPI0_ID, SPI1_ID, SPI2_ID + * + * @return none. + * + */ +void SPI_SelectSlave(SPI_ID_t spiNo, SPI_SelectSlave_t chipSelect); + +/** + * @brief Set Master data frame number. + * + * @param[in] spiNo: Select the SPI id, should be SPI0_ID, SPI1_ID, SPI2_ID. + * @param[in] frameNum: data frame number, should <= 0xFFFF. + * + * @return none. + * + * This function only used in Receive only transfer mode. + */ +void SPI_SetDataFrameNum(SPI_ID_t spiNo, uint32_t frameNum); + +/** + * @brief Send data. + * + * @param[in] spiNo: Select the SPI id, should be SPI0_ID, SPI1_ID, SPI2_ID. + * @param[in] data: The data to be send. + * + * @return none. + * + */ +void SPI_SendData(SPI_ID_t spiNo, uint32_t data); + +/** + * @brief Check whether raw interrupt status flag is set or not for + * given interrupt type. + * + * @param[in] spiNo: Select the SPI id, should be SPI0_ID, SPI1_ID, SPI2_ID. + * @param[in] intType: Specified interrupt type. + * - SPI_RAW_INT_TXE + * - SPI_RAW_INT_TXO + * - SPI_RAW_INT_RXU + * - SPI_RAW_INT_RXO + * - SPI_RAW_INT_RXF + * @return The state flag of interrupt Status register. + * - SET + * - RESET + * + */ +FlagStatus_t SPI_GetRawIntStatus(SPI_ID_t spiNo, SPI_RawInt_t intType); + +/** + * @brief Receive data. + * + * @param[in] spiNo: Select the SPI id, should be SPI0_ID, SPI1_ID, SPI2_ID. + * + * @return The received data. + * + */ +uint32_t SPI_ReceiveData(SPI_ID_t spiNo); + +/** + * @brief Master get transmit FIFO level. + * + * @param[in] spiNo: Select the SPI id, should be SPI0_ID, SPI1_ID, SPI2_ID. + * + * @return The number of valid data entries in the transmit FIFO memory. + * + */ +uint32_t SPI_GetTxFifoLevel(SPI_ID_t spiNo); + +/** + * @brief Get receive FIFO level. + * + * @param[in] spiNo: Select the SPI id, should be SPI0_ID, SPI1_ID, SPI2_ID. + * + * @return The number of valid data entries in the receive FIFO memory. + * + */ +uint32_t SPI_GetRxFifoLevel(SPI_ID_t spiNo); + +/** + * @brief Check whether status flag is set or not for given status type. + * + * @param[in] spiNo: Select the SPI id, should be SPI0_ID, SPI1_ID, SPI2_ID. + * @param[in] spiStatus: Specified status type. + * - SPI_STATUS_BUSY + * - SPI_STATUS_TFNF + * - SPI_STATUS_TFE + * - SPI_STATUS_RFNE + * - SPI_STATUS_RFF + * - SPI_STATUS_TXE + * + * @return The state value of SPI Status register. + * - SET + * - RESET + * + */ +FlagStatus_t SPI_GetStatus(SPI_ID_t spiNo, SPI_Status_t spiStatus); + +/** + * @brief Check whether interrupt status flag is set or not for given + * interrupt type. + * + * @param[in] spiNo: Select the SPI id, should be SPI0_ID, SPI1_ID, SPI2_ID. + * @param[in] intType: Specified interrupt type. + * - SPI_INT_TXE + * - SPI_INT_TXO + * - SPI_INT_RXU + * - SPI_INT_RXO + * - SPI_INT_RXF + * @return The state flag of interrupt Status register. + * - SET + * - RESET + * + */ +FlagStatus_t SPI_GetIntStatus(SPI_ID_t spiNo, SPI_Int_t intType); + +/** + * @brief Mask/Unmask specified interrupt type. + * + * @param[in] spiNo: Select the SPI id, should be SPI0_ID, SPI1_ID, SPI2_ID. + * @param[in] intType: Specified interrupt type. + * - SPI_INT_TXE + * - SPI_INT_TXO + * - SPI_INT_RXU + * - SPI_INT_RXO + * - SPI_INT_RXF + * - SPI_INT_ALL + * @param[in] intMask: Interrupt mask/unmask type. + * - SPI_INT_MASK: 0 + * - SPI_INT_UNMASK: 1 + * + * @return none. + * + */ +void SPI_IntMask(SPI_ID_t spiNo, SPI_Int_t intType, IntMask_t intMask); + +/** + * @brief install call back function. + * + * @param[in] intId: select the interrupt. + * @param[in] cbFun: pointer to callback function. + * + * @return none. + * + */ +void SPI_InstallCallBackFunc(SPI_ID_t spiId, SPI_Int_t intId, isr_cb_t *cbFun); + +/** @} end of group SPI_Public_FunctionDeclaration */ + +/** @} end of group SPI */ + +/** @} end of group Z20K11X_Peripheral_Driver */ + +#endif /* Z20K11XM_SPI_H */ diff --git a/StdDriver/Inc/Z20K11xM_srmc.h b/StdDriver/Inc/Z20K11xM_srmc.h new file mode 100644 index 0000000..1e940ed --- /dev/null +++ b/StdDriver/Inc/Z20K11xM_srmc.h @@ -0,0 +1,351 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_srmc.h + * @brief : SRMC driver module header file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (C) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + * + **************************************************************************************************/ + +#ifndef Z20K11XM_SRMC_H +#define Z20K11XM_SRMC_H + +#include "Z20K11xM_drv.h" + +/** @addtogroup Z20K11X_Peripheral_Driver + * @{ + */ + +/** @addtogroup SRMC + * @{ + */ + +/** @defgroup SRMC_Public_Types + * @{ + */ + +/** + * @brief SRMC reset cause type definition + */ +typedef enum +{ + SRMC_RESET_TYPE_STB_WAKEUP = 0x00000001U, /*!< SRMC RESET by Standby wakeup detected */ + SRMC_RESET_TYPE_LVD = 0x00000002U, /*!< SRMC RESET by Low Voltage detected */ + SRMC_RESET_TYPE_LOC = 0x00000004U, /*!< SRMC RESET by Loss of External Clock */ + SRMC_RESET_TYPE_WDOG = 0x00000020U, /*!< SRMC RESET by Watchdog Timer Timing Out */ + SRMC_RESET_TYPE_PIN = 0x00000040U, /*!< SRMC RESET by an Active_low Level on + the External RESET Pin */ + SRMC_RESET_TYPE_POR = 0x00000080U, /*!< SRMC RESET by Power-on Detection Logic */ + SRMC_RESET_TYPE_LOCKUP = 0x00000200U, /*!< SRMC RESET by ARM Core Iddication of + a LOCKUP event */ + SRMC_RESET_TYPE_SW = 0x00000400U, /*!< SRMC RESET by Software Setting of SYSRESETREQ bit */ + SRMC_RESET_TYPE_MDM_AP = 0x00000800U, /*!< SRMC RESET by Host Debugger System Setting in + the MDM-AP Control Register */ + SRMC_RESET_TYPE_SACKERR = 0x00008000U, /*!< SRMC RESET by Fail to ACK Attampte to Enter Stop Mode */ + SRMC_RESET_TYPE_ALL = 0x00008EE7U +} SRMC_ResetCause_t; + +/** + * @brief SRMC reset Pin Filter definition + */ +typedef enum +{ + SRMC_RESET_PIN_DISABLE_FILTER = 0U, /*!< SRMC RESET Pin filter disabled */ + SRMC_RESET_PIN_BUS_CLOCK_FILTER, /*!< SRMC RESET Pin bus clock filter */ + SRMC_RESET_PIN_LPO_CLOCK_FILTER /*!< SRMC RESET Pin lpo clock filter */ +} SRMC_ResetPinFilter_t; + +/** + * @brief SRMC Interrupt type definition + */ +typedef enum +{ + SRMC_INT_TYPE_LOC = 0U, /*!< SRMC int loc */ + SRMC_INT_TYPE_WDOG, /*!< SRMC int wdog */ + SRMC_INT_TYPE_PIN, /*!< SRMC int pin */ + SRMC_INT_TYPE_LOCKUP, /*!< SRMC int lockup */ + SRMC_INT_TYPE_SW, /*!< SRMC int software */ + SRMC_INT_TYPE_SACKERR, /*!< SRMC int stop ack error */ + SRMC_INT_TYPE_ALL +} SRMC_Int_t; + +/** + * @brief SRMC delay type definition + */ +typedef enum +{ + SRMC_DELAY_8_LPO_CYCLES = 0U, /*!< SRMC delay 8 lpo cycles */ + SRMC_DELAY_32_LPO_CYCLES, /*!< SRMC delay 32 lpo cycles */ + SRMC_DELAY_128_LPO_CYCLES, /*!< SRMC delay 128 lpo cycles */ + SRMC_DELAY_512_LPO_CYCLES /*!< SRMC delay 512 lpo cycles */ +} SRMC_Delay_t; + +/** + * @brief SRMC powermode type definition + */ +typedef enum +{ + SRMC_POWERMODE_RUN = 0U, /*!< SRMC run mode */ + SRMC_POWERMODE_WAIT, /*!< SRMC wait mode */ + SRMC_POWERMODE_STOP, /*!< SRMC stop mode */ + SRMC_POWERMODE_STANDBY /*!< SRMC standby mode */ +} SRMC_PowerMode_t; + +/** + * @brief SRMC stop mode(deep sleep mode) aborted status type definition + */ +typedef enum +{ + SRMC_STOP_SUCCESS = 0U, /*!< SRMC enter stop mode: success */ + SRMC_STOP_ABORT /*!< SRMC enter stop mode: abort */ +} SRMC_StopModeStatus_t; + +/** + * @brief SRMC wakeup source type definition + */ +typedef enum +{ + SRMC_WUPSRC_PTD0 = 0x0U, /*!< SRMC wakeup source: PTD0 pin */ + SRMC_WUPSRC_PTD1 = 0x1U, /*!< SRMC wakeup source: PTD1 pin*/ + SRMC_WUPSRC_PTA4 = 0x2U, /*!< SRMC wakeup source: PTA4 pin*/ + SRMC_WUPSRC_PTC4 = 0x4U, /*!< SRMC wakeup source: PTC4 pin*/ + SRMC_WUPSRC_PTC5 = 0x5U, /*!< SRMC wakeup source: PTC5 pin*/ + SRMC_WUPSRC_PTE0 = 0x6U, /*!< SRMC wakeup source: PTE0 pin*/ + SRMC_WUPSRC_PTE1 = 0x7U, /*!< SRMC wakeup source: PTE1 pin*/ + SRMC_WUPSRC_PTA10 = 0x8U, /*!< SRMC wakeup source: PTA10 pin*/ + SRMC_WUPSRC_PTA11 = 0x9U, /*!< SRMC wakeup source: PTA11 pin*/ + SRMC_WUPSRC_PMU = 0xAU, /*!< SRMC wakeup source: PMU */ + SRMC_WUPSRC_RTC = 0xBU /*!< SRMC wakeup source: RTC */ +} SRMC_WakeupSource_t; + +/** + * @brief SRMC wakeup source polarity type definition + */ +typedef enum +{ + SRMC_WUPPL_LOW = 0x0U, /*!< SRMC wakeup source polarity: active low */ + SRMC_WUPPL_HIGH = 0x1U /*!< SRMC wakeup source polarity: active high */ +}SRMC_WakePolarity_t; + +/** @} end of group SRMC_Public_Types */ + +/** @defgroup SRMC_Public_FunctionDeclaration + * @brief SRMC functions declaration + * @{ + */ +/** + * @brief Configure core lockup reset enable/disable + * + * @param[in] cmd: control cmd: DISABLE; ENABLE. + * + * @return none + * + */ +void SRMC_CoreLockupResetCtrl(ControlState_t cmd); + +/** + * @brief SRMC wakeup source polarity config + * + * @param[in] source: wakeup source select. + * @param[in] polarity: active polarity. + * - SRMC_WUPPL_LOW + * - SRMC_WUPPL_HIGH + * + * @return none + * + */ +void SRMC_WakeupSourceConfig(SRMC_WakeupSource_t source, SRMC_WakePolarity_t polarity); + +/** + * @brief SRMC wakeup source function enable/disable + * + * @param[in] source: wakeup source select. + * @param[in] cmd: enable/disable. + * + * @return none + * + */ +void SRMC_WakeupSourceCtrl(SRMC_WakeupSource_t source, ControlState_t cmd); + +/** + * @brief SRMC get wakeup source status, indicating corresponding wakeup + * source waked up system + * + * @param[in] source: wakeup source select. + * + * @return status + * + */ +FlagStatus_t SRMC_GetWakeupSourceStatus(SRMC_WakeupSource_t source); + +/** + * @brief configure reset pin filter bus clock width, + * actural reset pin bus clock filter width cycle = clkCycles + 1 + * + * @param[in] clkCycles: cycle number. + * + * @return none + * + */ +void SRMC_ResetPinFilterBusClockConfig(uint8_t clkCycles); + +/** + * @brief configure how reset pin filter is enabled in stop mode + * + * @param[in] filterType: only two type used in stop mode, as below + * - SRMC_RESET_PIN_DISABLE_FILTER + * - SRMC_RESET_PIN_LPO_CLOCK_FILTER + * + * @return none + * + */ +void SRMC_ResetPinFilterInStopMode(SRMC_ResetPinFilter_t filterType); + +/** + * @brief configure how reset pin filter is enabled in run and wait mode + * + * @param[in] filterType: three type used in run and wait mode, as below + * - SRMC_RESET_PIN_DISABLE_FILTER + * - SRMC_RESET_PIN_BUS_CLOCK_FILTER + * - SRMC_RESET_PIN_LPO_CLOCK_FILTER + * + * @return none + * + */ +void SRMC_ResetPinFilterInRunAndWaitMode(SRMC_ResetPinFilter_t filterType); + +/** + * @brief Get the status that if the pointed reset type is the system + * reset cause. + * + * @param[in] resetCauseType: reset cause type. + * + * @return status + * + */ +FlagStatus_t SRMC_GetSystemResetStatus(SRMC_ResetCause_t resetCauseType); + +/** + * @brief Clear the status that if the pointed reset type. + * + * @param[in] resetCauseType: reset cause type. + * + * @return status + * + */ +void SRMC_ClearSystemRestStatus(SRMC_ResetCause_t resetCauseType); + +/** + * @brief Get system reset all causes + * + * @param[in] none + * + * @return reset cause type(uint32 value): one bit, one cause; + * seeing SRMC_ResetCause_t type; + * + */ +uint32_t SRMC_GetSystemResetCause(void); + +/** + * @brief Unmask/Mask pointed interrupt + * + * @param[in] intType: srmc interrupt source. + * @param[in] intMask: UNMASK or MASK. + * + * @return none + * + */ +void SRMC_IntMask(SRMC_Int_t intType, IntMask_t intMask); + +/** + * @brief Configure max reset delay time from when the interrupt is + * asserted and the system reset occurs. + * + * @param[in] delayType: delay cycle type. + * + * @return none + * + */ +void SRMC_MaxResetDelayTimeConfig(SRMC_Delay_t delayType); + +/** + * @brief Configure standby mode entry allowed or not + * + * @param[in] cmd: DISABLE or ENABLE. + * + * @return none + * + */ +void SRMC_AllowStandbyMode(ControlState_t cmd); + +/** + * @brief Set system enter wait mode + * + * @return none + * + */ +void SRMC_EnterWaitMode(void); + +/** + * @brief Set system enter stop mode(deep sleep mode) + * + * @param[in] ackTimeout: stop mode acknowledge timeout value in clock cycles + * + * @return none + * + */ +void SRMC_EnterStopMode(uint8_t ackTimeout); + +/** + * @brief Set system enter standby mode + * + * @return none + * + */ +void SRMC_EnterStandbyMode(void); + +/** + * @brief Get current power mode + * + * @param[in] none + * + * @return power mode type + * + */ +SRMC_PowerMode_t SRMC_GetCurrentPowerMode(void); + +/** + * @brief Get previous stop mode(deep sleep mode) entry status + * + * @param[in] none + * + * @return stop entry status: + * - SRMC_STOP_SUCCESS; + * - SRMC_STOP_ABORT. + * + */ +SRMC_StopModeStatus_t SRMC_GetStopAbortedStatus(void); + +/** + * @brief Install callback func + * + * @param[in] intType: interrupt type id + * @param[in] cbFun : callback function pointer + * + * @return stop entry status: + * - SRMC_STOP_SUCCESS; + * - SRMC_STOP_ABORT. + * + */ +void SRMC_InstallCallBackFunc(SRMC_Int_t intType, isr_cb_t * cbFun); + +/** @} end of group SRMC_Public_FunctionDeclaration */ + +/** @} end of group SRMC */ + +/** @} end of group Z20K11X_Peripheral_Driver */ +#endif /* Z20K11XM_SRMC_H */ diff --git a/StdDriver/Inc/Z20K11xM_stim.h b/StdDriver/Inc/Z20K11xM_stim.h new file mode 100644 index 0000000..13bdb91 --- /dev/null +++ b/StdDriver/Inc/Z20K11xM_stim.h @@ -0,0 +1,291 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_stim.h + * @brief : STIM module driver header file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ + +#ifndef Z20K11XM_STIM_H +#define Z20K11XM_STIM_H + +#include "Z20K11xM_drv.h" + +/** @addtogroup Z20K11X_Peripheral_Driver + * @{ + */ + +/** @addtogroup STIM + * @{ + */ + +/** @defgroup STIM_Public_Types + * @{ + */ + +/** + * @brief STIM number type definition + */ +typedef enum +{ + STIM_0 = 0U, /*!< STIM_0 */ + STIM_1, /*!< STIM_1 */ + STIM_2, /*!< STIM_2 */ + STIM_3, /*!< STIM_3 */ + STIM_NUM_ALL +} STIM_No_t; + +/** + * @brief STIM clock source type definition + */ +typedef enum +{ + STIM_FUNCTION_CLOCK = 0U, /*!< Select stim function clock as counter clock source. */ + STIM_SRC_BUS_CLOCK, /*!< Select bus clock as counter clock source. */ + STIM_SRC_OSC40M, /*!< Select OSC40M as counter clock source. */ + STIM_SRC_LPO32K /*!< Select LPO32K as counter clock source. */ +} STIM_ClkSrc_t; + +/** + * @brief STIM prescaler divider factor and glitch filter value type definition + */ +typedef enum +{ + STIM_DIV_2 = 0U, /*!< divide the system clock by 2 as counter clock; glitch filter don't support this configuration. */ + STIM_DIV_4_FILTER_1, /*!< divide the system clock by 4 as counter clock; pulse width less than 1 system clock period will be filterred as glitch. */ + STIM_DIV_8_FILTER_3, /*!< divide the system clock by 8 as counter clock; pulse width less than 3 system clock period will be filterred as glitch. */ + STIM_DIV_16_FILTER_7, /*!< divide the system clock by 16 as counter clock; pulse width less than 7 system clock period will be filterred as glitch. */ + STIM_DIV_32_FILTER_15, /*!< divide the system clock by 32 as counter clock; pulse width less than 15 system clock period will be filterred as glitch. */ + STIM_DIV_64_FILTER_31, /*!< divide the system clock by 64 as counter clock; pulse width less than 31 system clock period will be filterred as glitch. */ + STIM_DIV_128_FILTER_63, /*!< divide the system clock by 128 as counter clock; pulse width less than 63 system clock period will be filterred as glitch. */ + STIM_DIV_256_FILTER_127, /*!< divide the system clock by 256 as counter clock; pulse width less than 127 system clock period will be filterred as glitch. */ + STIM_DIV_512_FILTER_255, /*!< divide the system clock by 512 as counter clock; pulse width less than 255 system clock period will be filterred as glitch. */ + STIM_DIV_1024_FILTER_511, /*!< divide the system clock by 1024 as counter clock; pulse width less than 511 system clock period will be filterred as glitch. */ + STIM_DIV_2048_FILTER_1023, /*!< divide the system clock by 2048 as counter clock; pulse width less than 1023 system clock period will be filterred as glitch. */ + STIM_DIV_4096_FILTER_2047, /*!< divide the system clock by 4096 as counter clock; pulse width less than 2047 system clock period will be filterred as glitch. */ + STIM_DIV_8192_FILTER_4095, /*!< divide the system clock by 8192 as counter clock; pulse width less than 4095 system clock period will be filterred as glitch. */ + STIM_DIV_16384_FILTER_8191, /*!< divide the system clock by 16384 as counter clock; pulse width less than 8191 system clock period will be filterred as glitch. */ + STIM_DIV_32768_FILTER_16383, /*!< divide the system clock by 32768 as counter clock; pulse width less than 16383 system clock period will be filterred as glitch. */ + STIM_DIV_65536_FILTER_32767 /*!< divide the system clock by 65536 as counter clock; pulse width less than 32767 system clock period will be filterred as glitch. */ +} STIM_PsOrFilter_t; + +/** + * @brief STIM input pin polarity type definition + */ +typedef enum +{ + STIM_ACTIVE_HIGH = 0U, /*!< input pin polarity is active high. */ + STIM_ACTIVE_LOW /*!< input pin polarity is acitve low. */ +} STIM_PinPoalrity_t; + +/** + * @brief STIM input pin source type definition + */ +typedef enum +{ + STIM_PIN_0 = 0U, /*!< input pin 0 is selected.Input pin 0 resource is come from TMU*/ + STIM_PIN_1, /*!< input pin 1 is selected.Input pin 1 is from pads */ + STIM_PIN_2, /*!< input pin 2 is selected.Input pin 2 is from pads */ + STIM_PIN_3 /*!< input pin 3 is selected.Input pin 3 is from pads */ +} STIM_PinSrc_t; + +/** + * @brief STIM mode type definition + */ +typedef enum +{ + STIM_FREE_COUNT = 0U, /*!< counter operates in free counting mode. */ + STIM_PULSE_COUNT /*!< counter operates in pulse counting mode. */ +} STIM_Mode_t; + +/** + * @brief STIM counter reset disable on match type definition + */ +typedef enum +{ + STIM_INCREASE_FROM_0 = 0U, /*!< stim counter reset and increaments from 0 when counter match. */ + STIM_INCREASE_CONTINUE /*!< stim counter continue to increament when counter match. */ +} STIM_CountReset_t; + +/** + * @brief STIM interrupt type definition + */ +typedef enum +{ + STIM_INT = 0U, /*!< Interrupt */ + STIM_INT_ALL +} STIM_INT_t; + +/** + * @brief STIM configuration struct definition + */ +typedef struct +{ + STIM_Mode_t workMode; /*!< Configure mode type. + - STIM_FREE_COUNT + - STIM_PULSE_COUNT*/ + uint32_t compareValue; /*!< When the counter is enabled, updating the related CV register by software will reset the coresponding + counter value and counter restart to count from 0. */ + STIM_CountReset_t countResetMode; /*!< This defines whether counter reset when counter matches the compare value. + - STIM_INCREASE_FROM_0: stim counter reset and increaments from 0 when counter match. + - STIM_INCREASE_CONTINUE: stim counter continue to increament when counter match.*/ + STIM_ClkSrc_t clockSource; /*!< Select which clock source as counter system clock. */ + STIM_PinSrc_t pinSource; /*!< Input pin source was selected as input pulse for pulse counting mode. */ + STIM_PinPoalrity_t pinPoalrity; /*!< Input pin polarity was selected for pulse counting mode.In free counting mode,counter increments on the rising edge of divided clock source. */ + STIM_PsOrFilter_t prescalerOrFilterValue; /*!< In pulse counting mode, if PSEN is enabled, PSDIV can not be configured as 0, otherwise will get unpredictable result. + - In free counting mode: PSDIV is used as the clock divider factor. + - In pulse counting mode: PSDIV is used as the glitch filter value. */ + ControlState_t prescalerMode; /*!< Prescaler enable/disable. + - In free counting mode, PSEN is used to enable the prescaler. + - In pulse counting mode, PSEN is used to enable the glitch filter.*/ +} STIM_Config_t; + +/** @} end of group STIM_Public_Types definitions */ + +/** @defgroup STIM_Public_Macro + * @{ + */ + +/** @} end of group STIM_Public_Macro */ + +/** @defgroup STIM_Public_FunctionDeclaration + * @brief STIM functions declaration + * @{ + */ + +/** + * @brief Install call back function + * + * @param[in] stimNo: Select the stim number,should be STIM_0,STIM_1,STIM_2, + * STIM_3. + * @param[in] intType: Select the interrupt. + * - STIM_INT + * @param[in] cbFun: pointer to callback function. + * + * @return none + * + */ +void STIM_InstallCallBackFunc(STIM_No_t stimNo, STIM_INT_t intType, + isr_cb_t * cbFun); + +/** + * @brief Initialize STIM configuration + * + * @param[in] stimNo: Select the stim number,should be STIM_0,STIM_1,STIM_2, + * STIM_3. + * @param[in] stimConfigStruct: Stim configuration struct. + * + * @return none + * + */ +void STIM_Init(STIM_No_t stimNo, const STIM_Config_t* stimConfigStruct); + +/** + * @brief Set compare value + * + * @param[in] stimNo: Select the stim number,should be STIM_0,STIM_1,STIM_2, + * STIM_3. + * @param[in] compareValue: stim compare value. + * + * @return none + * + */ +void STIM_SetCompareValue(STIM_No_t stimNo, uint32_t compareValue); + +/** + * @brief Current Value of stim + * + * @param[in] stimNo: Select the stim number,should be STIM_0,STIM_1,STIM_2, + * STIM_3. + * + * @return value of stim + * + */ +uint32_t STIM_GetCurrentCounterValue(STIM_No_t stimNo); + + /** + * @brief Enable stim + * + * @param[in] stimNo: Select the stim number,should be STIM_0,STIM_1,STIM_2, + * STIM_3. + * + * @return none + * + */ +void STIM_Enable(STIM_No_t stimNo); + +/** + * @brief Disable stim + * + * @param[in] stimNo: Select the stim number,should be STIM_0,STIM_1,STIM_2, + * STIM_3. + * + * @return none + * + */ +void STIM_Disable(STIM_No_t stimNo); + +/** + * @brief Enable/Disable the stim interrupt + * + * @param[in] stimNo: Select the stim number,should be STIM_0,STIM_1,STIM_2, + * STIM_3. + * @param[in] newState: Enable/Disable function state. + * - ENABLE: enable interrupt + * - DISABLE: disable interrupt + * + * @return none + * + */ +void STIM_IntCmd(STIM_No_t stimNo, ControlState_t newState); + +/** + * @brief Enable or disable the STIM DMA function. + * + * @param[in] stimNo: Select the stim number,should be STIM_0,STIM_1,STIM_2, + * STIM_3. + * @param[in] newState: Enable/Disable function state. + * - ENABLE: enable DMA request + * - DISABLE: disable DMA request + * + * @return none. + * + */ +void STIM_DmaCmd(STIM_No_t stimNo, ControlState_t newState); + +/** + * @brief Checks if the status flag is set when the counter matches the + * compare value + * + * @param[in] stimNo: Select the stim number,should be STIM_0,STIM_1,STIM_2, + * STIM_3. + * + * @return The status flag. + * - SET + * - RESET + * + */ +FlagStatus_t STIM_GetStatus(STIM_No_t stimNo); + +/** + * @brief Clear the interrupt of stim + * + * @param[in] stimNo: Select the stim number,should be STIM_0,STIM_1,STIM_2, + * STIM_3. + * + * @return none + * + */ +void STIM_ClearInt(STIM_No_t stimNo); + +/** @} end of group STIM_Public_FunctionDeclaration */ + +/** @} end of group STIM */ + +/** @} end of group Z20K11X_Peripheral_Driver */ + +#endif /* Z20K11XM_STIM_H */ diff --git a/StdDriver/Inc/Z20K11xM_sysctrl.h b/StdDriver/Inc/Z20K11xM_sysctrl.h new file mode 100644 index 0000000..a0e21f7 --- /dev/null +++ b/StdDriver/Inc/Z20K11xM_sysctrl.h @@ -0,0 +1,369 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_sysctrl.h + * @brief : SYSCTRL driver module header file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (C) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + * + **************************************************************************************************/ + +#ifndef Z20K11XM_SYSCTRL_H +#define Z20K11XM_SYSCTRL_H + +#include "Z20K11xM_drv.h" + +/** @addtogroup Z20K11X_Peripheral_Driver + * @{ + */ + +/** @addtogroup SYSCTRL + * @{ + */ + +/** @defgroup SYSCTRL_Public_Types + * @{ + */ + +/** + * @brief SYSCTRL module type definition + */ +typedef enum +{ + SYSCTRL_WDOG = 0U, /*!< WDOG */ + SYSCTRL_EWDT = 0x04U, /*!< EWDT */ + SYSCTRL_STIM = 0x08U, /*!< STIM */ + SYSCTRL_TIM0 = 0x0CU, /*!< TIM0 */ + SYSCTRL_TIM1 = 0x10U, /*!< TIM1 */ + SYSCTRL_TIM2 = 0x14U, /*!< TIM2 */ + SYSCTRL_TDG0 = 0x18U, /*!< TDG0 */ + SYSCTRL_CAN0 = 0x1CU, /*!< CAN0 */ + SYSCTRL_CAN1 = 0x20U, /*!< CAN1 */ + SYSCTRL_UART0 = 0x24U, /*!< UART0 */ + SYSCTRL_UART1 = 0x28U, /*!< UART1 */ + SYSCTRL_UART2 = 0x2CU, /*!< UART2 */ + SYSCTRL_UART3 = 0x30U, /*!< UART3 */ + SYSCTRL_SPI0 = 0x34U, /*!< SPI0 */ + SYSCTRL_SPI1 = 0x38U, /*!< SPI1 */ + SYSCTRL_SPI2 = 0x3CU, /*!< SPI2 */ + SYSCTRL_I2C0 = 0x40U, /*!< I2C0 */ + SYSCTRL_I2C1 = 0x44U, /*!< I2C1 */ + SYSCTRL_ADC0 = 0x48U, /*!< ADC0 */ + SYSCTRL_CMP = 0x4CU, /*!< CMP */ + SYSCTRL_CRC = 0x50U, /*!< CRC */ + SYSCTRL_FLASH = 0x54U, /*!< FLASH */ + SYSCTRL_DMA = 0x58U, /*!< DMA */ + SYSCTRL_DMAMUX = 0x5CU, /*!< DMAMUX */ + SYSCTRL_PORTA = 0x60U, /*!< PORTA */ + SYSCTRL_PORTB = 0x64U, /*!< PORTB */ + SYSCTRL_PORTC = 0x68U, /*!< PORTC */ + SYSCTRL_PORTD = 0x6cU, /*!< PORTD */ + SYSCTRL_PORTE = 0x70U, /*!< PORTE */ + SYSCTRL_TMU = 0x74U, /*!< TMU */ + SYSCTRL_REGFILE = 0x78U, /*!< REGFILE */ + SYSCTRL_GPIO = 0x7CU, /*!< GPIO */ + SYSCTRL_HWDIV = 0x80U /*!< HWDIV */ +}SYSCTRL_Module_t; + +typedef enum +{ + SYSCTRL_TRIG_LEVEL_LOW = 0U, /*!< software trigger level: low */ + SYSCTRL_TRIG_LEVEL_HIGH = 1U /*!< software trigger level: high */ +}SYSCTRL_TriggerLevel_t; + +typedef enum +{ + SYSCTRL_TRIG_SRC_0 = 0U, /*!< software trigger source 0 */ + SYSCTRL_TRIG_SRC_1 = 1U, /*!< software trigger source 1 */ + SYSCTRL_TRIG_SRC_2 = 2U, /*!< software trigger source 2 */ + SYSCTRL_TRIG_SRC_3 = 3U /*!< software trigger source 3 */ +}SYSCTRL_TriggerSrc_t; + +/** + * @brief SYSCTRL SRAM ID definition + */ +typedef enum +{ + SYSCTRL_SRAM_L = 0U, /*!< SRAM_L */ + SYSCTRL_SRAM_U /*!< SRAM_U */ +}SYSCTRL_Sram_t; + +/** + * @brief SYSCTRL master definition + */ +typedef enum +{ + SYSCTRL_MASTER_CPU = 1U, /*!< Master: CPU */ + SYSCTRL_MASTER_DMA = 2U, /*!< Master: DMA */ +}SYSCTRL_Master_t; + +/** + * @brief SYSCTRL access size definition + */ +typedef enum +{ + SYSCTRL_ACC_SIZE_8BIT = 0U, /*!< access size: 8 bits */ + SYSCTRL_ACC_SIZE_16BIT = 1U, /*!< access size: 16 bits */ + SYSCTRL_ACC_SIZE_32BIT = 2U, /*!< access size: 32 bits */ +}SYSCTRL_AccessSize_t; + +/** + * @brief SYSCTRL access type definition + */ +typedef enum +{ + SYSCTRL_ACC_TYPE_OPCODE = 0U, /*!< access type: opcode fetch */ + SYSCTRL_ACC_TYPE_DATA = 1U, /*!< access type: data access */ +}SYSCTRL_AccessType_t; + +/** + * @brief SYSCTRL access mode definition + */ +typedef enum +{ + SYSCTRL_ACC_MODE_USER = 0U, /*!< access mode: user */ + SYSCTRL_ACC_MODE_PRIVIL = 1U, /*!< access mode: privileged */ +}SYSCTRL_AccessMode_t; + +/** + * @brief SYSCTRL SRAM config struct definition + */ +typedef struct +{ + ControlState_t readEccEn; /*!< Enable/disable ECC when it reads SRAM */ + ControlState_t writeEccEn; /*!< Enable/disable ECC when it writes SRAM */ + ControlState_t singleBitEccEn; /*!< Enable/disable single bit ECC when + accesses SRAM */ + ControlState_t multiBitEccEn; /*!< Enable/disable multi bit ECC when + accesses SRAM */ +}SYSCTRL_SramEcc_t; + +/** + * @brief SYSCTRL SRAM ECC error cause struct definition + */ +typedef struct +{ + FlagStatus_t write; /*!< whether ECC error is caused by writing operation + - RESET: it is caused by reading + - SET: it is caused by writing */ + uint32_t errAddr; /*!< The access address that caused ECC error */ + uint32_t faultData; /*!< The fault data */ + SYSCTRL_Master_t faultMaster; /*!< Indicates error caused by which master.*/ + SYSCTRL_AccessSize_t faultSize; /*!< Indicates error caused by what size of + access.*/ + SYSCTRL_AccessType_t accessType;/*!< Indicates error caused by which type of + access. */ + SYSCTRL_AccessMode_t accessMode;/*!< Indicates error caused in which mode */ + FlagStatus_t bufferable; /*!< Indicates it is bufferable or not + - RESET: Non-bufferable + - SET: Bufferable */ + FlagStatus_t cacheable; /*!< Indicates it is bufferable or not + - RESET: Non-cacheable + - SET: Cacheable */ +}SYSCTRL_SramEccErrCause_t; + +/** + * @brief SYSCTRL device ID struct definition + */ +typedef struct +{ + uint8_t packageId; /*!< Package ID*/ + uint8_t featureId; /*!< Feature ID*/ + uint8_t RevisionId; /*!< Revision ID*/ + uint8_t familyId; /*!< Family ID*/ + uint8_t subFamilyId; /*!< Sub Family ID*/ + uint8_t seriesId; /*!< Series ID*/ + uint8_t memSizeId; /*!< Memory size ID*/ +}SYSCTRL_DeviceId_t; + + + +/** @} end of group SYSCTRL_Public_Types */ + +/** @defgroup SYSCTRL_Public_Constants + * @{ + */ + +/** @} end of group SYSCTRL_Public_Constants */ + +/** @defgroup SYSCTRL_Public_Macro + * @{ + */ +#define SYSCTRL_SRAM_ECC_ERR_SINGLEBIT_MASK 0x20000000U, /*!< SRAM ECC single bit error */ +#define SYSCTRL_SRAM_ECC_ERR_MULTIBIT_MASK 0x40000000U, /*!< SRAM ECC multi bit error */ +#define SYSCTRL_SRAM_ECC_ERR_OVERRUN_MASK 0x80000000U, /*!< SRAM ECC error overrun */ +#define SYSCTRL_SRAM_ECC_ERR_ALL_MASK 0xE0000000U /*!< all SRAM ECC error status */ +/** @} end of group SYSCTRL_Public_Macro */ + +/** @defgroup SYSCTRL_Public_FunctionDeclaration + * @brief SYSCTRL functions declaration + * @{ + */ + +/** + * @brief Get Device ID + * + * @param[in] none + * + * @return Device ID + * + */ +SYSCTRL_DeviceId_t SYSCTRL_GetDeviceId(void); + +/** + * @brief Get 128-bit unique ID + * + * @param[in] uniqueId: the start address of a array with 4 32-bit elements. + * the 128-bit unique ID will be written to this array. + * UniqueId[0]: bit 0-31 + * UniqueId[1]: bit 63-32 + * UniqueId[2]: bit 95-64 + * UniqueId[3]: bit 127-96 + * + * @return none + * + */ +void SYSCTRL_Get128BitUniqueId(uint32_t uniqueId[]); + +/** + * @brief reset module + * + * @param[in] mod: select which module to reset. It can select from modules + * defined in type SYSCTRL_Module_t except SYSCTRL_FLASH. + * + * @return none + * + */ +void SYSCTRL_ResetModule(SYSCTRL_Module_t mod); + +/** + * @brief Enable module. The module is enabled in normal/wait/stop modes. + * + * @param[in] mod: select which module to enable. + * + * @return none + * + */ +void SYSCTRL_EnableModule(SYSCTRL_Module_t mod); + +/** + * @brief Enable module but the module is off in stop mode. + * + * @param[in] mod: select which module to enable. + * + * @return none + * @note ADC does not support clock off in stop mode, no action is + * performed when mod = SYSCTRL_ADC0. + * + */ +void SYSCTRL_EnableModuleWithOffInStopMode(SYSCTRL_Module_t mod); + +/** + * @brief Disable module + * + * @param[in] mod: select which module to disable. + * + * @return none + * @note The module clock is switched off after calling this API. + * The register value of the selected module will be reset by + * this API except PORTx and flash modules. + * -- The PORTx is more likely to be shared among many modules, + * so the register values of PORTx are not reset by this API + * and only the function clock is diabled. + * The pinmux function retains when re-enable PORTx. + * User should use SYSCTRL_ResetModule() to reset PORTx regiters + * if desired. + * + */ +void SYSCTRL_DisableModule(SYSCTRL_Module_t mod); + +/** + * @brief Config the module write access limits + * + * @param[in] module: select which module to config + * @param[in] writeLock: write lock + * - ENABLE: Peripheral register write is denied + * - DISABLE: Peripheral register write is allowed + * @param[in] supervisorEn: supervisor enable + * - ENABLE: Peripheral register write is allowed in + * supervisor mode,but denied in user mode + * - DISABLE: Peripheral register write is allowed in + * both supervisor and user mode + * + * @return none + * + */ +void SYSCTRL_ModuleWriteControl(SYSCTRL_Module_t mod, ControlState_t writeLock, + ControlState_t supervisorEn); + +/** + * @brief Set Software trigger to TMU + * + * @param[in] source: select software trigger source to TMU + * @param[in] level: trigger level to TMU. + * + * @return none + * + */ +void SYSCTRL_SoftTriggerToTmu(SYSCTRL_TriggerSrc_t source, SYSCTRL_TriggerLevel_t level); + +/** + * @brief config SRAM ECC. SRAM ECC is enabled by default. ECC config can be + * changed through this function. + * + * @param[in] sram: select which SRAM to config. + * @param[in] eccConfig: points to the struct that stores the parameters. + * + * @return none + * + */ +void SYSCTRL_SramEccConfig(SYSCTRL_Sram_t sram, + const SYSCTRL_SramEcc_t *eccConfig); + +/** + * @brief Get SRAM ECC error status + * + * @param[in] sram: select which SRAM to config. + * @param[in] errMask: select the error mask. + * + * @return + * - RESET: the error status is not set + * - SET: the error status is set + * + */ +FlagStatus_t SYSCTRL_GetSramEccErrStatus(SYSCTRL_Sram_t sram, uint32_t errMask); + +/** + * @brief Clear SRAM ECC error status + * + * @param[in] sram: select which SRAM to config. + * @param[in] errMask: select the error mask. + * + * @return none + * + */ +void SYSCTRL_ClearSramEccErrStatus(SYSCTRL_Sram_t sram, uint32_t errMask); + +/** + * @brief Get SRAM ECC error cause + * + * @param[in] sram: select which SRAM to config. + * @param[in] cause: the cause of SRAM ERR error will be stored in the struct + * that is pointed by this parameter. + * + * @return none + * + */ +void SYSCTRL_GetSramEccErrCause(SYSCTRL_Sram_t sram, + SYSCTRL_SramEccErrCause_t *cause); + + +/** @} end of group SYSCTRL_Public_FunctionDeclaration */ + +/** @} end of group SYSCTRL */ + +/** @} end of group Z20K11X_Peripheral_Driver */ +#endif /* Z20K11XM_SYSCTRL_H */ diff --git a/StdDriver/Inc/Z20K11xM_tdg.h b/StdDriver/Inc/Z20K11xM_tdg.h new file mode 100644 index 0000000..4f8e59d --- /dev/null +++ b/StdDriver/Inc/Z20K11xM_tdg.h @@ -0,0 +1,509 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_TDG.h + * @brief : TDG driver module header file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ + +#ifndef Z20K11XM_TDG_H +#define Z20K11XM_TDG_H + +#include "Z20K11xM_drv.h" + +/** @addtogroup Z20K11X_Peripheral_Driver + * @{ + */ + +/** @addtogroup TDG + * @{ + */ + +/** @defgroup TDG_Public_Types + * @{ + */ +/** + * @brief TDG ID type definition + */ +typedef enum +{ + TDG0_ID = 0U, /*!< TDG0 */ +} TDG_ID_t; + +/** + * @brief TDG channel configuration update mode type definition + */ +typedef enum +{ + TDG_UPDATE_IMMEDIATELY = 0U, /*!< Immediately load configuration + afterupdate channel register */ + TDG_UPDATE_MODULATOR, /*!< Load configuration when counter + countup to equal to modulator */ + TDG_UPDATE_DELAY /*!< Load configuration when all + channelcomplete delay output */ +} TDG_UpdateMode_t; + +/** + * @brief TDG Clock Divide type definition + */ +typedef enum +{ + TDG_CLK_DIVIDE_1 = 0U, /*!< TDG Clock Divide by 1*/ + TDG_CLK_DIVIDE_2, /*!< TDG Clock Divide by 2*/ + TDG_CLK_DIVIDE_4, /*!< TDG Clock Divide by 4*/ + TDG_CLK_DIVIDE_8, /*!< TDG Clock Divide by 8*/ + TDG_CLK_DIVIDE_16, /*!< TDG Clock Divide by 16*/ + TDG_CLK_DIVIDE_32, /*!< TDG Clock Divide by 32*/ + TDG_CLK_DIVIDE_64, /*!< TDG Clock Divide by 64*/ + TDG_CLK_DIVIDE_128 /*!< TDG Clock Divide by 128*/ +} TDG_ClkDivide_t; + +/** + * @brief TDG Count Clear Mode type definition + */ +typedef enum +{ + TDG_CLEAR_MODULATOR = 0U, /*!< Clear counter when counter + equal to modulator */ + TDG_CLEAR_DELAY /*!< Clear counter when all channel + complete delay output */ +} TDG_CountClearMode_t; + +/** + * @brief TDG Count Mode type definition + */ +typedef enum +{ + TDG_COUNT_SINGLE = 0U, /*!< single loop mode */ + TDG_COUNT_INFINITY /*!< inifinity loop mode */ +} TDG_CountMode_t; + +/** + * @brief TDG Trig Source type definition + */ +typedef enum +{ + TDG_TRIG_EXTERNAL = 0U, /*!< external trig source */ + TDG_TRIG_SW /*!< software trig source */ +} TDG_TrigSource_t; + +/** + * @brief TDG Channel ID type definition + */ +typedef enum +{ + TDG_CHANNEL_0 = 0U, /*!< TDG Channel 0*/ + TDG_CHANNEL_1, /*!< TDG Channel 1*/ + TDG_CHANNEL_2, /*!< TDG Channel 2*/ + TDG_CHANNEL_3, /*!< TDG Channel 3*/ + TDG_CHANNEL_4, /*!< TDG Channel 4*/ + TDG_CHANNEL_5 /*!< TDG Channel 5*/ +} TDG_ChannelId_t; + +/** + * @brief TDG Interrupt type definition + */ +typedef enum +{ + TDG_INT_CH0 = 0U, /*!< channel 0 INT*/ + TDG_INT_CH1, /*!< channel 1 INT*/ + TDG_INT_CH2, /*!< channel 2 INT*/ + TDG_INT_CH3, /*!< channel 3 INT*/ + TDG_INT_CH4, /*!< channel 4 INT*/ + TDG_INT_CH5, /*!< channel 5 INT*/ + TDG_INT_ERR, /*!< Error interrupt*/ + TDG_INT_ALL +} TDG_INT_t; + +/** + * @brief TDG Delay Output point ID type definition + */ +typedef enum +{ + TDG_DO_0 = 0U, /*!< TDG Delay output 0*/ + TDG_DO_1, /*!< TDG Delay output 1*/ + TDG_DO_2, /*!< TDG Delay output 2*/ + TDG_DO_3, /*!< TDG Delay output 3*/ + TDG_DO_4, /*!< TDG Delay output 4*/ + TDG_DO_5, /*!< TDG Delay output 5*/ + TDG_DO_6, /*!< TDG Delay output 6*/ + TDG_DO_7 /*!< TDG Delay output 7*/ +} TDG_DelayOutputId_t; + +/** + * @brief TDG init configure struct definition + */ +typedef struct +{ + uint16_t modVal; /*!< modulate value */ + TDG_CountMode_t countMode; /*!< count mode */ + TDG_ClkDivide_t clkDivide; /*!< presacle clock source */ + TDG_TrigSource_t trigSource; /*!< counter trig source */ + TDG_UpdateMode_t updateMode; /*!< update mode */ + TDG_CountClearMode_t clearMode; /*!< counter clear mode */ +} TDG_InitConfig_t; + +/** + * @brief TDG delay output configure struct definition + */ +typedef struct +{ + TDG_DelayOutputId_t doId; /*!< delay output id */ + + uint16_t offset; /*!< delay output offset */ + ControlState_t cmd; /*!< delay output enable */ + +} TDG_DelayOutputConfig_t; + +/** + * @brief TDG Channel configure struct definition + */ +typedef struct +{ + TDG_ChannelId_t channelId; /*!< channel id */ + + uint16_t intDelayVal; /*!< delay output complete interrupt delay*/ + + uint8_t doNum; /* number of delya output point*/ + + TDG_DelayOutputConfig_t *doConfig; +} TDG_ChannelConfig_t; + +/** @} end of group TDG_Public_Types*/ + +/** @defgroup TDG_Public_Macro + * @{ + */ + +#define TDG_NUM 1U + +/** @}end of group TDG_Public_Macro */ +/** @defgroup TDG_Public_FunctionDeclaration + * @brief TDG functions statement + * @{ + */ + +/** + * @brief TDG ENABLE/DISABLE FUNCTION + * + * @param[in] tdgId + * @param[in] ControlState_t: ENABLE/DISABLE + * + * @return none + * + */ +void TDG_Enable(TDG_ID_t tdgId, ControlState_t cmd); + +/** + * @brief TDG init config function + * + * @param[in] tdgId + * @param[in] TDG_InitConfig_t: init config + * + * @return none + * + */ +void TDG_InitConfig(TDG_ID_t tdgId, const TDG_InitConfig_t *config); + +/** + * @brief TDG config update mode function + * + * @param[in] tdgId + * @param[in] updateMode: + * -TDG_UPDATE_IMMEDIATELY + * -TDG_UPDATE_MODULATOR + * -TDG_UPDATE_DELAY + * + * @return none + * + */ +void TDG_UpdateModeConfig(TDG_ID_t tdgId, TDG_UpdateMode_t updateMode); + +/** + * @brief TDG select counter clear mode + * + * @param[in] tdgId + * @param[in] clearMode: + * -TDG_ClEAR_MODULATOR + * -TDG_CLEAR_DELAY + * + * @return none + * + */ +void TDG_ClearCounterMode(TDG_ID_t tdgId, TDG_CountClearMode_t clearMode); + +/** + * @brief TDG select count mode + * + * @param[in] tdgId + * @param[in] countMode: + * -TDG_COUNT_SINGLE + * -TDG_COUNT_INFINITY + * + * @return none + * + */ +void TDG_SelectCountMode(TDG_ID_t tdgId, TDG_CountMode_t countMode); + +/** + * @brief TDG select trig source + * + * @param[in] tdgId + * @param[in] trigMode: + * -TDG_TRIG_EXTERNAL + * -TDG_TRIG_INFINITY + * + * @return none + * + */ +void TDG_SelectTrigMode(TDG_ID_t tdgId, TDG_TrigSource_t trig); + +/** + * @brief Set this bit to load channel configuration from shadow buffer to + * register + * + * @param[in] tdgId + * + * @return ResultStatus_t + * - SUCC: Load complete + * - ERR:load fail + * + */ +ResultStatus_t TDG_LoadCmd(TDG_ID_t tdgId); + +/** + * @brief TDG software trig + * + * @param[in] tdgId + * + * @return none + * + */ +void TDG_SoftwareTrig(TDG_ID_t tdgId); + +/** + * @brief TDG mod value config + * + * @param[in] tdgId + * @param[in] uint16_t modValue + * + * @return none + * + */ +void TDG_SetModVal(TDG_ID_t tdgId, uint16_t modValue); + +/** + * @brief GET TDG mod value + * + * @param[in] tdgId + * + * @return mod value + * + */ +uint16_t TDG_GetModVal(TDG_ID_t tdgId); + +/** + * @brief GET TDG counter value + * + * @param[in] tdgId + * + * @return counter value + * + */ +uint16_t TDG_GetCounterVal(TDG_ID_t tdgId); + +/** + * @brief TDG prescale the count clock sourec function + * + * @param[in] tdgId + * @param[in] TDG_ClkDivide_t: + * -TDG_CLK_DIVIDE_1 + * -TDG_CLK_DIVIDE_2 + * -TDG_CLK_DIVIDE_4 + * -TDG_CLK_DIVIDE_8 + * -TDG_CLK_DIVIDE_16 + * -TDG_CLK_DIVIDE_32 + * -TDG_CLK_DIVIDE_64 + * -TDG_CLK_DIVIDE_128 + * + * @return none + * + */ +void TDG_DivideClk(TDG_ID_t tdgId, TDG_ClkDivide_t divide); + +/** + * @brief TDG channel enable/disable + * + * @param[in] tdgId + * @param[in] TDG_ChannelId_t: select channel + * @param[in] ControlState_t:ENABLE/DISABLE + * + * @return none + * + */ +void TDG_ChannelEnable(TDG_ID_t tdgId, TDG_ChannelId_t channelId, + ControlState_t cmd); + +/** + * @brief TDG INT mask/unmask Function + * + * @param[in] tdgId + * @param[in] intType: Selcct interrupt type. + * @param[in] intMask: MASK/UNMASK . + * + * @return none + * + */ +void TDG_IntMask(TDG_ID_t tdgId, TDG_INT_t intType, IntMask_t intMask); + +/** + * @brief TDG INT status clear Function + * + * @param[in] tdgId + * @param[in] intType: Selcct interrupt type. + * + * @return none + * + */ +void TDG_IntClear(TDG_ID_t tdgId, TDG_INT_t intType); + +/** + * @brief TDG Get INT status Function + * + * @param[in] tdgId + * @param[in] intType: Selcct interrupt type. + * + * @return intstatus + * + */ +IntStatus_t TDG_GetIntStatus(TDG_ID_t tdgId, TDG_INT_t intType); + +/** + * @brief TDG channel delay output complete interrupt delay + * + * @param[in] tdgId + * @param[in] channelId: select channel + * @param[in] delayVal: delay output complete interrupt delay + * + * @return none + * + */ +void TDG_SetIntDelayVal(TDG_ID_t tdgId, TDG_ChannelId_t channelId, + uint16_t delayVal); + +/** + * @brief get TDG delay output complete interrupt delay value + * + * @param[in] tdgId + * @param[in] channelId: select channel y + * + * @return delay value + * + */ +uint16_t TDG_GetChannelIntDelayVal(TDG_ID_t tdgId, TDG_ChannelId_t channelId); + +/** + * @brief Clear TDG channel delay output function + * + * @param[in] tdgId + * @param[in] channelId: select channel + * + * @return none + * + */ +void TDG_ClearChannelDelayOutput(TDG_ID_t tdgId, TDG_ChannelId_t channelId); + +/** + * @brief TDG channel delay output enable function + * + * @param[in] tdgId + * @param[in] channelId: select channel + * @param[in] doConfig: config delay output + * + * @return none + * + */ +void TDG_DelayOuputConfig(TDG_ID_t tdgId, TDG_ChannelId_t channelId, + const TDG_DelayOutputConfig_t *doConfig); + +/** + * @brief TDG channel delay output config function + * + * @param[in] tdgId + * @param[in] doId: select delay output + * @param[in] ControlState_t: channel ENABLE/DISABLE + * + * @return none + * + */ +void TDG_ChannelDelayOutputConfig(TDG_ID_t tdgId, + const TDG_ChannelConfig_t *config, + ControlState_t cmd); + +/** + * @brief TDG get interrupt delay config load complete status Function + * + * @param[in] tdgId + * @param[in] channelId: Selcct channel type. + * + * @return intstatus + * + */ +IntStatus_t TDG_GetDelayStatus(TDG_ID_t tdgId, TDG_ChannelId_t channelId); + +/** + * @brief get TDG delay output offset value + * + * @param[in] tdgId + * @param[in] channelId: select channel id + * @param[in] doId: select delay output id + * + * @return delay value + * + */ +uint16_t TDG_GetChannelOffsetVal(TDG_ID_t tdgId, TDG_ChannelId_t channelId, + TDG_DelayOutputId_t doId); + +/** + * @brief TDG get channel number Function + * + * @param[in] tdgId + * + * @return channel number + * + */ +uint8_t TDG_GetCHNum(TDG_ID_t tdgId); + +/** + * @brief TDG get delay output point Function + * + * @param[in] tdgId + * + * @return delay output point + * + */ +uint8_t TDG_GetDoNum(TDG_ID_t tdgId); + +/** + * @brief install call back function + * + * @param[in] tdgId + * @param[in] intId: select the interrupt + * @param[in] cbFun: pointer to callback function + * + * @return none + */ +void TDG_InstallCallBackFunc(TDG_ID_t tdgId, TDG_INT_t intType, + isr_cb_t *cbFun); + +/** @} end of group TDG_Public_FunctionDeclaration */ + +/** @} end of group TDG */ + +/** @} end of group Z20K11X_Peripheral_Driver */ + +#endif /* Z20K11XM_TDG_H */ diff --git a/StdDriver/Inc/Z20K11xM_tim.h b/StdDriver/Inc/Z20K11xM_tim.h new file mode 100644 index 0000000..f3680ab --- /dev/null +++ b/StdDriver/Inc/Z20K11xM_tim.h @@ -0,0 +1,1097 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_tim.h + * @brief : TIM module driver header file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ + +#ifndef Z20K11XM_TIM_H +#define Z20K11XM_TIM_H + +#include "Z20K11xM_drv.h" + +/** @addtogroup Z20K11X_Peripheral_Driver + * @{ + */ + +/** @addtogroup TIM + * @{ + */ + +/** @defgroup TIM_Public_Types + * @{ + */ + +/** + * @brief TIM ID type definition + */ +typedef enum +{ + TIM0_ID = 0U, /*!< TIM0 */ + TIM1_ID, /*!< TIM1 */ + TIM2_ID /*!< TIM2 */ +}TIM_ID_t; + +/** + * @brief TIM Channel ID type definition + */ +typedef enum +{ + TIM_CHANNEL_0 = 0U, /*!< TIM Channel 0*/ + TIM_CHANNEL_1, /*!< TIM Channel 1*/ + TIM_CHANNEL_2, /*!< TIM Channel 2*/ + TIM_CHANNEL_3, /*!< TIM Channel 3*/ + TIM_CHANNEL_4, /*!< TIM Channel 4*/ + TIM_CHANNEL_5, /*!< TIM Channel 5*/ + TIM_CHANNEL_6, /*!< TIM Channel 6*/ + TIM_CHANNEL_7 /*!< TIM Channel 7*/ +}TIM_ChannelId_t; + +/** + * @brief TIM Pair Channel ID type definition + */ +typedef enum +{ + TIM_PAIR_CHANNEL_0 = 0U, /*!< TIM pair 0 control channel0 and channel 1*/ + TIM_PAIR_CHANNEL_1, /*!< TIM pair 1 control channel2 and channel 3*/ + TIM_PAIR_CHANNEL_2, /*!< TIM pair 2 control channel4 and channel 5*/ + TIM_PAIR_CHANNEL_3 /*!< TIM pair 3 control channel6 and channel 7*/ +}TIM_PairId_t; + +/** + * @brief TIM Clock Source type definition + */ +typedef enum +{ + TIM_CLK_SOURCE_SYSTEM = 1U, /*!< System Clock as TIM Counter Clock*/ + TIM_CLK_SOURCE_FUNCTION = 2U, /*!< Function Clock as TIM Counter Clock*/ + TIM_CLK_SOURCE_EXTERNAL = 3U /*!< External Clock as TIM Counter Clock*/ +}TIM_ClkSource_t; + +/** + * @brief TIM External Clock Source type definition + */ +typedef enum +{ + TIM_CLK_0 = 0U, /*!< PTB1 */ + TIM_CLK_1, /*!< PTA5 */ + TIM_CLK_2 /*!< PTE8 */ +}TIM_ExternalSource_t; + +/** + * @brief TIM Clock Divide type definition + */ +typedef enum +{ + TIM_CLK_DIVIDE_1 = 0U, /*!< TIM Clock Divide by 1*/ + TIM_CLK_DIVIDE_2, /*!< TIM Clock Divide by 2*/ + TIM_CLK_DIVIDE_4, /*!< TIM Clock Divide by 4*/ + TIM_CLK_DIVIDE_8, /*!< TIM Clock Divide by 8*/ + TIM_CLK_DIVIDE_16, /*!< TIM Clock Divide by 16*/ + TIM_CLK_DIVIDE_32, /*!< TIM Clock Divide by 32*/ + TIM_CLK_DIVIDE_64, /*!< TIM Clock Divide by 64*/ + TIM_CLK_DIVIDE_128 /*!< TIM Clock Divide by 128*/ +}TIM_ClkDivide_t; + +/** + * @brief TIM Counter Counting Mode type definition + */ +typedef enum +{ + TIM_COUNTING_UP = 0U, /*!< TIM Up Counting Mode*/ + TIM_COUNTING_UP_DOWN /*!< TIM Up-Down Counting Mode*/ +}TIM_CountingMode_t; + +/** + * @brief TIM Channel Work Mode type definition + */ +typedef enum +{ + TIM_MODE_NONE = 0U, /*!< TIM channel mode: disabled*/ + TIM_MODE_INPUT_CAPTURE, /*!< TIM channel mode: input capture */ + TIM_MODE_DUAL_EDGE_CAPTURE, /*!< TIM channel mode: dual edge capture*/ + TIM_MODE_OUTPUT_COMPARE, /*!< TIM channel mode: output compare */ + TIM_MODE_EGDE_ALIGNED_PWM, /*!< TIM channel mode: edge-aligned pwm */ + TIM_MODE_CENTER_ALIGNED_PWM, /*!< TIM channel mode: center-aligned pwm */ + TIM_MODE_COMPLEMENTARY_PWM /*!< TIM channel mode: complementary pwm */ +}TIM_ChannelWorkMode_t; + +/** + * @brief TIM Edge-Alignment Mode type definition + */ +typedef enum +{ + TIM_INPUT_DISABLED = 0U, /*!< TIM input capture disabled*/ + TIM_INPUT_EDGE_RISING, /*!< TIM input capture only on rising edge*/ + TIM_INPUT_EDGE_FAILING, /*!< TIM input capture only on failing edge*/ + TIM_INPUT_EDGE_BOTH /*!< TIM input capture both on rising and failing edge*/ +}TIM_InputCaptureMode_t; + +/** + * @brief TIM Output Mode type definition + */ +typedef enum +{ + TIM_OUTPUT_NO_CHANGE = 0U, /*!< TIM output no change on match*/ + TIM_OUTPUT_TOGGLE, /*!< TIM output toggle on match*/ + TIM_OUTPUT_INACTIVE_STATE, /*!< TIM output inactive state on match*/ + TIM_OUTPUT_ACTIVE_STATE /*!< TIM output active state on match*/ +}TIM_OutputMode_t; + +/** + * @brief TIM PWM mode type definition + */ +typedef enum +{ + TIM_PWM_DISABLED = 0U, /*!< TIM pwm: disabled*/ + TIM_PWM_LOW_TRUE_PULSE, /*!< TIM pwm: force output to active state on match*/ + TIM_PWM_HIGH_TRUE_PULSE /*!< TIM pwm: force output to inactive state on match*/ +}TIM_PwmMode_t; + +/** + * @brief level Type definition + */ +typedef enum +{ + LOW_LEVEL = 0U, /*!< TIM level: low*/ + HIGH_LEVEL /*!< TIM level: high*/ +}Level_t; + +/** + * @brief TIM Polarity type definition + */ +typedef enum +{ + TIM_POL_HIGH = 0U, /*!< TIM channel output polarity is high: + Logic 1 is active state; + Logic 0 is inactive state; */ + TIM_POL_LOW /*!< TIM channel output polarity is low: + Logic 1 is inactive state; + Logic 0 is active state; */ +}TIM_Polarity_t; + +/** + * @brief TIM Dual Edge Capture Mode type definition + */ +typedef enum +{ + TIM_ONE_PULSE_CAPTURE = 0U, /*!< one pulse capture in dual edge capture mode*/ + TIM_CONTINUOUS_PULSE_CAPTURE /*!< continuous pulse capture in dual edge capture mode*/ +}TIM_DualEdgeCaptureMode_t; + +/** + * @brief TIM Signal Measurement type definition + */ +typedef enum +{ + TIM_MEASURE_SIGNAL_PERIOD = 0U, /*!< signal period measurement*/ + TIM_MEASURE_SIGNAL_PULSE_WIDTH /*!< signal pulse width measurement*/ +}TIM_SignalMeasurement_t; + + +/** + * @brief TIM channel input filter type definition, only available for channel 0/1/2/3 + */ +typedef enum +{ + TIM_INPUT_FILTER_DISABLED = 0U, /*!< the channel input filter: disabled*/ + TIM_INPUT_FILTER_1, /*!< the channel input filter: 1*/ + TIM_INPUT_FILTER_2, /*!< the channel input filter: 2*/ + TIM_INPUT_FILTER_3, /*!< the channel input filter: 3*/ + TIM_INPUT_FILTER_4, /*!< the channel input filter: 4*/ + TIM_INPUT_FILTER_5, /*!< the channel input filter: 5*/ + TIM_INPUT_FILTER_6, /*!< the channel input filter: 6*/ + TIM_INPUT_FILTER_7, /*!< the channel input filter: 7*/ + TIM_INPUT_FILTER_8, /*!< the channel input filter: 8*/ + TIM_INPUT_FILTER_9, /*!< the channel input filter: 9*/ + TIM_INPUT_FILTER_10, /*!< the channel input filter: 10*/ + TIM_INPUT_FILTER_11, /*!< the channel input filter: 11*/ + TIM_INPUT_FILTER_12, /*!< the channel input filter: 12*/ + TIM_INPUT_FILTER_13, /*!< the channel input filter: 13*/ + TIM_INPUT_FILTER_14, /*!< the channel input filter: 14*/ + TIM_INPUT_FILTER_15 /*!< the channel input filter: 15*/ +}TIM_Filter_t; + +/** + * @brief TIM deadtime prescaler type define + */ +typedef enum +{ + TIM_PRESCALER_1 = 1U, /*!< divided the system clock by 1*/ + TIM_PRESCALER_4, /*!< divided the system clock by 4*/ + TIM_PRESCALER_16 /*!< divided the system clock by 16*/ +}TIM_DeadtimePrescaler_t; + +/** + * @brief TIM fault input ID type define + */ +typedef enum +{ + TIM_FAULT_CHANNEL_0 = 0U, /*!< fault input 0*/ + TIM_FAULT_CHANNEL_1, /*!< fault input 1*/ + TIM_FAULT_CHANNEL_ALL +}TIM_FaultChannelId_t; + +/** + * @brief TIM Fault Safe Output Status type definition + */ +typedef enum +{ + TIM_LOW_STATE = 0U, /*!< fault event is on-going, TIM output is low, inactive state*/ + TIM_TRI_STATE /*!< fault event is on-going, TIM output is high, tri-stated*/ +}TIM_FaultSafeState_t; + +/** + * @brief TIM Fault Clear Mode type definition + */ +typedef enum +{ + TIM_Fault_MANUAL_CLEAR = 0U,/*!< manual fault clear mode*/ + TIM_Fault_AUTO_CLEAR /*!< automatical fault clear mode*/ +}TIM_FaultClearMode_t; + +/** + * @brief TIM CNTINT OUTSWCR register update Mode type definition + */ +typedef enum +{ + TIM_UPDATE_SYSTEM_CLK = 0U, /*!< update on all rising edge of the system clock*/ + TIM_UPDATE_PWM_SYN /*!< update only by PWM synchronization*/ +}TIM_RegUpdateMode_t; + +/** + * @brief TIM Reload Mode type definition + */ +typedef enum +{ + TIM_RELOAD_FULL_CYCLE = 0U, /*!< full cycle reload opportunity, when TIM + counter reaches the value of MOD */ + TIM_RELOAD_HALF_CYCLE, /*!< half cycle reload opportunity, when HCSEL + enabled and TIM reaches the value of HCV*/ + TIM_RELOAD_CHANNEL_MATCH /*!< channel match reload opportunity, when CHnSel + is enabled and TIM counter reaches the value of CCV(n)*/ +}TIM_ReloadMode_t; + +/** + * @brief TIM Interrupt type definition + */ +typedef enum +{ + TIM_INT_CH0 = 0U, /*!< channel 0 INT*/ + TIM_INT_CH1, /*!< channel 1 INT*/ + TIM_INT_CH2, /*!< channel 2 INT*/ + TIM_INT_CH3, /*!< channel 3 INT*/ + TIM_INT_CH4, /*!< channel 4 INT*/ + TIM_INT_CH5, /*!< channel 5 INT*/ + TIM_INT_CH6, /*!< channel 6 INT*/ + TIM_INT_CH7, /*!< channel 7 INT*/ + TIM_INT_RLD, /*!< reload INT*/ + TIM_INT_TO, /*!< timer overflow INT*/ + TIM_INT_FAULT, /*!< fault INT*/ + TIM_INT_ALL +}TIM_INT_t; + +/** + * @brief TIM input capture channel config struct definition + */ +typedef struct +{ + TIM_ChannelId_t channelId; /*!< channel id */ + TIM_InputCaptureMode_t edgeConfig; /*!< edge-alignment mode */ + TIM_Filter_t filter; /*!< filter config */ + ControlState_t resetEnable; /*!< enable function that counter reset + when capture counter to CCV */ +}TIM_InputChannelConfig_t; + +/** + * @brief TIM input capture global config struct definition + */ +typedef struct +{ + uint8_t numChannels; /*!< channel number*/ + uint16_t maxCounterVal; /*!< max counter value*/ + TIM_InputChannelConfig_t * inputChConfig; /*!< input config for every channel*/ +}TIM_InputCaptureConfig_t; + +/** + * @brief TIM dual edge capture channel config struct definition + */ +typedef struct +{ + TIM_PairId_t pairId; /*!< pair id */ + TIM_InputCaptureMode_t mainEdgeConfig; /*!< main channel edge alignment mode*/ + TIM_InputCaptureMode_t secondEdgeConfig; /*!< second channel edge alignment mode*/ + TIM_Filter_t filter; /*!< filter config*/ + TIM_DualEdgeCaptureMode_t captureMode; /*!< capture mode: one pulse; continuous*/ +}TIM_DualEdgeChannelConfig_t; + +/** + * @brief TIM dual edge capture global config struct definition + */ +typedef struct +{ + uint8_t numPairs; /*!< pair number */ + uint16_t maxCounterVal; /*!< max counter value */ + TIM_DualEdgeChannelConfig_t * config; /*!< dual edge config for each channel */ +}TIM_DualEdgeCaptureConfig_t; + +/** + * @brief TIM output compare channel config struct definition + */ +typedef struct +{ + TIM_ChannelId_t channelId; /*!< channel id */ + TIM_OutputMode_t outputMode; /*!< output mode: + - no change; + - toggle; + - inactive; + - active + */ + TIM_Polarity_t polarity; /*!< polarity: + - TIM_POL_HIGH; + - TIM_POL_LOW + */ + uint16_t compareValue; /*!< compare value*/ + Level_t initValue; /*!< init output value*/ +}TIM_OutputCompareChannelConfig_t; + +/** + * @brief TIM output compare global config struct definition + */ +typedef struct +{ + uint8_t numChannels; /*!< channel number */ + uint16_t maxCounterVal; /*!< max counter value */ + ControlState_t initTriggerEnable; /*!< init trigger cmd: enable/disable*/ + ControlState_t faultCtrlChannelEnable; /*!< fault ctrl function enable/disable for each pair*/ + TIM_OutputCompareChannelConfig_t* outputConfig;/*!< output config for each channel*/ +}TIM_OutputCompareConfig_t; + +/** + * @brief TIM software control output config struct definition + */ +typedef struct +{ + ControlState_t outputSWCtrlEnable; /*!< SW control output cmd: enable/disable*/ + Level_t outputSWCtrlVal; /*!< SW control output value*/ +}TIM_OutputSWCtrlConfig_t; + +/** + * @brief TIM fault control channel config struct definition + */ +typedef struct +{ + ControlState_t faultInputChannelEnable; /*!< fault input enable for each fault channel */ + ControlState_t faultInputFilterEnable; /*!< fault input filter enable for each fault channel */ + TIM_Polarity_t faultInputPolarity; /*!< fault input polarity for each fault channel */ +}TIM_FaultChannelConfig_t; + +/** + * @brief TIM fault control config struct definition + */ +typedef struct +{ + ControlState_t faultCtrlEnable; /*!< fault control func enable */ + TIM_Filter_t faultFilterValue; /*!< fault filter value */ + TIM_FaultSafeState_t status; /*!< fault safe output status type */ + TIM_FaultClearMode_t faultClearMode; /*!< fault clear mode type */ + TIM_FaultChannelConfig_t faultChannelConfig[TIM_FAULT_CHANNEL_ALL]; + /*!< fault config for all fault channel*/ +}TIM_PwmFaultCtrlConfig_t; + +/** + * @brief TIM PWM output channel config struct definition + */ +typedef struct +{ + TIM_ChannelId_t channelId; /*!< channel id */ + TIM_PwmMode_t pwmModeConfig; /*!< pwm mode: disable; low-true-pulse; high-true-pulse*/ + TIM_Polarity_t polarity; /*!< polarity: TIM_POL_HIGH; TIM_POL_LOW*/ + uint16_t compareValue; /*!< compare value*/ + ControlState_t faultCtrlChannelEnable; /*!< fault ctrl function enable/disable for each channel*/ + ControlState_t ccvUpdateEnable; /*!< ccv sync function enable/disable for each channel*/ +}TIM_PwmChannelConfig_t; + +/** + * @brief TIM PWM output global config struct definition + */ +typedef struct +{ + uint8_t numChannels; /*!< channel number */ + uint16_t minCounterVal; /*!< min counter value */ + uint16_t maxCounterVal; /*!< max counter value */ + TIM_PwmChannelConfig_t * pwmChConfig;/*!< pwm config for each channel */ +}TIM_PwmConfig_t; + +/** + * @brief TIM complementary PWM output channel config struct definition + */ +typedef struct +{ + TIM_PairId_t pairId; /*!< pair id */ + TIM_PwmMode_t pwmModeConfig; /*!< pwm mode: disable; low-true-pulse; high-true-pulse*/ + TIM_Polarity_t polarity; /*!< polarity: TIM_POL_HIGH; TIM_POL_LOW*/ + uint16_t mainCompareValue; /*!< main channel compare value*/ + uint16_t secondCompareValue; /*!< second channel compare value*/ + ControlState_t deadtimeEnable; /*!< deadtime function enable/disable for each pair*/ + ControlState_t faultCtrlChannelEnable; /*!< fault ctrl function enable/disable for each pair*/ + ControlState_t ccvUpdateEnable; /*!< ccv sync function enable/disable for each pair*/ +}TIM_CompPwmChannelConfig_t; + +/** + * @brief TIM complementary PWM output global config struct definition + */ +typedef struct +{ + uint8_t numPairs; /*!< pair id */ + uint16_t minCounterVal; /*!< min Counter val*/ + uint16_t maxCounterVal; /*!< max Counter val*/ + TIM_DeadtimePrescaler_t deadTimePrescaler;/*!< deadtime prescaler*/ + uint8_t deadTimeVal; /*!< deadtime value*/ + TIM_CompPwmChannelConfig_t * cPwmChConfig;/*!< complementary pwm config for each channle*/ +}TIM_CompPwmConfig_t; + +/** + * @brief TIM channel config for channel match reload mode + */ +typedef struct +{ + TIM_ChannelId_t channelId; /*!< channel id */ + ControlState_t channelMatchEnable; /*!< channel match function Enable*/ +}TIM_ChannelMatchConfig_t; + +/** + * @brief TIM reload config struct definition + */ +typedef struct +{ + TIM_ReloadMode_t reloadMode; /*!< reload mode: + - full cycle; + - half cycle; + - channel match */ + uint8_t loadFrequency; /*!< load frequency */ + uint8_t numChannels; /*!< channel number */ + TIM_ChannelMatchConfig_t * channelMatchConfig;/*!< point to channel match config*/ +}TIM_ReloadConfig_t; + +/** + * @brief TIM register sync config struct define + */ +typedef struct +{ + TIM_RegUpdateMode_t cntinitSync; /*!< Configure CNTINIT sync*/ + TIM_RegUpdateMode_t outswcSync; /*!< Configure OUTSWC sync*/ + ControlState_t syncSWTriggerEnable; /*!< Enable/Disable software trigger sync*/ + ControlState_t syncReloadEnable; /*!< Enable/Disable reload sync*/ + TIM_ReloadConfig_t * reloadConfig; /*!< Configure reload params*/ +}TIM_PwmSyncConfig_t; + +/** @} end of group TIM_Public_Types definitions */ + +/** @defgroup TIM_Public_Constants + * @{ + */ + + +/** @} end of group TIM_Public_Constants */ + +/** @defgroup TIM_Public_FunctionDeclaration + * @{ + */ + +/** + * @brief TIM WriteProtection Enable Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * + * @return none + * + */ +void TIM_WriteProtectionEnable(TIM_ID_t timId); + +/** + * @brief TIM WriteProtection Disable Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * + * @return none + * + */ +void TIM_WriteProtectionDisable(TIM_ID_t timId); + + +/** + * @brief Init TIMER Counter with initial value and max value + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] initialVal: Counter init value. + * @param[in] maxVal: Counter max value, also named mod value. + * + * @return none + * + */ +void TIM_InitCounter(TIM_ID_t timId, uint16_t initialVal, uint16_t maxVal); + +/** + * @brief TIM Start counter with clock configuration + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] clkSource: Select TIM clock source: + * - TIM_CLK_SOURCE_SYSTEM + * - TIM_CLK_SOURCE_FUNCTION + * - TIM_CLK_SOURCE_EXTERNAL + * @param[in] divider: Select TIM clock divider. + * - 000b: Divide by 1 + * - 001b: Divide by 2 + * - 010b: Divide by 4 + * - 011b: Divide by 8 + * - 100b: Divide by 16 + * - 101b: Divide by 32 + * - 110b: Divide by 64 + * - 111b: Divide by 128 + * + * @return none + * + */ +void TIM_StartCounter(TIM_ID_t timId, TIM_ClkSource_t clkSource, + TIM_ClkDivide_t divider); + +/** + * @brief TIM external clock source configuration + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] clkSource: Select TIM external clock source + * + * @return none + * + */ +void TIM_ExternalCounterSelect(TIM_ID_t timId, TIM_ExternalSource_t clkSource); + +/** + * @brief TIM Stop counter + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * + * @return none + * + */ +void TIM_StopCounter(TIM_ID_t timId); + +/** + * @brief TIM Set Counter Init Value Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] initialVal: Counter init value. + * + * @return none + * + */ +void TIM_SetCounterInitialVal(TIM_ID_t timId, uint16_t initialVal); + +/** + * @brief TIM Load Counter Init Value Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * + * @return none + * + */ +void TIM_LoadCounterInitialVal(TIM_ID_t timId); + +/** + * @brief TIM Get Counter Init Value Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * + * @return Counter Init Value + * + */ +uint16_t TIM_GetCounterInitialVal(TIM_ID_t timId); + +/** + * @brief TIM Set Counter Mod Value Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] modVal: Counter MOD value. + * + * @return none + * + */ +void TIM_SetCounterModVal(TIM_ID_t timId, uint16_t modVal); + +/** + * @brief TIM Get Counter MOD Value Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * + * @return Counter MOD Value + * + */ +uint16_t TIM_GetCounterModVal(TIM_ID_t timId); + +/** + * @brief TIM Set Capture and Compare Value Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] channelId:Selcct channel ID. + * @param[in] ccVal: Capture and Compare Value. + * + * @return none + * + */ +void TIM_SetCCVal(TIM_ID_t timId, TIM_ChannelId_t channelId, uint16_t ccVal); + +/** + * @brief TIM Get Capture and Compare Value Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] channelId: Selcct channel ID. + * + * @return Capture and Compare Value + * + */ +uint16_t TIM_GetCCVal(TIM_ID_t timId, TIM_ChannelId_t channelId); + +/** + * @brief TIM Set Half Cycle Value Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] hcVal: Half Cycle value. + * + * @return none + * + */ +void TIM_SetHCVal(TIM_ID_t timId, uint16_t hcVal); + +/** + * @brief TIM Get Half Cycle Value Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * + * @return Half Cycle Value + * + */ +uint16_t TIM_GetHCVal(TIM_ID_t timId); + +/** + * @brief TIM Set Output Software Control Register Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] swCtrlCmd: Output Software Control Cmd. + * + * @return none + * + */ +void TIM_SetOutputSwControl(TIM_ID_t timId, uint8_t swCtrlCmd); + +/** + * @brief TIM Set Output Software Control Value Register Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] swCtrlVal: Output Software Control value. + * + * @return none + * + */ +void TIM_SetOutputSwCtrlVal(TIM_ID_t timId, uint8_t swCtrlVal); + +/** + * @brief TIM Get Output Software Control Register Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * + * @return Output Software Control Cmd. + * + */ +uint8_t TIM_GetOutputSwControl(TIM_ID_t timId); + +/** + * @brief TIM Get Output Software Control Register Value Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * + * @return Output Software Control Cmd. + * + */ +uint8_t TIM_GetOutputSwCtrlVal(TIM_ID_t timId); + +/** + * @brief TIM 16-bit Counter Counting Mode Config Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] cntMode: Counting Mode Param. + * + * @return none + * + */ +void TIM_CountingModeConfig(TIM_ID_t timId, TIM_CountingMode_t cntMode); + +/** + * @brief TIM Initialize the channels output Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * + * @return none + * + */ +void TIM_InitChannelsOutput(TIM_ID_t timId); + +/** + * @brief TIM initialise input capture mode config Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] config: Pointer to input capture config. + * + * @return none + * + */ +void TIM_InputCaptureInit(TIM_ID_t timId, const TIM_InputCaptureConfig_t * config); + +/** + * @brief TIM initialise dual edge capture mode config Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] config: Pointer to dual edge capture config. + * + * @return none + * + */ +void TIM_DualEdgeCaptureInit(TIM_ID_t timId, const TIM_DualEdgeCaptureConfig_t * config); + +/** + * @brief TIM initialise output compare mode config Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] config: Pointer to output compare config. + * + * @return none + * + */ +void TIM_OutputCompareInit(TIM_ID_t timId, const TIM_OutputCompareConfig_t * config); + +/** + * @brief TIM output software control config Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] channelId:Select Channel Id. + * @param[in] config: Pointer to software control config. + * + * @return none + * + */ +void TIM_OutputSWCtrlConfig(TIM_ID_t timId, TIM_ChannelId_t channelId, + const TIM_OutputSWCtrlConfig_t* config); + +/** + * @brief TIM enable channel output Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] channelId:Select Channel Id. + * + * @return none + * + */ +void TIM_ChannelOutputEnable(TIM_ID_t timId, TIM_ChannelId_t channelId); + +/** + * @brief TIM disable channel output Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] channelId:Select Channel Id. + * + * @return none + * + */ +void TIM_ChannelOutputDisable(TIM_ID_t timId, TIM_ChannelId_t channelId); + +/** + * @brief TIM Set match trigger cmd enable/disable Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] channelId: Select channel id . + * @param[in] cmd: enable/disable. + * + * @return none + * + */ +void TIM_ChannelMatchTriggerCmd(TIM_ID_t timId, TIM_ChannelId_t channelId, + ControlState_t cmd); + +/** + * @brief TIM Set init trigger cmd enable/disable Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] cmd: enable/disable. + * + * @return none + * + */ +void TIM_InitTriggerCmd(TIM_ID_t timId, ControlState_t cmd); + +/** + * @brief TIM get match trigger flag Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * + * @return flag status + * + */ +FlagStatus_t TIM_GetMatchTriggerFlag(TIM_ID_t timId); + +/** + * @brief TIM initialise center-aligned PWM output config Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] config: Pointer to center-aligned PWM output config. + * + * @return none + * + */ +void TIM_OutputCenterAlignedPwmConfig(TIM_ID_t timId, const TIM_PwmConfig_t * config); + +/** + * @brief TIM initialise edge-aligned PWM output config Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] config: Pointer to edge-aligned PWM output config. + * + * @return none + * + */ +void TIM_OutputEdgeAlignedPwmConfig(TIM_ID_t timId, const TIM_PwmConfig_t * config); + +/** + * @brief TIM initialise complementary PWM output config Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] config: Pointer to complementary PWM output config. + * + * @return none + * + */ +void TIM_OutputComplementaryPwmConfig(TIM_ID_t timId, const TIM_CompPwmConfig_t * config); + +/** + * @brief TIM initialise fault control config Function, which used in pwm mode + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] config: Pointer to fault control config. + * + * @return none + * + */ +void TIM_FaultControlConfig(TIM_ID_t timId, const TIM_PwmFaultCtrlConfig_t * config); + +/** + * @brief TIM initialise fault control config Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] cmd: Enable/Disable. + * + * @return none + * + */ +void TIM_FaultControlCmd(TIM_ID_t timId, ControlState_t cmd); + +/** + * @brief TIM Software Trigger Sync Config Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] cmd: Enable/Disable. + * + * @return none + * + */ +void TIM_SWTriggerSyncCmd(TIM_ID_t timId, ControlState_t cmd); + +/** + * @brief TIM Reload Sync Config Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] cmd: Enable/Disable. + * + * @return none + * + */ +void TIM_ReloadSyncCmd(TIM_ID_t timId, ControlState_t cmd); + +/** + * @brief TIM PWM synchronization software trigger Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * + * @return none + * + */ +void TIM_SyncSoftwareTrigger(TIM_ID_t timId); + +/** + * @brief TIM CNTINT update mode select Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] updateMode: update mode. + * + * @return none + * + */ +void TIM_CNTINTUpdateModeSelect(TIM_ID_t timId, TIM_RegUpdateMode_t updateMode); + +/** + * @brief TIM Output Software Control Register update mode select Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] updateMode: update mode. + * + * @return none + * + */ +void TIM_OSWCUpdateModeSelect(TIM_ID_t timId, TIM_RegUpdateMode_t updateMode); + +/** + * @brief Enable/Disable TIM CCV register update function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] channelId: Select channel id . + * @param[in] cmd: enable/disable. + * + * @return none + * + */ +void TIM_CCVUpdateCmd(TIM_ID_t timId, TIM_ChannelId_t channelId, ControlState_t cmd); + +/** + * @brief TIM Output Software Control Register update mode select Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] updateMode: update mode. + * + * @return none + * + */ +void TIM_ReloadParamConfig(TIM_ID_t timId, const TIM_ReloadConfig_t* reloadConfig); + +/** + * @brief TIM Set channel match reload cmd enable/disable Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] channelId: Select channel id . + * @param[in] cmd: enable/disable. + * + * @return none + * + */ +void TIM_ChannleMatchReloadCmd(TIM_ID_t timId, TIM_ChannelId_t channelId, + ControlState_t cmd); + +/** + * @brief TIM PWM Sync Configure Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] syncConfig: Pointer to sync configure struct. + * + * @return none + * + */ +void TIM_SyncConfig(TIM_ID_t timId, const TIM_PwmSyncConfig_t* syncConfig); + +/** + * @brief TIM INT DMA enable/disable Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] channelId: Selcct channel ID. + * @param[in] cmd: enable/disable. + * + * @return none + * + */ +void TIM_DMACtrl(TIM_ID_t timId, TIM_ChannelId_t channelId, ControlState_t cmd); + +/** + * @brief TIM INT mask/unmask Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] intType: Selcct interrupt type. + * @param[in] intMask: mask/unmask . + * + * @return none + * + */ +void TIM_IntMask(TIM_ID_t timId, TIM_INT_t intType, IntMask_t intMask); + +/** + * @brief TIM INT status clear Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] intType: Selcct interrupt type. + * + * @return none + * + */ +void TIM_IntClear(TIM_ID_t timId, TIM_INT_t intType); + +/** + * @brief TIM Get INT status Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] intType: Selcct interrupt type. + * + * @return intstatus + * + */ +IntStatus_t TIM_GetIntStatus(TIM_ID_t timId, TIM_INT_t intType); + +/** + * @brief TIM Get Fault detection flag status of fault channel Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] channelId: Selcct fault input channel:TIM_FAULT_CHANNEL_0,.. . + * + * @return intstatus + * + */ +IntStatus_t TIM_GetFaultStatus(TIM_ID_t timId, TIM_FaultChannelId_t channelId); + +/** + * @brief TIM fault status clear Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] intType: Selcct interrupt type. + * + * @return none + * + */ +void TIM_FaultStatusClear(TIM_ID_t timId, TIM_FaultChannelId_t channelId); + +/** + * @brief TIM match trigger clear Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * + * @return none + * + */ +void TIM_MatchTriggerClear(TIM_ID_t timId); + +/** + * @brief TIM INT mask/unmask Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] intType: Selcct interrupt type. + * @param[in] cbFun: callback function . + * + * @return none + * + */ +void TIM_InstallCallBackFunc(TIM_ID_t timId, TIM_INT_t intType, isr_cb_t * cbFun); + +/** @} end of group TIM_Public_FunctionDeclaration */ + +/** @} end of group TIM */ + +/** @} end of group Z20K11X_Peripheral_Driver */ +#endif /* Z20K11XM_TIM_H */ diff --git a/StdDriver/Inc/Z20K11xM_tmu.h b/StdDriver/Inc/Z20K11xM_tmu.h new file mode 100644 index 0000000..3743aa3 --- /dev/null +++ b/StdDriver/Inc/Z20K11xM_tmu.h @@ -0,0 +1,197 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_tmu.h + * @brief : TMU driver module header file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (C) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + * + **************************************************************************************************/ + +#ifndef Z20K11XM_TMU_H +#define Z20K11XM_TMU_H + +#include "Z20K11xM_drv.h" + +/** @addtogroup Z20K11X_Peripheral_Driver + * @{ + */ + +/** @addtogroup TMU + * @{ + */ + +/** @defgroup TMU_Public_Types + * @{ + */ + +/** + * @brief TMU ID type definition + */ +typedef enum +{ + TMU_MODULE_OUT0 = 0U, /*!< IO OUTPUT0 */ + TMU_MODULE_OUT1 = 1U, /*!< IO OUTPUT1 */ + TMU_MODULE_OUT2 = 2U, /*!< IO OUTPUT2 */ + TMU_MODULE_OUT3 = 3U, /*!< IO OUTPUT3 */ + TMU_MODULE_OUT4 = 4U, /*!< IO OUTPUT4 */ + TMU_MODULE_OUT5 = 5U, /*!< IO OUTPUT5 */ + TMU_MODULE_CMP_SAPMLE = 20U, /*!< CMP Sample */ + TMU_MODULE_CMP_EXT_EN = 21U, /*!< CMP external enable */ + TMU_MODULE_TIMER0_FAULT0 = 24U, /*!< Timer0 fault 0 */ + TMU_MODULE_TIMER0_FAULT1 = 25U, /*!< Timer0 fault 1 */ + TMU_MODULE_TIMER1_FAULT0 = 26U, /*!< Timer1 fault 0 */ + TMU_MODULE_TIMER1_FAULT1 = 27U, /*!< Timer1 fault 1 */ + TMU_MODULE_TIMER2_FAULT0 = 28U, /*!< Timer2 fault 0 */ + TMU_MODULE_TIMER2_FAULT1 = 29U, /*!< Timer2 fault 1 */ + TMU_MODULE_TDG0_TRIG_IN = 32U, /*!< TDG0 trig in */ + TMU_MODULE_STIM_TRIG_IN0 =36U, /*!< stim_trig_in[0] */ + TMU_MODULE_STIM_TRIG_IN1 =37U, /*!< stim_trig_in[1] */ + TMU_MODULE_STIM_TRIG_IN2 =38U, /*!< stim_trig_in[2] */ + TMU_MODULE_STIM_TRIG_IN3 =39U /*!< stim_trig_in[3] */ +}TMU_Module_t; +/** + * @brief TMU Input Select type definition + */ +typedef enum +{ + TMU_SOURCE_DISABLED = 0U, /*!< VSS */ + TMU_SOURCE_VDD = 1U, /*!< VDD */ + TMU_SOURCE_IN0 = 2U, /*!< TMU IN0 */ + TMU_SOURCE_IN1 = 3U, /*!< TMU IN1 */ + TMU_SOURCE_IN2 = 4U, /*!< TMU IN2 */ + TMU_SOURCE_IN3 = 5U, /*!< TMU IN3 */ + TMU_SOURCE_IN4 = 6U, /*!< TMU IN4 */ + TMU_SOURCE_IN5 = 7U, /*!< TMU IN5 */ + TMU_SOURCE_IN6 = 8U, /*!< TMU IN6 */ + TMU_SOURCE_IN7 = 9U, /*!< TMU IN7 */ + TMU_SOURCE_IN8 = 10U, /*!< TMU IN8 */ + TMU_SOURCE_IN9 = 11U, /*!< TMU IN9 */ + TMU_SOURCE_RTC_1Hz = 12U, /*!< RTC_1HZ_MUX_OUT */ + TMU_SOURCE_RTC_ALARM = 13U, /*!< RTC Alarm interrupt */ + TMU_SOURCE_STIM_OUT0 = 14U, /*!< stim_trig_out[0] */ + TMU_SOURCE_STIM_OUT1 = 15U, /*!< stim_trig_out[1] */ + TMU_SOURCE_STIM_OUT2 = 16U, /*!< stim_trig_out[2] */ + TMU_SOURCE_STIM_OUT3 = 17U, /*!< stim_trig_out[3] */ + TMU_SOURCE_TIMER0_MATCH = 18U, /*!< Timer0 Match Trigger */ + TMU_SOURCE_TIMER0_INITIAL = 19U, /*!< Timer0 Initialization Trigger */ + TMU_SOURCE_TIMER1_MATCH = 20U, /*!< Timer1 Match Trigger */ + TMU_SOURCE_TIMER1_INITIAL = 21U, /*!< Timer1 Initialization Trigger */ + TMU_SOURCE_TIMER2_MATCH = 22U, /*!< Timer2 Match Trigger */ + TMU_SOURCE_TIMER2_INITIAL = 23U, /*!< Timer2 Initialization Trigger */ + TMU_SOURCE_ADC0 = 26U, /*!< ADC0 COCO */ + TMU_SOURCE_CMP = 28U, /*!< CMP Cout */ + TMU_SOURCE_TDG0_CH0 = 30U, /*!< TDG0 channel 0 trigger out */ + TMU_SOURCE_TDG0_CH1 = 31U, /*!< TDG0 channel 1 trigger out */ + TMU_SOURCE_TDG0_CH2 = 32U, /*!< TDG0 channel 2 trigger out */ + TMU_SOURCE_TDG0_CH3 = 33U, /*!< TDG0 channel 3 trigger out */ + TMU_SOURCE_TDG0_CH4 = 34U, /*!< TDG0 channel 4 trigger out */ + TMU_SOURCE_TDG0_CH5 = 35U, /*!< TDG0 channel 5 trigger out */ + TMU_SOURCE_I2C0_RX = 38U, /*!< I2C0 Rx Data */ + TMU_SOURCE_I2C0_TX = 39U, /*!< I2C0 Tx Data */ +#if (2U == I2C_INSTANCE_NUM) + TMU_SOURCE_I2C1_RX = 40U, /*!< I2C1 Rx Data */ + TMU_SOURCE_I2C1_TX = 41U, /*!< I2C1 Tx Data */ +#endif + TMU_SOURCE_SPI0_RX = 44U, /*!< SPI0 Rx Data */ + TMU_SOURCE_SPI0_TX = 45U, /*!< SPI0 Tx Data */ + TMU_SOURCE_SPI1_RX = 46U, /*!< SPI1 Rx Data */ + TMU_SOURCE_SPI1_TX = 47U, /*!< SPI1 Tx Data */ +#if (3U == SPI_INSTANCE_NUM) + TMU_SOURCE_SPI2_RX = 48U, /*!< SPI2 Rx Data */ + TMU_SOURCE_SPI2_TX = 49U, /*!< SPI2 Tx Data */ +#endif + TMU_SOURCE_SCM_0 = 52U, /*!< SCM Trigger */ + TMU_SOURCE_SCM_1 = 53U, /*!< SCM Trigger */ + TMU_SOURCE_SCM_2 = 54U, /*!< SCM Trigger */ + TMU_SOURCE_SCM_3 = 55U, /*!< SCM Trigger */ + TMU_SOURCE_TIM0_CH0 = 56U, /*!< Timer0 Ch0 */ + TMU_SOURCE_TIM0_CH1 = 57U, /*!< Timer0 Ch1 */ + TMU_SOURCE_TIM1_CH0 = 58U, /*!< Timer1 Ch0 */ + TMU_SOURCE_TIM1_CH1 = 59U, /*!< Timer1 Ch1 */ + TMU_SOURCE_TIM2_CH0 = 60U, /*!< Timer2 Ch0 */ + TMU_SOURCE_TIM2_CH1 = 61U /*!< Timer2 Ch1 */ +}TMU_Source_t; + +/** @} end of group TMU_Public_Types*/ + +/** @defgroup TMU_Public_FunctionDeclaration + * @brief TMU functions statement + * @{ + */ + +/** + * @brief set source for TMU target module. + * + * @param[in] source: selects one of the TMU sources + * @param[in] module: selects target module of the TMU modules + * + * @return none + * + */ +void TMU_SetSourceForModule(TMU_Source_t source, TMU_Module_t module); + +/** + * @brief get source for TMU target module. + * + * @param[in] module: selects target module of the TMU modules + * + * @return the selected source for target module. + * + */ +TMU_Source_t TMU_GetSourceForModule(TMU_Module_t module); + +/** + * @brief Enable/Disable target module in TMU modules. + * + * @param[in] module: selects target module of the TMU modules + * @param[in] cmd: TMU Module Control: + * - ENABLE; + * - DISABLE; + * + * @return none + * + */ +void TMU_ModuleCmd(TMU_Module_t module, ControlState_t cmd); + +/** + * @brief Lock Relevant Register for TMU target module, then register is read only. + * + * @param[in] module: selects target module of the TMU modules + * + * @return none. + * + */ +void TMU_SetLockForModule(TMU_Module_t module); + +/** + * @brief Unlock Relevant Register for TMU target module, then register is writable. + * + * @param[in] module: selects target module of the TMU modules + * + * @return none. + * + */ +void TMU_SetUnlockForModule(TMU_Module_t module); + +/** + * @brief Get Lock status for TMU target module. + * + * @param[in] module: selects target module of the TMU modules + * + * @return Lock status: + * - SET----Locked; + * - RESET----Unlocked; + * + */ +FlagStatus_t TMU_GetLockStatusForModule(TMU_Module_t module); + +/** @} end of group TMU_Public_FunctionDeclaration */ + +/** @} end of group TMU */ + +/** @} end of group Z20K11X_Peripheral_Driver */ +#endif /* Z20K11XM_TMU_H */ diff --git a/StdDriver/Inc/Z20K11xM_uart.h b/StdDriver/Inc/Z20K11xM_uart.h new file mode 100644 index 0000000..81e717b --- /dev/null +++ b/StdDriver/Inc/Z20K11xM_uart.h @@ -0,0 +1,702 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_uart.h + * @brief : UART driver module header file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ + +#ifndef Z20K11XM_UART_H +#define Z20K11XM_UART_H + +#include "Z20K11xM_drv.h" + +/** @addtogroup Z20K11X_Peripheral_Driver + * @{ + */ + +/** @addtogroup UART + * @{ + */ + +/** @defgroup UART_Public_Types + * @{ + */ + +/** + * @brief UART ID type definition + */ +typedef enum +{ + UART0_ID = 0U, /*!< UART0 */ + UART1_ID, /*!< UART1 */ + UART2_ID, /*!< UART2 */ +#if (4U == UART_INSTANCE_NUM) + UART3_ID, /*!< UART3 */ +#endif +} UART_ID_t; + +/** + * @brief UART mode type definition + */ +typedef enum +{ + UART_MODE_UART = 0U, /*!< UART mode */ + UART_MODE_LIN, /*!< LIN mode */ +} UART_Mode_t; + +/** + * @brief UART parity type definition + */ +typedef enum +{ + UART_PARITY_NONE = 0U, /*!< UART parity none */ + UART_PARITY_ODD, /*!< UART parity odd */ + UART_PARITY_EVEN /*!< UART parity even */ +} UART_Parity_t; + +/** + * @brief UART data bits type definition + */ +typedef enum +{ + UART_DATABITS_5 = 0U, /*!< UART data bits length: 5 bits */ + UART_DATABITS_6, /*!< UART data bits length: 6 bits */ + UART_DATABITS_7, /*!< UART data bits length: 7 bits */ + UART_DATABITS_8, /*!< UART data bits length: 8 bits */ + UART_DATABITS_9 /*!< UART data bits length: 9 bits */ +} UART_DataBits_t; + +/** + * @brief UART stop bits type definition + */ +typedef enum +{ + UART_STOPBITS_1 = 0U, /*!< UART stop bits length: 1 bit */ + UART_STOPBITS_1P5_2 /*!< UART stop bits length: 1.5/2 bits */ +} UART_StopBits_t; + +/** + * @brief UART TX FIFO level type definition + */ +typedef enum +{ + UART_TX_FIFO_EMPTY = 0U, /*!< UART FIFO empty */ + UART_TX_FIFO_CHAR_2, /*!< UART 2 characters in the FIFO */ + UART_TX_FIFO_QUARTER, /*!< UART FIFO 1/4 full */ + UART_TX_FIFO_HALF /*!< UART FIFO 1/2 full */ +} UART_TxFIFOLvl_t; + +/** + * @brief UART RX FIFO level type definition + */ +typedef enum +{ + UART_RX_FIFO_CHAR_1 = 0U, /*!< UART 1 character in the FIFO */ + UART_RX_FIFO_QUARTER, /*!< UART 1/4 full*/ + UART_RX_FIFO_HALF, /*!< UART 1/2 full */ + UART_RX_FIFO_LESS_2 /*!< UART FIFO 2 less than full */ +} UART_RxFIFOLvl_t; + +/** + * @brief UART IDLE detect length type definition + */ +typedef enum +{ + UART_IDLE_DETECT_LENGTH_1 = 0U, /*!< UART idle detection length: + 1-bit character */ + UART_IDLE_DETECT_LENGTH_2, /*!< UART idle detection length: + 2-bit characters */ + UART_IDLE_DETECT_LENGTH_4, /*!< UART idle detection length: + 4-bit characters */ + UART_IDLE_DETECT_LENGTH_8, /*!< UART idle detection length: + 8-bit characters */ + UART_IDLE_DETECT_LENGTH_16, /*!< UART idle detection length: + 16-bit characters */ + UART_IDLE_DETECT_LENGTH_32, /*!< UART idle detection length: + 32-bit characters */ + UART_IDLE_DETECT_LENGTH_64, /*!< UART idle detection length: + 64-bit characters */ + UART_IDLE_DETECT_LENGTH_128 /*!< UART idle detection length: + 128-bit characters */ +} UART_IdleDetectLength_t; + +/** + * @brief UART Line status bit type definition + */ +typedef enum +{ + UART_LINESTA_DR = 0U, /*!< Data ready */ + UART_LINESTA_OE, /*!< Overrun error */ + UART_LINESTA_PE, /*!< Parity error */ + UART_LINESTA_FE, /*!< Framing Error */ + UART_LINESTA_BI, /*!< Break interrupt */ + UART_LINESTA_THRE, /*!< Transmit holding register empty */ + UART_LINESTA_TEMT, /*!< Transmit empty */ + UART_LINESTA_RFE, /*!< RCV FIFO error */ + UART_LINESTA_TRANS_ERR, /*!< Indicate whether any of 'OE','PE', + 'FE','BI' and 'RFE' happens */ + UART_LINESTA_ADDR_RCVD, /*!< Address receive */ + UART_LINESTA_ASYNC, /*!< STOP WAKE UP: async interrupt status*/ + UART_LINESTA_FIELD_ERR, /*!< LIN: sync field error */ + UART_LINESTA_PID_ERR, /*!< LIN: PID error */ + UART_LINESTA_CHECKSUM_ERR, /*!< LIN: checksum error */ + UART_LINESTA_TO_ERR, /*!< time out error in LIN mode*/ + UART_LINESTA_HEADER_DONE, /*!< header done in LIN mode*/ + UART_LINESTA_RSP_DONE /*!< response done in LIN mode*/ +} UART_LineStatus_t; + +/** + * @brief UART interrupt type definition + */ +typedef enum +{ + UART_INT_RBFI = 0U, /*!< Received data available interrupt.*/ + UART_INT_TBEI, /*!< Transmit holding register empty interrupt */ + UART_INT_LSI, /*!< RX line status interrupt*/ + UART_INT_BYDET, /*!< Busy detect interrupt, cannot be masked */ + UART_INT_RCVRTO, /*!< Character timeout interrupt, it is + effective only when enable the fifo */ + UART_INT_HEADER_DONE, /*!< Only LIN can generate header done interrupt */ + UART_INT_RSP_DONE, /*!< Only LIN can generate response done interrupt */ + UART_INT_ASYNC, /*!< Stop mode wake up: Async interrupt*/ + UART_INT_ALL /*!< All the interrupt */ +} UART_Int_t; + + +/** + * @brief UART LIN mode type definition + */ +typedef enum +{ + UART_LIN_SLAVE = 0U, /*!< work as a LIN slave */ + UART_LIN_MASTER, /*!< work as a LIN master */ +} UART_LinMode_t; + +/** + * @brief UART LIN checksum type definition + */ +typedef enum +{ + UART_LIN_CHECKSUM_CLASSIC = 0U, /*!< classic checksum */ + UART_LIN_CHECKSUM_ENHANCED, /*!< enhanced checksum */ +} UART_LinCheckSum_t; + + +/** + * @brief UART Configuration Structure type definition + */ +typedef struct +{ + uint32_t baudRate; /*!< baud rate */ + UART_DataBits_t dataBits; /*!< Data size, 5/6/7/8/9 bits */ + UART_Parity_t parity; /*!< Parity Enable */ + UART_StopBits_t stopBits; /*!< Number of stop bits */ + ControlState_t autoFlowControl; /*!< Auto flow control enable */ + uint32_t oscFreq; /*!< the frequency of the OSC clock source */ +} UART_Config_t; + +/** + * @brief UART FIFO Configuration Structure type definition + */ +typedef struct +{ + ControlState_t fifoEnable; /*!< Enable/disable FIFO function*/ + ControlState_t txFifoReset; /*!< Reset tx FIFO */ + ControlState_t rxFifoReset; /*!< Reset rx FIFO */ + UART_TxFIFOLvl_t fifoTet; /*!< Set TX Empty trigger level */ + UART_RxFIFOLvl_t fifoRt; /*!< Set RCVR trigger level */ +} UART_FIFOConfig_t; + +/** + * @brief UART idle detect Structure type definition + */ +typedef struct +{ + ControlState_t Cmd; /*!< Enable/disable idle detect*/ + UART_IdleDetectLength_t len; /*!< Set idle detect length */ +} UART_IdleDetectConfig_t; + +/** + * @brief UART LIN Configuration Structure type definition + */ +typedef struct +{ + uint32_t baudRate; /*!< baud rate */ + uint32_t oscFreq; /*!< the frequency of the OSC clock source */ + UART_LinMode_t mode; /*!< LIN mode */ + ControlState_t autoSyncEn; /*!< auto sync enable flag, if is set to + ENABLE, it will detect the baudrate + through the sync part of header and set + the baudrate automatically */ +} UART_LinConfig_t; + +/** + * @brief UART LIN header Structure type definition + */ +typedef struct +{ + uint32_t id; /*!< 6-bit ID */ + uint32_t breakLen; /*!< break field length */ + uint32_t deleLen; /*!< delemiter length */ +} UART_LinHeader_t; + +/** + * @brief UART LIN response Structure type definition + */ +typedef struct +{ + UART_LinCheckSum_t checkType; /*!< checksum type */ + uint32_t len; /*!< response length exclude checksum */ + uint8_t data[8]; /*!< the response payload exclude checksum*/ +} UART_LinResponse_t; + +/** @}end of group UART_Public_Types */ + +/** @defgroup UART_Public_Constants + * @{ + */ + +/** @}end of group UART_Public_Constants */ + +/** @defgroup UART_Public_Macro + * @{ + */ + +#define UART_INT_NUM 8U + +/** @}end of group UART_Public_Macro */ + +/** @defgroup UART_Public_FunctionDeclaration + * @brief UART functions declaration + * @{ + */ + +/** + * @brief Default initializes the UART. The OSC40M clock frequency is 40MHz. + * baudrate:115200, no parity, 8 date bits, 1 stop bit, + * disable autoflow. + * + * @param[in] uartId: Select the UART port. + * + * @return none + * + */ +void UART_DefaultInit(UART_ID_t uartId); + +/** + * @brief Initializes the UART + * @param[in] uartId: Select the UART port. + * @param[in] uartCfg: Pointer to a UART configuration structure + * @return none + */ +void UART_Init(UART_ID_t uartId, const UART_Config_t* uartCfg); + +/** + * @brief Wait for UART busy bit clear. + * + * @param[in] uartId: UART peripheral selected. + * @param[in] cycle: The software cycles to be waited. User decides how many + * cycles need to be waited. + * + * @return ResultStatus_t + * - SUCC: busy bit is cleared + * - ERR: UART is still busy + * + */ +ResultStatus_t UART_WaitBusyClear(UART_ID_t uartId, uint32_t cycle); + +/** + * @brief Set UART rts enable + * + * @param[in] uartId: UART peripheral selected. + * @param[in] newState: Enable/Disable function state + * + * @return none + * + */ +void UART_RtsEnable(UART_ID_t uartId, ControlState_t newState); + +/** + * @brief Reset uart receive fifo + * @param[in] uartId: Select the UART port. + * @return none + */ +void UART_ResetRxFifo(UART_ID_t uartId); + +/** + * @brief Reset uart transmit fifo + * @param[in] uartId: Select the UART port. + * @return none + */ +void UART_ResetTxFifo(UART_ID_t uartId); + +/** + * @brief Enable/Disable debug mode. If enabled, hardware will not clean + * the recevier fifo automaticlly + * + * @param[in] uartId: Select the UART port. + * + * @param[in] Cmd: ENABLE/DISABLE + * + * @return none + * + */ +void UART_DebugCmd(UART_ID_t uartId, ControlState_t Cmd); + +/** + * @brief Idle detect config + * + * @param[in] uartId: Select the UART port. + * + * @param[in] config: config idle detect + * + * @return none + * + */ +void UART_IdleDetectConfig(UART_ID_t uartId,UART_IdleDetectConfig_t *config); + +/** + * @brief Send break function, user can choose the length of break, + * the length should not be less than eleven + * + * @param[in] uartId: UART peripheral selected. + * @param[in] len: the length of break + * + * @return + * - SUCC : break is sent + * - ERR : break length is invalid + * + */ +ResultStatus_t UART_SendBreak(UART_ID_t uartId, uint8_t len); + +/** + * @brief Set UART loopback mode + * @param[in] uartId: UART peripheral selected. + * @param[in] newState: Enable/Disable function state + * @return none + */ +void UART_SetLoopBackMode(UART_ID_t uartId, ControlState_t newState); + +/** + * @brief Receive one byte data from the UART peripheral + * @param[in] uartId: Select the UART port. + * @return The received data + */ +uint8_t UART_ReceiveByte(UART_ID_t uartId); + +/** + * @brief Read received bytes from the RX FIFO + * @param[in] uartId: Select the UART port. + * @param[in] length: the number of bytes to be read. When call this function, + * the user needs to make sure that the "length" is not + * greater than the number of bytes that is available in + * RX FIFO + * @param[out] data: points to the memory where the data to be stored + *. + * @return The received data + */ +void UART_ReceiveBytes(UART_ID_t uartId,uint32_t length, uint8_t data[]); + +/** + * @brief Empty the RX FIFO. This function reads received data until RX + * FIFO is empty + * @param[in] uartId: Select the UART port. + * + * @return None + */ +void UART_EmptyRxFifo(UART_ID_t uartId); + +/** + * @brief Send one byte data to the UART peripheral + * @param[in] uartId: Select the UART port. + * @param[in] data: The data to be sent + * @return none + */ +void UART_SendByte(UART_ID_t uartId, uint8_t data); + +/** + * @brief Config UART FIFO function + * @param[in] uartId: Select the UART port. + * @param[in] fifoCfg: Pointer toFIFO configuration + * @return none + */ +void UART_FIFOConfig(UART_ID_t uartId, const UART_FIFOConfig_t* fifoCfg); + +/** + * @brief Get current value of Line Status register + * + * @param[in] uartId: Select the UART port. + * @param[in] lineStatus: + * - UART_LINESTA_DR + * - UART_LINESTA_OE + * - UART_LINESTA_PE + * - UART_LINESTA_FE + * - UART_LINESTA_BI + * - UART_LINESTA_THRE + * - UART_LINESTA_TEMT + * - UART_LINESTA_RFE + * - UART_LINESTA_TRANS_ERR + * - UART_LINESTA_ADDR_RCVD + * - UART_LINESTA_ASYNC + * - UART_LINESTA_FIELD_ERR + * - UART_LINESTA_PID_ERR + * - UART_LINESTA_CHECKSUM_ERR + * - UART_LINESTA_TO_ERR + * - UART_LINESTA_HEADER_DONE + * - UART_LINESTA_RSP_DONE + * + * @note This function returns only one line status. However, once call + * this function, all line status will be cleared. If user + * needs to read more than one line status, it is suggested to use + * UART_GetAllLineStatus() to get all line status and handle them + * one by one. + * @return The state value of UART Line Status register + * + */ +FlagStatus_t UART_GetLineStatus(UART_ID_t uartId, UART_LineStatus_t lineStatus); + +/** + * @brief Get all Line Status + * + * @param[in] uartId: Select the UART port. + * + * @note Once call the function, line status will be cleared + * + * @return The state value of UART Line Status register + * + */ +uint32_t UART_GetAllLineStatus(UART_ID_t uartId); + +/** + * @brief Get busy status + * + * @param[in] uartId: Select the UART port. + * + * @return The busy Status + * + */ +FlagStatus_t UART_GetBusyStatus(UART_ID_t uartId); + +/** + * @brief Get current UART interrupt status except async status + * + * @param[in] uartId: Select the UART port. + * @param[in] intType: select interrupt + * + * @note If user needs to get async status, user can use UART_GetLineStatus + * function. + * + * @return The state value of UART Status register + */ +IntStatus_t UART_GetIntStatus(UART_ID_t uartId, UART_Int_t intType); + +/** + * @brief Install call back function for interrupts + * + * @param[in] uartId: Select the UART port. + * @param[in] intType: select the interrupt + * @param[in] cbFun: pointer to callback function + * + * @return none + */ +void UART_InstallCallBackFunc(UART_ID_t uartId, UART_Int_t intType, + isr_cb_t * cbFun); + +/** + * @brief Get line status buffer in interrupt call back functions. The line + * status will be stored into line status buffer in UART_IRQHandler. + * If the call back functions which are installed through + * UART_InstallCallBackFunc() needs to get the line status, please + * use this function instead of UART_GetAllLineStatus or + * UART_GetLineStatus. + * + * @param[in] uartId: Select the UART port. + * + * @return linestatus + * + */ +uint32_t UART_GetLineStatusBufForCbf(UART_ID_t uartId); + +/** + * @brief Mask/Unmask the UART interrupt + * UART_INT_RCVRTO and UART_INT_RBFI are controlled by the same bit, + * so they are masked/unmasked at the same time. But UART_INT_RCVRTO + * is only generated when it in fifo mode and fifo is enabled + * @param[in] uartId: Select the UART port. + * @param[in] intType: Specifies the interrupt type + * @param[in] intMask: Enable/Disable Specified interrupt type + * @return none + */ +void UART_IntMask(UART_ID_t uartId, UART_Int_t intType, IntMask_t intMask); + +/** + * @brief get UART FIFO status + * @param[in] uartId: Select the UART port. + * @return status + */ +ControlState_t UART_GetfifoStatus(UART_ID_t uartId); + +/** + * @brief Set receive 9 bits data mode 0 + * @param[in] uartId: Select the UART port. + * @return none + */ +void UART_9BitsM0Rx(UART_ID_t uartId); + +/** + * @brief Program the address of receive 9 bits data, mode 1 + * @param[in] uartId: Select the UART port. + * @return none + */ +void UART_9BitsM1SetAddr(UART_ID_t uartId, uint8_t addr); + +/** + * @brief Select 9 bits hardware receive mode 1 + * @param[in] uartId: Select the UART port. + * @return none + */ +void UART_9BitsHWRecvEnable(UART_ID_t uartId); + +/** + * @brief Receive address from the UART peripheral, mode 1 + * @param[in] uartId: Select the UART port. + * @return the received address + */ +uint16_t UART_9BitsM1RxAddr(UART_ID_t uartId); + +/** + * @brief Receive one byte data from the UART peripheral, mode 1 + * @param[in] uartId: Select the UART port. + * @return The received data + */ +uint16_t UART_9BitsM1RxData(UART_ID_t uartId); + +/** + * @brief Program the transmit target address, 9bits, mode 0 + * @param[in] uartId: Select the UART port. + * @param[in] addr: program the address + * @return none + */ +void UART_9BitsM0SetAddr(UART_ID_t uartId, uint8_t addr); + +/** + * @brief Set send address bit, mode 0 + * @param[in] uartId: Select the UART port. + * @return none + */ +void UART_9BitsM0SendAddr(UART_ID_t uartId); + +/** + * @brief Send 9 bits data to the UART peripheral, mode 1 + * @param[in] uartId: Select the UART port. + * @param[in] data: The data to be send + * @return none + */ +void UART_9BitsM1TxData(UART_ID_t uartId, uint16_t data); + +/** + * @brief Config UART in LIN mode + * @param[in] uartId: Select the UART port. + * @param[in] config: points to the configuration of LIN mode + * @return none + */ +void UART_LinConfig(UART_ID_t uartId, const UART_LinConfig_t *config); + +/** + * @brief Set UART in LIN mode as a LIN master and start to send the header + * @param[in] uartId: Select the UART port. + * @param[in] header: points to the header to be sent + * @return status + * - SUCC : header is sent + * - ERR : header is not sent due to UART is busy + */ +ResultStatus_t UART_LinSendHeader(UART_ID_t uartId, + const UART_LinHeader_t *header); + +/** + * @brief This function stops receiving/sending header/response of LIN. + * + * @param[in] uartId: Select the UART port. + * + * @return none + */ +void UART_LinStopTransmission(UART_ID_t uartId); + +/** + * @brief If LIN is sending/receiving header/response + * this function returns SET, otherwise, return RESET. + * + * @param[in] uartId: Select the UART port. + * + * @return SET/RESET + */ +FlagStatus_t UART_LinGetTransmissionStatus(UART_ID_t uartId); + +/** + * @brief Set UART in LIN mode as a LIN slave and start to receive a header. + * FIFO is disabled before it starts to receive a header + * + * @param[in] uartId: Select the UART port. + * @return + * - SUCC : it starts to receive header + * - ERR : it dose not start to receive header due to UART is busy + */ +ResultStatus_t UART_LinStartReceiveHeader(UART_ID_t uartId); + +/** + * @brief Read the 6-bit ID(exclude parity bits) of header + * @param[in] uartId: Select the UART port. + * @return ID + */ +uint32_t UART_LinGetId(UART_ID_t uartId); + +/** + * @brief start to send a response + * @param[in] uartId: Select the UART port. + * @param[in] rsp: Points to reponse structure to be sent. + * @return + * - SUCC : response is sent + * - ERR : resoponse is not sent due to UART is busy + */ +ResultStatus_t UART_LinSendResponse(UART_ID_t uartId, + const UART_LinResponse_t *rsp); + +/** + * @brief Start to receive a response + * @param[in] uartId: Select the UART port. + * + * @param[in] check: Checksum type. + * @param[in] len: Response length, the maximun value is 8 bytes in a frame. + * @return + * - SUCC : it starts to receive response + * - ERR : it dose not start to receive response due to UART is busy + */ +ResultStatus_t UART_LinStartReceiveResponse(UART_ID_t uartId, + UART_LinCheckSum_t check, + uint32_t len); + +/** + * @brief read a response. if a reponse is received, this function can be + * called to get the data of response. This function is called + * after UART_LinStartReceiveResponse() and UART_INTSTA_RSP_DONE + * status is set. + * @param[in] uartId: Select the UART port. + * @param[in] len: response length to be read. + * @param[out] data: points to the memory where the response data to be stored. + * the memory size must not be smaller than len + * @return none + */ +void UART_LinReadResponse(UART_ID_t uartId, uint32_t len, uint8_t data[]); + +/** @}end of group UART_Public_FunctionDeclaration */ + +/** @}end of group UART */ + +/** @}end of group Z20K11X_Peripheral_Driver */ + +#endif /* Z20K11XM_UART_H */ diff --git a/StdDriver/Inc/Z20K11xM_wdog.h b/StdDriver/Inc/Z20K11xM_wdog.h new file mode 100644 index 0000000..14027d0 --- /dev/null +++ b/StdDriver/Inc/Z20K11xM_wdog.h @@ -0,0 +1,426 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_wdog.h + * @brief : WDOG driver module header file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ +#ifndef Z20K11XM_WDOG_H +#define Z20K11XM_WDOG_H + +#include "Z20K11xM_drv.h" + +/** @addtogroup Z20K11X_Peripheral_Driver + * @{ + */ + +/** @addtogroup WDOG + * @{ + */ + +/** @defgroup WDOG_Public_Types + * @{ + */ + +/*! @brief WDOG clock source type definition + * Implements : WDOG_Clk_Source_t_Class + */ +typedef enum +{ + WDOG_LPO_CLOCK = 0U, /*!< LPO clock */ + WDOG_BUS_CLOCK, /*!< Bus clock */ + WDOG_FIRC_CLOCK, /*!< FIRC clock */ + WDOG_OSC_CLOCK /*!< OSC clock */ +} WDOG_ClkSource_t; + +/*! @brief WDOG test mode type definition + * Implements : WDOG_Test_Mode_t_Class + */ +typedef enum +{ + WDOG_TST_MODE0 = 0U, /*!< Test mode 0 */ + WDOG_TST_MODE1, /*!< User mode 1 */ + WDOG_TST_MODE2, /*!< Test mode 2 */ + WDOG_TST_MODE3, /*!< Test mode 2 */ + WDOG_TST_NORMAL /*!< normal mode */ +} WDOG_TestMode_t; + +/*! + * @brief WDOG operate mode configuration structure. + * + * This structure configures the wdog operation mode. + * Implements : WDOG_OperationMode_t_Class + */ +typedef struct +{ + ControlState_t wait; /*!< Wait mode */ + ControlState_t stop; /*!< Stop mode */ + ControlState_t debug; /*!< Debug mode */ +} WDOG_OperationMode_t; + +/*! + * @brief WDOG configuration structure. + * + * This structure configures the basic attribute. + * Implements : WDOG_Config_t_Class + */ +typedef struct +{ + ControlState_t winEnable; /*!< window mode control + - ENABLE: enable window mode + - DISABLE: disable window mode */ + ControlState_t wait; /*!< wait mode control + - ENABLE: counter countinue + - DISABLE: counter halt */ + ControlState_t stop; /*!< stop mode control + - ENABLE: counter countinue + - DISABLE: counter halt */ + ControlState_t debug; /*!< debug mode control + - ENABLE: counter countinue + - DISABLE: counter halt */ + uint32_t windowValue; /*!< The window value: 32 bits */ + uint32_t timeoutValue; /*!< The timeout value: 32 bits */ + WDOG_ClkSource_t clkSource; /*!< The clock source of the WDOG */ + WDOG_TestMode_t testMode; /*!< test mode */ +} WDOG_Config_t; + +/** + * @brief WDOG interrupt type definition + */ +typedef enum +{ + WDOG_INT_BEFORERESET = 0U, /*!< wdog interrupt before reset */ + WDOG_INT_ALL +} WDOG_INT_t; + +/** @} end of group WDOG_Public_Types */ + +/** @defgroup WDOG_Public_Constants + * @{ + */ + +/** @} end of group WDOG_Public_Constants */ + +/** @defgroup WDOG_Public_Macro + * @{ + */ + +/** @} end of group WDOG_Public_Macro */ + +/** @defgroup WDOG_Public_FunctionDeclaration + * @brief WDOG functions declaration + * @{ + */ + +/** + * @brief wdog Initializes Function + * + * @param[in] ptWDOGInitConfig: Pointer to a WDOG configuration structure. + * + * @note If user has no need to enable irq, in next step user should + * disable_irq after calling this function. + * + * @return Initializes operate flag + * + */ +ResultStatus_t WDOG_Init(const WDOG_Config_t *ptWDOGInitConfig); + +/** + * @brief enable wdog count Function + * + * @param[in] none + * + * @note If user has no need to enable irq, in next step user should + * disable_irq after calling this function. + * + * @return operation status. + * + */ +ResultStatus_t WDOG_Enable(void); + +/** + * @brief disable wdog count Function + * + * @param[in] none + * + * @note If user has no need to enable irq, in next step user should + * disable_irq after calling this function. + * + * @return operation status. + * + */ +ResultStatus_t WDOG_Disable(void); + +/** + * @brief refresh wdog count Function + * + * @param[in] none + * + * @note If user has no need to enable irq, in next step user should + * disable_irq after calling this function. + * + * @return none. + * + */ +void WDOG_Refresh(void); + +/** + * @brief get wdog config allow flag status Function + * + * @param[in] none + * + * @return busy status. + * + */ +FlagStatus_t WDOG_GetConfigAllowStatus(void); + +/** + * @brief set wdog config allow flag Function + * + * @param[in] allow: config update control + * - ENABLE: enable config update + * - DISABLE: disbale config update + * + * @note If user has no need to enable irq, in next step user should + * disable_irq after calling this function. + * + * @return operation status. + * + */ +ResultStatus_t WDOG_ConfigAllowControl(ControlState_t allow); + +/** + * @brief enable/disbale wdog window mode Function + * + * @param[in] winEnable: window mode control + * - ENABLE: enable window mode + * - DISABLE: disbale window mode + * + * @note If user has no need to enable irq, in next step user should + * disable_irq after calling this function. + * + * @return operation status. + * + */ +ResultStatus_t WDOG_WindowModeControl(ControlState_t winEnable); + +/** + * @brief set wdog window value Function + * + * @param[in] windowValue: window value, 32 bits + * + * @note If user has no need to enable irq, in next step user should + * disable_irq after calling this function. + * + * @return operation status. + * + */ +ResultStatus_t WDOG_SetWindowValue(uint32_t windowValue); + +/** + * @brief get wdog window register value Function + * + * @param[in] none + * + * @return window register value. + * + */ +uint32_t WDOG_GetWindowValue(void); + +/** + * @brief set wdog clock source Function + * + * @param[in] clkSource: clock source + * + * @note If user has no need to enable irq, in next step user should + * disable_irq after calling this function. + * + * @return operation status. + * + */ +ResultStatus_t WDOG_SetClockSource(WDOG_ClkSource_t clkSource); + +/** + * @brief set wdog timeout value Function + * + * @param[in] timeoutValue: timeout value, 32 bits + * + * @note If user has no need to enable irq, in next step user should + * disable_irq after calling this function. + * + * @return operation status. + * + */ +ResultStatus_t WDOG_SetTimeoutValue(uint32_t timeoutValue); + +/** + * @brief get wdog timeout register value Function + * + * @param[in] none + * + * @return timeout register value. + * + */ +uint32_t WDOG_GetTimeoutValue(void); + +/** + * @brief configure wdog behavior in stop mode Function + * + * @param[in] cmd: stop mode control + * - ENABLE: counter continue in stop mode + * - DISABLE: counter halt in stop mode + * + * @note If user has no need to enable irq, in next step user should + * disable_irq after calling this function. + * + * @return operation status. + * + */ +ResultStatus_t WDOG_StopModeControl(ControlState_t cmd); + +/** + * @brief configure wdog behavior in wait mode Function + * + * @param[in] cmd: wait mode control + * - ENABLE: counter continue in wait mode + * - DISABLE: counter halt in wait mode + * + * @note If user has no need to enable irq, in next step user should + * disable_irq after calling this function. + * + * @return operation status. + * + */ +ResultStatus_t WDOG_WaitModeControl(ControlState_t cmd); + +/** + * @brief configure wdog behavior in debug mode Function + * + * @param[in] cmd: debug mode control + * - ENABLE: counter continue in debug mode + * - DISABLE: counter halt in debug mode + * + * @return operation status. + * + */ +ResultStatus_t WDOG_DebugModeControl(ControlState_t cmd); + +/** + * @brief set wdog test mode Function + * + * @param[in] testMode: test/normal mode + * + * @note If user has no need to enable irq, in next step user should + * disable_irq after calling this function. + * + * @return operation status. + * + */ +ResultStatus_t WDOG_SetTestMode(WDOG_TestMode_t testMode); + +/** + * @brief get wdog test/normal mode Function + * + * @param[in] none + * + * @return test/normal mode. + * + */ +WDOG_TestMode_t WDOG_GetTestMode(void); + +/** + * @brief get wdog free-running counter Function + * + * @param[in] none + * + * @return free-running counter value. + * + */ +uint32_t WDOG_GetCounter(void); + +/** + * @brief get flag indcates configuration update is completed Function + * + * @param[in] none + * + * @return configuration update completed status. + * + */ +FlagStatus_t WDOG_GetConfigCompletedStatus(void); + +/** + * @brief get Flag indcates all registers are locked or unlocked Function + * + * @param[in] none + * + * @return lock Flag. + * + */ +FlagStatus_t WDOG_GetLockStatus(void); + +/** + * @brief get WDOG int flag Function + * + * @param[in] intType: int type + * - WDOG_INT_BEFORERESET: int befor reset + * - WDOG_INT_ALL: all int type + * + * @return whether a int is asserted or not. + * + */ +IntStatus_t WDOG_GetIntStatus(WDOG_INT_t intType); + +/** + * @brief clear wdog int flag Function + * + * @param[in] intType: int type + * - WDOG_INT_BEFORERESET: int befor reset + * - WDOG_INT_ALL: all int type + * + * @note If user has no need to enable irq, in next step user should + * disable_irq after calling this function. + * + * @return operation status. + * + */ +ResultStatus_t WDOG_ClearIntStatus(WDOG_INT_t intType); + +/** + * @brief set wdog int mask Function + * + * @param[in] intType: int type + * - WDOG_INT_BEFORERESET: int befor reset + * - WDOG_INT_ALL: all int type + * @param[in] intMask: int mask + * + * @note If user has no need to enable irq, in next step user should + * disable_irq after calling this function. + * + * @return operation status. + * + */ +ResultStatus_t WDOG_IntMask(WDOG_INT_t intType, IntMask_t intMask); + +/** + * @brief Install callback function + * + * @param[in] intType: select interrrupt type + * - WDOG_INT_BEFORERESET: int befor reset + * @param[in] cbFun: indicate callback function + * + * @return none + * + */ +void WDOG_InstallCallBackFunc(WDOG_INT_t intType, isr_cb_t *cbFun); + +/** @} end of group WDOG_Public_FunctionDeclaration */ + +/** @} end of group WDOG */ + +/** @} end of group Z20K11X_Peripheral_Driver */ + +#endif /* Z20K11XM_WDOG_H */ diff --git a/StdDriver/Src/Z20K11xM_adc.c b/StdDriver/Src/Z20K11xM_adc.c new file mode 100644 index 0000000..621f917 --- /dev/null +++ b/StdDriver/Src/Z20K11xM_adc.c @@ -0,0 +1,684 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_adc.c + * @brief : ADC module driver file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ + +#include "Z20K11xM_adc.h" + +/** @addtogroup Z20K11X_Peripheral_Driver + * @{ + */ + +/** @defgroup ADC ADC + * @brief ADC driver modules + * @{ + */ + +/** @defgroup ADC_Private_Type + * @{ + */ + +/*@} end of group ADC_Private_Type*/ + +/** @defgroup ADC_Private_Defines + * @{ + */ + +#define ADC_NUM 0x1U + +/** @} end of group ADC_Private_Defines */ + +/** @defgroup ADC_Private_Variables + * @{ + */ + + /** + * @brief ADC interrupt ID definition + */ +static const uint32_t ADC_IntStatusTable[] = +{ + 0x00000001U, /*!< ADC_FWM_INT */ + 0x00000002U, /*!< ADC_FOF_INT */ + 0x00000004U, /*!< ADC_TCOMP_INT */ + 0x00000008U, /*!< ADC_CMP_INT */ + 0x00000200U, /*!< ADC_ERR_INT */ + 0x0000020FU /*!< ADC_INT_ALL */ +}; + +static uint32_t adcIntMaskStatus = 0U; + +/** + * @brief ADC0 address array + */ + /*PRQA S 0303,0306 ++*/ +static adc_reg_t * const adcRegPtr[ADC_NUM] = +{ + (adc_reg_t *)ADC0_BASE_ADDR +}; + +static adc_reg_w_t * const adcRegWPtr[ADC_NUM] = +{ + (adc_reg_w_t *)ADC0_BASE_ADDR +}; +/*PRQA S 0303,0306 --*/ + +/** + * @brief ADC ISR callback function pointer array + */ +static isr_cb_t * adcIsrCbFunc[ADC_NUM][ADC_INT_ALL] = +{ + {NULL,NULL,NULL,NULL,NULL} +}; + +/** @} end of group ADC_Private_Variables */ + +/** @defgroup ADC_Global_Variables + * @{ + */ + +/** @} end of group ADC_Global_Variables */ + +/** @defgroup ADC_Private_FunctionDeclaration + * @{ + */ +void ADC0_DriverIRQHandler(void); +static void ADC_IntHandler(ADC_ID_t adcId); +/** @} end of group ADC_Private_FunctionDeclaration */ + +/** @defgroup ADC_Private_Functions + * @{ + */ +/** + * @brief ADC interrupt handle + * @param[in] adcId: Select the ADC ID: ADC0_ID,.... + * + * @return none + * + */ +static void ADC_IntHandler(ADC_ID_t adcId) +{ + uint32_t intStatus; + + adc_reg_t * ADCx = (adc_reg_t *)(adcRegPtr[adcId]); + adc_reg_w_t * ADCWx = (adc_reg_w_t *) (adcRegWPtr[adcId]); + + /* get interrupt status */ + intStatus = ADCWx->ADC_STAT; + /* only check enabled interrupts */ + intStatus = intStatus & adcIntMaskStatus; + /* clear interrupt status */ + ADCWx->ADC_STAT = intStatus; + + /* FIFO Watermark Interrupt */ + if((intStatus & ADC_IntStatusTable[ADC_FWM_INT]) != 0U) + { + if(adcIsrCbFunc[adcId][ADC_FWM_INT] != NULL) + { + /* Check fifo ready flag, it represents the FIFO holding data above + * watermark level. This is a workaround for Errata ADC.1, please + * refer to Errata doc for more information. + */ + if(ADCx->ADC_STAT.RDY == 1U) + { + /* call the callback function */ + adcIsrCbFunc[adcId][ADC_FWM_INT](); + } + } + /* Disable the interrupt if callback function is not setup */ + else + { + ADCx->ADC_IE.FWM_IE = 0U; + } + } + + /* FIFO Overflow Interrupt */ + if((intStatus & ADC_IntStatusTable[ADC_FOF_INT]) != 0U) + { + if(adcIsrCbFunc[adcId][ADC_FOF_INT] != NULL) + { + /* call the callback function */ + adcIsrCbFunc[adcId][ADC_FOF_INT](); + } + /* Disable the interrupt if callback function is not setup */ + else + { + ADCx->ADC_IE.FOF_IE = 0U; + } + } + + /* Adc Complete Interrupt */ + if((intStatus & ADC_IntStatusTable[ADC_TCOMP_INT]) != 0U) + { + if(adcIsrCbFunc[adcId][ADC_TCOMP_INT] != NULL) + { + /* call the callback function */ + adcIsrCbFunc[adcId][ADC_TCOMP_INT](); + } + /* Disable the interrupt if callback function is not setup */ + else + { + ADCx->ADC_IE.TCOM_IE = 0U; + } + } + + /* Adc Compare Interrupt */ + if((intStatus & ADC_IntStatusTable[ADC_CMP_INT]) != 0U) + { + if(adcIsrCbFunc[adcId][ADC_CMP_INT] != NULL) + { + /* call the callback function */ + adcIsrCbFunc[adcId][ADC_CMP_INT](); + } + /* Disable the interrupt if callback function is not setup */ + else + { + ADCx->ADC_IE.CMP_IE = 0U; + } + } + + /* Adc trigger confict error Interrupt */ + if((intStatus & ADC_IntStatusTable[ADC_TC_ERR_INT]) != 0U) + { + if(adcIsrCbFunc[adcId][ADC_TC_ERR_INT] != NULL) + { + /* call the callback function */ + adcIsrCbFunc[adcId][ADC_TC_ERR_INT](); + } + /* Disable the interrupt if callback function is not setup */ + else + { + ADCx->ADC_IE.ERR_INT_IE = 0U; + } + } +} + +/** + * @brief ADC IRQHandler + * + * @param[in] none + * + * @return none + * + */ +void ADC0_DriverIRQHandler(void) +{ + ADC_IntHandler(ADC0_ID); +} + +/** @} end of group ADC_Private_Functions */ + +/** @defgroup ADC_Public_Functions + * @{ + */ + +/** + * @brief Adc Software Reset Function + * + * @param[in] adcId: Select the ADC ID + * + * @return none + * + */ +void ADC_SoftwareReset(ADC_ID_t adcId) +{ + volatile uint32_t i = 0U; + adc_reg_t * ADCx = (adc_reg_t *)(adcRegPtr[adcId]); + + ADCx->ADC_CTRL.RST = 1U; + + while(i < ADC_TIMEOUT_WAIT_CNT_SWRST) + { + i = i + 1U; + } +} + + +/** + * @brief Adc Initializes Function + * + * @param[in] adcId: Select the ADC ID: ADC0_ID,.... + * @param[in] adcConfigSet: Pointer to a ADC configuration structure. + * + * @return none + * + */ +void ADC_Init(ADC_ID_t adcId, const ADC_Config_t* adcConfigSet) +{ + adc_reg_t * ADCx = (adc_reg_t *)(adcRegPtr[adcId]); + + if(ADC_TDG_TRIGGER == adcConfigSet->adcTriggerMode) + { + ADCx->ADC_CTRL.TRIG_MODE_ENABLE = 1U; + } + else + { + ADCx->ADC_CTRL.TRIG_MODE_ENABLE = 0U; + } + + ADCx->ADC_CFG.REF_SEL = (uint32_t)adcConfigSet->adcVrefSource; + ADCx->ADC_CFG.RES = (uint32_t)adcConfigSet->adcResolution; + ADCx->ADC_CFG.CTYPE = (uint32_t)adcConfigSet->adcConversionMode; + ADCx->ADC_CFG.AVGS = (uint32_t)adcConfigSet->adcAvgsSelect; + ADCx->ADC_CFG.STS = (uint32_t)adcConfigSet->adcSampleTime; +} + +/** + * @brief Adc Reset(Terminate) Loop Mode for TDG Trigger Function + * + * @param[in] adcId: Select the ADC ID: ADC0_ID,.... + * + * @return none + * + */ +void ADC_ResetLoopMode(ADC_ID_t adcId) +{ + adc_reg_t * ADCx = (adc_reg_t *)(adcRegPtr[adcId]); + ADCx->ADC_CTRL.MODE1_RST = 1U; +} + +/** + * @brief Adc Channel Configurate Function + * + * @param[in] adcId: Select the ADC ID: ADC0_ID,.... + * @param[in] channelConfig: Pointer to a ADC channel configuration structure. + * + * @return none + * + */ +void ADC_ChannelConfig(ADC_ID_t adcId, + const ADC_ChannelConfig_t* channelConfig) +{ + adc_reg_t * ADCx = (adc_reg_t *)(adcRegPtr[adcId]); + + ADCx->ADC_CFG.DIFF_MODE = (uint32_t)channelConfig->adcDifferentialMode; + ADCx->ADC_CFG.CHSELP = (uint32_t)channelConfig->adcChannelP; + + if(ADC_DIFF_MODE == channelConfig->adcDifferentialMode) + { + ADCx->ADC_CFG.CHSELN = (uint32_t)channelConfig->adcChannelN; + } +} + +/** + * @brief Adc TDG Trigger Configurate Function + * + * @param[in] adcId: Select the ADC ID: ADC0_ID,.... + * @param[in] triggerConfig: Pointer to a ADC TDG trigger configuration + structure. + * + * @return none + * + */ +void ADC_TDGTriggerConfig(ADC_ID_t adcId, + const ADC_TDGTriggerConfig_t* triggerConfig) +{ + adc_reg_t * ADCx = (adc_reg_t *)(adcRegPtr[adcId]); + ADCx->ADC_CTRL.TRIG_MODE = (uint32_t)triggerConfig->adcTDGTrigMode; + ADCx->ADC_CMD_BUFF0.CMD0 = (uint32_t)triggerConfig->adcCmd0; + ADCx->ADC_CMD_BUFF0.CMD1 = (uint32_t)triggerConfig->adcCmd1; + ADCx->ADC_CMD_BUFF0.CMD2 = (uint32_t)triggerConfig->adcCmd2; + ADCx->ADC_CMD_BUFF0.CMD3 = (uint32_t)triggerConfig->adcCmd3; + ADCx->ADC_CMD_BUFF1.CMD4 = (uint32_t)triggerConfig->adcCmd4; + ADCx->ADC_CMD_BUFF1.CMD5 = (uint32_t)triggerConfig->adcCmd5; +} + +/** + * @brief Adc Enable Function + * + * @param[in] adcId: Select the ADC ID: ADC0_ID,.... + * + * @return none + * + */ +void ADC_Enable(ADC_ID_t adcId) +{ + adc_reg_t * ADCx = (adc_reg_t *)(adcRegPtr[adcId]); + + ADCx->ADC_CTRL.ADC_EN = 1U; +} + +/** + * @brief Adc Disable Function + * + * @param[in] adcId: Select the ADC ID: ADC0_ID,.... + * + * @return none + * + */ +void ADC_Disable(ADC_ID_t adcId) +{ + adc_reg_t * ADCx = (adc_reg_t *)(adcRegPtr[adcId]); + + ADCx->ADC_CTRL.ADC_EN = 0U; +} + +/** + * @brief Adc Compare Configurate Function + * + * @param[in] adcId: Select the ADC ID: ADC0_ID,.... + * @param[in] compareConfig: Pointer to a ADC compare configuration structure. + * adcCompareMode: Compare Mode + * - ADC_COMPARE_MODE_DISABLED + * - ADC_COMPARE_MODE_LESS_CVL + * - ADC_COMPARE_MODE_GREATER_CVL + * - ADC_COMPARE_MODE_EQUAL_CVL + * - ADC_COMPARE_MODE_WITHIN_CVL_CVH + * - ADC_COMPARE_MODE_OUT_OF_RANGE_CVL_CVH. + * cvl: Compare Value Low, which is used in below modes: + * - ADC_COMPARE_MODE_LESS_CVL + * - ADC_COMPARE_MODE_GREATER_CVL + * - ADC_COMPARE_MODE_EQUAL_CVL + * - ADC_COMPARE_MODE_WITHIN_CVL_CVH + * - ADC_COMPARE_MODE_OUT_OF_RANGE_CVL_CVH + * cvh: Compare Value High, which is used in below modes: + * - ADC_COMPARE_MODE_WITHIN_CVL_CVH + * - ADC_COMPARE_MODE_OUT_OF_RANGE_CVL_CVH + * + * @return none + * + */ +void ADC_CompareConfig(ADC_ID_t adcId, + const ADC_CompareConfig_t* compareConfig) +{ + adc_reg_t * ADCx = (adc_reg_t *)(adcRegPtr[adcId]); + + ADCx->ADC_CFG.CMPS = (uint32_t)compareConfig->adcCompareMode; + + if(compareConfig->adcCompareMode > ADC_COMPARE_MODE_DISABLED) + { + ADCx->ADC_CV.CVL = (uint32_t)compareConfig->adcCvl; + } + + if(compareConfig->adcCompareMode > ADC_COMPARE_MODE_EQUAL_CVL) + { + ADCx->ADC_CV.CVH = (uint32_t)compareConfig->adcCvh; + } +} + +/** + * @brief Adc Dozen Control Function + * + * @param[in] adcId: Select the ADC ID: ADC0_ID,.... + * + * @param[in] cmd: Enable/Disable. + * + * @return none + * + */ +void ADC_DozeControl(ADC_ID_t adcId, ControlState_t cmd) +{ + adc_reg_t * ADCx = (adc_reg_t *)(adcRegPtr[adcId]); + + ADCx->ADC_CTRL.DOZEN = (uint32_t)cmd; +} + +/** + * @brief Adc Get FIFO size Function + * + * @param[in] adcId: Select the ADC ID: ADC0_ID,.... + * + * @return FIFO size. + * + */ +uint32_t ADC_GetFifoSize(ADC_ID_t adcId) +{ + adc_reg_t const volatile * ADCx = (adc_reg_t *)(adcRegPtr[adcId]); + + return (uint32_t) ADCx->ADC_PARAM.FIFO_SIZE; +} + +/** + * @brief Adc FIFO Depth Redefine Function + * + * @param[in] adcId: Select the ADC ID + * @param[in] fifoDepth: FIFO depth Configuration. + * + * @return none + * + */ +void ADC_FifoDepthRedefine(ADC_ID_t adcId, uint8_t fifoDepth) +{ + adc_reg_t * ADCx = (adc_reg_t *)(adcRegPtr[adcId]); + + ADCx->ADC_FCTRL.FDRD = fifoDepth; +} + +/** + * @brief Adc FIFO Watermark Configurate Function + * + * @param[in] adcId: Select the ADC ID + * @param[in] fwmark: FIFO watermark configration. + * + * @return none + * + */ +void ADC_FifoWatermarkConfig(ADC_ID_t adcId, uint8_t fwmark) +{ + adc_reg_t * ADCx = (adc_reg_t *)(adcRegPtr[adcId]); + + ADCx->ADC_FCTRL.FWMARK = fwmark; +} + +/** + * @brief Adc Get data size in FIFO Function + * + * @param[in] adcId: Select the ADC ID + * + * @return Data size in FIFO. + * + */ +uint32_t ADC_GetNumOfFifoData(ADC_ID_t adcId) +{ + adc_reg_t const volatile * ADCx = (adc_reg_t *)(adcRegPtr[adcId]); + + return (uint32_t) ADCx->ADC_FCTRL.FCOUNT; +} + +/** + * @brief Adc Dma Request Command Function + * + * @param[in] adcId: Select the ADC ID + * @param[in] cmd: Enable/Disable. + * + * @return none + * + */ +void ADC_DmaRequestCmd(ADC_ID_t adcId, ControlState_t cmd) +{ + adc_reg_t * ADCx = (adc_reg_t *)(adcRegPtr[adcId]); + + ADCx->ADC_IE.FWMDE = (uint32_t)cmd; +} + +/** + * @brief Adc Software Trigger Control Function + * + * @param[in] adcId: Select the ADC ID + * + * @return none + * + */ +void ADC_SoftwareTrigger(ADC_ID_t adcId) +{ + adc_reg_t * ADCx = (adc_reg_t *)(adcRegPtr[adcId]); + + ADCx->ADC_SWTRIG.ADC_SWTRIG = 1U; +} + +/** + * @brief Adc Get Conversion Result Function + * + * @param[in] adcId: Select the ADC ID + * + * @return Conversion Result: bit[11:0] is conversion data; bit[16:12] is + conversion channel. + * + */ +uint32_t ADC_GetConversionResult(ADC_ID_t adcId) +{ + adc_reg_t const volatile * ADCx = (adc_reg_t *)(adcRegPtr[adcId]); + + return (uint32_t) ADCx->ADC_DATA_RD.ADC_DATA_RD; +} + +/** + * @brief Adc Get Status Function + * + * @param[in] adcId: Select the ADC ID + * @param[in] statusType: Status Type + * - ADC_STATUS_FWM_INT + * - ADC_STATUS_FOF_INT + * - ADC_STATUS_TCOMP_INT + * - ADC_STATUS_CMP_INT + * - ADC_STATUS_DMA_REQ + * - ADC_STATUS_FIFO_RDY + * - ADC_STATUS_CAL_RDY + * - ADC_STATUS_ACTIVE + * - ADC_STATUS_LOOP_IDLE + * - ADC_STATUS_TC_ERR_INT + * + * @return status: RESET, SET + * + */ +FlagStatus_t ADC_GetStatus(ADC_ID_t adcId, ADC_Status_t statusType) +{ + adc_reg_w_t const volatile * ADCWx = (adc_reg_w_t *) adcRegWPtr[adcId]; + + FlagStatus_t bitStatus = RESET; + + if((ADCWx->ADC_STAT & (0x00000001UL << (uint32_t)statusType)) != 0UL) + { + bitStatus = SET; + } + + return bitStatus; +} + +/** + * @brief Adc Interrupt Mask Function + * + * @param[in] adcId: Select the ADC ID: ADC0_ID,.... + * @param[in] intType: Interrupt Type + * - ADC_FWM_INT. + * - ADC_FOF_INT + * - ADC_TCOMP_INT + * - ADC_CMP_INT + * - ADC_TC_ERR_INT + * @param[in] intMask: Mask Type + * - UNMASK + * - MASK + * + * @return none. + * + */ +void ADC_IntMask(ADC_ID_t adcId, ADC_INT_t intType, IntMask_t intMask) +{ + adc_reg_w_t * ADCWx = (adc_reg_w_t *) (adcRegWPtr[adcId]); + + /** + * @brief ADC interrupt ID definition + */ + static const uint32_t ADC_IntMaskTable[] = + { + 0x00000001U, /*!< ADC_FWM_INT */ + 0x00000002U, /*!< ADC_FOF_INT */ + 0x00000004U, /*!< ADC_TCOMP_INT */ + 0x00000008U, /*!< ADC_CMP_INT */ + 0x00000020U, /*!< ADC_ERR_INT */ + 0x0000002FU /*!< ADC_INT_ALL */ + }; + + if(UNMASK == intMask) + { + ADCWx->ADC_IE = ADCWx->ADC_IE | ADC_IntMaskTable[intType]; + adcIntMaskStatus = adcIntMaskStatus | ADC_IntStatusTable[intType]; + } + else + { + ADCWx->ADC_IE = ADCWx->ADC_IE & (~ADC_IntMaskTable[intType]); + adcIntMaskStatus = adcIntMaskStatus &(~ADC_IntStatusTable[intType]); + } +} + +/** + * @brief Adc Interrupt Clear Status Function + * + * @param[in] adcId: Select the ADC ID + * @param[in] intType: Interrupt Type + * - ADC_FWM_INT. + * - ADC_FOF_INT + * - ADC_TCOMP_INT + * - ADC_CMP_INT + * - ADC_TC_ERR_INT + * - ADC_INT_ALL + * + * @return none. + * + */ +void ADC_IntClear(ADC_ID_t adcId, ADC_INT_t intType) +{ + adc_reg_w_t * ADCWx = (adc_reg_w_t *) (adcRegWPtr[adcId]); + + ADCWx->ADC_STAT = ADCWx->ADC_STAT | ADC_IntStatusTable[intType]; +} + +/** + * @brief Adc Get Interrupt Status Function + * + * @param[in] adcId: Select the ADC ID + * @param[in] intType: Interrupt Type + * - ADC_FWM_INT. + * - ADC_FOF_INT + * - ADC_TCOMP_INT + * - ADC_CMP_INT + * - ADC_TC_ERR_INT + * + * @return status: RESET, SET + * + */ +FlagStatus_t ADC_GetIntStatus(ADC_ID_t adcId, ADC_INT_t intType) +{ + adc_reg_w_t const volatile * ADCWx = (adc_reg_w_t *) (adcRegWPtr[adcId]); + FlagStatus_t bitStatus = RESET; + + if((ADCWx->ADC_STAT & ADC_IntStatusTable[intType]) != 0UL) + { + bitStatus = SET; + } + + return bitStatus; +} + +/** + * @brief install call back function + * + * @param[in] adcId: Select the ADC ID + * @param[in] intType: select the interrupt type + * - ADC_FWM_INT. + * - ADC_FOF_INT + * - ADC_TCOMP_INT + * - ADC_CMP_INT + * - ADC_TC_ERR_INT + * @param[in] cbFun: pointer to callback function + * + * @return none + * + */ +void ADC_InstallCallBackFunc(ADC_ID_t adcId, ADC_INT_t intType, + isr_cb_t * cbFun) +{ + adcIsrCbFunc[adcId][intType] = cbFun; +} + +/** @} end of group ADC_Public_Functions */ + +/** @} end of group ADC_definitions */ + +/** @} end of group Z20K11X_Peripheral_Driver */ diff --git a/StdDriver/Src/Z20K11xM_can.c b/StdDriver/Src/Z20K11xM_can.c new file mode 100644 index 0000000..65f5e28 --- /dev/null +++ b/StdDriver/Src/Z20K11xM_can.c @@ -0,0 +1,4591 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_can.c + * @brief : CAN module driver file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ + +#include "Z20K11xM_can.h" + +/** @addtogroup Z20K11X_Peripheral_Driver + * @{ + */ + +/** @defgroup CAN + * @brief CAN driver modules + * @{ + */ + +/** @defgroup CAN_Private_Type + * @{ + */ + +/** + * @brief CAN FD MB region type definition + */ +typedef enum +{ + CAN_FD_MB_REGION_0 = 0U, /*!< FD MB region 0*/ + CAN_FD_MB_REGION_1 /*!< FD MB region 1*/ +} CAN_FdMbRegion_t; + +/** + * @brief CAN MB type definition + */ +typedef enum +{ + CAN_MB_RX = 0U, /*!< TX MB */ + CAN_MB_TX /*!< RX MB */ +} CAN_MbTR_t; + +#define CAN_RX_INACTIVE 0x0U /*!< MB is not active.*/ +#define CAN_RX_FULL 0x2U /*!< MB is full.*/ +#define CAN_RX_EMPTY 0x4U /*!< MB is active and empty.*/ +#define CAN_RX_OVERRUN 0x6U /*!< MB is overwritten into a full buffer.*/ +#define CAN_RX_RANSWER 0xAU /*!< A frame was configured to recognize a + Remote Request Frame and transmit a + Response Frame in return.*/ + +#define CAN_TX_INACTIVE 0x08U /*!< MB is not active.*/ +#define CAN_TX_ABORT 0x09U /*!< MB is aborted.*/ +#define CAN_TX_DATA_REMOTE 0x0CU /*!< MB is a TX Data Frame(MB RTR must be 0).*/ +#define CAN_TX_TANSWER 0x0EU /*!< MB is a TX Response Request Frame from. + an incoming Remote Request Frame.*/ +#define CAN_NOT_USED 0xFU /*!< Not used*/ + + +typedef volatile struct +{ + union { + struct { + uint32_t TIME_STAMP :16; /* [15:0] */ + uint32_t DLC : 4; /* [19:16] */ + uint32_t RTR : 1; /* [20] */ + uint32_t IDE : 1; /* [21] */ + uint32_t SRR : 1; /* [22] */ + uint32_t RSVD_23 : 1; /* [23] */ + uint32_t CODE : 4; /* [27:24] */ + uint32_t RSVD_28 : 1; /* [28] */ + uint32_t ESI : 1; /* [29] */ + uint32_t BRS : 1; /* [30] */ + uint32_t EDL : 1; /* [31] */ + } BF; + uint32_t WORDVAL; + } config; + + /* 0x84*/ + union { + struct { + uint32_t ID_EXTEND :18; /* [17:0] */ + uint32_t ID_STANDARD :11; /* [28:18] */ + uint32_t PRIO : 3; /* [31:29] */ + } BF; + uint32_t WORDVAL; + } id; + + uint32_t data[16]; +} CAN_Mb_t; + +/** + * @brief CAN callback functions struct + */ +typedef struct +{ + can_mb_cb_t mbCbf; /*!< call back function for MB*/ + isr_cb_t * cbf[(uint32_t)CAN_INT_ALL - 1U]; /*!< other call back functions */ +} CAN_cbf_t; + +/** @} end of group CAN_Private_Type*/ + +/** @defgroup CAN_Private_Defines + * @{ + */ +#define CAN0 ((can_reg_t *) CAN0_BASE_ADDR) /*!< CAN0 Register */ +#define CAN1 ((can_reg_t *) CAN1_BASE_ADDR) /*!< CAN1 Register */ + +#define CAN_MB_NUM 64U +#define CAN_MCR_LPMACK_MASK 0x00100000U +#define CAN_MCR_FRZACK_MASK 0x01000000U + +#define CAN_WAIT_CNT 100000 +#define CAN_ID_STD_SHIFT 18U +#define CAN_ID_STD_MASK 0x1FFC0000U +#define CAN_ID_EXT_MASK 0x1FFFFFFFU + +/* CAN FD extended data length DLC encoding */ +#define CAN_DLC_VALUE_12_BYTES 9U +#define CAN_DLC_VALUE_16_BYTES 10U +#define CAN_DLC_VALUE_20_BYTES 11U +#define CAN_DLC_VALUE_24_BYTES 12U +#define CAN_DLC_VALUE_32_BYTES 13U +#define CAN_DLC_VALUE_48_BYTES 14U +#define CAN_DLC_VALUE_64_BYTES 15U + + +#define CAN_INT_MSK_BUS_OFF ((uint32_t)1U << 15U) +#define CAN_INT_MSK_ERR ((uint32_t)1U << 14U) +#define CAN_INT_MSK_TXW ((uint32_t)1U << 11U) +#define CAN_INT_MSK_RXW ((uint32_t)1U << 10U) +#define CAN_INT_MSK_BUS_OFF_DONE ((uint32_t)1U << 30U) +#define CAN_INT_MSK_ERR_FAST ((uint32_t)1U << 31U) +#define CAN_INT_MSK_SELF_WAKEUP ((uint32_t)1U << 26U) +#define CAN_INT_MSK_RXFIFO_FRAME ((uint32_t)1U << 5U) +#define CAN_INT_MSK_RXFIFO_WARNING ((uint32_t)1U << 6U) +#define CAN_INT_MSK_RXFIFO_OVERFLOW ((uint32_t)1U << 7U) +#define CAN_INT_MSK_HOST_MEM_ERR ((uint32_t)1U << 19U) +#define CAN_INT_MSK_CAN_MEM_ERR ((uint32_t)1U << 18U) +#define CAN_INT_MSK_COR_MEM_ERR ((uint32_t)1U << 16U) +#define CAN_INT_MSK_PN_WAKEUP_MATCH ((uint32_t)1U << 16U) +#define CAN_INT_MSK_PN_WAKEUP_TIMEOUT ((uint32_t)1U << 17U) +#define CAN_INT_MSK_MULTI_1 (CAN_INT_MSK_BUS_OFF | CAN_INT_MSK_ERR |\ + CAN_INT_MSK_TXW | CAN_INT_MSK_RXW) +#define CAN_INT_MSK_MULTI_2 (CAN_INT_MSK_BUS_OFF_DONE | \ + CAN_INT_MSK_ERR_FAST) +#define CAN_INT_MSK_MULTI_3 (CAN_INT_MSK_HOST_MEM_ERR | \ + CAN_INT_MSK_CAN_MEM_ERR | \ + CAN_INT_MSK_COR_MEM_ERR) +#define CAN_INT_MSK_MULTI_4 (CAN_INT_MSK_PN_WAKEUP_MATCH | \ + CAN_INT_MSK_PN_WAKEUP_TIMEOUT) + +#define CAN_INT_MSK_FLAG_BUS_OFF ((uint32_t)1U << 2U) +#define CAN_INT_MSK_FLAG_ERR ((uint32_t)1U << 1U) +#define CAN_INT_MSK_FLAG_TXW ((uint32_t)1U << 17U) +#define CAN_INT_MSK_FLAG_RXW ((uint32_t)1U << 16U) +#define CAN_INT_MSK_FLAG_BUS_OFF_DONE ((uint32_t)1U << 19U) +#define CAN_INT_MSK_FLAG_ERR_FAST ((uint32_t)1U << 20U) +#define CAN_INT_MSK_FLAG_SELF_WAKEUP (uint32_t)1U +#define CAN_INT_MSK_FLAG_RXFIFO_FRAME ((uint32_t)1U << 5U) +#define CAN_INT_MSK_FLAG_RXFIFO_WARNING ((uint32_t)1U << 6U) +#define CAN_INT_MSK_FLAG_RXFIFO_OVERFLOW ((uint32_t)1U << 7U) +#define CAN_INT_MSK_FLAG_HOST_MEM_ERR ((uint32_t)1U << 19U) +#define CAN_INT_MSK_FLAG_CAN_MEM_ERR ((uint32_t)1U << 18U) +#define CAN_INT_MSK_FLAG_COR_MEM_ERR ((uint32_t)1U << 16U) +#define CAN_INT_MSK_FLAG_PN_WAKEUP_MATCH ((uint32_t)1U << 16U) +#define CAN_INT_MSK_FLAG_PN_WAKEUP_TIMEOUT ((uint32_t)1U << 17U) +#define CAN_INT_MSK_FLAG_ALL_1 (CAN_INT_MSK_FLAG_BUS_OFF | \ + CAN_INT_MSK_FLAG_ERR | \ + CAN_INT_MSK_FLAG_TXW | \ + CAN_INT_MSK_FLAG_RXW |\ + CAN_INT_MSK_FLAG_BUS_OFF_DONE |\ + CAN_INT_MSK_FLAG_ERR_FAST |\ + CAN_INT_MSK_FLAG_SELF_WAKEUP) +#define CAN_INT_MSK_FLAG_ALL_2 (CAN_INT_MSK_FLAG_HOST_MEM_ERR |\ + CAN_INT_MSK_FLAG_CAN_MEM_ERR |\ + CAN_INT_MSK_FLAG_COR_MEM_ERR) +#define CAN_INT_MSK_FLAG_ALL_3 (CAN_INT_MSK_FLAG_PN_WAKEUP_MATCH | \ + CAN_INT_MSK_FLAG_PN_WAKEUP_TIMEOUT) + + +#define CAN_CAL_RX_MB_STD_MASK(mask) (((mask) << CAN_ID_STD_SHIFT) & \ + CAN_ID_STD_MASK) +#define CAN_CAL_RX_MB_EXT_MASK(mask) ((mask) & CAN_ID_EXT_MASK) +#define CAN_RX_FIFO_OCUP_LAST_MB_NUM(x) (5U + ((((x) + 1U) * 8U) >> 2U)) + +#define CAN_SWAP_BYTES_IN_WORD_INDEX(index) (((index) & ~3U) + \ + (3U - ((index) & 3U))) +#define CAN_SWAP_BYTES_IN_WORD(a, b) REV_BYTES_32(a, b) + +#define CAN_CODE_BUSY_MASK 0x01U + +#define CAN_RXFIFO_FRAME_AVAILABLE (5U) +#define CAN_RXFIFO_WARNING (6U) +#define CAN_RXFIFO_OVERFLOW (7U) + +#define CAN_STATUS_ALL_MASK 0xDC00FF00U + +#define CAN_RAM_RX_FIFO_ADDR 0xA80U +#define CAN_RAM_RX_FIFO_LEN_IN_WORD 6U +#define CAN_RAM_MSK_ADDR 0xAA0U +#define CAN_RAM_MSK_LEN_IN_WORD 4U +#define CAN_RAM_RX_SMB_ADDR 0xAB0U +#define CAN_RAM_RX_SMB_LEN_IN_WORD 12U +#define CAN_RAM_FD_SCRATCH_ADDR 0xF28U +#define CAN_RAM_FD_SCRATCH_LEN_IN_WORD 54U + +/** @} end of group CAN_Private_Defines */ + +/** @defgroup CAN_Private_Variables + * @{ + */ +/*PRQA S 0303,0306 ++*/ +static can_reg_t * const canRegPtr[CAN_INSTANCE_NUM] = +{ + (can_reg_t *)CAN0_BASE_ADDR, +#if ( 2U == CAN_INSTANCE_NUM ) + (can_reg_t *)CAN1_BASE_ADDR, +#endif +}; + +static can_reg_w_t * const canRegWPtr[CAN_INSTANCE_NUM] = +{ + (can_reg_w_t *)CAN0_BASE_ADDR, +#if ( 2U == CAN_INSTANCE_NUM ) + (can_reg_w_t *)CAN1_BASE_ADDR, +#endif +}; +/*PRQA S 0303,0306 --*/ + +static const uint32_t canInterruptMaskTable[] = +{ + CAN_INT_MSK_BUS_OFF, /* CAN_INT_BUS_OFF */ + CAN_INT_MSK_ERR, /* CAN_INT_ERR */ + CAN_INT_MSK_TXW, /* CAN_INT_TXW */ + CAN_INT_MSK_RXW, /* CAN_INT_RXW */ + CAN_INT_MSK_BUS_OFF_DONE, /* CAN_INT_BUS_OFF_DONE */ + CAN_INT_MSK_ERR_FAST, /* CAN_INT_ERR_FAST */ + CAN_INT_MSK_SELF_WAKEUP, /* CAN_INT_SELF_WAKEUP */ + CAN_INT_MSK_RXFIFO_FRAME, /* CAN_INT_RXFIFO_FRAME */ + CAN_INT_MSK_RXFIFO_WARNING, /* CAN_INT_RXFIFO_WARNING */ + CAN_INT_MSK_RXFIFO_OVERFLOW,/* CAN_INT_RXFIFO_OVERFLOW */ + CAN_INT_MSK_HOST_MEM_ERR, /* CAN_INT_HOST_MEM_ERR */ + CAN_INT_MSK_CAN_MEM_ERR, /* CAN_INT_CAN_MEM_ERR */ + CAN_INT_MSK_COR_MEM_ERR, /* CAN_INT_COR_MEM_ERR */ + CAN_INT_MSK_PN_WAKEUP_MATCH, /* CAN_INT_PN_WAKEUP_MATCH */ + CAN_INT_MSK_PN_WAKEUP_TIMEOUT,/* CAN_INT_PN_WAKEUP_TIMEOUT */ +}; + +static const uint32_t canInterruptFlagMaskTable[] = +{ + CAN_INT_MSK_FLAG_BUS_OFF, /* CAN_INT_BUS_OFF */ + CAN_INT_MSK_FLAG_ERR, /* CAN_INT_ERR */ + CAN_INT_MSK_FLAG_TXW, /* CAN_INT_TXW */ + CAN_INT_MSK_FLAG_RXW, /* CAN_INT_RXW */ + CAN_INT_MSK_FLAG_BUS_OFF_DONE, /* CAN_INT_BUS_OFF_DONE */ + CAN_INT_MSK_FLAG_ERR_FAST, /* CAN_INT_ERR_FAST */ + CAN_INT_MSK_FLAG_SELF_WAKEUP, /* CAN_INT_SELF_WAKEUP */ + CAN_INT_MSK_FLAG_RXFIFO_FRAME, /* CAN_INT_RXFIFO_FRAME */ + CAN_INT_MSK_FLAG_RXFIFO_WARNING,/* CAN_INT_RXFIFO_WARNING */ + CAN_INT_MSK_FLAG_RXFIFO_OVERFLOW, /* CAN_INT_RXFIFO_OVERFLOW */ + CAN_INT_MSK_FLAG_HOST_MEM_ERR, /* CAN_INT_HOST_MEM_ERR */ + CAN_INT_MSK_FLAG_CAN_MEM_ERR, /* CAN_INT_CAN_MEM_ERR */ + CAN_INT_MSK_FLAG_COR_MEM_ERR, /* CAN_INT_COR_MEM_ERR */ + CAN_INT_MSK_FLAG_PN_WAKEUP_MATCH, /* CAN_INT_PN_WAKEUP_MATCH */ + CAN_INT_MSK_FLAG_PN_WAKEUP_TIMEOUT,/* CAN_INT_PN_WAKEUP_TIMEOUT */ + 0U, /* CAN_INT_MB:not used */ +}; + +static CAN_cbf_t canIsrCbFunc[CAN_INSTANCE_NUM] = +{ + {NULL, {NULL, NULL, NULL,NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL,NULL, NULL}}, +#if ( 2U == CAN_INSTANCE_NUM ) + {NULL, {NULL, NULL, NULL,NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL,NULL, NULL}} +#endif +}; + +static uint32_t canESR1Buf[CAN_INSTANCE_NUM] = +{ + 0U, +#if ( 2U == CAN_INSTANCE_NUM ) + 0U +#endif +}; + +static uint32_t canIntMaskStatus1[CAN_INSTANCE_NUM] = +{ + 0U, +#if ( 2U == CAN_INSTANCE_NUM ) + 0U +#endif +}; + +/** @} end of group CAN_Private_Variables */ + +/** @defgroup CAN_Global_Variables + * @{ + */ + +/** @} end of group CAN_Global_Variables */ + +/** @defgroup CAN_Private_FunctionDeclaration + * @{ + */ +void CAN0_DriverIRQHandler(void); +#if ( 2U == CAN_INSTANCE_NUM ) +void CAN1_DriverIRQHandler(void); +#endif +/** @} end of group CAN_Private_FunctionDeclaration */ + +/** @defgroup CAN_Private_Functions + * @{ + */ + + +/** + * @brief Get MB status + * + * @param[in] id: select the CAN ID + * @param[in] mbIdx: the MB index + * + * @return SET/RESET + * + */ +static FlagStatus_t CAN_GetMbIntStatus(CAN_Id_t id, uint32_t mbIdx) +{ + can_reg_w_t * CANxw = (can_reg_w_t *)(canRegWPtr[id]); + FlagStatus_t retVal; + if(mbIdx < 32U) + { + retVal = ((CANxw->CAN_IFLAG1 & (1UL << mbIdx)) != 0U) ? SET : RESET; + } + else if(mbIdx < 64U) + { + retVal = ((CANxw->CAN_IFLAG2 & (1UL << (mbIdx - 32U))) != 0U) + ? SET : RESET; + } + else + { + retVal = RESET; + } + return retVal; +} + +/** + * @brief clear MB interrupt status + * + * @param[in] id: select the CAN ID + * @param[in] mbIdx: MB index to be checked + * @return none + * + */ +static inline void CAN_ClearMbIntStatus(CAN_Id_t id, uint32_t mbIdx) +{ + can_reg_w_t * CANxw = (can_reg_w_t *)(canRegWPtr[id]); + uint32_t flag = ((uint32_t)1U << (mbIdx % 32U)); + + /* Clear the corresponding message buffer interrupt flag*/ + if (mbIdx < 32U) + { + CANxw->CAN_IFLAG1 = flag; + } + else + { + CANxw->CAN_IFLAG2 = flag; + } + +} + +/** + * @brief Get ESR1 buffer in interrupt call back functions. The ESR1 + * will be stored into ESR1 buffer in CAN_IntHandler. + * If the call back functions which are installed through + * CAN_InstallCallBackFunc() needs to get the ESR1 , please use t + * his function instead of CAN_GetIntStatus or CAN_GetStatus. + * + * @param[in] id: Select the CAN port,should be CAN0_ID , CAN1_ID + * + * @return ESR1 Buff Value + * + */ +uint32_t CAN_GetESR1BufForCbf(CAN_Id_t id) +{ + return canESR1Buf[id]; +} + +/** + * @brief Get CAN status from ESR1 Buff + * + * @param[in] id: select the CAN ID + * @param[in] status: the status to be get + * + * @return status + * - SET + * - RESET + * + */ +FlagStatus_t CAN_GetStatusFromESR1Buf(CAN_Id_t id, CAN_Status_t status) +{ + FlagStatus_t res; + + res = ((canESR1Buf[id] & ((uint32_t)1U << (uint32_t)status)) != 0U) + ? SET : RESET; + + return res; +} + +/** + * @brief Computes the maximum payload size (in bytes), given a DLC field value + * + * @param data length DLC encoding + * + * @return payload size + * + */ +static uint8_t CAN_ComputePayloadSize(uint8_t dlcValue) +{ + uint8_t ret = 0U; + + if (dlcValue <= 8U) + { + ret = dlcValue; + } + else + { + switch (dlcValue) + { + case CAN_DLC_VALUE_12_BYTES: + ret = 12U; + break; + case CAN_DLC_VALUE_16_BYTES: + ret = 16U; + break; + case CAN_DLC_VALUE_20_BYTES: + ret = 20U; + break; + case CAN_DLC_VALUE_24_BYTES: + ret = 24U; + break; + case CAN_DLC_VALUE_32_BYTES: + ret = 32U; + break; + case CAN_DLC_VALUE_48_BYTES: + ret = 48U; + break; + case CAN_DLC_VALUE_64_BYTES: + ret = 64U; + break; + default: + /* The argument is not a valid DLC size */ + break; + } + } + + return ret; +} + +/** + * @brief Computes the DLC field value, and the actural data size given a data + * length (in bytes). + * + * @param dataLen: data length + * @param dlc:DLC encoding + * @param dataSize:data size + * + * @return none + * + */ +static void CAN_ComputeDlcAndDataSize(uint32_t dataLen, uint32_t *dlc, + uint32_t *dataSize) +{ + uint32_t dlcVal; + uint32_t dataSizeVal; + if (dataLen <= 8U) + { + dlcVal = dataLen; + dataSizeVal = dataLen; + } + else if(dataLen <= 12U) + { + dlcVal = CAN_DLC_VALUE_12_BYTES; + dataSizeVal = 12U; + } + else if(dataLen <= 16U) + { + dlcVal = CAN_DLC_VALUE_16_BYTES; + dataSizeVal = 16U; + } + else if(dataLen <= 20U) + { + dlcVal = CAN_DLC_VALUE_20_BYTES; + dataSizeVal = 20U; + } + else if(dataLen <= 24U) + { + dlcVal = CAN_DLC_VALUE_24_BYTES; + dataSizeVal = 24U; + } + else if(dataLen <= 32U) + { + dlcVal = CAN_DLC_VALUE_32_BYTES; + dataSizeVal = 32U; + } + else if(dataLen <= 48U) + { + dlcVal = CAN_DLC_VALUE_48_BYTES; + dataSizeVal = 48U; + } + else + { + dlcVal = CAN_DLC_VALUE_64_BYTES; + dataSizeVal = 64U; + } + + if(dlc != NULL) + { + *dlc = dlcVal; + } + + if(dataSize != NULL) + { + *dataSize = dataSizeVal; + } +} + + +/** + * @brief check if the given MB index is valid + * + * @param[in] id: select the CAN ID + * @param[in] mbIdx: MB index to be checked + * @return result + * + */ +static ResultStatus_t CAN_CheckMbId(CAN_Id_t id, uint32_t mbIdx) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + ResultStatus_t retVal = SUCC; + if ((mbIdx > CANx->CAN_MCR.MAXMB) || (mbIdx > (CAN_MB_NUM-1U))) + { + retVal = ERR; + } + else + { + if (CANx->CAN_MCR.RFEN != 0U) + { + if(mbIdx <= + CAN_RX_FIFO_OCUP_LAST_MB_NUM((uint32_t)CANx->CAN_CTRL2.RFFN)) + { + retVal = ERR; + } + } + } + + return retVal; +} + +/** + * @brief Get the number of Rx FIFO ID Filter Table Elements + * Affected by Rx Individual Masks. + * + * @param[in] id: select the CAN ID + * + * @return the max no of elements affected by Rx Individual Mask register + * RXMIR in RxFIFO Mode + * + */ +static inline uint32_t CAN_GetNoOfRxFIFOIndividualMask(CAN_Id_t id) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + + /* Get the number of RX FIFO Filters*/ + uint32_t ret = CANx->CAN_CTRL2.RFFN; + if(ret < 0x0CU) + { + /* Max filters configured by individual mask are (7 + RFFN * 2) depends + on the FIFO size */ + ret = (7U + (ret << 1U)); + } + else + { + ret = 31U; + } + + return ret; +} + + +/** + * @brief Enter freeze mode. + * + * @param[in] id: select the CAN ID + * + * @return result + * + */ +static ResultStatus_t CAN_EnterFreezeMode(CAN_Id_t id) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + volatile uint32_t cnt = 0U; + ResultStatus_t retVal = ERR; + CANx->CAN_MCR.FRZ = 1U; + CANx->CAN_MCR.HALT = 1U; + if (CANx->CAN_MCR.MDIS != 0U) + { + CANx->CAN_MCR.MDIS = 0U; + } + + /* Wait for entering the freeze mode */ + while(cnt < CAN_TIMEOUT_WAIT_CNT_1) + { + cnt++; + if(1U == CANx->CAN_MCR.NOTRDY ) + { + break; + } + } + + if(cnt >= CAN_TIMEOUT_WAIT_CNT_1) + { + retVal = ERR; + } + else + { + cnt = 0U; + while(cnt < CAN_TIMEOUT_WAIT_CNT_1) + { + cnt++; + if(1U == CANx->CAN_MCR.FRZACK ) + { + retVal = SUCC; + break; + } + } + } + + return retVal; +} + +/** + * @brief exit freeze mode. + * + * @param[in] id: select the CAN ID + * + * @return result + * + */ +static ResultStatus_t CAN_ExitFreezeMode(CAN_Id_t id) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + volatile uint32_t cnt = 0U; + ResultStatus_t retVal = ERR; + CANx->CAN_MCR.HALT = 0U; + CANx->CAN_MCR.FRZ = 0U; + + /* Wait for exit the freeze mode */ + while(cnt < CAN_TIMEOUT_WAIT_CNT_2) + { + cnt++; + if(0U == CANx->CAN_MCR.FRZACK ) + { + retVal = SUCC; + break; + } + } + + return retVal; +} + +/** + * @brief Disable memory error detection + * + * @param[in] id: select the CAN ID + * + * @return none + * + */ +static inline void CAN_DisableMemErrorDetection(CAN_Id_t id) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + + /* Enable write of MECR register */ + CANx->CAN_CTRL2.ECRWRE = 1U; + /* Enable write of MECR */ + CANx->CAN_MECR.ECRWRDIS = 0U; + /* Disable Error Detection and Correction mechanism, + that will set CAN in Freez Mode in case of trigger */ + CANx->CAN_MECR.NCEFAFRZ = 0U; + /* Disable write of MECR */ + CANx->CAN_CTRL2.ECRWRE = 0U; +} + +/** + * @brief Get the payload size of the MBs + * + * @param[in] id: select the CAN ID + @ @param[in] region:CAN FD MB region + * + * @return the payload size of the MBs (in bytes). + * + */ +static uint8_t CAN_GetPayloadSize(CAN_Id_t id,CAN_FdMbRegion_t region) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + uint32_t payloadSize; + + /* The standard payload size is 8 bytes */ + if (CANx->CAN_MCR.FDEN != 0U) + { + if(CAN_FD_MB_REGION_0 == region) + { + /* the payload size of region 0 and region1 is supposed to be*/ + payloadSize = 1UL << (CANx->CAN_FDCTRL.MBDSR0 + 3U); + } + else + { + /* the payload size of region 0 and region1 is supposed to be*/ + payloadSize = 1UL << (CANx->CAN_FDCTRL.MBDSR1 + 3U); + } + } + else + { + payloadSize = 8U; + } + + return (uint8_t)payloadSize; +} + +/** + * @brief Get the limit of max MB number, the actual MB number can not + * exceed it + * + * @param[in] id: select the CAN ID + * + * @return the limit of max MB number + * + */ +static uint8_t CAN_GetMaxMbNumLimit(CAN_Id_t id) +{ + uint32_t payloadSize; + uint8_t configFieldSize = 8U; + uint32_t ramBlockSize = 512U; + uint32_t mbSize; + uint32_t totalMbNum; + + payloadSize = CAN_GetPayloadSize(id,CAN_FD_MB_REGION_0); + mbSize= payloadSize + configFieldSize; + totalMbNum = ramBlockSize / mbSize; + + payloadSize = CAN_GetPayloadSize(id,CAN_FD_MB_REGION_1); + mbSize= payloadSize + configFieldSize; + totalMbNum += (ramBlockSize / mbSize); + + return (uint8_t)totalMbNum; +} + + +/** + * @brief get the start address of a MB + * + * @param[in] id: select the CAN ID + * @param[in] mbIdx: MB index + * @param[in] region: point to the address where the region number will + * be stored + * @param[in] addr: point to the address where the start address of the MB will + * be stored + * + * @return status + * + */ +static ResultStatus_t CAN_GetMbAddr(CAN_Id_t id,uint8_t mbIdx, + CAN_FdMbRegion_t *region, + CAN_Mb_t **addr) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + uint8_t payloadSize; + uint8_t configFieldSize = 8U; + uint32_t ramBlockSize = 512U; + uint32_t ramBlockOffset; + uint32_t mbSize,maxMbNum; + uint32_t mbOffset; + ResultStatus_t retVal = SUCC; + if(region != NULL) + { + *region = CAN_FD_MB_REGION_0; + } + + payloadSize = CAN_GetPayloadSize(id,CAN_FD_MB_REGION_0); + mbSize= (uint32_t)payloadSize + (uint32_t)configFieldSize; + maxMbNum = ramBlockSize / mbSize; + + ramBlockOffset = 0U; + + if(mbIdx >= maxMbNum) + { + mbIdx -= (uint8_t)maxMbNum; + + payloadSize = CAN_GetPayloadSize(id,CAN_FD_MB_REGION_1); + mbSize= (uint32_t)payloadSize + (uint32_t)configFieldSize; + maxMbNum = ramBlockSize / mbSize; + ramBlockOffset = 512U; + + if(mbIdx >= maxMbNum) + { + retVal = ERR; + } + else + { + if(region != NULL) + { + *region = CAN_FD_MB_REGION_1; + } + } + } + if(SUCC == retVal) + { + /* Multiply the MB index by the MB size (in words) */ + mbOffset = ramBlockOffset + (mbIdx ) * mbSize; + /*PRQA S 0303 ++*/ + *addr = (CAN_Mb_t *)((uint32_t)&(CANx->CAN_MB[0]) + mbOffset); + /*PRQA S 0303 --*/ + } + + return retVal; +} + +/** + * @brief Set TX message buffer.It copys user's buffer into the message buffer + * data area and configure the message buffer as required for transmission. + * + * @param[in] id: select the CAN ID + * @param[in] mbIdx: MB index + * @param[in] messInfo: message info config + * @param[in] msgId: config message id + * @param[in] msgData: message data + * @param[in] code: code command + * @param[in] localPrio: priority + * + * @return + * -SUCC: set tx MB successfully + * -ERR: fail to tx MB + */ +static ResultStatus_t CAN_SetTxMb(CAN_Id_t id, uint8_t mbIdx, + const CAN_MessageInfo_t *messInfo, + uint32_t msgId, const uint8_t *msgData, + uint32_t code, uint8_t localPrio) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + uint8_t cnt; + uint8_t tmpNum; + uint8_t tmpIndex; + uint32_t dlc; + uint32_t dataSize; + CAN_FdMbRegion_t region; + CAN_Mb_t *mbAddr; + volatile uint8_t *mbData; + ResultStatus_t retVal = SUCC; + if(ERR == CAN_GetMbAddr(id, mbIdx, ®ion, &mbAddr)) + { + retVal = ERR; + } + else if(messInfo->dataLen > 64U) + { + retVal = ERR; + } + else + { + mbData = (volatile uint8_t *)(&mbAddr->data[0]); + + if(ERR == CAN_CheckMbId(id,mbIdx)) + { + retVal = ERR; + } + else + { + if(CANx->CAN_MCR.FDEN != 0U) + { + if(ENABLE == messInfo->brsEn ) + { + CANx->CAN_FDCTRL.FD_RATE = 1U; + } + } + if(messInfo->dataLen > CAN_GetPayloadSize(id,region)) + { + retVal = ERR; + } + else + { + CAN_ComputeDlcAndDataSize(messInfo->dataLen,&dlc, &dataSize); + + /* Copy user's buffer into the message buffer data area */ + if(msgData != NULL) + { + tmpNum = (uint8_t)(messInfo->dataLen / 4U); + for (cnt = 0; cnt < tmpNum; cnt += 1U) + { + mbAddr->data[cnt] = ((uint32_t)msgData[cnt*4U] << 24U) | + ((uint32_t)msgData[cnt*4U + 1U] << 16U)| + ((uint32_t)msgData[cnt*4U + 2U] << 8U) | + (uint32_t)msgData[cnt*4U + 3U]; + } + + for ( cnt = tmpNum*4U; cnt < messInfo->dataLen; cnt++) + { + tmpIndex = CAN_SWAP_BYTES_IN_WORD_INDEX(cnt) & 0x3FU; + mbData[tmpIndex] = msgData[cnt]; + } + /* Add padding, if needed */ + for (cnt = messInfo->dataLen; cnt < (uint8_t)dataSize; cnt++) + { + tmpIndex = CAN_SWAP_BYTES_IN_WORD_INDEX(cnt) & 0x3FU; + mbData[tmpIndex] = messInfo->fdPadding; + } + } + + mbAddr->config.WORDVAL = 0U; + mbAddr->id.WORDVAL = 0U; + /* set DLC */ + mbAddr->config.BF.DLC = dlc; + + /* Set the ID according the format structure */ + if (CAN_MSG_ID_EXT == messInfo->idType) + { + /* ID [28-0] */ + mbAddr->id.WORDVAL = msgId & CAN_ID_EXT_MASK; + mbAddr->id.BF.PRIO = localPrio; + /* Set IDE */ + mbAddr->config.BF.IDE = 1U; + /* Clear SRR bit */ + mbAddr->config.BF.SRR = 0U; + } + else + { + /* ID[28-18] */ + mbAddr->id.BF.ID_STANDARD = msgId; + mbAddr->id.BF.PRIO = localPrio; + + /* clear IDE */ + mbAddr->config.BF.IDE = 0U; + /* Clear SRR bit */ + mbAddr->config.BF.SRR = 0U; + } + + if(SET == messInfo->remoteFlag ) + { + /* Set RTR bit */ + mbAddr->config.BF.RTR = 1U; + } + + /* Set MB CODE */ + + /* Reset the code */ + mbAddr->config.BF.CODE = 0U; + + if (ENABLE == messInfo->fdEn ) + { + mbAddr->config.BF.EDL = 1U; + } + + mbAddr->config.BF.BRS = (uint32_t)(messInfo->brsEn); + + /* Set the code */ + mbAddr->config.BF.CODE = code; + + } + + } + + } + + return retVal; +} + +/** + * @brief Set Rx message buffer. It copys user's buffer into the message buffer + * data area and configure the message buffer as required for transmission. + * + * @param[in] id: select the CAN ID + * @param[in] mbIdx: MB index + * @param[in] messInfo: CAN Message infomation + * @param[in] msgId: config message id + * @param[in] code: code command + * + * @return ERR/SUCC + */ +static ResultStatus_t CAN_SetRxMb(CAN_Id_t id, uint8_t mbIdx, + const CAN_MessageInfo_t *messInfo, + uint32_t msgId, uint32_t code) +{ + CAN_FdMbRegion_t region; + CAN_Mb_t *mbAddr; + ResultStatus_t retVal = SUCC; + if(ERR == CAN_GetMbAddr(id, mbIdx, ®ion, &mbAddr)) + { + retVal = ERR; + } + else if(ERR == CAN_CheckMbId(id,mbIdx)) + { + retVal = ERR; + } + else + { + mbAddr->config.WORDVAL = 0U; + mbAddr->id.WORDVAL = 0U; + + /* Set the ID according the format structure */ + if (CAN_MSG_ID_EXT == messInfo->idType) + { + /* ID [28-0] */ + mbAddr->id.WORDVAL = msgId & CAN_ID_EXT_MASK; + /* Set IDE */ + mbAddr->config.BF.IDE = 1U; + /* Clear SRR bit */ + mbAddr->config.BF.SRR = 0U; + } + else + { + /* ID[28-18] */ + mbAddr->id.BF.ID_STANDARD = msgId; + + /* clear IDE */ + mbAddr->config.BF.IDE = 0U; + /* Clear SRR bit */ + mbAddr->config.BF.SRR = 0U; + } + + if(code != CAN_NOT_USED) + { + mbAddr->config.BF.CODE = code; + } + + } + + return retVal; +} + + +/** + * @brief Clears CAN memory positions that require initialization. + * + * @param[in] id: select the CAN ID + * + * @return none + * + */ +static void CAN_ClearRam(CAN_Id_t id) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + can_reg_w_t * CANxw = (can_reg_w_t *)(canRegWPtr[id]); + uint32_t databyte; + uint32_t ramSize = CAN_RAM_SIZE_IN_WORD; + uint32_t rxImrSize = CAN_MAX_MB_NUM; + volatile uint32_t *RAM = &(CANxw->CAN_MB[0].MB0); + + CANx->CAN_CTRL2.WRMFRZ = 1U; + /* Clear MB region */ + for (databyte = 0U; databyte < ramSize; databyte++) + { + RAM[databyte] = 0x0U; + } + + RAM = &(CANxw->CAN_RXIMR[0]); + + /* Clear RXIMR region */ + for (databyte = 0U; databyte < rxImrSize; databyte++) + { + RAM[databyte] = 0xFFFFFFFFU; + } + + /* init mask */ + CANxw->CAN_RXMGMSK = 0xFFFFFFFFU; + CANxw->CAN_RX14MASK = 0xFFFFFFFFU; + CANxw->CAN_RX15MASK = 0xFFFFFFFFU; + + /* RX FIFO global mask */ + CANxw->CAN_RXFGMASK = 0xFFFFFFFFU; + + /* RX FIFO */ + /*PRQA S 0303,0306 ++*/ + RAM = (volatile uint32_t*)((uint32_t)canRegPtr[id] + CAN_RAM_RX_FIFO_ADDR); + /*PRQA S 0303,0306 --*/ + for (databyte = 0U; databyte < CAN_RAM_RX_FIFO_LEN_IN_WORD; databyte++) + { + RAM[databyte] = 0U; + } + + /* RXMGMASK, RXFGMASK, RX14MSK, RX15MASK */ + /*PRQA S 0303,0306 ++*/ + RAM = (volatile uint32_t*)((uint32_t)canRegPtr[id] + CAN_RAM_MSK_ADDR); + /*PRQA S 0303,0306 --*/ + for (databyte = 0U; databyte < CAN_RAM_MSK_LEN_IN_WORD; databyte++) + { + RAM[databyte] = 0xFFFFFFFFU; + } + + /* Rx_SMB0, Rx_SMB1 */ + /*PRQA S 0303,0306 ++*/ + RAM = (volatile uint32_t*)((uint32_t)canRegPtr[id] + CAN_RAM_RX_SMB_ADDR); + /*PRQA S 0303,0306 --*/ + for (databyte = 0U; databyte < CAN_RAM_RX_SMB_LEN_IN_WORD; databyte++) + { + RAM[databyte] = 0U; + } + + /* CAN-FD scratch memory */ + /*PRQA S 0303,0306 ++*/ + RAM = (volatile uint32_t*)((uint32_t)canRegPtr[id] + + CAN_RAM_FD_SCRATCH_ADDR); + /*PRQA S 0303,0306 --*/ + for (databyte = 0U; databyte < CAN_RAM_FD_SCRATCH_LEN_IN_WORD; databyte++) + { + RAM[databyte] = 0U; + } + CANx->CAN_CTRL2.WRMFRZ = 0U; +} + +/** + * @brief CAN interrupt handler + * + * @param[in] none + * + * @return none + * + */ +static void CAN_IntHandler(CAN_Id_t id) +{ + uint32_t status1; + uint32_t status2; + uint32_t status3; + uint32_t mbStatus1; + uint32_t mbStatus2; + uint32_t intId; + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + can_reg_w_t * CANxw = (can_reg_w_t *)(canRegWPtr[id]); + uint32_t totalMbNum = CANx->CAN_MCR.MAXMB + (uint32_t)1U; + uint32_t maxMb; + + + /* get status except MBs status */ + canESR1Buf[id] = CANxw->CAN_ESR1; + + status1 = canESR1Buf[id]; + /* only check enabled interrupts */ + status1 = status1 & canIntMaskStatus1[id]; + /* clear int status */ + CANxw->CAN_ESR1 = status1; + + status2 = CANxw->CAN_ERRSR; + /* only check enabled interrupts */ + status2 = status2 & (CANxw->CAN_MECR & CAN_INT_MSK_MULTI_3); + /* clear int status */ + CANxw->CAN_ERRSR = status2; + + status3 = CANxw->CAN_WU_MTC; + /* only check enabled interrupts */ + status3 = status3 & (CANxw->CAN_CTRL1_PN & CAN_INT_MSK_MULTI_4); + /* clear int status */ + CANxw->CAN_WU_MTC = status3; + + /* get status for MB0-31 */ + mbStatus1 = CANxw->CAN_IFLAG1; + mbStatus1 &= CANxw->CAN_IMASK1; + + /* get status for MB32-63 */ + mbStatus2 = CANxw->CAN_IFLAG2; + mbStatus2 &= CANxw->CAN_IMASK2; + + if(mbStatus1 != 0U) + { + maxMb = (totalMbNum > 32U) ? 32U : totalMbNum; + for(uint32_t mbId = 0U; mbId < maxMb; mbId++) + { + if((mbStatus1 & (0x00000001UL << mbId)) != 0U) + { + if((CANx->CAN_MCR.RFEN != 0U) && (mbId <= CAN_RXFIFO_OVERFLOW)) + { + /* RX FIFO frame available interrupt */ + if(CAN_RXFIFO_FRAME_AVAILABLE == mbId) + { + if(canIsrCbFunc[id].cbf[CAN_INT_RXFIFO_FRAME] != NULL) + { + canIsrCbFunc[id].cbf[CAN_INT_RXFIFO_FRAME](); + } + else + { + CANxw->CAN_IMASK1 &= ~CAN_INT_MSK_FLAG_RXFIFO_FRAME; + } + } + /* RX FIFO warning interrupt */ + if(CAN_RXFIFO_WARNING == mbId) + { + if(canIsrCbFunc[id].cbf[CAN_INT_RXFIFO_WARNING] != NULL) + { + canIsrCbFunc[id].cbf[CAN_INT_RXFIFO_WARNING](); + } + else + { + CANxw->CAN_IMASK1 &= ~ + CAN_INT_MSK_FLAG_RXFIFO_WARNING; + } + } + /* RX FIFO overflow interrupt */ + if(CAN_RXFIFO_OVERFLOW == mbId) + { + if(canIsrCbFunc[id].cbf[CAN_INT_RXFIFO_OVERFLOW] != NULL) + { + canIsrCbFunc[id].cbf[CAN_INT_RXFIFO_OVERFLOW](); + } + else + { + CANxw->CAN_IMASK1 &= ~ + CAN_INT_MSK_FLAG_RXFIFO_OVERFLOW; + } + } + } + else + { + if(canIsrCbFunc[id].mbCbf != NULL) + { + canIsrCbFunc[id].mbCbf(mbId); + } + else + { + CANxw->CAN_IMASK1 &= ~(0x00000001UL<CAN_IFLAG1 = 0x00000001UL< 32U) + { + if(mbStatus2 != 0U) + { + maxMb = totalMbNum - 32U; + for(uint32_t mbId = 0U; mbId < maxMb; mbId++) + { + if((mbStatus2 & (0x00000001UL<CAN_IMASK1 &= ~(0x00000001UL<CAN_IFLAG2 = 0x00000001UL<CAN_MCR.MDIS) + { + if(CAN_EnterFreezeMode(id) != SUCC) + { + retVal = ERR; + } + else if(CAN_Disable(id) != SUCC) + { + retVal = ERR; + } + else + { + /*nothing to do */ + } + } + if(SUCC == retVal) + { + if(CAN_Enable(id) != SUCC) + { + retVal = ERR; + } + else if(CAN_EnterFreezeMode(id) != SUCC) + { + retVal = ERR; + } + else + { + /* soft reset */ + CANx->CAN_MCR.SOFTRST = 1; + cnt = 0U; + while(cnt < CAN_TIMEOUT_WAIT_CNT_2) + { + cnt++; + if(0U == CANx->CAN_MCR.SOFTRST ) + { + break; + } + } + if(cnt >= CAN_TIMEOUT_WAIT_CNT_2) + { + retVal = ERR; + } + } + } + if(SUCC == retVal) + { + #if (1U == CAN_ABORT_EN ) + CANx->CAN_MCR.AEN = 1U; + #else + CANx->CAN_MCR.AEN = 0; + #endif + /* clear ram */ + CAN_ClearRam(id); + + /* Disable all MB interrupts */ + CANxw->CAN_IMASK1 = 0U; + CANxw->CAN_IMASK2 = 0U; + /* Clear all MB interrupt flags */ + CANxw->CAN_IFLAG1 = 0xFFFFFFFFU; + CANxw->CAN_IFLAG2 = 0xFFFFFFFFU; + + /* Clear all error interrupt flags */ + CANxw->CAN_ESR1 = CAN_INT_MSK_FLAG_ALL_1; + CANxw->CAN_ERRSR = CAN_INT_MSK_FLAG_ALL_2; + /* set FD */ + CANx->CAN_MCR.FDEN = (uint32_t)(config->fdEn); + + CANx->CAN_MCR.IRMQ = 1; + + /* Enable the use of extended bit time definitions */ + CANx->CAN_CBT.BTF = (uint32_t)(config->fdEn); + + /* Disable Transmission Delay Compensation by default */ + CANx->CAN_FDCTRL.TDCEN = 0U; + + /* enables the CAN FD protocol according to ISO specification (ISO 11898-1)*/ + CANx->CAN_CTRL2.ISOCANFDEN = (uint32_t)(config->fdEn); + + if(ENABLE == config->fdEn ) + { + /* set payload */ + CANx->CAN_FDCTRL.MBDSR0 = (uint32_t)(config->payload0); + CANx->CAN_FDCTRL.MBDSR1 = (uint32_t)(config->payload1); + + /* set FD timing */ + if(ERR == CAN_SetFdArbBitTiming(id, &(config->bitTiming))) + { + retVal = ERR; + } + else if(ERR == CAN_SetFdDataBitTiming(id, &(config->bitTimingFdData))) + { + retVal = ERR; + } + else + { + /*nothing to do*/ + } + } + else + { + /* set CAN timing */ + if(ERR == CAN_SetStdBitTiming(id, &(config->bitTiming))) + { + retVal = ERR; + } + } + } + if(SUCC == retVal) + { + if((config->mbMaxNum > CAN_GetMaxMbNumLimit(id)) || + (config->mbMaxNum > CAN_MAX_MB_NUM)) + { + retVal = ERR; + } + else + { + CANx->CAN_MCR.MAXMB = config->mbMaxNum - 1U; + } + } + if(SUCC == retVal) + { + /* Disable the self reception feature if CAN is not in loopback mode. */ + if (config->mode != CAN_MODE_LOOPBACK) + { + CANx->CAN_MCR.SRXDIS = 1U; + } + + /* config RX FIFO */ + if(ENABLE == config->rxFifoEn ) + { + if(ENABLE == config->fdEn ) + { + retVal = ERR; + } + else + { + /* Enable RX FIFO */ + CANx->CAN_MCR.RFEN = 1; + + /* Set the number of the RX FIFO filters needed */ + CANx->CAN_CTRL2.RFFN = (uint32_t)(config->rxFifoIdFilterNum); + + CANx->CAN_MCR.DMAE = (uint32_t)(config->transferType); + + /* RX FIFO global mask, take in consideration all filter fields*/ + CANxw->CAN_RXFGMASK = 0xFFFFFFFFU; + } + + } + else + { + /* Disable RX FIFO */ + CANx->CAN_MCR.RFEN = 0U; + + if( CAN_RXFIFO_DMA == config->transferType) + { + retVal = ERR; + } + } + } + if(SUCC == retVal) + { + /* CAN is able to enter into doze mode when received entering wait-mode + request */ + CANx->CAN_MCR.DOZE = 1U; + + if(SUCC != CAN_SetOperationMode(id, config->mode)) + { + retVal = ERR; + } + else + { + CAN_DisableMemErrorDetection(id); + } + } + + return retVal; + +} + +/** + * @brief Deinit the CAN peripheral. This function disables all CAN + interrupts, and disable the CAN + * + * @param[in] id: select the CAN ID + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_Deinit(CAN_Id_t id) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + ResultStatus_t retVal = SUCC; + if(SUCC != CAN_IntMask(id, CAN_INT_ALL,MASK, 0U, 0U)) + { + retVal = ERR; + } + else + { + if(0U == CANx->CAN_MCR.MDIS) + { + if(CAN_EnterFreezeMode(id) != SUCC) + { + retVal = ERR; + } + else if(CAN_Disable(id) != SUCC) + { + retVal = ERR; + } + else + { + /*nothing to do*/ + } + + } + } + + return retVal; +} + +/** + * @brief Set operation mode. + * + * @param[in] id: select the CAN ID + * @param[in] mode: select the CAN operation mode + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_SetOperationMode(CAN_Id_t id, CAN_Mode_t mode) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + ResultStatus_t retVal = SUCC; + uint32_t freeze = CANx->CAN_MCR.FRZACK; + if (0U == freeze) + { + if(CAN_EnterFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + if(SUCC == retVal) + { + switch(mode) + { + case CAN_MODE_NORMAL: + CANx->CAN_CTRL1.LOM = 0; + CANx->CAN_CTRL1.LPB = 0; + CANx->CAN_MCR.SUPV = 0; + break; + case CAN_MODE_LISTEN_ONLY: + CANx->CAN_CTRL1.LOM = 1; + CANx->CAN_CTRL1.LPB = 0; + break; + case CAN_MODE_LOOPBACK: + CANx->CAN_CTRL1.LOM = 0; + CANx->CAN_CTRL1.LPB = 1; + CANx->CAN_MCR.SRXDIS = 0; + CANx->CAN_FDCTRL.TDCEN = 0; + break; + case CAN_MODE_FREEZE: + break; + + case CAN_MODE_DISABLE: + CANx->CAN_MCR.MDIS = 1; + break; + default: + /*nothing to do*/ + break; + } + if(CAN_MODE_FREEZE != mode) + { + if(CAN_ExitFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + } + + return retVal; +} + +/** + * @brief Disable/Enable self reception. + * + * @param[in] id: select the CAN ID + * @param[in] ctrl: ENABLE/DISABLE + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_SetSelfRec(CAN_Id_t id, ControlState_t ctrl) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + uint32_t freeze = CANx->CAN_MCR.FRZACK; + ResultStatus_t retVal = SUCC; + if (0U == freeze) + { + if(CAN_EnterFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + if(SUCC == retVal) + { + CANx->CAN_MCR.SRXDIS = (ctrl == ENABLE) ? 0U : 1U; + + if (0U == freeze) + { + if(CAN_ExitFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + } + + return retVal; +} + +/** + * @brief Select TX Priority mode. + * + * @param[in] id: select the CAN ID + * @param[in] mode: select the CAN TX priority mode + * + * @return status + * - SUCC -- successful + * - ERR -- some error + */ +ResultStatus_t CAN_SelectTxPriorityMode(CAN_Id_t id, CAN_TxPriMode_t mode) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + uint32_t freeze = CANx->CAN_MCR.FRZACK; + ResultStatus_t retVal = SUCC; + if (0U == freeze) + { + if(CAN_EnterFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + if(SUCC == retVal) + { + if(CAN_TX_PRI_LOW_NUM_MB_FIRST == mode ) + { + CANx->CAN_CTRL1.LBUF = 1U; + } + else if(CAN_TX_PRI_HIGH_PRI_FIRST == mode ) + { + CANx->CAN_CTRL1.LBUF = 0U; + CANx->CAN_MCR.LPRIOEN = 0U; + } + else if(CAN_TX_PRI_LOCAL_PRI_EN == mode ) + { + CANx->CAN_CTRL1.LBUF = 0U; + CANx->CAN_MCR.LPRIOEN = 1U; + } + else + { + /*nothing to do*/ + } + + if (0U == freeze) + { + if(CAN_ExitFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + } + + return retVal; +} +/** + * @brief Enable CAN. + * + * @param[in] id: select the CAN ID + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_Enable(CAN_Id_t id) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + volatile uint32_t cnt = 0U; + ResultStatus_t retVal = SUCC; + if(CANx->CAN_MCR.LPMACK != 0U) + { + CANx->CAN_MCR.MDIS = 0U; + + while(cnt < CAN_TIMEOUT_WAIT_CNT_2) + { + cnt++; + if(0U == CANx->CAN_MCR.LPMACK ) + { + retVal = SUCC; + break; + } + } + if(cnt >= CAN_TIMEOUT_WAIT_CNT_2) + { + retVal = ERR; + } + + } + + return retVal; +} + +/** + * @brief Disable CAN. + * + * @param[in] id: select the CAN ID + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_Disable(CAN_Id_t id) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + volatile uint32_t cnt = 0U; + ResultStatus_t retVal = SUCC; + if(0U == CANx->CAN_MCR.MDIS) + { + /* Clock disable (module) */ + CANx->CAN_MCR.MDIS = 1U; + + while(cnt < CAN_TIMEOUT_WAIT_CNT_2) + { + cnt++; + if(1U == CANx->CAN_MCR.LPMACK ) + { + retVal = SUCC; + break; + } + } + if(cnt>=CAN_TIMEOUT_WAIT_CNT_2) + { + retVal = ERR; + } + } + + return retVal; +} + + +/** + * @brief Sets the CAN bit timing for standard frames or the arbitration + * phase of FD frames. + * + * @param[in] id: select the CAN ID + * @param[in] timeSeg: A pointer to the CAN bit timing settings + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_SetStdBitTiming(CAN_Id_t id, const CAN_BitTiming_t *timeSeg) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + ResultStatus_t retVal = SUCC; + uint32_t freeze = CANx->CAN_MCR.FRZACK; + + if (0U == freeze) + { + if(CAN_EnterFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + if(SUCC == retVal) + { + /* Set time segments*/ + if((0U == timeSeg->propSeg)||(0U == timeSeg->phaseSeg1) || + (timeSeg->phaseSeg2 < 1U) || (0U == timeSeg->preDivider)|| + (0U == timeSeg->rJumpwidth)) + { + retVal = ERR; + } + else + { + CANx->CAN_CTRL1.PROPSEG = timeSeg->propSeg - 1U; + CANx->CAN_CTRL1.PSEG2 = timeSeg->phaseSeg2 - 1U; + CANx->CAN_CTRL1.PSEG1 = timeSeg->phaseSeg1 - 1U; + CANx->CAN_CTRL1.PRESDIV = timeSeg->preDivider - 1U; + CANx->CAN_CTRL1.RJW = timeSeg->rJumpwidth - 1U; + + if (0U == freeze) + { + if(CAN_ExitFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + } + } + + return retVal; +} + +/** + * @brief Sets the CAN bit timing for the arbitration phase of FD frames of + CAN. + * + * @param[in] id: select the CAN ID + * @param[in] timeSeg: A pointer to the CAN bit timing settings + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_SetFdArbBitTiming(CAN_Id_t id, + const CAN_BitTiming_t *timeSeg) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + uint32_t freeze = CANx->CAN_MCR.FRZACK; + ResultStatus_t retVal = SUCC; + if (0U == freeze) + { + if(CAN_EnterFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + + if(SUCC == retVal) + { + /* Set time segments*/ + if((0U == timeSeg->propSeg)||(0U == timeSeg->phaseSeg1) || + (timeSeg->phaseSeg2 < 1U) || (0U == timeSeg->preDivider)|| + (0U == timeSeg->rJumpwidth)) + { + retVal = ERR; + } + else + { + CANx->CAN_CBT.EPROPSEG = timeSeg->propSeg - 1U; + CANx->CAN_CBT.EPSEG2 = timeSeg->phaseSeg2 - 1U; + CANx->CAN_CBT.EPSEG1 = timeSeg->phaseSeg1 - 1U; + CANx->CAN_CBT.EPRESDIV = timeSeg->preDivider - 1U; + CANx->CAN_CBT.ERJW = timeSeg->rJumpwidth - 1U; + } + } + if(SUCC == retVal) + { + if (0U == freeze) + { + if(CAN_ExitFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + } + + return retVal; +} + +/** + * @brief Sets the CAN bit timing for the data phase of FD frames. + * Those time segment values are passed in by the user and are based + * on the required baudrate. + * + * @param[in] id: select the CAN ID + * @param[in] timeSeg: A pointer to the CAN bit timing settings + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_SetFdDataBitTiming(CAN_Id_t id, + const CAN_BitTiming_t *timeSeg) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + uint32_t freeze = CANx->CAN_MCR.FRZACK; + ResultStatus_t retVal = SUCC; + if (0U == freeze) + { + if(CAN_EnterFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + if(SUCC == retVal) + { + /* Set time segments*/ + if((0U == timeSeg->propSeg)||(0U == timeSeg->phaseSeg1) || + (timeSeg->phaseSeg2 < 1U) || (0U == timeSeg->preDivider)|| + (0U == timeSeg->rJumpwidth)) + { + retVal = ERR; + } + else + { + CANx->CAN_FDCBT.FPROPSEG = timeSeg->propSeg; + CANx->CAN_FDCBT.FPSEG2 = timeSeg->phaseSeg2 - 1U; + CANx->CAN_FDCBT.FPSEG1 = timeSeg->phaseSeg1 - 1U; + CANx->CAN_FDCBT.FPRESDIV = timeSeg->preDivider - 1U; + CANx->CAN_FDCBT.FRJW = timeSeg->rJumpwidth - 1U; + if (0U == freeze) + { + if(CAN_ExitFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + } + } + + return retVal; +} + +/** + * @brief Sets the Rx masking type. + * + * @param[in] id: select the CAN ID + * @param[in] type: select RX mask type + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_SetRxMaskType(CAN_Id_t id, CAN_RxMask_t type) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + uint32_t freeze = CANx->CAN_MCR.FRZACK; + ResultStatus_t retVal = SUCC; + if (0U == freeze) + { + if(CAN_EnterFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + + if(SUCC == retVal) + { + CANx->CAN_MCR.IRMQ = (uint32_t)type; + + if (0U == freeze) + { + if(CAN_ExitFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + } + + return retVal; +} + +/** + * @brief Sets the CAN Rx MB global mask (standard or extended) + * + * @param[in] id: select the CAN ID + * @param[in] idType: Standard ID or extended ID + * @param[in] mask:Mask Value. 11-bit standard mask or 29-bit extended mask + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_SetRxMbGlobalMask(CAN_Id_t id, CAN_MsgId_t idType, + uint32_t mask) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + can_reg_w_t * CANxw = (can_reg_w_t *)(canRegWPtr[id]); + uint32_t freeze = CANx->CAN_MCR.FRZACK; + ResultStatus_t retVal = SUCC; + if (0U == freeze) + { + if(CAN_EnterFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + if(SUCC == retVal) + { + if (CAN_MSG_ID_STD == idType ) + { + CANxw->CAN_RXMGMSK = CAN_CAL_RX_MB_STD_MASK(mask); + } + else + { + CANxw->CAN_RXMGMSK = CAN_CAL_RX_MB_EXT_MASK(mask); + } + + if (0U == freeze) + { + if(CAN_ExitFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + } + + return retVal; +} + +/** + * @brief Set Rx Message Buffer 14 mask (standard or extended) + * + * @param[in] id: select the CAN ID + * @param[in] idType: Standard ID or extended ID + * @param[in] mask:Mask Value. 11-bit standard mask or 29-bit extended mask + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_SetRxMb14Mask(CAN_Id_t id, CAN_MsgId_t idType, uint32_t mask) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + can_reg_w_t * CANxw = (can_reg_w_t *)(canRegWPtr[id]); + uint32_t freeze = CANx->CAN_MCR.FRZACK; + ResultStatus_t retVal = SUCC; + if (0U == freeze) + { + if(CAN_EnterFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + if(SUCC == retVal) + { + if (CAN_MSG_ID_STD == idType ) + { + CANxw->CAN_RX14MASK = CAN_CAL_RX_MB_STD_MASK(mask); + } + else + { + CANxw->CAN_RX14MASK = CAN_CAL_RX_MB_EXT_MASK(mask); + } + + if (0U == freeze) + { + if(CAN_ExitFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + } + + return retVal; +} + +/** + * @brief Set Rx Message Buffer 15 mask (standard or extended) + * + * @param[in] id: select the CAN ID + * @param[in] idType: Standard ID or extended ID + * @param[in] mask:Mask Value. 11-bit standard mask or 29-bit extended mask + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_SetRxMb15Mask(CAN_Id_t id, CAN_MsgId_t idType, uint32_t mask) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + can_reg_w_t * CANxw = (can_reg_w_t *)(canRegWPtr[id]); + uint32_t freeze = CANx->CAN_MCR.FRZACK; + ResultStatus_t retVal = SUCC; + if (0U == freeze) + { + if(CAN_EnterFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + if(SUCC == retVal) + { + if (CAN_MSG_ID_STD == idType ) + { + CANxw->CAN_RX15MASK = CAN_CAL_RX_MB_STD_MASK(mask); + } + else + { + CANxw->CAN_RX15MASK = CAN_CAL_RX_MB_EXT_MASK(mask); + } + + if (0U == freeze) + { + if(CAN_ExitFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + } + + return retVal; +} + +/** + * @brief Sets Rx MB individual mask + * + * @param[in] id: select the CAN ID + * @param[in] idType: Standard ID or extended ID + * @param[in] mbIdx: MB index. The MB should not be occupied by RX FIFO if RX + * FIFO is enabled, otherwise, it will return ERR. + * @param[in] mask:Mask Value. 11-bit standard mask or 29-bit extended mask + * + * @return ResultStatus_t + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_SetRxMbIndividualMask(CAN_Id_t id, CAN_MsgId_t idType, + uint32_t mbIdx, uint32_t mask) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + can_reg_w_t * CANxw = (can_reg_w_t *)(canRegWPtr[id]); + ResultStatus_t retVal = SUCC; + + uint32_t freeze = CANx->CAN_MCR.FRZACK; + + if (CAN_CheckMbId(id,mbIdx) != SUCC) + { + retVal = ERR; + } + else if (0U == freeze) + { + if(CAN_EnterFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + else + { + /*nothing to do*/ + } + + if(SUCC == retVal) + { + if (CAN_MSG_ID_STD == idType ) + { + CANxw->CAN_RXIMR[mbIdx] = CAN_CAL_RX_MB_STD_MASK(mask); + } + else + { + CANxw->CAN_RXIMR[mbIdx] = CAN_CAL_RX_MB_EXT_MASK(mask); + } + + if (0U == freeze) + { + if(CAN_ExitFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + } + + return retVal; +} + +/** + * @brief Sets Rx FIFO global mask. It masks the Rx FIFO ID Filter Table + * elements that do not have a corresponding individual mask. + * + * @param[in] id: select the CAN ID + * @param[in] mask:Mask Value. Its format depends on the RX FIFO id filter format. + It should be set as follows: + + Format A ID mask: + bit31 | bit30 | bit29 ... 1 | bit0 + RTR | IDE(0)| IDmask(std:29-19, ext:29-1) | reserved + + Format B ID mask: + bit31 | bit30 | bit29 ... 16 | bit 15 | bit 14 | bit13 ... 0 + RTR | IDE | ID0(std:29-19, ext:29-16) | RTR | IDE | ID1 + (std:13-3, ext:13-0) + + Format C ID mask: + bit31...bit 24 | bit23...bit16 | bit15 ...bit8 | bit7 ... bit0 + IDmask0 | IDmask1 | IDmask2 | IDmask3 + + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_SetRxFifoGlobalMask(CAN_Id_t id, uint32_t mask) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + can_reg_w_t * CANxw = (can_reg_w_t *)(canRegWPtr[id]); + ResultStatus_t retVal = SUCC; + uint32_t freeze = CANx->CAN_MCR.FRZACK; + + if (0U == freeze) + { + if(CAN_EnterFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + if(SUCC == retVal) + { + if (CANx->CAN_MCR.RFEN != 0U) + { + CANxw->CAN_RXFGMASK = mask; + } + + if (0U == freeze) + { + if(CAN_ExitFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + } + + return retVal; +} + +/** + * @brief Sets Rx FIFO individual mask for the specific ID filter table + * element + * + * @param[in] id: select the CAN ID + * @param[in] elementIdx: ID filter table element index. It indicates which + * filter table element the mask is corresponding to. + * It should not exceeds the MB number that is occupied + * by Rx FIFO. + * @param[in] mask:Mask Value. Its format depends on the RX FIFO id filter format. + It should be set as follows: + + Format A ID mask: + bit31 | bit30 | bit29 ... 1 | bit0 + RTR | IDE(0)| IDmask(std:29-19, ext:29-1) | reserved + + Format B ID mask: + bit31 | bit30 | bit29 ... 16 | bit 15 | bit 14 | bit13 ... 0 + RTR | IDE | IDmask0(std:29-19, ext:29-16)| RTR | IDE | IDmask1 + (std:13-3, ext:13-0) + In the extended frame format B, IDmask0/IDmask1 corresponds to + the 14 most significant bits of the received ID + + Format C ID mask: + bit31...bit 24 | bit23...bit16 | bit15 ...bit8 | bit7 ... bit0 + IDmask0 | IDmask1 | IDmask2 | IDmask3 + For format C IDmask corresponds to the 8 most significant bits of the + received ID + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_SetRxFifoIndividualMask(CAN_Id_t id, uint32_t elementIdx, + uint32_t mask) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + can_reg_w_t * CANxw = (can_reg_w_t *)(canRegWPtr[id]); + ResultStatus_t retVal = SUCC; + uint32_t freeze = CANx->CAN_MCR.FRZACK; + + if (0U == freeze) + { + if(CAN_EnterFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + if(SUCC == retVal) + { + if (CANx->CAN_MCR.RFEN != 0U ) + { + if(elementIdx <= CAN_GetNoOfRxFIFOIndividualMask(id)) + { + CANxw->CAN_RXIMR[elementIdx] = mask; + } + } + + if (0U == freeze) + { + if(CAN_ExitFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + } + + return retVal; +} + +/** + * @brief Configure transmit message buffer. + * + * @param[in] id: select the CAN ID + * @param[in] mbIdx: MB index + * @param[in] txInfo: TX MB info + * @param[in] msgId: message ID + * @param[in] localPrio: the local priority field, if the TX priority mode is + * CAN_TX_PRI_LOCAL_PRI_EN, this parameter indicates the + * local priority + * + * @return status + * + * + */ +ResultStatus_t CAN_ConfigTxMb(CAN_Id_t id, uint8_t mbIdx, + const CAN_MessageInfo_t *txInfo, + uint32_t msgId, uint8_t localPrio) +{ + return CAN_SetTxMb(id, mbIdx, txInfo, msgId, NULL, CAN_TX_INACTIVE, + localPrio); +} + +/** + * @brief Configures a transmit message buffer for remote frame response + * + * @param[in] id: select the CAN ID + * @param[in] mbIdx: MB index + * @param[in] txInfo: TX MB info + * @param[in] msgId: message ID + * @param[in] msgData: data of the message + * @param[in] localPrio: the local priority field, if the TX priority mode is + * CAN_TX_PRI_LOCAL_PRI_EN, this parameter indicates the + * local priority + * + * @return status + * + * + */ +ResultStatus_t CAN_ConfigRemoteResponseMb(CAN_Id_t id, uint8_t mbIdx, + const CAN_MessageInfo_t *txInfo, + uint32_t msgId, const uint8_t *msgData, + uint8_t localPrio) +{ + CAN_ClearMbIntStatus(id,mbIdx); + + return CAN_SetTxMb(id, mbIdx, txInfo, msgId, msgData, CAN_RX_RANSWER, + localPrio); +} + +/** + * @brief Configure a Rx message buffer. + * + * @param[in] id: select the CAN ID + * @param[in] mbIdx: MB index + * @param[in] rxInfo: RX MB info + * @param[in] msgId: message ID + * + * @return status + * + * + */ +ResultStatus_t CAN_ConfigRxMb(CAN_Id_t id, uint8_t mbIdx, + const CAN_MessageInfo_t *rxInfo, uint32_t msgId) +{ + ResultStatus_t result; + + /* Clear the message buffer flag if previous remained triggered*/ + CAN_ClearMbIntStatus(id,mbIdx); + + /* Initialize rx mb*/ + result = CAN_SetRxMb(id, mbIdx, rxInfo, msgId, CAN_NOT_USED); + + if(SUCC == result) + { + /* Initialize receive MB*/ + result = CAN_SetRxMb(id, mbIdx, rxInfo, msgId, CAN_RX_INACTIVE); + } + + if (SUCC == result) + { + /* Set up MB for receiving data*/ + result = CAN_SetRxMb(id, mbIdx, rxInfo, msgId, CAN_RX_EMPTY); + } + if (SUCC == result) + { + /* Clear the message buffer flag if previous remained triggered*/ + CAN_ClearMbIntStatus(id,mbIdx); + } + + return result; +} + +/** + * @brief sends a CAN frame. This function sends a CAN frame using + * a configured message buffer. Before calling this function, + * user needs to make sure that the MB to be configured is inactive, + * otherwise, it will return BUSY. + * + * @param[in] id: select the CAN ID + * @param[in] mbIdx: MB index + * @param[in] txInfo: TX MB info + * @param[in] msgId: message ID + * @param[in] msgData: data of the message + * + * @return status + * - SUCC + * - ERR: mbIdx is invalid + * - BUSY: the MB to be configured is not in inactive status + * + */ +ResultStatus_t CAN_Send(CAN_Id_t id, uint8_t mbIdx, + const CAN_MessageInfo_t *txInfo, + uint32_t msgId, const uint8_t *msgData) +{ + CAN_FdMbRegion_t region; + CAN_Mb_t *mbAddr; + uint32_t code; + ResultStatus_t retVal = SUCC; + if(ERR == CAN_GetMbAddr(id, mbIdx, ®ion, &mbAddr)) + { + retVal = ERR; + } + /* check if it is a valid MB */ + else if(ERR == CAN_CheckMbId(id, mbIdx)) + { + retVal = ERR; + } + else + { + code = mbAddr->config.BF.CODE; + if((code != (uint32_t)CAN_MB_RX_INACTIVE) && + (code != (uint32_t)CAN_MB_TX_INACTIVE) && + (code != (uint32_t)CAN_MB_TX_ABORT)) + { + retVal = BUSY; + } + else + { + CAN_ClearMbIntStatus(id, mbIdx); + retVal = CAN_SetTxMb(id, mbIdx, txInfo, msgId, msgData, + CAN_TX_DATA_REMOTE, 0U); + } + } + + return retVal; + +} + +/** + * @brief Sends a CAN frame when the TX priority mode is CAN_TX_PRI_LOCAL_PRI_EN + * This function sends a CAN frame using a configured message buffer. + * It also configures the local priority. Before calling this + * function, user needs to make sure that the MB to be configured + * is inactive, otherwise, it will return BUSY. + * + * + * @param[in] id: select the CAN ID + * @param[in] mbIdx: MB index + * @param[in] txInfo: TX MB info + * @param[in] msgId: message ID + * @param[in] msgData: data of the message + * @param[in] localPrio: the local priority field for the MB + * + * @return status + * - SUCC + * - ERR: mbIdx is invalid + * - BUSY: the MB to be configured is not in inactive status + * + */ +ResultStatus_t CAN_SendwithLocalPrio(CAN_Id_t id, uint8_t mbIdx, + const CAN_MessageInfo_t *txInfo, + uint32_t msgId, const uint8_t *msgData, + uint8_t localPrio) +{ + CAN_FdMbRegion_t region; + CAN_Mb_t *mbAddr; + uint32_t code; + ResultStatus_t retVal = SUCC; + if(ERR == CAN_GetMbAddr(id, mbIdx, ®ion, &mbAddr)) + { + retVal = ERR; + } + else if(ERR == CAN_CheckMbId(id, mbIdx)) + { + retVal = ERR; + } + else + { + code = mbAddr->config.BF.CODE; + if((code != (uint32_t)CAN_MB_RX_INACTIVE) && + (code != (uint32_t)CAN_MB_TX_INACTIVE) && + (code != (uint32_t)CAN_MB_TX_ABORT)) + { + retVal = BUSY; + } + else + { + CAN_ClearMbIntStatus(id, mbIdx); + retVal = CAN_SetTxMb(id, mbIdx, txInfo, msgId, msgData, + CAN_TX_DATA_REMOTE, localPrio); + } + + } + + return retVal; + +} + +/** + * @brief receive a CAN frame into a configured MB. Before calling this + * function, user needs to make sure that the MB to be configured + * is inactive, otherwise, it will return BUSY. + * + * @param[in] id: select the CAN ID + * @param[in] mbIdx: MB index + * @param[in] rxInfo: RX MB info + * @param[in] msgId: message ID + * + * @return ResultStatus_t + * - SUCC + * - ERR: mbIdx is invalid + * - BUSY: the MB to be configured is not in inactive status + * + */ +ResultStatus_t CAN_MbReceive(CAN_Id_t id, uint8_t mbIdx, + const CAN_MessageInfo_t *rxInfo, uint32_t msgId) +{ + CAN_FdMbRegion_t region; + CAN_Mb_t *mbAddr; + uint32_t code; + ResultStatus_t retVal = SUCC; + if(ERR == CAN_GetMbAddr(id, mbIdx, ®ion, &mbAddr)) + { + retVal = ERR; + } + /* check if it is a valid MB */ + else if(ERR == CAN_CheckMbId(id, mbIdx)) + { + retVal = ERR; + } + else + { + code = mbAddr->config.BF.CODE; + if((code != (uint32_t)CAN_MB_RX_INACTIVE) && + (code != (uint32_t)CAN_MB_TX_INACTIVE) && + (code != (uint32_t)CAN_MB_TX_ABORT)) + { + retVal = BUSY; + } + else + { + CAN_ClearMbIntStatus(id, mbIdx); + retVal = CAN_ConfigRxMb(id, mbIdx, rxInfo, msgId); + } + + } + + return retVal; +} + +/** + * @brief Configure RX FIFO ID filter table elements + * + * @param[in] id: select the CAN ID + * @param[in] format: the ID filter format + * @param[in] idFilterTable: points to the ID filter table + * + * @note + * The number of elements in the ID filter table is defined by the + * following formula: + * - for format A: the number of Rx FIFO ID filters + * - for format B: twice the number of Rx FIFO ID filters + * - for format C: four times the number of Rx FIFO ID filters + * The user must provide the exact number of elements in order to avoid + * any misconfiguration. + * + * Each element in the ID filter table specifies an ID to be used as + * acceptance criteria for the FIFO as follows: + * - for format A: In the standard frame format, bits 10 to 0 of the ID + * are used for frame identification. In the extended frame format, bits + * 28 to 0 are used. + * - for format B: In the standard frame format, bits 10 to 0 of the ID + * are used for frame identification. In the extended frame format, only + * the 14 most significant bits (28 to 15) of the ID are compared to the + * 14 most significant bits (28 to 15) of the received ID. + * - for format C: In both standard and extended frame formats, only the 8 + * most significant bits(10 to 3 for standard, 28 to 21 for extended) of + * the ID are compared to the 8 most significant bits (10 to 3 for + * standard, 28 to 21 for extended) of the received ID. + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_ConfigRxFifo(CAN_Id_t id, CAN_RxFifoIdFormat_t format, + const CAN_IdFilter_t *idFilterTable) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + can_reg_w_t * CANxw = (can_reg_w_t *)(canRegWPtr[id]); + ResultStatus_t retVal = SUCC; + uint32_t freeze = CANx->CAN_MCR.FRZACK; + uint32_t i; + uint32_t j; + uint32_t filterNum; + uint32_t val1 = 0U; + uint32_t val2 = 0U; + uint32_t val = 0U; + volatile uint32_t *filterTable = &(CANxw->CAN_MB[6].MB0); + + filterNum = (CANx->CAN_CTRL2.RFFN +(uint32_t)1U) * 8U; + + if (0U == freeze) + { + if(CAN_EnterFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + if(SUCC == retVal) + { + /* clear RX FIFO */ + CANx->CAN_IFLAG1.BUF0I = 1U; + switch(format) + { + case (CAN_RX_FIFO_ID_FORMAT_A): + /* One full ID (standard and extended) per ID Filter Table element.*/ + CANx->CAN_MCR.IDAM = (uint32_t)format; + + for (i = 0U; i < filterNum; i++) + { + val = 0U; + + if (SET == idFilterTable[i].isRemoteFrame ) + { + val = 1UL << 31U; + } + if(SET == idFilterTable[i].isExtendedFrame ) + { + val |= 1UL << 30U; + filterTable[i] = val | ((idFilterTable[i].id << 1U) & + 0x3FFFFFFFU); + } + else + { + filterTable[i] = val | ((idFilterTable[i].id << 19U) & + 0x3FFFFFFFU); + } + } + break; + + case (CAN_RX_FIFO_ID_FORMAT_B): + /* Two full standard IDs or two partial 14-bit */ + /*(standard and extended) IDs*/ + /* per ID Filter Table element.*/ + CANx->CAN_MCR.IDAM = (uint32_t)format; + j = 0U; + for (i = 0U; i < filterNum; i++) + { + val1 = 0U; + val2 = 0U; + + if (SET == idFilterTable[j].isRemoteFrame ) + { + val1 = 1UL << 31U; + } + if (SET == idFilterTable[j + 1U].isRemoteFrame ) + { + val2 = 1UL << 15U; + } + if (SET== idFilterTable[j].isExtendedFrame ) + { + val1 |= 1UL << 30U; + + filterTable[i] = val1 | (((idFilterTable[j].id & + 0x1FFF8000U) >> 15U) <<16U); + } + else + { + filterTable[i] = val1 | ((idFilterTable[j].id & 0x7FFU) + << 19U); + } + if (SET == idFilterTable[j + 1U].isExtendedFrame ) + { + val2 |= 1UL << 14U; + + filterTable[i] |= val2 | ((idFilterTable[j + 1U].id & + 0x1FFF8000U) >>15U); + } + else + { + filterTable[i] |= val2 + ((idFilterTable[j + 1U].id & + 0x7FFU) << 3U); + } + j = j + 2U; + } + break; + case (CAN_RX_FIFO_ID_FORMAT_C): + /* Four partial 8-bit Standard IDs per ID Filter Table element.*/ + CANx->CAN_MCR.IDAM = (uint32_t)format; + j = 0U; + for (i = 0U; i < filterNum; i++) + { + if (SET == idFilterTable[j].isExtendedFrame ) + { + filterTable[i] |= (((idFilterTable[j].id & + 0x1FE00000U) >> 21U) << 24U); + } + else + { + filterTable[i] |= (((idFilterTable[j].id & + 0x7F8U) >> 3U) << 24U); + } + if (SET == idFilterTable[j + 1U].isExtendedFrame ) + { + filterTable[i] |= (((idFilterTable[j + 1U].id & + 0x1FE00000U) >> 21U) << 16U); + } + else + { + filterTable[i] |= (((idFilterTable[j + 1U].id & + 0x7F8U) >> 3U) << 16U); + } + if (SET == idFilterTable[j + 2U].isExtendedFrame ) + { + filterTable[i] |= (((idFilterTable[j + 2U].id & + 0x1FE00000U) >> 21U) << 8U); + } + else + { + filterTable[i] |= (((idFilterTable[j + 2U].id & + 0x7F8U) >> 3U) << 8U); + } + if (idFilterTable[j + 3U].isExtendedFrame == SET) + { + filterTable[i] |= ((idFilterTable[j + 3U].id & + 0x1FE00000U) >> 21U); + } + else + { + filterTable[i] |= ((idFilterTable[j + 3U].id & + 0x7F8U) >> 3U); + } + j = j + 4U; + } + break; + case (CAN_RX_FIFO_ID_FORMAT_D): + /* All frames rejected.*/ + CANx->CAN_MCR.IDAM = (uint32_t)format; + break; + default: + /* Should not get here */ + break; + } + + if (0U == freeze) + { + if(CAN_ExitFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + } + + return retVal; +} + +/** + * @brief Get a message buffer field values. + * + * @param[in] id: select the CAN ID + * @param[in] mbIdx: MB index + * @param[in] msgBuff: point to the address where the message buffer will be + * stored + * + * @return status + * + * + */ +ResultStatus_t CAN_GetMsgBuff(CAN_Id_t id, uint32_t mbIdx, + CAN_MsgBuf_t *msgBuff) +{ + can_reg_w_t * CANxw = (can_reg_w_t *)(canRegWPtr[id]); + uint8_t i; + uint8_t tmpNum; + uint8_t tmpIndex; + uint8_t payloadSize; + CAN_FdMbRegion_t region; + CAN_Mb_t *mbAddr; + volatile uint8_t *mbData; + ResultStatus_t retVal = SUCC; + if(ERR == CAN_GetMbAddr(id, (uint8_t)mbIdx, ®ion, &mbAddr)) + { + retVal = ERR; + } + else + { + mbData = (volatile uint8_t *)(&mbAddr->data[0]); + + if(ERR == CAN_CheckMbId(id,mbIdx)) + { + retVal = ERR; + } + else + { + /* Lock the mailbox by reading it */ + (void)(mbAddr->config.WORDVAL); + + payloadSize = + CAN_ComputePayloadSize((uint8_t)(mbAddr->config.BF.DLC)); + if(payloadSize > CAN_GetPayloadSize(id,region)) + { + payloadSize = CAN_GetPayloadSize(id,region); + } + + msgBuff->dataLen = payloadSize; + msgBuff->cs = mbAddr->config.WORDVAL; + if(mbAddr->config.BF.IDE != 0U) + { + msgBuff->msgId = mbAddr->id.WORDVAL & CAN_ID_EXT_MASK; + } + else + { + msgBuff->msgId = mbAddr->id.BF.ID_STANDARD; + } + + tmpNum = payloadSize / 4U; + for (i = 0U ; i < tmpNum; i += 1U) + { + msgBuff->data[i*4U] = + (uint8_t)((mbAddr->data[i] & 0xFF000000U) >> 24U); + msgBuff->data[i*4U + 1U] = + (uint8_t)((mbAddr->data[i] & 0xFF0000U) >> 16U); + msgBuff->data[i*4U + 2U] = + (uint8_t)((mbAddr->data[i] & 0xFF00U) >> 8U); + msgBuff->data[i*4U + 3U] = + (uint8_t)(mbAddr->data[i] & 0xFFU); + } + + for ( i = tmpNum * 4U; i < payloadSize ; i++) + { + tmpIndex = CAN_SWAP_BYTES_IN_WORD_INDEX(i) & 0x3FU; + /* Max allowed value for index is 63 */ + msgBuff->data[i] = mbData[tmpIndex]; + } + + /* Unlock the mailbox by reading the free running timer */ + (void)CANxw->CAN_TIMER; + } + + } + + return retVal; +} + +/** + * @brief Read a frame in RX FIFO. + * + * @param[in] id: select the CAN ID + * @param[in-out] msgBuff: point to the address where the message buffer will + * be stored + * + * @return none + */ +void CAN_ReadRxFifo(CAN_Id_t id, CAN_MsgBuf_t *msgBuff) +{ + can_reg_w_t * CANxw = (can_reg_w_t *)(canRegWPtr[id]); + uint8_t i; + uint8_t tmpNum; + uint8_t tmpIndex; + uint8_t payloadSize; + /*PRQA S 0303 ++*/ + CAN_Mb_t *mbAddr = (CAN_Mb_t *)(uint32_t)&(CANxw->CAN_MB[0].MB0); + /*PRQA S 0303 --*/ + volatile uint8_t *mbData; + + payloadSize = CAN_ComputePayloadSize((uint8_t)mbAddr->config.BF.DLC); + if(payloadSize > CAN_GetPayloadSize(id,CAN_FD_MB_REGION_0)) + { + payloadSize = CAN_GetPayloadSize(id,CAN_FD_MB_REGION_0); + } + + msgBuff->dataLen = payloadSize; + msgBuff->cs = mbAddr->config.WORDVAL; + if(mbAddr->config.BF.IDE != 0U) + { + msgBuff->msgId = mbAddr->id.WORDVAL & CAN_ID_EXT_MASK; + } + else + { + msgBuff->msgId = mbAddr->id.BF.ID_STANDARD; + } + + tmpNum = payloadSize/ 4U; + for (i = 0U ; i < tmpNum; i += 1U) + { + msgBuff->data[i*4U] = + (uint8_t)((mbAddr->data[i] & 0xFF000000U) >> 24U); + msgBuff->data[i*4U + 1U] = + (uint8_t)((mbAddr->data[i] & 0xFF0000U) >> 16U); + msgBuff->data[i*4U + 2U] = + (uint8_t)((mbAddr->data[i] & 0xFF00U) >> 8U); + msgBuff->data[i*4U + 3U] = + (uint8_t)(mbAddr->data[i] & 0xFFU); + } + + mbData = (volatile uint8_t *)(&mbAddr->data[0]); + for (i = tmpNum * 4U; i < payloadSize; i++) + { + tmpIndex = CAN_SWAP_BYTES_IN_WORD_INDEX(i) & 0x3FU; + /* Max allowed value for index is 63 */ + msgBuff->data[i] = mbData[tmpIndex]; + } +} + +/** + * @brief make the MB to inactive status and disable the interrupt of this + * MB. The MBs occupied by RX FIFO can not be handle by this function. + * If MB is RX MB, it will become CAN_MB_RX_INACTIVE after + * this function; if MB is TX MB, it will become CAN_MB_TX_INACTIVE + * or CAN_MB_TX_ABORT after this function. + * + * @param[in] id: select the CAN ID + * @param[in] mbIdx: MB index + * + * @return status + * + * + */ +ResultStatus_t CAN_InactiveMb(CAN_Id_t id, uint8_t mbIdx) +{ + CAN_FdMbRegion_t region; + CAN_Mb_t *mbAddr; + uint32_t code; + ResultStatus_t retVal = SUCC; + volatile uint32_t cnt; + + if(ERR == CAN_GetMbAddr(id, mbIdx, ®ion, &mbAddr)) + { + retVal = ERR; + } + else if(ERR == CAN_CheckMbId(id, mbIdx)) + { + retVal = ERR; + } + else if(ERR == CAN_MbIntMask(id, mbIdx, MASK)) + { + retVal = ERR; + } + else + { + /* clear interrupt status */ + CAN_ClearMbIntStatus(id, mbIdx); + + /* ignore the busy status */ + code = (mbAddr->config.BF.CODE) & (~(uint32_t)CAN_CODE_BUSY_MASK); + + /* MB is already inactive */ + if(((uint32_t)CAN_MB_RX_INACTIVE == code) || + ((uint32_t)CAN_MB_TX_INACTIVE == code) || + ((uint32_t)CAN_MB_TX_ABORT == code)) + { + retVal = SUCC; + } + else if(((uint32_t)CAN_MB_RX_FULL == code) || + ((uint32_t)CAN_MB_RX_EMPTY == code) || + ((uint32_t)CAN_MB_RX_OVERRUN == code) || + ((uint32_t)CAN_MB_RX_RANSWER == code)) + { + cnt = 0U; + /* wait until it is not busy */ + while(cnt < CAN_TIMEOUT_WAIT_CNT_3) + { + cnt++; + if(((mbAddr->config.BF.CODE) & CAN_CODE_BUSY_MASK) == 0U) + { + break; + } + } + if(cnt >= CAN_TIMEOUT_WAIT_CNT_3) + { + retVal = ERR; + } + else + { + mbAddr->config.BF.CODE = (uint32_t)CAN_MB_RX_INACTIVE; + + CAN_ClearMbIntStatus(id, mbIdx); + + retVal = SUCC; + } + + } + else if(((uint32_t)CAN_MB_TX_DATA_REMOTE == code) || + ((uint32_t)CAN_MB_TX_TANSWER == code)) + { + #if(CAN_ABORT_EN == 1U) + mbAddr->config.BF.CODE = (uint32_t)CAN_MB_TX_ABORT; + + cnt = 0U; + /* wait until abort is completed */ + while(cnt < CAN_TIMEOUT_WAIT_CNT_3) + { + cnt++; + if(SET == CAN_GetMbIntStatus(id, mbIdx)) + { + break; + } + } + if(cnt >= CAN_TIMEOUT_WAIT_CNT_3) + { + retVal = ERR; + } + else + { + if(mbAddr->config.BF.CODE == (uint32_t)CAN_MB_TX_ABORT) + { + mbAddr->config.BF.CODE = (uint32_t)CAN_MB_TX_INACTIVE; + } + } + + #else + mbAddr->config.BF.CODE = (uint32_t)CAN_MB_TX_INACTIVE; + #endif + if(SUCC == retVal) + { + CAN_ClearMbIntStatus(id, mbIdx); + } + + } + else + { + /*nothing to do*/ + } + } + + return retVal; +} + +/** + * @brief It selects How CAN recovers from bus off state. If + * CAN_BUS_OFF_RECOV_AUTO is selected, automatic recovering from Bus + * Off state occurs according to the CAN Specification. If + * CAN_BUS_OFF_RECOV_MANUAL is selected, user can call + * CAN_RecoverFromBusOffManually() to recover from bus off state. + * + * @param[in] id: select the CAN ID + * @param[in] recov: It selects how to recover from bus off. + + * @note this function shall be called before entering bus off state. If CAN + * recovers from bus off manually through CAN_RecoverFromBusOffManually(), + * and user need to select CAN_BUS_OFF_RECOV_MANUAL for the next time, + * this function shall be called again. + * + * @return none + * + * + */ +void CAN_BusOffRecoveryScheme(CAN_Id_t id, CAN_BusOffRecovery_t recov) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + + CANx->CAN_CTRL1.BOFFREC = (uint32_t)recov; +} + +/** + * @brief Once CAN is in bus off state and bus off recovery scheme is + * CAN_BUS_OFF_RECOV_MANUAL, which is selected through + * CAN_BusOffRecoveryScheme(), call this function can recover from + * bus off state manually. + * + * @param[in] id: select the CAN ID + * + * @return none + * + * + */ +void CAN_RecoverFromBusOffManually(CAN_Id_t id) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + + CANx->CAN_CTRL1.BOFFREC = 0; +} + +/** + * @brief Enables the Transceiver Delay Compensation feature in CAN FD mode + * and sets the Transceiver Delay Compensation Offset (offset value + * to be added to themeasured transceiver's loop delay in order to + * define the position of the delayed comparison point when bit rate + * switching is active). + * + * @param[in] id: select the CAN ID + * @param[in] offset: Transceiver Delay Compensation Offset + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_FdTdcEnable(CAN_Id_t id, uint8_t offset) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + uint32_t freeze = CANx->CAN_MCR.FRZACK; + ResultStatus_t retVal = SUCC; + if (0U == freeze) + { + if(CAN_EnterFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + if(SUCC == retVal) + { + CANx->CAN_FDCTRL.TDCEN = 1; + CANx->CAN_FDCTRL.TDCOFF = offset; + + if (0U == freeze) + { + if(CAN_ExitFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + } + + return retVal; +} + +/** + * @brief Disables the Transceiver Delay Compensation feature in CAN FD mode + * + * @param[in] id: select the CAN ID + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_FdTdcDisable(CAN_Id_t id) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + uint32_t freeze = CANx->CAN_MCR.FRZACK; + ResultStatus_t retVal = SUCC; + if (0U == freeze) + { + if(CAN_EnterFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + if(SUCC == retVal) + { + CANx->CAN_FDCTRL.TDCEN = 0; + + if (0U == freeze) + { + if(CAN_ExitFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + } + + return retVal; +} + +/** + * @brief Gets the value of the Transceiver Delay Compensation. + * + * @param[in] id: select the CAN ID + * + * @return The value of the transceiver loop delay measured from the transmitted + * EDL to R0 transition edge to the respective received one added to + * the TDCOFF value. + */ +uint8_t CAN_GetTdcValue(CAN_Id_t id) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + + return (uint8_t)(CANx->CAN_FDCTRL.TDCVAL); +} + +/** + * @brief Gets the value of the TDC Fail flag. + * + * @param[in] id: select the CAN ID + * + * @return If SET, indicates that the TDC mechanism is out of range, unable to + * compensate the transceiver's loop delay and successfully compare the + * delayed received bits to the transmitted ones. + */ +FlagStatus_t CAN_GetTdcFail(CAN_Id_t id) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + + return (CANx->CAN_FDCTRL.TDCFAIL != 0U) ? SET : RESET; +} + +/** + * @brief Clears the TDC Fail flag. + * + * @param[in] id: select the CAN ID + * + * @return none + * + */ +void CAN_ClearTdcFail(CAN_Id_t id) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + + CANx->CAN_FDCTRL.TDCFAIL = 1; +} + +/** + * @brief if a message is received by RX FIFO, this function can get the number + * of the ID filter which the received message hit. It is only valid, + * when CAN_IFLAG1[BUF5I] is asserted. + * + * @param[in] id: select the CAN ID + * + * return The number of the ID filter + */ +uint32_t CAN_GetRxFifoIdHit(CAN_Id_t id) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + + return CANx->CAN_RXFIR.IDHIT; +} + +/** + * @brief Set the code of a message buffer + * + * @param[in] id: select the CAN ID + * @param[in] mbIdx: Index of the message buffer. It should not be occupied by + * RX FIFO if RX FIFO is enabled, otherwise, it will return + * ERR. + * @param[in] code: the code to be set + * + * return status + * - ERR mbIdx is invalid, can not find the MB + * - SUCC + */ +ResultStatus_t CAN_SetMbCode(CAN_Id_t id, uint32_t mbIdx, CAN_MbCode_t code) +{ + CAN_Mb_t *mb; + ResultStatus_t retVal = SUCC; + if(ERR == CAN_GetMbAddr(id,(uint8_t)mbIdx,NULL,&mb)) + { + retVal = ERR; + } + else if(ERR == CAN_CheckMbId(id,mbIdx)) + { + retVal = ERR; + } + else + { + mb->config.BF.CODE = (uint32_t)code; + } + + return retVal; +} + +#if (1U == CAN_ABORT_EN ) +/** + * @brief Writes the abort code into the CODE field of the requested Tx message + * buffer to abort transmission. User needs to check if MB transmission + * is aborted or not after this function. It is suggested to use + * CAN_InactiveMb() to abort MB transmission instead of this function. + * + * @param[in] id: select the CAN ID + * @param[in] mbIdx: Index of the message buffer.It should not be occupied by + * RX FIFO if RX FIFO is enabled, otherwise, it will return + * ERR. + * + * @note This function is available only when CAN_ABORT_EN = 1U + * @return status + * - ERR mbIdx is invalid + * - SUCC + */ +ResultStatus_t CAN_AbortTxMb(CAN_Id_t id, uint32_t mbIdx) +{ + return CAN_SetMbCode(id, mbIdx, CAN_MB_TX_ABORT); +} +#endif + +/** + * @brief Enable/Disable global network time mechanism. If enabled, it resets + * the free running timer each time a message is received in message + * buffer 0. This feature provides means to synchronize multiple + * CAN stations with a special "SYNC" message, that is, global + * network time. If Rx FIFO is enabled, the first available mailbox, + * according to CAN_CTRL2[RFFN] setting, is used for timer + * synchronization instead of MB0. + * + * @param[in] id: select the CAN ID + * @param[in] state: ENABLE/DISABLE + * + * return status + * - SUCC -- successful + * - ERR -- some error + */ +ResultStatus_t CAN_ControlGlobalNetworkTime(CAN_Id_t id, ControlState_t state) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + uint32_t freeze = CANx->CAN_MCR.FRZACK; + ResultStatus_t retVal = SUCC; + if (0U == freeze) + { + if(CAN_EnterFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + if(SUCC == retVal) + { + CANx->CAN_CTRL1.TSYC = (uint32_t)state; + + if (0U == freeze) + { + if(CAN_ExitFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + } + + return retVal; +} + +/** + * @brief Get the lowest number inactive MB + * + * @param[in] id: select the CAN ID + * + * return the lowest number inactive MB. + * 0 - 63: the lowest number inactive MB + * 0xFF: it means that there is no inactive MB or it can not be read at + * this moment. + * + */ +uint8_t CAN_GetInactiveMb(CAN_Id_t id) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + uint8_t retVal = 0xFFU; + if(CANx->CAN_ESR2.VPS != 0U) + { + if(CANx->CAN_ESR2.IMB != 0U) + { + retVal = (uint8_t)(CANx->CAN_ESR2.LPTM); + } + } + + /* there is no inactive MB or it can not be read at this moment. */ + return retVal; +} + +/** + * @brief Get the code of a message buffer. + * + * @param[in] id: select the CAN ID + * @param[in] mbIdx: Index of the message buffer. It should not be occupied by + * RX FIFO if RX FIFO is enabled, otherwise, it will return + * ERR. + * @param[in] code: the code will be stored in the memory that pointed by this + * pointer + * + * @return ERR/SUCC + * + * + */ +ResultStatus_t CAN_GetMbCode(CAN_Id_t id, uint32_t mbIdx, uint32_t *code) +{ + CAN_Mb_t *mbAddr; + ResultStatus_t retVal = SUCC; + + if(ERR == CAN_GetMbAddr(id, (uint8_t)mbIdx, NULL, &mbAddr)) + { + retVal = ERR; + } + else if(ERR == CAN_CheckMbId(id,mbIdx)) + { + retVal = ERR; + } + else + { + *code = mbAddr->config.BF.CODE; + } + + return retVal; +} + +/** + * @brief Enable timeout to be a wakeup source for Pretended Networking. + * + * @param[in] id: select the CAN ID + * @param[in] timeout: timeout value. + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_EnablePnTimeoutWakeup(CAN_Id_t id, uint16_t timeout) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + uint32_t freeze = CANx->CAN_MCR.FRZACK; + ResultStatus_t retVal = SUCC; + if (0U == freeze) + { + if(CAN_EnterFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + if(SUCC == retVal) + { + /* set timeout value */ + CANx->CAN_CTRL2_PN.MATCHTO = timeout; + /* enable timeout as a wakeup source */ + if(SUCC != CAN_IntMask(id, CAN_INT_PN_WAKEUP_TIMEOUT, UNMASK,0,0)) + { + retVal = ERR; + } + else + { + if (0U == freeze) + { + if(CAN_ExitFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + } + + } + + return retVal; +} + + +/** + * @brief Disable timeout to be a wakeup source for Pretended Networking. + * + * @param[in] id: select the CAN ID + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_DisablePnTimeoutWakeup(CAN_Id_t id) +{ + return CAN_IntMask(id, CAN_INT_PN_WAKEUP_TIMEOUT, MASK,0,0); +} + +/** + * @brief Enable and config the wakeup source of receiving matched messages + * for Pretended Networking. + * + * @param[in] id: select the CAN ID + * @param[in] config: match wakeup config. + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_EnablePnMatchWakeup(CAN_Id_t id, + const CAN_PnMatchConfig_t *config) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + uint32_t freeze = CANx->CAN_MCR.FRZACK; + ResultStatus_t retVal = SUCC; + if (0U == freeze) + { + if(CAN_EnterFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + if(SUCC == retVal) + { + CANx->CAN_CTRL1_PN.NMATCH = config->numMatches; + CANx->CAN_CTRL1_PN.FCS = (uint32_t)(config->matchScheme); + CANx->CAN_CTRL1_PN.IDFS = (uint32_t)(config->idFilterType); + CANx->CAN_CTRL1_PN.PLFS = (uint32_t)(config->payloadFilterType); + + /* config ID filter1 */ + CANx->CAN_FLT_ID1.FLT_IDE = (uint32_t)(config->idFilter1.idType); + CANx->CAN_FLT_ID1.FLT_RTR = (uint32_t)(config->idFilter1.remoteFlag); + if(CAN_MSG_ID_EXT == config->idFilter1.idType ) + { + CANx->CAN_FLT_ID1.FLT_ID1 = config->idFilter1.id; + } + else + { + CANx->CAN_FLT_ID1.FLT_ID1 = + config->idFilter1.id << CAN_ID_STD_SHIFT; + } + + + /* set the mask for IDE and RTR */ + CANx->CAN_FLT_ID2_IDMASK.IDE_MSK = (uint32_t)(config->idFilter2.idType); + CANx->CAN_FLT_ID2_IDMASK.RTR_MSK = + (uint32_t)(config->idFilter2.remoteFlag); + + /* Configure the ID filter2, if needed */ + /* (as mask for exact matching or higher limit for range matching) */ + if ((CAN_PN_MATCH_EXACT == config->idFilterType) || + (CAN_PN_MATCH_RANGE == config->idFilterType)) + { + /* config ID filter2 */ + if(CAN_MSG_ID_EXT == config->idFilter2.idType ) + { + CANx->CAN_FLT_ID2_IDMASK.FLT_ID2_IDMASK = config->idFilter2.id; + } + else + { + CANx->CAN_FLT_ID2_IDMASK.FLT_ID2_IDMASK = + config->idFilter2.id << CAN_ID_STD_SHIFT; + } + } + + /* config payload match */ + if((CAN_FILTER_ID_PAYLOAD == config->matchScheme) || + (CAN_FILTER_ID_PAYLOAD_NTIMES == config->matchScheme)) + { + CANx->CAN_FLT_DLC.FLT_DLC_LO = config->payloadFilter.dlcLow; + CANx->CAN_FLT_DLC.FLT_DLC_HI = config->payloadFilter.dlcHigh; + CANx->CAN_PL1_LO.DATA_BYTE_0 = config->payloadFilter.payload1[0]; + CANx->CAN_PL1_LO.DATA_BYTE_1 = config->payloadFilter.payload1[1]; + CANx->CAN_PL1_LO.DATA_BYTE_2 = config->payloadFilter.payload1[2]; + CANx->CAN_PL1_LO.DATA_BYTE_3 = config->payloadFilter.payload1[3]; + CANx->CAN_PL1_HI.DATA_BYTE_4 = config->payloadFilter.payload1[4]; + CANx->CAN_PL1_HI.DATA_BYTE_5 = config->payloadFilter.payload1[5]; + CANx->CAN_PL1_HI.DATA_BYTE_6 = config->payloadFilter.payload1[6]; + CANx->CAN_PL1_HI.DATA_BYTE_7 = config->payloadFilter.payload1[7]; + + /* Configure the second payload, if needed */ + /*(as mask for exact matching or higher limit for range matching) */ + if ((CAN_PN_MATCH_EXACT == config->payloadFilterType) || + (CAN_PN_MATCH_RANGE == config->payloadFilterType)) + { + CANx->CAN_PL2_PLMASK_LO.DATA_BYTE_0 = + config->payloadFilter.payload2[0]; + CANx->CAN_PL2_PLMASK_LO.DATA_BYTE_1 = + config->payloadFilter.payload2[1]; + CANx->CAN_PL2_PLMASK_LO.DATA_BYTE_2 = + config->payloadFilter.payload2[2]; + CANx->CAN_PL2_PLMASK_LO.DATA_BYTE_3 = + config->payloadFilter.payload2[3]; + CANx->CAN_PL2_PLMASK_HI.DATA_BYTE_4 = + config->payloadFilter.payload2[4]; + CANx->CAN_PL2_PLMASK_HI.DATA_BYTE_5 = + config->payloadFilter.payload2[5]; + CANx->CAN_PL2_PLMASK_HI.DATA_BYTE_6 = + config->payloadFilter.payload2[6]; + CANx->CAN_PL2_PLMASK_HI.DATA_BYTE_7 = + config->payloadFilter.payload2[7]; + } + } + + /* enable wakeup match */ + if(SUCC != CAN_IntMask(id, CAN_INT_PN_WAKEUP_MATCH, UNMASK,0,0)) + { + retVal = ERR; + } + else + { + if (0U == freeze) + { + if(CAN_ExitFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + } + + } + + return retVal; +} + +/** + * @brief Disable the wakeup source of receiving matched messages + * for Pretended Networking. + * + * @param[in] id: select the CAN ID + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_DisablePnMatchWakeup(CAN_Id_t id) +{ + return CAN_IntMask(id, CAN_INT_PN_WAKEUP_MATCH, MASK,0,0); +} + +/** + * @brief Configures Pretended Networking settings. + * + * @param[in] id: select the CAN ID + * @param[in] pnConfig: Points to the Pretended Networking configuration + * structure. + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_EnablePn(CAN_Id_t id, const CAN_PnConfig_t *pnConfig) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + uint32_t freeze = CANx->CAN_MCR.FRZACK; + ResultStatus_t retVal = SUCC; + if (0U == freeze) + { + if(CAN_EnterFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + if(SUCC == retVal) + { + /* disable self wakeup */ + CANx->CAN_MCR.SLFWAK = 0; + + if(ENABLE == pnConfig->wakeUpTimeout) + { + if(SUCC != CAN_EnablePnTimeoutWakeup(id, pnConfig->timeout)) + { + retVal = ERR; + } + } + } + if(SUCC == retVal) + { + if(ENABLE == pnConfig->wakeUpMatch) + { + if(SUCC != CAN_EnablePnMatchWakeup(id, &(pnConfig->matchConfig))) + { + retVal = ERR; + } + } + } + if(SUCC == retVal) + { + CANx->CAN_MCR.PNET_EN = 1; + + if (0U == freeze) + { + if(CAN_ExitFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + } + + return retVal; +} + +/** + * @brief Disable Pretended Networking settings. + * + * @param[in] id: select the CAN ID + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_DisablePn(CAN_Id_t id) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + uint32_t freeze = CANx->CAN_MCR.FRZACK; + ResultStatus_t retVal = SUCC; + if (0U == freeze) + { + if(CAN_EnterFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + if(SUCC == retVal) + { + CANx->CAN_MCR.PNET_EN = 0; + + if (0U == freeze) + { + if(CAN_ExitFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + } + + return retVal; +} + +/** + * @brief Get a wakeup message buffer field values. + * + * @param[in] id: select the CAN ID + * @param[in] wmbIdx: wakeup MB index. Its range is 0-3. + * @param[in] msgBuff: point to the address where the message buffer will be + * stored. The size is 8 at least. + * + * @return status + * + * + */ +ResultStatus_t CAN_GetWakeupMsgBuff(CAN_Id_t id, uint32_t wmbIdx, + CAN_MsgBuf_t *msgBuff) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + can_reg_w_t * CANxw = (can_reg_w_t *)(canRegWPtr[id]); + + msgBuff->dataLen = (uint8_t)(CANx->CAN_WMB[wmbIdx].CS.DLC); + msgBuff->cs = CANxw->CAN_WMB[wmbIdx].CS; + if(CANx->CAN_WMB[wmbIdx].CS.IDE != 0U) + { + msgBuff->msgId = CANx->CAN_WMB[wmbIdx].ID.ID; + } + else + { + msgBuff->msgId = CANxw->CAN_WMB[wmbIdx].ID >> CAN_ID_STD_SHIFT; + } + + msgBuff->data[0U] = (uint8_t)(CANx->CAN_WMB[wmbIdx].D03.DATA_BYTE_0); + msgBuff->data[1U] = (uint8_t)(CANx->CAN_WMB[wmbIdx].D03.DATA_BYTE_1); + msgBuff->data[2U] = (uint8_t)(CANx->CAN_WMB[wmbIdx].D03.DATA_BYTE_2); + msgBuff->data[3U] = (uint8_t)(CANx->CAN_WMB[wmbIdx].D03.DATA_BYTE_3); + msgBuff->data[4U] = (uint8_t)(CANx->CAN_WMB[wmbIdx].D47.DATA_BYTE_4); + msgBuff->data[5U] = (uint8_t)(CANx->CAN_WMB[wmbIdx].D47.DATA_BYTE_5); + msgBuff->data[6U] = (uint8_t)(CANx->CAN_WMB[wmbIdx].D47.DATA_BYTE_6); + msgBuff->data[7U] = (uint8_t)(CANx->CAN_WMB[wmbIdx].D47.DATA_BYTE_7); + + return SUCC; +} + +/** + * @brief Enable self wakeup function. + * + * @param[in] id: select the CAN ID + * @param[in] intEn: it indicates if the self wakeup interrupt is enabled. + * If it is required to wake up the chip from stop mode + * through self wakeup. intEn has to be set to ENABLE. + * @param[in] filterEn: it indicates if the low-pass filter is enabled to + * protect the Rx CAN input from spurious wake up + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_EnableSelfWakeup(CAN_Id_t id, ControlState_t intEn, + ControlState_t filterEn) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + ResultStatus_t retVal = SUCC; + uint32_t freeze = CANx->CAN_MCR.FRZACK; + + if (0U == freeze) + { + if(CAN_EnterFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + + if(SUCC == retVal) + { + /* enable self wakeup */ + CANx->CAN_MCR.SLFWAK = 1U; + CANx->CAN_MCR.WAKSRC = (uint32_t)filterEn; + + if(ENABLE == intEn ) + { + /* enable self wakeup interrupt */ + if(SUCC != CAN_IntMask(id, CAN_INT_SELF_WAKEUP, UNMASK,0U,0U)) + { + retVal = ERR; + } + } + else + { + /* disable self wakeup interrupt */ + if(SUCC != CAN_IntMask(id, CAN_INT_SELF_WAKEUP, MASK,0U,0U)) + { + retVal = ERR; + } + } + } + + if(SUCC == retVal) + { + if (0U == freeze) + { + if(CAN_ExitFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + } + + return retVal; +} + +/** + * @brief Disable self wakeup function. + * + * @param[in] id: select the CAN ID + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_DisableSelfWakeup(CAN_Id_t id) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + uint32_t freeze = CANx->CAN_MCR.FRZACK; + ResultStatus_t retVal = SUCC; + if (0U == freeze) + { + if(CAN_EnterFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + if(SUCC == retVal) + { + /* disable self wakeup */ + CANx->CAN_MCR.SLFWAK = 0U; + + /* disable self wakeup interrupt */ + if(SUCC != CAN_IntMask(id, CAN_INT_SELF_WAKEUP, MASK,0U,0U)) + { + retVal = ERR; + } + else + { + if (0U == freeze) + { + if(CAN_ExitFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + } + + } + + return retVal; +} + +/** + * @brief Enable enter into doze mode when received entering into wait mode + * request. + * + * @param[in] id: select the CAN ID + * + * @return none + * + */ +void CAN_EnableDozeMode(CAN_Id_t id) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + + CANx->CAN_MCR.DOZE = 1U; +} + +/** + * @brief Disable enter into doze mode when received entering into wait mode + * request. + * + * @param[in] id: select the CAN ID + * + * @return none + * + */ +void CAN_DisableDozeMode(CAN_Id_t id) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + + CANx->CAN_MCR.DOZE = 0U; +} + +/** + * @brief config the action when received a remote request frame + * + * @param[in] id: select the CAN ID + * @param[in] autoResponse: config if remote response frame is transmitted + * automatically after receiving a remote request frame. + * - ENABLE: The received remote request frame is not + * stored and remote response frame, which is + * configured through function + * CAN_ConfigRemoteResponseMb() is transmitted + * automatically + * - DISABLE: remote request frame is stored in the + * same fashion of a data frame in a RX message + * buffer, configured through function CAN_MbReceive(), + * no automatic remote response is transmitted. + * if RXFIFO is enabled and used to receive remote + * request, remote request frame is stored and no + * automatic remote response is transmitted. + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_RemoteFrameConfig(CAN_Id_t id, ControlState_t autoResponse) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + uint32_t freeze = CANx->CAN_MCR.FRZACK; + ResultStatus_t retVal = SUCC; + if (0U == freeze) + { + if(CAN_EnterFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + if(SUCC == retVal) + { + if(ENABLE == autoResponse ) + { + CANx->CAN_CTRL2.RRS = 0U; + } + else + { + CANx->CAN_CTRL2.RRS = 1U; + } + + if (0U == freeze) + { + if(CAN_ExitFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + } + + return retVal; +} + +/** + * @brief Install callback function for CAN_INT_BUS_OFF, CAN_INT_ERR, + CAN_INT_TXW, CAN_INT_RXW, CAN_INT_BUS_OFF_DONE, CAN_INT_ERR_FAST, + CAN_INT_SELF_WAKEUP, CAN_INT_RXFIFO_FRAME, CAN_INT_RXFIFO_WARNING, + CAN_INT_RXFIFO_OVERFLOW, CAN_INT_HOST_MEM_ERR, CAN_INT_CAN_MEM_ERR, + CAN_INT_COR_MEM_ERR + * + * @param[in] id: select the CAN ID + * @param[in] intType: select interrupt type + * @param[in] cbFun: indicate callback function + * + * @return none + * + */ +void CAN_InstallCallBackFunc(CAN_Id_t id, CAN_Int_t intType, isr_cb_t * cbFun) +{ + if((uint32_t)intType >= ((uint32_t)CAN_INT_ALL - 1U)) + { + /*nothing to do*/ + } + else + { + canIsrCbFunc[id].cbf[intType] = cbFun; + } + +} + +/** + * @brief Install callback function for MB interrupt + * + * @param[in] id: select the CAN ID + * @param[in] mbCbf: indicate callback function + * + * @return none + * + */ +void CAN_InstallMbCallBackFunc(CAN_Id_t id, can_mb_cb_t mbCbf) +{ + canIsrCbFunc[id].mbCbf = mbCbf; +} + +/** + * @brief Interrupt mask/unmask + * + * @param[in] id: select the CAN ID + * @param[in] intType: interrupt to be masked/unmasked + * @param[in] intMask: MASK/UNMASK + * @param[in] mb0t31: if intType is CAN_INT_MB, this parameter selects the MBs + * (MB0-MB31) to be configured. Each bit corresponds a MB + * (bit0 - MB0, bit1 - MB1, ... ,bit31 - MB31). If a bit + * is 1,it means the corresponding MB to be configured. + * @param[in] mb32t63: if intType is CAN_INT_MB, this parameter selects the MBs + * (MB32-MB63) to be configured. Each bit corresponds a MB + * (bit0 - MB32, bit1 - MB33, ... ,bit31 - MB63). If a bit + * is 1,it means the corresponding MB to be configured. + * + * @return status + * - SUCC -- successful + * - ERR -- some error + * + */ +ResultStatus_t CAN_IntMask(CAN_Id_t id, CAN_Int_t intType, IntMask_t intMask, + uint32_t mb0t31, uint32_t mb32t63) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + can_reg_w_t * CANxw = (can_reg_w_t *)(canRegWPtr[id]); + ResultStatus_t retVal = SUCC; + + uint32_t freeze = CANx->CAN_MCR.FRZACK; + + if (0U == freeze) + { + if(CAN_EnterFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + if(SUCC == retVal) + { + switch(intType) + { + case CAN_INT_MB: + if(UNMASK == intMask) + { + CANxw->CAN_IMASK1 |= mb0t31; + CANxw->CAN_IMASK2 |= mb32t63; + } + else + { + CANxw->CAN_IMASK1 &= ~mb0t31; + CANxw->CAN_IMASK2 &= ~mb32t63; + } + break; + + case CAN_INT_BUS_OFF: + case CAN_INT_ERR: + if(UNMASK == intMask) + { + CANxw->CAN_CTRL1 |= canInterruptMaskTable[intType]; + canIntMaskStatus1[id] |= canInterruptFlagMaskTable[intType]; + } + else + { + CANxw->CAN_CTRL1 &= ~canInterruptMaskTable[intType]; + canIntMaskStatus1[id] &= ~canInterruptFlagMaskTable[intType]; + } + break; + + case CAN_INT_TXW: + case CAN_INT_RXW: + if(UNMASK == intMask) + { + CANx->CAN_MCR.WRNEN = 1U; + CANxw->CAN_CTRL1 |= canInterruptMaskTable[intType]; + canIntMaskStatus1[id] |= canInterruptFlagMaskTable[intType]; + } + else + { + CANx->CAN_MCR.WRNEN = 0U; + CANxw->CAN_CTRL1 &= ~canInterruptMaskTable[intType]; + canIntMaskStatus1[id]&= ~canInterruptFlagMaskTable[intType]; + } + break; + + case CAN_INT_BUS_OFF_DONE: + case CAN_INT_ERR_FAST: + if(UNMASK == intMask) + { + CANxw->CAN_CTRL2 |= canInterruptMaskTable[intType]; + canIntMaskStatus1[id] |= canInterruptFlagMaskTable[intType]; + } + else + { + CANxw->CAN_CTRL2 &= ~canInterruptMaskTable[intType]; + canIntMaskStatus1[id] &= ~canInterruptFlagMaskTable[intType]; + } + break; + + case CAN_INT_SELF_WAKEUP: + if(UNMASK == intMask) + { + CANxw->CAN_MCR |= canInterruptMaskTable[intType]; + canIntMaskStatus1[id] |= canInterruptFlagMaskTable[intType]; + } + else + { + CANxw->CAN_MCR &= ~canInterruptMaskTable[intType]; + canIntMaskStatus1[id] &= ~canInterruptFlagMaskTable[intType]; + } + break; + + case CAN_INT_RXFIFO_FRAME: + case CAN_INT_RXFIFO_WARNING: + case CAN_INT_RXFIFO_OVERFLOW: + if(UNMASK == intMask) + { + CANxw->CAN_IMASK1 |= canInterruptMaskTable[intType]; + } + else + { + CANxw->CAN_IMASK1 &= ~canInterruptMaskTable[intType]; + } + break; + + case CAN_INT_HOST_MEM_ERR: + case CAN_INT_CAN_MEM_ERR: + case CAN_INT_COR_MEM_ERR: + CANx->CAN_CTRL2.ECRWRE = 1U; + CANx->CAN_MECR.ECRWRDIS = 0U; + if(UNMASK == intMask) + { + CANxw->CAN_MECR |= canInterruptMaskTable[intType]; + } + else + { + CANxw->CAN_MECR &= ~canInterruptMaskTable[intType]; + } + break; + + case CAN_INT_PN_WAKEUP_MATCH: + case CAN_INT_PN_WAKEUP_TIMEOUT: + if(UNMASK == intMask) + { + CANxw->CAN_CTRL1_PN |= canInterruptMaskTable[intType]; + } + else + { + CANxw->CAN_CTRL1_PN &= ~canInterruptMaskTable[intType]; + } + break; + + case CAN_INT_ALL: + if(UNMASK == intMask) + { + CANxw->CAN_IMASK1 |= 0xFFFFFFFFU; + CANxw->CAN_IMASK2 |= 0xFFFFFFFFU; + CANxw->CAN_CTRL1 |= CAN_INT_MSK_MULTI_1; + CANxw->CAN_CTRL2 |= CAN_INT_MSK_MULTI_2; + CANx->CAN_CTRL2.ECRWRE = 1U; + CANx->CAN_MECR.ECRWRDIS = 0U; + CANxw->CAN_MECR |= CAN_INT_MSK_MULTI_3; + CANx->CAN_MCR.WAKMSK = 1U; + CANx->CAN_MCR.WRNEN = 1U; + CANxw->CAN_CTRL1_PN |= CAN_INT_MSK_MULTI_4; + canIntMaskStatus1[id] = CAN_INT_MSK_FLAG_ALL_1; + } + else + { + CANxw->CAN_IMASK1 &= 0x00U; + CANxw->CAN_IMASK2 &= 0x00U; + CANxw->CAN_CTRL1 &= ~CAN_INT_MSK_MULTI_1; + CANxw->CAN_CTRL2 &= ~CAN_INT_MSK_MULTI_2; + CANx->CAN_CTRL2.ECRWRE = 1U; + CANx->CAN_MECR.ECRWRDIS = 0U; + CANxw->CAN_MECR &= ~CAN_INT_MSK_MULTI_3; + CANx->CAN_MCR.WAKMSK = 0U; + CANx->CAN_MCR.WRNEN = 0U; + CANxw->CAN_CTRL1_PN &= ~CAN_INT_MSK_MULTI_4; + canIntMaskStatus1[id] = 0U; + } + break; + + default: + /* nothing to do */ + break; + } + if (0U == freeze) + { + if(CAN_ExitFreezeMode(id) != SUCC) + { + retVal = ERR; + } + } + } + + return retVal; +} + +/** + * @brief MB Interrupt mask/unmask + * + * @param[in] id: select the CAN ID + * @param[in] mbIdx: the MB index + * @param[in] intMask: MASK/UNMASK + * + * @return status + * -ERR + * -SUCC + * + */ +ResultStatus_t CAN_MbIntMask(CAN_Id_t id, uint32_t mbIdx,IntMask_t intMask) +{ + can_reg_w_t * CANxw = (can_reg_w_t *)(canRegWPtr[id]); + ResultStatus_t retVal = SUCC; + if(mbIdx < 32U) + { + if(UNMASK == intMask) + { + CANxw->CAN_IMASK1 |= (1UL << mbIdx); + } + else + { + CANxw->CAN_IMASK1 &= ~(1UL << mbIdx); + } + } + else if(mbIdx < 64U) + { + if(UNMASK == intMask) + { + CANxw->CAN_IMASK2 |= (1UL << (mbIdx - 32U)); + } + else + { + CANxw->CAN_IMASK2 &= ~(1UL << (mbIdx - 32U)); + } + } + else + { + retVal = ERR; + } + + return retVal; +} +/** + * @brief Clear interrupt + * + * @param[in] id: select the CAN ID + * @param[in] intType: select interrupt type +* @param[in] mb0t31: if intType is CAN_INT_MB, this parameter selects the MBs + * (MB0-MB31) to be configured. Each bit corresponds a MB + * (bit0 - MB0, bit1 - MB1, ... ,bit31 - MB31). If a bit + * is 1,it means the corresponding MB to be configured. + * For other interrupt type, this parameter can be ignored. + * @param[in] mb32t63: if intType is CAN_INT_MB, this parameter selects the MBs + * (MB0-MB31) to be configured. Each bit corresponds a MB + * (bit0 - MB32, bit1 - MB33, ... ,bit31 - MB63). If a bit + * is 1,it means the corresponding MB to be configured. + * For other interrupt type, this parameter can be ignored. + * + * @return none + * + */ +void CAN_IntClear(CAN_Id_t id, CAN_Int_t intType, uint32_t mb0t31, + uint32_t mb32t63) +{ + can_reg_w_t * CANxw = (can_reg_w_t *)(canRegWPtr[id]); + + switch(intType) + { + case CAN_INT_MB: + CANxw->CAN_IFLAG1 = mb0t31; + CANxw->CAN_IFLAG2 = mb32t63; + break; + + case CAN_INT_BUS_OFF: + case CAN_INT_ERR: + case CAN_INT_TXW: + case CAN_INT_RXW: + case CAN_INT_BUS_OFF_DONE: + case CAN_INT_ERR_FAST: + case CAN_INT_SELF_WAKEUP: + CANxw->CAN_ESR1 = canInterruptFlagMaskTable[intType]; + break; + + case CAN_INT_RXFIFO_FRAME: + case CAN_INT_RXFIFO_WARNING: + case CAN_INT_RXFIFO_OVERFLOW: + CANxw->CAN_IFLAG1 = canInterruptFlagMaskTable[intType]; + break; + + case CAN_INT_HOST_MEM_ERR: + case CAN_INT_CAN_MEM_ERR: + case CAN_INT_COR_MEM_ERR: + CANxw->CAN_ERRSR = canInterruptFlagMaskTable[intType]; + break; + + case CAN_INT_PN_WAKEUP_MATCH: + case CAN_INT_PN_WAKEUP_TIMEOUT: + CANxw->CAN_WU_MTC = canInterruptFlagMaskTable[intType]; + break; + + case CAN_INT_ALL: + CANxw->CAN_ESR1 = CAN_INT_MSK_FLAG_ALL_1; + CANxw->CAN_ERRSR = CAN_INT_MSK_FLAG_ALL_2; + CANxw->CAN_WU_MTC = CAN_INT_MSK_FLAG_ALL_3; + CANxw->CAN_IFLAG1 = 0xFFFFFFFFU; + CANxw->CAN_IFLAG2 = 0xFFFFFFFFU; + break; + + default: + /* nothing to do */ + break; + } + +} + +/** + * @brief Get interrupt status + * + * @param[in] id: select the CAN ID + * @param[in] intType: select interrupt type + * @param[in] mbId: if intType is CAN_INT_MB, this parameter selects the MB + * (MB0-MB63) status to be get + * + * @return status + * - SET + * - RESET + * + */ +IntStatus_t CAN_GetIntStatus(CAN_Id_t id, CAN_Int_t intType, uint32_t mbId) +{ + can_reg_w_t * CANxw = (can_reg_w_t *)(canRegWPtr[id]); + IntStatus_t status = RESET; + bool tmp[5]; + + switch(intType) + { + case CAN_INT_MB: + if(mbId < 32U) + { + status = ((CANxw->CAN_IFLAG1 & (1UL << mbId)) != 0U) + ? SET : RESET; + } + else if(mbId < 64U) + { + status = ((CANxw->CAN_IFLAG2 & (1UL << (mbId - 32U))) != 0U) + ? SET : RESET; + } + else + { + /* input parameter error */ + } + break; + + case CAN_INT_BUS_OFF: + case CAN_INT_ERR: + case CAN_INT_TXW: + case CAN_INT_RXW: + case CAN_INT_BUS_OFF_DONE: + case CAN_INT_ERR_FAST: + case CAN_INT_SELF_WAKEUP: + status = ((CANxw->CAN_ESR1 & + canInterruptFlagMaskTable[intType]) != 0U) ? SET : RESET; + break; + + case CAN_INT_RXFIFO_FRAME: + case CAN_INT_RXFIFO_WARNING: + case CAN_INT_RXFIFO_OVERFLOW: + status = ((CANxw->CAN_IFLAG1 & + canInterruptFlagMaskTable[intType]) != 0U) ? SET : RESET; + break; + + case CAN_INT_HOST_MEM_ERR: + case CAN_INT_CAN_MEM_ERR: + case CAN_INT_COR_MEM_ERR: + status = ((CANxw->CAN_ERRSR & + canInterruptFlagMaskTable[intType]) != 0U) ? SET : RESET; + break; + + case CAN_INT_PN_WAKEUP_MATCH: + case CAN_INT_PN_WAKEUP_TIMEOUT: + status = ((CANxw->CAN_WU_MTC & + canInterruptFlagMaskTable[intType]) != 0U) ? SET : RESET; + break; + + case CAN_INT_ALL: + tmp[0] = (CANxw->CAN_ESR1 & CAN_INT_MSK_FLAG_ALL_1) != 0U; + tmp[1] = (CANxw->CAN_ERRSR & CAN_INT_MSK_FLAG_ALL_2) != 0U; + tmp[2] = (CANxw->CAN_IFLAG1) != 0U; + tmp[3] = (CANxw->CAN_IFLAG2) != 0U; + tmp[4] = (CANxw->CAN_WU_MTC & CAN_INT_MSK_FLAG_ALL_3) != 0U; + + status = (tmp[0] || tmp[1] || tmp[2] || tmp[3]|| tmp[4]) + ? SET : RESET; + break; + + default: + /* nothing to do */ + break; + } + return status; +} + +/** + * @brief Get CAN state + * + * @param[in] id: select the CAN ID + * + * @return CAN state + * + */ +CAN_State_t CAN_GetState(CAN_Id_t id) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + CAN_State_t state = CAN_STATE_INVALID; + if(0U == CANx->CAN_ESR1.SYNCH) + { + state = CAN_STATE_NOT_SYNC; + } + else + { + if(CANx->CAN_ESR1.IDLE != 0U) + { + state = CAN_STATE_IDLE; + } + else + { + if(CANx->CAN_ESR1.TX != 0U) + { + state = CAN_STATE_TX; + } + else + { + if(CANx->CAN_ESR1.RX != 0U) + { + state = CAN_STATE_RX; + } + } + } + } + + return state; +} + +/** + * @brief Get CAN status + * + * @param[in] id: select the CAN ID + * @param[in] status: the status to be get + * + * @return status + * - SET + * - RESET + * + */ +FlagStatus_t CAN_GetStatus(CAN_Id_t id, CAN_Status_t status) +{ + can_reg_w_t * CANxw = (can_reg_w_t *)(canRegWPtr[id]); + FlagStatus_t res; + + if(CAN_STATUS_ALL == (CAN_Status_t)status) + { + res = ((CANxw->CAN_ESR1 & CAN_STATUS_ALL_MASK) != 0U) ? SET : RESET; + } + else + { + res = ((CANxw->CAN_ESR1 & ((uint32_t)1U << (uint32_t)status)) != 0U) + ? SET : RESET; + } + + return res; +} + +/** + * @brief Clear CAN status + * + * @param[in] id: select the CAN ID + * @param[in] status: the status to clear + * + * @return none + * + */ +void CAN_ClearStatus(CAN_Id_t id, CAN_Status_t status) +{ + can_reg_w_t * CANxw = (can_reg_w_t *)(canRegWPtr[id]); + + if(CAN_STATUS_ALL == status) + { + CANxw->CAN_ESR1 = CAN_STATUS_ALL_MASK; + } + else + { + CANxw->CAN_ESR1 = (uint32_t)1U << (uint32_t)status; + } +} + +/** + * @brief Get CAN Fault Confinement State + * + * @param[in] id: select the CAN ID + * + * @return CAN Fault Confinement State + * + */ +CAN_FaultConfState_t CAN_GetFaultConfinementState(CAN_Id_t id) +{ + can_reg_t * CANx = (can_reg_t *)(canRegPtr[id]); + CAN_FaultConfState_t ret; + if((uint32_t)CAN_FAULT_CONF_STATE_ERROR_ACTIVE == CANx->CAN_ESR1.FLTCONF) + { + ret = CAN_FAULT_CONF_STATE_ERROR_ACTIVE; + } + else if((uint32_t)CAN_FAULT_CONF_STATE_ERROR_PASSIVE + == CANx->CAN_ESR1.FLTCONF) + { + ret = CAN_FAULT_CONF_STATE_ERROR_PASSIVE; + } + else + { + ret = CAN_FAULT_CONF_STATE_BUS_OFF; + } + return ret; +} + +/** + * @brief CAN0 IRQHandler + * + * @param[in] none + * + * @return none + * + */ +void CAN0_DriverIRQHandler(void) +{ + CAN_IntHandler(CAN_ID_0); +} + +#if (2U == CAN_INSTANCE_NUM) +/** + * @brief CAN1 IRQHandler + * + * @param[in] none + * + * @return none + * + */ +void CAN1_DriverIRQHandler(void) +{ + CAN_IntHandler(CAN_ID_1); +} +#endif + +/** @} end of group CAN_Public_Functions */ + +/** @} end of group CAN_definitions */ + +/** @} end of group Z20K11X_Peripheral_Driver */ diff --git a/StdDriver/Src/Z20K11xM_clock.c b/StdDriver/Src/Z20K11xM_clock.c new file mode 100644 index 0000000..4923069 --- /dev/null +++ b/StdDriver/Src/Z20K11xM_clock.c @@ -0,0 +1,1375 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_clock.c + * @brief : CLOCK module driver file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (C) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + * + **************************************************************************************************/ + +#include "Z20K11xM_clock.h" + +/** @addtogroup Z20K11X_Peripheral_Driver + * @{ + */ + +/** @defgroup Clock + * @brief Clock driver modules + * @{ + */ + +/** @defgroup Clock_Private_Type + * @{ + */ +typedef volatile union +{ + struct { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } BF; + uint32_t WORDVAL; +} ModuleClk_t; +/** @} end of group Clock_Private_Type*/ + +/** @defgroup Clock_Private_Defines + * @{ + */ + +/** + * @brief RTC Register address array + */ +/*PRQA S 0303,0306 ++*/ +static rtc_reg_t * const rtcRegPtr = (rtc_reg_t *)RTC_BASE_ADDR; +static rtc_reg_w_t * const rtcRegWPtr = (rtc_reg_w_t *)RTC_BASE_ADDR; +/*PRQA S 0303,0306 --*/ + +/** + * @brief SCM Register address array + */ +/*PRQA S 0303,0306 ++*/ +static scm_reg_t * const scmRegPtr = (scm_reg_t *)SCM_BASE_ADDR; +/*PRQA S 0303,0306 --*/ + +/** + * @brief SCC Register address array + */ +/*PRQA S 0303,0306 ++*/ +static scc_reg_t * const sccRegPtr = (scc_reg_t *)SCC_BASE_ADDR; +static scc_reg_w_t * const sccRegWPtr = (scc_reg_w_t *)SCC_BASE_ADDR; +/*PRQA S 0303,0306 --*/ + +/** + * @brief PMU Register address array + */ +/*PRQA S 0303,0306 ++*/ +static pmu_reg_t * const pmuRegPtr = (pmu_reg_t *)PMU_BASE_ADDR; +static pmu_reg_w_t * const pmuRegWPtr = (pmu_reg_w_t *)PMU_BASE_ADDR; +/*PRQA S 0303,0306 --*/ + +/** + * @brief PARCC Register address array + */ +/*PRQA S 0303,0306 ++*/ +static ModuleClk_t * const parccRegPtr[]= +{ + (ModuleClk_t *)(PARCC_BASE_ADDR+0u), + (ModuleClk_t *)(PARCC_BASE_ADDR + (uint32_t)CLK_EWDT), + (ModuleClk_t *)(PARCC_BASE_ADDR+(uint32_t)CLK_STIM), + (ModuleClk_t *)(PARCC_BASE_ADDR+(uint32_t)CLK_TIM0), + (ModuleClk_t *)(PARCC_BASE_ADDR+(uint32_t)CLK_TIM1), + (ModuleClk_t *)(PARCC_BASE_ADDR+(uint32_t)CLK_TIM2), + (ModuleClk_t *)(PARCC_BASE_ADDR+(uint32_t)CLK_TDG0), + (ModuleClk_t *)(PARCC_BASE_ADDR+(uint32_t)CLK_CAN0), + (ModuleClk_t *)(PARCC_BASE_ADDR+(uint32_t)CLK_CAN1), + (ModuleClk_t *)(PARCC_BASE_ADDR+(uint32_t)CLK_UART0), + (ModuleClk_t *)(PARCC_BASE_ADDR+(uint32_t)CLK_UART1), + (ModuleClk_t *)(PARCC_BASE_ADDR+(uint32_t)CLK_UART2), + (ModuleClk_t *)(PARCC_BASE_ADDR+(uint32_t)CLK_UART3), + (ModuleClk_t *)(PARCC_BASE_ADDR+(uint32_t)CLK_SPI0), + (ModuleClk_t *)(PARCC_BASE_ADDR+(uint32_t)CLK_SPI1), + (ModuleClk_t *)(PARCC_BASE_ADDR+(uint32_t)CLK_SPI2), + (ModuleClk_t *)(PARCC_BASE_ADDR+(uint32_t)CLK_I2C0), + (ModuleClk_t *)(PARCC_BASE_ADDR+(uint32_t)CLK_I2C1), + (ModuleClk_t *)(PARCC_BASE_ADDR+(uint32_t)CLK_ADC0), + (ModuleClk_t *)(PARCC_BASE_ADDR+(uint32_t)CLK_CMP), + (ModuleClk_t *)(PARCC_BASE_ADDR+(uint32_t)CLK_CRC), + (ModuleClk_t *)(PARCC_BASE_ADDR+(uint32_t)CLK_FLASH), + (ModuleClk_t *)(PARCC_BASE_ADDR+(uint32_t)CLK_DMA), + (ModuleClk_t *)(PARCC_BASE_ADDR+(uint32_t)CLK_DMAMUX), + (ModuleClk_t *)(PARCC_BASE_ADDR+(uint32_t)CLK_PORTA), + (ModuleClk_t *)(PARCC_BASE_ADDR+(uint32_t)CLK_PORTB), + (ModuleClk_t *)(PARCC_BASE_ADDR+(uint32_t)CLK_PORTC), + (ModuleClk_t *)(PARCC_BASE_ADDR+(uint32_t)CLK_PORTD), + (ModuleClk_t *)(PARCC_BASE_ADDR+(uint32_t)CLK_PORTE), +}; +/*PRQA S 0303,0306 --*/ + +#define PMU_UNLOCK_SEQUENCE (0x94730000UL) + +/** @} end of group Clock_Private_Defines */ + +/** @defgroup Clock_Private_Variables + * @{ + */ + +/** + * @brief SCC ISR callback function pointer array + */ +static isr_cb_t * sccIsrCbFunc[CLK_INT_ALL]= {NULL, NULL}; + +/** @} end of group Clock_Private_Variables */ + +/** @defgroup Clock_Global_Variables + * @{ + */ + +/** @} end of group Clock_Global_Variables */ + +/** @defgroup Clock_Private_FunctionDeclaration + * @{ + */ +void SCC_DriverIRQHandler(void); + +static uint32_t CLK_GetSysClkFreq(uint32_t oscFreq); +static void CLK_WaitOSC40MSwitchReady(void); + +/** @} end of group Clock_Private_FunctionDeclaration */ + +/** @defgroup Clock_Private_Functions + * @{ + */ + +/** + * @brief get system clock frequency before divider + * + * @param[in] oscFreq: frequency of the OSC clock + * + * @return The clock frequency. If return 0, there is some error. + * + */ +static uint32_t CLK_GetSysClkFreq(uint32_t oscFreq) +{ + uint32_t ret = 0U; + + if(2U == sccRegPtr->SCC_CST.SCS) + { + ret = oscFreq; + } + else if(1U == sccRegPtr->SCC_CST.SCS) + { + ret = 64000000U; + } + else + { + /*nothing to do*/ + } + + return ret; +} + +/** + * @brief Wait 500us for the Crystal oscillator ready when switching mode + * + * @param[in] None + * + * @return None + * + */ +static void CLK_WaitOSC40MSwitchReady(void) +{ + uint32_t cldDiv, waitCount = CLK_WAITCONFIG_CNT; + volatile uint32_t cnt = 0U; + cldDiv = sccRegPtr->SCC_CST.DIVCORE + (uint32_t)1U; + + waitCount = (CLK_WAITCONFIG_CNT / cldDiv) + (uint32_t)1U; + + while(cnt++ < waitCount) + { + } +} + +/** @} end of group Clock_Private_Functions */ + +/** @defgroup Clock_Public_Functions + * @{ + */ + +/** + * @brief Enable FIRC64M clock and set enablement in stop mode + * + * @param[in] stopModeEn: Enable/Disable FIRC64M in stop mode. + * + * @return none + * + */ +void CLK_FIRC64MEnable(ControlState_t stopModeEn) +{ + if(sccRegPtr->SCC_FIRCCS.LOCK != 0U) + { + /* unlock this register */ + sccRegWPtr->SCC_FIRCCS = 0x5B000000U; + } + + sccRegPtr->SCC_FIRCCS.FIRCSTOPEN = (uint32_t)stopModeEn; + sccRegPtr->SCC_FIRCCS.FIRCEN = 1U; + + /* lock this register */ + sccRegPtr->SCC_FIRCCS.LOCK = 1U; +} + +/** + * @brief It is suggested to use CLK_OSC40MEnable2() instead of this + * function. It Configures and enables OSC40M clock. The frequency + * mode is selected according to the 'freq' parameter. However, the + * selection may be not accurate. + * + * @param[in] freq: the frequency of OSC40M, unit/MHz. The value should be + * between 4 and 40. If 4<= freq <= 24, CLK_OSC_FREQ_MODE_LOW + * is selected for the frequency mode; if 24< freq <= 40, + * CLK_OSC_FREQ_MODE_HIGH is selected for the frequency mode. + * @param[in] stopModeEn: Enable/Disable OSC40M in stop mode. + * @param[in] mode: select OSC mode. It selects from crystal oscillator or + * external square wave clock source. + * + * @note It is suggested to use CLK_OSC40MEnable2() instead of this function. + * + * + * @return status + * - ERR - some error. + * - SUCC - successful + * + */ +ResultStatus_t CLK_OSC40MEnable(uint32_t freq, ControlState_t stopModeEn, + CLK_OscMode_t mode) +{ + ResultStatus_t retVal = SUCC; + if(sccRegPtr->SCC_OSCCS.LOCK != 0U) + { + /* unlock this register */ + sccRegWPtr->SCC_OSCCS = 0x5B000000U; + } + sccRegPtr->SCC_OSCCS.OSCSTOPEN = (uint32_t)stopModeEn; + if(CLK_GetSysClkSrc() == CLK_SYS_OSC40M) + { + /* lock */ + sccRegPtr->SCC_OSCCS.LOCK = 1U; + } + else + { + if((freq <= 24U) && (freq >= 4U)) + { + sccRegPtr->SCC_OSCCFG.HFREQ = 0U; + } + else if((freq <= 40U) &&(freq > 24U)) + { + sccRegPtr->SCC_OSCCFG.HFREQ = 1U; + } + else + { + retVal = ERR; + } + + if(SUCC == retVal) + { + sccRegPtr->SCC_OSCCFG.EXCLKS = (uint32_t)mode; + sccRegPtr->SCC_OSCCFG.OLMEN = 1U; + + sccRegPtr->SCC_OSCCS.OSCEN = 0U; + + if(CLK_OSC_XTAL == mode) + { + CLK_WaitOSC40MSwitchReady(); + + sccRegPtr->SCC_OSCCS.OSCEN = 1U; + + /* lock */ + sccRegPtr->SCC_OSCCS.LOCK = 1U; + + if(sccRegPtr->SCC_OSCCS.OSCRDY == 1U) + { + /* for XTAL mode, it needs some time to be ready. If the OSCRDY is + set immediately, there is some error */ + retVal = ERR; + } + } + else + { + sccRegPtr->SCC_OSCCS.OSCEN = 1U; + + /* lock */ + sccRegPtr->SCC_OSCCS.LOCK = 1U; + } + } + + if(SUCC == retVal) + { + retVal = CLK_WaitClkReady(CLK_SRC_OSC40M); + } + } + + /* wait for clock ready */ + return retVal; +} + +/** + * @brief Config and enable OSC40M clock + * + * @param[in] freqMode: It selects the frequency mode of OSC40M + * @param[in] stopModeEn: Enable/Disable OSC40M in stop mode. + * @param[in] mode: select OSC mode. It selects from crystal oscillator or + * external square wave clock source. + * + * @return status + * ERR - some error. + * SUCC - successful + * + */ +ResultStatus_t CLK_OSC40MEnable2(CLK_OscFreqMode_t freqMode, + ControlState_t stopModeEn, + CLK_OscMode_t mode) +{ + ResultStatus_t retVal = SUCC; + if(sccRegPtr->SCC_OSCCS.LOCK != 0U) + { + /* unlock this register */ + sccRegWPtr->SCC_OSCCS = 0x5B000000U; + } + sccRegPtr->SCC_OSCCS.OSCSTOPEN = (uint32_t)stopModeEn; + if(CLK_GetSysClkSrc() == CLK_SYS_OSC40M) + { + /* lock */ + sccRegPtr->SCC_OSCCS.LOCK = 1U; + } + else + { + sccRegPtr->SCC_OSCCFG.HFREQ = (uint32_t)freqMode; + sccRegPtr->SCC_OSCCFG.EXCLKS = (uint32_t)mode; + sccRegPtr->SCC_OSCCFG.OLMEN = 1U; + + sccRegPtr->SCC_OSCCS.OSCEN = 0U; + + if(CLK_OSC_XTAL == mode) + { + CLK_WaitOSC40MSwitchReady(); + + sccRegPtr->SCC_OSCCS.OSCEN = 1U; + + /* lock */ + sccRegPtr->SCC_OSCCS.LOCK = 1U; + + if(sccRegPtr->SCC_OSCCS.OSCRDY == 1U) + { + /* for XTAL mode, it needs some time to be ready. If the OSCRDY is + set immediately, there is some error */ + retVal = ERR; + } + } + else + { + sccRegPtr->SCC_OSCCS.OSCEN = 1U; + + /* lock */ + sccRegPtr->SCC_OSCCS.LOCK = 1U; + } + + if(SUCC == retVal) + { + retVal = CLK_WaitClkReady(CLK_SRC_OSC40M); + } + } + + + return retVal; +} + +/** + * @brief Select system clock. + * + * @param[in] clk: select the clock source + * + * @return + * SUCC: the system clock is selected successfully + * ERR: fail + * @note The selected clock source has to be ready + * before call this function. + * + */ +ResultStatus_t CLK_SysClkSrc(CLK_System_t clk) +{ + ResultStatus_t retVal = SUCC; + if(CLK_SYS_FIRC64M == clk) + { + if(CLK_WaitClkReady(CLK_SRC_FIRC64M) != SUCC) + { + retVal = ERR; + } + else + { + if(sccRegPtr->SCC_CFG.LOCK != 0U) + { + /* unlock this register */ + sccRegWPtr->SCC_CFG = 0x5B000000U; + } + /* select sys clock source */ + sccRegWPtr->SCC_CFG = + (sccRegWPtr->SCC_CFG & 0xFFF8FFFFU) | (1UL << 16U); + + sccRegPtr->SCC_CFG.LOCK = 1U; + } + + } + else if(CLK_SYS_OSC40M == clk) + { + if(CLK_WaitClkReady(CLK_SRC_OSC40M) != SUCC) + { + retVal = ERR; + } + else + { + if(sccRegPtr->SCC_CFG.LOCK != 0U) + { + /* unlock this register */ + sccRegWPtr->SCC_CFG = 0x5B000000U; + } + /* select sys clock source */ + sccRegWPtr->SCC_CFG = + (sccRegWPtr->SCC_CFG & 0xFFF8FFFFU) | (1UL << 17U); + + sccRegPtr->SCC_CFG.LOCK = 1; + + } + + } + else + { + retVal = ERR; + } + return retVal; +} + +/** + * @brief Get system clock source. + * + * @param[in] none. + * + * @return + * -CLK_SYS_FIRC64M + * -CLK_SYS_OSC40M + * + */ +CLK_System_t CLK_GetSysClkSrc(void) +{ + CLK_System_t retVal; + if((uint32_t)CLK_SYS_FIRC64M == sccRegPtr->SCC_CST.SCS) + { + retVal = CLK_SYS_FIRC64M; + } + else /*CLK_SYS_OSC40M*/ + { + retVal = CLK_SYS_OSC40M; + } + return retVal; +} + +/** + * @brief Disable FIRC64M clock + * + * @param[in] none. + * + * @return none + * + */ +void CLK_FIRC64MDisable(void) +{ + if(sccRegPtr->SCC_FIRCCS.LOCK != 0U) + { + /* unlock this register */ + sccRegWPtr->SCC_FIRCCS = 0x5B000000; + } + + sccRegPtr->SCC_FIRCCS.FIRCEN = 0; + + /* lock this register */ + sccRegPtr->SCC_FIRCCS.LOCK = 1; +} + +/** + * @brief Disable OSC40M clock + * + * @param[in] none. + * + * @return none + * + */ +void CLK_OSC40MDisable(void) +{ + if(sccRegPtr->SCC_OSCCS.LOCK != 0U) + { + /* unlock this register */ + sccRegWPtr->SCC_OSCCS = 0x5B000000; + } + + sccRegPtr->SCC_OSCCS.OSCEN = 0U; + sccRegPtr->SCC_OSCCFG.OLMEN = 0U; + /* lock */ + sccRegPtr->SCC_OSCCS.LOCK = 1U; +} + +/** + * @brief Config and Enable OSC40M loss of clock monitor + * + * @param[in] act: select the action when loss of clock is detected. + * + * @return none + * + */ +void CLK_OSC40MMonitorEnable(CLK_MonitorAct_t act) +{ + if(sccRegPtr->SCC_OSCCS.LOCK != 0U) + { + /* unlock this register */ + sccRegWPtr->SCC_OSCCS = 0x5B000000; + } + + sccRegPtr->SCC_OSCCS.OSCCMRE = (uint32_t)act; + + sccRegPtr->SCC_OSCCS.OSCCME = 1; + sccRegPtr->SCC_OSCCS.OSCCMIE = 1; + /* lock */ + sccRegPtr->SCC_OSCCS.LOCK = 1; +} + +/** + * @brief Disable OSC40M loss of clock monitor + * + * @param[in] none. + * + * @return none + * + */ +void CLK_OSC40MMonitorDisable(void) +{ + if(sccRegPtr->SCC_OSCCS.LOCK != 0U) + { + /* unlock this register */ + sccRegWPtr->SCC_OSCCS = 0x5B000000; + } + + sccRegPtr->SCC_OSCCS.OSCCME = 0; + /* lock */ + sccRegPtr->SCC_OSCCS.LOCK = 1; +} + +/** + * @brief Config and Enable FIRC64M loss of clock monitor + * + * @param[in] act: select the action when loss of clock is detected. + * + * @return none + * + */ +void CLK_FIRC64MMonitorEnable(CLK_MonitorAct_t act) +{ + if(sccRegPtr->SCC_FIRCCS.LOCK != 0U) + { + /* unlock this register */ + sccRegWPtr->SCC_FIRCCS = 0x5B000000; + } + + sccRegPtr->SCC_FIRCCS.FIRCCMRE = (uint32_t)act; + + sccRegPtr->SCC_FIRCCS.FIRCCME = 1; + sccRegPtr->SCC_FIRCCS.FIRCCMIE =1; + /* lock */ + sccRegPtr->SCC_FIRCCS.LOCK = 1; +} + +/** + * @brief Config and Enable FIRC64M loss of clock monitor + * + * @param[in] none + * + * @return none + * + */ +void CLK_FIRC64MMonitorDisable(void) +{ + if(sccRegPtr->SCC_FIRCCS.LOCK != 0U) + { + /* unlock this register */ + sccRegWPtr->SCC_FIRCCS = 0x5B000000; + } + + sccRegPtr->SCC_FIRCCS.FIRCCME = 0; + /* lock */ + sccRegPtr->SCC_FIRCCS.LOCK = 1; +} + +/** + * @brief Config and Enable LPO32K clock + * + * @param[in] none + * + * @return none + * + */ +void CLK_LPO32KEnable(void) +{ + pmuRegWPtr->PMU_LOCK = (uint32_t)PMU_UNLOCK_SEQUENCE; + pmuRegPtr->PMU_LPO_32K_CFG.LPO_CLK_DIS = 0U; + pmuRegPtr->PMU_LOCK.LOCK = 1U; +} + +/** + * @brief Disable LPO32K clock + * + * @param[in] none. + * + * @return none + * + */ +void CLK_LPO32KDisable(void) +{ + pmuRegWPtr->PMU_LOCK = (uint32_t)PMU_UNLOCK_SEQUENCE; + pmuRegPtr->PMU_LPO_32K_CFG.LPO_CLK_DIS = 1U; + pmuRegPtr->PMU_LOCK.LOCK = 1U; +} + +/** + * @brief Config and Enable OSC32K clock + * + * @param[in] mode: select OSC mode. It selects from crystal oscillator or + * external square wave clock source. + * + * @return none + * + */ +void CLK_OSC32KEnable(CLK_OscMode_t mode) +{ + if(rtcRegPtr->RTC_LOCKR.LOCK != 0U) + { + rtcRegWPtr->RTC_LOCKR = 0x98670000U; + } + + if( CLK_OSC_XTAL == mode) + { + rtcRegPtr->RTC_CSR.EXTAL_32K_EN = 0U; + rtcRegPtr->RTC_CSR.CRYSTAL_EN = 1U; + } + else + { + rtcRegPtr->RTC_CSR.EXTAL_32K_EN = 1U; + rtcRegPtr->RTC_CSR.CRYSTAL_EN = 0U; + } + + rtcRegPtr->RTC_LOCKR.LOCK = 1U; +} + +/** + * @brief Disable OSC32K clock + * + * @param[in] none + * + * @return none + * + */ +void CLK_OSC32KDisable(void) +{ + if(rtcRegPtr->RTC_LOCKR.LOCK != 0U) + { + rtcRegWPtr->RTC_LOCKR = 0x98670000U; + } + + rtcRegPtr->RTC_CSR.EXTAL_32K_EN = 0U; + rtcRegPtr->RTC_CSR.CRYSTAL_EN = 0U; + + rtcRegPtr->RTC_LOCKR.LOCK = 1U; +} + +/** + * @brief Set clock divider + * + * @param[in] module: select which module clock to set divider. + * It selects from CLK_EWDT, CLK_STIM, CLK_TIM0, + * CLK_TIM1, CLK_TIM2, CLK_TDG0, CLK_CAN0, CLK_CAN1, + * CLK_UART0, CLK_UART1, CLK_UART2, CLK_UART3, + * CLK_SPI0, CLK_SPI1, CLK_SPI2, CLK_I2C0, CLK_I2C1, + * CLK_ADC0, CLK_PORTA,CLK_PORTB, CLK_PORTC, CLK_PORTD, + * CLK_PORTE CLK_CORE, CLK_BUS, CLK_SLOW + * + * @param[in] divider: clock divider + * @return none + * + */ +void CLK_SetClkDivider(CLK_Module_t module, CLK_Divider_t divider) +{ + uint32_t index = (uint32_t)module >> 2U; + /*PRQA S 0303,0306 ++*/ + ModuleClk_t *PARCCx = (ModuleClk_t *)(parccRegPtr[index]); + /*PRQA S 0303,0306 ++*/ + switch(module) + { + case CLK_EWDT: + case CLK_STIM: + case CLK_TIM0: + case CLK_TIM1: + case CLK_TIM2: + case CLK_TDG0: + case CLK_CAN0: +#if (2U == CAN_INSTANCE_NUM) + case CLK_CAN1: +#endif + case CLK_UART0: + case CLK_UART1: + case CLK_UART2: +#if (4U == UART_INSTANCE_NUM) + case CLK_UART3: +#endif + case CLK_SPI0: + case CLK_SPI1: +#if (3U == SPI_INSTANCE_NUM) + case CLK_SPI2: +#endif + case CLK_I2C0: +#if (2U == I2C_INSTANCE_NUM) + case CLK_I2C1: +#endif + case CLK_ADC0: + case CLK_PORTA: + case CLK_PORTB: + case CLK_PORTC: + case CLK_PORTD: + case CLK_PORTE: + if(PARCCx->BF.LOCK != 0U) + { + /* unlock this register */ + PARCCx->WORDVAL = 0x5B000000U; + } + + PARCCx->BF.CLKDIV = (uint32_t)divider; + PARCCx->BF.LOCK = 1; + break; + + case CLK_CORE: + if(sccRegPtr->SCC_CFG.LOCK != 0U) + { + /* unlock this register */ + sccRegWPtr->SCC_CFG = 0x5B000000U; + } + + sccRegWPtr->SCC_CFG = + (sccRegWPtr->SCC_CFG & 0xFFFFF0FFU) | ((uint32_t)divider << 8U); + sccRegPtr->SCC_CFG.LOCK = 1; + break; + + case CLK_BUS: + if(sccRegPtr->SCC_CFG.LOCK != 0U) + { + /* unlock this register */ + sccRegWPtr->SCC_CFG = 0x5B000000U; + } + + sccRegWPtr->SCC_CFG = (sccRegWPtr->SCC_CFG & 0xFFFFFF0FU) | + ((uint32_t)divider << 4U); + sccRegPtr->SCC_CFG.LOCK = 1U; + break; + + case CLK_SLOW: + if(sccRegPtr->SCC_CFG.LOCK != 0U) + { + /* unlock this register */ + sccRegWPtr->SCC_CFG = 0x5B000000U; + } + + sccRegWPtr->SCC_CFG = (sccRegWPtr->SCC_CFG & 0xFFFFFFF0U) | + (uint32_t)divider; + sccRegPtr->SCC_CFG.LOCK = 1U; + break; + + default: + /* nothing to do */ + break; + } + +} + +/** + * @brief Select clock source for module + * + * @param[in] module: select which module to set clock source. + * It selects from CLK_EWDT, CLK_STIM, CLK_TIM0, CLK_TIM1, + * CLK_TIM2, CLK_TDG0, CLK_CAN0, CLK_CAN1, CLK_UART0, + * CLK_UART1, CLK_UART2, CLK_UART3, CLK_SPI0, CLK_SPI1, + * CLK_SPI2, CLK_I2C0, CLK_I2C1, CLK_ADC0, CLK_PORTA, + * CLK_PORTB, CLK_PORTC, CLK_PORTD, CLK_PORTE + * + * @param[in] clockSource: select clock source + * @note For CAN0 CAN1, the clock source can only select from CLK_SRC_FIRC64M + * CLK_SRC_OSC40M,CLK_SRC_NO. + * For ADC0, the clock source can only select from CLK_SRC_FIRC64M, + * CLK_SRC_NO. + * This function should only be called when the module is not working, + * otherwise, the clock source will not change. + * @return + * - SUCC + * - ERR: the input parameter is unreasonable. + * + */ +ResultStatus_t CLK_ModuleSrc(CLK_Module_t module, CLK_Src_t clockSource) +{ + uint32_t index = (uint32_t)module >> 2; + /*PRQA S 0303,0306 ++*/ + ModuleClk_t *PARCCx = (ModuleClk_t *)(parccRegPtr[index]); + /*PRQA S 0303,0306 ++*/ + + ResultStatus_t res = SUCC; + + switch(module) + { + case CLK_EWDT: + case CLK_STIM: + case CLK_TIM0: + case CLK_TIM1: + case CLK_TIM2: + case CLK_TDG0: + case CLK_UART0: + case CLK_UART1: + case CLK_UART2: +#if (4U == UART_INSTANCE_NUM) + case CLK_UART3: +#endif + case CLK_SPI0: + case CLK_SPI1: +#if (3U == SPI_INSTANCE_NUM) + case CLK_SPI2: +#endif + case CLK_I2C0: +#if (2U == I2C_INSTANCE_NUM) + case CLK_I2C1: +#endif + case CLK_PORTA: + case CLK_PORTB: + case CLK_PORTC: + case CLK_PORTD: + case CLK_PORTE: + if(PARCCx->BF.LOCK != 0U) + { + /* unlock this register */ + PARCCx->WORDVAL = 0x5B000000U; + } + + PARCCx->BF.CLKMUX = (uint32_t)clockSource; + PARCCx->BF.LOCK = 1U; + break; + + case CLK_CAN0: +#if (2U == CAN_INSTANCE_NUM) + case CLK_CAN1: +#endif + if(PARCCx->BF.LOCK != 0U) + { + /* unlock this register */ + PARCCx->WORDVAL = 0x5B000000U; + } + + if(CLK_SRC_FIRC64M == clockSource) + { + PARCCx->BF.CLKMUX = 1U; + } + else if(CLK_SRC_OSC40M == clockSource) + { + PARCCx->BF.CLKMUX = 2U; + } + else if(CLK_SRC_NO == clockSource) + { + PARCCx->BF.CLKMUX = 0; + } + else + { + res = ERR; + } + + PARCCx->BF.LOCK = 1U; + break; + + case CLK_ADC0: + if(PARCCx->BF.LOCK != 0U) + { + /* unlock this register */ + PARCCx->WORDVAL = 0x5B000000U; + } + + if(CLK_SRC_FIRC64M == clockSource) + { + PARCCx->BF.CLKMUX = (uint32_t)clockSource; + } + else if(CLK_SRC_NO == clockSource) + { + PARCCx->BF.CLKMUX = (uint32_t)CLK_SRC_NO; + } + else + { + res = ERR; + } + PARCCx->BF.LOCK = 1U; + break; + + default: + res = ERR; + break; + } + + return res; +} + + +/** + * @brief get module clock frequency before divider + * + * @param[in] module: select the module + * @param[in] oscFreq: frequency of the OSC clock + * + * @return The clock frequency. If return 0, there is some error. + * + */ +uint32_t CLK_GetModuleClkFreq(CLK_Module_t module,uint32_t oscFreq) +{ + uint32_t index = (uint32_t)module >> 2; + /*PRQA S 0303,0306 ++*/ + ModuleClk_t *PARCCx = (ModuleClk_t *)(parccRegPtr[index]); + /*PRQA S 0303,0306 ++*/ + + uint32_t freq = 0,clkDiv = 1; + + switch(module) + { + case CLK_EWDT: + case CLK_STIM: + case CLK_TIM0: + case CLK_TIM1: + case CLK_TIM2: + case CLK_TDG0: + case CLK_UART0: + case CLK_UART1: + case CLK_UART2: +#if (4U == UART_INSTANCE_NUM) + case CLK_UART3: +#endif + case CLK_SPI0: + case CLK_SPI1: +#if (3U == SPI_INSTANCE_NUM) + case CLK_SPI2: +#endif + case CLK_I2C0: +#if (2U == I2C_INSTANCE_NUM) + case CLK_I2C1: +#endif + case CLK_ADC0: + case CLK_PORTA: + case CLK_PORTB: + case CLK_PORTC: + case CLK_PORTD: + case CLK_PORTE: + clkDiv = (PARCCx->BF.CLKDIV + (uint32_t)1U); + switch((uint32_t)PARCCx->BF.CLKMUX) + { + case (uint32_t)CLK_SRC_LPO32K: + freq = 32000U; + break; + + case (uint32_t)CLK_SRC_OSC32K: + freq = 32768U; + break; + + case (uint32_t)CLK_SRC_FIRC64M: + freq = 64000000U; + break; + + case (uint32_t)CLK_SRC_OSC40M: + freq = oscFreq; + break; + + default: + /* nothing to do */ + break; + } + break; + + case CLK_CAN0: +#if (2U == CAN_INSTANCE_NUM) + case CLK_CAN1: +#endif + clkDiv = (PARCCx->BF.CLKDIV + (uint32_t)1U); + switch(PARCCx->BF.CLKMUX) + { + case 1U: + freq = 64000000U; + break; + + case 2U: + freq = oscFreq; + break; + + default: + /* nothing to do */ + break; + } + break; + + case CLK_CORE: + clkDiv = (sccRegPtr->SCC_CST.DIVCORE + (uint32_t)1U); + freq = CLK_GetSysClkFreq(oscFreq); + break; + + case CLK_BUS: + clkDiv = (sccRegPtr->SCC_CST.DIVCORE + (uint32_t)1U); + clkDiv *= (sccRegPtr->SCC_CST.DIVBUS + (uint32_t)1U); + freq = CLK_GetSysClkFreq(oscFreq); + break; + + case CLK_SLOW: + clkDiv = (sccRegPtr->SCC_CST.DIVCORE + (uint32_t)1U); + clkDiv *= (sccRegPtr->SCC_CST.DIVSLOW +(uint32_t) 1U); + freq = CLK_GetSysClkFreq(oscFreq); + break; + + default: + /* nothing to do */ + break; + } + + return freq/clkDiv; + +} + +/** + * @brief Select TIM external clock source. If TIM is configured to use + * external clock source, this function can select a external clock + * source from a pin. + * + * @param[in] timId: it indicates which TIM to config + * @param[in] clockSrc: select the external TIM clock source + * + * @return None + * + */ +void CLK_TimExternalClkSrc(CLK_TIM_t timId, CLK_TIMExtClk_t clockSrc) +{ + if(CLK_TIM0_ID == timId) + { + scmRegPtr->SCM_TIMOPT.TIM0_CLK_SEL = (uint32_t)clockSrc; + } + else if(CLK_TIM1_ID == timId) + { + scmRegPtr->SCM_TIMOPT.TIM1_CLK_SEL = (uint32_t)clockSrc; + } + else + { + scmRegPtr->SCM_TIMOPT.TIM2_CLK_SEL = (uint32_t)clockSrc; + } +} + +/** + * @brief Get the clock source status + * + * @param[in] clockSource: it can get status of CLK_OUT_LPO32K,CLK_OUT_FIRC64M, + * CLK_OUT_OSC32K,CLK_OUT_OSC40M + * + * @return The clock source status + * + */ +FlagStatus_t CLK_GetClkStatus(CLK_Src_t clockSource) +{ + FlagStatus_t bitStatus = RESET; + + switch(clockSource) + { + case CLK_SRC_LPO32K: + bitStatus = ((pmuRegPtr->PMU_LPO_32K_CFG.LPO_CLK_READY != 0U) ? SET + : RESET); + break; + + case CLK_SRC_FIRC64M: + bitStatus = ((sccRegPtr->SCC_FIRCCS.FIRCRDY != 0U) ? SET : RESET); + break; + + case CLK_SRC_OSC32K: + bitStatus = ((rtcRegPtr->RTC_CSR.OSC_RDY != 0U) ? SET : RESET); + break; + + case CLK_SRC_OSC40M: + bitStatus = ((sccRegPtr->SCC_OSCCS.OSCRDY != 0U) ? SET : RESET); + break; + + default: + /* nothing to do */ + break; + } + + return bitStatus; +} + +/** + * @brief Wait the clock source status until it is ready + * + * @param[in] clockSource: the clock source to be waited + * + * @return SUCC -- the clock is ready + * ERR -- time out + * + */ +ResultStatus_t CLK_WaitClkReady(CLK_Src_t clockSource) +{ + volatile uint32_t localCnt = 0; + ResultStatus_t retVal = ERR; + switch(clockSource) + { + case CLK_SRC_LPO32K: + while(localCnt < CLK_TIMEOUT_WAIT_CNT ) + { + localCnt++; + if (1U == pmuRegPtr->PMU_LPO_32K_CFG.LPO_CLK_READY) + { + retVal = SUCC; + break; + } + } + break; + + case CLK_SRC_FIRC64M: + while(localCnt < CLK_TIMEOUT_WAIT_CNT ) + { + localCnt++; + if (1U == sccRegPtr->SCC_FIRCCS.FIRCRDY) + { + retVal = SUCC; + break; + } + } + break; + + case CLK_SRC_OSC32K: + while(localCnt < CLK_TIMEOUT_WAIT_CNT ) + { + localCnt++; + if (1U == rtcRegPtr->RTC_CSR.OSC_RDY) + { + retVal = SUCC; + break; + } + } + break; + + case CLK_SRC_OSC40M: + while(localCnt < CLK_TIMEOUT_WAIT_CNT ) + { + localCnt++; + if (1U == sccRegPtr->SCC_OSCCS.OSCRDY ) + { + retVal = SUCC; + break; + } + } + break; + + default: + retVal = SUCC; + break; + } + + return retVal; +} + +/** + * @brief Config and Enable clock output + * + * @param[in] outSrc: Select the clock source to be output. + * @param[in] divider: output clock divider + * + * @return none + * + */ +void CLK_ClkOutEnable(CLK_OutSrc_t outSrc, CLK_OutDiv_t divider) +{ + /*Disable clock out first before switching*/ + scmRegPtr->SCM_CHIPCTL.CLKOUTEN = 0; + + switch(outSrc) + { + case CLK_OUT_OSC40M: + case CLK_OUT_FIRC64M: + case CLK_OUT_SLOW: + case CLK_OUT_BUS: + case CLK_OUT_CORE: + scmRegPtr->SCM_CHIPCTL.CLKOUTSEL = 0; + sccRegPtr->SCC_CLKOUTCFG.CLKOUTSEL = (uint32_t)outSrc; + break; + + case CLK_OUT_OSC32K: + scmRegPtr->SCM_CHIPCTL.CLKOUTSEL = 1; + break; + + case CLK_OUT_LPO32K: + scmRegPtr->SCM_CHIPCTL.CLKOUTSEL = 2; + break; + + default: + /* nothing to do */ + break; + } + + scmRegPtr->SCM_CHIPCTL.CLKOUTDIV = (uint32_t)divider; + + /* Enable clock out */ + scmRegPtr->SCM_CHIPCTL.CLKOUTEN = 1; +} + +/** + * @brief Disable clock output + * + * @param[in] none + * + * @return none + * + */ +void CLK_ClkOutDisable(void) +{ + scmRegPtr->SCM_CHIPCTL.CLKOUTEN = 0U; +} + +/** + * @brief install call back function + * + * @param[in] intId: select the interrupt + * @param[in] cbFun: pointer to callback function + * + * @return none + * + */ +void SCC_InstallCallBackFunc(CLK_Int_t intId,isr_cb_t * cbFun) +{ + sccIsrCbFunc[intId] = cbFun; +} + +/** + * @brief Clear Interrupt status + * + * @param[in] intId: select the interrupt + * + * @return none + * + */ +void SCC_IntClear(CLK_Int_t intId) +{ + if(CLK_INT_OSCLOC == intId) + { + if(sccRegPtr->SCC_OSCCS.LOCK != 0U) + { + /* unlock this register */ + sccRegWPtr->SCC_OSCCS = 0x5B000000U; + } + + /* clear int status */ + sccRegPtr->SCC_OSCCS.OSCLOC = 1U; + /* lock */ + sccRegPtr->SCC_OSCCS.LOCK = 1U; + } + + if(CLK_INT_FIRCLOC == intId) + { + if(sccRegPtr->SCC_FIRCCS.LOCK != 0U) + { + /* unlock this register */ + sccRegWPtr->SCC_FIRCCS = 0x5B000000U; + } + + /* clear int status */ + sccRegPtr->SCC_FIRCCS.FIRCLOC = 1U; + /* lock */ + sccRegPtr->SCC_FIRCCS.LOCK = 1U; + } +} + +/** + * @brief SCC IRQHandler function + * + * @param none + * + * @return none + * + */ +void SCC_DriverIRQHandler(void) +{ + if(sccRegPtr->SCC_OSCCS.OSCLOC != 0U) + { + if(sccRegPtr->SCC_OSCCS.LOCK != 0U) + { + /* unlock this register */ + sccRegWPtr->SCC_OSCCS = 0x5B000000U; + } + + /* clear int status */ + sccRegPtr->SCC_OSCCS.OSCLOC = 1U; + /* lock */ + sccRegPtr->SCC_OSCCS.LOCK = 1U; + + if(sccIsrCbFunc[CLK_INT_OSCLOC] != NULL) + { + sccIsrCbFunc[CLK_INT_OSCLOC](); + } + else + { + CLK_OSC40MMonitorDisable(); + } + + } + + if(sccRegPtr->SCC_FIRCCS.FIRCLOC != 0U) + { + if(sccRegPtr->SCC_FIRCCS.LOCK != 0U) + { + /* unlock this register */ + sccRegWPtr->SCC_FIRCCS = 0x5B000000U; + } + + /* clear int status */ + sccRegPtr->SCC_FIRCCS.FIRCLOC = 1U; + /* lock */ + sccRegPtr->SCC_FIRCCS.LOCK = 1U; + + if(sccIsrCbFunc[CLK_INT_FIRCLOC] != NULL) + { + sccIsrCbFunc[CLK_INT_FIRCLOC](); + } + else + { + CLK_FIRC64MMonitorDisable(); + } + + } +} + +/** @} end of group Clock_Public_Functions */ + +/** @} end of group Clock_definitions */ + +/** @} end of group Z20K11X_Peripheral_Driver */ diff --git a/StdDriver/Src/Z20K11xM_cmp.c b/StdDriver/Src/Z20K11xM_cmp.c new file mode 100644 index 0000000..dcf0d5b --- /dev/null +++ b/StdDriver/Src/Z20K11xM_cmp.c @@ -0,0 +1,404 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_cmp.c + * @brief : CMP module driver file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ + +#include "Z20K11xM_cmp.h" + + +/** @addtogroup Z20K11X_Peripheral_Driver + * @{ + */ + +/** @defgroup CMP + * @brief CMP driver modules + * @{ + */ + +/** @defgroup CMP_Private_Type + * @{ + */ + +/** @} end of group CMP_Private_Type*/ + +/** @defgroup CMP_Private_Defines + * @{ + */ +/** @} end of group CMP_Private_Defines */ + +/** @defgroup CMP_Private_Variables + * @{ + */ +static isr_cb_t * cmpIsrCbFunc[CMP_INT_ALL] = {NULL, NULL}; + +/*PRQA S 0303 ++*/ +static cmp_reg_t *const cmpRegPtr = (cmp_reg_t *) CMP_BASE_ADDR; /*!< Analog comparator Register */ +static cmp_reg_w_t *const cmpRegWPtr = (cmp_reg_w_t *) CMP_BASE_ADDR; /*!< Analog comparator Register */ +/*PRQA S 0303 --*/ + +static const uint32_t CMP_InterruptMaskTable[] = +{ + 0x00000001U, /* CMP_INT_RAISE */ + 0x00000002U, /* CMP_INT_FALL */ + 0x00000003U /* CMP_INT_ALL */ +}; +/** @} end of group CMP_Private_Variables */ + +/** @defgroup CMP_Global_Variables + * @{ + */ + +/** @} end of group CMP_Global_Variables */ + +/** @defgroup CMP_Private_FunctionDeclaration + * @{ + */ + +/** @} end of group CMP_Private_FunctionDeclaration */ + +/** @defgroup CMP_Private_Functions + * @{ + */ + +void CMP_DriverIRQHandler(void); +/** @} end of group CMP_Private_Functions */ + +/** @defgroup CMP_Public_Functions + * @{ + */ +/** + * @brief Initialize CMP + * + * @param[in] cfg: the configuration parameters. + * if cfg->mode == CMP_MODE_WINDOW or CMP_MODE_WINDOW_FILTER, + * CMP_WindowConfig() need to be called to config window para. + * if cfg->mode == CMP_MODE_FILTER or CMP_MODE_WINDOW_FILTER, + * CMP_FilterConfig() need to be called to config filter para. + * + * @return none + * + */ +void CMP_Init(const CMP_Config_t * cfg) +{ + cmpRegPtr->CMP_CCR0.CMP_SEL = (uint32_t)(cfg->speed); + if(CMP_SPEED_LOW == cfg->speed) + { + cmpRegPtr->CMP_CCR2.LS_HSTCTR = (uint32_t)(cfg->hyst.ls); + cmpRegPtr->CMP_CCR2.LS_PSEL = (uint32_t)(cfg->pIn); + cmpRegPtr->CMP_CCR2.LS_MSEL = (uint32_t)(cfg->nIn); + } + else + { + cmpRegPtr->CMP_CCR2.HS_HSTCTR = (uint32_t)(cfg->hyst.hs); + cmpRegPtr->CMP_CCR2.HS_PSEL = (uint32_t)(cfg->pIn); + cmpRegPtr->CMP_CCR2.HS_MSEL = (uint32_t)(cfg->nIn); + } + + /* config working mode */ + switch(cfg->mode) + { + case CMP_MODE_BASIC: + cmpRegPtr->CMP_CCR1.WINDOW_EN = 0; + cmpRegPtr->CMP_CCR1.SAMPLE_EN = 0; + break; + + case CMP_MODE_WINDOW: + cmpRegPtr->CMP_CCR1.WINDOW_EN = 1; + cmpRegPtr->CMP_CCR1.SAMPLE_EN = 0; + cmpRegPtr->CMP_CCR1.FILT_CNT = 0; + cmpRegPtr->CMP_CCR1.FILT_PER = 0; + break; + + case CMP_MODE_FILTER: + cmpRegPtr->CMP_CCR1.WINDOW_EN = 0; + cmpRegPtr->CMP_CCR1.SAMPLE_EN = 0; + break; + + case CMP_MODE_SAMPLE: + cmpRegPtr->CMP_CCR1.WINDOW_EN = 0; + cmpRegPtr->CMP_CCR1.SAMPLE_EN = 1; + cmpRegPtr->CMP_CCR1.FILT_CNT = 1; + cmpRegPtr->CMP_CCR1.FILT_PER = 0; + break; + + case CMP_MODE_WINDOW_FILTER: + cmpRegPtr->CMP_CCR1.WINDOW_EN = 1; + cmpRegPtr->CMP_CCR1.SAMPLE_EN = 0; + break; + + default:/*PRQA S 2016*/ + break; + } + + /* default cout after filter */ + cmpRegPtr->CMP_CCR1.COUT_SEL = 0; + + cmpRegPtr->CMP_CCR0.STOP_EN = (uint32_t)(cfg->stopReqEn); + /* select DMA / interrupt request */ + cmpRegPtr->CMP_CCR1.DMA_EN = (uint32_t)(cfg->req); + /* invert output or not */ + cmpRegPtr->CMP_CCR1.COUT_INV = (uint32_t)(cfg->invertEn); + /* output to pad or not */ + cmpRegPtr->CMP_CCR1.COUT_PEN = (uint32_t)(cfg->outToPad); + +} + +/** + * @brief select the output + * + * @param[in] out: select the output + * + * @return None + * + */ +void CMP_SelectOutput(CMP_Output_t out) +{ + cmpRegPtr->CMP_CCR1.COUT_SEL = (uint32_t)out; +} + +/** + * @brief Config filter parameters + * + * @param[in] cnt: the consecutive sample count number that agree the output + * value to be changed. The range is 1 - 7. If it is 0, the + * filter is bypassed. + * @param[in] period: the sampling period in bus clock of the output filter. + * The range is 1-0xff. If it is 0, filter is bypassed + * + * @return None + * + */ +void CMP_FilterConfig(uint32_t cnt, uint32_t period) +{ + cmpRegPtr->CMP_CCR1.FILT_PER = period; + cmpRegPtr->CMP_CCR1.FILT_CNT = cnt; +} + +/** + * @brief Config window mode parameter + * + * @param[in] closedLvl: Select the output level when window is closed + * + * @return None + * + */ +void CMP_WindowConfig(CMP_WinOutLvl_t closedLvl) +{ + if(CMP_WIN_OUT_LVL_LAST == closedLvl) + { + cmpRegPtr->CMP_CCR1.COUT_OWE = 0; + } + else + { + cmpRegPtr->CMP_CCR1.COUT_OWE = 1; + cmpRegPtr->CMP_CCR1.COUT_OW = ((uint32_t)closedLvl) >> 1; + } +} + +/** + * @brief Initialize DAC + * + * @param[in] vref: Select the reference voltage + * + * @return None + * + */ +void CMP_DacInit(CMP_DACVref_t vref) +{ + cmpRegPtr->CMP_DCR.VREF_SEL = (uint32_t)vref; +} + +/** + * @brief Enable DAC + * + * @param[in] None + * + * @return None + * + */ +void CMP_DacEnable(void) +{ + cmpRegPtr->CMP_DCR.DAC_EN = 1; +} + +/** + * @brief Disable DAC + * + * @param[in] None + * + * @return None + * + */ +void CMP_DacDisable(void) +{ + cmpRegPtr->CMP_DCR.DAC_EN = 0; +} + +/** + * @brief set DAC output value + * + * @param[in] data: the data to be converted. The range is 0 - 0xFF. + * + * @return None + * + */ +void CMP_DacSetValue(uint8_t data) +{ + cmpRegPtr->CMP_DCR.DAC_SEL = data; +} + +/** + * @brief Trigger CMP + * + * @param[in] type: select how to trigger the CMP + * + * @return none + * + */ +void CMP_Trigger(CMP_Trigger_t type) +{ + if(CMP_SW_TRIGGER == type) + { + cmpRegPtr->CMP_CCR0.CMP_EN = 1; + cmpRegPtr->CMP_CCR0.SOC_TRG_EN = 0; + } + else + { + cmpRegPtr->CMP_CCR0.CMP_EN = 0; + cmpRegPtr->CMP_CCR0.SOC_TRG_EN = 1; + } +} + +/** + * @brief Clear CMP trigger + * + * @param[in] none + * + * @return none + * + */ +void CMP_TriggerClear(void) +{ + cmpRegPtr->CMP_CCR0.CMP_EN = 0; + cmpRegPtr->CMP_CCR0.SOC_TRG_EN = 0; +} + +/** + * @brief Get CMP output value + * + * @param[in] none + * + * @return 0 -- low level + * 1 -- high level + * + */ +uint32_t CMP_GetOutput(void) +{ + return cmpRegPtr->CMP_CSR.COUT; +} + +/** + * @brief Install callback function + * + * @param[in] intType: select interrrupt type + * @param[in] cbFun: indicate callback function + * + * @return none + * + */ +void CMP_InstallCallBackFunc(CMP_Int_t intType, isr_cb_t * cbFun) +{ + if(intType >= CMP_INT_ALL) + { + + } + else + { + cmpIsrCbFunc[intType] = cbFun; + } +} + +/** + * @brief Mask/Unmask interrupt + * + * @param[in] intType: select interrrupt type + * @param[in] intMask: MASK/UNMASK + * + * @return none + * + */ +void CMP_IntMask(CMP_Int_t intType, IntMask_t intMask) +{ + if(UNMASK == intMask) + { + cmpRegWPtr->CMP_IER |= CMP_InterruptMaskTable[intType]; + } + else + { + cmpRegWPtr->CMP_IER &= ~CMP_InterruptMaskTable[intType]; + } +} + +/** + * @brief Clear interrupt + * + * @param[in] intType: select interrrupt type + * + * @return none + * + */ +void CMP_IntClear(CMP_Int_t intType) +{ + uint32_t intstatus = cmpRegWPtr->CMP_CSR; + intstatus |= CMP_InterruptMaskTable[intType]; + cmpRegWPtr->CMP_CSR = intstatus; +} + +/** + * @brief CMP IRQHandler + * + * @param[in] none + * + * @return none + * + */ +void CMP_DriverIRQHandler(void) +{ + uint32_t status; + uint32_t intType; + + status = cmpRegWPtr->CMP_CSR; + /* get status */ + status = status & 0x00000003U; + status &= cmpRegWPtr->CMP_IER; + /* clear int status */ + cmpRegWPtr->CMP_CSR = status; + + for(intType = (uint32_t)CMP_INT_RAISE; intType < (uint32_t)CMP_INT_ALL; intType++) + { + if((status & (0x00000001UL << intType)) != 0U) + { + if(cmpIsrCbFunc[intType] != NULL) + { + cmpIsrCbFunc[intType](); + } + else + { + cmpRegWPtr->CMP_IER &= ~((uint32_t)0x00000001U << intType); + } + } + } +} + +/** @} end of group CMP_Public_Functions */ + +/** @} end of group CMP_definitions */ + +/** @} end of group Z20K11X_Peripheral_Driver */ diff --git a/StdDriver/Src/Z20K11xM_crc.c b/StdDriver/Src/Z20K11xM_crc.c new file mode 100644 index 0000000..af30e29 --- /dev/null +++ b/StdDriver/Src/Z20K11xM_crc.c @@ -0,0 +1,228 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_crc.c + * @brief : CRC module driver file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ + +#include "Z20K11xM_crc.h" + +/** @addtogroup Z20K11X_Peripheral_Driver + * @{ + */ +/** @defgroup CRC + * @brief CRC driver modules + * @{ + */ + +/** @defgroup CRC_Private_Type + * @{ + */ + +/** @} end of group CRC_Private_Type*/ + +/** @defgroup CRC_Private_Defines + * @{ + */ +#define CRC_WRITE_DATA \ + (0U) /*!< Writes to the CRC data register are data values */ +#define CRC_WRITE_SEED \ + (1U) /*!< Writes to the CRC data register are seed values */ +#define CRC_WRITE_BIT_Y_BYTE_Y \ + (2U) /*!< Both bits in bytes and bytes are transposed */ +#define CRC_WRITE_BIT_N_BYTE_Y \ + (3U) /*!< Only bytes are transposed; no bits in a byte are transposed */ + +/** @} end of group CRC_Private_Defines */ +/** @defgroup CRC_Private_Variables + * @{ + */ +/** + * @brief CRC address array + */ +/*PRQA S 0303 ++*/ +static crc_reg_w_t *const crcRegWPtr = (crc_reg_w_t *)CRC_BASE_ADDR; +static crc_reg_t *const crcRegPtr = (crc_reg_t *)CRC_BASE_ADDR; +/*PRQA S 0303 --*/ +/** @}end of group CRC_Private_Variables */ + +/** @defgroup CRC_Public_FunctionDeclaration + * @{ + */ + +/** + * @brief Initialization of CRC. + * In this version of the CRC, user configuration write type is CRC_WRITE_NO + * (No Transposition),the actual configuration is: bit no transposed, BYTE + * transposed. + * User configuration write type is CRC_WRITE_BIT_Y_BYTE_N (Bits in bytes are + * transposed; bytes are not transposed),the actual configuration is: both bits + * in bytes and bytes are transposed. + * + * @param[in] crcCfgStruct: Pointer to a CRC configuration structure. + * + * @return none. + * + */ +void CRC_Init(const CRC_Config_t *crcCfgStruct) +{ + if (crcCfgStruct != NULL) + { + crcRegPtr->CRC_CTRL.MODE = (uint32_t)(crcCfgStruct->dataMode); + crcRegPtr->CRC_CTRL.CR = (uint32_t)(crcCfgStruct->complementRead); + if ((uint32_t)CRC_MODE_16BIT == crcRegPtr->CRC_CTRL.MODE) + { + crcRegPtr->CRC_POLY.LPHW = (uint32_t)(crcCfgStruct->poly); + } + else + { + crcRegWPtr->CRC_POLY = (uint32_t)(crcCfgStruct->poly); + } + + if (CRC_WRITE_NO == crcCfgStruct->writeType) + { + crcRegPtr->CRC_CTRL.WT = CRC_WRITE_BIT_N_BYTE_Y; + } + else + { + crcRegPtr->CRC_CTRL.WT = CRC_WRITE_BIT_Y_BYTE_Y; + } + crcRegPtr->CRC_CTRL.RT = (uint32_t)(crcCfgStruct->readType); + crcRegPtr->CRC_CTRL.WS = (uint32_t)CRC_WRITE_SEED; + crcRegWPtr->CRC_DATA = crcCfgStruct->seedValue; + } +} + +/** + * @brief CRC calculation of 16 bits. + * + * + * @param[in] dataValue: 8 bits of calculated data + * @param[in] length: the length of the array + * @param[in] newSeed: Sets new CRC calculations + * - ENABLE: New seed sets and used for new calculation + * - DISABLE:Seed argument ignored, continues old + * calculation + * @param[in] seedValue: new seed if newSeed is enabled,else ignored + * + * @return 16-bit calculation results + * + */ + +uint16_t CRC_CalcCRC16bit(uint8_t dataValue[], uint32_t length, + ControlState_t newSeed, uint32_t seedValue) +{ + uint16_t ret; + uint32_t index = 0U; + uint32_t readTypeVal; + uint32_t data32; + uint32_t len; + + len = length; + if (ENABLE == newSeed) + { + crcRegPtr->CRC_CTRL.WS = (uint32_t)CRC_WRITE_SEED; + crcRegWPtr->CRC_DATA = seedValue; + } + + crcRegPtr->CRC_CTRL.WS = (uint32_t)CRC_WRITE_DATA; + + while (len >= 4U) + { + data32 = ((uint32_t)dataValue[index]) | + ((uint32_t)dataValue[index + 1UL] << 8U) | + ((uint32_t)dataValue[index + 2UL] << 16U) | + ((uint32_t)dataValue[index + 3UL] << 24U); + *(uint32_t volatile *)(&(crcRegWPtr->CRC_DATA)) = data32; + len -= 4U; + index += 4U; + + } + + while (len > 0U) + { + *(uint8_t volatile *)(&(crcRegWPtr->CRC_DATA)) = + *(uint8_t *)(&dataValue[index]); + len -= 1U; + index += 1U; + } + + readTypeVal = crcRegPtr->CRC_CTRL.RT; /* Misra improvement */ + + if ((((uint32_t)CRC_READ_NO) == readTypeVal) || + (((uint32_t)CRC_READ_BIT_Y_BYTE_N) == readTypeVal)) + { + ret = (uint16_t)(crcRegWPtr->CRC_DATA); + } + else + { + ret = (uint16_t)(crcRegWPtr->CRC_DATA >> 16); + } + + return ret; +} + +/** + * @brief CRC calculation of 32 bits + * + * + * @param[in] dataValue: 8 bits of calculated data + * @param[in] length: the length of the array + * @param[in] newSeed: Sets new CRC calculations + * - ENABLE: New seed sets and used for new calculation + * - DISABLE:Seed argument ignored, continues old + * calculation + * @param[in] seedValue: new seed if newSeed is enabled,else ignored + * + * @return 32-bit calculation results + * + */ +uint32_t CRC_CalcCRC32bit(uint8_t dataValue[], uint32_t length, + ControlState_t newSeed, uint32_t seedValue) +{ + uint32_t index = 0U; + uint32_t data32; + uint32_t len; + + len = length; + + if (ENABLE == newSeed) + { + crcRegPtr->CRC_CTRL.WS = (uint32_t)CRC_WRITE_SEED; + crcRegWPtr->CRC_DATA = seedValue; + } + + crcRegPtr->CRC_CTRL.WS = (uint32_t)CRC_WRITE_DATA; + + while (len >= 4U) + { + data32 = ((uint32_t)dataValue[index]) | + ((uint32_t)dataValue[index + 1UL] << 8U) | + ((uint32_t)dataValue[index + 2UL] << 16U) | + ((uint32_t)dataValue[index + 3UL] << 24U); + *(uint32_t volatile *)(&(crcRegWPtr->CRC_DATA)) = data32; + index += 4U; + len -= 4U; + } + + while (len > 0U) + { + *(uint8_t volatile *)(&(crcRegWPtr->CRC_DATA)) = + *(uint8_t *)(&dataValue[index]); + len -= 1U; + index += 1U; + } + + return crcRegWPtr->CRC_DATA; +} + +/** @} end of group CRC_Public_FunctionDeclaration */ + +/** @} end of group CRC */ + +/** @} end of group Z20K11X_Peripheral_Driver */ diff --git a/StdDriver/Src/Z20K11xM_dma.c b/StdDriver/Src/Z20K11xM_dma.c new file mode 100644 index 0000000..21c9a15 --- /dev/null +++ b/StdDriver/Src/Z20K11xM_dma.c @@ -0,0 +1,1221 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_dma.c + * @brief : DMA module driver file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ + +#include "Z20K11xM_dma.h" + +/** @addtogroup Z20K11XM_Peripheral_Driver + * @{ + */ + +/** @defgroup DMA + * @brief DMA driver modules + * @{ + */ + +/** @defgroup DMA_Private_Defines + * @{ + */ +/*PRQA S 0303 ++*/ +static dma_chmux_reg_t * const dmaMuxRegPtr = (dma_chmux_reg_t *) DMAMUX_BASE_ADDR; /*!< DMAMUX Register */ +static dma_reg_t * const dmaRegPtr = (dma_reg_t *) DMA_BASE_ADDR; /*!< DMA Register */ +static dma_reg_w_t * const dmaRegWPtr = (dma_reg_w_t *) DMA_BASE_ADDR; /*!< DMA Word Register */ +/*PRQA S 0303 --*/ + +#define DMA0TO3_NUM 0x00000004U /*!< dma 0 to 3 int entry idx */ +#define DMA4TO7_NUM 0x00000008U /*!< dma 4 to 7 int entry idx */ +#define DMA8TO11_NUM 0x0000000CU /*!< dma 8 to 11 int entry idx */ +#define DMA12TO15_NUM 0x00000010U /*!< dma 12 to 15 int entry idx */ + +#define DMA_CHANNEL0_MASK 0x00000001U /*!< dma channel 0 mask */ +#define DMA_CHANNEL1_MASK 0x00000002U /*!< dma channel 1 mask */ +#define DMA_CHANNEL2_MASK 0x00000004U /*!< dma channel 2 mask */ +#define DMA_CHANNEL3_MASK 0x00000008U /*!< dma channel 3 mask */ +#define DMA_CHANNEL4_MASK 0x00000010U /*!< dma channel 4 mask */ +#define DMA_CHANNEL5_MASK 0x00000020U /*!< dma channel 5 mask */ +#define DMA_CHANNEL6_MASK 0x00000040U /*!< dma channel 6 mask */ +#define DMA_CHANNEL7_MASK 0x00000080U /*!< dma channel 7 mask */ +#define DMA_CHANNEL8_MASK 0x00000100U /*!< dma channel 8 mask */ +#define DMA_CHANNEL9_MASK 0x00000200U /*!< dma channel 9 mask */ +#define DMA_CHANNEL10_MASK 0x00000400U /*!< dma channel 10 mask */ +#define DMA_CHANNEL11_MASK 0x00000800U /*!< dma channel 11 mask */ +#define DMA_CHANNEL12_MASK 0x00001000U /*!< dma channel 12 mask */ +#define DMA_CHANNEL13_MASK 0x00002000U /*!< dma channel 13 mask */ +#define DMA_CHANNEL14_MASK 0x00004000U /*!< dma channel 14 mask */ +#define DMA_CHANNEL15_MASK 0x00008000U /*!< dma channel 15 mask */ +#define DMA_CHANNELALL_MASK 0x0000FFFFU /*!< dma all channels mask */ + +#define DMA_CHANNEL_PRI_MASK ((uint32_t)0x0000000FU) /*!< dma channel priority mask */ + +/** + * @brief Calculate priority shift of reg via channel + */ +#define DMA_CHANNEL_PRI_SHIFT(x) ((uint32_t)(24U - (((uint32_t)(x) & 0x03U) << 3U))) +#define DMA_CHANNEL_PREEMPT_MASK ((uint32_t)0x00000003U) /*!< dma channel preempt set mask */ + +/** + * @brief Calculate preempt shift of reg via channel + */ +#define DMA_CHANNEL_PREEMPT_SHIFT(x) ((uint32_t)(30U - (((uint32_t)(x) & 0x03U) << 3U))) + +/** + * @brief Get base address of priority reg + */ +#define DMA_PRIORITY_REG_BASEADDR ((uint32_t)(&(dmaRegWPtr->DMA_CPRI0))) + +#define DMA_ERROR_ALL_MASK 0x00008000U /*!< dma all error mask */ +#define DMA_ERROR_PRIORITY_MASK 0x00002000U /*!< dma priority error mask */ +#define DMA_ERROR_SRCADDR_MASK 0x00000080U /*!< dma src addr unalign error mask */ +#define DMA_ERROR_SRCOFFSET_MASK 0x00000040U /*!< dma src offset unalign error mask */ +#define DMA_ERROR_DESTADDR_MASK 0x00000020U /*!< dma dest addr unalign error mask */ +#define DMA_ERROR_DESTOFFSET_MASK 0x00000010U /*!< dma dest offset unalign error mask */ +#define DMA_ERROR_TRANSFERNUM_MASK 0x00000008U /*!< dma number of transfer unalign error mask */ +#define DMA_ERROR_SRCBUS_MASK 0x00000002U /*!< dma src access error mask */ +#define DMA_ERROR_DESTBUS_MASK 0x00000001U /*!< dma dest access error mask */ + +#define DMA_ERROR_ALL_SHIFT 15U /*!< dma all error shift */ +#define DMA_ERROR_PRIORITY_SHIFT 13U /*!< dma priority error shift */ +#define DMA_ERROR_SRCADDR_SHIFT 7U /*!< dma src addr unalign error shift */ +#define DMA_ERROR_SRCOFFSET_SHIFT 6U /*!< dma src offset unalign error shift */ +#define DMA_ERROR_DESTADDR_SHIFT 5U /*!< dma dest addr unalign error shift */ +#define DMA_ERROR_DESTOFFSET_SHIFT 4U /*!< dma dest offset unalign error shift */ +#define DMA_ERROR_TRANSFERNUM_SHIFT 3U /*!< dma number of transfer unalign error shift */ +#define DMA_ERROR_SRCBUS_SHIFT 1U /*!< dma src access error shift */ +#define DMA_ERROR_DESTBUS_SHIFT 0U /*!< dma dest access error shift */ + +/** + * @brief Calculate set value of mask control + */ +#define DMA_MASK_CONVERT_ENABLE(x) (((uint32_t)(x) + 1U) & 0x1U) + +#define DMA_GCC_WPEN0_MASK 0x80808000U /*!< WPEN0 of global channel control reg mask */ +#define DMA_GCC_WPEN1_MASK 0x80800080U /*!< WPEN1 of global channel control reg mask */ +#define DMA_GCC_WPEN2_MASK 0x80008080U /*!< WPEN2 of global channel control reg mask */ +#define DMA_GCC_WPEN3_MASK 0x00808080U /*!< WPEN3 of global channel control reg mask */ +#define DMA_GCC_WPEN03_MASK 0x00808000U /*!< WPEN0&3 of global channel control reg mask */ +#define DMA_GCC_WPEN23_MASK 0x00008080U /*!< WPEN2&3 of global channel control reg mask */ +#define DMA_GCC_CACIS_MASK 0x40000000U /*!< CACIS of global channel control reg mask */ +#define DMA_GCC_CACES_MASK 0x00400000U /*!< CACES of global channel control reg mask */ +#define DMA_GCC_SACSTART_MASK 0x00004000U /*!< SACSTART of global channel control reg mask */ +#define DMA_GCC_CACDONE_MASK 0x00000040U /*!< CACDONE of global channel control reg mask */ +#define DMA_GCC_CACIES_MASK 0x40400000U /*!< CACIS&CACES of global channel control reg mask */ +#define DMA_GCC_CCIS_MASK 0x0F000000U /*!< CCIS of global channel control reg mask */ +#define DMA_GCC_CCES_MASK 0x000F0000U /*!< CCES of global channel control reg mask */ +#define DMA_GCC_SCSTART_MASK 0x00000F00U /*!< SCSTART of global channel control reg mask */ +#define DMA_GCC_CCDONE_MASK 0x0000000FU /*!< CCDONE of global channel control reg mask */ +#define DMA_GCC_CCIES_MASK 0x0F0F0000U /*!< CCIS&CCES of global channel control reg mask */ +#define DMA_GCC_CCDONE_SHIFT 0U /*!< CCDONE of global channel control reg shift */ +#define DMA_GCC_CCES_SHIFT 16U /*!< CCES of global channel control reg shift */ +#define DMA_GCC_CCIS_SHIFT 24U /*!< CCIS of global channel control reg shift */ + +#define DMA_CHANNEL_NUM 16U /*!< max number of dma channels */ + +/** + * @brief Calculate whether unsigned number is divided with no remainder + */ +#define DMA_GET_UNSIGNED_REMAINDER(x, y) ((uint32_t)(x) & (((uint32_t)1U << (uint32_t)(y)) - 1U)) + +/** + * @brief Calculate whether signed number is divided with no remainder + */ +#define DMA_GET_SIGNED_REMAINDER(x, y) ((int32_t)(x) >= 0 ? \ + ((uint32_t)(x) & (((uint32_t)1U << (uint32_t)(y)) - 1U)) : \ + ((((uint32_t)(x) - 1U) ^ 0xFFFFFFFFU) & \ + (((uint32_t)1U << (uint32_t)(y)) - 1U))) + +/** @} end of group DMA_Private_Defines */ + + +/** @defgroup DMA_Private_Type + * @{ + */ + +/** @} end of group DMA_Private_Type*/ + + + +/** @defgroup DMA_Private_Variables + * @{ + */ + +/*! @brief dma channel mask array */ +static const uint32_t dmaChannelMask[] = +{ + DMA_CHANNEL0_MASK, /*!< dma channel 0 mask */ + DMA_CHANNEL1_MASK, /*!< dma channel 1 mask */ + DMA_CHANNEL2_MASK, /*!< dma channel 2 mask */ + DMA_CHANNEL3_MASK, /*!< dma channel 3 mask */ + DMA_CHANNEL4_MASK, /*!< dma channel 4 mask */ + DMA_CHANNEL5_MASK, /*!< dma channel 5 mask */ + DMA_CHANNEL6_MASK, /*!< dma channel 6 mask */ + DMA_CHANNEL7_MASK, /*!< dma channel 7 mask */ + DMA_CHANNEL8_MASK, /*!< dma channel 8 mask */ + DMA_CHANNEL9_MASK, /*!< dma channel 9 mask */ + DMA_CHANNEL10_MASK, /*!< dma channel 10 mask */ + DMA_CHANNEL11_MASK, /*!< dma channel 11 mask */ + DMA_CHANNEL12_MASK, /*!< dma channel 12 mask */ + DMA_CHANNEL13_MASK, /*!< dma channel 13 mask */ + DMA_CHANNEL14_MASK, /*!< dma channel 14 mask */ + DMA_CHANNEL15_MASK /*!< dma channel 15 mask */ +}; + +/*! @brief dma error shift array */ +static const uint32_t dmaErrorShift[] = +{ + DMA_ERROR_PRIORITY_SHIFT, /*!< dma priority error shift */ + DMA_ERROR_SRCADDR_SHIFT, /*!< dma src addr unalign error shift */ + DMA_ERROR_SRCOFFSET_SHIFT, /*!< dma src offset unalign error shift */ + DMA_ERROR_DESTADDR_SHIFT, /*!< dma dest addr unalign error shift */ + DMA_ERROR_DESTOFFSET_SHIFT, /*!< dma dest offset unalign error shift */ + DMA_ERROR_TRANSFERNUM_SHIFT, /*!< dma number of transfer unalign error shift */ + DMA_ERROR_SRCBUS_SHIFT, /*!< dma src access error shift */ + DMA_ERROR_DESTBUS_SHIFT, /*!< dma dest access error shift */ + DMA_ERROR_ALL_SHIFT /*!< dma all error shift */ +}; + +static const uint32_t dmaGccWpenMask[] = +{ + DMA_GCC_WPEN2_MASK, /*!< WPEN2 of global channel control reg mask */ + DMA_GCC_WPEN3_MASK, /*!< WPEN3 of global channel control reg mask */ + DMA_GCC_WPEN23_MASK /*!< WPEN2&3 of global channel control reg mask */ +}; + +static const uint32_t dmaGccClearAllChannelsMask[] = +{ + DMA_GCC_CACES_MASK, /*!< CACES of global channel control reg mask */ + DMA_GCC_CACIS_MASK, /*!< CACIS of global channel control reg mask */ + DMA_GCC_CACIES_MASK /*!< CACIS&CACES of global channel control reg mask */ +}; + +static const uint32_t dmaGccClearChannelsMask[] = +{ + DMA_GCC_CCES_MASK, /*!< CCES of global channel control reg mask */ + DMA_GCC_CCIS_MASK, /*!< CCIS of global channel control reg mask */ + DMA_GCC_CCIES_MASK /*!< CCIS&CCES of global channel control reg mask */ +}; + +/*! @brief DMA ISR CallBack VECTOR structure */ +static isr_cb_t * dmaIsrCb[DMA_CHANNEL_NUM][DMA_INT_ALL]= +{ + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL}, + {NULL, NULL} +}; + +/** @} end of group DMA_Private_Variables */ + +/** @defgroup DMA_Global_Variables + * @{ + */ + +/** @} end of group DMA_Global_Variables */ + +/** @defgroup DMA_Private_FunctionDeclaration + * @{ + */ + +void DMA0TO3_DriverIRQHandler(void); +void DMA4TO7_DriverIRQHandler(void); +void DMA8TO11_DriverIRQHandler(void); +void DMA12TO15_DriverIRQHandler(void); +void DMAERR_DriverIRQHandler(void); +/** @} end of group DMA_Private_FunctionDeclaration */ + +/** @defgroup DMA_Private_Functions + * @{ + */ + +/** @} end of group DMA_Private_Functions */ + + +/** @defgroup DMA_Public_Functions + * @{ + */ + +/** + * @brief Select dmamux input source Function + * + * @param[in] outChannel: output channel id. + * @param[in] questSource: inpout source. + * + * @return none + * + */ +void DMAMUX_SelChannelSource(DMA_Channel_t outChannel, + DMA_RequestSource_t questSource) +{ + dmaMuxRegPtr->DMA_MUX_CH_CFG[outChannel].SRC_MUX = (uint32_t)questSource; +} + +/** + * @brief Enable dmamux output channel Function + * + * @param[in] outChannel: output channel id. + * + * @return none + * + */ +void DMAMUX_OutputChannelEnable(DMA_Channel_t outChannel) +{ + dmaMuxRegPtr->DMA_MUX_CH_CFG[outChannel].ENABLE = 1U; +} + +/** + * @brief Disable dmamux output channel Function + * + * @param[in] outChannel: output channel id. + * + * @return none + * + */ +void DMAMUX_OutputChannelDisable(DMA_Channel_t outChannel) +{ + dmaMuxRegPtr->DMA_MUX_CH_CFG[outChannel].ENABLE = 0U; +} + + +/** + * @brief Dma Initializes Function + * + * @param[in] ptDMAInitConfig: Pointer to a DMA configuration structure. + * + * @return none + * + */ +void DMA_Init(const DMA_Config_t * ptDMAInitConfig) +{ + dmaRegPtr->DMA_CONF.HOEE = (uint32_t)ptDMAInitConfig->dmaErrorBehavior; + dmaRegPtr->DMA_CONF.DBGE = (uint32_t)ptDMAInitConfig->dmaDebugBehavior; + dmaRegPtr->DMA_CONF.RRCAE = (uint32_t)ptDMAInitConfig->dmaPriorityArbitration; +} + +/** + * @brief Get dma busy status Function + * + * @param[in] none + * + * @return busy status. + * + */ +FlagStatus_t DMA_GetDmaBusyStatus(void) +{ + return ((FlagStatus_t)dmaRegPtr->DMA_CONF.BUSY); +} + +/** + * @brief Halt dma Function + * + * @param[in] cmd: halt control + * - ENABLE: stall the dma start a new channels for transfer + * - DISABLE: dma is not stall + * + * @return none. + * + */ +void DMA_HaltControl(ControlState_t cmd) +{ + dmaRegPtr->DMA_CONF.HALT = (uint32_t)cmd; +} + +/** + * @brief Get dma halt status Function + * + * @param[in] none + * + * @return whether dma halt is asserted or not. + * + */ +FlagStatus_t DMA_GetHaltStatus(void) +{ + return ((FlagStatus_t)dmaRegPtr->DMA_CONF.HALT); +} + +/** + * @brief Set dma priority arbitration mode Function + * + * @param[in] channelArbitration: arbitration mode + * + * @return none. + * + */ +void DMA_SetPriorityArbitrationMode(DMA_PriorityArbitration_t arbitration) +{ + dmaRegPtr->DMA_CONF.RRCAE = (uint32_t)arbitration; +} + +/** + * @brief Get dma current priority arbitration mode Function + * + * @param[in] none + * + * @return current priority arbitration mode. + * + */ +DMA_PriorityArbitration_t DMA_GetPriorityArbitrationMode(void) +{ + return ((DMA_PriorityArbitration_t)dmaRegPtr->DMA_CONF.RRCAE); +} + +/** + * @brief Enable dma channel request Function + * + * @param[in] channel: dma channel id + * + * @return none. + * + */ +void DMA_ChannelRequestEnable(DMA_Channel_t channel) +{ + dmaRegWPtr->DMA_DMAE |= dmaChannelMask[channel]; +} + +/** + * @brief Disable dma channel request Function + * + * @param[in] channel: dma channel id + * + * @return none. + * + */ +void DMA_ChannelRequestDisable(DMA_Channel_t channel) +{ + dmaRegWPtr->DMA_DMAE &= ~dmaChannelMask[channel]; +} + +/** + * @brief Get dma channel request status Function + * + * @param[in] channel: dma channel id + * + * @return whether dma channel request enable bit is asserted or not. + * + */ +FlagStatus_t DMA_GetChannelRequestStatus(DMA_Channel_t channel) +{ + return ((FlagStatus_t)((uint32_t)(dmaRegWPtr->DMA_DMAE >> (uint32_t)channel & 0x01U))); +} + +/** + * @brief Set dma channel priority Function + * + * @param[in] channel: dma channel id + * @param[in] priority: channel priority + * + * @return none. + * + */ +void DMA_SetChannelPriority(DMA_Channel_t channel, + DMA_ChannelPriority_t priority) +{ + uint32_t regValue; + /*PRQA S 0303 ++*/ + volatile uint32_t * priRegPtr = (volatile uint32_t *)(DMA_PRIORITY_REG_BASEADDR + + ((uint32_t)channel >> 0x2U) * 4U); + /*PRQA S 0303 --*/ + + regValue = *priRegPtr; + regValue &= ~(DMA_CHANNEL_PRI_MASK << DMA_CHANNEL_PRI_SHIFT(channel)); + regValue |= (uint32_t)priority << DMA_CHANNEL_PRI_SHIFT(channel); + *priRegPtr = regValue; +} + +/** + * @brief Get dma channel priority Function + * + * @param[in] channel: dma channel id + * + * @return channel priority. + * + */ +DMA_ChannelPriority_t DMA_GetChannelPriority(DMA_Channel_t channel) +{ + /*PRQA S 0303 ++*/ + volatile uint32_t * priRegPtr = (volatile uint32_t *)(DMA_PRIORITY_REG_BASEADDR + + ((uint32_t)channel >> 0x2U) * 4U); + /*PRQA S 0303 --*/ + + return ((DMA_ChannelPriority_t)((uint32_t)(*priRegPtr >> + DMA_CHANNEL_PRI_SHIFT(channel) & DMA_CHANNEL_PRI_MASK))); +} + +/** + * @brief Set dma channel preempt type Function + * + * @param[in] channel: dma channel id + * @param[in] preempt: channel preempt type + * + * @return none. + * + */ +void DMA_SetChannelPreempt(DMA_Channel_t channel, + DMA_ChannelPreempt_t preempt) +{ + uint32_t regValue; + /*PRQA S 0303 ++*/ + volatile uint32_t * priRegPtr = (volatile uint32_t *)(DMA_PRIORITY_REG_BASEADDR + + ((uint32_t)channel >> 0x2U) * 4U); + /*PRQA S 0303 --*/ + + regValue = *priRegPtr; + regValue &= ~(DMA_CHANNEL_PREEMPT_MASK << + DMA_CHANNEL_PREEMPT_SHIFT(channel)); + regValue |= (uint32_t)preempt << DMA_CHANNEL_PREEMPT_SHIFT(channel); + *priRegPtr = regValue; +} + +/** + * @brief Get dma channel preempt type Function + * + * @param[in] channel: dma channel id + * + * @return channel preempt type. + * + */ +DMA_ChannelPreempt_t DMA_GetChannelPreempt(DMA_Channel_t channel) +{ + /*PRQA S 0303 ++*/ + volatile uint32_t * priRegPtr = (volatile uint32_t *)(DMA_PRIORITY_REG_BASEADDR + + ((uint32_t)channel >> 0x2U) * 4U); + /*PRQA S 0303 --*/ + + return ((DMA_ChannelPreempt_t)((uint32_t)(*priRegPtr >> + DMA_CHANNEL_PREEMPT_SHIFT(channel) & DMA_CHANNEL_PREEMPT_MASK))); +} + +/** + * @brief Set dma source address Function + * + * @param[in] channel: dma channel id + * @param[in] address: dma transfer source address. + * + * @return none. + * + */ +void DMA_SetSrcAddr(DMA_Channel_t channel, uint32_t address) +{ + dmaRegPtr->DMA_CH_CONFIG[channel].DMA_SADDR.SADDR = address; +} + +/** + * @brief Get dma source address Function + * + * @param[in] channel: dma channel id + * + * @return dma source address. + * + */ +uint32_t DMA_GetSrcAddr(DMA_Channel_t channel) +{ + return ((uint32_t)dmaRegPtr->DMA_CH_CONFIG[channel].DMA_SADDR.SADDR); +} + +/** + * @brief Set dma destination address Function + * + * @param[in] channel: dma channel id + * @param[in] address: dma transfer destination address + * + * @return none. + * + */ +void DMA_SetDestAddr(DMA_Channel_t channel, uint32_t address) +{ + dmaRegPtr->DMA_CH_CONFIG[channel].DMA_DADDR.DADDR = address; +} + +/** + * @brief Get dma destination address Function + * + * @param[in] channel: dma channel id + * + * @return dma destination address. + * + */ +uint32_t DMA_GetDestAddr(DMA_Channel_t channel) +{ + return ((uint32_t)dmaRegPtr->DMA_CH_CONFIG[channel].DMA_DADDR.DADDR); +} + +/** + * @brief Set dma source address offset in minor loop Function + * + * @param[in] channel: dma channel id + * @param[in] offest: dma source address offset in minor loop + * + * @return none. + * + */ +void DMA_SetMinorLoopSrcOffest(DMA_Channel_t channel, int16_t offest) +{ + dmaRegPtr->DMA_CH_CONFIG[channel].DMA_AOFF.SAOFF = offest; +} + +/** + * @brief Set dma destination address offset in minor loop Function + * + * @param[in] channel: dma channel id + * @param[in] offest: dma destination address offset in minor loop + * + * @return none. + * + */ +void DMA_SetMinorLoopDestOffest(DMA_Channel_t channel, int16_t offest) +{ + dmaRegPtr->DMA_CH_CONFIG[channel].DMA_AOFF.DAOFF = offest; +} + +/** + * @brief Set dma source address offset after a major loop done Function + * + * @param[in] channel: dma channel id + * @param[in] offest: dma source address offset after a major loop done + * + * @return none. + * + */ +void DMA_SetMajorLoopSrcOffest(DMA_Channel_t channel, int16_t offest) +{ + dmaRegPtr->DMA_CH_CONFIG[channel].DMA_MLAOFF.MLSAOFF = offest; +} + +/** + * @brief Set dma destination address offset after a major loop done Function + * + * @param[in] channel: dma channel id + * @param[in] offest: dma destination address offset after a major loop done + * + * @return none. + * + */ +void DMA_SetMajorLoopDestOffest(DMA_Channel_t channel, int16_t offest) +{ + dmaRegPtr->DMA_CH_CONFIG[channel].DMA_MLAOFF.MLDAOFF = offest; +} + +/** + * @brief Set total number of minor loop in a major loop Function + * + * @param[in] channel: dma channel id + * @param[in] num: number of minor loop in a major loop + * + * @return none. + * + */ +void DMA_SetMinorLoopNum(DMA_Channel_t channel, uint16_t num) +{ + dmaRegPtr->DMA_CH_CONFIG[channel].DMA_ITER.MLITER = (uint16_t)(num & 0x7FFFU); +} + +/** + * @brief Get total number of minor loop in one major loop Function + * + * @param[in] channel: dma channel id + * + * @return number of minor loop in a major loop. + * + */ +uint16_t DMA_GetMinorLoopNum(DMA_Channel_t channel) +{ + return ((uint16_t)dmaRegPtr->DMA_CH_CONFIG[channel].DMA_ITER.MLITER); +} + +/** + * @brief Get number of minor loop that not finished in one major loop Function + * + * @param[in] channel: dma channel id + * + * @return number of rest minor loop in a major loop. + * + */ +uint16_t DMA_GetRestMinorLoopNum(DMA_Channel_t channel) +{ + return ((uint16_t)dmaRegPtr->DMA_CH_CONFIG[channel].DMA_ITER.MLSTA); +} + +/** + * @brief Set dma source transfer size Function + * + * @param[in] channel: dma channel id + * @param[in] size: dma source transfer size + * + * @return none. + * + */ +void DMA_SetSrcTransferSize(DMA_Channel_t channel, DMA_TransferSize_t size) +{ + dmaRegPtr->DMA_CH_CONFIG[channel].DMA_CS.SSIZE = (uint32_t)size; +} + +/** + * @brief Set dma destination transfer size Function + * + * @param[in] channel: dma channel id + * @param[in] size: dma destination transfer size + * + * @return none. + * + */ +void DMA_SetDestTransferSize(DMA_Channel_t channel, DMA_TransferSize_t size) +{ + dmaRegPtr->DMA_CH_CONFIG[channel].DMA_CS.DSIZE = (uint32_t)size; +} + +/** + * @brief Set dma transfer num of bytes in a minor loop Function + * + * @param[in] channel: dma channel id + * @param[in] num: dma transfer num of bytes in a minor loop + * + * @return none. + * + */ +void DMA_SetTransferByteNum(DMA_Channel_t channel, uint32_t num) +{ + dmaRegPtr->DMA_CH_CONFIG[channel].DMA_NUM.NUM = num; +} + +/** + * @brief Disables/enables the DMA request after the transfer complete Function + * + * @param[in] channel: dma channel id + * @param[in] cmd: disable request after done + * - ENABLE: disables the DMA request after the transfer complete + * - DISABLE: enables the DMA request after the transfer complete + * + * @return none. + * + */ +void DMA_SetDisableRequestAfterDone(DMA_Channel_t channel, ControlState_t cmd) +{ + dmaRegPtr->DMA_CH_CONFIG[channel].DMA_CS.REQDIS = (uint32_t)cmd; +} + +/** + * @brief Software trigger one channel dma transfer Function + * + * @param[in] channel: dma channel id + * + * @return none. + * + */ +void DMA_TriggerChannelStart(DMA_Channel_t channel) +{ + dmaRegPtr->DMA_CH_CONFIG[channel].DMA_CS.START = 1U; +} + +/** + * @brief Software trigger all channel dma transfer Function + * + * @param[in] none + * + * @return none. + * + */ +void DMA_TriggerAllChannelStart(void) +{ + dmaRegWPtr->DMA_GCC = DMA_GCC_WPEN1_MASK | DMA_GCC_SACSTART_MASK; +} + +/** + * @brief Get one channel hardware DMA request status Function + * + * @param[in] channel: dma channel id + * + * @return whether a channel hardware DMA request is asserted or not. + * + */ +FlagStatus_t DMA_GetHwRequestStatus(DMA_Channel_t channel) +{ + return ((FlagStatus_t)((uint32_t)(dmaRegWPtr->DMA_CHRS >> (uint32_t)channel & 0x01U))); +} + +/** + * @brief Get dma last error status Function + * + * @param[in] error: error type + * + * @return whether a dma error is asserted or not. + * + */ +FlagStatus_t DMA_GetLastErrorStatus(DMA_ERROR_t error) +{ + return ((FlagStatus_t)((uint32_t)(dmaRegWPtr->DMA_ES >> dmaErrorShift[error] & 0x01U))); +} + +/** + * @brief Get last error channel id Function + * + * @param[in] none + * + * @return channel which occur the last error + * + */ +DMA_Channel_t DMA_GetLastErrorChannel(void) +{ + return ((DMA_Channel_t)dmaRegPtr->DMA_ES.CHEF); +} + +/** + * @brief Get channel int flag Function + * + * @param[in] channel: dma channel id + * @param[in] intType: int type + * - DMA_INT_ERROR: error interrupt + * - DMA_INT_DONE: done interrupt + * - DMA_INT_ALL: all interrupt + * + * @return whether a channel int is asserted or not. + * + */ +IntStatus_t DMA_GetIntStatus(DMA_Channel_t channel, DMA_INT_t intType) +{ + uint32_t retVal; + + switch (intType) + { + case DMA_INT_ERROR: + retVal = dmaRegWPtr->DMA_CES >> (uint32_t)channel & 0x01U; + break; + + case DMA_INT_DONE: + retVal = dmaRegWPtr->DMA_CIS >> (uint32_t)channel & 0x01U; + break; + + case DMA_INT_ALL: + retVal = dmaRegWPtr->DMA_CIS; + retVal |= dmaRegWPtr->DMA_CES; + retVal = retVal >> (uint32_t)channel & 0x01U; + break; + + default: + retVal = 0U; + break; + } + + return ((IntStatus_t)retVal); +} + +/** + * @brief Clear channel int flag Function + * + * @param[in] channel: dma channel id + * @param[in] intType: int type + * - DMA_INT_ERROR: error interrupt + * - DMA_INT_DONE: done interrupt + * - DMA_INT_ALL: all interrupt + * + * @return none. + * + */ +void DMA_ClearIntStatus(DMA_Channel_t channel, DMA_INT_t intType) +{ + dmaRegWPtr->DMA_GCC = dmaGccWpenMask[intType] | + ((((uint32_t)channel << DMA_GCC_CCES_SHIFT) | + ((uint32_t)channel << DMA_GCC_CCIS_SHIFT)) & + dmaGccClearChannelsMask[intType]); +} + +/** + * @brief Clear all channels int flag Function + * + * @param[in] intType: int type + * - DMA_INT_ERROR: error interrupt + * - DMA_INT_DONE: done interrupt + * - DMA_INT_ALL: all interrupt + * + * @return none. + * + */ +void DMA_ClearAllChannelsIntStatus(DMA_INT_t intType) +{ + dmaRegWPtr->DMA_GCC = dmaGccWpenMask[intType] | + dmaGccClearAllChannelsMask[intType]; +} + +/** + * @brief Get channel done flag Function + * + * @param[in] channel: dma channel id + * + * @return whether a channel done flag is asserted or not. + * + */ +FlagStatus_t DMA_GetDoneStatus(DMA_Channel_t channel) +{ + return ((FlagStatus_t)dmaRegPtr->DMA_CH_CONFIG[channel].DMA_CS.DONE); +} + +/** + * @brief Clear channel done flag Function + * + * @param[in] channel: dma channel id + * + * @return none. + * + */ +void DMA_ClearDoneStatus(DMA_Channel_t channel) +{ + dmaRegWPtr->DMA_GCC = DMA_GCC_WPEN0_MASK | (uint32_t)channel; +} + +/** + * @brief Clear all channels done flag Function + * + * @param[in] none + * + * @return none. + * + */ +void DMA_ClearAllChannelsDoneStatus(void) +{ + dmaRegWPtr->DMA_GCC = DMA_GCC_WPEN0_MASK | DMA_GCC_CACDONE_MASK; +} + +/** + * @brief Get channel busy status Function + * + * @param[in] channel: dma channel id + * + * @return whether a channel is busy or not. + * + */ +FlagStatus_t DMA_GetChannelBusyStatus(DMA_Channel_t channel) +{ + return ((FlagStatus_t)dmaRegPtr->DMA_CH_CONFIG[channel].DMA_CS.BUSY); +} + +/** + * @brief Set channel int mask Function + * + * @param[in] channel: dma channel id + * @param[in] intType: int type + * - DMA_INT_ERROR: error interrupt + * - DMA_INT_DONE: done interrupt + * - DMA_INT_ALL: all interrupt + * @param[in] intMask: int mask + * + * @return none. + * + */ +void DMA_IntMask(DMA_Channel_t channel, DMA_INT_t intType, IntMask_t intMask) +{ + uint32_t regValue; + + switch (intType) + { + case DMA_INT_ERROR: + regValue = dmaRegWPtr->DMA_EIE; + regValue &= ~dmaChannelMask[channel]; + regValue |= DMA_MASK_CONVERT_ENABLE(intMask) << (uint32_t)channel; + dmaRegWPtr->DMA_EIE = regValue; + break; + + case DMA_INT_DONE: + dmaRegPtr->DMA_CH_CONFIG[channel].DMA_CS.INTE = DMA_MASK_CONVERT_ENABLE(intMask); + break; + + case DMA_INT_ALL: + regValue = dmaRegWPtr->DMA_EIE; + regValue &= ~dmaChannelMask[channel]; + regValue |= DMA_MASK_CONVERT_ENABLE(intMask) << (uint32_t)channel; + dmaRegWPtr->DMA_EIE = regValue; + dmaRegPtr->DMA_CH_CONFIG[channel].DMA_CS.INTE = DMA_MASK_CONVERT_ENABLE(intMask); + break; + + default: + /*Do nothing*/ + break; + } +} + +/** + * @brief Install callback function + * + * @param[in] channel: dma channel id + * @param[in] intType: select interrrupt type + * - DMA_INT_ERROR: error interrupt + * - DMA_INT_DONE: done interrupt + * @param[in] cbFun: indicate callback function + * + * @return none + * + */ +void DMA_InstallCallBackFunc(DMA_Channel_t channel, DMA_INT_t intType, + isr_cb_t * cbFun) +{ + if(intType < DMA_INT_ALL) + { + dmaIsrCb[channel][intType] = cbFun; + } +} + +/** + * @brief Dma transfer config Function + * + * @param[in] config: Pointer to dma transfer configuration structure. + * + * @return function execution result + * + */ +ResultStatus_t DMA_ConfigTransfer(const DMA_TransferConfig_t * config) +{ + ResultStatus_t retFlag = SUCC; + uint32_t regValue; + DMA_Channel_t channel = config->channel; + /*PRQA S 0303 ++*/ + volatile uint32_t * priRegPtr = (volatile uint32_t *)(DMA_PRIORITY_REG_BASEADDR + + ((uint32_t)channel >> 0x2U) * 4U); + /*PRQA S 0303 --*/ + + if ((DMA_GET_UNSIGNED_REMAINDER(config->srcAddr, config->srcTransferSize) + != 0U) || + (DMA_GET_UNSIGNED_REMAINDER(config->destAddr, config->destTransferSize) + != 0U)) + { + retFlag = ERR; + } + + /*PRQA S 2896 ++*/ + if ((DMA_GET_SIGNED_REMAINDER(config->minorLoopSrcOffset, config->srcTransferSize) + != 0U) || + (DMA_GET_SIGNED_REMAINDER(config->minorLoopDestOffset, config->destTransferSize) + != 0U)) + { + retFlag = ERR; + } + + if ((DMA_GET_SIGNED_REMAINDER(config->majorLoopSrcOffset, config->srcTransferSize) + != 0U) || + (DMA_GET_SIGNED_REMAINDER(config->majorLoopDestOffset, config->destTransferSize) + != 0U)) + { + retFlag = ERR; + } + /*PRQA S 2896 --*/ + + if ((DMA_GET_UNSIGNED_REMAINDER(config->transferByteNum, config->srcTransferSize) + != 0U) || + (DMA_GET_UNSIGNED_REMAINDER(config->transferByteNum, config->destTransferSize) + != 0U)) + { + retFlag = ERR; + } + + if (0U == config->transferByteNum) + { + retFlag = ERR; + } + + if (SUCC == retFlag) + { + /* dma channel config */ + dmaMuxRegPtr->DMA_MUX_CH_CFG[channel].SRC_MUX = (uint32_t)config->source; + dmaMuxRegPtr->DMA_MUX_CH_CFG[channel].ENABLE = 1U; + + regValue = *priRegPtr; + + regValue &= ~(DMA_CHANNEL_PRI_MASK << DMA_CHANNEL_PRI_SHIFT(channel)); + regValue |= (uint32_t)config->channelPriority << DMA_CHANNEL_PRI_SHIFT(channel); + + regValue &= ~(DMA_CHANNEL_PREEMPT_MASK << DMA_CHANNEL_PREEMPT_SHIFT(channel)); + regValue |= (uint32_t)config->channelPreempt << DMA_CHANNEL_PREEMPT_SHIFT(channel); + + *priRegPtr = regValue; + + dmaRegPtr->DMA_CH_CONFIG[channel].DMA_CS.INTE = DMA_MASK_CONVERT_ENABLE(config->doneIntMask); + dmaRegWPtr->DMA_EIE &= ~dmaChannelMask[channel]; + dmaRegWPtr->DMA_EIE |= DMA_MASK_CONVERT_ENABLE(config->errorIntMask) << (uint32_t)channel; + + /* transfer config */ + dmaRegPtr->DMA_CH_CONFIG[channel].DMA_SADDR.SADDR = config->srcAddr; + dmaRegPtr->DMA_CH_CONFIG[channel].DMA_DADDR.DADDR = config->destAddr; + + dmaRegPtr->DMA_CH_CONFIG[channel].DMA_AOFF.SAOFF = config->minorLoopSrcOffset; + dmaRegPtr->DMA_CH_CONFIG[channel].DMA_AOFF.DAOFF = config->minorLoopDestOffset; + + dmaRegPtr->DMA_CH_CONFIG[channel].DMA_CS.SSIZE = (uint32_t)config->srcTransferSize; + dmaRegPtr->DMA_CH_CONFIG[channel].DMA_CS.DSIZE = (uint32_t)config->destTransferSize; + + dmaRegPtr->DMA_CH_CONFIG[channel].DMA_NUM.NUM = config->transferByteNum; + + dmaRegPtr->DMA_CH_CONFIG[channel].DMA_MLAOFF.MLSAOFF = config->majorLoopSrcOffset; + dmaRegPtr->DMA_CH_CONFIG[channel].DMA_MLAOFF.MLDAOFF = config->majorLoopDestOffset; + + dmaRegPtr->DMA_CH_CONFIG[channel].DMA_ITER.MLITER = (uint16_t)(config->minorLoopNum & 0x7FFFU); + + dmaRegPtr->DMA_CH_CONFIG[channel].DMA_CS.REQDIS = (uint32_t)config->disableRequestAfterDoneCmd; + } + + return retFlag; +} + +/** + * @brief DMA error interrupt handle + * + * @param[in] none + * + * @return none + * + */ +static void DMA_ErrorIntHandler(void) +{ + uint32_t status; + uint32_t loop; + + status = dmaRegWPtr->DMA_CES; + status &= dmaRegWPtr->DMA_EIE; + + /* clear all channel error status*/ + /* DMA->DMA_GCC.WORDVAL = DMA_GCC_WPEN2_MASK | DMA_GCC_CACES_MASK; */ + + for (loop = (uint32_t)DMA_CHANNEL0; loop < DMA_CHANNEL_NUM; loop++) + { + if ((status & dmaChannelMask[loop]) != 0U) + { + if(dmaIsrCb[loop][DMA_INT_ERROR] != NULL) + { + dmaIsrCb[loop][DMA_INT_ERROR](); + } + else + { + dmaRegWPtr->DMA_EIE &= ~dmaChannelMask[loop]; + } + + dmaRegWPtr->DMA_GCC = DMA_GCC_WPEN2_MASK | + (loop << DMA_GCC_CCES_SHIFT); + } + } +} + +/** + * @brief DMA done interrupt handle + * + * @param[in] none + * + * @return none + * + */ +static void DMA_DoneIntHandler(uint32_t channelNum) +{ + uint32_t status; + uint32_t loop; + + status = dmaRegWPtr->DMA_CIS; + + /* clear all channel done flag and done interrupt flag*/ + /* + DMA->DMA_GCC.WORDVAL = DMA_GCC_WPEN03_MASK | DMA_GCC_CACIS_MASK | + DMA_GCC_CACDONE_MASK; + */ + + for (loop = (uint32_t)(channelNum - 4U); loop < channelNum; loop++) + { + if ((status & dmaChannelMask[loop]) != 0U) + { + if(dmaIsrCb[loop][DMA_INT_DONE] != NULL) + { + dmaIsrCb[loop][DMA_INT_DONE](); + } + else + { + dmaRegPtr->DMA_CH_CONFIG[loop].DMA_CS.INTE = 0U; + } + + dmaRegWPtr->DMA_GCC = DMA_GCC_WPEN03_MASK | + (loop << DMA_GCC_CCIS_SHIFT) | loop ; + } + } +} + +/** + * @brief DMA channel 0-3 interrupt function + * + * @param none + * + * @return none + * + */ +void DMA0TO3_DriverIRQHandler(void) +{ + DMA_DoneIntHandler(DMA0TO3_NUM); +} + +/** + * @brief DMA channel 4-7 interrupt function + * + * @param none + * + * @return none + * + */ +void DMA4TO7_DriverIRQHandler(void) +{ + DMA_DoneIntHandler(DMA4TO7_NUM); +} + +/** + * @brief DMA channel 8-11 interrupt function + * + * @param none + * + * @return none + * + */ +void DMA8TO11_DriverIRQHandler(void) +{ + DMA_DoneIntHandler(DMA8TO11_NUM); +} + +/** + * @brief DMA channel 12-15 interrupt function + * + * @param none + * + * @return none + * + */ +void DMA12TO15_DriverIRQHandler(void) +{ + DMA_DoneIntHandler(DMA12TO15_NUM); +} + +/** + * @brief DMA error interrupt function + * + * @param none + * + * @return none + * + */ +void DMAERR_DriverIRQHandler(void) +{ + DMA_ErrorIntHandler(); +} + +/** @} end of group DMA_Public_Functions */ + +/** @} end of group DMA driver modules */ + +/** @} end of group Z20K11XM_Peripheral_Driver */ + diff --git a/StdDriver/Src/Z20K11xM_drv.c b/StdDriver/Src/Z20K11xM_drv.c new file mode 100644 index 0000000..2e1e5c8 --- /dev/null +++ b/StdDriver/Src/Z20K11xM_drv.c @@ -0,0 +1,117 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_drv.c + * @brief : Common driver file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ + +#include "Z20K11xM_drv.h" + +/** @addtogroup Z20K11X_Peripheral_Driver + * @{ + */ + +/** @defgroup DRV_COMMON + * @brief Z20K11X driver common functions + * @{ + */ + +/** @defgroup DRV_Private_Type + * @{ + */ + + +/** @} end of group DRV_Private_Type*/ + +/** @defgroup DRV_Private_Defines + * @{ + */ + + +/** @} end of group DRV_Private_Defines */ + + +/** @defgroup DRV_Private_Variables + * @{ + */ + + + +/** @} end of group DRV_Private_Variables */ + +/** @defgroup DRV_Global_Variables + * @{ + */ + + + +/** @} end of group DRV_Global_Variables */ + + +/** @defgroup DRV_Private_FunctionDeclaration + * @{ + */ + + +/** @} end of group DRV_Private_FunctionDeclaration */ + +/** @defgroup DRV_Private_Functions + * @{ + */ + + +/** @} end of group DRV_Private_Functions */ + +/** @defgroup DRV_Public_Functions + * @{ + */ + + + +#ifdef DEBUG +/** +* @brief Reports the name of the source file and the source line number +* where the CHECK_PARAM error has occurred. + +* @param[in] file: Pointer to the source file name +* @param[in] line: assert_param error line source number + +* @return none + */ +void check_failed(uint8_t *file, uint32_t line) +{ + /* User can add his own implementation to report the file name and line number, + ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /*PRQA S 2053*/ + + /* Infinite loop */ + while(1); +} +#endif /* DEBUG */ + +/** + * @brief Delay for some cycles + * + * @param[in] delayCount: the cycles to delay + * + * @return None + * + */ +void Drv_Delay(uint32_t delayCount) /*PRQA S 3408*/ +{ + volatile uint32_t cnt = 0U; + + while(cnt++ < delayCount) + { + } +} + +/** @} end of group DRV_Public_Functions */ + +/** @} end of group DRV_COMMON */ + +/** @} end of group Z20K11X_Peripheral_Driver */ diff --git a/StdDriver/Src/Z20K11xM_ewdt.c b/StdDriver/Src/Z20K11xM_ewdt.c new file mode 100644 index 0000000..e8a4d3b --- /dev/null +++ b/StdDriver/Src/Z20K11xM_ewdt.c @@ -0,0 +1,377 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_ewdt.c + * @brief : EWDT module driver file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ + +#include "Z20K11xM_ewdt.h" + +/** @addtogroup Z20K11X_Peripheral_Driver + * @{ + */ + +/** @defgroup EWDT + * @brief EWDT driver modules + * @{ + */ + +/** @defgroup EWDT_Private_Defines + * @{ + */ +#define EWDT_CS_INTF_MASK (0x01000000U) +#define EWDT_CS_INPP_MASK (0x00000040U) +#define EWDT_CS_INPE_MASK (0x00000020U) +#define EWDT_CS_INPUT_MASK (0x00000060U) +#define EWDT_CS_INTE_MASK (0x00000010U) +#define EWDT_CS_WAITE_MASK (0x00000004U) +#define EWDT_CS_DEBUGE_MASK (0x00000002U) +#define EWDT_CS_EWDTE_MASK (0x00000001U) + +#define EWDT_CS_INTF_SHIFT (24U) +#define EWDT_CS_INPP_SHIFT (6U) +#define EWDT_CS_INPE_SHIFT (5U) +#define EWDT_CS_INTE_SHIFT (4U) +#define EWDT_CS_WAITE_SHIFT (2U) +#define EWDT_CS_DEBUGE_SHIFT (1U) + +#define EWDT_CS_INPUT_STATUS_SET(x) \ + (((uint32_t)(((uint32_t)(x)) << EWDT_CS_INPE_SHIFT)) & EWDT_CS_INPUT_MASK) + +#define EWDT_CS_INPP_SET(x) \ + (((uint32_t)(((uint32_t)(x)) << EWDT_CS_INPP_SHIFT)) & EWDT_CS_INPP_MASK) + +#define EWDT_CS_INPE_SET(x) \ + (((uint32_t)(((uint32_t)(x)) << EWDT_CS_INPE_SHIFT)) & EWDT_CS_INPE_MASK) + +#define EWDT_CS_INTE_SET(x) \ + (((uint32_t)(((uint32_t)(x)) << EWDT_CS_INTE_SHIFT)) & EWDT_CS_INTE_MASK) + +#define EWDT_CS_WAITE_SET(x) \ + (((uint32_t)(((uint32_t)(x)) << EWDT_CS_WAITE_SHIFT)) & EWDT_CS_WAITE_MASK) + +#define EWDT_CS_DEBUGE_SET(x) \ + (((uint32_t)(((uint32_t)(x)) << EWDT_CS_DEBUGE_SHIFT)) & \ + EWDT_CS_DEBUGE_MASK) + +#define EWDT_CS_EWDTE_SET(x) (((uint32_t)((uint32_t)(x))) & EWDT_CS_EWDTE_MASK) + +#define EWDT_REFRESH_VALUE1 (0xB2C5D3A8U) +#define EWDT_REFRESH_VALUE2 (0x1D7E4C5FU) + +#define EWDT_MASK_CONVERT_ENABLE(x) \ + ((uint32_t)((((uint32_t)(x) + 1U) & 0x1U) << EWDT_CS_INTE_SHIFT)) + +START_FUNCTION_DECLARATION_RAMSECTION +static void EWDT_REFRESH_COUNT(void) +END_FUNCTION_DECLARATION_RAMSECTION /* PRQA S 0605*/ + +/** @} end of group EWDT_Private_Defines */ + +/** @defgroup EWDT_Private_Type + * @{ + */ + +/** @} end of group EWDT_Private_Type*/ + +/** @defgroup EWDT_Private_Variables + * @{ + */ + +/** + * @brief EWDT Register address array + */ +/*PRQA S 0303 ++*/ +static ewdt_reg_t *const ewdtRegPtr = (ewdt_reg_t *)EWDT_BASE_ADDR; +static ewdt_reg_w_t *const ewdtRegWPtr = (ewdt_reg_w_t *)EWDT_BASE_ADDR; +/*PRQA S 0303 --*/ +/*! @brief ewdt int status mask array */ +static const uint32_t ewdtIntMask[] = {EWDT_CS_INTE_MASK, EWDT_CS_INTE_MASK}; + +static const uint32_t ewdtIntFlagMask[] = {EWDT_CS_INTF_MASK, + EWDT_CS_INTF_MASK}; + +/*! @brief EWDT ISR CallBack VECTOR structure */ +static isr_cb_t *ewdtIsrCb[EWDT_INT_ALL] = {NULL}; + +/** @} end of group EWDT_Private_Variables */ + +/** @defgroup EWDT_Global_Variables + * @{ + */ + +/** @} end of group EWDT_Global_Variables */ + +/** @defgroup EWDT_Private_FunctionDeclaration + * @{ + */ +void EWDT_DriverIRQHandler(void); +/** @} end of group EWDT_Private_FunctionDeclaration */ + +/** @defgroup EWDT_Private_Functions + * @{ + */ + +/** + * @brief ewdt counter register write REFRESH sequence Function + * + * @param[in] none + * + * @note If user has no need to enable irq, in next step user should + * disable_irq after calling this function. + * + * @return none + * + */ +static void EWDT_REFRESH_COUNT(void) +{ + __disable_irq(); + __asm("PUSH {R0, R1, R2}\n" + "LDR R0, =0x40061014\n" + "LDR R1, =0xB2C5D3A8\n" + "LDR R2, =0x1D7E4C5F\n" + + "STR R1, [R0]\n" + "STR R2, [R0]\n" + "POP {R0, R1, R2}\n"); + __enable_irq(); +} + +/** @} end of group EWDT_Private_Functions */ + +/** @defgroup EWDT_Public_Functions + * @{ + */ + +/** + * @brief ewdt Initializes Function + * + * @param[in] ptEWDTInitConfig: Pointer to a EWDT configuration structure. + * + * @return Initializes operate flag + * + */ +ResultStatus_t EWDT_Init(const EWDT_Config_t *ptEWDTInitConfig) +{ + ewdt_reg_w_t *EWDTxw = (ewdt_reg_w_t *)(ewdtRegWPtr); + uint32_t ewdt_cs = 0U; + + /* Construct CS register new value */ + ewdt_cs = EWDT_CS_INPUT_STATUS_SET(ptEWDTInitConfig->input); + ewdt_cs |= EWDT_MASK_CONVERT_ENABLE(ptEWDTInitConfig->intMask); + ewdt_cs |= EWDT_CS_WAITE_SET(ptEWDTInitConfig->wait); + ewdt_cs |= EWDT_CS_DEBUGE_SET(ptEWDTInitConfig->debug); + ewdt_cs |= EWDT_CS_EWDTE_SET(ptEWDTInitConfig->enable); + + /* config timeout value and window value */ + EWDTxw->EWDT_COMPH = ptEWDTInitConfig->cmpHighValue; + EWDTxw->EWDT_COMPL = ptEWDTInitConfig->cmpLowValue; + + EWDTxw->EWDT_CS = ewdt_cs; + + return SUCC; +} + +/** + * @brief refresh ewdt count Function + * + * @param[in] none + * + * @note If user has no need to enable irq, in next step user should + * disable_irq after calling this function. + * + * @return none. + * + */ +void EWDT_Refresh(void) +{ + EWDT_REFRESH_COUNT(); +} + +/** + * @brief get ewdt input pin assertion config Function + * + * @param[in] none + * + * @return input pin assertion config status. + * + */ +EWDT_InputStatus_t EWDT_GetInputAssertConfig(void) +{ + ewdt_reg_w_t *EWDTxw = (ewdt_reg_w_t *)(ewdtRegWPtr); + return (( + EWDT_InputStatus_t)((uint32_t)((EWDTxw->EWDT_CS & EWDT_CS_INPUT_MASK) >> + EWDT_CS_INPE_SHIFT))); +} + +/** + * @brief get ewdt compare low reg value Function + * + * @param[in] none + * + * @return compare low reg value. + * + */ +uint32_t EWDT_GetCompareLowValue(void) +{ + ewdt_reg_t *EWDTx = (ewdt_reg_t *)(ewdtRegPtr); + return ((uint32_t)EWDTx->EWDT_COMPL.COMPL); +} + +/** + * @brief get ewdt compare high reg value Function + * + * @param[in] none + * + * @return compare high reg value. + * + */ +uint32_t EWDT_GetCompareHighValue(void) +{ + ewdt_reg_t *EWDTx = (ewdt_reg_t *)(ewdtRegPtr); + return ((uint32_t)EWDTx->EWDT_COMPH.COMPH); +} + +/** + * @brief get ewdt counter current value Function + * + * @param[in] none + * + * @return current counter count value. + * + */ +uint32_t EWDT_GetCounter(void) +{ + ewdt_reg_t *EWDTx = (ewdt_reg_t *)(ewdtRegPtr); + return ((uint32_t)EWDTx->EWDT_CNT.CNT); +} + +/** + * @brief get flag indcates ewdt is enable/disable Function + * + * @param[in] none + * + * @return ewdt enable status. + * + */ +FlagStatus_t EWDT_GetEnableStatus(void) +{ + ewdt_reg_t *EWDTx = (ewdt_reg_t *)(ewdtRegPtr); + return ((FlagStatus_t)EWDTx->EWDT_CS.EWDTE); +} + +/** + * @brief get interrupt mask Function + * + * @param[in] intType: int type + * - EWDT_INT_OUTPUTASSERT: ewdt out assert int + * - EWDT_INT_ALL: all int type + * + * @return interrupt mask. + * + */ +IntMask_t EWDT_GetIntMaskStatus(EWDT_INT_t intType) +{ + ewdt_reg_w_t *EWDTxw = (ewdt_reg_w_t *)(ewdtRegWPtr); + return (((EWDTxw->EWDT_CS & ewdtIntMask[intType]) != 0U) ? UNMASK : MASK); +} + +/** + * @brief clear ewdt interrupt flag Function + * + * @param[in] intType: int type + * - EWDT_INT_OUTPUTASSERT: ewdt out assert int + * - EWDT_INT_ALL: all int type + * + * @return none. + * + */ +void EWDT_ClearIntStatus(EWDT_INT_t intType) +{ + ewdt_reg_t *EWDTx = (ewdt_reg_t *)(ewdtRegPtr); + EWDTx->EWDT_CS.INTF = 1U; +} + +/** + * @brief get ewdt int flag Function + * + * @param[in] intType: int type + * - EWDT_INT_OUTPUTASSERT: ewdt out assert int + * - EWDT_INT_ALL: all int type + * + * @return whether a int is asserted or not. + * + */ +IntStatus_t EWDT_GetIntStatus(EWDT_INT_t intType) +{ + ewdt_reg_w_t *EWDTxw = (ewdt_reg_w_t *)(ewdtRegWPtr); + return ( + (IntStatus_t)((uint32_t)((EWDTxw->EWDT_CS & ewdtIntFlagMask[intType]) >> + EWDT_CS_INTF_SHIFT))); +} + +/** + * @brief Install callback function + * + * @param[in] intType: select interrrupt type + * - EWDT_INT_OUTPUTASSERT: ewdt out assert int + * - EWDT_INT_ALL: all int type + * @param[in] cbFun: indicate callback function + * + * @return none + * + */ +void EWDT_InstallCallBackFunc(EWDT_INT_t intType, isr_cb_t *cbFun) +{ + if (intType < EWDT_INT_ALL) + { + ewdtIsrCb[intType] = cbFun; + } +} + +/** + * @brief EWDT interrupt handle + * + * @param[in] none + * + * @return none + * + */ +static void EWDT_IntHandler(void) +{ + ewdt_reg_t *EWDTx = (ewdt_reg_t *)(ewdtRegPtr); + ewdt_reg_w_t *EWDTxw = (ewdt_reg_w_t *)(ewdtRegWPtr); + if ((EWDTxw->EWDT_CS & ewdtIntFlagMask[EWDT_INT_OUTPUTASSERT]) != 0U) + { + EWDTx->EWDT_CS.INTF = 1U; + + if (ewdtIsrCb[EWDT_INT_OUTPUTASSERT] != NULL) + { + ewdtIsrCb[EWDT_INT_OUTPUTASSERT](); + } + } +} + +/** + * @brief EWDT interrupt function in vector + * + * @param none + * + * @return none + * + */ +void EWDT_DriverIRQHandler(void) +{ + EWDT_IntHandler(); +} + +/** @} end of group EWDT_Public_Functions */ + +/** @} end of group EWDT driver modules */ + +/** @} end of group Z20K11X_Peripheral_Driver */ diff --git a/StdDriver/Src/Z20K11xM_flash.c b/StdDriver/Src/Z20K11xM_flash.c new file mode 100644 index 0000000..182a66a --- /dev/null +++ b/StdDriver/Src/Z20K11xM_flash.c @@ -0,0 +1,1216 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_flash.c + * @brief : FLASH module driver file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ + +#include "Z20K11xM_flash.h" + +/** @addtogroup Z20K11X_Peripheral_Driver + * @{ + */ + +/** @defgroup FLASH + * @brief FLASH driver modules + * @{ + */ + +/** @defgroup FLASH_Private_Type + * @{ + */ +/** + * @brief FLASH command type definition + */ +typedef enum +{ + FLASH_CMD_RD1ALL = 0U, /*!< Verify that all flash and IFR space is + erased*/ + FLASH_CMD_RD1BLK = 1U, /*!< Verify that a flash block is erased */ + FLASH_CMD_RD1SCR = 2U, /*!< Verify that a flash sector is erased */ + FLASH_CMD_RD1PG = 3U, /*!< Verify that a flash page is erased */ + FLASH_CMD_RD1PHR = 4U, /*!< Verify that a flash phrase is erased */ + FLASH_CMD_RDMISR = 5U, /*!< Generate MISR signature for range of flash + pages */ + FLASH_CMD_RD1ISCR = 0x12U, /*!< Verify that an IFR sector is erased */ + FLASH_CMD_RD1IPG = 0x13U, /*!< Verify that an IFR page is erased */ + FLASH_CMD_RD1IPHR = 0x14U, /*!< Verify that an IFR phrase is erased */ + FLASH_CMD_RDIMISR = 0x15U, /*!< Generate MISR signature for range of IFR + pages */ + FLASH_CMD_PGMPHR = 0x24U, /*!< Program data to a flash or IFR phrase */ + FLASH_CMD_ERSALL = 0x40U, /*!< Erase all flash and IFR space */ + FLASH_CMD_ERSSCR = 0x42U /*!< Erase a flash sector */ +}FLASH_Cmd_t; +/** @} end of group FLASH_Private_Type*/ + +/** @defgroup FLASH_Private_Defines + * @{ + */ + +#define FLASH_SECURE_ADDR 0x02000000U +#define FLASH_PHRASE_SIZE 16U + +#define FLASH_CMD_ERR_MASK (FLASH_STATUS_CMDABT_MASK \ + | FLASH_STATUS_ACCERR_MASK \ + | FLASH_STATUS_FAIL_MASK) + +#define FLASH_INT_CCIF_MASK 0x00000080U +#define FLASH_INT_DFDIF_MASK 0x00010000U +#define FLASH_INT_SFDIF_MASK 0x00020000U +#define FLASH_INT_ALL_MASK (FLASH_INT_CCIF_MASK | FLASH_INT_DFDIF_MASK\ + | FLASH_INT_SFDIF_MASK) +#define FLASH_ECC_MASK (FLASH_INT_DFDIF_MASK | FLASH_INT_SFDIF_MASK) + +/** @} end of group FLASH_Private_Defines */ + +/** @defgroup FLASH_Private_Variables + * @{ + */ +/*PRQA S 0303 ++*/ +static flash_reg_t *const flsRegPtr = (flash_reg_t *) FLASHC_BASE_ADDR; +static flash_reg_w_t *const flsRegWPtr = (flash_reg_w_t *) FLASHC_BASE_ADDR; +/*PRQA S 0303 --*/ + +static isr_cb_t * flashIsrCbFunc[FLASH_INT_ALL] = {NULL, NULL}; + +static const uint32_t flashInterruptMaskTable[] = +{ + FLASH_INT_CCIF_MASK, /* FLASH_INT_CCIF */ + FLASH_INT_DFDIF_MASK, /* FLASH_INT_DFDIF */ + FLASH_INT_ALL_MASK /* FLASH_INT_ALL */ +}; + +/** @} end of group FLASH_Private_Variables */ + +/** @defgroup FLASH_Global_Variables + * @{ + */ + +/** @} end of group FLASH_Global_Variables */ + +/** @defgroup FLASH_Private_FunctionDeclaration + * @{ + */ + +void FLASH_DriverIRQHandler(void); + +#if (FLASH_CMD_FUNC_IN_RAM == 1) +/*PRQA S 0605 ++*/ +START_FUNCTION_DECLARATION_RAMSECTION +static ResultStatus_t FLASH_WaitCmdComplete(flash_cb_t callBack) +END_FUNCTION_DECLARATION_RAMSECTION + +START_FUNCTION_DECLARATION_RAMSECTION +static ResultStatus_t FLASH_WaitEraseAllComplete(flash_cb_t callBack) +END_FUNCTION_DECLARATION_RAMSECTION + +START_FUNCTION_DECLARATION_RAMSECTION +static ResultStatus_t FLASH_ExecuteCommand(FLASH_Cmd_t cmd, flash_cb_t callBack) +END_FUNCTION_DECLARATION_RAMSECTION + +START_FUNCTION_DECLARATION_RAMSECTION +static ResultStatus_t FLASH_ExecuteCommandInt(FLASH_Cmd_t cmd) +END_FUNCTION_DECLARATION_RAMSECTION +/*PRQA S 0605 --*/ +#else +static ResultStatus_t FLASH_WaitCmdComplete(flash_cb_t callBack); +static ResultStatus_t FLASH_WaitEraseAllComplete(flash_cb_t callBack); +static ResultStatus_t FLASH_ExecuteCommand(FLASH_Cmd_t cmd, flash_cb_t callBack); +static ResultStatus_t FLASH_ExecuteCommandInt(FLASH_Cmd_t cmd); +#endif + + +/** @} end of group FLASH_Private_FunctionDeclaration */ + +/** @defgroup FLASH_Private_Functions + * @{ + */ + +static ResultStatus_t FLASH_WaitCmdComplete(flash_cb_t callBack) +{ + ResultStatus_t ret = ERR; + volatile uint32_t localCnt = 0U; + /*PRQA S 0303 ++*/ + flash_reg_t *pFlashReg = (flash_reg_t *) FLASHC_BASE_ADDR; + /*PRQA S 0303 --*/ + + while(localCnt < FLASH_TIMEOUT_WAIT_CNT) + { + if(pFlashReg->FLASH_FSTAT.CCIF != 0U) + { + ret = SUCC; + break; + } + else + { + localCnt++; + + if(callBack != NULL) + { + DISABLE_CHECK_RAMSECTION_FUNCTION_CALL + callBack(); + ENABLE_CHECK_RAMSECTION_FUNCTION_CALL + } + } + } + + return ret; +} + +static ResultStatus_t FLASH_WaitEraseAllComplete(flash_cb_t callBack) +{ + ResultStatus_t ret = ERR; + volatile uint32_t localCnt = 0U; + /*PRQA S 0303 ++*/ + flash_reg_t *pFlashReg = (flash_reg_t *) FLASHC_BASE_ADDR; + /*PRQA S 0303 --*/ + + while(localCnt < FLASH_TIMEOUT_WAIT_CNT_ERASE_ALL) + { + if(pFlashReg->FLASH_FSTAT.CCIF != 0U) + { + ret = SUCC; + break; + } + else + { + localCnt++; + + if(callBack != NULL) + { + DISABLE_CHECK_RAMSECTION_FUNCTION_CALL + callBack(); + ENABLE_CHECK_RAMSECTION_FUNCTION_CALL + } + } + } + + return ret; +} + +static ResultStatus_t FLASH_ExecuteCommand(FLASH_Cmd_t cmd, flash_cb_t callBack) +{ + ResultStatus_t stat = SUCC; + /*PRQA S 0303 ++*/ + flash_reg_t *pFlashReg = (flash_reg_t *) FLASHC_BASE_ADDR; + flash_reg_w_t *pFlashRegW = (flash_reg_w_t *) FLASHC_BASE_ADDR; + /*PRQA S 0303 --*/ + + if(0U == pFlashReg->FLASH_FSTAT.CCIF) + { + stat = BUSY; + } + else + { + pFlashReg->FLASH_FCMD.CMDCODE = (uint32_t)cmd; + + pFlashReg->FLASH_FCTRL.ABTREQ = 0U; + + /* clear ACCERR, PVIOL, CMDABT, CWSABT if any is set */ + pFlashRegW->FLASH_FSTAT = 0x00000074U; + + /* clear CCIF to start cmd */ + pFlashRegW->FLASH_FSTAT = 0x00000080U; + + if(FLASH_CMD_ERSALL == cmd) + { + stat = FLASH_WaitEraseAllComplete(callBack); + } + else + { + stat = FLASH_WaitCmdComplete(callBack); + } + + if((pFlashRegW->FLASH_FSTAT & FLASH_CMD_ERR_MASK) != 0U) + { + stat = ERR; + } + } + + return stat; +} + +static ResultStatus_t FLASH_ExecuteCommandInt(FLASH_Cmd_t cmd) +{ + ResultStatus_t stat; + /*PRQA S 0303 ++*/ + flash_reg_t *pFlashReg = (flash_reg_t *) FLASHC_BASE_ADDR; + flash_reg_w_t *pFlashRegW = (flash_reg_w_t *) FLASHC_BASE_ADDR; + /*PRQA S 0303 --*/ + + if(0U == pFlashReg->FLASH_FSTAT.CCIF) + { + stat = BUSY; + } + else + { + pFlashReg->FLASH_FCMD.CMDCODE = (uint32_t)cmd; + + pFlashReg->FLASH_FCTRL.ABTREQ = 0; + + /* clear ACCERR, PVIOL, CMDABT, CWSABT if any is set */ + pFlashRegW->FLASH_FSTAT = 0x00000074; + + /* clear CCIF to start cmd */ + pFlashRegW->FLASH_FSTAT = 0x00000080; + + pFlashReg->FLASH_FCNFG.CCIE = 1; + stat = SUCC; + } + + return stat; +} + +/** @} end of group FLASH_Private_Functions */ + +/** @defgroup FLASH_Public_Functions + * @{ + */ + + +/** + * @brief Verify all flash and IFR space are in the erased state + * + * @param[in] config: config the action when the command is executing + * + * @note if config->callBack is not NULL, it has to point to a funtion + * that is not in flash memory + * + * @return + * - SUCC -- successful + * - ERR -- some error + * - BUSY -- flash is executing last command. It can not execute this + * new command now. + * + */ +ResultStatus_t FLASH_VerifyAll(const FLASH_CmdConfig_t *config) +{ + ResultStatus_t stat; + + if(0U == flsRegPtr->FLASH_FSTAT.CCIF) + { + stat = BUSY; + } + else + { + if(FLASH_CMD_ACT_WAIT == config->act) + { + stat = FLASH_ExecuteCommand(FLASH_CMD_RD1ALL, config->callBack); + } + else + { + stat = FLASH_ExecuteCommandInt(FLASH_CMD_RD1ALL); + } + } + + return stat; +} + + +/** + * @brief Verify that a flash block is erased + * + * @param[in] addr: block start address + * @param[in] config: config the action when the command is executing + * + * @note if config->callBack is not NULL, it has to point to a funtion + * that is not in the flash memory that flash commands is executing + * in. + * + * @return - SUCC -- successful + * - ERR -- some error + * - BUSY -- flash is executing last command. It can not execute this + * new command now. + * + */ +ResultStatus_t FLASH_VerifyBlock(uint32_t addr, + const FLASH_CmdConfig_t *config) +{ + ResultStatus_t stat; + + if(0U == flsRegPtr->FLASH_FSTAT.CCIF) + { + stat = BUSY; + } + else + { + flsRegWPtr->FLASH_FADDR = addr; + + if(FLASH_CMD_ACT_WAIT == config->act) + { + stat = FLASH_ExecuteCommand(FLASH_CMD_RD1BLK, config->callBack); + } + else + { + stat = FLASH_ExecuteCommandInt(FLASH_CMD_RD1BLK); + } + } + + return stat; +} + +/** + * @brief Verify that a flash sector is erased + * + * @param[in] addr: sector start address + * @param[in] config: config the action when the command is executing + * + * @note if config->callBack is not NULL, it has to point to a funtion + * that is not in the flash memory that flash commands is executing + * in. + * + * @return - SUCC -- successful + * - ERR -- some error + * - BUSY -- flash is executing last command. It can not execute this + * new command now. + * + */ +ResultStatus_t FLASH_VerifySector(uint32_t addr, + const FLASH_CmdConfig_t *config) +{ + ResultStatus_t stat; + + if(0U == flsRegPtr->FLASH_FSTAT.CCIF) + { + stat = BUSY; + } + else + { + flsRegWPtr->FLASH_FADDR = addr; + + if(FLASH_CMD_ACT_WAIT == config->act) + { + stat = FLASH_ExecuteCommand(FLASH_CMD_RD1SCR, config->callBack); + } + else + { + stat = FLASH_ExecuteCommandInt(FLASH_CMD_RD1SCR); + } + } + + return stat; +} + +/** + * @brief Verify that a flash page is erased + * + * @param[in] addr: page start address + * @param[in] config: config the action when the command is executing + * + * @note if config->callBack is not NULL, it has to point to a funtion + * that is not in the flash memory that flash commands is executing + * in. + * + * @return - SUCC -- successful + * - ERR -- some error + * - BUSY -- flash is executing last command. It can not execute this + * new command now. + * + */ +ResultStatus_t FLASH_VerifyPage(uint32_t addr, + const FLASH_CmdConfig_t *config) +{ + ResultStatus_t stat; + + if(0U == flsRegPtr->FLASH_FSTAT.CCIF) + { + stat = BUSY; + } + else + { + flsRegWPtr->FLASH_FADDR = addr; + + if(FLASH_CMD_ACT_WAIT == config->act) + { + stat = FLASH_ExecuteCommand(FLASH_CMD_RD1PG, config->callBack); + } + else + { + stat = FLASH_ExecuteCommandInt(FLASH_CMD_RD1PG); + } + } + + return stat; +} + +/** + * @brief Verify that a flash phrase is erased + * + * @param[in] addr: phrase start address + * @param[in] config: config the action when the command is executing + * + * @note if config->callBack is not NULL, it has to point to a funtion + * that is not in the flash memory that flash commands is executing + * in. + * + * @return - SUCC -- successful + * - ERR -- some error + * - BUSY -- flash is executing last command. It can not execute this + * new command now. + * + */ +ResultStatus_t FLASH_VerifyPhrase(uint32_t addr, + const FLASH_CmdConfig_t *config) +{ + ResultStatus_t stat; + + if(0U == flsRegPtr->FLASH_FSTAT.CCIF) + { + stat = BUSY; + } + else + { + flsRegWPtr->FLASH_FADDR = addr; + + if(FLASH_CMD_ACT_WAIT == config->act) + { + stat = FLASH_ExecuteCommand(FLASH_CMD_RD1PHR, config->callBack); + } + else + { + stat = FLASH_ExecuteCommandInt(FLASH_CMD_RD1PHR); + } + } + + return stat; +} + +/** + * @brief Generate MISR signature for flash pages + * + * @param[in] startAddr: page start address + * @param[in] endAddr: Ending phrase address. It must be the last phrase in a page. + * @param[in] seed: the pointer that points to the 4-word seed + * @param[in] signature: the pointer that points the memory that the 128-bit + * singnature result that will be stored through this function. + * it is only valid when config->act == FLASH_CMD_ACT_WAIT. + * If config->act == FLASH_CMD_ACT_WAIT, the result is not stored + * @param[in] config: config the action when the command is executing. If + * FLASH_CMD_ACT_WAIT is selected, the result is stored in + * signature[4]. If FLASH_CMD_ACT_INT is selected, the result + * is not selected. user can get the result in the interrupt + * call back function + * + * @note if config->callBack is not NULL, it has to point to a funtion + * that is not in the flash memory that flash commands is executing + * in. + * + * @return - SUCC -- successful + * - ERR -- some error + * - BUSY -- flash is executing last command. It can not execute this + * new command now. + * + */ +ResultStatus_t FLASH_PagesMircSignature(uint32_t startAddr, uint32_t endAddr, + uint32_t seed[4], uint32_t signature[4], + const FLASH_CmdConfig_t *config) +{ + ResultStatus_t stat; + + if(0U == flsRegPtr->FLASH_FSTAT.CCIF) + { + stat = BUSY; + } + else + { + flsRegWPtr->FLASH_FADDR = startAddr; + flsRegWPtr->FLASH_FADDR_END = endAddr; + + flsRegWPtr->FLASH_FDATA0 = seed[0]; + flsRegWPtr->FLASH_FDATA1 = seed[1]; + flsRegWPtr->FLASH_FDATA2 = seed[2]; + flsRegWPtr->FLASH_FDATA3 = seed[3]; + + if(FLASH_CMD_ACT_WAIT == config->act) + { + stat = FLASH_ExecuteCommand(FLASH_CMD_RDMISR, config->callBack); + if( SUCC == stat) + { + signature[0] = flsRegWPtr->FLASH_FDATA0; + signature[1] = flsRegWPtr->FLASH_FDATA1; + signature[2] = flsRegWPtr->FLASH_FDATA2; + signature[3] = flsRegWPtr->FLASH_FDATA3; + } + } + else + { + stat = FLASH_ExecuteCommandInt(FLASH_CMD_RDMISR); + } + } + + return stat; +} + +/** + * @brief Verify that a flash IFR sector is erased + * + * @param[in] addr: sector start address. + * @param[in] config: config the action when the command is executing + * + * @note if config->callBack is not NULL, it has to point to a funtion + * that is not in the flash memory that flash commands is executing + * in. + * + * @return - SUCC -- successful + * - ERR -- some error + * - BUSY -- flash is executing last command. It can not execute this + * new command now. + * + */ +ResultStatus_t FLASH_VerifyIfrSector(uint32_t addr, + const FLASH_CmdConfig_t *config) +{ + ResultStatus_t stat; + + if(0U == flsRegPtr->FLASH_FSTAT.CCIF) + { + stat = BUSY; + } + else + { + flsRegWPtr->FLASH_FADDR = addr; + + if(FLASH_CMD_ACT_WAIT == config->act) + { + stat = FLASH_ExecuteCommand(FLASH_CMD_RD1ISCR, config->callBack); + } + else + { + stat = FLASH_ExecuteCommandInt(FLASH_CMD_RD1ISCR); + } + } + + return stat; +} + +/** + * @brief Verify that a flash IFR page is erased + * + * @param[in] addr: IFR page start address + * @param[in] config: config the action when the command is executing + * + * @note if config->callBack is not NULL, it has to point to a funtion + * that is not in the flash memory that flash commands is executing + * in. + * + * @return - SUCC -- successful + * - ERR -- some error + * - BUSY -- flash is executing last command. It can not execute this + * new command now. + * + */ +ResultStatus_t FLASH_VerifyIfrPage(uint32_t addr, + const FLASH_CmdConfig_t *config) +{ + ResultStatus_t stat; + + if(0U == flsRegPtr->FLASH_FSTAT.CCIF) + { + stat = BUSY; + } + else + { + flsRegWPtr->FLASH_FADDR = addr; + + if(FLASH_CMD_ACT_WAIT == config->act) + { + stat = FLASH_ExecuteCommand(FLASH_CMD_RD1IPG, config->callBack); + } + else + { + stat = FLASH_ExecuteCommandInt(FLASH_CMD_RD1IPG); + } + } + + return stat; +} + +/** + * @brief Verify that a flash IFR phrase is erased + * + * @param[in] addr: IFR phrase start address + * @param[in] config: config the action when the command is executing + * + * @note if config->callBack is not NULL, it has to point to a funtion + * that is not in the flash memory that flash commands is executing + * in. + * + * @return - SUCC -- successful + * - ERR -- some error + * - BUSY -- flash is executing last command. It can not execute this + * new command now. + * + */ +ResultStatus_t FLASH_VerifyIfrPhrase(uint32_t addr, + const FLASH_CmdConfig_t *config) +{ + ResultStatus_t stat; + + if(0U == flsRegPtr->FLASH_FSTAT.CCIF) + { + stat = BUSY; + } + else + { + flsRegWPtr->FLASH_FADDR = addr; + + if(FLASH_CMD_ACT_WAIT == config->act) + { + stat = FLASH_ExecuteCommand(FLASH_CMD_RD1IPHR, config->callBack); + } + else + { + stat = FLASH_ExecuteCommandInt(FLASH_CMD_RD1IPHR); + } + } + + return stat; +} + + +/** + * @brief Generate MISR signature for flash IFR pages + * + * @param[in] startAddr: page start address + * @param[in] endAddr: Ending phrase address. It must be the last phrase in a page. + * @param[in] seed: the pointer that points to the 4-word seed + * @param[in] signature: the pointer that points the memory that the 128-bit + * singnature result that will be stored through this function. + * it is only valid when config->act == FLASH_CMD_ACT_WAIT. + * If config->act == FLASH_CMD_ACT_WAIT, the result is not stored + * @param[in] config: config the action when the command is executing. If + * FLASH_CMD_ACT_WAIT is selected, the result is stored in + * signature[4]. If FLASH_CMD_ACT_INT is selected, the result + * is not selected. user can get the result in the interrupt + * call back function + * + * @note if config->callBack is not NULL, it has to point to a funtion + * that is not in the flash memory that flash commands is executing + * in. + * + * @return - SUCC -- successful + * - ERR -- some error + * - BUSY -- flash is executing last command. It can not execute this + * new command now. + * + */ +ResultStatus_t FLASH_IfrPagesMircSignature(uint32_t startAddr, uint32_t endAddr, + uint32_t seed[4], uint32_t signature[4], + const FLASH_CmdConfig_t *config) +{ + ResultStatus_t stat; + + if(0U == flsRegPtr->FLASH_FSTAT.CCIF) + { + stat = BUSY; + } + else { + flsRegWPtr->FLASH_FADDR = startAddr; + flsRegWPtr->FLASH_FADDR_END = endAddr; + + flsRegWPtr->FLASH_FDATA0 = seed[0]; + flsRegWPtr->FLASH_FDATA1 = seed[1]; + flsRegWPtr->FLASH_FDATA2 = seed[2]; + flsRegWPtr->FLASH_FDATA3 = seed[3]; + + if(FLASH_CMD_ACT_WAIT == config->act) + { + stat = FLASH_ExecuteCommand(FLASH_CMD_RDIMISR, config->callBack); + if( SUCC == stat) + { + signature[0] = flsRegWPtr->FLASH_FDATA0; + signature[1] = flsRegWPtr->FLASH_FDATA1; + signature[2] = flsRegWPtr->FLASH_FDATA2; + signature[3] = flsRegWPtr->FLASH_FDATA3; + } + } + else + { + stat = FLASH_ExecuteCommandInt(FLASH_CMD_RDIMISR); + } + } + + return stat; +} + +/** + * @brief program a flash phrase + * + * @param[in] flashAddr: phrase start address to be programmed + * @param[in] dataP: points to data to be programmed into flash + * @param[in] config: config the action when the command is executing + * + * @note if config->callBack is not NULL, it has to point to a funtion + * that is not in the flash memory that flash commands is executing + * in. + * + * @return - SUCC -- successful + * - ERR -- some error + * - BUSY -- flash is executing last command. It can not execute this + * new command now. + * + */ +ResultStatus_t FLASH_ProgramPhrase(uint32_t flashAddr, const uint8_t *dataP, + const FLASH_CmdConfig_t *config) +{ + ResultStatus_t stat; + volatile uint8_t *fData = (volatile uint8_t *)&(flsRegWPtr->FLASH_FDATA0); + + if(0U == flsRegPtr->FLASH_FSTAT.CCIF) + { + stat = BUSY; + } + else + { + flsRegWPtr->FLASH_FADDR = flashAddr; + + for(uint8_t i = 0U; i < FLASH_PHRASE_SIZE; i++) + { + fData[i] = dataP[i]; + } + + if(FLASH_CMD_ACT_WAIT == config->act) + { + stat = FLASH_ExecuteCommand(FLASH_CMD_PGMPHR, config->callBack); + } + else + { + stat = FLASH_ExecuteCommandInt(FLASH_CMD_PGMPHR); + } + } + + return stat; +} + +/** + * @brief program flash memory + * + * @param[in] flashAddr: start address of flash memory. It is the start address of + * a phrase. This address should be aligned to 4 words(16 bytes) + * @param[in] len: length in byte to be programmed. + * This length should be aligned to 4 words(16 bytes). + * @param[in] dataP: points to the source buffer from which data is taken + * for program operation. + * @param[in] callBack: the callBack function when waiting for command executing + * + * @note if callBack is not NULL, it has to point to a funtion + * that is not in the flash memory that flash commands is executing + * in. + * + * @return - SUCC -- successful + * - ERR -- some error + * - BUSY -- flash is executing last command. It can not execute this + * new command now. + * + */ +ResultStatus_t FLASH_Program(uint32_t flashAddr, uint32_t len, const uint8_t *dataP, + flash_cb_t callBack) +{ + uint32_t count; + uint32_t bufAddr; + FLASH_CmdConfig_t config; + ResultStatus_t stat = ERR; + + config.act = FLASH_CMD_ACT_WAIT; + config.callBack = callBack; + + if(((flashAddr % 16U) != 0U) || (dataP == NULL) + || (len == 0U) || ((len % 16U) != 0U)) + { + stat = ERR; + } + else + { + /*PRQA S 0306 ++*/ + bufAddr = (uint32_t)dataP; + /*PRQA S 0306 --*/ + + for(count = 0U; count < len; count += 16U) + { + /*PRQA S 0306 ++*/ + stat = FLASH_ProgramPhrase((flashAddr + count), + (uint8_t *)(bufAddr + count), &config); + /*PRQA S 0306 --*/ + if(SUCC != stat) + { + break; + } + } + } + + return stat; +} + +/** + * @brief Erase all flash and IFR space + * + * @param[in] config: config the action when the command is executing + * + * @note if config->callBack is not NULL, it has to point to a funtion + * that is not in the flash memory + * + * @return - SUCC -- successful + * - ERR -- some error + * - BUSY -- flash is executing last command. It can not execute this + * new command now. + * + */ +ResultStatus_t FLASH_EraseAll(const FLASH_CmdConfig_t *config) +{ + ResultStatus_t stat; + + if(0U == flsRegPtr->FLASH_FSTAT.CCIF) + { + stat = BUSY; + } + else + { + if(FLASH_CMD_ACT_WAIT == config->act) + { + stat = FLASH_ExecuteCommand(FLASH_CMD_ERSALL, config->callBack); + } + else + { + stat = FLASH_ExecuteCommandInt(FLASH_CMD_ERSALL); + } + } + + return stat; +} + +/** + * @brief Erase a flash sector + * + * @param[in] addr: sector start address + * @param[in] config: config the action when the command is executing + * + * @note if config->callBack is not NULL, it has to point to a funtion + * that is not in the flash memory that flash commands is executing + * in. + * + * @return - SUCC -- successful + * - ERR -- some error + * - BUSY -- flash is executing last command. It can not execute this + * new command now. + * + */ +ResultStatus_t FLASH_EraseSector(uint32_t addr, const FLASH_CmdConfig_t *config) +{ + ResultStatus_t stat; + if(0U == flsRegPtr->FLASH_FSTAT.CCIF) + { + stat = BUSY; + } + else + { + flsRegWPtr->FLASH_FADDR = addr; + + if(FLASH_CMD_ACT_WAIT == config->act) + { + stat = FLASH_ExecuteCommand(FLASH_CMD_ERSSCR, config->callBack); + } + else + { + stat = FLASH_ExecuteCommandInt(FLASH_CMD_ERSSCR); + } + } + + return stat; +} + +/** + * @brief Flash enters security mode. In this mdoe, debug Port is prevented + * to read any AHB-AP memory-map addresses + * + * @param[in] debugEraseAllEn: Enable/Disable debug erase-all. + * - ENABLE: debug erase all request is allowed to + * erase flash + * - DIABLE: debug erase all request cannot erase flash + * @param[in] config: config the action when the command is executing + * + * @note if config->callBack is not NULL, it has to point to a funtion + * that is not in the flash memory that flash commands is executing + * in. + * + * @return - SUCC -- successful + * - ERR -- some error + * - BUSY -- flash is executing last command. It can not execute this + * new command now. + * + */ +ResultStatus_t FLASH_EnterSecurityMode(ControlState_t debugEraseAllEn, + const FLASH_CmdConfig_t *config) +{ + uint8_t data[16] = {0xECU, 0xF5U, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, + 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU}; + ResultStatus_t stat = ERR; + + if(0U == flsRegPtr->FLASH_FSTAT.CCIF) + { + stat = BUSY; + } + else + { + if(DISABLE == debugEraseAllEn) + { + data[2] = 0xE2U; + data[3] = 0x3EU; + } + stat = FLASH_ProgramPhrase(FLASH_SECURE_ADDR, data, config); + } + + return stat; +} + +/** + * @brief Set wait state. If the system clock frequency is higher than + * flash clock, some wait-states are required to be added to wait + * for flash data ready. + * + * @param[in] cycle: number of additional wait-state is added. + * Its range is 0-15. + * + * @return none + * + */ +void FLASH_SetWaitState(uint8_t cycle) +{ + flsRegPtr->FLASH_FCTRL.RWSC = cycle; +} + +/** + * @brief This function will wait until command is completed + * + * @param[in] none + * + * @return none + * + */ +void FLASH_WaitUntilCmdComplete(void) +{ + while(flsRegPtr->FLASH_FSTAT.CCIF == 0U) + { + } +} + +/** + * @brief Get FLASHC status + * + * @param[in] statMask: the status to be get + * + * @return the status + * + */ +FlagStatus_t FLASH_GetStatus(uint32_t statMask) +{ + FlagStatus_t status; + + status = (((flsRegWPtr->FLASH_FSTAT) & (uint32_t)statMask) == 0U)? RESET: SET; + + return status; +} + + +/** + * @brief Request to abort a command write sequence + * + * @param[in] none + * + * @return - FLASH_ABORT_OK -- abort flash command succeeded + * - FLASH_ABORT_FINISHED -- abort failed, but flash command has been finished + * - FLASH_ABORT_TIMEOUT -- abort flash command timeout + * + */ +FLASH_AbortResult_t FLASH_AbortCommand(void) +{ + volatile uint32_t localCnt = 0U; + uint32_t ccifFlag, cmdabtFlag; + FLASH_AbortResult_t stat; + + /* No flash command is being executed */ + if (1U == flsRegPtr->FLASH_FSTAT.CCIF) + { + stat = FLASH_ABORT_FINISHED; + } + else + { + /* Abort executing flash comand */ + flsRegPtr->FLASH_FCTRL.ABTREQ = 1U; + + stat = FLASH_ABORT_TIMEOUT; + while(localCnt < FLASH_TIMEOUT_ABORT_WAIT_CNT) + { + ccifFlag = flsRegPtr->FLASH_FSTAT.CCIF; + cmdabtFlag = flsRegPtr->FLASH_FSTAT.CMDABT; + + if ((1U == ccifFlag ) && (1U == cmdabtFlag)) + { + /* clear CMDABT flag */ + flsRegWPtr->FLASH_FSTAT = FLASH_STATUS_CMDABT_MASK; + stat = FLASH_ABORT_OK; + break; + } + else if (1U == ccifFlag) { + /* abort failed, but flash command has been finished */ + stat = FLASH_ABORT_FINISHED; + break; + } + else + { + localCnt++; + } + } + } + + return stat; +} + + +/** + * @brief Install callback function + * + * @param[in] intType: select interrrupt type + * @param[in] cbFun: indicate callback function + * + * + * @return none + * + */ +void FLASH_InstallCallBackFunc(FLASH_Int_t intType, isr_cb_t * cbFun) +{ + if(intType < FLASH_INT_ALL) + { + flashIsrCbFunc[intType] = cbFun; + } +} + +/** + * @brief Mask/Unmask interrupt + * + * @param[in] intType: select interrrupt type + * @param[in] intMask: MASK/UNMASK + * + * @return none + * + */ +void FLASH_IntMask(FLASH_Int_t intType, IntMask_t intMask) +{ + if(UNMASK == intMask) + { + flsRegWPtr->FLASH_FCNFG |= flashInterruptMaskTable[intType]; + } + else + { + flsRegWPtr->FLASH_FCNFG &= ~flashInterruptMaskTable[intType]; + } +} + +/** + * @brief Clear interrupt + * + * @param[in] intType: select interrrupt type + * + * @return none + * + */ +void FLASH_IntClear(FLASH_Int_t intType) +{ + switch (intType) { + case FLASH_INT_CCIF: + /* this flag can only be cleared by execute a new command,so disable this + interrupt here */ + flsRegPtr->FLASH_FCNFG.CCIE = 0; + break; + + case FLASH_INT_DFDIF: + flsRegWPtr->FLASH_FSTAT = flashInterruptMaskTable[intType]; + break; + + case FLASH_INT_ALL: + flsRegWPtr->FLASH_FSTAT = FLASH_ECC_MASK; + flsRegPtr->FLASH_FCNFG.CCIE = 0; + break; + /*PRQA S 2016 ++*/ + default: + /*PRQA S 2016 --*/ + break; + } +} + +/** + * @brief FLASH IRQHandler + * + * @param[in] none + * + * @return none + * + */ +void FLASH_DriverIRQHandler(void) +{ + uint32_t status, id; + + status = flsRegWPtr->FLASH_FSTAT & flashInterruptMaskTable[FLASH_INT_ALL]; + + /* get status */ + status &= flsRegWPtr->FLASH_FCNFG; + + if((status & FLASH_INT_CCIF_MASK) != 0U) + { + /* this flag can only be cleared by execute a new command,so disable this + interrupt here */ + flsRegPtr->FLASH_FCNFG.CCIE = 0; + } + /* clear int status */ + if((status & FLASH_INT_DFDIF_MASK) != 0U) + { + flsRegWPtr->FLASH_FSTAT = FLASH_INT_DFDIF_MASK; + } + + for(id = 0U; id < (uint32_t)FLASH_INT_ALL; id++) + { + if((status & flashInterruptMaskTable[id]) != 0U) + { + if(flashIsrCbFunc[id] != NULL) + { + flashIsrCbFunc[id](); + } + else + { + flsRegWPtr->FLASH_FCNFG &= ~flashInterruptMaskTable[id]; + } + } + } +} + + +/** + * @brief flash module init + * + * @param[in] none + * + * @return - SUCC -- Initialization succeeded. + * - ERR -- Initialization failed. + * + */ +ResultStatus_t Flash_Init(void) +{ + ResultStatus_t stat = SUCC; + + if(1U == flsRegPtr->FLASH_FSTAT.FAIL) + { + stat = ERR; + } + + return stat; +} + +/** @} end of group FLASH_Public_Functions */ + +/** @} end of group FLASH_definitions */ + +/** @} end of group Z20K11X_Peripheral_Driver */ diff --git a/StdDriver/Src/Z20K11xM_gpio.c b/StdDriver/Src/Z20K11xM_gpio.c new file mode 100644 index 0000000..a60c69e --- /dev/null +++ b/StdDriver/Src/Z20K11xM_gpio.c @@ -0,0 +1,1169 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_gpio.c + * @brief : GPIO module driver file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ + +#include "Z20K11xM_gpio.h" + +/** @addtogroup Z20K11X_Peripheral_Driver + * @{ + */ +/** @addtogroup GPIO + * @brief GPIO driver modules + * @{ + */ + +/** @defgroup PORT_Private_Type + * @{ + */ + +/** @} end of group PORT_Private_Type */ + +/** @defgroup PORT_Private_Defines + * @{ + */ +#define PORT_TOTAL_NUM (5U) +#define PINS_TOTAL_NUM (32U) +#define PORT_PARCC ((parcc_reg_t *)PARCC_BASE_ADDR) /*!< PARCC register */ +#define PORT_PCR_ALL_MASK (0x9F8F877BU) /*!< PCR register all functions */ +/** @} end of group PORT_Private_Defines */ + +/** @defgroup GPIO_Private_Defines + * @{ + */ +#define GPIO_TOTAL_NUM (5U) +/** @} end of group GPIO_Private_Defines */ + +/** @defgroup RGPIO_Private_Defines + * @{ + */ +#define RGPIO_TOTAL_NUM (5U) +/** @} end of group RGPIO_Private_Defines */ + +/** @defgroup PORT_Private_Variables + * @{ + */ + +/*PRQA S 0303 ++*/ +/** + * @brief PARRC address array + */ +static parcc_reg_t *const parccRegPtr = (parcc_reg_t *)PARCC_BASE_ADDR; +/** + * @brief PORTA PORTB PORT PORTD PORTE address array + */ +/*PRQA S 0303 ++*/ +static port_reg_t *const portRegPtr[PORT_TOTAL_NUM] = { + (port_reg_t *)PORTA_BASE_ADDR, /*!< Port A base address */ + (port_reg_t *)PORTB_BASE_ADDR, /*!< Port B base address */ + (port_reg_t *)PORTC_BASE_ADDR, /*!< Port C base address */ + (port_reg_t *)PORTD_BASE_ADDR, /*!< Port D base address */ + (port_reg_t *)PORTE_BASE_ADDR /*!< Port E base address */ +}; + +static port_reg_w_t *const portRegWPtr[PORT_TOTAL_NUM] = { + (port_reg_w_t *)PORTA_BASE_ADDR, /*!< Port A base address */ + (port_reg_w_t *)PORTB_BASE_ADDR, /*!< Port B base address */ + (port_reg_w_t *)PORTC_BASE_ADDR, /*!< Port C base address */ + (port_reg_w_t *)PORTD_BASE_ADDR, /*!< Port D base address */ + (port_reg_w_t *)PORTE_BASE_ADDR /*!< Port E base address */ +}; +/*PRQA S 0303 --*/ +/** + * @brief PORT ISR callback function pointer array + */ +static port_cb_t portIsrCbFun = NULL; + +/** @} end of group PORT_Private_Variables */ +/** @defgroup GPIO_Private_Variables + * @{ + */ +/** + * @brief GPIOA GPIOB GPIOC GPIOD GPIOE address array + */ +/*PRQA S 0303 ++*/ +static gpio_reg_t *const gpioRegPtr[GPIO_TOTAL_NUM] = { + (gpio_reg_t *)GPIOA_BASE_ADDR, /*!< GPIO A base address */ + (gpio_reg_t *)GPIOB_BASE_ADDR, /*!< GPIO B base address */ + (gpio_reg_t *)GPIOC_BASE_ADDR, /*!< GPIO C base address */ + (gpio_reg_t *)GPIOD_BASE_ADDR, /*!< GPIO D base address */ + (gpio_reg_t *)GPIOE_BASE_ADDR /*!< GPIO E base address */ +}; + +static gpio_reg_w_t *const gpioRegWPtr[GPIO_TOTAL_NUM] = { + (gpio_reg_w_t *)GPIOA_BASE_ADDR, /*!< GPIO A base address */ + (gpio_reg_w_t *)GPIOB_BASE_ADDR, /*!< GPIO B base address */ + (gpio_reg_w_t *)GPIOC_BASE_ADDR, /*!< GPIO C base address */ + (gpio_reg_w_t *)GPIOD_BASE_ADDR, /*!< GPIO D base address */ + (gpio_reg_w_t *)GPIOE_BASE_ADDR /*!< GPIO E base address */ +}; +/*PRQA S 0303 --*/ +/** @} end of group GPIO_Private_Variables */ + +/** @defgroup RGPIO_Private_Variables + * @{ + */ +/** + * @brief RGPIOA RGPIOB RGPIOC RGPIOD RGPIOE address array + */ +/*PRQA S 0303 ++*/ +static gpio_reg_w_t *const rgpioRegWPtr[RGPIO_TOTAL_NUM] = { + (gpio_reg_w_t *)RGPIOA_BASE_ADDR, /*!< GPIO A base address */ + (gpio_reg_w_t *)RGPIOB_BASE_ADDR, /*!< GPIO B base address */ + (gpio_reg_w_t *)RGPIOC_BASE_ADDR, /*!< GPIO C base address */ + (gpio_reg_w_t *)RGPIOD_BASE_ADDR, /*!< GPIO D base address */ + (gpio_reg_w_t *)RGPIOE_BASE_ADDR /*!< GPIO E base address */ +}; +/*PRQA S 0303 --*/ +/** @} end of group RGPIO_Private_Variables */ + +/** @defgroup PORT_Private_FunctionDeclaration + * @{ + */ +static void PORT_IntHandler(PORT_ID_t portId); +void PORTABC_DriverIRQHandler(void); +void PORTDE_DriverIRQHandler(void); + +/** @} end of group PORT_Private_FunctionDeclaration */ + +/** @defgroup PORT_Private_Functions + * @{ + */ +/** + * @brief PORT interrupt handle. + * + * @param[in] none. + * @return none. + * + */ +static void PORT_IntHandler(PORT_ID_t portId) +{ + uint32_t status; + uint32_t gpioNo; + port_reg_t *PORTx = (port_reg_t *)(portRegPtr[portId]); + port_reg_w_t *PORTxw = (port_reg_w_t *)(portRegWPtr[portId]); + status = PORTx->PORTx_IRQFLG.ISF; + + for (gpioNo = (uint32_t)GPIO_0; gpioNo < (uint32_t)PINS_TOTAL_NUM; gpioNo++) + { + if ((status & (0x01UL << gpioNo)) != 0U) + { + if (portIsrCbFun != NULL) + { + portIsrCbFun(portId, (PORT_GPIONO_t)gpioNo); + } + else + { + PORTxw->PORTx_PCRn[gpioNo] = 0x5B000000U; + PORTx->PORTx_PCRn[gpioNo].IRQC = 0U; + PORTx->PORTx_PCRn[gpioNo].LK = 1U; + } + } + PORTx->PORTx_IRQFLG.ISF = (status&(0x01UL << gpioNo)); + } +} + +/** + * @brief PORTABC interrupt function. + * + * @param none. + * + * @return none. + * + */ +void PORTABC_DriverIRQHandler(void) +{ + if (((parccRegPtr->PARCC_PORTA.PCKMD) & 0x1U) != 0U) /*PRQA S 0303*/ + { + if ((portRegPtr[PORT_A]->PORTx_IRQFLG.ISF) != 0U) + { + PORT_IntHandler(PORT_A); + } + } + + if (((parccRegPtr->PARCC_PORTB.PCKMD) & 0x1U) != 0U) /*PRQA S 0303*/ + { + if ((portRegPtr[PORT_B]->PORTx_IRQFLG.ISF) != 0U) + { + PORT_IntHandler(PORT_B); + } + } + + if (((parccRegPtr->PARCC_PORTC.PCKMD) & 0x1U) != 0U) /*PRQA S 0303*/ + { + if ((portRegPtr[PORT_C]->PORTx_IRQFLG.ISF) != 0U) + { + PORT_IntHandler(PORT_C); + } + } +} + +/** + * @brief PORTDE interrupt function. + * + * @param none. + * + * @return none. + * + */ +void PORTDE_DriverIRQHandler(void) +{ + if (((parccRegPtr->PARCC_PORTD.PCKMD) & 0x1U) != 0U) /*PRQA S 0303*/ + { + if ((portRegPtr[PORT_D]->PORTx_IRQFLG.ISF) != 0U) + { + PORT_IntHandler(PORT_D); + } + } + + if (((parccRegPtr->PARCC_PORTE.PCKMD) & 0x1U) != 0U) /*PRQA S 0303*/ + { + if ((portRegPtr[PORT_E]->PORTx_IRQFLG.ISF) != 0U) + { + PORT_IntHandler(PORT_E); + } + } +} +/** @} end of group PORT_Private_Functions */ + +/** @defgroup PORT_Public_Functions + * @{ + */ + +/** + * @brief Configure pins with the same global configuration + * If a pin is locked, global control will not work on it + * + * @param[in] portId: Select the PORT id,such as PORT_A,PORT_B,PORT_C, + * PORT_D,PORT_E. + * @param[in] pins: Select the GPIO pins. + * @param[in] value: Set GPIO pin global value. + * + * @return none. + * + */ +void PORT_GlobalPinsConfig(PORT_ID_t portId, uint32_t pins, uint32_t value) +{ + port_reg_w_t *PORTx = (port_reg_w_t *)(portRegWPtr[portId]); + uint32_t mask = 0U; + + mask |= PORT_PCR_ALL_MASK; + mask &= value; + + PORTx->PORTx_GLBDAT = mask; + PORTx->PORTx_GLBCTL = pins; +} + +/** + * @brief Initialize seleted pin with the given configuration structure. + * + * This function configures the pins with the options provided in the + * provided structure. + * + * @param[in] portId: Select the PORT id,such as PORT_A,PORT_B,PORT_C, + * PORT_D,PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * @param[in] pinConfig: Pin configuration struct. + * + * @return none. + * + */ +void PORT_PinInit(PORT_ID_t portId, PORT_GPIONO_t gpioNo, + const PORT_PinConfig_t *pinConfig) +{ + port_reg_t *PORTx = (port_reg_t *)(portRegPtr[portId]); + port_reg_w_t *PORTxw = (port_reg_w_t *)(portRegWPtr[portId]); + + if (PORTx->PORTx_PCRn[gpioNo].LK == 1U) + { + PORTxw->PORTx_PCRn[gpioNo] = 0x5B000000U; + } + PORTx->PORTx_PCRn[gpioNo].PS = ((uint32_t)(pinConfig->pullConfig)) & 0x01U; + PORTx->PORTx_PCRn[gpioNo].PE = + (((uint32_t)(pinConfig->pullConfig)) & 0x02U) >> 1U; + PORTx->PORTx_PCRn[gpioNo].SRE = (uint32_t)(pinConfig->slewRateConfig); + PORTx->PORTx_PCRn[gpioNo].PFE = (uint32_t)(pinConfig->passiveFilterConfig); + PORTx->PORTx_PCRn[gpioNo].ODE = (uint32_t)(pinConfig->openDrainConfig); + PORTx->PORTx_PCRn[gpioNo].DSE = (uint32_t)(pinConfig->driveStrengthConfig); + PORTx->PORTx_PCRn[gpioNo].FLTEN = (uint32_t)(pinConfig->filterEnable); + PORTx->PORTx_PCRn[gpioNo].FLT = (uint32_t)(pinConfig->filterConfig); + PORTx->PORTx_PCRn[gpioNo].LK = 1U; +} + +/** + * @brief Configure the pin mux function + * + * This function configures the pin muxing. + * + * @param[in] portId: Select the PORT id,such as PORT_A,PORT_B,PORT_C + * PORT_D,PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * @param[in] pinMuxFunc: Pin mux function. + * + * @return none. + * + */ +void PORT_PinmuxConfig(PORT_ID_t portId, PORT_GPIONO_t gpioNo, + PORT_PinMuxFunc_t pinMuxFunc) +{ + port_reg_t *PORTx = (port_reg_t *)(portRegPtr[portId]); + port_reg_w_t *PORTxw = (port_reg_w_t *)(portRegWPtr[portId]); + + if (PORTx->PORTx_PCRn[gpioNo].LK == 1U) + { + PORTxw->PORTx_PCRn[gpioNo] = 0x5B000000U; + } + PORTx->PORTx_PCRn[gpioNo].MUX = (uint32_t)pinMuxFunc; + PORTx->PORTx_PCRn[gpioNo].LK = 1U; +} + +/** + * @brief Configure the pin interrupt configuration + * + * This function configures the pin interrupt. + * + * @param[in] portId: Select the PORT id,such as PORT_A,PORT_B,PORT_C + * PORT_D,PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * @param[in] intConfig: Pin interrupt configuration. + * - PORT_ISF_DISABLED(0) + * - PORT_ISF_DMA_RISING_EDGE(1) + * - PORT_ISF_DMA_FALLING_EDGE(2) + * - PORT_ISF_DMA_BOTH_EDGE(3) + * - PORT_ISF_INT_LOGIC_0(8) + * - PORT_ISF_INT_RISING_EDGE(9) + * - PORT_ISF_INT_FALLING_EDGE(10) + * - PORT_ISF_INT_BOTH_EDGE(11) + * - PORT_ISF_INT_LOGIC_1(12) + * + * @return none. + * + */ +void PORT_PinIntConfig(PORT_ID_t portId, PORT_GPIONO_t gpioNo, + PORT_IntConfig_t intConfig) +{ + port_reg_t *PORTx = (port_reg_t *)(portRegPtr[portId]); + port_reg_w_t *PORTxw = (port_reg_w_t *)(portRegWPtr[portId]); + + if (PORTx->PORTx_PCRn[gpioNo].LK == 1U) + { + PORTxw->PORTx_PCRn[gpioNo] = 0x5B000000U; + } + PORTx->PORTx_PCRn[gpioNo].IRQC = (uint32_t)intConfig; + PORTx->PORTx_PCRn[gpioNo].LK = 1U; +} + +/** + * @brief Configure the pin pull configuration. + * + * This function configures the pin interrupt. + * + * @param[in] portId: Select the PORT id,such as PORT_A,PORT_B,PORT_C, + * PORT_D,PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * @param[in] pullConfig: Pin pull configuration, should be + * PORT_PULL_NONE, PORT_PULL_DOWN and PORT_PULL_UP. + * + * @return none. + * + */ +void PORT_PullConfig(PORT_ID_t portId, PORT_GPIONO_t gpioNo, + PORT_PullConfig_t pullConfig) +{ + port_reg_t *PORTx = (port_reg_t *)(portRegPtr[portId]); + port_reg_w_t *PORTxw = (port_reg_w_t *)(portRegWPtr[portId]); + + if (PORTx->PORTx_PCRn[gpioNo].LK == 1U) + { + PORTxw->PORTx_PCRn[gpioNo] = 0x5B000000U; + } + PORTx->PORTx_PCRn[gpioNo].PS = (uint32_t)pullConfig & 0x01U; + PORTx->PORTx_PCRn[gpioNo].PE = ((uint32_t)pullConfig & 0x02UL) >> 1UL; + PORTx->PORTx_PCRn[gpioNo].LK = 1U; +} + +/** + * @brief Configure the pin slew rate configuration. + * + * This function configures the pin slew rate. + * + * @param[in] portId: Select the PORT id,such as PORT_A,PORT_B,PORT_C, + * PORT_D,PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * @param[in] slewRateConfig: Pin slew rate configuration, should be + * PORT_FAST_RATE and PORT_SLOW_RATE. + * + * @return none. + * + */ +void PORT_SlewRateConfig(PORT_ID_t portId, PORT_GPIONO_t gpioNo, + PORT_SlewRate_t slewRateConfig) +{ + port_reg_t *PORTx = (port_reg_t *)(portRegPtr[portId]); + port_reg_w_t *PORTxw = (port_reg_w_t *)(portRegWPtr[portId]); + + if (PORTx->PORTx_PCRn[gpioNo].LK == 1U) + { + PORTxw->PORTx_PCRn[gpioNo] = 0x5B000000U; + } + PORTx->PORTx_PCRn[gpioNo].SRE = (uint32_t)slewRateConfig; + PORTx->PORTx_PCRn[gpioNo].LK = 1U; +} + +/** + * @brief Configure the pin passive filter configuration. + * + * This function configures the pin passive filter. + * + * @param[in] portId: Select the PORT id,such as PORT_A,PORT_B,PORT_C, + * PORT_D,PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * @param[in] passiveFilterConfig: Pin passive filter configuration, should be + * DISABLE and ENABLE. + * + * @return none. + * + */ +void PORT_PassiveFilterConfig(PORT_ID_t portId, PORT_GPIONO_t gpioNo, + ControlState_t passiveFilterConfig) +{ + port_reg_t *PORTx = (port_reg_t *)(portRegPtr[portId]); + port_reg_w_t *PORTxw = (port_reg_w_t *)(portRegWPtr[portId]); + + if (PORTx->PORTx_PCRn[gpioNo].LK == 1U) + { + PORTxw->PORTx_PCRn[gpioNo] = 0x5B000000U; + } + PORTx->PORTx_PCRn[gpioNo].PFE = (uint32_t)passiveFilterConfig; + PORTx->PORTx_PCRn[gpioNo].LK = 1U; +} + +/** + * @brief Configure the pin open drain configuration. + * + * This function configures the pin open drain. + * + * @param[in] portId: Select the PORT id,such as PORT_A,PORT_B,PORT_C, + * PORT_D,PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * @param[in] openDrainConfig: Pin open drain configuration, should be + * DISABLE and ENABLE. + * + * @return none. + * + */ +void PORT_OpenDrainConfig(PORT_ID_t portId, PORT_GPIONO_t gpioNo, + ControlState_t openDrainConfig) +{ + port_reg_t *PORTx = (port_reg_t *)(portRegPtr[portId]); + port_reg_w_t *PORTxw = (port_reg_w_t *)(portRegWPtr[portId]); + + if (PORTx->PORTx_PCRn[gpioNo].LK == 1U) + { + PORTxw->PORTx_PCRn[gpioNo] = 0x5B000000U; + } + PORTx->PORTx_PCRn[gpioNo].ODE = (uint32_t)openDrainConfig; + PORTx->PORTx_PCRn[gpioNo].LK = 1U; +} + +/** + * @brief Configure the pin drive strength configuration. + * + * This function configures the pin drive strength. + * + * @param[in] portId: Select the PORT id,such as PORT_A,PORT_B,PORT_C, + * PORT_D,PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * @param[in] driveStrengthConfig: Pin drive strength configuration, should + * be PORT_LOW_DRIVE_STRENGTH and + * PORT_HIGH_DRIVE_STRENGTH. + * + * @return none. + * + */ +void PORT_DriveStrengthConfig(PORT_ID_t portId, PORT_GPIONO_t gpioNo, + PORT_DriveStrength_t driveStrengthConfig) +{ + port_reg_t *PORTx = (port_reg_t *)(portRegPtr[portId]); + port_reg_w_t *PORTxw = (port_reg_w_t *)(portRegWPtr[portId]); + + if (PORTx->PORTx_PCRn[gpioNo].LK == 1U) + { + PORTxw->PORTx_PCRn[gpioNo] = 0x5B000000U; + } + PORTx->PORTx_PCRn[gpioNo].DSE = (uint32_t)driveStrengthConfig; + PORTx->PORTx_PCRn[gpioNo].LK = 1U; +} + +/** + * @brief Configure the pin filter configuration. + * + * This function configures the pin filter. + * + * @param[in] portId: Select the PORT id,such as PORT_A,PORT_B,PORT_C, + * PORT_D,PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * @param[in] filterConfig: pin filter configuration, the value is 0x0 - 0x1F. + * + * @return none. + * + */ +void PORT_FilterConfig(PORT_ID_t portId, PORT_GPIONO_t gpioNo, + uint8_t filterConfig) +{ + port_reg_t *PORTx = (port_reg_t *)(portRegPtr[portId]); + port_reg_w_t *PORTxw = (port_reg_w_t *)(portRegWPtr[portId]); + + if (PORTx->PORTx_PCRn[gpioNo].LK == 1U) + { + PORTxw->PORTx_PCRn[gpioNo] = 0x5B000000U; + } + PORTx->PORTx_PCRn[gpioNo].FLT = (uint32_t)filterConfig; + PORTx->PORTx_PCRn[gpioNo].LK = 1U; +} +/** + * @brief Enable/Disable the pin filter . + * + * This function enables/disables the pin filter. + * + * @param[in] portId: Select the PORT id,such as PORT_A,PORT_B,PORT_C, + * PORT_D,PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * @param[in] filterEnable: Pin filter configuration, should be + DISABLE or ENABLE. + * + * @return none. + * + */ +void PORT_FilterCmd(PORT_ID_t portId, PORT_GPIONO_t gpioNo, + ControlState_t filterEnable) +{ + port_reg_t *PORTx = (port_reg_t *)(portRegPtr[portId]); + port_reg_w_t *PORTxw = (port_reg_w_t *)(portRegWPtr[portId]); + + if (PORTx->PORTx_PCRn[gpioNo].LK == 1U) + { + PORTxw->PORTx_PCRn[gpioNo] = 0x5B000000U; + } + PORTx->PORTx_PCRn[gpioNo].FLTEN = (uint32_t)filterEnable; + PORTx->PORTx_PCRn[gpioNo].LK = 1U; +} + +/** + * @brief Get pin interrupt status function + * + * This function gets the pin interrupt status. + * + * @param[in] portId: Select the PORT id,such as PORT_A,PORT_B,PORT_C, + * PORT_D,PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * + * @return Interrupt status of a pin. + * + */ +FlagStatus_t PORT_GetIntStatus(PORT_ID_t portId, PORT_GPIONO_t gpioNo) +{ + port_reg_t *PORTx = (port_reg_t *)(portRegPtr[portId]); + + return ((FlagStatus_t)PORTx->PORTx_PCRn[gpioNo].ISF); +} + +/** + * @brief Get all pins interrupt status of a Port. + * + * This function gets all pins interrupt status. + * + * @param[in] portId: Select the PORT id,such as PORT_A,PORT_B,PORT_C, + * PORT_D,PORT_E. + * + * @return All Pins interrupt status of a Port. + * + */ +uint32_t PORT_GetIntStatusAll(PORT_ID_t portId) +{ + port_reg_w_t *PORTx = (port_reg_w_t *)(portRegWPtr[portId]); + + return ((uint32_t)PORTx->PORTx_IRQFLG); +} + +/** + * @brief Clear the pin interrupt status function. + * + * This function clears interrupt status of a pin. + * + * @param[in] portId: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * + * @return none. + * + */ +void PORT_ClearPinInt(PORT_ID_t portId, PORT_GPIONO_t gpioNo) +{ + port_reg_t *PORTx = (port_reg_t *)(portRegPtr[portId]); + port_reg_w_t *PORTxw = (port_reg_w_t *)(portRegWPtr[portId]); + + if (PORTx->PORTx_PCRn[gpioNo].LK == 1U) + { + PORTxw->PORTx_PCRn[gpioNo] = 0x5B000000U; + } + PORTx->PORTx_PCRn[gpioNo].ISF = 0x01U; + PORTx->PORTx_PCRn[gpioNo].LK = 1U; +} + +/** + * @brief Clear All Pins Interrupt Status Function + * + * @param[in] portId: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] clrPins: Select pins no, a bit is a pin, bit0-gpio0,... + * + * @return none. + * + */ +void PORT_ClearPinsInt(PORT_ID_t portId, uint32_t clrPins) +{ + uint32_t gpioNo; + port_reg_t *PORTx = (port_reg_t *)(portRegPtr[portId]); + port_reg_w_t *PORTxw = (port_reg_w_t *)(portRegWPtr[portId]); + + for (gpioNo = (uint32_t)GPIO_0; gpioNo < (uint32_t)PINS_TOTAL_NUM; gpioNo++) + { + if (PORTx->PORTx_PCRn[gpioNo].LK == 1U) + { + PORTxw->PORTx_PCRn[gpioNo] = 0x5B000000U; + } + } + PORTxw->PORTx_IRQFLG = clrPins; + for (gpioNo = (uint32_t)GPIO_0; gpioNo < (uint32_t)PINS_TOTAL_NUM; gpioNo++) + { + PORTx->PORTx_PCRn[gpioNo].LK = 1U; + } +} + +/** + * @brief Port install call back function + * + * @param[in] cbFun: pointer to callback function. + * + * @return none + * + */ +void PORT_InstallCallBackFunc(port_cb_t cbFun) +{ + portIsrCbFun = cbFun; +} + +/** @} end of group PORT_Public_Functions */ + +/** @defgroup GPIO_Public_Functions + * @{ + */ + +/** + * @brief Set the pin direction configuration. + * + * This function sets the pin direction. + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * @param[in] dir: Select I/O direction of a pin. + * - 0: corresponding pin is set to input + * - 1: corresponding pin is set to output + * + * @return none. + * + */ +void GPIO_SetPinDir(PORT_ID_t port, PORT_GPIONO_t gpioNo, GPIO_Dir_t dir) +{ + gpio_reg_w_t *GPIOx = (gpio_reg_w_t *)(gpioRegWPtr[port]); + + uint32_t pinDir = GPIOx->GPIOx_PDDR; + pinDir &= (~(0x01UL << (uint32_t)gpioNo)); + pinDir |= ((uint32_t)dir << (uint32_t)gpioNo); + GPIOx->GPIOx_PDDR = pinDir; +} + +/** + * @brief Set the direction configuration for all pins. + * + * This function sets the pin directions. + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] dataDir: Select I/O directions. + * - 0: corresponding pin is set to input + * - 1: corresponding pin is set to output + * + * @return none. + * + */ + +void GPIO_SetPinsDir(PORT_ID_t port, uint32_t dataDir) +{ + gpio_reg_w_t *GPIOx = (gpio_reg_w_t *)(gpioRegWPtr[port]); + + GPIOx->GPIOx_PDDR = dataDir; +} + +/** + * @brief Write a pin with a given value. + * + * This function writes a pin with a given value. + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * @param[in] val: Pin value. + * - 0: corresponding pin is set to LOW + * - 1: corresponding pin is set to HIGH + * + * @return none. + * + */ +void GPIO_WritePinOutput(PORT_ID_t port, PORT_GPIONO_t gpioNo, GPIO_LVL_t val) +{ + gpio_reg_w_t *GPIOx = (gpio_reg_w_t *)(gpioRegWPtr[port]); + + uint32_t pinValue = GPIOx->GPIOx_PDOR; + pinValue &= (~(0x01UL << (uint32_t)gpioNo)); + pinValue |= ((uint32_t)val << (uint32_t)gpioNo); + GPIOx->GPIOx_PDOR = pinValue; +} + +/** + * @brief Write pins with the given value. + * + * This function writes pins with the given value. + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] val: Pin value. + * - 0: corresponding pin is set to LOW + * - 1: corresponding pin is set to HIGH + * + * @return none. + * + */ +void GPIO_WritePinsOutput(PORT_ID_t port, uint32_t val) +{ + gpio_reg_w_t *GPIOx = (gpio_reg_w_t *)(gpioRegWPtr[port]); + + GPIOx->GPIOx_PDOR = val; +} + +/** + * @brief Write a pin to 'Clear' value. + * + * This function writes a pin to 'Clear' value. + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * + * @return none. + * + */ +void GPIO_ClearPinOutput(PORT_ID_t port, PORT_GPIONO_t gpioNo) +{ + gpio_reg_w_t *GPIOx = (gpio_reg_w_t *)(gpioRegWPtr[port]); + + GPIOx->GPIOx_PCOR = (0x01UL << (uint32_t)gpioNo); +} +/** + * @brief Write pins to 'Clear' value + * + * This function writes pins to 'Clear' value. + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] pins: Clean the GPIO pins. + * + * @return none. + * + */ +void GPIO_ClearPinsOutput(PORT_ID_t port, uint32_t pins) +{ + gpio_reg_t *GPIOx = (gpio_reg_t *)(gpioRegPtr[port]); + + GPIOx->GPIOx_PCOR.PCO = pins; +} + +/** + * @brief Write a pin with 'Set' value. + * + * This function writes a pin with 'Set' value. + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * + * @return none. + * + */ +void GPIO_SetPinOutput(PORT_ID_t port, PORT_GPIONO_t gpioNo) +{ + gpio_reg_w_t *GPIOx = (gpio_reg_w_t *)(gpioRegWPtr[port]); + + GPIOx->GPIOx_PSOR = (0x01UL << (uint32_t)gpioNo); +} + +/** + * @brief Write pins with 'Set' value. + * + * This function writes pins with 'Set' value. + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] pins: Set the GPIO pins. + * + * @return none. + * + */ +void GPIO_SetPinsOutput(PORT_ID_t port, uint32_t pins) +{ + gpio_reg_w_t *GPIOx = (gpio_reg_w_t *)(gpioRegWPtr[port]); + + GPIOx->GPIOx_PSOR = pins; +} + +/** + * @brief Toggle a pin value. + * + * This function toggles a pin with 'Set' value. + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * + * @return none. + * + */ +void GPIO_TogglePinOutput(PORT_ID_t port, PORT_GPIONO_t gpioNo) +{ + gpio_reg_w_t *GPIOx = (gpio_reg_w_t *)(gpioRegWPtr[port]); + + GPIOx->GPIOx_PTOR = (0x01UL << (uint32_t)gpioNo); +} + +/** + * @brief Toggle pins value. + * + * This function toggles pins with 'Set' value. + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] pins: Toggle the GPIO pins. + * + * @return none. + * + */ +void GPIO_TogglePinsOutput(PORT_ID_t port, uint32_t pins) +{ + gpio_reg_w_t *GPIOx = (gpio_reg_w_t *)(gpioRegWPtr[port]); + + GPIOx->GPIOx_PTOR = pins; +} + +/** + * @brief Read a pin value. + * + * This function reads a pin value. + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * + * @return GPIO_HIGH or GPIO_LOW. + * + */ +GPIO_LVL_t GPIO_ReadPinLevel(PORT_ID_t port, PORT_GPIONO_t gpioNo) +{ + gpio_reg_w_t *GPIOx = (gpio_reg_w_t *)(gpioRegWPtr[port]); + + uint32_t pinLevel = GPIOx->GPIOx_PDIR; + pinLevel &= (0x01UL << (uint32_t)gpioNo); + return ((pinLevel != 0U) ? GPIO_HIGH : GPIO_LOW); +} + +/** + * @brief Read pins value. + * + * This function reads pins value. + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * + * @return Pins value. + * + */ +uint32_t GPIO_ReadPinsLevel(PORT_ID_t port) +{ + gpio_reg_t *GPIOx = (gpio_reg_t *)(gpioRegPtr[port]); + + return GPIOx->GPIOx_PDIR.PDI; +} + +/** @} end of group GPIO_Public_Functions */ + +/** @defgroup RGPIO_Public_Functions + * @{ + */ +/** + * @brief Set the pin direction configuration. + * + * This function sets the pin direction. + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * @param[in] dir: Select I/O direction of a pin. + * - 0: corresponding pin is set to input + * - 1: corresponding pin is set to output + * + * @return none. + * + */ +void RGPIO_SetPinDir(PORT_ID_t port, PORT_GPIONO_t gpioNo, GPIO_Dir_t dir) +{ + gpio_reg_w_t *RGPIOx = (gpio_reg_w_t *)(rgpioRegWPtr[port]); + + uint32_t pinDir = RGPIOx->GPIOx_PDDR; + pinDir &= (~(0x01UL << (uint32_t)gpioNo)); + pinDir |= ((uint32_t)dir << (uint32_t)gpioNo); + RGPIOx->GPIOx_PDDR = pinDir; +} + +/** + * @brief Set the direction configuration for all pins. + * + * This function sets the pin directions. + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] dataDir: Select I/O directions. + * - 0: corresponding pin is set to input + * - 1: corresponding pin is set to output + * + * @return none. + * + */ +void RGPIO_SetPinsDir(PORT_ID_t port, uint32_t dataDir) +{ + gpio_reg_w_t *RGPIOx = (gpio_reg_w_t *)(rgpioRegWPtr[port]); + + RGPIOx->GPIOx_PDDR = dataDir; +} + +/** + * @brief Write a pin with a given value. + * + * This function writes a pin with a given value. + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] gpioNo: Select the RGPIO pin,such as GPIO_0~GPIO_31. + * @param[in] val: Pin value. + * - 0: corresponding pin is set to LOW + * - 1: corresponding pin is set to HIGH + * + * @return none. + * + */ +void RGPIO_WritePinOutput(PORT_ID_t port, PORT_GPIONO_t gpioNo, GPIO_LVL_t val) +{ + gpio_reg_w_t *RGPIOx = (gpio_reg_w_t *)(rgpioRegWPtr[port]); + + uint32_t pinValue = RGPIOx->GPIOx_PDOR; + pinValue &= (~(0x01UL << (uint32_t)gpioNo)); + pinValue |= ((uint32_t)val << (uint32_t)gpioNo); + RGPIOx->GPIOx_PDOR = pinValue; +} + +/** + * @brief Write pins with the given value. + * + * This function writes pins with the given value. + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] val: Pin value. + * - 0: corresponding pin is set to LOW + * - 1: corresponding pin is set to HIGH + * + * @return none. + * + */ +void RGPIO_WritePinsOutput(PORT_ID_t port, uint32_t val) +{ + gpio_reg_w_t *RGPIOx = (gpio_reg_w_t *)(rgpioRegWPtr[port]); + + RGPIOx->GPIOx_PDOR = val; +} + +/** + * @brief Write a pin to 'Clear' value. + * + * This function writes a pin to 'Clear' value. + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * + * @return none. + * + */ +void RGPIO_ClearPinOutput(PORT_ID_t port, PORT_GPIONO_t gpioNo) +{ + gpio_reg_w_t *RGPIOx = (gpio_reg_w_t *)(rgpioRegWPtr[port]); + + RGPIOx->GPIOx_PCOR = (0x01UL << (uint32_t)gpioNo); +} + +/** + * @brief Write pins to 'Clear' value + * + * This function writes pins to 'Clear' value. + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] pins: Clean the GPIO pins. + * + * @return none. + * + */ +void RGPIO_ClearPinsOutput(PORT_ID_t port, uint32_t pins) +{ + gpio_reg_w_t *RGPIOx = (gpio_reg_w_t *)(rgpioRegWPtr[port]); + + RGPIOx->GPIOx_PCOR = pins; +} + +/** + * @brief Write a pin with 'Set' value. + * + * This function writes a pin with 'Set' value. + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * + * @return none. + * + */ +void RGPIO_SetPinOutput(PORT_ID_t port, PORT_GPIONO_t gpioNo) +{ + gpio_reg_w_t *RGPIOx = (gpio_reg_w_t *)(rgpioRegWPtr[port]); + + RGPIOx->GPIOx_PSOR = (0x01UL << (uint32_t)gpioNo); +} + +/** + * @brief Write pins with 'Set' value. + * + * This function writes pins with 'Set' value. + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] pins: Set the GPIO pins. + * + * @return none. + * + */ +void RGPIO_SetPinsOutput(PORT_ID_t port, uint32_t pins) +{ + gpio_reg_w_t *RGPIOx = (gpio_reg_w_t *)(rgpioRegWPtr[port]); + + RGPIOx->GPIOx_PSOR = pins; +} + +/** + * @brief Toggle a pin value. + * + * This function toggles a pin with 'Set' value. + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * + * @return none. + * + */ +void RGPIO_TogglePinOutput(PORT_ID_t port, PORT_GPIONO_t gpioNo) +{ + gpio_reg_w_t *RGPIOx = (gpio_reg_w_t *)(rgpioRegWPtr[port]); + + RGPIOx->GPIOx_PTOR = (0x01UL << (uint32_t)gpioNo); +} + +/** + * @brief Toggle pins value. + * + * This function toggles pins with 'Set' value. + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] pins: Toggle the GPIO pins. + * + * @return none. + * + */ +void RGPIO_TogglePinsOutput(PORT_ID_t port, uint32_t pins) +{ + gpio_reg_w_t *RGPIOx = (gpio_reg_w_t *)(rgpioRegWPtr[port]); + + RGPIOx->GPIOx_PTOR = pins; +} + +/** + * @brief Read a pin value. + * + * This function reads a pin value. + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * @param[in] gpioNo: Select the GPIO pin,such as GPIO_0~GPIO_31. + * + * @return GPIO_HIGH or GPIO_LOW. + * + */ +GPIO_LVL_t RGPIO_ReadPinLevel(PORT_ID_t port, PORT_GPIONO_t gpioNo) +{ + gpio_reg_w_t *RGPIOx = (gpio_reg_w_t *)(rgpioRegWPtr[port]); + + uint32_t pinLevel = RGPIOx->GPIOx_PDIR; + pinLevel &= (0x01UL << (uint32_t)gpioNo); + return ((pinLevel != 0U) ? GPIO_HIGH : GPIO_LOW); +} + +/** + * @brief Read pins value. + * + * This function reads pins value. + * + * @param[in] port: Select pin PORT ID: PORT_A, PORT_B, PORT_C, + * PORT_D, PORT_E. + * + * @return Pins value. + * + */ +uint32_t RGPIO_ReadPinsLevel(PORT_ID_t port) +{ + gpio_reg_w_t *RGPIOx = (gpio_reg_w_t *)(rgpioRegWPtr[port]); + + return RGPIOx->GPIOx_PDIR; +} + +/** @} end of group RGPIO_Public_Functions */ + +/** @} end of group GPIO */ + +/** @} end of group Z20K11X_Peripheral_Driver */ diff --git a/StdDriver/Src/Z20K11xM_hwdiv.c b/StdDriver/Src/Z20K11xM_hwdiv.c new file mode 100644 index 0000000..16129b3 --- /dev/null +++ b/StdDriver/Src/Z20K11xM_hwdiv.c @@ -0,0 +1,475 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_hwdiv.c + * @brief : HWDIV module driver file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ + +#include "Z20K11xM_hwdiv.h" + +/** @addtogroup Z20K11X_Peripheral_Driver + * @{ + */ + +/** @defgroup HWDIV HWDIV + * @brief HWDIV driver modules + * @{ + */ + +/** @defgroup HWDIV_Private_Type + * @{ + */ + +/** @}end of group HWDIV_Private_Type*/ + +/** @defgroup HWDIV_Private_Defines + * @{ + */ + +/** @}end of group HWDIV_Private_Defines */ + +/** @defgroup HWDIV_Private_Variables + * @{ + */ + +/** @}end of group HWDIV_Private_Variables */ + +/** @defgroup HWDIV_Global_Variables + * @{ + */ + +/** @}end of group HWDIV_Global_Variables */ + +/** @defgroup HWDIV_Private_FunctionDeclaration + * @{ + */ + +/** @}end of group HWDIV_Private_FunctionDeclaration */ + +/** @defgroup HWDIV_Private_Functions + * @{ + */ + +/** @} end of group HWDIV_Private_Functions */ + +/** @defgroup HWDIV_Public_Functions + * @{ + */ +/** + * @brief Initializes the HWDIV + * @param[in] none + * + * + * @return + * - SUCC: Operation is successful + * - BUSY: Operation fails, the module is busy calculating + */ +ResultStatus_t HWDIV_Init(void) +{ + ResultStatus_t ret; + + ret = (hwdivRegPtr->HWDIV_CSR.BUSY != 0U) ? BUSY : SUCC; + + return ret; +} + +/** + * @brief Enable/disable divided by zero + * @param[in] newState: divided by zero enable/disable + * -DISABLE: If divisor is 0,the quotient result and remainder are + * forced to 0x0000_0000,else reads of the RES register + * return the register contents. + * -ENABLE: If divisor is 0,an attempted read of RES register will + * generate hardfault interrupt,else the register contents + * are returned + * + */ +void HWDIV_DivZeroCmd(ControlState_t newState) +{ + hwdivRegPtr->HWDIV_CSR.DZE = (uint32_t)newState; +} + +/** + * @brief Perform the unsigned division with non-blocking call + * @param[in] dividend: dividend operand + * @param[in] divisor: divisor operand + * + * @return + * - SUCC: Operation is successful + * - BUSY: Operation fails, the module is busy calculating + */ +ResultStatus_t HWDIV_UnsignedDiv(uint32_t dividend, uint32_t divisor) +{ + ResultStatus_t ret; + + if (hwdivRegPtr->HWDIV_CSR.BUSY != 0U) + { + ret = BUSY; + } + else + { + hwdivRegPtr->HWDIV_CSR.USGN = 1U; + hwdivRegWPtr->HWDIV_DEND = dividend; + hwdivRegWPtr->HWDIV_DSOR = divisor; + + if (hwdivRegPtr->HWDIV_CSR.DFS == 1U) + { + hwdivRegPtr->HWDIV_STRT.STRT = 1U; + } + ret = SUCC; + } + + return ret; +} + +/** + * @brief Get the result of unsigned division + * @param[out] result: the result of division + * @param[out] rem: the remainder of the division + * + * @return + * - SUCC: Operation is successful + * - BUSY: Operation fails, the module is busy calculating + * - ERR: Operation fails, the last operation is not a division or + * divided by 0 + */ +ResultStatus_t HWDIV_GetResultUnsignedDiv(uint32_t *result, uint32_t *rem) +{ + ResultStatus_t ret = SUCC; + + if (hwdivRegPtr->HWDIV_CSR.BUSY != 0U) + { + ret = BUSY; + } + else + { + if (hwdivRegPtr->HWDIV_CSR.DIV != 1U) + { + ret = ERR; + } + if ((ret == SUCC)&&(hwdivRegPtr->HWDIV_CSR.DZE == 0U)) + { + if (hwdivRegPtr->HWDIV_CSR.DZ == 1U) + { + ret = ERR; + } + } + } + + if (ret == SUCC) + { + *result = hwdivRegWPtr->HWDIV_RES; + *rem = hwdivRegWPtr->HWDIV_REM; + } + + return ret; +} + +/** + * @brief Perform the unsigned division with blocking call + * @param[in] dividend: dividend operand + * @param[in] divisor: divisor operand + * @param[out] result: the result of division + * @param[out] rem: the remainder of the division + * + * @return + * - SUCC: Operation is successful + * - BUSY: Operation fails, the module is busy calculating + * - ERR: Operation fails, the operation is not a division or + * divided by 0 + */ +ResultStatus_t HWDIV_UnsignedDivBlocking(uint32_t dividend, uint32_t divisor, + uint32_t *result, uint32_t *rem) +{ + volatile uint32_t i = 0U; + ResultStatus_t ret; + + ret = HWDIV_UnsignedDiv(dividend, divisor); + if (ret == SUCC) + { + while (i < HWDIV_TIMEOUT_WAIT_CNT) + { + if (hwdivRegPtr->HWDIV_CSR.BUSY != 1U) + { + break; + } + i++; + } + ret = HWDIV_GetResultUnsignedDiv(result, rem); + } + + return ret; +} + +/** + * @brief Perform the signed division with non-blocking call + * @param[in] dividend: dividend operand + * @param[in] divisor: divisor operand + * + * @return + * - SUCC: Operation is successful + * - BUSY: Operation fails, the module is busy calculating + */ +ResultStatus_t HWDIV_SignedDiv(int32_t dividend, int32_t divisor) +{ + ResultStatus_t ret; + + if (hwdivRegPtr->HWDIV_CSR.BUSY != 0U) + { + ret = BUSY; + } + else + { + hwdivRegPtr->HWDIV_CSR.USGN = 0U; + hwdivRegWPtr->HWDIV_DEND = (uint32_t)dividend; + hwdivRegWPtr->HWDIV_DSOR = (uint32_t)divisor; + + if (hwdivRegPtr->HWDIV_CSR.DFS == 1U) + { + hwdivRegPtr->HWDIV_STRT.STRT = 1U; + } + ret = SUCC; + } + + return ret; +} + +/** + * @brief Get the result of signed division + * @param[out] result: the result of division + * @param[out] rem: the remainder of the division + * + * @return + * - SUCC: Operation is successful + * - BUSY: Operation fails, the module is busy calculating + * - ERR: Operation fails, the last operation is not a division or + * divided by 0 + */ +ResultStatus_t HWDIV_GetResultSignedDiv(int32_t *result, int32_t *rem) +{ + ResultStatus_t ret = SUCC; + + if (hwdivRegPtr->HWDIV_CSR.BUSY != 0U) + { + ret = BUSY; + } + else + { + if (hwdivRegPtr->HWDIV_CSR.DIV != 1U) + { + ret = ERR; + } + if ((ret==SUCC)&&(hwdivRegPtr->HWDIV_CSR.DZE == 0U)) + { + if (hwdivRegPtr->HWDIV_CSR.DZ == 1U) + { + ret = ERR; + } + } + } + + if (ret == SUCC) + { + *result = (int32_t)hwdivRegWPtr->HWDIV_RES; + *rem = (int32_t)hwdivRegWPtr->HWDIV_REM; + } + + return ret; +} + +/** + * @brief Perform the signed division with blocking call + * @param[in] dividend: dividend operand + * @param[in] divisor: divisor operand + * @param[out] result: the result of division + * @param[out] rem: the remainder of the division + * + * @return + * - SUCC: Operation is successful + * - BUSY: Operation fails, the module is busy calculating + * - ERR: Operation fails, the operation is not a division or + * divided by 0 + */ +ResultStatus_t HWDIV_SignedDivBlocking(int32_t dividend, int32_t divisor, + int32_t *result, int32_t *rem) +{ + volatile uint32_t i = 0U; + ResultStatus_t ret; + + ret = HWDIV_SignedDiv(dividend, divisor); + if (ret == SUCC) + { + while (i < HWDIV_TIMEOUT_WAIT_CNT) + { + if (hwdivRegPtr->HWDIV_CSR.BUSY != 1U) + { + break; + } + i++; + } + ret = HWDIV_GetResultSignedDiv(result, rem); + } + + return ret; +} + +/** + * @brief Perform the square root calculation with non-blocking call + * @param[in] radicand: the radicand + * + * @return + * - SUCC: Operation is successful + * - BUSY: Operation fails, the module is busy calculating + */ +ResultStatus_t HWDIV_SquareRoot(uint32_t radicand) +{ + ResultStatus_t ret; + + if (hwdivRegPtr->HWDIV_CSR.BUSY != 0U) + { + ret = BUSY; + } + else + { + hwdivRegWPtr->HWDIV_RCND = radicand; + ret = SUCC; + } + + return ret; +} + +/** + * @brief Get the result of the square root calculation + * @param[out] result: the result of square root calculation + * @param[out] rem: the remainder of the square root calculation + * + * @return + * - SUCC: Operation is successful + * - BUSY: Operation fails, the module is busy calculating + * - ERR: Operation fails, the last operation is not a square root + * calculation + */ +ResultStatus_t HWDIV_GetResultSquareRoot(uint32_t *result, uint32_t *rem) +{ + ResultStatus_t ret = SUCC; + + if ((hwdivRegPtr->HWDIV_CSR.BUSY != 0U)) + { + ret = BUSY; + } + else if (hwdivRegPtr->HWDIV_CSR.SQRT != 1U) + { + ret = ERR; + } + else + { + *result = hwdivRegWPtr->HWDIV_RES; + *rem = hwdivRegWPtr->HWDIV_REM; + } + + return ret; +} + +/** + * @brief Perform the square root calculation with blocking call + * @param[in] radicand: the radicand + * @param[out] result: the result of square root calculation + * @param[out] rem: the remainder of the square root calculation + * + * @return + * - SUCC: Operation is successful + * - BUSY: Operation fails, the module is busy calculating + * - ERR: Operation fails, the operation is not a square root + * calculation + */ +ResultStatus_t HWDIV_SquareRootBlocking(uint32_t radicand, uint32_t *result, + uint32_t *rem) +{ + volatile uint32_t i = 0U; + ResultStatus_t ret; + + ret = HWDIV_SquareRoot(radicand); + if (ret == SUCC) + { + while (i < HWDIV_TIMEOUT_WAIT_CNT) + { + if (hwdivRegPtr->HWDIV_CSR.BUSY != 1U) + { + break; + } + i++; + } + ret = HWDIV_GetResultSquareRoot(result, rem); + } + + return ret; +} + +/** + * @brief Disable/Enable the Divider Fast Start Mode + * @param[in] disableDivFastStart: + * - ture: Disable the Fast Start Mode + * - false: Enable the Fast Start Mode + * @return + * - SUCC: Operation is successful + * - BUSY: Operation fails, the module is busy calculating + */ +ResultStatus_t HWDIV_DisableDivFastStart(ControlState_t disableDivFastStart) +{ + ResultStatus_t ret; + + if (hwdivRegPtr->HWDIV_CSR.BUSY != 0U) + { + ret = BUSY; + } + else + { + hwdivRegPtr->HWDIV_CSR.DFS = disableDivFastStart == ENABLE ? 1U : 0U; + ret = SUCC; + } + + return ret; +} + +/** + * @brief Get the HWDIV IP Version + * @param[out] version: the version of the IP + * + * + * @return + * - SUCC: Operation is successful + * + */ +ResultStatus_t HWDIV_GetIPVersion(uint32_t *version) +{ + *version = hwdivRegWPtr->HWDIV_VERSION; + + return SUCC; +} + +/** + * @brief Get the HWDIV IP Params + * @param[out] param: the Params of the IP + * + * + * @return + * - SUCC: Operation is successful + * + */ +ResultStatus_t HWDIV_GetIPParam(uint32_t *param) +{ + *param = hwdivRegWPtr->HWDIV_PARAM; + + return SUCC; +} + +/** @}end of group HWDIV_Public_Functions */ + +/** @}end of group HWDIV_definitions */ + +/** @}end of group Z20K11X_Peripheral_Driver */ diff --git a/StdDriver/Src/Z20K11xM_i2c.c b/StdDriver/Src/Z20K11xM_i2c.c new file mode 100644 index 0000000..504c915 --- /dev/null +++ b/StdDriver/Src/Z20K11xM_i2c.c @@ -0,0 +1,1352 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_i2c.c + * @brief : I2C module driver file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ + +#include "Z20K11xM_i2c.h" + +/** @addtogroup Z20K11X_Peripheral_Driver + * @{ + */ + +/** @defgroup I2C + * @brief I2C driver modules + * @{ + */ + +/** @defgroup I2C_Private_Type + * @{ + */ + +/** @} end of group I2C_Private_Type*/ + +/** @defgroup I2C_Private_Defines + * @{ + */ +#define I2C_STD_SPEED_SPKLEN (0x01U) /*!< I2C standard speed spike suppression limit */ +#define I2C_FAST_SPEED_SPKLEN (0x01U) /*!< I2C fast speed spike suppression limit */ +#define I2C_FAST_PLUS_SPEED_SPKLEN (0x02U) /*!< I2C fast plus speed spike suppression limit */ +#define I2C_HIGH_SPEED_SPKLEN (0x01U) /*!< I2C high speed spike suppression limit */ +#define I2C_STD_SPEED_SCL_HC (0x000000C0U) /*!< Standard speed I2C Clock SCL High Count */ +#define I2C_STD_SPEED_SCL_LC (0x000000C7U) /*!< Standard speed I2C Clock SCL Low Count */ +#define I2C_FAST_SPEED_SCL_HC (0x00000028U) /*!< Fast Mode I2C Clock SCL High Count */ +#define I2C_FAST_SPEED_SCL_LC (0x0000002FU) /*!< Fast Mode I2C Clock SCL Low Count */ +#define I2C_FAST_PLUS_SPEED_SCL_HC (0x00000009U) /*!< Fast Plus Mode I2C Clock SCL High Count */ +#define I2C_FAST_PLUS_SPEED_SCL_LC (0x00000011U) /*!< Fast Plus Mode I2C Clock SCL Low Count */ +#define I2C_HIGH_SPEED_SCL_HC (0x00000006U) /*!< High speed I2C Clock SCL High Count */ +#define I2C_HIGH_SPEED_SCL_LC (0x00000010U) /*!< High speed I2C Clock SCL Low Count */ + +/** @} end of group I2C_Private_Defines */ + +/** @defgroup I2C_Private_Variables + * @{ + */ + +/** + * @brief I2C0 and I2C1 address array + */ +/*PRQA S 0303 ++*/ +static i2c_reg_t * const i2cRegPtr[I2C_INSTANCE_NUM] = +{ + (i2c_reg_t *)I2C0_BASE_ADDR, +#if (2U == I2C_INSTANCE_NUM) + (i2c_reg_t *)I2C1_BASE_ADDR +#endif +}; + +static i2c_reg_w_t * const i2cRegWPtr[I2C_INSTANCE_NUM] = +{ + (i2c_reg_w_t *)I2C0_BASE_ADDR, +#if (2U == I2C_INSTANCE_NUM) + (i2c_reg_w_t *)I2C1_BASE_ADDR +#endif +}; +/*PRQA S 0303 --*/ + +/** + * @brief I2C ISR callback function pointer array + */ +static isr_cb_t * i2cIsrCb[I2C_INSTANCE_NUM][I2C_INT_ALL]= +{ + {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, +#if (2U == I2C_INSTANCE_NUM) + {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL} +#endif +}; + +/** + * @brief I2C interrupt enable array + */ +static const uint32_t i2cIntEnableTable[]= +{ + 0x00000001U, /*!< I2C_INT_GEN_CALL */ + 0x00000002U, /*!< I2C_INT_TX_OVER */ + 0x00000004U, /*!< I2C_INT_ERROR_ABORT */ + 0x00000008U, /*!< I2C_INT_ACTIVITY */ + 0x00000010U, /*!< I2C_INT_STOP_DET */ + 0x00000020U, /*!< I2C_INT_START_DET */ + 0x00400000U, /*!< I2C_INT_RD_REQ */ + 0x00800000U, /*!< I2C_INT_RX_DONE */ + 0x01000000U, /*!< I2C_INT_RX_UNDER */ + 0x02000000U, /*!< I2C_INT_RX_OVER */ + 0x04000000U, /*!< I2C_INT_RESTART_DET */ + 0x08000000U, /*!< I2C_SCL_STUCK_AT_LOW */ + 0x40000000U, /*!< I2C_INT_RX_FULL */ + 0x80000000U, /*!< I2C_INT_TX_EMPTY */ + 0xCFC0003FU /*!< I2C_INT_ALL */ +}; +/** @} end of group I2C_Private_Variables */ + +/** @defgroup I2C_Global_Variables + * @{ + */ + +/** @} end of group I2C_Global_Variables */ + + +/** @defgroup I2C_Private_FunctionDeclaration + * @{ + */ +void I2C0_DriverIRQHandler(void); +#if (2U == I2C_INSTANCE_NUM) +void I2C1_DriverIRQHandler(void); +#endif +static void I2C_IntHandler(I2C_Id_t i2cId); + +/** @} end of group I2C_Private_FunctionDeclaration */ + +/** @defgroup I2C_Private_Functions + * @{ + */ +/** + * @brief I2C interrupt handle + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * + * @return none + * + */ +static void I2C_IntHandler(I2C_Id_t i2cId) +{ + uint32_t intStatus; + i2c_reg_t * I2Cx = (i2c_reg_t *)(i2cRegPtr[i2cId]); + i2c_reg_w_t * I2Cxw = (i2c_reg_w_t *)(i2cRegWPtr[i2cId]); + + /* Read the interrupt status */ + intStatus = I2Cxw->I2C_STATUS0; + /* get status */ + intStatus &= I2Cxw->I2C_INT_ENABLE; + /* Clear the interrupt status */ + I2Cxw->I2C_STATUS0 = intStatus; + + if((intStatus & i2cIntEnableTable[I2C_INT_GEN_CALL]) != 0U) + { + if(i2cIsrCb[i2cId][I2C_INT_GEN_CALL]!= NULL) + { + i2cIsrCb[i2cId][I2C_INT_GEN_CALL](); + } + /* Disable the interrupt */ + else + { + I2Cx->I2C_INT_ENABLE.I2C_CALL_IE = 0U; + } + } + if((intStatus & i2cIntEnableTable[I2C_INT_TX_OVER]) != 0U) + { + if(i2cIsrCb[i2cId][I2C_INT_TX_OVER]!= NULL) + { + i2cIsrCb[i2cId][I2C_INT_TX_OVER](); + } + /* Disable the interrupt */ + else + { + I2Cx->I2C_INT_ENABLE.I2C_TX_OVF_IE = 0U; + } + } + if((intStatus & i2cIntEnableTable[I2C_INT_ERROR_ABORT]) != 0U) + { + if(i2cIsrCb[i2cId][I2C_INT_ERROR_ABORT]!= NULL) + { + i2cIsrCb[i2cId][I2C_INT_ERROR_ABORT](); + } + /* Disable the interrupt */ + else + { + I2Cx->I2C_INT_ENABLE.I2C_ERROR_ABORT_IE = 0U; + } + } + if((intStatus & i2cIntEnableTable[I2C_INT_ACTIVITY]) != 0U) + { + if(i2cIsrCb[i2cId][I2C_INT_ACTIVITY]!= NULL) + { + i2cIsrCb[i2cId][I2C_INT_ACTIVITY](); + } + /* Disable the interrupt */ + else + { + I2Cx->I2C_INT_ENABLE.I2C_ACTIVITY_DET_IE = 0U; + } + } + if((intStatus & i2cIntEnableTable[I2C_INT_STOP_DET]) != 0U) + { + if(i2cIsrCb[i2cId][I2C_INT_STOP_DET]!= NULL) + { + i2cIsrCb[i2cId][I2C_INT_STOP_DET](); + } + /* Disable the interrupt */ + else + { + I2Cx->I2C_INT_ENABLE.I2C_STOP_DET_IE = 0U; + } + } + if((intStatus & i2cIntEnableTable[I2C_INT_START_DET]) != 0U) + { + if(i2cIsrCb[i2cId][I2C_INT_START_DET]!= NULL) + { + i2cIsrCb[i2cId][I2C_INT_START_DET](); + } + /* Disable the interrupt */ + else + { + I2Cx->I2C_INT_ENABLE.I2C_START_DET_IE = 0U; + } + } + if((intStatus & i2cIntEnableTable[I2C_INT_RD_REQ]) != 0U) + { + if(i2cIsrCb[i2cId][I2C_INT_RD_REQ]!= NULL) + { + i2cIsrCb[i2cId][I2C_INT_RD_REQ](); + } + /* Disable the interrupt */ + else + { + I2Cx->I2C_INT_ENABLE.SLAVE_RD_REQ_IE = 0U; + } + } + if((intStatus & i2cIntEnableTable[I2C_INT_RX_DONE]) != 0U) + { + if(i2cIsrCb[i2cId][I2C_INT_RX_DONE]!= NULL) + { + i2cIsrCb[i2cId][I2C_INT_RX_DONE](); + } + /* Disable the interrupt */ + else + { + I2Cx->I2C_INT_ENABLE.RX_DONE_IE = 0U; + } + } + if((intStatus & i2cIntEnableTable[I2C_INT_RX_UNDER]) != 0U) + { + if(i2cIsrCb[i2cId][I2C_INT_RX_UNDER]!= NULL) + { + i2cIsrCb[i2cId][I2C_INT_RX_UNDER](); + } + /* Disable the interrupt */ + else + { + I2Cx->I2C_INT_ENABLE.RX_UNDER_IE = 0U; + } + } + if((intStatus & i2cIntEnableTable[I2C_INT_RX_OVER]) != 0U) + { + if(i2cIsrCb[i2cId][I2C_INT_RX_OVER]!= NULL) + { + i2cIsrCb[i2cId][I2C_INT_RX_OVER](); + } + /* Disable the interrupt */ + else + { + I2Cx->I2C_INT_ENABLE.RX_OVF_IE = 0U; + } + } + if((intStatus & i2cIntEnableTable[I2C_INT_RESTART_DET]) != 0U) + { + if(i2cIsrCb[i2cId][I2C_INT_RESTART_DET]!= NULL) + { + i2cIsrCb[i2cId][I2C_INT_RESTART_DET](); + } + /* Disable the interrupt */ + else + { + I2Cx->I2C_INT_ENABLE.RESTART_DET_IE = 0U; + } + } + if((intStatus & i2cIntEnableTable[I2C_SCL_STUCK_AT_LOW]) != 0U) + { + if(i2cIsrCb[i2cId][I2C_SCL_STUCK_AT_LOW]!= NULL) + { + i2cIsrCb[i2cId][I2C_SCL_STUCK_AT_LOW](); + } + /* Disable the interrupt */ + else + { + I2Cx->I2C_INT_ENABLE.SCL_STUCK_AT_LOW_IE = 0U; + } + } + if((intStatus & i2cIntEnableTable[I2C_INT_RX_FULL]) != 0U) + { + if(i2cIsrCb[i2cId][I2C_INT_RX_FULL]!= NULL) + { + i2cIsrCb[i2cId][I2C_INT_RX_FULL](); + } + /* Disable the interrupt */ + else + { + I2Cx->I2C_INT_ENABLE.RX_FULL_IE = 0U; + } + } + if((intStatus & i2cIntEnableTable[I2C_INT_TX_EMPTY]) != 0U) + { + if(i2cIsrCb[i2cId][I2C_INT_TX_EMPTY]!= NULL) + { + i2cIsrCb[i2cId][I2C_INT_TX_EMPTY](); + } + /* Disable the interrupt */ + else + { + I2Cx->I2C_INT_ENABLE.TX_EMPTY_IE = 0U; + } + } +} + +/** + * @brief I2C0 interrupt function + * + * @param none + * + * @return none + * + */ +void I2C0_DriverIRQHandler(void) +{ + I2C_IntHandler(I2C0_ID); +} + +#if (2U == I2C_INSTANCE_NUM) +/** + * @brief I2C1 interrupt function + * + * @param none + * + * @return none + * + */ +void I2C1_DriverIRQHandler(void) +{ + I2C_IntHandler(I2C1_ID); +} +#endif + +/** @} end of group I2C_Private_Functions */ + +/** @defgroup I2C_Public_Functions + * @{ + */ +/** + * @brief Install call back function + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C0_ID. + * @param[in] intId: Specified interrupt type. + * - I2C_INT_GEN_CALL + * - I2C_INT_TX_OVER + * - I2C_INT_ERROR_ABORT + * - I2C_INT_ACTIVITY + * - I2C_INT_STOP_DET + * - I2C_INT_START_DET + * - I2C_INT_RD_REQ + * - I2C_INT_RX_DONE + * - I2C_INT_RX_UNDER + * - I2C_INT_RX_OVER + * - I2C_INT_RESTART_DET + * - I2C_SCL_STUCK_AT_LOW + * - I2C_INT_RX_FULL + * - I2C_INT_TX_EMPTY + * - I2C_INT_ALL + * + * @param[in] cbFun: Pointer to callback function. + * + * @return none + * + */ +void I2C_InstallCallBackFunc(I2C_Id_t i2cId, I2C_INT_t intId, + isr_cb_t * cbFun) +{ + i2cIsrCb[i2cId][intId] = cbFun; +} + +/** + * @brief Initializes the I2C + * + * Under the premise that the crystal oscillator is OSC40M, speed mode selects + * standard speed and the default data transfer rate is 100 Kb/s. Speed mode + * selects fast speed and the default data transfer rate is 400 Kb/s.Speed mode + * selects fast plus speed and the default data transfer rate is 1 Mb/s. + * + * Under the premise that the crystal oscillator is FIRC64M,speed mode selects + * high speed and the default data transfer rate is 1.6 Mb/s. + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] i2cConfigStruct: Pointer to a I2C configuration structure. + * + * @return none + * + */ +void I2C_Init(I2C_Id_t i2cId, const I2C_Config_t* i2cConfigStruct) +{ + i2c_reg_t * I2Cx = (i2c_reg_t *)(i2cRegPtr[i2cId]); + /* Set the I2C speed mode */ + I2Cx->I2C_CONFIG1.SPEED_SEL = ((uint32_t)(i2cConfigStruct->speedMode))&0x3U; + + switch(i2cConfigStruct->speedMode) + { + case I2C_SPEED_STANDARD: + I2Cx->I2C_STD_SCL_HCNT.STD_SCL_HCNT = I2C_STD_SPEED_SCL_HC; + I2Cx->I2C_STD_SCL_LCNT.STD_SCL_LCNT = I2C_STD_SPEED_SCL_LC; + I2Cx->I2C_FSTD_SPKCNT.FSTD_SPKLEN = I2C_STD_SPEED_SPKLEN; + break; + + case I2C_SPEED_FAST: + I2Cx->I2C_FST_SCL_HCNT.FST_SCL_HCNT = I2C_FAST_SPEED_SCL_HC; + I2Cx->I2C_FST_SCL_LCNT.FST_SCL_LCNT = I2C_FAST_SPEED_SCL_LC; + I2Cx->I2C_FSTD_SPKCNT.FSTD_SPKLEN = I2C_FAST_SPEED_SPKLEN; + break; + + case I2C_SPEED_HIGH: + I2Cx->I2C_HS_SCL_HCNT.HS_SCL_HCNT = I2C_HIGH_SPEED_SCL_HC; + I2Cx->I2C_HS_SCL_LCNT.HS_SCL_LCNT = I2C_HIGH_SPEED_SCL_LC; + I2Cx->I2C_HS_SPKCNT.HS_SPKLEN = I2C_HIGH_SPEED_SPKLEN; + break; + + case I2C_SPEED_FAST_PLUS: + I2Cx->I2C_FST_SCL_HCNT.FST_SCL_HCNT = I2C_FAST_PLUS_SPEED_SCL_HC; + I2Cx->I2C_FST_SCL_LCNT.FST_SCL_LCNT = I2C_FAST_PLUS_SPEED_SCL_LC; + I2Cx->I2C_FSTD_SPKCNT.FSTD_SPKLEN = I2C_FAST_PLUS_SPEED_SPKLEN; + break; + + default: + /* Do nothing */ + break; + } + + /* Set the I2C master or slave mode */ + if(I2C_MASTER == i2cConfigStruct->masterSlaveMode) + { + /* Disable slave */ + I2Cx->I2C_CONFIG1.SLAVE_MODE_DIS = 1U; + /* Enable master */ + I2Cx->I2C_CONFIG1.MASTER_MODE_EN = 1U; + /* Set I2C start its transfer in 7 or 10 bits address mode */ + I2Cx->I2C_CONFIG1.MASTER_10BIT_ADDR_SEL = + (uint32_t)(i2cConfigStruct->addrBitMode); + /* Set whether RESTART conditions may be sent */ + I2Cx->I2C_CONFIG1.MASTER_RESTART_EN = + ((ENABLE == i2cConfigStruct->restart)? 1UL : 0UL); + } + else + { + /* Enable slave */ + I2Cx->I2C_CONFIG1.SLAVE_MODE_DIS = 0U; + /* Disable master */ + I2Cx->I2C_CONFIG1.MASTER_MODE_EN = 0U; + /* Set I2C slave address mode */ + I2Cx->I2C_CONFIG1.SLAVE_10BIT_ADDR_SEL = + (uint32_t)(i2cConfigStruct->addrBitMode); + /* Set I2C slave address */ + I2Cx->I2C_SLAVE_ADDR.SLV_ADDR = i2cConfigStruct->ownSlaveAddr; + } +} + +/** + * @brief Configure SCL High Count + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] speedMode: Speed mode types. + * - I2C_SPEED_STANDARD:I2C standard speed define.(0 to 100 Kb/s) + * - I2C_SPEED_FAST:I2C fast speed define.(up to 400 Kb/s) + * - I2C_SPEED_HIGH:I2C high speed define.(up to 1.6 Mb/s) + * - I2C_SPEED_FAST_PLUS:I2C fast mode plus define.(up to 1000 Kb/s) + * + * @return none + * + */ +void I2C_SclHighCount(I2C_Id_t i2cId, I2C_Speed_t speedMode) +{ + i2c_reg_t * I2Cx = (i2c_reg_t *)(i2cRegPtr[i2cId]); + I2Cx->I2C_CONFIG1.SPEED_SEL = (uint32_t)speedMode&0x3U; + switch(speedMode) + { + case I2C_SPEED_STANDARD: + I2Cx->I2C_STD_SCL_HCNT.STD_SCL_HCNT = I2C_STD_SPEED_SCL_HC; + break; + + case I2C_SPEED_FAST: + I2Cx->I2C_FST_SCL_HCNT.FST_SCL_HCNT = I2C_FAST_SPEED_SCL_HC; + break; + + case I2C_SPEED_HIGH: + I2Cx->I2C_HS_SCL_HCNT.HS_SCL_HCNT = I2C_HIGH_SPEED_SCL_HC; + break; + + case I2C_SPEED_FAST_PLUS: + I2Cx->I2C_FST_SCL_HCNT.FST_SCL_HCNT = I2C_FAST_PLUS_SPEED_SCL_HC; + break; + + default: + /* Do nothing */ + break; + } +} + +/** + * @brief Configure SCL Low Count + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] speedMode: Speed mode types. + * - I2C_SPEED_STANDARD:I2C standard speed define.(0 to 100 Kb/s) + * - I2C_SPEED_FAST:I2C fast speed define.(up to 400 Kb/s) + * - I2C_SPEED_HIGH:I2C high speed define.(up to 1.6 Mb/s) + * - I2C_SPEED_FAST_PLUS:I2C fast mode plus define.(up to 1000 Kb/s) + * + * @return none + * + */ +void I2C_SclLowCount(I2C_Id_t i2cId, I2C_Speed_t speedMode) +{ + i2c_reg_t * I2Cx = (i2c_reg_t *)(i2cRegPtr[i2cId]); + I2Cx->I2C_CONFIG1.SPEED_SEL = (uint32_t)speedMode&0x3U; + switch(speedMode) + { + case I2C_SPEED_STANDARD: + I2Cx->I2C_STD_SCL_LCNT.STD_SCL_LCNT = I2C_STD_SPEED_SCL_LC; + break; + + case I2C_SPEED_FAST: + I2Cx->I2C_FST_SCL_LCNT.FST_SCL_LCNT = I2C_FAST_SPEED_SCL_LC; + break; + + case I2C_SPEED_HIGH: + I2Cx->I2C_HS_SCL_LCNT.HS_SCL_LCNT = I2C_HIGH_SPEED_SCL_LC; + break; + + case I2C_SPEED_FAST_PLUS: + I2Cx->I2C_FST_SCL_LCNT.FST_SCL_LCNT = I2C_FAST_PLUS_SPEED_SCL_LC; + break; + + default: + /* Do nothing */ + break; + } +} + +/** + * @brief Configure Spike Suppression Limit + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] speedMode: Speed mode types. + * - I2C_SPEED_STANDARD:I2C standard speed define.(0 to 100 Kb/s) + * - I2C_SPEED_FAST:I2C fast speed define.(up to 400 Kb/s) + * - I2C_SPEED_HIGH:I2C high speed define.(up to 1.6 Mb/s) + * - I2C_SPEED_FAST_PLUS:I2C fast mode plus define.(up to 1000 Kb/s) + * + * @return none + * + */ +void I2C_LimitSpikeSuppression(I2C_Id_t i2cId, I2C_Speed_t speedMode) +{ + i2c_reg_t * I2Cx = (i2c_reg_t *)(i2cRegPtr[i2cId]); + I2Cx->I2C_CONFIG1.SPEED_SEL = (uint32_t)speedMode&0x3U; + switch(speedMode) + { + case I2C_SPEED_STANDARD: + I2Cx->I2C_FSTD_SPKCNT.FSTD_SPKLEN = I2C_STD_SPEED_SPKLEN; + break; + + case I2C_SPEED_FAST: + I2Cx->I2C_FSTD_SPKCNT.FSTD_SPKLEN = I2C_FAST_SPEED_SPKLEN; + break; + + case I2C_SPEED_HIGH: + I2Cx->I2C_HS_SPKCNT.HS_SPKLEN = I2C_HIGH_SPEED_SPKLEN; + break; + + case I2C_SPEED_FAST_PLUS: + I2Cx->I2C_FSTD_SPKCNT.FSTD_SPKLEN = I2C_FAST_PLUS_SPEED_SPKLEN; + break; + + default: + /* Do nothing */ + break; + } +} +/** + * @brief Set the target address . + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] targetAddr: The target address for any master transaction. + * + * @return none + * + */ +void I2C_SetTargetAddr(I2C_Id_t i2cId, uint32_t targetAddr) +{ + i2c_reg_t * I2Cx = (i2c_reg_t *)(i2cRegPtr[i2cId]); + + /* Set the target address */ + I2Cx->I2C_DEST_ADDR.DEST_ADDR = targetAddr; +} + +/** + * @brief Set the value of the I2C high speed mode master code + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] value: High speed master mode code . + * + * @return none + * + */ +void I2C_SetMasterModeCodeAddr(I2C_Id_t i2cId, uint32_t value) +{ + i2c_reg_t * I2Cx = (i2c_reg_t *)(i2cRegPtr[i2cId]); + + /* Set the value of the I2C high speed mode master code */ + I2Cx->I2C_CONFIG0.H_MCODE = value; +} + +/** + * @brief Issues the STOP_DETECT interrupt if addressed in slave mode + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] stopDetAddressedType: Specified types. + * - I2C_SLV_STOP_DET_WHE_ADDRESSED:I2C issues the STOP_DETECT + * irrespective of whether it is addressed or not. + * - I2C_SLV_STOP_DEF_ADDRESSED:I2C issues the STOP_DETECT interrupt + * only when it is addressed. + * + * @return none + * + */ +void I2C_StopDetIfAddressed(I2C_Id_t i2cId, + I2C_StopDetAddressed_t stopDetAddressedType) +{ + i2c_reg_t * I2Cx = (i2c_reg_t *)(i2cRegPtr[i2cId]); + + I2Cx->I2C_CONFIG1.SLAVE_STOP_DET_EN = (uint32_t)stopDetAddressedType; +} + +/** + * @brief Issues the STOP_DETECT interrupt if master active + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] stopDetMstActiveType: Specified types. + * - I2C_MST_STOP_DET_WHE_ACTIVE: I2C issues the STOP_DETECT + * irrespective of whether the master is active. + * - I2C_MST_STOP_DEF_ACTIVE: I2C issues the STOP_DETECT interrupt + * only when the master is active. + * + * @return none + * + */ +void I2C_StopDetIfMstActive(I2C_Id_t i2cId, + I2C_StopDetActive_t stopDetMstActiveType) +{ + i2c_reg_t * I2Cx = (i2c_reg_t *)(i2cRegPtr[i2cId]); + + I2Cx->I2C_CONFIG1.MASTER_STOP_DET_EN = (uint32_t)stopDetMstActiveType; +} + +/** + * @brief Control the generation of the TXFIFO_EMPTY interrupt, + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] txEmptyType: Specified tx empty type. + * - I2C_TX_BUFFER: transmit buffer is at or below the threshold + * value set in the TXFIFO_WATER_MARK register. + * - I2C_TX_DATA_PATH: transmit buffer is at or below the threshold + * value set in the TXFIFO_WATER_MARK register and the transmission + * of the address/data from the internal shift register for the + * most recently popped command is completed. + * + * @return none + * + */ +void I2C_TxEmptyCtrl(I2C_Id_t i2cId, I2C_TxEmptyCtrl_t txEmptyType) +{ + i2c_reg_t * I2Cx = (i2c_reg_t *)(i2cRegPtr[i2cId]); + + I2Cx->I2C_CONFIG1.TXFIFO_EMPTY_EN = (uint32_t)txEmptyType; +} + +/** + * @brief Control whether I2C module should hold the bus when the Rx FIFO + * is physically full to its RXFIFO_DEPTH + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] newState: Enable/Disable function state. + * - ENABLE: Hold the bus when the Rx FIFO is physically full to its + * RXFIFO_DEPTH. + * - DISABLE: When Rx FIFO's RXFIFO_DEPTH is physically full, + * the bus is not hold. + * + * @return none + * + */ +void I2C_HoldBusCmd(I2C_Id_t i2cId, ControlState_t newState) +{ + i2c_reg_t * I2Cx = (i2c_reg_t *)(i2cRegPtr[i2cId]); + + I2Cx->I2C_CONFIG1.HOLD_EN_RXFIFO_FULL = (uint32_t)newState; +} + +/** + * @brief Initializes the I2C DMA + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] i2cDmaConfig: Pointer to a I2C DMA configuration structure. + * + * @return none + * + */ +void I2C_DmaConfig(I2C_Id_t i2cId, const I2C_DmaConfig_t* i2cDmaConfig) +{ + i2c_reg_t * I2Cx = (i2c_reg_t *)(i2cRegPtr[i2cId]); + /* Set Transmit data level */ + I2Cx->I2C_DMA_CTRL.DMA_TXFIFO_WATERMARK = + i2cDmaConfig->I2C_DMA_TransmitReqLevel; + /* Set Receive data level */ + I2Cx->I2C_DMA_CTRL.DMA_RXFIFO_WATERMARK = + i2cDmaConfig->I2C_DMA_RecvReqLevel; +} + +/** + * @brief Enable/disable I2C DMA function. + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] transmitDmaCtrl: Transmit DMA Enable/Disable function state. + * @param[in] rcvDmaCtrl: Receive DMA Enable/Disable function state. + * + * @return none + * + */ +void I2C_DmaCmd(I2C_Id_t i2cId, ControlState_t transmitDmaCtrl, + ControlState_t rcvDmaCtrl) +{ + i2c_reg_t * I2Cx = (i2c_reg_t *)(i2cRegPtr[i2cId]); + /* Enable/Disable the I2C DMA transmit function */ + I2Cx->I2C_DMA_CTRL.TXFIFO_DMA_EN = (uint32_t)transmitDmaCtrl; + /* Enable/Disable the I2C DMA receive function */ + I2Cx->I2C_DMA_CTRL.RXFIFO_DMA_EN = (uint32_t)rcvDmaCtrl; +} + +/** + * @brief Set I2C SDA Transmit hold time + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] i2cSdaTxHoldTime: Pointer to a I2C SDA Tx hold time structure. + * + * @return none + * + */ +void I2C_SetSdaTxHoldTime(I2C_Id_t i2cId, + const I2C_SdaHoldTime_t* i2cSdaTxHoldTime) +{ + i2c_reg_t * I2Cx = (i2c_reg_t *)(i2cRegPtr[i2cId]); + + I2Cx->I2C_SDA_HOLD_TIMING.SDA_TX_HOLD_TIMING = + i2cSdaTxHoldTime->sdaTransmitHoldTime; +} + +/** + * @brief Set I2C SDA Receive hold time + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] i2cSdaRxHoldTime: Pointer to a I2C SDA Rx hold time structure. + * + * @return none + * + */ +void I2C_SetSdaRxHoldTime(I2C_Id_t i2cId, + const I2C_SdaHoldTime_t* i2cSdaRxHoldTime) +{ + i2c_reg_t * I2Cx = (i2c_reg_t *)(i2cRegPtr[i2cId]); + + I2Cx->I2C_SDA_HOLD_TIMING.SDA_RX_HOLD_TIMING = + i2cSdaRxHoldTime->sdaReceiveHoldTime; +} + +/** + * @brief SCL stuck at low timeout + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] time: SCL stuck at low time of duration. + * I2C module generates the SCL_STUCK_AT_LOW interrupt to indicate + * SCL stuck at low if it detects the SCL stuck at low for the + * I2C_SCL_LOW_TIMEOUT in units of I2C function clock period. + * + * @return none + * + */ +void I2C_SetSclHoldLowTimeout(I2C_Id_t i2cId, uint32_t timeOut) +{ + i2c_reg_t * I2Cx = (i2c_reg_t *)(i2cRegPtr[i2cId]); + + I2Cx->I2C_SCL_LOW_TIMEOUT.SCL_LOW_TIMEOUT = timeOut; +} + +/** + * @brief SDA stuck at low timeout + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] time: SDA stuck at low time of duration. + * I2C module initiates the recovery of SDA line through enabling + * the SDA_RECOVER_EN bit if it detects the SDA stuck at low for the + * I2C_SDA_LOW_TIMEOUT in units of I2C function clock period. + * + * @return none + * + */ +void I2C_SetSdaHoldLowTimeout(I2C_Id_t i2cId, uint32_t timeOut) +{ + i2c_reg_t * I2Cx = (i2c_reg_t *)(i2cRegPtr[i2cId]); + + I2Cx->I2C_SDA_LOW_TIMEOUT.SDA_LOW_TIMEOUT = timeOut; +} + +/** + * @brief Enable I2C . + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * + * @return none + * + */ +void I2C_Enable(I2C_Id_t i2cId) +{ + i2c_reg_t * I2Cx = (i2c_reg_t *)(i2cRegPtr[i2cId]); + + /* Enable the I2C */ + I2Cx->I2C_CONFIG0.MODULE_EN = 1U; +} + +/** + * @brief Disable I2C . + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * + * @return none + * + */ +void I2C_Disable(I2C_Id_t i2cId) +{ + i2c_reg_t * I2Cx = (i2c_reg_t *)(i2cRegPtr[i2cId]); + + /* Disable the I2C */ + I2Cx->I2C_CONFIG0.MODULE_EN = 0U; +} + +/** + * @brief I2C bus recover feature in master mode + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] newState: Enable/Disable function state. + * - ENABLE: Means bus recover feature is enable. + * - DISABLE: Means bus recover feature is disabled. + * + * @return none + * + */ +void I2C_MstBusRecover(I2C_Id_t i2cId, ControlState_t newState) +{ + i2c_reg_t * I2Cx = (i2c_reg_t *)(i2cRegPtr[i2cId]); + + I2Cx->I2C_CONFIG0.MASTER_BUS_RECOVER_EN = (uint32_t)newState; +} + +/** + * @brief I2C SDA recover feature + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] newState: Enable/Disable function state. + * - ENABLE: Means SDA recover feature is enable. + * - DISABLE: Means SDA recover feature is disabled. + * + * @return none + * + */ +void I2C_SdaRecover(I2C_Id_t i2cId, ControlState_t newState) +{ + i2c_reg_t * I2Cx = (i2c_reg_t *)(i2cRegPtr[i2cId]); + + I2Cx->I2C_CONFIG0.SDA_RECOVER_EN = (uint32_t)newState; +} + +/** + * @brief Block or not block the transmission of data on I2C bus + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] newState: Enable/Disable function state. + * - ENABLE: Blocks the transmission of data on I2C bus even if + * Tx FIFO has data to transmit. + * - DISABLE: The transmission of data starts on I2C bus automatically, + * as soon as the first data is available in the Tx FIFO. + * + * @return none + * + */ +void I2C_TxCmdBlock(I2C_Id_t i2cId, ControlState_t newState) +{ + i2c_reg_t * I2Cx = (i2c_reg_t *)(i2cRegPtr[i2cId]); + + I2Cx->I2C_CONFIG0.MASTER_BLK_TXFIFO = (uint32_t)newState; +} + +/** + * @brief Enable/Disable transfer abort. + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] newState: Enable/Disable function state. + * - ENABLE: ABORT operation in progress. + * - DISABLE: ABORT not initiated or ABORT done. + * + * @return none + * + */ +void I2C_TxAbortCmd(I2C_Id_t i2cId, ControlState_t newState) +{ + i2c_reg_t * I2Cx = (i2c_reg_t *)(i2cRegPtr[i2cId]); + + I2Cx->I2C_CONFIG0.MASTER_ABORT = (uint32_t)newState; +} + +/** + * @brief Configurate the FIFO threshold level. + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] fifoConfig: Pointer to FIFO type structure. + * + * @return none + * + */ +void I2C_FIFOConfig(I2C_Id_t i2cId, const I2C_FifoConfig_t* fifoConfig) +{ + i2c_reg_t * I2Cx = (i2c_reg_t *)(i2cRegPtr[i2cId]); + + /* Set Receive FIFO threshold level */ + I2Cx->I2C_RXFIFO_WATER_MARK.RXFIFO_WATER_MARK = fifoConfig->recvFifoThr; + /* Set Transmit FIFO threshold level */ + I2Cx->I2C_TXFIFO_WATER_MARK.TXFIFO_WATER_MARK = fifoConfig->transmitFifoThr; +} + +/** + * @brief Get transmit FIFO level + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * + * @return The number of valid data entries in the transmit FIFO memory. + * + */ +uint32_t I2C_GetTxFifoLevel(I2C_Id_t i2cId) +{ + i2c_reg_t * I2Cx = (i2c_reg_t *)(i2cRegPtr[i2cId]); + + return (I2Cx->I2C_TX_FIFO_CNT.TX_FIFO_CNT); +} + +/** + * @brief Get receive FIFO level + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * + * @return The number of valid data entries in the receive FIFO memory. + * + */ +uint32_t I2C_GetRxFifoLevel(I2C_Id_t i2cId) +{ + i2c_reg_t * I2Cx = (i2c_reg_t *)(i2cRegPtr[i2cId]); + + return (I2Cx->I2C_RX_FIFO_CNT.RX_FIFO_CNT); +} + +/** + * @brief I2C master selects transfer address function. + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] transAddrType:transfer address types + * - I2C_DEST_ADDR + * - I2C_GEN_CALL_ADDR + * - I2C_START_BYTE + * + * @return none + * + */ +void I2C_MstCmdSelect(I2C_Id_t i2cId, I2C_MstCmdSelect_t transAddrType) +{ + i2c_reg_t * I2Cx = (i2c_reg_t *)(i2cRegPtr[i2cId]); + + I2Cx->I2C_DEST_ADDR.MASTER_CMD_SEL = (uint32_t)transAddrType; +} + +/** + * @brief Enable/disable I2C general call ack function. + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] newState: Enable/Disable function state. + * - ENABLE: I2C responses with a ACK when it receives a general call. + * - Disable: No ACK the general call and doesn't generate general + * call interrupt. + * + * @return none + * + */ +void I2C_GeneralCallAckCmd(I2C_Id_t i2cId, ControlState_t newState) +{ + i2c_reg_t * I2Cx = (i2c_reg_t *)(i2cRegPtr[i2cId]); + + /* Set general call ACK function */ + I2Cx->I2C_CONFIG0.SLAVE_ACK_GENCALL = (uint32_t)newState; +} + +/** + * @brief Generate a NACK for the data part of a transfer when i2c is + * acting as a slave receiver + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] genNack: general call ACK/NACK type. + * - I2C_GEN_NACK_AFTER_RCV:I2C generates NACK after data byte received. + * - I2C_GEN_NACK_OR_ACK_NORMAL:I2C generates NACK/ACK normally. + * + * @return none + * + */ +void I2C_SlvDataNackGen(I2C_Id_t i2cId, I2C_GenSlvDataNack_t genNack) +{ + i2c_reg_t * I2Cx = (i2c_reg_t *)(i2cRegPtr[i2cId]); + + /* Generate a NACK for the data part of a transfer */ + I2Cx->I2C_CONFIG0.SLAVE_NACK = (uint32_t)genNack; +} + +/** + * @brief Send one byte when i2c as a master. + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] restartStopType: Specified restart,Stop type. + * - I2C_RESTART_AND_STOP_DISABLE + * - I2C_STOP_EN + * - I2C_RESTART_EN + * @param[in] data: The data to be send. + * + * @return none + * + */ +void I2C_MasterSendByte(I2C_Id_t i2cId, I2C_RestartStop_t restartStopType, + uint8_t data) +{ + i2c_reg_w_t * I2Cxw = (i2c_reg_w_t *)(i2cRegWPtr[i2cId]); + + /* Send one byte */ + I2Cxw->I2C_COMMAND_DATA = (((uint32_t)(restartStopType) << 0x9UL) | + ((uint32_t)data)); +} + +/** + * @brief Send one byte when i2c as a slave. + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * + * @param[in] data: The data to be send. + * + * @return none + * + */ +void I2C_SlaveSendByte(I2C_Id_t i2cId, uint8_t data) +{ + i2c_reg_w_t * I2Cxw = (i2c_reg_w_t *)(i2cRegWPtr[i2cId]); + + /* Send one byte */ + I2Cxw->I2C_COMMAND_DATA = ((uint32_t)data); +} + +/** + * @brief Master read/write request. + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] restartStopType: Specified restart,Stop type. + * - I2C_RESTART_AND_STOP_DISABLE + * - I2C_STOP_EN + * - I2C_RESTART_EN + * + * @return none + * + */ +void I2C_MasterReadCmd(I2C_Id_t i2cId, I2C_RestartStop_t restartStopType) +{ + i2c_reg_w_t * I2Cxw = (i2c_reg_w_t *)(i2cRegWPtr[i2cId]); + + /* Set read command */ + I2Cxw->I2C_COMMAND_DATA = + ((uint32_t)(restartStopType) << 0x9UL) | (0x100UL); +} + +/** + * @brief I2C read one byte . + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * + * @return The received data + * + */ +uint8_t I2C_ReceiveByte(I2C_Id_t i2cId) +{ + i2c_reg_w_t * I2Cxw = (i2c_reg_w_t *)(i2cRegWPtr[i2cId]); + + /* Read one byte */ + return ((uint8_t)(I2Cxw->I2C_COMMAND_DATA & 0xFFUL)); +} + +/** + * @brief Set sda setup time when i2c is acting as a slave receiver. + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] length: The length of setup time is calculated using + * [(SDA_SETUP_TIMING - 1) * (i2c function clock period)]. + * + * @return none + * + */ +void I2C_SetSdaSetupTime(I2C_Id_t i2cId, uint8_t length) +{ + i2c_reg_t * I2Cx = (i2c_reg_t *)(i2cRegPtr[i2cId]); + + /* SDA steup time */ + I2Cx->I2C_SDA_SETUP_TIMING.SDA_SETUP_TIMING = ((uint32_t)length); +} + +/** + * @brief Enable/Disable specified interrupt type + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] intType: Specified interrupt type. + * - I2C_INT_GEN_CALL + * - I2C_INT_TX_OVER + * - I2C_INT_ERROR_ABORT + * - I2C_INT_ACTIVITY + * - I2C_INT_STOP_DET + * - I2C_INT_START_DET + * - I2C_INT_RD_REQ + * - I2C_INT_RX_DONE + * - I2C_INT_RX_UNDER + * - I2C_INT_RX_OVER + * - I2C_INT_RESTART_DET + * - I2C_SCL_STUCK_AT_LOW + * - I2C_INT_RX_FULL + * - I2C_INT_TX_EMPTY + * - I2C_INT_ALL + * + * @param[in] newState: Interrupt enable/disable type. + * - ENABLE: enable interrupt + * - DISABLE: disable interrupt + * + * @return none + * + */ +void I2C_IntCmd(I2C_Id_t i2cId, I2C_INT_t intType, ControlState_t newState) +{ + i2c_reg_w_t * I2Cxw = (i2c_reg_w_t *)(i2cRegWPtr[i2cId]); + + if(DISABLE == newState ) + { + I2Cxw->I2C_INT_ENABLE &= (~i2cIntEnableTable[intType]); + } + else + { + I2Cxw->I2C_INT_ENABLE |= i2cIntEnableTable[intType]; + } +} + +/** + * @brief Check whether interrupt status flag is set or not for given + * interrupt type + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] intType: Specified interrupt type. + * - I2C_INT_GEN_CALL + * - I2C_INT_TX_OVER + * - I2C_INT_ERROR_ABORT + * - I2C_INT_ACTIVITY + * - I2C_INT_STOP_DET + * - I2C_INT_START_DET + * - I2C_INT_RD_REQ + * - I2C_INT_RX_DONE + * - I2C_INT_RX_UNDER + * - I2C_INT_RX_OVER + * - I2C_INT_RESTART_DET + * - I2C_SCL_STUCK_AT_LOW + * - I2C_INT_RX_FULL + * - I2C_INT_TX_EMPTY + * + * @return The status flag of interrupt status register. + * - SET + * - RESET + * + */ +FlagStatus_t I2C_GetIntStatus(I2C_Id_t i2cId, I2C_INT_t intType) +{ + uint32_t intBitStatus; + const uint32_t i2cIntTable[]= + { + 0U, 1U, 2U, 3U, 4U, 5U, 22U, 23U, 24U, 25U, 26U, 27U, 30U, 31U + }; + i2c_reg_w_t * I2Cxw = (i2c_reg_w_t *)(i2cRegWPtr[i2cId]); + + intBitStatus = (((I2Cxw->I2C_STATUS0) & + (0x01UL << (uint32_t)i2cIntTable[intType])) >> + (uint32_t)i2cIntTable[intType]); + + return (FlagStatus_t)intBitStatus; +} + +/** + * @brief Check whether error status flag is set or not + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] errorType: Specified abort type. + * - ERR_GEN_CALL_NO_ACK + * - ERR_GEN_CALL_READ + * - ERR_START_BYTE_ACK_DET + * - ERR_SBYTE_NORSTRT + * - ERR_H_NO_RSTRT + * - ERR_H_MCODE_ACK_DET + * - ERR_7BIT_ADDR_NO_ACK + * - ERR_10BIT_ADDR1_NO_ACK + * - ERR_10BIT_ADDR2_NO_ACK + * - ERR_10BIT_READ_NO_RSTRT + * - ERR_DATA_NO_ACK + * - ERR_MASTER_ABRT + * - ERR_MASTER_DIS + * - ERR_SLAVE_ARBLOST + * - ERR_MASTER_LOST + * - ERR_SLAVE_READ_REQ + * - ERR_SLAVE_FLUSH_TXFIFO + * - ERR_SDA_LOW_TIMEOUT + * + * @return The status flag of error status register. + * - SET + * - RESET + * + */ +FlagStatus_t I2C_GetErrorStatus(I2C_Id_t i2cId, I2C_ErrorStatus_t errorType) +{ + uint32_t bitStatus; + i2c_reg_w_t * I2Cxw = (i2c_reg_w_t *)(i2cRegWPtr[i2cId]); + bitStatus = (((I2Cxw->I2C_ERROR_STATUS) & + (0x01UL <<(uint32_t)errorType)) >> (uint32_t)errorType); + return (FlagStatus_t)bitStatus; +} + +/** + * @brief Clear specified interrupt type + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] intType: Specified interrupt type. + * - I2C_INT_GEN_CALL + * - I2C_INT_TX_OVER + * - I2C_INT_ERROR_ABORT + * - I2C_INT_ACTIVITY + * - I2C_INT_STOP_DET + * - I2C_INT_START_DET + * - I2C_INT_RD_REQ + * - I2C_INT_RX_DONE + * - I2C_INT_RX_UNDER + * - I2C_INT_RX_OVER + * - I2C_INT_RESTART_DET + * - I2C_SCL_STUCK_AT_LOW + * - I2C_INT_ALL + * + * @return none + * + */ +void I2C_ClearInt(I2C_Id_t i2cId, I2C_INT_t intType) +{ + i2c_reg_w_t * I2Cxw = (i2c_reg_w_t *)(i2cRegWPtr[i2cId]); + + I2Cxw->I2C_STATUS0 = i2cIntEnableTable[intType]; +} + +/** + * @brief Clear all error status . + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * + * @return none + * + */ +void I2C_ClearErrorStatusAll(I2C_Id_t i2cId) +{ + i2c_reg_t * I2Cx = (i2c_reg_t *)(i2cRegPtr[i2cId]); + + volatile uint32_t dummyData; + /* Dummy read to clear all error status */ + dummyData = I2Cx->I2C_RD_CLR_ERR_STATUS.CLR_ERR; +} + +/** + * @brief The number of Tx FIFO data Master-Transmitter commands that + * are flushed due to ERROR_ABORT or SlaveTransmitter interrupt. + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * + * @return The error flush count. + * + */ +uint32_t I2C_ErrorFlushCount(I2C_Id_t i2cId) +{ + i2c_reg_t * I2Cx = (i2c_reg_t *)(i2cRegPtr[i2cId]); + + return I2Cx->I2C_ERROR_STATUS.ERR_TXFIFO_FLUSH_CNT; +} + +/** + * @brief Check whether status flag is set or not for given status type + * + * @param[in] i2cId: Select the I2C id, should be I2C0_ID, I2C1_ID. + * @param[in] statusType: Specified status type. + * - I2C_MST_ACTIVITY + * - I2C_SLV_ACTIVITY + * - I2C_TXFIFO_EMPTY_MASTER_HOLD + * - I2C_TXFIFO_EMPTY_SLAVE_HOLD + * - I2C_RXFIFO_FULL_MASTER_HOLD + * - I2C_RXFIFO_FULL_SLAVE_HOLD + * - I2C_STATUS_TFNF + * - I2C_STATUS_TFE, + * - I2C_STATUS_RFNE, + * - I2C_STATUS_RFF, + * - I2C_SDA_ERR_RECOVER_STUCK_LOW, + * - I2C_SLAVE_IS_DISABLED_UNDER_ACT + * - I2C_SLAVE_RX_DATA_DISCARD + * - I2C_ENABLE + * + * @return The status flag of spi status register. + * - SET + * - RESET + * + */ +FlagStatus_t I2C_GetStatus(I2C_Id_t i2cId, I2C_Status_t statusType) +{ + uint32_t bitStatus; + i2c_reg_w_t * I2Cxw = (i2c_reg_w_t *)(i2cRegWPtr[i2cId]); + bitStatus = (((I2Cxw->I2C_STATUS1) & + (0x01UL << (uint32_t)statusType)) >> (uint32_t)statusType); + return (FlagStatus_t)bitStatus; +} +/** @} end of group I2C_Public_Functions */ + +/** @} end of group I2C_definitions */ + +/** @} end of group Z20K11X_Peripheral_Driver */ diff --git a/StdDriver/Src/Z20K11xM_pmu.c b/StdDriver/Src/Z20K11xM_pmu.c new file mode 100644 index 0000000..2bac17b --- /dev/null +++ b/StdDriver/Src/Z20K11xM_pmu.c @@ -0,0 +1,277 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_pmu.c + * @brief : PMU module driver file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ + +#include "Z20K11xM_pmu.h" + +/** @addtogroup Z20K11X_Peripheral_Driver + * @{ + */ + +/** @defgroup PMU + * @brief PMU driver modules + * @{ + */ + +/** @defgroup PMU_Private_Type + * @{ + */ + +/*@} end of group PMU_Private_Type*/ + +/** @defgroup PMU_Private_Defines + * @{ + */ +/*PRQA S 0303 ++ */ +static pmu_reg_t *const pmuRegPtr = (pmu_reg_t *) PMU_BASE_ADDR; /*!< PMU Register */ +static pmu_reg_w_t *const pmuRegWPtr = (pmu_reg_w_t *) PMU_BASE_ADDR; /*!< PMU word Register */ +/*PRQA S 0303 -- */ + +#define PMU_UNLOCK (0x94730000U) +/*@} end of group PMU_Private_Defines */ + +/** @defgroup PMU_Private_Variables + * @{ + */ +static isr_cb_t * pmuIsrCb[PMU_INT_ALL]= {NULL,NULL}; + +static const uint32_t PMU_IntStatusTable[] = +{ + 0x00000040U, /*PMU_VDD_LVW_INT status mask*/ + 0x00000080U, /*PMU_VDD_LVD_INT status mask*/ + 0x000000C0U /*PMU_INT_ALL status mask*/ +}; + +static const uint32_t PMU_IntMaskTable[] = +{ + 0x00000020U, /*PMU_VDD_LVW_INT enable mask*/ + 0x00000004U, /*PMU_VDD_LVD_INT enable mask*/ + 0x00000024U /*PMU_INT_ALL enable mask*/ +}; + +/* The bit6/bit7 are for LVW/LVD int status with w1c attributes*/ +static uint32_t pmuIntMaskStatus = 0xffffff3fU; + +/*@} end of group PMU_Private_Variables */ + +/** @defgroup PMU_Global_Variables + * @{ + */ + +/*@} end of group PMU_Global_Variables */ + +/** @defgroup PMU_Private_FunctionDeclaration + * @{ + */ + +void PMU_DriverIRQHandler(void); + +/*@} end of group PMU_Private_FunctionDeclaration */ + +/** @defgroup PMU_Private_Functions + * @{ + */ + +/** + * @brief PMU IRQHandler + * + * @param[in] none + * + * @return none + * + */ +void PMU_DriverIRQHandler(void) +{ + uint32_t intStatus; + + /* get interrupt status */ + intStatus = pmuRegWPtr->PMU_VDD5V_CSR; + /* only check enabled interrupts */ + intStatus = intStatus & pmuIntMaskStatus; + /* clear interrupt status */ + pmuRegWPtr->PMU_VDD5V_CSR = intStatus; + + /* VDD 5V low voltage warning detect Interrupt */ + if((intStatus & PMU_IntStatusTable[PMU_VDD_LVW_INT]) != 0U) + { + if(pmuIsrCb[PMU_VDD_LVW_INT] != NULL) + { + /* call the callback function */ + pmuIsrCb[PMU_VDD_LVW_INT](); + } + /* Disable the interrupt if callback function is not setup */ + else + { + PMU_IntMask(PMU_VDD_LVW_INT, MASK); + } + } + + /* VDDA low voltage detect Interrupt */ + if((intStatus & PMU_IntStatusTable[PMU_VDD_LVD_INT]) != 0U) + { + if(pmuIsrCb[PMU_VDD_LVD_INT] != NULL) + { + /* call the callback function */ + pmuIsrCb[PMU_VDD_LVD_INT](); + } + /* Disable the interrupt if callback function is not setup */ + else + { + PMU_IntMask(PMU_VDD_LVD_INT, MASK); + } + } +} +/*@} end of group PMU_Private_Functions */ + +/** @defgroup PMU_Public_Functions + * @{ + */ + +/** + * @brief Clear Isolation status + * + * @return none + * + */ +void PMU_IsoClr(void) +{ + pmuRegWPtr->PMU_LOCK = PMU_UNLOCK; + pmuRegPtr->PMU_ISO_CLR.ISO_CLR = 1; + pmuRegPtr->PMU_LOCK.LOCK = 1U; +} + +/** + * @brief Enable/Disable PMU Relevant Voltage's Function + * + * @param[in] ctrlType: Select the PMU Control type defined in PMU_Ctrl_t. + * @param[in] cmd: Enable or Disable. + * + * @return none + * + */ +void PMU_Ctrl(PMU_Ctrl_t ctrlType, ControlState_t cmd) +{ + pmuRegWPtr->PMU_LOCK = PMU_UNLOCK; + switch(ctrlType) + { + case PMU_VDD_LVD_LP: + pmuRegPtr->PMU_VDD5V_CSR.VDD_LVD_LP_EN = (uint32_t)cmd; + break; + case PMU_VDD_LVD_ACT: + pmuRegPtr->PMU_VDD5V_CSR.VDD_LVD_ACT_EN = (uint32_t)cmd; + break; + case PMU_VDD_LVD_RE: + pmuRegPtr->PMU_VDD5V_CSR.VDD_LVD_RE = (uint32_t)cmd; + break; + case PMU_VDD_LVW: + pmuRegPtr->PMU_VDD5V_CSR.VDD_LVW_EN = (uint32_t)cmd; + break; + case PMU_REF_BUF_1V: + pmuRegPtr->PMU_VDD5V_CSR.REF_BUF_1V_EN = (uint32_t)cmd; + break; + default: + /*Do nothing*/ + break; + } + pmuRegPtr->PMU_LOCK.LOCK = 1U; + + return; +} + +/** + * @brief Pmu Get Status Function + * + * @param[in] intType: Int Type. + * + * @return status. + * + */ +FlagStatus_t PMU_GetIntStatus(PMU_Int_t intType) +{ + FlagStatus_t bitStatus; + + pmuRegWPtr->PMU_LOCK = PMU_UNLOCK; + + if((pmuRegWPtr->PMU_VDD5V_CSR & PMU_IntStatusTable[intType]) != 0U) + { + bitStatus = SET; + } + else + { + bitStatus = RESET; + } + + pmuRegPtr->PMU_LOCK.LOCK = 1U; + return bitStatus; +} + +/** + * @brief Mask/Unmask the Relevant Interrupt Function + * + * @param[in] intType: Select the interrupt type. + * @param[in] intMask: UNMASK or MASK. + * + * @return none + * + */ +void PMU_IntMask(PMU_Int_t intType, IntMask_t intMask) +{ + pmuRegWPtr->PMU_LOCK = PMU_UNLOCK; + + if(UNMASK == intMask) + { + pmuRegWPtr->PMU_VDD5V_CSR = pmuRegWPtr->PMU_VDD5V_CSR | PMU_IntMaskTable[intType]; + pmuIntMaskStatus = pmuIntMaskStatus | PMU_IntStatusTable[intType]; + } + else + { + pmuRegWPtr->PMU_VDD5V_CSR = pmuRegWPtr->PMU_VDD5V_CSR & (~PMU_IntMaskTable[intType]); + pmuIntMaskStatus = pmuIntMaskStatus & (~PMU_IntStatusTable[intType]); + } + + pmuRegPtr->PMU_LOCK.LOCK = 1U; +} + +/** + * @brief Clear the Relevant Interrupt Status + * + * @param[in] intType: Select the interrupt type. + * + * @return none + * + */ +void PMU_IntClr(PMU_Int_t intType) +{ + pmuRegWPtr->PMU_LOCK = PMU_UNLOCK; + pmuRegWPtr->PMU_VDD5V_CSR = pmuRegWPtr->PMU_VDD5V_CSR | PMU_IntStatusTable[intType]; + pmuRegPtr->PMU_LOCK.LOCK = 1U; +} + +/** + * @brief install call back function + * + * @param[in] intId: select the interrupt type + * @param[in] cbFun: pointer to callback function + * + * @return none + * + */ +void PMU_InstallCallBackFunc(PMU_Int_t intType,isr_cb_t * cbFun) +{ + pmuIsrCb[intType] = cbFun; +} + + +/*@} end of group PMU_Public_Functions */ + +/*@} end of group PMU_definitions */ + +/*@} end of group Z20K11X_Peripheral_Driver */ diff --git a/StdDriver/Src/Z20K11xM_regfile.c b/StdDriver/Src/Z20K11xM_regfile.c new file mode 100644 index 0000000..7b74a43 --- /dev/null +++ b/StdDriver/Src/Z20K11xM_regfile.c @@ -0,0 +1,135 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_regfile.c + * @brief : REGFILE module driver file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ + +#include "Z20K11xM_regfile.h" + +/** @addtogroup Z20K11X_Peripheral_Driver + * @{ + */ + +/** @defgroup REGFILE REGFILE + * @brief REGFILE driver modules + * @{ + */ + +/** @defgroup REGFILE_Private_Type + * @{ + */ + +/** @}end of group REGFILE_Private_Type*/ + +/** @defgroup REGFILE_Private_Defines + * @{ + */ + +#define REGFILE_TOTAL_NUMBER (32U) + +/** @}end of group REGFILE_Private_Defines */ + +/** @defgroup REGFILE_Private_Variables + * @{ + */ +static regfile_reg_w_t *const regfileRegWPtr = + (regfile_reg_w_t *)REGFILE_BASE_ADDR; /*PRQA S 0303*/ + +/** @}end of group REGFILE_Private_Variables */ + +/** @defgroup REGFILE_Global_Variables + * @{ + */ + +/** @}end of group REGFILE_Global_Variables */ + +/** @defgroup REGFILE_Private_FunctionDeclaration + * @{ + */ + + +/** @}end of group REGFILE_Private_FunctionDeclaration */ + +/** @defgroup REGFILE_Private_Functions + * @{ + */ + +/** @} end of group REGFILE_Private_Functions */ + +/** @defgroup REGFILE_Public_Functions + * @{ + */ + +/** + * @brief Write into the REGFILE by regID + * @param[in] regID: the regID of the regfile, the scope is [0-31] + * @param[in] data: the data to be written + * + * @return Write into the REGFILE Status: + * - SUCC: Operation is successful + * - ERR: Operation fails, input param is invalid + * + */ +ResultStatus_t REGFILE_WriteByRegID(uint8_t regID, uint32_t const * data) +{ + ResultStatus_t ret = ERR; + + if( regID >= REGFILE_TOTAL_NUMBER ) + { + ret = ERR; + } + else + { + if(NULL != data) + { + regfileRegWPtr->REGFILE_REGn[regID] = *data; + ret = SUCC; + } + else + { + ret = ERR; + } + } + + return ret; +} + +/** + * @brief Read from the REGFILE by regID + * @param[in] regID: the regID of the regfile, the scope is [0-31] + * @param[inout] data: the data to be read + * + * + * @return Read from the REGFILE Status: + * - SUCC: Operation is successful + * - ERR: Operation fails, input param is invalid + * + */ +ResultStatus_t REGFILE_ReadByRegID(uint8_t regID, uint32_t *data) +{ + ResultStatus_t ret = ERR; + + if( regID >= REGFILE_TOTAL_NUMBER ) + { + ret = ERR; + } + else + { + *data = regfileRegWPtr->REGFILE_REGn[regID]; + ret = SUCC; + } + + return ret; +} + +/** @}end of group REGFILE_Public_Functions */ + +/** @}end of group REGFILE_definitions */ + +/** @}end of group Z20K11X_Peripheral_Driver */ diff --git a/StdDriver/Src/Z20K11xM_rtc.c b/StdDriver/Src/Z20K11xM_rtc.c new file mode 100644 index 0000000..9fcf33f --- /dev/null +++ b/StdDriver/Src/Z20K11xM_rtc.c @@ -0,0 +1,752 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_rtc.c + * @brief : RTC module driver file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ + +#include "Z20K11xM_rtc.h" +#include "Z20K11xM_clock.h" + +/** @addtogroup Z20K11X_Peripheral_Driver + * @{ + */ + +/** @defgroup RTC RTC + * @brief RTC driver modules + * @{ + */ + +/** @defgroup RTC_Private_Type + * @{ + */ + +/** @} end of group RTC_Private_Type*/ + +/** @defgroup RTC_Private_Defines + * @{ + */ + +/** @} end of group RTC_Private_Defines */ + +/** @defgroup RTC_Private_Variables + * @{ + */ + +/** + * @brief RTC ISR callback function pointer array + */ +static isr_cb_t * rtcIsrCb[RTC_INT_ALL]= {NULL, NULL, NULL}; + +/*PRQA S 0303 ++*/ +static rtc_reg_w_t *const rtcRegWPtr = (rtc_reg_w_t *) RTC_BASE_ADDR; +static rtc_reg_t *const rtcRegPtr = (rtc_reg_t *) RTC_BASE_ADDR; +/*PRQA S 0303 --*/ + +static const uint32_t rtcInterruptMaskTable[] = +{ + 0x00000008U, /*!< RTC overflow interrupt */ + 0x00000010U, /*!< RTC alarm interrupt */ + 0x00000020U, /*!< RTC second interrupt */ + 0x00000038U /*!< RTC_INT_ALL */ +}; + +static const uint32_t rtcIntStatusTable[] = +{ + 0x00000080U, /*!< RTC overflow interrupt flag */ + 0x00000100U, /*!< RTC alarm interrupt flag */ + 0x00000800U, /*!< RTC second interrupt flag */ + 0x00000980U /*!< RTC_INT_ALL */ +}; + +static uint32_t rtcIntMaskStatus = 0; /*PRQA S 3218*/ + +/** @} end of group RTC_Private_Variables */ + +/** @defgroup RTC_Global_Variables + * @{ + */ + +/** @} end of group RTC_Global_Variables */ + + +/** @defgroup RTC_Private_FunctionDeclaration + * @{ + */ +static void RTC_IntHandler(void); +void RTC_DriverIRQHandler(void); + +/** @} end of group RTC_Private_FunctionDeclaration */ + +/** @defgroup RTC_Private_Functions + * @{ + */ + +/** + * @brief RTC interrupt handle + * + * @param[in] none + * + * @return none + * + */ +static void RTC_IntHandler(void) +{ + uint32_t intStatus; + + if(rtcRegPtr->RTC_LOCKR.LOCK != 0U) + { + rtcRegWPtr->RTC_LOCKR = 0x98670000U; + } + + /* get interrupt status */ + intStatus = rtcRegWPtr->RTC_CSR; + + /* make sure interrupt is enable */ + intStatus = intStatus & rtcIntMaskStatus; + + if((intStatus & rtcIntStatusTable[RTC_INT_ALARM]) != 0U) + { + /* clear interrupt status */ + rtcRegWPtr->RTC_MATCH_CNTR = 0xFFFFFFFFU; + + if(rtcIsrCb[RTC_INT_ALARM] != NULL) + { + rtcIsrCb[RTC_INT_ALARM](); + } + else + { + rtcRegPtr->RTC_IER.ALARM_IE = 0U; + } + } + + if((intStatus & rtcIntStatusTable[RTC_INT_OVERFLOW]) != 0U) + { + if(rtcIsrCb[RTC_INT_OVERFLOW] != NULL) + { + rtcIsrCb[RTC_INT_OVERFLOW](); + } + else + { + rtcRegPtr->RTC_IER.OVFLOW_IE = 0U; + } + } + + if((intStatus & rtcIntStatusTable[RTC_INT_SECOND]) != 0U) + { + /* clear interrupt status */ + rtcRegPtr->RTC_CSR.SECONDS_INT_FLAG = 1U; + if(rtcIsrCb[RTC_INT_SECOND] != NULL) + { + rtcIsrCb[RTC_INT_SECOND](); + } + else + { + rtcRegPtr->RTC_IER.SECONDS_IE = 0U; + } + } + + rtcRegPtr->RTC_LOCKR.LOCK = 0x1U; + +} + +/** @} end of group RTC_Private_Functions */ + +/** @defgroup RTC_Public_Functions + * @{ + */ + + /** + * @brief RTC enable functioin + * + * @param[in] none + * + * @return none + * + */ +void RTC_Enable(void) +{ + if(rtcRegPtr->RTC_LOCKR.LOCK != 0U) + { + rtcRegWPtr->RTC_LOCKR = 0x98670000U; + } + + rtcRegPtr->RTC_CSR.COUNT_EN = 1U; + + rtcRegPtr->RTC_LOCKR.LOCK = 0x1U; +} + + /** + * @brief RTC disable functioin + * + * @param[in] none + * + * @return none + * + */ +void RTC_Disable(void) +{ + if(rtcRegPtr->RTC_LOCKR.LOCK != 0U) + { + rtcRegWPtr->RTC_LOCKR = 0x98670000U; + } + + rtcRegPtr->RTC_CSR.COUNT_EN = 0U; + + rtcRegPtr->RTC_LOCKR.LOCK = 0x1U; +} + + /** + * @brief RTC internal analog OSC clock disable functioin + * + * @param[in] none + * + * @return none + * + */ +void RTC_OSCDisable(void) +{ + if(rtcRegPtr->RTC_LOCKR.LOCK != 0U) + { + rtcRegWPtr->RTC_LOCKR = 0x98670000U; + } + + rtcRegPtr->RTC_CSR.CRYSTAL_EN = 0U; + + rtcRegPtr->RTC_LOCKR.LOCK = 0x1U; +} + +/** + * @brief Software reset all rtc registers except sw_rst bit + * + * @param[in] none + * + * @return none + * + */ +void RTC_SWRest(void) +{ + if(rtcRegPtr->RTC_LOCKR.LOCK != 0U) + { + rtcRegWPtr->RTC_LOCKR = 0x98670000U; + } + + rtcRegPtr->RTC_CSR.SW_RST = 1U; + rtcRegPtr->RTC_CSR.SW_RST = 0U; + rtcRegPtr->RTC_LOCKR.LOCK = 0x1U; +} + +/** + * @brief config whether write access to RTC in non-supervisor + * + * @param[in] cmd: ENABLE/DISABLE + * + * @return none + * + */ +void RTC_SupModeConfig(ControlState_t cmd) +{ + if(rtcRegPtr->RTC_LOCKR.LOCK != 0U) + { + rtcRegWPtr->RTC_LOCKR = 0x98670000U; + } + + rtcRegPtr->RTC_CSR.SUP_EN = (uint32_t)cmd; + rtcRegPtr->RTC_LOCKR.LOCK = 0x1U; +} + +/** + * @brief config second interrupt mux function + * + * @param[in] muxSel: select frequency to generate second frequency + * + * @return none + * + */ +void RTC_FreqMuxConfig(RTC_SecondIntMuxSel_t muxSel) +{ + if(rtcRegPtr->RTC_LOCKR.LOCK != 0U) + { + rtcRegWPtr->RTC_LOCKR = 0x98670000U; + } + + rtcRegPtr->RTC_IER.SECONDS_IE = 0U; + rtcRegPtr->RTC_IER.SECOND_INT_MUX_SEL = (uint32_t)muxSel; + + rtcRegPtr->RTC_LOCKR.LOCK = 0x1U; +} + +/** + * @brief Config RTC clcok source + * + * @param[in] config:config clock output + * + * @return none + * + */ +void RTC_OutputConfig(RTC_OutputConfig_t const * config) +{ + if(rtcRegPtr->RTC_LOCKR.LOCK != 0U) + { + rtcRegWPtr->RTC_LOCKR = 0x98670000U; + } + + rtcRegPtr->RTC_CSR.CLKOUT_SEL = (uint32_t)config->clkOutput; + rtcRegPtr->RTC_IER.SECOND_INT_MUX_SEL = (uint32_t)config -> freqSel; + + rtcRegPtr->RTC_LOCKR.LOCK = 0x1U; +} + +/** + * @brief Enable RTC output clock function after configure output + * + * @param[in] none + * + * @return none + * + */ +void RTC_OutputEnable(void) +{ + if(rtcRegPtr->RTC_LOCKR.LOCK != 0U) + { + rtcRegWPtr->RTC_LOCKR = 0x98670000U; + } + + rtcRegPtr->RTC_CSR.CLKOUT_PIN_EN = 0x1U; + + rtcRegPtr->RTC_LOCKR.LOCK = 0x1U; +} + +/** + * @brief Disable RTC output clock function + * + * @param[in] none + * + * @return none + * + */ +void RTC_OutputDisable(void) +{ + if(rtcRegPtr->RTC_LOCKR.LOCK != 0U) + { + rtcRegWPtr->RTC_LOCKR = 0x98670000U; + } + + rtcRegPtr->RTC_CSR.CLKOUT_PIN_EN = 0U; + + rtcRegPtr->RTC_LOCKR.LOCK = 0x1U; +} + +/** + * @brief Select clock source function, suggest select clock source before + * enable RTC clock + * + * @param[in] clockSource:RTC clock source + * + * @return + * -SUCC:clock config is success + * -ERR:clock config is fail + * + */ +ResultStatus_t RTC_ClkConfig(RTC_Clk_t clockSource) +{ + ResultStatus_t ret = ERR; + if(rtcRegPtr->RTC_LOCKR.LOCK != 0U) + { + rtcRegWPtr->RTC_LOCKR = 0x98670000U; + } + + switch(clockSource) + { + case RTC_CLK_OSC32K_INT: + rtcRegPtr->RTC_CSR.CNT_CLK_SEL = 0U; + CLK_OSC32KEnable(CLK_OSC_XTAL); + if(SUCC == CLK_WaitClkReady(CLK_SRC_OSC32K)) + { + ret = SUCC; + } + else + { + ret = ERR; + } + break; + + case RTC_CLK_OSC32K_EXT: + rtcRegPtr->RTC_CSR.CNT_CLK_SEL = 0U; + CLK_OSC32KEnable(CLK_OSC_EXT_SRC); + if(SUCC == CLK_WaitClkReady(CLK_SRC_OSC32K)) + { + ret = SUCC; + } + else + { + ret = ERR; + } + break; + + case RTC_CLK_LPO32K: + CLK_LPO32KEnable(); + rtcRegPtr->RTC_CSR.CNT_CLK_SEL = 1U; + if(SUCC == CLK_WaitClkReady(CLK_SRC_LPO32K)) + { + ret = SUCC; + } + else + { + ret = ERR; + } + break; + + case RTC_CLK_DISABLE: + CLK_LPO32KDisable(); + CLK_OSC32KDisable(); + break; + + default:/*PRQA S 2016*/ + break; + } + + rtcRegPtr->RTC_LOCKR.LOCK = 0x1U; + return ret; +} + +/** + * @brief Set match counter register to clear alarm interrupt + * + * @param[in] counterValue:set the counter value + * + * @return none + * + *****************************************************************************/ +void RTC_SetMatchCounter(uint32_t counterValue) +{ + if(rtcRegPtr->RTC_LOCKR.LOCK != 0U) + { + rtcRegWPtr->RTC_LOCKR = 0x98670000U; + } + + rtcRegPtr->RTC_MATCH_CNTR.MATCH_CNT = counterValue; + + rtcRegPtr->RTC_LOCKR.LOCK = 0x1U; +} + +/** + * @brief get match counter register + * + * @param[in] none + * + * @return match counter + * + *****************************************************************************/ +uint32_t RTC_GetMatchCounter(void) +{ + return (rtcRegPtr->RTC_MATCH_CNTR.MATCH_CNT); +} + +/** + * @brief Mask/Unmask the RTC interrupt funtion + * + * @param[in] intType: select interrupt + * @param[in] intMask:Enable/Disable interrupt + * + * @return none + * + *****************************************************************************/ +void RTC_IntMask(RTC_Int_t intType, IntMask_t intMask) +{ + if(rtcRegPtr->RTC_LOCKR.LOCK != 0U) + { + rtcRegWPtr->RTC_LOCKR = 0x98670000U; + } + + if(intMask == UNMASK) + { + rtcRegWPtr->RTC_IER |= rtcInterruptMaskTable[intType]; + rtcIntMaskStatus |= rtcIntStatusTable[intType]; + } + else + { + rtcRegWPtr->RTC_IER &= (~(rtcInterruptMaskTable[intType])); + rtcIntMaskStatus &= (~rtcIntStatusTable[intType]); + } + + rtcRegPtr->RTC_LOCKR.LOCK = 0x1U; +} + +/** + * @brief RTC Get alarm match status Function + * + * @param[in] none + * + * @return intstatus + * + */ +IntStatus_t RTC_GetAlarmMatchStatus(void) +{ + return ((IntStatus_t)rtcRegPtr->RTC_CSR.ALARM_MATCHF); /*PRQA S 4342*/ +} + +/** + * @brief Get second interrupt status Function + * + * @param[in] none + * + * @return intstatus + * + */ +IntStatus_t RTC_GetSecondStatus(void) +{ + return ((IntStatus_t)rtcRegPtr->RTC_CSR.SECONDS_INT_FLAG); /*PRQA S 4342*/ +} + +/** + * @brief RTC Get alarm overflow status Function + * + * @param[in] none + * + * @return intstatus + * + */ +IntStatus_t RTC_GetAlarmOVFStatus(void) +{ + return ((IntStatus_t)rtcRegPtr->RTC_CSR.OVF); /*PRQA S 4342*/ +} + +/** + * @brief Clear RTC overflow flag after disable RTC + * + * @param[in] countVal: set alarm counter value + * + * @return none + * + *****************************************************************************/ +void RTC_ClearOVF(uint32_t countVal) +{ + if(rtcRegPtr->RTC_LOCKR.LOCK != 0U) + { + rtcRegWPtr->RTC_LOCKR = 0x98670000U; + } + + rtcRegPtr->RTC_ALARM_CNTR.ALARM_CNT = countVal; + + rtcRegPtr->RTC_LOCKR.LOCK = 0x1U; +} + +/** + * @brief Clear RTC seconds interrupt flag function + * + * @param[in] none + * + * @return none + * + *****************************************************************************/ +void RTC_ClearSecondsFlag(void) +{ + if(rtcRegPtr->RTC_LOCKR.LOCK != 0U) + { + rtcRegWPtr->RTC_LOCKR = 0x98670000U; + } + + rtcRegPtr->RTC_CSR.SECONDS_INT_FLAG = 1; + + rtcRegPtr->RTC_LOCKR.LOCK = 0x1U; +} + +/** + * @brief Read the current alarm counter function + * + * @param[in] none + * + * @return current alarm counter + * + *****************************************************************************/ +uint32_t RTC_GetAlarmCounter(void) +{ + return (rtcRegPtr->RTC_ALARM_CNTR.ALARM_CNT); +} + +/** + * @brief Get the current compensation delay value function + * + * @param[in] none + * + * @return current compensation delay value + * + *****************************************************************************/ +uint8_t RTC_GetCurrentCompDelayCVal(void) +{ + return (uint8_t)(rtcRegPtr->RTC_COMPENSATIONR.CDLY); +} + +/** + * @brief Get current compensation counter value function + * + * @param[in] none + * + * @return current compensation value + * + *****************************************************************************/ +uint8_t RTC_GetCurrentCompVal(void) +{ + return (uint8_t)(rtcRegPtr->RTC_COMPENSATIONR.CCOMP_CNT); +} + +/** + * @brief Set compensation delay value function + * + * @param[in] delayVal: compensation delay value + * + * @return none + * + *****************************************************************************/ +void RTC_SetCompDelayVal(uint8_t delayVal) +{ + if(rtcRegPtr->RTC_LOCKR.LOCK != 0U) + { + rtcRegWPtr->RTC_LOCKR = 0x98670000U; + } + + rtcRegPtr->RTC_COMPENSATIONR.DLY = delayVal; + + rtcRegPtr->RTC_LOCKR.LOCK = 0x1U; +} + +/** + * @brief Set frequency compensation direction function + * + * @param[in] freqComp : select frequency compensation direction + * + * @return none + * + *****************************************************************************/ +void RTC_SetCompDirection(RTC_CompDirection_t freqComp) +{ + if(rtcRegPtr->RTC_LOCKR.LOCK != 0U) + { + rtcRegWPtr->RTC_LOCKR = 0x98670000U; + } + + rtcRegPtr->RTC_COMPENSATIONR.COMP_DIRECTION = (uint32_t)freqComp; + + rtcRegPtr->RTC_LOCKR.LOCK = 0x1U; +} + +/** + * @brief Set compensation counter value function + * + * @param[in] Val: compensation counter value + * + * @return none + * + *****************************************************************************/ +void RTC_SetCompVal(uint8_t Val) +{ + if(rtcRegPtr->RTC_LOCKR.LOCK != 0U) + { + rtcRegWPtr->RTC_LOCKR = 0x98670000U; + } + + rtcRegPtr->RTC_COMPENSATIONR.COMP_CNT = Val; + + rtcRegPtr->RTC_LOCKR.LOCK = 0x1U; +} + +/** + * @brief Get the current one second counter function + * + * @param[in] none + * + * @return current one second counter + * + *****************************************************************************/ +uint16_t RTC_GetSecondCounter(void) +{ + return (uint16_t)(rtcRegPtr->RTC_ONE_SECOND_CNTR.ONE_SECOND_CNT); +} + +/** + * @brief Config the compensation function + * + * @param[in] config: compensation config + * + * @return none + * + *****************************************************************************/ +void RTC_CompConfig(RTC_CompConfig_t const *config) +{ + if(rtcRegPtr->RTC_LOCKR.LOCK != 0U) + { + rtcRegWPtr->RTC_LOCKR = 0x98670000U; + } + + rtcRegPtr->RTC_COMPENSATIONR.DLY = config->delayVal; + rtcRegPtr->RTC_COMPENSATIONR.COMP_DIRECTION = (uint32_t)(config->dir); + rtcRegPtr->RTC_COMPENSATIONR.COMP_CNT = config->compVal; + + rtcRegPtr->RTC_LOCKR.LOCK = 0x1U; +} + +/** + * @brief Disable the compensation function + * + * @param[in] none + * + * @return none + * + *****************************************************************************/ +void RTC_CompDisable(void) +{ + if(rtcRegPtr->RTC_LOCKR.LOCK != 0U) + { + rtcRegWPtr->RTC_LOCKR = 0x98670000U; + } + + rtcRegWPtr->RTC_COMPENSATIONR = 0x00000000U; + + rtcRegPtr->RTC_LOCKR.LOCK = 0x1U; +} + +/** + * @brief install call back function + * + * @param[in] intId: select the interrupt + * @param[in] cbFun: pointer to callback function + * + * @return none + * + */ +void RTC_InstallCallBackFunc(RTC_Int_t intId,isr_cb_t * cbFun) +{ + if(RTC_INT_ALL <= intId) + { + /* Do nothing */ + } + else + { + rtcIsrCb[intId] = cbFun; + } +} + +/** + * @brief RTC ISR function + * + * @param none + * + * @return none + * + */ +void RTC_DriverIRQHandler(void) +{ + RTC_IntHandler(); +} + +/** @} end of group RTC_Public_Functions */ + +/** @} end of group RTC_definitions */ + +/** @} end of group Z20K11X_Peripheral_Driver */ diff --git a/StdDriver/Src/Z20K11xM_spi.c b/StdDriver/Src/Z20K11xM_spi.c new file mode 100644 index 0000000..edc6f33 --- /dev/null +++ b/StdDriver/Src/Z20K11xM_spi.c @@ -0,0 +1,624 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_spi.c + * @brief : SPI module driver file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ + +#include "Z20K11xM_spi.h" + +/** @addtogroup Z20K11X_Peripheral_Driver + * @{ + */ +/** @defgroup SPI + * @brief SPI driver modules + * @{ + */ + +/** @defgroup SPI_Private_Types + * @{ + */ + +/** @} end of group SPI_Private_Types */ + +/** @defgroup SPI_Private_Defines + * @{ + */ + +/** @} end of group SPI_Private_Defines */ + +/** @defgroup SPI_Private_Variables + * @{ + */ +/** + * @brief SPI ISR callback function pointer array + */ +static isr_cb_t *spiIsrCb[SPI_INSTANCE_NUM][SPI_INT_ALL] = { + {NULL, NULL, NULL, NULL, NULL}, + {NULL, NULL, NULL, NULL, NULL}, +#if (SPI_INSTANCE_NUM == 3) + {NULL, NULL, NULL, NULL, NULL} +#endif +}; + +/** + * @brief SPI0 SPI1 SPI2 address array + */ +/*PRQA S 0303 ++*/ +static spi_reg_t *const spiRegPtr[SPI_INSTANCE_NUM] = { + (spi_reg_t *)SPI0_BASE_ADDR, /*!< SPI0 base address */ + (spi_reg_t *)SPI1_BASE_ADDR, /*!< SPI1 base address */ +#if (SPI_INSTANCE_NUM == 3) + (spi_reg_t *)SPI2_BASE_ADDR /*!< SPI2 base address */ +#endif +}; + +static spi_reg_w_t *const spiRegWPtr[SPI_INSTANCE_NUM] = { + (spi_reg_w_t *)SPI0_BASE_ADDR, /*!< SPI0 base address */ + (spi_reg_w_t *)SPI1_BASE_ADDR, /*!< SPI1 base address */ +#if (SPI_INSTANCE_NUM == 3) + (spi_reg_w_t *)SPI2_BASE_ADDR /*!< SPI2 base address */ +#endif +}; +/*PRQA S 0303 --*/ +/** + * @brief SPI Interrupt Mask array + */ +static const uint32_t spi_InterruptMaskTable[] = { + 0x00000001U, /*!< Transmit FIFO empty interrupt */ + 0x00000002U, /*!< Transmit FIFO overflow interrupt*/ + 0x00000004U, /*!< Receive FIFO underflow interrupt */ + 0x00000008U, /*!< Received FIFO overflow interrupt */ + 0x00000010U, /*!< Received FIFO full interrupt */ + 0x0000001FU /*!< All the interrupt */ +}; + +/** @} end of group SPI_Private_Variables */ + +/** @defgroup SPI_Global_Variables + * @{ + */ + +/** @} end of group SPI_Global_Variables */ + +/** @defgroup SPI_Private_FunctionDeclaration + * @{ + */ +void SPI0_DriverIRQHandler(void); +void SPI1_DriverIRQHandler(void); +void SPI2_DriverIRQHandler(void); +static void SPI_IntHandler(SPI_ID_t spiNo); + +/** @} end of group SPI_Private_FunctionDeclaration */ + +/** @defgroup SPI_Private_Functions + * @{ + */ + +/** + * @brief SPI interrupt handler. + * + * @param[in] intPeriph: Select the peripheral. + * @param[in] spiNo: Select the SPI id, should be SPI0_ID, SPI1_ID. + * + * @return none. + * + */ +static void SPI_IntHandler(SPI_ID_t spiNo) +{ + uint32_t intStatus; + volatile uint32_t dummyData; + spi_reg_t *SPIx = (spi_reg_t *)(spiRegPtr[spiNo]); + spi_reg_w_t *SPIxw = (spi_reg_w_t *)(spiRegWPtr[spiNo]); + + /* Read the interrupt status */ + intStatus = SPIxw->SPI_ISR; + + if ((intStatus & spi_InterruptMaskTable[SPI_INT_TXE]) != 0U) + { + if (spiIsrCb[spiNo][SPI_INT_TXE] != NULL) + { + spiIsrCb[spiNo][SPI_INT_TXE](); + } + /* Mask this interrupt */ + else + { + SPIx->SPI_IER.TXEIE = 0U; + } + } + + if ((intStatus & spi_InterruptMaskTable[SPI_INT_TXO]) != 0U) + { + /* Dummy read to clear tx fifo overflow interrupt */ + dummyData = SPIx->SPI_TXOICR.TXOICR; + + if (spiIsrCb[spiNo][SPI_INT_TXO] != NULL) + { + spiIsrCb[spiNo][SPI_INT_TXO](); + } + /* Mask this interrupt */ + else + { + SPIx->SPI_IER.TXOIE = 0U; + } + } + + if ((intStatus & spi_InterruptMaskTable[SPI_INT_RXU]) != 0U) + { + /* Dummy read to clear rx fifo underflow interrupt */ + dummyData = SPIx->SPI_RXUICR.RXUICR; + + if (spiIsrCb[spiNo][SPI_INT_RXU] != NULL) + { + spiIsrCb[spiNo][SPI_INT_RXU](); + } + /* Mask this interrupt */ + else + { + SPIx->SPI_IER.RXUIE = 0U; + } + } + + if ((intStatus & spi_InterruptMaskTable[SPI_INT_RXO]) != 0U) + { + /* Dummy read to clear rx fifo overflow interrupt */ + dummyData = SPIx->SPI_RXOICR.RXOICR; + + if (spiIsrCb[spiNo][SPI_INT_RXO] != NULL) + { + spiIsrCb[spiNo][SPI_INT_RXO](); + } + /* Mask this interrupt */ + else + { + SPIx->SPI_IER.RXOIE = 0U; + } + } + + if ((intStatus & spi_InterruptMaskTable[SPI_INT_RXF]) != 0U) + { + if (spiIsrCb[spiNo][SPI_INT_RXF] != NULL) + { + spiIsrCb[spiNo][SPI_INT_RXF](); + } + /* Mask this interrupt */ + else + { + SPIx->SPI_IER.RXFIE = 0U; + } + } +} + +/** + * @brief SPI0 interrupt function. + * + * @param none. + * + * @return none. + * + */ +void SPI0_DriverIRQHandler(void) +{ + SPI_IntHandler(SPI0_ID); +} + +/** + * @brief SPI1 interrupt function. + * + * @param none. + * + * @return none. + * + */ +void SPI1_DriverIRQHandler(void) +{ + SPI_IntHandler(SPI1_ID); +} +#if (SPI_INSTANCE_NUM == 3) +/** + * @brief SPI2 interrupt function. + * + * @param none. + * + * @return none. + * + */ +void SPI2_DriverIRQHandler(void) +{ + SPI_IntHandler(SPI2_ID); +} +#endif + +/** @} end of group SPI_Private_Functions */ + +/** @defgroup SPI_Public_Functions + * @{ + */ + +/** + * @brief Initializes the SPI . + * + * @param[in] spiNo: Select the SPI id, should be SPI0_ID, SPI1_ID, SPI2_ID. + * @param[in] spiCfgStruct: Pointer to a SPI configuration structure. + * + * @return none. + * + */ +void SPI_Init(SPI_ID_t spiNo, const SPI_Config_t *spiCfgStruct) +{ + spi_reg_t *SPIx = (spi_reg_t *)(spiRegPtr[spiNo]); + if (NULL != spiCfgStruct) + { + SPIx->SPI_CTRLR0.MST_MODE = (uint32_t)spiCfgStruct->mode; + /* Set SPI clock divider */ + SPIx->SPI_BAUDR.SCKDV = spiCfgStruct->clkDivider; + /* Set data frame size */ + SPIx->SPI_CTRLR0.DFS_32 = spiCfgStruct->dataSize - 1U; + /* Set serial clock phase */ + SPIx->SPI_CTRLR0.SCPH = (uint32_t)spiCfgStruct->clkPhase; + /* et clock polarity */ + SPIx->SPI_CTRLR0.SCPOL = (uint32_t)spiCfgStruct->clkPolarity; + /* Set transfer mode */ + SPIx->SPI_CTRLR0.TMOD = (uint32_t)spiCfgStruct->transMode; + /* Set transmit FIFO threshold level */ + SPIx->SPI_FTLR.TFT = (uint32_t)spiCfgStruct->transFifoThr; + /* Set receive FIFO threshold level */ + SPIx->SPI_FTLR.RFT = (uint32_t)spiCfgStruct->recvFifoThr; + } +} + +/** + * @brief Initializes the SPI DMA. + * + * @param[in] spiNo: Select the SPI id, should be SPI0_ID, SPI1_ID, SPI2_ID. + * @param[in] dmaCfgStruct: Pointer to a SPI Master DMA configuration + * structure. + * + * @return none. + * + */ +void SPI_DmaConfig(SPI_ID_t spiNo, SPI_DmaLvl_t *dmaCfgStruct) +{ + spi_reg_t *SPIx = (spi_reg_t *)(spiRegPtr[spiNo]); + if (NULL != dmaCfgStruct) + { + /* Set transmit request level */ + SPIx->SPI_DMATDLR.DMATDL = dmaCfgStruct->dmaTransReqLevel; + /* Set receive request level */ + SPIx->SPI_DMARDLR.DMARDL = dmaCfgStruct->dmaRecvReqLevel; + } +} + +/** + * @brief Enable the SPI. + * + * @param[in] spiNo: Select the SPI port,should be SPI0_ID,SPI1_ID,SPI2_ID. + * + * @return none. + * + */ +void SPI_Enable(SPI_ID_t spiNo) +{ + spi_reg_t *SPIx = (spi_reg_t *)(spiRegPtr[spiNo]); + + /* Enable/Disable the SPI */ + SPIx->SPI_SSENR.SPI_EN = 1U; +} + +/** + * @brief Disable the SPI. + * + * @param[in] spiNo: Select the SPI id, should be SPI0_ID,SPI1_ID, SPI2_ID. + * + * @return none. + * + */ +void SPI_Disable(SPI_ID_t spiNo) +{ + spi_reg_t *SPIx = (spi_reg_t *)(spiRegPtr[spiNo]); + + /* Enable/Disable the SPI */ + SPIx->SPI_SSENR.SPI_EN = 0U; +} + +/** + * @brief Set Master data frame number. + * + * @param[in] spiNo: Select the SPI id, should be SPI0_ID, SPI1_ID, SPI2_ID. + * @param[in] frameNum: data frame number, should <= 0xFFFF. + * + * @return none. + * + * This function only used in Receive only and EEPROM transfer mode. + */ +void SPI_SetDataFrameNum(SPI_ID_t spiNo, uint32_t frameNum) +{ + spi_reg_t *SPIx = (spi_reg_t *)(spiRegPtr[spiNo]); + + if (frameNum > 0U) + { + SPIx->SPI_CTRLR1.NDF = frameNum - 1U; + } + else + { + SPIx->SPI_CTRLR1.NDF = 0U; + } +} + +/** + * @brief Enable or disable the SPI DMA function. + * + * @param[in] spiNo: Select the SPI id, should be SPI1_ID,SPI1_ID, SPI2_ID. + * @param[in] transmitDmaCtrl: Transmit DMA Enable/Disable function state + * @param[in] rcvDmaCtrl: Receive DMA Enable/Disable function state. + * + * @return none. + * + */ +void SPI_DmaCmd(SPI_ID_t spiNo, ControlState_t transmitDmaCtrl, + ControlState_t rcvDmaCtrl) +{ + spi_reg_t *SPIx = (spi_reg_t *)(spiRegPtr[spiNo]); + + /* Enable/Disable transmit DMA */ + SPIx->SPI_DMACR.TDMAE = (uint32_t)transmitDmaCtrl; + /* Enable/Disable receive DMA */ + SPIx->SPI_DMACR.RDMAE = (uint32_t)rcvDmaCtrl; +} + +/** + * @brief Select SPI slave. + * + * @param[in] spiNo: Select the SPI id, should be SPI0_ID, SPI1_ID, SPI2_ID + * + * @return none. + * + */ +void SPI_SelectSlave(SPI_ID_t spiNo, SPI_SelectSlave_t chipSelect) +{ + spi_reg_t *SPIx = (spi_reg_t *)(spiRegPtr[spiNo]); + + SPIx->SPI_SSENR.SER = (uint32_t)chipSelect; +} + +/** + * @brief Send data. + * + * @param[in] spiNo: Select the SPI id, should be SPI0_ID, SPI1_ID, SPI2_ID. + * @param[in] data: The data to be send. + * + * @return none. + * + */ +void SPI_SendData(SPI_ID_t spiNo, uint32_t data) +{ + spi_reg_w_t *SPIxw = (spi_reg_w_t *)(spiRegWPtr[spiNo]); + + /* Send data */ + SPIxw->SPI_DR_LOW = data; +} + +/** + * @brief Receive data. + * + * @param[in] spiNo: Select the SPI id, should be SPI0_ID, SPI1_ID, SPI2_ID. + * + * @return The received data. + * + */ +uint32_t SPI_ReceiveData(SPI_ID_t spiNo) +{ + spi_reg_w_t *SPIxw = (spi_reg_w_t *)(spiRegWPtr[spiNo]); + + return ((uint32_t)SPIxw->SPI_DR_LOW); +} + +/** + * @brief Get transmit FIFO level. + * + * @param[in] spiNo: Select the SPI id, should be SPI0_ID, SPI1_ID, SPI2_ID. + * + * @return The number of valid data entries in the transmit FIFO memory. + * + */ +uint32_t SPI_GetTxFifoLevel(SPI_ID_t spiNo) +{ + spi_reg_t *SPIx = (spi_reg_t *)(spiRegPtr[spiNo]); + + return (SPIx->SPI_FLR.TXTFL); +} + +/** + * @brief Get receive FIFO level. + * + * @param[in] spiNo: Select the SPI id, should be SPI0_ID, SPI1_ID, SPI2_ID. + * + * @return The number of valid data entries in the receive FIFO memory. + * + */ +uint32_t SPI_GetRxFifoLevel(SPI_ID_t spiNo) +{ + spi_reg_t *SPIx = (spi_reg_t *)(spiRegPtr[spiNo]); + + return (SPIx->SPI_FLR.RXTFL); +} + +/** + * @brief Check whether status flag is set or not for given status type. + * + * @param[in] spiNo: Select the SPI id, should be SPI0_ID, SPI1_ID, SPI2_ID. + * @param[in] spiStatus: Specified status type. + * - SPI_STATUS_BUSY + * - SPI_STATUS_TFNF + * - SPI_STATUS_TFE + * - SPI_STATUS_RFNE + * - SPI_STATUS_RFF + * - SPI_STATUS_TXE + * + * @return The state value of SPI Status register. + * - SET + * - RESET + * + */ +FlagStatus_t SPI_GetStatus(SPI_ID_t spiNo, SPI_Status_t spiStatus) +{ + uint32_t intBitStatus; + spi_reg_w_t *SPIxw = (spi_reg_w_t *)(spiRegWPtr[spiNo]); + + intBitStatus = (((SPIxw->SPI_SR) & (0x01UL << (uint32_t)spiStatus)) >> + (uint32_t)spiStatus); + return (FlagStatus_t)intBitStatus; +} + +/** + * @brief Check whether interrupt status flag is set or not for given + * interrupt type. + * + * @param[in] spiNo: Select the SPI id, should be SPI0_ID, SPI1_ID, SPI2_ID. + * @param[in] intType: Specified interrupt type. + * - SPI_INT_TXE + * - SPI_INT_TXO + * - SPI_INT_RXU + * - SPI_INT_RXO + * - SPI_INT_RXF + * @return The state flag of interrupt Status register. + * - SET + * - RESET + * + */ +FlagStatus_t SPI_GetIntStatus(SPI_ID_t spiNo, SPI_Int_t intType) +{ + uint32_t intBitStatus; + spi_reg_w_t *SPIxw = (spi_reg_w_t *)(spiRegWPtr[spiNo]); + + intBitStatus = (((SPIxw->SPI_ISR) & (0x01UL << (uint32_t)intType)) >> + (uint32_t)intType); + return (FlagStatus_t)intBitStatus; +} + +/** + * @brief Check whether raw interrupt status flag is set or not for + * given interrupt type. + * + * @param[in] spiNo: Select the SPI id, should be SPI0_ID, SPI1_ID, SPI2_ID. + * @param[in] intType: Specified interrupt type. + * - SPI_RAW_INT_TXE + * - SPI_RAW_INT_TXO + * - SPI_RAW_INT_RXU + * - SPI_RAW_INT_RXO + * - SPI_RAW_INT_RXF + * @return The state flag of interrupt Status register. + * - SET + * - RESET + * + */ +FlagStatus_t SPI_GetRawIntStatus(SPI_ID_t spiNo, SPI_RawInt_t intType) +{ + uint32_t intBitStatus; + spi_reg_w_t *SPIxw = (spi_reg_w_t *)(spiRegWPtr[spiNo]); + + intBitStatus = + (((SPIxw->SPI_ISR) & (0x01UL << ((uint32_t)intType + 16UL))) >> + ((uint32_t)intType + 16UL)); + return (FlagStatus_t)intBitStatus; +} + +/** + * @brief Mask/Unmask specified interrupt type. + * + * @param[in] spiNo: Select the SPI id, should be SPI0_ID, SPI1_ID, SPI2_ID. + * @param[in] intType: Specified interrupt type. + * - SPI_INT_TXE + * - SPI_INT_TXO + * - SPI_INT_RXU + * - SPI_INT_RXO + * - SPI_INT_RXF + * - SPI_INT_ALL + * @param[in] intMask: Interrupt mask/unmask type. + * - SPI_INT_MASK: 0 + * - SPI_INT_UNMASK: 1 + * + * @return none. + * + */ +void SPI_IntMask(SPI_ID_t spiNo, SPI_Int_t intType, IntMask_t intMask) +{ + spi_reg_w_t *SPIxw = (spi_reg_w_t *)(spiRegWPtr[spiNo]); + + if (MASK == intMask) + { + SPIxw->SPI_IER &= (~spi_InterruptMaskTable[intType]); + } + else + { + SPIxw->SPI_IER |= spi_InterruptMaskTable[intType]; + } +} + +/** + * @brief Clear all interrupt status flags. + * + * @param[in] spiNo: Select the SPI id, should be SPI0_ID,SPI1_ID, SPI2_ID. + * @param[in] intType: Specified interrupt type. + * - SPI_INT_TXO + * - SPI_INT_RXU + * - SPI_INT_RXO + * - SPI_INT_ALL + * + * @return none. + * + */ +uint32_t SPI_ClearInt(SPI_ID_t spiNo, SPI_Int_t intType) +{ + spi_reg_t *SPIx = (spi_reg_t *)(spiRegPtr[spiNo]); + volatile uint32_t dummyData; + + switch (intType) + { + case SPI_INT_TXO: + /* Dummy read to clear interrupt */ + dummyData = SPIx->SPI_TXOICR.TXOICR; + break; + case SPI_INT_RXO: + /* Dummy read to clear interrupt */ + dummyData = SPIx->SPI_RXOICR.RXOICR; + break; + case SPI_INT_RXU: + /* Dummy read to clear interrupt */ + dummyData = SPIx->SPI_RXUICR.RXUICR; + break; + case SPI_INT_ALL: + /* Dummy read to clear interrupt */ + dummyData = SPIx->SPI_ICR.ICR; + break; + default: + dummyData = 0U; + break; + } + return dummyData; +} + +/** + * @brief install call back function. + * + * @param[in] intId: select the interrupt. + * @param[in] cbFun: pointer to callback function. + * + * @return none. + * + */ +void SPI_InstallCallBackFunc(SPI_ID_t spiId, SPI_Int_t intId, isr_cb_t *cbFun) +{ + spiIsrCb[spiId][intId] = cbFun; +} + +/** @} end of group SPI_Public_Functions */ + +/** @} end of group SPI */ + +/** @} end of group Z20K11X_Peripheral_Driver */ diff --git a/StdDriver/Src/Z20K11xM_srmc.c b/StdDriver/Src/Z20K11xM_srmc.c new file mode 100644 index 0000000..833d8fb --- /dev/null +++ b/StdDriver/Src/Z20K11xM_srmc.c @@ -0,0 +1,567 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_srmc.c + * @brief : SRMC module driver file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (C) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + * + **************************************************************************************************/ + +#include "Z20K11xM_srmc.h" + +/** @addtogroup Z20K11X_Peripheral_Driver + * @{ + */ + +/** @defgroup SRMC SRMC + * @brief SRMC driver modules + * @{ + */ + +/** @defgroup SRMC_Private_Type + * @{ + */ + +/*@} end of group SRMC_Private_Type*/ + +/** @defgroup SRMC_Private_Defines + * @{ + */ +#define SRMC_GIE_BIT_POSITION (7U) /*Global Interrupt Enable Bit Position in SRIE*/ +/*PRQA S 0303,0306 ++*/ +static srmc_reg_t *const srmcRegPtr = (srmc_reg_t *) SRMC_BASE_ADDR; /* SRMC Register */ +static srmc_reg_w_t *const srmcRegWPtr = (srmc_reg_w_t *) SRMC_BASE_ADDR; /* SRMC Word Register */ +static SCB_Type *const coreSCB = (SCB_Type *)SCB_BASE; /* Core SCB Register*/ +/*PRQA S 0303,0306 --*/ + +static const uint32_t SRMC_IntStatusTable[] = +{ + 0x00000004U, /*SRMC_INT_TYPE_LOC status mask*/ + 0x00000020U, /*SRMC_INT_TYPE_WDOG status mask*/ + 0x00000040U, /*SRMC_INT_TYPE_PIN status mask*/ + 0x00000200U, /*SRMC_INT_TYPE_LOCKUP status mask*/ + 0x00000400U, /*SRMC_INT_TYPE_SW status mask*/ + 0x00008000U, /*SRMC_INT_TYPE_SACKERR status mask*/ + 0x00008664U, /*SRMC_INT_TYPE_ALL*/ +}; + +/*PRQA S 3218 ++*/ +static const uint32_t SRMC_IntMaskTable[] = +{ + 0x00000004U, /*SRMC_INT_TYPE_LOC enable mask*/ + 0x00000020U, /*SRMC_INT_TYPE_WDOG enable mask*/ + 0x00000040U, /*SRMC_INT_TYPE_PIN enable mask*/ + 0x00000200U, /*SRMC_INT_TYPE_LOCKUP enable mask*/ + 0x00000400U, /*SRMC_INT_TYPE_SW enable mask*/ + 0x00008000U, /*SRMC_INT_TYPE_SACKERR enable mask*/ + 0x000086E4U, /*SRMC_INT_TYPE_ALL*/ +}; +/*PRQA S 3218 --*/ + +static uint32_t srmcIntMaskStatus = 0; + +/*@} end of group SRMC_Private_Defines */ + +/** @defgroup SRMC_Private_Variables + * @{ + */ +static isr_cb_t * srmcIsrCbFunc[SRMC_INT_TYPE_ALL]= +{ + NULL,NULL,NULL,NULL,NULL,NULL +}; +/*@} end of group SRMC_Private_Variables */ + +/** @defgroup SRMC_Global_Variables + * @{ + */ + +/*@} end of group SRMC_Global_Variables */ + +/** @defgroup SRMC_Private_FunctionDeclaration + * @{ + */ +void SRMC_DriverIRQHandler(void); + +/*@} end of group SRMC_Private_FunctionDeclaration */ + +/** @defgroup SRMC_Private_Functions + * @{ + */ + +/** + * @brief SRMC Interrupt Handler + * + * @param[in] none + * + * @return none + * + */ +void SRMC_DriverIRQHandler(void) +{ + uint32_t intStatus; + + /* get interrupt status */ + intStatus = srmcRegWPtr->SRMC_SRS; + /* only check enabled interrupts */ + intStatus = intStatus & srmcIntMaskStatus; + /* clear interrupt status */ + srmcRegWPtr->SRMC_SRS = intStatus; + + /* loc cause reset Interrupt */ + if((intStatus & SRMC_IntStatusTable[SRMC_INT_TYPE_LOC]) != 0U) + { + if(srmcIsrCbFunc[SRMC_INT_TYPE_LOC] != NULL) + { + /* call the callback function */ + srmcIsrCbFunc[SRMC_INT_TYPE_LOC](); + } + /* Disable the interrupt if callback function is not setup */ + else + { + srmcRegPtr->SRMC_SRIE.LOC = 0U; + } + } + + /* wdog cause reset Interrupt */ + if((intStatus & SRMC_IntStatusTable[SRMC_INT_TYPE_WDOG]) != 0U) + { + if(srmcIsrCbFunc[SRMC_INT_TYPE_WDOG] != NULL) + { + /* call the callback function */ + srmcIsrCbFunc[SRMC_INT_TYPE_WDOG](); + } + /* Disable the interrupt if callback function is not setup */ + else + { + srmcRegPtr->SRMC_SRIE.WDOG = 0U; + } + } + + /* pin cause reset Interrupt */ + if((intStatus & SRMC_IntStatusTable[SRMC_INT_TYPE_PIN]) != 0U) + { + if(srmcIsrCbFunc[SRMC_INT_TYPE_PIN] != NULL) + { + /* call the callback function */ + srmcIsrCbFunc[SRMC_INT_TYPE_PIN](); + } + /* Disable the interrupt if callback function is not setup */ + else + { + srmcRegPtr->SRMC_SRIE.PIN = 0U; + } + } + + /* lock up cause reset Interrupt */ + if((intStatus & SRMC_IntStatusTable[SRMC_INT_TYPE_LOCKUP]) != 0U) + { + if(srmcIsrCbFunc[SRMC_INT_TYPE_LOCKUP] != NULL) + { + /* call the callback function */ + srmcIsrCbFunc[SRMC_INT_TYPE_LOCKUP](); + } + /* Disable the interrupt if callback function is not setup */ + else + { + srmcRegPtr->SRMC_SRIE.LOCKUP = 0U; + } + } + + /* software reset Interrupt */ + if((intStatus & SRMC_IntStatusTable[SRMC_INT_TYPE_SW]) != 0U) + { + if(srmcIsrCbFunc[SRMC_INT_TYPE_SW] != NULL) + { + /* call the callback function */ + srmcIsrCbFunc[SRMC_INT_TYPE_SW](); + } + /* Disable the interrupt if callback function is not setup */ + else + { + srmcRegPtr->SRMC_SRIE.SW = 0U; + } + } + + /* sack error cause reset Interrupt */ + if((intStatus & SRMC_IntStatusTable[SRMC_INT_TYPE_SACKERR]) != 0U) + { + if(srmcIsrCbFunc[SRMC_INT_TYPE_SACKERR] != NULL) + { + /* call the callback function */ + srmcIsrCbFunc[SRMC_INT_TYPE_SACKERR](); + } + /* Disable the interrupt if callback function is not setup */ + else + { + srmcRegPtr->SRMC_SRIE.SACKERR = 0U; + } + } +} +/*@} end of group SRMC_Private_Functions */ + +/** @defgroup SRMC_Public_Functions + * @{ + */ + +/** + * @brief configure core lockup reset enable/disable + * + * @param[in] cmd: control cmd: DISABLE; ENABLE. + * + * @return none + * + */ +void SRMC_CoreLockupResetCtrl(ControlState_t cmd) +{ + srmcRegPtr->SRMC_CTRL.LOCKUP_RST_EN = (uint32_t)cmd; +} + +/** + * @brief SRMC wakeup source polarity config + * + * @param[in] source: wakeup source select. + * @param[in] polarity: active polarity. + * - SRMC_WUPPL_LOW + * - SRMC_WUPPL_HIGH + * + * @return none + * + */ +void SRMC_WakeupSourceConfig(SRMC_WakeupSource_t source, SRMC_WakePolarity_t polarity) +{ + uint8_t leftshift = (uint8_t) source; + + if(SRMC_WUPPL_LOW == polarity) + { + srmcRegWPtr->SRMC_DSMWUPC = srmcRegWPtr->SRMC_DSMWUPC & (~(0x10000UL << leftshift)); + } + else + { + srmcRegWPtr->SRMC_DSMWUPC = srmcRegWPtr->SRMC_DSMWUPC | (0x10000UL << leftshift); + } +} + +/** + * @brief SRMC wakeup source function enable/disable + * + * @param[in] source: wakeup source select. + * @param[in] cmd: enable/disable. + * + * @return none + * + */ +void SRMC_WakeupSourceCtrl(SRMC_WakeupSource_t source, ControlState_t cmd) +{ + uint8_t leftshift = (uint8_t) source; + + if(DISABLE == cmd) + { + srmcRegWPtr->SRMC_DSMWUPC = srmcRegWPtr->SRMC_DSMWUPC & (~(0x1UL << leftshift)); + } + else + { + srmcRegWPtr->SRMC_DSMWUPC = srmcRegWPtr->SRMC_DSMWUPC | (0x1UL << leftshift); + } +} + +/** + * @brief SRMC get wakeup source status, indicating corresponding wakeup + * source waked up system + * + * @param[in] source: wakeup source select. + * + * @return status + * + */ +FlagStatus_t SRMC_GetWakeupSourceStatus(SRMC_WakeupSource_t source) +{ + uint8_t leftshift = (uint8_t) source; + FlagStatus_t retStatus; + + if((srmcRegWPtr->SRMC_DSMWUPS & (0x1UL << leftshift)) == 0UL) + { + retStatus = RESET; + } + else + { + retStatus = SET; + } + + return retStatus; +} + +/** + * @brief configure reset pin filter bus clock width, + * actural reset pin bus clock filter width cycle = clkCycles + 1 + * + * @param[in] clkCycles: cycle number. + * + * @return none + * + */ +void SRMC_ResetPinFilterBusClockConfig(uint8_t clkCycles) +{ + srmcRegPtr->SRMC_CTRL.RSTFLTSEL = (uint32_t)clkCycles & 0x1FUL; +} + +/** + * @brief configure how reset pin filter is enabled in stop mode + * + * @param[in] filterType: only two type used in stop mode, as below + * SRMC_RESET_PIN_DISABLE_FILTER + * SRMC_RESET_PIN_LPO_CLOCK_FILTER + * + * @return none + * + */ +void SRMC_ResetPinFilterInStopMode(SRMC_ResetPinFilter_t filterType) +{ + srmcRegPtr->SRMC_CTRL.RSTFLTSS = ((uint32_t)filterType >> 1U) & 0x1U; +} + +/** + * @brief configure how reset pin filter is enabled in run and wait mode + * + * @param[in] filterType: three type used in run and wait mode, as below + * SRMC_RESET_PIN_DISABLE_FILTER + * SRMC_RESET_PIN_BUS_CLOCK_FILTER + * SRMC_RESET_PIN_LPO_CLOCK_FILTER + * + * @return none + * + */ +void SRMC_ResetPinFilterInRunAndWaitMode(SRMC_ResetPinFilter_t filterType) +{ + srmcRegPtr->SRMC_CTRL.RSTFLTSRW = (uint32_t)filterType; +} + +/** + * @brief Get the status that if the pointed reset type is the system + * reset cause. + * + * @param[in] resetCauseType: reset cause type. + * + * @return status + * + */ +FlagStatus_t SRMC_GetSystemResetStatus(SRMC_ResetCause_t resetCauseType) +{ + FlagStatus_t status; + + status = ((srmcRegWPtr->SRMC_SRS & (uint32_t)resetCauseType) != 0UL)? SET : RESET; + + return status; +} + +/** + * @brief Clear the status that if the pointed reset type. + * + * @param[in] resetCauseType: reset cause type. + * + * @return status + * + */ +void SRMC_ClearSystemRestStatus(SRMC_ResetCause_t resetCauseType) +{ + srmcRegWPtr->SRMC_SSRS = (uint32_t )resetCauseType; +} + +/** + * @brief Get system reset all causes + * + * @param[in] none + * + * @return reset cause type(uint32 value): one bit, one cause; + * seeing SRMC_ResetCause_t type; + * + */ +uint32_t SRMC_GetSystemResetCause(void) +{ + uint32_t resetCause; + + resetCause = srmcRegWPtr->SRMC_SRS & (uint32_t)SRMC_RESET_TYPE_ALL; + + return resetCause; +} + +/** + * @brief Unmask/Mask pointed interrupt + * + * @param[in] intType: srmc interrupt source. + * @param[in] intMask: UNMASK or MASK. + * + * @return none + * + */ +void SRMC_IntMask(SRMC_Int_t intType, IntMask_t intMask) +{ + + if(UNMASK == intMask) + { + srmcRegWPtr->SRMC_SRIE = srmcRegWPtr->SRMC_SRIE | SRMC_IntMaskTable[intType] \ + | (1UL << SRMC_GIE_BIT_POSITION); + srmcIntMaskStatus = srmcIntMaskStatus | SRMC_IntStatusTable[intType]; + } + else + { + srmcRegWPtr->SRMC_SRIE = srmcRegWPtr->SRMC_SRIE & (~SRMC_IntMaskTable[intType]); + srmcIntMaskStatus = srmcIntMaskStatus & (~SRMC_IntStatusTable[intType]); + } +} + + +/** + * @brief configure max reset delay time + * + * @param[in] delayType: delay cycle type. + * + * @return none + * + */ +void SRMC_MaxResetDelayTimeConfig(SRMC_Delay_t delayType) +{ + srmcRegPtr->SRMC_SRIE.DELAY = (uint32_t)delayType; +} + +/** + * @brief configure standby mode entry allowed or not + * + * @param[in] cmd: DISABLE or ENABLE. + * + * @return none + * + */ +void SRMC_AllowStandbyMode(ControlState_t cmd) +{ + srmcRegPtr->SRMC_PMPORT.APD = (uint32_t)cmd; +} + +/** + * @brief Set system enter wait mode + * + * @return none + * + */ +void SRMC_EnterWaitMode(void) +{ + coreSCB->SCR &= (~SCB_SCR_SLEEPDEEP_Msk); + + __WFI(); +} + +/** + * @brief Set system enter stop mode(deep sleep mode) + * + * @param[in] ackTimeout: stop mode acknowledge timeout value in clock cycles + * + * @return none + * + */ +void SRMC_EnterStopMode(uint8_t ackTimeout) +{ + srmcRegPtr->SRMC_PMCTRL.DSMACKTMO = ackTimeout; + + /*10'b : STOP mode*/ + srmcRegPtr->SRMC_PMCTRL.DSMC = 2U; + + coreSCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; + + __WFI(); +} + +/** + * @brief Set system enter standby mode + * + * @return none + * + */ +void SRMC_EnterStandbyMode(void) +{ + /*11'b : Standby mode*/ + srmcRegPtr->SRMC_PMCTRL.DSMC = 3U; + + coreSCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; + + __WFI(); +} + +/** + * @brief Get current power mode + * + * @param[in] none + * + * @return power mode type + * + */ +SRMC_PowerMode_t SRMC_GetCurrentPowerMode(void) +{ + SRMC_PowerMode_t retPowerMode; + uint8_t pm = (uint8_t)srmcRegPtr->SRMC_PMSTAT.PMSTAT; + + switch(pm) + { + case 1U: + retPowerMode = SRMC_POWERMODE_RUN; + break; + + case 2U: + retPowerMode = SRMC_POWERMODE_WAIT; + break; + + case 4U: + retPowerMode = SRMC_POWERMODE_STOP; + break; + + case 8U: + retPowerMode = SRMC_POWERMODE_STANDBY; + break; + + default: + retPowerMode = SRMC_POWERMODE_RUN; + break; + } + + return retPowerMode; +} + +/** + * @brief Get previous stop mode(deep sleep mode) entry status + * + * @param[in] none + * + * @return stop entry status: + * - SRMC_STOP_SUCCESS; + * - SRMC_STOP_ABORT. + * + */ +SRMC_StopModeStatus_t SRMC_GetStopAbortedStatus(void) +{ + SRMC_StopModeStatus_t stopAborted = + (SRMC_StopModeStatus_t)srmcRegPtr->SRMC_PMSTAT.DSMABORT; /*PRQA S 4342*/ + + return stopAborted; +} + +/** + * @brief install callback func + * + * @param[in] intType: interrupt type id + * @param[in] cbFun : callback function pointer + * + * @return stop entry status: SRMC_STOP_SUCCESS; SRMC_STOP_ABORT. + * + */ +void SRMC_InstallCallBackFunc(SRMC_Int_t intType,isr_cb_t * cbFun) +{ + srmcIsrCbFunc[intType] = cbFun; +} + +/*@} end of group SRMC_Public_Functions */ + +/*@} end of group SRMC_definitions */ + +/*@} end of group Z20K11X_Peripheral_Driver */ diff --git a/StdDriver/Src/Z20K11xM_stim.c b/StdDriver/Src/Z20K11xM_stim.c new file mode 100644 index 0000000..03d838c --- /dev/null +++ b/StdDriver/Src/Z20K11xM_stim.c @@ -0,0 +1,302 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_stim.c + * @brief : STIM module driver file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ + +#include "Z20K11xM_stim.h" + +/** @addtogroup Z20K11X_Peripheral_Driver + * @{ + */ + +/** @defgroup STIM + * @brief STIM driver modules + * @{ + */ + +/** @defgroup STIM_Private_Defines + * @{ + */ +/*PRQA S 0303 ++*/ +static stim_reg_t *const stimRegPtr = (stim_reg_t *) STIM_BASE_ADDR; +static stim_reg_w_t *const stimRegWPtr = (stim_reg_w_t *) STIM_BASE_ADDR; +/*PRQA S 0303 --*/ + +/** @} end of group STIM_Private_Defines */ + +/** @defgroup STIM_Private_Variables + * @{ + */ + +/** + * @brief STIM ISR callback function pointer array + */ +static isr_cb_t * stimIsrCb[STIM_NUM_ALL][STIM_INT_ALL]= {{NULL}, + {NULL}, + {NULL}, + {NULL}}; + +/** @} end of group STIM_Private_Variables */ + +/** @defgroup STIM_Global_Variables + * @{ + */ + +/** @} end of group STIM_Global_Variables */ + +/** @defgroup STIM_Private_FunctionDeclaration + * @{ + */ +/* local functions */ +void STIM_DriverIRQHandler(void); +static void STIM_IntHandler(void); + +/** @} end of group STIM_Private_FunctionDeclaration */ + +/** @defgroup STIM_Private_Variables + * @{ + */ +/** + * @brief STIM interrupt handle + * + * @return none + * + */ +static void STIM_IntHandler(void) +{ + uint32_t i; + uint32_t intStatus; + + for(i=0U; i<(uint32_t)STIM_NUM_ALL; i++) + { + /* Read the interrupt status */ + intStatus = stimRegPtr->STIM_SCn[i].FLAG; + /* only check enabled interrupt */ + intStatus = intStatus & stimRegPtr->STIM_SCn[i].IE; + /* clear the interrupt */ + stimRegPtr->STIM_SCn[i].FLAG = intStatus; + + if(intStatus != 0U) + { + if(stimIsrCb[i][STIM_INT]!= NULL) + { + stimIsrCb[i][STIM_INT](); + } + /* Disable the interrupt */ + else + { + stimRegPtr->STIM_SCn[i].IE = 0U; + } + } + } +} + +/** + * @brief STIM interrupt function + * + * @param none + * + * @return none + * + */ +void STIM_DriverIRQHandler(void) +{ + STIM_IntHandler(); +} +/** @} end of group STIM_Private_Variables */ + +/** @defgroup STIM_Public_Functions + * @{ + */ +/** + * @brief Install call back function + * + * @param[in] stimNo: Select the stim number,should be STIM_0,STIM_1,STIM_2, + * STIM_3. + * @param[in] intType: Select the interrupt. + * - STIM_INT + * @param[in] cbFun: pointer to callback function. + * + * @return none + * + */ +void STIM_InstallCallBackFunc(STIM_No_t stimNo, STIM_INT_t intType, + isr_cb_t * cbFun) +{ + stimIsrCb[stimNo][intType] = cbFun; +} + +/** + * @brief Initialize STIM configuration + * + * @param[in] stimNo: Select the stim number,should be STIM_0,STIM_1,STIM_2, + * STIM_3. + * @param[in] stimConfigStruct: Stim configuration struct. + * + * @return none + * + */ +void STIM_Init(STIM_No_t stimNo, const STIM_Config_t* stimConfigStruct) +{ + if(STIM_PULSE_COUNT == stimConfigStruct->workMode) + { + stimRegPtr->STIM_SCn[stimNo].PSRC = + (uint32_t)stimConfigStruct->pinSource; + stimRegPtr->STIM_SCn[stimNo].POL = + (uint32_t)stimConfigStruct->pinPoalrity; + } + + stimRegPtr->STIM_SCn[stimNo].MODE = (uint32_t)stimConfigStruct->workMode; + + stimRegPtr->STIM_CVn[stimNo].CV = + (uint32_t)stimConfigStruct->compareValue; + stimRegPtr->STIM_SCn[stimNo].RSTDIS = + (uint32_t)stimConfigStruct->countResetMode; + stimRegPtr->STIM_SCn[stimNo].CLKS = + (uint32_t)stimConfigStruct->clockSource; + stimRegPtr->STIM_SCn[stimNo].PSEN = + (uint32_t)stimConfigStruct->prescalerMode; + stimRegPtr->STIM_SCn[stimNo].PSDIV = + (uint32_t)stimConfigStruct->prescalerOrFilterValue; +} + +/** + * @brief Set compare value + * + * @param[in] stimNo: Select the stim number,should be STIM_0,STIM_1,STIM_2, + * STIM_3. + * @param[in] compareValue: stim compare value. + * + * @return none + * + */ +void STIM_SetCompareValue(STIM_No_t stimNo, uint32_t compareValue) +{ + /* Set compare value */ + stimRegWPtr->STIM_CVn[stimNo] = (uint32_t)compareValue; +} + +/** + * @brief Current Value of stim + * + * @param[in] stimNo: Select the stim number,should be STIM_0,STIM_1,STIM_2, + * STIM_3. + * + * @return value of stim + * + */ +uint32_t STIM_GetCurrentCounterValue(STIM_No_t stimNo) +{ + /* Current Value of STIM */ + return ((uint32_t)stimRegWPtr->STIM_CNTn[stimNo]); +} + + /** + * @brief Enable stim + * + * @param[in] stimNo: Select the stim number,should be STIM_0,STIM_1,STIM_2, + * STIM_3. + * + * @return none + * + */ +void STIM_Enable(STIM_No_t stimNo) +{ + stimRegPtr->STIM_SCn[stimNo].EN = 1U; +} + +/** + * @brief Disable stim + * + * @param[in] stimNo: Select the stim number,should be STIM_0,STIM_1,STIM_2, + * STIM_3. + * + * @return none + * + */ +void STIM_Disable(STIM_No_t stimNo) +{ + stimRegPtr->STIM_SCn[stimNo].EN = 0U; +} + +/** + * @brief Enable/Disable the stim interrupt + * + * @param[in] stimNo: Select the stim number,should be STIM_0,STIM_1,STIM_2, + * STIM_3. + * @param[in] newState: Enable/Disable function state. + * - ENABLE: enable interrupt + * - DISABLE: disable interrupt + * + * @return none + * + */ +void STIM_IntCmd(STIM_No_t stimNo, ControlState_t newState) +{ + /* Mask/Unmask the timer interrupt */ + stimRegPtr->STIM_SCn[stimNo].IE = (uint32_t)newState; +} + +/** + * @brief Enable or disable the STIM DMA function. + * + * @param[in] stimNo: Select the stim number,should be STIM_0,STIM_1,STIM_2, + * STIM_3. + * @param[in] newState: Enable/Disable function state. + * - ENABLE: enable DMA request + * - DISABLE: disable DMA request + * + * @return none. + * + */ +void STIM_DmaCmd(STIM_No_t stimNo, ControlState_t newState) +{ + stimRegPtr->STIM_SCn[stimNo].DMAE = (uint32_t)newState; +} + +/** + * @brief Checks if the status flag is set when the counter matches the + * compare value + * + * @param[in] stimNo: Select the stim number,should be STIM_0,STIM_1,STIM_2, + * STIM_3. + * + * @return The status flag. + * - SET + * - RESET + * + */ +FlagStatus_t STIM_GetStatus(STIM_No_t stimNo) +{ + FlagStatus_t intBitStatus; + + intBitStatus = (stimRegPtr->STIM_SCn[stimNo].FLAG != 0U) ? SET : RESET; + return intBitStatus; +} +/** + * @brief Clear the interrupt of stim + * + * @param[in] stimNo: Select the stim number,should be STIM_0,STIM_1,STIM_2, + * STIM_3. + * + * @return none + * + */ +void STIM_ClearInt(STIM_No_t stimNo) +{ + /* Write 1 to clear interrupt */ + stimRegPtr->STIM_SCn[stimNo].FLAG = 1U; +} + +/** @} end of group STIM_Public_Functions */ + +/** @} end of group STIM_definitions */ + +/** @} end of group Z20K11X_Peripheral_Driver */ diff --git a/StdDriver/Src/Z20K11xM_sysctrl.c b/StdDriver/Src/Z20K11xM_sysctrl.c new file mode 100644 index 0000000..f610c3c --- /dev/null +++ b/StdDriver/Src/Z20K11xM_sysctrl.c @@ -0,0 +1,668 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_sysctrl.c + * @brief : SYSCTRL module driver file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (C) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + * + **************************************************************************************************/ + +#include "Z20K11xM_sysctrl.h" + +/** @addtogroup Z20K11X_Peripheral_Driver + * @{ + */ + +/** @defgroup SYSCTRL + * @brief SYSCTRL driver modules + * @{ + */ + +/** @defgroup SYSCTRL_Private_Type + * @{ + */ + +typedef volatile union +{ + struct + { + uint32_t PCKMD : 2; /* [1:0] r/w */ + uint32_t RSVD_3_2 : 2; /* [3:2] r */ + uint32_t CLKMUX : 3; /* [6:4] r/w */ + uint32_t RSVD_7 : 1; /* [7] r */ + uint32_t CLKDIV : 4; /* [11:8] r/w */ + uint32_t RSVD_15_12 : 4; /* [15:12] r */ + uint32_t PWLK : 1; /* [16] r/w */ + uint32_t RSVD_19_17 : 3; /* [19:17] r */ + uint32_t PSUPVACEN : 1; /* [20] r/w */ + uint32_t PRSTB : 1; /* [21] r/w */ + uint32_t RSVD_23_22 : 2; /* [23:22] r */ + uint32_t PPR : 1; /* [24] r/w */ + uint32_t PCLKMUXPR : 1; /* [25] r/w */ + uint32_t PCLKDIVPR : 1; /* [26] r/w */ + uint32_t PSUPVACPR : 1; /* [27] r/w */ + uint32_t RSVD_30_28 : 3; /* [30:28] r */ + uint32_t LOCK : 1; /* [31] r/w */ + } BF; + uint32_t WORDVAL; +} ModuleRst_t; + + +/** @} end of group SYSCTRL_Private_Type*/ + +/** @defgroup SYSCTRL_Private_Defines + * @{ + */ +/*PRQA S 0303 ++*/ +static scm_reg_t *const scmRegPtr = (scm_reg_t *) SCM_BASE_ADDR; /* SCM Register */ +static scm_reg_w_t *const scmRegWPtr = (scm_reg_w_t *) SCM_BASE_ADDR; /* SCM Word Register */ +static parcc_reg_t *const parccRegPtr = (parcc_reg_t *) PARCC_BASE_ADDR; /* PARCC Register */ +static parcc_reg_w_t *const parccRegWPtr = (parcc_reg_w_t *) PARCC_BASE_ADDR; /* PARCC Word Register */ +/*PRQA S 0303 --*/ +/** @} end of group SYSCTRL_Private_Defines */ + +/** @defgroup SYSCTRL_Private_Variables + * @{ + */ + + +/** @} end of group SYSCTRL_Private_Variables */ + +/** @defgroup SYSCTRL_Global_Variables + * @{ + */ + +/** @} end of group SYSCTRL_Global_Variables */ + +/** @defgroup SYSCTRL_Private_FunctionDeclaration + * @{ + */ + +/** @} end of group SYSCTRL_Private_FunctionDeclaration */ + +/** @defgroup SYSCTRL_Private_Functions + * @{ + */ + + +/** @} end of group SYSCTRL_Private_Functions */ + +/** @defgroup SYSCTRL_Public_Functions + * @{ + */ + +/** + * @brief Get Device ID + * + * @param[in] none + * + * @return Device ID + * + */ +SYSCTRL_DeviceId_t SYSCTRL_GetDeviceId(void) +{ + SYSCTRL_DeviceId_t devId; + + devId.packageId = (uint8_t)(scmRegPtr->SCM_DEVID.PACKAGE_ID); + devId.featureId = (uint8_t)(scmRegPtr->SCM_DEVID.FEATURE_ID); + devId.RevisionId = (uint8_t)(scmRegPtr->SCM_DEVID.REV_ID); + devId.familyId = (uint8_t)(scmRegPtr->SCM_DEVID.FAMILY_ID); + devId.subFamilyId = (uint8_t)(scmRegPtr->SCM_DEVID.SUBFAMILY_ID); + devId.seriesId = (uint8_t)(scmRegPtr->SCM_DEVID.SERIES_ID); + devId.memSizeId = (uint8_t)(scmRegPtr->SCM_DEVID.MEMSIZE_ID); + + return devId; +} + +/** + * @brief Get 128-bit unique ID + * + * @param[in] uniqueId: the start address of a array with 4 32-bit elements. + * the 128-bit unique ID will be written to this array. + * UniqueId[0]: bit 0-31 + * UniqueId[1]: bit 63-32 + * UniqueId[2]: bit 95-64 + * UniqueId[3]: bit 127-96 + * + * @return none + * + */ +void SYSCTRL_Get128BitUniqueId(uint32_t uniqueId[]) +{ + uniqueId[3] = scmRegPtr->SCM_UNIQUE3.UID_127_96; + uniqueId[2] = scmRegPtr->SCM_UNIQUE2.UID_95_64; + uniqueId[1] = scmRegPtr->SCM_UNIQUE1.UID_63_32; + uniqueId[0] = scmRegPtr->SCM_UNIQUE0.UID_31_0; +} + + +/** + * @brief reset module + * + * @param[in] module: select which module to reset. It can select from modules + * defined in type SYSCTRL_Module_t except SYSCTRL_FLASH. + * + * @return none + * + */ +void SYSCTRL_ResetModule(SYSCTRL_Module_t mod) +{ + ModuleRst_t *mod_p = (ModuleRst_t *)(PARCC_BASE_ADDR + (uint32_t)mod); /*PRQA S 0303*/ + + switch(mod) + { + case SYSCTRL_WDOG: + case SYSCTRL_EWDT: + case SYSCTRL_STIM: + case SYSCTRL_TIM0: + case SYSCTRL_TIM1: + case SYSCTRL_TIM2: + case SYSCTRL_TDG0: + case SYSCTRL_CAN0: + case SYSCTRL_CAN1: + case SYSCTRL_UART0: + case SYSCTRL_UART1: + case SYSCTRL_UART2: + case SYSCTRL_UART3: + case SYSCTRL_SPI0: + case SYSCTRL_SPI1: + case SYSCTRL_SPI2: + case SYSCTRL_I2C0: + case SYSCTRL_I2C1: + case SYSCTRL_ADC0: + case SYSCTRL_CMP: + case SYSCTRL_CRC: + case SYSCTRL_DMA: + case SYSCTRL_DMAMUX: + case SYSCTRL_PORTA: + case SYSCTRL_PORTB: + case SYSCTRL_PORTC: + case SYSCTRL_PORTD: + case SYSCTRL_PORTE: + case SYSCTRL_TMU: + case SYSCTRL_REGFILE: + case SYSCTRL_GPIO: + case SYSCTRL_HWDIV: + if(mod_p->BF.LOCK != 0U) + { + /* unlock this register */ + mod_p->WORDVAL = 0x5B000000U; + } + + mod_p->BF.PRSTB = 0U; + mod_p->BF.PRSTB = 1U; + mod_p->BF.LOCK = 1U; + break; + default: + /*Do Nothing*/ + break; + } +} + +/** + * @brief Enable module. The module is enabled in normal/wait/stop modes. + * + * @param[in] module: select which module to enable. + * + * @return none + * + */ +void SYSCTRL_EnableModule(SYSCTRL_Module_t mod) +{ + ModuleRst_t *mod_p = (ModuleRst_t *)(PARCC_BASE_ADDR + (uint32_t)mod); /*PRQA S 0303*/ + + switch(mod) + { + case SYSCTRL_WDOG: + case SYSCTRL_EWDT: + case SYSCTRL_STIM: + case SYSCTRL_TIM0: + case SYSCTRL_TIM1: + case SYSCTRL_TIM2: + case SYSCTRL_TDG0: + case SYSCTRL_CAN0: + case SYSCTRL_CAN1: + case SYSCTRL_UART0: + case SYSCTRL_UART1: + case SYSCTRL_UART2: + case SYSCTRL_UART3: + case SYSCTRL_SPI0: + case SYSCTRL_SPI1: + case SYSCTRL_SPI2: + case SYSCTRL_I2C0: + case SYSCTRL_I2C1: + case SYSCTRL_ADC0: + case SYSCTRL_CMP: + case SYSCTRL_CRC: + case SYSCTRL_DMA: + case SYSCTRL_DMAMUX: + case SYSCTRL_PORTA: + case SYSCTRL_PORTB: + case SYSCTRL_PORTC: + case SYSCTRL_PORTD: + case SYSCTRL_PORTE: + case SYSCTRL_TMU: + case SYSCTRL_REGFILE: + case SYSCTRL_GPIO: + case SYSCTRL_HWDIV: + if(mod_p->BF.LOCK != 0U) + { + /* unlock this register */ + mod_p->WORDVAL = 0x5B000000; + } + + mod_p->BF.PCKMD = 1; + + mod_p->BF.PRSTB = 1; + mod_p->BF.LOCK = 1; + break; + + case SYSCTRL_FLASH: + if(parccRegPtr->PARCC_FLASH.LOCK != 0U) + { + parccRegWPtr->PARCC_FLASH = 0x5B000000; + } + parccRegPtr->PARCC_FLASH.PCKMD = 1; + parccRegPtr->PARCC_FLASH.LOCK = 1; + break; + default: + /*Do Nothing*/ + break; + } +} + +/** + * @brief Enable module but the module is off in stop mode. + * + * @param[in] mod: select which module to enable. + * + * @return none + * @note ADC does not support clock off in stop mode, no action is + * performed when mod = SYSCTRL_ADC0. + * + */ +void SYSCTRL_EnableModuleWithOffInStopMode(SYSCTRL_Module_t mod) +{ + ModuleRst_t *mod_p = (ModuleRst_t *)(PARCC_BASE_ADDR + (uint32_t)mod); /*PRQA S 0303*/ + + switch(mod) + { + case SYSCTRL_WDOG: + case SYSCTRL_EWDT: + case SYSCTRL_STIM: + case SYSCTRL_TIM0: + case SYSCTRL_TIM1: + case SYSCTRL_TIM2: + case SYSCTRL_TDG0: + case SYSCTRL_CAN0: + case SYSCTRL_CAN1: + case SYSCTRL_UART0: + case SYSCTRL_UART1: + case SYSCTRL_UART2: + case SYSCTRL_UART3: + case SYSCTRL_SPI0: + case SYSCTRL_SPI1: + case SYSCTRL_SPI2: + case SYSCTRL_I2C0: + case SYSCTRL_I2C1: + case SYSCTRL_CMP: + case SYSCTRL_CRC: + case SYSCTRL_DMA: + case SYSCTRL_DMAMUX: + case SYSCTRL_PORTA: + case SYSCTRL_PORTB: + case SYSCTRL_PORTC: + case SYSCTRL_PORTD: + case SYSCTRL_PORTE: + case SYSCTRL_TMU: + case SYSCTRL_REGFILE: + case SYSCTRL_GPIO: + case SYSCTRL_HWDIV: + if(mod_p->BF.LOCK != 0U) + { + /* unlock this register */ + mod_p->WORDVAL = 0x5B000000U; + } + + mod_p->BF.PCKMD = 2; + + mod_p->BF.PRSTB = 1; + mod_p->BF.LOCK = 1; + break; + case SYSCTRL_FLASH: + if(parccRegPtr->PARCC_FLASH.LOCK != 0U) + { + parccRegWPtr->PARCC_FLASH = 0x5B000000U; + } + parccRegPtr->PARCC_FLASH.PCKMD = 2; + parccRegPtr->PARCC_FLASH.LOCK = 1; + break; + + default: + /*Do Nothing*/ + break; + } +} + +/** + * @brief Disable module + * + * @param[in] module: select which module to disable. + * + * @return none + * @note The module clock is switched off after calling this API. + * The register value of the selected module will be reset by + * this API except PORTx and flash modules. + * -- The PORTx is more likely to be shared among many modules, + * so the register values of PORTx are not reset by this API + * and only the function clock is diabled. + * The pinmux function retains when re-enable PORTx. + * User should use SYSCTRL_ResetModule() to reset PORTx regiters + * if desired. + * + */ +void SYSCTRL_DisableModule(SYSCTRL_Module_t mod) +{ + ModuleRst_t *mod_p = (ModuleRst_t *)(PARCC_BASE_ADDR + (uint32_t)mod); /*PRQA S 0303*/ + + switch(mod) + { + case SYSCTRL_WDOG: + case SYSCTRL_EWDT: + case SYSCTRL_STIM: + case SYSCTRL_TIM0: + case SYSCTRL_TIM1: + case SYSCTRL_TIM2: + case SYSCTRL_TDG0: + case SYSCTRL_CAN0: + case SYSCTRL_CAN1: + case SYSCTRL_UART0: + case SYSCTRL_UART1: + case SYSCTRL_UART2: + case SYSCTRL_UART3: + case SYSCTRL_SPI0: + case SYSCTRL_SPI1: + case SYSCTRL_SPI2: + case SYSCTRL_I2C0: + case SYSCTRL_I2C1: + case SYSCTRL_ADC0: + case SYSCTRL_CMP: + case SYSCTRL_CRC: + case SYSCTRL_DMA: + case SYSCTRL_DMAMUX: + case SYSCTRL_TMU: + case SYSCTRL_REGFILE: + case SYSCTRL_GPIO: + case SYSCTRL_HWDIV: + if(mod_p->BF.LOCK != 0U) + { + /* unlock this register */ + mod_p->WORDVAL = 0x5B000000; + } + + mod_p->BF.PCKMD = 0; + mod_p->BF.PRSTB = 0; + mod_p->BF.LOCK = 1; + break; + + case SYSCTRL_PORTA: + case SYSCTRL_PORTB: + case SYSCTRL_PORTC: + case SYSCTRL_PORTD: + case SYSCTRL_PORTE: + if(mod_p->BF.LOCK != 0U) + { + /* unlock this register */ + mod_p->WORDVAL = 0x5B000000; + } + + mod_p->BF.PCKMD = 0; + mod_p->BF.LOCK = 1; + break; + + case SYSCTRL_FLASH: + if(parccRegPtr->PARCC_FLASH.LOCK != 0U) + { + parccRegWPtr->PARCC_FLASH = 0x5B000000U; + } + parccRegPtr->PARCC_FLASH.PCKMD = 0; + parccRegPtr->PARCC_FLASH.LOCK = 1; + break; + + default: + /*Do Nothing*/ + break; + } +} + +/** + * @brief Config the module write access limits + * + * @param[in] module: select which module to config + * @param[in] writeLock: write lock + * - ENABLE: Peripheral register write is denied + * - DISABLE: Peripheral register write is allowed + * @param[in] supervisorEn: supervisor enable + * - ENABLE: Peripheral register write is allowed in + * supervisor mode,but denied in user mode + * - DISABLE: Peripheral register write is allowed in + * both supervisor and user mode + * + * @return none + * + */ +void SYSCTRL_ModuleWriteControl(SYSCTRL_Module_t mod, ControlState_t writeLock, + ControlState_t supervisorEn) +{ + ModuleRst_t *mod_p = (ModuleRst_t *)(PARCC_BASE_ADDR + (uint32_t)mod); /*PRQA S 0303*/ + + switch(mod) + { + case SYSCTRL_WDOG: + case SYSCTRL_EWDT: + case SYSCTRL_STIM: + case SYSCTRL_TIM0: + case SYSCTRL_TIM1: + case SYSCTRL_TIM2: + case SYSCTRL_TDG0: + case SYSCTRL_CAN0: + case SYSCTRL_CAN1: + case SYSCTRL_UART0: + case SYSCTRL_UART1: + case SYSCTRL_UART2: + case SYSCTRL_UART3: + case SYSCTRL_SPI0: + case SYSCTRL_SPI1: + case SYSCTRL_SPI2: + case SYSCTRL_I2C0: + case SYSCTRL_I2C1: + case SYSCTRL_ADC0: + case SYSCTRL_CMP: + case SYSCTRL_CRC: + case SYSCTRL_FLASH: + case SYSCTRL_DMA: + case SYSCTRL_DMAMUX: + case SYSCTRL_PORTA: + case SYSCTRL_PORTB: + case SYSCTRL_PORTC: + case SYSCTRL_PORTD: + case SYSCTRL_PORTE: + case SYSCTRL_TMU: + case SYSCTRL_REGFILE: + case SYSCTRL_GPIO: + case SYSCTRL_HWDIV: + if(mod_p->BF.LOCK != 0U) + { + /* unlock this register */ + mod_p->WORDVAL = 0x5B000000; + } + + mod_p->BF.PWLK = (uint32_t)writeLock; + mod_p->BF.PSUPVACEN = (uint32_t)supervisorEn; + mod_p->BF.LOCK = 1; + break; + default: + /*Do Nothing*/ + break; + } +} + +/** + * @brief config SRAM ECC. SRAM ECC is enabled by default. ECC config can + * be changed through this function. + * + * @param[in] sram: select which SRAM to config. + * @param[in] eccConfig: points to the struct that stores the parameters. + * + * @return none + * + */ +void SYSCTRL_SramEccConfig(SYSCTRL_Sram_t sram, + const SYSCTRL_SramEcc_t *eccConfig) +{ + if(SYSCTRL_SRAM_L == sram) + { + scmRegPtr->SCM_ECCOPT.SRAM0_ECCMB_DIS = (eccConfig->multiBitEccEn == ENABLE) ? 0U : 1U; + scmRegPtr->SCM_ECCOPT.SRAM0_ECCSB_DIS = (eccConfig->singleBitEccEn == ENABLE) ? 0U : 1U; + scmRegPtr->SCM_ECCOPT.SRAM0_ECCR_DIS = (eccConfig->readEccEn == ENABLE) ? 0U : 1U; + scmRegPtr->SCM_ECCOPT.SRAM0_ECCW_DIS = (eccConfig->writeEccEn == ENABLE) ? 0U : 1U; + } + + if(SYSCTRL_SRAM_U == sram) + { + scmRegPtr->SCM_ECCOPT.SRAM1_ECCMB_DIS = (eccConfig->multiBitEccEn == ENABLE) ? 0U : 1U; + scmRegPtr->SCM_ECCOPT.SRAM1_ECCSB_DIS = (eccConfig->singleBitEccEn == ENABLE) ? 0U : 1U; + scmRegPtr->SCM_ECCOPT.SRAM1_ECCR_DIS = (eccConfig->readEccEn == ENABLE) ? 0U : 1U; + scmRegPtr->SCM_ECCOPT.SRAM1_ECCW_DIS = (eccConfig->writeEccEn == ENABLE) ? 0U : 1U; + } +} + +/** + * @brief Get SRAM ECC error status + * + * @param[in] sram: select which SRAM to config. + * @param[in] errMask: select the error mask. + * + * @return + * - RESET: the error status is not set + * - SET: the error status is set + * + */ +FlagStatus_t SYSCTRL_GetSramEccErrStatus(SYSCTRL_Sram_t sram, uint32_t errMask) +{ + FlagStatus_t res = RESET; + + if(SYSCTRL_SRAM_L == sram) + { + res = ((scmRegWPtr->SCM_ECC0ST & (uint32_t)errMask) != 0U)? SET : RESET; + } + + if(SYSCTRL_SRAM_U == sram) + { + res = ((scmRegWPtr->SCM_ECC1ST & (uint32_t)errMask) != 0U)? SET : RESET; + } + + return res; +} + +/** + * @brief Clear SRAM ECC error status + * + * @param[in] sram: select which SRAM to config. + * @param[in] errMask: select the error mask. + * + * @return none + * + */ +void SYSCTRL_ClearSramEccErrStatus(SYSCTRL_Sram_t sram, uint32_t errMask) +{ + if(SYSCTRL_SRAM_L == sram) + { + scmRegWPtr->SCM_ECC0ST = (uint32_t)errMask; + } + + if(SYSCTRL_SRAM_U == sram) + { + scmRegWPtr->SCM_ECC1ST = (uint32_t)errMask; + } +} +/** + * @brief Get SRAM ECC error cause + * + * @param[in] sram: select which SRAM to config. + * @param[in] cause: the cause of SRAM ERR error will be stored in the struct + * that is pointed by this parameter. + * + * @return none + * + */ +void SYSCTRL_GetSramEccErrCause(SYSCTRL_Sram_t sram, + SYSCTRL_SramEccErrCause_t *cause) +{ + if(SYSCTRL_SRAM_L == sram) + { + cause->errAddr = scmRegWPtr->SCM_ECC0FADDR; + cause->faultData = scmRegWPtr->SCM_ECC0FDATA; + cause->write = (scmRegPtr->SCM_ECC0ST.EFW != 0U) ? SET : RESET; + cause->faultMaster = (SYSCTRL_Master_t)(scmRegPtr->SCM_ECC0ST.EFMST); + cause->faultSize = (SYSCTRL_AccessSize_t)(scmRegPtr->SCM_ECC0ST.EFSIZE); + cause->accessType = (((scmRegWPtr->SCM_ECC0ST)& 0x000000001UL) == 0U)? + SYSCTRL_ACC_TYPE_OPCODE : SYSCTRL_ACC_TYPE_DATA; + cause->accessMode = (((scmRegWPtr->SCM_ECC0ST)&0x000000002UL) == 0U)? + SYSCTRL_ACC_MODE_USER : SYSCTRL_ACC_MODE_PRIVIL; + cause->bufferable = (((scmRegWPtr->SCM_ECC0ST)&0x000000004UL) == 0U) ? + RESET : SET; + cause->cacheable = (((scmRegWPtr->SCM_ECC0ST)&0x000000008UL) == 0U) ? + RESET : SET; + } + + if(SYSCTRL_SRAM_U == sram) + { + cause->errAddr = scmRegWPtr->SCM_ECC1FADDR; + cause->faultData = scmRegWPtr->SCM_ECC1FDATA; + cause->write = (scmRegPtr->SCM_ECC1ST.EFW != 0U) ? SET : RESET; + cause->faultMaster = (SYSCTRL_Master_t)(scmRegPtr->SCM_ECC1ST.EFMST); + cause->faultSize = (SYSCTRL_AccessSize_t)(scmRegPtr->SCM_ECC1ST.EFSIZE); + cause->accessType = (((scmRegWPtr->SCM_ECC1ST)& 0x000000001UL) == 0U)? + SYSCTRL_ACC_TYPE_OPCODE : SYSCTRL_ACC_TYPE_DATA; + cause->accessMode = (((scmRegWPtr->SCM_ECC1ST)&0x000000002UL) == 0U)? + SYSCTRL_ACC_MODE_USER : SYSCTRL_ACC_MODE_PRIVIL; + cause->bufferable = (((scmRegWPtr->SCM_ECC1ST)&0x000000004UL) == 0U) ? + RESET : SET; + cause->cacheable = (((scmRegWPtr->SCM_ECC1ST)&0x000000008UL) == 0U) ? + RESET : SET; + } +} +/** + * @brief Set Software trigger to TMU + * + * @param[in] source: select software trigger source to TMU + * @param[in] level: trigger level to TMU. + * + * @return none + * + */ +void SYSCTRL_SoftTriggerToTmu(SYSCTRL_TriggerSrc_t source, SYSCTRL_TriggerLevel_t level) +{ + volatile uint32_t tmp; + + if(SYSCTRL_TRIG_LEVEL_LOW == level) + { + tmp = scmRegWPtr->SCM_MISCCTL & (~(1UL << (uint32_t)source)); + scmRegWPtr->SCM_MISCCTL = tmp; + } + else + { + tmp = scmRegWPtr->SCM_MISCCTL | (1UL << (uint32_t)source); + scmRegWPtr->SCM_MISCCTL = tmp; + } +} +/** @} end of group SYSCTRL_Public_Functions */ + +/** @} end of group SYSCTRL_definitions */ + +/** @} end of group Z20K11X_Peripheral_Driver */ diff --git a/StdDriver/Src/Z20K11xM_tdg.c b/StdDriver/Src/Z20K11xM_tdg.c new file mode 100644 index 0000000..8908dd0 --- /dev/null +++ b/StdDriver/Src/Z20K11xM_tdg.c @@ -0,0 +1,892 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_tdg.c + * @brief : TDG module driver file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ + +#include "Z20K11xM_tdg.h" + +/** @addtogroup Z20K11X_Peripheral_Driver + * @{ + */ + +/** @defgroup TDG TDG + * @brief TDG driver modules + * @{ + */ + +/** @defgroup TDG_Private_Type + * @{ + */ + +/** @} end of group TDG_Private_Type*/ + +/** @defgroup TDG_Private_Defines + * @{ + */ + +/** @} end of group TDG_Private_Defines */ + +/** @defgroup TDG_Private_Variables + * @{ + */ + +static isr_cb_t *tdgIsrCbFunc[TDG_NUM][TDG_INT_ALL] = { + {NULL, NULL, NULL, NULL, NULL, NULL, NULL} +}; + +/** + * @brief TDG address array + */ +/*PRQA S 0303 ++*/ +static tdg_reg_t *const tdgRegPtr[TDG_NUM] = { + (tdg_reg_t *)TDG0_BASE_ADDR, +}; + +static tdg_reg_w_t *const tdgRegWPtr[TDG_NUM] = { + (tdg_reg_w_t *)TDG0_BASE_ADDR, +}; +/*PRQA S 0303 --*/ +static const uint32_t TDG_IntMaskTable[] = { + 0x00000001U, /*!< Channel 0 complete delay output interrupt */ + 0x00000002U, /*!< Channel 1 complete delay output interrupt*/ + 0x00000004U, /*!< Channel 2 complete delay output interrupt*/ + 0x00000008U, /*!< Channel 3 complete delay output interrupt*/ + 0x00000010U, /*!< Channel 4 complete delay output interrupt*/ + 0x00000020U, /*!< Channel 5 complete delay output interrupt*/ + 0x00000100U, /*!< Error interrupt */ + 0x0000013FU /*!< TDG_INT_ALL */ +}; + +/** @} end of group TDG_Private_Variables */ + +/** @defgroup TDG_Global_Variables + * @{ + */ + +/** @} end of group TDG_Global_Variables */ + +/** @defgroup TDG_Private_FunctionDeclaration + * @{ + */ +void TDG0_DriverIRQHandler(void); +static void TDG_IntHandler(TDG_ID_t tdgId); + +/** @} end of group TDG_Private_FunctionDeclaration */ + +/** @defgroup TDG_Private_Functions + * @{ + */ +/** + * @brief TDG interrupt handle + * + * @param[in] tdgId + * + * @return none + * + */ +static void TDG_IntHandler(TDG_ID_t tdgId) +{ + tdg_reg_t *TDGx = (tdg_reg_t *)(tdgRegPtr[tdgId]); + tdg_reg_w_t *TDGxw = (tdg_reg_w_t *)(tdgRegWPtr[tdgId]); + + uint32_t intStatus; + + /* get interrupt status */ + intStatus = TDGxw->TDG_STAT & TDG_IntMaskTable[TDG_INT_ALL]; + /* only check enabled interrupts */ + intStatus &= TDGxw->TDG_CTRL2; + /* clear interrupt status */ + TDGxw->TDG_STAT = intStatus; + + /* CHANNEL 0 Interrupt */ + if ((intStatus & TDG_IntMaskTable[TDG_INT_CH0]) != 0U) + { + if (tdgIsrCbFunc[tdgId][TDG_INT_CH0] != NULL) + { + /* call the callback function */ + tdgIsrCbFunc[tdgId][TDG_INT_CH0](); + } + /* Disable the interrupt if callback function is not setup */ + else + { + TDGx->TDG_CTRL2.CDO0IE = 0U; + } + } + + /* CHANNEL 1 Interrupt */ + if ((intStatus & TDG_IntMaskTable[TDG_INT_CH1]) != 0U) + { + if (tdgIsrCbFunc[tdgId][TDG_INT_CH1] != NULL) + { + /* call the callback function */ + tdgIsrCbFunc[tdgId][TDG_INT_CH1](); + } + /* Disable the interrupt if callback function is not setup */ + else + { + TDGx->TDG_CTRL2.CDO1IE = 0U; + } + } + + /* CHANNEL 2 Interrupt */ + if ((intStatus & TDG_IntMaskTable[TDG_INT_CH2]) != 0U) + { + if (tdgIsrCbFunc[tdgId][TDG_INT_CH2] != NULL) + { + /* call the callback function */ + tdgIsrCbFunc[tdgId][TDG_INT_CH2](); + } + /* Disable the interrupt if callback function is not setup */ + else + { + TDGx->TDG_CTRL2.CDO2IE = 0U; + } + } + + /* CHANNEL 3 Interrupt */ + if ((intStatus & TDG_IntMaskTable[TDG_INT_CH3]) != 0U) + { + if (tdgIsrCbFunc[tdgId][TDG_INT_CH3] != NULL) + { + /* call the callback function */ + tdgIsrCbFunc[tdgId][TDG_INT_CH3](); + } + /* Disable the interrupt if callback function is not setup */ + else + { + TDGx->TDG_CTRL2.CDO3IE = 0U; + } + } + + /* CHANNEL 4 Interrupt */ + if ((intStatus & TDG_IntMaskTable[TDG_INT_CH4]) != 0U) + { + if (tdgIsrCbFunc[tdgId][TDG_INT_CH4] != NULL) + { + /* call the callback function */ + tdgIsrCbFunc[tdgId][TDG_INT_CH4](); + } + /* Disable the interrupt if callback function is not setup */ + else + { + TDGx->TDG_CTRL2.CDO4IE = 0U; + } + } + + /* CHANNEL 5 Interrupt */ + if ((intStatus & TDG_IntMaskTable[TDG_INT_CH5]) != 0U) + { + if (tdgIsrCbFunc[tdgId][TDG_INT_CH5] != NULL) + { + /* call the callback function */ + tdgIsrCbFunc[tdgId][TDG_INT_CH5](); + } + /* Disable the interrupt if callback function is not setup */ + else + { + TDGx->TDG_CTRL2.CDO5IE = 0U; + } + } + + /* ERR Interrupt */ + if ((intStatus & TDG_IntMaskTable[TDG_INT_ERR]) != 0U) + { + if (tdgIsrCbFunc[tdgId][TDG_INT_ERR] != NULL) + { + /* call the callback function */ + tdgIsrCbFunc[tdgId][TDG_INT_ERR](); + } + /* Disable the interrupt if callback function is not setup */ + else + { + TDGx->TDG_CTRL2.ERRIE = 0U; + } + } +} + +/** + * @brief TDG IRQHandler + * + * @param[in] NONE + * + * @return none + * + */ +void TDG0_DriverIRQHandler(void) +{ + TDG_IntHandler(TDG0_ID); +} +/** @} end of group TDG_Private_Functions */ + +/** @defgroup TDG_Public_Functions + * @{ + */ +/** + * @brief TDG ENABLE/DISABLE FUNCTION + * + * @param[in] tdgId + * @param[in] ControlState_t: ENABLE/DISABLE + * + * @return none + * + */ +void TDG_Enable(TDG_ID_t tdgId, ControlState_t cmd) +{ + tdg_reg_t *TDGx = (tdg_reg_t *)(tdgRegPtr[tdgId]); + TDGx->TDG_CTRL1.TDGEN = (uint32_t)cmd; +} + +/** + * @brief TDG init config function + * + * @param[in] tdgId + * @param[in] TDG_InitConfig_t: config + * + * @return none + * + */ +void TDG_InitConfig(TDG_ID_t tdgId, const TDG_InitConfig_t *config) +{ + tdg_reg_t *TDGx = (tdg_reg_t *)(tdgRegPtr[tdgId]); + /* modulate value */ + TDGx->TDG_MOD.MOD = config->modVal; + + /* count mode */ + TDGx->TDG_CTRL1.CNTMD = (uint32_t)config->countMode; + + TDGx->TDG_CTRL1.PRES = (uint32_t)config->clkDivide; + /* trig source */ + TDGx->TDG_CTRL1.TRIGS = (uint32_t)config->trigSource; + /* update mode select */ + TDGx->TDG_CTRL1.UPMD = (uint32_t)config->updateMode; + /* clear counter mode */ + TDGx->TDG_CTRL1.CLRMD = (uint32_t)config->clearMode; +} + +/** + * @brief TDG config update mode function + * + * @param[in] tdgId + * @param[in] updateMode: + * -TDG_UPDATE_IMMEDIATELY + * -TDG_UPDATE_MODULATOR + * -TDG_UPDATE_DELAY + * + * @return none + * + */ +void TDG_UpdateModeConfig(TDG_ID_t tdgId, TDG_UpdateMode_t updateMode) +{ + tdg_reg_t *TDGx = (tdg_reg_t *)(tdgRegPtr[tdgId]); + + TDGx->TDG_CTRL1.UPMD = (uint32_t)updateMode; +} + +/** + * @brief TDG select counter clear mode + * + * @param[in] tdgId + * @param[in] clearMode: + * -TDG_ClEAR_MODULATOR + * -TDG_CLEAR_DELAY + * + * @return none + * + */ +void TDG_ClearCounterMode(TDG_ID_t tdgId, TDG_CountClearMode_t clearMode) +{ + tdg_reg_t *TDGx = (tdg_reg_t *)(tdgRegPtr[tdgId]); + + TDGx->TDG_CTRL1.CLRMD = (uint32_t)clearMode; +} + +/** + * @brief TDG select count mode + * + * @param[in] tdgId + * @param[in] countMode: + * -TDG_COUNT_SINGLE + * -TDG_COUNT_INFINITY + * + * @return none + * + */ +void TDG_SelectCountMode(TDG_ID_t tdgId, TDG_CountMode_t countMode) +{ + tdg_reg_t *TDGx = (tdg_reg_t *)(tdgRegPtr[tdgId]); + + TDGx->TDG_CTRL1.CNTMD = (uint32_t)countMode; +} + +/** + * @brief TDG select trig source + * + * @param[in] tdgId + * @param[in] TDG_TrigSource_t: + * -TDG_TRIG_EXTERNAL + * -TDG_TRIG_INFINITY + * + * @return none + * + */ +void TDG_SelectTrigMode(TDG_ID_t tdgId, TDG_TrigSource_t trig) +{ + tdg_reg_t *TDGx = (tdg_reg_t *)(tdgRegPtr[tdgId]); + + TDGx->TDG_CTRL1.TRIGS = (uint32_t)trig; +} + +/** + * @brief Set this bit to load channel configuration from shadow buffer to + * register + * + * @param[in] tdgId + * + * @return ResultStatus_t + * - SUCC: Load complete + * - ERR:load fail + * + */ +ResultStatus_t TDG_LoadCmd(TDG_ID_t tdgId) +{ + tdg_reg_t *TDGx = (tdg_reg_t *)(tdgRegPtr[tdgId]); + + ResultStatus_t ret = ERR; + volatile uint32_t localcnt = 0; + + TDGx->TDG_CTRL1.CFGUP = 1U; + + while (localcnt < TDG_TIMEOUT_WAIT_CNT) + { + if ((uint32_t)RESET == TDGx->TDG_CTRL1.CFGUP) + { + ret = SUCC; + break; + } + + localcnt = localcnt + 1U; + } + + return ret; +} + +/** + * @brief TDG software trig + * + * @param[in] tdgId + * + * @return none + * + */ +void TDG_SoftwareTrig(TDG_ID_t tdgId) +{ + tdg_reg_t *TDGx = (tdg_reg_t *)(tdgRegPtr[tdgId]); + + TDGx->TDG_CTRL1.SWTRG = 1U; +} + +/** + * @brief TDG mod value config + * + * @param[in] tdgId + * @param[in] uint16_t modValue + * + * @return none + * + */ +void TDG_SetModVal(TDG_ID_t tdgId, uint16_t modValue) +{ + tdg_reg_t *TDGx = (tdg_reg_t *)(tdgRegPtr[tdgId]); + + TDGx->TDG_MOD.MOD = modValue; +} + +/** + * @brief GET TDG mod value + * + * @param[in] tdgId + * + * @return mod value + * + */ +uint16_t TDG_GetModVal(TDG_ID_t tdgId) +{ + tdg_reg_t const volatile *TDGx = (tdg_reg_t *)(tdgRegPtr[tdgId]); + + return (uint16_t)(TDGx->TDG_MOD.MOD); +} + +/** + * @brief GET TDG counter value + * + * @param[in] tdgId + * + * @return counter value + * + */ +uint16_t TDG_GetCounterVal(TDG_ID_t tdgId) +{ + tdg_reg_t const volatile *TDGx = (tdg_reg_t *)(tdgRegPtr[tdgId]); + + return (uint16_t)(TDGx->TDG_CNT.CNT); +} + +/** + * @brief TDG prescale the count clock sourec function + * + * @param[in] tdgId + * @param[in] TDG_ClkDivide_t: + * -TDG_CLK_DIVIDE_1 + * -TDG_CLK_DIVIDE_2 + * -TDG_CLK_DIVIDE_4 + * -TDG_CLK_DIVIDE_8 + * -TDG_CLK_DIVIDE_16 + * -TDG_CLK_DIVIDE_32 + * -TDG_CLK_DIVIDE_64 + * -TDG_CLK_DIVIDE_128 + * + * @return none + * + */ +void TDG_DivideClk(TDG_ID_t tdgId, TDG_ClkDivide_t divide) +{ + tdg_reg_t *TDGx = (tdg_reg_t *)(tdgRegPtr[tdgId]); + + TDGx->TDG_CTRL1.PRES = (uint32_t)divide; +} + +/** + * @brief TDG channel enable/disable + * + * @param[in] tdgId + * @param[in] TDG_ChannelId_t: select channel + * @param[in] ControlState_t:ENABLE/DISABLE + * + * @return none + * + */ +void TDG_ChannelEnable(TDG_ID_t tdgId, TDG_ChannelId_t channelId, + ControlState_t cmd) +{ + tdg_reg_t *TDGx = (tdg_reg_t *)(tdgRegPtr[tdgId]); + + switch (channelId) + { + case TDG_CHANNEL_0: + TDGx->TDG_CTRL2.CH0E = (uint32_t)cmd; + break; + + case TDG_CHANNEL_1: + TDGx->TDG_CTRL2.CH1E = (uint32_t)cmd; + break; + + case TDG_CHANNEL_2: + TDGx->TDG_CTRL2.CH2E = (uint32_t)cmd; + break; + + case TDG_CHANNEL_3: + TDGx->TDG_CTRL2.CH3E = (uint32_t)cmd; + break; + case TDG_CHANNEL_4: + TDGx->TDG_CTRL2.CH4E = (uint32_t)cmd; + break; + + case TDG_CHANNEL_5: + TDGx->TDG_CTRL2.CH5E = (uint32_t)cmd; + break; + + default: + /*Do nothing*/ + break; + } +} + +/** + * @brief TDG INT mask/unmask Function + * + * @param[in] tdgId + * @param[in] intType: Selcct interrupt type. + * @param[in] intMask: MASK/UNMASK . + * + * @return none + * + */ +void TDG_IntMask(TDG_ID_t tdgId, TDG_INT_t intType, IntMask_t intMask) +{ + tdg_reg_t *TDGx = (tdg_reg_t *)(tdgRegPtr[tdgId]); + + ControlState_t cmd = (intMask == UNMASK) ? ENABLE : DISABLE; + + switch (intType) + { + case TDG_INT_CH0: + TDGx->TDG_CTRL2.CDO0IE = (uint32_t)cmd; + break; + + case TDG_INT_CH1: + TDGx->TDG_CTRL2.CDO1IE = (uint32_t)cmd; + break; + + case TDG_INT_CH2: + TDGx->TDG_CTRL2.CDO2IE = (uint32_t)cmd; + break; + + case TDG_INT_CH3: + TDGx->TDG_CTRL2.CDO3IE = (uint32_t)cmd; + break; + + case TDG_INT_CH4: + TDGx->TDG_CTRL2.CDO4IE = (uint32_t)cmd; + break; + + case TDG_INT_CH5: + TDGx->TDG_CTRL2.CDO5IE = (uint32_t)cmd; + break; + + case TDG_INT_ERR: + TDGx->TDG_CTRL2.ERRIE = (uint32_t)cmd; + break; + + case TDG_INT_ALL: + TDGx->TDG_CTRL2.CDO0IE = (uint32_t)cmd; + TDGx->TDG_CTRL2.CDO1IE = (uint32_t)cmd; + TDGx->TDG_CTRL2.CDO2IE = (uint32_t)cmd; + TDGx->TDG_CTRL2.CDO3IE = (uint32_t)cmd; + TDGx->TDG_CTRL2.CDO4IE = (uint32_t)cmd; + TDGx->TDG_CTRL2.CDO5IE = (uint32_t)cmd; + TDGx->TDG_CTRL2.ERRIE = (uint32_t)cmd; + break; + + default: + /*Do nothing*/ + break; + } +} + +/** + * @brief TDG INT status clear Function + * + * @param[in] tdgId + * @param[in] intType: Selcct interrupt type. + * + * @return none + * + */ +void TDG_IntClear(TDG_ID_t tdgId, TDG_INT_t intType) +{ + tdg_reg_t *TDGx = (tdg_reg_t *)(tdgRegPtr[tdgId]); + + switch (intType) + { + case TDG_INT_CH0: + TDGx->TDG_STAT.CDO0IF = 1U; + break; + + case TDG_INT_CH1: + TDGx->TDG_STAT.CDO1IF = 1U; + break; + + case TDG_INT_CH2: + TDGx->TDG_STAT.CDO2IF = 1U; + break; + + case TDG_INT_CH3: + TDGx->TDG_STAT.CDO3IF = 1U; + break; + + case TDG_INT_CH4: + TDGx->TDG_STAT.CDO4IF = 1U; + break; + + case TDG_INT_CH5: + TDGx->TDG_STAT.CDO5IF = 1U; + break; + + case TDG_INT_ERR: + TDGx->TDG_STAT.ERRIF = 1U; + break; + + case TDG_INT_ALL: + TDGx->TDG_STAT.CDO0IF = 1U; + TDGx->TDG_STAT.CDO1IF = 1U; + TDGx->TDG_STAT.CDO2IF = 1U; + TDGx->TDG_STAT.CDO3IF = 1U; + TDGx->TDG_STAT.CDO4IF = 1U; + TDGx->TDG_STAT.CDO5IF = 1U; + TDGx->TDG_STAT.ERRIF = 1U; + break; + + default: + /*Do nothing*/ + break; + } +} + +/** + * @brief TDG Get INT status Function + * + * @param[in] tdgId + * @param[in] intType: Selcct interrupt type. + * + * @return intstatus + * + */ +IntStatus_t TDG_GetIntStatus(TDG_ID_t tdgId, TDG_INT_t intType) +{ + tdg_reg_t const volatile *TDGx = (tdg_reg_t *)(tdgRegPtr[tdgId]); + + IntStatus_t intStatus = RESET; + + switch (intType) + { + case TDG_INT_CH0: + intStatus = (IntStatus_t)TDGx->TDG_STAT.CDO0IF; + break; + + case TDG_INT_CH1: + intStatus = (IntStatus_t)TDGx->TDG_STAT.CDO1IF; + break; + + case TDG_INT_CH2: + intStatus = (IntStatus_t)TDGx->TDG_STAT.CDO2IF; + break; + + case TDG_INT_CH3: + intStatus = (IntStatus_t)TDGx->TDG_STAT.CDO3IF; + break; + + case TDG_INT_CH4: + intStatus = (IntStatus_t)TDGx->TDG_STAT.CDO4IF; + break; + + case TDG_INT_CH5: + intStatus = (IntStatus_t)TDGx->TDG_STAT.CDO5IF; + break; + + case TDG_INT_ERR: + intStatus = (IntStatus_t)TDGx->TDG_STAT.ERRIF; + break; + + default: + /*Do nothing*/ + break; + } + + return intStatus; +} + +/** + * @brief TDG channel delay output complete interrupt delay + * + * @param[in] tdgId + * @param[in] channelId: select channel + * @param[in] delayVal: delay output complete interrupt delay + * + * @return none + * + */ +void TDG_SetIntDelayVal(TDG_ID_t tdgId, TDG_ChannelId_t channelId, + uint16_t delayVal) +{ + tdg_reg_t *TDGx = (tdg_reg_t *)(tdgRegPtr[tdgId]); + + TDGx->TDG_CHCFG[channelId].TDG_CHDOCINTDLY.CDOINTDLY = delayVal & 0x03FFU; +} + +/** + * @brief get TDG delay output complete interrupt delay value + * + * @param[in] tdgId + * @param[in] channelId: select channel + * + * @return delay value + * + */ +uint16_t TDG_GetChannelIntDelayVal(TDG_ID_t tdgId, TDG_ChannelId_t channelId) +{ + tdg_reg_t const volatile *TDGx = (tdg_reg_t *)(tdgRegPtr[tdgId]); + + return (uint16_t)(TDGx->TDG_CHCFG[channelId].TDG_CHDOCINTDLY.CDOINTDLY & + 0x3FFU); +} + +/** + * @brief TDG delay output config function + * + * @param[in] tdgId + * @param[in] channelId: select channel + * @param[in] doConfig: config delay output + * + * @return none + * + */ +void TDG_DelayOuputConfig(TDG_ID_t tdgId, TDG_ChannelId_t channelId, + const TDG_DelayOutputConfig_t *doConfig) +{ + + tdg_reg_w_t *TDGxw = (tdg_reg_w_t *)(tdgRegWPtr[tdgId]); + + uint32_t doId = (uint32_t)doConfig->doId; + + uint32_t doEnable; + doEnable = TDGxw->TDG_CHCFG[channelId].TDG_CHCTRL; + if(ENABLE == doConfig->cmd) + { + TDGxw->TDG_CHCFG[channelId].TDG_CHCTRL = doEnable | + (((uint32_t)doConfig->cmd) << (8U + doId)); + } + else + { + TDGxw->TDG_CHCFG[channelId].TDG_CHCTRL = doEnable & + (~((1UL) << (8U + doId))); + } + + TDGxw->TDG_CHCFG[channelId].TDG_CHDOOFS[doId] = (uint32_t)doConfig->offset; +} + +/** + * @brief get TDG delay output offset value + * + * @param[in] tdgId + * @param[in] channelId: select channel id + * @param[in] doId: select delay output id + * + * @return delay value + * + */ +uint16_t TDG_GetChannelOffsetVal(TDG_ID_t tdgId, TDG_ChannelId_t channelId, + TDG_DelayOutputId_t doId) +{ + tdg_reg_w_t const volatile *TDGxw = (tdg_reg_w_t *)(tdgRegWPtr[tdgId]); + + uint32_t offsetVal; + + uint32_t delOutId = (uint32_t)doId; + + offsetVal = (TDGxw->TDG_CHCFG[channelId].TDG_CHDOOFS[delOutId]) & 0xFFFFU; + + return (uint16_t)offsetVal; +} + +/** + * @brief Clear TDG channel delay output function + * + * @param[in] tdgId + * @param[in] channelId: select channel + * + * @return none + * + */ +void TDG_ClearChannelDelayOutput(TDG_ID_t tdgId, TDG_ChannelId_t channelId) +{ + tdg_reg_w_t *TDGxw = (tdg_reg_w_t *)(tdgRegWPtr[tdgId]); + /* clear TDG Delay Output Complete Interrupt Delay */ + TDG_SetIntDelayVal(tdgId, channelId, 0U); + /*clear channel offset */ + for (uint8_t i = 0U; i < 8U; i++) + { + TDGxw->TDG_CHCFG[channelId].TDG_CHDOOFS[i] = 0U; + } +} + +/** + * @brief TDG channel delay output config function + * + * @param[in] tdgId + * @param[in] config: select delay output + * @param[in] ControlState_t: channel ENABLE/DISABLE + * + * @return none + * + */ +void TDG_ChannelDelayOutputConfig(TDG_ID_t tdgId, + const TDG_ChannelConfig_t *config, + ControlState_t cmd) +{ + uint8_t i; + uint16_t delayValue; + + delayValue = config->intDelayVal; + TDG_SetIntDelayVal(tdgId, config->channelId, delayValue); + + for (i = 0U; i < config->doNum; i++) + { + TDG_DelayOuputConfig(tdgId, config->channelId, &(config->doConfig[i])); + } + + TDG_ChannelEnable(tdgId, config->channelId, cmd); +} + +/** + * @brief TDG get interrupt delay config load complete status Function + * + * @param[in] tdgId + * @param[in] channelId: Selcct channel type. + * + * @return intstatus + * + */ +IntStatus_t TDG_GetDelayStatus(TDG_ID_t tdgId, TDG_ChannelId_t channelId) +{ + tdg_reg_t const volatile *TDGx = (tdg_reg_t *)(tdgRegPtr[tdgId]); + + return ((IntStatus_t)TDGx->TDG_CHCFG[channelId].TDG_CHDOCINTDLY.LDCO); +} + +/** + * @brief TDG get channel number Function + * + * @param[in] tdgId + * + * @return channel number + * + */ +uint8_t TDG_GetCHNum(TDG_ID_t tdgId) +{ + tdg_reg_t const volatile *TDGx = (tdg_reg_t *)(tdgRegPtr[tdgId]); + + return ((uint8_t)TDGx->TDG_PARAM.CHNUM); +} + +/** + * @brief TDG get delay output point Function + * + * @param[in] tdgId + * + * @return delay output point + * + */ +uint8_t TDG_GetDoNum(TDG_ID_t tdgId) +{ + tdg_reg_t const volatile *TDGx = (tdg_reg_t *)(tdgRegPtr[tdgId]); + + return ((uint8_t)TDGx->TDG_PARAM.DOPNUM); +} + +/** + * @brief TDG INT callback Function + * + * @param[in] tdgId + * @param[in] intType: Selcct interrupt type. + * @param[in] cbFun: callback function . + * + * @return none + * + */ +void TDG_InstallCallBackFunc(TDG_ID_t tdgId, TDG_INT_t intType, isr_cb_t *cbFun) +{ + tdgIsrCbFunc[tdgId][intType] = cbFun; +} + +/** @} end of group TDG_Public_Functions */ + +/** @} end of group TDG_definitions */ + +/** @} end of group Z20K11X_Peripheral_Driver */ diff --git a/StdDriver/Src/Z20K11xM_tim.c b/StdDriver/Src/Z20K11xM_tim.c new file mode 100644 index 0000000..5c1cfa9 --- /dev/null +++ b/StdDriver/Src/Z20K11xM_tim.c @@ -0,0 +1,2137 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_tim.c + * @brief : TIM module driver file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ + +#include "Z20K11xM_tim.h" + +/** @addtogroup Z20K11X_Peripheral_Driver + * @{ + */ + +/** @defgroup TIM TIM + * @brief TIM driver modules + * @{ + */ + +/** @defgroup TIM_Private_Type + * @{ + */ + +/*@} end of group TIM_Private_Type*/ + +/** @defgroup TIM_Private_Defines + * @{ + */ +#define TIM_NUM_ALL 0x3U +#define TIM_CH_INT_MASK (0x00000020U) +#define TIM_RLDF_INT_MASK (0x00000100U) +#define TIM_TOF_INT_MASK (0x00000200U) +#define TIM_FAULT_INT_MASK (0x00000010U) + + +/*@} end of group TIM_Private_Defines */ + +/** @defgroup TIM_Private_Variables + * @{ + */ +/** + * @brief TIM0, TIM1, TIM2, TIM3 address array + */ +/*PRQA S 0303,0306 ++*/ +static tim_reg_t *const timRegPtr[TIM_NUM_ALL] = +{ + (tim_reg_t *)TIM0_BASE_ADDR, + (tim_reg_t *)TIM1_BASE_ADDR, + (tim_reg_t *)TIM2_BASE_ADDR +}; +/*PRQA S 0303,0306 --*/ + +/** + * @brief TIM0, TIM1, TIM2, TIM3 address array + */ +/*PRQA S 0303,0306 ++*/ +static tim_reg_w_t *const timRegWPtr[TIM_NUM_ALL] = +{ + (tim_reg_w_t *)TIM0_BASE_ADDR, + (tim_reg_w_t *)TIM1_BASE_ADDR, + (tim_reg_w_t *)TIM2_BASE_ADDR +}; +/*PRQA S 0303,0306 --*/ + +static isr_cb_t * timIsrCbFunc[TIM_NUM_ALL][TIM_INT_ALL] = +{ + {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}, + {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}, + {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL} +}; + +/*@} end of group TIM_Private_Variables */ + +/** @defgroup TIM_Global_Variables + * @{ + */ + +/*@} end of group TIM_Global_Variables */ + +/** @defgroup TIM_Private_FunctionDeclaration + * @{ + */ +void TIM0_DriverIRQHandler(void); +void TIM1_DriverIRQHandler(void); +void TIM2_DriverIRQHandler(void); +static void TIM_IntHandler(TIM_ID_t timId); +/*@} end of group TIM_Private_FunctionDeclaration */ + +/** @defgroup TIM_Private_Functions + * @{ + */ +/** + * @brief TIM interrupt handle + * + * @param[in] timId: Select the TIM ID + * + * @return none + * + */ +static void TIM_IntHandler(TIM_ID_t timId) +{ + uint32_t timChannel = 0U; + uint32_t intStatus = 0U; + uint32_t intFaultStatus = 0U; + uint32_t timIntStatus = 0U; + tim_reg_t * TIMx = timRegPtr[timId]; + tim_reg_w_t * TIMw = timRegWPtr[timId]; + /* Check the parameters */ + + const uint32_t timIntMaskTable[] = + { + 0x00000001U, /*!< TIM_INT_CH0 */ + 0x00000002U, /*!< TIM_INT_CH1 */ + 0x00000004U, /*!< TIM_INT_CH2 */ + 0x00000008U, /*!< TIM_INT_CH3 */ + 0x00000010U, /*!< TIM_INT_CH4 */ + 0x00000020U, /*!< TIM_INT_CH5 */ + 0x00000040U, /*!< TIM_INT_CH6 */ + 0x00000080U, /*!< TIM_INT_CH7 */ + 0x00000100U, /*!< TIM_INT_RLD */ + 0x00000200U, /*!< TIM_INT_TO */ + 0x00000010U, /*!< TIM_INT_FAULT */ + 0x000003FFU /*!< TIM_INT_ALL except TIM_INT_FAULT*/ + }; + + intStatus = TIMw->TIM_GLBSR & timIntMaskTable[TIM_INT_ALL]; + intFaultStatus = TIMw->TIM_FLTSR & timIntMaskTable[TIM_INT_FAULT]; + + for (timChannel = 0U; timChannel <= 7U; timChannel++) + { + if ((0U != (intStatus & ((uint32_t)1U << timChannel))) && (1U == TIMx->TIM_CMCn[timChannel].CHIE)) + { + /* get interrupt status */ + timIntStatus = TIMw->TIM_CMCn[timChannel]; + /* only check enabled interrupts */ + timIntStatus = timIntStatus & (~(TIM_CH_INT_MASK)); + /* clear interrupt status */ + TIMw->TIM_CMCn[timChannel] = timIntStatus; + if(timIsrCbFunc[timId][timChannel] != NULL) + { + /* call the callback function */ + timIsrCbFunc[timId][timChannel](); + } + /* Disable the interrupt if callback function is not setup */ + else + { + TIMx->TIM_CMCn[timChannel].CHIE = 0U; + } + } + } + + /* Reload Interrupt */ + if(((intStatus & timIntMaskTable[TIM_INT_RLD]) != 0U) && (1U == TIMx->TIM_GLBCR.RLDIE)) + { + /* get interrupt status */ + timIntStatus = TIMw->TIM_GLBSR; + /* only check enabled interrupts */ + timIntStatus = timIntStatus & (~(TIM_RLDF_INT_MASK)); + /* clear interrupt status */ + TIMw->TIM_GLBSR = timIntStatus; + if(timIsrCbFunc[timId][TIM_INT_RLD] != NULL) + { + /* call the callback function */ + timIsrCbFunc[timId][TIM_INT_RLD](); + } + /* Disable the interrupt if callback function is not setup */ + else + { + TIMx->TIM_GLBCR.RLDIE = 0U; + } + } + + /* Timer overlop Interrupt */ + if(((intStatus & timIntMaskTable[TIM_INT_TO]) != 0U) && (1U == TIMx->TIM_GLBCR.TOIE)) + { + /* get interrupt status */ + timIntStatus = TIMw->TIM_GLBSR; + /* only check enabled interrupts */ + timIntStatus = timIntStatus & (~(TIM_TOF_INT_MASK)); + /* clear interrupt status */ + TIMw->TIM_GLBSR = timIntStatus; + if(timIsrCbFunc[timId][TIM_INT_TO] != NULL) + { + /* call the callback function */ + timIsrCbFunc[timId][TIM_INT_TO](); + } + /* Disable the interrupt if callback function is not setup */ + else + { + TIMx->TIM_GLBCR.TOIE = 0U; + } + } + + /* Fault Control Interrupt */ + if(((intFaultStatus & timIntMaskTable[TIM_INT_FAULT]) != 0U) && (1U == TIMx->TIM_FLTCR.FLTIE)) + { + /* get interrupt status */ + timIntStatus = TIMw->TIM_FLTSR; + /* only check enabled interrupts */ + timIntStatus = timIntStatus & (~(TIM_FAULT_INT_MASK)); + /* clear interrupt status */ + TIMw->TIM_FLTSR = timIntStatus; + if(timIsrCbFunc[timId][TIM_INT_FAULT] != NULL) + { + /* call the callback function */ + timIsrCbFunc[timId][TIM_INT_FAULT](); + } + /* Disable the interrupt if callback function is not setup */ + else + { + TIMx->TIM_FLTCR.FLTIE = 0U; + } + } + +} + +/** + * @brief TIM0 IRQHandler + * + * @param[in] none + * + * @return none + * + */ +void TIM0_DriverIRQHandler(void) +{ + TIM_IntHandler(TIM0_ID); +} + +/** + * @brief TIM1 IRQHandler + * + * @param[in] none + * + * @return none + * + */ +void TIM1_DriverIRQHandler(void) +{ + TIM_IntHandler(TIM1_ID); +} + +/** + * @brief TIM2 IRQHandler + * + * @param[in] none + * + * @return none + * + */ +void TIM2_DriverIRQHandler(void) +{ + TIM_IntHandler(TIM2_ID); +} + + +/** + * @brief TIM Set Combine enable/disable Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] pairId: Select paired id . + * @param[in] cmd: enable/disable. + * + * @return none + * + */ +static inline void TIM_SetCombineCmd(TIM_ID_t timId, TIM_PairId_t pairId, ControlState_t cmd) +{ + tim_reg_t * TIMx = timRegPtr[timId]; + + switch (pairId) + { + case TIM_PAIR_CHANNEL_0: + TIMx->TIM_PCR.COMB0 = (uint32_t)cmd; + break; + + case TIM_PAIR_CHANNEL_1: + TIMx->TIM_PCR.COMB1 = (uint32_t)cmd; + break; + + case TIM_PAIR_CHANNEL_2: + TIMx->TIM_PCR.COMB2 = (uint32_t)cmd; + break; + + case TIM_PAIR_CHANNEL_3: + TIMx->TIM_PCR.COMB3 = (uint32_t)cmd; + break; + + default: + /* do nothing */ + break; + + } +} + +/** + * @brief TIM Set deadtime function enable/disable Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] pairId: Select paired id . + * @param[in] cmd: enable/disable. + * + * @return none + * + */ +static inline void TIM_SetDeadTimeCmd(TIM_ID_t timId, TIM_PairId_t pairId, ControlState_t cmd) +{ + tim_reg_t * TIMx = timRegPtr[timId]; + + switch (pairId) + { + case TIM_PAIR_CHANNEL_0: + TIMx->TIM_PCR.DTEN0 = (uint32_t)cmd; + break; + + case TIM_PAIR_CHANNEL_1: + TIMx->TIM_PCR.DTEN1 = (uint32_t)cmd; + break; + + case TIM_PAIR_CHANNEL_2: + TIMx->TIM_PCR.DTEN2 = (uint32_t)cmd; + break; + + case TIM_PAIR_CHANNEL_3: + TIMx->TIM_PCR.DTEN3 = (uint32_t)cmd; + break; + + default: + /* do nothing */ + break; + + } +} + +/** + * @brief TIM Set fault control enable/disable Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] pairId: Select paired id . + * @param[in] cmd: enable/disable. + * + * @return none + * + */ +static inline void TIM_SetFaultCtrlCmd(TIM_ID_t timId, TIM_PairId_t pairId, ControlState_t cmd) +{ + tim_reg_t * TIMx = timRegPtr[timId]; + + switch (pairId) + { + case TIM_PAIR_CHANNEL_0: + TIMx->TIM_PCR.FCTLEN0 = (uint32_t)cmd; + break; + + case TIM_PAIR_CHANNEL_1: + TIMx->TIM_PCR.FCTLEN1 = (uint32_t)cmd; + break; + + case TIM_PAIR_CHANNEL_2: + TIMx->TIM_PCR.FCTLEN2 = (uint32_t)cmd; + break; + + case TIM_PAIR_CHANNEL_3: + TIMx->TIM_PCR.FCTLEN3 = (uint32_t)cmd; + break; + + default: + /* do nothing */ + break; + + } +} + +/** + * @brief TIM Set Sync CCV register enable/disable Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] pairId: Select paired id . + * @param[in] cmd: enable/disable. + * + * @return none + * + */ +static inline void TIM_SetSyncPairCCVCmd(TIM_ID_t timId, TIM_PairId_t pairId, ControlState_t cmd) +{ + tim_reg_t * TIMx = timRegPtr[timId]; + + switch (pairId) + { + case TIM_PAIR_CHANNEL_0: + TIMx->TIM_PCR.SYNCEN0 = (uint32_t)cmd; + break; + + case TIM_PAIR_CHANNEL_1: + TIMx->TIM_PCR.SYNCEN1 = (uint32_t)cmd; + break; + + case TIM_PAIR_CHANNEL_2: + TIMx->TIM_PCR.SYNCEN2 = (uint32_t)cmd; + break; + + case TIM_PAIR_CHANNEL_3: + TIMx->TIM_PCR.SYNCEN3 = (uint32_t)cmd; + break; + + default: + /* do nothing */ + break; + + } +} + +/** + * @brief TIM Set dual edge capture function enable/disable Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] pairId: Select paired id . + * @param[in] cmd: enable/disable. + * + * @return none + * + */ +static inline void TIM_SetDualEdgeCaptureCmd(TIM_ID_t timId, TIM_PairId_t pairId, + ControlState_t cmd) +{ + tim_reg_t * TIMx = timRegPtr[timId]; + + switch (pairId) + { + case TIM_PAIR_CHANNEL_0: + TIMx->TIM_PCR.DECAPEN0 = (uint32_t)cmd; + break; + + case TIM_PAIR_CHANNEL_1: + TIMx->TIM_PCR.DECAPEN1 = (uint32_t)cmd; + break; + + case TIM_PAIR_CHANNEL_2: + TIMx->TIM_PCR.DECAPEN2 = (uint32_t)cmd; + break; + + case TIM_PAIR_CHANNEL_3: + TIMx->TIM_PCR.DECAPEN3 = (uint32_t)cmd; + break; + + default: + /* do nothing */ + break; + + } +} + +/** + * @brief TIM Set dual edge decap enable/disable Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] pairId: Select paired id . + * @param[in] cmd: enable/disable. + * + * @return none + * + */ +static inline void TIM_SetDualEdgeDecapCmd(TIM_ID_t timId, TIM_PairId_t pairId, + ControlState_t cmd) +{ + tim_reg_t * TIMx = timRegPtr[timId]; + + switch (pairId) + { + case TIM_PAIR_CHANNEL_0: + TIMx->TIM_PCR.DECAP0 = (uint32_t)cmd; + break; + + case TIM_PAIR_CHANNEL_1: + TIMx->TIM_PCR.DECAP1 = (uint32_t)cmd; + break; + + case TIM_PAIR_CHANNEL_2: + TIMx->TIM_PCR.DECAP2 = (uint32_t)cmd; + break; + + case TIM_PAIR_CHANNEL_3: + TIMx->TIM_PCR.DECAP3 = (uint32_t)cmd; + break; + + default: + /* do nothing */ + break; + + } +} + +/** + * @brief TIM Set input filter Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] channelId: Select channel id . + * @param[in] filter: filter value. + * + * @return none + * + */ +static inline void TIM_SetInputFilter(TIM_ID_t timId, TIM_ChannelId_t channelId, + TIM_Filter_t filter) +{ + tim_reg_t * TIMx = timRegPtr[timId]; + + switch (channelId) + { + case TIM_CHANNEL_0: + TIMx->TIM_FILTER.FILVAL0 = (uint32_t)filter; + break; + + case TIM_CHANNEL_1: + TIMx->TIM_FILTER.FILVAL1 = (uint32_t)filter; + break; + + case TIM_CHANNEL_2: + TIMx->TIM_FILTER.FILVAL2 = (uint32_t)filter; + break; + + case TIM_CHANNEL_3: + TIMx->TIM_FILTER.FILVAL3 = (uint32_t)filter; + break; + + default: + /* do nothing */ + break; + + } +} + +/** + * @brief TIM Set output polarity Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] channelId: Select channel id . + * @param[in] polarity: polarity value. + * + * @return none + * + */ +static inline void TIM_SetOutputPolarity(TIM_ID_t timId, TIM_ChannelId_t channelId, + TIM_Polarity_t polarity) +{ + tim_reg_t * TIMx = timRegPtr[timId]; + + switch (channelId) + { + case TIM_CHANNEL_0: + TIMx->TIM_OUTCR.POL0 = (uint32_t)polarity; + break; + + case TIM_CHANNEL_1: + TIMx->TIM_OUTCR.POL1 = (uint32_t)polarity; + break; + + case TIM_CHANNEL_2: + TIMx->TIM_OUTCR.POL2 = (uint32_t)polarity; + break; + + case TIM_CHANNEL_3: + TIMx->TIM_OUTCR.POL3 = (uint32_t)polarity; + break; + case TIM_CHANNEL_4: + TIMx->TIM_OUTCR.POL4 = (uint32_t)polarity; + break; + + case TIM_CHANNEL_5: + TIMx->TIM_OUTCR.POL5 = (uint32_t)polarity; + break; + + case TIM_CHANNEL_6: + TIMx->TIM_OUTCR.POL6 = (uint32_t)polarity; + break; + + case TIM_CHANNEL_7: + TIMx->TIM_OUTCR.POL7 = (uint32_t)polarity; + break; + + default: + /* do nothing */ + break; + + } +} + +/** + * @brief TIM Set output init value Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] channelId: Select channel id . + * @param[in] val: level value. + * + * @return none + * + */ +static inline void TIM_SetOutputInitValue(TIM_ID_t timId, TIM_ChannelId_t channelId, + Level_t val) +{ + tim_reg_t * TIMx = timRegPtr[timId]; + + switch (channelId) + { + case TIM_CHANNEL_0: + TIMx->TIM_OUTCR.INIT0 = (uint32_t)val; + break; + + case TIM_CHANNEL_1: + TIMx->TIM_OUTCR.INIT1 = (uint32_t)val; + break; + + case TIM_CHANNEL_2: + TIMx->TIM_OUTCR.INIT2 = (uint32_t)val; + break; + + case TIM_CHANNEL_3: + TIMx->TIM_OUTCR.INIT3 = (uint32_t)val; + break; + case TIM_CHANNEL_4: + TIMx->TIM_OUTCR.INIT4 = (uint32_t)val; + break; + + case TIM_CHANNEL_5: + TIMx->TIM_OUTCR.INIT5 = (uint32_t)val; + break; + + case TIM_CHANNEL_6: + TIMx->TIM_OUTCR.INIT6 = (uint32_t)val; + break; + + case TIM_CHANNEL_7: + TIMx->TIM_OUTCR.INIT7 = (uint32_t)val; + break; + + default: + /* do nothing */ + break; + + } +} + +/*@} end of group TIM_Private_Functions */ + + +/** @defgroup TIM_Public_Functions + * @{ + */ + +/** + * @brief TIM WriteProtection Enable Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * + * @return none + * + */ +void TIM_WriteProtectionEnable(TIM_ID_t timId) +{ + tim_reg_t * TIMx = timRegPtr[timId]; + + TIMx->TIM_FLTSR.WPEN = (uint32_t)1UL; +} + +/** + * @brief TIM WriteProtection Disable Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * + * @return none + * + */ +void TIM_WriteProtectionDisable(TIM_ID_t timId) +{ + tim_reg_t * TIMx = timRegPtr[timId]; + + TIMx->TIM_GLBSR.WPDIS = (uint32_t)1UL; +} + +/** + * @brief Init TIMER Counter with initial value and max value + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] initialVal: Counter init value. + * @param[in] maxVal: Counter max value, also named mod value. + * + * @return none + * + */ +void TIM_InitCounter(TIM_ID_t timId, uint16_t initialVal, uint16_t maxVal) +{ + tim_reg_t * TIMx = timRegPtr[timId]; + + TIMx->TIM_CNTINIT.CNTINIT = initialVal; + + TIMx->TIM_MOD.MOD = maxVal; +} + +/** + * @brief TIM Start counter with clock configuration + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] clkSource: Select TIM clock source: + * - TIM_CLK_SOURCE_SYSTEM + * - TIM_CLK_SOURCE_FUNCTION + * - TIM_CLK_SOURCE_EXTERNAL + * @param[in] divider: Select TIM clock divider. + * - 000b: Divide by 1 + * - 001b: Divide by 2 + * - 010b: Divide by 4 + * - 011b: Divide by 8 + * - 100b: Divide by 16 + * - 101b: Divide by 32 + * - 110b: Divide by 64 + * - 111b: Divide by 128 + * + * @return none + * + */ +void TIM_StartCounter(TIM_ID_t timId, TIM_ClkSource_t clkSource, + TIM_ClkDivide_t divider) +{ + tim_reg_t * TIMx = timRegPtr[timId]; + + TIMx->TIM_TIMEBASE.CKSRC = (uint32_t)clkSource; + TIMx->TIM_TIMEBASE.PSDIV = (uint32_t)divider; +} + +/** + * @brief TIM exernal clock source configuration + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] clkSource: Select TIM external clock source + * + * @return none + * + */ +void TIM_ExternalCounterSelect(TIM_ID_t timId, TIM_ExternalSource_t clkSource) +{ + /*PRQA S 0303,0306 ++*/ + scm_reg_t *const SCMx = (scm_reg_t *)SCM_BASE_ADDR; + /*PRQA S 0303,0306 --*/ + + if(TIM0_ID == timId ) + { + SCMx->SCM_TIMOPT.TIM0_CLK_SEL = (uint32_t)clkSource; + } + else if(TIM1_ID == timId ) + { + SCMx->SCM_TIMOPT.TIM1_CLK_SEL = (uint32_t)clkSource; + } + else + { + SCMx->SCM_TIMOPT.TIM2_CLK_SEL = (uint32_t)clkSource; + } + +} + +/** + * @brief TIM Stop counter + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * + * @return none + * + */ +void TIM_StopCounter(TIM_ID_t timId) +{ + tim_reg_t * TIMx = timRegPtr[timId]; + + TIMx->TIM_TIMEBASE.CKSRC = (uint32_t)0UL; +} + +/** + * @brief TIM Set Counter Init Value Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] initialVal: Counter init value. + * + * @return none + * + */ + +void TIM_SetCounterInitialVal(TIM_ID_t timId, uint16_t initialVal) +{ + tim_reg_t * TIMx = timRegPtr[timId]; + + TIMx->TIM_CNTINIT.CNTINIT = initialVal; +} + +/** + * @brief TIM Load Counter Init Value Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * + * @return none + * + */ +void TIM_LoadCounterInitialVal(TIM_ID_t timId) +{ + tim_reg_t * TIMx = timRegPtr[timId]; + + TIMx->TIM_CNT.CNT = (uint16_t)0x0U; +} + +/** + * @brief TIM Get Counter Init Value Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * + * @return Counter Init Value + * + */ +uint16_t TIM_GetCounterInitialVal(TIM_ID_t timId) +{ + tim_reg_t const volatile* TIMx = timRegPtr[timId]; + + return (uint16_t)TIMx->TIM_CNTINIT.CNTINIT; +} + +/** + * @brief TIM Set Counter Mod Value Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] modVal: Counter MOD value. + * + * @return none + * + */ +void TIM_SetCounterModVal(TIM_ID_t timId, uint16_t modVal) +{ + tim_reg_t * TIMx = timRegPtr[timId]; + + TIMx->TIM_MOD.MOD = modVal; +} + +/** + * @brief TIM Get Counter MOD Value Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * + * @return Counter MOD Value + * + */ +uint16_t TIM_GetCounterModVal(TIM_ID_t timId) +{ + tim_reg_t const volatile* TIMx = timRegPtr[timId]; + + return (uint16_t)TIMx->TIM_MOD.MOD; +} + +/** + * @brief TIM Set Capture and Compare Value Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] channelId:Selcct channel ID. + * @param[in] ccVal: Capture and Compare Value. + * + * @return none + * + */ +void TIM_SetCCVal(TIM_ID_t timId, TIM_ChannelId_t channelId, uint16_t ccVal) +{ + tim_reg_t * TIMx = timRegPtr[timId]; + + TIMx->TIM_CCVn[channelId].CCV = ccVal; +} + +/** + * @brief TIM Get Capture and Compare Value Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] channelId: Selcct channel ID. + * + * @return Capture and Compare Value + * + */ +uint16_t TIM_GetCCVal(TIM_ID_t timId, TIM_ChannelId_t channelId) +{ + tim_reg_t const volatile* TIMx = timRegPtr[timId]; + + return (uint16_t)TIMx->TIM_CCVn[channelId].CCV; +} + +/** + * @brief TIM Set Half Cycle Value Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] hcVal: Half Cycle value. + * + * @return none + * + */ +void TIM_SetHCVal(TIM_ID_t timId, uint16_t hcVal) +{ + tim_reg_t * TIMx = timRegPtr[timId]; + + TIMx->TIM_HCV.HCV = hcVal; +} + +/** + * @brief TIM Get Half Cycle Value Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * + * @return Half Cycle Value + * + */ +uint16_t TIM_GetHCVal(TIM_ID_t timId) +{ + tim_reg_t const volatile* TIMx = timRegPtr[timId]; + + return (uint16_t)TIMx->TIM_HCV.HCV; +} + +/** + * @brief TIM Set Output Software Control Register Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] swCtrlCmd: Output Software Control Cmd. + * + * @return none + * + */ +void TIM_SetOutputSwControl(TIM_ID_t timId, uint8_t swCtrlCmd) +{ + tim_reg_w_t * TIMw = timRegWPtr[timId]; + uint32_t regVal = TIMw->TIM_OUTSWCR ; + + regVal |= (uint32_t)swCtrlCmd; + TIMw->TIM_OUTSWCR = regVal; +} + +/** + * @brief TIM Set Output Software Control Value Register Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] swCtrlVal: Output Software Control value. + * + * @return none + * + */ +void TIM_SetOutputSwCtrlVal(TIM_ID_t timId, uint8_t swCtrlVal) +{ + tim_reg_w_t * TIMw = timRegWPtr[timId]; + uint32_t regVal = TIMw->TIM_OUTSWCR; + + regVal |= ((uint32_t)swCtrlVal << 8); + TIMw->TIM_OUTSWCR = regVal; +} + +/** + * @brief TIM Get Output Software Control Register Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * + * @return Output Software Control Cmd. + * + */ +uint8_t TIM_GetOutputSwControl(TIM_ID_t timId) +{ + tim_reg_w_t const volatile* TIMw = timRegWPtr[timId]; + + return (uint8_t) (TIMw->TIM_OUTSWCR & 0x000000FFUL); +} + +/** + * @brief TIM Get Output Software Control Register Value Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * + * @return Output Software Control Cmd. + * + */ +uint8_t TIM_GetOutputSwCtrlVal(TIM_ID_t timId) +{ + tim_reg_w_t const volatile* TIMw = timRegWPtr[timId]; + + return (uint8_t) ((TIMw->TIM_OUTSWCR & 0x0000FF00UL) >> 8); +} + +/** + * @brief TIM output software control config Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] channelId:Select Channel Id. + * @param[in] config: Pointer to software control config. + * + * @return none + * + */ +void TIM_OutputSWCtrlConfig(TIM_ID_t timId, TIM_ChannelId_t channelId, + const TIM_OutputSWCtrlConfig_t* config) +{ + tim_reg_w_t * TIMw = timRegWPtr[timId]; + + volatile uint16_t regValue = 0U; + uint16_t regLow = ((uint16_t)0x1U) << (uint16_t)channelId ; + uint16_t regHigh= ((uint16_t)0x1U) << ((uint16_t)channelId + (uint16_t)8U); + uint8_t pairId = (uint8_t)channelId >> 1U; + + TIM_SetDualEdgeCaptureCmd(timId, (TIM_PairId_t)pairId, DISABLE); + + regValue = (uint16_t)TIMw->TIM_OUTSWCR; + + if((ENABLE == config->outputSWCtrlEnable) && (HIGH_LEVEL == config ->outputSWCtrlVal)) + { + regValue = regLow | regHigh | regValue; + } + else if((DISABLE == config->outputSWCtrlEnable) && (HIGH_LEVEL == config ->outputSWCtrlVal)) + { + regValue = regHigh | regValue; + regValue &= ~regLow; + } + + else if((ENABLE == config->outputSWCtrlEnable) && (LOW_LEVEL == config ->outputSWCtrlVal)) + { + regValue = regLow | regValue; + regValue &= ~regHigh; + } + else + { + regValue &= ~(regLow | regHigh) ; + } + + TIMw->TIM_OUTSWCR = regValue; +} + +/** + * @brief TIM 16-bit Counter Counting Mode Config Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] cntMode: Counting Mode Param. + * - TIM_COUNTING_UP + * - TIM_COUNTING_UP_DOWN + * + * @return none + * + */ +void TIM_CountingModeConfig(TIM_ID_t timId, TIM_CountingMode_t cntMode) +{ + tim_reg_t * TIMx = timRegPtr[timId]; + + TIMx->TIM_GLBCR.CNTMODE = (uint32_t)cntMode; +} + +/** + * @brief TIM Initialize the channels output Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * + * @return none + * + */ +void TIM_InitChannelsOutput(TIM_ID_t timId) +{ + tim_reg_t * TIMx = timRegPtr[timId]; + + TIMx->TIM_GLBCR.INIT = 1; +} + +/** + * @brief TIM initialise input capture mode config Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] config: Pointer to input capture config. + * + * @return none + * + */ +void TIM_InputCaptureInit(TIM_ID_t timId, const TIM_InputCaptureConfig_t * config) +{ + tim_reg_t * TIMx = timRegPtr[timId]; + uint8_t i; + TIM_ChannelId_t channelId; + uint8_t pairId; + + TIMx->TIM_GLBCR.CNTMODE = 0; + + TIMx->TIM_MOD.MOD = config->maxCounterVal; + + for(i = 0; i < config->numChannels; i++) + { + channelId = config->inputChConfig[i].channelId; + pairId = (uint8_t)channelId >> 1U; + + TIM_SetCombineCmd(timId, (TIM_PairId_t)pairId, DISABLE); + TIM_SetDualEdgeCaptureCmd(timId, (TIM_PairId_t)pairId, DISABLE); + TIMx->TIM_CMCn[channelId].CMS = 0U; + TIMx->TIM_CMCn[channelId].ELS = (uint32_t)config->inputChConfig[i].edgeConfig; + TIMx->TIM_CMCn[channelId].ICRST = (uint32_t)config->inputChConfig[i].resetEnable; + if(channelId < TIM_CHANNEL_4) + { + TIM_SetInputFilter(timId, channelId, config->inputChConfig[i].filter); + } + } +} + +/** + * @brief TIM initialise dual edge capture mode config Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] config: Pointer to dual edge capture config. + * + * @return none + * + */ +void TIM_DualEdgeCaptureInit(TIM_ID_t timId, const TIM_DualEdgeCaptureConfig_t * config) +{ + tim_reg_t * TIMx = timRegPtr[timId]; + uint32_t i; + uint8_t mainChannelId; + uint8_t secondChannelId; + TIM_PairId_t pairId; + + TIMx->TIM_GLBCR.CNTMODE = 0; + TIMx->TIM_MOD.MOD = config->maxCounterVal; + + for(i = 0; i < config->numPairs; i++) + { + pairId = config->config[i].pairId; + mainChannelId = (uint8_t)pairId << 1U; + secondChannelId = mainChannelId + 1U; + + TIM_SetCombineCmd(timId, pairId, DISABLE); + TIM_SetDualEdgeCaptureCmd(timId, pairId, ENABLE); + TIM_SetDualEdgeDecapCmd(timId, pairId, ENABLE); + TIM_SetCombineCmd(timId, pairId, DISABLE); + TIMx->TIM_CMCn[mainChannelId].CMS = (uint32_t)config->config[i].captureMode; + + TIMx->TIM_CMCn[mainChannelId].ELS = (uint32_t)config->config[i].mainEdgeConfig; + TIMx->TIM_CMCn[secondChannelId].ELS = (uint32_t)config->config[i].secondEdgeConfig; + + if(mainChannelId < (uint8_t)TIM_CHANNEL_4) + { + TIM_SetInputFilter(timId, (TIM_ChannelId_t)mainChannelId, config->config[i].filter); + } + } +} + +/** + * @brief TIM initialise output compare mode config Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] config: Pointer to output compare config. + * + * @return none + * + */ +void TIM_OutputCompareInit(TIM_ID_t timId, const TIM_OutputCompareConfig_t * config) +{ + tim_reg_t * TIMx = timRegPtr[timId]; + uint8_t i; + TIM_ChannelId_t channelId; + uint8_t pairId; + + + TIMx->TIM_GLBCR.CNTMODE = (uint32_t)0UL; + TIMx->TIM_MOD.MOD = config->maxCounterVal; + TIMx->TIM_OUTCR.INITRIGE = (uint32_t)config->initTriggerEnable; + + for(i = 0; i < config->numChannels; i++) + { + channelId = config->outputConfig[i].channelId; + pairId = (uint8_t)channelId >> 1; + + TIM_SetCombineCmd(timId, (TIM_PairId_t)pairId, DISABLE); + TIM_SetDualEdgeCaptureCmd(timId, (TIM_PairId_t)pairId, DISABLE); + TIMx->TIM_CMCn[channelId].CMS = 1; + TIMx->TIM_CMCn[channelId].ELS = (uint32_t)config->outputConfig[i].outputMode; + TIM_SetOutputPolarity(timId, channelId, config->outputConfig[i].polarity); + TIM_SetOutputInitValue(timId, channelId, config->outputConfig[i].initValue); + TIMx->TIM_CCVn[channelId].CCV = config->outputConfig[i].compareValue; + TIM_SetFaultCtrlCmd(timId, (TIM_PairId_t)pairId, config->faultCtrlChannelEnable); + } +} + +/** + * @brief TIM enable channel output Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] channelId:Select Channel Id. + * + * @return none + * + */ +void TIM_ChannelOutputEnable(TIM_ID_t timId, TIM_ChannelId_t channelId) +{ + tim_reg_t * TIMx = timRegPtr[timId]; + + switch (channelId) + { + case TIM_CHANNEL_0: + TIMx->TIM_GLBCR.CHOE0 = (uint32_t)ENABLE; + break; + + case TIM_CHANNEL_1: + TIMx->TIM_GLBCR.CHOE1 = (uint32_t)ENABLE; + break; + + case TIM_CHANNEL_2: + TIMx->TIM_GLBCR.CHOE2 = (uint32_t)ENABLE; + break; + + case TIM_CHANNEL_3: + TIMx->TIM_GLBCR.CHOE3 = (uint32_t)ENABLE; + break; + case TIM_CHANNEL_4: + TIMx->TIM_GLBCR.CHOE4 = (uint32_t)ENABLE; + break; + + case TIM_CHANNEL_5: + TIMx->TIM_GLBCR.CHOE5 = (uint32_t)ENABLE; + break; + + case TIM_CHANNEL_6: + TIMx->TIM_GLBCR.CHOE6 = (uint32_t)ENABLE; + break; + + case TIM_CHANNEL_7: + TIMx->TIM_GLBCR.CHOE7 = (uint32_t)ENABLE; + break; + + default: + /* do nothing */ + break; + + } +} + +/** + * @brief TIM disable channel output Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] channelId:Select Channel Id. + * + * @return none + * + */ +void TIM_ChannelOutputDisable(TIM_ID_t timId, TIM_ChannelId_t channelId) +{ + tim_reg_t * TIMx = timRegPtr[timId]; + + switch (channelId) + { + case TIM_CHANNEL_0: + TIMx->TIM_GLBCR.CHOE0 = (uint32_t)DISABLE; + break; + + case TIM_CHANNEL_1: + TIMx->TIM_GLBCR.CHOE1 = (uint32_t)DISABLE; + break; + + case TIM_CHANNEL_2: + TIMx->TIM_GLBCR.CHOE2 = (uint32_t)DISABLE; + break; + + case TIM_CHANNEL_3: + TIMx->TIM_GLBCR.CHOE3 = (uint32_t)DISABLE; + break; + case TIM_CHANNEL_4: + TIMx->TIM_GLBCR.CHOE4 = (uint32_t)DISABLE; + break; + + case TIM_CHANNEL_5: + TIMx->TIM_GLBCR.CHOE5 = (uint32_t)DISABLE; + break; + + case TIM_CHANNEL_6: + TIMx->TIM_GLBCR.CHOE6 = (uint32_t)DISABLE; + break; + + case TIM_CHANNEL_7: + TIMx->TIM_GLBCR.CHOE7 = (uint32_t)DISABLE; + break; + + default: + /* do nothing */ + break; + + } +} + +/** + * @brief TIM Set match trigger cmd enable/disable Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] channelId: Select channel id . + * @param[in] cmd: enable/disable. + * + * @return none + * + */ +void TIM_ChannelMatchTriggerCmd(TIM_ID_t timId, TIM_ChannelId_t channelId, + ControlState_t cmd) +{ + tim_reg_t * TIMx = timRegPtr[timId]; + + switch (channelId) + { + case TIM_CHANNEL_0: + TIMx->TIM_OUTCR.TRIGE0 = (uint32_t)cmd; + break; + + case TIM_CHANNEL_1: + TIMx->TIM_OUTCR.TRIGE1 = (uint32_t)cmd; + break; + + case TIM_CHANNEL_2: + TIMx->TIM_OUTCR.TRIGE2 = (uint32_t)cmd; + break; + + case TIM_CHANNEL_3: + TIMx->TIM_OUTCR.TRIGE3 = (uint32_t)cmd; + break; + case TIM_CHANNEL_4: + TIMx->TIM_OUTCR.TRIGE4 = (uint32_t)cmd; + break; + + case TIM_CHANNEL_5: + TIMx->TIM_OUTCR.TRIGE5 = (uint32_t)cmd; + break; + + case TIM_CHANNEL_6: + TIMx->TIM_OUTCR.TRIGE6 = (uint32_t)cmd; + break; + + case TIM_CHANNEL_7: + TIMx->TIM_OUTCR.TRIGE7 = (uint32_t)cmd; + break; + + default: + /* do nothing */ + break; + + } +} + +/** + * @brief TIM Set init trigger cmd enable/disable Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] cmd: enable/disable. + * + * @return none + * + */ +void TIM_InitTriggerCmd(TIM_ID_t timId, ControlState_t cmd) +{ + tim_reg_t * TIMx = timRegPtr[timId]; + + TIMx->TIM_OUTCR.INITRIGE = (uint32_t)cmd; +} + +/** + * @brief TIM get match trigger flag Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * + * @return flag status + * + */ +FlagStatus_t TIM_GetMatchTriggerFlag(TIM_ID_t timId) +{ + tim_reg_t const volatile* TIMx = timRegPtr[timId]; + + return (FlagStatus_t) TIMx->TIM_OUTCR.TRIGF; +} + +/** + * @brief TIM initialise center-aligned PWM output config Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] config: Pointer to center-aligned PWM output config. + * + * @return none + * + */ +void TIM_OutputCenterAlignedPwmConfig(TIM_ID_t timId, const TIM_PwmConfig_t * config) +{ + tim_reg_t * TIMx = timRegPtr[timId]; + uint8_t i; + TIM_ChannelId_t channelId; + uint8_t pairId; + + TIMx->TIM_GLBCR.CNTMODE = (uint32_t)1UL; + TIMx->TIM_MOD.MOD = config->maxCounterVal; + TIMx->TIM_CNTINIT.CNTINIT = config->minCounterVal; + + for(i = 0; i < config->numChannels; i++) + { + channelId = config->pwmChConfig[i].channelId; + pairId = (uint8_t)channelId >> 1U; + + TIM_SetCombineCmd(timId, (TIM_PairId_t)pairId, DISABLE); + TIM_SetDualEdgeCaptureCmd(timId, (TIM_PairId_t)pairId, DISABLE); + TIMx->TIM_CMCn[channelId].ELS = (uint32_t)config->pwmChConfig[i].pwmModeConfig; + TIM_SetOutputPolarity(timId, channelId, config->pwmChConfig[i].polarity); + TIMx->TIM_CCVn[channelId].CCV = config->pwmChConfig[i].compareValue; + TIM_SetFaultCtrlCmd(timId, (TIM_PairId_t)pairId, config->pwmChConfig[i].faultCtrlChannelEnable); + TIM_SetSyncPairCCVCmd(timId, (TIM_PairId_t)pairId, config->pwmChConfig[i].ccvUpdateEnable); + } +} + +/** + * @brief TIM initialise edge-aligned PWM output config Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] config: Pointer to edge-aligned PWM output config. + * + * @return none + * + */ +void TIM_OutputEdgeAlignedPwmConfig(TIM_ID_t timId, const TIM_PwmConfig_t * config) +{ + tim_reg_t * TIMx = timRegPtr[timId]; + uint8_t i; + TIM_ChannelId_t channelId; + uint8_t pairId; + + TIMx->TIM_GLBCR.CNTMODE = 0; + TIMx->TIM_MOD.MOD = config->maxCounterVal; + TIMx->TIM_CNTINIT.CNTINIT = config->minCounterVal; + + for(i = 0; i < config->numChannels; i++) + { + channelId = config->pwmChConfig[i].channelId; + pairId = (uint8_t)channelId >> 1; + + TIM_SetCombineCmd(timId, (TIM_PairId_t)pairId, DISABLE); + TIM_SetDualEdgeCaptureCmd(timId, (TIM_PairId_t)pairId, DISABLE); + TIMx->TIM_CMCn[channelId].CMS = 2; + TIMx->TIM_CMCn[channelId].ELS = (uint32_t)config->pwmChConfig[i].pwmModeConfig; + TIM_SetOutputPolarity(timId, channelId, config->pwmChConfig[i].polarity); + TIMx->TIM_CCVn[channelId].CCV = config->pwmChConfig[i].compareValue; + TIM_SetFaultCtrlCmd(timId, (TIM_PairId_t)pairId, config->pwmChConfig[i].faultCtrlChannelEnable); + TIM_SetSyncPairCCVCmd(timId, (TIM_PairId_t)pairId, config->pwmChConfig[i].ccvUpdateEnable); + } +} + +/** + * @brief TIM initialise complementary PWM output config Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] config: Pointer to complementary PWM output config. + * + * @return none + * + */ +void TIM_OutputComplementaryPwmConfig(TIM_ID_t timId, const TIM_CompPwmConfig_t * config) +{ + tim_reg_t * TIMx = timRegPtr[timId]; + uint8_t i; + uint8_t mainChannelId; + uint8_t secondChannelId; + TIM_PairId_t pairId; + + TIMx->TIM_GLBCR.CNTMODE = 0; + TIMx->TIM_MOD.MOD = config->maxCounterVal; + TIMx->TIM_CNTINIT.CNTINIT = config->minCounterVal; + /*dead time config*/ + TIMx->TIM_FILTER.DTPS = (uint32_t)config->deadTimePrescaler; + TIMx->TIM_FILTER.DTVAL = config->deadTimeVal; + + for(i = 0; i < config->numPairs; i++) + { + pairId = config->cPwmChConfig[i].pairId; + mainChannelId = (uint8_t)pairId << 1U; + secondChannelId = mainChannelId + 1U; + + TIM_SetCombineCmd(timId, pairId, ENABLE); + TIM_SetDualEdgeCaptureCmd(timId, pairId, DISABLE); + + TIMx->TIM_CMCn[mainChannelId].ELS = (uint32_t)config->cPwmChConfig[i].pwmModeConfig; + TIM_SetOutputPolarity(timId, (TIM_ChannelId_t)mainChannelId, config->cPwmChConfig[i].polarity); + TIM_SetOutputPolarity(timId, (TIM_ChannelId_t)secondChannelId, config->cPwmChConfig[i].polarity); + TIMx->TIM_CCVn[mainChannelId].CCV = config->cPwmChConfig[i].mainCompareValue; + TIMx->TIM_CCVn[secondChannelId].CCV = config->cPwmChConfig[i].secondCompareValue; + + TIM_SetDeadTimeCmd(timId, pairId, config->cPwmChConfig[i].deadtimeEnable); + TIM_SetFaultCtrlCmd(timId, pairId, config->cPwmChConfig[i].faultCtrlChannelEnable); + TIM_SetSyncPairCCVCmd(timId, pairId, config->cPwmChConfig[i].ccvUpdateEnable); + } +} + +/** + * @brief TIM initialise fault control config Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] config: Pointer to fault control config. + * + * @return none + * + */ +void TIM_FaultControlConfig(TIM_ID_t timId, const TIM_PwmFaultCtrlConfig_t * config) +{ + tim_reg_t * TIMx = timRegPtr[timId]; + + /*fault control config*/ + TIMx->TIM_FLTCR.FAULTEN0 = (uint32_t)config->faultChannelConfig[0].faultInputChannelEnable; + TIMx->TIM_FLTCR.FIFEN0 = (uint32_t)config->faultChannelConfig[0].faultInputFilterEnable; + TIMx->TIM_FLTCR.FLTPOL0 = (uint32_t)config->faultChannelConfig[0].faultInputPolarity; + TIMx->TIM_FLTCR.FAULTEN1 = (uint32_t)config->faultChannelConfig[1].faultInputChannelEnable; + TIMx->TIM_FLTCR.FIFEN1 = (uint32_t)config->faultChannelConfig[1].faultInputFilterEnable; + TIMx->TIM_FLTCR.FLTPOL1 = (uint32_t)config->faultChannelConfig[1].faultInputPolarity; + TIMx->TIM_FLTCR.FIFVAL = (uint32_t)config->faultFilterValue; + TIMx->TIM_FLTCR.FSTATE = (uint32_t)config->status; + TIMx->TIM_FLTCR.FLTCM = (uint32_t)config->faultClearMode; + TIMx->TIM_FLTCR.FLTCEN = (uint32_t)config->faultCtrlEnable; +} + +/** + * @brief TIM initialise fault control config Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] cmd: - ENABLE - DISABLE. + * + * @return none + * + */ +void TIM_FaultControlCmd(TIM_ID_t timId, ControlState_t cmd) +{ + tim_reg_t * TIMx = timRegPtr[timId]; + + TIMx->TIM_FLTCR.FLTCEN = (uint32_t)cmd; +} + +/** + * @brief TIM Software Trigger Sync Config Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] cmd: Enable/Disable. + * + * @return none + * + */ +void TIM_SWTriggerSyncCmd(TIM_ID_t timId, ControlState_t cmd) +{ + tim_reg_t * TIMx = timRegPtr[timId]; + + if(cmd == ENABLE) + { + TIMx->TIM_SYNC.SWWRBUF = 1U; + TIMx->TIM_SYNC.SWRSTCNT = 1U; + } + else + { + TIMx->TIM_SYNC.SWWRBUF = 0U; + TIMx->TIM_SYNC.SWRSTCNT = 0U; + } +} + +/** + * @brief TIM Reload Sync Config Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] cmd: Enable/Disable. + * + * @return none + * + */ +void TIM_ReloadSyncCmd(TIM_ID_t timId, ControlState_t cmd) +{ + tim_reg_t * TIMx = timRegPtr[timId]; + + if(cmd == ENABLE) + { + TIMx->TIM_RELOAD.LOADEN = 1U; + } + else + { + TIMx->TIM_RELOAD.LOADEN = 0U; + } +} + +/** + * @brief TIM PWM synchronization software trigger Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * + * @return none + * + */ +void TIM_SyncSoftwareTrigger(TIM_ID_t timId) +{ + tim_reg_t * TIMx = timRegPtr[timId]; + + TIMx->TIM_SYNC.SWTRIG = 1U; +} + +/** + * @brief TIM CNTINT update mode select Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] updateMode: update mode. + * + * @return none + * + */ +void TIM_CNTINTUpdateModeSelect(TIM_ID_t timId, TIM_RegUpdateMode_t updateMode) +{ + tim_reg_t * TIMx = timRegPtr[timId]; + + TIMx->TIM_SYNC.SYNCINIT = (uint32_t)updateMode; +} + +/** + * @brief TIM Output Software Control Register update mode select Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] updateMode: update mode. + * + * @return none + * + */ +void TIM_OSWCUpdateModeSelect(TIM_ID_t timId, TIM_RegUpdateMode_t updateMode) +{ + tim_reg_t * TIMx = timRegPtr[timId]; + + TIMx->TIM_SYNC.SYNCOSWC = (uint32_t)updateMode; +} + +/** + * @brief Enable/Disable TIM CCV register update function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] channelId: Select channel id . + * @param[in] cmd: enable/disable. + * + * @return none + * + */ +void TIM_CCVUpdateCmd(TIM_ID_t timId, TIM_ChannelId_t channelId, ControlState_t cmd) +{ + uint8_t pairId; + pairId = (uint8_t)channelId >> 1U; + TIM_SetSyncPairCCVCmd(timId, (TIM_PairId_t)pairId, cmd); +} + +/** + * @brief TIM Reload Param Config Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] reloadConfig: reload param. + * + * @return none + * + */ +void TIM_ReloadParamConfig(TIM_ID_t timId, const TIM_ReloadConfig_t* reloadConfig) +{ + tim_reg_t * TIMx = timRegPtr[timId]; + uint8_t i; + + switch (reloadConfig->reloadMode) + { + case TIM_RELOAD_FULL_CYCLE: + TIMx->TIM_RELOAD.HCSEL = 0U; + TIMx->TIM_RELOAD.CH0SEL = 0U; + TIMx->TIM_RELOAD.CH1SEL = 0U; + TIMx->TIM_RELOAD.CH2SEL = 0U; + TIMx->TIM_RELOAD.CH3SEL = 0U; + TIMx->TIM_RELOAD.CH4SEL = 0U; + TIMx->TIM_RELOAD.CH5SEL = 0U; + TIMx->TIM_RELOAD.CH6SEL = 0U; + TIMx->TIM_RELOAD.CH7SEL = 0U; + break; + + case TIM_RELOAD_HALF_CYCLE: + TIMx->TIM_RELOAD.HCSEL = 1U; + TIMx->TIM_RELOAD.CH0SEL = 0U; + TIMx->TIM_RELOAD.CH1SEL = 0U; + TIMx->TIM_RELOAD.CH2SEL = 0U; + TIMx->TIM_RELOAD.CH3SEL = 0U; + TIMx->TIM_RELOAD.CH4SEL = 0U; + TIMx->TIM_RELOAD.CH5SEL = 0U; + TIMx->TIM_RELOAD.CH6SEL = 0U; + TIMx->TIM_RELOAD.CH7SEL = 0U; + break; + + case TIM_RELOAD_CHANNEL_MATCH: + TIMx->TIM_RELOAD.HCSEL = 0U; + break; + + default: + /* do nothing */ + break; + } + + TIMx->TIM_RELOAD.LDFREQ = reloadConfig->loadFrequency; + + for(i=0; inumChannels; i++) + { + TIM_ChannleMatchReloadCmd(timId, + reloadConfig->channelMatchConfig[i].channelId, + reloadConfig->channelMatchConfig[i].channelMatchEnable); + } + +} + +/** + * @brief TIM Set channel match reload cmd enable/disable Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] channelId: Select channel id . + * @param[in] cmd: enable/disable. + * + * @return none + * + */ +void TIM_ChannleMatchReloadCmd(TIM_ID_t timId, TIM_ChannelId_t channelId, + ControlState_t cmd) +{ + tim_reg_t * TIMx = timRegPtr[timId]; + + switch (channelId) + { + case TIM_CHANNEL_0: + TIMx->TIM_RELOAD.CH0SEL = (uint32_t)cmd; + break; + + case TIM_CHANNEL_1: + TIMx->TIM_RELOAD.CH1SEL = (uint32_t)cmd; + break; + + case TIM_CHANNEL_2: + TIMx->TIM_RELOAD.CH2SEL = (uint32_t)cmd; + break; + + case TIM_CHANNEL_3: + TIMx->TIM_RELOAD.CH3SEL = (uint32_t)cmd; + break; + + case TIM_CHANNEL_4: + TIMx->TIM_RELOAD.CH4SEL = (uint32_t)cmd; + break; + + case TIM_CHANNEL_5: + TIMx->TIM_RELOAD.CH5SEL = (uint32_t)cmd; + break; + + case TIM_CHANNEL_6: + TIMx->TIM_RELOAD.CH6SEL = (uint32_t)cmd; + break; + + case TIM_CHANNEL_7: + TIMx->TIM_RELOAD.CH7SEL = (uint32_t)cmd; + break; + + default: + /* do nothing */ + break; + + } +} + +/** + * @brief TIM PWM Sync Configure Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] syncConfig: Pointer to sync configure struct. + * + * @return none + * + */ +void TIM_SyncConfig(TIM_ID_t timId, const TIM_PwmSyncConfig_t* syncConfig) +{ + TIM_CNTINTUpdateModeSelect(timId, syncConfig->cntinitSync); + + TIM_OSWCUpdateModeSelect(timId, syncConfig->outswcSync); + + TIM_SWTriggerSyncCmd(timId, syncConfig->syncSWTriggerEnable); + + if(ENABLE == syncConfig->syncReloadEnable) + { + TIM_ReloadParamConfig(timId, syncConfig->reloadConfig); + } + +} + +/** + * @brief TIM INT DMA enable/disable Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] channelId: Selcct channel ID. + * @param[in] cmd: enable/disable. + * + * @return none + * + */ +void TIM_DMACtrl(TIM_ID_t timId, TIM_ChannelId_t channelId, ControlState_t cmd) +{ + tim_reg_t * TIMx = timRegPtr[timId]; + + TIMx->TIM_CMCn[channelId].DMAEN = (uint32_t)cmd; +} + +/** + * @brief TIM INT mask/unmask Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] intType: Selcct interrupt type. + * @param[in] intMask: mask/unmask . + * + * @return none + * + */ +void TIM_IntMask(TIM_ID_t timId, TIM_INT_t intType, IntMask_t intMask) +{ + tim_reg_t * TIMx = timRegPtr[timId]; + ControlState_t cmd = (intMask == UNMASK) ? ENABLE : DISABLE; + + switch (intType) + { + case TIM_INT_CH0: + TIMx->TIM_CMCn[0].CHIE = (uint32_t)cmd; + break; + + case TIM_INT_CH1: + TIMx->TIM_CMCn[1].CHIE = (uint32_t)cmd; + break; + + case TIM_INT_CH2: + TIMx->TIM_CMCn[2].CHIE = (uint32_t)cmd; + break; + + case TIM_INT_CH3: + TIMx->TIM_CMCn[3].CHIE = (uint32_t)cmd; + break; + case TIM_INT_CH4: + TIMx->TIM_CMCn[4].CHIE = (uint32_t)cmd; + break; + + case TIM_INT_CH5: + TIMx->TIM_CMCn[5].CHIE = (uint32_t)cmd; + break; + + case TIM_INT_CH6: + TIMx->TIM_CMCn[6].CHIE = (uint32_t)cmd; + break; + + case TIM_INT_CH7: + TIMx->TIM_CMCn[7].CHIE = (uint32_t)cmd; + break; + + case TIM_INT_RLD: + TIMx->TIM_GLBCR.RLDIE = (uint32_t)cmd; + break; + + case TIM_INT_TO: + TIMx->TIM_GLBCR.TOIE = (uint32_t)cmd; + break; + + case TIM_INT_FAULT: + TIMx->TIM_FLTCR.FLTIE = (uint32_t)cmd; + break; + + case TIM_INT_ALL: + TIMx->TIM_CMCn[0].CHIE = (uint32_t)cmd; + TIMx->TIM_CMCn[1].CHIE = (uint32_t)cmd; + TIMx->TIM_CMCn[2].CHIE = (uint32_t)cmd; + TIMx->TIM_CMCn[3].CHIE = (uint32_t)cmd; + TIMx->TIM_CMCn[4].CHIE = (uint32_t)cmd; + TIMx->TIM_CMCn[5].CHIE = (uint32_t)cmd; + TIMx->TIM_CMCn[6].CHIE = (uint32_t)cmd; + TIMx->TIM_CMCn[7].CHIE = (uint32_t)cmd; + TIMx->TIM_GLBCR.RLDIE = (uint32_t)cmd; + TIMx->TIM_GLBCR.TOIE = (uint32_t)cmd; + TIMx->TIM_FLTCR.FLTIE = (uint32_t)cmd; + break; + + default: + /* do nothing */ + break; + + } +} + +/** + * @brief TIM INT status clear Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] intType: Selcct interrupt type. + * + * @return none + * + */ +void TIM_IntClear(TIM_ID_t timId, TIM_INT_t intType) +{ + tim_reg_t * TIMx = timRegPtr[timId]; + + switch (intType) + { + case TIM_INT_CH0: + TIMx->TIM_CMCn[0].CHF = 0; + break; + + case TIM_INT_CH1: + TIMx->TIM_CMCn[1].CHF = 0; + break; + + case TIM_INT_CH2: + TIMx->TIM_CMCn[2].CHF = 0; + break; + + case TIM_INT_CH3: + TIMx->TIM_CMCn[3].CHF = 0; + break; + case TIM_INT_CH4: + TIMx->TIM_CMCn[4].CHF = 0; + break; + + case TIM_INT_CH5: + TIMx->TIM_CMCn[5].CHF = 0; + break; + + case TIM_INT_CH6: + TIMx->TIM_CMCn[6].CHF = 0; + break; + + case TIM_INT_CH7: + TIMx->TIM_CMCn[7].CHF = 0; + break; + + case TIM_INT_RLD: + TIMx->TIM_GLBSR.RLDF = 0; + break; + + case TIM_INT_TO: + TIMx->TIM_GLBSR.TOF = 0; + break; + + case TIM_INT_FAULT: + TIMx->TIM_FLTSR.FAULTF = 0; + break; + + case TIM_INT_ALL: + TIMx->TIM_CMCn[0].CHF = 0; + TIMx->TIM_CMCn[1].CHF = 0; + TIMx->TIM_CMCn[2].CHF = 0; + TIMx->TIM_CMCn[3].CHF = 0; + TIMx->TIM_CMCn[4].CHF = 0; + TIMx->TIM_CMCn[5].CHF = 0; + TIMx->TIM_CMCn[6].CHF = 0; + TIMx->TIM_CMCn[7].CHF = 0; + TIMx->TIM_GLBSR.RLDF = 0; + TIMx->TIM_GLBSR.TOF = 0; + TIMx->TIM_FLTSR.FAULTF = 0; + break; + + default: + /* do nothing */ + break; + + } +} + +/** + * @brief TIM Get INT status Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] intType: Selcct interrupt type. + * + * @return intstatus + * + */ +IntStatus_t TIM_GetIntStatus(TIM_ID_t timId, TIM_INT_t intType) +{ + tim_reg_t const volatile* TIMx = timRegPtr[timId]; + IntStatus_t intStatus = RESET; + + switch (intType) + { + case TIM_INT_CH0: + intStatus = (IntStatus_t)TIMx->TIM_CMCn[0].CHF; + break; + + case TIM_INT_CH1: + intStatus = (IntStatus_t)TIMx->TIM_CMCn[1].CHF; + break; + + case TIM_INT_CH2: + intStatus = (IntStatus_t)TIMx->TIM_CMCn[2].CHF; + break; + + case TIM_INT_CH3: + intStatus = (IntStatus_t)TIMx->TIM_CMCn[3].CHF; + break; + + case TIM_INT_CH4: + intStatus = (IntStatus_t)TIMx->TIM_CMCn[4].CHF; + break; + + case TIM_INT_CH5: + intStatus = (IntStatus_t)TIMx->TIM_CMCn[5].CHF; + break; + + case TIM_INT_CH6: + intStatus = (IntStatus_t)TIMx->TIM_CMCn[6].CHF; + break; + + case TIM_INT_CH7: + intStatus = (IntStatus_t)TIMx->TIM_CMCn[7].CHF; + break; + + case TIM_INT_RLD: + intStatus = (IntStatus_t)TIMx->TIM_GLBSR.RLDF; + break; + + case TIM_INT_TO: + intStatus = (IntStatus_t)TIMx->TIM_GLBSR.TOF; + break; + + case TIM_INT_FAULT: + intStatus = (IntStatus_t)TIMx->TIM_FLTSR.FAULTF; + break; + + default: + /* do nothing */ + break; + + } + + return intStatus; +} + +/** + * @brief TIM Get Fault detection flag status of fault channel Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] channelId: Selcct fault channel:TIM_FAULT_CHANNEL_0,.. . + * + * @return intstatus + * + */ +IntStatus_t TIM_GetFaultStatus(TIM_ID_t timId, TIM_FaultChannelId_t channelId) +{ + tim_reg_t const volatile* TIMx = timRegPtr[timId]; + IntStatus_t intStatus = RESET; + + switch (channelId) + { + case TIM_FAULT_CHANNEL_0: + intStatus = (IntStatus_t)TIMx->TIM_FLTSR.FAULTF0; + break; + + case TIM_FAULT_CHANNEL_1: + intStatus = (IntStatus_t)TIMx->TIM_FLTSR.FAULTF1; + break; + + case TIM_FAULT_CHANNEL_ALL: + intStatus = (IntStatus_t)TIMx->TIM_FLTSR.FAULTF; + break; + + default: + /* do nothing */ + break; + + } + + return intStatus; +} + +/** + * @brief TIM fault status clear Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] intType: Selcct interrupt type. + * + * @return none + * + */ +void TIM_FaultStatusClear(TIM_ID_t timId, TIM_FaultChannelId_t channelId) +{ + tim_reg_t * TIMx = timRegPtr[timId]; + + switch (channelId) + { + case TIM_FAULT_CHANNEL_0: + TIMx->TIM_FLTSR.FAULTF0 = 0; + break; + + case TIM_FAULT_CHANNEL_1: + TIMx->TIM_FLTSR.FAULTF1 = 0; + break; + + case TIM_FAULT_CHANNEL_ALL: + TIMx->TIM_FLTSR.FAULTF0 = 0; + TIMx->TIM_FLTSR.FAULTF1 = 0; + TIMx->TIM_FLTSR.FAULTF = 0; + break; + + default: + /* do nothing */ + break; + } + +} + +/** + * @brief TIM match trigger clear Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * + * @return none + * + */ +void TIM_MatchTriggerClear(TIM_ID_t timId) +{ + tim_reg_t * TIMx = timRegPtr[timId]; + + TIMx->TIM_OUTCR.TRIGF = 0; +} + +/** + * @brief TIM INT mask/unmask Function + * + * @param[in] timId: Select the TIM ID: TIM0_ID, TIM1_ID, ... . + * @param[in] intType: Selcct interrupt type. + * @param[in] cbFun: callback function . + * + * @return none + * + */ +void TIM_InstallCallBackFunc(TIM_ID_t timId, TIM_INT_t intType, isr_cb_t * cbFun) +{ + timIsrCbFunc[timId][intType] = cbFun; +} + +/*@} end of group TIM_Public_Functions */ + +/*@} end of group TIM_definitions */ + +/*@} end of group Z20K11X_Peripheral_Driver */ diff --git a/StdDriver/Src/Z20K11xM_tmu.c b/StdDriver/Src/Z20K11xM_tmu.c new file mode 100644 index 0000000..721dc7f --- /dev/null +++ b/StdDriver/Src/Z20K11xM_tmu.c @@ -0,0 +1,149 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_tmu.c + * @brief : TMU module driver file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (C) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + * + **************************************************************************************************/ + +#include "Z20K11xM_tmu.h" + +/** @addtogroup Z20K11X_Peripheral_Driver + * @{ + */ + +/** @defgroup TMU + * @brief TMU driver modules + * @{ + */ + +/** @defgroup TMU_Private_Type + * @{ + */ + +/** @} end of group TMU_Private_Type*/ + +/** @defgroup TMU_Private_Defines + * @{ + */ + +/*PRQA S 0303,0306 ++*/ +static tmu_reg_t *const tmuRegPtr = (tmu_reg_t *) TMU_BASE_ADDR;/*!< TMU Register */ +static tmu_reg_w_t *const tmuRegWPtr = (tmu_reg_w_t *) TMU_BASE_ADDR;/*!< TMU word Register */ +/*PRQA S 0303,0306 ++*/ + + +/*@} end of group TMU_Private_Defines */ + +/** @defgroup TMU_Private_Variables + * @{ + */ + +/*@} end of group TMU_Private_Variables */ + +/** @defgroup TMU_Global_Variables + * @{ + */ + +/** @} end of group TMU_Global_Variables */ + +/** @defgroup TMU_Public_Functions + * @{ + */ + +/** + * @brief set source for TMU target module. + * + * @param[in] source: selects one of the TMU sources + * @param[in] module: selects target module of the TMU modules + * + * @return none + * + */ +void TMU_SetSourceForModule(TMU_Source_t source, TMU_Module_t module) +{ + tmuRegPtr->TMU_CFGn[module].SEL = (uint32_t)source; +} + +/** + * @brief get source for TMU target module. + * + * @param[in] module: selects target module of the TMU modules + * + * @return the selected source for target module. + * + */ +TMU_Source_t TMU_GetSourceForModule(TMU_Module_t module) +{ + uint32_t tmuSource; + + tmuSource = tmuRegPtr->TMU_CFGn[module].SEL; + + return (TMU_Source_t)tmuSource; +} + +/** + * @brief Enable/Disable target module in TMU modules. + * + * @param[in] module: selects target module of the TMU modules + * @param[in] cmd: TMU Module Control: ENABLE; DISABLE. + * + * @return none + * + */ +void TMU_ModuleCmd(TMU_Module_t module, ControlState_t cmd) +{ + tmuRegPtr->TMU_CFGn[module].EN = (uint32_t)cmd; +} + +/** + * @brief Lock Relevant Register for TMU target module, then register is read only. + * + * @param[in] module: selects target module of the TMU modules + * + * @return none. + * + */ +void TMU_SetLockForModule(TMU_Module_t module) +{ + tmuRegPtr->TMU_CFGn[module].LOCK = 1U; +} + +/** + * @brief Unlock Relevant Register for TMU target module, then register is writable. + * + * @param[in] module: selects target module of the TMU modules + * + * @return none. + * + */ +void TMU_SetUnlockForModule(TMU_Module_t module) +{ + uint32_t wordVal = tmuRegWPtr->TMU_CFGn[module] & 0x00FFFFFFUL; + + tmuRegWPtr->TMU_CFGn[module] = wordVal | 0x5B000000UL; +} + +/** + * @brief Get Lock status for TMU target module. + * + * @param[in] module: selects target module of the TMU modules + * + * @return Lock status: SET----Locked; RESET----Unlocked. + * + */ +FlagStatus_t TMU_GetLockStatusForModule(TMU_Module_t module) +{ + return (FlagStatus_t)tmuRegPtr->TMU_CFGn[module].LOCK; +} + +/** @} end of group TMU_Public_Functions */ + +/** @} end of group TMU_definitions */ + +/** @} end of group Z20K11X_Peripheral_Driver */ diff --git a/StdDriver/Src/Z20K11xM_uart.c b/StdDriver/Src/Z20K11xM_uart.c new file mode 100644 index 0000000..e137e7c --- /dev/null +++ b/StdDriver/Src/Z20K11xM_uart.c @@ -0,0 +1,1547 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_uart.c + * @brief : UART module driver file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ + +#include "Z20K11xM_uart.h" +#include "Z20K11xM_clock.h" + +/** @addtogroup Z20K11X_Peripheral_Driver + * @{ + */ + +/** @defgroup UART UART + * @brief UART driver modules + * @{ + */ + +/** @defgroup UART_Private_Type + * @{ + */ + +/** @}end of group UART_Private_Type*/ + +/** @defgroup UART_Private_Defines + * @{ + */ + +/** + * @brief UART interrupt IID definition + */ +#define UART_INTSTA_IID_TBEI 0x02U +#define UART_INTSTA_IID_RBFI 0x04U +#define UART_INTSTA_IID_LSI 0x06U +#define UART_INTSTA_IID_BYDET 0x07U +#define UART_INTSTA_IID_RCVRTO 0x0CU +#define UART_INTSTA_IID_HEADER_DONE 0x0DU +#define UART_INTSTA_IID_RSP_DONE 0x0EU + +#define UART_LIN_SEND_BREAK_MIN 13U +#define UART_LIN_SEND_BREAK_THR 11U + + +#define UART_LIN_HEADER_DONE_FLG ((uint32_t)1U << 14U) +#define UART_LIN_RSP_DONE_FLAG ((uint32_t)1U << 15U) +#define UART_LIN_TO_ERR ((uint32_t)1U << 13U) +#define UART_LIN_CHECKSUM_ERR ((uint32_t)1U << 12U) +#define UART_LIN_PID_ERR ((uint32_t)1U << 11U) +#define UART_LIN_SYNC_FIELD_ERR ((uint32_t)1U << 10U) +#define UART_LIN_ASYNC_INT_FLAG ((uint32_t)1U << 9U) + +#define UART_LSI_OE (1U << 1U) +#define UART_LSI_PE (1U << 2U) +#define UART_LSI_FE (1U << 3U) +#define UART_LSI_BI (1U << 4U) +#define UART_LSI_RFE (1U << 7U) + +#define UART_LIN_HEADER_DONE_INT_FLAG (UART_LIN_HEADER_DONE_FLG | \ + UART_LIN_SYNC_FIELD_ERR | \ + UART_LIN_PID_ERR| \ + UART_LIN_TO_ERR) + +#define UART_LIN_RSP_DONE_INT_FLAG (UART_LIN_RSP_DONE_FLAG | \ + UART_LIN_CHECKSUM_ERR | \ + UART_LIN_TO_ERR) +#define UART_LSI_INT_FLAG (UART_LSI_OE | \ + UART_LSI_PE | \ + UART_LSI_FE | \ + UART_LSI_BI | \ + UART_LSI_RFE) + + +#define UART_ENABLE_FIFO 1U +#define UART_RESET_RX_FIFO (1U << 1U) +#define UART_RESET_TX_FIFO (1U << 2U) + +static const uint32_t uartInterruptMaskTable[]= +{ + 0x00000001U, /*!< UART_INT_RBFI */ + 0x00000082U, /*!< UART_INT_TBEI */ + 0x00000004U, /*!< UART_INT_LSI */ + 0x00000000U, /*!< UART_INT_BYDET */ + 0x00000001U, /*!< UART_INT_RCVRTO */ + 0x00000100U, /*!< UART_INT_HEADER_DONE */ + 0x00000200U, /*!< UART_INT_RSP_DONE */ + 0x00000400U, /*!< UART_INT_ASYNC */ + 0x0000078FU, /*!< UART_INT_ALL */ +}; + +static const uint32_t uartInterruptStatusTable[]= +{ + UART_INTSTA_IID_RBFI, /*!< UART_INTSTA_RBFI */ + UART_INTSTA_IID_TBEI, /*!< UART_INTSTA_TBEI */ + UART_INTSTA_IID_LSI, /*!< UART_INTSTA_LSI */ + UART_INTSTA_IID_BYDET, /*!< UART_INTSTA_BYDET */ + UART_INTSTA_IID_RCVRTO, /*!< UART_INTSTA_RCVRTO */ + UART_INTSTA_IID_HEADER_DONE, /*!< UART_INTSTA_HEADER_DONE */ + UART_INTSTA_IID_RSP_DONE /*!< UART_INTSTA_RSP_DONE */ +}; + +static const uint32_t uartLineStatusTable[]= +{ + 0x00000001U, /*!< UART_LINESTA_DR */ + 0x00000002U, /*!< UART_LINESTA_OE */ + 0x00000004U, /*!< UART_LINESTA_PE */ + 0x00000008U, /*!< UART_LINESTA_FE */ + 0x00000010U, /*!< UART_LINESTA_BI */ + 0x00000020U, /*!< UART_LINESTA_THRE */ + 0x00000040U, /*!< UART_LINESTA_TEMT */ + 0x00000080U, /*!< UART_LINESTA_RFE */ + 0x0000009eU, /*!< UART_LINESTA_TRANS_ERR */ + 0x00000100U, /*!< UART_LINESTA_ADDR_RCVD */ + 0x00000200U, /*!< UART_LINESTA_ASYNC */ + 0x00000400U, /*!< UART_LINESTA_PID_ERR */ + 0x00000800U, /*!< UART_LINESTA_FIELD_ERR */ + 0x00001000U, /*!< UART_LINESTA_CHECKSUM_ERR */ + 0x00002000U, /*!< UART_LINESTA_TO_ERR */ + 0x00004000U, /*!< UART_LINESTA_HEADER_DONE */ + 0x00008000U, /*!< UART_LINESTA_RSP_DONE */ +}; + + +/** @}end of group UART_Private_Defines */ + +/** @defgroup UART_Private_Variables + * @{ + */ + +/** + * @brief UART ISR callback function pointer array + */ +static isr_cb_t * uartIsrCb[UART_INSTANCE_NUM][UART_INT_ALL]= +{ + {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}, + {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}, + {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}, +#if (4U == UART_INSTANCE_NUM) + {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}, +#endif +}; + +/** + * @brief UART address array + */ +/*PRQA S 0303,0306 ++*/ +static uart_reg_t * const uartRegPtr[UART_INSTANCE_NUM] = +{ + (uart_reg_t *)UART0_BASE_ADDR, + (uart_reg_t *)UART1_BASE_ADDR, + (uart_reg_t *)UART2_BASE_ADDR, +#if (4U == UART_INSTANCE_NUM ) + (uart_reg_t *)UART3_BASE_ADDR, +#endif +}; + +static uart_reg_w_t * const uartRegWPtr[UART_INSTANCE_NUM] = +{ + (uart_reg_w_t *)UART0_BASE_ADDR, + (uart_reg_w_t *)UART1_BASE_ADDR, + (uart_reg_w_t *)UART2_BASE_ADDR, +#if (4U == UART_INSTANCE_NUM ) + (uart_reg_w_t *)UART3_BASE_ADDR, +#endif +}; +/*PRQA S 0303,0306 --*/ + +/** @}end of group UART_Private_Variables */ + +/** @defgroup UART_Global_Variables + * @{ + */ +/* line status buff */ +static uint32_t uartLineStatusBuf[UART_INSTANCE_NUM] = {0U}; +/* FIFO Control register buff */ +static uint32_t uartFifoControlBuf[UART_INSTANCE_NUM] = {0U}; + + +/** @}end of group UART_Global_Variables */ + +/** @defgroup UART_Private_FunctionDeclaration + * @{ + */ +static void UART_IntHandler(UART_ID_t uartId); +void UART0_DriverIRQHandler(void); +void UART1_DriverIRQHandler(void); +void UART2_DriverIRQHandler(void); +#if (4U == UART_INSTANCE_NUM) +void UART3_DriverIRQHandler(void); +#endif + +/** @}end of group UART_Private_FunctionDeclaration */ + +/** @defgroup UART_Private_Functions + * @{ + */ + +/** + * @brief Handle UART interrupt. + * + * @param[in] uartId: Select the UART port. + * + * @return none + * + */ +static void UART_IntHandler(UART_ID_t uartId) +{ + uint32_t intId; + volatile uint32_t dummyData; + + uart_reg_t * UARTx = (uart_reg_t *)(uartRegPtr[uartId]); + uart_reg_w_t * UARTxw = (uart_reg_w_t *)(uartRegWPtr[uartId]); + + uartLineStatusBuf[uartId] = UARTxw->UART_LSR; + + if(1U == UARTx->UART_DLH_IER.UART_IER.HEADER_DONE_INT_EN) + { + /* LIN header done interrupt */ + if( (UART_LIN_HEADER_DONE_FLG & uartLineStatusBuf[uartId] ) != 0U ) + { + if(uartIsrCb[uartId][UART_INT_HEADER_DONE] != NULL) + { + /* call the callback function */ + uartIsrCb[uartId][UART_INT_HEADER_DONE](); + } + /* Disable the interrupt if callback function is not setup */ + else + { + UARTx->UART_DLH_IER.UART_IER.HEADER_DONE_INT_EN = 0U; + } + } + } + + if(1U == UARTx->UART_DLH_IER.UART_IER.RSP_DONE_INT_EN) + { + /* LIN respnse done interrupt*/ + if(0U != (UART_LIN_RSP_DONE_FLAG & uartLineStatusBuf[uartId])) + { + if(uartIsrCb[uartId][UART_INT_RSP_DONE] != NULL) + { + /* call the callback function */ + uartIsrCb[uartId][UART_INT_RSP_DONE](); + } + /* Disable the interrupt if callback function is not setup */ + else + { + UARTx->UART_DLH_IER.UART_IER.RSP_DONE_INT_EN = 0U; + } + } + } + + if(1U == UARTx->UART_DLH_IER.UART_IER.ELSI) + { + /* UART line status interrupt */ + if((UART_LSI_INT_FLAG & uartLineStatusBuf[uartId]) != 0U) + { + if(uartIsrCb[uartId][UART_INT_LSI] != NULL) + { + /* call the callback function */ + uartIsrCb[uartId][UART_INT_LSI](); + } + /* Disable the interrupt if callback function is not setup */ + else + { + UARTx->UART_DLH_IER.UART_IER.ELSI = 0U; + } + } + } + + if(1U == UARTx->UART_DLH_IER.UART_IER.ASYNC_INT_EN) + { + /* UART_LIN async interrupt */ + if((UART_LIN_ASYNC_INT_FLAG & uartLineStatusBuf[uartId]) != 0x0U ) + { + if(uartIsrCb[uartId][UART_INT_ASYNC] != NULL) + { + /* call the callback function */ + uartIsrCb[uartId][UART_INT_ASYNC](); + } + /* Disable the interrupt if callback function is not setup */ + else + { + UARTx->UART_DLH_IER.UART_IER.ASYNC_INT_EN = 0U; + } + } + } + + /* Get the BF related pointer */ + intId = UARTx->UART_IIR_FCR.UART_IIR.IID; + + switch(intId) + { + /* Transmit holding register empty inerrupt */ + case UART_INTSTA_IID_TBEI: + if(uartIsrCb[uartId][UART_INT_TBEI] != NULL) + { + /* call the callback function */ + uartIsrCb[uartId][UART_INT_TBEI](); + } + /* Disable the interrupt if callback function is not setup */ + else + { + UARTx->UART_DLH_IER.UART_IER.ETBEI = 0U; + } + break; + + case UART_INTSTA_IID_RBFI: + if(uartIsrCb[uartId][UART_INT_RBFI] != NULL) + { + /* call the callback function */ + uartIsrCb[uartId][UART_INT_RBFI](); + } + /* Disable the interrupt if callback function is not setup */ + else + { + UARTx->UART_DLH_IER.UART_IER.ERBFI = 0U; + } + break; + + /* Busy detect indication */ + case UART_INTSTA_IID_BYDET: + /* Clear it by reading the UART status register */ + dummyData = UARTxw->UART_USR; + if(uartIsrCb[uartId][UART_INT_BYDET] != NULL) + { + /* call the callback function */ + uartIsrCb[uartId][UART_INT_BYDET](); + } + /* Disable the interrupt if callback function is not setup */ + else + { + UARTx->UART_DLH_IER.UART_IER.ERBFI = 0U; + } + break; + + /* Character timeout indication */ + case UART_INTSTA_IID_RCVRTO: + if(uartIsrCb[uartId][UART_INT_RCVRTO] != NULL) + { + /* call the callback function */ + uartIsrCb[uartId][UART_INT_RCVRTO](); + } + /* Disable the interrupt if callback function is not setup */ + else + { + UARTx->UART_DLH_IER.UART_IER.ERBFI = 0U; + } + /* Clear it by reading the UART receive register */ + dummyData = UARTxw ->UART_RBR_THR_DLL.UART_RBR; + break; + + default: + /* do nothing */ + break; + } + + uartLineStatusBuf[uartId] = 0U; +} +/** @} end of group UART_Private_Functions */ + +/** @defgroup UART_Public_Functions + * @{ + */ + +/** + * @brief install call back function for interrupts + * + * @param[in] uartId: Select the UART port. + * @param[in] intType: select the interrupt + * @param[in] cbFun: pointer to callback function + * + * @return none + */ +void UART_InstallCallBackFunc(UART_ID_t uartId, UART_Int_t intType, + isr_cb_t * cbFun) +{ + uartIsrCb[uartId][intType] = cbFun; +} + +/** + * @brief Get line status buffer in interrupt call back functions. The line + * status will be stored into line status buffer in UART_IRQHandler. + * If the call back functions which are installed through () + * UART_InstallCallBackFunc() needs to get the line status, please + * use this function instead of UART_GetAllLineStatus or + * UART_GetLineStatus. + * + * @param[in] uartId: Select the UART port. + * + * @return linestatus + * + */ +uint32_t UART_GetLineStatusBufForCbf(UART_ID_t uartId) +{ + return uartLineStatusBuf[uartId]; +} + +/** + * @brief Default initializes the UART. The OSC40M clock frequency is 40MHz. + * baudrate:115200, no parity, 8 date bits, 1 stop bit, + * disable autoflow. + * + * @param[in] uartId: Select the UART port. + * + * @return none + * + */ +void UART_DefaultInit(UART_ID_t uartId) +{ + uart_reg_t * UARTx = (uart_reg_t *)(uartRegPtr[uartId]); + uint32_t integerDiv, fractionalDiv; +#if (4U == UART_INSTANCE_NUM) + CLK_Module_t const clk[] = {CLK_UART0,CLK_UART1,CLK_UART2,CLK_UART3}; +#else + CLK_Module_t const clk[] = {CLK_UART0,CLK_UART1,CLK_UART2}; +#endif + CLK_Module_t uartClkId = clk[uartId]; + uint32_t clkFreq = CLK_GetModuleClkFreq(uartClkId, 40000000U); + + /* Enable DLAB to set baud rate */ + UARTx->UART_LCR.DLAB = 0x01U; + /* get integer baudrate divisor*/ + integerDiv = clkFreq/(16U * 115200U); + + /* Config the DLL and DLH registers */ + UARTx->UART_RBR_THR_DLL.UART_DLL.DL_L = integerDiv & 0xFFU; + UARTx->UART_DLH_IER.UART_DLH.DL_H = (integerDiv >> 0x08U) ; + + /* config fractional divisor */ + fractionalDiv = clkFreq%(16U * 115200U); + fractionalDiv /= 115200U; + UARTx->UART_FD.FD = fractionalDiv; + + /* Disable DLAB */ + UARTx->UART_LCR.DLAB = 0x0U; + /* NO PARITY */ + UARTx->UART_LCR.PEN = 0x0U; + /*set 8 bits data */ + UARTx->UART_LCR.DLS = (uint32_t)UART_DATABITS_8; + /* Set UART stop bit */ + UARTx->UART_LCR.STOP = (uint32_t)UART_STOPBITS_1; + /* disable autoflow */ + UARTx->UART_AFCR.AFCE = (uint32_t)DISABLE; + UARTx->UART_AFCR.RTS = 0U; +} + +/** + * @brief Initializes the UART + * + * @param[in] uartId: Select the UART port. + * @param[in] uartCfg: Pointer to a UART configuration structure + * + * @return none + * + */ +void UART_Init(UART_ID_t uartId, const UART_Config_t* uartCfg) +{ + uint32_t integerDiv, fractionalDiv; +#if (4U == UART_INSTANCE_NUM) + CLK_Module_t clk[] = {CLK_UART0,CLK_UART1,CLK_UART2,CLK_UART3}; +#else + CLK_Module_t clk[] = {CLK_UART0,CLK_UART1,CLK_UART2}; +#endif + CLK_Module_t uartClkId = clk[uartId]; + uint32_t clkFreq = CLK_GetModuleClkFreq(uartClkId, uartCfg->oscFreq); + uart_reg_t * UARTx = (uart_reg_t *)(uartRegPtr[uartId]); + + /************Configure the Baud Rate*********************************/ + + /* Enable DLAB to set baud rate */ + UARTx->UART_LCR.DLAB = 0x01U; + + /* get integer baudrate divisor*/ + integerDiv = clkFreq/(16U * uartCfg->baudRate); + + /* Config the DLL and DLH registers */ + UARTx->UART_RBR_THR_DLL.UART_DLL.DL_L = integerDiv & 0xFFU; + UARTx->UART_DLH_IER.UART_DLH.DL_H = (integerDiv >> 0x08U)& 0xFFU; + + /* calculate fractional divisor + divisor = clkFreq/(16*baudrate) = BRDI +BRDF + FD = BRDF*2^4 = 16* BRDF + BRDF = clkFreq%(16*baudrate)/(16*baudrate) + FD = clkFreq%(16*baudrate)*16/(16*baudrate) + = clkFreq%(16*baudrate)/baudrate */ + fractionalDiv = clkFreq%(16U * uartCfg->baudRate); + fractionalDiv /= uartCfg->baudRate; + UARTx->UART_FD.FD = fractionalDiv; + + /* Disable DLAB */ + UARTx->UART_LCR.DLAB = 0x0U; + + if(uartCfg->parity == UART_PARITY_NONE) + { + UARTx->UART_LCR.PEN = 0x0U; + } + else if(uartCfg->parity == UART_PARITY_ODD) + { + UARTx->UART_LCR.PEN = 0x1U; + UARTx->UART_LCR.EPS = 0U; + } + else + { + UARTx->UART_LCR.PEN = 0x1U; + UARTx->UART_LCR.EPS = 1U; + } + + /* Set UART Data Length and stop bit */ + if(uartCfg->dataBits == UART_DATABITS_9) + { + UARTx->UART_LCR_EXT.DLS_E = 0x1U; + } + else + { + UARTx->UART_LCR.DLS = (uint32_t)uartCfg->dataBits ; + } + /* Set UART stop bit */ + UARTx->UART_LCR.STOP = (uint32_t)uartCfg->stopBits; + + /***********Configure auto flow *******************/ + UARTx->UART_AFCR.AFCE = (uint32_t)uartCfg->autoFlowControl; + + if(uartCfg->autoFlowControl == ENABLE) + { + UARTx->UART_AFCR.RTS = 1U; + } + else + { + UARTx->UART_AFCR.RTS = 0U; + } + +} + +/** + * @brief Wait for UART busy bit clear. + * + * @param[in] uartId: UART peripheral selected. + * @param[in] cycle: The software cycles to be waited. User decides how many + * cycles need to be waited. + * + * @return ResultStatus_t + * - SUCC: busy bit is cleared + * - ERR: UART is still busy + * + */ +ResultStatus_t UART_WaitBusyClear(UART_ID_t uartId, uint32_t cycle) +{ + ResultStatus_t ret = ERR; + volatile uint32_t localcnt = 0; + + while(localcnt < cycle) + { + if(RESET == UART_GetBusyStatus(uartId)) + { + ret = SUCC; + break; + } + + localcnt = localcnt + 1U; + } + + return ret; +} + +/** + * @brief Set UART rts enable + * + * @param[in] uartId: UART peripheral selected. + * @param[in] newState: Enable/Disable function state + * + * @return none + * + */ +void UART_RtsEnable(UART_ID_t uartId, ControlState_t newState) +{ + uart_reg_t * UARTx = (uart_reg_t *)(uartRegPtr[uartId]); + + UARTx->UART_AFCR.RTS = (uint32_t)newState; + +} + +/** + * @brief Set UART loopback mode + * + * @param[in] uartId: UART peripheral selected. + * @param[in] newState: Enable/Disable function state + * + * @return none + * + */ +void UART_SetLoopBackMode(UART_ID_t uartId, ControlState_t newState) +{ + uart_reg_t * UARTx = (uart_reg_t *)(uartRegPtr[uartId]); + + UARTx->UART_AFCR.LB = (uint32_t)newState; + +} + +/** + * @brief Send break function, user can choose the length of break, + * the length should not be less than eleven + * + * @param[in] uartId: UART peripheral selected. + * @param[in] len: the length of break + * + * @return + * - SUCC : break is sent + * - ERR : break length is invalid + * + */ +ResultStatus_t UART_SendBreak(UART_ID_t uartId, uint8_t len) +{ + uart_reg_t * UARTx = (uart_reg_t *)(uartRegPtr[uartId]); + ResultStatus_t ret = SUCC; + if(len < 0x0BU) + { + ret = ERR; + } + else + { + UARTx->UART_LCR.LBKM = (uint32_t)len - 0xBU; + UARTx->UART_LCR.LBKEN = 1U; + /* send break characters */ + UARTx->UART_LCR.BC = 1; + } + + return ret; +} + +/** + * @brief Receive one byte data from the UART peripheral + * + * @param[in] uartId: Select the UART port. + * + * @return The received data + * + */ +uint8_t UART_ReceiveByte(UART_ID_t uartId) +{ + uart_reg_t * UARTx = (uart_reg_t *)(uartRegPtr[uartId]); + + /* Receive data */ + return (uint8_t)(UARTx->UART_RBR_THR_DLL.UART_RBR.RBR_LSB); +} + +/** + * @brief Read received bytes from the RX FIFO + * @param[in] uartId: Select the UART port, should be UART0_ID, UART1_ID, + * UART2_ID, UART3_ID. + * @param[in] length: the number of bytes to be read. When call this function, + * the user needs to make sure that the "length" is not + * greater than the number of bytes that is available in + * RX FIFO + * @param[out] data: points to the memory where the data to be stored + *. + * @return The received data + */ +void UART_ReceiveBytes(UART_ID_t uartId,uint32_t length, uint8_t data[]) +{ + uart_reg_t * UARTx = (uart_reg_t *)(uartRegPtr[uartId]); + + for(uint32_t cnt = 0U; cnt UART_RBR_THR_DLL.UART_RBR.RBR_LSB; + } +} + +/** + * @brief Empty the RX FIFO. This function reads received data until RX + * FIFO is empty + * @param[in] uartId: Select the UART port. + * + * @return None + */ +void UART_EmptyRxFifo(UART_ID_t uartId) +{ + uart_reg_t * UARTx = (uart_reg_t *)(uartRegPtr[uartId]); + + volatile uint8_t dummyData; + + while(SET == UART_GetLineStatus(uartId, UART_LINESTA_DR)) + { + dummyData = (uint8_t)UARTx->UART_RBR_THR_DLL.UART_RBR.RBR_LSB; + } +} + +/** + * @brief Set receive 9 bits data mode 0 + * + * @param[in] uartId: Select the UART port. + * + * @return none + * + */ +void UART_9BitsM0Rx(UART_ID_t uartId) +{ + uart_reg_t * UARTx = (uart_reg_t *)(uartRegPtr[uartId]); + + if((uint32_t)SET == UARTx->UART_LCR_EXT.DLS_E) + { /* Receive mode 0 */ + UARTx->UART_LCR_EXT.ADDR_MATCH = 0x0U; + } + else + { + /* none */ + } + +} + +/** + * @brief Program the address of receive 9 bits data, mode 1 + * + * @param[in] uartId: Select the UART port. + * + * @return none + * + */ +void UART_9BitsM1SetAddr(UART_ID_t uartId, uint8_t addr) +{ + uart_reg_t * UARTx = (uart_reg_t *)(uartRegPtr[uartId]); + + /* set address in rar */ + UARTx->UART_RAR.RAR = addr; +} + +/** + * @brief Select 9 bits hardware receive mode 1 + * + * @param[in] uartId: Select the UART port. + * + * @return none + * + */ +void UART_9BitsHWRecvEnable(UART_ID_t uartId) +{ + uart_reg_t * UARTx = (uart_reg_t *)(uartRegPtr[uartId]); + + UARTx->UART_LCR_EXT.ADDR_MATCH = 0x1U; +} + +/** + * @brief Receive address from the UART peripheral, mode 1 + * + * @param[in] uartId: Select the UART port. + * + * @return the received address + * + */ +/* receive address */ +uint16_t UART_9BitsM1RxAddr(UART_ID_t uartId) +{ + uint16_t ret; + + uart_reg_t * UARTx = (uart_reg_t *)(uartRegPtr[uartId]); + uart_reg_w_t * UARTxw = (uart_reg_w_t *)(uartRegWPtr[uartId]); + + uint8_t rxAddr; + uint32_t regData; + + regData = (uint32_t)UARTxw->UART_RBR_THR_DLL.UART_RBR; + rxAddr = (uint8_t)UARTx->UART_RAR.RAR; + + if(0x100U == (regData & 0x100U)) + { + if(rxAddr == (regData & 0xFFU)) + { + ret = (uint16_t)(regData & 0x1FFU); + } + else + { + ret = (uint16_t)ERR; + } + } + else + { + ret = (uint16_t)ERR; + } + + return ret; +} + +/** + * @brief Receive one byte data from the UART peripheral, mode 1 + * + * @param[in] uartId: Select the UART port. + * + * @return The received data + * + */ +uint16_t UART_9BitsM1RxData(UART_ID_t uartId) +{ + uint16_t ret; + uint32_t regData; + + uart_reg_w_t * UARTxw = (uart_reg_w_t *)(uartRegWPtr[uartId]); + regData = (uint32_t)UARTxw->UART_RBR_THR_DLL.UART_RBR; + + if(0U == (regData & 0x100U)) + { + ret = (uint16_t)(regData & 0xFFU); + } + else + { + ret = 0x1FF; + } + + return ret; +} + +/** + * @brief Send one byte data to the UART peripheral,5/6/7/8 bits + * + * @param[in] uartId: Select the UART port. + * @param[in] data: The data to be sent + * + * @return none + * + */ +void UART_SendByte(UART_ID_t uartId, uint8_t data) +{ + uart_reg_w_t * UARTxw = (uart_reg_w_t *)(uartRegWPtr[uartId]); + /* Send data */ + UARTxw->UART_RBR_THR_DLL.UART_THR = (uint32_t)data; +} + +/** + * @brief Program the transmit target address, 9bits, mode 0 + * + * @param[in] uartId: Select the UART port. + * @param[in] addr: program the address + * + * @return none + * + */ +void UART_9BitsM0SetAddr(UART_ID_t uartId, uint8_t addr) +{ + uart_reg_t * UARTx = (uart_reg_t *)(uartRegPtr[uartId]); + /* transmit mode 0 */ + if(0x1U == UARTx->UART_LCR_EXT.DLS_E) + { + UARTx->UART_LCR_EXT.TRANSMIST_MODE = 0x0U; + UARTx->UART_TAR.TAR = (uint32_t)addr; + } +} + +/** + * @brief Set send address bit, mode 0 + * + * @param[in] uartId: Select the UART port. + * + * @return none + * + */ +void UART_9BitsM0SendAddr(UART_ID_t uartId) +{ + /* transmit mode 0 */ + uart_reg_t * UARTx = (uart_reg_t *)(uartRegPtr[uartId]); + + UARTx->UART_LCR_EXT.SEND_ADDR = 0x1U; +} + +/** + * @brief Send 9 bits data to the UART peripheral, mode 1 + * + * @param[in] uartId: Select the UART port. + * @param[in] data: The data to be send + * + * @return none + * + */ +void UART_9BitsM1TxData(UART_ID_t uartId, uint16_t data) +{ + uart_reg_t * UARTx = (uart_reg_t *)(uartRegPtr[uartId]); + uart_reg_w_t * UARTxw = (uart_reg_w_t *)(uartRegWPtr[uartId]); + /* transmit mode 1 */ + if((uint32_t)SET == UARTx->UART_LCR_EXT.DLS_E) + { + UARTx->UART_LCR_EXT.TRANSMIST_MODE = 0x1U; + /* Send data */ + UARTxw->UART_RBR_THR_DLL.UART_THR = ((uint32_t)data) & 0x1FFU; + } +} + +/** + * @brief Config UART FIFO function + * + * @param[in] uartId: Select the UART port. + * @param[in] fifoCfg: Pointer to a UART_FIFO_CFG_t Structure + * + * @return none + * + */ +void UART_FIFOConfig(UART_ID_t uartId, const UART_FIFOConfig_t * fifoCfg) +{ + uint32_t regValue; + uart_reg_w_t * UARTxw = (uart_reg_w_t *)(uartRegWPtr[uartId]); + + regValue =((((uint32_t)(fifoCfg->fifoRt) & 0x03U) << 6U) + | (((uint32_t)(fifoCfg->fifoTet) & 0x03U) << 4U) + | (((uint32_t)(fifoCfg->txFifoReset) & 0x01U) << 2U) + | (((uint32_t)(fifoCfg->rxFifoReset) & 0x01U) << 1U) + | ((uint32_t)(fifoCfg->fifoEnable) & 0x01U)); + + UARTxw->UART_IIR_FCR.UART_FCR = regValue; + + uartFifoControlBuf[uartId] = regValue; + uartFifoControlBuf[uartId] &= (~(UART_RESET_RX_FIFO | UART_RESET_TX_FIFO)); + +} + +/** + * @brief get UART FIFO status + * + * @param[in] uartId: Select the UART port. + * + * @return status + * + */ +ControlState_t UART_GetfifoStatus(UART_ID_t uartId) +{ + ControlState_t ret; + + uart_reg_t * UARTx = (uart_reg_t *)(uartRegPtr[uartId]); + + if(3U == UARTx->UART_IIR_FCR.UART_IIR.FIFOSE) + { + ret = ENABLE; + } + else + { + ret = DISABLE; + } + + return ret; +} + +/** + * @brief Reset uart receive fifo + * + * @param[in] uartId: Select the UART port. + * + * @return none + * + */ +void UART_ResetRxFifo(UART_ID_t uartId) +{ + uart_reg_w_t * UARTxw = (uart_reg_w_t *)(uartRegWPtr[uartId]); + + uartFifoControlBuf[uartId] |= UART_RESET_RX_FIFO; + + UARTxw->UART_IIR_FCR.UART_FCR = uartFifoControlBuf[uartId]; + + uartFifoControlBuf[uartId] &= (~UART_RESET_RX_FIFO); +} + +/** + * @brief Reset uart transmit fifo + * + * @param[in] uartId: Select the UART port. + * + * @return none + * + */ +void UART_ResetTxFifo(UART_ID_t uartId) +{ + uart_reg_w_t * UARTxw = (uart_reg_w_t *)(uartRegWPtr[uartId]); + + uartFifoControlBuf[uartId] |= UART_RESET_TX_FIFO; + UARTxw->UART_IIR_FCR.UART_FCR = uartFifoControlBuf[uartId]; + + uartFifoControlBuf[uartId] &= (~UART_RESET_TX_FIFO); +} + +/** + * @brief Enable/Disable debug mode. If enabled, hardware will not clean + * the recevier fifo automaticlly + * + * @param[in] uartId: Select the UART port. + * + * @param[in] Cmd: ENABLE/DISABLE + * + * @return none + * + */ +void UART_DebugCmd(UART_ID_t uartId, ControlState_t Cmd) +{ + uart_reg_t * UARTx = (uart_reg_t *)(uartRegPtr[uartId]); + + UARTx->UART_LCR.DEBUG_EN = (uint32_t)Cmd; +} + +/** + * @brief Idle detect config + * + * @param[in] uartId: Select the UART port. + * + * @param[in] config: config idle detect + * + * @return none + * + */ +void UART_IdleDetectConfig(UART_ID_t uartId,UART_IdleDetectConfig_t *config) +{ + uart_reg_t * UARTx = (uart_reg_t *)(uartRegPtr[uartId]); + + UARTx->UART_LCR.IDLE_DET_LENGTH = (uint32_t)config->len; + UARTx->UART_LCR.IDLE_DET_EN = (uint32_t)config->Cmd; +} + +/** + * @brief Config UART in LIN mode + * @param[in] uartId: Select the UART port. + * + * @param[in] config: points to the configuration of LIN mode + * @return none + */ +void UART_LinConfig(UART_ID_t uartId, const UART_LinConfig_t *config) +{ + uart_reg_t * UARTx = (uart_reg_t *)(uartRegPtr[uartId]); + uart_reg_w_t * UARTxw = (uart_reg_w_t *)(uartRegWPtr[uartId]); + + uint32_t integerDiv, fractionalDiv; +#if (4U == UART_INSTANCE_NUM) + CLK_Module_t clk[] = {CLK_UART0,CLK_UART1,CLK_UART2,CLK_UART3}; +#else + CLK_Module_t clk[] = {CLK_UART0,CLK_UART1,CLK_UART2}; +#endif + CLK_Module_t uartClkId = clk[uartId]; + uint32_t tmp; + + /* Enable DLAB to set baud rate */ + UARTx->UART_LCR.DLAB = 0x01U; + tmp = CLK_GetModuleClkFreq(uartClkId, config->oscFreq); + + if(1U == (uint32_t)config->autoSyncEn) + { + /* get baudrate divisor*/ + integerDiv = (10U * tmp/(16U * config->baudRate) )+ 5U; + integerDiv = integerDiv / 10U; + + /* Config the DLL and DLH registers */ + UARTx->UART_RBR_THR_DLL.UART_DLL.DL_L = integerDiv & 0xFFU; + UARTx->UART_DLH_IER.UART_DLH.DL_H = (integerDiv >> 0x08U)& 0xFFU; + + UARTx->UART_FD.FD = 0U; + } + else + { + /* get baudrate divisor*/ + integerDiv = tmp/(16U * config->baudRate); + + /* Config the DLL and DLH registers */ + UARTx->UART_RBR_THR_DLL.UART_DLL.DL_L = integerDiv & 0xFFU; + UARTx->UART_DLH_IER.UART_DLH.DL_H = (integerDiv >> 0x08U)& 0xFFU; + + /* calculate fractional divisor + * divisor = clkFreq/(16*baudrate) = BRDI +BRDF + * FD = BRDF*2^4 = 16* BRDF + * BRDF = clkFreq%(16*baudrate)/(16*baudrate) + * FD = clkFreq%(16*baudrate)*16/(16*baudrate) + * = clkFreq%(16*baudrate)/baudrate + */ + fractionalDiv = tmp%(16U * config->baudRate); + fractionalDiv /= config->baudRate; + UARTx->UART_FD.FD = fractionalDiv; + } + /* Disable DLAB */ + UARTx->UART_LCR.DLAB = 0x0U; + /* no parity */ + UARTx->UART_LCR.PEN = 0x0U; + + /* 8 bits */ + UARTx->UART_LCR.DLS = 3U ; + + /* 1 stop bit */ + UARTx->UART_LCR.STOP = 0U; + + UARTx->UART_AFCR.RTS = 0U; + + /* LIN mode */ + UARTx->UART_LIN_CTL.LIN_MODE = 1U; + UARTx->UART_LIN_CTL.MASTER_MODE = (uint32_t)config->mode; + + /* auto sync */ + UARTx->UART_LCR.AUTO_SYNC_EN = (uint32_t)config->autoSyncEn; + + /* enable and clear FIFO in LIN mode */ + uartFifoControlBuf[uartId] |= UART_ENABLE_FIFO; + + UARTxw->UART_IIR_FCR.UART_FCR = uartFifoControlBuf[uartId]; + + uartFifoControlBuf[uartId] |= ( UART_RESET_TX_FIFO | UART_RESET_RX_FIFO); + + UARTxw->UART_IIR_FCR.UART_FCR = uartFifoControlBuf[uartId]; + + uartFifoControlBuf[uartId] &= ( ~ (UART_RESET_TX_FIFO | UART_RESET_RX_FIFO)); + +} + +/** + * @brief Set UART in LIN mode as a LIN master and start to send the header + * @param[in] uartId: Select the UART port. + * + * @param[in] header: points to the header to be sent + * @return status + * - SUCC : header is sent + * - ERR : header is not sent due to UART is busy + */ +ResultStatus_t UART_LinSendHeader(UART_ID_t uartId, + const UART_LinHeader_t *header) +{ + ResultStatus_t ret; + uart_reg_t * UARTx = (uart_reg_t *)(uartRegPtr[uartId]); + + uint32_t breakLen; + uint32_t rsp_op_start = UARTx->UART_LIN_CTL.RSP_OP_START; + uint32_t header_op_start = UARTx->UART_LIN_CTL.HEADER_OP_START; + /* check if UART is busy */ + if( (rsp_op_start != 0U) || (header_op_start != 0U) ) + { + ret = ERR; + } + else + { + UARTx->UART_LIN_DEL_LENGTH.LIN_DEL_LENGTH = header->deleLen - 1U; + UARTx->UART_LIN_PID_VALUE.PID = header->id; + breakLen = ((header->breakLen) >= UART_LIN_SEND_BREAK_MIN)?( + (header->breakLen) - UART_LIN_SEND_BREAK_THR): + (UART_LIN_SEND_BREAK_MIN - UART_LIN_SEND_BREAK_THR); + + if(breakLen != UARTx->UART_LCR.LBKM ) + { + UARTx->UART_LCR.LBKM = breakLen; + } + else + { + /* Nothing to do */ + } + UARTx->UART_LIN_CTL.MASTER_MODE = 1U; + /* start to send */ + UARTx->UART_LIN_CTL.HEADER_OP_START = 1U; + + ret = SUCC; + } + + return ret; +} + +/** + * @brief This function stops receiving/sending header/response of LIN. + * + * @param[in] uartId: Select the UART port. + * + * @return none + */ +void UART_LinStopTransmission(UART_ID_t uartId) +{ + uart_reg_t * UARTx = (uart_reg_t *)(uartRegPtr[uartId]); + + UARTx->UART_LIN_CTL.RSP_OP_START = 0U; + + UARTx->UART_LIN_CTL.HEADER_OP_START = 0U; + +} + +/** + * @brief If LIN is sending/receiving header/response + * this function returns SET, otherwise, return RESET. + * + * @param[in] uartId: Select the UART port. + * + * @return SET/RESET + */ +FlagStatus_t UART_LinGetTransmissionStatus(UART_ID_t uartId) +{ + FlagStatus_t ret = RESET; + uart_reg_t * UARTx = (uart_reg_t *)(uartRegPtr[uartId]); + + uint32_t rsp_op_start = UARTx->UART_LIN_CTL.RSP_OP_START; + uint32_t header_op_start = UARTx->UART_LIN_CTL.HEADER_OP_START; + /* check if UART is busy */ + if( (rsp_op_start != 0U) || (header_op_start != 0U) ) + { + ret = SET; + } + else + { + /* nothing */ + } + + return ret; +} + +/** + * @brief Set UART in LIN mode as a LIN slave and start to receive a header. + * FIFO is disabled before it starts to receive a header + * + * @param[in] uartId: Select the UART port. + * @return + * - SUCC : it starts to receive header + * - ERR : it dose not start to receive header due to UART is busy + */ +ResultStatus_t UART_LinStartReceiveHeader(UART_ID_t uartId) +{ + ResultStatus_t ret; + uart_reg_t * UARTx = (uart_reg_t *)(uartRegPtr[uartId]); + uart_reg_w_t * UARTxw = (uart_reg_w_t *)(uartRegWPtr[uartId]); + + uint32_t rsp_op_start = UARTx->UART_LIN_CTL.RSP_OP_START; + uint32_t header_op_start = UARTx->UART_LIN_CTL.HEADER_OP_START; + /* check if UART is busy */ + if( (rsp_op_start != 0U) || (header_op_start != 0U) ) + { + ret = ERR; + } + else + { + /* reset rx fifo then disable fifo */ + uartFifoControlBuf[uartId] |= UART_RESET_RX_FIFO; + UARTxw->UART_IIR_FCR.UART_FCR = uartFifoControlBuf[uartId]; + uartFifoControlBuf[uartId] &= (~UART_RESET_RX_FIFO); + + uartFifoControlBuf[uartId] &= ~UART_ENABLE_FIFO; + UARTxw->UART_IIR_FCR.UART_FCR = uartFifoControlBuf[uartId]; + + UARTx->UART_LIN_CTL.MASTER_MODE = 0U; + /* start to receive */ + UARTx->UART_LIN_CTL.HEADER_OP_START = 1U; + + ret = SUCC; + } + + return ret; +} + +/** + * @brief Read the 6-bit ID(exclude parity bits) of header + * @param[in] uartId: Select the UART port. + * + * @return ID + */ +uint32_t UART_LinGetId(UART_ID_t uartId) +{ + uart_reg_t * UARTx = (uart_reg_t *)(uartRegPtr[uartId]); + + return UARTx->UART_LIN_PID_VALUE.PID; +} + +/** + * @brief start to send a response + * @param[in] uartId: Select the UART port. + * + * @param[in] rsp: Points to reponse structure to be sent. + * @return + * - SUCC : response is sent + * - ERR : resoponse is not sent due to UART is busy + */ +ResultStatus_t UART_LinSendResponse(UART_ID_t uartId, + const UART_LinResponse_t *rsp) +{ + ResultStatus_t ret; + uart_reg_t * UARTx = (uart_reg_t *)(uartRegPtr[uartId]); + uart_reg_w_t * UARTxw = (uart_reg_w_t *)(uartRegWPtr[uartId]); + + uint32_t rsp_op_start = UARTx->UART_LIN_CTL.RSP_OP_START; + uint32_t header_op_start = UARTx->UART_LIN_CTL.HEADER_OP_START; + if((rsp->len > 8U) || ( (rsp_op_start != 0U)|| (header_op_start != 0U))) + { + ret = ERR; + } + else + { + /* enable fifo */ + uartFifoControlBuf[uartId] |= UART_ENABLE_FIFO; + UARTxw->UART_IIR_FCR.UART_FCR = uartFifoControlBuf[uartId]; + + UARTx->UART_LIN_RSP_LENGTH.RSP_LENGTH = (uint32_t)rsp->len; + UARTx->UART_LIN_CHECKSUM.CHECKSUM_TYPE = (uint32_t)rsp->checkType; + + for(uint32_t cnt = 0U; cnt < rsp->len; cnt++) + { + UARTxw->UART_RBR_THR_DLL.UART_THR = (uint32_t)rsp->data[cnt]; + } + + UARTx->UART_LIN_CTL.RSP_DIR = 1U; + + UARTx->UART_LIN_CTL.RSP_OP_START = 1U; + + ret = SUCC; + } + + return ret; +} + +/** + * @brief Start to receive a response + * @param[in] uartId: Select the UART port. + * + * @param[in] check: Checksum type. + * @param[in] len: Response length, the maximun value is 8 bytes in a frame. + * @return + * - SUCC : it starts to receive response + * - ERR : it dose not start to receive response due to UART is busy + */ +ResultStatus_t UART_LinStartReceiveResponse(UART_ID_t uartId, + UART_LinCheckSum_t check, + uint32_t len) +{ + ResultStatus_t ret; + uart_reg_t * UARTx = (uart_reg_t *)(uartRegPtr[uartId]); + uart_reg_w_t * UARTxw = (uart_reg_w_t *)(uartRegWPtr[uartId]); + + uint32_t rsp_op_start = UARTx->UART_LIN_CTL.RSP_OP_START; + uint32_t header_op_start = UARTx->UART_LIN_CTL.HEADER_OP_START; + + /* check if UART is busy */ + if((rsp_op_start != 0U) || (header_op_start !=0U)) + { + ret = ERR; + } + else + { + /* enable fifo and reset rx fifo */ + uartFifoControlBuf[uartId] |= UART_ENABLE_FIFO; + UARTxw->UART_IIR_FCR.UART_FCR = uartFifoControlBuf[uartId]; + + uartFifoControlBuf[uartId] |= UART_RESET_RX_FIFO; + UARTxw->UART_IIR_FCR.UART_FCR = uartFifoControlBuf[uartId]; + uartFifoControlBuf[uartId] &= (~UART_RESET_RX_FIFO); + + UARTx->UART_LIN_RSP_LENGTH.RSP_LENGTH = len; + UARTx->UART_LIN_CHECKSUM.CHECKSUM_TYPE = (uint32_t)check; + + UARTx->UART_LIN_CTL.RSP_DIR = 0U; + + UARTx->UART_LIN_CTL.RSP_OP_START = 1U; + + ret = SUCC; + } + return ret; +} + +/** + * @brief read a response. if a reponse is received, this function can be + * called to get the data of response. This function is called + * after UART_LinStartReceiveResponse() and UART_INTSTA_RSP_DONE + * status is set. + * @param[in] uartId: Select the UART port. + * @param[in] len: response length to be read. + * @param[out] data: points to the memory where the response data to be stored. + * the memory size must not be smaller than len + * @return none + */ +void UART_LinReadResponse(UART_ID_t uartId, uint32_t len, uint8_t data[]) +{ + uart_reg_t * UARTx = (uart_reg_t *)(uartRegPtr[uartId]); + + for(uint32_t cnt = 0U; cnt < len; cnt++) + { + data[cnt] = (uint8_t)UARTx->UART_RBR_THR_DLL.UART_RBR.RBR_LSB; + } +} + +/** + * @brief Get current value of Line Status register + * + * @param[in] uartId: Select the UART port. + * @param[in] lineStatus: + * - UART_LINESTA_DR + * - UART_LINESTA_OE + * - UART_LINESTA_PE + * - UART_LINESTA_FE + * - UART_LINESTA_BI + * - UART_LINESTA_THRE + * - UART_LINESTA_TEMT + * - UART_LINESTA_RFE + * - UART_LINESTA_TRANS_ERR + * - UART_LINESTA_ADDR_RCVD + * - UART_LINESTA_ASYNC + * - UART_LINESTA_FIELD_ERR + * - UART_LINESTA_PID_ERR + * - UART_LINESTA_CHECKSUM_ERR + * - UART_LINESTA_TO_ERR + * - UART_LINESTA_HEADER_DONE + * - UART_LINESTA_RSP_DONE + * + * @note This function returns only one line status. However, once call + * this function, all line status will be cleared. If user + * needs to read more than one line status, it is suggested to use + * UART_GetAllLineStatus() to get all line status and handle them + * one by one. + * @return The state value of UART Line Status register + * + */ +FlagStatus_t UART_GetLineStatus(UART_ID_t uartId, UART_LineStatus_t lineStatus) +{ + FlagStatus_t bitStatus; + uart_reg_w_t * UARTxw = (uart_reg_w_t *)(uartRegWPtr[uartId]); + + bitStatus = (((UARTxw->UART_LSR & uartLineStatusTable[lineStatus]) != 0U) + ? SET : RESET); + + return bitStatus; +} + +/** + * @brief Get all Line Status + * + * @param[in] uartId: Select the UART port. + * + * @note Once call the function, line status will be cleared + * + * @return The state value of UART Line Status register + * + */ +uint32_t UART_GetAllLineStatus(UART_ID_t uartId) +{ + uart_reg_w_t * UARTxw = (uart_reg_w_t *)(uartRegWPtr[uartId]); + + return ((uint32_t)UARTxw->UART_LSR & 0xFFFFU); +} + +/** + * @brief Get busy status + * + * @param[in] uartId: Select the UART port. + * + * @return The state value of busy Status + * + */ +FlagStatus_t UART_GetBusyStatus(UART_ID_t uartId) +{ + uart_reg_t * UARTx = (uart_reg_t *)(uartRegPtr[uartId]); + + return (UARTx->UART_USR.BUSY != 0U) ? SET : RESET; +} + +/** + * @brief Get current UART interrupt status except async status + * + * @param[in] uartId: Select the UART port. + * @param[in] intType: select interrupt + * + * @note If user needs to get async status, user can use UART_GetLineStatus + * function. + * + * @return The state value of UART Status register + */ +IntStatus_t UART_GetIntStatus(UART_ID_t uartId, UART_Int_t intType) +{ + IntStatus_t bitStatus ; + uart_reg_t * UARTx = (uart_reg_t *)(uartRegPtr[uartId]); + + bitStatus = ((UARTx->UART_IIR_FCR.UART_IIR.IID == + uartInterruptStatusTable[intType] ) ? SET : RESET); + + return bitStatus; +} + +/** + * @brief Mask/Unmask the UART interrupt, UART_INT_BYDET cannot be masked, + * UART_INT_RCVRTO is only effective when fifo enable. + * + * @param[in] uartId: Select the UART port. + * @param[in] intType: Specifies the interrupt type + * @param[in] intMask: Enable/Disable Specified interrupt type + * + * @return none + * + */ +void UART_IntMask(UART_ID_t uartId, UART_Int_t intType, IntMask_t intMask) +{ + uart_reg_w_t * UARTxw = (uart_reg_w_t *)(uartRegWPtr[uartId]); + + if(intMask == UNMASK) + { + UARTxw->UART_DLH_IER.UART_IER |= (uartInterruptMaskTable[intType]); + } + else + { + UARTxw->UART_DLH_IER.UART_IER &= (~(uartInterruptMaskTable[intType])); + } +} + +/** + * @brief UART0 interrupt function + * + * @param none + * + * @return none + * + */ +void UART0_DriverIRQHandler(void) +{ + UART_IntHandler(UART0_ID); +} +/** + * @brief UART1 interrupt function + * + * @param none + * + * @return none + * + */ +void UART1_DriverIRQHandler(void) +{ + UART_IntHandler(UART1_ID); +} + +/** + * @brief UART2 interrupt function + * + * @param none + * + * @return none + * + */ +void UART2_DriverIRQHandler(void) +{ + UART_IntHandler(UART2_ID); +} + +#if (4U == UART_INSTANCE_NUM) +/** + * @brief UART3 interrupt function + * + * @param none + * + * @return none + * + */ +void UART3_DriverIRQHandler(void) +{ + UART_IntHandler(UART3_ID); +} +#endif + +/** @}end of group UART_Public_Functions */ + +/** @}end of group UART_definitions */ + +/** @}end of group Z20K11X_Peripheral_Driver */ diff --git a/StdDriver/Src/Z20K11xM_wdog.c b/StdDriver/Src/Z20K11xM_wdog.c new file mode 100644 index 0000000..66869d1 --- /dev/null +++ b/StdDriver/Src/Z20K11xM_wdog.c @@ -0,0 +1,772 @@ +/**************************************************************************************************/ +/** + * @file : Z20K11xM_wdog.c + * @brief : WDOG module driver file. + * @version : V1.8.0 + * @date : May-2020 + * @author : Zhixin Semiconductor + * + * @note + * @copyright : Copyright (c) 2020-2023 Zhixin Semiconductor Ltd. All rights reserved. + **************************************************************************************************/ + +#include "Z20K11xM_wdog.h" + +/** @addtogroup Z20K11X_Peripheral_Driver + * @{ + */ + +/** @defgroup WDOG + * @brief WDOG driver modules + * @{ + */ + +/** @defgroup WDOG_Private_Defines + * @{ + */ +#define WDOG_CS_INTF_MASK (0x04000000U) +#define WDOG_CS_CFGUF_MASK (0x01000000U) + +#define WDOG_CS_TSTM_MASK (0x00070000U) +#define WDOG_CS_CLKS_MASK (0x00000300U) +#define WDOG_CS_CFGUA_MASK (0x00000040U) +#define WDOG_CS_WINE_MASK (0x00000020U) +#define WDOG_CS_INTE_MASK (0x00000010U) +#define WDOG_CS_STOPE_MASK (0x00000008U) +#define WDOG_CS_WAITE_MASK (0x00000004U) +#define WDOG_CS_DEBUGE_MASK (0x00000002U) +#define WDOG_CS_WDOGE_MASK (0x00000001U) + +#define WDOG_CS_INTF_SHIFT (26U) +#define WDOG_CS_TSTM_SHIFT (16U) +#define WDOG_CS_CLKS_SHIFT (8U) +#define WDOG_CS_CFGUA_SHIFT (6U) +#define WDOG_CS_WINE_SHIFT (5U) +#define WDOG_CS_INTE_SHIFT (4U) +#define WDOG_CS_STOPE_SHIFT (3U) +#define WDOG_CS_WAITE_SHIFT (2U) +#define WDOG_CS_DEBUGE_SHIFT (1U) + +#define WDOG_CS_TSTM_SET(x) \ + (((uint32_t)(((uint32_t)(x)) << WDOG_CS_TSTM_SHIFT)) & WDOG_CS_TSTM_MASK) + +#define WDOG_CS_CLKS_SET(x) \ + (((uint32_t)(((uint32_t)(x)) << WDOG_CS_CLKS_SHIFT)) & WDOG_CS_CLKS_MASK) + +#define WDOG_CS_CFGUA_SET(x) \ + (((uint32_t)(((uint32_t)(x)) << WDOG_CS_CFGUA_SHIFT)) & WDOG_CS_CFGUA_MASK) + +#define WDOG_CS_WINE_SET(x) \ + (((uint32_t)(((uint32_t)(x)) << WDOG_CS_WINE_SHIFT)) & WDOG_CS_WINE_MASK) + +#define WDOG_CS_STOPE_SET(x) \ + (((uint32_t)(((uint32_t)(x)) << WDOG_CS_STOPE_SHIFT)) & WDOG_CS_STOPE_MASK) + +#define WDOG_CS_WAITE_SET(x) \ + (((uint32_t)(((uint32_t)(x)) << WDOG_CS_WAITE_SHIFT)) & WDOG_CS_WAITE_MASK) + +#define WDOG_CS_DEBUGE_SET(x) \ + (((uint32_t)(((uint32_t)(x)) << WDOG_CS_DEBUGE_SHIFT)) & \ + WDOG_CS_DEBUGE_MASK) + +#define WDOG_CS_INTE_SET(x) \ + (((uint32_t)(((uint32_t)(x)) << WDOG_CS_INTE_SHIFT)) & WDOG_CS_INTE_MASK) + +#define WDOG_UNLOCK_CONFIG_VALUE1 (0xB0D9A1C4U) +#define WDOG_UNLOCK_CONFIG_VALUE2 (0x1A1E3B0FU) +#define WDOG_REFRESH_VALUE1 (0xA0C4B1D6U) +#define WDOG_REFRESH_VALUE2 (0x1E0D0C7BU) + +#define WDOG_MASK_CONVERT_ENABLE(x) \ + ((uint32_t)((((uint32_t)(x) + 1U) & 0x1U) << WDOG_CS_INTE_SHIFT)) + +START_FUNCTION_DECLARATION_RAMSECTION +static void WDOG_REFRESH_COUNT(void) +END_FUNCTION_DECLARATION_RAMSECTION /* PRQA S 0605*/ + +/** @} end of group WDOG_Private_Defines */ + +/** @defgroup WDOG_Private_Type + * @{ + */ + +/** @} end of group WDOG_Private_Type*/ + +/** @defgroup WDOG_Private_Variables + * @{ + */ + +/** + * @brief WDOG Register address array + */ +/*PRQA S 0303 ++*/ +static wdog_reg_t *const wdogRegPtr = (wdog_reg_t *)WDOG_BASE_ADDR; +static wdog_reg_w_t *const wdogRegWPtr = (wdog_reg_w_t *)WDOG_BASE_ADDR; +/*PRQA S 0303 --*/ +/*! @brief wdog int status mask array */ +static const uint32_t wdogIntMask[] = {WDOG_CS_INTE_MASK, WDOG_CS_INTE_MASK}; + +static const uint32_t wdogIntFlagMask[] = {WDOG_CS_INTF_MASK, + WDOG_CS_INTF_MASK}; + +/*! @brief WDOG ISR CallBack VECTOR structure */ +static isr_cb_t *wdogIsrCb[WDOG_INT_ALL] = {NULL}; + +/** @} end of group WDOG_Private_Variables */ + +/** @defgroup WDOG_Global_Variables + * @{ + */ + +/** @} end of group WDOG_Global_Variables */ + +/** @defgroup WDOG_Private_FunctionDeclaration + * @{ + */ +void WDOG_DriverIRQHandler(void); +/** @} end of group WDOG_Private_FunctionDeclaration */ + +/** @defgroup WDOG_Private_Functions + * @{ + */ + +/** + * @brief wait until configuration update is completed Function + * + * @param[in] none + * + * @return wait operation status. + * + */ +static inline ResultStatus_t WDOG_WaitConfigCompleted(void) +{ + wdog_reg_t *WDOGx = (wdog_reg_t *)(wdogRegPtr); + volatile uint32_t uLoop = 0U; + ResultStatus_t retVal = SUCC; + + while ((uint32_t)SET != WDOGx->WDOG_CS.CFGUF) + { + if (uLoop > WDOG_WAITCONFIG_GOING_CNT) + { + retVal = ERR; + break; + } + + uLoop++; + } + + return retVal; +} + +/** + * @brief wdog counter register write REFRESH sequence Function + * + * @param[in] none + * + * @note If user has no need to enable irq, in next step user should + * disable_irq after calling this function. + * + * @return none + * + */ +static void WDOG_REFRESH_COUNT(void) +{ + uint32_t Primask = __get_PRIMASK(); + if (0U == Primask) + { + __disable_irq(); + } + __asm("PUSH {R0, R1, R2}\n" + "LDR R0, =0x40052014\n" + "LDR R1, =0xA0C4B1D6\n" + "LDR R2, =0x1E0D0C7B\n" + + "STR R1, [R0]\n" + "STR R2, [R0]\n" + "POP {R0, R1, R2}\n"); + if (0U == Primask) + { + __enable_irq(); + } +} + +/** + * @brief wdog counter register write UNLOCK sequence Function + * + * @param[in] none + * + * @note If user has no need to enable irq, in next step user should + * disable_irq after calling this function. + * + * @return none + * + */ +static inline void WDOG_UNLOCK_CONFIG(void) +{ + uint32_t Primask = __get_PRIMASK(); + if (0U == Primask) + { + __disable_irq(); + } + __asm("PUSH {R0, R1, R2}\n" + "LDR R0, =0x40052014\n" + "LDR R1, =0xB0D9A1C4\n" + "LDR R2, =0x1A1E3B0F\n" + + "STR R1, [R0]\n" + "STR R2, [R0]\n" + "POP {R0, R1, R2}\n"); + if (0U == Primask) + { + __enable_irq(); + } +} + +/** @} end of group WDOG_Private_Functions */ + +/** @defgroup WDOG_Public_Functions + * @{ + */ + +/** + * @brief wdog Initializes Function + * + * @param[in] ptWDOGInitConfig: Pointer to a WDOG configuration structure. + * + * @note If user has no need to enable irq, in next step user should + * disable_irq after calling this function. + * + * @return Initializes operate flag + * + */ +ResultStatus_t WDOG_Init(const WDOG_Config_t *ptWDOGInitConfig) +{ + wdog_reg_t *WDOGx = (wdog_reg_t *)(wdogRegPtr); + wdog_reg_w_t *WDOGxw = (wdog_reg_w_t *)(wdogRegWPtr); + ResultStatus_t retVal = SUCC; + uint32_t wdog_cs = WDOGxw->WDOG_CS; + + if (0U == WDOGx->WDOG_CS.CFGUA) + { + retVal = ERR; + } + + if (SUCC == retVal) + { + /* Clear the bits used for configuration */ + wdog_cs &= + ~(WDOG_CS_TSTM_MASK | WDOG_CS_CLKS_MASK | WDOG_CS_WINE_MASK | + WDOG_CS_STOPE_MASK | WDOG_CS_WAITE_MASK | WDOG_CS_DEBUGE_MASK); + + /* Construct CS register new value */ + wdog_cs |= WDOG_CS_TSTM_SET(ptWDOGInitConfig->testMode); + wdog_cs |= WDOG_CS_CLKS_SET(ptWDOGInitConfig->clkSource); + wdog_cs |= WDOG_CS_WINE_SET(ptWDOGInitConfig->winEnable); + wdog_cs |= WDOG_CS_STOPE_SET(ptWDOGInitConfig->stop); + wdog_cs |= WDOG_CS_WAITE_SET(ptWDOGInitConfig->wait); + wdog_cs |= WDOG_CS_DEBUGE_SET(ptWDOGInitConfig->debug); + + /* unlock config update */ + WDOG_UNLOCK_CONFIG(); + WDOGxw->WDOG_CS = wdog_cs; + retVal = WDOG_WaitConfigCompleted(); + if (SUCC == retVal) + { + WDOG_UNLOCK_CONFIG(); + WDOGxw->WDOG_TMO = ptWDOGInitConfig->timeoutValue; + retVal = WDOG_WaitConfigCompleted(); + if (SUCC == retVal) + { + if (ENABLE == ptWDOGInitConfig->winEnable) + { + WDOG_UNLOCK_CONFIG(); + WDOGxw->WDOG_WIN = ptWDOGInitConfig->windowValue; + retVal = WDOG_WaitConfigCompleted(); + } + } + } + } + + return retVal; +} + +/** + * @brief enable wdog count Function + * + * @param[in] none + * + * @note If user has no need to enable irq, in next step user should + * disable_irq after calling this function. + * + * @return operation status. + * + */ +ResultStatus_t WDOG_Enable(void) +{ + wdog_reg_t *WDOGx = (wdog_reg_t *)(wdogRegPtr); + /* unlock config update */ + WDOG_UNLOCK_CONFIG(); + WDOGx->WDOG_CS.WDOGE = 1U; + + return (WDOG_WaitConfigCompleted()); +} + +/** + * @brief disable wdog count Function + * + * @param[in] none + * + * @note If user has no need to enable irq, in next step user should + * disable_irq after calling this function. + * + * @return operation status. + * + */ +ResultStatus_t WDOG_Disable(void) +{ + wdog_reg_t *WDOGx = (wdog_reg_t *)(wdogRegPtr); + /* unlock config update */ + WDOG_UNLOCK_CONFIG(); + WDOGx->WDOG_CS.WDOGE = 0U; + + return (WDOG_WaitConfigCompleted()); +} + +/** + * @brief refresh wdog count Function + * + * @param[in] none + * + * @note If user has no need to enable irq, in next step user should + * disable_irq after calling this function. + * + * @return none. + * + */ +void WDOG_Refresh(void) +{ + WDOG_REFRESH_COUNT(); +} + +/** + * @brief get wdog config allow flag status Function + * + * @param[in] none + * + * @return busy status. + * + */ +FlagStatus_t WDOG_GetConfigAllowStatus(void) +{ + wdog_reg_t *WDOGx = (wdog_reg_t *)(wdogRegPtr); + return ((FlagStatus_t)WDOGx->WDOG_CS.CFGUA); +} + +/** + * @brief set wdog config allow flag Function + * + * @param[in] allow: config update control + * - ENABLE: enable config update + * - DISABLE: disbale config update + * + * @note If user has no need to enable irq, in next step user should + * disable_irq after calling this function. + * + * @return operation status. + * + */ +ResultStatus_t WDOG_ConfigAllowControl(ControlState_t allow) +{ + wdog_reg_t *WDOGx = (wdog_reg_t *)(wdogRegPtr); + /* unlock config update */ + WDOG_UNLOCK_CONFIG(); + WDOGx->WDOG_CS.CFGUA = (uint32_t)allow; + + return (WDOG_WaitConfigCompleted()); +} + +/** + * @brief enable/disbale wdog window mode Function + * + * @param[in] winEnable: window mode control + * - ENABLE: enable window mode + * - DISABLE: disbale window mode + * + * @note If user has no need to enable irq, in next step user should + * disable_irq after calling this function. + * + * @return operation status. + * + */ +ResultStatus_t WDOG_WindowModeControl(ControlState_t winEnable) +{ + wdog_reg_t *WDOGx = (wdog_reg_t *)(wdogRegPtr); + /* unlock config update */ + WDOG_UNLOCK_CONFIG(); + WDOGx->WDOG_CS.WINE = (uint32_t)winEnable; + + return (WDOG_WaitConfigCompleted()); +} + +/** + * @brief set wdog window value Function + * + * @param[in] windowValue: window value, 32 bits + * + * @note If user has no need to enable irq, in next step user should + * disable_irq after calling this function. + * + * @return operation status. + * + */ +ResultStatus_t WDOG_SetWindowValue(uint32_t windowValue) +{ + wdog_reg_w_t *WDOGxw = (wdog_reg_w_t *)(wdogRegWPtr); + /* unlock config update */ + WDOG_UNLOCK_CONFIG(); + WDOGxw->WDOG_WIN = windowValue; + + return (WDOG_WaitConfigCompleted()); +} + +/** + * @brief get wdog window register value Function + * + * @param[in] none + * + * @return window register value. + * + */ +uint32_t WDOG_GetWindowValue(void) +{ + wdog_reg_t *WDOGx = (wdog_reg_t *)(wdogRegPtr); + return ((uint32_t)WDOGx->WDOG_WIN.WIN); +} + +/** + * @brief set wdog clock source Function + * + * @param[in] clkSource: clock source + * + * @note If user has no need to enable irq, in next step user should + * disable_irq after calling this function. + * + * @return operation status. + * + */ +ResultStatus_t WDOG_SetClockSource(WDOG_ClkSource_t clkSource) +{ + wdog_reg_t *WDOGx = (wdog_reg_t *)(wdogRegPtr); + /* unlock config update */ + WDOG_UNLOCK_CONFIG(); + WDOGx->WDOG_CS.CLKS = (uint32_t)clkSource; + + return (WDOG_WaitConfigCompleted()); +} + +/** + * @brief set wdog timeout value Function + * + * @param[in] timeoutValue: timeout value, 32 bits + * + * @note If user has no need to enable irq, in next step user should + * disable_irq after calling this function. + * + * @return operation status. + * + */ +ResultStatus_t WDOG_SetTimeoutValue(uint32_t timeoutValue) +{ + wdog_reg_w_t *WDOGxw = (wdog_reg_w_t *)(wdogRegWPtr); + uint32_t Primask = __get_PRIMASK(); + if (0U == Primask) + { + __disable_irq(); + } + /* unlock config update */ + WDOGxw->WDOG_CNT = 0xB0D9A1C4U; + WDOGxw->WDOG_CNT = 0x1A1E3B0FU; + WDOGxw->WDOG_TMO = timeoutValue; + if (0U == Primask) + { + __enable_irq(); + } + return (WDOG_WaitConfigCompleted()); +} + +/** + * @brief get wdog timeout register value Function + * + * @param[in] none + * + * @return timeout register value. + * + */ +uint32_t WDOG_GetTimeoutValue(void) +{ + wdog_reg_t *WDOGx = (wdog_reg_t *)(wdogRegPtr); + return ((uint32_t)WDOGx->WDOG_TMO.TMO); +} + +/** + * @brief configure wdog behavior in stop mode Function + * + * @param[in] cmd: stop mode control + * - ENABLE: counter continue in stop mode + * - DISABLE: counter halt in stop mode + * + * @note If user has no need to enable irq, in next step user should + * disable_irq after calling this function. + * + * @return operation status. + * + */ +ResultStatus_t WDOG_StopModeControl(ControlState_t cmd) +{ + wdog_reg_t *WDOGx = (wdog_reg_t *)(wdogRegPtr); + /* unlock config update */ + WDOG_UNLOCK_CONFIG(); + WDOGx->WDOG_CS.STOPE = (uint32_t)cmd; + + return (WDOG_WaitConfigCompleted()); +} + +/** + * @brief configure wdog behavior in wait mode Function + * + * @param[in] cmd: wait mode control + * - ENABLE: counter continue in wait mode + * - DISABLE: counter halt in wait mode + * + * @note If user has no need to enable irq, in next step user should + * disable_irq after calling this function. + * + * @return operation status. + * + */ +ResultStatus_t WDOG_WaitModeControl(ControlState_t cmd) +{ + wdog_reg_t *WDOGx = (wdog_reg_t *)(wdogRegPtr); + /* unlock config update */ + WDOG_UNLOCK_CONFIG(); + WDOGx->WDOG_CS.WAITE = (uint32_t)cmd; + + return (WDOG_WaitConfigCompleted()); +} + +/** + * @brief configure wdog behavior in debug mode Function + * + * @param[in] cmd: debug mode control + * - ENABLE: counter continue in debug mode + * - DISABLE: counter halt in debug mode + * + * @note If user has no need to enable irq, in next step user should + * disable_irq after calling this function. + * + * @return operation status. + * + */ +ResultStatus_t WDOG_DebugModeControl(ControlState_t cmd) +{ + wdog_reg_t *WDOGx = (wdog_reg_t *)(wdogRegPtr); + /* unlock config update */ + WDOG_UNLOCK_CONFIG(); + WDOGx->WDOG_CS.DEBUGE = (uint32_t)cmd; + + return (WDOG_WaitConfigCompleted()); +} + +/** + * @brief set wdog test mode Function + * + * @param[in] testMode: test/normal mode + * + * @note If user has no need to enable irq, in next step user should + * disable_irq after calling this function. + * + * @return operation status. + * + */ +ResultStatus_t WDOG_SetTestMode(WDOG_TestMode_t testMode) +{ + wdog_reg_t *WDOGx = (wdog_reg_t *)(wdogRegPtr); + /* unlock config update */ + WDOG_UNLOCK_CONFIG(); + WDOGx->WDOG_CS.TSTM = (uint32_t)testMode; + + return (WDOG_WaitConfigCompleted()); +} + +/** + * @brief get wdog test/normal mode Function + * + * @param[in] none + * + * @return test/normal mode. + * + */ +WDOG_TestMode_t WDOG_GetTestMode(void) +{ + wdog_reg_t *WDOGx = (wdog_reg_t *)(wdogRegPtr); + return ((WDOG_TestMode_t)WDOGx->WDOG_CS.TSTM); +} + +/** + * @brief get wdog free-running counter Function + * + * @param[in] none + * + * @return free-running counter value. + * + */ +uint32_t WDOG_GetCounter(void) +{ + wdog_reg_t *WDOGx = (wdog_reg_t *)(wdogRegPtr); + return ((uint32_t)WDOGx->WDOG_CNT.CNT); +} + +/** + * @brief get flag indcates configuration update is completed Function + * + * @param[in] none + * + * @return configuration update completed status. + * + */ +FlagStatus_t WDOG_GetConfigCompletedStatus(void) +{ + wdog_reg_t *WDOGx = (wdog_reg_t *)(wdogRegPtr); + return ((FlagStatus_t)WDOGx->WDOG_CS.CFGUF); +} + +/** + * @brief get Flag indcates all registers are locked or unlocked Function + * + * @param[in] none + * + * @return lock Flag. + * + */ +FlagStatus_t WDOG_GetLockStatus(void) +{ + wdog_reg_t *WDOGx = (wdog_reg_t *)(wdogRegPtr); + return ((WDOGx->WDOG_CS.UNLKF == 1U) ? RESET : SET); +} + +/** + * @brief get WDOG int flag Function + * + * @param[in] intType: int type + * - WDOG_INT_BEFORERESET: int befor reset + * - WDOG_INT_ALL: all int type + * + * @return whether a int is asserted or not. + * + */ +IntStatus_t WDOG_GetIntStatus(WDOG_INT_t intType) +{ + wdog_reg_w_t *WDOGxw = (wdog_reg_w_t *)(wdogRegWPtr); + return ( + (IntStatus_t)((uint32_t)((WDOGxw->WDOG_CS & wdogIntFlagMask[intType]) >> + WDOG_CS_INTF_SHIFT))); +} + +/** + * @brief clear wdog int flag Function + * + * @param[in] intType: int type + * - WDOG_INT_BEFORERESET: int befor reset + * - WDOG_INT_ALL: all int type + * + * @note If user has no need to enable irq, in next step user should + * disable_irq after calling this function. + * + * @return operation status. + * + */ +ResultStatus_t WDOG_ClearIntStatus(WDOG_INT_t intType) +{ + wdog_reg_w_t *WDOGxw = (wdog_reg_w_t *)(wdogRegWPtr); + /* unlock config update */ + WDOG_UNLOCK_CONFIG(); + WDOGxw->WDOG_CS |= wdogIntFlagMask[intType]; + + return (WDOG_WaitConfigCompleted()); +} + +/** + * @brief set wdog int mask Function + * + * @param[in] intType: int type + * - WDOG_INT_BEFORERESET: int befor reset + * - WDOG_INT_ALL: all int type + * @param[in] intMask: int mask + * + * @note If user has no need to enable irq, in next step user should + * disable_irq after calling this function. + * + * @return operation status. + * + */ +ResultStatus_t WDOG_IntMask(WDOG_INT_t intType, IntMask_t intMask) +{ + wdog_reg_w_t *WDOGxw = (wdog_reg_w_t *)(wdogRegWPtr); + uint32_t uTmp; + + uTmp = WDOGxw->WDOG_CS; + + uTmp &= ~wdogIntMask[intType]; + uTmp |= WDOG_MASK_CONVERT_ENABLE(intMask); + + /* unlock config update */ + WDOG_UNLOCK_CONFIG(); + WDOGxw->WDOG_CS = uTmp; + + return (WDOG_WaitConfigCompleted()); +} + +/** + * @brief Install callback function + * + * @param[in] intType: select interrrupt type + * - WDOG_INT_BEFORERESET: int befor reset + * @param[in] cbFun: indicate callback function + * + * @return none + * + */ +void WDOG_InstallCallBackFunc(WDOG_INT_t intType, isr_cb_t *cbFun) +{ + if (intType < WDOG_INT_ALL) + { + wdogIsrCb[intType] = cbFun; + } +} + +/** + * @brief WDOG interrupt function in vector + * + * @param none + * + * @return none + * + */ +void WDOG_DriverIRQHandler(void) +{ + wdog_reg_w_t *WDOGxw = (wdog_reg_w_t *)(wdogRegWPtr); + if (wdogIsrCb[WDOG_INT_BEFORERESET] != NULL) + { + wdogIsrCb[WDOG_INT_BEFORERESET](); + } + + /* unlock config update */ + WDOG_UNLOCK_CONFIG(); + WDOGxw->WDOG_CS |= wdogIntFlagMask[WDOG_INT_BEFORERESET]; +} + +/** @} end of group WDOG_Public_Functions */ + +/** @} end of group WDOG driver modules */ + +/** @} end of group Z20K11X_Peripheral_Driver */ -- 2.34.1