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 )
78#define TIMER_RETVAL uint8_t
79
80#define TIMER_OK 0x00
81#define TIMER_INIT_ERROR 0xFF
88#define TIMER_I2C_ADDR 0x6B
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
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
122#define TIMER_EEPROM_SIZE 10
125 // End group macro
126// --------------------------------------------------------------- PUBLIC TYPES
135typedef 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
152
153} timer_t;
154
158typedef 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
176
177 // End types group
178// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
179
185#ifdef __cplusplus
186extern "C"{
187#endif
188
198
208
219void timer_generic_write ( timer_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
220
232void timer_generic_read ( timer_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
233
242
252
263void timer_write_byte_eeprom ( timer_t *ctx, uint8_t location, uint8_t write_data );
264
277uint8_t timer_read_byte_eeprom ( timer_t *ctx, uint8_t location );
278
290
301uint32_t timer_get_etc_data ( timer_t *ctx );
302
312void timer_set_etc_data ( timer_t *ctx, uint32_t etc_value );
313
325
338void timer_get_time ( timer_t *ctx, uint16_t *time_days, uint8_t *time_hours, uint8_t *time_minutes, uint8_t *time_seconds );
339
349void timer_set_etc_seconds ( timer_t *ctx, uint32_t etc_seconds );
350
361uint16_t timer_get_ec_data ( timer_t *ctx );
362
372void timer_set_ec_data ( timer_t *ctx, uint16_t ec_value );
373
385
395void timer_set_ec_seconds ( timer_t *ctx, uint16_t ec_seconds );
396
408
418void timer_set_alarm_data ( timer_t *ctx, uint32_t a_data );
419
431
443void timer_get_alarm_time ( timer_t *ctx, uint16_t *time_days, uint8_t *time_hours, uint8_t *time_minutes, uint8_t *time_seconds );
444
454void timer_set_alarm_seconds ( timer_t *ctx, uint32_t alarm_seconds );
455
469
479
489
499
509
519
536
546
559
560
561#ifdef __cplusplus
562}
563#endif
564#endif // _TIMER_H_
565
566 // End public_function group
568
569// ------------------------------------------------------------------------- END
#define TIMER_RETVAL
Definition timer.h:78
void timer_set_alarm_seconds(timer_t *ctx, uint32_t alarm_seconds)
Set alarm seconds function.
uint8_t timer_check_interrupt(timer_t *ctx)
Check interrupt function.
void timer_set_etc_data(timer_t *ctx, uint32_t etc_value)
Set elapsed time counter (ETC) data function.
TIMER_RETVAL timer_init(timer_t *ctx, timer_cfg_t *cfg)
Initialization function.
void timer_enable_write(timer_t *ctx)
Enable write data function.
void timer_cfg_setup(timer_cfg_t *cfg)
Config Object Initialization function.
void timer_set_etc_seconds(timer_t *ctx, uint32_t etc_seconds)
Set elapsed time counter (ETC) seconds function.
uint32_t timer_get_etc_seconds(timer_t *ctx)
Get elapsed time counter (ETC) seconds function.
void timer_set_ec_data(timer_t *ctx, uint16_t ec_value)
Set elapsed time counter (EC) data function.
uint32_t timer_get_etc_data(timer_t *ctx)
Get elapsed time counter (ETC) data function.
uint8_t timer_get_alarm_flag(timer_t *ctx)
Get alarm flag function.
void timer_set_ec_seconds(timer_t *ctx, uint16_t ec_seconds)
Set elapsed time counter (EC) seconds function.
void timer_generic_read(timer_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void timer_generic_write(timer_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write 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.
uint32_t timer_get_alarm_seconds(timer_t *ctx)
Get alarm seconds function.
uint8_t timer_check_write_disable(timer_t *ctx)
Check write disable ( write protection ) 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_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.
uint16_t timer_get_ec_seconds(timer_t *ctx)
Get elapsed time counter (EC) seconds function.
void timer_set_alarm_data(timer_t *ctx, uint32_t a_data)
Set alarm data function.
void timer_reset_enable(timer_t *ctx)
Set enable reset function.
void timer_soft_reset(timer_t *ctx)
Soft reset function.
uint16_t timer_get_ec_data(timer_t *ctx)
Get event counter (EC) data function.
void timer_alarm_output_select(timer_t *ctx)
Set alarm output select function.
void timer_hw_reset(timer_t *ctx)
Hardwere reset function.
void timer_disable_write(timer_t *ctx)
Disable write data ( write protection ) function.
uint8_t timer_get_configuration(timer_t *ctx)
Get configuration data function.
void timer_write_byte_eeprom(timer_t *ctx, uint8_t location, uint8_t write_data)
Write data from the EEPROM memory function.
void timer_read_eeprom(timer_t *ctx)
Read data from the EEPROM memory function.
void timer_set_alarm_polarity(timer_t *ctx)
Set alarm polarity function.
uint32_t timer_get_alarm_data(timer_t *ctx)
Get alarm data function.
Click configuration structure definition.
Definition timer.h:159
uint32_t i2c_speed
Definition timer.h:172
pin_name_t evt
Definition timer.h:167
pin_name_t scl
Definition timer.h:162
pin_name_t sda
Definition timer.h:163
pin_name_t alm
Definition timer.h:168
uint8_t i2c_address
Definition timer.h:173
Click ctx object definition.
Definition timer.h:136
digital_out_t evt
Definition timer.h:139
digital_in_t alm
Definition timer.h:143
i2c_master_t i2c
Definition timer.h:147
uint8_t slave_address
Definition timer.h:151