Semaphore_Display

Dependencies:   C12832

Files at this revision

API Documentation at this revision

Comitter:
corsa1600
Date:
Thu Mar 21 18:20:01 2019 +0000
Parent:
1:98ffcc251be8
Commit message:
Semaphore

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 98ffcc251be8 -r 9a1b2edd0b0d main.cpp
--- a/main.cpp	Thu Mar 21 18:13:40 2019 +0000
+++ b/main.cpp	Thu Mar 21 18:20:01 2019 +0000
@@ -60,6 +60,7 @@
 
 
 Mutex LCDMutex; // hier wird der Mutex instanziiert
+Semaphore one_slot(3);// die Anzahl der gleichzeitig erlaubten Threads bei 1 darf immer nur einer hier bei 3 haben wir wieder das Problem das alles gleichzeitig losgehen kann
  
 //void Led1_Blink(void *pvParameters)
 void Led1_Blink()       // red long
@@ -73,7 +74,8 @@
           wait_ms(xDelay);
        }
  // kritischer abschnitt!!! dieser soll mit Mutex behandelt werden
- LCDMutex.lock();// Mutex beginnt
+ //LCDMutex.lock();// Mutex beginnt
+ one_slot.wait();
        {
            lcd.cls();
            lcd.locate(0,3);
@@ -86,7 +88,8 @@
            Delay_Nonsense(&BlueDelay, &TargetCount);
            wait_ms(xDelay);
        }
-       LCDMutex.unlock(); // Mutex endet
+       //LCDMutex.unlock(); // Mutex endet
+       one_slot.release();
    }
 }
  
@@ -100,7 +103,8 @@
        for(int i = 0; i < 10; i++) {     // randomnes
           wait_ms(xDelay);
        }
-       LCDMutex.lock();// Mutex beginnt
+       //LCDMutex.lock();// Mutex beginnt
+       one_slot.wait();
        {
            lcd.cls();
            lcd.locate(0,3);
@@ -113,7 +117,8 @@
            Delay_Nonsense(&BlueDelay, &TargetCount);
            wait_ms(xDelay);
        }
-        LCDMutex.unlock(); // Mutex endet
+        //LCDMutex.unlock(); // Mutex endet
+       one_slot.release();
    }
 }
  
@@ -127,7 +132,8 @@
        for(int i = 0; i < 10; i++) {     // randomnes
           wait_ms(xDelay);
        }
-       LCDMutex.lock();// Mutex beginnt
+       //LCDMutex.lock();// Mutex beginnt
+       one_slot.wait();
        {
            lcd.cls();
            lcd.locate(0,3);
@@ -141,7 +147,8 @@
            Delay_Nonsense(&BlueDelay, &TargetCount);
            wait_ms(xDelay);
        }
-     LCDMutex.unlock(); // Mutex endet
+     //LCDMutex.unlock(); // Mutex endet
+       one_slot.release();
    }
 }