Does anyone have an example on using IO_IOCTL_SERIAL_GET_STATS to see the io_info_ptr->RX_CHARS? I am having trouble determining how to properly turn the params pointer into the io_info_ptr.
Thanks,
Lee
Solved! Go to Solution.
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);
}
Hi Lee,
I have implemented it in the code at the following post differently than soledad (her approach is nicer):
Receiving characters from a UART under MQX
I was looking at the RX_OVERRUNS field specifically buy with the call below you get all the flags to review.
uint32_t param[15]; //DES has extra room to buffer
if(lengthRead) {
_io_ioctl(stdout, IO_IOCTL_SERIAL_GET_STATS, ¶m); //DES get UART statisics
if(param[7]) { //DES check RX_OVERRUNS
_io_puts("\nRX_OVERRUNS Error...\n");
fflush(stdout);
_io_ioctl(stdout, IO_IOCTL_SERIAL_CLEAR_STATS, ¶m); //DES clear UART statisics
}
Look in serl_kuart.h for definitions of the Stats.
typedef struct kuart_info_struct
{
/* The current init values for this port */
KUART_INIT_STRUCT INIT;
/* The sci device register */
UART_MemMapPtr SCI_PTR;
/* The previous interrupt handler and data */
void (_CODE_PTR_ OLD_ISR)(void *);
void (_CODE_PTR_ OLD_ISR_EXCEPTION_HANDLER)(uint32_t, uint32_t, void *,
void *);
void *OLD_ISR_DATA;
/* Various flags */
uint32_t FLAGS;
/* Statistical information */
uint32_t INTERRUPTS;
uint32_t RX_CHARS;
uint32_t TX_CHARS;
uint32_t RX_BREAKS;
uint32_t RX_PARITY_ERRORS;
uint32_t RX_FRAMING_ERRORS;
uint32_t RX_OVERRUNS;
uint32_t RX_DROPPED_INPUT;
uint32_t RX_NOISE_ERRORS;
Look in serl_pol_kuart.c for the order in which the param array gets filled as it is slightly different than the definition order.
case IO_IOCTL_SERIAL_GET_STATS:
*param_ptr++ = io_info_ptr->INTERRUPTS;
*param_ptr++ = io_info_ptr->RX_CHARS;
*param_ptr++ = io_info_ptr->TX_CHARS;
*param_ptr++ = io_info_ptr->RX_BREAKS;
*param_ptr++ = io_info_ptr->RX_PARITY_ERRORS;
*param_ptr++ = io_info_ptr->RX_FRAMING_ERRORS;
*param_ptr++ = io_info_ptr->RX_OVERRUNS;
*param_ptr++ = io_info_ptr->RX_DROPPED_INPUT;
*param_ptr++ = io_info_ptr->RX_NOISE_ERRORS;
break;
Regards,
David
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);
}