Nut/OS  4.10.3
API Reference
rtc.h File Reference
#include <sys/types.h>
#include <stdint.h>
#include <time.h>
Include dependency graph for rtc.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  _NUTRTC
 RTC device structure. More...

Defines

#define RTC_STATUS_PF   0x00000001
#define RTC_STATUS_AL0   0x00000020
#define RTC_STATUS_AL1   0x00000040
#define RTC_ALARM_SECOND   0x00000001
#define RTC_ALARM_MINUTE   0x00000002
#define RTC_ALARM_HOUR   0x00000004
#define RTC_ALARM_MDAY   0x00000008
#define RTC_ALARM_MONTH   0x00000010
#define RTC_ALARM_WDAY   0x00000080
#define BCD2BIN(x)   ((((uint8_t)(x)) >> 4) * 10 + ((x) & 0x0F))
 Convert binary coded decimal to binary value.
#define BIN2BCD(x)   (((((uint8_t)(x)) / 10) << 4) + (x) % 10)
 Convert binary to binary coded decimal value.

Typedefs

typedef struct _NUTRTC NUTRTC
 RTC device type.

Functions

int NutRegisterRtc (NUTRTC *rtc)
 Register a specified RTC.
int NutRtcGetTime (struct _tm *tm)
 Get date and time from the registered RTC.
int NutRtcSetTime (CONST struct _tm *tm)
 Set date and time of the registered RTC.
int NutRtcGetAlarm (int idx, struct _tm *tm, int *aflags)
 Get alarm date and time from the registered RTC.
int NutRtcSetAlarm (int idx, CONST struct _tm *tm, int aflags)
 Set alarm date and time of the registered RTC.
int NutRtcGetStatus (uint32_t *sflags)
 Query status flags from the registered RTC.
int NutRtcClearStatus (uint32_t sflags)
 Clear status flags of the registered RTC.

Define Documentation

#define RTC_STATUS_PF   0x00000001
Examples:
caltime/caltime.c, and ftpd/ftpserv.c.

Definition at line 51 of file rtc.h.

Referenced by main(), and PcfRtcGetStatus().

#define RTC_STATUS_AL0   0x00000020

Definition at line 52 of file rtc.h.

#define RTC_STATUS_AL1   0x00000040

Definition at line 53 of file rtc.h.

#define RTC_ALARM_SECOND   0x00000001

Definition at line 55 of file rtc.h.

Referenced by X12RtcGetAlarm(), and X12RtcSetAlarm().

#define RTC_ALARM_MINUTE   0x00000002

Definition at line 56 of file rtc.h.

Referenced by X12RtcGetAlarm(), and X12RtcSetAlarm().

#define RTC_ALARM_HOUR   0x00000004

Definition at line 57 of file rtc.h.

Referenced by X12RtcGetAlarm(), and X12RtcSetAlarm().

#define RTC_ALARM_MDAY   0x00000008

Definition at line 58 of file rtc.h.

Referenced by X12RtcGetAlarm(), and X12RtcSetAlarm().

#define RTC_ALARM_MONTH   0x00000010

Definition at line 59 of file rtc.h.

Referenced by X12RtcGetAlarm(), and X12RtcSetAlarm().

#define RTC_ALARM_WDAY   0x00000080

Definition at line 60 of file rtc.h.

Referenced by X12RtcGetAlarm(), and X12RtcSetAlarm().

#define BCD2BIN (   x)    ((((uint8_t)(x)) >> 4) * 10 + ((x) & 0x0F))

Convert binary coded decimal to binary value.

Definition at line 65 of file rtc.h.

Referenced by DS1307RtcGetClock(), PcfRtcGetClock(), X12RtcGetAlarm(), and X12RtcGetClock().

#define BIN2BCD (   x)    (((((uint8_t)(x)) / 10) << 4) + (x) % 10)

Convert binary to binary coded decimal value.

Definition at line 70 of file rtc.h.

Referenced by DS1307RtcSetClock(), PcfRtcSetClock(), X12RtcSetAlarm(), and X12RtcSetClock().


Typedef Documentation

typedef struct _NUTRTC NUTRTC

RTC device type.

Definition at line 75 of file rtc.h.


Function Documentation

int NutRegisterRtc ( NUTRTC rtc)

Register a specified RTC.

This will also initialize any hardware, if required.

Parameters:
rtcPointer to the NUTRTC structure.
Returns:
0 on success or -1 in case of an error.
Examples:
caltime/caltime.c.

Definition at line 69 of file rtc.c.

References _NUTRTC::rtc_init.

Referenced by main().

int NutRtcGetTime ( struct _tm tm)

Get date and time from the registered RTC.

Portable applications should use standard C functions.

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

Definition at line 91 of file rtc.c.

References _NUTRTC::rtc_gettime.

Referenced by time().

int NutRtcSetTime ( CONST struct _tm tm)

Set date and time of the registered RTC.

Portable applications should stime().

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

Definition at line 109 of file rtc.c.

References _NUTRTC::rtc_settime.

Referenced by stime().

int NutRtcGetAlarm ( int  idx,
struct _tm tm,
int *  aflags 
)

Get alarm date and time from the registered RTC.

Parameters:
idxZero based index. Two alarms are supported.
tmPoints to a structure that receives the date and time information.
aflagsPoints to an unsigned long that receives the enable flags.
Returns:
0 on success or -1 in case of an error.

Definition at line 128 of file rtc.c.

References _NUTRTC::rtc_getalarm.

int NutRtcSetAlarm ( int  idx,
CONST struct _tm tm,
int  aflags 
)

Set alarm date and time of the registered RTC.

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.
aflagsEach 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.

Definition at line 152 of file rtc.c.

References _NUTRTC::rtc_setalarm.

int NutRtcGetStatus ( uint32_t sflags)

Query status flags from the registered RTC.

Parameters:
sflagsPoints 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.
Examples:
caltime/caltime.c.

Definition at line 170 of file rtc.c.

References _NUTRTC::rtc_getstatus.

Referenced by main().

int NutRtcClearStatus ( uint32_t  sflags)

Clear status flags of the registered RTC.

Parameters:
sflagsStatus flags to clear.
Returns:
Always 0.

Definition at line 185 of file rtc.c.

References _NUTRTC::rtc_clrstatus.