asd

Dependencies:   mbed-rtos mbed RTC

Committer:
manl2003
Date:
Mon Jan 25 18:03:29 2016 +0000
Revision:
2:ebbca46b415f
Parent:
1:7b379ec59b5d
Child:
3:1c077a1de3e5
asd

Who changed what in which revision?

UserRevisionLine numberNew contents of line
manl2003 0:b4d43279883c 1 #include "mbed.h"
manl2003 0:b4d43279883c 2 #include "rtos.h"
manl2003 0:b4d43279883c 3
manl2003 0:b4d43279883c 4 /*
manl2003 0:b4d43279883c 5 DigitalOut led1(LED1);
manl2003 0:b4d43279883c 6 DigitalOut led2(LED2);
manl2003 0:b4d43279883c 7 DigitalIn sw1(p15);
manl2003 0:b4d43279883c 8 DigitalIn sw2(p16);
manl2003 0:b4d43279883c 9
manl2003 0:b4d43279883c 10 Mutex mute;
manl2003 0:b4d43279883c 11 Queue<string, 5> mb;
manl2003 0:b4d43279883c 12
manl2003 0:b4d43279883c 13
manl2003 0:b4d43279883c 14 void producer_Thread(void const *args)
manl2003 0:b4d43279883c 15 {
manl2003 0:b4d43279883c 16 while (true) {
manl2003 0:b4d43279883c 17 mute.lock();
manl2003 0:b4d43279883c 18 mb.alloc
manl2003 0:b4d43279883c 19 mute.unlock();
manl2003 0:b4d43279883c 20 }
manl2003 0:b4d43279883c 21 }
manl2003 0:b4d43279883c 22 void consumer_Thread(void const *args)
manl2003 0:b4d43279883c 23 {
manl2003 0:b4d43279883c 24 while (true) {
manl2003 0:b4d43279883c 25 mute.lock();
manl2003 0:b4d43279883c 26 led1 = 0;
manl2003 0:b4d43279883c 27 led2 = 0;
manl2003 0:b4d43279883c 28 wait(0.5);
manl2003 0:b4d43279883c 29 mute.unlock();
manl2003 0:b4d43279883c 30 }
manl2003 0:b4d43279883c 31 }
manl2003 0:b4d43279883c 32
manl2003 0:b4d43279883c 33 int main()
manl2003 0:b4d43279883c 34 {
manl2003 0:b4d43279883c 35 Thread thread1(producer_Thread);
manl2003 0:b4d43279883c 36 Thread thread2(consumer_Thread);
manl2003 0:b4d43279883c 37 while (true) {
manl2003 0:b4d43279883c 38 }
manl2003 0:b4d43279883c 39 } */
manl2003 0:b4d43279883c 40
manl2003 0:b4d43279883c 41 //Pins
manl2003 0:b4d43279883c 42 DigitalIn en_1(p15);
manl2003 0:b4d43279883c 43 DigitalIn en_2(p16);
manl2003 0:b4d43279883c 44 AnalogIn ea_1(p19);
manl2003 0:b4d43279883c 45 AnalogIn ea_2(p20);
manl2003 0:b4d43279883c 46
manl2003 0:b4d43279883c 47 //Constantes
manl2003 0:b4d43279883c 48 #define FREQ_NUM_MS 100
manl2003 0:b4d43279883c 49 #define FREQ_ANAL_MS 250
manl2003 0:b4d43279883c 50 #define FREQ_NUM_STAB_MS 50
manl2003 0:b4d43279883c 51
manl2003 0:b4d43279883c 52 #define SIGNAL_NUM 0x1
manl2003 0:b4d43279883c 53 #define SIGNAL_ANAL 0x2
manl2003 0:b4d43279883c 54
manl2003 0:b4d43279883c 55 #define NIVEAU_DC_ANAL 3.3
manl2003 0:b4d43279883c 56 #define SEUIL_ANAL 1.125
manl2003 0:b4d43279883c 57
manl2003 2:ebbca46b415f 58 struct AnalArgs
manl2003 2:ebbca46b415f 59 {
manl2003 2:ebbca46b415f 60 AnalogIn* In;
manl2003 2:ebbca46b415f 61 //Mailbox
manl2003 2:ebbca46b415f 62 };
manl2003 2:ebbca46b415f 63
manl2003 0:b4d43279883c 64 void lecture_analog(void const *args) {
manl2003 2:ebbca46b415f 65 AnalArgs *analArgs = (AnalArgs*)args;
manl2003 2:ebbca46b415f 66
manl2003 0:b4d43279883c 67 bool premiereLectureDispo = false;
manl2003 0:b4d43279883c 68 int echantillonsAnal[5] = {0, 0, 0, 0, 0};
manl2003 0:b4d43279883c 69 int compteur = 0;
manl2003 0:b4d43279883c 70 float moyenneCourante = 0;
manl2003 0:b4d43279883c 71
manl2003 0:b4d43279883c 72 while (true)
manl2003 0:b4d43279883c 73 {
manl2003 0:b4d43279883c 74 // lecture des échantillons analogiques
manl2003 2:ebbca46b415f 75 echantillonsAnal[compteur] = *analArgs->In;
manl2003 0:b4d43279883c 76 // calcul de la nouvelle moyenne courante
manl2003 0:b4d43279883c 77 if(premiereLectureDispo == true)
manl2003 0:b4d43279883c 78 {
manl2003 0:b4d43279883c 79 moyenneCourante = 0;
manl2003 0:b4d43279883c 80 for(int i = 0; i < 5; i++)
manl2003 0:b4d43279883c 81 {
manl2003 0:b4d43279883c 82 moyenneCourante += echantillonsAnal[i];
manl2003 0:b4d43279883c 83 }
manl2003 0:b4d43279883c 84 moyenneCourante = moyenneCourante / 5;
manl2003 0:b4d43279883c 85 }
manl2003 0:b4d43279883c 86
manl2003 0:b4d43279883c 87 compteur++;
manl2003 0:b4d43279883c 88 if(compteur >= 5)
manl2003 0:b4d43279883c 89 {
manl2003 0:b4d43279883c 90 compteur = 0;
manl2003 0:b4d43279883c 91 premiereLectureDispo = true;
manl2003 0:b4d43279883c 92 }
manl2003 0:b4d43279883c 93 // génération éventuelle d'un événement
manl2003 0:b4d43279883c 94 if(moyenneCourante > SEUIL_ANAL * NIVEAU_DC_ANAL)
manl2003 0:b4d43279883c 95 {
manl2003 0:b4d43279883c 96 //Générer un évènement
manl2003 0:b4d43279883c 97 }
manl2003 0:b4d43279883c 98 }
manl2003 0:b4d43279883c 99 }
manl2003 0:b4d43279883c 100
manl2003 0:b4d43279883c 101
manl2003 2:ebbca46b415f 102 struct NumArgs
manl2003 2:ebbca46b415f 103 {
manl2003 2:ebbca46b415f 104 DigitalIn *In;
manl2003 2:ebbca46b415f 105 };
manl2003 2:ebbca46b415f 106
manl2003 0:b4d43279883c 107 void lecture_num(void const *args) {
manl2003 2:ebbca46b415f 108 NumArgs *numArgs = (NumArgs*)args;
manl2003 2:ebbca46b415f 109
manl2003 0:b4d43279883c 110 bool lecture, lecturePrecedente;
manl2003 0:b4d43279883c 111 while (true)
larryspaghetti 1:7b379ec59b5d 112 {
manl2003 0:b4d43279883c 113 // lecture des échantillons numériques
larryspaghetti 1:7b379ec59b5d 114 //TODO, généralisé la fonction
manl2003 2:ebbca46b415f 115 bool lectureDebut = numArgs->In->read();
manl2003 0:b4d43279883c 116 wait_ms(FREQ_NUM_STAB_MS);
manl2003 2:ebbca46b415f 117 if(lectureDebut == numArgs->In->read())
manl2003 0:b4d43279883c 118 {
larryspaghetti 1:7b379ec59b5d 119
manl2003 0:b4d43279883c 120 }
manl2003 0:b4d43279883c 121
larryspaghetti 1:7b379ec59b5d 122 // prise en charge du phénomène de rebond
larryspaghetti 1:7b379ec59b5d 123 // génération éventuelle d'un événement
larryspaghetti 1:7b379ec59b5d 124 }
manl2003 0:b4d43279883c 125 }
manl2003 0:b4d43279883c 126
manl2003 0:b4d43279883c 127 void collection(void const *args) {
manl2003 0:b4d43279883c 128 while (true)
manl2003 0:b4d43279883c 129 {
larryspaghetti 1:7b379ec59b5d 130 // attente et lecture d'un événement
larryspaghetti 1:7b379ec59b5d 131 // écriture de l'événement en sortie (port série)
manl2003 0:b4d43279883c 132 }
manl2003 0:b4d43279883c 133 }
manl2003 0:b4d43279883c 134
manl2003 0:b4d43279883c 135
manl2003 0:b4d43279883c 136
manl2003 0:b4d43279883c 137 void signaler() {
larryspaghetti 1:7b379ec59b5d 138 RtosTimer anal_timer(lecture_num, osTimerPeriodic, NULL);
larryspaghetti 1:7b379ec59b5d 139 RtosTimer num_timer(lecture_analog, osTimerPeriodic, NULL);
manl2003 0:b4d43279883c 140
larryspaghetti 1:7b379ec59b5d 141 anal_timer.start(FREQ_ANAL_MS);
larryspaghetti 1:7b379ec59b5d 142 num_timer.start(FREQ_NUM_MS);
larryspaghetti 1:7b379ec59b5d 143
larryspaghetti 1:7b379ec59b5d 144 //Thread thread_Anal(lecture_analog);
larryspaghetti 1:7b379ec59b5d 145 //Thread thread_Num(lecture_num);
manl2003 0:b4d43279883c 146 //Transitionner vers RTOS_TImer
larryspaghetti 1:7b379ec59b5d 147 //while (true)
larryspaghetti 1:7b379ec59b5d 148 //{
larryspaghetti 1:7b379ec59b5d 149 // thread_Anal.signal_set(SIGNAL_ANAL);
larryspaghetti 1:7b379ec59b5d 150 // thread_Num.signal_set(SIGNAL_NUM);
larryspaghetti 1:7b379ec59b5d 151 //}
manl2003 0:b4d43279883c 152 }
manl2003 0:b4d43279883c 153
manl2003 0:b4d43279883c 154 int main() {
larryspaghetti 1:7b379ec59b5d 155 // initialisation du RTC
larryspaghetti 1:7b379ec59b5d 156 set_time(1453667014);
larryspaghetti 1:7b379ec59b5d 157 // démarrage des tâches
larryspaghetti 1:7b379ec59b5d 158 while(1) {
larryspaghetti 1:7b379ec59b5d 159 }
manl2003 0:b4d43279883c 160 }