pm_uc3c.h File Reference


Detailed Description

Power Manager(PM) driver interface.

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

Definition in file pm_uc3c.h.

#include <avr32/io.h>
#include "compiler.h"

Go to the source code of this file.

Sleep Functions

#define pm_sleep(sleep_mode)   {__asm__ __volatile__ ("sleep "STRINGZ(sleep_mode));}
 Sets the MCU in the specified sleep mode.
#define SLEEP(mode)   pm_sleep(mode)
 Sets the MCU in the specified sleep mode.
__inline__ void pm_asyn_wake_up_disable (unsigned long awen_mask)
 Disable one or several asynchronous wake-up sources.
__inline__ void pm_asyn_wake_up_enable (unsigned long awen_mask)
 Enable one or several asynchronous wake-up source.
__inline__ unsigned long pm_get_wake_cause (void)
 Returns MCU wake cause.

Defines

#define _PM_UC3C_H_
#define PM_NOT_SUPPORTED   (-10000)
 Define "not supported" for the power manager features.
#define PM_POLL_TIMEOUT   100000
 Device-specific data.
#define PM_UNLOCK(reg)   (AVR32_PM.unlock = (unsigned long)(AVR32_PM_UNLOCK_KEY_VALUE << AVR32_PM_UNLOCK_KEY_OFFSET)|(reg))
 Unlock PM register macro.

Functions

Interrupt Functions
__inline__ void pm_clear_interrupt_status (unsigned long mask)
 Clear raised interrupts from the power manager.
__inline__ void pm_disable_interrupts (unsigned long mask)
 Disable power manager interrupts.
__inline__ void pm_enable_interrupts (unsigned long mask)
 Enable power manager interrupts.
__inline__ unsigned long pm_get_enabled_interrupts (void)
 Read the enabled power manager interrupts.
__inline__ unsigned long pm_get_interrupts_status (void)
 Read the interrupts status of the power manager.
Clock Functions
long pm_config_mainclk_safety (bool cfd, bool final)
 Configure the main clock safety mechanisms.
long pm_disable_clk_domain_div (pm_clk_domain_t clock_domain)
 Disable the division ratio for a clock domain.
long pm_set_clk_domain_div (pm_clk_domain_t clock_domain, pm_divratio_t divratio)
 Set the division ratio for a clock domain.
long pm_set_mclk_source (pm_clk_src_t src)
 Set the main clock.
long pm_wait_for_clk_ready (void)
 Wait actively for the clock settings to be effective.
Module Functions
long pm_disable_module (unsigned long module)
 Disable the clock of a module.
long pm_enable_module (unsigned long module)
 Enable the clock of a module.
Reset Functions
__inline__ unsigned long pm_get_reset_cause (void)
 Returns MCU last reset cause.
Misc Functions
__inline__ unsigned long pm_get_status (void)
 Get the PM status.


Define Documentation

#define _PM_UC3C_H_

Definition at line 49 of file pm_uc3c.h.

#define PM_NOT_SUPPORTED   (-10000)

Define "not supported" for the power manager features.

Definition at line 114 of file pm_uc3c.h.

#define PM_POLL_TIMEOUT   100000

Device-specific data.

The timeguard used for polling (expressed in ticks).

Definition at line 111 of file pm_uc3c.h.

Referenced by pm_wait_for_clk_ready().

#define pm_sleep ( sleep_mode   )     {__asm__ __volatile__ ("sleep "STRINGZ(sleep_mode));}

Sets the MCU in the specified sleep mode.

Note:
Precautions should be taken before entering sleep mode. Refer to the datasheet chapter 'Power Manager'.
Parameters:
sleep_mode The sleep mode index

Definition at line 237 of file pm_uc3c.h.

#define PM_UNLOCK ( reg   )     (AVR32_PM.unlock = (unsigned long)(AVR32_PM_UNLOCK_KEY_VALUE << AVR32_PM_UNLOCK_KEY_OFFSET)|(reg))

#define SLEEP ( mode   )     pm_sleep(mode)

Sets the MCU in the specified sleep mode.

Note:
For compatibility with pm.h
Parameters:
mode The sleep mode index

Definition at line 245 of file pm_uc3c.h.


Function Documentation

__inline__ void pm_asyn_wake_up_disable ( unsigned long  awen_mask  ) 

Disable one or several asynchronous wake-up sources.

Parameters:
awen_mask Mask of asynchronous wake-up sources (use one of the defines AVR32_PM_AWEN_xxxxWEN_MASK in the part-specific header file under "toolchain folder"/avr32/inc(lude)/avr32/)

Definition at line 283 of file pm_uc3c.h.

00284 {
00285   AVR32_PM.awen &= ~awen_mask;
00286 }

__inline__ void pm_asyn_wake_up_enable ( unsigned long  awen_mask  ) 

Enable one or several asynchronous wake-up source.

Parameters:
awen_mask Mask of asynchronous wake-up sources (use one of the defines AVR32_PM_AWEN_xxxxWEN_MASK in the part-specific header file under "toolchain folder"/avr32/inc(lude)/avr32/)

Definition at line 269 of file pm_uc3c.h.

00270 {
00271   AVR32_PM.awen |= awen_mask;
00272 }

__inline__ void pm_clear_interrupt_status ( unsigned long  mask  ) 

Clear raised interrupts from the power manager.

Parameters:
mask The interrupts to clear.

Definition at line 374 of file pm_uc3c.h.

00375 {
00376   AVR32_PM.icr |= mask;
00377 }

long pm_config_mainclk_safety ( bool  cfd,
bool  final 
)

Configure the main clock safety mechanisms.

Note:
Refer to the section Clock Failure Detector of the PM chapter in the datasheet
Warning:
The Critical Path Oscillator (CRIPOSC) must be enabled before enabling the Over Clock Protection mechanism.
Parameters:
cfd Enable/disable the Clock Failure Detection mechanism
final If true, make this configuration definitive
Returns:
Status.
Return values:
=0 Success.
<0 An error occured.

Definition at line 108 of file pm_uc3c.c.

References u_avr32_pm_cfdctrl_t::cfdctrl, u_avr32_pm_cfdctrl_t::CFDCTRL, and PM_UNLOCK.

00109 {
00110   u_avr32_pm_cfdctrl_t u_avr32_pm_cfdctrl = {AVR32_PM.cfdctrl};
00111 
00112   // Check if the CFDCTRL register is read-only.
00113   if(AVR32_PM.cfdctrl & AVR32_PM_CFDCTRL_SFV_MASK)
00114     return -1;
00115 
00116   // Unlock the write-protected CFDCTRL register
00117   AVR32_ENTER_CRITICAL_REGION( );
00118   // Modify
00119   u_avr32_pm_cfdctrl.CFDCTRL.cfden = cfd;
00120   u_avr32_pm_cfdctrl.CFDCTRL.sfv = final;
00121   // Write back
00122   PM_UNLOCK(AVR32_PM_CFDCTRL);  
00123   AVR32_PM.cfdctrl = u_avr32_pm_cfdctrl.cfdctrl;
00124   AVR32_LEAVE_CRITICAL_REGION( );
00125   
00126   return PASS;
00127 }

long pm_disable_clk_domain_div ( pm_clk_domain_t  clock_domain  ) 

Disable the division ratio for a clock domain.

Parameters:
clock_domain The clock domain to alter.
Warning:
Care should be taken that each new frequency of the synchronous clocks does not exceed the maximum frequency for each clock domain.
Returns:
Status.
Return values:
=0 Success.
<0 An error occured.

Definition at line 162 of file pm_uc3c.c.

00163 {
00164   u_avr32_pm_cpusel_t u_avr32_pm_cpusel = {AVR32_PM.cpusel};
00165 
00166 //# Implementation note: the CPUSEL and PBASEL and PBBSEL and PBCSEL registers all have the
00167 //# same structure.
00168 
00169 //# Implementation note: the ckSEL registers are contiguous and memory-mapped in
00170 //# that order: CPUSEL, HSBSEL, PBASEL, PBBSEL, PBCSEL.
00171 
00172   // ckSEL must not be written while SR.CKRDY is 0.
00173   if(!(AVR32_PM.sr & AVR32_PM_SR_CKRDY_MASK))
00174     return -1;
00175 
00176   // Modify
00177   u_avr32_pm_cpusel.CPUSEL.cpudiv= DISABLE;
00178   AVR32_ENTER_CRITICAL_REGION( );
00179   // Unlock the write-protected ckSEL register
00180   PM_UNLOCK(AVR32_PM_CPUSEL + clock_domain*sizeof(avr32_pm_cpusel_t));
00181   // Update
00182   *(&(AVR32_PM.cpusel) + clock_domain)= u_avr32_pm_cpusel.cpusel;
00183   AVR32_LEAVE_CRITICAL_REGION( );
00184 
00185   return PASS;
00186 }

__inline__ void pm_disable_interrupts ( unsigned long  mask  ) 

Disable power manager interrupts.

Parameters:
mask the interrupts to disable.

Definition at line 338 of file pm_uc3c.h.

00339 {
00340   AVR32_PM.idr |= mask;
00341 }

long pm_disable_module ( unsigned long  module  ) 

Disable the clock of a module.

Parameters:
module The module to shut down (use one of the defines in the part-specific header file under "toolchain folder"/avr32/inc(lude)/avr32/; depending on the clock domain, look for the sections "CPU clocks", "HSB clocks", "PBx clocks")
Returns:
Status.
Return values:
0 Success.
<0 An error occured.

Definition at line 228 of file pm_uc3c.c.

00229 {
00230   unsigned long domain = module>>5;
00231 //# Implementation note: the ckMASK registers are contiguous and memory-mapped
00232 //# in that order: CPUMASK, HSBMASK, PBAMASK, PBBMASK.
00233   volatile unsigned long *regptr = (volatile unsigned long*)(&(AVR32_PM.cpumask) + domain);
00234   unsigned long regvalue;
00235 
00236 
00237   // Read
00238   regvalue = *regptr;
00239   // Modify
00240   regvalue &= ~(1<<(module%32));
00241   AVR32_ENTER_CRITICAL_REGION( );
00242   // Unlock the write-protected ckMASK register
00243   PM_UNLOCK(AVR32_PM_CPUMASK + domain*sizeof(avr32_pm_cpumask_t));
00244   // Write
00245   *regptr = regvalue;
00246   AVR32_LEAVE_CRITICAL_REGION( );
00247 
00248   return PASS;
00249 }

__inline__ void pm_enable_interrupts ( unsigned long  mask  ) 

Enable power manager interrupts.

Parameters:
mask the interrupts to enable.

Definition at line 325 of file pm_uc3c.h.

00326 {
00327   AVR32_PM.ier |= mask;
00328 }

long pm_enable_module ( unsigned long  module  ) 

Enable the clock of a module.

Parameters:
module The module to clock (use one of the defines in the part-specific header file under "toolchain folder"/avr32/inc(lude)/avr32/; depending on the clock domain, look for the sections "CPU clocks", "HSB clocks", "PBx clocks")
Returns:
Status.
Return values:
0 Success.
<0 An error occured.

Definition at line 205 of file pm_uc3c.c.

00206 {
00207   unsigned long domain = module>>5;
00208 //# Implementation note: the ckMASK registers are contiguous and memory-mapped
00209 //# in that order: CPUMASK, HSBMASK, PBAMASK, PBBMASK.
00210   unsigned long *regptr = (unsigned long*)(&(AVR32_PM.cpumask) + domain);  
00211   unsigned long regvalue;
00212 
00213 
00214   // Read
00215   regvalue = *regptr;
00216   // Modify
00217   regvalue |= (1<<(module%32));
00218   AVR32_ENTER_CRITICAL_REGION( );
00219   // Unlock the write-protected ckMASK register
00220   PM_UNLOCK(AVR32_PM_CPUMASK + domain*sizeof(avr32_pm_cpumask_t));
00221   // Write
00222   *regptr = regvalue;
00223   AVR32_LEAVE_CRITICAL_REGION( );
00224 
00225   return PASS;
00226 }

__inline__ unsigned long pm_get_enabled_interrupts ( void   ) 

Read the enabled power manager interrupts.

Returns:
mask of the enabled interrupts.

Definition at line 350 of file pm_uc3c.h.

00351 {
00352   return(AVR32_PM.imr);
00353 }

__inline__ unsigned long pm_get_interrupts_status ( void   ) 

Read the interrupts status of the power manager.

Returns:
mask of the interrupts that have been triggered.

Definition at line 362 of file pm_uc3c.h.

00363 {
00364   return(AVR32_PM.isr);
00365 }

__inline__ unsigned long pm_get_reset_cause ( void   ) 

Returns MCU last reset cause.

Returns:
The MCU last reset cause which can be masked with the AVR32_PM_RCAUSE_x_MASK bit-masks to isolate specific causes.

Definition at line 304 of file pm_uc3c.h.

00305 {
00306   return AVR32_PM.rcause;
00307 }

__inline__ unsigned long pm_get_status ( void   ) 

Get the PM status.

Returns:
The content of the PM Status register.

Definition at line 394 of file pm_uc3c.h.

00395 {
00396   return AVR32_PM.sr;
00397 }

__inline__ unsigned long pm_get_wake_cause ( void   ) 

Returns MCU wake cause.

Returns:
The MCU wake cause which can be masked with the AVR32_PM_WCAUSE_x_MASK bit-masks to isolate specific causes.

Definition at line 255 of file pm_uc3c.h.

00256 {
00257   return AVR32_PM.wcause;
00258 }

long pm_set_clk_domain_div ( pm_clk_domain_t  clock_domain,
pm_divratio_t  divratio 
)

Set the division ratio for a clock domain.

Parameters:
clock_domain The clock domain to alter.
divratio The division ratio to set.
Warning:
Care should be taken that each new frequency of the synchronous clocks does not exceed the maximum frequency for each clock domain.
Returns:
Status.
Return values:
=0 Success.
<0 An error occured.

Definition at line 129 of file pm_uc3c.c.

00130 {
00131   u_avr32_pm_cpusel_t u_avr32_pm_cpusel = {AVR32_PM.cpusel};
00132 
00133 //# Implementation note: the CPUSEL and PBASEL and PBBSEL registers all have the
00134 //# same structure.
00135 
00136 //# Implementation note: the ckSEL registers are contiguous and memory-mapped in
00137 //# that order: CPUSEL, HSBSEL, PBASEL, PBBSEL.
00138   
00139 #ifdef AVR32SFW_INPUT_CHECK
00140   // Check the divratio
00141   if((divratio > PM_CPUSEL_DIVRATIO_MAX)||(divratio < 0))
00142     return -1;
00143 #endif
00144 
00145   // ckSEL must not be written while SR.CKRDY is 0.
00146   if(!(AVR32_PM.sr & AVR32_PM_SR_CKRDY_MASK))
00147     return -1;
00148 
00149   // Modify
00150   u_avr32_pm_cpusel.CPUSEL.cpudiv= 1;
00151   u_avr32_pm_cpusel.CPUSEL.cpusel = divratio;
00152   AVR32_ENTER_CRITICAL_REGION( );
00153   // Unlock the write-protected ckSEL register
00154   PM_UNLOCK(AVR32_PM_CPUSEL + clock_domain*sizeof(avr32_pm_cpusel_t));
00155   // Update
00156   *(&(AVR32_PM.cpusel) + clock_domain)= u_avr32_pm_cpusel.cpusel;
00157   AVR32_LEAVE_CRITICAL_REGION( );
00158 
00159   return PASS;
00160 }

long pm_set_mclk_source ( pm_clk_src_t  src  ) 

Set the main clock.

Parameters:
src The clock to use as the main clock.
Warning:
The input clock to use as the main clock must be enabled before calling this function, otherwise a deadlock will occur.
Returns:
Status.
Return values:
0 Success.
<0 An error occured when trying to set the main clock.

Definition at line 97 of file pm_uc3c.c.

00098 {
00099   // Unlock the write-protected MCCTRL register
00100   AVR32_ENTER_CRITICAL_REGION( );
00101   PM_UNLOCK(AVR32_PM_MCCTRL);
00102   AVR32_PM.mcctrl = src;
00103   AVR32_LEAVE_CRITICAL_REGION( );
00104   
00105   return PASS;
00106 }

long pm_wait_for_clk_ready ( void   ) 

Wait actively for the clock settings to be effective.

Note:
To avoid an infinite loop, this function checks the clock ready flag PM_POLL_TIMEOUT times.
Returns:
Status.
Return values:
0 Success.
<0 Unable to reach a clock ready status within the polling limit.

Definition at line 188 of file pm_uc3c.c.

00189 {
00190   unsigned int timeout = PM_POLL_TIMEOUT;
00191   while (!(AVR32_PM.sr & AVR32_PM_SR_CKRDY_MASK))
00192   {
00193     if(--timeout == 0)
00194       return -1;
00195   }
00196   return PASS;
00197 }


Generated on Thu Dec 17 19:58:59 2009 for AVR32 UC3 - Power Manager Driver Example 1 by  doxygen 1.5.5