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

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