Skip to content

Commit 17c291d

Browse files
author
Wegmann Peter
committed
added timer util
1 parent 2f24e4d commit 17c291d

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

timerUtil.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* timerUtil.c
3+
*
4+
* Created: 18.05.2022 09:57:51
5+
* Author: qfj
6+
*/
7+
8+
#include <stdint.h>
9+
10+
#include "Gascounter_main.h"
11+
#include "timerUtil.h"
12+
13+
TimerArrType timers = {.t_elapsed = &count_t_elapsed,.TArr[RECONNECT].end = 0,.TArr[RECONNECT].start = 0};
14+
15+
16+
void t_start(TIMER_NAME t_name,uint32_t duration_s){
17+
timers.TArr[t_name].start = *timers.t_elapsed;
18+
timers.TArr[t_name].end = *timers.t_elapsed +duration_s;
19+
}
20+
21+
uint8_t t_check(TIMER_NAME t_name){
22+
if (*timers.t_elapsed >= timers.TArr[t_name].end){
23+
return 1;
24+
}
25+
return 0;
26+
}

timerUtil.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* timerUtil.h
3+
*
4+
* Created: 18.05.2022 09:57:37
5+
* Author: qfj
6+
*/
7+
8+
9+
#ifndef TIMERUTIL_H_
10+
#define TIMERUTIL_H_
11+
12+
13+
typedef struct
14+
{
15+
uint32_t start;
16+
uint32_t end;
17+
}TimerType;
18+
19+
20+
typedef struct
21+
{
22+
TimerType TArr[20];
23+
volatile uint32_t * t_elapsed;
24+
}TimerArrType;
25+
26+
27+
28+
typedef enum {
29+
RECONNECT,
30+
PING,
31+
I2C_CHECK
32+
33+
}TIMER_NAME;
34+
35+
void t_start(TIMER_NAME t_name,uint32_t duration_s);
36+
uint8_t t_check(TIMER_NAME t_name);
37+
#endif /* TIMERUTIL_H_ */

0 commit comments

Comments
 (0)