Index: branch/decroux/Emb_App.tws
===================================================================
--- branch/decroux/Emb_App.tws	(revision 360)
+++ branch/decroux/Emb_App.tws	(revision 361)
@@ -7,13 +7,17 @@
 [GENERAL_DATA]
 [BREAKPOINTS]
 [OPEN_WORKSPACE_FILES]
+"E:\tp_info6_2018_decroux\tp_info6\bsp\periph.c" 
+"E:\tp_info6_2018_decroux\tp_info6\bsp\uart0.c" 
 "E:\tp_info6_2018_decroux\tp_info6\Emb_App\conf_noyau.cfg" 
 "E:\tp_info6_2018_decroux\tp_info6\Emb_App\crt0mr.a30" 
 "E:\tp_info6_2018_decroux\tp_info6\Emb_App\programme_principal_etud.c" 
 [WORKSPACE_FILE_STATES]
 "E:\tp_info6_2018_decroux\tp_info6\Emb_App\conf_noyau.cfg" 75 75 1430 351 0 2 
-"E:\tp_info6_2018_decroux\tp_info6\Emb_App\crt0mr.a30" 0 0 1596 539 0 1 
-"E:\tp_info6_2018_decroux\tp_info6\Emb_App\programme_principal_etud.c" -8 -30 1596 539 1 0 
+"E:\tp_info6_2018_decroux\tp_info6\Emb_App\crt0mr.a30" -8 -30 1596 539 1 1 
+"E:\tp_info6_2018_decroux\tp_info6\Emb_App\programme_principal_etud.c" 0 0 1596 539 0 0 
+"E:\tp_info6_2018_decroux\tp_info6\bsp\periph.c" 75 75 1430 351 0 3 
+"E:\tp_info6_2018_decroux\tp_info6\bsp\uart0.c" 100 100 1430 351 0 4 
 [LOADED_PROJECTS]
 "EmbM32C87App" 
 [END]
Index: branch/decroux/Emb_App/SessionM32C_E8a_system.hsf
===================================================================
--- branch/decroux/Emb_App/SessionM32C_E8a_system.hsf	(revision 360)
+++ branch/decroux/Emb_App/SessionM32C_E8a_system.hsf	(revision 361)
@@ -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" "0000000000004044" 
-"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_1" "0000000000000120" 
+"{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_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" "0000000000000512" 
-"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_16" "0000000000FF0586" 
-"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_17" "0000000000FFF800" 
-"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_18" "0000000000000FEE" 
-"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_19" "0000000000000818" 
-"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_2" "00000000000030FE" 
-"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_20" "0000000000004044" 
+"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_15" "0000000000000000" 
+"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_16" "0000000000FF001C" 
+"{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_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" "000000000000036A" 
+"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_34" "0000000000000000" 
 "{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_35" "0000000000000000" 
-"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_4" "0000000000000008" 
+"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_4" "0000000000000000" 
 "{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_5" "0000000000000000" 
-"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_6" "0000000000001014" 
-"{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_7" "0000000000000512" 
+"{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_8" "0000000000000000" 
 "{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_9" "0000000000000000" 
 "{64753FED-D387-4B8C-A91D-D3419C869C07}C_REGISTER_REG_COUNT" "36" 
@@ -209,9 +209,9 @@
 "{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd0ECX_WATCH_ITEM0000_SCOPE" "Current Scope," 
 "{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd0ECX_WATCH_ITEM0001" "capt, 2, 0, P, Col, Hex, MA" 
 "{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd0ECX_WATCH_ITEM0001_SCOPE" "Current Scope," 
-"{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd0ECX_WATCH_ITEM0002" "distance0, 10, 0, P, Col, Hex, N" 
+"{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd0ECX_WATCH_ITEM0002" "Mode, 2, 0, P, Col, Hex, MA" 
 "{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd0ECX_WATCH_ITEM0002_SCOPE" "Current Scope," 
-"{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd0ECX_WATCH_ITEMCnt" "2" 
+"{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd0ECX_WATCH_ITEMCnt" "3" 
 "{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd1ColWidth0" "120" 
 "{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd1ColWidth1" "150" 
 "{B266D880-6FA1-11D5-8613-00A024591A38}WatchWnd1ColWidth12" "200" 
@@ -283,12 +283,12 @@
 "Help" "TOOLBAR 0" 59419 2 4 "0.00" 0 0 0 0 0 17 0 "" "0.0" 
 "{WK_00000001_CmdLine}" "WINDOW" 59422 0 3 "0.07" 365 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" 365 0 0 350 200 18 0 "32774|32775|32777|<<separator>>|32780|<<separator>>" "0.0" 
+"{WK_00000001_EVENT}EmbM32C87AppSessionM32C_E8a_system" "WINDOW" 59422 0 0 "0.09" 365 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 1 "0.43" 365 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 2 "0.16" 365 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 1 "0.33" 365 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 2 "0.23" 365 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.30" 365 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.35" 365 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" 
@@ -313,9 +313,11 @@
 [WINDOW_POSITION_STATE_DATA_VD3]
 [WINDOW_POSITION_STATE_DATA_VD4]
 [WINDOW_Z_ORDER]
+"E:\tp_info6_2018_decroux\tp_info6\Emb_App\crt0mr.a30" 
 "E:\tp_info6_2018_decroux\tp_info6\Emb_App\programme_principal_etud.c" 
-"E:\tp_info6_2018_decroux\tp_info6\Emb_App\crt0mr.a30" 
+"E:\tp_info6_2018_decroux\tp_info6\bsp\uart0.c" 
 "E:\tp_info6_2018_decroux\tp_info6\Emb_App\conf_noyau.cfg" 
+"E:\tp_info6_2018_decroux\tp_info6\bsp\periph.c" 
 [TARGET_NAME]
 "M32C E8a SYSTEM" "" 0 
 [STATUSBAR_STATEINFO_VD1]
@@ -362,5 +364,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 100211616 1 "{00000000-0000-0000-C000-000000000046}" "" 
+"d:\profs\tp_info14_travail\tp_info14\emb_app\programme_principal_etud.c" 95 100930696 1 "{00000000-0000-0000-C000-000000000046}" "" 
 [END]
Index: branch/decroux/Emb_App/programme_principal_etud.c
===================================================================
--- branch/decroux/Emb_App/programme_principal_etud.c	(revision 360)
+++ branch/decroux/Emb_App/programme_principal_etud.c	(revision 361)
@@ -125,6 +125,7 @@
 int kr=1; // Gain roue
 unsigned int dis;
 unsigned int capt=0x0000;
+unsigned int Mode;
 
 
 // Tache qui met la tourelle a 45degres
@@ -133,11 +134,6 @@
 	while(1){
 		CanFrame commTourel;
 		CanFrame requeteTourel; 
-		CanFrame reponseTourel;
-		commTourel.data.id='T'; //Commade en vitesse de la tourelle portant le télémetre
-		commTourel.data.rtr=0; 
-		commTourel.data.val=300;
-		snd_dtq (CanTx,commTourel.msg);
 		// Lectre de l'angle
 		requeteTourel.data.id='R'; //Lecture de l'angle effecif de la tourelle portant le télémtre
     	requeteTourel.data.rtr=1; // Indiquation d'une requête de lecture
@@ -167,19 +163,48 @@
 		dis=periph[ADDR('U')].val; // Contient la derniere valeur renvoyee par le simulateur
 		periph[ADDR('U')].maj; // Incremente a chaque reception
 		//Assevicement 
-		if(dis>1000)
+		if(Mode==0x8304 || Mode==0x0304)//On est sur la piste noir
 		{
-			commRoues.data.id='D'; // Commande de l'angle des roues 
-			commRoues.data.rtr=0; //Indique une requete d'écriture
-			commRoues.data.val= 0; // Correction de la disance
-			snd_dtq(CanTx,commRoues.msg);
+			
+			if(dis>5000 || dis<400 ||capt==0x6208) //Pour passer les trous et les tonneau 
+			{
+				LED_R=1;
+				commRoues.data.id='D'; // Commande de l'angle des roues 
+				commRoues.data.rtr=0; //Indique une requete d'écriture
+				commRoues.data.val= 0; // Correction de la disance
+				snd_dtq(CanTx,commRoues.msg);
+			}
+			else if (capt==0x6308) //Pour passer le tonneau au milieu piste noir
+			{
+				commRoues.data.id='D'; // Commande de l'angle des roues 
+				commRoues.data.rtr=0; //Indique une requete d'écriture
+				commRoues.data.val=kr*(dis-1010); // Correction de la disance
+				snd_dtq(CanTx,commRoues.msg);	
+			}
+			else
+			{
+				commRoues.data.id='D'; // Commande de l'angle des roues 
+				commRoues.data.rtr=0; //Indique une requete d'écriture
+				commRoues.data.val=kr*(dis-700); // Correction de la disance
+				snd_dtq(CanTx,commRoues.msg);
+			}
 		}
-		else
-		{
-			commRoues.data.id='D'; // Commande de l'angle des roues 
-			commRoues.data.rtr=0; //Indique une requete d'écriture
-			commRoues.data.val=kr*(dis-680); // Correction de la disance
-			snd_dtq(CanTx,commRoues.msg);
+		else 
+		{	
+			if(dis>1000 ) //Pour passer les trous et les tonneau 
+			{
+				commRoues.data.id='D'; // Commande de l'angle des roues 
+				commRoues.data.rtr=0; //Indique une requete d'écriture
+				commRoues.data.val= 0; // Correction de la disance
+				snd_dtq(CanTx,commRoues.msg);
+			}
+			else
+			{
+				commRoues.data.id='D'; // Commande de l'angle des roues 
+				commRoues.data.rtr=0; //Indique une requete d'écriture
+				commRoues.data.val=kr*(dis-700); // Correction de la disance
+				snd_dtq(CanTx,commRoues.msg);
+			}
 		}
 		dly_tsk(10);	
 	}
@@ -186,44 +211,77 @@
 		
 }
 
-//Fonctin vitesse
-void vitesse(unsigned int valcapt)
+//Fonctin vitesse noir
+void vitesse4(unsigned int valcapt)
 {
 		CanFrame commVit;
-		commVit.data.id='V';
-		commVit.data.rtr=0;
-		commVit.data.val=25;
-		snd_dtq (CanTx,commVit.msg);
-		if(valcapt== 0x5603)
+	 if(capt==0x6308 || capt==0x4a01||capt==0x6208) // Rallentissement prés du tonneau
 		{
 			commVit.data.id='V';
 			commVit.data.rtr=0;
-			commVit.data.val=45;
+			commVit.data.val=15;
 			snd_dtq (CanTx,commVit.msg);
-		}
-		else if(valcapt==0x7608)
+		}	
+		else 
+		{	commVit.data.id='V';
+			commVit.data.rtr=0;
+			commVit.data.val=25; //Reprise de vitesse une fois la voiure stabilisé piste rouge
+			snd_dtq (CanTx,commVit.msg);
+		}		
+}
+//Fonction vitesse rouge
+void vitesse3(unsigned int valcapt)
+{
+		CanFrame commVit;
+		//vitesse pour passer le tramplin piste rouge
+		if(valcapt== 0x6a08)
 		{
 			commVit.data.id='V';
 			commVit.data.rtr=0;
-			commVit.data.val=0;
+			commVit.data.val=45; 
 			snd_dtq (CanTx,commVit.msg);
+		} 
+		//Ralentissemet après tramplin piste rouge
+		else if(valcapt==0x7608||valcapt==0x4203) 
+		{
 			commVit.data.id='V';
 			commVit.data.rtr=0;
-			commVit.data.val=5;
+			commVit.data.val=15;
 			snd_dtq (CanTx,commVit.msg);
-			
 		}	
-		else if(valcapt==0x5604)
-		{
-			commVit.data.id='V';
+		else 
+		{	commVit.data.id='V';
 			commVit.data.rtr=0;
-			commVit.data.val=25;
+			commVit.data.val=25; //Reprise de vitesse une fois la voiture stabilisé piste rouge
 			snd_dtq (CanTx,commVit.msg);
-		}			
+		}		
 }
 
+//Fonctin vitesse verte et bleu
+void vitesse1()
+{
+	CanFrame commVit;
+	commVit.data.id='V';
+	commVit.data.rtr=0;
+	commVit.data.val=30; 
+	snd_dtq (CanTx,commVit.msg);
+}
+//Lecture couleur de la piste et feu
+unsigned int lecture_piste()
+{
+	
+		CanFrame Mcourse;
+		Mcourse.data.id='M'; 
+   		Mcourse.data.rtr=1; // Indiquation d'une requiete de lecture
+  		snd_dtq (CanTx,Mcourse.msg); // Interrogation du peripherique
+		Mode=periph[ADDR('M')].val; // Contient la derniere valeur renvoyee par le simulateur
+		periph[ADDR('M')].maj;
+		dly_tsk(10);
+	return Mode;
+}
 
 
+
 // Focntion delay
 void Pause(void)
 {
@@ -255,18 +313,43 @@
 	
     while(1)
     {	
-		vitesse(capt);
-		//Lecture de la valeur du capteur
-		capteur.data.id='C'; //Information sur le dernier capteur 
-   		capteur.data.rtr=1; // Indiquation d'une requiete de lecture
-  		snd_dtq (CanTx,capteur.msg); // Interrogation du peripherique
-		capt=periph[ADDR('C')].val; // Contient la derniere valeur renvoyee par le simulateur
-		periph[ADDR('C')].maj;
-		 // Incremente a chaque reception
+		Mode= lecture_piste();
+		if(Mode==0x8304 || Mode==0x0304)//On est sur la piste noir
+		{
+			
+			//Lecture de la valeur du capteur
+			capteur.data.id='C'; //Information sur le dernier capteur 
+   			capteur.data.rtr=1; // Indiquation d'une requiete de lecture
+  			snd_dtq (CanTx,capteur.msg); // Interrogation du peripherique
+			capt=periph[ADDR('C')].val; // Contient la derniere valeur renvoyee par le simulateur
+			periph[ADDR('C')].maj;// Incremente a chaque reception
+			vitesse4(capt);
+		}
+		else if(Mode==0x8303 || Mode==0303) //O est sur la piste rouge
+		{
+			
+			//Lecture de la valeur du capteur
+			capteur.data.id='C'; //Information sur le dernier capteur 
+   			capteur.data.rtr=1; // Indiquation d'une requiete de lecture
+  			snd_dtq (CanTx,capteur.msg); // Interrogation du peripherique
+			capt=periph[ADDR('C')].val; // Contient la derniere valeur renvoyee par le simulateur
+			periph[ADDR('C')].maj;// Incremente a chaque reception
+			vitesse3(capt);
+		}
+		else if(Mode==0x8302 || Mode==0x0302) //On est dur la piste bleu
+		{
+			vitesse1();
+		}
+		else if(Mode==0x8301 || Mode==0x0301)//On est sur la piste verte
+		{
+			vitesse1();
+		}
+		
 		LED_J=1;
 		dly_tsk(100);
 		LED_J=0;
-		dly_tsk(100);		
+		dly_tsk(100);
+				
     }
 }
 
