* * $Log: x12rtc.c,v $ * Revision 1.6 2007/06/03 08:50:38 haraldkipp * Automatic detection of X1226 or X1286. * Fixed wrong century determination for X1226. * Debugging output added. * * Revision 1.5 2007/05/02 11:29:25 haraldkipp * Failed to store more than one EEPROM page. Removing NutSleep() from * X12WaitReady() fixes this. Why? * * Revision 1.4 2006/10/05 17:21:53 haraldkipp * Hardware specific functions marked deprecated. * Hardcoded register addresses and values replaced by macros. * * Revision 1.3 2006/03/02 19:57:34 haraldkipp * ICCARM insists on a (void *) typecast for the second parameter of memcpy(). * * Revision 1.2 2006/01/19 18:41:34 haraldkipp * Year translation was completely broken. Fixed. * * Revision 1.1 2005/10/24 10:21:57 haraldkipp * Initial check in. * * *
Definition in file x12rtc.c.
Go to the source code of this file.
Defines | |
#define | I2C_SLA_RTC 0x6F |
#define | I2C_SLA_EEPROM 0x57 |
#define | EEPROM_PAGE_SIZE 64 |
Functions | |
int | X12RtcReadRegs (u_char reg, u_char *buff, size_t cnt) |
Read RTC registers. | |
int | X12RtcWrite (int nv, CONST u_char *buff, size_t cnt) |
Write to RTC registers. | |
int | X12RtcGetClock (struct _tm *tm) |
Get date and time from an X12xx hardware clock. | |
int | X12RtcSetClock (CONST struct _tm *tm) |
Set an X12xx hardware clock. | |
int | X12RtcGetAlarm (int idx, struct _tm *tm, int *aflgs) |
Get alarm date and time of an X12xx hardware clock. | |
int | X12RtcSetAlarm (int idx, CONST struct _tm *tm, int aflgs) |
Set alarm of an X12xx hardware clock. | |
int | X12RtcGetStatus (u_long *sflgs) |
Query RTC status flags. | |
int | X12RtcClearStatus (u_long sflgs) |
Clear RTC status flags. | |
int | X12EepromRead (u_int addr, void *buff, size_t len) |
Read contents from non-volatile EEPROM. | |
int | X12EepromWrite (u_int addr, CONST void *buff, size_t len) |
Store buffer contents in non-volatile EEPROM. | |
int | X12Init (void) |
Initialize the interface to an Intersil X12xx hardware clock. | |
Variables | |
NUTRTC | rtcX12x6 |
#define I2C_SLA_EEPROM 0x57 |
#define EEPROM_PAGE_SIZE 64 |
Read RTC registers.
reg | The first register to read. | |
buff | Pointer to a buffer that receives the register contents. | |
cnt | The number of registers to read. |
Definition at line 158 of file x12rtc.c.
References I2C_SLA_RTC, NUT_WAIT_INFINITE, printf, putchar(), and TwMasterTransact().
int X12RtcWrite | ( | int | nv, | |
CONST u_char * | buff, | |||
size_t | cnt | |||
) |
Write to RTC registers.
nv | Must be set to 1 when writing to non-volatile registers. In this case the routine will poll for write cycle completion before returning to the caller. Set to zero if writing to volatile registers. | |
buff | This buffer must contain all bytes to be transfered to the RTC chip, including the register address. | |
cnt | Number of valid bytes in the buffer. |
Definition at line 191 of file x12rtc.c.
References I2C_SLA_RTC, NUT_WAIT_INFINITE, printf, putchar(), and TwMasterTransact().
int X12RtcGetClock | ( | struct _tm * | tm | ) |
Get date and time from an X12xx hardware clock.
tm | Points to a structure that receives the date and time information. |
Definition at line 223 of file x12rtc.c.
References BCD2BIN, _tm::tm_hour, _tm::tm_mday, _tm::tm_min, _tm::tm_mon, _tm::tm_sec, _tm::tm_wday, _tm::tm_year, X12RTC_SC, and X12RtcReadRegs().
int X12RtcSetClock | ( | CONST struct _tm * | tm | ) |
Set an X12xx hardware clock.
tm | Points to a structure which contains the date and time information. |
Definition at line 260 of file x12rtc.c.
References BIN2BCD, memset(), X12RTC_SC, and X12RtcWrite().
int X12RtcGetAlarm | ( | int | idx, | |
struct _tm * | tm, | |||
int * | aflgs | |||
) |
Get alarm date and time of an X12xx hardware clock.
idx | Zero based index. Two alarms are supported. | |
tm | Points to a structure that receives the date and time information. | |
aflgs | Points to an unsigned long that receives the enable flags. |
Definition at line 304 of file x12rtc.c.
References BCD2BIN, memset(), RTC_ALARM_HOUR, RTC_ALARM_MDAY, RTC_ALARM_MINUTE, RTC_ALARM_MONTH, RTC_ALARM_SECOND, RTC_ALARM_WDAY, _tm::tm_hour, _tm::tm_mday, _tm::tm_min, _tm::tm_mon, _tm::tm_sec, _tm::tm_wday, X12RTC_DTA_EDT, X12RTC_DWA_EDW, X12RTC_HRA_EHR, X12RTC_MNA_EMN, X12RTC_MOA_EMO, X12RTC_SCA_ESC, and X12RtcReadRegs().
int X12RtcSetAlarm | ( | int | idx, | |
CONST struct _tm * | tm, | |||
int | aflgs | |||
) |
Set alarm of an X12xx hardware clock.
idx | Zero based index. Two alarms are supported. | |
tm | Points to a structure which contains the date and time information. May be NULL to clear the alarm. | |
aflgs | Each bit enables a specific comparision.
|
Definition at line 358 of file x12rtc.c.
References BIN2BCD, memset(), RTC_ALARM_HOUR, RTC_ALARM_MDAY, RTC_ALARM_MINUTE, RTC_ALARM_MONTH, RTC_ALARM_SECOND, RTC_ALARM_WDAY, X12RTC_DTA_EDT, X12RTC_DWA_EDW, X12RTC_HRA_EHR, X12RTC_MNA_EMN, X12RTC_MOA_EMO, X12RTC_SCA_ESC, and X12RtcWrite().
int X12RtcGetStatus | ( | u_long * | sflgs | ) |
Query RTC status flags.
sflgs | Points to an unsigned long that receives the status flags.
|
Definition at line 399 of file x12rtc.c.
References X12RTC_SR, and X12RtcReadRegs().
int X12RtcClearStatus | ( | u_long | sflgs | ) |
Clear RTC status flags.
sflgs | Status flags to clear. |
int X12EepromRead | ( | u_int | addr, | |
void * | buff, | |||
size_t | len | |||
) |
Read contents from non-volatile EEPROM.
addr | Start location. | |
buff | Points to a buffer that receives the contents. | |
len | Number of bytes to read. |
Definition at line 447 of file x12rtc.c.
References I2C_SLA_EEPROM, NUT_WAIT_INFINITE, and TwMasterTransact().
int X12EepromWrite | ( | u_int | addr, | |
CONST void * | buff, | |||
size_t | len | |||
) |
Store buffer contents in non-volatile EEPROM.
The EEPROM of the X122x has a capacity of 512 bytes, while the X1286 is able to store 32 kBytes.
addr | Storage start location. | |
buff | Points to a buffer that contains the bytes to store. | |
len | Number of valid bytes in the buffer. |
Definition at line 472 of file x12rtc.c.
References CONST, EEPROM_PAGE_SIZE, free, I2C_SLA_EEPROM, malloc, memcpy(), NUT_WAIT_INFINITE, and TwMasterTransact().
int X12Init | ( | void | ) |
Initialize the interface to an Intersil X12xx hardware clock.
Definition at line 530 of file x12rtc.c.
References NutSleep(), printf, TwInit(), X128xRTC_SSEC, X12RtcGetStatus(), and X12RtcReadRegs().
Initial value: