$treeview $search $mathjax $extrastylesheet
avr-libc  2.0.0
$projectbrief
$projectbrief
$searchbox

AVR Libc Home Page

AVRs

AVR Libc Development Pages

Main Page

User Manual

Library Reference

FAQ

Example Projects

xmega.h

00001 /* Copyright (c) 2012 Joerg Wunsch
00002    All rights reserved.
00003 
00004    Redistribution and use in source and binary forms, with or without
00005    modification, are permitted provided that the following conditions are met:
00006 
00007    * Redistributions of source code must retain the above copyright
00008      notice, this list of conditions and the following disclaimer.
00009 
00010    * Redistributions in binary form must reproduce the above copyright
00011      notice, this list of conditions and the following disclaimer in
00012      the documentation and/or other materials provided with the
00013      distribution.
00014 
00015    * Neither the name of the copyright holders nor the names of
00016      contributors may be used to endorse or promote products derived
00017      from this software without specific prior written permission.
00018 
00019   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00020   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00021   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00022   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00023   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00024   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00025   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00026   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00027   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00028   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00029   POSSIBILITY OF SUCH DAMAGE. */
00030 
00031 /* $Id$ */
00032 
00033 /*
00034  * This file is included by <avr/io.h> whenever compiling for an Xmega
00035  * device.  It abstracts certain features common to the Xmega device
00036  * families.
00037  */
00038 
00039 #ifndef _AVR_XMEGA_H
00040 #define _AVR_XMEGA_H
00041 
00042 #ifdef __DOXYGEN__
00043 /**
00044  \def _PROTECTED_WRITE
00045  \ingroup avr_io
00046 
00047  Write value \c value to IO register \c reg that is protected through
00048  the Xmega configuration change protection (CCP) mechanism.  This
00049  implements the timed sequence that is required for CCP.
00050 
00051  Example to modify the CPU clock:
00052  \code
00053  #include <avr/io.h>
00054 
00055  _PROTECTED_WRITE(CLK_PSCTRL, CLK_PSADIV0_bm);
00056  _PROTECTED_WRITE(CLK_CTRL, CLK_SCLKSEL0_bm);
00057  \endcode
00058  */
00059 #define _PROTECTED_WRITE(reg, value)
00060 
00061 /**
00062  \def _PROTECTED_WRITE_SPM
00063  \ingroup avr_io
00064 
00065  Write value \c value to register \c reg that is protected through
00066  the Xmega configuration change protection (CCP) key for self
00067  programming (SPM).  This implements the timed sequence that is
00068  required for CCP.
00069 
00070  Example to modify the CPU clock:
00071  \code
00072  #include <avr/io.h>
00073 
00074  _PROTECTED_WRITE_SPM(NVMCTRL_CTRLA, NVMCTRL_CMD_PAGEERASEWRITE_gc);
00075  \endcode
00076  */
00077 #define _PROTECTED_WRITE_SPM(reg, value)
00078 
00079 #else  /* !__DOXYGEN__ */
00080 
00081 #define _PROTECTED_WRITE(reg, value)                \
00082   __asm__ __volatile__("out %[ccp], %[ccp_ioreg]" "\n\t"    \
00083                "sts %[ioreg], %[val]"           \
00084                :                    \
00085                : [ccp] "I" (_SFR_IO_ADDR(CCP)),     \
00086              [ccp_ioreg] "d" ((uint8_t)CCP_IOREG_gc),   \
00087              [ioreg] "n" (_SFR_MEM_ADDR(reg)),  \
00088              [val] "r" ((uint8_t)value))
00089 
00090 #define _PROTECTED_WRITE_SPM(reg, value) \
00091   __asm__ __volatile__("out %[ccp], %[ccp_spm_mask]" "\n\t" \
00092                        "sts %[ioreg], %[val]"               \
00093                        :                                    \
00094                        : [ccp]          "I" (_SFR_IO_ADDR(CCP)), \
00095                          [ccp_spm_mask] "d" ((uint8_t)CCP_SPM_gc), \
00096                          [ioreg]        "n" (_SFR_MEM_ADDR(reg)), \
00097                          [val]          "r" ((uint8_t)value))
00098 #endif /* DOXYGEN */
00099 
00100 #endif /* _AVR_XMEGA_H */
 All Data Structures Files Functions Variables Typedefs Enumerations Defines