Beispiel #1
0
void sd_mmc_spi_select_device(uint8_t slot, uint32_t clock, uint8_t bus_width,
		bool high_speed)
{
	UNUSED(bus_width);
	UNUSED(high_speed);
	sd_mmc_spi_err = SD_MMC_SPI_NO_ERR;

#ifdef SD_MMC_SPI_MAX_CLOCK
	if (clock > SD_MMC_SPI_MAX_CLOCK) {
		clock = SD_MMC_SPI_MAX_CLOCK;
	}
#endif
	while (STATUS_ERR_INVALID_ARG == spi_set_baudrate(&sd_mmc_master, clock)) {
		clock -= clock / 8;
	}
	spi_select_slave(&sd_mmc_master, &sd_mmc_spi_devices[slot], true);
}
Beispiel #2
0
/*!
 * This function configures the hardware SPI for the currrent client.
 * Lock must be taken
 *
 * @param        mod              the module number
 * @param        client_config    client hardware configuration.
 * @return       This function returns 0 if successful, -EPERM otherwise.
 */
static int spi_hard_config(module_nb_t mod, spi_config * client_config)
{
	int error = 0;
	error = spi_set_baudrate(mod, client_config->bit_rate);
	if (error < 0) {
		return error;
	}
	spi_set_transfer_length(mod, client_config->bit_count);
	error = spi_select_ss(mod, client_config->ss_asserted);
	if (error < 0) {
		return error;
	}

	if (client_config->master_mode == true) {
		spi_set_mode(mod, SPI_MASTER);
	} else {
		spi_set_mode(mod, SPI_SLAVE);
	}

	if (client_config->active_high_ss_polarity == true) {
		spi_set_ss_polarity(mod, SPI_SS_ACTIVE_HIGH);
	} else {
		spi_set_ss_polarity(mod, SPI_SS_ACTIVE_LOW);
	}

	if (client_config->ss_low_between_bursts == true) {
		spi_set_ss_waveform(mod, SPI_LOW_BTN_BURST);
	} else {
		spi_set_ss_waveform(mod, SPI_PULSE_BTN_BURST);
	}

	if (client_config->phase == true) {
		spi_set_phase(mod, SPI_PHASE_1);
	} else {
		spi_set_phase(mod, SPI_PHASE_0);
	}

	if (client_config->active_high_polarity == true) {
		spi_set_polarity(mod, SPI_POLARITY_ACTIVE_HIGH);
	} else {
		spi_set_polarity(mod, SPI_POLARITY_ACTIVE_LOW);
	}
	return 0;
}
Beispiel #3
0
void cph_deca_spi_set_baud(uint32_t baud) {
	spi_set_baudrate(&spi_master_instance, baud);
}
Beispiel #4
0
/**
 * Start SCI controller in UART mode
 * @param port number  
 * @param baud
 * @param polarity
 * @param phase
 * @param master or slave
 * @return none
 */
void 
spi_init(uint8 port, uint16 baud, uint8 polarity, uint8 phase, uint8 master_slave_selector) 
{
	/*
	 * Initialize all three UARTs for serial communications
	 */
	DEMO_SELECTOR_OFF;/*startup line for reference design*/
	   
  switch(port)
  {
    case SPI1_PORT:
      //Enable pins:
      
      /*SPI function*/      
      SPI1_MOSI_MISO_CLK_INIT;

      /*starting SPI clock*/
      SCGC2_SPI1 = 1;

      /*master-slave SPI*/
      if(master_slave_selector)
      {
         SPI1C1_MSTR = 1;//master
         SPI1_SS_GPIO_INIT;
      }
      else
      {
         SPI1C1_MSTR = 0;//slave
         SPI1_SS_INIT;
      }

    	/*baudrate and SPI baudrate*/
    	spi_set_baudrate(SPI1_PORT,baud);
    	
    	/*polarity*/
    	if(polarity)
    	{
    	  SPI1C1_CPOL = 1;
    	}
    	else
    	{
    	  SPI1C1_CPOL = 0;
    	}
    	    	 
    	/*phase*/
    	if(phase)
    	{
    	  SPI1C1_CPHA = 1;
    	}
    	else
    	{
    	  SPI1C1_CPHA = 0;
    	}

    	break;
    case SPI2_PORT:
      //Enable pins:
            
      /*SPI function*/      
      SPI2_MOSI_MISO_CLK_INIT;

      /*starting SPI clock*/
      SCGC2_SPI2 = 1;
 
       /*master-slave SPI*/
      if(master_slave_selector)
      {
         SPI2C1_MSTR = 1;//master
         SPI2_SS_GPIO_INIT;         
      }
      else
      {
         SPI2C1_MSTR = 0;//slave
         SPI2_SS_INIT;
      }

    	/*baudrate & start SPI controller*/
    	spi_set_baudrate(SPI2_PORT,baud);  

    	/*polarity*/
    	if(polarity)
    	{
    	  SPI2C1_CPOL = 1;
    	}
    	else
    	{
    	  SPI2C1_CPOL = 0;
    	}
    	    	 
    	/*phase*/
    	if(phase)
    	{
    	  SPI2C1_CPHA = 1;
    	}
    	else
    	{
    	  SPI2C1_CPHA = 0;
    	}
    	         
      break;
  }
}