Index: branch/sotty/Emb_App.tws
===================================================================
--- branch/sotty/Emb_App.tws	(revision 198)
+++ branch/sotty/Emb_App.tws	(revision 199)
@@ -8,14 +8,16 @@
 [BREAKPOINTS]
 [OPEN_WORKSPACE_FILES]
 "E:\tp_info6_2018_sotty\bsp\periph.c" 
+"E:\tp_info6_2018_sotty\bsp\uart0.c" 
 "E:\tp_info6_2018_sotty\Emb_App\conf_noyau.cfg" 
 "E:\tp_info6_2018_sotty\Emb_App\crt0mr.a30" 
 "E:\tp_info6_2018_sotty\Emb_App\programme_principal_etud.c" 
 [WORKSPACE_FILE_STATES]
 "E:\tp_info6_2018_sotty\Emb_App\conf_noyau.cfg" 0 0 1380 431 0 3 
-"E:\tp_info6_2018_sotty\Emb_App\crt0mr.a30" -8 -30 1596 669 1 2 
-"E:\tp_info6_2018_sotty\Emb_App\programme_principal_etud.c" 25 25 1426 347 0 0 
+"E:\tp_info6_2018_sotty\Emb_App\crt0mr.a30" 0 0 1596 669 0 2 
+"E:\tp_info6_2018_sotty\Emb_App\programme_principal_etud.c" -8 -30 1596 669 1 0 
 "E:\tp_info6_2018_sotty\bsp\periph.c" 50 50 1430 351 0 1 
+"E:\tp_info6_2018_sotty\bsp\uart0.c" 100 100 1380 431 0 4 
 [LOADED_PROJECTS]
 "EmbM32C87App" 
 [END]
Index: branch/sotty/Emb_App/SessionM32C_E8a_system.ini
===================================================================
--- branch/sotty/Emb_App/SessionM32C_E8a_system.ini	(revision 198)
+++ branch/sotty/Emb_App/SessionM32C_E8a_system.ini	(revision 199)
@@ -25,4 +25,4 @@
 [Target]
 M32C E8a SYSTEM=Renesas Communications
 [USER_DATA]
-RESET=ff001a
+RESET=ff002a
Index: branch/sotty/Emb_App/SessionM32C_E8a_system.hsf
===================================================================
--- branch/sotty/Emb_App/SessionM32C_E8a_system.hsf	(revision 198)
+++ branch/sotty/Emb_App/SessionM32C_E8a_system.hsf	(revision 199)
@@ -141,20 +141,20 @@
 "{55384715-F881-421C-A548-D7D1ABE158E1}PDMRWndInstanceKey0" "{WK_00000001_PDMR}EmbM32C87AppSessionM32C_E8a_system" 
 "{64753FED-D387-4B8C-A91D-D3419C869C07}C_EVAL_DENORMAL_MODE" "0" 
 "{64753FED-D387-4B8C-A91D-D3419C869C07}C_EVAL_ROUND_MODE" "0" 
-"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_0" "0000000000000000" 
-"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_1" "0000000000000000" 
+"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_0" "0000000000004044" 
+"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_1" "0000000000000120" 
 "{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_10" "0000000000000000" 
 "{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_11" "0000000000000000" 
 "{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_12" "0000000000000000" 
 "{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_13" "0000000000000000" 
 "{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_14" "0000000000000000" 
-"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_15" "0000000000000000" 
-"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_16" "0000000000FF0016" 
-"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_17" "0000000000000000" 
-"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_18" "0000000000000000" 
-"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_19" "0000000000000700" 
-"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_2" "0000000000000000" 
-"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_20" "0000000000000000" 
+"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_15" "0000000000000512" 
+"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_16" "0000000000FF0584" 
+"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_17" "0000000000FFF800" 
+"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_18" "00000000000009A2" 
+"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_19" "00000000000007FE" 
+"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_2" "0000000000000512" 
+"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_20" "0000000000004044" 
 "{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_21" "0000000000000000" 
 "{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_22" "0000000000000000" 
 "{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_23" "0000000000000000" 
@@ -169,12 +169,12 @@
 "{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_31" "0000000000000000" 
 "{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_32" "0000000000000000" 
 "{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_33" "0000000000000000" 
-"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_34" "0000000000000000" 
+"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_34" "000000000000036A" 
 "{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_35" "0000000000000000" 
-"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_4" "0000000000000000" 
+"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_4" "0000000000000008" 
 "{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_5" "0000000000000000" 
-"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_6" "0000000000000000" 
-"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_7" "0000000000000000" 
+"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_6" "00000000000009DC" 
+"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_7" "0000000000000512" 
 "{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_8" "0000000000000000" 
 "{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_9" "0000000000000000" 
 "{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_COUNT" "36" 
@@ -199,7 +199,7 @@
 "{AC411480-6F0A-11D5-8EB6-00004CC34E9D}ECX_IMAGE_VIEW" "0,0,0,0,0,0" 
 "{AC411480-6F0A-11D5-8EB6-00004CC34E9D}ImageCtrlViews" "0" 
 "{B266D880-6FA1-11D5-8613-00A024591A38}WatchCtrlViews" "4" 
-"{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd0ColWidth0" "148" 
+"{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd0ColWidth0" "237" 
 "{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd0ColWidth1" "186" 
 "{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd0ColWidth12" "200" 
 "{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd0ColWidth2" "120" 
@@ -209,7 +209,11 @@
 "{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd0ECX_WATCH_ITEM0000_SCOPE" "Global," 
 "{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd0ECX_WATCH_ITEM0001" "k, 10, 0, P, Col, Hex, N" 
 "{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd0ECX_WATCH_ITEM0001_SCOPE" "Current Scope," 
-"{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd0ECX_WATCH_ITEMCnt" "2" 
+"{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd0ECX_WATCH_ITEM0002" "distance_mesuree, 1, 0, P, Col, Dec, MA" 
+"{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd0ECX_WATCH_ITEM0002_SCOPE" "Current Scope," 
+"{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd0ECX_WATCH_ITEM0003" "reponse, 10, 0, P, Col, Hex, N" 
+"{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd0ECX_WATCH_ITEM0003_SCOPE" "Current Scope," 
+"{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd0ECX_WATCH_ITEMCnt" "4" 
 "{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd1ColWidth0" "120" 
 "{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd1ColWidth1" "150" 
 "{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd1ColWidth12" "200" 
@@ -279,14 +283,14 @@
 0 
 [WINDOW_POSITION_STATE_DATA_VD1]
 "Help" "TOOLBAR 0" 59419 2 4 "0.00" 0 0 0 0 0 17 0 "" "0.0" 
-"{WK_00000001_CmdLine}" "WINDOW" 59422 0 1 "0.09" 235 0 0 350 200 17 0 "32771|32772|32778|<<separator>>|32773|32774|<<separator>>|32820|<<separator>>|32801|32824" "0.0" 
+"{WK_00000001_CmdLine}" "WINDOW" 59422 0 1 "0.08" 235 0 0 350 200 17 0 "32771|32772|32778|<<separator>>|32773|32774|<<separator>>|32820|<<separator>>|32801|32824" "0.0" 
 "{WK_00000001_DISASSEMBLY}" "WINDOW" 0 0 0 "0.00" 0 -4 -30 948 486 9 0 "" "0.0" 
 "{WK_00000001_EVENT}EmbM32C87AppSessionM32C_E8a_system" "WINDOW" 59422 0 0 "0.11" 235 0 0 350 200 18 0 "32774|32775|32777|<<separator>>|32780|<<separator>>" "0.0" 
 "{WK_00000001_MEMORY}EmbM32C87AppSessionM32C_E8a_system" "WINDOW" 59422 0 1 "0.23" 365 2 -1 350 200 2065 0 "42202|42203|42204|42233|<<separator>>|42206|42205|42230|42229|42207|<<separator>>|42208|42209|42210|49076|42228|42227|<<separator>>|42231|42232|42234|42235|<<separator>>|42211|<<separator>>|32796|32797" "0.0" 
-"{WK_00000001_OUTPUT}" "WINDOW" 59422 0 2 "0.47" 235 0 0 350 200 18 0 "36756|36757|36758|36759|<<separator>>|36746|36747|<<separator>>|39531|<<separator>>|39500|39534|<<separator>>|36687" "0.0" 
-"{WK_00000001_PDMR}EmbM32C87AppSessionM32C_E8a_system" "WINDOW" 59422 0 3 "0.25" 235 0 0 350 200 18 0 "47300|47301|47302|47303|47304|47305|47314|47306|47307|47308|47311|47312|47313|42211|42509|42303" "0.0" 
+"{WK_00000001_OUTPUT}" "WINDOW" 59422 0 2 "0.29" 235 0 0 350 200 18 0 "36756|36757|36758|36759|<<separator>>|36746|36747|<<separator>>|39531|<<separator>>|39500|39534|<<separator>>|36687" "0.0" 
+"{WK_00000001_PDMR}EmbM32C87AppSessionM32C_E8a_system" "WINDOW" 59422 0 3 "0.10" 235 0 0 350 200 18 0 "47300|47301|47302|47303|47304|47305|47314|47306|47307|47308|47311|47312|47313|42211|42509|42303" "0.0" 
 "{WK_00000001_REGISTERS}EmbM32C87AppSessionM32C_E8a_system" "WINDOW" 59421 0 0 "1.00" 236 0 0 350 200 2065 0 "" "0.0" 
-"{WK_00000001_WATCH}EmbM32C87AppSessionM32C_E8a_system" "WINDOW" 59422 0 4 "0.17" 235 0 0 350 200 18 0 "32781|32783|<<separator>>|32771|32772|32773|<<separator>>|32786|<<separator>>|32810|32811" "0.0" 
+"{WK_00000001_WATCH}EmbM32C87AppSessionM32C_E8a_system" "WINDOW" 59422 0 4 "0.50" 235 0 0 350 200 18 0 "32781|32783|<<separator>>|32771|32772|32773|<<separator>>|32786|<<separator>>|32810|32811" "0.0" 
 "{WK_00000002_WORKSPACE}" "WINDOW" 59420 0 0 "1.00" 308 0 0 350 200 18 0 "" "0.0" 
 "{WK_TB00000001_STANDARD}" "TOOLBAR 0" 59419 0 2 "0.00" 0 0 0 0 0 18 0 "" "0.0" 
 "{WK_TB00000002_EDITOR}" "TOOLBAR 0" 59419 0 0 "0.00" 0 0 0 0 0 18 0 "" "0.0" 
@@ -315,6 +319,7 @@
 "E:\tp_info6_2018_sotty\Emb_App\programme_principal_etud.c" 
 "E:\tp_info6_2018_sotty\Emb_App\conf_noyau.cfg" 
 "E:\tp_info6_2018_sotty\bsp\periph.c" 
+"E:\tp_info6_2018_sotty\bsp\uart0.c" 
 [TARGET_NAME]
 "M32C E8a SYSTEM" "" 0 
 [STATUSBAR_STATEINFO_VD1]
@@ -361,5 +366,5 @@
 [FLASH_DETAILS]
 "" 0 0 "" 0 "" 0 0 "" 0 0 0 0 0 0 0 "" "" "" "" "" 
 [BREAKPOINTS]
-"d:\profs\tp_info14_travail\tp_info14\emb_app\programme_principal_etud.c" 95 92408704 1 "{00000000-0000-0000-C000-000000000046}" "" 
+"d:\profs\tp_info14_travail\tp_info14\emb_app\programme_principal_etud.c" 95 91096424 1 "{00000000-0000-0000-C000-000000000046}" "" 
 [END]
Index: branch/sotty/Emb_App/programme_principal_etud.c
===================================================================
--- branch/sotty/Emb_App/programme_principal_etud.c	(revision 198)
+++ branch/sotty/Emb_App/programme_principal_etud.c	(revision 199)
@@ -119,35 +119,38 @@
 //				disponible. 0xab avec a-> nombre de couleurs bien placées et b -> couleurs présentes mais mal placées.
 //'I'/73/Ox49 : Définition du nom du véhicule. Doit débuter par le caractère '#' et entraine le chargement de la configuration de piste
 //				correspondant au nom du véhicule si le nom se termine par '*'
+
+// Definition des codes commandes et requetes
+#define VITESSE_ROUES 'V'
+#define ANGLE_ROUES 'D'
+#define VITESSE_TOURELLE 'T'
+#define ANGLE_TOURELLE 'R'
+#define DISTANCE_TELEMETRE 'U'
+#define MODE_COURSE 'M'
+#define INFO_CAPTEUR 'C'
+
 
-
-void rotation_tourelle(void);
-short position_tourelle(void);
+void init(void);
+void rotation_tourelle(short angle);
+int position_tourelle(void);
 void asserv_tourelle(VP_INT stacd);
 short distance_telemetre(void);
 void vitesse_roue(char vitesse);
 void angle_roue(short angle);
-void asserv_angle_roue(void);
+void asserv_roue(void);
+int send_requete(unsigned char id_periph);
+void send_commande(unsigned char id_periph, short val);
 
 
-short distance_mesuree = 0;
-const distance_au_centre = 719;
+short distance_mur = 0;
+short angle_tourelle = 450;
+short vit_roue = 30;
 
 void main()
 {
-	ports_mcu();
-    lcd_init();
-	periph_init();
-	periph_nom("#AutoTest*");
-
-    can_init();
-    clavier_init(1);
-	capture_init();
-
-	sta_cyc(ID_acqui);
-	sta_tsk(ID_asserv_tourelle);
-//	sta_tsk(ID_periph_rx);
-
+	init();
+
+	//dly_tsk(1000);
     while(1)
     {
 		LED_J=1;
@@ -154,9 +157,8 @@
 		dly_tsk(100);
 		LED_J=0;
 		
-		distance_mesuree = distance_telemetre();
-		vitesse_roue(10);
-		asserv_angle_roue();
+		
+		asserv_roue();
     }
 }
 
@@ -166,29 +168,16 @@
 }
 
 
-void rotation_tourelle()
-{
-	CanFrame comm;
-	
-	comm.data.id = 'T';
-	comm.data.rtr = 0; 				//Ecriture
-	comm.data.val = 120;			//Rotation de 12°/s
-	snd_dtq(CanTx, comm.msg);
+void rotation_tourelle(short angle){
+	send_commande(VITESSE_TOURELLE,angle);
 }
 
 
-short position_tourelle(){
+int position_tourelle(){
 //Renseigne sur la position de la tourelle (angle en dizieme de degre)
-	CanFrame requete, reponse;
-	short angle;
+	int angle;
 
-	requete.data.id = 'R';				//Position tourelle
-	requete.data.rtr = 1; 				//Lecture
-	snd_dtq(CanTx, requete.msg);
-	
-	rcv_dtq(CanRx, &reponse.msg);
-	angle = reponse.data.val;
-	
+	angle = send_requete(ANGLE_TOURELLE);
 	return angle;
 }
 
@@ -195,74 +184,89 @@
 void asserv_tourelle(VP_INT stacd){	
 //Maintient de la tourelle orientee a 45 degre
 	CanFrame comm;
+	short vitesse_tourelle;
 	char K = 2;
 	
 	while(1){
-		comm.data.id = 'T';								//Rotation de la tourelle
-		comm.data.rtr = 0; 								//Ecriture
-		comm.data.val =	K*(450 - position_tourelle());	//Rotation
-		snd_dtq(CanTx, comm.msg);
+		vitesse_tourelle =	K*(angle_tourelle - position_tourelle());
+		send_commande(VITESSE_TOURELLE, vitesse_tourelle);
 	}
 }
 
 short distance_telemetre(void){
 //Renseigne la distance mesuree par le telemetre
-	CanFrame requete, reponse;
 	short distance;
 
-	requete.data.id = 'U';				//Distance mesuree par le telemetre
-	requete.data.rtr = 1; 				//Lecture
-	snd_dtq(CanTx, requete.msg);
-	
-	rcv_dtq(CanRx, &reponse.msg);
-	if(reponse.data.id != 'U' )  {rcv_dtq(CanRx, &reponse.msg);	}
-	distance = reponse.data.val;
-	
+	distance = send_requete(DISTANCE_TELEMETRE);	
 	return distance;
 }
 
 void vitesse_roue(char vitesse){
-	CanFrame comm;
+	send_commande(VITESSE_ROUES,vitesse);
+}
+
+
+void angle_roue(short angle){
+	send_commande(ANGLE_ROUES,angle);
+}
+
+
+void asserv_roue(void){
+//Maintient de la voiture au centre de la piste
+	char K = 1.5;
+	short ang_roue;
 	
-	comm.data.id = 'V';				//Vitesse des roues
-	comm.data.rtr = 0; 				//Ecriture
-	comm.data.val = vitesse;		//Rotation
-	snd_dtq(CanTx, comm.msg);
+	while(1){
+		vitesse_roue(vit_roue);
+		distance_mur = distance_telemetre()*sin(3.1415*angle_tourelle/1800.0);
+		ang_roue = K*(distance_mur-500);
+		angle_roue(ang_roue);
+	}
 }
 
 
-void angle_roue(short angle){
+
+int send_requete(unsigned char id_periph){
+	//Envoi la requete correspondant a lidentifiant id_periph
+	CanFrame req;
+	int val;
+	UINT flag;
+
+	req.data.id = id_periph;
+	req.data.rtr = 1; // envoie d'une requete de lecture
+	periph[ADDR(id_periph)].ev = 0x01; //declenche un evenement quand mise a jour du peripherique id_periph
+	snd_dtq(CanTx, req.msg); // attente de la reponse
+	wai_flg(ev_periph, 0x01, TWF_ANDW, &flag);
+	periph[ADDR(id_periph)].ev = 0x00;
+	val = periph[ADDR(id_periph)].val;
+	return val;
+}
+
+void send_commande(unsigned char id_periph, short val){
+	//Envoi la commande correspondant a lidentifiant id_periph avec la valeur val
 	CanFrame comm;
 	
-	comm.data.id = 'D';				//Angle des roues
+	comm.data.id = id_periph;
 	comm.data.rtr = 0; 				//Ecriture
-	comm.data.val = 0;				//Angle de 0°C
+	comm.data.val =	val;	
 	snd_dtq(CanTx, comm.msg);
 }
 
 
-void asserv_angle_roue(void){
-//Maintient de la voiture au centre de la piste
-	CanFrame comm;
-	char K = 1;
-	short dist;
+
+void init(void) {
+	//Initialise tous les peripheriques, taches et cycliques handler
 	
-		comm.data.id = 'D';								//Angle des roues
-		comm.data.rtr = 0; 								//Ecriture
-		dist = distance_telemetre();
-		if(dist > distance_au_centre) 		//on est trop a gauche
-		{
-			comm.data.val =	3;
-		}
-		else {
-			if(dist < distance_au_centre)	//on est trop a droite
-			{
-				comm.data.val =	-3;
-			}
-			else 											//on est deja au centre
-			{
-				comm.data.val =	0;
-			}
-		}
-		snd_dtq(CanTx, comm.msg);	
-}
+	ports_mcu();
+    lcd_init();
+	periph_init();
+	periph_nom("#AutoTest*");
+
+    can_init();
+    clavier_init(1);
+	capture_init();
+
+	sta_cyc(ID_acqui);
+	sta_tsk(ID_asserv_tourelle);
+	sta_tsk(ID_periph_rx);
+}
\ No newline at end of file
