feat: KT mBMS 펌웨어 3종(HW1/2/3) 및 통합 빌드 환경 초기 커밋 (V4.0.0.1)
This commit is contained in:
126
APP_R3221/App/Hardware/delay.c
Normal file
126
APP_R3221/App/Hardware/delay.c
Normal file
@@ -0,0 +1,126 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file delay.c
|
||||
* @author AMG Energy Solution Team
|
||||
* @version V1.0.0
|
||||
* @date 07-Feb-2022
|
||||
* @brief This file provides all the code of the delay functions.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
|
||||
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
|
||||
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
|
||||
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
|
||||
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2022 AMG</center></h2>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/** @addtogroup mBMS2
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "delay.h"
|
||||
#include "includes.h" //ucos use
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
#define SYS_CLOCK 200
|
||||
#define SYSTICK_LOAD 200000
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private prototype functions -----------------------------------------------*/
|
||||
|
||||
// OS is called the delay function delay
|
||||
// ticks:Delay number of beats
|
||||
void delay_ostimedly(uint32_t ticks)
|
||||
{
|
||||
#ifdef CPU_CFG_CRITICAL_METHOD
|
||||
OS_ERR err;
|
||||
OSTimeDly(ticks,OS_OPT_TIME_PERIODIC, &err);//UCOSIII delay adoption cycle mode
|
||||
#else
|
||||
OSTimeDly(ticks); //UCOSII delay
|
||||
#endif
|
||||
}
|
||||
|
||||
void delay_us1(uint32_t us)
|
||||
{
|
||||
uint32_t udelay = us * 10;
|
||||
|
||||
for (int i = 0; i < udelay; i++)
|
||||
{
|
||||
i = i;
|
||||
}
|
||||
}
|
||||
|
||||
void delay_us(uint32_t us)
|
||||
{
|
||||
uint32_t usec = us * SYS_CLOCK;
|
||||
uint32_t temp = CPU_REG_NVIC_ST_CURRENT;
|
||||
uint32_t comp = temp + usec;
|
||||
|
||||
if (temp < usec)
|
||||
{
|
||||
comp = SYSTICK_LOAD - (usec - temp); // 200 - 100 = 100, 200000 - 100 = 199900, 200000 + 100
|
||||
while ((comp < temp) || (temp < usec))
|
||||
{
|
||||
temp = CPU_REG_NVIC_ST_CURRENT;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
comp = temp - usec;
|
||||
while (comp < temp)
|
||||
{
|
||||
temp = CPU_REG_NVIC_ST_CURRENT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void delay_ns1(uint32_t ns)
|
||||
{
|
||||
uint32_t nsec = ns / 1;
|
||||
uint32_t temp = CPU_REG_NVIC_ST_CURRENT;
|
||||
uint32_t comp = temp + nsec;
|
||||
|
||||
if (temp < nsec)
|
||||
{
|
||||
comp = SYSTICK_LOAD - (nsec - temp); // 200 - 100 = 100, 200000 - 100 = 199900, 200000 + 100
|
||||
while ((comp < temp) || (temp < nsec))
|
||||
{
|
||||
temp = CPU_REG_NVIC_ST_CURRENT;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
comp = temp - nsec;
|
||||
while (comp < temp)
|
||||
{
|
||||
temp = CPU_REG_NVIC_ST_CURRENT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void delay_ns(uint32_t ns)
|
||||
{
|
||||
for (uint32_t i = 0; i < ns; i++)
|
||||
{
|
||||
__NOP();
|
||||
}
|
||||
}
|
||||
|
||||
void delay_os_ms(uint32_t ms)
|
||||
{
|
||||
OS_ERR err;
|
||||
|
||||
OSTimeDlyHMSM(0, 0, (ms / 1000), (ms % 1000),
|
||||
OS_OPT_TIME_HMSM_STRICT,
|
||||
&err);
|
||||
}
|
||||
|
||||
/*******************(C)COPYRIGHT 2022 AMG ********************END OF FILE******/
|
||||
Reference in New Issue
Block a user