Demonstration of a message queue + memory pool
Fork of Task632-mbedos54 by
Diff: main.cpp
- Revision:
- 3:423191a375dc
- Parent:
- 2:70084af839d3
- Child:
- 4:dae8898e55fe
diff -r 70084af839d3 -r 423191a375dc main.cpp --- a/main.cpp Tue Mar 08 20:51:13 2016 +0000 +++ b/main.cpp Wed Mar 09 10:12:51 2016 +0000 @@ -16,7 +16,7 @@ #define TWORD (7*TUNIT) //Size of the morse character buffer -#define BUFFERSIZE 240 +#define BUFFERSIZE 100 /* @@ -105,7 +105,7 @@ void addCharacterToQueue(const char c) { //Is there space? - spaceAvailable->wait(); + int32_t Nspaces = spaceAvailable->wait(); //Ok, there is space - take the lock bufferLock->lock(); @@ -114,7 +114,8 @@ //Update buffer newestIndex = (newestIndex+1) % BUFFERSIZE; buffer[newestIndex] = c; - + pc.printf("\tAdded ASCII Character: %2Xh (%c) to buffer, %d spaces available\n", c, c, Nspaces-1); + //Release lock bufferLock->unlock(); redLED = 0; @@ -127,7 +128,7 @@ char takeCharacterFromQueue() { //Are thre any samples in the buffer - samplesInBuffer->wait(); + int32_t Nsamples = samplesInBuffer->wait(); //Ok, there are samples - take the lock bufferLock->lock(); @@ -136,6 +137,7 @@ //Update buffer - remove oldest oldestIndex = (oldestIndex+1) % BUFFERSIZE; char cc = buffer[oldestIndex]; + pc.printf("\t\tTaking ASCII Character: %2Xh (%c) from buffer, %d bytes remaining\n", cc, cc, Nsamples-1); //Release lock bufferLock->unlock(); @@ -203,17 +205,6 @@ } } -void convertToMorseAsync(const char* pString) -{ - //Copy each character into the buffer - int L = strlen(pString); - for (int n=0; n<L; n++) { - char c = pString[n]; - addCharacterToQueue(c); - } -} - - //Main thread int main() { redLED = 0; @@ -237,7 +228,6 @@ while (true) { //Read keyboard (serial port) char c = pc.getc(); - pc.printf("\n"); addCharacterToQueue(c); }