Enumerations | Functions

Real-time clock (hal_rtc)
[nRF24LE1 HAL]


The real-time clock is a configurable, linear, 16-bit real time clock with capture and compare capabilities. The input clock frequency is 32 KHz. This module contains functions for initializing, configuring and controlling the real-time clock.

Enumerations

enum  hal_rtc_compare_mode_t { HAL_RTC_COMPARE_MODE_DISABLE = 0x00, HAL_RTC_COMPARE_MODE_1 = 0x02, HAL_RTC_COMPARE_MODE_0 = 0x03 }

Functions

void hal_rtc_capture (void)
void hal_rtc_radio_capture_enable (_Bool en)
void hal_rtc_set_compare_mode (hal_rtc_compare_mode_t mode)
void hal_rtc_start (_Bool en)
void hal_rtc_set_compare_value (uint16_t value)
uint16_t hal_rtc_get_compare_value (void)
uint16_t hal_rtc_get_capture_value (void)
uint8_t hal_rtc_get_capture_clock_cycles (void)

Enumeration Type Documentation

An enum describing the clock frequency.

Enumerator:
HAL_RTC_COMPARE_MODE_DISABLE 

Compare disabled

HAL_RTC_COMPARE_MODE_1 

Interrupt will not reset the timer

HAL_RTC_COMPARE_MODE_0 

The interrupt resets the timer

Definition at line 34 of file hal_rtc.h.


Function Documentation

void hal_rtc_capture ( void   )

Function that captures the current RCT2 value.

< The value of bit 4

Definition at line 22 of file hal_rtc.c.

{
  RTC2CON |= BIT_4;                         // Set "sfrCapture" bit(Trig. sig.)
}
void hal_rtc_radio_capture_enable ( _Bool  en )

Function that enables the timer value to be captured by an IRQ from the Radio

Parameters:
enTrue to enable, false to disable capture by radio

< The value of bit 3

< The value of bit 3

Definition at line 27 of file hal_rtc.c.

{
  if(en)
  {
    RTC2CON |= BIT_3;                       // Set "enableExtCapture" bit
  }
  else
  {
    RTC2CON &= ~BIT_3;                      // Clear "enableExtCapture" bit
  }
}
void hal_rtc_set_compare_mode ( hal_rtc_compare_mode_t  mode )

Function that sets the compare mode of RTC2.

Parameters:
modeCompare mode

Definition at line 39 of file hal_rtc.c.

{
  RTC2CON = (RTC2CON & 0xF9) | ((mode << 1) & ~0xF9); // Set "compareMode" bits
}
void hal_rtc_start ( _Bool  en )

Function that enables RTC2.

Remarks:
Remember to enable the low frequency clock before use
Parameters:
enTrue to enable, false to disable rtc

< The value of bit 0

< The value of bit 0

Definition at line 44 of file hal_rtc.c.

{
  if(en)
  { 
    RTC2CON |= BIT_0;                       // Set "rtc2Enable" bit
  }
  else
  {
    RTC2CON &= ~BIT_0;                      // Clear "rtc2Enable" bit
  }
}
void hal_rtc_set_compare_value ( uint16_t  value )

Function that sets the value to be compared to the timer value to generate interrupt.

Parameters:
valueComparing value

< The value of bit 1

< The value of bit 2

< The value of bit 1

< The value of bit 2

Definition at line 56 of file hal_rtc.c.

{
  uint8_t compare_status;                   
  compare_status = (RTC2CON & (BIT_1 | BIT_2)); // Save "compareMode" bits
  RTC2CON &= ~(BIT_1 | BIT_2);              // Disable compare
  RTC2CMP0 = LSB(value);                    // Write LSB
  RTC2CMP1 = MSB(value);                    // Write MSB
  RTC2CON |= compare_status;                // Update compare status 
}
uint16_t hal_rtc_get_compare_value ( void   )

Function that returns the compare value

Returns:
Compare value

< The value of bit 1

< The value of bit 2

< The value of bit 1

< The value of bit 2

Definition at line 66 of file hal_rtc.c.

{
  uint8_t compare_status;  
  uint16_t value;                           // Create temporary output variable
  compare_status = (RTC2CON & (BIT_1 | BIT_2)); // Save "compareMode" bits
  RTC2CON &= ~(BIT_1 | BIT_2);              // Disable compare
  value = RTC2CMP1;                         // Read MSB
  value <<= 8;                              // Shift to correct position
  value |= RTC2CMP0;                        // Add LSB
  RTC2CON |= compare_status;                // Update compare status 
  return value;                             // Return compare value
}
uint16_t hal_rtc_get_capture_value ( void   )

Function that returns the timer value.

Returns:
Timer value

< The value of bit 3

< The value of bit 3

Definition at line 79 of file hal_rtc.c.

{
  uint8_t capture_status;                 
  uint16_t value;                           // Create temporary output variable
  capture_status = (RTC2CON & BIT_3);       // Save "compareMode" bits
  RTC2CON &= ~BIT_3;                        // Disable compare
  value = RTC2CPT01;                        // Read MSB
  value <<= 8;                              // Shift to correct position
  value |= RTC2CPT00;                       // Add LSB
  RTC2CON |= capture_status;                // Update external capture status
  return value;                             // Return timer value
}
uint8_t hal_rtc_get_capture_clock_cycles ( void   )

Function that returns the value of the counter that counts the number of CPU clock cycles from the previous positive edge of the 32 KHz clock until the capture event.

Remarks:
External capture should be disabled when reading both capture value and clock cycles
Returns:
Number of CPU clock cycles

Definition at line 92 of file hal_rtc.c.

{
  return RTC2CPT10;                         // Return register
}