0

The code below receives data from serial port of friendlyarm board.Signal handler is able to receve data if only one port is used.When i configured another port the signalhandler get executed on reception of data at two serial ports(SGIO signal is generated from both ports). What is the method of identifying the source of data so that i can seperate the data from two ports correctly.

main()
{ Spo2fd=open("/dev/ttySAC1", O_RDWR | O_NOCTTY | O_NDELAY,0);
         if (Spo2fd == -1)
         {
            perror("open_port: Unable to open /dev/ttySAC3\n");
            exit(1);
         }


         sbio.sa_sigaction = &spo2signal_handler_IO;//sbio is a    structure of type sigaction
         sbio.sa_flags = SA_SIGINFO;//=0
         sbio.sa_restorer = NULL;

         sigaction(SIGIO,&sbio,NULL);


         fcntl(Spo2fd, F_SETFL, FNDELAY);
         fcntl(Spo2fd, F_SETOWN, getpid());
         fcntl(Spo2fd, F_SETFL,  O_ASYNC ); 

         cfsetispeed(&spo2term,B4800);
         cfsetospeed(&spo2term,B4800);
              spo2term.c_cflag &= ~PARENB;
              spo2term.c_cflag &= ~CSTOPB;
              spo2term.c_cflag &= ~CSIZE;
              spo2term.c_cflag |= CS8;
              spo2term.c_cflag |= (CLOCAL | CREAD);
              spo2term.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
              spo2term.c_iflag &= ~(IXON | IXOFF | IXANY);
              spo2term.c_oflag &= ~OPOST;
              tcsetattr(Spo2fd,TCSANOW,&spo2term);
              printf("spo2term configured....\n");

             tcflush(Spo2fd,TCIFLUSH); // Flush input buffer
             tcflush(Spo2fd,TCOFLUSH);  // Flush output buffer


 while(1)
 {

  // process the received data here.
 }



 }

signal handler

static void spo2signal_handler_IO (int sig, siginfo_t *siginfo, void *context)
{printf("\nspo2 data received\n");
unsigned int temp1;
unsigned int a=128,c;
//printf("\nSpo2");
res_spo2 = read(Spo2fd,&bufspo2,1);
//printf("\n%x",bufspo2);
temp1=bufspo2;
c=a&temp1;

if(c==128)
    spo2count=1;
if(spo2count==1)
    firstdataflag=true;
else if(spo2count==2)
    seconddataflag=true;
else if(spo2count==3)
    thirddataflag=true;
else if(spo2count==4)
    fourthdataflag=true;
else if(spo2count==5)
    fifthdataflag=true;
}
  • when responding to an interrupt event that can be raised by more than one source (BTW: the posted code is only generating one source) then the code needs to loop through the interrupt pending flags (might be called something else on your CPU) to determine which interrupt source to service. – user3629249 Feb 03 '15 at 05:32
  • How to access the FLAGS should i use ioctrl function.where are the flags defined.where do i get the list of FLAGS associated with the serial port interrupt.i can't find it in termios structure – dawnpaulmec Feb 06 '15 at 11:43

0 Answers0