diff --git a/EVT/CH32V20x_List.txt b/EVT/CH32V20x_List.txt index e3676bf..e84efe4 100644 --- a/EVT/CH32V20x_List.txt +++ b/EVT/CH32V20x_List.txt @@ -1,5 +1,5 @@ -南京沁恒微电子股份有限公司 2025.10 +南京沁恒微电子股份有限公司 2026.07 最新资料请到我们的网站上查询 https://wch.cn @@ -45,6 +45,10 @@ https://wch.cn | | | | | |-- WS2812_LED:通过SPI\PWM操作WS2812例程 | | | | |-- CoreMark | | | | | |-- CoreMark:168M(12M_HSE)系统时钟下CoreMark跑分例程——仅适用于CH32V20x_D6,168M仅适用于商业级应用:0℃ ≤TA ≤ 70℃且散热良好 + | | | | |-- Electric_Hair_Dryer + | | | | | |-- Electric_Hair_Dryer:吹风机例程 + | | | | |-- WUI + | | | | | |-- WUI:WCHGUI例程 | | | |-- BLE ——仅适用于CH32V20x_D8W | | | | |-- BackupUpgrade_IAP:备份无线升级IAP例程,检测当前代码标志,判断是否搬运备份区代码到用户区并运行用户区代码 | | | | |-- BackupUpgrade_OTA:备份无线升级用户例程,外设从机例程基础上添加OTA功能,可将升级固件保存到备份区后跳转IAP程序进行升级 diff --git a/EVT/CH32V20x_List_EN.txt b/EVT/CH32V20x_List_EN.txt index 4be7448..baf582c 100644 --- a/EVT/CH32V20x_List_EN.txt +++ b/EVT/CH32V20x_List_EN.txt @@ -1,5 +1,5 @@ -Nanjing Qinheng Microelectronics Co., Ltd. 2025.10 +Nanjing Qinheng Microelectronics Co., Ltd. 2026.07 https://wch-ic.com @@ -44,6 +44,10 @@ Directory | | | | | |-- WS2812_LED锛歋PI\PWM Operates WS2812_LED routine | | | | |-- CoreMark | | | | | |-- CoreMark锛欳oreMark routine under 168M锛�12M_HSE锛� system conditions鈥斺�攐nly applied to CH32V20x_D6,168M is only suitable for Commercial Grade applications: 0鈩� 鈮� TA 鈮� 70鈩� with good heat dissipation + | | | | |-- Electric_Hair_Dryer + | | | | | |-- Electric_Hair_Dryer锛欵lectric_Hair_Dryer routine + | | | | |-- WUI + | | | | | |-- WUI锛歐CHGUI routine | | | |-- BLE ----only for CH32V20x_D8W | | | | |-- BackupUpgrade_IAP: backup wireless upgrade IAP routine. Detect the current code flag, determine whether to move the code from the backup area to the user area, and run the code in the user area | | | | |-- BackupUpgrade_OTA: backup wireless upgrade user routine. Add OTA function to peripheral slave routines, save the upgrade firmware to the backup area and jump to the IAP program to upgrade diff --git a/EVT/EXAM/ADC/AnalogWatchdog/User/main.c b/EVT/EXAM/ADC/AnalogWatchdog/User/main.c index 4cee515..fb24434 100644 --- a/EVT/EXAM/ADC/AnalogWatchdog/User/main.c +++ b/EVT/EXAM/ADC/AnalogWatchdog/User/main.c @@ -1,8 +1,8 @@ /********************************** (C) COPYRIGHT ******************************* * File Name : main.c * Author : WCH - * Version : V1.0.0 - * Date : 2023/12/29 + * Version : V1.0.1 + * Date : 2026/05/13 * Description : Main program body. ********************************************************************************* * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. @@ -104,6 +104,7 @@ u16 Get_ADC_Val(u8 ch) { u16 val; + ADC_RegularChannelConfig(ADC1, ch, 1, ADC_SampleTime_239Cycles5); ADC_SoftwareStartConvCmd(ADC1, ENABLE); while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC)); diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/.cproject b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/.cproject new file mode 100644 index 0000000..d875f81 --- /dev/null +++ b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/.cproject @@ -0,0 +1,301 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/.project b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/.project new file mode 100644 index 0000000..354fa83 --- /dev/null +++ b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/.project @@ -0,0 +1,60 @@ + + + Electric_Hair_Dryer + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + + + Core + 2 + PARENT-2-PROJECT_LOC/SRC/Core + + + Debug + 2 + PARENT-2-PROJECT_LOC/SRC/Debug + + + Ld + 2 + PARENT-2-PROJECT_LOC/SRC/Ld + + + Peripheral + 2 + PARENT-2-PROJECT_LOC/SRC/Peripheral + + + Startup + 2 + PARENT-2-PROJECT_LOC/SRC/Startup + + + + + + 6 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-*.wvproj + + + + \ No newline at end of file diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/.template b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/.template new file mode 100644 index 0000000..022e2e2 --- /dev/null +++ b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/.template @@ -0,0 +1,32 @@ +Vendor=WCH +Toolchain=RISC-V +Series=CH32V203 +RTOS=NoneOS +CalibrateSupport=false +CalibrateCommand= +UIConfigSupport=false +UIConfigCommand= +ExternalFlashSupport=false +MCU=CH32V203RBT6 +Link=WCH-Link +PeripheralVersion=1.0 +Description=ROM(byte): 64K, SRAM(byte): 20K, CHIP PINS: 32, GPIO PORTS: 27.\nWCH CH32V2 series of mainstream MCUs covers the needs of a large variety of applications in the industrial,medical and consumer markets. High performance with first-class peripherals and low-power,low-voltage operation is paired with a high level of integration at accessible prices with a simple architecture and easy-to-use tools. +TempratureScope= +ArtifactType=executable +Mcu Type=CH32V20x +Address=0x08000000 +Target Path=obj/Electric_Hair_Dryer.hex +Exe Path= +Exe Arguments= +CLKSpeed=1 +DebugInterfaceMode=0 +Erase All=true +Program=true +Verify=true +Reset=true +SDIPrintf=false +Disable Power Output=false +Clear CodeFlash=false +Disable Code-Protect=false +Flash Type= +Algorithm File= \ No newline at end of file diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/DOC_SCH/CH32V203楂橀�熷惞椋庣瓛EMI鐗堟湰纭欢璇存槑.pdf b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/DOC_SCH/CH32V203楂橀�熷惞椋庣瓛EMI鐗堟湰纭欢璇存槑.pdf new file mode 100644 index 0000000..ee87574 Binary files /dev/null and b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/DOC_SCH/CH32V203楂橀�熷惞椋庣瓛EMI鐗堟湰纭欢璇存槑.pdf differ diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/DOC_SCH/HairDrier.pdf b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/DOC_SCH/HairDrier.pdf new file mode 100644 index 0000000..bf0ed29 Binary files /dev/null and b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/DOC_SCH/HairDrier.pdf differ diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/DOC_SCH/HairDrier/WCH_hairDrierBOTTOM_COM_V1.5.PcbDoc b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/DOC_SCH/HairDrier/WCH_hairDrierBOTTOM_COM_V1.5.PcbDoc new file mode 100644 index 0000000..dbc750b Binary files /dev/null and b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/DOC_SCH/HairDrier/WCH_hairDrierBOTTOM_COM_V1.5.PcbDoc differ diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/DOC_SCH/HairDrier/WCH_hairDrierBOTTOM_COM_V1.5.SchDoc b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/DOC_SCH/HairDrier/WCH_hairDrierBOTTOM_COM_V1.5.SchDoc new file mode 100644 index 0000000..b44d164 Binary files /dev/null and b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/DOC_SCH/HairDrier/WCH_hairDrierBOTTOM_COM_V1.5.SchDoc differ diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/DOC_SCH/HairDrier/WCH_hairDrierCore_V1.5.PcbDoc b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/DOC_SCH/HairDrier/WCH_hairDrierCore_V1.5.PcbDoc new file mode 100644 index 0000000..b6e735f Binary files /dev/null and b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/DOC_SCH/HairDrier/WCH_hairDrierCore_V1.5.PcbDoc differ diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/DOC_SCH/HairDrier/WCH_hairDrierCore_V1.5.SchDoc b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/DOC_SCH/HairDrier/WCH_hairDrierCore_V1.5.SchDoc new file mode 100644 index 0000000..17c5062 Binary files /dev/null and b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/DOC_SCH/HairDrier/WCH_hairDrierCore_V1.5.SchDoc differ diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/Electric_Hair_Dryer.wvproj b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/Electric_Hair_Dryer.wvproj new file mode 100644 index 0000000..f373ef9 --- /dev/null +++ b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/Electric_Hair_Dryer.wvproj @@ -0,0 +1,458 @@ +{ + "version": "1.0", + "hasAllParsed": true, + "isNormalMRSProject": true, + "basic": { + "chipInfo": { + "vendor": "WCH", + "toolchain": "RISC-V", + "series": "CH32V203", + "rtos": "NoneOS", + "mcu": "CH32V203RBT6", + "description": "ROM(byte): 64K, SRAM(byte): 20K, CHIP PINS: 32, GPIO PORTS: 27.\\nWCH CH32V2 series of mainstream MCUs covers the needs of a large variety of applications in the industrial,medical and consumer markets. High performance with first-class peripherals and low-power,low-voltage operation is paired with a high level of integration at accessible prices with a simple architecture and easy-to-use tools.", + "tempratureScope": "", + "artifactType": "executable", + "link": "WCH-Link", + "peripheral_version": "1.0", + "calibrateSupport": false, + "calibrateCommand": "", + "UIConfigSupport": false, + "UIConfigCommand": "", + "externalFlashSupport": false + }, + "linkedFolders": [ + { + "name": "Core", + "location": "../../SRC/Core" + }, + { + "name": "Debug", + "location": "../../SRC/Debug" + }, + { + "name": "Ld", + "location": "../../SRC/Ld" + }, + { + "name": "Peripheral", + "location": "../../SRC/Peripheral" + }, + { + "name": "Startup", + "location": "../../SRC/Startup" + } + ], + "removedResources": [ + { + "parentLogicPath": "", + "type": "file", + "name": "*.wvproj" + } + ], + "projectName": "Electric_Hair_Dryer", + "architecture": "RISC-V", + "projectType": "c" + }, + "buildConfig": { + "configurations": [ + { + "buildArtifact": { + "artifact_name": "${ProjName}", + "artifact_extension": "elf", + "output_prefix": "", + "artifact_type": "Executable" + }, + "parallelizationNumber": "optimal", + "stop_on_first_build_error": true, + "pre_script": "", + "pre_script_description": "", + "post_script": "", + "post_script_description": "", + "excludeResources": [ + "${project}/User/Motor_UsbData.h", + "${project}/User/Motor_UsbData.c", + "${project}/Startup/startup_ch32v20x_D8W.S", + "${project}/Startup/startup_ch32v20x_D8.S" + ], + "optimization": { + "level": "size", + "message_length": true, + "char_is_signed": true, + "function_sections": true, + "data_sections": true, + "no_common_unitialized": true, + "do_not_inline_functions": false, + "assume_freestanding_environment": false, + "disable_builtin": false, + "single_precision_constants": false, + "position_independent_code": false, + "link_time_optimizer": false, + "disable_loop_invariant_move": false, + "optimize_unused_sections_declared_as_high_code": false, + "code_generation_without_hardware_floating": false, + "use_pipelines": false, + "show_caret_indicating_the_column": false, + "calling_convention_variant": false, + "other_optimization_flags": "" + }, + "warnings": { + "check_syntax_only": false, + "pedantic": false, + "pedantic_warnings_as_errors": false, + "inhibit_all_warnings": false, + "warn_on_various_unused_elements": true, + "warn_on_uninitialized_variables": true, + "enable_all_common_warnings": false, + "enable_extra_warnings": false, + "warn_on_undeclared_global_function": false, + "warn_on_implicit_conversions": false, + "warn_if_pointer_arthmetic": false, + "warn_if_padding_is_included": false, + "warn_if_shadowed_variable": false, + "warn_if_suspicious_logical_ops": false, + "warn_if_struct_is_returned": false, + "warn_if_floats_are_compared_as_equal": false, + "generate_errors_instead_of_warnings": false, + "other_warning_flags": "" + }, + "debugging": { + "debug_level": "default", + "debug_format": "dwarf4", + "generate_prof_information": false, + "generate_gprof_information": false, + "other_debugging_flags": "" + }, + "assembler": { + "preprocessor": { + "use_preprocessor": true, + "do_not_search_system_directories": false, + "preprocess_only": false, + "defined_symbols": [], + "undefined_symbols": [] + }, + "includes": { + "include_paths": [ + "${project}/Startup" + ], + "include_system_paths": [], + "include_files": [] + }, + "other_warning_flags": "", + "miscellaneous": { + "assembler_flags": [], + "generate_assembler_listing": false, + "save_temporary_files": false, + "verbose": false, + "other_assembler_flags": "" + } + }, + "ccompiler": { + "preprocessor": { + "do_not_search_system_directories": false, + "preprocess_only": false, + "defined_symbols": [], + "undefined_symbols": [] + }, + "includes": { + "include_paths": [ + "${project}/Debug", + "${project}/Core", + "${project}/User", + "${project}/Peripheral/inc" + ], + "include_system_paths": [], + "include_files": [] + }, + "optimization": { + "language_standard": "gnu99", + "other_optimization_flags": "" + }, + "warnings": { + "warn_if_a_global_function_has_no_prototype": false, + "warn_if_a_function_has_no_arg_type": false, + "warn_if_wrong_cast": false, + "other_warning_flags": "" + }, + "miscellaneous": { + "generate_assembler_listing": false, + "save_temporary_files": false, + "verbose": false, + "other_compiler_flags": "" + } + }, + "cppcompiler": { + "preprocessor": { + "do_not_search_system_directories": false, + "do_not_search_system_cpp_directories": false, + "preprocess_only": false, + "defined_symbols": [], + "undefined_symbols": [] + }, + "includes": { + "include_paths": [], + "include_system_paths": [], + "include_files": [] + }, + "optimization": { + "cpp_language_standard": "gnucpp11", + "abi_version": "0", + "do_not_use_exceptions": false, + "do_not_use_rtti": false, + "do_not_use__cxa_atexit": false, + "do_not_use_thread_safe_statics": false, + "other_optimization_flags": "" + }, + "warnings": { + "warn_on_abi_violations": false, + "warn_on_class_privacy": false, + "warn_on_no_except_expressions": false, + "warn_on_virtual_destructors": false, + "warn_on_uncast_null": false, + "warn_on_sign_promotion": false, + "warn_about_effictive_cpp_violcations": false, + "other_warning_flags": "" + }, + "miscellaneous": { + "generate_assembler_listing": false, + "save_temporary_files": false, + "verbose": false, + "other_compiler_flags": "" + } + }, + "clinker": { + "general": { + "scriptFiles": [ + "${project}/Ld/Link.ld" + ], + "do_not_use_standard_start_files": true, + "do_not_use_default_libraries": false, + "no_startup_or_default_libs": false, + "remove_unused_sections": true, + "print_removed_sections": false, + "omit_all_symbol_information": false + }, + "libraries": { + "libraries": [ + "IQmath_RV32" + ], + "library_search_path": [ + "${project}/User" + ] + }, + "miscellaneous": { + "picolibc": "disabled", + "linker_flags": [], + "other_objects": [ + "${project}/User/libM12023_SV_1.0_COMCoreV1.5_Library.a", + "${project}/User/IQmath_RV32.a" + ], + "generate_map": "\"${BuildArtifactFileBaseName}.map\"", + "cross_reference": false, + "print_link_map": false, + "use_newlib_nano": true, + "use_float_with_nano_printf": false, + "use_float_with_nano_scanf": false, + "do_not_use_syscalls": true, + "verbose": false, + "use_wch_printffloat": false, + "use_wch_printf": false, + "use_iqmath": false, + "other_linker_flags": "" + } + }, + "cpplinker": { + "general": { + "scriptFiles": [ + "${project}/Ld/Link.ld" + ], + "do_not_use_standard_start_files": true, + "do_not_use_default_libraries": false, + "no_startup_or_default_libs": false, + "remove_unused_sections": true, + "print_removed_sections": false, + "omit_all_symbol_information": false + }, + "libraries": { + "libraries": [ + "IQmath_RV32" + ], + "library_search_path": [ + "${project}/User" + ] + }, + "miscellaneous": { + "picolibc": "disabled", + "linker_flags": [], + "other_objects": [ + "${project}/User/libM12023_SV_1.0_COMCoreV1.5_Library.a", + "${project}/User/IQmath_RV32.a" + ], + "generate_map": "\"${BuildArtifactFileBaseName}.map\"", + "cross_reference": false, + "print_link_map": false, + "use_newlib_nano": true, + "use_float_with_nano_printf": false, + "use_float_with_nano_scanf": false, + "do_not_use_syscalls": true, + "verbose": false, + "use_wch_printffloat": false, + "use_wch_printf": false, + "use_iqmath": false, + "other_linker_flags": "" + } + }, + "archiver": { + "archiver_flags": "-r", + "libOutputPrefix": "lib" + }, + "createFlash": { + "enabled": true, + "outputFileFormat": "ihex", + "copy_only_section_text": false, + "copy_only_section_data": false, + "copy_only_sections": [], + "create_algorithm_file": false, + "other_flags": "" + }, + "createList": { + "enabled": true, + "display_source": false, + "display_all_headers": true, + "demangle_names": true, + "display_debug_info": false, + "disassemble": true, + "display_file_headers": false, + "display_line_numbers": false, + "display_relocation_info": false, + "display_symbols": false, + "wide_lines": false, + "other_flags": "" + }, + "printSize": { + "enabled": true, + "size_format": "berkeley", + "hex": false, + "show_totals": false, + "other_flags": "" + }, + "configVariables": [], + "riscvTargetProcessor": { + "architecture": "rv32i", + "multiply_extension": true, + "atomic_extension": true, + "floating_point": "none", + "compressed_extension": true, + "extra_compressed_extension": true, + "bit_extension": false, + "multiplication_subset_of_the_M_extension": false, + "vector_cryptography_extensions": "", + "integer_ABI": "ilp32", + "floating_point_ABI": "none", + "tuning": "default", + "code_model": "default", + "small_data_limit": 8, + "align": "default", + "save_restore": true, + "other_target_flags": "" + }, + "component_toolchain": "${WCH:Toolchain:GCC15}", + "name": "obj" + } + ] + }, + "flashConfig": { + "mcutype": "CH32V20x", + "address": "0x08000000", + "target_path": "obj/Electric_Hair_Dryer.hex", + "clkSpeed": "High", + "debug_interface_mode": "", + "erase": true, + "program": true, + "verify": true, + "reset": true, + "sdiPrintf": false, + "disablepowerout": false, + "clearcodeflash": false, + "disablecodeprotect": false, + "flashType": "", + "asmFile_path": "", + "exepath": "", + "exearguments": "" + }, + "debugConfigurations": { + "openOCDCfg": { + "useLocalOpenOCD": true, + "executable": "${WCH:OpenOCD:default}", + "gdbport": 3333, + "telnetport": 4444, + "tclport": 6666, + "configOptions": [ + "-f \"${WCH:OpenOCD:default}/bin/wch-riscv.cfg\"" + ], + "host": "127.0.0.1", + "port": 3333, + "skipDownloadBeforeDebug": false, + "enablePageEraser": false, + "enableNoZeroWaitingAreaFlash": false + }, + "gdbCfg": { + "executable": "${WCH:Toolchain:GCC15}", + "options": [], + "commands": [ + "set mem inaccessible-by-default off", + "set architecture riscv:rv32", + "set remotetimeout unlimited", + "set disassembler-options xw" + ] + }, + "startup": { + "initCommands": { + "initReset": true, + "initResetType": "init", + "additionalCommands": [], + "armSemihosting": false, + "armSemihosting_old": false + }, + "loadedFiles": { + "loadSymbols": true, + "useProjBinaryForSymbols": true, + "useFileForSymbols": false, + "symbolFile": "", + "symbolFileOffset": "", + "loadImage": true, + "useProjBinaryForImage": true, + "useFileForImage": false, + "executableFile": "", + "executableFileOffset": "" + }, + "runCommands": { + "runReset": true, + "runResetType": "halt", + "additionalCommands": [], + "setBreakAt": "handle_reset", + "continue": true, + "setBreak": true, + "setProgramCounter": false, + "setProgramCounterAddress": "" + }, + "debugInRAM": false + }, + "svdpath": "${WCH:SDK:default}/RISC-V/CH32V203/NoneOS/CH32V203xx.svd", + "output": { + "showDebugGDBTrace": true, + "saveDebugOutputToFile": false, + "showDebugOutputTimestamps": true + }, + "reserve": { + "PROGRAM_NAME": "obj/Electric_Hair_Dryer.elf", + "PROJECT_ATTR": "Electric_Hair_Dryer", + "PROJECT_BUILD_CONFIG_AUTO_ATTR": true, + "PROJECT_BUILD_CONFIG_ID_ATTR": "", + "ATTR_BUILD_BEFORE_LAUNCH_ATTR": 2, + "GdbServerAllocateConsole": true, + "GdbServerAllocateTelnetConsole": false, + "StartGdbCLient": true, + "UPDATE_THREADLIST_ON_SUSPEND": false + } + } +} \ No newline at end of file diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/IQmath_RV32.h b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/IQmath_RV32.h new file mode 100644 index 0000000..ef661fc --- /dev/null +++ b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/IQmath_RV32.h @@ -0,0 +1,5052 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : IQmath_RV32.h + * Author : WCH + * Version : V1.0.0 + * Date : 2026/04/23 + * Description : Provide a set of fast MATH functions for RISC-V core MCUs that do not support hardware floating-point +********************************************************************************* +* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ + +#ifndef __IQMATH_RV_H__ +#define __IQMATH_RV_H__ + +#define IQMATH_RV_VER 0x10 + +#ifdef __cplusplus +extern "C" +{ +#endif +/* ********************************************************************************************************************* */ + +#define FLOAT_MATH 1 +#define IQ_MATH 0 + + +#ifndef MATH_TYPE +#define MATH_TYPE IQ_MATH +#endif + +#ifndef GLOBAL_Q +#define GLOBAL_Q 24 +#endif + +//#define DIV_FAST 0 +#define DIV_FAST 1 + +#if MATH_TYPE == FLOAT_MATH +#include +#include +#endif +#include + +#define Q30 30 +#define Q29 29 +#define Q28 28 +#define Q27 27 +#define Q26 26 +#define Q25 25 +#define Q24 24 +#define Q23 23 +#define Q22 22 +#define Q21 21 +#define Q20 20 +#define Q19 19 +#define Q18 18 +#define Q17 17 +#define Q16 16 +#define Q15 15 +#define Q14 14 +#define Q13 13 +#define Q12 12 +#define Q11 11 +#define Q10 10 +#define Q9 9 +#define Q8 8 +#define Q7 7 +#define Q6 6 +#define Q5 5 +#define Q4 4 +#define Q3 3 +#define Q2 2 +#define Q1 1 +#define QG GLOBAL_Q + +#define MAX_IQ_POS LONG_MAX +#define MAX_IQ_NEG LONG_MIN +#define MIN_IQ_POS 1 +#define MIN_IQ_NEG -1 + +#if MATH_TYPE == IQ_MATH + +typedef long _iq30; +typedef long _iq29; +typedef long _iq28; +typedef long _iq27; +typedef long _iq26; +typedef long _iq25; +typedef long _iq24; +typedef long _iq23; +typedef long _iq22; +typedef long _iq21; +typedef long _iq20; +typedef long _iq19; +typedef long _iq18; +typedef long _iq17; +typedef long _iq16; +typedef long _iq15; +typedef long _iq14; +typedef long _iq13; +typedef long _iq12; +typedef long _iq11; +typedef long _iq10; +typedef long _iq9; +typedef long _iq8; +typedef long _iq7; +typedef long _iq6; +typedef long _iq5; +typedef long _iq4; +typedef long _iq3; +typedef long _iq2; +typedef long _iq1; +typedef long _iq; + +/* 各种IQ格式的数乘以2的倍数 */ +#define _IQmpy2(A) ((A) << 1) +#define _IQmpy4(A) ((A) << 2) +#define _IQmpy8(A) ((A) << 3) +#define _IQmpy16(A) ((A) << 4) +#define _IQmpy32(A) ((A) << 5) +#define _IQmpy64(A) ((A) << 6) +#define _IQmpy128(A) ((A) << 7) +#define _IQmpy256(A) ((A) << 8) +#define _IQmpy512(A) ((A) << 9) +#define _IQdiv2(A) ((A) >> 1) +#define _IQdiv4(A) ((A) >> 2) +#define _IQdiv8(A) ((A) >> 3) +#define _IQdiv16(A) ((A) >> 4) +#define _IQdiv32(A) ((A) >> 5) +#define _IQdiv64(A) ((A) >> 6) +#define _IQdiv128(A) ((A) >> 7) +#define _IQdiv256(A) ((A) >> 8) +#define _IQdiv512(A) ((A) >> 9) + +/* 将浮点数转换成各种IQ格式的数 */ +#define _IQ30(A) ((_iq30)((A) * (1 << 30))) +#define _IQ29(A) ((_iq29)((A) * (1 << 29))) +#define _IQ28(A) ((_iq28)((A) * (1 << 28))) +#define _IQ27(A) ((_iq27)((A) * (1 << 27))) +#define _IQ26(A) ((_iq26)((A) * (1 << 26))) +#define _IQ25(A) ((_iq25)((A) * (1 << 25))) +#define _IQ24(A) ((_iq24)((A) * (1 << 24))) +#define _IQ23(A) ((_iq23)((A) * (1 << 23))) +#define _IQ22(A) ((_iq22)((A) * (1 << 22))) +#define _IQ21(A) ((_iq21)((A) * (1 << 21))) +#define _IQ20(A) ((_iq20)((A) * (1 << 20))) +#define _IQ19(A) ((_iq19)((A) * (1 << 19))) +#define _IQ18(A) ((_iq18)((A) * (1 << 18))) +#define _IQ17(A) ((_iq17)((A) * (1 << 17))) +#define _IQ16(A) ((_iq16)((A) * (1 << 16))) +#define _IQ15(A) ((_iq15)((A) * (1 << 15))) +#define _IQ14(A) ((_iq14)((A) * (1 << 14))) +#define _IQ13(A) ((_iq13)((A) * (1 << 13))) +#define _IQ12(A) ((_iq12)((A) * (1 << 12))) +#define _IQ11(A) ((_iq11)((A) * (1 << 11))) +#define _IQ10(A) ((_iq10)((A) * (1 << 10))) +#define _IQ9(A) ((_iq9)((A) * (1 << 9))) +#define _IQ8(A) ((_iq8)((A) * (1 << 8))) +#define _IQ7(A) ((_iq7)((A) * (1 << 7))) +#define _IQ6(A) ((_iq6)((A) * (1 << 6))) +#define _IQ5(A) ((_iq5)((A) * (1 << 5))) +#define _IQ4(A) ((_iq4)((A) * (1 << 4))) +#define _IQ3(A) ((_iq3)((A) * (1 << 3))) +#define _IQ2(A) ((_iq2)((A) * (1 << 2))) +#define _IQ1(A) ((_iq1)((A) * (1 << 1))) + +/******************************************************************************* +* Function Name : _IQ +* Description : 将浮点数转换成IQ格式数 +* Input : float类型数值 +* Return : 返回转换后的IQ格式数,与GLOBAL_Q指定的IQ格式相同 +*******************************************************************************/ +#if GLOBAL_Q == 30 +#define _IQ(A) _IQ30(A) +#endif +#if GLOBAL_Q == 29 +#define _IQ(A) _IQ29(A) +#endif +#if GLOBAL_Q == 28 +#define _IQ(A) _IQ28(A) +#endif +#if GLOBAL_Q == 27 +#define _IQ(A) _IQ27(A) +#endif +#if GLOBAL_Q == 26 +#define _IQ(A) _IQ26(A) +#endif +#if GLOBAL_Q == 25 +#define _IQ(A) _IQ25(A) +#endif +#if GLOBAL_Q == 24 +#define _IQ(A) _IQ24(A) +#endif +#if GLOBAL_Q == 23 +#define _IQ(A) _IQ23(A) +#endif +#if GLOBAL_Q == 22 +#define _IQ(A) _IQ22(A) +#endif +#if GLOBAL_Q == 21 +#define _IQ(A) _IQ21(A) +#endif +#if GLOBAL_Q == 20 +#define _IQ(A) _IQ20(A) +#endif +#if GLOBAL_Q == 19 +#define _IQ(A) _IQ19(A) +#endif +#if GLOBAL_Q == 18 +#define _IQ(A) _IQ18(A) +#endif +#if GLOBAL_Q == 17 +#define _IQ(A) _IQ17(A) +#endif +#if GLOBAL_Q == 16 +#define _IQ(A) _IQ16(A) +#endif +#if GLOBAL_Q == 15 +#define _IQ(A) _IQ15(A) +#endif +#if GLOBAL_Q == 14 +#define _IQ(A) _IQ14(A) +#endif +#if GLOBAL_Q == 13 +#define _IQ(A) _IQ13(A) +#endif +#if GLOBAL_Q == 12 +#define _IQ(A) _IQ12(A) +#endif +#if GLOBAL_Q == 11 +#define _IQ(A) _IQ11(A) +#endif +#if GLOBAL_Q == 10 +#define _IQ(A) _IQ10(A) +#endif +#if GLOBAL_Q == 9 +#define _IQ(A) _IQ9(A) +#endif +#if GLOBAL_Q == 8 +#define _IQ(A) _IQ8(A) +#endif +#if GLOBAL_Q == 7 +#define _IQ(A) _IQ7(A) +#endif +#if GLOBAL_Q == 6 +#define _IQ(A) _IQ6(A) +#endif +#if GLOBAL_Q == 5 +#define _IQ(A) _IQ5(A) +#endif +#if GLOBAL_Q == 4 +#define _IQ(A) _IQ4(A) +#endif +#if GLOBAL_Q == 3 +#define _IQ(A) _IQ3(A) +#endif +#if GLOBAL_Q == 2 +#define _IQ(A) _IQ2(A) +#endif +#if GLOBAL_Q == 1 +#define _IQ(A) _IQ1(A) +#endif + + +/******************************************************************************* +* Function Name : _IQMathVerStr +* Description : IQMath版本信息与编译时间的字符串 +* Input : 无 +* Return : 返回IQMath版本信息与编译时间的字符串 +*******************************************************************************/ +extern char * _IQMathVerStr(void); + +extern float _IQ30toF(_iq30 A); +extern float _IQ29toF(_iq29 A); +extern float _IQ28toF(_iq28 A); +extern float _IQ27toF(_iq27 A); +extern float _IQ26toF(_iq26 A); +extern float _IQ25toF(_iq25 A); +extern float _IQ24toF(_iq24 A); +extern float _IQ23toF(_iq23 A); +extern float _IQ22toF(_iq22 A); +extern float _IQ21toF(_iq21 A); +extern float _IQ20toF(_iq20 A); +extern float _IQ19toF(_iq19 A); +extern float _IQ18toF(_iq18 A); +extern float _IQ17toF(_iq17 A); +extern float _IQ16toF(_iq16 A); +extern float _IQ15toF(_iq15 A); +extern float _IQ14toF(_iq14 A); +extern float _IQ13toF(_iq13 A); +extern float _IQ12toF(_iq12 A); +extern float _IQ11toF(_iq11 A); +extern float _IQ10toF(_iq10 A); +extern float _IQ9toF(_iq9 A); +extern float _IQ8toF(_iq8 A); +extern float _IQ7toF(_iq7 A); +extern float _IQ6toF(_iq6 A); +extern float _IQ5toF(_iq5 A); +extern float _IQ4toF(_iq4 A); +extern float _IQ3toF(_iq3 A); +extern float _IQ2toF(_iq2 A); +extern float _IQ1toF(_iq1 A); + +/******************************************************************************* +* Function Name : _IQtoF +* Description : 将IQ格式的数转换成单精度浮点数 +* Input : IQ类型数据 +* Return : 转换后的float类型的数据 +*******************************************************************************/ +#if GLOBAL_Q == 30 +#define _IQtoF(A) _IQ30toF(A) +#endif +#if GLOBAL_Q == 29 +#define _IQtoF(A) _IQ29toF(A) +#endif +#if GLOBAL_Q == 28 +#define _IQtoF(A) _IQ28toF(A) +#endif +#if GLOBAL_Q == 27 +#define _IQtoF(A) _IQ27toF(A) +#endif +#if GLOBAL_Q == 26 +#define _IQtoF(A) _IQ26toF(A) +#endif +#if GLOBAL_Q == 25 +#define _IQtoF(A) _IQ25toF(A) +#endif +#if GLOBAL_Q == 24 +#define _IQtoF(A) _IQ24toF(A) +#endif +#if GLOBAL_Q == 23 +#define _IQtoF(A) _IQ23toF(A) +#endif +#if GLOBAL_Q == 22 +#define _IQtoF(A) _IQ22toF(A) +#endif +#if GLOBAL_Q == 21 +#define _IQtoF(A) _IQ21toF(A) +#endif +#if GLOBAL_Q == 20 +#define _IQtoF(A) _IQ20toF(A) +#endif +#if GLOBAL_Q == 19 +#define _IQtoF(A) _IQ19toF(A) +#endif +#if GLOBAL_Q == 18 +#define _IQtoF(A) _IQ18toF(A) +#endif +#if GLOBAL_Q == 17 +#define _IQtoF(A) _IQ17toF(A) +#endif +#if GLOBAL_Q == 16 +#define _IQtoF(A) _IQ16toF(A) +#endif +#if GLOBAL_Q == 15 +#define _IQtoF(A) _IQ15toF(A) +#endif +#if GLOBAL_Q == 14 +#define _IQtoF(A) _IQ14toF(A) +#endif +#if GLOBAL_Q == 13 +#define _IQtoF(A) _IQ13toF(A) +#endif +#if GLOBAL_Q == 12 +#define _IQtoF(A) _IQ12toF(A) +#endif +#if GLOBAL_Q == 11 +#define _IQtoF(A) _IQ11toF(A) +#endif +#if GLOBAL_Q == 10 +#define _IQtoF(A) _IQ10toF(A) +#endif +#if GLOBAL_Q == 9 +#define _IQtoF(A) _IQ9toF(A) +#endif +#if GLOBAL_Q == 8 +#define _IQtoF(A) _IQ8toF(A) +#endif +#if GLOBAL_Q == 7 +#define _IQtoF(A) _IQ7toF(A) +#endif +#if GLOBAL_Q == 6 +#define _IQtoF(A) _IQ6toF(A) +#endif +#if GLOBAL_Q == 5 +#define _IQtoF(A) _IQ5toF(A) +#endif +#if GLOBAL_Q == 4 +#define _IQtoF(A) _IQ4toF(A) +#endif +#if GLOBAL_Q == 3 +#define _IQtoF(A) _IQ3toF(A) +#endif +#if GLOBAL_Q == 2 +#define _IQtoF(A) _IQ2toF(A) +#endif +#if GLOBAL_Q == 1 +#define _IQtoF(A) _IQ1toF(A) +#endif + + +extern double _IQ30toD(_iq30 A); +extern double _IQ29toD(_iq29 A); +extern double _IQ28toD(_iq28 A); +extern double _IQ27toD(_iq27 A); +extern double _IQ26toD(_iq26 A); +extern double _IQ25toD(_iq25 A); +extern double _IQ24toD(_iq24 A); +extern double _IQ23toD(_iq23 A); +extern double _IQ22toD(_iq22 A); +extern double _IQ21toD(_iq21 A); +extern double _IQ20toD(_iq20 A); +extern double _IQ19toD(_iq19 A); +extern double _IQ18toD(_iq18 A); +extern double _IQ17toD(_iq17 A); +extern double _IQ16toD(_iq16 A); +extern double _IQ15toD(_iq15 A); +extern double _IQ14toD(_iq14 A); +extern double _IQ13toD(_iq13 A); +extern double _IQ12toD(_iq12 A); +extern double _IQ11toD(_iq11 A); +extern double _IQ10toD(_iq10 A); +extern double _IQ9toD(_iq9 A); +extern double _IQ8toD(_iq8 A); +extern double _IQ7toD(_iq7 A); +extern double _IQ6toD(_iq6 A); +extern double _IQ5toD(_iq5 A); +extern double _IQ4toD(_iq4 A); +extern double _IQ3toD(_iq3 A); +extern double _IQ2toD(_iq2 A); +extern double _IQ1toD(_iq1 A); + +/******************************************************************************* +* Function Name : _IQtoD +* Description : 将IQ格式的数转换成双精度浮点数 +* Input : IQ类型数据 +* Return : 转换后的double类型的数据 +*******************************************************************************/ +#if GLOBAL_Q == 30 +#define _IQtoD(A) _IQ30toD(A) +#endif +#if GLOBAL_Q == 29 +#define _IQtoD(A) _IQ29toD(A) +#endif +#if GLOBAL_Q == 28 +#define _IQtoD(A) _IQ28toD(A) +#endif +#if GLOBAL_Q == 27 +#define _IQtoD(A) _IQ27toD(A) +#endif +#if GLOBAL_Q == 26 +#define _IQtoD(A) _IQ26toD(A) +#endif +#if GLOBAL_Q == 25 +#define _IQtoD(A) _IQ25toD(A) +#endif +#if GLOBAL_Q == 24 +#define _IQtoD(A) _IQ24toD(A) +#endif +#if GLOBAL_Q == 23 +#define _IQtoD(A) _IQ23toD(A) +#endif +#if GLOBAL_Q == 22 +#define _IQtoD(A) _IQ22toD(A) +#endif +#if GLOBAL_Q == 21 +#define _IQtoD(A) _IQ21toD(A) +#endif +#if GLOBAL_Q == 20 +#define _IQtoD(A) _IQ20toD(A) +#endif +#if GLOBAL_Q == 19 +#define _IQtoD(A) _IQ19toD(A) +#endif +#if GLOBAL_Q == 18 +#define _IQtoD(A) _IQ18toD(A) +#endif +#if GLOBAL_Q == 17 +#define _IQtoD(A) _IQ17toD(A) +#endif +#if GLOBAL_Q == 16 +#define _IQtoD(A) _IQ16toD(A) +#endif +#if GLOBAL_Q == 15 +#define _IQtoD(A) _IQ15toD(A) +#endif +#if GLOBAL_Q == 14 +#define _IQtoD(A) _IQ14toD(A) +#endif +#if GLOBAL_Q == 13 +#define _IQtoD(A) _IQ13toD(A) +#endif +#if GLOBAL_Q == 12 +#define _IQtoD(A) _IQ12toD(A) +#endif +#if GLOBAL_Q == 11 +#define _IQtoD(A) _IQ11toD(A) +#endif +#if GLOBAL_Q == 10 +#define _IQtoD(A) _IQ10toD(A) +#endif +#if GLOBAL_Q == 9 +#define _IQtoD(A) _IQ9toD(A) +#endif +#if GLOBAL_Q == 8 +#define _IQtoD(A) _IQ8toD(A) +#endif +#if GLOBAL_Q == 7 +#define _IQtoD(A) _IQ7toD(A) +#endif +#if GLOBAL_Q == 6 +#define _IQtoD(A) _IQ6toD(A) +#endif +#if GLOBAL_Q == 5 +#define _IQtoD(A) _IQ5toD(A) +#endif +#if GLOBAL_Q == 4 +#define _IQtoD(A) _IQ4toD(A) +#endif +#if GLOBAL_Q == 3 +#define _IQtoD(A) _IQ3toD(A) +#endif +#if GLOBAL_Q == 2 +#define _IQtoD(A) _IQ2toD(A) +#endif +#if GLOBAL_Q == 1 +#define _IQtoD(A) _IQ1toD(A) +#endif + + +#define _IQsat(A, Pos, Neg) (((A) > (Pos)) ? \ + (Pos) : \ + (((A) < (Neg)) ? (Neg) : (A))) + +/* GLOBAL_Q指定的IQ精度的数与指定IQ精度数之间相互转换函数 */ +#define _IQtoIQ30(A) ((_iq30)(A) << (30 - GLOBAL_Q)) +#define _IQ30toIQ(A) ((_iq30)(A) >> (30 - GLOBAL_Q)) + +#if (GLOBAL_Q >= 29) +#define _IQtoIQ29(A) ((_iq29)(A) >> (GLOBAL_Q - 29)) +#define _IQ29toIQ(A) ((_iq29)(A) << (GLOBAL_Q - 29)) +#else +#define _IQtoIQ29(A) ((_iq29)(A) << (29 - GLOBAL_Q)) +#define _IQ29toIQ(A) ((_iq29)(A) >> (29 - GLOBAL_Q)) +#endif + +#if (GLOBAL_Q >= 28) +#define _IQtoIQ28(A) ((_iq28)(A) >> (GLOBAL_Q - 28)) +#define _IQ28toIQ(A) ((_iq28)(A) << (GLOBAL_Q - 28)) +#else +#define _IQtoIQ28(A) ((_iq28)(A) << (28 - GLOBAL_Q)) +#define _IQ28toIQ(A) ((_iq28)(A) >> (28 - GLOBAL_Q)) +#endif + +#if (GLOBAL_Q >= 27) +#define _IQtoIQ27(A) ((_iq27)(A) >> (GLOBAL_Q - 27)) +#define _IQ27toIQ(A) ((_iq27)(A) << (GLOBAL_Q - 27)) +#else +#define _IQtoIQ27(A) ((_iq27)(A) << (27 - GLOBAL_Q)) +#define _IQ27toIQ(A) ((_iq27)(A) >> (27 - GLOBAL_Q)) +#endif + +#if (GLOBAL_Q >= 26) +#define _IQtoIQ26(A) ((_iq26)(A) >> (GLOBAL_Q - 26)) +#define _IQ26toIQ(A) ((_iq26)(A) << (GLOBAL_Q - 26)) +#else +#define _IQtoIQ26(A) ((_iq26)(A) << (26 - GLOBAL_Q)) +#define _IQ26toIQ(A) ((_iq26)(A) >> (26 - GLOBAL_Q)) +#endif + +#if (GLOBAL_Q >= 25) +#define _IQtoIQ25(A) ((_iq25)(A) >> (GLOBAL_Q - 25)) +#define _IQ25toIQ(A) ((_iq25)(A) << (GLOBAL_Q - 25)) +#else +#define _IQtoIQ25(A) ((_iq25)(A) << (25 - GLOBAL_Q)) +#define _IQ25toIQ(A) ((_iq25)(A) >> (25 - GLOBAL_Q)) +#endif + +#if (GLOBAL_Q >= 24) +#define _IQtoIQ24(A) ((_iq24)(A) >> (GLOBAL_Q - 24)) +#define _IQ24toIQ(A) ((_iq24)(A) << (GLOBAL_Q - 24)) +#else +#define _IQtoIQ24(A) ((_iq24)(A) << (24 - GLOBAL_Q)) +#define _IQ24toIQ(A) ((_iq24)(A) >> (24 - GLOBAL_Q)) +#endif + +#if (GLOBAL_Q >= 23) +#define _IQtoIQ23(A) ((_iq23)(A) >> (GLOBAL_Q - 23)) +#define _IQ23toIQ(A) ((_iq23)(A) << (GLOBAL_Q - 23)) +#else +#define _IQtoIQ23(A) ((_iq23)(A) << (23 - GLOBAL_Q)) +#define _IQ23toIQ(A) ((_iq23)(A) >> (23 - GLOBAL_Q)) +#endif + +#if (GLOBAL_Q >= 22) +#define _IQtoIQ22(A) ((_iq22)(A) >> (GLOBAL_Q - 22)) +#define _IQ22toIQ(A) ((_iq22)(A) << (GLOBAL_Q - 22)) +#else +#define _IQtoIQ22(A) ((_iq22)(A) << (22 - GLOBAL_Q)) +#define _IQ22toIQ(A) ((_iq22)(A) >> (22 - GLOBAL_Q)) +#endif + +#if (GLOBAL_Q >= 21) +#define _IQtoIQ21(A) ((_iq21)(A) >> (GLOBAL_Q - 21)) +#define _IQ21toIQ(A) ((_iq21)(A) << (GLOBAL_Q - 21)) +#else +#define _IQtoIQ21(A) ((_iq21)(A) << (21 - GLOBAL_Q)) +#define _IQ21toIQ(A) ((_iq21)(A) >> (21 - GLOBAL_Q)) +#endif + +#if (GLOBAL_Q >= 20) +#define _IQtoIQ20(A) ((_iq20)(A) >> (GLOBAL_Q - 20)) +#define _IQ20toIQ(A) ((_iq20)(A) << (GLOBAL_Q - 20)) +#else +#define _IQtoIQ20(A) ((_iq20)(A) << (20 - GLOBAL_Q)) +#define _IQ20toIQ(A) ((_iq20)(A) >> (20 - GLOBAL_Q)) +#endif + +#if (GLOBAL_Q >= 19) +#define _IQtoIQ19(A) ((_iq19)(A) >> (GLOBAL_Q - 19)) +#define _IQ19toIQ(A) ((_iq19)(A) << (GLOBAL_Q - 19)) +#else +#define _IQtoIQ19(A) ((_iq19)(A) << (19 - GLOBAL_Q)) +#define _IQ19toIQ(A) ((_iq19)(A) >> (19 - GLOBAL_Q)) +#endif + +#if (GLOBAL_Q >= 18) +#define _IQtoIQ18(A) ((_iq18)(A) >> (GLOBAL_Q - 18)) +#define _IQ18toIQ(A) ((_iq18)(A) << (GLOBAL_Q - 18)) +#else +#define _IQtoIQ18(A) ((_iq18)(A) << (18 - GLOBAL_Q)) +#define _IQ18toIQ(A) ((_iq18)(A) >> (18 - GLOBAL_Q)) +#endif + +#if (GLOBAL_Q >= 17) +#define _IQtoIQ17(A) ((_iq17)(A) >> (GLOBAL_Q - 17)) +#define _IQ17toIQ(A) ((_iq17)(A) << (GLOBAL_Q - 17)) +#else +#define _IQtoIQ17(A) ((_iq17)(A) << (17 - GLOBAL_Q)) +#define _IQ17toIQ(A) ((_iq17)(A) >> (17 - GLOBAL_Q)) +#endif + +#if (GLOBAL_Q >= 16) +#define _IQtoIQ16(A) ((_iq16)(A) >> (GLOBAL_Q - 16)) +#define _IQ16toIQ(A) ((_iq16)(A) << (GLOBAL_Q - 16)) +#else +#define _IQtoIQ16(A) ((_iq16)(A) << (16 - GLOBAL_Q)) +#define _IQ16toIQ(A) ((_iq16)(A) >> (16 - GLOBAL_Q)) +#endif + +#if (GLOBAL_Q >= 15) +#define _IQtoIQ15(A) ((_iq15)(A) >> (GLOBAL_Q - 15)) +#define _IQ15toIQ(A) ((_iq15)(A) << (GLOBAL_Q - 15)) +#else +#define _IQtoIQ15(A) ((_iq15)(A) << (15 - GLOBAL_Q)) +#define _IQ15toIQ(A) ((_iq15)(A) >> (15 - GLOBAL_Q)) +#endif + +#if (GLOBAL_Q >= 14) +#define _IQtoIQ14(A) ((_iq14)(A) >> (GLOBAL_Q - 14)) +#define _IQ14toIQ(A) ((_iq14)(A) << (GLOBAL_Q - 14)) +#else +#define _IQtoIQ14(A) ((_iq14)(A) << (14 - GLOBAL_Q)) +#define _IQ14toIQ(A) ((_iq14)(A) >> (14 - GLOBAL_Q)) +#endif + +#if (GLOBAL_Q >= 13) +#define _IQtoIQ13(A) ((_iq13)(A) >> (GLOBAL_Q - 13)) +#define _IQ13toIQ(A) ((_iq13)(A) << (GLOBAL_Q - 13)) +#else +#define _IQtoIQ13(A) ((_iq13)(A) << (13 - GLOBAL_Q)) +#define _IQ13toIQ(A) ((_iq13)(A) >> (13 - GLOBAL_Q)) +#endif + +#if (GLOBAL_Q >= 12) +#define _IQtoIQ12(A) ((_iq12)(A) >> (GLOBAL_Q - 12)) +#define _IQ12toIQ(A) ((_iq12)(A) << (GLOBAL_Q - 12)) +#else +#define _IQtoIQ12(A) ((_iq12)(A) << (12 - GLOBAL_Q)) +#define _IQ12toIQ(A) ((_iq12)(A) >> (12 - GLOBAL_Q)) +#endif + +#if (GLOBAL_Q >= 11) +#define _IQtoIQ11(A) ((_iq11)(A) >> (GLOBAL_Q - 11)) +#define _IQ11toIQ(A) ((_iq11)(A) << (GLOBAL_Q - 11)) +#else +#define _IQtoIQ11(A) ((_iq11)(A) << (11 - GLOBAL_Q)) +#define _IQ11toIQ(A) ((_iq11)(A) >> (11 - GLOBAL_Q)) +#endif + +#if (GLOBAL_Q >= 10) +#define _IQtoIQ10(A) ((_iq10)(A) >> (GLOBAL_Q - 10)) +#define _IQ10toIQ(A) ((_iq10)(A) << (GLOBAL_Q - 10)) +#else +#define _IQtoIQ10(A) ((_iq10)(A) << (10 - GLOBAL_Q)) +#define _IQ10toIQ(A) ((_iq10)(A) >> (10 - GLOBAL_Q)) +#endif + +#if (GLOBAL_Q >= 9) +#define _IQtoIQ9(A) ((_iq9)(A) >> (GLOBAL_Q - 9)) +#define _IQ9toIQ(A) ((_iq9)(A) << (GLOBAL_Q - 9)) +#else +#define _IQtoIQ9(A) ((_iq9)(A) << (9 - GLOBAL_Q)) +#define _IQ9toIQ(A) ((_iq9)(A) >> (9 - GLOBAL_Q)) +#endif + +#if (GLOBAL_Q >= 8) +#define _IQtoIQ8(A) ((_iq8)(A) >> (GLOBAL_Q - 8)) +#define _IQ8toIQ(A) ((_iq8)(A) << (GLOBAL_Q - 8)) +#else +#define _IQtoIQ8(A) ((_iq8)(A) << (8 - GLOBAL_Q)) +#define _IQ8toIQ(A) ((_iq8)(A) >> (8 - GLOBAL_Q)) +#endif + +#if (GLOBAL_Q >= 7) +#define _IQtoIQ7(A) ((_iq7)(A) >> (GLOBAL_Q - 7)) +#define _IQ7toIQ(A) ((_iq7)(A) << (GLOBAL_Q - 7)) +#else +#define _IQtoIQ7(A) ((_iq7)(A) << (7 - GLOBAL_Q)) +#define _IQ7toIQ(A) ((_iq7)(A) >> (7 - GLOBAL_Q)) +#endif + +#if (GLOBAL_Q >= 6) +#define _IQtoIQ6(A) ((_iq6)(A) >> (GLOBAL_Q - 6)) +#define _IQ6toIQ(A) ((_iq6)(A) << (GLOBAL_Q - 6)) +#else +#define _IQtoIQ6(A) ((_iq6)(A) << (6 - GLOBAL_Q)) +#define _IQ6toIQ(A) ((_iq6)(A) >> (6 - GLOBAL_Q)) +#endif + +#if (GLOBAL_Q >= 5) +#define _IQtoIQ5(A) ((_iq5)(A) >> (GLOBAL_Q - 5)) +#define _IQ5toIQ(A) ((_iq5)(A) << (GLOBAL_Q - 5)) +#else +#define _IQtoIQ5(A) ((_iq5)(A) << (5 - GLOBAL_Q)) +#define _IQ5toIQ(A) ((_iq5)(A) >> (5 - GLOBAL_Q)) +#endif + +#if (GLOBAL_Q >= 4) +#define _IQtoIQ4(A) ((_iq4)(A) >> (GLOBAL_Q - 4)) +#define _IQ4toIQ(A) ((_iq4)(A) << (GLOBAL_Q - 4)) +#else +#define _IQtoIQ4(A) ((_iq4)(A) << (4 - GLOBAL_Q)) +#define _IQ4toIQ(A) ((_iq4)(A) >> (4 - GLOBAL_Q)) +#endif + +#if (GLOBAL_Q >= 3) +#define _IQtoIQ3(A) ((_iq3)(A) >> (GLOBAL_Q - 3)) +#define _IQ3toIQ(A) ((_iq3)(A) << (GLOBAL_Q - 3)) +#else +#define _IQtoIQ3(A) ((_iq3)(A) << (3 - GLOBAL_Q)) +#define _IQ3toIQ(A) ((_iq3)(A) >> (3 - GLOBAL_Q)) +#endif + +#if (GLOBAL_Q >= 2) +#define _IQtoIQ2(A) ((_iq2)(A) >> (GLOBAL_Q - 2)) +#define _IQ2toIQ(A) ((_iq2)(A) << (GLOBAL_Q - 2)) +#else +#define _IQtoIQ2(A) ((_iq2)(A) << (2 - GLOBAL_Q)) +#define _IQ2toIQ(A) ((_iq2)(A) >> (2 - GLOBAL_Q)) +#endif + +#define _IQtoIQ1(A) ((_iq1)(A) >> (GLOBAL_Q - 1)) +#define _IQ1toIQ(A) ((_iq1)(A) << (GLOBAL_Q - 1)) + +#if (GLOBAL_Q >= 15) +#define _IQtoQ15(A) ((long)(A) >> (GLOBAL_Q - 15)) +#define _Q15toIQ(A) ((_iq15)(A) << (GLOBAL_Q - 15)) +#else +#define _IQtoQ15(A) ((long)(A) << (15 - GLOBAL_Q)) +#define _Q15toIQ(A) ((_iq15)(A) >> (15 - GLOBAL_Q)) +#endif + +#if (GLOBAL_Q >= 14) +#define _IQtoQ14(A) ((long)(A) >> (GLOBAL_Q - 14)) +#define _Q14toIQ(A) ((_iq14)(A) << (GLOBAL_Q - 14)) +#else +#define _IQtoQ14(A) ((long)(A) << (14 - GLOBAL_Q)) +#define _Q14toIQ(A) ((_iq14)(A) >> (14 - GLOBAL_Q)) +#endif + +#if (GLOBAL_Q >= 13) +#define _IQtoQ13(A) ((long)(A) >> (GLOBAL_Q - 13)) +#define _Q13toIQ(A) ((_iq13)(A) << (GLOBAL_Q - 13)) +#else +#define _IQtoQ13(A) ((long)(A) << (13 - GLOBAL_Q)) +#define _Q13toIQ(A) ((_iq13)(A) >> (13 - GLOBAL_Q)) +#endif + +#if (GLOBAL_Q >= 12) +#define _IQtoQ12(A) ((long)(A) >> (GLOBAL_Q - 12)) +#define _Q12toIQ(A) ((_iq12)(A) << (GLOBAL_Q - 12)) +#else +#define _IQtoQ12(A) ((long)(A) << (12 - GLOBAL_Q)) +#define _Q12toIQ(A) ((_iq12)(A) >> (12 - GLOBAL_Q)) +#endif + +#if (GLOBAL_Q >= 11) +#define _IQtoQ11(A) ((long)(A) >> (GLOBAL_Q - 11)) +#define _Q11toIQ(A) ((_iq11)(A) << (GLOBAL_Q - 11)) +#else +#define _IQtoQ11(A) ((long)(A) << (11 - GLOBAL_Q)) +#define _Q11toIQ(A) ((_iq11)(A) >> (11 - GLOBAL_Q)) +#endif + +#if (GLOBAL_Q >= 10) +#define _IQtoQ10(A) ((long)(A) >> (GLOBAL_Q - 10)) +#define _Q10toIQ(A) ((_iq10)(A) << (GLOBAL_Q - 10)) +#else +#define _IQtoQ10(A) ((long)(A) << (10 - GLOBAL_Q)) +#define _Q10toIQ(A) ((_iq10)(A) >> (10 - GLOBAL_Q)) +#endif + +#if (GLOBAL_Q >= 9) +#define _IQtoQ9(A) ((long)(A) >> (GLOBAL_Q - 9)) +#define _Q9toIQ(A) ((_iq9)(A) << (GLOBAL_Q - 9)) +#else +#define _IQtoQ9(A) ((long)(A) << (9 - GLOBAL_Q)) +#define _Q9toIQ(A) ((_iq9)(A) >> (9 - GLOBAL_Q)) +#endif + +#if (GLOBAL_Q >= 8) +#define _IQtoQ8(A) ((long)(A) >> (GLOBAL_Q - 8)) +#define _Q8toIQ(A) ((_iq8)(A) << (GLOBAL_Q - 8)) +#else +#define _IQtoQ8(A) ((long)(A) << (8 - GLOBAL_Q)) +#define _Q8toIQ(A) ((_iq8)(A) >> (8 - GLOBAL_Q)) +#endif + +#if (GLOBAL_Q >= 7) +#define _IQtoQ7(A) ((long)(A) >> (GLOBAL_Q - 7)) +#define _Q7toIQ(A) ((_iq7)(A) << (GLOBAL_Q - 7)) +#else +#define _IQtoQ7(A) ((long)(A) << (7 - GLOBAL_Q)) +#define _Q7toIQ(A) ((_iq7)(A) >> (7 - GLOBAL_Q)) +#endif + +#if (GLOBAL_Q >= 6) +#define _IQtoQ6(A) ((long)(A) >> (GLOBAL_Q - 6)) +#define _Q6toIQ(A) ((_iq6)(A) << (GLOBAL_Q - 6)) +#else +#define _IQtoQ6(A) ((long)(A) << (6 - GLOBAL_Q)) +#define _Q6toIQ(A) ((_iq6)(A) >> (6 - GLOBAL_Q)) +#endif + +#if (GLOBAL_Q >= 5) +#define _IQtoQ5(A) ((long)(A) >> (GLOBAL_Q - 5)) +#define _Q5toIQ(A) ((_iq5)(A) << (GLOBAL_Q - 5)) +#else +#define _IQtoQ5(A) ((long)(A) << (5 - GLOBAL_Q)) +#define _Q5toIQ(A) ((_iq5)(A) >> (5 - GLOBAL_Q)) +#endif + +#if (GLOBAL_Q >= 4) +#define _IQtoQ4(A) ((long)(A) >> (GLOBAL_Q - 4)) +#define _Q4toIQ(A) ((_iq4)(A) << (GLOBAL_Q - 4)) +#else +#define _IQtoQ4(A) ((long)(A) << (4 - GLOBAL_Q)) +#define _Q4toIQ(A) ((_iq4)(A) >> (4 - GLOBAL_Q)) +#endif + +#if (GLOBAL_Q >= 3) +#define _IQtoQ3(A) ((long)(A) >> (GLOBAL_Q - 3)) +#define _Q3toIQ(A) ((_iq3)(A) << (GLOBAL_Q - 3)) +#else +#define _IQtoQ3(A) ((long)(A) << (3 - GLOBAL_Q)) +#define _Q3toIQ(A) ((_iq3)(A) >> (3 - GLOBAL_Q)) +#endif + +#if (GLOBAL_Q >= 2) +#define _IQtoQ2(A) ((long)(A) >> (GLOBAL_Q - 2)) +#define _Q2toIQ(A) ((_iq2)(A) << (GLOBAL_Q - 2)) +#else +#define _IQtoQ2(A) ((long)(A) << (2 - GLOBAL_Q)) +#define _Q2toIQ(A) ((_iq2)(A) >> (2 - GLOBAL_Q)) +#endif + +#define _IQtoQ1(A) ((long)(A) >> (GLOBAL_Q - 1)) +#define _Q1toIQ(A) ((_iq1)(A) << (GLOBAL_Q - 1)) + +extern _iq30 _IQ30mpy(_iq30 A, _iq30 B); +extern _iq29 _IQ29mpy(_iq29 A, _iq29 B); +extern _iq28 _IQ28mpy(_iq28 A, _iq28 B); +extern _iq27 _IQ27mpy(_iq27 A, _iq27 B); +extern _iq26 _IQ26mpy(_iq26 A, _iq26 B); +extern _iq25 _IQ25mpy(_iq25 A, _iq25 B); +extern _iq24 _IQ24mpy(_iq24 A, _iq24 B); +extern _iq23 _IQ23mpy(_iq23 A, _iq23 B); +extern _iq22 _IQ22mpy(_iq22 A, _iq22 B); +extern _iq21 _IQ21mpy(_iq21 A, _iq21 B); +extern _iq20 _IQ20mpy(_iq20 A, _iq20 B); +extern _iq19 _IQ19mpy(_iq19 A, _iq19 B); +extern _iq18 _IQ18mpy(_iq18 A, _iq18 B); +extern _iq17 _IQ17mpy(_iq17 A, _iq17 B); +extern _iq16 _IQ16mpy(_iq16 A, _iq16 B); +extern _iq15 _IQ15mpy(_iq15 A, _iq15 B); +extern _iq14 _IQ14mpy(_iq14 A, _iq14 B); +extern _iq13 _IQ13mpy(_iq13 A, _iq13 B); +extern _iq12 _IQ12mpy(_iq12 A, _iq12 B); +extern _iq11 _IQ11mpy(_iq11 A, _iq11 B); +extern _iq10 _IQ10mpy(_iq10 A, _iq10 B); +extern _iq9 _IQ9mpy(_iq9 A, _iq9 B); +extern _iq8 _IQ8mpy(_iq8 A, _iq8 B); +extern _iq7 _IQ7mpy(_iq7 A, _iq7 B); +extern _iq6 _IQ6mpy(_iq6 A, _iq6 B); +extern _iq5 _IQ5mpy(_iq5 A, _iq5 B); +extern _iq4 _IQ4mpy(_iq4 A, _iq4 B); +extern _iq3 _IQ3mpy(_iq3 A, _iq3 B); +extern _iq2 _IQ2mpy(_iq2 A, _iq2 B); +extern _iq1 _IQ1mpy(_iq1 A, _iq1 B); +/******************************************************************************* +* Function Name : _IQmpy +* Description : IQ格式数的乘法运算:A*B +* Input : A、B为两个相同IQ格式的乘数 +* Return : A与B的乘积,与参数的IQ格式相同 +*******************************************************************************/ +#if GLOBAL_Q == 30 +#define _IQmpy(A, B) _IQ30mpy(A, B) +#endif +#if GLOBAL_Q == 29 +#define _IQmpy(A, B) _IQ29mpy(A, B) +#endif +#if GLOBAL_Q == 28 +#define _IQmpy(A, B) _IQ28mpy(A, B) +#endif +#if GLOBAL_Q == 27 +#define _IQmpy(A, B) _IQ27mpy(A, B) +#endif +#if GLOBAL_Q == 26 +#define _IQmpy(A, B) _IQ26mpy(A, B) +#endif +#if GLOBAL_Q == 25 +#define _IQmpy(A, B) _IQ25mpy(A, B) +#endif +#if GLOBAL_Q == 24 +#define _IQmpy(A, B) _IQ24mpy(A, B) +#endif +#if GLOBAL_Q == 23 +#define _IQmpy(A, B) _IQ23mpy(A, B) +#endif +#if GLOBAL_Q == 22 +#define _IQmpy(A, B) _IQ22mpy(A, B) +#endif +#if GLOBAL_Q == 21 +#define _IQmpy(A, B) _IQ21mpy(A, B) +#endif +#if GLOBAL_Q == 20 +#define _IQmpy(A, B) _IQ20mpy(A, B) +#endif +#if GLOBAL_Q == 19 +#define _IQmpy(A, B) _IQ19mpy(A, B) +#endif +#if GLOBAL_Q == 18 +#define _IQmpy(A, B) _IQ18mpy(A, B) +#endif +#if GLOBAL_Q == 17 +#define _IQmpy(A, B) _IQ17mpy(A, B) +#endif +#if GLOBAL_Q == 16 +#define _IQmpy(A, B) _IQ16mpy(A, B) +#endif +#if GLOBAL_Q == 15 +#define _IQmpy(A, B) _IQ15mpy(A, B) +#endif +#if GLOBAL_Q == 14 +#define _IQmpy(A, B) _IQ14mpy(A, B) +#endif +#if GLOBAL_Q == 13 +#define _IQmpy(A, B) _IQ13mpy(A, B) +#endif +#if GLOBAL_Q == 12 +#define _IQmpy(A, B) _IQ12mpy(A, B) +#endif +#if GLOBAL_Q == 11 +#define _IQmpy(A, B) _IQ11mpy(A, B) +#endif +#if GLOBAL_Q == 10 +#define _IQmpy(A, B) _IQ10mpy(A, B) +#endif +#if GLOBAL_Q == 9 +#define _IQmpy(A, B) _IQ9mpy(A, B) +#endif +#if GLOBAL_Q == 8 +#define _IQmpy(A, B) _IQ8mpy(A, B) +#endif +#if GLOBAL_Q == 7 +#define _IQmpy(A, B) _IQ7mpy(A, B) +#endif +#if GLOBAL_Q == 6 +#define _IQmpy(A, B) _IQ6mpy(A, B) +#endif +#if GLOBAL_Q == 5 +#define _IQmpy(A, B) _IQ5mpy(A, B) +#endif +#if GLOBAL_Q == 4 +#define _IQmpy(A, B) _IQ4mpy(A, B) +#endif +#if GLOBAL_Q == 3 +#define _IQmpy(A, B) _IQ3mpy(A, B) +#endif +#if GLOBAL_Q == 2 +#define _IQmpy(A, B) _IQ2mpy(A, B) +#endif +#if GLOBAL_Q == 1 +#define _IQmpy(A, B) _IQ1mpy(A, B) +#endif + + +extern _iq30 _IQ30rmpy(_iq30 A, _iq30 B); +extern _iq29 _IQ29rmpy(_iq29 A, _iq29 B); +extern _iq28 _IQ28rmpy(_iq28 A, _iq28 B); +extern _iq27 _IQ27rmpy(_iq27 A, _iq27 B); +extern _iq26 _IQ26rmpy(_iq26 A, _iq26 B); +extern _iq25 _IQ25rmpy(_iq25 A, _iq25 B); +extern _iq24 _IQ24rmpy(_iq24 A, _iq24 B); +extern _iq23 _IQ23rmpy(_iq23 A, _iq23 B); +extern _iq22 _IQ22rmpy(_iq22 A, _iq22 B); +extern _iq21 _IQ21rmpy(_iq21 A, _iq21 B); +extern _iq20 _IQ20rmpy(_iq20 A, _iq20 B); +extern _iq19 _IQ19rmpy(_iq19 A, _iq19 B); +extern _iq18 _IQ18rmpy(_iq18 A, _iq18 B); +extern _iq17 _IQ17rmpy(_iq17 A, _iq17 B); +extern _iq16 _IQ16rmpy(_iq16 A, _iq16 B); +extern _iq15 _IQ15rmpy(_iq15 A, _iq15 B); +extern _iq14 _IQ14rmpy(_iq14 A, _iq14 B); +extern _iq13 _IQ13rmpy(_iq13 A, _iq13 B); +extern _iq12 _IQ12rmpy(_iq12 A, _iq12 B); +extern _iq11 _IQ11rmpy(_iq11 A, _iq11 B); +extern _iq10 _IQ10rmpy(_iq10 A, _iq10 B); +extern _iq9 _IQ9rmpy(_iq9 A, _iq9 B); +extern _iq8 _IQ8rmpy(_iq8 A, _iq8 B); +extern _iq7 _IQ7rmpy(_iq7 A, _iq7 B); +extern _iq6 _IQ6rmpy(_iq6 A, _iq6 B); +extern _iq5 _IQ5rmpy(_iq5 A, _iq5 B); +extern _iq4 _IQ4rmpy(_iq4 A, _iq4 B); +extern _iq3 _IQ3rmpy(_iq3 A, _iq3 B); +extern _iq2 _IQ2rmpy(_iq2 A, _iq2 B); +extern _iq1 _IQ1rmpy(_iq1 A, _iq1 B); +/******************************************************************************* +* Function Name : _IQrmpy +* Description : IQ格式数的乘法运算,结果4舍5入: A*B +* Input : A、B为两个相同IQ格式的乘数 +* Return : A与B的乘积,与参数的IQ格式相同 +*******************************************************************************/ +#if GLOBAL_Q == 30 +#define _IQrmpy(A, B) _IQ30rmpy(A, B) +#endif +#if GLOBAL_Q == 29 +#define _IQrmpy(A, B) _IQ29rmpy(A, B) +#endif +#if GLOBAL_Q == 28 +#define _IQrmpy(A, B) _IQ28rmpy(A, B) +#endif +#if GLOBAL_Q == 27 +#define _IQrmpy(A, B) _IQ27rmpy(A, B) +#endif +#if GLOBAL_Q == 26 +#define _IQrmpy(A, B) _IQ26rmpy(A, B) +#endif +#if GLOBAL_Q == 25 +#define _IQrmpy(A, B) _IQ25rmpy(A, B) +#endif +#if GLOBAL_Q == 24 +#define _IQrmpy(A, B) _IQ24rmpy(A, B) +#endif +#if GLOBAL_Q == 23 +#define _IQrmpy(A, B) _IQ23rmpy(A, B) +#endif +#if GLOBAL_Q == 22 +#define _IQrmpy(A, B) _IQ22rmpy(A, B) +#endif +#if GLOBAL_Q == 21 +#define _IQrmpy(A, B) _IQ21rmpy(A, B) +#endif +#if GLOBAL_Q == 20 +#define _IQrmpy(A, B) _IQ20rmpy(A, B) +#endif +#if GLOBAL_Q == 19 +#define _IQrmpy(A, B) _IQ19rmpy(A, B) +#endif +#if GLOBAL_Q == 18 +#define _IQrmpy(A, B) _IQ18rmpy(A, B) +#endif +#if GLOBAL_Q == 17 +#define _IQrmpy(A, B) _IQ17rmpy(A, B) +#endif +#if GLOBAL_Q == 16 +#define _IQrmpy(A, B) _IQ16rmpy(A, B) +#endif +#if GLOBAL_Q == 15 +#define _IQrmpy(A, B) _IQ15rmpy(A, B) +#endif +#if GLOBAL_Q == 14 +#define _IQrmpy(A, B) _IQ14rmpy(A, B) +#endif +#if GLOBAL_Q == 13 +#define _IQrmpy(A, B) _IQ13rmpy(A, B) +#endif +#if GLOBAL_Q == 12 +#define _IQrmpy(A, B) _IQ12rmpy(A, B) +#endif +#if GLOBAL_Q == 11 +#define _IQrmpy(A, B) _IQ11rmpy(A, B) +#endif +#if GLOBAL_Q == 10 +#define _IQrmpy(A, B) _IQ10rmpy(A, B) +#endif +#if GLOBAL_Q == 9 +#define _IQrmpy(A, B) _IQ9rmpy(A, B) +#endif +#if GLOBAL_Q == 8 +#define _IQrmpy(A, B) _IQ8rmpy(A, B) +#endif +#if GLOBAL_Q == 7 +#define _IQrmpy(A, B) _IQ7rmpy(A, B) +#endif +#if GLOBAL_Q == 6 +#define _IQrmpy(A, B) _IQ6rmpy(A, B) +#endif +#if GLOBAL_Q == 5 +#define _IQrmpy(A, B) _IQ5rmpy(A, B) +#endif +#if GLOBAL_Q == 4 +#define _IQrmpy(A, B) _IQ4rmpy(A, B) +#endif +#if GLOBAL_Q == 3 +#define _IQrmpy(A, B) _IQ3rmpy(A, B) +#endif +#if GLOBAL_Q == 2 +#define _IQrmpy(A, B) _IQ2rmpy(A, B) +#endif +#if GLOBAL_Q == 1 +#define _IQrmpy(A, B) _IQ1rmpy(A, B) +#endif + + +extern _iq30 _IQ30div(_iq30 A, _iq30 B); +extern _iq29 _IQ29div(_iq29 A, _iq29 B); +extern _iq28 _IQ28div(_iq28 A, _iq28 B); +extern _iq27 _IQ27div(_iq27 A, _iq27 B); +extern _iq26 _IQ26div(_iq26 A, _iq26 B); +extern _iq25 _IQ25div(_iq25 A, _iq25 B); +extern _iq24 _IQ24div(_iq24 A, _iq24 B); +extern _iq23 _IQ23div(_iq23 A, _iq23 B); +extern _iq22 _IQ22div(_iq22 A, _iq22 B); +extern _iq21 _IQ21div(_iq21 A, _iq21 B); +extern _iq20 _IQ20div(_iq20 A, _iq20 B); +extern _iq19 _IQ19div(_iq19 A, _iq19 B); +extern _iq18 _IQ18div(_iq18 A, _iq18 B); +extern _iq17 _IQ17div(_iq17 A, _iq17 B); +extern _iq16 _IQ16div(_iq16 A, _iq16 B); +extern _iq15 _IQ15div(_iq15 A, _iq15 B); +extern _iq14 _IQ14div(_iq14 A, _iq14 B); +extern _iq13 _IQ13div(_iq13 A, _iq13 B); +extern _iq12 _IQ12div(_iq12 A, _iq12 B); +extern _iq11 _IQ11div(_iq11 A, _iq11 B); +extern _iq10 _IQ10div(_iq10 A, _iq10 B); +extern _iq9 _IQ9div(_iq9 A, _iq9 B); +extern _iq8 _IQ8div(_iq8 A, _iq8 B); +extern _iq7 _IQ7div(_iq7 A, _iq7 B); +extern _iq6 _IQ6div(_iq6 A, _iq6 B); +extern _iq5 _IQ5div(_iq5 A, _iq5 B); +extern _iq4 _IQ4div(_iq4 A, _iq4 B); +extern _iq3 _IQ3div(_iq3 A, _iq3 B); +extern _iq2 _IQ2div(_iq2 A, _iq2 B); +extern _iq1 _IQ1div(_iq1 A, _iq1 B); + +/* 快速计算除法 */ +extern _iq30 _IQ30div_FAST(_iq30 A, _iq30 B); +extern _iq29 _IQ29div_FAST(_iq29 A, _iq29 B); +extern _iq28 _IQ28div_FAST(_iq28 A, _iq28 B); +extern _iq27 _IQ27div_FAST(_iq27 A, _iq27 B); +extern _iq26 _IQ26div_FAST(_iq26 A, _iq26 B); +extern _iq25 _IQ25div_FAST(_iq25 A, _iq25 B); +extern _iq24 _IQ24div_FAST(_iq24 A, _iq24 B); +extern _iq23 _IQ23div_FAST(_iq23 A, _iq23 B); +extern _iq22 _IQ22div_FAST(_iq22 A, _iq22 B); +extern _iq21 _IQ21div_FAST(_iq21 A, _iq21 B); +extern _iq20 _IQ20div_FAST(_iq20 A, _iq20 B); +extern _iq19 _IQ19div_FAST(_iq19 A, _iq19 B); +extern _iq18 _IQ18div_FAST(_iq18 A, _iq18 B); +extern _iq17 _IQ17div_FAST(_iq17 A, _iq17 B); +extern _iq16 _IQ16div_FAST(_iq16 A, _iq16 B); +extern _iq15 _IQ15div_FAST(_iq15 A, _iq15 B); +extern _iq14 _IQ14div_FAST(_iq14 A, _iq14 B); +extern _iq13 _IQ13div_FAST(_iq13 A, _iq13 B); +extern _iq12 _IQ12div_FAST(_iq12 A, _iq12 B); +extern _iq11 _IQ11div_FAST(_iq11 A, _iq11 B); +extern _iq10 _IQ10div_FAST(_iq10 A, _iq10 B); +extern _iq9 _IQ9div_FAST(_iq9 A, _iq9 B); +extern _iq8 _IQ8div_FAST(_iq8 A, _iq8 B); +extern _iq7 _IQ7div_FAST(_iq7 A, _iq7 B); +extern _iq6 _IQ6div_FAST(_iq6 A, _iq6 B); +extern _iq5 _IQ5div_FAST(_iq5 A, _iq5 B); +extern _iq4 _IQ4div_FAST(_iq4 A, _iq4 B); +extern _iq3 _IQ3div_FAST(_iq3 A, _iq3 B); +extern _iq2 _IQ2div_FAST(_iq2 A, _iq2 B); +extern _iq1 _IQ1div_FAST(_iq1 A, _iq1 B); + +/******************************************************************************* +* Function Name : _IQdiv +* Description : IQ格式数的除法运算:A/B +* Input : A为被除数,B为除数,A与B为相同IQ格式的数 +* Return : A除以B的商,与参数的IQ格式相同 +*******************************************************************************/ +#if DIV_FAST == 0 +#if GLOBAL_Q == 30 +#define _IQdiv(A, B) _IQ30div(A, B) +#endif +#if GLOBAL_Q == 29 +#define _IQdiv(A, B) _IQ29div(A, B) +#endif +#if GLOBAL_Q == 28 +#define _IQdiv(A, B) _IQ28div(A, B) +#endif +#if GLOBAL_Q == 27 +#define _IQdiv(A, B) _IQ27div(A, B) +#endif +#if GLOBAL_Q == 26 +#define _IQdiv(A, B) _IQ26div(A, B) +#endif +#if GLOBAL_Q == 25 +#define _IQdiv(A, B) _IQ25div(A, B) +#endif +#if GLOBAL_Q == 24 +#define _IQdiv(A, B) _IQ24div(A, B) +#endif +#if GLOBAL_Q == 23 +#define _IQdiv(A, B) _IQ23div(A, B) +#endif +#if GLOBAL_Q == 22 +#define _IQdiv(A, B) _IQ22div(A, B) +#endif +#if GLOBAL_Q == 21 +#define _IQdiv(A, B) _IQ21div(A, B) +#endif +#if GLOBAL_Q == 20 +#define _IQdiv(A, B) _IQ20div(A, B) +#endif +#if GLOBAL_Q == 19 +#define _IQdiv(A, B) _IQ19div(A, B) +#endif +#if GLOBAL_Q == 18 +#define _IQdiv(A, B) _IQ18div(A, B) +#endif +#if GLOBAL_Q == 17 +#define _IQdiv(A, B) _IQ17div(A, B) +#endif +#if GLOBAL_Q == 16 +#define _IQdiv(A, B) _IQ16div(A, B) +#endif +#if GLOBAL_Q == 15 +#define _IQdiv(A, B) _IQ15div(A, B) +#endif +#if GLOBAL_Q == 14 +#define _IQdiv(A, B) _IQ14div(A, B) +#endif +#if GLOBAL_Q == 13 +#define _IQdiv(A, B) _IQ13div(A, B) +#endif +#if GLOBAL_Q == 12 +#define _IQdiv(A, B) _IQ12div(A, B) +#endif +#if GLOBAL_Q == 11 +#define _IQdiv(A, B) _IQ11div(A, B) +#endif +#if GLOBAL_Q == 10 +#define _IQdiv(A, B) _IQ10div(A, B) +#endif +#if GLOBAL_Q == 9 +#define _IQdiv(A, B) _IQ9div(A, B) +#endif +#if GLOBAL_Q == 8 +#define _IQdiv(A, B) _IQ8div(A, B) +#endif +#if GLOBAL_Q == 7 +#define _IQdiv(A, B) _IQ7div(A, B) +#endif +#if GLOBAL_Q == 6 +#define _IQdiv(A, B) _IQ6div(A, B) +#endif +#if GLOBAL_Q == 5 +#define _IQdiv(A, B) _IQ5div(A, B) +#endif +#if GLOBAL_Q == 4 +#define _IQdiv(A, B) _IQ4div(A, B) +#endif +#if GLOBAL_Q == 3 +#define _IQdiv(A, B) _IQ3div(A, B) +#endif +#if GLOBAL_Q == 2 +#define _IQdiv(A, B) _IQ2div(A, B) +#endif +#if GLOBAL_Q == 1 +#define _IQdiv(A, B) _IQ1div(A, B) +#endif + +#else //DIV_FAST == 1 + +#if GLOBAL_Q == 30 +#define _IQdiv(A, B) _IQ30div_FAST(A, B) +#endif +#if GLOBAL_Q == 29 +#define _IQdiv(A, B) _IQ29div_FAST(A, B) +#endif +#if GLOBAL_Q == 28 +#define _IQdiv(A, B) _IQ28div_FAST(A, B) +#endif +#if GLOBAL_Q == 27 +#define _IQdiv(A, B) _IQ27div_FAST(A, B) +#endif +#if GLOBAL_Q == 26 +#define _IQdiv(A, B) _IQ26div_FAST(A, B) +#endif +#if GLOBAL_Q == 25 +#define _IQdiv(A, B) _IQ25div_FAST(A, B) +#endif +#if GLOBAL_Q == 24 +#define _IQdiv(A, B) _IQ24div_FAST(A, B) +#endif +#if GLOBAL_Q == 23 +#define _IQdiv(A, B) _IQ23div_FAST(A, B) +#endif +#if GLOBAL_Q == 22 +#define _IQdiv(A, B) _IQ22div_FAST(A, B) +#endif +#if GLOBAL_Q == 21 +#define _IQdiv(A, B) _IQ21div_FAST(A, B) +#endif +#if GLOBAL_Q == 20 +#define _IQdiv(A, B) _IQ20div_FAST(A, B) +#endif +#if GLOBAL_Q == 19 +#define _IQdiv(A, B) _IQ19div_FAST(A, B) +#endif +#if GLOBAL_Q == 18 +#define _IQdiv(A, B) _IQ18div_FAST(A, B) +#endif +#if GLOBAL_Q == 17 +#define _IQdiv(A, B) _IQ17div_FAST(A, B) +#endif +#if GLOBAL_Q == 16 +#define _IQdiv(A, B) _IQ16div_FAST(A, B) +#endif +#if GLOBAL_Q == 15 +#define _IQdiv(A, B) _IQ15div_FAST(A, B) +#endif +#if GLOBAL_Q == 14 +#define _IQdiv(A, B) _IQ14div_FAST(A, B) +#endif +#if GLOBAL_Q == 13 +#define _IQdiv(A, B) _IQ13div_FAST(A, B) +#endif +#if GLOBAL_Q == 12 +#define _IQdiv(A, B) _IQ12div_FAST(A, B) +#endif +#if GLOBAL_Q == 11 +#define _IQdiv(A, B) _IQ11div_FAST(A, B) +#endif +#if GLOBAL_Q == 10 +#define _IQdiv(A, B) _IQ10div_FAST(A, B) +#endif +#if GLOBAL_Q == 9 +#define _IQdiv(A, B) _IQ9div_FAST(A, B) +#endif +#if GLOBAL_Q == 8 +#define _IQdiv(A, B) _IQ8div_FAST(A, B) +#endif +#if GLOBAL_Q == 7 +#define _IQdiv(A, B) _IQ7div_FAST(A, B) +#endif +#if GLOBAL_Q == 6 +#define _IQdiv(A, B) _IQ6div_FAST(A, B) +#endif +#if GLOBAL_Q == 5 +#define _IQdiv(A, B) _IQ5div_FAST(A, B) +#endif +#if GLOBAL_Q == 4 +#define _IQdiv(A, B) _IQ4div_FAST(A, B) +#endif +#if GLOBAL_Q == 3 +#define _IQdiv(A, B) _IQ3div_FAST(A, B) +#endif +#if GLOBAL_Q == 2 +#define _IQdiv(A, B) _IQ2div_FAST(A, B) +#endif +#if GLOBAL_Q == 1 +#define _IQdiv(A, B) _IQ1div_FAST(A, B) +#endif + +#endif //end for DIV_FAST == 0 + + +extern _iq29 _IQ29sin(_iq29 A); +extern _iq28 _IQ28sin(_iq28 A); +extern _iq27 _IQ27sin(_iq27 A); +extern _iq26 _IQ26sin(_iq26 A); +extern _iq25 _IQ25sin(_iq25 A); +extern _iq24 _IQ24sin(_iq24 A); +extern _iq23 _IQ23sin(_iq23 A); +extern _iq22 _IQ22sin(_iq22 A); +extern _iq21 _IQ21sin(_iq21 A); +extern _iq20 _IQ20sin(_iq20 A); +extern _iq19 _IQ19sin(_iq19 A); +extern _iq18 _IQ18sin(_iq18 A); +extern _iq17 _IQ17sin(_iq17 A); +extern _iq16 _IQ16sin(_iq16 A); +extern _iq15 _IQ15sin(_iq15 A); +extern _iq14 _IQ14sin(_iq14 A); +extern _iq13 _IQ13sin(_iq13 A); +extern _iq12 _IQ12sin(_iq12 A); +extern _iq11 _IQ11sin(_iq11 A); +extern _iq10 _IQ10sin(_iq10 A); +extern _iq9 _IQ9sin(_iq9 A); +extern _iq8 _IQ8sin(_iq8 A); +extern _iq7 _IQ7sin(_iq7 A); +extern _iq6 _IQ6sin(_iq6 A); +extern _iq5 _IQ5sin(_iq5 A); +extern _iq4 _IQ4sin(_iq4 A); +extern _iq3 _IQ3sin(_iq3 A); +extern _iq2 _IQ2sin(_iq2 A); +extern _iq1 _IQ1sin(_iq1 A); +/******************************************************************************* +* Function Name : _IQsin +* Description : IQ格式数的正弦函数:sin(A) +* Input : 输入参数为IQ格式的弧度值 +* Return : 返回A的正弦值,与参数的IQ格式相同 +*******************************************************************************/ +#if GLOBAL_Q == 29 +#define _IQsin(A) _IQ29sin(A) +#endif +#if GLOBAL_Q == 28 +#define _IQsin(A) _IQ28sin(A) +#endif +#if GLOBAL_Q == 27 +#define _IQsin(A) _IQ27sin(A) +#endif +#if GLOBAL_Q == 26 +#define _IQsin(A) _IQ26sin(A) +#endif +#if GLOBAL_Q == 25 +#define _IQsin(A) _IQ25sin(A) +#endif +#if GLOBAL_Q == 24 +#define _IQsin(A) _IQ24sin(A) +#endif +#if GLOBAL_Q == 23 +#define _IQsin(A) _IQ23sin(A) +#endif +#if GLOBAL_Q == 22 +#define _IQsin(A) _IQ22sin(A) +#endif +#if GLOBAL_Q == 21 +#define _IQsin(A) _IQ21sin(A) +#endif +#if GLOBAL_Q == 20 +#define _IQsin(A) _IQ20sin(A) +#endif +#if GLOBAL_Q == 19 +#define _IQsin(A) _IQ19sin(A) +#endif +#if GLOBAL_Q == 18 +#define _IQsin(A) _IQ18sin(A) +#endif +#if GLOBAL_Q == 17 +#define _IQsin(A) _IQ17sin(A) +#endif +#if GLOBAL_Q == 16 +#define _IQsin(A) _IQ16sin(A) +#endif +#if GLOBAL_Q == 15 +#define _IQsin(A) _IQ15sin(A) +#endif +#if GLOBAL_Q == 14 +#define _IQsin(A) _IQ14sin(A) +#endif +#if GLOBAL_Q == 13 +#define _IQsin(A) _IQ13sin(A) +#endif +#if GLOBAL_Q == 12 +#define _IQsin(A) _IQ12sin(A) +#endif +#if GLOBAL_Q == 11 +#define _IQsin(A) _IQ11sin(A) +#endif +#if GLOBAL_Q == 10 +#define _IQsin(A) _IQ10sin(A) +#endif +#if GLOBAL_Q == 9 +#define _IQsin(A) _IQ9sin(A) +#endif +#if GLOBAL_Q == 8 +#define _IQsin(A) _IQ8sin(A) +#endif +#if GLOBAL_Q == 7 +#define _IQsin(A) _IQ7sin(A) +#endif +#if GLOBAL_Q == 6 +#define _IQsin(A) _IQ6sin(A) +#endif +#if GLOBAL_Q == 5 +#define _IQsin(A) _IQ5sin(A) +#endif +#if GLOBAL_Q == 4 +#define _IQsin(A) _IQ4sin(A) +#endif +#if GLOBAL_Q == 3 +#define _IQsin(A) _IQ3sin(A) +#endif +#if GLOBAL_Q == 2 +#define _IQsin(A) _IQ2sin(A) +#endif +#if GLOBAL_Q == 1 +#define _IQsin(A) _IQ1sin(A) +#endif + + +extern _iq30 _IQ30sinPU(_iq30 A); +extern _iq29 _IQ29sinPU(_iq29 A); +extern _iq28 _IQ28sinPU(_iq28 A); +extern _iq27 _IQ27sinPU(_iq27 A); +extern _iq26 _IQ26sinPU(_iq26 A); +extern _iq25 _IQ25sinPU(_iq25 A); +extern _iq24 _IQ24sinPU(_iq24 A); +extern _iq23 _IQ23sinPU(_iq23 A); +extern _iq22 _IQ22sinPU(_iq22 A); +extern _iq21 _IQ21sinPU(_iq21 A); +extern _iq20 _IQ20sinPU(_iq20 A); +extern _iq19 _IQ19sinPU(_iq19 A); +extern _iq18 _IQ18sinPU(_iq18 A); +extern _iq17 _IQ17sinPU(_iq17 A); +extern _iq16 _IQ16sinPU(_iq16 A); +extern _iq15 _IQ15sinPU(_iq15 A); +extern _iq14 _IQ14sinPU(_iq14 A); +extern _iq13 _IQ13sinPU(_iq13 A); +extern _iq12 _IQ12sinPU(_iq12 A); +extern _iq11 _IQ11sinPU(_iq11 A); +extern _iq10 _IQ10sinPU(_iq10 A); +extern _iq24 _IQ10sinPU_Q24(_iq10 A); +extern _iq9 _IQ9sinPU(_iq9 A); +extern _iq8 _IQ8sinPU(_iq8 A); +extern _iq7 _IQ7sinPU(_iq7 A); +extern _iq6 _IQ6sinPU(_iq6 A); +extern _iq5 _IQ5sinPU(_iq5 A); +extern _iq4 _IQ4sinPU(_iq4 A); +extern _iq3 _IQ3sinPU(_iq3 A); +extern _iq2 _IQ2sinPU(_iq2 A); +extern _iq1 _IQ1sinPU(_iq1 A); +/******************************************************************************* +* Function Name : _IQsinPU +* Description : IQ格式数的正弦函数:sin((2*PI)*A) +* Input : 输入参数是几分之一个圆 +* Return : 返回A的正弦值,与参数的IQ格式相同 +*******************************************************************************/ +#if GLOBAL_Q == 30 +#define _IQsinPU(A) _IQ30sinPU(A) +#endif +#if GLOBAL_Q == 29 +#define _IQsinPU(A) _IQ29sinPU(A) +#endif +#if GLOBAL_Q == 28 +#define _IQsinPU(A) _IQ28sinPU(A) +#endif +#if GLOBAL_Q == 27 +#define _IQsinPU(A) _IQ27sinPU(A) +#endif +#if GLOBAL_Q == 26 +#define _IQsinPU(A) _IQ26sinPU(A) +#endif +#if GLOBAL_Q == 25 +#define _IQsinPU(A) _IQ25sinPU(A) +#endif +#if GLOBAL_Q == 24 +#define _IQsinPU(A) _IQ24sinPU(A) +#endif +#if GLOBAL_Q == 23 +#define _IQsinPU(A) _IQ23sinPU(A) +#endif +#if GLOBAL_Q == 22 +#define _IQsinPU(A) _IQ22sinPU(A) +#endif +#if GLOBAL_Q == 21 +#define _IQsinPU(A) _IQ21sinPU(A) +#endif +#if GLOBAL_Q == 20 +#define _IQsinPU(A) _IQ20sinPU(A) +#endif +#if GLOBAL_Q == 19 +#define _IQsinPU(A) _IQ19sinPU(A) +#endif +#if GLOBAL_Q == 18 +#define _IQsinPU(A) _IQ18sinPU(A) +#endif +#if GLOBAL_Q == 17 +#define _IQsinPU(A) _IQ17sinPU(A) +#endif +#if GLOBAL_Q == 16 +#define _IQsinPU(A) _IQ16sinPU(A) +#endif +#if GLOBAL_Q == 15 +#define _IQsinPU(A) _IQ15sinPU(A) +#endif +#if GLOBAL_Q == 14 +#define _IQsinPU(A) _IQ14sinPU(A) +#endif +#if GLOBAL_Q == 13 +#define _IQsinPU(A) _IQ13sinPU(A) +#endif +#if GLOBAL_Q == 12 +#define _IQsinPU(A) _IQ12sinPU(A) +#endif +#if GLOBAL_Q == 11 +#define _IQsinPU(A) _IQ11sinPU(A) +#endif +#if GLOBAL_Q == 10 +#define _IQsinPU(A) _IQ10sinPU(A) +#endif +#if GLOBAL_Q == 9 +#define _IQsinPU(A) _IQ9sinPU(A) +#endif +#if GLOBAL_Q == 8 +#define _IQsinPU(A) _IQ8sinPU(A) +#endif +#if GLOBAL_Q == 7 +#define _IQsinPU(A) _IQ7sinPU(A) +#endif +#if GLOBAL_Q == 6 +#define _IQsinPU(A) _IQ6sinPU(A) +#endif +#if GLOBAL_Q == 5 +#define _IQsinPU(A) _IQ5sinPU(A) +#endif +#if GLOBAL_Q == 4 +#define _IQsinPU(A) _IQ4sinPU(A) +#endif +#if GLOBAL_Q == 3 +#define _IQsinPU(A) _IQ3sinPU(A) +#endif +#if GLOBAL_Q == 2 +#define _IQsinPU(A) _IQ2sinPU(A) +#endif +#if GLOBAL_Q == 1 +#define _IQsinPU(A) _IQ1sinPU(A) +#endif + +extern _iq29 _IQ29asin(_iq29 A); +extern _iq28 _IQ28asin(_iq28 A); +extern _iq27 _IQ27asin(_iq27 A); +extern _iq26 _IQ26asin(_iq26 A); +extern _iq25 _IQ25asin(_iq25 A); +extern _iq24 _IQ24asin(_iq24 A); +extern _iq23 _IQ23asin(_iq23 A); +extern _iq22 _IQ22asin(_iq22 A); +extern _iq21 _IQ21asin(_iq21 A); +extern _iq20 _IQ20asin(_iq20 A); +extern _iq19 _IQ19asin(_iq19 A); +extern _iq18 _IQ18asin(_iq18 A); +extern _iq17 _IQ17asin(_iq17 A); +extern _iq16 _IQ16asin(_iq16 A); +extern _iq15 _IQ15asin(_iq15 A); +extern _iq14 _IQ14asin(_iq14 A); +extern _iq13 _IQ13asin(_iq13 A); +extern _iq12 _IQ12asin(_iq12 A); +extern _iq11 _IQ11asin(_iq11 A); +extern _iq10 _IQ10asin(_iq10 A); +extern _iq9 _IQ9asin(_iq9 A); +extern _iq8 _IQ8asin(_iq8 A); +extern _iq7 _IQ7asin(_iq7 A); +extern _iq6 _IQ6asin(_iq6 A); +extern _iq5 _IQ5asin(_iq5 A); +extern _iq4 _IQ4asin(_iq4 A); +extern _iq3 _IQ3asin(_iq3 A); +extern _iq2 _IQ2asin(_iq2 A); +extern _iq1 _IQ1asin(_iq1 A); +/******************************************************************************* +* Function Name : _IQasin +* Description : IQ格式数的反正弦函数:asin(A) +* Input : 输入参数为IQ格式的弧度值 +* Return : 返回A的反正弦值,与参数的IQ格式相同 +*******************************************************************************/ +#if GLOBAL_Q == 29 +#define _IQasin(A) _IQ29asin(A) +#endif +#if GLOBAL_Q == 28 +#define _IQasin(A) _IQ28asin(A) +#endif +#if GLOBAL_Q == 27 +#define _IQasin(A) _IQ27asin(A) +#endif +#if GLOBAL_Q == 26 +#define _IQasin(A) _IQ26asin(A) +#endif +#if GLOBAL_Q == 25 +#define _IQasin(A) _IQ25asin(A) +#endif +#if GLOBAL_Q == 24 +#define _IQasin(A) _IQ24asin(A) +#endif +#if GLOBAL_Q == 23 +#define _IQasin(A) _IQ23asin(A) +#endif +#if GLOBAL_Q == 22 +#define _IQasin(A) _IQ22asin(A) +#endif +#if GLOBAL_Q == 21 +#define _IQasin(A) _IQ21asin(A) +#endif +#if GLOBAL_Q == 20 +#define _IQasin(A) _IQ20asin(A) +#endif +#if GLOBAL_Q == 19 +#define _IQasin(A) _IQ19asin(A) +#endif +#if GLOBAL_Q == 18 +#define _IQasin(A) _IQ18asin(A) +#endif +#if GLOBAL_Q == 17 +#define _IQasin(A) _IQ17asin(A) +#endif +#if GLOBAL_Q == 16 +#define _IQasin(A) _IQ16asin(A) +#endif +#if GLOBAL_Q == 15 +#define _IQasin(A) _IQ15asin(A) +#endif +#if GLOBAL_Q == 14 +#define _IQasin(A) _IQ14asin(A) +#endif +#if GLOBAL_Q == 13 +#define _IQasin(A) _IQ13asin(A) +#endif +#if GLOBAL_Q == 12 +#define _IQasin(A) _IQ12asin(A) +#endif +#if GLOBAL_Q == 11 +#define _IQasin(A) _IQ11asin(A) +#endif +#if GLOBAL_Q == 10 +#define _IQasin(A) _IQ10asin(A) +#endif +#if GLOBAL_Q == 9 +#define _IQasin(A) _IQ9asin(A) +#endif +#if GLOBAL_Q == 8 +#define _IQasin(A) _IQ8asin(A) +#endif +#if GLOBAL_Q == 7 +#define _IQasin(A) _IQ7asin(A) +#endif +#if GLOBAL_Q == 6 +#define _IQasin(A) _IQ6asin(A) +#endif +#if GLOBAL_Q == 5 +#define _IQasin(A) _IQ5asin(A) +#endif +#if GLOBAL_Q == 4 +#define _IQasin(A) _IQ4asin(A) +#endif +#if GLOBAL_Q == 3 +#define _IQasin(A) _IQ3asin(A) +#endif +#if GLOBAL_Q == 2 +#define _IQasin(A) _IQ2asin(A) +#endif +#if GLOBAL_Q == 1 +#define _IQasin(A) _IQ1asin(A) +#endif + + +extern _iq29 _IQ29cos(_iq29 A); +extern _iq28 _IQ28cos(_iq28 A); +extern _iq27 _IQ27cos(_iq27 A); +extern _iq26 _IQ26cos(_iq26 A); +extern _iq25 _IQ25cos(_iq25 A); +extern _iq24 _IQ24cos(_iq24 A); +extern _iq23 _IQ23cos(_iq23 A); +extern _iq22 _IQ22cos(_iq22 A); +extern _iq21 _IQ21cos(_iq21 A); +extern _iq20 _IQ20cos(_iq20 A); +extern _iq19 _IQ19cos(_iq19 A); +extern _iq18 _IQ18cos(_iq18 A); +extern _iq17 _IQ17cos(_iq17 A); +extern _iq16 _IQ16cos(_iq16 A); +extern _iq15 _IQ15cos(_iq15 A); +extern _iq14 _IQ14cos(_iq14 A); +extern _iq13 _IQ13cos(_iq13 A); +extern _iq12 _IQ12cos(_iq12 A); +extern _iq11 _IQ11cos(_iq11 A); +extern _iq10 _IQ10cos(_iq10 A); +extern _iq9 _IQ9cos(_iq9 A); +extern _iq8 _IQ8cos(_iq8 A); +extern _iq7 _IQ7cos(_iq7 A); +extern _iq6 _IQ6cos(_iq6 A); +extern _iq5 _IQ5cos(_iq5 A); +extern _iq4 _IQ4cos(_iq4 A); +extern _iq3 _IQ3cos(_iq3 A); +extern _iq2 _IQ2cos(_iq2 A); +extern _iq1 _IQ1cos(_iq1 A); +/******************************************************************************* +* Function Name : _IQcos +* Description : IQ格式数的余弦函数:cos(A) +* Input : 输入参数为IQ格式的弧度值 +* Return : 返回A的余弦值,与参数的IQ格式相同 +*******************************************************************************/ +#if GLOBAL_Q == 29 +#define _IQcos(A) _IQ29cos(A) +#endif +#if GLOBAL_Q == 28 +#define _IQcos(A) _IQ28cos(A) +#endif +#if GLOBAL_Q == 27 +#define _IQcos(A) _IQ27cos(A) +#endif +#if GLOBAL_Q == 26 +#define _IQcos(A) _IQ26cos(A) +#endif +#if GLOBAL_Q == 25 +#define _IQcos(A) _IQ25cos(A) +#endif +#if GLOBAL_Q == 24 +#define _IQcos(A) _IQ24cos(A) +#endif +#if GLOBAL_Q == 23 +#define _IQcos(A) _IQ23cos(A) +#endif +#if GLOBAL_Q == 22 +#define _IQcos(A) _IQ22cos(A) +#endif +#if GLOBAL_Q == 21 +#define _IQcos(A) _IQ21cos(A) +#endif +#if GLOBAL_Q == 20 +#define _IQcos(A) _IQ20cos(A) +#endif +#if GLOBAL_Q == 19 +#define _IQcos(A) _IQ19cos(A) +#endif +#if GLOBAL_Q == 18 +#define _IQcos(A) _IQ18cos(A) +#endif +#if GLOBAL_Q == 17 +#define _IQcos(A) _IQ17cos(A) +#endif +#if GLOBAL_Q == 16 +#define _IQcos(A) _IQ16cos(A) +#endif +#if GLOBAL_Q == 15 +#define _IQcos(A) _IQ15cos(A) +#endif +#if GLOBAL_Q == 14 +#define _IQcos(A) _IQ14cos(A) +#endif +#if GLOBAL_Q == 13 +#define _IQcos(A) _IQ13cos(A) +#endif +#if GLOBAL_Q == 12 +#define _IQcos(A) _IQ12cos(A) +#endif +#if GLOBAL_Q == 11 +#define _IQcos(A) _IQ11cos(A) +#endif +#if GLOBAL_Q == 10 +#define _IQcos(A) _IQ10cos(A) +#endif +#if GLOBAL_Q == 9 +#define _IQcos(A) _IQ9cos(A) +#endif +#if GLOBAL_Q == 8 +#define _IQcos(A) _IQ8cos(A) +#endif +#if GLOBAL_Q == 7 +#define _IQcos(A) _IQ7cos(A) +#endif +#if GLOBAL_Q == 6 +#define _IQcos(A) _IQ6cos(A) +#endif +#if GLOBAL_Q == 5 +#define _IQcos(A) _IQ5cos(A) +#endif +#if GLOBAL_Q == 4 +#define _IQcos(A) _IQ4cos(A) +#endif +#if GLOBAL_Q == 3 +#define _IQcos(A) _IQ3cos(A) +#endif +#if GLOBAL_Q == 2 +#define _IQcos(A) _IQ2cos(A) +#endif +#if GLOBAL_Q == 1 +#define _IQcos(A) _IQ1cos(A) +#endif + + +extern _iq30 _IQ30cosPU(_iq30 A); +extern _iq29 _IQ29cosPU(_iq29 A); +extern _iq28 _IQ28cosPU(_iq28 A); +extern _iq27 _IQ27cosPU(_iq27 A); +extern _iq26 _IQ26cosPU(_iq26 A); +extern _iq25 _IQ25cosPU(_iq25 A); +extern _iq24 _IQ24cosPU(_iq24 A); +extern _iq23 _IQ23cosPU(_iq23 A); +extern _iq22 _IQ22cosPU(_iq22 A); +extern _iq21 _IQ21cosPU(_iq21 A); +extern _iq20 _IQ20cosPU(_iq20 A); +extern _iq19 _IQ19cosPU(_iq19 A); +extern _iq18 _IQ18cosPU(_iq18 A); +extern _iq17 _IQ17cosPU(_iq17 A); +extern _iq16 _IQ16cosPU(_iq16 A); +extern _iq15 _IQ15cosPU(_iq15 A); +extern _iq14 _IQ14cosPU(_iq14 A); +extern _iq13 _IQ13cosPU(_iq13 A); +extern _iq12 _IQ12cosPU(_iq12 A); +extern _iq11 _IQ11cosPU(_iq11 A); +extern _iq10 _IQ10cosPU(_iq10 A); +extern _iq24 _IQ10cosPU_Q24(_iq10 A); +extern _iq9 _IQ9cosPU(_iq9 A); +extern _iq8 _IQ8cosPU(_iq8 A); +extern _iq7 _IQ7cosPU(_iq7 A); +extern _iq6 _IQ6cosPU(_iq6 A); +extern _iq5 _IQ5cosPU(_iq5 A); +extern _iq4 _IQ4cosPU(_iq4 A); +extern _iq3 _IQ3cosPU(_iq3 A); +extern _iq2 _IQ2cosPU(_iq2 A); +extern _iq1 _IQ1cosPU(_iq1 A); +/******************************************************************************* +* Function Name : _IQcosPU +* Description : IQ格式数的余弦函数,acos((2*PI)*A) +* Input : 输入参数是几分之一个圆 +* Return : 返回A的余弦值,与参数的IQ格式相同 +*******************************************************************************/ +#if GLOBAL_Q == 30 +#define _IQcosPU(A) _IQ30cosPU(A) +#endif +#if GLOBAL_Q == 29 +#define _IQcosPU(A) _IQ29cosPU(A) +#endif +#if GLOBAL_Q == 28 +#define _IQcosPU(A) _IQ28cosPU(A) +#endif +#if GLOBAL_Q == 27 +#define _IQcosPU(A) _IQ27cosPU(A) +#endif +#if GLOBAL_Q == 26 +#define _IQcosPU(A) _IQ26cosPU(A) +#endif +#if GLOBAL_Q == 25 +#define _IQcosPU(A) _IQ25cosPU(A) +#endif +#if GLOBAL_Q == 24 +#define _IQcosPU(A) _IQ24cosPU(A) +#endif +#if GLOBAL_Q == 23 +#define _IQcosPU(A) _IQ23cosPU(A) +#endif +#if GLOBAL_Q == 22 +#define _IQcosPU(A) _IQ22cosPU(A) +#endif +#if GLOBAL_Q == 21 +#define _IQcosPU(A) _IQ21cosPU(A) +#endif +#if GLOBAL_Q == 20 +#define _IQcosPU(A) _IQ20cosPU(A) +#endif +#if GLOBAL_Q == 19 +#define _IQcosPU(A) _IQ19cosPU(A) +#endif +#if GLOBAL_Q == 18 +#define _IQcosPU(A) _IQ18cosPU(A) +#endif +#if GLOBAL_Q == 17 +#define _IQcosPU(A) _IQ17cosPU(A) +#endif +#if GLOBAL_Q == 16 +#define _IQcosPU(A) _IQ16cosPU(A) +#endif +#if GLOBAL_Q == 15 +#define _IQcosPU(A) _IQ15cosPU(A) +#endif +#if GLOBAL_Q == 14 +#define _IQcosPU(A) _IQ14cosPU(A) +#endif +#if GLOBAL_Q == 13 +#define _IQcosPU(A) _IQ13cosPU(A) +#endif +#if GLOBAL_Q == 12 +#define _IQcosPU(A) _IQ12cosPU(A) +#endif +#if GLOBAL_Q == 11 +#define _IQcosPU(A) _IQ11cosPU(A) +#endif +#if GLOBAL_Q == 10 +#define _IQcosPU(A) _IQ10cosPU(A) +#endif +#if GLOBAL_Q == 9 +#define _IQcosPU(A) _IQ9cosPU(A) +#endif +#if GLOBAL_Q == 8 +#define _IQcosPU(A) _IQ8cosPU(A) +#endif +#if GLOBAL_Q == 7 +#define _IQcosPU(A) _IQ7cosPU(A) +#endif +#if GLOBAL_Q == 6 +#define _IQcosPU(A) _IQ6cosPU(A) +#endif +#if GLOBAL_Q == 5 +#define _IQcosPU(A) _IQ5cosPU(A) +#endif +#if GLOBAL_Q == 4 +#define _IQcosPU(A) _IQ4cosPU(A) +#endif +#if GLOBAL_Q == 3 +#define _IQcosPU(A) _IQ3cosPU(A) +#endif +#if GLOBAL_Q == 2 +#define _IQcosPU(A) _IQ2cosPU(A) +#endif +#if GLOBAL_Q == 1 +#define _IQcosPU(A) _IQ1cosPU(A) +#endif + + +#define _IQ29acos(A) (_IQ29(1.570796327) - _IQ29asin(A)) +#define _IQ28acos(A) (_IQ28(1.570796327) - _IQ28asin(A)) +#define _IQ27acos(A) (_IQ27(1.570796327) - _IQ27asin(A)) +#define _IQ26acos(A) (_IQ26(1.570796327) - _IQ26asin(A)) +#define _IQ25acos(A) (_IQ25(1.570796327) - _IQ25asin(A)) +#define _IQ24acos(A) (_IQ24(1.570796327) - _IQ24asin(A)) +#define _IQ23acos(A) (_IQ23(1.570796327) - _IQ23asin(A)) +#define _IQ22acos(A) (_IQ22(1.570796327) - _IQ22asin(A)) +#define _IQ21acos(A) (_IQ21(1.570796327) - _IQ21asin(A)) +#define _IQ20acos(A) (_IQ20(1.570796327) - _IQ20asin(A)) +#define _IQ19acos(A) (_IQ19(1.570796327) - _IQ19asin(A)) +#define _IQ18acos(A) (_IQ18(1.570796327) - _IQ18asin(A)) +#define _IQ17acos(A) (_IQ17(1.570796327) - _IQ17asin(A)) +#define _IQ16acos(A) (_IQ16(1.570796327) - _IQ16asin(A)) +#define _IQ15acos(A) (_IQ15(1.570796327) - _IQ15asin(A)) +#define _IQ14acos(A) (_IQ14(1.570796327) - _IQ14asin(A)) +#define _IQ13acos(A) (_IQ13(1.570796327) - _IQ13asin(A)) +#define _IQ12acos(A) (_IQ12(1.570796327) - _IQ12asin(A)) +#define _IQ11acos(A) (_IQ11(1.570796327) - _IQ11asin(A)) +#define _IQ10acos(A) (_IQ10(1.570796327) - _IQ10asin(A)) +#define _IQ9acos(A) (_IQ9(1.570796327) - _IQ9asin(A)) +#define _IQ8acos(A) (_IQ8(1.570796327) - _IQ8asin(A)) +#define _IQ7acos(A) (_IQ7(1.570796327) - _IQ7asin(A)) +#define _IQ6acos(A) (_IQ6(1.570796327) - _IQ6asin(A)) +#define _IQ5acos(A) (_IQ5(1.570796327) - _IQ5asin(A)) +#define _IQ4acos(A) (_IQ4(1.570796327) - _IQ4asin(A)) +#define _IQ3acos(A) (_IQ3(1.570796327) - _IQ3asin(A)) +#define _IQ2acos(A) (_IQ2(1.570796327) - _IQ2asin(A)) +#define _IQ1acos(A) (_IQ1(1.570796327) - _IQ1asin(A)) +/******************************************************************************* +* Function Name : _IQacos +* Description : IQ格式数的反余弦函数:acos(A) +* Input : 输入参数为IQ格式的弧度值 +* Return : 返回A的反余弦值,与参数的IQ格式相同 +*******************************************************************************/ +#if GLOBAL_Q == 29 +#define _IQacos(A) _IQ29acos(A) +#endif +#if GLOBAL_Q == 28 +#define _IQacos(A) _IQ28acos(A) +#endif +#if GLOBAL_Q == 27 +#define _IQacos(A) _IQ27acos(A) +#endif +#if GLOBAL_Q == 26 +#define _IQacos(A) _IQ26acos(A) +#endif +#if GLOBAL_Q == 25 +#define _IQacos(A) _IQ25acos(A) +#endif +#if GLOBAL_Q == 24 +#define _IQacos(A) _IQ24acos(A) +#endif +#if GLOBAL_Q == 23 +#define _IQacos(A) _IQ23acos(A) +#endif +#if GLOBAL_Q == 22 +#define _IQacos(A) _IQ22acos(A) +#endif +#if GLOBAL_Q == 21 +#define _IQacos(A) _IQ21acos(A) +#endif +#if GLOBAL_Q == 20 +#define _IQacos(A) _IQ20acos(A) +#endif +#if GLOBAL_Q == 19 +#define _IQacos(A) _IQ19acos(A) +#endif +#if GLOBAL_Q == 18 +#define _IQacos(A) _IQ18acos(A) +#endif +#if GLOBAL_Q == 17 +#define _IQacos(A) _IQ17acos(A) +#endif +#if GLOBAL_Q == 16 +#define _IQacos(A) _IQ16acos(A) +#endif +#if GLOBAL_Q == 15 +#define _IQacos(A) _IQ15acos(A) +#endif +#if GLOBAL_Q == 14 +#define _IQacos(A) _IQ14acos(A) +#endif +#if GLOBAL_Q == 13 +#define _IQacos(A) _IQ13acos(A) +#endif +#if GLOBAL_Q == 12 +#define _IQacos(A) _IQ12acos(A) +#endif +#if GLOBAL_Q == 11 +#define _IQacos(A) _IQ11acos(A) +#endif +#if GLOBAL_Q == 10 +#define _IQacos(A) _IQ10acos(A) +#endif +#if GLOBAL_Q == 9 +#define _IQacos(A) _IQ9acos(A) +#endif +#if GLOBAL_Q == 8 +#define _IQacos(A) _IQ8acos(A) +#endif +#if GLOBAL_Q == 7 +#define _IQacos(A) _IQ7acos(A) +#endif +#if GLOBAL_Q == 6 +#define _IQacos(A) _IQ6acos(A) +#endif +#if GLOBAL_Q == 5 +#define _IQacos(A) _IQ5acos(A) +#endif +#if GLOBAL_Q == 4 +#define _IQacos(A) _IQ4acos(A) +#endif +#if GLOBAL_Q == 3 +#define _IQacos(A) _IQ3acos(A) +#endif +#if GLOBAL_Q == 2 +#define _IQacos(A) _IQ2acos(A) +#endif +#if GLOBAL_Q == 1 +#define _IQacos(A) _IQ1acos(A) +#endif + + +extern _iq29 _IQ29atan2(_iq29 A, _iq29 B); +extern _iq28 _IQ28atan2(_iq28 A, _iq28 B); +extern _iq27 _IQ27atan2(_iq27 A, _iq27 B); +extern _iq26 _IQ26atan2(_iq26 A, _iq26 B); +extern _iq25 _IQ25atan2(_iq25 A, _iq25 B); +extern _iq24 _IQ24atan2(_iq24 A, _iq24 B); +extern _iq23 _IQ23atan2(_iq23 A, _iq23 B); +extern _iq22 _IQ22atan2(_iq22 A, _iq22 B); +extern _iq21 _IQ21atan2(_iq21 A, _iq21 B); +extern _iq20 _IQ20atan2(_iq20 A, _iq20 B); +extern _iq19 _IQ19atan2(_iq19 A, _iq19 B); +extern _iq18 _IQ18atan2(_iq18 A, _iq18 B); +extern _iq17 _IQ17atan2(_iq17 A, _iq17 B); +extern _iq16 _IQ16atan2(_iq16 A, _iq16 B); +extern _iq15 _IQ15atan2(_iq15 A, _iq15 B); +extern _iq14 _IQ14atan2(_iq14 A, _iq14 B); +extern _iq13 _IQ13atan2(_iq13 A, _iq13 B); +extern _iq12 _IQ12atan2(_iq12 A, _iq12 B); +extern _iq11 _IQ11atan2(_iq11 A, _iq11 B); +extern _iq10 _IQ10atan2(_iq10 A, _iq10 B); +extern _iq9 _IQ9atan2(_iq9 A, _iq9 B); +extern _iq8 _IQ8atan2(_iq8 A, _iq8 B); +extern _iq7 _IQ7atan2(_iq7 A, _iq7 B); +extern _iq6 _IQ6atan2(_iq6 A, _iq6 B); +extern _iq5 _IQ5atan2(_iq5 A, _iq5 B); +extern _iq4 _IQ4atan2(_iq4 A, _iq4 B); +extern _iq3 _IQ3atan2(_iq3 A, _iq3 B); +extern _iq2 _IQ2atan2(_iq2 A, _iq2 B); +extern _iq1 _IQ1atan2(_iq1 A, _iq1 B); +/******************************************************************************* +* Function Name : _IQatan2 +* Description : IQ格式数的反正切函数,可计算4个象限内的点:atan2(A,B) +* Input : A为IQ格式的Y轴坐标值,B为IQ格式的X轴坐标值 +* Return : 返回点(B,A)与X轴的夹角的弧度值,与参数的IQ格式相同 +*******************************************************************************/ +#if GLOBAL_Q == 29 +#define _IQatan2(A, B) _IQ29atan2(A, B) +#endif +#if GLOBAL_Q == 28 +#define _IQatan2(A, B) _IQ28atan2(A, B) +#endif +#if GLOBAL_Q == 27 +#define _IQatan2(A, B) _IQ27atan2(A, B) +#endif +#if GLOBAL_Q == 26 +#define _IQatan2(A, B) _IQ26atan2(A, B) +#endif +#if GLOBAL_Q == 25 +#define _IQatan2(A, B) _IQ25atan2(A, B) +#endif +#if GLOBAL_Q == 24 +#define _IQatan2(A, B) _IQ24atan2(A, B) +#endif +#if GLOBAL_Q == 23 +#define _IQatan2(A, B) _IQ23atan2(A, B) +#endif +#if GLOBAL_Q == 22 +#define _IQatan2(A, B) _IQ22atan2(A, B) +#endif +#if GLOBAL_Q == 21 +#define _IQatan2(A, B) _IQ21atan2(A, B) +#endif +#if GLOBAL_Q == 20 +#define _IQatan2(A, B) _IQ20atan2(A, B) +#endif +#if GLOBAL_Q == 19 +#define _IQatan2(A, B) _IQ19atan2(A, B) +#endif +#if GLOBAL_Q == 18 +#define _IQatan2(A, B) _IQ18atan2(A, B) +#endif +#if GLOBAL_Q == 17 +#define _IQatan2(A, B) _IQ17atan2(A, B) +#endif +#if GLOBAL_Q == 16 +#define _IQatan2(A, B) _IQ16atan2(A, B) +#endif +#if GLOBAL_Q == 15 +#define _IQatan2(A, B) _IQ15atan2(A, B) +#endif +#if GLOBAL_Q == 14 +#define _IQatan2(A, B) _IQ14atan2(A, B) +#endif +#if GLOBAL_Q == 13 +#define _IQatan2(A, B) _IQ13atan2(A, B) +#endif +#if GLOBAL_Q == 12 +#define _IQatan2(A, B) _IQ12atan2(A, B) +#endif +#if GLOBAL_Q == 11 +#define _IQatan2(A, B) _IQ11atan2(A, B) +#endif +#if GLOBAL_Q == 10 +#define _IQatan2(A, B) _IQ10atan2(A, B) +#endif +#if GLOBAL_Q == 9 +#define _IQatan2(A, B) _IQ9atan2(A, B) +#endif +#if GLOBAL_Q == 8 +#define _IQatan2(A, B) _IQ8atan2(A, B) +#endif +#if GLOBAL_Q == 7 +#define _IQatan2(A, B) _IQ7atan2(A, B) +#endif +#if GLOBAL_Q == 6 +#define _IQatan2(A, B) _IQ6atan2(A, B) +#endif +#if GLOBAL_Q == 5 +#define _IQatan2(A, B) _IQ5atan2(A, B) +#endif +#if GLOBAL_Q == 4 +#define _IQatan2(A, B) _IQ4atan2(A, B) +#endif +#if GLOBAL_Q == 3 +#define _IQatan2(A, B) _IQ3atan2(A, B) +#endif +#if GLOBAL_Q == 2 +#define _IQatan2(A, B) _IQ2atan2(A, B) +#endif +#if GLOBAL_Q == 1 +#define _IQatan2(A, B) _IQ1atan2(A, B) +#endif + + +extern _iq30 _IQ30atan2PU(_iq30 A, _iq30 B); +extern _iq29 _IQ29atan2PU(_iq29 A, _iq29 B); +extern _iq28 _IQ28atan2PU(_iq28 A, _iq28 B); +extern _iq27 _IQ27atan2PU(_iq27 A, _iq27 B); +extern _iq26 _IQ26atan2PU(_iq26 A, _iq26 B); +extern _iq25 _IQ25atan2PU(_iq25 A, _iq25 B); +extern _iq24 _IQ24atan2PU(_iq24 A, _iq24 B); +extern _iq23 _IQ23atan2PU(_iq23 A, _iq23 B); +extern _iq22 _IQ22atan2PU(_iq22 A, _iq22 B); +extern _iq21 _IQ21atan2PU(_iq21 A, _iq21 B); +extern _iq20 _IQ20atan2PU(_iq20 A, _iq20 B); +extern _iq19 _IQ19atan2PU(_iq19 A, _iq19 B); +extern _iq18 _IQ18atan2PU(_iq18 A, _iq18 B); +extern _iq17 _IQ17atan2PU(_iq17 A, _iq17 B); +extern _iq16 _IQ16atan2PU(_iq16 A, _iq16 B); +extern _iq15 _IQ15atan2PU(_iq15 A, _iq15 B); +extern _iq14 _IQ14atan2PU(_iq14 A, _iq14 B); +extern _iq13 _IQ13atan2PU(_iq13 A, _iq13 B); +extern _iq12 _IQ12atan2PU(_iq12 A, _iq12 B); +extern _iq11 _IQ11atan2PU(_iq11 A, _iq11 B); +extern _iq10 _IQ10atan2PU(_iq10 A, _iq10 B); +extern _iq9 _IQ9atan2PU(_iq9 A, _iq9 B); +extern _iq8 _IQ8atan2PU(_iq8 A, _iq8 B); +extern _iq7 _IQ7atan2PU(_iq7 A, _iq7 B); +extern _iq6 _IQ6atan2PU(_iq6 A, _iq6 B); +extern _iq5 _IQ5atan2PU(_iq5 A, _iq5 B); +extern _iq4 _IQ4atan2PU(_iq4 A, _iq4 B); +extern _iq3 _IQ3atan2PU(_iq3 A, _iq3 B); +extern _iq2 _IQ2atan2PU(_iq2 A, _iq2 B); +extern _iq1 _IQ1atan2PU(_iq1 A, _iq1 B); +/******************************************************************************* +* Function Name : _IQatan2PU +* Description : IQ格式数的反正切函数,可计算4个象限内的点 +* Input : A为IQ格式的Y轴坐标值,B为IQ格式的X轴坐标值 +* Return : 返回值是0到1之间的一个小数,代表几分之一个圆,与参数的IQ格式相同 +*******************************************************************************/ +#if GLOBAL_Q == 30 +#define _IQatan2PU(A, B) _IQ30atan2PU(A, B) +#endif +#if GLOBAL_Q == 29 +#define _IQatan2PU(A, B) _IQ29atan2PU(A, B) +#endif +#if GLOBAL_Q == 28 +#define _IQatan2PU(A, B) _IQ28atan2PU(A, B) +#endif +#if GLOBAL_Q == 27 +#define _IQatan2PU(A, B) _IQ27atan2PU(A, B) +#endif +#if GLOBAL_Q == 26 +#define _IQatan2PU(A, B) _IQ26atan2PU(A, B) +#endif +#if GLOBAL_Q == 25 +#define _IQatan2PU(A, B) _IQ25atan2PU(A, B) +#endif +#if GLOBAL_Q == 24 +#define _IQatan2PU(A, B) _IQ24atan2PU(A, B) +#endif +#if GLOBAL_Q == 23 +#define _IQatan2PU(A, B) _IQ23atan2PU(A, B) +#endif +#if GLOBAL_Q == 22 +#define _IQatan2PU(A, B) _IQ22atan2PU(A, B) +#endif +#if GLOBAL_Q == 21 +#define _IQatan2PU(A, B) _IQ21atan2PU(A, B) +#endif +#if GLOBAL_Q == 20 +#define _IQatan2PU(A, B) _IQ20atan2PU(A, B) +#endif +#if GLOBAL_Q == 19 +#define _IQatan2PU(A, B) _IQ19atan2PU(A, B) +#endif +#if GLOBAL_Q == 18 +#define _IQatan2PU(A, B) _IQ18atan2PU(A, B) +#endif +#if GLOBAL_Q == 17 +#define _IQatan2PU(A, B) _IQ17atan2PU(A, B) +#endif +#if GLOBAL_Q == 16 +#define _IQatan2PU(A, B) _IQ16atan2PU(A, B) +#endif +#if GLOBAL_Q == 15 +#define _IQatan2PU(A, B) _IQ15atan2PU(A, B) +#endif +#if GLOBAL_Q == 14 +#define _IQatan2PU(A, B) _IQ14atan2PU(A, B) +#endif +#if GLOBAL_Q == 13 +#define _IQatan2PU(A, B) _IQ13atan2PU(A, B) +#endif +#if GLOBAL_Q == 12 +#define _IQatan2PU(A, B) _IQ12atan2PU(A, B) +#endif +#if GLOBAL_Q == 11 +#define _IQatan2PU(A, B) _IQ11atan2PU(A, B) +#endif +#if GLOBAL_Q == 10 +#define _IQatan2PU(A, B) _IQ10atan2PU(A, B) +#endif +#if GLOBAL_Q == 9 +#define _IQatan2PU(A, B) _IQ9atan2PU(A, B) +#endif +#if GLOBAL_Q == 8 +#define _IQatan2PU(A, B) _IQ8atan2PU(A, B) +#endif +#if GLOBAL_Q == 7 +#define _IQatan2PU(A, B) _IQ7atan2PU(A, B) +#endif +#if GLOBAL_Q == 6 +#define _IQatan2PU(A, B) _IQ6atan2PU(A, B) +#endif +#if GLOBAL_Q == 5 +#define _IQatan2PU(A, B) _IQ5atan2PU(A, B) +#endif +#if GLOBAL_Q == 4 +#define _IQatan2PU(A, B) _IQ4atan2PU(A, B) +#endif +#if GLOBAL_Q == 3 +#define _IQatan2PU(A, B) _IQ3atan2PU(A, B) +#endif +#if GLOBAL_Q == 2 +#define _IQatan2PU(A, B) _IQ2atan2PU(A, B) +#endif +#if GLOBAL_Q == 1 +#define _IQatan2PU(A, B) _IQ1atan2PU(A, B) +#endif + + +#define _IQ29atan(A) _IQ29atan2(A, _IQ29(1.0)) +#define _IQ28atan(A) _IQ28atan2(A, _IQ28(1.0)) +#define _IQ27atan(A) _IQ27atan2(A, _IQ27(1.0)) +#define _IQ26atan(A) _IQ26atan2(A, _IQ26(1.0)) +#define _IQ25atan(A) _IQ25atan2(A, _IQ25(1.0)) +#define _IQ24atan(A) _IQ24atan2(A, _IQ24(1.0)) +#define _IQ23atan(A) _IQ23atan2(A, _IQ23(1.0)) +#define _IQ22atan(A) _IQ22atan2(A, _IQ22(1.0)) +#define _IQ21atan(A) _IQ21atan2(A, _IQ21(1.0)) +#define _IQ20atan(A) _IQ20atan2(A, _IQ20(1.0)) +#define _IQ19atan(A) _IQ19atan2(A, _IQ19(1.0)) +#define _IQ18atan(A) _IQ18atan2(A, _IQ18(1.0)) +#define _IQ17atan(A) _IQ17atan2(A, _IQ17(1.0)) +#define _IQ16atan(A) _IQ16atan2(A, _IQ16(1.0)) +#define _IQ15atan(A) _IQ15atan2(A, _IQ15(1.0)) +#define _IQ14atan(A) _IQ14atan2(A, _IQ14(1.0)) +#define _IQ13atan(A) _IQ13atan2(A, _IQ13(1.0)) +#define _IQ12atan(A) _IQ12atan2(A, _IQ12(1.0)) +#define _IQ11atan(A) _IQ11atan2(A, _IQ11(1.0)) +#define _IQ10atan(A) _IQ10atan2(A, _IQ10(1.0)) +#define _IQ9atan(A) _IQ9atan2(A, _IQ9(1.0)) +#define _IQ8atan(A) _IQ8atan2(A, _IQ8(1.0)) +#define _IQ7atan(A) _IQ7atan2(A, _IQ7(1.0)) +#define _IQ6atan(A) _IQ6atan2(A, _IQ6(1.0)) +#define _IQ5atan(A) _IQ5atan2(A, _IQ5(1.0)) +#define _IQ4atan(A) _IQ4atan2(A, _IQ4(1.0)) +#define _IQ3atan(A) _IQ3atan2(A, _IQ3(1.0)) +#define _IQ2atan(A) _IQ2atan2(A, _IQ2(1.0)) +#define _IQ1atan(A) _IQ1atan2(A, _IQ1(1.0)) +/******************************************************************************* +* Function Name : _IQatan +* Description : IQ格式数的反正切函数,计算第1、4象限内的点:atan(A) +* Input : 参数A为IQ格式的数 +* Return : 返回值介于-pi/2和pi/2之间,与参数的IQ格式相同 +*******************************************************************************/ +#if GLOBAL_Q == 29 +#define _IQatan(A) _IQ29atan2(A, _IQ29(1.0)) +#endif +#if GLOBAL_Q == 28 +#define _IQatan(A) _IQ28atan2(A, _IQ28(1.0)) +#endif +#if GLOBAL_Q == 27 +#define _IQatan(A) _IQ27atan2(A, _IQ27(1.0)) +#endif +#if GLOBAL_Q == 26 +#define _IQatan(A) _IQ26atan2(A, _IQ26(1.0)) +#endif +#if GLOBAL_Q == 25 +#define _IQatan(A) _IQ25atan2(A, _IQ25(1.0)) +#endif +#if GLOBAL_Q == 24 +#define _IQatan(A) _IQ24atan2(A, _IQ24(1.0)) +#endif +#if GLOBAL_Q == 23 +#define _IQatan(A) _IQ23atan2(A, _IQ23(1.0)) +#endif +#if GLOBAL_Q == 22 +#define _IQatan(A) _IQ22atan2(A, _IQ22(1.0)) +#endif +#if GLOBAL_Q == 21 +#define _IQatan(A) _IQ21atan2(A, _IQ21(1.0)) +#endif +#if GLOBAL_Q == 20 +#define _IQatan(A) _IQ20atan2(A, _IQ20(1.0)) +#endif +#if GLOBAL_Q == 19 +#define _IQatan(A) _IQ19atan2(A, _IQ19(1.0)) +#endif +#if GLOBAL_Q == 18 +#define _IQatan(A) _IQ18atan2(A, _IQ18(1.0)) +#endif +#if GLOBAL_Q == 17 +#define _IQatan(A) _IQ17atan2(A, _IQ17(1.0)) +#endif +#if GLOBAL_Q == 16 +#define _IQatan(A) _IQ16atan2(A, _IQ16(1.0)) +#endif +#if GLOBAL_Q == 15 +#define _IQatan(A) _IQ15atan2(A, _IQ15(1.0)) +#endif +#if GLOBAL_Q == 14 +#define _IQatan(A) _IQ14atan2(A, _IQ14(1.0)) +#endif +#if GLOBAL_Q == 13 +#define _IQatan(A) _IQ13atan2(A, _IQ13(1.0)) +#endif +#if GLOBAL_Q == 12 +#define _IQatan(A) _IQ12atan2(A, _IQ12(1.0)) +#endif +#if GLOBAL_Q == 11 +#define _IQatan(A) _IQ11atan2(A, _IQ11(1.0)) +#endif +#if GLOBAL_Q == 10 +#define _IQatan(A) _IQ10atan2(A, _IQ10(1.0)) +#endif +#if GLOBAL_Q == 9 +#define _IQatan(A) _IQ9atan2(A, _IQ9(1.0)) +#endif +#if GLOBAL_Q == 8 +#define _IQatan(A) _IQ8atan2(A, _IQ8(1.0)) +#endif +#if GLOBAL_Q == 7 +#define _IQatan(A) _IQ7atan2(A, _IQ7(1.0)) +#endif +#if GLOBAL_Q == 6 +#define _IQatan(A) _IQ6atan2(A, _IQ6(1.0)) +#endif +#if GLOBAL_Q == 5 +#define _IQatan(A) _IQ5atan2(A, _IQ5(1.0)) +#endif +#if GLOBAL_Q == 4 +#define _IQatan(A) _IQ4atan2(A, _IQ4(1.0)) +#endif +#if GLOBAL_Q == 3 +#define _IQatan(A) _IQ3atan2(A, _IQ3(1.0)) +#endif +#if GLOBAL_Q == 2 +#define _IQatan(A) _IQ2atan2(A, _IQ2(1.0)) +#endif +#if GLOBAL_Q == 1 +#define _IQatan(A) _IQ1atan2(A, _IQ1(1.0)) +#endif + + +extern _iq30 _IQ30sqrt(_iq30 A); +extern _iq29 _IQ29sqrt(_iq29 A); +extern _iq28 _IQ28sqrt(_iq28 A); +extern _iq27 _IQ27sqrt(_iq27 A); +extern _iq26 _IQ26sqrt(_iq26 A); +extern _iq25 _IQ25sqrt(_iq25 A); +extern _iq24 _IQ24sqrt(_iq24 A); +extern _iq23 _IQ23sqrt(_iq23 A); +extern _iq22 _IQ22sqrt(_iq22 A); +extern _iq21 _IQ21sqrt(_iq21 A); +extern _iq20 _IQ20sqrt(_iq20 A); +extern _iq19 _IQ19sqrt(_iq19 A); +extern _iq18 _IQ18sqrt(_iq18 A); +extern _iq17 _IQ17sqrt(_iq17 A); +extern _iq16 _IQ16sqrt(_iq16 A); +extern _iq15 _IQ15sqrt(_iq15 A); +extern _iq14 _IQ14sqrt(_iq14 A); +extern _iq13 _IQ13sqrt(_iq13 A); +extern _iq12 _IQ12sqrt(_iq12 A); +extern _iq11 _IQ11sqrt(_iq11 A); +extern _iq10 _IQ10sqrt(_iq10 A); +extern _iq9 _IQ9sqrt(_iq9 A); +extern _iq8 _IQ8sqrt(_iq8 A); +extern _iq7 _IQ7sqrt(_iq7 A); +extern _iq6 _IQ6sqrt(_iq6 A); +extern _iq5 _IQ5sqrt(_iq5 A); +extern _iq4 _IQ4sqrt(_iq4 A); +extern _iq3 _IQ3sqrt(_iq3 A); +extern _iq2 _IQ2sqrt(_iq2 A); +extern _iq1 _IQ1sqrt(_iq1 A); +/******************************************************************************* +* Function Name : _IQsqrt +* Description : IQ格式数的平方根函数:A^(1/2) +* Input : 参数A为IQ格式的数 +* Return : 返回A的平方根值,与参数的IQ格式相同 +*******************************************************************************/ +#if GLOBAL_Q == 30 +#define _IQsqrt(A) _IQ30sqrt(A) +#endif +#if GLOBAL_Q == 29 +#define _IQsqrt(A) _IQ29sqrt(A) +#endif +#if GLOBAL_Q == 28 +#define _IQsqrt(A) _IQ28sqrt(A) +#endif +#if GLOBAL_Q == 27 +#define _IQsqrt(A) _IQ27sqrt(A) +#endif +#if GLOBAL_Q == 26 +#define _IQsqrt(A) _IQ26sqrt(A) +#endif +#if GLOBAL_Q == 25 +#define _IQsqrt(A) _IQ25sqrt(A) +#endif +#if GLOBAL_Q == 24 +#define _IQsqrt(A) _IQ24sqrt(A) +#endif +#if GLOBAL_Q == 23 +#define _IQsqrt(A) _IQ23sqrt(A) +#endif +#if GLOBAL_Q == 22 +#define _IQsqrt(A) _IQ22sqrt(A) +#endif +#if GLOBAL_Q == 21 +#define _IQsqrt(A) _IQ21sqrt(A) +#endif +#if GLOBAL_Q == 20 +#define _IQsqrt(A) _IQ20sqrt(A) +#endif +#if GLOBAL_Q == 19 +#define _IQsqrt(A) _IQ19sqrt(A) +#endif +#if GLOBAL_Q == 18 +#define _IQsqrt(A) _IQ18sqrt(A) +#endif +#if GLOBAL_Q == 17 +#define _IQsqrt(A) _IQ17sqrt(A) +#endif +#if GLOBAL_Q == 16 +#define _IQsqrt(A) _IQ16sqrt(A) +#endif +#if GLOBAL_Q == 15 +#define _IQsqrt(A) _IQ15sqrt(A) +#endif +#if GLOBAL_Q == 14 +#define _IQsqrt(A) _IQ14sqrt(A) +#endif +#if GLOBAL_Q == 13 +#define _IQsqrt(A) _IQ13sqrt(A) +#endif +#if GLOBAL_Q == 12 +#define _IQsqrt(A) _IQ12sqrt(A) +#endif +#if GLOBAL_Q == 11 +#define _IQsqrt(A) _IQ11sqrt(A) +#endif +#if GLOBAL_Q == 10 +#define _IQsqrt(A) _IQ10sqrt(A) +#endif +#if GLOBAL_Q == 9 +#define _IQsqrt(A) _IQ9sqrt(A) +#endif +#if GLOBAL_Q == 8 +#define _IQsqrt(A) _IQ8sqrt(A) +#endif +#if GLOBAL_Q == 7 +#define _IQsqrt(A) _IQ7sqrt(A) +#endif +#if GLOBAL_Q == 6 +#define _IQsqrt(A) _IQ6sqrt(A) +#endif +#if GLOBAL_Q == 5 +#define _IQsqrt(A) _IQ5sqrt(A) +#endif +#if GLOBAL_Q == 4 +#define _IQsqrt(A) _IQ4sqrt(A) +#endif +#if GLOBAL_Q == 3 +#define _IQsqrt(A) _IQ3sqrt(A) +#endif +#if GLOBAL_Q == 2 +#define _IQsqrt(A) _IQ2sqrt(A) +#endif +#if GLOBAL_Q == 1 +#define _IQsqrt(A) _IQ1sqrt(A) +#endif + + +extern _iq30 _IQ30isqrt(_iq30 A); +extern _iq29 _IQ29isqrt(_iq29 A); +extern _iq28 _IQ28isqrt(_iq28 A); +extern _iq27 _IQ27isqrt(_iq27 A); +extern _iq26 _IQ26isqrt(_iq26 A); +extern _iq25 _IQ25isqrt(_iq25 A); +extern _iq24 _IQ24isqrt(_iq24 A); +extern _iq23 _IQ23isqrt(_iq23 A); +extern _iq22 _IQ22isqrt(_iq22 A); +extern _iq21 _IQ21isqrt(_iq21 A); +extern _iq20 _IQ20isqrt(_iq20 A); +extern _iq19 _IQ19isqrt(_iq19 A); +extern _iq18 _IQ18isqrt(_iq18 A); +extern _iq17 _IQ17isqrt(_iq17 A); +extern _iq16 _IQ16isqrt(_iq16 A); +extern _iq15 _IQ15isqrt(_iq15 A); +extern _iq14 _IQ14isqrt(_iq14 A); +extern _iq13 _IQ13isqrt(_iq13 A); +extern _iq12 _IQ12isqrt(_iq12 A); +extern _iq11 _IQ11isqrt(_iq11 A); +extern _iq10 _IQ10isqrt(_iq10 A); +extern _iq9 _IQ9isqrt(_iq9 A); +extern _iq8 _IQ8isqrt(_iq8 A); +extern _iq7 _IQ7isqrt(_iq7 A); +extern _iq6 _IQ6isqrt(_iq6 A); +extern _iq5 _IQ5isqrt(_iq5 A); +extern _iq4 _IQ4isqrt(_iq4 A); +extern _iq3 _IQ3isqrt(_iq3 A); +extern _iq2 _IQ2isqrt(_iq2 A); +extern _iq1 _IQ1isqrt(_iq1 A); +/******************************************************************************* +* Function Name : _IQisqrt +* Description : IQ格式数的平方根倒数函数:A^(-1/2) +* Input : 参数A为IQ格式的数 +* Return : 返回A的平方根倒数值,与参数的IQ格式相同 +*******************************************************************************/ +#if GLOBAL_Q == 30 +#define _IQisqrt(A) _IQ30isqrt(A) +#endif +#if GLOBAL_Q == 29 +#define _IQisqrt(A) _IQ29isqrt(A) +#endif +#if GLOBAL_Q == 28 +#define _IQisqrt(A) _IQ28isqrt(A) +#endif +#if GLOBAL_Q == 27 +#define _IQisqrt(A) _IQ27isqrt(A) +#endif +#if GLOBAL_Q == 26 +#define _IQisqrt(A) _IQ26isqrt(A) +#endif +#if GLOBAL_Q == 25 +#define _IQisqrt(A) _IQ25isqrt(A) +#endif +#if GLOBAL_Q == 24 +#define _IQisqrt(A) _IQ24isqrt(A) +#endif +#if GLOBAL_Q == 23 +#define _IQisqrt(A) _IQ23isqrt(A) +#endif +#if GLOBAL_Q == 22 +#define _IQisqrt(A) _IQ22isqrt(A) +#endif +#if GLOBAL_Q == 21 +#define _IQisqrt(A) _IQ21isqrt(A) +#endif +#if GLOBAL_Q == 20 +#define _IQisqrt(A) _IQ20isqrt(A) +#endif +#if GLOBAL_Q == 19 +#define _IQisqrt(A) _IQ19isqrt(A) +#endif +#if GLOBAL_Q == 18 +#define _IQisqrt(A) _IQ18isqrt(A) +#endif +#if GLOBAL_Q == 17 +#define _IQisqrt(A) _IQ17isqrt(A) +#endif +#if GLOBAL_Q == 16 +#define _IQisqrt(A) _IQ16isqrt(A) +#endif +#if GLOBAL_Q == 15 +#define _IQisqrt(A) _IQ15isqrt(A) +#endif +#if GLOBAL_Q == 14 +#define _IQisqrt(A) _IQ14isqrt(A) +#endif +#if GLOBAL_Q == 13 +#define _IQisqrt(A) _IQ13isqrt(A) +#endif +#if GLOBAL_Q == 12 +#define _IQisqrt(A) _IQ12isqrt(A) +#endif +#if GLOBAL_Q == 11 +#define _IQisqrt(A) _IQ11isqrt(A) +#endif +#if GLOBAL_Q == 10 +#define _IQisqrt(A) _IQ10isqrt(A) +#endif +#if GLOBAL_Q == 9 +#define _IQisqrt(A) _IQ9isqrt(A) +#endif +#if GLOBAL_Q == 8 +#define _IQisqrt(A) _IQ8isqrt(A) +#endif +#if GLOBAL_Q == 7 +#define _IQisqrt(A) _IQ7isqrt(A) +#endif +#if GLOBAL_Q == 6 +#define _IQisqrt(A) _IQ6isqrt(A) +#endif +#if GLOBAL_Q == 5 +#define _IQisqrt(A) _IQ5isqrt(A) +#endif +#if GLOBAL_Q == 4 +#define _IQisqrt(A) _IQ4isqrt(A) +#endif +#if GLOBAL_Q == 3 +#define _IQisqrt(A) _IQ3isqrt(A) +#endif +#if GLOBAL_Q == 2 +#define _IQisqrt(A) _IQ2isqrt(A) +#endif +#if GLOBAL_Q == 1 +#define _IQisqrt(A) _IQ1isqrt(A) +#endif + + +extern _iq30 _IQ30exp(_iq30 A); +extern _iq29 _IQ29exp(_iq29 A); +extern _iq28 _IQ28exp(_iq28 A); +extern _iq27 _IQ27exp(_iq27 A); +extern _iq26 _IQ26exp(_iq26 A); +extern _iq25 _IQ25exp(_iq25 A); +extern _iq24 _IQ24exp(_iq24 A); +extern _iq23 _IQ23exp(_iq23 A); +extern _iq22 _IQ22exp(_iq22 A); +extern _iq21 _IQ21exp(_iq21 A); +extern _iq20 _IQ20exp(_iq20 A); +extern _iq19 _IQ19exp(_iq19 A); +extern _iq18 _IQ18exp(_iq18 A); +extern _iq17 _IQ17exp(_iq17 A); +extern _iq16 _IQ16exp(_iq16 A); +extern _iq15 _IQ15exp(_iq15 A); +extern _iq14 _IQ14exp(_iq14 A); +extern _iq13 _IQ13exp(_iq13 A); +extern _iq12 _IQ12exp(_iq12 A); +extern _iq11 _IQ11exp(_iq11 A); +extern _iq10 _IQ10exp(_iq10 A); +extern _iq9 _IQ9exp(_iq9 A); +extern _iq8 _IQ8exp(_iq8 A); +extern _iq7 _IQ7exp(_iq7 A); +extern _iq6 _IQ6exp(_iq6 A); +extern _iq5 _IQ5exp(_iq5 A); +extern _iq4 _IQ4exp(_iq4 A); +extern _iq3 _IQ3exp(_iq3 A); +extern _iq2 _IQ2exp(_iq2 A); +extern _iq1 _IQ1exp(_iq1 A); +/******************************************************************************* +* Function Name : _IQexp +* Description : IQ格式数以e为底的指数函数:e^A +* Input : 参数A为IQ格式的数 +* Return : 返回A以e为底的指数值,与参数的IQ格式相同 +*******************************************************************************/ +#if GLOBAL_Q == 30 +#define _IQexp(A) _IQ30exp(A) +#endif +#if GLOBAL_Q == 29 +#define _IQexp(A) _IQ29exp(A) +#endif +#if GLOBAL_Q == 28 +#define _IQexp(A) _IQ28exp(A) +#endif +#if GLOBAL_Q == 27 +#define _IQexp(A) _IQ27exp(A) +#endif +#if GLOBAL_Q == 26 +#define _IQexp(A) _IQ26exp(A) +#endif +#if GLOBAL_Q == 25 +#define _IQexp(A) _IQ25exp(A) +#endif +#if GLOBAL_Q == 24 +#define _IQexp(A) _IQ24exp(A) +#endif +#if GLOBAL_Q == 23 +#define _IQexp(A) _IQ23exp(A) +#endif +#if GLOBAL_Q == 22 +#define _IQexp(A) _IQ22exp(A) +#endif +#if GLOBAL_Q == 21 +#define _IQexp(A) _IQ21exp(A) +#endif +#if GLOBAL_Q == 20 +#define _IQexp(A) _IQ20exp(A) +#endif +#if GLOBAL_Q == 19 +#define _IQexp(A) _IQ19exp(A) +#endif +#if GLOBAL_Q == 18 +#define _IQexp(A) _IQ18exp(A) +#endif +#if GLOBAL_Q == 17 +#define _IQexp(A) _IQ17exp(A) +#endif +#if GLOBAL_Q == 16 +#define _IQexp(A) _IQ16exp(A) +#endif +#if GLOBAL_Q == 15 +#define _IQexp(A) _IQ15exp(A) +#endif +#if GLOBAL_Q == 14 +#define _IQexp(A) _IQ14exp(A) +#endif +#if GLOBAL_Q == 13 +#define _IQexp(A) _IQ13exp(A) +#endif +#if GLOBAL_Q == 12 +#define _IQexp(A) _IQ12exp(A) +#endif +#if GLOBAL_Q == 11 +#define _IQexp(A) _IQ11exp(A) +#endif +#if GLOBAL_Q == 10 +#define _IQexp(A) _IQ10exp(A) +#endif +#if GLOBAL_Q == 9 +#define _IQexp(A) _IQ9exp(A) +#endif +#if GLOBAL_Q == 8 +#define _IQexp(A) _IQ8exp(A) +#endif +#if GLOBAL_Q == 7 +#define _IQexp(A) _IQ7exp(A) +#endif +#if GLOBAL_Q == 6 +#define _IQexp(A) _IQ6exp(A) +#endif +#if GLOBAL_Q == 5 +#define _IQexp(A) _IQ5exp(A) +#endif +#if GLOBAL_Q == 4 +#define _IQexp(A) _IQ4exp(A) +#endif +#if GLOBAL_Q == 3 +#define _IQexp(A) _IQ3exp(A) +#endif +#if GLOBAL_Q == 2 +#define _IQexp(A) _IQ2exp(A) +#endif +#if GLOBAL_Q == 1 +#define _IQexp(A) _IQ1exp(A) +#endif + + +extern _iq30 _IQ30exp2(_iq30 A); +extern _iq29 _IQ29exp2(_iq29 A); +extern _iq28 _IQ28exp2(_iq28 A); +extern _iq27 _IQ27exp2(_iq27 A); +extern _iq26 _IQ26exp2(_iq26 A); +extern _iq25 _IQ25exp2(_iq25 A); +extern _iq24 _IQ24exp2(_iq24 A); +extern _iq23 _IQ23exp2(_iq23 A); +extern _iq22 _IQ22exp2(_iq22 A); +extern _iq21 _IQ21exp2(_iq21 A); +extern _iq20 _IQ20exp2(_iq20 A); +extern _iq19 _IQ19exp2(_iq19 A); +extern _iq18 _IQ18exp2(_iq18 A); +extern _iq17 _IQ17exp2(_iq17 A); +extern _iq16 _IQ16exp2(_iq16 A); +extern _iq15 _IQ15exp2(_iq15 A); +extern _iq14 _IQ14exp2(_iq14 A); +extern _iq13 _IQ13exp2(_iq13 A); +extern _iq12 _IQ12exp2(_iq12 A); +extern _iq11 _IQ11exp2(_iq11 A); +extern _iq10 _IQ10exp2(_iq10 A); +extern _iq9 _IQ9exp2(_iq9 A); +extern _iq8 _IQ8exp2(_iq8 A); +extern _iq7 _IQ7exp2(_iq7 A); +extern _iq6 _IQ6exp2(_iq6 A); +extern _iq5 _IQ5exp2(_iq5 A); +extern _iq4 _IQ4exp2(_iq4 A); +extern _iq3 _IQ3exp2(_iq3 A); +extern _iq2 _IQ2exp2(_iq2 A); +extern _iq1 _IQ1exp2(_iq1 A); +/******************************************************************************* +* Function Name : _IQexp2 +* Description : IQ格式数以2为底的指数函数:2^A +* Input : 参数A为IQ格式的数 +* Return : 返回A以2为底的指数值,与参数的IQ格式相同 +*******************************************************************************/ +#if GLOBAL_Q == 30 +#define _IQexp2(A) _IQ30exp2(A) +#endif +#if GLOBAL_Q == 29 +#define _IQexp2(A) _IQ29exp2(A) +#endif +#if GLOBAL_Q == 28 +#define _IQexp2(A) _IQ28exp2(A) +#endif +#if GLOBAL_Q == 27 +#define _IQexp2(A) _IQ27exp2(A) +#endif +#if GLOBAL_Q == 26 +#define _IQexp2(A) _IQ26exp2(A) +#endif +#if GLOBAL_Q == 25 +#define _IQexp2(A) _IQ25exp2(A) +#endif +#if GLOBAL_Q == 24 +#define _IQexp2(A) _IQ24exp2(A) +#endif +#if GLOBAL_Q == 23 +#define _IQexp2(A) _IQ23exp2(A) +#endif +#if GLOBAL_Q == 22 +#define _IQexp2(A) _IQ22exp2(A) +#endif +#if GLOBAL_Q == 21 +#define _IQexp2(A) _IQ21exp2(A) +#endif +#if GLOBAL_Q == 20 +#define _IQexp2(A) _IQ20exp2(A) +#endif +#if GLOBAL_Q == 19 +#define _IQexp2(A) _IQ19exp2(A) +#endif +#if GLOBAL_Q == 18 +#define _IQexp2(A) _IQ18exp2(A) +#endif +#if GLOBAL_Q == 17 +#define _IQexp2(A) _IQ17exp2(A) +#endif +#if GLOBAL_Q == 16 +#define _IQexp2(A) _IQ16exp2(A) +#endif +#if GLOBAL_Q == 15 +#define _IQexp2(A) _IQ15exp2(A) +#endif +#if GLOBAL_Q == 14 +#define _IQexp2(A) _IQ14exp2(A) +#endif +#if GLOBAL_Q == 13 +#define _IQexp2(A) _IQ13exp2(A) +#endif +#if GLOBAL_Q == 12 +#define _IQexp2(A) _IQ12exp2(A) +#endif +#if GLOBAL_Q == 11 +#define _IQexp2(A) _IQ11exp2(A) +#endif +#if GLOBAL_Q == 10 +#define _IQexp2(A) _IQ10exp2(A) +#endif +#if GLOBAL_Q == 9 +#define _IQexp2(A) _IQ9exp2(A) +#endif +#if GLOBAL_Q == 8 +#define _IQexp2(A) _IQ8exp2(A) +#endif +#if GLOBAL_Q == 7 +#define _IQexp2(A) _IQ7exp2(A) +#endif +#if GLOBAL_Q == 6 +#define _IQexp2(A) _IQ6exp2(A) +#endif +#if GLOBAL_Q == 5 +#define _IQexp2(A) _IQ5exp2(A) +#endif +#if GLOBAL_Q == 4 +#define _IQexp2(A) _IQ4exp2(A) +#endif +#if GLOBAL_Q == 3 +#define _IQexp2(A) _IQ3exp2(A) +#endif +#if GLOBAL_Q == 2 +#define _IQexp2(A) _IQ2exp2(A) +#endif +#if GLOBAL_Q == 1 +#define _IQexp2(A) _IQ1exp2(A) +#endif + + +#define _IQ30int(A) ((A) >> 30) +#define _IQ29int(A) ((A) >> 29) +#define _IQ28int(A) ((A) >> 28) +#define _IQ27int(A) ((A) >> 27) +#define _IQ26int(A) ((A) >> 26) +#define _IQ25int(A) ((A) >> 25) +#define _IQ24int(A) ((A) >> 24) +#define _IQ23int(A) ((A) >> 23) +#define _IQ22int(A) ((A) >> 22) +#define _IQ21int(A) ((A) >> 21) +#define _IQ20int(A) ((A) >> 20) +#define _IQ19int(A) ((A) >> 19) +#define _IQ18int(A) ((A) >> 18) +#define _IQ17int(A) ((A) >> 17) +#define _IQ16int(A) ((A) >> 16) +#define _IQ15int(A) ((A) >> 15) +#define _IQ14int(A) ((A) >> 14) +#define _IQ13int(A) ((A) >> 13) +#define _IQ12int(A) ((A) >> 12) +#define _IQ11int(A) ((A) >> 11) +#define _IQ10int(A) ((A) >> 10) +#define _IQ9int(A) ((A) >> 9) +#define _IQ8int(A) ((A) >> 8) +#define _IQ7int(A) ((A) >> 7) +#define _IQ6int(A) ((A) >> 6) +#define _IQ5int(A) ((A) >> 5) +#define _IQ4int(A) ((A) >> 4) +#define _IQ3int(A) ((A) >> 3) +#define _IQ2int(A) ((A) >> 2) +#define _IQ1int(A) ((A) >> 1) +/******************************************************************************* +* Function Name : _IQint +* Description : 计算IQ格式数的整数部分 +* Input : 参数A为IQ格式的数 +* Return : 返回A整数部分 +*******************************************************************************/ +#define _IQint(A) ((A) >> GLOBAL_Q) + + +extern _iq30 _IQ30frac(_iq30 A); +extern _iq29 _IQ29frac(_iq29 A); +extern _iq28 _IQ28frac(_iq28 A); +extern _iq27 _IQ27frac(_iq27 A); +extern _iq26 _IQ26frac(_iq26 A); +extern _iq25 _IQ25frac(_iq25 A); +extern _iq24 _IQ24frac(_iq24 A); +extern _iq23 _IQ23frac(_iq23 A); +extern _iq22 _IQ22frac(_iq22 A); +extern _iq21 _IQ21frac(_iq21 A); +extern _iq20 _IQ20frac(_iq20 A); +extern _iq19 _IQ19frac(_iq19 A); +extern _iq18 _IQ18frac(_iq18 A); +extern _iq17 _IQ17frac(_iq17 A); +extern _iq16 _IQ16frac(_iq16 A); +extern _iq15 _IQ15frac(_iq15 A); +extern _iq14 _IQ14frac(_iq14 A); +extern _iq13 _IQ13frac(_iq13 A); +extern _iq12 _IQ12frac(_iq12 A); +extern _iq11 _IQ11frac(_iq11 A); +extern _iq10 _IQ10frac(_iq10 A); +extern _iq9 _IQ9frac(_iq9 A); +extern _iq8 _IQ8frac(_iq8 A); +extern _iq7 _IQ7frac(_iq7 A); +extern _iq6 _IQ6frac(_iq6 A); +extern _iq5 _IQ5frac(_iq5 A); +extern _iq4 _IQ4frac(_iq4 A); +extern _iq3 _IQ3frac(_iq3 A); +extern _iq2 _IQ2frac(_iq2 A); +extern _iq1 _IQ1frac(_iq1 A); +/******************************************************************************* +* Function Name : _IQfrac +* Description : 计算IQ格式数的小数部分 +* Input : 参数A为IQ格式的数 +* Return : 返回A小数部分,与参数的IQ格式相同 +*******************************************************************************/ +#if GLOBAL_Q == 30 +#define _IQfrac(A) _IQ30frac(A) +#endif +#if GLOBAL_Q == 29 +#define _IQfrac(A) _IQ29frac(A) +#endif +#if GLOBAL_Q == 28 +#define _IQfrac(A) _IQ28frac(A) +#endif +#if GLOBAL_Q == 27 +#define _IQfrac(A) _IQ27frac(A) +#endif +#if GLOBAL_Q == 26 +#define _IQfrac(A) _IQ26frac(A) +#endif +#if GLOBAL_Q == 25 +#define _IQfrac(A) _IQ25frac(A) +#endif +#if GLOBAL_Q == 24 +#define _IQfrac(A) _IQ24frac(A) +#endif +#if GLOBAL_Q == 23 +#define _IQfrac(A) _IQ23frac(A) +#endif +#if GLOBAL_Q == 22 +#define _IQfrac(A) _IQ22frac(A) +#endif +#if GLOBAL_Q == 21 +#define _IQfrac(A) _IQ21frac(A) +#endif +#if GLOBAL_Q == 20 +#define _IQfrac(A) _IQ20frac(A) +#endif +#if GLOBAL_Q == 19 +#define _IQfrac(A) _IQ19frac(A) +#endif +#if GLOBAL_Q == 18 +#define _IQfrac(A) _IQ18frac(A) +#endif +#if GLOBAL_Q == 17 +#define _IQfrac(A) _IQ17frac(A) +#endif +#if GLOBAL_Q == 16 +#define _IQfrac(A) _IQ16frac(A) +#endif +#if GLOBAL_Q == 15 +#define _IQfrac(A) _IQ15frac(A) +#endif +#if GLOBAL_Q == 14 +#define _IQfrac(A) _IQ14frac(A) +#endif +#if GLOBAL_Q == 13 +#define _IQfrac(A) _IQ13frac(A) +#endif +#if GLOBAL_Q == 12 +#define _IQfrac(A) _IQ12frac(A) +#endif +#if GLOBAL_Q == 11 +#define _IQfrac(A) _IQ11frac(A) +#endif +#if GLOBAL_Q == 10 +#define _IQfrac(A) _IQ10frac(A) +#endif +#if GLOBAL_Q == 9 +#define _IQfrac(A) _IQ9frac(A) +#endif +#if GLOBAL_Q == 8 +#define _IQfrac(A) _IQ8frac(A) +#endif +#if GLOBAL_Q == 7 +#define _IQfrac(A) _IQ7frac(A) +#endif +#if GLOBAL_Q == 6 +#define _IQfrac(A) _IQ6frac(A) +#endif +#if GLOBAL_Q == 5 +#define _IQfrac(A) _IQ5frac(A) +#endif +#if GLOBAL_Q == 4 +#define _IQfrac(A) _IQ4frac(A) +#endif +#if GLOBAL_Q == 3 +#define _IQfrac(A) _IQ3frac(A) +#endif +#if GLOBAL_Q == 2 +#define _IQfrac(A) _IQ2frac(A) +#endif +#if GLOBAL_Q == 1 +#define _IQfrac(A) _IQ1frac(A) +#endif + +extern long __IQxmpy(long A, long B, long S); +#define _IQ30mpyIQX(A, IQA, B, IQB) __IQxmpy(A, B, 30 + 32 - (IQA) - (IQB)) +#define _IQ29mpyIQX(A, IQA, B, IQB) __IQxmpy(A, B, 29 + 32 - (IQA) - (IQB)) +#define _IQ28mpyIQX(A, IQA, B, IQB) __IQxmpy(A, B, 28 + 32 - (IQA) - (IQB)) +#define _IQ27mpyIQX(A, IQA, B, IQB) __IQxmpy(A, B, 27 + 32 - (IQA) - (IQB)) +#define _IQ26mpyIQX(A, IQA, B, IQB) __IQxmpy(A, B, 26 + 32 - (IQA) - (IQB)) +#define _IQ25mpyIQX(A, IQA, B, IQB) __IQxmpy(A, B, 25 + 32 - (IQA) - (IQB)) +#define _IQ24mpyIQX(A, IQA, B, IQB) __IQxmpy(A, B, 24 + 32 - (IQA) - (IQB)) +#define _IQ23mpyIQX(A, IQA, B, IQB) __IQxmpy(A, B, 23 + 32 - (IQA) - (IQB)) +#define _IQ22mpyIQX(A, IQA, B, IQB) __IQxmpy(A, B, 22 + 32 - (IQA) - (IQB)) +#define _IQ21mpyIQX(A, IQA, B, IQB) __IQxmpy(A, B, 21 + 32 - (IQA) - (IQB)) +#define _IQ20mpyIQX(A, IQA, B, IQB) __IQxmpy(A, B, 20 + 32 - (IQA) - (IQB)) +#define _IQ19mpyIQX(A, IQA, B, IQB) __IQxmpy(A, B, 19 + 32 - (IQA) - (IQB)) +#define _IQ18mpyIQX(A, IQA, B, IQB) __IQxmpy(A, B, 18 + 32 - (IQA) - (IQB)) +#define _IQ17mpyIQX(A, IQA, B, IQB) __IQxmpy(A, B, 17 + 32 - (IQA) - (IQB)) +#define _IQ16mpyIQX(A, IQA, B, IQB) __IQxmpy(A, B, 16 + 32 - (IQA) - (IQB)) +#define _IQ15mpyIQX(A, IQA, B, IQB) __IQxmpy(A, B, 15 + 32 - (IQA) - (IQB)) +#define _IQ14mpyIQX(A, IQA, B, IQB) __IQxmpy(A, B, 14 + 32 - (IQA) - (IQB)) +#define _IQ13mpyIQX(A, IQA, B, IQB) __IQxmpy(A, B, 13 + 32 - (IQA) - (IQB)) +#define _IQ12mpyIQX(A, IQA, B, IQB) __IQxmpy(A, B, 12 + 32 - (IQA) - (IQB)) +#define _IQ11mpyIQX(A, IQA, B, IQB) __IQxmpy(A, B, 11 + 32 - (IQA) - (IQB)) +#define _IQ10mpyIQX(A, IQA, B, IQB) __IQxmpy(A, B, 10 + 32 - (IQA) - (IQB)) +#define _IQ9mpyIQX(A, IQA, B, IQB) __IQxmpy(A, B, 9 + 32 - (IQA) - (IQB)) +#define _IQ8mpyIQX(A, IQA, B, IQB) __IQxmpy(A, B, 8 + 32 - (IQA) - (IQB)) +#define _IQ7mpyIQX(A, IQA, B, IQB) __IQxmpy(A, B, 7 + 32 - (IQA) - (IQB)) +#define _IQ6mpyIQX(A, IQA, B, IQB) __IQxmpy(A, B, 6 + 32 - (IQA) - (IQB)) +#define _IQ5mpyIQX(A, IQA, B, IQB) __IQxmpy(A, B, 5 + 32 - (IQA) - (IQB)) +#define _IQ4mpyIQX(A, IQA, B, IQB) __IQxmpy(A, B, 4 + 32 - (IQA) - (IQB)) +#define _IQ3mpyIQX(A, IQA, B, IQB) __IQxmpy(A, B, 3 + 32 - (IQA) - (IQB)) +#define _IQ2mpyIQX(A, IQA, B, IQB) __IQxmpy(A, B, 2 + 32 - (IQA) - (IQB)) +#define _IQ1mpyIQX(A, IQA, B, IQB) __IQxmpy(A, B, 1 + 32 - (IQA) - (IQB)) +/******************************************************************************* +* Function Name : _IQmpyIQX +* Description : 2个任意IQ格式数乘积 +* Input : A:IQ格式数。IQA:A的IQ精度 +* Input : B:IQ格式数。IQB:B的IQ精度 +* Return : 返回A与B的乘积,与GLOBAL_Q指定的IQ格式相同 +*******************************************************************************/ +#define _IQmpyIQX(A, IQA, B, IQB) __IQxmpy(A, B, \ + (GLOBAL_Q) + 32 - (IQA) - (IQB)) + + +#define _IQ30mpyI32(A, B) ((A) * (B)) +#define _IQ29mpyI32(A, B) ((A) * (B)) +#define _IQ28mpyI32(A, B) ((A) * (B)) +#define _IQ27mpyI32(A, B) ((A) * (B)) +#define _IQ26mpyI32(A, B) ((A) * (B)) +#define _IQ25mpyI32(A, B) ((A) * (B)) +#define _IQ24mpyI32(A, B) ((A) * (B)) +#define _IQ23mpyI32(A, B) ((A) * (B)) +#define _IQ22mpyI32(A, B) ((A) * (B)) +#define _IQ21mpyI32(A, B) ((A) * (B)) +#define _IQ20mpyI32(A, B) ((A) * (B)) +#define _IQ19mpyI32(A, B) ((A) * (B)) +#define _IQ18mpyI32(A, B) ((A) * (B)) +#define _IQ17mpyI32(A, B) ((A) * (B)) +#define _IQ16mpyI32(A, B) ((A) * (B)) +#define _IQ15mpyI32(A, B) ((A) * (B)) +#define _IQ14mpyI32(A, B) ((A) * (B)) +#define _IQ13mpyI32(A, B) ((A) * (B)) +#define _IQ12mpyI32(A, B) ((A) * (B)) +#define _IQ11mpyI32(A, B) ((A) * (B)) +#define _IQ10mpyI32(A, B) ((A) * (B)) +#define _IQ9mpyI32(A, B) ((A) * (B)) +#define _IQ8mpyI32(A, B) ((A) * (B)) +#define _IQ7mpyI32(A, B) ((A) * (B)) +#define _IQ6mpyI32(A, B) ((A) * (B)) +#define _IQ5mpyI32(A, B) ((A) * (B)) +#define _IQ4mpyI32(A, B) ((A) * (B)) +#define _IQ3mpyI32(A, B) ((A) * (B)) +#define _IQ2mpyI32(A, B) ((A) * (B)) +#define _IQ1mpyI32(A, B) ((A) * (B)) +/******************************************************************************* +* Function Name : _IQmpyI32 +* Description : IQ格式数乘以整数 +* Input : A:IQ格式数。B:整数 +* Return : 返回A与B的乘积,与参数A的IQ格式相同 +*******************************************************************************/ +#define _IQmpyI32(A, B) ((A) * (B)) + +extern _iq30 _IQ30mpyI32int(_iq30 A, long B); +extern _iq29 _IQ29mpyI32int(_iq29 A, long B); +extern _iq28 _IQ28mpyI32int(_iq28 A, long B); +extern _iq27 _IQ27mpyI32int(_iq27 A, long B); +extern _iq26 _IQ26mpyI32int(_iq26 A, long B); +extern _iq25 _IQ25mpyI32int(_iq25 A, long B); +extern _iq24 _IQ24mpyI32int(_iq24 A, long B); +extern _iq23 _IQ23mpyI32int(_iq23 A, long B); +extern _iq22 _IQ22mpyI32int(_iq22 A, long B); +extern _iq21 _IQ21mpyI32int(_iq21 A, long B); +extern _iq20 _IQ20mpyI32int(_iq20 A, long B); +extern _iq19 _IQ19mpyI32int(_iq19 A, long B); +extern _iq18 _IQ18mpyI32int(_iq18 A, long B); +extern _iq17 _IQ17mpyI32int(_iq17 A, long B); +extern _iq16 _IQ16mpyI32int(_iq16 A, long B); +extern _iq15 _IQ15mpyI32int(_iq15 A, long B); +extern _iq14 _IQ14mpyI32int(_iq14 A, long B); +extern _iq13 _IQ13mpyI32int(_iq13 A, long B); +extern _iq12 _IQ12mpyI32int(_iq12 A, long B); +extern _iq11 _IQ11mpyI32int(_iq11 A, long B); +extern _iq10 _IQ10mpyI32int(_iq10 A, long B); +extern _iq9 _IQ9mpyI32int(_iq9 A, long B); +extern _iq8 _IQ8mpyI32int(_iq8 A, long B); +extern _iq7 _IQ7mpyI32int(_iq7 A, long B); +extern _iq6 _IQ6mpyI32int(_iq6 A, long B); +extern _iq5 _IQ5mpyI32int(_iq5 A, long B); +extern _iq4 _IQ4mpyI32int(_iq4 A, long B); +extern _iq3 _IQ3mpyI32int(_iq3 A, long B); +extern _iq2 _IQ2mpyI32int(_iq2 A, long B); +extern _iq1 _IQ1mpyI32int(_iq1 A, long B); +/******************************************************************************* +* Function Name : _IQmpyI32int +* Description : IQ格式数乘以整数 +* Input : A:IQ格式数。B:整数 +* Return : 返回A与B乘积的整数部分 +*******************************************************************************/ +#if GLOBAL_Q == 30 +#define _IQmpyI32int(A, B) _IQ30mpyI32int(A, B) +#endif +#if GLOBAL_Q == 29 +#define _IQmpyI32int(A, B) _IQ29mpyI32int(A, B) +#endif +#if GLOBAL_Q == 28 +#define _IQmpyI32int(A, B) _IQ28mpyI32int(A, B) +#endif +#if GLOBAL_Q == 27 +#define _IQmpyI32int(A, B) _IQ27mpyI32int(A, B) +#endif +#if GLOBAL_Q == 26 +#define _IQmpyI32int(A, B) _IQ26mpyI32int(A, B) +#endif +#if GLOBAL_Q == 25 +#define _IQmpyI32int(A, B) _IQ25mpyI32int(A, B) +#endif +#if GLOBAL_Q == 24 +#define _IQmpyI32int(A, B) _IQ24mpyI32int(A, B) +#endif +#if GLOBAL_Q == 23 +#define _IQmpyI32int(A, B) _IQ23mpyI32int(A, B) +#endif +#if GLOBAL_Q == 22 +#define _IQmpyI32int(A, B) _IQ22mpyI32int(A, B) +#endif +#if GLOBAL_Q == 21 +#define _IQmpyI32int(A, B) _IQ21mpyI32int(A, B) +#endif +#if GLOBAL_Q == 20 +#define _IQmpyI32int(A, B) _IQ20mpyI32int(A, B) +#endif +#if GLOBAL_Q == 19 +#define _IQmpyI32int(A, B) _IQ19mpyI32int(A, B) +#endif +#if GLOBAL_Q == 18 +#define _IQmpyI32int(A, B) _IQ18mpyI32int(A, B) +#endif +#if GLOBAL_Q == 17 +#define _IQmpyI32int(A, B) _IQ17mpyI32int(A, B) +#endif +#if GLOBAL_Q == 16 +#define _IQmpyI32int(A, B) _IQ16mpyI32int(A, B) +#endif +#if GLOBAL_Q == 15 +#define _IQmpyI32int(A, B) _IQ15mpyI32int(A, B) +#endif +#if GLOBAL_Q == 14 +#define _IQmpyI32int(A, B) _IQ14mpyI32int(A, B) +#endif +#if GLOBAL_Q == 13 +#define _IQmpyI32int(A, B) _IQ13mpyI32int(A, B) +#endif +#if GLOBAL_Q == 12 +#define _IQmpyI32int(A, B) _IQ12mpyI32int(A, B) +#endif +#if GLOBAL_Q == 11 +#define _IQmpyI32int(A, B) _IQ11mpyI32int(A, B) +#endif +#if GLOBAL_Q == 10 +#define _IQmpyI32int(A, B) _IQ10mpyI32int(A, B) +#endif +#if GLOBAL_Q == 9 +#define _IQmpyI32int(A, B) _IQ9mpyI32int(A, B) +#endif +#if GLOBAL_Q == 8 +#define _IQmpyI32int(A, B) _IQ8mpyI32int(A, B) +#endif +#if GLOBAL_Q == 7 +#define _IQmpyI32int(A, B) _IQ7mpyI32int(A, B) +#endif +#if GLOBAL_Q == 6 +#define _IQmpyI32int(A, B) _IQ6mpyI32int(A, B) +#endif +#if GLOBAL_Q == 5 +#define _IQmpyI32int(A, B) _IQ5mpyI32int(A, B) +#endif +#if GLOBAL_Q == 4 +#define _IQmpyI32int(A, B) _IQ4mpyI32int(A, B) +#endif +#if GLOBAL_Q == 3 +#define _IQmpyI32int(A, B) _IQ3mpyI32int(A, B) +#endif +#if GLOBAL_Q == 2 +#define _IQmpyI32int(A, B) _IQ2mpyI32int(A, B) +#endif +#if GLOBAL_Q == 1 +#define _IQmpyI32int(A, B) _IQ1mpyI32int(A, B) +#endif + +extern _iq30 _IQ30mpyI32frac(_iq30 A, long B); +extern _iq29 _IQ29mpyI32frac(_iq29 A, long B); +extern _iq28 _IQ28mpyI32frac(_iq28 A, long B); +extern _iq27 _IQ27mpyI32frac(_iq27 A, long B); +extern _iq26 _IQ26mpyI32frac(_iq26 A, long B); +extern _iq25 _IQ25mpyI32frac(_iq25 A, long B); +extern _iq24 _IQ24mpyI32frac(_iq24 A, long B); +extern _iq23 _IQ23mpyI32frac(_iq23 A, long B); +extern _iq22 _IQ22mpyI32frac(_iq22 A, long B); +extern _iq21 _IQ21mpyI32frac(_iq21 A, long B); +extern _iq20 _IQ20mpyI32frac(_iq20 A, long B); +extern _iq19 _IQ19mpyI32frac(_iq19 A, long B); +extern _iq18 _IQ18mpyI32frac(_iq18 A, long B); +extern _iq17 _IQ17mpyI32frac(_iq17 A, long B); +extern _iq16 _IQ16mpyI32frac(_iq16 A, long B); +extern _iq15 _IQ15mpyI32frac(_iq15 A, long B); +extern _iq14 _IQ14mpyI32frac(_iq14 A, long B); +extern _iq13 _IQ13mpyI32frac(_iq13 A, long B); +extern _iq12 _IQ12mpyI32frac(_iq12 A, long B); +extern _iq11 _IQ11mpyI32frac(_iq11 A, long B); +extern _iq10 _IQ10mpyI32frac(_iq10 A, long B); +extern _iq9 _IQ9mpyI32frac(_iq9 A, long B); +extern _iq8 _IQ8mpyI32frac(_iq8 A, long B); +extern _iq7 _IQ7mpyI32frac(_iq7 A, long B); +extern _iq6 _IQ6mpyI32frac(_iq6 A, long B); +extern _iq5 _IQ5mpyI32frac(_iq5 A, long B); +extern _iq4 _IQ4mpyI32frac(_iq4 A, long B); +extern _iq3 _IQ3mpyI32frac(_iq3 A, long B); +extern _iq2 _IQ2mpyI32frac(_iq2 A, long B); +extern _iq1 _IQ1mpyI32frac(_iq1 A, long B); +/******************************************************************************* +* Function Name : _IQmpyI32frac +* Description : IQ格式数乘以整数 +* Input : A:IQ格式数。B:整数 +* Return : 返回乘积的小数部分,与参数A的IQ格式相同 +*******************************************************************************/ +#if GLOBAL_Q == 30 +#define _IQmpyI32frac(A, B) _IQ30mpyI32frac(A, B) +#endif +#if GLOBAL_Q == 29 +#define _IQmpyI32frac(A, B) _IQ29mpyI32frac(A, B) +#endif +#if GLOBAL_Q == 28 +#define _IQmpyI32frac(A, B) _IQ28mpyI32frac(A, B) +#endif +#if GLOBAL_Q == 27 +#define _IQmpyI32frac(A, B) _IQ27mpyI32frac(A, B) +#endif +#if GLOBAL_Q == 26 +#define _IQmpyI32frac(A, B) _IQ26mpyI32frac(A, B) +#endif +#if GLOBAL_Q == 25 +#define _IQmpyI32frac(A, B) _IQ25mpyI32frac(A, B) +#endif +#if GLOBAL_Q == 24 +#define _IQmpyI32frac(A, B) _IQ24mpyI32frac(A, B) +#endif +#if GLOBAL_Q == 23 +#define _IQmpyI32frac(A, B) _IQ23mpyI32frac(A, B) +#endif +#if GLOBAL_Q == 22 +#define _IQmpyI32frac(A, B) _IQ22mpyI32frac(A, B) +#endif +#if GLOBAL_Q == 21 +#define _IQmpyI32frac(A, B) _IQ21mpyI32frac(A, B) +#endif +#if GLOBAL_Q == 20 +#define _IQmpyI32frac(A, B) _IQ20mpyI32frac(A, B) +#endif +#if GLOBAL_Q == 19 +#define _IQmpyI32frac(A, B) _IQ19mpyI32frac(A, B) +#endif +#if GLOBAL_Q == 18 +#define _IQmpyI32frac(A, B) _IQ18mpyI32frac(A, B) +#endif +#if GLOBAL_Q == 17 +#define _IQmpyI32frac(A, B) _IQ17mpyI32frac(A, B) +#endif +#if GLOBAL_Q == 16 +#define _IQmpyI32frac(A, B) _IQ16mpyI32frac(A, B) +#endif +#if GLOBAL_Q == 15 +#define _IQmpyI32frac(A, B) _IQ15mpyI32frac(A, B) +#endif +#if GLOBAL_Q == 14 +#define _IQmpyI32frac(A, B) _IQ14mpyI32frac(A, B) +#endif +#if GLOBAL_Q == 13 +#define _IQmpyI32frac(A, B) _IQ13mpyI32frac(A, B) +#endif +#if GLOBAL_Q == 12 +#define _IQmpyI32frac(A, B) _IQ12mpyI32frac(A, B) +#endif +#if GLOBAL_Q == 11 +#define _IQmpyI32frac(A, B) _IQ11mpyI32frac(A, B) +#endif +#if GLOBAL_Q == 10 +#define _IQmpyI32frac(A, B) _IQ10mpyI32frac(A, B) +#endif +#if GLOBAL_Q == 9 +#define _IQmpyI32frac(A, B) _IQ9mpyI32frac(A, B) +#endif +#if GLOBAL_Q == 8 +#define _IQmpyI32frac(A, B) _IQ8mpyI32frac(A, B) +#endif +#if GLOBAL_Q == 7 +#define _IQmpyI32frac(A, B) _IQ7mpyI32frac(A, B) +#endif +#if GLOBAL_Q == 6 +#define _IQmpyI32frac(A, B) _IQ6mpyI32frac(A, B) +#endif +#if GLOBAL_Q == 5 +#define _IQmpyI32frac(A, B) _IQ5mpyI32frac(A, B) +#endif +#if GLOBAL_Q == 4 +#define _IQmpyI32frac(A, B) _IQ4mpyI32frac(A, B) +#endif +#if GLOBAL_Q == 3 +#define _IQmpyI32frac(A, B) _IQ3mpyI32frac(A, B) +#endif +#if GLOBAL_Q == 2 +#define _IQmpyI32frac(A, B) _IQ2mpyI32frac(A, B) +#endif +#if GLOBAL_Q == 1 +#define _IQmpyI32frac(A, B) _IQ1mpyI32frac(A, B) +#endif + +extern _iq30 _IQ30mag(_iq30 A, _iq30 B); +extern _iq29 _IQ29mag(_iq29 A, _iq29 B); +extern _iq28 _IQ28mag(_iq28 A, _iq28 B); +extern _iq27 _IQ27mag(_iq27 A, _iq27 B); +extern _iq26 _IQ26mag(_iq26 A, _iq26 B); +extern _iq25 _IQ25mag(_iq25 A, _iq25 B); +extern _iq24 _IQ24mag(_iq24 A, _iq24 B); +extern _iq23 _IQ23mag(_iq23 A, _iq23 B); +extern _iq22 _IQ22mag(_iq22 A, _iq22 B); +extern _iq21 _IQ21mag(_iq21 A, _iq21 B); +extern _iq20 _IQ20mag(_iq20 A, _iq20 B); +extern _iq19 _IQ19mag(_iq19 A, _iq19 B); +extern _iq18 _IQ18mag(_iq18 A, _iq18 B); +extern _iq17 _IQ17mag(_iq17 A, _iq17 B); +extern _iq16 _IQ16mag(_iq16 A, _iq16 B); +extern _iq15 _IQ15mag(_iq15 A, _iq15 B); +extern _iq14 _IQ14mag(_iq14 A, _iq14 B); +extern _iq13 _IQ13mag(_iq13 A, _iq13 B); +extern _iq12 _IQ12mag(_iq12 A, _iq12 B); +extern _iq11 _IQ11mag(_iq11 A, _iq11 B); +extern _iq10 _IQ10mag(_iq10 A, _iq10 B); +extern _iq9 _IQ9mag(_iq9 A, _iq9 B); +extern _iq8 _IQ8mag(_iq8 A, _iq8 B); +extern _iq7 _IQ7mag(_iq7 A, _iq7 B); +extern _iq6 _IQ6mag(_iq6 A, _iq6 B); +extern _iq5 _IQ5mag(_iq5 A, _iq5 B); +extern _iq4 _IQ4mag(_iq4 A, _iq4 B); +extern _iq3 _IQ3mag(_iq3 A, _iq3 B); +extern _iq2 _IQ2mag(_iq2 A, _iq2 B); +extern _iq1 _IQ1mag(_iq1 A, _iq1 B); +/******************************************************************************* +* Function Name : _IQmag +* Description : IQ格式数的的求模函数:(A*A+B*B)^(1/2) +* Input : 参数A、B为IQ格式的数 +* Return : 返回原点与点(A,B)之间的长度值,与参数的IQ格式相同 +*******************************************************************************/ +#if GLOBAL_Q == 30 +#define _IQmag(A, B) _IQ30mag(A, B) +#endif +#if GLOBAL_Q == 29 +#define _IQmag(A, B) _IQ29mag(A, B) +#endif +#if GLOBAL_Q == 28 +#define _IQmag(A, B) _IQ28mag(A, B) +#endif +#if GLOBAL_Q == 27 +#define _IQmag(A, B) _IQ27mag(A, B) +#endif +#if GLOBAL_Q == 26 +#define _IQmag(A, B) _IQ26mag(A, B) +#endif +#if GLOBAL_Q == 25 +#define _IQmag(A, B) _IQ25mag(A, B) +#endif +#if GLOBAL_Q == 24 +#define _IQmag(A, B) _IQ24mag(A, B) +#endif +#if GLOBAL_Q == 23 +#define _IQmag(A, B) _IQ23mag(A, B) +#endif +#if GLOBAL_Q == 22 +#define _IQmag(A, B) _IQ22mag(A, B) +#endif +#if GLOBAL_Q == 21 +#define _IQmag(A, B) _IQ21mag(A, B) +#endif +#if GLOBAL_Q == 20 +#define _IQmag(A, B) _IQ20mag(A, B) +#endif +#if GLOBAL_Q == 19 +#define _IQmag(A, B) _IQ19mag(A, B) +#endif +#if GLOBAL_Q == 18 +#define _IQmag(A, B) _IQ18mag(A, B) +#endif +#if GLOBAL_Q == 17 +#define _IQmag(A, B) _IQ17mag(A, B) +#endif +#if GLOBAL_Q == 16 +#define _IQmag(A, B) _IQ16mag(A, B) +#endif +#if GLOBAL_Q == 15 +#define _IQmag(A, B) _IQ15mag(A, B) +#endif +#if GLOBAL_Q == 14 +#define _IQmag(A, B) _IQ14mag(A, B) +#endif +#if GLOBAL_Q == 13 +#define _IQmag(A, B) _IQ13mag(A, B) +#endif +#if GLOBAL_Q == 12 +#define _IQmag(A, B) _IQ12mag(A, B) +#endif +#if GLOBAL_Q == 11 +#define _IQmag(A, B) _IQ11mag(A, B) +#endif +#if GLOBAL_Q == 10 +#define _IQmag(A, B) _IQ10mag(A, B) +#endif +#if GLOBAL_Q == 9 +#define _IQmag(A, B) _IQ9mag(A, B) +#endif +#if GLOBAL_Q == 8 +#define _IQmag(A, B) _IQ8mag(A, B) +#endif +#if GLOBAL_Q == 7 +#define _IQmag(A, B) _IQ7mag(A, B) +#endif +#if GLOBAL_Q == 6 +#define _IQmag(A, B) _IQ6mag(A, B) +#endif +#if GLOBAL_Q == 5 +#define _IQmag(A, B) _IQ5mag(A, B) +#endif +#if GLOBAL_Q == 4 +#define _IQmag(A, B) _IQ4mag(A, B) +#endif +#if GLOBAL_Q == 3 +#define _IQmag(A, B) _IQ3mag(A, B) +#endif +#if GLOBAL_Q == 2 +#define _IQmag(A, B) _IQ2mag(A, B) +#endif +#if GLOBAL_Q == 1 +#define _IQmag(A, B) _IQ1mag(A, B) +#endif + + +extern _iq _atoIQN(const char *A, long B); +#define _atoIQ30(A) _atoIQN(A, 30) +#define _atoIQ29(A) _atoIQN(A, 29) +#define _atoIQ28(A) _atoIQN(A, 28) +#define _atoIQ27(A) _atoIQN(A, 27) +#define _atoIQ26(A) _atoIQN(A, 26) +#define _atoIQ25(A) _atoIQN(A, 25) +#define _atoIQ24(A) _atoIQN(A, 24) +#define _atoIQ23(A) _atoIQN(A, 23) +#define _atoIQ22(A) _atoIQN(A, 22) +#define _atoIQ21(A) _atoIQN(A, 21) +#define _atoIQ20(A) _atoIQN(A, 20) +#define _atoIQ19(A) _atoIQN(A, 19) +#define _atoIQ18(A) _atoIQN(A, 18) +#define _atoIQ17(A) _atoIQN(A, 17) +#define _atoIQ16(A) _atoIQN(A, 16) +#define _atoIQ15(A) _atoIQN(A, 15) +#define _atoIQ14(A) _atoIQN(A, 14) +#define _atoIQ13(A) _atoIQN(A, 13) +#define _atoIQ12(A) _atoIQN(A, 12) +#define _atoIQ11(A) _atoIQN(A, 11) +#define _atoIQ10(A) _atoIQN(A, 10) +#define _atoIQ9(A) _atoIQN(A, 9) +#define _atoIQ8(A) _atoIQN(A, 8) +#define _atoIQ7(A) _atoIQN(A, 7) +#define _atoIQ6(A) _atoIQN(A, 6) +#define _atoIQ5(A) _atoIQN(A, 5) +#define _atoIQ4(A) _atoIQN(A, 4) +#define _atoIQ3(A) _atoIQN(A, 3) +#define _atoIQ2(A) _atoIQN(A, 2) +#define _atoIQ1(A) _atoIQN(A, 1) +/******************************************************************************* +* Function Name : _atoIQ +* Description : 将一个字符串转换成IQ格式数。 +* Input : 参数A为一个字符串 +* Return : 返回IQ格式数 +*******************************************************************************/ +#define _atoIQ(A) _atoIQN(A, GLOBAL_Q) + +extern int __IQNtoa(char *A, const char *B, _iq C, int D); +#define _IQ30toa(A, B, C) __IQNtoa(A, B, C, 30); +#define _IQ29toa(A, B, C) __IQNtoa(A, B, C, 29); +#define _IQ28toa(A, B, C) __IQNtoa(A, B, C, 28); +#define _IQ27toa(A, B, C) __IQNtoa(A, B, C, 27); +#define _IQ26toa(A, B, C) __IQNtoa(A, B, C, 26); +#define _IQ25toa(A, B, C) __IQNtoa(A, B, C, 25); +#define _IQ24toa(A, B, C) __IQNtoa(A, B, C, 24); +#define _IQ23toa(A, B, C) __IQNtoa(A, B, C, 23); +#define _IQ22toa(A, B, C) __IQNtoa(A, B, C, 22); +#define _IQ21toa(A, B, C) __IQNtoa(A, B, C, 21); +#define _IQ20toa(A, B, C) __IQNtoa(A, B, C, 20); +#define _IQ19toa(A, B, C) __IQNtoa(A, B, C, 19); +#define _IQ18toa(A, B, C) __IQNtoa(A, B, C, 18); +#define _IQ17toa(A, B, C) __IQNtoa(A, B, C, 17); +#define _IQ16toa(A, B, C) __IQNtoa(A, B, C, 16); +#define _IQ15toa(A, B, C) __IQNtoa(A, B, C, 15); +#define _IQ14toa(A, B, C) __IQNtoa(A, B, C, 14); +#define _IQ13toa(A, B, C) __IQNtoa(A, B, C, 13); +#define _IQ12toa(A, B, C) __IQNtoa(A, B, C, 12); +#define _IQ11toa(A, B, C) __IQNtoa(A, B, C, 11); +#define _IQ10toa(A, B, C) __IQNtoa(A, B, C, 10); +#define _IQ9toa(A, B, C) __IQNtoa(A, B, C, 9); +#define _IQ8toa(A, B, C) __IQNtoa(A, B, C, 8); +#define _IQ7toa(A, B, C) __IQNtoa(A, B, C, 7); +#define _IQ6toa(A, B, C) __IQNtoa(A, B, C, 6); +#define _IQ5toa(A, B, C) __IQNtoa(A, B, C, 5); +#define _IQ4toa(A, B, C) __IQNtoa(A, B, C, 4); +#define _IQ3toa(A, B, C) __IQNtoa(A, B, C, 3); +#define _IQ2toa(A, B, C) __IQNtoa(A, B, C, 2); +#define _IQ1toa(A, B, C) __IQNtoa(A, B, C, 1); +/******************************************************************************* +* Function Name : _IQtoa +* Description : 将IQ格式数转换成一个字符串。 +* Input : A:存放转换结果的缓冲区。 +* : B:格式化输出参数"%I.Qf",I和Q分别代表整数、小数部分的10进制个数。 +* : 例如,"%7.8f"打印整数部分7个10进制数,小数部分打印8个10进制数。 +* : C:要转换的IQ格式数。 +* Return : 返回C的字符串形式。 +*******************************************************************************/ +#define _IQtoa(A, B, C) __IQNtoa(A, B, C, GLOBAL_Q) + + +#define _IQ30abs(A) (((A) < 0) ? - (A) : (A)) +#define _IQ29abs(A) (((A) < 0) ? - (A) : (A)) +#define _IQ28abs(A) (((A) < 0) ? - (A) : (A)) +#define _IQ27abs(A) (((A) < 0) ? - (A) : (A)) +#define _IQ26abs(A) (((A) < 0) ? - (A) : (A)) +#define _IQ25abs(A) (((A) < 0) ? - (A) : (A)) +#define _IQ24abs(A) (((A) < 0) ? - (A) : (A)) +#define _IQ23abs(A) (((A) < 0) ? - (A) : (A)) +#define _IQ22abs(A) (((A) < 0) ? - (A) : (A)) +#define _IQ21abs(A) (((A) < 0) ? - (A) : (A)) +#define _IQ20abs(A) (((A) < 0) ? - (A) : (A)) +#define _IQ19abs(A) (((A) < 0) ? - (A) : (A)) +#define _IQ18abs(A) (((A) < 0) ? - (A) : (A)) +#define _IQ17abs(A) (((A) < 0) ? - (A) : (A)) +#define _IQ16abs(A) (((A) < 0) ? - (A) : (A)) +#define _IQ15abs(A) (((A) < 0) ? - (A) : (A)) +#define _IQ14abs(A) (((A) < 0) ? - (A) : (A)) +#define _IQ13abs(A) (((A) < 0) ? - (A) : (A)) +#define _IQ12abs(A) (((A) < 0) ? - (A) : (A)) +#define _IQ11abs(A) (((A) < 0) ? - (A) : (A)) +#define _IQ10abs(A) (((A) < 0) ? - (A) : (A)) +#define _IQ9abs(A) (((A) < 0) ? - (A) : (A)) +#define _IQ8abs(A) (((A) < 0) ? - (A) : (A)) +#define _IQ7abs(A) (((A) < 0) ? - (A) : (A)) +#define _IQ6abs(A) (((A) < 0) ? - (A) : (A)) +#define _IQ5abs(A) (((A) < 0) ? - (A) : (A)) +#define _IQ4abs(A) (((A) < 0) ? - (A) : (A)) +#define _IQ3abs(A) (((A) < 0) ? - (A) : (A)) +#define _IQ2abs(A) (((A) < 0) ? - (A) : (A)) +#define _IQ1abs(A) (((A) < 0) ? - (A) : (A)) +/******************************************************************************* +* Function Name : _IQabs +* Description : IQ格式数的绝对值函数:|A| +* Input : 参数A为IQ格式的数 +* Return : 返回A的绝对值,与参数的IQ格式相同 +*******************************************************************************/ +#define _IQabs(A) (((A) < 0) ? - (A) : (A)) + + +#else // MATH_TYPE == FLOAT_MATH + + +typedef float _iq30; +typedef float _iq29; +typedef float _iq28; +typedef float _iq27; +typedef float _iq26; +typedef float _iq25; +typedef float _iq24; +typedef float _iq23; +typedef float _iq22; +typedef float _iq21; +typedef float _iq20; +typedef float _iq19; +typedef float _iq18; +typedef float _iq17; +typedef float _iq16; +typedef float _iq15; +typedef float _iq14; +typedef float _iq13; +typedef float _iq12; +typedef float _iq11; +typedef float _iq10; +typedef float _iq9; +typedef float _iq8; +typedef float _iq7; +typedef float _iq6; +typedef float _iq5; +typedef float _iq4; +typedef float _iq3; +typedef float _iq2; +typedef float _iq1; +typedef float _iq; + + +#define _IQmpy2(A) ((A) * 2.0) +#define _IQmpy4(A) ((A) * 4.0) +#define _IQmpy8(A) ((A) * 8.0) +#define _IQmpy16(A) ((A) * 16.0) +#define _IQmpy32(A) ((A) * 32.0) +#define _IQmpy64(A) ((A) * 64.0) +#define _IQmpy128(A) ((A) * 128.0) +#define _IQmpy256(A) ((A) * 256.0) +#define _IQmpy512(A) ((A) * 512.0) +#define _IQdiv2(A) ((A) / 2.0) +#define _IQdiv4(A) ((A) / 4.0) +#define _IQdiv8(A) ((A) / 8.0) +#define _IQdiv16(A) ((A) / 16.0) +#define _IQdiv32(A) ((A) / 32.0) +#define _IQdiv64(A) ((A) / 64.0) +#define _IQdiv128(A) ((A) / 128.0) +#define _IQdiv256(A) ((A) / 256.0) +#define _IQdiv512(A) ((A) / 512.0) + +#define _IQ30(A) (A) +#define _IQ29(A) (A) +#define _IQ28(A) (A) +#define _IQ27(A) (A) +#define _IQ26(A) (A) +#define _IQ25(A) (A) +#define _IQ24(A) (A) +#define _IQ23(A) (A) +#define _IQ22(A) (A) +#define _IQ21(A) (A) +#define _IQ20(A) (A) +#define _IQ19(A) (A) +#define _IQ18(A) (A) +#define _IQ17(A) (A) +#define _IQ16(A) (A) +#define _IQ15(A) (A) +#define _IQ14(A) (A) +#define _IQ13(A) (A) +#define _IQ12(A) (A) +#define _IQ11(A) (A) +#define _IQ10(A) (A) +#define _IQ9(A) (A) +#define _IQ8(A) (A) +#define _IQ7(A) (A) +#define _IQ6(A) (A) +#define _IQ5(A) (A) +#define _IQ4(A) (A) +#define _IQ3(A) (A) +#define _IQ2(A) (A) +#define _IQ1(A) (A) +#define _IQ(A) (A) + + +#define _IQ30toF(A) (A) +#define _IQ29toF(A) (A) +#define _IQ28toF(A) (A) +#define _IQ27toF(A) (A) +#define _IQ26toF(A) (A) +#define _IQ25toF(A) (A) +#define _IQ24toF(A) (A) +#define _IQ23toF(A) (A) +#define _IQ22toF(A) (A) +#define _IQ21toF(A) (A) +#define _IQ20toF(A) (A) +#define _IQ19toF(A) (A) +#define _IQ18toF(A) (A) +#define _IQ17toF(A) (A) +#define _IQ16toF(A) (A) +#define _IQ15toF(A) (A) +#define _IQ14toF(A) (A) +#define _IQ13toF(A) (A) +#define _IQ12toF(A) (A) +#define _IQ11toF(A) (A) +#define _IQ10toF(A) (A) +#define _IQ9toF(A) (A) +#define _IQ8toF(A) (A) +#define _IQ7toF(A) (A) +#define _IQ6toF(A) (A) +#define _IQ5toF(A) (A) +#define _IQ4toF(A) (A) +#define _IQ3toF(A) (A) +#define _IQ2toF(A) (A) +#define _IQ1toF(A) (A) +#define _IQtoF(A) (A) + + +#define _IQ30toD(A) (A) +#define _IQ29toD(A) (A) +#define _IQ28toD(A) (A) +#define _IQ27toD(A) (A) +#define _IQ26toD(A) (A) +#define _IQ25toD(A) (A) +#define _IQ24toD(A) (A) +#define _IQ23toD(A) (A) +#define _IQ22toD(A) (A) +#define _IQ21toD(A) (A) +#define _IQ20toD(A) (A) +#define _IQ19toD(A) (A) +#define _IQ18toD(A) (A) +#define _IQ17toD(A) (A) +#define _IQ16toD(A) (A) +#define _IQ15toD(A) (A) +#define _IQ14toD(A) (A) +#define _IQ13toD(A) (A) +#define _IQ12toD(A) (A) +#define _IQ11toD(A) (A) +#define _IQ10toD(A) (A) +#define _IQ9toD(A) (A) +#define _IQ8toD(A) (A) +#define _IQ7toD(A) (A) +#define _IQ6toD(A) (A) +#define _IQ5toD(A) (A) +#define _IQ4toD(A) (A) +#define _IQ3toD(A) (A) +#define _IQ2toD(A) (A) +#define _IQ1toD(A) (A) +#define _IQtoD(A) (A) + + +#define _IQsat(A, Pos, Neg) (((A) > (Pos)) ? \ + (Pos) : \ + (((A) < (Neg)) ? (Neg) : (A))) + + +#define _IQtoIQ30(A) (A) +#define _IQ30toIQ(A) (A) +#define _IQtoIQ29(A) (A) +#define _IQ29toIQ(A) (A) +#define _IQtoIQ28(A) (A) +#define _IQ28toIQ(A) (A) +#define _IQtoIQ27(A) (A) +#define _IQ27toIQ(A) (A) +#define _IQtoIQ26(A) (A) +#define _IQ26toIQ(A) (A) +#define _IQtoIQ25(A) (A) +#define _IQ25toIQ(A) (A) +#define _IQtoIQ24(A) (A) +#define _IQ24toIQ(A) (A) +#define _IQtoIQ23(A) (A) +#define _IQ23toIQ(A) (A) +#define _IQtoIQ22(A) (A) +#define _IQ22toIQ(A) (A) +#define _IQtoIQ21(A) (A) +#define _IQ21toIQ(A) (A) +#define _IQtoIQ20(A) (A) +#define _IQ20toIQ(A) (A) +#define _IQtoIQ19(A) (A) +#define _IQ19toIQ(A) (A) +#define _IQtoIQ18(A) (A) +#define _IQ18toIQ(A) (A) +#define _IQtoIQ17(A) (A) +#define _IQ17toIQ(A) (A) +#define _IQtoIQ16(A) (A) +#define _IQ16toIQ(A) (A) +#define _IQtoIQ15(A) (A) +#define _IQ15toIQ(A) (A) +#define _IQtoIQ14(A) (A) +#define _IQ14toIQ(A) (A) +#define _IQtoIQ13(A) (A) +#define _IQ13toIQ(A) (A) +#define _IQtoIQ12(A) (A) +#define _IQ12toIQ(A) (A) +#define _IQtoIQ11(A) (A) +#define _IQ11toIQ(A) (A) +#define _IQtoIQ10(A) (A) +#define _IQ10toIQ(A) (A) +#define _IQtoIQ9(A) (A) +#define _IQ9toIQ(A) (A) +#define _IQtoIQ8(A) (A) +#define _IQ8toIQ(A) (A) +#define _IQtoIQ7(A) (A) +#define _IQ7toIQ(A) (A) +#define _IQtoIQ6(A) (A) +#define _IQ6toIQ(A) (A) +#define _IQtoIQ5(A) (A) +#define _IQ5toIQ(A) (A) +#define _IQtoIQ4(A) (A) +#define _IQ4toIQ(A) (A) +#define _IQtoIQ3(A) (A) +#define _IQ3toIQ(A) (A) +#define _IQtoIQ2(A) (A) +#define _IQ2toIQ(A) (A) +#define _IQtoIQ1(A) (A) +#define _IQ1toIQ(A) (A) + +#define _IQtoQ15(A) ((short)((long)((A) * (1 << 15)))) +#define _Q15toIQ(A) (((float)(A)) * (1.0 / (1 << 15))) +#define _IQtoQ14(A) ((short)((long)((A) * (1 << 14)))) +#define _Q14toIQ(A) (((float)(A)) * (1.0 / (1 << 14))) +#define _IQtoQ13(A) ((short)((long)((A) * (1 << 13)))) +#define _Q13toIQ(A) (((float)(A)) * (1.0 / (1 << 13))) +#define _IQtoQ12(A) ((short)((long)((A) * (1 << 12)))) +#define _Q12toIQ(A) (((float)(A)) * (1.0 / (1 << 12))) +#define _IQtoQ11(A) ((short)((long)((A) * (1 << 11)))) +#define _Q11toIQ(A) (((float)(A)) * (1.0 / (1 << 11))) +#define _IQtoQ10(A) ((short)((long)((A) * (1 << 10)))) +#define _Q10toIQ(A) (((float)(A)) * (1.0 / (1 << 10))) +#define _IQtoQ9(A) ((short)((long)((A) * (1 << 9)))) +#define _Q9toIQ(A) (((float)(A)) * (1.0 / (1 << 9))) +#define _IQtoQ8(A) ((short)((long)((A) * (1 << 8)))) +#define _Q8toIQ(A) (((float)(A)) * (1.0 / (1 << 8))) +#define _IQtoQ7(A) ((short)((long)((A) * (1 << 7)))) +#define _Q7toIQ(A) (((float)(A)) * (1.0 / (1 << 7))) +#define _IQtoQ6(A) ((short)((long)((A) * (1 << 6)))) +#define _Q6toIQ(A) (((float)(A)) * (1.0 / (1 << 6))) +#define _IQtoQ5(A) ((short)((long)((A) * (1 << 5)))) +#define _Q5toIQ(A) (((float)(A)) * (1.0 / (1 << 5))) +#define _IQtoQ4(A) ((short)((long)((A) * (1 << 4)))) +#define _Q4toIQ(A) (((float)(A)) * (1.0 / (1 << 4))) +#define _IQtoQ3(A) ((short)((long)((A) * (1 << 3)))) +#define _Q3toIQ(A) (((float)(A)) * (1.0 / (1 << 3))) +#define _IQtoQ2(A) ((short)((long)((A) * (1 << 2)))) +#define _Q2toIQ(A) (((float)(A)) * (1.0 / (1 << 2))) +#define _IQtoQ1(A) ((short)((long)((A) * (1 << 1)))) +#define _Q1toIQ(A) (((float)(A)) * (1.0 / (1 << 1))) + +#define _IQ30mpy(A, B) ((A) * (B)) +#define _IQ29mpy(A, B) ((A) * (B)) +#define _IQ28mpy(A, B) ((A) * (B)) +#define _IQ27mpy(A, B) ((A) * (B)) +#define _IQ26mpy(A, B) ((A) * (B)) +#define _IQ25mpy(A, B) ((A) * (B)) +#define _IQ24mpy(A, B) ((A) * (B)) +#define _IQ23mpy(A, B) ((A) * (B)) +#define _IQ22mpy(A, B) ((A) * (B)) +#define _IQ21mpy(A, B) ((A) * (B)) +#define _IQ20mpy(A, B) ((A) * (B)) +#define _IQ19mpy(A, B) ((A) * (B)) +#define _IQ18mpy(A, B) ((A) * (B)) +#define _IQ17mpy(A, B) ((A) * (B)) +#define _IQ16mpy(A, B) ((A) * (B)) +#define _IQ15mpy(A, B) ((A) * (B)) +#define _IQ14mpy(A, B) ((A) * (B)) +#define _IQ13mpy(A, B) ((A) * (B)) +#define _IQ12mpy(A, B) ((A) * (B)) +#define _IQ11mpy(A, B) ((A) * (B)) +#define _IQ10mpy(A, B) ((A) * (B)) +#define _IQ9mpy(A, B) ((A) * (B)) +#define _IQ8mpy(A, B) ((A) * (B)) +#define _IQ7mpy(A, B) ((A) * (B)) +#define _IQ6mpy(A, B) ((A) * (B)) +#define _IQ5mpy(A, B) ((A) * (B)) +#define _IQ4mpy(A, B) ((A) * (B)) +#define _IQ3mpy(A, B) ((A) * (B)) +#define _IQ2mpy(A, B) ((A) * (B)) +#define _IQ1mpy(A, B) ((A) * (B)) +#define _IQmpy(A, B) ((A) * (B)) + + +#define _IQ30rmpy(A, B) ((A) * (B)) +#define _IQ29rmpy(A, B) ((A) * (B)) +#define _IQ28rmpy(A, B) ((A) * (B)) +#define _IQ27rmpy(A, B) ((A) * (B)) +#define _IQ26rmpy(A, B) ((A) * (B)) +#define _IQ25rmpy(A, B) ((A) * (B)) +#define _IQ24rmpy(A, B) ((A) * (B)) +#define _IQ23rmpy(A, B) ((A) * (B)) +#define _IQ22rmpy(A, B) ((A) * (B)) +#define _IQ21rmpy(A, B) ((A) * (B)) +#define _IQ20rmpy(A, B) ((A) * (B)) +#define _IQ19rmpy(A, B) ((A) * (B)) +#define _IQ18rmpy(A, B) ((A) * (B)) +#define _IQ17rmpy(A, B) ((A) * (B)) +#define _IQ16rmpy(A, B) ((A) * (B)) +#define _IQ15rmpy(A, B) ((A) * (B)) +#define _IQ14rmpy(A, B) ((A) * (B)) +#define _IQ13rmpy(A, B) ((A) * (B)) +#define _IQ12rmpy(A, B) ((A) * (B)) +#define _IQ11rmpy(A, B) ((A) * (B)) +#define _IQ10rmpy(A, B) ((A) * (B)) +#define _IQ9rmpy(A, B) ((A) * (B)) +#define _IQ8rmpy(A, B) ((A) * (B)) +#define _IQ7rmpy(A, B) ((A) * (B)) +#define _IQ6rmpy(A, B) ((A) * (B)) +#define _IQ5rmpy(A, B) ((A) * (B)) +#define _IQ4rmpy(A, B) ((A) * (B)) +#define _IQ3rmpy(A, B) ((A) * (B)) +#define _IQ2rmpy(A, B) ((A) * (B)) +#define _IQ1rmpy(A, B) ((A) * (B)) +#define _IQrmpy(A, B) ((A) * (B)) + + +#define _IQ30rsmpy(A, B) ((A) * (B)) +#define _IQ29rsmpy(A, B) ((A) * (B)) +#define _IQ28rsmpy(A, B) ((A) * (B)) +#define _IQ27rsmpy(A, B) ((A) * (B)) +#define _IQ26rsmpy(A, B) ((A) * (B)) +#define _IQ25rsmpy(A, B) ((A) * (B)) +#define _IQ24rsmpy(A, B) ((A) * (B)) +#define _IQ23rsmpy(A, B) ((A) * (B)) +#define _IQ22rsmpy(A, B) ((A) * (B)) +#define _IQ21rsmpy(A, B) ((A) * (B)) +#define _IQ20rsmpy(A, B) ((A) * (B)) +#define _IQ19rsmpy(A, B) ((A) * (B)) +#define _IQ18rsmpy(A, B) ((A) * (B)) +#define _IQ17rsmpy(A, B) ((A) * (B)) +#define _IQ16rsmpy(A, B) ((A) * (B)) +#define _IQ15rsmpy(A, B) ((A) * (B)) +#define _IQ14rsmpy(A, B) ((A) * (B)) +#define _IQ13rsmpy(A, B) ((A) * (B)) +#define _IQ12rsmpy(A, B) ((A) * (B)) +#define _IQ11rsmpy(A, B) ((A) * (B)) +#define _IQ10rsmpy(A, B) ((A) * (B)) +#define _IQ9rsmpy(A, B) ((A) * (B)) +#define _IQ8rsmpy(A, B) ((A) * (B)) +#define _IQ7rsmpy(A, B) ((A) * (B)) +#define _IQ6rsmpy(A, B) ((A) * (B)) +#define _IQ5rsmpy(A, B) ((A) * (B)) +#define _IQ4rsmpy(A, B) ((A) * (B)) +#define _IQ3rsmpy(A, B) ((A) * (B)) +#define _IQ2rsmpy(A, B) ((A) * (B)) +#define _IQ1rsmpy(A, B) ((A) * (B)) +#define _IQrsmpy(A, B) ((A) * (B)) + + +#define _IQ30div(A, B) ((A) / (B)) +#define _IQ29div(A, B) ((A) / (B)) +#define _IQ28div(A, B) ((A) / (B)) +#define _IQ27div(A, B) ((A) / (B)) +#define _IQ26div(A, B) ((A) / (B)) +#define _IQ25div(A, B) ((A) / (B)) +#define _IQ24div(A, B) ((A) / (B)) +#define _IQ23div(A, B) ((A) / (B)) +#define _IQ22div(A, B) ((A) / (B)) +#define _IQ21div(A, B) ((A) / (B)) +#define _IQ20div(A, B) ((A) / (B)) +#define _IQ19div(A, B) ((A) / (B)) +#define _IQ18div(A, B) ((A) / (B)) +#define _IQ17div(A, B) ((A) / (B)) +#define _IQ16div(A, B) ((A) / (B)) +#define _IQ15div(A, B) ((A) / (B)) +#define _IQ14div(A, B) ((A) / (B)) +#define _IQ13div(A, B) ((A) / (B)) +#define _IQ12div(A, B) ((A) / (B)) +#define _IQ11div(A, B) ((A) / (B)) +#define _IQ10div(A, B) ((A) / (B)) +#define _IQ9div(A, B) ((A) / (B)) +#define _IQ8div(A, B) ((A) / (B)) +#define _IQ7div(A, B) ((A) / (B)) +#define _IQ6div(A, B) ((A) / (B)) +#define _IQ5div(A, B) ((A) / (B)) +#define _IQ4div(A, B) ((A) / (B)) +#define _IQ3div(A, B) ((A) / (B)) +#define _IQ2div(A, B) ((A) / (B)) +#define _IQ1div(A, B) ((A) / (B)) +#define _IQdiv(A, B) ((A) / (B)) + + +#define _IQ29sin(A) sin(A) +#define _IQ28sin(A) sin(A) +#define _IQ27sin(A) sin(A) +#define _IQ26sin(A) sin(A) +#define _IQ25sin(A) sin(A) +#define _IQ24sin(A) sin(A) +#define _IQ23sin(A) sin(A) +#define _IQ22sin(A) sin(A) +#define _IQ21sin(A) sin(A) +#define _IQ20sin(A) sin(A) +#define _IQ19sin(A) sin(A) +#define _IQ18sin(A) sin(A) +#define _IQ17sin(A) sin(A) +#define _IQ16sin(A) sin(A) +#define _IQ15sin(A) sin(A) +#define _IQ14sin(A) sin(A) +#define _IQ13sin(A) sin(A) +#define _IQ12sin(A) sin(A) +#define _IQ11sin(A) sin(A) +#define _IQ10sin(A) sin(A) +#define _IQ9sin(A) sin(A) +#define _IQ8sin(A) sin(A) +#define _IQ7sin(A) sin(A) +#define _IQ6sin(A) sin(A) +#define _IQ5sin(A) sin(A) +#define _IQ4sin(A) sin(A) +#define _IQ3sin(A) sin(A) +#define _IQ2sin(A) sin(A) +#define _IQ1sin(A) sin(A) +#define _IQsin(A) sin(A) + + +#define _IQ30sinPU(A) sin((A) * 6.283185307) +#define _IQ29sinPU(A) sin((A) * 6.283185307) +#define _IQ28sinPU(A) sin((A) * 6.283185307) +#define _IQ27sinPU(A) sin((A) * 6.283185307) +#define _IQ26sinPU(A) sin((A) * 6.283185307) +#define _IQ25sinPU(A) sin((A) * 6.283185307) +#define _IQ24sinPU(A) sin((A) * 6.283185307) +#define _IQ23sinPU(A) sin((A) * 6.283185307) +#define _IQ22sinPU(A) sin((A) * 6.283185307) +#define _IQ21sinPU(A) sin((A) * 6.283185307) +#define _IQ20sinPU(A) sin((A) * 6.283185307) +#define _IQ19sinPU(A) sin((A) * 6.283185307) +#define _IQ18sinPU(A) sin((A) * 6.283185307) +#define _IQ17sinPU(A) sin((A) * 6.283185307) +#define _IQ16sinPU(A) sin((A) * 6.283185307) +#define _IQ15sinPU(A) sin((A) * 6.283185307) +#define _IQ14sinPU(A) sin((A) * 6.283185307) +#define _IQ13sinPU(A) sin((A) * 6.283185307) +#define _IQ12sinPU(A) sin((A) * 6.283185307) +#define _IQ11sinPU(A) sin((A) * 6.283185307) +#define _IQ10sinPU(A) sin((A) * 6.283185307) +#define _IQ9sinPU(A) sin((A) * 6.283185307) +#define _IQ8sinPU(A) sin((A) * 6.283185307) +#define _IQ7sinPU(A) sin((A) * 6.283185307) +#define _IQ6sinPU(A) sin((A) * 6.283185307) +#define _IQ5sinPU(A) sin((A) * 6.283185307) +#define _IQ4sinPU(A) sin((A) * 6.283185307) +#define _IQ3sinPU(A) sin((A) * 6.283185307) +#define _IQ2sinPU(A) sin((A) * 6.283185307) +#define _IQ1sinPU(A) sin((A) * 6.283185307) +#define _IQsinPU(A) sin((A) * 6.283185307) + + +#define _IQ29asin(A) asin(A) +#define _IQ28asin(A) asin(A) +#define _IQ27asin(A) asin(A) +#define _IQ26asin(A) asin(A) +#define _IQ25asin(A) asin(A) +#define _IQ24asin(A) asin(A) +#define _IQ23asin(A) asin(A) +#define _IQ22asin(A) asin(A) +#define _IQ21asin(A) asin(A) +#define _IQ20asin(A) asin(A) +#define _IQ19asin(A) asin(A) +#define _IQ18asin(A) asin(A) +#define _IQ17asin(A) asin(A) +#define _IQ16asin(A) asin(A) +#define _IQ15asin(A) asin(A) +#define _IQ14asin(A) asin(A) +#define _IQ13asin(A) asin(A) +#define _IQ12asin(A) asin(A) +#define _IQ11asin(A) asin(A) +#define _IQ10asin(A) asin(A) +#define _IQ9asin(A) asin(A) +#define _IQ8asin(A) asin(A) +#define _IQ7asin(A) asin(A) +#define _IQ6asin(A) asin(A) +#define _IQ5asin(A) asin(A) +#define _IQ4asin(A) asin(A) +#define _IQ3asin(A) asin(A) +#define _IQ2asin(A) asin(A) +#define _IQ1asin(A) asin(A) +#define _IQasin(A) asin(A) + + +#define _IQ29cos(A) cos(A) +#define _IQ28cos(A) cos(A) +#define _IQ27cos(A) cos(A) +#define _IQ26cos(A) cos(A) +#define _IQ25cos(A) cos(A) +#define _IQ24cos(A) cos(A) +#define _IQ23cos(A) cos(A) +#define _IQ22cos(A) cos(A) +#define _IQ21cos(A) cos(A) +#define _IQ20cos(A) cos(A) +#define _IQ19cos(A) cos(A) +#define _IQ18cos(A) cos(A) +#define _IQ17cos(A) cos(A) +#define _IQ16cos(A) cos(A) +#define _IQ15cos(A) cos(A) +#define _IQ14cos(A) cos(A) +#define _IQ13cos(A) cos(A) +#define _IQ12cos(A) cos(A) +#define _IQ11cos(A) cos(A) +#define _IQ10cos(A) cos(A) +#define _IQ9cos(A) cos(A) +#define _IQ8cos(A) cos(A) +#define _IQ7cos(A) cos(A) +#define _IQ6cos(A) cos(A) +#define _IQ5cos(A) cos(A) +#define _IQ4cos(A) cos(A) +#define _IQ3cos(A) cos(A) +#define _IQ2cos(A) cos(A) +#define _IQ1cos(A) cos(A) +#define _IQcos(A) cos(A) + + +#define _IQ30cosPU(A) cos((A) * 6.283185307) +#define _IQ29cosPU(A) cos((A) * 6.283185307) +#define _IQ28cosPU(A) cos((A) * 6.283185307) +#define _IQ27cosPU(A) cos((A) * 6.283185307) +#define _IQ26cosPU(A) cos((A) * 6.283185307) +#define _IQ25cosPU(A) cos((A) * 6.283185307) +#define _IQ24cosPU(A) cos((A) * 6.283185307) +#define _IQ23cosPU(A) cos((A) * 6.283185307) +#define _IQ22cosPU(A) cos((A) * 6.283185307) +#define _IQ21cosPU(A) cos((A) * 6.283185307) +#define _IQ20cosPU(A) cos((A) * 6.283185307) +#define _IQ19cosPU(A) cos((A) * 6.283185307) +#define _IQ18cosPU(A) cos((A) * 6.283185307) +#define _IQ17cosPU(A) cos((A) * 6.283185307) +#define _IQ16cosPU(A) cos((A) * 6.283185307) +#define _IQ15cosPU(A) cos((A) * 6.283185307) +#define _IQ14cosPU(A) cos((A) * 6.283185307) +#define _IQ13cosPU(A) cos((A) * 6.283185307) +#define _IQ12cosPU(A) cos((A) * 6.283185307) +#define _IQ11cosPU(A) cos((A) * 6.283185307) +#define _IQ10cosPU(A) cos((A) * 6.283185307) +#define _IQ9cosPU(A) cos((A) * 6.283185307) +#define _IQ8cosPU(A) cos((A) * 6.283185307) +#define _IQ7cosPU(A) cos((A) * 6.283185307) +#define _IQ6cosPU(A) cos((A) * 6.283185307) +#define _IQ5cosPU(A) cos((A) * 6.283185307) +#define _IQ4cosPU(A) cos((A) * 6.283185307) +#define _IQ3cosPU(A) cos((A) * 6.283185307) +#define _IQ2cosPU(A) cos((A) * 6.283185307) +#define _IQ1cosPU(A) cos((A) * 6.283185307) +#define _IQcosPU(A) cos((A) * 6.283185307) + + +#define _IQ29acos(A) acos(A) +#define _IQ28acos(A) acos(A) +#define _IQ27acos(A) acos(A) +#define _IQ26acos(A) acos(A) +#define _IQ25acos(A) acos(A) +#define _IQ24acos(A) acos(A) +#define _IQ23acos(A) acos(A) +#define _IQ22acos(A) acos(A) +#define _IQ21acos(A) acos(A) +#define _IQ20acos(A) acos(A) +#define _IQ19acos(A) acos(A) +#define _IQ18acos(A) acos(A) +#define _IQ17acos(A) acos(A) +#define _IQ16acos(A) acos(A) +#define _IQ15acos(A) acos(A) +#define _IQ14acos(A) acos(A) +#define _IQ13acos(A) acos(A) +#define _IQ12acos(A) acos(A) +#define _IQ11acos(A) acos(A) +#define _IQ10acos(A) acos(A) +#define _IQ9acos(A) acos(A) +#define _IQ8acos(A) acos(A) +#define _IQ7acos(A) acos(A) +#define _IQ6acos(A) acos(A) +#define _IQ5acos(A) acos(A) +#define _IQ4acos(A) acos(A) +#define _IQ3acos(A) acos(A) +#define _IQ2acos(A) acos(A) +#define _IQ1acos(A) acos(A) +#define _IQacos(A) acos(A) + + +#define _IQ29atan(A) atan(A) +#define _IQ28atan(A) atan(A) +#define _IQ27atan(A) atan(A) +#define _IQ26atan(A) atan(A) +#define _IQ25atan(A) atan(A) +#define _IQ24atan(A) atan(A) +#define _IQ23atan(A) atan(A) +#define _IQ22atan(A) atan(A) +#define _IQ21atan(A) atan(A) +#define _IQ20atan(A) atan(A) +#define _IQ19atan(A) atan(A) +#define _IQ18atan(A) atan(A) +#define _IQ17atan(A) atan(A) +#define _IQ16atan(A) atan(A) +#define _IQ15atan(A) atan(A) +#define _IQ14atan(A) atan(A) +#define _IQ13atan(A) atan(A) +#define _IQ12atan(A) atan(A) +#define _IQ11atan(A) atan(A) +#define _IQ10atan(A) atan(A) +#define _IQ9atan(A) atan(A) +#define _IQ8atan(A) atan(A) +#define _IQ7atan(A) atan(A) +#define _IQ6atan(A) atan(A) +#define _IQ5atan(A) atan(A) +#define _IQ4atan(A) atan(A) +#define _IQ3atan(A) atan(A) +#define _IQ2atan(A) atan(A) +#define _IQ1atan(A) atan(A) +#define _IQatan(A) atan(A) + + +#define _IQ30atan2(A, B) atan2(A, B) +#define _IQ29atan2(A, B) atan2(A, B) +#define _IQ28atan2(A, B) atan2(A, B) +#define _IQ27atan2(A, B) atan2(A, B) +#define _IQ26atan2(A, B) atan2(A, B) +#define _IQ25atan2(A, B) atan2(A, B) +#define _IQ24atan2(A, B) atan2(A, B) +#define _IQ23atan2(A, B) atan2(A, B) +#define _IQ22atan2(A, B) atan2(A, B) +#define _IQ21atan2(A, B) atan2(A, B) +#define _IQ20atan2(A, B) atan2(A, B) +#define _IQ19atan2(A, B) atan2(A, B) +#define _IQ18atan2(A, B) atan2(A, B) +#define _IQ17atan2(A, B) atan2(A, B) +#define _IQ16atan2(A, B) atan2(A, B) +#define _IQ15atan2(A, B) atan2(A, B) +#define _IQ14atan2(A, B) atan2(A, B) +#define _IQ13atan2(A, B) atan2(A, B) +#define _IQ12atan2(A, B) atan2(A, B) +#define _IQ11atan2(A, B) atan2(A, B) +#define _IQ10atan2(A, B) atan2(A, B) +#define _IQ9atan2(A, B) atan2(A, B) +#define _IQ8atan2(A, B) atan2(A, B) +#define _IQ7atan2(A, B) atan2(A, B) +#define _IQ6atan2(A, B) atan2(A, B) +#define _IQ5atan2(A, B) atan2(A, B) +#define _IQ4atan2(A, B) atan2(A, B) +#define _IQ3atan2(A, B) atan2(A, B) +#define _IQ2atan2(A, B) atan2(A, B) +#define _IQ1atan2(A, B) atan2(A, B) +#define _IQatan2(A, B) atan2(A, B) + + +#define _IQ30atan2PU(A, B) (((atan2(A, B) * (1.0 / 6.283185307)) >= \ + 0.0) ? \ + (atan2(A, B) * (1.0 / 6.283185307)) : \ + (atan2(A, B) * (1.0 / 6.283185307) + 1.0)) +#define _IQ29atan2PU(A, B) (((atan2(A, B) * (1.0 / 6.283185307)) >= \ + 0.0) ? \ + (atan2(A, B) * (1.0 / 6.283185307)) : \ + (atan2(A, B) * (1.0 / 6.283185307) + 1.0)) +#define _IQ28atan2PU(A, B) (((atan2(A, B) * (1.0 / 6.283185307)) >= \ + 0.0) ? \ + (atan2(A, B) * (1.0 / 6.283185307)) : \ + (atan2(A, B) * (1.0 / 6.283185307) + 1.0)) +#define _IQ27atan2PU(A, B) (((atan2(A, B) * (1.0 / 6.283185307)) >= \ + 0.0) ? \ + (atan2(A, B) * (1.0 / 6.283185307)) : \ + (atan2(A, B) * (1.0 / 6.283185307) + 1.0)) +#define _IQ26atan2PU(A, B) (((atan2(A, B) * (1.0 / 6.283185307)) >= \ + 0.0) ? \ + (atan2(A, B) * (1.0 / 6.283185307)) : \ + (atan2(A, B) * (1.0 / 6.283185307) + 1.0)) +#define _IQ25atan2PU(A, B) (((atan2(A, B) * (1.0 / 6.283185307)) >= \ + 0.0) ? \ + (atan2(A, B) * (1.0 / 6.283185307)) : \ + (atan2(A, B) * (1.0 / 6.283185307) + 1.0)) +#define _IQ24atan2PU(A, B) (((atan2(A, B) * (1.0 / 6.283185307)) >= \ + 0.0) ? \ + (atan2(A, B) * (1.0 / 6.283185307)) : \ + (atan2(A, B) * (1.0 / 6.283185307) + 1.0)) +#define _IQ23atan2PU(A, B) (((atan2(A, B) * (1.0 / 6.283185307)) >= \ + 0.0) ? \ + (atan2(A, B) * (1.0 / 6.283185307)) : \ + (atan2(A, B) * (1.0 / 6.283185307) + 1.0)) +#define _IQ22atan2PU(A, B) (((atan2(A, B) * (1.0 / 6.283185307)) >= \ + 0.0) ? \ + (atan2(A, B) * (1.0 / 6.283185307)) : \ + (atan2(A, B) * (1.0 / 6.283185307) + 1.0)) +#define _IQ21atan2PU(A, B) (((atan2(A, B) * (1.0 / 6.283185307)) >= \ + 0.0) ? \ + (atan2(A, B) * (1.0 / 6.283185307)) : \ + (atan2(A, B) * (1.0 / 6.283185307) + 1.0)) +#define _IQ20atan2PU(A, B) (((atan2(A, B) * (1.0 / 6.283185307)) >= \ + 0.0) ? \ + (atan2(A, B) * (1.0 / 6.283185307)) : \ + (atan2(A, B) * (1.0 / 6.283185307) + 1.0)) +#define _IQ19atan2PU(A, B) (((atan2(A, B) * (1.0 / 6.283185307)) >= \ + 0.0) ? \ + (atan2(A, B) * (1.0 / 6.283185307)) : \ + (atan2(A, B) * (1.0 / 6.283185307) + 1.0)) +#define _IQ18atan2PU(A, B) (((atan2(A, B) * (1.0 / 6.283185307)) >= \ + 0.0) ? \ + (atan2(A, B) * (1.0 / 6.283185307)) : \ + (atan2(A, B) * (1.0 / 6.283185307) + 1.0)) +#define _IQ17atan2PU(A, B) (((atan2(A, B) * (1.0 / 6.283185307)) >= \ + 0.0) ? \ + (atan2(A, B) * (1.0 / 6.283185307)) : \ + (atan2(A, B) * (1.0 / 6.283185307) + 1.0)) +#define _IQ16atan2PU(A, B) (((atan2(A, B) * (1.0 / 6.283185307)) >= \ + 0.0) ? \ + (atan2(A, B) * (1.0 / 6.283185307)) : \ + (atan2(A, B) * (1.0 / 6.283185307) + 1.0)) +#define _IQ15atan2PU(A, B) (((atan2(A, B) * (1.0 / 6.283185307)) >= \ + 0.0) ? \ + (atan2(A, B) * (1.0 / 6.283185307)) : \ + (atan2(A, B) * (1.0 / 6.283185307) + 1.0)) +#define _IQ14atan2PU(A, B) (((atan2(A, B) * (1.0 / 6.283185307)) >= \ + 0.0) ? \ + (atan2(A, B) * (1.0 / 6.283185307)) : \ + (atan2(A, B) * (1.0 / 6.283185307) + 1.0)) +#define _IQ13atan2PU(A, B) (((atan2(A, B) * (1.0 / 6.283185307)) >= \ + 0.0) ? \ + (atan2(A, B) * (1.0 / 6.283185307)) : \ + (atan2(A, B) * (1.0 / 6.283185307) + 1.0)) +#define _IQ12atan2PU(A, B) (((atan2(A, B) * (1.0 / 6.283185307)) >= \ + 0.0) ? \ + (atan2(A, B) * (1.0 / 6.283185307)) : \ + (atan2(A, B) * (1.0 / 6.283185307) + 1.0)) +#define _IQ11atan2PU(A, B) (((atan2(A, B) * (1.0 / 6.283185307)) >= \ + 0.0) ? \ + (atan2(A, B) * (1.0 / 6.283185307)) : \ + (atan2(A, B) * (1.0 / 6.283185307) + 1.0)) +#define _IQ10atan2PU(A, B) (((atan2(A, B) * (1.0 / 6.283185307)) >= \ + 0.0) ? \ + (atan2(A, B) * (1.0 / 6.283185307)) : \ + (atan2(A, B) * (1.0 / 6.283185307) + 1.0)) +#define _IQ9atan2PU(A, B) (((atan2(A, B) * (1.0 / 6.283185307)) >= \ + 0.0) ? \ + (atan2(A, B) * (1.0 / 6.283185307)) : \ + (atan2(A, B) * (1.0 / 6.283185307) + 1.0)) +#define _IQ8atan2PU(A, B) (((atan2(A, B) * (1.0 / 6.283185307)) >= \ + 0.0) ? \ + (atan2(A, B) * (1.0 / 6.283185307)) : \ + (atan2(A, B) * (1.0 / 6.283185307) + 1.0)) +#define _IQ7atan2PU(A, B) (((atan2(A, B) * (1.0 / 6.283185307)) >= \ + 0.0) ? \ + (atan2(A, B) * (1.0 / 6.283185307)) : \ + (atan2(A, B) * (1.0 / 6.283185307) + 1.0)) +#define _IQ6atan2PU(A, B) (((atan2(A, B) * (1.0 / 6.283185307)) >= \ + 0.0) ? \ + (atan2(A, B) * (1.0 / 6.283185307)) : \ + (atan2(A, B) * (1.0 / 6.283185307) + 1.0)) +#define _IQ5atan2PU(A, B) (((atan2(A, B) * (1.0 / 6.283185307)) >= \ + 0.0) ? \ + (atan2(A, B) * (1.0 / 6.283185307)) : \ + (atan2(A, B) * (1.0 / 6.283185307) + 1.0)) +#define _IQ4atan2PU(A, B) (((atan2(A, B) * (1.0 / 6.283185307)) >= \ + 0.0) ? \ + (atan2(A, B) * (1.0 / 6.283185307)) : \ + (atan2(A, B) * (1.0 / 6.283185307) + 1.0)) +#define _IQ3atan2PU(A, B) (((atan2(A, B) * (1.0 / 6.283185307)) >= \ + 0.0) ? \ + (atan2(A, B) * (1.0 / 6.283185307)) : \ + (atan2(A, B) * (1.0 / 6.283185307) + 1.0)) +#define _IQ2atan2PU(A, B) (((atan2(A, B) * (1.0 / 6.283185307)) >= \ + 0.0) ? \ + (atan2(A, B) * (1.0 / 6.283185307)) : \ + (atan2(A, B) * (1.0 / 6.283185307) + 1.0)) +#define _IQ1atan2PU(A, B) (((atan2(A, B) * (1.0 / 6.283185307)) >= \ + 0.0) ? \ + (atan2(A, B) * (1.0 / 6.283185307)) : \ + (atan2(A, B) * (1.0 / 6.283185307) + 1.0)) +#define _IQatan2PU(A, B) (((atan2(A, B) * (1.0 / 6.283185307)) >= \ + 0.0) ? \ + (atan2(A, B) * (1.0 / 6.283185307)) : \ + (atan2(A, B) * (1.0 / 6.283185307) + 1.0)) + + +#define _IQ30sqrt(A) sqrt(A) +#define _IQ29sqrt(A) sqrt(A) +#define _IQ28sqrt(A) sqrt(A) +#define _IQ27sqrt(A) sqrt(A) +#define _IQ26sqrt(A) sqrt(A) +#define _IQ25sqrt(A) sqrt(A) +#define _IQ24sqrt(A) sqrt(A) +#define _IQ23sqrt(A) sqrt(A) +#define _IQ22sqrt(A) sqrt(A) +#define _IQ21sqrt(A) sqrt(A) +#define _IQ20sqrt(A) sqrt(A) +#define _IQ19sqrt(A) sqrt(A) +#define _IQ18sqrt(A) sqrt(A) +#define _IQ17sqrt(A) sqrt(A) +#define _IQ16sqrt(A) sqrt(A) +#define _IQ15sqrt(A) sqrt(A) +#define _IQ14sqrt(A) sqrt(A) +#define _IQ13sqrt(A) sqrt(A) +#define _IQ12sqrt(A) sqrt(A) +#define _IQ11sqrt(A) sqrt(A) +#define _IQ10sqrt(A) sqrt(A) +#define _IQ9sqrt(A) sqrt(A) +#define _IQ8sqrt(A) sqrt(A) +#define _IQ7sqrt(A) sqrt(A) +#define _IQ6sqrt(A) sqrt(A) +#define _IQ5sqrt(A) sqrt(A) +#define _IQ4sqrt(A) sqrt(A) +#define _IQ3sqrt(A) sqrt(A) +#define _IQ2sqrt(A) sqrt(A) +#define _IQ1sqrt(A) sqrt(A) +#define _IQsqrt(A) sqrt(A) + + +#define _IQ30isqrt(A) (1.0 / sqrt(A)) +#define _IQ29isqrt(A) (1.0 / sqrt(A)) +#define _IQ28isqrt(A) (1.0 / sqrt(A)) +#define _IQ27isqrt(A) (1.0 / sqrt(A)) +#define _IQ26isqrt(A) (1.0 / sqrt(A)) +#define _IQ25isqrt(A) (1.0 / sqrt(A)) +#define _IQ24isqrt(A) (1.0 / sqrt(A)) +#define _IQ23isqrt(A) (1.0 / sqrt(A)) +#define _IQ22isqrt(A) (1.0 / sqrt(A)) +#define _IQ21isqrt(A) (1.0 / sqrt(A)) +#define _IQ20isqrt(A) (1.0 / sqrt(A)) +#define _IQ19isqrt(A) (1.0 / sqrt(A)) +#define _IQ18isqrt(A) (1.0 / sqrt(A)) +#define _IQ17isqrt(A) (1.0 / sqrt(A)) +#define _IQ16isqrt(A) (1.0 / sqrt(A)) +#define _IQ15isqrt(A) (1.0 / sqrt(A)) +#define _IQ14isqrt(A) (1.0 / sqrt(A)) +#define _IQ13isqrt(A) (1.0 / sqrt(A)) +#define _IQ12isqrt(A) (1.0 / sqrt(A)) +#define _IQ11isqrt(A) (1.0 / sqrt(A)) +#define _IQ10isqrt(A) (1.0 / sqrt(A)) +#define _IQ9isqrt(A) (1.0 / sqrt(A)) +#define _IQ8isqrt(A) (1.0 / sqrt(A)) +#define _IQ7isqrt(A) (1.0 / sqrt(A)) +#define _IQ6isqrt(A) (1.0 / sqrt(A)) +#define _IQ5isqrt(A) (1.0 / sqrt(A)) +#define _IQ4isqrt(A) (1.0 / sqrt(A)) +#define _IQ3isqrt(A) (1.0 / sqrt(A)) +#define _IQ2isqrt(A) (1.0 / sqrt(A)) +#define _IQ1isqrt(A) (1.0 / sqrt(A)) +#define _IQisqrt(A) (1.0 / sqrt(A)) + + +#define _IQ30exp(A) exp(A) +#define _IQ29exp(A) exp(A) +#define _IQ28exp(A) exp(A) +#define _IQ27exp(A) exp(A) +#define _IQ26exp(A) exp(A) +#define _IQ25exp(A) exp(A) +#define _IQ24exp(A) exp(A) +#define _IQ23exp(A) exp(A) +#define _IQ22exp(A) exp(A) +#define _IQ21exp(A) exp(A) +#define _IQ20exp(A) exp(A) +#define _IQ19exp(A) exp(A) +#define _IQ18exp(A) exp(A) +#define _IQ17exp(A) exp(A) +#define _IQ16exp(A) exp(A) +#define _IQ15exp(A) exp(A) +#define _IQ14exp(A) exp(A) +#define _IQ13exp(A) exp(A) +#define _IQ12exp(A) exp(A) +#define _IQ11exp(A) exp(A) +#define _IQ10exp(A) exp(A) +#define _IQ9exp(A) exp(A) +#define _IQ8exp(A) exp(A) +#define _IQ7exp(A) exp(A) +#define _IQ6exp(A) exp(A) +#define _IQ5exp(A) exp(A) +#define _IQ4exp(A) exp(A) +#define _IQ3exp(A) exp(A) +#define _IQ2exp(A) exp(A) +#define _IQ1exp(A) exp(A) +#define _IQexp(A) exp(A) + + +#define _IQ30exp2(A) exp2(A) +#define _IQ29exp2(A) exp2(A) +#define _IQ28exp2(A) exp2(A) +#define _IQ27exp2(A) exp2(A) +#define _IQ26exp2(A) exp2(A) +#define _IQ25exp2(A) exp2(A) +#define _IQ24exp2(A) exp2(A) +#define _IQ23exp2(A) exp2(A) +#define _IQ22exp2(A) exp2(A) +#define _IQ21exp2(A) exp2(A) +#define _IQ20exp2(A) exp2(A) +#define _IQ19exp2(A) exp2(A) +#define _IQ18exp2(A) exp2(A) +#define _IQ17exp2(A) exp2(A) +#define _IQ16exp2(A) exp2(A) +#define _IQ15exp2(A) exp2(A) +#define _IQ14exp2(A) exp2(A) +#define _IQ13exp2(A) exp2(A) +#define _IQ12exp2(A) exp2(A) +#define _IQ11exp2(A) exp2(A) +#define _IQ10exp2(A) exp2(A) +#define _IQ9exp2(A) exp2(A) +#define _IQ8exp2(A) exp2(A) +#define _IQ7exp2(A) exp2(A) +#define _IQ6exp2(A) exp2(A) +#define _IQ5exp2(A) exp2(A) +#define _IQ4exp2(A) exp2(A) +#define _IQ3exp2(A) exp2(A) +#define _IQ2exp2(A) exp2(A) +#define _IQ1exp2(A) exp2(A) +#define _IQexp2(A) exp2(A) + + +#define _IQ30int(A) ((long)(A)) +#define _IQ29int(A) ((long)(A)) +#define _IQ28int(A) ((long)(A)) +#define _IQ27int(A) ((long)(A)) +#define _IQ26int(A) ((long)(A)) +#define _IQ25int(A) ((long)(A)) +#define _IQ24int(A) ((long)(A)) +#define _IQ23int(A) ((long)(A)) +#define _IQ22int(A) ((long)(A)) +#define _IQ21int(A) ((long)(A)) +#define _IQ20int(A) ((long)(A)) +#define _IQ19int(A) ((long)(A)) +#define _IQ18int(A) ((long)(A)) +#define _IQ17int(A) ((long)(A)) +#define _IQ16int(A) ((long)(A)) +#define _IQ15int(A) ((long)(A)) +#define _IQ14int(A) ((long)(A)) +#define _IQ13int(A) ((long)(A)) +#define _IQ12int(A) ((long)(A)) +#define _IQ11int(A) ((long)(A)) +#define _IQ10int(A) ((long)(A)) +#define _IQ9int(A) ((long)(A)) +#define _IQ8int(A) ((long)(A)) +#define _IQ7int(A) ((long)(A)) +#define _IQ6int(A) ((long)(A)) +#define _IQ5int(A) ((long)(A)) +#define _IQ4int(A) ((long)(A)) +#define _IQ3int(A) ((long)(A)) +#define _IQ2int(A) ((long)(A)) +#define _IQ1int(A) ((long)(A)) +#define _IQint(A) ((long)(A)) + + +#define _IQ30frac(A) ((A) - (float)((long)(A))) +#define _IQ29frac(A) ((A) - (float)((long)(A))) +#define _IQ28frac(A) ((A) - (float)((long)(A))) +#define _IQ27frac(A) ((A) - (float)((long)(A))) +#define _IQ26frac(A) ((A) - (float)((long)(A))) +#define _IQ25frac(A) ((A) - (float)((long)(A))) +#define _IQ24frac(A) ((A) - (float)((long)(A))) +#define _IQ23frac(A) ((A) - (float)((long)(A))) +#define _IQ22frac(A) ((A) - (float)((long)(A))) +#define _IQ21frac(A) ((A) - (float)((long)(A))) +#define _IQ20frac(A) ((A) - (float)((long)(A))) +#define _IQ19frac(A) ((A) - (float)((long)(A))) +#define _IQ18frac(A) ((A) - (float)((long)(A))) +#define _IQ17frac(A) ((A) - (float)((long)(A))) +#define _IQ16frac(A) ((A) - (float)((long)(A))) +#define _IQ15frac(A) ((A) - (float)((long)(A))) +#define _IQ14frac(A) ((A) - (float)((long)(A))) +#define _IQ13frac(A) ((A) - (float)((long)(A))) +#define _IQ12frac(A) ((A) - (float)((long)(A))) +#define _IQ11frac(A) ((A) - (float)((long)(A))) +#define _IQ10frac(A) ((A) - (float)((long)(A))) +#define _IQ9frac(A) ((A) - (float)((long)(A))) +#define _IQ8frac(A) ((A) - (float)((long)(A))) +#define _IQ7frac(A) ((A) - (float)((long)(A))) +#define _IQ6frac(A) ((A) - (float)((long)(A))) +#define _IQ5frac(A) ((A) - (float)((long)(A))) +#define _IQ4frac(A) ((A) - (float)((long)(A))) +#define _IQ3frac(A) ((A) - (float)((long)(A))) +#define _IQ2frac(A) ((A) - (float)((long)(A))) +#define _IQ1frac(A) ((A) - (float)((long)(A))) +#define _IQfrac(A) ((A) - (float)((long)(A))) + + +#define _IQ30mpyIQX(A, IQA, B, IQB) ((A) * (B)) +#define _IQ29mpyIQX(A, IQA, B, IQB) ((A) * (B)) +#define _IQ28mpyIQX(A, IQA, B, IQB) ((A) * (B)) +#define _IQ27mpyIQX(A, IQA, B, IQB) ((A) * (B)) +#define _IQ26mpyIQX(A, IQA, B, IQB) ((A) * (B)) +#define _IQ25mpyIQX(A, IQA, B, IQB) ((A) * (B)) +#define _IQ24mpyIQX(A, IQA, B, IQB) ((A) * (B)) +#define _IQ23mpyIQX(A, IQA, B, IQB) ((A) * (B)) +#define _IQ22mpyIQX(A, IQA, B, IQB) ((A) * (B)) +#define _IQ21mpyIQX(A, IQA, B, IQB) ((A) * (B)) +#define _IQ20mpyIQX(A, IQA, B, IQB) ((A) * (B)) +#define _IQ19mpyIQX(A, IQA, B, IQB) ((A) * (B)) +#define _IQ18mpyIQX(A, IQA, B, IQB) ((A) * (B)) +#define _IQ17mpyIQX(A, IQA, B, IQB) ((A) * (B)) +#define _IQ16mpyIQX(A, IQA, B, IQB) ((A) * (B)) +#define _IQ15mpyIQX(A, IQA, B, IQB) ((A) * (B)) +#define _IQ14mpyIQX(A, IQA, B, IQB) ((A) * (B)) +#define _IQ13mpyIQX(A, IQA, B, IQB) ((A) * (B)) +#define _IQ12mpyIQX(A, IQA, B, IQB) ((A) * (B)) +#define _IQ11mpyIQX(A, IQA, B, IQB) ((A) * (B)) +#define _IQ10mpyIQX(A, IQA, B, IQB) ((A) * (B)) +#define _IQ9mpyIQX(A, IQA, B, IQB) ((A) * (B)) +#define _IQ8mpyIQX(A, IQA, B, IQB) ((A) * (B)) +#define _IQ7mpyIQX(A, IQA, B, IQB) ((A) * (B)) +#define _IQ6mpyIQX(A, IQA, B, IQB) ((A) * (B)) +#define _IQ5mpyIQX(A, IQA, B, IQB) ((A) * (B)) +#define _IQ4mpyIQX(A, IQA, B, IQB) ((A) * (B)) +#define _IQ3mpyIQX(A, IQA, B, IQB) ((A) * (B)) +#define _IQ2mpyIQX(A, IQA, B, IQB) ((A) * (B)) +#define _IQ1mpyIQX(A, IQA, B, IQB) ((A) * (B)) +#define _IQmpyIQX(A, IQA, B, IQB) ((A) * (B)) + + +#define _IQ30mpyI32(A, B) ((A) * (float)(B)) +#define _IQ29mpyI32(A, B) ((A) * (float)(B)) +#define _IQ28mpyI32(A, B) ((A) * (float)(B)) +#define _IQ27mpyI32(A, B) ((A) * (float)(B)) +#define _IQ26mpyI32(A, B) ((A) * (float)(B)) +#define _IQ25mpyI32(A, B) ((A) * (float)(B)) +#define _IQ24mpyI32(A, B) ((A) * (float)(B)) +#define _IQ23mpyI32(A, B) ((A) * (float)(B)) +#define _IQ22mpyI32(A, B) ((A) * (float)(B)) +#define _IQ21mpyI32(A, B) ((A) * (float)(B)) +#define _IQ20mpyI32(A, B) ((A) * (float)(B)) +#define _IQ19mpyI32(A, B) ((A) * (float)(B)) +#define _IQ18mpyI32(A, B) ((A) * (float)(B)) +#define _IQ17mpyI32(A, B) ((A) * (float)(B)) +#define _IQ16mpyI32(A, B) ((A) * (float)(B)) +#define _IQ15mpyI32(A, B) ((A) * (float)(B)) +#define _IQ14mpyI32(A, B) ((A) * (float)(B)) +#define _IQ13mpyI32(A, B) ((A) * (float)(B)) +#define _IQ12mpyI32(A, B) ((A) * (float)(B)) +#define _IQ11mpyI32(A, B) ((A) * (float)(B)) +#define _IQ10mpyI32(A, B) ((A) * (float)(B)) +#define _IQ9mpyI32(A, B) ((A) * (float)(B)) +#define _IQ8mpyI32(A, B) ((A) * (float)(B)) +#define _IQ7mpyI32(A, B) ((A) * (float)(B)) +#define _IQ6mpyI32(A, B) ((A) * (float)(B)) +#define _IQ5mpyI32(A, B) ((A) * (float)(B)) +#define _IQ4mpyI32(A, B) ((A) * (float)(B)) +#define _IQ3mpyI32(A, B) ((A) * (float)(B)) +#define _IQ2mpyI32(A, B) ((A) * (float)(B)) +#define _IQ1mpyI32(A, B) ((A) * (float)(B)) +#define _IQmpyI32(A, B) ((A) * (float)(B)) + + +#define _IQ30mpyI32int(A, B) ((long)((A) * (float)(B))) +#define _IQ29mpyI32int(A, B) ((long)((A) * (float)(B))) +#define _IQ28mpyI32int(A, B) ((long)((A) * (float)(B))) +#define _IQ27mpyI32int(A, B) ((long)((A) * (float)(B))) +#define _IQ26mpyI32int(A, B) ((long)((A) * (float)(B))) +#define _IQ25mpyI32int(A, B) ((long)((A) * (float)(B))) +#define _IQ24mpyI32int(A, B) ((long)((A) * (float)(B))) +#define _IQ23mpyI32int(A, B) ((long)((A) * (float)(B))) +#define _IQ22mpyI32int(A, B) ((long)((A) * (float)(B))) +#define _IQ21mpyI32int(A, B) ((long)((A) * (float)(B))) +#define _IQ20mpyI32int(A, B) ((long)((A) * (float)(B))) +#define _IQ19mpyI32int(A, B) ((long)((A) * (float)(B))) +#define _IQ18mpyI32int(A, B) ((long)((A) * (float)(B))) +#define _IQ17mpyI32int(A, B) ((long)((A) * (float)(B))) +#define _IQ16mpyI32int(A, B) ((long)((A) * (float)(B))) +#define _IQ15mpyI32int(A, B) ((long)((A) * (float)(B))) +#define _IQ14mpyI32int(A, B) ((long)((A) * (float)(B))) +#define _IQ13mpyI32int(A, B) ((long)((A) * (float)(B))) +#define _IQ12mpyI32int(A, B) ((long)((A) * (float)(B))) +#define _IQ11mpyI32int(A, B) ((long)((A) * (float)(B))) +#define _IQ10mpyI32int(A, B) ((long)((A) * (float)(B))) +#define _IQ9mpyI32int(A, B) ((long)((A) * (float)(B))) +#define _IQ8mpyI32int(A, B) ((long)((A) * (float)(B))) +#define _IQ7mpyI32int(A, B) ((long)((A) * (float)(B))) +#define _IQ6mpyI32int(A, B) ((long)((A) * (float)(B))) +#define _IQ5mpyI32int(A, B) ((long)((A) * (float)(B))) +#define _IQ4mpyI32int(A, B) ((long)((A) * (float)(B))) +#define _IQ3mpyI32int(A, B) ((long)((A) * (float)(B))) +#define _IQ2mpyI32int(A, B) ((long)((A) * (float)(B))) +#define _IQ1mpyI32int(A, B) ((long)((A) * (float)(B))) +#define _IQmpyI32int(A, B) ((long)((A) * (float)(B))) + + +#define _IQ30mpyI32frac(A, B) (((A) * (B)) - \ + (float)((long)((A) * (float)(B)))) +#define _IQ29mpyI32frac(A, B) (((A) * (B)) - \ + (float)((long)((A) * (float)(B)))) +#define _IQ28mpyI32frac(A, B) (((A) * (B)) - \ + (float)((long)((A) * (float)(B)))) +#define _IQ27mpyI32frac(A, B) (((A) * (B)) - \ + (float)((long)((A) * (float)(B)))) +#define _IQ26mpyI32frac(A, B) (((A) * (B)) - \ + (float)((long)((A) * (float)(B)))) +#define _IQ25mpyI32frac(A, B) (((A) * (B)) - \ + (float)((long)((A) * (float)(B)))) +#define _IQ24mpyI32frac(A, B) (((A) * (B)) - \ + (float)((long)((A) * (float)(B)))) +#define _IQ23mpyI32frac(A, B) (((A) * (B)) - \ + (float)((long)((A) * (float)(B)))) +#define _IQ22mpyI32frac(A, B) (((A) * (B)) - \ + (float)((long)((A) * (float)(B)))) +#define _IQ21mpyI32frac(A, B) (((A) * (B)) - \ + (float)((long)((A) * (float)(B)))) +#define _IQ20mpyI32frac(A, B) (((A) * (B)) - \ + (float)((long)((A) * (float)(B)))) +#define _IQ19mpyI32frac(A, B) (((A) * (B)) - \ + (float)((long)((A) * (float)(B)))) +#define _IQ18mpyI32frac(A, B) (((A) * (B)) - \ + (float)((long)((A) * (float)(B)))) +#define _IQ17mpyI32frac(A, B) (((A) * (B)) - \ + (float)((long)((A) * (float)(B)))) +#define _IQ16mpyI32frac(A, B) (((A) * (B)) - \ + (float)((long)((A) * (float)(B)))) +#define _IQ15mpyI32frac(A, B) (((A) * (B)) - \ + (float)((long)((A) * (float)(B)))) +#define _IQ14mpyI32frac(A, B) (((A) * (B)) - \ + (float)((long)((A) * (float)(B)))) +#define _IQ13mpyI32frac(A, B) (((A) * (B)) - \ + (float)((long)((A) * (float)(B)))) +#define _IQ12mpyI32frac(A, B) (((A) * (B)) - \ + (float)((long)((A) * (float)(B)))) +#define _IQ11mpyI32frac(A, B) (((A) * (B)) - \ + (float)((long)((A) * (float)(B)))) +#define _IQ10mpyI32frac(A, B) (((A) * (B)) - \ + (float)((long)((A) * (float)(B)))) +#define _IQ9mpyI32frac(A, B) (((A) * (B)) - \ + (float)((long)((A) * (float)(B)))) +#define _IQ8mpyI32frac(A, B) (((A) * (B)) - \ + (float)((long)((A) * (float)(B)))) +#define _IQ7mpyI32frac(A, B) (((A) * (B)) - \ + (float)((long)((A) * (float)(B)))) +#define _IQ6mpyI32frac(A, B) (((A) * (B)) - \ + (float)((long)((A) * (float)(B)))) +#define _IQ5mpyI32frac(A, B) (((A) * (B)) - \ + (float)((long)((A) * (float)(B)))) +#define _IQ4mpyI32frac(A, B) (((A) * (B)) - \ + (float)((long)((A) * (float)(B)))) +#define _IQ3mpyI32frac(A, B) (((A) * (B)) - \ + (float)((long)((A) * (float)(B)))) +#define _IQ2mpyI32frac(A, B) (((A) * (B)) - \ + (float)((long)((A) * (float)(B)))) +#define _IQ1mpyI32frac(A, B) (((A) * (B)) - \ + (float)((long)((A) * (float)(B)))) +#define _IQmpyI32frac(A, B) (((A) * (B)) - \ + (float)((long)((A) * (float)(B)))) + + +#define _IQ30mag(A, B) sqrt(((A) * (A)) + ((B) * (B))) +#define _IQ29mag(A, B) sqrt(((A) * (A)) + ((B) * (B))) +#define _IQ28mag(A, B) sqrt(((A) * (A)) + ((B) * (B))) +#define _IQ27mag(A, B) sqrt(((A) * (A)) + ((B) * (B))) +#define _IQ26mag(A, B) sqrt(((A) * (A)) + ((B) * (B))) +#define _IQ25mag(A, B) sqrt(((A) * (A)) + ((B) * (B))) +#define _IQ24mag(A, B) sqrt(((A) * (A)) + ((B) * (B))) +#define _IQ23mag(A, B) sqrt(((A) * (A)) + ((B) * (B))) +#define _IQ22mag(A, B) sqrt(((A) * (A)) + ((B) * (B))) +#define _IQ21mag(A, B) sqrt(((A) * (A)) + ((B) * (B))) +#define _IQ20mag(A, B) sqrt(((A) * (A)) + ((B) * (B))) +#define _IQ19mag(A, B) sqrt(((A) * (A)) + ((B) * (B))) +#define _IQ18mag(A, B) sqrt(((A) * (A)) + ((B) * (B))) +#define _IQ17mag(A, B) sqrt(((A) * (A)) + ((B) * (B))) +#define _IQ16mag(A, B) sqrt(((A) * (A)) + ((B) * (B))) +#define _IQ15mag(A, B) sqrt(((A) * (A)) + ((B) * (B))) +#define _IQ14mag(A, B) sqrt(((A) * (A)) + ((B) * (B))) +#define _IQ13mag(A, B) sqrt(((A) * (A)) + ((B) * (B))) +#define _IQ12mag(A, B) sqrt(((A) * (A)) + ((B) * (B))) +#define _IQ11mag(A, B) sqrt(((A) * (A)) + ((B) * (B))) +#define _IQ10mag(A, B) sqrt(((A) * (A)) + ((B) * (B))) +#define _IQ9mag(A, B) sqrt(((A) * (A)) + ((B) * (B))) +#define _IQ8mag(A, B) sqrt(((A) * (A)) + ((B) * (B))) +#define _IQ7mag(A, B) sqrt(((A) * (A)) + ((B) * (B))) +#define _IQ6mag(A, B) sqrt(((A) * (A)) + ((B) * (B))) +#define _IQ5mag(A, B) sqrt(((A) * (A)) + ((B) * (B))) +#define _IQ4mag(A, B) sqrt(((A) * (A)) + ((B) * (B))) +#define _IQ3mag(A, B) sqrt(((A) * (A)) + ((B) * (B))) +#define _IQ2mag(A, B) sqrt(((A) * (A)) + ((B) * (B))) +#define _IQ1mag(A, B) sqrt(((A) * (A)) + ((B) * (B))) +#define _IQmag(A, B) sqrt(((A) * (A)) + ((B) * (B))) + + +#define _atoIQ30(A) atof(A) +#define _atoIQ29(A) atof(A) +#define _atoIQ28(A) atof(A) +#define _atoIQ27(A) atof(A) +#define _atoIQ26(A) atof(A) +#define _atoIQ25(A) atof(A) +#define _atoIQ24(A) atof(A) +#define _atoIQ23(A) atof(A) +#define _atoIQ22(A) atof(A) +#define _atoIQ21(A) atof(A) +#define _atoIQ20(A) atof(A) +#define _atoIQ19(A) atof(A) +#define _atoIQ18(A) atof(A) +#define _atoIQ17(A) atof(A) +#define _atoIQ16(A) atof(A) +#define _atoIQ15(A) atof(A) +#define _atoIQ14(A) atof(A) +#define _atoIQ13(A) atof(A) +#define _atoIQ12(A) atof(A) +#define _atoIQ11(A) atof(A) +#define _atoIQ10(A) atof(A) +#define _atoIQ9(A) atof(A) +#define _atoIQ8(A) atof(A) +#define _atoIQ7(A) atof(A) +#define _atoIQ6(A) atof(A) +#define _atoIQ5(A) atof(A) +#define _atoIQ4(A) atof(A) +#define _atoIQ3(A) atof(A) +#define _atoIQ2(A) atof(A) +#define _atoIQ1(A) atof(A) +#define _atoIQ(A) atof(A) + + +#define _IQ30toa(A, B, C) sprintf(A, B, C) +#define _IQ29toa(A, B, C) sprintf(A, B, C) +#define _IQ28toa(A, B, C) sprintf(A, B, C) +#define _IQ27toa(A, B, C) sprintf(A, B, C) +#define _IQ26toa(A, B, C) sprintf(A, B, C) +#define _IQ25toa(A, B, C) sprintf(A, B, C) +#define _IQ24toa(A, B, C) sprintf(A, B, C) +#define _IQ23toa(A, B, C) sprintf(A, B, C) +#define _IQ22toa(A, B, C) sprintf(A, B, C) +#define _IQ21toa(A, B, C) sprintf(A, B, C) +#define _IQ20toa(A, B, C) sprintf(A, B, C) +#define _IQ19toa(A, B, C) sprintf(A, B, C) +#define _IQ18toa(A, B, C) sprintf(A, B, C) +#define _IQ17toa(A, B, C) sprintf(A, B, C) +#define _IQ16toa(A, B, C) sprintf(A, B, C) +#define _IQ15toa(A, B, C) sprintf(A, B, C) +#define _IQ14toa(A, B, C) sprintf(A, B, C) +#define _IQ13toa(A, B, C) sprintf(A, B, C) +#define _IQ12toa(A, B, C) sprintf(A, B, C) +#define _IQ11toa(A, B, C) sprintf(A, B, C) +#define _IQ10toa(A, B, C) sprintf(A, B, C) +#define _IQ9toa(A, B, C) sprintf(A, B, C) +#define _IQ8toa(A, B, C) sprintf(A, B, C) +#define _IQ7toa(A, B, C) sprintf(A, B, C) +#define _IQ6toa(A, B, C) sprintf(A, B, C) +#define _IQ5toa(A, B, C) sprintf(A, B, C) +#define _IQ4toa(A, B, C) sprintf(A, B, C) +#define _IQ3toa(A, B, C) sprintf(A, B, C) +#define _IQ2toa(A, B, C) sprintf(A, B, C) +#define _IQ1toa(A, B, C) sprintf(A, B, C) +#define _IQtoa(A, B, C) sprintf(A, B, C) + + +#define _IQ30abs(A) fabs(A) +#define _IQ29abs(A) fabs(A) +#define _IQ28abs(A) fabs(A) +#define _IQ27abs(A) fabs(A) +#define _IQ26abs(A) fabs(A) +#define _IQ25abs(A) fabs(A) +#define _IQ24abs(A) fabs(A) +#define _IQ23abs(A) fabs(A) +#define _IQ22abs(A) fabs(A) +#define _IQ21abs(A) fabs(A) +#define _IQ20abs(A) fabs(A) +#define _IQ19abs(A) fabs(A) +#define _IQ18abs(A) fabs(A) +#define _IQ17abs(A) fabs(A) +#define _IQ16abs(A) fabs(A) +#define _IQ15abs(A) fabs(A) +#define _IQ14abs(A) fabs(A) +#define _IQ13abs(A) fabs(A) +#define _IQ12abs(A) fabs(A) +#define _IQ11abs(A) fabs(A) +#define _IQ10abs(A) fabs(A) +#define _IQ9abs(A) fabs(A) +#define _IQ8abs(A) fabs(A) +#define _IQ7abs(A) fabs(A) +#define _IQ6abs(A) fabs(A) +#define _IQ5abs(A) fabs(A) +#define _IQ4abs(A) fabs(A) +#define _IQ3abs(A) fabs(A) +#define _IQ2abs(A) fabs(A) +#define _IQ1abs(A) fabs(A) +#define _IQabs(A) fabs(A) + +#endif // MATH_TYPE == IQ_MATH + + +#ifdef __cplusplus +} +#endif + +#endif // __IQMATH_RV_H__ diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M0_Control_Configure.h b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M0_Control_Configure.h new file mode 100644 index 0000000..6c1565d --- /dev/null +++ b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M0_Control_Configure.h @@ -0,0 +1,79 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : M0_Control_Configure.h + * Author : WCH + * Version : V1.0.0 + * Date : 2026/04/23 + * Description : Function selection and configuration. +********************************************************************************* +* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ + +#ifndef __M0_CONTROL_CONFIGURE_H +#define __M0_CONTROL_CONFIGURE_H +#define OBSERVER_ADAPTOR + +//#define POSICOM + +#define IF_VIBRATION_COM + +//#define SIX_SECTOR_POSITION +#define TWELVE_SECTOR_POSITION + +#define SPEED_RECOVERKEY + +#if defined SPEED_RECOVERKEY + #define POWERON_START + //#define KEY_START +#endif + +#define ZEROCROSSOVER_TR +//#define ZEROCROSSOVER_OC + +//电压限幅表选择,共8种配置:100,098,096,094,092,090,088,086 +//#define MAG100_TABLE_USED +//#define MAG098_TABLE_USED +//#define MAG096_TABLE_USED +//#define MAG094_TABLE_USED +#define MAG092_TABLE_USED +//#define MAG090_TABLE_USED +//#define MAG088_TABLE_USED +//#define MAG086_TABLE_USED + +#if ( (!defined(MAG100_TABLE_USED))&&(!defined(MAG098_TABLE_USED))&&\ + (!defined(MAG096_TABLE_USED))&&(!defined(MAG094_TABLE_USED))\ + &&(!defined(MAG092_TABLE_USED))&&(!defined(MAG090_TABLE_USED))\ + &&(!defined(MAG088_TABLE_USED))&&(!defined(MAG086_TABLE_USED))) +#error "Invalid configuration: No voltage limit selected" +#endif + +#if ( (!defined(SIX_SECTOR_POSITION))&&(!defined(TWELVE_SECTOR_POSITION))) +#error "Invalid configuration: No HFVQI configure" +#endif + +#if ( (defined(SIX_SECTOR_POSITION))&&(defined(TWELVE_SECTOR_POSITION))) +#error "Invalid configuration: Duplicate HFVQI configure" +#endif + +#if defined SPEED_RECOVERKEY + +#if ((defined(POWERON_START))&&(defined(KEY_START))) +#error "Invalid configuration: Duplicate Startmode configure" +#endif + +#if ((!defined(POWERON_START))&&(!defined(KEY_START))) +#error "Invalid configuration: No Startmode configure" +#endif +#endif + +#if ((!defined(ZEROCROSSOVER_TR))&&(!defined(ZEROCROSSOVER_OC))) +#error "Invalid configuration: No ZeroCrossmode configure" +#endif + + +/* Exported variables -------------------------------------------------------*/ +/* Exported macro -----------------------------------------------------------*/ +/* Exported functions ------------------------------------------------------ */ + +#endif diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M0_Control_Library.h b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M0_Control_Library.h new file mode 100644 index 0000000..49d351a --- /dev/null +++ b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M0_Control_Library.h @@ -0,0 +1,36 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : M0_Control_Library.h + * Author : WCH + * Version : V1.0.0 + * Date : 2026/04/23 + * Description : Project header file processing. +********************************************************************************* +* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ + +#ifndef __M0_CONTROL_LIBRAYR_H +#define __M0_CONTROL_LIBRAYR_H + +#include "ch32v20x.h" +#include "ch32v20x_opa.h" +#include "debug.h" +#include "M0_type_and_Constant.h" +#include "M0_Control_Configure.h" +#include "M1_Motor_Parameter.h" +#include "M2_PID_Parameter.h" +#include "M3_LBG_Observer_Parameter.h" +#include "M4_SVPWM_ADC1R.h" +#include "M5_Operation_and_Display.h" +#include "M5_MotorStart.h" +#include "M6_SpeedLoop.h" +#include "M6_CurrentLoop.h" +#include "M7_Interrupt.h" +#include "M8_Protection.h" +#include "M9_Appication_Blocks.h" +#include "MA_HFVQI_Parameter.h" +#include +#include "Motor_SPI_USART_MonitorData.h" + +#endif diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M0_type_and_Constant.h b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M0_type_and_Constant.h new file mode 100644 index 0000000..f303109 --- /dev/null +++ b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M0_type_and_Constant.h @@ -0,0 +1,1342 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : Mo_type_and_Constant.h + * Author : WCH + * Version : V1.0.0 + * Date : 2026/04/23 + * Description : Data type definition, constant definition, state definition. +********************************************************************************* +* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ +/* Define to prevent recursive inclusion ------------------------------------*/ +#ifndef __M0_TYPE_AND_CONSTANT_H +#define __M0_TYPE_AND_CONSTANT_H + +/* Includes -----------------------------------------------------------------*/ +#include "stdint.h" +#include "IQmath_RV32.h" + +/* Exported types -----------------------------------------------------------*/ +//电压电流结构体原型定义 +typedef struct +{ + _iq24 PhaseA; + _iq24 PhaseB; + _iq24 PhaseC; +} Component_3S_Type; + +typedef struct +{ + _iq24 Alpha; + _iq24 Beta; +} Component_2S_Type; + +typedef struct +{ + _iq24 cd; + _iq24 cq; + _iq24 peak; +} Component_2R_Type; + +typedef enum +{ + IDLE, INIT, DIRCHECK ,PRESTART, POSITION, START , RUN, STOP, BRAKE, WAIT, FAULT +} Runningstatus_Type; + +typedef enum +{ + INITIAL, INJECTION, RAMP +}Motor_Startup_Status_Type; + +typedef struct +{ + _iq24 Cos; + _iq24 Sin; +}Struct_Cossin_Type; + +typedef enum {FALSE = 0, TRUE = !FALSE} Truth_Verify_Type; + +typedef enum {DIRDOWN = 0, DIRUP = !DIRDOWN} Direction_Type; + +typedef struct +{ + uint16_t CalFreq; + _iq24 CalT; + _iq24 Kpreal; + _iq24 Kireal; + _iq24 Kdreal; + uint16_t Bw; + + _iq24 Kp; + _iq24 Kpadj; + _iq24 Ki; + _iq24 Kiadj; + _iq24 Kd; + _iq24 Kdadj; + + _iq24 Lower_Lim; + _iq24 Upper_Lim; + + _iq24 Integral; + _iq24 Differential; + + _iq24 Err_New; + _iq24 Err_Prev1; + _iq24 Err_Prev2; + _iq24 Output_New; + _iq24 Output_Prev; + + _iq24 Deltaoutput; + _iq24 Deltalim; + + _iq24 Propotion; + _iq24 Integer; + _iq24 Difference; +} PID_Structure_Type; + +typedef struct +{ + _iq24 Out_Pre; + _iq24 Out_New; + _iq24 Input_Coef; + _iq24 Output_Coef; +} LPF_First_Order_Type; + +typedef struct +{ + _iq24 In_Pre; + _iq24 Out_Pre; + _iq24 Out_New; + _iq24 Input_Coef; + _iq24 Output_Coef; +} HPF_First_Order_Type; + +typedef struct +{ + _iq24 Out_Pre1; + _iq24 Out_Pre2; + _iq24 Out_New; + + _iq24 Input_Coef; + _iq24 Output_Coef1; + _iq24 Output_Coef2; +} LPF_Second_Order_Type; + +typedef struct +{ + _iq24 In_Pre1; + _iq24 In_Pre2; + _iq24 Out_Pre1; + _iq24 Out_Pre2; + _iq24 Out_New; + + _iq24 Input_Coef; + _iq24 Output_Coef1; + _iq24 Output_Coef2; +} HPF_Second_Order_Type; + +typedef struct +{ + _iq24 In_Pre1; + _iq24 In_Pre2; + _iq24 Out_Pre1; + _iq24 Out_Pre2; + _iq24 Out_New; + + _iq24 Input_Coef; + _iq24 Output_Coef1; + _iq24 Output_Coef2; +} BPF_Second_Order_Type; + +typedef struct +{ + uint16_t CalFreq; + _iq24 CalT; + int32_t K1CerrC; + int32_t K2CerrE; + + _iq24 kCC; + _iq24 kVC; + _iq24 kEC; + _iq24 kCeC; + _iq24 kSC; + _iq24 kEE; + _iq24 kCE; + uint16_t kCE_Adj; + uint8_t Caltimes; +} LBG_Paramter_Type; + +typedef struct +{ + _iq24 K_Volt; + _iq24 K1_Curr; + _iq24 K2_Curr; + _iq24 K3_Curr; +} LBG_EMF_Init_Type; + +typedef struct +{ + _iq24 EalphaNew; + _iq24 EalphaPrev; + _iq24 EbetaNew; + _iq24 EbetaPrev; + _iq24 Ealpha_wphase; + _iq24 Ebeta_wphase; + _iq24 EUlim; + _iq24 ELlim; + + _iq24 CalphaNew; + _iq24 CalphaPrev; + _iq24 CbetaNew; + _iq24 CbetaPrev; + _iq24 CUlim; + _iq24 CLlim; + + _iq24 K_WetoPos; + + _iq24 ThetaErr; + _iq24 PosiElecPU; + _iq24 PosiElecPU_Pre; + + _iq24 Angspeed_Inst; + _iq24 Angspeed_Aver1; + _iq24 Angspeed_Aver2; + _iq24 Angspeed_Filter; + _iq24 Direction; + _iq24 Angspeed_Aver20; + _iq24 Deltaspeed; + + _iq24 EmfPeak; + _iq24 EmfErrBandup; + _iq24 EmfErrBanddown; + _iq24 EmfErr; + _iq24 Speedband; + + LPF_First_Order_Type SpeedLPF1st_M; + Struct_Cossin_Type Triangle; + + _iq24 PosiElecPU_Cali; + _iq24 PosiElecPU_Com; + _iq24 Kposcali; + uint8_t Posicom_Enable; + + LPF_First_Order_Type EMFLPF1st_M; + Truth_Verify_Type Inimark; + + uint8_t Obs_Calcnt; +} LBG_Cal_Structure_Type; + +typedef struct +{ + int32_t Kpreal; + int32_t Kireal; + _iq24 Kp; + _iq24 Ki; + _iq24 Error_New; + _iq24 Error_Prev; + _iq24 Output_New; + _iq24 Output_Prev; + _iq24 Lower_Lim; + _iq24 Upper_Lim; +}Speed_PLL_Type; + +typedef struct +{ + uint8_t Enable; + int32_t Gain; + _iq24 Err_CoefT; + _iq24 EMF_CoefT; + _iq24 EMF_Adj; + _iq24 Alpha_Err; + _iq24 Alpha_Pre; + _iq24 Alpha_New; + _iq24 Beta_Err; + _iq24 Beta_Pre; + _iq24 Beta_New; +} Observer_Adaptor_type; + +typedef struct +{ + _iq24 Vpolar; + _iq24 Vmag; + _iq24 Vmagmax; + _iq24 Vmagmin; + uint32_t Counter; + + uint16_t TimeStep; + uint16_t TimeEffect; + _iq24 AngleInit; + _iq24 AngleStep; + uint8_t SectorSet; + uint8_t SectorAct; + _iq24 AngleInj; + _iq24 Position; + _iq24 Posi_Cali; + _iq24 CurrMax; + uint8_t SectorMax; + Truth_Verify_Type Finish; + _iq24 Start_id; + _iq24 Start_iq; + uint8_t Verifytime; + uint8_t Cycletime; + uint8_t Sectorbuff; + uint8_t Cyclemax; + Truth_Verify_Type Uniform; + + Component_3S_Type Curr3S; + Component_2S_Type Curr2S; + Component_2R_Type Curr2R; + Struct_Cossin_Type Triangle; + Component_2R_Type VoltRef2R; + Component_2R_Type VoltRef2RC; + Component_2S_Type VoltRef2SC; + _iq24 Phaseloss_Currthre; + uint8_t Phaseloss_Cntthre; + uint8_t Phaseloss_Cnt; +}HFVQI_Start_Type; + +typedef struct +{ + Truth_Verify_Type Overspeed; + Truth_Verify_Type Underspeed; + Truth_Verify_Type Reliable; + Truth_Verify_Type Convergence; + Truth_Verify_Type Stable; + Truth_Verify_Type Timeout; + Truth_Verify_Type Stall; + Truth_Verify_Type Reverse; + + _iq24 OverspeedThresh; + uint16_t Overspeed_CNT; + uint16_t OverspeedcntThresh; + + _iq24 UnderspeedThresh; + uint16_t Underspeed_CNT; + uint16_t UnderspeedcntThresh; + + _iq24 VarianceThresh; + _iq24 ConvergeUpper; + _iq24 ConvergeLower; + uint16_t Converged_CNT; + uint16_t ConvergeCntThresh; + _iq24 ConvergeEmfBandup; + _iq24 ConvergeEmfBanddown; + + uint16_t Unstable_CNT; + uint16_t UnstableCntThresh; + _iq24 UnstableSpeedThresh; + + _iq24 StallSpeedBand; + _iq24 StallSpeed; + _iq24 StallCurr; + uint16_t Stall_CNT; + uint16_t StallCntThresh; + + uint16_t Reverse_CNT; + uint16_t ReverseCntThresh; + _iq24 ReverseSpeedThresh; +}Observer_Status_Type; + + +//SVPWM计算结构体 +typedef struct +{ + _iq18 BusVolt; + _iq16 T_IQ16; + uint16_t T; + uint16_t HALF_T; + uint16_t Quard_T; + _iq16 coef1; + _iq16 coef2; + _iq16 hx; + _iq16 hy; + _iq16 hz; + uint8_t sector; + _iq16 ht1; + _iq16 ht2; + uint16_t tv1; + uint16_t tv2; + uint16_t tv1half; + uint16_t tv2half; + uint16_t tvhalf; + uint16_t tv0quard; + uint16_t tv0cali; + uint16_t cc1; + uint16_t cc2; + uint16_t cc3; + uint16_t cc1Load; + uint16_t cc2Load; + uint16_t cc3Load; + uint16_t cc1Loadup; + uint16_t cc2Loadup; + uint16_t cc3Loadup; + uint16_t cc4Load; + uint8_t VoltLimMark; + _iq24 Maxmodulesqure; + _iq24 Maxmodule; + + _iq16 Ualpha_coef1; + _iq16 Ubeta_coef2; + + uint16_t PWMUcali1; + uint16_t PWMUcali2; + uint16_t PWMVcali1; + uint16_t PWMVcali2; + uint16_t PWMWcali1; + uint16_t PWMWcali2; + +} SVPWM_1R_Type; + +typedef struct +{ + int32_t Value1; + int32_t Value2; +}ADC_Result_Buff_Type; + + +typedef struct +{ + ADC_Result_Buff_Type ADC_Result; + _iq16 RatedCurr_ConvInv; + uint16_t OffsetValue1; + uint16_t OffsetValue2; + uint8_t AdcChannel1; + uint8_t AdcChannel2; + + _iq24 DCVoltPres; + _iq24 DCVoltAver; + + LPF_First_Order_Type VdcLPF1st; + _iq24 DCVolt_Filter; + _iq18 DCVoltRatedADC; + _iq18 DCVoltRatedADCInv; + _iq24 DCVoltAverSizeInv1; + _iq24 DCVoltAverSizeInv2; + _iq24 DCVoltcali; +} ADCStruc_Type; + +typedef struct +{ + uint16_t Cali1; + uint16_t Cali2; + uint16_t Cali3; + uint16_t Cali4; + uint16_t Cali5; + uint16_t Cali6; +}PWMCali_Buff_Type; + +typedef struct +{ + uint16_t Trig1; + uint16_t Trig2; + Truth_Verify_Type Trig1_limmark; + Truth_Verify_Type Trig2_limmark; +}ADC_Trig_Buff_Type; + +typedef struct +{ + uint16_t Trig1; + uint16_t Trig2; + uint16_t Trig3; + uint16_t Trig4; + uint16_t Trig5; + uint16_t Trig6; +}DMA_Trig_Buff_Type; + + +typedef struct +{ + PWMCali_Buff_Type Cali_Buff; + ADC_Trig_Buff_Type ADC_Trig; + DMA_Trig_Buff_Type DMA_Trig; + + uint8_t CaliMark; + uint16_t CaliValue1; + uint16_t CaliValue2; + uint16_t ADCTimeMin; + uint16_t ADCTimeMinDouble; + uint16_t ADCTimeMinHalf; + uint16_t Currconverttime; +} PWMCali_Type; + +typedef struct +{ + _iq24 Inv1; + _iq24 Inv2; + uint8_t Length; + uint8_t Index; +} BuffPara_Type; + +typedef struct +{ + _iq24 Kcom; + _iq24 Wecom; + _iq24 Wecomupper; + _iq24 Wecomlower; + _iq24 Powerinst; + _iq24 Powerfilter; + HPF_First_Order_Type Power_HPF1st; +}IF_Vibrationcom_type; + +typedef struct +{ + Component_2R_Type Curr_2R; //电流闭环启动观测两相旋转坐标系电流,用于闭环的初始化 + Component_2R_Type VoltRef_2R; //电流闭环启动观测两相旋转坐标系电压给定,用于闭环的初始化 + Struct_Cossin_Type Triangle; //电流闭环启动观测两相旋转坐标三角函数,用于闭环的初始化 + + _iq24 ForceInjCurrStep; //强制定位电流上升步长(unit-A/s_per) + _iq24 ForceInjCurrRef; //强制定位电流实时值(unit-A_per) + _iq24 ForceInjCurrTarget; //强制定位电流目标值(unit-A_per) + _iq24 ForceInjCurrAngle; //强制定位电流矢量位置角(unit-PU) + uint32_t ForceInjCounter; //强制定位定时计数器 + uint32_t ForceInjStage; //强制定位结束判定时间 + + _iq24 RampInjCurrTarget; //电流闭环启动电流目标值(unit-A_per) + _iq24 RampInjCurrStep; //电流闭环启动电流上升步长(unit-A_per) + _iq24 RampInjCurrRef; //电流闭环电流给定实时值(unit-A_per) + _iq24 RampInjSpeedTarget; //电流闭环启动转速目标值(unit-rad/s_per) + _iq24 RampInjSpeedStep; //电流闭环启动转速上升步长(unit-rad/s_per) + _iq24 RampInjSpeedRef; //电流闭环启动实时转速(unit-rad/s_per) + _iq24 RampInjSpeedRef2; //电流闭环启动实时转速_修正后(unit-rad/s_per) + _iq24 RampInjAngle; //电流闭环启动电流矢量角(unit-PU) + _iq24 K_WetoPosi; //同步电角速度转子电气角度积分折算系数 + uint32_t RampInjCounter; //电流闭环启动定时计数器 + uint32_t RampInjStage1; //电流闭环启动阶段1 + uint32_t RampInjStage2; //电流闭环启动阶段2 + _iq24 CurrErrThresh; //电流闭环启动阶段电流误差阈值(unit-A_per) + _iq24 Speedadj; //电流闭环阶段环路切换转速调整值(unit-rad/s_per) + _iq24 Curradj; //电流闭环阶段环路切换电流调整值(unit-A_per) + Motor_Startup_Status_Type Status; //电机启动状态 + + IF_Vibrationcom_type IF_Vicom; //电流闭环启动转速波动抑制结构体 + uint8_t InjStage; +}InjStart_Type;//电机启动控制结构体原型 + + +//加减速控制结构体 +typedef struct +{ + _iq24 Preramp; //斜坡前给定转速(unit-rad/s_per) + _iq24 Aftramp; //斜坡后给定转速(unit-rad/s_per) + _iq24 AccStep; //加速步长(unit-rad/s^2_per) + _iq24 DecStep; //减速步长(unit-rad/s^2_per) + _iq24 PoweroffDecStep; //下电减速步长(unit-rad/s^2_per) + _iq24 Aftrampcom; //斜坡后给定补偿后转速(unit-rad/s_per) + + _iq24 Startfinishspeed; //启动结束判定转速(unit-rad/s_per) + _iq24 Faststopspeed; //快速制动转速(unit-rad/s_per) + Truth_Verify_Type Startfinish; //启动完成标志 + + Truth_Verify_Type BreakStop; //定子短路制动停止状态 + Truth_Verify_Type Break; //定子短路制动状态(TRUE-处于制动状态,FALSE-非制动状态) + _iq24 Breakspeed; //定子短路制动转速(unit-Rad/s_per) + uint16_t Breakwait_cnt; //定子短路制动计数器 + uint16_t Breakwait_cntset; //定子短路制动定时设定值 + + uint16_t Precharge_cnt; //预充电计数器 + uint16_t Precharge_cntset; //预充电定时设定值 + + uint8_t Speed_Rank; //档位数 + uint8_t Speed_adncnt; //转速调整计数值 + _iq24 Speed1; //给定转速1(unit-Rad/s_per) + _iq24 Speed2; //给定转速2(unit-Rad/s_per) + _iq24 Speed3; //给定转速3(unit-Rad/s_per) + uint8_t Stopmode; //给停机模式,1:下电停机,2:按键停机 + + LPF_First_Order_Type VdcLPF1st; //转速限制用母线电压滤波器 + _iq24 Vdcact; //滤波后母线电压(unit-V_per) + _iq24 Voltbegin; //限制起始电压(unit-V_per) + _iq24 Voltrelease; //限制取消电压(unit-V_per) + Truth_Verify_Type Speedlimmark; //转速限制标志 + _iq24 Vdclimcoef; //母线电压限制转速系数 + _iq24 Vdclimspeed; //母线电压限制转速系(unit-rad/s_per) + + int8_t Direction; //转速方向 +}Speedrampctr_Type; + +//D轴电流处理结构体 +typedef struct DCurrProcess +{ + _iq24 Target; //d轴电流给定目标值1(unit-A_per) + _iq24 Target1; //d轴电流给定目标值1(unit-A_per) + _iq24 Target2; //d轴电流给定目标值2(unit-A_per) + _iq24 Weakpoint; //弱磁转速(unit-rad/s_per) + _iq24 AdjustStep; //调整步长(unit-A/s_per) + _iq24 AdjustStep1; //调整步长1(unit-A/s_per) + _iq24 AdjustStep2; //调整步长2(unit-A/s_per) + uint8_t Stage; //阶段,0-快减,1-慢减 +}DCurrProcess_Type; + +typedef struct +{ + _iq24 CurrThreshold; //过流阈值(unit-A_per) + uint16_t CntThreshold; //满足条件计数阈值 + uint16_t Cnt; //满足条件计数值 +} InstPhaseOC_Type; //瞬时过流保护结构体 + +typedef struct +{ + _iq24 OverThresh; //过压阈值(unit-V_per) + uint16_t OverCntThresh; //过压保护计数阈值 + uint16_t OverCnt; //过压保护计数值 + Truth_Verify_Type Overvolt;//过压标志 + + _iq24 UnderThresh; //欠压阈值(unit-V_per) + uint16_t UnderCntThresh; //欠压保护计数阈值 + uint16_t UnderCnt; //欠压保护计数值 + Truth_Verify_Type Undervolt;//欠压标志 + + uint16_t PeakOverCntThresh; //峰值过压保护计数阈值 + uint16_t PeakOverCnt; //峰值过压保护计数值 + uint16_t PeakOverDetectiontime; //峰值过压保护检测时间 + uint16_t PeakOverDetectiontCnt; //峰值过压保护检测时间计数 +} DCbusProtection_Type; //母线电压保护结构体 + +typedef struct +{ + _iq24 CurrCal; //过载计算电流(unit-A_per) + _iq24 CurrThresh; //过载阈值(unit-A_per) + uint16_t CntThresh; //满足条件计数阈值 + uint16_t Cnt; //满足条件计数值 + _iq24 CalCoef; //计算系数 +} OverLoad_Type; //过载保护结构体 + +typedef struct +{ + _iq24 CurrThresh; //缺相电流阈值(unit-A_per) + _iq24 CurrAabs; //A相电流绝对值(unit-A_per) + _iq24 CurrBabs; //B相电流绝对值(unit-A_per) + _iq24 CurrCabs; //C相电流绝对值(unit-A_per) + + uint16_t CntThresh; //缺相条件计数阈值 + uint16_t SiglephaseCntA; //U相缺相满足条件计数值 + uint16_t SiglephaseCntB; //V相缺相满足条件计数值 + uint16_t SiglephaseCntC; //W相缺相满足条件计数值 + uint16_t MultiphaseCnt; //多相缺相满足条件计数值 + + BuffPara_Type CurrBuffPara; //电流平均值计算参数 + +} Phaseloss_Type; //缺相保护结构体 + +typedef struct +{ + _iq18 TempConDuty; //温度折算系数 + _iq24 TempRatedADCInv; //3.3vAD采样整数的倒数 + _iq24 TempPres; //ADC采样结果当前值 + _iq24 TempAver; //ADC采样结果均值 + _iq24 TempAverSizeInv1; //温度均值计算系数1 + _iq24 TempAverSizeInv2; //温度均值计算系数2 + + _iq24 NTCOverThresh; + _iq24 NTCOpenThresh; + uint16_t NTCOverCntThresh; + uint16_t NTCOpenCntThresh; + uint16_t NTCOverCnt; + uint16_t NTCOpenCnt; + Truth_Verify_Type NTCOverStatus; + Truth_Verify_Type NTCOpenStatus; + Truth_Verify_Type NTCFlickerStatus; +} Temperature_ctl_Type; + +typedef struct +{ + Truth_Verify_Type Zcrosseffective; + uint16_t Zcrossset; + uint16_t Zcrosscnt; + uint8_t ZcrossEvent; + + uint16_t Zcrosslostcnt; + uint16_t Zcrosslostset; + Truth_Verify_Type Zcrosslost; + uint8_t Zcrosseffectivecnt; + uint16_t ZcrossDelayTrigset; + uint16_t ZcrossDelayTrigcnt; + + uint16_t SecondZcrossCnt; + uint16_t SecondZcrossSet; + uint8_t Prestatus; + uint8_t Aftstatus; + Truth_Verify_Type Inittatus; + Truth_Verify_Type Risingseffective; + Truth_Verify_Type SecondZsseffective; +} Zcross_Type; + + +typedef struct +{ + volatile uint16_t Cnt; + volatile uint16_t Duty_cycle; + volatile uint16_t Duty; + uint16_t Period; + uint16_t MaxPeriod; + volatile uint16_t Toncnt; + uint16_t Tonset; + volatile uint8_t TonEvent; + Truth_Verify_Type TonStatus; +}Phase_Type; + +typedef struct +{ + uint8_t NumData; + uint8_t Serial_Num; + uint8_t Serial_Nummax; + uint8_t Serial_Nummin; + uint8_t ChangSerial_Num; + uint8_t DelayProcess_Flag; + volatile uint16_t Cnt; + volatile uint16_t Duty_cycle; + uint16_t Period; + uint16_t HalfPeriod; + uint16_t MaxPeriod; + Truth_Verify_Type DutychangeFlag; + + uint8_t Duty_TS; + uint8_t Dutymax_T1S1; + uint8_t Dutymin_T1S1; + uint8_t Dutydefault_T1S1; + + uint8_t Dutymax_T1S2; + uint8_t Dutymin_T1S2; + uint8_t Dutydefault_T1S2; + + uint8_t Dutymax_T1S3; + uint8_t Dutymin_T1S3; + uint8_t Dutydefault_T1S3; + + uint8_t Dutymax_T2S1; + uint8_t Dutymin_T2S1; + uint8_t Dutydefault_T2S1; + + uint8_t Dutymax_T2S2; + uint8_t Dutymin_T2S2; + uint8_t Dutydefault_T2S2; + + uint8_t Dutymax_T2S3; + uint8_t Dutymin_T2S3; + uint8_t Dutydefault_T2S3; + + uint8_t Dutymax_T3S1; + uint8_t Dutymin_T3S1; + uint8_t Dutydefault_T3S1; + + uint8_t Dutymax_T3S2; + uint8_t Dutymin_T3S2; + uint8_t Dutydefault_T3S2; + + uint8_t Dutymax_T3S3; + uint8_t Dutymin_T3S3; + uint8_t Dutydefault_T3S3; +}Period_Type; + +typedef struct +{ + _iq24 ACVoltcali; + _iq24 ACVoltcaliMin; + _iq24 ACVoltcaliPrev; + _iq24 ACVoltcali_Square; + uint16_t TonEnable_cntset; + uint16_t TonEnable_cnt; + volatile uint8_t TonEnable; + + Zcross_Type Zero; + Period_Type PeriodCtl; + Phase_Type PhaseCtl; +}TRIAC_ctl_Type; + +typedef struct +{ + uint16_t SHkey_checkcnt; + uint16_t SHkey_checkinterval; + uint16_t SHkey_effcnt_thresh; + uint16_t SHkey_ineff_cntthresh; + uint16_t SHkey_effcnt1; + uint16_t SHkey_ineff_cnt1; + uint16_t SHkey_effcnt2; + uint16_t SHkey_ineff_cnt2; + uint16_t SHkey_Powerdown; + Truth_Verify_Type SHkey_Speedset; + + uint16_t SRkey_effcnt_thresh; + uint16_t SRkey_ineff_cntthresh; + uint16_t SRkey_effcnt; + uint16_t SRkey_ineff_cnt; + + Truth_Verify_Type Skeyeffective; + Truth_Verify_Type Skeystop; + uint8_t Skeystopcnt; + Direction_Type Skey_rank_Dir; + + uint8_t Tkey_rankset; + uint8_t Tkey_rank; + Direction_Type Tkey_rank_Dir; + Truth_Verify_Type Tkeycyc; + uint16_t Tkey_cyccntthresh; + uint16_t Tkey_shtcntthreshup; + uint16_t Tkey_shtcntthreshdown; + uint16_t Tkeycnt; + + uint16_t TCkey_effcnt_thresh; + uint16_t TCkey_ineff_cntthresh; + Truth_Verify_Type TCkeycold; + uint16_t TCkey_effcnt; + uint16_t TCkey_ineff_cnt; + Truth_Verify_Type Tkeyeffective; + + uint16_t ACkey_checkcnt; + uint16_t ACkey_checkinterval; + uint16_t ACkey_effcnt_thresh; + uint16_t ACkey_ineff_cntthresh; + uint16_t ACkey_effcnt; + uint16_t ACkey_ineff_cnt; + uint16_t ACkey_Poweron; + + uint16_t EEwritewaitset; + uint16_t EEwritewaitcnt; + uint8_t EEwritecycset; + uint8_t EEwritecyccnt; + uint8_t Keytowrite; + + Truth_Verify_Type Keymemreadmark; +} Key_Manager_Type; + +typedef struct +{ + uint16_t Fn; + _iq18 Vn; + _iq18 In; + _iq24 Flux; + uint16_t Pn; + _iq24 Rs; + _iq24 Ld; + _iq24 Lq; + _iq24 Rstotal; + _iq24 Inertia; + _iq24 Friction; + uint16_t Webase; + uint16_t Wmbase; + _iq18 Vbase; + _iq18 Ebase; + _iq18 Ibase; + _iq24 Fluxbase; + _iq24 Rbase; + _iq24 Lbase; + _iq18 Pbase; + _iq24 Tcoef; + _iq18 Tbase; + _iq24 Inertiabase; + _iq24 Frictionbase; +} Motor_Base_Type; + +typedef struct +{ + volatile Truth_Verify_Type Poweron; + uint16_t Poweron_CntThresh; + uint16_t Poweron_Cnt; + _iq24 Poweron_Volt; + _iq24 Poweroff_Volt1; + _iq24 Poweroff_Volt2; + _iq24 DCVoltAverSizeInv1; + _iq24 DCVoltAverSizeInv2; + _iq24 DCVoltAver; +} Powercontrol_Type; + +//电机整体状态结构体原型 +typedef struct +{ + Component_2R_Type VRef2R; + Component_2R_Type VRef2RC; + Component_2S_Type VRef2S; + Component_2S_Type VRef2SC; + Component_2R_Type CRef2R; + Component_3S_Type C3S; + Component_2S_Type C2S; + Component_2R_Type C2R_H; + Component_2R_Type C2R_L; + Component_2R_Type C2R; + Struct_Cossin_Type Cossin; + Component_2R_Type C2R_Obs; + Component_2S_Type C2S_Obs; + + LPF_First_Order_Type IdLPF1stH; + LPF_First_Order_Type IdLPF1stL; + + LPF_First_Order_Type IqLPF1stH; + LPF_First_Order_Type IqLPF1stL; + + LPF_First_Order_Type IdLPF1stObs; + LPF_First_Order_Type IqLPF1stObs; + + LPF_First_Order_Type IdLPF1stInj; + LPF_First_Order_Type IqLPF1stInj; +} Motor_Sructure_Type; + +//电机PID调节器结构体 +typedef struct +{ + PID_Structure_Type Speed; + PID_Structure_Type dCurr; + PID_Structure_Type qCurr; +} Motor_PID_Type; + +//LBG观测器结构体原型 +typedef struct +{ + LBG_Paramter_Type Para; + Speed_PLL_Type Speed_PLL; + LBG_Cal_Structure_Type Cal_Struc; + Observer_Adaptor_type Adaptor; + LBG_EMF_Init_Type EMF_InitPara; + BuffPara_Type SpeedBuffPara; +} Motor_LBG_Type; + +//定时管理结构体原型 +typedef struct +{ + Truth_Verify_Type Event_10ms; + uint16_t Event_10ms_cnt; + uint16_t Event_10ms_cntset; + + Truth_Verify_Type Event_1ms; + uint16_t Event_1ms_cnt; + uint16_t Event_1ms_cntset; + + Truth_Verify_Type Event_2s; + uint16_t Event_2s_cnt; + uint16_t Event_2s_cntset; +} Eventmanager_Type; + +typedef enum {NONE = 0, CHECK = 1, INTERVAL = 2, LAST = 3} Poweroncheckstage_Type; + +typedef struct +{ + Truth_Verify_Type Mark; + Poweroncheckstage_Type Stage; + Truth_Verify_Type Process; + + uint16_t Ledinttimeset; + uint8_t Ledintnum; + uint8_t Ledintnumset; + uint16_t Ledintnumtotal; + uint16_t Ledintnumtotalset; + Direction_Type Ledintdir; + + uint16_t Ledlasttimeset; + uint16_t Ledcnt; +} Poweroncheck_Type; + +typedef struct +{ + uint16_t StopwaitCnt; + uint16_t StopwaitSet; + + uint16_t FaultHoldingSet; + uint16_t FaultHoldingCnt; + + Truth_Verify_Type Faultstop; + + uint16_t reset_cnt; + Poweroncheck_Type PSC; +} Operation_Type; + + +//功率波动抑制结构体原型 +typedef struct +{ + _iq24 Power; + _iq24 PowerfilterH; + _iq24 PowerfilterL; + HPF_First_Order_Type Power_HPF1st; + LPF_First_Order_Type Power_LPF1st; + + PID_Structure_Type PowerPID; + _iq24 Kpdefine; + _iq24 Kidefine; + _iq24 Kddefine; + _iq24 Kpadj1; + _iq24 Kpadj2; + _iq24 Kpadj3; + _iq24 Kpadj; + + uint16_t Startcom_cntset; + uint16_t Startcom_cnt; + + _iq24 Speederrthre; + uint16_t Speedcolse_cntset; + uint16_t Speedclose_cnt; + + _iq24 Voltthre; + _iq24 Speedcom; +}Powercom_type; + +/* Exported constants -------------------------------------------------------*/ +#define SPEED_CONTROL_M 0x0001 +#define FIRST_START_M 0x0002 +#define STARTUP_FAILURE_M 0x0004 +#define SPEED_ABNORMAL_M 0x0008 +#define BRAKE_RES_ON_M 0x0010 +//#define MOTOR_OVER_HEAT_M 0x0020 +#define MOTOR_OVER_CURR_SOFT_M 0x0040 +#define DC_OVER_CURR_SOFT_M 0x0080 +#define DC_OVER_CURR_HARD_M 0x0100 +#define MOTOR_STALL_M 0x0200 +#define DC_OVER_VOLT 0x0400 +#define DC_UNDER_VOLT 0x0800 +//#define MOTOR_REVERSE_M 0x1000 +#define MOTOR_OVERLOAD_M 0x2000 +#define POSITION_FAILUE_M 0x4000 +#define PHASELOSS_FALUT 0x8000 + +#define NTC_OVER_ERR 0x0020 +#define NTC_OPEN_ERR 0x1000 + + +#define PI_2f 6.28318531 //2*PI float:35897932384626433832795 +#define PI_1_Q24 _IQ(3.14159265) //PI +#define PI_2_Q24 _IQ(6.28318531) //2*PI 7179586476925286766559 +#define PI_2_Q18 _IQ18(6.28318531) //2*PI +#define DIV_PI_2_Q24 _IQ(0.15915494) //1/(2*PI)309189533576888376337251 +#define PI_05_Q24 _IQ(1.57079633) //0.5*PI67948966192313216916398 +#define Three_Q24 _IQ(3.0) //3.0 +#define Three_Q18 _IQ18(3.0) //3.0 +#define Three_Q16 _IQ16(3.0) //3.0 +#define SQRT3_Q24 _IQ(1.73205081) //SQRT(3) +#define SQRT3_Q18 _IQ18(1.73205081) //SQRT(3) +#define SQRT3_Q16 _IQ16(1.732051) //SQRT(3) +#define SQRT_3 1.73205081 //SQRT(3) +#define SQRT2_Q24 _IQ(1.41421356) //SQRT(2) +#define UNIT_Q24 _IQ(1.0) //1.0 +#define HALF_Q24 _IQ(0.5) //0.5 +#define QUARD_Q24 _IQ(0.25) //0.5 +#define DIV_SQRT3_Q24 _IQ(0.57735027) //1/SQRT(3) +#define SQRT3_DIV2_Q24 _IQ(0.86602540) //SQRT(3) +#define SQRT_2DIV3_Q24 _IQ(0.81649658) //SQRT(2/3) +#define ONE_HALF_Q24 _IQ(1.50) //1.5 +#define DIV_MIN_Q24 _IQ(0.000001) + +#define U8_MAX ((uint8_t)255) +#define S8_MAX ((int8_t)127) +#define S8_MIN ((int8_t)-128) +#define U16_MAX ((uint16_t)65535u) +#define S16_MAX ((int16_t)32767) +#define S16_MIN ((int16_t)-32768) +#define U32_MAX ((uint32_t)4294967295uL) +#define S32_MAX ((int32_t)2147483647) +#define S32_MIN ((int32_t)-2147483648) + +#define SIN_TABLE_1024 {\ +0x00000000,0x0001921F,0x0003243A,0x0004B64D,0x00064855,0x0007DA4D,0x00096C32,0x000AFE00,\ +0x000C8FB2,0x000E2146,0x000FB2B7,0x00114401,0x0012D520,0x00146611,0x0015F6D0,0x00178758,\ +0x001917A6,0x001AA7B7,0x001C3785,0x001DC70E,0x001F564E,0x0020E540,0x002273E1,0x0024022D,\ +0x00259020,0x00271DB7,0x0028AAED,0x002A37BF,0x002BC428,0x002D5026,0x002EDBB3,0x003066CD,\ +0x0031F170,0x00337B97,0x00350540,0x00368E65,0x00381704,0x00399F19,0x003B269F,0x003CAD94,\ +0x003E33F2,0x003FB9B8,0x00413EE0,0x0042C367,0x00444749,0x0045CA83,0x00474D10,0x0048CEEE,\ +0x004A5018,0x004BD08B,0x004D5043,0x004ECF3B,0x00504D72,0x0051CAE2,0x00534789,0x0054C362,\ +0x00563E69,0x0057B89C,0x005931F7,0x005AAA75,0x005C2214,0x005D98D0,0x005F0EA4,0x0060838E,\ +0x0061F78A,0x00636A94,0x0064DCA9,0x00664DC5,0x0067BDE5,0x00692D04,0x006A9B20,0x006C0835,\ +0x006D7440,0x006EDF3C,0x00704927,0x0071B1FD,0x007319BA,0x0074805B,0x0075E5DD,0x00774A3C,\ +0x0078AD74,0x007A0F83,0x007B7065,0x007CD016,0x007E2E93,0x007F8BD9,0x0080E7E4,0x008242B1,\ +0x00839C3C,0x0084F483,0x00864B82,0x0087A135,0x0088F59A,0x008A48AD,0x008B9A6B,0x008CEAD0,\ +0x008E39D9,0x008F8784,0x0090D3CC,0x00921EAF,0x0093682A,0x0094B039,0x0095F6D9,0x00973C07,\ +0x00987FBF,0x0099C200,0x009B02C5,0x009C420C,0x009D7FD1,0x009EBC11,0x009FF6CA,0x00A12FF8,\ +0x00A26799,0x00A39DA8,0x00A4D224,0x00A6050A,0x00A73655,0x00A86604,0x00A99414,0x00AAC081,\ +0x00ABEB49,0x00AD1469,0x00AE3BDD,0x00AF61A4,0x00B085BA,0x00B1A81D,0x00B2C8C9,0x00B3E7BC,\ +0x00B504F3,0x00B6206B,0x00B73A22,0x00B85215,0x00B96841,0x00BA7CA4,0x00BB8F3A,0x00BCA002,\ +0x00BDAEF9,0x00BEBC1B,0x00BFC767,0x00C0D0D9,0x00C1D870,0x00C2DE28,0x00C3E200,0x00C4E3F4,\ +0x00C5E403,0x00C6E229,0x00C7DE65,0x00C8D8B3,0x00C9D112,0x00CAC77F,0x00CBBBF7,0x00CCAE79,\ +0x00CD9F02,0x00CE8D8F,0x00CF7A1F,0x00D064AF,0x00D14D3D,0x00D233C6,0x00D31848,0x00D3FAC2,\ +0x00D4DB31,0x00D5B992,0x00D695E4,0x00D77025,0x00D84852,0x00D91E6A,0x00D9F269,0x00DAC44F,\ +0x00DB941A,0x00DC61C6,0x00DD2D53,0x00DDF6BE,0x00DEBE05,0x00DF8327,0x00E04621,0x00E106F1,\ +0x00E1C597,0x00E28210,0x00E33C59,0x00E3F472,0x00E4AA59,0x00E55E0B,0x00E60F87,0x00E6BECC,\ +0x00E76BD7,0x00E816A7,0x00E8BF3B,0x00E96591,0x00EA09A6,0x00EAAB7A,0x00EB4B0B,0x00EBE858,\ +0x00EC835E,0x00ED1C1D,0x00EDB293,0x00EE46BE,0x00EED89D,0x00EF682F,0x00EFF573,0x00F08066,\ +0x00F10908,0x00F18F57,0x00F21352,0x00F294F8,0x00F31447,0x00F3913E,0x00F40BDD,0x00F48421,\ +0x00F4FA0A,0x00F56D97,0x00F5DEC6,0x00F64D96,0x00F6BA07,0x00F72417,0x00F78BC5,0x00F7F110,\ +0x00F853F7,0x00F8B47A,0x00F91297,0x00F96E4E,0x00F9C79D,0x00FA1E84,0x00FA7301,0x00FAC515,\ +0x00FB14BE,0x00FB61FB,0x00FBACCD,0x00FBF531,0x00FC3B27,0x00FC7EAF,0x00FCBFC9,0x00FCFE72,\ +0x00FD3AAB,0x00FD7474,0x00FDABCB,0x00FDE0B0,0x00FE1323,0x00FE4323,0x00FE70AF,0x00FE9BC8,\ +0x00FEC46D,0x00FEEA9C,0x00FF0E57,0x00FF2F9D,0x00FF4E6D,0x00FF6AC7,0x00FF84AB,0x00FF9C18,\ +0x00FFB10F,0x00FFC38E,0x00FFD397,0x00FFE128,0x00FFEC43,0x00FFF4E5,0x00FFFB10,0x00FFFEC4} + +#define MAG100_LIMIT_TABLE {\ +0x00FF017D,0x00FE05EC,0x00FD0D3D,0x00FC1764,0x00FB2451,0x00FA33F9,0x00F9464D,0x00F85B42,\ +0x00F772CA,0x00F68CDB,0x00F5A968,0x00F4C866,0x00F3E9CA,0x00F30D89,0x00F23399,0x00F15BEE,\ +0x00F08680,0x00EFB344,0x00EEE231,0x00EE133D,0x00ED4660,0x00EC7B90,0x00EBB2C4,0x00EAEBF5,\ +0x00EA2719,0x00E96429,0x00E8A31D,0x00E7E3ED,0x00E72691,0x00E66B02,0x00E5B138,0x00E4F92E,\ +0x00E442DB,0x00E38E38,0x00E2DB40,0x00E229EC,0x00E17A35,0x00E0CC15,0x00E01F86,0x00DF7482,\ +0x00DECB03,0x00DE2304,0x00DD7C7F,0x00DCD76D,0x00DC33CB,0x00DB9192,0x00DAF0BE,0x00DA5149,\ +0x00D9B32F,0x00D9166A,0x00D87AF6,0x00D7E0CE,0x00D747EE,0x00D6B050,0x00D619F2,0x00D584CD,\ +0x00D4F0DE,0x00D45E22,0x00D3CC92,0x00D33C2D,0x00D2ACEE,0x00D21ED0,0x00D191D0,0x00D105EB,\ +0x00D07B1C,0x00CFF161,0x00CF68B5,0x00CEE115,0x00CE5A7E,0x00CDD4ED,0x00CD505D,0x00CCCCCC,\ +0x00CC4A37,0x00CBC89B,0x00CB47F3,0x00CAC83F,0x00CA497A,0x00C9CBA1,0x00C94EB2,0x00C8D2AB,\ +0x00C85787,0x00C7DD45,0x00C763E1,0x00C6EB5A,0x00C673AC,0x00C5FCD5,0x00C586D3,0x00C511A2,\ +0x00C49D42,0x00C429AE,0x00C3B6E6,0x00C344E6,0x00C2D3AC,0x00C26336,0x00C1F383,0x00C1848F,\ +0x00C11658,0x00C0A8DD,0x00C03C1C,0x00BFD011,0x00BF64BD,0x00BEFA1B,0x00BE902B,0x00BE26EB,\ +0x00BDBE58,0x00BD5671,0x00BCEF34,0x00BC889F,0x00BC22B0,0x00BBBD66,0x00BB58BF,0x00BAF4BA,\ +0x00BA9153,0x00BA2E8B,0x00B9CC5F,0x00B96ACE,0x00B909D5,0x00B8A974,0x00B849AA,0x00B7EA73,\ +0x00B78BD0,0x00B72DBE,0x00B6D03C,0x00B67349,0x00B616E3,0x00B5BB09,0x00B55FB9,0x00B504F3,\ +0x00B4AAB4,0x00B450FC,0x00B3F7C8,0x00B39F19,0x00B346EC,0x00B2EF41,0x00B29816,0x00B24169,\ +0x00B1EB3B,0x00B19589,0x00B14052,0x00B0EB95,0x00B09752,0x00B04386,0x00AFF032,0x00AF9D53,\ +0x00AF4AE8,0x00AEF8F2,0x00AEA76E,0x00AE565B,0x00AE05B9,0x00ADB587,0x00AD65C3,0x00AD166C,\ +0x00ACC782,0x00AC7903,0x00AC2AEF,0x00ABDD45,0x00AB9003,0x00AB432A,0x00AAF6B7,0x00AAAAAA,\ +0x00AA5F03,0x00AA13BF,0x00A9C8DF,0x00A97E62,0x00A93446,0x00A8EA8B,0x00A8A130,0x00A85835,\ +0x00A80F98,0x00A7C758,0x00A77F76,0x00A737EF,0x00A6F0C4,0x00A6A9F3,0x00A6637D,0x00A61D5F,\ +0x00A5D799,0x00A5922C,0x00A54D15,0x00A50854,0x00A4C3E9,0x00A47FD3,0x00A43C11,0x00A3F8A2,\ +0x00A3B586,0x00A372BC,0x00A33044,0x00A2EE1D,0x00A2AC45,0x00A26ABE,0x00A22985,0x00A1E89B,\ +0x00A1A7FE,0x00A167AE,0x00A127AB,0x00A0E7F4,0x00A0A888,0x00A06967,0x00A02A90,0x009FEC03,\ +0x009FADBF,0x009F6FC3,0x009F3210,0x009EF4A4,0x009EB77E,0x009E7A9F,0x009E3E06,0x009E01B2,\ +0x009DC5A3,0x009D89D8,0x009D4E51,0x009D130D,0x009CD80C,0x009C9D4E,0x009C62D1,0x009C2895,\ +0x009BEE9B,0x009BB4E0,0x009B7B66,0x009B422B,0x009B092F,0x009AD072,0x009A97F3,0x009A5FB1,\ +0x009A27AD,0x0099EFE6,0x0099B85B,0x0099810C,0x009949F8,0x0099131F,0x0098DC82,0x0098A61E,\ +0x00986FF5,0x00983A05,0x0098044E,0x0097CECF,0x00979989,0x0097647B,0x00972FA5,0x0096FB06,\ +0x0096C69D,0x0096926B,0x00965E6F,0x00962AA9,0x0095F718,0x0095C3BC,0x00959094,0x00955DA1,\ +0x00952AE2,0x0094F857,0x0094C5FE,0x009493D9,0x009461E6,0x00943025,0x0093FE97,0x0093CD3A} + +#define MAG098_LIMIT_TABLE {\ +0x00FEF70F,0x00FDF14E,0x00FCEEAD,0x00FBEF1C,0x00FAF28C,0x00F9F8ED,0x00F90231,0x00F80E4B,\ +0x00F71D2C,0x00F62EC6,0x00F5430E,0x00F459F5,0x00F37370,0x00F28F73,0x00F1ADF2,0x00F0CEE1,\ +0x00EFF235,0x00EF17E4,0x00EE3FE2,0x00ED6A26,0x00EC96A5,0x00EBC555,0x00EAF62D,0x00EA2923,\ +0x00E95E2F,0x00E89546,0x00E7CE62,0x00E70978,0x00E64680,0x00E58573,0x00E4C648,0x00E408F8,\ +0x00E34D7B,0x00E293C9,0x00E1DBDB,0x00E125AB,0x00E07130,0x00DFBE66,0x00DF0D43,0x00DE5DC3,\ +0x00DDAFDE,0x00DD038F,0x00DC58D0,0x00DBAF99,0x00DB07E7,0x00DA61B2,0x00D9BCF5,0x00D919AB,\ +0x00D877CD,0x00D7D758,0x00D73846,0x00D69A92,0x00D5FE36,0x00D5632E,0x00D4C974,0x00D43106,\ +0x00D399DD,0x00D303F5,0x00D26F4A,0x00D1DBD8,0x00D1499A,0x00D0B88C,0x00D028AA,0x00CF99F0,\ +0x00CF0C5A,0x00CE7FE4,0x00CDF48B,0x00CD6A4A,0x00CCE11E,0x00CC5904,0x00CBD1F7,0x00CB4BF5,\ +0x00CAC6F9,0x00CA4302,0x00C9C00A,0x00C93E10,0x00C8BD10,0x00C83D06,0x00C7BDF1,0x00C73FCC,\ +0x00C6C295,0x00C64649,0x00C5CAE5,0x00C55066,0x00C4D6CA,0x00C45E0D,0x00C3E62E,0x00C36F29,\ +0x00C2F8FC,0x00C283A4,0x00C20F1F,0x00C19B6B,0x00C12884,0x00C0B66A,0x00C04518,0x00BFD48E,\ +0x00BF64C8,0x00BEF5C5,0x00BE8782,0x00BE19FD,0x00BDAD34,0x00BD4125,0x00BCD5CE,0x00BC6B2D,\ +0x00BC0140,0x00BB9804,0x00BB2F79,0x00BAC79B,0x00BA606A,0x00B9F9E3,0x00B99404,0x00B92ECC,\ +0x00B8CA39,0x00B8664A,0x00B802FB,0x00B7A04D,0x00B73E3C,0x00B6DCC8,0x00B67BEF,0x00B61BAF,\ +0x00B5BC07,0x00B55CF5,0x00B4FE77,0x00B4A08D,0x00B44334,0x00B3E66B,0x00B38A31,0x00B32E85,\ +0x00B2D364,0x00B278CD,0x00B21EC0,0x00B1C53B,0x00B16C3C,0x00B113C2,0x00B0BBCC,0x00B06458,\ +0x00B00D66,0x00AFB6F4,0x00AF6101,0x00AF0B8B,0x00AEB692,0x00AE6214,0x00AE0E11,0x00ADBA86,\ +0x00AD6773,0x00AD14D7,0x00ACC2B0,0x00AC70FE,0x00AC1FC0,0x00ABCEF4,0x00AB7E99,0x00AB2EAF,\ +0x00AADF34,0x00AA9027,0x00AA4187,0x00A9F354,0x00A9A58D,0x00A9582F,0x00A90B3B,0x00A8BEB0,\ +0x00A8728C,0x00A826CF,0x00A7DB78,0x00A79086,0x00A745F7,0x00A6FBCC,0x00A6B204,0x00A6689C,\ +0x00A61F96,0x00A5D6EF,0x00A58EA7,0x00A546BD,0x00A4FF31,0x00A4B801,0x00A4712D,0x00A42AB5,\ +0x00A3E496,0x00A39ED1,0x00A35965,0x00A31451,0x00A2CF94,0x00A28B2E,0x00A2471E,0x00A20363,\ +0x00A1BFFD,0x00A17CEA,0x00A13A2B,0x00A0F7BE,0x00A0B5A3,0x00A073D9,0x00A03260,0x009FF136,\ +0x009FB05C,0x009F6FD1,0x009F2F93,0x009EEFA3,0x009EB000,0x009E70A9,0x009E319D,0x009DF2DD,\ +0x009DB467,0x009D763B,0x009D3858,0x009CFABE,0x009CBD6C,0x009C8061,0x009C439E,0x009C0722,\ +0x009BCAEB,0x009B8EFA,0x009B534E,0x009B17E6,0x009ADCC3,0x009AA1E2,0x009A6745,0x009A2CEA,\ +0x0099F2D2,0x0099B8FA,0x00997F64,0x0099460E,0x00990CF8,0x0098D422,0x00989B8B,0x00986333,\ +0x00982B19,0x0097F33C,0x0097BB9D,0x0097843B,0x00974D16,0x0097162C,0x0096DF7E,0x0096A90B,\ +0x009672D3,0x00963CD6,0x00960712,0x0095D188,0x00959C37,0x0095671F,0x0095323F,0x0094FD98,\ +0x0094C927,0x009494EE,0x009460EC,0x00942D21,0x0093F98B,0x0093C62B,0x00939301,0x0093600B,\ +0x00932D4A,0x0092FABE,0x0092C865,0x00929640,0x0092644E,0x00923290,0x00920103,0x0091CFA9} + +#define MAG096_LIMIT_TABLE {\ +0x00FEEBF9,0x00FDDB69,0x00FCCE3B,0x00FBC45E,0x00FABDC2,0x00F9BA54,0x00F8BA06,0x00F7BCC6,\ +0x00F6C286,0x00F5CB36,0x00F4D6C8,0x00F3E52D,0x00F2F659,0x00F20A3C,0x00F120CB,0x00F039F8,\ +0x00EF55B8,0x00EE73FD,0x00ED94BC,0x00ECB7E9,0x00EBDD7A,0x00EB0563,0x00EA2F9A,0x00E95C14,\ +0x00E88AC8,0x00E7BBAA,0x00E6EEB2,0x00E623D7,0x00E55B0E,0x00E4944F,0x00E3CF92,0x00E30CCD,\ +0x00E24BF8,0x00E18D0B,0x00E0CFFF,0x00E014CA,0x00DF5B67,0x00DEA3CC,0x00DDEDF4,0x00DD39D6,\ +0x00DC876C,0x00DBD6AF,0x00DB2798,0x00DA7A21,0x00D9CE43,0x00D923F9,0x00D87B3B,0x00D7D404,\ +0x00D72E4F,0x00D68A15,0x00D5E751,0x00D545FD,0x00D4A614,0x00D40790,0x00D36A6D,0x00D2CEA6,\ +0x00D23435,0x00D19B15,0x00D10342,0x00D06CB7,0x00CFD76F,0x00CF4367,0x00CEB099,0x00CE1F01,\ +0x00CD8E9B,0x00CCFF63,0x00CC7155,0x00CBE46D,0x00CB58A6,0x00CACDFD,0x00CA446F,0x00C9BBF7,\ +0x00C93491,0x00C8AE3B,0x00C828F1,0x00C7A4AE,0x00C72171,0x00C69F35,0x00C61DF7,0x00C59DB4,\ +0x00C51E6A,0x00C4A013,0x00C422AF,0x00C3A639,0x00C32AAF,0x00C2B00E,0x00C23653,0x00C1BD7B,\ +0x00C14584,0x00C0CE6B,0x00C0582C,0x00BFE2C6,0x00BF6E36,0x00BEFA7A,0x00BE878E,0x00BE1571,\ +0x00BDA420,0x00BD3398,0x00BCC3D9,0x00BC54DE,0x00BBE6A6,0x00BB792E,0x00BB0C75,0x00BAA079,\ +0x00BA3536,0x00B9CAAC,0x00B960D8,0x00B8F7B8,0x00B88F49,0x00B8278B,0x00B7C07C,0x00B75A18,\ +0x00B6F45F,0x00B68F4E,0x00B62AE4,0x00B5C720,0x00B563FE,0x00B5017E,0x00B49F9D,0x00B43E5B,\ +0x00B3DDB5,0x00B37DAB,0x00B31E39,0x00B2BF5F,0x00B2611B,0x00B2036B,0x00B1A64F,0x00B149C4,\ +0x00B0EDC9,0x00B0925C,0x00B0377D,0x00AFDD2A,0x00AF8360,0x00AF2A20,0x00AED168,0x00AE7935,\ +0x00AE2188,0x00ADCA5E,0x00AD73B7,0x00AD1D91,0x00ACC7EB,0x00AC72C3,0x00AC1E19,0x00ABC9EB,\ +0x00AB7638,0x00AB22FF,0x00AAD03E,0x00AA7DF6,0x00AA2C23,0x00A9DAC6,0x00A989DE,0x00A93968,\ +0x00A8E965,0x00A899D3,0x00A84AB0,0x00A7FBFD,0x00A7ADB8,0x00A75FE0,0x00A71274,0x00A6C573,\ +0x00A678DC,0x00A62CAE,0x00A5E0E8,0x00A5958A,0x00A54A92,0x00A4FFFF,0x00A4B5D1,0x00A46C07,\ +0x00A4229F,0x00A3D99A,0x00A390F6,0x00A348B2,0x00A300CD,0x00A2B947,0x00A2721F,0x00A22B54,\ +0x00A1E4E5,0x00A19ED1,0x00A15919,0x00A113BA,0x00A0CEB4,0x00A08A07,0x00A045B2,0x00A001B3,\ +0x009FBE0B,0x009F7AB8,0x009F37BA,0x009EF510,0x009EB2BA,0x009E70B7,0x009E2F05,0x009DEDA5,\ +0x009DAC96,0x009D6BD7,0x009D2B68,0x009CEB47,0x009CAB75,0x009C6BF0,0x009C2CB8,0x009BEDCD,\ +0x009BAF2D,0x009B70D9,0x009B32CF,0x009AF510,0x009AB79A,0x009A7A6C,0x009A3D88,0x009A00EA,\ +0x0099C495,0x00998885,0x00994CBC,0x00991139,0x0098D5FB,0x00989B01,0x0098604B,0x009825D9,\ +0x0097EBAA,0x0097B1BE,0x00977813,0x00973EAB,0x00970583,0x0096CC9C,0x009693F5,0x00965B8D,\ +0x00962365,0x0095EB7C,0x0095B3D1,0x00957C63,0x00954533,0x00950E40,0x0094D78A,0x0094A110,\ +0x00946AD1,0x009434CD,0x0093FF05,0x0093C976,0x00939422,0x00935F07,0x00932A26,0x0092F57D,\ +0x0092C10C,0x00928CD4,0x009258D3,0x00922509,0x0091F176,0x0091BE1A,0x00918AF4,0x00915803,\ +0x00912548,0x0090F2C2,0x0090C070,0x00908E52,0x00905C69,0x00902AB3,0x008FF930,0x008FC7E0} + +#define MAG094_LIMIT_TABLE {\ +0x00FEE02E,0x00FDC420,0x00FCABBE,0x00FB96F7,0x00FA85B5,0x00F977E6,0x00F86D77,0x00F76657,\ +0x00F66274,0x00F561BE,0x00F46423,0x00F36995,0x00F27203,0x00F17D5E,0x00F08B99,0x00EF9CA3,\ +0x00EEB071,0x00EDC6F3,0x00ECE01E,0x00EBFBE4,0x00EB1A38,0x00EA3B10,0x00E95E5E,0x00E88417,\ +0x00E7AC30,0x00E6D69F,0x00E60357,0x00E53250,0x00E4637F,0x00E396DA,0x00E2CC56,0x00E203EC,\ +0x00E13D92,0x00E0793E,0x00DFB6E8,0x00DEF687,0x00DE3814,0x00DD7B85,0x00DCC0D3,0x00DC07F6,\ +0x00DB50E6,0x00DA9B9D,0x00D9E812,0x00D9363E,0x00D8861B,0x00D7D7A2,0x00D72ACD,0x00D67F93,\ +0x00D5D5F0,0x00D52DDD,0x00D48754,0x00D3E24F,0x00D33EC8,0x00D29CB9,0x00D1FC1D,0x00D15CEE,\ +0x00D0BF27,0x00D022C3,0x00CF87BC,0x00CEEE0E,0x00CE55B3,0x00CDBEA7,0x00CD28E4,0x00CC9467,\ +0x00CC012A,0x00CB6F2A,0x00CADE61,0x00CA4ECB,0x00C9C065,0x00C9332A,0x00C8A716,0x00C81C24,\ +0x00C79252,0x00C7099B,0x00C681FC,0x00C5FB70,0x00C575F5,0x00C4F186,0x00C46E20,0x00C3EBC0,\ +0x00C36A62,0x00C2EA03,0x00C26A9F,0x00C1EC34,0x00C16EBF,0x00C0F23C,0x00C076A8,0x00BFFC00,\ +0x00BF8242,0x00BF096A,0x00BE9176,0x00BE1A62,0x00BDA42D,0x00BD2ED3,0x00BCBA52,0x00BC46A7,\ +0x00BBD3D0,0x00BB61CA,0x00BAF093,0x00BA8028,0x00BA1086,0x00B9A1AD,0x00B93398,0x00B8C647,\ +0x00B859B6,0x00B7EDE3,0x00B782CD,0x00B71872,0x00B6AECE,0x00B645E0,0x00B5DDA6,0x00B5761F,\ +0x00B50F47,0x00B4A91D,0x00B443A0,0x00B3DECD,0x00B37AA2,0x00B3171E,0x00B2B43F,0x00B25202,\ +0x00B1F067,0x00B18F6C,0x00B12F0F,0x00B0CF4E,0x00B07027,0x00B01199,0x00AFB3A3,0x00AF5643,\ +0x00AEF976,0x00AE9D3D,0x00AE4195,0x00ADE67C,0x00AD8BF2,0x00AD31F5,0x00ACD883,0x00AC7F9B,\ +0x00AC273C,0x00ABCF64,0x00AB7812,0x00AB2144,0x00AACAFA,0x00AA7532,0x00AA1FEB,0x00A9CB23,\ +0x00A976D9,0x00A9230D,0x00A8CFBC,0x00A87CE6,0x00A82A8A,0x00A7D8A5,0x00A78738,0x00A73641,\ +0x00A6E5BF,0x00A695B1,0x00A64615,0x00A5F6EC,0x00A5A833,0x00A559E9,0x00A50C0E,0x00A4BEA1,\ +0x00A471A0,0x00A4250B,0x00A3D8E0,0x00A38D1F,0x00A341C7,0x00A2F6D7,0x00A2AC4D,0x00A26229,\ +0x00A2186B,0x00A1CF10,0x00A18619,0x00A13D84,0x00A0F550,0x00A0AD7D,0x00A0660A,0x00A01EF6,\ +0x009FD840,0x009F91E8,0x009F4BEC,0x009F064B,0x009EC106,0x009E7C1B,0x009E378A,0x009DF351,\ +0x009DAF70,0x009D6BE6,0x009D28B3,0x009CE5D6,0x009CA34D,0x009C6119,0x009C1F39,0x009BDDAC,\ +0x009B9C71,0x009B5B87,0x009B1AEF,0x009ADAA7,0x009A9AAE,0x009A5B05,0x009A1BAA,0x0099DC9C,\ +0x00999DDC,0x00995F68,0x00992141,0x0098E364,0x0098A5D3,0x0098688B,0x00982B8D,0x0097EED9,\ +0x0097B26C,0x00977647,0x00973A6A,0x0096FED4,0x0096C383,0x00968879,0x00964DB3,0x00961332,\ +0x0095D8F6,0x00959EFC,0x00956546,0x00952BD3,0x0094F2A1,0x0094B9B2,0x00948103,0x00944895,\ +0x00941067,0x0093D879,0x0093A0C9,0x00936959,0x00933227,0x0092FB33,0x0092C47C,0x00928E02,\ +0x009257C4,0x009221C3,0x0091EBFD,0x0091B672,0x00918123,0x00914C0D,0x00911732,0x0090E28F,\ +0x0090AE27,0x009079F6,0x009045FE,0x0090123E,0x008FDEB6,0x008FAB65,0x008F784A,0x008F4566,\ +0x008F12B8,0x008EE03F,0x008EADFC,0x008E7BEE,0x008E4A14,0x008E186E,0x008DE6FC,0x008DB5BE} + +#define MAG092_LIMIT_TABLE {\ +0x00FED39E,0x00FDAB55,0x00FC870C,0x00FB66AC,0x00FA4A1F,0x00F93150,0x00F81C2A,0x00F70A99,\ +0x00F5FC89,0x00F4F1E7,0x00F3EAA1,0x00F2E6A4,0x00F1E5E0,0x00F0E844,0x00EFEDBF,0x00EEF641,\ +0x00EE01BB,0x00ED101E,0x00EC215B,0x00EB3563,0x00EA4C2A,0x00E965A1,0x00E881BB,0x00E7A06C,\ +0x00E6C1A6,0x00E5E55F,0x00E50B8A,0x00E4341C,0x00E35F09,0x00E28C46,0x00E1BBCA,0x00E0ED89,\ +0x00E02179,0x00DF5791,0x00DE8FC6,0x00DDCA10,0x00DD0666,0x00DC44BD,0x00DB850F,0x00DAC751,\ +0x00DA0B7C,0x00D95187,0x00D8996C,0x00D7E321,0x00D72E9F,0x00D67BDF,0x00D5CADA,0x00D51B88,\ +0x00D46DE3,0x00D3C1E3,0x00D31783,0x00D26EBB,0x00D1C786,0x00D121DD,0x00D07DBA,0x00CFDB17,\ +0x00CF39EE,0x00CE9A3A,0x00CDFBF5,0x00CD5F19,0x00CCC3A2,0x00CC298A,0x00CB90CB,0x00CAF962,\ +0x00CA6348,0x00C9CE79,0x00C93AF1,0x00C8A8AB,0x00C817A1,0x00C787D1,0x00C6F935,0x00C66BC8,\ +0x00C5DF88,0x00C55470,0x00C4CA7B,0x00C441A6,0x00C3B9ED,0x00C3334C,0x00C2ADBF,0x00C22943,\ +0x00C1A5D4,0x00C1236F,0x00C0A20F,0x00C021B2,0x00BFA255,0x00BF23F3,0x00BEA68A,0x00BE2A17,\ +0x00BDAE96,0x00BD3405,0x00BCBA60,0x00BC41A5,0x00BBC9D0,0x00BB52DF,0x00BADCCE,0x00BA679C,\ +0x00B9F345,0x00B97FC7,0x00B90D1F,0x00B89B4B,0x00B82A48,0x00B7BA13,0x00B74AAB,0x00B6DC0C,\ +0x00B66E35,0x00B60122,0x00B594D3,0x00B52943,0x00B4BE72,0x00B4545D,0x00B3EB03,0x00B3825F,\ +0x00B31A72,0x00B2B338,0x00B24CB0,0x00B1E6D8,0x00B181AD,0x00B11D2F,0x00B0B95A,0x00B0562D,\ +0x00AFF3A6,0x00AF91C4,0x00AF3085,0x00AECFE6,0x00AE6FE7,0x00AE1085,0x00ADB1BF,0x00AD5393,\ +0x00ACF600,0x00AC9903,0x00AC3C9C,0x00ABE0C9,0x00AB8588,0x00AB2AD7,0x00AAD0B6,0x00AA7723,\ +0x00AA1E1C,0x00A9C5A0,0x00A96DAD,0x00A91643,0x00A8BF5F,0x00A86901,0x00A81327,0x00A7BDD0,\ +0x00A768FA,0x00A714A4,0x00A6C0CE,0x00A66D75,0x00A61A98,0x00A5C837,0x00A57650,0x00A524E2,\ +0x00A4D3EB,0x00A4836B,0x00A43361,0x00A3E3CB,0x00A394A8,0x00A345F8,0x00A2F7B9,0x00A2A9E9,\ +0x00A25C89,0x00A20F97,0x00A1C312,0x00A176F9,0x00A12B4B,0x00A0E006,0x00A0952B,0x00A04AB8,\ +0x00A000AD,0x009FB707,0x009F6DC7,0x009F24EB,0x009EDC73,0x009E945D,0x009E4CA9,0x009E0556,\ +0x009DBE63,0x009D77D0,0x009D319B,0x009CEBC3,0x009CA648,0x009C6129,0x009C1C66,0x009BD7FC,\ +0x009B93ED,0x009B5036,0x009B0CD7,0x009AC9D0,0x009A871F,0x009A44C4,0x009A02BF,0x0099C10E,\ +0x00997FB0,0x00993EA6,0x0098FDEE,0x0098BD88,0x00987D73,0x00983DAF,0x0097FE3A,0x0097BF14,\ +0x0097803C,0x009741B3,0x00970377,0x0096C587,0x009687E3,0x00964A8B,0x00960D7D,0x0095D0B9,\ +0x0095943F,0x0095580E,0x00951C26,0x0094E085,0x0094A52C,0x00946A1A,0x00942F4D,0x0093F4C7,\ +0x0093BA85,0x00938088,0x009346CF,0x00930D5A,0x0092D428,0x00929B38,0x0092628A,0x00922A1E,\ +0x0091F1F3,0x0091BA08,0x0091825E,0x00914AF3,0x009113C7,0x0090DCDA,0x0090A62B,0x00906FBA,\ +0x00903987,0x00900390,0x008FCDD5,0x008F9856,0x008F6313,0x008F2E0B,0x008EF93E,0x008EC4AB,\ +0x008E9052,0x008E5C32,0x008E284B,0x008DF49D,0x008DC127,0x008D8DE8,0x008D5AE2,0x008D2812,\ +0x008CF579,0x008CC316,0x008C90E9,0x008C5EF1,0x008C2D2F,0x008BFBA2,0x008BCA48,0x008B9923} + +//0.90限幅表定义,幅值平方限制范围2.8100 +#define MAG090_LIMIT_TABLE {\ +0x00FEC637,0x00FD90E6,0x00FC5FF1,0x00FB333E,0x00FA0AB4,0x00F8E63A,0x00F7C5BA,0x00F6A91C,\ +0x00F59049,0x00F47B2E,0x00F369B4,0x00F25BC8,0x00F15157,0x00F04A4D,0x00EF4697,0x00EE4625,\ +0x00ED48E4,0x00EC4EC4,0x00EB57B5,0x00EA63A7,0x00E97289,0x00E8844E,0x00E798E6,0x00E6B044,\ +0x00E5CA59,0x00E4E718,0x00E40675,0x00E32862,0x00E24CD2,0x00E173BB,0x00E09D10,0x00DFC8C5,\ +0x00DEF6D0,0x00DE2725,0x00DD59BB,0x00DC8E86,0x00DBC57D,0x00DAFE96,0x00DA39C7,0x00D97707,\ +0x00D8B64D,0x00D7F790,0x00D73AC7,0x00D67FEA,0x00D5C6F0,0x00D50FD1,0x00D45A86,0x00D3A706,\ +0x00D2F54B,0x00D2454D,0x00D19704,0x00D0EA6A,0x00D03F77,0x00CF9626,0x00CEEE6F,0x00CE484C,\ +0x00CDA3B6,0x00CD00A8,0x00CC5F1C,0x00CBBF0B,0x00CB206F,0x00CA8344,0x00C9E784,0x00C94D29,\ +0x00C8B42E,0x00C81C8D,0x00C78642,0x00C6F148,0x00C65D9A,0x00C5CB32,0x00C53A0D,0x00C4AA26,\ +0x00C41B78,0x00C38DFE,0x00C301B5,0x00C27699,0x00C1ECA4,0x00C163D3,0x00C0DC23,0x00C0558E,\ +0x00BFD011,0x00BF4BA9,0x00BEC852,0x00BE4608,0x00BDC4C7,0x00BD448D,0x00BCC555,0x00BC471C,\ +0x00BBC9DF,0x00BB4D9A,0x00BAD24C,0x00BA57EF,0x00B9DE81,0x00B96600,0x00B8EE68,0x00B877B6,\ +0x00B801E8,0x00B78CFA,0x00B718EA,0x00B6A5B5,0x00B63359,0x00B5C1D2,0x00B5511E,0x00B4E13C,\ +0x00B47227,0x00B403DE,0x00B3965E,0x00B329A5,0x00B2BDB0,0x00B2527E,0x00B1E80C,0x00B17E57,\ +0x00B1155E,0x00B0AD1F,0x00B04597,0x00AFDEC3,0x00AF78A3,0x00AF1335,0x00AEAE75,0x00AE4A62,\ +0x00ADE6FB,0x00AD843D,0x00AD2226,0x00ACC0B5,0x00AC5FE8,0x00ABFFBD,0x00ABA032,0x00AB4145,\ +0x00AAE2F6,0x00AA8541,0x00AA2826,0x00A9CBA3,0x00A96FB6,0x00A9145E,0x00A8B999,0x00A85F66,\ +0x00A805C2,0x00A7ACAE,0x00A75426,0x00A6FC2A,0x00A6A4B8,0x00A64DCF,0x00A5F76D,0x00A5A192,\ +0x00A54C3B,0x00A4F768,0x00A4A316,0x00A44F46,0x00A3FBF5,0x00A3A922,0x00A356CC,0x00A304F2,\ +0x00A2B392,0x00A262AC,0x00A2123E,0x00A1C247,0x00A172C6,0x00A123BA,0x00A0D522,0x00A086FC,\ +0x00A03947,0x009FEC03,0x009F9F2F,0x009F52C8,0x009F06CF,0x009EBB42,0x009E7021,0x009E256A,\ +0x009DDB1C,0x009D9136,0x009D47B8,0x009CFEA0,0x009CB5EE,0x009C6DA1,0x009C25B7,0x009BDE30,\ +0x009B970B,0x009B5047,0x009B09E3,0x009AC3DF,0x009A7E39,0x009A38F1,0x0099F405,0x0099AF76,\ +0x00996B42,0x00992769,0x0098E3E9,0x0098A0C2,0x00985DF4,0x00981B7C,0x0097D95C,0x00979791,\ +0x0097561C,0x009714FB,0x0096D42E,0x009693B4,0x0096538D,0x009613B7,0x0095D432,0x009594FE,\ +0x00955619,0x00951784,0x0094D93D,0x00949B44,0x00945D97,0x00942038,0x0093E324,0x0093A65C,\ +0x009369DE,0x00932DAA,0x0092F1C0,0x0092B61F,0x00927AC6,0x00923FB6,0x009204EC,0x0091CA69,\ +0x0091902C,0x00915634,0x00911C82,0x0090E314,0x0090A9EA,0x00907104,0x00903861,0x00900000,\ +0x008FC7E0,0x008F9003,0x008F5866,0x008F210A,0x008EE9ED,0x008EB310,0x008E7C72,0x008E4613,\ +0x008E0FF2,0x008DDA0E,0x008DA467,0x008D6EFD,0x008D39D0,0x008D04DE,0x008CD027,0x008C9BAC,\ +0x008C676B,0x008C3364,0x008BFF97,0x008BCC02,0x008B98A7,0x008B6585,0x008B329A,0x008AFFE7,\ +0x008ACD6B,0x008A9B26,0x008A6918,0x008A373F,0x008A059C,0x0089D42F,0x0089A2F7,0x008971F3} + +//0.88限幅表定义,幅值平方限制范围2.7744 +#define MAG088_LIMIT_TABLE {\ +0x00FEB7E6,0x00FD74AE,0x00FC3639,0x00FAFC68,0x00F9C71F,0x00F89642,0x00F769B8,0x00F64165,\ +0x00F51D31,0x00F3FD03,0x00F2E0C5,0x00F1C860,0x00F0B3BC,0x00EFA2C6,0x00EE9569,0x00ED8B8F,\ +0x00EC8527,0x00EB821D,0x00EA825F,0x00E985DB,0x00E88C80,0x00E7963D,0x00E6A302,0x00E5B2C0,\ +0x00E4C566,0x00E3DAE6,0x00E2F331,0x00E20E39,0x00E12BF2,0x00E04C4C,0x00DF6F3C,0x00DE94B4,\ +0x00DDBCA9,0x00DCE70E,0x00DC13D7,0x00DB42FA,0x00DA746C,0x00D9A821,0x00D8DE0F,0x00D8162B,\ +0x00D7506D,0x00D68CC9,0x00D5CB37,0x00D50BAD,0x00D44E22,0x00D3928E,0x00D2D8E8,0x00D22127,\ +0x00D16B43,0x00D0B734,0x00D004F3,0x00CF5477,0x00CEA5BA,0x00CDF8B3,0x00CD4D5D,0x00CCA3AF,\ +0x00CBFBA3,0x00CB5533,0x00CAB057,0x00CA0D0A,0x00C96B45,0x00C8CB02,0x00C82C3B,0x00C78EEB,\ +0x00C6F30B,0x00C65897,0x00C5BF88,0x00C527D9,0x00C49185,0x00C3FC87,0x00C368DA,0x00C2D678,\ +0x00C2455E,0x00C1B586,0x00C126EC,0x00C0998A,0x00C00D5E,0x00BF8262,0x00BEF892,0x00BE6FE9,\ +0x00BDE865,0x00BD6200,0x00BCDCB7,0x00BC5886,0x00BBD569,0x00BB535C,0x00BAD25C,0x00BA5265,\ +0x00B9D373,0x00B95584,0x00B8D893,0x00B85C9E,0x00B7E1A1,0x00B76798,0x00B6EE81,0x00B67659,\ +0x00B5FF1D,0x00B588C9,0x00B5135B,0x00B49ECF,0x00B42B23,0x00B3B855,0x00B34661,0x00B2D544,\ +0x00B264FD,0x00B1F588,0x00B186E3,0x00B1190B,0x00B0ABFE,0x00B03FBA,0x00AFD43C,0x00AF6981,\ +0x00AEFF88,0x00AE964F,0x00AE2DD2,0x00ADC60F,0x00AD5F06,0x00ACF8B3,0x00AC9314,0x00AC2E27,\ +0x00ABC9EB,0x00AB665D,0x00AB037B,0x00AAA144,0x00AA3FB5,0x00A9DECD,0x00A97E89,0x00A91EE8,\ +0x00A8BFE9,0x00A86189,0x00A803C6,0x00A7A6A0,0x00A74A14,0x00A6EE20,0x00A692C3,0x00A637FC,\ +0x00A5DDC9,0x00A58427,0x00A52B17,0x00A4D296,0x00A47AA2,0x00A4233A,0x00A3CC5E,0x00A3760A,\ +0x00A3203F,0x00A2CAFA,0x00A2763A,0x00A221FE,0x00A1CE45,0x00A17B0D,0x00A12854,0x00A0D61A,\ +0x00A0845E,0x00A0331E,0x009FE258,0x009F920D,0x009F423A,0x009EF2DE,0x009EA3F8,0x009E5587,\ +0x009E078B,0x009DBA01,0x009D6CE9,0x009D2041,0x009CD409,0x009C883F,0x009C3CE3,0x009BF1F4,\ +0x009BA76F,0x009B5D56,0x009B13A5,0x009ACA5D,0x009A817D,0x009A3903,0x0099F0EF,0x0099A93F,\ +0x009961F3,0x00991B0B,0x0098D484,0x00988E5E,0x00984898,0x00980332,0x0097BE2B,0x00977981,\ +0x00973534,0x0096F143,0x0096ADAD,0x00966A72,0x00962790,0x0095E508,0x0095A2D7,0x009560FE,\ +0x00951F7C,0x0094DE4F,0x00949D78,0x00945CF5,0x00941CC5,0x0093DCE9,0x00939D5F,0x00935E27,\ +0x00931F40,0x0092E0A9,0x0092A261,0x00926469,0x009226BF,0x0091E962,0x0091AC53,0x00916F90,\ +0x00913319,0x0090F6EC,0x0090BB0B,0x00907F73,0x00904425,0x00900920,0x008FCE63,0x008F93ED,\ +0x008F59BF,0x008F1FD7,0x008EE635,0x008EACD8,0x008E73C0,0x008E3AED,0x008E025D,0x008DCA11,\ +0x008D9207,0x008D5A40,0x008D22BA,0x008CEB76,0x008CB472,0x008C7DAF,0x008C472B,0x008C10E7,\ +0x008BDAE1,0x008BA51A,0x008B6F90,0x008B3A44,0x008B0535,0x008AD062,0x008A9BCC,0x008A6771,\ +0x008A3351,0x0089FF6C,0x0089CBC1,0x00899850,0x00896518,0x0089321A,0x0088FF54,0x0088CCC6,\ +0x00889A70,0x00886852,0x0088366A,0x008804B9,0x0087D33F,0x0087A1FA,0x008770EB,0x00874010} + +//0.86限幅表定义,幅值平方限制范围2.7396 +#define MAG086_LIMIT_TABLE {\ +0x00FEA895,0x00FD5683,0x00FC09A5,0x00FAC1DA,0x00F97F01,0x00F840FA,0x00F707A8,0x00F5D2ED,\ +0x00F4A2AB,0x00F376C9,0x00F24F2B,0x00F12BB8,0x00F00C57,0x00EEF0EF,0x00EDD96A,0x00ECC5B2,\ +0x00EBB5AF,0x00EAA94E,0x00E9A079,0x00E89B1D,0x00E79927,0x00E69A83,0x00E59F21,0x00E4A6ED,\ +0x00E3B1D8,0x00E2BFD0,0x00E1D0C5,0x00E0E4A9,0x00DFFB6B,0x00DF14FD,0x00DE3150,0x00DD5057,\ +0x00DC7204,0x00DB964A,0x00DABD1C,0x00D9E66D,0x00D91232,0x00D8405E,0x00D770E6,0x00D6A3BE,\ +0x00D5D8DC,0x00D51036,0x00D449C0,0x00D38571,0x00D2C33E,0x00D2031F,0x00D14509,0x00D088F3,\ +0x00CFCED6,0x00CF16A7,0x00CE605E,0x00CDABF4,0x00CCF95F,0x00CC4899,0x00CB9999,0x00CAEC57,\ +0x00CA40CD,0x00C996F4,0x00C8EEC3,0x00C84834,0x00C7A341,0x00C6FFE3,0x00C65E14,0x00C5BDCD,\ +0x00C51F08,0x00C481BE,0x00C3E5EB,0x00C34B89,0x00C2B291,0x00C21AFF,0x00C184CC,0x00C0EFF4,\ +0x00C05C71,0x00BFCA3F,0x00BF3958,0x00BEA9B7,0x00BE1B59,0x00BD8E37,0x00BD024E,0x00BC7799,\ +0x00BBEE13,0x00BB65B9,0x00BADE86,0x00BA5876,0x00B9D385,0x00B94FAF,0x00B8CCEF,0x00B84B44,\ +0x00B7CAA7,0x00B74B17,0x00B6CC8E,0x00B64F0A,0x00B5D288,0x00B55703,0x00B4DC78,0x00B462E5,\ +0x00B3EA46,0x00B37297,0x00B2FBD6,0x00B285FF,0x00B21110,0x00B19D06,0x00B129DD,0x00B0B793,\ +0x00B04625,0x00AFD591,0x00AF65D3,0x00AEF6E9,0x00AE88D1,0x00AE1B87,0x00ADAF0A,0x00AD4356,\ +0x00ACD86A,0x00AC6E43,0x00AC04DF,0x00AB9C3B,0x00AB3454,0x00AACD2A,0x00AA66BA,0x00AA0100,\ +0x00A99BFD,0x00A937AC,0x00A8D40D,0x00A8711C,0x00A80ED9,0x00A7AD41,0x00A74C52,0x00A6EC0B,\ +0x00A68C69,0x00A62D6B,0x00A5CF0F,0x00A57152,0x00A51434,0x00A4B7B3,0x00A45BCC,0x00A4007E,\ +0x00A3A5C8,0x00A34BA8,0x00A2F21C,0x00A29923,0x00A240BB,0x00A1E8E2,0x00A19198,0x00A13ADA,\ +0x00A0E4A7,0x00A08EFE,0x00A039DD,0x009FE544,0x009F912F,0x009F3D9F,0x009EEA91,0x009E9805,\ +0x009E45F9,0x009DF46B,0x009DA35C,0x009D52C8,0x009D02B0,0x009CB312,0x009C63EC,0x009C153D,\ +0x009BC705,0x009B7942,0x009B2BF3,0x009ADF17,0x009A92AD,0x009A46B3,0x0099FB29,0x0099B00E,\ +0x00996560,0x00991B1E,0x0098D148,0x009887DC,0x00983EDA,0x0097F640,0x0097AE0E,0x00976642,\ +0x00971EDC,0x0096D7DA,0x0096913C,0x00964B01,0x00960528,0x0095BFB0,0x00957A98,0x009535DF,\ +0x0094F185,0x0094AD88,0x009469E9,0x009426A5,0x0093E3BC,0x0093A12D,0x00935EF9,0x00931D1C,\ +0x0092DB98,0x00929A6B,0x00925995,0x00921914,0x0091D8E9,0x00919911,0x0091598D,0x00911A5C,\ +0x0090DB7D,0x00909CF0,0x00905EB3,0x009020C7,0x008FE329,0x008FA5DB,0x008F68DB,0x008F2C28,\ +0x008EEFC2,0x008EB3A8,0x008E77D9,0x008E3C56,0x008E011D,0x008DC62E,0x008D8B88,0x008D512A,\ +0x008D1714,0x008CDD46,0x008CA3BF,0x008C6A7E,0x008C3182,0x008BF8CC,0x008BC05A,0x008B882D,\ +0x008B5043,0x008B189B,0x008AE137,0x008AAA14,0x008A7333,0x008A3C93,0x008A0633,0x0089D013,\ +0x00899A33,0x00896492,0x00892F2F,0x0088FA0A,0x0088C523,0x00889079,0x00885C0C,0x008827DB,\ +0x0087F3E5,0x0087C02B,0x00878CAC,0x00875967,0x0087265C,0x0086F38B,0x0086C0F3,0x00868E93,\ +0x00865C6C,0x00862A7D,0x0085F8C6,0x0085C745,0x008595FB,0x008564E8,0x0085340A,0x00850363} + +/* Exported macro ------------------------------------------------------------*/ +#define _IQMPY_MACRO(A,B) (signed long)( ((signed long long)A *B )>>24) +#define _IQ18MPY_MACRO(A,B) (signed long)( ((signed long long)A *B )>>18) +#define _IQ16MPY_MACRO(A,B) (signed long)( ((signed long long)A *B )>>16) + +/* Exported functions ------------------------------------------------------- */ +#endif diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M1_Motor_Parameter.h b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M1_Motor_Parameter.h new file mode 100644 index 0000000..a990f9c --- /dev/null +++ b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M1_Motor_Parameter.h @@ -0,0 +1,61 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : M1_Motor_Parameter.h + * Author : WCH + * Version : V1.0.0 + * Date : 2026/04/23 + * Description : Definition of motor parameters file. +********************************************************************************* +* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ + +#ifndef __M1_MOTOR_PARAMETER_H +#define __M1_MOTOR_PARAMETER_H +#define RATED_FREQ_M 1833 +#define RATED_VOLT_M _IQ18(220) +#define RATED_CURR_M _IQ18(1) +#define POLEPARE_M 1 +#define ROTOR_FLUX_M _IQ(0.00930) +#define STATOR_RES_M _IQ(25.24) +#define STATOR_LD_M _IQ(0.0019301) +#define STATOR_LQ_M _IQ(0.0054236) + +#define INERTIA_M _IQ(0.00002) +#define FRICTION_M _IQ(0.0001) + +#define STATOR_RES_TOTAL_M (STATOR_RES_M + _IQ(2.0)) + +#define IDQLPF_CF_HIGH_M 600 +#define IDQLPF_CF_LOW_M 200 +#define IDQLPF_PERIOD_M LBG_CAL_PERIOD_M +#define IDQLPF_WcT_HIGH_M _IQmpyI32(_IQmpy(IDQLPF_PERIOD_M,PI_2_Q24),IDQLPF_CF_HIGH_M) +#define IDQLPF_WcT_LOW_M _IQmpyI32(_IQmpy(IDQLPF_PERIOD_M,PI_2_Q24),IDQLPF_CF_LOW_M) + +#define IDQLPF_CF_OBSERVER_M 1200 +#define IDQLPF_PERIOD_OBSERVER_M LBG_CAL_PERIOD_M +#define IDQLPF_WcT_OBSERVER_M _IQmpyI32(_IQmpy(IDQLPF_PERIOD_OBSERVER_M,PI_2_Q24),IDQLPF_CF_OBSERVER_M) + +#define IDQLPF_CF_INITIAL_M 200 +#define IDQLPF_PERIOD_INITIAL_M LBG_CAL_PERIOD_M +#define IDQLPF_WcT_INITIAL_M _IQmpyI32(_IQmpy(IDQLPF_PERIOD_INITIAL_M,PI_2_Q24),IDQLPF_CF_INITIAL_M) + +/* Exported variables -------------------------------------------------------*/ +extern Motor_Sructure_Type MStruc_M; +extern Motor_Base_Type MBase_M; +extern Runningstatus_Type RunningStatus_M; +extern volatile uint16_t System_Status_Global; + +/* Exported macro -----------------------------------------------------------*/ +/* Exported functions -------------------------------------------------------*/ +void Motor_Prameter_Define(Motor_Base_Type *Basestruc); + +void Motor_Status_Initial_M(Motor_Sructure_Type *MStruc); + +void Global_Status_Initial(void); + +void Motor_FilerPara_Cal_M(Motor_Sructure_Type *MStruc); + +void Motor_BaseCal_M(Motor_Base_Type *Basestruc); + +#endif diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M1_Motor_Parameter_Init.c b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M1_Motor_Parameter_Init.c new file mode 100644 index 0000000..b517551 --- /dev/null +++ b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M1_Motor_Parameter_Init.c @@ -0,0 +1,149 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : M1_Motor_Parameter_Init.h + * Author : WCH + * Version : V1.0.0 + * Date : 2026/04/23 + * Description : Motor parameters and state initialization. +********************************************************************************* +* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ + +#include "M0_Control_Library.h" +Motor_Sructure_Type MStruc_M; +Motor_Base_Type MBase_M; +Runningstatus_Type RunningStatus_M; +volatile uint16_t System_Status_Global; + +/****************************************************************************** +* Function Name : Motor_Prameter_Define +* Description : Motor Prameter Define +* Input : Pointer to motor base value parameter structure +* Output : None +* Return : None +******************************************************************************/ +void Motor_Prameter_Define(Motor_Base_Type *Basestruc) +{ + + Basestruc->Fn = RATED_FREQ_M; + Basestruc->Vn = RATED_VOLT_M; + Basestruc->In = RATED_CURR_M; + Basestruc->Flux = ROTOR_FLUX_M; + Basestruc->Pn = POLEPARE_M; + Basestruc->Rs = STATOR_RES_M; + Basestruc->Ld = STATOR_LD_M; + Basestruc->Lq = STATOR_LQ_M; + Basestruc->Rstotal = STATOR_RES_TOTAL_M; + Basestruc->Inertia = INERTIA_M; + Basestruc->Friction = FRICTION_M; +} + +/****************************************************************************** +* Function Name : Motor_Status_Initial_M +* Description : Motor Status Initialization +* Input : Pointer to the motor overall status structure +* Output : None +* Return : None +******************************************************************************/ +void Motor_Status_Initial_M(Motor_Sructure_Type *MStruc) +{ + MStruc->VRef2R.cd = _IQ(0.0); + MStruc->VRef2R.cq = _IQ(0.0); + MStruc->VRef2R.peak = _IQ(0.0); + MStruc->VRef2RC.cd = _IQ(0.0); + MStruc->VRef2RC.cq = _IQ(0.0); + MStruc->VRef2RC.peak = _IQ(0.0); + MStruc->VRef2S.Alpha = _IQ(0.0); + MStruc->VRef2S.Beta = _IQ(0.0); + MStruc->VRef2SC.Alpha = _IQ(0.0); + MStruc->VRef2SC.Beta = _IQ(0.0); + MStruc->CRef2R.cd = _IQ(0.0); + MStruc->CRef2R.cq = _IQ(0.0); + MStruc->CRef2R.peak = _IQ(0.0); + MStruc->C3S.PhaseA = _IQ(0.0); + MStruc->C3S.PhaseB = _IQ(0.0); + MStruc->C3S.PhaseC = _IQ(0.0); + MStruc->C2S.Alpha = _IQ(0.0); + MStruc->C2S.Beta = _IQ(0.0); + + MStruc->C2R_H.cd = _IQ(0.0); + MStruc->C2R_H.cq = _IQ(0.0); + MStruc->C2R_L.cd = _IQ(0.0); + MStruc->C2R_L.cq = _IQ(0.0); + MStruc->C2R.cd = _IQ(0.0); + MStruc->C2R.cq = _IQ(0.0); + + MStruc->C2R_Obs.cd = _IQ(0.0); + MStruc->C2R_Obs.cq = _IQ(0.0); + MStruc->C2S_Obs.Alpha = _IQ(0.0); + MStruc->C2S_Obs.Beta = _IQ(0.0); + + MStruc->IdLPF1stH.Out_Pre = _IQ(0.0); + MStruc->IdLPF1stH.Out_New = _IQ(0.0); + MStruc->IdLPF1stL.Out_Pre = _IQ(0.0); + MStruc->IdLPF1stL.Out_New = _IQ(0.0); + + MStruc->IqLPF1stH.Out_Pre = _IQ(0.0); + MStruc->IqLPF1stH.Out_New = _IQ(0.0); + MStruc->IqLPF1stL.Out_Pre = _IQ(0.0); + MStruc->IqLPF1stL.Out_New = _IQ(0.0); + + MStruc->IdLPF1stObs.Out_Pre = _IQ(0.0); + MStruc->IdLPF1stObs.Out_New = _IQ(0.0); + MStruc->IqLPF1stObs.Out_Pre = _IQ(0.0); + MStruc->IqLPF1stObs.Out_New = _IQ(0.0); + + MStruc->IdLPF1stInj.Out_Pre = _IQ(0.0); + MStruc->IdLPF1stInj.Out_New = _IQ(0.0); + MStruc->IqLPF1stInj.Out_Pre = _IQ(0.0); + MStruc->IqLPF1stInj.Out_New = _IQ(0.0); + +} + +/****************************************************************************** +* Function Name : Global_Status_Initial +* Description : Initialization of system status and motor operation status +* Input : None +* Output : None +* Return : None +******************************************************************************/ +void Global_Status_Initial(void) +{ + System_Status_Global |= SPEED_CONTROL_M; + System_Status_Global |= FIRST_START_M; + RunningStatus_M = IDLE; +} + +/****************************************************************************** +* Function Name : Motor_FilerPara_Cal_M +* Description : Motor Phase Filter Parameter Initialization +* Input : Pointer to the motor overall status structure +* Output : None +* Return : None +******************************************************************************/ +void Motor_FilerPara_Cal_M(Motor_Sructure_Type *MStruc) +{ + + MStruc->IdLPF1stH.Input_Coef = _IQdiv(IDQLPF_WcT_HIGH_M,(IDQLPF_WcT_HIGH_M + UNIT_Q24)); + MStruc->IdLPF1stH.Output_Coef = _IQdiv(UNIT_Q24,(IDQLPF_WcT_HIGH_M + UNIT_Q24)); + MStruc->IdLPF1stL.Input_Coef = _IQdiv(IDQLPF_WcT_LOW_M,(IDQLPF_WcT_LOW_M + UNIT_Q24)); + MStruc->IdLPF1stL.Output_Coef = _IQdiv(UNIT_Q24,(IDQLPF_WcT_LOW_M + UNIT_Q24)); + + MStruc->IqLPF1stH.Input_Coef = _IQdiv(IDQLPF_WcT_HIGH_M,(IDQLPF_WcT_HIGH_M + UNIT_Q24)); + MStruc->IqLPF1stH.Output_Coef = _IQdiv(UNIT_Q24,(IDQLPF_WcT_HIGH_M + UNIT_Q24)); + MStruc->IqLPF1stL.Input_Coef = _IQdiv(IDQLPF_WcT_LOW_M,(IDQLPF_WcT_LOW_M + UNIT_Q24)); + MStruc->IqLPF1stL.Output_Coef = _IQdiv(UNIT_Q24,(IDQLPF_WcT_LOW_M + UNIT_Q24)); + + MStruc->IdLPF1stObs.Input_Coef = _IQdiv(IDQLPF_WcT_OBSERVER_M,(IDQLPF_WcT_OBSERVER_M + UNIT_Q24)); + MStruc->IdLPF1stObs.Output_Coef = _IQdiv(UNIT_Q24,(IDQLPF_WcT_OBSERVER_M + UNIT_Q24)); + + MStruc->IqLPF1stObs.Input_Coef = _IQdiv(IDQLPF_WcT_OBSERVER_M,(IDQLPF_WcT_OBSERVER_M + UNIT_Q24)); + MStruc->IqLPF1stObs.Output_Coef = _IQdiv(UNIT_Q24,(IDQLPF_WcT_OBSERVER_M + UNIT_Q24)); + + MStruc->IdLPF1stInj.Input_Coef = _IQdiv(IDQLPF_WcT_INITIAL_M,(IDQLPF_WcT_INITIAL_M + UNIT_Q24)); + MStruc->IdLPF1stInj.Output_Coef = _IQdiv(UNIT_Q24,(IDQLPF_WcT_INITIAL_M + UNIT_Q24)); + + MStruc->IqLPF1stInj.Input_Coef = _IQdiv(IDQLPF_WcT_INITIAL_M,(IDQLPF_WcT_INITIAL_M + UNIT_Q24)); + MStruc->IqLPF1stInj.Output_Coef = _IQdiv(UNIT_Q24,(IDQLPF_WcT_INITIAL_M + UNIT_Q24)); +} diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M2_PID_Parameter.h b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M2_PID_Parameter.h new file mode 100644 index 0000000..deb3b2c --- /dev/null +++ b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M2_PID_Parameter.h @@ -0,0 +1,96 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : M2_PID_Parameter.h + * Author : WCH + * Version : V1.0.0 + * Date : 2026/04/23 + * Description : Definition of PID control parameters. +********************************************************************************* +* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ + +#ifndef __M2_MOTOR_PID_H +#define __M2_MOTOR_PID_H +#define SPEED_REGULATOR_FREQ_M SPEED_LOOP_CAL_FREQ +#define SPEED_REGULATOR_PERIOD_M (_IQ(1.0)/SPEED_REGULATOR_FREQ_M) +#define SPEED_REGULATOR_KP_M _IQ(0.000006) +#define SPEED_REGULATOR_KI_M _IQ(0.000006) +#define SPEED_REGULATOR_KD_M _IQ(0.0) +#define SPEED_REGULATOR_KPADJ_M _IQ(1.0) +#define SPEED_REGULATOR_KIADJ_M _IQ(1.0) +#define SPEED_REGULATOR_KDADJ_M _IQ(1.0) +#define SPEED_REGULATOR_ULIM_M _IQ(0.8) +#define SPEED_REGULATOR_LLIM_M _IQ(-0.1) +#define SPEED_REGULATOR_DLIM_M _IQ(1.0) + + +#ifdef MAG100_TABLE_USED +#define MAX_MODULATIONSQUARE _IQ(1.0000) +#define MAX_MODULATION _IQ(1.0000) +#elif defined MAG098_TABLE_USED +#define MAX_MODULATIONSQUARE _IQ(0.9604) +#define MAX_MODULATION _IQ(0.9800) +#elif defined MAG096_TABLE_USED +#define MAX_MODULATIONSQUARE _IQ(0.9216) +#define MAX_MODULATION _IQ(0.9600) +#elif defined MAG094_TABLE_USED +#define MAX_MODULATIONSQUARE _IQ(0.8836) +#define MAX_MODULATION _IQ(0.9400) +#elif defined MAG092_TABLE_USED +#define MAX_MODULATIONSQUARE _IQ(0.8464) +#define MAX_MODULATION _IQ(0.9200) +#elif defined MAG090_TABLE_USED +#define MAX_MODULATIONSQUARE _IQ(0.8100) +#define MAX_MODULATION _IQ(0.9000) +#elif defined MAG088_TABLE_USED +#define MAX_MODULATIONSQUARE _IQ(0.7744) +#define MAX_MODULATION _IQ(0.8800) +#elif defined MAG086_TABLE_USED +#define MAX_MODULATIONSQUARE _IQ(0.7396) +#define MAX_MODULATION _IQ(0.8600) +#endif + +#define CURR_REGULATOR_FREQ_M FREQ_SVPWM +#define CURR_REGULATOR_BW_M (uint16_t)(PI_2f * 200) + +#define DAXIS_CURR_REGULATOR_KD_M _IQ(0.0) +#define DAXIS_CURR_REGULATOR_KPADJ_M _IQ(5.0) +#define DAXIS_CURR_REGULATOR_KIADJ_M _IQ(1.0) +#define DAXIS_CURR_REGULATOR_KDADJ_M _IQ(1.0) +#define DAXIS_CURR_REGULATOR_ULIM_M _IQ(0.25) +#define DAXIS_CURR_REGULATOR_LLIM_M _IQ(-0.25) +#define DAXIS_CURR_REGULATOR_DLIM_M _IQ(1.0) + +#define QAXIS_CURR_REGULATOR_KD_M _IQ(0.0) +#define QAXIS_CURR_REGULATOR_KPADJ_M _IQ(5.0) +#define QAXIS_CURR_REGULATOR_KIADJ_M _IQ(1.0) +#define QAXIS_CURR_REGULATOR_KDADJ_M _IQ(1.0) +#define QAXIS_CURR_REGULATOR_ULIM_M MAX_MODULATION +#define QAXIS_CURR_REGULATOR_LLIM_M (-MAX_MODULATION) +#define QAXIS_CURR_REGULATOR_DLIM_M _IQ(1.0) + + +#define DAXIS_CURR_REF_INIT1_M _IQ(0.3) +#define DAXIS_CURR_REF_INIT2_M _IQ(0.15) +#define DAXIS_CURR_REF_STEP1_M _IQ(0.0002) +#define DAXIS_CURR_REF_STEP2_M _IQ(0.00002) +#define DAXIS_CURR_WEAK_SPEED_M _IQ(1.5) + +/* Exported variables -------------------------------------------------------*/ +extern Motor_PID_Type Mpid_M; +extern DCurrProcess_Type DCurrProcess_M; +extern _iq24 Magnitude_table[]; + + +/* Exported macro -----------------------------------------------------------*/ +/* Exported functions -------------------------------------------------------*/ +void PID_Prameter_Define(Motor_PID_Type * Mpid); + +void PID_Output_Init(Motor_PID_Type * Mpid); + +void PID_ParaBase_Cal_M(Motor_Base_Type *Basestruc,Motor_PID_Type * Mpid); + +void DCurrProcess_Parameter_Define(DCurrProcess_Type * DCurrProcess); + +#endif diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M2_PID_Parameter_Initl.c b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M2_PID_Parameter_Initl.c new file mode 100644 index 0000000..6e76ce5 --- /dev/null +++ b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M2_PID_Parameter_Initl.c @@ -0,0 +1,137 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : M2_PID_Parameter_Initl.c + * Author : WCH + * Version : V1.0.0 + * Date : 2026/04/23 + * Description : PID control structure definition and state initialization. +********************************************************************************* +* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ + +#include "M0_Control_Library.h" +Motor_PID_Type Mpid_M; +DCurrProcess_Type DCurrProcess_M; + +#ifdef MAG100_TABLE_USED +_iq24 Magnitude_table[256] = MAG100_LIMIT_TABLE; +#elif defined MAG098_TABLE_USED +_iq24 Magnitude_table[256] = MAG098_LIMIT_TABLE; +#elif defined MAG096_TABLE_USED +_iq24 Magnitude_table[256] = MAG096_LIMIT_TABLE; +#elif defined MAG094_TABLE_USED +_iq24 Magnitude_table[256] = MAG094_LIMIT_TABLE; +#elif defined MAG092_TABLE_USED +_iq24 Magnitude_table[256] = MAG092_LIMIT_TABLE; +#elif defined MAG090_TABLE_USED +_iq24 Magnitude_table[256] = MAG090_LIMIT_TABLE; +#elif defined MAG088_TABLE_USED +_iq24 Magnitude_table[256] = MAG088_LIMIT_TABLE; +#elif defined MAG086_TABLE_USED +_iq24 Magnitude_table[256] = MAG086_LIMIT_TABLE; +#endif + +/****************************************************************************** +* Function Name : PID_Prameter_Define +* Description : Speed regulator and current regulator machine parameter definition +* Input : Pointer to motor PID controller structure +* Output : None +* Return : None +******************************************************************************/ +void PID_Prameter_Define (Motor_PID_Type * Mpid) +{ + + Mpid->Speed.CalFreq = SPEED_LOOP_CAL_FREQ; + Mpid->Speed.CalT = SPEED_REGULATOR_PERIOD_M; + Mpid->Speed.Kpreal= SPEED_REGULATOR_KP_M; + Mpid->Speed.Kireal= SPEED_REGULATOR_KI_M; + Mpid->Speed.Kdreal= SPEED_REGULATOR_KD_M; + Mpid->Speed.Kpadj = SPEED_REGULATOR_KPADJ_M; + Mpid->Speed.Kiadj = SPEED_REGULATOR_KIADJ_M; + Mpid->Speed.Kdadj = SPEED_REGULATOR_KDADJ_M; + if(STARTUP_DIRECTION==1) + { + Mpid->Speed.Upper_Lim = SPEED_REGULATOR_ULIM_M; + Mpid->Speed.Lower_Lim = SPEED_REGULATOR_LLIM_M; + } + else + { + Mpid->Speed.Upper_Lim = -SPEED_REGULATOR_LLIM_M; + Mpid->Speed.Lower_Lim = -SPEED_REGULATOR_ULIM_M; + } + Mpid->Speed.Deltalim = SPEED_REGULATOR_DLIM_M; + + Mpid->dCurr.CalFreq= CURR_REGULATOR_FREQ_M; + Mpid->dCurr.CalT= _IQ(1.0)/CURR_REGULATOR_FREQ_M; + Mpid->dCurr.Bw= CURR_REGULATOR_BW_M; + Mpid->dCurr.Kdreal= DAXIS_CURR_REGULATOR_KD_M; + Mpid->dCurr.Kpadj = DAXIS_CURR_REGULATOR_KPADJ_M; + Mpid->dCurr.Kiadj = DAXIS_CURR_REGULATOR_KIADJ_M; + Mpid->dCurr.Kdadj = DAXIS_CURR_REGULATOR_KDADJ_M; + Mpid->dCurr.Upper_Lim = DAXIS_CURR_REGULATOR_ULIM_M; + Mpid->dCurr.Lower_Lim = DAXIS_CURR_REGULATOR_LLIM_M; + Mpid->dCurr.Deltalim = QAXIS_CURR_REGULATOR_DLIM_M; + + Mpid->qCurr.CalFreq= CURR_REGULATOR_FREQ_M; + Mpid->qCurr.CalT= _IQ(1.0)/CURR_REGULATOR_FREQ_M; + Mpid->qCurr.Bw= CURR_REGULATOR_BW_M; + Mpid->qCurr.Kdreal= QAXIS_CURR_REGULATOR_KD_M; + Mpid->qCurr.Kpadj = QAXIS_CURR_REGULATOR_KPADJ_M; + Mpid->qCurr.Kiadj = QAXIS_CURR_REGULATOR_KIADJ_M; + Mpid->qCurr.Kdadj = QAXIS_CURR_REGULATOR_KDADJ_M; + Mpid->qCurr.Upper_Lim = QAXIS_CURR_REGULATOR_ULIM_M; + Mpid->qCurr.Lower_Lim = QAXIS_CURR_REGULATOR_LLIM_M; + Mpid->qCurr.Deltalim = QAXIS_CURR_REGULATOR_DLIM_M; +} + +/****************************************************************************** +* Function Name : PID_Output_Init +* Description : Speed regulator, current regulator output state initialization. +* Input : Pointer to motor PID controller structure +* Output : None +* Return : None +******************************************************************************/ +void PID_Output_Init(Motor_PID_Type * Mpid) +{ + Mpid->Speed.Err_New= 0; + Mpid->Speed.Err_Prev1= 0; + Mpid->Speed.Err_Prev2= 0; + Mpid->Speed.Output_New = 0; + Mpid->Speed.Output_Prev = 0; + + Mpid->Speed.Deltaoutput = 0; + Mpid->Speed.Propotion = 0; + Mpid->Speed.Integer = 0; + Mpid->Speed.Differential = 0; + + Mpid->dCurr.Err_New= 0; + Mpid->dCurr.Err_Prev1= 0; + Mpid->dCurr.Err_Prev2= 0; + Mpid->dCurr.Output_New= 0; + Mpid->dCurr.Output_Prev= 0; + Mpid->dCurr.Deltaoutput =0; + + Mpid->qCurr.Err_New= 0; + Mpid->qCurr.Err_Prev1= 0; + Mpid->qCurr.Err_Prev2= 0; + Mpid->qCurr.Output_New = 0; + Mpid->qCurr.Output_Prev = 0; + Mpid->qCurr.Deltaoutput = 0; +} + +/****************************************************************************** +* Function Name : DCurrProcess_Parameter_Define +* Description : Definition of parameters related to d-axis current processing +* Input : d-axis current processing structure +* Output : None +* Return : None +******************************************************************************/ +void DCurrProcess_Parameter_Define(DCurrProcess_Type * DCurrProcess) +{ + DCurrProcess->Target1 = DAXIS_CURR_REF_INIT1_M; + DCurrProcess->Target2 = DAXIS_CURR_REF_INIT2_M; + DCurrProcess->AdjustStep1 = DAXIS_CURR_REF_STEP1_M; + DCurrProcess->AdjustStep2 = DAXIS_CURR_REF_STEP2_M; + DCurrProcess->Weakpoint = DAXIS_CURR_WEAK_SPEED_M; +} diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M3_LBG_Observer_Initial.c b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M3_LBG_Observer_Initial.c new file mode 100644 index 0000000..d474083 --- /dev/null +++ b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M3_LBG_Observer_Initial.c @@ -0,0 +1,164 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : M3_LBG_Observer_Initial.c + * Author : WCH + * Version : V1.0.0 + * Date : 2026/04/23 + * Description : +********************************************************************************* +* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ + +#include "M0_Control_Library.h" +Motor_LBG_Type MLBG_M; +Observer_Status_Type LBG_Status_M; +_iq24 LBG_SpeedBuffer_M[LBG_SPEED_BUFFERSIZE_M]; + +/****************************************************************************** +* Function Name : LBG_Parameter_Define +* Description : LBG Observer Parameter Definition +* Input : LBG observer structure pointer, LBG observer state structure pointer +* Output : None +* Return : None +******************************************************************************/ +void LBG_Parameter_Define (Motor_LBG_Type *MLBG,Observer_Status_Type *LBGStatus) +{ + + MLBG->Para.CalFreq = LBG_CAL_FREQ_M; + MLBG->Para.CalT = LBG_CAL_PERIOD_M; + MLBG->Para.K1CerrC = LBG_K1_CERROR_CURR_M; + MLBG->Para.K2CerrE = LBG_K2_CERROR_EMF_M; + MLBG->Para.kCE_Adj = LBG_K2_CERROR_EMF_ADJ_M; + MLBG->Para.Caltimes = LBG_CAL_TIMES_M; + + MLBG->Cal_Struc.EUlim = LBG_MAX_EMF_M; + MLBG->Cal_Struc.ELlim = LBG_MIN_EMF_M; + MLBG->Cal_Struc.CUlim = LBG_MAX_CURR_M; + MLBG->Cal_Struc.CLlim = LBG_MIN_CURR_M; + + MLBG->Cal_Struc.SpeedLPF1st_M.Input_Coef = _IQdiv(LBG_SPEEDLPF_WcT_M,(LBG_SPEEDLPF_WcT_M + UNIT_Q24)); + MLBG->Cal_Struc.SpeedLPF1st_M.Output_Coef = _IQdiv(UNIT_Q24,(LBG_SPEEDLPF_WcT_M + UNIT_Q24)); + + MLBG->Cal_Struc.Posicom_Enable = LBG_POSICOM_ENABLE; + + MLBG->Speed_PLL.Kpreal = PLL_KP_M; + MLBG->Speed_PLL.Kireal = PLL_KI_M; + MLBG->Speed_PLL.Upper_Lim = LBG_SPEED_MAX_M; + MLBG->Speed_PLL.Lower_Lim = LBG_SPEED_MIN_M; + + MLBG->Adaptor.Enable = LBG_ADAPTOR_ENABLE; + MLBG->Adaptor.Gain = LBG_ADAPTOR_COEF_M; + MLBG->Adaptor.EMF_Adj = LBG_ADAPTOR_EMF_ADJ_M; + + MLBG->SpeedBuffPara.Length = LBG_SPEED_BUFFERSIZE_M; + + LBGStatus->OverspeedThresh = LBG_OVERSPEED_THRESH_M; + LBGStatus->OverspeedcntThresh = LBG_OVERSPEED_CNT_THRESH_M; + LBGStatus->UnderspeedThresh = LBG_UNDERSPEED_THRESH_M; + LBGStatus->UnderspeedcntThresh = LBG_UNDERSPEED_CNT_THRESH_M; + LBGStatus->VarianceThresh = LBG_SPEED_VARIANCE_THRESH_M; + LBGStatus->UnstableCntThresh = LBG_UNSTABLE_CNT_THRESH_M; + LBGStatus->UnstableSpeedThresh = LBG_UNSTABLE_SPEED_THRESH_M; + LBGStatus->ConvergeCntThresh = LBG_CONVERGED_CNT_THRESH_M; + LBGStatus->ConvergeUpper = LBG_CONVERGED_UPPER_THRESH_M; + LBGStatus->ConvergeLower = LBG_CONVERGED_LOWER_THRESH_M; + LBGStatus->ConvergeEmfBandup = LBG_CONVERGED_EMFUP_THRESH_M; + LBGStatus->ConvergeEmfBanddown = LBG_CONVERGED_EMFDOWN_THRESH_M; + LBGStatus->StallSpeedBand = LBG_STALLBAND_M; + LBGStatus->StallSpeed = LBG_STALLSPEED_M; + LBGStatus->StallCurr = LBG_STALLCURR_M; + LBGStatus->StallCntThresh = LBG_STALL_CNT_THRESH_M; + LBGStatus->ReverseCntThresh = LBG_REVERSE_CNT_THRESH_M; + LBGStatus->ReverseSpeedThresh = LBG_REVERSE_SPEED_THRESH_M; + + MLBG->Cal_Struc.EMFLPF1st_M.Input_Coef = _IQdiv(LBG_EMFLPF_WcT_M,(LBG_EMFLPF_WcT_M + UNIT_Q24)); + MLBG->Cal_Struc.EMFLPF1st_M.Output_Coef = _IQdiv(UNIT_Q24,(LBG_EMFLPF_WcT_M + UNIT_Q24)); +} + +/****************************************************************************** +* Function Name : LBG_Status_Init +* Description : LBG Observer State Initialization +* Input : LBG observer structure pointer, LBG observer state structure pointer +* Output : None +* Return : None +******************************************************************************/ +void LBG_Status_Init (Motor_LBG_Type *MLBG,Observer_Status_Type *LBGStatus) +{ + + MLBG->Cal_Struc.Inimark = FALSE; + + MLBG->Cal_Struc.EalphaNew = _IQ(0.0); + MLBG->Cal_Struc.EalphaPrev = _IQ(0.0); + + MLBG->Cal_Struc.EbetaNew = _IQ(0.0); + MLBG->Cal_Struc.EbetaPrev = _IQ(0.0); + + MLBG->Cal_Struc.CalphaNew = _IQ(0.0); + MLBG->Cal_Struc.CalphaPrev = _IQ(0.0); + MLBG->Cal_Struc.CbetaNew = _IQ(0.0); + MLBG->Cal_Struc.CbetaPrev = _IQ(0.0); + + MLBG->Cal_Struc.ThetaErr = _IQ(0.0); + MLBG->Cal_Struc.PosiElecPU = _IQ(0.0); + MLBG->Cal_Struc.PosiElecPU_Pre = _IQ(0.0); + MLBG->Cal_Struc.PosiElecPU_Cali = _IQ(0.0); + MLBG->Cal_Struc.PosiElecPU_Com = _IQ(0.0); + MLBG->Cal_Struc.Angspeed_Inst = _IQ(0.0); + MLBG->Cal_Struc.Angspeed_Aver1 = _IQ(0.0); + MLBG->Cal_Struc.Angspeed_Aver2 = _IQ(0.0); + MLBG->Cal_Struc.Triangle.Cos = _IQ(0.0); + MLBG->Cal_Struc.Triangle.Sin = _IQ(0.0); + + MLBG->Cal_Struc.Obs_Calcnt =0; + + LBGStatus->Overspeed = FALSE; + LBGStatus->Underspeed = FALSE; + LBGStatus->Reliable = FALSE; + LBGStatus->Convergence = FALSE; + LBGStatus->Timeout = FALSE; + LBGStatus->Stable = TRUE; + LBGStatus->Stall = FALSE; + LBGStatus->Reverse = FALSE; + + LBGStatus->Overspeed_CNT =0; + LBGStatus->Underspeed_CNT = 0; + LBGStatus->Converged_CNT = 0; + LBGStatus->Unstable_CNT = 0; + LBGStatus->Stall_CNT = 0; + LBGStatus->Reverse_CNT = 0; + + MLBG->Speed_PLL.Error_New = _IQ(0.0); + MLBG->Speed_PLL.Error_Prev = _IQ(0.0); + MLBG->Speed_PLL.Output_New = _IQ(0.0); + MLBG->Speed_PLL.Output_Prev = _IQ(0.0); + +#if defined OBSERVER_ADAPTOR + + MLBG->Adaptor.Alpha_Err = _IQ(0.0); + MLBG->Adaptor.Alpha_Pre = _IQ(0.0); + MLBG->Adaptor.Alpha_New = _IQ(0.0); + MLBG->Adaptor.Beta_Err = _IQ(0.0); + MLBG->Adaptor.Beta_Pre = _IQ(0.0); + MLBG->Adaptor.Beta_New = _IQ(0.0); +#endif +} + +/****************************************************************************** +* Function Name : LBG_Cal_Init +* Description : LBG Calculation Initialization +* Input : Pointer to motor start control structure, +* pointer to overall motor status structure, pointer to LBG observer structure +* Output : None +* Return : None +******************************************************************************/ +void LBG_Cal_Init (InjStart_Type *InjStart,Motor_Sructure_Type *MStruc,Motor_LBG_Type *MLBG) +{ + LBG_EMF_CalInitial(MStruc,InjStart,MLBG); + + #if defined OBSERVER_ADAPTOR + LBG_Adaptor_CalInitial(MLBG); + #endif + + LBG_Speed_CalInitial(MLBG,&(LBG_SpeedBuffer_M[0]),InjStart->RampInjSpeedRef); +} diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M3_LBG_Observer_Parameter.h b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M3_LBG_Observer_Parameter.h new file mode 100644 index 0000000..27ec37a --- /dev/null +++ b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M3_LBG_Observer_Parameter.h @@ -0,0 +1,102 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : M3_LBG_Observer_Parameter.h + * Author : WCH + * Version : V1.0.0 + * Date : 2026/04/23 + * Description : +********************************************************************************* +* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ + +#ifndef __M3_LBG_OBSERVER_H +#define __M3_LBG_OBSERVER_H +#define LBG_CAL_FREQ_M FREQ_SVPWM +#define LBG_CAL_PERIOD_M _IQ(1.0)/LBG_CAL_FREQ_M +#define LBG_K1_CERROR_CURR_M (-30000) +#define LBG_K2_CERROR_EMF_M 40000 +#define LBG_K2_CERROR_EMF_ADJ_M 20 +#define LBG_CAL_TIMES_M 2 + +#define LBG_MAX_EMF_M _IQ(2.0) +#define LBG_MIN_EMF_M _IQ(-2.0) + +#define LBG_MAX_CURR_M _IQ(2.0) +#define LBG_MIN_CURR_M _IQ(-2.0) + +#define PLL_KP_M 140 +#define PLL_KI_M 25148 +#define LBG_SPEED_MAX_M _IQ(1.5) +#define LBG_SPEED_MIN_M _IQ(0.01) + +#if defined OBSERVER_ADAPTOR +#define LBG_ADAPTOR_ENABLE 1; +#else +#define LBG_ADAPTOR_ENABLE 0; +#endif + +#define LBG_ADAPTOR_COEF_M 8000 +#define LBG_ADAPTOR_EMF_ADJ_M _IQ(0.5) +#define LBG_SPEED_BUFFERSIZE_M 96 + +#if defined POSICOM +#define LBG_POSICOM_ENABLE 1; +#else +#define LBG_POSICOM_ENABLE 0; +#endif + +#define LBG_SPEEDLPF_CF_M 50 +#define LBG_SPEEDLPF_PERIOD_M (_IQ(1.0)/SPEED_LOOP_CAL_FREQ) +#define LBG_SPEEDLPF_WcT_M _IQmpyI32(_IQmpy(LBG_SPEEDLPF_PERIOD_M,PI_2_Q24),LBG_SPEEDLPF_CF_M) + +#define LBG_OVERSPEED_THRESH_M _IQ(1.5) +#define LBG_UNDERSPEED_THRESH_M _IQ(0.05) +#define LBG_OVERSPEED_CNT_THRESH_M 500 +#define LBG_UNDERSPEED_CNT_THRESH_M 500 + +#define LBG_SPEED_VARIANCE_THRESH_M _IQ(0.2) +#define LBG_UNSTABLE_CNT_THRESH_M 300 +#define LBG_UNSTABLE_SPEED_THRESH_M _IQ(0.02) + +#define LBG_CONVERGED_CNT_THRESH_M 100 +#define LBG_CONVERGED_UPPER_THRESH_M _IQ(1.2) +#define LBG_CONVERGED_LOWER_THRESH_M _IQ(0.8) +#define LBG_CONVERGED_EMFUP_THRESH_M _IQ(0.5) +#define LBG_CONVERGED_EMFDOWN_THRESH_M _IQ(-0.2) +#define LBG_EMFLPF_CF_M 50 +#define LBG_EMFLPF_PERIOD_M (_IQ(1.0)/SPEED_LOOP_CAL_FREQ) +#define LBG_EMFLPF_WcT_M _IQmpyI32(_IQmpy(LBG_EMFLPF_PERIOD_M,PI_2_Q24),LBG_EMFLPF_CF_M) + +#define LBG_STALLBAND_M _IQ(0.5) +#define LBG_STALLSPEED_M _IQ(0.1) +#define LBG_STALLCURR_M _IQMPY_MACRO(_IQ(0.9),SPEED_REGULATOR_ULIM_M) +#define LBG_STALL_CNT_THRESH_M 100 + +#define LBG_REVERSE_CNT_THRESH_M 100 +#define LBG_REVERSE_SPEED_THRESH_M _IQ(0.02) + +/* Exported variables -------------------------------------------------------*/ +extern Motor_LBG_Type MLBG_M; +extern Observer_Status_Type LBG_Status_M; +extern _iq24 LBG_SpeedBuffer_M[LBG_SPEED_BUFFERSIZE_M]; + +void LBG_Parameter_Define (Motor_LBG_Type *MLBG,Observer_Status_Type *LBGStatus); + +void LBG_Paramter_Cal (Motor_Base_Type *Basestruc,Motor_LBG_Type *MLBG); + +void LBG_Status_Init (Motor_LBG_Type *MLBG,Observer_Status_Type *LBGStatus); + +void LBG_EMF_CalInitial(Motor_Sructure_Type *MStruc,InjStart_Type * InjStart,Motor_LBG_Type *MLBG); + +void LBG_Adaptor_CalInitial(Motor_LBG_Type *MLBG); + +void LBG_Speed_CalInitial(Motor_LBG_Type *MLBG,_iq24 *Buffer,_iq24 SpeedInial); + +void LBG_EMF_Cal(Motor_Sructure_Type *MStruc,Motor_LBG_Type *MLBG); + +void LBG_Speed_Posi_Cal(Motor_LBG_Type *MLBG); + +void LBG_Cal_Init (InjStart_Type *InjStart,Motor_Sructure_Type *MStruc,Motor_LBG_Type *MLBG); + +#endif diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M4_SVPWM_ADC1R.c b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M4_SVPWM_ADC1R.c new file mode 100644 index 0000000..0f492c9 --- /dev/null +++ b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M4_SVPWM_ADC1R.c @@ -0,0 +1,659 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : M4_SVPWM_ADC1R.c + * Author : WCH + * Version : V1.0.0 + * Date : 2026/04/23 + * Description : +********************************************************************************* +* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ + +#include "M0_Control_Library.h" + +SVPWM_1R_Type SVPWM_Cal_M; +ADCStruc_Type ADC_M; +PWMCali_Type PWMCali_M; + +/****************************************************************************** +* Function Name : SVPWM_1R_Paramter_Init +* Description : SVPWM Parameter Initialization +* Input : SVPWM calculation structure, PWM correction structure pointer, +* motor base value parameter structure pointer +* Output : None +* Return : None +******************************************************************************/ +void SVPWM_1R_Paramter_Init(SVPWM_1R_Type *SVPWM_Cal,PWMCali_Type *PWMCali,Motor_Base_Type *Mbase) +{ + SVPWM_Cal->T = ((uint16_t)(TIMER_CLOCK_FREQ_SVPWM/(uint32_t)(FREQ_SVPWM))); + SVPWM_Cal->T_IQ16 = (_IQ16(SVPWM_Cal->T)); + SVPWM_Cal->HALF_T = SVPWM_Cal->T/2; + SVPWM_Cal->Quard_T = SVPWM_Cal->T/4; + + SVPWM_Cal->BusVolt = _IQ18div(DCBUS_RATED_VOLT,Mbase->Vbase); + + SVPWM_Cal->coef1 = _IQ16mpy(_IQ16div(SVPWM_Cal->T_IQ16/2,SVPWM_Cal->BusVolt>>2),Three_Q16); + SVPWM_Cal->coef2 = _IQ16mpy(_IQ16div(SVPWM_Cal->T_IQ16/2,SVPWM_Cal->BusVolt>>2),SQRT3_Q16); + + SVPWM_Cal->Maxmodulesqure = MAX_MODULATIONSQUARE; + SVPWM_Cal->Maxmodule = MAX_MODULATION; + + PWMCali->Currconverttime = CURR_CONVERT_CLOCK_ADC; + PWMCali->ADCTimeMin = CURR_MAX_TRTN_CLOCK_ADC + DEADTIME_CLOCK_SVPWM + CURR_CONVERT_CLOCK_ADC ; + PWMCali->ADCTimeMinDouble = PWMCali->ADCTimeMin*2; + PWMCali->ADCTimeMinHalf = PWMCali->ADCTimeMin/2; +} + +/****************************************************************************** +* Function Name : SVPWM_Status_Initial_M +* Description : SVPWM State Initialization +* Input : SVPWM calculation structure, PWM correction structure pointer +* Output : None +* Return : None +******************************************************************************/ +void SVPWM_1R_Status_Init_M(SVPWM_1R_Type *SVPWM_Cal,PWMCali_Type *PWMCali) +{ + TIM1->CH1CVR = SVPWM_Cal->Quard_T; + TIM1->CH2CVR = SVPWM_Cal->Quard_T; + TIM1->CH3CVR = SVPWM_Cal->Quard_T; + TIM1->CH4CVR = SVPWM_Cal->Quard_T - PWMCali->Currconverttime; + TIM3->CH4CVR = SVPWM_Cal->HALF_T - PWMCali->Currconverttime; + + SVPWM_Cal->cc1 = SVPWM_Cal->Quard_T; + SVPWM_Cal->cc2 = SVPWM_Cal->Quard_T; + SVPWM_Cal->cc3 = SVPWM_Cal->Quard_T; + SVPWM_Cal->cc1Load = SVPWM_Cal->Quard_T; + SVPWM_Cal->cc2Load = SVPWM_Cal->Quard_T; + SVPWM_Cal->cc3Load = SVPWM_Cal->Quard_T; + SVPWM_Cal->cc1Loadup = SVPWM_Cal->Quard_T; + SVPWM_Cal->cc2Loadup = SVPWM_Cal->Quard_T; + SVPWM_Cal->cc3Loadup = SVPWM_Cal->Quard_T; + + SVPWM_Cal->sector = 1; + SVPWM_Cal->VoltLimMark = 0; + + SVPWM_Cal->PWMUcali1 = SVPWM_Cal->Quard_T; + SVPWM_Cal->PWMUcali2 = SVPWM_Cal->Quard_T; + SVPWM_Cal->PWMVcali1 = SVPWM_Cal->Quard_T; + SVPWM_Cal->PWMVcali2 = SVPWM_Cal->Quard_T; + SVPWM_Cal->PWMWcali1 = SVPWM_Cal->Quard_T; + SVPWM_Cal->PWMWcali2 = SVPWM_Cal->Quard_T; + + PWMCali->Cali_Buff.Cali1 = SVPWM_Cal->Quard_T; + PWMCali->Cali_Buff.Cali2 = SVPWM_Cal->Quard_T; + PWMCali->Cali_Buff.Cali3 = SVPWM_Cal->Quard_T; + PWMCali->Cali_Buff.Cali4 = SVPWM_Cal->Quard_T; + PWMCali->Cali_Buff.Cali5 = SVPWM_Cal->Quard_T; + PWMCali->Cali_Buff.Cali6 = SVPWM_Cal->Quard_T; + + PWMCali->ADC_Trig.Trig1 = SVPWM_Cal->Quard_T - PWMCali->Currconverttime; + PWMCali->ADC_Trig.Trig2 = SVPWM_Cal->HALF_T - PWMCali->Currconverttime; + PWMCali->ADC_Trig.Trig1_limmark = FALSE; + PWMCali->ADC_Trig.Trig2_limmark = FALSE; + + PWMCali->DMA_Trig.Trig1 = 1; + PWMCali->DMA_Trig.Trig2 = SVPWM_Cal->HALF_T +1; + PWMCali->DMA_Trig.Trig3 = 1; + PWMCali->DMA_Trig.Trig4 = SVPWM_Cal->HALF_T +1; + PWMCali->DMA_Trig.Trig5 = 1; + PWMCali->DMA_Trig.Trig6 = SVPWM_Cal->HALF_T +1; + + TIM2->CH3CVR = PWMCali->DMA_Trig.Trig1; + TIM3->CH3CVR = PWMCali->DMA_Trig.Trig2; + TIM4->CH2CVR = PWMCali->DMA_Trig.Trig3; + TIM2->CH1CVR = PWMCali->DMA_Trig.Trig4; + TIM3->CH1CVR = PWMCali->DMA_Trig.Trig5; + TIM2->CH2CVR = PWMCali->DMA_Trig.Trig6; + + PWMCali->CaliMark = 0; +} + +/****************************************************************************** +* Function Name : ADC_Parameter_Init +* Description : ADC Parameter Calculation +* Input : ADC calculation structure pointer, +* motor base value parameter structure pointer +* Output : None +* Return : None +******************************************************************************/ +void ADC_Parameter_Init (ADCStruc_Type *ADCStruc,Motor_Base_Type *Mbase) +{ + ADCStruc->RatedCurr_ConvInv = _IQ16mpyIQX(_IQ16div(_IQ16(128),_IQ16(32767)),\ + 16,_IQ18div(CURR_SAMPLE_RANGE_ADC,Mbase->Ibase),18); + + ADCStruc->AdcChannel1 = ADC1_CURR_CHANNEL_PHASE_M; + ADCStruc->AdcChannel2 = ADC2_CURR_CHANNEL_PHASE_M; + + ADCStruc->DCVoltRatedADC = _IQ18div(_IQ18mpy(DCVOLT_CONV_RATIO,DCBUS_RATED_VOLT),_IQ18(3.3))*4096; + + ADCStruc->DCVoltRatedADCInv =_IQ18div(_IQ18(1.0),ADCStruc->DCVoltRatedADC); + + ADCStruc->DCVoltAverSizeInv1 = _IQ(1.0)/DCVOLT_AVER_SIZE; + ADCStruc->DCVoltAverSizeInv2 = _IQ(1.0) - ADCStruc->DCVoltAverSizeInv1; + + ADCStruc->VdcLPF1st.Input_Coef = _IQdiv(DCVOLT_LPF_WcT_M,(DCVOLT_LPF_WcT_M + UNIT_Q24)); + ADCStruc->VdcLPF1st.Output_Coef = _IQdiv(UNIT_Q24,(DCVOLT_LPF_WcT_M + UNIT_Q24)); + + ADCStruc->DCVoltPres=0; + ADCStruc->DCVoltAver=0; + ADCStruc->DCVoltcali=0; + ADCStruc->DCVolt_Filter=0; + ADCStruc->VdcLPF1st.Out_New=0; + ADCStruc->VdcLPF1st.Out_Pre=0; + + +} + +/****************************************************************************** +* Function Name : ADC_Status_Init +* Description : ADC Status Init +* Input : ADC calculation structure pointer +* Output : None +* Return : None +******************************************************************************/ +void ADC_Status_Init (ADCStruc_Type *ADCStruc) +{ + + ADCStruc->ADC_Result.Value1 = ADC_M.OffsetValue1; + ADCStruc->ADC_Result.Value2 = ADC_M.OffsetValue2; + +// ADCStruc->DCVoltPres = DCVOLT_INIT; +// ADCStruc->DCVoltAver = DCVOLT_INIT; +// ADCStruc->DCVolt_Filter = DCVOLT_INIT; +// ADCStruc->DCVoltcali = _IQ(1.0); +// +// ADCStruc->VdcLPF1st.Out_New =0; +// ADCStruc->VdcLPF1st.Out_Pre =0; +} + +/****************************************************************************** +* Function Name : SVPWM_1R_Timer_Configure +* Description : SVPWM Port and Timer Initialization +* Input : None +* Output : None +* Return : None +******************************************************************************/ +void SVPWM_1R_Timer_Configure() +{ + TIM_TimeBaseInitTypeDef TIM1_TimeBaseStructure={0}; + TIM_TimeBaseInitTypeDef TIM3_TimeBaseInitStructure= {0}; + TIM_OCInitTypeDef TIM1_OCInitStructure={0}; + TIM_OCInitTypeDef TIM3_OCInitStructure= {0}; + TIM_BDTRInitTypeDef TIM_BDTRInitStructure={0}; + GPIO_InitTypeDef GPIO_InitStructure={0}; + DMA_InitTypeDef DMA1_InitStructure = {0}; + + RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB\ + | RCC_APB2Periph_AFIO | RCC_APB2Periph_TIM1, ENABLE); + + RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM2 |RCC_APB1Periph_TIM3\ + | RCC_APB1Periph_TIM4, ENABLE ); + + RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); + + GPIO_StructInit(&GPIO_InitStructure); + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 ; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_Init(GPIOA, &GPIO_InitStructure); + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12|GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_Init(GPIOB, &GPIO_InitStructure); + GPIO_SetBits(GPIOB,GPIO_Pin_12); + + TIM_DeInit(TIM1); + + TIM_TimeBaseStructInit(&TIM1_TimeBaseStructure); + + TIM1_TimeBaseStructure.TIM_Prescaler = TIMER_PRESCALER_SVPWM; + + TIM1_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_CenterAligned1; + + TIM1_TimeBaseStructure.TIM_Period = SVPWM_Cal_M.HALF_T-1; + + TIM1_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; + + TIM1_TimeBaseStructure.TIM_RepetitionCounter = TIMER_UPDATE_RATE_SVPWM; + + TIM_TimeBaseInit(TIM1, &TIM1_TimeBaseStructure); + + TIM_OCStructInit(&TIM1_OCInitStructure); + + TIM1_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; + + TIM1_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; + + TIM1_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable; + + //dummy value + TIM1_OCInitStructure.TIM_Pulse = SVPWM_Cal_M.HALF_T/2; + + TIM1_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; + + TIM1_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High; + //TIM1_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_Low; //SA2603 + + TIM1_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset; + + TIM1_OCInitStructure.TIM_OCNIdleState = TIM_OCNIdleState_Reset; + + TIM_OC1Init(TIM1, &TIM1_OCInitStructure); + TIM_OC2Init(TIM1, &TIM1_OCInitStructure); + TIM_OC3Init(TIM1, &TIM1_OCInitStructure); + + TIM_OCStructInit(&TIM1_OCInitStructure); + + TIM1_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2; + + TIM1_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; + + TIM1_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable; + + TIM1_OCInitStructure.TIM_Pulse = SVPWM_Cal_M.HALF_T - 1; + + TIM1_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; + + TIM1_OCInitStructure.TIM_OCNPolarity =TIM_OCNPolarity_Low; + + TIM1_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset; + + TIM1_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset; + + TIM_OC4Init(TIM1, &TIM1_OCInitStructure); + + TIM_OC1PreloadConfig(TIM1, TIM_OCPreload_Disable); + TIM_OC2PreloadConfig(TIM1, TIM_OCPreload_Disable); + TIM_OC3PreloadConfig(TIM1, TIM_OCPreload_Disable); + TIM_OC4PreloadConfig(TIM1, TIM_OCPreload_Enable); + + TIM_BDTRInitStructure.TIM_OSSRState = TIM_OSSRState_Enable; + TIM_BDTRInitStructure.TIM_OSSIState = TIM_OSSIState_Enable; + + TIM_BDTRInitStructure.TIM_LOCKLevel = TIM_LOCKLevel_1; + + TIM_BDTRInitStructure.TIM_DeadTime = DEADTIME_CONFIGURE; + + TIM_BDTRInitStructure.TIM_Break = TIM_Break_Enable; + + TIM_BDTRInitStructure.TIM_BreakPolarity = TIM_BreakPolarity_Low; + + TIM_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Disable; + + TIM_BDTRConfig(TIM1, &TIM_BDTRInitStructure); + + TIM_SetCounter(TIM1,0); + TIM_ClearFlag(TIM1, TIM_FLAG_Update); + TIM_ITConfig(TIM1, TIM_IT_Update, ENABLE); + + DMA_DeInit(DMA1_Channel1); + DMA_DeInit(DMA1_Channel2); + DMA_DeInit(DMA1_Channel4); + DMA_DeInit(DMA1_Channel5); + DMA_DeInit(DMA1_Channel6); + DMA_DeInit(DMA1_Channel7); + + DMA1_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; + DMA1_InitStructure.DMA_BufferSize = 1; + DMA1_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; + DMA1_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable; + DMA1_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word; + DMA1_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; + DMA1_InitStructure.DMA_Mode = DMA_Mode_Circular; + DMA1_InitStructure.DMA_Priority = DMA_Priority_VeryHigh; + DMA1_InitStructure.DMA_M2M = DMA_M2M_Disable; + + + DMA1_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&(TIM1->CH1CVR); + DMA1_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&(PWMCali_M.Cali_Buff.Cali1); + DMA_Init(DMA1_Channel1, &DMA1_InitStructure); + + DMA1_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&(TIM1->CH1CVR); + DMA1_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&(PWMCali_M.Cali_Buff.Cali2); + DMA_Init(DMA1_Channel2, &DMA1_InitStructure); + + DMA1_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&(TIM1->CH2CVR); + DMA1_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&(PWMCali_M.Cali_Buff.Cali3); + DMA_Init(DMA1_Channel4, &DMA1_InitStructure); + + DMA1_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&(TIM1->CH2CVR); + DMA1_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&(PWMCali_M.Cali_Buff.Cali4); + DMA_Init(DMA1_Channel5, &DMA1_InitStructure); + + DMA1_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&(TIM1->CH3CVR); + DMA1_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&(PWMCali_M.Cali_Buff.Cali5); + DMA_Init(DMA1_Channel6, &DMA1_InitStructure); + + DMA1_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&(TIM1->CH3CVR); + DMA1_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&(PWMCali_M.Cali_Buff.Cali6); + DMA_Init(DMA1_Channel7, &DMA1_InitStructure); + + DMA_Cmd(DMA1_Channel1, ENABLE); + DMA_Cmd(DMA1_Channel2, ENABLE); + DMA_Cmd(DMA1_Channel4, ENABLE); + DMA_Cmd(DMA1_Channel5, ENABLE); + DMA_Cmd(DMA1_Channel6, ENABLE); + DMA_Cmd(DMA1_Channel7, ENABLE); + + TIM_DeInit(TIM3); + TIM_DeInit(TIM2); + TIM_DeInit(TIM4); + + TIM_TimeBaseStructInit(&TIM3_TimeBaseInitStructure); + TIM3_TimeBaseInitStructure.TIM_Prescaler = TIMER_PRESCALER_SVPWM; + TIM3_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up; + TIM3_TimeBaseInitStructure.TIM_Period = SVPWM_Cal_M.T-1; + + TIM_TimeBaseInit(TIM3, &TIM3_TimeBaseInitStructure); + TIM_TimeBaseInit(TIM2, &TIM3_TimeBaseInitStructure); + TIM_TimeBaseInit(TIM4, &TIM3_TimeBaseInitStructure); + + TIM_OCStructInit(&TIM3_OCInitStructure); + TIM3_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2; + TIM3_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; + TIM3_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; + + TIM_OC3Init(TIM2, &TIM3_OCInitStructure); + TIM_OC3Init(TIM3, &TIM3_OCInitStructure); + TIM_OC2Init(TIM4, &TIM3_OCInitStructure); + TIM_OC1Init(TIM2, &TIM3_OCInitStructure); + TIM_OC1Init(TIM3, &TIM3_OCInitStructure); + TIM_OC2Init(TIM2, &TIM3_OCInitStructure); + + TIM_OC4Init(TIM3, &TIM3_OCInitStructure); + + TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable); + TIM_OC3PreloadConfig(TIM3, TIM_OCPreload_Enable); + TIM_OC4PreloadConfig(TIM3, TIM_OCPreload_Enable); + + TIM_OC3PreloadConfig(TIM2, TIM_OCPreload_Enable); + TIM_OC1PreloadConfig(TIM2, TIM_OCPreload_Enable); + TIM_OC2PreloadConfig(TIM2, TIM_OCPreload_Enable); + + TIM_OC2PreloadConfig(TIM4, TIM_OCPreload_Enable); + + TIM_SelectOutputTrigger(TIM1, TIM_TRGOSource_Update); + TIM_SelectInputTrigger(TIM3, TIM_TS_ITR0); + TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_Reset); + + TIM_SelectOutputTrigger(TIM1, TIM_TRGOSource_Update); + TIM_SelectInputTrigger(TIM2, TIM_TS_ITR0); + TIM_SelectSlaveMode(TIM2, TIM_SlaveMode_Reset); + + TIM_SelectOutputTrigger(TIM1, TIM_TRGOSource_Update); + TIM_SelectInputTrigger(TIM4, TIM_TS_ITR0); + TIM_SelectSlaveMode(TIM4, TIM_SlaveMode_Reset); + + TIM_SetCounter(TIM3,0); + TIM_SetCounter(TIM2,0); + TIM_SetCounter(TIM4,0); +} + +/****************************************************************************** +* Function Name : ADC_OPA_Configure +* Description : ADC/OPA Configuration +* Input : ADC calculation structure pointer, ADC register pointer +* Output : None +* Return : None +******************************************************************************/ +void ADC_OPA_Configure(ADCStruc_Type *ADCStruc) +{ + + ADC_InitTypeDef ADC_InitStructure={0}; + GPIO_InitTypeDef GPIO_InitStructure={0}; + OPA_InitTypeDef OPA1_InitStructure = {0}; + OPA_InitTypeDef OPA2_InitStructure = {0}; + + RCC_ADCCLKConfig(RCC_PCLK2_Div6); + + RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB\ + |RCC_APB2Periph_AFIO | RCC_APB2Periph_ADC1\ + | RCC_APB2Periph_ADC2, ENABLE); + + GPIO_StructInit(&GPIO_InitStructure); + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 |GPIO_Pin_2 ; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; + GPIO_Init(GPIOA, &GPIO_InitStructure); + + GPIO_StructInit(&GPIO_InitStructure); + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4|GPIO_Pin_5;//CH4 CH5 + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; + GPIO_Init(GPIOA, &GPIO_InitStructure); + + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; + GPIO_Init( GPIOB, &GPIO_InitStructure ); + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; + GPIO_Init( GPIOA, &GPIO_InitStructure ); + + OPA2_InitStructure.OPA_NUM = OPA2; + OPA2_InitStructure.PSEL = CHP1; + OPA2_InitStructure.NSEL = CHN0; + OPA2_InitStructure.Mode = OUT_IO_OUT1; + OPA_Init( &OPA2_InitStructure ); + OPA_Cmd( OPA2, ENABLE ); + + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; + GPIO_Init( GPIOA, &GPIO_InitStructure ); + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; + GPIO_Init( GPIOB, &GPIO_InitStructure ); + + OPA1_InitStructure.OPA_NUM = OPA1; + OPA1_InitStructure.PSEL = CHP1; + OPA1_InitStructure.NSEL = CHN1; + OPA1_InitStructure.Mode = OUT_IO_OUT1; + OPA_Init( &OPA1_InitStructure ); + OPA_Cmd( OPA1, ENABLE ); + + ADC_DeInit(ADC1); + ADC_DeInit(ADC2); + + ADC_StructInit(&ADC_InitStructure); + ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; + ADC_InitStructure.ADC_ScanConvMode = ENABLE; + ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; + ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; + ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Left; + ADC_InitStructure.ADC_NbrOfChannel = 1; + ADC_Init(ADC1, &ADC_InitStructure); + ADC_Init(ADC2, &ADC_InitStructure); + + ADC_RegularChannelConfig(ADC2,ADC_Channel_1, 1, SAMPLING_TIMER_CLOCK ); + + ADC_RegularChannelConfig(ADC1,ADC_Channel_2, 1, SAMPLING_TIMER_CLOCK ); + + ADC_Cmd(ADC1, ENABLE); + ADC_Cmd(ADC2, ENABLE); + + ADC_BufferCmd(ADC1, DISABLE); //disable buffer + ADC_ResetCalibration(ADC1); + while(ADC_GetResetCalibrationStatus(ADC1)); + ADC_StartCalibration(ADC1); + while(ADC_GetCalibrationStatus(ADC1)); + + ADC_BufferCmd(ADC2, DISABLE); //disable buffer + ADC_ResetCalibration(ADC2); + while(ADC_GetResetCalibrationStatus(ADC2)); + ADC_StartCalibration(ADC2); + while(ADC_GetCalibrationStatus(ADC2)); +} + +/****************************************************************************** +* Function Name : ADC_1R_Offset_Reading +* Description : ADC current sampling zero reading +* Input : ADC register pointer, ADC calculation structure pointer, ADC number +* Output : None +* Return : None +******************************************************************************/ +void ADC_1R_Offset_Reading(ADC_TypeDef *ADCx, ADCStruc_Type *ADCStruc,u_int8_t ADC_num) +{ + uint16_t i; + + if(ADC_num ==1) + ADCStruc->OffsetValue1 = 0; + else if (ADC_num ==2) + ADCStruc->OffsetValue2 = 0; + + ADC_ITConfig(ADCx, ADC_IT_JEOC, DISABLE); + + ADC_ExternalTrigInjectedConvConfig(ADCx, ADC_ExternalTrigInjecConv_None); + + ADC_ExternalTrigInjectedConvCmd(ADCx,ENABLE); + + ADC_InjectedSequencerLengthConfig(ADCx,1); + + if(ADC_num ==1) + ADC_InjectedChannelConfig(ADCx, ADCStruc->AdcChannel1,1,SAMPLING_TIMER_CLOCK); + else if (ADC_num ==2) + ADC_InjectedChannelConfig(ADCx, ADCStruc->AdcChannel2,1,SAMPLING_TIMER_CLOCK); + + ADC_ClearFlag(ADCx, ADC_FLAG_JEOC); + + ADC_SoftwareStartInjectedConvCmd(ADCx,ENABLE); + + for(i=0; i OffsetValue1 += (ADC_GetInjectedConversionValue(ADCx,ADC_InjectedChannel_1)>>3); + else if (ADC_num ==2) + ADCStruc->OffsetValue2 += (ADC_GetInjectedConversionValue(ADCx,ADC_InjectedChannel_1)>>3); + + ADC_ClearFlag(ADCx, ADC_FLAG_JEOC); + ADC_SoftwareStartInjectedConvCmd(ADCx,ENABLE); + } + + ADC_ExternalTrigInjectedConvCmd(ADCx,ENABLE); +} + +/****************************************************************************** +* Function Name : ADC_1R_Start +* Description : ADC Conversion Start +* Input : Enable command +* Output : None +* Return : None +******************************************************************************/ +void ADC_1R_Start (FunctionalState cmd) +{ + if (cmd == ENABLE) + { + ADC_ExternalTrigInjectedConvConfig(ADC1, ADC_ExternalTrigInjecConv_T1_CC4); + ADC_ExternalTrigInjectedConvConfig(ADC2, ADC_ExternalTrigInjecConv_T3_CC4); + + ADC1->STATR = ~(uint32_t)ADC_FLAG_JEOC; + ADC2->STATR = ~(uint32_t)ADC_FLAG_JEOC; + + ADC_ITConfig(ADC1, ADC_IT_JEOC, ENABLE); + ADC_ITConfig(ADC2, ADC_IT_JEOC, ENABLE); + + TIM_DMACmd(TIM2, TIM_DMA_CC1, ENABLE); + TIM_DMACmd(TIM2, TIM_DMA_CC2, ENABLE); + TIM_DMACmd(TIM2, TIM_DMA_CC3, ENABLE); + TIM_DMACmd(TIM3, TIM_DMA_CC1, ENABLE); + TIM_DMACmd(TIM3, TIM_DMA_CC3, ENABLE); + TIM_DMACmd(TIM4, TIM_DMA_CC2, ENABLE); + } + else + { + + ADC_ExternalTrigInjectedConvConfig(ADC1, ADC_ExternalTrigInjecConv_None); + ADC_ExternalTrigInjectedConvConfig(ADC2, ADC_ExternalTrigInjecConv_None); + + TIM_DMACmd(TIM2, TIM_DMA_CC1, DISABLE); + TIM_DMACmd(TIM2, TIM_DMA_CC2, DISABLE); + TIM_DMACmd(TIM2, TIM_DMA_CC3, DISABLE); + TIM_DMACmd(TIM3, TIM_DMA_CC1, DISABLE); + TIM_DMACmd(TIM3, TIM_DMA_CC3, DISABLE); + TIM_DMACmd(TIM4, TIM_DMA_CC2, DISABLE); + + ADC_ExternalTrigInjectedConvCmd(ADC1,DISABLE); + ADC_ExternalTrigInjectedConvCmd(ADC2,DISABLE); + TIM_CtrlPWMOutputs(TIM1, DISABLE); + } +} + +/****************************************************************************** +* Function Name : DCBUS_Volt_Cal +* Description : Bus Voltage Calculation +* Input : ADC calculation structure pointer, ADC register pointer +* Output : None +* Return : None +******************************************************************************/ +void DCBUS_Volt_Cal(ADCStruc_Type *ADCStruc,ADC_TypeDef *ADCx) +{ + if((ADCx->STATR & ADC_FLAG_EOC) == ADC_FLAG_EOC) + { + ADCStruc->DCVoltPres=_IQ18toIQ(_IQ18MPY_MACRO(_IQ18(ADCx->RDATAR>>4),ADCStruc->DCVoltRatedADCInv)); + + ADCStruc->DCVolt_Filter = LPF_1st_Process(&(ADCStruc->VdcLPF1st), ADCStruc->DCVoltPres); + + ADCStruc->DCVoltAver = _IQMPY_MACRO(ADCStruc->DCVoltAver,ADCStruc->DCVoltAverSizeInv2)\ + + _IQMPY_MACRO(ADCStruc->DCVoltPres,ADCStruc->DCVoltAverSizeInv1); + } +} + +/****************************************************************************** +* Function Name : NTCSample +* Description : NTC Sampling Calculation +* Input : Temperature control structure pointer, ADC register pointer +* Output : None +* Return : None +******************************************************************************/ +void NTCSample(Temperature_ctl_Type *TempM, ADC_TypeDef *ADCx) +{ + if((ADCx->STATR & ADC_FLAG_EOC) == ADC_FLAG_EOC) + { + TempM->TempPres=(_iq24)((u16)ADCx->RDATAR*TempM->TempRatedADCInv); + //均值计算 + + + TempM->TempAver =_IQMPY_MACRO(TempM->TempAver,TempM->TempAverSizeInv2)\ + + _IQMPY_MACRO(TempM->TempPres,TempM->TempAverSizeInv1); + + } +} +/****************************************************************************** +* Function Name : ADC_Trigger_Update +* Description : Update at ADC trigger moment +* Input : PWM correction calculation structure pointer +* Output : None +* Return : None +******************************************************************************/ +void ADC_Trigger_Update(PWMCali_Type *PWMCali) +{ + TIM1->CH4CVR = PWMCali->ADC_Trig.Trig1; + TIM3->CH4CVR = PWMCali->ADC_Trig.Trig2; +} + +/******************************************************************************* +* Function Name : SVPWM_Zerovolt_Output_Immidiate +* Description : 0 voltage output, takes effect immediately +* Input : SVPWM calculation structure pointer +* Output : None +* Return : None +*******************************************************************************/ +void SVPWM_Zerovolt_Output_Immediate(SVPWM_1R_Type *SVPWM_Cal) +{ + TIM1->CH1CVR = SVPWM_Cal->Quard_T; + TIM1->CH2CVR = SVPWM_Cal->Quard_T; + TIM1->CH3CVR = SVPWM_Cal->Quard_T; +} + +/******************************************************************************* +* Function Name : SVPWM_Lowside_Effective +* Description : All lower tubes are fully conductive and take effect immediately +* Input : None +* Output : None +* Return : None +*******************************************************************************/ +void SVPWM_Lowside_Effective_Immediate(void) +{ + TIM1->CH1CVR = 0; + TIM1->CH2CVR = 0; + TIM1->CH3CVR = 0; +} diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M4_SVPWM_ADC1R.h b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M4_SVPWM_ADC1R.h new file mode 100644 index 0000000..7427367 --- /dev/null +++ b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M4_SVPWM_ADC1R.h @@ -0,0 +1,112 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : M4_SVPWM_ADC1R.h + * Author : WCH + * Version : V1.0.0 + * Date : 2026/04/23 + * Description : +********************************************************************************* +* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ + +#ifndef __MOTOR_SVPWM_ADC1R_H +#define __MOTOR_SVPWM_ADC1R_H +#define DCBUS_RATED_VOLT _IQ18(311) + +#define SYSTEM_CLOCK_FREQ 144000000uL +#define TIMER_PRESCALER_SVPWM 0 +#define TIMER_CLOCK_FREQ_SVPWM (SYSTEM_CLOCK_FREQ/(TIMER_PRESCALER_SVPWM+1)) +#define TIMER_UPDATE_RATE_SVPWM 1 +#define FREQ_SVPWM 30000 + +#define DEADTIME_SVPWM 1000 +#define DEADTIME_CLOCK_SVPWM (uint16_t)((DEADTIME_SVPWM*(SYSTEM_CLOCK_FREQ/1000000))/1000) +#define DEADTIME_CONFIGURE (uint8_t)136 + +#define BRK_GPIO_M GPIOB +#define BRK_PIN_M GPIO_Pin_12 + +#define CURR_SAMPLE_RESISTOR_ADC _IQ18(0.1) +#define CURR_AMPLIFIER_ADC _IQ18(3.73333) +#define CURR_SAMPLE_RANGE_ADC _IQ18div(_IQ18(1.65),_IQ18mpy(CURR_SAMPLE_RESISTOR_ADC,CURR_AMPLIFIER_ADC)) +#define CURR_OFFSET_READ_NUM_ADC ((uint8_t)16) + + +#define SAMPLING_TIMER_CLOCK ADC_SampleTime_7Cycles5 + +#define CONVER_TIME_ADC 750 + +#define CURR_CONVERT_CLOCK_ADC (uint16_t)((CONVER_TIME_ADC*(SYSTEM_CLOCK_FREQ/1000000))/1000) + +#define CURR_RISE_TIME_ADC 900 + +#define CURR_RISE_CLOCK_ADC (uint16_t)((CURR_RISE_TIME_ADC*(SYSTEM_CLOCK_FREQ/1000000))/1000) + +#define CURR_NOISE_TIME_ADC 650 + +#define CURR_NOISE_CLOCK_ADC (uint16_t)((CURR_NOISE_TIME_ADC*(SYSTEM_CLOCK_FREQ/1000000))/1000) + +#if(CURR_RISE_TIME_ADC > CURR_NOISE_TIME_ADC) + #define CURR_MAX_TRTN_CLOCK_ADC CURR_RISE_CLOCK_ADC +#else + #define CURR_MAX_TRTN_CLOCK_ADC CURR_NOISE_CLOCK_ADC +#endif + +#define ADC1_CURR_CHANNEL_PHASE_M ADC_Channel_4 +#define ADC2_CURR_CHANNEL_PHASE_M ADC_Channel_5 + +#define DCVOLT_INIT _IQ(1.0) +#define DCVOLT_CONV_RATIO _IQ18(0.006651884) +#define DCVOLT_AVER_SIZE 100 + +#define DCVOLT_LPF_CF_M 1000 +#define DCVOLT_LPF_PERIOD_M LBG_CAL_PERIOD_M +#define DCVOLT_LPF_WcT_M _IQmpyI32(_IQmpy(DCVOLT_LPF_PERIOD_M,PI_2_Q24),DCVOLT_LPF_CF_M) + +/* Exported variables -------------------------------------------------------*/ +extern SVPWM_1R_Type SVPWM_Cal_M; +extern ADCStruc_Type ADC_M; +extern PWMCali_Type PWMCali_M; + +void SVPWM_1R_Paramter_Init(SVPWM_1R_Type *SVPWM_Cal,PWMCali_Type *PWMCali,Motor_Base_Type *Mbase); + +void SVPWM_1R_Status_Init_M(SVPWM_1R_Type *SVPWM_Cal,PWMCali_Type *PWMCali); + +void ADC_Parameter_Init (ADCStruc_Type *ADCStruc,Motor_Base_Type *Mbase); + +void ADC_Status_Init (ADCStruc_Type *ADCStruc); + +void SVPWM_1R_Timer_Configure(void); + +void ADC_OPA_Configure(ADCStruc_Type *ADCStruc); + +void ADC_1R_Offset_Reading(ADC_TypeDef *ADCx, ADCStruc_Type *ADCStruc,u_int8_t ADC_num); + +void ADC_1R_Start (FunctionalState cmd); + +void SVPWM_Updateup(SVPWM_1R_Type *SVPWM_Cal,PWMCali_Type *PWMCali); + +void SVPWM_Updatedown (SVPWM_1R_Type *SVPWM_Cal,PWMCali_Type *PWMCali); + +void ADC_Trigger_Update(PWMCali_Type *PWMCali); + +void DCBUS_Volt_Cal(ADCStruc_Type *ADCStruc,ADC_TypeDef *ADCx); + +void SVPWM_Calculation(SVPWM_1R_Type *SVPWM_Cal, Component_2S_Type *VoltRef); + +void SVPWM_Calibration(SVPWM_1R_Type *SVPWM_Cal, PWMCali_Type *PWMCali_Struc); + +Component_3S_Type Current_Cal_1R(uint8_t Sector, ADCStruc_Type *ADCStruc); + +void SVPWM_Zerovolt_Output(SVPWM_1R_Type *SVPWM_Cal); + +void SVPWM_Lowside_Effective(SVPWM_1R_Type *SVPWM_Cal); + +void SVPWM_Zerovolt_Output_Immediate(SVPWM_1R_Type *SVPWM_Cal); + +void SVPWM_Lowside_Effective_Immediate(void); + +void NTCSample(Temperature_ctl_Type *TempM, ADC_TypeDef *ADCx); + +#endif diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M5_MotorStart.c b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M5_MotorStart.c new file mode 100644 index 0000000..e75e4e2 --- /dev/null +++ b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M5_MotorStart.c @@ -0,0 +1,252 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : M5_MotorStart.c + * Author : WCH + * Version : V1.0.0 + * Date : 2026/04/23 + * Description : Initialization of the motor before starting +********************************************************************************* +* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ +#include "M0_Control_Library.h" + +InjStart_Type InjStart_M; + +/****************************************************************************** +* Function Name : Motor_Start_Init +* Description : Motor Start Init +* Input : None +* Output : None +* Return : None +******************************************************************************/ +void Motor_Start_Init_M(void) +{ + LED_OFF(&LED_M); + + KeyandLED_Status_Ini(&Key_M,&LED_M); + + Operation_Status_Init(&Operation_M); + + Eventmanager_Initial(&Emanager_M); + + Speedrampctr_Start_Init_M(&SpeedRamp_M); + + Speed_Set(&SpeedRamp_M); + + Temp_Set(&Key_M,&SpeedRamp_M,&Triac_ctl); + + Protection_and_Emergency_Init(); + + PID_Output_Init(&Mpid_M); + + Motor_Status_Initial_M(&MStruc_M); + + Injstart_Status_Init_M(&InjStart_M); + + Dcurr_Process_Init(&DCurrProcess_M,1); + + SVPWM_1R_Status_Init_M(&SVPWM_Cal_M,&PWMCali_M); + + LBG_Status_Init(&MLBG_M,&LBG_Status_M); + + Buffer_Clear(&(LBG_SpeedBuffer_M[0]),&(MLBG_M.SpeedBuffPara)); + + HFVQI_Status_Init_M(&HFVQI_StartStruc_M); + + Buffer_Clear(&(HFVQIPosi_CBuff_M[0]),&HFVQIPosi_CBuffPara_M); + + Powercom_Status_Init(&Powercom_M); + + ADC_1R_Offset_Reading(ADC1,&ADC_M,1); + ADC_1R_Offset_Reading(ADC2,&ADC_M,2); + + ADC_Status_Init (&ADC_M); + + Triac_Status_Init(&Triac_ctl,&Tempctl_M); + + SVPWM_Zerovolt_Output_Immediate(&SVPWM_Cal_M); + + TIM_CtrlPWMOutputs(TIM1,ENABLE); + + TempLed_Set(&Key_M,&LED_M); + + SpeedLed_Set(&SpeedRamp_M,&LED_M); +} + +/****************************************************************************** +* Function Name : Injstart_Parameter_Define_M +* Description : Definition of Current Injection Start Parameters +* Input : Pointer to motor start control structure +* Output : None +* Return : None +******************************************************************************/ +void Injstart_Parameter_Define_M (InjStart_Type *InjStart) +{ + + InjStart->ForceInjCurrStep = _IQdiv(FORCE_INJ_CURR_M,FORCE_INJ_CURR_RAMP_TIME_M)/FORCE_INJ_FREQ_M; + + InjStart->ForceInjCurrTarget = FORCE_INJ_CURR_M; + + InjStart->ForceInjCurrAngle = FORCE_INJ_ANGLE_M; + + InjStart->ForceInjStage = RAMP_INJ_STAGE_M; + + InjStart->RampInjCurrTarget = RAMP_INJ_CURR_FINAL_M; + + InjStart->RampInjCurrStep = _IQdiv((RAMP_INJ_CURR_FINAL_M - RAMP_INJ_CURR_INIT_M),\ + RAMP_INJ_CURR_RAMP_TIME_M)/RAMP_INJ_FREQ_M; + + InjStart->RampInjSpeedTarget = RAMP_INJ_SPEED_M*STARTUP_DIRECTION; + + InjStart->RampInjSpeedStep = _IQdiv(RAMP_INJ_SPEED_M,RAMP_INJ_SPEED_RAMP_TIME_M)/RAMP_INJ_FREQ_M; + + InjStart->K_WetoPosi = RAMP_INJ_PERIOD_M*RATED_FREQ_M; + + InjStart->CurrErrThresh = INJECTION_CURRERR_THRESH_M; + + InjStart->RampInjStage1 = RAMP_INJ_STAGE1_M; + InjStart->RampInjStage2 = RAMP_INJ_STAGE2_M; + + InjStart->Speedadj = RAMP_INJ_SPEED_ADJ*STARTUP_DIRECTION; + InjStart->Curradj = RAMP_INJ_CURR_ADJ; + + InjStart->IF_Vicom.Kcom = IF_VICOM_COEF_M * STARTUP_DIRECTION; + InjStart->IF_Vicom.Wecomupper = IF_VICOM_UPPER_M; + InjStart->IF_Vicom.Wecomlower = IF_VICOM_LOWER_M; + InjStart->IF_Vicom.Power_HPF1st.Input_Coef=_IQdiv(UNIT_Q24,(IF_VICOM_HPF1st_WcT_M + UNIT_Q24)); + InjStart->IF_Vicom.Power_HPF1st.Output_Coef=_IQdiv(UNIT_Q24,(IF_VICOM_HPF1st_WcT_M + UNIT_Q24)); +} + +/****************************************************************************** +* Function Name : Injstart_Status_Init_M +* Description : Current injection start-up state initialization +* Input : Pointer to motor start control structure +* Output : None +* Return : None +******************************************************************************/ +void Injstart_Status_Init_M(InjStart_Type *InjStart) +{ + InjStart->ForceInjCurrRef = _IQ(0); + InjStart->ForceInjCounter = 0; + + InjStart->RampInjCurrRef = RAMP_INJ_CURR_INIT_M; + InjStart->RampInjSpeedRef = RAMP_INJ_SPEEDINT_M *STARTUP_DIRECTION; + InjStart->RampInjAngle = _IQ(0); + InjStart->RampInjCounter =0; + InjStart->Curr_2R.cd = _IQ(0); + InjStart->Curr_2R.cq = _IQ(0); + InjStart->VoltRef_2R.cd = _IQ(0); + InjStart->VoltRef_2R.cq = _IQ(0); + InjStart->Status = INITIAL; + + InjStart->InjStage=0; + + InjStart->IF_Vicom.Powerinst = 0; + InjStart->IF_Vicom.Powerfilter = 0; + InjStart->IF_Vicom.Wecom = 0; + InjStart->IF_Vicom.Power_HPF1st.Out_New = 0; + InjStart->IF_Vicom.Power_HPF1st.Out_Pre = 0; + InjStart->IF_Vicom.Power_HPF1st.In_Pre = 0; +} + +/****************************************************************************** +* Function Name : Injstart_Process_M +* Description : Injection start, first force positioning, then current closed-loop start +* Input : Pointer to motor start control structure, +* pointer to overall motor status structure, +* pointer to LBG observer structure +* Output : None +* Return : None +******************************************************************************/ +void Injstart_Process_M(InjStart_Type *InjStart,Motor_Sructure_Type *MStruc,Motor_LBG_Type *MLBG) +{ + switch(InjStart->Status)//启动状态机 + { + case INITIAL: + InjStart->Status = INJECTION; + break; + + case INJECTION: + + if(InjStart->ForceInjCounter < U32_MAX) + InjStart->ForceInjCounter++; + + if(InjStart->ForceInjCurrRef < InjStart->ForceInjCurrTarget) + { + + InjStart->ForceInjCurrRef += InjStart->ForceInjCurrStep; + if(InjStart->ForceInjCurrRef > InjStart->ForceInjCurrTarget) + InjStart->ForceInjCurrRef = InjStart->ForceInjCurrTarget; + + MStruc->CRef2R.cd = InjStart->ForceInjCurrRef; + MStruc->CRef2R.cq = 0; + + MStruc->Cossin = TrigonoMetric_Function( InjStart->ForceInjCurrAngle); + } + else + { + if( _IQabs(MStruc->C2R_L.cd)>=_IQMPY_MACRO(InjStart->CurrErrThresh, + _IQabs(MStruc->CRef2R.cd))) + { + if( InjStart->ForceInjCounter >= InjStart->ForceInjStage) + { + InjStart->RampInjCurrRef = InjStart->ForceInjCurrRef; + InjStart->RampInjAngle = InjStart->ForceInjCurrAngle; + InjStart->Status = RAMP; + } + } + else + Protection_SetFault(STARTUP_FAILURE_M); + } + break; + case RAMP: + if(InjStart->RampInjCounter < U32_MAX) + InjStart->RampInjCounter++; + + Injstart_Curr_Speed_Ramp(InjStart); + + #if defined IF_VIBRATION_COM + IF_Vibration_Com(&(MStruc->VRef2R), &(MStruc->C2R_L), InjStart); + InjStart->RampInjAngle = InjStart->RampInjAngle +\ + _IQMPY_MACRO(InjStart->RampInjSpeedRef2,InjStart->K_WetoPosi); + #else + InjStart->RampInjAngle = InjStart->RampInjAngle +\ + _IQMPY_MACRO(InjStart->RampInjSpeedRef,InjStart->K_WetoPosi); + #endif + + InjStart->RampInjAngle = Round_Circle_Limitation_PU(InjStart->RampInjAngle); + + MStruc->Cossin = TrigonoMetric_Function(InjStart->RampInjAngle); + + MStruc->CRef2R.cd = InjStart->RampInjCurrRef; + MStruc->CRef2R.cq = 0; + + if(InjStart->RampInjCounter >= (InjStart->RampInjStage1)) + { + if(_IQabs(MStruc->C2R_L.cd)>=_IQMPY_MACRO(InjStart->CurrErrThresh,\ + _IQabs(MStruc->CRef2R.cd))) + { + if(MLBG->Cal_Struc.Inimark == TRUE) + Injstart_Transition_Cal(InjStart,MStruc,MLBG); + else + { + LBG_Cal_Init(InjStart,MStruc,MLBG); + MLBG->Cal_Struc.Inimark = TRUE; + } + } + else + Protection_SetFault(STARTUP_FAILURE_M); + } + else + { + MLBG->Cal_Struc.CalphaPrev = MStruc->C2S.Alpha; + MLBG->Cal_Struc.CbetaPrev = MStruc->C2S.Beta; + } + if (InjStart->RampInjCounter >=InjStart->RampInjStage2) + Protection_SetFault(STARTUP_FAILURE_M); + break; + default: + break; + } +} diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M5_MotorStart.h b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M5_MotorStart.h new file mode 100644 index 0000000..7133dae --- /dev/null +++ b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M5_MotorStart.h @@ -0,0 +1,61 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : M5_MotorStart.h + * Author : WCH + * Version : V1.0.0 + * Date : 2026/04/23 + * Description : Initialization of the motor before starting +********************************************************************************* +* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ + +#ifndef __M5_MOTORSTART_H +#define __M5_MOTORSTART_H +#define FORCE_INJ_FREQ_M FREQ_SVPWM +#define FORCE_INJ_CURR_M _IQ(0.3) +#define FORCE_INJ_ANGLE_M _IQ(0.083333*1) +#define FORCE_INJ_CURR_RAMP_TIME_M _IQ(0.2) +#define RAMP_INJ_STAGE_M (uint32_t)(FREQ_SVPWM*3) + +#define RAMP_INJ_FREQ_M FREQ_SVPWM +#define RAMP_INJ_PERIOD_M _IQ(1.0)/FREQ_SVPWM +#define RAMP_INJ_CURR_INIT_M _IQ(0.00) +#define RAMP_INJ_CURR_FINAL_M _IQ(0.4) +#define RAMP_INJ_CURR_RAMP_TIME_M _IQ(0.001) +#define RAMP_INJ_SPEEDINT_M _IQ(0.005) +#define RAMP_INJ_SPEED_M _IQ(0.2) +#define RAMP_INJ_SPEED_RAMP_TIME_M _IQ(0.2) +#define RAMP_INJ_STAGE1_M (uint32_t)(FREQ_SVPWM*0.15) +#define RAMP_INJ_STAGE2_M (uint32_t)(FREQ_SVPWM*0.6) +#define INJECTION_CURRERR_THRESH_M _IQ(0.5) +#define RAMP_INJ_SPEED_ADJ _IQ(0.05) +#define RAMP_INJ_CURR_ADJ _IQ(1.1) + +#define IF_VICOM_COEF_M _IQ(-0.15) +#define IF_VICOM_UPPER_M _IQ(0.01) +#define IF_VICOM_LOWER_M _IQ(-0.01) +#define IF_VICOM_PERIOD_M _IQ(1.0)/FREQ_SVPWM +#define IF_VICOM_HPF1st_CF_M 10 +#define IF_VICOM_HPF1st_WcT_M _IQmpy(_IQmpyI32(IF_VICOM_PERIOD_M,IF_VICOM_HPF1st_CF_M),PI_2_Q24) + +/* Exported variables -------------------------------------------------------*/ +extern InjStart_Type InjStart_M; + +void Motor_Start_Init_M(void); + +void Injstart_Parameter_Define_M (InjStart_Type *InjStart); + +void Injstart_Status_Init_M(InjStart_Type *InjStart); + +void Injstart_Process_M(InjStart_Type *InjStart,Motor_Sructure_Type *MStruc,Motor_LBG_Type *MLBG); + +void Controlloop_Initial(InjStart_Type *InjStart,_iq24 Speedact,Motor_Sructure_Type *MStruc,\ + Motor_PID_Type *Mpid,Speedrampctr_Type *Speed_Ramp); + +void Injstart_Curr_Speed_Ramp(InjStart_Type *InjStart); + +void Injstart_Transition_Cal(InjStart_Type *InjStart,Motor_Sructure_Type *MStruc,Motor_LBG_Type *MLBG); + +void Speedrampctr_Start_Init_M(Speedrampctr_Type *Speed_Ramp); +#endif diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M5_Operation_Cusevent.c b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M5_Operation_Cusevent.c new file mode 100644 index 0000000..cfd6a96 --- /dev/null +++ b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M5_Operation_Cusevent.c @@ -0,0 +1,152 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : M5_Operation_Cusevent.c + * Author : WCH + * Version : V1.0.0 + * Date : 2026/04/23 + * Description : +********************************************************************************* +* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ +#include "M0_Control_Library.h" + +Eventmanager_Type Emanager_M; +uint8_t testcounter =0; + +/****************************************************************************** +* Function Name : Eventmanager_Initial +* Description : Event manage Init +* Input : Event management structure pointer +* Output : None +* Return : None +******************************************************************************/ +void Eventmanager_Initial(Eventmanager_Type *EventM) +{ + EventM->Event_10ms= FALSE; + EventM->Event_10ms_cntset = (uint16_t)(EVENT_10ms*EVENT_CHECK_FREQ); + EventM->Event_10ms_cnt = 0; + + EventM->Event_1ms= FALSE; + EventM->Event_1ms_cntset = (uint16_t)(EVENT_1ms*EVENT_CHECK_FREQ); + EventM->Event_1ms_cnt = 0; + + EventM->Event_2s= FALSE; + EventM->Event_2s_cntset = (uint16_t)(EVENT_2s*EVENT_CHECK_FREQ); + EventM->Event_2s_cnt = 0; +} + +/****************************************************************************** +* Function Name : Zerocross_Process +* Description : AC input zero-crossing event handling +* Input : Temperature control structure pointer, thyristor control structure pointer, key management structure pointer +* Output : None +* Return : None +******************************************************************************/ +void ACZerocross_Process(Temperature_ctl_Type *TempM,Key_Manager_Type *KeyM,TRIAC_ctl_Type *TriacM) +{ + if((KeyM->Tkeyeffective==TRUE)||(KeyM->Skeyeffective==TRUE)) + TriacM->PeriodCtl.DutychangeFlag=TRUE; + + if( (TriacM->Zero.ZcrossEvent==1) && (TriacM->Zero.Zcrosseffective == TRUE) ) + { + #ifdef ZEROCROSSOVER_OC + if(TriacM->Zero.Zcrosseffectivecnt<2) + TriacM->Zero.Zcrosseffectivecnt++; + if(TriacM->Zero.Zcrosseffectivecnt>=2) + { + if(TriacM->PeriodCtl.DelayProcess_Flag==0)// + { + TriacM->Zero.ZcrossDelayTrigcnt=TriacM->Zero.ZcrossDelayTrigset; + TriacM->PeriodCtl.DelayProcess_Flag=1; + } + if((TriacM->Zero.ZcrossDelayTrigcnt==0)&&(TriacM->PeriodCtl.DelayProcess_Flag==1)) + { + TriacZero_50HZControl_Process(TempM,KeyM,TriacM,&SpeedRamp_M); + TriacM->Zero.Zcrosseffectivecnt=0; + TriacM->Zero.ZcrossEvent=0; + TriacM->PeriodCtl.DelayProcess_Flag=0; + } + } + else + { + TriacM->Zero.ZcrossEvent=0; + TriacM->PeriodCtl.DelayProcess_Flag=0; + } + + #else + + if(TriacM->PeriodCtl.DelayProcess_Flag==0)// + { + TriacM->Zero.ZcrossDelayTrigcnt=TriacM->Zero.ZcrossDelayTrigset; + TriacM->PeriodCtl.DelayProcess_Flag=1; + } + if((TriacM->Zero.ZcrossDelayTrigcnt==0)&&(TriacM->PeriodCtl.DelayProcess_Flag==1)) + { + TriacZero_50HZControl_Process(TempM,KeyM,TriacM,&SpeedRamp_M); + TriacM->Zero.ZcrossEvent=0; + TriacM->PeriodCtl.DelayProcess_Flag=0; + } + #endif + } +} + +/****************************************************************************** +* Function Name : Event_10ms_Process +* Description : 10ms Event process +* Input : Event management structure pointer +* Output : None +* Return : None +******************************************************************************/ +void Event_10ms_Process(Eventmanager_Type *EventM) +{ + if(EventM->Event_10ms == TRUE) + { +// testcounter++; +// +// if(testcounter ==2) +// LED_Lighton(&LED_M.YLED); +// if(testcounter ==4) +// { +// LED_Lightoff(&LED_M.YLED); +// testcounter = 0; +// } + + EventM->Event_10ms_cnt = EventM->Event_10ms_cntset; + EventM->Event_10ms = FALSE; + } +} + +/****************************************************************************** +* Function Name : Event_1ms_Process +* Description : 1ms Event Handling +* Input : Event management structure pointer +* Output : None +* Return : None +******************************************************************************/ +void Event_1ms_Process(Eventmanager_Type *EventM) +{ + //static u8 Event_50ms_cnt; + if(EventM->Event_1ms == TRUE) + { + + EventM->Event_1ms_cnt = EventM->Event_1ms_cntset; + EventM->Event_1ms = FALSE; + } +} + +/****************************************************************************** +* Function Name : Event_1ms_Process +* Description : 2s Event Handling +* Input : Event management structure pointer +* Output : None +* Return : None +******************************************************************************/ +void Event_2s_Process(Eventmanager_Type *EventM) +{ + if(EventM->Event_2s == TRUE)//定时到 + { + EventM->Event_2s_cnt = EventM->Event_2s_cntset; + EventM->Event_2s = FALSE; + } +} diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M5_Operation_and_Display.c b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M5_Operation_and_Display.c new file mode 100644 index 0000000..b9674ab --- /dev/null +++ b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M5_Operation_and_Display.c @@ -0,0 +1,1485 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : M5_Operation_and_Display.c + * Author : WCH + * Version : V1.0.0 + * Date : 2026/04/23 + * Description : Motor operation related processing +********************************************************************************* +* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ +#include "M0_Control_Library.h" +static volatile uint16_t Timewait = 0; + +Speedrampctr_Type SpeedRamp_M; +Powercontrol_Type Powerctr_M; +Led_Manager_Type LED_M; +Key_Manager_Type Key_M; +Operation_Type Operation_M; + +Temperature_ctl_Type Tempctl_M; + +uint8_t Keymembuff[EEWRITE_CYCLE]; +//uint8_t testcounter =0; + +/****************************************************************************** +* Function Name : Motor_Operation_Process +* Description : Motor Operation Handling +* Input : None +* Output : None +* Return : None +******************************************************************************/ +void Motor_Operation_Process(void) +{ + + switch (RunningStatus_M) + { + case IDLE: + if((Powerctr_M.Poweron == TRUE)&&(Key_M.ACkey_Poweron == TRUE)) + { + if(Key_M.Keymemreadmark == FALSE) + { + Key_Memread(&Key_M,&SpeedRamp_M,&Flash_M); + Key_M.Keymemreadmark = TRUE; + } + if((Operation_M.PSC.Mark ==FALSE)&&(Operation_M.PSC.Process ==TRUE)) + { + #if defined KEY_START + if(SpeedRamp_M.Speed_adncnt >0) + { + Key_Memwrite(&Key_M,&SpeedRamp_M,&Flash_M); + RunningStatus_M = INIT; + } + #elif defined POWERON_START + if(Powerctr_M.Poweron == TRUE) + { + RunningStatus_M = INIT; + } + #endif + } + } + break; + case INIT: + Motor_Start_Init_M(); + Time_Delay_Set(SpeedRamp_M.Precharge_cntset,&SpeedRamp_M.Precharge_cnt); + RunningStatus_M = PRESTART; + break; + + case PRESTART: + break; + + case POSITION: + break; + + case START: + break; + + case RUN: + break; + + case STOP: + TIM_CtrlPWMOutputs(TIM1, DISABLE); + ADC_1R_Start(DISABLE); + TRIAC_OFF(); + LED_OFF(&LED_M); + RunningStatus_M = WAIT; + Time_Delay_Set(Operation_M.StopwaitSet,&Operation_M.StopwaitCnt); + + break; + + case WAIT: + + if (Time_Delay_Elapse(Operation_M.StopwaitCnt) == TRUE) + { + RunningStatus_M = IDLE; + LED_OFF(&LED_M); + } + break; + case FAULT: + LED_Flicker(&(LED_M.LED4)); + TRIAC_OFF(); + break; + + default: + break; + } + + switch (RunningStatus_M) + { + case PRESTART: + case POSITION: + case START: + case RUN: + if(Powerctr_M.Poweron == TRUE) + { + if(((Key_M.Skeyeffective == TRUE)||(Key_M.Tkeyeffective == TRUE))&&(Flash_M.FlashExcep==0)) + { + Key_Memwrite(&Key_M,&SpeedRamp_M,&Flash_M); + } + } + else + { + Key_M.Skeyeffective = FALSE; + Key_M.Tkeyeffective = FALSE; + } + break; + + default: + break; + } + + Event_10ms_Process(&Emanager_M); + + Event_2s_Process(&Emanager_M); +} + +/****************************************************************************** +* Function Name : Speedrampctr_Parameter_Define +* Description : Definition of Speed Control Parameters +* Input : Acceleration and deceleration control structure pointer +* Output : None +* Return : None +*****************************************************************************/ +void Speedrampctr_Parameter_Define(Speedrampctr_Type *Speed_Ramp) +{ + Speed_Ramp->Direction=STARTUP_DIRECTION; + Speed_Ramp->Speed_Rank = SPEEDPOINT_RANK; + Speed_Ramp->Speed1 = SPEEDPOINT1*Speed_Ramp->Direction; + Speed_Ramp->Speed2 = SPEEDPOINT2*Speed_Ramp->Direction; + Speed_Ramp->Speed3 = SPEEDPOINT3*Speed_Ramp->Direction; + + Speed_Ramp->Aftramp = RAMP_INJ_SPEED_M*Speed_Ramp->Direction; + + Speed_Ramp->AccStep = _IQ(1.0)/(SPEED_LOOP_CAL_FREQ*ACCE_TIME_M); + Speed_Ramp->DecStep = _IQ(1.0)/(SPEED_LOOP_CAL_FREQ*DECE_TIME_M); + Speed_Ramp->PoweroffDecStep= _IQ(1.0)/(SPEED_LOOP_CAL_FREQ*POWEROFF_DECE_TIME_M); + + Speed_Ramp->Startfinishspeed = START_FINISH_SPEED; + Speed_Ramp->Startfinish =FALSE; + Speed_Ramp->Faststopspeed = FAST_DECE_SPEED*Speed_Ramp->Direction; + + Speed_Ramp->Break = FALSE; + Speed_Ramp->BreakStop = FALSE; + Speed_Ramp->Breakspeed = BREAKSPEED; + Speed_Ramp->Breakwait_cntset = (uint16_t)(BREAKTIME*SPEED_RAMP_FREQ_M); + + Speed_Ramp->Precharge_cntset = (uint16_t)(PRECHAGE_TIME*SPEED_RAMP_FREQ_M); + +#ifdef POWERON_START + Speed_Ramp->Stopmode =1; +#else + Speed_Ramp->Stopmode =2; +#endif + +#ifdef KEY_START //按键启动 + Speed_Ramp->Speed_adncnt =0; +#endif + + Speed_Ramp->VdcLPF1st.Input_Coef = _IQdiv(VDCLPF_SPEEDLIM_WcT_M,(VDCLPF_SPEEDLIM_WcT_M + UNIT_Q24)); + Speed_Ramp->VdcLPF1st.Output_Coef = _IQdiv(UNIT_Q24,(VDCLPF_SPEEDLIM_WcT_M + UNIT_Q24)); + Speed_Ramp->VdcLPF1st.Out_New =_IQ(1.0); + Speed_Ramp->VdcLPF1st.Out_Pre =_IQ(1.0); + Speed_Ramp->Voltbegin = VDC_SPEEDLIM_BEGIN; + Speed_Ramp->Voltrelease = VDC_SPEEDLIM_RELEASE; + Speed_Ramp->Speedlimmark = FALSE; + Speed_Ramp->Vdclimcoef = _IQdiv(_IQ(1.0),_IQmpy(VDC_SPEEDLIM_ADJ,VDC_SPEEDLIM_BEGIN)); +} + +/****************************************************************************** +* Function Name : Speedrampctr_Start_Init_M +* Description : Speed Control Parameter Initialization +* Input : Acceleration and deceleration control structure pointer +* Output : None +* Return : None +*****************************************************************************/ +void Speedrampctr_Start_Init_M(Speedrampctr_Type *Speed_Ramp) +{ + Speed_Ramp->Aftramp = RAMP_INJ_SPEED_M*Speed_Ramp->Direction; + Speed_Ramp->Startfinish =FALSE; + Speed_Ramp->BreakStop = FALSE; + Speed_Ramp->Faststopspeed = FAST_DECE_SPEED*Speed_Ramp->Direction; + Speed_Ramp->Break = FALSE; + Speed_Ramp->Speedlimmark = FALSE; + + Speed_Ramp->VdcLPF1st.Out_New =ADC_M.DCVoltAver; + Speed_Ramp->VdcLPF1st.Out_Pre =ADC_M.DCVoltAver; +} + +/****************************************************************************** +* Function Name : Poweroperation_Initial +* Description : Power-on and power-off parameter initialization and state initialization +* Input : Power on/off control structure pointer +* Output : None +* Return : None +*****************************************************************************/ +void Poweroperation_Initial(Powercontrol_Type *PowerOper) +{ + PowerOper->Poweron_CntThresh = (uint16_t)(POWERVERY_FREQ*POWERON_TIME); + PowerOper->Poweron_Volt = POWERON_VOLT; + PowerOper->Poweroff_Volt1 = POWEROFF_VOLT1; + PowerOper->Poweroff_Volt2 = POWEROFF_VOLT2; + PowerOper->Poweron = FALSE; + PowerOper->Poweron_Cnt = 0; + PowerOper->DCVoltAverSizeInv1 = _IQ(1.0)/POWERVERY_DCVOLTAVERSIZE; + PowerOper->DCVoltAverSizeInv2 = _IQ(1.0) - PowerOper->DCVoltAverSizeInv1; + PowerOper->DCVoltAver = 0; +} + +/****************************************************************************** +* Function Name : KEY_AND_LEDIO_Init +* Description : Button and indicator light IO configuration +* Input : None +* Output : None +* Return : None +******************************************************************************/ +void KeyandLED_IOInit(void) +{ + GPIO_InitTypeDef GPIO_InitStructure={0}; + + RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO|RCC_APB2Periph_GPIOA|\ + RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOD, ENABLE); + + GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable, ENABLE); + + GPIO_StructInit(&GPIO_InitStructure); + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14|GPIO_Pin_12; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; + GPIO_Init(GPIOA, &GPIO_InitStructure); + + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; + GPIO_Init(GPIOB, &GPIO_InitStructure); + + GPIO_StructInit(&GPIO_InitStructure); + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; + GPIO_Init(GPIOA, &GPIO_InitStructure); + + GPIO_StructInit(&GPIO_InitStructure); + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_Init(GPIOB, &GPIO_InitStructure); + GPIO_SetBits(GPIOB, GPIO_Pin_7); + +} + +/****************************************************************************** +* Function Name : KeyandLED_Parameter_Define +* Description : Rotation Speed and LED Parameter Definition +* Input : Pointer to key management structure, pointer to LED management structure +* Output : None +* Return : None +******************************************************************************/ +void KeyandLED_Parameter_Define(Key_Manager_Type *KeyM,Led_Manager_Type *LEDM) +{ + KeyM->SHkey_checkinterval = (uint16_t)(SHKEY_CHECK_INTERVAL*KEY_CHECK_FREQ); + KeyM->SHkey_effcnt_thresh = (uint16_t)(SHKEY_EFFECTIVE_TIME*KEY_CHECK_FREQ); + KeyM->SHkey_ineff_cntthresh = (uint16_t)(SHKEY_INEFFECTIVE_TIME*KEY_CHECK_FREQ); + KeyM->SHkey_Speedset=FALSE; + + KeyM->SRkey_effcnt_thresh = (uint16_t)(SRKEY_EFFECTIVE_TIME*KEY_CHECK_FREQ); + KeyM->SRkey_ineff_cntthresh = (uint16_t)(SRKEY_INEFFECTIVE_TIME*KEY_CHECK_FREQ); + + KeyM->Tkey_rankset = TKEY_RANK_SET; + KeyM->Tkey_cyccntthresh = (uint16_t)(TKEY_LONG_TIME*KEY_CHECK_FREQ); + KeyM->Tkey_shtcntthreshdown = (uint16_t)(TKEY_SHORT_TIME_DOWM*KEY_CHECK_FREQ); + KeyM->Tkey_shtcntthreshup = (uint16_t)(TKEY_SHORT_TIME_UP*KEY_CHECK_FREQ); + + KeyM->EEwritewaitset = (uint16_t)(EEWRITE_WAITING_TIME*KEY_CHECK_FREQ); + KeyM->EEwritecycset = EEWRITE_CYCLE; + + KeyM->TCkey_effcnt_thresh=(uint16_t)(TCKEY_EFFECTIVE_TIME*KEY_CHECK_FREQ); + KeyM->TCkey_ineff_cntthresh=(uint16_t)(TCKEY_INEFFECTIVE_TIME*KEY_CHECK_FREQ); + + KeyM->Keymemreadmark = FALSE; + + KeyM->ACkey_checkinterval = (uint16_t)(ACKEY_CHECK_INTERVAL*KEY_CHECK_FREQ); + KeyM->ACkey_effcnt_thresh = (uint16_t)(ACKEY_EFFECTIVE_TIME*KEY_CHECK_FREQ); + KeyM->ACkey_ineff_cntthresh = (uint16_t)(ACKEY_INEFFECTIVE_TIME*KEY_CHECK_FREQ); + KeyM->ACkey_checkcnt = 0; + KeyM->ACkey_effcnt = 0; + KeyM->ACkey_ineff_cnt = 0; + KeyM->ACkey_Poweron = FALSE; + + KeyM->TCkey_effcnt = 0; + KeyM->TCkey_ineff_cnt = 0; + KeyM->TCkeycold= FALSE; + +#ifndef POWERON_START + SpeedRamp_M.Speed_adncnt = 0; +#endif + + LEDM->Pin1.Group = GPIOB; + LEDM->Pin1.Pin = GPIO_Pin_8; + + LEDM->Pin2.Group = GPIOA; + LEDM->Pin2.Pin = GPIO_Pin_0; + + LEDM->Pin3.Group = GPIOA; + LEDM->Pin3.Pin = GPIO_Pin_11; + + LEDM->LED4.FlickInterval = (uint16_t)(LED_PROCESS_FREQ*LED_FLICKER_TIME); + LEDM->LED5.FlickInterval = (uint16_t)(LED_PROCESS_FREQ*LED_FLICKER_TIME); + LEDM->LED6.FlickInterval = (uint16_t)(LED_PROCESS_FREQ*LED_FLICKER_TIME); + LEDM->LED7.FlickInterval = (uint16_t)(LED_PROCESS_FREQ*LED_FLICKER_TIME); + LEDM->LED8.FlickInterval = (uint16_t)(LED_PROCESS_FREQ*LED_FLICKER_TIME); + LEDM->LED9.FlickInterval = (uint16_t)(LED_PROCESS_FREQ*LED_FLICKER_TIME); + + LEDM->LED4.LightFlag=OFF; + LEDM->LED5.LightFlag=OFF; + LEDM->LED6.LightFlag=OFF; + LEDM->LED7.LightFlag=OFF; + LEDM->LED8.LightFlag=OFF; + LEDM->LED9.LightFlag=OFF; +} + +/****************************************************************************** +* Function Name : KeyandLED_Status_Ini +* Description : Initialize rotational speed and LED status +* Input : Pointer to key management structure, pointer to LED management structure +* Output : None +* Return : None +******************************************************************************/ +void KeyandLED_Status_Ini(Key_Manager_Type *KeyM,Led_Manager_Type *LEDM) +{ + KeyM->SHkey_checkcnt = 0; + KeyM->SHkey_effcnt1 = 0; + KeyM->SHkey_ineff_cnt1 = 0; + KeyM->SHkey_effcnt2 = 0; + KeyM->SHkey_ineff_cnt2 = 0; + + KeyM->SRkey_effcnt =0; + KeyM->SRkey_ineff_cnt =0; + + KeyM->Skeyeffective = FALSE; + KeyM->Skeystop = FALSE; + KeyM->Skeystopcnt = 0; + + KeyM->Tkeycnt = 0; + KeyM->Tkeyeffective = FALSE; + + KeyM->EEwritecyccnt = 0; + KeyM->EEwritewaitcnt = 0; +} + +/****************************************************************************** +* Function Name : Tempkeycheck +* Description : Temperature control key detection +* Input : Button management structure pointer +* Output : None +* Return : None +******************************************************************************/ +void Tempkeycheck(Key_Manager_Type *KeyM) +{ + if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_14) == 0) + { + if(KeyM->Tkeycnt< U16_MAX) + KeyM->Tkeycnt++; + } + else + { + if((RunningStatus_M==RUN)&&((KeyM->Tkeycnt >= KeyM->Tkey_shtcntthreshdown)&&(KeyM->Tkeycnt <=KeyM->Tkey_shtcntthreshup)) && ( KeyM->TCkeycold==FALSE) && (Tempctl_M.NTCOverStatus==FALSE) && (Tempctl_M.NTCOpenStatus==FALSE))//短按 没有按一键制冷 + { + if(KeyM->Tkey_rank >= KeyM->Tkey_rankset) + KeyM->Tkey_rank_Dir = DIRDOWN; + else if (KeyM->Tkey_rank <=0) + KeyM->Tkey_rank_Dir = DIRUP; + + if(KeyM->Tkey_rank_Dir == DIRUP) + KeyM->Tkey_rank ++; + else if(KeyM->Tkey_rank_Dir == DIRDOWN) + KeyM->Tkey_rank --; + + KeyM->Tkeycyc = FALSE; + KeyM->Tkeycnt = 0; + KeyM->Tkeyeffective = TRUE; + TempLed_Set(&Key_M,&LED_M); + } + +// else if(KeyM->Tkeycnt >= KeyM->Tkey_cyccntthresh) +// { +// KeyM->Tkeycyc = TRUE; +// KeyM->Tkeycnt = 0; +// } + else + { + KeyM->Tkeycnt = 0; + } + } +} +/****************************************************************************** +* Function Name : Coldkeycheck +* Description : One-touch cooling symbol +* Input : Button management structure pointer +* Output : None +* Return : None +******************************************************************************/ +void Coldkeycheck(Key_Manager_Type *KeyM) +{ + + if(GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_11) == 0) + KeyM->TCkey_effcnt++; + else + KeyM->TCkey_ineff_cnt++; + + + if(KeyM->TCkey_effcnt >= KeyM->TCkey_effcnt_thresh) + { + KeyM->TCkeycold=TRUE; + KeyM->TCkey_effcnt = 0; + KeyM->TCkey_ineff_cnt = 0; + } + else if(KeyM->TCkey_ineff_cnt >= KeyM->TCkey_ineff_cntthresh) + { + KeyM->TCkeycold=FALSE; + KeyM->TCkey_effcnt = 0; + KeyM->TCkey_ineff_cnt = 0; + } +} + +/****************************************************************************** +* Function Name : Speedkeycheck_Hold +* Description : Speed Button Detection_Push-to-Shift Hold Type +* Input : Pointer to key management structure, acceleration and deceleration control structure +* Output : None +* Return : None +******************************************************************************/ +void Speedkeycheck_Hold(Key_Manager_Type *KeyM,Speedrampctr_Type *Speed_Ramp) +{ + KeyM->SHkey_checkcnt++; + + if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_2) == 0) + KeyM->SHkey_effcnt1++; + else + KeyM->SHkey_ineff_cnt1++; + + if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_2) == 0) + KeyM->SHkey_effcnt2++; + else + KeyM->SHkey_ineff_cnt2++; + + if (KeyM->SHkey_checkcnt >= KeyM->SHkey_checkinterval) + { + if(KeyM->SHkey_effcnt2 >= KeyM->SHkey_effcnt_thresh) + { + if((KeyM->ACkey_Poweron==TRUE)&&(Powerctr_M.Poweron == TRUE)) + { + if( Speed_Ramp->Speed_adncnt !=2) + { + Speed_Ramp->Speed_adncnt = 2; + KeyM->Skeyeffective = TRUE; + KeyM->SHkey_Speedset= TRUE; + } + } + } + else if(KeyM->SHkey_effcnt1 >= KeyM->SHkey_effcnt_thresh) + { + if((KeyM->ACkey_Poweron==TRUE)&&(Powerctr_M.Poweron == TRUE)) + { + if( Speed_Ramp->Speed_adncnt != 1) + { + Speed_Ramp->Speed_adncnt = 1; + KeyM->Skeyeffective = TRUE; + KeyM->SHkey_Powerdown = FALSE; + KeyM->SHkey_Speedset= TRUE; + } + } + } + + KeyM->SHkey_checkcnt = 0; + KeyM->SHkey_effcnt1 = 0; + KeyM->SHkey_ineff_cnt1 = 0; + KeyM->SHkey_effcnt2 = 0; + KeyM->SHkey_ineff_cnt2 = 0; + } + switch(RunningStatus_M) + { + case PRESTART: + case POSITION: + case START: + case RUN: + if(Powerctr_M.Poweron == TRUE) + { + if((KeyM->Skeystop == TRUE)||(Operation_M.Faultstop == TRUE)) + { + if(KeyM->SkeystopcntSkeystopcnt ++; + + if(KeyM->Skeystopcnt <=1) + { + if(RunningStatus_M == RUN) + { + if(_IQabs(Speed_Ramp->Aftramp) > _IQabs(MLBG_M.Cal_Struc.Angspeed_Aver2)) + Speed_Ramp->Aftramp = MLBG_M.Cal_Struc.Angspeed_Aver2; + Speed_Ramp->Preramp = Speed_Ramp->Faststopspeed; + Mpid_M.Speed.Output_New = 0; + Mpid_M.Speed.Output_Prev = 0; + Speed_Ramp->BreakStop = TRUE; + } + else if(RunningStatus_M == START) + { + Speed_Ramp->BreakStop = TRUE; + } + else + RunningStatus_M = STOP; + } + } + if((KeyM->SHkey_Speedset==TRUE)) + { + if((KeyM->Skeystop == FALSE)&&(Operation_M.Faultstop == FALSE)) + { + Speed_Set(Speed_Ramp); + } + KeyM->SHkey_Speedset=FALSE; + } + } + break; + default: + break; + } + if((KeyM->ACkey_Poweron==FALSE)||(Powerctr_M.Poweron == FALSE)) + { + Speed_Ramp->Speed_adncnt = 0; + KeyM->SHkey_Speedset = FALSE; + } +} + +/****************************************************************************** +* Function Name : Speedkeycheck_Recover +* Description : Speed Button Detection_Restore Cyclic Type +* Input : Pointer to key management structure, acceleration and deceleration control structure +* Output : None +* Return : None +******************************************************************************/ +void Speedkeycheck_Recover(Key_Manager_Type *KeyM,Speedrampctr_Type *Speed_Ramp) +{ + if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_12) == 0) + KeyM->SRkey_effcnt++; + else + KeyM->SRkey_ineff_cnt++; + + if(KeyM->SRkey_ineff_cnt >= KeyM->SRkey_ineff_cntthresh) + { + if(KeyM->SRkey_effcnt >= KeyM->SRkey_effcnt_thresh) + { + #if defined POWERON_START + if(((RunningStatus_M==RUN)||(RunningStatus_M==START))&&\ + (Powerctr_M.Poweron == TRUE)&&(KeyM->ACkey_Poweron == TRUE)&&(Operation_M.Faultstop==FALSE)) + { + if(Speed_Ramp->Speed_adncnt >= Speed_Ramp->Speed_Rank) + KeyM->Skey_rank_Dir = DIRDOWN; + else if (Speed_Ramp->Speed_adncnt <=1) + KeyM->Skey_rank_Dir = DIRUP; + + if(KeyM->Skey_rank_Dir == DIRUP) + Speed_Ramp->Speed_adncnt ++; + else if(KeyM->Skey_rank_Dir == DIRDOWN) + Speed_Ramp->Speed_adncnt --; + KeyM->Skeyeffective = TRUE;//档位变化有效 + KeyM->SHkey_Speedset= TRUE; + } + + #elif defined KEY_START + if((Powerctr_M.Poweron == TRUE)&&(KeyM->ACkey_Poweron == TRUE)&&(Operation_M.Faultstop==FALSE)&&((RunningStatus_M==IDLE)||(RunningStatus_M==RUN)||(RunningStatus_M==START))) + { + Speed_Ramp->Speed_adncnt ++; + if(Speed_Ramp->Speed_adncnt > Speed_Ramp->Speed_Rank) + { + Speed_Ramp->Speed_adncnt = 0; + Key_M.Skeystop = TRUE; + } + if((RunningStatus_M==RUN)||(RunningStatus_M==START))// + KeyM->SHkey_Speedset= TRUE; + // KeyM->Skeyeffective = TRUE;//档位变化有效 + } + #endif + } + KeyM->SRkey_effcnt = 0; + KeyM->SRkey_ineff_cnt = 0; + } + switch(RunningStatus_M) + { + case PRESTART: + case POSITION: + case START: + case RUN: + if(Powerctr_M.Poweron == TRUE) + { + if(KeyM->SHkey_Speedset==TRUE) + { + if(Operation_M.Faultstop==FALSE) + { + Speed_Set(Speed_Ramp); + SpeedLed_Set(Speed_Ramp,&LED_M); + } + KeyM->SHkey_Speedset=FALSE; + } + if((Key_M.Skeystop == TRUE)||(Operation_M.Faultstop == TRUE)) + { + if(Key_M.SkeystopcntAftramp)>_IQabs(MLBG_M.Cal_Struc.Angspeed_Aver2)) + Speed_Ramp->Aftramp = MLBG_M.Cal_Struc.Angspeed_Aver2; + + Speed_Ramp->Preramp = Speed_Ramp->Faststopspeed; + Mpid_M.Speed.Output_New = 0; + Mpid_M.Speed.Output_Prev = 0; + Speed_Ramp->BreakStop = TRUE; + } + else if(RunningStatus_M == START) + { + Speed_Ramp->BreakStop = TRUE; + } + else + RunningStatus_M = STOP; + } + } + } + break; + + default: + break; + } + if((KeyM->ACkey_Poweron==FALSE)||(Powerctr_M.Poweron == FALSE)) + { + #if defined KEY_START + Speed_Ramp->Speed_adncnt = 0; + #endif + KeyM->SHkey_Speedset=FALSE; + } + +} + +/****************************************************************************** +* Function Name : Speed_Set +* Description : Speed setting +* Input : Pointer to acceleration and deceleration control structure, pointer to power-on and power-off control structure +* Output : None +* Return : None +*****************************************************************************/ +void Speed_Set(Speedrampctr_Type *Speed_Ramp) +{ + switch(Speed_Ramp->Speed_adncnt) + { + case 1: + Speed_Ramp->Preramp = Speed_Ramp->Speed1; + break; + case 2: + Speed_Ramp->Preramp = Speed_Ramp->Speed2; + break; + case 3: + Speed_Ramp->Preramp = Speed_Ramp->Speed3; + break; + default: + break; + } +} + +/****************************************************************************** +* Function Name : Temp_Set +* Description : Temperature Setting +* Input : Pointer to key management structure, pointer to acceleration and deceleration control structure +* Output : None +* Return : None +*****************************************************************************/ +void Temp_Set(Key_Manager_Type *KeyM,Speedrampctr_Type *Speed_Ramp,TRIAC_ctl_Type *TriacM) +{ + switch(KeyM->Tkey_rank) + { + case 1: + switch(Speed_Ramp->Speed_adncnt) + { + case 1: + TriacM->PeriodCtl.Serial_Nummax=(TriacM->PeriodCtl.Dutymax_T1S1-TriacM->PeriodCtl.NumData); + TriacM->PeriodCtl.Serial_Nummin=(TriacM->PeriodCtl.Dutymin_T1S1-TriacM->PeriodCtl.NumData); + TriacM->PeriodCtl.Duty_TS=(TriacM->PeriodCtl.Dutydefault_T1S1); + break; + case 2: + TriacM->PeriodCtl.Serial_Nummax=(TriacM->PeriodCtl.Dutymax_T1S2-TriacM->PeriodCtl.NumData); + TriacM->PeriodCtl.Serial_Nummin=(TriacM->PeriodCtl.Dutymin_T1S2-TriacM->PeriodCtl.NumData); + TriacM->PeriodCtl.Duty_TS=(TriacM->PeriodCtl.Dutydefault_T1S2); + break; + case 3: + TriacM->PeriodCtl.Serial_Nummax=(TriacM->PeriodCtl.Dutymax_T1S3-TriacM->PeriodCtl.NumData); + TriacM->PeriodCtl.Serial_Nummin=(TriacM->PeriodCtl.Dutymin_T1S3-TriacM->PeriodCtl.NumData); + TriacM->PeriodCtl.Duty_TS=(TriacM->PeriodCtl.Dutydefault_T1S3); + break; + default: + break; + } + break; + case 2://温度挡位2 + switch(Speed_Ramp->Speed_adncnt) + { + case 1: + TriacM->PeriodCtl.Serial_Nummax=(TriacM->PeriodCtl.Dutymax_T2S1-TriacM->PeriodCtl.NumData); + TriacM->PeriodCtl.Serial_Nummin=(TriacM->PeriodCtl.Dutymin_T2S1-TriacM->PeriodCtl.NumData); + TriacM->PeriodCtl.Duty_TS=(TriacM->PeriodCtl.Dutydefault_T2S1); + break; + case 2: + TriacM->PeriodCtl.Serial_Nummax=(TriacM->PeriodCtl.Dutymax_T2S2-TriacM->PeriodCtl.NumData); + TriacM->PeriodCtl.Serial_Nummin=(TriacM->PeriodCtl.Dutymin_T2S2-TriacM->PeriodCtl.NumData); + TriacM->PeriodCtl.Duty_TS=(TriacM->PeriodCtl.Dutydefault_T2S2); + break; + case 3: + TriacM->PeriodCtl.Serial_Nummax=(TriacM->PeriodCtl.Dutymax_T2S3-TriacM->PeriodCtl.NumData); + TriacM->PeriodCtl.Serial_Nummin=(TriacM->PeriodCtl.Dutymin_T2S3-TriacM->PeriodCtl.NumData); + TriacM->PeriodCtl.Duty_TS=(TriacM->PeriodCtl.Dutydefault_T2S3); + break; + default: + break; + } + break; + case 3: + switch(Speed_Ramp->Speed_adncnt) + { + case 1: + TriacM->PeriodCtl.Serial_Nummax=(TriacM->PeriodCtl.Dutymax_T3S1-TriacM->PeriodCtl.NumData); + TriacM->PeriodCtl.Serial_Nummin=(TriacM->PeriodCtl.Dutymin_T3S1-TriacM->PeriodCtl.NumData); + TriacM->PeriodCtl.Duty_TS=(TriacM->PeriodCtl.Dutydefault_T3S1); + break; + case 2: + TriacM->PeriodCtl.Serial_Nummax=(TriacM->PeriodCtl.Dutymax_T3S2-TriacM->PeriodCtl.NumData); + TriacM->PeriodCtl.Serial_Nummin=(TriacM->PeriodCtl.Dutymin_T3S2-TriacM->PeriodCtl.NumData); + TriacM->PeriodCtl.Duty_TS=(TriacM->PeriodCtl.Dutydefault_T3S2); + break; + case 3: + TriacM->PeriodCtl.Serial_Nummax=(TriacM->PeriodCtl.Dutymax_T3S3-TriacM->PeriodCtl.NumData); + TriacM->PeriodCtl.Serial_Nummin=(TriacM->PeriodCtl.Dutymin_T3S3-TriacM->PeriodCtl.NumData); + TriacM->PeriodCtl.Duty_TS=(TriacM->PeriodCtl.Dutydefault_T3S3); + break; + default: + break; + } + break; + default: + break; + } +//#endif +} + +/****************************************************************************** +* Function Name : Key_Memwrite +* Description : Key Memory Writing +* Input : Pointer to key management structure, acceleration and deceleration control structure +* Output : None +* Return : None +******************************************************************************/ +void Key_Memwrite(Key_Manager_Type *KeyM,Speedrampctr_Type *Speed_Ramp,Flash_Operation_Type *FlashM) +{ + KeyM->Keytowrite = ((Speed_Ramp->Speed_adncnt&0x0F)<<4)&0x70; + + KeyM->Keytowrite = KeyM->Keytowrite|(KeyM->Tkey_rank&0x07); + + if(KeyM->Tkey_rank_Dir == DIRUP) + { + KeyM->Keytowrite = KeyM->Keytowrite|0x08; + } + else + { + KeyM->Keytowrite = KeyM->Keytowrite&0xF7; + } + + if(KeyM->Skey_rank_Dir == DIRUP) + { + KeyM->Keytowrite = KeyM->Keytowrite|0x80; + } + else + { + KeyM->Keytowrite = KeyM->Keytowrite&0x7F; + } + + if(FlashM->MemAddress<(PAGE_WRITE_HALF_END_ADDR-4)) + { + for(KeyM->EEwritecyccnt=0;KeyM->EEwritecyccnt < KeyM->EEwritecycset;KeyM->EEwritecyccnt++) + { + Flash_ProgramHalfWord(FlashM,(KeyM->EEwritecyccnt*2048+FlashM->MemAddress),(u16)(KeyM->Keytowrite)); + } + FlashM->MemAddress+=2; + } + if(FlashM->FlashExcep!=1) + { + FlashM->FlashData[0]=KeyM->Keytowrite; + FlashM->FlashData[1]=KeyM->Keytowrite; + } + + KeyM->Skeyeffective = FALSE; + KeyM->Tkeyeffective = FALSE; + +} + +/****************************************************************************** +* Function Name : Keymem_Read +* Description : Key Memory Recall +* Input : Pointer to key management structure, acceleration and deceleration control structure +* Output : None +* Return : None +*****************************************************************************/ +void Key_Memread(Key_Manager_Type *KeyM,Speedrampctr_Type *Speed_Ramp,Flash_Operation_Type *FlashM) +{ + uint8_t i,j; + + for(i=0; iEEwritecycset; i++) + Keymembuff[i]=FlashM->FlashData[i]; + + for(i=0,j=1; iEEwritecycset-1; i++,j++) + { + if((Keymembuff[i]!=Keymembuff[j])||(FlashM->FlashExcep==1)) + { + KeyM->Tkey_rank = 0; + #ifdef POWERON_START + Speed_Ramp->Speed_adncnt = 1; + #endif + break; + } + else + { + //温度档赋值 + KeyM->Tkey_rank = Keymembuff[0]&0x07;//bit210; + if(KeyM->Tkey_rank > KeyM->Tkey_rankset) + KeyM->Tkey_rank = 0; + + if((Keymembuff[0]&0x08)!=0) + KeyM->Tkey_rank_Dir = DIRUP; + else + KeyM->Tkey_rank_Dir = DIRDOWN; + + #ifdef POWERON_START + + Speed_Ramp->Speed_adncnt = (Keymembuff[0]&0x70)>>4;//bit654 + + if((Keymembuff[0]&0x80)!=0) + KeyM->Skey_rank_Dir = DIRUP; + else + KeyM->Skey_rank_Dir = DIRDOWN; + + if((Speed_Ramp->Speed_adncnt > Speed_Ramp->Speed_Rank)||(Speed_Ramp->Speed_adncnt ==0)) + Speed_Ramp->Speed_adncnt = 1; + + Key_Memwrite(&Key_M,&SpeedRamp_M,&Flash_M); + #endif + } + } +} + +/****************************************************************************** +* Function Name : Time_Delay_Process +* Description : The program is used for variable decrement processing based on interrupt time (0.5 ms). +* Input : None +* Output : None +* Return : None +******************************************************************************/ +void Time_Delay_Process(void) +{ + if (Timewait != 0) + Timewait --; + + if (Operation_M.StopwaitCnt != 0) + Operation_M.StopwaitCnt --; + + if (Key_M.EEwritewaitcnt != 0) + Key_M.EEwritewaitcnt --; + + if (Operation_M.FaultHoldingCnt != 0) + Operation_M.FaultHoldingCnt--; + + if (SpeedRamp_M.Breakwait_cnt != 0) + { + SpeedRamp_M.Breakwait_cnt --; + } + + if (SpeedRamp_M.Precharge_cnt != 0) + SpeedRamp_M.Precharge_cnt --; + + if (LED_M.LED4.FlickCnt != 0) + LED_M.LED4.FlickCnt --; + + if (LED_M.LED5.FlickCnt != 0) + LED_M.LED5.FlickCnt --; + + if (LED_M.LED6.FlickCnt != 0) + LED_M.LED6.FlickCnt --; + + if (LED_M.LED7.FlickCnt != 0) + LED_M.LED7.FlickCnt --; + + if (LED_M.LED8.FlickCnt != 0) + LED_M.LED8.FlickCnt --; + + if (Emanager_M.Event_10ms_cnt != 0) + Emanager_M.Event_10ms_cnt --; + else + Emanager_M.Event_10ms = TRUE; + + if (Emanager_M.Event_1ms_cnt != 0) + Emanager_M.Event_1ms_cnt --; + else + Emanager_M.Event_1ms = TRUE; + + if (Emanager_M.Event_2s_cnt != 0) + Emanager_M.Event_2s_cnt --; + else + Emanager_M.Event_2s = TRUE; + + + if (Operation_M.PSC.Ledcnt != 0) + Operation_M.PSC.Ledcnt --; + + if (Triac_ctl.TonEnable_cnt != 0) + Triac_ctl.TonEnable_cnt--; + + if (Triac_ctl.Zero.ZcrossDelayTrigcnt != 0) + Triac_ctl.Zero.ZcrossDelayTrigcnt--; + + +} + +/****************************************************************************** +* Function Name : Time_Wait +* Description : The function wait for a delay to be over. +* Input : None +* Output : None +* Return : None +******************************************************************************/ +void Time_Wait(uint16_t time) +{ + Timewait = time; + while (Timewait != 0) + {;} +} + +/****************************************************************************** +* Function Name : Time_Delay_Set +* Description : Timer time setting function +* Input : Timing time, timer count variable pointer +* Output : None +* Return : None +******************************************************************************/ +void Time_Delay_Set(uint16_t Delayset, uint16_t *Delaycounter) +{ + *Delaycounter = Delayset; +} + +/****************************************************************************** +* Function Name : Time_Delay_Elapse +* Description : Timer expiration determination +* Input : timing and counting variable +* Output : Judgment result, time reached: TRUE, time not reached: FALSE +* Return : Judgment result +******************************************************************************/ +Truth_Verify_Type Time_Delay_Elapse(uint16_t Delaycounter) +{ + if (Delaycounter == 0) + return (TRUE); + else + return (FALSE); +} + +/****************************************************************************** +* Function Name : Operation_Parameter_Define +* Description : Operation Parameter Definition +* Input : Operate control structure pointer +* Output : None +* Return : None +*****************************************************************************/ +void Operation_Parameter_Define(Operation_Type *Operastruc) +{ + Operastruc->StopwaitSet = (uint16_t)(STOP_WAITING_TIME * OPERATION_CAL_FREQ); + Operastruc->FaultHoldingSet = (uint16_t)(FAULT_HOLDING_TIME * OPERATION_CAL_FREQ); + Operastruc->Faultstop = FALSE; + + Operastruc->PSC.Ledinttimeset = (uint16_t)(PSC_LED_INTERVAL*PSC_FREQ); + Operastruc->PSC.Ledintnumset = PSC_LED_INTERVAL_NUM; + Operastruc->PSC.Ledintnumtotalset = (uint16_t)(PSC_LED_INTERVAL_TOTAL/PSC_LED_INTERVAL); + Operastruc->PSC.Ledlasttimeset = (uint16_t)(PSC_LED_LAST*PSC_FREQ); + + Operastruc->PSC.Mark = FALSE; + Operastruc->PSC.Stage = NONE; + Operastruc->PSC.Process = FALSE; + Operastruc->PSC.Ledintdir =DIRUP; +} + +/****************************************************************************** +* Function Name : Operation_Status_Init +* Description : Operation status initialization +* Input : Operate control structure pointer +* Output : None +* Return : None +*****************************************************************************/ +void Operation_Status_Init(Operation_Type *Operastruc) +{ + Operastruc->StopwaitCnt = 0; + Operastruc->FaultHoldingCnt = 0; + Operastruc->reset_cnt = 0; + + Operastruc->PSC.Ledcnt = 0; + Operastruc->PSC.Ledintnum = 0; + Operastruc->PSC.Ledintnumtotal = 0; +} + +/****************************************************************************** +* Function Name : Poweroperation_Process +* Description : Power On/Off Control Logic +* Input : Pointer to acceleration and deceleration control structure, +* pointer to ADC sampling structure, pointer to power-on/off control structure, +* operating status, pointer to speed PID controller, actual speed +* Output : None +* Return : None +******************************************************************************/ +void Poweroperation_Process(Speedrampctr_Type *SpeedRamp,ADCStruc_Type *ADCStruc,\ + Powercontrol_Type *PowerOper,Runningstatus_Type *Runningstatus,\ + PID_Structure_Type *Speedpid,_iq24 Speedact) +{ + PowerOper->DCVoltAver = _IQMPY_MACRO(PowerOper->DCVoltAver,PowerOper->DCVoltAverSizeInv2)\ + + _IQMPY_MACRO(ADCStruc->DCVoltPres,PowerOper->DCVoltAverSizeInv1); + + if((_IQabs(SpeedRamp->Aftramp) >= SpeedRamp->Startfinishspeed)&&(_IQabs(Speedact) >= SpeedRamp->Startfinishspeed)) + SpeedRamp->Startfinish = TRUE; + + if( PowerOper->DCVoltAver <= PowerOper->Poweroff_Volt2) + { +// if(*Runningstatus == RUN || *Runningstatus == INIT \ +// || *Runningstatus == START|| *Runningstatus == PRESTART) +// { +// if(SpeedRamp->Break !=FALSE)//不在刹车状态 +// { +// *Runningstatus = STOP; +// SpeedRamp->Break =FALSE; +// } +// } + PowerOper->Poweron = FALSE; + } + + if(PowerOper->Poweron == TRUE) + { + if(( PowerOper->DCVoltAver < PowerOper->Poweroff_Volt1)&&( PowerOper->DCVoltAver > PowerOper->Poweroff_Volt2)) + { + if(*Runningstatus == RUN) + { + if(_IQabs(SpeedRamp->Aftramp)>_IQabs(Speedact)) + SpeedRamp->Aftramp = Speedact; + SpeedRamp->Preramp = SpeedRamp->Faststopspeed; + Speedpid->Output_New = 0; + Speedpid->Output_Prev = 0; + } + PowerOper->Poweron = FALSE; + } + } + + if( PowerOper->DCVoltAver > PowerOper->Poweron_Volt) + { + PowerOper->Poweron_Cnt++; + if(PowerOper->Poweron_Cnt >= PowerOper->Poweron_CntThresh) + { + PowerOper->Poweron = TRUE; + PowerOper->Poweron_Cnt = 0; + } + } +} + +/****************************************************************************** +* Function Name : LED_Reset +* Description : LED Reset +* Input : LED Management Pointer +* Output : None +* Return : None +******************************************************************************/ +void LED_Reset(Led_Manager_Type *LEDM) +{ + LEDM->Pin1.Group->CFGHR&=~(0xf<<(4*0));//PB8 + LEDM->Pin2.Group->CFGLR&=~(0xf<<(4*0));//PA0 + LEDM->Pin3.Group->CFGHR&=~(0xf<<(4*3));//PA11 + + LEDM->Pin1.Group->CFGHR|=(0x4<<(4*0));//PB8 + LEDM->Pin2.Group->CFGLR|=(0x4<<(4*0));//PA0 + LEDM->Pin3.Group->CFGHR|=(0x4<<(4*3));//PA11 + +} +/****************************************************************************** +* Function Name : LED4_ON +* Description : LED4ON +* Input : LED Management Pointer +* Output : None +* Return : None +******************************************************************************/ +void LED4_ON(Led_Manager_Type *LEDM) +{ + LEDM->Pin1.Group->CFGHR&=~(0xf<<(4*0));//PB8 + LEDM->Pin1.Group->CFGHR|=0x3<<(4*0); + GPIO_SetBits( LEDM->Pin1.Group,LEDM->Pin1.Pin); +} + +/****************************************************************************** +* Function Name : LED5_ON +* Description : LED5ON +* Input : LED Management Pointer +* Output : None +* Return : None +******************************************************************************/ +void LED5_ON(Led_Manager_Type *LEDM) +{ + LEDM->Pin1.Group->CFGHR&=~(0xf<<(4*0));//PB8 + LEDM->Pin1.Group->CFGHR|=0x3<<(4*0); + GPIO_ResetBits( LEDM->Pin1.Group,LEDM->Pin1.Pin); +} + +/****************************************************************************** +* Function Name : LED6_ON +* Description : LED6ON +* Input : LED Management Pointer +* Output : None +* Return : None +******************************************************************************/ +void LED6_ON(Led_Manager_Type *LEDM) +{ + LEDM->Pin2.Group->CFGLR&=~(0xf<<(4*0));//PA0 + LEDM->Pin2.Group->CFGLR|=0x3<<(4*0); + GPIO_ResetBits( LEDM->Pin2.Group,LEDM->Pin2.Pin); +} + +/****************************************************************************** +* Function Name : LED7_ON +* Description : LED7ON +* Input : LED Management Pointer +* Output : None +* Return : None +******************************************************************************/ +void LED7_ON(Led_Manager_Type *LEDM) +{ + LEDM->Pin2.Group->CFGLR&=~(0xf<<(4*0));//PA0 + LEDM->Pin2.Group->CFGLR|=0x3<<(4*0); + GPIO_SetBits( LEDM->Pin2.Group,LEDM->Pin2.Pin); +} + +/****************************************************************************** +* Function Name : LED8_ON +* Description : LED8ON +* Input : LED Management Pointer +* Output : None +* Return : None +******************************************************************************/ +void LED8_ON(Led_Manager_Type *LEDM) +{ + LEDM->Pin3.Group->CFGHR&=~(0xf<<(4*3));//PA11 + LEDM->Pin3.Group->CFGHR|=0x3<<(4*3); + GPIO_ResetBits( LEDM->Pin3.Group,LEDM->Pin3.Pin); +} + +/****************************************************************************** +* Function Name : LED9_ON +* Description : LED9ON +* Input : LED Management Pointer +* Output : None +* Return : None +******************************************************************************/ +void LED9_ON(Led_Manager_Type *LEDM) +{ + LEDM->Pin3.Group->CFGHR&=~(0xf<<(4*3));//PA11 + LEDM->Pin3.Group->CFGHR|=0x3<<(4*3); + GPIO_SetBits( LEDM->Pin3.Group,LEDM->Pin3.Pin); +} + +/****************************************************************************** +* Function Name : Led_Operation +* Description : LED operation +* Input : LED Management Pointer +* Output : None +* Return : None +******************************************************************************/ +void Led_Operation(Led_Manager_Type *LEDM) +{ + static u8 Led_cnt; + Led_cnt++; + if(Led_cnt>2) + Led_cnt=1 ; + + LED_Reset(LEDM); + switch(Led_cnt) + { + case 1: + if(((LEDM->LED5.LightFlag)&&(Key_M.TCkeycold==FALSE))||((LEDM->LED5.LightFlag)&&(Tempctl_M.NTCFlickerStatus ==TRUE))||((LEDM->LED5.LightFlag)&&(RunningStatus_M ==FAULT))) + LED5_ON(LEDM); + + if(((LEDM->LED6.LightFlag)&&(Key_M.TCkeycold==FALSE))||((LEDM->LED6.LightFlag)&&(Tempctl_M.NTCFlickerStatus ==TRUE))||((LEDM->LED6.LightFlag)&&(RunningStatus_M ==FAULT))) + LED6_ON(LEDM); + + if(LEDM->LED8.LightFlag) + LED8_ON(LEDM); + break; + case 2: + if(((LEDM->LED4.LightFlag)&&(Key_M.TCkeycold==FALSE))|| ((LEDM->LED4.LightFlag)&&(Tempctl_M.NTCFlickerStatus ==TRUE))||((LEDM->LED4.LightFlag)&&(RunningStatus_M ==FAULT)) )//温度 + LED4_ON(LEDM); + + if(LEDM->LED7.LightFlag) + LED7_ON(LEDM); + + if(LEDM->LED9.LightFlag) + LED9_ON(LEDM); + } + +} +/****************************************************************************** +* Function Name : SpeedLed_Set +* Description : Speed gear LED setting +* Input : Pointer to acceleration and deceleration control structure, pointer to LED management structure +* Output : None +* Return : None +*****************************************************************************/ +void SpeedLed_Set(Speedrampctr_Type *Speed_Ramp,Led_Manager_Type *LEDM) +{ + switch(Speed_Ramp->Speed_adncnt) + { + case 0: + LEDM->LED7.LightFlag=0; + LEDM->LED8.LightFlag=0; + LEDM->LED9.LightFlag=0; + break; + case 1: + LEDM->LED7.LightFlag=1; + LEDM->LED8.LightFlag=0; + LEDM->LED9.LightFlag=0; + break; + case 2: + LEDM->LED7.LightFlag=1; + LEDM->LED8.LightFlag=1; + LEDM->LED9.LightFlag=0; + break; + case 3: + LEDM->LED7.LightFlag=1; + LEDM->LED8.LightFlag=1; + LEDM->LED9.LightFlag=1; + break; + default: + break; + } +} + +/****************************************************************************** +* Function Name :TempLed_Set +* Description : Temperature gear LED setting +* Input : Pointer to key management structure, pointer to LED management structure +* Output : None +* Return : None +*****************************************************************************/ +void TempLed_Set(Key_Manager_Type *KeyM,Led_Manager_Type *LEDM) +{ +// if((Tempctl_M.NTCFlickerStatus ==FALSE) && (KeyM->TCkeycold==FALSE) && (Tempctl_M.NTCShortStatus==FALSE) && (Tempctl_M.NTCOpenStatus==FALSE) ) +// { + switch(KeyM->Tkey_rank) + { + case 0: + LEDM->LED4.LightFlag=0; + LEDM->LED5.LightFlag=0; + LEDM->LED6.LightFlag=0; + break; + case 1: + LEDM->LED4.LightFlag=0; + LEDM->LED5.LightFlag=0; + LEDM->LED6.LightFlag=1; + break; + case 2: + LEDM->LED4.LightFlag=0; + LEDM->LED5.LightFlag=1; + LEDM->LED6.LightFlag=1; + break; + case 3: + LEDM->LED4.LightFlag=1; + LEDM->LED5.LightFlag=1; + LEDM->LED6.LightFlag=1; + break; + default: + break; + } + // } +} + +/****************************************************************************** +* Function Name : LED_OFF +* Description : LED OFF +* Input : Pointer to LED management structure +* Output : None +* Return : None +*****************************************************************************/ +void LED_OFF(Led_Manager_Type *LEDM) +{ + LED_M.LED4.LightFlag=0; + LED_M.LED5.LightFlag=0; + LED_M.LED6.LightFlag=0; + LED_M.LED7.LightFlag=0; + LED_M.LED8.LightFlag=0; + LED_M.LED9.LightFlag=0; +} + +/****************************************************************************** +* Function Name : LED_Flicker +* Description : LED Flicker Handling +* Input : LED structure pointer +* Output : None +* Return : None +******************************************************************************/ +void LED_Flicker(LED_Type *LedM) +{ + if (Time_Delay_Elapse(LedM->FlickCnt) == TRUE) + { + LedM->FlickCtl++; + Time_Delay_Set(LedM->FlickInterval,&(LedM->FlickCnt)); + + if(LedM->FlickCtl == 1) + { + LED_M.LED4.LightFlag=1; + LED_M.LED5.LightFlag=1; + LED_M.LED6.LightFlag=1; + } + + if(LedM->FlickCtl == 2) + { + LED_M.LED4.LightFlag=0; + LED_M.LED5.LightFlag=0; + LED_M.LED6.LightFlag=0; + LedM->FlickCtl =0; + } + + LED_M.LED7.LightFlag=0; + LED_M.LED8.LightFlag=0; + LED_M.LED9.LightFlag=0; + } +} + +/****************************************************************************** +* Function Name : ACON_CHECK +* Description : AC power-on detection +* Input : Button management structure pointer +* Output : None +* Return : None +******************************************************************************/ +void ACKEY_CHECK(Key_Manager_Type *KeyM) +{ + KeyM->ACkey_checkcnt++; + + //AC上电 + if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_3) == 0) + KeyM->ACkey_effcnt++; + else + KeyM->ACkey_ineff_cnt++; + + if (KeyM->ACkey_checkcnt >= KeyM->ACkey_checkinterval) + { + if(KeyM->ACkey_effcnt >= KeyM->ACkey_effcnt_thresh) + { + KeyM->ACkey_Poweron = TRUE; + } + else if(KeyM->ACkey_ineff_cnt >= KeyM->ACkey_ineff_cntthresh) + { + KeyM->ACkey_Poweron = FALSE; + } + + KeyM->ACkey_checkcnt = 0; + KeyM->ACkey_effcnt = 0; + KeyM->ACkey_ineff_cnt = 0; + } +} + +/****************************************************************************** +* Function Name : PSC_Process +* Description : Power-on self-test processing +* Input : Pointer to key management structure, pointer to LED management structure +* Output : None +* Return : None +******************************************************************************/ +void PSC_Process(Operation_Type *Operation) +{ + switch (Operation->PSC.Stage) + { + case NONE: +#ifdef POWERONCHECK + if((GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_2) == 0)&&(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_12)== 0)&&(Key_M.ACkey_Poweron == FALSE)) + Operation->PSC.Stage = CHECK; +#endif + Operation->PSC.Process = TRUE; + + break; + case CHECK: + + if((GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_2) == 0)&&(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_12)== 0)&&(Key_M.ACkey_Poweron == TRUE)) + { + Operation->PSC.Mark =TRUE; + + Operation_M.PSC.Ledintnum = 0; + Operation_M.PSC.Ledintnumtotal = 0; + + Operation->PSC.Stage = INTERVAL; + Time_Delay_Set(Operation->PSC.Ledinttimeset,&(Operation->PSC.Ledcnt)); + } + break; + + case INTERVAL: + if(Operation->PSC.Ledcnt ==0) + { + if(Operation->PSC.Ledintdir == DIRUP) + { + Operation_M.PSC.Ledintnum++; + if(Operation_M.PSC.Ledintnum >= (Operation_M.PSC.Ledintnumset-1)) + { + Operation->PSC.Ledintdir = DIRDOWN; + } + } + else if(Operation->PSC.Ledintdir == DIRDOWN) + { + Operation_M.PSC.Ledintnum--; + if(Operation_M.PSC.Ledintnum <= 0) + { + Operation->PSC.Ledintdir = DIRUP; + } + } + + Operation_M.PSC.Ledintnumtotal++; + + Time_Delay_Set(Operation_M.PSC.Ledinttimeset,&(Operation->PSC.Ledcnt)); + } + LED_Reset(&LED_M); + switch(Operation->PSC.Ledintnum) + { + case 0: + LED9_ON(&LED_M); + break; + + case 1: + LED8_ON(&LED_M); + break; + + case 2: + LED7_ON(&LED_M); + break; + + default: + break; + } + if(Operation_M.PSC.Ledintnumtotal >= Operation_M.PSC.Ledintnumtotalset) + { + Operation_M.PSC.Stage = LAST; + LED_Reset(&LED_M); + Time_Delay_Set(Operation->PSC.Ledlasttimeset,&(Operation->PSC.Ledcnt)); + } + break; + + case LAST: + LED6_ON(&LED_M); + if(Operation_M.PSC.Ledcnt ==0) + { + Operation_M.PSC.Stage = NONE; + LED_Reset(&LED_M); + } + break; + + default: + break; + } +} diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M5_Operation_and_Display.h b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M5_Operation_and_Display.h new file mode 100644 index 0000000..3e9f0b0 --- /dev/null +++ b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M5_Operation_and_Display.h @@ -0,0 +1,351 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : M5_Operation_and_Display.h + * Author : WCH + * Version : V1.0.0 + * Date : 2026/04/23 + * Description : Definition of relevant operation parameters such as buttons and displays + Definition of acceleration and deceleration parameters +********************************************************************************* +* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ + +#ifndef __MOTOR_OPERATION_AND_DISPLAY_H +#define __MOTOR_OPERATION_AND_DISPLAY_H + +typedef enum {FAILED = 0, PASSED = !FAILED} TestStatus; +typedef enum {OFF = 0, ON = !OFF} LightStatus; + +typedef struct +{ + uint8_t FlashExcep; + uint16_t FlashData[2]; + volatile uint32_t MemAddress; + volatile FLASH_Status FLASHStatus; + volatile TestStatus MemoryProgramStatus; + +} Flash_Operation_Type; + +typedef struct +{ + GPIO_TypeDef *Group; + uint16_t Pin; +} LEDGPIO_Type; +typedef struct +{ + uint16_t FlickInterval; + uint16_t FlickCnt; + uint8_t FlickCtl; + LightStatus LightFlag; +} LED_Type; + +typedef struct +{ + LED_Type LED4; + LED_Type LED5; + LED_Type LED6; + LED_Type LED7; + LED_Type LED8; + LED_Type LED9; + LEDGPIO_Type Pin1; + LEDGPIO_Type Pin2; + LEDGPIO_Type Pin3; +} Led_Manager_Type;//LED管理 + +/* Exported constants -------------------------------------------------------*/ +/*********************** 转速操作定义 ******************************/ +#define STARTUP_DIRECTION 1 +#define SPEED_ADJUST_STEP _IQ(0.05) +#define MAX_ANGSPEED_POS_M _IQ(1.0) +#define MAX_ANGSPEED_NEG_M _IQ(-1.0) +#define MIN_ANGSPEED_POS_M _IQ(0.025) +#define MIN_ANGSPEED_NEG_M _IQ(-0.025) +#define SPEED_RAMP_FREQ_M SPEED_LOOP_CAL_FREQ +#define ACCE_TIME_M 0.5 +#define DECE_TIME_M 0.4 +#define POWEROFF_DECE_TIME_M 0.15 + +#define SPEEDPOINT1 _IQ(0.7965085) +#define SPEEDPOINT2 _IQ(0.8545455) +#define SPEEDPOINT3 _IQ(0.9094380) +//#define SPEEDPOINT3 _IQ(0.92744135) +//#define SPEEDPOINT3 _IQ(0.9383524) +//#define SPEEDPOINT3 _IQ(0.954719) + +#define SPEEDPOINT_RANK 3 + +#define PRECHAGE_TIME 0.05 + +#define FAST_DECE_SPEED _IQ(0.6) +#define BREAKSPEED _IQ(0.65) +#define BREAKTIME 0.25 +#define START_FINISH_SPEED (FAST_DECE_SPEED +_IQ(0.055)) + + +#define LED_PROCESS_FREQ SPEED_LOOP_CAL_FREQ +#define LED_FLICKER_TIME 0.5 + +#define OPERATION_CAL_FREQ SPEED_LOOP_CAL_FREQ +#define STOP_WAITING_TIME 0.5 +#define FAULT_HOLDING_TIME 0.5 +#define SYS_RESET_TIME 0.025 + +#define POWERVERY_FREQ SPEED_LOOP_CAL_FREQ +#define POWERON_VOLT _IQ(0.85) +#define POWERON_TIME 0.1 +#define POWEROFF_VOLT1 _IQ(0.7) +#define POWEROFF_VOLT2 _IQ(0.5) +#define POWERVERY_DCVOLTAVERSIZE 4 + +#define VDCLPF_SPEEDLIM_CF_M 5 +#define VDCLPF_SPEEDLIM_PERIOD_M _IQ(1.0)/SPEED_LOOP_CAL_FREQ +#define VDCLPF_SPEEDLIM_WcT_M _IQmpyI32(_IQmpy(VDCLPF_SPEEDLIM_PERIOD_M,PI_2_Q24),VDCLPF_SPEEDLIM_CF_M) +#define VDC_SPEEDLIM_BEGIN _IQ(0.89) +#define VDC_SPEEDLIM_RELEASE _IQ(0.915) +#define VDC_SPEEDLIM_ADJ _IQ(1.1) + +#define KEY_CHECK_FREQ SPEED_LOOP_CAL_FREQ +#define EEWRITE_WAITING_TIME 0.005 +#define EEWRITE_CYCLE 2 + +#define SHKEY_CHECK_INTERVAL 0.040 +#define SHKEY_EFFECTIVE_TIME 0.010 +#define SHKEY_INEFFECTIVE_TIME 0.035 + +#define TCKEY_EFFECTIVE_TIME 0.010 +#define TCKEY_INEFFECTIVE_TIME 0.035 + +#define SRKEY_EFFECTIVE_TIME 0.1 +#define SRKEY_INEFFECTIVE_TIME 0.1 + +#define TKEY_RANK_SET 3 +#define TKEY_SHORT_TIME_UP 0.5 +#define TKEY_SHORT_TIME_DOWM 0.1 +#define TKEY_LONG_TIME 2 + +#define ACKEY_CHECK_INTERVAL 0.040 +#define ACKEY_EFFECTIVE_TIME 0.005 +#define ACKEY_INEFFECTIVE_TIME 0.035 + +#define ZEROCROSS_FREQ 100 +#define ZEROCROSS_VERYFREQ FREQ_SVPWM +#define OC_ZEROCROSS_VERYTIME 5 +#define TR_ZEROCROSS_VERYTIME 7 + +#define ZEROCROSSLOST_VERYTIME 0.05 +#define ZEROCROSSLOST_VERYFREQ FREQ_SVPWM + +#define EVENT_CHECK_FREQ SPEED_LOOP_CAL_FREQ +#define EVENT_10ms 0.01 +#define EVENT_1ms 0.001 +#define EVENT_2s 2.00 + +#define TRIAC_ENABLEWAIT 1.5 +#define TRIAC_OFF() (GPIO_SetBits(GPIOB, GPIO_Pin_7)) +#define TRIAC_ON() (GPIO_ResetBits(GPIOB, GPIO_Pin_7)) + +#define TRIAC_TIME 660 +#define TRIAC_CONTOROL_PERIOD 20 + +#ifdef ZEROCROSSOVER_OC +#define TRIAC_TIME_TO_TRIGGER 0.005 +#else +#define TRIAC_TIME_TO_TRIGGER 0.003 +#endif + +#define DUTYMAX_T1S1 13 +#define DUTYMIN_T1S1 3 +#define DUTYDEFAULT_T1S1 11 + +#define DUTYMAX_T1S2 17 +#define DUTYMIN_T1S2 3 +#define DUTYDEFAULT_T1S2 14 + +#define DUTYMAX_T1S3 19 +#define DUTYMIN_T1S3 3 +#define DUTYDEFAULT_T1S3 16 + + +#define DUTYMAX_T2S1 20 +#define DUTYMIN_T2S1 3 +#define DUTYDEFAULT_T2S1 16 +#define DUTYMAX_T2S2 20 +#define DUTYMIN_T2S2 3 +#define DUTYDEFAULT_T2S2 18 + +#define DUTYMAX_T2S3 23 +#define DUTYMIN_T2S3 3 +#define DUTYDEFAULT_T2S3 21 + + +#define DUTYMAX_T3S1 22 +#define DUTYMIN_T3S1 3 +#define DUTYDEFAULT_T3S1 19 + +#define DUTYMAX_T3S2 24 +#define DUTYMIN_T3S2 3 +#define DUTYDEFAULT_T3S2 20 + +#define DUTYMAX_T3S3 27 +#define DUTYMIN_T3S3 3 +#define DUTYDEFAULT_T3S3 23 + + +#define NUM50HZ_DATA (u8)3 +#define NUM100HZ_DATA (u8)6 + +#define PSC_LED_INTERVAL 0.2 +#define PSC_LED_INTERVAL_TOTAL 5.0 +#define PSC_LED_INTERVAL_NUM 3 +#define PSC_LED_LAST 3.0 +#define PSC_FREQ SPEED_LOOP_CAL_FREQ + +#define PT_RS _IQ18(10.0) +#define TEMP_AVER_SIZE (u32)8 + +//34~289 +#define DUTY_LIM_TABLE {\ +0x00643,0x006D0,0x00766,0x00803,0x008A9,0x00957,0x00A0E,0x00ACE,\ +0x00B96,0x00C68,0x00D42,0x00E26,0x00F14,0x0100B,0x0110C,0x01217,\ +0x0132B,0x0144A,0x01574,0x016A7,0x017E5,0x0192E,0x01A81,0x01BE0,\ +0x01D49,0x01EBD,0x0203C,0x021C6,0x0235C,0x024FD,0x026A9,0x02860,\ +0x02A23,0x02BF2,0x02DCC,0x02FB1,0x031A2,0x0339F,0x035A8,0x037BC,\ +0x039DB,0x03C07,0x03E3E,0x04081,0x042CF,0x0452A,0x0478F,0x04A01,\ +0x04C7E,0x04F06,0x0519B,0x0543A,0x056E5,0x0599C,0x05C5D,0x05F2A,\ +0x06202,0x064E5,0x067D4,0x06ACD,0x06DD1,0x070E0,0x073F9,0x0771D,\ +0x07A4B,0x07D84,0x080C7,0x08414,0x0876B,0x08ACC,0x08E37,0x091AB,\ +0x09529,0x098AF,0x09C3F,0x09FD8,0x0A37A,0x0A725,0x0AAD8,0x0AE93,\ +0x0B256,0x0B622,0x0B9F5,0x0BDD0,0x0C1B2,0x0C59B,0x0C98C,0x0CD83,\ +0x0D181,0x0D585,0x0D990,0x0DDA0,0x0E1B7,0x0E5D3,0x0E9F4,0x0EE1B,\ +0x0F246,0x0F676,0x0FAAB,0x0FEE4,0x10321,0x10762,0x10BA6,0x10FEE,\ +0x11439,0x11886,0x11CD7,0x12129,0x1257E,0x129D5,0x12E2D,0x13287,\ +0x136E2,0x13B3E,0x13F9B,0x143F8,0x14855,0x14CB3,0x15110,0x1556C,\ +0x159C8,0x15E23,0x1627C,0x166D4,0x16B2A,0x16F7E,0x173D0,0x17820,\ +0x17C6D,0x180B7,0x184FD,0x18941,0x18D80,0x191BC,0x195F4,0x19A27,\ +0x19E56,0x1A280,0x1A6A5,0x1AAC5,0x1AEDF,0x1B2F4,0x1B703,0x1BB0B,\ +0x1BF0E,0x1C30A,0x1C6FF,0x1CAED,0x1CED5,0x1D2B5,0x1D68D,0x1DA5E,\ +0x1DE27,0x1E1E8,0x1E5A1,0x1E951,0x1ECF9,0x1F098,0x1F42F,0x1F7BC,\ +0x1FB40,0x1FEBB,0x2022C,0x20594,0x208F2,0x20C46,0x20F90,0x212D0,\ +0x21605,0x21931,0x21C52,0x21F68,0x22273,0x22574,0x2286A,0x22B55,\ +0x22E35,0x23109,0x233D3,0x23691,0x23944,0x23BEC,0x23E88,0x24119,\ +0x2439E,0x24617,0x24885,0x24AE8,0x24D3E,0x24F89,0x251C9,0x253FC,\ +0x25624,0x25841,0x25A51,0x25C56,0x25E4F,0x2603D,0x2621F,0x263F6,\ +0x265C1,0x26780,0x26934,0x26ADD,0x26C7A,0x26E0C,0x26F93,0x2710F,\ +0x27280,0x273E6,0x27541,0x27691,0x277D6,0x27911,0x27A42,0x27B68,\ +0x27C84,0x27D96,0x27E9E,0x27F9C,0x28090,0x2817A,0x2825C,0x28333,\ +0x28402,0x284C8,0x28585,0x28639,0x286E5,0x28788,0x28823,0x288B6,\ +0x28942,0x289C5,0x28A42,0x28AB7,0x28B25,0x28B8C,0x28BEC,0x28C46,\ +0x28C9A,0x28CE7,0x28D2F,0x28D71,0x28DAE,0x28DE6,0x28E18,0x28E46,\ +0x28E70,0x28E95,0x28EB6,0x28ED3,0x28EEC,0x28F02,0x28F15,0x28F26}; +/* Exported variables -------------------------------------------------------*/ +extern Speedrampctr_Type SpeedRamp_M; +extern Powercontrol_Type Powerctr_M; +extern Led_Manager_Type LED_M; +extern Key_Manager_Type Key_M; +extern Eventmanager_Type Emanager_M; +extern Operation_Type Operation_M; +extern Temperature_ctl_Type Tempctl_M; +extern uint8_t Keymembuff[EEWRITE_CYCLE]; +extern TRIAC_ctl_Type Triac_ctl; + +extern u16 Temp_PhaseDuty[SPEEDPOINT_RANK][TKEY_RANK_SET+1]; + + +/* Exported macro -----------------------------------------------------------*/ +/* Exported functions ------------------------------------------------------ */ +void Motor_Operation_Process(void); + +void Speedrampctr_Parameter_Define(Speedrampctr_Type *Speed_Ramp); + +void Speedrampctr_Start_Init_M(Speedrampctr_Type *Speed_Ramp); + +void Speed_Set(Speedrampctr_Type *Speed_Ramp); + +void Poweroperation_Initial(Powercontrol_Type *PowerOper); + +void Poweroperation_Process(Speedrampctr_Type *SpeedRamp,ADCStruc_Type *ADCStruc,Powercontrol_Type *PowerOper,\ + Runningstatus_Type *Runningstatus,PID_Structure_Type *Speedpid,_iq24 Speedact); + +void KeyandLED_IOInit(void); + +void KeyandLED_Parameter_Define(Key_Manager_Type *KeyM,Led_Manager_Type *LEDM); + +void KeyandLED_Status_Ini(Key_Manager_Type *KeyM,Led_Manager_Type *LEDM); + +void Tempkeycheck(Key_Manager_Type *KeyM); + +void Speedkeycheck_Hold(Key_Manager_Type *KeyM,Speedrampctr_Type *Speed_Ramp); + +void Speedkeycheck_Recover(Key_Manager_Type *KeyM,Speedrampctr_Type *Speed_Ramp); + +void Coldkeycheck(Key_Manager_Type *KeyM); + +void Key_Memwrite(Key_Manager_Type *KeyM,Speedrampctr_Type *Speed_Ramp,Flash_Operation_Type *FlashM); + +void Key_Memread(Key_Manager_Type *KeyM,Speedrampctr_Type *Speed_Ramp,Flash_Operation_Type *FlashM); + +void Fault_LEDflicker(Led_Manager_Type *LED_M); + +void Time_Delay_Process(void); + +void Time_Wait(uint16_t); + +void Time_Delay_Set(uint16_t Delayset, uint16_t *Delaycounter); + +Truth_Verify_Type Time_Delay_Elapse(uint16_t Delaycounter); + +void Operation_Parameter_Define(Operation_Type *Operastruc); + +void Operation_Status_Init(Operation_Type *Operastruc); + +void Eventmanager_Initial(Eventmanager_Type *EventM); + +void AC_Zerocross_Detect(Key_Manager_Type *KeyM); + +void AC_Zerocross_Detect_OC(TRIAC_ctl_Type *TriacM); + +void AC_Zerocross_Detect_TR(TRIAC_ctl_Type *TriacM); + +void ACZerocross_Process(Temperature_ctl_Type *TempM,Key_Manager_Type *KeyM,TRIAC_ctl_Type *TriacM); + +void Event_10ms_Process(Eventmanager_Type *EventM); + +void Event_1ms_Process(Eventmanager_Type *EventM); + +void Event_2s_Process(Eventmanager_Type *EventM); + +void Triac_Parameter_Define(TRIAC_ctl_Type *TriacM,Temperature_ctl_Type *TempM); + +void Triac_Status_Init(TRIAC_ctl_Type *TriacM,Temperature_ctl_Type *TempM); + +void Temp_Set(Key_Manager_Type *KeyM,Speedrampctr_Type *Speed_Ramp,TRIAC_ctl_Type *TriacM); + +void Triac_Control_Process(TRIAC_ctl_Type *TriacM); + +void Temp_Ramp_Process(Temperature_ctl_Type *TempM); + +void TempInit_Measure(Temperature_ctl_Type *TempM,ADC_TypeDef *ADCx); + +void TriacPhAngle_Control_Process(Temperature_ctl_Type *TempM,Key_Manager_Type *KeyM,TRIAC_ctl_Type *TriacM); + +void TriacZero_50HZControl_Process(Temperature_ctl_Type *TempM,Key_Manager_Type *KeyM,TRIAC_ctl_Type *TriacM,Speedrampctr_Type *Speed_Ramp); + +void Triac_Timeoff(TRIAC_ctl_Type *TriacM); + +void ACKEY_CHECK(Key_Manager_Type *KeyM); + +void PSC_Process(Operation_Type *Operation); + +void Led_Operation(Led_Manager_Type *LEDM); + +void SpeedLed_Set(Speedrampctr_Type *Speed_Ramp,Led_Manager_Type *LEDM); + +void TempLed_Set(Key_Manager_Type *KeyM,Led_Manager_Type *LEDM); + +void LED_OFF(Led_Manager_Type *LEDM); + +void LED_Flicker(LED_Type *LedM); + +uint16_t Duty_lim(TRIAC_ctl_Type *TriacM,_iq24 value); +#endif diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M5_TRIAC_Control.c b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M5_TRIAC_Control.c new file mode 100644 index 0000000..c1d6b45 --- /dev/null +++ b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M5_TRIAC_Control.c @@ -0,0 +1,425 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : M5_TRIAC_Control.c + * Author : WCH + * Version : V1.0.0 + * Date : 2026/04/23 + * Description : +********************************************************************************* +* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ + +#include "M0_Control_Library.h" + +TRIAC_ctl_Type Triac_ctl; +//u16 Temp_PhaseDuty[SPEEDPOINT_RANK][TKEY_RANK_SET+1]={{0,85,110,125},{0,110,125,140},{0,125,145,165}}; +_iq24 DutyLim_table[256]=DUTY_LIM_TABLE; +/****************************************************************************** +* Function Name : Triac_Parameter_Define +* Description : Silicon Controlled Rectifier Control Parameter Initialization +* Input : Thyristor control pointer Temperature control pointer +* Output : None +* Return : None +******************************************************************************/ +void Triac_Parameter_Define(TRIAC_ctl_Type *TriacM,Temperature_ctl_Type *TempM) +{ + TriacM->PeriodCtl.NumData=NUM50HZ_DATA; + + TriacM->PeriodCtl.Period = (uint16_t)(TRIAC_TIME/TRIAC_CONTOROL_PERIOD); + TriacM->PeriodCtl.HalfPeriod = (TriacM->PeriodCtl.Period -1)/2; + TriacM->PeriodCtl.Serial_Nummax=0; + TriacM->PeriodCtl.Serial_Nummin=0; + TriacM->PeriodCtl.Serial_Num=0; + TriacM->PeriodCtl.Duty_TS=0; + + TriacM->PeriodCtl.Dutymax_T1S1=DUTYMAX_T1S1; + TriacM->PeriodCtl.Dutymin_T1S1=DUTYMIN_T1S1; + TriacM->PeriodCtl.Dutydefault_T1S1=DUTYDEFAULT_T1S1; + + TriacM->PeriodCtl.Dutymax_T2S1=DUTYMAX_T2S1; + TriacM->PeriodCtl.Dutymin_T2S1=DUTYMIN_T2S1; + TriacM->PeriodCtl.Dutydefault_T2S1=DUTYDEFAULT_T2S1; + + TriacM->PeriodCtl.Dutymax_T3S1=DUTYMAX_T3S1; + TriacM->PeriodCtl.Dutymin_T3S1=DUTYMIN_T3S1; + TriacM->PeriodCtl.Dutydefault_T3S1=DUTYDEFAULT_T3S1; + + + TriacM->PeriodCtl.Dutymax_T1S2=DUTYMAX_T1S2; + TriacM->PeriodCtl.Dutymin_T1S2=DUTYMIN_T1S2; + TriacM->PeriodCtl.Dutydefault_T1S2=DUTYDEFAULT_T1S2; + + TriacM->PeriodCtl.Dutymax_T2S2=DUTYMAX_T2S2; + TriacM->PeriodCtl.Dutymin_T2S2=DUTYMIN_T2S2; + TriacM->PeriodCtl.Dutydefault_T2S2=DUTYDEFAULT_T2S2; + + TriacM->PeriodCtl.Dutymax_T3S2=DUTYMAX_T3S2; + TriacM->PeriodCtl.Dutymin_T3S2=DUTYMIN_T3S2; + TriacM->PeriodCtl.Dutydefault_T3S2=DUTYDEFAULT_T3S2; + + TriacM->PeriodCtl.Dutymax_T1S3=DUTYMAX_T1S3; + TriacM->PeriodCtl.Dutymin_T1S3=DUTYMIN_T1S3; + TriacM->PeriodCtl.Dutydefault_T1S3=DUTYDEFAULT_T1S3; + + TriacM->PeriodCtl.Dutymax_T2S3=DUTYMAX_T2S3; + TriacM->PeriodCtl.Dutymin_T2S3=DUTYMIN_T2S3; + TriacM->PeriodCtl.Dutydefault_T2S3=DUTYDEFAULT_T2S3; + + TriacM->PeriodCtl.Dutymax_T3S3=DUTYMAX_T3S3; + TriacM->PeriodCtl.Dutymin_T3S3=DUTYMIN_T3S3; + TriacM->PeriodCtl.Dutydefault_T3S3=DUTYDEFAULT_T3S3; + +#ifdef ZEROCROSSOVER_OC + TriacM->Zero.Zcrossset=(uint16_t)OC_ZEROCROSS_VERYTIME;//光耦过零 +#else + TriacM->Zero.Zcrossset=(uint16_t)TR_ZEROCROSS_VERYTIME;//三极管过零 +#endif + + TriacM->Zero.Zcrosslostset=(uint16_t)(ZEROCROSSLOST_VERYTIME*ZEROCROSSLOST_VERYFREQ); + TriacM->Zero.SecondZcrossSet=(uint16_t)(ZEROCROSSLOST_VERYFREQ/ZEROCROSS_FREQ); + TriacM->Zero.ZcrossDelayTrigset=(uint16_t)(TRIAC_TIME_TO_TRIGGER*SPEED_LOOP_CAL_FREQ); + + TriacM->TonEnable_cntset=(uint16_t)(TRIAC_ENABLEWAIT*TIMER_FREQ_SPEED_LOOP); + + TempM->TempRatedADCInv=_IQ(1.0)/65536; + TempM->TempAverSizeInv1 = _IQ(1.0)/TEMP_AVER_SIZE; + TempM->TempAverSizeInv2 = _IQ(1.0) - TempM->TempAverSizeInv1; + +} + +/****************************************************************************** +* Function Name : ZeroCross_Status_Ini +* Description : Silicon-controlled rectifier start-up state initialization +* Input : SCR control structure Temperature control structure +* Output : None +* Return : None +******************************************************************************/ +void Triac_Status_Init(TRIAC_ctl_Type *TriacM,Temperature_ctl_Type *TempM) +{ + TriacM->Zero.Zcrosscnt = 0; + TriacM->Zero.ZcrossEvent=0; + TriacM->Zero.Zcrosslostcnt=0; + TriacM->Zero.Zcrosslost=FALSE; + TriacM->Zero.Zcrosseffective = FALSE; + + TriacM->Zero.ZcrossDelayTrigcnt=0; + TriacM->Zero.Zcrosseffectivecnt=0; + + TriacM->Zero.SecondZcrossCnt = 0; + TriacM->Zero.Prestatus = 0; + TriacM->Zero.Aftstatus = 0; + TriacM->Zero.Risingseffective =FALSE; + TriacM->Zero.Inittatus =FALSE; + TriacM->Zero.SecondZsseffective=FALSE; + + TriacM->TonEnable_cnt=0; + TriacM->TonEnable=0; + TriacM->ACVoltcaliMin=_IQ(1.0); + TriacM->ACVoltcali=_IQ(1.0); + TriacM->ACVoltcaliPrev=_IQ(1.0); + TriacM->ACVoltcali_Square=_IQ(1.0); + + + TriacM->PeriodCtl.Cnt=TriacM->PeriodCtl.Period; + TriacM->PeriodCtl.Serial_Num=0; + TriacM->PeriodCtl.DelayProcess_Flag=0; + TriacM->PeriodCtl.DutychangeFlag=FALSE; + +} + +/****************************************************************************** +* Function Name : AC_Zerocross_Detect_OC +* Description : Optocoupler AC Input Zero-Crossing Detection +* Input : SCR control structure pointer +* Output : None +* Return : None +******************************************************************************/ +void AC_Zerocross_Detect_OC(TRIAC_ctl_Type *TriacM) +{ + if(TriacM->Zero.Zcrosseffective == FALSE) + { + if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_3) == 1) + TriacM->Zero.Zcrosscnt++; + else + TriacM->Zero.Zcrosscnt = 0; + + if(TriacM->Zero.Zcrosscnt >= TriacM->Zero.Zcrossset) + { + TriacM->Zero.Zcrosseffective = TRUE; + TriacM->Zero.Zcrosscnt=0; + TriacM->Zero.ZcrossEvent=1; + TriacM->Zero.Zcrosslostcnt=0; + TriacM->Zero.Zcrosslost=FALSE; + + TriacM->PhaseCtl.Toncnt=0; + TriacM->PhaseCtl.TonStatus=FALSE; + TriacM->PhaseCtl.TonEvent=1; + + TriacM->ACVoltcali=TriacM->ACVoltcaliMin; + TriacM->ACVoltcaliMin=ADC_M.DCVoltcali; + } + } + else if((TriacM->Zero.Zcrosseffective == TRUE)&&( TriacM->Zero.ZcrossEvent==0)) + { + if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_3) == 0) + TriacM->Zero.Zcrosscnt++; + else + TriacM->Zero.Zcrosscnt = 0; + + if(TriacM->Zero.Zcrosscnt >= TriacM->Zero.Zcrossset) + { + TriacM->Zero.Zcrosseffective = FALSE; + TriacM->Zero.Zcrosscnt=0; + } + } + TriacM->Zero.Zcrosslostcnt++; + if(TriacM->Zero.Zcrosslostcnt >= TriacM->Zero.Zcrosslostset) + { + TriacM->Zero.Zcrosslost=TRUE; + TriacM->Zero.Zcrosslostcnt=0; + } +} +/****************************************************************************** +* Function Name : AC_Zerocross_Detect_TR +* Description : Transistor AC Input Zero-Crossing Detection +* Input : SCR control structure pointer +* Output : None +* Return : None +******************************************************************************/ +void AC_Zerocross_Detect_TR(TRIAC_ctl_Type *TriacM) +{ + if(TriacM->Zero.Zcrosseffective == FALSE) + { + if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_3) == 0) + TriacM->Zero.Zcrosscnt++; + else + TriacM->Zero.Zcrosscnt = 0; + + if(TriacM->Zero.Zcrosscnt >= TriacM->Zero.Zcrossset) + { + TriacM->Zero.Zcrosseffective = TRUE; + TriacM->Zero.Zcrosscnt=0; + TriacM->Zero.ZcrossEvent=1; + TriacM->Zero.Zcrosslostcnt=0; + TriacM->Zero.Zcrosslost=FALSE; + + TriacM->PhaseCtl.Toncnt=0; + TriacM->PhaseCtl.TonStatus=FALSE; + TriacM->PhaseCtl.TonEvent=1; + + TriacM->ACVoltcali=TriacM->ACVoltcaliMin; + TriacM->ACVoltcaliMin=ADC_M.DCVoltcali; + } + } + else if((TriacM->Zero.Zcrosseffective == TRUE)&&( TriacM->Zero.ZcrossEvent==0)) + { + if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_3) == 1) + TriacM->Zero.Zcrosscnt++; + else + TriacM->Zero.Zcrosscnt = 0; + + if(TriacM->Zero.Zcrosscnt >= TriacM->Zero.Zcrossset) + { + TriacM->Zero.Zcrosseffective = FALSE; + TriacM->Zero.Zcrosscnt=0; + } + } + TriacM->Zero.Zcrosslostcnt++; + if(TriacM->Zero.Zcrosslostcnt >= TriacM->Zero.Zcrosslostset) + { + TriacM->Zero.Zcrosslost=TRUE; + TriacM->Zero.Zcrosslostcnt=0; + } +} + +/****************************************************************************** +* Function Name : TriacZero50HZ_Control_Process +* Description : Thyristor Period Control Processing +* Input : Silicon-controlled rectifier control pointer Temperature gear Temperature control pointer +* Output : None +* Return : None +******************************************************************************/ +u_int32_t Triac50hz_Data[30]={0X80100100,0X80804040,0X81020810,0X82084108,0X84422110,0X88888888,0X89122448,0X92249224,\ + 0XA4924924,0X94949494,0XA4A5294A,0XA92A552A,0XA92B552A,0XAAAAAAAA,0XD5556AAA,0XD5AAD5AA,\ + 0XB5AD6B5A,0XD6D6D6D6,0XB6DB6DB6,0XDBB6DBB6,0XEDDBB76E,0XEEEEEEEE,0XF77BBDDE,0XF7DEF7DE,\ + 0XF7DFF7DE,0XFFDFF7DE,0XFFDFFFDE,0XFFFEFFFE,0XFFFFFFFE,0XFFFFFFFF};//占空比9.09%~96.9696% +void TriacZero_50HZControl_Process(Temperature_ctl_Type *TempM,Key_Manager_Type *KeyM,TRIAC_ctl_Type *TriacM,Speedrampctr_Type *Speed_Ramp) +{ + _iq24 ACVoltcali; + u32 data=0; + if((TriacM->TonEnable==1)&&(KeyM->Tkey_rank>0)&&( TriacM->Zero.Zcrosslost == FALSE)&&(KeyM->TCkeycold==FALSE)&&\ + (TempM->NTCOverStatus==FALSE)&&(TempM->NTCOpenStatus==FALSE)&&\ + (RunningStatus_M==RUN)&&(KeyM->Skeystop==FALSE)&&(Operation_M.Faultstop == FALSE)) + { + TriacM->PeriodCtl.Cnt++; + if(TriacM->PeriodCtl.Cnt>TriacM->PeriodCtl.Period) + { + TriacM->PeriodCtl.Cnt=1; + if(TriacM->PeriodCtl.DutychangeFlag==TRUE) + { + Temp_Set(KeyM,&SpeedRamp_M,TriacM); + TriacM->PeriodCtl.DutychangeFlag=FALSE; + } + + //ACVoltcali= TriacM->ACVoltcali; + ACVoltcali=ADC_M.DCVoltcali; + + TriacM->ACVoltcali_Square= _IQmpy(ACVoltcali, ACVoltcali); + + TriacM->PeriodCtl.Serial_Num=(u_int8_t)((TriacM->PeriodCtl.Duty_TS*TriacM->ACVoltcali_Square)>>24)-TriacM->PeriodCtl.NumData; + +// TriacM->PeriodCtl.Serial_Num=(u_int8_t)(TriacM->PeriodCtl.Duty_TS-TriacM->PeriodCtl.NumData); + + if(TriacM->PeriodCtl.Serial_Num>=TriacM->PeriodCtl.Serial_Nummax) + TriacM->PeriodCtl.Serial_Num=TriacM->PeriodCtl.Serial_Nummax; + else if(TriacM->PeriodCtl.Serial_Num<=TriacM->PeriodCtl.Serial_Nummin) + TriacM->PeriodCtl.Serial_Num=TriacM->PeriodCtl.Serial_Nummin; + } + data=Triac50hz_Data[TriacM->PeriodCtl.Serial_Num]; + if(TriacM->PeriodCtl.CntPeriodCtl.Period) + { + data<<=(TriacM->PeriodCtl.Cnt-1); + + if(data&0x80000000) + TRIAC_ON(); + else + TRIAC_OFF(); + } + else + { + TRIAC_ON(); + //TRIAC_OFF(); + } + } + else + { + TriacM->PeriodCtl.Cnt=TriacM->PeriodCtl.Period; + TRIAC_OFF(); + } +} + +u_int32_t Triac100hz_Data1[58]={0X80100100,0X80200802,0X81010100,0X81010402,0X84104080,0X84104104,0X84081041,0X88422081,\ + 0X21084211,0X22222211,0X11111111,0X22248891,0X88912484,0X92222248,0X89224928,0X92492492,\ + 0X92492492,0XA9292492,0XA9292492,0XAA924952,0XAA924952,0XA9294AA9,0XAA4954AA,0XAA4AAAAA,\ + 0XAA4AAAAA,0XAAAAAAAA,0XAAAAAAAA,0X66D55555,0X66D55555,0X66D6D666,0X66D6D666,0X76D6D666,\ + 0X76D6D666,0X76DB7666,0X76DB7666,0X76DB7766,0X76DB7766,0X776B7767,0X776B7767,0X776B7777,\ + 0X776B7777,0X77777777,0X77777777,0XF77BDEEE,0XF77BDEEE,0X777F7F77,0X777F7F77,0X777F7F7F,\ + 0XF77F7F7E,0XF77F7F7F,0XF7FEFEFE,0XF7FFFEFE,0XF7FFFEFE,0XF7FFFEFF,0XFFFEFFFE,0XFFFFFFFE,\ + 0XFFFFFFFE,0XFFFFFFFF}; +/* 6 ~ 13 + * 14 ~ 21 + * 22 ~ 29 + * 30 ~ 37 + * 38 ~ 45 + * 46 ~ 53 + * 54 ~ 61 + * 62 ~63 + */ +u_int32_t Triac100hz_Data2[58]={0X80100100,0X00804040,0X81010100,0X08041008,0X84104080,0X10404210,0X11041110,0X11041110,\ + 0X10884442,0X10884442,0X11111111,0X11111111,0X88912444,0X92249224,0X89224928,0X49224928,\ + 0X92492492,0X92492492,0XA9292492,0XA9292492,0XAA924952,0X29294AAA,0XAA4954AA,0XAA4954AA,\ + 0XAA4AAAAA,0XAA4AAAAA,0XAAAAAAAA,0X55555555,0X66D55555,0X66D55555,0X66D6D666,0X66D6D666,\ + 0X76D6D666,0X76D6D666,0X76DB7666,0X76DB7666,0X76DB7766,0X776B5577,0X776B7767,0X776B7767,\ + 0X776B7777,0X776B7777,0X77777777,0XF777776E,0XF77BDEEE,0X777FDEEE,0X777F7F77,0X777F7F77,\ + 0XF77F7F7E,0XF77F7F7E,0XF7FEFEFE,0XF7FEFEFE,0XF7FFFEFE,0XF7FFFEFE,0XFFFEFFFE,0XFFFEFFFE,\ + 0XFFFFFFFE,0XFFFFFFFE}; + +/****************************************************************************** +* Function Name : TriacZero50HZ_Control_Process +* Description : Thyristor Period Control Processing +* Input : Silicon-controlled rectifier control pointer Temperature gear Temperature control pointer +* Output : None +* Return : None +******************************************************************************/ +void TriacZero_100HZControl_Process(Temperature_ctl_Type *TempM,Key_Manager_Type *KeyM,TRIAC_ctl_Type *TriacM,Speedrampctr_Type *Speed_Ramp) +{ + u32 data=0; + u32 Data1; + u32 Data2; + _iq24 ACVoltcali; + if((TriacM->TonEnable==1)&&(KeyM->Tkey_rank>0)&&( TriacM->Zero.Zcrosslost == FALSE)&&(KeyM->TCkeycold==FALSE)&&\ + (TempM->NTCOverStatus==FALSE)&&(TempM->NTCOpenStatus==FALSE)&&\ + (RunningStatus_M==RUN)&&(KeyM->Skeystop==FALSE)&&(Operation_M.Faultstop == FALSE)) + { + + TriacM->PeriodCtl.Cnt++; + if(TriacM->PeriodCtl.Cnt>TriacM->PeriodCtl.Period)// + { + TriacM->PeriodCtl.Cnt=1; + if(TriacM->PeriodCtl.DutychangeFlag==TRUE) + { + Temp_Set(KeyM,&SpeedRamp_M,TriacM); + TriacM->PeriodCtl.DutychangeFlag=FALSE; + } + + //根据母线电压峰值矫正占空比 + ACVoltcali=ADC_M.DCVoltcali; + + TriacM->ACVoltcali_Square= _IQmpy(ACVoltcali, ACVoltcali); + + TriacM->PeriodCtl.Serial_Num=(u_int8_t)((TriacM->PeriodCtl.Duty_TS*TriacM->ACVoltcali_Square)>>24)-TriacM->PeriodCtl.NumData; + //TriacM->PeriodCtl.Serial_Num=(u_int8_t)(TriacM->PeriodCtl.Duty_TS-TriacM->PeriodCtl.NumData); + + if(TriacM->PeriodCtl.Serial_Num>=TriacM->PeriodCtl.Serial_Nummax) + TriacM->PeriodCtl.Serial_Num=TriacM->PeriodCtl.Serial_Nummax; + else if(TriacM->PeriodCtl.Serial_Num<=TriacM->PeriodCtl.Serial_Nummin) + TriacM->PeriodCtl.Serial_Num=TriacM->PeriodCtl.Serial_Nummin; + } + Data1=Triac100hz_Data1[TriacM->PeriodCtl.Serial_Num]; + Data2=Triac100hz_Data2[TriacM->PeriodCtl.Serial_Num]; + if(TriacM->PeriodCtl.Cnt<=TriacM->PeriodCtl.HalfPeriod) + { + data=Data1; + data<<=(TriacM->PeriodCtl.Cnt-1); + + if(data&0x80000000) + TRIAC_ON(); + else + TRIAC_OFF(); + } + else if((TriacM->PeriodCtl.Cnt>TriacM->PeriodCtl.HalfPeriod)&&(TriacM->PeriodCtl.CntPeriodCtl.Period))//Triac100hz_Data2 1~32 发波 + { + data=Data2; + data<<=(TriacM->PeriodCtl.Cnt-1-TriacM->PeriodCtl.HalfPeriod); + + if(data&0x80000000) + TRIAC_ON(); + else + TRIAC_OFF(); + } + else + { + TRIAC_OFF(); + } + } + else + { + TriacM->PeriodCtl.Cnt=TriacM->PeriodCtl.Period; + TRIAC_OFF(); + } +} + +/****************************************************************************** +* Function Name : TempInit_Measure +* Description : NTC Temperature Reading +* Input : Temperature Control Body Pointer ADC +* Output : None +* Return : None +******************************************************************************/ +void TempInit_Measure(Temperature_ctl_Type *TempM,ADC_TypeDef *ADCx) +{ + u8 i; + ADC_ClearFlag(ADCx, ADC_FLAG_JEOC); + ADC_SoftwareStartConvCmd(ADCx, ENABLE); + + for(i=0; i TempPres += ((_iq24)((u16)ADCx->RDATAR*(TempM->TempRatedADCInv))>>3); + + ADC_ClearFlag(ADCx, ADC_FLAG_JEOC); + ADC_SoftwareStartConvCmd(ADCx,ENABLE); + } +} diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M5_Waveform_Configure.c b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M5_Waveform_Configure.c new file mode 100644 index 0000000..3eab878 --- /dev/null +++ b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M5_Waveform_Configure.c @@ -0,0 +1,28 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : M5_Waveform_Configure.c + * Author : WCH + * Version : V1.0.0 + * Date : 2026/04/23 + * Description : +********************************************************************************* +* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ + +#include "M0_Control_Library.h" + +/****************************************************************************** +* Function Name : Waveform_Display +* Description : Waveform Display Variable Settings +* Input : None +* Return : None +******************************************************************************/ +void Waveform_Display (void) +{ + sendUsbData.sendDataBuf[sendUsbData.head+0] = (uint16_t)(SVPWM_Cal_M.VoltLimMark*1000); + sendUsbData.sendDataBuf[sendUsbData.head+1] = (uint16_t)(MLBG_M.Cal_Struc.Angspeed_Aver2>>10); + sendUsbData.sendDataBuf[sendUsbData.head+2] = (uint16_t)(ADC_M.DCVoltAver>>10); + sendUsbData.sendDataBuf[sendUsbData.head+3] = (uint16_t)(MStruc_M.CRef2R.cq>>10); + sendUsbData.head += MaxUsbDataLen; +} diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M6_CurrentLoop.c b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M6_CurrentLoop.c new file mode 100644 index 0000000..9b659d7 --- /dev/null +++ b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M6_CurrentLoop.c @@ -0,0 +1,114 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : M6_CurrentLoop.c + * Author : WCH + * Version : V1.0.0 + * Date : 2026/04/23 + * Description : ADC sampling result reading, current loop processing, FOC calculation, overcurrent phaseloss protection processing +********************************************************************************* +* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ + +#include "M0_Control_Library.h" + +void ADC1_2_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast"))); +extern void FOC_Cal(Motor_Sructure_Type *MStruc,SVPWM_1R_Type *SVPWM_Cal,Motor_PID_Type *Mpid,\ + ADCStruc_Type *ADCStruc,Motor_LBG_Type *MLBG,PWMCali_Type *PWMCali); + +uint8_t ADC_1Rsample_Counter_test = 0; +uint8_t Observer_countertest = 0; + +/****************************************************************************** +* Function Name : ADC1_2_IRQHandler +* Description : ADC1&2 Interrupt response function, read current conversion results +* Input : None +* Output : None +* Return : None +******************************************************************************/ +void ADC1_2_IRQHandler(void) +{ + // ADC_1Rsample_Counter_test++; + + if((ADC1->STATR & ADC_FLAG_JEOC) == ADC_FLAG_JEOC) + { + ADC_M.ADC_Result.Value1= (ADC1->IDATAR1)<<1; + ADC1->STATR = ~(uint32_t)ADC_FLAG_JEOC; + } + if((ADC2->STATR & ADC_FLAG_JEOC) == ADC_FLAG_JEOC) + { + // GPIO_SetBits(GPIOB, GPIO_Pin_8); + ADC_M.ADC_Result.Value2= (ADC2->IDATAR1)<<1; + + if(SpeedRamp_M.Break == TRUE) + SVPWM_Lowside_Effective(&SVPWM_Cal_M); + else + { + switch(RunningStatus_M) + { + case POSITION: + HFVQI_PosiSearch_Process(&HFVQI_StartStruc_M,&SVPWM_Cal_M,\ + &PWMCali_M,&ADC_M,&InjStart_M,SpeedRamp_M.Direction); + if(HFVQI_StartStruc_M.Finish == TRUE) + { + RunningStatus_M = START; + InjStart_M.Status = RAMP; + } + break; + + case START: + Injstart_Process_M(&InjStart_M,&MStruc_M,&MLBG_M); + + if (LBG_Status_M.Convergence == TRUE) + { + Controlloop_Initial(&InjStart_M, MLBG_M.Cal_Struc.Angspeed_Aver1,&MStruc_M,&Mpid_M,&SpeedRamp_M); + Time_Delay_Set(Triac_ctl.TonEnable_cntset,&Triac_ctl.TonEnable_cnt); + RunningStatus_M = RUN; + } + FOC_Cal(&MStruc_M,&SVPWM_Cal_M,&Mpid_M,&ADC_M,&MLBG_M,&PWMCali_M); + break; + + case RUN: + FOC_Cal(&MStruc_M,&SVPWM_Cal_M,&Mpid_M,&ADC_M,&MLBG_M,&PWMCali_M); + if(Triac_ctl.TonEnable==0) + { + if(Time_Delay_Elapse(Triac_ctl.TonEnable_cnt) == TRUE) + Triac_ctl.TonEnable=1; + } +#ifdef ZEROCROSSOVER_OC + AC_Zerocross_Detect_OC(&Triac_ctl); +#else + AC_Zerocross_Detect_TR(&Triac_ctl); +#endif + + break; + + default: + break; + } + + if ( ((RunningStatus_M==START)||(RunningStatus_M==RUN))&&(Powerctr_M.Poweron == TRUE) ) + { + if(Phaseloss_Verify(&(MStruc_M.C3S),&Phaseloss_M ,SVPWM_Cal_M.sector)) + Protection_SetFault(PHASELOSS_FALUT); + } + } + ADC_Trigger_Update(&PWMCali_M); + + SVPWM_Updateup(&SVPWM_Cal_M, &PWMCali_M); + + if ((RunningStatus_M==START)||(RunningStatus_M==RUN)) + { + if(Phase_Ins_OverCurrent_Verify(&(MStruc_M.C3S),&InstPhaseOC_M) == TRUE) + Protection_SetFault(MOTOR_OVER_CURR_SOFT_M); + } + + Break_Verify(&Powerctr_M,&SpeedRamp_M,&RunningStatus_M,&ADC_M); + + ADC_SoftwareStartConvCmd(ADC2, ENABLE); + ADC_SoftwareStartConvCmd(ADC1, ENABLE); + ADC2->STATR = ~(uint32_t)ADC_FLAG_JEOC; + +// GPIO_ResetBits(GPIOB, GPIO_Pin_8); + } +} diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M6_CurrentLoop.h b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M6_CurrentLoop.h new file mode 100644 index 0000000..9dc9bc3 --- /dev/null +++ b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M6_CurrentLoop.h @@ -0,0 +1,20 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : M6_CurrentLoop.h + * Author : WCH + * Version : V1.0.0 + * Date : 2026/04/23 + * Description : current loop processing +********************************************************************************* +* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ + +#ifndef __M6_CURRENTLOOP_H +#define __M6_CURRENTLOOP_H + +extern uint8_t ADC_1Rsample_Counter_test; +extern uint8_t Observer_countertest; + + +#endif diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M6_SpeedLoop.c b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M6_SpeedLoop.c new file mode 100644 index 0000000..5bfb502 --- /dev/null +++ b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M6_SpeedLoop.c @@ -0,0 +1,157 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : M6_SpeedLoop.c + * Author : WCH + * Version : V1.0.0 + * Date : 2026/04/23 + * Description : Speed loop processing, related protection treatment, power up and down control processing +********************************************************************************* +* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ + +#include "M0_Control_Library.h" + +void SysTick_Handler(void) __attribute__((interrupt("WCH-Interrupt-fast"))); +static uint8_t Speed_Sample_PID_CNT = SPEED_SAMPLE_PID_PERIOD; + +/****************************************************************************** +* Function Name : SysTick_Handler +* Description : Speed loop processing interrupt +* Input : None +* Output : None +* Return : None +******************************************************************************/ + +void SysTick_Handler(void) +{ + Speed_Sample_PID_CNT --; + + Time_Delay_Process(); + + Led_Operation(&LED_M); + + Poweroperation_Process(&SpeedRamp_M,&ADC_M,&Powerctr_M,&RunningStatus_M,&(Mpid_M.Speed),\ + MLBG_M.Cal_Struc.Angspeed_Aver2); + + NTCSample(&Tempctl_M,ADC1); + + Coldkeycheck(&Key_M); + + Tempkeycheck(&Key_M); + + ACKEY_CHECK(&Key_M); + + if(RunningStatus_M == IDLE) + PSC_Process(&Operation_M); + + if((Operation_M.PSC.Mark == FALSE)&&(Operation_M.PSC.Process ==TRUE)) + Speedkeycheck_Recover(&Key_M,&SpeedRamp_M); + + Event_1ms_Process(&Emanager_M); + + ACZerocross_Process(&Tempctl_M,&Key_M,&Triac_ctl); + + if (Speed_Sample_PID_CNT == 0 ) + { + Speed_Sample_PID_CNT = SPEED_SAMPLE_PID_PERIOD; + + Buffer_Update(&(LBG_SpeedBuffer_M[0]), &(MLBG_M.SpeedBuffPara), MLBG_M.Cal_Struc.Angspeed_Inst); + + MLBG_M.Cal_Struc.Angspeed_Aver1 = LPF_1st_Process(&(MLBG_M.Cal_Struc.SpeedLPF1st_M),\ + MLBG_M.Cal_Struc.Angspeed_Inst); + + LBG_Status_M.Reliable = Speed_Reliable_Verify(&(MLBG_M.SpeedBuffPara),&LBG_SpeedBuffer_M[0],\ + MLBG_M.Cal_Struc.Angspeed_Aver1,LBG_Status_M.VarianceThresh); + + switch(RunningStatus_M) + { + case START: + if(_IQabs(InjStart_M.RampInjSpeedTarget)<_IQ(0.2)) + LBG_Status_M.Reliable = TRUE; + + Speed_Converged_Verify1(InjStart_M.RampInjSpeedRef, &MLBG_M, &LBG_Status_M); + break; + + case RUN: + if(SpeedRamp_M.Break == FALSE) + { + if((Key_M.Skeystop == FALSE)&&(Operation_M.Faultstop == FALSE)&&(Powerctr_M.Poweron == TRUE)) + { + VDC_Limitspeed(&SpeedRamp_M,&ADC_M,&Powerctr_M); + } + if(Powerctr_M.Poweron == TRUE) + Speed_Ramp_Process(&SpeedRamp_M); + else + Poweroff_Speed_Ramp_Process(&SpeedRamp_M); + + if(STARTUP_DIRECTION==1) + SpeedRamp_M.Aftrampcom = SpeedRamp_M.Aftramp + Powercom_M.Speedcom; + else if(STARTUP_DIRECTION==-1) + SpeedRamp_M.Aftrampcom = SpeedRamp_M.Aftramp - Powercom_M.Speedcom; + + Speed_Stable_Verify(&LBG_Status_M, MLBG_M.Cal_Struc.Angspeed_Aver1); + if(LBG_Status_M.Stable==FALSE) + Protection_SetFault(SPEED_ABNORMAL_M); + + Motor_Stall_Verify1(SpeedRamp_M.Aftramp, &MLBG_M, MStruc_M.CRef2R.cq,&LBG_Status_M); + if(LBG_Status_M.Stall==TRUE) + Protection_SetFault(MOTOR_STALL_M); + + MStruc_M.CRef2R.cq = PID_Calculaion_Delta (SpeedRamp_M.Aftrampcom, MLBG_M.Cal_Struc.Angspeed_Aver2, &(Mpid_M.Speed)); + + if((DCurrProcess_M.Stage == 1)&&(_IQabs(MStruc_M.CRef2R.cd) <= DCurrProcess_M.Target1)) + Dcurr_Process_Init(&DCurrProcess_M,2); + + MStruc_M.CRef2R.cd = Dcurr_Process(&DCurrProcess_M, MLBG_M.Cal_Struc.Angspeed_Aver1, MStruc_M.CRef2R.cd); + } + break; + default: + break; + } + } + + DCOvervolt_Protection(ADC_M.DCVoltAver, &DCBusProtecion_M); + + DCUndervolt_Protection1(ADC_M.DCVoltAver, &DCBusProtecion_M,&Powerctr_M); + + NTC_Protection(&Tempctl_M,Tempctl_M.TempAver); + + SysTick->SR &= ~(1 << 0); +} + +/************************************************************************************************************ +* Function Name : Systick_Init +* Description : Systick Init +* Input : NewState - ENABLE or DISABLE. +* Output : None +* Return : None +*************************************************************************************************************/ +void Systick_Init(void) +{ + SysTick->CTLR =0; + SysTick->CMP =0; + SysTick->SR &= ~(1 << 0); + SysTick->CNT = 0; + SysTick->CMP = TIMER_PERIDO_SYSTICK; + SysTick->CTLR |=(1 << 1)|(1 << 3)|(1 << 5); +} + +/************************************************************************************************************ +* Function Name : SYS_TIM_Cmd +* Description : SysTick Enable +* Input : NewState - ENABLE or DISABLE. +* Output : None +* Return : None +*************************************************************************************************************/ +void SYS_TIM_Cmd(FunctionalState NewState) +{ + if(NewState != DISABLE) + { + SysTick->CTLR |= TIM_CEN; + } + else + { + SysTick->CTLR &= (uint16_t)(~((uint16_t)TIM_CEN)); + } +} diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M6_SpeedLoop.h b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M6_SpeedLoop.h new file mode 100644 index 0000000..ce2474a --- /dev/null +++ b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M6_SpeedLoop.h @@ -0,0 +1,32 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : M6_SpeedLoop.h + * Author : WCH + * Version : V1.0.0 + * Date : 2026/04/23 + * Description : The speed loop is defined by timer parameters and control counting parameters. +********************************************************************************* +* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ + +#ifndef __M6_SPEEDLOOP_H +#define __M6_SPEEDLOOP_H +#define TIMER_CLOCK_FREQ_SPEED 144000000uL +#define TIMER_FREQ_SPEED_LOOP 2000 + +#define TIMER_PERIDO_SYSTICK TIMER_CLOCK_FREQ_SPEED / (u32)(TIMER_FREQ_SPEED_LOOP*8) + +#define TIMER_PRESCALER_SPEED_LOOP 17 + +#define SPEED_LOOP_CAL_FREQ 2000 + +#define SPEED_LOOP_CAL_PERIOD _IQ(1.0)/SPEED_LOOP_CAL_FREQ + +#define SPEED_SAMPLE_PID_PERIOD TIMER_FREQ_SPEED_LOOP/SPEED_LOOP_CAL_FREQ +#define LED_PERIOD 4 + +//void Timer4_Init(void); +void Systick_Init(void); +void SYS_TIM_Cmd(FunctionalState NewState); +#endif diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M7_Interrupt.c b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M7_Interrupt.c new file mode 100644 index 0000000..dede9f0 --- /dev/null +++ b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M7_Interrupt.c @@ -0,0 +1,159 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : M7_Interrupt.c + * Author : WCH + * Version : V1.0.0 + * Date : 2026/04/23 + * Description : Interrupt configuration +********************************************************************************* +* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ +#include "M0_Control_Library.h" +void TIM1_UP_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast"))); +void TIM1_BRK_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast"))); +void NMI_Handler(void) __attribute__((interrupt("WCH-Interrupt-fast"))); +void HardFault_Handler(void) __attribute__((interrupt("WCH-Interrupt-fast"))); +void Observer_Calibration(Motor_Sructure_Type *MStruc,SVPWM_1R_Type *SVPWM_Cal,Motor_PID_Type *Mpid,\ + ADCStruc_Type *ADCStruc,Motor_LBG_Type *MLBG,PWMCali_Type *PWMCali); +uint8_t Timer1_Interrupt_Count_test = 0; + +/****************************************************************************** +* Function Name : Interrupt_Configuration +* Description : Interrupt Priority Configuration +* Input : None +* Output : None +* Return : None +******************************************************************************/ +void Interrupt_Configuration(void) +{ + NVIC_InitTypeDef NVIC_InitStructure; + NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); + + NVIC_InitStructure.NVIC_IRQChannel = ADC_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; + NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + + NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; + NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + + NVIC_InitStructure.NVIC_IRQChannel = TIM1_BRK_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; + NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + TIM_ClearITPendingBit(TIM1, TIM_IT_Break); + TIM_ITConfig(TIM1, TIM_IT_Break,ENABLE); + + NVIC_InitStructure.NVIC_IRQChannel = SysTicK_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; + NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); +} + +/****************************************************************************** +* Function Name : TIM1_UP_IRQHandler +* Description : Timer 1 overflow interrupt, processing waveform data output +* Input : None +* Output : None +* Return : None +******************************************************************************/ +void TIM1_UP_IRQHandler(void) +{ + + if( RunningStatus_M ==PRESTART) + { + if(Time_Delay_Elapse(SpeedRamp_M.Precharge_cnt) == TRUE) + { + ADC_1R_Start(ENABLE); + RunningStatus_M = POSITION; + } + } + + if((RunningStatus_M == POSITION)||(RunningStatus_M == START)||(RunningStatus_M == RUN)) + SVPWM_Updatedown(&SVPWM_Cal_M, &PWMCali_M); + else + { + ADC_SoftwareStartConvCmd(ADC2, ENABLE); + ADC_SoftwareStartConvCmd(ADC1, ENABLE); + } + + DCBUS_Volt_Cal(&ADC_M,ADC2); + + ADC_M.DCVoltcali= (_IQdiv(_IQ(1.0),ADC_M.DCVolt_Filter)); + + if(RunningStatus_M == RUN) + { + if ((ADC_M.DCVoltcaliADC_M.DCVoltcali)) + Triac_ctl.ACVoltcaliMin=ADC_M.DCVoltcali; + } + else + { + Triac_ctl.ACVoltcaliPrev= ADC_M.DCVoltcali; + Triac_ctl.ACVoltcaliMin=ADC_M.DCVoltcali; + } + +#ifdef PHASEANGLE_CONTROL + Triac_Control_Process(&Triac_ctl); +#endif + if(SpeedRamp_M.Break == FALSE) + { + if((RunningStatus_M == START)||(RunningStatus_M == RUN)) + { + Observer_Calibration(&MStruc_M,&SVPWM_Cal_M,&Mpid_M,&ADC_M,&MLBG_M,&PWMCali_M); + } + } + // Waveform_Display(); + //GPIO_SetBits(GPIOD, GPIO_Pin_0); + Powercom_Process(&Powercom_M,&MStruc_M,&Powerctr_M,&SpeedRamp_M); + if(RunningStatus_M == RUN) + { + Triac_ctl.ACVoltcaliPrev= ADC_M.DCVoltcali; + PeakDCOvervolt_Protection(ADC_M.DCVolt_Filter,&DCBusProtecion_M); + } + TIM_ClearFlag(TIM1, TIM_FLAG_Update); +} + +/****************************************************************************** +* Function Name : TIM1_BRK_IRQHandler +* Description : Brake interruption, set fault +* Input : None +* Output : None +* Return : None +******************************************************************************/ +void TIM1_BRK_IRQHandler(void) +{ + Protection_SetFault(DC_OVER_CURR_HARD_M); + TIM_ClearITPendingBit(TIM1, TIM_IT_Break); +} + +/******************************************************************************* +* Function Name : NMI_Handler +* Description : This function handles NMI exception. +* Input : None +* Return : None +*******************************************************************************/ +void NMI_Handler(void) +{ + +} + +/******************************************************************************* +* Function Name : HardFault_Handler +* Description : This function handles Hard Fault exception. +* Input : None +* Return : None +*******************************************************************************/ +void HardFault_Handler(void) +{ + while (1) + { + //NVIC_SystemReset(); + } +} diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M7_Interrupt.h b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M7_Interrupt.h new file mode 100644 index 0000000..a66fe32 --- /dev/null +++ b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M7_Interrupt.h @@ -0,0 +1,19 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : M7_Interrupt.h + * Author : WCH + * Version : V1.0.0 + * Date : 2026/04/23 + * Description : Interrupt configuration, waveform display +********************************************************************************* +* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ + +#ifndef __M7_INTERRUPT_H +#define __M7_INTERRUPT_H + +extern uint8_t Timer1_Interrupt_Count_test; +void Interrupt_Configuration(void);//中断整体配置 + +#endif diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M8_Protection.c b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M8_Protection.c new file mode 100644 index 0000000..251defd --- /dev/null +++ b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M8_Protection.c @@ -0,0 +1,330 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : M8_Protection.c + * Author : WCH + * Version : V1.0.0 + * Date : 2026/04/23 + * Description : Protection parameter initialization, protection state setting +********************************************************************************* +* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ + +#include "M0_Control_Library.h" + +InstPhaseOC_Type InstPhaseOC_M; +DCbusProtection_Type DCBusProtecion_M; +OverLoad_Type Overload_M; +LPF_First_Order_Type OverloadLPF1st_M; +Phaseloss_Type Phaseloss_M; + +/****************************************************************************** +* Function Name : Protection_and_Emergency_Parameter_Define +* Description : Fault protection parameter initialization +* Input : None +* Output : None +* Return : None +******************************************************************************/ +void Protection_and_Emergency_Parameter_Define (void) +{ + InstPhaseOC_M.Cnt = 0; + InstPhaseOC_M.CurrThreshold = INST_PHASEOC_THRE_M; + InstPhaseOC_M.CntThreshold = INST_PHASEOC_CNT_THRE_M; + + DCBusProtecion_M.OverThresh = DCBUS_OVER_VOLT_THRE; + DCBusProtecion_M.UnderThresh = DCBUS_UNDER_VOLT_THRE; + DCBusProtecion_M.OverCntThresh = DCBUS_OVER_VOLT_CNT; + DCBusProtecion_M.UnderCntThresh = DCBUS_UNDER_VOLT_CNT; + DCBusProtecion_M.OverCnt = 0; + DCBusProtecion_M.UnderCnt = 0; + DCBusProtecion_M.Overvolt = FALSE; + DCBusProtecion_M.Undervolt = FALSE; + DCBusProtecion_M.PeakOverCnt=0; + DCBusProtecion_M.PeakOverCntThresh=PEAKDCBUS_OVER_VOLT_CNT; + DCBusProtecion_M.PeakOverDetectiontime=(u_int16_t)(PEAKDCBUS_OVER_VOLT_DETECTIONTIME*FREQ_SVPWM); + DCBusProtecion_M.PeakOverDetectiontCnt=0; + + Overload_M.CurrThresh = OVERLOAD_CURR_THRE; + Overload_M.CalCoef = OVERLOAD_CAL_COEF; + Overload_M.CntThresh = (uint16_t)(OVERLOAD_TIME_THRE*OVERLOAD_CAL_FREQ); + Overload_M.Cnt = 0; + Overload_M.CurrCal = 0; + OverloadLPF1st_M.Input_Coef = _IQdiv(OVERLOADLPF_WcT_M,(OVERLOADLPF_WcT_M + UNIT_Q24)); + OverloadLPF1st_M.Output_Coef = _IQdiv(UNIT_Q24,(OVERLOADLPF_WcT_M + UNIT_Q24)); + + Phaseloss_M.CurrThresh = PHASELOSS_CURR_THRE; + Phaseloss_M.CntThresh = (uint16_t)(PHASELOSS_TIME_THRE * PHASELOSS_CAL_FREQ); + Phaseloss_M.MultiphaseCnt = 0; + Phaseloss_M.SiglephaseCntA = 0; + Phaseloss_M.SiglephaseCntB = 0; + Phaseloss_M.SiglephaseCntC = 0; + Phaseloss_M.CurrBuffPara.Length = PHASELOSS_CAL_BUFFSIZE; + Phaseloss_M.CurrBuffPara.Inv1 = _IQ(1.0)/PHASELOSS_CAL_BUFFSIZE; + Phaseloss_M.CurrBuffPara.Inv2 = _IQ(1.0) - Phaseloss_M.CurrBuffPara.Inv1; + + Tempctl_M.NTCOverThresh = NTC_OVERTEMP_RATEADC; + Tempctl_M.NTCOpenThresh = NTC_OPENTEMP_RATEADC; + Tempctl_M.NTCOverCntThresh = (uint16_t)(TEMP_OVER_TIME*NTC_VERIFY_FREQ); + Tempctl_M.NTCOpenCntThresh = (uint16_t)(NTC_OPEN_TIME*NTC_VERIFY_FREQ); + Tempctl_M.NTCOverCnt = 0; + Tempctl_M.NTCOpenCnt = 0; + Tempctl_M.NTCOpenStatus =FALSE; + Tempctl_M.NTCOverStatus =FALSE; + +} + +/****************************************************************************** +* Function Name : Protection_and_Emergency_Init +* Description : Fault protection parameter initialization +* Input : None +* Output : None +* Return : None +******************************************************************************/ +void Protection_and_Emergency_Init () +{ + InstPhaseOC_M.Cnt = 0; + + DCBusProtecion_M.OverCnt = 0; + DCBusProtecion_M.UnderCnt = 0; + + DCBusProtecion_M.Overvolt = FALSE; + DCBusProtecion_M.Undervolt = FALSE; + DCBusProtecion_M.PeakOverDetectiontCnt=0; + DCBusProtecion_M.PeakOverCnt=0; + Overload_M.Cnt = 0; + Overload_M.CurrCal = 0; + + Phaseloss_M.MultiphaseCnt = 0; + Phaseloss_M.SiglephaseCntA = 0; + Phaseloss_M.SiglephaseCntB = 0; + Phaseloss_M.SiglephaseCntC = 0; + +// Tempctl_M.NTCOverCnt = 0; +// Tempctl_M.NTCOpenCnt = 0; + // Tempctl_M.NTCOverHysteresisCnt = 0; + // Tempctl_M.NTCOverRecoverCnt = 0; + // Tempctl_M.NTCOpenStatus =FALSE; + // Tempctl_M.NTCOverStatus =FALSE; + // Tempctl_M.NTCOverHysStatus =FALSE; + Tempctl_M.NTCFlickerStatus =FALSE; +} + +/****************************************************************************** +* Function Name : Protection_SetFault +* Description : Fault Setting +* Input : Fault type +* Output : None +* Return : None +******************************************************************************/ +void Protection_SetFault(uint16_t Fault_type) +{ + Time_Delay_Set(Operation_M.FaultHoldingSet,&(Operation_M.FaultHoldingCnt)); + + TIM_CtrlPWMOutputs(TIM1, DISABLE); + + TRIAC_OFF(); + + RunningStatus_M = FAULT; + + System_Status_Global |= Fault_type; +} + +/****************************************************************************** +* Function Name : Protction_Fault_Reset_M +* Description : Fault Reset +* Input : None +* Output : None +* Return : None +******************************************************************************/ +void Protction_Fault_Reset_M(void) +{ + if (Time_Delay_Elapse(Operation_M.FaultHoldingCnt)) + { + System_Status_Global &= ~STARTUP_FAILURE_M; + + System_Status_Global &= ~SPEED_ABNORMAL_M; + LBG_Status_M.Unstable_CNT = 0; + + System_Status_Global &= ~MOTOR_OVER_CURR_SOFT_M; + InstPhaseOC_M.Cnt = 0; + + System_Status_Global &= ~MOTOR_OVERLOAD_M; + Overload_M.Cnt = 0; + + if (GPIO_ReadInputDataBit(BRK_GPIO_M, BRK_PIN_M)) + System_Status_Global &= ~DC_OVER_CURR_HARD_M; + + System_Status_Global &= ~MOTOR_STALL_M; + LBG_Status_M.Stall_CNT = 0; + + System_Status_Global &= ~PHASELOSS_FALUT; + LBG_Status_M.Stall_CNT = 0; + + System_Status_Global &= ~NTC_OVER_ERR; + Tempctl_M.NTCOverCnt =0; + Tempctl_M.NTCOverStatus =FALSE; + + System_Status_Global &= ~NTC_OPEN_ERR; + Tempctl_M.NTCOpenCnt =0; + Tempctl_M.NTCOpenStatus =FALSE; + + if((System_Status_Global&DC_OVER_VOLT)==DC_OVER_VOLT) + { + if(ADC_M.DCVolt_Filter < DCBusProtecion_M.OverThresh) + { + System_Status_Global&= ~DC_OVER_VOLT; + DCBusProtecion_M.OverCnt = 0; + } + } + if((System_Status_Global&DC_OVER_VOLT)==DC_UNDER_VOLT) + { + if(ADC_M.DCVolt_Filter > DCBusProtecion_M.UnderThresh) + { + System_Status_Global&= ~DC_UNDER_VOLT; + DCBusProtecion_M.UnderCnt = 0; + } + } + } + + if ( (System_Status_Global & (STARTUP_FAILURE_M |SPEED_ABNORMAL_M | MOTOR_OVER_CURR_SOFT_M | MOTOR_OVERLOAD_M\ + | DC_OVER_CURR_HARD_M | MOTOR_STALL_M |PHASELOSS_FALUT|NTC_OVER_ERR|NTC_OPEN_ERR| DC_OVER_VOLT | DC_UNDER_VOLT)) == 0 ) + { + RunningStatus_M = IDLE; + System_Status_Global |= FIRST_START_M; + } +} + +/****************************************************************************** +* Function Name : DCOvervolt_Protection +* Description : Bus Overvoltage Protection +* Input : Detect bus voltage, voltage protection structure pointer +* Output : None +* Return : None +******************************************************************************/ +void DCOvervolt_Protection(_iq24 DCVolt, DCbusProtection_Type *DCbusProtec) +{ + if (DCVolt >= DCbusProtec->OverThresh) + DCbusProtec->OverCnt++; + else + DCbusProtec->OverCnt = 0; + + if(DCbusProtec->OverCnt > DCbusProtec->OverCntThresh) + { + DCBusProtecion_M.Overvolt = TRUE; + Protection_SetFault(DC_OVER_VOLT);//母线过压 + + } +} + +/****************************************************************************** +* Function Name : PeakDCOvervolt_Protection +* Description : Peak bus overvoltage protection +* Input : Detect bus voltage, voltage protection structure pointer +* Output : None +* Return : None +******************************************************************************/ +void PeakDCOvervolt_Protection(_iq24 DCVolt, DCbusProtection_Type *DCbusProtec) +{ + DCbusProtec->PeakOverDetectiontCnt++; + if(DCbusProtec->PeakOverDetectiontCntPeakOverDetectiontime) + { + if (DCVolt >= DCbusProtec->OverThresh) + DCbusProtec->PeakOverCnt++; + + + if(DCbusProtec->PeakOverCnt > DCbusProtec->PeakOverCntThresh) + { + DCBusProtecion_M.Overvolt = TRUE; + Protection_SetFault(DC_OVER_VOLT); + } + } + else + { + DCbusProtec->PeakOverCnt=0; + DCbusProtec->PeakOverDetectiontCnt=0; + } +} + +/****************************************************************************** +* Function Name : DCUndervolt_Protection +* Description : Bus Undervoltage Protection +* Input : Detect bus voltage, voltage protection structure pointerv +* Output : None +* Return : None +******************************************************************************/ +void DCUndervolt_Protection(_iq24 DCVolt, DCbusProtection_Type *DCbusProtec) +{ + if (DCVolt <= DCbusProtec->UnderThresh) + DCbusProtec->UnderCnt++; + else + DCbusProtec->UnderCnt = 0; + + if(DCbusProtec->UnderCnt > DCbusProtec->UnderCntThresh) + { + DCBusProtecion_M.Undervolt = TRUE; + Protection_SetFault(DC_UNDER_VOLT); + } +} + +/****************************************************************************** +* Function Name : DCUndervolt_Protection +* Description : Bus Undervoltage Protection +* Input : Detect bus voltage, voltage protection structure pointer +* Output : None +* Return : None +******************************************************************************/ +void DCUndervolt_Protection1(_iq24 DCVolt, DCbusProtection_Type *DCbusProtec,Powercontrol_Type *PowerOper) +{ + if (((DCVolt <= DCbusProtec->UnderThresh)||(PowerOper->Poweron==FALSE))&&(Key_M.ACkey_Poweron == TRUE)) + { + if(DCbusProtec->UnderCntUnderCnt++; + } + else + DCbusProtec->UnderCnt = 0; + + if(DCbusProtec->UnderCnt > DCbusProtec->UnderCntThresh) + { + Protection_SetFault(DC_UNDER_VOLT); + DCBusProtecion_M.Undervolt = TRUE; + } +} + +/****************************************************************************** +* Function Name : NTC_Protection +* Description : NTC Protection +* Input : Temperature control structure pointer +* Output : None +* Return : None +******************************************************************************/ +void NTC_Protection(Temperature_ctl_Type *Temctl,_iq24 Temp) +{ + if(Temp < Temctl->NTCOverThresh) + { + if(Temctl->NTCOverCnt<=U16_MAX) + Temctl->NTCOverCnt ++; + } + else + Temctl->NTCOverCnt =0; + + + if(Temctl->NTCOverCnt >= Temctl-> NTCOverCntThresh) + { + Temctl->NTCOverStatus = TRUE; + Protection_SetFault(NTC_OVER_ERR); + } + + if(Temp > Temctl->NTCOpenThresh) + { + if(Temctl->NTCOpenCnt<=U16_MAX) + Temctl->NTCOpenCnt ++; + } + else + Temctl->NTCOpenCnt =0; + + if(Temctl->NTCOpenCnt >= Temctl-> NTCOpenCntThresh) + { + Temctl->NTCOpenStatus = TRUE; + Protection_SetFault(NTC_OPEN_ERR); + } +} diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M8_Protection.h b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M8_Protection.h new file mode 100644 index 0000000..9cf7a0b --- /dev/null +++ b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M8_Protection.h @@ -0,0 +1,95 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : M8_Protection.h + * Author : WCH + * Version : V1.0.0 + * Date : 2026/04/23 + * Description : Protection parameter definition +********************************************************************************* +* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ +#ifndef __M8_PROTECTION_H +#define __M8_PROTECTION_H +#define INST_PHASEOC_THRE_M _IQ(1.3) +#define INST_PHASEOC_CNT_THRE_M (uint16_t)5 + +#define DCBUS_OVER_VOLT_THRE _IQ(1.175) +#define DCBUS_UNDER_VOLT_THRE _IQ(0.72) +#define DCBUS_OVER_VOLT_CNT (uint16_t)500 +#define DCBUS_UNDER_VOLT_CNT (uint16_t)3000 + +#define PEAKDCBUS_OVER_VOLT_CNT (uint16_t)1500 +#define PEAKDCBUS_OVER_VOLT_DETECTIONTIME 0.3 + +#define NTC_OVERHYSTERESIS_TEMP_TIME 5 + +#define NTC_OVERTEMP_OHM _IQ18(0.8844) +#define NTC_OVERTEMP_RATEADC _IQ18toIQ(_IQ18div(NTC_OVERTEMP_OHM , NTC_OVERTEMP_OHM + PT_RS)) + +#define NTC_OPENTEMP_OHM _IQ18(981.5699) +#define NTC_OPENTEMP_RATEADC _IQ18toIQ(_IQ18div(NTC_OPENTEMP_OHM , NTC_OPENTEMP_OHM + PT_RS)) + +#define NTC_VERIFY_FREQ TIMER_FREQ_SPEED_LOOP + +#define TEMP_OVER_TIME 0.1 +#define NTC_OPEN_TIME 0.1 + +#define OVERLOAD_CURR_THRE _IQ(1.1) +#define OVERLOAD_TIME_THRE 0.5 +#define OVERLOAD_CAL_FREQ TIMER_FREQ_SPEED_LOOP +#define OVERLOAD_CAL_COEF _IQ(1/1.91) +#define OVERLOADLPF_CF_M 500 +#define OVERLOADLPF_WcT_M (PI_2_Q24/OVERLOAD_CAL_FREQ)*OVERLOADLPF_CF_M + +#define PHASELOSS_CURR_THRE _IQ(0.1) +#define PHASELOSS_TIME_THRE 0.1 +#define PHASELOSS_CAL_FREQ FREQ_SVPWM +#define PHASELOSS_CAL_BUFFSIZE 32 +#define PHASELOSS_CNT_THRE 3 + +/* Exported variables -------------------------------------------------------*/ +extern InstPhaseOC_Type InstPhaseOC_M; +extern DCbusProtection_Type DCBusProtecion_M; +extern OverLoad_Type Overload_M; +extern LPF_First_Order_Type OverloadLPF1st_M; +extern Phaseloss_Type Phaseloss_M; + +/* Exported macro -----------------------------------------------------------*/ +/* Exported functions -------------------------------------------------------*/ +void Protection_and_Emergency_Parameter_Define (void); + +void Protection_and_Emergency_Init (void); + +void Protection_SetFault(uint16_t Fault_type); + +void Protction_Fault_Reset_M(void); + +Truth_Verify_Type Phase_Ins_OverCurrent_Verify (Component_3S_Type *PhaseABC, InstPhaseOC_Type * InstOC); + +void DCOvervolt_Protection(_iq24 DCVolt, DCbusProtection_Type *DCbusProtec); + +void DCUndervolt_Protection(_iq24 DCVolt, DCbusProtection_Type *DCbusProtec); +void DCUndervolt_Protection1(_iq24 DCVolt, DCbusProtection_Type *DCbusProtec,Powercontrol_Type *PowerOper); +void Speed_Outrange_Verify(_iq24 Speedref, _iq24 Speedact, Observer_Status_Type *Status); + +Truth_Verify_Type Speed_Reliable_Verify(BuffPara_Type *Buffpara,_iq24 *Buffer,_iq24 Averspeed,_iq24 Threshold); + +void Speed_Stable_Verify(Observer_Status_Type *Status,_iq24 Speedact); + +void Motor_Stall_Verify1(_iq24 Speedref, Motor_LBG_Type *MLBG,_iq24 Iqref, Observer_Status_Type *Status); +void Motor_Stall_Verify2(_iq24 Speedref, _iq24 Speedact , _iq24 Iqref, Observer_Status_Type *Status); + +void Motor_Reverse_Verify(_iq24 Speedref, _iq24 Speedact, Observer_Status_Type *Status); + +void Speed_Converged_Verify1(_iq24 Speedref,Motor_LBG_Type *MLBG,Observer_Status_Type *Status); +void Speed_Converged_Verify2(_iq24 Speedref,_iq24 Speedact,Observer_Status_Type *Status); + +Truth_Verify_Type OverLoad_Verify (Component_3S_Type *PhaseABC, OverLoad_Type * Overload, LPF_First_Order_Type * LPF); + +Truth_Verify_Type Phaseloss_Verify (Component_3S_Type *PhaseABC,Phaseloss_Type *Phaseloss, uint8_t PWMsector); + +void NTC_Protection(Temperature_ctl_Type *Temctl,_iq24 Temp); + +void PeakDCOvervolt_Protection(_iq24 DCVolt, DCbusProtection_Type *DCbusProtec); +#endif diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M9_Appication_Blocks.h b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M9_Appication_Blocks.h new file mode 100644 index 0000000..da535d1 --- /dev/null +++ b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M9_Appication_Blocks.h @@ -0,0 +1,110 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : M9_Appication_Blocks.h + * Author : WCH + * Version : V1.0.0 + * Date : 2026/04/23 + * Description : Standard application module declaration +********************************************************************************* +* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __M9_APPLICATION_BLOCKS_H +#define __M9_APPLICATION_BLOCKS_H +#define POWERCOM_FREQ_M FREQ_SVPWM +#define POWERCOM_PERIOD_M _IQ(1.0)/FREQ_SVPWM + +#define POWERCOM_HPF1st_CF_M 10 +#define POWERCOM_HPF1st_WcT_M _IQmpy(_IQmpyI32(POWERCOM_PERIOD_M,POWERCOM_HPF1st_CF_M),PI_2_Q24) +#define POWERCOM_LPF1st_CF_M 1000 +#define POWERCOM_LPF1st_WcT_M _IQmpy(_IQmpyI32(POWERCOM_PERIOD_M,POWERCOM_LPF1st_CF_M),PI_2_Q24) + +#define POWERCOM_STARTTIME_M 0.5 +#define POWERCOM_SPEEDCLOSETIME_M 0.1 +#define POWERCOM_SPEEDERRTHRE_M _IQ(0.01) +#define POWERCOM_VOLT_THRESHOLD_M _IQ(0.75) + +#define POWERCOM_KP _IQ(0.5) +#define POWERCOM_KIT _IQ(0.0)//0.000001 +#define POWERCOM_KD _IQ(0.0) +#define POWERCOM_KPADJ1_M _IQ(1.0) +#define POWERCOM_KPADJ2_M _IQ(1.0) +#define POWERCOM_KPADJ3_M _IQ(1.0) +#define POWERCOM_ULIM_M _IQ(0.012) +#define POWERCOM_LLIM_M _IQ(-0.012) +#define POWERCOM_DLIM_M _IQ(0.01) + +/* Exported variables -------------------------------------------------------*/ +extern Powercom_type Powercom_M; + +/* Exported macro -----------------------------------------------------------*/ +/* Exported functions--------------------------------------------------------*/ +//PID计算 +_iq24 PID_Calculaion_Delta(_iq24 hReference, _iq24 hFeedback, PID_Structure_Type *PID_Struct); +_iq24 PID_Calculaion_Abs(_iq24 hReference, _iq24 hFeedback, PID_Structure_Type *PID_Struct); + +Struct_Cossin_Type TrigonoMetric_Function(_iq24 Angle_PU); + +Component_2S_Type Clark_TransForm(Component_3S_Type *Input3s); + +Component_2R_Type Park_TransForm(Component_2S_Type *Input2s,Struct_Cossin_Type *Struct_Cossin); + +Component_2S_Type Rev_Park_TransForm(Component_2R_Type *Input2r,Struct_Cossin_Type *Struct_Cossin); + +Component_2R_Type ComponentLimit_2Ror2S(Component_2R_Type *Input,_iq24 Maxsquare,uint8_t *LimMark, _iq24 *Magtable); + +_iq24 Round_Circle_Limitation_Rad(_iq24 Input); + +_iq24 Round_Circle_Limitation_PU(_iq24 Input); + +_iq24 LPF_1st_Process(LPF_First_Order_Type *LPF_1st, _iq24 input); + +_iq24 BPF_2nd_Process(BPF_Second_Order_Type *BPF_2nd,_iq24 input); + +_iq24 LPF_2nd_Process(LPF_Second_Order_Type *LPF_2nd, _iq24 input); + +_iq24 HPF_1st_Process(HPF_First_Order_Type *HPF_1st, _iq24 input); + +_iq24 HPF_2nd_Process(HPF_Second_Order_Type *HPF_2nd,_iq24 input); + +void Observer_Adaptor_Process(Observer_Adaptor_type *Adaptor,_iq24 Alpha,_iq24 Beta,_iq24 Angspeed); + +_iq24 Speedband_Avoid(_iq24 Speedinput,_iq24 Band,_iq24 Bandwidth); + +void Dcurr_Process_Init(DCurrProcess_Type * DCurrProcess,uint8_t Stage); + +_iq24 Dcurr_Process(DCurrProcess_Type * DCurrProcess, _iq24 Speedact,_iq24 DCurrRefact); + +void Speed_Ramp_Process(Speedrampctr_Type *Speed_Ramp); + +void Poweroff_Speed_Ramp_Process(Speedrampctr_Type *Speed_Ramp); + +_iq24 AverValue_Cal(_iq24 Input,_iq24 Output, BuffPara_Type *Buffpara); + +void Buffer_Clear(_iq24 *Buffer, BuffPara_Type *BuffPara); + +void Buffer_Update(_iq24 *Buffer, BuffPara_Type *BuffPara,_iq24 Updatevalue); + +void Buffer_Set(_iq24 *Buffer, BuffPara_Type *BuffPara,_iq24 Setvalue); + +_iq24 Speed_PLL_Cal(Speed_PLL_Type *SpeedPLL, _iq24 Theta_Err); + +void IF_Vibration_Com(Component_2R_Type *Volt, Component_2R_Type *Curr, InjStart_Type *InjStart); + +_iq24 IQ24divider(_iq24 dividendin, _iq24 divisorin); + +void Saturation(_iq24 *input,_iq24 Upper,_iq24 Lower); + +void VDC_Limitspeed(Speedrampctr_Type *Speed_Ramp,ADCStruc_Type *ADCStruc,Powercontrol_Type *PowerOper); + +void Break_Verify(Powercontrol_Type *PowerOper,Speedrampctr_Type *Speed_Ramp,\ + Runningstatus_Type *Runningstatus,ADCStruc_Type *ADCStruc); + +void Powercom_Prameter_Define(Powercom_type *Powercom); + +void Powercom_Status_Init(Powercom_type *Powercom); + +void Powercom_Process(Powercom_type *Powercom,Motor_Sructure_Type *MStruc,Powercontrol_Type *PowerOper,Speedrampctr_Type *Speed_Ramp); + +#endif diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M9_Appication_Initl.c b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M9_Appication_Initl.c new file mode 100644 index 0000000..fc588b5 --- /dev/null +++ b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/M9_Appication_Initl.c @@ -0,0 +1,87 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : M9_Appication_Initl.c + * Author : WCH + * Version : V1.0.0 + * Date : 2026/04/23 + * Description : +********************************************************************************* +* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ + +#include "M0_Control_Library.h" + +Powercom_type Powercom_M; + +/******************************************************************************* +* Function Name : Powercom_Prameter_Define +* Description : Power Compensation Parameter Definition +* Input : Power Fluctuation Suppression Structure +* Output : None +* Return : None +*******************************************************************************/ +void Powercom_Prameter_Define(Powercom_type *Powercom) +{ + Powercom->Power_HPF1st.Input_Coef = _IQdiv(UNIT_Q24,(POWERCOM_HPF1st_WcT_M+UNIT_Q24)); + Powercom->Power_HPF1st.Output_Coef = _IQdiv(UNIT_Q24,(POWERCOM_HPF1st_WcT_M+UNIT_Q24)); + + Powercom->Power_LPF1st.Input_Coef = _IQdiv(POWERCOM_LPF1st_WcT_M,(POWERCOM_LPF1st_WcT_M+UNIT_Q24)); + Powercom->Power_LPF1st.Output_Coef = _IQdiv(UNIT_Q24,(POWERCOM_LPF1st_WcT_M+UNIT_Q24)); + + Powercom->Kpdefine = POWERCOM_KP; + Powercom->Kidefine = POWERCOM_KIT; + Powercom->Kddefine = POWERCOM_KD; + Powercom->Kpadj1 = POWERCOM_KPADJ1_M; + Powercom->Kpadj2 = POWERCOM_KPADJ2_M; + Powercom->Kpadj3 = POWERCOM_KPADJ3_M; + Powercom->Kpadj = Powercom->Kpadj1; + + Powercom->PowerPID.Kp = _IQMPY_MACRO(Powercom->Kpdefine,Powercom->Kpadj); + Powercom->PowerPID.Ki = Powercom->Kidefine; + Powercom->PowerPID.Kd = Powercom->Kddefine; + Powercom->PowerPID.Upper_Lim = POWERCOM_ULIM_M; + Powercom->PowerPID.Lower_Lim = POWERCOM_LLIM_M; + Powercom->PowerPID.Deltalim = POWERCOM_DLIM_M; + + Powercom->Startcom_cntset = POWERCOM_FREQ_M*POWERCOM_STARTTIME_M; + Powercom->Speedcolse_cntset = POWERCOM_FREQ_M*POWERCOM_SPEEDCLOSETIME_M; + Powercom->Speederrthre = POWERCOM_SPEEDERRTHRE_M; + Powercom->Voltthre = POWERCOM_VOLT_THRESHOLD_M; +} + +/******************************************************************************* +* Function Name : Powercom_Status_Init +* Description : Power Compensation Parameter Initialization +* Input : Power Fluctuation Suppression Structure +* Output : None +* Return : None +*******************************************************************************/ +void Powercom_Status_Init(Powercom_type *Powercom) +{ + Powercom->Power_HPF1st.In_Pre = 0; + Powercom->Power_HPF1st.Out_Pre = 0; + Powercom->Power_HPF1st.Out_New = 0; + + Powercom->Power_LPF1st.Out_Pre = 0; + Powercom->Power_LPF1st.Out_New = 0; + + Powercom->PowerPID.Err_New = 0; + Powercom->PowerPID.Err_Prev1 = 0; + Powercom->PowerPID.Err_Prev2 = 0; + Powercom->PowerPID.Differential = 0; + Powercom->PowerPID.Deltaoutput = 0; + Powercom->PowerPID.Output_New = 0; + Powercom->PowerPID.Output_Prev = 0; + Powercom->PowerPID.Difference = 0; + + Powercom->Speedcom =0; + + Powercom->Power = _IQ(0.0); + Powercom->PowerfilterH = _IQ(0.0); + Powercom->PowerfilterL = _IQ(0.0); + + Powercom->Startcom_cnt=0; + Powercom->Speedclose_cnt = 0; +} + diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/MA_HFVQI_Init.c b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/MA_HFVQI_Init.c new file mode 100644 index 0000000..b621075 --- /dev/null +++ b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/MA_HFVQI_Init.c @@ -0,0 +1,103 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : MA_HFVQI_Init.c + * Author : WCH + * Version : V1.0.0 + * Date : 2026/04/23 + * Description : +********************************************************************************* +* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ + +#include "M0_Control_Library.h" +HFVQI_Start_Type HFVQI_StartStruc_M; +BuffPara_Type HFVQIPosi_CBuffPara_M; +_iq24 HFVQIPosi_CBuff_M[HFVQI_POSI_SECTOR_M]; +uint8_t HFVQI_Sectorbuf_M[HFVQI_SECTORBUFF]; + +/******************************************************************************/ +/* Function Name : HFVQI_Parameter_Define +/* Description : HFVQI Parameter define +/* Input: None +/* Output : None +/* Return : None +/******************************************************************************/ +void HFVQI_Parameter_Define (HFVQI_Start_Type *HFVQI_Start,SVPWM_1R_Type *SVPWM_Cal,PWMCali_Type *PWMCali) +{ + HFVQI_Start->Vmag = HFVQI_POSI_VMAG_M; + + HFVQI_Start->Vmagmax = _IQ16((SVPWM_Cal->HALF_T - PWMCali->ADCTimeMin -2)/2); + HFVQI_Start->Vmagmax = _IQ16div(HFVQI_Start->Vmagmax,SVPWM_Cal->coef2) <<8; + HFVQI_Start->Vmagmin = _IQ16div(_IQ16(PWMCali->ADCTimeMin + 2) , SVPWM_Cal->coef2) <<8; + + HFVQI_Start->TimeStep = HFVQI_POSI_STEP_M; + HFVQI_Start->TimeEffect = HFVQI_POSI_PULSE_EFFECTIVE_M; + HFVQI_Start->AngleInit = _IQ(-1.0)/12; + HFVQI_Start->AngleStep = _IQ(1.0)/HFVQI_POSI_SECTOR_M; + HFVQI_Start->SectorSet = HFVQI_POSI_SECTOR_M; + HFVQI_Start->Posi_Cali = _IQ(1.0)/(HFVQI_POSI_SECTOR_M*2); + + HFVQIPosi_CBuffPara_M.Length = HFVQI_POSI_SECTOR_M; + HFVQI_Start->Sectorbuff = HFVQI_SECTORBUFF; + HFVQI_Start->Cyclemax = HFVQI_CYCLE_MAX; + + HFVQI_Start->Phaseloss_Currthre = PHASELOSS_CURR_THRE; + HFVQI_Start->Phaseloss_Cntthre = PHASELOSS_CNT_THRE; +} + +/*******************************************************************************/ +/* Function Name : HFVQI_PosiSearch_Status_Init_M +/* Description : HFVQI initial positioning state initialization +/* Input: None +/* Output : None +/* Return : None +/******************************************************************************/ +void HFVQI_Status_Init_M (HFVQI_Start_Type *HFVQI_Start) +{ + HFVQI_Start->Vpolar = _IQ(0.0); + HFVQI_Start->Counter = 0; + HFVQI_Start->Position = 0; + HFVQI_Start->SectorAct = 0; + HFVQI_Start->CurrMax = 0; + HFVQI_Start->SectorMax = 0; + HFVQI_Start->Finish = FALSE; + HFVQI_Start->AngleInit = _IQ(-1.0)/12;//固定-30°开始 + + HFVQI_Start->Curr3S.PhaseA = 0; + HFVQI_Start->Curr3S.PhaseB = 0; + HFVQI_Start->Curr3S.PhaseC = 0; + HFVQI_Start->Curr2S.Alpha = 0; + HFVQI_Start->Curr2S.Beta = 0; + HFVQI_Start->Curr2R.cd = 0; + HFVQI_Start->Curr2R.cq = 0; + HFVQI_Start->VoltRef2R.cd = 0; + HFVQI_Start->VoltRef2R.cq = 0; + HFVQI_Start->VoltRef2RC.cd = 0; + HFVQI_Start->VoltRef2RC.cq = 0; + HFVQI_Start->VoltRef2SC.Alpha = 0; + HFVQI_Start->VoltRef2SC.Beta = 0; + + HFVQI_Start->Verifytime =0; + HFVQI_Start->Cycletime =0; + + HFVQI_Buffer_Clear(); + + HFVQI_Start->Phaseloss_Cnt = 0; +} + +/*******************************************************************************/ +/* Function Name : HFVQI_Buffer_Clear +/* Description : HFVQI Initial Positioning Sector Array Initialization +/* Input: None +/* Output : None +/* Return : None +/******************************************************************************/ +void HFVQI_Buffer_Clear(void) +{ + u_int8_t i; + for(i=0; i < HFVQI_SECTORBUFF; i++) + { + HFVQI_Sectorbuf_M[i]=0; + } +} diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/MA_HFVQI_Parameter.h b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/MA_HFVQI_Parameter.h new file mode 100644 index 0000000..f989928 --- /dev/null +++ b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/MA_HFVQI_Parameter.h @@ -0,0 +1,50 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : MA_HFVQI_Parameter.h + * Author : WCH + * Version : V1.0.0 + * Date : 2026/04/23 + * Description : +********************************************************************************* +* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ + +#ifndef _MA_HFVQI_OBSERVER_H +#define _MA_HFVQI_OBSERVER_H + +#define HFVQI_POSI_VMAG_M _IQ(0.25) + +#if defined TWELVE_SECTOR_POSITION +#define HFVQI_POSI_SECTOR_M 12 +#endif + +#if defined SIX_SECTOR_POSITION +#define HFVQI_POSI_SECTOR_M 6 +#endif + +#define HFVQI_POSI_STEP_M 10 +#define HFVQI_POSI_PULSE_EFFECTIVE_M 3 +#define HFVQI_SECTORBUFF 2 +#define HFVQI_CYCLE_MAX 2 + +/* Exported variables -------------------------------------------------------*/ +extern HFVQI_Start_Type HFVQI_StartStruc_M; +extern BuffPara_Type HFVQIPosi_CBuffPara_M; +extern _iq24 HFVQIPosi_CBuff_M[]; +extern uint8_t HFVQI_Sectorbuf_M[]; + +//HFVQI Init +void HFVQI_Parameter_Define (HFVQI_Start_Type *HFVQI_Start,SVPWM_1R_Type *SVPWM_Cal,PWMCali_Type *PWMCali); + +//HFVQI Init +void HFVQI_Status_Init_M (HFVQI_Start_Type *HFVQI_Start); + +//HFVQI Init +void HFVQI_Buffer_Clear(void); + +//HFVQI Init +void HFVQI_PosiSearch_Process(HFVQI_Start_Type *HFVQI_Start,SVPWM_1R_Type *SVPWM_Cal,\ + PWMCali_Type *PWMCali,ADCStruc_Type *ADCStruc,InjStart_Type *Injstart, int8_t Direction); + +#endif diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/MB_Operation_Flash.c b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/MB_Operation_Flash.c new file mode 100644 index 0000000..9056998 --- /dev/null +++ b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/MB_Operation_Flash.c @@ -0,0 +1,175 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : MB_Operation_Flash.c + * Author : WCH + * Version : V1.0.0 + * Date : 2026/04/23 + * Description : +********************************************************************************* +* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ + +#include "M0_Control_Library.h" +Flash_Operation_Type Flash_M; + +/****************************************************************************** +* Function Name : SysclkFreq_Change144_48 +* Description : Switch system from 144M to 48M +* Input : None +* Output : None +* Return : None +******************************************************************************/ +void SysclkFreq_Change144_48(void) +{ + RCC->CFGR0&=~(0x3<<0); + + RCC->CFGR0&=~(0x3<<2); + RCC->CFGR0|=(RCC_SW_HSI); + + RCC->CTLR &=~ RCC_PLLON; + EXTEN->EXTEN_CTR |= EXTEN_PLL_HSI_PRE; + + /* HCLK = SYSCLK */ + RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1; + /* PCLK2 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1; + /* PCLK1 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2; + + /* PLL configuration: PLLCLK = HSI * 6 = 48 MHz */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | RCC_PLLMULL)); + + RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSI_Div2 | RCC_PLLMULL6); + + /* Enable PLL */ + RCC->CTLR |= RCC_PLLON; + /* Wait till PLL is ready */ + while((RCC->CTLR & RCC_PLLRDY) == 0) + { + } + /* Select PLL as system clock source */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW)); + RCC->CFGR0 |= (uint32_t)RCC_SW_PLL; + /* Wait till PLL is used as system clock source */ + while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08) + { + } +} + +/****************************************************************************** +* Function Name : SysclkFreq_Change144_48 +* Description : Switch system from 48M to 144M +* Input : None +* Output : None +* Return : None +******************************************************************************/ +void SysclkFreq_Change48_144(void) +{ + + RCC->CFGR0&=~(0x3<<0); + + RCC->CFGR0&=~(0x3<<2); + RCC->CFGR0|=(RCC_SW_HSI); + + RCC->CTLR &=~ RCC_PLLON; + EXTEN->EXTEN_CTR |= EXTEN_PLL_HSI_PRE; + + /* HCLK = SYSCLK */ + RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1; + /* PCLK2 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1; + /* PCLK1 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2; + + /* PLL configuration: PLLCLK = HSI * 18 = 144 MHz */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | RCC_PLLMULL)); + + RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSI_Div2 | RCC_PLLMULL18); + + /* Enable PLL */ + RCC->CTLR |= RCC_PLLON; + /* Wait till PLL is ready */ + while((RCC->CTLR & RCC_PLLRDY) == 0) + { + } + /* Select PLL as system clock source */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW)); + RCC->CFGR0 |= (uint32_t)RCC_SW_PLL; + /* Wait till PLL is used as system clock source */ + while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08) + { + } +} + +/****************************************************************************** +* Function Name : Flash_Operation_Init +* Description : Flash Init , Read the Flash value of the 4K Flash after erasing 64K +* Input : operate Flash struct point +* Output : None +* Return : None +******************************************************************************/ +void Flash_Operation_Init(Flash_Operation_Type *FlashM) +{ + uint32_t Address = 0x0; + + FlashM->MemAddress=PAGE_WRITE_START_ADDR; + FlashM->FlashExcep=0; + FlashM->FLASHStatus=FLASH_COMPLETE; + FlashM->MemoryProgramStatus=PASSED; + + SysclkFreq_Change144_48(); + + FLASH_Unlock(); + + Address = PAGE_WRITE_START_ADDR; + + while((Address < (PAGE_WRITE_HALF_END_ADDR-2)) && (FlashM->MemoryProgramStatus != FAILED)) + { + FlashM->FlashData[0]=(*(__IO uint16_t*) Address); + + if( FlashM->FlashData[0]== 0xe339) + { + FlashM->MemoryProgramStatus=FAILED; + if(Address>PAGE_WRITE_START_ADDR) + { + FlashM->FlashData[0]=(*(__IO uint16_t*) (Address-2)); + FlashM->FlashData[1]=(*(__IO uint16_t*) (Address-2+2048)); + + } + } + else + Address += 2; + } + + FlashM->FLASHStatus= FLASH_ErasePage(PAGE_WRITE_START_ADDR); + if(FlashM->FLASHStatus != FLASH_COMPLETE) + { + FlashM->FlashExcep=1; + } + + SysclkFreq_Change48_144(); + + FLASH_Lock();// +} + +/****************************************************************************** +* Function Name : Flash_ProgramHalfWord +* Description : Flash program Half word +* Input : operate Flash struct point/ address/ data +* Output : None +* Return : None +******************************************************************************/ +void Flash_ProgramHalfWord(Flash_Operation_Type *FlashM ,uint32_t Address,uint16_t Data ) +{ + FLASH_Unlock(); + + FlashM->FLASHStatus = FLASH_ProgramHalfWord(Address, Data); + + if(FlashM->FLASHStatus != FLASH_COMPLETE) + { + FlashM->FlashExcep = 1; + } + + FLASH_Lock(); +} diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/MB_Operation_Flash.h b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/MB_Operation_Flash.h new file mode 100644 index 0000000..8931882 --- /dev/null +++ b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/MB_Operation_Flash.h @@ -0,0 +1,24 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : MB_Operation_Flash.h + * Author : WCH + * Version : V1.0.0 + * Date : 2026/04/23 + * Description : +********************************************************************************* +* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ + +#include "M0_Control_Library.h" + +#define PAGE_WRITE_START_ADDR ((uint32_t)0x08010000) /* Start from 64K */ +#define PAGE_WRITE_HALF_END_ADDR ((uint32_t)0x08010800) /* End at 66K */ +#define PAGE_WRITE_END_ADDR ((uint32_t)0x08011000) /* End at 68K */ +#define FLASH_PAGE_SIZE 4096 + +extern Flash_Operation_Type Flash_M; + +void Flash_Operation_Init(Flash_Operation_Type *FlashM);//操作Flash初始化 + +void Flash_ProgramHalfWord(Flash_Operation_Type *FlashM ,uint32_t Address,uint16_t Data ); diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/Motor_SPI_USART_MonitorData.c b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/Motor_SPI_USART_MonitorData.c new file mode 100644 index 0000000..377f84d --- /dev/null +++ b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/Motor_SPI_USART_MonitorData.c @@ -0,0 +1,220 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : Motor_SPI_USART_MonitorData.c + * Author : WCH + * Version : V1.0.0 + * Date : 2026/04/23 + * Description : +********************************************************************************* +* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ + +#include "Motor_SPI_USART_MonitorData.h" + +t_sendUsbData sendUsbData = {0,0,0,0,0,0,0}; +const u_int8_t usbFrameByteNum[12] = {0, 32, 32, 28, 28, 24, 28, 32, 20, 22, 24, 26}; +const u_int8_t needSendLen[12] = {0, USB_NEEDSEND_LEN1, USB_NEEDSEND_LEN2, USB_NEEDSEND_LEN3, USB_NEEDSEND_LEN4, USB_NEEDSEND_LEN5, + USB_NEEDSEND_LEN6, USB_NEEDSEND_LEN7, USB_NEEDSEND_LEN8, USB_NEEDSEND_LEN9, USB_NEEDSEND_LEN10, USB_NEEDSEND_LEN11}; + +/****************************************************************************** +* Function Name : getUsbBufLen +* Description : get Usb Buf Len +* Input : u_int8_t data +* Output : None +* Return : Return head and tail pointer length +******************************************************************************/ +u_int8_t getUsbBufLen(void) +{ + u_int8_t reDataLen; + if(sendUsbData.head >= sendUsbData.end) + { + reDataLen = sendUsbData.head - sendUsbData.end; + } + else + { + reDataLen = (u_int16_t)USB_SENDBUF_LEN - sendUsbData.end + sendUsbData.head; + } + return reDataLen; +} + +/****************************************************************************** +* Function Name : SPI_Deal_sendMonitorData +* Description : SPI send Monitor Data +* Input : None +* Output : None +* Return : None +******************************************************************************/ +void SPI_Deal_sendMonitorData(void) +{ + u_int16_t data=0; + u_int8_t i=0, frameByteNum=0; + sendUsbData.sendDataLen=7; +// if(sendUsbData.sendDataLen) +// { + if(getUsbBufLen() >= 16) + { + GPIO_ResetBits(GPIOB,GPIO_Pin_6); + __asm volatile ("nop"); + while((SPI1->STATR & SPI_I2S_FLAG_TXE) == (uint16_t)RESET); + + SPI1->DATAR = 0x55AA; + while((SPI1->STATR & SPI_I2S_FLAG_TXE) == (uint16_t)RESET); + + sendUsbData.heartBeat++; + data=sendUsbData.heartBeat<<8; + data|=32; + SPI1->DATAR = data; + while((SPI1->STATR & SPI_I2S_FLAG_TXE) == (uint16_t)RESET); + + frameByteNum = 4; +// while(frameByteNum < usbFrameByteNum[sendUsbData.sendDataLen])//{0, 32, 32, 28, 28, 24, 28, 32, 20, 22, 24, 26}; + while(frameByteNum < 32) + { + for(i = 0; i < sendUsbData.sendDataLen; i++) + { + SPI1->DATAR=sendUsbData.sendDataBuf[sendUsbData.end+i]; + while((SPI1->STATR & SPI_I2S_FLAG_TXE) == (uint16_t)RESET); + frameByteNum+=2; + } + sendUsbData.end += MaxUsbDataLen; + } + + while( (SPI1->STATR & SPI_I2S_FLAG_BSY) != (uint16_t)RESET); + __asm volatile ("nop"); + GPIO_SetBits(GPIOB,GPIO_Pin_6); + + } + // } +} + +/****************************************************************************** +* Function Name : SPI_FullDuplex_Init +* Description : SPI Init +* Input : None +* Output : None +* Return : None +******************************************************************************/ +void SPI_FullDuplex_Init(void) +{ + GPIO_InitTypeDef GPIO_InitStructure={0}; + SPI_InitTypeDef SPI_InitStructure={0}; + + RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB | RCC_APB2Periph_SPI1|RCC_APB2Periph_AFIO, ENABLE ); + + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;//MOSI + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_Init( GPIOB, &GPIO_InitStructure ); + + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_Init( GPIOB, &GPIO_InitStructure );//SCK + + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; + GPIO_Init(GPIOB, &GPIO_InitStructure); + + GPIO_PinRemapConfig(GPIO_Remap_SPI1, ENABLE); + + GPIO_SetBits(GPIOB,GPIO_Pin_6); + + SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; + SPI_InitStructure.SPI_Mode = SPI_Mode_Master; + SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b;//16位 + SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; + SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; + SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; + + SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;//72/4=16M + + SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_LSB; + SPI_Init( SPI1, &SPI_InitStructure ); + + GPIO_ResetBits(GPIOB,GPIO_Pin_6); + SPI_Cmd( SPI1, ENABLE ); +} + +/****************************************************************************** +* Function Name : Usart_Init +* Description : SPI Init +* Input : uint32_t Baud 4000000 +* Output : None +* Return : None +******************************************************************************/ +void Usart_Init(uint32_t Baud) +{ + GPIO_InitTypeDef GPIO_InitStructure={0}; + USART_InitTypeDef USART_InitStructure = {0}; + + RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB|RCC_APB2Periph_USART1|RCC_APB2Periph_AFIO, ENABLE ); + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; + GPIO_Init(GPIOB, &GPIO_InitStructure); + GPIO_PinRemapConfig(GPIO_Remap_USART1,ENABLE); + + + USART_InitStructure.USART_BaudRate = Baud; + USART_InitStructure.USART_WordLength = USART_WordLength_8b; + USART_InitStructure.USART_StopBits = USART_StopBits_1; + USART_InitStructure.USART_Parity = USART_Parity_No; + USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; + USART_InitStructure.USART_Mode = USART_Mode_Tx ; + + USART_Init(USART1, &USART_InitStructure); + + USART_Cmd(USART1, ENABLE); + +} + +/****************************************************************************** +* Function Name : Usart_Deal_sendMonitorData +* Description : Usart Send +* Input : None +* Output : None +* Return : None +******************************************************************************/ +void Usart_Deal_sendMonitorData(void) +{ + u_int8_t i=0, frameByteNum=0; + sendUsbData.sendDataLen=4; + if(sendUsbData.sendDataLen) + { + if(getUsbBufLen() >= needSendLen[sendUsbData.sendDataLen]) + { + __asm volatile ("nop"); + while((USART1->STATR & USART_FLAG_TXE) == (uint16_t)RESET); + USART1->DATAR=0xAA; + while((USART1->STATR & USART_FLAG_TXE) == (uint16_t)RESET); + USART1->DATAR=0x55; + while((USART1->STATR & USART_FLAG_TXE) == (uint16_t)RESET); + + USART1->DATAR=usbFrameByteNum[sendUsbData.sendDataLen]; + while((USART1->STATR & USART_FLAG_TXE) == (uint16_t)RESET); + sendUsbData.heartBeat++; + USART1->DATAR=sendUsbData.heartBeat; + while((USART1->STATR & USART_FLAG_TXE) == (uint16_t)RESET); + + + frameByteNum = 4; + while(frameByteNum < usbFrameByteNum[sendUsbData.sendDataLen])//{0, 32, 32, 28, 28, 24, 28, 32, 20, 22, 24, 26}; + { + for(i = 0; i < sendUsbData.sendDataLen; i++) + { + USART1->DATAR = (u_int8_t)((sendUsbData.sendDataBuf[sendUsbData.end+i])&0x00FF); + frameByteNum++; + while((USART1->STATR & USART_FLAG_TXE) == (uint16_t)RESET); + USART1->DATAR = (u_int8_t)((sendUsbData.sendDataBuf[sendUsbData.end+i])>>8); + frameByteNum++; + while((USART1->STATR & USART_FLAG_TXE) == (uint16_t)RESET); + } + sendUsbData.end += MaxUsbDataLen; + } + while((USART1->STATR & USART_FLAG_TXE) == (uint16_t)RESET); + __asm volatile ("nop"); + } + } +} diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/Motor_SPI_USART_MonitorData.h b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/Motor_SPI_USART_MonitorData.h new file mode 100644 index 0000000..feba565 --- /dev/null +++ b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/Motor_SPI_USART_MonitorData.h @@ -0,0 +1,45 @@ +#ifndef __MOTOR_SPI_USART_MONITORDATA_H_ +#define __MOTOR_SPI_USART_MONITORDATA_H_ +/* Includes -----------------------------------------------------------------*/ +#include "debug.h" +/* Exported constants -------------------------------------------------------*/ +#define MaxUsbDataLen 8 +#define USB_SENDBUF_LEN (MaxUsbDataLen<<5) +#define USB_NEEDSEND_LEN1 (MaxUsbDataLen*14) +#define USB_NEEDSEND_LEN2 (MaxUsbDataLen*7) +#define USB_NEEDSEND_LEN3 (MaxUsbDataLen*4) +#define USB_NEEDSEND_LEN4 (MaxUsbDataLen*3) +#define USB_NEEDSEND_LEN5 (MaxUsbDataLen*2) +#define USB_NEEDSEND_LEN6 (MaxUsbDataLen*2) +#define USB_NEEDSEND_LEN7 (MaxUsbDataLen*2) +#define USB_NEEDSEND_LEN8 (MaxUsbDataLen) +#define USB_NEEDSEND_LEN9 (MaxUsbDataLen) +#define USB_NEEDSEND_LEN10 (MaxUsbDataLen) +#define USB_NEEDSEND_LEN11 (MaxUsbDataLen) + +/* Exported types -----------------------------------------------------------*/ +typedef struct +{ + u_int8_t heartBeat; //---心跳包--- + u_int8_t delayNum; //---延迟传输--- + u_int8_t volatile sendDataLen; //----数据长度--- + //UINT8 frameByteNum; //---发送包字节序列--- + u_int8_t curWriteFrame; //----当前写数据帧--- + u_int8_t recDataLen; //----接收上位机数据长度--- + u_int8_t end; + u_int8_t volatile head; + u_int8_t recDataBuf[16]; //---接收数据缓冲区--- + u_int8_t sendDataType[MaxUsbDataLen]; //---发送数据类型--- + u_int16_t sendDataBuf[USB_SENDBUF_LEN]; //---发送数据缓冲区--- +}t_sendUsbData; + +/* Exported variables -------------------------------------------------------*/ +extern t_sendUsbData sendUsbData; + +/* Exported functions--------------------------------------------------------*/ +extern void Deal_sendMonitorData(void); +extern void SPI_FullDuplex_Init(void); +extern void SPI_Deal_sendMonitorData(void); +extern void Usart_Init(uint32_t Baud); +extern void Usart_Deal_sendMonitorData(void); +#endif diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/ch32v20x_conf.h b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/ch32v20x_conf.h new file mode 100644 index 0000000..3a49fb8 --- /dev/null +++ b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/ch32v20x_conf.h @@ -0,0 +1,41 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : ch32v20x_conf.h + * Author : WCH + * Version : V1.0.0 + * Date : 2021/06/06 + * Description : Library configuration file. +********************************************************************************* +* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ +#ifndef __CH32V20x_CONF_H +#define __CH32V20x_CONF_H + +#include "ch32v20x_adc.h" +#include "ch32v20x_bkp.h" +#include "ch32v20x_can.h" +#include "ch32v20x_crc.h" +#include "ch32v20x_dbgmcu.h" +#include "ch32v20x_dma.h" +#include "ch32v20x_exti.h" +#include "ch32v20x_flash.h" +#include "ch32v20x_gpio.h" +#include "ch32v20x_i2c.h" +#include "ch32v20x_iwdg.h" +#include "ch32v20x_pwr.h" +#include "ch32v20x_rcc.h" +#include "ch32v20x_rtc.h" +#include "ch32v20x_spi.h" +#include "ch32v20x_tim.h" +#include "ch32v20x_usart.h" +#include "ch32v20x_wwdg.h" +#include "ch32v20x_misc.h" + + +#endif /* __CH32V20x_CONF_H */ + + + + + diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/libIQmath_RV32.a b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/libIQmath_RV32.a new file mode 100644 index 0000000..93b89ff Binary files /dev/null and b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/libIQmath_RV32.a differ diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/libM12023_SV_1.0_COMCoreV1.5_Library.a b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/libM12023_SV_1.0_COMCoreV1.5_Library.a new file mode 100644 index 0000000..905d92b Binary files /dev/null and b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/libM12023_SV_1.0_COMCoreV1.5_Library.a differ diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/main.c b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/main.c new file mode 100644 index 0000000..8b110a2 --- /dev/null +++ b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/main.c @@ -0,0 +1,65 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : main.c + * Author : WCH + * Version : V1.0.0 + * Date : 2026/04/23 + * Description : Main program body. + ********************************************************************************* + * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. + * Attention: This software (modified or not) and binary are used for + * microcontroller manufactured by Nanjing Qinheng Microelectronics. + *******************************************************************************/ + +#include "M0_Control_Library.h" +#include "ch32v20x_conf.h" +#include "IQmath_RV32.h" +#include "debug.h" + +/********************************************************************* + * @fn main + * + * @brief Main program. + * + * @return none + */ +int main(void) +{ + Delay_Init(); + Delay_Ms(100); + Flash_Operation_Init(&Flash_M); //Post 4K FLASH Erase and Read + KeyandLED_IOInit(); //Button and indicator light IO configuration + KeyandLED_Parameter_Define(&Key_M, &LED_M); //Button and indicator parameters definition + Global_Status_Initial(); //Initialization of global state + Triac_Parameter_Define(&Triac_ctl,&Tempctl_M); //SCR State Initialization + Operation_Parameter_Define(&Operation_M); //Operation Parameter Definition + Motor_Prameter_Define(&MBase_M); //Motor Parameter Definition + Motor_FilerPara_Cal_M(&MStruc_M); //Motor Phase Filter Parameter Initialization + Motor_BaseCal_M(&MBase_M); //Base Value Parameter Calculation + PID_Prameter_Define(&Mpid_M); //PID Parameter Definition + DCurrProcess_Parameter_Define(&DCurrProcess_M); + PID_ParaBase_Cal_M(&MBase_M,&Mpid_M); //PID Base Value Parameter Calculation + Injstart_Parameter_Define_M(&InjStart_M); //Current Injection Start-up Parameter Configuration + Protection_and_Emergency_Parameter_Define(); //Protection Parameter Configuration + Speedrampctr_Parameter_Define(&SpeedRamp_M); //Rotational Speed Operation Parameter Configuration + SVPWM_1R_Paramter_Init(&SVPWM_Cal_M,&PWMCali_M ,&MBase_M); //SVPWM Calculation Parameter Configuration + SVPWM_1R_Timer_Configure(); //SVPWM uses timer and GPIO configuration + ADC_Parameter_Init(&ADC_M,&MBase_M); //ADC Calculation Parameter Configuration + ADC_OPA_Configure(&ADC_M); //ADC and OPA configuration + TempInit_Measure(&Tempctl_M,ADC1); //Initial temperature measurement + LBG_Parameter_Define(&MLBG_M,&LBG_Status_M); //LBG Observer Parameter Definition + LBG_Paramter_Cal (&MBase_M,&MLBG_M); //LBG Observer Parameter Calculation + HFVQI_Parameter_Define(&HFVQI_StartStruc_M,&SVPWM_Cal_M,&PWMCali_M); //Pulse Positioning Parameter Configuration + Poweroperation_Initial(&Powerctr_M); //Power On/Off Control Parameter Configuration + Powercom_Prameter_Define(&Powercom_M); + Systick_Init(); //Speed Loop Configuration + Interrupt_Configuration(); //Configure Interrupt + TIM_Cmd(TIM1, ENABLE); + TIM_Cmd(TIM2, ENABLE); + TIM_Cmd(TIM3, ENABLE); + TIM_Cmd(TIM4, ENABLE); + SYS_TIM_Cmd(ENABLE); + while(1) + { + Motor_Operation_Process(); //Motor Operation + } +} diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/system_ch32v20x.c b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/system_ch32v20x.c new file mode 100644 index 0000000..4e3c710 --- /dev/null +++ b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/system_ch32v20x.c @@ -0,0 +1,964 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : system_ch32v20x.c + * Author : WCH + * Version : V1.0.0 + * Date : 2021/06/06 + * Description : CH32V20x Device Peripheral Access Layer System Source File. + * For HSE = 32Mhz (CH32V208x/CH32V203RBT) + * For HSE = 8Mhz (other CH32V203x) +********************************************************************************* +* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ +#include "ch32v20x.h" + +/* +* Uncomment the line corresponding to the desired System clock (SYSCLK) frequency (after +* reset the HSI is used as SYSCLK source). +* If none of the define below is enabled, the HSI is used as System clock source. +*/ +//#define SYSCLK_FREQ_HSE HSE_VALUE +//#define SYSCLK_FREQ_48MHz_HSE 48000000 +//#define SYSCLK_FREQ_56MHz_HSE 56000000 +//#define SYSCLK_FREQ_72MHz_HSE 72000000 +//#define SYSCLK_FREQ_96MHz_HSE 96000000 +//#define SYSCLK_FREQ_120MHz_HSE 120000000 +//#define SYSCLK_FREQ_144MHz_HSE 144000000 +//#define SYSCLK_FREQ_HSI HSI_VALUE +//#define SYSCLK_FREQ_48MHz_HSI 48000000 +//#define SYSCLK_FREQ_56MHz_HSI 56000000 +//#define SYSCLK_FREQ_72MHz_HSI 72000000 +//#define SYSCLK_FREQ_96MHz_HSI 96000000 +//#define SYSCLK_FREQ_120MHz_HSI 120000000 +#define SYSCLK_FREQ_144MHz_HSI 144000000 + +/* Clock Definitions */ +#ifdef SYSCLK_FREQ_HSE +uint32_t SystemCoreClock = SYSCLK_FREQ_HSE; /* System Clock Frequency (Core Clock) */ +#elif defined SYSCLK_FREQ_48MHz_HSE +uint32_t SystemCoreClock = SYSCLK_FREQ_48MHz_HSE; /* System Clock Frequency (Core Clock) */ +#elif defined SYSCLK_FREQ_56MHz_HSE +uint32_t SystemCoreClock = SYSCLK_FREQ_56MHz_HSE; /* System Clock Frequency (Core Clock) */ +#elif defined SYSCLK_FREQ_72MHz_HSE +uint32_t SystemCoreClock = SYSCLK_FREQ_72MHz_HSE; /* System Clock Frequency (Core Clock) */ +#elif defined SYSCLK_FREQ_96MHz_HSE +uint32_t SystemCoreClock = SYSCLK_FREQ_96MHz_HSE; /* System Clock Frequency (Core Clock) */ +#elif defined SYSCLK_FREQ_120MHz_HSE +uint32_t SystemCoreClock = SYSCLK_FREQ_120MHz_HSE; /* System Clock Frequency (Core Clock) */ +#elif defined SYSCLK_FREQ_144MHz_HSE +uint32_t SystemCoreClock = SYSCLK_FREQ_144MHz_HSE; /* System Clock Frequency (Core Clock) */ +#elif defined SYSCLK_FREQ_48MHz_HSI +uint32_t SystemCoreClock = SYSCLK_FREQ_48MHz_HSI; /* System Clock Frequency (Core Clock) */ +#elif defined SYSCLK_FREQ_56MHz_HSI +uint32_t SystemCoreClock = SYSCLK_FREQ_56MHz_HSI; /* System Clock Frequency (Core Clock) */ +#elif defined SYSCLK_FREQ_72MHz_HSI +uint32_t SystemCoreClock = SYSCLK_FREQ_72MHz_HSI; /* System Clock Frequency (Core Clock) */ +#elif defined SYSCLK_FREQ_96MHz_HSI +uint32_t SystemCoreClock = SYSCLK_FREQ_96MHz_HSI; /* System Clock Frequency (Core Clock) */ +#elif defined SYSCLK_FREQ_120MHz_HSI +uint32_t SystemCoreClock = SYSCLK_FREQ_120MHz_HSI; /* System Clock Frequency (Core Clock) */ +#elif defined SYSCLK_FREQ_144MHz_HSI +uint32_t SystemCoreClock = SYSCLK_FREQ_144MHz_HSI; /* System Clock Frequency (Core Clock) */ +#else +uint32_t SystemCoreClock = HSI_VALUE; /* System Clock Frequency (Core Clock) */ + +#endif + +__I uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}; + + +/* system_private_function_proto_types */ +static void SetSysClock(void); + +#ifdef SYSCLK_FREQ_HSE +static void SetSysClockToHSE( void ); +#elif defined SYSCLK_FREQ_48MHz_HSE +static void SetSysClockTo48_HSE( void ); +#elif defined SYSCLK_FREQ_56MHz_HSE +static void SetSysClockTo56_HSE( void ); +#elif defined SYSCLK_FREQ_72MHz_HSE +static void SetSysClockTo72_HSE( void ); +#elif defined SYSCLK_FREQ_96MHz_HSE +static void SetSysClockTo96_HSE( void ); +#elif defined SYSCLK_FREQ_120MHz_HSE +static void SetSysClockTo120_HSE( void ); +#elif defined SYSCLK_FREQ_144MHz_HSE +static void SetSysClockTo144_HSE( void ); +#elif defined SYSCLK_FREQ_48MHz_HSI +static void SetSysClockTo48_HSI( void ); +#elif defined SYSCLK_FREQ_56MHz_HSI +static void SetSysClockTo56_HSI( void ); +#elif defined SYSCLK_FREQ_72MHz_HSI +static void SetSysClockTo72_HSI( void ); +#elif defined SYSCLK_FREQ_96MHz_HSI +static void SetSysClockTo96_HSI( void ); +#elif defined SYSCLK_FREQ_120MHz_HSI +static void SetSysClockTo120_HSI( void ); +#elif defined SYSCLK_FREQ_144MHz_HSI +static void SetSysClockTo144_HSI( void ); + +#endif + +/********************************************************************* + * @fn SystemInit + * + * @brief Setup the microcontroller system Initialize the Embedded Flash Interface, + * the PLL and update the SystemCoreClock variable. + * + * @return none + */ +void SystemInit (void) +{ + RCC->CTLR |= (uint32_t)0x00000001; + RCC->CFGR0 &= (uint32_t)0xF8FF0000; + RCC->CTLR &= (uint32_t)0xFEF6FFFF; + RCC->CTLR &= (uint32_t)0xFFFBFFFF; + RCC->CFGR0 &= (uint32_t)0xFF80FFFF; + RCC->INTR = 0x009F0000; + SetSysClock(); +} + + +/********************************************************************* + * @fn SystemCoreClockUpdate + * + * @brief Update SystemCoreClock variable according to Clock Register Values. + * + * @return none + */ +void SystemCoreClockUpdate (void) +{ + uint32_t tmp = 0, pllmull = 0, pllsource = 0, Pll_6_5 = 0; + + tmp = RCC->CFGR0 & RCC_SWS; + + switch (tmp) + { + case 0x00: + SystemCoreClock = HSI_VALUE; + break; + case 0x04: + SystemCoreClock = HSE_VALUE; + break; + case 0x08: + pllmull = RCC->CFGR0 & RCC_PLLMULL; + pllsource = RCC->CFGR0 & RCC_PLLSRC; + pllmull = ( pllmull >> 18) + 2; + + if(pllmull == 17) pllmull = 18; + + if (pllsource == 0x00) + { + if(EXTEN->EXTEN_CTR & EXTEN_PLL_HSI_PRE){ + SystemCoreClock = HSI_VALUE * pllmull; + } + else{ + SystemCoreClock = (HSI_VALUE >> 1) * pllmull; + } + } + else + { +#if defined (CH32V20x_D8W) + if((RCC->CFGR0 & (3<<22)) == (3<<22)) + { + SystemCoreClock = ((HSE_VALUE>>1)) * pllmull; + } + else +#endif + if ((RCC->CFGR0 & RCC_PLLXTPRE) != (uint32_t)RESET) + { +#if defined (CH32V20x_D8) || defined (CH32V20x_D8W) + SystemCoreClock = ((HSE_VALUE>>2) >> 1) * pllmull; +#else + SystemCoreClock = (HSE_VALUE >> 1) * pllmull; +#endif + } + else + { +#if defined (CH32V20x_D8) || defined (CH32V20x_D8W) + SystemCoreClock = (HSE_VALUE>>2) * pllmull; +#else + SystemCoreClock = HSE_VALUE * pllmull; +#endif + } + } + + if(Pll_6_5 == 1) SystemCoreClock = (SystemCoreClock / 2); + + break; + default: + SystemCoreClock = HSI_VALUE; + break; + } + + tmp = AHBPrescTable[((RCC->CFGR0 & RCC_HPRE) >> 4)]; + SystemCoreClock >>= tmp; +} + +/********************************************************************* + * @fn SetSysClock + * + * @brief Configures the System clock frequency, HCLK, PCLK2 and PCLK1 prescalers. + * + * @return none + */ +static void SetSysClock(void) +{ +#ifdef SYSCLK_FREQ_HSE + SetSysClockToHSE(); +#elif defined SYSCLK_FREQ_48MHz_HSE + SetSysClockTo48_HSE(); +#elif defined SYSCLK_FREQ_56MHz_HSE + SetSysClockTo56_HSE(); +#elif defined SYSCLK_FREQ_72MHz_HSE + SetSysClockTo72_HSE(); +#elif defined SYSCLK_FREQ_96MHz_HSE + SetSysClockTo96_HSE(); +#elif defined SYSCLK_FREQ_120MHz_HSE + SetSysClockTo120_HSE(); +#elif defined SYSCLK_FREQ_144MHz_HSE + SetSysClockTo144_HSE(); +#elif defined SYSCLK_FREQ_48MHz_HSI + SetSysClockTo48_HSI(); +#elif defined SYSCLK_FREQ_56MHz_HSI + SetSysClockTo56_HSI(); +#elif defined SYSCLK_FREQ_72MHz_HSI + SetSysClockTo72_HSI(); +#elif defined SYSCLK_FREQ_96MHz_HSI + SetSysClockTo96_HSI(); +#elif defined SYSCLK_FREQ_120MHz_HSI + SetSysClockTo120_HSI(); +#elif defined SYSCLK_FREQ_144MHz_HSI + SetSysClockTo144_HSI(); + +#endif + + /* If none of the define above is enabled, the HSI is used as System clock + * source (default after reset) + */ +} + + +#ifdef SYSCLK_FREQ_HSE + +/********************************************************************* + * @fn SetSysClockToHSE + * + * @brief Sets HSE as System clock source and configure HCLK, PCLK2 and PCLK1 prescalers. + * + * @return none + */ +static void SetSysClockToHSE(void) +{ + __IO uint32_t StartUpCounter = 0, HSEStatus = 0; + + + RCC->CTLR |= ((uint32_t)RCC_HSEON); + + /* Wait till HSE is ready and if Time out is reached exit */ + do + { + HSEStatus = RCC->CTLR & RCC_HSERDY; + StartUpCounter++; + } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT)); + + if ((RCC->CTLR & RCC_HSERDY) != RESET) + { + HSEStatus = (uint32_t)0x01; + } + else + { + HSEStatus = (uint32_t)0x00; + } + + if (HSEStatus == (uint32_t)0x01) + { + /* HCLK = SYSCLK */ + RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1; + /* PCLK2 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1; + /* PCLK1 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV1; + + /* Select HSE as system clock source */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW)); + RCC->CFGR0 |= (uint32_t)RCC_SW_HSE; + + /* Wait till HSE is used as system clock source */ + while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x04) + { + } + } + else + { + /* If HSE fails to start-up, the application will have wrong clock + * configuration. User can add here some code to deal with this error + */ + } +} + +#elif defined SYSCLK_FREQ_48MHz_HSE + +/********************************************************************* + * @fn SetSysClockTo48_HSE + * + * @brief Sets System clock frequency to 48MHz and configure HCLK, PCLK2 and PCLK1 prescalers. + * + * @return none + */ +static void SetSysClockTo48_HSE(void) +{ + __IO uint32_t StartUpCounter = 0, HSEStatus = 0; + + + RCC->CTLR |= ((uint32_t)RCC_HSEON); + /* Wait till HSE is ready and if Time out is reached exit */ + do + { + HSEStatus = RCC->CTLR & RCC_HSERDY; + StartUpCounter++; + } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT)); + + if ((RCC->CTLR & RCC_HSERDY) != RESET) + { + HSEStatus = (uint32_t)0x01; + } + else + { + HSEStatus = (uint32_t)0x00; + } + + if (HSEStatus == (uint32_t)0x01) + { + /* HCLK = SYSCLK */ + RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1; + /* PCLK2 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1; + /* PCLK1 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2; + + /* PLL configuration: PLLCLK = HSE * 6 = 48 MHz */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | RCC_PLLMULL)); + + RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL6); + + /* Enable PLL */ + RCC->CTLR |= RCC_PLLON; + /* Wait till PLL is ready */ + while((RCC->CTLR & RCC_PLLRDY) == 0) + { + } + /* Select PLL as system clock source */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW)); + RCC->CFGR0 |= (uint32_t)RCC_SW_PLL; + /* Wait till PLL is used as system clock source */ + while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08) + { + } + } + else + { + /* + * If HSE fails to start-up, the application will have wrong clock + * configuration. User can add here some code to deal with this error + */ + } +} + +#elif defined SYSCLK_FREQ_56MHz_HSE + +/********************************************************************* + * @fn SetSysClockTo56_HSE + * + * @brief Sets System clock frequency to 56MHz and configure HCLK, PCLK2 and PCLK1 prescalers. + * + * @return none + */ +static void SetSysClockTo56_HSE(void) +{ + __IO uint32_t StartUpCounter = 0, HSEStatus = 0; + + RCC->CTLR |= ((uint32_t)RCC_HSEON); + + /* Wait till HSE is ready and if Time out is reached exit */ + do + { + HSEStatus = RCC->CTLR & RCC_HSERDY; + StartUpCounter++; + } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT)); + + if ((RCC->CTLR & RCC_HSERDY) != RESET) + { + HSEStatus = (uint32_t)0x01; + } + else + { + HSEStatus = (uint32_t)0x00; + } + + if (HSEStatus == (uint32_t)0x01) + { + /* HCLK = SYSCLK */ + RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1; + /* PCLK2 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1; + /* PCLK1 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2; + + /* PLL configuration: PLLCLK = HSE * 7 = 56 MHz */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | RCC_PLLMULL)); + + RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL7); + + /* Enable PLL */ + RCC->CTLR |= RCC_PLLON; + /* Wait till PLL is ready */ + while((RCC->CTLR & RCC_PLLRDY) == 0) + { + } + + /* Select PLL as system clock source */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW)); + RCC->CFGR0 |= (uint32_t)RCC_SW_PLL; + /* Wait till PLL is used as system clock source */ + while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08) + { + } + } + else + { + /* + * If HSE fails to start-up, the application will have wrong clock + * configuration. User can add here some code to deal with this error + */ + } +} + +#elif defined SYSCLK_FREQ_72MHz_HSE + +/********************************************************************* + * @fn SetSysClockTo72_HSE + * + * @brief Sets System clock frequency to 72MHz and configure HCLK, PCLK2 and PCLK1 prescalers. + * + * @return none + */ +static void SetSysClockTo72_HSE(void) +{ + __IO uint32_t StartUpCounter = 0, HSEStatus = 0; + + RCC->CTLR |= ((uint32_t)RCC_HSEON); + + /* Wait till HSE is ready and if Time out is reached exit */ + do + { + HSEStatus = RCC->CTLR & RCC_HSERDY; + StartUpCounter++; + } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT)); + + if ((RCC->CTLR & RCC_HSERDY) != RESET) + { + HSEStatus = (uint32_t)0x01; + } + else + { + HSEStatus = (uint32_t)0x00; + } + + if (HSEStatus == (uint32_t)0x01) + { + /* HCLK = SYSCLK */ + RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1; + /* PCLK2 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1; + /* PCLK1 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2; + + /* PLL configuration: PLLCLK = HSE * 9 = 72 MHz */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | + RCC_PLLMULL)); + + RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL9); + + /* Enable PLL */ + RCC->CTLR |= RCC_PLLON; + /* Wait till PLL is ready */ + while((RCC->CTLR & RCC_PLLRDY) == 0) + { + } + /* Select PLL as system clock source */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW)); + RCC->CFGR0 |= (uint32_t)RCC_SW_PLL; + /* Wait till PLL is used as system clock source */ + while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08) + { + } + } + else + { + /* + * If HSE fails to start-up, the application will have wrong clock + * configuration. User can add here some code to deal with this error + */ + } +} + + +#elif defined SYSCLK_FREQ_96MHz_HSE + +/********************************************************************* + * @fn SetSysClockTo96_HSE + * + * @brief Sets System clock frequency to 96MHz and configure HCLK, PCLK2 and PCLK1 prescalers. + * + * @return none + */ +static void SetSysClockTo96_HSE(void) +{ + __IO uint32_t StartUpCounter = 0, HSEStatus = 0; + + RCC->CTLR |= ((uint32_t)RCC_HSEON); + + /* Wait till HSE is ready and if Time out is reached exit */ + do + { + HSEStatus = RCC->CTLR & RCC_HSERDY; + StartUpCounter++; + } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT)); + + if ((RCC->CTLR & RCC_HSERDY) != RESET) + { + HSEStatus = (uint32_t)0x01; + } + else + { + HSEStatus = (uint32_t)0x00; + } + + if (HSEStatus == (uint32_t)0x01) + { + /* HCLK = SYSCLK */ + RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1; + /* PCLK2 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1; + /* PCLK1 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2; + + /* PLL configuration: PLLCLK = HSE * 12 = 96 MHz */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | + RCC_PLLMULL)); + + RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL12); + + /* Enable PLL */ + RCC->CTLR |= RCC_PLLON; + /* Wait till PLL is ready */ + while((RCC->CTLR & RCC_PLLRDY) == 0) + { + } + /* Select PLL as system clock source */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW)); + RCC->CFGR0 |= (uint32_t)RCC_SW_PLL; + /* Wait till PLL is used as system clock source */ + while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08) + { + } + } + else + { + /* + * If HSE fails to start-up, the application will have wrong clock + * configuration. User can add here some code to deal with this error + */ + } +} + + +#elif defined SYSCLK_FREQ_120MHz_HSE + +/********************************************************************* + * @fn SetSysClockTo120_HSE + * + * @brief Sets System clock frequency to 120MHz and configure HCLK, PCLK2 and PCLK1 prescalers. + * + * @return none + */ +static void SetSysClockTo120_HSE(void) +{ + __IO uint32_t StartUpCounter = 0, HSEStatus = 0; + + RCC->CTLR |= ((uint32_t)RCC_HSEON); + + /* Wait till HSE is ready and if Time out is reached exit */ + do + { + HSEStatus = RCC->CTLR & RCC_HSERDY; + StartUpCounter++; + } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT)); + + if((RCC->CTLR & RCC_HSERDY) != RESET) + { + HSEStatus = (uint32_t)0x01; + } + else + { + HSEStatus = (uint32_t)0x00; + } + + if(HSEStatus == (uint32_t)0x01) + { +#if defined (CH32V20x_D8W) + RCC->CFGR0 |= (uint32_t)(3<<22); + /* HCLK = SYSCLK/2 */ + RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV2; +#else + /* HCLK = SYSCLK */ + RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1; +#endif + /* PCLK2 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1; + /* PCLK1 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2; + + /* PLL configuration: PLLCLK = HSE * 15 = 120 MHz */ + RCC->CFGR0 &= (uint32_t)((uint32_t) ~(RCC_PLLSRC | RCC_PLLXTPRE | + RCC_PLLMULL)); + + RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL15); + + /* Enable PLL */ + RCC->CTLR |= RCC_PLLON; + /* Wait till PLL is ready */ + while((RCC->CTLR & RCC_PLLRDY) == 0) + { + } + /* Select PLL as system clock source */ + RCC->CFGR0 &= (uint32_t)((uint32_t) ~(RCC_SW)); + RCC->CFGR0 |= (uint32_t)RCC_SW_PLL; + /* Wait till PLL is used as system clock source */ + while((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08) + { + } + } + else + { + /* + * If HSE fails to start-up, the application will have wrong clock + * configuration. User can add here some code to deal with this error + */ + } +} +#elif defined SYSCLK_FREQ_144MHz_HSE + +/********************************************************************* + * @fn SetSysClockTo144_HSE + * + * @brief Sets System clock frequency to 144MHz and configure HCLK, PCLK2 and PCLK1 prescalers. + * + * @return none + */ +static void SetSysClockTo144_HSE(void) +{ + __IO uint32_t StartUpCounter = 0, HSEStatus = 0; + + RCC->CTLR |= ((uint32_t)RCC_HSEON); + + /* Wait till HSE is ready and if Time out is reached exit */ + do + { + HSEStatus = RCC->CTLR & RCC_HSERDY; + StartUpCounter++; + } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT)); + + if ((RCC->CTLR & RCC_HSERDY) != RESET) + { + HSEStatus = (uint32_t)0x01; + } + else + { + HSEStatus = (uint32_t)0x00; + } + + if (HSEStatus == (uint32_t)0x01) + { + /* HCLK = SYSCLK */ + RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1; + /* PCLK2 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1; + /* PCLK1 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2; + + /* PLL configuration: PLLCLK = HSE * 18 = 144 MHz */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | + RCC_PLLMULL)); + + RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL18); + + /* Enable PLL */ + RCC->CTLR |= RCC_PLLON; + /* Wait till PLL is ready */ + while((RCC->CTLR & RCC_PLLRDY) == 0) + { + } + /* Select PLL as system clock source */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW)); + RCC->CFGR0 |= (uint32_t)RCC_SW_PLL; + /* Wait till PLL is used as system clock source */ + while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08) + { + } + } + else + { + /* + * If HSE fails to start-up, the application will have wrong clock + * configuration. User can add here some code to deal with this error + */ + } +} + +#elif defined SYSCLK_FREQ_48MHz_HSI + +/********************************************************************* + * @fn SetSysClockTo48_HSI + * + * @brief Sets System clock frequency to 48MHz and configure HCLK, PCLK2 and PCLK1 prescalers. + * + * @return none + */ +static void SetSysClockTo48_HSI(void) +{ + EXTEN->EXTEN_CTR |= EXTEN_PLL_HSI_PRE; + + /* HCLK = SYSCLK */ + RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1; + /* PCLK2 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1; + /* PCLK1 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2; + + /* PLL configuration: PLLCLK = HSI * 6 = 48 MHz */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | RCC_PLLMULL)); + + RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSI_Div2 | RCC_PLLMULL6); + + /* Enable PLL */ + RCC->CTLR |= RCC_PLLON; + /* Wait till PLL is ready */ + while((RCC->CTLR & RCC_PLLRDY) == 0) + { + } + /* Select PLL as system clock source */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW)); + RCC->CFGR0 |= (uint32_t)RCC_SW_PLL; + /* Wait till PLL is used as system clock source */ + while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08) + { + } +} + +#elif defined SYSCLK_FREQ_56MHz_HSI + +/********************************************************************* + * @fn SetSysClockTo56_HSI + * + * @brief Sets System clock frequency to 56MHz and configure HCLK, PCLK2 and PCLK1 prescalers. + * + * @return none + */ +static void SetSysClockTo56_HSI(void) +{ + EXTEN->EXTEN_CTR |= EXTEN_PLL_HSI_PRE; + + /* HCLK = SYSCLK */ + RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1; + /* PCLK2 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1; + /* PCLK1 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2; + + /* PLL configuration: PLLCLK = HSI * 7 = 48 MHz */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | RCC_PLLMULL)); + + RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSI_Div2 | RCC_PLLMULL7); + + /* Enable PLL */ + RCC->CTLR |= RCC_PLLON; + /* Wait till PLL is ready */ + while((RCC->CTLR & RCC_PLLRDY) == 0) + { + } + /* Select PLL as system clock source */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW)); + RCC->CFGR0 |= (uint32_t)RCC_SW_PLL; + /* Wait till PLL is used as system clock source */ + while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08) + { + } +} + +#elif defined SYSCLK_FREQ_72MHz_HSI + +/********************************************************************* + * @fn SetSysClockTo72_HSI + * + * @brief Sets System clock frequency to 72MHz and configure HCLK, PCLK2 and PCLK1 prescalers. + * + * @return none + */ +static void SetSysClockTo72_HSI(void) +{ + EXTEN->EXTEN_CTR |= EXTEN_PLL_HSI_PRE; + + /* HCLK = SYSCLK */ + RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1; + /* PCLK2 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1; + /* PCLK1 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2; + + /* PLL configuration: PLLCLK = HSI * 9 = 72 MHz */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | RCC_PLLMULL)); + + RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSI_Div2 | RCC_PLLMULL9); + + /* Enable PLL */ + RCC->CTLR |= RCC_PLLON; + /* Wait till PLL is ready */ + while((RCC->CTLR & RCC_PLLRDY) == 0) + { + } + /* Select PLL as system clock source */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW)); + RCC->CFGR0 |= (uint32_t)RCC_SW_PLL; + /* Wait till PLL is used as system clock source */ + while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08) + { + } +} + + +#elif defined SYSCLK_FREQ_96MHz_HSI + +/********************************************************************* + * @fn SetSysClockTo96_HSI + * + * @brief Sets System clock frequency to 96MHz and configure HCLK, PCLK2 and PCLK1 prescalers. + * + * @return none + */ +static void SetSysClockTo96_HSI(void) +{ + EXTEN->EXTEN_CTR |= EXTEN_PLL_HSI_PRE; + + /* HCLK = SYSCLK */ + RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1; + /* PCLK2 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1; + /* PCLK1 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2; + + /* PLL configuration: PLLCLK = HSI * 12 = 96 MHz */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | RCC_PLLMULL)); + + RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSI_Div2 | RCC_PLLMULL12); + + /* Enable PLL */ + RCC->CTLR |= RCC_PLLON; + /* Wait till PLL is ready */ + while((RCC->CTLR & RCC_PLLRDY) == 0) + { + } + /* Select PLL as system clock source */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW)); + RCC->CFGR0 |= (uint32_t)RCC_SW_PLL; + /* Wait till PLL is used as system clock source */ + while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08) + { + } +} + + +#elif defined SYSCLK_FREQ_120MHz_HSI + +/********************************************************************* + * @fn SetSysClockTo120_HSI + * + * @brief Sets System clock frequency to 120MHz and configure HCLK, PCLK2 and PCLK1 prescalers. + * + * @return none + */ +static void SetSysClockTo120_HSI(void) +{ + EXTEN->EXTEN_CTR |= EXTEN_PLL_HSI_PRE; + + /* HCLK = SYSCLK */ + RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1; + /* PCLK2 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1; + /* PCLK1 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2; + + /* PLL configuration: PLLCLK = HSI * 15 = 120 MHz */ + RCC->CFGR0 &= (uint32_t)((uint32_t) ~(RCC_PLLSRC | RCC_PLLXTPRE | + RCC_PLLMULL)); + + RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSI_Div2 | RCC_PLLMULL15); + + /* Enable PLL */ + RCC->CTLR |= RCC_PLLON; + /* Wait till PLL is ready */ + while((RCC->CTLR & RCC_PLLRDY) == 0) + { + } + /* Select PLL as system clock source */ + RCC->CFGR0 &= (uint32_t)((uint32_t) ~(RCC_SW)); + RCC->CFGR0 |= (uint32_t)RCC_SW_PLL; + /* Wait till PLL is used as system clock source */ + while((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08) + { + } +} +#elif defined SYSCLK_FREQ_144MHz_HSI + +/********************************************************************* + * @fn SetSysClockTo144_HSI + * + * @brief Sets System clock frequency to 144MHz and configure HCLK, PCLK2 and PCLK1 prescalers. + * + * @return none + */ +static void SetSysClockTo144_HSI(void) +{ + EXTEN->EXTEN_CTR |= EXTEN_PLL_HSI_PRE; + + /* HCLK = SYSCLK */ + RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1; + /* PCLK2 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV2; + /* PCLK1 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2; + + /* PLL configuration: PLLCLK = HSI * 18 = 144 MHz */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | RCC_PLLMULL)); + + RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSI_Div2 | RCC_PLLMULL18); + + /* Enable PLL */ + RCC->CTLR |= RCC_PLLON; + /* Wait till PLL is ready */ + while((RCC->CTLR & RCC_PLLRDY) == 0) + { + } + /* Select PLL as system clock source */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW)); + RCC->CFGR0 |= (uint32_t)RCC_SW_PLL; + /* Wait till PLL is used as system clock source */ + while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08) + { + } +} + + +#endif diff --git a/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/system_ch32v20x.h b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/system_ch32v20x.h new file mode 100644 index 0000000..9c8a3f7 --- /dev/null +++ b/EVT/EXAM/APPLICATION/Electric_Hair_Dryer/User/system_ch32v20x.h @@ -0,0 +1,32 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : system_ch32v20x.h + * Author : WCH + * Version : V1.0.0 + * Date : 2021/06/06 + * Description : CH32V20x Device Peripheral Access Layer System Header File. +********************************************************************************* +* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ +#ifndef __SYSTEM_ch32v20x_H +#define __SYSTEM_ch32v20x_H + +#ifdef __cplusplus + extern "C" { +#endif + +extern uint32_t SystemCoreClock; /* System Clock Frequency (Core Clock) */ + +/* System_Exported_Functions */ +extern void SystemInit(void); +extern void SystemCoreClockUpdate(void); + +#ifdef __cplusplus +} +#endif + +#endif /*__CH32V20x_SYSTEM_H */ + + + diff --git a/EVT/EXAM/APPLICATION/WUI/.cproject b/EVT/EXAM/APPLICATION/WUI/.cproject new file mode 100644 index 0000000..ef4db59 --- /dev/null +++ b/EVT/EXAM/APPLICATION/WUI/.cproject @@ -0,0 +1,295 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/EVT/EXAM/APPLICATION/WUI/.project b/EVT/EXAM/APPLICATION/WUI/.project new file mode 100644 index 0000000..b0cef1b --- /dev/null +++ b/EVT/EXAM/APPLICATION/WUI/.project @@ -0,0 +1,60 @@ + + + wui_demo + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + + + Core + 2 + PARENT-2-PROJECT_LOC/SRC/Core + + + Debug + 2 + PARENT-2-PROJECT_LOC/SRC/Debug + + + Ld + 2 + PARENT-2-PROJECT_LOC/SRC/Ld + + + Peripheral + 2 + PARENT-2-PROJECT_LOC/SRC/Peripheral + + + Startup + 2 + PARENT-2-PROJECT_LOC/SRC/Startup + + + + + + 6 + + org.eclipse.ui.ide.multiFilter + 1.0-name-matches-false-false-*.wvproj + + + + \ No newline at end of file diff --git a/EVT/EXAM/APPLICATION/WUI/.template b/EVT/EXAM/APPLICATION/WUI/.template new file mode 100644 index 0000000..e422213 --- /dev/null +++ b/EVT/EXAM/APPLICATION/WUI/.template @@ -0,0 +1,32 @@ +Vendor=WCH +Toolchain=RISC-V +Series=CH32V203 +RTOS=NoneOS +CalibrateSupport=false +CalibrateCommand= +UIConfigSupport=false +UIConfigCommand= +ExternalFlashSupport=false +MCU=CH32V203RBT +Link=WCH-Link +PeripheralVersion=1.0 +Description=ROM(byte): 64K, SRAM(byte): 20K, CHIP PINS: 32, GPIO PORTS: 27.\nWCH CH32V2 series of mainstream MCUs covers the needs of a large variety of applications in the industrial,medical and consumer markets. High performance with first-class peripherals and low-power,low-voltage operation is paired with a high level of integration at accessible prices with a simple architecture and easy-to-use tools. +TempratureScope= +ArtifactType=executable +Mcu Type=CH32V20x +Address=0x08000000 +Target Path=obj\wui_demo.hex +Exe Path= +Exe Arguments= +CLKSpeed=1 +DebugInterfaceMode=0 +Erase All=true +Program=true +Verify=true +Reset=true +SDIPrintf=false +Disable Power Output=false +Clear CodeFlash=false +Disable Code-Protect=false +Flash Type= +Algorithm File= \ No newline at end of file diff --git a/EVT/EXAM/APPLICATION/WUI/DOC_SCH/CH32V20x_WUI_DEMO.pdf b/EVT/EXAM/APPLICATION/WUI/DOC_SCH/CH32V20x_WUI_DEMO.pdf new file mode 100644 index 0000000..5a21db5 Binary files /dev/null and b/EVT/EXAM/APPLICATION/WUI/DOC_SCH/CH32V20x_WUI_DEMO.pdf differ diff --git a/EVT/EXAM/APPLICATION/WUI/DOC_SCH/WUI_DEMO/CH32V20x_WUI_DEMO.schdoc b/EVT/EXAM/APPLICATION/WUI/DOC_SCH/WUI_DEMO/CH32V20x_WUI_DEMO.schdoc new file mode 100644 index 0000000..e53ff29 Binary files /dev/null and b/EVT/EXAM/APPLICATION/WUI/DOC_SCH/WUI_DEMO/CH32V20x_WUI_DEMO.schdoc differ diff --git a/EVT/EXAM/APPLICATION/WUI/DOC_SCH/娌佹亽WCHGUI杞欢璇存槑鏂囨。.pdf b/EVT/EXAM/APPLICATION/WUI/DOC_SCH/娌佹亽WCHGUI杞欢璇存槑鏂囨。.pdf new file mode 100644 index 0000000..7ca380b Binary files /dev/null and b/EVT/EXAM/APPLICATION/WUI/DOC_SCH/娌佹亽WCHGUI杞欢璇存槑鏂囨。.pdf differ diff --git a/EVT/EXAM/APPLICATION/WUI/User/Drivers/LCD.c b/EVT/EXAM/APPLICATION/WUI/User/Drivers/LCD.c new file mode 100644 index 0000000..c8e5bce --- /dev/null +++ b/EVT/EXAM/APPLICATION/WUI/User/Drivers/LCD.c @@ -0,0 +1,383 @@ +/********************************************************************* + * File Name : lcd.c + * Author : WCH + * Version : V1.0.0 + * Date : 2023/8/15 + * Description : file for lcd screen. + ********************************************************************************* +* Copyright (c) 2023 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ + +#include "lcd.h" +#include "debug.h" +#include "LCD_Font.h" + +#define LCD_SOFT_RESET (0x01) +#define LCD_READ_ID (0x04) +#define LCD_READ_DISPLAY_STATUS (0x09) +#define LCD_ON (0x28) +#define LCD_OFF (0x29) + +#define LCD_SET_X (0x2a) +#define LCD_SET_Y (0x2b) +#define LCD_MEM_WRITE (0x2C) +#define LCD_MEM_READ (0x2e) + +static void LCD_WR_REG(uint8_t data) +{ + LCD_DC_CLR(); + SPI2_Write(data); +} + +static void LCD_WR_DATA(uint8_t data) +{ + LCD_DC_SET(); + SPI2_Write(data); +} + +/********************************************************************* + * @fn Lcd_WriteData_16Bit + * + * @brief write two bytes to the lcd screen + * + * @param Data - the data to write + * + * @return none + */ +void Lcd_WriteData_16Bit(uint16_t Data) +{ + SPI2_Write(Data >> 8); + SPI2_Write(Data); +} + +/********************************************************************* + * @fn LCD_GPIOInit + * + * @brief Configuring the control gpio for the lcd screen + * + * @return none + */ +void LCD_GPIOInit(void) +{ + GPIO_InitTypeDef GPIO_InitStructure; + RCC_APB2PeriphClockCmd(LCD_LED_RCC, ENABLE); + RCC_APB2PeriphClockCmd(LCD_DC_RCC, ENABLE); + RCC_APB2PeriphClockCmd(LCD_RST_RCC, ENABLE); + RCC_APB2PeriphClockCmd(LCD_CS_RCC, ENABLE); + + GPIO_InitStructure.GPIO_Pin = LCD_LED_PIN; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; + GPIO_Init(LCD_LED_PORT, &GPIO_InitStructure); + + GPIO_InitStructure.GPIO_Pin = LCD_DC_PIN; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; + GPIO_Init(LCD_DC_PORT, &GPIO_InitStructure); + + GPIO_InitStructure.GPIO_Pin = LCD_RST_PIN; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; + GPIO_Init(LCD_RST_PORT, &GPIO_InitStructure); + + GPIO_InitStructure.GPIO_Pin = LCD_CS_PIN; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; + GPIO_Init(LCD_CS_PORT, &GPIO_InitStructure); + + LCD_LED_CLR(); + LCD_CS_SET(); +} + +/********************************************************************* + * @fn LCD_RESET + * + * @brief reset the lcd screen by the rst pin + * + * @return none + */ +void LCD_RESET(void) +{ + Delay_Ms(50); + LCD_RST_CLR(); + Delay_Ms(100); + LCD_RST_SET(); + Delay_Ms(50); +} + +static const uint8_t lcd_st7789_init_cmds[] = { + + 1, + 0x3A, + 0x05, + + 2, + 0xB0, + 0x00, + 0xF0, + + 5, + 0xB2, + 0x0C, + 0x0C, + 0x00, + 0x33, + 0x33, + + 1, + 0xB7, + 0x35, + + 1, + 0xBB, + 0x19, + + 1, + 0xC0, + 0x2C, + + 1, + 0xC2, + 0x01, + + 1, + 0xC3, + 0x12, + + 1, + 0xC4, + 0x20, + + 1, + 0xC6, + 0x0F, + + 2, + 0xD0, + 0xA4, + 0xA1, + + 14, + 0xE0, + 0xD0, + 0x04, + 0x0D, + 0x11, + 0x13, + 0x2B, + 0x3F, + 0x54, + 0x4C, + 0x18, + 0x0D, + 0x0B, + 0x1F, + 0x23, + + 14, + 0xE1, + 0xD0, + 0x04, + 0x0C, + 0x11, + 0x13, + 0x2C, + 0x3F, + 0x44, + 0x51, + 0x2F, + 0x1F, + 0x1F, + 0x20, + 0x23, + + 0, + 0x21, + + 1, + 0x36, +#if USE_HORIZONTAL == 0 + 0, +#elif USE_HORIZONTAL == 1 + (1 << 7) | (1 << 6) | (0 << 5), +#elif USE_HORIZONTAL == 2 + (1 << 6) | (0 << 7) | (1 << 5), +#elif USE_HORIZONTAL == 3 + (1 << 7) | (1 << 5), +#endif + + 0, + 0x11, + + 0, + 0x29, + + 0xff, + 0xff, +}; + +void LCD_exec_init(uint8_t* init_code) +{ + uint8_t* p = init_code; + + uint8_t data_len; + uint8_t cmd; + + LCD_CS_CLR(); + while (1) + { + data_len = *p++; + cmd = *p++; + + if (cmd == 0xFF) + { + break; + } + + LCD_WR_REG(cmd); + + for (uint8_t i = 0; i < data_len; i++) + { + LCD_WR_DATA(*p++); + } + } + LCD_CS_SET(); +} + +void LCD_Init(void) +{ + + SPI2_Init(); + SPI2_DMA_Init(); + LCD_GPIOInit(); + + LCD_RESET(); + + LCD_CS_CLR(); + + LCD_WR_REG(0x28); + + LCD_exec_init((uint8_t*)lcd_st7789_init_cmds); + + Delay_Ms(10); + + LCD_Clear(LCD_BLACK); + + Delay_Ms(10); + LCD_LED_SET(); +} + +/********************************************************************* + * @fn LCD_SetWindows + * + * @brief Setting LCD display window + * + * @param xStar - the bebinning x coordinate of the LCD display window + * yStar - the bebinning y coordinate of the LCD display window + * xEnd - the endning x coordinate of the LCD display window + * yEnd - the endning y coordinate of the LCD display window + * + * @return none + */ +void LCD_SetWindows(uint16_t xStar, uint16_t yStar, uint16_t xEnd, uint16_t yEnd) +{ + LCD_CS_CLR(); + LCD_WR_REG(LCD_SET_X); + LCD_WR_DATA(xStar >> 8); + LCD_WR_DATA(0x00FF & xStar); + LCD_WR_DATA(xEnd >> 8); + LCD_WR_DATA(0x00FF & xEnd); + + LCD_WR_REG(LCD_SET_Y); + LCD_WR_DATA(yStar >> 8); + LCD_WR_DATA(0x00FF & yStar); + LCD_WR_DATA(yEnd >> 8); + LCD_WR_DATA(0x00FF & yEnd); + LCD_WR_REG(LCD_MEM_WRITE); + + LCD_CS_SET(); +} + +// 设置引脚为高电平 +void LCD_LED_SET(void) +{ + LCD_LED_PORT->BSHR = LCD_LED_PIN; +} + +void LCD_CS_SET(void) +{ + LCD_CS_PORT->BSHR = LCD_CS_PIN; +} + +void LCD_DC_SET(void) +{ + LCD_DC_PORT->BSHR = LCD_DC_PIN; +} + +void LCD_RST_SET(void) +{ + LCD_RST_PORT->BSHR = LCD_RST_PIN; +} + +// 设置引脚为低电平 +void LCD_LED_CLR(void) +{ + LCD_LED_PORT->BCR = LCD_LED_PIN; +} + +void LCD_CS_CLR(void) +{ + LCD_CS_PORT->BCR = LCD_CS_PIN; +} + +void LCD_DC_CLR(void) +{ + LCD_DC_PORT->BCR = LCD_DC_PIN; +} + +void LCD_RST_CLR(void) +{ + LCD_RST_PORT->BCR = LCD_RST_PIN; +} + +void SPI1_wait_for_bsy() +{ + while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET) + ; +} + +void SPI2_wait_for_bsy() +{ + while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_BSY) == SET) + ; +} + +void SPI2_wait_for_txe() +{ + while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET) + ; +} + +void SPI1_wait_for_DMA() +{ + while (SPI1_DMA_TX_CH->CNTR > 0) + { + } +} + +void SPI2_wait_for_DMA() +{ + while (SPI2_DMA_TX_CH->CNTR > 0) + { + } +} + + +void LCD_Clear(uint16_t color) +{ + LCD_Fill(0, 0, LCD_W, LCD_H, color); +} + + \ No newline at end of file diff --git a/EVT/EXAM/APPLICATION/WUI/User/Drivers/LCD.h b/EVT/EXAM/APPLICATION/WUI/User/Drivers/LCD.h new file mode 100644 index 0000000..a7683fd --- /dev/null +++ b/EVT/EXAM/APPLICATION/WUI/User/Drivers/LCD.h @@ -0,0 +1,84 @@ +/********************************************************************* + * File Name : lcd.h + * Author : WCH + * Version : V1.0.0 + * Date : 2023/8/15 + * Description : file for lcd screen. + ********************************************************************************* +* Copyright (c) 2023 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ + +#ifndef __LCD_H +#define __LCD_H +#include "spi.h" +#include "stdio.h" +#include "stdlib.h" +#include "flash.h" +#include "config.h" + +#define USE_HORIZONTAL 2 + +#if USE_HORIZONTAL == 0 || USE_HORIZONTAL == 1 +#define LCD_W 240 +#define LCD_H 320 +#endif + +#if USE_HORIZONTAL == 2 || USE_HORIZONTAL == 3 +#define LCD_W 320 +#define LCD_H 240 +#endif + +#define LCD_WIDTH LCD_W +#define LCD_HEIGHT LCD_H + +#define LCD_SWAP16(x) ((((x) & 0xFF) << 8) | (((x) >> 8) & 0xFF)) + +#define RGB888_TO_RGB565(r, g, b) LCD_SWAP16((((r) & 0xF8) << 8) | (((g) & 0xFC) << 3) | (((b) & 0xF8) >> 3)) + +#define RGB24_TO_RGB565(rgb) LCD_SWAP16((((rgb) >> 8) & 0xF800) | (((rgb) >> 5) & 0x07E0) | (((rgb) >> 3) & 0x001F)) + +#define LCD_red RGB888_TO_RGB565(255, 0, 0) +#define LCD_green RGB888_TO_RGB565(0, 255, 0) +#define LCD_blue RGB888_TO_RGB565(0, 0, 255) +#define LCD_white RGB888_TO_RGB565(255, 255, 255) +#define LCD_gray RGB888_TO_RGB565(128, 128, 128) +#define LCD_black RGB888_TO_RGB565(0, 0, 0) +#define LCD_yellow RGB888_TO_RGB565(255, 255, 0) + +#define LCD_WHITE LCD_white +#define LCD_BLACK LCD_black +#define LCD_BLUE LCD_blue +#define LCD_RED LCD_red +#define LCD_MAGENTA RGB888_TO_RGB565(255, 0, 255) +#define LCD_GREEN LCD_green +#define LCD_CYAN RGB888_TO_RGB565(0, 255, 255) +#define LCD_YELLOW LCD_yellow +#define LCD_BROWN RGB888_TO_RGB565(165, 42, 42) +#define LCD_GRAY LCD_gray + +void LCD_LED_SET(void); +void LCD_CS_SET(void); +void LCD_DC_SET(void); +void LCD_RST_SET(void); + +void LCD_LED_CLR(void); +void LCD_CS_CLR(void); +void LCD_DC_CLR(void); +void LCD_RST_CLR(void); + +void SPI1_wait_for_bsy(); +void SPI2_wait_for_bsy(); +void SPI2_wait_for_txe(); +void SPI1_wait_for_DMA(); +void SPI2_wait_for_DMA(); + +void LCD_Init(void); +void LCD_Clear(uint16_t Color); + +void Lcd_WriteData_16Bit(uint16_t Data); +void LCD_SetWindows(uint16_t xStar, uint16_t yStar, uint16_t xEnd, uint16_t yEnd); +void LCD_Fill(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t Color); + +#endif diff --git a/EVT/EXAM/APPLICATION/WUI/User/Drivers/LCD_Font.c b/EVT/EXAM/APPLICATION/WUI/User/Drivers/LCD_Font.c new file mode 100644 index 0000000..a268f39 --- /dev/null +++ b/EVT/EXAM/APPLICATION/WUI/User/Drivers/LCD_Font.c @@ -0,0 +1,200 @@ +#include "LCD_Font.h" +#include "wui.h" + +//12*12 +const unsigned char asc2_1206[95][12]={ +{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*" ",0*/ +{0x00,0x00,0x00,0x00,0x3F,0x40,0x00,0x00,0x00,0x00,0x00,0x00},/*"!",1*/ +{0x00,0x00,0x30,0x00,0x40,0x00,0x30,0x00,0x40,0x00,0x00,0x00},/*""",2*/ +{0x09,0x00,0x0B,0xC0,0x3D,0x00,0x0B,0xC0,0x3D,0x00,0x09,0x00},/*"#",3*/ +{0x18,0xC0,0x24,0x40,0x7F,0xE0,0x22,0x40,0x31,0x80,0x00,0x00},/*"$",4*/ +{0x18,0x00,0x24,0xC0,0x1B,0x00,0x0D,0x80,0x32,0x40,0x01,0x80},/*"%",5*/ +{0x03,0x80,0x1C,0x40,0x27,0x40,0x1C,0x80,0x07,0x40,0x00,0x40},/*"&",6*/ +{0x10,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"'",7*/ +{0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x80,0x20,0x40,0x40,0x20},/*"(",8*/ +{0x00,0x00,0x40,0x20,0x20,0x40,0x1F,0x80,0x00,0x00,0x00,0x00},/*")",9*/ +{0x09,0x00,0x06,0x00,0x1F,0x80,0x06,0x00,0x09,0x00,0x00,0x00},/*"*",10*/ +{0x04,0x00,0x04,0x00,0x3F,0x80,0x04,0x00,0x04,0x00,0x00,0x00},/*"+",11*/ +{0x00,0x10,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*",",12*/ +{0x04,0x00,0x04,0x00,0x04,0x00,0x04,0x00,0x04,0x00,0x00,0x00},/*"-",13*/ +{0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*".",14*/ +{0x00,0x20,0x01,0xC0,0x06,0x00,0x38,0x00,0x40,0x00,0x00,0x00},/*"/",15*/ +{0x1F,0x80,0x20,0x40,0x20,0x40,0x20,0x40,0x1F,0x80,0x00,0x00},/*"0",16*/ +{0x00,0x00,0x10,0x40,0x3F,0xC0,0x00,0x40,0x00,0x00,0x00,0x00},/*"1",17*/ +{0x18,0xC0,0x21,0x40,0x22,0x40,0x24,0x40,0x18,0x40,0x00,0x00},/*"2",18*/ +{0x10,0x80,0x20,0x40,0x24,0x40,0x24,0x40,0x1B,0x80,0x00,0x00},/*"3",19*/ +{0x02,0x00,0x0D,0x00,0x11,0x00,0x3F,0xC0,0x01,0x40,0x00,0x00},/*"4",20*/ +{0x3C,0x80,0x24,0x40,0x24,0x40,0x24,0x40,0x23,0x80,0x00,0x00},/*"5",21*/ +{0x1F,0x80,0x24,0x40,0x24,0x40,0x34,0x40,0x03,0x80,0x00,0x00},/*"6",22*/ +{0x30,0x00,0x20,0x00,0x27,0xC0,0x38,0x00,0x20,0x00,0x00,0x00},/*"7",23*/ +{0x1B,0x80,0x24,0x40,0x24,0x40,0x24,0x40,0x1B,0x80,0x00,0x00},/*"8",24*/ +{0x1C,0x00,0x22,0xC0,0x22,0x40,0x22,0x40,0x1F,0x80,0x00,0x00},/*"9",25*/ +{0x00,0x00,0x00,0x00,0x08,0x40,0x00,0x00,0x00,0x00,0x00,0x00},/*":",26*/ +{0x00,0x00,0x00,0x00,0x04,0x60,0x00,0x00,0x00,0x00,0x00,0x00},/*";",27*/ +{0x00,0x00,0x04,0x00,0x0A,0x00,0x11,0x00,0x20,0x80,0x40,0x40},/*"<",28*/ +{0x09,0x00,0x09,0x00,0x09,0x00,0x09,0x00,0x09,0x00,0x00,0x00},/*"=",29*/ +{0x00,0x00,0x40,0x40,0x20,0x80,0x11,0x00,0x0A,0x00,0x04,0x00},/*">",30*/ +{0x18,0x00,0x20,0x00,0x23,0x40,0x24,0x00,0x18,0x00,0x00,0x00},/*"?",31*/ +{0x1F,0x80,0x20,0x40,0x27,0x40,0x29,0x40,0x1F,0x40,0x00,0x00},/*"@",32*/ +{0x00,0x40,0x07,0xC0,0x39,0x00,0x0F,0x00,0x01,0xC0,0x00,0x40},/*"A",33*/ +{0x20,0x40,0x3F,0xC0,0x24,0x40,0x24,0x40,0x1B,0x80,0x00,0x00},/*"B",34*/ +{0x1F,0x80,0x20,0x40,0x20,0x40,0x20,0x40,0x30,0x80,0x00,0x00},/*"C",35*/ +{0x20,0x40,0x3F,0xC0,0x20,0x40,0x20,0x40,0x1F,0x80,0x00,0x00},/*"D",36*/ +{0x20,0x40,0x3F,0xC0,0x24,0x40,0x2E,0x40,0x30,0xC0,0x00,0x00},/*"E",37*/ +{0x20,0x40,0x3F,0xC0,0x24,0x40,0x2E,0x00,0x30,0x00,0x00,0x00},/*"F",38*/ +{0x0F,0x00,0x10,0x80,0x20,0x40,0x22,0x40,0x33,0x80,0x02,0x00},/*"G",39*/ +{0x20,0x40,0x3F,0xC0,0x04,0x00,0x04,0x00,0x3F,0xC0,0x20,0x40},/*"H",40*/ +{0x20,0x40,0x20,0x40,0x3F,0xC0,0x20,0x40,0x20,0x40,0x00,0x00},/*"I",41*/ +{0x00,0x60,0x20,0x20,0x20,0x20,0x3F,0xC0,0x20,0x00,0x20,0x00},/*"J",42*/ +{0x20,0x40,0x3F,0xC0,0x24,0x40,0x0B,0x00,0x30,0xC0,0x20,0x40},/*"K",43*/ +{0x20,0x40,0x3F,0xC0,0x20,0x40,0x00,0x40,0x00,0x40,0x00,0xC0},/*"L",44*/ +{0x3F,0xC0,0x3C,0x00,0x03,0xC0,0x3C,0x00,0x3F,0xC0,0x00,0x00},/*"M",45*/ +{0x20,0x40,0x3F,0xC0,0x0C,0x40,0x23,0x00,0x3F,0xC0,0x20,0x00},/*"N",46*/ +{0x1F,0x80,0x20,0x40,0x20,0x40,0x20,0x40,0x1F,0x80,0x00,0x00},/*"O",47*/ +{0x20,0x40,0x3F,0xC0,0x24,0x40,0x24,0x00,0x18,0x00,0x00,0x00},/*"P",48*/ +{0x1F,0x80,0x21,0x40,0x21,0x40,0x20,0xE0,0x1F,0xA0,0x00,0x00},/*"Q",49*/ +{0x20,0x40,0x3F,0xC0,0x24,0x40,0x26,0x00,0x19,0xC0,0x00,0x40},/*"R",50*/ +{0x18,0xC0,0x24,0x40,0x24,0x40,0x22,0x40,0x31,0x80,0x00,0x00},/*"S",51*/ +{0x30,0x00,0x20,0x40,0x3F,0xC0,0x20,0x40,0x30,0x00,0x00,0x00},/*"T",52*/ +{0x20,0x00,0x3F,0x80,0x00,0x40,0x00,0x40,0x3F,0x80,0x20,0x00},/*"U",53*/ +{0x20,0x00,0x3E,0x00,0x01,0xC0,0x07,0x00,0x38,0x00,0x20,0x00},/*"V",54*/ +{0x38,0x00,0x07,0xC0,0x3C,0x00,0x07,0xC0,0x38,0x00,0x00,0x00},/*"W",55*/ +{0x20,0x40,0x39,0xC0,0x06,0x00,0x39,0xC0,0x20,0x40,0x00,0x00},/*"X",56*/ +{0x20,0x00,0x38,0x40,0x07,0xC0,0x38,0x40,0x20,0x00,0x00,0x00},/*"Y",57*/ +{0x30,0x40,0x21,0xC0,0x26,0x40,0x38,0x40,0x20,0xC0,0x00,0x00},/*"Z",58*/ +{0x00,0x00,0x00,0x00,0x7F,0xE0,0x40,0x20,0x40,0x20,0x00,0x00},/*"[",59*/ +{0x00,0x00,0x70,0x00,0x0C,0x00,0x03,0x80,0x00,0x40,0x00,0x00},/*"\",60*/ +{0x00,0x00,0x40,0x20,0x40,0x20,0x7F,0xE0,0x00,0x00,0x00,0x00},/*"]",61*/ +{0x00,0x00,0x20,0x00,0x40,0x00,0x20,0x00,0x00,0x00,0x00,0x00},/*"^",62*/ +{0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10},/*"_",63*/ +{0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"`",64*/ +{0x00,0x00,0x02,0x80,0x05,0x40,0x05,0x40,0x03,0xC0,0x00,0x40},/*"a",65*/ +{0x20,0x00,0x3F,0xC0,0x04,0x40,0x04,0x40,0x03,0x80,0x00,0x00},/*"b",66*/ +{0x00,0x00,0x03,0x80,0x04,0x40,0x04,0x40,0x06,0x40,0x00,0x00},/*"c",67*/ +{0x00,0x00,0x03,0x80,0x04,0x40,0x24,0x40,0x3F,0xC0,0x00,0x40},/*"d",68*/ +{0x00,0x00,0x03,0x80,0x05,0x40,0x05,0x40,0x03,0x40,0x00,0x00},/*"e",69*/ +{0x00,0x00,0x04,0x40,0x1F,0xC0,0x24,0x40,0x24,0x40,0x20,0x00},/*"f",70*/ +{0x00,0x00,0x02,0xE0,0x05,0x50,0x05,0x50,0x06,0x50,0x04,0x20},/*"g",71*/ +{0x20,0x40,0x3F,0xC0,0x04,0x40,0x04,0x00,0x03,0xC0,0x00,0x40},/*"h",72*/ +{0x00,0x00,0x04,0x40,0x27,0xC0,0x00,0x40,0x00,0x00,0x00,0x00},/*"i",73*/ +{0x00,0x10,0x00,0x10,0x04,0x10,0x27,0xE0,0x00,0x00,0x00,0x00},/*"j",74*/ +{0x20,0x40,0x3F,0xC0,0x01,0x40,0x07,0x00,0x04,0xC0,0x04,0x40},/*"k",75*/ +{0x20,0x40,0x20,0x40,0x3F,0xC0,0x00,0x40,0x00,0x40,0x00,0x00},/*"l",76*/ +{0x07,0xC0,0x04,0x00,0x07,0xC0,0x04,0x00,0x03,0xC0,0x00,0x00},/*"m",77*/ +{0x04,0x40,0x07,0xC0,0x04,0x40,0x04,0x00,0x03,0xC0,0x00,0x40},/*"n",78*/ +{0x00,0x00,0x03,0x80,0x04,0x40,0x04,0x40,0x03,0x80,0x00,0x00},/*"o",79*/ +{0x04,0x10,0x07,0xF0,0x04,0x50,0x04,0x40,0x03,0x80,0x00,0x00},/*"p",80*/ +{0x00,0x00,0x03,0x80,0x04,0x40,0x04,0x50,0x07,0xF0,0x00,0x10},/*"q",81*/ +{0x04,0x40,0x07,0xC0,0x02,0x40,0x04,0x00,0x04,0x00,0x00,0x00},/*"r",82*/ +{0x00,0x00,0x06,0x40,0x05,0x40,0x05,0x40,0x04,0xC0,0x00,0x00},/*"s",83*/ +{0x00,0x00,0x04,0x00,0x1F,0x80,0x04,0x40,0x00,0x40,0x00,0x00},/*"t",84*/ +{0x04,0x00,0x07,0x80,0x00,0x40,0x04,0x40,0x07,0xC0,0x00,0x40},/*"u",85*/ +{0x04,0x00,0x07,0x00,0x04,0xC0,0x01,0x80,0x06,0x00,0x04,0x00},/*"v",86*/ +{0x06,0x00,0x01,0xC0,0x07,0x00,0x01,0xC0,0x06,0x00,0x00,0x00},/*"w",87*/ +{0x04,0x40,0x06,0xC0,0x01,0x00,0x06,0xC0,0x04,0x40,0x00,0x00},/*"x",88*/ +{0x04,0x10,0x07,0x10,0x04,0xE0,0x01,0x80,0x06,0x00,0x04,0x00},/*"y",89*/ +{0x00,0x00,0x04,0x40,0x05,0xC0,0x06,0x40,0x04,0x40,0x00,0x00},/*"z",90*/ +{0x00,0x00,0x00,0x00,0x04,0x00,0x7B,0xE0,0x40,0x20,0x00,0x00},/*"{",91*/ +{0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xF0,0x00,0x00,0x00,0x00},/*"|",92*/ +{0x00,0x00,0x40,0x20,0x7B,0xE0,0x04,0x00,0x00,0x00,0x00,0x00},/*"}",93*/ +{0x40,0x00,0x80,0x00,0x40,0x00,0x20,0x00,0x20,0x00,0x40,0x00},/*"~",94*/ +}; + +//16*16 +const unsigned char asc2_1608[95][16]={ +{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*" ",0*/ +{0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xCC,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00},/*"!",1*/ +{0x00,0x00,0x08,0x00,0x30,0x00,0x60,0x00,0x08,0x00,0x30,0x00,0x60,0x00,0x00,0x00},/*""",2*/ +{0x02,0x20,0x03,0xFC,0x1E,0x20,0x02,0x20,0x03,0xFC,0x1E,0x20,0x02,0x20,0x00,0x00},/*"#",3*/ +{0x00,0x00,0x0E,0x18,0x11,0x04,0x3F,0xFF,0x10,0x84,0x0C,0x78,0x00,0x00,0x00,0x00},/*"$",4*/ +{0x0F,0x00,0x10,0x84,0x0F,0x38,0x00,0xC0,0x07,0x78,0x18,0x84,0x00,0x78,0x00,0x00},/*"%",5*/ +{0x00,0x78,0x0F,0x84,0x10,0xC4,0x11,0x24,0x0E,0x98,0x00,0xE4,0x00,0x84,0x00,0x08},/*"&",6*/ +{0x08,0x00,0x68,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"'",7*/ +{0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xE0,0x18,0x18,0x20,0x04,0x40,0x02,0x00,0x00},/*"(",8*/ +{0x00,0x00,0x40,0x02,0x20,0x04,0x18,0x18,0x07,0xE0,0x00,0x00,0x00,0x00,0x00,0x00},/*")",9*/ +{0x02,0x40,0x02,0x40,0x01,0x80,0x0F,0xF0,0x01,0x80,0x02,0x40,0x02,0x40,0x00,0x00},/*"*",10*/ +{0x00,0x80,0x00,0x80,0x00,0x80,0x0F,0xF8,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x00},/*"+",11*/ +{0x00,0x01,0x00,0x0D,0x00,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*",",12*/ +{0x00,0x00,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80},/*"-",13*/ +{0x00,0x00,0x00,0x0C,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*".",14*/ +{0x00,0x00,0x00,0x06,0x00,0x18,0x00,0x60,0x01,0x80,0x06,0x00,0x18,0x00,0x20,0x00},/*"/",15*/ +{0x00,0x00,0x07,0xF0,0x08,0x08,0x10,0x04,0x10,0x04,0x08,0x08,0x07,0xF0,0x00,0x00},/*"0",16*/ +{0x00,0x00,0x08,0x04,0x08,0x04,0x1F,0xFC,0x00,0x04,0x00,0x04,0x00,0x00,0x00,0x00},/*"1",17*/ +{0x00,0x00,0x0E,0x0C,0x10,0x14,0x10,0x24,0x10,0x44,0x11,0x84,0x0E,0x0C,0x00,0x00},/*"2",18*/ +{0x00,0x00,0x0C,0x18,0x10,0x04,0x11,0x04,0x11,0x04,0x12,0x88,0x0C,0x70,0x00,0x00},/*"3",19*/ +{0x00,0x00,0x00,0xE0,0x03,0x20,0x04,0x24,0x08,0x24,0x1F,0xFC,0x00,0x24,0x00,0x00},/*"4",20*/ +{0x00,0x00,0x1F,0x98,0x10,0x84,0x11,0x04,0x11,0x04,0x10,0x88,0x10,0x70,0x00,0x00},/*"5",21*/ +{0x00,0x00,0x07,0xF0,0x08,0x88,0x11,0x04,0x11,0x04,0x18,0x88,0x00,0x70,0x00,0x00},/*"6",22*/ +{0x00,0x00,0x1C,0x00,0x10,0x00,0x10,0xFC,0x13,0x00,0x1C,0x00,0x10,0x00,0x00,0x00},/*"7",23*/ +{0x00,0x00,0x0E,0x38,0x11,0x44,0x10,0x84,0x10,0x84,0x11,0x44,0x0E,0x38,0x00,0x00},/*"8",24*/ +{0x00,0x00,0x07,0x00,0x08,0x8C,0x10,0x44,0x10,0x44,0x08,0x88,0x07,0xF0,0x00,0x00},/*"9",25*/ +{0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x0C,0x03,0x0C,0x00,0x00,0x00,0x00,0x00,0x00},/*":",26*/ +{0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*";",27*/ +{0x00,0x00,0x00,0x80,0x01,0x40,0x02,0x20,0x04,0x10,0x08,0x08,0x10,0x04,0x00,0x00},/*"<",28*/ +{0x02,0x20,0x02,0x20,0x02,0x20,0x02,0x20,0x02,0x20,0x02,0x20,0x02,0x20,0x00,0x00},/*"=",29*/ +{0x00,0x00,0x10,0x04,0x08,0x08,0x04,0x10,0x02,0x20,0x01,0x40,0x00,0x80,0x00,0x00},/*">",30*/ +{0x00,0x00,0x0E,0x00,0x12,0x00,0x10,0x0C,0x10,0x6C,0x10,0x80,0x0F,0x00,0x00,0x00},/*"?",31*/ +{0x03,0xE0,0x0C,0x18,0x13,0xE4,0x14,0x24,0x17,0xC4,0x08,0x28,0x07,0xD0,0x00,0x00},/*"@",32*/ +{0x00,0x04,0x00,0x3C,0x03,0xC4,0x1C,0x40,0x07,0x40,0x00,0xE4,0x00,0x1C,0x00,0x04},/*"A",33*/ +{0x10,0x04,0x1F,0xFC,0x11,0x04,0x11,0x04,0x11,0x04,0x0E,0x88,0x00,0x70,0x00,0x00},/*"B",34*/ +{0x03,0xE0,0x0C,0x18,0x10,0x04,0x10,0x04,0x10,0x04,0x10,0x08,0x1C,0x10,0x00,0x00},/*"C",35*/ +{0x10,0x04,0x1F,0xFC,0x10,0x04,0x10,0x04,0x10,0x04,0x08,0x08,0x07,0xF0,0x00,0x00},/*"D",36*/ +{0x10,0x04,0x1F,0xFC,0x11,0x04,0x11,0x04,0x17,0xC4,0x10,0x04,0x08,0x18,0x00,0x00},/*"E",37*/ +{0x10,0x04,0x1F,0xFC,0x11,0x04,0x11,0x00,0x17,0xC0,0x10,0x00,0x08,0x00,0x00,0x00},/*"F",38*/ +{0x03,0xE0,0x0C,0x18,0x10,0x04,0x10,0x04,0x10,0x44,0x1C,0x78,0x00,0x40,0x00,0x00},/*"G",39*/ +{0x10,0x04,0x1F,0xFC,0x10,0x84,0x00,0x80,0x00,0x80,0x10,0x84,0x1F,0xFC,0x10,0x04},/*"H",40*/ +{0x00,0x00,0x10,0x04,0x10,0x04,0x1F,0xFC,0x10,0x04,0x10,0x04,0x00,0x00,0x00,0x00},/*"I",41*/ +{0x00,0x03,0x00,0x01,0x10,0x01,0x10,0x01,0x1F,0xFE,0x10,0x00,0x10,0x00,0x00,0x00},/*"J",42*/ +{0x10,0x04,0x1F,0xFC,0x11,0x04,0x03,0x80,0x14,0x64,0x18,0x1C,0x10,0x04,0x00,0x00},/*"K",43*/ +{0x10,0x04,0x1F,0xFC,0x10,0x04,0x00,0x04,0x00,0x04,0x00,0x04,0x00,0x0C,0x00,0x00},/*"L",44*/ +{0x10,0x04,0x1F,0xFC,0x1F,0x00,0x00,0xFC,0x1F,0x00,0x1F,0xFC,0x10,0x04,0x00,0x00},/*"M",45*/ +{0x10,0x04,0x1F,0xFC,0x0C,0x04,0x03,0x00,0x00,0xE0,0x10,0x18,0x1F,0xFC,0x10,0x00},/*"N",46*/ +{0x07,0xF0,0x08,0x08,0x10,0x04,0x10,0x04,0x10,0x04,0x08,0x08,0x07,0xF0,0x00,0x00},/*"O",47*/ +{0x10,0x04,0x1F,0xFC,0x10,0x84,0x10,0x80,0x10,0x80,0x10,0x80,0x0F,0x00,0x00,0x00},/*"P",48*/ +{0x07,0xF0,0x08,0x18,0x10,0x24,0x10,0x24,0x10,0x1C,0x08,0x0A,0x07,0xF2,0x00,0x00},/*"Q",49*/ +{0x10,0x04,0x1F,0xFC,0x11,0x04,0x11,0x00,0x11,0xC0,0x11,0x30,0x0E,0x0C,0x00,0x04},/*"R",50*/ +{0x00,0x00,0x0E,0x1C,0x11,0x04,0x10,0x84,0x10,0x84,0x10,0x44,0x1C,0x38,0x00,0x00},/*"S",51*/ +{0x18,0x00,0x10,0x00,0x10,0x04,0x1F,0xFC,0x10,0x04,0x10,0x00,0x18,0x00,0x00,0x00},/*"T",52*/ +{0x10,0x00,0x1F,0xF8,0x10,0x04,0x00,0x04,0x00,0x04,0x10,0x04,0x1F,0xF8,0x10,0x00},/*"U",53*/ +{0x10,0x00,0x1E,0x00,0x11,0xE0,0x00,0x1C,0x00,0x70,0x13,0x80,0x1C,0x00,0x10,0x00},/*"V",54*/ +{0x1F,0xC0,0x10,0x3C,0x00,0xE0,0x1F,0x00,0x00,0xE0,0x10,0x3C,0x1F,0xC0,0x00,0x00},/*"W",55*/ +{0x10,0x04,0x18,0x0C,0x16,0x34,0x01,0xC0,0x01,0xC0,0x16,0x34,0x18,0x0C,0x10,0x04},/*"X",56*/ +{0x10,0x00,0x1C,0x00,0x13,0x04,0x00,0xFC,0x13,0x04,0x1C,0x00,0x10,0x00,0x00,0x00},/*"Y",57*/ +{0x08,0x04,0x10,0x1C,0x10,0x64,0x10,0x84,0x13,0x04,0x1C,0x04,0x10,0x18,0x00,0x00},/*"Z",58*/ +{0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFE,0x40,0x02,0x40,0x02,0x40,0x02,0x00,0x00},/*"[",59*/ +{0x00,0x00,0x30,0x00,0x0C,0x00,0x03,0x80,0x00,0x60,0x00,0x1C,0x00,0x03,0x00,0x00},/*"\",60*/ +{0x00,0x00,0x40,0x02,0x40,0x02,0x40,0x02,0x7F,0xFE,0x00,0x00,0x00,0x00,0x00,0x00},/*"]",61*/ +{0x00,0x00,0x00,0x00,0x20,0x00,0x40,0x00,0x40,0x00,0x40,0x00,0x20,0x00,0x00,0x00},/*"^",62*/ +{0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01},/*"_",63*/ +{0x00,0x00,0x40,0x00,0x40,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"`",64*/ +{0x00,0x00,0x00,0x98,0x01,0x24,0x01,0x44,0x01,0x44,0x01,0x44,0x00,0xFC,0x00,0x04},/*"a",65*/ +{0x10,0x00,0x1F,0xFC,0x00,0x88,0x01,0x04,0x01,0x04,0x00,0x88,0x00,0x70,0x00,0x00},/*"b",66*/ +{0x00,0x00,0x00,0x70,0x00,0x88,0x01,0x04,0x01,0x04,0x01,0x04,0x00,0x88,0x00,0x00},/*"c",67*/ +{0x00,0x00,0x00,0x70,0x00,0x88,0x01,0x04,0x01,0x04,0x11,0x08,0x1F,0xFC,0x00,0x04},/*"d",68*/ +{0x00,0x00,0x00,0xF8,0x01,0x44,0x01,0x44,0x01,0x44,0x01,0x44,0x00,0xC8,0x00,0x00},/*"e",69*/ +{0x00,0x00,0x01,0x04,0x01,0x04,0x0F,0xFC,0x11,0x04,0x11,0x04,0x11,0x00,0x18,0x00},/*"f",70*/ +{0x00,0x00,0x00,0xD6,0x01,0x29,0x01,0x29,0x01,0x29,0x01,0xC9,0x01,0x06,0x00,0x00},/*"g",71*/ +{0x10,0x04,0x1F,0xFC,0x00,0x84,0x01,0x00,0x01,0x00,0x01,0x04,0x00,0xFC,0x00,0x04},/*"h",72*/ +{0x00,0x00,0x01,0x04,0x19,0x04,0x19,0xFC,0x00,0x04,0x00,0x04,0x00,0x00,0x00,0x00},/*"i",73*/ +{0x00,0x00,0x00,0x03,0x00,0x01,0x01,0x01,0x19,0x01,0x19,0xFE,0x00,0x00,0x00,0x00},/*"j",74*/ +{0x10,0x04,0x1F,0xFC,0x00,0x24,0x00,0x40,0x01,0xB4,0x01,0x0C,0x01,0x04,0x00,0x00},/*"k",75*/ +{0x00,0x00,0x10,0x04,0x10,0x04,0x1F,0xFC,0x00,0x04,0x00,0x04,0x00,0x00,0x00,0x00},/*"l",76*/ +{0x01,0x04,0x01,0xFC,0x01,0x04,0x01,0x00,0x01,0xFC,0x01,0x04,0x01,0x00,0x00,0xFC},/*"m",77*/ +{0x01,0x04,0x01,0xFC,0x00,0x84,0x01,0x00,0x01,0x00,0x01,0x04,0x00,0xFC,0x00,0x04},/*"n",78*/ +{0x00,0x00,0x00,0xF8,0x01,0x04,0x01,0x04,0x01,0x04,0x01,0x04,0x00,0xF8,0x00,0x00},/*"o",79*/ +{0x01,0x01,0x01,0xFF,0x00,0x85,0x01,0x04,0x01,0x04,0x00,0x88,0x00,0x70,0x00,0x00},/*"p",80*/ +{0x00,0x00,0x00,0x70,0x00,0x88,0x01,0x04,0x01,0x04,0x01,0x05,0x01,0xFF,0x00,0x01},/*"q",81*/ +{0x01,0x04,0x01,0x04,0x01,0xFC,0x00,0x84,0x01,0x04,0x01,0x00,0x01,0x80,0x00,0x00},/*"r",82*/ +{0x00,0x00,0x00,0xCC,0x01,0x24,0x01,0x24,0x01,0x24,0x01,0x24,0x01,0x98,0x00,0x00},/*"s",83*/ +{0x00,0x00,0x01,0x00,0x01,0x00,0x07,0xF8,0x01,0x04,0x01,0x04,0x00,0x00,0x00,0x00},/*"t",84*/ +{0x01,0x00,0x01,0xF8,0x00,0x04,0x00,0x04,0x00,0x04,0x01,0x08,0x01,0xFC,0x00,0x04},/*"u",85*/ +{0x01,0x00,0x01,0x80,0x01,0x70,0x00,0x0C,0x00,0x10,0x01,0x60,0x01,0x80,0x01,0x00},/*"v",86*/ +{0x01,0xF0,0x01,0x0C,0x00,0x30,0x01,0xC0,0x00,0x30,0x01,0x0C,0x01,0xF0,0x01,0x00},/*"w",87*/ +{0x00,0x00,0x01,0x04,0x01,0x8C,0x00,0x74,0x01,0x70,0x01,0x8C,0x01,0x04,0x00,0x00},/*"x",88*/ +{0x01,0x01,0x01,0x81,0x01,0x71,0x00,0x0E,0x00,0x18,0x01,0x60,0x01,0x80,0x01,0x00},/*"y",89*/ +{0x00,0x00,0x01,0x84,0x01,0x0C,0x01,0x34,0x01,0x44,0x01,0x84,0x01,0x0C,0x00,0x00},/*"z",90*/ +{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x3E,0xFC,0x40,0x02,0x40,0x02},/*"{",91*/ +{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00},/*"|",92*/ +{0x00,0x00,0x40,0x02,0x40,0x02,0x3E,0xFC,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"}",93*/ +{0x00,0x00,0x60,0x00,0x80,0x00,0x80,0x00,0x40,0x00,0x40,0x00,0x20,0x00,0x20,0x00},/*"~",94*/ +}; diff --git a/EVT/EXAM/APPLICATION/WUI/User/Drivers/LCD_Font.h b/EVT/EXAM/APPLICATION/WUI/User/Drivers/LCD_Font.h new file mode 100644 index 0000000..fe8fda8 --- /dev/null +++ b/EVT/EXAM/APPLICATION/WUI/User/Drivers/LCD_Font.h @@ -0,0 +1,18 @@ +/********************************** (C) COPYRIGHT ******************************* +* File Name : lcd_font.h +* Author : WCH +* Version : V1.0.1 +* Date : 2025/09/15 +* Description : ASCII character library. +********************************************************************************* +* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ +#ifndef __LCD_FONT_H +#define __LCD_FONT_H + +extern const unsigned char asc2_1206[95][12]; +extern const unsigned char asc2_1608[95][16]; + +#endif diff --git a/EVT/EXAM/APPLICATION/WUI/User/Drivers/config.h b/EVT/EXAM/APPLICATION/WUI/User/Drivers/config.h new file mode 100644 index 0000000..f40053a --- /dev/null +++ b/EVT/EXAM/APPLICATION/WUI/User/Drivers/config.h @@ -0,0 +1,36 @@ +/********************************************************************* + * File Name : config.h + * Author : WCH + * Version : V1.0.0 + * Date : 2023/8/15 + * Description : file for Config. + ********************************************************************************* +* Copyright (c) 2023 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ +#ifndef __CONFIG_H__ +#define __CONFIG_H__ + +/* SPI FLASH and LCD_SCREEN GPIO Definition */ +#define FLASH_CS_PORT GPIOA +#define FLASH_CS_RCC RCC_APB2Periph_GPIOA +#define FLASH_CS_PIN (GPIO_Pin_4) + +#define LCD_LED_RCC RCC_APB2Periph_GPIOB +#define LCD_LED_PORT GPIOB +#define LCD_LED_PIN (GPIO_Pin_9) + +#define LCD_DC_RCC RCC_APB2Periph_GPIOB +#define LCD_DC_PORT GPIOB +#define LCD_DC_PIN (GPIO_Pin_10) + +#define LCD_RST_RCC RCC_APB2Periph_GPIOB +#define LCD_RST_PORT GPIOB +#define LCD_RST_PIN (GPIO_Pin_11) + +#define LCD_CS_RCC RCC_APB2Periph_GPIOB +#define LCD_CS_PORT GPIOB +#define LCD_CS_PIN (GPIO_Pin_12) + +#endif diff --git a/EVT/EXAM/APPLICATION/WUI/User/Drivers/flash.c b/EVT/EXAM/APPLICATION/WUI/User/Drivers/flash.c new file mode 100644 index 0000000..ae1b67b --- /dev/null +++ b/EVT/EXAM/APPLICATION/WUI/User/Drivers/flash.c @@ -0,0 +1,465 @@ +/********************************************************************* + * File Name : flash.c + * Author : WCH + * Version : V1.0.0 + * Date : 2023/8/15 + * Description : file for spi flash. + ********************************************************************************* +* Copyright (c) 2023 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ +#include "flash.h" +#include "spi.h" + +static uint8_t FLASH_readWrite(uint8_t TxData) +{ + while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET) + ; + SPI_I2S_SendData(SPI1, TxData); + + while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET) + ; + + return SPI_I2S_ReceiveData(SPI1); +} + +/********************************************************************* + * @fn cs_pin_init + * + * @brief gpio cs pin init + * + * @return none + */ +static void cs_pin_init() +{ + GPIO_InitTypeDef GPIO_InitStructure; + RCC_APB2PeriphClockCmd(FLASH_CS_RCC, ENABLE); + GPIO_InitStructure.GPIO_Pin = FLASH_CS_PIN; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; + GPIO_Init(FLASH_CS_PORT, &GPIO_InitStructure); +} + +/********************************************************************* + * @fn SPI_FLASH_Init + * + * @brief SPI FLASH Init + * + * @return none + */ +void SPI_FLASH_Init(void) +{ + SPI1_Init(); + SPI1_Read_DMA_Init(); + cs_pin_init(); + FLASH_CS_SET; +} + +/********************************************************************* + * @fn SPI_Flash_ReadSR + * + * @brief Read W25Qxx status register. + * 锛侊紒BIT7 6 5 4 3 2 1 0 + * 锛侊紒SPR RV TB BP2 BP1 BP0 WEL BUSY + * + * @return byte - status register value. + */ +uint8_t SPI_Flash_ReadSR(void) +{ + uint8_t byte = 0; + + FLASH_CS_CLR; + FLASH_readWrite(W25X_ReadStatusReg); + byte = FLASH_readWrite(0Xff); + FLASH_CS_SET; + + return byte; +} + +/********************************************************************* + * @fn SPI_FLASH_Write_SR + * + * @brief Write W25Qxx status register. + * + * @param sr - status register value. + * + * @return none + */ +void SPI_FLASH_Write_SR(uint8_t sr) +{ + FLASH_CS_CLR; + FLASH_readWrite(W25X_WriteStatusReg); + FLASH_readWrite(sr); + FLASH_CS_SET; +} + +/********************************************************************* + * @fn SPI_Flash_Wait_Busy + * + * @brief Wait flash free. + * + * @return none + */ +void SPI_Flash_Wait_Busy(void) +{ + while ((SPI_Flash_ReadSR() & 0x01) == 0x01) + ; +} + +/********************************************************************* + * @fn SPI_FLASH_Write_Enable + * + * @brief Enable flash write. + * + * @return none + */ +void SPI_FLASH_Write_Enable(void) +{ + FLASH_CS_CLR; + FLASH_readWrite(W25X_WriteEnable); + FLASH_CS_SET; +} + +/********************************************************************* + * @fn SPI_FLASH_Write_Disable + * + * @brief Disable flash write. + * + * @return none + */ +void SPI_FLASH_Write_Disable(void) +{ + FLASH_CS_CLR; + FLASH_readWrite(W25X_WriteDisable); + FLASH_CS_SET; +} + +/********************************************************************* + * @fn SPI_Flash_ReadID + * + * @brief Read flash ID. + * + * @return Temp - FLASH ID. + */ +uint16_t SPI_Flash_ReadID(void) +{ + uint16_t Temp = 0; + + FLASH_CS_CLR; + FLASH_readWrite(W25X_ManufactDeviceID); + FLASH_readWrite(0x00); + FLASH_readWrite(0x00); + FLASH_readWrite(0x00); + Temp |= FLASH_readWrite(0xFF) << 8; + Temp |= FLASH_readWrite(0xFF); + FLASH_CS_SET; + + return Temp; +} + +/********************************************************************* + * @fn SPI_Flash_ReadJedecDeviceID + * + * @brief Read JedecDevice ID. + * + * @return JedecDevice ID. + */ +uint32_t SPI_Flash_ReadJedecDeviceID(void) +{ + uint32_t Temp = 0; + FLASH_CS_CLR; + FLASH_readWrite(W25X_JedecDeviceID); + Temp |= FLASH_readWrite(0xFF) << 16; + Temp |= FLASH_readWrite(0xFF) << 8; + Temp |= FLASH_readWrite(0xFF); + FLASH_CS_SET; + return Temp; +} + +/********************************************************************* + * @fn SPI_Flash_Erase_Sector + * + * @brief Erase one sector(4Kbyte). + * + * @param Dst_Addr - 0 锛侊紒 2047 + * + * @return none + */ +void SPI_Flash_Erase_Sector(uint32_t Dst_Addr) +{ + Dst_Addr *= 4096; + SPI_FLASH_Write_Enable(); + SPI_Flash_Wait_Busy(); + FLASH_CS_CLR; + FLASH_readWrite(W25X_SectorErase); + FLASH_readWrite((uint8_t)((Dst_Addr) >> 16)); + FLASH_readWrite((uint8_t)((Dst_Addr) >> 8)); + FLASH_readWrite((uint8_t)Dst_Addr); + FLASH_CS_SET; + SPI_Flash_Wait_Busy(); +} + +/********************************************************************* + * @fn SPI_Flash_Read + * + * @brief Read data from flash. + * + * @param pBuffer - + * ReadAddr -Initial address(24bit). + * size - Data length. + * + * @return none + */ +void SPI_Flash_Read(uint8_t *pBuffer, uint32_t ReadAddr, uint16_t size) +{ + uint16_t i; + + FLASH_CS_CLR; + FLASH_readWrite(W25X_ReadData); + FLASH_readWrite((uint8_t)((ReadAddr) >> 16)); + FLASH_readWrite((uint8_t)((ReadAddr) >> 8)); + FLASH_readWrite((uint8_t)ReadAddr); + + for (i = 0; i < size; i++) + { + pBuffer[i] = FLASH_readWrite(0XFF); + } + + FLASH_CS_SET; +} + +/********************************************************************* + * @fn SPI_Flash_Write_Page + * + * @brief Write data by one page. + * + * @param pBuffer - + * WriteAddr - Initial address(24bit). + * size - Data length. + * + * @return none + */ +void SPI_Flash_Write_Page(uint8_t *pBuffer, uint32_t WriteAddr, uint16_t size) +{ + uint16_t i; + + SPI_FLASH_Write_Enable(); + FLASH_CS_CLR; + FLASH_readWrite(W25X_PageProgram); + FLASH_readWrite((uint8_t)((WriteAddr) >> 16)); + FLASH_readWrite((uint8_t)((WriteAddr) >> 8)); + FLASH_readWrite((uint8_t)WriteAddr); + + for (i = 0; i < size; i++) + { + FLASH_readWrite(pBuffer[i]); + } + + FLASH_CS_SET; + SPI_Flash_Wait_Busy(); +} + +/********************************************************************* + * @fn SPI_Flash_Write_NoCheck + * + * @brief Write data to flash.(need Erase) + * All data in address rang is 0xFF. + * + * @param pBuffer - + * WriteAddr - Initial address(24bit). + * size - Data length. + * + * @return none + */ +void SPI_Flash_Write_NoCheck(uint8_t *pBuffer, uint32_t WriteAddr, uint16_t size) +{ + uint16_t pageremain; + + pageremain = 256 - WriteAddr % 256; + + if (size <= pageremain) + pageremain = size; + + while (1) + { + SPI_Flash_Write_Page(pBuffer, WriteAddr, pageremain); + + if (size == pageremain) + { + break; + } + else + { + pBuffer += pageremain; + WriteAddr += pageremain; + size -= pageremain; + + if (size > 256) + pageremain = 256; + else + pageremain = size; + } + } +} + +static uint8_t W25QXX_BUFFER[4096]; +/********************************************************************* + * @fn SPI_Flash_Write + * + * @brief Write data to flash.(no need Erase) + * + * @param pBuffer - + * WriteAddr - Initial address(24bit). + * size - Data length. + * + * @return none + */ +void SPI_Flash_Write(uint8_t *pBuffer, uint32_t WriteAddr, uint16_t size) +{ + uint32_t secpos; + uint16_t secoff; + uint16_t secremain; + uint16_t i; + + secpos = WriteAddr / 4096; + secoff = WriteAddr % 4096; + secremain = 4096 - secoff; + + if (size <= secremain) + secremain = size; + + while (1) + { + SPI_Flash_Read(W25QXX_BUFFER, secpos * 4096, 4096); + + for (i = 0; i < secremain; i++) + { + if (W25QXX_BUFFER[secoff + i] != 0XFF) + break; + } + + if (i < secremain) + { + SPI_Flash_Erase_Sector(secpos); + + for (i = 0; i < secremain; i++) + { + W25QXX_BUFFER[i + secoff] = pBuffer[i]; + } + + SPI_Flash_Write_NoCheck(W25QXX_BUFFER, secpos * 4096, 4096); + } + else + { + SPI_Flash_Write_NoCheck(pBuffer, WriteAddr, secremain); + } + + if (size == secremain) + { + break; + } + else + { + secpos++; + secoff = 0; + + pBuffer += secremain; + WriteAddr += secremain; + size -= secremain; + + if (size > 4096) + { + secremain = 4096; + } + else + { + secremain = size; + } + } + } +} + +/********************************************************************* + * @fn SPI_Flash_Erase_Block + * + * @brief Erase all FLASH pages. + * + * + * @return none + */ +void SPI_Flash_Erase_Block(uint32_t Dst_Addr) +{ + SPI_FLASH_Write_Enable(); + SPI_Flash_Wait_Busy(); + FLASH_CS_CLR; + FLASH_readWrite(W25X_BlockErase); + FLASH_readWrite((uint8_t)((Dst_Addr) >> 16)); + FLASH_readWrite((uint8_t)((Dst_Addr) >> 8)); + FLASH_readWrite((uint8_t)Dst_Addr); + FLASH_CS_SET; + SPI_Flash_Wait_Busy(); +} + +/********************************************************************* + * @fn SPI_Flash_PowerDown + * + * @brief Enter power down mode. + * + * @return none + */ +void SPI_Flash_PowerDown(void) +{ + FLASH_CS_CLR; + FLASH_readWrite(W25X_PowerDown); + FLASH_CS_SET; + Delay_Us(3); +} + +/********************************************************************* + * @fn SPI_Flash_WAKEUP + * + * @brief Power down wake up. + * + * @return none + */ +void SPI_Flash_WAKEUP(void) +{ + FLASH_CS_CLR; + FLASH_readWrite(W25X_ReleasePowerDown); + FLASH_CS_SET; + Delay_Us(3); +} + +/********************************************************************* + * @fn SPI_Flash_Read_dma_start + * + * @brief enable spi dma and set read address + * + * @param ReadAddr - the address in spi flash + * + * @return none + */ +void SPI_Flash_Read_dma_start(uint32_t ReadAddr) +{ + FLASH_CS_CLR; + FLASH_readWrite(W25X_FastReadData); + FLASH_readWrite((uint8_t)((ReadAddr) >> 16)); + FLASH_readWrite((uint8_t)((ReadAddr) >> 8)); + FLASH_readWrite((uint8_t)ReadAddr); + FLASH_readWrite(0xFF); + SPI_I2S_DMACmd(SPI1, SPI_I2S_DMAReq_Tx | SPI_I2S_DMAReq_Rx, ENABLE); +} + +/********************************************************************* + * @fn SPI_Flash_Read_dma_end + * + * @brief disable spi dma + * + * @return none + */ +void SPI_Flash_Read_dma_end(void) +{ + FLASH_CS_SET; + SPI_I2S_DMACmd(SPI1, SPI_I2S_DMAReq_Tx | SPI_I2S_DMAReq_Rx, DISABLE); +} diff --git a/EVT/EXAM/APPLICATION/WUI/User/Drivers/flash.h b/EVT/EXAM/APPLICATION/WUI/User/Drivers/flash.h new file mode 100644 index 0000000..9bc606c --- /dev/null +++ b/EVT/EXAM/APPLICATION/WUI/User/Drivers/flash.h @@ -0,0 +1,57 @@ +/********************************************************************* + * File Name : flash.h + * Author : WCH + * Version : V1.0.0 + * Date : 2023/8/15 + * Description : file for spi flash. + ********************************************************************************* +* Copyright (c) 2023 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ +#ifndef __SPI_FLASH_H +#define __SPI_FLASH_H +#include "debug.h" +#include "spi.h" +#include "config.h" + +#define W25X_WriteEnable 0x06 +#define W25X_WriteDisable 0x04 +#define W25X_ReadStatusReg 0x05 +#define W25X_WriteStatusReg 0x01 +#define W25X_ReadData 0x03 +#define W25X_FastReadData 0x0B +#define W25X_FastReadDual 0x3B +#define W25X_PageProgram 0x02 +#define W25X_BlockErase 0xD8 +#define W25X_SectorErase 0x20 +#define W25X_ChipErase 0xC7 +#define W25X_PowerDown 0xB9 +#define W25X_ReleasePowerDown 0xAB +#define W25X_DeviceID 0xAB +#define W25X_ManufactDeviceID 0x90 +#define W25X_JedecDeviceID 0x9F + +#define FLASH_CS_SET (FLASH_CS_PORT->BSHR = FLASH_CS_PIN) +#define FLASH_CS_CLR (FLASH_CS_PORT->BCR = FLASH_CS_PIN) + +void SPI_FLASH_Init(void); +uint8_t SPI_Flash_ReadSR(void); +void SPI_FLASH_Write_SR(uint8_t sr); +void SPI_Flash_Wait_Busy(void); +void SPI_FLASH_Write_Enable(void); +void SPI_FLASH_Write_Disable(void); +uint16_t SPI_Flash_ReadID(void); +uint32_t SPI_Flash_ReadJedecDeviceID(void); +void SPI_Flash_Erase_Sector(uint32_t Dst_Addr); +void SPI_Flash_Read(uint8_t *pBuffer, uint32_t ReadAddr, uint16_t size); +void SPI_Flash_Write_Page(uint8_t *pBuffer, uint32_t WriteAddr, uint16_t size); +void SPI_Flash_Write_NoCheck(uint8_t *pBuffer, uint32_t WriteAddr, uint16_t size); +void SPI_Flash_Write(uint8_t *pBuffer, uint32_t WriteAddr, uint16_t size); +void SPI_Flash_Erase_Chip(void); +void SPI_Flash_PowerDown(void); +void SPI_Flash_WAKEUP(void); +void SPI_Flash_Read_dma_start(uint32_t ReadAddr); +void SPI_Flash_Read_dma_end(void); + +#endif diff --git a/EVT/EXAM/APPLICATION/WUI/User/Drivers/spi.c b/EVT/EXAM/APPLICATION/WUI/User/Drivers/spi.c new file mode 100644 index 0000000..c9ae001 --- /dev/null +++ b/EVT/EXAM/APPLICATION/WUI/User/Drivers/spi.c @@ -0,0 +1,247 @@ +/********************************************************************* + * File Name : spi.c + * Author : WCH + * Version : V1.0.0 + * Date : 2023/8/15 + * Description : file for spi. + ********************************************************************************* +* Copyright (c) 2023 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ +#include "spi.h" + +/********************************************************************* + * @fn SPI1_Init + * + * @brief Initialize SPI1 + * + * @return none + */ +void SPI1_Init(void) +{ + GPIO_InitTypeDef GPIO_InitStructure = {0}; + SPI_InitTypeDef SPI_InitStructure = {0}; + + RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_SPI1, ENABLE); + + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_Init(GPIOA, &GPIO_InitStructure); + + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; + GPIO_Init(GPIOA, &GPIO_InitStructure); + + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_Init(GPIOA, &GPIO_InitStructure); + + SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; + SPI_InitStructure.SPI_Mode = SPI_Mode_Master; + SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; + SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; + SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; + SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; + SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4; + SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; + SPI_InitStructure.SPI_CRCPolynomial = 7; + SPI_Init(SPI1, &SPI_InitStructure); + + SPI_Cmd(SPI1, ENABLE); + + SPI1->HSCR = 1; +} + +/********************************************************************* + * @fn SPI1_Read_DMA_Init + * + * @brief Initialize DMA for SPI1, In this condition every time send 0XFF to read data + * + * @return none + */ +void SPI1_Read_DMA_Init() +{ + static uint32_t DummyByte = 0xff; + DMA_InitTypeDef DMA_InitStructure = {0}; + + RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); + + // Tx + DMA_DeInit(SPI1_DMA_TX_CH); + + DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&SPI1->DATAR; + DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&DummyByte; + DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; + DMA_InitStructure.DMA_BufferSize = 0; + DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; + DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable; + DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte; + DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; + DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; + DMA_InitStructure.DMA_Priority = DMA_Priority_High; + DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; + DMA_Init(SPI1_DMA_TX_CH, &DMA_InitStructure); + + // Rx + DMA_DeInit(SPI1_DMA_RX_CH); + + DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&SPI1->DATAR; + DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)NULL; + DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; + DMA_InitStructure.DMA_BufferSize = 0; + DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; + DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; + DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte; + DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; + DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; + DMA_InitStructure.DMA_Priority = DMA_Priority_High; + DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; + DMA_Init(SPI1_DMA_RX_CH, &DMA_InitStructure); +} + +/********************************************************************* + * @fn SPI1_Read_DMA + * + * @brief read data from SPI1 via DMA + * + * @param data - the data to recive + * len - read length + * + * @return none + */ +void SPI1_Read_DMA(uint8_t* data, uint16_t len) +{ + while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET) + ; + DMA_Cmd(SPI1_DMA_TX_CH, DISABLE); + DMA_Cmd(SPI1_DMA_RX_CH, DISABLE); + DMA_ClearFlag(DMA1_FLAG_TC3); + DMA_ClearFlag(DMA1_FLAG_TC3); + SPI1_DMA_TX_CH->CNTR = len; + + SPI1_DMA_RX_CH->MADDR = (uint32_t)data; + SPI1_DMA_RX_CH->CNTR = len; + + DMA_Cmd(SPI1_DMA_TX_CH, ENABLE); + DMA_Cmd(SPI1_DMA_RX_CH, ENABLE); +} + +/********************************************************************* + * @fn SPI2_Init + * + * @brief Initialize SPI2 + * + * @return none + */ +void SPI2_Init(void) +{ + GPIO_InitTypeDef GPIO_InitStructure = {0}; + SPI_InitTypeDef SPI_InitStructure = {0}; + + RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB, ENABLE); + RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE); + + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_Init(GPIOB, &GPIO_InitStructure); + + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; + GPIO_Init(GPIOB, &GPIO_InitStructure); + + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_Init(GPIOB, &GPIO_InitStructure); + + SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Tx; + SPI_InitStructure.SPI_Mode = SPI_Mode_Master; + SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; + SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; + SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; + SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; + SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2; + SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; + SPI_InitStructure.SPI_CRCPolynomial = 7; + SPI_Init(SPI2, &SPI_InitStructure); + + SPI_Cmd(SPI2, ENABLE); +} + +/********************************************************************* + * @fn SPI2_DMA_Init + * + * @brief Initialize DMA for SPI2 + * + * @return none + */ +void SPI2_DMA_Init() +{ + DMA_InitTypeDef DMA_InitStructure = {0}; + + RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); + + DMA_DeInit(SPI2_DMA_TX_CH); + + DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&SPI2->DATAR; + DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)NULL; + DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; + DMA_InitStructure.DMA_BufferSize = 0; + DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; + DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; + DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte; + DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; + DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; + DMA_InitStructure.DMA_Priority = DMA_Priority_High; + DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; + DMA_Init(SPI2_DMA_TX_CH, &DMA_InitStructure); + + SPI_I2S_DMACmd(SPI2, SPI_I2S_DMAReq_Tx, ENABLE); +} + +/********************************************************************* + * @fn SPI2_Write + * + * @brief send one byte + * + * @param data - the data to send + * + * @return none + */ +void SPI2_Write(uint8_t data) +{ + while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET) + ; + SPI_I2S_SendData(SPI2, data); + + while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_BSY) == SET) + ; +} + +/********************************************************************* + * @fn SPI2_Write_DMA + * + * @brief send a lot of data + * + * @param data - the data to be send + * len - the length of data + * + * @return none + */ +void SPI2_Write_DMA(uint8_t* data, uint16_t len) +{ + while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_BSY) == SET) + ; + + DMA_Cmd(SPI2_DMA_TX_CH, DISABLE); + DMA_ClearFlag(SPI2_DMA_TC_FLAG); + SPI2_DMA_TX_CH->MADDR = (uint32_t)data; + SPI2_DMA_TX_CH->CNTR = len; + SPI2_DMA_TX_CH->CFGR = 0x2090; + + DMA_Cmd(SPI2_DMA_TX_CH, ENABLE); +} diff --git a/EVT/EXAM/APPLICATION/WUI/User/Drivers/spi.h b/EVT/EXAM/APPLICATION/WUI/User/Drivers/spi.h new file mode 100644 index 0000000..1d2923b --- /dev/null +++ b/EVT/EXAM/APPLICATION/WUI/User/Drivers/spi.h @@ -0,0 +1,39 @@ +/********************************************************************* + * File Name : spi.h + * Author : WCH + * Version : V1.0.0 + * Date : 2023/8/15 + * Description : file for spi. + ********************************************************************************* +* Copyright (c) 2023 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ +#ifndef __SPI_H__ +#define __SPI_H__ + +#include "debug.h" +#include "config.h" + +#define SPI1_DMA_RX_CH DMA1_Channel2 +#define SPI1_DMA_TX_CH DMA1_Channel3 + +#define SPI1_DMA_TC_FLAG DMA1_FLAG_TC3 +#define SPI1_DMA_RC_FLAG DMA1_FLAG_TC2 + +#define SPI2_DMA_RX_CH DMA1_Channel4 +#define SPI2_DMA_TX_CH DMA1_Channel5 + +#define SPI2_DMA_TC_FLAG DMA1_FLAG_TC5 +#define SPI2_DMA_RC_FLAG DMA1_FLAG_TC4 + +void SPI1_Init(void); +void SPI1_Read_DMA_Init(void); +void SPI1_Read_DMA(uint8_t *data, uint16_t len); + +void SPI2_Init(void); +void SPI2_DMA_Init(void); +void SPI2_Write(uint8_t data); +void SPI2_Write_DMA(uint8_t *data, uint16_t len); + +#endif diff --git a/EVT/EXAM/APPLICATION/WUI/User/ch32v20x_conf.h b/EVT/EXAM/APPLICATION/WUI/User/ch32v20x_conf.h new file mode 100644 index 0000000..d1eeb38 --- /dev/null +++ b/EVT/EXAM/APPLICATION/WUI/User/ch32v20x_conf.h @@ -0,0 +1,42 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : ch32v20x_conf.h + * Author : WCH + * Version : V1.0.0 + * Date : 2021/06/06 + * Description : Library configuration file. +********************************************************************************* +* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ +#ifndef __CH32V20x_CONF_H +#define __CH32V20x_CONF_H + +#include "ch32v20x_adc.h" +#include "ch32v20x_bkp.h" +#include "ch32v20x_can.h" +#include "ch32v20x_crc.h" +#include "ch32v20x_dbgmcu.h" +#include "ch32v20x_dma.h" +#include "ch32v20x_exti.h" +#include "ch32v20x_flash.h" +#include "ch32v20x_gpio.h" +#include "ch32v20x_i2c.h" +#include "ch32v20x_iwdg.h" +#include "ch32v20x_pwr.h" +#include "ch32v20x_rcc.h" +#include "ch32v20x_rtc.h" +#include "ch32v20x_spi.h" +#include "ch32v20x_tim.h" +#include "ch32v20x_usart.h" +#include "ch32v20x_wwdg.h" +#include "ch32v20x_it.h" +#include "ch32v20x_misc.h" + + +#endif /* __CH32V20x_CONF_H */ + + + + + diff --git a/EVT/EXAM/APPLICATION/WUI/User/ch32v20x_it.c b/EVT/EXAM/APPLICATION/WUI/User/ch32v20x_it.c new file mode 100644 index 0000000..e3dff91 --- /dev/null +++ b/EVT/EXAM/APPLICATION/WUI/User/ch32v20x_it.c @@ -0,0 +1,46 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : ch32v20x_it.c + * Author : WCH + * Version : V1.0.0 + * Date : 2023/12/29 + * Description : Main Interrupt Service Routines. +********************************************************************************* +* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ +#include "ch32v20x_it.h" + +void NMI_Handler(void) __attribute__((interrupt("WCH-Interrupt-fast"))); +void HardFault_Handler(void) __attribute__((interrupt("WCH-Interrupt-fast"))); + +/********************************************************************* + * @fn NMI_Handler + * + * @brief This function handles NMI exception. + * + * @return none + */ +void NMI_Handler(void) +{ + while (1) + { + } +} + +/********************************************************************* + * @fn HardFault_Handler + * + * @brief This function handles Hard Fault exception. + * + * @return none + */ +void HardFault_Handler(void) +{ + NVIC_SystemReset(); + while (1) + { + } +} + + diff --git a/EVT/EXAM/APPLICATION/WUI/User/ch32v20x_it.h b/EVT/EXAM/APPLICATION/WUI/User/ch32v20x_it.h new file mode 100644 index 0000000..f68b203 --- /dev/null +++ b/EVT/EXAM/APPLICATION/WUI/User/ch32v20x_it.h @@ -0,0 +1,20 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : ch32v20x_it.h + * Author : WCH + * Version : V1.0.0 + * Date : 2021/06/06 + * Description : This file contains the headers of the interrupt handlers. +********************************************************************************* +* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ +#ifndef __CH32V20x_IT_H +#define __CH32V20x_IT_H + +#include "debug.h" + + +#endif /* __CH32V20x_IT_H */ + + diff --git a/EVT/EXAM/APPLICATION/WUI/User/main.c b/EVT/EXAM/APPLICATION/WUI/User/main.c new file mode 100644 index 0000000..7c3b60d --- /dev/null +++ b/EVT/EXAM/APPLICATION/WUI/User/main.c @@ -0,0 +1,304 @@ +/********************************************************************* + * File Name : main.c + * Author : WCH + * Version : V1.0.0 + * Date : 2026/08/06 + * Description : Main program body. + ********************************************************************************* +* Copyright (c) 2023 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ + +/* + *@Note + A demo for wui + pins: + FLASH_CS -- PA4 + FLASH_DO -- PA6 + FLASH_DI -- PA7 + FLASH_CLK -- PA5 + + LCD_LED -- PB9 + LCD_DC -- PB10 + LCD_RST -- PB11 + LCD_CS -- PB12 + LCD_SCK -- PB13 + LCD_MOSI -- PB15 + + + */ + + +#include +#include "debug.h" +#include "string.h" +#include "lcd.h" +#include "flash.h" +#include "config.h" +#include "wui.h" +#include "wui_port.h" +#include "wui_user/wui_page.h" + +/* Global define */ + +/* Global Variable */ + + +#define TIM_PCK (8000ul) + +/********************************************************************* + * @fn TIM4_init + * + * @brief Initialize TIM2 for WCHGUI + * + * @return none. + */ +void TIM4_init() +{ + RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE); + + TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure = {0}; + + TIM_Cmd(TIM4, DISABLE); + + TIM_TimeBaseInitStructure.TIM_Period = 0xffff; + TIM_TimeBaseInitStructure.TIM_Prescaler = ((SystemCoreClock) / TIM_PCK) - 1; + TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1; + TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up; + TIM_TimeBaseInit(TIM4, &TIM_TimeBaseInitStructure); + + TIM_ARRPreloadConfig(TIM4, DISABLE); + TIM_ClearFlag(TIM4, TIM_FLAG_Update); + + TIM_Cmd(TIM4, ENABLE); +} + +/********************************************************************* + * @fn TIM3_Encoder_Init + * + * @brief Initialize TIM1 for encoder + * + * @return none. + */ +void TIM3_Encoder_Init() +{ + TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; + TIM_ICInitTypeDef TIM_ICInitStructure; + GPIO_InitTypeDef GPIO_InitStructure = {0}; + + RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); + RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); + RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); + RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); + + { + GPIO_PinRemapConfig(GPIO_PartialRemap_TIM3, ENABLE); + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; + GPIO_Init(GPIOB, &GPIO_InitStructure); + } + + TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); + TIM_TimeBaseStructure.TIM_Prescaler = 0x0; + TIM_TimeBaseStructure.TIM_Period = 160; + TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; + TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; + TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); + + TIM_EncoderInterfaceConfig(TIM3, TIM_EncoderMode_TI12, TIM_ICPolarity_Rising, TIM_ICPolarity_Rising); + + TIM_ICStructInit(&TIM_ICInitStructure); + TIM_ICInitStructure.TIM_ICFilter = 10; + TIM_ICInit(TIM3, &TIM_ICInitStructure); + + TIM_SetCounter(TIM3, 0); + TIM_Cmd(TIM3, ENABLE); +} + +/********************************************************************* + * @fn check_direction + * + * @brief Compute the absolute value of a signed 32-bit integer. + * + * @param a Signed 32-bit integer. + * + * @return Absolute value of a + */ +uint32_t static inline iabs(int32_t a) +{ + if (a < 0) + { + return -a; + } + return a; +} + +/********************************************************************* + * @fn check_direction + * + * @brief Detect the rotation direction of the encoder + * + * @param current_value The current count value + * + * @return direction The direction of the encoder's rotation + */ +int32_t check_direction(int current_value) +{ + + static int last_value = 0; + + if (current_value == last_value) + { + return 0; + } + + int diff = current_value - last_value; + if (iabs(diff) < 4) + { + return 0; + } + + int32_t direction; + + if (iabs(diff) < 80) + { + if (diff > 0) + { + direction = 1; + } + else + { + direction = -1; + } + } + else + { + if (diff > 0) + { + direction = -1; + } + else + { + direction = 1; + } + } + + last_value = current_value; + return direction; +} + +#define ENC_KEY_PORT GPIOA +#define ENC_KEY_PIN (GPIO_Pin_15) + +#define ENC_KEY() ((ENC_KEY_PORT->INDR & ENC_KEY_PIN) == 0) + +uint32_t key3_state = 0; +/********************************************************************* + * @fn Key_GPIOInit + * + * @brief Initialization of the key pins of the encoder + * + * @return none. + */ +void Key_GPIOInit(void) +{ + + GPIO_InitTypeDef GPIO_InitStructure = {0}; + + GPIO_InitStructure.GPIO_Pin = ENC_KEY_PIN; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; + GPIO_Init(ENC_KEY_PORT, &GPIO_InitStructure); +} + +static uint8_t wui_heap_buffer[4 * 1024]; + +/********************************************************************* + * @fn main + * + * @brief Main program. + * + * @return none + */ +int main(void) +{ + + SystemCoreClockUpdate(); + Delay_Init(); + USART_Printf_Init(115200); + printf("SystemClk:%d\r\n", SystemCoreClock); + printf(__TIME__ "\n"); + + SPI_FLASH_Init(); + + uint32_t id = SPI_Flash_ReadJedecDeviceID(); + printf("flash_id %x\n", id); + + LCD_Init(); + + TIM3_Encoder_Init(); + TIM4_init(); + Key_GPIOInit(); + + wui_init_data_t data = { + .page_count = WUI_PAGE_COUNT, + .width = LCD_WIDTH, + .height = LCD_HEIGHT, + .heap_addr = wui_heap_buffer, + .heap_size = sizeof(wui_heap_buffer), + }; + + wui_init(&data); + + wui_register_hal(wui_get_hal()); + + wui_page_switch(WUI_START_PAGE); + + while (1) + { + + uint16_t now = TIM4->CNT; + if (now > 16) + { + now = now / 8; + TIM4->CNT = 0; + + wui_page_ui_tick(now); + } + + wui_page_ui_update(); + uint32_t tcnt = TIM3->CNT; + + int32_t dir = check_direction(tcnt); + + if (dir > 0) + { + HW_Key_event('a'); + } + else if (dir < 0) + { + HW_Key_event('d'); + } + + uint32_t k3 = ENC_KEY(); + if (k3) + { + if (key3_state) + { + } + else + { + key3_state = 1; + HW_Key_event('b'); + } + } + else + { + key3_state = 0; + } + } + + while (1) + { + } +} diff --git a/EVT/EXAM/APPLICATION/WUI/User/main.c.bak b/EVT/EXAM/APPLICATION/WUI/User/main.c.bak new file mode 100644 index 0000000..31bc693 --- /dev/null +++ b/EVT/EXAM/APPLICATION/WUI/User/main.c.bak @@ -0,0 +1,305 @@ +/********************************************************************* + * File Name : main.c + * Author : WCH + * Version : V1.0.0 + * Date : 2026/08/06 + * Description : Main program body. + ********************************************************************************* +* Copyright (c) 2023 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ + +/* + *@Note + A demo for wui + pins: + pins: + FLASH_CS -- PA4 + FLASH_DO -- PA6 + FLASH_DI -- PA7 + FLASH_CLK -- PA5 + + LCD_LED -- PB9 + LCD_DC -- PB10 + LCD_RST -- PB11 + LCD_CS -- PB12 + LCD_SCK -- PB13 + LCD_MOSI -- PB15 + + + */ + + +#include +#include "debug.h" +#include "string.h" +#include "lcd.h" +#include "flash.h" +#include "config.h" +#include "wui.h" +#include "wui_port.h" +#include "wui_user/wui_page.h" + +/* Global define */ + +/* Global Variable */ + + +#define TIM_PCK (8000ul) + +/********************************************************************* + * @fn TIM4_init + * + * @brief Initialize TIM2 for WCHGUI + * + * @return none. + */ +void TIM4_init() +{ + RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE); + + TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure = {0}; + + TIM_Cmd(TIM4, DISABLE); + + TIM_TimeBaseInitStructure.TIM_Period = 0xffff; + TIM_TimeBaseInitStructure.TIM_Prescaler = ((SystemCoreClock) / TIM_PCK) - 1; + TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1; + TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up; + TIM_TimeBaseInit(TIM4, &TIM_TimeBaseInitStructure); + + TIM_ARRPreloadConfig(TIM4, DISABLE); + TIM_ClearFlag(TIM4, TIM_FLAG_Update); + + TIM_Cmd(TIM4, ENABLE); +} + +/********************************************************************* + * @fn TIM3_Encoder_Init + * + * @brief Initialize TIM1 for encoder + * + * @return none. + */ +void TIM3_Encoder_Init() +{ + TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; + TIM_ICInitTypeDef TIM_ICInitStructure; + GPIO_InitTypeDef GPIO_InitStructure = {0}; + + RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); + RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); + RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); + RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); + + { + GPIO_PinRemapConfig(GPIO_PartialRemap_TIM3, ENABLE); + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; + GPIO_Init(GPIOB, &GPIO_InitStructure); + } + + TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); + TIM_TimeBaseStructure.TIM_Prescaler = 0x0; + TIM_TimeBaseStructure.TIM_Period = 160; + TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; + TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; + TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); + + TIM_EncoderInterfaceConfig(TIM3, TIM_EncoderMode_TI12, TIM_ICPolarity_Rising, TIM_ICPolarity_Rising); + + TIM_ICStructInit(&TIM_ICInitStructure); + TIM_ICInitStructure.TIM_ICFilter = 10; + TIM_ICInit(TIM3, &TIM_ICInitStructure); + + TIM_SetCounter(TIM3, 0); + TIM_Cmd(TIM3, ENABLE); +} + +/********************************************************************* + * @fn check_direction + * + * @brief Compute the absolute value of a signed 32-bit integer. + * + * @param a Signed 32-bit integer. + * + * @return Absolute value of a + */ +uint32_t static inline iabs(int32_t a) +{ + if (a < 0) + { + return -a; + } + return a; +} + +/********************************************************************* + * @fn check_direction + * + * @brief Detect the rotation direction of the encoder + * + * @param current_value The current count value + * + * @return direction The direction of the encoder's rotation + */ +int32_t check_direction(int current_value) +{ + + static int last_value = 0; + + if (current_value == last_value) + { + return 0; + } + + int diff = current_value - last_value; + if (iabs(diff) < 4) + { + return 0; + } + + int32_t direction; + + if (iabs(diff) < 80) + { + if (diff > 0) + { + direction = 1; + } + else + { + direction = -1; + } + } + else + { + if (diff > 0) + { + direction = -1; + } + else + { + direction = 1; + } + } + + last_value = current_value; + return direction; +} + +#define ENC_KEY_PORT GPIOA +#define ENC_KEY_PIN (GPIO_Pin_15) + +#define ENC_KEY() ((ENC_KEY_PORT->INDR & ENC_KEY_PIN) == 0) + +uint32_t key3_state = 0; +/********************************************************************* + * @fn Key_GPIOInit + * + * @brief Initialization of the key pins of the encoder + * + * @return none. + */ +void Key_GPIOInit(void) +{ + + GPIO_InitTypeDef GPIO_InitStructure = {0}; + + GPIO_InitStructure.GPIO_Pin = ENC_KEY_PIN; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; + GPIO_Init(ENC_KEY_PORT, &GPIO_InitStructure); +} + +static uint8_t wui_heap_buffer[4 * 1024]; + +/********************************************************************* + * @fn main + * + * @brief Main program. + * + * @return none + */ +int main(void) +{ + + SystemCoreClockUpdate(); + Delay_Init(); + USART_Printf_Init(115200); + printf("SystemClk:%d\r\n", SystemCoreClock); + printf(__TIME__ "\n"); + + SPI_FLASH_Init(); + + uint32_t id = SPI_Flash_ReadJedecDeviceID(); + printf("flash_id %x\n", id); + + LCD_Init(); + + TIM3_Encoder_Init(); + TIM4_init(); + Key_GPIOInit(); + + wui_init_data_t data = { + .page_count = WUI_PAGE_COUNT, + .width = LCD_WIDTH, + .height = LCD_HEIGHT, + .heap_addr = wui_heap_buffer, + .heap_size = sizeof(wui_heap_buffer), + }; + + wui_init(&data); + + wui_register_hal(wui_get_hal()); + + wui_page_switch(WUI_START_PAGE); + + while (1) + { + + uint16_t now = TIM4->CNT; + if (now > 16) + { + now = now / 8; + TIM4->CNT = 0; + + wui_page_ui_tick(now); + } + + wui_page_ui_update(); + uint32_t tcnt = TIM3->CNT; + + int32_t dir = check_direction(tcnt); + + if (dir > 0) + { + HW_Key_event('a'); + } + else if (dir < 0) + { + HW_Key_event('d'); + } + + uint32_t k3 = ENC_KEY(); + if (k3) + { + if (key3_state) + { + } + else + { + key3_state = 1; + HW_Key_event('b'); + } + } + else + { + key3_state = 0; + } + } + + while (1) + { + } +} diff --git a/EVT/EXAM/APPLICATION/WUI/User/system_ch32v20x.c b/EVT/EXAM/APPLICATION/WUI/User/system_ch32v20x.c new file mode 100644 index 0000000..7facd53 --- /dev/null +++ b/EVT/EXAM/APPLICATION/WUI/User/system_ch32v20x.c @@ -0,0 +1,987 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : system_ch32v20x.c + * Author : WCH + * Version : V1.0.0 + * Date : 2021/06/06 + * Description : CH32V20x Device Peripheral Access Layer System Source File. + * For HSE = 32Mhz (CH32V208x/CH32V203RBT) + * For HSE = 8Mhz (other CH32V203x) +********************************************************************************* +* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ +#include "ch32v20x.h" + +/* +* Uncomment the line corresponding to the desired System clock (SYSCLK) frequency (after +* reset the HSI is used as SYSCLK source). +* If none of the define below is enabled, the HSI is used as System clock source. +*/ +//#define SYSCLK_FREQ_HSE HSE_VALUE +//#define SYSCLK_FREQ_48MHz_HSE 48000000 +//#define SYSCLK_FREQ_56MHz_HSE 56000000 +//#define SYSCLK_FREQ_72MHz_HSE 72000000 +#define SYSCLK_FREQ_96MHz_HSE 96000000 +//#define SYSCLK_FREQ_120MHz_HSE 120000000 +//#define SYSCLK_FREQ_144MHz_HSE 144000000 +//#define SYSCLK_FREQ_HSI HSI_VALUE +//#define SYSCLK_FREQ_48MHz_HSI 48000000 +//#define SYSCLK_FREQ_56MHz_HSI 56000000 +//#define SYSCLK_FREQ_72MHz_HSI 72000000 +//#define SYSCLK_FREQ_96MHz_HSI 96000000 +//#define SYSCLK_FREQ_120MHz_HSI 120000000 +//#define SYSCLK_FREQ_144MHz_HSI 144000000 + +/* Clock Definitions */ +#ifdef SYSCLK_FREQ_HSE +uint32_t SystemCoreClock = SYSCLK_FREQ_HSE; /* System Clock Frequency (Core Clock) */ +#elif defined SYSCLK_FREQ_48MHz_HSE +uint32_t SystemCoreClock = SYSCLK_FREQ_48MHz_HSE; /* System Clock Frequency (Core Clock) */ +#elif defined SYSCLK_FREQ_56MHz_HSE +uint32_t SystemCoreClock = SYSCLK_FREQ_56MHz_HSE; /* System Clock Frequency (Core Clock) */ +#elif defined SYSCLK_FREQ_72MHz_HSE +uint32_t SystemCoreClock = SYSCLK_FREQ_72MHz_HSE; /* System Clock Frequency (Core Clock) */ +#elif defined SYSCLK_FREQ_96MHz_HSE +uint32_t SystemCoreClock = SYSCLK_FREQ_96MHz_HSE; /* System Clock Frequency (Core Clock) */ +#elif defined SYSCLK_FREQ_120MHz_HSE +uint32_t SystemCoreClock = SYSCLK_FREQ_120MHz_HSE; /* System Clock Frequency (Core Clock) */ +#elif defined SYSCLK_FREQ_144MHz_HSE +uint32_t SystemCoreClock = SYSCLK_FREQ_144MHz_HSE; /* System Clock Frequency (Core Clock) */ +#elif defined SYSCLK_FREQ_48MHz_HSI +uint32_t SystemCoreClock = SYSCLK_FREQ_48MHz_HSI; /* System Clock Frequency (Core Clock) */ +#elif defined SYSCLK_FREQ_56MHz_HSI +uint32_t SystemCoreClock = SYSCLK_FREQ_56MHz_HSI; /* System Clock Frequency (Core Clock) */ +#elif defined SYSCLK_FREQ_72MHz_HSI +uint32_t SystemCoreClock = SYSCLK_FREQ_72MHz_HSI; /* System Clock Frequency (Core Clock) */ +#elif defined SYSCLK_FREQ_96MHz_HSI +uint32_t SystemCoreClock = SYSCLK_FREQ_96MHz_HSI; /* System Clock Frequency (Core Clock) */ +#elif defined SYSCLK_FREQ_120MHz_HSI +uint32_t SystemCoreClock = SYSCLK_FREQ_120MHz_HSI; /* System Clock Frequency (Core Clock) */ +#elif defined SYSCLK_FREQ_144MHz_HSI +uint32_t SystemCoreClock = SYSCLK_FREQ_144MHz_HSI; /* System Clock Frequency (Core Clock) */ +#else +uint32_t SystemCoreClock = HSI_VALUE; /* System Clock Frequency (Core Clock) */ + +#endif + +__I uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}; + + +/* system_private_function_proto_types */ +static void SetSysClock(void); + +#ifdef SYSCLK_FREQ_HSE +static void SetSysClockToHSE( void ); +#elif defined SYSCLK_FREQ_48MHz_HSE +static void SetSysClockTo48_HSE( void ); +#elif defined SYSCLK_FREQ_56MHz_HSE +static void SetSysClockTo56_HSE( void ); +#elif defined SYSCLK_FREQ_72MHz_HSE +static void SetSysClockTo72_HSE( void ); +#elif defined SYSCLK_FREQ_96MHz_HSE +static void SetSysClockTo96_HSE( void ); +#elif defined SYSCLK_FREQ_120MHz_HSE +static void SetSysClockTo120_HSE( void ); +#elif defined SYSCLK_FREQ_144MHz_HSE +static void SetSysClockTo144_HSE( void ); +#elif defined SYSCLK_FREQ_48MHz_HSI +static void SetSysClockTo48_HSI( void ); +#elif defined SYSCLK_FREQ_56MHz_HSI +static void SetSysClockTo56_HSI( void ); +#elif defined SYSCLK_FREQ_72MHz_HSI +static void SetSysClockTo72_HSI( void ); +#elif defined SYSCLK_FREQ_96MHz_HSI +static void SetSysClockTo96_HSI( void ); +#elif defined SYSCLK_FREQ_120MHz_HSI +static void SetSysClockTo120_HSI( void ); +#elif defined SYSCLK_FREQ_144MHz_HSI +static void SetSysClockTo144_HSI( void ); + +#endif + +/********************************************************************* + * @fn SystemInit + * + * @brief Setup the microcontroller system Initialize the Embedded Flash Interface, + * the PLL and update the SystemCoreClock variable. + * + * @return none + */ +void SystemInit (void) +{ + RCC->CTLR |= (uint32_t)0x00000001; + RCC->CFGR0 &= (uint32_t)0xF0FF0000; + RCC->CTLR &= (uint32_t)0xFEF6FFFF; + RCC->CTLR &= (uint32_t)0xFFFBFFFF; + RCC->CFGR0 &= (uint32_t)0xFF00FFFF; + RCC->INTR = 0x009F0000; + SetSysClock(); +} + + +/********************************************************************* + * @fn SystemCoreClockUpdate + * + * @brief Update SystemCoreClock variable according to Clock Register Values. + * + * @return none + */ +void SystemCoreClockUpdate (void) +{ + uint32_t tmp = 0, pllmull = 0, pllsource = 0, Pll_6_5 = 0; + + tmp = RCC->CFGR0 & RCC_SWS; + + switch (tmp) + { + case 0x00: + SystemCoreClock = HSI_VALUE; + break; + case 0x04: + SystemCoreClock = HSE_VALUE; + break; + case 0x08: + pllmull = RCC->CFGR0 & RCC_PLLMULL; + pllsource = RCC->CFGR0 & RCC_PLLSRC; + pllmull = ( pllmull >> 18) + 2; + + if(pllmull == 17) pllmull = 18; + + if (pllsource == 0x00) + { + if(EXTEN->EXTEN_CTR & EXTEN_PLL_HSI_PRE){ + SystemCoreClock = HSI_VALUE * pllmull; + } + else{ + SystemCoreClock = (HSI_VALUE >> 1) * pllmull; + } + } + else + { +#if defined (CH32V20x_D8W) || defined (CH32V20x_D8) + if(((RCC->CFGR0 & (3<<22)) == (3<<22)) && (RCC_USB5PRE_JUDGE()== SET)) + { + SystemCoreClock = ((HSE_VALUE>>1)) * pllmull; + } + else +#endif + if ((RCC->CFGR0 & RCC_PLLXTPRE) != (uint32_t)RESET) + { +#if defined (CH32V20x_D8) || defined (CH32V20x_D8W) + SystemCoreClock = ((HSE_VALUE>>2) >> 1) * pllmull; +#else + SystemCoreClock = (HSE_VALUE >> 1) * pllmull; +#endif + } + else + { +#if defined (CH32V20x_D8) || defined (CH32V20x_D8W) + SystemCoreClock = (HSE_VALUE>>2) * pllmull; +#else + SystemCoreClock = HSE_VALUE * pllmull; +#endif + } + } + + if(Pll_6_5 == 1) SystemCoreClock = (SystemCoreClock / 2); + + break; + default: + SystemCoreClock = HSI_VALUE; + break; + } + + tmp = AHBPrescTable[((RCC->CFGR0 & RCC_HPRE) >> 4)]; + SystemCoreClock >>= tmp; +} + +/********************************************************************* + * @fn SetSysClock + * + * @brief Configures the System clock frequency, HCLK, PCLK2 and PCLK1 prescalers. + * + * @return none + */ +static void SetSysClock(void) +{ + //GPIO_IPD_Unused(); +#ifdef SYSCLK_FREQ_HSE + SetSysClockToHSE(); +#elif defined SYSCLK_FREQ_48MHz_HSE + SetSysClockTo48_HSE(); +#elif defined SYSCLK_FREQ_56MHz_HSE + SetSysClockTo56_HSE(); +#elif defined SYSCLK_FREQ_72MHz_HSE + SetSysClockTo72_HSE(); +#elif defined SYSCLK_FREQ_96MHz_HSE + SetSysClockTo96_HSE(); +#elif defined SYSCLK_FREQ_120MHz_HSE + SetSysClockTo120_HSE(); +#elif defined SYSCLK_FREQ_144MHz_HSE + SetSysClockTo144_HSE(); +#elif defined SYSCLK_FREQ_48MHz_HSI + SetSysClockTo48_HSI(); +#elif defined SYSCLK_FREQ_56MHz_HSI + SetSysClockTo56_HSI(); +#elif defined SYSCLK_FREQ_72MHz_HSI + SetSysClockTo72_HSI(); +#elif defined SYSCLK_FREQ_96MHz_HSI + SetSysClockTo96_HSI(); +#elif defined SYSCLK_FREQ_120MHz_HSI + SetSysClockTo120_HSI(); +#elif defined SYSCLK_FREQ_144MHz_HSI + SetSysClockTo144_HSI(); + +#endif + + /* If none of the define above is enabled, the HSI is used as System clock + * source (default after reset) + */ +} + + +#ifdef SYSCLK_FREQ_HSE + +/********************************************************************* + * @fn SetSysClockToHSE + * + * @brief Sets HSE as System clock source and configure HCLK, PCLK2 and PCLK1 prescalers. + * + * @return none + */ +static void SetSysClockToHSE(void) +{ + __IO uint32_t StartUpCounter = 0, HSEStatus = 0; + + + RCC->CTLR |= ((uint32_t)RCC_HSEON); + + /* Wait till HSE is ready and if Time out is reached exit */ + do + { + HSEStatus = RCC->CTLR & RCC_HSERDY; + StartUpCounter++; + } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT)); + + if ((RCC->CTLR & RCC_HSERDY) != RESET) + { + HSEStatus = (uint32_t)0x01; + } + else + { + HSEStatus = (uint32_t)0x00; + } + + if (HSEStatus == (uint32_t)0x01) + { + /* HCLK = SYSCLK */ + RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1; + /* PCLK2 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1; + /* PCLK1 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV1; + + /* Select HSE as system clock source + * CH32V20x_D6 (HSE=8MHZ) + * CH32V20x_D8 (HSE=32MHZ) + * CH32V20x_D8W (HSE=32MHZ) + */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW)); + RCC->CFGR0 |= (uint32_t)RCC_SW_HSE; + + /* Wait till HSE is used as system clock source */ + while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x04) + { + } + } + else + { + /* If HSE fails to start-up, the application will have wrong clock + * configuration. User can add here some code to deal with this error + */ + } +} + +#elif defined SYSCLK_FREQ_48MHz_HSE + +/********************************************************************* + * @fn SetSysClockTo48_HSE + * + * @brief Sets System clock frequency to 48MHz and configure HCLK, PCLK2 and PCLK1 prescalers. + * + * @return none + */ +static void SetSysClockTo48_HSE(void) +{ + __IO uint32_t StartUpCounter = 0, HSEStatus = 0; + + + RCC->CTLR |= ((uint32_t)RCC_HSEON); + /* Wait till HSE is ready and if Time out is reached exit */ + do + { + HSEStatus = RCC->CTLR & RCC_HSERDY; + StartUpCounter++; + } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT)); + + if ((RCC->CTLR & RCC_HSERDY) != RESET) + { + HSEStatus = (uint32_t)0x01; + } + else + { + HSEStatus = (uint32_t)0x00; + } + + if (HSEStatus == (uint32_t)0x01) + { + /* HCLK = SYSCLK */ + RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1; + /* PCLK2 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1; + /* PCLK1 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2; + + /* CH32V20x_D6-PLL configuration: PLLCLK = HSE * 6 = 48 MHz (HSE=8MHZ) + * CH32V20x_D8-PLL configuration: PLLCLK = HSE/4 * 6 = 48 MHz (HSE=32MHZ) + * CH32V20x_D8W-PLL configuration: PLLCLK = HSE/4 * 6 = 48 MHz (HSE=32MHZ) + */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | RCC_PLLMULL)); + + RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL6); + + /* Enable PLL */ + RCC->CTLR |= RCC_PLLON; + /* Wait till PLL is ready */ + while((RCC->CTLR & RCC_PLLRDY) == 0) + { + } + /* Select PLL as system clock source */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW)); + RCC->CFGR0 |= (uint32_t)RCC_SW_PLL; + /* Wait till PLL is used as system clock source */ + while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08) + { + } + } + else + { + /* + * If HSE fails to start-up, the application will have wrong clock + * configuration. User can add here some code to deal with this error + */ + } +} + +#elif defined SYSCLK_FREQ_56MHz_HSE + +/********************************************************************* + * @fn SetSysClockTo56_HSE + * + * @brief Sets System clock frequency to 56MHz and configure HCLK, PCLK2 and PCLK1 prescalers. + * + * @return none + */ +static void SetSysClockTo56_HSE(void) +{ + __IO uint32_t StartUpCounter = 0, HSEStatus = 0; + + RCC->CTLR |= ((uint32_t)RCC_HSEON); + + /* Wait till HSE is ready and if Time out is reached exit */ + do + { + HSEStatus = RCC->CTLR & RCC_HSERDY; + StartUpCounter++; + } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT)); + + if ((RCC->CTLR & RCC_HSERDY) != RESET) + { + HSEStatus = (uint32_t)0x01; + } + else + { + HSEStatus = (uint32_t)0x00; + } + + if (HSEStatus == (uint32_t)0x01) + { + /* HCLK = SYSCLK */ + RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1; + /* PCLK2 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1; + /* PCLK1 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2; + + /* CH32V20x_D6-PLL configuration: PLLCLK = HSE * 7 = 56 MHz (HSE=8MHZ) + * CH32V20x_D8-PLL configuration: PLLCLK = HSE/4 * 7 = 56 MHz (HSE=32MHZ) + * CH32V20x_D8W-PLL configuration: PLLCLK = HSE/4 * 7 = 56 MHz (HSE=32MHZ) + */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | RCC_PLLMULL)); + + RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL7); + + /* Enable PLL */ + RCC->CTLR |= RCC_PLLON; + /* Wait till PLL is ready */ + while((RCC->CTLR & RCC_PLLRDY) == 0) + { + } + + /* Select PLL as system clock source */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW)); + RCC->CFGR0 |= (uint32_t)RCC_SW_PLL; + /* Wait till PLL is used as system clock source */ + while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08) + { + } + } + else + { + /* + * If HSE fails to start-up, the application will have wrong clock + * configuration. User can add here some code to deal with this error + */ + } +} + +#elif defined SYSCLK_FREQ_72MHz_HSE + +/********************************************************************* + * @fn SetSysClockTo72_HSE + * + * @brief Sets System clock frequency to 72MHz and configure HCLK, PCLK2 and PCLK1 prescalers. + * + * @return none + */ +static void SetSysClockTo72_HSE(void) +{ + __IO uint32_t StartUpCounter = 0, HSEStatus = 0; + + RCC->CTLR |= ((uint32_t)RCC_HSEON); + + /* Wait till HSE is ready and if Time out is reached exit */ + do + { + HSEStatus = RCC->CTLR & RCC_HSERDY; + StartUpCounter++; + } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT)); + + if ((RCC->CTLR & RCC_HSERDY) != RESET) + { + HSEStatus = (uint32_t)0x01; + } + else + { + HSEStatus = (uint32_t)0x00; + } + + if (HSEStatus == (uint32_t)0x01) + { + /* HCLK = SYSCLK */ + RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1; + /* PCLK2 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1; + /* PCLK1 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2; + + /* CH32V20x_D6-PLL configuration: PLLCLK = HSE * 9 = 72 MHz (HSE=8MHZ) + * CH32V20x_D8-PLL configuration: PLLCLK = HSE/4 * 9 = 72 MHz (HSE=32MHZ) + * CH32V20x_D8W-PLL configuration: PLLCLK = HSE/4 * 9 = 72 MHz (HSE=32MHZ) + */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | + RCC_PLLMULL)); + + RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL9); + + /* Enable PLL */ + RCC->CTLR |= RCC_PLLON; + /* Wait till PLL is ready */ + while((RCC->CTLR & RCC_PLLRDY) == 0) + { + } + /* Select PLL as system clock source */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW)); + RCC->CFGR0 |= (uint32_t)RCC_SW_PLL; + /* Wait till PLL is used as system clock source */ + while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08) + { + } + } + else + { + /* + * If HSE fails to start-up, the application will have wrong clock + * configuration. User can add here some code to deal with this error + */ + } +} + + +#elif defined SYSCLK_FREQ_96MHz_HSE + +/********************************************************************* + * @fn SetSysClockTo96_HSE + * + * @brief Sets System clock frequency to 96MHz and configure HCLK, PCLK2 and PCLK1 prescalers. + * + * @return none + */ +static void SetSysClockTo96_HSE(void) +{ + __IO uint32_t StartUpCounter = 0, HSEStatus = 0; + + RCC->CTLR |= ((uint32_t)RCC_HSEON); + + /* Wait till HSE is ready and if Time out is reached exit */ + do + { + HSEStatus = RCC->CTLR & RCC_HSERDY; + StartUpCounter++; + } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT)); + + if ((RCC->CTLR & RCC_HSERDY) != RESET) + { + HSEStatus = (uint32_t)0x01; + } + else + { + HSEStatus = (uint32_t)0x00; + } + + if (HSEStatus == (uint32_t)0x01) + { + /* HCLK = SYSCLK */ + RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1; + /* PCLK2 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1; + /* PCLK1 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2; + + /* CH32V20x_D6-PLL configuration: PLLCLK = HSE * 12 = 96 MHz (HSE=8MHZ) + * CH32V20x_D8-PLL configuration: PLLCLK = HSE/4 * 12 = 96 MHz (HSE=32MHZ) + * CH32V20x_D8W-PLL configuration: PLLCLK = HSE/4 * 12 = 96 MHz (HSE=32MHZ) + */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | + RCC_PLLMULL)); + + RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL12); + + /* Enable PLL */ + RCC->CTLR |= RCC_PLLON; + /* Wait till PLL is ready */ + while((RCC->CTLR & RCC_PLLRDY) == 0) + { + } + /* Select PLL as system clock source */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW)); + RCC->CFGR0 |= (uint32_t)RCC_SW_PLL; + /* Wait till PLL is used as system clock source */ + while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08) + { + } + } + else + { + /* + * If HSE fails to start-up, the application will have wrong clock + * configuration. User can add here some code to deal with this error + */ + } +} + + +#elif defined SYSCLK_FREQ_120MHz_HSE + +/********************************************************************* + * @fn SetSysClockTo120_HSE + * + * @brief Sets System clock frequency to 120MHz and configure HCLK, PCLK2 and PCLK1 prescalers. + * + * @return none + */ +static void SetSysClockTo120_HSE(void) +{ + __IO uint32_t StartUpCounter = 0, HSEStatus = 0; + + RCC->CTLR |= ((uint32_t)RCC_HSEON); + + /* Wait till HSE is ready and if Time out is reached exit */ + do + { + HSEStatus = RCC->CTLR & RCC_HSERDY; + StartUpCounter++; + } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT)); + + if((RCC->CTLR & RCC_HSERDY) != RESET) + { + HSEStatus = (uint32_t)0x01; + } + else + { + HSEStatus = (uint32_t)0x00; + } + + if(HSEStatus == (uint32_t)0x01) + { +#if defined (CH32V20x_D8W) + RCC->CFGR0 |= (uint32_t)(3<<22); + /* HCLK = SYSCLK/2 */ + RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV2; +#else + /* HCLK = SYSCLK */ + RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1; +#endif + /* PCLK2 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1; + /* PCLK1 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2; + + /* CH32V20x_D6-PLL configuration: PLLCLK = HSE * 15 = 120 MHz (HSE=8MHZ) + * CH32V20x_D8-PLL configuration: PLLCLK = HSE/4 * 15 = 120 MHz (HSE=32MHZ) + * CH32V20x_D8W-PLL configuration: PLLCLK = HSE/2 * 15 = 240 MHz (HSE=32MHZ) + */ + RCC->CFGR0 &= (uint32_t)((uint32_t) ~(RCC_PLLSRC | RCC_PLLXTPRE | + RCC_PLLMULL)); + + RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL15); + + /* Enable PLL */ + RCC->CTLR |= RCC_PLLON; + /* Wait till PLL is ready */ + while((RCC->CTLR & RCC_PLLRDY) == 0) + { + } + /* Select PLL as system clock source */ + RCC->CFGR0 &= (uint32_t)((uint32_t) ~(RCC_SW)); + RCC->CFGR0 |= (uint32_t)RCC_SW_PLL; + /* Wait till PLL is used as system clock source */ + while((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08) + { + } + } + else + { + /* + * If HSE fails to start-up, the application will have wrong clock + * configuration. User can add here some code to deal with this error + */ + } +} +#elif defined SYSCLK_FREQ_144MHz_HSE + +/********************************************************************* + * @fn SetSysClockTo144_HSE + * + * @brief Sets System clock frequency to 144MHz and configure HCLK, PCLK2 and PCLK1 prescalers. + * + * @return none + */ +static void SetSysClockTo144_HSE(void) +{ + __IO uint32_t StartUpCounter = 0, HSEStatus = 0; + + RCC->CTLR |= ((uint32_t)RCC_HSEON); + + /* Wait till HSE is ready and if Time out is reached exit */ + do + { + HSEStatus = RCC->CTLR & RCC_HSERDY; + StartUpCounter++; + } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT)); + + if ((RCC->CTLR & RCC_HSERDY) != RESET) + { + HSEStatus = (uint32_t)0x01; + } + else + { + HSEStatus = (uint32_t)0x00; + } + + if (HSEStatus == (uint32_t)0x01) + { + /* HCLK = SYSCLK */ + RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1; + /* PCLK2 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1; + /* PCLK1 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2; + + /* CH32V20x_D6-PLL configuration: PLLCLK = HSE * 18 = 144 MHz (HSE=8MHZ) + * CH32V20x_D8-PLL configuration: PLLCLK = HSE/4 * 18 = 144 MHz (HSE=32MHZ) + * CH32V20x_D8W-PLL configuration: PLLCLK = HSE/4 * 18 = 144 MHz (HSE=32MHZ) + */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | + RCC_PLLMULL)); + + RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL18); + + /* Enable PLL */ + RCC->CTLR |= RCC_PLLON; + /* Wait till PLL is ready */ + while((RCC->CTLR & RCC_PLLRDY) == 0) + { + } + /* Select PLL as system clock source */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW)); + RCC->CFGR0 |= (uint32_t)RCC_SW_PLL; + /* Wait till PLL is used as system clock source */ + while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08) + { + } + } + else + { + /* + * If HSE fails to start-up, the application will have wrong clock + * configuration. User can add here some code to deal with this error + */ + } +} + +#elif defined SYSCLK_FREQ_48MHz_HSI + +/********************************************************************* + * @fn SetSysClockTo48_HSI + * + * @brief Sets System clock frequency to 48MHz and configure HCLK, PCLK2 and PCLK1 prescalers. + * + * @return none + */ +static void SetSysClockTo48_HSI(void) +{ + EXTEN->EXTEN_CTR |= EXTEN_PLL_HSI_PRE; + + /* HCLK = SYSCLK */ + RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1; + /* PCLK2 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1; + /* PCLK1 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2; + + /* PLL configuration: PLLCLK = HSI * 6 = 48 MHz */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | RCC_PLLMULL)); + + RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSI_Div2 | RCC_PLLMULL6); + + /* Enable PLL */ + RCC->CTLR |= RCC_PLLON; + /* Wait till PLL is ready */ + while((RCC->CTLR & RCC_PLLRDY) == 0) + { + } + /* Select PLL as system clock source */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW)); + RCC->CFGR0 |= (uint32_t)RCC_SW_PLL; + /* Wait till PLL is used as system clock source */ + while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08) + { + } +} + +#elif defined SYSCLK_FREQ_56MHz_HSI + +/********************************************************************* + * @fn SetSysClockTo56_HSI + * + * @brief Sets System clock frequency to 56MHz and configure HCLK, PCLK2 and PCLK1 prescalers. + * + * @return none + */ +static void SetSysClockTo56_HSI(void) +{ + EXTEN->EXTEN_CTR |= EXTEN_PLL_HSI_PRE; + + /* HCLK = SYSCLK */ + RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1; + /* PCLK2 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1; + /* PCLK1 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2; + + /* PLL configuration: PLLCLK = HSI * 7 = 48 MHz */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | RCC_PLLMULL)); + + RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSI_Div2 | RCC_PLLMULL7); + + /* Enable PLL */ + RCC->CTLR |= RCC_PLLON; + /* Wait till PLL is ready */ + while((RCC->CTLR & RCC_PLLRDY) == 0) + { + } + /* Select PLL as system clock source */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW)); + RCC->CFGR0 |= (uint32_t)RCC_SW_PLL; + /* Wait till PLL is used as system clock source */ + while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08) + { + } +} + +#elif defined SYSCLK_FREQ_72MHz_HSI + +/********************************************************************* + * @fn SetSysClockTo72_HSI + * + * @brief Sets System clock frequency to 72MHz and configure HCLK, PCLK2 and PCLK1 prescalers. + * + * @return none + */ +static void SetSysClockTo72_HSI(void) +{ + EXTEN->EXTEN_CTR |= EXTEN_PLL_HSI_PRE; + + /* HCLK = SYSCLK */ + RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1; + /* PCLK2 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1; + /* PCLK1 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2; + + /* PLL configuration: PLLCLK = HSI * 9 = 72 MHz */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | RCC_PLLMULL)); + + RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSI_Div2 | RCC_PLLMULL9); + + /* Enable PLL */ + RCC->CTLR |= RCC_PLLON; + /* Wait till PLL is ready */ + while((RCC->CTLR & RCC_PLLRDY) == 0) + { + } + /* Select PLL as system clock source */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW)); + RCC->CFGR0 |= (uint32_t)RCC_SW_PLL; + /* Wait till PLL is used as system clock source */ + while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08) + { + } +} + + +#elif defined SYSCLK_FREQ_96MHz_HSI + +/********************************************************************* + * @fn SetSysClockTo96_HSI + * + * @brief Sets System clock frequency to 96MHz and configure HCLK, PCLK2 and PCLK1 prescalers. + * + * @return none + */ +static void SetSysClockTo96_HSI(void) +{ + EXTEN->EXTEN_CTR |= EXTEN_PLL_HSI_PRE; + + /* HCLK = SYSCLK */ + RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1; + /* PCLK2 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1; + /* PCLK1 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2; + + /* PLL configuration: PLLCLK = HSI * 12 = 96 MHz */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | RCC_PLLMULL)); + + RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSI_Div2 | RCC_PLLMULL12); + + /* Enable PLL */ + RCC->CTLR |= RCC_PLLON; + /* Wait till PLL is ready */ + while((RCC->CTLR & RCC_PLLRDY) == 0) + { + } + /* Select PLL as system clock source */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW)); + RCC->CFGR0 |= (uint32_t)RCC_SW_PLL; + /* Wait till PLL is used as system clock source */ + while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08) + { + } +} + + +#elif defined SYSCLK_FREQ_120MHz_HSI + +/********************************************************************* + * @fn SetSysClockTo120_HSI + * + * @brief Sets System clock frequency to 120MHz and configure HCLK, PCLK2 and PCLK1 prescalers. + * + * @return none + */ +static void SetSysClockTo120_HSI(void) +{ + EXTEN->EXTEN_CTR |= EXTEN_PLL_HSI_PRE; + + /* HCLK = SYSCLK */ + RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1; + /* PCLK2 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1; + /* PCLK1 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2; + + /* PLL configuration: PLLCLK = HSI * 15 = 120 MHz */ + RCC->CFGR0 &= (uint32_t)((uint32_t) ~(RCC_PLLSRC | RCC_PLLXTPRE | + RCC_PLLMULL)); + + RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSI_Div2 | RCC_PLLMULL15); + + /* Enable PLL */ + RCC->CTLR |= RCC_PLLON; + /* Wait till PLL is ready */ + while((RCC->CTLR & RCC_PLLRDY) == 0) + { + } + /* Select PLL as system clock source */ + RCC->CFGR0 &= (uint32_t)((uint32_t) ~(RCC_SW)); + RCC->CFGR0 |= (uint32_t)RCC_SW_PLL; + /* Wait till PLL is used as system clock source */ + while((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08) + { + } +} +#elif defined SYSCLK_FREQ_144MHz_HSI + +/********************************************************************* + * @fn SetSysClockTo144_HSI + * + * @brief Sets System clock frequency to 144MHz and configure HCLK, PCLK2 and PCLK1 prescalers. + * + * @return none + */ +static void SetSysClockTo144_HSI(void) +{ + EXTEN->EXTEN_CTR |= EXTEN_PLL_HSI_PRE; + + /* HCLK = SYSCLK */ + RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1; + /* PCLK2 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1; + /* PCLK1 = HCLK */ + RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2; + + /* PLL configuration: PLLCLK = HSI * 18 = 144 MHz */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | RCC_PLLMULL)); + + RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSI_Div2 | RCC_PLLMULL18); + + /* Enable PLL */ + RCC->CTLR |= RCC_PLLON; + /* Wait till PLL is ready */ + while((RCC->CTLR & RCC_PLLRDY) == 0) + { + } + /* Select PLL as system clock source */ + RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW)); + RCC->CFGR0 |= (uint32_t)RCC_SW_PLL; + /* Wait till PLL is used as system clock source */ + while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08) + { + } +} + + +#endif diff --git a/EVT/EXAM/APPLICATION/WUI/User/system_ch32v20x.h b/EVT/EXAM/APPLICATION/WUI/User/system_ch32v20x.h new file mode 100644 index 0000000..9c8a3f7 --- /dev/null +++ b/EVT/EXAM/APPLICATION/WUI/User/system_ch32v20x.h @@ -0,0 +1,32 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : system_ch32v20x.h + * Author : WCH + * Version : V1.0.0 + * Date : 2021/06/06 + * Description : CH32V20x Device Peripheral Access Layer System Header File. +********************************************************************************* +* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. +* Attention: This software (modified or not) and binary are used for +* microcontroller manufactured by Nanjing Qinheng Microelectronics. +*******************************************************************************/ +#ifndef __SYSTEM_ch32v20x_H +#define __SYSTEM_ch32v20x_H + +#ifdef __cplusplus + extern "C" { +#endif + +extern uint32_t SystemCoreClock; /* System Clock Frequency (Core Clock) */ + +/* System_Exported_Functions */ +extern void SystemInit(void); +extern void SystemCoreClockUpdate(void); + +#ifdef __cplusplus +} +#endif + +#endif /*__CH32V20x_SYSTEM_H */ + + + diff --git a/EVT/EXAM/APPLICATION/WUI/User/wui/libwui_0.2.a b/EVT/EXAM/APPLICATION/WUI/User/wui/libwui_0.2.a new file mode 100644 index 0000000..5a0528d Binary files /dev/null and b/EVT/EXAM/APPLICATION/WUI/User/wui/libwui_0.2.a differ diff --git a/EVT/EXAM/APPLICATION/WUI/User/wui/wui.h b/EVT/EXAM/APPLICATION/WUI/User/wui/wui.h new file mode 100644 index 0000000..943c6b6 --- /dev/null +++ b/EVT/EXAM/APPLICATION/WUI/User/wui/wui.h @@ -0,0 +1,205 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : wui.h + * Author : WCH + * Version : V1.2.0 + * Date : 2026/07/30 + * Description : This file contains core type definitions, HAL interface, + * event system, and main API functions. + *********************************************************************************/ +#ifndef WUI_H +#define WUI_H + +#include +#include +#include "LCD.h" + + +/******************************************************************************* + * TYPE DEFINITIONS + ******************************************************************************/ + + +typedef struct { + uint32_t addr; + uint16_t width; + uint16_t height; + uint32_t data_size; +} image_info_t; + + +// +#define IMAGE_TYPE_RAW 0x0000 +#define IMAGE_TYPE_RLE 0x2000 +#define IMAGE_TYPE_CLUT 0x4000 +#define IMAGE_TYPE_CLUT4 0x6000 +#define IMAGE_TYPE_MASK 0xE000 +#define IMAGE_INDEX_MASK 0x1FFF +#define MAKE_IMAGE_ID(type, idx) ((type) | ((idx) & IMAGE_INDEX_MASK)) +#define IMAGE_GET_TYPE(id) ((id) & IMAGE_TYPE_MASK) +#define IMAGE_GET_INDEX(id) ((id) & IMAGE_INDEX_MASK) + + +/******************************************************************************* + * HAL CALLBACK TYPES + ******************************************************************************/ + + +typedef void (*wui_touch_read_cb_t)(uint16_t* x, uint16_t* y, uint8_t* pressed); +typedef void (*wui_flash_read_cb_t)(uint8_t* buf, uint32_t addr, uint32_t size); +typedef void (*wui_lcd_set_windows_cb_t)(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2); +typedef void (*wui_lcd_dma_start_cb_t)(void); +typedef void (*wui_lcd_dma_send_cb_t)(const uint8_t* buf, uint32_t len); +typedef void (*wui_lcd_dma_wait_cb_t)(void); +typedef void (*wui_lcd_dma_end_cb_t)(void); + +/******************************************************************************* + * HAL INTERFACE + ******************************************************************************/ + +/* Contains all hardware abstraction layer function pointers */ +typedef struct +{ + wui_touch_read_cb_t touch_read; /* Touch screen read function */ + wui_flash_read_cb_t flash_read; /* Flash read function */ + wui_lcd_set_windows_cb_t lcd_set_windows; /* LCD window set function */ + wui_lcd_dma_start_cb_t lcd_dma_start; /* LCD DMA start function */ + wui_lcd_dma_send_cb_t lcd_dma_send; /* LCD DMA send function */ + wui_lcd_dma_wait_cb_t lcd_dma_wait; /* LCD DMA wait function */ + wui_lcd_dma_end_cb_t lcd_dma_end; /* LCD DMA end function */ +} wui_hal_t; + +/******************************************************************************* + * PAGE DEFINITIONS + ******************************************************************************/ + +/* Page descriptor structure */ +typedef struct +{ + uint16_t bg_color; /* Background color */ + const char* page_name; /* Page name string */ + void (*page_init)(void); /* Page initialization function */ + void (*page_loop)(void); /* Page loop function */ + void* user_data; /* User data pointer */ +} wui_page_desc_t; + +/******************************************************************************* + * INITIALIZATION + ******************************************************************************/ + +/* WUI initialization data structure */ +typedef struct +{ + uint16_t width; /* Display width */ + uint16_t height; /* Display height */ + uint16_t page_count; /* Number of pages */ + uint8_t* heap_addr; /* Heap memory address */ + size_t heap_size; /* Heap memory size */ +} wui_init_data_t; + + + +/******************************************************************************* + * FONT SYSTEM + ******************************************************************************/ + +/* Font structure */ +typedef struct +{ + uint16_t height; /* Font height */ + uint16_t width; /* Font width */ + uint8_t cnt; /* Character count */ + uint8_t start_char; /* Start character */ + uint16_t first_img_id; /* First image ID */ +} wui_font_t; + +/* Bitmap font structure */ +typedef struct +{ + uint8_t width; /* Font width */ + uint8_t height; /* Font height */ + uint8_t start_char; /* Start character */ + uint8_t cnt; /* Character count */ + const uint8_t* data; /* Font data pointer */ +} wui_bitfont_t; + +/******************************************************************************* + * EVENT SYSTEM + ******************************************************************************/ + +/* Event type enumeration */ +typedef enum +{ + WUI_EVENT_NONE = 0, /* No event */ + + WUI_EVENT_TOUCH_DOWN = 1, /* Touch down event */ + WUI_EVENT_TOUCH_MOVE = 2, /* Touch move event */ + WUI_EVENT_TOUCH_LONGPRESS = 3, /* Long press event */ + WUI_EVENT_TOUCH_UP = 4, /* Touch up event */ + + WUI_EVENT_WIDGET_CLICK = 0x10, /* Click event */ + WUI_EVENT_WIDGET_LONG_PRESS = 0x11, /* Long press event */ + WUI_EVENT_WIDGET_CHANGE = 0x20, /* Value change event */ + +} _wui_event_t; + +typedef uint16_t wui_event_t; + +/******************************************************************************* + * TOUCH AREA + ******************************************************************************/ + +typedef struct +{ + uint16_t widget_id; /* Widget ID */ + uint16_t x, y, w, h; /* Touch area position and size */ +} wui_touch_area_t; + +/******************************************************************************* + * VERSION API + ******************************************************************************/ + +const char* wui_get_version(void); + +/******************************************************************************* + * CORE INITIALIZATION API + ******************************************************************************/ + +void wui_init(wui_init_data_t* data); +void wui_register_hal(const wui_hal_t* hal); + + +/******************************************************************************* + * PAGE MANAGEMENT API + ******************************************************************************/ + + +void wui_page_switch(uint16_t page); +void wui_page_ui_init(void); +void wui_page_ui_loop(void); +const wui_page_desc_t* wui_page_get_desc(uint16_t page); +const char* wui_page_get_name(uint16_t page); + +/******************************************************************************* + * UI UPDATE API + ******************************************************************************/ + +uint32_t wui_page_ui_update(void); +void wui_page_ui_tick(uint32_t delta_ms); + +/******************************************************************************* + * KEY EVENT API + ******************************************************************************/ + +void wui_register_key_handler(void (*handler)(uint32_t key)); +void wui_dispatch_key(void); +void wui_set_key_event(uint32_t key); + +/******************************************************************************* + * TOUCH LAYER API + ******************************************************************************/ + + +void wui_register_touch_layer(const wui_touch_area_t* areas, uint8_t count, void (*on_event)(uint16_t widget_id, wui_event_t event)); +void wui_touch_area_set_enabled(uint16_t widget_id, uint8_t enabled); + +#endif /* WUI_H */ \ No newline at end of file diff --git a/EVT/EXAM/APPLICATION/WUI/User/wui/wui_widget.h b/EVT/EXAM/APPLICATION/WUI/User/wui/wui_widget.h new file mode 100644 index 0000000..ce1f92f --- /dev/null +++ b/EVT/EXAM/APPLICATION/WUI/User/wui/wui_widget.h @@ -0,0 +1,304 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : wui_widget.h + * Author : WCH + * Version : V1.2.0 + * Date : 2026/07/30 + * Description : This file contains widget type definitions, properties structures, + * and API functions for widget manipulation. + *********************************************************************************/ +#ifndef WUI_WIDGET_H +#define WUI_WIDGET_H +#include +#include "wui.h" + + +/******************************************************************************* + * TYPE DEFINITIONS + ******************************************************************************/ + +/* Widget ID types */ +typedef uint16_t wui_str_id_t; /* String resource ID */ +typedef uint16_t wui_font_id_t; /* Font resource ID */ +typedef uint16_t wui_bitmap_font_id_t; /* Bitmap font resource ID */ +typedef uint16_t wui_imgtable_id_t; /* Image table resource ID */ +typedef uint16_t wui_swgroup_id_t; /* Switch group resource ID */ + +/******************************************************************************* + * WIDGET TYPES + ******************************************************************************/ + +/** + * @brief Widget type enumeration + */ +typedef enum +{ + Wui_w_None, /* Invalid widget type */ + Wui_w_Anime, /* Animation widget */ + Wui_w_Switch, /* Switch widget */ + Wui_w_Res0, /* Reserved 0 */ + Wui_w_MultiState, /* Multi-state widget */ + Wui_w_StaticImage, /* Static image widget */ + Wui_w_QRCode, /* QR code widget */ + Wui_w_Rect, /* Rectangle widget */ + Wui_w_Res1, /* Reserved 1 */ + Wui_w_Res2, /* Reserved 2 */ + Wui_w_Res3, /* Reserved 3 */ + Wui_w_ProgressBar, /* Progress bar widget */ + Wui_w_Button, /* Button widget */ + Wui_w_ImgSlider, /* Image slider widget */ + Wui_w_SimpleString, /* Simple string widget */ + Wui_w_ExString, /* Extended string widget */ + Wui_w_COUNT /* Widget type count */ +} _wui_widget_type_t; + +typedef uint16_t wui_widget_type_t; + +/******************************************************************************* + * CONSTANTS & MACROS + ******************************************************************************/ + +/* Progress bar direction */ +#define WUI_PB_HORIZONTAL 0 /* Horizontal progress bar */ +#define WUI_PB_VERTICAL 1 /* Vertical progress bar */ + +/* Image slider direction */ +#define WUI_IMGSLIDER_HORIZONTAL 0 /* Horizontal image slider */ +#define WUI_IMGSLIDER_VERTICAL 1 /* Vertical image slider */ + +/* Simple string alignment */ +#define WUI_SIMPLESTRING_ALIGN_LEFT 0 /* Left alignment */ +#define WUI_SIMPLESTRING_ALIGN_RIGHT 1 /* Right alignment */ +#define WUI_SIMPLESTRING_ALIGN_CENTER 2 /* Center alignment */ + +/* Extended string type */ +#define WUI_EXSTRING_TYPE_NORMAL 0 /* Normal type */ + +/* Extended string alignment */ +#define WUI_EXSTRING_ALIGN_LEFT 0 /* Left alignment */ +#define WUI_EXSTRING_ALIGN_RIGHT 1 /* Right alignment */ +#define WUI_EXSTRING_ALIGN_CENTER 2 /* Center alignment */ + +/******************************************************************************* + * WIDGET PROPERTIES + ******************************************************************************/ + +/* Animation widget properties */ +typedef struct +{ + uint16_t start_img_id; /* Start image ID */ + uint16_t frame_count; /* Total frame count */ + uint8_t fps; /* Frames per second */ + uint8_t loop; /* Loop mode (0: no loop, 1: loop) */ +} wui_widget_anime_props_t; + +/* Switch widget properties*/ +typedef struct +{ + uint16_t on_img_id; /* ON state image ID */ + uint16_t off_img_id; /* OFF state image ID */ + uint8_t is_on; /* Current state (0: OFF, 1: ON) */ +} wui_widget_switch_props_t; + +/* Multi-state widget properties */ +typedef struct +{ + wui_imgtable_id_t imgtable_id; /* Image table ID */ + uint8_t state_count; /* Number of states */ + uint8_t default_state; /* Default state index */ +} wui_widget_multistate_props_t; + +/* Static image widget properties */ +typedef struct +{ + uint16_t img_id; /* Image ID */ +} wui_widget_staticimg_props_t; + +/* QR code widget properties */ +typedef struct +{ + uint16_t img_id; /* Image ID */ +} wui_widget_qrcode_props_t; + +/* Rectangle widget properties */ +typedef struct +{ + uint16_t color; /* Rectangle color */ +} wui_widget_rect_props_t; + +/* Button widget properties */ +typedef struct +{ + uint16_t normal_img_id; /* Normal state image ID */ + uint16_t pressed_img_id; /* Pressed state image ID */ + uint8_t is_pressed; /* Current state (0: released, 1: pressed) */ +} wui_widget_button_props_t; + +/* Progress bar widget properties */ +typedef struct +{ + uint8_t direction; /* Direction (HORIZONTAL/VERTICAL) */ + uint8_t min_value; /* Minimum value */ + uint8_t max_value; /* Maximum value */ + uint8_t current_value; /* Current value */ + uint16_t bg_color; /* Background color */ + uint16_t fill_color; /* Fill color */ + uint16_t thumb_color; /* Thumb color */ + uint16_t thumb_w; /* Thumb width */ +} wui_widget_pb_props_t; + +/* Image slider widget properties */ +typedef struct +{ + uint16_t full_img_id; /* Full image ID , Must be in raw format */ + uint16_t empty_img_id; /* Empty image ID , Must be in raw format*/ + uint8_t current_value; /* Initialization percentage (0-100) */ + uint8_t direction; /* Direction (HORIZONTAL/VERTICAL) */ +} wui_widget_imgslider_props_t; + +/* Simple string widget properties */ +typedef struct +{ + wui_str_id_t str_id; /* String resource ID */ + uint16_t fg_color; /* Foreground color */ + uint16_t bg_color; /* Background color */ + uint8_t align; /* Alignment (LEFT/RIGHT/CENTER) */ + wui_bitmap_font_id_t font_id; /* Bitmap font ID */ +} wui_widget_simplestring_props_t; + +/* Extended string widget properties */ +typedef struct +{ + uint8_t type; /* String type */ + uint8_t align; /* Alignment (LEFT/RIGHT/CENTER) */ + union + { + struct + { + uint16_t fg_color; /* Foreground color */ + uint16_t bg_color; /* Background color */ + }; + void* res; /* Reserved pointer */ + }; + wui_str_id_t str_id; /* String resource ID */ + wui_font_id_t font_id; /* Font ID */ +} wui_widget_exstring_props_t; + + + +/******************************************************************************* + * WIDGET DESCRIPTOR + ******************************************************************************/ + +/* This is the main structure for defining a widget */ +typedef struct +{ + uint16_t widget_id; /* Unique widget ID */ + uint16_t type; /* Widget type */ + uint16_t x, y, w, h; /* Widget position and size */ + uint8_t flags; /* Widget flags */ + union + { + wui_widget_anime_props_t anime; /* Animation properties */ + wui_widget_switch_props_t switch_; /* Switch properties */ + // wui_widget_swgroup_props_t swgroup; /* Switch group properties */ + wui_widget_multistate_props_t multistate; /* Multi-state properties */ + wui_widget_staticimg_props_t staticimg; /* Static image properties */ + wui_widget_qrcode_props_t qrcode; /* QR code properties */ + wui_widget_rect_props_t rect; /* Rectangle properties */ + wui_widget_pb_props_t progress; /* Progress bar properties */ + wui_widget_button_props_t button; /* Button properties */ + wui_widget_imgslider_props_t imgslider; /* Image slider properties */ + wui_widget_simplestring_props_t simplestring; /* Simple string properties */ + wui_widget_exstring_props_t exstring; /* Extended string properties */ + } props; +} wui_widget_desc_t; + +/******************************************************************************* + * API FUNCTIONS + ******************************************************************************/ + + +void wui_page_init(const wui_widget_desc_t* widgets, uint8_t widget_count); + +/******************************************************************************* + * ANIMATION API + ******************************************************************************/ + +void wui_widget_anime_play(uint16_t widget_id); +void wui_widget_anime_pause(uint16_t widget_id); +void wui_widget_anime_reset(uint16_t widget_id); +uint8_t wui_widget_anime_is_completed(uint16_t widget_id); + +/******************************************************************************* + * SWITCH API + ******************************************************************************/ + +void wui_widget_switch_toggle(uint16_t widget_id); +void wui_widget_switch_set_on(uint16_t widget_id, uint8_t on); +uint8_t wui_widget_switch_is_on(uint16_t widget_id); + +/******************************************************************************* + * MULTI-STATE API + ******************************************************************************/ + +void wui_widget_multistate_next(uint16_t widget_id); +void wui_widget_multistate_prev(uint16_t widget_id); +void wui_widget_multistate_set_index(uint16_t widget_id, uint8_t index); +uint8_t wui_widget_multistate_get_index(uint16_t widget_id); + +/******************************************************************************* + * STATIC IMAGE API + ******************************************************************************/ + +uint16_t wui_widget_staticimg_get_img_id(uint16_t widget_id); +void wui_widget_staticimg_set_img_id(uint16_t widget_id, uint16_t img_id); + +/******************************************************************************* + * RECTANGLE API + ******************************************************************************/ + +void wui_widget_rect_set_color(uint16_t widget_id, uint16_t color); +uint16_t wui_widget_rect_get_color(uint16_t widget_id); + +/******************************************************************************* + * PROGRESS BAR API + ******************************************************************************/ + +void wui_widget_pb_set_value(uint16_t widget_id, uint8_t value); +uint8_t wui_widget_pb_get_value(uint16_t widget_id); + +/******************************************************************************* + * IMAGE SLIDER API + ******************************************************************************/ + +void wui_widget_imgslider_set_value(uint16_t widget_id, uint8_t current_value); +uint8_t wui_widget_imgslider_get_value(uint16_t widget_id); + +/******************************************************************************* + * BUTTON API + ******************************************************************************/ + +void wui_widget_button_press(uint16_t widget_id); +void wui_widget_button_release(uint16_t widget_id); +uint8_t wui_widget_button_is_pressed(uint16_t widget_id); + +/******************************************************************************* + * SIMPLE STRING API + ******************************************************************************/ + +void wui_widget_simplestring_set_str(uint16_t widget_id, const char* str); +const char* wui_widget_simplestring_get_str(uint16_t widget_id); +void wui_widget_simplestring_set_align(uint16_t widget_id, uint8_t align); +uint8_t wui_widget_simplestring_get_align(uint16_t widget_id); +void wui_widget_simplestring_set_color(uint16_t widget_id, uint16_t fg_color, uint16_t bg_color); + +/******************************************************************************* + * EXTENDED STRING API + ******************************************************************************/ + +void wui_widget_exstring_set_str(uint16_t widget_id, const char* str); +const char* wui_widget_exstring_get_str(uint16_t widget_id); +void wui_widget_exstring_set_align(uint16_t widget_id, uint8_t align); +uint8_t wui_widget_exstring_get_align(uint16_t widget_id); + +#endif /* WUI_WIDGET_H */ \ No newline at end of file diff --git a/EVT/EXAM/APPLICATION/WUI/User/wui_port/wui_port.c b/EVT/EXAM/APPLICATION/WUI/User/wui_port/wui_port.c new file mode 100644 index 0000000..41a2eeb --- /dev/null +++ b/EVT/EXAM/APPLICATION/WUI/User/wui_port/wui_port.c @@ -0,0 +1,150 @@ +#include "wui.h" +#include "wui_port.h" +#include +#include +#include +#include +#include "flash.h" +#include "images.h" +#include "LCD.h" +#include "spi.h" + +void HW_Key_event(uint32_t _key_code) +{ + printf("[KEY] press %c\n", _key_code); + wui_set_key_event(_key_code); +} + +/********************************************************************* + * @fn touch_read + * + * @brief Read touch screen coordinates and pressed state. + * v203 has no touch screen, so touch is disabled. + * + * @param x - Pointer to store X coordinate. + * @param y - Pointer to store Y coordinate. + * @param pressed - Pointer to store pressed state. + * + * @return none + */ +static void touch_read(uint16_t* x, uint16_t* y, uint8_t* pressed) +{ + *x = 0; + *y = 0; + *pressed = 0; +} + +/********************************************************************* + * @fn spi_flash_read + * + * @brief Read data from SPI Flash. + * + * @param outBuffer - Pointer to data buffer to store read data. + * @param ReadAddr - Start address to read from. + * @param size - Number of bytes to read. + * + * @return none + */ +static void spi_flash_read(uint8_t* outBuffer, uint32_t ReadAddr, uint32_t size) +{ + SPI_Flash_Read_dma_start(ReadAddr); + SPI1_Read_DMA(outBuffer, (uint16_t)size); + SPI1_wait_for_bsy(); + SPI_Flash_Read_dma_end(); +} + +/********************************************************************* + * @fn lcd_set_windows + * + * @brief Set LCD display window. + * + * @param x_start - Start X coordinate. + * @param y_start - Start Y coordinate. + * @param x_end - End X coordinate. + * @param y_end - End Y coordinate. + * + * @return none + */ +static void lcd_set_windows(uint16_t x_start, uint16_t y_start, uint16_t x_end, uint16_t y_end) +{ + LCD_SetWindows(x_start, y_start, x_end, y_end); +} + +/********************************************************************* + * @fn lcd_dma_start + * + * @brief Start LCD data transfer. + * + * @return none + */ +static void lcd_dma_start(void) +{ + LCD_DC_SET(); + LCD_CS_CLR(); +} + +/********************************************************************* + * @fn lcd_dma_send + * + * @brief Send data via LCD DMA. + * + * @param buf - Pointer to data buffer to send. + * @param len - Length of data in bytes. + * + * @return none + */ +static void lcd_dma_send(const uint8_t* buf, uint32_t len) +{ + SPI2_Write_DMA((uint8_t*)buf, (uint16_t)len); +} + +/********************************************************************* + * @fn lcd_dma_wait + * + * @brief Wait for LCD DMA transfer to complete. + * + * @return none + */ +static void lcd_dma_wait(void) +{ + while (SPI2_DMA_TX_CH->CNTR > 0) + { + } + + while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_BSY) == SET) + ; +} + +/********************************************************************* + * @fn lcd_dma_end + * + * @brief End LCD DMA transfer. + * + * @return none + */ +static void lcd_dma_end(void) +{ + LCD_CS_SET(); +} + +/********************************************************************* + * @fn wui_get_hal + * + * @brief Get WUI HAL interface structure. + * + * @return Pointer to HAL interface structure. + */ +const wui_hal_t* wui_get_hal(void) +{ + static const wui_hal_t hal = { + .touch_read = touch_read, + .flash_read = spi_flash_read, + .lcd_set_windows = lcd_set_windows, + .lcd_dma_start = lcd_dma_start, + .lcd_dma_send = lcd_dma_send, + .lcd_dma_wait = lcd_dma_wait, + .lcd_dma_end = lcd_dma_end, + }; + + return &hal; +} diff --git a/EVT/EXAM/APPLICATION/WUI/User/wui_port/wui_port.h b/EVT/EXAM/APPLICATION/WUI/User/wui_port/wui_port.h new file mode 100644 index 0000000..00e8c15 --- /dev/null +++ b/EVT/EXAM/APPLICATION/WUI/User/wui_port/wui_port.h @@ -0,0 +1,11 @@ +#ifndef __WUI_PORT_H +#define __WUI_PORT_H + +#include +#include "wui.h" + +void HW_Key_event(uint32_t _key_code); + +const wui_hal_t* wui_get_hal(void); + +#endif // __WUI_PORT_H diff --git a/EVT/EXAM/APPLICATION/WUI/User/wui_user/images.bin b/EVT/EXAM/APPLICATION/WUI/User/wui_user/images.bin new file mode 100644 index 0000000..356fc7e Binary files /dev/null and b/EVT/EXAM/APPLICATION/WUI/User/wui_user/images.bin differ diff --git a/EVT/EXAM/APPLICATION/WUI/User/wui_user/images.h b/EVT/EXAM/APPLICATION/WUI/User/wui_user/images.h new file mode 100644 index 0000000..2c41b7b --- /dev/null +++ b/EVT/EXAM/APPLICATION/WUI/User/wui_user/images.h @@ -0,0 +1,377 @@ +/** + * @file images.h + * @brief Image resource table generated by WCHGUIDesigner. + * @note Byte order: Big Endian + */ + +#ifndef _IMAGES_H_ +#define _IMAGES_H_ + +#include +#include + +typedef enum { + IMAGE_NONE = 0xFFFF, + // === Raw images (0b000) === + IMAGE_ART_WUI_PAGE_MAIN_MAIN_TIME_0030 = MAKE_IMAGE_ID(IMAGE_TYPE_RAW, 0), + IMAGE_ART_WUI_PAGE_MAIN_MAIN_TIME_0031 = MAKE_IMAGE_ID(IMAGE_TYPE_RAW, 1), + IMAGE_ART_WUI_PAGE_MAIN_MAIN_TIME_0032 = MAKE_IMAGE_ID(IMAGE_TYPE_RAW, 2), + IMAGE_ART_WUI_PAGE_MAIN_MAIN_TIME_0033 = MAKE_IMAGE_ID(IMAGE_TYPE_RAW, 3), + IMAGE_ART_WUI_PAGE_MAIN_MAIN_TIME_0034 = MAKE_IMAGE_ID(IMAGE_TYPE_RAW, 4), + IMAGE_ART_WUI_PAGE_MAIN_MAIN_TIME_0035 = MAKE_IMAGE_ID(IMAGE_TYPE_RAW, 5), + IMAGE_ART_WUI_PAGE_MAIN_MAIN_TIME_0036 = MAKE_IMAGE_ID(IMAGE_TYPE_RAW, 6), + IMAGE_ART_WUI_PAGE_MAIN_MAIN_TIME_0037 = MAKE_IMAGE_ID(IMAGE_TYPE_RAW, 7), + IMAGE_ART_WUI_PAGE_MAIN_MAIN_TIME_0038 = MAKE_IMAGE_ID(IMAGE_TYPE_RAW, 8), + IMAGE_ART_WUI_PAGE_MAIN_MAIN_TIME_0039 = MAKE_IMAGE_ID(IMAGE_TYPE_RAW, 9), + IMAGE_ART_WUI_PAGE_MAIN_MAIN_TIME_003A = MAKE_IMAGE_ID(IMAGE_TYPE_RAW, 10), + // === CLUT images (0b010) === + IMAGE_RES_IMG_TPL_MAIN_PAGELIGHTCFG1 = MAKE_IMAGE_ID(IMAGE_TYPE_CLUT, 11), + IMAGE_RES_IMG_TPL_MAIN_PAGELIGHTCFG2 = MAKE_IMAGE_ID(IMAGE_TYPE_CLUT, 12), + IMAGE_RES_IMG_TPL_MAIN_PAGELIGHTCOLOR1 = MAKE_IMAGE_ID(IMAGE_TYPE_CLUT, 13), + IMAGE_RES_IMG_TPL_MAIN_PAGELIGHTCOLOR2 = MAKE_IMAGE_ID(IMAGE_TYPE_CLUT, 14), + IMAGE_RES_IMG_TPL_MAIN_PAGERELDATA1 = MAKE_IMAGE_ID(IMAGE_TYPE_CLUT, 15), + IMAGE_RES_IMG_TPL_MAIN_PAGERELDATA2 = MAKE_IMAGE_ID(IMAGE_TYPE_CLUT, 16), + IMAGE_RES_IMG_TPL_MAIN_PAGEANIMAL1 = MAKE_IMAGE_ID(IMAGE_TYPE_CLUT, 17), + IMAGE_RES_IMG_TPL_MAIN_PAGEANIMAL2 = MAKE_IMAGE_ID(IMAGE_TYPE_CLUT, 18), + IMAGE_RES_IMG_TPL_MAIN_PAGEMODEL1 = MAKE_IMAGE_ID(IMAGE_TYPE_CLUT, 19), + IMAGE_RES_IMG_TPL_MAIN_PAGEMODEL2 = MAKE_IMAGE_ID(IMAGE_TYPE_CLUT, 20), + IMAGE_RES_IMG_TPL_MAIN_PAGESETTING1 = MAKE_IMAGE_ID(IMAGE_TYPE_CLUT, 21), + IMAGE_RES_IMG_TPL_MAIN_PAGESETTING2 = MAKE_IMAGE_ID(IMAGE_TYPE_CLUT, 22), + IMAGE_RES_IMG_TPL_MAIN_BAT00 = MAKE_IMAGE_ID(IMAGE_TYPE_CLUT, 23), + IMAGE_RES_IMG_TPL_MAIN_BAT01 = MAKE_IMAGE_ID(IMAGE_TYPE_CLUT, 24), + IMAGE_RES_IMG_TPL_MAIN_BAT02 = MAKE_IMAGE_ID(IMAGE_TYPE_CLUT, 25), + IMAGE_RES_IMG_TPL_MAIN_BAT03 = MAKE_IMAGE_ID(IMAGE_TYPE_CLUT, 26), + IMAGE_RES_IMG_TPL_MAIN_BAT04 = MAKE_IMAGE_ID(IMAGE_TYPE_CLUT, 27), + IMAGE_RES_IMG_TPL_MAIN_BAT05 = MAKE_IMAGE_ID(IMAGE_TYPE_CLUT, 28), + IMAGE_RES_IMG_TPL_MAIN_BAT06 = MAKE_IMAGE_ID(IMAGE_TYPE_CLUT, 29), + IMAGE_RES_IMG_TPL_MAIN_BAT07 = MAKE_IMAGE_ID(IMAGE_TYPE_CLUT, 30), + IMAGE_RES_IMG_TPL_MAIN_BAT08 = MAKE_IMAGE_ID(IMAGE_TYPE_CLUT, 31), + IMAGE_RES_IMG_TPL_MAIN_BAT09 = MAKE_IMAGE_ID(IMAGE_TYPE_CLUT, 32), + IMAGE_RES_IMG_TPL_MAIN_BAT10 = MAKE_IMAGE_ID(IMAGE_TYPE_CLUT, 33), + IMAGE_RES_IMG_TPL_MAIN_BAT11 = MAKE_IMAGE_ID(IMAGE_TYPE_CLUT, 34), + IMAGE_RES_IMG_TPL_MAIN_BAT12 = MAKE_IMAGE_ID(IMAGE_TYPE_CLUT, 35), + IMAGE_RES_IMG_TPL_MAIN_BAT13 = MAKE_IMAGE_ID(IMAGE_TYPE_CLUT, 36), + IMAGE_RES_IMG_TPL_MAIN_BAT14 = MAKE_IMAGE_ID(IMAGE_TYPE_CLUT, 37), + IMAGE_RES_IMG_TPL_MAIN_BAT15 = MAKE_IMAGE_ID(IMAGE_TYPE_CLUT, 38), + IMAGE_RES_IMG_TPL_MAIN_BAT16 = MAKE_IMAGE_ID(IMAGE_TYPE_CLUT, 39), + IMAGE_RES_IMG_TPL_MAIN_BAT17 = MAKE_IMAGE_ID(IMAGE_TYPE_CLUT, 40), + IMAGE_RES_IMG_TPL_MAIN_BAT18 = MAKE_IMAGE_ID(IMAGE_TYPE_CLUT, 41), + IMAGE_RES_IMG_TPL_MAIN_BAT19 = MAKE_IMAGE_ID(IMAGE_TYPE_CLUT, 42), + IMAGE_RES_IMG_TPL_MAIN_BAT20 = MAKE_IMAGE_ID(IMAGE_TYPE_CLUT, 43), + IMAGE_RES_IMG_TPL_MAIN_BAT21 = MAKE_IMAGE_ID(IMAGE_TYPE_CLUT, 44), + IMAGE_RES_IMG_TPL_MAIN_CON1 = MAKE_IMAGE_ID(IMAGE_TYPE_CLUT, 45), + IMAGE_RES_IMG_TPL_MAIN_CON2 = MAKE_IMAGE_ID(IMAGE_TYPE_CLUT, 46), + IMAGE_RES_IMG_TPL_MAIN_CON3 = MAKE_IMAGE_ID(IMAGE_TYPE_CLUT, 47), + IMAGE_RES_IMG_TPL_MAIN_BG = MAKE_IMAGE_ID(IMAGE_TYPE_CLUT, 48), +} image_index_t; + +static const image_info_t image_table[] = { + { // IMAGE_ART_WUI_PAGE_MAIN_MAIN_TIME_0030 + .addr = 0x0001DED4, + .width = 10, + .height = 26, + .data_size = 520, + }, + { // IMAGE_ART_WUI_PAGE_MAIN_MAIN_TIME_0031 + .addr = 0x0001E0DC, + .width = 10, + .height = 26, + .data_size = 520, + }, + { // IMAGE_ART_WUI_PAGE_MAIN_MAIN_TIME_0032 + .addr = 0x0001E2E4, + .width = 10, + .height = 26, + .data_size = 520, + }, + { // IMAGE_ART_WUI_PAGE_MAIN_MAIN_TIME_0033 + .addr = 0x0001E4EC, + .width = 10, + .height = 26, + .data_size = 520, + }, + { // IMAGE_ART_WUI_PAGE_MAIN_MAIN_TIME_0034 + .addr = 0x0001E6F4, + .width = 10, + .height = 26, + .data_size = 520, + }, + { // IMAGE_ART_WUI_PAGE_MAIN_MAIN_TIME_0035 + .addr = 0x0001E8FC, + .width = 10, + .height = 26, + .data_size = 520, + }, + { // IMAGE_ART_WUI_PAGE_MAIN_MAIN_TIME_0036 + .addr = 0x0001EB04, + .width = 10, + .height = 26, + .data_size = 520, + }, + { // IMAGE_ART_WUI_PAGE_MAIN_MAIN_TIME_0037 + .addr = 0x0001ED0C, + .width = 10, + .height = 26, + .data_size = 520, + }, + { // IMAGE_ART_WUI_PAGE_MAIN_MAIN_TIME_0038 + .addr = 0x0001EF14, + .width = 10, + .height = 26, + .data_size = 520, + }, + { // IMAGE_ART_WUI_PAGE_MAIN_MAIN_TIME_0039 + .addr = 0x0001F11C, + .width = 10, + .height = 26, + .data_size = 520, + }, + { // IMAGE_ART_WUI_PAGE_MAIN_MAIN_TIME_003A + .addr = 0x0001F324, + .width = 10, + .height = 26, + .data_size = 520, + }, + { // IMAGE_RES_IMG_TPL_MAIN_PAGELIGHTCFG1 + .addr = 0x00000000, + .width = 73, + .height = 99, + .data_size = 7739, + }, + { // IMAGE_RES_IMG_TPL_MAIN_PAGELIGHTCFG2 + .addr = 0x00001E3C, + .width = 73, + .height = 99, + .data_size = 7739, + }, + { // IMAGE_RES_IMG_TPL_MAIN_PAGELIGHTCOLOR1 + .addr = 0x00003C78, + .width = 73, + .height = 99, + .data_size = 7739, + }, + { // IMAGE_RES_IMG_TPL_MAIN_PAGELIGHTCOLOR2 + .addr = 0x00005AB4, + .width = 73, + .height = 99, + .data_size = 7739, + }, + { // IMAGE_RES_IMG_TPL_MAIN_PAGERELDATA1 + .addr = 0x000078F0, + .width = 73, + .height = 99, + .data_size = 7739, + }, + { // IMAGE_RES_IMG_TPL_MAIN_PAGERELDATA2 + .addr = 0x0000972C, + .width = 73, + .height = 99, + .data_size = 7739, + }, + { // IMAGE_RES_IMG_TPL_MAIN_PAGEANIMAL1 + .addr = 0x0000B568, + .width = 73, + .height = 99, + .data_size = 7739, + }, + { // IMAGE_RES_IMG_TPL_MAIN_PAGEANIMAL2 + .addr = 0x0000D3A4, + .width = 73, + .height = 99, + .data_size = 7739, + }, + { // IMAGE_RES_IMG_TPL_MAIN_PAGEMODEL1 + .addr = 0x0000F1E0, + .width = 73, + .height = 99, + .data_size = 7739, + }, + { // IMAGE_RES_IMG_TPL_MAIN_PAGEMODEL2 + .addr = 0x0001101C, + .width = 73, + .height = 99, + .data_size = 7739, + }, + { // IMAGE_RES_IMG_TPL_MAIN_PAGESETTING1 + .addr = 0x00012E58, + .width = 73, + .height = 99, + .data_size = 7739, + }, + { // IMAGE_RES_IMG_TPL_MAIN_PAGESETTING2 + .addr = 0x00014C94, + .width = 73, + .height = 99, + .data_size = 7739, + }, + { // IMAGE_RES_IMG_TPL_MAIN_BAT00 + .addr = 0x00016AD0, + .width = 26, + .height = 26, + .data_size = 1188, + }, + { // IMAGE_RES_IMG_TPL_MAIN_BAT01 + .addr = 0x00016F74, + .width = 26, + .height = 26, + .data_size = 1188, + }, + { // IMAGE_RES_IMG_TPL_MAIN_BAT02 + .addr = 0x00017418, + .width = 26, + .height = 26, + .data_size = 1188, + }, + { // IMAGE_RES_IMG_TPL_MAIN_BAT03 + .addr = 0x000178BC, + .width = 26, + .height = 26, + .data_size = 1188, + }, + { // IMAGE_RES_IMG_TPL_MAIN_BAT04 + .addr = 0x00017D60, + .width = 26, + .height = 26, + .data_size = 1188, + }, + { // IMAGE_RES_IMG_TPL_MAIN_BAT05 + .addr = 0x00018204, + .width = 26, + .height = 26, + .data_size = 1188, + }, + { // IMAGE_RES_IMG_TPL_MAIN_BAT06 + .addr = 0x000186A8, + .width = 26, + .height = 26, + .data_size = 1188, + }, + { // IMAGE_RES_IMG_TPL_MAIN_BAT07 + .addr = 0x00018B4C, + .width = 26, + .height = 26, + .data_size = 1188, + }, + { // IMAGE_RES_IMG_TPL_MAIN_BAT08 + .addr = 0x00018FF0, + .width = 26, + .height = 26, + .data_size = 1188, + }, + { // IMAGE_RES_IMG_TPL_MAIN_BAT09 + .addr = 0x00019494, + .width = 26, + .height = 26, + .data_size = 1188, + }, + { // IMAGE_RES_IMG_TPL_MAIN_BAT10 + .addr = 0x00019938, + .width = 26, + .height = 26, + .data_size = 1188, + }, + { // IMAGE_RES_IMG_TPL_MAIN_BAT11 + .addr = 0x00019DDC, + .width = 26, + .height = 26, + .data_size = 1188, + }, + { // IMAGE_RES_IMG_TPL_MAIN_BAT12 + .addr = 0x0001A280, + .width = 26, + .height = 26, + .data_size = 1188, + }, + { // IMAGE_RES_IMG_TPL_MAIN_BAT13 + .addr = 0x0001A724, + .width = 26, + .height = 26, + .data_size = 1188, + }, + { // IMAGE_RES_IMG_TPL_MAIN_BAT14 + .addr = 0x0001ABC8, + .width = 26, + .height = 26, + .data_size = 1188, + }, + { // IMAGE_RES_IMG_TPL_MAIN_BAT15 + .addr = 0x0001B06C, + .width = 26, + .height = 26, + .data_size = 1188, + }, + { // IMAGE_RES_IMG_TPL_MAIN_BAT16 + .addr = 0x0001B510, + .width = 26, + .height = 26, + .data_size = 1188, + }, + { // IMAGE_RES_IMG_TPL_MAIN_BAT17 + .addr = 0x0001B9B4, + .width = 26, + .height = 26, + .data_size = 1188, + }, + { // IMAGE_RES_IMG_TPL_MAIN_BAT18 + .addr = 0x0001BE58, + .width = 26, + .height = 26, + .data_size = 1188, + }, + { // IMAGE_RES_IMG_TPL_MAIN_BAT19 + .addr = 0x0001C2FC, + .width = 26, + .height = 26, + .data_size = 1188, + }, + { // IMAGE_RES_IMG_TPL_MAIN_BAT20 + .addr = 0x0001C7A0, + .width = 26, + .height = 26, + .data_size = 1188, + }, + { // IMAGE_RES_IMG_TPL_MAIN_BAT21 + .addr = 0x0001CC44, + .width = 26, + .height = 26, + .data_size = 1188, + }, + { // IMAGE_RES_IMG_TPL_MAIN_CON1 + .addr = 0x0001D0E8, + .width = 26, + .height = 26, + .data_size = 1188, + }, + { // IMAGE_RES_IMG_TPL_MAIN_CON2 + .addr = 0x0001D58C, + .width = 26, + .height = 26, + .data_size = 1188, + }, + { // IMAGE_RES_IMG_TPL_MAIN_CON3 + .addr = 0x0001DA30, + .width = 26, + .height = 26, + .data_size = 1188, + }, + { // IMAGE_RES_IMG_TPL_MAIN_BG + .addr = 0x0001F52C, + .width = 320, + .height = 240, + .data_size = 77312, + }, +}; + +#define RAW_IMAGE_COUNT 11 +#define RLE_IMAGE_COUNT 0 +#define CLUT_IMAGE_COUNT 38 +#define CLUT4_IMAGE_COUNT 0 +#define IMAGE_COUNT 49 + +static inline const image_info_t* get_image(image_index_t index) { + uint16_t idx = IMAGE_GET_INDEX(index); + if (idx >= IMAGE_COUNT) return NULL; + return &image_table[idx]; +} + +#endif /* _IMAGES_H_ */ diff --git a/EVT/EXAM/APPLICATION/WUI/User/wui_user/wui_asset.c b/EVT/EXAM/APPLICATION/WUI/User/wui_user/wui_asset.c new file mode 100644 index 0000000..e71e943 --- /dev/null +++ b/EVT/EXAM/APPLICATION/WUI/User/wui_user/wui_asset.c @@ -0,0 +1,170 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : wui_asset.c + * Author : WCH + * Version : V1.2.0 + * Date : 2026/07/30 + * Description : This file is auto-generated by WUI Designer Tool. + * : Contains WUI asset resources (strings, images, fonts). + ********************************************************************************* + * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. + * Attention: This software (modified or not) and binary are used for + * microcontroller manufactured by Nanjing Qinheng Microelectronics. + *******************************************************************************/ + +#include "wui_asset.h" +#include + +#include "LCD_Font.h" +const wui_bitfont_t wui_font_6x12 = { 6, 12, 0x20, 95, (const uint8_t*)asc2_1206 }; +const wui_bitfont_t wui_font_8x16 = { 8, 16, 0x20, 95, (const uint8_t*)asc2_1608 }; + +/******************************************************************************* + * STRING RESOURCES + ******************************************************************************/ + +/* Maps string IDs to string pointers */ +static const char* wui_string_table[WUI_STR_COUNT] = { + [WUI_STR_NONE] = NULL, + [WUI_STR_MAIN_MAIN_TIME] = "12:34", +}; + +/** + * @brief Get string by ID + * @param id - String ID + * @return String pointer, or NULL if not found + */ +const char* wui_get_string(wui_str_id_t id) +{ + if (id > 0 && id < WUI_STR_COUNT) + { + return wui_string_table[id]; + } + return NULL; +} + +/******************************************************************************* + * IMAGE TABLE RESOURCES + ******************************************************************************/ + + +static const uint16_t wui_imgtable_main_main_battery[] = { + IMAGE_RES_IMG_TPL_MAIN_BAT00, + IMAGE_RES_IMG_TPL_MAIN_BAT01, + IMAGE_RES_IMG_TPL_MAIN_BAT02, + IMAGE_RES_IMG_TPL_MAIN_BAT03, + IMAGE_RES_IMG_TPL_MAIN_BAT04, + IMAGE_RES_IMG_TPL_MAIN_BAT05, + IMAGE_RES_IMG_TPL_MAIN_BAT06, + IMAGE_RES_IMG_TPL_MAIN_BAT07, + IMAGE_RES_IMG_TPL_MAIN_BAT08, + IMAGE_RES_IMG_TPL_MAIN_BAT09, + IMAGE_RES_IMG_TPL_MAIN_BAT10, + IMAGE_RES_IMG_TPL_MAIN_BAT11, + IMAGE_RES_IMG_TPL_MAIN_BAT12, + IMAGE_RES_IMG_TPL_MAIN_BAT13, + IMAGE_RES_IMG_TPL_MAIN_BAT14, + IMAGE_RES_IMG_TPL_MAIN_BAT15, + IMAGE_RES_IMG_TPL_MAIN_BAT16, + IMAGE_RES_IMG_TPL_MAIN_BAT17, + IMAGE_RES_IMG_TPL_MAIN_BAT18, + IMAGE_RES_IMG_TPL_MAIN_BAT19, + IMAGE_RES_IMG_TPL_MAIN_BAT20, + IMAGE_RES_IMG_TPL_MAIN_BAT21, +}; + +static const uint16_t wui_imgtable_main_main_connection[] = { + IMAGE_RES_IMG_TPL_MAIN_CON1, + IMAGE_RES_IMG_TPL_MAIN_CON2, + IMAGE_RES_IMG_TPL_MAIN_CON3, +}; + +/* Maps image table IDs to image ID arrays */ +static const uint16_t* wui_imgtable_list[WUI_IMGTABLE_COUNT] = { + [WUI_IMGTABLE_NONE] = NULL, + [WUI_IMGTABLE_MAIN_MAIN_BATTERY] = wui_imgtable_main_main_battery, + [WUI_IMGTABLE_MAIN_MAIN_CONNECTION] = wui_imgtable_main_main_connection, +}; + +/** + * @brief Get image table by ID + * @param id - Image table ID + * @return Image table pointer, or NULL if not found + */ +const uint16_t* wui_get_imgtable(wui_imgtable_id_t id) +{ + if (id > 0 && id < WUI_IMGTABLE_COUNT) + { + return wui_imgtable_list[id]; + } + return NULL; +} + +/******************************************************************************* + * FONT RESOURCES + ******************************************************************************/ + +/** + * @brief Font table for WUI + * @details Maps font IDs to font structures + */ +static const wui_font_t wui_font_table[WUI_FONT_COUNT] = { + [WUI_FONT_NONE] = {0}, + [WUI_FONT_WUI_PAGE_MAIN_MAIN_TIME] = { + .cnt = 10, + .start_char = '0', + .width = 10, + .height = 26, + .first_img_id = IMAGE_ART_WUI_PAGE_MAIN_MAIN_TIME_0030, + }, +}; + +const wui_font_t* wui_get_font(wui_font_id_t id) +{ + if (id > 0 && id < WUI_FONT_COUNT) + { + return &wui_font_table[id]; + } + return NULL; +} + +/******************************************************************************* + * BITMAP FONT RESOURCES + ******************************************************************************/ + +/* Maps bitmap font IDs to font structures */ +static const wui_bitfont_t* wui_bitmap_font_table[WUI_BITMAP_FONT_COUNT] = { + [WUI_BITMAP_FONT_DEFAULT] = &wui_font_8x16, + [WUI_BITMAP_FONT_6X12] = &wui_font_6x12, + [WUI_BITMAP_FONT_8X16] = &wui_font_8x16, +}; + +/** + * @brief Get bitmap font by ID + * @param id - Bitmap font ID + * @return Bitmap font structure pointer, or default font if not found + */ +const wui_bitfont_t* wui_get_bitmap_font(wui_bitmap_font_id_t id) +{ + if (id > 0 && id < WUI_BITMAP_FONT_COUNT) { + return wui_bitmap_font_table[id]; + } + return wui_bitmap_font_table[WUI_BITMAP_FONT_DEFAULT]; +} + + +/********************************************************************* + * @fn wui_get_image + * + * @brief Get image information by index. + * + * @param index - Image index. + * + * @return Pointer to image information structure. + */ +const image_info_t* wui_get_image(uint32_t index) +{ + // return get_image(index); + uint16_t idx = IMAGE_GET_INDEX(index); + if (idx >= IMAGE_COUNT) return NULL; + return &image_table[idx]; +} diff --git a/EVT/EXAM/APPLICATION/WUI/User/wui_user/wui_asset.h b/EVT/EXAM/APPLICATION/WUI/User/wui_user/wui_asset.h new file mode 100644 index 0000000..db036a6 --- /dev/null +++ b/EVT/EXAM/APPLICATION/WUI/User/wui_user/wui_asset.h @@ -0,0 +1,58 @@ +/********************************** (C) COPYRIGHT ******************************* + * File Name : wui_asset.h + * Author : WCH + * Version : V1.2.0 + * Date : 2026/07/30 + * Description : Asset management functions + *********************************************************************************/ + +#ifndef WUI_ASSET_H +#define WUI_ASSET_H + +#include +#include "wui.h" +#include "images.h" +#include "wui_widget.h" + +enum +{ + WUI_STR_NONE = 0, + WUI_STR_MAIN_MAIN_TIME, + WUI_STR_COUNT +}; + +const char* wui_get_string(wui_str_id_t id); + +enum +{ + WUI_FONT_NONE = 0, + WUI_FONT_WUI_PAGE_MAIN_MAIN_TIME, + WUI_FONT_COUNT +}; + +const wui_font_t* wui_get_font(wui_font_id_t id); + +enum +{ + WUI_IMGTABLE_NONE = 0, + WUI_IMGTABLE_MAIN_MAIN_BATTERY, + WUI_IMGTABLE_MAIN_MAIN_CONNECTION, + WUI_IMGTABLE_COUNT +}; + +const uint16_t* wui_get_imgtable(wui_imgtable_id_t id); + + +enum { + WUI_BITMAP_FONT_DEFAULT = 0, + WUI_BITMAP_FONT_6X12, + WUI_BITMAP_FONT_8X16, + + WUI_BITMAP_FONT_COUNT +}; + +const wui_bitfont_t* wui_get_bitmap_font(wui_bitmap_font_id_t id); + +const image_info_t* wui_get_image(uint32_t index); + +#endif diff --git a/EVT/EXAM/APPLICATION/WUI/User/wui_user/wui_page.c b/EVT/EXAM/APPLICATION/WUI/User/wui_user/wui_page.c new file mode 100644 index 0000000..59cf41d --- /dev/null +++ b/EVT/EXAM/APPLICATION/WUI/User/wui_user/wui_page.c @@ -0,0 +1,22 @@ +#include "wui_page.h" +#include "wui.h" +#include "images.h" +#include + + +const wui_page_desc_t wui_pages[WUI_PAGE_COUNT] = { + [WUI_PAGE_NONE] = { + .bg_color = RGB888_TO_RGB565(0, 0, 0), + .page_name = "None", + .page_init = wui_page_none_init, + .page_loop = wui_page_none_loop, + .user_data = NULL, + }, + [WUI_PAGE_MAIN] = { + .bg_color = RGB888_TO_RGB565(0, 0, 0), + .page_name = "Menu Page", + .page_init = wui_page_main_init, + .page_loop = wui_page_main_loop, + .user_data = NULL, + }, +}; diff --git a/EVT/EXAM/APPLICATION/WUI/User/wui_user/wui_page.h b/EVT/EXAM/APPLICATION/WUI/User/wui_user/wui_page.h new file mode 100644 index 0000000..96e6793 --- /dev/null +++ b/EVT/EXAM/APPLICATION/WUI/User/wui_user/wui_page.h @@ -0,0 +1,25 @@ +#ifndef WUI_PAGE_H +#define WUI_PAGE_H + +#include +#include "stddef.h" +#include "wui.h" + +typedef enum +{ + WUI_PAGE_NONE = 0, + WUI_PAGE_MAIN, + WUI_PAGE_COUNT, +} wui_page_t; + +#define WUI_START_PAGE WUI_PAGE_MAIN + +void wui_page_none_init(void); +void wui_page_none_loop(void); + +void wui_page_main_init(void); +void wui_page_main_loop(void); + +extern const wui_page_desc_t wui_pages[WUI_PAGE_COUNT]; + +#endif diff --git a/EVT/EXAM/APPLICATION/WUI/User/wui_user/wui_page_main.c b/EVT/EXAM/APPLICATION/WUI/User/wui_user/wui_page_main.c new file mode 100644 index 0000000..dc6a8c6 --- /dev/null +++ b/EVT/EXAM/APPLICATION/WUI/User/wui_user/wui_page_main.c @@ -0,0 +1,80 @@ +#include "wui_user/wui_page_main.h" + +// ================= Template Page ================= +// Template: main menu +// Template interaction logic is generated from known template IDs. + +// ================= Template Logic Hooks ================= + +#define MENU_COUNT 6 + +static const uint8_t menu_widget_ids[MENU_COUNT] = { + MAIN_MAIN_SETTING, + MAIN_MAIN_MODE, + MAIN_MAIN_ANIM, + MAIN_MAIN_REAL_DATA, + MAIN_MAIN_LIGHT_COLOR, + MAIN_MAIN_COLOR_CFG, +}; + +static const wui_page_t menu_pages[MENU_COUNT] = { + WUI_PAGE_MAIN, + WUI_PAGE_MAIN, + WUI_PAGE_MAIN, + WUI_PAGE_MAIN, + WUI_PAGE_MAIN, + WUI_PAGE_MAIN, +}; + +static uint8_t main_saved_selection = 0; +static uint8_t current_menu = 0; + +static void menu_set(uint8_t index, uint8_t on) +{ + if (index < MENU_COUNT) + { + if (on) + { + wui_widget_button_press(menu_widget_ids[index]); + } + else + { + wui_widget_button_release(menu_widget_ids[index]); + } + } +} + +static void main_on_key(uint32_t key) +{ + if (key == 'a') + { + menu_set(current_menu, 0); + current_menu = (current_menu == 0) ? MENU_COUNT - 1 : current_menu - 1; + menu_set(current_menu, 1); + } + else if (key == 'd') + { + menu_set(current_menu, 0); + current_menu = (current_menu + 1 >= MENU_COUNT) ? 0 : current_menu + 1; + menu_set(current_menu, 1); + } + else if (key == 'b') + { + main_saved_selection = current_menu; + wui_page_switch(menu_pages[current_menu]); + } +} + +// ================= Page Functions ================= + +void wui_page_main_init(void) +{ + wui_page_init(widgets_main, sizeof(widgets_main) / sizeof(widgets_main[0])); + current_menu = main_saved_selection; + menu_set(current_menu, 1); + wui_register_key_handler(main_on_key); +} + +void wui_page_main_loop(void) +{ +} diff --git a/EVT/EXAM/APPLICATION/WUI/User/wui_user/wui_page_main.h b/EVT/EXAM/APPLICATION/WUI/User/wui_user/wui_page_main.h new file mode 100644 index 0000000..ca8f814 --- /dev/null +++ b/EVT/EXAM/APPLICATION/WUI/User/wui_user/wui_page_main.h @@ -0,0 +1,183 @@ +#ifndef WUI_PAGE_MAIN_H +#define WUI_PAGE_MAIN_H + +#include "wui.h" +#include "wui_user/wui_page.h" +#include "wui_widget.h" +#include "images.h" +#include "wui_asset.h" +#include + +// ================= Widget ID Enum ================= +typedef enum +{ + MAIN_MAIN_BG_BLACK, + MAIN_MAIN_BG, + MAIN_MAIN_TIME, + MAIN_MAIN_CONNECTION, + MAIN_MAIN_BATTERY, + MAIN_MAIN_SETTING, + MAIN_MAIN_MODE, + MAIN_MAIN_ANIM, + MAIN_MAIN_REAL_DATA, + MAIN_MAIN_LIGHT_COLOR, + MAIN_MAIN_COLOR_CFG, +} main_widget_id_t; + +// ================= Declarative Widgets ================= +static const wui_widget_desc_t widgets_main[] = { + [MAIN_MAIN_BG_BLACK] = { + .widget_id = MAIN_MAIN_BG_BLACK, + .type = Wui_w_Rect, + .x = 0, + .y = 0, + .w = 320, + .h = 240, + .props.rect = { + .color = RGB888_TO_RGB565(0, 0, 0), + }, + }, + + [MAIN_MAIN_BG] = { + .widget_id = MAIN_MAIN_BG, + .type = Wui_w_StaticImage, + .x = 0, + .y = 0, + .w = 320, + .h = 240, + .props.staticimg = { + .img_id = IMAGE_RES_IMG_TPL_MAIN_BG, + }, + }, + + [MAIN_MAIN_TIME] = { + .widget_id = MAIN_MAIN_TIME, + .type = Wui_w_ExString, + .x = 12, + .y = 4, + .w = 50, + .h = 26, + .props.exstring = { + .str_id = WUI_STR_MAIN_MAIN_TIME, + .font_id = WUI_FONT_WUI_PAGE_MAIN_MAIN_TIME, + .bg_color = RGB888_TO_RGB565(0, 0, 0), + .align = WUI_EXSTRING_ALIGN_LEFT, + }, + }, + + [MAIN_MAIN_CONNECTION] = { + .widget_id = MAIN_MAIN_CONNECTION, + .type = Wui_w_MultiState, + .x = 119, + .y = 4, + .w = 26, + .h = 26, + .props.multistate = { + .imgtable_id = WUI_IMGTABLE_MAIN_MAIN_CONNECTION, + .state_count = 3, + .default_state = 2, + }, + }, + + [MAIN_MAIN_BATTERY] = { + .widget_id = MAIN_MAIN_BATTERY, + .type = Wui_w_MultiState, + .x = 280, + .y = 4, + .w = 26, + .h = 26, + .props.multistate = { + .imgtable_id = WUI_IMGTABLE_MAIN_MAIN_BATTERY, + .state_count = 22, + .default_state = 0, + }, + }, + + [MAIN_MAIN_SETTING] = { + .widget_id = MAIN_MAIN_SETTING, + .type = Wui_w_Button, + .x = 24, + .y = 42, + .w = 73, + .h = 99, + .props.button = { + .pressed_img_id = IMAGE_RES_IMG_TPL_MAIN_PAGESETTING2, + .normal_img_id = IMAGE_RES_IMG_TPL_MAIN_PAGESETTING1, + .is_pressed = 0, + }, + }, + + [MAIN_MAIN_MODE] = { + .widget_id = MAIN_MAIN_MODE, + .type = Wui_w_Button, + .x = 127, + .y = 42, + .w = 73, + .h = 99, + .props.button = { + .pressed_img_id = IMAGE_RES_IMG_TPL_MAIN_PAGEMODEL2, + .normal_img_id = IMAGE_RES_IMG_TPL_MAIN_PAGEMODEL1, + .is_pressed = 0, + }, + }, + + [MAIN_MAIN_ANIM] = { + .widget_id = MAIN_MAIN_ANIM, + .type = Wui_w_Button, + .x = 226, + .y = 42, + .w = 73, + .h = 99, + .props.button = { + .pressed_img_id = IMAGE_RES_IMG_TPL_MAIN_PAGEANIMAL2, + .normal_img_id = IMAGE_RES_IMG_TPL_MAIN_PAGEANIMAL1, + .is_pressed = 0, + }, + }, + + [MAIN_MAIN_REAL_DATA] = { + .widget_id = MAIN_MAIN_REAL_DATA, + .type = Wui_w_Button, + .x = 24, + .y = 141, + .w = 73, + .h = 99, + .props.button = { + .pressed_img_id = IMAGE_RES_IMG_TPL_MAIN_PAGERELDATA2, + .normal_img_id = IMAGE_RES_IMG_TPL_MAIN_PAGERELDATA1, + .is_pressed = 0, + }, + }, + + [MAIN_MAIN_LIGHT_COLOR] = { + .widget_id = MAIN_MAIN_LIGHT_COLOR, + .type = Wui_w_Button, + .x = 127, + .y = 141, + .w = 73, + .h = 99, + .props.button = { + .pressed_img_id = IMAGE_RES_IMG_TPL_MAIN_PAGELIGHTCOLOR2, + .normal_img_id = IMAGE_RES_IMG_TPL_MAIN_PAGELIGHTCOLOR1, + .is_pressed = 0, + }, + }, + + [MAIN_MAIN_COLOR_CFG] = { + .widget_id = MAIN_MAIN_COLOR_CFG, + .type = Wui_w_Button, + .x = 226, + .y = 141, + .w = 73, + .h = 99, + .props.button = { + .pressed_img_id = IMAGE_RES_IMG_TPL_MAIN_PAGELIGHTCFG2, + .normal_img_id = IMAGE_RES_IMG_TPL_MAIN_PAGELIGHTCFG1, + .is_pressed = 0, + }, + }, + +}; + + +#endif // WUI_PAGE_MAIN_H diff --git a/EVT/EXAM/APPLICATION/WUI/User/wui_user/wui_page_none.c b/EVT/EXAM/APPLICATION/WUI/User/wui_user/wui_page_none.c new file mode 100644 index 0000000..fafe7f0 --- /dev/null +++ b/EVT/EXAM/APPLICATION/WUI/User/wui_user/wui_page_none.c @@ -0,0 +1,16 @@ +#include "wui_user/wui_page_none.h" + +static void none_on_key(uint32_t key) +{ + wui_page_switch(WUI_START_PAGE); +} + +void wui_page_none_init() +{ + wui_page_init(widgets_none, sizeof(widgets_none) / sizeof(widgets_none[0])); + wui_register_key_handler(none_on_key); +} + +void wui_page_none_loop() +{ +} diff --git a/EVT/EXAM/APPLICATION/WUI/User/wui_user/wui_page_none.h b/EVT/EXAM/APPLICATION/WUI/User/wui_user/wui_page_none.h new file mode 100644 index 0000000..54667b8 --- /dev/null +++ b/EVT/EXAM/APPLICATION/WUI/User/wui_user/wui_page_none.h @@ -0,0 +1,27 @@ +#ifndef WUI_PAGE_NONE_H +#define WUI_PAGE_NONE_H + +#include "wui.h" +#include "wui_user/wui_page.h" +#include "wui_widget.h" + +typedef enum +{ + WIDGET_NONE_BG = 0, +} none_widget_id_t; + +static const wui_widget_desc_t widgets_none[] = { + [WIDGET_NONE_BG] = { + .widget_id = WIDGET_NONE_BG, + .type = Wui_w_Rect, + .x = 0, + .y = 0, + .w = LCD_WIDTH, + .h = LCD_HEIGHT, + .props.rect = { + .color = LCD_black, + }, + }, +}; + +#endif // WUI_PAGE_NONE_H diff --git a/EVT/EXAM/APPLICATION/WUI/wui_demo.wvproj b/EVT/EXAM/APPLICATION/WUI/wui_demo.wvproj new file mode 100644 index 0000000..d52b306 --- /dev/null +++ b/EVT/EXAM/APPLICATION/WUI/wui_demo.wvproj @@ -0,0 +1,450 @@ +{ + "version": "1.0", + "hasAllParsed": true, + "isNormalMRSProject": true, + "basic": { + "chipInfo": { + "vendor": "WCH", + "toolchain": "RISC-V", + "series": "CH32V203", + "rtos": "NoneOS", + "mcu": "CH32V203RBT", + "description": "ROM(byte): 64K, SRAM(byte): 20K, CHIP PINS: 32, GPIO PORTS: 27.\\nWCH CH32V2 series of mainstream MCUs covers the needs of a large variety of applications in the industrial,medical and consumer markets. High performance with first-class peripherals and low-power,low-voltage operation is paired with a high level of integration at accessible prices with a simple architecture and easy-to-use tools.", + "tempratureScope": "", + "artifactType": "executable", + "link": "WCH-Link", + "peripheral_version": "1.0", + "calibrateSupport": false, + "calibrateCommand": "", + "UIConfigSupport": false, + "UIConfigCommand": "", + "externalFlashSupport": false + }, + "linkedFolders": [ + { + "name": "Core", + "location": "../../SRC/Core" + }, + { + "name": "Debug", + "location": "../../SRC/Debug" + }, + { + "name": "Ld", + "location": "../../SRC/Ld" + }, + { + "name": "Peripheral", + "location": "../../SRC/Peripheral" + }, + { + "name": "Startup", + "location": "../../SRC/Startup" + } + ], + "removedResources": [ + { + "parentLogicPath": "", + "type": "file", + "name": "*.wvproj" + } + ], + "projectName": "WS2812_LED", + "architecture": "RISC-V", + "projectType": "c" + }, + "buildConfig": { + "configurations": [ + { + "buildArtifact": { + "artifact_name": "${ProjName}", + "artifact_extension": "elf", + "output_prefix": "", + "artifact_type": "Executable" + }, + "parallelizationNumber": "optimal", + "stop_on_first_build_error": true, + "pre_script": "", + "pre_script_description": "", + "post_script": "", + "post_script_description": "", + "excludeResources": [ + "${project}/Startup/startup_ch32v20x_D8W.S", + "${project}/Startup/startup_ch32v20x_D8.S" + ], + "optimization": { + "level": "size", + "message_length": true, + "char_is_signed": true, + "function_sections": true, + "data_sections": true, + "no_common_unitialized": true, + "do_not_inline_functions": false, + "assume_freestanding_environment": false, + "disable_builtin": false, + "single_precision_constants": false, + "position_independent_code": false, + "link_time_optimizer": false, + "disable_loop_invariant_move": false, + "optimize_unused_sections_declared_as_high_code": false, + "code_generation_without_hardware_floating": false, + "use_pipelines": false, + "show_caret_indicating_the_column": false, + "calling_convention_variant": false, + "other_optimization_flags": "" + }, + "warnings": { + "check_syntax_only": false, + "pedantic": false, + "pedantic_warnings_as_errors": false, + "inhibit_all_warnings": false, + "warn_on_various_unused_elements": true, + "warn_on_uninitialized_variables": true, + "enable_all_common_warnings": false, + "enable_extra_warnings": false, + "warn_on_undeclared_global_function": false, + "warn_on_implicit_conversions": false, + "warn_if_pointer_arthmetic": false, + "warn_if_padding_is_included": false, + "warn_if_shadowed_variable": false, + "warn_if_suspicious_logical_ops": false, + "warn_if_struct_is_returned": false, + "warn_if_floats_are_compared_as_equal": false, + "generate_errors_instead_of_warnings": false, + "other_warning_flags": "" + }, + "debugging": { + "debug_level": "default", + "debug_format": "default", + "generate_prof_information": false, + "generate_gprof_information": false, + "other_debugging_flags": "" + }, + "assembler": { + "preprocessor": { + "use_preprocessor": true, + "do_not_search_system_directories": false, + "preprocess_only": false, + "defined_symbols": [], + "undefined_symbols": [] + }, + "includes": { + "include_paths": [ + "${project}/Startup" + ], + "include_system_paths": [], + "include_files": [] + }, + "other_warning_flags": "", + "miscellaneous": { + "assembler_flags": [], + "generate_assembler_listing": false, + "save_temporary_files": false, + "verbose": false, + "other_assembler_flags": "" + } + }, + "ccompiler": { + "preprocessor": { + "do_not_search_system_directories": false, + "preprocess_only": false, + "defined_symbols": [], + "undefined_symbols": [] + }, + "includes": { + "include_paths": [ + "${project}/Debug", + "${project}/Core", + "${project}/User", + "${project}/Peripheral/inc", + "${project}/User/Drivers", + "${project}/User/wui", + "${project}/User/wui_port", + "${project}/User/wui_user" + ], + "include_system_paths": [], + "include_files": [] + }, + "optimization": { + "language_standard": "gnu99", + "other_optimization_flags": "" + }, + "warnings": { + "warn_if_a_global_function_has_no_prototype": false, + "warn_if_a_function_has_no_arg_type": false, + "warn_if_wrong_cast": false, + "other_warning_flags": "" + }, + "miscellaneous": { + "generate_assembler_listing": false, + "save_temporary_files": false, + "verbose": false, + "other_compiler_flags": "" + } + }, + "cppcompiler": { + "preprocessor": { + "do_not_search_system_directories": false, + "do_not_search_system_cpp_directories": false, + "preprocess_only": false, + "defined_symbols": [], + "undefined_symbols": [] + }, + "includes": { + "include_paths": [], + "include_system_paths": [], + "include_files": [] + }, + "optimization": { + "cpp_language_standard": "gnucpp11", + "abi_version": "0", + "do_not_use_exceptions": false, + "do_not_use_rtti": false, + "do_not_use__cxa_atexit": false, + "do_not_use_thread_safe_statics": false, + "other_optimization_flags": "" + }, + "warnings": { + "warn_on_abi_violations": false, + "warn_on_class_privacy": false, + "warn_on_no_except_expressions": false, + "warn_on_virtual_destructors": false, + "warn_on_uncast_null": false, + "warn_on_sign_promotion": false, + "warn_about_effictive_cpp_violcations": false, + "other_warning_flags": "" + }, + "miscellaneous": { + "generate_assembler_listing": false, + "save_temporary_files": false, + "verbose": false, + "other_compiler_flags": "" + } + }, + "clinker": { + "general": { + "scriptFiles": [ + "${project}/Ld/Link.ld" + ], + "do_not_use_standard_start_files": true, + "do_not_use_default_libraries": false, + "no_startup_or_default_libs": false, + "remove_unused_sections": true, + "print_removed_sections": false, + "omit_all_symbol_information": false + }, + "libraries": { + "libraries": [], + "library_search_path": [] + }, + "miscellaneous": { + "picolibc": "disabled", + "linker_flags": [], + "other_objects": [ + "${project}/User/wui/libwui_0.2.a" + ], + "generate_map": "\"${BuildArtifactFileBaseName}.map\"", + "cross_reference": false, + "print_link_map": false, + "use_newlib_nano": true, + "use_float_with_nano_printf": false, + "use_float_with_nano_scanf": false, + "do_not_use_syscalls": true, + "verbose": false, + "use_wch_printffloat": false, + "use_wch_printf": false, + "use_iqmath": false, + "other_linker_flags": "" + } + }, + "cpplinker": { + "general": { + "scriptFiles": [ + "${project}/Ld/Link.ld" + ], + "do_not_use_standard_start_files": true, + "do_not_use_default_libraries": false, + "no_startup_or_default_libs": false, + "remove_unused_sections": true, + "print_removed_sections": false, + "omit_all_symbol_information": false + }, + "libraries": { + "libraries": [], + "library_search_path": [] + }, + "miscellaneous": { + "picolibc": "disabled", + "linker_flags": [], + "other_objects": [ + "${project}/User/wui/libwui_0.2.a" + ], + "generate_map": "\"${BuildArtifactFileBaseName}.map\"", + "cross_reference": false, + "print_link_map": false, + "use_newlib_nano": true, + "use_float_with_nano_printf": false, + "use_float_with_nano_scanf": false, + "do_not_use_syscalls": true, + "verbose": false, + "use_wch_printffloat": false, + "use_wch_printf": false, + "use_iqmath": false, + "other_linker_flags": "" + } + }, + "archiver": { + "archiver_flags": "-r", + "libOutputPrefix": "lib" + }, + "createFlash": { + "enabled": true, + "outputFileFormat": "ihex", + "copy_only_section_text": false, + "copy_only_section_data": false, + "copy_only_sections": [], + "create_algorithm_file": false, + "other_flags": "" + }, + "createList": { + "enabled": true, + "display_source": false, + "display_all_headers": true, + "demangle_names": true, + "display_debug_info": false, + "disassemble": true, + "display_file_headers": false, + "display_line_numbers": false, + "display_relocation_info": false, + "display_symbols": false, + "wide_lines": false, + "other_flags": "" + }, + "printSize": { + "enabled": true, + "size_format": "berkeley", + "hex": false, + "show_totals": false, + "other_flags": "" + }, + "configVariables": [], + "riscvTargetProcessor": { + "architecture": "rv32i", + "multiply_extension": true, + "atomic_extension": true, + "floating_point": "none", + "compressed_extension": true, + "extra_compressed_extension": true, + "bit_extension": false, + "multiplication_subset_of_the_M_extension": false, + "vector_cryptography_extensions": "", + "integer_ABI": "ilp32", + "floating_point_ABI": "none", + "tuning": "default", + "code_model": "default", + "small_data_limit": 8, + "align": "default", + "save_restore": true, + "other_target_flags": "" + }, + "component_toolchain": "${WCH:Toolchain:GCC8}", + "name": "obj" + } + ] + }, + "flashConfig": { + "mcutype": "CH32V20x", + "address": "0x08000000", + "target_path": "obj\\WS2812_LED.hex", + "clkSpeed": "High", + "debug_interface_mode": "1-wire serial", + "erase": true, + "program": true, + "verify": true, + "reset": true, + "sdiPrintf": false, + "disablepowerout": false, + "clearcodeflash": false, + "disablecodeprotect": false, + "flashType": "", + "asmFile_path": "", + "exepath": "", + "exearguments": "" + }, + "debugConfigurations": { + "openOCDCfg": { + "useLocalOpenOCD": true, + "executable": "${WCH:OpenOCD:default}", + "gdbport": 3333, + "telnetport": 4444, + "tclport": 6666, + "configOptions": [ + "-f \"${WCH:OpenOCD:default}/bin/wch-riscv.cfg\"" + ], + "host": "127.0.0.1", + "port": 3333, + "skipDownloadBeforeDebug": false, + "enablePageEraser": false, + "enableNoZeroWaitingAreaFlash": false + }, + "gdbCfg": { + "executable": "${WCH:Toolchain:GCC8}", + "options": [], + "commands": [ + "set mem inaccessible-by-default off", + "set architecture riscv:rv32", + "set remotetimeout unlimited", + "set disassembler-options xw" + ] + }, + "startup": { + "initCommands": { + "initReset": true, + "initResetType": "init", + "additionalCommands": [], + "armSemihosting": false, + "armSemihosting_old": false + }, + "loadedFiles": { + "loadSymbols": true, + "useProjBinaryForSymbols": true, + "useFileForSymbols": false, + "symbolFile": "", + "symbolFileOffset": "", + "loadImage": true, + "useProjBinaryForImage": true, + "useFileForImage": false, + "executableFile": "", + "executableFileOffset": "" + }, + "runCommands": { + "runReset": true, + "runResetType": "halt", + "additionalCommands": [], + "setBreakAt": "handle_reset", + "continue": true, + "setBreak": true, + "setProgramCounter": false, + "setProgramCounterAddress": "" + }, + "debugInRAM": false + }, + "svdpath": "${WCH:SDK:default}/RISC-V/CH32V203/NoneOS/CH32V203xx.svd", + "output": { + "showDebugGDBTrace": true, + "saveDebugOutputToFile": false, + "showDebugOutputTimestamps": true + }, + "reserve": { + "PROGRAM_NAME": "obj/WS2812_LED.elf", + "PROJECT_ATTR": "WS2812_LED", + "PROJECT_BUILD_CONFIG_AUTO_ATTR": true, + "PROJECT_BUILD_CONFIG_ID_ATTR": "", + "ATTR_BUILD_BEFORE_LAUNCH_ATTR": 2, + "GdbServerAllocateConsole": true, + "GdbServerAllocateTelnetConsole": false, + "StartGdbCLient": true, + "UPDATE_THREADLIST_ON_SUSPEND": false + } + } +} \ No newline at end of file diff --git a/EVT/EXAM/BLE/BackupUpgrade_OTA/APP/peripheral.c b/EVT/EXAM/BLE/BackupUpgrade_OTA/APP/peripheral.c index 73cba73..e588615 100644 --- a/EVT/EXAM/BLE/BackupUpgrade_OTA/APP/peripheral.c +++ b/EVT/EXAM/BLE/BackupUpgrade_OTA/APP/peripheral.c @@ -672,6 +672,7 @@ void Rec_OTA_IAP_DataDeal(void) OpAdd = OpAdd * 16; OpAdd += IMAGE_A_SIZE+0x08000000; + block_buf_len = 0; EraseBlockNum = (uint32_t)(iap_rec_data.erase.block_num[0]); EraseBlockNum |= ((uint32_t)(iap_rec_data.erase.block_num[1]) << 8); @@ -754,6 +755,8 @@ void Rec_OTA_IAP_DataDeal(void) PRINT("IAP_INFO \r\n"); + block_buf_len = 0; + /* IMAGE FLAG */ send_buf[0] = IMAGE_B_FLAG; diff --git a/EVT/EXAM/BLE/HAL/MCU.c b/EVT/EXAM/BLE/HAL/MCU.c index 6df834b..974da14 100644 --- a/EVT/EXAM/BLE/HAL/MCU.c +++ b/EVT/EXAM/BLE/HAL/MCU.c @@ -200,8 +200,8 @@ tmosEvents HAL_ProcessEvent(tmosTaskID task_id, tmosEvents events) #if(defined HAL_KEY) && (HAL_KEY == TRUE) HAL_KeyPoll(); /* Check for keys */ tmos_start_task(halTaskID, HAL_KEY_EVENT, MS1_TO_SYSTEM_TIME(100)); - return events ^ HAL_KEY_EVENT; #endif + return events ^ HAL_KEY_EVENT; } if(events & HAL_REG_INIT_EVENT) { diff --git a/EVT/EXAM/BLE/MESH/adv_vendor_self_provision_with_peripheral/APP/app.c b/EVT/EXAM/BLE/MESH/adv_vendor_self_provision_with_peripheral/APP/app.c index 5a47a5d..82b7470 100644 --- a/EVT/EXAM/BLE/MESH/adv_vendor_self_provision_with_peripheral/APP/app.c +++ b/EVT/EXAM/BLE/MESH/adv_vendor_self_provision_with_peripheral/APP/app.c @@ -1125,6 +1125,9 @@ void App_trans_model_reveived(uint8_t *pValue, uint16_t len, uint16_t addr ) } int status; uint8_t i; + + block_buf_len = 0; + // 清除codeflash FLASH_Unlock(); for(i=0; i<(IMAGE_B_SIZE+4095)/4096; i++) diff --git a/EVT/EXAM/BLE/MESH/娌佹亽MESH APP绠$悊閰嶇綉搴旂敤鎵嬪唽.PDF b/EVT/EXAM/BLE/MESH/娌佹亽MESH APP绠$悊閰嶇綉搴旂敤鎵嬪唽.PDF index 63fd127..c998d95 100644 Binary files a/EVT/EXAM/BLE/MESH/娌佹亽MESH APP绠$悊閰嶇綉搴旂敤鎵嬪唽.PDF and b/EVT/EXAM/BLE/MESH/娌佹亽MESH APP绠$悊閰嶇綉搴旂敤鎵嬪唽.PDF differ diff --git a/EVT/EXAM/BLE/MESH/娌佹亽浣庡姛鑰楄摑鐗橫ESH杞欢寮�鍙戝弬鑰冩墜鍐�.PDF b/EVT/EXAM/BLE/MESH/娌佹亽浣庡姛鑰楄摑鐗橫ESH杞欢寮�鍙戝弬鑰冩墜鍐�.PDF index bafeeff..2be4a34 100644 Binary files a/EVT/EXAM/BLE/MESH/娌佹亽浣庡姛鑰楄摑鐗橫ESH杞欢寮�鍙戝弬鑰冩墜鍐�.PDF and b/EVT/EXAM/BLE/MESH/娌佹亽浣庡姛鑰楄摑鐗橫ESH杞欢寮�鍙戝弬鑰冩墜鍐�.PDF differ diff --git a/EVT/EXAM/BLE/OnlyUpdateApp_IAP/APP/peripheral.c b/EVT/EXAM/BLE/OnlyUpdateApp_IAP/APP/peripheral.c index 8a89b85..b689a89 100644 --- a/EVT/EXAM/BLE/OnlyUpdateApp_IAP/APP/peripheral.c +++ b/EVT/EXAM/BLE/OnlyUpdateApp_IAP/APP/peripheral.c @@ -578,7 +578,7 @@ void Rec_OTA_IAP_DataDeal(void) OpAdd = OpAdd * 16; OpAdd += 0x08000000; - + block_buf_len = 0; EraseBlockNum = (uint32_t)(iap_rec_data.erase.block_num[0]); EraseBlockNum |= ((uint32_t)(iap_rec_data.erase.block_num[1]) << 8); EraseAdd = OpAdd; @@ -664,6 +664,8 @@ void Rec_OTA_IAP_DataDeal(void) uint8_t send_buf[20]; PRINT("IAP_INFO \r\n"); + + block_buf_len = 0; /* IMAGE FLAG */ send_buf[0] = IMAGE_IAP_FLAG; diff --git a/EVT/EXAM/BLE/娌佹亽浣庡姛鑰楄摑鐗欒蒋浠跺紑鍙戝弬鑰冩墜鍐�.PDF b/EVT/EXAM/BLE/娌佹亽浣庡姛鑰楄摑鐗欒蒋浠跺紑鍙戝弬鑰冩墜鍐�.PDF index 660aeca..09a0322 100644 Binary files a/EVT/EXAM/BLE/娌佹亽浣庡姛鑰楄摑鐗欒蒋浠跺紑鍙戝弬鑰冩墜鍐�.PDF and b/EVT/EXAM/BLE/娌佹亽浣庡姛鑰楄摑鐗欒蒋浠跺紑鍙戝弬鑰冩墜鍐�.PDF differ diff --git a/EVT/EXAM/BLE/钃濈墮鑺墖鐨勭數璺強PCB璁捐鐨勯噸瑕佹敞鎰忎簨椤�.pdf b/EVT/EXAM/BLE/钃濈墮鑺墖鐨勭數璺強PCB璁捐鐨勯噸瑕佹敞鎰忎簨椤�.pdf index 6d0279b..90eafed 100644 Binary files a/EVT/EXAM/BLE/钃濈墮鑺墖鐨勭數璺強PCB璁捐鐨勯噸瑕佹敞鎰忎簨椤�.pdf and b/EVT/EXAM/BLE/钃濈墮鑺墖鐨勭數璺強PCB璁捐鐨勯噸瑕佹敞鎰忎簨椤�.pdf differ diff --git a/EVT/EXAM/ETH/MAC_RAW/ETH_Driver/eth_driver.c b/EVT/EXAM/ETH/MAC_RAW/ETH_Driver/eth_driver.c index a0d0446..3cdf75e 100644 --- a/EVT/EXAM/ETH/MAC_RAW/ETH_Driver/eth_driver.c +++ b/EVT/EXAM/ETH/MAC_RAW/ETH_Driver/eth_driver.c @@ -488,13 +488,13 @@ void ETH_Configuration( uint8_t *macAddr ) uint32_t MACRAW_Tx(uint8_t *buff, uint16_t len) { /* Check if the descriptor is owned by the ETHERNET DMA (when set) or CPU (when reset) */ - if((DMATxDescToSet->Status & ETH_DMATxDesc_OWN)) + if( DMATxDescToSet->Status & ETH_DMATxDesc_OWN ) { - if((R8_ETH_ECON1 & RB_ETH_ECON1_TXRTS) == 0) - { - DMATxDescToSet->Status &= ~ETH_DMATxDesc_OWN; - } - else return ETH_ERROR; + if((R8_ETH_ECON1 & RB_ETH_ECON1_TXRTS) == 0) + { + DMATxDescToSet->Status &= ~ETH_DMATxDesc_OWN; + } + else return ETH_ERROR; /* Return ERROR: OWN bit set */ } DMATxDescToSet->Status |= ETH_DMATxDesc_OWN; R16_ETH_ETXLN = len; diff --git a/EVT/EXAM/ETH/MAC_RAW/ETH_Driver/eth_driver.h b/EVT/EXAM/ETH/MAC_RAW/ETH_Driver/eth_driver.h index 5853310..e10958d 100644 --- a/EVT/EXAM/ETH/MAC_RAW/ETH_Driver/eth_driver.h +++ b/EVT/EXAM/ETH/MAC_RAW/ETH_Driver/eth_driver.h @@ -48,7 +48,7 @@ }while(0) /* definition for Ethernet frame */ -#define ETH_MAX_PACKET_SIZE 1536 /* ETH_HEADER + ETH_EXTRA + MAX_ETH_PAYLOAD + ETH_CRC */ +#define ETH_MAX_PACKET_SIZE 1524 /* ETH_HEADER + VLAN_TAG + MAX_ETH_PAYLOAD + ETH_CRC */ #define ETH_HEADER 14 /* 6 byte Dest addr, 6 byte Src addr, 2 byte length/type */ #define ETH_CRC 4 /* Ethernet CRC */ #define ETH_EXTRA 2 /* Extra bytes in some cases */ diff --git a/EVT/EXAM/ETH/NetLib/eth_driver.c b/EVT/EXAM/ETH/NetLib/eth_driver.c index 50bee7a..821fbd3 100644 --- a/EVT/EXAM/ETH/NetLib/eth_driver.c +++ b/EVT/EXAM/ETH/NetLib/eth_driver.c @@ -535,13 +535,13 @@ void ETH_Configuration( uint8_t *macAddr ) uint32_t ETH_TxPktChainMode(uint16_t len, uint32_t *pBuff ) { /* Check if the descriptor is owned by the ETHERNET DMA (when set) or CPU (when reset) */ - if((DMATxDescToSet->Status & ETH_DMATxDesc_OWN)) + if( DMATxDescToSet->Status & ETH_DMATxDesc_OWN ) { - if((R8_ETH_ECON1 & RB_ETH_ECON1_TXRTS) == 0) - { - DMATxDescToSet->Status &= ~ETH_DMATxDesc_OWN; - } - else return ETH_ERROR; + if((R8_ETH_ECON1 & RB_ETH_ECON1_TXRTS) == 0) + { + DMATxDescToSet->Status &= ~ETH_DMATxDesc_OWN; + } + else return ETH_ERROR; /* Return ERROR: OWN bit set */ } DMATxDescToSet->Status |= ETH_DMATxDesc_OWN; R16_ETH_ETXLN = len; diff --git a/EVT/EXAM/ETH/NetLib/eth_driver.h b/EVT/EXAM/ETH/NetLib/eth_driver.h index 4ee7691..a7b7e0f 100644 --- a/EVT/EXAM/ETH/NetLib/eth_driver.h +++ b/EVT/EXAM/ETH/NetLib/eth_driver.h @@ -48,7 +48,7 @@ }while(0) /* definition for Ethernet frame */ -#define ETH_MAX_PACKET_SIZE 1536 /* ETH_HEADER + VLAN_TAG + MAX_ETH_PAYLOAD + ETH_CRC */ +#define ETH_MAX_PACKET_SIZE 1524 /* ETH_HEADER + VLAN_TAG + MAX_ETH_PAYLOAD + ETH_CRC */ #define ETH_HEADER 14 /* 6 byte Dest addr, 6 byte Src addr, 2 byte length/type */ #define ETH_CRC 4 /* Ethernet CRC */ #define ETH_EXTRA 2 /* Extra bytes in some cases */ diff --git a/EVT/EXAM/ETH/NetLib/libwchnet.a b/EVT/EXAM/ETH/NetLib/libwchnet.a index 8fa4baa..1a7b224 100644 Binary files a/EVT/EXAM/ETH/NetLib/libwchnet.a and b/EVT/EXAM/ETH/NetLib/libwchnet.a differ diff --git a/EVT/EXAM/FLASH/FLASH_Program/User/main.c b/EVT/EXAM/FLASH/FLASH_Program/User/main.c index f2beb25..9193538 100644 --- a/EVT/EXAM/FLASH/FLASH_Program/User/main.c +++ b/EVT/EXAM/FLASH/FLASH_Program/User/main.c @@ -1,8 +1,8 @@ /********************************** (C) COPYRIGHT ******************************* * File Name : main.c * Author : WCH - * Version : V1.0.0 - * Date : 2023/12/29 + * Version : V1.0.1 + * Date : 2026/05/22 * Description : Main program body. ********************************************************************************* * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. @@ -76,7 +76,7 @@ void Flash_Test(void) NbrOfPage = (PAGE_WRITE_END_ADDR - PAGE_WRITE_START_ADDR) / FLASH_PAGE_SIZE; - FLASH_ClearFlag(FLASH_FLAG_BSY | FLASH_FLAG_EOP |FLASH_FLAG_WRPRTERR); + FLASH_ClearFlag( FLASH_FLAG_EOP |FLASH_FLAG_WRPRTERR); for(EraseCounter = 0; (EraseCounter < NbrOfPage) && (FLASHStatus == FLASH_COMPLETE); EraseCounter++) { diff --git a/EVT/EXAM/PWR/PVD_VoltageJudger/.template b/EVT/EXAM/PWR/PVD_VoltageJudger/.template index b3b691b..634f1d1 100644 --- a/EVT/EXAM/PWR/PVD_VoltageJudger/.template +++ b/EVT/EXAM/PWR/PVD_VoltageJudger/.template @@ -8,7 +8,7 @@ Reset=true Vendor=WCH Link=WCH-Link Toolchain=RISC-V -Series=CH32V307 +Series=CH32V203 Description=ROM(byte): 256K, SRAM(byte): 64K, CHIP PINS: 64, GPIO PORTS: 51.\nWCH CH32V3 series of mainstream MCUs covers the needs of a large variety of applications in the industrial,medical and consumer markets. High performance with first-class peripherals and low-power,low-voltage operation is paired with a high level of integration at accessible prices with a simple architecture and easy-to-use tools. PeripheralVersion=1.4 diff --git a/EVT/EXAM/PWR/PVD_Wakeup/.template b/EVT/EXAM/PWR/PVD_Wakeup/.template index b6cb96a..ff34f28 100644 --- a/EVT/EXAM/PWR/PVD_Wakeup/.template +++ b/EVT/EXAM/PWR/PVD_Wakeup/.template @@ -8,7 +8,7 @@ Reset=true Vendor=WCH Link=WCH-Link Toolchain=RISC-V -Series=CH32V307 +Series=CH32V203 Description=ROM(byte): 256K, SRAM(byte): 64K, CHIP PINS: 64, GPIO PORTS: 51.\nWCH CH32V3 series of mainstream MCUs covers the needs of a large variety of applications in the industrial,medical and consumer markets. High performance with first-class peripherals and low-power,low-voltage operation is paired with a high level of integration at accessible prices with a simple architecture and easy-to-use tools. PeripheralVersion=1.4 diff --git a/EVT/EXAM/RCC/HSI_Calibration/.template b/EVT/EXAM/RCC/HSI_Calibration/.template index bac81dc..4123b55 100644 --- a/EVT/EXAM/RCC/HSI_Calibration/.template +++ b/EVT/EXAM/RCC/HSI_Calibration/.template @@ -8,7 +8,7 @@ Reset=true Vendor=WCH Link=WCH-Link Toolchain=RISC-V -Series=CH32V307 +Series=CH32V203 Description=ROM(byte): 256K, SRAM(byte): 64K, CHIP PINS: 64, GPIO PORTS: 51.\nWCH CH32V3 series of mainstream MCUs covers the needs of a large variety of applications in the industrial,medical and consumer markets. High performance with first-class peripherals and low-power,low-voltage operation is paired with a high level of integration at accessible prices with a simple architecture and easy-to-use tools. PeripheralVersion=1.4 diff --git a/EVT/EXAM/RTC/RTC_Calibrations/.template b/EVT/EXAM/RTC/RTC_Calibrations/.template index 6782d5c..7a7b71c 100644 --- a/EVT/EXAM/RTC/RTC_Calibrations/.template +++ b/EVT/EXAM/RTC/RTC_Calibrations/.template @@ -8,7 +8,7 @@ Reset=true Vendor=WCH Link=WCH-Link Toolchain=RISC-V -Series=CH32V307 +Series=CH32V203 Description=ROM(byte): 256K, SRAM(byte): 64K, CHIP PINS: 64, GPIO PORTS: 51.\nWCH CH32V3 series of mainstream MCUs covers the needs of a large variety of applications in the industrial,medical and consumer markets. High performance with first-class peripherals and low-power,low-voltage operation is paired with a high level of integration at accessible prices with a simple architecture and easy-to-use tools. PeripheralVersion=1.4 diff --git a/EVT/EXAM/SRC/Debug/debug.c b/EVT/EXAM/SRC/Debug/debug.c index 311b8d4..a00c322 100644 --- a/EVT/EXAM/SRC/Debug/debug.c +++ b/EVT/EXAM/SRC/Debug/debug.c @@ -1,8 +1,8 @@ /********************************** (C) COPYRIGHT ******************************* * File Name : debug.c * Author : WCH - * Version : V1.0.0 - * Date : 2021/06/06 + * Version : V1.0.1 + * Date : 2026/07/10 * Description : This file contains all the functions prototypes for UART * Printf , Delay functions. ********************************************************************************* @@ -173,16 +173,14 @@ __attribute__((used)) int _write(int fd, char *buf, int size) { int i = 0; - #if (SDI_PRINT == SDI_PR_OPEN) int writeSize = size; - do { - /** - * data0 data1 8 byte - * data0 The storage length of the lowest byte, with a maximum of 7 bytes. + * data0 + data1 = 8 bytes + * data0 The lowest byte storage length, the maximum is 7 + * */ while( (*(DEBUG_DATA0_ADDRESS) != 0u)) @@ -192,23 +190,37 @@ int _write(int fd, char *buf, int size) if(writeSize>7) { - *(DEBUG_DATA1_ADDRESS) = (*(buf+i+3)) | (*(buf+i+4)<<8) | (*(buf+i+5)<<16) | (*(buf+i+6)<<24); - *(DEBUG_DATA0_ADDRESS) = (7u) | (*(buf+i)<<8) | (*(buf+i+1)<<16) | (*(buf+i+2)<<24); + *(DEBUG_DATA1_ADDRESS) = \ + ((uint8_t)(buf[i+3])) | \ + ((uint8_t)(buf[i+4]) << 8) | \ + ((uint8_t)(buf[i+5]) << 16) | \ + ((uint8_t)(buf[i+6]) << 24); + *(DEBUG_DATA0_ADDRESS) = \ + (7u) | \ + ((uint8_t)(buf[i]) << 8) | \ + ((uint8_t)(buf[i+1]) << 16) | \ + ((uint8_t)(buf[i+2]) << 24); i += 7; writeSize -= 7; } else { - *(DEBUG_DATA1_ADDRESS) = (*(buf+i+3)) | (*(buf+i+4)<<8) | (*(buf+i+5)<<16) | (*(buf+i+6)<<24); - *(DEBUG_DATA0_ADDRESS) = (writeSize) | (*(buf+i)<<8) | (*(buf+i+1)<<16) | (*(buf+i+2)<<24); - + uint8_t tmp = (uint8_t)writeSize; + *(DEBUG_DATA1_ADDRESS) = \ + ((tmp > 3 ? (uint8_t)buf[i+3] : 0)) | \ + ((tmp > 4 ? (uint8_t)buf[i+4] : 0) << 8) | \ + ((tmp > 5 ? (uint8_t)buf[i+5] : 0) << 16) |\ + ((tmp > 6 ? (uint8_t)buf[i+6] : 0) << 24); + *(DEBUG_DATA0_ADDRESS) = + (tmp) | ((uint8_t)buf[i] << 8) | \ + ((tmp > 1 ? (uint8_t)buf[i+1] : 0) << 16) |\ + ((tmp > 2 ? (uint8_t)buf[i+2] : 0) << 24); writeSize = 0; } } while (writeSize); - #else for(i = 0; i < size; i++){ #if(DEBUG == DEBUG_UART1) diff --git a/EVT/EXAM/SRC/Peripheral/inc/ch32v20x.h b/EVT/EXAM/SRC/Peripheral/inc/ch32v20x.h index 47a3b57..d97c71d 100644 --- a/EVT/EXAM/SRC/Peripheral/inc/ch32v20x.h +++ b/EVT/EXAM/SRC/Peripheral/inc/ch32v20x.h @@ -45,7 +45,7 @@ extern "C" { /* CH32V20x Standard Peripheral Library version number */ #define __CH32V20x_STDPERIPH_VERSION_MAIN (0x02) /* [15:8] main version */ -#define __CH32V20x_STDPERIPH_VERSION_SUB (0x03) /* [7:0] sub version */ +#define __CH32V20x_STDPERIPH_VERSION_SUB (0x04) /* [7:0] sub version */ #define __CH32V20x_STDPERIPH_VERSION ( (__CH32V20x_STDPERIPH_VERSION_MAIN << 8)\ |(__CH32V20x_STDPERIPH_VERSION_SUB << 0)) diff --git a/EVT/EXAM/SRC/Peripheral/inc/ch32v20x_adc.h b/EVT/EXAM/SRC/Peripheral/inc/ch32v20x_adc.h index dd90c63..f20900b 100644 --- a/EVT/EXAM/SRC/Peripheral/inc/ch32v20x_adc.h +++ b/EVT/EXAM/SRC/Peripheral/inc/ch32v20x_adc.h @@ -1,8 +1,8 @@ /********************************** (C) COPYRIGHT ******************************* * File Name : ch32v20x_adc.h * Author : WCH - * Version : V1.0.0 - * Date : 2021/06/06 + * Version : V1.0.1 + * Date : 2026/01/20 * Description : This file contains all the functions prototypes for the * ADC firmware library. ********************************************************************************* @@ -75,13 +75,6 @@ typedef struct #define ADC_ExternalTrigConv_T1_CC3 ((uint32_t)0x00040000) #define ADC_ExternalTrigConv_None ((uint32_t)0x000E0000) -#define ADC_ExternalTrigConv_T3_CC1 ((uint32_t)0x00000000) -#define ADC_ExternalTrigConv_T2_CC3 ((uint32_t)0x00020000) -#define ADC_ExternalTrigConv_T8_CC1 ((uint32_t)0x00060000) -#define ADC_ExternalTrigConv_T8_TRGO ((uint32_t)0x00080000) -#define ADC_ExternalTrigConv_T5_CC1 ((uint32_t)0x000A0000) -#define ADC_ExternalTrigConv_T5_CC3 ((uint32_t)0x000C0000) - /* ADC_data_align */ #define ADC_DataAlign_Right ((uint32_t)0x00000000) #define ADC_DataAlign_Left ((uint32_t)0x00000800) diff --git a/EVT/EXAM/SRC/Peripheral/src/ch32v20x_dbgmcu.c b/EVT/EXAM/SRC/Peripheral/src/ch32v20x_dbgmcu.c index 4f397c3..3091cb5 100644 --- a/EVT/EXAM/SRC/Peripheral/src/ch32v20x_dbgmcu.c +++ b/EVT/EXAM/SRC/Peripheral/src/ch32v20x_dbgmcu.c @@ -1,8 +1,8 @@ /********************************** (C) COPYRIGHT ******************************* * File Name : ch32v20x_dbgmcu.c * Author : WCH - * Version : V1.0.0 - * Date : 2021/06/06 + * Version : V1.0.1 + * Date : 2026/06/18 * Description : This file provides all the DBGMCU firmware functions. ********************************************************************************* * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. @@ -115,6 +115,7 @@ void DBGMCU_Config(uint32_t DBGMCU_Periph, FunctionalState NewState) * CH32V203F6P-0x203705x0-0x203905x0 * CH32V203F8P-0x203A05x0 * CH32V203RBT-0x203405xC + * CH32V203K8U-0x203215x0 * CH32V208WBU-0x208005xC * CH32V208RBT-0x208105xC * CH32V208CBU-0x208205xC diff --git a/EVT/EXAM/SRC/Peripheral/src/ch32v20x_flash.c b/EVT/EXAM/SRC/Peripheral/src/ch32v20x_flash.c index 74a91b7..3472a75 100644 --- a/EVT/EXAM/SRC/Peripheral/src/ch32v20x_flash.c +++ b/EVT/EXAM/SRC/Peripheral/src/ch32v20x_flash.c @@ -1,8 +1,8 @@ /********************************** (C) COPYRIGHT ******************************* * File Name : ch32v20x_flash.c * Author : WCH - * Version : V1.0.1 - * Date : 2025/01/09 + * Version : V1.0.2 + * Date : 2026/08/06 * Description : This file provides all the FLASH firmware functions. ********************************************************************************* * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. @@ -56,8 +56,8 @@ #define EEPROM_ADDRESS ((uint32_t)0x8070000) /* Delay definition */ -#define EraseTimeout ((uint32_t)0x00130000) -#define ProgramTimeout ((uint32_t)0x00005000) +#define EraseTimeout ((uint32_t)0x10000000) +#define ProgramTimeout ((uint32_t)0x10000000) /* Flash Program Valid Address */ #define ValidAddrStart (FLASH_BASE) diff --git a/EVT/EXAM/SRC/Peripheral/src/ch32v20x_gpio.c b/EVT/EXAM/SRC/Peripheral/src/ch32v20x_gpio.c index 67f84fa..5fcfd99 100644 --- a/EVT/EXAM/SRC/Peripheral/src/ch32v20x_gpio.c +++ b/EVT/EXAM/SRC/Peripheral/src/ch32v20x_gpio.c @@ -2,7 +2,7 @@ * File Name : ch32v20x_gpio.c * Author : WCH * Version : V1.0.1 - * Date : 2025/04/26 + * Date : 2025/06/18 * Description : This file provides all the GPIO firmware functions. ********************************************************************************* * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. @@ -849,6 +849,30 @@ void GPIO_IPD_Unused(void) GPIO_Init(GPIOD, &GPIO_InitStructure); break; } + case 0x20321500: //CH32V203K8U + { + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11\ + |GPIO_Pin_12|GPIO_Pin_13\ + |GPIO_Pin_14; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; + GPIO_Init(GPIOB, &GPIO_InitStructure); + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1\ + |GPIO_Pin_2|GPIO_Pin_3\ + |GPIO_Pin_4|GPIO_Pin_5\ + |GPIO_Pin_6|GPIO_Pin_7\ + |GPIO_Pin_8|GPIO_Pin_9\ + |GPIO_Pin_10|GPIO_Pin_11\ + |GPIO_Pin_12|GPIO_Pin_13\ + |GPIO_Pin_14|GPIO_Pin_15; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; + GPIO_Init(GPIOC, &GPIO_InitStructure); + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2|GPIO_Pin_3\ + |GPIO_Pin_4|GPIO_Pin_5\ + |GPIO_Pin_6; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; + GPIO_Init(GPIOD, &GPIO_InitStructure); + break; + } case 0x20330500: //CH32V203C6T { GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1\ diff --git a/EVT/EXAM/TIM/Encoder/.template b/EVT/EXAM/TIM/Encoder/.template index 3fd17a0..9b41339 100644 --- a/EVT/EXAM/TIM/Encoder/.template +++ b/EVT/EXAM/TIM/Encoder/.template @@ -8,7 +8,7 @@ Reset=true Vendor=WCH Link=WCH-Link Toolchain=RISC-V -Series=CH32V307 +Series=CH32V203 Description=ROM(byte): 256K, SRAM(byte): 64K, CHIP PINS: 64, GPIO PORTS: 51.\nWCH CH32V3 series of mainstream MCUs covers the needs of a large variety of applications in the industrial,medical and consumer markets. High performance with first-class peripherals and low-power,low-voltage operation is paired with a high level of integration at accessible prices with a simple architecture and easy-to-use tools. PeripheralVersion=1.4 diff --git a/EVT/PUB/CH32V20xSCH.pdf b/EVT/PUB/CH32V20xSCH.pdf index 2ebffd9..5a263aa 100644 Binary files a/EVT/PUB/CH32V20xSCH.pdf and b/EVT/PUB/CH32V20xSCH.pdf differ diff --git a/EVT/PUB/SCHPCB/CH32F&V208C-R0/CH32F&V208C-R0-1v1.PcbDoc b/EVT/PUB/SCHPCB/CH32F&V208C-R0/CH32F&V208C-R0-1v1.PcbDoc index 86e6d7f..8933450 100644 Binary files a/EVT/PUB/SCHPCB/CH32F&V208C-R0/CH32F&V208C-R0-1v1.PcbDoc and b/EVT/PUB/SCHPCB/CH32F&V208C-R0/CH32F&V208C-R0-1v1.PcbDoc differ diff --git a/EVT/PUB/SCHPCB/CH32F&V208C-R0/CH32F&V208C-R0.SchDoc b/EVT/PUB/SCHPCB/CH32F&V208C-R0/CH32F&V208C-R0.SchDoc index 308ff4f..7054b48 100644 Binary files a/EVT/PUB/SCHPCB/CH32F&V208C-R0/CH32F&V208C-R0.SchDoc and b/EVT/PUB/SCHPCB/CH32F&V208C-R0/CH32F&V208C-R0.SchDoc differ diff --git a/EVT/PUB/SCHPCB/CH32F&V208G-R0/CH32F&V208G-R0.PcbDoc b/EVT/PUB/SCHPCB/CH32F&V208G-R0/CH32F&V208G-R0.PcbDoc index 99f8ead..69e1c1f 100644 Binary files a/EVT/PUB/SCHPCB/CH32F&V208G-R0/CH32F&V208G-R0.PcbDoc and b/EVT/PUB/SCHPCB/CH32F&V208G-R0/CH32F&V208G-R0.PcbDoc differ diff --git a/EVT/PUB/SCHPCB/CH32F&V208G-R0/CH32F&V208G-R0.SchDoc b/EVT/PUB/SCHPCB/CH32F&V208G-R0/CH32F&V208G-R0.SchDoc index 1c810fa..e280c17 100644 Binary files a/EVT/PUB/SCHPCB/CH32F&V208G-R0/CH32F&V208G-R0.SchDoc and b/EVT/PUB/SCHPCB/CH32F&V208G-R0/CH32F&V208G-R0.SchDoc differ diff --git a/EVT/PUB/SCHPCB/CH32F&V208R-R0/CH32F&V208R-R0-1v1.PcbDoc b/EVT/PUB/SCHPCB/CH32F&V208R-R0/CH32F&V208R-R0-1v1.PcbDoc index 012e3d8..49fe775 100644 Binary files a/EVT/PUB/SCHPCB/CH32F&V208R-R0/CH32F&V208R-R0-1v1.PcbDoc and b/EVT/PUB/SCHPCB/CH32F&V208R-R0/CH32F&V208R-R0-1v1.PcbDoc differ diff --git a/EVT/PUB/SCHPCB/CH32F&V208R-R0/CH32F&V208R-R0.SchDoc b/EVT/PUB/SCHPCB/CH32F&V208R-R0/CH32F&V208R-R0.SchDoc index b7a5329..7ce47bf 100644 Binary files a/EVT/PUB/SCHPCB/CH32F&V208R-R0/CH32F&V208R-R0.SchDoc and b/EVT/PUB/SCHPCB/CH32F&V208R-R0/CH32F&V208R-R0.SchDoc differ diff --git a/EVT/PUB/SCHPCB/CH32F&V208W-R0/CH32F&V208W-R0-1v4.PcbDoc b/EVT/PUB/SCHPCB/CH32F&V208W-R0/CH32F&V208W-R0-1v4.PcbDoc index feb862f..30bc4cc 100644 Binary files a/EVT/PUB/SCHPCB/CH32F&V208W-R0/CH32F&V208W-R0-1v4.PcbDoc and b/EVT/PUB/SCHPCB/CH32F&V208W-R0/CH32F&V208W-R0-1v4.PcbDoc differ diff --git a/EVT/PUB/SCHPCB/CH32F&V208W-R0/CH32F&V208W-R0.SchDoc b/EVT/PUB/SCHPCB/CH32F&V208W-R0/CH32F&V208W-R0.SchDoc index 51861da..a8ff3fc 100644 Binary files a/EVT/PUB/SCHPCB/CH32F&V208W-R0/CH32F&V208W-R0.SchDoc and b/EVT/PUB/SCHPCB/CH32F&V208W-R0/CH32F&V208W-R0.SchDoc differ diff --git a/EVT/PUB/SCHPCB/CH32V203C6T6-R0/CH32V203C6T6-R0.SchDoc b/EVT/PUB/SCHPCB/CH32V203C6T6-R0/CH32V203C6T6-R0.SchDoc index 99712f4..1506fe3 100644 Binary files a/EVT/PUB/SCHPCB/CH32V203C6T6-R0/CH32V203C6T6-R0.SchDoc and b/EVT/PUB/SCHPCB/CH32V203C6T6-R0/CH32V203C6T6-R0.SchDoc differ diff --git a/EVT/PUB/SCHPCB/CH32V203C6T6-R0/CH32Vx03C-R0-1v0.PcbDoc b/EVT/PUB/SCHPCB/CH32V203C6T6-R0/CH32Vx03C-R0-1v0.PcbDoc index 1e7336a..e75133c 100644 Binary files a/EVT/PUB/SCHPCB/CH32V203C6T6-R0/CH32Vx03C-R0-1v0.PcbDoc and b/EVT/PUB/SCHPCB/CH32V203C6T6-R0/CH32Vx03C-R0-1v0.PcbDoc differ diff --git a/EVT/PUB/SCHPCB/CH32V203C8T6-R0/CH32V203C8T6-R0.SchDoc b/EVT/PUB/SCHPCB/CH32V203C8T6-R0/CH32V203C8T6-R0.SchDoc index 77e9b3b..5ba5f0e 100644 Binary files a/EVT/PUB/SCHPCB/CH32V203C8T6-R0/CH32V203C8T6-R0.SchDoc and b/EVT/PUB/SCHPCB/CH32V203C8T6-R0/CH32V203C8T6-R0.SchDoc differ diff --git a/EVT/PUB/SCHPCB/CH32V203C8T6-R0/CH32Vx03C-R0-1v0.PcbDoc b/EVT/PUB/SCHPCB/CH32V203C8T6-R0/CH32Vx03C-R0-1v0.PcbDoc index 1e7336a..50e8679 100644 Binary files a/EVT/PUB/SCHPCB/CH32V203C8T6-R0/CH32Vx03C-R0-1v0.PcbDoc and b/EVT/PUB/SCHPCB/CH32V203C8T6-R0/CH32Vx03C-R0-1v0.PcbDoc differ diff --git a/EVT/PUB/SCHPCB/CH32V203C8T6-R1/CH32V203C8T6-R1.SchDoc b/EVT/PUB/SCHPCB/CH32V203C8T6-R1/CH32V203C8T6-R1.SchDoc index 71769ae..ac0eb73 100644 Binary files a/EVT/PUB/SCHPCB/CH32V203C8T6-R1/CH32V203C8T6-R1.SchDoc and b/EVT/PUB/SCHPCB/CH32V203C8T6-R1/CH32V203C8T6-R1.SchDoc differ diff --git a/EVT/PUB/SCHPCB/CH32V203C8T6-R1/CH32x203C-R1-1v0.PcbDoc b/EVT/PUB/SCHPCB/CH32V203C8T6-R1/CH32x203C-R1-1v0.PcbDoc index 1ee839b..20240a9 100644 Binary files a/EVT/PUB/SCHPCB/CH32V203C8T6-R1/CH32x203C-R1-1v0.PcbDoc and b/EVT/PUB/SCHPCB/CH32V203C8T6-R1/CH32x203C-R1-1v0.PcbDoc differ diff --git a/EVT/PUB/SCHPCB/CH32V203C8U6-R0/CH32V203C8U6-R0.SchDoc b/EVT/PUB/SCHPCB/CH32V203C8U6-R0/CH32V203C8U6-R0.SchDoc index fbf18a1..260b806 100644 Binary files a/EVT/PUB/SCHPCB/CH32V203C8U6-R0/CH32V203C8U6-R0.SchDoc and b/EVT/PUB/SCHPCB/CH32V203C8U6-R0/CH32V203C8U6-R0.SchDoc differ diff --git a/EVT/PUB/SCHPCB/CH32V203C8U6-R0/CH32x203C8U6-R0-1v0.PcbDoc b/EVT/PUB/SCHPCB/CH32V203C8U6-R0/CH32x203C8U6-R0-1v0.PcbDoc index 5616ca2..e96eda5 100644 Binary files a/EVT/PUB/SCHPCB/CH32V203C8U6-R0/CH32x203C8U6-R0-1v0.PcbDoc and b/EVT/PUB/SCHPCB/CH32V203C8U6-R0/CH32x203C8U6-R0-1v0.PcbDoc differ diff --git a/EVT/PUB/SCHPCB/CH32V203F6P6-R0/CH32V203F-R0-1v0.PcbDoc b/EVT/PUB/SCHPCB/CH32V203F6P6-R0/CH32V203F-R0-1v0.PcbDoc index 295cf19..b72d026 100644 Binary files a/EVT/PUB/SCHPCB/CH32V203F6P6-R0/CH32V203F-R0-1v0.PcbDoc and b/EVT/PUB/SCHPCB/CH32V203F6P6-R0/CH32V203F-R0-1v0.PcbDoc differ diff --git a/EVT/PUB/SCHPCB/CH32V203F6P6-R0/CH32V203F6P6-R0.SchDoc b/EVT/PUB/SCHPCB/CH32V203F6P6-R0/CH32V203F6P6-R0.SchDoc index 1f15565..d96017b 100644 Binary files a/EVT/PUB/SCHPCB/CH32V203F6P6-R0/CH32V203F6P6-R0.SchDoc and b/EVT/PUB/SCHPCB/CH32V203F6P6-R0/CH32V203F6P6-R0.SchDoc differ diff --git a/EVT/PUB/SCHPCB/CH32V203F8P6-R0/CH32V203F8P6-R0.SchDoc b/EVT/PUB/SCHPCB/CH32V203F8P6-R0/CH32V203F8P6-R0.SchDoc index 2959c2a..d3224d8 100644 Binary files a/EVT/PUB/SCHPCB/CH32V203F8P6-R0/CH32V203F8P6-R0.SchDoc and b/EVT/PUB/SCHPCB/CH32V203F8P6-R0/CH32V203F8P6-R0.SchDoc differ diff --git a/EVT/PUB/SCHPCB/CH32V203F8P6-R0/CH32V20xF8-R0-1v0.PcbDoc b/EVT/PUB/SCHPCB/CH32V203F8P6-R0/CH32V20xF8-R0-1v0.PcbDoc index 0418721..954ccd4 100644 Binary files a/EVT/PUB/SCHPCB/CH32V203F8P6-R0/CH32V20xF8-R0-1v0.PcbDoc and b/EVT/PUB/SCHPCB/CH32V203F8P6-R0/CH32V20xF8-R0-1v0.PcbDoc differ diff --git a/EVT/PUB/SCHPCB/CH32V203F8U6-R0/CH32V203F8U6-R0-1v0.PcbDoc b/EVT/PUB/SCHPCB/CH32V203F8U6-R0/CH32V203F8U6-R0-1v0.PcbDoc index 73f14c7..3d7abef 100644 Binary files a/EVT/PUB/SCHPCB/CH32V203F8U6-R0/CH32V203F8U6-R0-1v0.PcbDoc and b/EVT/PUB/SCHPCB/CH32V203F8U6-R0/CH32V203F8U6-R0-1v0.PcbDoc differ diff --git a/EVT/PUB/SCHPCB/CH32V203F8U6-R0/CH32V203F8U6-R0.SchDoc b/EVT/PUB/SCHPCB/CH32V203F8U6-R0/CH32V203F8U6-R0.SchDoc index 24d9566..8b5f709 100644 Binary files a/EVT/PUB/SCHPCB/CH32V203F8U6-R0/CH32V203F8U6-R0.SchDoc and b/EVT/PUB/SCHPCB/CH32V203F8U6-R0/CH32V203F8U6-R0.SchDoc differ diff --git a/EVT/PUB/SCHPCB/CH32V203G6U6-R0/CH32V203G-R0-1v0.PcbDoc b/EVT/PUB/SCHPCB/CH32V203G6U6-R0/CH32V203G-R0-1v0.PcbDoc index e88e88c..eeb0878 100644 Binary files a/EVT/PUB/SCHPCB/CH32V203G6U6-R0/CH32V203G-R0-1v0.PcbDoc and b/EVT/PUB/SCHPCB/CH32V203G6U6-R0/CH32V203G-R0-1v0.PcbDoc differ diff --git a/EVT/PUB/SCHPCB/CH32V203G6U6-R0/CH32V203G6U6-R0.SchDoc b/EVT/PUB/SCHPCB/CH32V203G6U6-R0/CH32V203G6U6-R0.SchDoc index 0e1b9a7..76a3986 100644 Binary files a/EVT/PUB/SCHPCB/CH32V203G6U6-R0/CH32V203G6U6-R0.SchDoc and b/EVT/PUB/SCHPCB/CH32V203G6U6-R0/CH32V203G6U6-R0.SchDoc differ diff --git a/EVT/PUB/SCHPCB/CH32V203K6T6-R0/CH32V203K6T6-R0.SchDoc b/EVT/PUB/SCHPCB/CH32V203K6T6-R0/CH32V203K6T6-R0.SchDoc index 4b8c13f..ac0b0bc 100644 Binary files a/EVT/PUB/SCHPCB/CH32V203K6T6-R0/CH32V203K6T6-R0.SchDoc and b/EVT/PUB/SCHPCB/CH32V203K6T6-R0/CH32V203K6T6-R0.SchDoc differ diff --git a/EVT/PUB/SCHPCB/CH32V203K6T6-R0/CH32x203K-R0-1v0.PcbDoc b/EVT/PUB/SCHPCB/CH32V203K6T6-R0/CH32x203K-R0-1v0.PcbDoc index 0fe0446..7835077 100644 Binary files a/EVT/PUB/SCHPCB/CH32V203K6T6-R0/CH32x203K-R0-1v0.PcbDoc and b/EVT/PUB/SCHPCB/CH32V203K6T6-R0/CH32x203K-R0-1v0.PcbDoc differ diff --git a/EVT/PUB/SCHPCB/CH32V203K8T6-R0/CH32V203K8T6-R0.SchDoc b/EVT/PUB/SCHPCB/CH32V203K8T6-R0/CH32V203K8T6-R0.SchDoc index d28e08b..b680eda 100644 Binary files a/EVT/PUB/SCHPCB/CH32V203K8T6-R0/CH32V203K8T6-R0.SchDoc and b/EVT/PUB/SCHPCB/CH32V203K8T6-R0/CH32V203K8T6-R0.SchDoc differ diff --git a/EVT/PUB/SCHPCB/CH32V203K8T6-R0/CH32x203K-R0-1v0.PcbDoc b/EVT/PUB/SCHPCB/CH32V203K8T6-R0/CH32x203K-R0-1v0.PcbDoc index 2a51498..32a093f 100644 Binary files a/EVT/PUB/SCHPCB/CH32V203K8T6-R0/CH32x203K-R0-1v0.PcbDoc and b/EVT/PUB/SCHPCB/CH32V203K8T6-R0/CH32x203K-R0-1v0.PcbDoc differ diff --git a/EVT/PUB/SCHPCB/CH32V203RBT6-R1/CH32F&Vx0xR-R1-1v2.PcbDoc b/EVT/PUB/SCHPCB/CH32V203RBT6-R1/CH32F&Vx0xR-R1-1v2.PcbDoc index 92c4e9e..31cec40 100644 Binary files a/EVT/PUB/SCHPCB/CH32V203RBT6-R1/CH32F&Vx0xR-R1-1v2.PcbDoc and b/EVT/PUB/SCHPCB/CH32V203RBT6-R1/CH32F&Vx0xR-R1-1v2.PcbDoc differ diff --git a/EVT/PUB/SCHPCB/CH32V203RBT6-R1/CH32V203RBT6-R1.SchDoc b/EVT/PUB/SCHPCB/CH32V203RBT6-R1/CH32V203RBT6-R1.SchDoc index 2536070..61d96c8 100644 Binary files a/EVT/PUB/SCHPCB/CH32V203RBT6-R1/CH32V203RBT6-R1.SchDoc and b/EVT/PUB/SCHPCB/CH32V203RBT6-R1/CH32V203RBT6-R1.SchDoc differ diff --git a/EVT/PUB/SCHPCB/CH32V20xG8-R0/CH32V20xG8-R0-1v1.PcbDoc b/EVT/PUB/SCHPCB/CH32V20xG8-R0/CH32V20xG8-R0-1v1.PcbDoc index 848466d..7f3423a 100644 Binary files a/EVT/PUB/SCHPCB/CH32V20xG8-R0/CH32V20xG8-R0-1v1.PcbDoc and b/EVT/PUB/SCHPCB/CH32V20xG8-R0/CH32V20xG8-R0-1v1.PcbDoc differ diff --git a/EVT/PUB/SCHPCB/CH32V20xG8-R0/CH32V20xG8-R0.SchDoc b/EVT/PUB/SCHPCB/CH32V20xG8-R0/CH32V20xG8-R0.SchDoc index c9b096a..2def472 100644 Binary files a/EVT/PUB/SCHPCB/CH32V20xG8-R0/CH32V20xG8-R0.SchDoc and b/EVT/PUB/SCHPCB/CH32V20xG8-R0/CH32V20xG8-R0.SchDoc differ