How can I test if GETCHAR() will block?

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

How can I test if GETCHAR() will block?

1,073件の閲覧回数
robertpoor
Senior Contributor I

We are developing a device around the MKL27Z64xxx, and will be using its UART for calibration and testing.  The processor will be running a real-time process until the user types a character, at which point it will drop out of real time and do calls to GETCHAR() to process the user input.

 

Is there a function call that will tell me if GETCHAR() has a character available, i.e., will not block when I call it?

 

ラベル(1)
タグ(1)
0 件の賞賛
3 返答(返信)

687件の閲覧回数
robertpoor
Senior Contributor I

XiangJun Rong:

Thank you for your response!  What I ended up doing is writing a simple method 'hasChar()' for the LPUART as follows:

bool hasChar(LPUART_Type *base) {
     return !!(base->STAT & LPUART_STAT_RDRF_MASK);
}

... then all I need to do is call hasChar().  If it returns true, then I can call getchar() and know that it won't block.

0 件の賞賛

687件の閲覧回数
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

Obviously, you only read the Uart status register, you do NOT repeat reading the status register to poll the status, I am sure it will not block.

Hope it can help you.

BR

Xiangjun Rong

0 件の賞賛

687件の閲覧回数
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Robert,

I suppose that you have a host processor, the host processor can send instruction to MKL27 via UART interface. If it is the case, you do not need to call the GETCHAR() function, you can set the UART of MKL27 in interrupt mode, once the host send an instruction to MKL27, the UART of MKL27 will receive the instruction and trigger an interrupt to MKL27 core so that user can deal with the instruction in UART ISR. You can use polling mode to check if the UART has received a char, the efficency of MKL27 is low in the mode.

In conclusion, I suggest you use UART interrupt mode, in the ISR of UART, you can write code to deal with the instruction from host.

Hope it can help you

BR

XiangJun Rong

0 件の賞賛