English
Language : 

PIC32MX440F256H-80I Datasheet, PDF (237/646 Pages) Microchip Technology – 64/100-Pin General Purpose and USB 32-Bit Flash Microcontrollers
PIC32MX3XX/4XX
EXAMPLE 10-4: CRC BACKGROUND MODE OPERATION
/*
The following code example illustrates a DMA calculation using the CRC background mode. Data is
transferred from a 256 bytes Flash buffer to a RAM buffer and the CRC is calculated while the
transfer takes place. */
unsigned int blockCrc;
// CRC of the flash block
IEC1CLR=0x00010000;
IFS1CLR=0x00010000;
// disable DMA channel 0 interrupts
// clear any existing DMA channel 0 interrupt flag
DMACONSET=0x00008000;
DCRCDATA=0xffff;
DCRCXOR=0x1021;
DCRCCON=0x0f80;
// enable the DMA controller
// seed the CRC generator
// Use the standard CCITT CRC 16 polynomial: X^16+X^12+X^5+1
// CRC enabled, polynomial length 16, background mode
// CRC attached to the DMA channel 0.
DCH0CON=0x03;
DCH0ECON=0;
// channel off, priority 3, no chaining
// no start irqs, no match enabled
DCH0SSA=VirtToPhys(flashBuff);
DCH0DSA=VirtToPhys(ramBuff);
DCH0SSIZ=0;
DCH0DSIZ=0;
DCH0CSIZ=0;
// program channel transfer
// transfer source physical address
// transfer destination physical address
// source size
// dst size
// 256 bytes per transfer
DCH0INTCLR=0x00ff00ff;
// DMA0: clear events, disable interrupts
DCH0CONSET=0x80;
// channel 0 on
DCH0ECONSET=0x00000080;
// initiate a transfer
// set CFORCE to 1
// do something else while the transfer takes place
// poll to see that the transfer was done
BOOL error=FALSE;
while(TRUE)
{
register int pollCnt;
// don’t poll in a tight loop
int dmaFlags=DCH0INT;
if( (dmaFlags& 0x3)
{
// CHERIF (DCHxINT<0>) or CHTAIF (DCHxINT<1> set
error=TRUE;
// error or aborted...
break;
}
else if (dmaFlags&0x8)
{
// CHBCIF (DCHxINT<3>) set
break;
// transfer completed normally
}
pollCnt=100;
// use an adjusted value here
while(pollCnt--);
// wait before polling again
}
if(!error)
{
blockCrc=DCRDATA;
}
else
{
}
// read the CRC of the transferred flash block
// process error
© 2008 Microchip Technology Inc.
Preliminary
DS61143E-page 235