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#else
204 #define CHIP_MEMORY_MAP_RTC_BASE (0x40004000UL)
205#endif // RTC_SECURE_EN
206
207
211typedef struct
212{
213 // register values for seconds, minutes, hours, days, months, years
214 // note that these must be written and read in BCD
215 __IO uint32_t seconds_value; // 0x00
216 __IO uint32_t minutes_value; // 0x04
217 __IO uint32_t hours_value; // 0x08
218 __IO uint32_t days_value; // 0x0C
219 __IO uint32_t months_value; // 0x10
220 __IO uint32_t years_value; // 0x14
221
222 // used for testing (can speed up rate) and to clear counters and values
223 __IO uint32_t control; // 0x18
224
225 // Clock Divisor for generating a 1Hz enable pulse to the seconds counter
226 __IO uint32_t clock_divisor; // 0x1C
227
228 // what trigger to use for each time unit: off, on_change, on_value, combo
229 // these registers also hold the trigger value if in on_value mode
230 __IO uint32_t seconds_event_trigger; // 0x20
231 __IO uint32_t minutes_event_trigger; // 0x24
232 __IO uint32_t hours_event_trigger; // 0x28
233 __IO uint32_t days_event_trigger; // 0x2C
234 __IO uint32_t months_event_trigger; // 0x30
235 __IO uint32_t years_event_trigger; // 0x34
236
237 // interrupts
238 __IO uint32_t interrupt_enable; // 0x38
239 __IO uint32_t interrupt_status; // 0x3C
240 __IO uint32_t interrupt_clear; // 0x40
241
242 // once clock divisior, event trigger values, or time values have been updated,
243 // this register allows them to be "loaded" == become active
244 __IO uint32_t load; // 0x44
245
246 // NEW in CZ20
247 __IO uint32_t milliseconds_value; // 0x48
248 __IO uint32_t milliseconds_event_trigger; // 0x4C
249
250
252
253
254// *****************************************************************
255// this enum helps when dealing with the CONTROL REGISTER (0x18)
256#define TR_HAL_RTC_CONTROL_REG_ENABLE_BIT 0x100
257
268
269
270// *****************************************************************
271// these defines help when dealing with the CLOCK DIVISIOR REGISTER (0x1C)
272// 32.768 KHz = 20.C49C = 0x20C49C = 2147484
273//#define TR_HAL_DEFAULT_CLOCK_DIVISOR 0x20C49C
274// tuned for my board
275#define TR_HAL_DEFAULT_CLOCK_DIVISOR 2110000
276
277
278// *****************************************************************
279// these defines help when dealing with the EVENT TRIGGER REGISTERs (0x20 - 0x34)
280#define TR_HAL_REG_SETTING_EVENT_OFF 0x0000
281#define TR_HAL_REG_SETTING_EVENT_ON_CHANGE 0x0100
282#define TR_HAL_REG_SETTING_EVENT_ON_VALUE 0x0000
283#define TR_HAL_REG_SETTING_COMBO_EVENT 0x0200
284
285
286// *****************************************************************
287// these defines help when dealing with the INTERRUPT ENABLE REGISTER (0x38),
288// the INTERRUPT STATUS REGISTER (0x3C) and the INTERRUPT CLEAR REGISTER (0x40)
289#define TR_HAL_RTC_INTERRUPT_NONE 0x00
290#define TR_HAL_RTC_INTERRUPT_SECONDS 0x01
291#define TR_HAL_RTC_INTERRUPT_MINUTES 0x02
292#define TR_HAL_RTC_INTERRUPT_HOURS 0x04
293#define TR_HAL_RTC_INTERRUPT_DAYS 0x08
294#define TR_HAL_RTC_INTERRUPT_MONTHS 0x10
295#define TR_HAL_RTC_INTERRUPT_YEARS 0x20
296#define TR_HAL_RTC_INTERRUPT_COMBINED_EVENT 0x40
297#define TR_HAL_RTC_INTERRUPT_MILLISECONDS 0x80
298#define TR_HAL_RTC_INTERRUPT_ALL 0xFF
299
300
301// *****************************************************************
302// these defines help when dealing with the LOAD REGISTER (0x44)
303#define TR_HAL_RTC_UPDATE_TIME_VALUES 0x01
304#define TR_HAL_RTC_UPDATE_EVENT_TRIGGER 0x02
305#define TR_HAL_RTC_UPDATE_CLOCK_DIVISOR 0x04
306
307
308// *****************************************************************
309// this orients the RTC_REGISTERS struct with the correct address
310// so referencing a field will now read/write the correct RTC
311// register chip address
312#define RTC_REGISTERS ((RTC_REGISTERS_T *) CHIP_MEMORY_MAP_RTC_BASE)
313
314
320
321
325typedef void (*tr_hal_rtc_event_callback_t) (uint32_t event_bitmask,
326 tr_hal_rtc_date_time current_date_time);
327
328
334#define TR_HAL_RTC_EVENT_TRIGGERED_SECONDS 0x00000001
335#define TR_HAL_RTC_EVENT_TRIGGERED_MINUTES 0x00000002
336#define TR_HAL_RTC_EVENT_TRIGGERED_HOURS 0x00000004
337#define TR_HAL_RTC_EVENT_TRIGGERED_DAYS 0x00000008
338#define TR_HAL_RTC_EVENT_TRIGGERED_MONTHS 0x00000010
339#define TR_HAL_RTC_EVENT_TRIGGERED_YEARS 0x00000020
340#define TR_HAL_RTC_EVENT_TRIGGERED_COMBINED_EVENT 0x00000040
341#define TR_HAL_RTC_EVENT_TRIGGERED_MILLISECONDS 0x00000080
342
343
349#define TR_HAL_RTC_MILLISECOND_TRIGGER_OFF_VALUE 1001
350#define TR_HAL_RTC_SECOND_TRIGGER_OFF_VALUE 62
351#define TR_HAL_RTC_MINUTE_TRIGGER_OFF_VALUE 62
352#define TR_HAL_RTC_HOUR_TRIGGER_OFF_VALUE 25
353#define TR_HAL_RTC_DAY_TRIGGER_OFF_VALUE 32
354#define TR_HAL_RTC_MONTH_TRIGGER_OFF_VALUE 0
355#define TR_HAL_RTC_YEAR_TRIGGER_OFF_VALUE 0
356
357
362typedef struct
363{
364 // **** date, time, and clock divisor ****
365
366 tr_hal_rtc_date_time rtc_date_time;
367
368 uint32_t clock_divisor;
369
370
371 // **** event callback from HAL to App when an event happens ****
372 // if the app doesn't want this, then set it to NULL
373 tr_hal_rtc_event_callback_t event_handler_fx;
374
375
376 // **** chip behavior settings ****
377
378 // are the chip interrupts enabled?
379 bool enable_chip_interrupts;
380
381 // set the INT priority
382 tr_hal_int_pri_t interrupt_priority;
383
384 // when the device is sleeping, we can choose to DISABLE interrupts,
385 // or leave them enabled which would allow the device to wake on
386 // an interrupt from this peripheral
387 bool wake_on_interrupt;
388
389
390 // **** time unit events ****
391
392 tr_hal_rtc_event_trigger_t seconds_event_trigger;
393 uint8_t seconds_trigger_value;
394 tr_hal_rtc_event_trigger_t minutes_event_trigger;
395 uint8_t minutes_trigger_value;
396 tr_hal_rtc_event_trigger_t hours_event_trigger;
397 uint8_t hours_trigger_value;
398 tr_hal_rtc_event_trigger_t days_event_trigger;
399 uint8_t days_trigger_value;
400 tr_hal_rtc_event_trigger_t months_event_trigger;
401 uint8_t months_trigger_value;
402 tr_hal_rtc_event_trigger_t years_event_trigger;
403 uint16_t years_trigger_value;
406
407 // **** combo event ****
408
409 bool combo_event_enabled;
410 tr_hal_rtc_date_time combo_event_trigger_date_time;
411
413
414
423#define DEFAULT_RTC_CONFIG \
424 { \
425 .rtc_date_time.time.milliseconds = 0, \
426 .rtc_date_time.time.seconds = 0, \
427 .rtc_date_time.time.minutes = 0, \
428 .rtc_date_time.time.hours = 0, \
429 .rtc_date_time.date.days = 1, \
430 .rtc_date_time.date.months = 1, \
431 .rtc_date_time.date.years = 2025, \
432 .clock_divisor = TR_HAL_DEFAULT_CLOCK_DIVISOR, \
433 .event_handler_fx = NULL, \
434 .enable_chip_interrupts = true, \
435 .interrupt_priority = TR_HAL_INTERRUPT_PRIORITY_5, \
436 .wake_on_interrupt = false, \
437 .seconds_event_trigger = TR_HAL_EVENT_TRIGGER_OFF, \
438 .minutes_event_trigger = TR_HAL_EVENT_TRIGGER_OFF, \
439 .hours_event_trigger = TR_HAL_EVENT_TRIGGER_OFF, \
440 .days_event_trigger = TR_HAL_EVENT_TRIGGER_OFF, \
441 .months_event_trigger = TR_HAL_EVENT_TRIGGER_OFF, \
442 .years_event_trigger = TR_HAL_EVENT_TRIGGER_OFF, \
443 .milliseconds_event_trigger = TR_HAL_EVENT_TRIGGER_OFF, \
444 .combo_event_enabled = false, \
445 }
446
447
448// this API causes the time unit specified to speed up to change once per second
449// this is useful for testing
451
452// expose these so they can be fully tested
453uint32_t convert_bcd_to_int(uint32_t register_value);
454uint32_t convert_int_to_bcd(uint32_t int_value);
455
456
460
461
462#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
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
uint32_t convert_int_to_bcd(uint32_t int_value)
void(* tr_hal_rtc_event_callback_t)(uint32_t event_bitmask, tr_hal_rtc_date_time current_date_time)
Definition T32CZ20_rtc.h:325
tr_hal_rtc_speedup_unit_t
Definition T32CZ20_rtc.h:259
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
uint32_t convert_bcd_to_int(uint32_t register_value)
RTC_REGISTERS_T * tr_hal_rtc_get_register_address(void)
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 T32CZ20_rtc.h:162
tr_hal_status_t tr_hal_rtc_speedup_for_testing(tr_hal_rtc_speedup_unit_t speedup_unit)
@ TR_HAL_RTC_SPEEDUP_YEARS
Definition T32CZ20_rtc.h:265
@ TR_HAL_RTC_SPEEDUP_MINUTES
Definition T32CZ20_rtc.h:261
@ TR_HAL_RTC_SPEEDUP_NONE
Definition T32CZ20_rtc.h:260
@ TR_HAL_RTC_SPEEDUP_HOURS
Definition T32CZ20_rtc.h:262
@ TR_HAL_RTC_SPEEDUP_DAYS
Definition T32CZ20_rtc.h:263
@ TR_HAL_RTC_SPEEDUP_MONTHS
Definition T32CZ20_rtc.h:264
@ TR_HAL_EVENT_TRIGGER_OFF
Definition T32CZ20_rtc.h:184
@ TR_HAL_EVENT_TRIGGER_INVALID
Definition T32CZ20_rtc.h:187
@ TR_HAL_EVENT_TRIGGER_ON_SPECIFIC_VALUE
Definition T32CZ20_rtc.h:186
@ TR_HAL_EVENT_TRIGGER_ON_UNIT_CHANGE
Definition T32CZ20_rtc.h:185
@ TR_HAL_RTC_TIME_UNIT_MONTHS
Definition T32CZ20_rtc.h:168
@ TR_HAL_RTC_TIME_UNIT_MINUTES
Definition T32CZ20_rtc.h:165
@ TR_HAL_RTC_TIME_UNIT_INVALID
Definition T32CZ20_rtc.h:170
@ TR_HAL_RTC_TIME_UNIT_YEARS
Definition T32CZ20_rtc.h:169
@ TR_HAL_RTC_TIME_UNIT_MILLISECONDS
Definition T32CZ20_rtc.h:163
@ TR_HAL_RTC_TIME_UNIT_DAYS
Definition T32CZ20_rtc.h:167
@ TR_HAL_RTC_TIME_UNIT_SECONDS
Definition T32CZ20_rtc.h:164
@ TR_HAL_RTC_TIME_UNIT_HOURS
Definition T32CZ20_rtc.h:166
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:247
__IO uint32_t milliseconds_event_trigger
Definition T32CZ20_rtc.h:248
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
uint16_t milliseconds_trigger_value
Definition T32CZ20_rtc.h:405
tr_hal_rtc_event_trigger_t milliseconds_event_trigger
Definition T32CZ20_rtc.h:404
Definition T32CM11_rtc.h:121
uint16_t milliseconds
Definition T32CZ20_rtc.h:135