/* ** Main Function. */ int main(void) { unsigned char choice = 0; /* Enable the clocks for McSPI0 module.*/ McSPI0ModuleClkConfig(); /* Perform Pin-Muxing for SPI0 Instance.*/ McSPIPinMuxSetup(0); /* Perform Pin-Muxing for CS0 of SPI0 Instance.*/ McSPI0CSPinMuxSetup(MCSPI_CH_NUM); /* Initialize the UART utility functions.*/ UARTStdioInit(); /* Enable IRQ in CPSR.*/ IntMasterIRQEnable(); UARTPuts("Here the McSPI controller on the SOC communicates with ",-1); UARTPuts("the McSPI Flash.\r\n\r\n",-1); /* Initialize the EDMA3 instance.*/ EDMA3Initialize(); /* Request EDMA3CC for Tx and Rx channels for SPI0. */ RequestEDMA3Channels(); /* Set up the McSPI instance.*/ McSPISetUp(); /* Enable the SPI Flash for writing to it. */ WriteEnable(); UARTPuts("Do you want to erase a sector of the flash before writing to it ?.", -1); UARTPuts("\r\nInput y(Y)/n(N) to proceed.\r\n", -1); choice = UARTGetc(); UARTPutc(choice); if(('y' == choice) || ('Y' == choice)) { /* Erasing the specified sector of SPI Flash. */ FlashSectorErase(); } /* Enable the SPI Flash for writing to it. */ WriteEnable(); /* Write data of 1 page size into a page of Flash.*/ FlashPageProgram(); /* Read data of 1 page size from a page of flash.*/ ReadFromFlash(); /* Verify the data written to and read from Flash are same or not.*/ VerifyData(); while(1); }
/*#####################################################*/ bool _mcspi_open(Mcspi_t *McspiStruct) { if(McspiStruct->BuffSize) { switch(McspiStruct->McspiNr) { case 0: McspiStruct->BaseAddr = SOC_SPI_0_REGS; Mcspi_Int_Service.Mcspi0 = McspiStruct; break; case 1: McspiStruct->BaseAddr = SOC_SPI_1_REGS; Mcspi_Int_Service.Mcspi1 = McspiStruct; break; } McspiStruct->Buff = (unsigned char*)malloc(McspiStruct->BuffSize); if(!McspiStruct->Buff) return false; McspiStruct->flag = 1; McSPIModuleClkConfig(McspiStruct->McspiNr); McSPIPinMux(McspiStruct); McSPISetUp(McspiStruct); McSPIAintcConfigure(McspiStruct->McspiNr); return true; } return false; }
/****************************************************************************** ** INTERNAL FUNCTION DEFINITIONS ******************************************************************************/ int main(void) { volatile unsigned int count = 0x0FFFu; unsigned int retVal = FALSE; unsigned char choice = 0; /* Enable the clocks for McSPI0 module.*/ McSPI0ModuleClkConfig(); /* Perform Pin-Muxing for SPI0 Instance */ McSPIPinMuxSetup(0); /* Perform Pin-Muxing for CS0 of SPI0 Instance */ McSPI0CSPinMuxSetup(chNum); /* Initialize the UART utility functions */ UARTStdioInit(); UARTPuts("Here the McSPI controller on the SoC communicates with", -1); UARTPuts(" the SPI Flash.\r\n\r\n", -1); /* Enable IRQ in CPSR.*/ IntMasterIRQEnable(); /* Map McSPI Interrupts to AINTC */ McSPI0AintcConfigure(); /* Do the necessary set up configurations for McSPI.*/ McSPISetUp(); /* Pass the write enable command to flash.*/ WriteEnable(); /* Wait until write enable command is successfully written to flash.*/ while(FALSE == retVal) { retVal = IsWriteSuccess(); } retVal = FALSE; UARTPuts("Do you want to erase a sector of the flash before ", -1); UARTPuts("writing to it ?.", -1); UARTPuts("\r\nInput y(Y)/n(N) to proceed.\r\n", -1); choice = UARTGetc(); UARTPutc(choice); if(('Y' == choice) || ('y' == choice)) { /* Erase a sector of flash.*/ SectorErase(); } /* Pass the write enable command to flash.*/ WriteEnable(); /* Wait until write enable command is successfully written to flash.*/ while(FALSE == retVal) { retVal = IsWriteSuccess(); } /* Write data of 1 page size to flash.*/ WriteToFlash(); while(count--); count = 0x0FFFu; /* Read data of 1 page size from flash.*/ ReadFromFlash(); while(count--); /* Verify the data written to and read from flash are same or not.*/ VerifyData(); while(1); }