Hi Robert,
I could not find such document but I have enabled NON_BLOCKING functionality on UART drivers and implement a while forever loop that polls for data on both UART modules.
fread and fwrite functions return number of data sent/written so when polling for incoming data, fread function returns 0 when no data is available, otherwise, return 1 (in my case, I requested to read just 1 byte) this way I can send this data to opposite UART.
In your first comment you tried to enable this functionality using:
ioctl(p_uart0 , IO_IOCTL_SERIAL_SET_FLAGS, (void *)(IO_SERIAL_TRANSLATION | IO_SERIAL_NON_BLOCKING));
but for this ioctl function, parameters should be passed throug pointers, for example:
char flags = IO_SERIAL_NON_BLOCKING;
ioctl(g_uart2_pointer, IO_IOCTL_SERIAL_GET_FLAGS, (void *)&flags)
due in _io_serial_int_ioctl function, this parameters is obtained from a pointer (serl_int.c line 571):
case IO_IOCTL_SERIAL_SET_FLAGS:
int_io_dev_ptr->FLAGS = *((_mqx_uint_ptr)param_ptr);
fd_ptr->FLAGS = *((_mqx_uint_ptr)param_ptr);
This is not needed when openning UART port for first time:
g_uart2_pointer = fopen(UART2_PORT_NAME,(char *)IO_SERIAL_NON_BLOCKING);
Once, NON_BLOCKING functionality is enabled, you can implement your polling system without blocking this task. Here is my code for this unique task:
void UART_Bridge_task(uint32_t initial_data) {
/* UART Pointer*/
MQX_FILE_PTR g_uart1_pointer = NULL;
MQX_FILE_PTR g_uart2_pointer = NULL;
uint32_t read_bytes = 0, written_bytes = 0;
uint8_t received_bytes = 0;
char flags;
printf("Opening UART1 port \"%s\" .......",UART1_PORT_NAME);
/* Try to open this port with NON_BLOCKING functionality */
g_uart1_pointer = fopen(UART1_PORT_NAME, (char *)IO_SERIAL_NON_BLOCKING);
if (NULL == g_uart1_pointer) {
printf("[FAIL]\n");
_task_block();
} else {
printf("[DONE]\n");
}
/* Get Driver's flags*/
if (MQX_OK != ioctl(g_uart1_pointer, IO_IOCTL_SERIAL_GET_FLAGS, (void *)&flags)) {
printf("Error getting UART flags\n");
} else {
/* Verify if NON_BLOCKING functionality is enabled */
if (0 == (flags & IO_SERIAL_NON_BLOCKING)) {
/* Add NON_BLOCKING functionality to current configuration */
flags |= IO_SERIAL_NON_BLOCKING;
if (MQX_OK != ioctl(g_uart1_pointer, IO_IOCTL_SERIAL_SET_FLAGS, (void *)&flags)) {
printf("Error setting flags\n");
}
}
}
printf("Opening UART2 port \"%s\" .......",UART2_PORT_NAME);
g_uart2_pointer = fopen(UART2_PORT_NAME,(char *)IO_SERIAL_NON_BLOCKING);
if (NULL == g_uart2_pointer) {
printf("[FAIL]\n");
_task_block();
} else {
printf("[DONE]\n");
}
if (MQX_OK != ioctl(g_uart2_pointer, IO_IOCTL_SERIAL_GET_FLAGS, (void *)&flags)) {
printf("Error getting UART flags\n");
} else {
if (0 == (flags & IO_SERIAL_NON_BLOCKING)) {
flags |= IO_SERIAL_NON_BLOCKING;
if (MQX_OK != ioctl(g_uart2_pointer, IO_IOCTL_SERIAL_SET_FLAGS, (void *)&flags)) {
printf("Error setting flags\n");
}
}
}
while (1) {
read_bytes = fread((void *)&received_bytes,1,1,g_uart1_pointer);
if (read_bytes != 0) {
written_bytes = fwrite((void *)&received_bytes, 1, read_bytes, g_uart2_pointer);
if (written_bytes != read_bytes) {
/* Error handling */
}
}
read_bytes = fread((void *)&received_bytes,1,1,g_uart2_pointer);
if (read_bytes != 0) {
written_bytes = fwrite((void *)&received_bytes, 1, read_bytes, g_uart1_pointer);
if (written_bytes != read_bytes) {
/* Error handling */
}
}
}
}
Could you try this program and see if this fits your needs?
I hope this can helps you,
Best Regards,
Isaac
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------