Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of rtos_basic by
Revision 13:bd6c24a90b4a, committed 2017-01-30
- Comitter:
- saudraisn
- Date:
- Mon Jan 30 21:51:36 2017 +0000
- Parent:
- 12:9573a2e293e2
- Commit message:
- WORKING
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 9573a2e293e2 -r bd6c24a90b4a main.cpp
--- a/main.cpp Mon Jan 30 21:20:31 2017 +0000
+++ b/main.cpp Mon Jan 30 21:51:36 2017 +0000
@@ -3,15 +3,22 @@
#include "AnalogBuffer.h"
const int SEUIL_ANALOG = 0x2000;
+
DigitalIn en_1(p15);
DigitalIn en_2(p16);
AnalogIn ea_1(p19);
AnalogIn ea_2(p20);
+
bool digital_1;
bool digital_2;
+
AnalogBuffer ab_1;
AnalogBuffer ab_2;
+Ticker ticker1, ticker2;
+
+Thread *t1, *t2;
+
Serial pc(USBTX, USBRX); // tx, rx
typedef struct {
@@ -24,15 +31,20 @@
Mail<mail_t, 16> mail_box;
+//Benchmark section.
+Timer timer;
+unsigned int old;
+unsigned int newT;
+
void lecture_analog(void const *args)
{
-// Timer timer;
unsigned short old_average_1 = 0;
unsigned short old_average_2 = 0;
while (true) {
-// pc.printf("Thread anal attend");
-// Thread::signal_wait(0x1);
- // timer.start(); // synchronisation sur la période d'échantillonnage
+ Thread::signal_wait(0x1);
+ old = newT;
+ newT = timer.read_ms();
+ pc.printf("Time : %d\n",newT-old);
time_t rtc_time = time(NULL); // lecture de l'étampe temporelle
ab_1.put(ea_1.read_u16()); // lecture des échantillons analogiques
ab_2.put(ea_2.read_u16());
@@ -59,25 +71,18 @@
mail_box.put(mail);
old_average_2 = new_average_2;
}
- //Thread::wait(250 - timer.read_ms());
-// timer.stop();
-// timer.reset();
}
}
+
+
+
void lecture_num(void const *args)
{
-// Timer timer;
- // timer1.start();
-// unsigned int old;
-// unsigned int newT;
-
while (true) {
-// pc.printf("Thread num attend");
-// Thread::signal_wait(0x1);
-// timer.start(); // synchronisation sur la période d'échantillonnage
+ Thread::signal_wait(0x1);
//old = newT;
-// newT = timer1.read_ms();
-
+// newT = timer.read_ms();
+// pc.printf("Time : %d\n",newT-old);
time_t rtc_time = time(NULL); // lecture de l'étampe temporelle
bool new_digital_1 = en_1.read(); // lecture des échantillons numériques
bool new_digital_2 = en_2.read(); // lecture des échantillons numériques
@@ -112,12 +117,6 @@
}
}
}
- // pc.printf("time : %d\n", timer.read_ms());
-//// Thread::wait(100 - timer.read_ms());
-// Thread::wait(1000);
-// pc.printf("time2 : %d\n", timer.read_ms());
-// timer.stop();
-// timer.reset();
}
}
@@ -126,7 +125,6 @@
while (true) {
// attente et lecture d'un événement
// écriture de l'événement en sortie (port série)
- pc.printf("je fonctionne");
osEvent evt = mail_box.get();
if (evt.status == osEventMail) {
mail_t *mail = (mail_t*)evt.value.p;
@@ -139,48 +137,34 @@
}
}
}
-//Ticker ticker1, ticker2;
-
-//Thread *t1, *t2;
-//void wakeupThread1(void const *args)
-//{
-// pc.printf("12345");
-// t1->signal_set(0x1);
-//}
-//
-//void wakeupThread2(void const *args)
-//{
-// pc.printf("67890");
-// t2->signal_set(0x1);
-//}
+void wakeupThread1()
+{
+ t1->signal_set(0x1);
+}
+
+void wakeupThread2()
+{
+ t2->signal_set(0x1);
+}
int main()
{
-// pc.printf("gogogo");
// initialisation du RTC
set_time(1485732233);
+ timer.start();
+
// démarrage des tâches
- // Thread analogThread(lecture_analog);
-// Thread digitalThread(lecture_num);
+ Thread analogThread(lecture_analog);
+ Thread digitalThread(lecture_num);
Thread collectionThread(collection);
-// pc.printf("pogogogogo");
- // *t1 = analogThread;
-// *t2 = digitalThread;
+ t1 = &analogThread;
+ t2 = &digitalThread;
- //ticker1.attach(&wakeupThread1, 0.250);
-// ticker2.attach(&wakeupThread2, 0.100);
-
- RtosTimer led_1_timer(lecture_analog, osTimerPeriodic);
- RtosTimer led_2_timer(lecture_num, osTimerPeriodic);
-
- led_1_timer.start(250);
-
- Thread::wait(10);
- led_2_timer.start(100);
+ ticker1.attach(&wakeupThread1, 0.250);
+ ticker2.attach(&wakeupThread2, 0.100);
-// pc.printf("fuck");
while(1);
}
