1 /***************************************************************************
\r
3 ** Common definition for IAR EW ARM
\r
5 ** Used with ARM IAR C/C++ Compiler and Assembler.
\r
7 ** (c) Copyright IAR Systems 2006
\r
9 ** $Revision: 52705 $
\r
11 ***************************************************************************/
\r
12 #include <intrinsics.h>
\r
14 #ifndef __ARM_COMM_DEF_H
\r
15 #define __ARM_COMM_DEF_H
\r
17 #define MHZ *1000000l
\r
22 #define FALSE (1 == 0)
\r
26 #define TRUE (1 == 1)
\r
30 #define NULL ((void*)0)
\r
33 typedef double Flo64; // Double precision floating point
\r
34 typedef double * pFlo64;
\r
35 typedef float Flo32; // Single precision floating point
\r
36 typedef float * pFlo32;
\r
37 typedef signed long long Int64S; // Signed 64 bit quantity
\r
38 typedef signed long long * pInt64S;
\r
39 typedef unsigned long long Int64U; // Unsigned 64 bit quantity
\r
40 typedef unsigned long long * pInt64U;
\r
41 typedef signed int Int32S; // Signed 32 bit quantity
\r
42 typedef signed int * pInt32S;
\r
43 typedef unsigned int Int32U; // Unsigned 32 bit quantity
\r
44 typedef unsigned int * pInt32U;
\r
45 typedef signed short Int16S; // Signed 16 bit quantity
\r
46 typedef signed short * pInt16S;
\r
47 typedef unsigned short Int16U; // Unsigned 16 bit quantity
\r
48 typedef unsigned short * pInt16U;
\r
49 typedef signed char Int8S; // Signed 8 bit quantity
\r
50 typedef signed char * pInt8S;
\r
51 typedef unsigned char Int8U; // Unsigned 8 bit quantity
\r
52 typedef unsigned char * pInt8U;
\r
53 typedef unsigned int Boolean; // Boolean
\r
54 typedef unsigned int * pBoolean;
\r
56 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
\r
57 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
\r
58 #define _2BL(a) (Int8U)(a),(Int8U)(a>>8)
\r
59 #define _2BB(a) (Int8U)(a>>8),(Int8U)(a),
\r
60 #define _3BL(a) (Int8U)(a),(Int8U)(a>>8),(Int8U)(a>>16)
\r
61 #define _3BB(a) (Int8U)(a>>16),(Int8U)(a>>8),(Int8U)(a)
\r
62 #define _4BL(a) (Int8U)(a),(Int8U)(a>>8),(Int8U)(a>>16),(Int8U)(a>>24)
\r
63 #define _4BB(a) (Int8U)(a>>24),(Int8U)(a>>16),(Int8U)(a>>8),(Int8U)(a)
\r
65 typedef void * (*CommUserFpnt_t)(void *);
\r
66 typedef void (*VoidFpnt_t)(void);
\r
68 // Atomic exchange of data between a memory cell and a register
\r
69 // return value of the memory cell
\r
71 inline __arm Int32U AtomicExchange (Int32U State, pInt32U Flag)
\r
73 asm("swp r0, r0, [r1]");
\r
77 #define IRQ_FLAG 0x80
\r
78 #define FIQ_FLAG 0x40
\r
80 inline __arm Int32U EntrCritSection(void)
\r
84 __set_CPSR(tmp | IRQ_FLAG);
\r
88 inline __arm void ExtCritSection(Int32U Save)
\r
92 __set_CPSR(tmp & (Save | ~IRQ_FLAG));
\r
95 inline __arm Int32U EntrCritSectionFiq(void)
\r
99 __set_CPSR(tmp | (IRQ_FLAG | FIQ_FLAG));
\r
103 inline __arm void ExtCritSectionFiq(Int32U Save)
\r
106 tmp = __get_CPSR();
\r
107 __set_CPSR(tmp & (Save | ~(IRQ_FLAG | FIQ_FLAG)));
\r
110 #define ENTR_CRT_SECTION(Save) Save = EntrCritSection()
\r
111 #define EXT_CRT_SECTION(Save) ExtCritSection(Save)
\r
113 #define ENTR_CRT_SECTION_F(Save) Save = EntrCritSectionFiq()
\r
114 #define EXT_CRT_SECTION_F(Save) ExtCritSectionFiq(Save)
\r
116 #elif __CORE__ == 7
\r
118 extern Int32U CriticalSecCntr;
\r
120 inline void EntrCritSection(void)
\r
122 if(CriticalSecCntr == 0)
\r
126 // avoid lost of one count in case of simultaneously calling from both places
\r
130 inline void ExtCritSection(void)
\r
132 if(--CriticalSecCntr == 0)
\r
138 inline Int32U AtomicExchange (Int32U State, pInt32U Flag)
\r
148 #define ENTR_CRT_SECTION() EntrCritSection()
\r
149 #define EXT_CRT_SECTION() ExtCritSection()
\r
152 #define LongToBin(n) (((n >> 21) & 0x80) | \
\r
153 ((n >> 18) & 0x40) | \
\r
154 ((n >> 15) & 0x20) | \
\r
155 ((n >> 12) & 0x10) | \
\r
156 ((n >> 9) & 0x08) | \
\r
157 ((n >> 6) & 0x04) | \
\r
158 ((n >> 3) & 0x02) | \
\r
161 #define __BIN(n) LongToBin(0x##n##l)
\r
163 #define BIN8(n) __BIN(n)
\r
164 #define BIN(n) __BIN(n)
\r
165 #define BIN16(b1,b2) (( __BIN(b1) << 8UL) + \
\r
167 #define BIN32(b1,b2,b3,b4) ((((Int32U)__BIN(b1)) << 24UL) + \
\r
168 (((Int32U)__BIN(b2)) << 16UL) + \
\r
169 (((Int32U)__BIN(b3)) << 8UL) + \
\r
172 #endif // __ARM_COMM_DEF_H
\r