timer  2.0.0.0
timer.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef TIMER_H
36 #define TIMER_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define TIMER_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
56  cfg.evt = MIKROBUS( mikrobus, MIKROBUS_RST ); \
57  cfg.alm = MIKROBUS( mikrobus, MIKROBUS_INT )
58 
64 #define TIMER_RETVAL uint8_t
65 
66 #define TIMER_OK 0x00
67 #define TIMER_INIT_ERROR 0xFF
68 
74 #define TIMER_I2C_ADDR 0x6B
75 
81 #define TIMER_REG_CONFIG 0x00
82 #define TIMER_REG_ALARM 0x01
83 #define TIMER_REG_ELAPSED 0x05
84 #define TIMER_REG_EVT_CNTR 0x09
85 #define TIMER_REG_EEPROM 0x0B
86 #define TIMER_REG_RESET 0x1D
87 #define TIMER_REG_WRITE_DISABLE 0x1E
88 #define TIMER_REG_WRITE_MEM_DISABLE 0x1F
89 
95 #define TIMER_ECMSB_BIT 0x01
96 #define TIMER_AP_BIT 0x02
97 #define TIMER_RE_BIT 0x04
98 #define TIMER_AOS_BIT 0x08
99 #define TIMER_WMDF_BIT 0x10
100 #define TIMER_WDF_BIT 0x20
101 #define TIMER_AF_BIT 0x40
102 
108 #define TIMER_EEPROM_SIZE 10
109  // End group macro
112 // --------------------------------------------------------------- PUBLIC TYPES
121 typedef struct
122 {
123  // Output pins
124 
125  digital_out_t evt;
126 
127  // Input pins
128 
129  digital_in_t alm;
130 
131  // Modules
132 
133  i2c_master_t i2c;
134 
135  // ctx variable
136 
137  uint8_t slave_address;
138 
139 } timer_t;
140 
144 typedef struct
145 {
146  // Communication gpio pins
147 
148  pin_name_t scl;
149  pin_name_t sda;
150 
151  // Additional gpio pins
152 
153  pin_name_t evt;
154  pin_name_t alm;
155 
156  // static variable
157 
158  uint32_t i2c_speed;
159  uint8_t i2c_address;
160 
161 } timer_cfg_t;
162  // End types group
164 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
165 
171 #ifdef __cplusplus
172 extern "C"{
173 #endif
174 
183 void timer_cfg_setup ( timer_cfg_t *cfg );
184 
194 
205 void timer_generic_write ( timer_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
206 
218 void timer_generic_read ( timer_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
219 
227 void timer_hw_reset ( timer_t *ctx );
228 
237 void timer_read_eeprom ( timer_t *ctx );
238 
249 void timer_write_byte_eeprom ( timer_t *ctx, uint8_t location, uint8_t write_data );
250 
263 uint8_t timer_read_byte_eeprom ( timer_t *ctx, uint8_t location );
264 
275 uint8_t timer_get_configuration ( timer_t *ctx );
276 
287 uint32_t timer_get_etc_data ( timer_t *ctx );
288 
298 void timer_set_etc_data ( timer_t *ctx, uint32_t etc_value );
299 
310 uint32_t timer_get_etc_seconds ( timer_t *ctx );
311 
324 void timer_get_time ( timer_t *ctx, uint16_t *time_days, uint8_t *time_hours, uint8_t *time_minutes, uint8_t *time_seconds );
325 
335 void timer_set_etc_seconds ( timer_t *ctx, uint32_t etc_seconds );
336 
347 uint16_t timer_get_ec_data ( timer_t *ctx );
348 
358 void timer_set_ec_data ( timer_t *ctx, uint16_t ec_value );
359 
370 uint16_t timer_get_ec_seconds ( timer_t *ctx );
371 
381 void timer_set_ec_seconds ( timer_t *ctx, uint16_t ec_seconds );
382 
393 uint32_t timer_get_alarm_data ( timer_t *ctx );
394 
404 void timer_set_alarm_data ( timer_t *ctx, uint32_t a_data );
405 
416 uint32_t timer_get_alarm_seconds ( timer_t *ctx );
417 
429 void timer_get_alarm_time ( timer_t *ctx, uint16_t *time_days, uint8_t *time_hours, uint8_t *time_minutes, uint8_t *time_seconds );
430 
440 void timer_set_alarm_seconds ( timer_t *ctx, uint32_t alarm_seconds );
441 
454 uint8_t timer_check_write_disable ( timer_t *ctx );
455 
464 void timer_disable_write ( timer_t *ctx );
465 
474 void timer_enable_write ( timer_t *ctx );
475 
484 void timer_alarm_output_select ( timer_t *ctx );
485 
494 void timer_reset_enable ( timer_t *ctx );
495 
504 void timer_set_alarm_polarity ( timer_t *ctx );
505 
521 uint8_t timer_get_alarm_flag ( timer_t *ctx );
522 
531 void timer_soft_reset ( timer_t *ctx );
532 
544 uint8_t timer_check_interrupt ( timer_t *ctx );
545 
546 
547 #ifdef __cplusplus
548 }
549 #endif
550 #endif // _TIMER_H_
551  // End public_function group
554 
555 // ------------------------------------------------------------------------- END
pin_name_t alm
Definition: timer.h:154
void timer_alarm_output_select(timer_t *ctx)
Set alarm output select function.
digital_out_t evt
Definition: timer.h:125
void timer_enable_write(timer_t *ctx)
Enable write data function.
void timer_soft_reset(timer_t *ctx)
Soft reset function.
void timer_cfg_setup(timer_cfg_t *cfg)
Config Object Initialization function.
Click ctx object definition.
Definition: timer.h:121
pin_name_t sda
Definition: timer.h:149
void timer_get_alarm_time(timer_t *ctx, uint16_t *time_days, uint8_t *time_hours, uint8_t *time_minutes, uint8_t *time_seconds)
Get alarm time.
void timer_set_alarm_seconds(timer_t *ctx, uint32_t alarm_seconds)
Set alarm seconds function.
uint32_t timer_get_etc_data(timer_t *ctx)
Get elapsed time counter (ETC) data function.
uint16_t timer_get_ec_seconds(timer_t *ctx)
Get elapsed time counter (EC) seconds function.
uint32_t timer_get_alarm_seconds(timer_t *ctx)
Get alarm seconds function.
Click configuration structure definition.
Definition: timer.h:144
void timer_set_ec_seconds(timer_t *ctx, uint16_t ec_seconds)
Set elapsed time counter (EC) seconds function.
uint32_t timer_get_etc_seconds(timer_t *ctx)
Get elapsed time counter (ETC) seconds function.
void timer_get_time(timer_t *ctx, uint16_t *time_days, uint8_t *time_hours, uint8_t *time_minutes, uint8_t *time_seconds)
Set elapsed time counter (ETC) time function.
void timer_reset_enable(timer_t *ctx)
Set enable reset function.
uint8_t timer_check_interrupt(timer_t *ctx)
Check interrupt function.
pin_name_t evt
Definition: timer.h:153
uint16_t timer_get_ec_data(timer_t *ctx)
Get event counter (EC) data function.
void timer_hw_reset(timer_t *ctx)
Hardwere reset function.
pin_name_t scl
Definition: timer.h:148
#define TIMER_RETVAL
Definition: timer.h:64
void timer_set_etc_data(timer_t *ctx, uint32_t etc_value)
Set elapsed time counter (ETC) data function.
uint8_t timer_get_configuration(timer_t *ctx)
Get configuration data function.
uint32_t i2c_speed
Definition: timer.h:158
uint32_t timer_get_alarm_data(timer_t *ctx)
Get alarm data function.
void timer_set_etc_seconds(timer_t *ctx, uint32_t etc_seconds)
Set elapsed time counter (ETC) seconds function.
digital_in_t alm
Definition: timer.h:129
void timer_set_alarm_data(timer_t *ctx, uint32_t a_data)
Set alarm data function.
uint8_t i2c_address
Definition: timer.h:159
i2c_master_t i2c
Definition: timer.h:133
void timer_write_byte_eeprom(timer_t *ctx, uint8_t location, uint8_t write_data)
Write data from the EEPROM memory function.
uint8_t slave_address
Definition: timer.h:137
uint8_t timer_check_write_disable(timer_t *ctx)
Check write disable ( write protection ) function.
void timer_set_ec_data(timer_t *ctx, uint16_t ec_value)
Set elapsed time counter (EC) data function.
void timer_read_eeprom(timer_t *ctx)
Read data from the EEPROM memory function.
void timer_generic_write(timer_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
void timer_disable_write(timer_t *ctx)
Disable write data ( write protection ) function.
uint8_t timer_get_alarm_flag(timer_t *ctx)
Get alarm flag function.
TIMER_RETVAL timer_init(timer_t *ctx, timer_cfg_t *cfg)
Initialization function.
uint8_t timer_read_byte_eeprom(timer_t *ctx, uint8_t location)
Read the byte of data from the EEPROM memory function.
void timer_generic_read(timer_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void timer_set_alarm_polarity(timer_t *ctx)
Set alarm polarity function.