![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
School Project
main.cpp@0:c637467eeb8f, 2017-01-30 (annotated)
- Committer:
- ericbisson
- Date:
- Mon Jan 30 18:52:54 2017 +0000
- Revision:
- 0:c637467eeb8f
- Child:
- 1:b3ae0d9f02ad
app2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ericbisson | 0:c637467eeb8f | 1 | #include "mbed.h" |
ericbisson | 0:c637467eeb8f | 2 | #include "rtos.h" |
ericbisson | 0:c637467eeb8f | 3 | |
ericbisson | 0:c637467eeb8f | 4 | Ticker tick; |
ericbisson | 0:c637467eeb8f | 5 | Thread* t1; |
ericbisson | 0:c637467eeb8f | 6 | Thread* t2; |
ericbisson | 0:c637467eeb8f | 7 | Thread* t3; |
ericbisson | 0:c637467eeb8f | 8 | |
ericbisson | 0:c637467eeb8f | 9 | DigitalIn en_1(p15); |
ericbisson | 0:c637467eeb8f | 10 | DigitalIn en_2(p16); |
ericbisson | 0:c637467eeb8f | 11 | AnalogIn ea_1(p19); |
ericbisson | 0:c637467eeb8f | 12 | AnalogIn ea_2(p20); |
ericbisson | 0:c637467eeb8f | 13 | Serial pc(USBTX, USBRX); |
ericbisson | 0:c637467eeb8f | 14 | |
ericbisson | 0:c637467eeb8f | 15 | void signal_analog() |
ericbisson | 0:c637467eeb8f | 16 | { |
ericbisson | 0:c637467eeb8f | 17 | t1->signal_set(1); |
ericbisson | 0:c637467eeb8f | 18 | } |
ericbisson | 0:c637467eeb8f | 19 | |
ericbisson | 0:c637467eeb8f | 20 | void signal_digital() |
ericbisson | 0:c637467eeb8f | 21 | { |
ericbisson | 0:c637467eeb8f | 22 | t2->signal_set(2); |
ericbisson | 0:c637467eeb8f | 23 | } |
ericbisson | 0:c637467eeb8f | 24 | |
ericbisson | 0:c637467eeb8f | 25 | void lecture_analog(void/* const *args*/) { |
ericbisson | 0:c637467eeb8f | 26 | while (true) { |
ericbisson | 0:c637467eeb8f | 27 | t1->signal_wait(1); |
ericbisson | 0:c637467eeb8f | 28 | // synchronisation sur la période d'échantillonnage |
ericbisson | 0:c637467eeb8f | 29 | // lecture de l'étampe temporelle |
ericbisson | 0:c637467eeb8f | 30 | // lecture des échantillons analogiques |
ericbisson | 0:c637467eeb8f | 31 | // calcul de la nouvelle moyenne courante |
ericbisson | 0:c637467eeb8f | 32 | // génération éventuelle d'un événement |
ericbisson | 0:c637467eeb8f | 33 | |
ericbisson | 0:c637467eeb8f | 34 | t1->signal_clr(1); |
ericbisson | 0:c637467eeb8f | 35 | t1->yield(); |
ericbisson | 0:c637467eeb8f | 36 | } |
ericbisson | 0:c637467eeb8f | 37 | } |
ericbisson | 0:c637467eeb8f | 38 | void lecture_num(void/* const *args*/) { |
ericbisson | 0:c637467eeb8f | 39 | while (true) { |
ericbisson | 0:c637467eeb8f | 40 | t2->signal_wait(2); |
ericbisson | 0:c637467eeb8f | 41 | // synchronisation sur la période d'échantillonnage |
ericbisson | 0:c637467eeb8f | 42 | // lecture de l'étampe temporelle |
ericbisson | 0:c637467eeb8f | 43 | // lecture des échantillons numériques |
ericbisson | 0:c637467eeb8f | 44 | // prise en charge du phénomène de rebond |
ericbisson | 0:c637467eeb8f | 45 | // génération éventuelle d'un événement |
ericbisson | 0:c637467eeb8f | 46 | |
ericbisson | 0:c637467eeb8f | 47 | t2->signal_clr(2); |
ericbisson | 0:c637467eeb8f | 48 | t2->yield(); |
ericbisson | 0:c637467eeb8f | 49 | } |
ericbisson | 0:c637467eeb8f | 50 | } |
ericbisson | 0:c637467eeb8f | 51 | void collection(void/* const *args*/) { |
ericbisson | 0:c637467eeb8f | 52 | while (true) { |
ericbisson | 0:c637467eeb8f | 53 | // attente et lecture d'un événement |
ericbisson | 0:c637467eeb8f | 54 | // écriture de l'événement en sortie (port série) |
ericbisson | 0:c637467eeb8f | 55 | } |
ericbisson | 0:c637467eeb8f | 56 | } |
ericbisson | 0:c637467eeb8f | 57 | int main() { |
ericbisson | 0:c637467eeb8f | 58 | // initialisation du RTC |
ericbisson | 0:c637467eeb8f | 59 | |
ericbisson | 0:c637467eeb8f | 60 | // get the current time from the terminal |
ericbisson | 0:c637467eeb8f | 61 | struct tm t; |
ericbisson | 0:c637467eeb8f | 62 | pc.printf("Enter current date and time:\n"); |
ericbisson | 0:c637467eeb8f | 63 | pc.printf("YYYY MM DD HH MM SS[enter]\n"); |
ericbisson | 0:c637467eeb8f | 64 | pc.scanf("%d %d %d %d %d %d", &t.tm_year, &t.tm_mon, &t.tm_mday |
ericbisson | 0:c637467eeb8f | 65 | , &t.tm_hour, &t.tm_min, &t.tm_sec); |
ericbisson | 0:c637467eeb8f | 66 | |
ericbisson | 0:c637467eeb8f | 67 | // adjust for tm structure required values |
ericbisson | 0:c637467eeb8f | 68 | t.tm_year = t.tm_year - 1900; |
ericbisson | 0:c637467eeb8f | 69 | t.tm_mon = t.tm_mon - 1; |
ericbisson | 0:c637467eeb8f | 70 | |
ericbisson | 0:c637467eeb8f | 71 | // set the time |
ericbisson | 0:c637467eeb8f | 72 | set_time(mktime(&t)); |
ericbisson | 0:c637467eeb8f | 73 | |
ericbisson | 0:c637467eeb8f | 74 | // démarrage des tâches |
ericbisson | 0:c637467eeb8f | 75 | t1 = new Thread(); |
ericbisson | 0:c637467eeb8f | 76 | t2 = new Thread(); |
ericbisson | 0:c637467eeb8f | 77 | t3 = new Thread(); |
ericbisson | 0:c637467eeb8f | 78 | |
ericbisson | 0:c637467eeb8f | 79 | t1->start(lecture_analog); |
ericbisson | 0:c637467eeb8f | 80 | t2->start(lecture_num); |
ericbisson | 0:c637467eeb8f | 81 | t3->start(collection); |
ericbisson | 0:c637467eeb8f | 82 | |
ericbisson | 0:c637467eeb8f | 83 | tick.attach(&signal_analog, 0.25); // fréquence de 250ms |
ericbisson | 0:c637467eeb8f | 84 | tick.attach(&signal_digital, 0.1); // fréquence de 100ms |
ericbisson | 0:c637467eeb8f | 85 | |
ericbisson | 0:c637467eeb8f | 86 | while(1) { |
ericbisson | 0:c637467eeb8f | 87 | } |
ericbisson | 0:c637467eeb8f | 88 | } |