--- /dev/null
+/* $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
--- /dev/null
+/* $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