Nut/OS  5.0.5
API Reference
x12rtc.c File Reference

RTC and EEPROM routines for the Intersil X12xx clock chips. More...

#include <cfg/os.h>
#include <cfg/eeprom.h>
#include <dev/twif.h>
#include <sys/event.h>
#include <sys/timer.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <memdebug.h>
#include <dev/x12rtc.h>
Include dependency graph for x12rtc.c:

Defines

#define NUT_DEPRECATED
#define I2C_SLA_RTC   0x6F
#define I2C_SLA_EEPROM   0x57
#define EEPROM_PAGE_SIZE   64

Functions

int X12RtcReadRegs (uint8_t reg, uint8_t *buff, size_t cnt)
 Read RTC registers.
int X12RtcWrite (int nv, const uint8_t *buff, size_t cnt)
 Write to RTC registers.
int X12RtcGetClock (NUTRTC *rtc, struct _tm *tm)
 Get date and time from an X12xx hardware clock.
int X12RtcSetClock (NUTRTC *rtc, const struct _tm *tm)
 Set an X12xx hardware clock.
int X12RtcGetAlarm (NUTRTC *rtc, int idx, struct _tm *tm, int *aflgs)
 Get alarm date and time of an X12xx hardware clock.
int X12RtcSetAlarm (NUTRTC *rtc, int idx, const struct _tm *tm, int aflgs)
 Set alarm of an X12xx hardware clock.
int X12RtcGetStatus (NUTRTC *rtc, uint32_t *sflgs)
 Query RTC status flags.
int X12RtcClearStatus (NUTRTC *rtc, uint32_t sflgs)
 Clear RTC status flags.
int X12EepromRead (unsigned int addr, void *buff, size_t len)
 Read contents from non-volatile EEPROM.
int X12EepromWrite (unsigned int addr, const void *buff, size_t len)
 Store buffer contents in non-volatile EEPROM.
int X12Init (NUTRTC *rtc)
 Initialize the interface to an Intersil X12xx hardware clock.

Variables

NUTRTC rtcX12x6

Detailed Description

RTC and EEPROM routines for the Intersil X12xx clock chips.

 *
 * $Log$
 * Revision 1.10  2009/02/13 14:52:05  haraldkipp
 * Include memdebug.h for heap management debugging support.
 *
 * Revision 1.9  2009/01/17 11:26:46  haraldkipp
 * Getting rid of two remaining BSD types in favor of stdint.
 * Replaced 'u_int' by 'unsinged int' and 'uptr_t' by 'uintptr_t'.
 *
 * Revision 1.8  2008/08/11 06:59:42  haraldkipp
 * BSD types replaced by stdint types (feature request #1282721).
 *
 * Revision 1.7  2008/07/09 14:25:06  haraldkipp
 * Made EEPROM_PAGE_SIZE configurable. Does it really make sense?
 *
 * 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.
 *
 *
 * 

Define Documentation

#define NUT_DEPRECATED
#define I2C_SLA_RTC   0x6F

Referenced by X12RtcReadRegs(), and X12RtcWrite().

#define I2C_SLA_EEPROM   0x57

Referenced by X12EepromRead(), and X12EepromWrite().

#define EEPROM_PAGE_SIZE   64

Referenced by X12EepromWrite().


Function Documentation

int X12RtcReadRegs ( uint8_t  reg,
uint8_t buff,
size_t  cnt 
)

Read RTC registers.

Parameters:
regThe first register to read.
buffPointer to a buffer that receives the register contents.
cntThe number of registers to read.
Returns:
0 on success or -1 in case of an error.

References I2C_SLA_RTC, NUT_WAIT_INFINITE, printf, putchar(), rc, and TwMasterTransact.

Referenced by X12Init(), X12RtcGetAlarm(), X12RtcGetClock(), and X12RtcGetStatus().

Here is the call graph for this function:

int X12RtcWrite ( int  nv,
const uint8_t buff,
size_t  cnt 
)

Write to RTC registers.

Parameters:
nvMust 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.
buffThis buffer must contain all bytes to be transfered to the RTC chip, including the register address.
cntNumber of valid bytes in the buffer.
Returns:
0 on success or -1 in case of an error.

References I2C_SLA_RTC, NUT_WAIT_INFINITE, printf, putchar(), rc, and TwMasterTransact.

Referenced by X12RtcSetAlarm(), and X12RtcSetClock().

Here is the call graph for this function:

int X12RtcGetClock ( NUTRTC rtc,
struct _tm tm 
)

Get date and time from an X12xx hardware clock.

Deprecated:
New applications must use NutRtcGetTime().
Parameters:
tmPoints to a structure that receives the date and time information.
Returns:
0 on success or -1 in case of an error.

References BCD2BIN, rc, _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().

Here is the call graph for this function:

int X12RtcSetClock ( NUTRTC rtc,
const struct _tm tm 
)

Set an X12xx hardware clock.

Deprecated:
New applications must use NutRtcSetTime().

New time will be taken over at the beginning of the next second.

Parameters:
tmPoints to a structure which contains the date and time information.
Returns:
0 on success or -1 in case of an error.

References BIN2BCD, memset(), _tm::tm_hour, _tm::tm_mday, _tm::tm_min, _tm::tm_mon, _tm::tm_sec, _tm::tm_wday, _tm::tm_year, X12RTC_SC, and X12RtcWrite().

Here is the call graph for this function:

int X12RtcGetAlarm ( NUTRTC rtc,
int  idx,
struct _tm tm,
int *  aflgs 
)

Get alarm date and time of an X12xx hardware clock.

Deprecated:
New applications must use NutRtcGetAlarm().
Parameters:
idxZero based index. Two alarms are supported.
tmPoints to a structure that receives the date and time information.
aflgsPoints to an unsigned long that receives the enable flags.
Returns:
0 on success or -1 in case of an error.

References BCD2BIN, memset(), rc, 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().

Here is the call graph for this function:

int X12RtcSetAlarm ( NUTRTC rtc,
int  idx,
const struct _tm tm,
int  aflgs 
)

Set alarm of an X12xx hardware clock.

Deprecated:
New applications must use NutRtcSetAlarm().
Parameters:
idxZero based index. Two alarms are supported.
tmPoints to a structure which contains the date and time information. May be NULL to clear the alarm.
aflgsEach bit enables a specific comparision.
  • Bit 0: Seconds
  • Bit 1: Minutes
  • Bit 2: Hours
  • Bit 3: Day of month
  • Bit 4: Month
  • Bit 7: Day of week (Sunday is zero)
Returns:
0 on success or -1 in case of an error.

References BIN2BCD, 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 X12RtcWrite().

Here is the call graph for this function:

int X12RtcGetStatus ( NUTRTC rtc,
uint32_t sflgs 
)

Query RTC status flags.

Deprecated:
New applications must use NutRtcGetStatus().
Parameters:
sflgsPoints to an unsigned long that receives the status flags.
  • Bit 0: Power fail.
  • Bit 5: Alarm 0 occured.
  • Bit 6: Alarm 1 occured.
Returns:
0 on success or -1 in case of an error.

References rc, X12RTC_SR, and X12RtcReadRegs().

Referenced by X12Init().

Here is the call graph for this function:

int X12RtcClearStatus ( NUTRTC rtc,
uint32_t  sflgs 
)

Clear RTC status flags.

Deprecated:
New applications must use NutRtcClearStatus().
Parameters:
sflgsStatus flags to clear.
Returns:
Always 0.
int X12EepromRead ( unsigned int  addr,
void *  buff,
size_t  len 
)

Read contents from non-volatile EEPROM.

Parameters:
addrStart location.
buffPoints to a buffer that receives the contents.
lenNumber of bytes to read.
Returns:
0 on success or -1 in case of an error.

References I2C_SLA_EEPROM, NUT_WAIT_INFINITE, rc, and TwMasterTransact.

Referenced by NutNvMemLoad().

int X12EepromWrite ( unsigned 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.

Parameters:
addrStorage start location.
buffPoints to a buffer that contains the bytes to store.
lenNumber of valid bytes in the buffer.
Returns:
0 on success or -1 in case of an error.

References EEPROM_PAGE_SIZE, free(), I2C_SLA_EEPROM, malloc(), memcpy(), NUT_WAIT_INFINITE, rc, and TwMasterTransact.

Referenced by NutNvMemSave().

Here is the call graph for this function:

int X12Init ( NUTRTC rtc)

Initialize the interface to an Intersil X12xx hardware clock.

Deprecated:
New applications must use NutRegisterRtc().
Returns:
0 on success or -1 in case of an error.

References NutSleep(), printf, rc, TwInit, X128xRTC_SSEC, X12RtcGetStatus(), and X12RtcReadRegs().

Here is the call graph for this function:


Variable Documentation