Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 334
  • Last Modified:

RS-232 Port Break Charator Caused

Hi, All,

I am writing a short program which interfaces to the little Motorola 68hc11 processor.  I need to detect break charators (RxD stucked to constant zero) and cause an interrupt signal to the main process.

According to man termio:

   If IGNBRK is set, the break condition is ignored.  Therefore the break
      condition cannot be read by any process.  If IGNBRK is clear and
      BRKINT is set, the break condition flushes both the input and output
      queues and, if the terminal is the controlling terminal of a
      foreground process group, the break condition generates a single
      SIGINT signal to that foreground process group.  If neither IGNBRK nor
      BRKINT is set, a break condition is read as a single \0 character, or


 I put the statement:
      t_ptr.c_iflag = BRKINT
in the following code to enable the interrupt.  

I also use a scope to make sure I indeed put a constant zero (+12v) onto the RxD line.  The problem I am having is that no matter what I do, the break charactor on the RxD line will _never_ cause an interrupt.  Just to verify the interrupt is still working, I use the alarm() function to cause an interrupt every 5 second.  The alarm() function works.  Secondly, if I ran the following program, I can make the SIGINT signal triggered by hitting ctlr-C.  Second ctlr-C will terminate the execution.

I am using a Ultrasparc and runing SunOS 5.5.1.  

Please help and thanks.

Jian Zhang
DSC Communications Corp.
Petaluma, California

Here is the source code:

------------------cut here------------------

#include
#include
#include
#include

#include
#include

#include
#include

unsigned char  bin_wt [2048];
int        fd;

void alarm_hdlr();
void sig_handlr();

main(int argc, char * argv[]) {


  const  baud_rate = B1800;
  const sync_char = 0xff;


  unsigned char in_char;
  int    i, j;

  int    n, wrt_n, rd_n;

  FILE*  file_ptr;

  struct termios t_ptr;

  char* str_line;
  char* str_load;
  char* a_str;

  unsigned char  bin_rd [2048];
  unsigned int srec_len;

  str_line   = (char*)malloc (1024);
  str_load   = (char*)malloc (3000);
  a_str      = (char*)malloc (3000);

  bin_wt [0] = sync_char;
  fd = open("/dev/ttyb", O_RDWR);

  //t_ptr.c_iflag = BRKINT | INPCK;
  t_ptr.c_iflag = BRKINT;
  //t_ptr.c_iflag = PARMRK;
  t_ptr.c_oflag = 0;
  t_ptr.c_cflag = CS8 | CREAD | CLOCAL | CSTOPB;
  t_ptr.c_lflag = 0;
  t_ptr.c_cc[VTIME] = t_ptr.c_cc[VMIN] = 0;

  cfsetispeed(&t_ptr, baud_rate);
  cfsetospeed(&t_ptr, baud_rate);
  tcsetattr(fd, TCSANOW, &t_ptr);

  if (signal(SIGINT, SIG_IGN) != SIG_IGN) {
    printf ("enable signal\n");
    signal(SIGINT, sig_handlr);
    }

  signal(SIGALRM, alarm_hdlr);
  alarm(5);

  while (1) {
    if (read(fd, &in_char, 1)) {
      printf ("received char = %x\n", in_char);
      }
    }

  close(fd);
  fclose(file_ptr);

  exit (0);
  }

void alarm_hdlr() {
  signal(SIGALRM,  alarm_hdlr);
  alarm(5);
  printf ("inside alarm_hdlr\n");
  }

void sig_handlr() {
  printf ("inside sig_handlr().\n");
  write(fd, bin_wt, 1);
  }

0
jian_zhang
Asked:
jian_zhang
  • 2
1 Solution
 
jian_zhangAuthor Commented:
Edited text of question
0
 
hotlavaCommented:
There seem to be several things missing from the code.  When changing ioctl flags, one would normally read the existing flags, and just set or clear the particular flag that they aare interested in.  This means that you do not have to know what all of the IO flags do, but just the ones you are interested in.  So my first recommendation is to change the flag setting code to a "get flags", clear IGNBRK and set BRKINT, "set flags".  And my second recommendation is to ensure that you are the controlling terminal of a foreground process group, like the man page says.  To do this is think you would use setpgrp - although I may be wrong here so you'll have to do some reading, but even so, the code you posted appears to make no effort to create a process group, so may be another possible cause of your problems.
0
 
jian_zhangAuthor Commented:
Hi, hotlava and other experts,

The above answer did help me to get an interrupt (signal) when a break char is received.  But the interrupt only occurs when the RxD line changes from low->high.  It seams to me that the COM port is waiting for a valid '0x00' with valid stop bit appears on RxD line when it generates the interrupt.  My application requires my code detects a high->low transition on RxD instead.  Any comment on this?

Thanks again.

Jian Zhang
DSC Communications
jzhang@optilink.dsccc.com
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now