Chip_UART_ReadRB() Not Correctly Implemented?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Chip_UART_ReadRB() Not Correctly Implemented?

1,028 Views
kenatmicrolynx
Contributor I

Has anyone successfully used the method Chip_UART_ReadRB() as implemented in LPCOpen 2.1 in uart_17xx_40xx.c? I ask because the code does not look complete. This is what I see in the library source code:

/* Copy data from a receive ring buffer */
int Chip_UART_ReadRB(LPC_USART_T *pUART, RINGBUFF_T *pRB, void *data, int bytes)
{
    (void) pUART;

    return RingBuffer_PopMult(pRB, (uint8_t *) data, bytes);
}

Two things:

1. The "(void)pUART;" does nothing

2. Interrupts should be getting disabled around the call to RingBuffer_PopMul()

Thanks,

Ken

Labels (2)
0 Kudos
3 Replies

679 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Ken,

   I have test this API function on my EA LPC4088 board, it works.

pastedImage_1.png

  You can find, when I use the serial assistant send the UART data to the LPC4088, the Chip_UART_ReadRB()  can get the data, and use the Chip_UART_SendRB send it back.

 About your two question:

1. The "(void)pUART;" does nothing

 Answer: Yes, it does nothing, but I think it used for the API format, just used for the good readability.It's the write habit. It won't influence the function, so you don't need to care about it.

2. Interrupts should be getting disabled around the call to RingBuffer_PopMul()

Answer: No, you don't need to disable the interrupt, actually, interrupt receive the data with rxring:

void HANDLER_NAME(void)
{
    /* Want to handle any errors? Do it here. */

    /* Use default ring buffer handler. Override this with your own
       code if you need more capability. */
    Chip_UART_IRQRBHandler(UART_SELECTION, &rxring, &txring);
}

Then use the RingBuffer_PopMul copy the rxring data to the key like this:

bytes = Chip_UART_ReadRB(UART_SELECTION, &rxring, &key, 1);

I have test it, the function works OK, give you another test result, you can find I can use this API receive the data successfully.

pastedImage_2.png


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

679 Views
kenatmicrolynx
Contributor I

Hi Kerry,

Thanks for taking the time to respond to this.

With respect, I'm still not convinced that a Chip_UART_ReadRB() is interrupt safe. A simple keyboard typing test wouldn't expose that kind of bug. To expose this bug the Rx data interrupt would have to firing very frequently while the main code is in RingBuffer_PopMult() pulling data off the ring buffer.

I don't have the bandwidth to write a test for this at the moment, maybe when I retire I will :smileyhappy:

Ken

0 Kudos

679 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Ken,

  Chip_UART_ReadRB()  is just used to read the buffer data which saved data in the interrupt ISR, Chip_UART_ReadRB()  is not the interrupt process function, if you are not sure it works, you also can save the data in the ISR directly by yourself.

Wish it helps you!


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos