atom.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2001-2009 by egnite Software GmbH. 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
00006  * are met:
00007  *
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the copyright holders nor the names of
00014  *    contributors may be used to endorse or promote products derived
00015  *    from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
00018  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00019  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00020  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
00021  * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00022  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00023  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00024  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00025  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00026  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00027  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00028  * SUCH DAMAGE.
00029  *
00030  * For additional information see http://www.ethernut.de/
00031  *
00032  */
00033 
00034 /*
00035  * $Log: atom.h,v $
00036  *
00037  */
00038 
00039 #ifndef _SYS_ATOM_H_
00040 #error "Do not include this file directly. Use sys/atom.h instead!"
00041 #endif
00042 
00043 #if (__GNUC__ && __AVR32__)
00044 
00045 #include <avr32/io.h>
00046 
00047 #if defined(NUT_CRITICAL_NESTING)
00048 
00049 #if defined(NUT_CRITICAL_NESTING_STACK)
00050 
00051 // This doesn't work right now. Not sure how to fix yet.
00052 // but this is unreacheable since critical neasting can't be enabled in the configurator
00053 // for AVR32
00054 #error Not Working
00055 #define NutEnterCritical()               \
00056 {                                        \
00057     register int temp_;                  \
00058     __asm__ volatile (                       \
00059     "mfsr    r10, %[SR]"                "\n\t" \
00060     "pushm   r10"     "\n\t"        \
00061     "ssrf    %[SR_GM_OFFSET]"     "\n\t"        \
00062     : [temp] "=r" (temp_) \
00063     : [SR] "i" (AVR32_SR), \
00064       [SR_GM_OFFSET] "i" (AVR32_SR_GM_OFFSET) \
00065     : "memory", "cc", "r10"); \
00066 }
00067 
00068 #define NutExitCritical() \
00069 { \
00070     register int temp_; \
00071     __asm__ volatile (             \
00072     "popm    r10"                                     "\n\t" \
00073     "andl    r10, LO(%[SR_GM_MASK])"               "\n\t" \
00074     "andh    r10, HI(%[SR_GM_MASK])"               "\n\t" \
00075     "cp.w    r10, 0"                               "\n\t" \
00076     "breq   LABEL_INT_SKIP_ENABLE_INTERRUPTS_%[LINE]" "\n\t" \
00077     "csrf   %[SR_GM_OFFSET]"                          "\n\t" \
00078     "LABEL_INT_SKIP_SAVE_CONTEXT_%[LINE]:"            "\n\t" \
00079     : [temp] "=r" (temp_)                                    \
00080     : [SR_GM_OFFSET] "i" (AVR32_SR_GM_OFFSET),               \
00081       [SR_GM_MASK]   "i" (AVR32_SR_GM_MASK),                 \
00082       [LINE] "i" (__LINE__)                                  \
00083     : "memory", "cc", "r10");                                \
00084 }
00085 
00086 #else /* NUT_CRITICAL_NESTING_STACK */
00087 
00088 // If we ever enable critical nesting, implement me.
00089 #error Not implemented
00090 extern unsigned int critical_nesting_level;
00091 
00092 #define NutEnterCritical()
00093 
00094 #define NutExitCritical()
00095 
00096 #endif /* NUT_CRITICAL_NESTING_STACK */
00097 
00098 #else /* NUT_CRITICAL_NESTING */
00099 
00100 #define NutEnterCritical() \
00101 {                                 \
00102     __asm__ __volatile__ (        \
00103     "ssrf\t%0"      "\n\t"        \
00104     :: "i" (AVR32_SR_GM_OFFSET)); \
00105 }
00106 
00107 #define NutExitCritical()         \
00108 {                                 \
00109     __asm__ __volatile__ (        \
00110     "csrf\t%0"      "\n\t"        \
00111     :: "i" (AVR32_SR_GM_OFFSET)); \
00112 }
00113 
00114 #endif /* NUT_CRITICAL_NESTING */
00115 
00116 #define NutJumpOutCritical()    NutExitCritical()
00117 
00118 #endif

© 2000-2007 by egnite Software GmbH - visit http://www.ethernut.de/