void dma_main(void){ #else void main(void){ #endif DMA_DESC dmaChannel; char sourceString[56] = "This is a test string used to demonstrate DMA transfer."; //56 bytes char destString[56]; INT8 i; INT8 errors = 0; initDma(); //Clearing the destination memset(destString,0,sizeof(destString)); // Setting up the DMA channel. SET_WORD(dmaChannel.SRCADDRH, dmaChannel.SRCADDRL, &sourceString); // The start address of the data to be transmitted SET_WORD(dmaChannel.DESTADDRH, dmaChannel.DESTADDRL, &destString); // The start address of the destination. SET_WORD(dmaChannel.LENH, dmaChannel.LENL, sizeof(sourceString)); // Setting the number of bytes to transfer. dmaChannel.VLEN = VLEN_USE_LEN; // Using the length field to determine how many bytes to transfer. dmaChannel.PRIORITY = PRI_HIGH; // High priority. dmaChannel.M8 = M8_USE_8_BITS; // Irrelevant since length is determined by the LENH and LENL. dmaChannel.IRQMASK = FALSE; // The DMA shall not issue an IRQ upon completion. dmaChannel.DESTINC = DESTINC_1; // The destination address is to be incremented by 1 after each transfer. dmaChannel.SRCINC = SRCINC_1; // The source address inremented by 1 byte after each transfer. dmaChannel.TRIG = DMATRIG_NONE; // The DMA channel will be started manually. dmaChannel.TMODE = TMODE_BLOCK; // The number of bytes specified by LENH and LENL is transferred. dmaChannel.WORDSIZE = WORDSIZE_BYTE; // One byte is transferred each time. // Using DMA channel 0. // Setting where the DMA channel is to read the desciptor and arming the DMA channel. DMA_SET_ADDR_DESC0(&dmaChannel); DMA_ABORT_CHANNEL(0); DMA_ARM_CHANNEL(0); //Waiting for the user to start the transfer. lcdUpdate((char*)"Press S1",(char*)"to start DMA."); while(!buttonPushed()); // Clearing all DMA complete flags and starting the transfer. DMAIRQ = 0x00; DMA_START_CHANNEL(0); // Waiting for the DMA to finish. while(!(DMAIRQ & DMA_CHANNEL_0)); // Verifying that data is transferred correctly for(i=0;i<sizeof(sourceString);i++) { if(sourceString[i] != destString[i]) errors++; } //Displaying the result if(errors == 0) {lcdUpdate((char*)"Dma transfer",(char*)"correct!");} else {lcdUpdate((char*)"Error in DMA",(char*)"Transfer");} haltApplicationWithLED(); return; }
void flash_main(void){ #else void main(void){ #endif BYTE buffer[30]; char inputBuffer[STRING_LENGTH]; INT8 pointer = 0; BOOL stop = FALSE; BOOL write = FALSE; char c; char *menuText[] = {(char*)" CPU write?", (char*)" DMA write?"}; BYTE command; BOOL unUsed; initFlash(); // Clearing buffers memset(buffer,0,sizeof(buffer)); memset(inputBuffer,0,sizeof(inputBuffer)); // Setting up UART UART_SETUP(0,57600,HIGH_STOP); UTX0IF = 1; // Set UART 0 TX interrupt flag while(getJoystickDirection() != CENTRED); //Displaying the stored flash message. lcdUpdateLine(LINE1,(char*)"Last written:"); if((unUsed = flashUnused((BYTE*)testData, STRING_LENGTH))) { lcdUpdateLine(LINE2,(char*)"Unused"); } else { scrollText((char*) testData, STRING_LENGTH); } while(getJoystickDirection() != CENTRED); while(getJoystickDirection() == CENTRED); while(getJoystickDirection() != CENTRED); // User decides whether to use CPU or DMA to write flash or to abort. command = lcdMenu(menuText,2); if(command == ABORT_MENU) { return; } // Uart communication lcdUpdate((char*)"Enter UART", (char*)"data"); printf((char*)"\n\nFlash Programming\n"); printf((char*)"Press a key\n\n"); uartGetkey (); // wait for a key to be pressed or the application to be ended if (stopApplication() ) return; else { inputBuffer[0] = U0DBUF; halWait(5); USART0_FLUSH(); inputBuffer[1] = U0DBUF; } // Printing the previously written data printf((char*)"\nLast written:\n"); if(unUsed) { printf((char*)"Unused\n"); } else { printf((char*)"%s\n",&testData); } //Aquiring new data: printf((char*)"\n\nType data to be written.\nWill be printed to the LCD next time."); printf((char*)"\n(ENTER: store in flash, ESC: abort)\n\n"); memset(inputBuffer,0,STRING_LENGTH); while(!stop) { c = getkey(); U0DBUF = c; switch (c){ case ENTER: inputBuffer[pointer] = 0; printf((char*)"\n\nTo write: %s\nENTER if OK.\n",inputBuffer); if(getkey() == ENTER) { // Write data to flash; stop = TRUE; write = TRUE; } else { // Reaquire data. printf((char*)"\nEnter text:\n"); pointer = 0; } break; case BACK_SPACE: // Erasing the last typed data. if (pointer > 0) { pointer--; inputBuffer[pointer] = ' '; } break; case ESC: // Abort Flash write. stop = TRUE; write = FALSE; break; default: // Add typed data to buffer. if (pointer < STRING_LENGTH-1) { inputBuffer[pointer] = c; pointer++; } break; } } INT_GLOBAL_ENABLE(INT_OFF); // Updating the flash if asked to. if(write == TRUE) { if(command == 0) { halFlashWritePage((BYTE*) &inputBuffer, buffer, PAGE_NUMBER); } else { writeFlashUsingDMA((BYTE*) &inputBuffer, STRING_LENGTH, PAGE_ADDRESS, TRUE); } printf((char*)"\nUpdated:"); printf((char*)" %s\n",(char __code*) (PAGE_NUMBER << 10)); lcdUpdateLine(LINE1,(char*)"Updated"); } else { printf((char*)"\nNot updated\n"); lcdUpdateLine(LINE1,(char*)"Not updated"); } lcdUpdateLine(LINE2,(char*)"LEFT to continue"); // Done haltApplicationWithLED(); return; }