00001 /* 00002 * Copyright (C) 2001-2005 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 * Revision 1.6 2008/07/07 11:04:27 haraldkipp 00037 * Configurable ways of handling critical sections for ARM targets. 00038 * 00039 * Revision 1.5 2008/03/17 10:15:36 haraldkipp 00040 * Added memory and cc clobbers to NutEnter/ExitCritical. This keeps 00041 * compiler optimizations inside and outside of critical sections 00042 * seperated. 00043 * 00044 * Revision 1.4 2007/08/17 10:47:03 haraldkipp 00045 * Bug #1757410 fixed. NutEnter/ExitCritical destroyed ARM register R0. 00046 * 00047 * Revision 1.3 2006/03/02 20:03:39 haraldkipp 00048 * Added ICCARM inline assembly for NutEnter/ExitCritical(). Also fixed 00049 * SF 1440949 (FIQ never enabled). 00050 * 00051 * Revision 1.2 2005/07/26 15:47:06 haraldkipp 00052 * AtomicInc() and AtomicDec() are no longer required by Nut/Net. 00053 * Removed to simplify the porting job. Broken applications should 00054 * implement their own version. 00055 * 00056 * Revision 1.1 2005/06/06 10:49:35 haraldkipp 00057 * Building outside the source tree failed. All header files moved from 00058 * arch/cpu/include to include/arch/cpu. 00059 * 00060 * Revision 1.1 2005/05/27 17:41:52 drsung 00061 * Moved the file. 00062 * 00063 * Revision 1.1 2005/05/26 10:08:42 drsung 00064 * Moved the platform dependend code from include/sys/atom.h to this file. 00065 * 00066 * 00067 */ 00068 00069 #ifndef _SYS_ATOM_H_ 00070 #error "Do not include this file directly. Use sys/atom.h instead!" 00071 #endif 00072 00073 #ifdef __GNUC__ 00074 00075 #if defined(NUT_CRITICAL_NESTING) 00076 00077 #if defined(NUT_CRITICAL_NESTING_STACK) 00078 00079 #define NutEnterCritical() \ 00080 { \ 00081 int temp_; \ 00082 asm volatile ( \ 00083 "@ NutEnterCritical" "\n\t" \ 00084 "mrs %0, cpsr" "\n\t" \ 00085 "stmfd sp!, {%0}" "\n\t" \ 00086 "orr %0, %0, #0xC0" "\n\t" \ 00087 "msr cpsr, %0" "\n\t" \ 00088 : "=r" (temp_) : : "memory", "cc"); \ 00089 } 00090 00091 #define NutExitCritical() \ 00092 { \ 00093 int temp_; \ 00094 asm volatile ( \ 00095 "@ NutExitCritical" "\n\t" \ 00096 "ldmfd sp!, {%0}" "\n\t" \ 00097 "msr cpsr, %0" "\n\t" \ 00098 : "=r" (temp_) : : "memory", "cc"); \ 00099 } 00100 00101 #else /* NUT_CRITICAL_NESTING_STACK */ 00102 00103 extern u_int critical_nesting_level; 00104 00105 #define NutEnterCritical() \ 00106 if (critical_nesting_level++ == 0) { \ 00107 int temp_; \ 00108 asm volatile ( \ 00109 "@ NutEnterCritical" "\n\t" \ 00110 "mrs %0, cpsr" "\n\t" \ 00111 "orr %0, %0, #0xC0" "\n\t" \ 00112 "msr cpsr, %0" "\n\t" \ 00113 : "=r" (temp_) : : "cc"); \ 00114 } 00115 00116 #define NutExitCritical() \ 00117 if (critical_nesting_level) { \ 00118 int temp_; \ 00119 asm volatile ( \ 00120 "@ NutExitCritical" "\n\t" \ 00121 "mrs %0, cpsr" "\n\t" \ 00122 "bic %0, %0, #0xC0" "\n\t" \ 00123 "msr cpsr, %0" "\n\t" \ 00124 : "=r" (temp_) : : "cc"); \ 00125 critical_nesting_level--; \ 00126 } 00127 00128 #endif /* NUT_CRITICAL_NESTING_STACK */ 00129 00130 #else /* NUT_CRITICAL_NESTING */ 00131 00132 #define NutEnterCritical() \ 00133 { \ 00134 int temp_; \ 00135 asm volatile ( \ 00136 "@ NutEnterCritical" "\n\t" \ 00137 "mrs %0, cpsr" "\n\t" \ 00138 "orr %0, %0, #0xC0" "\n\t" \ 00139 "msr cpsr, %0" "\n\t" \ 00140 : "=r" (temp_) : : "cc"); \ 00141 } 00142 00143 #define NutExitCritical() \ 00144 { \ 00145 int temp_; \ 00146 asm volatile ( \ 00147 "@ NutExitCritical" "\n\t" \ 00148 "mrs %0, cpsr" "\n\t" \ 00149 "bic %0, %0, #0xC0" "\n\t" \ 00150 "msr cpsr, %0" "\n\t" \ 00151 : "=r" (temp_) : : "cc"); \ 00152 } 00153 00154 #endif /* NUT_CRITICAL_NESTING */ 00155 00156 #define NutJumpOutCritical() NutExitCritical() 00157 00158 #else /* __IMAGECRAFT__ */ 00159 00160 #define NutEnterCritical() \ 00161 asm("; NutEnterCritical\n" \ 00162 "mrs r12, cpsr\n" \ 00163 "orr r12, r12, #0xC0\n" \ 00164 "msr cpsr_c, r12") 00165 00166 #define NutExitCritical() \ 00167 asm("; NutExitCritical\n" \ 00168 "mrs r12, cpsr\n" \ 00169 "bic r12, r12, #0xC0\n" \ 00170 "msr cpsr_c, r12") 00171 00172 #endif