Netcruzer Library API  V2.03
 All Data Structures Files Functions Variables Typedefs Enumerations Macros Groups Pages
nz_rtc.h
Go to the documentation of this file.
1 
62 #ifndef NZ_RTC_H
63 #define NZ_RTC_H
64 
65 #if defined(HAS_NZ_RTC)
66 
67 #include "nz_tick.h"
68 
70 #ifndef __INLINE_FUNCTION__
71 #define __INLINE_FUNCTION__ extern inline __attribute__((always_inline))
72 #endif
73 
74 typedef struct __attribute__((__packed__)) {
75  BYTE hour; //The current time in Hours ( 0 to 23 )
76  BYTE min; //The current time in Minutes ( 0 to 59 )
77  BYTE sec; //The current time in seconds ( 0 to 59 )
78  BYTE day; //The current date, in day of the month ( 1 to 31 )
79  BYTE month; //The current date, in month of the year ( 1 to 12 )
80  BYTE year; //The current date, in years since 2000. For example, is 14 for 2014
81  BYTE wday; //The current date, in day of week ( 0 to 6 where Sunday = 0)
82 } RTC_TIME_AND_DATE;
83 
84 typedef struct __attribute__((__packed__)) {
85  BYTE hour; //The current time in Hours ( 0 to 23 )
86  BYTE min; //The current time in Minutes ( 0 to 59 )
87  BYTE sec; //The current time in seconds ( 0 to 59 )
88 } RTC_TIME;
89 
90 typedef struct __attribute__((__packed__)) {
91  BYTE day; //The current date, in day of the month ( 1 to 31 )
92  BYTE month; //The current date, in month of the year ( 1 to 12 )
93  BYTE year; //The current date, in years since 2000. For example, is 14 for 2014
94  BYTE wday; //The current date, in day of week ( 0 to 6 where Sunday = 0)
95 } RTC_DATE;
96 
97 
99 
100 
105 BYTE rtcInit(void);
106 
107 
113 BYTE rtcLock(void);
114 
115 
121 BYTE rtcUnlock(void);
122 
123 
130 BYTE nz_rtcGetRegBcd2Bin(BYTE reg);
131 
132 
141 BYTE nz_rtcSetRegBin2Bcd(BYTE reg, BYTE val);
142 
149 BYTE rtcGetReg(BYTE regAdr, BYTE* reg);
150 
151 
159 BYTE rtcSetReg(BYTE regAdr, BYTE val);
160 
161 
162 
164 // Get Time & Date Functions
166 
172 BYTE __INLINE_FUNCTION__ rtcGetSec(void) {
173  return nz_rtcGetRegBcd2Bin(0x0); //Return second register = 0x00
174 }
175 
176 
182 BYTE __INLINE_FUNCTION__ rtcGetMin(void) {
183  return nz_rtcGetRegBcd2Bin(0x01); //Return min register = 0x01
184 }
185 
186 
192 BYTE rtcGetHour(void);
193 
194 
200 BYTE __INLINE_FUNCTION__ rtcGetDay(void) {
201  return nz_rtcGetRegBcd2Bin(0x03); //Return hour register = 0x03
202 }
203 
204 
210 BYTE __INLINE_FUNCTION__ rtcGetMonth(void) {
211  return nz_rtcGetRegBcd2Bin(0x04); //Return hour register = 0x04
212 }
213 
214 
221 WORD __INLINE_FUNCTION__ rtcGetYear(void) {
222  return nz_rtcGetRegBcd2Bin(0x05); //Return hour register = 0x05
223 }
224 
225 
231 WORD __INLINE_FUNCTION__ rtcGetWeekDay(void) {
232  return nz_rtcGetRegBcd2Bin(0x06); //Return hour register = 0x06
233 }
234 
235 
256 BYTE rtcGetTime(RTC_TIME* tm, BOOL bcdFormat);
257 
258 
280 BYTE rtcGetDate(RTC_DATE* dt, BOOL bcdFormat);
281 
282 
307 BYTE rtcGetTimeAndDate(RTC_TIME_AND_DATE* td, BOOL bcdFormat);
308 
309 
311 // Set Time & Date Functions
313 
321 BYTE __INLINE_FUNCTION__ rtcSetSec(BYTE sec) {
322  return nz_rtcSetRegBin2Bcd(0x0, sec); //Set seconds register = address 0x0
323 }
324 
332 BYTE __INLINE_FUNCTION__ rtcSetMin(BYTE min) {
333  return nz_rtcSetRegBin2Bcd(0x01, min); //Set minutes register = address 0x01
334 }
335 
336 
344 BYTE rtcSetHour(BYTE hour);
345 
346 
354 BYTE __INLINE_FUNCTION__ rtcSetDay(BYTE day) {
355  return nz_rtcSetRegBin2Bcd(0x03, day); //Set day register = address 0x03
356 }
357 
358 
366 BYTE __INLINE_FUNCTION__ rtcSetMonth(BYTE month) {
367  return nz_rtcSetRegBin2Bcd(0x04, month); //Set month register = address 0x04
368 }
369 
370 
378 BYTE __INLINE_FUNCTION__ rtcSetYear(WORD year) {
379  return nz_rtcSetRegBin2Bcd(0x05, year); //Set year register = address 0x05
380 }
381 
382 
390 BYTE __INLINE_FUNCTION__ rtcSetWeekDay(BYTE wday) {
391  return nz_rtcSetRegBin2Bcd(0x06, wday); //Set weekday register = address 0x06
392 }
393 
394 
416 BYTE rtcSetTime(RTC_TIME* tm);
417 
418 
444 BYTE rtcSetTimeAndDate(RTC_TIME_AND_DATE* td);
445 
446 
448 // Flag and Alarm Functions
450 
451 BOOL rtcDidPowerFail();
452 
453 BOOL rtcGetBatteryFlag();
454 
455 void rtcClearBatteryFlag();
456 
457 BOOL rtcGetAlarmFlag();
458 
459 void rtcClearAlarmFlag();
460 
461 
463 // RAM Functions
465 
471 BYTE __INLINE_FUNCTION__ rtcGetRAM1(void) {
472  BYTE val;
473  rtcGetReg(0x12, &val); //Get user ram 1 = address 0x12
474  return val;
475 }
476 
482 BYTE __INLINE_FUNCTION__ rtcGetRAM2(void) {
483  BYTE val;
484  rtcGetReg(0x13, &val); //Get user ram 2 = address 0x13
485  return val;
486 }
487 
494 BYTE __INLINE_FUNCTION__ rtcSetRAM1(BYTE val) {
495  return rtcSetReg(0x12, val); //Set user ram 1 = address 0x12
496 }
497 
498 
505 BYTE __INLINE_FUNCTION__ rtcSetRAM2(BYTE val) {
506  return rtcSetReg(0x13, val); //Set user ram 2 = address 0x13
507 }
508 
509 #endif //#if defined(HAS_NZ_RTC)
510 #endif //#ifndef NZ_RTC_H