Hello Lee Penn,
IO_IOCTL_SERIAL_GET_STATS is used to get the statistics information of the serial port, e.g. Rx parity error, overrun, etc. If you want to check whether there is character received, _io_fstatus() could be used like: bCharRecved = _io_fstatus(uart3_file);
You may use that code as reference. I hope it helps!!!
Have a great day,
Sol
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
/* Task IDs */
#define NILL_TASK 5
extern void nill_task(uint_32);
KUART_INFO_STRUCT stats;
// serial port settings
uint_32 baud = 9600, *baud_ptr = &baud;
uint_32 databits = 9, *databits_ptr = &databits;
uint_32 stopbits = 1, *stopbits_ptr = &stopbits;
//uint_8 parity = IO_SERIAL_PARITY_NONE, *parity_ptr = &parity;
uint_32 parity = IO_SERIAL_PARITY_EVEN, *parity_ptr = &parity;
//uint_8 parity = IO_SERIAL_PARITY_ODD, *parity_ptr = &parity;
//uint_8 parity = IO_SERIAL_PARITY_MARK, *parity_ptr = &parity;
const unsigned char serial_options = (IO_SERIAL_RAW_IO);
const char sendstring[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz", *sendstring_ptr = &sendstring[0];
char recvstring[20];
const TASK_TEMPLATE_STRUCT MQX_template_list[] =
{
/* Task Index, Function, Stack, Priority, Name, Attributes, Param, Time Slice */
{ NILL_TASK, nill_task, 4000, 8, "nill", MQX_AUTO_START_TASK, 0, 0 },
{ 0 }
};
/*TASK*-----------------------------------------------------
*
* Task Name : nill_task
* Comments :
* This task does nothing
*
*END*-----------------------------------------------------*/
void nill_task
(
uint_32 initial_data
)
{
MQX_FILE_PTR serial_fd;
uint_32 flags = IO_SERIAL_NON_BLOCKING;
serial_fd = fopen("ttyd:", (char const*) serial_options);
ioctl(serial_fd, IO_IOCTL_SERIAL_SET_BAUD, baud_ptr);
ioctl(serial_fd, IO_IOCTL_SERIAL_SET_FLAGS,&flags );
write(serial_fd, (void *) sendstring_ptr, 62);
ioctl( serial_fd , IO_IOCTL_SERIAL_WAIT_FOR_TC, NULL );
fflush(serial_fd);
ioctl( serial_fd, IO_IOCTL_SERIAL_GET_STATS, (pointer)&stats);
ioctl(serial_fd, IO_IOCTL_SERIAL_GET_FLAGS,&flags );
while(1)
read(serial_fd, recvstring, 20);
_io_fclose(serial_fd);
_mqx_exit(0);
}