| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- #include "timeout.h"
- /*----------------------------------------------------------------------------
- * 设置定时器
- * tt:定时器指针
- * val,延时ms
- *---------------------------------------------------------------------------*/
- void timeout_setValue(timeout_t *tt,uint32_t val){
- tt->counter = Get_SysTick();
- tt->timeout = val;
- }
- /*----------------------------------------------------------------------------
- * 启动定时器
- * tt :定时器指针
- *---------------------------------------------------------------------------*/
- void timeout_start(timeout_t *tt){
- tt->counter = Get_SysTick();
- tt->flag = 1;
- tt->endMode = 1;
- }
- /*----------------------------------------------------------------------------
- * 停止定时器
- * tt: 定时器指针
- *---------------------------------------------------------------------------*/
- void timeout_stop(timeout_t *tt){
- tt->flag = 0;
- tt->endMode = 2;
- }
- /*----------------------------------------------------------------------------
- * 返回定时器是否超时
- * tt:定时器指针
- * 返回值 1:超时 0:未超时
- *---------------------------------------------------------------------------*/
- uint8_t timeout_isOut(timeout_t *tt){
- if(tt->flag){
- if((Get_SysTick() - tt->counter) > tt->timeout){
- tt->counter = Get_SysTick();
- if(tt->flag == 1){
- tt->flag = 0;
- }
- tt->endMode = 0x03;
- return 1;
- }
- else{
- return 0;
- }
- }
- else{
- return 1;
- }
- }
|