Trident IoT SDK
Loading...
Searching...
No Matches
T32CZ20_rtc.h
Go to the documentation of this file.
1
43
44
45#ifndef T32CZ20_RTC_H_
46#define T32CZ20_RTC_H_
47
48#include "tr_hal_platform.h"
49
50
56
57
61#define TR_HAL_RTC_YEAR_MINIMUM 2000
62#define TR_HAL_RTC_YEAR_MAXIMUM 2099
63
64#define TR_HAL_RTC_MONTH_MINIMUM 1
65#define TR_HAL_RTC_MONTH_MAXIMUM 12
66
67#define TR_HAL_RTC_DAY_MINIMUM 1
68#define TR_HAL_RTC_DAY_MAXIMUM 31
69
70#define TR_HAL_RTC_SHORT_MONTH_DAY_MAXIMUM 30
71#define TR_HAL_RTC_FEB_DAY_MAXIMUM 28
72#define TR_HAL_RTC_FEB_LEAP_YEAR_DAY_MAXIMUM 29
73
74#define TR_HAL_RTC_HOUR_MINIMUM 0
75#define TR_HAL_RTC_HOUR_MAXIMUM 23
76
77#define TR_HAL_RTC_MINUTE_MINIMUM 0
78#define TR_HAL_RTC_MINUTE_MAXIMUM 59
79
80#define TR_HAL_RTC_SECOND_MINIMUM 0
81#define TR_HAL_RTC_SECOND_MAXIMUM 59
82
83#define TR_HAL_RTC_MILLISECOND_MINIMUM 0
84#define TR_HAL_RTC_MILLISECOND_MAXIMUM 999
85
86
90#define TR_HAL_MONTH_JANUARY 1
91#define TR_HAL_MONTH_FEBRUARY 2
92#define TR_HAL_MONTH_MARCH 3
93#define TR_HAL_MONTH_APRIL 4
94#define TR_HAL_MONTH_MAY 5
95#define TR_HAL_MONTH_JUNE 6
96#define TR_HAL_MONTH_JULY 7
97#define TR_HAL_MONTH_AUGUST 8
98#define TR_HAL_MONTH_SEPTEMBER 9
99#define TR_HAL_MONTH_OCTOBER 10
100#define TR_HAL_MONTH_NOVEMBER 11
101#define TR_HAL_MONTH_DECEMBER 12
102
103
107
108// date
109typedef struct
110{
111 // 4 digit year and must be >= 2000
112 uint16_t years;
113
114 // 1-12
115 uint8_t months;
116
117 // 1-31, depends on month
118 uint8_t days;
119
121
122// time
123typedef struct
124{
125 // range 0-23
126 uint8_t hours;
127
128 // range 0-59
129 uint8_t minutes;
130
131 // range 0-59
132 uint8_t seconds;
133
134 // range 0-999
135 uint16_t milliseconds;
136
138
139// date and time
140typedef struct
141{
142 tr_hal_rtc_date date;
143 tr_hal_rtc_time time;
144
146
147
154#define TR_HAL_INVALID_DATE_TIME_VALUE 255
155
156
173
174
190
191
201#ifdef RTC_SECURE_EN
202 #define CHIP_MEMORY_MAP_RTC_BASE (0x50004000UL)
203 #define CHIP_MEMORY_MAP_RCO32K_BASE (0x5001C000UL)
204#else
205 #define CHIP_MEMORY_MAP_RTC_BASE (0x40004000UL)
206 #define CHIP_MEMORY_MAP_RCO32K_BASE (0x4001C000UL)
207#endif // RTC_SECURE_EN
208
209
210typedef struct rco32k_result0_
211{
212 uint32_t EST_32K_RESULT : 20;
213 uint32_t RESERVED1 : 4;
215 uint32_t RESERVED2 : 3;
216 uint32_t CAL32K_BUSY : 1;
217 uint32_t CAL32K_LOCK : 1;
218 uint32_t CAL32K_TIMEOUT : 1;
219 uint32_t RESERVED3 : 1;
221
222typedef struct rco32k_result1_
223{
224 uint32_t TUNE_FINE_CAL32K : 8;
225 uint32_t RESERVED1 : 8;
226 uint32_t TUNE_COARSE_CAL32K : 2;
227 uint32_t RESERVED2 : 14;
229
230
235typedef struct
236{
237 __IO uint32_t CAL32K_CFG0; /*offset:0x00*/
238 __IO uint32_t CAL32K_CFG1; /*offset:0x04*/
242
243
247typedef struct
248{
249 // register values for seconds, minutes, hours, days, months, years
250 // note that these must be written and read in BCD
251 __IO uint32_t seconds_value; // 0x00
252 __IO uint32_t minutes_value; // 0x04
253 __IO uint32_t hours_value; // 0x08
254 __IO uint32_t days_value; // 0x0C
255 __IO uint32_t months_value; // 0x10
256 __IO uint32_t years_value; // 0x14
257
258 // used for testing (can speed up rate) and to clear counters and values
259 __IO uint32_t control; // 0x18
260
261 // Clock Divisor for generating a 1Hz enable pulse to the seconds counter
262 __IO uint32_t clock_divisor; // 0x1C
263
264 // what trigger to use for each time unit: off, on_change, on_value, combo
265 // these registers also hold the trigger value if in on_value mode
266 __IO uint32_t seconds_event_trigger; // 0x20
267 __IO uint32_t minutes_event_trigger; // 0x24
268 __IO uint32_t hours_event_trigger; // 0x28
269 __IO uint32_t days_event_trigger; // 0x2C
270 __IO uint32_t months_event_trigger; // 0x30
271 __IO uint32_t years_event_trigger; // 0x34
272
273 // interrupts
274 __IO uint32_t interrupt_enable; // 0x38
275 __IO uint32_t interrupt_status; // 0x3C
276 __IO uint32_t interrupt_clear; // 0x40
277
278 // once clock divisior, event trigger values, or time values have been updated,
279 // this register allows them to be "loaded" == become active
280 __IO uint32_t load; // 0x44
281
282 // NEW in CZ20
283 __IO uint32_t milliseconds_value; // 0x48
284 __IO uint32_t milliseconds_event_trigger; // 0x4C
285
286
288
289
290// *****************************************************************
291// this enum helps when dealing with the CONTROL REGISTER (0x18)
292#define TR_HAL_RTC_CONTROL_REG_ENABLE_BIT 0x100
293
304
305
306// *****************************************************************
307// these defines help when dealing with the CLOCK DIVISIOR REGISTER (0x1C)
308// 32.768 KHz = 20.C49C = 0x20C49C = 2147484
309//#define TR_HAL_DEFAULT_CLOCK_DIVISOR 0x20C49C
310// tuned for my board
311#define TR_HAL_DEFAULT_CLOCK_DIVISOR 2110000
312
313
314// *****************************************************************
315// these defines help when dealing with the EVENT TRIGGER REGISTERs (0x20 - 0x34)
316#define TR_HAL_REG_SETTING_EVENT_OFF 0x0000
317#define TR_HAL_REG_SETTING_EVENT_ON_CHANGE 0x0100
318#define TR_HAL_REG_SETTING_EVENT_ON_VALUE 0x0000
319#define TR_HAL_REG_SETTING_COMBO_EVENT 0x0200
320
321
322// *****************************************************************
323// these defines help when dealing with the INTERRUPT ENABLE REGISTER (0x38),
324// the INTERRUPT STATUS REGISTER (0x3C) and the INTERRUPT CLEAR REGISTER (0x40)
325#define TR_HAL_RTC_INTERRUPT_NONE 0x00
326#define TR_HAL_RTC_INTERRUPT_SECONDS 0x01
327#define TR_HAL_RTC_INTERRUPT_MINUTES 0x02
328#define TR_HAL_RTC_INTERRUPT_HOURS 0x04
329#define TR_HAL_RTC_INTERRUPT_DAYS 0x08
330#define TR_HAL_RTC_INTERRUPT_MONTHS 0x10
331#define TR_HAL_RTC_INTERRUPT_YEARS 0x20
332#define TR_HAL_RTC_INTERRUPT_COMBINED_EVENT 0x40
333#define TR_HAL_RTC_INTERRUPT_MILLISECONDS 0x80
334#define TR_HAL_RTC_INTERRUPT_ALL 0xFF
335
336
337// *****************************************************************
338// these defines help when dealing with the LOAD REGISTER (0x44)
339#define TR_HAL_RTC_UPDATE_TIME_VALUES 0x01
340#define TR_HAL_RTC_UPDATE_EVENT_TRIGGER 0x02
341#define TR_HAL_RTC_UPDATE_CLOCK_DIVISOR 0x04
342
343
344// *****************************************************************
345// this orients the RTC_REGISTERS struct with the correct address
346// so referencing a field will now read/write the correct RTC
347// register chip address
348#define RTC_REGISTERS ((RTC_REGISTERS_T *) CHIP_MEMORY_MAP_RTC_BASE)
349
350
351// *****************************************************************
352// this orients the RC032K_REGISTERS struct with the correct address
353// so referencing a field will now read/write the correct RCo21K
354// register chip address
355#define RCO32K_REGISTERS ((RCO32K_REGISTERS_T *) CHIP_MEMORY_MAP_RCO32K_BASE)
356
362
363
369
373typedef void (*tr_hal_rtc_event_callback_t) (uint32_t event_bitmask,
374 tr_hal_rtc_date_time current_date_time);
375
376
382#define TR_HAL_RTC_EVENT_TRIGGERED_SECONDS 0x00000001
383#define TR_HAL_RTC_EVENT_TRIGGERED_MINUTES 0x00000002
384#define TR_HAL_RTC_EVENT_TRIGGERED_HOURS 0x00000004
385#define TR_HAL_RTC_EVENT_TRIGGERED_DAYS 0x00000008
386#define TR_HAL_RTC_EVENT_TRIGGERED_MONTHS 0x00000010
387#define TR_HAL_RTC_EVENT_TRIGGERED_YEARS 0x00000020
388#define TR_HAL_RTC_EVENT_TRIGGERED_COMBINED_EVENT 0x00000040
389#define TR_HAL_RTC_EVENT_TRIGGERED_MILLISECONDS 0x00000080
390
391
397#define TR_HAL_RTC_MILLISECOND_TRIGGER_OFF_VALUE 1001
398#define TR_HAL_RTC_SECOND_TRIGGER_OFF_VALUE 62
399#define TR_HAL_RTC_MINUTE_TRIGGER_OFF_VALUE 62
400#define TR_HAL_RTC_HOUR_TRIGGER_OFF_VALUE 25
401#define TR_HAL_RTC_DAY_TRIGGER_OFF_VALUE 32
402#define TR_HAL_RTC_MONTH_TRIGGER_OFF_VALUE 0
403#define TR_HAL_RTC_YEAR_TRIGGER_OFF_VALUE 0
404
405
410typedef struct
411{
412 // **** date, time, and clock divisor ****
413
414 tr_hal_rtc_date_time rtc_date_time;
415
416 uint32_t clock_divisor;
417
418
419 // **** event callback from HAL to App when an event happens ****
420 // if the app doesn't want this, then set it to NULL
421 tr_hal_rtc_event_callback_t event_handler_fx;
422
423
424 // **** chip behavior settings ****
425
426 // are the chip interrupts enabled?
427 bool enable_chip_interrupts;
428
429 // set the INT priority
430 tr_hal_int_pri_t interrupt_priority;
431
432 // when the device is sleeping, we can choose to DISABLE interrupts,
433 // or leave them enabled which would allow the device to wake on
434 // an interrupt from this peripheral
435 bool wake_on_interrupt;
436
437
438 // **** time unit events ****
439
440 tr_hal_rtc_event_trigger_t seconds_event_trigger;
441 uint8_t seconds_trigger_value;
442 tr_hal_rtc_event_trigger_t minutes_event_trigger;
443 uint8_t minutes_trigger_value;
444 tr_hal_rtc_event_trigger_t hours_event_trigger;
445 uint8_t hours_trigger_value;
446 tr_hal_rtc_event_trigger_t days_event_trigger;
447 uint8_t days_trigger_value;
448 tr_hal_rtc_event_trigger_t months_event_trigger;
449 uint8_t months_trigger_value;
450 tr_hal_rtc_event_trigger_t years_event_trigger;
451 uint16_t years_trigger_value;
454
455 // **** combo event ****
456
459
461
462
471#define DEFAULT_RTC_CONFIG \
472 { \
473 .rtc_date_time.time.milliseconds = 0, \
474 .rtc_date_time.time.seconds = 0, \
475 .rtc_date_time.time.minutes = 0, \
476 .rtc_date_time.time.hours = 0, \
477 .rtc_date_time.date.days = 1, \
478 .rtc_date_time.date.months = 1, \
479 .rtc_date_time.date.years = 2025, \
480 .clock_divisor = TR_HAL_DEFAULT_CLOCK_DIVISOR, \
481 .event_handler_fx = NULL, \
482 .enable_chip_interrupts = true, \
483 .interrupt_priority = TR_HAL_INTERRUPT_PRIORITY_5, \
484 .wake_on_interrupt = false, \
485 .seconds_event_trigger = TR_HAL_EVENT_TRIGGER_OFF, \
486 .minutes_event_trigger = TR_HAL_EVENT_TRIGGER_OFF, \
487 .hours_event_trigger = TR_HAL_EVENT_TRIGGER_OFF, \
488 .days_event_trigger = TR_HAL_EVENT_TRIGGER_OFF, \
489 .months_event_trigger = TR_HAL_EVENT_TRIGGER_OFF, \
490 .years_event_trigger = TR_HAL_EVENT_TRIGGER_OFF, \
491 .milliseconds_event_trigger = TR_HAL_EVENT_TRIGGER_OFF, \
492 .combo_event_enabled = false, \
493 }
494
495
496// this API causes the time unit specified to speed up to change once per second
497// this is useful for testing
499
500// expose these so they can be fully tested
501uint32_t convert_bcd_to_int(uint32_t register_value);
502uint32_t convert_int_to_bcd(uint32_t int_value);
503
504// Disable and clear all RTC interrupts
506
507// Read the rtc interrupt status register
509
510//Enable/Disable the RTC timer
511void tr_hal_rtc_enable(bool enable);
512
516
517
518#endif // T32CZ20_RTC_H_
tr_hal_int_pri_t
values and a range checking function for setting the interrupt priority in the Trident HAL APIs
Definition tr_hal_platform.h:34
This file contains the CHIP SPECIFIC types and defines for the T32CZ20.
tr_hal_status_t
Definition tr_hal_common.h:25
void(* tr_hal_rtc_event_callback_t)(uint32_t event_bitmask, tr_hal_rtc_date_time current_date_time)
Definition T32CM11_rtc.h:304
tr_hal_rtc_speedup_unit_t
Definition T32CM11_rtc.h:241
tr_hal_rtc_event_trigger_t
this enum is the trigger setting for time unit events OFF = not enabled ON_CHANGE = whenever the time...
Definition T32CM11_rtc.h:176
tr_hal_rtc_time_unit_t
this enum is used when we set up a time unit event, to tell which units we are using
Definition T32CM11_rtc.h:156
@ TR_HAL_RTC_SPEEDUP_YEARS
Definition T32CM11_rtc.h:247
@ TR_HAL_RTC_SPEEDUP_MINUTES
Definition T32CM11_rtc.h:243
@ TR_HAL_RTC_SPEEDUP_NONE
Definition T32CM11_rtc.h:242
@ TR_HAL_RTC_SPEEDUP_HOURS
Definition T32CM11_rtc.h:244
@ TR_HAL_RTC_SPEEDUP_DAYS
Definition T32CM11_rtc.h:245
@ TR_HAL_RTC_SPEEDUP_MONTHS
Definition T32CM11_rtc.h:246
@ TR_HAL_EVENT_TRIGGER_OFF
Definition T32CM11_rtc.h:177
@ TR_HAL_EVENT_TRIGGER_INVALID
Definition T32CM11_rtc.h:180
@ TR_HAL_EVENT_TRIGGER_ON_SPECIFIC_VALUE
Definition T32CM11_rtc.h:179
@ TR_HAL_EVENT_TRIGGER_ON_UNIT_CHANGE
Definition T32CM11_rtc.h:178
@ TR_HAL_RTC_TIME_UNIT_MONTHS
Definition T32CM11_rtc.h:161
@ TR_HAL_RTC_TIME_UNIT_MINUTES
Definition T32CM11_rtc.h:158
@ TR_HAL_RTC_TIME_UNIT_INVALID
Definition T32CM11_rtc.h:163
@ TR_HAL_RTC_TIME_UNIT_YEARS
Definition T32CM11_rtc.h:162
@ TR_HAL_RTC_TIME_UNIT_DAYS
Definition T32CM11_rtc.h:160
@ TR_HAL_RTC_TIME_UNIT_SECONDS
Definition T32CM11_rtc.h:157
@ TR_HAL_RTC_TIME_UNIT_HOURS
Definition T32CM11_rtc.h:159
uint32_t convert_int_to_bcd(uint32_t int_value)
struct rco32k_result0_ rco32k_result_0_t
tr_hal_rtc_event_trigger_t
this enum is the trigger setting for time unit events OFF = not enabled ON_CHANGE = whenever the time...
Definition T32CZ20_rtc.h:183
RCO32K_REGISTERS_T * tr_hal_rco32k_get_register_address(void)
uint32_t tr_hal_rtc_get_interrupt_status(void)
uint32_t convert_bcd_to_int(uint32_t register_value)
RTC_REGISTERS_T * tr_hal_rtc_get_register_address(void)
void tr_hal_rtc_disable_interrupts(void)
tr_hal_status_t tr_hal_rtc_speedup_for_testing(tr_hal_rtc_speedup_unit_t speedup_unit)
struct rco32k_result1_ rco32k_result_1_t
void tr_hal_rtc_enable(bool enable)
@ TR_HAL_RTC_TIME_UNIT_MILLISECONDS
Definition T32CZ20_rtc.h:163
Definition T32CZ20_rtc.h:236
__IO uint32_t CAL32K_CFG0
Definition T32CZ20_rtc.h:237
__I rco32k_result_1_t CAL32K_RESULT1
Definition T32CZ20_rtc.h:240
__I rco32k_result_0_t CAL32K_RESULT0
Definition T32CZ20_rtc.h:239
__IO uint32_t CAL32K_CFG1
Definition T32CZ20_rtc.h:238
the struct we use so we can address registers using field names
Definition T32CM11_rtc.h:201
__IO uint32_t milliseconds_value
Definition T32CZ20_rtc.h:283
__IO uint32_t milliseconds_event_trigger
Definition T32CZ20_rtc.h:284
Definition T32CZ20_rtc.h:211
uint32_t CAL32K_LOCK
Definition T32CZ20_rtc.h:217
uint32_t CAL32K_BUSY
Definition T32CZ20_rtc.h:216
uint32_t EST_32K_RESULT_VALID
Definition T32CZ20_rtc.h:214
uint32_t EST_32K_RESULT
Definition T32CZ20_rtc.h:212
uint32_t RESERVED2
Definition T32CZ20_rtc.h:215
uint32_t RESERVED3
Definition T32CZ20_rtc.h:219
uint32_t CAL32K_TIMEOUT
Definition T32CZ20_rtc.h:218
uint32_t RESERVED1
Definition T32CZ20_rtc.h:213
Definition T32CZ20_rtc.h:223
uint32_t RESERVED1
Definition T32CZ20_rtc.h:225
uint32_t TUNE_FINE_CAL32K
Definition T32CZ20_rtc.h:224
uint32_t TUNE_COARSE_CAL32K
Definition T32CZ20_rtc.h:226
uint32_t RESERVED2
Definition T32CZ20_rtc.h:227
Definition T32CM11_rtc.h:135
convenience structs for use when passing around dates, times, or both
Definition T32CM11_rtc.h:107
Definition T32CM11_rtc.h:327
bool combo_event_enabled
Definition T32CM11_rtc.h:372
tr_hal_rtc_date_time combo_event_trigger_date_time
Definition T32CM11_rtc.h:373
uint16_t milliseconds_trigger_value
Definition T32CZ20_rtc.h:453
tr_hal_rtc_event_trigger_t milliseconds_event_trigger
Definition T32CZ20_rtc.h:452
Definition T32CM11_rtc.h:121
uint16_t milliseconds
Definition T32CZ20_rtc.h:135