Nut/OS  5.0.5
API Reference
ds1307rtc.c File Reference

RTC and RAM routines for the Dallas DS1307 clock chip. More...

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

Defines

#define I2C_SLA_RTC   0x68

Functions

int DS1307RtcReadRegs (uint8_t reg, uint8_t *buff, size_t cnt)
 Read RTC registers.
int DS1307RtcWrite (const uint8_t *buff, size_t cnt)
 Write to RTC registers.
int DS1307RtcGetClock (NUTRTC *rtc, struct _tm *tm)
 Get date and time from an DS1307 hardware clock.
int DS1307RtcSetClock (NUTRTC *rtc, const struct _tm *tm)
 Set the DS1307 hardware clock.
int DS1307RamRead (uint8_t addr, uint8_t *buff, size_t cnt)
 Read contents from DS1307 RAM.
int DS1307RamWrite (uint8_t addr, const void *buff, size_t len)
 Store buffer contents in DS1307 RAM.
int DS1307Init (NUTRTC *rtc)
 Initialize the interface to an Dallas DS1307 hardware clock.

Variables

NUTRTC rtcDs1307

Detailed Description

RTC and RAM routines for the Dallas DS1307 clock chip.

 *
 * $Log$
 * Revision 1.6  2008/08/11 06:59:42  haraldkipp
 * BSD types replaced by stdint types (feature request #1282721).
 *
 * Revision 1.5  2007/09/11 17:32:30  haraldkipp
 * Last minute fix (bug #1786271)
 *
 * Revision 1.4  2006/10/08 16:39:33  haraldkipp
 * Corrected range check in DS1307RamRead(). Thanks to Helmut Holbach.
 *
 * Revision 1.3  2006/10/05 17:18:49  haraldkipp
 * Hardware independant RTC layer added.
 *
 * Revision 1.2  2006/08/25 13:42:55  olereinhardt
 * avr-gcc 3.4 does not understand binary representation of numbers,
 * changed to hex
 *
 * Revision 1.1  2006/06/30 22:05:51  christianwelzel
 * Initial check in.
 *
 *
 * 

Define Documentation

#define I2C_SLA_RTC   0x68

Function Documentation

int DS1307RtcReadRegs ( 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, rc, and TwMasterTransact.

Referenced by DS1307Init(), DS1307RamRead(), and DS1307RtcGetClock().

int DS1307RtcWrite ( const uint8_t buff,
size_t  cnt 
)

Write to RTC registers.

Parameters:
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, rc, and TwMasterTransact.

Referenced by DS1307Init(), and DS1307RtcSetClock().

int DS1307RtcGetClock ( NUTRTC rtc,
struct _tm tm 
)

Get date and time from an DS1307 hardware clock.

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, DS1307RtcReadRegs(), rc, _tm::tm_hour, _tm::tm_mday, _tm::tm_min, _tm::tm_mon, _tm::tm_sec, _tm::tm_wday, and _tm::tm_year.

Here is the call graph for this function:

int DS1307RtcSetClock ( NUTRTC rtc,
const struct _tm tm 
)

Set the DS1307 hardware clock.

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, DS1307RtcWrite(), memset(), _tm::tm_hour, _tm::tm_mday, _tm::tm_min, _tm::tm_mon, _tm::tm_sec, _tm::tm_wday, and _tm::tm_year.

Here is the call graph for this function:

int DS1307RamRead ( uint8_t  addr,
uint8_t buff,
size_t  cnt 
)

Read contents from DS1307 RAM.

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

References DS1307RtcReadRegs(), and rc.

Here is the call graph for this function:

int DS1307RamWrite ( uint8_t  addr,
const void *  buff,
size_t  len 
)

Store buffer contents in DS1307 RAM.

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 free(), I2C_SLA_RTC, malloc(), memcpy(), NUT_WAIT_INFINITE, rc, and TwMasterTransact.

Here is the call graph for this function:

int DS1307Init ( NUTRTC rtc)

Initialize the interface to an Dallas DS1307 hardware clock.

Returns:
0 on success or -1 in case of an error.

References DS1307RtcReadRegs(), DS1307RtcWrite(), rc, and TwInit.

Here is the call graph for this function:


Variable Documentation