rtc4 2.0.0.0
rtc4.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
28#ifndef RTC4_H
29#define RTC4_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_one_wire.h"
52
73#define RTC4_CMD_READ_CLOCK 0x66
74#define RTC4_CMD_WRITE_CLOCK 0x99
75
76 // rtc4_cmd
77
92#define RTC4_SEC_PER_MINUTE 60
93#define RTC4_SEC_PER_HOUR 3600
94#define RTC4_SEC_PER_DAY 86400
95#define RTC4_START_YEAR 1970
96#define RTC4_DAYS_PER_LEAP_YEAR 366
97#define RTC4_DAYS_PER_YEAR 365
98#define RTC4_DAYS_IN_FEB 29
99
100 // rtc4_time
101
116#define RTC4_DCB_INT_ENABLE 0x80
117#define RTC4_DCB_OSC_ENABLE 0x0C
118#define RTC4_DCB_INTERVAL_1S 0x00
119#define RTC4_DCB_INTERVAL_4S 0x10
120#define RTC4_DCB_INTERVAL_32S 0x20
121#define RTC4_DCB_INTERVAL_64S 0x30
122#define RTC4_DCB_INTERVAL_2048S 0x40
123#define RTC4_DCB_INTERVAL_4096S 0x50
124#define RTC4_DCB_INTERVAL_65536S 0x60
125#define RTC4_DCB_INTERVAL_131072S 0x70
126
131#define RTC4_FAMILY_CODE 0x27
132
133 // rtc4_set
134
149#define RTC4_MAP_MIKROBUS( cfg, mikrobus ) \
150 cfg.gp0 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
151 cfg.gp1 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
152 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
153
154 // rtc4_map
155
156 // rtc4
157
162typedef struct
163{
164 uint32_t hours;
165 uint32_t min;
166 uint32_t sec;
167
169
174typedef struct
175{
176 uint32_t year;
177 uint32_t month;
178 uint32_t day;
179
181
192
197typedef struct
198{
199 //Input pins
200 digital_in_t int_pin;
202 //Modules
203 one_wire_t ow;
205 one_wire_rom_address_t rom_addr;
206 uint8_t address;
208} rtc4_t;
209
214typedef struct
215{
216 // Communication gpio pins
217 pin_name_t gp0;
218 pin_name_t gp1;
220 // Additional gpio pins
221 pin_name_t int_pin;
225} rtc4_cfg_t;
226
231typedef enum
232{
234 RTC4_ERROR = -1
235
237
254
270
282err_t rtc4_init ( rtc4_t *ctx, rtc4_cfg_t *cfg );
283
296
306uint8_t rtc4_get_interrupt ( rtc4_t *ctx );
307
319err_t rtc4_set_unix_and_int ( rtc4_t *ctx, uint32_t unix_time, uint8_t int_interval );
320
333err_t rtc4_get_unix_time ( rtc4_t *ctx, uint32_t *unix_time );
334
346void rtc4_unix_to_date_time ( uint32_t unix_time, rtc4_time_t *time, rtc4_date_t *date );
347
359void rtc4_date_time_to_unix ( rtc4_date_t *date, rtc4_time_t *time, uint32_t *unix_time );
360
374err_t rtc4_set_date_time ( rtc4_t *ctx, rtc4_date_t *date, rtc4_time_t *time, uint8_t int_interval );
375
389
390#ifdef __cplusplus
391}
392#endif
393#endif // RTC4_H
394
395 // rtc4
396
397// ------------------------------------------------------------------------ END
void rtc4_date_time_to_unix(rtc4_date_t *date, rtc4_time_t *time, uint32_t *unix_time)
RTC 4 date time to unix function.
err_t rtc4_check_communication(rtc4_t *ctx)
RTC 4 check communication function.
void rtc4_unix_to_date_time(uint32_t unix_time, rtc4_time_t *time, rtc4_date_t *date)
RTC 4 unix to date time function.
err_t rtc4_set_date_time(rtc4_t *ctx, rtc4_date_t *date, rtc4_time_t *time, uint8_t int_interval)
RTC 4 set date time function.
err_t rtc4_init(rtc4_t *ctx, rtc4_cfg_t *cfg)
RTC 4 initialization function.
err_t rtc4_get_unix_time(rtc4_t *ctx, uint32_t *unix_time)
RTC 4 get unix time function.
void rtc4_cfg_setup(rtc4_cfg_t *cfg)
RTC 4 configuration object setup function.
void rtc4_gpio_selection(rtc4_cfg_t *cfg, rtc4_gpio_sel_t gpio_sel)
RTC 4 driver interface setup function.
err_t rtc4_set_unix_and_int(rtc4_t *ctx, uint32_t unix_time, uint8_t int_interval)
RTC 4 set unix and interrupt interval function.
err_t rtc4_get_date_time(rtc4_t *ctx, rtc4_date_t *date, rtc4_time_t *time)
RTC 4 get date time function.
uint8_t rtc4_get_interrupt(rtc4_t *ctx)
RTC 4 get interrupt function.
rtc4_date_t date
Definition main.c:31
rtc4_time_t time
Definition main.c:30
rtc4_return_value_t
RTC 4 Click return value data.
Definition rtc4.h:232
@ RTC4_OK
Definition rtc4.h:233
@ RTC4_ERROR
Definition rtc4.h:234
rtc4_gpio_sel_t
RTC 4 Click gpio selector.
Definition rtc4.h:187
@ RTC4_GPIO_1
Definition rtc4.h:189
@ RTC4_GPIO_0
Definition rtc4.h:188
RTC 4 Click configuration object.
Definition rtc4.h:215
pin_name_t gp0
Definition rtc4.h:217
pin_name_t int_pin
Definition rtc4.h:221
pin_name_t gp1
Definition rtc4.h:218
rtc4_gpio_sel_t gpio_sel
Definition rtc4.h:223
RTC 4 Click date object.
Definition rtc4.h:175
uint32_t month
Definition rtc4.h:177
uint32_t day
Definition rtc4.h:178
uint32_t year
Definition rtc4.h:176
RTC 4 Click context object.
Definition rtc4.h:198
one_wire_rom_address_t rom_addr
Definition rtc4.h:205
digital_in_t int_pin
Definition rtc4.h:200
uint8_t address
Definition rtc4.h:206
one_wire_t ow
Definition rtc4.h:203
RTC 4 Click time object.
Definition rtc4.h:163
uint32_t min
Definition rtc4.h:165
uint32_t sec
Definition rtc4.h:166
uint32_t hours
Definition rtc4.h:164