core_hwtimer.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. /*
  2. * Copyright (c) 2022 OpenLuat & AirM2M
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  5. * this software and associated documentation files (the "Software"), to deal in
  6. * the Software without restriction, including without limitation the rights to
  7. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  8. * the Software, and to permit persons to whom the Software is furnished to do so,
  9. * subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in all
  12. * copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  16. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  17. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  18. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  19. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. */
  21. #include "user.h"
  22. typedef struct
  23. {
  24. // const I2C_TypeDef *RegBase;
  25. const int IrqLine;
  26. OPQueue_CmdStruct *Cmd;
  27. Buffer_Struct InDataBuf;
  28. CBFuncEx_t CmdDoneCB;
  29. void *pCmdDoneParam;
  30. uint32_t TotalCount;
  31. uint32_t TotalRepeat;
  32. uint32_t CurCount;
  33. uint32_t RepeatCnt;
  34. uint32_t CmdQueuePos;
  35. uint32_t CapturePin;
  36. uint8_t IsQueueRunning;
  37. uint8_t ContinueDelay;
  38. }HWTimer_CtrlStruct;
  39. static HWTimer_CtrlStruct prvHWTimer[HW_TIMER_MAX] = {
  40. {
  41. // TIMM0,
  42. TIM0_0_IRQn,
  43. NULL,
  44. {
  45. NULL, 0, 0,
  46. }
  47. },
  48. {
  49. // TIMM0,
  50. TIM0_1_IRQn,
  51. NULL,
  52. {
  53. NULL, 0, 0,
  54. }
  55. },
  56. {
  57. // TIMM0,
  58. TIM0_2_IRQn,
  59. NULL,
  60. {
  61. NULL, 0, 0,
  62. }
  63. },
  64. {
  65. // TIMM0,
  66. TIM0_3_IRQn,
  67. NULL,
  68. {
  69. NULL, 0, 0,
  70. }
  71. },
  72. {
  73. // TIMM0,
  74. TIM0_4_IRQn,
  75. NULL,
  76. {
  77. NULL, 0, 0,
  78. }
  79. },
  80. {
  81. // TIMM0,
  82. TIM0_5_IRQn,
  83. NULL,
  84. {
  85. NULL, 0, 0,
  86. }
  87. },
  88. };
  89. static void prvHWTimer_IrqHandlerOperationQueue( int32_t Line, void *pData);
  90. static void prvHWTimer_StartOperationQueue(uint8_t HWTimerID, HWTimer_CtrlStruct *HWTimer);
  91. static int32_t prvHWTimer_DummyCB(void *pData, void *pParam)
  92. {
  93. return 0;
  94. }
  95. static void prvHWTimer_IrqHandlerEndOperationQueue( int32_t Line, void *pData)
  96. {
  97. uint32_t HWTimerID = (uint32_t)pData;
  98. HWTimer_Stop(HWTimerID);
  99. prvHWTimer[HWTimerID].CmdDoneCB(0, prvHWTimer[HWTimerID].pCmdDoneParam);
  100. }
  101. static int32_t __FUNC_IN_RAM__ prvHWTimer_OperationQueuExti(void *pData, void *pParam)
  102. {
  103. uint32_t HWTimerID = (uint32_t)pParam;
  104. uint32_t pin = (uint32_t)pData;
  105. // DBG("%x,%x", pin, prvHWTimer[HWTimerID].CapturePin);
  106. if ((pin & prvHWTimer[HWTimerID].CapturePin) == prvHWTimer[HWTimerID].CapturePin)
  107. {
  108. prvHWTimer_StartOperationQueue(HWTimerID, &prvHWTimer[HWTimerID]);
  109. }
  110. return 0;
  111. }
  112. static void __FUNC_IN_RAM__ prvHWTimer_StartOperationQueue(uint8_t HWTimerID, HWTimer_CtrlStruct *HWTimer)
  113. {
  114. volatile uint32_t Period;
  115. while(HWTimer->IsQueueRunning)
  116. {
  117. // DBG("%u, %u, %u, %u, %u, %u, %u, %u, %u, %x, %x", HWTimer->TotalRepeat, HWTimer->RepeatCnt,
  118. // HWTimer->TotalCount, HWTimer->CurCount, HWTimer->Cmd[HWTimer->CurCount].Operation,
  119. // HWTimer->Cmd[HWTimer->CurCount].Arg1, HWTimer->Cmd[HWTimer->CurCount].uArg.IOArg.Level,
  120. // HWTimer->Cmd[HWTimer->CurCount].uArg.IOArg.PullMode, HWTimer->Cmd[HWTimer->CurCount].uArg.Time,
  121. // HWTimer->Cmd[HWTimer->CurCount].CB, HWTimer->Cmd[HWTimer->CurCount].pParam);
  122. switch(HWTimer->Cmd[HWTimer->CurCount].Operation)
  123. {
  124. case OP_QUEUE_CMD_GPIO_OUT:
  125. GPIO_Output(HWTimer->Cmd[HWTimer->CurCount].Arg1, HWTimer->Cmd[HWTimer->CurCount].uArg.IOArg.Level);
  126. HWTimer->CurCount++;
  127. break;
  128. case OP_QUEUE_CMD_GPIO_IN:
  129. HWTimer->Cmd[HWTimer->CurCount].uArg.IOArg.Level = GPIO_Input(HWTimer->Cmd[HWTimer->CurCount].Arg1);
  130. BSP_SetBit(HWTimer->InDataBuf.Data, HWTimer->InDataBuf.Pos, HWTimer->Cmd[HWTimer->CurCount].uArg.IOArg.Level);
  131. HWTimer->CurCount++;
  132. break;
  133. case OP_QUEUE_CMD_ONE_TIME_DELAY:
  134. HWTimer->ContinueDelay = 0;
  135. goto START_HWTIMER;
  136. break;
  137. case OP_QUEUE_CMD_REPEAT_DELAY:
  138. HWTimer->CurCount++;
  139. return;
  140. break;
  141. case OP_QUEUE_CMD_CAPTURE:
  142. if (!TIMM0->TIM[HWTimerID].ControlReg)
  143. {
  144. HWTimer->Cmd[HWTimer->CurCount + 1].Operation = OP_QUEUE_CMD_CAPTURE_END;
  145. }
  146. else
  147. {
  148. HWTimer->Cmd[HWTimer->CurCount].uParam.MaxCnt = TIMM0->TIM[HWTimerID].LoadCount - TIMM0->TIM[HWTimerID].CurrentValue;
  149. HWTimer->Cmd[HWTimer->CurCount].uArg.IOArg.Level = GPIO_Input(HWTimer->Cmd[HWTimer->CurCount].Arg1);
  150. }
  151. HWTimer->CurCount++;
  152. if (OP_QUEUE_CMD_CAPTURE_END != HWTimer->Cmd[HWTimer->CurCount + 1].Operation)
  153. {
  154. return;
  155. }
  156. break;
  157. case OP_QUEUE_CMD_CONTINUE_DELAY:
  158. HWTimer->ContinueDelay = 1;
  159. goto START_HWTIMER;
  160. break;
  161. case OP_QUEUE_CMD_SET_GPIO_DIR_OUT:
  162. GPIO_Config(HWTimer->Cmd[HWTimer->CurCount].Arg1, 0, HWTimer->Cmd[HWTimer->CurCount].uArg.IOArg.Level);
  163. GPIO_PullConfig(HWTimer->Cmd[HWTimer->CurCount].Arg1, HWTimer->Cmd[HWTimer->CurCount].uArg.IOArg.PullMode, (HWTimer->Cmd[HWTimer->CurCount].uArg.IOArg.PullMode > 1)?0:1);
  164. HWTimer->CurCount++;
  165. break;
  166. case OP_QUEUE_CMD_SET_GPIO_DIR_IN:
  167. GPIO_PullConfig(HWTimer->Cmd[HWTimer->CurCount].Arg1, HWTimer->Cmd[HWTimer->CurCount].uArg.IOArg.PullMode, (HWTimer->Cmd[HWTimer->CurCount].uArg.IOArg.PullMode > 1)?0:1);
  168. GPIO_Config(HWTimer->Cmd[HWTimer->CurCount].Arg1, 1, 0);
  169. HWTimer->CurCount++;
  170. break;
  171. case OP_QUEUE_CMD_CB:
  172. HWTimer->Cmd[HWTimer->CurCount].CB(HWTimerID, HWTimer->Cmd[HWTimer->CurCount].uParam.pParam);
  173. HWTimer->CurCount++;
  174. break;
  175. case OP_QUEUE_CMD_CAPTURE_SET:
  176. GPIO_PullConfig(HWTimer->Cmd[HWTimer->CurCount].Arg1, HWTimer->Cmd[HWTimer->CurCount].uArg.ExitArg.PullMode, (HWTimer->Cmd[HWTimer->CurCount].uArg.ExitArg.PullMode > 1)?0:1);
  177. GPIO_Config(HWTimer->Cmd[HWTimer->CurCount].Arg1, 1, 0);
  178. HWTimer->CapturePin = HWTimer->Cmd[HWTimer->CurCount].Arg1 & 0xf0;
  179. HWTimer->CapturePin = (HWTimer->CapturePin << 12) | (1 << (HWTimer->Cmd[HWTimer->CurCount].Arg1 & 0x0000000f));
  180. TIMM0->TIM[HWTimerID].ControlReg = 0;
  181. TIMM0->TIM[HWTimerID].LoadCount = HWTimer->Cmd[HWTimer->CurCount].uParam.MaxCnt;
  182. TIMM0->TIM[HWTimerID].ControlReg = TIMER_CONTROL_REG_TIMER_ENABLE|TIMER_CONTROL_REG_TIMER_MODE;
  183. GPIO_ExtiSetHWTimerCB(prvHWTimer_OperationQueuExti, HWTimerID);
  184. prvHWTimer[HWTimerID].ContinueDelay = 0;
  185. switch(HWTimer->Cmd[HWTimer->CurCount].uArg.ExitArg.ExtiMode)
  186. {
  187. case OP_QUEUE_CMD_IO_EXTI_BOTH:
  188. GPIO_ExtiConfig(HWTimer->Cmd[HWTimer->CurCount].Arg1, 0, 1, 1);
  189. break;
  190. case OP_QUEUE_CMD_IO_EXTI_UP:
  191. GPIO_ExtiConfig(HWTimer->Cmd[HWTimer->CurCount].Arg1, 0, 1, 0);
  192. break;
  193. case OP_QUEUE_CMD_IO_EXTI_DOWN:
  194. GPIO_ExtiConfig(HWTimer->Cmd[HWTimer->CurCount].Arg1, 0, 0, 1);
  195. break;
  196. }
  197. HWTimer->CurCount++;
  198. return;
  199. break;
  200. case OP_QUEUE_CMD_CAPTURE_END:
  201. TIMM0->TIM[HWTimerID].ControlReg = 0;
  202. GPIO_ExtiSetHWTimerCB(NULL, NULL);
  203. HWTimer->CurCount++;
  204. break;
  205. case OP_QUEUE_CMD_END:
  206. HWTimer->CurCount = 0;
  207. HWTimer->RepeatCnt++;
  208. if (HWTimer->RepeatCnt >= HWTimer->TotalRepeat)
  209. {
  210. TIMM0->TIM[HWTimerID].ControlReg = 0;
  211. TIMM0->TIM[HWTimerID].LoadCount = 24;
  212. ISR_SetHandler(prvHWTimer[HWTimerID].IrqLine, prvHWTimer_IrqHandlerEndOperationQueue, HWTimerID);
  213. #ifdef __BUILD_OS__
  214. ISR_SetPriority(prvHWTimer[HWTimerID].IrqLine, configLIBRARY_LOWEST_INTERRUPT_PRIORITY - 1);
  215. #else
  216. ISR_SetPriority(prvHWTimer[HWTimerID].IrqLine, 6);
  217. #endif
  218. TIMM0->TIM[HWTimerID].ControlReg = TIMER_CONTROL_REG_TIMER_ENABLE|TIMER_CONTROL_REG_TIMER_MODE;
  219. return;
  220. }
  221. break;
  222. }
  223. }
  224. return ;
  225. START_HWTIMER:
  226. TIMM0->TIM[HWTimerID].ControlReg = 0;
  227. Period = HWTimer->Cmd[HWTimer->CurCount].uArg.Time;
  228. Period = Period * SYS_TIMER_1US + HWTimer->Cmd[HWTimer->CurCount].Arg1;
  229. TIMM0->TIM[HWTimerID].LoadCount = Period;
  230. TIMM0->TIM[HWTimerID].ControlReg = TIMER_CONTROL_REG_TIMER_ENABLE|TIMER_CONTROL_REG_TIMER_MODE;
  231. HWTimer->CurCount++;
  232. return ;
  233. }
  234. static void __FUNC_IN_RAM__ prvHWTimer_IrqHandlerOperationQueue( int32_t Line, void *pData)
  235. {
  236. uint32_t HWTimerID = (uint32_t)pData;
  237. volatile uint32_t clr;
  238. clr = TIMM0->TIM[HWTimerID].EOI;
  239. if (!prvHWTimer[HWTimerID].ContinueDelay)
  240. {
  241. TIMM0->TIM[HWTimerID].ControlReg = 0;
  242. }
  243. prvHWTimer_StartOperationQueue(HWTimerID, &prvHWTimer[HWTimerID]);
  244. }
  245. void HWTimer_StartPWM(uint8_t HWTimerID, uint32_t HighCnt, uint32_t LowCnt, uint8_t IsOnePulse)
  246. {
  247. if (!HighCnt) HighCnt = 1;
  248. if (!LowCnt) LowCnt = 1;
  249. TIMM0->TIM[HWTimerID].LoadCount = LowCnt - 1;
  250. TIMM0->TIM_ReloadCount[HWTimerID] = HighCnt - 1;
  251. if (IsOnePulse)
  252. {
  253. TIMM0->TIM[HWTimerID].ControlReg = TIMER_CONTROL_REG_PWM_SINGLE_PULSE|TIMER_CONTROL_REG_TIMER_PWM|TIMER_CONTROL_REG_TIMER_MODE|TIMER_CONTROL_REG_TIMER_ENABLE|TIMER_CONTROL_REG_TIMER_INTERRUPT;;
  254. }
  255. else
  256. {
  257. TIMM0->TIM[HWTimerID].ControlReg = TIMER_CONTROL_REG_TIMER_PWM|TIMER_CONTROL_REG_TIMER_MODE|TIMER_CONTROL_REG_TIMER_ENABLE|TIMER_CONTROL_REG_TIMER_INTERRUPT;
  258. }
  259. }
  260. void HWTimer_SetPWM(uint8_t HWTimerID, uint32_t Period, uint16_t Duty, uint8_t IsOnePulse)
  261. {
  262. uint32_t TotalCnt;
  263. uint32_t LowCnt, HighCnt;
  264. if (Duty >= 999) return;
  265. if (Period > (SystemCoreClock >> 3)) return;
  266. switch(Period)
  267. {
  268. case 24000000:
  269. LowCnt = 1;
  270. HighCnt = 1;
  271. break;
  272. case 12000000:
  273. LowCnt = 2;
  274. HighCnt = 2;
  275. break;
  276. case 6000000:
  277. LowCnt = 3;
  278. HighCnt = 3;
  279. break;
  280. default:
  281. TotalCnt = (SystemCoreClock >> 2) / Period;
  282. HighCnt = (TotalCnt * Duty) / 1000;
  283. if ((TotalCnt - HighCnt) < 1)
  284. {
  285. LowCnt = 1;
  286. HighCnt = TotalCnt - LowCnt;
  287. }
  288. else
  289. {
  290. LowCnt = TotalCnt - HighCnt;
  291. }
  292. break;
  293. }
  294. HWTimer_StartPWM(HWTimerID, HighCnt, LowCnt, IsOnePulse);
  295. // DBG("L %u, H %u", LowCnt, HighCnt);
  296. // TIMM0->TIM[HWTimerID].LoadCount = LowCnt - 1;
  297. // TIMM0->TIM_ReloadCount[HWTimerID] = HighCnt - 1;
  298. // if (IsOnePulse)
  299. // {
  300. // TIMM0->TIM[HWTimerID].ControlReg = TIMER_CONTROL_REG_PWM_SINGLE_PULSE|TIMER_CONTROL_REG_TIMER_PWM|TIMER_CONTROL_REG_TIMER_MODE|TIMER_CONTROL_REG_TIMER_ENABLE|TIMER_CONTROL_REG_TIMER_INTERRUPT;;
  301. // }
  302. // else
  303. // {
  304. // TIMM0->TIM[HWTimerID].ControlReg = TIMER_CONTROL_REG_TIMER_PWM|TIMER_CONTROL_REG_TIMER_MODE|TIMER_CONTROL_REG_TIMER_ENABLE|TIMER_CONTROL_REG_TIMER_INTERRUPT;
  305. // }
  306. }
  307. void HWTimer_Stop(uint8_t HWTimerID)
  308. {
  309. volatile uint32_t clr;
  310. ISR_OnOff(prvHWTimer[HWTimerID].IrqLine, 0);
  311. clr = TIMM0->TIM[HWTimerID].EOI;
  312. TIMM0->TIM[HWTimerID].ControlReg = 0;
  313. ISR_Clear(prvHWTimer[HWTimerID].IrqLine);
  314. prvHWTimer[HWTimerID].IsQueueRunning = 0;
  315. prvHWTimer[HWTimerID].ContinueDelay = 0;
  316. }
  317. void HWTimer_InitOperationQueue(uint8_t HWTimerID, uint32_t nCount, uint32_t Repeat, uint32_t InputByte, CBFuncEx_t CmdDoneCB, void *pCmdDoneParam)
  318. {
  319. if (prvHWTimer[HWTimerID].IsQueueRunning)
  320. {
  321. HWTimer_Stop(HWTimerID);
  322. prvHWTimer[HWTimerID].CmdDoneCB(-ERROR_OPERATION_FAILED, prvHWTimer[HWTimerID].pCmdDoneParam);
  323. }
  324. prvHWTimer[HWTimerID].TotalCount = nCount;
  325. prvHWTimer[HWTimerID].TotalRepeat = Repeat;
  326. if (InputByte)
  327. {
  328. OS_ReInitBuffer(&prvHWTimer[HWTimerID].InDataBuf, InputByte);
  329. }
  330. else
  331. {
  332. OS_DeInitBuffer(&prvHWTimer[HWTimerID].InDataBuf);
  333. }
  334. if (prvHWTimer[HWTimerID].Cmd)
  335. {
  336. OS_Free(prvHWTimer[HWTimerID].Cmd);
  337. prvHWTimer[HWTimerID].Cmd = NULL;
  338. }
  339. prvHWTimer[HWTimerID].Cmd = OS_Zalloc((nCount + 1) * sizeof(OPQueue_CmdStruct));
  340. prvHWTimer[HWTimerID].CmdQueuePos = 0;
  341. if (CmdDoneCB)
  342. {
  343. prvHWTimer[HWTimerID].CmdDoneCB = CmdDoneCB;
  344. }
  345. else
  346. {
  347. prvHWTimer[HWTimerID].CmdDoneCB = prvHWTimer_DummyCB;
  348. }
  349. prvHWTimer[HWTimerID].pCmdDoneParam = pCmdDoneParam;
  350. }
  351. void HWTimer_AddOperation(uint8_t HWTimerID, OPQueue_CmdStruct *pCmd)
  352. {
  353. if (prvHWTimer[HWTimerID].TotalCount > prvHWTimer[HWTimerID].CmdQueuePos)
  354. {
  355. memcpy(&prvHWTimer[HWTimerID].Cmd[prvHWTimer[HWTimerID].CmdQueuePos], pCmd, sizeof(OPQueue_CmdStruct));
  356. prvHWTimer[HWTimerID].CmdQueuePos++;
  357. }
  358. }
  359. static void HWTimer_ResetOperationQueue(uint8_t HWTimerID)
  360. {
  361. prvHWTimer[HWTimerID].CurCount = 0;
  362. prvHWTimer[HWTimerID].RepeatCnt = 0;
  363. prvHWTimer[HWTimerID].InDataBuf.Pos = 0;
  364. if (prvHWTimer[HWTimerID].InDataBuf.MaxLen)
  365. {
  366. memset(prvHWTimer[HWTimerID].InDataBuf.Data, 0, prvHWTimer[HWTimerID].InDataBuf.MaxLen);
  367. }
  368. }
  369. void HWTimer_StartOperationQueue(uint8_t HWTimerID)
  370. {
  371. if (prvHWTimer[HWTimerID].IsQueueRunning)
  372. {
  373. HWTimer_Stop(HWTimerID);
  374. prvHWTimer[HWTimerID].CmdDoneCB(-ERROR_OPERATION_FAILED, prvHWTimer[HWTimerID].pCmdDoneParam);
  375. }
  376. else
  377. {
  378. HWTimer_Stop(HWTimerID);
  379. }
  380. ISR_SetHandler(prvHWTimer[HWTimerID].IrqLine, prvHWTimer_IrqHandlerOperationQueue, HWTimerID);
  381. ISR_SetPriority(prvHWTimer[HWTimerID].IrqLine, HWTIMER_IRQ_LEVEL);
  382. prvHWTimer[HWTimerID].Cmd[prvHWTimer[HWTimerID].CmdQueuePos].Operation = OP_QUEUE_CMD_END;
  383. HWTimer_ResetOperationQueue(HWTimerID);
  384. prvHWTimer[HWTimerID].IsQueueRunning = 1;
  385. prvHWTimer_StartOperationQueue(HWTimerID, &prvHWTimer[HWTimerID]);
  386. ISR_OnOff(prvHWTimer[HWTimerID].IrqLine, 1);
  387. }
  388. void HWTimer_ClearOperationQueue(uint8_t HWTimerID)
  389. {
  390. // HWTimer_ResetOperationQueue(HWTimerID);
  391. prvHWTimer[HWTimerID].CmdQueuePos = 0;
  392. }
  393. void HWTimer_FreeOperationQueue(uint8_t HWTimerID)
  394. {
  395. OS_DeInitBuffer(&prvHWTimer[HWTimerID].InDataBuf);
  396. OS_Free(prvHWTimer[HWTimerID].Cmd);
  397. prvHWTimer[HWTimerID].Cmd = NULL;
  398. prvHWTimer[HWTimerID].CmdDoneCB = prvHWTimer_DummyCB;
  399. }
  400. void HWTimer_AddEndCmdInOperationQueue(uint8_t HWTimerID)
  401. {
  402. HWTimer_CtrlStruct *HWTimer = &prvHWTimer[HWTimerID];
  403. if (HWTimer->Cmd[HWTimer->CurCount].Operation != OP_QUEUE_CMD_END)
  404. {
  405. HWTimer->Cmd[HWTimer->CurCount + 1].Operation = OP_QUEUE_CMD_END;
  406. }
  407. }
  408. uint8_t HWTimer_CheckOperationQueueDone(uint8_t HWTimerID)
  409. {
  410. return !prvHWTimer[HWTimerID].IsQueueRunning;
  411. }
  412. int HWTimer_GetOperationQueueInputResult(uint8_t HWTimerID, uint8_t *Value)
  413. {
  414. memcpy(Value, prvHWTimer[HWTimerID].InDataBuf.Data, prvHWTimer[HWTimerID].InDataBuf.MaxLen);
  415. return prvHWTimer[HWTimerID].InDataBuf.MaxLen;
  416. }
  417. uint32_t HWTimer_GetOperationQueueCaptureResult(uint8_t HWTimerID, CBFuncEx_t CB, void *pParam)
  418. {
  419. uint32_t i = 0;
  420. uint32_t Cnt = 0;
  421. if (!prvHWTimer[HWTimerID].Cmd) return 0;
  422. for(i = 0; i < prvHWTimer[HWTimerID].CmdQueuePos; i++)
  423. {
  424. if (OP_QUEUE_CMD_CAPTURE == prvHWTimer[HWTimerID].Cmd[i].Operation)
  425. {
  426. CB(&prvHWTimer[HWTimerID].Cmd[i], pParam);
  427. Cnt++;
  428. }
  429. }
  430. return Cnt;
  431. }