/** ****************************************************************************** * @file : functions.c * @brief : funcstions program body ****************************************************************************** */ //#include "globaldef.h" #include "functions.h" #include "string.h" #include "stm32f0xx_hal.h" extern __IO uint32_t uwTick; //#include "Myprotocol.h" int TickFreq=10000; int CoreClkMHz; //=SystemCoreClock/1000000; int TickPriodClk; //=SystemCoreClock/TickFreq; unsigned int TickPrioduS; // volatile unsigned int nCurTick=0; volatile unsigned int CurTickuS=0; //volatile unsigned int ThisRunTime=0; //开机时间 //volatile unsigned int TotalRunTime=0; //总开机时间 //volatile unsigned int PwrCount=0; //开机次数 unsigned short ClkuS; //每个Clk的nS数, int InituS(int TickFreq1) { TickPrioduS=1000000/TickFreq1; //每个SysTick的微秒数 CoreClkMHz=HAL_RCC_GetHCLKFreq()/1000000; //=SystemCoreClock/1000000;每uS的时钟数 TickPriodClk=SystemCoreClock/TickFreq1; //每个SysTick的时钟数 ClkuS=(1000000LL*65536)/SystemCoreClock; CurTickuS=TickPrioduS+100u; return 0; } inline unsigned int GetuS(void) { // unsigned short Clk1=SysTick->VAL; int CurTickuS1=CurTickuS; int Val1=SysTick->VAL; if (CurTickuS1 != CurTickuS ) { CurTickuS1=CurTickuS; Val1=SysTick->VAL; } uint32_t us1=CurTickuS1-(((Val1)*1365)>>16); return us1; } inline unsigned int GetTick(void) { // unsigned short Clk1=SysTick->VAL; return nCurTick; } const uint16_t polynom = 0xA001; unsigned short crc16bitbybit(const unsigned char *ptr, unsigned int len) { uint8_t i; uint16_t crc = 0xffff; if (len == 0) { len = 1; } while (len--) { crc ^= *ptr; for (i = 0; i<8; i++) { if (crc & 1) { crc >>= 1; crc ^= polynom; } else { crc >>= 1; } } ptr++; } return(crc); } void modbuscrc16test() { } void TriggerPendSV() { SCB->ICSR=SCB_ICSR_PENDSVSET_Msk; //1<