/**
|
******************************************************************************
|
* @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<<SCB_ICSR_PENDSVSET_Pos;
|
}
|
|
void PendSvCallBack()
|
{
|
|
}
|
|
void SPI1_IRQ_CallBack()
|
{
|
|
}
|
|
void Uart1SendDone()
|
{
|
return;
|
}
|
|
void Uart1RecvDone()
|
{
|
|
}
|
|
void Uart2SendDone()
|
{
|
|
}
|
void Uart2RecvDone()
|
{
|
|
}
|
|
int PutStr(char * str1, int len1)
|
{
|
|
return len1;
|
}
|
int PutStr1(char * str1, int len1)
|
{
|
return len1;
|
}
|
int PutStr2(char * str1, int len1)
|
{
|
|
return len1;
|
}
|
|
int SendPacket(int nChn, void * pBuf,int len1)
|
{
|
if (nChn==1) {
|
PutStr1((char *)pBuf,len1);
|
}else if (nChn==2){
|
PutStr2((char *)pBuf,len1);
|
}
|
return len1;
|
}
|
/*
|
int SendPacket1(void * pBuf,int len1)
|
{
|
PutStr1((char *)pBuf,len1);
|
// PushIn(&Uart1Stat.QTx,p1,len1);
|
// Uart1TriggerSendDMA();
|
Uart1Stat.SentPacket++;
|
return len1;
|
}
|
int SendPacket2(pKBPacket p1,int len1)
|
{
|
PutStr2((char *)p1,len1);
|
// PushIn(&Uart2Stat.QTx,p1,len1);
|
// Uart2TriggerSendDMA();
|
Uart2Stat.SentPacket++;
|
return len1;
|
}
|
*/
|
void ToggleRunLed() { LL_GPIO_TogglePin(GPIOC,LL_GPIO_PIN_13);}
|
void ToggleErrLed() { LL_GPIO_TogglePin(GPIOC,LL_GPIO_PIN_14);}
|
void ToggleErr2Led() { LL_GPIO_TogglePin(GPIOC,LL_GPIO_PIN_15);}
|
|
#if (BOARD_TYPE == 14)
|
void ToggleOutStat() { LL_GPIO_TogglePin(GPIOC,LL_GPIO_PIN_15);}
|
|
void SetOutStat(uchar bOn)
|
{
|
if (bOn) {LL_GPIO_SetOutputPin(GPIOC,LL_GPIO_PIN_15);}
|
else {LL_GPIO_ResetOutputPin(GPIOC,LL_GPIO_PIN_15);}
|
}
|
#else
|
void ToggleOutStat() { LL_GPIO_TogglePin(GPIOA,LL_GPIO_PIN_11);}
|
|
void SetOutStat(uchar bOn)
|
{
|
if (bOn) {LL_GPIO_SetOutputPin(GPIOA,LL_GPIO_PIN_11);}
|
else {LL_GPIO_ResetOutputPin(GPIOA,LL_GPIO_PIN_11);}
|
}
|
#endif
|
|
void SetRunLed(uchar bOn)
|
{
|
if (bOn) {LL_GPIO_ResetOutputPin(GPIOC,LL_GPIO_PIN_13);}
|
else {LL_GPIO_SetOutputPin(GPIOC,LL_GPIO_PIN_13);}
|
}
|
void SetErrLed(uchar bOn)
|
{
|
if (bOn) {LL_GPIO_ResetOutputPin(GPIOC,LL_GPIO_PIN_14);}
|
else {LL_GPIO_SetOutputPin(GPIOC,LL_GPIO_PIN_14);}
|
}
|
void SetErr2Led(uchar bOn)
|
{
|
if (bOn) {LL_GPIO_ResetOutputPin(GPIOC,LL_GPIO_PIN_15);}
|
else {LL_GPIO_SetOutputPin(GPIOC,LL_GPIO_PIN_15);}
|
}
|
/*
|
void SetLeds(uchar bRun, uchar bErr)
|
{
|
SetRunLed(bRun); SetErrLed (bErr);
|
}
|
*/
|