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