K60n512 serial in block mode,how to change it?MQX4.0

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

K60n512 serial in block mode,how to change it?MQX4.0

Jump to solution
815 Views
jackerison
Contributor III

Description:I was using board K60n512.I want to use the serial port to read data,But I find it has some problems.when I use to read

data from serial port,it blocks at there,until it has recevied data from serial prot.when I  change the open_flages:fopen("ttyf:",(pointer)IO_SERIAL_RAW_IO | IO_SERIAL_NON_BLOCKING),but it seems doesn‘t work.it blocks until it recevied some data.

I use the primitve libraries and configuration.and test the com ttya to ttyf

I find that ttya,ttyb,ttyc,ttye can achieve the NON_BLOCKING function by using the IO_SERIAL_NON_BLOCK mode,the  othesrs doesn't.

I find that the  "#define BSPCFG_ENABLE_TTYD  1"         and  "#define BSPCFG_ENABLE_TTYF    1" in the  user_config.h file.

Code:

FILE_PTR serial_f=fopen("ttyf:",(pointer)(IO_SERIAL_RAW_IO | IO_SERIAL_NON_BLOCKING));

fgetc(serial_fd);//if doesn't have data,it will block at here

I don't konw why,it puzzled me for a long time.

0 Kudos
Reply
1 Solution
596 Views
jackerison
Contributor III

Thks for your tip.I typed it wrong in the page,but not in my project code.I have found the reason,because I have added  the code

  uint_32 flags=0;

  ioctl(serial_fd, IO_IOCTL_SERIAL_SET_FLAGS, &flags);

after the

FILE_PTR serial_fd=fopen("ttyf:",(pointer)(IO_SERIAL_RAW_IO | IO_SERIAL_NON_BLOCKING));

,so it will clear the IO_SERIAL_NON_BLOCKING mode that set in the fopen function.


View solution in original post

0 Kudos
Reply
2 Replies
596 Views
Martin_
NXP Employee
NXP Employee

your code:

FILE_PTR serial_f=fopen("ttyf:",(pointer)(IO_SERIAL_RAW_IO | IO_SERIAL_NON_BLOCKING));

fgetc(serial_fd);//if doesn't have data,it will block at here

check that you're using the right file

597 Views
jackerison
Contributor III

Thks for your tip.I typed it wrong in the page,but not in my project code.I have found the reason,because I have added  the code

  uint_32 flags=0;

  ioctl(serial_fd, IO_IOCTL_SERIAL_SET_FLAGS, &flags);

after the

FILE_PTR serial_fd=fopen("ttyf:",(pointer)(IO_SERIAL_RAW_IO | IO_SERIAL_NON_BLOCKING));

,so it will clear the IO_SERIAL_NON_BLOCKING mode that set in the fopen function.


0 Kudos
Reply