예제 #1
0
/**
 * @brief   Configures and activates the SPI peripheral.
 *
 * @param[in] spip      pointer to the @p SPIDriver object
 *
 * @notapi
 */
void spi_lld_start(SPIDriver *spip) {

  /* Configures the peripheral.*/

  if (spip->state == SPI_STOP) {
  /* Execute a software reset of the SPI twice */
    spip->spi->SPI_CR = SPI_CR_SWRST;
    spip->spi->SPI_CR = SPI_CR_SWRST;

#if SAMA_SPI_USE_SPI0
    if (&SPID0 == spip) {
      spip->dmarx = dmaChannelAllocate(SAMA_SPI_SPI0_IRQ_PRIORITY,
                                       (sama_dmaisr_t)spi_lld_serve_rx_interrupt,
                                       (void *)spip);

      spip->dmatx = dmaChannelAllocate(SAMA_SPI_SPI0_IRQ_PRIORITY,
                                       (sama_dmaisr_t)spi_lld_serve_tx_interrupt,
                                       (void *)spip);

    /* Enable SPI0 clock */
      pmcEnableSPI0();

    }
#endif /* SAMA_SPI_USE_SPI0 */
#if SAMA_SPI_USE_SPI1
    if (&SPID1 == spip) {
      spip->dmarx = dmaChannelAllocate(SAMA_SPI_SPI1_IRQ_PRIORITY,
                                       (sama_dmaisr_t)spi_lld_serve_rx_interrupt,
                                       (void *)spip);

      spip->dmatx = dmaChannelAllocate(SAMA_SPI_SPI1_IRQ_PRIORITY,
                                       (sama_dmaisr_t)spi_lld_serve_tx_interrupt,
                                       (void *)spip);
    /* Enable SPI1 clock */
      pmcEnableSPI1();

    }
#endif /* SAMA_SPI_USE_SPI1 */
  }

  /* Disable write protection */
  spiDisableWP(spip->spi);
  /* SPI configuration */
  spip->spi->SPI_MR = spip->config->mr;
  spip->spi->SPI_CSR[spip->config->npcs] = spip->config->csr;
  /* Enable SPI */
  spip->spi->SPI_CR |= SPI_CR_SPIEN;
  /* Enable write protection.  */
  spiEnableWP(spip->spi);
}
예제 #2
0
void samaCryptoDriverStart(CRYDriver *cryp) {


	if (cryp->config->transfer_mode == TRANSFER_DMA)
	{
#if defined(SAMA_DMA_REQUIRED)
		cryp->dmarx = dmaChannelAllocate(SAMA_CRY_CRYD1_DMA_IRQ_PRIORITY,
				(sama_dmaisr_t) crypto_lld_serve_read_interrupt, (void *) cryp);
		osalDbgAssert(cryp->dmarx != NULL, "no channel allocated");

		cryp->dmatx = dmaChannelAllocate(SAMA_CRY_CRYD1_DMA_IRQ_PRIORITY,
				(sama_dmaisr_t) crypto_lld_serve_write_interrupt, (void *) cryp);
		osalDbgAssert(cryp->dmatx != NULL, "no channel allocated");
#endif
	}

}
예제 #3
0
파일: dac_lld.c 프로젝트: ISMER/ChibiOS-RT
/**
 * @brief   Configures and activates the DAC peripheral.
 *
 * @param[in] dacp      pointer to the @p DACDriver object
 *
 * @notapi
 */
void dac_lld_start(DACDriver *dacp) {

  if (dacp->state == DAC_STOP) {

    /* Enable DAC */
    LPC_PINCON->PINSEL1 |= (2UL << 20);   /* Set AOUT P0.26 pin.*/

    LPC_DAC->CR = 0;
    LPC_DAC->CTRL = 0;
    LPC_DAC->CNTVAL = LPC17xx_PCLK/dacp->config->frequency;

    dmaChannelAllocate(LPC17xx_DAC_DMA_CHANNEL, \
                     (lpc17xx_dmaisr_t)dac_serve_dma_interrupt, \
                     (void *)dacp);
  }
}
예제 #4
0
파일: main.c 프로젝트: ISMER/ChibiOS-RT
/*
 * Application entry point.
 */
int main(void) {
  uint32_t i;
  /*
   * System initializations.
   * - HAL initialization, this also initializes the configured device drivers
   *   and performs the board-specific initializations.
   * - Kernel initialization, the main() function becomes a thread and the
   *   RTOS is active.
   */
  halInit();
  chSysInit();

  /*
   * Creates the blinker thread.
   */
  chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);

  /*
   * Activates the SD driver 1.
   */
  sdStart(&SD4, NULL);          /* Default is 38400-8-N-1.*/

  chprintf(chp, "Data before dma transfer.\r\n");
  chprintf(chp, "source \t destination\r\n");
  for (i = 0; i < MEM_SIZE; i++) {
     mem_src[i] = i;
     mem_dst[i] = 0;
     chprintf(chp, "%x \t %x\r\n", mem_src[i], mem_dst[i]);
  }

  dmaChannelAllocate(DMA_CHANNEL0, &dma_mem_callback, NULL);
  dmaChannelSrcAddr(DMA_CHANNEL0, &mem_src[0]);
  dmaChannelDstAddr(DMA_CHANNEL0, &mem_dst[0]);
  dmaChannelControl(DMA_CHANNEL0, DMA_CTRL_TRANSFER_SIZE(MEM_SIZE)  |
                                  DMA_CTRL_SRC_BSIZE_16             |
                                  DMA_CTRL_DST_BSIZE_16             |
                                  DMA_CTRL_SRC_WIDTH_WORD           |
                                  DMA_CTRL_DST_WIDTH_WORD           |
                                  DMA_CTRL_SRC_AHBM0                |
                                  DMA_CTRL_DST_AHBM0                |
                                  DMA_CTRL_SRC_INC                  |
                                  DMA_CTRL_DST_INC                  |
                                  DMA_CTRL_INT);

  dmaChannelConfig(DMA_CHANNEL0,  DMA_CFG_CH_ENABLE   |
                                  DMA_CFG_FCTRL_M2M   |
                                  DMA_CFG_IE          |
                                  DMA_CFG_ITC);

  chThdSleepMilliseconds(5000);
  chprintf(chp, "Data after dma transfer.\r\n");
  chprintf(chp, "source \t destination\r\n");
  for (i = 0; i < MEM_SIZE; i++) {
    chprintf(chp, "%x \t %x\r\n", mem_src[i], mem_dst[i]);
  }

  for (i = 0; i < MEM_SIZE; i++)
    if (mem_src[i] != mem_dst[i])
      break;

  if (i == MEM_SIZE)
    chprintf(chp, "Data transfer ok.\r\n");
  else
    chprintf(chp, "Error.\r\n");

  while (TRUE) {

  chThdSleepMilliseconds(1000);

  }
}