OpenCores
URL https://opencores.org/ocsvn/neorv32/neorv32/trunk

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [sw/] [lib/] [source/] [neorv32_spi.c] - Diff between revs 23 and 36

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 23 Rev 36
Line 64... Line 64...
/**********************************************************************//**
/**********************************************************************//**
 * Enable and configure SPI controller. The SPI control register bits are listed in #NEORV32_SPI_CT_enum.
 * Enable and configure SPI controller. The SPI control register bits are listed in #NEORV32_SPI_CT_enum.
 *
 *
 * @param[in] prsc Clock prescaler select (0..7).  See #NEORV32_CLOCK_PRSC_enum.
 * @param[in] prsc Clock prescaler select (0..7).  See #NEORV32_CLOCK_PRSC_enum.
 * @param[in] clk_polarity Idle clock polarity (0, 1).
 * @param[in] clk_polarity Idle clock polarity (0, 1).
 * @param[in] dir Shift direction (0: MSB first, 1: LSB first).
 
 * @param[in] data_size Data transfer size (0: 8-bit, 1: 16-bit, 2: 24-bit, 3: 32-bit).
 * @param[in] data_size Data transfer size (0: 8-bit, 1: 16-bit, 2: 24-bit, 3: 32-bit).
 * @param[in] irq_en Enable transfer-done interrupt when 1.
 * @param[in] irq_en Enable transfer-done interrupt when 1.
 **************************************************************************/
 **************************************************************************/
void neorv32_spi_setup(uint8_t prsc, uint8_t clk_polarity, uint8_t dir, uint8_t data_size, uint8_t irq_en) {
void neorv32_spi_setup(uint8_t prsc, uint8_t clk_polarity, uint8_t data_size, uint8_t irq_en) {
 
 
  SPI_CT = 0; // reset
  SPI_CT = 0; // reset
 
 
  uint32_t ct_enable = 1;
  uint32_t ct_enable = 1;
  ct_enable = ct_enable << SPI_CT_EN;
  ct_enable = ct_enable << SPI_CT_EN;
Line 81... Line 80...
  ct_prsc = ct_prsc << SPI_CT_PRSC0;
  ct_prsc = ct_prsc << SPI_CT_PRSC0;
 
 
  uint32_t ct_polarity = (uint32_t)(clk_polarity & 0x01);
  uint32_t ct_polarity = (uint32_t)(clk_polarity & 0x01);
  ct_polarity = ct_polarity << SPI_CT_CPHA;
  ct_polarity = ct_polarity << SPI_CT_CPHA;
 
 
  uint32_t ct_dir = (uint32_t)(dir & 0x01);
 
  ct_dir = ct_dir << SPI_CT_DIR;
 
 
 
  uint32_t ct_size = (uint32_t)(data_size & 0x03);
  uint32_t ct_size = (uint32_t)(data_size & 0x03);
  ct_size = ct_size << SPI_CT_SIZE0;
  ct_size = ct_size << SPI_CT_SIZE0;
 
 
  uint32_t ct_irq = (uint32_t)(irq_en & 0x01);
  uint32_t ct_irq = (uint32_t)(irq_en & 0x01);
  ct_irq = ct_irq << SPI_CT_IRQ_EN;
  ct_irq = ct_irq << SPI_CT_IRQ_EN;
 
 
  SPI_CT = ct_enable | ct_prsc | ct_polarity | ct_dir | ct_size | ct_irq;
  SPI_CT = ct_enable | ct_prsc | ct_polarity | ct_size | ct_irq;
}
}
 
 
 
 
/**********************************************************************//**
/**********************************************************************//**
 * Disable and SPI controller.
 * Disable and SPI controller.
Line 136... Line 132...
 
 
 
 
/**********************************************************************//**
/**********************************************************************//**
 * Initiate SPI transfer.
 * Initiate SPI transfer.
 *
 *
 
 * @warning The SPI always sends MSB first.
 
 *
 * @note This function is blocking.
 * @note This function is blocking.
 *
 *
 * @param tx_data Transmit data (8/16/24/32-bit, LSB-aligned).
 * @param tx_data Transmit data (8/16/24/32-bit, LSB-aligned).
 * @return Receive data (8/16/24/32-bit, LSB-aligned).
 * @return Receive data (8/16/24/32-bit, LSB-aligned).
 **************************************************************************/
 **************************************************************************/

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.