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

Subversion Repositories neorv32

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

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

Rev 64 Rev 65
Line 63... Line 63...
 
 
/**********************************************************************//**
/**********************************************************************//**
 * Enable and configure SPI controller. The SPI control register bits are listed in #NEORV32_SPI_CTRL_enum.
 * Enable and configure SPI controller. The SPI control register bits are listed in #NEORV32_SPI_CTRL_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_phase Clock phase (0=sample on rising edge, 1=sample on falling edge).
 
 * @param[in] clk_polarity Clock polarity (when idle).
 * @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).
 **************************************************************************/
 **************************************************************************/
void neorv32_spi_setup(uint8_t prsc, uint8_t clk_polarity, uint8_t data_size) {
void neorv32_spi_setup(uint8_t prsc, uint8_t clk_phase, uint8_t clk_polarity, uint8_t data_size) {
 
 
  NEORV32_SPI.CTRL = 0; // reset
  NEORV32_SPI.CTRL = 0; // reset
 
 
  uint32_t ct_enable = 1;
  uint32_t ct_enable = 1;
  ct_enable = ct_enable << SPI_CTRL_EN;
  ct_enable = ct_enable << SPI_CTRL_EN;
 
 
  uint32_t ct_prsc = (uint32_t)(prsc & 0x07);
  uint32_t ct_prsc = (uint32_t)(prsc & 0x07);
  ct_prsc = ct_prsc << SPI_CTRL_PRSC0;
  ct_prsc = ct_prsc << SPI_CTRL_PRSC0;
 
 
 
  uint32_t ct_phase = (uint32_t)(clk_phase & 0x01);
 
  ct_phase = ct_phase << SPI_CTRL_CPHA;
 
 
  uint32_t ct_polarity = (uint32_t)(clk_polarity & 0x01);
  uint32_t ct_polarity = (uint32_t)(clk_polarity & 0x01);
  ct_polarity = ct_polarity << SPI_CTRL_CPHA;
  ct_polarity = ct_polarity << SPI_CTRL_CPOL;
 
 
  uint32_t ct_size = (uint32_t)(data_size & 0x03);
  uint32_t ct_size = (uint32_t)(data_size & 0x03);
  ct_size = ct_size << SPI_CTRL_SIZE0;
  ct_size = ct_size << SPI_CTRL_SIZE0;
 
 
  NEORV32_SPI.CTRL = ct_enable | ct_prsc | ct_polarity | ct_size;
  NEORV32_SPI.CTRL = ct_enable | ct_prsc | ct_phase | ct_polarity | ct_size;
}
}
 
 
 
 
/**********************************************************************//**
/**********************************************************************//**
 * Disable SPI controller.
 * Disable SPI controller.
Line 156... Line 160...
 
 
 
 
/**********************************************************************//**
/**********************************************************************//**
 * Check if SPI transceiver is busy.
 * Check if SPI transceiver is busy.
 *
 *
 * @note This function is blocking.
 
 *
 
 * @return 0 if idle, 1 if busy
 * @return 0 if idle, 1 if busy
 **************************************************************************/
 **************************************************************************/
int neorv32_spi_busy(void) {
int neorv32_spi_busy(void) {
 
 
  if ((NEORV32_SPI.CTRL & (1<<SPI_CTRL_BUSY)) != 0) {
  if ((NEORV32_SPI.CTRL & (1<<SPI_CTRL_BUSY)) != 0) {
    return 1;
    return 1;
  }
  }
 
  else {
  return 0;
  return 0;
}
}
 
}
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

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