Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
RTC - Real Time Counter

Driver for the RTC (32-bit Real Time Counter).

The RTC enables periodic interrupts at long intervals, or accurate measurement of real-time sequences. Can be clocked from internal RC oscillator or external 32 kHz crystal.

Functions

void rtc_clear_interrupt (volatile avr32_rtc_t *rtc)
 Clear the interrupt flag. Call this function once you handled the interrupt. More...
 
void rtc_disable (volatile avr32_rtc_t *rtc)
 Disable the RTC. More...
 
void rtc_disable_interrupt (volatile avr32_rtc_t *rtc)
 Disable the interrupt feature of the RTC. More...
 
void rtc_disable_wake_up (volatile avr32_rtc_t *rtc)
 Disable the wake up feature of the RTC. More...
 
void rtc_enable (volatile avr32_rtc_t *rtc)
 Enable the RTC. More...
 
void rtc_enable_interrupt (volatile avr32_rtc_t *rtc)
 Enable the interrupt feature of the RTC. An interrupt is raised when the value of the RTC is equal to its top value. More...
 
void rtc_enable_wake_up (volatile avr32_rtc_t *rtc)
 Enable the wake up feature of the RTC. More...
 
unsigned long rtc_get_top_value (volatile avr32_rtc_t *rtc)
 This function returns the RTC current top value. More...
 
unsigned long rtc_get_value (volatile avr32_rtc_t *rtc)
 This function returns the RTC current value. More...
 
int rtc_init (volatile avr32_rtc_t *rtc, unsigned char osc_type, unsigned char psel)
 This function will initialize the RTC module. If you use the 32 KHz oscillator, it will enable this module. This function also set the top value of the RTC to 0xFFFFFFFF and the value to 0. More...
 
int rtc_interrupt_enabled (volatile avr32_rtc_t *rtc)
 Get the status of interrupts. More...
 
int rtc_is_busy (volatile avr32_rtc_t *rtc)
 This function checks if the RTC is busy or not. More...
 
int rtc_is_interrupt (volatile avr32_rtc_t *rtc)
 Check if an interrupt is raised. More...
 
void rtc_set_top_value (volatile avr32_rtc_t *rtc, unsigned long top)
 This function sets the RTC current top value. More...
 
void rtc_set_value (volatile avr32_rtc_t *rtc, unsigned long val)
 This function sets the RTC current value. More...
 

Oscillator Types

#define RTC_OSC_32KHZ   1
 
#define RTC_OSC_RC   0
 

Predefined PSEL Values

#define RTC_PSEL_32KHZ_1HZ   14
 The PSEL value to set the RTC source clock (after the prescaler) to 1 Hz, when using an external 32-kHz crystal. More...
 
#define RTC_PSEL_RC_1_76HZ   15
 The PSEL value to set the RTC source clock (after the prescaler) to 1.76 Hz, when using the internal RC oscillator (~ 115 kHz). More...
 

#define RTC_OSC_32KHZ   1

Referenced by rtc_init().

#define RTC_OSC_RC   0

Referenced by ui_display_init_rtc().

#define RTC_PSEL_32KHZ_1HZ   14

The PSEL value to set the RTC source clock (after the prescaler) to 1 Hz, when using an external 32-kHz crystal.

#define RTC_PSEL_RC_1_76HZ   15

The PSEL value to set the RTC source clock (after the prescaler) to 1.76 Hz, when using the internal RC oscillator (~ 115 kHz).

Referenced by ui_display_init_rtc().

void rtc_clear_interrupt ( volatile avr32_rtc_t *  rtc)

Clear the interrupt flag. Call this function once you handled the interrupt.

Parameters
rtcBase address of the RTC (i.e. &AVR32_RTC).

References cpu_irq_disable, cpu_irq_enable, and cpu_irq_is_enabled.

Referenced by ISR().

void rtc_disable ( volatile avr32_rtc_t *  rtc)

Disable the RTC.

Parameters
rtcBase address of the RTC (i.e. &AVR32_RTC).

References rtc_is_busy().

Referenced by ui_display_disable_rtc().

void rtc_disable_interrupt ( volatile avr32_rtc_t *  rtc)

Disable the interrupt feature of the RTC.

Parameters
rtcBase address of the RTC (i.e. &AVR32_RTC).

References cpu_irq_disable, cpu_irq_enable, and cpu_irq_is_enabled.

Referenced by ui_display_disable_rtc().

void rtc_disable_wake_up ( volatile avr32_rtc_t *  rtc)

Disable the wake up feature of the RTC.

Parameters
rtcBase address of the RTC (i.e. &AVR32_RTC).

References rtc_is_busy().

void rtc_enable ( volatile avr32_rtc_t *  rtc)

Enable the RTC.

Parameters
rtcBase address of the RTC (i.e. &AVR32_RTC).

References rtc_is_busy().

Referenced by ui_display_init_rtc().

void rtc_enable_interrupt ( volatile avr32_rtc_t *  rtc)

Enable the interrupt feature of the RTC. An interrupt is raised when the value of the RTC is equal to its top value.

Parameters
rtcBase address of the RTC (i.e. &AVR32_RTC).

Referenced by ui_display_init_rtc().

void rtc_enable_wake_up ( volatile avr32_rtc_t *  rtc)

Enable the wake up feature of the RTC.

Parameters
rtcBase address of the RTC (i.e. &AVR32_RTC).

References rtc_is_busy().

Referenced by ui_display_init_rtc().

unsigned long rtc_get_top_value ( volatile avr32_rtc_t *  rtc)

This function returns the RTC current top value.

Parameters
rtcBase address of the RTC (i.e. &AVR32_RTC).
Returns
The RTC current top value.
unsigned long rtc_get_value ( volatile avr32_rtc_t *  rtc)

This function returns the RTC current value.

Parameters
rtcBase address of the RTC (i.e. &AVR32_RTC).
Returns
The RTC current value.
int rtc_init ( volatile avr32_rtc_t *  rtc,
unsigned char  osc_type,
unsigned char  psel 
)

This function will initialize the RTC module. If you use the 32 KHz oscillator, it will enable this module. This function also set the top value of the RTC to 0xFFFFFFFF and the value to 0.

Parameters
rtcBase address of the RTC (i.e. &AVR32_RTC).
osc_typeThe oscillator you want to use. If you need a better accuracy, use the 32 KHz oscillator (i.e. RTC_OSC_32KHZ).
pselThe preselector value for the corresponding oscillator (4-bits). To obtain this value, you can use this formula: psel = log(Fosc/Frtc)/log(2)-1, where Fosc is the frequency of the oscillator you are using (32 KHz or 115 KHz) and Frtc the frequency desired.
Returns
1 if the initialization succeeds otherwise it will return 0.

References pm_enable_clk32(), pm_enable_osc32_crystal(), rtc_is_busy(), RTC_OSC_32KHZ, rtc_set_top_value(), and rtc_set_value().

Referenced by ui_display_init_rtc().

int rtc_interrupt_enabled ( volatile avr32_rtc_t *  rtc)

Get the status of interrupts.

Parameters
rtcBase address of the RTC (i.e. &AVR32_RTC).
Returns
1 if the interrupts are enabled otherwise it returns 0.
int rtc_is_busy ( volatile avr32_rtc_t *  rtc)

This function checks if the RTC is busy or not.

Parameters
rtcBase address of the RTC (i.e. &AVR32_RTC).
Returns
1 if the RTC is busy otherwise it will return 0.

Referenced by rtc_disable(), rtc_disable_wake_up(), rtc_enable(), rtc_enable_wake_up(), rtc_init(), rtc_set_top_value(), and rtc_set_value().

int rtc_is_interrupt ( volatile avr32_rtc_t *  rtc)

Check if an interrupt is raised.

Parameters
rtcBase address of the RTC (i.e. &AVR32_RTC).
Returns
1 if an interrupt is currently raised otherwise it returns 0.
void rtc_set_top_value ( volatile avr32_rtc_t *  rtc,
unsigned long  top 
)

This function sets the RTC current top value.

Parameters
rtcBase address of the RTC (i.e. &AVR32_RTC).
topThe top value you want to store.

References rtc_is_busy().

Referenced by rtc_init(), and ui_display_init_rtc().

void rtc_set_value ( volatile avr32_rtc_t *  rtc,
unsigned long  val 
)

This function sets the RTC current value.

Parameters
rtcBase address of the RTC (i.e. &AVR32_RTC).
valThe value you want to store.

References rtc_is_busy().

Referenced by rtc_init().