none

Dependencies:   mbed Threads

Fork of HelloWorld by Simon Ford

Committer:
JacquesEd
Date:
Mon Jan 26 22:16:46 2015 +0000
Revision:
3:58803195db3f
Parent:
2:8d4c217c39e5
Child:
4:2857c116c1e1
now

Who changed what in which revision?

UserRevisionLine numberNew contents of line
simon 0:fb6bbc10ffa0 1 #include "mbed.h"
JacquesEd 2:8d4c217c39e5 2 //#include "rtos.h"
JacquesEd 2:8d4c217c39e5 3 DigitalIn en_1(p15);
JacquesEd 2:8d4c217c39e5 4 DigitalIn en_2(p16);
JacquesEd 2:8d4c217c39e5 5 AnalogIn ea_1(p19);
JacquesEd 2:8d4c217c39e5 6 AnalogIn ea_2(p20);
JacquesEd 2:8d4c217c39e5 7 Serial pc (USBTX, USBRX);
JacquesEd 2:8d4c217c39e5 8
JacquesEd 3:58803195db3f 9 int test[100] = {1,0,1,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,0,1,0,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,,1,1,0,1,0,0,0,1,1,0,1,0
JacquesEd 3:58803195db3f 10 ,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,1
JacquesEd 3:58803195db3f 11 ,01,1,1,1,1,1,1,0,1,0,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,0,0,1,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,};
JacquesEd 3:58803195db3f 12 int index = 0;
JacquesEd 2:8d4c217c39e5 13
JacquesEd 2:8d4c217c39e5 14 //RtosTimer time ;
JacquesEd 2:8d4c217c39e5 15
JacquesEd 2:8d4c217c39e5 16 int date = 0;
JacquesEd 2:8d4c217c39e5 17
JacquesEd 2:8d4c217c39e5 18 int taille = 100;
JacquesEd 2:8d4c217c39e5 19 int compteur = 0;
JacquesEd 2:8d4c217c39e5 20 int index = 0;
JacquesEd 2:8d4c217c39e5 21 int tableau[100][2];
JacquesEd 2:8d4c217c39e5 22
JacquesEd 2:8d4c217c39e5 23 int flag[2] = {0,1};
simon 0:fb6bbc10ffa0 24
JacquesEd 2:8d4c217c39e5 25 void lecture_analog(void const *args)
JacquesEd 2:8d4c217c39e5 26 {
JacquesEd 2:8d4c217c39e5 27 int sample[6][2];
JacquesEd 2:8d4c217c39e5 28 int i = 0;
JacquesEd 2:8d4c217c39e5 29 for (i = 0; i <6; i ++) {
JacquesEd 3:58803195db3f 30 //sample[i][0] = args.read_u16();
JacquesEd 3:58803195db3f 31 sample[i][0] = test[indext];
JacquesEd 2:8d4c217c39e5 32 // sample[i][1] = date;
JacquesEd 2:8d4c217c39e5 33 }
JacquesEd 2:8d4c217c39e5 34 i = 0;
JacquesEd 2:8d4c217c39e5 35 while (true) {
JacquesEd 2:8d4c217c39e5 36
JacquesEd 2:8d4c217c39e5 37 // synchronisation sur la période d'échantillonnage
JacquesEd 2:8d4c217c39e5 38 flag[0] = 1;
JacquesEd 2:8d4c217c39e5 39 while (flag[1] == 1)
JacquesEd 2:8d4c217c39e5 40 thread.yield();
JacquesEd 2:8d4c217c39e5 41
JacquesEd 2:8d4c217c39e5 42 // lecture de l'étampe temporelle
JacquesEd 2:8d4c217c39e5 43 //date = time.read_ms();
JacquesEd 2:8d4c217c39e5 44 // lecture des échantillons analogiques
JacquesEd 2:8d4c217c39e5 45 sample[i][0] = args.read_u16();
JacquesEd 2:8d4c217c39e5 46 i++;
JacquesEd 2:8d4c217c39e5 47
JacquesEd 2:8d4c217c39e5 48
JacquesEd 2:8d4c217c39e5 49 // calcul de la nouvelle moyenne courante
JacquesEd 2:8d4c217c39e5 50 if ((sample[i][0] - sample[(i+5)%6][0]) > 0x9FFF) {
JacquesEd 2:8d4c217c39e5 51 tableau[i][0] = 1; // 1 pr analog
JacquesEd 2:8d4c217c39e5 52 //tableau[i][1] = date;
JacquesEd 2:8d4c217c39e5 53 }
simon 0:fb6bbc10ffa0 54
JacquesEd 2:8d4c217c39e5 55 // génération éventuelle d'un événement
JacquesEd 2:8d4c217c39e5 56 if (i >= 6) i = 0;
JacquesEd 2:8d4c217c39e5 57 }
JacquesEd 2:8d4c217c39e5 58 flag[0] = 0;
JacquesEd 2:8d4c217c39e5 59 }
JacquesEd 2:8d4c217c39e5 60
JacquesEd 2:8d4c217c39e5 61 void lecture_num(void const *args)
JacquesEd 2:8d4c217c39e5 62 {
JacquesEd 2:8d4c217c39e5 63 flag[1] = 1;
JacquesEd 2:8d4c217c39e5 64 while (flag[0] == 1)
JacquesEd 2:8d4c217c39e5 65 thread.yield();
JacquesEd 2:8d4c217c39e5 66 int value[2][2];
JacquesEd 2:8d4c217c39e5 67 int i = 0;
JacquesEd 2:8d4c217c39e5 68 value[i][0] = args.read();
JacquesEd 2:8d4c217c39e5 69 //value[i][1] = date;
JacquesEd 2:8d4c217c39e5 70 while (true) {
JacquesEd 2:8d4c217c39e5 71 // synchronisation sur la période d'échantillonnage
JacquesEd 2:8d4c217c39e5 72
JacquesEd 2:8d4c217c39e5 73 // lecture de l'étampe temporelle
JacquesEd 2:8d4c217c39e5 74 //date = time.read_ms();
JacquesEd 2:8d4c217c39e5 75 // lecture des échantillons numériques
JacquesEd 2:8d4c217c39e5 76 wait_ms(100);
JacquesEd 2:8d4c217c39e5 77 i++;
JacquesEd 2:8d4c217c39e5 78 value[i][0] = args.read();
JacquesEd 2:8d4c217c39e5 79 //value[i][1] = date;
JacquesEd 2:8d4c217c39e5 80 // prise en charge du phénomène de rebond
JacquesEd 2:8d4c217c39e5 81 if (value[0][0] != value[1][0]) {
JacquesEd 2:8d4c217c39e5 82 wait_ms(50);
JacquesEd 2:8d4c217c39e5 83 int *temp = new int;
JacquesEd 2:8d4c217c39e5 84 temp = args.read();
JacquesEd 2:8d4c217c39e5 85 // génération éventuelle d'un événement
JacquesEd 2:8d4c217c39e5 86 if (temp == value[i]) {
JacquesEd 2:8d4c217c39e5 87 tableau[compteur][0] = 0; //0 pr numérique
JacquesEd 2:8d4c217c39e5 88 // tableau[compteur][1] = value[i][1];
JacquesEd 2:8d4c217c39e5 89 compteur++;
JacquesEd 2:8d4c217c39e5 90 }
JacquesEd 2:8d4c217c39e5 91 wait_ms(50);
JacquesEd 2:8d4c217c39e5 92 }
JacquesEd 2:8d4c217c39e5 93 if (i >=2) i = 0;
JacquesEd 2:8d4c217c39e5 94 }
JacquesEd 2:8d4c217c39e5 95 flag[1] = 0;
JacquesEd 2:8d4c217c39e5 96 }
JacquesEd 2:8d4c217c39e5 97
JacquesEd 2:8d4c217c39e5 98 void collection(void const *args)
JacquesEd 2:8d4c217c39e5 99 {
JacquesEd 2:8d4c217c39e5 100 int i = 0;
JacquesEd 2:8d4c217c39e5 101 while (true) {
JacquesEd 2:8d4c217c39e5 102 // attente et lecture d'un événement
JacquesEd 2:8d4c217c39e5 103
JacquesEd 2:8d4c217c39e5 104
JacquesEd 2:8d4c217c39e5 105 // écriture de l'événement en sortie (port série)
JacquesEd 2:8d4c217c39e5 106 if (tableau[i][0] == 0)
JacquesEd 2:8d4c217c39e5 107 pc.printf("event_n at: ");
JacquesEd 2:8d4c217c39e5 108 else
JacquesEd 2:8d4c217c39e5 109 pc.printf("event_a at: ");
JacquesEd 2:8d4c217c39e5 110 pc.printf ("%i", tableau[i][1]);
JacquesEd 2:8d4c217c39e5 111 i++;
simon 0:fb6bbc10ffa0 112 }
simon 0:fb6bbc10ffa0 113 }
JacquesEd 2:8d4c217c39e5 114 int main()
JacquesEd 2:8d4c217c39e5 115 {
JacquesEd 2:8d4c217c39e5 116 // initialisation du RTC
JacquesEd 2:8d4c217c39e5 117 // time.start();
JacquesEd 2:8d4c217c39e5 118 // démarrage des tâches
JacquesEd 2:8d4c217c39e5 119 while(1) {
JacquesEd 2:8d4c217c39e5 120 // creation des threads
JacquesEd 2:8d4c217c39e5 121 Thread event_n1 = new Thread(new lecture_num(en_1));
JacquesEd 2:8d4c217c39e5 122 Thread event_n2 = new Thread(new lecture_num(en_2));
JacquesEd 2:8d4c217c39e5 123 Thread event_a1 = new Thread(new lecture_analog(ea_1));
JacquesEd 2:8d4c217c39e5 124 Thread event_a2 = new Thread(new lecture_analog(ea_2));
JacquesEd 2:8d4c217c39e5 125
JacquesEd 2:8d4c217c39e5 126 event_n1.start();
JacquesEd 2:8d4c217c39e5 127 event_n2.start();
JacquesEd 2:8d4c217c39e5 128 event_a1.start();
JacquesEd 2:8d4c217c39e5 129 event_a2.start();
JacquesEd 2:8d4c217c39e5 130 }
JacquesEd 2:8d4c217c39e5 131 // time.stop();
JacquesEd 2:8d4c217c39e5 132 }