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.7 2006/02/20 01:46:59 bernie
20 *#* Revision 1.6 2006/02/15 09:12:33 bernie
21 *#* Don't mask useful user signals on UNIX.
23 *#* Revision 1.5 2005/11/27 23:32:42 bernie
24 *#* Add CPU fallback for OS_ID.
26 *#* Revision 1.4 2005/11/27 03:07:13 bernie
27 *#* IRQ_SAVE_DISABLE(): Really block signals.
29 *#* Revision 1.3 2005/11/27 03:02:40 bernie
30 *#* Add POSIX emulation for IRQ_* macros; Add Qt support.
32 *#* Revision 1.2 2005/11/04 16:20:01 bernie
33 *#* Fix reference to README.devlib in header.
35 *#* Revision 1.1 2005/04/11 19:04:13 bernie
36 *#* Move top-level headers to cfg/ subdir.
38 *#* Revision 1.1 2004/12/31 17:40:24 bernie
39 *#* Add OS detection code.
45 /*! Macro to include OS-specific versions of the headers. */
46 #define OS_HEADER(module) PP_STRINGIZE(PP_CAT3(module, _, OS_ID).h)
47 #define OS_CSOURCE(module) PP_STRINGIZE(PP_CAT3(module, _, OS_ID).c)
50 * OS autodetection (Some systems trigger multiple OS definitions)
59 #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
61 #define OS_POSIX 1 /* Not strictly UNIX, but no way to autodetect it. */
65 * The POSIX moral equivalent of disabling IRQs is disabling signals.
67 // #define _XOPEN_SOURCE 600 /* Avoid BSDish stuff */
68 // #undef _GNU_SOURCE /* This implies _BSD_SOURCE and is predefined on Linux. */
70 typedef sigset_t cpuflags_t;
72 #define SET_ALL_SIGNALS(sigs) \
75 sigdelset(&sigs, SIGINT); \
76 sigdelset(&sigs, SIGSTOP); \
77 sigdelset(&sigs, SIGCONT); \
83 SET_ALL_SIGNALS(sigs); \
84 sigprocmask(SIG_BLOCK, &sigs, NULL); \
90 SET_ALL_SIGNALS(sigs); \
91 sigprocmask(SIG_UNBLOCK, &sigs, NULL); \
94 #define IRQ_SAVE_DISABLE(old_sigs) \
97 SET_ALL_SIGNALS(sigs); \
98 sigprocmask(SIG_BLOCK, &sigs, &old_sigs); \
101 #define IRQ_RESTORE(old_sigs) \
103 sigprocmask(SIG_SETMASK, &old_sigs, NULL); \
116 #if defined(__APPLE__) && defined(__MACH__)
123 * We want Qt and other frameworks to look like OSes because you would
124 * tipically want their portable abstractions if you're using one of these.
135 * Summarize hosted environments as OS_HOSTED and embedded
136 * environment with OS_EMBEDDED.
138 #if OS_WIN32 || OS_UNIX || OS_DARWIN
140 #define OS_EMBEDDED 0
143 #define OS_EMBEDDED 1
145 /* Embedded environments fall back to CPU-specific code. */
149 /* Self-check for the detection */
151 #error OS_ID not defined
153 #if OS_HOSTED && OS_EMBEDDED
154 #error Both hosted and embedded OS environment
156 #if !OS_HOSTED && !OS_EMBEDDED
157 #error Neither hosted nor embedded OS environment
160 #endif /* DEVLIB_OS_H */