rtc.c File Reference


Detailed Description

RTC driver for AVR32 UC3.

AVR32 Real Time Counter driver module.

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/

Definition in file rtc.c.

#include "rtc.h"
#include "pm.h"

Include dependency graph for rtc.c:

Go to the source code of this file.

Functions

void rtc_clear_interrupt (volatile avr32_rtc_t *rtc)
 Clear the interruption flag. Call this function once you handled the interruption.
void rtc_disable (volatile avr32_rtc_t *rtc)
 Disable the RTC.
void rtc_disable_interrupt (volatile avr32_rtc_t *rtc)
 Disable the interruption 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 interruption 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.


Function Documentation

void rtc_clear_interrupt ( volatile avr32_rtc_t *  rtc  ) 

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

Parameters:
rtc Base address of the RTC (i.e. &AVR32_RTC).

Definition at line 170 of file rtc.c.

00171 {
00172      rtc->ICR.topi = 1;
00173 }

void rtc_disable ( volatile avr32_rtc_t *  rtc  ) 

Disable the RTC.

Parameters:
rtc Base address of the RTC (i.e. &AVR32_RTC).

Definition at line 146 of file rtc.c.

References rtc_is_busy().

00147 {
00148      int ctrl;
00149 
00150      // Wait until the rtc CTRL register is up to date
00151      while(rtc_is_busy(rtc));
00152      // Read the current configuration
00153      ctrl = rtc->ctrl;
00154      // Disable the RTC
00155      rtc->ctrl = ctrl & (~AVR32_RTC_CTRL_EN_MASK);
00156      // Wait until write is done
00157      while(rtc_is_busy(rtc));
00158 }

Here is the call graph for this function:

void rtc_disable_interrupt ( volatile avr32_rtc_t *  rtc  ) 

Disable the interruption feature of the RTC.

Parameters:
rtc Base address of the RTC (i.e. &AVR32_RTC).

Definition at line 165 of file rtc.c.

00166 {
00167      rtc->IDR.topi = 1;
00168 }

void rtc_disable_wake_up ( volatile avr32_rtc_t *  rtc  ) 

Disable the wake up feature of the RTC.

Parameters:
rtc Base address of the RTC (i.e. &AVR32_RTC).

Definition at line 122 of file rtc.c.

References rtc_is_busy().

Referenced by main().

00123 {
00124      int ctrl;
00125 
00126      // Wait until the rtc CTRL register is up to date
00127      while(rtc_is_busy(rtc));
00128      // Read the current configuration
00129      ctrl = rtc->ctrl;
00130      // Disable the wake up of the RTC
00131      rtc->ctrl = ctrl & (~AVR32_RTC_CTRL_WAKE_EN_MASK);
00132      // Wait until write is done
00133      while(rtc_is_busy(rtc));
00134 }

Here is the call graph for this function:

void rtc_enable ( volatile avr32_rtc_t *  rtc  ) 

Enable the RTC.

Parameters:
rtc Base address of the RTC (i.e. &AVR32_RTC).

Definition at line 136 of file rtc.c.

References rtc_is_busy().

Referenced by main().

00137 {
00138      // Wait until the rtc CTRL register is up to date
00139      while(rtc_is_busy(rtc));
00140      // Enable the RTC
00141      rtc->ctrl |= 1 << AVR32_RTC_CTRL_EN_OFFSET;
00142      // Wait until write is done
00143      while(rtc_is_busy(rtc));
00144 }

Here is the call graph for this function:

void rtc_enable_interrupt ( volatile avr32_rtc_t *  rtc  ) 

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

Parameters:
rtc Base address of the RTC (i.e. &AVR32_RTC).

Definition at line 160 of file rtc.c.

00161 {
00162      rtc->IER.topi = 1;
00163 }

void rtc_enable_wake_up ( volatile avr32_rtc_t *  rtc  ) 

Enable the wake up feature of the RTC.

Parameters:
rtc Base address of the RTC (i.e. &AVR32_RTC).

Definition at line 112 of file rtc.c.

References rtc_is_busy().

Referenced by main().

00113 {
00114      // Wait until the rtc CTRL register is up to date
00115      while(rtc_is_busy(rtc));
00116      // Enable the wake up of the RTC
00117      rtc->ctrl |= 1 << AVR32_RTC_CTRL_WAKE_EN_OFFSET;
00118      // Wait until write is done
00119      while(rtc_is_busy(rtc));
00120 }

Here is the call graph for this function:

unsigned long rtc_get_top_value ( volatile avr32_rtc_t *  rtc  ) 

This function returns the RTC current top value.

Parameters:
rtc Base address of the RTC (i.e. &AVR32_RTC).
Returns:
The RTC current top value.

Definition at line 185 of file rtc.c.

00186 {
00187      return rtc->top;
00188 }

unsigned long rtc_get_value ( volatile avr32_rtc_t *  rtc  ) 

This function returns the RTC current value.

Parameters:
rtc Base address of the RTC (i.e. &AVR32_RTC).
Returns:
The RTC current value.

Definition at line 107 of file rtc.c.

Referenced by main().

00108 {
00109      return rtc->val;
00110 }

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.

Parameters:
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.
Returns:
1 if the initialisation succeds otherwize it will return 0.

Definition at line 54 of file rtc.c.

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

Referenced by main().

00055 {
00056      int ctrl;
00057 
00058      // if we use the 32KHz oscillator, we have to enable it first
00059      if (osc_type == RTC_OSC_32KHZ)
00060      {
00061           // Select the 32 KHz oscillator crystal
00062           pm_enable_osc32_crystal(&AVR32_PM);
00063           // Enable the clock 32 KHz
00064           pm_enable_clk32_no_wait(&AVR32_PM, 0);
00065      }
00066 
00067      // Wait until the rtc CTRL register is up to date
00068      while(rtc_is_busy(rtc));
00069 
00070      // Set the ctrl value to configure the RTC
00071      ctrl =
00072          (((int) osc_type) << AVR32_RTC_CTRL_CLK32_OFFSET)
00073      |   (((int) psel) << AVR32_RTC_CTRL_PSEL_OFFSET)
00074 #ifdef AVR32_RTC_CLKEN
00075      |   AVR32_RTC_CLKEN_MASK
00076 #endif
00077      ;
00078 
00079      // Set the new configuration
00080      rtc->ctrl = ctrl;
00081 
00082      // Wait until write is done
00083      while(rtc_is_busy(rtc));
00084 
00085      // if exit, it means that the configuration has not been set correctly
00086      if (rtc->ctrl != ctrl)
00087           return 0;
00088 
00089      // Set the counter value to 0
00090      rtc_set_value(rtc, 0);
00091      // Set the top value to 0xFFFFFFFF
00092      rtc_set_top_value(rtc, (unsigned long) -1);
00093 
00094      return 1;
00095 }

Here is the call graph for this function:

int rtc_interrupt_enabled ( volatile avr32_rtc_t *  rtc  ) 

Get the status of interrupts.

Parameters:
rtc Base address of the RTC (i.e. &AVR32_RTC).
Returns:
1 if the interrupts are enabled otherwize it returns 0.

Definition at line 190 of file rtc.c.

00191 {
00192      return rtc->IMR.topi;
00193 }

int rtc_is_busy ( volatile avr32_rtc_t *  rtc  ) 

This function checks if the RTC is busy or not.

Parameters:
rtc Base address of the RTC (i.e. &AVR32_RTC).
Returns:
1 if the RTC is busy otherwize it will return 0.

Definition at line 49 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().

00050 {
00051      return rtc->CTRL.busy;
00052 }

int rtc_is_interrupt ( volatile avr32_rtc_t *  rtc  ) 

Check if an interrupt is raised.

Parameters:
rtc Base address of the RTC (i.e. &AVR32_RTC).
Returns:
1 if an interrupt is currently raised otherwize it returns 0.

Definition at line 195 of file rtc.c.

00196 {
00197      return rtc->ISR.topi;
00198 }

void rtc_set_top_value ( volatile avr32_rtc_t *  rtc,
unsigned long  top 
)

This function sets the RTC current top value.

Parameters:
rtc Base address of the RTC (i.e. &AVR32_RTC).
top The top value you want to store.

Definition at line 175 of file rtc.c.

References rtc_is_busy().

Referenced by main(), and rtc_init().

00176 {
00177      // Wait until we can write into the VAL register
00178      while(rtc_is_busy(rtc));
00179      // Set the new val value
00180      rtc->top = top;
00181      // Wait until write is done
00182      while(rtc_is_busy(rtc));
00183 }

Here is the call graph for this function:

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

This function sets the RTC current value.

Parameters:
rtc Base address of the RTC (i.e. &AVR32_RTC).
val The value you want to store.

Definition at line 97 of file rtc.c.

References rtc_is_busy().

Referenced by rtc_init().

00098 {
00099      // Wait until we can write into the VAL register
00100      while(rtc_is_busy(rtc));
00101      // Set the new val value
00102      rtc->val = val;
00103      // Wait until write is done
00104      while(rtc_is_busy(rtc));
00105 }

Here is the call graph for this function:


Generated on Wed May 7 14:40:10 2008 for AVR32114 Using the AVR32 LCD Controller by  doxygen 1.5.3-20071008