4 * Copyright 2004, 2005 Develer S.r.l. (http://www.develer.com/)
5 * This file is part of DevLib - See README.devlib for information.
8 * \brief OS-specific definitions
12 * \author Bernardo Innocenti <bernie@develer.com>
17 *#* Revision 1.8 2006/02/23 09:09:28 bernie
18 *#* Remove Linux specific hack.
20 *#* Revision 1.7 2006/02/20 01:46:59 bernie
23 *#* Revision 1.6 2006/02/15 09:12:33 bernie
24 *#* Don't mask useful user signals on UNIX.
26 *#* Revision 1.5 2005/11/27 23:32:42 bernie
27 *#* Add CPU fallback for OS_ID.
29 *#* Revision 1.4 2005/11/27 03:07:13 bernie
30 *#* IRQ_SAVE_DISABLE(): Really block signals.
32 *#* Revision 1.3 2005/11/27 03:02:40 bernie
33 *#* Add POSIX emulation for IRQ_* macros; Add Qt support.
35 *#* Revision 1.2 2005/11/04 16:20:01 bernie
36 *#* Fix reference to README.devlib in header.
38 *#* Revision 1.1 2005/04/11 19:04:13 bernie
39 *#* Move top-level headers to cfg/ subdir.
41 *#* Revision 1.1 2004/12/31 17:40:24 bernie
42 *#* Add OS detection code.
48 /*! Macro to include OS-specific versions of the headers. */
49 #define OS_HEADER(module) PP_STRINGIZE(PP_CAT3(module, _, OS_ID).h)
50 #define OS_CSOURCE(module) PP_STRINGIZE(PP_CAT3(module, _, OS_ID).c)
53 * OS autodetection (Some systems trigger multiple OS definitions)
62 #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
64 #define OS_POSIX 1 /* Not strictly UNIX, but no way to autodetect it. */
68 * The POSIX moral equivalent of disabling IRQs is disabling signals.
71 typedef sigset_t cpuflags_t;
73 #define SET_ALL_SIGNALS(sigs) \
76 sigdelset(&sigs, SIGINT); \
77 sigdelset(&sigs, SIGSTOP); \
78 sigdelset(&sigs, SIGCONT); \
84 SET_ALL_SIGNALS(sigs); \
85 sigprocmask(SIG_BLOCK, &sigs, NULL); \
91 SET_ALL_SIGNALS(sigs); \
92 sigprocmask(SIG_UNBLOCK, &sigs, NULL); \
95 #define IRQ_SAVE_DISABLE(old_sigs) \
98 SET_ALL_SIGNALS(sigs); \
99 sigprocmask(SIG_BLOCK, &sigs, &old_sigs); \
102 #define IRQ_RESTORE(old_sigs) \
104 sigprocmask(SIG_SETMASK, &old_sigs, NULL); \
117 #if defined(__APPLE__) && defined(__MACH__)
124 * We want Qt and other frameworks to look like OSes because you would
125 * tipically want their portable abstractions if you're using one of these.
136 * Summarize hosted environments as OS_HOSTED and embedded
137 * environment with OS_EMBEDDED.
139 #if OS_WIN32 || OS_UNIX || OS_DARWIN
141 #define OS_EMBEDDED 0
144 #define OS_EMBEDDED 1
146 /* Embedded environments fall back to CPU-specific code. */
150 /* Self-check for the detection */
152 #error OS_ID not defined
154 #if OS_HOSTED && OS_EMBEDDED
155 #error Both hosted and embedded OS environment
157 #if !OS_HOSTED && !OS_EMBEDDED
158 #error Neither hosted nor embedded OS environment
161 #endif /* DEVLIB_OS_H */