Ajout des tests en interaction avec le Pico_Annex (porte et turbine) - Correction d'un soucis dans l'I2C
This commit is contained in:
		
							parent
							
								
									1abccc981b
								
							
						
					
					
						commit
						2abcdf5d52
					
				
							
								
								
									
										80
									
								
								Test.c
									
									
									
									
									
								
							
							
						
						
									
										80
									
								
								Test.c
									
									
									
									
									
								
							| @ -48,6 +48,7 @@ void affiche_localisation(void); | ||||
| int test_i2c_lecture_pico_annex(); | ||||
| int test_i2c_lecture_pico_annex_nb(); | ||||
| int test_i2c_lecture_pico_annex_nb2(); | ||||
| int test_i2c_ecriture_pico_annex_nb(); | ||||
| int test_aller_retour(); | ||||
| void test_trajectoire_teleplot(); | ||||
| 
 | ||||
| @ -75,6 +76,7 @@ int mode_test(){ | ||||
|     printf("V - APDS_9960\n"); | ||||
|     printf("W - Com i2c Pico Annexe\n"); | ||||
|     printf("X - Com i2c Pico Annexe - non bloquant\n"); | ||||
|     printf("Y - I2C - Turbine & porte\n"); | ||||
|     stdio_flush(); | ||||
|     int rep = getchar_timeout_us(TEST_TIMEOUT_US); | ||||
|     stdio_flush(); | ||||
| @ -174,6 +176,11 @@ int mode_test(){ | ||||
|         while(test_i2c_lecture_pico_annex_nb2()); | ||||
|         break; | ||||
| 
 | ||||
|     case 'Y': | ||||
|     case 'y': | ||||
|         while(test_i2c_ecriture_pico_annex_nb()); | ||||
|         break; | ||||
| 
 | ||||
|     case PICO_ERROR_TIMEOUT: | ||||
|         iteration--;         | ||||
|         if(iteration == 0){ | ||||
| @ -378,6 +385,79 @@ int test_i2c_lecture_pico_annex_nb2(){ | ||||
|     return test_continue_test(); | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| int test_i2c_ecriture_pico_annex_nb(){ | ||||
|     i2c_maitre_init(); | ||||
| 
 | ||||
|     uint8_t tampon[10]; | ||||
|     uint8_t registre=0x09; | ||||
|     uint8_t adresse = 0x17; | ||||
|     uint32_t time_i2c[5]; | ||||
|     const uint8_t T_I2C_ENVOI = 2; | ||||
|     static uint8_t commande=0; | ||||
|     enum i2c_resultat_t retour_i2c = I2C_EN_COURS; | ||||
| 
 | ||||
| 
 | ||||
|     printf("F - Ferme porte\n"); | ||||
|     printf("O - Ouvre porte\n"); | ||||
|     printf("T - Turbine On\n"); | ||||
|     printf("U - Turbine Off\n"); | ||||
| 
 | ||||
|     int lettre; | ||||
|     do{  | ||||
|         lettre = getchar_timeout_us(0); | ||||
|         stdio_flush(); | ||||
| 
 | ||||
|     }while(lettre == PICO_ERROR_TIMEOUT || lettre == '\0'); | ||||
| 
 | ||||
|     tampon[1] = 0x0; | ||||
|     switch(lettre){ | ||||
|         case 'F': | ||||
|         case 'f': | ||||
|             commande = commande | 0x02; // 0b0000 0010
 | ||||
|             printf("=> Ferme porte\n"); | ||||
|             break; | ||||
| 
 | ||||
|         case 'O': | ||||
|         case 'o': | ||||
|             commande = commande & 0xFD; // 0b1111 1101
 | ||||
|             printf("=> Ouvre porte\n"); | ||||
|             break; | ||||
|          | ||||
|         case 't': | ||||
|         case 'T': | ||||
|             commande = commande | 0x01; // 0b0000 0001
 | ||||
|             printf("=> Active turbine\n"); | ||||
|             break; | ||||
|          | ||||
|         case 'u': | ||||
|         case 'U': | ||||
|             commande = commande & 0xFE; // 0b1111 1110
 | ||||
|             printf("=> Arrete turbine\n"); | ||||
|             break; | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     tampon[0] = 54; | ||||
|     tampon[1] = commande; | ||||
| 
 | ||||
|     time_i2c[0] = time_us_32(); | ||||
|     time_i2c[2] = 0; | ||||
| 
 | ||||
|     while(retour_i2c == I2C_EN_COURS){ | ||||
|         time_i2c[1] = time_us_32(); // Pour mesurer le temps d'execution
 | ||||
|         i2c_gestion(i2c0); | ||||
|         retour_i2c = i2c_ecrire_registre_nb(adresse, registre, tampon, T_I2C_ENVOI); | ||||
|         time_i2c[2] += time_us_32() - time_i2c[1]; // Pour mesurer le temps d'execution
 | ||||
|         sleep_us(100); // Attente, ou le reste du code
 | ||||
|     } | ||||
|     time_i2c[3] = time_us_32() - time_i2c[0]; | ||||
| 
 | ||||
|     printf("Temps lecture : %u microsecondes, temps specifique i2c : %u microsecondes.\n", time_i2c[3], time_i2c[2]); | ||||
| 
 | ||||
|     return test_continue_test(); | ||||
| } | ||||
| 
 | ||||
| int test_i2c_bus(){ | ||||
|     // Adresse I2C : 0b0100 000 R/W
 | ||||
|     // Lecture des broches sur les registres 0 et 1
 | ||||
|  | ||||
							
								
								
									
										23
									
								
								i2c_maitre.c
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								i2c_maitre.c
									
									
									
									
									
								
							| @ -120,7 +120,7 @@ void i2c_gestion(i2c_inst_t *i2c){ | ||||
|         I2C_tampon_reception[index_reception] = (uint8_t) i2c->hw->data_cmd; | ||||
|         index_reception++; | ||||
|     } | ||||
|     if(index_reception == I2C_nb_a_recevoir && I2C_nb_a_recevoir > 0 ){ | ||||
|     if(index_reception == I2C_nb_a_recevoir){ | ||||
|         statu_reception = TRANSACTION_TERMINEE; | ||||
|         index_reception = 0; | ||||
|         I2C_nb_a_recevoir = 0; | ||||
| @ -158,7 +158,7 @@ void i2d_set_adresse_esclave(uint8_t _adresse_7bits){ | ||||
| /// @param emission : données à envoyer
 | ||||
| /// @param nb_envoi : nombre de données à envoyer
 | ||||
| /// @param nb_reception : nombre de données à recevoir
 | ||||
| /// @return 1 en cas d'échec, 0 en cas de succès
 | ||||
| /// @return I2C_EN_COURS, I2C_SUCCES ou I2C_ECHEC
 | ||||
| enum i2c_resultat_t i2c_transmission(uint8_t _adresse_7bits, uint8_t* emission, uint16_t nb_envoi, uint16_t nb_reception){ | ||||
|     static enum m_statu_t{ | ||||
|         I2C_STATU_INIT, | ||||
| @ -184,7 +184,7 @@ enum i2c_resultat_t i2c_transmission(uint8_t _adresse_7bits, uint8_t* emission, | ||||
|             I2C_nb_a_envoyer = nb_envoi + nb_reception; | ||||
|             I2C_nb_a_recevoir = nb_reception; | ||||
|              | ||||
|             // On appelle le fonction gestion pour gagner du temps.
 | ||||
|             // On appelle la fonction gestion pour gagner du temps.
 | ||||
|             i2c_gestion(i2c0); | ||||
|             m_statu = I2C_STATU_EN_COURS; | ||||
|             break; | ||||
| @ -218,10 +218,23 @@ enum i2c_resultat_t i2c_lire_registre_nb(uint8_t adresse_7_bits, uint8_t registr | ||||
|     }else if(i2c_resultat == I2C_ECHEC){ | ||||
|         return I2C_ECHEC; | ||||
|     } | ||||
|     return I2C_EN_COURS; | ||||
|      | ||||
|     return I2C_EN_COURS;    | ||||
| } | ||||
| 
 | ||||
| /// @brief Initialise une transaction I2C. 
 | ||||
| /// Renvoie I2C_SUCCES si l'intégralité du message est chargé en envoi, 
 | ||||
| /// Renvoie I2C_EN_COURS si la fonction doit encore être appelée pour finir d'envoyer le message
 | ||||
| /// Renvoie I2C_ECHEC en cas d'erreur I2C.
 | ||||
| enum i2c_resultat_t i2c_ecrire_registre_nb(uint8_t adresse_7_bits, uint8_t registre, uint8_t * _emission, uint8_t len){ | ||||
|     uint8_t emission[I2C_NB_MAX_TAMPON]; | ||||
|     emission[0] = registre; | ||||
|     for(uint32_t i = 0; i < len; i++){ | ||||
|         emission[i+1] = _emission[i]; | ||||
|     } | ||||
|     enum i2c_resultat_t i2c_resultat; | ||||
|     return i2c_transmission(adresse_7_bits, emission, 1 + len, 0); | ||||
|      | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| /// @brief Pour l'instant bloquant, mais devrait passer en non bloquant bientôt => Non, voir i2c_lire_registre_nb
 | ||||
|  | ||||
| @ -10,5 +10,6 @@ enum i2c_resultat_t { | ||||
| void i2c_maitre_init(void); | ||||
| void i2c_gestion(i2c_inst_t *i2c); | ||||
| enum i2c_resultat_t i2c_lire_registre_nb(uint8_t adresse_7_bits, uint8_t registre, uint8_t * reception, uint8_t len); | ||||
| enum i2c_resultat_t i2c_ecrire_registre_nb(uint8_t adresse_7_bits, uint8_t registre, uint8_t * _emission, uint8_t len); | ||||
| int i2c_ecrire_registre(char adresse_7_bits, char registre, char valeur_registre); | ||||
| int i2c_lire_registre(char adresse_7_bits, char registre, char * reception, char len); | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user