dnx RTOS 2.2.0 "Eagle"
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
RTC Driver

Detailed Description

Description

Driver handles real time clock peripheral.

Supported architectures

Details

Meaning of major and minor numbers

The major number value depends on number RTC peripherals in microcontroller. The minor number should be set to 0.

Numeration restrictions

Major number architecture limitations:

Driver initialization

To initialize driver the following code can be used:

driver_init("RTC", 0, 0, "/dev/rtc");

Driver path is used by system to read time. The path of RTC device can be configured by Configtool.

Driver release

To release driver the following code can be used:

driver_release("RTC", 0, 0);

Driver configuration

Driver can be configured by using ioctl() function. The RTC alarm only can be configured. Example:

#include <stdio.h>
#include <sys/ioctl.h>
#include <time.h>
#include <unistd.h>
#include <dnx/os.h>
// ...
FILE *rtc = fopen("/dev/rtc", "r+");
if (rtc) {
// wake up in 5 seconds
time_t t = time(NULL) + 5000;
if (ioctl(fileno(rtc), IOCTL_RTC__SET_ALARM, &t) == 0) {
sync();
} else {
perror("ioctl()");
}
fclose(rtc);
} else {
perror("/dev/rtc");
}
// ...

Data write

Only sizeof(time_t) bytes can be written to the device at position 0. More bytes is trimmed. When write position is not 0 then error is returned.

Note
To setup time please use stime() function instead of direct device write.

Data read

Only sizeof(time_t) bytes can be read from device at position 0. Reading other file positions is not allowed and error is generated.

Note
To read time please use time() function instead of direct device read.

Macros

#define IOCTL_RTC__SET_ALARM   _IOW(RTC, 0x00, time_t*)
 Set RTC alarm. This function can be used to wake up CPU from sleep. More...
 
#define IOCTL_RTC__GET_ALARM   _IOR(RTC, 0x01, time_t*)
 Get RTC alarm value. More...
 

Macro Definition Documentation

#define IOCTL_RTC__GET_ALARM   _IOR(RTC, 0x01, time_t*)
Parameters
[RD]time_t * UNIX timestamp.
Returns
On success 0 is returned, otherwise -1.
#define IOCTL_RTC__SET_ALARM   _IOW(RTC, 0x00, time_t*)
Parameters
[WR]time_t * UNIX timestamp.
Returns
On success 0 is returned, otherwise -1.