AVR32 Real Time Counter driver module.
Definition in file rtc.c.
#include <avr32/io.h>
#include "compiler.h"
#include "pm.h"
#include "rtc.h"
Go to the source code of this file.
Functions | |
void | rtc_clear_interrupt (volatile avr32_rtc_t *rtc) |
Clear the interrupt flag. Call this function once you handled the interrupt. | |
void | rtc_disable (volatile avr32_rtc_t *rtc) |
Disable the RTC. | |
void | rtc_disable_interrupt (volatile avr32_rtc_t *rtc) |
Disable the interrupt feature of the RTC. | |
void | rtc_disable_wake_up (volatile avr32_rtc_t *rtc) |
Disable the wake up feature of the RTC. | |
void | rtc_enable (volatile avr32_rtc_t *rtc) |
Enable the 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. | |
void | rtc_enable_wake_up (volatile avr32_rtc_t *rtc) |
Enable the wake up feature of the RTC. | |
unsigned long | rtc_get_top_value (volatile avr32_rtc_t *rtc) |
This function returns the RTC current top value. | |
unsigned long | rtc_get_value (volatile avr32_rtc_t *rtc) |
This function returns the RTC current value. | |
int | rtc_init (volatile avr32_rtc_t *rtc, unsigned char osc_type, unsigned char psel) |
This function will initialise 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. | |
int | rtc_interrupt_enabled (volatile avr32_rtc_t *rtc) |
Get the status of interrupts. | |
int | rtc_is_busy (volatile avr32_rtc_t *rtc) |
This function checks if the RTC is busy or not. | |
int | rtc_is_interrupt (volatile avr32_rtc_t *rtc) |
Check if an interrupt is raised. | |
void | rtc_set_top_value (volatile avr32_rtc_t *rtc, unsigned long top) |
This function sets the RTC current top value. | |
void | rtc_set_value (volatile avr32_rtc_t *rtc, unsigned long val) |
This function sets the RTC current value. |
void rtc_clear_interrupt | ( | volatile avr32_rtc_t * | rtc | ) |
Clear the interrupt flag. Call this function once you handled the interrupt.
rtc | Base address of the RTC (i.e. &AVR32_RTC). |
Definition at line 174 of file rtc.c.
Referenced by rtc_irq().
00175 { 00176 Bool global_interrupt_enabled = Is_global_interrupt_enabled(); 00177 00178 if (global_interrupt_enabled) Disable_global_interrupt(); 00179 rtc->icr = AVR32_RTC_ICR_TOPI_MASK; 00180 rtc->isr; 00181 if (global_interrupt_enabled) Enable_global_interrupt(); 00182 }
void rtc_disable | ( | volatile avr32_rtc_t * | rtc | ) |
Disable the RTC.
rtc | Base address of the RTC (i.e. &AVR32_RTC). |
Definition at line 146 of file rtc.c.
References rtc_is_busy().
00147 { 00148 // Wait until the rtc CTRL register is up-to-date 00149 while (rtc_is_busy(rtc)); 00150 // Disable the RTC 00151 rtc->ctrl &= ~AVR32_RTC_CTRL_EN_MASK; 00152 // Wait until write is done 00153 while (rtc_is_busy(rtc)); 00154 }
void rtc_disable_interrupt | ( | volatile avr32_rtc_t * | rtc | ) |
Disable the interrupt feature of the RTC.
rtc | Base address of the RTC (i.e. &AVR32_RTC). |
Definition at line 163 of file rtc.c.
00164 { 00165 Bool global_interrupt_enabled = Is_global_interrupt_enabled(); 00166 00167 if (global_interrupt_enabled) Disable_global_interrupt(); 00168 rtc->idr = AVR32_RTC_IDR_TOPI_MASK; 00169 rtc->imr; 00170 if (global_interrupt_enabled) Enable_global_interrupt(); 00171 }
void rtc_disable_wake_up | ( | volatile avr32_rtc_t * | rtc | ) |
Disable the wake up feature of the RTC.
rtc | Base address of the RTC (i.e. &AVR32_RTC). |
Definition at line 124 of file rtc.c.
References rtc_is_busy().
00125 { 00126 // Wait until the rtc CTRL register is up-to-date 00127 while (rtc_is_busy(rtc)); 00128 // Disable the wake up of the RTC 00129 rtc->ctrl &= ~AVR32_RTC_CTRL_WAKE_EN_MASK; 00130 // Wait until write is done 00131 while (rtc_is_busy(rtc)); 00132 }
void rtc_enable | ( | volatile avr32_rtc_t * | rtc | ) |
Enable the RTC.
rtc | Base address of the RTC (i.e. &AVR32_RTC). |
Definition at line 135 of file rtc.c.
References rtc_is_busy().
Referenced by main().
00136 { 00137 // Wait until the rtc CTRL register is up-to-date 00138 while (rtc_is_busy(rtc)); 00139 // Enable the RTC 00140 rtc->ctrl |= AVR32_RTC_CTRL_EN_MASK; 00141 // Wait until write is done 00142 while (rtc_is_busy(rtc)); 00143 }
void rtc_enable_interrupt | ( | volatile avr32_rtc_t * | rtc | ) |
void rtc_enable_wake_up | ( | volatile avr32_rtc_t * | rtc | ) |
Enable the wake up feature of the RTC.
rtc | Base address of the RTC (i.e. &AVR32_RTC). |
Definition at line 113 of file rtc.c.
References rtc_is_busy().
00114 { 00115 // Wait until the rtc CTRL register is up-to-date 00116 while (rtc_is_busy(rtc)); 00117 // Enable the wake up of the RTC 00118 rtc->ctrl |= AVR32_RTC_CTRL_WAKE_EN_MASK; 00119 // Wait until write is done 00120 while (rtc_is_busy(rtc)); 00121 }
unsigned long rtc_get_top_value | ( | volatile avr32_rtc_t * | rtc | ) |
unsigned long rtc_get_value | ( | volatile avr32_rtc_t * | rtc | ) |
int rtc_init | ( | volatile avr32_rtc_t * | rtc, | |
unsigned char | osc_type, | |||
unsigned char | psel | |||
) |
This function will initialise 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.
rtc | Base address of the RTC (i.e. &AVR32_RTC). | |
osc_type | The oscillator you want to use. If you need a better accuracy, use the 32 KHz oscillator (i.e. RTC_OSC_32KHZ). | |
psel | The 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. |
Definition at line 60 of file rtc.c.
References rtc_is_busy(), RTC_OSC_32KHZ, rtc_set_top_value(), and rtc_set_value().
Referenced by main().
00061 { 00062 // If exit, it means that the configuration has not been set correctly 00063 if (osc_type > (1 << AVR32_RTC_CTRL_CLK32_SIZE) - 1 || 00064 psel > (1 << AVR32_RTC_CTRL_PSEL_SIZE) - 1) 00065 return 0; 00066 00067 // If we use the 32-kHz oscillator, we have to enable it first 00068 if (osc_type == RTC_OSC_32KHZ) 00069 { 00070 // Select the 32-kHz oscillator crystal 00071 pm_enable_osc32_crystal(&AVR32_PM); 00072 // Enable the 32-kHz clock 00073 pm_enable_clk32_no_wait(&AVR32_PM, AVR32_PM_OSCCTRL32_STARTUP_0_RCOSC); 00074 } 00075 00076 // Wait until the rtc CTRL register is up-to-date 00077 while (rtc_is_busy(rtc)); 00078 00079 // Set the new RTC configuration 00080 rtc->ctrl = osc_type << AVR32_RTC_CTRL_CLK32_OFFSET | 00081 psel << AVR32_RTC_CTRL_PSEL_OFFSET | 00082 AVR32_RTC_CTRL_CLKEN_MASK; 00083 00084 // Wait until write is done 00085 while (rtc_is_busy(rtc)); 00086 00087 // Set the counter value to 0 00088 rtc_set_value(rtc, 0x00000000); 00089 // Set the top value to 0xFFFFFFFF 00090 rtc_set_top_value(rtc, 0xFFFFFFFF); 00091 00092 return 1; 00093 }
int rtc_interrupt_enabled | ( | volatile avr32_rtc_t * | rtc | ) |
int rtc_is_busy | ( | volatile avr32_rtc_t * | rtc | ) |
This function checks if the RTC is busy or not.
rtc | Base address of the RTC (i.e. &AVR32_RTC). |
Definition at line 54 of file rtc.c.
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 | ) |
void rtc_set_top_value | ( | volatile avr32_rtc_t * | rtc, | |
unsigned long | top | |||
) |
This function sets the RTC current top value.
rtc | Base address of the RTC (i.e. &AVR32_RTC). | |
top | The top value you want to store. |
Definition at line 185 of file rtc.c.
References rtc_is_busy().
Referenced by main(), and rtc_init().
00186 { 00187 // Wait until we can write into the VAL register 00188 while (rtc_is_busy(rtc)); 00189 // Set the new val value 00190 rtc->top = top; 00191 // Wait until write is done 00192 while (rtc_is_busy(rtc)); 00193 }
void rtc_set_value | ( | volatile avr32_rtc_t * | rtc, | |
unsigned long | val | |||
) |
This function sets the RTC current value.
rtc | Base address of the RTC (i.e. &AVR32_RTC). | |
val | The value you want to store. |
Definition at line 96 of file rtc.c.
References rtc_is_busy().
Referenced by rtc_init().
00097 { 00098 // Wait until we can write into the VAL register 00099 while (rtc_is_busy(rtc)); 00100 // Set the new val value 00101 rtc->val = val; 00102 // Wait until write is done 00103 while (rtc_is_busy(rtc)); 00104 }