diff --git a/README.md b/README.md index 2781c471b70c5708c695029c8bc56ae088c5eb9a..e827e701ec2e8a6889160b2d8a66f25963394fa7 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -Solarec 1.0.0.6 +SolarA2 1.0.1.2 # 目录整体结构 **表 1** 目录整体结构说明 diff --git a/application/board_sample/dimming/dimming_sample.c b/application/board_sample/dimming/dimming_sample.c deleted file mode 100644 index 2ea43b219329c4607099c5ab85e225322369e38b..0000000000000000000000000000000000000000 --- a/application/board_sample/dimming/dimming_sample.c +++ /dev/null @@ -1,92 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file dimming_sample.c - * @author MCU Application Team - * @brief Dimming sample code - * @details This file provides firmware functions to manage the following - * functionalities of the common function sample. - * + Dimming sample functions - */ - -/* Includes ------------------------------------------------------------------ */ -#include "dimming_sample.h" - -/* Private macro ------------------------------------------------------------- */ -#define BOARD_DIMMING_SAMPLE_BAUDRATE 115200 - -/* Private variables --------------------------------------------------------- */ -static TIMER_Handle g_timer1; /**< Timer handle */ -static GPT_Handle g_gpt1; /**< Gpt handle */ - -static void TIMER1_Init(void); -static void GPT1_Init(void); - -/** - * @brief Timer initialization function, it is automatically generated by the code generation tool. - */ -static void TIMER1_Init(void) -{ - g_timer1.baseAddress = TIMER1; - g_timer1.load = 1; /* Set timer value immediately */ - g_timer1.bgLoad = 1; - g_timer1.mode = TIMER_MODE_RUN_PERIODIC; /* Run in period mode */ - g_timer1.prescaler = 0; /* don't frequency division */ - g_timer1.interruptEn = 1; /* trigger interrupt enable */ - g_timer1.size = 1; /* 1 for 32bit, 0 for 16bit */ - g_timer1.irqNum = IRQ_TIMER1; - IRQ_SetPriority(g_timer1.irqNum, 1); /* set timer0 interrupt priority to 1, 1~7 */ - IRQ_EnableN(g_timer1.irqNum); /* timer interrupt enable */ - HAL_TIMER_Init(&g_timer1); -} - -/** - * @brief GPT initialization function, it is automatically generated by the code generation tool. - */ -static void GPT1_Init(void) -{ - g_gpt1.baseAddress = GPT1; - g_gpt1.duty = 0; - g_gpt1.period = BOARD_DIM_TABLE_MAX_VALUE; - g_gpt1.pwmKeep = BASE_CFG_SET; - HAL_GPT_Init(&g_gpt1); -} - -/** - * @brief Using gpt dimming example. - * @return int Execution result. - */ -int BOARD_DIMMING_Sample(void) -{ - DBG_UartPrintInit(BOARD_DIMMING_SAMPLE_BAUDRATE); - IRQ_Enable(); - IRQ_Init(); - - TIMER1_Init(); - GPT1_Init(); - - BOARD_DIM_Init(&g_gpt1, &g_timer1, 0, 1000); /* 1000 : 1000ms. */ - - while (1) { - BOARD_DIM_SetDuty(0, 255); /* 255 : dimming level. */ - BASE_FUNC_DELAY_S(5); /* 5 : 5 second. */ - BOARD_DIM_SetDuty(0, 0); - BASE_FUNC_DELAY_S(5); /* 5 : 5 second. */ - } - - return 0; -} \ No newline at end of file diff --git a/application/board_sample/dimming/dimming_sample.h b/application/board_sample/dimming/dimming_sample.h deleted file mode 100644 index cd244553be0d84ccd7eec1214e676da5d45bf9d3..0000000000000000000000000000000000000000 --- a/application/board_sample/dimming/dimming_sample.h +++ /dev/null @@ -1,34 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file dimming_sample.h - * @author MCU Application Team - * @brief Include the header file of the dimming_sample.c file. - */ - -/* Define to prevent recursive inclusion ------------------------------------- */ -#ifndef McuMagicTag_DIMMING_SAMPLE_H -#define McuMagicTag_DIMMING_SAMPLE_H - -/* Includes ------------------------------------------------------------------ */ -#include "dimming.h" -#include "debug.h" - -/* Exported global functions ------------------------------------------------- */ -int BOARD_DIMMING_Sample(void); - -#endif /* McuMagicTag_DIMMING_SAMPLE_H */ \ No newline at end of file diff --git a/application/board_sample/key/key_sample.c b/application/board_sample/key/key_sample.c deleted file mode 100644 index 2dcde50605f4701ee73aace2cbb4ef31d140124f..0000000000000000000000000000000000000000 --- a/application/board_sample/key/key_sample.c +++ /dev/null @@ -1,112 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file key_sample.c - * @author MCU Application Team - * @brief Key sample code - * @details This file provides firmware functions to manage the following - * functionalities of the common function sample. - * + Key sample functions - */ - -/* Includes ------------------------------------------------------------------ */ -#include "key_sample.h" - -/* Private macro ------------------------------------------------------------- */ -#define BOARD_KEY_SAMPLE_BAUDRATE 115200 - -/* Private variables --------------------------------------------------------- */ -static TIMER_Handle g_timer1; /**< Timer handle */ - -static void TIMER1_Init(void); -void Key0LongPress(void); -void Key0ShortPress(void); -void Key1LongPress(void); -void Key1ShortPress(void); - -/** - * @brief Timer initialization function, it is automatically generated by the code generation tool. - */ -static void TIMER1_Init(void) -{ - g_timer1.baseAddress = TIMER1; - g_timer1.load = 1; /* Set timer value immediately */ - g_timer1.bgLoad = 1; - g_timer1.mode = TIMER_MODE_RUN_PERIODIC; /* Run in period mode */ - g_timer1.prescaler = 0; /* don't frequency division */ - g_timer1.interruptEn = 1; /* trigger interrupt enable */ - g_timer1.size = 1; /* 1 for 32bit, 0 for 16bit */ - g_timer1.irqNum = IRQ_TIMER1; - IRQ_SetPriority(g_timer1.irqNum, 1); /* set timer0 interrupt priority to 1, 1~7 */ - IRQ_EnableN(g_timer1.irqNum); /* timer interrupt enable */ - HAL_TIMER_Init(&g_timer1); -} - -/** - * @brief Pin 0 long press binding functions. - */ -void Key0LongPress() -{ - DBG_PRINTF("pin0 long\r\n"); -} - -/** - * @brief Pin 0 short press binding functions. - */ -void Key0ShortPress() -{ - DBG_PRINTF("pin0 short\r\n"); -} - -/** - * @brief Pin 1 long press binding functions. - */ -void Key1LongPress() -{ - DBG_PRINTF("pin1 long\r\n"); -} - -/** - * @brief Pin 1 short press binding functions. - */ -void Key1ShortPress() -{ - DBG_PRINTF("pin1 short\r\n"); -} - -/** - * @brief Key press detection example. - * @return int Execution result. - */ -int BOARD_KEY_Sample(void) -{ - DBG_UartPrintInit(BOARD_KEY_SAMPLE_BAUDRATE); - IRQ_Enable(); - IRQ_Init(); - TIMER1_Init(); - - BOARD_KEY_Init(&g_timer1, 100, 1000); /* 100 : 100ms, 1000 : 1000ms */ - - BOARD_KEY_Register(GPIO3, GPIO_PIN_0, Key0LongPress, Key0ShortPress); - BOARD_KEY_Register(GPIO3, GPIO_PIN_1, Key1LongPress, Key1ShortPress); - - HAL_TIMER_Start(&g_timer1); - - while (1) { - } - return 0; -} \ No newline at end of file diff --git a/application/board_sample/key/key_sample.h b/application/board_sample/key/key_sample.h deleted file mode 100644 index 7b9749125dcadc829835762a72b57d1777185a20..0000000000000000000000000000000000000000 --- a/application/board_sample/key/key_sample.h +++ /dev/null @@ -1,34 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file key_sample.h - * @author MCU Application Team - * @brief Include the header file of the key_sample.c file. - */ - -/* Define to prevent recursive inclusion ------------------------------------- */ -#ifndef McuMagicTag_KEY_SAMPLE_H -#define McuMagicTag_KEY_SAMPLE_H - -/* Includes ------------------------------------------------------------------ */ -#include "key.h" -#include "debug.h" - -/* Exported global functions ------------------------------------------------- */ -int BOARD_KEY_Sample(void); - -#endif /* McuMagicTag_KEY_SAMPLE_H */ \ No newline at end of file diff --git a/application/board_sample/key/matrixkey_sample.c b/application/board_sample/key/matrixkey_sample.c deleted file mode 100644 index 07f4450d16c8cd20e9af6f3f7a567bd58118175f..0000000000000000000000000000000000000000 --- a/application/board_sample/key/matrixkey_sample.c +++ /dev/null @@ -1,108 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file matrixkey_sample.c - * @author MCU Application Team - * @brief Matrix key sample code - * @details This file provides firmware functions to manage the following - * functionalities of the common function sample. - * + Matrix key sample functions - */ - -/* Includes ------------------------------------------------------------------ */ -#include "matrixkey_sample.h" - -/* Private macro ------------------------------------------------------------- */ -#define BOARD_MATRIXKEY_SAMPLE_BAUDRATE 115200 - -/* Private variables --------------------------------------------------------- */ -static TIMER_Handle g_timer1; /**< Timer handle */ - -static void TIMER1_Init(void); -void MKey0Func(void); -void MKey1Func(void); - -/** - * @brief Timer initialization function, it is automatically generated by the code generation tool. - */ -static void TIMER1_Init(void) -{ - g_timer1.baseAddress = TIMER1; - g_timer1.load = 1; /* Set timer value immediately */ - g_timer1.bgLoad = 1; - g_timer1.mode = TIMER_MODE_RUN_PERIODIC; /* Run in period mode */ - g_timer1.prescaler = 0; /* don't frequency division */ - g_timer1.interruptEn = 1; /* trigger interrupt enable */ - g_timer1.size = 1; /* 1 for 32bit, 0 for 16bit */ - g_timer1.irqNum = IRQ_TIMER1; - IRQ_SetPriority(g_timer1.irqNum, 1); /* set timer0 interrupt priority to 1, 1~7 */ - IRQ_EnableN(g_timer1.irqNum); /* timer interrupt enable */ - HAL_TIMER_Init(&g_timer1); -} - -/** - * @brief Key 0 binding function. - */ -void MKey0Func() -{ - DBG_PRINTF("key0 press\r\n"); -} - -/** - * @brief Key 1 binding function. - */ -void MKey1Func() -{ - DBG_PRINTF("key1 press\r\n"); -} - -/** - * @brief Matrix keys sample. - * @return int Execution result. - */ -int BOARD_MATRIXKEY_Sample(void) -{ - DBG_UartPrintInit(BOARD_MATRIXKEY_SAMPLE_BAUDRATE); - DBG_PRINTF("get in main! \r\n"); - IRQ_Enable(); - IRQ_Init(); - TIMER1_Init(); - - BOARD_MKEY_Init(&g_timer1, 100); /* 100 : 100ms. */ - - BOARD_MKEY_ConfigOutputPin(GPIO1, GPIO_PIN_0, 0); /* 0 : index value. */ - BOARD_MKEY_ConfigOutputPin(GPIO1, GPIO_PIN_1, 1); /* 1 : index value. */ - BOARD_MKEY_ConfigOutputPin(GPIO1, GPIO_PIN_2, 2); /* 2 : index value. */ - BOARD_MKEY_ConfigOutputPin(GPIO1, GPIO_PIN_3, 3); /* 3 : index value. */ - - BOARD_MKEY_ConfigInputPin(GPIO3, GPIO_PIN_0, 0); /* 0 : index value. */ - BOARD_MKEY_ConfigInputPin(GPIO3, GPIO_PIN_1, 1); /* 1 : index value. */ - BOARD_MKEY_ConfigInputPin(GPIO0, GPIO_PIN_2, 2); /* 2 : index value. */ - BOARD_MKEY_ConfigInputPin(GPIO0, GPIO_PIN_3, 3); /* 3 : index value. */ - - BOARD_MKEY_RegisterKeyFun(0, MKey0Func); - BOARD_MKEY_RegisterKeyFun(1, MKey1Func); - - HAL_TIMER_Start(&g_timer1); - while (1) { -#if (BOARD_MKEY_SCHEME_NUMBER == BOARD_MKEY_SCHEME_NUMBER_TWO) - BOARD_MKEY_SCAN_KEY(); -#endif - } - - return 0; -} \ No newline at end of file diff --git a/application/board_sample/key/matrixkey_sample.h b/application/board_sample/key/matrixkey_sample.h deleted file mode 100644 index b91edaed2096add392faaae306b5a5c7a807bdbe..0000000000000000000000000000000000000000 --- a/application/board_sample/key/matrixkey_sample.h +++ /dev/null @@ -1,34 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file matrixkey_sample.h - * @author MCU Application Team - * @brief Include the header file of the matrixkey_sample.c file. - */ - -/* Define to prevent recursive inclusion ------------------------------------- */ -#ifndef McuMagicTag_MATRIXKEY_SAMPLE_H -#define McuMagicTag_MATRIXKEY_SAMPLE_H - -/* Includes ------------------------------------------------------------------ */ -#include "matrixkey.h" -#include "debug.h" - -/* Exported global functions ------------------------------------------------- */ -int BOARD_MATRIXKEY_Sample(void); - -#endif /* McuMagicTag_MATRIXKEY_SAMPLE_H */ \ No newline at end of file diff --git a/application/board_sample/led/led_sample.c b/application/board_sample/led/led_sample.c deleted file mode 100644 index 48bd9db762e7e66168268ac5087c2d983f20382a..0000000000000000000000000000000000000000 --- a/application/board_sample/led/led_sample.c +++ /dev/null @@ -1,85 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file led_sample.c - * @author MCU Application Team - * @brief Led sample code - * @details This file provides firmware functions to manage the following - * functionalities of the common function sample. - * + Led sample functions - */ - -/* Includes ------------------------------------------------------------------ */ -#include "led_sample.h" - -/* Private macro ------------------------------------------------------------- */ -#define BOARD_LED_SAMPLE_BAUDRATE 115200 - -/* Private variables --------------------------------------------------------- */ -static TIMER_Handle g_timer1; /**< Timer handle */ - -static void TIMER1_Init(void); - -/** - * @brief Timer initialization function, it is automatically generated by the code generation tool. - */ -static void TIMER1_Init(void) -{ - g_timer1.baseAddress = TIMER1; - g_timer1.load = 1; /* Set timer value immediately */ - g_timer1.bgLoad = 1; - g_timer1.mode = TIMER_MODE_RUN_PERIODIC; /* Run in period mode */ - g_timer1.prescaler = 0; /* don't frequency division */ - g_timer1.interruptEn = 1; /* trigger interrupt enable */ - g_timer1.size = 1; /* 1 for 32bit, 0 for 16bit */ - g_timer1.irqNum = IRQ_TIMER1; - IRQ_SetPriority(g_timer1.irqNum, 1); /* set timer0 interrupt priority to 1, 1~7 */ - IRQ_EnableN(g_timer1.irqNum); /* timer interrupt enable */ - HAL_TIMER_Init(&g_timer1); -} - -/** - * @brief LED digit tube display example. - * @return int Execution result. - */ -int BOARD_LED_Sample(void) -{ - DBG_UartPrintInit(BOARD_LED_SAMPLE_BAUDRATE); - IRQ_Enable(); - IRQ_Init(); - TIMER1_Init(); - - BOARD_LED_PinConfig(GPIO0, GPIO_PIN_0, 0); /* 0 : index value. */ - BOARD_LED_PinConfig(GPIO1, GPIO_PIN_1, 1); /* 1 : index value. */ - BOARD_LED_PinConfig(GPIO2, GPIO_PIN_2, 2); /* 2 : index value. */ - BOARD_LED_PinConfig(GPIO3, GPIO_PIN_3, 3); /* 3 : index value. */ - BOARD_LED_PinConfig(GPIO4, GPIO_PIN_4, 4); /* 4 : index value. */ - BOARD_LED_PinConfig(GPIO5, GPIO_PIN_5, 5); /* 5 : index value. */ - BOARD_LED_PinConfig(GPIO6, GPIO_PIN_6, 6); /* 6 : index value. */ - BOARD_LED_PinConfig(GPIO7, GPIO_PIN_7, 7); /* 7 : index value. */ - - BOARD_LED_SegmentConfig(GPIO2, GPIO_PIN_4, 0); /* 0 : index value. */ - BOARD_LED_SegmentConfig(GPIO4, GPIO_PIN_3, 1); /* 1 : index value. */ - BOARD_LED_SegmentConfig(GPIO5, GPIO_PIN_3, 2); /* 2 : index value. */ - BOARD_LED_SegmentConfig(GPIO7, GPIO_PIN_3, 3); /* 3 : index value. */ - BOARD_LED_PolarityConfig(BOARD_LED_CATHODE); - - BOARD_LED_ShowString("1111", 3000, &g_timer1); /* 3000 : 3000ms. */ - while (1) { - } - return 0; -} \ No newline at end of file diff --git a/application/board_sample/led/led_sample.h b/application/board_sample/led/led_sample.h deleted file mode 100644 index d804421a1d49863e2abdc0722b6b5c7805aff8c7..0000000000000000000000000000000000000000 --- a/application/board_sample/led/led_sample.h +++ /dev/null @@ -1,34 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file led_sample.h - * @author MCU Application Team - * @brief Include the header file of the led_sample.c file. - */ - -/* Define to prevent recursive inclusion ------------------------------------- */ -#ifndef McuMagicTag_LED_SAMPLE_H -#define McuMagicTag_LED_SAMPLE_H - -/* Includes ------------------------------------------------------------------ */ -#include "led.h" -#include "debug.h" - -/* Exported global functions ------------------------------------------------- */ -int BOARD_LED_Sample(void); - -#endif /* McuMagicTag_LED_SAMPLE_H */ \ No newline at end of file diff --git a/application/board_sample/pulses/pulses_sample.c b/application/board_sample/pulses/pulses_sample.c deleted file mode 100644 index bc3beaebc088af1bf87b14f6428ced6fe6f56c3f..0000000000000000000000000000000000000000 --- a/application/board_sample/pulses/pulses_sample.c +++ /dev/null @@ -1,80 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file pulses_sample.c - * @author MCU Application Team - * @brief Pulses sample code - * @details This file provides firmware functions to manage the following - * functionalities of the common function sample. - * + Pulses sample functions - */ - -/* Includes ------------------------------------------------------------------ */ -#include "pulses_sample.h" - -/* Private macro ------------------------------------------------------------- */ -#define BOARD_PULSES_SAMPLE_BAUDRATE 115200 - -/* Private variables --------------------------------------------------------- */ -static TIMER_Handle g_timer1; /**< Timer handle */ - -static void TIMER1_Init(void); - -/** - * @brief Timer initialization function, it is automatically generated by the code generation tool. - */ -static void TIMER1_Init(void) -{ - g_timer1.baseAddress = TIMER1; - g_timer1.load = 1; /* Set timer value immediately */ - g_timer1.bgLoad = 1; - g_timer1.mode = TIMER_MODE_RUN_ONTSHOT; /* Run in period mode */ - g_timer1.prescaler = 0; /* don't frequency division */ - g_timer1.interruptEn = 1; /* trigger interrupt enable */ - g_timer1.size = 1; /* 1 for 32bit, 0 for 16bit */ - g_timer1.irqNum = IRQ_TIMER1; - IRQ_SetPriority(g_timer1.irqNum, 1); /* set timer0 interrupt priority to 1, 1~7 */ - IRQ_EnableN(g_timer1.irqNum); /* timer interrupt enable */ - HAL_TIMER_Init(&g_timer1); -} - -/** - * @brief Pulse generation example. - * @return int Execution result. - */ -int BOARD_PULSES_Sample(void) -{ - DBG_UartPrintInit(BOARD_PULSES_SAMPLE_BAUDRATE); - DBG_PRINTF("get in main! \r\n"); - IRQ_Enable(); - IRQ_Init(); - TIMER1_Init(); - - BOARD_PULSES_Init(GPIO0, GPIO_PIN_0, &g_timer1, 1, 0.8, 1); /* 0.8 : dutu cycle. */ - - BOARD_PULSES_Start(1); - BASE_FUNC_DELAY_S(5); /* 5 : 5 second. */ - BOARD_PULSES_Stop(1); - BASE_FUNC_DELAY_S(5); /* 5 : 5 second. */ - BOARD_PULSES_Start(1); - BASE_FUNC_DELAY_S(5); /* 5 : 5 second. */ - BOARD_PULSES_Stop(1); - while (1) { - } - - return 0; -} \ No newline at end of file diff --git a/application/board_sample/pulses/pulses_sample.h b/application/board_sample/pulses/pulses_sample.h deleted file mode 100644 index 0d553af605e0edf5f6637e91ce8c127fc96e3c8c..0000000000000000000000000000000000000000 --- a/application/board_sample/pulses/pulses_sample.h +++ /dev/null @@ -1,34 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file pulses_sample.h - * @author MCU Application Team - * @brief Include the header file of the pulses_sample.c file. - */ - -/* Define to prevent recursive inclusion ------------------------------------- */ -#ifndef McuMagicTag_PULSES_SAMPLE_H -#define McuMagicTag_PULSES_SAMPLE_H - -/* Includes ------------------------------------------------------------------ */ -#include "pulses.h" -#include "debug.h" - -/* Exported global functions ------------------------------------------------- */ -int BOARD_PULSES_Sample(void); - -#endif /* McuMagicTag_PULSES_SAMPLE_H */ \ No newline at end of file diff --git a/application/board_sample/softserial/softserial_sample.c b/application/board_sample/softserial/softserial_sample.c deleted file mode 100644 index 291797ea23c96a4e981068214e787d872d720aec..0000000000000000000000000000000000000000 --- a/application/board_sample/softserial/softserial_sample.c +++ /dev/null @@ -1,132 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file softserial_sample.c - * @author MCU Application Team - * @brief Softserial sample code - * @details This file provides firmware functions to manage the following - * functionalities of the common function sample. - * + Softserial sample functions. - */ - -/* Includes ------------------------------------------------------------------ */ -#include "softserial_sample.h" - -/* Private macro ------------------------------------------------------------- */ -#define BOARD_SOFTSERIAL_SAMPLE_BAUDRATE 1200 -#define BOARD_SOFTSERIAL_SAMPLE_DATALENGTH 8 - -/* Private variables --------------------------------------------------------- */ -static TIMER_Handle g_timer1; -static TIMER_Handle g_timer2; -static GPIO_Handle g_gpio0; -static GPIO_Handle g_gpio1; - -static void TIMER1_Init(void); -static void TIMER2_Init(void); -static void GPIO0_Init(void); -static void GPIO1_Init(void); - -/** - * @brief Timer initialization function, it is automatically generated by the code generation tool. - */ -static void TIMER1_Init(void) -{ - g_timer1.baseAddress = TIMER1; - g_timer1.load = 1; /* Set timer value immediately */ - g_timer1.bgLoad = 1; - g_timer1.mode = TIMER_MODE_RUN_PERIODIC; /* Run in period mode */ - g_timer1.prescaler = 0; /* don't frequency division */ - g_timer1.interruptEn = 1; /* trigger interrupt enable */ - g_timer1.size = 1; /* 1 for 32bit, 0 for 16bit */ - g_timer1.irqNum = IRQ_TIMER1; - IRQ_SetPriority(g_timer1.irqNum, 1); /* set timer0 interrupt priority to 1, 1~7 */ - IRQ_EnableN(g_timer1.irqNum); /* timer interrupt enable */ - HAL_TIMER_Init(&g_timer1); -} - -/** - * @brief Timer initialization function, it is automatically generated by the code generation tool. - */ -static void TIMER2_Init(void) -{ - g_timer2.baseAddress = TIMER2; - g_timer2.load = 1; /* Set timer value immediately */ - g_timer2.bgLoad = 1; - g_timer2.mode = TIMER_MODE_RUN_PERIODIC; /* Run in period mode */ - g_timer2.prescaler = 0; /* don't frequency division */ - g_timer2.interruptEn = 1; /* trigger interrupt enable */ - g_timer2.size = 1; /* 1 for 32bit, 0 for 16bit */ - g_timer2.irqNum = IRQ_TIMER2; - IRQ_SetPriority(g_timer2.irqNum, 1); /* set timer0 interrupt priority to 1, 1~7 */ - IRQ_EnableN(g_timer2.irqNum); /* timer interrupt enable */ - HAL_TIMER_Init(&g_timer2); -} - -/** - * @brief GPIO initialization function, it is automatically generated by the code generation tool. - */ -static void GPIO0_Init(void) -{ - g_gpio0.baseAddress = GPIO0; - g_gpio0.dir = GPIO_OUTPUT_MODE; - g_gpio0.value = GPIO_HIGH_LEVEL; - g_gpio0.interruptMode = GPIO_INT_TYPE_NONE; - g_gpio0.pins = GPIO_PIN_0; - HAL_GPIO_Init(&g_gpio0); -} - -/** - * @brief GPIO initialization function, it is automatically generated by the code generation tool. - */ -static void GPIO1_Init(void) -{ - g_gpio1.baseAddress = GPIO3; - g_gpio1.dir = GPIO_OUTPUT_MODE; - g_gpio1.value = GPIO_HIGH_LEVEL; - g_gpio1.interruptMode = GPIO_INT_TYPE_NONE; - g_gpio1.pins = GPIO_PIN_0; - HAL_GPIO_Init(&g_gpio1); -} - -/** - * @brief Soft serial port loopback example. - * @return int Execution result. - */ -int BOARD_SOFTSERIAL_Sample(void) -{ - IRQ_Enable(); - IRQ_Init(); - - TIMER1_Init(); - GPIO0_Init(); - TIMER2_Init(); - GPIO1_Init(); - - BOARD_SOFTSERIAL_TxInit(&g_gpio0, &g_timer1, BOARD_SOFTSERIAL_SAMPLE_BAUDRATE, BOARD_SOFTSERIAL_SAMPLE_DATALENGTH, - BOARD_SOFTSERIAL_PARITY_NONE, BOARD_SOFTSERIAL_STOPBITS_ONE); - BOARD_SOFTSERIAL_RxInit(&g_gpio1, &g_timer2, BOARD_SOFTSERIAL_SAMPLE_BAUDRATE, BOARD_SOFTSERIAL_SAMPLE_DATALENGTH, - BOARD_SOFTSERIAL_PARITY_NONE, BOARD_SOFTSERIAL_STOPBITS_ONE); - - unsigned char tmp; - while (1) { - if (BOARD_SOFTSERIAL_GetChar(&tmp) == BOARD_SOFTSERIAL_OK) { - BOARD_SOFTSERIAL_PrintCh(tmp); - } - } - return BASE_STATUS_OK; -} \ No newline at end of file diff --git a/application/board_sample/softserial/softserial_sample.h b/application/board_sample/softserial/softserial_sample.h deleted file mode 100644 index bc318d6dbb88dae54d7b4528fe1021992c64e396..0000000000000000000000000000000000000000 --- a/application/board_sample/softserial/softserial_sample.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file softserial_sample.h - * @author MCU Application Team - * @brief Include the header file of the softserial_sample.c file. - */ - -/* Define to prevent recursive inclusion ------------------------------------- */ -#ifndef McuMagicTag_SOFTSERIAL_SAMPLE_H -#define McuMagicTag_SOFTSERIAL_SAMPLE_H - -/* Includes ------------------------------------------------------------------ */ -#include "baseinc.h" -#include "debug.h" -#include "timer.h" -#include "gpio.h" -#include "softserial.h" - -/* Exported global functions ------------------------------------------------- */ -int BOARD_SOFTSERIAL_Sample(void); - -#endif /* McuMagicTag_SOFTSERIAL_SAMPLE_H */ \ No newline at end of file diff --git a/application/drivers_sample/capm/capm_hall_sample/readme.rd b/application/drivers_sample/capm/capm_hall_sample/readme.rd deleted file mode 100644 index 063867325627f281d23fb038e87fec2fc27c560d..0000000000000000000000000000000000000000 --- a/application/drivers_sample/capm/capm_hall_sample/readme.rd +++ /dev/null @@ -1,18 +0,0 @@ -# CAPM读取电机HALL位置传感器 -## 关键字: CAPM, HALL传感器 - -**【功能描述】** -+ 使用三个CAPM捕获三个HALL传感器的电平信息 - -**【示例配置】** -+ 捕获模式:可通过“g_capmAConfig.capMode”进行配置,默认为连续捕获CAPM_CONTINUECAP - -+ 预分频:对CAPM输入信号进行预分频,可通过”g_capmAConfig.preScale“进行配置,默认为不分频 - -+ 捕获寄存器配置:可通过”g_capmAConfig.capRegConfig“进行配置,默认为上升沿捕获,每次复位 - -**【示例效果】** -+ 在IOCMG_15、IOCMG_18和IOCMG_19输入HALL传感器的输入信号。在串口打印的数据中的每一位表示当前时刻的对应的HALL传感器的电平状态。 - -**【注意事项】** -+ 需要转动电机才能进行CAPM捕获霍尔传感器信号 diff --git a/application/drivers_sample/cfd/sample_cfd_check_error/readme.rd b/application/drivers_sample/cfd/sample_cfd_check_error/readme.rd deleted file mode 100644 index 80ba155fa21ef614371697bef72e2167cd44822a..0000000000000000000000000000000000000000 --- a/application/drivers_sample/cfd/sample_cfd_check_error/readme.rd +++ /dev/null @@ -1,21 +0,0 @@ -# 验证CFD的时钟失效保护功能 -## 关键字: CFD, 时钟失效, 中断 - -**【功能描述】** -+ 监测目标时钟(HOSC或TCXO)是否失效,每隔5s分别注入时钟失效中断和解除时钟失效中断,用于验证CFD的时钟失效保护功能。 - -**【示例配置】** -+ CFD参考时钟源:参考时钟源固定为内部低速时钟CLK_LOSC,默认为不分频。 - -+ CFD目标时钟源:目标时钟源固定为HOSC或TCXO,分频比固定为2048。 - -+ CFD上限值: 上限值可通过“g_cfd.upperBound”配置。 - -+ CFD中断类型:中断类型可通过“g_cfd.interruptType”进行配置,默认为时钟失效中断。 - -**【示例效果】** -+ Debug串口首先每隔1s打印出监测目标时钟频率的CFDCNTLOCK锁存值,在注入时钟失效中断后每隔1s分别打印时钟失效回调函数中的log, 5s后解除时钟失效中断后再每隔1s打印CFDCNTLOCK锁存值,循环往复。 - -**【注意事项】** -+ 时钟失效中断触发硬件系统事件2会自动关闭APT并将主时钟切换为LOSC进行保护,用户可在中断服务函数中进行时钟恢复或者复位等安全操作; -+ 每次中断触发后自行判断计数值是否在门限内,非门限内则判定为异常时钟;该模块目标时钟分配比固化为2048分频,参考时钟不分频。 diff --git a/application/drivers_sample/cmm/sample_cmm_check_error/readme.rd b/application/drivers_sample/cmm/sample_cmm_check_error/readme.rd deleted file mode 100644 index 1d4198cfdcd4d178e1aa502a4daf954144ee86f9..0000000000000000000000000000000000000000 --- a/application/drivers_sample/cmm/sample_cmm_check_error/readme.rd +++ /dev/null @@ -1,20 +0,0 @@ -# 验证CMM时钟频率监测功能,同时验证CMM频率错误中断功能 -## 关键字: CMM, 时钟频率监测, 中断 - -**【功能描述】** -+ 用于检查目标时钟(LOSC/HOSC/TCXO/HS_CLK/LS_CLK)频率是否发生错误。每隔5s分别注入频率错误中断,用于验证CMM的频率中断处理函数。 - -**【示例配置】** -+ CMM参考时钟源:参考时钟源可通过“g_cmm.refClockSource”配置,默认为内部低速时钟CMM_REF_CLK_LOSC,分频比可通过“g_cmm.refFreqDivision”配置,默认为不分频CMM_REF_FREQ_DIV_0。 - -+ CMM目标时钟源:目标时钟源可通过“g_cmm.targetClockSource”配置,默认为内部低速时钟CMM_TARGET_CLK_LOSC,分频比可通过“g_cmm.targetFreqDivision”配置,默认为8192分频CMM_TARGET_FREQ_DIV_8192。 - -+ CMM上下限值: 上限值可通过“g_cmm.upperBound”配置,下限值可通过“g_cmm.lowerBound”配置。 - -+ CMM中断类型:中断类型可通过“g_cmm.interruptType”进行配置,默认为频率错误中断。 - -**【示例效果】** -+ Debug串口首先每隔1s打印出监测目标时钟频率的CMCNTLOCK锁存值,在注入频率错误中断后每隔1s分别打印频率错误回调函数中的log, 5s后解除频率错误中断后再每隔1s打印CMCNTLOCK锁存值,循环往复。 - -**【注意事项】** -+ 上下限值的范围可反应系统对目标时钟偏差的冗余度,可自行设计门限值和时钟分频比,门限值具体计算方法请参照芯片技术指南。 diff --git a/application/drivers_sample/iocmg/iolist_sample/readme.rd b/application/drivers_sample/iocmg/iolist_sample/readme.rd deleted file mode 100644 index 1793dd8bb0bdc426cbdbba46c2e1777b0282c85a..0000000000000000000000000000000000000000 --- a/application/drivers_sample/iocmg/iolist_sample/readme.rd +++ /dev/null @@ -1,14 +0,0 @@ -# 使用HAL_IOCMG_Init API完成IO端口的相关功能配置 -## 关键字: IOCMG,iomap映射 - -**【功能描述】** -+ 通过HAL_IOCMG_Init API初始化iolist配置表格。 - -**【示例配置】** -+ g_ioListTable数组的初始化:该数组中的每个元素值表示一个IO端口的结构体IOCMG_Handle,而每个结构体表示某一个IO端口的所有配置信息(包括端口映射地址值pinTypedef,上下拉pullMode,施密特状态schmidtMode、管脚驱动能力levelShiftRate、电平转换速率driveRate) - -**【示例效果】** -+ Debug串口打印配置前的iolist数据,然后打印初始化后的寄存器中的数据,判断配置的数据和预期的是否相同,同时调用HAL_IOCMG_SetXXX API接口和HAL_IOCMG_GetXXX API分别配置和获取IOCMG寄存器的数据是否符合预期。 - -**【注意事项】** -+ PIN NUMBER和function mode均已编码定义,在iomap中,若配置数据与定义的数据不符则配置失败返回对应的错误,已定义的pin number和function mode可在iomap.h中直接调用。 \ No newline at end of file diff --git a/application/drivers_sample/qdm/sample_qdm_m/readme.rd b/application/drivers_sample/qdm/sample_qdm_m/readme.rd deleted file mode 100644 index b96149081654ac69c03c962aedcbc01338f4e3b3..0000000000000000000000000000000000000000 --- a/application/drivers_sample/qdm/sample_qdm_m/readme.rd +++ /dev/null @@ -1,24 +0,0 @@ -# M法测量电机实时转速 -## 关键字: QDM, 电机,M法 - -**【功能描述】** -+ 通过获取电机编码器QDM的相关信息,使用M法进行计算电机实时转速 - -**【示例配置】** -+ QDM控制配置:输入模式inputMode,极性选择polarity,正交分解resolution、触发锁存模式trgLockMode,A/B相互换swap,PTU单元周期模式ptuMode - -+ 输入滤波配置:可通过“g_qdmHandle.inputFilter”对A/B/Z相滤波等级进行配置,默认均为0 - -+ PPU电机位置处理单元配置:位置计数模式pcntMode,位置计数复位模式pcntRstMode,位置计数初始化模式pcntIdxInitMode,位置计数器最大值posMax,位置计数初始化值posInit - -+ TSU时间戳单元配置:TSU计数器最大值qcMax,TSU预分频tsuPrescaler - -+ PTU周期触发单元配置:PTU周期大小period - -+ 其他配置:捕获事件预分频cevtPrescaler,编码器线数motorLineNum,中断使能interruptEn,子模块使能subModeEn - -**【示例效果】** -+ 串口打印出电机实时的转速值大小 - -**【注意事项】** -+ 需要转动电机才能进行测量实时转速 diff --git a/application/drivers_sample/qdm/sample_qdm_mt/readme.rd b/application/drivers_sample/qdm/sample_qdm_mt/readme.rd deleted file mode 100644 index 5bfb9f9bc428ce06151ea21cab5c5086480d65c4..0000000000000000000000000000000000000000 --- a/application/drivers_sample/qdm/sample_qdm_mt/readme.rd +++ /dev/null @@ -1,24 +0,0 @@ -# MT法测量电机实时转速 -## 关键字: QDM, 电机,MT法 - -**【功能描述】** -+ 通过获取电机编码器QDM的相关信息,使用MT法进行计算电机实时转速 - -**【示例配置】** -+ QDM控制配置:输入模式inputMode,极性选择polarity,正交分解resolution、触发锁存模式trgLockMode,A/B相互换swap,PTU单元周期模式ptuMode - -+ 输入滤波配置:可通过“g_qdmHandle.inputFilter”对A/B/Z相滤波等级进行配置,默认均为0 - -+ PPU电机位置处理单元配置:位置计数模式pcntMode,位置计数复位模式pcntRstMode,位置计数初始化模式pcntIdxInitMode,位置计数器最大值posMax,位置计数初始化值posInit - -+ TSU时间戳单元配置:TSU计数器最大值qcMax,TSU预分频tsuPrescaler - -+ PTU周期触发单元配置:PTU周期大小period - -+ 其他配置:捕获事件预分频cevtPrescaler,编码器线数motorLineNum,中断使能interruptEn,子模块使能subModeEn - -**【示例效果】** -+ 串口打印出电机实时的转速值大小 - -**【注意事项】** -+ 需要转动电机才能进行测量实时转速 diff --git a/application/middleware_sample/mcs_65demo/common/inc/mcs_carrier_process.h b/application/middleware_sample/mcs_65demo/common/inc/mcs_carrier_process.h deleted file mode 100644 index 4f4b9f9ba4d9e979dabce6f7051d9e6203e0ba58..0000000000000000000000000000000000000000 --- a/application/middleware_sample/mcs_65demo/common/inc/mcs_carrier_process.h +++ /dev/null @@ -1,96 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_carrier_process.h - * @author MCU Algorithm Team - * @brief This file provides functions declaration for carrier interrupt processing function. - */ -#ifndef McuMagicTag_MCS_CARRIER_PROCESS_H -#define McuMagicTag_MCS_CARRIER_PROCESS_H - -#include "mcs_sys_status.h" -#include "mcs_mtr_param.h" -#include "mcs_fsm.h" -#include "mcs_svpwm.h" -#include "mcs_curr_ctrl.h" -#include "mcs_if_ctrl.h" -#include "mcs_ramp_mgmt.h" -#include "mcs_spd_ctrl.h" -#include "mcs_fosmo.h" -#include "mcs_pll.h" -#include "mcs_startup.h" -#include "mcs_r1_svpwm.h" - -typedef void (*MCS_ReadCurrUvwCb)(UvwAxis *CurrUvw); -typedef void (*MCS_SetPwmDutyCb)(UvwAxis *dutyUvwLeft, UvwAxis *dutyUvwRight); -typedef void (*MCS_SetADCTriggerTimeCb)(unsigned short cntCmpSOCA, unsigned short cntCmpSOCB); - -/** - * @brief Sampling mode. - */ -typedef enum { - THREE_RESISTORS = 0, - SINGLE_RESISTOR = 1 -} SampleMode; - -/** - * @brief Motor control data structure - */ -typedef struct { - float spdCmdHz; /**< External input speed command value */ - short axisAngle; /**< Angle of the synchronous coordinate system, used for coordinate transformation */ - float spdRefHz; /**< Command value after speed ramp management */ - float currCtrlPeriod; /**< current loop control period */ - unsigned short aptMaxcntCmp; /**< Apt Maximum Comparison Count */ - - unsigned short sysTickCnt; /**< System Timer Tick Count */ - unsigned short capChargeTickNum; /**< Bootstrap Capacitor Charge Tick Count */ - volatile unsigned int msTickCnt; /**< Millisecond-level counter, which can be used in 1-ms and 5-ms tasks. */ - unsigned short msTickNum; /**< Number of ticks corresponding to 1 ms */ - - SysStatusReg statusReg; /**< System status */ - volatile FsmState stateMachine; /**< Motor Control State Machine */ - - SampleMode sampleMode; /**< sample mode */ - MtrParamHandle mtrParam; /**< Motor parameters */ - FoSmoHandle smo; /**< SMO observer handle */ - IfHandle ifCtrl; /**< I/F control handle */ - SvpwmHandle sv; /**< SVPWM Handle */ - R1SvpwmHandle r1Sv; /**< Single-resistance phase-shifted SVPWM handld */ - RmgHandle spdRmg; /**< Ramp management struct for the speed controller input reference */ - SpdCtrlHandle spdCtrl; /**< Speed loop Control Handle */ - CurrCtrlHandle currCtrl; /**< Current loop control handle */ - StartupHandle startup; /**< Startup Switch Handle */ - - DqAxis currRefDq; /**< Command value of the dq axis current */ - UvwAxis currUvw; /**< Three-phase current sampling value */ - AlbeAxis currAlbe; /**< αβ-axis current feedback value */ - DqAxis currDq; /**< Current feedback value of the dq axis */ - DqAxis vdq; /**< Current loop output dq voltage */ - AlbeAxis vab; /**< Current loop output voltage αβ */ - UvwAxis dutyUvw; /**< UVW three-phase duty cycle */ - UvwAxis dutyUvwLeft; /**< Single Resistor UVW Three-Phase Left Duty Cycle */ - UvwAxis dutyUvwRight; /**< Single Resistor UVW Three-Phase Right Duty Cycle*/ - - MCS_ReadCurrUvwCb readCurrUvwCb; /**< Read current callback function */ - MCS_SetPwmDutyCb setPwmDutyCb; /**< Set the duty cycle callback function. */ - MCS_SetADCTriggerTimeCb setADCTriggerTimeCb; /**< Sets the ADC trigger point callback function. */ -} MtrCtrlHandle; - -void MCS_CarrierProcess(MtrCtrlHandle *mtrCtrl); - -#endif \ No newline at end of file diff --git a/application/middleware_sample/mcs_65demo/common/inc/mcs_config_motor.h b/application/middleware_sample/mcs_65demo/common/inc/mcs_config_motor.h deleted file mode 100644 index a3de7f98a2454841bf08fd1b3860ca5ad511b1dd..0000000000000000000000000000000000000000 --- a/application/middleware_sample/mcs_65demo/common/inc/mcs_config_motor.h +++ /dev/null @@ -1,55 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_config_motor.h - * @author MCU Algorithm Team - * @brief This file provides the electromechanical parameters of the tested motor. - */ - -#ifndef McuMagicTag_MCS_CONFIG_MOTOR_H -#define McuMagicTag_MCS_CONFIG_MOTOR_H - -#include "mcs_mtr_param.h" - -/* Typedef definitions ------------------------------------------------------------------------- */ -typedef struct { - /* electromechanical parameters */ - unsigned int mtrNp; /**< numbers of pole pairs */ - float mtrRs; /**< resistor of stator */ - float mtrLd; /**< inductance of D-axis */ - float mtrLq; /**< inductance of Q-axis */ - float mtrPsif; /**< permanent magnet flux */ - float mtrJ; /**< rotor inertia */ - float maxElecSpd; /**< max elec speed */ - float maxCurr; /**< max current */ - /* Encoder parameters */ - unsigned int mtrPPMR; /**< pulse per mechanical round */ - unsigned int zShift; /**< pulse Z shift */ -} MotorConfig; - -typedef struct { - float currPiKp; /**< current loop kp */ - float currPiKi; /**< current loop ki */ - float currPiLimitPu; /**< current loop limit per unit value */ - float spdPiKp; /**< speed loop kp */ - float spdPiKi; /**< speed loop ki */ - float spdPiLimit; /**< speed loop limit */ -} PiCtrlParam; - -void MtrParamInit(MtrParamHandle *handle, const MotorConfig *motorTable); - -#endif diff --git a/application/middleware_sample/mcs_65demo/common/inc/mcs_sys_status.h b/application/middleware_sample/mcs_65demo/common/inc/mcs_sys_status.h deleted file mode 100644 index 5503700df6e596184b9077b8a8cf28b4971010bb..0000000000000000000000000000000000000000 --- a/application/middleware_sample/mcs_65demo/common/inc/mcs_sys_status.h +++ /dev/null @@ -1,188 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_sys_status.h - * @author MCU Algorithm Team - * @brief This file provides functions declaration of system status. - */ - -/* Define to prevent recursive inclusion ------------------------------------------------------- */ -#ifndef McuMagicTag_MCS_SYS_STATUS_H -#define McuMagicTag_MCS_SYS_STATUS_H - -/* Includes ------------------------------------------------------------------------------------ */ -#include "typedefs.h" -#include "mcs_assert.h" - -/* Typedef definitions ------------------------------------------------------------------------- */ -/** - * @brief System status define - */ -typedef union { - unsigned short all; - struct { - unsigned short cmdStart : 1; /**< Indicates that a start system command has been received. */ - unsigned short cmdStop : 1; /**< Indicates that a stop system command has been received. */ - unsigned short isRunning : 1; /**< Indicates that the system is running (enable signal) */ - unsigned short sysError : 1; /**< Indicates that the system reports an error. */ - unsigned short poweron : 1; /**< Indicates that the power-on initialization phase is complete. */ - unsigned short capcharge : 1; /**< Indicates that the bootstrap capacitor charging phase is complete. */ - unsigned short adczero : 1; /**< The current sampling point is reset to zero after power-on. */ - } Bit; -} SysStatusReg; - -/** - * @brief Get status of Bit cmdStart. - * @param sysStatus System status register handle. - * @retval Status of Bit cmdStart. - */ -static inline bool SysGetCmdStart(SysStatusReg *sysStatus) -{ - MCS_ASSERT_PARAM(sysStatus != NULL); - bool ret; - ret = (sysStatus->Bit.cmdStart == 1) ? true : false; - return ret; -} - -/** - * @brief Set Bit cmdStart. - * @param sysStatus System status register handle. - * @retval None. - */ -static inline void SysCmdStartSet(SysStatusReg *sysStatus) -{ - MCS_ASSERT_PARAM(sysStatus != NULL); - sysStatus->Bit.cmdStart = 1; -} - -/** - * @brief Clear Bit cmdStart. - * @param handle System status register handle. - * @retval None. - */ -static inline void SysCmdStartClr(SysStatusReg *sysStatus) -{ - MCS_ASSERT_PARAM(sysStatus != NULL); - sysStatus->Bit.cmdStart = 0; -} - -/** - * @brief Get status of Bit cmdStop. - * @param sysStatus System status register handle. - * @retval Status of Bit cmdStart. - */ -static inline bool SysGetCmdStop(SysStatusReg *sysStatus) -{ - MCS_ASSERT_PARAM(sysStatus != NULL); - bool ret; - ret = (sysStatus->Bit.cmdStop == 1) ? true : false; - return ret; -} - -/** - * @brief Set Bit cmdStop. - * @param sysStatus System status register handle. - * @retval None. - */ -static inline void SysCmdStopSet(SysStatusReg *sysStatus) -{ - MCS_ASSERT_PARAM(sysStatus != NULL); - sysStatus->Bit.cmdStop = 1; -} - -/** - * @brief Clear Bit cmdStop. - * @param sysStatus System status register handle. - * @retval None. - */ -static inline void SysCmdStopClr(SysStatusReg *sysStatus) -{ - MCS_ASSERT_PARAM(sysStatus != NULL); - sysStatus->Bit.cmdStop = 0; -} - -/** - * @brief Get status of Bit isRunning. - * @param sysStatus System status register handle. - * @retval Status of Bit isRunning. - */ -static inline bool SysIsRunning(SysStatusReg *sysStatus) -{ - MCS_ASSERT_PARAM(sysStatus != NULL); - bool ret; - ret = (sysStatus->Bit.isRunning == 1) ? true : false; - return ret; -} - -/** - * @brief Set Bit isRuning. - * @param sysStatus System status register handle. - * @retval None. - */ -static inline void SysRunningSet(SysStatusReg *sysStatus) -{ - MCS_ASSERT_PARAM(sysStatus != NULL); - sysStatus->Bit.isRunning = 1; -} - -/** - * @brief Clear Bit isRuning. - * @param sysStatus System status register handle. - * @retval None. - */ -static inline void SysRunningClr(SysStatusReg *sysStatus) -{ - MCS_ASSERT_PARAM(sysStatus != NULL); - sysStatus->Bit.isRunning = 0; -} - -/** - * @brief Get status of Bit sysError. - * @param sysStatus System status register handle. - * @retval Status of Bit sysError. - */ -static inline bool SysIsError(SysStatusReg *sysStatus) -{ - MCS_ASSERT_PARAM(sysStatus != NULL); - bool ret; - ret = (sysStatus->Bit.sysError == 1) ? true : false; - return ret; -} - -/** - * @brief Set Bit sysError. - * @param sysStatus System status register handle. - * @retval None. - */ -static inline void SysErrorSet(SysStatusReg *sysStatus) -{ - MCS_ASSERT_PARAM(sysStatus != NULL); - sysStatus->Bit.sysError = 1; -} - -/** - * @brief Clear Bit sysError. - * @param sysStatus System status register handle. - * @retval None. - */ -static inline void SysErrorClr(SysStatusReg *sysStatus) -{ - MCS_ASSERT_PARAM(sysStatus != NULL); - sysStatus->Bit.sysError = 0; -} - -#endif diff --git a/application/middleware_sample/mcs_65demo/common/src/mcs_carrier_process.c b/application/middleware_sample/mcs_65demo/common/src/mcs_carrier_process.c deleted file mode 100644 index be8184a7d29c37c7cd9987f422b61f0b00c32d5f..0000000000000000000000000000000000000000 --- a/application/middleware_sample/mcs_65demo/common/src/mcs_carrier_process.c +++ /dev/null @@ -1,134 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_carrier_process.c - * @author MCU Algorithm Team - * @brief This file provides carrier interrupt application for motor control. - */ - -#include "mcs_carrier_process.h" -#include "mcs_math.h" -#include "typedefs.h" -#include "mcs_assert.h" - -/** - * @brief Synchronous rotation coordinate system angle. - * @param mtrCtrl The motor control handle. - * @retval None. - */ -static void MCS_SyncCoorAngle(MtrCtrlHandle *mtrCtrl) -{ - MCS_ASSERT_PARAM(mtrCtrl != NULL); - /* Synchronous rotation coordinate system angle. */ - switch (mtrCtrl->stateMachine) { - case FSM_STARTUP: - /* Current ramp angle is 0. */ - if (mtrCtrl->startup.stage == STARTUP_STAGE_CURR) { - mtrCtrl->axisAngle = 0; - } else if (mtrCtrl->startup.stage == STARTUP_STAGE_SPD) { /* IF control phase angle self-addition. */ - mtrCtrl->axisAngle = IF_CurrAngleCalc(&mtrCtrl->ifCtrl, mtrCtrl->spdRefHz); - } else if (mtrCtrl->startup.stage == STARTUP_STAGE_SWITCH) { /* Switch Angle */ - mtrCtrl->axisAngle = mtrCtrl->smo.elecAngle; - } - break; - - case FSM_RUN: - mtrCtrl->axisAngle = mtrCtrl->smo.elecAngle; - break; - - default: - mtrCtrl->axisAngle = 0; - break; - } -} - -/** - * @brief PWM waveform setting and sampling point setting for a single resistors and three resistors. - * @param mtrCtrl The motor control handle. - * @retval None. - */ -static void MCS_PwmAdcSet(MtrCtrlHandle *mtrCtrl) -{ - MCS_ASSERT_PARAM(mtrCtrl != NULL); - SampleMode sampleMode = mtrCtrl->sampleMode; - /* Set the duty cycle according to the sampling mode. */ - if (sampleMode == THREE_RESISTORS) { - SVPWM_Exec(&mtrCtrl->sv, &mtrCtrl->vab, &mtrCtrl->dutyUvw); - mtrCtrl->setPwmDutyCb(&mtrCtrl->dutyUvw, &mtrCtrl->dutyUvw); - } else if (sampleMode == SINGLE_RESISTOR) { - R1SVPWM_Exec(&mtrCtrl->r1Sv, &mtrCtrl->vab, &mtrCtrl->dutyUvwLeft, &mtrCtrl->dutyUvwRight); - mtrCtrl->setPwmDutyCb(&mtrCtrl->dutyUvwLeft, &mtrCtrl->dutyUvwRight); - /* The ADC sampling point position needs to be set based on the phase shift of a single resistors. */ - mtrCtrl->setADCTriggerTimeCb(mtrCtrl->r1Sv.samplePoint[0] * mtrCtrl->aptMaxcntCmp, \ - mtrCtrl->r1Sv.samplePoint[1] * mtrCtrl->aptMaxcntCmp); - } -} - -/** - * @brief Carrier interrupt function. - * @param mtrCtrl The motor control handle. - * @retval None. - */ -void MCS_CarrierProcess(MtrCtrlHandle *mtrCtrl) -{ - MCS_ASSERT_PARAM(mtrCtrl != NULL); - UvwAxis *currUvw = &mtrCtrl->currUvw; - AlbeAxis *currAlbe = &mtrCtrl->currAlbe; - AlbeAxis *vab = &mtrCtrl->vab; - SampleMode sampleMode = mtrCtrl->sampleMode; - - if (sampleMode > SINGLE_RESISTOR || mtrCtrl->setADCTriggerTimeCb == NULL) { - return; - } - - if (mtrCtrl->setPwmDutyCb == NULL || mtrCtrl->readCurrUvwCb == NULL) { - return; - } - /* Read the three-phase current value. */ - mtrCtrl->readCurrUvwCb(currUvw); - /* Clark Calc */ - ClarkeCalc(currUvw, currAlbe); - - /* Smo observation */ - FOSMO_Exec(&mtrCtrl->smo, currAlbe, vab, mtrCtrl->spdRefHz); - /* Synchronization angle */ - MCS_SyncCoorAngle(mtrCtrl); - - /* Park transformation */ - ParkCalc(currAlbe, mtrCtrl->axisAngle, &mtrCtrl->currDq); - - /* statemachine */ - switch (mtrCtrl->stateMachine) { - case FSM_STARTUP: - case FSM_RUN: - CURRCTRL_Exec(&mtrCtrl->currCtrl, &mtrCtrl->vdq); - InvParkCalc(&mtrCtrl->vdq, mtrCtrl->axisAngle, vab); - MCS_PwmAdcSet(mtrCtrl); - break; - - case FSM_CAP_CHARGE: - case FSM_CLEAR: - case FSM_IDLE: - break; - - default: - vab->alpha = 0.0f; - vab->beta = 0.0f; - MCS_PwmAdcSet(mtrCtrl); - break; - } -} \ No newline at end of file diff --git a/application/middleware_sample/mcs_65demo/common/src/mcs_config_motor.c b/application/middleware_sample/mcs_65demo/common/src/mcs_config_motor.c deleted file mode 100644 index 504968a3566ec68d8c70c9033cda05d628461121..0000000000000000000000000000000000000000 --- a/application/middleware_sample/mcs_65demo/common/src/mcs_config_motor.c +++ /dev/null @@ -1,48 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_config_motor.c - * @author MCU Algorithm Team - * @brief This file provides the electromechanical parameters of the tested motor. - */ - -#include "mcs_config_motor.h" -#include "mcs_assert.h" - -/** - * @brief Initialzer of motor parameters. - * @param mtrParamHandle Motor parameters handle. - * @param motorTable Motor parameters table handle. - * @retval None. - */ -void MtrParamInit(MtrParamHandle *mtrParamHandle, const MotorConfig *motorTable) -{ - MCS_ASSERT_PARAM(mtrParamHandle != NULL); - MCS_ASSERT_PARAM(motorTable != NULL); - /* Initialzer of motor parameters */ - mtrParamHandle->mtrRs = motorTable->mtrRs; /* resistor of stator */ - mtrParamHandle->mtrLd = motorTable->mtrLd; /* inductance of D-axis */ - mtrParamHandle->mtrLq = motorTable->mtrLq; /* inductance of Q-axis */ - /* Average inductance, mtrLs = (mtrLd + mtrLq) * 0.5f */ - mtrParamHandle->mtrLs = (motorTable->mtrLd + motorTable->mtrLq) * 0.5f; - mtrParamHandle->mtrPsif= motorTable->mtrPsif; /* permanent magnet flux */ - mtrParamHandle->mtrNp = motorTable->mtrNp; /* numbers of pole pairs */ - mtrParamHandle->mtrJ = motorTable->mtrJ; /* rotor inertia */ - mtrParamHandle->maxElecSpd = motorTable->maxElecSpd; /* max elec speed */ - mtrParamHandle->maxCurr = motorTable->maxCurr; /* max current */ - mtrParamHandle->maxTrq = 0.0f; -} \ No newline at end of file diff --git a/application/middleware_sample/mcs_65demo/inc/mcs_65demo.h b/application/middleware_sample/mcs_65demo/inc/mcs_65demo.h deleted file mode 100644 index bd63331f480157f5a3553953afad8964b1504b51..0000000000000000000000000000000000000000 --- a/application/middleware_sample/mcs_65demo/inc/mcs_65demo.h +++ /dev/null @@ -1,54 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_65demo.h - * @author MCU Algorithm Team - * @brief This file provides motor sample functions declaration for AD105HDMA board. - */ -#ifndef McuMagicTag_MCS_65DEMO_H -#define McuMagicTag_MCS_65DEMO_H - -#include "mcs_65demo_system_init.h" -#include "main.h" - -/** - * @brief phase sequence. - */ -typedef enum { - PHASE_U = 0, - PHASE_V, - PHASE_W, - PHASE_MAX_NUM -} MCS_PhaseEnum; - -/** - * @brief Motor number enum - */ -typedef enum { - MOTOR_NO0, - MOTOR_NO1, - MOTOR_MAX_NUM -} MOTOR_ENUM; - -int Main65Demo(void); - -void Timer1ITCallBack(void *param); -void APT3EventCallback(void *para); -void APT0EventCallback(void *para); -void APT3TimerCallback(void *para); - -#endif \ No newline at end of file diff --git a/application/middleware_sample/mcs_65demo/inc/mcs_65demo_system_init.h b/application/middleware_sample/mcs_65demo/inc/mcs_65demo_system_init.h deleted file mode 100644 index 95a32ea52631f3992dd935e35d1903a34e3d58fc..0000000000000000000000000000000000000000 --- a/application/middleware_sample/mcs_65demo/inc/mcs_65demo_system_init.h +++ /dev/null @@ -1,62 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_65demo_system_init.h - * @author MCU Algorithm Team - * @brief This file provides motor sample param declaration for AD105HDMA board. - */ -#ifndef McuMagicTag_MCS_65DEMO_SYSTEM_INIT_H -#define McuMagicTag_MCS_65DEMO_SYSTEM_INIT_H - -#include "gpio.h" -#include "apt.h" -#include "apt_ip.h" -#include "adc.h" -#include "pga.h" -#include "timer.h" - -extern ADC_Handle g_adc0; -extern ADC_Handle g_adc2; -extern APT_Handle g_apt0; -extern APT_OutCtrlProtect g_protectApt0; -extern APT_Handle g_apt1; -extern APT_OutCtrlProtect g_protectApt1; -extern APT_Handle g_apt2; -extern APT_OutCtrlProtect g_protectApt2; -extern APT_Handle g_apt3; -extern APT_OutCtrlProtect g_protectApt3; -extern APT_Handle g_apt4; -extern APT_OutCtrlProtect g_protectApt4; -extern APT_Handle g_apt5; -extern APT_OutCtrlProtect g_protectApt5; -extern GPIO_Handle g_gpio0; -extern GPIO_Handle g_gpio2; -extern TIMER_Handle g_timer1; - -#define APT_SYNC_IN_SRC APT_SYNCIN_SRC_APT3_SYNCOUT - -#define APT_U_CP APT3_BASE /* Base address of U phase APT module */ -#define APT_V_CP APT4_BASE /* Base address of V phase APT module */ -#define APT_W_CP APT5_BASE /* Base address of W phase APT module */ - -#define APT_U_FAN APT0_BASE /* Base address of U phase APT module */ -#define APT_V_FAN APT1_BASE /* Base address of V phase APT module */ -#define APT_W_FAN APT2_BASE /* Base address of W phase APT module */ - -void SystemInit(void); - -#endif /* McuMagicTag_MCS_65DEMO_SYSTEM_INIT_H */ diff --git a/application/middleware_sample/mcs_65demo/inc/mcs_config_65demo.h b/application/middleware_sample/mcs_65demo/inc/mcs_config_65demo.h deleted file mode 100644 index 1a8fbe5ea2ba2e09e7edcbd8a9a285ccfbc3ad0d..0000000000000000000000000000000000000000 --- a/application/middleware_sample/mcs_65demo/inc/mcs_config_65demo.h +++ /dev/null @@ -1,77 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_config_65demo.h - * @author MCU Algorithm Team - * @brief This file provides config macros for 65demo app. - */ -#ifndef McuMagicTag_MCS_CONFIG_65DEMO_H -#define McuMagicTag_MCS_CONFIG_65DEMO_H - -#include "debug.h" -#include "typedefs.h" - -#define SYSTICK_PERIOD_US 500u /* systick period */ - -#define INV_CAP_CHARGE_MS 3u -#define INV_VOLTAGE_BUS 24.0f /* Bus voltage, V */ - -#define CTRL_CURR_PERIOD 0.0001f /* carrier ISR period */ -#define CTRL_SYSTICK_PERIOD 0.0005f /* systick control period */ - -/** Duty of sample window, the real time is 0.06*50us = 3us. */ -#define SAMPLE_WINDOW_DUTY 0.06f - -/** Duty of sample point shift as flip point, the real time is 0.008*50us = 0.4us. */ -#define SAMPLE_POINT_SHIFT 0.008f - -/* SMO */ -#define SPEED_FILTER_CUTOFF_FREQUENCY 40.0f -#define FOSMO_GAIN 10.0f -#define FILTER_ANGLE_COMPENSATION 4826 - -/* User Command */ -#define CTRL_IF_CURR_AMP_A 1.0f /* IF control current amplitude */ -/* 0.008055 Sampling resistance20 Ohm Sampling resistance 100mOhm 0.001611f */ -#define ADC_CURR_COFFI_CP 0.001611f -#define USER_TARGET_SPD_HZ (100.0f) /* Parentheses are used to enter negative instructions */ -#define USER_SWITCH_SPDBEGIN_HZ 70.0f /* Start of handover interval */ -#define USER_SWITCH_SPDEND_HZ 73.0f /* End of handover period */ - -#define USER_SPD_SLOPE 15.0f /* slope of velocity change */ -#define USER_CURR_SLOPE (CTRL_IF_CURR_AMP_A * 0.5f) /* Current change slope */ - -/* FAN ----------------------------------------------------------------------------------------- */ -#define CTRL_IF_CURR_AMP_A_FAN 1.0f /* IF control current amplitude */ - -/* 0.008055 Sampling resistance20 Ohm Sampling resistance 100mOhm 0.001611f */ -#define ADC_CURR_COFFI_FAN 0.001611f - -#define USER_TARGET_SPD_HZ_FAN (100.0f) /* Parentheses are used to enter negative instructions */ -#define USER_SWITCH_SPDBEGIN_HZ_FAN 70.0f /* Start of handover interval, Positive number only */ -#define USER_SWITCH_SPDEND_HZ_FAN 73.0f /* End of handover period, Positive number only */ - -#define USER_SPD_SLOPE_FAN 15.0f /* slope of velocity change */ -#define USER_CURR_SLOPE_FAN CTRL_IF_CURR_AMP_A_FAN /* Current change slope */ - -/* Service Definition */ -#define PTC_RELAY_DELAY 2 -#define MOTOR_START_DELAY 10 -#define IPM_90DEGRESS_V 2.9f /* IPM voltage at 90°C */ -#define IPM_VOLT_COEFFI 0.0008056f /* 3.3 / 4096 */ - -#endif \ No newline at end of file diff --git a/application/middleware_sample/mcs_65demo/readme.txt b/application/middleware_sample/mcs_65demo/readme.txt deleted file mode 100644 index 00987d133b4e74e17191080897d78784bee5fe99..0000000000000000000000000000000000000000 --- a/application/middleware_sample/mcs_65demo/readme.txt +++ /dev/null @@ -1,5 +0,0 @@ -ʾơmcs_65demo -˵AD105HDMA VER.A˫FOCӦ -Ҫ󡿣õԴΪʾõ24Vѹ˫ѡڽ42JSF630AS-1000 -IDE÷chipConfigеsampleĿѡMotorcontrolsystemʾȻɴ뼴 -עAD105HDMA VER.A屾Ϊѹ壬Ҫij24Vѹ \ No newline at end of file diff --git a/application/middleware_sample/mcs_65demo/src/mcs_65demo.c b/application/middleware_sample/mcs_65demo/src/mcs_65demo.c deleted file mode 100644 index 951922a400ebe2eef16234eb06d045844312c084..0000000000000000000000000000000000000000 --- a/application/middleware_sample/mcs_65demo/src/mcs_65demo.c +++ /dev/null @@ -1,894 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_65demo.c - * @author MCU Algorithm Team - * @brief This file provides motor application for AD105HDMA board. - * @details Dual FOC application based on the AD105HDMA VER.A board - * 1) Both motor model is JMC 42JSF630AS-1000. - * 2) Select the Motorcontrolsystem example in the sample column of chipConfig and click Generate Code. - * 3) The AD105HDMA VER.A board is a high-voltage board, its power supply must be changed to 24V. - */ -#include "mcs_65demo.h" -#include "mcs_config_65demo.h" -#include "mcs_math_const.h" -#include "mcs_math.h" -#include "mcs_config_motor.h" -#include "mcs_carrier_process.h" - -#define MICROSECOND_NUM_PER_MILLISECOND 1000 -#define ANGLE_RANGE_ABS 65536 -#define ANGLE_360_F 65536.0f /* 0 - 65536 indicates 0 to 360. */ -#define APT_FULL_DUTY 1.0f - -/* Motor parameters. */ -static MotorConfig g_MotorParam[MOTOR_MAX_NUM] = { - {4, 0.5f, 0.000295f, 0.000295f, 0.0f, 0.0f, 200.0f, 4.0f, 4000, 410}, /* Wildfire 24V */ - {4, 0.5f, 0.000295f, 0.000295f, 0.0f, 0.0f, 200.0f, 4.0f, 4000, 410} /* Wildfire 24V */ -}; - -/* Motor PI param. */ -static PiCtrlParam g_motorPiParam[MOTOR_MAX_NUM] = { - /* currKp,ki, limitPu, spdKp, ki, limit */ - {0.7414f, 0.1256f, 1.0f, 0.0105f, 0.000003f, 1.0f}, /* Wildfire 24V */ - {0.7414f, 0.1256f, 1.0f, 0.0105f, 0.000003f, 1.0f} /* Wildfire 24V */ -}; - -static void *g_aptCp[PHASE_MAX_NUM] = {APT_U_CP, APT_V_CP, APT_W_CP}; -static void *g_aptFan[PHASE_MAX_NUM] = {APT_U_FAN, APT_V_FAN, APT_W_FAN}; - -/* Motor control handle for compressor */ -static MtrCtrlHandle g_mc; - -/* Motor control handle for fan */ -static MtrCtrlHandle g_fan; - -/** - * @brief Initialzer of system tick. - * @param mtrCtrl Motor control struct handle. - * @retval None. - */ -static void TimerTickInit(MtrCtrlHandle *mtrCtrl) -{ - MCS_ASSERT_PARAM(mtrCtrl != NULL); - mtrCtrl->sysTickCnt = 0; - mtrCtrl->msTickNum = MICROSECOND_NUM_PER_MILLISECOND / SYSTICK_PERIOD_US; - mtrCtrl->capChargeTickNum = (INV_CAP_CHARGE_MS * MICROSECOND_NUM_PER_MILLISECOND / SYSTICK_PERIOD_US); -} - -/** - * @brief Initialzer of Current controller. - * @param currHandle Current control handle. - * @param mtrCtrl Motor control handle. - * @param piCtrlTable Dual loop control parameters. - * @retval None. - */ -static void CurrCtrlInit(CurrCtrlHandle *currHandle, MtrCtrlHandle *mtrCtrl, const PiCtrlParam *piCtrlTable) -{ - MCS_ASSERT_PARAM(currHandle != NULL); - MCS_ASSERT_PARAM(mtrCtrl != NULL); - MCS_ASSERT_PARAM(piCtrlTable != NULL); - currHandle->currRef = &mtrCtrl->currRefDq; - currHandle->currFdbk = &mtrCtrl->currDq; - /* Initialization current feedforward value */ - currHandle->currFf.d = 0.0f; - currHandle->currFf.q = 0.0f; - - PID_Reset(&currHandle->dAxisPi); /* clear d-axis PI param */ - - PID_Reset(&currHandle->qAxisPi); /* clear q-axis PI param */ - - currHandle->outLimit = 0.0f; - currHandle->mtrParam = &(mtrCtrl->mtrParam); - currHandle->ctrlPeriod = mtrCtrl->currCtrlPeriod; - - currHandle->dAxisPi.kp = piCtrlTable->currPiKp; - currHandle->dAxisPi.ki = piCtrlTable->currPiKi; - currHandle->qAxisPi.kp = piCtrlTable->currPiKp; - currHandle->qAxisPi.ki = piCtrlTable->currPiKi; - currHandle->outLimit = INV_VOLTAGE_BUS * ONE_DIV_SQRT3 * piCtrlTable->currPiLimitPu; /* output voltage limit */ - currHandle->dAxisPi.upperLimit = currHandle->outLimit; - currHandle->dAxisPi.lowerLimit = -currHandle->outLimit; - currHandle->qAxisPi.upperLimit = currHandle->outLimit; - currHandle->qAxisPi.lowerLimit = -currHandle->outLimit; -} - -/** - * @brief Initialzer of speed control struct handle. - * @param spdHandle Speed control struct handle. - * @param piCtrlTable PI controller parameter table. - * @retval None. - */ -static void SpdCtrlInit(SpdCtrlHandle *spdHandle, const PiCtrlParam *piCtrlTable) -{ - MCS_ASSERT_PARAM(spdHandle != NULL); - MCS_ASSERT_PARAM(piCtrlTable != NULL); - PID_Reset(&spdHandle->spdPi); /* reset speed loop PI */ - - spdHandle->trqLimit = 0.0f; - spdHandle->mtrParam = NULL; - spdHandle->ctrlPeriod = CTRL_SYSTICK_PERIOD; - /* Initialize the PI parameter of the speed loop. */ - spdHandle->spdPi.kp = piCtrlTable->spdPiKp; - spdHandle->spdPi.ki = piCtrlTable->spdPiKi; - spdHandle->trqLimit = piCtrlTable->spdPiLimit; - spdHandle->spdPi.upperLimit = spdHandle->trqLimit; - spdHandle->spdPi.lowerLimit = -spdHandle->trqLimit; -} - -/** - * @brief Initialzer of Pll struct handle. - * @param pllHandle pll struct handle. - * @retval None. - */ -static void PLL_Init(PllHandle *pllHandle) -{ - MCS_ASSERT_PARAM(pllHandle != NULL); - float we = 300.0f; /* PLL bandwidth (unit: Hz) */ - /* Reset PLL PID. */ - PID_Reset(&pllHandle->pi); - /* Initializing PLL Parameters. */ - pllHandle->ctrlPeriod = CTRL_CURR_PERIOD; - pllHandle->pi.kp = 1.414f * we; /* sqrt(2) * we */ - pllHandle->pi.ki = we * we * CTRL_CURR_PERIOD; - pllHandle->pi.upperLimit = 5000.0f; /* The upper limit value of the pid comp output. */ - pllHandle->pi.lowerLimit = -pllHandle->pi.upperLimit; - pllHandle->minAmp = 0.1f; /* Minimum value of the input value in case of the divergence of the PLL. */ - pllHandle->freq = 0.0f; - pllHandle->ratio = ANGLE_360_F * CTRL_CURR_PERIOD; - pllHandle->angle = 0; -} - -/** - * @brief Initialzer of Smo control struct handle. - * @param smoHandle Position SMO struct handle. - * @param mtrParam Motor parameter handle. - * @retval None. - */ -static void SmoInit(FoSmoHandle *smoHandle, MtrParamHandle *mtrParam) -{ - MCS_ASSERT_PARAM(smoHandle != NULL); - MCS_ASSERT_PARAM(mtrParam != NULL); - smoHandle->mtrParam = mtrParam; - smoHandle->ctrlPeriod = CTRL_CURR_PERIOD; - - smoHandle->a1 = 1.0f - (smoHandle->ctrlPeriod * smoHandle->mtrParam->mtrRs / smoHandle->mtrParam->mtrLd); - smoHandle->a2 = smoHandle->ctrlPeriod / smoHandle->mtrParam->mtrLd; - - smoHandle->kSmo = FOSMO_GAIN; - smoHandle->lambda = 2.0f; /* SMO coefficient of cut-off frequency is 2.0. */ - /* smo angle filcompAngle */ - smoHandle->filCompAngle = FILTER_ANGLE_COMPENSATION; - FOSMO_Clear(smoHandle); - - smoHandle->emfLpfMinFreq = 2.0f; /* The minimum cutoff frequency of the back EMF filter is 2.0. */ - PLL_Init(&smoHandle->pll); - - /* low pass filter cutoff frequency for speed estimation is 40Hz */ - FoLowPassFilterInit(&smoHandle->spdFilter, smoHandle->ctrlPeriod, SPEED_FILTER_CUTOFF_FREQUENCY); -} - -/** - * @brief Init motor control task. - * @retval None. - */ -static void TSK_InitCp(void) -{ - IfCtrlInit ifInitParam; - - g_mc.stateMachine = FSM_IDLE; - g_mc.spdCmdHz = USER_TARGET_SPD_HZ; - g_mc.aptMaxcntCmp = g_apt3.waveform.timerPeriod; - g_mc.sampleMode = SINGLE_RESISTOR; - - ifInitParam.currSlope = USER_CURR_SLOPE; - ifInitParam.anglePeriod = CTRL_CURR_PERIOD; - ifInitParam.targetAmp = CTRL_IF_CURR_AMP_A; - ifInitParam.stepAmpPeriod = CTRL_SYSTICK_PERIOD; - - IF_Init(&g_mc.ifCtrl, &ifInitParam); - - RMG_Init(&g_mc.spdRmg, CTRL_SYSTICK_PERIOD, USER_SPD_SLOPE); /* Init speed slope */ - - MtrParamInit(&g_mc.mtrParam, &g_MotorParam[MOTOR_NO0]); - - TimerTickInit(&g_mc); - - SVPWM_Init(&g_mc.sv, INV_VOLTAGE_BUS * ONE_DIV_SQRT3); - - R1SVPWM_Init(&g_mc.r1Sv, INV_VOLTAGE_BUS * ONE_DIV_SQRT3, SAMPLE_POINT_SHIFT, SAMPLE_WINDOW_DUTY); - - g_mc.currCtrlPeriod = CTRL_CURR_PERIOD; /* Init current controller */ - CurrCtrlInit(&g_mc.currCtrl, &g_mc, &g_motorPiParam[MOTOR_NO0]); - - SpdCtrlInit(&g_mc.spdCtrl, &g_motorPiParam[MOTOR_NO0]); /* Init speed controller */ - - SmoInit(&g_mc.smo, &g_mc.mtrParam); /* Init the SMO observer */ - - STARTUP_Init(&g_mc.startup, USER_SWITCH_SPDBEGIN_HZ, USER_SWITCH_SPDEND_HZ); -} - -/** - * @brief Init motor control task. - * @retval None. - */ -static void TSK_InitFan(void) -{ - IfCtrlInit ifInitParam; - - g_fan.stateMachine = FSM_IDLE; - g_fan.spdCmdHz = USER_TARGET_SPD_HZ_FAN; - g_fan.aptMaxcntCmp = g_apt0.waveform.timerPeriod; - g_fan.sampleMode = SINGLE_RESISTOR; - - ifInitParam.anglePeriod = CTRL_CURR_PERIOD; - ifInitParam.currSlope = USER_CURR_SLOPE_FAN; - ifInitParam.stepAmpPeriod = CTRL_SYSTICK_PERIOD; - ifInitParam.targetAmp = CTRL_IF_CURR_AMP_A_FAN; - IF_Init(&g_fan.ifCtrl, &ifInitParam); - - RMG_Init(&g_fan.spdRmg, CTRL_SYSTICK_PERIOD, USER_SPD_SLOPE_FAN); /* Init speed slope */ - - MtrParamInit(&g_fan.mtrParam, &g_MotorParam[MOTOR_NO1]); - - TimerTickInit(&g_fan); - - R1SVPWM_Init(&g_fan.r1Sv, INV_VOLTAGE_BUS * ONE_DIV_SQRT3, SAMPLE_POINT_SHIFT, SAMPLE_WINDOW_DUTY); - - g_fan.currCtrlPeriod = CTRL_CURR_PERIOD; /* Init current controller */ - - CurrCtrlInit(&g_fan.currCtrl, &g_fan, &g_motorPiParam[MOTOR_NO1]); - - SpdCtrlInit(&g_fan.spdCtrl, &g_motorPiParam[MOTOR_NO1]); /* Init speed controller */ - - SmoInit(&g_fan.smo, &g_fan.mtrParam); /* Init the SMO observer */ - - STARTUP_Init(&g_fan.startup, USER_SWITCH_SPDBEGIN_HZ_FAN, USER_SWITCH_SPDEND_HZ_FAN); -} - -/** - * @brief Clear historical values of all controller before start-up. - * @param mtrCtrl The motor control handle. - * @retval None. - */ -static void ClearBeforeStartup(MtrCtrlHandle *mtrCtrl) -{ - MCS_ASSERT_PARAM(mtrCtrl != NULL); - /* The initial angle is 0. */ - mtrCtrl->axisAngle = 0; - - mtrCtrl->spdRefHz = 0.0f; - /* The initial dq-axis reference current is 0. */ - mtrCtrl->currRefDq.d = 0.0f; - mtrCtrl->currRefDq.q = 0.0f; - - mtrCtrl->vdq.d = 0.0f; - mtrCtrl->vdq.q = 0.0f; - /* Clear Duty Cycle Value. The initial duty cycle is 0.5. */ - mtrCtrl->dutyUvwLeft.u = 0.5f; - mtrCtrl->dutyUvwLeft.v = 0.5f; - mtrCtrl->dutyUvwLeft.w = 0.5f; - mtrCtrl->dutyUvwRight.u = 0.5f; - mtrCtrl->dutyUvwRight.v = 0.5f; - mtrCtrl->dutyUvwRight.w = 0.5f; - - RMG_Clear(&mtrCtrl->spdRmg); /* Clear the history value of speed slope control */ - CURRCTRL_Clear(&mtrCtrl->currCtrl); - IF_Clear(&mtrCtrl->ifCtrl); - SPDCTRL_Clear(&mtrCtrl->spdCtrl); - FOSMO_Clear(&mtrCtrl->smo); - STARTUP_Clear(&mtrCtrl->startup); - R1SVPWM_Clear(&mtrCtrl->r1Sv); -} - -/** - * @brief To set the comparison value of the IGBT single-resistance ADC sampling trigger position. - * @param aptx The APT register struct handle. - * @param cntCmpA A Count compare reference of time-base counter. - * @param cntCmpB B Count compare reference of time-base counter. - * @param maxCntCmp Maximum Comparison Value - * @retval None. - */ -static void MCS_SetAdcCompareR1(APT_RegStruct *aptx, unsigned short cntCmpA, - unsigned short cntCmpB, unsigned short maxCntCmp) -{ - MCS_ASSERT_PARAM(aptx != NULL); - MCS_ASSERT_PARAM(maxCntCmp != 0); - unsigned short tmp; - /* Sets the A Count compare reference of time-base counter. */ - tmp = (cntCmpA >= maxCntCmp) ? (maxCntCmp - 1) : cntCmpA; - DCL_APT_SetCounterCompare(aptx, APT_COMPARE_REFERENCE_A, tmp); - /* Sets the B Count compare reference of time-base counter. */ - tmp = (cntCmpB >= maxCntCmp) ? (maxCntCmp - 1) : cntCmpB; - DCL_APT_SetCounterCompare(aptx, APT_COMPARE_REFERENCE_B, tmp); -} - -/** - * @brief Open the three-phase lower pipe. - * @param aptAddr Three-phase APT address pointer. - * @param maxDutyCnt Max duty count. - * @retval None. - */ -static void AptTurnOnLowSidePwm(void **aptAddr, unsigned int maxDutyCnt) -{ - MCS_ASSERT_PARAM(aptAddr != NULL); - MCS_ASSERT_PARAM(maxDutyCnt != 0); - unsigned int dutyCnt; - dutyCnt = maxDutyCnt * APT_FULL_DUTY; - /* Open the three-phase lower pipe */ - for (unsigned int i = 0; i < PHASE_MAX_NUM; i++) { - APT_RegStruct *aptx = (APT_RegStruct *)(aptAddr[i]); - aptx->TC_REFC.BIT.rg_cnt_refch = dutyCnt; - aptx->TC_REFD.BIT.rg_cnt_refdh = dutyCnt; - } -} - -/** - * @brief Enable three-phase pwm output. - * @param aptAddr Three-phase APT address pointer. - * @retval None. - */ -static void MotorPwmOutputEnable(void **aptAddr) -{ - MCS_ASSERT_PARAM(aptAddr != NULL); - /* Enable three-phase pwm output */ - for (unsigned int i = 0; i < PHASE_MAX_NUM; i++) { - APT_RegStruct *aptx = (APT_RegStruct *)(aptAddr[i]); - aptx->PG_OUT_FRC.BIT.rg_pga_frc_en = BASE_CFG_UNSET; - aptx->PG_OUT_FRC.BIT.rg_pgb_frc_en = BASE_CFG_UNSET; - } -} - -/** - * @brief Disable three-phase pwm output. - * @param aptAddr Three-phase APT address pointer. - * @retval None. - */ -static void MotorPwmOutputDisable(void **aptAddr) -{ - MCS_ASSERT_PARAM(aptAddr != NULL); - /* Disable three-phase pwm output. */ - for (unsigned int i = 0; i < PHASE_MAX_NUM; i++) { - APT_RegStruct *aptx = (APT_RegStruct *)(aptAddr[i]); - aptx->PG_OUT_FRC.BIT.rg_pga_frc_en = BASE_CFG_SET; - aptx->PG_OUT_FRC.BIT.rg_pgb_frc_en = BASE_CFG_SET; - DCL_APT_ForcePWMOutputLow(aptx); - } -} - -/** - * @brief Smo IF angle difference calculation. - * @param smoElecAngle Smo electrical angle. - * @param ifCtrlAngle IF control angle. - * @retval signed short angle difference. - */ -static signed short SmoIfAngleDiffCalc(signed short smoElecAngle, signed short ifCtrlAngle) -{ - /* Smo IF angle difference calculation */ - signed int tmpS32 = (signed int)(smoElecAngle - ifCtrlAngle); - if (tmpS32 > INT16_MAX) { - tmpS32 -= ANGLE_RANGE_ABS; - } - if (tmpS32 < INT16_MIN) { - tmpS32 += ANGLE_RANGE_ABS; - } - return (signed short)(tmpS32); -} - -/** - * @brief Construct a new mcs startupswitch object. - * @param mtrCtrl The motor control handle. - * @retval None. - */ -static void MCS_StartupSwitch(MtrCtrlHandle *mtrCtrl) -{ - MCS_ASSERT_PARAM(mtrCtrl != NULL); - StartupHandle *startup = &mtrCtrl->startup; - DqAxis *currRefDq = &mtrCtrl->currRefDq; - float iftargetAmp = mtrCtrl->ifCtrl.targetAmp; - float spdRefHz = mtrCtrl->spdRefHz; - - switch (startup->stage) { - case STARTUP_STAGE_CURR: - if (mtrCtrl->ifCtrl.curAmp >= iftargetAmp) { - /* Stage change */ - currRefDq->q = iftargetAmp; - startup->stage = STARTUP_STAGE_SPD; - } else { - /* current amplitude increase */ - currRefDq->q = IF_CurrAmpCalc(&mtrCtrl->ifCtrl); - spdRefHz = 0.0f; - } - break; - case STARTUP_STAGE_SPD: - /* current frequency increase */ - if (Abs(spdRefHz) >= startup->spdBegin) { - /* Stage change */ - startup->stage = STARTUP_STAGE_SWITCH; - TrigVal localTrigVal; - TrigCalc(&localTrigVal, SmoIfAngleDiffCalc(mtrCtrl->smo.elecAngle, mtrCtrl->ifCtrl.angle)); - currRefDq->d = iftargetAmp * localTrigVal.sin; - mtrCtrl->startup.initCurr = currRefDq->d; - currRefDq->q = iftargetAmp; - mtrCtrl->spdCtrl.spdPi.integral = iftargetAmp * localTrigVal.cos; - } else { - /* Speed rmg */ - spdRefHz = RMG_Exec(&mtrCtrl->spdRmg, mtrCtrl->spdCmdHz); - } - break; - - case STARTUP_STAGE_SWITCH: - /* Switch from IF to SMO */ - spdRefHz = RMG_Exec(&mtrCtrl->spdRmg, mtrCtrl->spdCmdHz); - currRefDq->d = STARTUP_CurrCal(&mtrCtrl->startup, spdRefHz); - SPDCTRL_Exec(&mtrCtrl->spdCtrl, spdRefHz, mtrCtrl->smo.spdEstHz, &mtrCtrl->currRefDq); - if (spdRefHz >= startup->spdEnd) { - /* Stage change */ - currRefDq->d = 0.0f; - mtrCtrl->stateMachine = FSM_RUN; - } - break; - - default: - break; - } - - mtrCtrl->spdRefHz = spdRefHz; -} - -/** - * @brief Pre-processing of motor status. - * @param statusReg System status. - * @param stateMachine Motor Control Status. - * @retval None. - */ -static void MotorStatePerProc(SysStatusReg *statusReg, volatile FsmState *stateMachine) -{ - MCS_ASSERT_PARAM(statusReg != NULL); - MCS_ASSERT_PARAM(stateMachine != NULL); - /* Get system status */ - if (SysIsError(statusReg)) { - *stateMachine = FSM_FAULT; - } - if (SysGetCmdStop(statusReg)) { - SysCmdStopClr(statusReg); - *stateMachine = FSM_STOP; - } -} - -/** - * @brief System timer tick task. - * @param mtrCtrl The motor control handle. - * @param aptAddr Three-phase APT address pointer. - * @retval None. - */ -static void TSK_SystickIsr(MtrCtrlHandle *mtrCtrl, void **aptAddr) -{ - MCS_ASSERT_PARAM(mtrCtrl != NULL); - MCS_ASSERT_PARAM(aptAddr != NULL); - SysStatusReg *statusReg = &mtrCtrl->statusReg; - volatile FsmState *stateMachine = &mtrCtrl->stateMachine; - mtrCtrl->msTickCnt++; - /* Pre-processing of motor status. */ - MotorStatePerProc(statusReg, stateMachine); - /* statemachine */ - switch (*stateMachine) { - case FSM_IDLE: - if (SysGetCmdStart(statusReg)) { - SysRunningSet(statusReg); - SysCmdStartClr(statusReg); - mtrCtrl->sysTickCnt = 0; - *stateMachine = FSM_CAP_CHARGE; - /* Preparation for charging the bootstrap capacitor. */ - AptTurnOnLowSidePwm(aptAddr, mtrCtrl->aptMaxcntCmp); - /* Out put pwm */ - MotorPwmOutputEnable(aptAddr); - } - break; - - case FSM_CAP_CHARGE: - /* Bootstrap Capacitor Charging Timing */ - mtrCtrl->sysTickCnt++; - if (mtrCtrl->sysTickCnt == mtrCtrl->capChargeTickNum) { - *stateMachine = FSM_CLEAR; - } - break; - - case FSM_CLEAR: - ClearBeforeStartup(mtrCtrl); - *stateMachine = FSM_STARTUP; - break; - - case FSM_STARTUP: - MCS_StartupSwitch(mtrCtrl); - break; - - case FSM_RUN: - /* Speed ramp control */ - mtrCtrl->spdRefHz = RMG_Exec(&mtrCtrl->spdRmg, mtrCtrl->spdCmdHz); - /* speed loop control */ - SPDCTRL_Exec(&mtrCtrl->spdCtrl, mtrCtrl->spdRefHz, mtrCtrl->smo.spdEstHz, &mtrCtrl->currRefDq); - break; - - case FSM_STOP: - MotorPwmOutputDisable(aptAddr); - SysRunningClr(statusReg); - *stateMachine = FSM_IDLE; - break; - - case FSM_FAULT: /* Overcurrent state */ - if (SysIsError(statusReg) == false) { - *stateMachine = FSM_IDLE; - } - break; - default: - break; - } -} - -/** - * @brief Read the ADC current sampling value of the compressor. - * @param CurrUvw Three-phase current. - * @retval None. - */ -static void ReadCurrUvwCp(UvwAxis *CurrUvw) -{ - MCS_ASSERT_PARAM(CurrUvw != NULL); - float iBusSocA, iBusSocB; - - /* Zero sampling value of hardware circuit is 2104.0f. */ - iBusSocA = (float)(HAL_ADC_GetConvResult(&g_adc2, ADC_SOC_NUM8) - 2104.0f) * ADC_CURR_COFFI_CP; - iBusSocB = (float)(HAL_ADC_GetConvResult(&g_adc2, ADC_SOC_NUM9) - 2104.0f) * ADC_CURR_COFFI_CP; - R1CurrReconstruct(g_mc.r1Sv.voltIndexLast, iBusSocA, iBusSocB, CurrUvw); -} - -/** - * @brief Setting the APT Output Duty Cycle. - * @param aptx APT register base address. - * @param leftDuty Left duty cycle. - * @param rightDuty Right duty cycle. - * @retval None. - */ -static void SetPwmDuty(APT_Handle *aptx, float leftDuty, float rightDuty) -{ - MCS_ASSERT_PARAM(aptx != NULL); - MCS_ASSERT_PARAM(leftDuty < 0); - MCS_ASSERT_PARAM(rightDuty < 0); - unsigned short maxPeriodCnt = aptx->waveform.timerPeriod; - unsigned short cntCmpLeftEdge = (unsigned short)(leftDuty * maxPeriodCnt); - unsigned short cntCmpRightEdge = (unsigned short)(rightDuty * maxPeriodCnt); - /* avoid overflowing */ - cntCmpLeftEdge = (cntCmpLeftEdge > maxPeriodCnt) ? maxPeriodCnt : cntCmpLeftEdge; - cntCmpRightEdge = (cntCmpRightEdge > maxPeriodCnt) ? maxPeriodCnt : cntCmpRightEdge; - HAL_APT_SetPWMDuty(aptx, cntCmpLeftEdge, cntCmpRightEdge); -} - -/** - * @brief Compressor Duty Cycle Setting. - * @param dutyUvwLeft Three-phase left duty cycle. - * @param dutyUvwRight Three-phase right duty cycle. - * @retval None. - */ -static void SetPwmDutyCp(UvwAxis *dutyUvwLeft, UvwAxis *dutyUvwRight) -{ - MCS_ASSERT_PARAM(dutyUvwLeft != NULL); - MCS_ASSERT_PARAM(dutyUvwRight != NULL); - /* Setting the Three-Phase Duty Cycle */ - SetPwmDuty(&g_apt3, dutyUvwLeft->u, dutyUvwRight->u); - SetPwmDuty(&g_apt4, dutyUvwLeft->v, dutyUvwRight->v); - SetPwmDuty(&g_apt5, dutyUvwLeft->w, dutyUvwRight->w); -} - -/** - * @brief To set the ADC sampling trigger comparison value. - * @param cntCmpSOCA Soca Compare Count Value. - * @param cntCmpSOCB Socb Compare Count Value. - * @retval None. - */ -static void SetADCTriggerTimeCp(unsigned short cntCmpSOCA, unsigned short cntCmpSOCB) -{ - MCS_SetAdcCompareR1(g_aptCp[PHASE_U], cntCmpSOCA, cntCmpSOCB, g_mc.aptMaxcntCmp); -} - -/** - * @brief Obtaining the Three-Phase Current of the Fan. - * @param CurrUvw Three-phase current data return pointer. - * @retval None. - */ -static void ReadCurrUvwFan(UvwAxis *CurrUvw) -{ - MCS_ASSERT_PARAM(CurrUvw != NULL); - float iBusSocA, iBusSocB; - - /* Zero sampling value of hardware circuit is 2076.0f. */ - iBusSocA = (float)(HAL_ADC_GetConvResult(&g_adc0, ADC_SOC_NUM0) - 2076.0f) * ADC_CURR_COFFI_FAN; - iBusSocB = (float)(HAL_ADC_GetConvResult(&g_adc0, ADC_SOC_NUM1) - 2076.0f) * ADC_CURR_COFFI_FAN; - R1CurrReconstruct(g_fan.r1Sv.voltIndexLast, iBusSocA, iBusSocB, CurrUvw); -} - -/** - * @brief Fan Duty Cycle Setting. - * @param dutyUvwLeft Three-phase left duty cycle. - * @param dutyUvwRight Three-phase right duty cycle. - * @retval None. - */ -static void SetPwmDutyFan(UvwAxis *dutyUvwLeft, UvwAxis *dutyUvwRight) -{ - MCS_ASSERT_PARAM(dutyUvwLeft != NULL); - MCS_ASSERT_PARAM(dutyUvwRight != NULL); - /* Setting the Three-Phase Duty Cycle */ - SetPwmDuty(&g_apt0, dutyUvwLeft->u, dutyUvwRight->u); - SetPwmDuty(&g_apt1, dutyUvwLeft->v, dutyUvwRight->v); - SetPwmDuty(&g_apt2, dutyUvwLeft->w, dutyUvwRight->w); -} - -/** - * @brief To set the ADC sampling trigger comparison value. - * @param cntCmpSOCA Soca Compare Count Value. - * @param cntCmpSOCB Socb Compare Count Value. - * @retval None. - */ -static void SetADCTriggerTimeFan(unsigned short cntCmpSOCA, unsigned short cntCmpSOCB) -{ - MCS_SetAdcCompareR1(g_aptFan[PHASE_U], cntCmpSOCA, cntCmpSOCB, g_fan.aptMaxcntCmp); -} - -/** - * @brief System timer ISR function. - * @param param The systick timer handle. - * @retval None. - */ -void Timer1ITCallBack(void *param) -{ - MCS_ASSERT_PARAM(param != NULL); - TIMER_Handle *timer = (TIMER_Handle *)param; - TIMER_ASSERT_PARAM(timer != NULL); - TIMER_ASSERT_PARAM(timer->baseAddress != NULL); - /* Clear timer interrupt. */ - HAL_TIMER_IrqClear(timer); - TSK_SystickIsr(&g_mc, g_aptCp); - TSK_SystickIsr(&g_fan, g_aptFan); -} - -/* global variables for variable trace */ -volatile float g_mc_u, g_mc_v, g_mc_w; -volatile float g_fan_u, g_fan_v, g_fan_w; -volatile int g_tracevalue_ref = 1; -/** - * @brief The carrier ISR wrapper function, entry for both compressor and fan. - * @param aptHandle The APT handle. - * @retval None. - */ -void APT3TimerCallback(void *aptHandle) -{ - MCS_ASSERT_PARAM(aptHandle != NULL); - /* the carrierprocess of comp */ - MCS_CarrierProcess(&g_mc); - g_mc_u = g_mc.currUvw.u; - g_mc_v = g_mc.currUvw.v; - g_mc_w = g_mc.currUvw.w; - - /* the carrierprocess of fan */ - MCS_CarrierProcess(&g_fan); - g_fan_u = g_fan.currUvw.u; - g_fan_v = g_fan.currUvw.v; - g_fan_w = g_fan.currUvw.w; - - int tmp = g_tracevalue_ref; - - BASE_FUNC_UNUSED(aptHandle); -} - -/** - * @brief Event interrupt callback function of APT module. - * @param para APT module handle. - * @retval None. - */ -void APT0EventCallback(void *para) -{ - MCS_ASSERT_PARAM(para != NULL); - APT_Handle *handle = (APT_Handle *)para; - /* The fan IPM overcurrent triggers and disables the three-phase PWM output. */ - MotorPwmOutputDisable(g_aptFan); - DCL_APT_ClearOutCtrlEventFlag((APT_RegStruct *)g_aptFan[PHASE_U], APT_OC_COMBINE_EVENT_A1); - DCL_APT_ClearOutCtrlEventFlag((APT_RegStruct *)g_aptFan[PHASE_V], APT_OC_COMBINE_EVENT_A1); - DCL_APT_ClearOutCtrlEventFlag((APT_RegStruct *)g_aptFan[PHASE_W], APT_OC_COMBINE_EVENT_A1); - /* Status setting error */ - SysErrorSet(&g_fan.statusReg); - DBG_PRINTF("APT_EVT_IRQ_FAN\r\n"); - BASE_FUNC_UNUSED(handle); -} - -/** - * @brief Event interrupt callback function of APT module. - * @param para APT module handle. - * @retval None. - */ -void APT3EventCallback(void *para) -{ - MCS_ASSERT_PARAM(para != NULL); - APT_Handle *handle = (APT_Handle *)para; - /* The compressor IPM overcurrent triggers and disables the three-phase PWM output. */ - MotorPwmOutputDisable(g_aptCp); - DCL_APT_ClearOutCtrlEventFlag((APT_RegStruct *)g_aptCp[PHASE_U], APT_OC_COMBINE_EVENT_A1); - DCL_APT_ClearOutCtrlEventFlag((APT_RegStruct *)g_aptCp[PHASE_V], APT_OC_COMBINE_EVENT_A1); - DCL_APT_ClearOutCtrlEventFlag((APT_RegStruct *)g_aptCp[PHASE_W], APT_OC_COMBINE_EVENT_A1); - /* Status setting error */ - SysErrorSet(&g_mc.statusReg); - DBG_PRINTF("APT_EVT_IRQ_CP\r\n"); - BASE_FUNC_UNUSED(handle); -} - -/** - * @brief Disable PWM output when IPM temperature too high. - * @retval None. - */ -static void OverTempProtProcess(void) -{ - float tempV; - - HAL_ADC_SoftTrigSample(&g_adc2, ADC_SOC_NUM7); - tempV = HAL_ADC_GetConvResult(&g_adc2, ADC_SOC_NUM7) * IPM_VOLT_COEFFI; - /* IPM voltage at 90°C */ - if (tempV >= IPM_90DEGRESS_V) { - MotorPwmOutputDisable(g_aptCp); - } -} - -/** - * @brief Init motor controller's data structure. - * @retval None. - */ -static void InitSoftware(void) -{ - /* Initializing Compressor and Fan Control Tasks */ - TSK_InitCp(); - TSK_InitFan(); - - /* MCU peripheral configuration function used for initial motor control */ - g_mc.readCurrUvwCb = ReadCurrUvwCp; - g_mc.setPwmDutyCb = SetPwmDutyCp; - g_mc.setADCTriggerTimeCb = SetADCTriggerTimeCp; - - g_fan.readCurrUvwCb = ReadCurrUvwFan; - g_fan.setPwmDutyCb = SetPwmDutyFan; - g_fan.setADCTriggerTimeCb = SetADCTriggerTimeFan; -} - -/** - * @brief Confit the master APT. - * @param aptx The master APT handle. - * @retval None. - */ -static void AptMasterSet(APT_Handle *aptx) -{ - MCS_ASSERT_PARAM(aptx != NULL); - /* Confit the master APT. */ - HAL_APT_MasterSyncInit(aptx, APT_SYNC_OUT_ON_CNTR_ZERO); -} - -/** - * @brief Config the slave APT. - * @param aptx The slave APT handle. - * @retval None. - */ -static void AptSalveSet(APT_Handle *aptx) -{ - MCS_ASSERT_PARAM(aptx != NULL); - APT_SlaveSyncIn slave; - /* Config the slave APT. */ - slave.divPhase = 0; - slave.cntPhase = 0; - slave.syncCntMode = APT_COUNT_MODE_AFTER_SYNC_UP; - slave.syncInSrc = APT_SYNC_IN_SRC; - slave.cntrSyncSrc = APT_CNTR_SYNC_SRC_SYNCIN; - HAL_APT_SlaveSyncInit(aptx, &slave); -} - -/** - * @brief Configuring Master and Slave APTs. - * @retval None. - */ -static void AptMasterSalveSet(void) -{ - /* Compressor fan APT master/slave synchronization */ - AptMasterSet(&g_apt3); - AptSalveSet(&g_apt4); - AptSalveSet(&g_apt5); - AptSalveSet(&g_apt0); - AptSalveSet(&g_apt1); - AptSalveSet(&g_apt2); -} - -/** - * @brief Switch motor running status. - * @param mtrCtrl The motor control handle. - * @param motorNum The motor ID number. - */ -static void GetExternalParam(MtrCtrlHandle *mtrCtrl, MOTOR_ENUM motorNum) -{ - MCS_ASSERT_PARAM(mtrCtrl != NULL); - BASE_FUNC_UNUSED(mtrCtrl->spdCmdHz); /* Externally controlled motor speed, Control motor speed */ - BASE_FUNC_UNUSED(motorNum); /* Current motor number */ -} - -/** - * @brief Initial configuration of the underlying driver. - * @retval None. - */ -__weak void SystemInit(void) -{ -} - -/** - * @brief User application main entry for 65demo board. - * @retval BSP_OK. - */ -int Main65Demo(void) -{ - unsigned int tickNum1Ms = 2; /* 1ms tick */ - static unsigned int tickCnt1Ms = 0; - - unsigned int tickNum500Ms = 1000; /* 500ms tick */ - static unsigned int tickCnt500Ms = 0; - - SystemInit(); - - HAL_TIMER_Start(&g_timer1); - - AptMasterSalveSet(); - /* Disable PWM output before startup. */ - MotorPwmOutputDisable(g_aptCp); - MotorPwmOutputDisable(g_aptFan); - - HAL_CRG_IpEnableSet(UART0_BASE, BASE_CFG_ENABLE); - DBG_UartPrintInit(BAUDRATE); - /* Software initialization. */ - InitSoftware(); - /* Start the PWM clock. */ - HAL_APT_StartModule(RUN_APT0 | RUN_APT1 | RUN_APT2 | RUN_APT3 | RUN_APT4 | RUN_APT5); - - BASE_FUNC_DELAY_S(PTC_RELAY_DELAY); - /* Open PTC relay */ - HAL_GPIO_SetValue(&g_gpio2, GPIO_PIN_0, GPIO_HIGH_LEVEL); - - BASE_FUNC_DELAY_S(MOTOR_START_DELAY); - /* Starting motor. */ - SysCmdStartSet(&g_mc.statusReg); - SysCmdStartSet(&g_fan.statusReg); - - while (1) { - if (g_mc.msTickCnt - tickCnt1Ms >= tickNum1Ms) { - GetExternalParam(&g_mc, MOTOR_NO0); - GetExternalParam(&g_fan, MOTOR_NO1); - tickCnt1Ms = g_mc.msTickCnt; - if (g_mc.stateMachine == FSM_RUN || - g_mc.stateMachine == FSM_STARTUP) { - OverTempProtProcess(); - } - } - - if (g_mc.msTickCnt - tickCnt500Ms >= tickNum500Ms) { - if (SysIsError(&g_mc.statusReg) != true && SysIsError(&g_fan.statusReg) != true) { - /* The LED blinks when no status is not error. */ - HAL_GPIO_TogglePin(&g_gpio0, GPIO_PIN_5); - } - tickCnt500Ms = g_mc.msTickCnt; - } - } - return 0; -} \ No newline at end of file diff --git a/application/middleware_sample/mcs_65ldemo/common/inc/mcs_carrier_process.h b/application/middleware_sample/mcs_65ldemo/common/inc/mcs_carrier_process.h deleted file mode 100644 index 4f4b9f9ba4d9e979dabce6f7051d9e6203e0ba58..0000000000000000000000000000000000000000 --- a/application/middleware_sample/mcs_65ldemo/common/inc/mcs_carrier_process.h +++ /dev/null @@ -1,96 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_carrier_process.h - * @author MCU Algorithm Team - * @brief This file provides functions declaration for carrier interrupt processing function. - */ -#ifndef McuMagicTag_MCS_CARRIER_PROCESS_H -#define McuMagicTag_MCS_CARRIER_PROCESS_H - -#include "mcs_sys_status.h" -#include "mcs_mtr_param.h" -#include "mcs_fsm.h" -#include "mcs_svpwm.h" -#include "mcs_curr_ctrl.h" -#include "mcs_if_ctrl.h" -#include "mcs_ramp_mgmt.h" -#include "mcs_spd_ctrl.h" -#include "mcs_fosmo.h" -#include "mcs_pll.h" -#include "mcs_startup.h" -#include "mcs_r1_svpwm.h" - -typedef void (*MCS_ReadCurrUvwCb)(UvwAxis *CurrUvw); -typedef void (*MCS_SetPwmDutyCb)(UvwAxis *dutyUvwLeft, UvwAxis *dutyUvwRight); -typedef void (*MCS_SetADCTriggerTimeCb)(unsigned short cntCmpSOCA, unsigned short cntCmpSOCB); - -/** - * @brief Sampling mode. - */ -typedef enum { - THREE_RESISTORS = 0, - SINGLE_RESISTOR = 1 -} SampleMode; - -/** - * @brief Motor control data structure - */ -typedef struct { - float spdCmdHz; /**< External input speed command value */ - short axisAngle; /**< Angle of the synchronous coordinate system, used for coordinate transformation */ - float spdRefHz; /**< Command value after speed ramp management */ - float currCtrlPeriod; /**< current loop control period */ - unsigned short aptMaxcntCmp; /**< Apt Maximum Comparison Count */ - - unsigned short sysTickCnt; /**< System Timer Tick Count */ - unsigned short capChargeTickNum; /**< Bootstrap Capacitor Charge Tick Count */ - volatile unsigned int msTickCnt; /**< Millisecond-level counter, which can be used in 1-ms and 5-ms tasks. */ - unsigned short msTickNum; /**< Number of ticks corresponding to 1 ms */ - - SysStatusReg statusReg; /**< System status */ - volatile FsmState stateMachine; /**< Motor Control State Machine */ - - SampleMode sampleMode; /**< sample mode */ - MtrParamHandle mtrParam; /**< Motor parameters */ - FoSmoHandle smo; /**< SMO observer handle */ - IfHandle ifCtrl; /**< I/F control handle */ - SvpwmHandle sv; /**< SVPWM Handle */ - R1SvpwmHandle r1Sv; /**< Single-resistance phase-shifted SVPWM handld */ - RmgHandle spdRmg; /**< Ramp management struct for the speed controller input reference */ - SpdCtrlHandle spdCtrl; /**< Speed loop Control Handle */ - CurrCtrlHandle currCtrl; /**< Current loop control handle */ - StartupHandle startup; /**< Startup Switch Handle */ - - DqAxis currRefDq; /**< Command value of the dq axis current */ - UvwAxis currUvw; /**< Three-phase current sampling value */ - AlbeAxis currAlbe; /**< αβ-axis current feedback value */ - DqAxis currDq; /**< Current feedback value of the dq axis */ - DqAxis vdq; /**< Current loop output dq voltage */ - AlbeAxis vab; /**< Current loop output voltage αβ */ - UvwAxis dutyUvw; /**< UVW three-phase duty cycle */ - UvwAxis dutyUvwLeft; /**< Single Resistor UVW Three-Phase Left Duty Cycle */ - UvwAxis dutyUvwRight; /**< Single Resistor UVW Three-Phase Right Duty Cycle*/ - - MCS_ReadCurrUvwCb readCurrUvwCb; /**< Read current callback function */ - MCS_SetPwmDutyCb setPwmDutyCb; /**< Set the duty cycle callback function. */ - MCS_SetADCTriggerTimeCb setADCTriggerTimeCb; /**< Sets the ADC trigger point callback function. */ -} MtrCtrlHandle; - -void MCS_CarrierProcess(MtrCtrlHandle *mtrCtrl); - -#endif \ No newline at end of file diff --git a/application/middleware_sample/mcs_65ldemo/common/inc/mcs_config_motor.h b/application/middleware_sample/mcs_65ldemo/common/inc/mcs_config_motor.h deleted file mode 100644 index a3de7f98a2454841bf08fd1b3860ca5ad511b1dd..0000000000000000000000000000000000000000 --- a/application/middleware_sample/mcs_65ldemo/common/inc/mcs_config_motor.h +++ /dev/null @@ -1,55 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_config_motor.h - * @author MCU Algorithm Team - * @brief This file provides the electromechanical parameters of the tested motor. - */ - -#ifndef McuMagicTag_MCS_CONFIG_MOTOR_H -#define McuMagicTag_MCS_CONFIG_MOTOR_H - -#include "mcs_mtr_param.h" - -/* Typedef definitions ------------------------------------------------------------------------- */ -typedef struct { - /* electromechanical parameters */ - unsigned int mtrNp; /**< numbers of pole pairs */ - float mtrRs; /**< resistor of stator */ - float mtrLd; /**< inductance of D-axis */ - float mtrLq; /**< inductance of Q-axis */ - float mtrPsif; /**< permanent magnet flux */ - float mtrJ; /**< rotor inertia */ - float maxElecSpd; /**< max elec speed */ - float maxCurr; /**< max current */ - /* Encoder parameters */ - unsigned int mtrPPMR; /**< pulse per mechanical round */ - unsigned int zShift; /**< pulse Z shift */ -} MotorConfig; - -typedef struct { - float currPiKp; /**< current loop kp */ - float currPiKi; /**< current loop ki */ - float currPiLimitPu; /**< current loop limit per unit value */ - float spdPiKp; /**< speed loop kp */ - float spdPiKi; /**< speed loop ki */ - float spdPiLimit; /**< speed loop limit */ -} PiCtrlParam; - -void MtrParamInit(MtrParamHandle *handle, const MotorConfig *motorTable); - -#endif diff --git a/application/middleware_sample/mcs_65ldemo/common/inc/mcs_sys_status.h b/application/middleware_sample/mcs_65ldemo/common/inc/mcs_sys_status.h deleted file mode 100644 index 5503700df6e596184b9077b8a8cf28b4971010bb..0000000000000000000000000000000000000000 --- a/application/middleware_sample/mcs_65ldemo/common/inc/mcs_sys_status.h +++ /dev/null @@ -1,188 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_sys_status.h - * @author MCU Algorithm Team - * @brief This file provides functions declaration of system status. - */ - -/* Define to prevent recursive inclusion ------------------------------------------------------- */ -#ifndef McuMagicTag_MCS_SYS_STATUS_H -#define McuMagicTag_MCS_SYS_STATUS_H - -/* Includes ------------------------------------------------------------------------------------ */ -#include "typedefs.h" -#include "mcs_assert.h" - -/* Typedef definitions ------------------------------------------------------------------------- */ -/** - * @brief System status define - */ -typedef union { - unsigned short all; - struct { - unsigned short cmdStart : 1; /**< Indicates that a start system command has been received. */ - unsigned short cmdStop : 1; /**< Indicates that a stop system command has been received. */ - unsigned short isRunning : 1; /**< Indicates that the system is running (enable signal) */ - unsigned short sysError : 1; /**< Indicates that the system reports an error. */ - unsigned short poweron : 1; /**< Indicates that the power-on initialization phase is complete. */ - unsigned short capcharge : 1; /**< Indicates that the bootstrap capacitor charging phase is complete. */ - unsigned short adczero : 1; /**< The current sampling point is reset to zero after power-on. */ - } Bit; -} SysStatusReg; - -/** - * @brief Get status of Bit cmdStart. - * @param sysStatus System status register handle. - * @retval Status of Bit cmdStart. - */ -static inline bool SysGetCmdStart(SysStatusReg *sysStatus) -{ - MCS_ASSERT_PARAM(sysStatus != NULL); - bool ret; - ret = (sysStatus->Bit.cmdStart == 1) ? true : false; - return ret; -} - -/** - * @brief Set Bit cmdStart. - * @param sysStatus System status register handle. - * @retval None. - */ -static inline void SysCmdStartSet(SysStatusReg *sysStatus) -{ - MCS_ASSERT_PARAM(sysStatus != NULL); - sysStatus->Bit.cmdStart = 1; -} - -/** - * @brief Clear Bit cmdStart. - * @param handle System status register handle. - * @retval None. - */ -static inline void SysCmdStartClr(SysStatusReg *sysStatus) -{ - MCS_ASSERT_PARAM(sysStatus != NULL); - sysStatus->Bit.cmdStart = 0; -} - -/** - * @brief Get status of Bit cmdStop. - * @param sysStatus System status register handle. - * @retval Status of Bit cmdStart. - */ -static inline bool SysGetCmdStop(SysStatusReg *sysStatus) -{ - MCS_ASSERT_PARAM(sysStatus != NULL); - bool ret; - ret = (sysStatus->Bit.cmdStop == 1) ? true : false; - return ret; -} - -/** - * @brief Set Bit cmdStop. - * @param sysStatus System status register handle. - * @retval None. - */ -static inline void SysCmdStopSet(SysStatusReg *sysStatus) -{ - MCS_ASSERT_PARAM(sysStatus != NULL); - sysStatus->Bit.cmdStop = 1; -} - -/** - * @brief Clear Bit cmdStop. - * @param sysStatus System status register handle. - * @retval None. - */ -static inline void SysCmdStopClr(SysStatusReg *sysStatus) -{ - MCS_ASSERT_PARAM(sysStatus != NULL); - sysStatus->Bit.cmdStop = 0; -} - -/** - * @brief Get status of Bit isRunning. - * @param sysStatus System status register handle. - * @retval Status of Bit isRunning. - */ -static inline bool SysIsRunning(SysStatusReg *sysStatus) -{ - MCS_ASSERT_PARAM(sysStatus != NULL); - bool ret; - ret = (sysStatus->Bit.isRunning == 1) ? true : false; - return ret; -} - -/** - * @brief Set Bit isRuning. - * @param sysStatus System status register handle. - * @retval None. - */ -static inline void SysRunningSet(SysStatusReg *sysStatus) -{ - MCS_ASSERT_PARAM(sysStatus != NULL); - sysStatus->Bit.isRunning = 1; -} - -/** - * @brief Clear Bit isRuning. - * @param sysStatus System status register handle. - * @retval None. - */ -static inline void SysRunningClr(SysStatusReg *sysStatus) -{ - MCS_ASSERT_PARAM(sysStatus != NULL); - sysStatus->Bit.isRunning = 0; -} - -/** - * @brief Get status of Bit sysError. - * @param sysStatus System status register handle. - * @retval Status of Bit sysError. - */ -static inline bool SysIsError(SysStatusReg *sysStatus) -{ - MCS_ASSERT_PARAM(sysStatus != NULL); - bool ret; - ret = (sysStatus->Bit.sysError == 1) ? true : false; - return ret; -} - -/** - * @brief Set Bit sysError. - * @param sysStatus System status register handle. - * @retval None. - */ -static inline void SysErrorSet(SysStatusReg *sysStatus) -{ - MCS_ASSERT_PARAM(sysStatus != NULL); - sysStatus->Bit.sysError = 1; -} - -/** - * @brief Clear Bit sysError. - * @param sysStatus System status register handle. - * @retval None. - */ -static inline void SysErrorClr(SysStatusReg *sysStatus) -{ - MCS_ASSERT_PARAM(sysStatus != NULL); - sysStatus->Bit.sysError = 0; -} - -#endif diff --git a/application/middleware_sample/mcs_65ldemo/common/src/mcs_carrier_process.c b/application/middleware_sample/mcs_65ldemo/common/src/mcs_carrier_process.c deleted file mode 100644 index be8184a7d29c37c7cd9987f422b61f0b00c32d5f..0000000000000000000000000000000000000000 --- a/application/middleware_sample/mcs_65ldemo/common/src/mcs_carrier_process.c +++ /dev/null @@ -1,134 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_carrier_process.c - * @author MCU Algorithm Team - * @brief This file provides carrier interrupt application for motor control. - */ - -#include "mcs_carrier_process.h" -#include "mcs_math.h" -#include "typedefs.h" -#include "mcs_assert.h" - -/** - * @brief Synchronous rotation coordinate system angle. - * @param mtrCtrl The motor control handle. - * @retval None. - */ -static void MCS_SyncCoorAngle(MtrCtrlHandle *mtrCtrl) -{ - MCS_ASSERT_PARAM(mtrCtrl != NULL); - /* Synchronous rotation coordinate system angle. */ - switch (mtrCtrl->stateMachine) { - case FSM_STARTUP: - /* Current ramp angle is 0. */ - if (mtrCtrl->startup.stage == STARTUP_STAGE_CURR) { - mtrCtrl->axisAngle = 0; - } else if (mtrCtrl->startup.stage == STARTUP_STAGE_SPD) { /* IF control phase angle self-addition. */ - mtrCtrl->axisAngle = IF_CurrAngleCalc(&mtrCtrl->ifCtrl, mtrCtrl->spdRefHz); - } else if (mtrCtrl->startup.stage == STARTUP_STAGE_SWITCH) { /* Switch Angle */ - mtrCtrl->axisAngle = mtrCtrl->smo.elecAngle; - } - break; - - case FSM_RUN: - mtrCtrl->axisAngle = mtrCtrl->smo.elecAngle; - break; - - default: - mtrCtrl->axisAngle = 0; - break; - } -} - -/** - * @brief PWM waveform setting and sampling point setting for a single resistors and three resistors. - * @param mtrCtrl The motor control handle. - * @retval None. - */ -static void MCS_PwmAdcSet(MtrCtrlHandle *mtrCtrl) -{ - MCS_ASSERT_PARAM(mtrCtrl != NULL); - SampleMode sampleMode = mtrCtrl->sampleMode; - /* Set the duty cycle according to the sampling mode. */ - if (sampleMode == THREE_RESISTORS) { - SVPWM_Exec(&mtrCtrl->sv, &mtrCtrl->vab, &mtrCtrl->dutyUvw); - mtrCtrl->setPwmDutyCb(&mtrCtrl->dutyUvw, &mtrCtrl->dutyUvw); - } else if (sampleMode == SINGLE_RESISTOR) { - R1SVPWM_Exec(&mtrCtrl->r1Sv, &mtrCtrl->vab, &mtrCtrl->dutyUvwLeft, &mtrCtrl->dutyUvwRight); - mtrCtrl->setPwmDutyCb(&mtrCtrl->dutyUvwLeft, &mtrCtrl->dutyUvwRight); - /* The ADC sampling point position needs to be set based on the phase shift of a single resistors. */ - mtrCtrl->setADCTriggerTimeCb(mtrCtrl->r1Sv.samplePoint[0] * mtrCtrl->aptMaxcntCmp, \ - mtrCtrl->r1Sv.samplePoint[1] * mtrCtrl->aptMaxcntCmp); - } -} - -/** - * @brief Carrier interrupt function. - * @param mtrCtrl The motor control handle. - * @retval None. - */ -void MCS_CarrierProcess(MtrCtrlHandle *mtrCtrl) -{ - MCS_ASSERT_PARAM(mtrCtrl != NULL); - UvwAxis *currUvw = &mtrCtrl->currUvw; - AlbeAxis *currAlbe = &mtrCtrl->currAlbe; - AlbeAxis *vab = &mtrCtrl->vab; - SampleMode sampleMode = mtrCtrl->sampleMode; - - if (sampleMode > SINGLE_RESISTOR || mtrCtrl->setADCTriggerTimeCb == NULL) { - return; - } - - if (mtrCtrl->setPwmDutyCb == NULL || mtrCtrl->readCurrUvwCb == NULL) { - return; - } - /* Read the three-phase current value. */ - mtrCtrl->readCurrUvwCb(currUvw); - /* Clark Calc */ - ClarkeCalc(currUvw, currAlbe); - - /* Smo observation */ - FOSMO_Exec(&mtrCtrl->smo, currAlbe, vab, mtrCtrl->spdRefHz); - /* Synchronization angle */ - MCS_SyncCoorAngle(mtrCtrl); - - /* Park transformation */ - ParkCalc(currAlbe, mtrCtrl->axisAngle, &mtrCtrl->currDq); - - /* statemachine */ - switch (mtrCtrl->stateMachine) { - case FSM_STARTUP: - case FSM_RUN: - CURRCTRL_Exec(&mtrCtrl->currCtrl, &mtrCtrl->vdq); - InvParkCalc(&mtrCtrl->vdq, mtrCtrl->axisAngle, vab); - MCS_PwmAdcSet(mtrCtrl); - break; - - case FSM_CAP_CHARGE: - case FSM_CLEAR: - case FSM_IDLE: - break; - - default: - vab->alpha = 0.0f; - vab->beta = 0.0f; - MCS_PwmAdcSet(mtrCtrl); - break; - } -} \ No newline at end of file diff --git a/application/middleware_sample/mcs_65ldemo/common/src/mcs_config_motor.c b/application/middleware_sample/mcs_65ldemo/common/src/mcs_config_motor.c deleted file mode 100644 index 504968a3566ec68d8c70c9033cda05d628461121..0000000000000000000000000000000000000000 --- a/application/middleware_sample/mcs_65ldemo/common/src/mcs_config_motor.c +++ /dev/null @@ -1,48 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_config_motor.c - * @author MCU Algorithm Team - * @brief This file provides the electromechanical parameters of the tested motor. - */ - -#include "mcs_config_motor.h" -#include "mcs_assert.h" - -/** - * @brief Initialzer of motor parameters. - * @param mtrParamHandle Motor parameters handle. - * @param motorTable Motor parameters table handle. - * @retval None. - */ -void MtrParamInit(MtrParamHandle *mtrParamHandle, const MotorConfig *motorTable) -{ - MCS_ASSERT_PARAM(mtrParamHandle != NULL); - MCS_ASSERT_PARAM(motorTable != NULL); - /* Initialzer of motor parameters */ - mtrParamHandle->mtrRs = motorTable->mtrRs; /* resistor of stator */ - mtrParamHandle->mtrLd = motorTable->mtrLd; /* inductance of D-axis */ - mtrParamHandle->mtrLq = motorTable->mtrLq; /* inductance of Q-axis */ - /* Average inductance, mtrLs = (mtrLd + mtrLq) * 0.5f */ - mtrParamHandle->mtrLs = (motorTable->mtrLd + motorTable->mtrLq) * 0.5f; - mtrParamHandle->mtrPsif= motorTable->mtrPsif; /* permanent magnet flux */ - mtrParamHandle->mtrNp = motorTable->mtrNp; /* numbers of pole pairs */ - mtrParamHandle->mtrJ = motorTable->mtrJ; /* rotor inertia */ - mtrParamHandle->maxElecSpd = motorTable->maxElecSpd; /* max elec speed */ - mtrParamHandle->maxCurr = motorTable->maxCurr; /* max current */ - mtrParamHandle->maxTrq = 0.0f; -} \ No newline at end of file diff --git a/application/middleware_sample/mcs_65ldemo/inc/mcs_61h48.h b/application/middleware_sample/mcs_65ldemo/inc/mcs_61h48.h deleted file mode 100644 index cf141751dbd48d1325d72ec676f1c18d91b46a76..0000000000000000000000000000000000000000 --- a/application/middleware_sample/mcs_65ldemo/inc/mcs_61h48.h +++ /dev/null @@ -1,42 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_61h48.h - * @author MCU Algorithm Team - * @brief This file provides motor sample functions declaration for AD101LDMA board - */ -#include "main.h" - -extern GPIO_Handle g_Led; -extern TIMER_Handle g_sysTickTimer; -extern APT_Handle g_aptUcp; -extern APT_Handle g_aptVcp; -extern APT_Handle g_aptWcp; -extern ADC_Handle g_adc; -extern ACMP_Handle g_acmp1; - -/** - * @brief phase sequence. - */ -typedef enum { - PHASE_U = 0, - PHASE_V, - PHASE_W, - PHASE_MAX_NUM -} MCS_PhaseEnum; - -int Main61H48(void); diff --git a/application/middleware_sample/mcs_65ldemo/inc/mcs_config_61h48.h b/application/middleware_sample/mcs_65ldemo/inc/mcs_config_61h48.h deleted file mode 100644 index 18e7608e947ac263da743a00d80fbc38944ff6fe..0000000000000000000000000000000000000000 --- a/application/middleware_sample/mcs_65ldemo/inc/mcs_config_61h48.h +++ /dev/null @@ -1,60 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_config_61h48.h - * @author MCU Algorithm Team - * @brief This file provides config macros for 61demo app. - */ -#ifndef McuMagicTag_MCS_61H48_H -#define McuMagicTag_MCS_61H48_H - -#include "debug.h" -#include "typedefs.h" - -#define INV_CAP_CHARGE_MS 3u -#define INV_VOLTAGE_BUS 24.0f /* Bus voltage, V */ - -#define CTRL_CURR_PERIOD 0.0001f /* carrier ISR period */ -#define CTRL_SYSTICK_PERIOD 0.0005f /* systick control period */ - -/** Duty of sample window, the real time is 0.06*50us = 3us. */ -#define SAMPLE_WINDOW_DUTY 0.06f - -/** Duty of sample point shift as flip point, the real time is 0.008*50us = 0.4us. */ -#define SAMPLE_POINT_SHIFT 0.008f - -/* SMO */ -#define SPEED_FILTER_CUTOFF_FREQUENCY 40.0f -#define FOSMO_GAIN 10.0f -#define FILTER_ANGLE_COMPENSATION 4826 - -/* User_Commond */ -#define CTRL_IF_CURR_AMP_A 1.0f /* IF control current amplitude */ -/* 0.008055 Sampling resistance20 Ohm Sampling resistance 100mOhm 0.001611f */ -#define ADC_CURR_COFFI_CP 0.001611f -#define USER_TARGET_SPD_HZ (100.0f) /* Parentheses are used to enter negative instructions */ -#define USER_SWITCH_SPDBEGIN_HZ (70.0f) /* Start of handover interval */ -#define USER_SWITCH_SPDEND_HZ (73.0f) /* End of handover period */ - -#define USER_SPD_SLOPE 15.0f /* slope of velocity change */ -#define USER_CURR_SLOPE (CTRL_IF_CURR_AMP_A * 0.5f) /* Current change slope */ - -/* Service Definition */ -#define PTC_RELAY_DELAY 2 -#define MOTOR_START_DELAY 10 - -#endif /* McuMagicTag_MCS_61H48_H */ diff --git a/application/middleware_sample/mcs_65ldemo/src/mcs_61h48.c b/application/middleware_sample/mcs_65ldemo/src/mcs_61h48.c deleted file mode 100644 index eb7a9481d4d8dd327f79452fb2a5db780e82684e..0000000000000000000000000000000000000000 --- a/application/middleware_sample/mcs_65ldemo/src/mcs_61h48.c +++ /dev/null @@ -1,765 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_61h48.c - * @author MCU Algorithm Team - * @brief This file provides motor application for AD101LDMA board. - * @details Single FOC application based on the AD101LDMA VER.A board - * 1) The motor model is JMC 42JSF630AS-1000. - * 2) Select the Motorcontrolsystem example in the sample column of chipConfig and click Generate Code. - * 3) The AD101LDMA VER.A board is a high-voltage board, its power supply must be changed to 24V. - */ -#include "mcs_61h48.h" -#include "mcs_config_61h48.h" -#include "mcs_math_const.h" -#include "mcs_math.h" -#include "mcs_config_motor.h" -#include "mcs_carrier_process.h" - -#define MHZ 1000000u - -#define SYSTICK_PERIOD_US 500u /* systick period */ -/* APT module interrupt priority. */ -#define EVT_INTERRUPT_PRIORITY 7 -#define TMR_INTERRUPT_PRIORITY 6 -#define SYS_TMR_INTERRUPT_PRIORITY IRQ_PRIO_LOWEST -/* Use sync-out pulse from APT_U as the sync-in source for slave APT module. */ -#define APT_SYNC_IN_SRC APT_SYNCIN_SRC_APT0_SYNCOUT - -/* Define of OC Event selection */ -#define APT_OC_ENABLE BASE_CFG_ENABLE - -#define APT_U_CP APT0_BASE /* Base address of U phase APT module */ -#define APT_V_CP APT1_BASE /* Base address of V phase APT module */ -#define APT_W_CP APT2_BASE /* Base address of W phase APT module */ - -#define APT_TMR_IRQ IRQ_APT0_TMR - -#define POE_EVENT_PROTECT 0 -#define ACMP_EVENT_PROTECT 1 - -#define POE_ACMP_EVENT_PROTECT ACMP_EVENT_PROTECT - -/** - * Output control event polarity for IPM. - * APT_EM_EVENT_POLARITY_NOT_INVERT (High active) - * APT_EM_EVENT_POLARITY_INVERT (Low active) - */ -#define PROTECT_EVENT_POLARITY_CP APT_EM_EVENT_POLARITY_INVERT - -#define APT_EVT_IRQ_CP IRQ_APT0_EVT - -/* Some configuration values of APT modules. */ -#define APT_PWM_FREQ 10000 /* Set PWM frequency to 10KHz. */ -#define APT_DUTY_MAX (HAL_CRG_GetIpFreq(APT_U_CP) / (APT_PWM_FREQ * 2)) -#define APT_DIVIDER_FACTOR 1 /* The APT clock is not divided. */ -#define DB_US 1.5f /* Dead-Band time, in units of us */ - -#define MICROSECOND_NUM_PER_MILLISECOND 1000 -#define ANGLE_RANGE_ABS 65536 -#define ANGLE_360_F 65536.0f /* 0 - 65536 indicates 0 to 360. */ -#define APT_FULL_DUTY 1.0f - -void ISR_Systick(void *param); -void ISR_Carrier(void *aptHandle); -void ISR_OverCurrProt(void *aptHandle); - -/* Motor parameters. */ -static MotorConfig g_MotorParam[1] = { - {4, 0.5f, 0.000295f, 0.000295f, 0.0f, 0.0f, 200.0f, 4.0f, 4000, 410}, /* Wildfire 24V */ -}; - -/* Motor PI param. */ -static PiCtrlParam g_motorPiParam[1] = { - /* currKp,ki, limitPu, spdKp, ki, limit */ - {0.7414f, 0.1256f, 1.0f, 0.0105f, 0.000003f, 1.0f}, /* Wildfire 24V */ -}; - -static void *g_aptCp[PHASE_MAX_NUM] = {APT_U_CP, APT_V_CP, APT_W_CP}; - -/* Motor control handle for compressor */ -static MtrCtrlHandle g_mc; - -/** - * @brief Initialzer of system tick. - * @param mtrCtrl Motor control struct handle. - * @retval None. - */ -static void TimerTickInit(MtrCtrlHandle *mtrCtrl) -{ - mtrCtrl->sysTickCnt = 0; - mtrCtrl->msTickNum = MICROSECOND_NUM_PER_MILLISECOND / SYSTICK_PERIOD_US; - mtrCtrl->capChargeTickNum = (INV_CAP_CHARGE_MS * MICROSECOND_NUM_PER_MILLISECOND / SYSTICK_PERIOD_US); -} - -/** - * @brief Initialzer of Current controller. - * @param currHandle Current control handle. - * @param mtrCtrl Motor control handle. - * @param piCtrlTable Dual loop control parameters. - * @retval None. - */ -static void CurrCtrlInit(CurrCtrlHandle *currHandle, MtrCtrlHandle *mtrCtrl, const PiCtrlParam *piCtrlTable) -{ - currHandle->currRef = &mtrCtrl->currRefDq; - currHandle->currFdbk = &mtrCtrl->currDq; - currHandle->currFf.d = 0.0f; - currHandle->currFf.q = 0.0f; - - PID_Reset(&currHandle->dAxisPi); /* clear d-axis PI param */ - - PID_Reset(&currHandle->qAxisPi); /* clear q-axis PI param */ - - currHandle->outLimit = 0.0f; - currHandle->mtrParam = &(mtrCtrl->mtrParam); - currHandle->ctrlPeriod = mtrCtrl->currCtrlPeriod; - - currHandle->dAxisPi.kp = piCtrlTable->currPiKp; - currHandle->dAxisPi.ki = piCtrlTable->currPiKi; - currHandle->qAxisPi.kp = piCtrlTable->currPiKp; - currHandle->qAxisPi.ki = piCtrlTable->currPiKi; - currHandle->outLimit = INV_VOLTAGE_BUS * ONE_DIV_SQRT3 * piCtrlTable->currPiLimitPu; /* output voltage limit */ - currHandle->dAxisPi.upperLimit = currHandle->outLimit; - currHandle->dAxisPi.lowerLimit = -currHandle->outLimit; - currHandle->qAxisPi.upperLimit = currHandle->outLimit; - currHandle->qAxisPi.lowerLimit = -currHandle->outLimit; -} - -/** - * @brief Initialzer of speed control struct handle. - * @param spdHandle Speed control struct handle. - * @param piCtrlTable PI controller parameter table. - * @retval None. - */ -static void SpdCtrlInit(SpdCtrlHandle *spdHandle, const PiCtrlParam *piCtrlTable) -{ - PID_Reset(&spdHandle->spdPi); /* reset speed loop PI */ - - spdHandle->trqLimit = 0.0f; - spdHandle->mtrParam = NULL; - spdHandle->ctrlPeriod = CTRL_SYSTICK_PERIOD; - /* Initialize the PI parameter of the speed loop. */ - spdHandle->spdPi.kp = piCtrlTable->spdPiKp; - spdHandle->spdPi.ki = piCtrlTable->spdPiKi; - spdHandle->trqLimit = piCtrlTable->spdPiLimit; - spdHandle->spdPi.upperLimit = spdHandle->trqLimit; - spdHandle->spdPi.lowerLimit = -spdHandle->trqLimit; -} - -/** - * @brief Initialzer of Pll struct handle. - * @param pllHandle pll struct handle. - * @retval None. - */ -static void PLL_Init(PllHandle *pllHandle) -{ - float we = 300.0f; /* PLL bandwidth (unit: Hz) */ - /* Reset PLL PID. */ - PID_Reset(&pllHandle->pi); - /* Initializing PLL Parameters. */ - pllHandle->ctrlPeriod = CTRL_CURR_PERIOD; - pllHandle->pi.kp = 1.414f * we; /* sqrt(2) * we */ - pllHandle->pi.ki = we * we * CTRL_CURR_PERIOD; - pllHandle->pi.upperLimit = 5000.0f; /* The upper limit value of the pid comp output. */ - pllHandle->pi.lowerLimit = -pllHandle->pi.upperLimit; - pllHandle->minAmp = 0.1f; /* Minimum value of the input value in case of the divergence of the PLL. */ - pllHandle->freq = 0.0f; - pllHandle->ratio = ANGLE_360_F * CTRL_CURR_PERIOD; - pllHandle->angle = 0; -} - -/** - * @brief Initialzer of Smo control struct handle. - * @param smoHandle Position SMO struct handle. - * @param mtrParam Motor parameter handle. - * @retval None. - */ -static void SmoInit(FoSmoHandle *smoHandle, MtrParamHandle *mtrParam) -{ - smoHandle->mtrParam = mtrParam; - smoHandle->ctrlPeriod = CTRL_CURR_PERIOD; - - smoHandle->a1 = 1.0f - (smoHandle->ctrlPeriod * smoHandle->mtrParam->mtrRs / smoHandle->mtrParam->mtrLd); - smoHandle->a2 = smoHandle->ctrlPeriod / smoHandle->mtrParam->mtrLd; - - smoHandle->kSmo = FOSMO_GAIN; - smoHandle->lambda = 2.0f; /* SMO coefficient of cut-off frequency is 2.0. */ - /* smo angle filcompAngle */ - smoHandle->filCompAngle = FILTER_ANGLE_COMPENSATION; - FOSMO_Clear(smoHandle); - - smoHandle->emfLpfMinFreq = 2.0f; /* The minimum cutoff frequency of the back EMF filter is 2.0. */ - PLL_Init(&smoHandle->pll); - - /* low pass filter cutoff frequency for speed estimation is 40Hz */ - FoLowPassFilterInit(&smoHandle->spdFilter, smoHandle->ctrlPeriod, SPEED_FILTER_CUTOFF_FREQUENCY); -} - -/** - * @brief Init motor control task. - * @retval None. - */ -static void TSK_InitCp(void) -{ - IfCtrlInit ifInitParam; - - g_mc.stateMachine = FSM_IDLE; - g_mc.spdCmdHz = USER_TARGET_SPD_HZ; - g_mc.aptMaxcntCmp = APT_DUTY_MAX; - g_mc.sampleMode = SINGLE_RESISTOR; - - ifInitParam.currSlope = USER_CURR_SLOPE; - ifInitParam.anglePeriod = CTRL_CURR_PERIOD; - ifInitParam.targetAmp = CTRL_IF_CURR_AMP_A; - ifInitParam.stepAmpPeriod = CTRL_SYSTICK_PERIOD; - - IF_Init(&g_mc.ifCtrl, &ifInitParam); - - RMG_Init(&g_mc.spdRmg, CTRL_SYSTICK_PERIOD, USER_SPD_SLOPE); /* Init speed slope */ - - MtrParamInit(&g_mc.mtrParam, &g_MotorParam[0]); - - TimerTickInit(&g_mc); - - SVPWM_Init(&g_mc.sv, INV_VOLTAGE_BUS * ONE_DIV_SQRT3); - - R1SVPWM_Init(&g_mc.r1Sv, INV_VOLTAGE_BUS * ONE_DIV_SQRT3, SAMPLE_POINT_SHIFT, SAMPLE_WINDOW_DUTY); - - g_mc.currCtrlPeriod = CTRL_CURR_PERIOD; /* Init current controller */ - - CurrCtrlInit(&g_mc.currCtrl, &g_mc, &g_motorPiParam[0]); - - SpdCtrlInit(&g_mc.spdCtrl, &g_motorPiParam[0]); /* Init speed controller */ - - SmoInit(&g_mc.smo, &g_mc.mtrParam); /* Init the SMO observer */ - - STARTUP_Init(&g_mc.startup, USER_SWITCH_SPDBEGIN_HZ, USER_SWITCH_SPDEND_HZ); -} - -/** - * @brief Clear historical values of all controller before start-up. - * @param mtrCtrl The motor control handle. - * @retval None. - */ -static void ClearBeforeStartup(MtrCtrlHandle *mtrCtrl) -{ - /* The initial angle is 0. */ - mtrCtrl->axisAngle = 0; - - mtrCtrl->spdRefHz = 0.0f; - /* The initial dq-axis reference current is 0. */ - mtrCtrl->currRefDq.d = 0.0f; - mtrCtrl->currRefDq.q = 0.0f; - - mtrCtrl->vdq.d = 0.0f; - mtrCtrl->vdq.q = 0.0f; - /* Clear Duty Cycle Value. The initial duty cycle is 0.5. */ - mtrCtrl->dutyUvwLeft.u = 0.5f; - mtrCtrl->dutyUvwLeft.v = 0.5f; - mtrCtrl->dutyUvwLeft.w = 0.5f; - mtrCtrl->dutyUvwRight.u = 0.5f; - mtrCtrl->dutyUvwRight.v = 0.5f; - mtrCtrl->dutyUvwRight.w = 0.5f; - - RMG_Clear(&mtrCtrl->spdRmg); /* Clear the history value of speed slope control */ - CURRCTRL_Clear(&mtrCtrl->currCtrl); - IF_Clear(&mtrCtrl->ifCtrl); - SPDCTRL_Clear(&mtrCtrl->spdCtrl); - FOSMO_Clear(&mtrCtrl->smo); - STARTUP_Clear(&mtrCtrl->startup); - R1SVPWM_Clear(&mtrCtrl->r1Sv); -} - -/** - * @brief To set the comparison value of the IGBT single-resistance ADC sampling trigger position - * @param aptx The APT register struct handle. - * @param cntCmpA A Count compare reference of time-base counter. - * @param cntCmpB B Count compare reference of time-base counter. - * @param maxCntCmp Maximum Comparison Value - * @retval None. - */ -static void MCS_SetAdcCompareR1(APT_RegStruct *aptx, unsigned short cntCmpA, - unsigned short cntCmpB, unsigned short maxCntCmp) -{ - unsigned short tmp; - /* Sets the A Count compare reference of time-base counter. */ - tmp = (cntCmpA >= maxCntCmp) ? (maxCntCmp - 1) : cntCmpA; - DCL_APT_SetCounterCompare(aptx, APT_COMPARE_REFERENCE_A, tmp); - /* Sets the B Count compare reference of time-base counter. */ - tmp = (cntCmpB >= maxCntCmp) ? (maxCntCmp - 1) : cntCmpB; - DCL_APT_SetCounterCompare(aptx, APT_COMPARE_REFERENCE_B, tmp); -} - -/** - * @brief Setting the APT Output Duty Cycle. - * @param aptx APT register base address. - * @param leftDuty Left duty cycle. - * @param rightDuty Right duty cycle. - * @retval None. - */ -static void SetPwmDuty(APT_Handle *aptx, float leftDuty, float rightDuty) -{ - unsigned short maxPeriodCnt = aptx->waveform.timerPeriod; - unsigned short cntCmpLeftEdge = (unsigned short)(leftDuty * maxPeriodCnt); - unsigned short cntCmpRightEdge = (unsigned short)(rightDuty * maxPeriodCnt); - /* avoid overflowing */ - cntCmpLeftEdge = (cntCmpLeftEdge > maxPeriodCnt) ? maxPeriodCnt : cntCmpLeftEdge; - cntCmpRightEdge = (cntCmpRightEdge > maxPeriodCnt) ? maxPeriodCnt : cntCmpRightEdge; - HAL_APT_SetPWMDuty(aptx, cntCmpLeftEdge, cntCmpRightEdge); -} - -/** - * @brief Open the three-phase lower pipe. - * @param aptAddr Three-phase APT address pointer. - * @param maxDutyCnt Max duty count. - * @retval None. - */ -static void AptTurnOnLowSidePwm(void **aptAddr, unsigned int maxDutyCnt) -{ - unsigned int dutyCnt; - dutyCnt = maxDutyCnt * APT_FULL_DUTY; - /* Open the three-phase lower pipe */ - for (unsigned int i = 0; i < PHASE_MAX_NUM; i++) { - APT_RegStruct *aptx = (APT_RegStruct *)(aptAddr[i]); - aptx->TC_REFC.BIT.rg_cnt_refch = dutyCnt; - aptx->TC_REFD.BIT.rg_cnt_refdh = dutyCnt; - } -} -/** - * @brief Enable three-phase pwm output. - * @param aptAddr Three-phase APT address pointer. - * @retval None. - */ -static void MotorPwmOutputEnable(void **aptAddr) -{ - for (unsigned int i = 0; i < PHASE_MAX_NUM; i++) { - APT_RegStruct *aptx = (APT_RegStruct *)(aptAddr[i]); - aptx->PG_OUT_FRC.BIT.rg_pga_frc_en = BASE_CFG_UNSET; - aptx->PG_OUT_FRC.BIT.rg_pgb_frc_en = BASE_CFG_UNSET; - } -} -/** - * @brief Disable three-phase pwm output. - * @param aptAddr Three-phase APT address pointer. - * @retval None. - */ -static void MotorPwmOutputDisable(void **aptAddr) -{ - /* Disable three-phase pwm output. */ - for (unsigned int i = 0; i < PHASE_MAX_NUM; i++) { - APT_RegStruct *aptx = (APT_RegStruct *)(aptAddr[i]); - aptx->PG_OUT_FRC.BIT.rg_pga_frc_en = BASE_CFG_SET; - aptx->PG_OUT_FRC.BIT.rg_pgb_frc_en = BASE_CFG_SET; - DCL_APT_ForcePWMOutputLow(aptx); - } -} - -/** - * @brief Smo IF angle difference calculation. - * @param smoElecAngle Smo electrical angle. - * @param ifCtrlAngle IF control angle. - * @retval signed short angle difference. - */ -static signed short SmoIfAngleDiffCalc(signed short smoElecAngle, signed short ifCtrlAngle) -{ - /* Smo IF angle difference calculation */ - signed int tmpS32 = (signed int)(smoElecAngle - ifCtrlAngle); - if (tmpS32 > INT16_MAX) { - tmpS32 -= ANGLE_RANGE_ABS; - } - if (tmpS32 < INT16_MIN) { - tmpS32 += ANGLE_RANGE_ABS; - } - return (signed short)(tmpS32); -} - -/** - * @brief Construct a new mcs startupswitch object - * @param mtrCtrl The motor control handle. - * @retval None. - */ -static void MCS_StartupSwitch(MtrCtrlHandle *mtrCtrl) -{ - StartupHandle *startup = &mtrCtrl->startup; - DqAxis *currRefDq = &mtrCtrl->currRefDq; - float iftargetAmp = mtrCtrl->ifCtrl.targetAmp; - float spdRefHz = mtrCtrl->spdRefHz; - - switch (startup->stage) { - case STARTUP_STAGE_CURR: - if (mtrCtrl->ifCtrl.curAmp >= iftargetAmp) { - /* Stage change */ - currRefDq->q = iftargetAmp; - startup->stage = STARTUP_STAGE_SPD; - } else { - /* current Amplitude increase */ - currRefDq->q = IF_CurrAmpCalc(&mtrCtrl->ifCtrl); - spdRefHz = 0.0f; - } - break; - case STARTUP_STAGE_SPD: - /* current frequency increase */ - if (Abs(spdRefHz) >= startup->spdBegin) { - /* Stage change */ - startup->stage = STARTUP_STAGE_SWITCH; - TrigVal localTrigVal; - TrigCalc(&localTrigVal, SmoIfAngleDiffCalc(mtrCtrl->smo.elecAngle, mtrCtrl->ifCtrl.angle)); - currRefDq->d = iftargetAmp * localTrigVal.sin; - mtrCtrl->startup.initCurr = currRefDq->d; - currRefDq->q = iftargetAmp; - mtrCtrl->spdCtrl.spdPi.integral = iftargetAmp * localTrigVal.cos; - } else { - /* Speed rmg */ - spdRefHz = RMG_Exec(&mtrCtrl->spdRmg, mtrCtrl->spdCmdHz); - } - break; - - case STARTUP_STAGE_SWITCH: - /* Switch from IF to SMO */ - spdRefHz = RMG_Exec(&mtrCtrl->spdRmg, mtrCtrl->spdCmdHz); - currRefDq->d = STARTUP_CurrCal(&mtrCtrl->startup, spdRefHz); - SPDCTRL_Exec(&mtrCtrl->spdCtrl, spdRefHz, mtrCtrl->smo.spdEstHz, &mtrCtrl->currRefDq); - if (spdRefHz >= startup->spdEnd) { - /* Stage change */ - currRefDq->d = 0.0f; - mtrCtrl->stateMachine = FSM_RUN; - } - break; - - default: - break; - } - - mtrCtrl->spdRefHz = spdRefHz; -} - -/** - * @brief Pre-processing of motor status. - * @param statusReg System status. - * @param stateMachine Motor Control Status. - * @retval None. - */ -static void MotorStatePerProc(SysStatusReg *statusReg, volatile FsmState *stateMachine) -{ - /* Get system status */ - if (SysIsError(statusReg)) { - *stateMachine = FSM_FAULT; - } - if (SysGetCmdStop(statusReg)) { - SysCmdStopClr(statusReg); - *stateMachine = FSM_STOP; - } -} - -/** - * @brief Actiong for FSM_CAP_CHARGE status. - * @param mtrCtrl The motor control handle. - * @param stateMachine Motor Control Status. - * @retval None. - */ -static void MCS_CAPChage(MtrCtrlHandle *mtrCtrl, FsmState *stateMachine) -{ - mtrCtrl->sysTickCnt++; - if (mtrCtrl->sysTickCnt == mtrCtrl->capChargeTickNum) { - *stateMachine = FSM_CLEAR; - } -} - -/** - * @brief Actiong for FSM_FAlT status. - * @param statusReg System status. - * @param stateMachine Motor Control Status. - * @retval None. - */ -static void MCS_Fault(SysStatusReg *statusReg, FsmState *stateMachine) -{ - if (SysIsError(statusReg) == false) { - *stateMachine = FSM_IDLE; - } -} - -/** - * @brief System timer tick task.+ - * @param mtrCtrl The motor control handle. - * @param aptAddr Three-phase APT address pointer. - * @retval None. - */ -static void TSK_SystickIsr(MtrCtrlHandle *mtrCtrl, void **aptAddr) -{ - SysStatusReg *statusReg = &mtrCtrl->statusReg; - volatile FsmState *stateMachine = &mtrCtrl->stateMachine; - mtrCtrl->msTickCnt++; - /* Pre-processing of motor status */ - MotorStatePerProc(statusReg, stateMachine); - /* statemachine */ - switch (*stateMachine) { - case FSM_IDLE: - if (SysGetCmdStart(statusReg)) { - SysRunningSet(statusReg); - SysCmdStartClr(statusReg); - mtrCtrl->sysTickCnt = 0; - *stateMachine = FSM_CAP_CHARGE; - /* Preparation for charging the bootstrap capacitor */ - AptTurnOnLowSidePwm(aptAddr, mtrCtrl->aptMaxcntCmp); - /* Out put pwm */ - MotorPwmOutputEnable(aptAddr); - } - break; - - case FSM_CAP_CHARGE: - /* Bootstrap Capacitor Charging Timing */ - MCS_CAPChage(mtrCtrl, stateMachine); - break; - - case FSM_CLEAR: - ClearBeforeStartup(mtrCtrl); - *stateMachine = FSM_STARTUP; - break; - - case FSM_STARTUP: - MCS_StartupSwitch(mtrCtrl); - break; - - case FSM_RUN: - /* Speed ramp control */ - mtrCtrl->spdRefHz = RMG_Exec(&mtrCtrl->spdRmg, mtrCtrl->spdCmdHz); - /* speed loop control */ - SPDCTRL_Exec(&mtrCtrl->spdCtrl, mtrCtrl->spdRefHz, mtrCtrl->smo.spdEstHz, &mtrCtrl->currRefDq); - break; - - case FSM_STOP: - MotorPwmOutputDisable(aptAddr); - SysRunningClr(statusReg); - *stateMachine = FSM_IDLE; - break; - - case FSM_FAULT: /* Overcurrent state */ - MCS_Fault(statusReg, stateMachine); - break; - default: - break; - } -} -/** - * @brief Obtaining the Three-Phase Current of the Compressor. - * @param CurrUvw Three-phase current data return pointer. - */ -static void ReadCurrUvwCp(UvwAxis *CurrUvw) -{ - float iBusSocA, iBusSocB; - iBusSocA = (float)(HAL_ADC_GetConvResult(&g_adc, ADC_SOC_NUM8) - 2086.0f) * ADC_CURR_COFFI_CP; - iBusSocB = (float)(HAL_ADC_GetConvResult(&g_adc, ADC_SOC_NUM9) - 2086.0f) * ADC_CURR_COFFI_CP; - R1CurrReconstruct(g_mc.r1Sv.voltIndexLast, iBusSocA, iBusSocB, CurrUvw); -} - -/** - * @brief Compressor Duty Cycle Setting. - * @param dutyUvwLeft Three-phase left duty cycle. - * @param dutyUvwRight Three-phase right duty cycle. - * @retval None. - */ -static void SetPwmDutyCp(UvwAxis *dutyUvwLeft, UvwAxis *dutyUvwRight) -{ - SetPwmDuty(&g_aptUcp, dutyUvwLeft->u, dutyUvwRight->u); - SetPwmDuty(&g_aptVcp, dutyUvwLeft->v, dutyUvwRight->v); - SetPwmDuty(&g_aptWcp, dutyUvwLeft->w, dutyUvwRight->w); -} - -/** - * @brief To set the ADC sampling trigger comparison value. - * @param cntCmpSOCA Soca Compare Count Value. - * @param cntCmpSOCB Socb Compare Count Value. - * @retval None. - */ -static void SetADCTriggerTimeCp(unsigned short cntCmpSOCA, unsigned short cntCmpSOCB) -{ - MCS_SetAdcCompareR1(g_aptCp[PHASE_U], cntCmpSOCA, cntCmpSOCB, g_mc.aptMaxcntCmp); -} - - -/** - * @brief System timer ISR function. - * @param param The systick timer handle. - * @retval None. - */ -void ISR_Systick(void *param) -{ - TIMER_Handle *timer = (TIMER_Handle *)param; - TIMER_ASSERT_PARAM(timer != NULL); - TIMER_ASSERT_PARAM(timer->baseAddress != NULL); - /* Clear timer interrupt. */ - HAL_TIMER_IrqClear(timer); - TSK_SystickIsr(&g_mc, g_aptCp); -} - - -volatile float g_mc_u, g_mc_v, g_mc_w; -volatile int g_tracevalue_ref = 1; -/** - * @brief Timer interrupt callback function of U phase APT module. - * @param aptHandle APT module handle. - * @retval None. - */ -void ISR_Carrier(void *aptHandle) -{ - /* the carrierprocess */ - MCS_CarrierProcess(&g_mc); - g_mc_u = g_mc.currUvw.u; - g_mc_v = g_mc.currUvw.v; - g_mc_w = g_mc.currUvw.w; - int tmp = g_tracevalue_ref; - BASE_FUNC_UNUSED(aptHandle); -} - -/** - * @brief Event interrupt callback function of APT module. - * @param aptHandle APT module handle. - * @retval None. - */ -void ISR_OverCurrProt(void *aptHandle) -{ - APT_Handle *apt = (APT_Handle *)aptHandle; - if (apt->irqNumEvt == APT_EVT_IRQ_CP) { - /* The IPM overcurrent triggers and disables the three-phase PWM output. */ - MotorPwmOutputDisable(g_aptCp); - DCL_APT_ClearOutCtrlEventFlag((APT_RegStruct *)g_aptCp[PHASE_U], APT_OC_COMBINE_EVENT_A1); - DCL_APT_ClearOutCtrlEventFlag((APT_RegStruct *)g_aptCp[PHASE_V], APT_OC_COMBINE_EVENT_A1); - DCL_APT_ClearOutCtrlEventFlag((APT_RegStruct *)g_aptCp[PHASE_W], APT_OC_COMBINE_EVENT_A1); - /* Status setting error */ - SysErrorSet(&g_mc.statusReg); - DBG_PRINTF("APT_EVT_IRQ\r\n"); - } else { - DBG_PRINTF("ISR_OverCurrProt\r\n"); - } - HAL_GPIO_TogglePin(&g_Led, GPIO_PIN_6); -} - -/** - * @brief Init motor controller's data structure. - * @retval None. - */ -static void InitSoftware(void) -{ - /* Initializing Compressor and Fan Control Tasks */ - TSK_InitCp(); - /* MCU peripheral configuration function used for initial motor control */ - g_mc.readCurrUvwCb = ReadCurrUvwCp; - g_mc.setPwmDutyCb = SetPwmDutyCp; - g_mc.setADCTriggerTimeCb = SetADCTriggerTimeCp; -} - -/** - * @brief Switch motor running status. - * @param mtrCtrl The motor control handle. - */ -static void GetExternalParam(MtrCtrlHandle *mtrCtrl) -{ - BASE_FUNC_UNUSED(mtrCtrl->spdCmdHz); /* Externally controlled motor speed, Control motor speed */ -} - -/** - * @brief Initial configuration of the underlying driver. - * @retval None. - */ -__weak void MCS_SystemInit(void) -{ -} -/** - * @brief Confit the master APT. - * @param aptx The master APT handle. - * @retval None. - */ -static void AptMasterSet(APT_Handle *aptx) -{ - MCS_ASSERT_PARAM(aptx != NULL); - /* Confit the master APT. */ - HAL_APT_MasterSyncInit(aptx, APT_SYNC_OUT_ON_CNTR_ZERO); -} - -/** - * @brief Config the slave APT. - * @param aptx The slave APT handle. - * @retval None. - */ -static void AptSalveSet(APT_Handle *aptx) -{ - MCS_ASSERT_PARAM(aptx != NULL); - APT_SlaveSyncIn slave; - /* Config the slave APT. */ - slave.divPhase = 0; - slave.cntPhase = 0; - slave.syncCntMode = APT_COUNT_MODE_AFTER_SYNC_UP; - slave.syncInSrc = APT_SYNC_IN_SRC; - slave.cntrSyncSrc = APT_CNTR_SYNC_SRC_SYNCIN; - HAL_APT_SlaveSyncInit(aptx, &slave); -} - -/** - * @brief Configuring Master and Slave APTs. - * @retval None. - */ -static void AptMasterSalveSet(void) -{ - /* Compressor fan APT master/slave synchronization */ - AptMasterSet(&g_aptUcp); - AptSalveSet(&g_aptVcp); - AptSalveSet(&g_aptWcp); -} - -/** - * @brief User application entry. - * @retval BSP_OK. - */ -int Main61H48(void) -{ - SystemInit(); - AptMasterSalveSet(); - HAL_TIMER_Start(&g_sysTickTimer); - /* Disable PWM output before startup. */ - MotorPwmOutputDisable(g_aptCp); - /* Software initialization. */ - InitSoftware(); - /* Start the PWM clock. */ - HAL_APT_StartModule(RUN_APT0 | RUN_APT1 | RUN_APT2); - - unsigned int tickNum_1ms = 2; /* 1ms tick */ - static unsigned int tickCnt_1ms = 0; - - unsigned int tickNum_500ms = 1000; /* 500ms tick */ - static unsigned int tickCnt_500ms = 0; - - BASE_FUNC_DELAY_S(MOTOR_START_DELAY); - SysCmdStartSet(&g_mc.statusReg); /* start motor */ - - while (1) { - if (g_mc.msTickCnt - tickCnt_1ms >= tickNum_1ms) { - tickCnt_1ms = g_mc.msTickCnt; - if (g_mc.stateMachine == FSM_RUN || - g_mc.stateMachine == FSM_STARTUP) { - } - } - - if (g_mc.msTickCnt - tickCnt_500ms >= tickNum_500ms) { - if (SysIsError(&g_mc.statusReg) != true) { - /* The LED blinks when no status is not error. */ - HAL_GPIO_TogglePin(&g_Led, G_LED_PIN); - } - tickCnt_500ms = g_mc.msTickCnt; - } - } - return 0; -} \ No newline at end of file diff --git a/application/middleware_sample/pmsm_sensorless_1shunt_foc/inc/mcs_config.h b/application/middleware_sample/pmsm_sensorless_1shunt_foc/inc/mcs_config.h deleted file mode 100644 index 848337d235e076eb0ec53abadb65358585a1ad81..0000000000000000000000000000000000000000 --- a/application/middleware_sample/pmsm_sensorless_1shunt_foc/inc/mcs_config.h +++ /dev/null @@ -1,76 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_config.h - * @author MCU Algorithm Team - * @brief This file provides config macros for ECMCU105H app. - */ -#ifndef McuMagicTag_MCS_CONFIG_H -#define McuMagicTag_MCS_CONFIG_H - -#include "debug.h" -#include "typedefs.h" - -#define SMO4TH - -#define SYSTICK_PERIOD_US 500u /* systick period */ - -#define INV_CAP_CHARGE_MS 3u - -#define INV_VOLTAGE_BUS 12.0f /* Bus voltage, V */ - -#define CTRL_CURR_PERIOD 0.0001f /* carrier ISR period, 100us */ -#define CTRL_SYSTICK_PERIOD 0.0005f /* systick control period, 500us */ - -/* Duty of sample window, the real time is 0.06*50us = 3us. */ -#define SAMPLE_WINDOW_DUTY 0.06f - -/* Duty of sample point shift as flip point, the real time is 0.008*50us = 0.4us. */ -#define SAMPLE_POINT_SHIFT 0.008f - -/* SMO */ -#define SPEED_FILTER_CUTOFF_FREQUENCY 40.0f -#define FILTER_ANGLE_COMPENSATION 4826 -/* Sampling resistance 200mOhm 0.0013295 */ -#define ADC_CURR_COFFI_CP 0.0013295f /* 3.3/4096/3.03/0.2 pga: 3.03, 200mohm */ -/* APT */ -#define APT_SYNC_IN_SRC APT_SYNCIN_SRC_APT0_SYNCOUT - -#define APT_U_CP APT0_BASE /* Base address of U phase APT module */ -#define APT_V_CP APT1_BASE /* Base address of V phase APT module */ -#define APT_W_CP APT2_BASE /* Base address of W phase APT module */ - - -#define FOSMO_GAIN 1.5f -/* User_Commond */ -#define CTRL_IF_CURR_AMP_A 0.12f /* IF control current amplitude */ -#define USER_TARGET_SPD_HZ (100.0f) /* Parentheses are used to enter negative instructions */ -#define USER_SWITCH_SPDBEGIN_HZ (30.0f) /* Start of handover interval */ -#define USER_SWITCH_SPDEND_HZ (33.0f) /* End of handover period */ -#define USER_MAX_SPD_HZ 180.25 -#define USER_SPD_SLOPE 100.0f /* slope of velocity change */ -#define USER_CURR_SLOPE (CTRL_IF_CURR_AMP_A * 40.0f) /* Current change slope */ - - -/* Service Definition */ -#define MOTOR_START_DELAY 100 -#define ADC_READINIT_DELAY 200 -#define ADC_READINIT_TIMES 20 -#define ADC_TRIMVALUE_MIN 2020.0 -#define ADC_TRIMVALUE_MAX 2080.0 - -#endif \ No newline at end of file diff --git a/application/middleware_sample/pmsm_sensorless_1shunt_foc/inc/mcs_motor.h b/application/middleware_sample/pmsm_sensorless_1shunt_foc/inc/mcs_motor.h deleted file mode 100644 index 21b66279baae1cf4f16c9c561c9742b3ad165702..0000000000000000000000000000000000000000 --- a/application/middleware_sample/pmsm_sensorless_1shunt_foc/inc/mcs_motor.h +++ /dev/null @@ -1,52 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_motor.h - * @author MCU Algorithm Team - * @brief This file provides the electromechanical parameters of the tested motor. - */ - -#ifndef McuMagicTag_MCS_MOTOR_H -#define McuMagicTag_MCS_MOTOR_H - -#include "mcs_mtr_param.h" - -/* Typedef definitions ------------------------------------------------------------------------- */ -typedef struct { - /* electromechanical parameters */ - unsigned int mtrNp; /**< numbers of pole pairs */ - float mtrRs; /**< resistor of stator */ - float mtrLd; /**< inductance of D-axis */ - float mtrLq; /**< inductance of Q-axis */ - float mtrPsif; /**< permanent magnet flux */ - float mtrJ; /**< rotor inertia */ - float maxElecSpd; /**< max elec speed */ - float maxCurr; /**< max current */ -} MotorConfig; - -typedef struct { - float currPiKp; /**< current loop kp */ - float currPiKi; /**< current loop ki */ - float currPiLimitPu; /**< current loop limit per unit value */ - float spdPiKp; /**< speed loop kp */ - float spdPiKi; /**< speed loop ki */ - float spdPiLimit; /**< speed loop limit */ -} PiCtrlParam; - -void MtrParamInit(MtrParamHandle *handle, const MotorConfig *motorTable); - -#endif diff --git a/application/middleware_sample/pmsm_sensorless_1shunt_foc/readme.txt b/application/middleware_sample/pmsm_sensorless_1shunt_foc/readme.txt deleted file mode 100644 index a97714e0da6a8c769e5251f93be66daad3aae842..0000000000000000000000000000000000000000 --- a/application/middleware_sample/pmsm_sensorless_1shunt_foc/readme.txt +++ /dev/null @@ -1,4 +0,0 @@ -ʾơpmsm_sensorless_1shunt_foc -˵ECMCU105Hĵ˫FOCӦ -Ҫ󡿣õԴΪʾõ12VѹѡGimbal GBM2804H-100T -IDE÷chipConfigеsampleĿѡpmsm sensorless 1shunt focʾȻɴ뼴 \ No newline at end of file diff --git a/application/middleware_sample/pmsm_sensorless_1shunt_foc/src/mcs_motor.c b/application/middleware_sample/pmsm_sensorless_1shunt_foc/src/mcs_motor.c deleted file mode 100644 index d7f371f06c104ad473af3716c97aaf522fdcaa67..0000000000000000000000000000000000000000 --- a/application/middleware_sample/pmsm_sensorless_1shunt_foc/src/mcs_motor.c +++ /dev/null @@ -1,48 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_motor.c - * @author MCU Algorithm Team - * @brief This file provides the electromechanical parameters of the tested motor. - */ - -#include "mcs_motor.h" -#include "mcs_assert.h" - -/** - * @brief Initialzer of motor parameters. - * @param mtrParamHandle Motor parameters handle. - * @param motorTable Motor parameters table handle. - * @retval None. - */ -void MtrParamInit(MtrParamHandle *mtrParamHandle, const MotorConfig *motorTable) -{ - MCS_ASSERT_PARAM(mtrParamHandle != NULL); - MCS_ASSERT_PARAM(motorTable != NULL); - /* Initialzer of motor parameters */ - mtrParamHandle->mtrRs = motorTable->mtrRs; /* resistor of stator */ - mtrParamHandle->mtrLd = motorTable->mtrLd; /* inductance of D-axis */ - mtrParamHandle->mtrLq = motorTable->mtrLq; /* inductance of Q-axis */ - /* Average inductance, mtrLs = (mtrLd + mtrLq) * 0.5f */ - mtrParamHandle->mtrLs = (motorTable->mtrLd + motorTable->mtrLq) * 0.5f; - mtrParamHandle->mtrPsif= motorTable->mtrPsif; /* permanent magnet flux */ - mtrParamHandle->mtrNp = motorTable->mtrNp; /* numbers of pole pairs */ - mtrParamHandle->mtrJ = motorTable->mtrJ; /* rotor inertia */ - mtrParamHandle->maxElecSpd = motorTable->maxElecSpd; /* max elec speed */ - mtrParamHandle->maxCurr = motorTable->maxCurr; /* max current */ - mtrParamHandle->maxTrq = 0.0f; -} \ No newline at end of file diff --git a/application/middleware_sample/pmsm_sensorless_2shunt_foc/inc/mcs_config.h b/application/middleware_sample/pmsm_sensorless_2shunt_foc/inc/mcs_config.h deleted file mode 100644 index 88bc4c718df9b827d431cd479c6796a7166b4892..0000000000000000000000000000000000000000 --- a/application/middleware_sample/pmsm_sensorless_2shunt_foc/inc/mcs_config.h +++ /dev/null @@ -1,77 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_config.h - * @author MCU Algorithm Team - * @brief This file provides config macros for ECMCU105H app. - */ -#ifndef McuMagicTag_MCS_CONFIG_H -#define McuMagicTag_MCS_CONFIG_H - -#include "debug.h" -#include "typedefs.h" - -#define SMO4TH - -#define SYSTICK_PERIOD_US 500u /* systick period */ - -#define INV_CAP_CHARGE_MS 3u - -#define INV_VOLTAGE_BUS 12.0f /* Bus voltage, V */ - -#define CTRL_CURR_PERIOD 0.0001f /* carrier ISR period, 100us */ -#define CTRL_SYSTICK_PERIOD 0.0005f /* systick control period, 500us */ - -/* Duty of sample window, the real time is 0.06*50us = 3us. */ -#define SAMPLE_WINDOW_DUTY 0.06f - -/* Duty of sample point shift as flip point, the real time is 0.008*50us = 0.4us. */ -#define SAMPLE_POINT_SHIFT 0.008f - -/* SMO */ -#define SPEED_FILTER_CUTOFF_FREQUENCY 40.0f -#define FILTER_ANGLE_COMPENSATION 4826 -/* Sampling resistance 200mOhm 0.0013295 */ -#define ADC_CURR_COFFI_CP 0.0013295f /* 3.3/4096/3.03/0.2 pga: 3.03, 200mohm */ -/* APT */ -#define APT_SYNC_IN_SRC APT_SYNCIN_SRC_APT0_SYNCOUT - -#define APT_U_CP APT0_BASE /* Base address of U phase APT module */ -#define APT_V_CP APT1_BASE /* Base address of V phase APT module */ -#define APT_W_CP APT2_BASE /* Base address of W phase APT module */ - - -#define FOSMO_GAIN 1.5f -/* User_Commond */ -#define CTRL_IF_CURR_AMP_A 0.07f /* IF control current amplitude */ -#define USER_TARGET_SPD_HZ (100.0f) /* Parentheses are used to enter negative instructions */ -#define USER_SWITCH_SPDBEGIN_HZ (30.0f) /* Start of handover interval */ -#define USER_SWITCH_SPDEND_HZ (33.0f) /* End of handover period */ -#define USER_MAX_SPD_HZ 180.25 -#define USER_SPD_SLOPE 100.0f /* slope of velocity change */ -#define USER_CURR_SLOPE (CTRL_IF_CURR_AMP_A * 40.0f) /* Current change slope */ - - -/* Service Definition */ -#define ADC_INITREAD_DELAY 5 -#define MOTOR_START_DELAY 50 -#define ADC_READINIT_DELAY 20 -#define ADC_READINIT_TIMES 20 -#define ADC_TRIMVALUE_MIN 1950.0 -#define ADC_TRIMVALUE_MAX 2150.0 - -#endif \ No newline at end of file diff --git a/application/middleware_sample/pmsm_sensorless_2shunt_foc/inc/mcs_motor.h b/application/middleware_sample/pmsm_sensorless_2shunt_foc/inc/mcs_motor.h deleted file mode 100644 index 21b66279baae1cf4f16c9c561c9742b3ad165702..0000000000000000000000000000000000000000 --- a/application/middleware_sample/pmsm_sensorless_2shunt_foc/inc/mcs_motor.h +++ /dev/null @@ -1,52 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_motor.h - * @author MCU Algorithm Team - * @brief This file provides the electromechanical parameters of the tested motor. - */ - -#ifndef McuMagicTag_MCS_MOTOR_H -#define McuMagicTag_MCS_MOTOR_H - -#include "mcs_mtr_param.h" - -/* Typedef definitions ------------------------------------------------------------------------- */ -typedef struct { - /* electromechanical parameters */ - unsigned int mtrNp; /**< numbers of pole pairs */ - float mtrRs; /**< resistor of stator */ - float mtrLd; /**< inductance of D-axis */ - float mtrLq; /**< inductance of Q-axis */ - float mtrPsif; /**< permanent magnet flux */ - float mtrJ; /**< rotor inertia */ - float maxElecSpd; /**< max elec speed */ - float maxCurr; /**< max current */ -} MotorConfig; - -typedef struct { - float currPiKp; /**< current loop kp */ - float currPiKi; /**< current loop ki */ - float currPiLimitPu; /**< current loop limit per unit value */ - float spdPiKp; /**< speed loop kp */ - float spdPiKi; /**< speed loop ki */ - float spdPiLimit; /**< speed loop limit */ -} PiCtrlParam; - -void MtrParamInit(MtrParamHandle *handle, const MotorConfig *motorTable); - -#endif diff --git a/application/middleware_sample/pmsm_sensorless_2shunt_foc/readme.txt b/application/middleware_sample/pmsm_sensorless_2shunt_foc/readme.txt deleted file mode 100644 index 5ad9a7a5a79e6c1ac08d6920d6cdb2d44465b03c..0000000000000000000000000000000000000000 --- a/application/middleware_sample/pmsm_sensorless_2shunt_foc/readme.txt +++ /dev/null @@ -1,4 +0,0 @@ -ʾơpmsm_sensorless_2shunt_foc -˵ECMCU105Hĵ˫FOCӦ -Ҫ󡿣õԴΪʾõ12VѹѡGimbal GBM2804H-100T -IDE÷chipConfigеsampleĿѡpmsm sensorless 2shunt focʾȻɴ뼴 \ No newline at end of file diff --git a/application/middleware_sample/pmsm_sensorless_2shunt_foc/src/mcs_motor.c b/application/middleware_sample/pmsm_sensorless_2shunt_foc/src/mcs_motor.c deleted file mode 100644 index d7f371f06c104ad473af3716c97aaf522fdcaa67..0000000000000000000000000000000000000000 --- a/application/middleware_sample/pmsm_sensorless_2shunt_foc/src/mcs_motor.c +++ /dev/null @@ -1,48 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_motor.c - * @author MCU Algorithm Team - * @brief This file provides the electromechanical parameters of the tested motor. - */ - -#include "mcs_motor.h" -#include "mcs_assert.h" - -/** - * @brief Initialzer of motor parameters. - * @param mtrParamHandle Motor parameters handle. - * @param motorTable Motor parameters table handle. - * @retval None. - */ -void MtrParamInit(MtrParamHandle *mtrParamHandle, const MotorConfig *motorTable) -{ - MCS_ASSERT_PARAM(mtrParamHandle != NULL); - MCS_ASSERT_PARAM(motorTable != NULL); - /* Initialzer of motor parameters */ - mtrParamHandle->mtrRs = motorTable->mtrRs; /* resistor of stator */ - mtrParamHandle->mtrLd = motorTable->mtrLd; /* inductance of D-axis */ - mtrParamHandle->mtrLq = motorTable->mtrLq; /* inductance of Q-axis */ - /* Average inductance, mtrLs = (mtrLd + mtrLq) * 0.5f */ - mtrParamHandle->mtrLs = (motorTable->mtrLd + motorTable->mtrLq) * 0.5f; - mtrParamHandle->mtrPsif= motorTable->mtrPsif; /* permanent magnet flux */ - mtrParamHandle->mtrNp = motorTable->mtrNp; /* numbers of pole pairs */ - mtrParamHandle->mtrJ = motorTable->mtrJ; /* rotor inertia */ - mtrParamHandle->maxElecSpd = motorTable->maxElecSpd; /* max elec speed */ - mtrParamHandle->maxCurr = motorTable->maxCurr; /* max current */ - mtrParamHandle->maxTrq = 0.0f; -} \ No newline at end of file diff --git a/board/key/inc/matrixkey.h b/board/key/inc/matrixkey.h deleted file mode 100644 index 6482b9ad15cb912581399ad7ee5d20b416862b72..0000000000000000000000000000000000000000 --- a/board/key/inc/matrixkey.h +++ /dev/null @@ -1,103 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file matrixkey.h - * @author MCU Application Team - * @brief Include the header file of the matrixkey.c file. - */ - -/* Define to prevent recursive inclusion ------------------------------------- */ -#ifndef McuMagicTag_MATRIXKEY_H -#define McuMagicTag_MATRIXKEY_H - -/* Includes ------------------------------------------------------------------ */ -#include "baseinc.h" -#include "timer.h" -#include "gpio.h" - -#ifdef MKEY_PARAM_CHECK -#define MKEY_ASSERT_PARAM BASE_FUNC_ASSERT_PARAM -#define MKEY_PARAM_CHECK_NO_RET BASE_FUNC_PARAMCHECK_NO_RET -#define MKEY_PARAM_CHECK_WITH_RET BASE_FUNC_PARAMCHECK_WITH_RET -#else -#define MKEY_ASSERT_PARAM(para) ((void)0U) -#define MKEY_PARAM_CHECK_NO_RET(para) ((void)0U) -#define MKEY_PARAM_CHECK_WITH_RET(para, ret) ((void)0U) -#endif - -/* Macro definitions --------------------------------------------------------- */ -/** Solution 1 : Proactively process keystroke events. The interrupt processing \ - function scans the I/O port. When the key press tick reaches the press \ - threshold, the key registration function is invoked in the interrupt. This \ - function applies to scenarios where the key event execution time is short. \ - Advantage: It is easy to invoke. When the while loop in main is long, this \ - method responds to keys in real time. */ -#define BOARD_MKEY_SCHEME_NUMBER_ONE 0 -/** Solution 2: Passively process keystroke events. The interrupt processing \ - function scans I/O ports and counts ticks. The main function polls tick \ - values in the while loop. When the threshold is reached, the registration \ - function is called. Advantage: The interrupt function processing period is \ - reduced. */ -#define BOARD_MKEY_SCHEME_NUMBER_TWO 1 - -/* Typedef definitions ------------------------------------------------------- */ -/** - * @brief Function return type definition. - */ -typedef enum { - BOARD_MKEY_RET_OK = 0x00000000U, - BOARD_MKEY_RET_INVALID_PARAM = 0x00000001U -} BOARD_MKEY_RET; - -/** - * @brief GPIO group and Pin definition. - */ -typedef struct { - GPIO_RegStruct *gpiox; /**< GPIO register. */ - unsigned int pins; /**< Pin value. */ -} GPIO_MKEY_PinInfo; - -typedef void (*MKeyHandleFun)(void); - -/** - * @brief Key attribute definition. - */ -typedef struct { - unsigned int tick; /**< Current key press count. */ - MKeyHandleFun fun; /**< Function pointer bound when a key event is triggered. */ -} GPIO_MKEY_KeyInfo; - -/** - * @brief Matrix key handle. - */ -typedef struct { - GPIO_MKEY_PinInfo outPins[BOARD_MKEY_OUT_NUM]; /**< GPIO pin used as output during scanning. */ - GPIO_MKEY_PinInfo inPins[BOARD_MKEY_IN_NUM]; /**< GPIO pin used as input during scanning. */ - GPIO_MKEY_KeyInfo keyInfo[BOARD_MKEY_OUT_NUM * BOARD_MKEY_IN_NUM]; /**< Stores information about each key. */ -} BOARD_MKEY_Handle; - -/* Exported global functions ------------------------------------------------- */ -void BOARD_MKEY_Init(TIMER_Handle *timerHandle, unsigned int validPressTimeMs); -BOARD_MKEY_RET BOARD_MKEY_ConfigOutputPin(GPIO_RegStruct *gpiox, unsigned int pins, unsigned int index); -BOARD_MKEY_RET BOARD_MKEY_ConfigInputPin(GPIO_RegStruct *gpiox, unsigned int pins, unsigned int index); -BOARD_MKEY_RET BOARD_MKEY_RegisterKeyFun(unsigned int keyNum, MKeyHandleFun fun); -void BOARD_MKEY_TimerCallBack(void *param); -#if (BOARD_MKEY_SCHEME_NUMBER == BOARD_MKEY_SCHEME_NUMBER_TWO) -void BOARD_MKEY_SCAN_KEY(void); -#endif - -#endif /* McuMagicTag_MATRIXKEY_H */ \ No newline at end of file diff --git a/board/key/src/matrixkey.c b/board/key/src/matrixkey.c deleted file mode 100644 index c654817176139c241d8bf9a58d183471c3b75469..0000000000000000000000000000000000000000 --- a/board/key/src/matrixkey.c +++ /dev/null @@ -1,223 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file matrixkey.c - * @author MCU Application Team - * @brief Dynamic key scanning module application. - * @details This file provides firmware functions to manage the following - * functionalities of the Dynamic key scanning. - * + Initialization functions. - * + Pin configuration and key event registration function. - * @verbatim - * usage: - * 1) Use the chip config tool to generate the timer/gpt initialization code. - * 2) Call the BOARD_MKEY_Init() function to select the specified TIMER and set Key valid values. - * 3) Call the BOARD_MKEY_ConfigOutputPin() and BOARD_MKEY_ConfigInputPin() function to set pins. - * 4) Call the BOARD_MKEY_RegisterKeyFun() to register the key triggering event. - * 5) Start the corresponding TIMER to monitor the key press status. - * 6) Note: If BOARD_MKEY_SCHEME_NUMBER_TWO is used, the BOARD_MKEY_SCAN_KEY() function should be called in the main - * function while loop to complete key scanning. - * The pin numbers of the Key matrix are as follows: - * out1 | key1 key2 key3 key4 - * | - * out2 | key5 key6 key7 key8 - * | - * out3 | key9 key10 key11 key12 - * | - * out4 | key13 key14 key15 key16 - * |-------------------------------- - * in1 in2 in3 in4 - * @endverbatim - */ - -/* Includes ------------------------------------------------------------------ */ -#include "matrixkey.h" - -/* Private variables --------------------------------------------------------- */ -BOARD_MKEY_Handle g_mKeyInfo; /**< Matrix key array. */ -static unsigned int g_mKeyValidTick; /**< Number of ticks for which keys take effect. */ -static const unsigned int g_mKeyTotalKeyNumber = BOARD_MKEY_IN_NUM * BOARD_MKEY_OUT_NUM; /**< Total number of keys. */ - -/** - * @brief Initialization function, setting the timer and key validity period (ms). - * @param timerHandle Timer handle. - * @param validPressTimeMs Key validity period, in milliseconds. - */ -void BOARD_MKEY_Init(TIMER_Handle *timerHandle, unsigned int validPressTimeMs) -{ - MKEY_ASSERT_PARAM(timerHandle != NULL); - - g_mKeyValidTick = validPressTimeMs; - - unsigned int loadVal = HAL_CRG_GetIpFreq((void *)timerHandle->baseAddress) / 1000; /* 1000: get cycles in 1 ms. */ - timerHandle->load = loadVal; - timerHandle->bgLoad = loadVal; - HAL_TIMER_Config(timerHandle, TIMER_CFG_LOAD); - HAL_TIMER_Config(timerHandle, TIMER_CFG_BGLOAD); - HAL_TIMER_RegisterCallback(timerHandle, BOARD_MKEY_TimerCallBack); - - for (unsigned int i = 0; i < g_mKeyTotalKeyNumber; i++) { - g_mKeyInfo.keyInfo[i].fun = NULL; - g_mKeyInfo.keyInfo[i].tick = 0; - } -} - -/** - * @brief Configuring GPIO for Output. - * @param gpiox GPIO group: GPIO0, GPIO1, GPIO2... - * @param pins Specific pin value. - * @param index Specifies the index value, in [0, BOARD_MKEY_OUT_NUM). - * @return BOARD_MKEY_RET @ref BOARD_MKEY_RET. - */ -BOARD_MKEY_RET BOARD_MKEY_ConfigOutputPin(GPIO_RegStruct *gpiox, unsigned int pins, unsigned int index) -{ - MKEY_ASSERT_PARAM(gpiox != NULL); - MKEY_PARAM_CHECK_WITH_RET((index < BOARD_MKEY_OUT_NUM), BOARD_MKEY_RET_INVALID_PARAM); - - g_mKeyInfo.outPins[index].gpiox = gpiox; - g_mKeyInfo.outPins[index].pins = pins; - DCL_GPIO_SetDirection(gpiox, pins, GPIO_OUTPUT_MODE); - DCL_GPIO_SetValue(gpiox, pins, BOARD_MKEY_OUT_PIN_INVALID); - - return BOARD_MKEY_RET_OK; -} - -/** - * @brief Configuring GPIO for Input. - * @param gpiox GPIO group: GPIO0, GPIO1, GPIO2... - * @param pins Specific pin value. - * @param index Specifies the index value, in [0, BOARD_MKEY_In_NUM). - * @return BOARD_MKEY_RET @ref BOARD_MKEY_RET. - */ -BOARD_MKEY_RET BOARD_MKEY_ConfigInputPin(GPIO_RegStruct *gpiox, unsigned int pins, unsigned int index) -{ - MKEY_ASSERT_PARAM(gpiox != NULL); - MKEY_PARAM_CHECK_WITH_RET((index < BOARD_MKEY_IN_NUM), BOARD_MKEY_RET_INVALID_PARAM); - - g_mKeyInfo.inPins[index].gpiox = gpiox; - g_mKeyInfo.inPins[index].pins = pins; - DCL_GPIO_SetDirection(gpiox, pins, GPIO_INPUT_MODE); - DCL_GPIO_SetValue(gpiox, pins, BOARD_MKEY_IN_PIN_INVALID); - - return BOARD_MKEY_RET_OK; -} - -/** - * @brief Registering the Key Binding Function. - * @param keyNum Key Number.Calculated based on the input and output index values. - * @param fun Key function pointer. - * @return BOARD_MKEY_RET @ref BOARD_MKEY_RET. - */ -BOARD_MKEY_RET BOARD_MKEY_RegisterKeyFun(unsigned int keyNum, MKeyHandleFun fun) -{ - MKEY_ASSERT_PARAM(fun != NULL); - MKEY_PARAM_CHECK_WITH_RET((keyNum < g_mKeyTotalKeyNumber), BOARD_MKEY_RET_INVALID_PARAM); - - g_mKeyInfo.keyInfo[keyNum].fun = fun; - return BOARD_MKEY_RET_OK; -} - -/** - * @brief Disable all output GPIOs. - */ -static void BOARD_MKEY_TurnOffOutPin(void) -{ - for (int i = 0; i < BOARD_MKEY_OUT_NUM; i++) { - MKEY_PARAM_CHECK_NO_RET(g_mKeyInfo.outPins[i].gpiox); - DCL_GPIO_SetValue(g_mKeyInfo.outPins[i].gpiox, g_mKeyInfo.outPins[i].pins, BOARD_MKEY_OUT_PIN_INVALID); - } -} - -#if (BOARD_MKEY_SCHEME_NUMBER == BOARD_MKEY_SCHEME_NUMBER_ONE) -/** - * @brief Timer callback function. Determines the status of each key and executes the registration event according to - * the status. - * @param irqNum Interrupt number. - * @param param Pointer to the timer handle. - */ -void BOARD_MKEY_TimerCallBack(void *param) -{ - TIMER_Handle *handle = (TIMER_Handle *)param; - HAL_TIMER_IrqClear(handle); - - for (unsigned int i = 0; i < BOARD_MKEY_OUT_NUM; i++) { - BOARD_MKEY_TurnOffOutPin(); - DCL_GPIO_SetValue(g_mKeyInfo.outPins[i].gpiox, g_mKeyInfo.outPins[i].pins, BOARD_MKEY_OUT_PIN_VALID); - for (unsigned int j = 0; j < BOARD_MKEY_IN_NUM; j++) { - unsigned int tmp = i * BOARD_MKEY_IN_NUM + j; - GPIO_Value value = DCL_GPIO_GetPinValue(g_mKeyInfo.inPins[j].gpiox, g_mKeyInfo.inPins[j].pins); - if (value == BOARD_MKEY_IN_PIN_VALID) { - g_mKeyInfo.keyInfo[tmp].tick++; - continue; - } - if (g_mKeyInfo.keyInfo[tmp].tick >= g_mKeyValidTick && g_mKeyInfo.keyInfo[tmp].fun) { - g_mKeyInfo.keyInfo[tmp].fun(); - } - g_mKeyInfo.keyInfo[tmp].tick = 0; - } - } -} -#endif - -#if (BOARD_MKEY_SCHEME_NUMBER == BOARD_MKEY_SCHEME_NUMBER_TWO) -/** - * @brief Timer callback function. Check the status of each key and update the tick value. - * @param irqNum Interrupt number. - * @param param Pointer to the timer handle. - */ -void BOARD_MKEY_TimerCallBack(void *param) -{ - TIMER_Handle *handle = (TIMER_Handle *)param; - HAL_TIMER_IrqClear(handle); - - for (int i = 0; i < BOARD_MKEY_OUT_NUM; i++) { - BOARD_MKEY_TurnOffOutPin(); - DCL_GPIO_SetValue(g_mKeyInfo.outPins[i].gpiox, g_mKeyInfo.outPins[i].pins, BOARD_MKEY_OUT_PIN_VALID); - for (int j = 0; j < BOARD_MKEY_IN_NUM; j++) { - int tmp = i * BOARD_MKEY_IN_NUM + j; - int gpioVal = DCL_GPIO_GetPinValue(g_mKeyInfo.inPins[j].gpiox, g_mKeyInfo.inPins[j].pins); - if (gpioVal == BOARD_MKEY_IN_PIN_VALID && g_mKeyInfo.keyInfo[tmp].tick < g_mKeyValidTick) { - g_mKeyInfo.keyInfo[tmp].tick++; - continue; - } - if (gpioVal == BOARD_MKEY_IN_PIN_INVALID && g_mKeyInfo.keyInfo[tmp].tick < g_mKeyValidTick) { - g_mKeyInfo.keyInfo[tmp].tick = 0; - continue; - } - if (gpioVal == BOARD_MKEY_IN_PIN_INVALID && g_mKeyInfo.keyInfo[tmp].tick == g_mKeyValidTick) { - g_mKeyInfo.keyInfo[tmp].tick++; - } - } - } -} - -/** - * @brief Scans the key tick value and executes the binding function when the value reaches the threshold. - * This function is called in the main loop. - */ -void BOARD_MKEY_SCAN_KEY(void) -{ - for (unsigned int i = 0; i < g_mKeyTotalKeyNumber; i++) { - if (g_mKeyInfo.keyInfo[i].tick > g_mKeyValidTick) { - g_mKeyInfo.keyInfo[i].tick = 0; - if (g_mKeyInfo.keyInfo[i].fun) { - g_mKeyInfo.keyInfo[i].fun(); - } - } - } -} -#endif \ No newline at end of file diff --git a/build/build_check.py b/build/build_check.py deleted file mode 100644 index 12c391bf2218ed77aaa5e06a9c14fd6c0b914bb2..0000000000000000000000000000000000000000 --- a/build/build_check.py +++ /dev/null @@ -1,641 +0,0 @@ -#!/usr/bin/env python3 -# coding=utf-8 - -''' -# @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. -# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the -# following conditions are met: -# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following -# disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the -# following disclaimer in the documentation and/or other materials provided with the distribution. -# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote -# products derived from this software without specific prior written permission. -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE -# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -''' - -import os -import stat -import sys -import json -import configparser -import subprocess -import tarfile -import zipfile -import shutil -import pathlib - - -def set_bool_parameter(parameter, value, compile_parameter): - ''' - Function description: Set bool parameter, yes is true, no is false - ''' - - if parameter == "yes": - if value not in compile_parameter: - compile_parameter.append(value) - else: - if value in compile_parameter: - compile_parameter.remove(value) - - -def un_alltools(file_name): - ''' - Function description: Decompress all compilation tools. - ''' - if len(str(file_name)) > 256: - print("Error!!!! The file path string is too long(256): ", file_name) - return - - for word in file_name: - if '.' in word: - suffix = file_name.split('.')[-1] - if suffix in ('gz', 'tar'): - untar(file_name) - elif suffix == 'zip': - unzip(file_name) - break - - -def untar(file_name): - ''' - Function description: Decompress the tar or tar.gz file. - ''' - - head, tail = os.path.split(file_name) - cur_path = os.path.join(head, tail.split('.')[0]) - - if not os.path.exists(cur_path): - with tarfile.open(file_name) as tar: - tar.extractall(os.path.dirname(cur_path)) - - -def unzip(file_name): - ''' - Function description: Decompress the zip file. - ''' - - max_size = 1 * 1024 * 1024 * 500 - cur_size = 0 - - with zipfile.ZipFile(file_name) as zip_file: - head, tail = os.path.split(file_name) - file_name = os.path.join(head, tail.split('.')[0]) - - if not os.path.isdir(file_name): - os.mkdir(file_name) - - for names in zip_file.infolist(): - cur_size += names.file_size - if cur_size > max_size: - break - zip_file.extract(names.filename, file_name) - - -def config_toolchain(tool_path, sdk_path): - files1 = (os.listdir(tool_path)) - files2 = (os.listdir(sdk_path)) - files1.sort() - files2.sort() - - for item in files2: - if item not in files1: - source = os.path.join(sdk_path, item) - if os.path.isdir(source): - continue - target = os.path.join(tool_path, item) - shutil.copyfile(source, target) - un_alltools(target) - - gn_path = os.path.join(tool_path, "gn-win", "gn.exe") - gnzip_path = os.path.join(tool_path, "gn-win.zip") - if not os.path.exists(gn_path): - un_alltools(gnzip_path) - - ninja_path = os.path.join(tool_path, "ninja-win", "ninja.exe") - ninjazip_path = os.path.join(tool_path, "ninja-win.zip") - if not os.path.exists(ninja_path): - un_alltools(ninjazip_path) - - -def config_download_toolchain(tool_path): - del_list = [f for f in os.listdir(tool_path)] - for f in del_list: - file_path = os.path.join(tool_path, f) - if os.path.isdir(file_path): - shutil.rmtree(file_path) - - cc_riscv32_win_env_tar_gz_path = os.path.join( - tool_path, "cc_riscv32_win_env.tar.gz") - un_alltools(cc_riscv32_win_env_tar_gz_path) - - cc_riscv32_musl_win_tar_gz_path = os.path.join( - tool_path, "cc_riscv32_musl_win.tar.gz") - un_alltools(cc_riscv32_musl_win_tar_gz_path) - - cc_riscv32_musl_fp_win_tar_gz_path = os.path.join( - tool_path, "cc_riscv32_musl_fp_win.tar.gz") - un_alltools(cc_riscv32_musl_fp_win_tar_gz_path) - - gnzip_path = os.path.join(tool_path, "gn-win.zip") - un_alltools(gnzip_path) - - ninjazip_path = os.path.join(tool_path, "ninja-win.zip") - un_alltools(ninjazip_path) - - path1 = os.path.join(tool_path, "bundle.json") - path2 = os.path.join(tool_path, "LICENSE") - path3 = os.path.join(tool_path, "README.md") - if os.path.exists(path1): - os.remove(path1) - if os.path.exists(path2): - os.remove(path2) - if os.path.exists(path3): - os.remove(path3) - - -def config_win_env(tool_path): - source = os.path.join(tool_path, "cc_riscv32_win_env") - if not os.path.exists(source): - return - - target1 = os.path.join(tool_path, "cc_riscv32_musl_fp_win\\bin") - target2 = os.path.join(tool_path, "cc_riscv32_musl_win\\bin") - src_files = os.listdir(source) - for file_name in src_files: - full_file_name = os.path.join(source, file_name) - if not os.path.isfile(full_file_name): - continue - if os.path.exists(target1): - shutil.copy(full_file_name, target1) - if os.path.exists(target2): - shutil.copy(full_file_name, target2) - - -def config_gdb_env(tool_path): - tool_chain = ["cc_riscv32_musl_fp_win", "cc_riscv32_musl_win"] - rename_bin = [ - ["riscv32-linux-musl-gdb.exe", "riscv32-unknown-elf-gdb.exe"], - ["riscv32-linux-musl-objdump.exe", "riscv32-unknown-elf-objdump.exe"] - ] - - for tool in tool_chain: - for bins in rename_bin: - old = os.path.join(tool_path, tool, "bin", bins[0]) - new = os.path.join(tool_path, tool, "bin", bins[1]) - - if os.path.exists(old) and not os.path.exists(new): - shutil.copyfile(old, new) - - -def convert_file_to_path(includes): - path = [i for i in includes.replace('\n', '').split(",") if i != ''] - - for i, item in enumerate(path): - if os.path.isfile(item): - path[i] = os.path.dirname(item) - return list(set(path)) - - -def convert_file_to_path_extern(includes, cur_path): - # Processing Path - path = [i for i in includes.replace('\n', '').split(",") if i != ''] - # Process only paths outside the project - path = [i for i in path if cur_path not in i] - - if not path: - return path - - for i, item in enumerate(path): - if os.path.isfile(item): - path[i] = os.path.dirname(item) - - return list(set(path)) - - -class CompileParameter: - optimization = '' - warning = '' - werror = '' - wno_unused_function = '' - wno_unused_label = '' - wno_unused_parameter = '' - wno_unused_variable = '' - fstack = '' - - def __init__(self): - pass - - def set_optimization(self, config): - self.optimization = config - - def set_warnning(self, config): - self.warnning = config - - def set_werror(self, config): - self.werror = config - - def set_function(self, config): - self.wno_unused_function = config - - def set_label(self, config): - self.wno_unused_label = config - - def set_parameter(self, config): - self.wno_unused_parameter = config - - def set_variable(self, config): - self.wno_unused_variable = config - - def set_fstack(self, config): - self.fstack = config - - @staticmethod - def set_generate_crc(value): - deveco_path = 'build/config.ini' - if not os.path.exists(deveco_path): - return - - config = configparser.ConfigParser() - config.read(deveco_path) - - if not config.has_section('gn_args'): - return - - config.set('gn_args', 'gen_crc', value) - modes = stat.S_IWUSR | stat.S_IRUSR - flags = os.O_RDWR | os.O_CREAT - config.write(os.fdopen(os.open(deveco_path, flags, modes), 'w')) - - - @staticmethod - def set_build_type(build_type): - command = 'python build/build.py -b ' + build_type - process = subprocess.Popen(command, shell=False) - process.wait() - - @staticmethod - def check_toolchain(sdk_path): - ide_path = ".deveco-device-tool/compiler_tool_chain/Windows" - tool_path = os.path.join(os.path.expanduser("~"), ide_path) - sdk_path = os.path.join(sdk_path, "tools/toolchain/Windows") - ninja_exe_path = os.path.join(tool_path, "ninja-win", "ninja.exe") - # check toolchain - all_times = 3 - times = 0 - if not os.path.exists(sdk_path): - for times in range(0, all_times): - if not os.path.exists(ninja_exe_path): - config_download_toolchain(tool_path) - config_win_env(tool_path) - config_gdb_env(tool_path) - times += 1 - else: - return - if not os.path.exists(ninja_exe_path): - print("Packages in " + tool_path + - " are damaged! Please manually delete and rebuild!") - return - - if not os.path.exists(os.path.dirname(tool_path)): - os.mkdir(os.path.dirname(tool_path)) - if not os.path.exists(tool_path): - os.mkdir(tool_path) - else: - if check_tool_chain_md5(sdk_path, tool_path): - return - - config_toolchain(tool_path, sdk_path) - config_win_env(tool_path) - config_gdb_env(tool_path) - - @staticmethod - def set_toolchain(toolchian, build_type): - if toolchian == 'cc_riscv32_musl_fp_win': - command = 'python build/build.py -t hcc_fpu -b' + build_type - else: - command = 'python build/build.py -t hcc -b' + build_type - - process = subprocess.Popen(command, shell=False) - process.wait() - - def set_compile_parameter(self): - ''' - Function description: Set compile parameter. - ''' - - file_data = "" - file_path = "chip/target/userconfig.json" - - modes = stat.S_IWUSR | stat.S_IRUSR - flags = os.O_RDWR | os.O_CREAT - with os.fdopen(os.open(file_path, flags, modes), 'r+') as f: - file_data = f.read() - content = json.loads(file_data) - - for subsystem in content["system"][0]["subsystem"]: - if subsystem["name"] != "compile_frame": - continue - - param = subsystem["cflags"] - param[0] = f'-{self.optimization}' - - if self.warnning == "yes": - param[2] = "-Wall" - else: - param[2] = "-w" - - set_bool_parameter( - self.werror, "-Werror", param) - set_bool_parameter( - self.wno_unused_function, "-Wno-unused-function", param) - set_bool_parameter(self.wno_unused_label, - "-Wno-unused-label", param) - set_bool_parameter( - self.wno_unused_parameter, "-Wno-unused-parameter", param) - set_bool_parameter( - self.wno_unused_variable, "-Wno-unused-variable", param) - set_bool_parameter( - self.fstack, "-fstack-protector-strong", param) - - file_data = json.dumps( - content, indent=4, ensure_ascii=False) - - f.seek(0) - f.truncate() - f.write(file_data) - break - - @staticmethod - def set_static_library(enable, name, sources, includes): - ''' - Function description: Set static library. - ''' - file_data = "" - file_path = "chip/target/userconfig.json" - cflags = [] - asmflags = [] - ldflags = [] - - modes = stat.S_IWUSR | stat.S_IRUSR - flags = os.O_RDWR | os.O_CREAT - with os.fdopen(os.open(file_path, flags, modes), 'r+') as f: - file_data = f.read() - content = json.loads(file_data) - - for subsystem in content["system"][0]["subsystem"]: - if subsystem["name"] != "compile_frame": - continue - if enable == "no": - name = "" - sources = "" - includes = "" - continue - - cflags = subsystem["cflags"] - asmflags = subsystem["asmflags"] - ldflags = subsystem["ldflags"] - break - - for subsystem in content["system"][0]["subsystem"]: - if subsystem["name"] != "static_lib": - continue - - for component in subsystem["component"]: - component["cflags"] = cflags - component["asmflags"] = asmflags - component["ldflags"] = ldflags - component["name"] = name - component["sources"] = [i for i in sources.replace( - '\n', '').split(",") if i != ''] - component["includes"] = convert_file_to_path(includes) - - file_data = json.dumps(content, indent=4, ensure_ascii=False) - - f.seek(0) - f.truncate() - f.write(file_data) - - @staticmethod - def set_extern_staticlib_link(libspath, libsinclude): - ''' - Function description: Set static library. - ''' - file_data = "" - file_path = "chip/target/userconfig.json" - ext_path = [] - ext_include = [] - cur_path = str(pathlib.Path.cwd()) - - modes = stat.S_IWUSR | stat.S_IRUSR - flags = os.O_RDWR | os.O_CREAT - with os.fdopen(os.open(file_path, flags, modes), 'r+') as f: - file_data = f.read() - content = json.loads(file_data) - - for subsystem in content["system"][0]["subsystem"]: - if subsystem["name"] != "compile_frame": - continue - - subsystem['extlibspath'] = [] - subsystem['extlibsname'] = [] - subsystem['extlibsinclude'] = [] - - if not libspath: - break - # Processing Path - ext_path = [i for i in libspath.replace( - '\n', '').split(",") if i != ''] - # Process only paths outside the project - ext_path = [i for i in ext_path if cur_path not in i] - if ext_path: - subsystem['extlibspath'] = [os.path.dirname(i) - for i in ext_path] - subsystem['extlibsname'] = [os.path.basename(i) - for i in ext_path] - # List deduplication - subsystem['extlibspath'] = list( - set(subsystem['extlibspath'])) - subsystem['extlibsname'] = list( - set(subsystem['extlibsname'])) - if not libsinclude: - break - subsystem['extlibsinclude'] = convert_file_to_path_extern( - libsinclude, cur_path) - - file_data = json.dumps(content, indent=4, ensure_ascii=False) - - f.seek(0) - f.truncate() - f.write(file_data) - - -def check_tool_chain_md5(sdk_path, tool_path): - tool_name = os.path.join(tool_path, "ninja-win", "ninja.exe") - if not os.path.exists(tool_name): - print("Tool chain is damaged! Repairing in progress.") - del_file(tool_path) - return False - - file_name = os.path.join(sdk_path, "cc_riscv32_musl_fp_win") - if not os.path.exists(file_name): - release_tool_chain(sdk_path) - - sdk_md5 = get_toolchain_md5(os.path.join(file_name, "bin")) - - tool_name = os.path.join(tool_path, "cc_riscv32_musl_fp_win") - tool_zip_name = os.path.join(tool_path, "cc_riscv32_musl_fp_win.tar.gz") - if os.path.exists(tool_zip_name) and os.path.exists(tool_name): - tool_md5 = get_toolchain_md5(os.path.join(tool_name, "bin")) - if sdk_md5 == tool_md5 or\ - sdk_md5 == "noMD5" or\ - tool_md5 == "noMD5": - return True - - del_file(tool_path) - return False - - -def release_tool_chain(sdk_path): - for item in os.listdir(sdk_path): - if "cc_riscv32_musl_fp_win" in item or "cc_riscv32_win_env" in item: - zip_name = os.path.join(sdk_path, item) - if os.path.isdir(zip_name): - continue - un_alltools(zip_name) - - target = os.path.join(sdk_path, "cc_riscv32_musl_fp_win", "bin") - source = os.path.join(sdk_path, "cc_riscv32_win_env") - if not os.path.exists(source): - return - - for file_name in os.listdir(source): - full_file_name = os.path.join(source, file_name) - if not os.path.isfile(full_file_name): - continue - if os.path.exists(target): - shutil.copy(full_file_name, target) - - -def del_file(filepath): - ''' - Delete all files or folders in a directory. - ''' - del_list = [f for f in os.listdir(filepath) if "cc_riscv32" in f] - for f in del_list: - file_path = os.path.join(filepath, f) - if os.path.isfile(file_path): - os.remove(file_path) - elif os.path.isdir(file_path): - shutil.rmtree(file_path) - - -def get_toolchain_md5(target_path): - cur_path = pathlib.Path.cwd() - - if not os.path.exists(target_path): - return "noMD5" - - os.chdir(target_path) - # Check the MD5 value. - cmd = ['certutil', '-hashfile', 'riscv32-linux-musl-gcc.exe', 'md5'] - out_bytes = subprocess.check_output(cmd, shell=False) - os.chdir(cur_path) - return out_bytes - - -def extern_static_library(env, config, param): - ''' - Function description: Linking External Static Libraries. - ''' - - if 'extern_staticlib_path' in config[env] and \ - 'extern_staticlib_include' in config[env]: - param.set_extern_staticlib_link( - config[env]['extern_staticlib_path'], - config[env]['extern_staticlib_include']) - - -def fix_warning(config, env, deveco_path): - if 'warnning' in config[env]: - config.set(env, 'warning', config[env]['warnning']) - config.remove_option(env, 'warnning') - modes = stat.S_IWUSR | stat.S_IRUSR - flags = os.O_RDWR | os.O_CREAT - with os.fdopen(os.open(deveco_path, flags, modes), 'w') as file: - file.seek(0) - file.truncate() - config.write(file) - - -def build_check(argv): - ''' - Function description: check compile parameter and tool chain. - ''' - - if len(argv) < 2: - return - - deveco_path = '.deveco/deveco.ini' - chip = argv[1] - env = "env:" + chip - config = configparser.ConfigParser() - config.read(deveco_path) - - param = CompileParameter() - if 'chip_package_path' in config[env]: - param.check_toolchain(config[env]['chip_package_path']) - - if 'compiler' in config[env] and 'build_type' in config[env]: - param.set_toolchain(config[env]['compiler'], config[env]['build_type']) - - if 'optimization' in config[env] and \ - 'werror' in config[env] and \ - 'wno_unused_function' in config[env] and \ - 'wno_unused_label' in config[env] and \ - 'wno_unused_parameter' in config[env] and \ - 'wno_unused_variable' in config[env] : - - param.set_optimization(config[env]['optimization']) - param.set_werror(config[env]['werror']) - param.set_function(config[env]['wno_unused_function']) - param.set_label(config[env]['wno_unused_label']) - param.set_parameter(config[env]['wno_unused_parameter']) - param.set_variable(config[env]['wno_unused_variable']) - - if 'fstack_protector_strong' in config[env]: - param.set_fstack(config[env]['fstack_protector_strong']) - - fix_warning(config, env, deveco_path) - - if 'warning' in config[env]: - param.set_warnning(config[env]['warning']) - param.set_compile_parameter() - - if 'static_library_enable' in config[env] and \ - 'static_library_name' in config[env] and \ - 'static_library_source_file' in config[env] and \ - 'static_library_dependency_header_file' in config[env]: - param.set_static_library( - config[env]['static_library_enable'], - config[env]['static_library_name'], - config[env]['static_library_source_file'], - config[env]['static_library_dependency_header_file']) - - extern_static_library(env, config, param) - - if 'generate_crc' in config[env]: - param.set_generate_crc(config[env]['generate_crc']) - - elf_path = 'out/bin/elf.json' - if os.path.exists(elf_path): - os.remove(elf_path) - -if __name__ == "__main__": - sys.exit(build_check(sys.argv)) diff --git "a/document/hardware/3065H\351\200\232\347\224\250\347\224\237\346\200\201\346\235\277\347\224\250\346\210\267\346\211\213\345\206\214 V02.pdf" "b/document/hardware/3065H\351\200\232\347\224\250\347\224\237\346\200\201\346\235\277\347\224\250\346\210\267\346\211\213\345\206\214 V02.pdf" deleted file mode 100644 index 739b12dd261e5154749244d601d6f19b9e6da53d..0000000000000000000000000000000000000000 Binary files "a/document/hardware/3065H\351\200\232\347\224\250\347\224\237\346\200\201\346\235\277\347\224\250\346\210\267\346\211\213\345\206\214 V02.pdf" and /dev/null differ diff --git a/drivers/gpt/common/inc/gpt.h b/drivers/gpt/common/inc/gpt.h deleted file mode 100644 index e8d6bb36434118f4b7ff93f40f22bd87da8689f4..0000000000000000000000000000000000000000 --- a/drivers/gpt/common/inc/gpt.h +++ /dev/null @@ -1,93 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file gpt.h - * @author MCU Driver Team - * @brief GPT module driver. - * @details This file provides firmware GPT Handle Structure and functions - * prototypes to manage the following functionalities of the GPT. - * + Initialization and de-initialization functions - * + config the register of GPT - * + interrupt register and register functions - */ - -#ifndef McuMagicTag_GPT_H -#define McuMagicTag_GPT_H - -/* Includes-------------------------------------------------------------------*/ -#include "gpt_ip.h" - -/** - * @defgroup GPT GPT - * @brief GPT module. - * @{ - */ - -/** - * @defgroup GPT_Common GPT Common - * @brief GPT common external module. - * @{ - */ - -/** - * @defgroup GPT_Handle_Definition GPT Handle Definition - * @{ - */ -typedef struct { - GPT_RegStruct *baseAddress; /**< Base address of GPT register */ - unsigned int period; /**< PWM period, unit ns */ - unsigned int duty; /**< PWM duty, unit ns */ - unsigned int pwmNum; /**< PWM number, only valid when pwmKeep is false */ - bool pwmKeep; /**< PWM output mode */ - bool pwmPolarity; /**< PWM output positive and negative control */ - bool pwmEnable; /**< PWM Enable */ -} GPT_Handle; - -/** - * @} - */ - -/** - * @defgroup GPT_API_Declaration GPT HAL API - * @{ - */ -/** - * GPT Extended Control functions - */ -BASE_StatusType HAL_GPT_Init(GPT_Handle *handle); - -BASE_StatusType HAL_GPT_RspInit(GPT_Handle *handle); - -void HAL_GPT_Start(GPT_Handle *handle); - -void HAL_GPT_Stop(GPT_Handle *handle); - -BASE_StatusType HAL_GPT_Config(GPT_Handle *handle); - -BASE_StatusType HAL_GPT_GetConfig(GPT_Handle *handle); -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -#endif /* McuMagicTag_GPT_H */ \ No newline at end of file diff --git a/middleware/control_library/mcs_assert.h b/middleware/control_library/mcs_assert.h deleted file mode 100644 index 81c872379c2d592b4028501aa31706e64498fe3c..0000000000000000000000000000000000000000 --- a/middleware/control_library/mcs_assert.h +++ /dev/null @@ -1,59 +0,0 @@ - -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_assert.h - * @author MCU Algorithm Team - * @brief This file provides functions declaration of the assert. - */ - -/* Define to prevent recursive inclusion ------------------------------------- */ -#ifndef McuMagicTag_MCS_ASSERT_H -#define McuMagicTag_MCS_ASSERT_H - -/* Includes ------------------------------------------------------------------ */ -#include "baseinc.h" - -/** - * @defgroup MCS_ASSERT MCS_ASSERT - * @brief MCS ASSERT module. - * @{ - */ - -/** - * @defgroup ASSERT_Macro ASSERT Macro Function Definition - * @{ - */ - -#ifdef MCS_PARAM_CHECK -#define MCS_ASSERT_PARAM BASE_FUNC_ASSERT_PARAM -#define MCS_PARAM_CHECK_NO_RET BASE_FUNC_PARAMCHECK_NO_RET -#define MCS_PARAM_CHECK_WITH_RET BASE_FUNC_PARAMCHECK_WITH_RET -#else -#define MCS_ASSERT_PARAM(para) ((void)0U) -#define MCS_PARAM_CHECK_NO_RET(para) ((void)0U) -#define MCS_PARAM_CHECK_WITH_RET(para, ret) ((void)0U) -#endif - -/** - * @} - */ - -/** - * @} - */ -#endif \ No newline at end of file diff --git a/middleware/control_library/mcs_curr_ctrl.c b/middleware/control_library/mcs_curr_ctrl.c deleted file mode 100644 index 2edcdba27c0ad6d3b4cd35b6070653a24edf3f28..0000000000000000000000000000000000000000 --- a/middleware/control_library/mcs_curr_ctrl.c +++ /dev/null @@ -1,77 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_curr_ctrl.c - * @author MCU Algorithm Team - * @brief This file provides function of motor current control. - */ - -#include "typedefs.h" -#include "mcs_curr_ctrl.h" -#include "mcs_math_const.h" -#include "mcs_assert.h" - -/** - * @brief Reset the current control handle, fill with zero, NULL. - * @param currHandle The current control handle. - * @retval None. - */ -void CURRCTRL_Reset(CurrCtrlHandle *currHandle) -{ - MCS_ASSERT_PARAM(currHandle != NULL); - /* Reset the current control handle, fill with zero, NULL. */ - currHandle->currRef = NULL; - currHandle->currFdbk = NULL; - currHandle->currFf.d = 0.0f; - currHandle->currFf.q = 0.0f; - currHandle->mtrParam = NULL; - currHandle->outLimit = 0.0f; - currHandle->ctrlPeriod = 0.0f; - /* Reset Dq axis PID current control */ - PID_Reset(&currHandle->dAxisPi); - PID_Reset(&currHandle->qAxisPi); -} - -/** - * @brief Clear historical values of current controller. - * @param currHandle Current controller struct handle. - * @retval None. - */ -void CURRCTRL_Clear(CurrCtrlHandle *currHandle) -{ - MCS_ASSERT_PARAM(currHandle != NULL); - PID_Clear(&currHandle->dAxisPi); - PID_Clear(&currHandle->qAxisPi); -} - -/** - * @brief Simplified current controller PI calculation. - * @param currHandle Current controller struct handle. - * @param voltRef Dq-axis voltage reference which is the output of current controller. - * @retval None. - */ -void CURRCTRL_Exec(CurrCtrlHandle *currHandle, DqAxis *voltRef) -{ - MCS_ASSERT_PARAM(currHandle != NULL); - MCS_ASSERT_PARAM(voltRef != NULL); - /* Calculate the current error of the dq axis. */ - currHandle->dAxisPi.error = currHandle->currRef->d - currHandle->currFdbk->d; - currHandle->qAxisPi.error = currHandle->currRef->q - currHandle->currFdbk->q; - /* Calculation of the PI of the Dq axis current. */ - voltRef->d = PI_Exec(&currHandle->dAxisPi); - voltRef->q = PI_Exec(&currHandle->qAxisPi); -} diff --git a/middleware/control_library/mcs_curr_ctrl.h b/middleware/control_library/mcs_curr_ctrl.h deleted file mode 100644 index 36ebd780adf4e7a4bf977b57108b1b4704277989..0000000000000000000000000000000000000000 --- a/middleware/control_library/mcs_curr_ctrl.h +++ /dev/null @@ -1,79 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_curr_ctrl.h - * @author MCU Algorithm Team - * @brief Current controller for motor control. - * This file provides functions declaration of the current controller module. - */ - -/* Define to prevent recursive inclusion ------------------------------------------------------- */ -#ifndef McuMagicTag_MCS_CURR_CTRL_H -#define McuMagicTag_MCS_CURR_CTRL_H - -/* Includes ------------------------------------------------------------------------------------ */ -#include "mcs_typedef.h" -#include "mcs_pid_ctrl.h" -#include "mcs_mtr_param.h" - -/** - * @defgroup CURRENT_CONTROLLER CURRENT CONTROLLER MODULE - * @brief The current controller function. - * @{ - */ - -/** - * @defgroup CURRENT_CONTROLLER_STRUCT CURRENT CONTROLLER STRUCT - * @brief The current controller's data structure definition. - * @{ - */ - -/* Typedef definitions ------------------------------------------------------------------------- */ -/** - * @brief Current controller struct members and parameters. - */ -typedef struct { - DqAxis *currRef; /**< Current reference in the d-q coordinate (A). */ - DqAxis *currFdbk; /**< Current feedback in the d-q coordinate (A). */ - DqAxis currFf; /**< Current feedforward value (V). */ - PidHandle dAxisPi; /**< d-axis current PI controller. */ - PidHandle qAxisPi; /**< q-axis current PI controller. */ - MtrParamHandle *mtrParam; /**< Motor parameters. */ - float outLimit; /**< Current controller output voltage limitation (V). */ - float ctrlPeriod; /**< Current controller control period (s). */ -} CurrCtrlHandle; -/** - * @} - */ - -/** - * @defgroup CURRENT_CONTROLLER_API CURRENT CONTROLLER API - * @brief The current controller's API declaration. - * @{ - */ -void CURRCTRL_Reset(CurrCtrlHandle *currHandle); -void CURRCTRL_Clear(CurrCtrlHandle *currHandle); -void CURRCTRL_Exec(CurrCtrlHandle *currHandle, DqAxis *voltRef); -/** - * @} - */ - -/** - * @} - */ - -#endif diff --git a/middleware/control_library/mcs_filter.c b/middleware/control_library/mcs_filter.c deleted file mode 100644 index caa1bf2f16cba7cb3f540fcb87979e1c945cf9c7..0000000000000000000000000000000000000000 --- a/middleware/control_library/mcs_filter.c +++ /dev/null @@ -1,77 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_filter.c - * @author MCU Algorithm Team - * @brief This file provides functions of first-order filter. - */ - -#include "mcs_filter.h" -#include "mcs_math_const.h" -#include "mcs_assert.h" - -/** - * @brief Initialzer of first-order low-pass filter handle. - * @param lpfHandle First-order filter handle. - * @param ts Control period (s). - * @param fc Cut-off frequency (Hz). - * @retval None. - */ -void FoLowPassFilterInit(FoFilterHandle *lpfHandle, float ts, float fc) -{ - MCS_ASSERT_PARAM(lpfHandle != NULL); - MCS_ASSERT_PARAM(ts > 0.0f); - MCS_ASSERT_PARAM(fc > 0.0f); - lpfHandle->ctrlPeriod = ts; - lpfHandle->fc = fc; - - FoFilterClear(lpfHandle); - - /* y(k) = (1/(1+wcTs)) * y(k-1) + (wcTs/(1+wcTs)) * u(k) */ - float wcTs = DOUBLE_PI * fc * ts; - lpfHandle->a1 = 1.0f / (1.0f + wcTs); /* wcTs > 0 */ - lpfHandle->b1 = 1.0f - lpfHandle->a1; -} - -/** - * @brief Clear historical values of first-order filter handle. - * @param foFilterHandle First-order filter handle. - * @retval None. - */ -void FoFilterClear(FoFilterHandle *foFilterHandle) -{ - MCS_ASSERT_PARAM(foFilterHandle != NULL); - foFilterHandle->uLast = 0.0f; - foFilterHandle->yLast = 0.0f; -} - -/** - * @brief Calculation method of first-order filter. - * @param lpfHandle First-order filter handle. - * @param u The signal that wants to be filtered. - * @retval The signal that is filered. - */ -float FoLowPassFilterExec(FoFilterHandle *lpfHandle, float u) -{ - MCS_ASSERT_PARAM(lpfHandle != NULL); - float out; - - /* y(k) = (1/(1+wcTs)) * y(k-1) + (wcTs/(1+wcTs)) * u(k) */ - out = lpfHandle->a1 * lpfHandle->yLast + lpfHandle->b1 * u; - lpfHandle->yLast = out; - return out; -} diff --git a/middleware/control_library/mcs_filter.h b/middleware/control_library/mcs_filter.h deleted file mode 100644 index 649019c8a8769352ceea85dbeb6a71e161dc56f0..0000000000000000000000000000000000000000 --- a/middleware/control_library/mcs_filter.h +++ /dev/null @@ -1,75 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_filter.h - * @author MCU Algorithm Team - * @brief filter library. - * This file provides functions declaration of the filter module. - */ - -/* Define to prevent recursive inclusion ------------------------------------------------------- */ -#ifndef McuMagicTag_MCS_FILTER_H -#define McuMagicTag_MCS_FILTER_H - -/** - * @defgroup FILTER FILTER - * @brief Filter module. - * @{ - */ - -/** - * @defgroup FILTER_HANDLE FILTER Struct - * @brief Filter data structure definition. - * @{ - */ - -/* Typedef definitions ------------------------------------------------------------------------- */ -/** - * @brief 1st-order Filter struct members and parameters. - * LPF(low-pass filter): y(k)=a1*y(k-1)+b1*u(k) - * HPF(high-pass filter): y(k)=a1*y(k-1)+b1*u(k)+b2*u(k-1) - */ -typedef struct { - float yLast; /**< Last output of 1st-order filter. */ - float uLast; /**< Last input variable. */ - float fc; /**< 1st-order filter cut-off frequency (Hz). */ - float ctrlPeriod; /**< 1st-order filter running period. */ - float a1; /**< Coefficient of 1st-order filter. */ - float b1; /**< Coefficient of 1st-order filter. */ - float b2; /**< Coefficient of 1st-order filter. */ -} FoFilterHandle; -/** - * @} - */ - -/** - * @defgroup FILTER_API FILTER API - * @brief Filter function API declaration. - * @{ - */ -void FoLowPassFilterInit(FoFilterHandle *lpfHandle, float ts, float fc); -void FoFilterClear(FoFilterHandle *foFilterHandle); -float FoLowPassFilterExec(FoFilterHandle *lpfHandle, float u); -/** - * @} - */ - -/** - * @} - */ - -#endif diff --git a/middleware/control_library/mcs_fosmo.c b/middleware/control_library/mcs_fosmo.c deleted file mode 100644 index b3f0a5671616ce561e228c4ef665017b0379983b..0000000000000000000000000000000000000000 --- a/middleware/control_library/mcs_fosmo.c +++ /dev/null @@ -1,106 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_fosmo.c - * @author MCU Algorithm Team - * @brief This file provides functions of position sliding mode observer (SMO) module. - */ - -#include "mcs_fosmo.h" -#include "mcs_math_const.h" -#include "mcs_math.h" -#include "typedefs.h" -#include "mcs_assert.h" - -/** - * @brief Clear historical values of SMO handle. - * @param smoHandle SMO struct handle. - * @retval None. - */ -void FOSMO_Clear(FoSmoHandle *smoHandle) -{ - MCS_ASSERT_PARAM(smoHandle != NULL); - /* Clear historical values of SMO handle */ - smoHandle->currEst.alpha = 0.0f; - smoHandle->currEst.beta = 0.0f; - smoHandle->currEstLast.alpha = 0.0f; - smoHandle->currEstLast.beta = 0.0f; - smoHandle->emfEstUnFil.alpha = 0.0f; - smoHandle->emfEstUnFil.beta = 0.0f; - smoHandle->emfEstFil.alpha = 0.0f; - smoHandle->emfEstFil.beta = 0.0f; - /* Clear historical values of PLL controller */ - PLL_Clear(&smoHandle->pll); - /* Clear historical values of first-order smoHandle speed filter */ - FoFilterClear(&smoHandle->spdFilter); -} - -/** - * @brief Calculation method of first-order SMO. - * @param smoHandle SMO struct handle. - * @param currAlbe Feedback currents in the alpha-beta coordinate (A). - * @param voltAlbe FOC output voltages in alpha-beta coordinate (V). - * @param refHz The reference frequency (Hz). - * @retval None. - */ -void FOSMO_Exec(FoSmoHandle *smoHandle, const AlbeAxis *currAlbe, const AlbeAxis *voltAlbe, float refHz) -{ - MCS_ASSERT_PARAM(smoHandle != NULL); - MCS_ASSERT_PARAM(currAlbe != NULL); - MCS_ASSERT_PARAM(voltAlbe != NULL); - float err; - float wcTs; - float fcAbs = Abs(refHz); - signed short filCompAngle; /* Compensation angle */ - float currAlpha = smoHandle->currEstLast.alpha; - float currBeta = smoHandle->currEstLast.beta; - float emfUnAlpha = smoHandle->emfEstUnFil.alpha; - float emfUnBeta = smoHandle->emfEstUnFil.beta; - - smoHandle->currEst.alpha = - (smoHandle->a1 * currAlpha) + (smoHandle->a2 * (voltAlbe->alpha - emfUnAlpha)); - smoHandle->currEst.beta = - (smoHandle->a1 * currBeta) + (smoHandle->a2 * (voltAlbe->beta - emfUnBeta)); - - smoHandle->currEstLast.alpha = smoHandle->currEst.alpha; - smoHandle->currEstLast.beta = smoHandle->currEst.beta; - - /* Estmated back EMF by sign function. */ - err = smoHandle->currEst.alpha - currAlbe->alpha; - smoHandle->emfEstUnFil.alpha = smoHandle->kSmo * ((err > 0.0f) ? 1.0f : -1.0f); - err = smoHandle->currEst.beta - currAlbe->beta; - smoHandle->emfEstUnFil.beta = smoHandle->kSmo * ((err > 0.0f) ? 1.0f : -1.0f); - - /* Estmated back EMF is filtered by first-order LPF. */ - if (fcAbs <= smoHandle->emfLpfMinFreq) { - wcTs = smoHandle->emfLpfMinFreq * DOUBLE_PI * smoHandle->ctrlPeriod * smoHandle->lambda; - } else { - wcTs = fcAbs * DOUBLE_PI * smoHandle->ctrlPeriod * smoHandle->lambda; - } - smoHandle->emfEstFil.alpha = (smoHandle->emfEstFil.alpha + wcTs * smoHandle->emfEstUnFil.alpha) / (wcTs + 1.0f); - smoHandle->emfEstFil.beta = (smoHandle->emfEstFil.beta + wcTs * smoHandle->emfEstUnFil.beta) / (wcTs + 1.0f); - - /* Get phase angle and frequency from BEMF by PLL. */ - PLL_Exec(&smoHandle->pll, -smoHandle->emfEstFil.alpha, smoHandle->emfEstFil.beta); - - /* Compensation phase lag caused by the LPF. */ - filCompAngle = (refHz > 0.0f) ? (smoHandle->filCompAngle) : (INT16_MAX - smoHandle->filCompAngle); - smoHandle->elecAngle = smoHandle->pll.angle + filCompAngle; - - /* Estmated speed is filtered by first-order LPF. */ - smoHandle->spdEstHz = FoLowPassFilterExec(&smoHandle->spdFilter, smoHandle->pll.freq); -} diff --git a/middleware/control_library/mcs_fosmo.h b/middleware/control_library/mcs_fosmo.h deleted file mode 100644 index 7d1657158e45608857f5a3c0d8ec5ecf02452278..0000000000000000000000000000000000000000 --- a/middleware/control_library/mcs_fosmo.h +++ /dev/null @@ -1,86 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_fosmo.h - * @author MCU Algorithm Team - * @brief Sliding-mode observer (SMO) for motor position acquisition. - * This file provides position SMO and Phase-locked loop (PLL) declaration for motor control. - */ - -/* Define to prevent recursive inclusion ------------------------------------------------------- */ -#ifndef McuMagicTag_MCS_FOSMO_H -#define McuMagicTag_MCS_FOSMO_H - -/* Includes ------------------------------------------------------------------------------------ */ -#include "mcs_mtr_param.h" -#include "mcs_typedef.h" -#include "mcs_pll.h" -#include "mcs_filter.h" - -/** - * @defgroup FOSMO_MODULE FOSMO MODULE - * @brief The First Order Sliding Mode Observer module. - * @{ - */ - -/** - * @defgroup FOSMO_STRUCT FOSMO STRUCT - * @brief The First Order Sliding Mode Observer's data struct definition. - * @{ - */ -/* Typedef definitions ------------------------------------------------------------------------- */ -/** - * @brief Position SMO struct members and parameters. - */ -typedef struct { - MtrParamHandle *mtrParam; /**< Motor parameters. */ - float ctrlPeriod; /**< SMO control period (s). */ - float a1; /**< Coefficient of differential equation. */ - float a2; /**< Coefficient of differential equation. */ - AlbeAxis currEst; /**< SMO estimated currents in the alpha-beta coordinate. */ - AlbeAxis currEstLast; /**< SMO history values of estimated currents in the alpha-beta coordinate. */ - float kSmo; /**< SMO gain. */ - AlbeAxis emfEstUnFil; /**< Estimated back-EMF in the alpha-beta coordinate by differential equation. */ - float lambda; /**< SMO coefficient of cut-off frequency. */ - float emfLpfMinFreq; /**< The minimum cut-off frequency of back-EMF filter. */ - signed short filCompAngle; /**< Compensation angle for the back-EMF filter. */ - AlbeAxis emfEstFil; /**< SMO estimated back-EMF in the alpha-beta coordinate. */ - PllHandle pll; /**< PLL handle. */ - signed short elecAngle; /**< SMO estimated electronic angle (Q15). */ - FoFilterHandle spdFilter; /**< First-order LPF for speed. */ - float spdEstHz; /**< SMO estimated electronic speed (Hz). */ -} FoSmoHandle; -/** - * @} - */ - -/** - * @defgroup FOSMO_API FOSMO API - * @brief The First Order Sliding Mode Observer's API declaration. - * @{ - */ -void FOSMO_Clear(FoSmoHandle *smoHandle); -void FOSMO_Exec(FoSmoHandle *smoHandle, const AlbeAxis *currAlbe, const AlbeAxis *voltAlbe, float refHz); -/** - * @} - */ - -/** - * @} - */ - -#endif diff --git a/middleware/control_library/mcs_fw_ctrl.c b/middleware/control_library/mcs_fw_ctrl.c deleted file mode 100644 index f8d9a177202a7e29ae9e3441fed67d468a160e5b..0000000000000000000000000000000000000000 --- a/middleware/control_library/mcs_fw_ctrl.c +++ /dev/null @@ -1,89 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_fw_ctrl.c - * @author MCU Algorithm Team - * @brief This file provides Flux-Weakening control for motor control. - */ -#include "mcs_fw_ctrl.h" -#include "mcs_math.h" -#include "mcs_math_const.h" - -/** - * @brief Clear historical values of Flux-Weakening handle. - * @param FwCtrlHandle Flux-Weakening struct handle. - * @retval None. - */ -static void FwCtrl_Clear(FwCtrlHandle *fw) -{ - fw->idRef = 0.0f; -} - -/** - * @brief Flux-Weakening control Handle Initialization. - * @param FwCtrlHandle Flux-Weakening struct handle. - * @param ts - * @param enable - * @retval None. - */ -void FwCtrl_Init(FwCtrlHandle *fw, float ts, int enable) -{ - /* Indicates whether to enable the Flux-Weakening field function. */ - fw->enable = enable; - fw->ts = ts; - fw->udcThreshPer = SPECIAL_FW_CTRL_VOLT_BUS_THRESHOLD_PER * ONE_DIV_SQRT3; - /* id control step */ - fw->idStep = SPECIAL_FW_CTRL_ID_CHANGE_PER_SEC * ts; - fw->idMaxAmp = \ - (SPECIAL_FW_CTRL_OC_AMP < SPECIAL_FW_CTRL_ID_DEMAG_AMP) ? SPECIAL_FW_CTRL_OC_AMP : SPECIAL_FW_CTRL_ID_DEMAG_AMP; - FwCtrl_Clear(fw); -} - -/** - * @brief Flux-Weakening calculation execution function. - * @param FwCtrlHandle Flux-Weakening struct handle. - * @param udqRef dq axis voltage reference. - * @param udc bus voltage. - * @param idRefRaw Command value of the d axis current. - * @retval None. - */ -float FwCtrl_Exec(FwCtrlHandle *fw, DqAxis udqRef, float udc, float idRefRaw) -{ - float udcLimit = udc * fw->udcThreshPer; - float voltRefAmp = ASM_Sqrt(udqRef.d * udqRef.d + udqRef.q * udqRef.q); - float voltErr = udcLimit - voltRefAmp; - /* Check whether the Flux-Weakening field function is enabled. */ - if (!fw->enable) { - fw->idRef = idRefRaw; - return fw->idRef; - } - /* Adjust the injection ID based on the output voltage error. */ - /* The voltage error is positive. -id of weakening injection. */ - if (voltErr >= 0.0f) { - fw->idRef += fw->idStep; - if (fw->idRef > idRefRaw) { - fw->idRef = idRefRaw; - } - } - /* The voltage error is negative. Add the ingested -id. */ - if (voltErr < 0.0f) { - fw->idRef -= fw->idStep; - if (fw->idRef < -fw->idMaxAmp) { - fw->idRef = -fw->idMaxAmp; - } - } - return fw->idRef; -} diff --git a/middleware/control_library/mcs_fw_ctrl.h b/middleware/control_library/mcs_fw_ctrl.h deleted file mode 100644 index a19f8ea10dd7014c99c77f68fb56adc3afe17d21..0000000000000000000000000000000000000000 --- a/middleware/control_library/mcs_fw_ctrl.h +++ /dev/null @@ -1,43 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_fw_ctrl.h - * @author MCU Algorithm Team - * @brief This file provides functions of Flux-Weakening control. - */ -#ifndef McuMagicTag_MCS_SPECIAL_FW_CTRL_H -#define McuMagicTag_MCS_SPECIAL_FW_CTRL_H - -#include "mcs_typedef.h" - -#define SPECIAL_FW_CTRL_ID_CHANGE_PER_SEC (5.0f) -#define SPECIAL_FW_CTRL_VOLT_BUS_THRESHOLD_PER (0.95f) -#define SPECIAL_FW_CTRL_ID_DEMAG_AMP (10.0f) -#define SPECIAL_FW_CTRL_OC_AMP (7.0f) - -typedef struct { - int enable; - float udcThreshPer; - float ts; - float idStep; /* iD injection control step */ - float idRef; /* reference instruction value. */ - float idMaxAmp; /* Maximum id ingested */ -} FwCtrlHandle; - -void FwCtrl_Init(FwCtrlHandle *fw, float ts, int enable); -float FwCtrl_Exec(FwCtrlHandle *fw, DqAxis udqRef, float udc, float idRefRaw); - -#endif \ No newline at end of file diff --git a/middleware/control_library/mcs_if_ctrl.c b/middleware/control_library/mcs_if_ctrl.c deleted file mode 100644 index 7d15160b204cd16247ff2932d979292a7146e1a7..0000000000000000000000000000000000000000 --- a/middleware/control_library/mcs_if_ctrl.c +++ /dev/null @@ -1,96 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_if_ctrl.c - * @author MCU Algorithm Team - * @brief This file provides function of I/F control. - */ - -#include "mcs_if_ctrl.h" -#include "mcs_assert.h" - -#define ANGLE_360 65536.0f /* 0 - 65536 indicates 0 to 360°. */ - -/** - * @brief Initialzer of I/F control struct handle. - * @param ifHandle I/F handle. - * @param ifInit IfCtrlInit struct handle. - * @retval None. - */ -void IF_Init(IfHandle *ifHandle, IfCtrlInit *ifInit) -{ - MCS_ASSERT_PARAM(ifHandle != NULL); - MCS_ASSERT_PARAM(ifInit != NULL); - MCS_ASSERT_PARAM(ifInit->targetAmp > 0.0f); - MCS_ASSERT_PARAM(ifInit->currSlope > 0.0f); - MCS_ASSERT_PARAM(ifInit->anglePeriod > 0.0f && ifInit->anglePeriod < 1.0f); - MCS_ASSERT_PARAM(ifInit->stepAmpPeriod > 0.0f); - ifHandle->targetAmp = ifInit->targetAmp; - ifHandle->stepAmp = ifInit->currSlope * ifInit->stepAmpPeriod; /* current step increment */ - ifHandle->curAmp = 0.0f; - - ifHandle->anglePeriod = ifInit->anglePeriod; - ifHandle->ratio = ANGLE_360 * ifHandle->anglePeriod; /* Typical 0.0001f */ - ifHandle->angle = 0; -} - -/** - * @brief Clear historical values of first-order filter handle. - * @param ifHandle I/F control handle. - * @retval None. - */ -void IF_Clear(IfHandle *ifHandle) -{ - MCS_ASSERT_PARAM(ifHandle != NULL); - ifHandle->curAmp = 0.0f; - ifHandle->angle = 0; -} - -/** - * @brief I/F current amplitude calculation. - * @param ifHandle I/F control handle. - * @retval I/F current amplitude (A). - */ -float IF_CurrAmpCalc(IfHandle *ifHandle) -{ - MCS_ASSERT_PARAM(ifHandle != NULL); - /* Calculation of IF Current Amplitude */ - if (ifHandle->curAmp < ifHandle->targetAmp) { - ifHandle->curAmp += ifHandle->stepAmp; - } else { - ifHandle->curAmp = ifHandle->targetAmp; - } - - return ifHandle->curAmp; -} - -/** - * @brief I/F current angle calculation. - * @param ifHandle I/F control handle. - * @param spdRefHz Frequency of current vector. - * @retval I/F output angle (Q15). - */ -signed short IF_CurrAngleCalc(IfHandle *ifHandle, float spdRefHz) -{ - MCS_ASSERT_PARAM(ifHandle != NULL); - float delta = spdRefHz * ifHandle->ratio; - ifHandle->angleTemp += delta; - - /* Params force convert to signed short. */ - ifHandle->angle = (signed short)ifHandle->angleTemp; - return ifHandle->angle; -} diff --git a/middleware/control_library/mcs_if_ctrl.h b/middleware/control_library/mcs_if_ctrl.h deleted file mode 100644 index 4ef54dd9b63fc36bff3e64e8c1952431cbd17951..0000000000000000000000000000000000000000 --- a/middleware/control_library/mcs_if_ctrl.h +++ /dev/null @@ -1,86 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_if_ctrl.h - * @author MCU Algorithm Team - * @brief Current controller for motor I/F control. - * This file provides functions declaration of I/F control. - */ - -/* Define to prevent recursive inclusion ------------------------------------------------------- */ -#ifndef McuMagicTag_MCS_IF_CTRL_H -#define McuMagicTag_MCS_IF_CTRL_H - -/** - * @defgroup IF_MODULE I/F MODULE - * @brief The I/F motor control method module. - * @{ - */ - -/** - * @defgroup IF_STRUCT I/F STRUCT - * @brief The I/F motor control method data struct definition. - * @{ - */ -/* Typedef definitions ------------------------------------------------------------------------- */ -/** - * @brief General IF controller struct members and parameters. - */ -typedef struct { - float anglePeriod; /**< Calculation period of the I/F angle (s). */ - float curAmpPeriod; /**< Calculation period of the I/F current amplitude (s). */ - - float targetAmp; /**< Target value of the I/F current (A). */ - float curAmp; /**< Current value of the I/F current (A). */ - float stepAmp; /**< Increment of the I/F current (A). */ - - float ratio; /**< Rario change spdHz to digtial angle. */ - float angleTemp; /** < I/F temp output angle sum. */ - signed short angle; /**< I/F output angle (Q15). */ -} IfHandle; - -/** - * @brief The initial parameters struct for I/F control. - */ -typedef struct { - float targetAmp; /**< Target value of the I/F current (A). */ - float currSlope; /**< Current slope. */ - float stepAmpPeriod; /**< Step control period, using systick. */ - float anglePeriod; /**< Calculation period of the I/F angle (s). */ -} IfCtrlInit; -/** - * @} - */ - -/** - * @defgroup IF_API I/F API - * @brief The I/F motor control method API declaration. - * @{ - */ -void IF_Init(IfHandle *ifHandle, IfCtrlInit *ifInit); -void IF_Clear(IfHandle *ifHandle); -float IF_CurrAmpCalc(IfHandle *ifHandle); -signed short IF_CurrAngleCalc(IfHandle *ifHandle, float spdRefHz); -/** - * @} - */ - -/** - * @} - */ - -#endif diff --git a/middleware/control_library/mcs_math.c b/middleware/control_library/mcs_math.c deleted file mode 100644 index d37bacdece3527744561efee5bbd33981ac1fc82..0000000000000000000000000000000000000000 --- a/middleware/control_library/mcs_math.c +++ /dev/null @@ -1,288 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_math.c - * @author MCU Algorithm Team - * @brief This file provides common math functions including trigonometric, coordinate transformation, - * square root math calculation. - */ - -#include "mcs_math.h" -#include "mcs_math_const.h" -#include "mcs_assert.h" - -/* Macro definitions --------------------------------------------------------------------------- */ -#define SIN_TABLE \ - { \ - 0, 51, 101, 151, 202, 252, 302, 352, 403, 453, 503, 553, 604, 654, 704, 754, 805, 855, 905, 955, 1006, 1056, \ - 1106, 1156, 1207, 1257, 1307, 1357, 1407, 1458, 1508, 1558, 1608, 1659, 1709, 1759, 1809, 1859, 1909, \ - 1960, 2010, 2060, 2110, 2160, 2210, 2261, 2311, 2361, 2411, 2461, 2511, 2561, 2611, 2662, 2712, 2762, \ - 2812, 2862, 2912, 2962, 3012, 3062, 3112, 3162, 3212, 3262, 3312, 3362, 3412, 3462, 3512, 3562, 3612, \ - 3662, 3712, 3762, 3812, 3862, 3912, 3962, 4012, 4061, 4111, 4161, 4211, 4261, 4311, 4360, 4410, 4460, \ - 4510, 4560, 4609, 4659, 4709, 4759, 4808, 4858, 4908, 4958, 5007, 5057, 5107, 5156, 5206, 5255, 5305, \ - 5355, 5404, 5454, 5503, 5553, 5602, 5652, 5701, 5751, 5800, 5850, 5899, 5949, 5998, 6048, 6097, 6146, \ - 6196, 6245, 6294, 6344, 6393, 6442, 6492, 6541, 6590, 6639, 6689, 6738, 6787, 6836, 6885, 6934, 6983, \ - 7033, 7082, 7131, 7180, 7229, 7278, 7327, 7376, 7425, 7474, 7523, 7572, 7620, 7669, 7718, 7767, 7816, \ - 7865, 7913, 7962, 8011, 8060, 8108, 8157, 8206, 8254, 8303, 8352, 8400, 8449, 8497, 8546, 8594, 8643, \ - 8691, 8740, 8788, 8837, 8885, 8933, 8982, 9030, 9078, 9127, 9175, 9223, 9271, 9320, 9368, 9416, 9464, \ - 9512, 9560, 9608, 9656, 9704, 9752, 9800, 9848, 9896, 9944, 9992, 10040, 10088, 10136, 10183, 10231, \ - 10279, 10327, 10374, 10422, 10470, 10517, 10565, 10612, 10660, 10707, 10755, 10802, 10850, 10897, 10945, \ - 10992, 11039, 11087, 11134, 11181, 11228, 11276, 11323, 11370, 11417, 11464, 11511, 11558, 11605, 11652, \ - 11699, 11746, 11793, 11840, 11887, 11934, 11981, 12027, 12074, 12121, 12167, 12214, 12261, 12307, 12354, \ - 12400, 12447, 12493, 12540, 12586, 12633, 12679, 12725, 12772, 12818, 12864, 12910, 12957, 13003, 13049, \ - 13095, 13141, 13187, 13233, 13279, 13325, 13371, 13417, 13463, 13508, 13554, 13600, 13646, 13691, 13737, \ - 13783, 13828, 13874, 13919, 13965, 14010, 14056, 14101, 14146, 14192, 14237, 14282, 14327, 14373, 14418, \ - 14463, 14508, 14553, 14598, 14643, 14688, 14733, 14778, 14823, 14867, 14912, 14957, 15002, 15046, 15091, \ - 15136, 15180, 15225, 15269, 15314, 15358, 15402, 15447, 15491, 15535, 15580, 15624, 15668, 15712, 15756, \ - 15800, 15844, 15888, 15932, 15976, 16020, 16064, 16108, 16151, 16195, 16239, 16282, 16326, 16369, 16413, \ - 16456, 16500, 16543, 16587, 16630, 16673, 16717, 16760, 16803, 16846, 16889, 16932, 16975, 17018, 17061, \ - 17104, 17147, 17190, 17233, 17275, 17318, 17361, 17403, 17446, 17488, 17531, 17573, 17616, 17658, 17700, \ - 17743, 17785, 17827, 17869, 17911, 17953, 17995, 18037, 18079, 18121, 18163, 18205, 18247, 18288, 18330, \ - 18372, 18413, 18455, 18496, 18538, 18579, 18621, 18662, 18703, 18745, 18786, 18827, 18868, 18909, 18950, \ - 18991, 19032, 19073, 19114, 19155, 19195, 19236, 19277, 19317, 19358, 19398, 19439, 19479, 19520, 19560, \ - 19600, 19641, 19681, 19721, 19761, 19801, 19841, 19881, 19921, 19961, 20001, 20041, 20080, 20120, 20160, \ - 20199, 20239, 20278, 20318, 20357, 20397, 20436, 20475, 20514, 20554, 20593, 20632, 20671, 20710, 20749, \ - 20788, 20826, 20865, 20904, 20943, 20981, 21020, 21058, 21097, 21135, 21174, 21212, 21250, 21289, 21327, \ - 21365, 21403, 21441, 21479, 21517, 21555, 21593, 21630, 21668, 21706, 21744, 21781, 21819, 21856, 21894, \ - 21931, 21968, 22005, 22043, 22080, 22117, 22154, 22191, 22228, 22265, 22302, 22339, 22375, 22412, 22449, \ - 22485, 22522, 22558, 22595, 22631, 22667, 22704, 22740, 22776, 22812, 22848, 22884, 22920, 22956, 22992, \ - 23028, 23063, 23099, 23135, 23170, 23206, 23241, 23277, 23312, 23347, 23383, 23418, 23453, 23488, 23523, \ - 23558, 23593, 23628, 23662, 23697, 23732, 23767, 23801, 23836, 23870, 23904, 23939, 23973, 24007, 24042, \ - 24076, 24110, 24144, 24178, 24212, 24245, 24279, 24313, 24347, 24380, 24414, 24447, 24481, 24514, 24547, \ - 24581, 24614, 24647, 24680, 24713, 24746, 24779, 24812, 24845, 24878, 24910, 24943, 24975, 25008, 25040, \ - 25073, 25105, 25137, 25170, 25202, 25234, 25266, 25298, 25330, 25362, 25393, 25425, 25457, 25488, 25520, \ - 25551, 25583, 25614, 25646, 25677, 25708, 25739, 25770, 25801, 25832, 25863, 25894, 25925, 25955, 25986, \ - 26017, 26047, 26078, 26108, 26138, 26169, 26199, 26229, 26259, 26289, 26319, 26349, 26379, 26409, 26438, \ - 26468, 26498, 26527, 26557, 26586, 26616, 26645, 26674, 26703, 26732, 26761, 26790, 26819, 26848, 26877, \ - 26906, 26934, 26963, 26991, 27020, 27048, 27077, 27105, 27133, 27161, 27189, 27217, 27245, 27273, 27301, \ - 27329, 27356, 27384, 27412, 27439, 27467, 27494, 27521, 27549, 27576, 27603, 27630, 27657, 27684, 27711, \ - 27737, 27764, 27791, 27817, 27844, 27870, 27897, 27923, 27949, 27976, 28002, 28028, 28054, 28080, 28106, \ - 28132, 28157, 28183, 28209, 28234, 28260, 28285, 28310, 28336, 28361, 28386, 28411, 28436, 28461, 28486, \ - 28511, 28535, 28560, 28585, 28609, 28634, 28658, 28682, 28707, 28731, 28755, 28779, 28803, 28827, 28851, \ - 28875, 28898, 28922, 28946, 28969, 28993, 29016, 29039, 29063, 29086, 29109, 29132, 29155, 29178, 29201, \ - 29223, 29246, 29269, 29291, 29314, 29336, 29359, 29381, 29403, 29425, 29447, 29469, 29491, 29513, 29535, \ - 29557, 29578, 29600, 29622, 29643, 29664, 29686, 29707, 29728, 29749, 29770, 29791, 29812, 29833, 29854, \ - 29874, 29895, 29916, 29936, 29956, 29977, 29997, 30017, 30037, 30057, 30077, 30097, 30117, 30137, 30157, \ - 30176, 30196, 30215, 30235, 30254, 30273, 30292, 30312, 30331, 30350, 30369, 30387, 30406, 30425, 30443, \ - 30462, 30481, 30499, 30517, 30536, 30554, 30572, 30590, 30608, 30626, 30644, 30661, 30679, 30697, 30714, \ - 30732, 30749, 30767, 30784, 30801, 30818, 30835, 30852, 30869, 30886, 30903, 30919, 30936, 30952, 30969, \ - 30985, 31002, 31018, 31034, 31050, 31066, 31082, 31098, 31114, 31129, 31145, 31161, 31176, 31192, 31207, \ - 31222, 31237, 31253, 31268, 31283, 31298, 31312, 31327, 31342, 31357, 31371, 31386, 31400, 31414, 31429, \ - 31443, 31457, 31471, 31485, 31499, 31513, 31526, 31540, 31554, 31567, 31581, 31594, 31607, 31620, 31634, \ - 31647, 31660, 31673, 31685, 31698, 31711, 31724, 31736, 31749, 31761, 31773, 31786, 31798, 31810, 31822, \ - 31834, 31846, 31857, 31869, 31881, 31892, 31904, 31915, 31927, 31938, 31949, 31960, 31971, 31982, 31993, \ - 32004, 32015, 32025, 32036, 32047, 32057, 32067, 32078, 32088, 32098, 32108, 32118, 32128, 32138, 32148, \ - 32157, 32167, 32177, 32186, 32195, 32205, 32214, 32223, 32232, 32241, 32250, 32259, 32268, 32276, 32285, \ - 32294, 32302, 32311, 32319, 32327, 32335, 32343, 32351, 32359, 32367, 32375, 32383, 32390, 32398, 32405, \ - 32413, 32420, 32427, 32435, 32442, 32449, 32456, 32463, 32469, 32476, 32483, 32489, 32496, 32502, 32509, \ - 32515, 32521, 32527, 32533, 32539, 32545, 32551, 32557, 32562, 32568, 32573, 32579, 32584, 32589, 32595, \ - 32600, 32605, 32610, 32615, 32619, 32624, 32629, 32633, 32638, 32642, 32647, 32651, 32655, 32659, 32663, \ - 32667, 32671, 32675, 32679, 32682, 32686, 32689, 32693, 32696, 32700, 32703, 32706, 32709, 32712, 32715, \ - 32718, 32720, 32723, 32726, 32728, 32730, 32733, 32735, 32737, 32739, 32741, 32743, 32745, 32747, 32749, \ - 32751, 32752, 32754, 32755, 32756, 32758, 32759, 32760, 32761, 32762, 32763, 32764, 32764, 32765, 32766, \ - 32766, 32767, 32767, 32767, 32767, 32767 \ - } - -#define SIN_MASK 0x0C00 -#define U0_90 0x0800 -#define U90_180 0x0C00 -#define U180_270 0x0000 -#define U270_360 0x0400 -#define SIN_TAB_LEN 0x03FF -#define Q15_BASE 32768 -#define ANGLE_TO_INDEX_SHIFT 4 - -/* Private variables --------------------------------------------------------- */ -const short g_sinTable[SIN_TAB_LEN + 1] = SIN_TABLE; - -/** - * @brief Calculate sine and cosine function of the input angle. - * @param val: Output result, which contain the calculated sin, cos value. - * @param angle: The input parameter angle (Q15). - * @retval None. - */ -void TrigCalc(TrigVal *val, signed short angle) -{ - MCS_ASSERT_PARAM(val != NULL); - int indexS32; - unsigned short indexU16; - unsigned short angleRange; - float sinVal = 0.0f; - float cosVal = 0.0f; - float oneDivPu = 0.00003051851f; /* 1.0f / 32767.0f */ - - /* 16bit angle ->12bit index */ - indexS32 = Q15_BASE + (int)angle; - indexU16 = (unsigned short)indexS32; - indexU16 = indexU16 >> ANGLE_TO_INDEX_SHIFT; - /* Calculate Angle Quadrant. */ - angleRange = indexU16 & SIN_MASK; - indexU16 &= 0x03FF; - - /* Calculate symbols based on angle quadrants and look up tables. */ - switch (angleRange) { - case U0_90: - sinVal = g_sinTable[indexU16]; - cosVal = g_sinTable[SIN_TAB_LEN - indexU16]; /* indexU16 0 ~ 1023, indexU16 <= SIN_TAB_LEN */ - break; - case U90_180: - sinVal = g_sinTable[SIN_TAB_LEN - indexU16]; - cosVal = -g_sinTable[indexU16]; - break; - case U180_270: - sinVal = -g_sinTable[indexU16]; - cosVal = -g_sinTable[SIN_TAB_LEN - indexU16]; - break; - case U270_360: - sinVal = -g_sinTable[SIN_TAB_LEN - indexU16]; - cosVal = g_sinTable[indexU16]; - break; - default: - break; - } - /* Returns a sine-cosine result. */ - val->sin = sinVal * oneDivPu; - val->cos = cosVal * oneDivPu; -} - -/** - * @brief Park transformation: transforms stator values alpha and beta, which - * belong to a stationary albe reference frame, to a rotor flux - * synchronous reference dq frame. - * @param albe: Input alpha beta axis value. - * @param angle: Input the theta angle. - * @param dq: Output DQ axis value. - * @retval None - */ -void ParkCalc(const AlbeAxis *albe, signed short angle, DqAxis *dq) -{ - MCS_ASSERT_PARAM(albe != NULL); - MCS_ASSERT_PARAM(dq != NULL); - float alpha = albe->alpha; - float beta = albe->beta; - TrigVal localTrigVal; - /* The projection of ia, ib, and ic currents on alpha and beta axes is equivalent to that on d, q axes. */ - TrigCalc(&localTrigVal, angle); - dq->d = alpha * localTrigVal.cos + beta * localTrigVal.sin; - dq->q = -alpha * localTrigVal.sin + beta * localTrigVal.cos; -} - -/** - * @brief Inverse Park transformation: transforms stator values d and q, which - * belong to a rotor flux synchronous reference dq frame, to a stationary - * albe reference frame. - * @param dq: Input DQ axis value. - * @param angle: Input the theta angle. - * @param albe: Output alpha beta axis value. - * @retval None - */ -void InvParkCalc(const DqAxis *dq, signed short angle, AlbeAxis *albe) -{ - MCS_ASSERT_PARAM(dq != NULL); - MCS_ASSERT_PARAM(albe != NULL); - float d = dq->d; - float q = dq->q; - TrigVal localTrigVal; - /* Inversely transform the d, q-axis current to alpha ,beta. */ - TrigCalc(&localTrigVal, angle); - albe->alpha = d * localTrigVal.cos - q * localTrigVal.sin; - albe->beta = d * localTrigVal.sin + q * localTrigVal.cos; -} - -/** - * @brief Clarke transformation: transforms stationary three-phase quantites to - * stationary albe quantites. - * @param uvw: Clarke struct handle. - * @param albe: AlbeAxis struct handle used to store the Clarke transform output. - * @retval None. - */ -void ClarkeCalc(const UvwAxis *uvw, AlbeAxis *albe) -{ - MCS_ASSERT_PARAM(uvw != NULL); - MCS_ASSERT_PARAM(albe != NULL); - albe->alpha = uvw->u; - albe->beta = ONE_DIV_SQRT3 * (uvw->u + 2.0f * uvw->v); -} - -/** - * @brief This function returns the absolute value of the input value. - * @param val: The quantity that wants to execute absolute operation. - * @retval The absolute value of the input value. - */ -float Abs(float val) -{ - return (val >= 0.0f) ? val : (-val); -} - -/** - * @brief Clamp operation. - * @param val Value that needs to be clamped. - * @param upperLimit The upper limitation. - * @param lowerLimit The lower limitation. - * @retval Clamped value. - */ -float Clamp(float val, float upperLimit, float lowerLimit) -{ - MCS_ASSERT_PARAM(upperLimit > lowerLimit); - float result; - /* Clamping Calculation. */ - if (val >= upperLimit) { - result = upperLimit; - } else if (val <= lowerLimit) { - result = lowerLimit; - } else { - result = val; - } - return result; -} - -/** - * @brief Get bigger value. - * @param val1 The value to be compared. - * @param val2 The value to be compared. - * @retval The greater value. - */ -float Max(float val1, float val2) -{ - return ((val1 >= val2) ? val1 : val2); -} - -/** - * @brief Get smaller value. - * @param val1 The value to be compared. - * @param val2 The value to be compared. - * @retval The smaller value. - */ -float Min(float val1, float val2) -{ - return ((val1 <= val2) ? val1 : val2); -} - -/** - * @brief Fast sqrt calculation using ASM. - * @param val Float val. - * @retval Sqrt result. - */ -float ASM_Sqrt(float val) -{ - MCS_ASSERT_PARAM(val >= 0.0f); - float rd = val; - - __asm volatile("fsqrt.s %0, %1" : "=f"(rd) : "f"(val)); - - return rd; -} diff --git a/middleware/control_library/mcs_math.h b/middleware/control_library/mcs_math.h deleted file mode 100644 index a327e0633037c3dff3646e04a870bc55258a0d76..0000000000000000000000000000000000000000 --- a/middleware/control_library/mcs_math.h +++ /dev/null @@ -1,74 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_math.h - * @author MCU Algorithm Team - * @brief Math library. - * This file provides math functions declaration of motor math module. - */ - -/* Define to prevent recursive inclusion ------------------------------------------------------- */ -#ifndef McuMagicTag_MCS_MATH_H -#define McuMagicTag_MCS_MATH_H - -/* Includes ------------------------------------------------------------------------------------ */ -#include "mcs_typedef.h" - -/** - * @defgroup MATH MATH - * @brief The common math const define for motor control. - * @{ - */ - -/** - * @defgroup MATH_Triangle MATH Triangle - * @brief The triangle structure definition. - * @{ - */ -/** - * @brief sin cos define - */ -typedef struct { - float sin; /**< The sine value of input angle. */ - float cos; /**< The cosine value of input angle. */ -} TrigVal; -/** - * @} - */ - -/** - * @defgroup MATH_API MATH API - * @brief The common math API definition. - * @{ - */ -void TrigCalc(TrigVal *val, signed short angle); -void ParkCalc(const AlbeAxis *albe, signed short angle, DqAxis *dq); -void InvParkCalc(const DqAxis *dq, signed short angle, AlbeAxis *albe); -void ClarkeCalc(const UvwAxis *uvw, AlbeAxis *albe); -float Abs(float val); -float Clamp(float val, float upperLimit, float lowerLimit); -float Max(float val1, float val2); -float Min(float val1, float val2); -float ASM_Sqrt(float val); -/** - * @} - */ - -/** - * @} - */ -#endif diff --git a/middleware/control_library/mcs_math_const.h b/middleware/control_library/mcs_math_const.h deleted file mode 100644 index 33aa139cdd1f8433ef0d2b676878c3800e9e53a0..0000000000000000000000000000000000000000 --- a/middleware/control_library/mcs_math_const.h +++ /dev/null @@ -1,57 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_math_const.h - * @author MCU Algorithm Team - * @brief This file provides math constant macro definition functionality for - * managing math calculation number definitions. - */ - -/* Define to prevent recursive inclusion ------------------------------------- */ -#ifndef McuMagicTag_MCS_MATH_CONST_H -#define McuMagicTag_MCS_MATH_CONST_H - -/** - * @addtogroup MATH - * @brief Math const definition. - * @{ - */ - -/** - * @defgroup MATH_CONST MATH CONST - * @brief The common math const definition for motor control. - * @{ - */ -/* Macro definitions ---------------------------------------------------------*/ -#define ONE_DIV_THREE (0.3333333f) /**< 1/3 */ -#define TWO_DIV_THREE (0.6666667f) /**< 2/3 */ -#define ONE_PI (3.141593f) /**< PI */ -#define DOUBLE_PI (6.283185f) /**< 2*PI */ -#define SQRT3_DIV_TWO (0.8660254f) /**< Sqrt(3)/2 */ -#define ONE_DIV_SQRT3 (0.5773503f) /**< 1/sqrt(3) */ -#define ONE_DIV_DOUBLE_PI (0.1591549f) /**< 1/(2*PI) */ -#define RAD_TO_DEG (57.29578f) /**< 1/pi*180 */ -#define RAD_TO_DIGITAL (10430.06f) /**< 1/pi*32767 */ -/** - * @} - */ - - /** - * @} - */ - -#endif /* McuMagicTag_MCS_MATH_CONST_H */ diff --git a/middleware/control_library/mcs_mtr_param.h b/middleware/control_library/mcs_mtr_param.h deleted file mode 100644 index 373ebfd742e94b9a075379e2280b008950ffb376..0000000000000000000000000000000000000000 --- a/middleware/control_library/mcs_mtr_param.h +++ /dev/null @@ -1,53 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_mtr_param.h - * @author MCU Algorithm Team - * @brief This file provides data structure define of motor parameters. - */ - -/* Define to prevent recursive inclusion ------------------------------------------------------- */ -#ifndef McuMagicTag_MCS_MTR_PARAM_H -#define McuMagicTag_MCS_MTR_PARAM_H - -/* Typedef definitions ------------------------------------------------------------------------- */ - -/** - * @defgroup MOTOR_PARAMETER MOTOR PARAMETER - * @brief The motor parameter definitions. - * @{ - */ -/** - * @brief motor parameters data structure - */ -typedef struct { - unsigned short mtrNp; /**< Numbers of pole pairs. */ - float mtrRs; /**< Resistor of stator, Ohm. */ - float mtrLd; /**< Inductance of D-axis, H. */ - float mtrLq; /**< Inductance of Q-axis, H. */ - float mtrLs; /**< Average inductance, H. */ - float mtrPsif; /**< Permanent magnet flux, Wb. */ - float mtrJ; /**< Rotor inertia, Kg*m2. */ - float maxElecSpd; /**< Max elec speed, Hz. */ - float maxCurr; /**< Max current, A. */ - float maxTrq; /**< Max torque, Nm. */ -} MtrParamHandle; -/** - * @} - */ - -#endif diff --git a/middleware/control_library/mcs_pid_ctrl.c b/middleware/control_library/mcs_pid_ctrl.c deleted file mode 100644 index f1ec541b7b382421a82c07da8e2997b0237e3879..0000000000000000000000000000000000000000 --- a/middleware/control_library/mcs_pid_ctrl.c +++ /dev/null @@ -1,160 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_pid_ctrl.c - * @author MCU Algorithm Team - * @brief This file provides functions of general PID controller - */ - -#include "mcs_pid_ctrl.h" -#include "mcs_math.h" -#include "mcs_assert.h" - -/** - * @brief Reset all member variables of PID controller to zero. - * @param pidHandle PID controller struct handle. - * @retval None. - */ -void PID_Reset(PidHandle *pidHandle) -{ - MCS_ASSERT_PARAM(pidHandle != NULL); - /* Reset the PID parameter. */ - pidHandle->error = 0.0f; - pidHandle->errorLast = 0.0f; - pidHandle->feedforward = 0.0f; - pidHandle->integral = 0.0f; - pidHandle->saturation = 0.0f; - pidHandle->differ = 0.0f; - pidHandle->kp = 0.0f; - pidHandle->ki = 0.0f; - pidHandle->kd = 0.0f; - pidHandle->ns = 0.0f; - pidHandle->ka = 0.0f; - /* Reset the Limiting Value. */ - pidHandle->upperLimit = 0.0f; - pidHandle->lowerLimit = 0.0f; -} - -/** - * @brief Clear historical values of PID controller. - * @param pidHandle PID controller struct handle. - * @retval None. - */ -void PID_Clear(PidHandle *pidHandle) -{ - MCS_ASSERT_PARAM(pidHandle != NULL); - /* Clear historical values of PID controller. */ - pidHandle->differ = 0.0f; - pidHandle->integral = 0.0f; - pidHandle->saturation = 0.0f; - pidHandle->feedforward = 0.0f; - pidHandle->error = 0.0f; - pidHandle->errorLast = 0.0f; -} - -/** - * @brief Execute simplified PI controller calculation, static clamping, no feedfoward. - * @param pidHandle PI controller struct handle. - * @retval PI control output. - */ -float PI_Exec(PidHandle *pidHandle) -{ - MCS_ASSERT_PARAM(pidHandle != NULL); - /* Proportional Item */ - float p = pidHandle->kp * pidHandle->error; - - /* Integral Item */ - float i = pidHandle->ki * pidHandle->error + pidHandle->integral; - i = Clamp(i, pidHandle->upperLimit, pidHandle->lowerLimit); - pidHandle->integral = i; - - /* static clamping and output calculaiton */ - float val = p + i; - float out = Clamp(val, pidHandle->upperLimit, pidHandle->lowerLimit); - - return out; -} - -/** - * @brief Execute PID controller calculation. dynamic clamping, feedfoward compenstaion - * @param pidHandle PID controller struct handle. - * @retval PID control output. - */ -float PID_Exec(PidHandle *pidHandle) -{ - MCS_ASSERT_PARAM(pidHandle != NULL); - /* Proportional Item */ - float p = pidHandle->kp * pidHandle->error; - - /* Integral Item */ - float i = pidHandle->ki * (pidHandle->error - pidHandle->ka * pidHandle->saturation) + pidHandle->integral; - i = Clamp(i, Max(0.0f, pidHandle->upperLimit), Min(0.0f, pidHandle->lowerLimit)); - pidHandle->integral = i; - - /* Differential Item */ - float d = pidHandle->kd * pidHandle->ns * (pidHandle->error - pidHandle->errorLast) - \ - pidHandle->differ * (pidHandle->ns - 1.0f); - - pidHandle->errorLast = pidHandle->error; - pidHandle->differ = d; - - /* Output value update and saturation value calculation */ - float val = p + i + d + pidHandle->feedforward; - float out = Clamp(val, pidHandle->upperLimit, pidHandle->lowerLimit); - pidHandle->saturation = val - out; - - return out; -} - -/** - * @brief Set the proportional parameter kp of PID controller. - * @param pidHandle PID controller struct handle. - * @param kp The proportional parameter. - * @retval None. - */ -void PID_SetKp(PidHandle *pidHandle, float kp) -{ - MCS_ASSERT_PARAM(pidHandle != NULL); - MCS_ASSERT_PARAM(kp >= 0.0f); - pidHandle->kp = kp; -} - -/** - * @brief Set the integral parameter ki of PID controller. - * @param pidHandle PID controller struct handle. - * @param ki The integral parameter. - * @retval None. - */ -void PID_SetKi(PidHandle *pidHandle, float ki) -{ - MCS_ASSERT_PARAM(pidHandle != NULL); - MCS_ASSERT_PARAM(ki >= 0.0f); - pidHandle->ki = ki; -} - -/** - * @brief Set the derivative parameter kd of PID controller. - * @param pidHandle PID controller struct handle. - * @param kd The derivative parameter. - * @retval None. - */ -void PID_SetKd(PidHandle *pidHandle, float kd) -{ - MCS_ASSERT_PARAM(pidHandle != NULL); - MCS_ASSERT_PARAM(kd >= 0.0f); - pidHandle->kd = kd; -} diff --git a/middleware/control_library/mcs_pid_ctrl.h b/middleware/control_library/mcs_pid_ctrl.h deleted file mode 100644 index a942dc4d8cada4867d1d3e79cebbf3f97b087bf6..0000000000000000000000000000000000000000 --- a/middleware/control_library/mcs_pid_ctrl.h +++ /dev/null @@ -1,82 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_pid_ctrl.h - * @author MCU Algorithm Team - * @brief General PI controller. - * This file provides functions declaration of the PI controller module. - */ - -/* Define to prevent recursive inclusion ------------------------------------------------------- */ -#ifndef McuMagicTag_MCS_PID_CTRL_H -#define McuMagicTag_MCS_PID_CTRL_H - -/** - * @defgroup PID PID - * @brief The PID module. - * @{ - */ - -/** - * @defgroup PID_STRUCT PID STRUCT - * @brief The PID control structure definition. - * @{ - */ -/* Typedef definitions ------------------------------------------------------------------------- */ -/** - * @brief General PID Controller struct members and parameters. - */ -typedef struct { - float error; /**< Error feedback. */ - float errorLast; /**< Error feedback history values. */ - float feedforward; /**< Feedforward item. */ - float integral; /**< Integral item. */ - float saturation; /**< Saturation value of the integral item. */ - float differ; /**< Differential item. */ - float kp; /**< Gained of the proportional item. */ - float ki; /**< Gained of the integral item, multiplied by control period. */ - float kd; /**< Gained of the differential item. */ - float ns; /**< Filter parameter of the differential item. */ - float ka; /**< Gained of the saturation item. */ - float upperLimit; /**< The upper limit value of the pid comp output. */ - float lowerLimit; /**< The lower limit value of the pid output. */ -} PidHandle; -/** - * @} - */ - -/** - * @defgroup PID_API PID API - * @brief The PID control API definitions. - * @{ - */ -void PID_Reset(PidHandle *pidHandle); -void PID_Clear(PidHandle *pidHandle); -float PI_Exec(PidHandle *pidHandle); -float PID_Exec(PidHandle *pidHandle); -void PID_SetKp(PidHandle *pidHandle, float kp); -void PID_SetKi(PidHandle *pidHandle, float ki); -void PID_SetKd(PidHandle *pidHandle, float kd); -/** - * @} - */ - -/** - * @} - */ - -#endif diff --git a/middleware/control_library/mcs_pll.c b/middleware/control_library/mcs_pll.c deleted file mode 100644 index 149088d01a8546ba5f01596930f00d52702e48e7..0000000000000000000000000000000000000000 --- a/middleware/control_library/mcs_pll.c +++ /dev/null @@ -1,75 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_pll.c - * @author MCU Algorithm Team - * @brief This file provides function of phase-locked loop (PLL) module. - */ - -#include "mcs_pll.h" -#include "mcs_math.h" -#include "mcs_assert.h" - -/** - * @brief Reset the PLL handle, fill all parameters with zero. - * @param pllHandle PLL struct handle. - * @retval None. - */ -void PLL_Reset(PllHandle *pllHandle) -{ - MCS_ASSERT_PARAM(pllHandle != NULL); - /* Reset PLL PID parameters */ - PID_Reset(&(pllHandle->pi)); - pllHandle->minAmp = 0.0f; - pllHandle->ctrlPeriod = 0.0f; - pllHandle->ratio = 0.0f; - pllHandle->freq = 0.0f; - pllHandle->angle = 0; -} - -/** - * @brief Clear historical values of PLL controller. - * @param pllHandle PLL struct handle. - * @retval None. - */ -void PLL_Clear(PllHandle *pllHandle) -{ - MCS_ASSERT_PARAM(pllHandle != NULL); - PID_Clear(&pllHandle->pi); -} - -/** - * @brief Calculation method of PLL controller. - * @param pllHandle PLL struct handle. - * @param sinVal Input sin value. - * @param cosVal Input cos value. - * @retval None. - */ -void PLL_Exec(PllHandle *pllHandle, float sinVal, float cosVal) -{ - MCS_ASSERT_PARAM(pllHandle != NULL); - float amplitude = ASM_Sqrt(sinVal * sinVal + cosVal * cosVal); - amplitude = (amplitude < pllHandle->minAmp) ? pllHandle->minAmp : amplitude; /* amplitude > minAmp > 0 */ - - TrigVal localTrigVal; - pllHandle->angle += pllHandle->freq * pllHandle->ratio; - TrigCalc(&localTrigVal, pllHandle->angle); - - float err = sinVal * localTrigVal.cos - cosVal * localTrigVal.sin; - pllHandle->pi.error = err / amplitude; /* amplitude != 0 */ - pllHandle->freq = PI_Exec(&pllHandle->pi); -} diff --git a/middleware/control_library/mcs_pll.h b/middleware/control_library/mcs_pll.h deleted file mode 100644 index 202352945bf68f661b2a90e63925e67425576636..0000000000000000000000000000000000000000 --- a/middleware/control_library/mcs_pll.h +++ /dev/null @@ -1,72 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_pll.h - * @author MCU Algorithm Team - * @brief This file provides functions declaration of Phase-locked loop (PLL) module. - */ - -/* Define to prevent recursive inclusion ------------------------------------------------------- */ -#ifndef McuMagicTag_MCS_PLL_H -#define McuMagicTag_MCS_PLL_H - -/* Includes ------------------------------------------------------------------------------------ */ -#include "mcs_pid_ctrl.h" - -/** - * @defgroup PLL_MODULE PLL MODULE - * @brief The PLL module. - * @{ - */ - -/** - * @defgroup PLL_STRUCT PLL STRUCT - * @brief The PLL module data structure. - * @{ - */ -/* Typedef definitions ------------------------------------------------------------------------- */ -/** - * @brief PLL struct. - */ -typedef struct { - PidHandle pi; /**< PI controller for the PLL. */ - float minAmp; /**< Minimum value of the input value in case of the divergence of the PLL. */ - float ctrlPeriod; /**< Control period of the PLL. */ - float ratio; /**< Conversion factor, ctrlPeriod * 65535 / TWO_PI. */ - float freq; /**< Output estimated frequency (Hz). */ - signed short angle; /**< Output estimated phasse angle (Q15). */ -} PllHandle; -/** - * @} - */ - -/** - * @defgroup PLL_API PLL API - * @brief The PLL module API definitions. - * @{ - */ -void PLL_Reset(PllHandle *pllHandle); -void PLL_Clear(PllHandle *pllHandle); -void PLL_Exec(PllHandle *pllHandle, float sinVal, float cosVal); -/** - * @} - */ - -/** - * @} - */ -#endif diff --git a/middleware/control_library/mcs_r1_svpwm.c b/middleware/control_library/mcs_r1_svpwm.c deleted file mode 100644 index ba6c3121cb54675f1d0caf895217ccf1ef198f6e..0000000000000000000000000000000000000000 --- a/middleware/control_library/mcs_r1_svpwm.c +++ /dev/null @@ -1,246 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_r1_svpwm.c - * @author MCU Algorithm Team - * @brief This file provides function of Space-vector pulse-width-modulation calculations - * in case of single shunt current sample and current reconstruction. - */ - -#include "mcs_svpwm.h" -#include "mcs_r1_svpwm.h" -#include "mcs_assert.h" - -/* Macro definitions ---------------------------------------------------------*/ -#define SOCA 0 -#define SOCB 1 - -/** - * @brief Structure of temporary variables for R1SVPWM calculation. - */ -typedef struct { - SvpwmCalcHandle svCalc; - float compLeft[SVPWM_COMP_VAL_TOTAL]; - float compRight[SVPWM_COMP_VAL_TOTAL]; -} R1SvpwmCalcHandle; - -/** - * @brief R1SVPWM handlel init. - * @param r1svHandle The R1SVPWM handle. - * @param voltPu Voltage per unit value. - */ -void R1SVPWM_Init(R1SvpwmHandle *r1svHandle, float voltPu, float samplePointShift, float sampleWindow) -{ - MCS_ASSERT_PARAM(r1svHandle != NULL); - MCS_ASSERT_PARAM(voltPu > 0.0f); - MCS_ASSERT_PARAM(sampleWindow > 0.0f && sampleWindow < 1.0f); - MCS_ASSERT_PARAM(samplePointShift > -1.0f && samplePointShift < 1.0f); - /* Initialize the phase-shift sampling window size and sampling point offset. */ - r1svHandle->samplePointShift = samplePointShift; - r1svHandle->sampleWindow = sampleWindow; - /* Initialize the Voltage per unit value */ - r1svHandle->voltPu = voltPu; - r1svHandle->oneDivVoltPu = 1.0f / voltPu; -} - -/** - * @brief R1SVPWM clear. - * @param r1svHandle The R1SVPWM handle. - * @retval None. - */ -void R1SVPWM_Clear(R1SvpwmHandle *r1svHandle) -{ - MCS_ASSERT_PARAM(r1svHandle != NULL); - /* Clear the historical values calculated by the R1 SVPWM. */ - r1svHandle->voltIndex = 0; - r1svHandle->voltIndexLast = 0; - r1svHandle->samplePoint[SOCA] = 0.0f; - r1svHandle->samplePoint[SOCB] = 0.0f; -} - -/** - * @brief Phase shift calculation for single resistance sampling. - * @param r1SvCalc R1 svpwm calculation handle. - * @param sampleWindow sample window. - * @retval None. - */ -static void R1SVPWM_PhaseShift(R1SvpwmCalcHandle *r1SvCalc, float sampleWindow) -{ - MCS_ASSERT_PARAM(r1SvCalc != NULL); - MCS_ASSERT_PARAM(sampleWindow > 0.0f && sampleWindow < 1.0f); - /* Pointer to the array of left and right comparison values. */ - float *compRight = r1SvCalc->compRight; - float *compLeft = r1SvCalc->compLeft; - /* Comparison of three levels. */ - float compMax = r1SvCalc->svCalc.comp[SVPWM_COMP_VAL_MAX]; - float compMid = r1SvCalc->svCalc.comp[SVPWM_COMP_VAL_MID]; - float compMin = r1SvCalc->svCalc.comp[SVPWM_COMP_VAL_MIN]; - /* action time of two vectors */ - float t1 = r1SvCalc->svCalc.t1; - float t2 = r1SvCalc->svCalc.t2; - /** - * PWM phase shift: - * When the action time t1 of the first vector is less than the minimum sampling window, - * the phase with the smallest comparison value(with the largest duty) shifts to the right. - */ - if (t1 < sampleWindow) { - compRight[SVPWM_COMP_VAL_MIN] = compMid - sampleWindow; - compLeft[SVPWM_COMP_VAL_MIN] = compMin + sampleWindow - t1; - } else { - compRight[SVPWM_COMP_VAL_MIN] = compMin; - compLeft[SVPWM_COMP_VAL_MIN] = compMin; - } - - /** - * When the action time t2 of the second vector is less than the minimum sampling window, - * the phase with the largest comparison value (minimum duty) shifts to the left. - */ - if (t2 < sampleWindow) { - compRight[SVPWM_COMP_VAL_MAX] = compMid + sampleWindow; - compLeft[SVPWM_COMP_VAL_MAX] = compMax - sampleWindow + t2; - } else { - compRight[SVPWM_COMP_VAL_MAX] = compMax; - compLeft[SVPWM_COMP_VAL_MAX] = compMax; - } - /* intermediate large unshifted phase */ - compRight[SVPWM_COMP_VAL_MID] = compMid; - compLeft[SVPWM_COMP_VAL_MID] = compMid; -} - -/** - * @brief The duty cycles of PWM wave of three-phase upper switches are - * calculated in the two-phase stationary coordinate system (albe). - * @param r1svHandle R1SVPWM struct handle. - * @param uAlbe Input voltage vector. - * @param dutyUvwLeft Three-phase left duty cycle. - * @param dutyUvwRight Three-phase right duty cycle. - * @retval None. - */ -void R1SVPWM_Exec(R1SvpwmHandle *r1svHandle, const AlbeAxis *uAlbe, UvwAxis *dutyUvwLeft, UvwAxis *dutyUvwRight) -{ - MCS_ASSERT_PARAM(r1svHandle != NULL); - MCS_ASSERT_PARAM(uAlbe != NULL); - MCS_ASSERT_PARAM(dutyUvwLeft != NULL); - MCS_ASSERT_PARAM(dutyUvwRight != NULL); - R1SvpwmCalcHandle r1SvCalc; - float *samplePoint = r1svHandle->samplePoint; - r1SvCalc.svCalc.vAlpha = uAlbe->alpha * r1svHandle->oneDivVoltPu; - r1SvCalc.svCalc.vBeta = uAlbe->beta * r1svHandle->oneDivVoltPu; - - /* Sector Calculation */ - SVPWM_SectorCalc(&r1SvCalc.svCalc); - /** - * In control tick k, record the sector number of the voltage vector calculated in the k–1 tick. - * For the next tick(k+1), it is the voltage vector to be applied. - * Calculate the sector number of the voltage vector that actually acts on the (k+1)th tick. - */ - r1svHandle->voltIndexLast = r1svHandle->voltIndex; - r1svHandle->voltIndex = r1SvCalc.svCalc.sectorIndex; - - if (r1SvCalc.svCalc.sectorIndex < SVPWM_SECTOR_INDEX_MIN || r1SvCalc.svCalc.sectorIndex > SVPWM_SECTOR_INDEX_MAX) { - dutyUvwLeft->u = 0.5f; - dutyUvwLeft->v = 0.5f; - dutyUvwLeft->w = 0.5f; - dutyUvwRight->u = 0.5f; - dutyUvwRight->v = 0.5f; - dutyUvwRight->w = 0.5f; - samplePoint[SOCA] = 0.5f; - samplePoint[SOCB] = 0.5f; - return; - } - /* Calculate three comparison values: max, medium, and min. */ - SVPWM_CompareValCalc(&r1SvCalc.svCalc); - /* phase shift */ - R1SVPWM_PhaseShift(&r1SvCalc, r1svHandle->sampleWindow); - - /* Set sample point SOCA */ - samplePoint[SOCA] = r1SvCalc.compRight[SVPWM_COMP_VAL_MIN] + r1svHandle->samplePointShift; - /* Set sample point SOCB */ - samplePoint[SOCB] = r1SvCalc.compRight[SVPWM_COMP_VAL_MID] + r1svHandle->samplePointShift; - /* Three-phase duty cycle data index based on sector convert */ - SVPWM_IndexConvert(&r1SvCalc.svCalc); - - dutyUvwLeft->u = r1SvCalc.compLeft[r1SvCalc.svCalc.indexU]; - dutyUvwLeft->v = r1SvCalc.compLeft[r1SvCalc.svCalc.indexV]; - dutyUvwLeft->w = r1SvCalc.compLeft[r1SvCalc.svCalc.indexW]; - dutyUvwRight->u = r1SvCalc.compRight[r1SvCalc.svCalc.indexU]; - dutyUvwRight->v = r1SvCalc.compRight[r1SvCalc.svCalc.indexV]; - dutyUvwRight->w = r1SvCalc.compRight[r1SvCalc.svCalc.indexW]; -} - -/** - * @brief The stator current uvw is reconstructed from bus current according to the sector index - * of the output voltage vector. - * @param sectorIndex Sector index of the output voltage vector. - * @param currSocA Bus current at the sample point A. - * @param currSocB Bus current at the sample point B. - * @param curr The reconstructed stator current uvw. - * @retval None. - */ -void R1CurrReconstruct(short sectorIndex, float currSocA, float currSocB, UvwAxis *curr) -{ - MCS_ASSERT_PARAM(curr != NULL); - /* Reconstructed uvw three-phase current */ - float u; - float v; - float w; - - /* - * The stator current uvw is reconstructed from bus current according to the sector index - * of the output voltage vector. - */ - switch (sectorIndex) { - case SVPWM_ANGLE_0_TO_60_DEG: /* 0 ~ 60° Voltage vector sector */ - u = currSocA; - w = -currSocB; - v = -u - w; - break; - case SVPWM_ANGLE_60_TO_120_DEG: /* 60 ~ 120° Voltage vector sector */ - v = currSocA; - w = -currSocB; - u = -v - w; - break; - case SVPWM_ANGLE_120_TO_180_DEG: /* 120 ~ 180° Voltage vector sector */ - v = currSocA; - u = -currSocB; - w = -u - v; - break; - case SVPWM_ANGLE_180_TO_240_DEG: /* 180 ~ 240° Voltage vector sector */ - w = currSocA; - u = -currSocB; - v = -u - w; - break; - case SVPWM_ANGLE_240_TO_300_DEG: /* 240 ~ 300° Voltage vector sector */ - w = currSocA; - v = -currSocB; - u = -v - w; - break; - case SVPWM_ANGLE_300_TO_360_DEG: /* 300 ~ 360° Voltage vector sector */ - u = currSocA; - v = -currSocB; - w = -u - v; - break; - default: - u = 0.0f; - v = 0.0f; - w = 0.0f; - break; - } - curr->u = u; - curr->v = v; - curr->w = w; -} diff --git a/middleware/control_library/mcs_r1_svpwm.h b/middleware/control_library/mcs_r1_svpwm.h deleted file mode 100644 index ceec2ef1a0e7536c30da00a3781b19552ef00fb8..0000000000000000000000000000000000000000 --- a/middleware/control_library/mcs_r1_svpwm.h +++ /dev/null @@ -1,78 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_r1_svpwm.h - * @author MCU Algorithm Team - * @brief This file provides functions declaration of Space-vector pulse-width-modulation calculations. - */ - -/* Define to prevent recursive inclusion ------------------------------------- */ -#ifndef McuMagicTag_MCS_R1_SVPWM_H -#define McuMagicTag_MCS_R1_SVPWM_H - -/* Includes ------------------------------------------------------------------*/ -#include "mcs_typedef.h" - -/** The ADC sampling twice for one resistor motor control application, SOCA + SOCB */ -#define R1_ADC_SAMPLE_NUMS 2 - -/** - * @defgroup R1_SVPWM_MODULE R1 SVPWM MODULE - * @brief The SVPWM module for R1(One Resistor) application. - * @{ - */ - -/** - * @defgroup R1_SVPWM_STRUCT R1 SVPWM STRUCT - * @brief The SVPWM module's struct definition for R1(One Resistor) application. - * @{ - */ -/* Typedef definitions -------------------------------------------------------*/ -/** - * @brief R1SVPWM struct members and parameters. - */ -typedef struct { - float voltPu; /**< Voltage per unit value. */ - float oneDivVoltPu; /**< Reciprocal of voltage unit value. */ - float sampleWindow; /**< Sampling Window */ - float samplePointShift; /**< Sampling point phase shift */ - short voltIndex; /**< Index of voltage sector. */ - short voltIndexLast; /**< Index of last voltage sector. */ - float samplePoint[R1_ADC_SAMPLE_NUMS]; /**< Sample point of twice sample. */ -} R1SvpwmHandle; -/** - * @} - */ - -/** - * @defgroup R1_SVPWM_API R1 SVPWM API - * @brief The SVPWM module's API declaration for R1(One Resistor) application. - * @{ - */ -void R1SVPWM_Init(R1SvpwmHandle *r1svHandle, float voltPu, float samplePointShift, float sampleWindow); -void R1SVPWM_Clear(R1SvpwmHandle *r1svHandle); -void R1SVPWM_Exec(R1SvpwmHandle *r1svHandle, const AlbeAxis *uAlbe, UvwAxis *dutyUvwLeft, UvwAxis *dutyUvwRight); -void R1CurrReconstruct(short sectorIndex, float currSocA, float currSocB, UvwAxis *curr); -/** - * @} - */ - -/** - * @} - */ - -#endif /* McuMagicTag_MCS_SVPWM_H */ diff --git a/middleware/control_library/mcs_ramp_mgmt.c b/middleware/control_library/mcs_ramp_mgmt.c deleted file mode 100644 index c4ded265c216ab048178e0a926918df9d09ac118..0000000000000000000000000000000000000000 --- a/middleware/control_library/mcs_ramp_mgmt.c +++ /dev/null @@ -1,77 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_ramp_mgmt.c - * @author MCU Algorithm Team - * @brief This file provides function of ramp function. - */ - -#include "mcs_ramp_mgmt.h" -#include "mcs_assert.h" - -/** - * @brief Initializer of RMG handle. - * @param rmgHandle: Pointer of RMG handle. - * @param ctrlPeriod: Control period of the RMG module. - * @param slope: Target value divide time of variation. - * @retval None. - */ -void RMG_Init(RmgHandle *rmgHandle, float ctrlPeriod, float slope) -{ - MCS_ASSERT_PARAM(rmgHandle != NULL); - MCS_ASSERT_PARAM(ctrlPeriod > 0.0f); - MCS_ASSERT_PARAM(slope > 0.0f); - /* Initializer of RMG handle. */ - rmgHandle->delta = ctrlPeriod * slope; - rmgHandle->yLast = 0.0f; - rmgHandle->ctrlPeriod = ctrlPeriod; - rmgHandle->slope = slope; -} - -/** - * @brief Clear historical values of RMG handle. - * @param rmgHandle: Pointer of RMG handle. - * @retval None. - */ -void RMG_Clear(RmgHandle *rmgHandle) -{ - MCS_ASSERT_PARAM(rmgHandle != NULL); - rmgHandle->yLast = 0.0f; -} - -/** - * @brief Ramp generation and management. - * @param rmgHandle: Pointer of RMG handle. - * @param targetVal: The target value. - * @retval The reference value which is ramped. - */ -float RMG_Exec(RmgHandle *rmgHandle, float targetVal) -{ - MCS_ASSERT_PARAM(rmgHandle != NULL); - float out; - /* Calculate the current output value based on the target value and slope. */ - if (rmgHandle->yLast < targetVal) { - out = rmgHandle->yLast + rmgHandle->delta; - } else if (rmgHandle->yLast > targetVal) { - out = rmgHandle->yLast - rmgHandle->delta; - } else { - out = rmgHandle->yLast; - } - /* Recording and outputting slope calculation results. */ - rmgHandle->yLast = out; - return out; -} diff --git a/middleware/control_library/mcs_ramp_mgmt.h b/middleware/control_library/mcs_ramp_mgmt.h deleted file mode 100644 index d823eab187b2ca3ebf4fad7c8c81c6690a538cc7..0000000000000000000000000000000000000000 --- a/middleware/control_library/mcs_ramp_mgmt.h +++ /dev/null @@ -1,69 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_ramp_mgmt.h - * @author MCU Algorithm Team - * @brief Ramp generation and management for motor control. - * This file provides functions declaration of ramp generation and management module. - */ - -/* Define to prevent recursive inclusion ------------------------------------------------------- */ -#ifndef McuMagicTag_MCS_RAMP_MGMT_H -#define McuMagicTag_MCS_RAMP_MGMT_H - -/** - * @defgroup RAMP_MODULE RAMP MODULE - * @brief The RAMP management module. - * @{ - */ - -/** - * @defgroup RAMP_STRUCT RAMP STRUCT - * @brief The RAMP management data structure. - * @{ - */ -/* Typedef definitions ------------------------------------------------------------------------- */ -/** - * @brief Ramp mgmt Struct. - */ -typedef struct { - float delta; /**< Step value per calculate period. */ - float yLast; /**< History value of output value. */ - float ctrlPeriod; /**< Control period of the RMG module. */ - float slope; /**< Slope, target value divide time of variation. */ -} RmgHandle; -/** - * @} - */ - -/** - * @defgroup RAMP_API RAMP API - * @brief The RAMP API definitions. - * @{ - */ -void RMG_Init(RmgHandle *rmgHandle, float ctrlPeriod, float slope); -void RMG_Clear(RmgHandle *rmgHandle); -float RMG_Exec(RmgHandle *rmgHandle, float targetVal); -/** - * @} - */ - -/** - * @} - */ - -#endif diff --git a/middleware/control_library/mcs_smo_4th.c b/middleware/control_library/mcs_smo_4th.c deleted file mode 100644 index 4c94d9d83cd8f7965ff8525eb79e6185c694b234..0000000000000000000000000000000000000000 --- a/middleware/control_library/mcs_smo_4th.c +++ /dev/null @@ -1,165 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_smo_4th.c - * @author MCU Algorithm Team - * @brief This file provides function of 4th order smo function. - */ - -#include "mcs_smo_4th.h" -#include "mcs_math.h" -#include "mcs_math_const.h" - - -/** - * @brief internal initial function for PLL - * @param pll The PLL handle for SMO observer. - * @param smo The SMO handle. - */ -static void PLL_Init(PllHandle *pll, Smo4thHandle *smo) -{ - /* clear PI */ - PID_Reset(&pll->pi); - pll->ctrlPeriod = smo->ts; - /* Init PI parameters with given bandwidth */ - pll->pi.kp = (1.414f) * smo->pllBdw; - pll->pi.ki = smo->pllBdw * smo->pllBdw * smo->ts; - pll->pi.upperLimit = 5000.0f; - pll->pi.lowerLimit = -pll->pi.upperLimit; - pll->minAmp = 0.1f; - pll->freq = 0.0f; - pll->ratio = (65536.0f) * pll->ctrlPeriod; - pll->angle = 0; -} - -/** - * @brief The 4th SMO observer initial function. - * @param smo The SMO handle. - * @param ld The motor's D-axis inductance Ld. - * @param lq The motor's Q-axis inductance Lq. - * @param rs The motor's resistor value. - * @param ts control period - */ -void SMO4TH_Init(Smo4thHandle *smo, float ld, float lq, float rs, float ts) -{ - /* give SMO observer the motor parameter for current & voltage calculation */ - smo->ld = ld; - smo->lq = lq; - smo->rs = rs; - smo->ts = ts; - /* SMO parameter init from user */ - smo->kd = SPECIAL_SMO4TH_KD; - smo->kq = SPECIAL_SMO4TH_KQ; - smo->pllBdw = SPECIAL_SMO4TH_PLL_BDW; - SMO4TH_Clear(smo); - PLL_Init(&smo->pll, smo); - FoLowPassFilterInit(&smo->spdFilter, ts, SPECIAL_SMO4TH_SPD_FILTER_CUTOFF_FREQ); -} - -/** - * @brief Set kd, kq, pll bandwidth and cut-off frequency for 4TH smo, etc. - * @param smo The SMO handle. - * @param kd The d-axis gain. - * @param kq The q-axis gain. - * @param pllBdw The PLL bandwidth. - * @param cutOffFreq The first-order low pass filter cut-off frequency. - */ -void Set_SMO4TH_PARAM(Smo4thHandle *smo, float kd, float kq, float pllBdw, float cutOffFreq) -{ - smo->kd = kd; - smo->kq = kq; - smo->pllBdw = pllBdw; - smo->spdFilter.fc = cutOffFreq; -} - -/** - * @brief Clear function, put initial zero to voltage, current, etc. - * @param smo The SMO handle. - */ -void SMO4TH_Clear(Smo4thHandle *smo) -{ - /* zero all current & voltage first */ - smo->currAlbeEst.alpha = 0.0f; - smo->currAlbeEst.beta = 0.0f; - smo->emfAlbeEst.alpha = 0.0f; - smo->emfAlbeEst.beta = 0.0f; - PLL_Clear(&smo->pll); - FoFilterClear(&smo->spdFilter); -} - -/** - * @brief Calculate estimated current in the SMO observer. - * @param smo The SMO handle. - * @param currAlbeFbk Feedback current in Alpha-Beta axis. - * @param voltAlbeRef Voltage reference in Alpha-Beta axis. - */ -static void SMO4TH_CurrEstCalc(Smo4thHandle *smo, AlbeAxis *currAlbeFbk, AlbeAxis *voltAlbeRef) -{ - float ld = smo->ld; - float lq = smo->lq; - float rs = smo->rs; - float ts = smo->ts; - float kd = smo->kd; - float kq = smo->kq; - /* use more local variables */ - float currEstA = smo->currAlbeEst.alpha; - float currEstB = smo->currAlbeEst.beta; - AlbeAxis *emfAlbe = &(smo->emfAlbeEst); - AlbeAxis *currAlbe = &(smo->currAlbeEst); - float ia; - float ib; - float eVa; - float eVb; - float iEstSignA; - float iEstSignB; - - /* use Rad in calculation */ - float weEst = smo->spdEstHz * DOUBLE_PI; - AlbeAxis eAlbeEst = smo->emfAlbeEst; - AlbeAxis *iAlbeFbk = currAlbeFbk; - AlbeAxis *uAlbeRef = voltAlbeRef; - iEstSignA = ((currEstA - iAlbeFbk->alpha) > 0.0f) ? (1.0f) : (-1.0f); - iEstSignB = ((currEstB - iAlbeFbk->beta) > 0.0f) ? (1.0f) : (-1.0f); - - /* calculate estimated current */ - ia = (-rs * currEstA - weEst * (ld - lq) * currEstB + uAlbeRef->alpha - eAlbeEst.alpha) / ld - kd * iEstSignA; - ib = (weEst * (ld - lq) * currEstA - rs * currEstB + uAlbeRef->beta - eAlbeEst.beta) / ld - kd * iEstSignB; - /* estimated current alpha, beta */ - currAlbe->alpha += ts * ia; - currAlbe->beta += ts * ib; - - /* calculate estimate back EMF */ - eVa = -weEst * eAlbeEst.beta + (kd * ld * kq * iEstSignA - kd * ld * weEst * iEstSignB); - eVb = weEst * eAlbeEst.alpha + (kd * ld * weEst * iEstSignA + kd * ld * kq * iEstSignB); - /* estimated emf alpha, beta */ - emfAlbe->alpha += ts * eVa; - emfAlbe->beta += ts * eVb; -} - -/** - * @brief Excute the 4th SMO observer. - * @param smo the SMO handle. - * @param currAlbeFbk current feedback in Alpha-Beta coordinate. - * @param voltAlbeRef voltage feedback in Alpha-Beta coordinate. - */ -void SMO4TH_Exec(Smo4thHandle *smo, AlbeAxis *currAlbeFbk, AlbeAxis *voltAlbeRef) -{ - SMO4TH_CurrEstCalc(smo, currAlbeFbk, voltAlbeRef); - PLL_Exec(&smo->pll, -smo->emfAlbeEst.alpha, smo->emfAlbeEst.beta); - smo->elecAngle = smo->pll.angle; - smo->spdEstHz = FoLowPassFilterExec(&smo->spdFilter, smo->pll.freq); -} \ No newline at end of file diff --git a/middleware/control_library/mcs_smo_4th.h b/middleware/control_library/mcs_smo_4th.h deleted file mode 100644 index 692b19e991fb4bc8aec9a6216105bc1323755cf0..0000000000000000000000000000000000000000 --- a/middleware/control_library/mcs_smo_4th.h +++ /dev/null @@ -1,61 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_smo_4th.h - * @author MCU Algorithm Team - * @brief This file provides functions declaration of 4th order smo module. - */ -#ifndef McuMagicTag_MCS_SMO_4TH_H -#define McuMagicTag_MCS_SMO_4TH_H - -#include "mcs_typedef.h" -#include "mcs_pll.h" -#include "mcs_filter.h" - -#define SPECIAL_SMO4TH_PLL_BDW (30.0f * 6.28318f) -#define SPECIAL_SMO4TH_SPD_FILTER_CUTOFF_FREQ (40.0f) -#define SPECIAL_SMO4TH_KD (300.0f) -#define SPECIAL_SMO4TH_KQ (2000.0f) - -typedef struct { - /* Model parameters */ - float ld; - float lq; - float rs; - float ts; - /* Internal variable */ - AlbeAxis currAlbeEst; - AlbeAxis emfAlbeEst; - PllHandle pll; - signed short elecAngle; - FoFilterHandle spdFilter; - float spdEstHz; - /* observer gain */ - float kd; - float kq; - float pllBdw; -} Smo4thHandle; - -void SMO4TH_Init(Smo4thHandle *smo, float ld, float lq, float rs, float ts); - -void SMO4TH_Clear(Smo4thHandle *smo); - -void Set_SMO4TH_PARAM(Smo4thHandle *smo, float kd, float kq, float pllBdw, float cutOffFreq); - -void SMO4TH_Exec(Smo4thHandle *smo, AlbeAxis *currAlbeFbk, AlbeAxis *voltAlbeRef); - -#endif \ No newline at end of file diff --git a/middleware/control_library/mcs_spd_ctrl.c b/middleware/control_library/mcs_spd_ctrl.c deleted file mode 100644 index 78e3288a13801f897f21aa1e1e7f454b565148f1..0000000000000000000000000000000000000000 --- a/middleware/control_library/mcs_spd_ctrl.c +++ /dev/null @@ -1,73 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_spd_ctrl.c - * @author MCU Algorithm Team - * @brief This file provides function of motor speed control. - */ - -#include "typedefs.h" -#include "mcs_spd_ctrl.h" -#include "mcs_assert.h" - -/** - * @brief Reset the speed controller, fill with zero, NULL. - * @param spdHandle Speed controller struct handle. - * @retval None. - */ -void SPDCTRL_Reset(SpdCtrlHandle *spdHandle) -{ - MCS_ASSERT_PARAM(spdHandle != NULL); - /* Reset speed ring PI */ - PID_Reset(&spdHandle->spdPi); - /* Reset the speed controller, fill with zero, NULL. */ - spdHandle->trqLimit = 0.0f; - spdHandle->mtrParam = NULL; - spdHandle->ctrlPeriod = 0.0f; -} - -/** - * @brief Clear historical values of speed controller. - * @param spdHandle Speed controller struct handle. - * @retval None. - */ -void SPDCTRL_Clear(SpdCtrlHandle *spdHandle) -{ - MCS_ASSERT_PARAM(spdHandle != NULL); - PID_Clear(&spdHandle->spdPi); -} - -/** - * @brief Simplified speed controller PI calculation. - * @param spdHandle Speed controller struct handle. - * @param spdTarget The target speed value (Hz). - * @param spdFdbk Motor electrical speed (Hz). - * @param currRef Dq-axis currents reference which is the output of speed controller. - * @retval None. - */ -void SPDCTRL_Exec(SpdCtrlHandle *spdHandle, float spdTarget, float spdFdbk, DqAxis *currRef) -{ - float teRef; - - MCS_ASSERT_PARAM(spdHandle != NULL); - MCS_ASSERT_PARAM(currRef != NULL); - /* Speed error calculation */ - spdHandle->spdPi.error = spdTarget - spdFdbk; - /* Performs simplified speed PI controller calculations, static clamping, no feedforward */ - teRef = PI_Exec(&spdHandle->spdPi); - currRef->q = teRef; -} diff --git a/middleware/control_library/mcs_spd_ctrl.h b/middleware/control_library/mcs_spd_ctrl.h deleted file mode 100644 index 0e868fa661354247a9ee63ab2138031f6f5cc56c..0000000000000000000000000000000000000000 --- a/middleware/control_library/mcs_spd_ctrl.h +++ /dev/null @@ -1,73 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_spd_ctrl.h - * @author MCU Algorithm Team - * @brief Speed controller for motor control. - * This file provides functions declaration of the speed controller module. - */ - -/* Define to prevent recursive inclusion ------------------------------------------------------- */ -#ifndef McuMagicTag_MCS_SPD_CTRL_H -#define McuMagicTag_MCS_SPD_CTRL_H - -/* Includes ------------------------------------------------------------------------------------ */ -#include "mcs_typedef.h" -#include "mcs_pid_ctrl.h" -#include "mcs_mtr_param.h" - -/** - * @defgroup SPEED_CONTROLLER SPEED CONTROLLER - * @brief The speed controller module - * @{ - */ - -/** - * @defgroup SPEED_CONTROLLER_STRUCT SPEED CONTROLLER STRUCT - * @brief The speed controller data struct. - * @{ - */ -/* Typedef definitions ------------------------------------------------------------------------- */ -/** - * @brief Speed controller struct members and parameters. - */ -typedef struct { - PidHandle spdPi; /**< PI controller struct in the speed controller. */ - float trqLimit; /**< Maximum of the speed controller output torque (Nm). */ - MtrParamHandle *mtrParam; /**< Motor parameters. */ - float ctrlPeriod; /**< Speed controller control period (s). */ -} SpdCtrlHandle; -/** - * @} - */ - -/** - * @defgroup SPEED_CONTROLLER_API SPEED CONTROLLER API - * @brief The speed controller API declaration. - * @{ - */ -void SPDCTRL_Reset(SpdCtrlHandle *spdHandle); -void SPDCTRL_Clear(SpdCtrlHandle *spdHandle); -void SPDCTRL_Exec(SpdCtrlHandle *spdHandle, float spdTarget, float spdFdbk, DqAxis *currRef); -/** - * @} - */ - -/** - * @} - */ -#endif diff --git a/middleware/control_library/mcs_startup.c b/middleware/control_library/mcs_startup.c deleted file mode 100644 index f14891b71b59759147b127a63eb06af9a0acf3d7..0000000000000000000000000000000000000000 --- a/middleware/control_library/mcs_startup.c +++ /dev/null @@ -1,76 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_startup.c - * @author MCU Algorithm Team - * @brief This file provides transition method from startup stage to run stage。 - */ - -#include "mcs_startup.h" -#include "mcs_math.h" -#include "mcs_assert.h" - -/** - * @brief Init the startup control handle. - * @param startHandle The startup coontrol handle. - * @param spdBegin The begin speed for transition process. - * @param spdEnd The end speed for transition process. - * @retval None. - */ -void STARTUP_Init(StartupHandle *startHandle, float spdBegin, float spdEnd) -{ - MCS_ASSERT_PARAM(startHandle != NULL); - MCS_ASSERT_PARAM(spdBegin > 0.0f); - MCS_ASSERT_PARAM(spdEnd > 0.0f); - MCS_ASSERT_PARAM(spdBegin < spdEnd); - startHandle->stage = STARTUP_STAGE_CURR; - startHandle->spdBegin = spdBegin; - startHandle->spdEnd = spdEnd; - /* current AMP = slope * control period */ - startHandle->regionInv = 1.0f / (startHandle->spdEnd - startHandle->spdBegin); -} - -/** - * @brief Clear hisitory value, assign the stage to current change. - * @param startHandle The startup control handle. - * @retval None. - */ -void STARTUP_Clear(StartupHandle *startHandle) -{ - MCS_ASSERT_PARAM(startHandle != NULL); - startHandle->stage = STARTUP_STAGE_CURR; -} - -/** - * @brief Calculate the reference current in the startup stage. - * @param startHandle The startup control handle. - * @param refHz The speed reference in the startup stage. - * @return The current AMP. - */ -float STARTUP_CurrCal(const StartupHandle *startHandle, float refHz) -{ - float out; - float tmp; - - MCS_ASSERT_PARAM(startHandle != NULL); - /* Calculate the reference current in the startup stage */ - tmp = startHandle->spdEnd - Abs(refHz); - tmp = tmp * startHandle->regionInv; - out = tmp * startHandle->initCurr; - - return out; -} diff --git a/middleware/control_library/mcs_startup.h b/middleware/control_library/mcs_startup.h deleted file mode 100644 index ae4c28df4ea44cbbd9c83e7eb1a6f2eb76141c66..0000000000000000000000000000000000000000 --- a/middleware/control_library/mcs_startup.h +++ /dev/null @@ -1,82 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_startup.h - * @author MCU Algorithm Team - * @brief Motor transition process from one speed and angle to another speed and angle. - */ - -/* Define to prevent recursive inclusion ------------------------------------------------------- */ -#ifndef McuMagicTag_STARTUP_H -#define McuMagicTag_STARTUP_H - -/** - * @defgroup STARTUP_MODULE STARTUP MODULE - * @brief The startup management module. - * @{ - */ - -/** - * @defgroup STARTUP_STRUCT STARTUP STRUCT - * @brief The startup management data struct definition. - * @{ - */ -/* Typedef definitions ------------------------------------------------------------------------- */ -/** - * @brief Startup process enum. - * @details Speed transition stages: - * + STARTUP_STAGE_CURR -- Stage of current AMP is changing - * + STARTUP_STAGE_SPD -- Stage of speed is changing - * + STARTUP_STAGE_SWITCH -- Stage of switch - */ -typedef enum { - STARTUP_STAGE_CURR = 1, - STARTUP_STAGE_SPD, - STARTUP_STAGE_SWITCH -} Startup_Stage; - -/** - * @brief Startup handover method struct members and parameters. - */ -typedef struct { - Startup_Stage stage; /**< Startup switching status. */ - float spdBegin; /**< Startup switching start speed (Hz). */ - float spdEnd; /**< Startup switching end speed (Hz). */ - float regionInv; /**< Inverse of the speed region. */ - float initCurr; /**< The initial current (A). */ -} StartupHandle; -/** - * @} - */ - -/** - * @defgroup STARTUP_API STARTUP API - * @brief The startup management API declaration. - * @{ - */ -void STARTUP_Init(StartupHandle *startHandle, float spdBegin, float spdEnd); -void STARTUP_Clear(StartupHandle *startHandle); -float STARTUP_CurrCal(const StartupHandle *startHandle, float refHz); -/** - * @} - */ - -/** - * @} - */ - -#endif diff --git a/middleware/control_library/mcs_svpwm.c b/middleware/control_library/mcs_svpwm.c deleted file mode 100644 index 589f5da17fffebafe90374817edea6e4c2cdd3b3..0000000000000000000000000000000000000000 --- a/middleware/control_library/mcs_svpwm.c +++ /dev/null @@ -1,202 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_svpwm.c - * @author MCU Algorithm Team - * @brief This file provides function of Space-Vector Pulse-Width-Modulation(SVPWM) calculations. - */ - -#include "mcs_svpwm.h" -#include "mcs_math_const.h" -#include "mcs_assert.h" - -/* Macro definitions ---------------------------------------------------------*/ -/** - * @brief Initialzer of SVPWM handle. - * @param svHandle The SVPWM handle. - * @param voltPu The per-unit voltage value. - * @retval None. - */ -void SVPWM_Init(SvpwmHandle *svHandle, float voltPu) -{ - MCS_ASSERT_PARAM(svHandle != NULL); - MCS_ASSERT_PARAM(voltPu > 0.0f); - svHandle->voltPu = voltPu; - svHandle->oneDivVoltPu = 1.0f / voltPu; -} - -/** - * @brief Calculate svpwm sector. - * @param svCalc The svpwm calc struct. - * @retval None. - */ -void SVPWM_SectorCalc(SvpwmCalcHandle *svCalc) -{ - MCS_ASSERT_PARAM(svCalc != NULL); - /* The initial sector is 0. */ - svCalc->sectorIndex = 0; - /* Three-level voltage calculation */ - svCalc->volt[SVPWM_VOLT_0] = svCalc->vBeta; - svCalc->volt[SVPWM_VOLT_1] = SQRT3_DIV_TWO * svCalc->vAlpha - 0.5f * svCalc->vBeta; - svCalc->volt[SVPWM_VOLT_2] = -SQRT3_DIV_TWO * svCalc->vAlpha - 0.5f * svCalc->vBeta; - - /* sector index calculate && calculate abs values (V) */ - if (svCalc->volt[SVPWM_VOLT_0] > 0.0f) { - svCalc->sectorIndex += SVPWM_SECTOR_ADD_1; - } else { - svCalc->volt[SVPWM_VOLT_0] = -svCalc->volt[SVPWM_VOLT_0]; - } - if (svCalc->volt[SVPWM_VOLT_1] > 0.0f) { - svCalc->sectorIndex += SVPWM_SECTOR_ADD_2; - } else { - svCalc->volt[SVPWM_VOLT_1] = -svCalc->volt[SVPWM_VOLT_1]; - } - if (svCalc->volt[SVPWM_VOLT_2] > 0.0f) { - svCalc->sectorIndex += SVPWM_SECTOR_ADD_4; - } else { - svCalc->volt[SVPWM_VOLT_2] = -svCalc->volt[SVPWM_VOLT_2]; - } -} - -/** - * @brief Calculate three comparison values: max, medium, and min.. - * @param svCalc The svpwm calc struct. - * @retval None. - */ -void SVPWM_CompareValCalc(SvpwmCalcHandle *svCalc) -{ - MCS_ASSERT_PARAM(svCalc != NULL); - /* Calculate the action time of the two vectors based on the sector. */ - switch (svCalc->sectorIndex) { - case SVPWM_ANGLE_0_TO_60_DEG: /* 0 ~ 60° Voltage vector sector */ - svCalc->t1 = svCalc->volt[SVPWM_VOLT_1]; - svCalc->t2 = svCalc->volt[SVPWM_VOLT_0]; - break; - case SVPWM_ANGLE_60_TO_120_DEG: /* 60 ~ 120° Voltage vector sector */ - svCalc->t1 = svCalc->volt[SVPWM_VOLT_1]; - svCalc->t2 = svCalc->volt[SVPWM_VOLT_2]; - break; - case SVPWM_ANGLE_120_TO_180_DEG: /* 120 ~ 180° Voltage vector sector */ - svCalc->t1 = svCalc->volt[SVPWM_VOLT_0]; - svCalc->t2 = svCalc->volt[SVPWM_VOLT_2]; - break; - case SVPWM_ANGLE_180_TO_240_DEG: /* 180 ~ 240° Voltage vector sector */ - svCalc->t1 = svCalc->volt[SVPWM_VOLT_0]; - svCalc->t2 = svCalc->volt[SVPWM_VOLT_1]; - break; - case SVPWM_ANGLE_240_TO_300_DEG: /* 240 ~ 300° Voltage vector sector */ - svCalc->t1 = svCalc->volt[SVPWM_VOLT_2]; - svCalc->t2 = svCalc->volt[SVPWM_VOLT_1]; - break; - case SVPWM_ANGLE_300_TO_360_DEG: /* 300 ~ 360° Voltage vector sector */ - svCalc->t1 = svCalc->volt[SVPWM_VOLT_2]; - svCalc->t2 = svCalc->volt[SVPWM_VOLT_0]; - break; - default: - break; - } - - if ((svCalc->t1 + svCalc->t2) > 1.0f) { - svCalc->t1 = svCalc->t1 / (svCalc->t1 + svCalc->t2); - svCalc->t2 = 1.0f - svCalc->t1; - } - /* The action time of two vectors is converted to three comparison values. */ - svCalc->comp[SVPWM_COMP_VAL_MIN] = (1.0f - svCalc->t1 - svCalc->t2) * 0.5f; - svCalc->comp[SVPWM_COMP_VAL_MID] = svCalc->comp[SVPWM_COMP_VAL_MIN] + svCalc->t1; - svCalc->comp[SVPWM_COMP_VAL_MAX] = svCalc->comp[SVPWM_COMP_VAL_MID] + svCalc->t2; -} - -/** - * @brief Three-phase duty cycle data index based on sector convert. - * @param svCalc The svpwm calc struct. - * @retval None. - */ -void SVPWM_IndexConvert(SvpwmCalcHandle *svCalc) -{ - MCS_ASSERT_PARAM(svCalc != NULL); - /* Three-phase duty cycle data index based on sector convert */ - switch (svCalc->sectorIndex) { - case SVPWM_ANGLE_0_TO_60_DEG: /* 0 ~ 60° Voltage vector sector */ - svCalc->indexU = SVPWM_COMP_VAL_MIN; - svCalc->indexV = SVPWM_COMP_VAL_MID; - svCalc->indexW = SVPWM_COMP_VAL_MAX; - break; - case SVPWM_ANGLE_60_TO_120_DEG: /* 60 ~ 120° Voltage vector sector */ - svCalc->indexU = SVPWM_COMP_VAL_MID; - svCalc->indexV = SVPWM_COMP_VAL_MIN; - svCalc->indexW = SVPWM_COMP_VAL_MAX; - break; - case SVPWM_ANGLE_120_TO_180_DEG: /* 120 ~ 180° Voltage vector sector */ - svCalc->indexU = SVPWM_COMP_VAL_MAX; - svCalc->indexV = SVPWM_COMP_VAL_MIN; - svCalc->indexW = SVPWM_COMP_VAL_MID; - break; - case SVPWM_ANGLE_180_TO_240_DEG: /* 180 ~ 240° Voltage vector sector */ - svCalc->indexU = SVPWM_COMP_VAL_MAX; - svCalc->indexV = SVPWM_COMP_VAL_MID; - svCalc->indexW = SVPWM_COMP_VAL_MIN; - break; - case SVPWM_ANGLE_240_TO_300_DEG: /* 240 ~ 300° Voltage vector sector */ - svCalc->indexU = SVPWM_COMP_VAL_MID; - svCalc->indexV = SVPWM_COMP_VAL_MAX; - svCalc->indexW = SVPWM_COMP_VAL_MIN; - break; - case SVPWM_ANGLE_300_TO_360_DEG: /* 300 ~ 360° Voltage vector sector */ - svCalc->indexU = SVPWM_COMP_VAL_MIN; - svCalc->indexV = SVPWM_COMP_VAL_MAX; - svCalc->indexW = SVPWM_COMP_VAL_MID; - break; - default: - break; - } -} - -/** - * @brief The duty cycles of PWM wave of three-phase upper switches are - * calculated in the two-phase stationary coordinate system (albe). - * @param svHandle The SVPWM struct handle. - * @param uAlbe Input voltage vector. - * @param dutyUvw Three-phase A compare value. - * @retval None. - */ -void SVPWM_Exec(const SvpwmHandle *svHandle, const AlbeAxis *uAlbe, UvwAxis *dutyUvw) -{ - MCS_ASSERT_PARAM(svHandle != NULL); - MCS_ASSERT_PARAM(uAlbe != NULL); - MCS_ASSERT_PARAM(dutyUvw != NULL); - SvpwmCalcHandle svCalc; - - svCalc.vAlpha = uAlbe->alpha * svHandle->oneDivVoltPu; - svCalc.vBeta = uAlbe->beta * svHandle->oneDivVoltPu; - /* Voltage vector sector calculation */ - SVPWM_SectorCalc(&svCalc); - /* Check whether the current sector is abnormal. */ - if (svCalc.sectorIndex < SVPWM_SECTOR_INDEX_MIN || svCalc.sectorIndex > SVPWM_SECTOR_INDEX_MAX) { - dutyUvw->u = 0.5f; - dutyUvw->v = 0.5f; - dutyUvw->w = 0.5f; - return; - } - /* Calculate three comparison values: max, medium, and min. */ - SVPWM_CompareValCalc(&svCalc); - /* Three-phase duty cycle data index based on sector convert */ - SVPWM_IndexConvert(&svCalc); - /* Output UVW three-phase duty cycle */ - dutyUvw->u = svCalc.comp[svCalc.indexU]; - dutyUvw->v = svCalc.comp[svCalc.indexV]; - dutyUvw->w = svCalc.comp[svCalc.indexW]; -} diff --git a/middleware/control_library/mcs_svpwm.h b/middleware/control_library/mcs_svpwm.h deleted file mode 100644 index 46319df664cb93d6d6becd13d028c7820bd0736c..0000000000000000000000000000000000000000 --- a/middleware/control_library/mcs_svpwm.h +++ /dev/null @@ -1,117 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_svpwm.h - * @author MCU Algorithm Team - * @brief This file provides functions declaration of Space-Vector Pulse-Width-Modulation(SVPWM) calculations. - */ - -/* Define to prevent recursive inclusion ------------------------------------- */ -#ifndef McuMagicTag_MCS_SVPWM_H -#define McuMagicTag_MCS_SVPWM_H - -/* Includes ------------------------------------------------------------------*/ -#include "mcs_typedef.h" - -/** Voltage vector sector */ -#define SVPWM_ANGLE_0_TO_60_DEG 3 -#define SVPWM_ANGLE_60_TO_120_DEG 1 -#define SVPWM_ANGLE_120_TO_180_DEG 5 -#define SVPWM_ANGLE_180_TO_240_DEG 4 -#define SVPWM_ANGLE_240_TO_300_DEG 6 -#define SVPWM_ANGLE_300_TO_360_DEG 2 - -/** The U-V-W phase compare value's index of APT timers. */ -#define SVPWM_COMP_VAL_MAX 2 -#define SVPWM_COMP_VAL_MID 1 -#define SVPWM_COMP_VAL_MIN 0 -#define SVPWM_COMP_VAL_TOTAL 3 - -/** The three voltage level to compare, for sector index decision. */ -#define SVPWM_VOLT_0 0 -#define SVPWM_VOLT_1 1 -#define SVPWM_VOLT_2 2 -#define SVPWM_VOLT_TOTAL 3 - -/** Sector index calculate: N = A + 2B + 4C */ -#define SVPWM_SECTOR_ADD_1 1 -#define SVPWM_SECTOR_ADD_2 2 -#define SVPWM_SECTOR_ADD_4 4 - -#define SVPWM_SECTOR_INDEX_MIN 1 -#define SVPWM_SECTOR_INDEX_MAX 6 - -/** - * @defgroup SVPWM_MODULE SVPWM MODULE - * @brief The Space-Vector Pulse-Width-Modulation(SVPWM) module. - * @{ - */ - -/** - * @defgroup SVPWM_STRUCT SVPWM STRUCT - * @brief The SVPWM module's data struct definition. - * @{ - */ - -/* Typedef definitions -------------------------------------------------------*/ -/** - * @brief SVPWM struct members and parameters. - */ -typedef struct { - float voltPu; /**< Voltage per unit value. */ - float oneDivVoltPu; /**< Reciprocal of voltage unit value. */ -} SvpwmHandle; - -/** - * @brief Structure of temporary variables for SVPWM calculation. - */ -typedef struct { - float vAlpha; /**< Voltage vector. */ - float vBeta; /**< Voltage vector. */ - float t1; /**< T1 are the action times of the sequential action vectors. */ - float t2; /**< T2 are the action times of the sequential action vectors. */ - unsigned short indexU; /**< U-phase duty cycle conversion index */ - unsigned short indexV; /**< V-phase duty cycle conversion index */ - unsigned short indexW; /**< W-phase duty cycle conversion index */ - short int sectorIndex; /**< Sector index */ - float volt[SVPWM_VOLT_TOTAL]; /**< temporary voltage to calculate sector index */ - float comp[SVPWM_COMP_VAL_TOTAL]; /**< Duty cycle corresponding to the comparison value */ -} SvpwmCalcHandle; - -/** - * @} - */ - -/** - * @defgroup SVPWM_API SVPWM API - * @brief The SVPWM module's API declaration. - * @{ - */ -void SVPWM_Init(SvpwmHandle *svHandle, float voltPu); -void SVPWM_SectorCalc(SvpwmCalcHandle *svCalc); -void SVPWM_CompareValCalc(SvpwmCalcHandle *svCalc); -void SVPWM_IndexConvert(SvpwmCalcHandle *svCalc); -void SVPWM_Exec(const SvpwmHandle *svHandle, const AlbeAxis *uAlbe, UvwAxis *dutyUvw); -/** - * @} - */ - -/** - * @} - */ - -#endif /* McuMagicTag_MCS_SVPWM_H */ diff --git a/middleware/control_library/mcs_typedef.h b/middleware/control_library/mcs_typedef.h deleted file mode 100644 index 1eb03ffc6f467cd8c6890edc43dc2a1852d32455..0000000000000000000000000000000000000000 --- a/middleware/control_library/mcs_typedef.h +++ /dev/null @@ -1,64 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file mcs_typedef.h - * @author MCU Algorithm Team - * @brief This file provides the definition of the motor basic data structure. - */ - -/* Define to prevent recursive inclusion ------------------------------------- */ -#ifndef McuMagicTag_MCS_TYPEDEF_H -#define McuMagicTag_MCS_TYPEDEF_H - -/* Typedef definitions -------------------------------------------------------*/ - -/** - * @defgroup MCS COORDINATE - * @brief Motor Basic coordinate data structures. - * @{ - */ - -/** - * @brief Rotor synchronous rotation coordinate frame Variables. - */ -typedef struct { - float d; /**< Component d of the rotor synchronous rotation coordinate variable. */ - float q; /**< Component q of the rotor synchronous rotation coordinate variable. */ -} DqAxis; - -/** - * @brief Two-phase stationary coordinate frame variable. - */ -typedef struct { - float alpha; /**< Component alpha of the two-phase stationary coordinate variable. */ - float beta; /**< Component beta of the two-phase stationary coordinate variable. */ -} AlbeAxis; - -/** - * @brief Three-phase static coordinate frame variable. - */ -typedef struct { - float u; /**< Component u of the three-phase static coordinate frame variable. */ - float v; /**< Component v of the three-phase static coordinate frame variable. */ - float w; /**< Component w of the three-phase static coordinate frame variable. */ -} UvwAxis; - -/** - * @} - */ - -#endif /* McuMagicTag_MCS_TYPEDEF_H */ diff --git a/middleware/control_library/pfc_curr_ctrl.c b/middleware/control_library/pfc_curr_ctrl.c deleted file mode 100644 index 76a54ccb34f8c2db6271f0cf88e868b481d31cbc..0000000000000000000000000000000000000000 --- a/middleware/control_library/pfc_curr_ctrl.c +++ /dev/null @@ -1,49 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file pfc_curr_ctrl.c - * @author MCU Algorithm Team - * @brief This file provides function of power factor correction(PFC) current control - */ -#include "pfc_curr_ctrl.h" -#include "mcs_assert.h" - -/** - * @brief Clear historical values of power factor correction(PFC) current controller. - * @param currCtrl PFC current control structure - * @retval None. - */ -void PFC_CurrCtrlClear(PFC_CurrCtrlHandle *currCtrl) -{ - MCS_ASSERT_PARAM(currCtrl != NULL); - currCtrl->currPiCtrl.differ = 0.0f; - currCtrl->currPiCtrl.integral = 0.0f; -} - -/** - * @brief Simplified power factor correction(PFC) current controller PI calculation. - * @param currCtrl PFC current control structure - * @retval None. - */ -void PFC_CurrCtrlExec(PFC_CurrCtrlHandle *currCtrl) -{ - MCS_ASSERT_PARAM(currCtrl != NULL); - /* Calculate the current error of power factor correction(PFC). */ - currCtrl->currPiCtrl.error = currCtrl->currRef - currCtrl->unitCurrFdbk; - /* Calculation the output pwm duty of power factor correction(PFC) current. */ - currCtrl->pwmDuty = PI_Exec(&currCtrl->currPiCtrl); -} diff --git a/middleware/control_library/pfc_curr_ctrl.h b/middleware/control_library/pfc_curr_ctrl.h deleted file mode 100644 index 7635ca8f173cce8fdfa65cad4b73dbba462f7bea..0000000000000000000000000000000000000000 --- a/middleware/control_library/pfc_curr_ctrl.h +++ /dev/null @@ -1,75 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file pfc_curr_ctrl.h - * @author MCU Algorithm Team - * @brief Current loop control. This file provides function of power factor correction(PFC) current control - */ -/* Define to prevent recursive inclusion ------------------------------------------------------- */ -#ifndef McuMagicTag_PFC_CURR_CTRL_H -#define McuMagicTag_PFC_CURR_CTRL_H - -/* Includes ------------------------------------------------------------------------------------ */ -#include "mcs_pid_ctrl.h" - -/** - * @defgroup PFC_CURRENT_CONTROLLER PFC_CURRENT CONTROLLER MODULE - * @brief The current controller function. - * @{ - */ - -/** - * @defgroup PFC_CURRENT_CONTROLLER_STRUCT PFC_CURRENT CONTROLLER STRUCT - * @brief The current controller's data structure definition. - * @{ - */ - -/* Typedef definitions ------------------------------------------------------------------------- */ -/** - * @brief current Controller Struct members and parameters. - */ -typedef struct { - float currRef; /**< current loop control reference current(A) */ - float currFdbk; /**< current loop control feedback current(A) */ - float unitCurrFdbk; /**< current loop control feedback unitary current */ - float maxCurrFdbk; /**< current loop control max feedback current(A) */ - float startCurrFdbk; /**< current loop control start feedback current(A) */ - float stopCurrFdbk; /**< current loop control stop feedback current(A) */ - PidHandle currPiCtrl; /**< current loop controller define */ - float pwmDuty; /**< current loop control pulse width modulation(PWM) duty output */ - float rectVoltFdbk; /**< current loop control rectified feedback voltage(V) */ - float unitRectVoltFdbk; /**< current loop control rectified feedback unitary voltage */ -} PFC_CurrCtrlHandle; -/** - * @} - */ - -/** - * @defgroup PFC_CURRENT_CONTROLLER_API PFC_CURRENT CONTROLLER API - * @brief The current controller's API declaration. - * @{ - */ -void PFC_CurrCtrlClear(PFC_CurrCtrlHandle *currCtrl); -void PFC_CurrCtrlExec(PFC_CurrCtrlHandle *currCtrl); -/** - * @} - */ - -/** - * @} - */ -#endif /* McuMagicTag_PFC_CURR_CTRL_H */ diff --git a/middleware/control_library/pfc_volt_ctrl.c b/middleware/control_library/pfc_volt_ctrl.c deleted file mode 100644 index c087dc23f120b470412f0b8a6f24108112d5ac36..0000000000000000000000000000000000000000 --- a/middleware/control_library/pfc_volt_ctrl.c +++ /dev/null @@ -1,73 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file pfc_volt_ctrl.c - * @author MCU Algorithm Team - * @brief This file provides function of power factor correction(PFC) voltage control - */ -#include "pfc_volt_ctrl.h" -#include "mcs_math.h" -#include "mcs_assert.h" - -/** - * @brief Clear historical values of power factor correction(PFC) voltage controller. - * @param voltCtrl PFC voltage control structure - * @retval None. - */ -void PFC_VoltCtrlClear(PFC_VoltCtrlHandle *voltCtrl) -{ - MCS_ASSERT_PARAM(voltCtrl != NULL); - voltCtrl->voltPiCtrl.differ = 0.0f; - voltCtrl->voltPiCtrl.integral = 0.0f; -} - -/** - * @brief Execute simplified PI controller calculation, static clamping, no feedfoward - * @param handle PI controller struct handle. - * @retval PI control output. - */ -float PI_PfcExec(PidHandle *pidHandle) -{ - MCS_ASSERT_PARAM(pidHandle != NULL); - /* Proportional Item */ - float p = pidHandle->kp * pidHandle->error; - - /* Integral Item */ - float i = pidHandle->ki * pidHandle->error + pidHandle->integral; - i = Clamp(i, pidHandle->saturation, pidHandle->lowerLimit); - pidHandle->integral = i; - - /* static clamping and output calculaiton */ - float val = p + i; - float out = Clamp(val, pidHandle->upperLimit, pidHandle->lowerLimit); - - return out; -} - -/** - * @brief Simplified power factor correction(PFC) voltage controller PI calculation. - * @param voltCtrl PFC voltage control structure - * @retval None. - */ -void PFC_VoltCtrlExec(PFC_VoltCtrlHandle *voltCtrl) -{ - MCS_ASSERT_PARAM(voltCtrl != NULL); - /* Calculate the voltage error of power factor correction(PFC). */ - voltCtrl->voltPiCtrl.error = voltCtrl->voltRef - voltCtrl->unitVoltFdbk; - /* Calculation the voltage loop control output of power factor correction(PFC). */ - voltCtrl->voltOut = PI_PfcExec(&voltCtrl->voltPiCtrl); -} diff --git a/middleware/control_library/pfc_volt_ctrl.h b/middleware/control_library/pfc_volt_ctrl.h deleted file mode 100644 index 1488519a86d11cf443104648520b45e2207681d8..0000000000000000000000000000000000000000 --- a/middleware/control_library/pfc_volt_ctrl.h +++ /dev/null @@ -1,72 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file pfc_volt_ctrl.h - * @author MCU Algorithm Team - * @brief Voltage loop control. This file provides function of power factor correction(PFC) voltage control - */ -/* Define to prevent recursive inclusion ------------------------------------------------------- */ -#ifndef McuMagicTag_PFC_VOLT_CTRL_H -#define McuMagicTag_PFC_VOLT_CTRL_H - -/* Includes ------------------------------------------------------------------------------------ */ -#include "mcs_pid_ctrl.h" - -/** - * @defgroup VOLTAGE_CONTROLLER VOLTAGE CONTROLLER MODULE - * @brief The voltage controller function. - * @{ - */ - -/** - * @defgroup VOLTAGE_CONTROLLER_STRUCT VOLTAGE CONTROLLER STRUCT - * @brief The voltage controller's data structure definition. - * @{ - */ - -/* Typedef definitions ------------------------------------------------------------------------- */ -/** - * @brief Voltage controller struct. - */ -typedef struct { - float voltRef; /**< voltage loop control reference voltage(V) */ - float voltFdbk; /**< voltage loop control feedback voltage(V) */ - float unitVoltFdbk; /**< voltage loop control feedback unitary voltage */ - float startVolt; /**< voltage loop control start voltage(V) */ - PidHandle voltPiCtrl; /**< voltage loop controller define */ - float voltOut; /**< voltage loop control output */ -} PFC_VoltCtrlHandle; -/** - * @} - */ - -/** - * @defgroup VOLTAGE_CONTROLLER_API VOLTAGE CONTROLLER API - * @brief The voltage controller's API declaration. - * @{ - */ -void PFC_VoltCtrlClear(PFC_VoltCtrlHandle *voltCtrl); -float PI_PfcExec(PidHandle *pidHandle); -void PFC_VoltCtrlExec(PFC_VoltCtrlHandle *voltCtrl); -/** - * @} - */ - -/** - * @} - */ -#endif /* McuMagicTag_PFC_VOLT_CTRL_H */ diff --git a/middleware/hisilicon/loaderboot/BUILD.gn b/middleware/hisilicon/loaderboot/BUILD.gn deleted file mode 100644 index 17ccd8437f87b88673e96f2604a482cc55415740..0000000000000000000000000000000000000000 --- a/middleware/hisilicon/loaderboot/BUILD.gn +++ /dev/null @@ -1,131 +0,0 @@ -import("//build/toolchain/config.gni") -set_defaults("executable") { - cflags = [ - "-Os", - "-pipe", - "-W", - "-Wextra", - "-Wmissing-declarations", - "-Winit-self", - "-Wmissing-include-dirs", - "-Wtrampolines", - "-Wundef", - "-Wpointer-arith", - "-Wlogical-op", - "-Wstrict-prototypes", - "-Wmissing-prototypes", - "-Wjump-misses-init", - "-Wformat=2", - "-Wfloat-equal", - "-Wdate-time", - "-Wswitch-default", - "-Wimplicit-fallthrough=2", - "-Wno-missing-declarations", - "-std=gnu99", - "-fsigned-char", - "-fno-builtin", - "-ffreestanding", - "-nostdlib", - "-fno-exceptions", - "-fno-unwind-tables", - "-fno-short-enums", - "-fno-common", - "-freg-struct-return", - "-mabi=ilp32", - "-march=rv32imc", - "-fno-strict-aliasing", - "-fdata-sections", - "-ffunction-sections", - "-falign-functions=2", - "-fno-schedule-insns", - "-fno-optimize-strlen", - "-fno-aggressive-loop-optimizations", - "-Wa,-enable-c-lbu-sb", - "-Wa,-enable-c-lhu-sh", - "-msave-restore", - "-msmall-data-limit=0", - "-fimm-compare", - "-femit-muliadd", - "-fmerge-immshf", - "-femit-uxtb-uxth", - "-femit-lli", - "-fldm-stm-optimize", - "-fstack-protector-strong", - "-fno-inline-small-functions", - "-fsingle-precision-constant" - ] - asmflags = [] - ldflags = [ - "-Wl,-Map,bin/loader.map", - "-Wl,--enjal16", - "-Wl,--gc-section", - "-nostdlib", - "-static", - "-lgcc", - "-lc", - "-T../scripts/loaderboot.lds", - ] - defines = [ - ] - if(build_type == "debug") { - cflags += [ - "-g" - ] - }else if(build_type == "release") { - cflags += [ - "-fomit-frame-pointer" - ] - defines += [ - "NDEBUG" - ] - } -} -executable("loader.elf") { - sources = [ - "//startup/riscv_init.S", - "//source/main.c", - "//source/loader/src/cmd.c", - "//source/loader/src/reset.c", - "//source/loader/src/loadertype.c", - "//source/loader/src/handshake.c", - "//source/loader/src/uart_rcv.c", - "//source/loader/src/uart_xmit.c", - "//source/loader/src/stack_protect.c", - "//source/drivers_adapt/src/flash_adapt.c", - "//source/drivers_adapt/src/uart_adapt.c", - "//source/drivers_adapt/src/crc_adapt.c", - "//source/drivers_adapt/src/timer_adapt.c", - "//source/fake_drivers/crg/src/crg.c", - "//drivers/crc/crc_v0/src/crc.c", - "//drivers/timer/timer_v0/src/timer.c", - "//drivers/flash/flash_v0/src/flash.c", - "//drivers/uart/uart_v0/src/uart.c", - "//drivers/base/base_v0/src/interrupt.c", - "//drivers/base/base_v0/src/clock.c", - "//drivers/dma/dma_v0/src/dma.c", - "//chip/3065h/chipinit/systickinit/systickinit.c", - ] - include_dirs = [ - "//include", - "//generatecode", - "//chip/3065h", - "//chip/3065h/ip_crg", - "//chip/3065h/chipinit/systickinit", - "//drivers/base/base_v0/inc", - "//drivers/base/common/inc", - "//drivers/dma/dma_v0/inc", - "//drivers/dma/common/inc", - "//drivers/timer/timer_v0/inc", - "//drivers/timer/common/inc", - "//drivers/crc/crc_v0/inc", - "//drivers/crc/common/inc", - "//drivers/flash/flash_v0/inc", - "//drivers/flash/common/inc", - "//drivers/uart/uart_v0/inc", - "//drivers/uart/common/inc", - "//source/loader/inc", - "//source/drivers_adapt/inc", - "//source/fake_drivers/crg/common/inc", - "//source/fake_drivers/crg/inc", - ] -} diff --git a/middleware/hisilicon/loaderboot/build.py b/middleware/hisilicon/loaderboot/build.py deleted file mode 100644 index 84564e3ccf34bca3b48beea491e4a2c3daeabd16..0000000000000000000000000000000000000000 --- a/middleware/hisilicon/loaderboot/build.py +++ /dev/null @@ -1,143 +0,0 @@ -# !/usr/bin/env python -# -*- coding: utf-8 -*- - -# @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. -# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the -# following conditions are met: -# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following -# disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the -# following disclaimer in the documentation and/or other materials provided with the distribution. -# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote -# products derived from this software without specific prior written permission. -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE -# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# build.py Function implementation: Build the compilation framework and -# compile the project. - -import sys -import os -import pathlib -import subprocess -import shlex -import shutil -import stat -import re - - -def copy_code(cpy_dir): - ''' - Function description: Code copy phase for CI build work. - ''' - src_list = [] - target_list = [] - cur_path = pathlib.Path.cwd() - base = os.path.realpath(cur_path.joinpath("../../..")) - for i in cpy_dir: - src_list.append(os.path.realpath(cur_path.joinpath(base, i))) - target_list.append(os.path.realpath(cur_path.joinpath(cur_path, i))) - - index = 0 - for dir_path in src_list: - if pathlib.Path(dir_path).exists(): - if not pathlib.Path(target_list[index]).exists(): - shutil.copytree(dir_path, target_list[index]) - index += 1 - - -def get_chipname_in_gn(gn): - with open(gn, 'r', encoding='UTF-8') as f: - buf = f.readlines() - for line in buf: - if re.search(r'//chip', line) != None: - chip_name = line.split('/')[3] - return chip_name - raise Exception('Error: Get Chip Name fail.') - - -def replace_string_in_files(gn, chipname): - file_data = '' - with open(gn, "r", encoding='UTF-8') as f: - buf = f.readlines() - for line in buf: - line = line.replace(chipname['oldname'], chipname['newname']) - file_data += line - flags = os.O_WRONLY | os.O_CREAT | os.O_TRUNC - modes = stat.S_IWUSR | stat.S_IRUSR - with os.fdopen(os.open(gn, flags, modes), 'w+') as gn_file: - gn_file.writelines(file_data) - - -def modify_build_gn(): - cur_path = pathlib.Path.cwd() - chip_dir = os.path.realpath(cur_path.joinpath('chip')) - dirs = os.listdir(chip_dir) - build_gn = os.path.realpath(cur_path.joinpath('BUILD.gn')) - old_chip_name = get_chipname_in_gn(build_gn) - for chip_name in dirs: - if chip_name != 'target': - replace_dict = {'newname':chip_name, 'oldname':old_chip_name} - replace_string_in_files(build_gn, replace_dict) - return - raise Exception('Error: Get Chip Dir Fail.') - - -def main(argv): - ''' - Function description: build and compile entry function. - ''' - source_dir = ['chip', - 'drivers', - 'generatecode'] - copy_code(source_dir) - modify_build_gn() - - cmd = shlex.split('gn gen out --root=. --dotfile=build/\.gn') - proc = subprocess.Popen(cmd, shell=False) - proc.wait() - ret_code = proc.returncode - if ret_code != 0: - raise Exception("CI {} failed, return code is {}".format(cmd, ret_code)) - - cmd = shlex.split('ninja -C out') - proc = subprocess.Popen(cmd, shell=False) - proc.wait() - ret_code = proc.returncode - if ret_code != 0: - raise Exception("CI {} failed, return code is {}".format(cmd, - ret_code)) - - file_abspath = pathlib.Path().cwd().joinpath("out", "bin", "loader.elf") - bin_abspath = pathlib.Path().cwd().joinpath("loader.bin") - cmd = ['riscv32-linux-musl-objcopy', '-Obinary', - str(file_abspath), str(bin_abspath)] - process = subprocess.Popen(cmd, shell=False) - process.wait() - ret_code = process.returncode - if ret_code != 0: - raise Exception("{} failed, return code is {}".format('bin_file', - ret_code)) - - list_path = file_abspath.parent.joinpath('{}.list' - .format(file_abspath.stem)) - if list_path.exists(): - os.remove(list_path) - flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL - modes = stat.S_IWUSR | stat.S_IRUSR - with os.fdopen(os.open(list_path, flags, modes), 'w+') as list_file: - cmd = ['riscv32-linux-musl-objdump', '-S', str(file_abspath)] - process = subprocess.Popen(cmd, stdout=list_file, shell=False) - process.wait() - ret_code = process.returncode - if ret_code != 0: - raise Exception("{} failed, return code is {}"\ - .format('bin_file', ret_code)) - - -if __name__ == "__main__": - sys.exit(main(sys.argv)) diff --git a/middleware/hisilicon/loaderboot/build/.gn b/middleware/hisilicon/loaderboot/build/.gn deleted file mode 100644 index 635f8a208ea872c9cab85e5de11c19920218e2c7..0000000000000000000000000000000000000000 --- a/middleware/hisilicon/loaderboot/build/.gn +++ /dev/null @@ -1,19 +0,0 @@ -# @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. -# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the -# following conditions are met: -# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following -# disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the -# following disclaimer in the documentation and/or other materials provided with the distribution. -# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote -# products derived from this software without specific prior written permission. -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE -# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# The location of the build configuration file. - -buildconfig = "//build/config/BUILDCONFIG.gn" diff --git a/middleware/hisilicon/loaderboot/build/config/BUILDCONFIG.gn b/middleware/hisilicon/loaderboot/build/config/BUILDCONFIG.gn deleted file mode 100644 index fe46d1a13e22c23b676f3e306fb4e76b131d89bc..0000000000000000000000000000000000000000 --- a/middleware/hisilicon/loaderboot/build/config/BUILDCONFIG.gn +++ /dev/null @@ -1,22 +0,0 @@ -# @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. -# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the -# following conditions are met: -# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following -# disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the -# following disclaimer in the documentation and/or other materials provided with the distribution. -# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote -# products derived from this software without specific prior written permission. -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE -# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# BUILD.gn Function implementation: Selecting the default compilation toolchain - -import("//build/toolchain/config.gni") - -set_default_toolchain("//build/toolchain:riscv32_hcc") - diff --git a/middleware/hisilicon/loaderboot/build/toolchain/BUILD.gn b/middleware/hisilicon/loaderboot/build/toolchain/BUILD.gn deleted file mode 100644 index 282da139fe593eb7d8f6c12f4c4e3968e3863490..0000000000000000000000000000000000000000 --- a/middleware/hisilicon/loaderboot/build/toolchain/BUILD.gn +++ /dev/null @@ -1,28 +0,0 @@ -# @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. -# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the -# following conditions are met: -# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following -# disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the -# following disclaimer in the documentation and/or other materials provided with the distribution. -# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote -# products derived from this software without specific prior written permission. -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE -# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# BUILD.gn Function implementation: Pre-configuration of the Compilation Toolchain - -import("//build/toolchain/config.gni") - -hcc_toolchain("riscv32_hcc") { - build_compiler_prefix = "riscv32-linux-musl" - cc = "${build_compiler_prefix}-gcc" - cxx = "${build_compiler_prefix}-g++" - ar = "${build_compiler_prefix}-ar" - ld = cc -} - diff --git a/middleware/hisilicon/loaderboot/build/toolchain/config.gni b/middleware/hisilicon/loaderboot/build/toolchain/config.gni deleted file mode 100644 index 9d2155f256be86283f29fe25e87f3fc0de7ff0a2..0000000000000000000000000000000000000000 --- a/middleware/hisilicon/loaderboot/build/toolchain/config.gni +++ /dev/null @@ -1,131 +0,0 @@ -# @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. -# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the -# following conditions are met: -# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following -# disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the -# following disclaimer in the documentation and/or other materials provided with the distribution. -# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote -# products derived from this software without specific prior written permission. -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE -# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# config.gni Function implementation: Global parameter definition and template configuration - -declare_args() { - build_type = "" - build_compiler_specified = "" -} - -template("hcc_toolchain") { - toolchain(target_name) { - assert(defined(invoker.ar), "gcc toolchain must specify a \"ar\" value") - assert(defined(invoker.cc), "gcc toolchain must specify a \"cc\" value") - assert(defined(invoker.cxx), "gcc toolchain must specify a \"cxx\" value") - assert(defined(invoker.ld), "gcc toolchain must specify a \"ld\" value") - - cc = invoker.cc - cxx = invoker.cxx - ar = invoker.ar - ld = invoker.ld - - need_strip = false - if(defined(invoker.strip)) { - strip = invoker.strip - need_strip = true - } - - tool("cc") { - depfile = "{{output}}.d" - command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} -c {{source}} -o {{output}}" - depsformat = "gcc" - description = "cross compiler {{output}}" - outputs = [ - "{{source_out_dir}}/{{source_name_part}}.o", - ] - } - tool("cxx") { - depfile = "{{output}}.d" - command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} -c {{source}} -o {{output}}" - depsformat = "gcc" - description = "CXX {{output}}" - outputs = [ - "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o", - ] - } - tool("asm") { - depfile = "{{output}}.d" - command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{asmflags}} -c {{source}} -o {{output}}" - depsformat = "gcc" - description = "cross compiler {{output}}" - outputs = [ - "{{source_out_dir}}/{{source_name_part}}.o" - ] - } - tool("alink") { - outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}" - rspfile = "{{output}}.rsp" - rspfile_content = "{{inputs}}" - command = "$ar cr {{output}} @\"$rspfile\"" - - description = "AR {{output}}" - outputs = [ - outfile - ] - - default_output_dir = "{{root_out_dir}}/libs" - default_output_extension = ".a" - output_prefix = "lib" - } - tool("solink") { - outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}" - rspfile = "{{output}}.rsp" - rspfile_content = "{{inputs}}" - command = "$ld -shared -Wl,--start-group {{ldflags}} " + - "{{inputs}} {{libs}} -Wl,--end-group -o $outfile" - if(need_strip) { - command += "&& $strip $outfile" - } - description = "SOLINK $outfile" - outputs = [ - outfile - ] - - default_output_dir = "{{root_out_dir}}" - default_output_extension = ".so" - output_prefix = "lib" - } - tool("link") { - outfile = "{{output_dir}}/bin/{{target_output_name}}{{output_extension}}" - rspfile = "$outfile.rsp" - command = "$ld -Wl,--start-group {{ldflags}} " + - "{{inputs}} {{libs}} -Wl,--end-group -o $outfile " - if(need_strip) { - command += "&& $strip $outfile" - } - - description = "LINK $outfile" - default_output_dir = "{{root_out_dir}}" - rspfile_content = "{{inputs}}" - outputs = [ - outfile - ] - } - tool("stamp") { - if (host_os == "win") { - command = "cmd /c type nul > \"{{output}}\"" - } else { - command = "/usr/bin/touch {{output}}" - } - description = "STAMP {{output}}" - } - tool("copy") { - command = "cp -afd {{source}} {{output}}" - description = "COPY {{source}} {{output}}" - } - } -} \ No newline at end of file diff --git a/middleware/hisilicon/loaderboot/include/loaderboot.h b/middleware/hisilicon/loaderboot/include/loaderboot.h deleted file mode 100644 index f630e7025abf2b3ad84c62da1df3dad5b0b34430..0000000000000000000000000000000000000000 --- a/middleware/hisilicon/loaderboot/include/loaderboot.h +++ /dev/null @@ -1,79 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file loaderboot.h - * @author MCU Driver Team - * @brief Header file containing typedef and function as follow. - * @details Register manipulation macro and Error Number - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef McuMagicTag_LOADERBOOT_H -#define McuMagicTag_LOADERBOOT_H - -/* Includes ------------------------------------------------------------------*/ -#include "typedefs.h" -#include "utils.h" - -/* Macro definitions ---------------------------------------------------------*/ -#ifdef FPGA -#define FLASH_SUPPORT -#ifdef FLASH_SUPPORT -#define CONFIG_CPU_CLOCK (40 * 1000 * 1000) -#else /* FPGA SRAM Version */ -#define CONFIG_CPU_CLOCK (60 * 1000 * 1000) -#endif -#else /* ASIC Version */ -#define CONFIG_CPU_CLOCK (25 * 1000 * 1000) -#endif - -#define CONFIG_LS_CLOCK (CONFIG_CPU_CLOCK / 2) -#define CONFIG_UART_CLOCK CONFIG_LS_CLOCK - -#if !defined(FPGA) || defined(FLASH_SUPPORT) -#define EFLASH_ENABLE 1 -#else -#define EFLASH_ENABLE 0 -#endif - -#define SC_LOCKEN_VALUE (0xEA510000) /** undo lock need to write to SC_LOCKEN */ - -#define BOOTROM_FINISH (1 << 0) /* bootrom finish flag, 0: not finish, 1: finished */ -#define UPDATE_MODE (1 << 4) /* Update mode bit in SC_SYS_STATE, 0:don't update 1: update */ - -#define MS_PER_SEC 1000 -#define US_PER_MS 1000 -#define US_PER_SEC (MS_PER_SEC * US_PER_MS) -#define FREQ_1M 1000000 - -/* Typedef definitions -------------------------------------------------------*/ - -typedef enum { - LOADERBOOT_V1, /* Loader support download one image */ - LOADERBOOT_V2, /* Loader support handshake and download images */ -} LOADER_VER; - - -/* Functions -----------------------------------------------------------------*/ - -void Reset(void); - -LOADER_VER GetLoaderType(void); - -void SetLoaderType(LOADER_VER type); - -#endif /* McuMagicTag_LOADERBOOT_H */ diff --git a/middleware/hisilicon/loaderboot/include/utils.h b/middleware/hisilicon/loaderboot/include/utils.h deleted file mode 100644 index c64e6ab42d961f708ebfd200ccd6f99be40da433..0000000000000000000000000000000000000000 --- a/middleware/hisilicon/loaderboot/include/utils.h +++ /dev/null @@ -1,108 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file utils.h - * @author MCU Driver Team - * @brief Header file containing typedef and function of utils. - */ - -#ifndef McuMagicTag_UTILS_H -#define McuMagicTag_UTILS_H - -/* - * byte and bit offset in unsigned int - */ -#define BYTE_0 0 -#define BYTE_0_OFFSET 24 -#define BYTE_1 1 -#define BYTE_1_OFFSET 16 -#define BYTE_2 2 -#define BYTE_2_OFFSET 8 -#define BYTE_3 3 - -#define OFFSETOF(struct_t, member) ((unsigned int)&((struct_t *)0)->member) - -/** - * @brief Get the Min Value - * @param a number 1 - * @param b number 2 - * @retval int The min Value - */ -static inline unsigned int GetMinValue(unsigned int a, unsigned int b) -{ - return a < b ? a : b; -} - -/** - * @brief Merge two byte into unsigned int short - * @param highByte Byte in higher - * @param lowByte Byte in lower - * @retval unsigned short Converted value - */ -static inline unsigned short MergeToUshort(unsigned char highByte, unsigned char lowByte) -{ - return (highByte << 0x8) + lowByte; /* Make highByte in the high 8 bit */ -} - -/** - * @brief Endian conversion - * @param buf Perform a pointer of the char type of a 32-bit integer - * @retval unsigned int Converted value - */ -static inline unsigned int BigEndianToUint(const unsigned char *buf) -{ - unsigned int i = 0; - unsigned int sum; - if (buf == NULL) { - return 0; - } - sum = buf[i++] << BYTE_0_OFFSET; - sum += buf[i++] << BYTE_1_OFFSET; - sum += buf[i++] << BYTE_2_OFFSET; - sum += buf[i++]; - return sum; -} - -/** - * @brief Host sequence to network byte sequence conversion - * @param data Integer to be converted - * @param buf The result of the conversion - * @retval None - */ -static inline void UintToBigEndian(unsigned int data, unsigned char *const buf) -{ - unsigned int i = 0; - buf[i++] = (unsigned char)((data >> BYTE_0_OFFSET) & 0xFF); - buf[i++] = (unsigned char)((data >> BYTE_1_OFFSET) & 0xFF); - buf[i++] = (unsigned char)((data >> BYTE_2_OFFSET) & 0xFF); - buf[i] = (unsigned char)(data & 0xFF); -} - -/** - * @brief Host sequence to network byte sequence conversion - * @param data Unsigned short to be converted - * @param buf The result of the conversion - * @retval None - */ -static inline void UShortToBigEndian(unsigned short data, unsigned char *const buf) -{ - unsigned int i = 0; - buf[i++] = (unsigned char)((data >> 0x8) & 0xFF); /* get the higher 8 bit of unsigned short */ - buf[i] = (unsigned char)(data & 0xFF); -} - -#endif \ No newline at end of file diff --git a/middleware/hisilicon/loaderboot/loader.bin b/middleware/hisilicon/loaderboot/loader.bin deleted file mode 100644 index 4e4c92e2ab7a7bad49cfe0ef979de335fe4bb160..0000000000000000000000000000000000000000 Binary files a/middleware/hisilicon/loaderboot/loader.bin and /dev/null differ diff --git a/middleware/hisilicon/loaderboot/scripts/loaderboot.lds b/middleware/hisilicon/loaderboot/scripts/loaderboot.lds deleted file mode 100644 index 096c1cec283b69785a5d0d69976b2a1c043aa53e..0000000000000000000000000000000000000000 --- a/middleware/hisilicon/loaderboot/scripts/loaderboot.lds +++ /dev/null @@ -1,101 +0,0 @@ - -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file loaderboot.lds - * @author MCU Driver Team - * @brief loaderboot link config file - */ - -OUTPUT_ARCH( "riscv" ) -ENTRY(_start) - -MEMORY -{ - /* ram for common bss and data */ - SRAM_DATA(xrw) : ORIGIN = 0x4000000+5K,LENGTH = 1K - - /* ram for stack */ - SRAM_STACK(xrw) : ORIGIN = 0x4000000+6K,LENGTH = 2K - - /* ram for loaderboot */ - SRAM_ITCAM_CODE(rx): ORIGIN = 0x2000000,LENGTH = 5K -} - -STACK_SIZE = 2k-300; -NMI_STACK_SIZE = 200; - -SECTIONS -{ - /* The startup code goes first into FLASH */ - .text.entry : ALIGN(4) - { - KEEP(*(.text.entry)) - } > SRAM_ITCAM_CODE - - /* Stack in SRAM_DATA at Highest addresses */ - .stacks (NOLOAD) : - { - . = ALIGN(4); - __SYSTEM_STACK_BEGIN__ = ORIGIN(SRAM_STACK); - KEEP(*(.stacks)) - __SYSTEM_STACK_END__ = ORIGIN(SRAM_STACK) + STACK_SIZE; - . = ALIGN(0x20); - __nmi_stack_bottom = .; - . += NMI_STACK_SIZE; - __nmi_stack_top = .; - } > SRAM_STACK - __SYSTEM_STACK_SIZE__ = __SYSTEM_STACK_END__ - __SYSTEM_STACK_BEGIN__; - __stack_top = __SYSTEM_STACK_END__; - - .text : ALIGN(4) - { - __start_addr = .; - *(.text*) - *(.ram.text*) - . = ALIGN(4); - __rodata_start = .; - *(.rodata*) - *(.got*) - . = ALIGN(4); - __rodata_end = .; - __text_end = .; - } > SRAM_ITCAM_CODE - - /* data section */ - .data : ALIGN(4) - { - __data_load = LOADADDR(.data); - __data_start = .; - *(.data*) - . = ALIGN(4); - __data_end = .; - } > SRAM_DATA AT > SRAM_ITCAM_CODE - __data_size = __data_end - __data_start; - __global_pointer$ = __data_start + (__data_size / 2); - - /* bss section */ - .bss (NOLOAD) : ALIGN(4) - { - __bss_begin__ = .; - *(.bss*) - *(COMMON) - . = ALIGN(4); - __bss_end__ = .; - } > SRAM_DATA AT > SRAM_ITCAM_CODE - __bss_size__ = __bss_end__ - __bss_begin__; -} diff --git a/middleware/hisilicon/loaderboot/source/drivers_adapt/inc/crc_adapt.h b/middleware/hisilicon/loaderboot/source/drivers_adapt/inc/crc_adapt.h deleted file mode 100644 index 5fb9205e444a349df9eba7152339c38e7fd5359a..0000000000000000000000000000000000000000 --- a/middleware/hisilicon/loaderboot/source/drivers_adapt/inc/crc_adapt.h +++ /dev/null @@ -1,39 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file crc_adapt.h - * @author MCU Driver Team - * @brief Header file containing adapter functions of crc - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef McuMagicTag_CRC_ADAPT_H -#define McuMagicTag_CRC_ADAPT_H - -/* Includes ------------------------------------------------------------------*/ -#include "baseinc.h" - -/* Macro definitions ---------------------------------------------------------*/ -#define CRC_8_BIT 8 /**< Number of bits read each time */ - -/* Functions -----------------------------------------------------------------*/ -void CRC_Init(void); -unsigned int CRC_Generate(const unsigned char *buf, unsigned int len); -bool CRC_Check(const unsigned char *buf, unsigned int len, unsigned int crc); -bool CRC_AccCheck(const unsigned char *buf, unsigned int len, unsigned int crc); - -#endif /* McuMagicTag_CRC_OP_H */ diff --git a/middleware/hisilicon/loaderboot/source/drivers_adapt/inc/flash_adapt.h b/middleware/hisilicon/loaderboot/source/drivers_adapt/inc/flash_adapt.h deleted file mode 100644 index 6630ace34106c61d72482c716875f2f540f6bfe9..0000000000000000000000000000000000000000 --- a/middleware/hisilicon/loaderboot/source/drivers_adapt/inc/flash_adapt.h +++ /dev/null @@ -1,36 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file flash_adapt.h - * @author MCU Driver Team - * @brief Header file containing adapter functions of flash - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef McuMagicTag_FLASH_ADAPT_H -#define McuMagicTag_FLASH_ADAPT_H - -#include "baseinc.h" -#include "flash.h" - -void FLASH_Init(void); -BASE_StatusType FLASH_Erase(unsigned int addr, unsigned int len); -BASE_StatusType FLASH_Write(unsigned char *buf, unsigned int dest, unsigned int rcvLen); -BASE_StatusType FLASH_Read(const unsigned int srcAddr, unsigned int readLen, - unsigned char *dataBuff, const unsigned int buffLen); - -#endif \ No newline at end of file diff --git a/middleware/hisilicon/loaderboot/source/drivers_adapt/inc/timer_adapt.h b/middleware/hisilicon/loaderboot/source/drivers_adapt/inc/timer_adapt.h deleted file mode 100644 index 53327c60f00f9b1408a38879b98b9054bcbba90a..0000000000000000000000000000000000000000 --- a/middleware/hisilicon/loaderboot/source/drivers_adapt/inc/timer_adapt.h +++ /dev/null @@ -1,28 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file timer_adapt.h - * @author MCU Driver Team - * @brief Header file containing adapter functions of timer - */ -#ifndef McuMagicTag_TIMER_ADAPT_H -#define McuMagicTag_TIMER_ADAPT_H - -void TimerStart(unsigned int timeout); -bool IsTimerOut(void); - -#endif diff --git a/middleware/hisilicon/loaderboot/source/drivers_adapt/inc/uart_adapt.h b/middleware/hisilicon/loaderboot/source/drivers_adapt/inc/uart_adapt.h deleted file mode 100644 index 63d063f4f67a851a7c9a7750ff6b77e9d93842ff..0000000000000000000000000000000000000000 --- a/middleware/hisilicon/loaderboot/source/drivers_adapt/inc/uart_adapt.h +++ /dev/null @@ -1,58 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file uart_adapt.h - * @author MCU Driver Team - * @brief Header file containing adapter functions of uart - */ - -#ifndef McuMagicTag_UART_ADAPT_H -#define McuMagicTag_UART_ADAPT_H - -void UART_Init(unsigned int baudRate); - -void UART_DeInit(void); - -void BOOT_PutHex(unsigned int h, bool print0); - -void BOOT_Msg0(const char *s); - -void BOOT_Msg1(const char *s, unsigned int h); - -void BOOT_Msg2(const char *s, unsigned int h1, unsigned int h2); - -void BOOT_Msg4(const char *s, unsigned int h1, unsigned int h2, unsigned int h3, unsigned int h4); - -void SERIAL_SetMute(void); - -void SERIAL_CancelMute(void); - -void SERIAL_PutChar(const char c); - -void SERIAL_PutStr(const char *s); - -void SERIAL_PutBuf(const char *buffer, signed int length); - -unsigned char SERIAL_GetChar(void); - -bool SERIAL_TstChar(void); - -void SERIAL_PutHex(unsigned int h, bool printAll); - -unsigned int SERIAL_GetCharTimeout(unsigned int timeout_us, unsigned char *ch); - -#endif diff --git a/middleware/hisilicon/loaderboot/source/drivers_adapt/src/crc_adapt.c b/middleware/hisilicon/loaderboot/source/drivers_adapt/src/crc_adapt.c deleted file mode 100644 index 4065288fa26a7c385b8a082d6bb521b4bc2d45e0..0000000000000000000000000000000000000000 --- a/middleware/hisilicon/loaderboot/source/drivers_adapt/src/crc_adapt.c +++ /dev/null @@ -1,98 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file crc_adapt.c - * @author MCU Driver Team - * @brief CRC adapt module. - * @details This file provides functions about the following functionalities: - * + Generate CRC base CRC16 - * + Check CRC - */ - -/* Includes ------------------------------------------------------------------*/ -#include "crc.h" -#include "crc_adapt.h" - -/* Macro definitions ---------------------------------------------------------*/ - -/* Typedef definitions -------------------------------------------------------*/ - -/* Functions -----------------------------------------------------------------*/ -CRC_Handle crcHandle; - -/** - * @brief CRC Init Adapter - * @param None - * @retval None - */ -void CRC_Init(void) -{ - crcHandle.baseAddress = CRC; - crcHandle.algoMode = CRC16_XMODEM; - crcHandle.inputDataFormat = CRC_MODE_BIT8; /* Valid bits provided for CRC */ - crcHandle.timeout = CRC_8_BIT; - crcHandle.enableIT = false; - crcHandle.enableErrInject = false; - - HAL_CRC_Init(&crcHandle); -} - -/** - * @brief Generate CRC of buf. - * @param buf Data buffer which need generate CRC - * @param len Data buffer length - * @retval The Generated CRC - * @note crcStart must be 0 or 0xFFFF - */ -unsigned int CRC_Generate(const unsigned char *buf, unsigned int len) -{ - CRC_ASSERT_PARAM(IsCRCInstance(crcHandle.baseAddress)); - CRC_ASSERT_PARAM(buf != NULL); - return HAL_CRC_Calculate(&crcHandle, buf, len); -} - -/** - * @brief Check the CRC - * @param buf Data buffer which need generate CRC - * @param len Data buffer length - * @param crc the expect crc - * @retval true CRC OK - * @retval false CRC ERROR - */ -bool CRC_Check(const unsigned char *buf, unsigned int len, unsigned int crc) -{ - CRC_ASSERT_PARAM(IsCRCInstance(crcHandle.baseAddress)); - CRC_ASSERT_PARAM(buf != NULL); - return HAL_CRC_CheckInputData(&crcHandle, buf, len, crc); -} - - -/** - * @brief Check the CRC with seed - * @param buf Data buffer which need generate CRC - * @param len Data buffer length - * @param crc the expect crc - * @retval true CRC OK - * @retval false CRC ERROR - * @note Must follow the CRC Generate, The Output of CRC_Generate is the input of CRC_AccCheck - */ -bool CRC_AccCheck(const unsigned char *buf, unsigned int len, unsigned int crc) -{ - CRC_ASSERT_PARAM(IsCRCInstance(crcHandle.baseAddress)); - CRC_ASSERT_PARAM(buf != NULL); - return HAL_CRC_Accumulate(&crcHandle, buf, len) == crc; -} diff --git a/middleware/hisilicon/loaderboot/source/drivers_adapt/src/flash_adapt.c b/middleware/hisilicon/loaderboot/source/drivers_adapt/src/flash_adapt.c deleted file mode 100644 index 3f85775210e9b3e1ec089159fbd303206e5d1d99..0000000000000000000000000000000000000000 --- a/middleware/hisilicon/loaderboot/source/drivers_adapt/src/flash_adapt.c +++ /dev/null @@ -1,101 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file flash_adapt.c - * @author MCU Driver Team - * @brief FLASH adapt module. - * @details This file provides functions about the following functionalities: - * + Flash Init - * + Flash Write - * + Flash Read - * + Flash Erase - */ -#include "flash.h" -#include "flash_adapt.h" - -FLASH_Handle g_flashBlockingHandle; - -/** - * @brief Flash Init Adapter - * @param None - * @retval None - */ -void FLASH_Init(void) -{ - g_flashBlockingHandle.baseAddress = (EFC_RegStruct *)EFC_BASE; - g_flashBlockingHandle.peMode = FLASH_PE_OP_BLOCK; - - HAL_FLASH_Init(&g_flashBlockingHandle); -} - -/** - * @brief Flash Erase Adapter - * @param addr The earse address - * @param len The erase length - * @retval BASE_StatusType - */ -BASE_StatusType FLASH_Erase(unsigned int addr, unsigned int len) -{ - unsigned int pageNum = (len + FLASH_ONE_PAGE_SIZE - 1) / FLASH_ONE_PAGE_SIZE; - return HAL_FLASH_EraseBlocking(&g_flashBlockingHandle, FLASH_ERASE_MODE_PAGE, addr, pageNum); -} - -/** - * @brief Flash Write Adapter - * @param buf The data to be written - * @param dest The write address - * @param len The write length - * @retval BASE_StatusType - */ -BASE_StatusType FLASH_Write(unsigned char *buf, unsigned int dest, unsigned int rcvLen) -{ - if (buf == NULL) { - return BASE_STATUS_ERROR; - } - return HAL_FLASH_WriteBlocking(&g_flashBlockingHandle, (unsigned int)(uintptr_t)buf, dest, rcvLen); -} - -/** - * @brief Flash Read Adapter - * @param srcAddr Read address - * @param readLen Read length - * @param dataBuff Buffer to keep the read out data - * @param buffLen Sizeof buffer - * @retval BASE_StatusType - */ -BASE_StatusType FLASH_Read(const unsigned int srcAddr, unsigned int readLen, - unsigned char *dataBuff, const unsigned int buffLen) -{ - unsigned int *ptemp = NULL; - unsigned int *dst = NULL; - unsigned int len = readLen; - - if (dataBuff == NULL) { - return BASE_STATUS_ERROR; - } - dst = (unsigned int *)dataBuff; - - ptemp = (unsigned int *)(uintptr_t)srcAddr; - if (readLen > buffLen) { - return BASE_STATUS_ERROR; - } - len /= sizeof(unsigned int); - while (len--) { - *dst++ = *ptemp++; - } - return BASE_STATUS_OK; -} \ No newline at end of file diff --git a/middleware/hisilicon/loaderboot/source/drivers_adapt/src/timer_adapt.c b/middleware/hisilicon/loaderboot/source/drivers_adapt/src/timer_adapt.c deleted file mode 100644 index 5036a6c193346619cacd1ff1040a836d78072bd4..0000000000000000000000000000000000000000 --- a/middleware/hisilicon/loaderboot/source/drivers_adapt/src/timer_adapt.c +++ /dev/null @@ -1,59 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file timer_adapt.c - * @author MCU Driver Team - * @brief TIMER adapt module. - * @details This file provides functions about the following functionalities: - * + Start Timer - * + Check Timer is out or not - */ -#include "chipinc.h" -#include "loaderboot.h" -#include "timer.h" -#include "timer_adapt.h" - -TIMER_Handle g_htim1; - -#define TIMER_1US (HAL_CRG_GetIpFreq((void *)TIMER1_BASE) / US_PER_SEC) - -/** - * @brief Start timer. - * @param timeout Timer Timeout value, unit:us - * @retval None - */ -void TimerStart(unsigned int timeout) -{ - g_htim1.baseAddress = TIMER1; - g_htim1.load = timeout * TIMER_1US - 1; - g_htim1.bgLoad = g_htim1.load; - g_htim1.mode = TIMER_MODE_RUN_ONTSHOT; /* Run in period mode */ - g_htim1.prescaler = 0; /* Don't frequency division */ - g_htim1.size = 1; /* 1 for 32bit, 0 for 16bit */ - (void)HAL_TIMER_Init(&g_htim1); - HAL_TIMER_Start(&g_htim1); -} - -/** - * @brief Check Timer out - * @return true - * @return false - */ -bool IsTimerOut(void) -{ - return (DCL_TIMER_GetValue(g_htim1.baseAddress) == 0); -} diff --git a/middleware/hisilicon/loaderboot/source/drivers_adapt/src/uart_adapt.c b/middleware/hisilicon/loaderboot/source/drivers_adapt/src/uart_adapt.c deleted file mode 100644 index 3d8578c4fdffa193e022c46f6b174b35387462c7..0000000000000000000000000000000000000000 --- a/middleware/hisilicon/loaderboot/source/drivers_adapt/src/uart_adapt.c +++ /dev/null @@ -1,353 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file uart_adapt.c - * @author MCU Driver Team - * @brief UART adapt module. - * @details This file provides functions about the following functionalities: - * + UART Init/DeInit - * + Receive Data from UART - * + Send Data to UART - */ -#include "loaderboot.h" -#include "uart.h" -#include "uart_adapt.h" - -#define UART_GETC_DELAY_TIME 20 -#define BITS_PER_BYTE 8 -#define DECIMAL 10 - -static UART_Handle g_uartHandle; -#define BOOT_UART UART0 - -/** - * @brief UART Init Adapter - * @param baudRate Uart baud rate - * @retval None - */ -void UART_Init(unsigned int baudRate) -{ - UART_Handle *handle = &g_uartHandle; - - handle->baseAddress = BOOT_UART; - handle->baudRate = baudRate; - handle->dataLength = UART_DATALENGTH_8BIT; - handle->stopBits = UART_STOPBITS_ONE; - handle->parity = UART_PARITY_NONE; - handle->txMode = UART_MODE_BLOCKING; - handle->rxMode = UART_MODE_BLOCKING; - handle->fifoMode = true; - handle->fifoTxThr = UART_FIFOFULL_ONE_EIGHT; - handle->fifoRxThr = UART_FIFOFULL_ONE_EIGHT; - handle->hwFlowCtr = UART_HW_FLOWCTR_DISABLE; - - HAL_UART_Init(handle); -} - -/** - * @brief Write char to UART TX FIFO - * @param c Character to be written - * @retval None - */ -static inline void DwPutChar(char c) -{ - while (BOOT_UART->UART_FR.BIT.txff != 0) { /* True when the TX FIFO is full */ - ; - } - BOOT_UART->UART_DR.BIT.data = (unsigned char)c; -} - -/** - * @brief Check if the RX FIFO is not empty - * @param None - * @retval 0(empty) or 1(not empty) - */ -static inline bool DwTstChar(void) -{ - return (BOOT_UART->UART_FR.BIT.rxfe == 1) ? false : true; -} - -/** - * @brief Read one character from RX FIFO - * @param None - * @retval Character read - */ -static inline unsigned char DwGetChar(void) -{ - while (!DwTstChar()) { - ; - } - return BOOT_UART->UART_DR.BIT.data; -} - -/** - * @brief Check if the UART is in mute mode, always return false - * @param None - * @retval false - */ -static inline bool UartCheckMute(void) -{ - return false; -} - -/** - * @brief Write a character to the UART - * @param c Character to be written - * @retval None - */ -void SERIAL_PutChar(const char c) -{ - bool isMute = UartCheckMute(); - if (isMute == true) { - return; - } - - if (c == '\n') { - DwPutChar('\r'); - } - - DwPutChar(c); -} - -/** - * @brief Write string to UART - * @param str String to be written - * @retval None - */ -void SERIAL_PutStr(const char *str) -{ - bool isMute = UartCheckMute(); - const char *p = str; - if (str == NULL) { - return; - } - if (isMute == true) { - return; - } - while (*p != 0) { - SERIAL_PutChar(*p++); - } -} - -/** - * @brief Write data in buffer to UART - * @param buffer Pointer to data - * @param length Data length - * @retval None - */ -void SERIAL_PutBuf(const char *buffer, signed int length) -{ - signed int i; - bool isMute; - if (buffer == NULL) { - return; - } - isMute = UartCheckMute(); - if (isMute == true) { - return; - } - - for (i = 0; i < length; i++) { - DwPutChar(buffer[i]); - } -} - -/** - * @brief Get character from the serial port - * @param None - * @retval Character - */ -unsigned char SERIAL_GetChar(void) -{ - return DwGetChar(); -} - -/** - * @brief Get character from the serial port - * @param None - * @retval true Rcv Data - * @retval false No Data - */ -bool SERIAL_TstChar(void) -{ - return DwTstChar(); -} - -/** - * @brief Output to serial port in hexadecimal format - * @param h Integer to be output - * @param printAll Whether the left side is filled with 0 - * @retval None - */ -void SERIAL_PutHex(unsigned int hex, bool printAll) -{ - signed int i; - unsigned int h = hex; - char c; - char mark = 0; - - bool isMute = UartCheckMute(); - if (isMute == true) { - return; - } - - SERIAL_PutStr("0x"); - - for (i = 0; i < BITS_PER_BYTE; i++) { - c = (h >> 28) & 0x0F; /* u32 right shift 28 */ - - if (c >= DECIMAL) { - c = (c - DECIMAL) + 'A'; - } else { - c = c + '0'; - } - - if (printAll) { - SERIAL_PutChar(c); - h = h << 4; /* u32 left shift 4 */ - continue; - } - - /* If it is not the last number and the previous numbers are all 0 */ - if ((mark == 0) && (i != BITS_PER_BYTE - 1)) { - if (c != '0') { - mark = 1; - SERIAL_PutChar(c); - } - } else { - SERIAL_PutChar(c); - } - - h = h << 4; /* u32 left shift 4 */ - } -} - -/** - * @brief Read a character from the serial port. - * if the reading fails, return with timeout - * @param timeoutUs overtime time(us) - * @param ch Pointer to read character - * @retval BASE_STATUS_OK (success) - * @retval BASE_STATUS_ERROR (fail) - */ -unsigned int SERIAL_GetCharTimeout(unsigned int timeoutUs, unsigned char *ch) -{ - unsigned int maxCnt = timeoutUs / (unsigned int)UART_GETC_DELAY_TIME; - unsigned int cnt = 0; - - if (ch == NULL) { - return BASE_STATUS_ERROR; - } - while ((SERIAL_TstChar() == false) && (cnt < maxCnt)) { - BASE_FUNC_DELAY_US(UART_GETC_DELAY_TIME); - cnt++; - } - - if (SERIAL_TstChar() == true) { - *ch = SERIAL_GetChar(); - return BASE_STATUS_OK; - } - - return BASE_STATUS_ERROR; -} - -/** - * @brief Output formatted hexadecimal number - * @param h Value - * @param print0 Output type - * @retval None - */ -void BOOT_PutHex(unsigned int h, bool print0) -{ - SERIAL_PutStr(" "); - SERIAL_PutHex(h, print0); - SERIAL_PutStr("\r\n"); -} - -/** - * @brief Output one string with newline - * @param s String - * @retval None - */ -void BOOT_Msg0(const char *s) -{ - if (s == NULL) { - return; - } - SERIAL_PutStr(s); - SERIAL_PutStr("\r\n"); -} - -/** - * @brief Output one string and one hexadecimal number with newline - * @param s String - * @param h unsigned integer parameter printed out in hexadecimal - * @retval None - */ -void BOOT_Msg1(const char *s, unsigned int h) -{ - if (s == NULL) { - return; - } - SERIAL_PutStr(s); - SERIAL_PutHex(h, 0); - SERIAL_PutStr("\r\n"); -} - -/** - * @brief Output one string and two hexadecimal number with newline - * @param s String - * @param h1 unsigned integer parameter 1 printed out in hexadecimal - * @param h2 unsigned integer parameter 2 printed out in hexadecimal - * @retval None - */ -void BOOT_Msg2(const char *s, unsigned int h1, unsigned int h2) -{ - if (s == NULL) { - return; - } - SERIAL_PutStr(s); - SERIAL_PutHex(h1, 0); - SERIAL_PutStr(" "); - SERIAL_PutHex(h2, 0); - SERIAL_PutStr("\r\n"); -} - -/** - * @brief Output one string and four hexadecimal number with newline - * @param s String - * @param h1 unsigned integer parameter 1 printed out in hexadecimal - * @param h2 unsigned integer parameter 2 printed out in hexadecimal - * @param h3 unsigned integer parameter 3 printed out in hexadecimal - * @param h4 unsigned integer parameter 4 printed out in hexadecimal - * @retval None - */ -void BOOT_Msg4(const char *s, unsigned int h1, unsigned int h2, unsigned int h3, unsigned int h4) -{ - if (s == NULL) { - return; - } - SERIAL_PutStr(s); - SERIAL_PutHex(h1, 0); - SERIAL_PutStr(" "); - SERIAL_PutHex(h2, 0); - SERIAL_PutStr(" "); - SERIAL_PutHex(h3, 0); - SERIAL_PutStr(" "); - SERIAL_PutHex(h4, 0); - SERIAL_PutStr("\r\n"); -} diff --git a/middleware/hisilicon/loaderboot/source/fake_drivers/crg/common/inc/crg.h b/middleware/hisilicon/loaderboot/source/fake_drivers/crg/common/inc/crg.h deleted file mode 100644 index 9000ebcd883d28342dfd63020fbabbfe032b0ecc..0000000000000000000000000000000000000000 --- a/middleware/hisilicon/loaderboot/source/fake_drivers/crg/common/inc/crg.h +++ /dev/null @@ -1,54 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file crg.h - * @author MCU Driver Team - * @brief CRG module driver - * @details This file provides fake CRG function. - * + Get IP Frequence - * + Get CPU Core Frequence - */ -#ifndef McuMagicTag_CRG_H -#define McuMagicTag_CRG_H - -/* Includes ------------------------------------------------------------------*/ -#include "crg_ip.h" -/* Macro definitions ---------------------------------------------------------*/ - -/** - * @defgroup CRG CRG - * @brief CRG module. - * @{ - */ - -/** - * @defgroup CRG_API_Declaration CRG HAL API - * @{ - */ -unsigned int HAL_CRG_GetIpFreq(const void *ipBaseAddr); -unsigned int HAL_CRG_GetCoreClkFreq(void); - -/** - * @} - */ - - -/** - * @} - */ - -#endif /* McuMagicTag_CRG_H */ \ No newline at end of file diff --git a/middleware/hisilicon/loaderboot/source/fake_drivers/crg/inc/crg_ip.h b/middleware/hisilicon/loaderboot/source/fake_drivers/crg/inc/crg_ip.h deleted file mode 100644 index 9f4f9bdb113bae291dbab5439c0cf9fbb4e8a8cb..0000000000000000000000000000000000000000 --- a/middleware/hisilicon/loaderboot/source/fake_drivers/crg/inc/crg_ip.h +++ /dev/null @@ -1,62 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file crg_ip.h - * @author MCU Driver Team - * @brief TIMER module driver. - * @details This file provides firmware functions to manage the following - * functionalities of the TIMER. - * + CRG register mapping structure - * + Direct Configuration Layer functions of CRG - */ -#ifndef McuMagicTag_CRG_IP_H -#define McuMagicTag_CRG_IP_H - -/* Includes ------------------------------------------------------------------*/ -#include "baseinc.h" - -/** - * @addtogroup CRG - * @{ - */ - -/** - * @defgroup CRG_IP CRG_IP - * @brief CRG_IP: crg_v0 - * @{ - */ - -/** - * @defgroup CRG_Param_Def CRG Parameters Definition - * @brief Definition of CRG configuration parameters. - * @{ - */ -#define CRG_FREQ_1MHz (1000 * 1000) -#define HCLK_FREQ (25 * CRG_FREQ_1MHz) -#define PCLK_FREQ (HCLK_FREQ / 2) -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -#endif /* McuMagicTag_CRG_IP_H */ diff --git a/middleware/hisilicon/loaderboot/source/fake_drivers/crg/src/crg.c b/middleware/hisilicon/loaderboot/source/fake_drivers/crg/src/crg.c deleted file mode 100644 index d8eb5704d458ebbf7dc4c4696559130f5aedf287..0000000000000000000000000000000000000000 --- a/middleware/hisilicon/loaderboot/source/fake_drivers/crg/src/crg.c +++ /dev/null @@ -1,50 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file crg.c - * @author MCU Driver Team - * @brief CRG module driver. - * @details This file provides fake functions of CRG. - * + Get IP Frequence - * + Get CPU Core Frequence - */ - -/* Includes ------------------------------------------------------------------*/ -#include "baseinc.h" -#include "crg.h" -#include "crg_ip.h" - -/** - * @brief Get Clock Frequence - * @param handle CRG Handle - * @retval Frequece of IP - */ -unsigned int HAL_CRG_GetIpFreq(const void *baseAddress) -{ - BASE_FUNC_UNUSED(baseAddress); - return PCLK_FREQ; -} - -/** - * @brief Get Core Clock Frequence - * @param None - * @retval unsigned int Core clock frequency - */ -unsigned int HAL_CRG_GetCoreClkFreq(void) -{ - return HCLK_FREQ; -} diff --git a/middleware/hisilicon/loaderboot/source/loader/inc/cmd.h b/middleware/hisilicon/loaderboot/source/loader/inc/cmd.h deleted file mode 100644 index 19ba5f552f57a4ec8bbd46948ccb0bc5c508c814..0000000000000000000000000000000000000000 --- a/middleware/hisilicon/loaderboot/source/loader/inc/cmd.h +++ /dev/null @@ -1,60 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file cmd.h - * @author MCU Driver Team - * @brief Header file containing functions prototypes of cmd module. - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef McuMagicTag_CMD_H -#define McuMagicTag_CMD_H - -/* Includes ------------------------------------------------------------------*/ - -/* Macro definitions ---------------------------------------------------------*/ - -#define UART_CMD_PAYLOAD_MAX 60 /**< UART command payload length */ -#define CMD_HEADER_SIZE 2 /**< Command header size */ - -/* Typedef definitions -------------------------------------------------------*/ - -/** - * @brief valid cmd - */ -enum { - CMD_DL_IMAGE = 0xD2, /**< Download Image */ - CMD_UL_DATA = 0xB4, /**< Upload Image */ - CMD_RESET = 0x87, /**< Reset MCU */ -}; - -/** - * @brief UART CMD frame - */ -typedef struct { - unsigned char type; /**< Command Type */ - unsigned char rcvBuf[UART_CMD_PAYLOAD_MAX]; /**< Command */ - unsigned char crcHigh; /**< CRC high byte */ - unsigned char crcLow; /**< CRC low byte */ - unsigned char rsv[1]; -} UartCmd; - -/* Functions -----------------------------------------------------------------*/ - -void CmdLoop(void); - -#endif /* McuMagicTag_CMD_H */ diff --git a/middleware/hisilicon/loaderboot/source/loader/inc/handshake.h b/middleware/hisilicon/loaderboot/source/loader/inc/handshake.h deleted file mode 100644 index 397561c40250ecff330930f3ec4ab3f4f6c0d871..0000000000000000000000000000000000000000 --- a/middleware/hisilicon/loaderboot/source/loader/inc/handshake.h +++ /dev/null @@ -1,29 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file handshake.h - * @author MCU Driver Team - * @brief Header file containing functions prototypes of handshake module. - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef McuMagicTag_HANDSHAKE_H -#define McuMagicTag_HANDSHAKE_H - -bool HandShake(unsigned int timeoutMs); - -#endif /* McuMagicTag_HANDSHAKE_H */ diff --git a/middleware/hisilicon/loaderboot/source/loader/inc/serial_dw.h b/middleware/hisilicon/loaderboot/source/loader/inc/serial_dw.h deleted file mode 100644 index bbefacfe54a8c67c14330c74e462e066b8fd541a..0000000000000000000000000000000000000000 --- a/middleware/hisilicon/loaderboot/source/loader/inc/serial_dw.h +++ /dev/null @@ -1,134 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file serial_dw.h - * @author MCU Driver Team - * @brief serial driver head file. - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef McuMagicTag_SERIAL_DW_H -#define McuMagicTag_SERIAL_DW_H - -/* Includes ------------------------------------------------------------------*/ - -/* Macro definitions ---------------------------------------------------------*/ - -/* UART register OFFSET */ -#define UART_DR 0x0 /**< Data register */ -#define UART_RSR_ECR 0x04 /**< Receive status register/error clear register */ -#define UART_FR 0x18 /**< Flag register */ -#define UART_IBRD 0x24 /**< Integer baud rate register */ -#define UART_FBRD 0x28 /**< Float baud rate register */ -#define UART_LCR_H 0x2C /**< Line control register */ -#define UART_CR 0x30 /**< Control register */ -#define UART_IFLS 0x34 /**< Interrupt FIFO threshold selection register */ -#define UART_IMSC 0x38 /**< Interrupt mask register */ -#define UART_RIS 0x3C /**< Raw interrupt status register */ -#define UART_MIS 0x40 /**< Interrupt status register after mask */ -#define UART_ICR 0x44 /**< Interrupt clear register */ -#define UART_DMACR 0x48 /**< DMA control register */ - -#define UARTFR_TXFE_MASK 0x80 /**< TX FIFO Empty mask */ -#define UARTFR_RXFF_MASK 0x40 /**< RX FIFO Full mask */ -#define UARTFR_TXFF_MASK 0x20 /**< TX FIFO Full mask */ -#define UARTFR_RXFE_MASK 0x10 /**< RX FIFO Empty mask */ -#define UARTFR_BUSY_MASK 0x04 /**< Busy mask */ -#define UARTDR_DATA_MASK 0xFF /**< Data mask */ - -#define UARTLCR_H_CFG 0x60 /**< 8bit, no parity, FIFO disable */ -#define UARTLCR_H_CFG_ODD 0x72 /**< 8bit, odd parity,FIFO enable */ -#define UARTLCR_H_CFG_FIFO 0x70 /**< 8bit, no parity, FIFO enable */ -#define UARTCR_CFG 0x301 /**< UART tx enable, rx enable, uart enable */ -#define UARTCR_CFG_FLOWENABLE 0xC301 /**< UART tx enable, rx enable, uart enable, flow control enable */ -#define UARTCR_RTX_FC_SHIFT 14 -#define UARTCR_CTX_FC_SHIFT 15 -#define UARTCR_ENABLE 0x0001 -#define UARTIMSC_CFG 0x0 /**< Disable all uart interrupt */ -#define UARTIMSC_CFG_INT 0x50 /**< enable rx time out interrupt */ -#define UARTIFS_CFG 0x10A /**< FIFO water mark:Rx 16 Tx 32 RTS 56 */ -#define UARTIFS_RXFF_SHIFT 3 /**< RX FIFO full shift */ -#define UARTIFS_RTSFF_SHIFT 6 - -#define UART_DMA_ENABLE 0X03 /**< DMA Enable */ -#define UART_DMA_DISABLE 0X04 /**< DMA Disable */ -#define UARTICR_CFG 0x7FF /* Clear up all uart interrupt */ - -/* Typedef definitions -------------------------------------------------------*/ -/** - * @brief The structure of the serial port baud rate - */ -typedef struct { - unsigned int baudrate; /**< Uart baud rate */ - unsigned short iBrd; /**< Ibrd that needs to be configured to the register*/ - unsigned short fBrd; /**< Fbrd that needs to be configured to the register*/ -} UartBrd; - -/** - * @brief Uart baud rate index - */ -enum UartBrdIdx { - UART_BRD_IDX_9600 = 0, - UART_BRD_IDX_115200 = 1, - UART_BRD_IDX_230400 = 2, - UART_BRD_IDX_460800 = 3, - UART_BRD_IDX_1024000 = 4, - UART_BRD_IDX_2048000 = 5, - UART_BRD_IDX_2560000 = 6, - UART_BRD_IDX_3000000 = 7, - UART_BRD_IDX_6000000 = 8, - UART_BRD_IDX_MAX, -}; - -/** - * @brief Uart baud rate - */ -enum UartBaudrate { - UART_BRD_1200 = 1200, - UART_BRD_2400 = 2400, - UART_BRD_9600 = 9600, - UART_BRD_19200 = 19200, - UART_BRD_115200 = 115200, - UART_BRD_230400 = 230400, - UART_BRD_460800 = 460800, - UART_BRD_921600 = 921600, - UART_BRD_1000000 = 1000000, - UART_BRD_1024000 = 1024000, - UART_BRD_1500000 = 1500000, - UART_BRD_1536000 = 1536000, - UART_BRD_2000000 = 2000000, - UART_BRD_2048000 = 2048000, - UART_BRD_2252800 = 2252800, - UART_BRD_2304000 = 2304000, - UART_BRD_2500000 = 2500000, - UART_BRD_2560000 = 2560000, - UART_BRD_3000000 = 3000000, - UART_BRD_3072000 = 3072000, - UART_BRD_3500000 = 3500000, - UART_BRD_3584000 = 3584000, - UART_BRD_3840000 = 3840000, - UART_BRD_4000000 = 4000000, - UART_BRD_4096000 = 4096000, - UART_BRD_4500000 = 4500000, - UART_BRD_4608000 = 4608000, - UART_BRD_5000000 = 5000000, - UART_BRD_6000000 = 6000000, -}; - -/* Functions -----------------------------------------------------------------*/ - -#endif /* McuMagicTag_SERIAL_DW_H */ diff --git a/middleware/hisilicon/loaderboot/source/loader/inc/transfer.h b/middleware/hisilicon/loaderboot/source/loader/inc/transfer.h deleted file mode 100644 index 8a5bcf70538202d0c4f3bc1fcbc03f7b18f068a8..0000000000000000000000000000000000000000 --- a/middleware/hisilicon/loaderboot/source/loader/inc/transfer.h +++ /dev/null @@ -1,148 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file transfer.h - * @author MCU Driver Team - * @brief uart transfer head file. - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef McuMagicTag_TRANSFER_H -#define McuMagicTag_TRANSFER_H - -/* Includes ------------------------------------------------------------------*/ -#include "baseinc.h" - -/* Macro definitions ---------------------------------------------------------*/ -#define MAX_SYNC_RETRIES 0xFFFFFFFF /**< Maximum number of attempts to receive synchronization frame*/ - -#define HEADER_RX_DELAY_US 5000000 /**< Frame header receiving timeout time */ -#define FRAME_RX_DELAY_US 3000000 /**< Frame receiving timeout time */ - -#define HANDSHAK_DELAY_US 100000 /**< Handshake timeout time */ - -#define MAX_FRAME_DATA_SIZE 1024 /**< Max size of Frame Data Payload */ - -/** - * @brief Maximum length of various frames - */ -#define HANDSHAKE_FRAME_SIZE 9 -#define HEADER_FRAME_SIZE 14 -#define TAIL_FRAME_SIZE 5 -#define ACK_FRAME_SIZE 6 - -#define FRAME_RETRY_MAX_TH 1000 /**< Frame overhead size */ -#define FRAME_COST_SIZE 5 /**< Number of received frame attempts */ - -#define FRAME_HEADER_CHK_LEN 3 /**< frame header CRC check length */ -#define DATA_FRAME_COST 2 /**< Data frame overhead */ - -/* - * @brief Offset of common frame - */ -#define FRAME_TYPE_OFFSET 0 -#define FRAME_SEQ_OFFSET 1 -#define FRAME_INV_SEQ_OFFSET 2 - -/** - * @brief Offset of ack frame - */ -#define ACK_FRAME_RESULT_OFFSET 3 -#define ACK_FRAME_CRC_OFFSET 4 - -/** - * @brief Offset of header frame - */ -#define HEAD_FRAME_LENGTH_OFFSET 4 -#define HEAD_FRAME_ADDRESS_OFFSET 8 -#define HEAD_FRAME_CRC_OFFSET 12 - -/** - * @brief Offset of data crc frame - */ -#define DATA_FRAME_CRC_OFFSET 3 - -/** - * @brief FRAME Type - */ -#define XHDSHK 0xBE -#define XHEAD 0xFE -#define XDATA 0xDA -#define XTAIL 0xED -#define XACK 0xCB -#define XCMD 0xAB -#define XKEY 0xCD - -/** - * @brief ACK Result - */ -#define ACK_SUCCESS 0x5A -#define ACK_FAILURE 0xA5 - -/* Typedef definitions -------------------------------------------------------*/ -/** - * @brief Uart Frame Structure - */ -struct UartFrame { - unsigned char header; /**< Frame Type */ - unsigned char index; /**< Frame index */ - unsigned char indexReverse; /**< Frame index Reversed */ - unsigned char *payloadBuf; /**< Pointer to payload buffer */ - unsigned int payloadBufLen; /**< Length of payload buffer */ - unsigned char crcHigh; /**< The first byte of CRC16 */ - unsigned char crcLow; /**< The Seconde byte of CRC16 */ - unsigned char ackSeq; /**< The Sequence of ACK */ - unsigned char ackRslt; /**< Result of ACK */ -}; - -/* Functions -----------------------------------------------------------------*/ -/** - * @brief Check whether it is a file header frame - * @param frame Pointer to the frame structure - * @retval true - * @retval false - */ -static inline bool UartRcvIsHeaderFrame(struct UartFrame *frame) -{ - return ((frame->header == XHEAD) && (frame->index == 0x0)) ? true : false; -} - -/** - * @brief Check whether it is a command header frame - * @param frame Pointer to the frame structure - * @retval true - * @retval false - */ -static inline bool UartRcvIsCmdHeaderFrame(struct UartFrame *frame) -{ - return (frame->header == XCMD) ? true : false; -} - -void UartFlush(void); -BASE_StatusType UartRcvFrame(struct UartFrame *const frame, unsigned int rcvLen, unsigned int timeoutUs); -BASE_StatusType UartRcvHdrFrame(struct UartFrame *const frame, unsigned int *rcvLen, unsigned int maxLen); -BASE_StatusType UartRcvTailFrame(struct UartFrame *const frame, unsigned char index); -BASE_StatusType UartRcvDataFrame(struct UartFrame *const frame, unsigned char idx, unsigned int length); - -void UartAck(unsigned char result, unsigned char index); -BASE_StatusType UartWaitAck(struct UartFrame *const frame, unsigned char index); -BASE_StatusType UartXmitMakeHeadFrame(unsigned char *const frame, unsigned int len, unsigned int addr); -BASE_StatusType UartXmitMakeDataFrame(unsigned char *const frame, unsigned int dataLen, - unsigned int bufLen, unsigned char seq); -BASE_StatusType UartXmitMakeTailFrame(unsigned char seq); - -#endif /* McuMagicTag_TRANSFER_H */ diff --git a/middleware/hisilicon/loaderboot/source/loader/src/cmd.c b/middleware/hisilicon/loaderboot/source/loader/src/cmd.c deleted file mode 100644 index e70e6154474b9af6f013dd7e5f7183523668d427..0000000000000000000000000000000000000000 --- a/middleware/hisilicon/loaderboot/source/loader/src/cmd.c +++ /dev/null @@ -1,359 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file cmd.c - * @author MCU Driver Team - * @brief cmd module. - * @details This file provides cmd's functions to parse exec the cmd received. - */ - -/* Includes ------------------------------------------------------------------*/ -#include "transfer.h" -#include "loaderboot.h" -#include "flash_adapt.h" -#include "crc_adapt.h" -#include "uart_adapt.h" -#include "clock.h" -#include "cmd.h" - -/* Macro definitions ---------------------------------------------------------*/ -#define IMAGE_ADDR_OFFSET 1 /**< Image address offset field in header frame */ -#define IMAGE_SIZE_OFFSET 5 /**< Image size offset field in header frame */ -#define FRAME_DATA_OFFSET 3 /**< Data offset field in data frame */ -#define BYTE_HIGH_OFFSET 8 /**< Bitoffset of in unsigned short */ -#define RESET_DELAY 100 /**< Delay of jump to target(ms) */ - -/* Typedef definitions -------------------------------------------------------*/ -/* Global variables ----------------------------------------------------------*/ - -/* Functions -----------------------------------------------------------------*/ -/** - * @brief calculate cmd's crc. - * @param cmd, len. - * @retval true false. - */ -static bool IsCmdCrcSucc(const UartCmd *cmd, unsigned int len) -{ - unsigned char *p = (unsigned char *)(void *)cmd; - unsigned int crcDataLen = len + sizeof(cmd->type); - return CRC_Check(p, crcDataLen, MergeToUshort(cmd->crcHigh, cmd->crcLow)); -} - -#ifndef EFLASH_ENABLE -/** - * @brief Write Image to SRAM - * @param daddr destination address to be written - * @param saddr source address - * @param len data length - */ -static void WriteToSRAM(unsigned char *daddr, unsigned char *saddr, unsigned int len) -{ - unsigned int i; - for (i = 0; i < len; ++i) { - daddr[i] = saddr[i]; - } -} -#endif - -/** - * @brief exec download image cmd. - * @param cmd. command type - * @retval succ fail. - */ -static BASE_StatusType LoaderDownloadImage(const UartCmd *cmd) -{ - unsigned int addr; - unsigned int size; - unsigned char idx; - unsigned int rcvLen; - unsigned int remainLen; - unsigned int flashBaseAddr = 0; - - unsigned char buf[MAX_FRAME_DATA_SIZE]; - struct UartFrame frame = {0}; - - addr = BigEndianToUint(&cmd->rcvBuf[IMAGE_ADDR_OFFSET]); - size = BigEndianToUint(&cmd->rcvBuf[IMAGE_SIZE_OFFSET]); - - frame.payloadBuf = buf; - frame.payloadBufLen = MAX_FRAME_DATA_SIZE; - - /* Get File header Frame, and get the file total length */ - if (UartRcvHdrFrame(&frame, &remainLen, size) != BASE_STATUS_OK) { - return BASE_STATUS_ERROR; - } - - if (addr < FLASH_READ_BASE) { - return BASE_STATUS_ERROR; - } - - /* Erase Flash */ - flashBaseAddr = addr - FLASH_READ_BASE; - if (BASE_STATUS_OK != FLASH_Erase(flashBaseAddr, remainLen)) { - return BASE_STATUS_ERROR; - } - UartAck(ACK_SUCCESS, 0); - idx = 1; - - /* Get Data from UART and Write to Flash */ - while (remainLen > 0) { - rcvLen = GetMinValue(remainLen, MAX_FRAME_DATA_SIZE); - if (UartRcvDataFrame(&frame, idx, rcvLen) != BASE_STATUS_OK) { - return BASE_STATUS_ERROR; - } - if (idx == frame.index) { -#if defined(EFLASH_ENABLE) && (EFLASH_ENABLE == 1) - if (BASE_STATUS_OK != FLASH_Write(buf, flashBaseAddr, rcvLen)) { - return BASE_STATUS_ERROR; - } - flashBaseAddr += rcvLen; -#else - WriteToSRAM((unsigned char *)(void*)addr, frame.payloadBuf, rcvLen); - addr += rcvLen; -#endif - remainLen -= rcvLen; - ++idx; - } - } - /* Wait to get the Tail Frame */ - return UartRcvTailFrame(&frame, idx); -} - -/** - * @brief exec upload image cmd. - * @param cmd uart command - * @retval succ fail. - */ -static BASE_StatusType LoaderUploadImage(const UartCmd *cmd) -{ - unsigned int ret; - unsigned int sendLen; - unsigned int remainLen; - unsigned int addr; - unsigned int size; - unsigned char idx; - unsigned char frame[MAX_FRAME_DATA_SIZE + FRAME_COST_SIZE]; - - addr = BigEndianToUint(&cmd->rcvBuf[IMAGE_ADDR_OFFSET]); - size = BigEndianToUint(&cmd->rcvBuf[IMAGE_SIZE_OFFSET]); - - /* make the header of frame */ - UartXmitMakeHeadFrame(frame, size, addr); - - ret = UartWaitAck((struct UartFrame *)frame, 0); - if (ret != BASE_STATUS_OK) { - return BASE_STATUS_ERROR; - } - - /* Send data cyclically */ - idx = 0; - remainLen = size; - while (remainLen > 0) { - idx++; /* Data frame index starts from 1 */ - sendLen = GetMinValue(remainLen, MAX_FRAME_DATA_SIZE); - - /* Read image from flash */ - ret = FLASH_Read(addr, sendLen, frame + FRAME_DATA_OFFSET, sizeof(frame) - FRAME_DATA_OFFSET); - if (ret != BASE_STATUS_OK) { - return BASE_STATUS_ERROR; - } - - ret = UartXmitMakeDataFrame(frame, sendLen, sizeof(frame), idx); - if (ret != BASE_STATUS_OK) { - return BASE_STATUS_ERROR; - } - - ret = UartWaitAck((struct UartFrame *)frame, idx); - if (ret != BASE_STATUS_OK) { - return BASE_STATUS_ERROR; - } - - remainLen -= sendLen; - addr += sendLen; - } - - /* Send the tail frame */ - ret = (unsigned int)UartXmitMakeTailFrame(++idx); - if (ret != BASE_STATUS_OK) { - return BASE_STATUS_ERROR; - } - - ret = UartWaitAck((struct UartFrame *)frame, idx); - if (ret != BASE_STATUS_OK) { - return BASE_STATUS_ERROR; - } - - return BASE_STATUS_OK; -} - -/** - * @brief Get Command Frame length - * @param cmd. uart command - * @param length. Output of command frame length - * @retval succ fail. - */ -static BASE_StatusType UartGetCmdLength(UartCmd *cmd, unsigned short *length) -{ - unsigned int ret; - unsigned short cmdLen; - - ret = SERIAL_GetCharTimeout(FRAME_RX_DELAY_US, &cmd->rcvBuf[0]); - ret |= SERIAL_GetCharTimeout(FRAME_RX_DELAY_US, &cmd->rcvBuf[1]); - ret |= SERIAL_GetCharTimeout(FRAME_RX_DELAY_US, &cmd->crcHigh); - ret |= SERIAL_GetCharTimeout(FRAME_RX_DELAY_US, &cmd->crcLow); - if ((ret != BASE_STATUS_OK) || (!IsCmdCrcSucc(cmd, CMD_HEADER_SIZE))) { - return BASE_STATUS_ERROR; - } - cmdLen = (cmd->rcvBuf[0] << BYTE_HIGH_OFFSET) + cmd->rcvBuf[1]; - if (cmdLen > UART_CMD_PAYLOAD_MAX) { - return BASE_STATUS_ERROR; - } - UartAck(ACK_SUCCESS, 0); /* Received cmd header frame success */ - *length = cmdLen; - return BASE_STATUS_OK; -} - -/** - * @brief Get Command Context - * @param cmd. uart command - * @param length. Output of command frame length - * @retval succ fail. - */ -static BASE_StatusType UartGetCmdContext(UartCmd *cmd, unsigned short length) -{ - unsigned int ret; - unsigned short cmdLen = length; - - for (unsigned int i = 0; i < cmdLen; i++) { - ret = SERIAL_GetCharTimeout(FRAME_RX_DELAY_US, cmd->rcvBuf + i); /* get timeout status */ - if (ret != BASE_STATUS_OK) { - return BASE_STATUS_ERROR; - } - } - - ret = SERIAL_GetCharTimeout(FRAME_RX_DELAY_US, &cmd->crcHigh); /* read crc high */ - ret |= SERIAL_GetCharTimeout(FRAME_RX_DELAY_US, &cmd->crcLow); /* read crc low */ - if ((ret != BASE_STATUS_OK) || (!IsCmdCrcSucc(cmd, cmdLen))) { - return BASE_STATUS_ERROR; - } - UartAck(ACK_SUCCESS, 0); /* received a valid cmd */ - return BASE_STATUS_OK; -} - -/** - * @brief loop receive a valid cmd. - * @param cmd. uart command - * @retval succ fail - */ -static BASE_StatusType UartRcvCmd(UartCmd *cmd) -{ - unsigned int i; - unsigned int ret; - unsigned short cmdLen = 0; - - /* loop receive cmd header frame & cmd frame */ - while (1) { - ret = SERIAL_GetCharTimeout(HEADER_RX_DELAY_US, &cmd->type); - if (ret != BASE_STATUS_OK) { - continue; - } - switch (cmd->type) { - case XCMD: - if (UartGetCmdLength(cmd, &cmdLen) != BASE_STATUS_OK) { - continue; - } - break; - - case XKEY: - if (UartGetCmdContext(cmd, cmdLen) != BASE_STATUS_OK) { - continue; - } - return BASE_STATUS_OK; - - default: - break; - } - } - return BASE_STATUS_ERROR; -} - -/** - * @brief exec reset cmd. - * @param cmd uart command - * @retval succ fail. - */ -static BASE_StatusType LoaderReset(void) -{ - BOOT_Msg0("\nExecution Reset====\n"); - Reset(); - return BASE_STATUS_OK; -} - -/** - * @brief parse cmd. - * @param cmd. uart command - * @retval succ fail. - */ -static BASE_StatusType LoaderCmdExec(UartCmd *cmd) -{ - unsigned char cmdType = cmd->rcvBuf[0]; - if (cmdType == CMD_DL_IMAGE) { - LOADER_VER type = GetLoaderType(); - if (type == LOADERBOOT_V2) { - return LoaderDownloadImage(cmd); - } else { - if (LoaderDownloadImage(cmd) == BASE_STATUS_OK) { - BASE_FUNC_DELAY_MS(RESET_DELAY); - LoaderReset(); - } - return BASE_STATUS_ERROR; - } - } - - if (cmdType == CMD_UL_DATA) { - return LoaderUploadImage(cmd); - } - - if (cmdType == CMD_RESET) { - UartAck(ACK_SUCCESS, 0); - BASE_FUNC_DELAY_MS(RESET_DELAY); - return LoaderReset(); - } - return BASE_STATUS_ERROR; -} - -/** - * @brief loop receive & parse & exec cmd. - * @param . - * @retval . - */ -void CmdLoop(void) -{ - unsigned int ret; - UartCmd cmd; - - for (;;) { - /* recevice cmd header frame */ - UartRcvCmd(&cmd); - /* parse cmd & exec */ - ret = LoaderCmdExec(&cmd); - if (ret != BASE_STATUS_OK) { - UartAck(ACK_FAILURE, 0); - continue; - } - } -} diff --git a/middleware/hisilicon/loaderboot/source/loader/src/handshake.c b/middleware/hisilicon/loaderboot/source/loader/src/handshake.c deleted file mode 100644 index d5b2b317214025f907ef1cd0f7159fdbe83b72c5..0000000000000000000000000000000000000000 --- a/middleware/hisilicon/loaderboot/source/loader/src/handshake.c +++ /dev/null @@ -1,71 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file handshake.c - * @author MCU Driver Team - * @brief The following functions are implemented: - * + uart hand shake function - */ - -/* Includes ------------------------------------------------------------------*/ -#include "loaderboot.h" -#include "transfer.h" -#include "utils.h" -#include "uart_adapt.h" -#include "timer_adapt.h" -#include "handshake.h" - -/* Macro definitions ---------------------------------------------------------*/ -#define UART_DEFAULT_BAUDRATE (115200) - -/** - * @brief rsv handshake frame & check. - * @param timeoutMs. - * @retval true false. - */ -bool HandShake(unsigned int timeoutMs) -{ - BASE_StatusType ret; - unsigned int baudrate; - unsigned char buf[HANDSHAKE_FRAME_SIZE] = {0}; - struct UartFrame frame = {0}; - - frame.header = XHDSHK; - frame.payloadBuf = buf; - frame.payloadBufLen = sizeof(buf); - - /* Receive handshake frame */ - TimerStart(timeoutMs * US_PER_MS); - do { - ret = UartRcvFrame(&frame, sizeof(buf), 1); - if ((ret != BASE_STATUS_OK) || (frame.header != XHDSHK) || (frame.index != 0x0)) { - continue; - } - /* Check baud rate */ - baudrate = BigEndianToUint(frame.payloadBuf); - if (baudrate == 0) { - continue; - } - UartAck(ACK_SUCCESS, 0); - if (baudrate != UART_DEFAULT_BAUDRATE) { - UART_Init(baudrate); - } - return true; - } while (!IsTimerOut()); - - return false; -} diff --git a/middleware/hisilicon/loaderboot/source/loader/src/loadertype.c b/middleware/hisilicon/loaderboot/source/loader/src/loadertype.c deleted file mode 100644 index 01b47d8fca01f48b01b06d6836541ac59ac1a66d..0000000000000000000000000000000000000000 --- a/middleware/hisilicon/loaderboot/source/loader/src/loadertype.c +++ /dev/null @@ -1,47 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file loadertype.c - * @author MCU Driver Team - * @brief The following functions are implemented: - * + Set Loader Type - * + Get Loader Type - */ - -#include "loaderboot.h" - -static LOADER_VER loadType; - -/** - * @brief Get Loader Type - * @param none. - * @retval loader type. - */ -LOADER_VER GetLoaderType(void) -{ - return loadType; -} - -/** - * @brief Set Loader Type - * @param type loader type. - * @retval none. - */ -void SetLoaderType(LOADER_VER type) -{ - loadType = type; -} diff --git a/middleware/hisilicon/loaderboot/source/loader/src/reset.c b/middleware/hisilicon/loaderboot/source/loader/src/reset.c deleted file mode 100644 index 5dfa28926f3c2accbdd25b7cd4412931df5f6d3c..0000000000000000000000000000000000000000 --- a/middleware/hisilicon/loaderboot/source/loader/src/reset.c +++ /dev/null @@ -1,40 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file reset.c - * @author MCU Driver Team - * @brief The following functions are implemented: - * + MCU Reset - */ - -#include "baseinc.h" -#include "loaderboot.h" - -void Reset(void) -{ - SC_LOCKEN_REG lock; - lock.reg = SYSCTRL0->SC_LOCKEN.reg; - lock.BIT.sc_cfg_lock = 0; - lock.reg |= SC_LOCKEN_VALUE; - SYSCTRL0->SC_LOCKEN.reg = lock.reg; - - SYSCTRL0->SC_SYS_RES.BIT.softresreq = true; - - while (1) { - __asm__ volatile ("nop"); - } -} \ No newline at end of file diff --git a/middleware/hisilicon/loaderboot/source/loader/src/stack_protect.c b/middleware/hisilicon/loaderboot/source/loader/src/stack_protect.c deleted file mode 100644 index fd2c22b53147a5c8a51e86fae65372e01e1cdab7..0000000000000000000000000000000000000000 --- a/middleware/hisilicon/loaderboot/source/loader/src/stack_protect.c +++ /dev/null @@ -1,54 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file stack_protect.c - * @author MCU Driver Team - * @brief gcc stack protect. - */ - -/* Includes ------------------------------------------------------------------*/ - - -/* Macro definitions ---------------------------------------------------------*/ - -/* Typedef definitions -------------------------------------------------------*/ - -/* Global variables ----------------------------------------------------------*/ -unsigned long __stack_chk_guard = 0x000a0dff; - -/* Functions -----------------------------------------------------------------*/ -void __stack_chk_fail(void); -void set_stack_chk_guard(unsigned long canary); - -/** - * @brief The stack check failure is handled on time - */ -void __stack_chk_fail(void) -{ -} - -#pragma GCC push_options -#pragma GCC optimize ("-fno-stack-protector") -/** - * @brief Set the stack chk guard object - * @param canary - */ -void set_stack_chk_guard(unsigned long canary) -{ - __stack_chk_guard = canary; -} -#pragma GCC pop_options diff --git a/middleware/hisilicon/loaderboot/source/loader/src/uart_rcv.c b/middleware/hisilicon/loaderboot/source/loader/src/uart_rcv.c deleted file mode 100644 index 291ccce4be857107971eb5ff3f1677f52394429c..0000000000000000000000000000000000000000 --- a/middleware/hisilicon/loaderboot/source/loader/src/uart_rcv.c +++ /dev/null @@ -1,383 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file uart_rcv.c - * @author MCU Driver Team - * @brief Boot uart rcv funcs. - */ - -/* Includes ------------------------------------------------------------------*/ -#include "loaderboot.h" -#include "utils.h" -#include "crc_adapt.h" -#include "uart_adapt.h" -#include "transfer.h" - -/* Macro definitions ---------------------------------------------------------*/ - -/* Typedef definitions -------------------------------------------------------*/ - -/* Functions -----------------------------------------------------------------*/ -/** - * @brief Get Data length of Frame - * @param header Frame type - * @param expectLen Expected frame length(only for data frame) - * @retval unsigned int Frame length - */ -static unsigned int UartGetFrameDataLen(unsigned char header, - unsigned int expectLen) -{ - if (header == XHDSHK) { - return HANDSHAKE_FRAME_SIZE - FRAME_COST_SIZE; - } - - if (header == XHEAD) { - return HEADER_FRAME_SIZE - FRAME_COST_SIZE; - } - - if (header == XTAIL) { - return TAIL_FRAME_SIZE - FRAME_COST_SIZE; - } - - if (header == XDATA) { - return expectLen; - } - - return 0; -} - -/** - * @brief Check if it is a valid frame header. - * @param header Frame header. - * @retval true - * @retval false - */ -static bool UartRcvIsHeaderSupported(unsigned char header) -{ - bool supported = false; - - switch (header) { - case XHDSHK: - case XHEAD: - case XTAIL: - case XDATA: - case XACK: - case XCMD: - case XKEY: - supported = true; - break; - - default: - break; - } - - return supported; -} - -/** - * @brief Check if there is a data frame. - * @param header Frame header. - * @retval true - * @retval false - */ -static inline bool UartRcvIsDataFrame(unsigned char header) -{ - return (header == XDATA) ? true : false; -} - -/** - * @brief Check if there is a tail frame. - * @param header Frame header. - * @retval true - * @retval false - */ -static inline bool UartRcvIsTailFrame(unsigned char header) -{ - return (header == XTAIL) ? true : false; -} - -/** - * @brief Check whether the CRC of the received frame is correct. - * @param frame Frame header. - * @param len Data payload length - * @retval true - * @retval false - */ -static bool UartRcvIsCrcSucc(struct UartFrame *frame, unsigned int len) -{ - unsigned int crc; - if (frame == NULL) { - return false; - } - crc = MergeToUshort(frame->crcHigh, frame->crcLow); - CRC_Generate((unsigned char *)(void *)frame, OFFSETOF(struct UartFrame, indexReverse) + 1); - return CRC_AccCheck(frame->payloadBuf, len, crc); -} - -/** - * @brief Check whether the CRC of the received ACK frame is correct. - * @param frame Frame header. - * @retval true - * @retval false - */ -static bool UartRcvAckIsCrcSucc(struct UartFrame *frame) -{ - unsigned char buf[sizeof(struct UartFrame)]; - unsigned short crc; - unsigned int len = 0; - - if (frame == NULL) { - return false; - } - buf[len++] = frame->header; - buf[len++] = frame->index; - buf[len++] = frame->indexReverse; - buf[len++] = frame->ackRslt; - crc = MergeToUshort(frame->crcHigh, frame->crcLow); - return CRC_Check(buf, len, crc); -} - -/** - * @brief Receive sync frame - * @param frame Frame header. - * @param timeoutUs Overtime time(us) - * @retval BASE_STATUS_OK Success - * @retval BASE_STATUS_ERROR Fail - */ -static BASE_StatusType UartRcvSync(struct UartFrame *const frame, unsigned int timeoutUs) -{ - unsigned int retry = 0; - BASE_StatusType ret; - - while (retry < timeoutUs) { - ret = SERIAL_GetCharTimeout(FRAME_RX_DELAY_US, &frame->header); - if ((ret != BASE_STATUS_OK) || - !UartRcvIsHeaderSupported(frame->header)) { - retry++; - continue; - } - - ret = SERIAL_GetCharTimeout(FRAME_RX_DELAY_US, &frame->index); - ret |= SERIAL_GetCharTimeout(FRAME_RX_DELAY_US, &frame->indexReverse); - if (ret != BASE_STATUS_OK) { - retry++; - continue; - } - if (frame->index & frame->indexReverse) { - retry++; - continue; - } - if ((frame->index == 0) && (frame->indexReverse != 0xFF)) { - retry++; - continue; - } - - return BASE_STATUS_OK; - } - - return BASE_STATUS_TIMEOUT; -} - -/** - * @brief Clear UART FIFO - * @retval None - */ -void UartFlush(void) -{ - while (1) { - unsigned char ch = (char)0xff; - unsigned int ret = SERIAL_GetCharTimeout(HEADER_RX_DELAY_US, &ch); - if (ret == BASE_STATUS_ERROR) { - return; - } - } -} - -/** - * @brief Receive Frame - * @param frame Struct Pointer to save frame - * @param rcvDataLen The data length - * @param retryCnt Maximum number of retries - * @retval BASE_STATUS_OK Success - * @retval BASE_STATUS_ERROR Fail - */ -BASE_StatusType UartRcvFrame(struct UartFrame *const frame, - unsigned int rcvDataLen, - unsigned int retryCnt) -{ - unsigned int ret; - unsigned int realLen; - unsigned int i; - - if (!frame || - (frame->payloadBufLen < rcvDataLen) || - (rcvDataLen > MAX_FRAME_DATA_SIZE)) { - return BASE_STATUS_ERROR; - } - - /* Receive frame synchronization */ - ret = UartRcvSync(frame, retryCnt); - if (ret != BASE_STATUS_OK) { - return BASE_STATUS_ERROR; - } - - /* According to the frame type, get the frame length and receive the frame - content cyclically */ - realLen = UartGetFrameDataLen(frame->header, rcvDataLen); - - /* Because UartRcvSync() above has received the first three bytes of the - frame, so here we need to start from the third byte */ - for (i = 0; i < realLen; i++) { - ret = SERIAL_GetCharTimeout(FRAME_RX_DELAY_US, frame->payloadBuf + i); - if (ret != BASE_STATUS_OK) { - return ret; - } - } - ret = SERIAL_GetCharTimeout(FRAME_RX_DELAY_US, &frame->crcHigh); - ret |= SERIAL_GetCharTimeout(FRAME_RX_DELAY_US, &frame->crcLow); - if (ret != BASE_STATUS_OK) { - return ret; - } - if (!UartRcvIsCrcSucc(frame, realLen)) { - return BASE_STATUS_ERROR; - } - return BASE_STATUS_OK; -} - -/** - * @brief Receive Header frame - * @param frame Pointer to frame struct - * @param rcvLen Get the total data length - * @param maxLen Max data length - * @retval BASE_STATUS_OK Success - * @retval BASE_STATUS_ERROR Fail - */ - -BASE_StatusType UartRcvHdrFrame(struct UartFrame *const frame, unsigned int *rcvLen, unsigned int maxLen) -{ - signed int frameRcvTh = FRAME_RETRY_MAX_TH; - unsigned int ret; - - if ((frame == NULL) || (rcvLen == NULL)) { - return BASE_STATUS_ERROR; - } - while (--frameRcvTh >= 0) { - ret = UartRcvFrame(frame, HEADER_FRAME_SIZE, MAX_SYNC_RETRIES); - if ((ret == BASE_STATUS_OK) && UartRcvIsHeaderFrame(frame)) { - break; - } - if (frameRcvTh == 0) { - return BASE_STATUS_ERROR; - } - } - - *rcvLen = BigEndianToUint(frame->payloadBuf + 1); - - if (*rcvLen > maxLen) { - UartAck(ACK_FAILURE, 0); - return BASE_STATUS_ERROR; - } - - return BASE_STATUS_OK; -} - -/** - * @brief Receive Data frame - * @param frame Pointer to frame struct - * @param idx The index of data frame - * @param length Data length - * @retval BASE_STATUS_OK Success - * @retval BASE_STATUS_ERROR Fail - */ -BASE_StatusType UartRcvDataFrame(struct UartFrame *const frame, unsigned char idx, unsigned int length) -{ - signed int frameRcvTh = FRAME_RETRY_MAX_TH; - BASE_StatusType ret; - - if (frame == NULL) { - return BASE_STATUS_ERROR; - } - while (--frameRcvTh >= 0) { - ret = UartRcvFrame(frame, length, MAX_SYNC_RETRIES); - if ((ret == BASE_STATUS_OK) && - ((idx == frame->index) || (idx == frame->index + 1))) { - break; - } - if (frameRcvTh > 0) { - UartAck(ACK_FAILURE, idx); - } else { - return BASE_STATUS_ERROR; - } - } - UartAck(ACK_SUCCESS, frame->index); - return BASE_STATUS_OK; -} - -/** - * @brief Receive tail frame - * @param frame Pointer to frame struct - * @param idx The index of tail frame - * @retval BASE_STATUS_OK Success - * @retval BASE_STATUS_ERROR Fail - */ -BASE_StatusType UartRcvTailFrame(struct UartFrame *const frame, unsigned char idx) -{ - if (frame == NULL) { - return BASE_STATUS_ERROR; - } - return UartRcvDataFrame(frame, idx, 0); -} - -/** - * @brief Waiting for confirmation frame - * @param frame Pointer to frame struct - * @param idx The index of waiting frame - * @retval BASE_STATUS_OK Success - * @retval BASE_STATUS_ERROR Fail - */ -BASE_StatusType UartWaitAck(struct UartFrame *const frame, unsigned char idx) -{ - BASE_StatusType ret; - - if (frame == NULL) { - return BASE_STATUS_ERROR; - } - - /* Wait The Sync bytes of frame */ - ret = UartRcvSync(frame, MAX_SYNC_RETRIES); - if (ret != BASE_STATUS_OK) { - return BASE_STATUS_ERROR; - } - - /* Wait CRC and ACK result */ - ret = SERIAL_GetCharTimeout(FRAME_RX_DELAY_US, &frame->ackRslt); - ret |= SERIAL_GetCharTimeout(FRAME_RX_DELAY_US, &frame->crcHigh); - ret |= SERIAL_GetCharTimeout(FRAME_RX_DELAY_US, &frame->crcLow); - if (ret != BASE_STATUS_OK) { - return BASE_STATUS_ERROR; - } - - /* Do CRC check */ - if (!UartRcvAckIsCrcSucc(frame)) { - return BASE_STATUS_ERROR; - } - - if ((frame->ackRslt != ACK_SUCCESS) || (frame->index != idx)) { - return BASE_STATUS_ERROR; - } - return BASE_STATUS_OK; -} diff --git a/middleware/hisilicon/loaderboot/source/loader/src/uart_xmit.c b/middleware/hisilicon/loaderboot/source/loader/src/uart_xmit.c deleted file mode 100644 index c4a361c3e921d2c0c02a50355043c0a32f8f7603..0000000000000000000000000000000000000000 --- a/middleware/hisilicon/loaderboot/source/loader/src/uart_xmit.c +++ /dev/null @@ -1,159 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file uart_xmit.c - * @author MCU Driver Team - * @brief Boot uart send funcs. - * @details Frame construction function - */ - -/* Includes ------------------------------------------------------------------*/ -#include "loaderboot.h" -#include "crc_adapt.h" -#include "uart_adapt.h" -#include "transfer.h" - -/* Macro definitions ---------------------------------------------------------*/ -#define HEAD_FRAME_HEAD 0xFE00FF01 /**< Header Frame head*/ - -/* Typedef definitions -------------------------------------------------------*/ - -/* Functions -----------------------------------------------------------------*/ -/** - * @brief The caller prepares the buffer and reserves the front and rear space - * according to the frame format - * 00 FF - * XDATA seq ~seq 0x01 ---len--- ---addr--- CRC_HIGH CRC_LOW - * @param frame The buffer to save the frame - * @param length The length to be written - * @param addr The address to be written - * @retval BASE_STATUS_OK success - */ -unsigned int UartXmitMakeHeadFrame(unsigned char *const frame, unsigned int len, unsigned int addr) -{ - unsigned short crc; - - if (frame == NULL) { - return BASE_STATUS_ERROR; - } - /* Write in header */ - UintToBigEndian(HEAD_FRAME_HEAD, frame); - - /* Write in length */ - UintToBigEndian(len, frame + HEAD_FRAME_LENGTH_OFFSET); - - /* Write in address */ - UintToBigEndian(addr, frame + HEAD_FRAME_CRC_OFFSET); - - /* Calc and Write CRC */ - crc = CRC_Generate(frame, HEAD_FRAME_CRC_OFFSET); - UShortToBigEndian(crc, frame + HEAD_FRAME_CRC_OFFSET); - - SERIAL_PutBuf((const char *)frame, HEADER_FRAME_SIZE); - return BASE_STATUS_OK; -} - -/** - * @brief The caller prepares the buffer and reserves the front and rear space - * according to the frame format - * -------------------bufLen------------------ - * XDATA seq ~seq ---dataLen--- CRC_HIGH CRC_LOW - * @param frame The Pointer to the buffer - * @param dataLen The data length in frame - * @param bufLen The length of buffer - * @param seq Sequence of buffer - * @retval BOOT_FAILUE fail - * @retval BASE_STATUS_OK success - */ -unsigned int UartXmitMakeDataFrame(unsigned char *const frame, - unsigned int dataLen, - unsigned int bufLen, - unsigned char seq) -{ - unsigned short crc; - unsigned int sequence = seq; - - /* Parameter Check */ - if (frame == NULL) { - return BASE_STATUS_ERROR; - } - if ((dataLen + FRAME_COST_SIZE > bufLen) || - (dataLen > MAX_FRAME_DATA_SIZE)) { - return BASE_STATUS_ERROR; - } - - /* Construct the Frame */ - frame[FRAME_TYPE_OFFSET] = XDATA; - frame[FRAME_SEQ_OFFSET] = seq; - frame[FRAME_INV_SEQ_OFFSET] = (unsigned char)(~sequence & 0xFF); - - /* Generate CRC and write to frame */ - crc = CRC_Generate(frame, dataLen + FRAME_HEADER_CHK_LEN); - UShortToBigEndian(crc, &frame[dataLen + DATA_FRAME_CRC_OFFSET]); - SERIAL_PutBuf((const char *)frame, dataLen + FRAME_COST_SIZE); - return BASE_STATUS_OK; -} - -/** - * @brief send tail frame. - * XTAIL seq ~seq CRC_HIGH CRC_LOW - * @param seq the sequence number of transmit frame - * @retval BASE_STATUS_OK success - */ -unsigned int UartXmitMakeTailFrame(unsigned char seq) -{ - unsigned char frame[TAIL_FRAME_SIZE]; - unsigned short crc; - unsigned int sequence = seq; - - /* Construct the Frame */ - frame[FRAME_TYPE_OFFSET] = XTAIL; - frame[FRAME_SEQ_OFFSET] = seq; - frame[FRAME_INV_SEQ_OFFSET] = (unsigned char)(~sequence & 0xFF); - - /* Generate CRC and write to frame */ - crc = CRC_Generate(frame, (DATA_FRAME_CRC_OFFSET - FRAME_TYPE_OFFSET)); - UShortToBigEndian(crc, &frame[DATA_FRAME_CRC_OFFSET]); - SERIAL_PutBuf((const char *)frame, TAIL_FRAME_SIZE); - return BASE_STATUS_OK; -} - -/** - * @brief send ack frame. - * XACK seq ~seq result CRC_HIGH CRC_LOW - * @param result Result in ACK Frame - * @param seq Sequence in ACK Frame - * @retval . - */ -void UartAck(unsigned char result, unsigned char seq) -{ - unsigned char frame[ACK_FRAME_SIZE]; - unsigned short crc; - unsigned int sequence = seq; - - /* Construct the Frame */ - frame[FRAME_TYPE_OFFSET] = XACK; - frame[FRAME_SEQ_OFFSET] = seq; - frame[FRAME_INV_SEQ_OFFSET] = (unsigned char)(~sequence & 0xFF); - frame[ACK_FRAME_RESULT_OFFSET] = result; - - /* Generate CRC and write to frame */ - crc = CRC_Generate(frame, (ACK_FRAME_CRC_OFFSET - FRAME_TYPE_OFFSET)); - UShortToBigEndian(crc, &frame[ACK_FRAME_CRC_OFFSET]); - SERIAL_PutBuf((const char *)frame, ACK_FRAME_SIZE); - return; -} diff --git a/middleware/hisilicon/loaderboot/source/main.c b/middleware/hisilicon/loaderboot/source/main.c deleted file mode 100644 index 6f20331d14ade645c80a58266c373675de92c8b7..0000000000000000000000000000000000000000 --- a/middleware/hisilicon/loaderboot/source/main.c +++ /dev/null @@ -1,61 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file main.c - * @author MCU Driver Team - * @brief Defined The following functions - * @details Loaderboot C function entry - */ - -/* Includes ------------------------------------------------------------------*/ -#include "baseinc.h" -#include "handshake.h" -#include "loaderboot.h" -#include "flash_adapt.h" -#include "uart_adapt.h" -#include "crc_adapt.h" -#include "reset.h" -#include "systickinit.h" -#include "cmd.h" - -/* Macro definitions ---------------------------------------------------------*/ -#define LOADER_HANDSHAKE_TIMEOUT_MS 40 -#define DEFAULT_BAUDRATE 115200 - -#pragma GCC push_options -#pragma GCC optimize ("-fno-stack-protector") - -/** - * @brief The C Main Entry of Loader - * @param None - * @retval None - */ -void main(void) -{ - bool succ; - - CRC_Init(); - FLASH_Init(); - SYSTICK_Init(); - - succ = HandShake(LOADER_HANDSHAKE_TIMEOUT_MS); - SetLoaderType(succ ? LOADERBOOT_V2 : LOADERBOOT_V1); - CmdLoop(); - Reset(); -} - -#pragma GCC pop_options diff --git a/middleware/hisilicon/loaderboot/startup/riscv_init.S b/middleware/hisilicon/loaderboot/startup/riscv_init.S deleted file mode 100644 index d53cc2d7184ab534704c97ba57bebaa0d3cd8c9b..0000000000000000000000000000000000000000 --- a/middleware/hisilicon/loaderboot/startup/riscv_init.S +++ /dev/null @@ -1,198 +0,0 @@ -/** - * @copyright Copyright (c) 2022, HiSilicon (Shanghai) Technologies Co., Ltd. All rights reserved. - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote - * products derived from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * @file riscv_init.S - * @author MCU Driver Team - * @brief loaderboot RISC-V trap handling and startup code. - */ -#ifndef ENTRY_S -#define ENTRY_S - -.extern __stack_top - -#define LREG lw -#define SREG sw -#define REGBYTES 4 - -#define INT_SIZE_ON_STACK (16 * REGBYTES) - -#define MSTATUS_MPP_MACHINE 0x00001800 -#define MCAULSE_ECALL_FROM_MMODE 11 -#define MCAULSE_ECALL_FROM_UMODE 8 -#define EXC_SIZE_ON_STACK (160) - -#define EFC_MAGIC_NUMBER 0xFEDCBA98 /* magic number */ -#define EFC_MAGIC_LOCK_RW 0x14710200 /* cmd operation magic word protection register */ - -#define YEAR 0x22 -#define MON 0x05 -#define DAY 0x05 -#define VER 0x02 - - .extern trap_entry - .section .text.entry - .global _start - .option norvc -_start: - j handle_reset - -version: - .byte YEAR - .byte MON - .byte DAY - .byte VER - -trap_vector: - j trap_entry_wrapper - .option rvc - -.macro push_reg - addi sp, sp, -(INT_SIZE_ON_STACK) - stmia {ra, t0-t2, a0-a7, t3-t6}, (sp) - addi sp, sp, -(INT_SIZE_ON_STACK) -.endm - -.macro pop_reg - addi sp, sp, INT_SIZE_ON_STACK - ldmia {ra, t0-t2, a0-a7, t3-t6},(sp) - addi sp, sp, INT_SIZE_ON_STACK -.endm - -trap_entry_wrapper: - j trap_entry - -.align 2 -trap_entry: - push_reg - csrr a0, mcause - li t1, MCAULSE_ECALL_FROM_MMODE - beq a0, t1, switch_to_umode - li t1, MCAULSE_ECALL_FROM_UMODE - beq a0, t1, switch_to_mmode - - pop_reg - j trap_entry - -.align 2 -switch_to_umode: - li t2, MSTATUS_MPP_MACHINE - csrc mstatus, t2 - csrr t0, mepc - addi t0, t0, 4 - csrw mepc, t0 - pop_reg - mret - -.align 2 -switch_to_mmode: - li t2, MSTATUS_MPP_MACHINE - csrs mstatus, t2 - csrr t0, mepc - addi t0, t0, 4 - csrw mepc, t0 - pop_reg - mret - -handle_reset: - csrwi mstatus, 0 - csrwi mie, 0 - csrci mstatus, 0x08 - la t0, trap_vector - addi t0, t0, 1 - csrw mtvec, t0 -/* lock mtvec */ - #csrwi 0x7EF, 0x1 - -/* initialize global pointer */ - .option push - .option norelax - la gp, __global_pointer$ - .option pop - -/* initialize stack pointer */ - la sp, __stack_top - -/* perform the rest of initialization in C */ -clear_bss: - la t0, __bss_begin__ - la t1, __bss_end__ - li t2, 0x00000000 -clear_bss_loop: - bge t0, t1, clear_bss_done /* are we at the end yet, if not , continue till the end */ - sw t2, (t0) /* clear BSS location */ - addi t0, t0, 4 /* increment clear index pointer */ - j clear_bss_loop -clear_bss_done: - -start_coderom_data_copy: - la t0, __data_start /* SRAM addr */ - la t1, __data_load /* ROM addr */ - la t2, __data_end - -coderom_data_copy_loop: - bge t0, t2, coderom_data_copy_done - lw t3, (t1) - sw t3, (t0) - addi t0, t0, 4 - addi t1, t1, 4 - j coderom_data_copy_loop -coderom_data_copy_done: - -pmp_init: - li t0, 0xB00 - csrw pmpaddr0, t0 - li t0,0x400400 /* 2C00?~0x1000FFF, BOOTROM, enable R+X */ - csrw pmpaddr1, t0 - li t0,0x800000 /* 0x1001000~0x1FFFFFF, Reserved: disable R+X+W */ - csrw pmpaddr2, t0 - li t0,0x801000 /* 0x2000000~0x2003FFF, SYSRAM_ITCM */ - csrw pmpaddr3, t0 - li t0, 0xC00000 /* 0x2004000 ~ 0x2FFFFFF, Reserved: disable R+X+W */ - csrw pmpaddr4, t0 - li t0, 0x1000000 /* 0x3000000 ~ 0x03FFFFFF: EFLASH: enable R+W */ - csrw pmpaddr5, t0 - li t0,0x1001000 /* 0x4000000 ~ 0x0x04003FFF: SYSTEM_DTCM enable R+W */ - csrw pmpaddr6, t0 - li t0,0x7080000 /* 0x0d:TOR-R-X; 0x0b:TOR-R-W; 0x08:TOR; 0x0c:TOR-x; 0x09:TOR-R */ - csrw pmpaddr7, t0 - - li t0,0xf3333333 /* register TOR-R-W */ - csrw 0x7d8,t0 - - li t0,0x0d080d8b /* 0x0d:TOR-R-X; 0x0b:TOR-R-W; 0x08:TOR; 0x0c:TOR-x; 0x09:TOR-R */ - csrw pmpcfg0,t0 - li t0,0x0b0b0b08 - csrw pmpcfg1,t0 - -/* enable flash cmd */ - li t0, EFC_MAGIC_NUMBER - li t1, EFC_MAGIC_LOCK_RW - sw t0, (t1) - -/* disable Icache */ - csrwi 0x7C0, 0x0 /* disable ICACHE */ - fence - -/* disable Dcache */ - csrwi 0x7C1, 0x0 /* disable DCACHE */ - fence - - ecall /* ecall: M-mode -> U-mode */ - -/* jump to C func. */ - tail main -#endif diff --git a/middleware/thirdparty/.keep b/middleware/thirdparty/.keep deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/middleware/thirdparty/sysroot/.keep b/middleware/thirdparty/sysroot/.keep deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/middleware/thirdparty/sysroot/include/.keep b/middleware/thirdparty/sysroot/include/.keep deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/middleware/thirdparty/sysroot/lib/.keep b/middleware/thirdparty/sysroot/lib/.keep deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000