RTC

The basic purpose for the RTC is to keep time of day. The other equally important purpose of RTC is for Digital Rights management. Some degree of tamper proofing is needed to ensure that simply stopping, resetting, or corrupting the RTC does not go unnoticed so that if this occurs, the application can re-acquire the time of day from a trusted source.

Features Supported

  • Supported 15 bit 32768Hz counter.

  • Supported 48 bit seconds counter with +/- 1 30uS upto +/- 1 S drift adjustment every 4048 Seconds.

  • Support for 256 bits of Scratch PAD

  • 1 ON_OFF compare event, 48-bits

  • 1 OFF_ON compare event, 48-bits

  • 2 event outputs OFF_ON and ON_OFF to CORE

  • Functional lockout, unlock by special vbusp sequence

  • HOST PROCESSOR can update MMRs without polling, thanks to HW Shadow/Auto Sync

  • HOST PROCESSOR can read time without polling, thanks to HW Shadow/Auto Sync

SysConfig Features

Note

It is strongly recommend to use SysConfig where it is available instead of using direct SW API calls. This will help simplify the SW application and also catch common mistakes early in the development cycle.

  • RTC instance name

  • Input clock frequency to be used for RTC module

  • Enable Freeze Mode for RTC.

  • Enable Interrupt and Assign User Callback

  • Support to attach callback functions to each of the ON_OFF/OFF_ON events

Features NOT Supported

  • PMIC enable support

Example Usage

Include the below file to access the APIs

#include <drivers/rtc.h>

Instance Open Example

    RTC_Params         params;

    /* Initialize parameters */
    RTC_Params_init(&params);

    params.isfreezemode = true,
    params.onOffCallback = false,
    params.offOnCallback = false,

    /* Update object Parameters mode settings */
    gRTCObjects[CONFIG_RTC0].On_OffCallbackFunction = NULL,
    gRTCObjects[CONFIG_RTC0].Off_OnCallbackFunction = NULL,

    gRTCHandle = RTC_open(CONFIG_RTC0, &params);
    DebugP_assert(gRTCHandle != NULL);

Instance Close Example

    RTC_close(gRTCHandle);

API Reference

RTC Driver API/interface file.

RTC Timer Interrupt Set/Indication Flags

RTC_TMR_INT_INT0_STATUS_FLAG

ON_OFF status interrupt.

RTC_TMR_INT_INT1_STATUS_FLAG

OFF_ON status interrupt.

RTC_TMR_INT_INT0_CLEAR_FLAG

ON_OFF clear interrupt.

RTC_TMR_INT_INT1_CLEAR_FLAG

OFF_ON clear interrupt.

RTC_TMR_INT_INT0_SET_FLAG

ON_OFF set interrupt.

RTC_TMR_INT_INT1_SET_FLAG

OFF_ON set interrupt.

RTC_TMR_INT_INT0_RAW_STATUS_FLAG

ON_OFF raw status interrupt.

RTC_TMR_INT_INT1_RAW_STATUS_FLAG

OFF_ON raw status interrupt.

RTC_TMR_INT_STATUS_ALL

All interrupt status mask.

RTC_TMR_INT_CLEAR_ALL

All interrupt clear mask.

RTC_TMR_INT_REQ_ALL

All interrupt set mask.

RTC_TMR_INT_RAW_STATUS_ALL

All interrupt raw status mask.

Defines

OSCILLATOR_FREQ_HZ

32.768 kHz Crystal Oscillator Frequency

RTC_FREEZE_MODE

Enable Freeze Mode.

O32K_OSC_DEP_EN_MASK

O32K_OSC_DEP_EN_MASK.

RD_PEND_MASK

Read Pend Status.

WR_PEND_MASK

Write Pend Status.

O32K_CLK_OBS_BIT_MASK

O32K_CLK_OBS_BIT_MASK.

RTC_SW_OFF_MASK

RTC_SW_OFF_MASK.

RTC_UNLOCK_MASK

Unlock State Status.

OSC_LOCK_WAIT

Wait time for stabalizing OSC.

KICK0_UNLOCK_VALUE

RTC Kick unlock values.

KICK1_UNLOCK_VALUE
KICK0_LOCK_VALUE

RTC Kick lock values.

KICK1_LOCK_VALUE
RTC_BASEADDR

RTC Base Address.

Typedefs

typedef struct RTC_Config_s *RTC_Handle

A handle that is returned from a RTC_open() call.

typedef void (*RTC_OnOffCallbackFxn)(RTC_Handle handle)

The definition of a ON_OFF callback function used by the RTC driver.

The callback will be called if the ON_OFF interrupt is enabled.

Param handle:

RTC_Handle

typedef void (*RTC_OffOnCallbackFxn)(RTC_Handle handle)

The definition of a OFF_ON callback function used by the RTC driver.

  • The callback will be called if the OFF_ON interrupt is enabled.

Param handle:

RTC_Handle

Functions

void RTC_init(void)

Initialize the RTC module.

void RTC_deinit(void)

De-initialize the RTC module.

void RTC_paramsInit(RTC_Params *params)

Function to set default values of RTC_Params in params.

Parameters:

params – [IN] pointer to the structure to be initialized

RTC_Handle RTC_open(uint32_t idx, const RTC_Params *params)

Open the RTC at index idx with parameters params.

Parameters:
  • idx – [IN] Index of RTC to open in global config

  • params – [IN] RTC_Params values to use for opening

Returns:

RTC_Handle

void RTC_close(RTC_Handle handle)

Function to close the RTC Peripheral specified by the handle.

See also

RTC_open()

Parameters:

handle – [IN] RTC_Handle returned from RTC_open()

Pre:

RTC_open() has to be called first

int32_t RTC_setTime(RTC_Handle handle, const RTC_Time *rtc_time)

Set the RTC time.

Parameters:
Returns:

RTC_StatusCode

int32_t RTC_getTime(RTC_Handle handle, RTC_Time *rtc_time)

Get the current RTC time.

Parameters:
Returns:

RTC_StatusCode

int32_t RTC_setOff_OnTimerEvent(RTC_Handle handle, const RTC_Time *rtc_time)

Set the off-on timer event / Use as timer 1 for RTC.

Parameters:
Returns:

RTC_StatusCode

int32_t RTC_setOn_OffTimerEvent(RTC_Handle handle, const RTC_Time *rtc_time)

Set the on-off timer event / Use as timer 2 for RTC.

Parameters:
Returns:

RTC_StatusCode

uint32_t RTC_readScratchRegister(RTC_Handle handle, uint32_t scratchIndex)

Read a value from a specific RTC scratch register.

Parameters:
  • handle – [IN] RTC_Handle returned from RTC_open()

  • scratchIndex – [IN] Index of scratch register to read

Returns:

Value from the specified scratch register

int32_t RTC_writeScratchRegister(RTC_Handle handle, uint32_t scratchIndex, uint32_t value)

Write a value to a specific RTC scratch register.

Parameters:
  • handle – [IN] RTC_Handle returned from RTC_open()

  • scratchIndex – [IN] Index of scratch register to write

  • value – [IN] Value to write to the scratch register

Returns:

RTC_StatusCode

RTC_Time RTC_calculateElapsedTime(const RTC_Time *startTime, const RTC_Time *endTime)

Calculate Elapsed Time.

Parameters:
  • startTime – [IN] RTC_Time structure having start time

  • endTime – [IN] RTC_Time structure having end time

int32_t RTC_adjustForDrift(RTC_Handle handle, Float32 measuredDriftInSeconds)

Calculate Elapsed Time.

Parameters:
  • handle – [IN] RTC_Handle returned from RTC_open()

  • measuredDriftInSeconds – [IN] Drift Value to be adjusted in Seconds

Returns:

RTC_StatusCode

int32_t RTC_stop(RTC_Handle handle)

Stop the RTC.

Parameters:

handle – [IN] RTC_Handle returned from RTC_open()

Returns:

RTC_StatusCode

int32_t RTC_start(RTC_Handle handle)

Start the RTC after it’s stopped.

Parameters:

handle – [IN] RTC_Handle returned from RTC_open()

Returns:

RTC_StatusCode

void RTC_erratumi2327Init(void)

RTC Erratum i2327 Workaround.

Due to a bug in initial synchronization out of cold power on, IRQ status can get locked infinitely if we do not: a) unlock RTC

This workaround must be applied within 1 second of power on, So, this is closest point to be able to guarantee the max timing.

struct RTC_HwAttrs
#include <rtc.h>

RTC Hardware attributes.

Public Members

uint32_t baseAddr

RTC Peripheral base address

uint32_t intNum

RTC Peripheral interrupt vector

uint16_t eventId

RTC Peripheral event id

uint32_t inputClk

RTC input clock

bool enableIntr

Enable Interrupt

uint8_t intrPriority

Interrupt Priority

struct RTC_Params
#include <rtc.h>

RTC Parameters.

RTC parameters are used to with the RTC_open() call. Default values for these parameters are set using RTC_paramsInit().

Public Members

uint32_t isfreezemode

RTC freeze Mode Enabled/Disabled

bool onOffCallback

RTC On Off Callback

bool offOnCallback

RTC Off On Callback

struct RTC_Object
#include <rtc.h>

RTC driver object.

RTC Interrupt Callback Functions

RTC_OnOffCallbackFxn On_OffCallbackFunction

Callback Function Pointer for ON_OFF Interrupt

RTC_OffOnCallbackFxn Off_OnCallbackFunction

Callback Function Pointer for OFF_ON Interrupt

Public Members

SemaphoreP_Object mutex

Grants exclusive access to this RTC Instance

HwiP_Object hwiObj

HwiP object

bool isOpen

Flag to indicate whether the instance is opened already

RTC_Params RTC_params

RTC open parameters as provided by user

struct RTC_Config
#include <rtc.h>

RTC Global Configuration.

The RTC_Config structure contains a set of pointers used to characterise the RTC driver implementation.

This structure needs to be defined before calling RTC_init() and it must not be changed thereafter.

Public Members

RTC_Object *object

Pointer to a driver specific data object

RTC_HwAttrs const *hwAttrs

Pointer to a driver specific hardware attributes structure

struct RTC_Time
#include <rtc.h>

RTC Time Structure.

Public Members

uint32_t second

Time in Seconds

uint32_t minute

Time in minute

uint32_t hour

Time in hour

uint32_t day

Time in day

uint32_t month

Time in month

uint32_t year

Time in year