English
Language : 

PIC32MX440F256H-80I Datasheet, PDF (241/646 Pages) Microchip Technology – 64/100-Pin General Purpose and USB 32-Bit Flash Microcontrollers
PIC32MX3XX/4XX
EXAMPLE 10-6: DMA INITIALIZATION WITH INTERRUPTS
/*
The following code example illustrates a DMA channel 0 interrupt configuration.
When the DMA channel 0 interrupt is generated, the CPU will jump to the vector assigned to DMA0
interrupt.
*/
IEC1CLR=0x00010000;
IFS1CLR=0x00010000;
// disable DMA channel 0 interrupts
// clear any existing DMA channel 0 interrupt flag
DMACONSET=0x00008000;
DCH0CON=0x03;
// enable the DMA controller
// channel off, priority 3, no chaining
DCH0ECON=0;
// no start or stop irq’s, no pattern match
DCH0SSA=0x1d010000;
DCH0DSA=0x1d020000;
DCH0SSIZ=0;
DCH0DSIZ=0;
DCH0CSIZ=0;
// program the transfer
// transfer source physical address
// transfer destination physical address
// source size 256 bytes
// destination size 256 bytes
// 256 bytes transferred pe event
DCH0INTCLR=0x00ff00ff;
DCH0INTSET=0x00090000;
// clear existing events, disable all interrupts
// enable Block Complete and error interrupts
IPC9CLR=0x0000001f;
IPC9SET=0x00000016;
IEC1SET=0x00010000;
// clear the DMA channel 0 priority and subpriority
// set IPL 5, subpriority 2
// enable DMA channel 0 interrupt
DCH0CONSET=0x80;
DCH0ECONSET=0x00000080;
// turn channel on
// initiate a transfer
// set CFORCE to 1
// do something else
// will get an interrupt when the block transfer is done
// or when error occurred
EXAMPLE 10-7: DMA CHANNEL 0 ISR
/*
The following code example demonstrates a simple Interrupt Service Routine for DMA channel 0
interrupts. The user’s code at this vector should perform any application specific operations
and must clear the DMA0 interrupt flags before exiting.
*/
void __ISR(_DMA_0_VECTOR, ipl5) __DMA0Interrupt(void)
{
int dmaFlags=DCH0INT&0xff;
// read the interrupt flags
// perform application specific operations in response to any interrupt flag set
DCH0INTCLR=0x000000ff;
IFS1CLR = 0x00010000;
}
// clear the DMA channel interrupt flags
// Be sure to clear the DMA0 interrupt flags
// before exiting the service routine.
Note:
The DMA ISR code example shows
MPLAB® C32 C compiler specific syntax.
Refer to your compiler manual regarding
support for ISRs.
© 2008 Microchip Technology Inc.
Preliminary
DS61143E-page 239