Queues
Dependencies: ELEC350-Practicals-FZ429
Fork of Task631-mbedos54 by
Revision 12:43370561e925, committed 2017-11-14
- Comitter:
- noutram
- Date:
- Tue Nov 14 15:16:06 2017 +0000
- Parent:
- 11:40f94f38591c
- Child:
- 13:ab9f53427355
- Commit message:
- Updated for FZ429
Changed in this revision
| ELEC350-Practicals-FZ429.lib | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ELEC350-Practicals-FZ429.lib Tue Nov 14 15:16:06 2017 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/teams/University-of-Plymouth-Stage-2-and-3/code/ELEC350-Practicals-FZ429/#3250ba797c16
--- a/main.cpp Tue Nov 14 15:06:25 2017 +0000
+++ b/main.cpp Tue Nov 14 15:16:06 2017 +0000
@@ -1,5 +1,6 @@
#include "mbed.h"
-#include "rtos.h"
+#include "sample_hardware.hpp"
+
#include "string.h"
#include <stdio.h>
#include <ctype.h>
@@ -10,38 +11,24 @@
void thread2();
void switchISR();
-//Analogue inputs
-AnalogIn adcIn(A0);
-
-//Digital outputs
-DigitalOut onBoardLED(LED1);
-DigitalOut redLED(D7);
-DigitalOut yellowLED(D6);
-DigitalOut greenLED(D5);
-
-//Digital inputs
-DigitalIn onBoardSwitch(USER_BUTTON);
-DigitalIn sw1(D4); //CONSIDER CHANGING THIS TO AN INTERRUPT
-DigitalIn sw2(D3);
-
//Threads
-Thread *t1;
+Thread t1;
//Queues - "A message can be a integer or pointer value to a certain type T that is sent to a thread or interrupt service routine."
-Queue<uint32_t, 5> *queue;
+Queue<uint32_t, 5> queue;
// Call this on precise intervals
void adcISR() {
//Option to starve the queue
- if (sw2 == 1) return;
+ if (SW2 == 1) return;
//Read sample - make a copy
uint32_t sample = (uint32_t)(4095*adcIn.read());
//Write to queue
- osStatus stat = queue->put((uint32_t*)sample);
+ osStatus stat = queue.put((uint32_t*)sample);
//Check if succesful
if (stat == osErrorResource) {
@@ -56,7 +43,7 @@
{
while (true) {
//Read queue - block (with timeout)
- osEvent evt = queue->get(5000); //With timeout
+ osEvent evt = queue.get(5000); //With timeout
//Check status of get()
switch (evt.status) {
@@ -77,7 +64,7 @@
//Block up consumer if switch is held down
//Will fill the queue if held long enough
- while (sw1 == 1);
+ while (SW1 == 1);
} //end while
}
@@ -92,16 +79,12 @@
//Start message
printf("Welcome\n");
- //Queue
- queue = new Queue<uint32_t,5>();
-
//Hook up timer interrupt
Ticker timer;
timer.attach(&adcISR, 1.0);
//Threads
- t1 = new Thread();
- t1->start(thread1);
+ t1.start(thread1);
printf("Main Thread\n");
while (true) {
