void SPIDrvTest(void) { platform_spi_config_t cfg; s_segs[0].length = 1024; s_segs[0].tx_buffer = (const void*) 0; s_segs[0].rx_buffer = s_spiTestbuf; s_segs[1].length = 1025; s_segs[1].tx_buffer = (const void*) 0x1000; s_segs[1].rx_buffer = s_spiTestbuf; s_segs[2].length = sizeof(s_spiTestbuf); s_segs[2].tx_buffer = (const void*) 0x4000; s_segs[2].rx_buffer = s_spiTestbuf; cfg.speed = mico_spi_flash.speed; cfg.chip_select = platform_gpio_pins + mico_spi_flash.chip_select; cfg.mode = mico_spi_flash.mode; cfg.bits = mico_spi_flash.bits; // >>> { platform_spi_driver_t *pDrv = &platform_spi_drivers[MICO_SPI_0]; platform_spi_t const *pHw = pDrv->peripheral; platform_spi_init(pDrv, pHw, &cfg); platform_spi_deinit(pDrv); platform_spi_init(pDrv, pHw, &cfg); g_pSPI0->CFG |= 1UL << 7; platform_spi_transfer(pDrv, &cfg, s_segs + 0, 3); } }
OSStatus MicoSpiTransfer( const mico_spi_device_t* spi, const mico_spi_message_segment_t* segments, uint16_t number_of_segments ) { platform_spi_config_t config; OSStatus err = kNoErr; if ( spi->port >= MICO_SPI_NONE ) return kUnsupportedErr; #ifdef MICO_WIFI_SHARE_SPI_BUS if( platform_spi_peripherals[spi->port].port == wifi_spi.port ) { return platform_wlan_spi_transfer( &platform_gpio_pins[spi->chip_select], segments, number_of_segments ); } #endif if( platform_spi_drivers[spi->port].spi_mutex == NULL) mico_rtos_init_mutex( &platform_spi_drivers[spi->port].spi_mutex ); config.chip_select = &platform_gpio_pins[spi->chip_select]; config.speed = spi->speed; config.mode = spi->mode; config.bits = spi->bits; mico_rtos_lock_mutex( &platform_spi_drivers[spi->port].spi_mutex ); err = platform_spi_init( &platform_spi_drivers[spi->port], &platform_spi_peripherals[spi->port], &config ); err = platform_spi_transfer( &platform_spi_drivers[spi->port], &config, segments, number_of_segments ); mico_rtos_unlock_mutex( &platform_spi_drivers[spi->port].spi_mutex ); return err; }
wwd_result_t host_platform_spi_transfer( wwd_bus_transfer_direction_t direction, uint8_t* buffer, uint16_t buffer_length ) { const platform_spi_t* wlan_spi_base = &platform_spi_peripherals[WWD_SPI]; wiced_result_t result = WWD_SUCCESS; platform_spi_message_segment_t segment; platform_spi_init( wlan_spi_base, &wlan_spi_config ); segment.length = buffer_length; segment.tx_buffer = buffer; segment.rx_buffer = direction == BUS_WRITE ? NULL : buffer; result = platform_spi_transfer( wlan_spi_base, &wlan_spi_config, &segment, 1); platform_spi_deinit( wlan_spi_base ); return result; }
OSStatus MicoSpiInitialize( const mico_spi_device_t* spi ) { platform_spi_config_t config; OSStatus err = kNoErr; if ( spi->port >= MICO_SPI_NONE ) return kUnsupportedErr; if( platform_spi_drivers[spi->port].spi_mutex == NULL) mico_rtos_init_mutex( &platform_spi_drivers[spi->port].spi_mutex ); config.chip_select = &platform_gpio_pins[spi->chip_select]; config.speed = spi->speed; config.mode = spi->mode; config.bits = spi->bits; mico_rtos_lock_mutex( &platform_spi_drivers[spi->port].spi_mutex ); err = platform_spi_init( &platform_spi_drivers[spi->port], &platform_spi_peripherals[spi->port], &config ); mico_rtos_unlock_mutex( &platform_spi_drivers[spi->port].spi_mutex ); return err; }