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

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