CPU_INT08U PMP_Read(CPU_INT16U address) { #ifdef _TARGET_440H #else CPU_INT08U value; PMPSetAddress(address); PMPMasterRead(); // Read the previous value and start a read operation onto PMP value = mPMPMasterReadByte(); // Read the actual latched value return value; #endif }
/********************************************************************* * Function: * * PreCondition: * * Input: * * Output: * * Side Effects: * * Overview: * * Note: ********************************************************************/ inline BYTE __attribute__((always_inline)) Ex16LCDGetChar(void) { BYTE data; PMPSetAddress(0x0001); data = PMPMasterRead(); MSTimerWait(2); // wait 1ms return data; }
//------------------------------PMP Handler------------------------------------- void __ISR(_EXTERNAL_0_VECTOR, IPL6) GetSlaveData(void){ unsigned char pitch, vel; PMPMasterRead(); pitch = mPMPMasterReadByte(); vel = mPMPMasterReadByte(); if(!USBHandleBusy(USBTxHandle)) { midiData.Val = 0; //must set all unused values to 0 midiData.CableNumber = 0; midiData.CodeIndexNumber = MIDI_CIN_NOTE_ON; midiData.DATA_0 = 0x90; //Note on midiData.DATA_1 = pitch + 60; //pitch midiData.DATA_2 = vel; //velocity USBTxHandle = USBTxOnePacket(MIDI_EP,(BYTE*)&midiData,4); } mINT0ClearIntFlag(); }
int main(void) { int ix; int errCnt=0; int dmaChn=0; // the DMA channel to use // Configure the device for maximum performance but do not change the PBDIV // Given the options, this function will change the flash wait states, RAM // wait state and enable prefetch cache but will not change the PBDIV. // The PBDIV value is already set via the pragma FPBDIV option above.. SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE); // init the pseudo-random generator srand(ReadCoreTimer()); // fill the bufffers with some random data for(ix=0; ix<sizeof(srcBuff); ix++) { srcBuff[ix]=rand(); dstBuff[ix]=rand(); } // setup the PMP mPMPOpen(PMP_CONTROL, PMP_MODE,PMP_PORT_PINS ,PMP_INTERRUPT); // setup the external memory device address PMPSetAddress(PMP_EXT_ADDR); // Open the desired DMA channel. We use priority 0. DmaChnOpen(dmaChn, 0, DMA_OPEN_DEFAULT); // set the transfer event control: what event is to start the DMA transfer DmaChnSetEventControl(dmaChn, DMA_EV_START_IRQ(_PMP_IRQ)); // set the transfer parameters: source & destination address, source & destination size, number of bytes per event DmaChnSetTxfer(dmaChn, srcBuff, (void*)&PMDIN, sizeof(srcBuff), 2, 2); // once we configured the DMA channel we can enable it // now it's ready and waiting for an event to occur... DmaChnEnable(dmaChn); // force the first transfer, the PMP is quiet DmaChnForceTxfer(dmaChn); // wait for the transfer to be completed while(!(DmaChnGetEvFlags(dmaChn)&DMA_EV_BLOCK_DONE)) { // do some other useful work } // setup the external memory device address PMPSetAddress(PMP_EXT_ADDR); // flush the PMP data latches PMPMasterRead(); // set the transfer parameters: source & destination address, source & destination size, number of bytes per event DmaChnSetTxfer(dmaChn, (void*)&PMDIN, dstBuff, 2, sizeof(dstBuff), 2); DmaChnEnable(dmaChn); DmaChnForceTxfer(dmaChn); // wait for the transfer to be completed while(!(DmaChnGetEvFlags(dmaChn)&DMA_EV_BLOCK_DONE)) { // do some other useful work } // compare the transfer completed ok for(ix=0; ix<sizeof(srcBuff); ix++) { if(srcBuff[ix]!=dstBuff[ix]) { errCnt++; } } // close the PMP mPMPClose(); while(1); return errCnt; }