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 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.4.2.1  2008/04/06 10:44:25  haraldkipp
00037  * Added memory and cc clobbers to NutEnter/ExitCritical. This keeps compiler
00038  * optimizations inside and outside of critical sections seperated.
00039  *
00040  * Revision 1.4  2007/08/17 10:47:03  haraldkipp
00041  * Bug #1757410 fixed. NutEnter/ExitCritical destroyed ARM register R0.
00042  *
00043  * Revision 1.3  2006/03/02 20:03:39  haraldkipp
00044  * Added ICCARM inline assembly for NutEnter/ExitCritical(). Also fixed
00045  * SF 1440949 (FIQ never enabled).
00046  *
00047  * Revision 1.2  2005/07/26 15:47:06  haraldkipp
00048  * AtomicInc() and AtomicDec() are no longer required by Nut/Net.
00049  * Removed to simplify the porting job. Broken applications should
00050  * implement their own version.
00051  *
00052  * Revision 1.1  2005/06/06 10:49:35  haraldkipp
00053  * Building outside the source tree failed. All header files moved from
00054  * arch/cpu/include to include/arch/cpu.
00055  *
00056  * Revision 1.1  2005/05/27 17:41:52  drsung
00057  * Moved the file.
00058  *
00059  * Revision 1.1  2005/05/26 10:08:42  drsung
00060  * Moved the platform dependend code from include/sys/atom.h to this file.
00061  *
00062  *
00063  */
00064 
00065 #ifndef _SYS_ATOM_H_
00066 #error "Do not include this file directly. Use sys/atom.h instead!"
00067 #endif
00068 
00069 #ifdef __GNUC__
00070 
00071 #define NutEnterCritical() \
00072 { \
00073     int temp_; \
00074     asm volatile (             \
00075             "@ NutEnterCritical"    "\n\t" \
00076             "mrs     %0, cpsr"      "\n\t" \
00077             "stmfd   sp!, {%0}"     "\n\t" \
00078             "orr     %0, %0, #0xC0" "\n\t" \
00079             "msr     cpsr, %0"      "\n\t" \
00080             : "=r" (temp_) : : "memory", "cc"); \
00081 }
00082 
00083 #define NutExitCritical() \
00084 { \
00085     int temp_; \
00086     asm volatile (             \
00087             "@ NutExitCritical" "\n\t" \
00088             "ldmfd   sp!, {%0}" "\n\t" \
00089             "msr     cpsr, %0"  "\n\t" \
00090             : "=r" (temp_) : : "memory", "cc"); \
00091 }
00092 
00093 #define NutJumpOutCritical()    NutExitCritical()
00094 
00095 #else /* __IMAGECRAFT__ */
00096 
00097 #define NutEnterCritical() \
00098         asm("; NutEnterCritical\n" \
00099             "mrs r12, cpsr\n" \
00100             "orr r12, r12, #0xC0\n" \
00101             "msr cpsr_c, r12")
00102 
00103 #define NutExitCritical() \
00104         asm("; NutExitCritical\n" \
00105             "mrs r12, cpsr\n" \
00106             "bic r12, r12, #0xC0\n" \
00107             "msr cpsr_c, r12")
00108 
00109 #endif

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