提交 | 用户 | age
|
483170
|
1 |
/** |
Q |
2 |
****************************************************************************** |
|
3 |
* @file : functions.c |
|
4 |
* @brief : funcstions program body |
|
5 |
****************************************************************************** |
|
6 |
*/ |
|
7 |
//#include "globaldef.h" |
|
8 |
#include "functions.h" |
|
9 |
#include "string.h" |
|
10 |
#include "stm32f0xx_hal.h" |
|
11 |
extern __IO uint32_t uwTick; |
|
12 |
//#include "Myprotocol.h" |
|
13 |
int TickFreq=10000; |
|
14 |
int CoreClkMHz; //=SystemCoreClock/1000000; |
|
15 |
int TickPriodClk; //=SystemCoreClock/TickFreq; |
|
16 |
unsigned int TickPrioduS; // |
|
17 |
volatile unsigned int nCurTick=0; |
|
18 |
volatile unsigned int CurTickuS=0; |
|
19 |
//volatile unsigned int ThisRunTime=0; //开机时间 |
|
20 |
//volatile unsigned int TotalRunTime=0; //总开机时间 |
|
21 |
//volatile unsigned int PwrCount=0; //开机次数 |
|
22 |
unsigned short ClkuS; //每个Clk的nS数, |
|
23 |
|
|
24 |
int InituS(int TickFreq1) |
|
25 |
{ |
|
26 |
TickPrioduS=1000000/TickFreq1; //每个SysTick的微秒数 |
|
27 |
CoreClkMHz=HAL_RCC_GetHCLKFreq()/1000000; //=SystemCoreClock/1000000;每uS的时钟数 |
|
28 |
TickPriodClk=SystemCoreClock/TickFreq1; //每个SysTick的时钟数 |
|
29 |
ClkuS=(1000000LL*65536)/SystemCoreClock; |
|
30 |
CurTickuS=TickPrioduS+100u; |
|
31 |
return 0; |
|
32 |
} |
|
33 |
|
|
34 |
inline unsigned int GetuS(void) |
|
35 |
{ |
|
36 |
// unsigned short Clk1=SysTick->VAL; |
|
37 |
|
|
38 |
int CurTickuS1=CurTickuS; |
|
39 |
int Val1=SysTick->VAL; |
|
40 |
if (CurTickuS1 != CurTickuS ) |
|
41 |
{ |
|
42 |
CurTickuS1=CurTickuS; |
|
43 |
Val1=SysTick->VAL; |
|
44 |
} |
|
45 |
uint32_t us1=CurTickuS1-(((Val1)*1365)>>16); |
|
46 |
return us1; |
|
47 |
} |
|
48 |
|
|
49 |
inline unsigned int GetTick(void) |
|
50 |
{ |
|
51 |
// unsigned short Clk1=SysTick->VAL; |
|
52 |
return nCurTick; |
|
53 |
} |
|
54 |
|
|
55 |
const uint16_t polynom = 0xA001; |
|
56 |
|
|
57 |
unsigned short crc16bitbybit(const unsigned char *ptr, unsigned int len) |
|
58 |
{ |
|
59 |
uint8_t i; |
|
60 |
uint16_t crc = 0xffff; |
|
61 |
|
|
62 |
if (len == 0) { |
|
63 |
len = 1; |
|
64 |
} |
|
65 |
while (len--) { |
|
66 |
crc ^= *ptr; |
|
67 |
for (i = 0; i<8; i++) |
|
68 |
{ |
|
69 |
if (crc & 1) { |
|
70 |
crc >>= 1; |
|
71 |
crc ^= polynom; |
|
72 |
} |
|
73 |
else { |
|
74 |
crc >>= 1; |
|
75 |
} |
|
76 |
} |
|
77 |
ptr++; |
|
78 |
} |
|
79 |
return(crc); |
|
80 |
} |
|
81 |
|
|
82 |
|
|
83 |
void modbuscrc16test() |
|
84 |
{ |
|
85 |
|
|
86 |
} |
|
87 |
|
|
88 |
void TriggerPendSV() |
|
89 |
{ |
|
90 |
SCB->ICSR=SCB_ICSR_PENDSVSET_Msk; //1<<SCB_ICSR_PENDSVSET_Pos; |
|
91 |
} |
|
92 |
|
|
93 |
void PendSvCallBack() |
|
94 |
{ |
|
95 |
|
|
96 |
} |
|
97 |
|
|
98 |
void SPI1_IRQ_CallBack() |
|
99 |
{ |
|
100 |
|
|
101 |
} |
|
102 |
|
|
103 |
void Uart1SendDone() |
|
104 |
{ |
|
105 |
return; |
|
106 |
} |
|
107 |
|
|
108 |
void Uart1RecvDone() |
|
109 |
{ |
|
110 |
|
|
111 |
} |
|
112 |
|
|
113 |
void Uart2SendDone() |
|
114 |
{ |
|
115 |
|
|
116 |
} |
|
117 |
void Uart2RecvDone() |
|
118 |
{ |
|
119 |
|
|
120 |
} |
|
121 |
|
|
122 |
int PutStr(char * str1, int len1) |
|
123 |
{ |
|
124 |
|
|
125 |
return len1; |
|
126 |
} |
|
127 |
int PutStr1(char * str1, int len1) |
|
128 |
{ |
|
129 |
return len1; |
|
130 |
} |
|
131 |
int PutStr2(char * str1, int len1) |
|
132 |
{ |
|
133 |
|
|
134 |
return len1; |
|
135 |
} |
|
136 |
|
|
137 |
int SendPacket(int nChn, void * pBuf,int len1) |
|
138 |
{ |
|
139 |
if (nChn==1) { |
|
140 |
PutStr1((char *)pBuf,len1); |
|
141 |
}else if (nChn==2){ |
|
142 |
PutStr2((char *)pBuf,len1); |
|
143 |
} |
|
144 |
return len1; |
|
145 |
} |
|
146 |
/* |
|
147 |
int SendPacket1(void * pBuf,int len1) |
|
148 |
{ |
|
149 |
PutStr1((char *)pBuf,len1); |
|
150 |
// PushIn(&Uart1Stat.QTx,p1,len1); |
|
151 |
// Uart1TriggerSendDMA(); |
|
152 |
Uart1Stat.SentPacket++; |
|
153 |
return len1; |
|
154 |
} |
|
155 |
int SendPacket2(pKBPacket p1,int len1) |
|
156 |
{ |
|
157 |
PutStr2((char *)p1,len1); |
|
158 |
// PushIn(&Uart2Stat.QTx,p1,len1); |
|
159 |
// Uart2TriggerSendDMA(); |
|
160 |
Uart2Stat.SentPacket++; |
|
161 |
return len1; |
|
162 |
} |
|
163 |
*/ |
|
164 |
void ToggleRunLed() { LL_GPIO_TogglePin(GPIOC,LL_GPIO_PIN_13);} |
|
165 |
void ToggleErrLed() { LL_GPIO_TogglePin(GPIOC,LL_GPIO_PIN_14);} |
|
166 |
void ToggleErr2Led() { LL_GPIO_TogglePin(GPIOC,LL_GPIO_PIN_15);} |
|
167 |
|
|
168 |
#if (BOARD_TYPE == 14) |
|
169 |
void ToggleOutStat() { LL_GPIO_TogglePin(GPIOC,LL_GPIO_PIN_15);} |
|
170 |
|
|
171 |
void SetOutStat(uchar bOn) |
|
172 |
{ |
|
173 |
if (bOn) {LL_GPIO_SetOutputPin(GPIOC,LL_GPIO_PIN_15);} |
|
174 |
else {LL_GPIO_ResetOutputPin(GPIOC,LL_GPIO_PIN_15);} |
|
175 |
} |
|
176 |
#else |
|
177 |
void ToggleOutStat() { LL_GPIO_TogglePin(GPIOA,LL_GPIO_PIN_11);} |
|
178 |
|
|
179 |
void SetOutStat(uchar bOn) |
|
180 |
{ |
|
181 |
if (bOn) {LL_GPIO_SetOutputPin(GPIOA,LL_GPIO_PIN_11);} |
|
182 |
else {LL_GPIO_ResetOutputPin(GPIOA,LL_GPIO_PIN_11);} |
|
183 |
} |
|
184 |
#endif |
|
185 |
|
|
186 |
void SetRunLed(uchar bOn) |
|
187 |
{ |
|
188 |
if (bOn) {LL_GPIO_ResetOutputPin(GPIOC,LL_GPIO_PIN_13);} |
|
189 |
else {LL_GPIO_SetOutputPin(GPIOC,LL_GPIO_PIN_13);} |
|
190 |
} |
|
191 |
void SetErrLed(uchar bOn) |
|
192 |
{ |
|
193 |
if (bOn) {LL_GPIO_ResetOutputPin(GPIOC,LL_GPIO_PIN_14);} |
|
194 |
else {LL_GPIO_SetOutputPin(GPIOC,LL_GPIO_PIN_14);} |
|
195 |
} |
|
196 |
void SetErr2Led(uchar bOn) |
|
197 |
{ |
|
198 |
if (bOn) {LL_GPIO_ResetOutputPin(GPIOC,LL_GPIO_PIN_15);} |
|
199 |
else {LL_GPIO_SetOutputPin(GPIOC,LL_GPIO_PIN_15);} |
|
200 |
} |
|
201 |
/* |
|
202 |
void SetLeds(uchar bRun, uchar bErr) |
|
203 |
{ |
|
204 |
SetRunLed(bRun); SetErrLed (bErr); |
|
205 |
} |
|
206 |
*/ |
|
207 |
|
|
208 |
|