Library that uses mbed-os

Dependents:   My_Libraries

Files at this revision

API Documentation at this revision

Comitter:
altb
Date:
Wed Mar 06 14:19:23 2019 +0000
Commit message:
New RTOS part

Changed in this revision

Signal.cpp Show annotated file Show diff for this revision Revisions of this file
Signal.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r ff3de4aaacf8 Signal.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Signal.cpp	Wed Mar 06 14:19:23 2019 +0000
@@ -0,0 +1,54 @@
+/*
+ * Signal.cpp
+ * Copyright (c) 2017, ZHAW
+ * All rights reserved.
+ */
+
+#include "Signal.h"
+
+using namespace std;
+
+int32_t Signal::signals = 0;
+
+/**
+ * Creates a signal object and assignes a unique flag.
+ */
+Signal::Signal() {
+    
+    mutex.lock();
+    
+    int32_t n = 0;
+    while ((((1 << n) & signals) > 0) && (n < 30)) n++;
+    signal = (1 << n);
+    
+    mutex.unlock();
+}
+
+/**
+ * Deletes the signal object and releases the assigned flag.
+ */
+Signal::~Signal() {
+    
+    mutex.lock();
+    
+    signals &= ~signal;
+    
+    mutex.unlock();
+}
+
+/**
+ * Gets the assigned signal flag.
+ */
+int32_t Signal::read() {
+    
+    return signal;
+}
+
+/**
+ * The empty operator is a shorthand notation of the <code>read()</code> method.
+ */
+Signal::operator int32_t() {
+    
+    return read();
+}
+
diff -r 000000000000 -r ff3de4aaacf8 Signal.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Signal.h	Wed Mar 06 14:19:23 2019 +0000
@@ -0,0 +1,34 @@
+/*
+ * Signal.h
+ * Copyright (c) 2017, ZHAW
+ * All rights reserved.
+ */
+
+#ifndef SIGNAL_H_
+#define SIGNAL_H_
+
+#include <cstdlib>
+#include <stdint.h>
+#include <mbed.h>
+
+/**
+ * This class manages the handling of unique signal flags to trigger rtos threads.
+ */
+class Signal {
+    
+    public:
+        
+                        Signal();
+        virtual         ~Signal();
+        virtual int32_t read();
+                        operator int32_t();
+        
+    private:
+        
+        static int32_t  signals;    // variable that holds all assigned signal flags
+        int32_t         signal;     // signal flag of this object
+        Mutex           mutex;      // mutex to lock critical sections
+};
+
+#endif /* SIGNAL_H_ */
+