// ***************************************************************************** // @fn spi_init // @brief Initialize SPI // @param none // @return none // ***************************************************************************** void spi_init(void) { setupCmu(); setupSpi(); #ifdef SPI_USE_DMA setupDma(); #endif DPRINT("SPI Init."); }
/**************************************************************************//** * @brief Main function * This exmaple sets up the TIMER to trigger the ADC through PRS at a set * interval. The ADC then sets a DMA request and the DMA fetches each sample * until the a set number of samples have been received. *****************************************************************************/ int main(void) { /* Initialize chip */ CHIP_Init(); /* Configuring clocks in the Clock Management Unit (CMU) */ setupCmu(); /* Configure DMA transfer from ADC to RAM */ setupDma(); /* Configure ADC Sampling and TIMER trigger through PRS. Start TIMER as well */ setupAdc(); /* Enter EM1 while DMA transfer is active to save power. Note that * interrupts are disabled to prevent the ISR from being triggered * after checking the transferActive flag, but before entering * sleep. If this were to happen, there would be no interrupt to wake * the core again and the MCU would be stuck in EM1. While the * core is in sleep, pending interrupts will still wake up the * core and the ISR will be triggered after interrupts are enabled * again. */ while(1) { INT_Disable(); if ( transferActive ) { EMU_EnterEM1(); } INT_Enable(); /* Exit the loop if transfer has completed */ if ( !transferActive ) { break; } } /* Cleaning up after DMA transfers */ DMA_Reset(); /* Done */ while (1); }
char *FpgaDev::allocate_mem(size_t memsz) { int memfd = portalAlloc(memsz, 1); if (memfd < 0) return 0; char *buf = (char *)portalMmap(memfd, memsz); if (buf == MAP_FAILED) { close(memfd); return 0; } fprintf(stderr, "FpgaDev::allocate_mem memsz=%lx memfd=%d buf=%p\n", memsz, memfd, buf); if (!mainMemFd) { setupDma(memfd); mainMemFd = memfd; mainMemBuf = buf; fprintf(stderr, "FpgaDev::allocate_mem mainMemFd=%d\n", memfd); } return buf; }
/**************************************************************************//** * @brief Main function * This example sets up the DMA to transfer outbound and incoming data from the * SPI (USART1) to/from the source/destination buffers. Three tests are done: * 1) Transmit data (string) without reading received data * 2) Transmit data (string) and transfer received data to RAM buffer * 3) Transmit dummy data and transfer received data to RAM buffer *****************************************************************************/ int main(void) { /* Initialize chip */ CHIP_Init(); /* Configuring clocks in the Clock Management Unit (CMU) */ setupCmu(); /* Configura USART for SPI */ setupSpi(); /* Configure DMA transfer from RAM to SPI using ping-pong */ setupDma(); /* Send data to slave, no data reception */ spiDmaTransfer((uint8_t*) spiTxData, NULL, SPI_TRANSFER_SIZE); /* Sleep until transfer is done */ sleepUntilTransferDone(); /* Send data to slave and save received data in buffer */ spiDmaTransfer((uint8_t*) spiTxData, (uint8_t*) spiRxData1, SPI_TRANSFER_SIZE); /* Sleep until transfer is done */ sleepUntilTransferDone(); /* Send dummy data to slave and save received data in buffer */ spiDmaTransfer(NULL, (uint8_t*) spiRxData2, SPI_TRANSFER_SIZE); /* Sleep until transfer is done */ sleepUntilTransferDone(); /* Send dummy data to slave and save received data in buffer */ spiDmaTransfer(NULL, (uint8_t*) spiRxData2, SPI_TRANSFER_SIZE); /* Sleep until transfer is done */ sleepUntilTransferDone(); /* Send data to slave, no data reception */ spiDmaTransfer((uint8_t*) spiTxData, NULL, SPI_TRANSFER_SIZE); /* Sleep until transfer is done */ sleepUntilTransferDone(); /* Send data to slave and save received data in buffer */ spiDmaTransfer((uint8_t*) spiTxData, (uint8_t*) spiRxData1, SPI_TRANSFER_SIZE); /* Sleep until transfer is done */ sleepUntilTransferDone(); /* Send dummy data to slave and save received data in buffer */ spiDmaTransfer(NULL, (uint8_t*) spiRxData2, SPI_TRANSFER_SIZE); /* Sleep until transfer is done */ sleepUntilTransferDone(); /* Cleaning up after DMA transfers */ DMA_Reset(); /* Done */ while (1); }