For use when compiler ignores the volatile keyword
authorMatthew Mondor <mmondor@pulsar-zone.net>
Sun, 17 Sep 2006 09:02:47 +0000 (09:02 +0000)
committerMatthew Mondor <mmondor@pulsar-zone.net>
Sun, 17 Sep 2006 09:02:47 +0000 (09:02 +0000)
mmsoftware/mmlib/volatile.c [new file with mode: 0644]
mmsoftware/mmlib/volatile.h [new file with mode: 0644]

diff --git a/mmsoftware/mmlib/volatile.c b/mmsoftware/mmlib/volatile.c
new file mode 100644 (file)
index 0000000..056af4f
--- /dev/null
@@ -0,0 +1,32 @@
+/* $Id: volatile.c,v 1.1 2006/09/17 09:02:47 mmondor Exp $ */
+
+/*
+ * Test based on an idea from Rohit Shetye to provide portable volatile
+ * functions in environments for which the compiler does not support the
+ * volatile keyword.
+ *
+ * Written by Matthew Mondor,
+ * Put in the public domain.
+ *
+ * Make sure that volatile.[ch] files are in the same directory, then
+ * compile as follows:
+ * cc -c -I. -O2 -fomit-frame-pointer -fno-inline volatile.c
+ *
+ * You may then link volatile.o statically with your other modules when
+ * creating the executable.  Code which uses this library should include the
+ * volatile.h header file.
+ */
+
+#include <stdint.h>
+
+#include <volatile.h>
+
+#define VOLATILE_FUNCS(t)                                              \
+    t get_##t(t *ptr) { return *ptr; }                                 \
+    void set_##t(t *ptr, t v) { *ptr = v; }
+
+VOLATILE_FUNCS(uint8_t)
+VOLATILE_FUNCS(uint16_t)
+VOLATILE_FUNCS(uint32_t)
+
+#undef VOLATILE_FUNCS
diff --git a/mmsoftware/mmlib/volatile.h b/mmsoftware/mmlib/volatile.h
new file mode 100644 (file)
index 0000000..0fe3631
--- /dev/null
@@ -0,0 +1,35 @@
+/* $Id: volatile.h,v 1.1 2006/09/17 09:02:47 mmondor Exp $ */
+
+/*
+ * Test based on an idea from Rohit Shetye to provide portable volatile
+ * functions in environments for which the compiler does not support the
+ * volatile keyword.
+ *
+ * Written by Matthew Mondor,
+ * Put in the public domain.
+ *
+ * Make sure that volatile.[ch] files are in the same directory, then
+ * compile as follows:
+ * cc -c -I. -O2 -fomit-frame-pointer -fno-inline volatile.c
+ *
+ * You may then link volatile.o statically with your other modules when
+ * creating the executable.  Code which uses this library should include the
+ * volatile.h header file.
+ */
+
+#ifndef _VOLATILE_H_
+#define _VOLATILE_H_
+
+#include <stdint.h>
+
+#define VOLATILE_PROTOS(t)                                             \
+    extern t get_##t(t *);                                             \
+    extern void set_##t(t *, t);
+
+VOLATILE_PROTOS(uint8_t)
+VOLATILE_PROTOS(uint16_t)
+VOLATILE_PROTOS(uint32_t)
+
+#undef VOLATILE_PROTOS
+
+#endif