1. Home
  2. Docs
  3. Code Overview
  4. Real-time Clock and Calendar

Real-time Clock and Calendar

Each programmable module has a real-time clock (RTC) and calendar that can be used to track time and date. The module will sustain an accurate internal time and date as long as it is powered from a power source or battery, and the initial time and date were set up correctly.

Current time and date can be accessed anywhere in the project by calling the GetTimeDate() API and reading the global BOS.time and BOS.date structs:

BOS.time.ampm      // Current time in 12-hour format: RTC_AM or RTC_PM
BOS.time.msec      // Milliseconds: 0-999
BOS.time.seconds   // Seconds: 0-59
BOS.time.minutes   // Minutes: 0-59
BOS.time.hours     // Hours: 0-23
BOS.date.day       // Date: 1-31
BOS.date.month     // Month: JANUARY (1) to DECEMBER (12)
BOS.date.weekday   // Weekday: MONDAY (1) to SUNDAY (7)
BOS.date.year      // Year: Starting from 2000

You can set up the hour format (12 or 24) and calendar daylight saving settings (DAYLIGHT_SUB1H, DAYLIGHT_ADD1H, or DAYLIGHT_NONE) from the BOS.hourformat and the BOS.daylightsaving parameters, respectively. The settings will be saved in the emulated-EEPROM and loaded on startup.

The RTC takes the firmware’s compile time and date as the initial time and date by default. You can reset the initial time and date via the BOS_CalendarConfig() API or the set CLI command. Even if the MCU was hardware-reset, it will keep its current initial time and date (and hence sustain time and date accurately) as long as it is powered. Once it loses power, it returns to the default firmware compile time and date and the RTC must be reconfigured again.

To display current time and date in the CLI, use the time and date commands. You can also configure the RTC in the CLI via the set time and set date commands.

How can we help?

0