Display text on LCD displays (even on multiple ones). Allow to create windows (frames) on display, and to combine them (split, add, duplicate, scroll). See http://mbed.org/users/hlipka/notebook/lcdwindow/ for more information.

Dependents:   Mbell

Committer:
hlipka
Date:
Tue Feb 22 22:57:44 2011 +0000
Revision:
9:2fe93daa2106
Parent:
3:e5d5e2fe4bf6
fixed semaphore handling - should now be really thread safe (can be called from interrupts)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hlipka 3:e5d5e2fe4bf6 1 /**
hlipka 3:e5d5e2fe4bf6 2 * code from Igor Skochinsky
hlipka 3:e5d5e2fe4bf6 3 * taken from http://mbed.org/forum/mbed/post/799/
hlipka 3:e5d5e2fe4bf6 4 */
hlipka 3:e5d5e2fe4bf6 5
hlipka 3:e5d5e2fe4bf6 6 #include "semaphore.h"
hlipka 3:e5d5e2fe4bf6 7
hlipka 9:2fe93daa2106 8 Semaphore::Semaphore(): s(SemFree) {};
hlipka 9:2fe93daa2106 9 bool Semaphore::_abort=false;
hlipka 9:2fe93daa2106 10
hlipka 9:2fe93daa2106 11 bool Semaphore::take(bool block) {
hlipka 9:2fe93daa2106 12 if (_abort)
hlipka 9:2fe93daa2106 13 block=false;
hlipka 3:e5d5e2fe4bf6 14 int oldval;
hlipka 3:e5d5e2fe4bf6 15 #if defined(TARGET_LPC1768) // on Cortex-M3 we can use ldrex/strex
hlipka 3:e5d5e2fe4bf6 16 do {
hlipka 9:2fe93daa2106 17 // read the semaphore value
hlipka 9:2fe93daa2106 18 oldval = __ldrex(&s);
hlipka 9:2fe93daa2106 19 // loop again if it is locked and we are blocking
hlipka 9:2fe93daa2106 20 // or setting it with strex failed
hlipka 9:2fe93daa2106 21 } while ( (block && oldval == SemTaken) || __strex(SemTaken, &s) != 0 );
hlipka 3:e5d5e2fe4bf6 22 if ( !block ) __clrex(); // clear exclusive lock set by ldrex
hlipka 3:e5d5e2fe4bf6 23 #else // on arm7 there's only swp
hlipka 3:e5d5e2fe4bf6 24 do {
hlipka 9:2fe93daa2106 25 // swp sets the pointed data to the given value and returns the previous one
hlipka 9:2fe93daa2106 26 oldval = __swp(SemTaken, &s);
hlipka 9:2fe93daa2106 27 // if blocking, loop until the previous value becomes 0
hlipka 9:2fe93daa2106 28 // which would mean we have successfully taken the lock
hlipka 9:2fe93daa2106 29 } while (block && oldval == SemTaken);
hlipka 3:e5d5e2fe4bf6 30 #endif
hlipka 3:e5d5e2fe4bf6 31 return oldval == SemFree;
hlipka 9:2fe93daa2106 32 }
hlipka 9:2fe93daa2106 33
hlipka 9:2fe93daa2106 34 // release the semaphore
hlipka 9:2fe93daa2106 35 void Semaphore::release() {
hlipka 3:e5d5e2fe4bf6 36 s = SemFree;
hlipka 9:2fe93daa2106 37 }