summaryrefslogtreecommitdiffstats
path: root/app/i2c.c
diff options
context:
space:
mode:
authorfishsoupisgood <github@madingley.org>2020-06-13 21:05:45 +0100
committerfishsoupisgood <github@madingley.org>2020-06-13 21:05:45 +0100
commitd85f3aeeeefd6926fe71ec8e066adb74f62dc1cc (patch)
treefc4e43a80dc50717d41a869dddce20c94a0f25c4 /app/i2c.c
downloadrobs_speedo-d85f3aeeeefd6926fe71ec8e066adb74f62dc1cc.tar.gz
robs_speedo-d85f3aeeeefd6926fe71ec8e066adb74f62dc1cc.tar.bz2
robs_speedo-d85f3aeeeefd6926fe71ec8e066adb74f62dc1cc.zip
fish
Diffstat (limited to 'app/i2c.c')
-rw-r--r--app/i2c.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/app/i2c.c b/app/i2c.c
new file mode 100644
index 0000000..bf25256
--- /dev/null
+++ b/app/i2c.c
@@ -0,0 +1,20 @@
+static int mutex = 0;
+
+int
+i2c_lock (void)
+{
+ if (__sync_add_and_fetch (&mutex, 1) != 1)
+ {
+ __sync_sub_and_fetch (&mutex, 1);
+ return -1;
+ }
+
+ return 0;
+}
+
+
+void
+i2c_unlock (void)
+{
+ __sync_sub_and_fetch (&mutex, 1);
+}