Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds temporary change to incorporate RS9116 UULP wake up fix #247

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 136 additions & 0 deletions matter/si91x/support/src/rsi_spi_iface_init.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*******************************************************************************
* @file rsi_spi_iface_init.c
* @brief
*******************************************************************************
* # License
* <b>Copyright 2020 Silicon Laboratories Inc. www.silabs.com</b>
*******************************************************************************
*
* The licensor of this software is Silicon Laboratories Inc. Your use of this
* software is governed by the terms of Silicon Labs Master Software License
* Agreement (MSLA) available at
* www.silabs.com/about-us/legal/master-software-license-agreement. This
* software is distributed to you in Source Code format and is governed by the
* sections of the MSLA applicable to Source Code.
*
******************************************************************************/
/**
* @file rsi_spi_iface_init.c
* @version 0.1
* @date 15 Aug 2015
*
*
*
* @brief SPI INIT: Functions to initiaize the SPI hardware interface in the module
* Description
* Contains the SPI Initialization function.
* Enable the SPI interface on the Wi-Fi chip.
* Only run once - during startup, after power-on, or reset
*
*
*/

/*
Includes
*/
#include "rsi_driver.h"
#ifdef RSI_SPI_INTERFACE

/*
Global Variables
*/
/** @addtogroup DRIVER2
* @{
*/
/*=============================================*/
/**
* @brief Initialize the SPI secondary device interface of the module
* @param[in] void
* @return 0 - Success \n
* @return Non-Zero value - Failure \n
*/

int16_t rsi_spi_iface_init(void)
{
SL_PRINTF(SL_SPI_IFACE_INIT_ENTRY, DRIVER, LOG_INFO);

uint8_t txCmd[4];
uint8_t localBuf[4] = { 0 };
int16_t retval = 0;
uint16_t timeout;

// 10ms timeout on command, nothing magic, just a reasonable number
timeout = 100;

// Init the timer counter
RSI_RESET_TIMER1;
while (1) {
if (RSI_INC_TIMER_1 > timeout) {
retval = RSI_ERROR_SPI_TIMEOUT;
break;
}

txCmd[0] = (RSI_RS9116_INIT_CMD & 0xFF);
txCmd[1] = ((RSI_RS9116_INIT_CMD >> 8) & 0xFF);
txCmd[2] = ((RSI_RS9116_INIT_CMD >> 16) & 0xFF);
txCmd[3] = ((RSI_RS9116_INIT_CMD >> 24) & 0xFF);

retval = rsi_spi_transfer(txCmd, localBuf, sizeof(localBuf), RSI_MODE_8BIT);
// Retval = rsi_spi_send(txCmd, 2, localBuf, RSI_MODE_8BIT);
if (localBuf[3] == RSI_SPI_SUCCESS) {
retval = RSI_SUCCESS;
break;
} else {
retval = RSI_ERROR_SPI_BUSY;
}
}
SL_PRINTF(SL_SPI_IFACE_INIT_EXIT, DRIVER, LOG_INFO, "retval: %d", retval);
return retval;
}

/*=============================================*/
/**
* @brief Initialize the SPI secondary device interface of the module on ULP wakeup
* @param[in] void
* @return 0 - Success \n
* @return Non-Zero value - Failure \n
*/
int16_t rsi_ulp_wakeup_init(void)
{
uint8_t txCmd[4];
uint8_t rxbuff[2];
int16_t retval = RSI_SUCCESS;
uint16_t timeout;

// 10ms timeout on command, nothing magic, just a reasonable number
timeout = 10;

// Init the timer counter
RSI_RESET_TIMER1;
while (1) {
if (RSI_INC_TIMER_1 > timeout) {
retval = RSI_ERROR_SPI_TIMEOUT;
break;
}

txCmd[0] = (RSI_RS9116_INIT_CMD & 0xFF);
txCmd[1] = ((RSI_RS9116_INIT_CMD >> 8) & 0xFF);
txCmd[2] = ((RSI_RS9116_INIT_CMD >> 16) & 0xFF);
txCmd[3] = ((RSI_RS9116_INIT_CMD >> 24) & 0xFF);

rsi_spi_transfer(txCmd, rxbuff, 2, RSI_MODE_8BIT);
if (rxbuff[1] == RSI_SPI_FAIL) {
break;
} else if (rxbuff[1] == 0x00) {
rsi_spi_transfer(&txCmd[2], rxbuff, 2, RSI_MODE_8BIT);
if (rxbuff[1] == RSI_SPI_SUCCESS) {
break;
}
} else {
retval = RSI_ERROR_SPI_BUSY;
}
}
return retval;
}
#endif
/** @} */
Loading