/* ** Main function. */ int main(void) { volatile char originalData[260] = {0}; volatile char readFlash[260] = {0}; unsigned int retVal = 0; unsigned char choice; /* Initializes the UART Instance for serial communication. */ UARTStdioInit(); UARTPuts("Welcome to SPI EDMA application.\r\n", -1); UARTPuts("Here the SPI controller on the SoC communicates with", -1); UARTPuts(" the SPI Flash present on the SoM.\r\n\r\n", -1); /* Initializes the EDMA3 Instance. */ EDMA3Initialize(); /* Initializes the SPI1 Instance. */ SPIInitialize(); /* Request EDMA3CC for Tx and Rx channels for SPI1. */ RequestEDMA3Channels(); /* Enable SPI communication. */ SPIEnable(SOC_SPI_1_REGS); /* 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(); } WriteEnable(); /* Program a specified Page of the SPI Flash. */ FlashPageProgram(originalData); /* Read the contents of the page that was previously written to. */ ReadFromFlash(readFlash); /* Verify whether the written and the read contents are equal. */ retVal = verifyData(&originalData[4], &readFlash[4], 256); if(TRUE == retVal) { UARTPuts("\r\nThe data in the Flash and the one written ", -1); UARTPuts("to it are equal.\r\n", -1); } else { UARTPuts("\r\n\r\nThe data in the Flash and the one written to it", -1); UARTPuts(" are not equal.\r\n", -1); } while(1); }
void static InitializeAsMaster() { SPCR = 0; AsMaster(); SPIEnable(); }
/*! \brief open spi communication port to be used for communicating with a SimpleLink device Given an interface name and option flags, this function opens the spi communication port and creates a file descriptor. This file descriptor can be used afterwards to read and write data from and to this specific spi channel. The SPI speed, clock polarity, clock phase, chip select and all other attributes are all set to hardcoded values in this function. \param ifName - points to the interface name/path. The interface name is an optional attributes that the simple link driver receives on opening the device. in systems that the spi channel is not implemented as part of the os device drivers, this parameter could be NULL. \param flags - option flags \return upon successful completion, the function shall open the spi channel and return a non-negative integer representing the file descriptor. Otherwise, -1 shall be returned \sa spi_Close , spi_Read , spi_Write \note \warning */ Fd_t spi_Open(char *ifName, unsigned long flags) { unsigned long ulBase; //NWP master interface ulBase = LSPI_BASE; //Enable MCSPIA2 PRCMPeripheralClkEnable(PRCM_LSPI,PRCM_RUN_MODE_CLK|PRCM_SLP_MODE_CLK); //Disable Chip Select SPICSDisable(ulBase); //Disable SPI Channel SPIDisable(ulBase); // Reset SPI SPIReset(ulBase); // // Configure SPI interface // SPIConfigSetExpClk(ulBase,PRCMPeripheralClockGet(PRCM_LSPI), SPI_IF_BIT_RATE,SPI_MODE_MASTER,SPI_SUB_MODE_0, (SPI_SW_CTRL_CS | SPI_4PIN_MODE | SPI_TURBO_OFF | SPI_CS_ACTIVEHIGH | SPI_WL_32)); if(PRCMPeripheralStatusGet(PRCM_UDMA)) { g_ucDMAEnabled = (HWREG(UDMA_BASE + UDMA_O_CTLBASE) != 0x0) ? 1 : 0; } else { g_ucDMAEnabled = 0; } #ifdef SL_CPU_MODE g_ucDMAEnabled = 0; #endif if(g_ucDMAEnabled) { memset(g_ucDinDout,0xFF,sizeof(g_ucDinDout)); //g_ucDout[0]=0xFF; //Simplelink_UDMAInit(); // Set DMA channel cc_UDMAChannelSelect(UDMA_CH12_LSPI_RX); cc_UDMAChannelSelect(UDMA_CH13_LSPI_TX); SPIFIFOEnable(ulBase,SPI_RX_FIFO); SPIFIFOEnable(ulBase,SPI_TX_FIFO); SPIDmaEnable(ulBase,SPI_RX_DMA); SPIDmaEnable(ulBase,SPI_TX_DMA); SPIFIFOLevelSet(ulBase,1,1); #if defined(SL_PLATFORM_MULTI_THREADED) osi_InterruptRegister(INT_LSPI, (P_OSI_INTR_ENTRY)DmaSpiSwIntHandler,INT_PRIORITY_LVL_1); SPIIntEnable(ulBase,SPI_INT_EOW); osi_MsgQCreate(&DMAMsgQ,"DMAQueue",sizeof(int),1); #else IntRegister(INT_LSPI,(void(*)(void))DmaSpiSwIntHandler); IntPrioritySet(INT_LSPI, INT_PRIORITY_LVL_1); IntEnable(INT_LSPI); SPIIntEnable(ulBase,SPI_INT_EOW); g_cDummy = 0x0; #endif } SPIEnable(ulBase); g_SpiFd = 1; return g_SpiFd; }