Uart read fdmonitor not working after few minutes

I am faced the issue in uart fdmonitor handler,uart baudrate 460800. uart get interrupt every 1 milli second.

  1. In fdmonitor handler when we report a le_event_Report function it will work few minute,
    after that fdmonitor handler is not calling.
  2. cat /dev/ttyHS1 is also not printing any data.
  3. If we remove le_event_Report function from the fdmonitor handler it will work fine.
  4. if we restart app it work again.

please attach the application here
Please also try in WP76 R10.1 as i don’t see problem with that, not sure if issue happened only with 1ms interrupt

sorry your website is not supporting new user file attachement. please check below
root@swi-mdm9x28-wp:~# cm info
Device: WP7608
IMEI: 35291309036xxxx
IMEISV: 6
FSN: 3N050785621410
Firmware Version: SWI9X07Y_02.28.03.03 000000 jenkins 2019/05/21 03:33:04
Bootloader Version: SWI9X07Y_02.28.03.03 000000 jenkins 2019/05/21 03:33:04
MCU Version: 002.011
PRI Part Number (PN): 9908665
PRI Revision: 001.002
Carrier PRI Name: GENERIC
Carrier PRI Revision: 002.068_000
SKU: 1104194
Last Reset Cause: Reset, User Requested
Resets Count: Expected: 79 Unexpected: 0
^C
root@swi-mdm9x28-wp:~# legato version
20.04.0_16a16a0bfad7b1df9755ccd71cf393a0_modified

.c file*****
#include"mcuData.h"

static mcuApp_t App1;
mcuApp_t* hApp = &App1;

int WriteToUart(const uint8_t *wBuf , uint32_t wLen)
{
int retLen;
int offset=0;
LE_INFO(“seraia fd:%d”, hApp->serialFd);

PRINTDATAINHEX(“UWRITE”, (uint8_t*)wBuf, wLen);
while(offset < wLen)
{
retLen = write( hApp->serialFd ,wBuf+offset ,wLen-offset);
if(-1 == retLen)
{
break;
}
else if(retLen <= (wLen-offset))
{
offset = offset + retLen;
retLen = offset;
}
LE_INFO(“Uart write byte count:%d” ,retLen);

}
LE_INFO(“Uart Total write byte count:%d Recieved len:%d”,offset ,wLen);
LE_INFO("write to uart :%d ", retLen);
return retLen;
}

uint32_t fdmonitorCount=0;
uint32_t CheckMessageCount=0;
tm_Data_t ParseData;
void CheckMessageHdlr(void
ctx)
{
LE_INFO("%s", func);
LE_INFO(“eventCount checkMessge:%d”, CheckMessageCount++);
ParseData = (tm_Data_t*)ctx;
PRINTDATAINHEX(“read data”, ParseData->Buf, ParseData->bLen);
}

/*

  • AsyncRecvHandler () → Callback func for UART fd_monitor ,events(POLLIN).
    */
    tm_Data_t tmpData;
    void AsyncRecvHandler (int fd, short event)
    {
    int retval = -1;
    LE_INFO("%d %s %#x ",fd ,FUNCTION, event);

if((event & POLLIN))
{
LE_INFO(“eventCount fdmonitor:%d”,fdmonitorCount++);
memset(hApp->RxBuf, 0, sizeof(hApp->RxBuf) );
retval = read(fd, hApp->RxBuf, sizeof(hApp->RxBuf));

if(retval > 0 )
{

#if 1
memset(&tmpData, 0, sizeof(tmpData) );
tmpData.bLen = retval;
memcpy( &tmpData.Buf, hApp->RxBuf, retval);
le_event_Report(hApp->CheckMsgEvtId, &tmpData, sizeof(tmpData));//
#endif
}
}

if(event & POLLOUT)
{
le_fdMonitor_Disable(hApp->fdMonitorRef, POLLOUT);
}

if( (event & POLLRDHUP) || (event & POLLERR) || (event & POLLHUP))
{
LE_INFO(“event %#x”, event);
le_fdMonitor_Delete(hApp->fdMonitorRef);
usleep(100);
hApp->fdMonitorRef = le_fdMonitor_Create(“serial Comm”,
hApp->serialFd,
(le_fdMonitor_HandlerFunc_t) &AsyncRecvHandler,
POLLIN|POLLRDHUP|POLLERR|POLLHUP);
}
LE_INFO("%s done", func);
return;
}

/*

  • OpenUart() → Func Open’s the uart and set the custom Baudrate,
  • And also the Set to read the 8 bit data sets the start bit and stop bit.
    */
    int32_t OpenUart(void)
    {
    struct termios tty;

LE_INFO(“OpenUart called”);
hApp->serialFd = open(MCU_UART1, O_RDWR | O_NONBLOCK| O_NDELAY);
if(hApp->serialFd < 0 ){
LE_ERROR(“mcu uart open failed : %d %s”, errno, strerror(errno));
return LE_FAULT;
}

LE_INFO("%s:%d",hApp->PortName, hApp->serialFd);
if (tcgetattr (hApp->serialFd, &tty) != 0) //Get attribute Prop
{
LE_INFO(“error %d from tcgetattr”, errno);
return LE_FAULT;
}

LE_INFO(“OpenUart Opened uartd. Modifyuing UART settings”);
cfsetospeed (&tty, BAUDRATE); // O/p Baudrate setting
cfsetispeed (&tty, BAUDRATE); // I/p baudrate setting

tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8; // 8-bit chars
tty.c_cflag |= (CLOCAL | CREAD); // ignore modem controls,(

cfmakeraw(&tty); // Make these options as default.
tcflush(hApp->serialFd , TCIOFLUSH); // Push the changes onto Uart File Descrriptor
if (tcsetattr (hApp->serialFd, TCSANOW, &tty) != 0) // Setting the Attributes
{
LE_INFO (“error %d from tcsetattr”, errno);
return LE_FAULT;
}

// Create monitor FD handle for activity, as defined by the events
LE_INFO(“OpenUart Opened uartd. Adding fdMonitor”);
hApp->fdMonitorRef = le_fdMonitor_Create(“serial Comm”,
hApp->serialFd,
(le_fdMonitor_HandlerFunc_t) &AsyncRecvHandler,
POLLIN|POLLRDHUP|POLLERR|POLLHUP);
LE_INFO(“uart open success”);
return hApp->serialFd;
}

void TimerVerHDLR(le_timer_Ref_t timerref)
{
uint8_t data={“uart write done”};
WriteToUart(data, sizeof(data) );

}

void CreateVerTimer(void)
{
le_timer_Ref_t timerRef;
le_clk_Time_t clk={ 60, 0};

timerRef = le_timer_Create(“send data”);
le_timer_SetHandler(timerRef ,TimerVerHDLR);

le_timer_SetInterval(timerRef ,clk);
le_timer_SetRepeat(timerRef ,0);
le_timer_Start(timerRef);

}

void createParseeventHdlr(void)
{
LE_INFO("%s", func);
hApp->CheckMsgEvtId = le_event_CreateId(“checkMsg”, sizeof(tm_Data_t));
hApp->CheckMsgEvtHdlr = le_event_AddHandler(“chaeckMsgHdlr”, hApp->CheckMsgEvtId, CheckMessageHdlr);

}

void* AppThreadHdlr (void* context)
{
createParseeventHdlr();
if( OpenUart() < 0)
{
LE_INFO(“uart open fail”);
exit(EXIT_SUCCESS);
}

CreateVerTimer();
le_event_RunLoop();
}

COMPONENT_INIT
{
LE_INFO(“mcuData app start”);
le_thread_Ref_t ThreadRef;
ThreadRef = le_thread_Create(“mcuAPP”, AppThreadHdlr, NULL);
le_thread_Start(ThreadRef);
}

.h*****
#ifndef MCUDATA_H
#define MCUDATA_H

#include “legato.h”
#include “interfaces.h”
#include <termios.h>
#include <unistd.h>

#define MCU_UART1 “/dev/ttyHS1”

#define BAUDRATE B460800
#define MAXRXLEN 256
#define MAXMCUDATALEN 512

#define PROT_STX 0x02
#define PROT_ETX 0x03
#define PROT_DLE 0x10

#define MSGTYPE_LEN 1
#define MSGLEN_LEN 2
#define MSGCRC_LEN 2

#define PRINTDATAINHEX(_msgstr ,_buf ,_maxLen) {int _offset=0, _i=0,_ret=0;
int _max= _maxLen;
uint8_t _ptr= _buf;
char _debugstr[50];
LE_INFO("%s: Len=%d", _msgstr ,_max);
while(_max >= _offset) {
memset(_debugstr, 0, sizeof(_debugstr) );
for(_i=0,_ret=0; _i<10 && _max >= _offset;_i++) {
_ret+= sprintf((char
)_debugstr+_ret, “%02x ,”, _ptr[_offset]);
_offset++; }
LE_INFO("%s: %s", _msgstr, _debugstr); }
}

typedef struct mcu
{
int serialFd; ///< Serial device file descriptor
char *PortName; ///<
le_fdMonitor_Ref_t fdMonitorRef; ///< Reference to the fd monitor

uint8_t RxBuf[MAXMCUDATALEN];
uint16_t RxLen;

uint8_t MessageBuf[MAXMCUDATALEN];
uint16_t MessageBufIndex;

bool bDLEFound;

le_event_Id_t CheckMsgEvtId;
le_event_HandlerRef_t CheckMsgEvtHdlr;
}mcuApp_t;

typedef struct buffer
{
uint8_t Buf[MAXMCUDATALEN];
uint16_t bLen;
}tm_Data_t;

int WriteToUart(const uint8_t *, uint32_t );

#endif

.cdef********

sources:
{
mcuDataComponent.c
}

requires:
{
device:
{
[rw] /dev/ttyHS1 /dev/ttyHS1
}

}
.adef********
sandboxed: false
version: 1.0.0
start: auto

executables:
{

mcuData = ( mcuDataComponent )

}

processes:
{
run:
{
( mcuData )
}
// faultAction: restartApp
}

Please zip it and put to google drive.

BTW, I don’t see problem on R10.1
mcudata.log (49.3 KB)

please find attached sample code file.
mcudata

Hi jyijyi,

i tried in release 13.1 legato 19.02 fdmonitor is working in 1 millisec, but after i getting data from uart i need to send other application , so i created api event handler when we report this event handler event , again fdmonitor is hanging after few minute.
(NOTE:event handler registered function we are not doing any performance , suddenly i am returning from that function )

Do you have the reproducible steps for PC and mangoh red board?

hi,
Am trying to do an sample program to read the input from terminal and based on the input need to call a specific method any one guide me how to do it in vscode.

You can try this application

https://source.sierrawireless.com/resources/airprime/application_notes_and_code_samples/airprime_wp_series_and_fx30_uart_to_tcp_app/