fixed the 9m master server having to be rebooted for hv to work

This commit is contained in:
Dhanya Maliakal
2017-06-22 14:32:24 +02:00
parent fe73e09aa4
commit f66950d312
4 changed files with 26 additions and 16 deletions

View File

@ -8,6 +8,7 @@
#include <unistd.h> // read, close #include <unistd.h> // read, close
#include <string.h> // memset #include <string.h> // memset
#include <linux/i2c-dev.h> // I2C_SLAVE, __u8 reg #include <linux/i2c-dev.h> // I2C_SLAVE, __u8 reg
#include <errno.h>
#define PORTNAME "/dev/ttyBF1" #define PORTNAME "/dev/ttyBF1"
#define GOODBYE 200 #define GOODBYE 200
@ -89,37 +90,40 @@ int i2c_write(unsigned int value){
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
int fd = open(PORTNAME, O_RDWR | O_NOCTTY); int fd = open(PORTNAME, O_RDWR | O_NOCTTY | O_SYNC);
if(fd < 0){ if(fd < 0){
cprintf(RED,"Warning: Unable to open port %s\n", PORTNAME); cprintf(RED,"Warning: Unable to open port %s\n", PORTNAME);
return -1; return -1;
} }
struct termios serial_conf; struct termios serial_conf;
// Get the current options for the port
tcgetattr(fd, &serial_conf);
// reset structure // reset structure
memset(&serial_conf,0,sizeof(serial_conf)); memset(&serial_conf,0,sizeof(serial_conf));
// control options // control options
serial_conf.c_cflag = B2400 | CS8 | CREAD | CLOCAL; serial_conf.c_cflag = B2400 | CS8 | CREAD | CLOCAL;
// input options // input options
serial_conf.c_iflag = IGNPAR; serial_conf.c_iflag = 0;//IGNPAR; (stuck because it was in ignore parity)
// output options // output options
serial_conf.c_oflag = 0; serial_conf.c_oflag = 0;
// line options // line options
serial_conf.c_lflag = ICANON; serial_conf.c_lflag = ICANON;
// flush input // flush input
tcflush(fd, TCIFLUSH); if(tcflush(fd, TCIFLUSH) < 0){
cprintf(RED,"Warning: error form tcflush %d\n", errno);
return 0;
}
// set new options for the port, TCSANOW:changes occur immediately without waiting for data to complete // set new options for the port, TCSANOW:changes occur immediately without waiting for data to complete
tcsetattr(fd, TCSANOW, &serial_conf); if(tcsetattr(fd, TCSANOW, &serial_conf) < 0){
cprintf(RED,"Warning: error form tcsetattr %d\n", errno);
return 0;
}
int ret = 0; int ret = 0;
int n = 0; int n = 0;
int ival= 0; int ival= 0;
char buffer[BUFFERSIZE]; char buffer[BUFFERSIZE];
memset(buffer,0,BUFFERSIZE);
buffer[BUFFERSIZE-2] = '\0'; buffer[BUFFERSIZE-2] = '\0';
buffer[BUFFERSIZE-1] = '\n'; buffer[BUFFERSIZE-1] = '\n';
cprintf(GREEN,"Ready...\n"); cprintf(GREEN,"Ready...\n");

View File

@ -13,6 +13,7 @@
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include <termios.h> // POSIX terminal control definitions(CS8, CREAD, CLOCAL..) #include <termios.h> // POSIX terminal control definitions(CS8, CREAD, CLOCAL..)
#include <errno.h>
#include "FebRegisterDefs.h" #include "FebRegisterDefs.h"
#include "FebControl.h" #include "FebControl.h"
@ -225,31 +226,35 @@ int Feb_Control_Init(int master, int top, int normal, int module_num){
int Feb_Control_OpenSerialCommunication(){ int Feb_Control_OpenSerialCommunication(){
cprintf(BG_BLUE,"opening serial communication of hv\n"); cprintf(BG_BLUE,"opening serial communication of hv\n");
if(Feb_Control_hv_fd != -1) //if(Feb_Control_hv_fd != -1)
close(Feb_Control_hv_fd); close(Feb_Control_hv_fd);
Feb_Control_hv_fd = open(SPECIAL9M_HIGHVOLTAGE_PORT, O_RDWR | O_NOCTTY); Feb_Control_hv_fd = open(SPECIAL9M_HIGHVOLTAGE_PORT, O_RDWR | O_NOCTTY | O_SYNC);
if(Feb_Control_hv_fd < 0){ if(Feb_Control_hv_fd < 0){
cprintf(RED,"Warning: Unable to open port %s to set up high voltage serial communciation to the blackfin\n", SPECIAL9M_HIGHVOLTAGE_PORT); cprintf(RED,"Warning: Unable to open port %s to set up high voltage serial communciation to the blackfin\n", SPECIAL9M_HIGHVOLTAGE_PORT);
return 0; return 0;
} }
struct termios serial_conf; struct termios serial_conf;
// Get the current options for the port
tcgetattr(Feb_Control_hv_fd, &serial_conf);
// reset structure // reset structure
memset(&serial_conf,0,sizeof(serial_conf)); memset (&serial_conf, 0, sizeof(serial_conf));
// control options // control options
serial_conf.c_cflag = B2400 | CS8 | CREAD | CLOCAL;//57600 too high serial_conf.c_cflag = B2400 | CS8 | CREAD | CLOCAL;//57600 too high
// input options // input options
serial_conf.c_iflag = IGNPAR; serial_conf.c_iflag = 0;//IGNPAR; (stuck because it was in ignore parity)
// output options // output options
serial_conf.c_oflag = 0; serial_conf.c_oflag = 0;
// line options // line options
serial_conf.c_lflag = ICANON; serial_conf.c_lflag = ICANON;
// flush input // flush input
tcflush(Feb_Control_hv_fd, TCIFLUSH); if(tcflush(Feb_Control_hv_fd, TCIFLUSH) < 0){
cprintf(RED,"Warning: error form tcflush %d\n", errno);
return 0;
}
// set new options for the port, TCSANOW:changes occur immediately without waiting for data to complete // set new options for the port, TCSANOW:changes occur immediately without waiting for data to complete
tcsetattr(Feb_Control_hv_fd, TCSANOW, &serial_conf); if(tcsetattr(Feb_Control_hv_fd, TCSANOW, &serial_conf) < 0){
cprintf(RED,"Warning: error form tcsetattr %d\n", errno);
return 0;
}
return 1; return 1;
} }
@ -605,6 +610,7 @@ int Feb_Control_SendHighVoltage(int dacvalue){
} }
char buffer[SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE]; char buffer[SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE];
memset(buffer,0,SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE);
buffer[SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE-2]='\0'; buffer[SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE-2]='\0';
buffer[SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE-1]='\n'; buffer[SPECIAL9M_HIGHVOLTAGE_BUFFERSIZE-1]='\n';
int n; int n;