Appiko
time_tracker.h
1 /*
2  * time_tracker.h : Module to keep track of time in MS_TIEMR ticks
3  * Copyright (C) 2019 Appiko
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef CODEBASE_PERIPHERAL_MODULES_TIME_TRACKER_H_
20 #define CODEBASE_PERIPHERAL_MODULES_TIME_TRACKER_H_
21 
32 #include "stdint.h"
33 #include "ms_timer.h"
34 #include "nvm_logger.h"
35 
36 #ifndef MS_TIMER_FREQ
37 #error "Time Tracker module requires MS Timer module"
38 #endif
39 
40 #ifndef TIME_TRACKER_NVM_NO_PAGES_USED
41 #define TIME_TRACKER_NVM_NO_PAGES_USED 2
42 #endif
43 #ifndef TIME_TRACKER_NVM_PAGE_USED_0
44 #define TIME_TRACKER_NVM_PAGE_USED_0 NVM_LOG_PAGE0
45 #endif
46 
47 #ifndef TIME_TRACKER_NVM_PAGE_USED_1
48 #define TIME_TRACKER_NVM_PAGE_USED_1 NVM_LOG_PAGE1
49 #endif
50 
51 #define TIME_TRACKER_TIME_NOT_SET 0xFFFFFFFF
52 
53 #define TIME_TRACKER_DAY_LEN_S (24 * 3600 )
54 
55 typedef struct
56 {
57  uint8_t dd;
58  uint8_t mm;
59  uint8_t yy;
60 }time_tracker_ddmmyy_t;
61 
68 uint32_t time_tracker_init (uint32_t time_log);
69 
76 void time_tracker_set_date_time (time_tracker_ddmmyy_t * p_date_ddmmyy, uint32_t time_s);
77 
82 void time_tracker_update_time (uint32_t ticks);
83 
89 
95 time_tracker_ddmmyy_t * time_tracker_get_current_date ();
96 
97 #endif /* CODEBASE_PERIPHERAL_MODULES_TIME_TRACKER_H_ */
98 
uint32_t time_tracker_init(uint32_t time_log)
Function to initiate the time tracker module.
Definition: time_tracker.c:70
time_tracker_ddmmyy_t * time_tracker_get_current_date()
Function to get current date.
Definition: time_tracker.c:125
void time_tracker_set_date_time(time_tracker_ddmmyy_t *p_date_ddmmyy, uint32_t time_s)
Function to set current time.
Definition: time_tracker.c:96
uint32_t time_tracker_get_current_time_s()
Function to get current time in ms.
Definition: time_tracker.c:120
void time_tracker_update_time(uint32_t ticks)
Function to update time.
Definition: time_tracker.c:106