//================================
/***************************************************
* Programmer: Syed Tahmid Mahbub
* Target PIC: PIC32MX250F128B
*
* Date: 05/08/2014 – 05/10/2014
*
* Program to test DMA operation
* DMA will transfer const (from FLASH) to PORTA
***************************************************/
#include “plib.h” // peripheral library
#include “settings.h” // configuration bits settings
const unsigned char portOut[] = {0x05, 0x0A};
unsigned int sourceAddr;
unsigned int destinationAddr;
void Initialize(void){
SYSTEMConfigPerformance(8000000); // Running at 8MHz for now
ANSELA = 0; ANSELB = 0;
TRISA = 0; TRISB = 0;
///// Virtual to physical memory
/* using a pointer returns virtual memory address:
* eg. const unsigned int* src = (void*) &LATA;
* returns 0xBF886030 -> agrees with datasheet
*
* reference manual says that to convert this to physical
* address, AND it with 0x1FFFFFFF and get the
* corresponding physical address
*/
///// Set source and destination addresses
sourceAddr = (unsigned int) &portOut & 0x1FFFFFFF; // Physical address of portOut
destinationAddr = (unsigned int) &LATA & 0x1FFFFFFF; // Physical address of LATA
///// Initialize dma first
DMACON = 0x8000; // dma module on
DCRCCON = 0; // crc module off
DCH0INT = 0; // interrupts disabled
DCH0SSA = sourceAddr; // source start address
DCH0DSA = destinationAddr; // destination start address
DCH0SSIZ = 2; // source size – 2 bytes
DCH0DSIZ = 1; // destination size – 1 byte
DCH0CSIZ = 1; // cell size – 1 bytes
DCH0ECON = 0x1310; // dma transfer triggered by interrupt 19: Timer 4
///// Initialize timer 4 now – timer 4 interrupt triggers dma transfer
PR4 = 3124; // 100 milliseconds
T4CON = 0x70; // prescaler 1:256, timer currently off
// timer 4 interrupt request triggers dma
///// Enable dma channel
DCH0CON = 0x93; // channel enabled, always on, priority 3
}
void main(void){
Initialize();
T4CONSET = 0x8000; // turn on timer 4
while (1){
}
}
//================================
The DMA module allows data transfer from a source to a destination without CPU intervention during data transfer. The data transfer can be triggered by any interrupt request within the PIC. An interesting point of note is that the DMA module maintains its own flags for detecting interrupt requests for data transfer start/abort requests. This is completely independent of the INT interrupt controller enable and flag settings/configuration.
Points of note on the DMA:
For further details on the DMA controller, go through the reference manual.
For information on using the DMA plib (peripheral library) functions, see: http://people.ece.cornell.edu/land/courses/ece4760/PIC32/