<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic what is the best way for Timeout on UART RX with MQX? in MQX Software Solutions</title>
    <link>https://community.nxp.com/t5/MQX-Software-Solutions/what-is-the-best-way-for-Timeout-on-UART-RX-with-MQX/m-p/365271#M12046</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi to all,&lt;/P&gt;&lt;P&gt;I have develop (with support of another user of this community) an UART RX with demo board FRDM-K64 with MQX 4.1.1 using KDS 1.1.1&lt;/P&gt;&lt;P&gt;Now the code is that:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 12pt; font-family: inherit; color: #0000ff;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;main.c:&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;#include &amp;lt;mqx.h&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;#include &amp;lt;bsp.h&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;#include &amp;lt;sem.h&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;#include "main.h"&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;#if ! BSPCFG_ENABLE_IO_SUBSYSTEM&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;#error This application requires BSPCFG_ENABLE_IO_SUBSYSTEM defined non-zero in user_config.h. Please recompile BSP with this option.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;#endif&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;#ifndef BSP_DEFAULT_IO_CHANNEL_DEFINED&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;#error This application requires BSP_DEFAULT_IO_CHANNEL to be not NULL. Please set corresponding BSPCFG_ENABLE_TTYx to non-zero in user_config.h and recompile BSP with this option.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;#endif&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;#define MaxSci1_CHANNEL "ittyb:"&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;LWSEM_STRUCT&amp;nbsp;&amp;nbsp;&amp;nbsp; lwsemUartRX;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;typedef struct rx_str_template&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp; char data_buf_RX[256];&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp; _mqx_uint nCharRx;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp; _mqx_uint ConteggioInternoCharRicevuti;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;} RX_STR, * RX_STR_PTR;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;RX_STR rx_str;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;void main_task (uint32_t initial_data){&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp; _task_id&amp;nbsp;&amp;nbsp; task_id;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp; uint32_t result;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp; result = _lwsem_create(&amp;amp;lwsemUartRX, 0);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp; if (result != MQX_OK) {&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf("\nCreating lwsemUartRX failed: 0x%X", result);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _task_block();&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp; task_id = _task_create(0,READ_TASK, 0);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp; printf("\nread_task created, id 0x%lX", task_id);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp; while(1)&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp; {&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; _lwsem_wait(&amp;amp;lwsemUartRX);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf("\nData:\n ");&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int i =0;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for(i=0;i&amp;lt;rx_str.nCharRx;i++){&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf("%c",rx_str.data_buf_RX[i]);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf("\n");&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp; _task_block();&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;void read_task(uint32_t initial_data){&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp; MQX_FILE_PTR MaxSci1_dev = NULL;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp; bool disable_rx = FALSE;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp; rx_str.nCharRx = 0;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp; MaxSci1_dev =&amp;nbsp; fopen( MaxSci1_CHANNEL, NULL );&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp; if (MaxSci1_dev == NULL) {printf("\nError opening Sci1");}&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp; else{printf("\nSci1 opned!");}&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp; while (TRUE) {&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; fread(&amp;amp;(rx_str.data_buf_RX[rx_str.nCharRx]), 1, 1, MaxSci1_dev);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(rx_str.data_buf_RX[rx_str.nCharRx] == 0x0D){&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; _lwsem_post(&amp;amp;lwsemUartRX);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; rx_str.nCharRx++;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can see that the receive-task give the semaphore on the stop byte 0x0D, now I want that the semaphore will be give when elaps 200msec, so I need to implement a TimeOut that it will refresh every time I receive a char and when will be triggered it will give me the semaphpore.&lt;/P&gt;&lt;P&gt;There are two ways, I suppose, to do that&lt;/P&gt;&lt;P&gt;- Interrupt&lt;/P&gt;&lt;P&gt;-internal check on receive byte.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For the second choice one user of this community tell me this way:&lt;/P&gt;&lt;P style="font-size: 13.1428575515747px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;SPAN style="color: #339966;"&gt;Do&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.1428575515747px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;SPAN style="color: #339966;"&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.1428575515747px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d; text-indent: 36pt;"&gt;&lt;SPAN style="color: #339966;"&gt;bytesRead = fread(inBuffer,1,1,fd);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.1428575515747px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;SPAN style="color: #339966;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _time_get_elapsed_ticks(&amp;amp;lastByteTime);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.1428575515747px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;SPAN style="color: #339966;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; memcpy(&amp;amp;inPacket[inPacketSize], inBuffer, bytesReaded);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.1428575515747px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;SPAN style="color: #339966;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; inPacketSize += bytesReaded;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.1428575515747px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;SPAN style="color: #339966;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _time_get_elapsed_ticks(&amp;amp;now);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.1428575515747px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;SPAN style="color: #339966;"&gt;} while (_time_diff_milliseconds(&amp;amp;now, &amp;amp;lastByteTime, &amp;amp;overflow) &amp;lt;250);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN-US" style="font-size: 10pt; font-family: Helvetica, sans-serif; color: #3d3d3d;"&gt;But do not work because last time the cycle do/while condition will be check on the first byte of another packet because on last byte check condition, that are ok and cycle another time, and stuck on fread until next packet.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN-US" style="font-size: 10pt; font-family: Helvetica, sans-serif; color: #3d3d3d;"&gt;So I’m asking, how to do a timeout on last byte with interrupt and how to with internal cycle (if possible) ? what is the best in efficiency?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN-US" style="font-size: 10pt; font-family: Helvetica, sans-serif; color: #3d3d3d;"&gt;Many thanks,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN-US" style="font-size: 10pt; font-family: Helvetica, sans-serif; color: #3d3d3d;"&gt;Massimiliano&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 03 Oct 2014 11:36:11 GMT</pubDate>
    <dc:creator>holyhope</dc:creator>
    <dc:date>2014-10-03T11:36:11Z</dc:date>
    <item>
      <title>what is the best way for Timeout on UART RX with MQX?</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/what-is-the-best-way-for-Timeout-on-UART-RX-with-MQX/m-p/365271#M12046</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi to all,&lt;/P&gt;&lt;P&gt;I have develop (with support of another user of this community) an UART RX with demo board FRDM-K64 with MQX 4.1.1 using KDS 1.1.1&lt;/P&gt;&lt;P&gt;Now the code is that:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 12pt; font-family: inherit; color: #0000ff;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;main.c:&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;#include &amp;lt;mqx.h&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;#include &amp;lt;bsp.h&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;#include &amp;lt;sem.h&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;#include "main.h"&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;#if ! BSPCFG_ENABLE_IO_SUBSYSTEM&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;#error This application requires BSPCFG_ENABLE_IO_SUBSYSTEM defined non-zero in user_config.h. Please recompile BSP with this option.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;#endif&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;#ifndef BSP_DEFAULT_IO_CHANNEL_DEFINED&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;#error This application requires BSP_DEFAULT_IO_CHANNEL to be not NULL. Please set corresponding BSPCFG_ENABLE_TTYx to non-zero in user_config.h and recompile BSP with this option.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;#endif&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;#define MaxSci1_CHANNEL "ittyb:"&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;LWSEM_STRUCT&amp;nbsp;&amp;nbsp;&amp;nbsp; lwsemUartRX;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;typedef struct rx_str_template&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp; char data_buf_RX[256];&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp; _mqx_uint nCharRx;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp; _mqx_uint ConteggioInternoCharRicevuti;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;} RX_STR, * RX_STR_PTR;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;RX_STR rx_str;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;void main_task (uint32_t initial_data){&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp; _task_id&amp;nbsp;&amp;nbsp; task_id;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp; uint32_t result;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp; result = _lwsem_create(&amp;amp;lwsemUartRX, 0);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp; if (result != MQX_OK) {&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf("\nCreating lwsemUartRX failed: 0x%X", result);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _task_block();&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp; task_id = _task_create(0,READ_TASK, 0);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp; printf("\nread_task created, id 0x%lX", task_id);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp; while(1)&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp; {&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; _lwsem_wait(&amp;amp;lwsemUartRX);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf("\nData:\n ");&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int i =0;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for(i=0;i&amp;lt;rx_str.nCharRx;i++){&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf("%c",rx_str.data_buf_RX[i]);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf("\n");&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp; _task_block();&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;void read_task(uint32_t initial_data){&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp; MQX_FILE_PTR MaxSci1_dev = NULL;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp; bool disable_rx = FALSE;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp; rx_str.nCharRx = 0;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp; MaxSci1_dev =&amp;nbsp; fopen( MaxSci1_CHANNEL, NULL );&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp; if (MaxSci1_dev == NULL) {printf("\nError opening Sci1");}&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp; else{printf("\nSci1 opned!");}&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp; while (TRUE) {&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; fread(&amp;amp;(rx_str.data_buf_RX[rx_str.nCharRx]), 1, 1, MaxSci1_dev);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(rx_str.data_buf_RX[rx_str.nCharRx] == 0x0D){&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; _lwsem_post(&amp;amp;lwsemUartRX);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; rx_str.nCharRx++;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 13.1428575515747px; font-family: inherit; color: #ff0000;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can see that the receive-task give the semaphore on the stop byte 0x0D, now I want that the semaphore will be give when elaps 200msec, so I need to implement a TimeOut that it will refresh every time I receive a char and when will be triggered it will give me the semaphpore.&lt;/P&gt;&lt;P&gt;There are two ways, I suppose, to do that&lt;/P&gt;&lt;P&gt;- Interrupt&lt;/P&gt;&lt;P&gt;-internal check on receive byte.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For the second choice one user of this community tell me this way:&lt;/P&gt;&lt;P style="font-size: 13.1428575515747px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;SPAN style="color: #339966;"&gt;Do&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.1428575515747px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;SPAN style="color: #339966;"&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.1428575515747px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d; text-indent: 36pt;"&gt;&lt;SPAN style="color: #339966;"&gt;bytesRead = fread(inBuffer,1,1,fd);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.1428575515747px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;SPAN style="color: #339966;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _time_get_elapsed_ticks(&amp;amp;lastByteTime);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.1428575515747px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;SPAN style="color: #339966;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; memcpy(&amp;amp;inPacket[inPacketSize], inBuffer, bytesReaded);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.1428575515747px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;SPAN style="color: #339966;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; inPacketSize += bytesReaded;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.1428575515747px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;SPAN style="color: #339966;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _time_get_elapsed_ticks(&amp;amp;now);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.1428575515747px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;SPAN style="color: #339966;"&gt;} while (_time_diff_milliseconds(&amp;amp;now, &amp;amp;lastByteTime, &amp;amp;overflow) &amp;lt;250);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN-US" style="font-size: 10pt; font-family: Helvetica, sans-serif; color: #3d3d3d;"&gt;But do not work because last time the cycle do/while condition will be check on the first byte of another packet because on last byte check condition, that are ok and cycle another time, and stuck on fread until next packet.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN-US" style="font-size: 10pt; font-family: Helvetica, sans-serif; color: #3d3d3d;"&gt;So I’m asking, how to do a timeout on last byte with interrupt and how to with internal cycle (if possible) ? what is the best in efficiency?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN-US" style="font-size: 10pt; font-family: Helvetica, sans-serif; color: #3d3d3d;"&gt;Many thanks,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN-US" style="font-size: 10pt; font-family: Helvetica, sans-serif; color: #3d3d3d;"&gt;Massimiliano&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Oct 2014 11:36:11 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/what-is-the-best-way-for-Timeout-on-UART-RX-with-MQX/m-p/365271#M12046</guid>
      <dc:creator>holyhope</dc:creator>
      <dc:date>2014-10-03T11:36:11Z</dc:date>
    </item>
    <item>
      <title>Re: what is the best way for Timeout on UART RX with MQX?</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/what-is-the-best-way-for-Timeout-on-UART-RX-with-MQX/m-p/365272#M12047</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Massimiliano,&lt;/P&gt;&lt;P&gt;It has been long time since I created and tested my own custom read with a timeout.&amp;nbsp; I have attached that test file.&amp;nbsp; Hopefully it helps.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;David&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Oct 2014 14:22:14 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/what-is-the-best-way-for-Timeout-on-UART-RX-with-MQX/m-p/365272#M12047</guid>
      <dc:creator>DavidS</dc:creator>
      <dc:date>2014-10-06T14:22:14Z</dc:date>
    </item>
    <item>
      <title>Re: what is the best way for Timeout on UART RX with MQX?</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/what-is-the-best-way-for-Timeout-on-UART-RX-with-MQX/m-p/365273#M12048</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, many thanks for your answer.&lt;/P&gt;&lt;P&gt;I'm sorry for my delay but I have several problem.&lt;/P&gt;&lt;P&gt;today or next week I will test your routine and give you an answer.&lt;/P&gt;&lt;P&gt;sorry another time for delay and really many thanks for your help!&lt;/P&gt;&lt;P&gt;Massimiliano&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;@edit: sorry for delay, I can't test this routine now, I have study that and seems ok but I can't test now :-( &lt;/P&gt;&lt;P&gt;priority were reverse so this go in second stage... I will test as soon as possible and give you an answer! &lt;/P&gt;&lt;P&gt;Many thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Oct 2014 06:59:15 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/what-is-the-best-way-for-Timeout-on-UART-RX-with-MQX/m-p/365273#M12048</guid>
      <dc:creator>holyhope</dc:creator>
      <dc:date>2014-10-10T06:59:15Z</dc:date>
    </item>
    <item>
      <title>Re: what is the best way for Timeout on UART RX with MQX?</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/what-is-the-best-way-for-Timeout-on-UART-RX-with-MQX/m-p/365274#M12049</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi &lt;STRONG style="font-size: 11.6999998092651px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;A href="https://community.nxp.com/people/holyhope"&gt;holyhope&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How did you go with your problem with UART RX.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Were you able to receive and terminate after a timeout?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If so, could you share your solution?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 15 Mar 2015 01:47:22 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/what-is-the-best-way-for-Timeout-on-UART-RX-with-MQX/m-p/365274#M12049</guid>
      <dc:creator>F50SC</dc:creator>
      <dc:date>2015-03-15T01:47:22Z</dc:date>
    </item>
    <item>
      <title>Re: what is the best way for Timeout on UART RX with MQX?</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/what-is-the-best-way-for-Timeout-on-UART-RX-with-MQX/m-p/365275#M12050</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&amp;nbsp; ,&lt;STRONG style="font-size: 11.6999998092651px;"&gt;&lt;A _jive_internal="true" data-containerid="-1" data-containertype="-1" data-content-finding="Community" data-objectid="225016" data-objecttype="3" href="https://community.nxp.com/people/holyhope" style="font-weight: inherit; font-style: inherit; font-family: inherit; color: #017bba; text-decoration: underline;"&gt;Massimiliano Sturla&lt;/A&gt;​&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 11.6999998092651px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; How about your test ?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 11.6999998092651px;"&gt;Thanks!&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 21 Sep 2015 12:07:20 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/what-is-the-best-way-for-Timeout-on-UART-RX-with-MQX/m-p/365275#M12050</guid>
      <dc:creator>tongjianwu</dc:creator>
      <dc:date>2015-09-21T12:07:20Z</dc:date>
    </item>
  </channel>
</rss>

