4 * Copyright 2003,2004 Develer S.r.l. (http://www.develer.com/)
5 * Copyright 2001,2002,2003 Bernardo Innocenti <bernie@codewiz.org>
11 * \author Bernardo Innocenti <bernie@develer.com>
13 * \brief Additional support macros for compiler independance
18 * Revision 1.1 2004/05/23 17:48:35 bernie
19 * Add top-level files.
25 #include "arch_config.h"
27 #if defined(__IAR_SYSTEMS_ICC) || defined(__IAR_SYSTEMS_ICC__)
28 #pragma language=extended
29 #define INTERRUPT(x) interrupt [x]
30 #define REGISTER shortad
31 #define ATOMIC monitor
34 #define FORMAT(type,fmt,first) /* nothing */
35 #define NORETURN /* nothing */
36 #define UNUSED(arg) arg
38 /* Imported from <longjmp.h>. Unfortunately, we can't just include
39 * this header because it typedefs jmp_buf to be an array of chars.
40 * This would allow the compiler to place the buffer on an odd address.
41 * The CPU _should_ be able to perform word accesses to
42 * unaligned data, but there are *BUGS* in the 80196KC with
43 * some combinations of opcodes and addressing modes. One of
44 * these, "ST SP,[?GR]+" is used in the longjmp() implementation
45 * provided by the IAR compiler ANSI C library. When ?GR contains
46 * an odd address, surprisingly the CPU will copy the high order
47 * byte of the source operand (SP) in the low order byte of the
48 * destination operand (the memory location pointed to by ?GR).
50 * We also need to replace the library setjmp()/longjmp() with
51 * our own versions because the IAR implementation "forgets" to
52 * save the contents of local registers (?LR).
56 void * sp; /* Stack pointer */
57 void * return_addr; /* Return address */
58 int lr[6]; /* 6 local registers */
61 typedef struct _JMP_BUF jmp_buf[1];
63 int setjmp(jmp_buf env);
64 void longjmp(jmp_buf env, int val);
69 typedef unsigned char bool;
70 #endif /* !__cplusplus */
72 #elif defined(_MSC_VER) /* Win32 emulation support */
75 #include <time.h> /* for time_t */
78 #define REGISTER /* nothing */
79 #define INTERRUPT(x) /* nothing */
82 #define FORMAT(type,fmt,first) /* nothing */
83 #define NORETURN /* nothing */
84 #define UNUSED(arg) arg
85 #define INLINE static inline
90 void SchedulerIdle(void);
95 /* Ouch, ReleaseSemaphore() conflicts with a WIN32 call ;-( */
96 #define ReleaseSemaphore KReleaseSemaphore
102 #endif /* !__cplusplus */
104 #elif defined(__GNUC__)
107 #define FORMAT(type,fmt,first) __attribute__((__format__(type, fmt, first)))
108 #define NORETURN __attribute__((__noreturn__))
109 #define UNUSED(arg) __attribute__((__unused__)) arg
110 //FIXME #define INLINE static inline
111 #define INLINE extern inline
113 #if defined(__i386__)
115 /* hack to avoid conflicts with system type */
116 #define sigset_t system_sigset_t
120 #undef system_sigset_t
122 #define REGISTER /* nothing */
123 #define INTERRUPT(x) /* nothing */
128 void SchedulerIdle(void);
133 #elif defined(__AVR__)
137 #define FLASH __attribute__((progmem))
138 #define REGISTER /* nothing */
140 /* Missing printf-family functions in avr-libc/stdio.h */
142 #include <avr/pgmspace.h>
143 int vsprintf(char *buf, const char *fmt, va_list ap);
144 int vsprintf_P(char *buf, const char * PROGMEM fmt, va_list ap);
146 /* Support for hardvard architectures */
148 #define PGM_READ_CHAR(s) pgm_read_byte(s)
149 #define PGM_FUNC(x) x ## _P
150 #define PGM_ATTR PROGMEM
152 #define PGM_READ_CHAR(s) (*(s))
153 #define PGM_FUNC(x) x
154 #define PGM_ATTR /*nop*/
159 #elif defined(__MWERKS__) && (defined(__m56800E__) || defined(__m56800__))
166 #define FLASH /* nothing */
167 #define REGISTER /* nothing */
168 #define INTERRUPT(x) ERROR_NOT_IMPLEMENTED
169 #define SCHEDULER_IDLE /* nothing */
171 #define INLINE static inline
174 #define FORMAT(type,fmt,first) /* nothing */
175 #define NORETURN /* nothing */
176 #define UNUSED(arg) arg
178 /* Support for hardvard architectures */
179 #define PGM_READ_CHAR(s) (*(s))
180 #define PGM_FUNC /* nothing */
181 #define PGM_ATTR /* nothing */
182 #define PSTR /* nothing */
185 #error unknown compiler
188 /* Misc definitions */
199 * offsetof(s,m) - Give the byte offset of the member <m> in struct <s>
200 * countof(a) - Count the number of elements in the static array <a>
203 #define offsetof(s,m) (size_t)&(((s *)0)->m)
207 #define countof(a) (sizeof(a) / sizeof(*(a)))
211 #define ABS(a) (((a) < 0) ? -(a) : (a))
212 #define MIN(a,b) (((a) < (b)) ? (a) : (b))
213 #define MAX(a,b) (((a) > (b)) ? (a) : (b))
215 /*! Convert a bit value to a binary flag */
217 #define BV(x) (1<<(x))
220 /*! Round up \a x to an even multiple of the 2's power \a pad */
221 #define ROUND2(x, pad) (((x) + ((pad) - 1)) & ~((pad) - 1))
223 /*! Calculate a compile-time log2 for a uint8_t */
224 #define UINT8_LOG2(x) \
231 ((x) < 128 ? 6 : 7)))))))
233 /*! Calculate a compile-time log2 for a uint16_t */
234 #define UINT16_LOG2(x) \
235 ((x < 256) ? UINT8_LOG2(x) : UINT8_LOG2((x) >> 8) + 8)
237 /*! Calculate a compile-time log2 for a uint32_t */
238 #define UINT32_LOG2(x) \
239 ((x < 65536UL) ? UINT16_LOG2(x) : UINT16_LOG2((x) >> 16) + 16)
241 /* Type definitions - should go in <sys/types.h> */
242 #if !(defined(size_t) || defined(_SIZE_T_DEFINED))
243 #define size_t unsigned int
245 #if !(defined(_TIME_T_DEFINED) || defined(__time_t_defined))
247 #endif /* _TIME_T_DEFINED || __time_t_defined */
249 /*! Storage for pointers and integers */
252 typedef long utime_t;
253 typedef unsigned char sig_t;
254 typedef unsigned char sigset_t;
255 typedef unsigned char page_t;
257 /* ISO C99 fixed-size types */
258 #if (defined(_MSC_VER) || defined(__IAR_SYSTEMS_ICC) || defined(__IAR_SYSTEMS_ICC__))
259 typedef signed char int8_t;
260 typedef short int int16_t;
261 typedef long int int32_t;
262 typedef unsigned char uint8_t;
263 typedef unsigned short int uint16_t;
264 typedef unsigned long int uint32_t;
265 #elif defined(__AVR__)
266 # include <inttypes.h>
271 #if (defined(__m56800E__) || defined(__m56800__))
272 /* Registers can be accessed only through 16-bit pointers */
273 typedef volatile uint16_t reg16_t;
275 typedef volatile uint8_t reg8_t;
276 typedef volatile uint16_t reg16_t;
277 typedef volatile uint32_t reg32_t;
280 #endif /* COMPILER_H */