Reason for disabling IRQ in EDMA UART Example

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

Reason for disabling IRQ in EDMA UART Example

3,255 Views
darshan_shah1
Contributor II

Hi,

While going through the example code uart_edma_rb_trasnfer on FRDM-K64, in function EXAMPLE_GetRingBufferLengthEDMA, before getting received bytes in ring buffer, we are disabling IRQ.

What is the reason for this? Do we need to disable global IRQ or just UART?

/* Get how many bytes in ring buffer. */
static uint32_t EXAMPLE_GetRingBufferLengthEDMA(void)
{
uint32_t regPrimask = 0U;
uint32_t receivedBytes = 0U;

/* Disable IRQ, protect ring buffer. */
regPrimask = DisableGlobalIRQ();

receivedBytes =
EXAMPLE_RING_BUFFER_SIZE - EDMA_GetRemainingMajorLoopCount(EXAMPLE_UART_DMA_BASEADDR, UART_RX_DMA_CHANNEL);

/* If the received bytes is less than index value, it means the ring buffer has reached it boundary. */
if (receivedBytes < ringBufferIndex)
{
receivedBytes += EXAMPLE_RING_BUFFER_SIZE;
}

receivedBytes -= ringBufferIndex;

/* Enable IRQ if previously enabled. */
EnableGlobalIRQ(regPrimask);

return receivedBytes;
}

Tags (2)
0 Kudos
Reply
12 Replies

3,144 Views
nxf56274
NXP Employee
NXP Employee

Hi,

Disable the interrupt to avoid being disturbed by other interrupt and protect the data we are going to process from unexpected accessing. You would better not remove this code. It's a protection for the data.

Have a great day,
TIC

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

- We are following threads for 7 days after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
Reply

3,144 Views
darshan_shah1
Contributor II

Hi,

We have USB and UART both in our application. While integrating UART, we are seeing fault at usb_device_khci.c (Line No 639). I have doubt on disabling and enabling the IRQ. As in our application, we are continuously reading UART (UART is connected to modem). So we are calling EXAMPLE_GetRingBufferLengthEDMA API at every 50ms to check if we got any data from UART or not.

Let me know if we have any other way to check pending data bytes in ring-buffer.

0 Kudos
Reply

3,144 Views
nxf56274
NXP Employee
NXP Employee

Hi,

 

If you project do not have many interrupts, you can try to remove it.  

 

Have a great day,
TIC

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

- We are following threads for 7 days after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
Reply

3,144 Views
darshan_shah1
Contributor II

Hi,

We have multiple IRQ (SPI,I2C,USB,UART,SDIO). Is it good to remove it? What will be implecations?

0 Kudos
Reply

3,144 Views
nxf56274
NXP Employee
NXP Employee

Hi,

 

If you have many peripheral working with usb, you would better use rtos to manage them. If you do not use rtos,here is my suggestions. Do not remove the code. Set the interrupt priority for every peripheral according to your peripheral importance. Make sure when the usb is enumerating , no interrupt will disturb it. line 639 is belong to token interrupt. Set a flag for usb token interrupt. When the flag isn't cleared, other operation won't be permitted.

 

Have a great day,
TIC

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

- We are following threads for 7 days after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
Reply

3,144 Views
darshan_shah1
Contributor II

Hi,

Thanks for the answer. I have FreeRTOS. So what should be proper way? Should I disable disabling code and set priority accordingly?

0 Kudos
Reply

3,144 Views
nxf56274
NXP Employee
NXP Employee

Hi,

 

You should set the task priority properly. Remove the disabling irq code. 

 

Have a great day,
TIC

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

- We are following threads for 7 days after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
Reply

3,144 Views
darshan_shah1
Contributor II

Hi,

Thanks for confirmation.

After disabling code, I am still getting fault at usb_device_cdc_acm.c line no. 796.

What should be the cause for this?

0 Kudos
Reply

3,144 Views
nxf56274
NXP Employee
NXP Employee

Hi,

 

If you do not read the ring buffer, does it still have fault?

 

Have a great day,
TIC

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

- We are following threads for 7 days after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
Reply

3,144 Views
darshan_shah1
Contributor II

Hi,

Now I am not seeing fault yet after sometime (10 minutes) UART TX is not getting idle and due to this my application waits for infinite for this.

/* Wait for sending finished */
while (txOnGoing)
{
vTaskDelay(pdMS_TO_TICKS(10));
}

/* UART user callback */
void UART_UserCallback(UART_Type *base, uart_edma_handle_t *handle, status_t status, void *userData)
{
tx_status = status;
if (kStatus_UART_TxIdle == status)
{
txOnGoing = false;
}
}

0 Kudos
Reply

3,144 Views
nxf56274
NXP Employee
NXP Employee

Hi,

You question is deviated from the original question. Please create a new case.

 

Have a great day,
TIC

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

- We are following threads for 7 days after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
Reply

3,144 Views
cashapp_number8
Contributor I

Cash App Support Number | Call Toll free number now | 24/7 Helpdesk

Is your Cash App account or app not working properly? Having refund or login
problems? call 24/7 Cash App Support Number now for help for experts support.


Cash App Number | Call Our Toll Free Number now | customer service

Are you facing any issues with your cashapp account? call our Cash App Number
to get in touch with Customer Service. 24/7 help and support from Experts.

0 Kudos
Reply