From 69ceaba85e6e84f2dc6500ca702a18898af39177 Mon Sep 17 00:00:00 2001 From: Geoffrey Frogeye Date: Tue, 1 May 2018 14:51:41 +0200 Subject: [PATCH] Diagnostics --- chef/Makefile | 2 +- chef/src/CF.c | 46 +++++++++++++++++++++++----------- chef/src/debug.c | 3 +-- chef/src/diagnostics.c | 56 ++++++++++++++++++++++++++++++++++++++++++ chef/src/diagnostics.h | 17 +++++++++++++ chef/src/ihm.c | 4 +-- fpga/principal.ucf | 1 - 7 files changed, 109 insertions(+), 20 deletions(-) create mode 100644 chef/src/diagnostics.c create mode 100644 chef/src/diagnostics.h diff --git a/chef/Makefile b/chef/Makefile index 4c3e038..d70df86 100644 --- a/chef/Makefile +++ b/chef/Makefile @@ -11,7 +11,7 @@ CFLAGS_CUSTOM += -g ## Générateurs de drapeaux pour les bibliothèques PKG_CONFIG=pkg-config ## Nom des objets communs -OBJS=buttons CF debug i2c ihm lcd movement parcours points position +OBJS=buttons CF debug diagnostics i2c ihm lcd movement parcours points position OBJS_O=$(addprefix obj/,$(addsuffix .o,$(OBJS))) # VARIABLES AUTOMATIQUES diff --git a/chef/src/CF.c b/chef/src/CF.c index 2791faa..3e3a551 100644 --- a/chef/src/CF.c +++ b/chef/src/CF.c @@ -26,27 +26,49 @@ void configureFpga() // Connection au port série printf("Connexion à %s... ", FPGA_PORTNAME); fflush(stdout); - fpga = open(FPGA_PORTNAME, O_RDWR | O_NOCTTY | O_NDELAY); + fpga = open(FPGA_PORTNAME, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK); + fpga = serialOpen(FPGA_PORTNAME, 9600); if (fpga < 0) { printf("Échec !\n"); exit(1); } // Configuration du port série + fcntl(fpga, F_SETFL, O_RDWR); + struct termios cfg; - bzero(&cfg, sizeof(cfg)); - cfg.c_cflag = CLOCAL | CREAD | CF_BAUDRATE | CS8; - cfg.c_iflag = 0; - cfg.c_oflag = 0; - cfg.c_lflag = 0; /* set input mode (non-canonical, no echo,...) */ - cfg.c_cc[VTIME] = 0; /* inter-character timer unused */ - cfg.c_cc[VMIN] = 1; /* blocking read until 1 char received */ + + tcgetattr(fpga, &cfg); + + cfmakeraw(&cfg); + cfsetispeed(&cfg, CF_BAUDRATE); + cfsetospeed(&cfg, CF_BAUDRATE); + + cfg.c_cflag |= (CLOCAL | CREAD); + cfg.c_cflag &= ~PARENB; + cfg.c_cflag &= ~CSTOPB; + cfg.c_cflag &= ~CSIZE; + cfg.c_cflag |= CS8; + cfg.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); + cfg.c_oflag &= ~OPOST; + + cfg.c_cc[VMIN] = 0; + cfg.c_cc[VTIME] = 10; + if (tcsetattr(fpga, TCSANOW, &cfg) < 0) { perror("serialConfig.tcsetattr"); exit(1); } - sleep(1); + int status; + ioctl(fpga, TIOCMGET, &status); + + status |= TIOCM_DTR; + status |= TIOCM_RTS; + + ioctl(fpga, TIOCMSET, &status); + + usleep(10 * 1000); // Flush unsigned char trash[1024]; @@ -101,7 +123,6 @@ void setPret() void doNothing() { - } void configureCF() @@ -116,16 +137,13 @@ void configureCF() printf("Attente de réponse du Fpga... "); fflush(stdout); - struct timespec tim; - tim.tv_sec = 0; - tim.tv_nsec = 100000000L; // Dans le cas où on aurait laissé l'Fpga en attente de donnée, // on envoie des pings en boucle jusqu'à ce qu'il nous réponde. pret = false; registerRxHandler(C2FD_PING, setPret); while (!pret) { sendCF(C2FD_PING, NULL, 0); - nanosleep(&tim, NULL); + usleep(100 * 1000); } registerRxHandler(C2FD_PING, doNothing); // TODO registerRxHandler(C2FD_PING, NULL); diff --git a/chef/src/debug.c b/chef/src/debug.c index aa5e672..09b4682 100644 --- a/chef/src/debug.c +++ b/chef/src/debug.c @@ -6,7 +6,6 @@ #include #include #include // sleep -#include #include "debug.h" @@ -91,7 +90,7 @@ void* TaskDebug(void* pdata) fprintf(debugFd, "\n"); fflush(debugFd); - delay(DEBUG_INTERVAL); + usleep(DEBUG_INTERVAL * 1000); } return NULL; diff --git a/chef/src/diagnostics.c b/chef/src/diagnostics.c new file mode 100644 index 0000000..48b26e3 --- /dev/null +++ b/chef/src/diagnostics.c @@ -0,0 +1,56 @@ +#include + +#include "diagnostics.h" +#include "buttons.h" +#include "lcd.h" + +#include "CF.h" + +bool recu; + +void setRecu() +{ + recu = true; +} + +bool diagFPGA() +{ + recu = false; + registerRxHandler(C2FD_PING, setRecu); + sendCF(C2FD_PING, NULL, 0); + + for (int i = 0; i <= DIAGNOSTIC_SERIAL_TIMEOUT; i += DIAGNOSTIC_POLL_INTERVAL) { + if (recu) { + break; + } + usleep(DIAGNOSTIC_POLL_INTERVAL * 1000); + } + return recu; +} + +bool diagArduino() +{ + return false; +} + +void execDiagnostic(char *name, bool (*diagnostic)(void)) +{ + clearLCD(); + printToLCD(LCD_LINE_1, name); + printToLCD(LCD_LINE_2, "..."); + bool res = diagnostic(); + if (res) { + printToLCD(LCD_LINE_2, "Ok!"); + usleep(DIAGNOSTIC_INTERVAL * 1000); + } else { + printToLCD(LCD_LINE_2, "Echec!"); + pressedButton(BUT_BLOCK); + } +} + +void runDiagnostics() +{ + execDiagnostic("Lien FPGA", diagFPGA); + /* execDiagnostic("Lien Arduino", diagArduino); */ +} + diff --git a/chef/src/diagnostics.h b/chef/src/diagnostics.h new file mode 100644 index 0000000..07610c4 --- /dev/null +++ b/chef/src/diagnostics.h @@ -0,0 +1,17 @@ +#ifndef __DIAGNOSTICS_H_ +#define __DIAGNOSTICS_H_ + +#include + +// Constantes +#define DIAGNOSTIC_INTERVAL 500 +#define DIAGNOSTIC_POLL_INTERVAL 100 +#define DIAGNOSTIC_SERIAL_TIMEOUT 10000 + +// Public +void runDiagnostics(); + +// Private +void execDiagnostic(char *name, bool (*diagnostic)(void)); + +#endif diff --git a/chef/src/ihm.c b/chef/src/ihm.c index 0179c1a..bb6981c 100644 --- a/chef/src/ihm.c +++ b/chef/src/ihm.c @@ -8,6 +8,7 @@ #include "points.h" #include "lcd.h" #include "buttons.h" +#include "diagnostics.h" // Globales pthread_t tIHM; @@ -117,8 +118,7 @@ void* TaskIHM(void* pdata) if (bout == rouge) { clearLCD(); - printToLCD(LCD_LINE_1, "Diagnostics..."); - delay(3000); // TODO + runDiagnostics(); } else if (bout == jaune) { break; } diff --git a/fpga/principal.ucf b/fpga/principal.ucf index 2d7556c..1bf99d3 100644 --- a/fpga/principal.ucf +++ b/fpga/principal.ucf @@ -40,7 +40,6 @@ NET "BACKECHO" LOC = "P73" | IOSTANDARD = LVTTL ; # IO<20> NET "ENA" LOC = "P5" | IOSTANDARD = LVTTL ; - # IO<21> NET "IN1ENC" LOC = "P4" | IOSTANDARD = LVTTL ;