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 
42 #ifdef PREINIT_SUPPORTED
43 #include "preinit.h"
44 #endif
45 
46 #ifdef MikroCCoreVersion
47  #if MikroCCoreVersion >= 1
48  #include "delays.h"
49  #endif
50 #endif
51 
52 #include "drv_digital_out.h"
53 #include "drv_digital_in.h"
54 #include "drv_i2c_master.h"
55 
56 
57 // -------------------------------------------------------------- PUBLIC MACROS
67 #define TIMER_MAP_MIKROBUS( cfg, mikrobus ) \
68  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
69  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
70  cfg.evt = MIKROBUS( mikrobus, MIKROBUS_RST ); \
71  cfg.alm = MIKROBUS( mikrobus, MIKROBUS_INT )
72 
78 #define TIMER_RETVAL uint8_t
79 
80 #define TIMER_OK 0x00
81 #define TIMER_INIT_ERROR 0xFF
82 
88 #define TIMER_I2C_ADDR 0x6B
89 
95 #define TIMER_REG_CONFIG 0x00
96 #define TIMER_REG_ALARM 0x01
97 #define TIMER_REG_ELAPSED 0x05
98 #define TIMER_REG_EVT_CNTR 0x09
99 #define TIMER_REG_EEPROM 0x0B
100 #define TIMER_REG_RESET 0x1D
101 #define TIMER_REG_WRITE_DISABLE 0x1E
102 #define TIMER_REG_WRITE_MEM_DISABLE 0x1F
103 
109 #define TIMER_ECMSB_BIT 0x01
110 #define TIMER_AP_BIT 0x02
111 #define TIMER_RE_BIT 0x04
112 #define TIMER_AOS_BIT 0x08
113 #define TIMER_WMDF_BIT 0x10
114 #define TIMER_WDF_BIT 0x20
115 #define TIMER_AF_BIT 0x40
116 
122 #define TIMER_EEPROM_SIZE 10
123  // End group macro
126 // --------------------------------------------------------------- PUBLIC TYPES
135 typedef struct
136 {
137  // Output pins
138 
139  digital_out_t evt;
140 
141  // Input pins
142 
143  digital_in_t alm;
144 
145  // Modules
146 
147  i2c_master_t i2c;
148 
149  // ctx variable
150 
151  uint8_t slave_address;
152 
153 } timer_t;
154 
158 typedef struct
159 {
160  // Communication gpio pins
161 
162  pin_name_t scl;
163  pin_name_t sda;
164 
165  // Additional gpio pins
166 
167  pin_name_t evt;
168  pin_name_t alm;
169 
170  // static variable
171 
172  uint32_t i2c_speed;
173  uint8_t i2c_address;
174 
175 } timer_cfg_t;
176  // End types group
178 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
179 
185 #ifdef __cplusplus
186 extern "C"{
187 #endif
188 
198 
208 
219 void timer_generic_write ( timer_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
220 
232 void timer_generic_read ( timer_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
233 
241 void timer_hw_reset ( timer_t *ctx );
242 
252 
263 void timer_write_byte_eeprom ( timer_t *ctx, uint8_t location, uint8_t write_data );
264 
277 uint8_t timer_read_byte_eeprom ( timer_t *ctx, uint8_t location );
278 
290 
301 uint32_t timer_get_etc_data ( timer_t *ctx );
302 
312 void timer_set_etc_data ( timer_t *ctx, uint32_t etc_value );
313 
324 uint32_t timer_get_etc_seconds ( timer_t *ctx );
325 
338 void timer_get_time ( timer_t *ctx, uint16_t *time_days, uint8_t *time_hours, uint8_t *time_minutes, uint8_t *time_seconds );
339 
349 void timer_set_etc_seconds ( timer_t *ctx, uint32_t etc_seconds );
350 
361 uint16_t timer_get_ec_data ( timer_t *ctx );
362 
372 void timer_set_ec_data ( timer_t *ctx, uint16_t ec_value );
373 
384 uint16_t timer_get_ec_seconds ( timer_t *ctx );
385 
395 void timer_set_ec_seconds ( timer_t *ctx, uint16_t ec_seconds );
396 
407 uint32_t timer_get_alarm_data ( timer_t *ctx );
408 
418 void timer_set_alarm_data ( timer_t *ctx, uint32_t a_data );
419 
431 
443 void timer_get_alarm_time ( timer_t *ctx, uint16_t *time_days, uint8_t *time_hours, uint8_t *time_minutes, uint8_t *time_seconds );
444 
454 void timer_set_alarm_seconds ( timer_t *ctx, uint32_t alarm_seconds );
455 
469 
479 
489 
499 
509 
519 
535 uint8_t timer_get_alarm_flag ( timer_t *ctx );
536 
545 void timer_soft_reset ( timer_t *ctx );
546 
559 
560 
561 #ifdef __cplusplus
562 }
563 #endif
564 #endif // _TIMER_H_
565  // End public_function group
568 
569 // ------------------------------------------------------------------------- END
timer_write_byte_eeprom
void timer_write_byte_eeprom(timer_t *ctx, uint8_t location, uint8_t write_data)
Write data from the EEPROM memory function.
timer_set_alarm_polarity
void timer_set_alarm_polarity(timer_t *ctx)
Set alarm polarity function.
timer_soft_reset
void timer_soft_reset(timer_t *ctx)
Soft reset function.
TIMER_RETVAL
#define TIMER_RETVAL
Definition: timer.h:78
timer_check_write_disable
uint8_t timer_check_write_disable(timer_t *ctx)
Check write disable ( write protection ) function.
timer_cfg_t::i2c_address
uint8_t i2c_address
Definition: timer.h:173
timer_get_etc_data
uint32_t timer_get_etc_data(timer_t *ctx)
Get elapsed time counter (ETC) data function.
timer_get_alarm_time
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.
timer_get_alarm_seconds
uint32_t timer_get_alarm_seconds(timer_t *ctx)
Get alarm seconds function.
timer_t::evt
digital_out_t evt
Definition: timer.h:139
timer_set_ec_data
void timer_set_ec_data(timer_t *ctx, uint16_t ec_value)
Set elapsed time counter (EC) data function.
timer_t
Click ctx object definition.
Definition: timer.h:136
timer_reset_enable
void timer_reset_enable(timer_t *ctx)
Set enable reset function.
timer_hw_reset
void timer_hw_reset(timer_t *ctx)
Hardwere reset function.
timer_set_etc_seconds
void timer_set_etc_seconds(timer_t *ctx, uint32_t etc_seconds)
Set elapsed time counter (ETC) seconds function.
timer_generic_write
void timer_generic_write(timer_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
timer_get_alarm_flag
uint8_t timer_get_alarm_flag(timer_t *ctx)
Get alarm flag function.
timer_check_interrupt
uint8_t timer_check_interrupt(timer_t *ctx)
Check interrupt function.
timer_t::slave_address
uint8_t slave_address
Definition: timer.h:151
timer_cfg_t::sda
pin_name_t sda
Definition: timer.h:163
timer_read_byte_eeprom
uint8_t timer_read_byte_eeprom(timer_t *ctx, uint8_t location)
Read the byte of data from the EEPROM memory function.
timer_cfg_t::scl
pin_name_t scl
Definition: timer.h:162
timer_get_time
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.
timer_get_configuration
uint8_t timer_get_configuration(timer_t *ctx)
Get configuration data function.
timer_cfg_setup
void timer_cfg_setup(timer_cfg_t *cfg)
Config Object Initialization function.
timer_cfg_t::alm
pin_name_t alm
Definition: timer.h:168
timer_t::i2c
i2c_master_t i2c
Definition: timer.h:147
timer_enable_write
void timer_enable_write(timer_t *ctx)
Enable write data function.
timer_read_eeprom
void timer_read_eeprom(timer_t *ctx)
Read data from the EEPROM memory function.
timer_set_alarm_seconds
void timer_set_alarm_seconds(timer_t *ctx, uint32_t alarm_seconds)
Set alarm seconds function.
timer_t::alm
digital_in_t alm
Definition: timer.h:143
timer_set_ec_seconds
void timer_set_ec_seconds(timer_t *ctx, uint16_t ec_seconds)
Set elapsed time counter (EC) seconds function.
timer_alarm_output_select
void timer_alarm_output_select(timer_t *ctx)
Set alarm output select function.
timer_cfg_t
Click configuration structure definition.
Definition: timer.h:159
timer_cfg_t::evt
pin_name_t evt
Definition: timer.h:167
timer_set_alarm_data
void timer_set_alarm_data(timer_t *ctx, uint32_t a_data)
Set alarm data function.
timer_get_etc_seconds
uint32_t timer_get_etc_seconds(timer_t *ctx)
Get elapsed time counter (ETC) seconds function.
timer_set_etc_data
void timer_set_etc_data(timer_t *ctx, uint32_t etc_value)
Set elapsed time counter (ETC) data function.
timer_init
TIMER_RETVAL timer_init(timer_t *ctx, timer_cfg_t *cfg)
Initialization function.
timer_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: timer.h:172
timer_generic_read
void timer_generic_read(timer_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
timer_disable_write
void timer_disable_write(timer_t *ctx)
Disable write data ( write protection ) function.
timer_get_ec_data
uint16_t timer_get_ec_data(timer_t *ctx)
Get event counter (EC) data function.
timer_get_alarm_data
uint32_t timer_get_alarm_data(timer_t *ctx)
Get alarm data function.
timer_get_ec_seconds
uint16_t timer_get_ec_seconds(timer_t *ctx)
Get elapsed time counter (EC) seconds function.