rtc11  2.0.0.0
rtc11.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 RTC11_H
29 #define RTC11_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_spi_master.h"
48 
69 #define RTC11_RD_BIT_MASK 0x7F
70 #define RTC11_WR_BIT_MASK 0x80
71 
72 #define RTC11_REG_HDT 0x00
73 #define RTC11_REG_SEC 0x01
74 #define RTC11_REG_MIN 0x02
75 #define RTC11_REG_HRS 0x03
76 #define RTC11_REG_DAT 0x04
77 #define RTC11_REG_MON 0x05
78 #define RTC11_REG_YRS 0x06
79 #define RTC11_REG_WKD 0x07
80 #define RTC11_REG_ALA_HDT 0x08
81 #define RTC11_REG_ALA_SEC 0x09
82 #define RTC11_REG_ALA_MIN 0x0A
83 #define RTC11_REG_ALA_HRS 0x0B
84 #define RTC11_REG_ALA_DAT 0x0C
85 #define RTC11_REG_ALA_MON 0x0D
86 #define RTC11_REG_ALA_WKD 0x0E
87 #define RTC11_REG_STAT 0x0F
88 #define RTC11_REG_CTL1 0x10
89 #define RTC11_REG_CTL2 0x11
90 #define RTC11_REG_INT_MSK 0x12
91 #define RTC11_REG_SQW 0x13
92 #define RTC11_REG_CAL_XT 0x14
93 #define RTC11_REG_CAL_RC_HI 0x15
94 #define RTC11_REG_CAL_RC_LOW 0x16
95 #define RTC11_REG_INT_POL 0x17
96 #define RTC11_REG_TMR_CTL 0x18
97 #define RTC11_REG_TMR 0x19
98 #define RTC11_REG_TMR_INIT 0x1A
99 #define RTC11_REG_WDT 0x1B
100 #define RTC11_REG_OSC_CTL 0x1C
101 #define RTC11_REG_OSC_STAT 0x1D
102 #define RTC11_REG_CFG_KEY 0x1F
103 #define RTC11_REG_TRCK 0x20
104 #define RTC11_REG_BREF_CTL 0x21
105 #define RTC11_REG_BAT_MODE 0x27
106 #define RTC11_REG_ID_0 0x28
107 #define RTC11_REG_ID_1 0x29
108 #define RTC11_REG_ID_2 0x2A
109 #define RTC11_REG_ID_3 0x2B
110 #define RTC11_REG_ID_4 0x2C
111 #define RTC11_REG_ID_5 0x2D
112 #define RTC11_REG_ID_6 0x2E
113 #define RTC11_REG_ASTAT 0x2F
114 #define RTC11_REG_OCTRL 0x30
115 #define RTC11_REG_EXT_ADR 0x3F
116 #define RTC11_REG_RAM 0x40
117  // rtc11_reg
119 
134 #define RTC11_CTL1_STOP 0x80
135 #define RTC11_CTL1_12_HRS 0x40
136 #define RTC11_CTL1_OUTB 0x20
137 #define RTC11_CTL1_OUT 0x10
138 #define RTC11_CTL1_ARST 0x04
139 #define RTC11_CTL1_WRTC 0x01
140 
141 #define RTC11_ACS_OSC_CTL 0xA1
142 #define RTC11_SW_RST 0x3C
143 #define RTC11_ACS_AN_CTL_REG 0x9D
144 
145 #define RTC11_CEB 0x80
146 #define RTC11_BLIE 0x10
147 #define RTC11_TIE 0x08
148 #define RTC11_AIE 0x04
149 #define RTC11_EX2E 0x02
150 #define RTC11_EX1E 0x01
151 
152 #define RTC11_PROP_DIS 0x00
153 #define RTC11_PROP_EN 0x01
154  // rtc11_set
156 
171 #define RTC11_MAP_MIKROBUS( cfg, mikrobus ) \
172  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
173  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
174  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
175  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
176  cfg.wdi = MIKROBUS( mikrobus, MIKROBUS_AN ); \
177  cfg.exi = MIKROBUS( mikrobus, MIKROBUS_RST ); \
178  cfg.it2 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
179  cfg.it1 = MIKROBUS( mikrobus, MIKROBUS_INT )
180  // rtc11_map // rtc11
183 
188 typedef struct
189 {
190  // Output pins
191  digital_out_t wdi;
192  digital_out_t exi;
194  // Input pins
195  digital_in_t it2;
196  digital_in_t it1;
198  // Modules
199  spi_master_t spi;
201  pin_name_t chip_select;
203 } rtc11_t;
204 
209 typedef struct
210 {
211  // Communication gpio pins
212  pin_name_t miso;
213  pin_name_t mosi;
214  pin_name_t sck;
215  pin_name_t cs;
217  // Additional gpio pins
218  pin_name_t wdi;
219  pin_name_t exi;
220  pin_name_t it2;
221  pin_name_t it1;
223  // static variable
224  uint32_t spi_speed;
225  spi_master_mode_t spi_mode;
226  spi_master_chip_select_polarity_t cs_polarity;
228 } rtc11_cfg_t;
229 
234 typedef struct
235 {
236  uint8_t hours;
237  uint8_t min;
238  uint8_t sec;
239 } rtc11_time_t;
240 
245 typedef struct
246 {
247  uint8_t year;
248  uint8_t month;
249  uint8_t day;
250  uint8_t day_of_week;
251 } rtc11_date_t;
252 
257 typedef enum
258 {
259  RTC11_OK = 0,
260  RTC11_ERROR = -1
261 
263 
280 
295 err_t rtc11_init ( rtc11_t *ctx, rtc11_cfg_t *cfg );
296 
308 void rtc11_generic_write ( rtc11_t *ctx, uint8_t reg, uint8_t *wr_data, uint16_t n_len );
309 
321 void rtc11_generic_read ( rtc11_t *ctx, uint8_t reg, uint8_t *rd_data, uint16_t n_len );
322 
331 uint8_t rtc11_check_irq_1 ( rtc11_t *ctx );
332 
341 uint8_t rtc11_check_irq_2 ( rtc11_t *ctx );
342 
352 void rtc11_wdi ( rtc11_t *ctx, uint8_t state );
353 
363 void rtc11_ext_int ( rtc11_t *ctx, uint8_t state );
364 
373 void rtc11_set_time_hundredths ( rtc11_t *ctx, uint8_t hundredths );
374 
383 void rtc11_set_time_seconds ( rtc11_t *ctx, uint8_t seconds );
384 
393 void rtc11_set_time_minutes ( rtc11_t *ctx, uint8_t minutes );
394 
403 void rtc11_set_time_hours ( rtc11_t *ctx, uint8_t hours );
404 
413 
422 
431 
439 uint8_t rtc11_get_time_hours ( rtc11_t *ctx );
440 
448 uint8_t rtc11_get_date_day ( rtc11_t *ctx );
449 
458 void rtc11_set_date_day ( rtc11_t *ctx, uint8_t date_day );
459 
467 uint8_t rtc11_get_date_month ( rtc11_t *ctx );
468 
477 void rtc11_set_date_month ( rtc11_t *ctx, uint8_t date_mth );
478 
486 uint8_t rtc11_get_date_year ( rtc11_t *ctx );
487 
496 void rtc11_set_date_year ( rtc11_t *ctx, uint16_t date_yrs );
497 
506 
515 
524 void rtc11_set_day_of_the_week ( rtc11_t *ctx, uint8_t w_day );
525 
534 void rtc11_set_ala_time_hundredths ( rtc11_t *ctx, uint8_t hundredths );
535 
544 void rtc11_set_ala_time_seconds ( rtc11_t *ctx, uint8_t seconds );
545 
554 void rtc11_set_ala_time_minutes ( rtc11_t *ctx, uint8_t minutes );
555 
564 void rtc11_set_ala_time_hours ( rtc11_t *ctx, uint8_t hours );
565 
574 
583 
592 
601 
610 
619 void rtc11_set_ala_date_day ( rtc11_t *ctx, uint8_t date_day );
620 
629 
638 void rtc11_set_ala_date_month ( rtc11_t *ctx, uint8_t date_mth );
639 
648 
657 void rtc11_set_ala_day_of_the_week ( rtc11_t *ctx, uint8_t w_day );
658 
666 void rtc11_soft_rst ( rtc11_t *ctx );
667 
680 err_t rtc11_set_time ( rtc11_t *ctx, rtc11_time_t rtc_time );
681 
691 void rtc11_get_time ( rtc11_t *ctx, rtc11_time_t *rtc_time );
692 
705 err_t rtc11_set_date ( rtc11_t *ctx, rtc11_date_t rtc_date );
706 
716 void rtc11_get_date ( rtc11_t *ctx, rtc11_date_t *rtc_date );
717 
726 void rtc11_stp_sys_slk ( rtc11_t *ctx, uint8_t state );
727 
736 void rtc11_auto_rst ( rtc11_t *ctx, uint8_t state );
737 
746 void rtc11_write_rtc ( rtc11_t *ctx, uint8_t state );
747 
757 void rtc11_cen_en ( rtc11_t *ctx, uint8_t state );
758 
768 void rtc11_bat_low_int_en ( rtc11_t *ctx, uint8_t state );
769 
779 void rtc11_timer_int_en ( rtc11_t *ctx, uint8_t state );
780 
790 void rtc11_alarm_int_en ( rtc11_t *ctx, uint8_t state );
791 
801 void rtc11_xt2_int_en ( rtc11_t *ctx, uint8_t state );
802 
812 void rtc11_xt1_int_en ( rtc11_t *ctx, uint8_t state );
813 
823 void rtc11_bat_mode_en ( rtc11_t *ctx, uint8_t state );
824 
825 #ifdef __cplusplus
826 }
827 #endif
828 #endif // RTC11_H
829  // rtc11
831 
832 // ------------------------------------------------------------------------ END
rtc11_xt1_int_en
void rtc11_xt1_int_en(rtc11_t *ctx, uint8_t state)
XT1 Interrupt Enable function.
rtc11_check_irq_1
uint8_t rtc11_check_irq_1(rtc11_t *ctx)
Check Interrupt 1 pin function.
rtc11_set_ala_time_seconds
void rtc11_set_ala_time_seconds(rtc11_t *ctx, uint8_t seconds)
Set alarm time seconds function.
rtc11_wdi
void rtc11_wdi(rtc11_t *ctx, uint8_t state)
Watchdog reset function.
rtc11_set_date_year
void rtc11_set_date_year(rtc11_t *ctx, uint16_t date_yrs)
Set year function.
rtc11_time_t::min
uint8_t min
Definition: rtc11.h:237
rtc11_bat_low_int_en
void rtc11_bat_low_int_en(rtc11_t *ctx, uint8_t state)
Battery Low Interrupt Enable function.
rtc11_bat_mode_en
void rtc11_bat_mode_en(rtc11_t *ctx, uint8_t state)
Batmode enable function.
rtc11_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: rtc11.h:226
rtc11_set_time_hundredths
void rtc11_set_time_hundredths(rtc11_t *ctx, uint8_t hundredths)
Set hundredths function.
rtc11_get_time
void rtc11_get_time(rtc11_t *ctx, rtc11_time_t *rtc_time)
Get time hours, minutes and seconds function.
rtc11_set_time
err_t rtc11_set_time(rtc11_t *ctx, rtc11_time_t rtc_time)
Set time hours, minutes and seconds function.
rtc11_get_date_month
uint8_t rtc11_get_date_month(rtc11_t *ctx)
Get month function.
rtc11_get_time_seconds
uint8_t rtc11_get_time_seconds(rtc11_t *ctx)
Get seconds function.
rtc11_cfg_t::cs
pin_name_t cs
Definition: rtc11.h:215
rtc11_get_time_hundredths
uint8_t rtc11_get_time_hundredths(rtc11_t *ctx)
Get hundredths function.
rtc11_time_t::hours
uint8_t hours
Definition: rtc11.h:236
rtc11_set_time_hours
void rtc11_set_time_hours(rtc11_t *ctx, uint8_t hours)
Set hours function.
rtc11_generic_read
void rtc11_generic_read(rtc11_t *ctx, uint8_t reg, uint8_t *rd_data, uint16_t n_len)
RTC 11 data reading function.
rtc11_cfg_t::exi
pin_name_t exi
Definition: rtc11.h:219
rtc11_set_ala_time_hours
void rtc11_set_ala_time_hours(rtc11_t *ctx, uint8_t hours)
Set alarm time hours function.
rtc11_t
RTC 11 Click context object.
Definition: rtc11.h:189
rtc11_t::chip_select
pin_name_t chip_select
Definition: rtc11.h:201
rtc11_get_ala_time_hours
uint8_t rtc11_get_ala_time_hours(rtc11_t *ctx)
Get alarm time hours function.
rtc11_alarm_int_en
void rtc11_alarm_int_en(rtc11_t *ctx, uint8_t state)
Alarm Interrupt Enable function.
rtc11_time_t::sec
uint8_t sec
Definition: rtc11.h:238
rtc11_get_ala_date_month
uint8_t rtc11_get_ala_date_month(rtc11_t *ctx)
Get alarm time month function.
rtc11_get_date_year
uint8_t rtc11_get_date_year(rtc11_t *ctx)
Get year function.
rtc11_get_time_minutes
uint8_t rtc11_get_time_minutes(rtc11_t *ctx)
Get minutes function.
rtc11_t::wdi
digital_out_t wdi
Definition: rtc11.h:191
rtc11_get_ala_date_day
uint8_t rtc11_get_ala_date_day(rtc11_t *ctx)
Get alarm time days function.
rtc11_date_t::day_of_week
uint8_t day_of_week
Definition: rtc11.h:250
rtc11_set_time_minutes
void rtc11_set_time_minutes(rtc11_t *ctx, uint8_t minutes)
Set minutes function.
rtc11_get_date_day
uint8_t rtc11_get_date_day(rtc11_t *ctx)
Get day function.
rtc11_get_time_hours
uint8_t rtc11_get_time_hours(rtc11_t *ctx)
Get hours function.
rtc11_set_ala_date_day
void rtc11_set_ala_date_day(rtc11_t *ctx, uint8_t date_day)
Set alarm time day function.
rtc11_get_ala_time_minutes
uint8_t rtc11_get_ala_time_minutes(rtc11_t *ctx)
Get alarm time minutes function.
rtc11_get_day_of_the_week
uint8_t rtc11_get_day_of_the_week(rtc11_t *ctx)
Get day of the week function.
rtc11_set_day_of_the_week
void rtc11_set_day_of_the_week(rtc11_t *ctx, uint8_t w_day)
Set day of the week function.
rtc11_cfg_t::miso
pin_name_t miso
Definition: rtc11.h:212
rtc11_set_date
err_t rtc11_set_date(rtc11_t *ctx, rtc11_date_t rtc_date)
Set date day of the week, day, month and year function.
rtc11_t::it2
digital_in_t it2
Definition: rtc11.h:195
rtc11_return_value_t
rtc11_return_value_t
RTC 11 Click return value data.
Definition: rtc11.h:258
rtc11_t::spi
spi_master_t spi
Definition: rtc11.h:199
rtc11_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: rtc11.h:225
rtc11_time_t
RTC 11 Click time object.
Definition: rtc11.h:235
rtc11_cfg_t
RTC 11 Click configuration object.
Definition: rtc11.h:210
rtc11_check_irq_2
uint8_t rtc11_check_irq_2(rtc11_t *ctx)
Check Interrupt 2 pin function.
rtc11_get_ala_day_of_the_week
uint8_t rtc11_get_ala_day_of_the_week(rtc11_t *ctx)
Get alarm time day of the week function.
rtc11_timer_int_en
void rtc11_timer_int_en(rtc11_t *ctx, uint8_t state)
Timer Interrupt Enable function.
rtc11_auto_rst
void rtc11_auto_rst(rtc11_t *ctx, uint8_t state)
Auto reset enable function.
rtc11_cen_en
void rtc11_cen_en(rtc11_t *ctx, uint8_t state)
Century Enable function.
rtc11_t::it1
digital_in_t it1
Definition: rtc11.h:196
rtc11_init
err_t rtc11_init(rtc11_t *ctx, rtc11_cfg_t *cfg)
RTC 11 initialization function.
rtc11_date_t
RTC 11 Click date object.
Definition: rtc11.h:246
rtc11_t::exi
digital_out_t exi
Definition: rtc11.h:192
rtc11_soft_rst
void rtc11_soft_rst(rtc11_t *ctx)
Software Reset function.
rtc11_cfg_t::mosi
pin_name_t mosi
Definition: rtc11.h:213
rtc11_date_t::month
uint8_t month
Definition: rtc11.h:248
rtc11_get_date
void rtc11_get_date(rtc11_t *ctx, rtc11_date_t *rtc_date)
Get date day of the week, day, month and year function.
rtc11_generic_write
void rtc11_generic_write(rtc11_t *ctx, uint8_t reg, uint8_t *wr_data, uint16_t n_len)
RTC 11 data writing function.
rtc11_cfg_t::it2
pin_name_t it2
Definition: rtc11.h:220
rtc11_cfg_setup
void rtc11_cfg_setup(rtc11_cfg_t *cfg)
RTC 11 configuration object setup function.
rtc11_get_ala_time_hundredths
uint8_t rtc11_get_ala_time_hundredths(rtc11_t *ctx)
Get alarm time hundredths function.
rtc11_xt2_int_en
void rtc11_xt2_int_en(rtc11_t *ctx, uint8_t state)
XT2 Interrupt Enable function.
rtc11_set_ala_time_hundredths
void rtc11_set_ala_time_hundredths(rtc11_t *ctx, uint8_t hundredths)
Set alarm time hundredths function.
RTC11_ERROR
@ RTC11_ERROR
Definition: rtc11.h:260
rtc11_set_time_seconds
void rtc11_set_time_seconds(rtc11_t *ctx, uint8_t seconds)
Set seconds function.
rtc11_stp_sys_slk
void rtc11_stp_sys_slk(rtc11_t *ctx, uint8_t state)
Stop the clocking system function.
rtc11_cfg_t::wdi
pin_name_t wdi
Definition: rtc11.h:218
RTC11_OK
@ RTC11_OK
Definition: rtc11.h:259
rtc11_get_century_flag
uint8_t rtc11_get_century_flag(rtc11_t *ctx)
Get century flag function.
rtc11_date_t::year
uint8_t year
Definition: rtc11.h:247
rtc11_cfg_t::sck
pin_name_t sck
Definition: rtc11.h:214
rtc11_get_ala_time_seconds
uint8_t rtc11_get_ala_time_seconds(rtc11_t *ctx)
Get alarm time seconds function.
rtc11_set_ala_time_minutes
void rtc11_set_ala_time_minutes(rtc11_t *ctx, uint8_t minutes)
Set alarm time minutes function.
rtc11_write_rtc
void rtc11_write_rtc(rtc11_t *ctx, uint8_t state)
Write RTC enable function.
rtc11_set_ala_day_of_the_week
void rtc11_set_ala_day_of_the_week(rtc11_t *ctx, uint8_t w_day)
Set alarm time day of the week function.
rtc11_cfg_t::it1
pin_name_t it1
Definition: rtc11.h:221
rtc11_set_date_month
void rtc11_set_date_month(rtc11_t *ctx, uint8_t date_mth)
Set month function.
rtc11_date_t::day
uint8_t day
Definition: rtc11.h:249
rtc11_ext_int
void rtc11_ext_int(rtc11_t *ctx, uint8_t state)
External interrupt function.
rtc11_set_ala_date_month
void rtc11_set_ala_date_month(rtc11_t *ctx, uint8_t date_mth)
Set alarm time month function.
rtc11_cfg_t::spi_speed
uint32_t spi_speed
Definition: rtc11.h:224
rtc11_set_date_day
void rtc11_set_date_day(rtc11_t *ctx, uint8_t date_day)
Set day function.