diff --git a/Logiciel/Firmware_testeur/Drivers/testeur.c b/Logiciel/Firmware_testeur/Drivers/testeur.c index 5ece048ff5c2082c22ef44bc9358daa42a26850f..637149e4bf354753bfb1eb19a159442aae224cc5 100644 --- a/Logiciel/Firmware_testeur/Drivers/testeur.c +++ b/Logiciel/Firmware_testeur/Drivers/testeur.c @@ -9,116 +9,24 @@ #include "main.h" #include <string.h> -// Fonctions privées -void testerBroche(RJ45_Sortie_Port connecteur) { - RJ45_Sortie_Port_ecrireBroche1(&connecteur, RJ45_HAUT); - RJ45_Sortie_Port_ecrireBroche2(&connecteur, RJ45_HAUT); - RJ45_Sortie_Port_ecrireBroche3(&connecteur, RJ45_HAUT); - RJ45_Sortie_Port_ecrireBroche4(&connecteur, RJ45_HAUT); - - RJ45_Sortie_Port_ecrireBroche5(&connecteur, RJ45_HAUT); - RJ45_Sortie_Port_ecrireBroche6(&connecteur, RJ45_HAUT); - RJ45_Sortie_Port_ecrireBroche7(&connecteur, RJ45_HAUT); - RJ45_Sortie_Port_ecrireBroche8(&connecteur, RJ45_HAUT); -} - // Fonctions publiques void Testeur_init (Testeur* testeur) { RJ45_Sortie_Port connecteurA; RJ45_Entree_Port connecteurB; - RJ45_Sortie_Port_init(&connecteurA); - RJ45_Entree_Port_init(&connecteurB); + RJ45_Sortie_Port_init(&connecteurA, ports_ethA, broches_ethA); + RJ45_Entree_Port_init(&connecteurB, ports_ethB, broches_ethB); - testeur->ethernetA_ = &connecteurA; - testeur->ethernetB_ = &connecteurB; + testeur->ethernetA_ = connecteurA; + testeur->ethernetB_ = connecteurB; SeptSegment_Port ecrans[N_ECRANS]; - // Liste des ports GPIO utilisés par l'ensemble des écrans - GPIO_TypeDef* ports_segments[N_ECRANS][N_SEGMENTS] = { - { - DS1_1_GPIO_Port, DS1_2_GPIO_Port, DS1_3_GPIO_Port, - DS1_4_GPIO_Port, DS1_5_GPIO_Port, DS1_6_GPIO_Port, - DS1_7_GPIO_Port - }, { - DS2_1_GPIO_Port, DS2_2_GPIO_Port, DS2_3_GPIO_Port, - DS2_4_GPIO_Port, DS2_5_GPIO_Port, DS2_6_GPIO_Port, - DS2_7_GPIO_Port - }, { - DS3_1_GPIO_Port, DS3_2_GPIO_Port, DS3_3_GPIO_Port, - DS3_4_GPIO_Port, DS3_5_GPIO_Port, DS3_6_GPIO_Port, - DS3_7_GPIO_Port - }, { - DS4_1_GPIO_Port, DS4_2_GPIO_Port, DS4_3_GPIO_Port, - DS4_4_GPIO_Port, DS4_5_GPIO_Port, DS4_6_GPIO_Port, - DS4_7_GPIO_Port - }, { - DS4_1_GPIO_Port, DS5_2_GPIO_Port, DS5_3_GPIO_Port, - DS5_4_GPIO_Port, DS5_5_GPIO_Port, DS5_6_GPIO_Port, - DS5_7_GPIO_Port - }, { - DS6_1_GPIO_Port, DS6_2_GPIO_Port, DS6_3_GPIO_Port, - DS6_4_GPIO_Port, DS6_5_GPIO_Port, DS6_6_GPIO_Port, - DS6_7_GPIO_Port - }, { - DS7_1_GPIO_Port, DS7_2_GPIO_Port, DS7_3_GPIO_Port, - DS7_4_GPIO_Port, DS7_5_GPIO_Port, DS7_6_GPIO_Port, - DS7_7_GPIO_Port - }, { - DS8_1_GPIO_Port, DS8_2_GPIO_Port, DS8_3_GPIO_Port, - DS8_4_GPIO_Port, DS8_5_GPIO_Port, DS8_6_GPIO_Port, - DS8_7_GPIO_Port - } - }; - - // Liste des broches GPIO utilisées par l'ensemble des écrans - uint16_t broches_segments[N_ECRANS][N_SEGMENTS] = { - { - DS1_1_Pin, DS1_2_Pin, DS1_3_Pin, - DS1_4_Pin, DS1_5_Pin, DS1_6_Pin, - DS1_7_Pin - }, { - DS2_1_Pin, DS2_2_Pin, DS2_3_Pin, - DS2_4_Pin, DS2_5_Pin, DS2_6_Pin, - DS2_7_Pin - }, { - DS3_1_Pin, DS3_2_Pin, DS3_3_Pin, - DS3_4_Pin, DS3_5_Pin, DS3_6_Pin, - DS3_7_Pin - }, { - DS4_1_Pin, DS4_2_Pin, DS4_3_Pin, - DS4_4_Pin, DS4_5_Pin, DS4_6_Pin, - DS4_7_Pin - }, { - DS4_1_Pin, DS5_2_Pin, DS5_3_Pin, - DS5_4_Pin, DS5_5_Pin, DS5_6_Pin, - DS5_7_Pin - }, { - DS6_1_Pin, DS6_2_Pin, DS6_3_Pin, - DS6_4_Pin, DS6_5_Pin, DS6_6_Pin, - DS6_7_Pin - }, { - DS7_1_Pin, DS7_2_Pin, DS7_3_Pin, - DS7_4_Pin, DS7_5_Pin, DS7_6_Pin, - DS7_7_Pin - }, { - DS8_1_Pin, DS8_2_Pin, DS8_3_Pin, - DS8_4_Pin, DS8_5_Pin, DS8_6_Pin, - DS8_7_Pin - } - }; - for (int i=0; i<N_ECRANS; i++) { SeptSegment_Port_init(&(ecrans[i]), ports_segments[i], broches_segments[i]); } - memcpy(testeur->ecrans_, ecrans, N_ECRANS*sizeof(SeptSegment_Port)); } -void Testeur_reglerAlim2V (Testeur* testeur, GPIO_PinState allumeOuEteint) { - -} - void Testeur_allumerAlim2V (Testeur* testeur) { HAL_GPIO_WritePin(EN_2V_GPIO_Port, EN_2V_Pin, GPIO_PIN_SET); } @@ -127,11 +35,68 @@ void Testeur_eteindreAlim2V (Testeur* testeur) { HAL_GPIO_WritePin(EN_2V_GPIO_Port, EN_2V_Pin, GPIO_PIN_RESET); } +/* + * @brief Exécuter le processus complet de test de câble + * @note Les étapes du processus sont: + * -Pour chaque broche du câble RJ45 + * -Allumer la broche du connecteur en sortie + * -Regarder quelle broche y est connecte + * -Si aucune ou plusieur, afficher tiret + * -Si une seule, afficher le chiffre correspondant + * @param Testeur* testeur Pointeur objet + */ void Testeur_testerCable (Testeur* testeur) { - for (int i=0; i<=9; i++) { - for (int j=0; j<N_ECRANS; j++) { - SeptSegment_Port_afficher(&(testeur->ecrans_[j]), i + '0'); + + // FIXME: La ligne ci-dessous plante au max + RJ45_Sortie_Port_ecrireToutesBroches(&(testeur->ethernetA_), RJ45_BAS); + + int nContacts[RJ45_N_BROCHES] = { 0 }; + + // Si un contact n'est connecté à aucun autre (faux contact), afficher un tiret + char affichageEcrans[N_ECRANS]; + memset(affichageEcrans, '-', N_ECRANS*sizeof(char) ); + + for (int i=0; i<RJ45_N_BROCHES; i++) { + + RJ45_Sortie_Port_ecrireBroche(&(testeur->ethernetA_), i, RJ45_HAUT); + + // Lister tout les contacts sur le connecteur d'entrée + for (int j=0; j<RJ45_N_BROCHES; j++) { + + // Si le même contact est court-circuité sur plus de deux contact, + // l'affichage reste le même de toute manière + if (nContacts[j] > 1) { + continue; + } + + // FIXME: Plante a i=0, j=4 + if ( RJ45_Entree_Port_lireBroche(&(testeur->ethernetB_), j) == RJ45_HAUT) { + (nContacts[j])++; + + if (nContacts[j] == 1) { + // Si le contact est connecté à un autre contact, + // afficher le numéro correspondant + affichageEcrans[j] = '1' + j; + } + else { + // Si plus d'un contact, alors il y a un court-circuit + // Afficher un tiret pour indiquer l'erreur + affichageEcrans[j] = '-'; + } + } } - HAL_Delay(500); + + RJ45_Sortie_Port_ecrireBroche(&(testeur->ethernetA_), i, RJ45_BAS); + } + + for (int i=0; i<N_ECRANS; i++) { + SeptSegment_Port_afficher(&(testeur->ecrans_[i]), affichageEcrans[i]); } + +// for (int i=0; i<=9; i++) { +// for (int j=0; j<N_ECRANS; j++) { +// SeptSegment_Port_afficher(&(testeur->ecrans_[j]), i + '0'); +// } +// HAL_Delay(500); +// } } diff --git a/Logiciel/Firmware_testeur/Drivers/testeur.h b/Logiciel/Firmware_testeur/Drivers/testeur.h index d85af8621466475bbaacbdea54c5a968b009fc01..8eb0c8efc73605ae47427f66ad4cc766d439ac06 100644 --- a/Logiciel/Firmware_testeur/Drivers/testeur.h +++ b/Logiciel/Firmware_testeur/Drivers/testeur.h @@ -10,18 +10,18 @@ #include "rj45_port_stm32f071v8.h" #include "sept_segments_port_stm32f071v8.h" -#include "alim2v_port_stm32f071v8.h" #define N_ECRANS 8 // Nombres d'écrans 7-segments programmables sur le testeur +// Assignation des ports et broches GPIO des périphériques +#include "testeur_liste_gpios.h" + // Structure typedef struct { - RJ45_Sortie_Port* ethernetA_; - RJ45_Entree_Port* ethernetB_; + RJ45_Sortie_Port ethernetA_; + RJ45_Entree_Port ethernetB_; -// TODO: Implémenter les classes SeptSegments et Alim2V SeptSegment_Port ecrans_[N_ECRANS]; -// Alim2V alimentation2V_; } Testeur; // Fonctions publiques diff --git a/Logiciel/Firmware_testeur/Drivers/testeur_liste_gpios.h b/Logiciel/Firmware_testeur/Drivers/testeur_liste_gpios.h new file mode 100644 index 0000000000000000000000000000000000000000..427da047ee013db3550c976adc8b9115d566fb5b --- /dev/null +++ b/Logiciel/Firmware_testeur/Drivers/testeur_liste_gpios.h @@ -0,0 +1,135 @@ +/* + * testeur_liste_gpios.h + * + * Created on: 7 mai 2020 + * Author: Yann Roberge (Lenclume) + */ + +#ifndef TESTEUR_LISTE_GPIOS_H_ +#define TESTEUR_LISTE_GPIOS_H_ + +#include "main.h" + +// Liste des ports GPIO utilisés par ETHA (sortie) +static GPIO_TypeDef* ports_ethA[RJ45_N_BROCHES] = { + ETHA_1_GPIO_Port, + ETHA_2_GPIO_Port, + ETHA_3_GPIO_Port, + ETHA_4_GPIO_Port, + ETHA_5_GPIO_Port, + ETHA_6_GPIO_Port, + ETHA_7_GPIO_Port, + ETHA_8_GPIO_Port +}; + +// Liste des ports GPIO utilisés par ETHB (entree) +static GPIO_TypeDef* ports_ethB[RJ45_N_BROCHES] = { + ETHB_1_GPIO_Port, + ETHB_2_GPIO_Port, + ETHB_3_GPIO_Port, + ETHB_4_GPIO_Port, + ETHB_5_GPIO_Port, + ETHB_6_GPIO_Port, + ETHB_7_GPIO_Port, + ETHB_8_GPIO_Port +}; + +// Liste des broches GPIO utilisés par ETHA (sortie) +static uint16_t broches_ethA[RJ45_N_BROCHES] = { + ETHA_1_Pin, + ETHA_2_Pin, + ETHA_3_Pin, + ETHA_4_Pin, + ETHA_5_Pin, + ETHA_6_Pin, + ETHA_7_Pin, + ETHA_8_Pin +}; + +// Liste des broches GPIO utilisés par ETHB (entree) +static uint16_t broches_ethB[RJ45_N_BROCHES] = { + ETHB_1_Pin, + ETHB_2_Pin, + ETHB_3_Pin, + ETHB_4_Pin, + ETHB_5_Pin, + ETHB_6_Pin, + ETHB_7_Pin, + ETHB_8_Pin +}; + +// Liste des ports GPIO utilisés par l'ensemble des écrans +static GPIO_TypeDef* ports_segments[N_ECRANS][N_SEGMENTS] = { + { + DS1_1_GPIO_Port, DS1_2_GPIO_Port, DS1_3_GPIO_Port, + DS1_4_GPIO_Port, DS1_5_GPIO_Port, DS1_6_GPIO_Port, + DS1_7_GPIO_Port + }, { + DS2_1_GPIO_Port, DS2_2_GPIO_Port, DS2_3_GPIO_Port, + DS2_4_GPIO_Port, DS2_5_GPIO_Port, DS2_6_GPIO_Port, + DS2_7_GPIO_Port + }, { + DS3_1_GPIO_Port, DS3_2_GPIO_Port, DS3_3_GPIO_Port, + DS3_4_GPIO_Port, DS3_5_GPIO_Port, DS3_6_GPIO_Port, + DS3_7_GPIO_Port + }, { + DS4_1_GPIO_Port, DS4_2_GPIO_Port, DS4_3_GPIO_Port, + DS4_4_GPIO_Port, DS4_5_GPIO_Port, DS4_6_GPIO_Port, + DS4_7_GPIO_Port + }, { + DS4_1_GPIO_Port, DS5_2_GPIO_Port, DS5_3_GPIO_Port, + DS5_4_GPIO_Port, DS5_5_GPIO_Port, DS5_6_GPIO_Port, + DS5_7_GPIO_Port + }, { + DS6_1_GPIO_Port, DS6_2_GPIO_Port, DS6_3_GPIO_Port, + DS6_4_GPIO_Port, DS6_5_GPIO_Port, DS6_6_GPIO_Port, + DS6_7_GPIO_Port + }, { + DS7_1_GPIO_Port, DS7_2_GPIO_Port, DS7_3_GPIO_Port, + DS7_4_GPIO_Port, DS7_5_GPIO_Port, DS7_6_GPIO_Port, + DS7_7_GPIO_Port + }, { + DS8_1_GPIO_Port, DS8_2_GPIO_Port, DS8_3_GPIO_Port, + DS8_4_GPIO_Port, DS8_5_GPIO_Port, DS8_6_GPIO_Port, + DS8_7_GPIO_Port + } +}; + +// Liste des broches GPIO utilisées par l'ensemble des écrans +static uint16_t broches_segments[N_ECRANS][N_SEGMENTS] = { + { + DS1_1_Pin, DS1_2_Pin, DS1_3_Pin, + DS1_4_Pin, DS1_5_Pin, DS1_6_Pin, + DS1_7_Pin + }, { + DS2_1_Pin, DS2_2_Pin, DS2_3_Pin, + DS2_4_Pin, DS2_5_Pin, DS2_6_Pin, + DS2_7_Pin + }, { + DS3_1_Pin, DS3_2_Pin, DS3_3_Pin, + DS3_4_Pin, DS3_5_Pin, DS3_6_Pin, + DS3_7_Pin + }, { + DS4_1_Pin, DS4_2_Pin, DS4_3_Pin, + DS4_4_Pin, DS4_5_Pin, DS4_6_Pin, + DS4_7_Pin + }, { + DS4_1_Pin, DS5_2_Pin, DS5_3_Pin, + DS5_4_Pin, DS5_5_Pin, DS5_6_Pin, + DS5_7_Pin + }, { + DS6_1_Pin, DS6_2_Pin, DS6_3_Pin, + DS6_4_Pin, DS6_5_Pin, DS6_6_Pin, + DS6_7_Pin + }, { + DS7_1_Pin, DS7_2_Pin, DS7_3_Pin, + DS7_4_Pin, DS7_5_Pin, DS7_6_Pin, + DS7_7_Pin + }, { + DS8_1_Pin, DS8_2_Pin, DS8_3_Pin, + DS8_4_Pin, DS8_5_Pin, DS8_6_Pin, + DS8_7_Pin + } +}; + +#endif /* TESTEUR_LISTE_GPIOS_H_ */ diff --git a/Logiciel/Firmware_testeur/Inc/main.h b/Logiciel/Firmware_testeur/Inc/main.h index 60ae4315a0434424fb30ecf204994a1e8a621f62..cf98cc52b345d85919b1b7b38e72d31f211c8263 100644 --- a/Logiciel/Firmware_testeur/Inc/main.h +++ b/Logiciel/Firmware_testeur/Inc/main.h @@ -32,7 +32,7 @@ extern "C" { /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ -#include "testeur.h" + /* USER CODE END Includes */ /* Exported types ------------------------------------------------------------*/ diff --git a/Logiciel/Firmware_testeur/Src/main.c b/Logiciel/Firmware_testeur/Src/main.c index 3baf72989415a881d4f38689d69b914e74e30c3e..70e5392a2c61b3ad4b668ef893184f3452ff7808 100644 --- a/Logiciel/Firmware_testeur/Src/main.c +++ b/Logiciel/Firmware_testeur/Src/main.c @@ -23,7 +23,7 @@ /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ - +#include "testeur.h" /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ @@ -88,8 +88,10 @@ int main(void) /* Initialize all configured peripherals */ MX_GPIO_Init(); /* USER CODE BEGIN 2 */ + Testeur_init(&testeur); Testeur_allumerAlim2V(&testeur); + /* USER CODE END 2 */ /* Infinite loop */ @@ -97,7 +99,10 @@ int main(void) while (1) { /* USER CODE END WHILE */ - Testeur_testerCable(&testeur); + + // Attente d'interruption + HAL_Delay(10); + /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ diff --git a/Logiciel/Firmware_testeur/Src/stm32f0xx_it.c b/Logiciel/Firmware_testeur/Src/stm32f0xx_it.c index da008b04d017070838d6ca462e3abf87a9cafce6..c2c13841a9145e3af8c127bb49583f0434e38afa 100644 --- a/Logiciel/Firmware_testeur/Src/stm32f0xx_it.c +++ b/Logiciel/Firmware_testeur/Src/stm32f0xx_it.c @@ -23,6 +23,7 @@ #include "stm32f0xx_it.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ +#include "testeur.h" /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/