Each time a bit operation of some global variable is done before DMA is started, the DMA forward int

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

Each time a bit operation of some global variable is done before DMA is started, the DMA forward int

406 Views
ALOONG
Contributor I

I am in the use of LPC4370 microcontroller HSADC+DMA, if each time in the DMA before do some global variable bit operations, each DMA into the interrupt time will be longer, do not know what is the reason, do not have brothers know?

My code:

void DMA_IRQHandler(void)
{
if(LPC_GPDMA->INTSTAT & (1UL << 7))
{
LPC_GPDMA->INTTCCLEAR |= (1UL <<7);
LPC_GPIO_PORT->B[0][13] = false;
ucColletStop = 1;
}
}

 

int main(void)
{

SystemCoreClockUpdate();

Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, 0, 13);
Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, 13, false);

HsadcInit();
DmaInit();

for(uint32_t i = 50000000; i > 0; i--){__asm("nop");}//1s
LPC_GPIO_PORT->B[0][13] = true;
Chip_HSADC_SWTrigger(LPC_ADCHS);


while(1)
{
if(ucColletStop == 1)
{
ucColletStop = 0;


for(uint32_t i = 1000000; i > 0; i--){__asm("nop");}//20ms

Chip_HSADC_SetActiveDescriptor(LPC_ADCHS, 1, 0);//Stop HSADC
Chip_HSADC_SWTrigger(LPC_ADCHS);


for(uint32_t i = 1000000; i > 0; i--){__asm("nop");}//20ms

for(uint16_t i = 0; i < 1024; i++)
{

ulConvertedData[2*i] = dma_buffer[i]&0xFFF;
ulConvertedData[2*i+1] = (dma_buffer[i]>>16)&0xFFF;
}


for(uint32_t i = 1000000; i > 0; i--){__asm("nop");}//20ms

Chip_HSADC_SetActiveDescriptor(LPC_ADCHS, 0, 1);//Start HSADC
CollectStart();//Start DMA
Chip_HSADC_SWTrigger(LPC_ADCHS);

LPC_GPIO_PORT->B[0][13] = true;
}


}

}

Labels (1)
0 Kudos
Reply
1 Reply

373 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello @ALOONG 

 

  1. a bit operation of some global variable (e.g., var |= 0x01) may trigger multiple ​Read-Modify-Write  operations. If the DMA is accessing the same memory region (e.g., the ADC buffer) during this time, the CPU and DMA will contend for the bus, resulting in ​bus arbitration delays.

  2. Check the DMA interrupt priority to ensure it is higher than other non-real-time tasks。

 

BR

Alice

0 Kudos
Reply