squelette de demarrage projet ERS3 IUT NICE GEII

Dependencies:   mbed bloc_io mbed-rtos html EthernetInterface

Committer:
superphil06
Date:
Sat Aug 22 15:51:59 2015 +0000
Revision:
0:e30c9ba95bd4
Child:
1:545a3d6b5933
squelette programme ERS3

Who changed what in which revision?

UserRevisionLine numberNew contents of line
superphil06 0:e30c9ba95bd4 1
superphil06 0:e30c9ba95bd4 2
superphil06 0:e30c9ba95bd4 3 //#include "EthernetInterface.h"
superphil06 0:e30c9ba95bd4 4 #include <stdlib.h>
superphil06 0:e30c9ba95bd4 5 #include <string.h>
superphil06 0:e30c9ba95bd4 6 #include "mbed.h"
superphil06 0:e30c9ba95bd4 7 #include "rtos.h" // need for main thread sleep
superphil06 0:e30c9ba95bd4 8 #include "html.h" // need for html patch working with web server
superphil06 0:e30c9ba95bd4 9 #include "bloc_io.h"
superphil06 0:e30c9ba95bd4 10 #define RADIUS 0.2F // wheel size
superphil06 0:e30c9ba95bd4 11 #define NBPOLES 8 // magnetic pole number
superphil06 0:e30c9ba95bd4 12 #define DELTA_T 0.1F // speed measurement counting period
superphil06 0:e30c9ba95bd4 13
superphil06 0:e30c9ba95bd4 14
superphil06 0:e30c9ba95bd4 15 Bloc_IO MyPLD(p25,p26,p5,p6,p7,p8,p9,p10,p23,p24);// instantiate object needed to communicate with PLD
superphil06 0:e30c9ba95bd4 16 // analog input connected to mbed
superphil06 0:e30c9ba95bd4 17 // valid pmw mbed pin
superphil06 0:e30c9ba95bd4 18 Serial pc(USBTX, USBRX); // tx, rx
superphil06 0:e30c9ba95bd4 19 // Top_Hall Pin
superphil06 0:e30c9ba95bd4 20
superphil06 0:e30c9ba95bd4 21
superphil06 0:e30c9ba95bd4 22
superphil06 0:e30c9ba95bd4 23
superphil06 0:e30c9ba95bd4 24 /************ persistent file parameters section *****************/
superphil06 0:e30c9ba95bd4 25 LocalFileSystem local("local"); // Create the local filesystem under the name "local"
superphil06 0:e30c9ba95bd4 26
superphil06 0:e30c9ba95bd4 27
superphil06 0:e30c9ba95bd4 28
superphil06 0:e30c9ba95bd4 29
superphil06 0:e30c9ba95bd4 30
superphil06 0:e30c9ba95bd4 31
superphil06 0:e30c9ba95bd4 32
superphil06 0:e30c9ba95bd4 33 /********************* web server section **********************************/
superphil06 0:e30c9ba95bd4 34
superphil06 0:e30c9ba95bd4 35 var_field_t tab_balise[10]; //une balise est présente dans le squelette
superphil06 0:e30c9ba95bd4 36 int giCounter=0;// acces counting
superphil06 0:e30c9ba95bd4 37
superphil06 0:e30c9ba95bd4 38
superphil06 0:e30c9ba95bd4 39 /*********************** can bus section ************/
superphil06 0:e30c9ba95bd4 40 // determine message ID used to send Gaz ref over can bus
superphil06 0:e30c9ba95bd4 41 #define _CAN_DEBUG // used to debug can bus activity
superphil06 0:e30c9ba95bd4 42 //#define USE_CAN_REF // uncomment to receive gaz ref over can_bus
superphil06 0:e30c9ba95bd4 43 CAN can_port (p30, p29); // initialisation du Bus CAN sur les broches 30 (rd) et 29(td) for lpc1768 + mbed shield
superphil06 0:e30c9ba95bd4 44 bool bCan_Active=false;
superphil06 0:e30c9ba95bd4 45
superphil06 0:e30c9ba95bd4 46
superphil06 0:e30c9ba95bd4 47
superphil06 0:e30c9ba95bd4 48 DigitalOut led1(LED1); //initialisation des Leds présentes sur le micro-controleur Mbed*/
superphil06 0:e30c9ba95bd4 49 DigitalOut led2(LED2);
superphil06 0:e30c9ba95bd4 50 DigitalOut led3(LED3); // blink when can message is sent
superphil06 0:e30c9ba95bd4 51 DigitalOut led4(LED4); // blink when can message is received
superphil06 0:e30c9ba95bd4 52
superphil06 0:e30c9ba95bd4 53
superphil06 0:e30c9ba95bd4 54
superphil06 0:e30c9ba95bd4 55
superphil06 0:e30c9ba95bd4 56
superphil06 0:e30c9ba95bd4 57 //************ local function prototypes *******************
superphil06 0:e30c9ba95bd4 58
superphil06 0:e30c9ba95bd4 59
superphil06 0:e30c9ba95bd4 60
superphil06 0:e30c9ba95bd4 61
superphil06 0:e30c9ba95bd4 62
superphil06 0:e30c9ba95bd4 63
superphil06 0:e30c9ba95bd4 64
superphil06 0:e30c9ba95bd4 65 /**************** Read persistent data from text file located on local file system ****************/
superphil06 0:e30c9ba95bd4 66
superphil06 0:e30c9ba95bd4 67
superphil06 0:e30c9ba95bd4 68
superphil06 0:e30c9ba95bd4 69 /**************** write persitant data to text file located on local file system ****************/
superphil06 0:e30c9ba95bd4 70
superphil06 0:e30c9ba95bd4 71
superphil06 0:e30c9ba95bd4 72
superphil06 0:e30c9ba95bd4 73
superphil06 0:e30c9ba95bd4 74
superphil06 0:e30c9ba95bd4 75
superphil06 0:e30c9ba95bd4 76 //************** calibation gaz function needed to record min_gaz and max_gaz value to persistent text file ******************
superphil06 0:e30c9ba95bd4 77
superphil06 0:e30c9ba95bd4 78
superphil06 0:e30c9ba95bd4 79 // ************top hall counting interrupt needed for speed measurement
superphil06 0:e30c9ba95bd4 80
superphil06 0:e30c9ba95bd4 81
superphil06 0:e30c9ba95bd4 82 //********************** timer interrupt for speed measurement each 100ms *************************
superphil06 0:e30c9ba95bd4 83
superphil06 0:e30c9ba95bd4 84
superphil06 0:e30c9ba95bd4 85
superphil06 0:e30c9ba95bd4 86
superphil06 0:e30c9ba95bd4 87
superphil06 0:e30c9ba95bd4 88
superphil06 0:e30c9ba95bd4 89 //********************* Timer Interrupt for gaz ref management each 10ms ********************
superphil06 0:e30c9ba95bd4 90
superphil06 0:e30c9ba95bd4 91
superphil06 0:e30c9ba95bd4 92
superphil06 0:e30c9ba95bd4 93 /********* main cgi function used to patch data to the web server thread **********************************/
superphil06 0:e30c9ba95bd4 94 void CGI_Function(void) // cgi function that patch web data to empty web page
superphil06 0:e30c9ba95bd4 95 { char ma_chaine4[20]={};// needed to form html response
superphil06 0:e30c9ba95bd4 96
superphil06 0:e30c9ba95bd4 97 }
superphil06 0:e30c9ba95bd4 98
superphil06 0:e30c9ba95bd4 99
superphil06 0:e30c9ba95bd4 100 /*********************** CAN BUS SECTION **********************/
superphil06 0:e30c9ba95bd4 101
superphil06 0:e30c9ba95bd4 102
superphil06 0:e30c9ba95bd4 103
superphil06 0:e30c9ba95bd4 104 void CAN_REC_THREAD(void const *args)
superphil06 0:e30c9ba95bd4 105 { int iCount,iError;
superphil06 0:e30c9ba95bd4 106
superphil06 0:e30c9ba95bd4 107 while (bCan_Active)
superphil06 0:e30c9ba95bd4 108 {Thread::wait(100);// wait 100ms
superphil06 0:e30c9ba95bd4 109 // code todo
superphil06 0:e30c9ba95bd4 110
superphil06 0:e30c9ba95bd4 111 }
superphil06 0:e30c9ba95bd4 112
superphil06 0:e30c9ba95bd4 113 }
superphil06 0:e30c9ba95bd4 114
superphil06 0:e30c9ba95bd4 115
superphil06 0:e30c9ba95bd4 116
superphil06 0:e30c9ba95bd4 117 //*************************** main function *****************************************
superphil06 0:e30c9ba95bd4 118 int main() {
superphil06 0:e30c9ba95bd4 119 char cChoix=0;
superphil06 0:e30c9ba95bd4 120
superphil06 0:e30c9ba95bd4 121
superphil06 0:e30c9ba95bd4 122
superphil06 0:e30c9ba95bd4 123
superphil06 0:e30c9ba95bd4 124
superphil06 0:e30c9ba95bd4 125 //***************************************** web section ********************************************/
superphil06 0:e30c9ba95bd4 126 //Init_Web_Server(&CGI_Function); // create and initialize tcp server socket and pass function pointer to local CGI function
superphil06 0:e30c9ba95bd4 127 //Thread WebThread(Web_Server_Thread);// create and launch web server thread
superphil06 0:e30c9ba95bd4 128 /********* main cgi function used to patch data to the web server thread **********************************/
superphil06 0:e30c9ba95bd4 129
superphil06 0:e30c9ba95bd4 130 //******************************************* end web section ************************************* /
superphil06 0:e30c9ba95bd4 131
superphil06 0:e30c9ba95bd4 132
superphil06 0:e30c9ba95bd4 133
superphil06 0:e30c9ba95bd4 134
superphil06 0:e30c9ba95bd4 135 pc.printf(" programme scooter mbed \n");
superphil06 0:e30c9ba95bd4 136
superphil06 0:e30c9ba95bd4 137
superphil06 0:e30c9ba95bd4 138
superphil06 0:e30c9ba95bd4 139 //********************* can bus section initialisation *******************************************
superphil06 0:e30c9ba95bd4 140 //bCan_Active=true;// needed to lauchn CAN thread
superphil06 0:e30c9ba95bd4 141 //Thread CanThread(CAN_REC_THREAD);// create and launch can receiver thread
superphil06 0:e30c9ba95bd4 142 //********************* end can bus section *****************************************************
superphil06 0:e30c9ba95bd4 143
superphil06 0:e30c9ba95bd4 144
superphil06 0:e30c9ba95bd4 145 while(cChoix!='q' and cChoix!='Q')
superphil06 0:e30c9ba95bd4 146 {pc.printf(" veuillez saisir un choix parmi la liste proposee: \n");
superphil06 0:e30c9ba95bd4 147 pc.printf(" a:saisie consigne pwm \n");
superphil06 0:e30c9ba95bd4 148 pc.printf(" q:quitter \n");
superphil06 0:e30c9ba95bd4 149
superphil06 0:e30c9ba95bd4 150 /************* multithreading : main thread need to sleep in order to allow web response */
superphil06 0:e30c9ba95bd4 151 while (pc.readable()==0) // determine if char availabler
superphil06 0:e30c9ba95bd4 152 {Thread::wait(10);} // wait 10 until char available on serial input
superphil06 0:e30c9ba95bd4 153 /************* end of main thread sleep ****************/
superphil06 0:e30c9ba95bd4 154
superphil06 0:e30c9ba95bd4 155 pc.scanf(" %c",&cChoix);
superphil06 0:e30c9ba95bd4 156 switch (cChoix){
superphil06 0:e30c9ba95bd4 157 case 'a':
superphil06 0:e30c9ba95bd4 158 break;
superphil06 0:e30c9ba95bd4 159 case 'q':
superphil06 0:e30c9ba95bd4 160 break;
superphil06 0:e30c9ba95bd4 161 }
superphil06 0:e30c9ba95bd4 162 } // end while
superphil06 0:e30c9ba95bd4 163
superphil06 0:e30c9ba95bd4 164 //************** thread deinit *********************
superphil06 0:e30c9ba95bd4 165 //DeInit_Web_Server();
superphil06 0:e30c9ba95bd4 166 //bCan_Active=false;
superphil06 0:e30c9ba95bd4 167 //CanThread=false;// close can received thread
superphil06 0:e30c9ba95bd4 168 pc.printf(" fin programme scooter mbed \n");
superphil06 0:e30c9ba95bd4 169 } // end main