Enable Milli Second Wakeup Source -// Default: 0 -#define ENABLE_MSEC 0 - //Alarm Time (in milliseconds) // Default: 5000 #define ALARM_TIME_MSEC 5000 @@ -78,16 +74,12 @@ extern "C" { #define ENABLE_NPSS_GPIO_3 0 //
Byte-wise Swapping Read -// Default: 1 -#define SL_GSPI_SWAP_READ_DATA 1 +// Default: 0 +#define SL_GSPI_SWAP_READ_DATA 0 //Byte-wise Swapping Write // Default: 0 diff --git a/components/device/silabs/si91x/mcu/drivers/unified_api/config/sl_si91x_sio_config.h b/components/device/silabs/si91x/mcu/drivers/unified_api/config/sl_si91x_sio_config.h deleted file mode 100644 index f8f37cb64..000000000 --- a/components/device/silabs/si91x/mcu/drivers/unified_api/config/sl_si91x_sio_config.h +++ /dev/null @@ -1,767 +0,0 @@ -/***************************************************************************/ /** - * @file sl_si91x_sio_config.h - * @brief SL SIO Config. - ******************************************************************************* - * # License - * Copyright 2023 Silicon Laboratories Inc. www.silabs.com - ******************************************************************************* - * - * SPDX-License-Identifier: Zlib - * - * The licensor of this software is Silicon Laboratories Inc. - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - * - ******************************************************************************/ - -#ifndef SL_SIO_CONFIG_H -#define SL_SIO_CONFIG_H - -#include "sl_si91x_sio.h" -#include "sl_sio_board.h" - -// <<< Use Configuration Wizard in Context Menu >>> -#ifdef __cplusplus -extern "C" { -#endif - -//SIO UC Configuration -// Enable: Peripheral configuration is taken straight from the configuration set in the universal configuration (UC). -// Disable: If the application demands it to be modified during runtime, use the sl_si91x_sio_spi_init API to modify the peripheral configuration. -// Default: 1 -#define SIO_UC 1 - -// - -#define SL_SIO_I2C_SAMPLE_RATE 100000 - -#define SL_SIO_I2C_SCL_CHANNEL SL_SIO_CH_6 - -#define SL_SIO_I2C_SDA_CHANNEL SL_SIO_CH_7 - -#ifdef __cplusplus -} -#endif -// <<< end of configuration section >>> - -// <<< sl:start pin_tool >>> -//SPI Configuration - -// - -//Clock <9600-7372800> -// Default: 1000000 -#define SL_SIO_SPI_CLK_FREQUENCY 1000000 - -// Mode -// Mode 0 -// Mode 3 -// Default: SL_SIO_SPI_MODE_3 -#define SL_SIO_SPI_MODE SL_SIO_SPI_MODE_3 - -// Clock Channel -// Channel 0 -// Channel 1 -// Channel 2 -// Channel 3 -// Channel 4 -// Channel 5 -// Channel 6 -// Channel 7 -// Default: SL_SIO_CH_1 -#define SL_SIO_SPI_CLK_CH SL_SIO_CH_1 - -// MOSI Channel -// Channel 0 -// Channel 1 -// Channel 2 -// Channel 3 -// Channel 4 -// Channel 5 -// Channel 6 -// Channel 7 -// Default: SL_SIO_CH_3 -#define SL_SIO_SPI_MOSI_CH SL_SIO_CH_3 - -// MISO Channel -// Channel 0 -// Channel 1 -// Channel 2 -// Channel 3 -// Channel 4 -// Channel 5 -// Channel 6 -// Channel 7 -// Default: SL_SIO_CH_2 -#define SL_SIO_SPI_MISO_CH SL_SIO_CH_2 - -// CS Channel -// Channel 0 -// Channel 1 -// Channel 2 -// Channel 3 -// Channel 4 -// Channel 5 -// Channel 6 -// Channel 7 -// Default: SL_SIO_CH_0 -#define SL_SIO_SPI_CS_CH SL_SIO_CH_0 - -// Data Width -// Data Width 8 -// Data Width 16 -// Default: SL_SIO_SPI_BIT_16 -#define SL_SIO_SPI_BIT_LEN SL_SIO_SPI_BIT_16 - -// MSB/LSB First -// MSB First -// LSB First -// Default: SL_SIO_SPI_MSB_FIRST -#define SL_SIO_SPI_MSB_LSB_FIRST SL_SIO_SPI_MSB_FIRST -// UART Configuration - -// - -//Baud Rate <4800-128000> -// Default: 115200 -#define SL_SIO_UART_BAUD_RATE 115200 - -// Bit Length -// Bit Length 8 -// Bit Length 9 -// Default: SL_SIO_UART_BIT_8 -#define SL_SIO_UART_BIT_LENGTH SL_SIO_UART_BIT_8 - -// Parity -// Even Parity 0 -// Odd Parity 1 -// Default: SL_SIO_UART_EVEN_PARITY -#define SL_SIO_UART_PARITY SL_SIO_UART_EVEN_PARITY - -// Receive Channel -// Channel 0 -// Channel 1 -// Channel 2 -// Channel 3 -// Channel 4 -// Channel 5 -// Channel 6 -// Channel 7 -// Default: SL_SIO_CH_2 -#define SL_SIO_UART_RX_CH SL_SIO_CH_2 - -// Transmit channel -// Channel 0 -// Channel 1 -// Channel 2 -// Channel 3 -// Channel 4 -// Channel 5 -// Channel 6 -// Channel 7 -// Default: SL_SIO_CH_3 -#define SL_SIO_UART_TX_CH SL_SIO_CH_3 - -// Stop Bit -// Stop Bit 1 -// Stop Bit 2 -// Default: SL_SIO_UART_STOP_BIT_1 -#define SL_SIO_UART_STOP_BIT SL_SIO_UART_STOP_BIT_1 - -// SL_SIO -// $[SIO_SL_SIO] -#ifndef SL_SIO_PERIPHERAL -#define SL_SIO_PERIPHERAL SIO -#endif - -// SIO SIO0 on GPIO_6 -#ifndef SL_SIO_SIO0_PORT -#define SL_SIO_SIO0_PORT 0 -#endif -#ifndef SL_SIO_SIO0_PIN -#define SL_SIO_SIO0_PIN 6 -#endif -#ifndef SL_SIO_0_LOC -#define SL_SIO_0_LOC 0 -#endif - -// SIO SIO1 on GPIO_26 -#ifndef SL_SIO_SIO1_PORT -#define SL_SIO_SIO1_PORT 0 -#endif -#ifndef SL_SIO_SIO1_PIN -#define SL_SIO_SIO1_PIN 26 -#endif -#ifndef SL_SIO_1_LOC -#define SL_SIO_1_LOC 5 -#endif - -// SIO SIO2 on GPIO_27 -#ifndef SL_SIO_SIO2_PORT -#define SL_SIO_SIO2_PORT 0 -#endif -#ifndef SL_SIO_SIO2_PIN -#define SL_SIO_SIO2_PIN 27 -#endif -#ifndef SL_SIO_2_LOC -#define SL_SIO_2_LOC 9 -#endif - -// SIO SIO3 on GPIO_28 -#ifndef SL_SIO_SIO3_PORT -#define SL_SIO_SIO3_PORT 0 -#endif -#ifndef SL_SIO_SIO3_PIN -#define SL_SIO_SIO3_PIN 28 -#endif -#ifndef SL_SIO_3_LOC -#define SL_SIO_3_LOC 12 -#endif - -// SIO SIO4 on GPIO_29 -#ifndef SL_SIO_SIO4_PORT -#define SL_SIO_SIO4_PORT 0 -#endif -#ifndef SL_SIO_SIO4_PIN -#define SL_SIO_SIO4_PIN 29 -#endif -#ifndef SL_SIO_4_LOC -#define SL_SIO_4_LOC 15 -#endif - -// SIO SIO5 on GPIO_11 -#ifndef SL_SIO_SIO5_PORT -#define SL_SIO_SIO5_PORT 0 -#endif -#ifndef SL_SIO_SIO5_PIN -#define SL_SIO_SIO5_PIN 11 -#endif -#ifndef SL_SIO_5_LOC -#define SL_SIO_5_LOC 17 -#endif - -// SIO SIO6 on ULP_GPIO_6/GPIO_70 -#ifndef SL_SIO_SIO6_PORT -#define SL_SIO_SIO6_PORT 0 -#endif -#ifndef SL_SIO_SIO6_PIN -#define SL_SIO_SIO6_PIN 6 -#endif -#ifndef SL_SIO_6_LOC -#define SL_SIO_6_LOC 20 -#endif - -// SIO SIO7 on ULP_GPIO_7/GPIO_71 -#ifndef SL_SIO_SIO7_PORT -#define SL_SIO_SIO7_PORT 0 -#endif -#ifndef SL_SIO_SIO7_PIN -#define SL_SIO_SIO7_PIN 7 -#endif -#ifndef SL_SIO_7_LOC -#define SL_SIO_7_LOC 22 -#endif -// [SIO_SL_SIO]$ -// <<< sl:end pin_tool >>> - -#if defined(SL_SIO_SPI_CLK_FREQUENCY) -stc_sio_spi_cfg_t pstcSpiConfigUc = { - .u32SpiClockFrq = SL_SIO_SPI_CLK_FREQUENCY, - .u8BitOrder = SL_SIO_SPI_MSB_LSB_FIRST, - .u8SpiClkCh = SL_SIO_SPI_CLK_CH, - .u8SpiMosiCh = SL_SIO_SPI_MOSI_CH, - .u8SpiMisoCh = SL_SIO_SPI_MISO_CH, - .u8SpiCsCh = SL_SIO_SPI_CS_CH, - .u8BitLen = SL_SIO_SPI_BIT_LEN, - .u8Mode = SL_SIO_SPI_MODE, -}; - -#if (SL_SIO_0_LOC == 2) -#define SL_SI91X_SIO0_PIN (SL_SIO_SIO0_PIN + 64) -#else -#define SL_SI91X_SIO0_PIN SL_SIO_SIO0_PIN -#endif -#if (SL_SIO_1_LOC == 2) -#define SL_SI91X_SIO1_PIN (SL_SIO_SIO1_PIN + 64) -#else -#define SL_SI91X_SIO1_PIN SL_SIO_SIO1_PIN -#endif -#if ((SL_SIO_2_LOC == 2) || (SL_SIO_2_LOC == 3)) -#define SL_SI91X_SIO2_PIN (SL_SIO_SIO2_PIN + 64) -#else -#define SL_SI91X_SIO2_PIN SL_SIO_SIO2_PIN -#endif -#define SL_SI91X_SIO3_PIN SL_SIO_SIO3_PIN -#define SL_SI91X_SIO4_PIN SL_SIO_SIO4_PIN -#define SL_SI91X_SIO5_PIN SL_SIO_SIO5_PIN -#define SL_SI91X_SIO6_PIN (SL_SIO_SIO6_PIN + 64) -#define SL_SI91X_SIO7_PIN (SL_SIO_SIO7_PIN + 64) - -#if (SL_SIO_SPI_CLK_CH == SL_SIO_CH_0) -#define SL_SI91X_SIO_SPI_CLK_PORT SL_SIO_SIO0_PORT -#define SL_SI91X_SIO_SPI_CLK_PIN SL_SI91X_SIO0_PIN -#define SL_SI91X_SIO_SPI_CLK_MUX SL_SI91X_SIO_0_MUX -#define SL_SI91X_SIO_SPI_CLK_PAD SL_SI91X_SIO_0_PAD - -#elif (SL_SIO_SPI_CLK_CH == SL_SIO_CH_1) -#define SL_SI91X_SIO_SPI_CLK_PORT SL_SIO_SIO1_PORT -#define SL_SI91X_SIO_SPI_CLK_PIN SL_SI91X_SIO1_PIN -#define SL_SI91X_SIO_SPI_CLK_MUX SL_SI91X_SIO_1_MUX -#define SL_SI91X_SIO_SPI_CLK_PAD SL_SI91X_SIO_1_PAD - -#elif (SL_SIO_SPI_CLK_CH == SL_SIO_CH_2) -#define SL_SI91X_SIO_SPI_CLK_PORT SL_SIO_SIO2_PORT -#define SL_SI91X_SIO_SPI_CLK_PIN SL_SI91X_SIO2_PIN -#define SL_SI91X_SIO_SPI_CLK_MUX SL_SI91X_SIO_2_MUX -#define SL_SI91X_SIO_SPI_CLK_PAD SL_SI91X_SIO_2_PAD - -#elif (SL_SIO_SPI_CLK_CH == SL_SIO_CH_3) -#define SL_SI91X_SIO_SPI_CLK_PORT SL_SIO_SIO3_PORT -#define SL_SI91X_SIO_SPI_CLK_PIN SL_SI91X_SIO3_PIN -#define SL_SI91X_SIO_SPI_CLK_MUX SL_SI91X_SIO_3_MUX -#define SL_SI91X_SIO_SPI_CLK_PAD SL_SI91X_SIO_3_PAD - -#elif (SL_SIO_SPI_CLK_CH == SL_SIO_CH_4) -#define SL_SI91X_SIO_SPI_CLK_PORT SL_SIO_SIO4_PORT -#define SL_SI91X_SIO_SPI_CLK_PIN SL_SI91X_SIO4_PIN -#define SL_SI91X_SIO_SPI_CLK_MUX SL_SI91X_SIO_4_MUX -#define SL_SI91X_SIO_SPI_CLK_PAD SL_SI91X_SIO_4_PAD - -#elif (SL_SIO_SPI_CLK_CH == SL_SIO_CH_5) -#define SL_SI91X_SIO_SPI_CLK_PORT SL_SIO_SIO5_PORT -#define SL_SI91X_SIO_SPI_CLK_PIN SL_SI91X_SIO5_PIN -#define SL_SI91X_SIO_SPI_CLK_MUX SL_SI91X_SIO_5_MUX -#define SL_SI91X_SIO_SPI_CLK_PAD SL_SI91X_SIO_5_PAD - -#elif (SL_SIO_SPI_CLK_CH == SL_SIO_CH_6) -#define SL_SI91X_SIO_SPI_CLK_PORT SL_SIO_SIO6_PORT -#define SL_SI91X_SIO_SPI_CLK_PIN SL_SI91X_SIO6_PIN -#define SL_SI91X_SIO_SPI_CLK_MUX SL_SI91X_SIO_6_MUX -#define SL_SI91X_SIO_SPI_CLK_PAD SL_SI91X_SIO_6_PAD - -#elif (SL_SIO_SPI_CLK_CH == SL_SIO_CH_7) -#define SL_SI91X_SIO_SPI_CLK_PORT SL_SIO_SIO7_PORT -#define SL_SI91X_SIO_SPI_CLK_PIN SL_SI91X_SIO7_PIN -#define SL_SI91X_SIO_SPI_CLK_MUX SL_SI91X_SIO_7_MUX -#define SL_SI91X_SIO_SPI_CLK_PAD SL_SI91X_SIO_7_PAD -#endif - -#if (SL_SIO_SPI_CS_CH == SL_SIO_CH_0) -#define SL_SI91X_SIO_SPI_CS_PORT SL_SIO_SIO0_PORT -#define SL_SI91X_SIO_SPI_CS_PIN SL_SI91X_SIO0_PIN -#define SL_SI91X_SIO_SPI_CS_MUX SL_SI91X_SIO_0_MUX -#define SL_SI91X_SIO_SPI_CS_PAD SL_SI91X_SIO_0_PAD - -#elif (SL_SIO_SPI_CS_CH == SL_SIO_CH_1) -#define SL_SI91X_SIO_SPI_CS_PORT SL_SIO_SIO1_PORT -#define SL_SI91X_SIO_SPI_CS_PIN SL_SI91X_SIO1_PIN -#define SL_SI91X_SIO_SPI_CS_MUX SL_SI91X_SIO_1_MUX -#define SL_SI91X_SIO_SPI_CS_PAD SL_SI91X_SIO_1_PAD - -#elif (SL_SIO_SPI_CS_CH == SL_SIO_CH_2) -#define SL_SI91X_SIO_SPI_CS_PORT SL_SIO_SIO2_PORT -#define SL_SI91X_SIO_SPI_CS_PIN SL_SI91X_SIO2_PIN -#define SL_SI91X_SIO_SPI_CS_MUX SL_SI91X_SIO_2_MUX -#define SL_SI91X_SIO_SPI_CS_PAD SL_SI91X_SIO_2_PAD - -#elif (SL_SIO_SPI_CS_CH == SL_SIO_CH_3) -#define SL_SI91X_SIO_SPI_CS_PORT SL_SIO_SIO3_PORT -#define SL_SI91X_SIO_SPI_CS_PIN SL_SI91X_SIO3_PIN -#define SL_SI91X_SIO_SPI_CS_MUX SL_SI91X_SIO_3_MUX -#define SL_SI91X_SIO_SPI_CS_PAD SL_SI91X_SIO_3_PAD - -#elif (SL_SIO_SPI_CS_CH == SL_SIO_CH_4) -#define SL_SI91X_SIO_SPI_CS_PORT SL_SIO_SIO4_PORT -#define SL_SI91X_SIO_SPI_CS_PIN SL_SI91X_SIO4_PIN -#define SL_SI91X_SIO_SPI_CS_MUX SL_SI91X_SIO_4_MUX -#define SL_SI91X_SIO_SPI_CS_PAD SL_SI91X_SIO_4_PAD - -#elif (SL_SIO_SPI_CS_CH == SL_SIO_CH_5) -#define SL_SI91X_SIO_SPI_CS_PORT SL_SIO_SIO5_PORT -#define SL_SI91X_SIO_SPI_CS_PIN SL_SI91X_SIO5_PIN -#define SL_SI91X_SIO_SPI_CS_MUX SL_SI91X_SIO_5_MUX -#define SL_SI91X_SIO_SPI_CS_PAD SL_SI91X_SIO_5_PAD - -#elif (SL_SIO_SPI_CS_CH == SL_SIO_CH_6) -#define SL_SI91X_SIO_SPI_CS_PORT SL_SIO_SIO6_PORT -#define SL_SI91X_SIO_SPI_CS_PIN SL_SI91X_SIO6_PIN -#define SL_SI91X_SIO_SPI_CS_MUX SL_SI91X_SIO_6_MUX -#define SL_SI91X_SIO_SPI_CS_PAD SL_SI91X_SIO_6_PAD - -#elif (SL_SIO_SPI_CS_CH == SL_SIO_CH_7) -#define SL_SI91X_SIO_SPI_CS_PORT SL_SIO_SIO7_PORT -#define SL_SI91X_SIO_SPI_CS_PIN SL_SI91X_SIO7_PIN -#define SL_SI91X_SIO_SPI_CS_MUX SL_SI91X_SIO_7_MUX -#define SL_SI91X_SIO_SPI_CS_PAD SL_SI91X_SIO_7_PAD -#endif - -#if (SL_SIO_SPI_MOSI_CH == SL_SIO_CH_0) -#define SL_SI91X_SIO_SPI_MOSI_PORT SL_SIO_SIO0_PORT -#define SL_SI91X_SIO_SPI_MOSI_PIN SL_SI91X_SIO0_PIN -#define SL_SI91X_SIO_SPI_MOSI_MUX SL_SI91X_SIO_0_MUX -#define SL_SI91X_SIO_SPI_MOSI_PAD SL_SI91X_SIO_0_PAD - -#elif (SL_SIO_SPI_MOSI_CH == SL_SIO_CH_1) -#define SL_SI91X_SIO_SPI_MOSI_PORT SL_SIO_SIO1_PORT -#define SL_SI91X_SIO_SPI_MOSI_PIN SL_SI91X_SIO1_PIN -#define SL_SI91X_SIO_SPI_MOSI_MUX SL_SI91X_SIO_1_MUX -#define SL_SI91X_SIO_SPI_MOSI_PAD SL_SI91X_SIO_1_PAD - -#elif (SL_SIO_SPI_MOSI_CH == SL_SIO_CH_2) -#define SL_SI91X_SIO_SPI_MOSI_PORT SL_SIO_SIO2_PORT -#define SL_SI91X_SIO_SPI_MOSI_PIN SL_SI91X_SIO2_PIN -#define SL_SI91X_SIO_SPI_MOSI_MUX SL_SI91X_SIO_2_MUX -#define SL_SI91X_SIO_SPI_MOSI_PAD SL_SI91X_SIO_2_PAD - -#elif (SL_SIO_SPI_MOSI_CH == SL_SIO_CH_3) -#define SL_SI91X_SIO_SPI_MOSI_PORT SL_SIO_SIO3_PORT -#define SL_SI91X_SIO_SPI_MOSI_PIN SL_SI91X_SIO3_PIN -#define SL_SI91X_SIO_SPI_MOSI_MUX SL_SI91X_SIO_3_MUX -#define SL_SI91X_SIO_SPI_MOSI_PAD SL_SI91X_SIO_3_PAD - -#elif (SL_SIO_SPI_MOSI_CH == SL_SIO_CH_4) -#define SL_SI91X_SIO_SPI_MOSI_PORT SL_SIO_SIO4_PORT -#define SL_SI91X_SIO_SPI_MOSI_PIN SL_SI91X_SIO4_PIN -#define SL_SI91X_SIO_SPI_MOSI_MUX SL_SI91X_SIO_4_MUX -#define SL_SI91X_SIO_SPI_MOSI_PAD SL_SI91X_SIO_4_PAD - -#elif (SL_SIO_SPI_MOSI_CH == SL_SIO_CH_5) -#define SL_SI91X_SIO_SPI_MOSI_PORT SL_SIO_SIO5_PORT -#define SL_SI91X_SIO_SPI_MOSI_PIN SL_SI91X_SIO5_PIN -#define SL_SI91X_SIO_SPI_MOSI_MUX SL_SI91X_SIO_5_MUX -#define SL_SI91X_SIO_SPI_MOSI_PAD SL_SI91X_SIO_5_PAD - -#elif (SL_SIO_SPI_MOSI_CH == SL_SIO_CH_6) -#define SL_SI91X_SIO_SPI_MOSI_PORT SL_SIO_SIO6_PORT -#define SL_SI91X_SIO_SPI_MOSI_PIN SL_SI91X_SIO6_PIN -#define SL_SI91X_SIO_SPI_MOSI_MUX SL_SI91X_SIO_6_MUX -#define SL_SI91X_SIO_SPI_MOSI_PAD SL_SI91X_SIO_6_PAD - -#elif (SL_SIO_SPI_MOSI_CH == SL_SIO_CH_7) -#define SL_SI91X_SIO_SPI_MOSI_PORT SL_SIO_SIO7_PORT -#define SL_SI91X_SIO_SPI_MOSI_PIN SL_SI91X_SIO7_PIN -#define SL_SI91X_SIO_SPI_MOSI_MUX SL_SI91X_SIO_7_MUX -#define SL_SI91X_SIO_SPI_MOSI_PAD SL_SI91X_SIO_7_PAD -#endif - -#if (SL_SIO_SPI_MISO_CH == SL_SIO_CH_0) -#define SL_SI91X_SIO_SPI_MISO_PORT SL_SIO_SIO0_PORT -#define SL_SI91X_SIO_SPI_MISO_PIN SL_SI91X_SIO0_PIN -#define SL_SI91X_SIO_SPI_MISO_MUX SL_SI91X_SIO_0_MUX -#define SL_SI91X_SIO_SPI_MISO_PAD SL_SI91X_SIO_0_PAD - -#elif (SL_SIO_SPI_MISO_CH == SL_SIO_CH_1) -#define SL_SI91X_SIO_SPI_MISO_PORT SL_SIO_SIO1_PORT -#define SL_SI91X_SIO_SPI_MISO_PIN SL_SI91X_SIO1_PIN -#define SL_SI91X_SIO_SPI_MISO_MUX SL_SI91X_SIO_1_MUX -#define SL_SI91X_SIO_SPI_MISO_PAD SL_SI91X_SIO_1_PAD - -#elif (SL_SIO_SPI_MISO_CH == SL_SIO_CH_2) -#define SL_SI91X_SIO_SPI_MISO_PORT SL_SIO_SIO2_PORT -#define SL_SI91X_SIO_SPI_MISO_PIN SL_SI91X_SIO2_PIN -#define SL_SI91X_SIO_SPI_MISO_MUX SL_SI91X_SIO_2_MUX -#define SL_SI91X_SIO_SPI_MISO_PAD SL_SI91X_SIO_2_PAD - -#elif (SL_SIO_SPI_MISO_CH == SL_SIO_CH_3) -#define SL_SI91X_SIO_SPI_MISO_PORT SL_SIO_SIO3_PORT -#define SL_SI91X_SIO_SPI_MISO_PIN SL_SI91X_SIO3_PIN -#define SL_SI91X_SIO_SPI_MISO_MUX SL_SI91X_SIO_3_MUX -#define SL_SI91X_SIO_SPI_MISO_PAD SL_SI91X_SIO_3_PAD - -#elif (SL_SIO_SPI_MISO_CH == SL_SIO_CH_4) -#define SL_SI91X_SIO_SPI_MISO_PORT SL_SIO_SIO4_PORT -#define SL_SI91X_SIO_SPI_MISO_PIN SL_SI91X_SIO4_PIN -#define SL_SI91X_SIO_SPI_MISO_MUX SL_SI91X_SIO_4_MUX -#define SL_SI91X_SIO_SPI_MISO_PAD SL_SI91X_SIO_4_PAD - -#elif (SL_SIO_SPI_MISO_CH == SL_SIO_CH_5) -#define SL_SI91X_SIO_SPI_MISO_PORT SL_SIO_SIO5_PORT -#define SL_SI91X_SIO_SPI_MISO_PIN SL_SI91X_SIO5_PIN -#define SL_SI91X_SIO_SPI_MISO_MUX SL_SI91X_SIO_5_MUX -#define SL_SI91X_SIO_SPI_MISO_PAD SL_SI91X_SIO_5_PAD - -#elif (SL_SIO_SPI_MISO_CH == SL_SIO_CH_6) -#define SL_SI91X_SIO_SPI_MISO_PORT SL_SIO_SIO6_PORT -#define SL_SI91X_SIO_SPI_MISO_PIN SL_SI91X_SIO6_PIN -#define SL_SI91X_SIO_SPI_MISO_MUX SL_SI91X_SIO_6_MUX -#define SL_SI91X_SIO_SPI_MISO_PAD SL_SI91X_SIO_6_PAD - -#elif (SL_SIO_SPI_MISO_CH == SL_SIO_CH_7) -#define SL_SI91X_SIO_SPI_MISO_PORT SL_SIO_SIO7_PORT -#define SL_SI91X_SIO_SPI_MISO_PIN SL_SI91X_SIO7_PIN -#define SL_SI91X_SIO_SPI_MISO_MUX SL_SI91X_SIO_7_MUX -#define SL_SI91X_SIO_SPI_MISO_PAD SL_SI91X_SIO_7_PAD -#endif - -sl_sio_spi_t sl_sio_spi_init = { - .spi_cs_port = SL_SI91X_SIO_SPI_CS_PORT, - .spi_cs_pin = SL_SI91X_SIO_SPI_CS_PIN, - .spi_cs_mux = SL_SI91X_SIO_SPI_CS_MUX, - .spi_cs_pad = SL_SI91X_SIO_SPI_CS_PAD, - .spi_clk_port = SL_SI91X_SIO_SPI_CLK_PORT, - .spi_clk_pin = SL_SI91X_SIO_SPI_CLK_PIN, - .spi_clk_mux = SL_SI91X_SIO_SPI_CLK_MUX, - .spi_clk_pad = SL_SI91X_SIO_SPI_CLK_PAD, - .spi_mosi_port = SL_SI91X_SIO_SPI_MOSI_PORT, - .spi_mosi_pin = SL_SI91X_SIO_SPI_MOSI_PIN, - .spi_mosi_mux = SL_SI91X_SIO_SPI_MOSI_MUX, - .spi_mosi_pad = SL_SI91X_SIO_SPI_MOSI_PAD, - .spi_miso_port = SL_SI91X_SIO_SPI_MISO_PORT, - .spi_miso_pin = SL_SI91X_SIO_SPI_MISO_PIN, - .spi_miso_mux = SL_SI91X_SIO_SPI_MISO_MUX, - .spi_miso_pad = SL_SI91X_SIO_SPI_MISO_PAD, -}; -#endif - -#if defined(SL_SIO_UART_BAUD_RATE) -stc_sio_uart_config_t UartInitstcUc = { - .u32BaudRate = SL_SIO_UART_BAUD_RATE, - .u8Bitlen = SL_SIO_UART_BIT_8, - .u8Parity = SL_SIO_UART_EVEN_PARITY, - .u8SioUartRxChannel = SL_SIO_UART_RX_CH, - .u8SioUartTxChannel = SL_SIO_UART_TX_CH, - .u8StopBits = SL_SIO_UART_STOP_BIT, -}; - -#if (SL_SIO_UART_TX_CH == SL_SIO_CH_0) -#define SL_SI91X_SIO_UART_TX_PORT SL_SIO_SIO0_PORT -#define SL_SI91X_SIO_UART_TX_PIN SL_SI91X_SIO0_PIN -#define SL_SI91X_SIO_UART_TX_MUX SL_SI91X_SIO_0_MUX -#define SL_SI91X_SIO_UART_TX_PAD SL_SI91X_SIO_0_PAD - -#elif (SL_SIO_UART_TX_CH == SL_SIO_CH_1) -#define SL_SI91X_SIO_UART_TX_PORT SL_SIO_SIO1_PORT -#define SL_SI91X_SIO_UART_TX_PIN SL_SI91X_SIO1_PIN -#define SL_SI91X_SIO_UART_TX_MUX SL_SI91X_SIO_1_MUX -#define SL_SI91X_SIO_UART_TX_PAD SL_SI91X_SIO_1_PAD - -#elif (SL_SIO_UART_TX_CH == SL_SIO_CH_2) -#define SL_SI91X_SIO_UART_TX_PORT SL_SIO_SIO2_PORT -#define SL_SI91X_SIO_UART_TX_PIN SL_SI91X_SIO2_PIN -#define SL_SI91X_SIO_UART_TX_MUX SL_SI91X_SIO_2_MUX -#define SL_SI91X_SIO_UART_TX_PAD SL_SI91X_SIO_2_PAD - -#elif (SL_SIO_UART_TX_CH == SL_SIO_CH_3) -#define SL_SI91X_SIO_UART_TX_PORT SL_SIO_SIO3_PORT -#define SL_SI91X_SIO_UART_TX_PIN SL_SI91X_SIO3_PIN -#define SL_SI91X_SIO_UART_TX_MUX SL_SI91X_SIO_3_MUX -#define SL_SI91X_SIO_UART_TX_PAD SL_SI91X_SIO_3_PAD - -#elif (SL_SIO_UART_TX_CH == SL_SIO_CH_4) -#define SL_SI91X_SIO_UART_TX_PORT SL_SIO_SIO4_PORT -#define SL_SI91X_SIO_UART_TX_PIN SL_SI91X_SIO4_PIN -#define SL_SI91X_SIO_UART_TX_MUX SL_SI91X_SIO_4_MUX -#define SL_SI91X_SIO_UART_TX_PAD SL_SI91X_SIO_4_PAD - -#elif (SL_SIO_UART_TX_CH == SL_SIO_CH_5) -#define SL_SI91X_SIO_UART_TX_PORT SL_SIO_SIO5_PORT -#define SL_SI91X_SIO_UART_TX_PIN SL_SI91X_SIO5_PIN -#define SL_SI91X_SIO_UART_TX_MUX SL_SI91X_SIO_5_MUX -#define SL_SI91X_SIO_UART_TX_PAD SL_SI91X_SIO_5_PAD - -#elif (SL_SIO_UART_TX_CH == SL_SIO_CH_6) -#define SL_SI91X_SIO_UART_TX_PORT SL_SIO_SIO6_PORT -#define SL_SI91X_SIO_UART_TX_PIN SL_SI91X_SIO6_PIN -#define SL_SI91X_SIO_UART_TX_MUX SL_SI91X_SIO_6_MUX -#define SL_SI91X_SIO_UART_TX_PAD SL_SI91X_SIO_6_PAD - -#elif (SL_SIO_UART_TX_CH == SL_SIO_CH_7) -#define SL_SI91X_SIO_UART_TX_PORT SL_SIO_SIO7_PORT -#define SL_SI91X_SIO_UART_TX_PIN SL_SI91X_SIO7_PIN -#define SL_SI91X_SIO_UART_TX_MUX SL_SI91X_SIO_7_MUX -#define SL_SI91X_SIO_UART_TX_PAD SL_SI91X_SIO_7_PAD -#endif - -#if (SL_SIO_UART_RX_CH == SL_SIO_CH_0) -#define SL_SI91X_SIO_UART_RX_PORT SL_SIO_SIO0_PORT -#define SL_SI91X_SIO_UART_RX_PIN SL_SI91X_SIO0_PIN -#define SL_SI91X_SIO_UART_RX_MUX SL_SI91X_SIO_0_MUX -#define SL_SI91X_SIO_UART_RX_PAD SL_SI91X_SIO_0_PAD - -#elif (SL_SIO_UART_RX_CH == SL_SIO_CH_1) -#define SL_SI91X_SIO_UART_RX_PORT SL_SIO_SIO1_PORT -#define SL_SI91X_SIO_UART_RX_PIN SL_SI91X_SIO1_PIN -#define SL_SI91X_SIO_UART_RX_MUX SL_SI91X_SIO_1_MUX -#define SL_SI91X_SIO_UART_RX_PAD SL_SI91X_SIO_1_PAD - -#elif (SL_SIO_UART_RX_CH == SL_SIO_CH_2) -#define SL_SI91X_SIO_UART_RX_PORT SL_SIO_SIO2_PORT -#define SL_SI91X_SIO_UART_RX_PIN SL_SI91X_SIO2_PIN -#define SL_SI91X_SIO_UART_RX_MUX SL_SI91X_SIO_2_MUX -#define SL_SI91X_SIO_UART_RX_PAD SL_SI91X_SIO_2_PAD - -#elif (SL_SIO_UART_RX_CH == SL_SIO_CH_3) -#define SL_SI91X_SIO_UART_RX_PORT SL_SIO_SIO3_PORT -#define SL_SI91X_SIO_UART_RX_PIN SL_SI91X_SIO3_PIN -#define SL_SI91X_SIO_UART_RX_MUX SL_SI91X_SIO_3_MUX -#define SL_SI91X_SIO_UART_RX_PAD SL_SI91X_SIO_3_PAD - -#elif (SL_SIO_UART_RX_CH == SL_SIO_CH_4) -#define SL_SI91X_SIO_UART_RX_PORT SL_SIO_SIO4_PORT -#define SL_SI91X_SIO_UART_RX_PIN SL_SI91X_SIO4_PIN -#define SL_SI91X_SIO_UART_RX_MUX SL_SI91X_SIO_4_MUX -#define SL_SI91X_SIO_UART_RX_PAD SL_SI91X_SIO_4_PAD - -#elif (SL_SIO_UART_RX_CH == SL_SIO_CH_5) -#define SL_SI91X_SIO_UART_RX_PORT SL_SIO_SIO5_PORT -#define SL_SI91X_SIO_UART_RX_PIN SL_SI91X_SIO5_PIN -#define SL_SI91X_SIO_UART_RX_MUX SL_SI91X_SIO_5_MUX -#define SL_SI91X_SIO_UART_RX_PAD SL_SI91X_SIO_5_PAD - -#elif (SL_SIO_UART_RX_CH == SL_SIO_CH_6) -#define SL_SI91X_SIO_UART_RX_PORT SL_SIO_SIO6_PORT -#define SL_SI91X_SIO_UART_RX_PIN SL_SI91X_SIO6_PIN -#define SL_SI91X_SIO_UART_RX_MUX SL_SI91X_SIO_6_MUX -#define SL_SI91X_SIO_UART_RX_PAD SL_SI91X_SIO_6_PAD - -#elif (SL_SIO_UART_RX_CH == SL_SIO_CH_7) -#define SL_SI91X_SIO_UART_RX_PORT SL_SIO_SIO7_PORT -#define SL_SI91X_SIO_UART_RX_PIN SL_SI91X_SIO7_PIN -#define SL_SI91X_SIO_UART_RX_MUX SL_SI91X_SIO_7_MUX -#define SL_SI91X_SIO_UART_RX_PAD SL_SI91X_SIO_7_PAD -#endif - -sl_sio_uart_t sl_sio_uart_init = { - .uart_tx_port = SL_SI91X_SIO_UART_TX_PORT, - .uart_tx_pin = SL_SI91X_SIO_UART_TX_PIN, - .uart_tx_mux = SL_SI91X_SIO_UART_TX_MUX, - .uart_tx_pad = SL_SI91X_SIO_UART_TX_PAD, - .uart_rx_port = SL_SI91X_SIO_UART_RX_PORT, - .uart_rx_pin = SL_SI91X_SIO_UART_RX_PIN, - .uart_rx_mux = SL_SI91X_SIO_UART_RX_MUX, - .uart_rx_pad = SL_SI91X_SIO_UART_RX_PAD, -}; -#endif - -#if defined(SL_SIO_I2C_SAMPLE_RATE) -stc_sio_i2c_config_t i2cConfigUc = { - .u32SampleRate = SL_SIO_I2C_SAMPLE_RATE, - .u8SioI2cScl = SL_SIO_I2C_SCL_CHANNEL, - .u8SioI2cSda = SL_SIO_I2C_SDA_CHANNEL, -}; - -#if (SL_SIO_I2C_SCL_CHANNEL == SL_SIO_CH_0) -#define SL_SI91X_SIO_I2C_SCL_PORT SL_SIO_SIO0_PORT -#define SL_SI91X_SIO_I2C_SCL_PIN SL_SI91X_SIO0_PIN -#define SL_SI91X_SIO_I2C_SCL_MUX SL_SI91X_SIO_0_MUX -#define SL_SI91X_SIO_I2C_SCL_PAD SL_SI91X_SIO_0_PAD - -#elif (SL_SIO_I2C_SCL_CHANNEL == SL_SIO_CH_1) -#define SL_SI91X_SIO_I2C_SCL_PORT SL_SIO_SIO1_PORT -#define SL_SI91X_SIO_I2C_SCL_PIN SL_SI91X_SIO1_PIN -#define SL_SI91X_SIO_I2C_SCL_MUX SL_SI91X_SIO_1_MUX -#define SL_SI91X_SIO_I2C_SCL_PAD SL_SI91X_SIO_1_PAD - -#elif (SL_SIO_I2C_SCL_CHANNEL == SL_SIO_CH_2) -#define SL_SI91X_SIO_I2C_SCL_PORT SL_SIO_SIO2_PORT -#define SL_SI91X_SIO_I2C_SCL_PIN SL_SI91X_SIO2_PIN -#define SL_SI91X_SIO_I2C_SCL_MUX SL_SI91X_SIO_2_MUX -#define SL_SI91X_SIO_I2C_SCL_PAD SL_SI91X_SIO_2_PAD - -#elif (SL_SIO_I2C_SCL_CHANNEL == SL_SIO_CH_3) -#define SL_SI91X_SIO_I2C_SCL_PORT SL_SIO_SIO3_PORT -#define SL_SI91X_SIO_I2C_SCL_PIN SL_SI91X_SIO3_PIN -#define SL_SI91X_SIO_I2C_SCL_MUX SL_SI91X_SIO_3_MUX -#define SL_SI91X_SIO_I2C_SCL_PAD SL_SI91X_SIO_3_PAD - -#elif (SL_SIO_I2C_SCL_CHANNEL == SL_SIO_CH_4) -#define SL_SI91X_SIO_I2C_SCL_PORT SL_SIO_SIO4_PORT -#define SL_SI91X_SIO_I2C_SCL_PIN SL_SI91X_SIO4_PIN -#define SL_SI91X_SIO_I2C_SCL_MUX SL_SI91X_SIO_4_MUX -#define SL_SI91X_SIO_I2C_SCL_PAD SL_SI91X_SIO_4_PAD - -#elif (SL_SIO_I2C_SCL_CHANNEL == SL_SIO_CH_5) -#define SL_SI91X_SIO_I2C_SCL_PORT SL_SIO_SIO5_PORT -#define SL_SI91X_SIO_I2C_SCL_PIN SL_SI91X_SIO5_PIN -#define SL_SI91X_SIO_I2C_SCL_MUX SL_SI91X_SIO_5_MUX -#define SL_SI91X_SIO_I2C_SCL_PAD SL_SI91X_SIO_5_PAD - -#elif (SL_SIO_I2C_SCL_CHANNEL == SL_SIO_CH_6) -#define SL_SI91X_SIO_I2C_SCL_PORT SL_SIO_SIO6_PORT -#define SL_SI91X_SIO_I2C_SCL_PIN SL_SI91X_SIO6_PIN -#define SL_SI91X_SIO_I2C_SCL_MUX SL_SI91X_SIO_6_MUX -#define SL_SI91X_SIO_I2C_SCL_PAD SL_SI91X_SIO_6_PAD - -#elif (SL_SIO_I2C_SCL_CHANNEL == SL_SIO_CH_7) -#define SL_SI91X_SIO_I2C_SCL_PORT SL_SIO_SIO7_PORT -#define SL_SI91X_SIO_I2C_SCL_PIN SL_SI91X_SIO7_PIN -#define SL_SI91X_SIO_I2C_SCL_MUX SL_SI91X_SIO_7_MUX -#define SL_SI91X_SIO_I2C_SCL_PAD SL_SI91X_SIO_7_PAD -#endif - -#if (SL_SIO_I2C_SDA_CHANNEL == SL_SIO_CH_0) -#define SL_SI91X_SIO_I2C_SDA_PORT SL_SIO_SIO0_PORT -#define SL_SI91X_SIO_I2C_SDA_PIN SL_SI91X_SIO0_PIN -#define SL_SI91X_SIO_I2C_SDA_MUX SL_SI91X_SIO_0_MUX -#define SL_SI91X_SIO_I2C_SDA_PAD SL_SI91X_SIO_0_PAD - -#elif (SL_SIO_I2C_SDA_CHANNEL == SL_SIO_CH_1) -#define SL_SI91X_SIO_I2C_SDA_PORT SL_SIO_SIO1_PORT -#define SL_SI91X_SIO_I2C_SDA_PIN SL_SI91X_SIO1_PIN -#define SL_SI91X_SIO_I2C_SDA_MUX SL_SI91X_SIO_1_MUX -#define SL_SI91X_SIO_I2C_SDA_PAD SL_SI91X_SIO_1_PAD - -#elif (SL_SIO_I2C_SDA_CHANNEL == SL_SIO_CH_2) -#define SL_SI91X_SIO_I2C_SDA_PORT SL_SIO_SIO2_PORT -#define SL_SI91X_SIO_I2C_SDA_PIN SL_SI91X_SIO2_PIN -#define SL_SI91X_SIO_I2C_SDA_MUX SL_SI91X_SIO_2_MUX -#define SL_SI91X_SIO_I2C_SDA_PAD SL_SI91X_SIO_2_PAD - -#elif (SL_SIO_I2C_SDA_CHANNEL == SL_SIO_CH_3) -#define SL_SI91X_SIO_I2C_SDA_PORT SL_SIO_SIO3_PORT -#define SL_SI91X_SIO_I2C_SDA_PIN SL_SI91X_SIO3_PIN -#define SL_SI91X_SIO_I2C_SDA_MUX SL_SI91X_SIO_3_MUX -#define SL_SI91X_SIO_I2C_SDA_PAD SL_SI91X_SIO_3_PAD - -#elif (SL_SIO_I2C_SDA_CHANNEL == SL_SIO_CH_4) -#define SL_SI91X_SIO_I2C_SDA_PORT SL_SIO_SIO4_PORT -#define SL_SI91X_SIO_I2C_SDA_PIN SL_SI91X_SIO4_PIN -#define SL_SI91X_SIO_I2C_SDA_MUX SL_SI91X_SIO_4_MUX -#define SL_SI91X_SIO_I2C_SDA_PAD SL_SI91X_SIO_4_PAD - -#elif (SL_SIO_I2C_SDA_CHANNEL == SL_SIO_CH_5) -#define SL_SI91X_SIO_I2C_SDA_PORT SL_SIO_SIO5_PORT -#define SL_SI91X_SIO_I2C_SDA_PIN SL_SI91X_SIO5_PIN -#define SL_SI91X_SIO_I2C_SDA_MUX SL_SI91X_SIO_5_MUX -#define SL_SI91X_SIO_I2C_SDA_PAD SL_SI91X_SIO_5_PAD - -#elif (SL_SIO_I2C_SDA_CHANNEL == SL_SIO_CH_6) -#define SL_SI91X_SIO_I2C_SDA_PORT SL_SIO_SIO6_PORT -#define SL_SI91X_SIO_I2C_SDA_PIN SL_SI91X_SIO6_PIN -#define SL_SI91X_SIO_I2C_SDA_MUX SL_SI91X_SIO_6_MUX -#define SL_SI91X_SIO_I2C_SDA_PAD SL_SI91X_SIO_6_PAD - -#elif (SL_SIO_I2C_SDA_CHANNEL == SL_SIO_CH_7) -#define SL_SI91X_SIO_I2C_SDA_PORT SL_SIO_SIO7_PORT -#define SL_SI91X_SIO_I2C_SDA_PIN SL_SI91X_SIO7_PIN -#define SL_SI91X_SIO_I2C_SDA_MUX SL_SI91X_SIO_7_MUX -#define SL_SI91X_SIO_I2C_SDA_PAD SL_SI91X_SIO_7_PAD -#endif - -sl_sio_i2c_t sl_sio_i2c_init = { - .i2c_scl_port = SL_SI91X_SIO_I2C_SCL_PORT, - .i2c_scl_pin = SL_SI91X_SIO_I2C_SCL_PIN, - .i2c_scl_mux = SL_SI91X_SIO_I2C_SCL_MUX, - .i2c_scl_pad = SL_SI91X_SIO_I2C_SCL_PAD, - .i2c_sda_port = SL_SI91X_SIO_I2C_SDA_PORT, - .i2c_sda_pin = SL_SI91X_SIO_I2C_SDA_PIN, - .i2c_sda_mux = SL_SI91X_SIO_I2C_SDA_MUX, - .i2c_sda_pad = SL_SI91X_SIO_I2C_SDA_PAD, -}; -#endif - -#endif //SL_SIO_CONFIG_H \ No newline at end of file diff --git a/components/device/silabs/si91x/mcu/drivers/unified_api/config/sl_si91x_uart_config.h b/components/device/silabs/si91x/mcu/drivers/unified_api/config/sl_si91x_uart_config.h index 113c52e5e..f5fcc8b59 100644 --- a/components/device/silabs/si91x/mcu/drivers/unified_api/config/sl_si91x_uart_config.h +++ b/components/device/silabs/si91x/mcu/drivers/unified_api/config/sl_si91x_uart_config.h @@ -74,7 +74,6 @@ extern "C" { // 6 // 7 // 8 -// 9 // Default: USART_DATA_BITS_8 #define SL_UART1_DATA_BITS SL_USART_DATA_BITS_8 diff --git a/components/device/silabs/si91x/mcu/drivers/unified_api/config/sl_si91x_ulp_uart_config.h b/components/device/silabs/si91x/mcu/drivers/unified_api/config/sl_si91x_ulp_uart_config.h index e323b3762..c26558d7b 100644 --- a/components/device/silabs/si91x/mcu/drivers/unified_api/config/sl_si91x_ulp_uart_config.h +++ b/components/device/silabs/si91x/mcu/drivers/unified_api/config/sl_si91x_ulp_uart_config.h @@ -74,15 +74,11 @@ extern "C" { // 6 // 7 // 8 -// 9 // Default: USART_DATA_BITS_8 #define SL_ULP_UART_DATA_BITS SL_USART_DATA_BITS_8 // Flow control // None -// CTS -// RTS -// CTS/RTS // Default: USART_FLOW_CONTROL_NONE #define SL_ULP_UART_FLOW_CONTROL_TYPE SL_USART_FLOW_CONTROL_NONE #endif diff --git a/components/device/silabs/si91x/mcu/drivers/unified_api/config/sl_si91x_usart_config.h b/components/device/silabs/si91x/mcu/drivers/unified_api/config/sl_si91x_usart_config.h index 5a9b55812..398fd9c3c 100644 --- a/components/device/silabs/si91x/mcu/drivers/unified_api/config/sl_si91x_usart_config.h +++ b/components/device/silabs/si91x/mcu/drivers/unified_api/config/sl_si91x_usart_config.h @@ -84,7 +84,6 @@ extern "C" { // 6 // 7 // 8 -// 9 // Default: USART_DATA_BITS_8 #define SL_USART_DATA_BITS SL_USART_DATA_BITS_8 diff --git a/components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_adc.h b/components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_adc.h index 7faa51b98..924e53b72 100644 --- a/components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_adc.h +++ b/components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_adc.h @@ -48,7 +48,6 @@ extern "C" { typedef adc_ch_config_t sl_adc_channel_config_t; ///< Renamed ADC channel configuration structure typedef adc_config_t sl_adc_config_t; ///< Renamed ADC configuration structure typedef adc_inter_config_t sl_adc_internal_config_t; ///< Renamed ADC internal configuration structure -typedef adc_extr_config_t sl_adc_external_config_t; ///< Renamed ADC external trigger configuration structure /***************************************************************************/ /** * Typedef for user supplied callback function, which is called when ADC sample completes @@ -92,40 +91,6 @@ typedef enum { SL_ADC_CHANNEL_TYPE_LAST, ///< Last member of enum for validation } sl_adc_channel_type_typedef_t; -/// @brief Enumeration for ADC external trigger type -typedef enum { - SL_ULP_TIMER_EXT_TRIGGER = ULP_TIMER_EXT_TRIGGER, ///< ULP timer external trigger type - SL_ULP_GPIO_EXT_TRIGGER = ULP_GPIO_EXT_TRIGGER, ///< ULP gpio external trigger type - SL_M4_CT_EXT_TRIGGER = M4_CT_EXT_TRIGGER, ///< M4 CT external trigger type - SL_ADC_EXT_TRIGGER_TYPE_LAST, ///< Last member of enum for validation -} sl_adc_ext_trigger_type_t; - -/// @brief Enumeration for ADC external trigger number -typedef enum { - SL_ADC_EXT_TRIGGER_1 = DETECTION1, ///< External trigger detection 1 - SL_ADC_EXT_TRIGGER_2 = DETECTION2, ///< External trigger detection 2 - SL_ADC_EXT_TRIGGER_3 = DETECTION3, ///< External trigger detection 3 - SL_ADC_EXT_TRIGGER_4 = DETECTION4, ///< External trigger detection 4 - SL_ADC_EXT_TRIGGER_LAST, ///< Last member of enum for validation -} sl_adc_ext_trigger_num_t; - -/// @brief Enumeration for ADC external trigger edge selection -typedef enum { - SL_ADC_EXT_TRIGGER_POS_EDGE = POSITIVE_EDGE, ///< External trigger positive edge - SL_ADC_EXT_TRIGGER_NEG_EDGE = NEGATIVE_EDGE, ///< External trigger negative edge - SL_ADC_EXT_TRIGGER_POS_NEG_EDGE = POS_NEG_EDGE, ///< External trigger positive and negative edge - SL_ADC_EXT_TRIGGER_EDGE_LAST, ///< Last member of enum for validation -} sl_adc_ext_trigger_edge_t; - -/// @brief Enumeration for ADC external trigger selection -typedef enum { - SL_ADC_EXT_TRIGGER_SEL_1 = EXT_TRIGGER_SEL1, ///< External trigger selection 1 - SL_ADC_EXT_TRIGGER_SEL_2 = EXT_TRIGGER_SEL2, ///< External trigger selection 2 - SL_ADC_EXT_TRIGGER_SEL_3 = EXT_TRIGGER_SEL3, ///< External trigger selection 3 - SL_ADC_EXT_TRIGGER_SEL_4 = EXT_TRIGGER_SEL4, ///< External trigger selection 4 - SL_ADC_EXT_TRIGGER_SEL_LAST, ///< Last member of enum for validation -} sl_adc_ext_trigger_sel_t; - /// @brief Enumeration for ADC channel. typedef enum { SL_ADC_CHANNEL_1, ///< ADC channel 1 @@ -268,27 +233,6 @@ sl_status_t sl_si91x_adc_register_event_callback(sl_adc_callback_t callback_even ******************************************************************************/ void sl_si91x_adc_unregister_event_callback(void); -/***************************************************************************/ /** - * @brief Configure the ADC external trigger. - * @details Triggers can be used in PS4 State to collect samples from a predefined channel. - * ADC can provide a sample for the selected trigger if the trigger matches. - * There are three external triggers enabled by - * - ULPSS Timer Interrupts - * - ULPSS GPIOs - * - M4SS Configuration Timer. - * The trigger match can be verified by reading the \ref sl_si91x_adc_get_external_trigger_status. - * @pre Pre-conditions: - * - \ref sl_si91x_adc_configure_clock - * - \ref sl_si91x_adc_init - * - \ref sl_si91x_adc_set_channel_configuration - * @param[in] adc_external_trigger : ADC external trigger configuration structure variable. - * @return status 0 if successful, else error code as follow - * - SL_STATUS_OK (0x0000) - Success - * - SL_STATUS_NULL_POINTER (0x0022) - The parameter is a null pointer - * - SL_STATUS_INVALID_PARAMETER (0x0021) - Parameters are invalid - ******************************************************************************/ -sl_status_t sl_si91x_adc_configure_external_trigger(sl_adc_external_config_t adc_external_trigger); - /***************************************************************************/ /** * @brief Configure the ADC sampling rate for the ADC channels. * @details It adjusts the channel offset and frequency for each channel to determine the sample rate. @@ -304,42 +248,6 @@ sl_status_t sl_si91x_adc_configure_external_trigger(sl_adc_external_config_t adc sl_status_t sl_si91x_adc_configure_channel_sampling_rate(sl_adc_internal_config_t adc_internal_config, uint8_t channel_num); -/***************************************************************************/ /** - * @brief This API will provide the status of an external trigger. - * @details This will read the status of an external trigger and update in the ext_trigger. - * @pre Pre-conditions: - * - \ref sl_si91x_adc_configure_clock - * - \ref sl_si91x_adc_init - * - \ref sl_si91x_adc_set_channel_configuration - * - \ref sl_si91x_adc_configure_external_trigger - * @param[in] adc_external_trigger : ADC external trigger configuration structure variable. - * @param[out] ext_trigger : The status of external trigger will be store in this. - * @return status 0 if successful, else error code as follow - * - SL_STATUS_OK (0x0000) - Success - * - SL_STATUS_NULL_POINTER (0x0022) - The parameter is a null pointer - * - SL_STATUS_INVALID_PARAMETER (0x0021) - Parameters are invalid - ******************************************************************************/ -sl_status_t sl_si91x_adc_get_external_trigger_status(sl_adc_external_config_t adc_external_trigger, - uint8_t *ext_trigger); - -/***************************************************************************/ /** - * @brief Clear the ADC external trigger. - * @details After reading the trigger match, use the \ref sl_si91x_adc_clear_external_trigger - * API to clear a specific trigger. - * @pre Pre-conditions: - * - \ref sl_si91x_adc_configure_clock - * - \ref sl_si91x_adc_init - * - \ref sl_si91x_adc_set_channel_configuration - * - \ref sl_si91x_adc_configure_external_trigger - * - \ref sl_si91x_adc_register_event_callback - * - \ref sl_si91x_adc_star - * @param[in] adc_external_trigger : ADC external trigger configuration structure variable. - * @return status 0 if successful, else error code as follow - * - SL_STATUS_OK (0x0000) - Success - * - SL_STATUS_INVALID_PARAMETER (0x0021) - Parameters are invalid - ******************************************************************************/ -sl_status_t sl_si91x_adc_clear_external_trigger(sl_adc_external_config_t adc_external_trigger); - /***************************************************************************/ /** * @brief Configure the ADC ping and pong memory location and length. * @details Configure the ping and pong memory locations, diff --git a/components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_config_timer.h b/components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_config_timer.h index 4be8892b6..9e81d6254 100644 --- a/components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_config_timer.h +++ b/components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_config_timer.h @@ -172,7 +172,7 @@ typedef enum { SL_EVENT2_RISING_EDGE_REGISTERED_OR_EVENT, ///< enum for input-2 rising edge registered or-event SL_EVENT3_RISING_EDGE_REGISTERED_AND_EVENT, ///< enum for input-3 rising edge registered and-event SL_EVENT3_RISING_EDGE_REGISTERED_OR_EVENT, ///< enum for input-3 rising edge registered or-event - SL_EVENT_LAST, ///< Last member of enum for validation + SL_CT_EVENT_LAST, ///< Last member of enum for validation } sl_config_timer_event_t; /// @brief Enumeration to represent various timer actions @@ -442,6 +442,17 @@ sl_status_t sl_si91x_config_timer_set_match_count(sl_config_timer_mode_t mode, sl_counter_number_t counter_number, uint32_t match_value); +/***************************************************************************/ /** +* @brief API to calculate and return the match value of the timer for desired time period +* +* @param[in] time_period_in_us : Time period in microseconds +* @param[out] match_value : Gets match value of the timer for desired time period +* @return status 0 if successful, else error-code as follow +* - \ref SL_STATUS_INVALID_COUNT (0x002B) - Count is invalid. +* - \ref SL_STATUS_OK (0x0000) - Success. +*******************************************************************************/ +sl_status_t sl_si91x_config_timer_get_match_value(uint32_t time_period_in_us, uint32_t *match_value); + /***************************************************************************/ /** * @brief This API will get Config-timer current count. * @details This API will get Config-timer current count as per timer mode and counter-number diff --git a/components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_dac.h b/components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_dac.h index 2479d391d..58b890ab7 100644 --- a/components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_dac.h +++ b/components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_dac.h @@ -64,7 +64,7 @@ typedef void (*sl_dac_callback_t)(uint8_t event); // typedef enum { SL_DAC_FIFO_MODE, ///< operation mode as fifo mode SL_DAC_STATIC_MODE, ///< operation mode as static mode - SL_DAC_OUTPUT_REF_VOLTAGE_FOR_ADC, ///< operation mode as dac output reference voltage for ADC + SL_DAC_OUTPUT_REF_VOLTAGE_FOR_ADC, ///< This mode is currently not supported SL_DAC_OPERATION_MODE_LAST, ///< Last member of enum for validation } sl_dac_operation_mode_t; @@ -75,6 +75,7 @@ typedef enum { } sl_dac_callback_event_t; /// @brief Enumeration for ADC channel this enum only used on Reference voltage for ADC mode of DAC. +/// note: These enums are not used as SL_DAC_OUTPUT_REF_VOLTAGE_FOR_ADC mode is not supported currently. typedef enum { SL_DAC_ADC_CHANNEL_0, ///< ADC channel 0 SL_DAC_ADC_CHANNEL_1, ///< ADC channel 1 diff --git a/components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_driver_gpio.h b/components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_driver_gpio.h index 43a5b90f8..baf119cb1 100644 --- a/components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_driver_gpio.h +++ b/components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_driver_gpio.h @@ -156,9 +156,11 @@ sl_status_t sl_si91x_gpio_driver_enable_pad_selection(uint8_t gpio_padnum); /***************************************************************************/ /** * @brief Enable the host pad selection bit in the PAD selection register. + * GPIO pin number(25 to 30) are valid for HOST PAD selection, referring + * to SL_GPIO_PORT_B, pins 9 to 14. * @pre Pre-condition: * - \ref sl_si91x_gpio_driver_enable_clock() - * @param[in] gpio_num - GPIO pin number to be used + * @param[in] gpio_num - GPIO pin number(25-30) to be used * @return returns status 0 if successful, * else error code as follow. * - \ref SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument diff --git a/components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_gspi.h b/components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_gspi.h index 0bf7520ce..c1b513c15 100644 --- a/components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_gspi.h +++ b/components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_gspi.h @@ -197,10 +197,11 @@ sl_status_t sl_si91x_gspi_deinit(sl_gspi_handle_t gspi_handle); * - The configurations are listed below: * - swap_read (enable/disable) * - swap_write (enable/disable) - * - bit_width (8_bit/16_bit) + * - bit_width (1-16 bits) * - clock_mode (mode0/mode3) * - slave_select_mode (hw_output/sw) * - bitrate + * @note Swap Read and Swap Write can be used only if the bit_width is configured as 16. * @pre Pre-conditions: * - \ref sl_si91x_gspi_configure_clock * - \ref sl_si91x_gspi_init diff --git a/components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_ro_temperature_sensor.h b/components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_ro_temperature_sensor.h deleted file mode 100644 index f9f42e4b2..000000000 --- a/components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_ro_temperature_sensor.h +++ /dev/null @@ -1,284 +0,0 @@ -/***************************************************************************/ /** - * @file sl_si91x_ro_temperature_sensor.h - * @brief RO temperature sensor API implementation - ******************************************************************************* - * # License - * Copyright 2023 Silicon Laboratories Inc. www.silabs.com - ******************************************************************************* - * - * SPDX-License-Identifier: Zlib - * - * The licensor of this software is Silicon Laboratories Inc. - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - * - ******************************************************************************/ - -#ifndef SL_SI91X_RO_TEMPERATURE_SENSOR_H_ -#define SL_SI91X_RO_TEMPERATURE_SENSOR_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -//// Includes -#include "sl_status.h" -#include "rsi_temp_sensor.h" - -/***************************************************************************/ /** - * @addtogroup ROTEMPSENSOR RO Temperature Sensor - * @ingroup SI91X_PERIPHERAL_APIS - * @{ - * - ******************************************************************************/ -/******************************************************************************* - ****************************** Defines / Macros *************************** - ******************************************************************************/ - -/******************************************************************************* - ******************************** Local Variables ************************** - ******************************************************************************/ - -/******************************************************************************* - *************************** Global VARIABLES ******************************** - ******************************************************************************/ - -/******************************************************************************* - ******************************** ENUMS ************************************ - ******************************************************************************/ -///@brief RO temperature sensor reference clock -typedef enum { - SL_RO_REF_CLK, ///< Enable RO kHz clock from analog as reference clock - SL_RO_FSM_CLK, ///< Enable MCU FSM clock as reference clock - SL_RO_CLK_LAST, ///< Last member of enum for validation -} sl_ro_reference_clock_t; - -///@brief Enable/Disable RO temperature sensor -typedef enum { - SL_RO_TEMPERATURE_DISABLE, ///< Temperature sensing disable - SL_RO_TEMPERATURE_ENABLE, ///< Temperature sensing enable - SL_RO_TEMPERATURE_LAST, ///< Last member of enum for validation -} sl_ro_temperature_state_t; - -///@brief Enable/Disable BJT based temperature update -typedef enum { - SL_RO_TEMP_BJT_UPDATE_ENABLE, ///< Enable BJT based temperature through RO calculation - SL_RO_TEMP_SPI_UPDATE_ENABLE, ///< Disable BJT based temperature through RO calculation and Enable update through SPI. - SL_RO_TEMP_BJT_UPDATE_LAST, ///< Last member of enum for validation -} sl_ro_temperature_update_t; - -///@brief Enable/Disable RO periodic temperature checking -typedef enum { - SL_RO_TEMPERATURE_PERIODIC_DISABLE, ///< Periodic temperature checking disable - SL_RO_TEMPERATURE_PERIODIC_ENABLE, ///< Periodic temperature checking enable - SL_RO_TEMPERATURE_PERIODIC_LAST, ///< Last member of enum for validation -} sl_ro_temperature_periodic_check_t; - -///@brief RO temperature periodic check time -typedef enum { - SL_RO_TEMPERATURE_TRIGGER_1SEC, ///< RO temperature update for every 1second - SL_RO_TEMPERATURE_TRIGGER_2SEC, ///< RO temperature update for every 2seconds - SL_RO_TEMPERATURE_TRIGGER_4SEC, ///< RO temperature update for every 4seconds - SL_RO_TEMPERATURE_TRIGGER_5SEC, ///< RO temperature update for every 5seconds - SL_RO_TEMPERATURE_TRIGGER_LAST, ///< Last member of enum for validation -} sl_ro_temperature_trigger_time_t; - -/******************************************************************************* - ***************************** PROTOTYPES ********************************** - ******************************************************************************/ - -/***************************************************************************/ /** - * @brief Set reference clock count for RO temperature sensor - * @details This API is used to set the count of reference clock on which ptat clock counts. - * - * @param[in] count Count of reference clock on which ptat clock counts (0- 1024) - * - * @return Status 0 if successful, else error code: - * - SL_STATUS_OK on success - * - SL_STATUS_INVALID_PARAMETER (0x0021) , The parameter is invalid argument - * - SL_STATUS_NULL_POINTER (0x0022) , The parameter is null pointer - ******************************************************************************/ -sl_status_t sl_si91x_ro_temperature_set_count(uint32_t count); - -/***************************************************************************/ /** - * @brief Select reference clock for RO temperature sensor - * @details This API is used to select the reference clock to the temperature sensor - * @param[in] ref_clk Reference clock selection: - * - 0 - reference RO clock from analog - * - 1 - MCU FSM clock - * @return Status 0 if successful, else error code: - * - SL_STATUS_OK on success \n - * - SL_STATUS_INVALID_PARAMETER (0x0021) , The parameter is invalid argument - * - SL_STATUS_NULL_POINTER (0x0022) , The parameter is null pointer - ******************************************************************************/ -sl_status_t sl_si91x_ro_temperature_select_reference_clock(sl_ro_reference_clock_t ref_clk); - -/***************************************************************************/ /** - * @brief Enable/disable RO temperature sensor - * @details This API is used to enable / disable the temperature sensor - * @param[in] state Enable / disable the temperature sensor: - * - 0 - Disable - * - 1 - Enable - * @return Status 0 if successful, else error code: - * - SL_STATUS_OK on success - * - SL_STATUS_INVALID_PARAMETER (0x0021) , The parameter is invalid argument - * - SL_STATUS_NULL_POINTER (0x0022) , The parameter is null pointer - ******************************************************************************/ -sl_status_t sl_si91x_ro_temperature_enable(sl_ro_temperature_state_t state); - -/***************************************************************************/ /** - * @brief Set nominal value for RO temperature sensor - * @details This API is used to set the nominal value of the temperature sensor - * - * @param[in] value Calibrated temperature value(0-128). - * - * @return Status 0 if successful, else error code: - * - SL_STATUS_OK on success - * - SL_STATUS_INVALID_PARAMETER (0x0021) , The parameter is invalid argument - * - SL_STATUS_NULL_POINTER (0x0022) , The parameter is null pointer - ******************************************************************************/ -sl_status_t sl_si91x_ro_temperature_nominal(uint32_t value); - -/***************************************************************************/ /** - * @brief Read value from RO temperature sensor - * @details This API is used to read the temperature value - * @param[out] temperature Temperature value reading - * @return Status 0 if successful, else error code: - * - SL_STATUS_OK on success - * - SL_STATUS_NULL_POINTER (0x0022) , The parameter is null pointer - ******************************************************************************/ -sl_status_t sl_si91x_ro_temperature_read(int32_t *temperature); - -/***************************************************************************/ /** - * @brief Calculate temperature from RO temperature sensor reading - * @details This API is used to updating temperature through RO based calculation - * @param[in] enable Enable RO based BJT temperature update - * @return Status 0 if successful, else error code: - * - SL_STATUS_OK on success - * - SL_STATUS_INVALID_PARAMETER (0x0021) , The parameter is invalid argument - * - SL_STATUS_NULL_POINTER (0x0022) , The parameter is null pointer - ******************************************************************************/ -sl_status_t sl_si91x_ro_temperature_based_update(sl_ro_temperature_update_t enable); - -/***************************************************************************/ /** - * @brief Update temperature for RO temperature sensor - * @details This API is used to updating temperature - * - * @param[in] temperature Known temperature (0- 255) - * - * @return SL_STATUS_OK on success - ******************************************************************************/ -sl_status_t sl_si91x_ro_temperature_load(uint8_t temperature); - -/***************************************************************************/ /** - * @brief Get reference clock count for RO temperature sensor - * @details This API is used to read the reference clock count - * @param[out] ref_count Count of f1 clock cycles - * @return Status 0 if successful, else error code: - * - SL_STATUS_OK on success - * - SL_STATUS_NULL_POINTER (0x0022) , The parameter is null pointer - ******************************************************************************/ -sl_status_t sl_si91x_ro_temperature_get_reference_clk_count(uint32_t *ref_count); - -/***************************************************************************/ /** - * @brief Get ptat clock count for RO temperature sensor - * @details This API is used to read the ptat clock count - * @param[out] ptat_count Count of f2 clock cycles - * @return Status 0 if successful, else error code: - * - SL_STATUS_OK on success - * - SL_STATUS_NULL_POINTER (0x0022) , The parameter is null pointer - ******************************************************************************/ -sl_status_t sl_si91x_ro_temperature_get_ptat_clk_count(uint32_t *ptat_count); - -/***************************************************************************/ /** - * @brief Update temperature periodically for RO temperature sensor - * @details This API is used to update the temperature periodically after some time - * @param[in] periodic_check Enable periodic checking of temperature - * @param[in] trigger_time Periodic check time in sec: - * - 0 - for every 1 sec - * - 1 - for every 2 secs - * - 2 - for every 4 secs - * - 3 - for every 5 secs - * @return Status 0 if successful, else error code: - * - SL_STATUS_OK on success - * - SL_STATUS_INVALID_PARAMETER (0x0021) , The parameter is invalid argument - * - SL_STATUS_NULL_POINTER (0x0022) , The parameter is null pointer - ******************************************************************************/ -sl_status_t sl_si91x_ro_temperature_periodic_update(sl_ro_temperature_periodic_check_t periodic_check, - sl_ro_temperature_trigger_time_t trigger_time); - -// ******** THE REST OF THE FILE IS DOCUMENTATION ONLY !*********************** -/// @addtogroup ROTEMPSENSOR RO Temperature Sensor -/// @{ -/// -/// @details -/// -/// -/// @n @section ROTEMPSENSOR_Intro Introduction -/// -/// -/// A Ring Oscillator Temperature Sensor (RO Temperature Sensor) is a type of temperature sensor that utilizes -/// a ring oscillator circuit to measure temperature variations. A ring oscillator is a circuit configuration that -/// consists of an odd number of inverters connected in a loop. The frequency of oscillation of the ring oscillator -/// is influenced by various factors, including temperature. -/// -/// Here's how a Ring Oscillator Temperature Sensor typically works: -/// -/// @li **Ring Oscillator Circuit**: The ring oscillator is designed with an odd number of inverters (amplifiers) connected in a loop. -/// The delay through each inverter contributes to the overall oscillation frequency of the ring. -/// -/// @li **Temperature Sensitivity**: The delay through each inverter is sensitive to temperature variations. As the temperature changes, -/// the characteristics of the transistors in the inverters are affected, causing a change in the overall delay and, consequently, the oscillation frequency. -/// -/// @li **Frequency Measurement**: The frequency of the ring oscillator is measured or monitored. This frequency is directly related to the -/// temperature of the environment or the temperature of the integrated circuit itself. -/// -/// @li **Temperature Calibration**: The sensor is often calibrated to provide an accurate temperature reading based on the measured oscillation frequency. -/// Calibration may involve correlating the frequency with a temperature reference to create a temperature-sensitive output. -/// -/// @n @section ROTEMPSENSOR_Config Configuration -/// -/// By altering the mode in the structure below, one can update the trigger time @li @ref sl_ro_temperature_trigger_time_t. -/// -/// @n @section ROTEMPSENSOR_Use Usage -/// -/// RO temperature sensor is set with nominal temperature and the temperature sensor is enabled -/// after the Temperature is updated through RO based calculation. RO temperature sensor will be -/// triggered and updated for every 2 seconds. -/// And the apis used in the RO Temperature Sensor are: -/// -/// 1. @ref sl_si91x_ro_temperature_select_reference_clock -/// -/// 2. @ref sl_si91x_ro_temperature_nominal -/// -/// 3. @ref sl_si91x_ro_temperature_based_update -/// -/// 4. @ref sl_si91x_ro_temperature_set_count -/// -/// 5. @ref sl_si91x_ro_temperature_enable -/// -/// 6. @ref sl_si91x_ro_temperature_periodic_update -/// -/// 7. @ref sl_si91x_ro_temperature_read -/// -/** @} (end addtogroup SL_SI91X_RO_TEMPERATURE_SENSOR) */ - -#ifdef __cplusplus -} -#endif - -#endif /* SL_SI91X_RO_TEMPERATURE_SENSOR_H_ */ diff --git a/components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_sio.h b/components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_sio.h deleted file mode 100644 index b4097a78d..000000000 --- a/components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_sio.h +++ /dev/null @@ -1,947 +0,0 @@ -/***************************************************************************/ /** - * @file sl_si91x_sio.h - * @brief SIO API implementation - ******************************************************************************* - * # License - * Copyright 2023 Silicon Laboratories Inc. www.silabs.com - ******************************************************************************* - * - * SPDX-License-Identifier: Zlib - * - * The licensor of this software is Silicon Laboratories Inc. - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - * - ******************************************************************************/ - -#ifndef SL_SI91X_SIO_H -#define SL_SI91X_SIO_H - -#ifdef __cplusplus -extern "C" { -#endif - -//// Includes -#include "rsi_sio.h" -#include "sl_status.h" - -/***************************************************************************/ /** - * @addtogroup SIO Serial Input-Output - * @ingroup SI91X_PERIPHERAL_APIS - * @{ - * - *******************************************************************************/ - -/******************************************************************************* - *************************** DEFINES / MACROS ******************************** - ******************************************************************************/ -#define SL_SIO_CH_0 0 ///< SIO-SPI channel 0 -#define SL_SIO_CH_1 1 ///< SIO-SPI channel 1 -#define SL_SIO_CH_2 2 ///< SIO-SPI channel 2 -#define SL_SIO_CH_3 3 ///< SIO-SPI channel 3 -#define SL_SIO_CH_4 4 ///< SIO-SPI channel 4 -#define SL_SIO_CH_5 5 ///< SIO-SPI channel 5 -#define SL_SIO_CH_6 6 ///< SIO-SPI channel 6 -#define SL_SIO_CH_7 7 ///< SIO-SPI channel 7 - -typedef stc_sio_spi_cfg_t sl_sio_spi_config_t; ///< SIO-SPI configuration structure -typedef stc_sio_spi_xfer_t sl_sio_spi_xfer_config_t; ///< SIO-SPI Transfer structure -typedef stc_sio_i2s_config_t sl_sio_i2s_config_t; ///< SIO-I2S configuration structure -typedef stc_sio_i2s_xfer_t sl_sio_i2s_xfer_config_t; ///< SIO-I2S Transfer structure -typedef stc_sio_uart_config_t sl_sio_uart_config_t; ///< SIO-UART configuration structure -typedef sio_i2s_func_ptr_t sl_sio_i2s_callback_t; ///< SIO-I2S callback function pointer -typedef sio_Spi_func_ptr_t sl_sio_spi_callback_t; ///< SIO-SPI callback function pointer -typedef sio_Uart_func_ptr_t sl_sio_uart_callback_t; ///< SIO_UART callback function pointer -typedef stc_sio_i2c_config_t sl_sio_i2c_config_t; ///< SIO-I2C configuration structure - -/******************************************************************************* - ******************************** Local Variables ************************** - ******************************************************************************/ - -/******************************************************************************* - *************************** Global VARIABLES ******************************** - ******************************************************************************/ - -/******************************************************************************* - ******************************** ENUMS ************************************ - ******************************************************************************/ -///@brief SIO-SPI Events -typedef enum { - SL_SIO_SPI_TX_DONE, ///< SIO-SPI Transfer done event - SL_SIO_SPI_RX_DONE, ///< SIO-SPI Receive done event -} sl_sio_spi_event_t; - -///@brief SIO-UART Events -typedef enum { - SL_SIO_UART_TX_DONE, ///< SIO-UART transfer done event - SL_SIO_UART_RX_DONE, ///< SIO-UART receive done event - SL_SIO_UART_PARITY_ERR, ///< SIO-UART parity error - SL_SIO_UART_FRAMING_ERR, ///< SIO-UART framing error - SL_SIO_UART_RECEIVE_CHAR, ///< SIO-UART receive character -} sl_sio_uart_event_t; - -///@brief SIO-SPI modes configurations -typedef enum { - SL_SIO_SPI_MODE_0 = 0, ///< SIO-SPI mode 0 - SL_SIO_SPI_MODE_3 = 3, ///< SIO-SPI mode 3 -} sl_sio_spi_mode_t; - -///@brief SIO-SPI bit width configurations -typedef enum { - SL_SIO_SPI_BIT_8 = 8, ///< SIO-SPI bit width 8 - SL_SIO_SPI_BIT_16 = 16, ///< SIO-SPI bit width 16 -} sl_sio_spi_bit_width_t; - -///@brief SIO-SPI MSB/LSB first configurations -typedef enum { - SL_SIO_SPI_LSB_FIRST = 0, ///< SIO-SPI LSB first - SL_SIO_SPI_MSB_FIRST = 1, ///< SIO-SPI MSB first -} sl_sio_spi_msb_lsb_t; - -///@brief SIO-UART bit length configurations -typedef enum { - SL_SIO_UART_BIT_8 = 8, ///< SIO-SPI bit length 8 - SL_SIO_UART_BIT_16 = 16, ///< SIO-SPI bit length 16 -} sl_sio_spi_bit_length_t; - -///@brief SIO-UART parity configurations -typedef enum { - SL_SIO_UART_EVEN_PARITY = 0, ///< SIO-SPI even parity - SL_SIO_UART_ODD_PARITY = 1, ///< SIO-SPI odd parity -} sl_sio_spi_parity_t; - -///@brief SIO-UART stop bit configurations -typedef enum { - SL_SIO_UART_STOP_BIT_1 = 1, ///< SIO-UART stop bit 1 - SL_SIO_UART_STOP_BIT_2 = 2, ///< SIO-UART stop bit 2 -} sl_sio_spi_stop_bit_t; - -/******************************************************************************* - ******************************* STRUCTS *********************************** - ******************************************************************************/ -/// @brief Structure to hold the different versions of the peripheral API -typedef struct { - uint8_t release; ///< Release version number - uint8_t major; ///< Major version number - uint8_t minor; ///< Minor version number -} sl_sio_version_t; - -///@brief Structure to hold the port and pin of SIO SPI -typedef struct { - uint8_t spi_cs_port; ///< SIO SPI CS port - uint8_t spi_cs_pin; ///< SIO SPI CS pin - uint8_t spi_cs_mux; ///< SIO SPI CS mux - uint8_t spi_cs_pad; ///< SIO SPI CS pad - uint8_t spi_clk_port; ///< SIO SPI CLK port - uint8_t spi_clk_pin; ///< SIO SPI CLK pin - uint8_t spi_clk_mux; ///< SIO SPI CLK mux - uint8_t spi_clk_pad; ///< SIO SPI CLK pad - uint8_t spi_mosi_port; ///< SIO SPI MOSI port - uint8_t spi_mosi_pin; ///< SIO SPI MOSI pin - uint8_t spi_mosi_mux; ///< SIO SPI MOSI mux - uint8_t spi_mosi_pad; ///< SIO SPI MOSI pad - uint8_t spi_miso_port; ///< SIO SPI MISO port - uint8_t spi_miso_pin; ///< SIO SPI MISO pin - uint8_t spi_miso_mux; ///< SIO SPI MISO mux - uint8_t spi_miso_pad; ///< SIO SPI MISO pad -} sl_sio_spi_t; - -///@brief Structure to hold the port and pin of SIO UART -typedef struct { - uint8_t uart_tx_port; ///< SIO UART TX port - uint8_t uart_tx_pin; ///< SIO UART TX pin - uint8_t uart_tx_mux; ///< SIO UART TX mux - uint8_t uart_tx_pad; ///< SIO UART TX pad - uint8_t uart_rx_port; ///< SIO UART RX port - uint8_t uart_rx_pin; ///< SIO UART RX pin - uint8_t uart_rx_mux; ///< SIO UART RX mux - uint8_t uart_rx_pad; ///< SIO UART RX pad -} sl_sio_uart_t; - -///@brief Structure to hold the port and pin of SIO I2C -typedef struct { - uint8_t i2c_sda_port; ///< SIO I2C SDA port - uint8_t i2c_sda_pin; ///< SIO I2C SDA pin - uint8_t i2c_sda_mux; ///< SIO I2C SDA mux - uint8_t i2c_sda_pad; ///< SIO I2C SDA pad - uint8_t i2c_scl_port; ///< SIO I2C SCL port - uint8_t i2c_scl_pin; ///< SIO I2C SCL pin - uint8_t i2c_scl_mux; ///< SIO I2C SCL mux - uint8_t i2c_scl_pad; ///< SIO I2C SCL pad -} sl_sio_i2c_t; - -/******************************************************************************* - ***************************** PROTOTYPES ********************************** - ******************************************************************************/ - -/***************************************************************************/ /** - * @brief Initialize the SIO module. It initializes the SIO - * GPIO's and enables the SIO module clock. - * - * @param none - * - * @return returns status 0 if successful, else error code as follows: - * - \ref SL_STATUS_FAIL (0x0001) - Fail, SIO initialization failed - * - \ref SL_STATUS_OK (0x0000) - Success, SIO initialization successful -******************************************************************************/ -sl_status_t sl_si91x_sio_init(void); - -/***************************************************************************/ /** - * @brief Initialize the SIO-SPI module. It configures - * the SPI mode, bit length, bit order, SIO frequency, and the SIO channels for - * the SPI transfer lines. - * @pre Pre-condition: - * - \ref sl_si91x_sio_init() - * @param[in] configuration - Pointer to SIO-SPI configuration structure - * \ref sl_sio_spi_config_t - * @return returns status 0 if successful, - * else error code as follows: - * - \ref SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument - * - \ref SL_STATUS_NULL_POINTER (0x0022) - The parameter is a null pointer - * - \ref SL_STATUS_OK (0x0000) - Success, SPI initialization done properly -******************************************************************************/ -sl_status_t sl_si91x_sio_spi_init(sl_sio_spi_config_t *configuration); - -/***************************************************************************/ /** - * @brief This API is used to De-initialize SIO module - * @param none - * @return none - ******************************************************************************/ -void sl_si91x_sio_deinit(void); - -/***************************************************************************/ /** - * @brief Initialize SIO SPI pins and clock - * @param[in] sio_spi_init : Pointer to the structure of type \ref sl_sio_spi_t - * @return returns status 0 if successful, - * else error code as follows: - * - \ref SL_STATUS_OK - Success - * - \ref SL_STATUS_NULL_POINTER - The parameter is a null pointer -******************************************************************************/ -sl_status_t sl_si91x_sio_spi_pin_initialization(sl_sio_spi_t *sio_spi_init); - -/***************************************************************************/ /** - * @brief Initialize SIO UART pins and clock. This holds the UART Tx, Rx pins - * configuration. - * - * @param[in] sio_uart_init : Pointer to the structure of type \ref sl_sio_uart_t - * - * @return returns status 0 if successful, - * else error code as follows: - * - \ref SL_STATUS_OK - Success - * - \ref SL_STATUS_NULL_POINTER - The parameter is a null pointer -******************************************************************************/ -sl_status_t sl_si91x_sio_uart_pin_initialization(sl_sio_uart_t *sio_uart_init); - -/***************************************************************************/ /** - * @brief Initialize SIO I2C pins and clock. This holds the I2C SDA, SCL pins - * configuration. - * - * @param[in] sio_i2c_init : Pointer to the structure of type \ref sl_sio_i2c_t - * - * @return returns status 0 if successful, - * else error code as follows: - * - \ref SL_STATUS_OK - Success - * - \ref SL_STATUS_NULL_POINTER - The parameter is a null pointer -******************************************************************************/ -sl_status_t sl_si91x_sio_i2c_pin_initialization(sl_sio_i2c_t *sio_i2c_init); - -/***************************************************************************/ /** - * @brief Assert the SIO SPI chip select. - * @details This tells peripheral that it should wake up - * and receive / send data and is also used when multiple peripherals are present to - * select the one you'd like to communicate with. - * @pre Pre-conditions: - * - \ref sl_si91x_sio_init() - * - \ref sl_si91x_sio_spi_init() - * @param[in] chip_select_num - Chip select number (0 to 7) - * @return returns status 0 if successful, - * else error code as follows: - * - \ref SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument - * - \ref SL_STATUS_NULL_POINTER (0x0022) - The parameter is a null pointer - * - \ref SL_STATUS_OK (0x0000) - Success -******************************************************************************/ -sl_status_t sl_si91x_sio_spi_cs_assert(uint8_t chip_select_num); - -/***************************************************************************/ /** - * @brief De-assert the SIO SPI chip select. This is used to disable after the last byte - * is transmitted / received. - * @pre Pre-conditions: - * - \ref sl_si91x_sio_init() - * - \ref sl_si91x_sio_spi_init() - * - \ref sl_si91x_sio_spi_cs_assert() - * - \ref sl_si91x_sio_spi_transfer() - * @param[in] chip_select_num - Chip select number (0 to 7) - * @return returns status 0 if successful, - * else error code as follows: - * - \ref SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument - * - \ref SL_STATUS_NULL_POINTER (0x0022) - The parameter is a null pointer - * - \ref SL_STATUS_OK (0x0000) - Success -******************************************************************************/ -sl_status_t sl_si91x_sio_spi_cs_deassert(uint8_t chip_select_num); - -/***************************************************************************/ /** - * @brief Register the user callback function. It registers the callback, i.e., - * stores the callback function address and pass to the variable that is called - * in Interrupt Handler. If another callback is registered without unregistering - * previous callback then, it returns an error code, so it is mandatory to unregister - * the callback before registering another callback. It will returns error if any - * callback is already registered. - * @pre Pre-conditions: - * - \ref sl_si91x_sio_init() - * - \ref sl_si91x_sio_spi_init() - * @param[in] callback_event - Pointer to the function \ref sl_sio_spi_callback_t - * which needs to be called at the time of interrupt. - * @return returns status 0 if successful, - * else error code as follows: - * - \ref SL_STATUS_OK (0x0000) - Success - * - \ref SL_STATUS_NULL_POINTER (0x0022) - The parameter is a null pointer - * - \ref SL_STATUS_BUSY (0x0004) - Driver is busy -******************************************************************************/ -sl_status_t sl_si91x_sio_spi_register_event_callback(sl_sio_spi_callback_t callback_event); - -/***************************************************************************/ /** - * @brief Un-register the user callback function, i.e., clear the callback - * function address and disables IRQ handler. - * @pre Pre-conditions: - * - \ref sl_si91x_sio_init() - * - \ref sl_si91x_sio_spi_init() - * - \ref sl_si91x_sio_spi_register_event_callback() - * @param none - * @return none -******************************************************************************/ -void sl_si91x_sio_spi_unregister_event_callback(void); - -/***************************************************************************/ /** - * @brief Transfer the SIO SPI data. It is used to make the SIO-SPI - * transfer in non-blocking mode. - * @pre Pre-conditions: - * - \ref sl_si91x_sio_init() - * - \ref sl_si91x_sio_spi_init() - * - \ref sl_si91x_sio_spi_cs_assert() - * - * @param[in] xfer_config - Pointer to SIO-SPI transfer configuration structure - * \ref sl_sio_spi_xfer_config_t - * - * @return returns status 0 if successful, else error code as follows: - * - \ref SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument - * - \ref SL_STATUS_NULL_POINTER (0x0022) - The parameter is a null pointer - * - \ref SL_STATUS_OK (0x0000) - Success -******************************************************************************/ -sl_status_t sl_si91x_sio_spi_transfer(sl_sio_spi_xfer_config_t *xfer_config); - -/***************************************************************************/ /** - * @brief Get the SIO version. It is used to get the release, SQA and DEV version - * of the SIO module. - * @param none - * @return returns structure of type \ref sl_sio_version_t -******************************************************************************/ -sl_sio_version_t sl_si91x_sio_get_version(void); - -/***************************************************************************/ /** - * @brief Initialize SIO-UART, i.e., set baud rate, parity, - * channel selection, stop bits, and data length. - * @pre Pre-conditions: - * - \ref sl_si91x_sio_init() - * @param[in] configuration - Pointer to SIO-UART configuration structure - * \ref sl_sio_uart_config_t - * @return returns status 0 if successful, - * else error code as follows: - * - \ref SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument - * - \ref SL_STATUS_NULL_POINTER (0x0022) - The parameter is a null pointer - * - \ref SL_STATUS_OK (0x0000) - Success, UART initialization done properly -******************************************************************************/ -sl_status_t sl_si91x_sio_uart_init(sl_sio_uart_config_t *configuration); - -/***************************************************************************/ /** - * @brief Send the data over SIO-UART in non-blocking mode. Transmit bytes from the - * buffer using an interrupt service. Will return immediately, but cannot be called - * again until the previous call has finished. - * @pre Pre-conditions: - * - \ref sl_si91x_sio_init() - * - \ref sl_si91x_sio_uart_init() - * @param[in] buffer - data pointer to send - * @param[in] length - data length - * @return returns status 0 if successful, - * else error code as follows: - * - \ref SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument - * - \ref SL_STATUS_NULL_POINTER (0x0022) - The parameter is a null pointer - * - \ref SL_STATUS_OK (0x0000) - Success -******************************************************************************/ -sl_status_t sl_si91x_sio_uart_send(const void *buffer, uint16_t length); - -/***************************************************************************/ /** - * @brief Send the data over SIO-UART in blocking mode. Transmit bytes from the - * buffer using a blocking send byte function. Does not return until all bytes are sent. - * @pre Pre-conditions: - * - \ref sl_si91x_sio_init() - * - \ref sl_si91x_sio_uart_init() - * - \ref sl_si91x_sio_uart_send() (or) \ref sl_si91x_sio_uart_send_blocking() - * @param[in] buffer - data pointer to send - * @param[in] length - number of bytes to send - * @return returns status 0 if successful, - * else error code as follows: - * - \ref SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument - * - \ref SL_STATUS_NULL_POINTER (0x0022) - The parameter is a null pointer - * - \ref SL_STATUS_OK (0x0000) - Success -******************************************************************************/ -sl_status_t sl_si91x_sio_uart_send_blocking(const void *buffer, uint16_t length); - -/***************************************************************************/ /** - * @brief Read data from SIO-UART in non-blocking mode. - * @pre Pre-conditions: - * - \ref sl_si91x_sio_init() - * - \ref sl_si91x_sio_uart_init() - * - \ref sl_si91x_sio_uart_send() (or) \ref sl_si91x_sio_uart_send_blocking() - * @param[out] data_buffer - data buffer pointer to read - * @param[in] num_bytes - number of bytes read - * @return returns status 0 if successful, - * else error code as follows: - * - \ref SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument - * - \ref SL_STATUS_NULL_POINTER (0x0022) - The parameter is a null pointer - * - \ref SL_STATUS_OK (0x0000) - Success -******************************************************************************/ -sl_status_t sl_si91x_sio_uart_read(void *data_buffer, uint16_t num_bytes); - -/***************************************************************************/ /** - * @brief Read data from UART in blocking mode. - * @pre Pre-conditions: - * - \ref sl_si91x_sio_init() - * - \ref sl_si91x_sio_uart_init() - * - \ref sl_si91x_sio_uart_send() (or) - * - \ref sl_si91x_sio_uart_send_blocking() - * @param[out] data_buffer - data buffer pointer to read - * @param[in] num_bytes - number of bytes read - * @return returns status 0 if successful, - * else error code as follows: - * - \ref SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument - * - \ref SL_STATUS_NULL_POINTER (0x0022) - The parameter is a null pointer - * - \ref SL_STATUS_OK (0x0000) - Success -******************************************************************************/ -sl_status_t sl_si91x_sio_uart_read_blocking(void *data_buffer, uint16_t num_bytes); - -/***************************************************************************/ /** - * @brief Register the user callback function. - * @pre Pre-conditions: - * - \ref sl_si91x_sio_init() - * - \ref sl_si91x_sio_uart_init() - * @param[in] callback_event - Pointer to the function \ref sl_sio_uart_callback_t - * which needs to be called at the time of interrupt. - * @return returns status 0 if successful, - * else error code as follows: - * - \ref SL_STATUS_OK (0x0000) - Success - * - \ref SL_STATUS_NULL_POINTER (0x0022) - The parameter is a null pointer - * - \ref SL_STATUS_BUSY (0x0004) - Driver is busy -******************************************************************************/ -sl_status_t sl_si91x_sio_uart_register_event_callback(sl_sio_uart_callback_t callback_event); - -/***************************************************************************/ /** - * @brief Write data using SIO-I2C. - * @pre Pre-conditions: - * - \ref sl_si91x_sio_init() - * - \ref sl_si91x_sio_i2c_generate_start() - * @param[in] configuration - pointer to the I2C configuration structure - * \ref stc_sio_i2c_config_t in SIO module - * @param[in] address - slave address(1- 255). - * @param[in] data - pointer to the data - * @param[in] length - data length - * @return returns status 0 if successful, - * else error code as follows: - * - \ref SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument - * - \ref SL_STATUS_NULL_POINTER (0x0022) - The parameter is a null pointer - * - \ref SL_STATUS_OK (0X000) - Success -******************************************************************************/ -sl_status_t sl_si91x_sio_i2c_write(stc_sio_i2c_config_t *configuration, - uint8_t address, - uint8_t *data, - uint16_t length); - -/***************************************************************************/ /** - * @brief Read data using SIO-I2C. - * @pre Pre-conditions: - * - \ref sl_si91x_sio_init() - * - \ref sl_si91x_sio_i2c_generate_start() - * - \ref sl_si91x_sio_i2c_write() (or) - * - \ref sl_si91x_sio_i2c_transfer() - * @param[in] configuration - pointer to the I2C configuration structure - * \ref stc_sio_i2c_config_t in SIO module - * @param[in] address - slave address(1- 255). - * @param[out] data - pointer to the data - * @param[in] length - data length - * @return returns status 0 if successful, - * else error code as follows: - * - \ref SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument - * - \ref SL_STATUS_NULL_POINTER (0x0022) - The parameter is a null pointer - * - \ref SL_STATUS_OK (0X000) - Success -******************************************************************************/ -sl_status_t sl_si91x_sio_i2c_read(stc_sio_i2c_config_t *configuration, uint8_t address, uint8_t *data, uint16_t length); - -/***************************************************************************/ /** - * @brief Transfer data using SIO-I2C. - * @pre Pre-conditions: - * - \ref sl_si91x_sio_init() - * - \ref sl_si91x_sio_i2c_generate_start() - * @param[in] configuration - Pointer to the I2C configuration structure - * \ref stc_sio_i2c_config_t in SIO module - * @param[in] address - Slave address (1- 255). - * @param[in] tx_buffer - Pointer to the data transmit buffer - * @param[in] tx_length - TX data length - * @param[out] rx_buffer - Pointer to the data receive buffer - * @param[in] rx_length - RX data length - * @return returns status 0 if successful, - * else error code as follows: - * - \ref SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument - * - \ref SL_STATUS_NULL_POINTER (0x0022) - The parameter is a null pointer - * - \ref SL_STATUS_OK (0X000) - Success -******************************************************************************/ -sl_status_t sl_si91x_sio_i2c_transfer(stc_sio_i2c_config_t *configuration, - uint8_t address, - uint8_t *tx_buffer, - uint16_t tx_length, - uint8_t *rx_buffer, - uint16_t rx_length); - -/***************************************************************************/ /** - * @brief Generate I2C start in SIO. - * @pre Pre-condition: - * - \ref sl_si91x_sio_init() - * @param none - * @return none -******************************************************************************/ -void sl_si91x_sio_i2c_generate_start(void); - -/***************************************************************************/ /** - * @brief Generate I2C stop in SIO. - * @pre Pre-conditions: - * - \ref sl_si91x_sio_init() - * - \ref sl_si91x_sio_i2c_generate_start() - * - \ref sl_si91x_sio_i2c_write() (or) - * - \ref sl_si91x_sio_i2c_transfer() - * @param none - * @return none -******************************************************************************/ -void sl_si91x_sio_i2c_generate_stop(void); - -/***************************************************************************/ -/** - * @brief Un-register the user callback function. - * @pre Pre-conditions: - * - \ref sl_si91x_sio_init() - * - \ref sl_si91x_sio_uart_init() - * - \ref sl_si91x_sio_uart_register_event_callback() - * @param none - * @return none -******************************************************************************/ -void sl_si91x_sio_uart_unregister_event_callback(void); - -/***************************************************************************/ /** - * @brief Used when UART receive is done. - * @pre Pre-conditions: - * - \ref sl_si91x_sio_init() - * - \ref sl_si91x_sio_uart_init() - * - \ref sl_si91x_sio_uart_send() - * - \ref sl_si91x_sio_uart_read() - * @param none - * @return none -******************************************************************************/ -void sl_si91x_sio_uart_rx_done(void); - -/***************************************************************************/ /** - * @brief Configure pin detection mode to be considered for GPIO interrupt. - * @pre Pre-conditions: - * - \ref sl_si91x_sio_init() - * @param[in] channel - SIO channel to be selected \ref en_sio_channels_t - * @param[in] flag - GPIO interrupt generated \ref interrupt_flag_t - * - Rise edge: 0 - * - Fall edge: 1 - * - Level 0: 2 - * - Level 1: 3 - * @return returns status 0 if successful, - * else error code as follows: - * - \ref SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument - * - \ref SL_STATUS_NULL_POINTER (0x0022) - The parameter is a null pointer - * - \ref SL_STATUS_OK (0X000) - Success -******************************************************************************/ -sl_status_t sl_si91x_sio_configure_interrupt(en_sio_channels_t channel, interrupt_flag_t flag); - -/***************************************************************************/ /** - * @brief Match the pattern with data to be detected. - * @pre Pre-conditions: - * - \ref sl_si91x_sio_init() - * @param[in] channel - SIO channel to be selected \ref en_sio_channels_t - * @param[in] pattern - Pattern match bit to be enabled for pattern match to take place \ref pattern_match_t - * - Pattern match disable: 0 - * - Pattern match enable: 1 - * @param[in] slice - Slice number (0,1,2,8,9,10) to select. - * @param[in] slice_pattern - Pattern to match for selected slice - * @return returns status 0 if successful, - * else error code as follows: - * - \ref SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument - * - \ref SL_STATUS_NULL_POINTER (0x0022) - The parameter is a null pointer - * - \ref SL_STATUS_OK (0X000) - Success -******************************************************************************/ -sl_status_t sl_si91x_sio_match_pattern(en_sio_channels_t channel, - pattern_match_t pattern, - uint8_t slice, - uint32_t slice_pattern); - -/***************************************************************************/ /** - * @brief Generate the shift clock. - * @pre Pre-conditions: - * - \ref sl_si91x_sio_init() - * @param[in] divider - Desired clock frequency configuration - * @param[in] channel - SIO channel to be selected \ref en_sio_channels_t - * @return returns status 0 if successful, - * else error code as follows: - * - \ref SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument - * - \ref SL_STATUS_NULL_POINTER (0x0022) - The parameter is a null pointer - * - \ref SL_STATUS_OK (0X000) - Success -******************************************************************************/ -sl_status_t sl_si91x_sio_shift_clock(uint32_t divider, en_sio_channels_t channel); - -/***************************************************************************/ /** - * @brief Select SIO peripheral clock. - * @pre Pre-conditions: - * - \ref sl_si91x_sio_init() - * - \ref sl_si91x_sio_uart_init() - * - \ref sl_si91x_sio_uart_register_event_callback() - * - \ref sl_si91x_sio_uart_send() - * @param[in] channel - SIO channel to be selected \ref en_sio_channels_t - * @param[in] clock - Clock used for shift operations \ref clock_type_t - * - Internal clock: 0 - * - External clock: 1 - * @return returns status 0 if successful, - * else error code as follows: - * - \ref SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument - * - \ref SL_STATUS_NULL_POINTER (0x0022n) - The parameter is null pointer - * - \ref SL_STATUS_OK (0X000) - Success -******************************************************************************/ -sl_status_t sl_si91x_sio_select_clock(en_sio_channels_t channel, clock_type_t clock); - -/***************************************************************************/ /** - * @brief Shift the number of bits. Number of shifts to happen before reloading - * the shift register with data/pausing the operation. i.e. value to be - * set = (total no. of valid bits in shift register/ number of bits per shift) – 1 - * @pre Pre-conditions: - * - \ref sl_si91x_sio_init() - * @param[in] channel - SIO channel to be selected \ref en_sio_channels_t - * @param[in] data_shift - Number of shifts to happen before reloading register with data. - * Value to be set = (total no. of valid bits in shift register/ no. of bits per shift) - 1 - * @return returns status 0 if successful, - * else error code as follows: - * - \ref SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument - * - \ref SL_STATUS_NULL_POINTER (0x0022) - The parameter is null pointer - * - \ref SL_STATUS_OK (0X000) - Success -******************************************************************************/ -sl_status_t sl_si91x_sio_position_counter(en_sio_channels_t channel, uint32_t data_shift); - -/***************************************************************************/ /** - * @brief Enable/disable the flow control bit. - * @pre Pre-conditions: - * - \ref sl_si91x_sio_init() - * @param[in] channel - SIO channel to be selected \ref en_sio_channels_t - * @param[in] flow_control - It decides whether to continue data shifting based on data - * present in shift register validation \ref flow_control_t - * - Flow control disable: 0 - * - Flow control enable: 1 - * @return returns status 0 if successful, - * else error code as follows: - * - \ref SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument - * - \ref SL_STATUS_NULL_POINTER (0x0022n) - The parameter is null pointer - * - \ref SL_STATUS_OK (0X000) - Success -******************************************************************************/ -sl_status_t sl_si91x_sio_control_flow(en_sio_channels_t channel, flow_control_t flow_control); - -/***************************************************************************/ /** - * @brief Load data to buffer in reverse order. - * @pre Pre-condition: - * - \ref sl_si91x_sio_init() - * @param[in] channel - SIO channel to be selected \ref en_sio_channels_t - * @param[in] reverse - If data to be shifted out MSB first, it is to be set \ref reverse_load_t - * @return returns status 0 if successful, - * else error code as follows: - * - \ref SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument - * - \ref SL_STATUS_NULL_POINTER (0x0022n) - The parameter is null pointer - * - \ref SL_STATUS_OK (0X000) - Success -******************************************************************************/ -sl_status_t sl_si91x_sio_reverse_load(en_sio_channels_t channel, reverse_load_t reverse); - -/***************************************************************************/ /** - * @brief Enable the common swap interrupt. - * @pre Pre-condition: - * - \ref sl_si91x_sio_init() - * @param[in] channel - SIO channel to be selected \ref en_sio_channels_t - * @return returns status 0 if successful, - * else error code as follows: - * - \ref SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument - * - \ref SL_STATUS_NULL_POINTER (0x0022n) - The parameter is null pointer - * - \ref SL_STATUS_OK (0X000) - Success -******************************************************************************/ -sl_status_t sl_si91x_sio_set_interrupt(en_sio_channels_t channel); - -/***************************************************************************/ /** - * @brief Disable the common swap interrupt. - * @pre Pre-conditions: - * - \ref sl_si91x_sio_init() - * - \ref sl_si91x_sio_i2c_generate_start() - * - \ref sl_si91x_sio_i2c_write() (or) - * - \ref sl_si91x_sio_i2c_transfer() - * @param[in] channel - SIO channel to be selected \ref en_sio_channels_t - * @return returns status 0 if successful, - * else error code as follows: - * - \ref SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument - * - \ref SL_STATUS_NULL_POINTER (0x0022n) - The parameter is null pointer - * - \ref SL_STATUS_OK (0X000) - Success -******************************************************************************/ -sl_status_t sl_si91x_sio_clear_interrupt(en_sio_channels_t channel); - -/***************************************************************************/ /** - * @brief Mask the common swap interrupt. - * @pre Pre-conditions: - * - \ref sl_si91x_sio_init() - * @param[in] channel - SIO channel to be selected \ref en_sio_channels_t - * @return returns status 0 if successful, - * else error code as follows: - * - \ref SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument - * - \ref SL_STATUS_NULL_POINTER (0x0022n) - The parameter is null pointer - * - \ref SL_STATUS_OK (0X000) - Success -******************************************************************************/ -sl_status_t sl_si91x_sio_mask_interrupt(en_sio_channels_t channel); - -/***************************************************************************/ /** - * @brief Unmask the common swap interrupt. - * @pre Pre-condition: - * - \ref sl_si91x_sio_init() - * @param[in] channel - SIO channel to be selected \ref en_sio_channels_t - * @return returns status 0 if successful, - * else error code as follows: - * - \ref SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument - * - \ref SL_STATUS_NULL_POINTER (0x0022n) - The parameter is null pointer - * - \ref SL_STATUS_OK (0X000) - Success -******************************************************************************/ -sl_status_t sl_si91x_sio_unmask_interrupt(en_sio_channels_t channel); - -/***************************************************************************/ /** - * @brief Read the common swap interrupt status. - * @pre Pre-condition: - * - \ref sl_si91x_sio_init() - * @param none - * @return returns interrupt status -******************************************************************************/ -uint32_t sl_si91x_sio_get_interrupt_status(void); - -/***************************************************************************/ /** - * @brief Enable the common shift interrupt. - * @pre Pre-condition: - * - \ref sl_si91x_sio_init() - * @param[in] channel - SIO channel to be selected \ref en_sio_channels_t - * @return returns status 0 if successful, - * else error code as follows: - * - \ref SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument - * - \ref SL_STATUS_NULL_POINTER (0x0022n) - The parameter is null pointer - * - \ref SL_STATUS_OK (0X000) - Success -******************************************************************************/ -sl_status_t sl_si91x_sio_set_shift_interrupt(en_sio_channels_t channel); - -/***************************************************************************/ /** - * @brief Disable the common shift interrupt. - * @pre Pre-condition: - * - \ref sl_si91x_sio_init() - * @param[in] channel - SIO channel to be selected \ref en_sio_channels_t - * @return returns status 0 if successful, - * else error code as follows: - * - \ref SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument - * - \ref SL_STATUS_NULL_POINTER (0x0022n) - The parameter is null pointer - * - \ref SL_STATUS_OK (0X000) - Success -******************************************************************************/ -sl_status_t sl_si91x_sio_clear_shift_interrupt(en_sio_channels_t channel); - -/***************************************************************************/ /** - * @brief Mask the common shift interrupt. - * @pre Pre-condition: - * - \ref sl_si91x_sio_init() - * @param[in] channel - SIO channel to be selected \ref en_sio_channels_t - * @return returns status 0 if successful, - * else error code as follows: - * - \ref SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument - * - \ref SL_STATUS_NULL_POINTER (0x0022n) - The parameter is null pointer - * - \ref SL_STATUS_OK (0X000) - Success -******************************************************************************/ -sl_status_t sl_si91x_sio_mask_shift_interrupt(en_sio_channels_t channel); - -/***************************************************************************/ /** - * @brief Unmask the common shift interrupt. - * @pre Pre-condition: - * - \ref sl_si91x_sio_init() - * @param[in] channel - SIO channel to be selected \ref en_sio_channels_t - * @return returns status 0 if successful, - * else error code as follows: - * - \ref SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument - * - \ref SL_STATUS_NULL_POINTER (0x0022n) - The parameter is null pointer - * - \ref SL_STATUS_OK (0X000) - Success -******************************************************************************/ -sl_status_t sl_si91x_sio_unmask_shift_interrupt(en_sio_channels_t channel); - -/***************************************************************************/ /** - * @brief Read the common shift interrupt status. - * @pre Pre-condition: - * - \ref sl_si91x_sio_init() - * @param[in] channel - SIO channel to be selected \ref en_sio_channels_t - * @return returns shift interrupt status -******************************************************************************/ -uint32_t sl_si91x_sio_shift_interrupt_status(void); - -/***************************************************************************/ /** - * @brief Select edge of the clock cycle for sampling bits. - * @pre Pre-condition: - * - \ref sl_si91x_sio_init() - * @param[in] channel - SIO channel to be selected \ref en_sio_channels_t - * @param[in] edge_sel - Select the edge for bit sample to start \ref edge_select_t - * - Positive edge: 0 - * - Negative edge: 1 - * @return returns status 0 if successful, - * else error code as follows: - * - \ref SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument - * - \ref SL_STATUS_NULL_POINTER (0x0022n) - The parameter is null pointer - * - \ref SL_STATUS_OK (0X000) - Success -******************************************************************************/ -sl_status_t sl_si91x_sio_edge_select(en_sio_channels_t channel, edge_select_t edge_sel); - -/***************************************************************************/ /** - * @brief Read SIO buffer register. - * @pre Pre-condition: - * - \ref sl_si91x_sio_init() - * - \ref sl_si91x_sio_uart_init() - * - \ref sl_si91x_sio_uart_register_event_callback() - * - \ref sl_si91x_sio_uart_send() - * @param[in] channel - SIO channel to be selected \ref en_sio_channels_t - * @return returns data from buffer -******************************************************************************/ -uint32_t sl_si91x_sio_read_buffer(en_sio_channels_t channel); - -/***************************************************************************/ /** - * @brief Write into SIO buffer register. - * @pre Pre-condition: - * - \ref sl_si91x_sio_init() - * - \ref sl_si91x_sio_uart_init() - * - \ref sl_si91x_sio_uart_register_event_callback() - * - \ref sl_si91x_sio_uart_send() - * @param[in] channel - SIO channel to be selected \ref en_sio_channels_t - * @param[in] data - Data to be written to buffer - * @return returns status 0 if successful, - * else error code as follows: - * - \ref SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is an invalid argument - * - \ref SL_STATUS_NULL_POINTER (0x0022n) - The parameter is null pointer - * - \ref SL_STATUS_OK (0X000) - Success -******************************************************************************/ -sl_status_t sl_si91x_sio_write_buffer(en_sio_channels_t channel, uint32_t data); - -// ******** THE REST OF THE FILE IS DOCUMENTATION ONLY! *********************** -/// @addtogroup SIO Serial Input-Output -/// @{ -/// -/// @details -/// -/// -/// @n @section SIO_Intro Introduction -/// -/// -/// Serial Input/Output (SIO) refers to a method of data transfer where information is sent and received -/// sequentially, one bit at a time, over a single communication channel. This communication can occur between -/// different electronic devices, such as micro-controllers, sensors, or other components. -/// -/// Key features of SIO include: -/// -/// @li SIO Functionality is supported by Eight GPIO pins. -/// -/// @li Detects a 32-bit pattern on the input pins. -/// -/// @li SIO will transmit or receive the MSB First. -/// -/// @n @section SIO_Config Configuration -/// -/// Various parameters SPI bit order, SPI clock, MOSI channel, MISO channel, -/// SPI CS channel, bit length, SPI mode can be configured. -/// Various parameters UART baud rate, bit length, parity, receive channel selection, transmit -/// channel selection, stop bits can be configured with below given Enumerations. -/// -/// 1. @ref sl_sio_spi_event_t -/// -/// 2. @ref sl_sio_uart_event_t -/// -/// 3. @ref sl_sio_spi_mode_t -/// -/// 4. @ref sl_sio_spi_bit_width_t -/// -/// 5. @ref sl_sio_spi_msb_lsb_t -/// -/// 6. @ref sl_sio_spi_bit_length_t -/// -/// 7. @ref sl_sio_spi_parity_t -/// -/// 8. @ref sl_sio_spi_stop_bit_t -/// -/// @li For more information on configuring available parameters refer to the respective peripheral example readme document. -/// -/// @n @section SIO_Use Usage -/// -/// Data is transferred over SIO SPI after it has been initialized and configured. A callback -/// API is then called to register the callback at the moment of the event. Before transfer has -/// begin, chip select assert is to be done. In order to do this test, the MISO and MOSI pins must -/// be connected in loopback mode. -/// -/// After transfer completion, chip select de-assert is to be done using When the transfer complete event -/// is generated, it compares the sent and received data. -/// -/// 1. @ref sl_si91x_sio_spi_pin_initialization -/// -/// 2. @ref sl_si91x_sio_spi_init -/// -/// 3. @ref sl_si91x_sio_spi_register_event_callback -/// -/// 4. @ref sl_si91x_sio_spi_cs_assert -/// -/// 5. @ref sl_si91x_sio_spi_transfer -/// -/// 6. @ref sl_si91x_sio_spi_cs_deassert -/// -/// 7. @ref sl_si91x_sio_deinit -/// -/// Data is sent and received by SIO UART after it has been initiated and configured. A callback API is -/// then called to register the callback at the moment of the event. Subsequently, the transfer buffer will -/// transmit the required number of bytes, and the receive buffer will obtain the data bytes. It compares the -/// sent and received data when the receive complete event is created. -/// -/// 1. @ref sl_si91x_sio_uart_pin_initialization -/// -/// 2. @ref sl_si91x_sio_uart_init -/// -/// 2. @ref sl_si91x_sio_uart_register_event_callback -/// -/// 3. @ref sl_si91x_sio_uart_send -/// -/// 4. @ref sl_si91x_sio_uart_read -/// -/// 5. @ref sl_si91x_sio_deinit -/// -/** @} (end addtogroup PWM) */ - -#ifdef __cplusplus -} -#endif - -#endif ///< SL_SI91X_SIO_H -/**************************************************************************************************/ diff --git a/components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_usart.h b/components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_usart.h index a786171dd..8624bf852 100644 --- a/components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_usart.h +++ b/components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_usart.h @@ -95,7 +95,6 @@ typedef enum { SL_USART_DATA_BITS_6 = ARM_USART_DATA_BITS_6, ///< 6 data bits SL_USART_DATA_BITS_7 = ARM_USART_DATA_BITS_7, ///< 7 data bits SL_USART_DATA_BITS_8 = ARM_USART_DATA_BITS_8, ///< 8 data bits - SL_USART_DATA_BITS_9 = ARM_USART_DATA_BITS_9, ///< 9 data bits } usart_databits_typedef_t; /// @brief Parity selection @@ -394,7 +393,10 @@ uint32_t sl_si91x_usart_get_rx_data_count(sl_usart_handle_t usart_handle); * @param[in] usart_handle Pointer to the USART/UART driver * * @param[in] control_configuration pointer to the USART configurations -* +* @note +* control_configuration - This parameter is used to pass the respective peripheral configuration when +* USART_UC, UART_UC, ULP_UART_UC macros are disabled for particular instance. When this macros are enabled +* configuration are taken directly from the UC and this parameter is not considered. * @return status 0 if successful, else error code * - \ref SL_STATUS_BUSY (0x0004) - Busy ,already data transfer is going on * - \ref SL_STATUS_INVALID_PARAMETER (0x0021) - The parameter is invalid argument diff --git a/components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_watchdog_timer.h b/components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_watchdog_timer.h index 1bd6654f1..a29c2bebb 100644 --- a/components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_watchdog_timer.h +++ b/components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_watchdog_timer.h @@ -161,8 +161,7 @@ sl_status_t sl_si91x_watchdog_configure_clock(watchdog_timer_clock_config_t *tim * @brief This API configures watchdog timer parameters. * @details The configurable parameters are interrupt time (WDT restart time), * system reset time & window time (lower time stamp for WDT restart, if required). - * System reset time should be greater than interrupt time. - * And Interrupt time should be greater than window time, else API will give an error. + * Interrupt time should be greater than window time, else API will give an error. * * @pre Pre-conditions: * - \ref sl_si91x_watchdog_init_timer @@ -172,8 +171,8 @@ sl_status_t sl_si91x_watchdog_configure_clock(watchdog_timer_clock_config_t *tim * @return status 0 if successful, else error code as follows: * - \ref SL_STATUS_INVALID_PARAMETER (0x0021) - Timer configuration structure members have invalid values, * for members \ref watchdog_timer_config_t - * - \ref SL_STATUS_INVALID_CONFIGURATION (0x0023) - Timer configuration structure member 'system_reset_time' is less than or equal to 'interrupt_time'. - * It should be greater than interrupt time of timer. + * - \ref SL_STATUS_INVALID_CONFIGURATION (0x0023) - Timer configuration structure member 'interrupt_time' is less than or equal to 'window_time'. + * It should be greater than window time of timer. * - \ref SL_STATUS_NULL_POINTER (0x0022) - The parameter is a null pointer * - \ref SL_STATUS_OK (0x0000) - Success, timer parameters configured properly *******************************************************************************/ @@ -199,7 +198,7 @@ sl_status_t sl_si91x_watchdog_register_timeout_callback(watchdog_timer_callback_ * @details This also referred as upper time-stamp for WDT restart * Its maximum value is 31. * @li Number of clock pulses for timer timeout = 2^(interrupt_time) - * @note The timeout value should be less than system-reset time and greater than window time. + * @note The 'interrupt time' value should be greater than window time. * * @pre Pre-conditions: * - \ref sl_si91x_watchdog_init_timer @@ -209,7 +208,7 @@ sl_status_t sl_si91x_watchdog_register_timeout_callback(watchdog_timer_callback_ * Number of clock pulses = 2^(interrupt_time), \ref time_delays_t * @return status 0 if successful, else error code as follows: * - \ref SL_STATUS_INVALID_PARAMETER (0x0021) - 'interrupt_time' parameter has an invalid value. - * - \ref SL_STATUS_INVALID_CONFIGURATION (0x0023) - 'interrupt_time' value is less than window time or greater than system reset time + * - \ref SL_STATUS_INVALID_CONFIGURATION (0x0023) - 'interrupt_time' value is less than window time. * - \ref SL_STATUS_OK (0x0000) - Successfully set watchdog timer timeout time value *******************************************************************************/ sl_status_t sl_si91x_watchdog_set_interrupt_time(time_delays_t interrupt_time); @@ -230,7 +229,7 @@ uint8_t sl_si91x_watchdog_get_interrupt_time(void); * @brief This API will set the Watchdog timer system-reset time duration. * @details Number of clock pulses for system reset time = 2^(system_reset_time). * Its maximum value is 31. - * This value should be greater than timer interrupt time & window time. + * This value should be greater than timer window time. * @pre Pre-conditions: * - \ref sl_si91x_watchdog_init_timer * - \ref sl_si91x_watchdog_configure_clock @@ -238,7 +237,7 @@ uint8_t sl_si91x_watchdog_get_interrupt_time(void); * Number of clock pulses = 2^(system_reset_time), \ref time_delays_t * @return status 0 if successful, else error code as follows: * - \ref SL_STATUS_INVALID_PARAMETER (0x0021) - 'system_reset_time' parameter has an invalid value. - * - \ref SL_STATUS_INVALID_CONFIGURATION (0x0023) - 'system_reset_time' value is less than window time or interrupt time + * - \ref SL_STATUS_INVALID_CONFIGURATION (0x0023) - 'system_reset_time' value is less than window time. * - \ref SL_STATUS_OK (0x0000) - Successfully set watchdog timer system-reset time value *******************************************************************************/ sl_status_t sl_si91x_watchdog_set_system_reset_time(time_delays_t system_reset_time); diff --git a/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_adc.c b/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_adc.c index 9ddc4793a..52e94c3d7 100644 --- a/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_adc.c +++ b/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_adc.c @@ -44,7 +44,6 @@ #ifndef MISC_CONFIG_MISC_CTRL1 #define MISC_CONFIG_MISC_CTRL1 *(volatile uint32_t *)(0x46008000 + 0x44) #endif // MISC_CONFIG_MISC_CTRL1 -#define SOC_PLL_LIMIT 120000000 // Limit for soc pll clock. #define MAX_SAMPLE_RATE 2500000 // Maximum sampling rate 2.5 Msps. #define MINIMUM_NUMBER_OF_CHANNEL 1 // Minimum number of channel enable #define MAXIMUM_NUMBER_OF_CHANNEL 16 // Maximum number of channel enable @@ -82,7 +81,6 @@ static sl_status_t convert_rsi_to_sl_error_code(rsi_error_t error); static sl_status_t validate_adc_parameters(sl_adc_config_t *adc_config); static sl_status_t validate_adc_channel_parameters(sl_adc_channel_config_t *adc_channel_config); static sl_status_t validate_adc_thrld_parameters(sl_adc_fifo_thrld_config_t *adc_fifo_threshold); -static sl_status_t validate_adc_ext_trigger_parameters(sl_adc_external_config_t *adc_external_trigger); static sl_status_t validate_adc_internal_parameters(sl_adc_internal_config_t *adc_internal_config); static sl_status_t sl_si91x_adc_channel_interrupt_clear(sl_adc_config_t adc_config, uint8_t channel_num); static sl_status_t sl_si91x_adc_configure_reference_voltage(float vref_value, float chip_voltage); @@ -122,16 +120,8 @@ sl_status_t sl_si91x_adc_configure_clock(sl_adc_clock_config_t *clock_configurat status = SL_STATUS_NULL_POINTER; break; } - if (clock_configuration->soc_pll_clock >= SOC_PLL_LIMIT) { - /*Configure the prefetch and registering when SOC clock is more than 120Mhz*/ - /*Configure the SOC PLL to 220MHz*/ - ICACHE2_ADDR_TRANSLATE_1_REG = BIT(21); //Icache registering when clk freq more than 120 - /*When set, enables registering in M4-TA AHB2AHB. This will have performance penalty. This has to be set above 100MHz*/ - MISC_CFG_SRAM_REDUNDANCY_CTRL = BIT(4); - MISC_CONFIG_MISC_CTRL1 |= BIT(4); //Enable Register ROM as clock frequency is 200 Mhz - } clock_configuration->division_factor = 1; - /* Switch ULP Pro clock to 90 MHZ */ + /* Switch ULP Pro clock to 90MHz */ RSI_ULPSS_ClockConfig(M4CLK, adc_clock, clock_configuration->division_factor, odd_divfactor); } while (false); return status; @@ -364,25 +354,6 @@ void sl_si91x_adc_unregister_event_callback(void) user_callback = NULL; } -/******************************************************************************* - * To configure external trigger as ULP_timer, ULP_gpio,M4_CT based on this - * it will detect edge and channel trigger selection will be happen. - * RSI errors are converted to the SL errors via convert_rsi_to_sl_error_code - * function. - ******************************************************************************/ -sl_status_t sl_si91x_adc_configure_external_trigger(sl_adc_external_config_t adc_external_trigger) -{ - sl_status_t status; - rsi_error_t error_status; - // Validate adc_external_trigger parameters. - status = validate_adc_ext_trigger_parameters(&adc_external_trigger); - if (status == SL_STATUS_OK) { - error_status = RSI_ADC_ExtTrigConfig(AUX_ADC_DAC_COMP, adc_external_trigger); - status = convert_rsi_to_sl_error_code(error_status); - } - return status; -} - /******************************************************************************* * To configure the ADC sampling rate for ADC channels. * It will set channel offset value and channel frequency for each channel to set the @@ -863,42 +834,6 @@ sl_status_t sl_si91x_adc_channel_disable(uint8_t channel_num) return status; } -/******************************************************************************* - * To read the external trigger status of ADC. - * RSI errors are converted to the SL errors via convert_rsi_to_sl_error_code - * function. - ******************************************************************************/ -sl_status_t sl_si91x_adc_get_external_trigger_status(sl_adc_external_config_t adc_external_trigger, - uint8_t *ext_trigger) -{ - sl_status_t status; - // Validate adc_external_trigger parameters. - status = validate_adc_ext_trigger_parameters(&adc_external_trigger); - if (status == SL_STATUS_OK) { - *ext_trigger = RSI_ADC_ExtTrigStatusRead(AUX_ADC_DAC_COMP, adc_external_trigger); - status = SL_STATUS_OK; - } - return status; -} - -/******************************************************************************* - * To clear the external trigger status. - * RSI errors are converted to the SL errors via convert_rsi_to_sl_error_code - * function. - ******************************************************************************/ -sl_status_t sl_si91x_adc_clear_external_trigger(sl_adc_external_config_t adc_external_trigger) -{ - sl_status_t status; - // Validate adc_external_trigger parameters. - status = validate_adc_ext_trigger_parameters(&adc_external_trigger); - if (status == SL_STATUS_OK) { - RSI_ADC_ExtTrigStatusClear(AUX_ADC_DAC_COMP, adc_external_trigger); - // In rsi not returning RSI_OK, so that we passing SL_STATUS_OK here. - status = SL_STATUS_OK; - } - return status; -} - /******************************************************************************* * To Unmask the ADC channel. * The interrupt will clear when static mode interrupt will detect, threshold @@ -1070,41 +1005,6 @@ static sl_status_t validate_adc_channel_parameters(sl_adc_channel_config_t *adc_ return status; } -/******************************************************************************* - * To validate the parameters of ADC external trigger and build a 32 bit integer - * It takes pointer to ADC external trigger configuration structure and pointer - * to the uint32_t as argument and builds the integer using the validations and - * 'OR' operation. - * According to the values in external trigger configuration structure, it - * performs the 'OR' operation of the values. - ******************************************************************************/ -static sl_status_t validate_adc_ext_trigger_parameters(sl_adc_external_config_t *adc_external_trigger) -{ - sl_status_t status; - do { - //Validate ADC external trigger type. - if (adc_external_trigger->trigger_type >= SL_ADC_EXT_TRIGGER_TYPE_LAST) { - status = SL_STATUS_INVALID_PARAMETER; - break; - } - // Validate ADC external trigger detection and edge trigger. - if ((adc_external_trigger->trigger_num >= SL_ADC_EXT_TRIGGER_LAST) - || (adc_external_trigger->detection_edge_sel >= SL_ADC_EXT_TRIGGER_EDGE_LAST)) { - status = SL_STATUS_INVALID_PARAMETER; - break; - } - // Validate ADC external trigger selection and channel_id. - if ((adc_external_trigger->trigger_sel_val >= MAXIMUM_CHANNEL_ID) - || (adc_external_trigger->trigger_sel >= SL_ADC_EXT_TRIGGER_SEL_LAST)) { - status = SL_STATUS_INVALID_PARAMETER; - break; - } - // Returns SL_STATUS_OK if the parameter are appropriate - status = SL_STATUS_OK; - } while (false); - return status; -} - /******************************************************************************* * To validate the parameters of ADC internal parameters and build a 32 bit integer * It takes pointer to ADC internal parameters configuration structure and pointer diff --git a/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_bjt_temperature_sensor.c b/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_bjt_temperature_sensor.c index 3b926bb86..28d83c28c 100644 --- a/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_bjt_temperature_sensor.c +++ b/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_bjt_temperature_sensor.c @@ -40,7 +40,7 @@ #define VREF_VALUE 2.61f // default reference voltage #define BOD_TEST_SEL_VALUE 3 // BOD test selection value #define LOAD_BJT_TEMP 25 // load bjt temperature -#define SAMPLING_RATE 50000 // sampling rate value for adc +#define SAMPLING_RATE 9000 // sampling rate value for adc #define CHANNEL_NUMBER 0 // channel number for adc #define POS_IP_OPAMP 20 // Positive input to ADC using OPAMP #define POS_IP_BJT 23 // positive input to ADC using bjt temperature sensor @@ -68,7 +68,7 @@ static float adc_output_bjt[CHANNEL_SAMPLE_LENGTH] = { 0 }; static float adc_output_bg[CHANNEL_SAMPLE_LENGTH] = { 0 }; adc_config_t sl_bjt_config = { SL_ADC_STATIC_MODE, NUMBER_OF_CHANNELS }; -adc_ch_config_t sl_bjt_channel_config = { .input_type[0] = CHANNEL_NUMBER, +adc_ch_config_t sl_bjt_channel_config = { .input_type[0] = SL_ADC_SINGLE_ENDED, .sampling_rate[0] = SAMPLING_RATE, .num_of_samples[0] = CHANNEL_SAMPLE_LENGTH }; diff --git a/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_config_timer.c b/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_config_timer.c index 0db7a0691..648539607 100644 --- a/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_config_timer.c +++ b/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_config_timer.c @@ -31,7 +31,7 @@ #include "sl_si91x_config_timer_config.h" #include "rsi_rom_ct.h" #include "rsi_rom_clks.h" - +#include "clock_update.h" /******************************************************************************* *************************** DEFINES / MACROS ******************************** ******************************************************************************/ @@ -298,6 +298,27 @@ sl_status_t sl_si91x_config_timer_set_match_count(sl_config_timer_mode_t mode, return status; } +/******************************************************************************* +* @brief: API to calculate and return the match value of the timer for desired time period +*******************************************************************************/ +sl_status_t sl_si91x_config_timer_get_match_value(uint32_t time_period_in_us, uint32_t *match_value) +{ + uint32_t ct_base_clock; + // Get CT base clock + ct_base_clock = RSI_CLK_GetBaseClock(M4_CT); + ct_base_clock /= 1000000; + // Validate the time period by comparing with maximum count of 16-bit counter and the CT base clock. + // For example, for a CT base clock of 32MHz, the maximum time period achieved is 2047us. + // For a CT base clock of 180MHz, the maximum time period achieved is 364us. + // The counter can be loaded multiple times if requires a higher time period. + if (time_period_in_us > (MAX_COUNT_VALUE_16BIT / ct_base_clock)) { + return SL_STATUS_INVALID_COUNT; + } + // Calculate match value + *match_value = ct_base_clock * time_period_in_us; // time period in microseconds + return SL_STATUS_OK; +} + /******************************************************************************* * @brief:sets initial value for counter-0 or counter-1 ,as per ct MODE * @@ -481,10 +502,10 @@ sl_status_t sl_si91x_config_timer_configure_action_event(sl_config_action_event_ break; } // Validating event value - if ((event_config_handle->and_event_counter0 >= SL_EVENT_LAST) - || (event_config_handle->or_event_counter0 >= SL_EVENT_LAST) - || (event_config_handle->and_event_counter1 >= SL_EVENT_LAST) - || (event_config_handle->or_event_counter1 >= SL_EVENT_LAST)) { + if ((event_config_handle->and_event_counter0 >= SL_CT_EVENT_LAST) + || (event_config_handle->or_event_counter0 >= SL_CT_EVENT_LAST) + || (event_config_handle->and_event_counter1 >= SL_CT_EVENT_LAST) + || (event_config_handle->or_event_counter1 >= SL_CT_EVENT_LAST)) { status = SL_STATUS_INVALID_PARAMETER; break; } @@ -569,7 +590,7 @@ sl_status_t sl_si91x_config_timer_select_action_event(sl_config_timer_action_t a break; } // Validating select-event value - if ((select_event_counter0 >= SL_EVENT_LAST) || (select_event_counter1 >= SL_EVENT_LAST)) { + if ((select_event_counter0 >= SL_CT_EVENT_LAST) || (select_event_counter1 >= SL_CT_EVENT_LAST)) { status = SL_STATUS_INVALID_PARAMETER; break; } diff --git a/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_crc.c b/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_crc.c index ac10643f6..a8af8d2db 100644 --- a/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_crc.c +++ b/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_crc.c @@ -189,7 +189,7 @@ sl_status_t sl_si91x_crc_write_data(sl_crc_params_t *pCRCParams, uint32_t data, * sl_crc_params_t *pCRCParams, * uint32_t crc) * @brief This API is used to monitor the CRC Calculation status and the - *returns the CRC Value. + * returns the CRC Value. *******************************************************************************/ sl_status_t sl_si91x_crc_monitor_crc_calc(sl_crc_params_t *pCRCParams, uint32_t *crc) { @@ -259,7 +259,7 @@ sl_status_t sl_si91x_crc_enable(void) /******************************************************************************* * @fn sl_status_t sl_si91x_crc_disable(void) - * @brief Enables the CRC peripheral. + * @brief Disables the CRC peripheral. * * This function disable the CRC peripheral by disabling its clock. ******************************************************************************/ diff --git a/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_driver_gpio.c b/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_driver_gpio.c index d02720eb6..8794a0ebb 100644 --- a/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_driver_gpio.c +++ b/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_driver_gpio.c @@ -198,14 +198,16 @@ sl_status_t sl_gpio_set_configuration(sl_si91x_gpio_pin_config_t pin_config) case SL_GPIO_PORT_B: case SL_GPIO_PORT_C: case SL_GPIO_PORT_D: + status = sl_gpio_validation(&pin_config.port_pin); + if (status != SL_STATUS_OK) { + return status; + } // Check if the GPIO pad is selected and it's not NO PAD. if (m4_gpio_pad[(pin_config.port_pin.port * MAX_GPIO_PORT_PIN) + pin_config.port_pin.pin] != GPIO_PAD_SELECT_NO_PAD) { // Check if the GPIO pad is selected and not PAD_SELECT_9. if (m4_gpio_pad[(pin_config.port_pin.port * MAX_GPIO_PORT_PIN) + pin_config.port_pin.pin] != PAD_SELECT_9) { - if ((pin_config.port_pin.pin >= HOST_PAD_MIN && pin_config.port_pin.pin <= HOST_PAD_MAX) - || ((pin_config.port_pin.port == SL_GPIO_PORT_B && pin_config.port_pin.pin >= GPIO_PIN_NUMBER9) - && (pin_config.port_pin.port == SL_GPIO_PORT_B && pin_config.port_pin.pin <= GPIO_PIN_NUMBER14))) { + if (SL_GPIO_VALIDATE_HOST_PIN(pin_config.port_pin.port, pin_config.port_pin.pin)) { status = sl_si91x_gpio_driver_enable_host_pad_selection( m4_gpio_pad[(pin_config.port_pin.port * MAX_GPIO_PORT_PIN) + pin_config.port_pin.pin]); if (status != SL_STATUS_OK) { @@ -783,7 +785,7 @@ sl_status_t sl_si91x_gpio_driver_enable_pad_selection(uint8_t gpio_padnum) sl_status_t sl_si91x_gpio_driver_enable_host_pad_selection(uint8_t gpio_num) { // Check if the GPIO pin number exceeds the maximum allowed value. - if (gpio_num >= HOST_PAD_MIN && gpio_num <= HOST_PAD_MAX) { + if (!(gpio_num >= HOST_PAD_MIN && gpio_num <= HOST_PAD_MAX)) { return SL_STATUS_INVALID_PARAMETER; } // Enable host pad selection for the GPIO pin. @@ -1856,12 +1858,6 @@ void PIN_IRQ6_Handler(void) ******************************************************************************/ void PIN_IRQ7_Handler(void) { -// A temporary fix (delay of 46 micro seconds) to supress dual interrupts with rising edge. -#ifdef SL_SI91x_DUAL_INTERRUPTS_ERRATA - for (int i = 0; i < 1000; i++) - __asm__("nop;"); -#endif // SL_SI91x_DUAL_INTERRUPTS_ERRATA - sl_gpio_driver_clear_interrupts(PIN_INTR_7); gpio_callback_function_pointer[PIN_INTR_7](PIN_INTR_7); } @@ -1909,7 +1905,9 @@ void UULP_PIN_IRQ_Handler(void) sl_si91x_gpio_driver_clear_uulp_interrupt(UULP_INTR_5); flag = PIN_INTR_4; } - gpio_uulp_pin_int_callback_fptr[flag](flag); + if (gpio_uulp_pin_int_callback_fptr[flag] != NULL) { + gpio_uulp_pin_int_callback_fptr[flag](flag); + } } /******************************************************************************* @@ -1967,6 +1965,7 @@ void ULP_GROUP_IRQ_Handler(void) sl_si91x_gpio_driver_clear_ulp_group_interrupt(GROUP_INT_2); flag = GROUP_INT_2; } + gpio_ulp_group_int_callback_fptr[flag](flag); } diff --git a/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_gspi.c b/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_gspi.c index 4a89dd3e7..df42838c5 100644 --- a/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_gspi.c +++ b/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_gspi.c @@ -235,7 +235,7 @@ static sl_status_t sli_si91x_gspi_configure_power_mode(sl_gspi_handle_t gspi_han * It configures GSPI mode, Bit width (frame length), master mode, bitrate, * swap read, swap write and slave select mode. * - GSPI Mode, Value: GSPI_MODE_0 / GSPI_MODE_3 - * - Bit width (frame length), Value: 4 to 16 + * - Bit width (frame length), Value: 1 to 16 * - Master Mode, Value: GSPI_MASTER_ACTIVE / GSPI_MASTER_INACTIVE * - Bitrate, Value: Less than 40000000 * - Swap Read, Value: ENABLE / DISABLE @@ -275,7 +275,10 @@ sl_status_t sl_si91x_gspi_set_configuration(sl_gspi_handle_t gspi_handle, if (status != SL_STATUS_OK) { break; } - + if (control_configuration->bit_width == MAX_BIT_WIDTH) { + // For 16 data width, it is required to set the data width as 0. + control_configuration->bit_width = 0; + } input_mode = (control_configuration->clock_mode | SL_GSPI_MASTER_ACTIVE | control_configuration->slave_select_mode | ARM_SPI_DATA_BITS(control_configuration->bit_width)); // CMSIS API for GSPI control is called and the arm error code returned from @@ -699,7 +702,7 @@ static sl_status_t validate_control_parameters(sl_gspi_control_config_t *control } // If the bit width is not in range i.e., between 0 and 16, // returns the error code. - if ((control_configuration->bit_width == MIN_BIT_WIDTH) || (control_configuration->bit_width >= MAX_BIT_WIDTH)) { + if ((control_configuration->bit_width == MIN_BIT_WIDTH) || (control_configuration->bit_width > MAX_BIT_WIDTH)) { status = SL_STATUS_INVALID_PARAMETER; break; } diff --git a/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_i2c.c b/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_i2c.c index 897108ce5..2731b75d6 100644 --- a/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_i2c.c +++ b/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_i2c.c @@ -149,6 +149,7 @@ sl_i2c_status_t sl_i2c_driver_init(sl_i2c_instance_t i2c_instance, const sl_i2c_ // will return an error code, also validating members of i2c-config // structure. if ((p_user_config == NULL) || (i2c_instance >= SL_I2C_LAST) || (p_user_config->mode > SL_I2C_FOLLOWER_MODE) + || (p_user_config->operating_mode < SL_I2C_STANDARD_MODE) || (p_user_config->operating_mode >= SL_I2C_OPERATING_MODE_LAST) || (p_user_config->transfer_type >= SL_I2C_TRANFER_TYPE_LAST)) { i2c_status = SL_I2C_INVALID_PARAMETER; @@ -170,7 +171,6 @@ sl_i2c_status_t sl_i2c_driver_init(sl_i2c_instance_t i2c_instance, const sl_i2c_ i2c = (I2C0_Type *)i2c_addr(i2c_instance); // Initializing I2c clock i2c_clock_init(i2c); - if ((p_user_config->operating_mode == SL_I2C_FAST_PLUS_MODE) || (p_user_config->operating_mode == SL_I2C_HIGH_SPEED_MODE)) { if (i2c_instance == SL_I2C2) { @@ -179,7 +179,6 @@ sl_i2c_status_t sl_i2c_driver_init(sl_i2c_instance_t i2c_instance, const sl_i2c_ RSI_ULPSS_UlpProcClkConfig(ULPCLK, ULP_PROC_SOC_CLK, ULP_PRO_CLOCK_DIV_FACTOR, DELAY_DISABLE); } } - // Read the current M4 Core clock sl_si91x_clock_manager_m4_get_core_clk_src_freq(&config.freq); // Registering callback as per transfer type diff --git a/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_ro_temperature_sensor.c b/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_ro_temperature_sensor.c deleted file mode 100644 index 10f2d145a..000000000 --- a/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_ro_temperature_sensor.c +++ /dev/null @@ -1,286 +0,0 @@ -/***************************************************************************/ /** - * @file sl_si91x_ro_temperature_sensor.c - * @brief RO temperature sensor API implementation - ******************************************************************************* - * # License - * Copyright 2023 Silicon Laboratories Inc. www.silabs.com - ******************************************************************************* - * - * SPDX-License-Identifier: Zlib - * - * The licensor of this software is Silicon Laboratories Inc. - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - * - ******************************************************************************/ -#include "sl_si91x_ro_temperature_sensor.h" -#include "rsi_ipmu.h" - -/******************************************************************************* - *************************** DEFINES / MACROS ******************************* - ******************************************************************************/ -#define SIGN_BIT_POSITION 10 // Temperature read in signed format bit -#define NOMINAL_TEMP 25 // Nominal temperature value -#define ARRAY_SIZE 31 // Array size -#define MSB_BIT_POSITION 31 // MSB bit for sign check -#define MAX_NOMINAL_VALUE 128 // Maximum nominal value -#define KNOWN_TEMP 255 // Known temperature -#define MAX_COUNT_VALUE 1024 // Maximum count value -#define NEG_VALUE 1.3437f // value multiplied for conversion to negative -/******************************************************************************* - *************************** Global VARIABLES ******************************** - ******************************************************************************/ - -/******************************************************************************* - *************************** LOCAL VARIABLES ******************************** - ******************************************************************************/ -static int16_t temp_decimal_value; - -/******************************************************************************* - ************************** Global function Definitions ******************** - ******************************************************************************/ - -/******************************************************************************* - ********************* LOCAL FUNCTION PROTOTYPES *************************** - ******************************************************************************/ -static void temp_conversion(uint32_t temp); - -/****************************************************************************** - * Sets the count of reference clock on which ptat clock counts. - *****************************************************************************/ -sl_status_t sl_si91x_ro_temperature_set_count(uint32_t count) -{ - sl_status_t status; - // Returns invalid parameter if count of reference count is greater than MAX_COUNT_VALUE - if (count > MAX_COUNT_VALUE) { - status = SL_STATUS_INVALID_PARAMETER; - } else { - // set the count of reference clock on which ptat clock counts - RSI_TS_SetCntFreez(MCU_TEMP, count); - status = SL_STATUS_OK; - } - return status; -} - -/****************************************************************************** - * Selects the reference clock (use RO kHz clock (or) MCU FSM clock) to the temperature sensor. - *****************************************************************************/ -sl_status_t sl_si91x_ro_temperature_select_reference_clock(sl_ro_reference_clock_t ref_clk) -{ - sl_status_t status; - // Returns invalid parameter if reference clock selection is not proper - if (ref_clk >= SL_RO_CLK_LAST) { - status = SL_STATUS_INVALID_PARAMETER; - } else { - // Selects the reference clock based on sl_ro_reference_clock_t selection - RSI_TS_RefClkSel(MCU_TEMP, ref_clk); - status = SL_STATUS_OK; - } - return status; -} - -/****************************************************************************** - * Used to enable/disable the temperature sensor. It is a self clearing register. - *****************************************************************************/ -sl_status_t sl_si91x_ro_temperature_enable(sl_ro_temperature_state_t state) -{ - sl_status_t status; - // Returns invalid parameter if other than enabling (or) disabling is choosen - if (state >= SL_RO_TEMPERATURE_LAST) { - status = SL_STATUS_INVALID_PARAMETER; - } else { - // Enable/Disable the sensor based on sl_ro_temperature_t selection - RSI_TS_Enable(MCU_TEMP, state); - status = SL_STATUS_OK; - } - return status; -} - -/****************************************************************************** - * Used to set the calibrated temperature value of the sensor. By default it is set to 25. - *****************************************************************************/ -sl_status_t sl_si91x_ro_temperature_nominal(uint32_t value) -{ - sl_status_t status; - // Returns invalid parameter if calibrated temperature value > MAX_NOMINAL_VALUE - if (value > MAX_NOMINAL_VALUE) { - status = SL_STATUS_INVALID_PARAMETER; - } else { - // Calibrates temperature value of sensor - RSI_TS_Config(MCU_TEMP, value); - status = SL_STATUS_OK; - } - return status; -} - -/****************************************************************************** - * Reads the temperature value in signed format. - *****************************************************************************/ -sl_status_t sl_si91x_ro_temperature_read(int32_t *temperature) -{ - sl_status_t status; - uint32_t temp_read, f2_count; - int32_t temp; - // Validates the null pointer, if true returns error code - if (temperature == NULL) { - status = SL_STATUS_NULL_POINTER; - } else { - // Reads the temperature from sensor - temp = (int32_t)RSI_TS_ReadTemp(MCU_TEMP); - if (temp & BIT(SIGN_BIT_POSITION)) { - // read the f2 count - f2_count = RSI_TS_GetPtatClkCnt(MCU_TEMP); - // subtract f2_nominal count from f2_count NOTE:configure the f2_nominal - // temp_read=(f2-f2_nominal) - temp_read = (f2_count - RSI_IPMU_RO_TsEfuse()); - if (temp_read & BIT(MSB_BIT_POSITION)) { - temp_conversion(temp_read); - // calculate the negative temperature - *temperature = (int32_t)(NOMINAL_TEMP - (temp_decimal_value * NEG_VALUE)); - } - } else { - *temperature = temp; - } - status = SL_STATUS_OK; - } - return status; -} - -/****************************************************************************** - * Enable/Disable bjt based temperature updation. - *****************************************************************************/ -sl_status_t sl_si91x_ro_temperature_based_update(sl_ro_temperature_update_t enable) -{ - sl_status_t status; - // Returns invalid parameter if temperature update based on RO is >= SL_RO_TEMP_BJT_UPDATE_LAST - if (enable >= SL_RO_TEMP_BJT_UPDATE_LAST) { - status = SL_STATUS_INVALID_PARAMETER; - } else { - // Enables the temperature update based on RO calculation - RSI_TS_RoBjtEnable(MCU_TEMP, enable); - status = SL_STATUS_OK; - } - return status; -} - -/****************************************************************************** - * Updation of RO temperature through SPI. - *****************************************************************************/ -sl_status_t sl_si91x_ro_temperature_load(uint8_t temperature) -{ - sl_status_t status; - // Returns invalid parameter if known temperature >= KNOWN_TEMP - if (temperature >= KNOWN_TEMP) { - status = SL_STATUS_INVALID_PARAMETER; - } else { - // Read the temperature value for spi based - RSI_TS_LoadBjt(MCU_TEMP, temperature); - status = SL_STATUS_OK; - } - return status; -} - -/****************************************************************************** - * Reads the count of f1 clock cycles. - *****************************************************************************/ -sl_status_t sl_si91x_ro_temperature_get_reference_clk_count(uint32_t *ref_count) -{ - sl_status_t status; - // Validates the null pointer, if true returns error code - if (ref_count == NULL) { - status = SL_STATUS_NULL_POINTER; - } else { - // Reads the f1 clock cycles count - *ref_count = RSI_TS_GetRefClkCnt(MCU_TEMP); - status = SL_STATUS_OK; - } - return status; -} - -/****************************************************************************** - * Reads the count of f2 clock cycles. - *****************************************************************************/ -sl_status_t sl_si91x_ro_temperature_get_ptat_clk_count(uint32_t *ptat_count) -{ - sl_status_t status; - // Validates the null pointer, if true returns error code - if (ptat_count == NULL) { - status = SL_STATUS_NULL_POINTER; - } else { - // Reads the f2 clock cycles count - *ptat_count = RSI_TS_GetPtatClkCnt(MCU_TEMP); - status = SL_STATUS_OK; - } - return status; -} - -/****************************************************************************** - * Updates the temperature periodically based on trigger time selected - *****************************************************************************/ -sl_status_t sl_si91x_ro_temperature_periodic_update(sl_ro_temperature_periodic_check_t periodic_check, - sl_ro_temperature_trigger_time_t trigger_time) -{ - sl_status_t status; - // Validates periodic and trigger times and if true returns error code - if ((periodic_check >= SL_RO_TEMPERATURE_PERIODIC_LAST) || (trigger_time >= SL_RO_TEMPERATURE_TRIGGER_LAST)) { - status = SL_STATUS_INVALID_PARAMETER; - } else { - // Updates the temperature periodically - RSI_Periodic_TempUpdate(TIME_PERIOD, periodic_check, trigger_time); - status = SL_STATUS_OK; - } - return status; -} - -/****************************************************************************** - * Two's complement conversion function - *****************************************************************************/ -static void temp_conversion(uint32_t temp) -{ - int16_t base = 1; - char binary[ARRAY_SIZE], ones_comp[ARRAY_SIZE], twos_comp[ARRAY_SIZE]; - uint8_t i = 0, rem, carry = 1; - uint8_t num = 0; - temp_decimal_value = 0, base = 1; - while (temp > 0) { - binary[i] = temp % 2; - temp = temp / 2; - i++; - } - for (i = 0; i < MSB_BIT_POSITION; i++) { - if (binary[i] == 0) - ones_comp[i] = 1; - else - ones_comp[i] = 0; - } - for (i = 0; i < MSB_BIT_POSITION; i++) { - if (ones_comp[i] == 1 && (carry == 1)) { - twos_comp[i] = 0; - } else if ((ones_comp[i] == 0) && (carry == 1)) { - twos_comp[i] = 1; - carry = 0; - } else { - twos_comp[i] = ones_comp[i]; - } - } - for (i = 0; i < MSB_BIT_POSITION; i++) { - num = twos_comp[i]; - rem = num % 10; - temp_decimal_value = (int16_t)(temp_decimal_value + rem * base); - base = base * 2; - } -} diff --git a/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_sio.c b/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_sio.c deleted file mode 100644 index d9587fd72..000000000 --- a/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_sio.c +++ /dev/null @@ -1,1186 +0,0 @@ -/***************************************************************************/ /** -* @file sl_si91x_sio.c -* @brief SIO API implementation -******************************************************************************* -* # License -* Copyright 2023 Silicon Laboratories Inc. www.silabs.com -******************************************************************************* -* -* SPDX-License-Identifier: Zlib -* -* The licensor of this software is Silicon Laboratories Inc. -* -* This software is provided 'as-is', without any express or implied -* warranty. In no event will the authors be held liable for any damages -* arising from the use of this software. -* -* Permission is granted to anyone to use this software for any purpose, -* including commercial applications, and to alter it and redistribute it -* freely, subject to the following restrictions: -* -* 1. The origin of this software must not be misrepresented; you must not -* claim that you wrote the original software. If you use this software -* in a product, an acknowledgment in the product documentation would be -* appreciated but is not required. -* 2. Altered source versions must be plainly marked as such, and must not be -* misrepresented as being the original software. -* 3. This notice may not be removed or altered from any source distribution. -* -******************************************************************************/ -#include "sl_si91x_sio.h" -#include "sl_si91x_sio_config.h" -#include "sl_si91x_peripheral_gpio.h" -#include "rsi_rom_clks.h" -#include "clock_update.h" -/******************************************************************************* - *************************** LOCAL MACROS *********************************** - ******************************************************************************/ -#define CS_NUM_MIN 0 ///< Minimum chip select number -#define OUTPUT 1 ///< Output value set -#define CLOCK_TYPE 2 ///< Maximum types of clocks -#define PATTERN_MATCH 2 ///< Maximum pattern match number -#define FLOW_CONTROL 2 ///< Maximum flow control number -#define REVERSE_LOAD 2 ///< Maximum reverse load number -#define EDGE_SELECT 2 ///< Maximum edge select number -#define FLAG 3 ///< Maximum interrupt flag -#define ULP_PORT 4 ///< GPIO ULP port -#define ULP_MODE 6 ///< ULP GPIO mode -#define SIO_CHANNEL 7 ///< SIO maximum channel -#define CS_NUM_MAX 7 ///< Maximum chip select number -#define HOST_MIN 24 ///< GPIO host pad minimum pin number -#define HOST_MAX 31 ///< GPIO host pad maximum pin number -#define MAX_GPIO 64 ///< maximum GPIO pins -#define SIO_RELEASE_VERSION 0 ///< SIO Release version -#define SIO_SQA_VERSION 0 ///< SIO SQA version -#define SIO_DEV_VERSION 2 ///< SIO Developer version -#define SLI_SIO_INTERRUPT SIO_IRQn ///< SIO interrupt handler - -/******************************************************************************* - *************************** Global VARIABLES ******************************** - ******************************************************************************/ - -/******************************************************************************* - *************************** LOCAL VARIABLES ******************************** - ******************************************************************************/ -sl_sio_i2s_callback_t i2s_user_callback; -sl_sio_spi_callback_t spi_user_callback; -sl_sio_uart_callback_t uart_user_callback; -stc_sio_uart_config_t UartInitstc = { 0 }; - -/******************************************************************************* - ********************* LOCAL FUNCTION PROTOTYPES *************************** - ******************************************************************************/ -static sl_status_t convert_rsi_to_sl_error_code(rsi_error_t error); -static void callback_event_handler(en_sio_spi_events_t en_event); - -/******************************************************************************* - ************************** Global function Definitions ******************** - ******************************************************************************/ - -/******************************************************************************* - * This API initializes SIO gpio's and enables SIO module clock - ******************************************************************************/ -sl_status_t sl_si91x_sio_init(void) -{ - sl_status_t status; - rsi_error_t error_status; - // Initialize the SIO - error_status = RSI_SIO_Initialization(); - if (error_status == RSI_OK) { - status = SL_STATUS_OK; // Returns status OK if no error occurs - } else { - status = SL_STATUS_FAIL; // Returns status error code - } - return status; -} - -/******************************************************************************* - * This API is used to De-initialize SIO module - ******************************************************************************/ -void sl_si91x_sio_deinit(void) -{ - sl_si91x_sio_spi_unregister_event_callback(); - sl_si91x_sio_uart_unregister_event_callback(); - RSI_CLK_PeripheralClkDisable3(M4CLK, (SGPIO_PCLK_ENABLE)); -} - -/******************************************************************************* - * This API initializes SIO-SPI i.e SPI mode, bit length, bit order, SIO - * frequency and the SIO channels for the SPI transfer lines. The actions to be - * performed before SPI initialization is: - * - Initialize SIO using @ref sl_si91x_sio_init() API - ******************************************************************************/ -sl_status_t sl_si91x_sio_spi_init(sl_sio_spi_config_t *configuration) -{ -#if (SIO_UC == 1) - configuration = &pstcSpiConfigUc; -#endif - sl_status_t status; - rsi_error_t error_status; - do { - if (configuration == NULL) { - status = SL_STATUS_NULL_POINTER; // Returns null pointer status code - break; - } - // Initialize the SIO-SPI - error_status = RSI_SIO_InitSpi(SIO, configuration); - status = convert_rsi_to_sl_error_code(error_status); // Returns status code - } while (false); - return status; -} - -/******************************************************************************* - * This API is used for initialize sio spi pins and clock. The formal argument passed - * takes pointer to structure of type \ref sl_sio_uart_t. This holds the spi cs, clk, - * mosi, miso pins configuration. The members are assigned to SL macros defined in - * sl_sio_board.h. The SL macros are integrated to RTE macros present in RTE device file. - ******************************************************************************/ -sl_status_t sl_si91x_sio_spi_pin_initialization(sl_sio_spi_t *sio_spi_init) -{ - sl_status_t status; - do { - // Validates the null pointer, if true returns error code - if (sio_spi_init == NULL) { - status = SL_STATUS_NULL_POINTER; - break; - } - // sio spi chip select pin muxing - if (sio_spi_init->spi_cs_pin >= GPIO_MAX_PIN) { - sl_si91x_gpio_enable_ulp_pad_receiver((uint8_t)(sio_spi_init->spi_cs_pin - GPIO_MAX_PIN)); - sl_gpio_set_pin_mode(ULP_PORT, (uint8_t)(sio_spi_init->spi_cs_pin - GPIO_MAX_PIN), ULP_GPIO_MODE_6, OUTPUT); - } else { - sl_si91x_gpio_enable_pad_receiver(sio_spi_init->spi_cs_pin); - } - if (sio_spi_init->spi_cs_pin >= (HOST_PAD_GPIO_MIN - 1) && sio_spi_init->spi_cs_pin <= (HOST_PAD_GPIO_MAX + 1)) { - sl_si91x_gpio_enable_pad_selection(sio_spi_init->spi_cs_pin); - } else { - sl_si91x_gpio_enable_pad_selection(sio_spi_init->spi_cs_pad); - } - sl_gpio_set_pin_mode(sio_spi_init->spi_cs_port, sio_spi_init->spi_cs_pin, sio_spi_init->spi_cs_mux, OUTPUT); - // sio spi clock pin muxing - if (sio_spi_init->spi_clk_pin >= GPIO_MAX_PIN) { - sl_si91x_gpio_enable_ulp_pad_receiver((uint8_t)(sio_spi_init->spi_clk_pin - GPIO_MAX_PIN)); - sl_gpio_set_pin_mode(ULP_PORT, (uint8_t)(sio_spi_init->spi_clk_pin - GPIO_MAX_PIN), ULP_GPIO_MODE_6, OUTPUT); - } else { - sl_si91x_gpio_enable_pad_receiver(sio_spi_init->spi_clk_pin); - } - if (sio_spi_init->spi_clk_pin >= (HOST_PAD_GPIO_MIN - 1) && sio_spi_init->spi_clk_pin <= (HOST_PAD_GPIO_MAX + 1)) { - sl_si91x_gpio_enable_pad_selection(sio_spi_init->spi_clk_pin); - } else { - sl_si91x_gpio_enable_pad_selection(sio_spi_init->spi_clk_pad); - } - sl_gpio_set_pin_mode(sio_spi_init->spi_clk_port, sio_spi_init->spi_clk_pin, sio_spi_init->spi_clk_mux, OUTPUT); - // sio spi mosi pin muxing - if (sio_spi_init->spi_mosi_pin >= GPIO_MAX_PIN) { - sl_si91x_gpio_enable_ulp_pad_receiver((uint8_t)(sio_spi_init->spi_mosi_pin - GPIO_MAX_PIN)); - sl_gpio_set_pin_mode(ULP_PORT, (uint8_t)(sio_spi_init->spi_mosi_pin - GPIO_MAX_PIN), ULP_GPIO_MODE_6, OUTPUT); - } else { - sl_si91x_gpio_enable_pad_receiver(sio_spi_init->spi_mosi_pin); - } - if (sio_spi_init->spi_mosi_pin >= (HOST_PAD_GPIO_MIN - 1) - && sio_spi_init->spi_mosi_pin <= (HOST_PAD_GPIO_MAX + 1)) { - sl_si91x_gpio_enable_pad_selection(sio_spi_init->spi_mosi_pin); - } else { - sl_si91x_gpio_enable_pad_selection(sio_spi_init->spi_mosi_pad); - } - sl_gpio_set_pin_mode(sio_spi_init->spi_mosi_port, sio_spi_init->spi_mosi_pin, sio_spi_init->spi_mosi_mux, OUTPUT); - // sio spi miso pin muxing - if (sio_spi_init->spi_miso_pin >= GPIO_MAX_PIN) { - sl_si91x_gpio_enable_ulp_pad_receiver((uint8_t)(sio_spi_init->spi_miso_pin - GPIO_MAX_PIN)); - sl_gpio_set_pin_mode(ULP_PORT, (uint8_t)(sio_spi_init->spi_miso_pin - GPIO_MAX_PIN), ULP_GPIO_MODE_6, OUTPUT); - } else { - sl_si91x_gpio_enable_pad_receiver(sio_spi_init->spi_miso_pin); - } - if (sio_spi_init->spi_miso_pin >= (HOST_PAD_GPIO_MIN - 1) - && sio_spi_init->spi_miso_pin <= (HOST_PAD_GPIO_MAX + 1)) { - sl_si91x_gpio_enable_pad_selection(sio_spi_init->spi_miso_pin); - } else { - sl_si91x_gpio_enable_pad_selection(sio_spi_init->spi_miso_pad); - } - sl_gpio_set_pin_mode(sio_spi_init->spi_miso_port, sio_spi_init->spi_miso_pin, sio_spi_init->spi_miso_mux, OUTPUT); - // SIO CLock enable - RSI_SIO_ClockEnable(); - status = SL_STATUS_OK; - } while (false); - return status; -} - -/******************************************************************************* - * This API asserts the SIO SPI chip select - * The actions to be performed before SPI chip select assert are: - * - Initialize SIO using @ref sl_si91x_sio_init() API - * - Initialize SIO-SPI using @ref sl_si91x_sio_spi_init() API - ******************************************************************************/ -sl_status_t sl_si91x_sio_spi_cs_assert(uint8_t chip_select_num) -{ - sl_status_t status; - do { - if (chip_select_num > CS_NUM_MAX) { - // Returns invalid parameter status code if chip select > 7 - status = SL_STATUS_INVALID_PARAMETER; - break; - } - // Assert the SPI chip select - RSI_SIO_SpiCsAssert(SIO, chip_select_num); - status = SL_STATUS_OK; - } while (false); - return status; -} - -/******************************************************************************* - * This API de-asserts the SIO-SPI chip select - * The actions to be performed before SPI chip select de-assert are: - * - Initialize SIO using @ref sl_si91x_sio_init() API - * - Initialize SIO-SPI using @ref sl_si91x_sio_spi_init() API - * - Assert SIO chip select using @ref sl_si91x_sio_spi_cs_assert() API - * - Transfer data using @ref sl_si91x_sio_spi_transfer() API - ******************************************************************************/ -sl_status_t sl_si91x_sio_spi_cs_deassert(uint8_t chip_select_num) -{ - sl_status_t status; - do { - if (chip_select_num > CS_NUM_MAX) { - // Returns invalid parameter status code if chip select > 7 - status = SL_STATUS_INVALID_PARAMETER; - break; - } - // Deassert the SPI chip select - RSI_SIO_SpiCsDeAssert(SIO, chip_select_num); - status = SL_STATUS_OK; - } while (false); - return status; -} - -/******************************************************************************* - * This API is used to register the event callback. - * It registers the callback, i.e., stores the callback function address - * and pass to the variable that is called in Interrupt Handler. - * If another callback is registered without unregistering previous callback - * then, it returns an error code, so it is mandatory to unregister the callback - * before registering another callback. It will returns error if any callback is - * already registered. The actions to be performed before callback are: - * - Initialize SIO using @ref sl_si91x_sio_init() API - * - Initialize SIO-SPI using @ref sl_si91x_sio_spi_init() API - ******************************************************************************/ -sl_status_t sl_si91x_sio_spi_register_event_callback(sl_sio_spi_callback_t callback_event) -{ - sl_status_t status; - do { - // Validates the null pointer, if true returns error code - if (callback_event == NULL) { - status = SL_STATUS_NULL_POINTER; - break; - } - // To validate the function pointer if the parameters is not NULL then, it - // returns an error code - if (spi_user_callback != NULL) { - status = SL_STATUS_BUSY; - break; - } - // Enable the SIO interrupt - NVIC_EnableIRQ(SLI_SIO_INTERRUPT); - // User callback address is passed to the static variable which is called at - // the time of interrupt - spi_user_callback = callback_event; - // Returns SL_STATUS_OK if callback is successfully registered - status = SL_STATUS_OK; - } while (false); - return status; -} - -/******************************************************************************* - * It unregisters the callback, i.e., clear the callback function address - * and pass NULL value to the variable - ******************************************************************************/ -void sl_si91x_sio_spi_unregister_event_callback(void) -{ - // Pass the NULL value to the static variable which is called at the time of - // interrupt. - // It is further validated in register callback API. - spi_user_callback = NULL; - NVIC_DisableIRQ(SLI_SIO_INTERRUPT); -} - -/******************************************************************************* - * This API updates the callback function which in turns call the user callback - * API and used to make the SIO-SPI Transfer in non blocking mode. - * The actions to be performed before SPI transfer are: - * - Initialize SIO using @ref sl_si91x_sio_init() API - * - Initialize SIO-SPI using @ref sl_si91x_sio_spi_init() API - * - Assert SIO chip select using @ref sl_si91x_sio_spi_cs_assert() API - ******************************************************************************/ -sl_status_t sl_si91x_sio_spi_transfer(sl_sio_spi_xfer_config_t *xfer_config) -{ -#if (SIO_UC == 1) - xfer_config->u8BitLen = pstcSpiConfigUc.u8BitLen; -#endif - sl_status_t status; - rsi_error_t error_status; - do { - if (xfer_config == NULL) { - status = SL_STATUS_NULL_POINTER; // Returns null pointer status code - break; - } - // Update the callback function - xfer_config->pfnCb = callback_event_handler; - // Initiate the SIO data transfer - error_status = RSI_SIO_SpiTrasnfer(SIO, xfer_config); - status = convert_rsi_to_sl_error_code(error_status); - } while (false); - return status; -} - -/******************************************************************************* - * This API is a Static callback function for handling the callbacks - ******************************************************************************/ -static void callback_event_handler(en_sio_spi_events_t en_event) -{ - switch (en_event) { - // Handle SPI TX done event here - case SioSpiTxDone: - break; - // Handle SPI RX done event here - case SioSpiRxDone: - break; - } - spi_user_callback(en_event); - return; -} - -/******************************************************************************* - * This API is to validate the RSI error code. - * While calling the RSI APIs, it returns the RSI Error codes. - * This function converts the RSI error codes into SL error codes. - * It takes argument as RSI error type and returns the SL error type. - * It has a single switch statement which is mapped with the SL error code and - * after successful conversion it breaks the switch statement. - * If the error code is not listed, by default is SL_STATUS_FAIL. - ******************************************************************************/ -static sl_status_t convert_rsi_to_sl_error_code(rsi_error_t error) -{ - sl_status_t status; - switch (error) { - case RSI_OK: - status = SL_STATUS_OK; - break; - case INVALID_PARAMETERS: - status = SL_STATUS_INVALID_PARAMETER; - break; - case ERROR_INVALID_INPUT_FREQUENCY: - status = SL_STATUS_INVALID_PARAMETER; - break; - case ERROR_CLOCK_NOT_ENABLED: - status = SL_STATUS_NOT_INITIALIZED; - break; - default: - status = SL_STATUS_FAIL; - break; - } - return status; -} - -/******************************************************************************* - * This API is used to get the release, SQA and DEV version of SIO - * It returns the structure for SIO version. - * Structure includes three members: - * - Release version - * - SQA version - * - DEV version - ******************************************************************************/ -sl_sio_version_t sl_si91x_sio_get_version(void) -{ - sl_sio_version_t version; - version.minor = SIO_DEV_VERSION; - version.release = SIO_RELEASE_VERSION; - version.major = SIO_SQA_VERSION; - return version; -} - -/******************************************************************************* - * This API is used for initialize sio uart pins and clock. The formal argument passed - * takes pointer to structure of type \ref sl_sio_uart_t. This holds the uart tx, rx pins - * configuration. The members are assigned to SL macros defined in sl_sio_board.h. - * The SL macros are integrated to RTE macros present in RTE device file. - ******************************************************************************/ -sl_status_t sl_si91x_sio_uart_pin_initialization(sl_sio_uart_t *sio_uart_init) -{ - sl_status_t status; - do { - // Validates the null pointer, if true returns error code - if (sio_uart_init == NULL) { - status = SL_STATUS_NULL_POINTER; - break; - } - // sio uart tx pin muxing - if (sio_uart_init->uart_tx_pin >= GPIO_MAX_PIN) { - sl_si91x_gpio_enable_ulp_pad_receiver((uint8_t)(sio_uart_init->uart_tx_pin - GPIO_MAX_PIN)); - sl_gpio_set_pin_mode(ULP_PORT, (uint8_t)(sio_uart_init->uart_tx_pin - GPIO_MAX_PIN), ULP_GPIO_MODE_6, OUTPUT); - } else { - sl_si91x_gpio_enable_pad_receiver(sio_uart_init->uart_tx_pin); - } - if (sio_uart_init->uart_tx_pin >= (HOST_PAD_GPIO_MIN - 1) - && sio_uart_init->uart_tx_pin <= (HOST_PAD_GPIO_MAX + 1)) { - sl_si91x_gpio_enable_pad_selection(sio_uart_init->uart_tx_pin); - } else { - sl_si91x_gpio_enable_pad_selection(sio_uart_init->uart_tx_pad); - } - sl_gpio_set_pin_mode(sio_uart_init->uart_tx_port, sio_uart_init->uart_tx_pin, sio_uart_init->uart_tx_mux, OUTPUT); - // sio uart rx pin muxing - if (sio_uart_init->uart_rx_pin >= GPIO_MAX_PIN) { - sl_si91x_gpio_enable_ulp_pad_receiver((uint8_t)(sio_uart_init->uart_rx_pin - GPIO_MAX_PIN)); - sl_gpio_set_pin_mode(ULP_PORT, (uint8_t)(sio_uart_init->uart_rx_pin - GPIO_MAX_PIN), ULP_GPIO_MODE_6, OUTPUT); - } else { - sl_si91x_gpio_enable_pad_receiver(sio_uart_init->uart_rx_pin); - } - if (sio_uart_init->uart_rx_pin >= (HOST_PAD_GPIO_MIN - 1) - && sio_uart_init->uart_rx_pin <= (HOST_PAD_GPIO_MAX + 1)) { - sl_si91x_gpio_enable_pad_selection(sio_uart_init->uart_rx_pin); - } else { - sl_si91x_gpio_enable_pad_selection(sio_uart_init->uart_rx_pad); - } - sl_gpio_set_pin_mode(sio_uart_init->uart_rx_port, sio_uart_init->uart_rx_pin, sio_uart_init->uart_rx_mux, OUTPUT); - // SIO CLock enable - RSI_SIO_ClockEnable(); - status = SL_STATUS_OK; - } while (false); - return status; -} - -/******************************************************************************* - * This API is used for SIO-UART initialization i.e., setting baud rate, parity, - * channel selection, stop bits, data length. - * The actions to be performed before UART initialization is: - * - Initialize SIO using @ref sl_si91x_sio_init() API - ******************************************************************************/ -sl_status_t sl_si91x_sio_uart_init(sl_sio_uart_config_t *configuration) -{ -#if (SIO_UC == 1) - configuration = &UartInitstcUc; - UartInitstc = UartInitstcUc; -#endif - sl_status_t status; - rsi_error_t error_status; - configuration->pfn = uart_user_callback; - do { - if (configuration == NULL) { - status = SL_STATUS_NULL_POINTER; // Returns null pointer status code - break; - } - // Initialize the SIO-UART - error_status = RSI_SIO_UartInit(SIO, configuration); - status = convert_rsi_to_sl_error_code(error_status); - } while (false); - return status; -} - -/******************************************************************************* - * This API is used to send the data over SIO-UART. - * The actions to be performed before UART initialization is: - * - Initialize SIO using @ref sl_si91x_sio_init() API - * - Initialize SIO-UART using @ref sl_si91x_sio_uart_init() API - ******************************************************************************/ -sl_status_t sl_si91x_sio_uart_send(const void *buffer, uint16_t length) -{ - sl_status_t status; - rsi_error_t error_status; - do { - if (buffer == NULL) { - status = SL_STATUS_NULL_POINTER; // Returns null pointer status code - break; - } - // Send the data over UART - error_status = RSI_SIO_UARTSend(SIO, buffer, length); - status = convert_rsi_to_sl_error_code(error_status); - } while (false); - return status; -} - -/******************************************************************************* - * This API is used to write data in SIO-UART mode. - * The actions to be performed before UART initialization is: - * - Initialize SIO using @ref sl_si91x_sio_init() API - * - Initialize SIO-UART using @ref sl_si91x_sio_uart_init() API - ******************************************************************************/ -sl_status_t sl_si91x_sio_uart_send_blocking(const void *buffer, uint16_t length) -{ - sl_status_t status; - rsi_error_t error_status; - do { - if (buffer == NULL) { - status = SL_STATUS_NULL_POINTER; // Returns null pointer status code - break; - } - // write data in UART mode - error_status = RSI_SIO_UARTSendBlocking(SIO, buffer, length); - status = convert_rsi_to_sl_error_code(error_status); - } while (false); - return status; -} - -/******************************************************************************* - * This API is used to read data in UART mode. - * The actions to be performed before UART initialization is: - * - Initialize SIO using @ref sl_si91x_sio_init() API - * - Initialize SIO-UART using @ref sl_si91x_sio_uart_init() API - * - Send data using @ref sl_si91x_sio_uart_send() API(or) - * @ref sl_si91x_sio_uart_send_blocking() API - ******************************************************************************/ -sl_status_t sl_si91x_sio_uart_read(void *data_buffer, uint16_t num_bytes) -{ - sl_status_t status; - rsi_error_t error_status; - do { - if (data_buffer == NULL) { - status = SL_STATUS_NULL_POINTER; // Returns null pointer status code - break; - } - // Read data in UART mode - - error_status = RSI_SIO_UARTRead(SIO, data_buffer, num_bytes); - status = convert_rsi_to_sl_error_code(error_status); - } while (false); - return status; -} - -/******************************************************************************* - * This API is used to read data in UART blocking mode - * The actions to be performed before UART initialization is: - * - Initialize SIO using @ref sl_si91x_sio_init() API - * - Initialize SIO-UART using @ref sl_si91x_sio_uart_init() API - * - Send data using @ref sl_si91x_sio_uart_send() API(or) - * @ref sl_si91x_sio_uart_send_blocking() API - ******************************************************************************/ -sl_status_t sl_si91x_sio_uart_read_blocking(void *data_buffer, uint16_t num_bytes) -{ - sl_status_t status; - rsi_error_t error_status; - do { - if (data_buffer == NULL) { - status = SL_STATUS_NULL_POINTER; // Returns null pointer status code - break; - } - // Read data in UART blocking mode - error_status = RSI_SIO_UARTReadBlocking(SIO, data_buffer, num_bytes); - status = convert_rsi_to_sl_error_code(error_status); - } while (false); - return status; -} - -/******************************************************************************* - * This API is used to register the event callback. - * It registers the callback, i.e., stores the callback function address - * and pass to the variable that is called in Interrupt Handler. - * If another callback is registered without unregistering previous callback - * then, it returns an error code, so it is mandatory to unregister the callback - * before registering another callback. It will returns error if any callback is - * already registered. The actions to be performed before callback are: - * - Initialize SIO using @ref sl_si91x_sio_init() API - * - Initialize SIO-UART using @ref sl_si91x_sio_uart_init() API - ******************************************************************************/ -sl_status_t sl_si91x_sio_uart_register_event_callback(sl_sio_uart_callback_t callback_event) -{ - sl_status_t status; - do { - // Validates the null pointer, if true returns error code - if (callback_event == NULL) { - status = SL_STATUS_NULL_POINTER; - break; - } - // To validate the function pointer if the parameters is not NULL then, it - // returns an error code - if (uart_user_callback != NULL) { - status = SL_STATUS_BUSY; - break; - } - // Enable the SIO interrupt - NVIC_EnableIRQ(SLI_SIO_INTERRUPT); - // User callback address is passed to the static variable which is called at - // the time of interrupt - uart_user_callback = callback_event; - // Returns SL_STATUS_OK if callback is successfully registered - status = SL_STATUS_OK; - } while (false); - return status; -} - -/******************************************************************************* - * It unregisters the callback, i.e., clear the callback function address - * and pass NULL value to the variable - ******************************************************************************/ -void sl_si91x_sio_uart_unregister_event_callback(void) -{ - // Pass the NULL value to the static variable which is called at the time of - // interrupt. - // It is further validated in register callback API. - uart_user_callback = NULL; - NVIC_DisableIRQ(SLI_SIO_INTERRUPT); -} - -/******************************************************************************* - * This API is used when UART receive is done. - ******************************************************************************/ -void sl_si91x_sio_uart_rx_done(void) -{ - gstcSioCb.uart_sio.u16UartRxDone = 0; -} - -/******************************************************************************* - * This API is used for initialize sio i2c pins and clock. The formal argument passed - * takes pointer to structure of type \ref sl_sio_i2c_t. This holds the i2c sda, scl pins - * configuration. The members are assigned to SL macros defined in sl_sio_board.h. - * The SL macros are integrated to RTE macros present in RTE device file. - ******************************************************************************/ -sl_status_t sl_si91x_sio_i2c_pin_initialization(sl_sio_i2c_t *sio_i2c_init) -{ - sl_status_t status; - do { - // Validates the null pointer, if true returns error code - if (sio_i2c_init == NULL) { - status = SL_STATUS_NULL_POINTER; - break; - } - // sio i2c scl pin muxing - if (sio_i2c_init->i2c_scl_pin >= GPIO_MAX_PIN) { - sl_si91x_gpio_enable_ulp_pad_receiver((uint8_t)(sio_i2c_init->i2c_scl_pin - GPIO_MAX_PIN)); - sl_gpio_set_pin_mode(ULP_PORT, (uint8_t)(sio_i2c_init->i2c_scl_pin - GPIO_MAX_PIN), ULP_GPIO_MODE_6, OUTPUT); - } else { - sl_si91x_gpio_enable_pad_receiver(sio_i2c_init->i2c_scl_pin); - } - if (sio_i2c_init->i2c_scl_pin >= (HOST_PAD_GPIO_MIN - 1) && sio_i2c_init->i2c_scl_pin <= (HOST_PAD_GPIO_MAX + 1)) { - sl_si91x_gpio_enable_pad_selection(sio_i2c_init->i2c_scl_pin); - } else { - sl_si91x_gpio_enable_pad_selection(sio_i2c_init->i2c_scl_pad); - } - sl_gpio_set_pin_mode(sio_i2c_init->i2c_scl_port, sio_i2c_init->i2c_scl_pin, sio_i2c_init->i2c_scl_mux, OUTPUT); - // sio i2c sda pin muxing - if (sio_i2c_init->i2c_sda_pin >= GPIO_MAX_PIN) { - sl_si91x_gpio_enable_ulp_pad_receiver((uint8_t)(sio_i2c_init->i2c_sda_pin - GPIO_MAX_PIN)); - sl_gpio_set_pin_mode(ULP_PORT, (uint8_t)(sio_i2c_init->i2c_sda_pin - GPIO_MAX_PIN), ULP_GPIO_MODE_6, OUTPUT); - } else { - sl_si91x_gpio_enable_pad_receiver(sio_i2c_init->i2c_sda_pin); - } - if (sio_i2c_init->i2c_sda_pin >= (HOST_PAD_GPIO_MIN - 1) && sio_i2c_init->i2c_sda_pin <= (HOST_PAD_GPIO_MAX + 1)) { - sl_si91x_gpio_enable_pad_selection(sio_i2c_init->i2c_sda_pin); - } else { - sl_si91x_gpio_enable_pad_selection(sio_i2c_init->i2c_sda_pad); - } - sl_gpio_set_pin_mode(sio_i2c_init->i2c_sda_port, sio_i2c_init->i2c_sda_pin, sio_i2c_init->i2c_sda_mux, OUTPUT); - // SIO CLock enable - RSI_SIO_ClockEnable(); - status = SL_STATUS_OK; - } while (false); - return status; -} - -/******************************************************************************* - * This API is used to write the data over SIO-I2C. - * The actions to be performed before I2C write are: - * - Initialize SIO using @ref sl_si91x_sio_init() API - * - I2C generate start using @ref sl_si91x_sio_i2c_generate_start() API - ******************************************************************************/ -sl_status_t sl_si91x_sio_i2c_write(stc_sio_i2c_config_t *configuration, uint8_t address, uint8_t *data, uint16_t length) -{ - sl_status_t status; - rsi_error_t error_status; -#if (SIO_UC == 1) - configuration = &i2cConfigUc; -#endif - do { - // Returns null pointer status code - if (configuration == NULL) { - status = SL_STATUS_NULL_POINTER; - break; - } - // Write data over I2C - error_status = RSI_SIO_I2cWrite(SIO, configuration, address, data, length); - status = convert_rsi_to_sl_error_code(error_status); - } while (false); - return status; -} - -/******************************************************************************* - * This API is used to read the data over SIO-I2C. - * The actions to be performed before I2C read are: - * - Initialize SIO using @ref sl_si91x_sio_init() API - * - I2C generate start using @ref sl_si91x_sio_i2c_generate_start() API - * - Write data using @ref sl_si91x_sio_i2c_write() API - * (OR) @ref sl_si91x_sio_i2c_transfer() API - ******************************************************************************/ -sl_status_t sl_si91x_sio_i2c_read(stc_sio_i2c_config_t *configuration, uint8_t address, uint8_t *data, uint16_t length) -{ - sl_status_t status; - rsi_error_t error_status; -#if (SIO_UC == 1) - configuration = &i2cConfigUc; -#endif - do { - // Returns null pointer status code - if (configuration == NULL) { - status = SL_STATUS_NULL_POINTER; - break; - } - // Read data over I2C - error_status = RSI_SIO_I2cRead(SIO, configuration, address, data, length); - status = convert_rsi_to_sl_error_code(error_status); - } while (false); - return status; -} - -/******************************************************************************* - * This API is used to transfer the data over SIO-I2C. - * The actions to be performed before I2C transfer are: - * - Initialize SIO using @ref sl_si91x_sio_init() API - * - I2C generate start using @ref sl_si91x_sio_i2c_generate_start() API - ******************************************************************************/ -sl_status_t sl_si91x_sio_i2c_transfer(stc_sio_i2c_config_t *configuration, - uint8_t address, - uint8_t *tx_buffer, - uint16_t tx_length, - uint8_t *rx_buffer, - uint16_t rx_length) -{ -#if (SIO_UC == 1) - configuration = &i2cConfigUc; -#endif - sl_status_t status; - rsi_error_t error_status; - do { - // Returns null pointer status code - if (configuration == NULL) { - status = SL_STATUS_NULL_POINTER; - break; - } - // Transfer data over I2C - error_status = RSI_SIO_I2cTransfer(SIO, configuration, address, tx_buffer, tx_length, rx_buffer, rx_length); - status = convert_rsi_to_sl_error_code(error_status); - } while (false); - return status; -} - -/******************************************************************************* - * This API is used for i2c generate start over SIO-I2C. - * The actions to be performed before I2C generate start is: - * - Initialize SIO using @ref sl_si91x_sio_init() API - ******************************************************************************/ -void sl_si91x_sio_i2c_generate_start(void) -{ - RSI_SIO_I2cGenerateStart(SIO); -} - -/******************************************************************************* - * This API is used for i2c generate stop over SIO-I2C. - * The actions to be performed before i2c generate stop are: - * - Initialize SIO using @ref sl_si91x_sio_init() API - * - I2C generate start using @ref sl_si91x_sio_i2c_generate_start() API - * - Write data using @ref sl_si91x_sio_i2c_write() API - * (OR) @ref sl_si91x_sio_i2c_transfer() API - ******************************************************************************/ -void sl_si91x_sio_i2c_generate_stop(void) -{ - RSI_SIO_I2cGenerateStop(SIO); -} - -/******************************************************************************* - * This API is used for configure gpio interrupt. - * The actions to be performed before configuring interrupt is: - * - Initialize SIO using @ref sl_si91x_sio_init() API - ******************************************************************************/ -sl_status_t sl_si91x_sio_configure_interrupt(en_sio_channels_t channel, interrupt_flag_t flag) -{ - sl_status_t status; - do { - // Returns invalid parameter status code if channel > 7 and flag > 3 - if ((channel > SIO_CHANNEL) || (flag > FLAG)) { - status = SL_STATUS_INVALID_PARAMETER; - break; - } - RSI_SIO_Configure_Interrupt(SIO, channel, flag); - status = SL_STATUS_OK; - } while (false); - return status; -} - -/******************************************************************************* - * This API is used to match the pattern with data to be detected - * When pattern match bit is enabled, pattern match register should be - * programmed with data pattern to be detected. - * Pattern mask register to be programmed with valid bits to match. - * The actions to be performed before pattern match is: - * - Initialize SIO using @ref sl_si91x_sio_init() API - ******************************************************************************/ -sl_status_t sl_si91x_sio_match_pattern(en_sio_channels_t channel, - pattern_match_t pattern, - uint8_t slice, - uint32_t slice_pattern) -{ - sl_status_t status; - do { - // Returns invalid parameter status code if channel > 7 and pattern > 1 - if ((channel > SIO_CHANNEL) || (pattern >= PATTERN_MATCH)) { - status = SL_STATUS_INVALID_PARAMETER; - break; - } - RSI_SIO_Match_Pattern(SIO, channel, pattern, slice, slice_pattern); - status = SL_STATUS_OK; - } while (false); - return status; -} - -/******************************************************************************* - * This API is used to generate shift clock - * The actions to be performed before shift clock is: - * - Initialize SIO using @ref sl_si91x_sio_init() API - ******************************************************************************/ -sl_status_t sl_si91x_sio_shift_clock(uint32_t divider, en_sio_channels_t channel) -{ - sl_status_t status; - do { - // Returns invalid parameter status code if channel > 7 - if (channel > SIO_CHANNEL) { - status = SL_STATUS_INVALID_PARAMETER; - break; - } - RSI_SIO_Shift_Clock(SIO, divider, channel); - status = SL_STATUS_OK; - } while (false); - return status; -} - -/******************************************************************************* - * This API is used to select internal/external clock - * When external clock is used, shift/capture happens one system clock - * after the external clock edge - * The actions to be performed before select clock is: - * - Initialize SIO using @ref sl_si91x_sio_init() API - ******************************************************************************/ -sl_status_t sl_si91x_sio_select_clock(en_sio_channels_t channel, clock_type_t clock) -{ - sl_status_t status; - do { - // Returns invalid parameter status code if channel > 7 and clock > 1 - if ((channel > SIO_CHANNEL) || (clock >= CLOCK_TYPE)) { - status = SL_STATUS_INVALID_PARAMETER; - break; - } - RSI_SIO_Select_Clock(SIO, channel, clock); - status = SL_STATUS_OK; - } while (false); - return status; -} - -/******************************************************************************* - * This API is used to shift number of bits - * No. of shifts to happen before reloading the shift register with data/pausing - * the operation. i.e. value to be set = (total no. of valid bits in shift - * register/ number of bits per shift) – 1 The actions to be performed are: - * - Initialize SIO using @ref sl_si91x_sio_init() API - ******************************************************************************/ -sl_status_t sl_si91x_sio_position_counter(en_sio_channels_t channel, uint32_t data_shift) -{ - sl_status_t status; - do { - // Returns invalid parameter status code if channel > 7 - if (channel > SIO_CHANNEL) { - status = SL_STATUS_INVALID_PARAMETER; - break; - } - RSI_SIO_Position_Counter(SIO, channel, data_shift); - status = SL_STATUS_OK; - } while (false); - return status; -} - -/******************************************************************************* - * This API is used to enable/disable flow control bit. If flow control - * disabled, Data shifting continues even when data in shift register is not - * valid. Counters keep moving. If flow control is enabled, Counters and shift - * operations pause when data is not available. - * The actions to be performed are: - * - Initialize SIO using @ref sl_si91x_sio_init() API - ******************************************************************************/ -sl_status_t sl_si91x_sio_control_flow(en_sio_channels_t channel, flow_control_t flow_control) -{ - sl_status_t status; - do { - // Returns invalid parameter status code if channel > 7 and flow_control > 1 - if ((channel > SIO_CHANNEL) || (flow_control >= FLOW_CONTROL)) { - status = SL_STATUS_INVALID_PARAMETER; - break; - } - RSI_SIO_Control_Flow(SIO, channel, flow_control); - status = SL_STATUS_OK; - } while (false); - return status; -} - -/******************************************************************************* - * This API is used to load data to buffer in reverse order - * When set, the data on APB is loaded to buffer is reverse order. If the - * requirement is to shift out the MSB first, this has to be enabled. - * The actions to be performed are: - * - Initialize SIO using @ref sl_si91x_sio_init() API - ******************************************************************************/ -sl_status_t sl_si91x_sio_reverse_load(en_sio_channels_t channel, reverse_load_t reverse) -{ - sl_status_t status; - do { - // Returns invalid parameter status code if channel > 7 and reverse > 1 - if ((channel > SIO_CHANNEL) || (reverse >= REVERSE_LOAD)) { - status = SL_STATUS_INVALID_PARAMETER; - break; - } - RSI_SIO_Reverse_Load(SIO, channel, reverse); - status = SL_STATUS_OK; - } while (false); - return status; -} - -/******************************************************************************* - * This API is used for common swap interrupt enable set - * Common swap interrupt enable set register for all SIOs. Each bit - * corresponds to one SIO. When '1' is written, swap interrupt - * enable gets set. Interrupt would be raised if not masked and interrupt - * status would be reflected in interrupt status register. - * The actions to be performed are: - * - Initialize SIO using @ref sl_si91x_sio_init() API - ******************************************************************************/ -sl_status_t sl_si91x_sio_set_interrupt(en_sio_channels_t channel) -{ - sl_status_t status; - do { - // Returns invalid parameter status code if channel > 7 - if (channel > SIO_CHANNEL) { - status = SL_STATUS_INVALID_PARAMETER; - break; - } - RSI_SIO_Set_Interrupt(SIO, channel); - status = SL_STATUS_OK; - } while (false); - return status; -} - -/******************************************************************************* - * This API is used for common swap interrupt enable clear - * Common swap interrupt enable clear register for all SIOs. Each bit - * corresponds to one SIO. When '1' is written, swap interrupt - * enable gets cleared. Interrupt would not be raised and interrupt status - * would not be reflected in interrupt status register. - * The actions to be performed are: - * - Initialize SIO using @ref sl_si91x_sio_init() API - ******************************************************************************/ -sl_status_t sl_si91x_sio_clear_interrupt(en_sio_channels_t channel) -{ - sl_status_t status; - do { - // Returns invalid parameter status code if channel > 7 - if (channel > SIO_CHANNEL) { - status = SL_STATUS_INVALID_PARAMETER; - break; - } - RSI_SIO_Clear_Interrupt(SIO, channel); - status = SL_STATUS_OK; - } while (false); - return status; -} - -/******************************************************************************* - * This API is used for common swap interrupt mask set - * The actions to be performed are: - * - Initialize SIO using @ref sl_si91x_sio_init() API - ******************************************************************************/ -sl_status_t sl_si91x_sio_mask_interrupt(en_sio_channels_t channel) -{ - sl_status_t status; - do { - // Returns invalid parameter status code if channel > 7 - if (channel > SIO_CHANNEL) { - status = SL_STATUS_INVALID_PARAMETER; - break; - } - RSI_SIO_Mask_Interrupt(SIO, channel); - status = SL_STATUS_OK; - } while (false); - return status; -} - -/******************************************************************************* - * This API is used for common swap interrupt mask clear - * The actions to be performed are: - * - Initialize SIO using @ref sl_si91x_sio_init() API - ******************************************************************************/ -sl_status_t sl_si91x_sio_unmask_interrupt(en_sio_channels_t channel) -{ - sl_status_t status; - do { - // Returns invalid parameter status code if channel > 7 - if (channel > SIO_CHANNEL) { - status = SL_STATUS_INVALID_PARAMETER; - break; - } - RSI_SIO_UnMask_Interrupt(SIO, channel); - status = SL_STATUS_OK; - } while (false); - return status; -} - -/******************************************************************************* - * This API is used to read common swap interrupt status - * The actions to be performed are: - * - Initialize SIO using @ref sl_si91x_sio_init() API - ******************************************************************************/ -uint32_t sl_si91x_sio_get_interrupt_status(void) -{ - return RSI_SIO_Get_Interrupt_Status(SIO); -} - -/******************************************************************************* - * This API is used for common shift interrupt enable set - * Common shift interrupt enable set register for all SIOs. Each bit - * corresponds to one SIO. When '1' is written, shift interrupt - * enable gets set. Interrupt would be raised if not masked and interrupt - * status would be reflected in interrupt status register. - * The actions to be performed are: - * - Initialize SIO using @ref sl_si91x_sio_init() API - ******************************************************************************/ -sl_status_t sl_si91x_sio_set_shift_interrupt(en_sio_channels_t channel) -{ - sl_status_t status; - do { - // Returns invalid parameter status code if channel > 7 - if (channel > SIO_CHANNEL) { - status = SL_STATUS_INVALID_PARAMETER; - break; - } - RSI_SIO_Set_Shift_Interrupt(SIO, channel); - status = SL_STATUS_OK; - } while (false); - return status; -} - -/******************************************************************************* - * This API is used for common shift interrupt enable clear - * Common shift interrupt enable clear register for all SIOs. Each bit - * corresponds to one SIO. When '1' is written, shift interrupt - * enable gets cleared. Interrupt would not be raised and interrupt status - * would not be reflected in interrupt status register. - * The actions to be performed are: - * - Initialize SIO using @ref sl_si91x_sio_init() API - ******************************************************************************/ -sl_status_t sl_si91x_sio_clear_shift_interrupt(en_sio_channels_t channel) -{ - sl_status_t status; - do { - // Returns invalid parameter status code if channel > 7 - if (channel > SIO_CHANNEL) { - status = SL_STATUS_INVALID_PARAMETER; - break; - } - RSI_SIO_Clear_Shift_Interrupt(SIO, channel); - status = SL_STATUS_OK; - } while (false); - return status; -} - -/******************************************************************************* - * This API is used for common shift interrupt mask set - * The actions to be performed are: - * - Initialize SIO using @ref sl_si91x_sio_init() API - ******************************************************************************/ -sl_status_t sl_si91x_sio_mask_shift_interrupt(en_sio_channels_t channel) -{ - sl_status_t status; - do { - // Returns invalid parameter status code if channel > 7 - if (channel > SIO_CHANNEL) { - status = SL_STATUS_INVALID_PARAMETER; - break; - } - RSI_SIO_Mask_Shift_Interrupt(SIO, channel); - status = SL_STATUS_OK; - } while (false); - return status; -} - -/******************************************************************************* - * This API is used for common shift interrupt mask clear - * The actions to be performed are: - * - Initialize SIO using @ref sl_si91x_sio_init() API - ******************************************************************************/ -sl_status_t sl_si91x_sio_unmask_shift_interrupt(en_sio_channels_t channel) -{ - sl_status_t status; - do { - // Returns invalid parameter status code if channel > 7 - if (channel > SIO_CHANNEL) { - status = SL_STATUS_INVALID_PARAMETER; - break; - } - RSI_SIO_UnMask_Shift_Interrupt(SIO, channel); - status = SL_STATUS_OK; - } while (false); - return status; -} - -/******************************************************************************* - * This API is used to read common shift interrupt status - * The actions to be performed are: - * - Initialize SIO using @ref sl_si91x_sio_init() API - ******************************************************************************/ -uint32_t sl_si91x_sio_shift_interrupt_status(void) -{ - return RSI_SIO_Shift_Interrupt_Status(SIO); -} - -/******************************************************************************* - * This API is used to select edge of the clock cycle for sampling bits - * The actions to be performed are: - * - Initialize SIO using @ref sl_si91x_sio_init() API - ******************************************************************************/ -sl_status_t sl_si91x_sio_edge_select(en_sio_channels_t channel, edge_select_t edge_sel) -{ - sl_status_t status; - do { - // Returns invalid parameter status code if channel > 7 and edge_sel > 1 - if ((channel > SIO_CHANNEL) || (edge_sel >= EDGE_SELECT)) { - status = SL_STATUS_INVALID_PARAMETER; - break; - } - RSI_SIO_Edge_Select(SIO, channel, edge_sel); - status = SL_STATUS_OK; - } while (false); - return status; -} - -/******************************************************************************* - * This API is used to read sio buffer register - * The actions to be performed are: - * - Initialize SIO using @ref sl_si91x_sio_init() API - * - Initialize SPI using @ref sl_si91x_sio_spi_init() API for SIO-SPI - * - Initialize UART using @ref sl_si91x_sio_uart_init() API for SIO-UART - ******************************************************************************/ -uint32_t sl_si91x_sio_read_buffer(en_sio_channels_t channel) -{ - return RSI_SIO_Read_Buffer(SIO, channel); -} - -/******************************************************************************* - * This API is used to write into sio buffer register - * The actions to be performed are: - * - Initialize SIO using @ref sl_si91x_sio_init() API - * - Initialize SPI using @ref sl_si91x_sio_spi_init() API for SIO-SPI - * - Initialize UART using @ref sl_si91x_sio_uart_init() API for SIO-UART - ******************************************************************************/ -sl_status_t sl_si91x_sio_write_buffer(en_sio_channels_t channel, uint32_t data) -{ - sl_status_t status; - do { - // Returns invalid parameter status code if channel > 7 - if (channel > SIO_CHANNEL) { - status = SL_STATUS_INVALID_PARAMETER; - break; - } - RSI_SIO_Write_Buffer(SIO, channel, data); - status = SL_STATUS_OK; - } while (false); - return status; -} diff --git a/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_ssi.c b/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_ssi.c index f3690ae44..37c910cab 100644 --- a/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_ssi.c +++ b/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_ssi.c @@ -47,12 +47,12 @@ #define MIN_BIT_WIDTH 4 // Minimum Bit width #define MAX_SLAVE_BIT_WIDTH 16 // Maximum Slave Bit width #define MAX_BIT_WIDTH 16 // Maximum Bit width +#define MAX_INSTANCE 3 // Maximum SSI Instance /******************************************************************************* *************************** LOCAL VARIABLES ******************************* ******************************************************************************/ -static const void *local_ssi_handle = NULL; -static sl_ssi_signal_event_t user_callback = NULL; +static sl_ssi_signal_event_t user_callback[] = { NULL, NULL, NULL }; extern sl_ssi_driver_t Driver_SSI_MASTER; extern sl_ssi_driver_t Driver_SSI_SLAVE; extern sl_ssi_driver_t Driver_SSI_ULP_MASTER; @@ -72,6 +72,7 @@ static void callback_event_handler(uint32_t event); static void sl_ssi_set_receive_sample_delay(sl_ssi_handle_t ssi_handle, uint32_t sample_delay); static boolean_t validate_ssi_handle(sl_ssi_handle_t ssi_handle); static sl_status_t sli_si91x_ssi_configure_power_mode(sl_ssi_handle_t ssi_handle, sl_ssi_power_state_t state); +static uint8_t convert_handle_to_instance(sl_ssi_handle_t ssi_handle); /******************************************************************************* ********************** Local Function Definition**************************** @@ -176,8 +177,10 @@ sl_status_t sl_si91x_ssi_deinit(sl_ssi_handle_t ssi_handle) status = SL_STATUS_INVALID_PARAMETER; break; } - // Unregister the user callback function. - user_callback = NULL; + // Getting the instance number from the input handle + uint8_t instance = convert_handle_to_instance(ssi_handle); + // NULL is passed to the callback function pointer of instance which is deinitialized + user_callback[instance] = NULL; error_status = ((sl_ssi_driver_t *)ssi_handle)->Uninitialize(); status = convert_arm_to_sl_error_code(error_status); @@ -554,16 +557,17 @@ sl_status_t sl_si91x_ssi_register_event_callback(sl_ssi_handle_t ssi_handle, sl_ status = SL_STATUS_INVALID_PARAMETER; break; } + // Getting the instance number from the input handle + uint8_t instance = convert_handle_to_instance(ssi_handle); // To validate the function pointer if the parameters is not NULL then, it // returns an error code - if ((user_callback != NULL) || (local_ssi_handle != NULL)) { + if (user_callback[instance] != NULL) { status = SL_STATUS_BUSY; break; } // User callback address is passed to the static variable which is called at the time of // interrupt - user_callback = callback_event; - local_ssi_handle = ssi_handle; + user_callback[instance] = callback_event; // Returns SL_STATUS_OK if callback is successfully registered status = SL_STATUS_OK; } while (false); @@ -580,8 +584,10 @@ void sl_si91x_ssi_unregister_event_callback(void) // Pass the NULL value to the static variable which is called at the time of // interrupt. // It is further validated in register callback API. - user_callback = NULL; - local_ssi_handle = NULL; + for (int i = 0; i < MAX_INSTANCE; i++) { + // Clearing all the three instance callbacks + user_callback[i] = NULL; + } } /******************************************************************************* @@ -731,9 +737,26 @@ uint32_t sl_si91x_ssi_get_receiver_sample_delay(sl_ssi_handle_t ssi_handle) static void callback_event_handler(uint32_t event) { + uint8_t ssi_instance = 0; + ARM_DRIVER_SPI *handle = NULL; + // Extracting the instance number from the event variable + ssi_instance = (uint8_t)(event >> SSI_INSTANCE_BIT); + if (ssi_instance == SSI_MASTER_INSTANCE) { + // assigning local handle to the master mode address + handle = &Driver_SSI_MASTER; + } else if (ssi_instance == SSI_SLAVE_INSTANCE) { + // assigning local handle to the slave mode address + handle = &Driver_SSI_SLAVE; + } else if (ssi_instance == SSI_ULP_MASTER_INSTANCE) { + // assigning local handle to the ulp master mode address + handle = &Driver_SSI_ULP_MASTER; + } + // Clearing the instance number to evaluate the event + event &= SSI_INSTANCE_MASK; switch (event) { case SSI_EVENT_TRANSFER_COMPLETE: - ((sl_ssi_driver_t *)local_ssi_handle)->Control(ARM_SPI_CONTROL_SS, ARM_SPI_SS_INACTIVE); + // Disabling the slave select line after the transfer complete + handle->Control(ARM_SPI_CONTROL_SS, ARM_SPI_SS_INACTIVE); break; case SSI_EVENT_DATA_LOST: // Occurs in slave mode when data is requested/sent by master @@ -748,7 +771,8 @@ static void callback_event_handler(uint32_t event) default: break; } - user_callback(event); + // Calling the callback as per the instance + user_callback[ssi_instance](event); } /******************************************************************************* @@ -899,3 +923,30 @@ static boolean_t validate_ssi_handle(sl_ssi_handle_t ssi_handle) } return status; } + +/******************************************************************************* + * Internal function to convert ssi handle to the instance number. + * + * @param[in] ssi handle. + * @return instance, 0,1,2 for master, slave and ulp master respectively + * +*******************************************************************************/ +static uint8_t convert_handle_to_instance(sl_ssi_handle_t ssi_handle) +{ + uint8_t instance = 0; + do { + if (ssi_handle == &Driver_SSI_MASTER) { + instance = SSI_MASTER_INSTANCE; + break; + } + if (ssi_handle == &Driver_SSI_SLAVE) { + instance = SSI_SLAVE_INSTANCE; + break; + } + if (ssi_handle == &Driver_SSI_ULP_MASTER) { + instance = SSI_ULP_MASTER_INSTANCE; + break; + } + } while (false); + return instance; +} diff --git a/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_usart.c b/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_usart.c index f24a8681f..7207c6861 100644 --- a/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_usart.c +++ b/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_usart.c @@ -663,6 +663,8 @@ sl_status_t sl_si91x_usart_set_configuration(sl_usart_handle_t usart_handle, uint32_t input_mode = false; sl_si91x_usart_control_config_t control_config[NO_OF_UART_INSTANCES]; usart_peripheral_t uart_instance; + (void)control_config; + (void)uart_instance; /* USART_UC is defined by default. when this macro (USART_UC) is defined, peripheral * configuration is directly taken from the configuration set in the universal configuration (UC). diff --git a/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_watchdog_timer.c b/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_watchdog_timer.c index e1d0ce9ea..6711c8532 100644 --- a/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_watchdog_timer.c +++ b/components/device/silabs/si91x/mcu/drivers/unified_api/src/sl_si91x_watchdog_timer.c @@ -28,8 +28,9 @@ * ******************************************************************************/ #include "sl_si91x_watchdog_timer.h" +#ifndef SL_WDT_MANAGER_PRESENT #include "sl_si91x_watchdog_timer_config.h" - +#endif #include "rsi_rtc.h" /******************************************************************************* *************************** DEFINES / MACROS ******************************** @@ -136,9 +137,9 @@ sl_status_t sl_si91x_watchdog_configure_clock(watchdog_timer_clock_config_t *tim * @brief: Configures watchdog-timer parameters * * @details: -* Sets interrupt timeout time (with default value '15' for 1-secs delay) -* Sets system reset time (with default value '17' for 4-secs delay) -* Sets system window time (with default value 0) +* Sets interrupt timeout time +* Sets system reset time +* Sets system window time *******************************************************************************/ sl_status_t sl_si91x_watchdog_set_configuration(watchdog_timer_config_t *timer_config_ptr) { @@ -165,9 +166,8 @@ sl_status_t sl_si91x_watchdog_set_configuration(watchdog_timer_config_t *timer_c status = SL_STATUS_INVALID_PARAMETER; break; } - // Comparing time values with each other - if ((timer_config_ptr->system_reset_time <= timer_config_ptr->interrupt_time) - || (timer_config_ptr->interrupt_time <= timer_config_ptr->window_time)) { + // Comparing interrupt time with window time + if (timer_config_ptr->interrupt_time <= timer_config_ptr->window_time) { status = SL_STATUS_INVALID_CONFIGURATION; break; } @@ -230,8 +230,6 @@ sl_status_t sl_si91x_watchdog_register_timeout_callback(watchdog_timer_callback_ * timer restart. * * Number of clock pulses for timer timeout = 2^(interrupt_time) -* -* This value should be less than system-reset time. *******************************************************************************/ sl_status_t sl_si91x_watchdog_set_interrupt_time(time_delays_t interrupt_time) { @@ -243,11 +241,6 @@ sl_status_t sl_si91x_watchdog_set_interrupt_time(time_delays_t interrupt_time) status = SL_STATUS_INVALID_PARAMETER; break; } - // Validating interrupt time as per system reset time value - if (RSI_WWDT_GetSysRstTime(MCU_WDT) <= interrupt_time) { - status = SL_STATUS_INVALID_CONFIGURATION; - break; - } // Validating interrupt time as per window time value if (RSI_WWDT_GetWindowTime(MCU_WDT) >= interrupt_time) { status = SL_STATUS_INVALID_CONFIGURATION; @@ -312,9 +305,8 @@ sl_status_t sl_si91x_watchdog_set_window_time(time_delays_t window_time) * 'WWD_SYSTEM_RESET_TIMER' register (5-bit), so its maximum value is 31. * * It is used to calculate clock pulse count of FSM clock, to reset the system -* Number of clock pulses for system reset delay = 2^(system_reset_time) -* -* This value should be greater than timer interrupt time. +* Number of clock pulses for system reset delay = 2^(system_reset_time) +* This value should be greater than timer window time. *******************************************************************************/ sl_status_t sl_si91x_watchdog_set_system_reset_time(time_delays_t system_reset_time) { @@ -326,11 +318,6 @@ sl_status_t sl_si91x_watchdog_set_system_reset_time(time_delays_t system_reset_t status = SL_STATUS_INVALID_PARAMETER; break; } - // Validating system-reset time as per interrupt time value - if (RSI_WWDT_GetIntrTime(MCU_WDT) >= system_reset_time) { - status = SL_STATUS_INVALID_CONFIGURATION; - break; - } // Validating system reset time as per window time value if (RSI_WWDT_GetWindowTime(MCU_WDT) >= system_reset_time) { status = SL_STATUS_INVALID_CONFIGURATION; diff --git a/components/device/silabs/si91x/mcu/drivers/unified_peripheral_drivers/inc/sl_si91x_gpio_common.h b/components/device/silabs/si91x/mcu/drivers/unified_peripheral_drivers/inc/sl_si91x_gpio_common.h index 9e695318a..250dcff17 100644 --- a/components/device/silabs/si91x/mcu/drivers/unified_peripheral_drivers/inc/sl_si91x_gpio_common.h +++ b/components/device/silabs/si91x/mcu/drivers/unified_peripheral_drivers/inc/sl_si91x_gpio_common.h @@ -143,7 +143,11 @@ extern "C" { : port == 2 ? ((pin > GPIO_PC_PIN_MAX_VALIDATE) ? 0 : 1) \ : port == 3 ? ((pin > GPIO_PD_PIN_MAX_VALIDATE) ? 0 : 1) \ : 0) - +///< Validate GPIO host pad port and pin +#define SL_GPIO_VALIDATE_HOST_PIN(port, pin) \ + (port == SL_GPIO_PORT_A ? (((pin >= HOST_PAD_MIN) && (pin <= HOST_PAD_MAX)) ? TRUE : FALSE) \ + : port == SL_GPIO_PORT_B ? (((pin >= GPIO_PIN_NUMBER9) && (pin <= GPIO_PIN_NUMBER14)) ? TRUE : FALSE) \ + : FALSE) #define SL_GPIO_VALIDATE_ULP_PORT_PIN(port, pin) (port == 4 ? ((pin > 11) ? 0 : 1) : 0) ///< Validate ULP port and pin #define SL_GPIO_VALIDATE_UULP_PORT_PIN(port, pin) (port == 5 ? ((pin > 5) ? 0 : 1) : 0) ///< Validate UULP port and pin diff --git a/components/device/silabs/si91x/mcu/hal/inc/rsi_m4.h b/components/device/silabs/si91x/mcu/hal/inc/rsi_m4.h deleted file mode 100644 index 2d77d07ce..000000000 --- a/components/device/silabs/si91x/mcu/hal/inc/rsi_m4.h +++ /dev/null @@ -1,215 +0,0 @@ -/******************************************************************************* -* @file rsi_m4.h -* @brief -******************************************************************************* -* # License -* Copyright 2020 Silicon Laboratories Inc. www.silabs.com -******************************************************************************* -* -* 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. -* -******************************************************************************/ - -#ifndef _RSI_M4_HAL_H_ -#define _RSI_M4_HAL_H_ -#ifdef SLI_SI91X_MCU_INTERFACE - -#include "rsi_pkt_mgmt.h" -#include "RS1xxxx.h" -#include "core_cm4.h" -/****************************************************** - * * Constants - * ******************************************************/ - -#define M4_ISR_IRQ 74 - -#define TA_MEMORY_OFFSET_ADDRESS 0x00400000 -#ifdef SLI_SI917 -#define M4_MEMORY_OFFSET_ADDRESS 0x00500000 -#else -#define M4_MEMORY_OFFSET_ADDRESS 0x00200000 -#endif - -#define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */ - -#define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */ -#ifndef NVIC -#define NVIC ((NVIC_Type *)NVIC_BASE) /*!< NVIC configuration struct */ -#endif - -#define M4SS_P2P_INT_BASE_ADDRESS 0x46008000 -#define MCU_PWR_CTRL_BASE_ADDR 0x24048400 -#define MISC_CFG_HOST_CTRL *(volatile uint32_t *)(M4SS_P2P_INT_BASE_ADDRESS + 0x0C) - -#define M4SS_P2P_INTR_SET_REG *(volatile uint32_t *)(M4SS_P2P_INT_BASE_ADDRESS + 0x16C) -#define M4SS_P2P_INTR_CLR_REG *(volatile uint32_t *)(M4SS_P2P_INT_BASE_ADDRESS + 0x170) -#define P2P_STATUS_REG *(volatile uint32_t *)(M4SS_P2P_INT_BASE_ADDRESS + 0x174) -#define TASS_P2P_INTR_MASK_SET *(volatile uint32_t *)(M4SS_P2P_INT_BASE_ADDRESS + 0x178) -#define TASS_P2P_INTR_MASK_CLR *(volatile uint32_t *)(M4SS_P2P_INT_BASE_ADDRESS + 0x17C) -#define TASS_P2P_INTR_CLEAR *(volatile uint32_t *)(M4SS_P2P_INT_BASE_ADDRESS + 0x180) - -#define TASS_P2P_INT_BASE_ADDRESS 0x41050000 - -#define TASS_P2P_INTR_SET_REG *(volatile uint32_t *)(TASS_P2P_INT_BASE_ADDRESS + 0x8C) -#define TASS_P2P_INTR_CLR_REG *(volatile uint32_t *)(TASS_P2P_INT_BASE_ADDRESS + 0x90) - -#define M4_TX_DMA_DESC_REG *(volatile uint32_t *)(TASS_P2P_INT_BASE_ADDRESS + 0x34) -#define M4_RX_DMA_DESC_REG *(volatile uint32_t *)(TASS_P2P_INT_BASE_ADDRESS + 0x5C) -#define HOST_INTR_STATUS_REG *(volatile uint32_t *)(TASS_P2P_INT_BASE_ADDRESS + 0x04) - -#define DMA_DESC_REG_VALID (0xA0 << 8) - -#define TA_wakeup_M4 BIT(2) -#define TA_is_active BIT(3) -#define M4_wakeup_TA BIT(0) -#define M4_is_active BIT(1) -#define NWP_DEINIT_IN_COMM_FLASH BIT(7) -#define ARM_MASK_1 0xE000E100 -#define ARM_MASK_1 0xE000E100 -#define ARM_MASK_1 0xE000E100 - -#ifndef BIT -#define BIT(x) (1 << (x)) -#endif - -//! This interrupt is raised by M4 to TA when there is a TX packet from M4 to read -#define RX_BUFFER_VALID BIT(1) -#define TX_PKT_PENDING_INTERRUPT BIT(2) -#define UPGRADE_M4_IMAGE BIT(5) -#ifdef SLI_SI917 -#define M4_WAITING_FOR_TA_TO_WR_ON_FLASH BIT(6) -#endif - -#define TX_PKT_TRANSFER_DONE_INTERRUPT BIT(2) -//! This interrupt is received from TA when RX packet is pending from TA - -#define RX_PKT_TRANSFER_DONE_INTERRUPT BIT(1) -//! This interrupt is received from TA when TX packet transfer from M4 to TA is done - -#define M4_IMAGE_UPGRADATION_PENDING_INTERRUPT BIT(4) -//! This interrupt is raised by TA to M4 when there is a TX packet from M4 to read - -#ifdef SLI_SI917 -//! This interrupt is raised by TA to M4 when there is a flash write request from M4 to TA in comm flash mode -#define TA_WRITING_ON_COMM_FLASH BIT(5) -#endif - -#ifndef RSI_BUFFER_FULL -//! buffer full indication register value from module -#define RSI_BUFFER_FULL BIT(0) -#endif - -#ifdef SLI_SI917 -//! Option value for m4 app from flash to ram API -#define UPGRADE_M4_IMAGE_OTA 1 -#define TA_WRITES_ON_COMM_FLASH 2 -#endif - -#ifdef SLI_SI91X_ENABLE_OS -#define TASS_P2P_INTR_PRI 5 -#define SYSTICK_INTR_PRI 7 -#endif -/****************************************************** - * * Enumerations - * ******************************************************/ - -/****************************************************** - * * Type Definitions - * ******************************************************/ -typedef struct rsi_m4ta_desc_dword1_s { - //! Reserved - uint32_t reserved : 15; - - //! 1 bit : indicates the presence of more descriptors - //! 1 - last descriptor - //! 0 - more descriptors are present - uint32_t last_desc : 1; - - //! Buffer queue_no to be transfered for this descriptor - uint32_t queue_no : 4; - - //! Buffer length to be transfered for this descriptor - uint32_t length : 12; - -} rsi_m4ta_desc_dword1_t; - -typedef struct rsi_m4ta_desc_s { - //! source address - uint32_t addr; - - uint16_t length; - //! descriptor control fields - //rsi_m4ta_desc_dword1_t dword1; - -} rsi_m4ta_desc_t; - -//! host descriptor structure -typedef struct rsi_frame_desc_s { - //! Data frame body length. Bits 14:12=queue, 000 for data, Bits 11:0 are the length - uint8_t frame_len_queue_no[2]; - //! Frame type - uint8_t frame_type; - //! Unused , set to 0x00 - uint8_t reserved[9]; - //! Management frame descriptor response status, 0x00=success, else error - uint8_t status; - uint8_t reserved1[3]; -} rsi_frame_desc_t; - -//! P2P registers Backup structure -typedef struct rsi_p2p_intr_status_bkp_s { - uint32_t tass_p2p_intr_mask_clr_bkp; - uint32_t m4ss_p2p_intr_set_reg_bkp; -} rsi_p2p_intr_status_bkp_t; - -/****************************************************** - * * Structures - * ******************************************************/ - -/****************************************************** - * * Global Variables - * ******************************************************/ -/****************************************************** - * * Function Declarations - * ******************************************************/ -int16_t rsi_frame_write(rsi_frame_desc_t *uFrameDscFrame, uint8_t *payloadparam, uint16_t size_param); -rsi_pkt_t *rsi_frame_read(void); -int16_t rsi_device_interrupt_status(uint8_t *int_status); - -void rsi_m4_interrupt_isr(void); -void rsi_m4_ta_interrupt_init(void); -void rsi_raise_pkt_pending_interrupt_to_ta(void); -int32_t rsi_send_pkt_to_ta(rsi_m4ta_desc_t *tx_desc); -void rsi_transfer_to_ta_done_isr(void); -void rsi_pkt_pending_from_ta_isr(void); -void rsi_receive_from_ta_done_isr(void); -int16_t rsi_device_buffer_full_status(void); -int rsi_submit_rx_pkt(void); -void unmask_ta_interrupt(uint32_t interrupt_no); -void raise_m4_to_ta_interrupt(uint32_t interrupt_no); -void clear_m4_to_ta_interrupt(uint32_t interrupt_no); -void clear_ta_interrupt_mask(void); -void set_ta_interrupt_mask(void); -void mask_ta_interrupt(uint32_t interrupt_no); -void unmask_ta_interrupt(uint32_t interrupt_no); -void clear_ta_to_m4_interrupt(uint32_t interrupt_no); -void ROM_WL_raise_m4_to_ta_interrupt(uint32_t interrupt_no); -void ROM_WL_clear_m4_to_ta_interrupt(uint32_t interrupt_no); -void ROM_WL_clear_ta_interrupt_mask(void); -void ROM_WL_set_ta_interrupt_mask(void); -void ROM_WL_mask_ta_interrupt(uint32_t interrupt_no); -void ROM_WL_unmask_ta_interrupt(uint32_t interrupt_no); -void ROM_WL_clear_ta_to_m4_interrupt(uint32_t interrupt_no); -uint32_t NVIC_GetIRQEnable(IRQn_Type IRQn); -void rsi_config_m4_dma_desc_on_reset(void); -void rsi_update_tx_dma_desc(uint8_t skip_dma_valid); -void rsi_update_rx_dma_desc(void); -void IRQ074_Handler(void); - -#endif -#endif diff --git a/components/device/silabs/si91x/mcu/hal/inc/sl_si91x_hal_soc_soft_reset.h b/components/device/silabs/si91x/mcu/hal/inc/sl_si91x_hal_soc_soft_reset.h index 1fcf0b621..cbb69a561 100644 --- a/components/device/silabs/si91x/mcu/hal/inc/sl_si91x_hal_soc_soft_reset.h +++ b/components/device/silabs/si91x/mcu/hal/inc/sl_si91x_hal_soc_soft_reset.h @@ -31,6 +31,10 @@ #ifndef __SL_SI91X_HAL_SOC_SOFT_RESET__ #define __SL_SI91X_HAL_SOC_SOFT_RESET__ +#define M4_BBFF_STORAGE1 *(volatile uint32 *)0x24048580 +#define M4_QSPI_AES_CONFIG *(volatile uint32 *)0x120000C8 +#define AES_QSPI_KEY_SIZE BIT(16) +#define KEY_LENGTH BIT(11) /* * * @brief This API is used to config WDT @@ -38,4 +42,11 @@ * @return None */ void sl_si91x_soc_soft_reset(void); +/* + * + * @brief This API is used to do soc NVIC reset with the debug module disabled. + * @param None + * @return None + */ +void sl_si91x_soc_nvic_reset(void); #endif \ No newline at end of file diff --git a/components/device/silabs/si91x/mcu/hal/src/sl_si91x_hal_soc_soft_reset.c b/components/device/silabs/si91x/mcu/hal/src/sl_si91x_hal_soc_soft_reset.c index 3410643f8..df1630aa1 100644 --- a/components/device/silabs/si91x/mcu/hal/src/sl_si91x_hal_soc_soft_reset.c +++ b/components/device/silabs/si91x/mcu/hal/src/sl_si91x_hal_soc_soft_reset.c @@ -30,7 +30,7 @@ #include "rsi_wwdt.h" #include "cmsis_os2.h" #include "sl_si91x_hal_soc_soft_reset.h" -#define M4_BBFF_STORAGE1 *(volatile uint32 *)0x24048580 + /* * * @brief WDT interrupt handler @@ -64,8 +64,44 @@ void sl_si91x_soc_soft_reset(void) NVIC_EnableIRQ(NVIC_WDT); /*Start WDT */ RSI_WWDT_Start(MCU_WDT); + /*Upon Reset key size is 16 by default in case of inline encryption */ - M4_BBFF_STORAGE1 = 0; + /*Store key length bit (32 Bytes) in BBFF if device security is with 32 Bytes key*/ + if (M4_QSPI_AES_CONFIG & AES_QSPI_KEY_SIZE) { + M4_BBFF_STORAGE1 |= KEY_LENGTH; + } while (1) ; } +/* + * + * @brief This API is used to do soc NVIC reset with the debug module disabled. + * @param None + * @return None + */ +void sl_si91x_soc_nvic_reset(void) +{ + /*Upon Reset key size is 16 by default in case of inline encryption */ + /*Store key length bit (32 Bytes) in BBFF if device security is with 32 Bytes key*/ + if (M4_QSPI_AES_CONFIG & AES_QSPI_KEY_SIZE) { + M4_BBFF_STORAGE1 |= KEY_LENGTH; + } + __asm volatile("cpsid i" ::: "memory"); + /*Data Synchronization Barrier */ + __DSB(); + /*Instruction Synchronization Barrier */ + __ISB(); + /*Power Down the Debug Module */ + RSI_PS_M4ssPeriPowerDown(M4SS_PWRGATE_ULP_M4_DEBUG_FPU); + /*Set the SYSRESETREQ bit in the AIRCR register to initiate a system reset */ + SCB->AIRCR = (0x5FA << SCB_AIRCR_VECTKEY_Pos) | SCB_AIRCR_SYSRESETREQ_Msk; + /*Ensure the instruction is not optimized out */ + /*Data Synchronization Barrier */ + __DSB(); + /*Instruction Synchronization Barrier */ + __ISB(); + /*Wait for the reset to occur */ + while (1) { + /* Infinite loop to keep the program running until the reset happens */ + } +} diff --git a/components/device/silabs/si91x/mcu/toolchain/component/wiseconnect_toolchain_plugin.slcc b/components/device/silabs/si91x/mcu/toolchain/component/wiseconnect_toolchain_plugin.slcc index 3aa70fcc5..32102793f 100644 --- a/components/device/silabs/si91x/mcu/toolchain/component/wiseconnect_toolchain_plugin.slcc +++ b/components/device/silabs/si91x/mcu/toolchain/component/wiseconnect_toolchain_plugin.slcc @@ -10,8 +10,10 @@ root_path: components/device/silabs/si91x/mcu/toolchain provides: - name: wiseconnect_toolchain_plugin template_file: + - path: linkerfile_psram_SoC.ld.jinja + condition: [wiseconnect_toolchain_psram_linker] - path: linkerfile_SoC.ld.jinja - unless: [wiseconnect_toolchain_gcc_override, wiseconnect_toolchain_custom_linker] + unless: [wiseconnect_toolchain_gcc_override, wiseconnect_toolchain_custom_linker, wiseconnect_toolchain_psram_linker] requires: - name: toolchain_gcc - name: toolchain_variant_arm @@ -24,9 +26,12 @@ library: unless: - wiseconnect_toolchain_gcc_override toolchain_settings: + - option: linkerfile + value: autogen/linkerfile_psram_SoC.ld + condition: [wiseconnect_toolchain_psram_linker] - option: linkerfile value: autogen/linkerfile_SoC.ld - unless: [wiseconnect_toolchain_gcc_override, wiseconnect_toolchain_custom_linker] + unless: [wiseconnect_toolchain_gcc_override, wiseconnect_toolchain_custom_linker, wiseconnect_toolchain_psram_linker] - option: gcc_linker_option value: "-u _printf_float" - option: gcc_compiler_option diff --git a/components/device/silabs/si91x/mcu/toolchain/component/wiseconnect_toolchain_psram_linker.slcc b/components/device/silabs/si91x/mcu/toolchain/component/wiseconnect_toolchain_psram_linker.slcc new file mode 100644 index 000000000..3ed12bff2 --- /dev/null +++ b/components/device/silabs/si91x/mcu/toolchain/component/wiseconnect_toolchain_psram_linker.slcc @@ -0,0 +1,14 @@ +id: wiseconnect_toolchain_psram_linker +label: Toolchain support for PSRAM Linker +package: platform +description: > + Selecting this will include the PSRAM Linker component. +category: Device|Si91x|MCU|Toolchain +ui_hints: + visibility: never +quality: production +root_path: components/device/silabs/si91x/mcu/toolchain +provides: + - name: wiseconnect_toolchain_psram_linker +requires: + - name: wiseconnect_toolchain_plugin \ No newline at end of file diff --git a/components/device/silabs/si91x/mcu/toolchain/linkerfile.ld.jinja b/components/device/silabs/si91x/mcu/toolchain/linkerfile.ld.jinja deleted file mode 100644 index 8e3570907..000000000 --- a/components/device/silabs/si91x/mcu/toolchain/linkerfile.ld.jinja +++ /dev/null @@ -1,341 +0,0 @@ -/***************************************************************************//** - * GCC Linker script for Silicon Labs devices - ******************************************************************************* - * # License - * Copyright 2020 Silicon Laboratories Inc. www.silabs.com - ******************************************************************************* - * - * SPDX-License-Identifier: Zlib - * - * The licensor of this software is Silicon Laboratories Inc. - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - * - ******************************************************************************/ - -{#- - Device specific sizes and addresses. These variables describes the physical - memory of the device. -#} -{%- set sram_addr = device_ram_addr | first %} -{%- set sram_size = device_ram_size | first %} -{%- set flash_addr = device_flash_addr | first %} -{%- set flash_size = device_flash_size | first %} -{%- set flash_page_size = device_flash_page_size | first %} - -{%- if udma_enable %} - {%- set udma0_main_size = udma0_size | sum %} - {%- set udma0_start_addr = udma0 | sum %} - {%- set udma1_main_size = udma1_size | sum %} - {%- set udma1_start_addr = udma1 | sum %} -{%- endif %} - -{#- - Application specific sizes. Here we start to calculate the application view - of the physical memory. -#} -{%- set app_flash_start = flash_addr %} -{%- set app_flash_end = flash_addr + flash_size %} -{%- set app_ram_start = sram_addr %} -{%- set app_ram_end = sram_addr + sram_size %} - -{#- - Calculate application flash and ram size based on start and end address. -#} -{%- set app_flash_size = app_flash_end - app_flash_start %} -{%- set app_ram_size = app_ram_end - app_ram_start %} - -{%- if udma_enable %} - {%- set udma_buffer = udma_buffer | sum %} - {%- set app_ram_size = app_ram_size - udma_buffer %} - {%- set udma0_start_addr = app_ram_size %} - {%- set udma1_start_addr = udma1_start_addr - udma_buffer%} -{%- endif %} - -{%- set rtt = 0 %} -{% if linker_rtt_section is defined %} -{%- set rtt = 1 %} -{% endif %} - -{%- if nvm3_flash_size %} - {%- set nvm_size = nvm3_size | first%} - {%- set app_flash_size = app_flash_size - nvm_size %} -{%- endif %} - MEMORY - { - rom (rx) : ORIGIN = 0x{{ '%0x' % app_flash_start }}, LENGTH = 0x{{ '%0x' % app_flash_size }} - ram (rwx) : ORIGIN = 0x{{ '%0x' % app_ram_start }}, LENGTH = 0x{{ '%0x' % app_ram_size }} - } - -{%- if udma_enable %} - MEMORY - { - udma0 (rwx) : ORIGIN = 0x{{ '%0x' % udma0_start_addr }}, LENGTH = 0x{{ '%0x' % udma0_main_size }} - udma1 (rwx) : ORIGIN = 0x{{ '%0x' % udma1_start_addr }}, LENGTH = 0x{{ '%0x' % udma1_main_size }} - } -{%- endif %} - -ENTRY(Reset_Handler) - -SECTIONS -{ - .text : - { - KEEP(*(.isr_vector)) - {% if not EXECUTION_FROM_RAM_PS2 %} - {% if not SLI_SI91X_MCU_ENABLE_RAM_BASED_EXECUTION %} - *(.text*) - {% endif %} - {% if EXECUTION_FROM_RAM %} - KEEP(*(.reset_handler)) - *(EXCLUDE_FILE( *rsi_common.o *rsi_driver.o *rsi_driver_event_handlers.o *rsi_events.o *rsi_os_none.o *rsi_pkt_mgmt.o *rsi_queue.o *rsi_scheduler.o *rsi_timer.o *rsi_utils.o *rsi_wlan.o *rsi_common_apis.o *rsi_wlan_apis.o *rsi_apis_non_rom.o *rsi_hal_mcu_timer.o *rsi_hal_mcu_interrupt.o *rsi_hal_mcu_m4.o *rsi_hal_mcu_platform_init.o *rsi_apis_rom.o *rsi_events_rom.o *rsi_hal_mcu_m4_rom.o *rsi_hal_mcu_m4_ram.o *rsi_pkt_mgmt_rom.o *rsi_queue_rom.o *rsi_scheduler_rom.o *rsi_socket_rom.o *rsi_utils_rom.o *rsi_nwk_rom.o *rsi_os_wrapper.o *port.o *heap_4.o *timers.o *croutine.o *event_groups.o *list.o *queue.o *tasks.o *stream_buffer.o *network_sapi_wrapper.o *rsi_deepsleep_soc.o ) .text*) - {% endif %} - {% if not EXECUTION_FROM_RAM %} - *(EXCLUDE_FILE(*rsi_deepsleep_soc.o *rsi_hal_mcu_m4_ram.o) .text*) - KEEP(*(.init)) - KEEP(*(.fini)) - {% endif %} - {% endif %} - /* .ctors */ - *crtbegin.o(.ctors) - *crtbegin?.o(.ctors) - *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) - *(SORT(.ctors.*)) - *(.ctors) - - /* .dtors */ - *crtbegin.o(.dtors) - *crtbegin?.o(.dtors) - *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) - *(SORT(.dtors.*)) - *(.dtors) - {% if not EXECUTION_FROM_RAM_PS2 %} - {% if not EXECUTION_FROM_RAM %} - *(.rodata*) - {% endif %} - {% if not SLI_SI91X_MCU_ENABLE_RAM_BASED_EXECUTION %} - *(.rodata*) - {% endif %} - {% endif %} - KEEP(*(.eh_fram e*)) - } > rom - - .ARM.extab : - { - *(.ARM.extab* .gnu.linkonce.armextab.*) - } > rom - - __exidx_start = .; - .ARM.exidx : - { - *(.ARM.exidx* .gnu.linkonce.armexidx.*) - } > rom - __exidx_end = .; - __etext = .; - - /* _sidata is used in startup code */ - _sidata = __etext; - - .data : - { - __data_start__ = .; - - /* _sdata is used in startup code */ - _sdata = __data_start__; - {% if EXECUTION_FROM_RAM %} - KEEP(*(.ramVector)) - KEEP(*(.init)) - KEEP(*(.fini)) - *(.rodata*) - {% endif %} - {% if EXECUTION_FROM_RAM_PS2 %} - KEEP(*(.ramVector)) - KEEP(*(.init)) - KEEP(*(.fini)) - *(.rodata*) - *(.text*) - {% endif %} - *(vtable) - *(.data*) - {% if EXECUTION_FROM_RAM %} - *rsi_common.o(.text*) - *rsi_driver.o(.text*) - *rsi_driver_event_handlers.o(.text*) - *rsi_events.o(.text*) - *rsi_os_none.o(.text*) - *rsi_pkt_mgmt.o(.text*) - *rsi_queue.o(.text*) - *rsi_scheduler.o(.text*) - *rsi_timer.o(.text*) - *rsi_utils.o(.text*) - *rsi_wlan.o(.text*) - *rsi_common_apis.o(.text*) - *rsi_wlan_apis.o(.text*) - *rsi_apis_non_rom.o(.text*) - *rsi_hal_mcu_timer.o(.text*) - *rsi_hal_mcu_m4.o(.text*) - *rsi_hal_mcu_interrupt.o(.text*) - *rsi_hal_mcu_platform_init.o(.text*) - *rsi_hal_mcu_m4_rom.o(.text*) - *rsi_hal_mcu_m4_ram.o(.text*) - *rsi_apis_rom.o(.text*) - *rsi_events_rom.o(.text*) - *rsi_pkt_mgmt_rom.o(.text*) - *rsi_queue_rom.o(.text*) - *rsi_scheduler_rom.o(.text*) - *rsi_socket_rom.o(.text*) - *rsi_utils_rom.o(.text*) - *rsi_nwk_rom.o(.text*) - *rsi_os_wrapper.o(.text*) - *timers.o(.text*) - *croutine.o(.text*) - *event_groups.o(.text*) - *list.o(.text*) - *queue.o(.text*) - *stream_buffer.o(.text*) - *tasks.o(.text*) - *heap_4.o(.text*) - *port.o(.text*) - *network_sapi_wrapper.o(.text*) - *rsi_deepsleep_soc.o(.text*) - {% endif %} - {% if not EXECUTION_FROM_RAM_PS2 %} - {% if not EXECUTION_FROM_RAM %} - *rsi_deepsleep_soc.o(.text*) - *rsi_hal_mcu_m4_ram.o(.text*) - {% endif %} - {% endif %} - {% if SLI_SI91X_MCU_ENABLE_RAM_BASED_EXECUTION %} - *(.text*) - *(.rodata*) - KEEP(*(.init)) - KEEP(*(.fini)) - {% endif %} - . = ALIGN(4); - /* preinit data */ - PROVIDE_HIDDEN (__preinit_array_start = .); - KEEP(*(.preinit_array)) - PROVIDE_HIDDEN (__preinit_array_end = .); - - . = ALIGN(4); - /* init data */ - PROVIDE_HIDDEN (__init_array_start = .); - KEEP(*(SORT(.init_array.*))) - KEEP(*(.init_array)) - PROVIDE_HIDDEN (__init_array_end = .); - - . = ALIGN(4); - /* finit data */ - PROVIDE_HIDDEN (__fini_array_start = .); - KEEP(*(SORT(.fini_array.*))) - KEEP(*(.fini_array)) - PROVIDE_HIDDEN (__fini_array_end = .); - - KEEP(*(.jcr*)) - . = ALIGN(4); - /* All data end */ - __data_end__ = .; - - /* _edata is used in startup code */ - _edata = __data_end__; - } > ram AT> rom - - .bss : - { - . = ALIGN(4); - __bss_start__ = .; - _sbss = __bss_start__; - *(.bss*) - *(COMMON) - . = ALIGN(4); - __bss_end__ = .; - _ebss = __bss_end__; - } > ram - - /* .stack_dummy section doesn't contains any symbols. It is only - * used for linker to calculate size of stack sections, and assign - * values to stack symbols later */ - Co_Stack_Size = 0x3000; - .co_stack ALIGN(8) (NOLOAD): - { - __co_stackLimit = .; - KEEP(*(.co_stack*)) - . = ALIGN(4); - . += Co_Stack_Size; - __co_stackTop = .; - } > ram - - StackSize = 0x1400; - .stack ALIGN(8) (NOLOAD): - { - __StackLimit = .; - KEEP(*(.stack*)) - . = ALIGN(4); - . += StackSize; - __StackTop = .; - PROVIDE(__stack = __StackTop); - } > ram - - .heap (COPY): - { - __HeapBase = .; - __end__ = .; - end = __end__; - _end = __end__; - KEEP(*(.heap*)) - . = ORIGIN(ram) + LENGTH(ram); - __HeapLimit = .; - } > ram - __heap_size = __HeapLimit - __HeapBase; - -{%- if udma_enable %} - .udma_addr0 : - { - *(.udma_addr0*) - } > udma0 AT> rom - - .udma_addr1 : - { - *(.udma_addr1*) - } > udma1 AT> rom -{%- endif %} - -{%- if nvm3_enable %} - __ram_end__ = 0x{{ '%0x' % app_ram_start }} + 0x{{ '%0x' % app_ram_size }}; - __main_flash_end__ = 0x{{ '%0x' % app_flash_start }} + 0x{{ '%0x' % app_flash_size }}; - - /* This is where we handle flash storage blocks. We use dummy sections for finding the configured - * block sizes and then "place" them at the end of flash when the size is known. */ - .internal_storage (DSECT) : { - KEEP(*(.internal_storage*)) - } > rom - - .nvm (DSECT) : { - KEEP(*(.simee*)) - } > rom - - linker_nvm_end = __main_flash_end__; - linker_nvm_begin = linker_nvm_end - SIZEOF(.nvm); - linker_nvm_size = SIZEOF(.nvm); - linker_storage_end = linker_nvm_begin; - __nvm3Base = linker_nvm_begin; - - linker_storage_begin = linker_storage_end - SIZEOF(.internal_storage); - linker_storage_size = SIZEOF(.internal_storage); - ASSERT((linker_storage_begin >= (__etext + SIZEOF(.data))), "FLASH memory overflowed !") -{%- endif %} -} \ No newline at end of file diff --git a/components/device/silabs/si91x/mcu/toolchain/linkerfile_SoC.ld.jinja b/components/device/silabs/si91x/mcu/toolchain/linkerfile_SoC.ld.jinja index c57146459..cd3091c9e 100644 --- a/components/device/silabs/si91x/mcu/toolchain/linkerfile_SoC.ld.jinja +++ b/components/device/silabs/si91x/mcu/toolchain/linkerfile_SoC.ld.jinja @@ -39,12 +39,6 @@ {%- endif %} {%- set flash_page_size = device_flash_page_size | first %} - -{%- if psram_present %} - {%- set psram_addr = device_psram_addr | first %} - {%- set psram_size = device_psram_size | first %} -{%- endif %} - {%- if udma_enable %} {%- set udma0_main_size = udma0_size | sum %} {%- set udma0_start_addr = udma0 | sum %} @@ -63,16 +57,6 @@ {%- set app_ram_start = sram_addr %} {%- set app_ram_end = sram_size %} -{%- if psram_present %} - {%- set app_psram_start = psram_addr %} - {%- if text_segment_in_psram %} - {#- Adds 0x1000 offset (4096 in decimal) #} - {%- set psram_start_offset = 4096 %} - {%- set app_psram_start = psram_addr + psram_start_offset %} - {%- endif %} - {%- set app_psram_end = psram_addr + psram_size %} -{%- endif %} - {#- Calculate application flash and ram size based on start and end address. #} @@ -88,10 +72,6 @@ {%- set udma1_start_addr = udma1_start_addr - udma_buffer%} {%- endif %} -{%- if psram_present %} - {%- set app_psram_size = app_psram_end - app_psram_start %} -{%- endif %} - {%- set rtt = 0 %} {% if linker_rtt_section is defined %} {%- set rtt = 1 %} @@ -102,15 +82,16 @@ {%- set app_flash_size = app_flash_size - nvm_size %} {%- endif %} +{%- if nvm3_enable or littlefs_enable %} + {%- set nvm3_app_max_flash_size = max_flash_size | first %} +{%- endif %} + MEMORY { {%- if flash_present %} rom (rx) : ORIGIN = 0x{{ '%0x' % app_flash_start }}, LENGTH = 0x{{ '%0x' % app_flash_size }} {% endif %} ram (rwx) : ORIGIN = 0x{{ '%0x' % app_ram_start }}, LENGTH = 0x{{ '%0x' % app_ram_size }} - {%- if psram_present %} - psram (rwx) : ORIGIN = 0x{{ '%0x' % app_psram_start }}, LENGTH = 0x{{ '%0x' % app_psram_size }} - {%- endif %} } {%- if udma_enable %} @@ -121,12 +102,6 @@ } {%- endif %} -{%- if psram_present and psram_linker_config_enabled %} - -_last_psram_location = ORIGIN(psram); -_last_ram_location = ORIGIN(ram); -{%- endif %} - ENTRY(Reset_Handler) SECTIONS @@ -134,22 +109,20 @@ SECTIONS .text : { KEEP(*(.isr_vector)) - {%- if ram_execution %} - KEEP(*(.reset_handler)) + {%- if not power_manager_ps2 %} + {%- if ram_execution %} + KEEP(*(.reset_handler)) *(EXCLUDE_FILE(*sl_si91x_bus.o *sl_si91x_driver.o *sli_si91x_multithreaded.o *rsi_deepsleep_soc.o *rsi_hal_mcu_m4_ram.o *rsi_hal_mcu_m4_rom.o *UDMA.o *sl_sleeptimer.o *sl_sleeptimer_hal_si91x_sysrtc.o *rsi_sysrtc.o *sl_si91x_low_power_tickless_mode.o *croutine.o *event_groups.o *list.o *queue.o *stream_buffer.o *tasks.o *timers.o *cmsis_os2.o *freertos_umm_malloc_host.o *malloc_buffers.o *sl_rsi_utility.o *port.o *heap_*.o) .text*) - {% endif %} - {% if psram_present and psram_linker_config_enabled and psram_powersave_handle %} - *(EXCLUDE_FILE(*rsi_deepsleep_soc.o *sl_si91x_psram.o *rsi_qspi.o *rsi_pll.o *rsi_egpio.o *UDMA.o *sl_rsi_utility.o) .text*) - {% elif power_manager_ps2 %} + {% else %} + *(EXCLUDE_FILE(*UDMA.o).text*) + KEEP(*(.init)) + KEEP(*(.fini)) + {% endif %} + {% endif %} + + {% if power_manager_ps2 %} *(EXCLUDE_FILE( *cmsis_gcc.o *cmsis_os2.o *port.o *queue.o *sl_rsi_utility.o *tasks.o *clock_update.o *rsi_deepsleep_soc.o *rsi_egpio.o *rsi_ipmu.o *ipmu_apis.o *rsi_pll.o *rsi_power_save.o *rsi_ps_ram_func.o *rsi_system_config.o *rsi_time_period.o *rsi_ulpss_clk.o *system_si91x.o *sl_slist.o *strcmp.o *sl_si91x_power_manager.o *sli_si91x_power_manager.o *sl_si91x_power_manager_handler.o *sl_si91x_power_manager_debug.o *sli_si91x_power_manager_wakeup_init.o *sl_si91x_power_manager_wakeup_handler.o *sl_sleeptimer.o *sl_sleeptimer_hal_si91x_sysrtc.o *rsi_sysrtc.o *sl_si91x_low_power_tickless_mode.o *sl_core_cortexm.o *UDMA.o {% for c in debug_ps2 %}*{{c}} {% endfor %}{% for c in calendar_ps2 %}*{{c}} {% endfor %}{% for c in ulp_timer_ps2 %}*{{c}} {% endfor %}{% for c in wdt_ps2 %}*{{c}} {% endfor %}{% for c in adc_ps2 %}*{{c}} {% endfor %}{% for c in bod_ps2 %}*{{c}} {% endfor %}{% for c in comparator_ps2 %}*{{c}} {% endfor %}{% for c in cts_ps2 %}*{{c}} {% endfor %}{% for c in dac_ps2 %}*{{c}} {% endfor %}{% for c in dma_ps2 %}*{{c}} {% endfor %}{% for c in gpio_ps2 %}*{{c}} {% endfor %}{% for c in i2c_ps2 %}*{{c}} {% endfor %}{% for c in i2s_ps2 %}*{{c}} {% endfor %}{% for c in ir_ps2 %}*{{c}} {% endfor %}{% for c in ssi_ps2 %}*{{c}} {% endfor %}{% for c in sysrtc_ps2 %}*{{c}} {% endfor %}{% for c in usart_ps2 %}*{{c}} {% endfor %}{% for c in user_files_ps2 %}*{{c}} {% endfor %}) .text*) - {% elif ulp_mode_execution %} - *(.copysection*) - *(.zerosection*) - - {% elif not ram_execution %} - *(EXCLUDE_FILE(*UDMA.o).text*) - KEEP(*(.init)) - KEEP(*(.fini)) + {%- endif %} /* .ctors */ @@ -166,17 +139,13 @@ SECTIONS *(SORT(.dtors.*)) *(.dtors) - {%- if not ulp_mode_execution %} {%- if not power_manager_ps2 %} *(.rodata*) {%- endif %} - {%- endif %} KEEP(*(.eh_fram e*)) - {%- if psram_present and text_segment_in_psram %} - _last_psram_location = .; - } > psram - {%- elif flash_present %} + + {%- if flash_present %} } > rom {%- else %} } > ram @@ -185,10 +154,8 @@ SECTIONS .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) - {%- if psram_present and text_segment_in_psram %} - _last_psram_location = .; - } > psram - {%- elif flash_present %} + + {%- if flash_present %} } > rom {%- else %} } > ram @@ -198,10 +165,8 @@ SECTIONS .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) - {%- if psram_present and text_segment_in_psram %} - _last_psram_location = .; - } > psram - {%- elif flash_present %} + + {%- if flash_present %} } > rom {%- else %} } > ram @@ -209,119 +174,40 @@ SECTIONS __exidx_end = .; __etext = .; - {%- if flash_present %} - {% if ulp_mode_execution %} - .copysection : - { - . = ALIGN(4); - __copysection_start__ = .; - *(.copysection*) - __copysection_end__ = .; - } > rom - - .zerosection : - { - . = ALIGN(4); - __zerosection_start__ = .; - *(.zerosection*) - __zerosection_end__ = .; - } > rom - {% endif %} - {% endif %} - - {% if psram_present and psram_linker_config_enabled and psram_powersave_handle %} - _slpcode = __etext; - - . = _last_ram_location; - /* Power save & PSRAM driver code */ - .sleep_psram_driver : - { - __sleep_code_start__ = .; - /* _scode is used in code startup code */ - _scode = __sleep_code_start__; - . = ALIGN(4); - *rsi_deepsleep_soc.o(.text*) - *sl_si91x_psram.o(.text*) - *sl_si91x_psram_handle.o(.text*) - *rsi_qspi.o(.text*) - *rsi_pll.o(.text*) - *rsi_egpio.o(.text*) - *rsi_deepsleep_soc.o(.data*) - *sl_si91x_psram.o(.data*) - *sl_si91x_psram_handle.o(.data*) - *rsi_qspi.o(.data*) - *rsi_pll.o(.data*) - *rsi_egpio.o(.data*) - __sleep_code_end__ = .; - /* _ecode is used in code startup code */ - _ecode = __sleep_code_end__; - _last_ram_location = .; - {%- if text_segment_in_psram %} - } > ram AT> psram - - /* _sidata is used in code startup code */ - _sidata = __etext + (__sleep_code_end__ - __sleep_code_start__); - _last_psram_location = _sidata; - {%- elif flash_present %} - } > ram AT> rom - {%- else %} - } > ram - /* _sidata is used in code startup code */ - _sidata = __etext + (__sleep_code_end__ - __sleep_code_start__); - {% endif %} - {%- else %} /* _sidata is used in code startup code */ _sidata = __etext; - {% endif %} + + + - {%- if psram_present and psram_linker_config_enabled %} - {%- if data_segment_in_psram %} - . = _last_psram_location; - {%- else %} - . = _last_ram_location; - {% endif %} - {% endif %} - {%- if psram_present and psram_linker_config_enabled %} - .data . : - {%- else %} .data : - {% endif %} + { __data_start__ = .; /* _sdata is used in startup code */ _sdata = __data_start__; {%- if not power_manager_ps2 %} + {%- if ram_execution %} KEEP(*(.ramVector)) KEEP(*(.init)) KEEP(*(.fini)) *(.data*) - {% endif %} - {%- if ulp_mode_execution %} - *(.text*) - *(.rodata*) - KEEP(*(.init)) - KEEP(*(.fini)) - {% endif %} - {%- if ram_execution %} - {%- if not ulp_mode_execution %} *rsi_hal_mcu_m4_ram.o(.text*) *rsi_hal_mcu_m4_rom.o(.text*) *sl_si91x_driver.o(.text*) *sl_si91x_bus.o(.text*) - *UDMA.o(.text*) + *UDMA.o(.text*) *sl_sleeptimer.o(.text*) *sl_sleeptimer_hal_si91x_sysrtc.o(.text*) *rsi_sysrtc.o(.text*) *sl_si91x_low_power_tickless_mode.o(.text*) *sli_si91x_multithreaded.o(.text*) - {%- if not psram_linker_config_enabled %} *rsi_deepsleep_soc.o(.text*) - {%- endif %} *croutine.o(.text*) *event_groups.o(.text*) *list.o(.text*) @@ -335,17 +221,9 @@ SECTIONS *sl_rsi_utility.o(.text*) *port.o(.text*) *heap_*.o(.text*) - {%- elif ulp_mode_execution %} - *(.text*) - *(.rodata*) - *(.data*) - KEEP(*(.init)) - KEEP(*(.fini)) - {%- else %} - *(.data*) - {% endif %} {%- else %} *(.data*) + *UDMA.o(.text*) {% endif %} {% endif %} {%- if power_manager_ps2 %} @@ -385,7 +263,7 @@ SECTIONS *rsi_sysrtc.o(.text*) *sl_si91x_low_power_tickless_mode.o(.text*) *sl_core_cortexm.o(.text*) - *UDMA.o(.text*) + *UDMA.o(.text*) {% for c in debug_ps2 %}*{{c}}(.text*) {% endfor %}{% for c in calendar_ps2 %}*{{c}}(.text*) {% endfor %}{% for c in ulp_timer_ps2 %}*{{c}}(.text*) @@ -406,11 +284,7 @@ SECTIONS {% endfor %}{% for c in user_files_ps2 %}*{{c}}(.text*) {% endfor %} {% endif %} - {%- if udma_in_ram %} - *UDMA.o(.text*) - {% endif %} - - + . = ALIGN(4); /* preinit data */ PROVIDE_HIDDEN (__preinit_array_start = .); @@ -439,31 +313,11 @@ SECTIONS /* _edata is used in startup code */ _edata = __data_end__; - {%- if psram_present and data_segment_in_psram and not text_segment_in_psram and flash_present %} - _last_psram_location = .; - } > psram AT> rom - {%- elif psram_present and data_segment_in_psram and text_segment_in_psram %} - _last_psram_location = .; - } > psram - {%- elif psram_present and text_segment_in_psram %} - _last_ram_location = .; - } > ram AT> psram - {%- elif psram_present and psram_linker_config_enabled and flash_present %} - _last_ram_location = .; - } > ram AT> rom - {%- elif flash_present %} + {%- if flash_present %} } > ram AT> rom {%- else %} } > ram {% endif %} - - {%- if psram_present and psram_linker_config_enabled %} - {%- if bss_segment_in_psram %} - . = _last_psram_location; - {%- else %} - . = _last_ram_location; - {% endif %} - {% endif %} .bss (NOLOAD) : { @@ -473,23 +327,8 @@ SECTIONS *(COMMON) . = ALIGN(4); __bss_end__ = .; - {%- if psram_present and bss_segment_in_psram %} - _last_psram_location = .; - } > psram - {%- elif psram_present and psram_linker_config_enabled %} - _last_ram_location = .; - } > ram - {%- else %} } > ram - {% endif %} - - {%- if psram_present and psram_linker_config_enabled %} - {%- if stack_segment_in_psram %} - . = _last_psram_location; - {%- else %} - . = _last_ram_location; - {% endif %} - {% endif %} + .stack (NOLOAD): { @@ -497,24 +336,8 @@ SECTIONS KEEP(*(.stack*)) . = ALIGN(4); __StackTop = .; - PROVIDE(__stack = __StackTop); - {%- if psram_present and stack_segment_in_psram %} - _last_psram_location = .; - } > psram - {%- elif psram_present and psram_linker_config_enabled %} - _last_ram_location = .; - } > ram - {%- else %} + PROVIDE(__stack = __StackTop); } > ram - {% endif %} - - {%- if psram_present and psram_linker_config_enabled %} - {%- if heap_segment_in_psram %} - . = _last_psram_location; - {%- else %} - . = _last_ram_location; - {% endif %} - {% endif %} .heap (COPY): { __HeapBase = .; @@ -522,18 +345,10 @@ SECTIONS end = __end__; _end = __end__; KEEP(*(.heap*)) - {%- if psram_present and heap_segment_in_psram %} - . = ORIGIN(psram) + LENGTH(psram); - {%- else %} . = ORIGIN(ram) + LENGTH(ram); - {% endif %} - __HeapLimit = .; - {%- if psram_present and heap_segment_in_psram %} - _last_psram_location = .; - } > psram - {%- else %} + __HeapLimit = .; } > ram - {% endif %} + __heap_size = __HeapLimit - __HeapBase; @@ -542,26 +357,22 @@ SECTIONS .udma_addr0 : { *(.udma_addr0*) - {%- if psram_present and text_segment_in_psram %} - } > udma0 AT> psram - {%- else %} } > udma0 AT> rom - {% endif %} .udma_addr1 : { - *(.udma_addr1*) - {%- if psram_present and text_segment_in_psram %} - } > udma1 AT> psram - {%- else %} + *(.udma_addr1*) } > udma1 AT> rom - {%- endif %} {%- endif %} {% endif %} {%- if nvm3_enable %} __ram_end__ = 0x{{ '%0x' % app_ram_start }} + 0x{{ '%0x' % app_ram_size }}; - __main_flash_end__ = 0x{{ '%0x' % app_flash_start }} + 0x{{ '%0x' % app_flash_size }}; + {%- if app_flash_size >= nvm3_app_max_flash_size %} + __main_flash_end__ = 0x{{ '%0x' % app_flash_start }} + 0x{{ '%0x' % nvm3_app_max_flash_size }}; + {%- else %} + __main_flash_end__ = 0x{{ '%0x' % app_flash_start }} + 0x{{ '%0x' % app_flash_size }}; + {% endif %} /* This is where we handle flash storage blocks. We use dummy sections for finding the configured * block sizes and then "place" them at the end of flash when the size is known. */ .internal_storage1 (DSECT) : { @@ -585,6 +396,8 @@ SECTIONS {%- if littlefs_enable %} {%- if nvm3_enable %} __main_flash_end__ = linker_nvm_begin; +{%- elif app_flash_size >= nvm3_app_max_flash_size %} + __main_flash_end__ = 0x{{ '%0x' % app_flash_start }} + 0x{{ '%0x' % nvm3_app_max_flash_size }}; {%- else %} __main_flash_end__ = 0x{{ '%0x' % app_flash_start }} + 0x{{ '%0x' % app_flash_size }}; {%- endif %} diff --git a/components/device/silabs/si91x/mcu/toolchain/linkerfile_psram_SoC.ld.jinja b/components/device/silabs/si91x/mcu/toolchain/linkerfile_psram_SoC.ld.jinja new file mode 100644 index 000000000..28313d982 --- /dev/null +++ b/components/device/silabs/si91x/mcu/toolchain/linkerfile_psram_SoC.ld.jinja @@ -0,0 +1,489 @@ +/***************************************************************************//** + * GCC Linker script for Silicon Labs devices + ******************************************************************************* + * # License + * Copyright 2020 Silicon Laboratories Inc. www.silabs.com + ******************************************************************************* + * + * SPDX-License-Identifier: Zlib + * + * The licensor of this software is Silicon Laboratories Inc. + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + * + ******************************************************************************/ + +{#- + Device specific sizes and addresses. These variables describes the physical + memory of the device. +#} +{%- set sram_addr = device_ram_addr | first %} +{%- set sram_size = device_ram_size | first %} +{%- if flash_present %} + {%- set flash_addr = device_flash_addr | first %} + {%- set flash_size = device_flash_size | first %} +{%- endif %} +{%- set flash_page_size = device_flash_page_size | first %} + + +{%- if psram_present %} + {%- set psram_addr = device_psram_addr | first %} + {%- set psram_size = device_psram_size | first %} +{%- endif %} + +{%- if udma_enable %} + {%- set udma0_main_size = udma0_size | sum %} + {%- set udma0_start_addr = udma0 | sum %} + {%- set udma1_main_size = udma1_size | sum %} + {%- set udma1_start_addr = udma1 | sum %} +{%- endif %} + +{#- + Application specific sizes. Here we start to calculate the application view + of the physical memory. +#} +{%- if flash_present %} + {%- set app_flash_start = flash_addr %} + {%- set app_flash_end = flash_addr + flash_size %} +{%- endif %} +{%- set app_ram_start = sram_addr %} +{%- set app_ram_end = sram_size %} + +{%- if psram_present %} + {%- set app_psram_start = psram_addr %} + {%- if text_segment_in_psram %} + {#- Adds 0x1000 offset (4096 in decimal) #} + {%- set psram_start_offset = 4096 %} + {%- set app_psram_start = psram_addr + psram_start_offset %} + {%- endif %} + {%- set app_psram_end = psram_addr + psram_size %} +{%- endif %} + +{#- + Calculate application flash and ram size based on start and end address. +#} +{%- if flash_present %} +{%- set app_flash_size = app_flash_end - app_flash_start %} +{%- endif %} +{%- set app_ram_size = app_ram_end - app_ram_start %} + +{%- if udma_enable %} + {%- set udma_buffer = udma_buffer | sum %} + {%- set app_ram_size = app_ram_size - udma_buffer %} + {%- set udma0_start_addr = app_ram_size + app_ram_start %} + {%- set udma1_start_addr = udma1_start_addr - udma_buffer%} +{%- endif %} + +{%- if psram_present %} + {%- set app_psram_size = app_psram_end - app_psram_start %} +{%- endif %} + +{%- set rtt = 0 %} +{% if linker_rtt_section is defined %} +{%- set rtt = 1 %} +{% endif %} + + + MEMORY + { +{%- if flash_present %} + rom (rx) : ORIGIN = 0x{{ '%0x' % app_flash_start }}, LENGTH = 0x{{ '%0x' % app_flash_size }} +{% endif %} + ram (rwx) : ORIGIN = 0x{{ '%0x' % app_ram_start }}, LENGTH = 0x{{ '%0x' % app_ram_size }} + {%- if psram_present %} + psram (rwx) : ORIGIN = 0x{{ '%0x' % app_psram_start }}, LENGTH = 0x{{ '%0x' % app_psram_size }} + {%- endif %} + } + +{%- if udma_enable %} + MEMORY + { + udma0 (rwx) : ORIGIN = 0x{{ '%0x' % udma0_start_addr }}, LENGTH = 0x{{ '%0x' % udma0_main_size }} + udma1 (rwx) : ORIGIN = 0x{{ '%0x' % udma1_start_addr }}, LENGTH = 0x{{ '%0x' % udma1_main_size }} + } +{%- endif %} + +{%- if psram_present and psram_linker_config_enabled %} + +_last_psram_location = ORIGIN(psram); +_last_ram_location = ORIGIN(ram); +{%- endif %} + +ENTRY(Reset_Handler) + +SECTIONS +{ + .text : + { + KEEP(*(.isr_vector)) + {% if (psram_present and psram_linker_config_enabled and ram_execution) %} + KEEP(*(.reset_handler)) + *(EXCLUDE_FILE(*sl_si91x_bus.o *sl_si91x_driver.o *sli_si91x_multithreaded.o *rsi_deepsleep_soc.o *rsi_hal_mcu_m4_ram.o *rsi_hal_mcu_m4_rom.o *sl_sleeptimer.o *sl_sleeptimer_hal_si91x_sysrtc.o *rsi_sysrtc.o *sl_si91x_low_power_tickless_mode.o *croutine.o *event_groups.o *list.o *queue.o *stream_buffer.o *tasks.o *timers.o *cmsis_os2.o *freertos_umm_malloc_host.o *malloc_buffers.o *port.o *heap_*.o *sl_si91x_psram.o *rsi_qspi.o *rsi_pll.o *rsi_egpio.o *UDMA.o *sl_rsi_utility.o *ipmu_apis.o *rsi_d_cache.o) .text*) + {%- else %} + *(EXCLUDE_FILE(*UDMA.o).text*) + KEEP(*(.init)) + KEEP(*(.fini)) + {% endif %} + + /* .ctors */ + *crtbegin.o(.ctors) + *crtbegin?.o(.ctors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) + *(SORT(.ctors.*)) + *(.ctors) + + /* .dtors */ + *crtbegin.o(.dtors) + *crtbegin?.o(.dtors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) + *(SORT(.dtors.*)) + *(.dtors) + + *(.rodata*) + + KEEP(*(.eh_fram e*)) + {%- if psram_present and text_segment_in_psram %} + _last_psram_location = .; + } > psram + {%- elif flash_present %} + } > rom + {%- else %} + } > ram + {% endif %} + + .ARM.extab : + { + *(.ARM.extab* .gnu.linkonce.armextab.*) + {%- if psram_present and text_segment_in_psram %} + _last_psram_location = .; + } > psram + {%- elif flash_present %} + } > rom + {%- else %} + } > ram + {% endif %} + + __exidx_start = .; + .ARM.exidx : + { + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + {%- if psram_present and text_segment_in_psram %} + _last_psram_location = .; + } > psram + {%- elif flash_present %} + } > rom + {%- else %} + } > ram + {% endif %} + __exidx_end = .; + __etext = .; + +{% if data_segment_in_psram %} + {% if psram_present and psram_linker_config_enabled and ram_execution %} + _slpcode = __etext; + + . = _last_ram_location; + + /* Power save & PSRAM driver code */ + .sleep_psram_driver : + { + __sleep_code_start__ = .; + /* _scode is used in code startup code */ + _scode = __sleep_code_start__; + . = ALIGN(4); + KEEP(*(.ramVector)) + *rsi_deepsleep_soc.o(.text*) + *sl_si91x_psram.o(.text*) + *sl_si91x_psram_handle.o(.text*) + *rsi_qspi.o(.text*) + *rsi_pll.o(.text*) + *rsi_egpio.o(.text*) + *rsi_deepsleep_soc.o(.data*) + *sl_si91x_psram.o(.data*) + *sl_si91x_psram_handle.o(.data*) + *rsi_qspi.o(.data*) + *rsi_pll.o(.data*) + *rsi_egpio.o(.data*) + *rsi_hal_mcu_m4_ram.o(.text*) + *rsi_hal_mcu_m4_rom.o(.text*) + *sl_si91x_driver.o(.text*) + *sl_si91x_bus.o(.text*) + *UDMA.o(.text*) + *sl_sleeptimer.o(.text*) + *sl_sleeptimer_hal_si91x_sysrtc.o(.text*) + *rsi_sysrtc.o(.text*) + *sl_si91x_low_power_tickless_mode.o(.text*) + *sli_si91x_multithreaded.o(.text*) + *croutine.o(.text*) + *event_groups.o(.text*) + *list.o(.text*) + *queue.o(.text*) + *cmsis_os2.o(.text*) + *stream_buffer.o(.text*) + *tasks.o(.text*) + *timers.o(.text*) + *freertos_umm_malloc_host.o(.text*) + *malloc_buffers.o(.text*) + *sl_rsi_utility.o(.text*) + *port.o(.text*) + *heap_*.o(.text*) + *ipmu_apis.o(.text*) + *rsi_d_cache.o(.text*) + __sleep_code_end__ = .; + /* _ecode is used in code startup code */ + _ecode = __sleep_code_end__; + _last_ram_location = .; + {%- if text_segment_in_psram %} + } > ram AT> psram + + /* _sidata is used in code startup code */ + _sidata = __etext + (__sleep_code_end__ - __sleep_code_start__); + _last_psram_location = _sidata; + {%- elif data_segment_in_psram %} + } > ram AT> rom + + /* _sidata is used in code startup code */ + _sidata = __etext + (__sleep_code_end__ - __sleep_code_start__); + _last_ram_location = _sidata; + + {%- elif flash_present %} + } > ram AT> rom + {%- else %} + } > ram + + /* _sidata is used in code startup code */ + _sidata = __etext + (__sleep_code_end__ - __sleep_code_start__); + {% endif %} + {%- else %} + /* _sidata is used in code startup code */ + _sidata = __etext; + {% endif %} +{%- else %} + /* _sidata is used in code startup code */ + _sidata = __etext; +{% endif %} + + {%- if psram_present and psram_linker_config_enabled %} + {%- if data_segment_in_psram %} + . = _last_psram_location; + {%- else %} + . = _last_ram_location; + {% endif %} + {% endif %} + + {%- if psram_present and psram_linker_config_enabled %} + .data . : + {%- else %} + .data : + {% endif %} + { + __data_start__ = .; + + /* _sdata is used in startup code */ + _sdata = __data_start__; + + {%- if (ram_execution and not data_segment_in_psram) %} + KEEP(*(.ramVector)) + *rsi_deepsleep_soc.o(.text*) + *sl_si91x_psram.o(.text*) + *sl_si91x_psram_handle.o(.text*) + *rsi_qspi.o(.text*) + *rsi_pll.o(.text*) + *rsi_egpio.o(.text*) + *rsi_deepsleep_soc.o(.data*) + *sl_si91x_psram.o(.data*) + *sl_si91x_psram_handle.o(.data*) + *rsi_qspi.o(.data*) + *rsi_pll.o(.data*) + *rsi_egpio.o(.data*) + *rsi_hal_mcu_m4_ram.o(.text*) + *rsi_hal_mcu_m4_rom.o(.text*) + *sl_si91x_driver.o(.text*) + *sl_si91x_bus.o(.text*) + *UDMA.o(.text*) + *sl_sleeptimer.o(.text*) + *sl_sleeptimer_hal_si91x_sysrtc.o(.text*) + *rsi_sysrtc.o(.text*) + *sl_si91x_low_power_tickless_mode.o(.text*) + *sli_si91x_multithreaded.o(.text*) + *croutine.o(.text*) + *event_groups.o(.text*) + *list.o(.text*) + *queue.o(.text*) + *cmsis_os2.o(.text*) + *stream_buffer.o(.text*) + *tasks.o(.text*) + *timers.o(.text*) + *freertos_umm_malloc_host.o(.text*) + *malloc_buffers.o(.text*) + *sl_rsi_utility.o(.text*) + *port.o(.text*) + *heap_*.o(.text*) + *(.data*) + {%- else %} + *(.data*) + *UDMA.o(.text*) + {% endif %} + + . = ALIGN(4); + /* preinit data */ + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP(*(.preinit_array)) + PROVIDE_HIDDEN (__preinit_array_end = .); + + . = ALIGN(4); + /* init data */ + + PROVIDE_HIDDEN (__init_array_start = .); + KEEP(*(SORT(.init_array.*))) + KEEP(*(.init_array)) + PROVIDE_HIDDEN (__init_array_end = .); + + . = ALIGN(4); + /* finit data */ + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP(*(SORT(.fini_array.*))) + KEEP(*(.fini_array)) + PROVIDE_HIDDEN (__fini_array_end = .); + + KEEP(*(.jcr*)) + . = ALIGN(4); + /* All data end */ + __data_end__ = .; + + /* _edata is used in startup code */ + _edata = __data_end__; + {%- if psram_present and data_segment_in_psram and not text_segment_in_psram and flash_present %} + _last_psram_location = .; + } > psram AT> rom + {%- elif psram_present and data_segment_in_psram and text_segment_in_psram %} + _last_psram_location = .; + } > psram + {%- elif psram_present and text_segment_in_psram %} + _last_ram_location = .; + } > ram AT> psram + {%- elif psram_present and psram_linker_config_enabled and flash_present %} + _last_ram_location = .; + } > ram AT> rom + {%- elif flash_present %} + } > ram AT> rom + {%- else %} + } > ram + {% endif %} + + {%- if psram_present and psram_linker_config_enabled %} + {%- if bss_segment_in_psram %} + . = _last_psram_location; + {%- else %} + . = _last_ram_location; + {% endif %} + {% endif %} + + .bss (NOLOAD) : + { + . = ALIGN(4); + __bss_start__ = .; + *(.bss*) + *(COMMON) + . = ALIGN(4); + __bss_end__ = .; + {%- if psram_present and bss_segment_in_psram %} + _last_psram_location = .; + } > psram + {%- elif psram_present and psram_linker_config_enabled %} + _last_ram_location = .; + } > ram + {%- else %} + } > ram + {% endif %} + + {%- if psram_present and psram_linker_config_enabled %} + {%- if stack_segment_in_psram %} + . = _last_psram_location; + {%- else %} + . = _last_ram_location; + {% endif %} + {% endif %} + + .stack (NOLOAD): + { + __StackLimit = .; + KEEP(*(.stack*)) + . = ALIGN(4); + __StackTop = .; + PROVIDE(__stack = __StackTop); + {%- if psram_present and stack_segment_in_psram %} + _last_psram_location = .; + } > psram + {%- elif psram_present and psram_linker_config_enabled %} + _last_ram_location = .; + } > ram + {%- else %} + } > ram + {% endif %} + + {%- if psram_present and psram_linker_config_enabled %} + {%- if heap_segment_in_psram %} + . = _last_psram_location; + {%- else %} + . = _last_ram_location; + {% endif %} + {% endif %} + .heap (COPY): + { + __HeapBase = .; + __end__ = .; + end = __end__; + _end = __end__; + KEEP(*(.heap*)) + {%- if psram_present and heap_segment_in_psram %} + . = ORIGIN(psram) + LENGTH(psram); + {%- else %} + . = ORIGIN(ram) + LENGTH(ram); + {% endif %} + __HeapLimit = .; + {%- if psram_present and heap_segment_in_psram %} + _last_psram_location = .; + } > psram + {%- else %} + } > ram + {% endif %} + __heap_size = __HeapLimit - __HeapBase; + + +{%- if flash_present %} +{%- if udma_enable %} + .udma_addr0 : + { + *(.udma_addr0*) + {%- if psram_present and text_segment_in_psram %} + } > udma0 AT> psram + {%- else %} + } > udma0 AT> rom + {% endif %} + + .udma_addr1 : + { + *(.udma_addr1*) + {%- if psram_present and text_segment_in_psram %} + } > udma1 AT> psram + {%- else %} + } > udma1 AT> rom + {%- endif %} +{%- endif %} +{% endif %} +} diff --git a/components/device/silabs/si91x/wireless/ahb_interface/inc/rsi_m4.h b/components/device/silabs/si91x/wireless/ahb_interface/inc/rsi_m4.h index 1fe1f9061..7b76cf112 100644 --- a/components/device/silabs/si91x/wireless/ahb_interface/inc/rsi_m4.h +++ b/components/device/silabs/si91x/wireless/ahb_interface/inc/rsi_m4.h @@ -73,6 +73,14 @@ #define M4_wakeup_TA BIT(0) #define M4_is_active BIT(1) +/*Macro used to define the PTE CRC value of the Firmware 17 Boards*/ +#define FIRMWARE_17_PTE_CRC_VALUE 0 + +/*Macro used to notify TA about M4 XTAL usage*/ +#define TURN_ON_XTAL_REQUEST BIT(9) +#define TURN_OFF_XTAL_REQUEST BIT(10) +#define M4_IS_USING_XTAL_REQUEST BIT(11) + #define ARM_MASK_1 0xE000E100 #define ARM_MASK_1 0xE000E100 #define ARM_MASK_1 0xE000E100 @@ -155,7 +163,6 @@ typedef struct rsi_m4ta_desc_s { uint16_t length; //! descriptor control fields - //rsi_m4ta_desc_dword1_t dword1; } rsi_m4ta_desc_t; @@ -218,6 +225,12 @@ void rsi_update_tx_dma_desc(uint8_t skip_dma_valid); void rsi_update_rx_dma_desc(void); sl_status_t si91x_req_wakeup(void); void sl_si91x_ta_events_init(void); /*Function used to create and initialize event mechanism for TA related events */ - +bool sli_si91x_is_m4_using_xtal(void); +bool sli_si91x_is_xtal_in_use_by_m4(void); +void sli_si91x_set_m4_is_using_xtal(void); +void sli_si91x_set_xtal_in_use_by_m4(void); +void sli_si91x_xtal_turn_on_request_from_m4_to_TA(void); +void sli_si91x_raise_xtal_interrupt_to_ta(uint16_t xtal_enable); +void sli_si91x_send_m4_xtal_usage_notification_to_ta(void); #endif #endif diff --git a/components/device/silabs/si91x/wireless/ahb_interface/inc/sli_siwx917_soc.h b/components/device/silabs/si91x/wireless/ahb_interface/inc/sli_siwx917_soc.h index b695f99cb..f9ead2f67 100644 --- a/components/device/silabs/si91x/wireless/ahb_interface/inc/sli_siwx917_soc.h +++ b/components/device/silabs/si91x/wireless/ahb_interface/inc/sli_siwx917_soc.h @@ -43,7 +43,7 @@ #define HOST_INTERACT_REG_VALID_READ (0xAB << 8) #endif -#define RSI_RESET_LOOP_COUNTER(X) X = 0; +#define RSI_RESET_LOOP_COUNTER(X) X = 0 #define RSI_WHILE_LOOP(X, Y) while ((X++) < (uint32_t)Y) #define RSI_LOOP_COUNT_UPGRADE_IMAGE 0xFFFF #define RSI_LOOP_COUNT_WAKEUP_REQ 0xFFFFFFFF @@ -53,10 +53,10 @@ #define RSI_LOOP_COUNT_UPGRADE_STATUS 0xFFFF #define RSI_LOOP_COUNT_SELECT_OPTION 0xFFFF #define RSI_CHECK_LOOP_COUNTER(X, Y) \ - { \ + do { \ if (X >= Y) \ return -1; \ - } + } while (0) void sli_siwx917_update_system_core_clock(void); void RSI_Set_Cntrls_To_M4(void); @@ -69,4 +69,4 @@ int16_t rsi_select_option(uint8_t cmd); int16_t rsi_bl_select_option(uint8_t cmd); int16_t rsi_boot_insn(uint8_t type, uint16_t *data); int16_t rsi_mem_rd(uint32_t addr, uint16_t len, uint8_t *dBuf); -void sl_si91x_ulp_wakeup_init(void); \ No newline at end of file +void sl_si91x_ulp_wakeup_init(void); diff --git a/components/device/silabs/si91x/wireless/ahb_interface/inc/sli_siwx917_timer.h b/components/device/silabs/si91x/wireless/ahb_interface/inc/sli_siwx917_timer.h index d679a8e2d..e8def6ecc 100644 --- a/components/device/silabs/si91x/wireless/ahb_interface/inc/sli_siwx917_timer.h +++ b/components/device/silabs/si91x/wireless/ahb_interface/inc/sli_siwx917_timer.h @@ -39,7 +39,7 @@ typedef struct { void sl_si91x_timer_expiry_interrupt_handler(void); uint32_t sl_si91x_timer_read_counter(void); void sl_si91x_timer_init(sl_si91x_timer_t *timer, uint32_t duration); -int32_t sl_si91x_timer_expired(sl_si91x_timer_t *timer); -uint32_t sl_si91x_timer_left(sl_si91x_timer_t *timer); +int32_t sl_si91x_timer_expired(const sl_si91x_timer_t *timer); +uint32_t sl_si91x_timer_left(const sl_si91x_timer_t *timer); uint32_t rsi_hal_gettickcount(void); diff --git a/components/device/silabs/si91x/wireless/ahb_interface/src/rsi_hal_mcu_m4_rom.c b/components/device/silabs/si91x/wireless/ahb_interface/src/rsi_hal_mcu_m4_rom.c index bce91947b..e036746b0 100644 --- a/components/device/silabs/si91x/wireless/ahb_interface/src/rsi_hal_mcu_m4_rom.c +++ b/components/device/silabs/si91x/wireless/ahb_interface/src/rsi_hal_mcu_m4_rom.c @@ -21,6 +21,7 @@ #include "sl_device.h" #include "sl_rsi_utility.h" #include "rsi_m4.h" +#include "rsi_ipmu.h" #ifdef SL_WIFI_COMPONENT_INCLUDED #include "sl_si91x_host_interface.h" @@ -33,6 +34,9 @@ osEventFlagsId_t ta_events = NULL; #define SIDE_BAND_DONE (1 << 2) #endif +static bool m4_is_using_xtal_without_ta_notification; +static bool m4_using_xtal; + /** @addtogroup SOC4 * @{ */ @@ -46,7 +50,120 @@ void sli_si91x_raise_pkt_pending_interrupt_to_ta(void) { // Write the packet pending interrupt to TA register M4SS_P2P_INTR_SET_REG = TX_PKT_PENDING_INTERRUPT; - osEventFlagsWait(ta_events, TA_PKT_TX_DONE, (osFlagsWaitAny), osWaitForever); + osEventFlagsWait(ta_events, TA_PKT_TX_DONE, osFlagsWaitAny, osWaitForever); +} +/** + * @fn bool sli_si91x_is_m4_using_xtal(void); + * @brief This API is used to get the whether XTAL is enabled by M4 without notifying TA + * @return true : XTAL is enabled by M4 without notifying TA + * false : XTAL is not enabled by M4 + */ +bool sli_si91x_is_m4_using_xtal(void) +{ + return m4_is_using_xtal_without_ta_notification; +} +/** + * @fn void sli_si91x_set_m4_is_using_xtal(void); + * @brief This API is set XTAL is enabled by M4 without notifying TA + */ +void sli_si91x_set_m4_is_using_xtal(void) +{ + m4_is_using_xtal_without_ta_notification = true; +} + +/** + * @fn bool sli_si91x_is_xtal_in_use_by_m4(void); + * @brief This API is used to get the whether XTAL is used by M4 or any of HP peripherals + * @return true : XTAL is being used by M4 or HP peripherals + * false : XTAL is not being used + */ +bool sli_si91x_is_xtal_in_use_by_m4(void) +{ + return m4_using_xtal; +} + +/** + * @fn void sli_si91x_set_xtal_in_use_by_m4(void); + * @brief This API is used set XTAL is used by M4 or any of HP peripherals + */ +void sli_si91x_set_xtal_in_use_by_m4(void) +{ + m4_using_xtal = true; +} + +/** + * @fn void sli_si91x_xtal_turn_on_request_from_m4_to_TA(void); + * @brief This API is used to Notify TA that M4 requires XTAL clock source + */ +void sli_si91x_xtal_turn_on_request_from_m4_to_TA(void) +{ + if ((TASS_P2P_INTR_CLEAR_REG & TURN_ON_XTAL_REQUEST)) { + clear_ta_to_m4_interrupt(TURN_ON_XTAL_REQUEST); + } else { + /* Set M4 XTAL usage flag */ + sli_si91x_set_xtal_in_use_by_m4(); + + /* Confirm if the TA has completed its initialization process */ + if (sl_si91x_is_device_initialized()) { + /* Raise the turn ON xtal interrupt to TA */ + sli_si91x_raise_xtal_interrupt_to_ta(TURN_ON_XTAL_REQUEST); + /* If M4 is using XTAL then notify TA to turn ON XTAL during programing common flash*/ + sli_si91x_raise_xtal_interrupt_to_ta(M4_IS_USING_XTAL_REQUEST); + } + /*If the 'M4 Enabled XTAL without TA Notification, +* then after net initialization (TA device initialization), a request to turn on the XTAL will be sent to the TA*/ + else { + /* set XTAL is enabled by M4 without notifying TA */ + sli_si91x_set_m4_is_using_xtal(); + } + } +} + +/** + * @fn void sli_si91x_raise_xtal_interrupt_to_ta(uint16_t interrupt_no) + * @brief Raise the turn on/off xtal interrupt to TA + * @param[in] xtal_enable - true to enable xtal, false to disable xtal + * @return void + */ +void sli_si91x_raise_xtal_interrupt_to_ta(uint16_t interrupt_no) +{ + //! Wake up TA + P2P_STATUS_REG |= M4_WAKEUP_TA; + + //!wait for TA active + while (!(P2P_STATUS_REG & TA_IS_ACTIVE)) + ; + + // Write the turn_on_xtal interrupt to TA register + M4SS_P2P_INTR_SET_REG = interrupt_no; + + //! Poll for bit to clear + //!Wait for TA using flash bit + while (!(TASS_P2P_INTR_CLEAR_REG & interrupt_no)) + ; + clear_ta_to_m4_interrupt(interrupt_no); + + sl_si91x_host_clear_sleep_indicator(); +} + +/** + * @fn void sli_si91x_send_m4_xtal_usage_notification_to_ta(void); + * @brief This API sends a notification to the TA indicating whether + * the M4 core is currently utilizing the XTAL as its clock source. + */ +void sli_si91x_send_m4_xtal_usage_notification_to_ta(void) +{ + +#if !(SLI_SI91X_MCU_PSRAM_PRESENT) + /* Check whether M4 is using XTAL */ + if (sli_si91x_is_m4_using_xtal() == true) +#endif + { + /* If M4 is using XTAL then request TA to turn ON XTAL*/ + sli_si91x_raise_xtal_interrupt_to_ta(TURN_ON_XTAL_REQUEST); + /* If M4 is using XTAL then notify TA to turn ON XTAL during programing common flash*/ + sli_si91x_raise_xtal_interrupt_to_ta(M4_IS_USING_XTAL_REQUEST); + } } #ifdef SL_SI91X_SIDE_BAND_CRYPTO diff --git a/components/device/silabs/si91x/wireless/ahb_interface/src/sl_platform.c b/components/device/silabs/si91x/wireless/ahb_interface/src/sl_platform.c index fb27284cd..ac1824cd2 100644 --- a/components/device/silabs/si91x/wireless/ahb_interface/src/sl_platform.c +++ b/components/device/silabs/si91x/wireless/ahb_interface/src/sl_platform.c @@ -50,6 +50,10 @@ void sli_si91x_platform_init(void) // Set P2P Intr priority NVIC_SetPriority(SysTick_IRQn, SYSTICK_INTR_PRI); #endif + //On boot-up, verify the M4_wakeup_TA bit in the P2P status register and clearing the bit if it is set. + if ((P2P_STATUS_REG & M4_wakeup_TA)) { + P2P_STATUS_REG &= ~M4_wakeup_TA; + } } void sl_board_enable_vcom(void) diff --git a/components/device/silabs/si91x/wireless/ahb_interface/src/sl_platform_wireless.c b/components/device/silabs/si91x/wireless/ahb_interface/src/sl_platform_wireless.c index e2edd743c..c65f09828 100644 --- a/components/device/silabs/si91x/wireless/ahb_interface/src/sl_platform_wireless.c +++ b/components/device/silabs/si91x/wireless/ahb_interface/src/sl_platform_wireless.c @@ -197,6 +197,8 @@ void sli_si91x_configure_wireless_frontend_controls(uint32_t switch_sel) RSI_EGPIO_SetPinMux(EGPIO1, 0, GPIO7, 6); #endif break; + default: + break; } #endif } @@ -261,17 +263,16 @@ void sl_si91x_trigger_sleep(SLEEP_TYPE_T sleepType, #if (configUSE_TICKLESS_IDLE == 0) - volatile uint8_t delay; if ((osEventFlagsGet(si91x_events) | osEventFlagsGet(si91x_bus_events) | osEventFlagsGet(si91x_async_events)) #ifdef SL_SI91X_SIDE_BAND_CRYPTO || (osMutexGetOwner(side_band_crypto_mutex) != NULL) #endif - || ((sl_si91x_host_get_queue_packet_count((sl_si91x_queue_type_t)SI91X_COMMON_CMD) - | sl_si91x_host_get_queue_packet_count((sl_si91x_queue_type_t)SI91X_WLAN_CMD) - | sl_si91x_host_get_queue_packet_count((sl_si91x_queue_type_t)SI91X_NETWORK_CMD) - | sl_si91x_host_get_queue_packet_count((sl_si91x_queue_type_t)SI91X_SOCKET_CMD) - | sl_si91x_host_get_queue_packet_count((sl_si91x_queue_type_t)SI91X_BT_CMD) - | sl_si91x_host_get_queue_packet_count((sl_si91x_queue_type_t)SI91X_SOCKET_DATA)))) { + || (sl_si91x_host_get_queue_packet_count((sl_si91x_queue_type_t)SI91X_COMMON_CMD) + | sl_si91x_host_get_queue_packet_count((sl_si91x_queue_type_t)SI91X_WLAN_CMD) + | sl_si91x_host_get_queue_packet_count((sl_si91x_queue_type_t)SI91X_NETWORK_CMD) + | sl_si91x_host_get_queue_packet_count((sl_si91x_queue_type_t)SI91X_SOCKET_CMD) + | sl_si91x_host_get_queue_packet_count((sl_si91x_queue_type_t)SI91X_BT_CMD) + | sl_si91x_host_get_queue_packet_count((sl_si91x_queue_type_t)SI91X_SOCKET_DATA))) { return; } // Disabling the interrupts & clearing m4_is_active as m4 is going to sleep @@ -281,7 +282,7 @@ void sl_si91x_trigger_sleep(SLEEP_TYPE_T sleepType, P2P_STATUS_REG &= ~M4_is_active; P2P_STATUS_REG; // Adding delay to sync m4 with TA - for (delay = 0; delay < 10; delay++) { + for (volatile uint8_t delay = 0; delay < 10; delay++) { __ASM("NOP"); } @@ -318,12 +319,24 @@ void sl_si91x_trigger_sleep(SLEEP_TYPE_T sleepType, printf("RSI_CLK_M4SocClkConfig failed\n"); } + /* Check whether M4 is using XTAL */ + if (sli_si91x_is_xtal_in_use_by_m4() == true) { + /* If M4 is using XTAL then request TA to turn OFF XTAL as M4 is going to sleep */ + sli_si91x_raise_xtal_interrupt_to_ta(TURN_OFF_XTAL_REQUEST); + } + // Configure sleep parameters required by bootloader upon Wake-up - RSI_PS_RetentionSleepConfig(stack_address, (uint32_t)jump_cb_address, vector_offset, mode); + RSI_PS_RetentionSleepConfig(stack_address, jump_cb_address, vector_offset, mode); // Trigger M4 to sleep RSI_PS_EnterDeepSleep(sleepType, lf_clk_mode); + /* Check whether M4 is using XTAL */ + if (sli_si91x_is_xtal_in_use_by_m4() == true) { + /* If M4 is using XTAL then request TA to turn ON XTAL as M4 is going to sleep */ + sli_si91x_raise_xtal_interrupt_to_ta(TURN_ON_XTAL_REQUEST); + } + #ifdef SLI_SI917 // Upon wake up program wireless GPIO frontend switch controls if (frontend_switch_control != 0) { @@ -394,7 +407,7 @@ void sl_si91x_configure_ram_retention(uint32_t rams_in_use, uint32_t rams_retent RSI_PS_M4ssRamBanksPowerDown(rams_to_be_powered_down); /* Turn off Unused SRAM Core/Periphery domains*/ - RSI_PS_M4ssRamBanksPeriPowerDown(rams_in_use); + RSI_PS_M4ssRamBanksPeriPowerDown(rams_to_be_powered_down); /* Clear all RAM retention control before configuring the user RAM retentions*/ RSI_PS_ClrRamRetention(M4ULP_RAM16K_RETENTION_MODE_EN | TA_RAM_RETENTION_MODE_EN | M4ULP_RAM_RETENTION_MODE_EN); @@ -420,4 +433,4 @@ void sl_si91x_configure_ram_retention(uint32_t rams_in_use, uint32_t rams_retent } } -/** @} */ \ No newline at end of file +/** @} */ diff --git a/components/device/silabs/si91x/wireless/ahb_interface/src/sl_si91x_bus.c b/components/device/silabs/si91x/wireless/ahb_interface/src/sl_si91x_bus.c index 873a9165d..c9f263371 100644 --- a/components/device/silabs/si91x/wireless/ahb_interface/src/sl_si91x_bus.c +++ b/components/device/silabs/si91x/wireless/ahb_interface/src/sl_si91x_bus.c @@ -69,13 +69,13 @@ sl_status_t sli_si91x_submit_rx_pkt(void) rx_desc[0].addr = (M4_MEMORY_OFFSET_ADDRESS + (uint32_t)pkt_buffer); // Fill source address in the TX descriptors - rx_desc[0].length = (16); + rx_desc[0].length = 16; // Fill source address in the TX descriptors rx_desc[1].addr = (M4_MEMORY_OFFSET_ADDRESS + (uint32_t)(pkt_buffer + 16)); // Fill source address in the TX descriptors - rx_desc[1].length = (1600); + rx_desc[1].length = 1600; raise_m4_to_ta_interrupt(RX_BUFFER_VALID); @@ -107,13 +107,13 @@ sl_status_t sl_si91x_bus_write_frame(sl_si91x_packet_t *packet, const uint8_t *p tx_desc[0].addr = (M4_MEMORY_OFFSET_ADDRESS + (uint32_t)&packet->desc[0]); // Fill source address in the TX descriptors - tx_desc[0].length = (16); + tx_desc[0].length = 16; // Fill source address in the TX descriptors tx_desc[1].addr = (M4_MEMORY_OFFSET_ADDRESS + (uint32_t)payloadparam); // Fill source address in the TX descriptors - tx_desc[1].length = (size_param); + tx_desc[1].length = size_param; sli_si91x_raise_pkt_pending_interrupt_to_ta(); diff --git a/components/device/silabs/si91x/wireless/ahb_interface/src/sl_si91x_timer.c b/components/device/silabs/si91x/wireless/ahb_interface/src/sl_si91x_timer.c index 691b53949..caa2c9dac 100644 --- a/components/device/silabs/si91x/wireless/ahb_interface/src/sl_si91x_timer.c +++ b/components/device/silabs/si91x/wireless/ahb_interface/src/sl_si91x_timer.c @@ -18,12 +18,8 @@ /* Include files */ -//#include "rsi_driver.h" -//#include "rsi_timer.h" -//#include "rsi_hal.h" #include "sli_siwx917_timer.h" #include "sl_device.h" -//#include "cmsis_os2.h" /** @addtogroup DRIVER11 * @{ @@ -37,11 +33,6 @@ * */ -//void rsi_timer_expiry_interrupt_handler(void) -//{ -// rsi_driver_cb_non_rom->timer_counter++; -//} - /*==============================================*/ /** * @fn uint32_t rsi_timer_read_counter() @@ -56,7 +47,6 @@ uint32_t sl_si91x_timer_read_counter(void) extern uint32_t SystemCoreClock; #define CYCLES_PER_MILLISECOND (SystemCoreClock / 1000) return DWT->CYCCNT / CYCLES_PER_MILLISECOND; - // return osKernelGetTickCount(); } /*==============================================*/ @@ -85,7 +75,7 @@ void sl_si91x_timer_init(sl_si91x_timer_t *rsi_timer, uint32_t duration) * */ -int32_t sl_si91x_timer_expired(sl_si91x_timer_t *timer) +int32_t sl_si91x_timer_expired(const sl_si91x_timer_t *timer) { if ((sl_si91x_timer_read_counter() - (timer->start_time)) > (timer->timeout)) return 1; @@ -103,7 +93,7 @@ int32_t sl_si91x_timer_expired(sl_si91x_timer_t *timer) * */ -uint32_t sl_si91x_timer_left(sl_si91x_timer_t *timer) +uint32_t sl_si91x_timer_left(const sl_si91x_timer_t *timer) { int32_t left = (timer->timeout) - (sl_si91x_timer_read_counter() - (timer->start_time)); return (left < 0) ? 0 : left; diff --git a/components/device/silabs/si91x/wireless/ahb_interface/src/sli_siwx917_soc.c b/components/device/silabs/si91x/wireless/ahb_interface/src/sli_siwx917_soc.c index 4832d9399..83d661b97 100644 --- a/components/device/silabs/si91x/wireless/ahb_interface/src/sli_siwx917_soc.c +++ b/components/device/silabs/si91x/wireless/ahb_interface/src/sli_siwx917_soc.c @@ -49,30 +49,6 @@ typedef struct { #define SI91X_PING_BUFFER ((sli_si91x_pingpong_buffer_t *)(0x19000)) #define SI91X_PONG_BUFFER ((sli_si91x_pingpong_buffer_t *)(0x1A000)) -// #if defined(__GNUC__) -// #pragma GCC diagnostic push -// #pragma GCC diagnostic ignored "-Warray-bounds" -// #pragma GCC diagnostic ignored "-Wcast-align" -// #endif // __GNUC__ - -/** - *@} - */ -//static void rsi_mem_wr(uint32_t addr, uint16_t len, uint8_t *dBuf) -//{ -// UNUSED_PARAMETER(len); -// *(uint32_t *)addr = *(uint32_t *)dBuf; -//} - -//void rsi_mem_rd(uint32_t addr, uint16_t len, uint8_t *dBuf) -//{ -// UNUSED_PARAMETER(len); -// *(uint32_t *)dBuf = *(uint32_t *)addr; -//} -// #if defined(__GNUC__) -// #pragma GCC diagnostic pop -// #endif // __GNUC__ - /** * @fn int16_t rsi_bl_select_option(uint8_t cmd) * @brief Send firmware load request to module or update default configurations. @@ -193,55 +169,13 @@ int16_t sli_si91x_send_boot_instruction(uint8_t type, uint16_t *data) switch (type) { case RSI_REG_READ: - *data = SI91X_INTERFACE_OUT_REGISTER; + *data = (uint16_t)SI91X_INTERFACE_OUT_REGISTER; break; case RSI_REG_WRITE: SI91X_INTERFACE_IN_REGISTER = *data; break; - // case RSI_PING_WRITE: - // - // for (j = 0; j <= RSI_PING_PONG_CHUNK_SIZE / RSI_HAL_MAX_WR_BUFF_LEN; j++) { - // if (j == RSI_PING_PONG_CHUNK_SIZE / RSI_HAL_MAX_WR_BUFF_LEN) { - // len = (RSI_PING_PONG_CHUNK_SIZE % RSI_HAL_MAX_WR_BUFF_LEN); - // if (len == 0) { - // break; - // } - // } else { - // len = RSI_HAL_MAX_WR_BUFF_LEN; - // } - // rsi_mem_wr(RSI_PING_BUFFER_ADDR + offset, len, (uint8_t *)((uint32_t)data + offset)); - // if (retval < 0) { - // return retval; - // } - // offset += len; - // } - // SI91X_INTERFACE_IN_REGISTER = RSI_PING_AVAIL | RSI_HOST_INTERACT_REG_VALID; - // break; - // case RSI_PONG_WRITE: - // - // for (j = 0; j <= RSI_PING_PONG_CHUNK_SIZE / RSI_HAL_MAX_WR_BUFF_LEN; j++) { - // if (j == RSI_PING_PONG_CHUNK_SIZE / RSI_HAL_MAX_WR_BUFF_LEN) { - // len = (RSI_PING_PONG_CHUNK_SIZE % RSI_HAL_MAX_WR_BUFF_LEN); - // if (len == 0) { - // break; - // } - // } else { - // len = RSI_HAL_MAX_WR_BUFF_LEN; - // } - // retval = rsi_mem_wr(RSI_PONG_BUFFER_ADDR + offset, len, (uint8_t *)((uint32_t)data + offset)); - // if (retval < 0) { - // return retval; - // } - // offset += len; - // } - // // Perform the write operation - // local = (RSI_PONG_AVAIL | RSI_HOST_INTERACT_REG_VALID); - // - // SI91X_INTERFACE_IN_REGISTER = local; - // break; - case BURN_NWP_FW: cmd = BURN_NWP_FW | RSI_HOST_INTERACT_REG_VALID; @@ -250,7 +184,7 @@ int16_t sli_si91x_send_boot_instruction(uint8_t type, uint16_t *data) sl_si91x_timer_init(&timer_instance, 300); do { - read_data = SI91X_INTERFACE_OUT_REGISTER; + read_data = (uint16_t)SI91X_INTERFACE_OUT_REGISTER; if (sl_si91x_timer_expired(&timer_instance)) { return RSI_ERROR_FW_LOAD_OR_UPGRADE_TIMEOUT; } @@ -442,7 +376,7 @@ int16_t rsi_boot_insn(uint8_t type, uint16_t *data) switch (type) { case REG_READ: - *data = SI91X_INTERFACE_OUT_REGISTER; + *data = (uint16_t)SI91X_INTERFACE_OUT_REGISTER; break; case REG_WRITE: @@ -465,7 +399,7 @@ int16_t rsi_boot_insn(uint8_t type, uint16_t *data) RSI_RESET_LOOP_COUNTER(loop_counter); RSI_WHILE_LOOP((uint32_t)loop_counter, RSI_LOOP_COUNT_UPGRADE_IMAGE) { - read_data = SI91X_INTERFACE_OUT_REGISTER; + read_data = (uint16_t)SI91X_INTERFACE_OUT_REGISTER; if (read_data == (RSI_SEND_RPS_FILE | HOST_INTERACT_REG_VALID)) { break; } @@ -484,7 +418,7 @@ int16_t rsi_boot_insn(uint8_t type, uint16_t *data) RSI_RESET_LOOP_COUNTER(loop_counter); RSI_WHILE_LOOP((uint32_t)loop_counter, RSI_LOOP_COUNT_UPGRADE_IMAGE) { - read_data = SI91X_INTERFACE_OUT_REGISTER; + read_data = (uint16_t)SI91X_INTERFACE_OUT_REGISTER; if (read_data == (RSI_SEND_RPS_FILE | HOST_INTERACT_REG_VALID)) { break; } diff --git a/components/device/silabs/si91x/wireless/asynchronous_socket/inc/sl_si91x_socket.h b/components/device/silabs/si91x/wireless/asynchronous_socket/inc/sl_si91x_socket.h index 930698141..6eceb71e9 100644 --- a/components/device/silabs/si91x/wireless/asynchronous_socket/inc/sl_si91x_socket.h +++ b/components/device/silabs/si91x/wireless/asynchronous_socket/inc/sl_si91x_socket.h @@ -205,7 +205,7 @@ int sl_si91x_send_async(int socket, * @note The flags parameter is not currently supported. */ int sl_si91x_sendto(int socket, - uint8_t *buffer, + const uint8_t *buffer, size_t buffer_length, int32_t flags, const struct sockaddr *addr, @@ -235,7 +235,7 @@ int sl_si91x_sendto(int socket, * @note The flags parameter is not currently supported. */ int sl_si91x_sendto_async(int socket, - uint8_t *buffer, + const uint8_t *buffer, size_t buffer_length, int32_t flags, const struct sockaddr *to_addr, @@ -344,7 +344,7 @@ int sl_si91x_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, - struct timeval *timeout, + const struct timeval *timeout, select_callback callback); /** diff --git a/components/device/silabs/si91x/wireless/asynchronous_socket/src/sl_si91x_socket.c b/components/device/silabs/si91x/wireless/asynchronous_socket/src/sl_si91x_socket.c index 22766d1de..4f4d17a11 100644 --- a/components/device/silabs/si91x/wireless/asynchronous_socket/src/sl_si91x_socket.c +++ b/components/device/silabs/si91x/wireless/asynchronous_socket/src/sl_si91x_socket.c @@ -62,7 +62,7 @@ int sl_si91x_socket_async(int family, int type, int protocol, receive_data_callb return sli_si91x_socket(family, type, protocol, callback); } -int sli_si91x_socket(int family, int type, int protocol, receive_data_callback callback) +static int sli_si91x_socket(int family, int type, int protocol, receive_data_callback callback) { // Validate the socket parameters SET_ERRNO_AND_RETURN_IF_TRUE(family != AF_INET && family != AF_INET6, EAFNOSUPPORT); @@ -84,7 +84,7 @@ int sli_si91x_socket(int family, int type, int protocol, receive_data_callback c // Populate the socket structure with provided parameters and callbacks si91x_socket->type = type; - si91x_socket->local_address.sin6_family = family; + si91x_socket->local_address.sin6_family = (uint8_t)family; si91x_socket->protocol = protocol; si91x_socket->state = INITIALIZED; si91x_socket->recv_data_callback = callback; @@ -95,40 +95,7 @@ int sli_si91x_socket(int family, int type, int protocol, receive_data_callback c int sl_si91x_bind(int socket, const struct sockaddr *addr, socklen_t addr_len) { - // Retrieve the socket using the socket index - si91x_socket_t *si91x_socket = get_si91x_socket(socket); - struct sockaddr_in *socket_address = (struct sockaddr_in *)addr; - - // Check if the socket is valid - SET_ERRNO_AND_RETURN_IF_TRUE(si91x_socket == NULL || si91x_socket->state != INITIALIZED, EBADF); - SET_ERRNO_AND_RETURN_IF_TRUE( - (si91x_socket->local_address.sin6_family == AF_INET && addr_len < sizeof(struct sockaddr_in)) - || (si91x_socket->local_address.sin6_family == AF_INET6 && addr_len < sizeof(struct sockaddr_in6)), - EINVAL); - - // Check if the provided address is valid and if the specified port is available - SET_ERRNO_AND_RETURN_IF_TRUE(addr == NULL, EFAULT); - - if (!is_port_available(socket_address->sin_port)) { - SET_ERROR_AND_RETURN(EADDRINUSE); - } - - // Copy the provided address and set the socket state to BOUND - memcpy(&si91x_socket->local_address, - addr, - (addr_len > sizeof(struct sockaddr_in6)) ? sizeof(struct sockaddr_in6) : addr_len); - - si91x_socket->state = BOUND; - - // For UDP sockets, create and send a socket request. - if (si91x_socket->type == SOCK_DGRAM) { - sl_status_t socket_create_request_status = create_and_send_socket_request(socket, SI91X_SOCKET_LUDP, NULL); - SOCKET_VERIFY_STATUS_AND_RETURN(socket_create_request_status, SI91X_NO_ERROR, SI91X_UNDEFINED_ERROR); - - si91x_socket->state = UDP_UNCONNECTED_READY; - } - - return SI91X_NO_ERROR; + return sli_si91x_bind(socket, addr, addr_len); } int sl_si91x_connect(int socket, const struct sockaddr *addr, socklen_t addr_len) @@ -147,7 +114,7 @@ int sl_si91x_listen(int socket, int max_number_of_clients) SET_ERRNO_AND_RETURN_IF_TRUE(si91x_socket->type != SOCK_STREAM, EOPNOTSUPP); // Create and send a socket request to make it a TCP server with the specified maximum number of clients - status = create_and_send_socket_request(socket, SI91X_SOCKET_TCP_SERVER, (int *)&max_number_of_clients); + status = create_and_send_socket_request(socket, SI91X_SOCKET_TCP_SERVER, &max_number_of_clients); SOCKET_VERIFY_STATUS_AND_RETURN(status, SI91X_NO_ERROR, SI91X_UNDEFINED_ERROR); si91x_socket->state = LISTEN; @@ -172,25 +139,12 @@ int sl_si91x_accept_async(int socket, accept_callback callback) static int sli_si91x_accept_async(int socket, const struct sockaddr *addr, socklen_t addr_len, accept_callback callback) { - - // Get the server socket associated with the given socket ID - si91x_socket_t *si91x_server_socket = get_si91x_socket(socket); - si91x_socket_t *si91x_client_socket = NULL; - - // Create variables for context and client socket - sl_si91x_socket_context_t *context = NULL; - int *client_socket = NULL; - - // Create an accept request structure and LTCP response structure + sl_status_t status = SL_STATUS_OK; + si91x_socket_t *si91x_server_socket = + get_si91x_socket(socket); // Get the server socket associated with the given socket ID + si91x_socket_t *si91x_client_socket = NULL; sl_si91x_socket_accept_request_t accept_request = { 0 }; - sl_si91x_rsp_ltcp_est_t *ltcp = NULL; - - sl_wifi_buffer_t *buffer = NULL; - sl_si91x_packet_t *packet = NULL; - sl_si91x_wait_period_t wait_time = 0; - - sl_status_t status = SL_STATUS_OK; - int32_t client_socket_id = -1; + int32_t client_socket_id = -1; // Check if the server socket is valid SET_ERRNO_AND_RETURN_IF_TRUE(si91x_server_socket == NULL, EBADF); @@ -210,58 +164,34 @@ static int sli_si91x_accept_async(int socket, const struct sockaddr *addr, sockl memcpy(&si91x_client_socket->local_address, &si91x_server_socket->local_address, sizeof(struct sockaddr_in6)); // Create accept request - accept_request.socket_id = si91x_server_socket->id; + accept_request.socket_id = (uint8_t)si91x_server_socket->id; accept_request.source_port = si91x_server_socket->local_address.sin6_port; - // Set the wait time based on whether a callback is provided - wait_time = - (callback == NULL ? (SL_SI91X_WAIT_FOR_EVER | SL_SI91X_WAIT_FOR_RESPONSE_BIT) : SL_SI91X_RETURN_IMMEDIATELY); - + // Set the callback and client socket ID. + sli_si91x_set_accept_callback(si91x_server_socket, callback, client_socket_id); if (callback != NULL) { - // Set the callback and client socket ID. - sli_si91x_set_accept_callback(callback, client_socket_id); status = sl_si91x_driver_send_async_command(RSI_WLAN_REQ_SOCKET_ACCEPT, SI91X_SOCKET_CMD_QUEUE, &accept_request, sizeof(accept_request)); SOCKET_VERIFY_STATUS_AND_RETURN(status, SL_STATUS_OK, SI91X_UNDEFINED_ERROR); - return SI91X_NO_ERROR; + return SL_STATUS_OK; } else { - status = sl_si91x_driver_send_command(RSI_WLAN_REQ_SOCKET_ACCEPT, - SI91X_SOCKET_CMD_QUEUE, - &accept_request, - sizeof(accept_request), - wait_time, - context, - &buffer); + status = sli_si91x_sync_accept_command(si91x_server_socket, (void *)&accept_request, sizeof(accept_request)); } // If the accept request fails, clean up allocated memory and return an error if (status != SL_STATUS_OK) { - SL_CLEANUP_MALLOC(client_socket); - SL_CLEANUP_MALLOC(context); close(client_socket_id); - if (buffer != NULL) - sl_si91x_host_free_buffer(buffer); SET_ERROR_AND_RETURN(SI91X_UNDEFINED_ERROR); } - // Extract LTCP response from the received buffer - packet = sl_si91x_host_get_buffer_data(buffer, 0, NULL); - ltcp = (sl_si91x_rsp_ltcp_est_t *)packet->data; - - // Handle the accept response and update the client socket's state - handle_accept_response(client_socket_id, ltcp); - sl_si91x_host_free_buffer(buffer); - - if (addr_len <= 0) { - return client_socket_id; + if ((addr != NULL) && (addr_len > 0)) { + memcpy((struct sockaddr *)&addr, + &si91x_client_socket->remote_address, + (addr_len > sizeof(struct sockaddr_in6)) ? sizeof(struct sockaddr_in6) : addr_len); } - memcpy((struct sockaddr *)&addr, - &si91x_client_socket->remote_address, - (addr_len > sizeof(struct sockaddr_in6)) ? sizeof(struct sockaddr_in6) : addr_len); - return client_socket_id; } @@ -282,7 +212,7 @@ int sl_si91x_setsockopt_async(int32_t sockID, SET_ERRNO_AND_RETURN_IF_TRUE(si91x_socket == NULL, EBADF); // Check if the option value is not NULL - SET_ERRNO_AND_RETURN_IF_TRUE(option_value == NULL, EFAULT) + SET_ERRNO_AND_RETURN_IF_TRUE(option_value == NULL, EFAULT); switch (option_name) { case SL_SI91X_SO_RCVTIME: { @@ -294,7 +224,7 @@ int sl_si91x_setsockopt_async(int32_t sockID, timeout->tv_usec = 1000; } // Calculate the timeout value in milliseconds - timeout_val = (timeout->tv_usec / 1000) + (timeout->tv_sec * 1000); + timeout_val = (uint16_t)((timeout->tv_usec / 1000) + (timeout->tv_sec * 1000)); // Need to add check here if Synchronous bit map is set (after async socket_id implementation) memcpy(&si91x_socket->read_timeout, @@ -306,14 +236,14 @@ int sl_si91x_setsockopt_async(int32_t sockID, case SL_SI91X_SO_MAXRETRY: { // Set the maximum number of TCP retries memcpy(&si91x_socket->max_tcp_retries, - (uint16_t *)option_value, + (const uint16_t *)option_value, GET_SAFE_MEMCPY_LENGTH(sizeof(si91x_socket->max_tcp_retries), option_len)); break; } case SL_SI91X_SO_MSS: { memcpy(&si91x_socket->mss, - (uint16_t *)option_value, + (const uint16_t *)option_value, GET_SAFE_MEMCPY_LENGTH(sizeof(si91x_socket->mss), option_len)); break; } @@ -321,7 +251,7 @@ int sl_si91x_setsockopt_async(int32_t sockID, case SL_SI91X_SO_TCP_KEEPALIVE: { // Set the TCP keep-alive initial time memcpy(&si91x_socket->tcp_keepalive_initial_time, - (uint16_t *)option_value, + (const uint16_t *)option_value, GET_SAFE_MEMCPY_LENGTH(sizeof(si91x_socket->tcp_keepalive_initial_time), option_len)); break; } @@ -362,10 +292,16 @@ int sl_si91x_setsockopt_async(int32_t sockID, case SL_SI91X_SO_SOCK_VAP_ID: { // Set the VAP ID for the socket - si91x_socket->vap_id = *((uint8_t *)option_value); + si91x_socket->vap_id = *((const uint8_t *)option_value); break; } + case SL_SI91x_SO_TCP_ACK_INDICATION: { + // Enable TCP_ACK_INDICATION + SET_ERRNO_AND_RETURN_IF_TRUE((*(uint8_t *)option_value) != SI91X_SOCKET_FEAT_TCP_ACK_INDICATION, EINVAL); + si91x_socket->socket_bitmap |= SI91X_SOCKET_FEAT_TCP_ACK_INDICATION; + break; + } #ifdef SLI_SI917 case SL_SI91X_SO_SSL_V_1_3_ENABLE: { // Enable SSL version 1.3 for the socket. @@ -376,23 +312,18 @@ int sl_si91x_setsockopt_async(int32_t sockID, } #endif - // case si91x_SO_TCP_ACK_INDICATION:{ - // SET_ERRNO_AND_RETURN_IF_TRUE(*(uint8_t *)option_value !=SI91X_SOCKET_FEAT_TCP_ACK_INDICATION,EINVAL ); - // si91x_socket->ssl_bitmap |= SI91X_SOCKET_FEAT_TCP_ACK_INDICATION; - // break; - // } case SL_SI91X_SO_CERT_INDEX: { SET_ERRNO_AND_RETURN_IF_TRUE( ((*(uint8_t *)option_value < SI91X_CERT_INDEX_0) || (*(uint8_t *)option_value > SI91X_CERT_INDEX_2)), EINVAL); - si91x_socket->certificate_index = *(uint8_t *)option_value; + si91x_socket->certificate_index = *(const uint8_t *)option_value; break; } case SL_SI91X_SO_TLS_SNI: { sl_status_t status = add_server_name_indication_extension(&si91x_socket->sni_extensions, - (si91x_socket_type_length_value_t *)option_value); + (const si91x_socket_type_length_value_t *)option_value); if (status != SL_STATUS_OK) { SET_ERROR_AND_RETURN(ENOMEM); @@ -402,9 +333,10 @@ int sl_si91x_setsockopt_async(int32_t sockID, #ifdef SLI_SI917 case SL_SI91X_SO_MAX_RETRANSMISSION_TIMEOUT_VALUE: { - if (IS_POWER_OF_TWO((*(uint8_t *)option_value)) && ((*(uint8_t *)option_value) < MAX_RETRANSMISSION_TIME_VALUE)) { + if (IS_POWER_OF_TWO((*(uint8_t *)option_value)) + && ((*(const uint8_t *)option_value) < MAX_RETRANSMISSION_TIME_VALUE)) { memcpy(&si91x_socket->max_retransmission_timeout_value, - (uint8_t *)option_value, + (const uint8_t *)option_value, GET_SAFE_MEMCPY_LENGTH(sizeof(si91x_socket->max_retransmission_timeout_value), option_len)); } else { SL_DEBUG_LOG("\n Max retransmission timeout value in between 1 - 32 and " @@ -433,11 +365,11 @@ int sl_si91x_send_async(int socket, int32_t flags, data_transfer_complete_handler callback) { - return sl_si91x_sendto_async(socket, (uint8_t *)buffer, buffer_length, flags, NULL, 0, callback); + return sl_si91x_sendto_async(socket, buffer, buffer_length, flags, NULL, 0, callback); } int sl_si91x_sendto(int socket, - uint8_t *buffer, + const uint8_t *buffer, size_t buffer_length, int32_t flags, const struct sockaddr *addr, @@ -448,11 +380,11 @@ int sl_si91x_sendto(int socket, int sl_si91x_send_large_data(int socket, const uint8_t *buffer, size_t buffer_length, int32_t flags) { - si91x_socket_t *si91x_socket = get_si91x_socket(socket); - int bsd_ret_code = 0; - size_t offset = 0; - size_t chunk_size = 0; - size_t max_len = 0; + const si91x_socket_t *si91x_socket = get_si91x_socket(socket); + int bsd_ret_code = 0; + size_t offset = 0; + size_t chunk_size = 0; + size_t max_len = 0; SET_ERRNO_AND_RETURN_IF_TRUE(si91x_socket == NULL, EBADF); SET_ERRNO_AND_RETURN_IF_TRUE(si91x_socket->state == RESET || si91x_socket->state == INITIALIZED, EBADF); @@ -485,7 +417,7 @@ int sl_si91x_send_large_data(int socket, const uint8_t *buffer, size_t buffer_le } int sl_si91x_sendto_async(int socket, - uint8_t *buffer, + const uint8_t *buffer, size_t buffer_length, int32_t flags, const struct sockaddr *to_addr, @@ -502,6 +434,9 @@ int sl_si91x_sendto_async(int socket, SET_ERRNO_AND_RETURN_IF_TRUE(si91x_socket == NULL, EBADF); SET_ERRNO_AND_RETURN_IF_TRUE(si91x_socket->type == SOCK_STREAM && si91x_socket->state != CONNECTED, ENOTCONN); SET_ERRNO_AND_RETURN_IF_TRUE(buffer == NULL, EFAULT); + if (si91x_socket->socket_bitmap & SI91X_SOCKET_FEAT_TCP_ACK_INDICATION) { + SET_ERRNO_AND_RETURN_IF_TRUE(si91x_socket->is_waiting_on_ack == true, EWOULDBLOCK); + } SET_ERRNO_AND_RETURN_IF_TRUE(si91x_socket->state != CONNECTED && to_addr == NULL, EFAULT); // Set the data transfer callback for this socket @@ -520,6 +455,10 @@ int sl_si91x_sendto_async(int socket, : DEFAULT_STREAM_MSS_SIZE_IPV6; SET_ERRNO_AND_RETURN_IF_TRUE(buffer_length > max_size, EMSGSIZE); } + if (si91x_socket->socket_bitmap & SI91X_SOCKET_FEAT_TCP_ACK_INDICATION) { + // When using SOCK_STREAM (TCP), socket will wait for an ack if the SI91X_SOCKET_FEAT_TCP_ACK_INDICATION bit is set. + si91x_socket->is_waiting_on_ack = true; + } } else if (si91x_socket->type == SOCK_DGRAM) { // For SOCK_DGRAM (UDP), check the message size against the default maximum size size_t max_size = (si91x_socket->local_address.sin6_family == AF_INET) ? DEFAULT_DATAGRAM_MSS_SIZE_IPV4 @@ -528,7 +467,7 @@ int sl_si91x_sendto_async(int socket, } if (si91x_socket->type == SOCK_DGRAM && (si91x_socket->state == BOUND || si91x_socket->state == INITIALIZED)) { - sl_status_t status = create_and_send_socket_request(socket, SI91X_SOCKET_LUDP, NULL); + status = create_and_send_socket_request(socket, SI91X_SOCKET_LUDP, NULL); SET_ERRNO_AND_RETURN_IF_TRUE(status != SL_STATUS_OK, SI91X_UNDEFINED_ERROR); si91x_socket->state = UDP_UNCONNECTED_READY; @@ -542,15 +481,15 @@ int sl_si91x_sendto_async(int socket, si91x_socket->state == UDP_UNCONNECTED_READY && ((si91x_socket->local_address.sin6_family == AF_INET && to_addr_len < sizeof(struct sockaddr_in)) || (si91x_socket->local_address.sin6_family == AF_INET6 && to_addr_len < sizeof(struct sockaddr_in6))), - EINVAL) + EINVAL); // create a socket send request if (si91x_socket->local_address.sin6_family == AF_INET6) { // If the socket uses IPv6, set the IP version and destination IPv6 address - struct sockaddr_in6 *socket_address = (struct sockaddr_in6 *)to_addr; - request.ip_version = SL_IPV6_ADDRESS_LENGTH; + const struct sockaddr_in6 *socket_address = (const struct sockaddr_in6 *)to_addr; + request.ip_version = SL_IPV6_ADDRESS_LENGTH; request.data_offset = (si91x_socket->type == SOCK_STREAM) ? TCP_V6_HEADER_LENGTH : UDP_V6_HEADER_LENGTH; - uint8_t *destination_ip = + const uint8_t *destination_ip = (si91x_socket->state == UDP_UNCONNECTED_READY || to_addr_len >= sizeof(struct sockaddr_in6)) ? socket_address->sin6_addr.__u6_addr.__u6_addr8 : si91x_socket->remote_address.sin6_addr.__u6_addr.__u6_addr8; @@ -561,22 +500,25 @@ int sl_si91x_sendto_async(int socket, struct sockaddr_in *socket_address = (struct sockaddr_in *)to_addr; request.ip_version = SL_IPV4_ADDRESS_LENGTH; request.data_offset = (si91x_socket->type == SOCK_STREAM) ? TCP_HEADER_LENGTH : UDP_HEADER_LENGTH; - uint32_t *destination_ip = + uint32_t destination_ip = (si91x_socket->state == UDP_UNCONNECTED_READY || to_addr_len >= sizeof(struct sockaddr_in)) - ? &socket_address->sin_addr.s_addr - : &((struct sockaddr_in *)&si91x_socket->remote_address)->sin_addr.s_addr; + ? socket_address->sin_addr.s_addr + : ((struct sockaddr_in *)&si91x_socket->remote_address)->sin_addr.s_addr; - memcpy(&request.dest_ip_addr.ipv4_address[0], destination_ip, SL_IPV4_ADDRESS_LENGTH); + memcpy(&request.dest_ip_addr.ipv4_address[0], &destination_ip, SL_IPV4_ADDRESS_LENGTH); } // Set other parameters in the send request - request.socket_id = si91x_socket->id; - request.dest_port = ((si91x_socket->state == UDP_UNCONNECTED_READY || to_addr_len > 0)) - ? ((struct sockaddr_in *)to_addr)->sin_port + request.socket_id = (uint16_t)si91x_socket->id; + request.dest_port = (si91x_socket->state == UDP_UNCONNECTED_READY || to_addr_len > 0) + ? ((const struct sockaddr_in *)to_addr)->sin_port : si91x_socket->remote_address.sin6_port; request.length = buffer_length; // Send the socket data status = sl_si91x_driver_send_socket_data(&request, buffer, 0); + if (status != SL_STATUS_OK && (si91x_socket->socket_bitmap & SI91X_SOCKET_FEAT_TCP_ACK_INDICATION)) { + si91x_socket->is_waiting_on_ack = false; + } SOCKET_VERIFY_STATUS_AND_RETURN(status, SL_STATUS_OK, ENOBUFS); return buffer_length; @@ -584,7 +526,7 @@ int sl_si91x_sendto_async(int socket, int sl_si91x_recv(int socket, uint8_t *buf, size_t buf_len, int32_t flags) { - return recvfrom(socket, buf, buf_len, flags, NULL, NULL); + return sl_si91x_recvfrom(socket, buf, buf_len, flags, NULL, NULL); } int sl_si91x_recvfrom(int socket, @@ -597,14 +539,14 @@ int sl_si91x_recvfrom(int socket, UNUSED_PARAMETER(flags); // Initialize variables for socket communication - sl_si91x_wait_period_t wait_time = 0; - sl_si91x_req_socket_read_t request = { 0 }; - uint32_t event = NCP_HOST_SOCKET_RESPONSE_EVENT; - ssize_t bytes_read = 0; - si91x_rsp_socket_recv_t *response = NULL; - si91x_socket_t *si91x_socket = get_si91x_socket(socket); - sl_wifi_buffer_t *buffer = NULL; - void *sdk_context = NULL; + sl_si91x_wait_period_t wait_time = 0; + sl_si91x_req_socket_read_t request = { 0 }; + uint32_t event = NCP_HOST_SOCKET_RESPONSE_EVENT; + ssize_t bytes_read = 0; + sl_si91x_socket_metadata_t *response = NULL; + si91x_socket_t *si91x_socket = get_si91x_socket(socket); + sl_wifi_buffer_t *buffer = NULL; + void *sdk_context = NULL; // Check if the socket is valid SET_ERRNO_AND_RETURN_IF_TRUE(si91x_socket == NULL, EBADF); @@ -614,7 +556,7 @@ int sl_si91x_recvfrom(int socket, SET_ERRNO_AND_RETURN_IF_TRUE(buf == NULL, EFAULT); // Check if the specified buffer length is valid - SET_ERRNO_AND_RETURN_IF_TRUE(buf_len <= 0, EINVAL) + SET_ERRNO_AND_RETURN_IF_TRUE(buf_len <= 0, EINVAL); // create and send a socket request to configure it as UDP. if (si91x_socket->type == SOCK_DGRAM && (si91x_socket->state == BOUND || si91x_socket->state == INITIALIZED)) { @@ -625,7 +567,7 @@ int sl_si91x_recvfrom(int socket, } // Possible states are only reset and disconnected. - SET_ERRNO_AND_RETURN_IF_TRUE(si91x_socket->state != CONNECTED && si91x_socket->state != UDP_UNCONNECTED_READY, EBADF) + SET_ERRNO_AND_RETURN_IF_TRUE(si91x_socket->state != CONNECTED && si91x_socket->state != UDP_UNCONNECTED_READY, EBADF); // Limit the buffer length based on the socket type if (si91x_socket->type == SOCK_STREAM) { @@ -639,7 +581,7 @@ int sl_si91x_recvfrom(int socket, } // Initialize the socket read request with the socket ID and requested buffer length - request.socket_id = si91x_socket->id; + request.socket_id = (uint8_t)si91x_socket->id; sdk_context = &(request.socket_id); memcpy(request.requested_bytes, &buf_len, sizeof(buf_len)); wait_time = (SL_SI91X_WAIT_FOR_EVER | SL_SI91X_WAIT_FOR_RESPONSE_BIT); @@ -660,7 +602,7 @@ int sl_si91x_recvfrom(int socket, sl_si91x_host_free_buffer(buffer); } - SOCKET_VERIFY_STATUS_AND_RETURN(status, SL_STATUS_OK, SI91X_UNDEFINED_ERROR) + SOCKET_VERIFY_STATUS_AND_RETURN(status, SL_STATUS_OK, SI91X_UNDEFINED_ERROR); // Determine the number of bytes read, considering the buffer length and response length bytes_read = (response->length <= buf_len) ? response->length : buf_len; @@ -700,13 +642,21 @@ int sl_si91x_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, - struct timeval *timeout, + const struct timeval *timeout, select_callback callback) { UNUSED_PARAMETER(exceptfds); sl_status_t status = SL_STATUS_OK; + if (callback == NULL) { + int total_fd_set_count = select(nfds, readfds, writefds, exceptfds, timeout); + if (total_fd_set_count == 0 || total_fd_set_count == -1) { + return SI91X_UNDEFINED_ERROR; + } + return SI91X_NO_ERROR; + } + // Define a structure to hold the select request parameters sl_si91x_socket_select_req_t request = { 0 }; @@ -732,7 +682,7 @@ int sl_si91x_select(int nfds, for (uint8_t host_socket_index = 0; host_socket_index < nfds; host_socket_index++) { // Retrieve the si91x_socket associated with the host socket index - si91x_socket_t *socket = get_si91x_socket(host_socket_index); + const si91x_socket_t *socket = get_si91x_socket(host_socket_index); // Throw error if the socket file descriptor set by developer is not valid if (socket == NULL @@ -747,30 +697,26 @@ int sl_si91x_select(int nfds, continue; } - if (readfds != NULL) { - // Check if the socket is set for read operations in the readfds set - if (FD_ISSET(host_socket_index, readfds)) { - // Set the corresponding bit in the read file descriptor set - request.read_fds.fd_array[0] |= (1U << socket->id); - } + // Check if the socket is set for read operations in the readfds set + // Set the corresponding bit in the read file descriptor set + if ((readfds != NULL) && (FD_ISSET(host_socket_index, readfds))) { + request.read_fds.fd_array[0] |= (1U << socket->id); } - if (writefds != NULL) { - // Check if the socket is set for write operations in the writefds set - if (FD_ISSET(host_socket_index, writefds)) { - // Set the corresponding bit in the write file descriptor set - request.write_fds.fd_array[0] |= (1U << socket->id); - } + // Check if the socket is set for write operations in the writefds set + // Set the corresponding bit in the write file descriptor set + if ((writefds != NULL) && (FD_ISSET(host_socket_index, writefds))) { + request.write_fds.fd_array[0] |= (1U << socket->id); } // Update the maximum file descriptor number encountered if (request.num_fd <= socket->id) { - request.num_fd = socket->id + 1; + request.num_fd = (uint8_t)(socket->id + 1); } } // Check if a timeout value is provided - if (timeout != NULL && ((timeout->tv_sec != 0) || (timeout->tv_usec != 0))) { + if (timeout != NULL) { request.select_timeout.tv_sec = timeout->tv_sec; request.select_timeout.tv_usec = timeout->tv_usec; } else { diff --git a/components/device/silabs/si91x/wireless/ble/inc/rsi_ble.h b/components/device/silabs/si91x/wireless/ble/inc/rsi_ble.h index 5c0daebc2..89b593f20 100644 --- a/components/device/silabs/si91x/wireless/ble/inc/rsi_ble.h +++ b/components/device/silabs/si91x/wireless/ble/inc/rsi_ble.h @@ -48,7 +48,6 @@ #define BLE_AE_REPORTING_ENABLED 0x00 #define BLE_AE_PERODIC_DUPLICATE_FILTERING_ENABLED 0x01 #define BLE_AE_PERODIC_DUPLICATE_FILTERING_DISABLED 0x00 -#define BLE_AE_PERIODIC_LIST_NOT_USED 0x00 #define BLE_AE_PERIODIC_LIST_USED 0x01 /****************************************************** @@ -1067,9 +1066,6 @@ typedef struct rsi_ble_get_local_att_value_s { typedef struct rsi_ble_gatt_read_response_s { //uint8[6], remote device address. uint8_t dev_addr[RSI_DEV_ADDR_LEN]; - //uint8[2], attribute handle. - // uint16_t handle; - // uint16_t offset; uint8_t type; uint8_t reserved; //uint8[2], attribute value length. @@ -1130,12 +1126,10 @@ typedef struct rsi_ble_att_error_response_s { uint8_t err_code; } rsi_ble_att_error_response_t; -//accept list(cmd), cmd_ix = 0x00AB typedef struct rsi_ble_gatt_remove_serv_s { uint32_t serv_hndler; } rsi_ble_gatt_remove_serv_t; -//accept list(cmd), cmd_ix = 0x00AC typedef struct rsi_ble_gatt_remove_att_s { uint32_t serv_hndler; uint16_t att_hndl; @@ -1160,11 +1154,11 @@ typedef struct rsi_ble_mtu_exchange_resp_s { } rsi_ble_mtu_exchange_resp_t; typedef struct rsi_ble_ae_get_supported_no_of_adv_sets_s { - uint16_t reserved; //sets_cnt; + uint16_t reserved; } SL_ATTRIBUTE_PACKED rsi_ble_ae_get_supported_no_of_adv_sets_t; typedef struct rsi_ble_ae_read_supported_max_adv_data_s { - uint16_t reserved; //max_adv_data_len; + uint16_t reserved; } SL_ATTRIBUTE_PACKED rsi_ble_ae_read_supported_max_adv_data_t; // AE Set Random Address (cmd), cmd_ix = @@ -1432,7 +1426,6 @@ typedef struct rsi_ble_ae_set_scan_enable_s { uint16_t period; } SL_ATTRIBUTE_PACKED rsi_ble_ae_set_scan_enable_t; -//#pragma pack(push, 1) typedef struct rsi_ble_ae_set_periodic_adv_create_sync_s { /** uint8_t, Options field, The Options parameter is used to determine whether the Periodic Advertiser List is used @@ -1630,7 +1623,6 @@ typedef struct rsi_ble_ae_pdu { rsi_ble_ae_extended_create_connect_t extended_create_conn; - //uint8_t data[1]; } SL_ATTRIBUTE_PACKED pdu_type; } SL_ATTRIBUTE_PACKED rsi_ble_ae_pdu_t; diff --git a/components/device/silabs/si91x/wireless/ble/inc/rsi_ble_apis.h b/components/device/silabs/si91x/wireless/ble/inc/rsi_ble_apis.h index bac477ee7..8b8c0ba48 100644 --- a/components/device/silabs/si91x/wireless/ble/inc/rsi_ble_apis.h +++ b/components/device/silabs/si91x/wireless/ble/inc/rsi_ble_apis.h @@ -1620,7 +1620,7 @@ int32_t rsi_ble_start_advertising(void); * 0x4046 - Invalid Arguments * @note Refer to the Status Codes section for the above error codes at [additional-status-codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) . */ -int32_t rsi_ble_start_advertising_with_values(void *rsi_ble_adv); +int32_t rsi_ble_start_advertising_with_values(const void *rsi_ble_adv); /*==============================================*/ /** @@ -1640,7 +1640,7 @@ int32_t rsi_ble_start_advertising_with_values(void *rsi_ble_adv); * -4 - Buffer not available to serve the command * @note Refer to the Status Codes section for the above error codes at [additional-status-codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) . */ -int32_t rsi_ble_encrypt(uint8_t *key, uint8_t *data, uint8_t *resp); +int32_t rsi_ble_encrypt(const uint8_t *key, const uint8_t *data, uint8_t *resp); /*==============================================*/ /** @@ -1677,7 +1677,7 @@ int32_t rsi_ble_stop_advertising(void); * @note The maximum length of advertising data payload is 31 bytes. * @note The basic format of advertising payload record contains length and data. */ -int32_t rsi_ble_set_advertise_data(uint8_t *data, uint16_t data_len); +int32_t rsi_ble_set_advertise_data(const uint8_t *data, uint16_t data_len); /*========================================================*/ /** @@ -1694,7 +1694,7 @@ int32_t rsi_ble_set_advertise_data(uint8_t *data, uint16_t data_len); * -4 - Buffer not available to serve the command * @note Refer to the Status Codes section for the above error codes at [additional-status-codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) . */ -int32_t rsi_ble_set_scan_response_data(uint8_t *data, uint16_t data_len); +int32_t rsi_ble_set_scan_response_data(const uint8_t *data, uint16_t data_len); /*==============================================*/ /** @@ -1816,7 +1816,7 @@ int32_t rsi_ble_stop_scanning(void); * @note Refer to the Status Codes section for the above error codes at [additional-status-codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) . */ int32_t rsi_ble_connect_with_params(uint8_t remote_dev_addr_type, - int8_t *remote_dev_addr, + const int8_t *remote_dev_addr, uint16_t scan_interval, uint16_t scan_window, uint16_t conn_interval_max, @@ -1845,7 +1845,7 @@ int32_t rsi_ble_connect_with_params(uint8_t remote_dev_addr_type, * @note To recover from this situation, the application can implement a timeout and call rsi_ble_connect_cancel() to cancel the connection request. * @note Subsequent calls of this command have to wait for the ongoing command to complete. */ -int32_t rsi_ble_connect(uint8_t remote_dev_addr_type, int8_t *remote_dev_addr); +int32_t rsi_ble_connect(uint8_t remote_dev_addr_type, const int8_t *remote_dev_addr); /*==============================================*/ /** @@ -1921,7 +1921,7 @@ int32_t rsi_ble_enhance_connect_with_params(void *ble_enhance_conn_params); * - 0x4E02 - Unknown Connection Identifier * @note Refer to the Status Codes section for the above error codes at [additional-status-codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) . */ -int32_t rsi_ble_connect_cancel(int8_t *remote_dev_address); +int32_t rsi_ble_connect_cancel(const int8_t *remote_dev_address); /*==============================================*/ /** @@ -1939,7 +1939,7 @@ int32_t rsi_ble_connect_cancel(int8_t *remote_dev_address); * 0x4D04 BLE not connected * @note Refer to the Status Codes section for the above error codes at [additional-status-codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) . */ -int32_t rsi_ble_disconnect(int8_t *remote_dev_address); +int32_t rsi_ble_disconnect(const int8_t *remote_dev_address); /*==============================================*/ /** @@ -1994,7 +1994,7 @@ int32_t rsi_ble_set_smp_pairing_cap_data(rsi_ble_set_smp_pairing_capabilty_data_ * - Non-Zero Value - Failure * @note Refer to the Status Codes section for the above error codes at [additional-status-codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) . */ -int32_t rsi_ble_set_local_irk_value(uint8_t *l_irk); +int32_t rsi_ble_set_local_irk_value(const uint8_t *l_irk); /*==============================================*/ /** @@ -2015,7 +2015,7 @@ int32_t rsi_ble_set_local_irk_value(uint8_t *l_irk); * - 0x4E02 - Unknown Connection Identifier * @note Refer to the Status Codes section for the above error codes at [additional-status-codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) . */ -int32_t rsi_ble_conn_param_resp(uint8_t *remote_dev_address, uint8_t status); +int32_t rsi_ble_conn_param_resp(const uint8_t *remote_dev_address, uint8_t status); /*==============================================*/ /** @@ -2092,7 +2092,7 @@ int32_t rsi_ble_smp_pair_failed(uint8_t *remote_dev_address, uint8_t reason); * - 0x4D04 BLE not connected * @note Refer to the Status Codes section for the above error codes at [additional-status-codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) . */ -int32_t rsi_ble_ltk_req_reply(uint8_t *remote_dev_address, uint8_t reply_type, uint8_t *ltk); +int32_t rsi_ble_ltk_req_reply(uint8_t *remote_dev_address, uint8_t reply_type, const uint8_t *ltk); /*==============================================*/ /** @@ -2225,7 +2225,7 @@ int32_t rsi_ble_clear_acceptlist(void); * @note Maximum number of device address that firmware can store is 10. * Refer to the Status Codes section for the above error codes at [additional-status-codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) . */ -int32_t rsi_ble_addto_acceptlist(int8_t *dev_address, uint8_t dev_addr_type); +int32_t rsi_ble_addto_acceptlist(const int8_t *dev_address, uint8_t dev_addr_type); /*==============================================*/ /** @@ -2242,7 +2242,7 @@ int32_t rsi_ble_addto_acceptlist(int8_t *dev_address, uint8_t dev_addr_type); * - -4 - Buffer not available to serve the command * @note Refer to the Status Codes section for the above error codes at [additional-status-codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) . */ -int32_t rsi_ble_deletefrom_acceptlist(int8_t *dev_address, uint8_t dev_addr_type); +int32_t rsi_ble_deletefrom_acceptlist(const int8_t *dev_address, uint8_t dev_addr_type); /*==============================================*/ /** * @fn int32_t rsi_ble_resolvlist(uint8_t process_type, @@ -2273,8 +2273,8 @@ int32_t rsi_ble_deletefrom_acceptlist(int8_t *dev_address, uint8_t dev_addr_type int32_t rsi_ble_resolvlist(uint8_t process_type, uint8_t remote_dev_addr_type, uint8_t *remote_dev_address, - uint8_t *peer_irk, - uint8_t *local_irk); + const uint8_t *peer_irk, + const uint8_t *local_irk); /*==============================================*/ /** @@ -2345,7 +2345,7 @@ int32_t rsi_ble_set_privacy_mode(uint8_t remote_dev_addr_type, uint8_t *remote_d * Non-Zero Value - Failure * @note Refer to the Status Codes section for the above error codes at [additional-status-codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) . */ -int32_t rsi_ble_readphy(int8_t *remote_dev_address, rsi_ble_resp_read_phy_t *resp); +int32_t rsi_ble_readphy(const int8_t *remote_dev_address, rsi_ble_resp_read_phy_t *resp); /*==============================================*/ /** @@ -2379,7 +2379,7 @@ int32_t rsi_ble_readphy(int8_t *remote_dev_address, rsi_ble_resp_read_phy_t *res * - 0x4D04 BLE not connected * @note Refer to the Status Codes section for the above error codes at [additional-status-codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) . */ -int32_t rsi_ble_setphy(int8_t *remote_dev_address, uint8_t tx_phy, uint8_t rx_phy, uint16_t coded_phy); +int32_t rsi_ble_setphy(const int8_t *remote_dev_address, uint8_t tx_phy, uint8_t rx_phy, uint16_t coded_phy); /*==============================================*/ /** @@ -2415,7 +2415,7 @@ int32_t rsi_ble_setphy(int8_t *remote_dev_address, uint8_t tx_phy, uint8_t rx_ph Max supported peripheral latency is 32 when Device is in peripheral Role. * */ -int32_t rsi_ble_conn_params_update(uint8_t *remote_dev_address, +int32_t rsi_ble_conn_params_update(const uint8_t *remote_dev_address, uint16_t min_int, uint16_t max_int, uint16_t latency, @@ -2583,7 +2583,7 @@ int32_t rsi_ble_per_receive(struct rsi_ble_per_receive_s *rsi_ble_per_rx); int32_t rsi_ble_accept_list_using_adv_data(uint8_t enable, uint8_t data_compare_index, uint8_t len_for_compare_data, - uint8_t *payload); + const uint8_t *payload); /*==============================================*/ /** @@ -2597,7 +2597,7 @@ int32_t rsi_ble_accept_list_using_adv_data(uint8_t enable, * @return The following values are returned: * void */ -void BT_LE_ADPacketExtract(uint8_t *remote_name, uint8_t *pbuf, uint8_t buf_len); +void BT_LE_ADPacketExtract(uint8_t *remote_name, const uint8_t *pbuf, uint8_t buf_len); /*==============================================*/ /** @@ -2623,7 +2623,7 @@ void BT_LE_ADPacketExtract(uint8_t *remote_name, uint8_t *pbuf, uint8_t buf_len) * - 0x4D04 BLE not connected * @note Refer to the Status Codes section for the above error codes at [additional-status-codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors). */ -int32_t rsi_ble_start_encryption(uint8_t *remote_dev_address, uint16_t ediv, uint8_t *rand, uint8_t *ltk); +int32_t rsi_ble_start_encryption(uint8_t *remote_dev_address, uint16_t ediv, const uint8_t *rand, const uint8_t *ltk); /*==============================================*/ /** @@ -2971,7 +2971,7 @@ int32_t rsi_ble_get_att_value(uint8_t *dev_addr, uint16_t handle, rsi_ble_resp_a */ int32_t rsi_ble_get_multiple_att_values(uint8_t *dev_addr, uint8_t num_of_handlers, - uint16_t *handles, + const uint16_t *handles, rsi_ble_resp_att_value_t *p_att_vals); /*==============================================*/ @@ -3019,7 +3019,7 @@ int32_t rsi_ble_get_long_att_value(uint8_t *dev_addr, * - Non-Zero Value - Failure * @note Refer to the Status Codes section for the above error codes at [additional-status-codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) . */ -int32_t rsi_ble_set_att_value(uint8_t *dev_addr, uint16_t handle, uint8_t data_len, uint8_t *p_data); +int32_t rsi_ble_set_att_value(uint8_t *dev_addr, uint16_t handle, uint8_t data_len, const uint8_t *p_data); /*==============================================*/ /** @@ -3043,7 +3043,7 @@ int32_t rsi_ble_set_att_value(uint8_t *dev_addr, uint16_t handle, uint8_t data_l * - 0x4E65 - Invalid Attribute Length When Small Buffer Mode is Configured * @note Refer to the Status Codes section for the above error codes at [additional-status-codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) . */ -int32_t rsi_ble_set_att_cmd(uint8_t *dev_addr, uint16_t handle, uint8_t data_len, uint8_t *p_data); +int32_t rsi_ble_set_att_cmd(uint8_t *dev_addr, uint16_t handle, uint8_t data_len, const uint8_t *p_data); /*==============================================*/ /** @@ -3072,7 +3072,7 @@ int32_t rsi_ble_set_long_att_value(uint8_t *dev_addr, uint16_t handle, uint16_t offset, uint8_t data_len, - uint8_t *p_data); + const uint8_t *p_data); /*==============================================*/ /** @@ -3095,7 +3095,11 @@ int32_t rsi_ble_set_long_att_value(uint8_t *dev_addr, * @note Refer to the Status Codes section for the above error codes at [additional-status-codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) . * */ -int32_t rsi_ble_prepare_write(uint8_t *dev_addr, uint16_t handle, uint16_t offset, uint8_t data_len, uint8_t *p_data); +int32_t rsi_ble_prepare_write(uint8_t *dev_addr, + uint16_t handle, + uint16_t offset, + uint8_t data_len, + const uint8_t *p_data); /*==============================================*/ /** @@ -3185,7 +3189,7 @@ int32_t rsi_ble_add_attribute(rsi_ble_req_add_att_t *p_attribute); * @note Rule 4: If the services are maintained in the Application/Host, * then need to use \ref rsi_ble_notify_value() API to send the notifications to the remote devices. */ -int32_t rsi_ble_set_local_att_value(uint16_t handle, uint16_t data_len, uint8_t *p_data); +int32_t rsi_ble_set_local_att_value(uint16_t handle, uint16_t data_len, const uint8_t *p_data); /*==============================================*/ /** @@ -3213,7 +3217,7 @@ int32_t rsi_ble_set_local_att_value(uint16_t handle, uint16_t data_len, uint8_t * - 0x4E64 - BLE Buffer already in use * @note Refer to the Status Codes section for the above error codes at [additional-status-codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) . */ -int32_t rsi_ble_set_wo_resp_notify_buf_info(uint8_t *dev_addr, uint8_t buf_mode, uint8_t buf_cnt); +int32_t rsi_ble_set_wo_resp_notify_buf_info(const uint8_t *dev_addr, uint8_t buf_mode, uint8_t buf_cnt); /*==============================================*/ /** @@ -3241,7 +3245,7 @@ int32_t rsi_ble_set_wo_resp_notify_buf_info(uint8_t *dev_addr, uint8_t buf_mode, * then need to use \ref rsi_ble_notify_value() API instead of using \ref rsi_ble_set_local_att_value() API * to send the notifications to the remote devices. */ -int32_t rsi_ble_notify_value(uint8_t *dev_addr, uint16_t handle, uint16_t data_len, uint8_t *p_data); +int32_t rsi_ble_notify_value(const uint8_t *dev_addr, uint16_t handle, uint16_t data_len, const uint8_t *p_data); /*==============================================*/ /** @@ -3262,7 +3266,7 @@ int32_t rsi_ble_notify_value(uint8_t *dev_addr, uint16_t handle, uint16_t data_l * - 0x4E60 - Invalid Handle Range * @note Refer to the Status Codes section for the above error codes at [additional-status-codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) */ -int32_t rsi_ble_indicate_value(uint8_t *dev_addr, uint16_t handle, uint16_t data_len, uint8_t *p_data); +int32_t rsi_ble_indicate_value(const uint8_t *dev_addr, uint16_t handle, uint16_t data_len, const uint8_t *p_data); /** @} */ /** @addtogroup BT-LOW-ENERGY4 @@ -3291,7 +3295,7 @@ int32_t rsi_ble_indicate_value(uint8_t *dev_addr, uint16_t handle, uint16_t data * - 0x4E60 - Invalid Handle Range * @note Refer to the Status Codes section for the above error codes at [additional-status-codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) */ -int32_t rsi_ble_indicate_value_sync(uint8_t *dev_addr, uint16_t handle, uint16_t data_len, uint8_t *p_data); +int32_t rsi_ble_indicate_value_sync(const uint8_t *dev_addr, uint16_t handle, uint16_t data_len, const uint8_t *p_data); /*==============================================*/ /** @@ -3306,7 +3310,7 @@ int32_t rsi_ble_indicate_value_sync(uint8_t *dev_addr, uint16_t handle, uint16_t * - 0x4D05 - BLE socket not available * @note Refer to the Status Codes section for the above error codes at [additional-status-codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) */ -int32_t rsi_ble_indicate_confirm(uint8_t *dev_addr); +int32_t rsi_ble_indicate_confirm(const uint8_t *dev_addr); /** @} */ /** @addtogroup BT-LOW-ENERGY5 @@ -3365,7 +3369,7 @@ int32_t rsi_ble_gatt_read_response(uint8_t *dev_addr, uint16_t handle, uint16_t offset, uint16_t length, - uint8_t *p_data); + const uint8_t *p_data); /*==============================================*/ /** @@ -3508,7 +3512,7 @@ int32_t rsi_ble_gatt_prepare_write_response(uint8_t *dev_addr, uint16_t handle, uint16_t offset, uint16_t length, - uint8_t *data); + const uint8_t *data); /** @} */ /** @addtogroup BT-LOW-ENERGY1 @@ -3551,7 +3555,7 @@ int32_t rsi_ble_get_max_no_of_supp_adv_sets(uint8_t *resp); * @return The following values are returned: * - !0 = failure */ -int32_t rsi_ble_set_ae_set_random_address(uint8_t handle, uint8_t *rand_addr); +int32_t rsi_ble_set_ae_set_random_address(uint8_t handle, const uint8_t *rand_addr); /*========================================================*/ /** @@ -3983,7 +3987,7 @@ int32_t rsi_ble_get_att_value_async(uint8_t *dev_addr, uint16_t handle, rsi_ble_ */ int32_t rsi_ble_get_multiple_att_values_async(uint8_t *dev_addr, uint8_t num_of_handlers, - uint16_t *handles, + const uint16_t *handles, rsi_ble_resp_att_value_t *p_att_vals); /*==============================================*/ @@ -4038,7 +4042,7 @@ int32_t rsi_ble_get_long_att_value_async(uint8_t *dev_addr, * - 0x4D05 - BLE Socket not available * @note Refer to the Status Codes section for the above error codes at [additional-status-codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) . */ -int32_t rsi_ble_set_att_value_async(uint8_t *dev_addr, uint16_t handle, uint8_t data_len, uint8_t *p_data); +int32_t rsi_ble_set_att_value_async(uint8_t *dev_addr, uint16_t handle, uint8_t data_len, const uint8_t *p_data); /*==============================================*/ /** @@ -4069,7 +4073,7 @@ int32_t rsi_ble_prepare_write_async(uint8_t *dev_addr, uint16_t handle, uint16_t offset, uint8_t data_len, - uint8_t *p_data); + const uint8_t *p_data); /*==============================================*/ /** diff --git a/components/device/silabs/si91x/wireless/ble/inc/rsi_bt_common_apis.h b/components/device/silabs/si91x/wireless/ble/inc/rsi_bt_common_apis.h index 3a8729467..f4dcd6fe1 100644 --- a/components/device/silabs/si91x/wireless/ble/inc/rsi_bt_common_apis.h +++ b/components/device/silabs/si91x/wireless/ble/inc/rsi_bt_common_apis.h @@ -71,7 +71,7 @@ extern "C" { * - 3 - Command is given in wrong state (i.e., not immediate after opermode) * @note This is a blocking API. Refer to the Status Codes section for the above error codes at [additional-status-codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) . */ -int32_t rsi_bt_set_bd_addr(uint8_t *dev_addr); +int32_t rsi_bt_set_bd_addr(const uint8_t *dev_addr); /*==============================================*/ /** @@ -86,7 +86,7 @@ int32_t rsi_bt_set_bd_addr(uint8_t *dev_addr); * - Non-Zero Value - Failure * @note Refer to the Status Codes section for the above error codes at [additional-status-codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors). */ -int32_t rsi_bt_set_local_name(uint8_t *local_name); +int32_t rsi_bt_set_local_name(const uint8_t *local_name); /*==============================================*/ /** diff --git a/components/device/silabs/si91x/wireless/ble/inc/rsi_utils.h b/components/device/silabs/si91x/wireless/ble/inc/rsi_utils.h index ed05e76d7..31f9483a4 100644 --- a/components/device/silabs/si91x/wireless/ble/inc/rsi_utils.h +++ b/components/device/silabs/si91x/wireless/ble/inc/rsi_utils.h @@ -53,16 +53,16 @@ * ******************************************************/ void rsi_uint32_to_4bytes(uint8_t *dBuf, uint32_t val); void rsi_uint16_to_2bytes(uint8_t *dBuf, uint16_t val); -uint16_t rsi_bytes2R_to_uint16(uint8_t *dBuf); -uint32_t rsi_bytes4R_to_uint32(uint8_t *dBuf); +uint16_t rsi_bytes2R_to_uint16(const uint8_t *dBuf); +uint32_t rsi_bytes4R_to_uint32(const uint8_t *dBuf); uint8_t *rsi_ascii_dev_address_to_6bytes_rev(uint8_t *hex_addr, int8_t *ascii_mac_address); -uint8_t *rsi_6byte_dev_address_to_ascii(uint8_t *ascii_mac_address, uint8_t *hex_addr); +uint8_t *rsi_6byte_dev_address_to_ascii(uint8_t *ascii_mac_address, const uint8_t *hex_addr); uint8_t convert_lower_case_to_upper_case(uint8_t lwrcase); -void string2array(uint8_t *dst, uint8_t *src, uint32_t length); +void string2array(uint8_t *dst, const uint8_t *src, uint32_t length); int32_t rsi_atoi(const int8_t *str); void rsi_ascii_dot_address_to_4bytes(uint8_t *hexAddr, int8_t *asciiDotAddress); void rsi_ascii_mac_address_to_6bytes(uint8_t *hexAddr, int8_t *asciiMacAddress); -uint64_t ip_to_reverse_hex(char *ip); +uint64_t ip_to_reverse_hex(const char *ip); int8_t rsi_ascii_hex2num(int8_t ascii_hex_in); int8_t rsi_char_hex2dec(int8_t *cBuf); diff --git a/components/device/silabs/si91x/wireless/ble/src/rsi_ble_gap_apis.c b/components/device/silabs/si91x/wireless/ble/src/rsi_ble_gap_apis.c index 0a7acbae1..2c0dbc65d 100644 --- a/components/device/silabs/si91x/wireless/ble/src/rsi_ble_gap_apis.c +++ b/components/device/silabs/si91x/wireless/ble/src/rsi_ble_gap_apis.c @@ -192,7 +192,7 @@ int32_t rsi_ble_start_advertising(void) * 0x4046 - Invalid Arguments * @note Refer to the Status Codes section for the above error codes at [additional-status-codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) . */ -int32_t rsi_ble_start_advertising_with_values(void *rsi_ble_adv) +int32_t rsi_ble_start_advertising_with_values(const void *rsi_ble_adv) { SL_PRINTF(SL_RSI_BLE_START_ADV_WITH_VALUES_TRIGGER, BLE, LOG_INFO); rsi_ble_req_adv_t ble_adv = { 0 }; @@ -221,7 +221,7 @@ int32_t rsi_ble_start_advertising_with_values(void *rsi_ble_adv) * -4 - Buffer not available to serve the command * @note Refer to the Status Codes section for the above error codes at [additional-status-codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) . */ -int32_t rsi_ble_encrypt(uint8_t *key, uint8_t *data, uint8_t *resp) +int32_t rsi_ble_encrypt(const uint8_t *key, const uint8_t *data, uint8_t *resp) { SL_PRINTF(SL_RSI_BLE_ENCRYPT_TRIGGER, BLE, LOG_INFO); @@ -274,13 +274,13 @@ int32_t rsi_ble_stop_advertising(void) * @note 1. The maximum length of advertising data payload is 31 bytes. \n * 2. The basic format of advertising payload record contains length and data. \n */ -int32_t rsi_ble_set_advertise_data(uint8_t *data, uint16_t data_len) +int32_t rsi_ble_set_advertise_data(const uint8_t *data, uint16_t data_len) { SL_PRINTF(SL_RSI_BLE_SET_ADV_DATA_TRIGGER, BLE, LOG_INFO); rsi_ble_req_adv_data_t ble_adv_data = { 0 }; - ble_adv_data.data_len = RSI_MIN(data_len, sizeof(ble_adv_data.adv_data)); + ble_adv_data.data_len = (uint8_t)(RSI_MIN(data_len, sizeof(ble_adv_data.adv_data))); memcpy(ble_adv_data.adv_data, data, ble_adv_data.data_len); // Send stop advertise command @@ -300,12 +300,12 @@ int32_t rsi_ble_set_advertise_data(uint8_t *data, uint16_t data_len) * -4 - Buffer not available to serve the command * @note Refer to the Status Codes section for the above error codes at [additional-status-codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) . */ -int32_t rsi_ble_set_scan_response_data(uint8_t *data, uint16_t data_len) +int32_t rsi_ble_set_scan_response_data(const uint8_t *data, uint16_t data_len) { SL_PRINTF(SL_RSI_BLE_SET_SCAN_RESPONSE_DATA_TRIGGER, BLE, LOG_INFO); rsi_ble_req_scanrsp_data_t ble_scanrsp_data = { 0 }; - ble_scanrsp_data.data_len = RSI_MIN(data_len, sizeof(ble_scanrsp_data.scanrsp_data)); + ble_scanrsp_data.data_len = (uint8_t)(RSI_MIN(data_len, sizeof(ble_scanrsp_data.scanrsp_data))); memcpy(ble_scanrsp_data.scanrsp_data, data, ble_scanrsp_data.data_len); return rsi_bt_driver_send_cmd(RSI_BLE_SET_SCAN_RESPONSE_DATA, &ble_scanrsp_data, NULL); @@ -464,7 +464,7 @@ int32_t rsi_ble_stop_scanning(void) */ int32_t rsi_ble_connect_with_params(uint8_t remote_dev_addr_type, - int8_t *remote_dev_addr, + const int8_t *remote_dev_addr, uint16_t scan_interval, uint16_t scan_window, uint16_t conn_interval_max, @@ -530,7 +530,7 @@ int32_t rsi_ble_connect_with_params(uint8_t remote_dev_addr_type, * @note Refer to the Status Codes section for the above error codes at [additional-status-codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) . */ -int32_t rsi_ble_connect(uint8_t remote_dev_addr_type, int8_t *remote_dev_addr) +int32_t rsi_ble_connect(uint8_t remote_dev_addr_type, const int8_t *remote_dev_addr) { SL_PRINTF(SL_RSI_BLE_CONNECT, BLE, LOG_INFO, "ADDRESS_TYPE: %2x", remote_dev_addr_type); @@ -590,7 +590,7 @@ int32_t rsi_ble_enhance_connect_with_params(void *ble_enhance_conn_params) * 0x4E02 - Unknown Connection Identifier \n * @note Refer to the Status Codes section for the above error codes at [additional-status-codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) . */ -int32_t rsi_ble_connect_cancel(int8_t *remote_dev_address) +int32_t rsi_ble_connect_cancel(const int8_t *remote_dev_address) { SL_PRINTF(SL_RSI_BLE_CONNECT_CANCEL, BLE, LOG_INFO); @@ -621,7 +621,7 @@ int32_t rsi_ble_connect_cancel(int8_t *remote_dev_address) * 0x4D04 BLE not connected \n * @note Refer to the Status Codes section for the above error codes at [additional-status-codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) . */ -int32_t rsi_ble_disconnect(int8_t *remote_dev_address) +int32_t rsi_ble_disconnect(const int8_t *remote_dev_address) { SL_PRINTF(SL_RSI_BLE_DISCONNECT, BLE, LOG_INFO, "ADDRESS: %1x", *remote_dev_address); rsi_ble_req_disconnect_t ble_disconnect = { 0 }; @@ -692,7 +692,7 @@ int32_t rsi_ble_set_smp_pairing_cap_data(rsi_ble_set_smp_pairing_capabilty_data_ * @note Refer to the Status Codes section for the above error codes at [additional-status-codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) . */ -int32_t rsi_ble_set_local_irk_value(uint8_t *l_irk) +int32_t rsi_ble_set_local_irk_value(const uint8_t *l_irk) { SL_PRINTF(SL_RSI_BLE_SET_LOCAL_IRK_VALUE, BLE, LOG_INFO); @@ -722,7 +722,7 @@ int32_t rsi_ble_set_local_irk_value(uint8_t *l_irk) * */ -int32_t rsi_ble_conn_param_resp(uint8_t *remote_dev_address, uint8_t status) +int32_t rsi_ble_conn_param_resp(const uint8_t *remote_dev_address, uint8_t status) { SL_PRINTF(SL_RSI_BLE_CONN_PARAM_RESPONSE, BLE, LOG_INFO, "STATUS: %1x", status); @@ -844,7 +844,7 @@ int32_t rsi_ble_smp_pair_failed(uint8_t *remote_dev_address, uint8_t reason) * @note Refer to the Status Codes section for the above error codes at [additional-status-codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) . */ -int32_t rsi_ble_ltk_req_reply(uint8_t *remote_dev_address, uint8_t reply_type, uint8_t *ltk) +int32_t rsi_ble_ltk_req_reply(uint8_t *remote_dev_address, uint8_t reply_type, const uint8_t *ltk) { SL_PRINTF(SL_RSI_BLE_LTK_REQ_REPLY, BLE, LOG_INFO, "REPLY_TYPE: %1x", reply_type); @@ -981,7 +981,7 @@ int32_t rsi_ble_get_le_ping_timeout(uint8_t *remote_dev_address, uint16_t *time_ #else memcpy(leping_cmd.dev_addr, (int8_t *)remote_dev_address, 6); #endif - status = rsi_bt_driver_send_cmd(RSI_BLE_GET_LE_PING, &leping_cmd, &le_ping_rsp); + status = (uint16_t)(rsi_bt_driver_send_cmd(RSI_BLE_GET_LE_PING, &leping_cmd, &le_ping_rsp)); if (status == 0) { *time_out = le_ping_rsp.time_out; } @@ -1059,7 +1059,7 @@ int32_t rsi_ble_clear_acceptlist(void) * @note Maximum number of device address that firmware can store is 10. \n Refer to the Status Codes section for the above error codes at [additional-status-codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) . */ -int32_t rsi_ble_addto_acceptlist(int8_t *dev_address, uint8_t dev_addr_type) +int32_t rsi_ble_addto_acceptlist(const int8_t *dev_address, uint8_t dev_addr_type) { SL_PRINTF(SL_RSI_BLE_ADD_TO_ACCEPTLIST, BLE, LOG_INFO, "DEVICE_ADDRESS_TYPE: %1x", dev_addr_type); @@ -1088,7 +1088,7 @@ int32_t rsi_ble_addto_acceptlist(int8_t *dev_address, uint8_t dev_addr_type) * @note Refer to the Status Codes section for the above error codes at [additional-status-codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) . */ -int32_t rsi_ble_deletefrom_acceptlist(int8_t *dev_address, uint8_t dev_addr_type) +int32_t rsi_ble_deletefrom_acceptlist(const int8_t *dev_address, uint8_t dev_addr_type) { SL_PRINTF(SL_RSI_BLE_DELETEFROM_ACCEPTLIST, BLE, LOG_INFO, "DEVICE_ADDRESS_TYPE: %1x", dev_addr_type); @@ -1133,8 +1133,8 @@ int32_t rsi_ble_deletefrom_acceptlist(int8_t *dev_address, uint8_t dev_addr_type int32_t rsi_ble_resolvlist(uint8_t process_type, uint8_t remote_dev_addr_type, uint8_t *remote_dev_address, - uint8_t *peer_irk, - uint8_t *local_irk) + const uint8_t *peer_irk, + const uint8_t *local_irk) { SL_PRINTF(SL_RSI_BLE_RESOLVLIST, @@ -1250,7 +1250,7 @@ int32_t rsi_ble_set_privacy_mode(uint8_t remote_dev_addr_type, uint8_t *remote_d * Non-Zero Value - Failure * @note Refer to the Status Codes section for the above error codes at [additional-status-codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) . */ -int32_t rsi_ble_readphy(int8_t *remote_dev_address, rsi_ble_resp_read_phy_t *resp) +int32_t rsi_ble_readphy(const int8_t *remote_dev_address, rsi_ble_resp_read_phy_t *resp) { SL_PRINTF(SL_RSI_BLE_READPHY, BLE, LOG_INFO); @@ -1295,7 +1295,7 @@ int32_t rsi_ble_readphy(int8_t *remote_dev_address, rsi_ble_resp_read_phy_t *res * @note Refer to the Status Codes section for the above error codes at [additional-status-codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) . */ -int32_t rsi_ble_setphy(int8_t *remote_dev_address, uint8_t tx_phy, uint8_t rx_phy, uint16_t coded_phy) +int32_t rsi_ble_setphy(const int8_t *remote_dev_address, uint8_t tx_phy, uint8_t rx_phy, uint16_t coded_phy) { SL_PRINTF(SL_RSI_SETPHY_TRIGGER, BLE, LOG_INFO); @@ -1347,7 +1347,7 @@ int32_t rsi_ble_setphy(int8_t *remote_dev_address, uint8_t tx_phy, uint8_t rx_ph Max supported peripheral latency is 32 when Device is in Peripheral Role. * */ -int32_t rsi_ble_conn_params_update(uint8_t *remote_dev_address, +int32_t rsi_ble_conn_params_update(const uint8_t *remote_dev_address, uint16_t min_int, uint16_t max_int, uint16_t latency, @@ -1614,7 +1614,7 @@ int32_t rsi_ble_vendor_rf_type(uint8_t ble_power_index) int32_t rsi_ble_accept_list_using_adv_data(uint8_t enable, uint8_t data_compare_index, uint8_t len_for_compare_data, - uint8_t *payload) + const uint8_t *payload) { SL_PRINTF(SL_RSI_BLE_ACCEPTLIST_USING_ADV_DATA, BLE, LOG_INFO); @@ -1645,7 +1645,7 @@ int32_t rsi_ble_accept_list_using_adv_data(uint8_t enable, * @return void */ -void BT_LE_ADPacketExtract(uint8_t *remote_name, uint8_t *pbuf, uint8_t buf_len) +void BT_LE_ADPacketExtract(uint8_t *remote_name, const uint8_t *pbuf, uint8_t buf_len) { SL_PRINTF(SL_RSI_BLE_AD_PACKET_EXTRACT, BLE, LOG_INFO); @@ -1706,7 +1706,7 @@ void BT_LE_ADPacketExtract(uint8_t *remote_name, uint8_t *pbuf, uint8_t buf_len) * @note Refer to the Status Codes section for the above error codes at [additional-status-codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) . */ -int32_t rsi_ble_start_encryption(uint8_t *remote_dev_address, uint16_t ediv, uint8_t *rand, uint8_t *ltk) +int32_t rsi_ble_start_encryption(uint8_t *remote_dev_address, uint16_t ediv, const uint8_t *rand, const uint8_t *ltk) { SL_PRINTF(SL_RSI_BLE_ENCRYPTION_TRIGGER, BLE, LOG_INFO); @@ -1830,7 +1830,7 @@ int32_t rsi_ble_get_max_adv_data_len(uint8_t *resp) * @section description * This function is used by the host to set the random device address specified by the Random_Address_parameter */ -int32_t rsi_ble_set_ae_set_random_address(uint8_t handle, uint8_t *rand_addr) +int32_t rsi_ble_set_ae_set_random_address(uint8_t handle, const uint8_t *rand_addr) { rsi_ble_ae_pdu_t ae_pdu = { 0 }; diff --git a/components/device/silabs/si91x/wireless/ble/src/rsi_ble_gatt_apis.c b/components/device/silabs/si91x/wireless/ble/src/rsi_ble_gatt_apis.c index 67ea793ed..048440462 100644 --- a/components/device/silabs/si91x/wireless/ble/src/rsi_ble_gatt_apis.c +++ b/components/device/silabs/si91x/wireless/ble/src/rsi_ble_gatt_apis.c @@ -366,21 +366,20 @@ int32_t rsi_ble_get_att_value_async(uint8_t *dev_addr, uint16_t handle, rsi_ble_ int32_t rsi_ble_get_multiple_att_values_async(uint8_t *dev_addr, uint8_t num_of_handlers, - uint16_t *handles, + const uint16_t *handles, rsi_ble_resp_att_value_t *p_att_vals) { SL_PRINTF(SL_RSI_BLE_GET_MULTIPLE_ATT_VALUES_ASYNC, BLE, LOG_INFO, "NUMBER_OF_HANDLERS: %1x", num_of_handlers); rsi_ble_req_multi_att_values_t req_att_vals; memset(&req_att_vals, 0, sizeof(req_att_vals)); - uint8_t ix; #ifdef BD_ADDR_IN_ASCII rsi_ascii_dev_address_to_6bytes_rev(req_att_vals.dev_addr, dev_addr); #else memcpy((uint8_t *)req_att_vals.dev_addr, (int8_t *)dev_addr, 6); #endif - req_att_vals.num_of_handles = RSI_MIN(num_of_handlers, RSI_BLE_MAX_REQ_LIST); - for (ix = 0; ix < req_att_vals.num_of_handles; ix++) { + req_att_vals.num_of_handles = (uint8_t)(RSI_MIN(num_of_handlers, RSI_BLE_MAX_REQ_LIST)); + for (uint8_t ix = 0; ix < req_att_vals.num_of_handles; ix++) { req_att_vals.handles[ix] = handles[ix]; } @@ -452,7 +451,7 @@ int32_t rsi_ble_get_long_att_value_async(uint8_t *dev_addr, * */ -int32_t rsi_ble_set_att_value_async(uint8_t *dev_addr, uint16_t handle, uint8_t data_len, uint8_t *p_data) +int32_t rsi_ble_set_att_value_async(uint8_t *dev_addr, uint16_t handle, uint8_t data_len, const uint8_t *p_data) { SL_PRINTF(SL_RSI_BLE_SET_ATT_VALUE_ASYNC, BLE, LOG_INFO, "HANDLE: %2x, DATA_LEN: %1x", handle, data_len); @@ -464,7 +463,7 @@ int32_t rsi_ble_set_att_value_async(uint8_t *dev_addr, uint16_t handle, uint8_t memcpy((uint8_t *)set_att_val.dev_addr, (int8_t *)dev_addr, 6); #endif rsi_uint16_to_2bytes(set_att_val.handle, handle); - set_att_val.length = RSI_MIN(sizeof(set_att_val.att_value), data_len); + set_att_val.length = (uint8_t)(RSI_MIN(sizeof(set_att_val.att_value), data_len)); memcpy(set_att_val.att_value, p_data, set_att_val.length); return rsi_bt_driver_send_cmd(RSI_BLE_SET_DESCVALUE_ASYNC, &set_att_val, NULL); @@ -498,7 +497,7 @@ int32_t rsi_ble_prepare_write_async(uint8_t *dev_addr, uint16_t handle, uint16_t offset, uint8_t data_len, - uint8_t *p_data) + const uint8_t *p_data) { SL_PRINTF(SL_RSI_BLE_PREPARE_WRITE_ASYNC, @@ -518,7 +517,7 @@ int32_t rsi_ble_prepare_write_async(uint8_t *dev_addr, #endif rsi_uint16_to_2bytes(req_prepare_write.handle, handle); rsi_uint16_to_2bytes(req_prepare_write.offset, offset); - req_prepare_write.length = RSI_MIN(sizeof(req_prepare_write.att_value), data_len); + req_prepare_write.length = (uint8_t)(RSI_MIN(sizeof(req_prepare_write.att_value), data_len)); memcpy(req_prepare_write.att_value, p_data, req_prepare_write.length); return rsi_bt_driver_send_cmd(RSI_BLE_SET_PREPAREWRITE_ASYNC, &req_prepare_write, NULL); @@ -870,20 +869,19 @@ int32_t rsi_ble_get_att_value(uint8_t *dev_addr, uint16_t handle, rsi_ble_resp_a int32_t rsi_ble_get_multiple_att_values(uint8_t *dev_addr, uint8_t num_of_handlers, - uint16_t *handles, + const uint16_t *handles, rsi_ble_resp_att_value_t *p_att_vals) { SL_PRINTF(SL_RSI_BLE_GET_MULTIPLE_ATT_VALUES, BLE, LOG_INFO, "NUMBER_OF_HANDLERS: %1x", num_of_handlers); rsi_ble_req_multi_att_values_t req_att_vals; memset(&req_att_vals, 0, sizeof(req_att_vals)); - uint8_t ix; #ifdef BD_ADDR_IN_ASCII rsi_ascii_dev_address_to_6bytes_rev(req_att_vals.dev_addr, dev_addr); #else memcpy((uint8_t *)req_att_vals.dev_addr, (int8_t *)dev_addr, 6); #endif - req_att_vals.num_of_handles = RSI_MIN(num_of_handlers, RSI_BLE_MAX_REQ_LIST); - for (ix = 0; ix < req_att_vals.num_of_handles; ix++) { + req_att_vals.num_of_handles = (uint8_t)(RSI_MIN(num_of_handlers, RSI_BLE_MAX_REQ_LIST)); + for (uint8_t ix = 0; ix < req_att_vals.num_of_handles; ix++) { req_att_vals.handles[ix] = handles[ix]; } @@ -949,7 +947,7 @@ int32_t rsi_ble_get_long_att_value(uint8_t *dev_addr, * */ -int32_t rsi_ble_set_att_value(uint8_t *dev_addr, uint16_t handle, uint8_t data_len, uint8_t *p_data) +int32_t rsi_ble_set_att_value(uint8_t *dev_addr, uint16_t handle, uint8_t data_len, const uint8_t *p_data) { SL_PRINTF(SL_RSI_BLE_SET_ATT_VALUE, BLE, LOG_INFO); @@ -961,7 +959,7 @@ int32_t rsi_ble_set_att_value(uint8_t *dev_addr, uint16_t handle, uint8_t data_l memcpy((uint8_t *)set_att_val.dev_addr, (int8_t *)dev_addr, 6); #endif rsi_uint16_to_2bytes(set_att_val.handle, handle); - set_att_val.length = RSI_MIN(sizeof(set_att_val.att_value), data_len); + set_att_val.length = (uint8_t)(RSI_MIN(sizeof(set_att_val.att_value), data_len)); memcpy(set_att_val.att_value, p_data, set_att_val.length); return rsi_bt_driver_send_cmd(RSI_BLE_REQ_WRITE, &set_att_val, NULL); @@ -988,7 +986,7 @@ int32_t rsi_ble_set_att_value(uint8_t *dev_addr, uint16_t handle, uint8_t data_l * */ -int32_t rsi_ble_set_att_cmd(uint8_t *dev_addr, uint16_t handle, uint8_t data_len, uint8_t *p_data) +int32_t rsi_ble_set_att_cmd(uint8_t *dev_addr, uint16_t handle, uint8_t data_len, const uint8_t *p_data) { SL_PRINTF(SL_RSI_BLE_SET_ATT_COMMAND, BLE, LOG_INFO, "HANDLE: %2x, DATA_LEN: %1x", handle, data_len); @@ -1000,7 +998,7 @@ int32_t rsi_ble_set_att_cmd(uint8_t *dev_addr, uint16_t handle, uint8_t data_len memcpy((uint8_t *)set_att_cmd.dev_addr, (int8_t *)dev_addr, 6); #endif rsi_uint16_to_2bytes(set_att_cmd.handle, handle); - set_att_cmd.length = RSI_MIN(sizeof(set_att_cmd.att_value), data_len); + set_att_cmd.length = (uint8_t)(RSI_MIN(sizeof(set_att_cmd.att_value), data_len)); memcpy(set_att_cmd.att_value, p_data, set_att_cmd.length); return rsi_bt_driver_send_cmd(RSI_BLE_REQ_WRITE_NO_ACK, &set_att_cmd, NULL); @@ -1033,7 +1031,7 @@ int32_t rsi_ble_set_long_att_value(uint8_t *dev_addr, uint16_t handle, uint16_t offset, uint8_t data_len, - uint8_t *p_data) + const uint8_t *p_data) { SL_PRINTF(SL_RSI_BLE_SET_LONG_ATT_VALUE, @@ -1052,7 +1050,7 @@ int32_t rsi_ble_set_long_att_value(uint8_t *dev_addr, #endif rsi_uint16_to_2bytes(set_long_att.handle, handle); rsi_uint16_to_2bytes(set_long_att.offset, offset); - set_long_att.length = RSI_MIN(sizeof(set_long_att.att_value), data_len); + set_long_att.length = (uint8_t)(RSI_MIN(sizeof(set_long_att.att_value), data_len)); memcpy(set_long_att.att_value, p_data, set_long_att.length); return rsi_bt_driver_send_cmd(RSI_BLE_REQ_LONG_WRITE, &set_long_att, NULL); @@ -1078,7 +1076,11 @@ int32_t rsi_ble_set_long_att_value(uint8_t *dev_addr, * */ -int32_t rsi_ble_prepare_write(uint8_t *dev_addr, uint16_t handle, uint16_t offset, uint8_t data_len, uint8_t *p_data) +int32_t rsi_ble_prepare_write(uint8_t *dev_addr, + uint16_t handle, + uint16_t offset, + uint8_t data_len, + const uint8_t *p_data) { SL_PRINTF(SL_RSI_BLE_PREPARE_WRITE, BLE, @@ -1096,7 +1098,7 @@ int32_t rsi_ble_prepare_write(uint8_t *dev_addr, uint16_t handle, uint16_t offse #endif rsi_uint16_to_2bytes(req_prepare_write.handle, handle); rsi_uint16_to_2bytes(req_prepare_write.offset, offset); - req_prepare_write.length = RSI_MIN(sizeof(req_prepare_write.att_value), data_len); + req_prepare_write.length = (uint8_t)(RSI_MIN(sizeof(req_prepare_write.att_value), data_len)); memcpy(req_prepare_write.att_value, p_data, req_prepare_write.length); return rsi_bt_driver_send_cmd(RSI_BLE_REQ_PREPARE_WRITE, &req_prepare_write, NULL); @@ -1217,14 +1219,14 @@ int32_t rsi_ble_add_attribute(rsi_ble_req_add_att_t *p_attribute) * then need to use \ref rsi_ble_notify_value() API to send the notifications to the remote devices.\n */ -int32_t rsi_ble_set_local_att_value(uint16_t handle, uint16_t data_len, uint8_t *p_data) +int32_t rsi_ble_set_local_att_value(uint16_t handle, uint16_t data_len, const uint8_t *p_data) { SL_PRINTF(SL_RSI_BLE_SET_LOCAL_ATT_VALUE, BLE, LOG_INFO, "HANDLE: %2x", handle); rsi_ble_set_local_att_value_t rec_data = { 0 }; rec_data.handle = handle; - rec_data.data_len = RSI_MIN(data_len, sizeof(rec_data.data)); + rec_data.data_len = (uint16_t)(RSI_MIN(data_len, sizeof(rec_data.data))); memcpy(rec_data.data, p_data, rec_data.data_len); return rsi_bt_driver_send_cmd(RSI_BLE_SET_LOCAL_ATT_VALUE, &rec_data, NULL); @@ -1257,7 +1259,7 @@ int32_t rsi_ble_set_local_att_value(uint16_t handle, uint16_t data_len, uint8_t * @note Refer to the Status Codes section for the above error codes at [additional-status-codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) . * */ -int32_t rsi_ble_set_wo_resp_notify_buf_info(uint8_t *dev_addr, uint8_t buf_mode, uint8_t buf_cnt) +int32_t rsi_ble_set_wo_resp_notify_buf_info(const uint8_t *dev_addr, uint8_t buf_mode, uint8_t buf_cnt) { SL_PRINTF(SL_RSI_BLE_SET_WO_RESP_NOTIFY_BUF_INFO, BLE, LOG_INFO, "BUF_MODE: %1x, BUF_COUNT: %1x", buf_mode, buf_cnt); @@ -1298,7 +1300,7 @@ int32_t rsi_ble_set_wo_resp_notify_buf_info(uint8_t *dev_addr, uint8_t buf_mode, * then need to use \ref rsi_ble_notify_value() API instead of using \ref rsi_ble_set_local_att_value() API\n * to send the notifications to the remote devices. */ -int32_t rsi_ble_notify_value(uint8_t *dev_addr, uint16_t handle, uint16_t data_len, uint8_t *p_data) +int32_t rsi_ble_notify_value(const uint8_t *dev_addr, uint16_t handle, uint16_t data_len, const uint8_t *p_data) { SL_PRINTF(SL_RSI_BLE_NOTIFY_VALUE_TRIGGER, BLE, LOG_INFO, "HANDLE: %2x", handle); @@ -1311,7 +1313,7 @@ int32_t rsi_ble_notify_value(uint8_t *dev_addr, uint16_t handle, uint16_t data_l #endif rec_data.handle = handle; - rec_data.data_len = RSI_MIN(data_len, sizeof(rec_data.data)); + rec_data.data_len = (uint16_t)(RSI_MIN(data_len, sizeof(rec_data.data))); memcpy(rec_data.data, p_data, rec_data.data_len); return rsi_bt_driver_send_cmd(RSI_BLE_CMD_NOTIFY, &rec_data, NULL); @@ -1336,7 +1338,7 @@ int32_t rsi_ble_notify_value(uint8_t *dev_addr, uint16_t handle, uint16_t data_l * */ -int32_t rsi_ble_indicate_value(uint8_t *dev_addr, uint16_t handle, uint16_t data_len, uint8_t *p_data) +int32_t rsi_ble_indicate_value(const uint8_t *dev_addr, uint16_t handle, uint16_t data_len, const uint8_t *p_data) { SL_PRINTF(SL_RSI_BLE_INDICATE_VOLUME_TRIGGER, BLE, LOG_INFO); @@ -1349,7 +1351,7 @@ int32_t rsi_ble_indicate_value(uint8_t *dev_addr, uint16_t handle, uint16_t data #endif rec_data.handle = handle; - rec_data.data_len = RSI_MIN(data_len, sizeof(rec_data.data)); + rec_data.data_len = (uint16_t)(RSI_MIN(data_len, sizeof(rec_data.data))); memcpy(rec_data.data, p_data, rec_data.data_len); return rsi_bt_driver_send_cmd(RSI_BLE_CMD_INDICATE, &rec_data, NULL); @@ -1377,7 +1379,7 @@ int32_t rsi_ble_indicate_value(uint8_t *dev_addr, uint16_t handle, uint16_t data * */ -int32_t rsi_ble_indicate_value_sync(uint8_t *dev_addr, uint16_t handle, uint16_t data_len, uint8_t *p_data) +int32_t rsi_ble_indicate_value_sync(const uint8_t *dev_addr, uint16_t handle, uint16_t data_len, const uint8_t *p_data) { SL_PRINTF(SL_RSI_BLE_INDICATE_VALUE_SYNC, BLE, LOG_INFO); @@ -1390,7 +1392,7 @@ int32_t rsi_ble_indicate_value_sync(uint8_t *dev_addr, uint16_t handle, uint16_t #endif rec_data.handle = handle; - rec_data.data_len = RSI_MIN(data_len, sizeof(rec_data.data)); + rec_data.data_len = (uint16_t)(RSI_MIN(data_len, sizeof(rec_data.data))); memcpy(rec_data.data, p_data, rec_data.data_len); return rsi_bt_driver_send_cmd(RSI_BLE_CMD_INDICATE_SYNC, &rec_data, NULL); @@ -1412,7 +1414,7 @@ int32_t rsi_ble_indicate_value_sync(uint8_t *dev_addr, uint16_t handle, uint16_t * @note Refer to the Status Codes section for the above error codes at [additional-status-codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) \n * */ -int32_t rsi_ble_indicate_confirm(uint8_t *dev_addr) +int32_t rsi_ble_indicate_confirm(const uint8_t *dev_addr) { SL_PRINTF(SL_RSI_BLE_INDICATE_CONFIRM, BLE, LOG_INFO); @@ -1489,7 +1491,7 @@ int32_t rsi_ble_gatt_read_response(uint8_t *dev_addr, uint16_t handle, uint16_t offset, uint16_t length, - uint8_t *p_data) + const uint8_t *p_data) { SL_PRINTF(SL_RSI_BLE_GATT_READ_RESPONSE, BLE, LOG_INFO); @@ -1504,8 +1506,8 @@ int32_t rsi_ble_gatt_read_response(uint8_t *dev_addr, memcpy((uint8_t *)local_read_blob_resp.dev_addr, (int8_t *)dev_addr, 6); #endif local_read_blob_resp.type = read_type; - local_read_blob_resp.data_len = RSI_MIN(length, sizeof(local_read_blob_resp.data)); - memcpy(local_read_blob_resp.data, p_data, local_read_blob_resp.data_len); //local_read_blob_resp.data_len); + local_read_blob_resp.data_len = (uint16_t)(RSI_MIN(length, sizeof(local_read_blob_resp.data))); + memcpy(local_read_blob_resp.data, p_data, local_read_blob_resp.data_len); return rsi_bt_driver_send_cmd(RSI_BLE_CMD_READ_RESP, &local_read_blob_resp, NULL); } @@ -1715,7 +1717,7 @@ int32_t rsi_ble_gatt_prepare_write_response(uint8_t *dev_addr, uint16_t handle, uint16_t offset, uint16_t length, - uint8_t *data) + const uint8_t *data) { SL_PRINTF(SL_RSI_BLE_GATT_PREPARE_WRITE_RESPONSE, diff --git a/components/device/silabs/si91x/wireless/ble/src/rsi_bt_ble.c b/components/device/silabs/si91x/wireless/ble/src/rsi_bt_ble.c index f8a36d6f7..cf3b16b99 100644 --- a/components/device/silabs/si91x/wireless/ble/src/rsi_bt_ble.c +++ b/components/device/silabs/si91x/wireless/ble/src/rsi_bt_ble.c @@ -22,23 +22,21 @@ #include "sl_wifi_host_interface.h" #include "sl_si91x_driver.h" +#include "rsi_bt_common.h" +#include "rsi_ble.h" +#include "stdio.h" + +#include "sl_si91x_host_interface.h" + sl_status_t sl_si91x_allocate_command_buffer(sl_wifi_buffer_t **host_buffer, void **buffer, uint32_t requested_buffer_size, uint32_t wait_duration_ms); -uint32_t rsi_get_bt_state(rsi_bt_cb_t *bt_cb); -/* - Include files - */ -#include "rsi_bt_common.h" -#include "rsi_ble.h" -#include "stdio.h" +uint32_t rsi_get_bt_state(const rsi_bt_cb_t *bt_cb); #define BT_SEM 0x1 #define BT_CMD_SEM 0x2 -#include "sl_si91x_host_interface.h" - /* * Global Variables * */ @@ -46,10 +44,10 @@ uint32_t rsi_get_bt_state(rsi_bt_cb_t *bt_cb); // rsi_bt_ble.c function declarations void rsi_bt_common_register_callbacks(rsi_bt_get_ber_pkt_t rsi_bt_get_ber_pkt_from_app); uint32_t rsi_bt_get_timeout(uint16_t cmd_type, uint16_t protocol_type); -uint32_t rsi_bt_get_status(rsi_bt_cb_t *bt_cb); -void rsi_ble_update_le_dev_buf(rsi_ble_event_le_dev_buf_ind_t *rsi_ble_event_le_dev_buf_ind); -void rsi_add_remote_ble_dev_info(rsi_ble_event_enhance_conn_status_t *remote_dev_info); -void rsi_remove_remote_ble_dev_info(rsi_ble_event_disconnect_t *remote_dev_info); +uint32_t rsi_bt_get_status(const rsi_bt_cb_t *bt_cb); +void rsi_ble_update_le_dev_buf(const rsi_ble_event_le_dev_buf_ind_t *rsi_ble_event_le_dev_buf_ind); +void rsi_add_remote_ble_dev_info(const rsi_ble_event_enhance_conn_status_t *remote_dev_info); +void rsi_remove_remote_ble_dev_info(const rsi_ble_event_disconnect_t *remote_dev_info); int32_t rsi_driver_process_bt_resp( rsi_bt_cb_t *bt_cb, sl_si91x_packet_t *pkt, @@ -96,8 +94,6 @@ uint16_t rsi_bt_get_proto_type(uint16_t rsp_type, rsi_bt_cb_t **bt_cb) { SL_PRINTF(SL_RSI_BT_GET_PROTO_TYPE_TRIGGER, BLUETOOTH, LOG_INFO, "RESPONSE_TYPE: %2x", rsp_type); uint16_t return_value = 0xFF; - //static uint16_t local_prototype; - //static rsi_bt_cb_t *local_cb; if (rsp_type == RSI_BLE_EVENT_DISCONNECT) { if (rsi_driver_cb->bt_common_cb->dev_type == RSI_BT_LE_DEVICE) { @@ -106,7 +102,6 @@ uint16_t rsi_bt_get_proto_type(uint16_t rsp_type, rsi_bt_cb_t **bt_cb) } return return_value; - //} } /** @} */ // Determine the protocol type by looking at the packet type @@ -140,11 +135,6 @@ uint16_t rsi_bt_get_proto_type(uint16_t rsp_type, rsi_bt_cb_t **bt_cb) return_value = RSI_PROTO_BLE; *bt_cb = rsi_driver_cb->ble_cb; } - /*if (return_value != RSI_PROTO_BT_COMMON) - { - local_prototype = return_value; - local_cb = *bt_cb; - }*/ return return_value; } @@ -181,15 +171,15 @@ uint32_t rsi_bt_get_timeout(uint16_t cmd_type, uint16_t protocol_type) case RSI_PROTO_BLE: { if (((cmd_type >= RSI_BLE_REQ_ADV) && (cmd_type <= RSI_BLE_SMP_PASSKEY)) || ((cmd_type >= RSI_BLE_SET_ADVERTISE_DATA) && (cmd_type <= RSI_BLE_PER_RX_MODE)) - || ((cmd_type == RSI_BLE_CONN_PARAM_RESP_CMD)) - || ((cmd_type == RSI_BLE_MTU_EXCHANGE_REQUEST) || ((cmd_type == RSI_BLE_CMD_MTU_EXCHANGE_RESP)))) { + || (cmd_type == RSI_BLE_CONN_PARAM_RESP_CMD) + || ((cmd_type == RSI_BLE_MTU_EXCHANGE_REQUEST) || (cmd_type == RSI_BLE_CMD_MTU_EXCHANGE_RESP))) { return_value = RSI_BLE_GAP_CMD_RESP_WAIT_TIME; } else if (((cmd_type >= RSI_BLE_REQ_PROFILES) && (cmd_type <= RSI_BLE_CMD_INDICATE)) || ((cmd_type >= RSI_BLE_CMD_ATT_ERROR) && (cmd_type <= RSI_BLE_SET_SMP_PAIRING_CAPABILITY_DATA)) - || ((cmd_type == RSI_BLE_CMD_INDICATE_CONFIRMATION)) || (cmd_type == RSI_BLE_CMD_INDICATE_SYNC)) { + || (cmd_type == RSI_BLE_CMD_INDICATE_CONFIRMATION) || (cmd_type == RSI_BLE_CMD_INDICATE_SYNC)) { return_value = RSI_BLE_GATT_CMD_RESP_WAIT_TIME; } else { - return_value = RSI_BT_BLE_CMD_MAX_RESP_WAIT_TIME; //RSI_WAIT_FOREVER; + return_value = RSI_BT_BLE_CMD_MAX_RESP_WAIT_TIME; } } break; @@ -222,7 +212,7 @@ void rsi_bt_common_tx_done(sl_si91x_packet_t *pkt) rsp_type = rsi_bytes2R_to_uint16(host_desc + RSI_BT_RSP_TYPE_OFFSET); // Get the protocol Type - protocol_type = rsi_bt_get_proto_type(rsp_type, &bt_cb); + protocol_type = (uint8_t)rsi_bt_get_proto_type(rsp_type, &bt_cb); if (protocol_type == 0xFF) { return; @@ -249,7 +239,7 @@ void rsi_bt_common_tx_done(sl_si91x_packet_t *pkt) * Non-Zero Value - Failure */ -uint32_t rsi_get_bt_state(rsi_bt_cb_t *bt_cb) +uint32_t rsi_get_bt_state(const rsi_bt_cb_t *bt_cb) { SL_PRINTF(SL_RSI_BT_STATE_TRIGGER, BLUETOOTH, LOG_INFO); return bt_cb->state; @@ -278,7 +268,7 @@ void rsi_bt_set_status(rsi_bt_cb_t *bt_cb, int32_t status) * @return 0 - Success \n * Non-Zero Value - Failure */ -uint32_t rsi_bt_get_status(rsi_bt_cb_t *bt_cb) +uint32_t rsi_bt_get_status(const rsi_bt_cb_t *bt_cb) { return bt_cb->status; } @@ -290,14 +280,13 @@ uint32_t rsi_bt_get_status(rsi_bt_cb_t *bt_cb) * */ -void rsi_ble_update_le_dev_buf(rsi_ble_event_le_dev_buf_ind_t *rsi_ble_event_le_dev_buf_ind) +void rsi_ble_update_le_dev_buf(const rsi_ble_event_le_dev_buf_ind_t *rsi_ble_event_le_dev_buf_ind) { SL_PRINTF(SL_RSI_BT_UPDATE_LE_DEV_BUF_TRIGGER, BLUETOOTH, LOG_INFO); - uint8_t inx = 0; rsi_bt_cb_t *le_cb = rsi_driver_cb->ble_cb; - for (inx = 0; inx < (RSI_BLE_MAX_NBR_PERIPHERALS + RSI_BLE_MAX_NBR_CENTRALS); inx++) { + for (uint8_t inx = 0; inx < (RSI_BLE_MAX_NBR_PERIPHERALS + RSI_BLE_MAX_NBR_CENTRALS); inx++) { if (!memcmp(rsi_ble_event_le_dev_buf_ind->remote_dev_bd_addr, le_cb->remote_ble_info[inx].remote_dev_bd_addr, RSI_DEV_ADDR_LEN)) { @@ -322,14 +311,13 @@ void rsi_ble_update_le_dev_buf(rsi_ble_event_le_dev_buf_ind_t *rsi_ble_event_le_ * */ -void rsi_add_remote_ble_dev_info(rsi_ble_event_enhance_conn_status_t *remote_dev_info) +void rsi_add_remote_ble_dev_info(const rsi_ble_event_enhance_conn_status_t *remote_dev_info) { SL_PRINTF(SL_RSI_ADD_REMOTE_BLE_DEV_INFO_TRIGGER, BLUETOOTH, LOG_INFO); - uint8_t inx = 0; rsi_bt_cb_t *le_cb = rsi_driver_cb->ble_cb; - for (inx = 0; inx < (RSI_BLE_MAX_NBR_PERIPHERALS + RSI_BLE_MAX_NBR_CENTRALS); inx++) { + for (uint8_t inx = 0; inx < (RSI_BLE_MAX_NBR_PERIPHERALS + RSI_BLE_MAX_NBR_CENTRALS); inx++) { if (!le_cb->remote_ble_info[inx].used) { memcpy(le_cb->remote_ble_info[inx].remote_dev_bd_addr, remote_dev_info->dev_addr, RSI_DEV_ADDR_LEN); le_cb->remote_ble_info[inx].used = 1; @@ -351,14 +339,13 @@ void rsi_add_remote_ble_dev_info(rsi_ble_event_enhance_conn_status_t *remote_dev * */ -void rsi_remove_remote_ble_dev_info(rsi_ble_event_disconnect_t *remote_dev_info) +void rsi_remove_remote_ble_dev_info(const rsi_ble_event_disconnect_t *remote_dev_info) { SL_PRINTF(SL_RSI_REMOVE_REMOTE_BLE_DEV_INFO_TRIGGER, BLUETOOTH, LOG_INFO); - uint8_t inx = 0; rsi_bt_cb_t *le_cb = rsi_driver_cb->ble_cb; - for (inx = 0; inx < (RSI_BLE_MAX_NBR_PERIPHERALS + RSI_BLE_MAX_NBR_CENTRALS); inx++) { + for (uint8_t inx = 0; inx < (RSI_BLE_MAX_NBR_PERIPHERALS + RSI_BLE_MAX_NBR_CENTRALS); inx++) { if (!memcmp(remote_dev_info->dev_addr, le_cb->remote_ble_info[inx].remote_dev_bd_addr, RSI_DEV_ADDR_LEN)) { memset(le_cb->remote_ble_info[inx].remote_dev_bd_addr, 0, RSI_DEV_ADDR_LEN); le_cb->remote_ble_info[inx].used = 0; @@ -425,11 +412,12 @@ int32_t rsi_driver_process_bt_resp( if (bt_cb->expected_response_type == RSI_BT_EVENT_CARD_READY) { bt_cb->state = RSI_BT_STATE_OPERMODE_DONE; } - if (status == RSI_SUCCESS) { //To not allow BT SetAddress after these states are triggered - if (bt_cb->expected_response_type == RSI_BLE_REQ_ADV || bt_cb->expected_response_type == RSI_BLE_REQ_SCAN - || bt_cb->expected_response_type == RSI_BLE_REQ_CONN) { - rsi_driver_cb->bt_common_cb->state = RSI_BT_STATE_NONE; - } + + //To not allow BT SetAddress after these states are triggered + if ((status == RSI_SUCCESS) + && (bt_cb->expected_response_type == RSI_BLE_REQ_ADV || bt_cb->expected_response_type == RSI_BLE_REQ_SCAN + || bt_cb->expected_response_type == RSI_BLE_REQ_CONN)) { + rsi_driver_cb->bt_common_cb->state = RSI_BT_STATE_NONE; } expected_resp = bt_cb->expected_response_type; // Clear expected response type @@ -437,7 +425,6 @@ int32_t rsi_driver_process_bt_resp( // Copy the expected response to response structure/buffer, if any, passed in API if (bt_cb->expected_response_buffer != NULL) { - // If (payload_length <= RSI_BLE_GET_MAX_PAYLOAD_LENGTH(expected_response_type)) memcpy(bt_cb->expected_response_buffer, payload, payload_length); // Save expected_response pointer to a local variable, since it is being cleared below @@ -451,23 +438,21 @@ int32_t rsi_driver_process_bt_resp( if (bt_cb->sync_rsp) { /* handling this for the new buf configuration */ - if (expected_resp == RSI_BLE_RSP_SET_WWO_RESP_NOTIFY_BUF_INFO) { - if (status == RSI_SUCCESS) { - rsi_ble_set_wo_resp_notify_buf_info_t *buf_info = (rsi_ble_set_wo_resp_notify_buf_info_t *)payload; - - bt_cb->remote_ble_info[bt_cb->remote_ble_index].mode = buf_info->buf_mode; - - if (buf_info->buf_mode == 0) /* small buf cnt */ - { - bt_cb->remote_ble_info[bt_cb->remote_ble_index].max_buf_cnt = (buf_info->buf_count * 10); - bt_cb->remote_ble_info[bt_cb->remote_ble_index].avail_buf_cnt = (buf_info->buf_count * 10); - } else /* big buf cnt */ - { - bt_cb->remote_ble_info[bt_cb->remote_ble_index].max_buf_cnt = buf_info->buf_count; - bt_cb->remote_ble_info[bt_cb->remote_ble_index].avail_buf_cnt = buf_info->buf_count; - } - bt_cb->remote_ble_index = 0; /* assigning value to 0 after successful response */ + if ((expected_resp == RSI_BLE_RSP_SET_WWO_RESP_NOTIFY_BUF_INFO) && (status == RSI_SUCCESS)) { + const rsi_ble_set_wo_resp_notify_buf_info_t *buf_info = (rsi_ble_set_wo_resp_notify_buf_info_t *)payload; + + bt_cb->remote_ble_info[bt_cb->remote_ble_index].mode = buf_info->buf_mode; + + if (buf_info->buf_mode == 0) /* small buf cnt */ + { + bt_cb->remote_ble_info[bt_cb->remote_ble_index].max_buf_cnt = (buf_info->buf_count * 10); + bt_cb->remote_ble_info[bt_cb->remote_ble_index].avail_buf_cnt = (buf_info->buf_count * 10); + } else /* big buf cnt */ + { + bt_cb->remote_ble_info[bt_cb->remote_ble_index].max_buf_cnt = buf_info->buf_count; + bt_cb->remote_ble_info[bt_cb->remote_ble_index].avail_buf_cnt = buf_info->buf_count; } + bt_cb->remote_ble_index = 0; /* assigning value to 0 after successful response */ } // Signal the bt semaphore osSemaphoreRelease(bt_cb->bt_sem); @@ -501,21 +486,19 @@ uint16_t rsi_driver_process_bt_resp_handler(void *rx_pkt) { SL_PRINTF(SL_RSI_DRIVER_PROCESS_BT_RESP_HANDLER_TRIGGER, BLUETOOTH, LOG_INFO); - sl_si91x_packet_t *pkt = (sl_si91x_packet_t *)rx_pkt; - uint8_t *host_desc = NULL; - uint8_t protocol_type = 0; - uint16_t rsp_type = 0; - // uint16_t rsp_len = 0; - int16_t status = RSI_SUCCESS; - rsi_bt_cb_t *bt_cb = NULL; - rsi_ble_event_disconnect_t *temp_data = NULL; + sl_si91x_packet_t *pkt = (sl_si91x_packet_t *)rx_pkt; + uint8_t *host_desc = NULL; + uint8_t protocol_type = 0; + uint16_t rsp_type = 0; + int16_t status = RSI_SUCCESS; + rsi_bt_cb_t *bt_cb = NULL; + const rsi_ble_event_disconnect_t *temp_data = NULL; // Get Host Descriptor host_desc = pkt->desc; // Get Command response Type rsp_type = rsi_bytes2R_to_uint16(host_desc + RSI_BT_RSP_TYPE_OFFSET); - //rsp_len = rsi_bytes2R_to_uint16(host_desc + RSI_BT_RSP_LEN_OFFSET) & RSI_BT_RSP_LEN_MASK; if (rsp_type == RSI_BLE_EVENT_DISCONNECT) { @@ -526,7 +509,7 @@ uint16_t rsi_driver_process_bt_resp_handler(void *rx_pkt) } // Get the protocol Type - protocol_type = rsi_bt_get_proto_type(rsp_type, &bt_cb); + protocol_type = (uint8_t)rsi_bt_get_proto_type(rsp_type, &bt_cb); SL_PRINTF(SL_RSI_BT_DRIVER_PROCESS_BT_RESP_HANDLER_TRIGGER, BLUETOOTH, LOG_INFO, "PROTOCOL_TYPE: %1x", protocol_type); if (protocol_type == 0xFF) { @@ -535,10 +518,10 @@ uint16_t rsi_driver_process_bt_resp_handler(void *rx_pkt) // Call the corresponding protocol process rsp handler if (protocol_type == RSI_PROTO_BT_COMMON) { // Call BT common process rsp handler - status = rsi_driver_process_bt_resp(bt_cb, pkt, NULL, protocol_type); + status = (int16_t)rsi_driver_process_bt_resp(bt_cb, pkt, NULL, protocol_type); } else { // Call BLE process response handler - status = rsi_driver_process_bt_resp(bt_cb, pkt, rsi_ble_callbacks_handler, protocol_type); + status = (int16_t)rsi_driver_process_bt_resp(bt_cb, pkt, rsi_ble_callbacks_handler, protocol_type); } return status; } @@ -1005,15 +988,15 @@ void rsi_ble_callbacks_handler(rsi_bt_cb_t *ble_cb, uint16_t rsp_type, uint8_t * // This statement is added only to resolve compilation warning, value is unchanged UNUSED_PARAMETER(payload_length); // Get ble cb struct pointer - rsi_ble_cb_t *ble_specific_cb = ble_cb->bt_global_cb->ble_specific_cb; - uint16_t status = 0; - uint16_t sync_status = 0; - uint8_t le_cmd_inuse_check = 0; + const rsi_ble_cb_t *ble_specific_cb = ble_cb->bt_global_cb->ble_specific_cb; + uint16_t status = 0; + uint16_t sync_status = 0; + uint8_t le_cmd_inuse_check = 0; // updating the response status; - status = ble_cb->async_status; + status = (uint16_t)ble_cb->async_status; - sync_status = rsi_bt_get_status(ble_cb); + sync_status = (uint16_t)rsi_bt_get_status(ble_cb); SL_PRINTF(SL_RSI_BLE_CALLBACKS_HANDLER_STATUS, BLE, LOG_INFO, "STATUS: %2x", status); @@ -1029,7 +1012,6 @@ void rsi_ble_callbacks_handler(rsi_bt_cb_t *ble_cb, uint16_t rsp_type, uint8_t * ((rsi_ble_event_conn_status_t *)payload)->status = status; ble_specific_cb->ble_on_conn_status_event((rsi_ble_event_conn_status_t *)payload); } - // rsi_bt_set_status(ble_cb, RSI_BLE_STATE_CONNECTION); rsi_add_remote_ble_dev_info((rsi_ble_event_enhance_conn_status_t *)payload); } break; @@ -1038,7 +1020,6 @@ void rsi_ble_callbacks_handler(rsi_bt_cb_t *ble_cb, uint16_t rsp_type, uint8_t * ((rsi_ble_event_enhance_conn_status_t *)payload)->status = status; ble_specific_cb->ble_on_enhance_conn_status_event((rsi_ble_event_enhance_conn_status_t *)payload); } - // rsi_bt_set_status(ble_cb, RSI_BLE_STATE_CONNECTION); rsi_add_remote_ble_dev_info((rsi_ble_event_enhance_conn_status_t *)payload); } break; @@ -1046,7 +1027,6 @@ void rsi_ble_callbacks_handler(rsi_bt_cb_t *ble_cb, uint16_t rsp_type, uint8_t * if (ble_specific_cb->ble_on_disconnect_event != NULL) { ble_specific_cb->ble_on_disconnect_event((rsi_ble_event_disconnect_t *)payload, status); } - // rsi_bt_set_status(ble_cb, RSI_BLE_STATE_DSICONNECT); rsi_remove_remote_ble_dev_info((rsi_ble_event_disconnect_t *)payload); } break; case RSI_BLE_EVENT_GATT_ERROR_RESPONSE: { @@ -1383,21 +1363,19 @@ void rsi_ble_callbacks_handler(rsi_bt_cb_t *ble_cb, uint16_t rsp_type, uint8_t * ble_specific_cb->ble_on_rcp_resp_rcvd_event(status, (rsi_ble_event_rcp_rcvd_info_t *)payload); } } - default: { - } + default: + break; } if (le_cmd_inuse_check) { - uint8_t inx = 0; - uint8_t *remote_dev_bd_addr = (uint8_t *)payload; - for (inx = 0; inx < (RSI_BLE_MAX_NBR_PERIPHERALS + RSI_BLE_MAX_NBR_CENTRALS); inx++) { + const uint8_t *remote_dev_bd_addr = payload; + for (uint8_t inx = 0; inx < (RSI_BLE_MAX_NBR_PERIPHERALS + RSI_BLE_MAX_NBR_CENTRALS); inx++) { if (!memcmp(ble_cb->remote_ble_info[inx].remote_dev_bd_addr, remote_dev_bd_addr, RSI_DEV_ADDR_LEN)) { - if (ble_cb->remote_ble_info[inx].cmd_in_use) { - if ((rsp_type == RSI_BLE_EVENT_GATT_ERROR_RESPONSE) - || (rsp_type == ble_cb->remote_ble_info[inx].expected_resp)) { - ble_cb->remote_ble_info[inx].cmd_in_use = 0; - ble_cb->remote_ble_info[inx].expected_resp = 0; - } + if ((ble_cb->remote_ble_info[inx].cmd_in_use) + && ((rsp_type == RSI_BLE_EVENT_GATT_ERROR_RESPONSE) + || (rsp_type == ble_cb->remote_ble_info[inx].expected_resp))) { + ble_cb->remote_ble_info[inx].cmd_in_use = 0; + ble_cb->remote_ble_info[inx].expected_resp = 0; } break; } @@ -1501,14 +1479,14 @@ uint16_t rsi_bt_prepare_common_pkt(uint16_t cmd_type, void *cmd_struct, sl_si91x payload_size = sizeof(rsi_ble_per_receive_t); memcpy(pkt->data, cmd_struct, payload_size); break; - default: { - } + default: + return RSI_ERROR_INVALID_PARAM; } } break; case RSI_BT_VENDOR_SPECIFIC: { pkt->data[0] = ((uint8_t *)cmd_struct)[0]; pkt->data[1] = ((uint8_t *)cmd_struct)[1]; - switch ((pkt->data[0] | (pkt->data[1] << 8))) { + switch (pkt->data[0] | (pkt->data[1] << 8)) { case BLE_VENDOR_RF_TYPE_CMD_OPCODE: payload_size = sizeof(rsi_ble_vendor_rf_type_t); memcpy(pkt->data, cmd_struct, payload_size); @@ -2030,9 +2008,8 @@ uint16_t rsi_bt_prepare_le_pkt(uint16_t cmd_type, void *cmd_struct, sl_si91x_pac } if (le_buf_check || le_cmd_inuse_check || le_buf_in_use_check) { - uint8_t inx = 0; uint8_t *remote_dev_bd_addr = (uint8_t *)cmd_struct; - for (inx = 0; inx < (RSI_BLE_MAX_NBR_PERIPHERALS + RSI_BLE_MAX_NBR_CENTRALS); inx++) { + for (uint8_t inx = 0; inx < (RSI_BLE_MAX_NBR_PERIPHERALS + RSI_BLE_MAX_NBR_CENTRALS); inx++) { if (!memcmp(le_cb->remote_ble_info[inx].remote_dev_bd_addr, remote_dev_bd_addr, RSI_DEV_ADDR_LEN)) { /* ERROR PRONE : Do not changes if else checks order */ diff --git a/components/device/silabs/si91x/wireless/ble/src/rsi_bt_common_apis.c b/components/device/silabs/si91x/wireless/ble/src/rsi_bt_common_apis.c index 544add49e..36a7a212a 100644 --- a/components/device/silabs/si91x/wireless/ble/src/rsi_bt_common_apis.c +++ b/components/device/silabs/si91x/wireless/ble/src/rsi_bt_common_apis.c @@ -26,14 +26,14 @@ /****************************************************** * Function Declarations ******************************************************/ -int32_t rsi_bt_set_bd_addr(uint8_t *dev_addr); -int32_t rsi_bt_set_local_name(uint8_t *local_name); +int32_t rsi_bt_set_bd_addr(const uint8_t *dev_addr); +int32_t rsi_bt_set_local_name(const uint8_t *local_name); int32_t rsi_bt_cmd_update_gain_table_offset_or_max_pwr(uint8_t node_id, uint8_t payload_len, - uint8_t *payload, + const uint8_t *payload, uint8_t req_type); int32_t rsi_bt_get_local_name(rsi_bt_resp_get_local_name_t *bt_resp_get_local_name); -int32_t rsi_bt_get_rssi(uint8_t *dev_addr, int8_t *resp); +int32_t rsi_bt_get_rssi(const uint8_t *dev_addr, int8_t *resp); int32_t rsi_bt_get_local_device_address(uint8_t *resp); int32_t rsi_bt_get_bt_stack_version(rsi_bt_resp_get_bt_stack_version_t *bt_resp_get_bt_stack_version); int32_t rsi_bt_init(void); @@ -57,7 +57,7 @@ int32_t rsi_bt_per_stats(uint8_t cmd_type, struct rsi_bt_per_stats_s *per_stats) * -3 - Command is given in wrong state(i.e not immediate after opermode) * @note Refer to the Status Codes section for the above error codes at [additional-status-codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) . */ -int32_t rsi_bt_set_bd_addr(uint8_t *dev_addr) +int32_t rsi_bt_set_bd_addr(const uint8_t *dev_addr) { rsi_bt_set_local_bd_addr_t bd_addr; #ifdef BD_ADDR_IN_ASCII @@ -86,11 +86,11 @@ int32_t rsi_bt_set_bd_addr(uint8_t *dev_addr) * @note Refer to the Status Codes section for the above error codes at [additional-status-codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) . * */ -int32_t rsi_bt_set_local_name(uint8_t *local_name) +int32_t rsi_bt_set_local_name(const uint8_t *local_name) { uint8_t name_len; rsi_bt_req_set_local_name_t bt_req_set_local_name = { 0 }; - name_len = RSI_MIN(strlen((const char *)local_name), (RSI_DEV_NAME_LEN - 1)); + name_len = (uint8_t)RSI_MIN(strlen((const char *)local_name), (RSI_DEV_NAME_LEN - 1)); memcpy(bt_req_set_local_name.name, local_name, name_len); bt_req_set_local_name.name[name_len] = 0; @@ -123,7 +123,7 @@ int32_t rsi_bt_set_local_name(uint8_t *local_name) */ int32_t rsi_bt_cmd_update_gain_table_offset_or_max_pwr(uint8_t node_id, uint8_t payload_len, - uint8_t *payload, + const uint8_t *payload, uint8_t req_type) { rsi_bt_cmd_update_gain_table_offset_or_maxpower_t bt_gain_table_offset = { 0 }; @@ -163,7 +163,7 @@ int32_t rsi_bt_get_local_name(rsi_bt_resp_get_local_name_t *bt_resp_get_local_na * Non-Zero Value - Failure * @note Refer to the Status Codes section for the above error codes at [additional-status-codes](../wiseconnect-api-reference-guide-err-codes/sl-additional-status-errors) . */ -int32_t rsi_bt_get_rssi(uint8_t *dev_addr, int8_t *resp) +int32_t rsi_bt_get_rssi(const uint8_t *dev_addr, int8_t *resp) { rsi_bt_get_rssi_t bt_rssi = { { 0 } }; #ifdef BD_ADDR_IN_ASCII @@ -382,7 +382,7 @@ int32_t rsi_bt_power_save_profile(uint8_t psp_mode, uint8_t psp_type) } break; case RSI_SLEEP_MODE_2: { if (psp_type == RSI_MAX_PSP) { - profile.profile = ASSOCIATED_POWER_SAVE; + profile.profile = ASSOCIATED_POWER_SAVE_LOW_LATENCY; } else { return RSI_FEATURE_NOT_SUPPORTED; } diff --git a/components/device/silabs/si91x/wireless/ble/src/rsi_common_apis.c b/components/device/silabs/si91x/wireless/ble/src/rsi_common_apis.c index 0fabf6ef6..62890c970 100644 --- a/components/device/silabs/si91x/wireless/ble/src/rsi_common_apis.c +++ b/components/device/silabs/si91x/wireless/ble/src/rsi_common_apis.c @@ -68,14 +68,12 @@ int32_t rsi_ble_driver_init(uint8_t *buffer, uint32_t length) { uint32_t actual_length = 0; - // If (((uint32_t)buffer & 3) != 0) if (((uintptr_t)buffer & 3) != 0) // To avoid compiler warning, replace uint32_t with uintptr_t { // Making buffer 4 byte aligned // Length -= (4 - ((uint32_t)buffer & 3)); // To avoid compiler warning, replace uint32_t with uintptr_t length -= (4 - ((uintptr_t)buffer & 3)); - // Buffer = (uint8_t *)(((uint32_t)buffer + 3) & ~3);// To avoid compiler warning, replace uint32_t with uintptr_t buffer = (uint8_t *)(((uintptr_t)buffer + 3) & ~3); } @@ -163,7 +161,7 @@ int32_t rsi_ble_driver_deinit(void) SL_PRINTF(SL_DRIVER_DEINIT_ENTRY, COMMON, LOG_INFO); uint32_t actual_length = 0; - if ((rsi_driver_cb->device_state < RSI_DRIVER_INIT_DONE)) { + if (rsi_driver_cb->device_state < RSI_DRIVER_INIT_DONE) { // Command given in wrong state return RSI_ERROR_COMMAND_GIVEN_IN_WRONG_STATE; } diff --git a/components/device/silabs/si91x/wireless/ble/src/rsi_utils.c b/components/device/silabs/si91x/wireless/ble/src/rsi_utils.c index 865722f1a..de6f5a498 100644 --- a/components/device/silabs/si91x/wireless/ble/src/rsi_utils.c +++ b/components/device/silabs/si91x/wireless/ble/src/rsi_utils.c @@ -78,7 +78,7 @@ void rsi_uint32_to_4bytes(uint8_t *dBuf, uint32_t val) * @param[in] dBuf - Pointer to a buffer to get the data from * @return Converted 16 bit data */ -uint16_t rsi_bytes2R_to_uint16(uint8_t *dBuf) +uint16_t rsi_bytes2R_to_uint16(const uint8_t *dBuf) { uint16_t val; if (rsi_driver_cb->endian == IS_LITTLE_ENDIAN) { @@ -101,7 +101,7 @@ uint16_t rsi_bytes2R_to_uint16(uint8_t *dBuf) * @return Converted 32 bit data */ -uint32_t rsi_bytes4R_to_uint32(uint8_t *dBuf) +uint32_t rsi_bytes4R_to_uint32(const uint8_t *dBuf) { // the 32-bit value to return uint32_t val; @@ -157,8 +157,7 @@ int8_t rsi_ascii_hex2num(int8_t ascii_hex_in) int8_t rsi_char_hex2dec(int8_t *cBuf) { int8_t k = 0; - uint8_t i; - for (i = 0; i < strlen((char *)cBuf); i++) { + for (uint8_t i = 0; i < strlen((char *)cBuf); i++) { k = ((k * 16) + rsi_ascii_hex2num(cBuf[i])); } return k; @@ -175,14 +174,13 @@ int8_t rsi_char_hex2dec(int8_t *cBuf) uint8_t *rsi_ascii_dev_address_to_6bytes_rev(uint8_t *hex_addr, int8_t *ascii_mac_address) { - uint8_t i; // loop counter uint8_t cBufPos; // which char in the ASCII representation uint8_t byteNum; // which byte in the 32Bithex_address int8_t cBuf[6]; // temporary buffer byteNum = 5; cBufPos = 0; - for (i = 0; i < strlen((char *)ascii_mac_address); i++) { + for (uint8_t i = 0; i < strlen((char *)ascii_mac_address); i++) { // this will take care of the first 5 octets if (ascii_mac_address[i] == ':') { // we are at the end of the address octet cBuf[cBufPos] = 0; // terminate the string @@ -233,7 +231,6 @@ int8_t hex_to_ascii(uint8_t hex_num) case 0xf: ascii = (hex_num & 0x0F) - 10 + 'A'; return ascii; - // break; default: break; } @@ -250,14 +247,12 @@ int8_t hex_to_ascii(uint8_t hex_num) * @return Converted ASCII mac address */ -uint8_t *rsi_6byte_dev_address_to_ascii(uint8_t *ascii_mac_address, uint8_t *hex_addr) +uint8_t *rsi_6byte_dev_address_to_ascii(uint8_t *ascii_mac_address, const uint8_t *hex_addr) { - int8_t i; // loop counter uint8_t cBufPos; // which char in the ASCII representation - //byteNum = 5; cBufPos = 0; - for (i = 5; i >= 0; i--) { + for (int8_t i = 5; i >= 0; i--) { ascii_mac_address[cBufPos++] = hex_to_ascii(hex_addr[i] >> 4); ascii_mac_address[cBufPos++] = hex_to_ascii(hex_addr[i]); if (i != 0) { @@ -291,12 +286,11 @@ uint8_t convert_lower_case_to_upper_case(uint8_t lwrcase) * @return void */ -void string2array(uint8_t *dst, uint8_t *src, uint32_t length) +void string2array(uint8_t *dst, const uint8_t *src, uint32_t length) { - uint32_t i = 0, j = 0; - for (i = 0, j = 0; i < (length * 2) && j < length; i += 2, j++) + for (uint32_t i = 0, j = 0; i < (length * 2) && j < length; i += 2, j++) if (src[i] && src[i + 1]) { - dst[j] = ((uint16_t)convert_lower_case_to_upper_case(src[i])) * 16; + dst[j] = (uint8_t)((convert_lower_case_to_upper_case(src[i])) * 16); dst[j] += convert_lower_case_to_upper_case(src[i + 1]); } else { dst[j] = 0; @@ -313,7 +307,8 @@ void string2array(uint8_t *dst, uint8_t *src, uint32_t length) uint8_t *rsi_itoa(uint32_t val, uint8_t *str) { - int16_t ii = 0, jj = 0; + int16_t ii = 0; + int16_t jj = 0; uint8_t tmp[10]; if (val == 0) { // if value is zero then handling @@ -392,8 +387,7 @@ int8_t asciihex_2_num(int8_t ascii_hex_in) int8_t rsi_charhex_2_dec(int8_t *cBuf) { int8_t k = 0; - uint8_t i; - for (i = 0; i < strlen((char *)cBuf); i++) { + for (uint8_t i = 0; i < strlen((char *)cBuf); i++) { k = ((k * 16) + asciihex_2_num(cBuf[i])); } return k; @@ -409,14 +403,13 @@ int8_t rsi_charhex_2_dec(int8_t *cBuf) */ void rsi_ascii_mac_address_to_6bytes(uint8_t *hexAddr, int8_t *asciiMacAddress) { - uint8_t i; // loop counter uint8_t cBufPos; // which char in the ASCII representation uint8_t byteNum; // which byte in the 32BitHexAddress int8_t cBuf[6]; // temporary buffer byteNum = 0; cBufPos = 0; - for (i = 0; i < strlen((char *)asciiMacAddress); i++) { + for (uint8_t i = 0; i < strlen((char *)asciiMacAddress); i++) { // this will take care of the first 5 octets if (asciiMacAddress[i] == ':') { // we are at the end of the address octet cBuf[cBufPos] = 0; // terminate the string @@ -441,8 +434,6 @@ void rsi_ascii_mac_address_to_6bytes(uint8_t *hexAddr, int8_t *asciiMacAddress) */ void rsi_ascii_dot_address_to_4bytes(uint8_t *hexAddr, int8_t *asciiDotAddress) { - uint8_t i; - // loop counter uint8_t cBufPos; // which char in the ASCII representation uint8_t byteNum; @@ -452,7 +443,7 @@ void rsi_ascii_dot_address_to_4bytes(uint8_t *hexAddr, int8_t *asciiDotAddress) byteNum = 0; cBufPos = 0; - for (i = 0; i < strlen((char *)asciiDotAddress); i++) { + for (uint8_t i = 0; i < strlen((char *)asciiDotAddress); i++) { // this will take care of the first 3 octets if (asciiDotAddress[i] == '.') { // we are at the end of the address octet @@ -480,9 +471,12 @@ void rsi_ascii_dot_address_to_4bytes(uint8_t *hexAddr, int8_t *asciiDotAddress) * @param[in] ip - IP address to convert. * @return IP address in reverse Hex format */ -uint64_t ip_to_reverse_hex(char *ip) +uint64_t ip_to_reverse_hex(const char *ip) { - uint32_t ip1, ip2, ip3, ip4; + uint32_t ip1; + uint32_t ip2; + uint32_t ip3; + uint32_t ip4; uint64_t ip_hex; uint32_t status; @@ -508,7 +502,7 @@ uint64_t ip_to_reverse_hex(char *ip) // network to host long uint32_t rsi_ntohl(uint32_t a) { - return ((((a)&0xff000000) >> 24) | (((a)&0x00ff0000) >> 8) | (((a)&0x0000ff00) << 8) | (((a)&0x000000ff) << 24)); + return (((a & 0xff000000) >> 24) | ((a & 0x00ff0000) >> 8) | ((a & 0x0000ff00) << 8) | ((a & 0x000000ff) << 24)); } /** @} */ diff --git a/components/device/silabs/si91x/wireless/crypto/attestation/src/sl_si91x_attestation.c b/components/device/silabs/si91x/wireless/crypto/attestation/src/sl_si91x_attestation.c index af401c0c1..887202d05 100644 --- a/components/device/silabs/si91x/wireless/crypto/attestation/src/sl_si91x_attestation.c +++ b/components/device/silabs/si91x/wireless/crypto/attestation/src/sl_si91x_attestation.c @@ -54,8 +54,8 @@ sl_status_t sl_si91x_attestation_get_token(uint8_t *token, uint16_t length, uint return SL_STATUS_INVALID_PARAMETER; } sl_status_t status; - sl_wifi_buffer_t *buffer; - sl_si91x_packet_t *packet; + sl_wifi_buffer_t *buffer = NULL; + sl_si91x_packet_t *packet = NULL; sl_si91x_rsi_token_req_t *attest = (sl_si91x_rsi_token_req_t *)malloc(sizeof(sl_si91x_rsi_token_req_t)); @@ -73,6 +73,7 @@ sl_status_t sl_si91x_attestation_get_token(uint8_t *token, uint16_t length, uint attest->total_msg_length = length; #ifdef SL_SI91X_SIDE_BAND_CRYPTO + UNUSED_VARIABLE(packet); // to avoid unused variable warning attest->msg = nonce; attest->token_buf = token; #else diff --git a/components/device/silabs/si91x/wireless/crypto/ccm/src/sl_si91x_ccm.c b/components/device/silabs/si91x/wireless/crypto/ccm/src/sl_si91x_ccm.c index 5c769cb79..96c9598f3 100644 --- a/components/device/silabs/si91x/wireless/crypto/ccm/src/sl_si91x_ccm.c +++ b/components/device/silabs/si91x/wireless/crypto/ccm/src/sl_si91x_ccm.c @@ -39,6 +39,39 @@ #endif #include +static sl_status_t sli_si91x_ccm_config_check(sl_si91x_ccm_config_t *config) +{ + // Only 32 bytes M4 OTA built-in key support is present + if (config->key_config.b0.key_type == SL_SI91X_BUILT_IN_KEY) { + if (((int)config->key_config.b0.key_size != (int)SL_SI91X_KEY_SIZE_1) + || (config->key_config.b0.key_slot != SL_SI91X_KEY_SLOT_1)) + return SL_STATUS_INVALID_PARAMETER; + } + + if ((config->nonce_length < SL_SI91X_CCM_IV_MIN_SIZE) || (config->nonce_length > SL_SI91X_CCM_IV_MAX_SIZE)) { + return SL_STATUS_INVALID_PARAMETER; + } + + return SL_STATUS_OK; +} + +#ifdef SLI_SI917B0 +static void sli_si91x_ccm_get_key_info(sl_si91x_ccm_request_t *request, const sl_si91x_ccm_config_t *config) +{ + request->key_info.key_type = config->key_config.b0.key_type; + request->key_info.key_detail.key_size = config->key_config.b0.key_size; + request->key_info.key_detail.key_spec.key_slot = config->key_config.b0.key_slot; + request->key_info.key_detail.key_spec.wrap_iv_mode = config->key_config.b0.wrap_iv_mode; + request->key_info.reserved = config->key_config.b0.reserved; + if (config->key_config.b0.wrap_iv_mode) { + memcpy(request->key_info.key_detail.key_spec.wrap_iv, config->key_config.b0.wrap_iv, SL_SI91X_IV_SIZE); + } + memcpy(request->key_info.key_detail.key_spec.key_buffer, + config->key_config.b0.key_buffer, + config->key_config.b0.key_size); +} +#endif + #ifndef SL_SI91X_SIDE_BAND_CRYPTO static sl_status_t sli_si91x_ccm_pending(sl_si91x_ccm_config_t *config, uint16_t chunk_length, @@ -52,15 +85,9 @@ static sl_status_t sli_si91x_ccm_pending(sl_si91x_ccm_config_t *config, SL_VERIFY_POINTER_OR_RETURN(request, SL_STATUS_ALLOCATION_FAILED); - // Only 32 bytes M4 OTA built-in key support is present - if (config->key_config.b0.key_type == SL_SI91X_BUILT_IN_KEY) { - if (((int)config->key_config.b0.key_size != (int)SL_SI91X_KEY_SIZE_1) - || (config->key_config.b0.key_slot != SL_SI91X_KEY_SLOT_1)) - return SL_STATUS_INVALID_PARAMETER; - } - - if ((config->nonce_length < SL_SI91X_CCM_IV_MIN_SIZE) || (config->nonce_length > SL_SI91X_CCM_IV_MAX_SIZE)) { - return SL_STATUS_INVALID_PARAMETER; + status = sli_si91x_ccm_config_check(config); + if (status != SL_STATUS_OK) { + return status; } memset(request, 0, sizeof(sl_si91x_ccm_request_t)); @@ -84,17 +111,7 @@ static sl_status_t sli_si91x_ccm_pending(sl_si91x_ccm_config_t *config, memcpy(request->tag, config->tag, config->tag_length); #ifdef SLI_SI917B0 - request->key_info.key_type = config->key_config.b0.key_type; - request->key_info.key_detail.key_size = config->key_config.b0.key_size; - request->key_info.key_detail.key_spec.key_slot = config->key_config.b0.key_slot; - request->key_info.key_detail.key_spec.wrap_iv_mode = config->key_config.b0.wrap_iv_mode; - request->key_info.reserved = config->key_config.b0.reserved; - if (config->key_config.b0.wrap_iv_mode) { - memcpy(request->key_info.key_detail.key_spec.wrap_iv, config->key_config.b0.wrap_iv, SL_SI91X_IV_SIZE); - } - memcpy(request->key_info.key_detail.key_spec.key_buffer, - config->key_config.b0.key_buffer, - config->key_config.b0.key_size); + sli_si91x_ccm_get_key_info(request, config); #else memcpy(request->key, config->key_config.a0.key, request->key_length); @@ -143,15 +160,9 @@ static sl_status_t sli_si91x_ccm_side_band(sl_si91x_ccm_config_t *config, uint8_ SL_VERIFY_POINTER_OR_RETURN(request, SL_STATUS_ALLOCATION_FAILED); - // Only 32 bytes M4 OTA built-in key support is present - if (config->key_config.b0.key_type == SL_SI91X_BUILT_IN_KEY) { - if (((int)config->key_config.b0.key_size != (int)SL_SI91X_KEY_SIZE_1) - || (config->key_config.b0.key_slot != SL_SI91X_KEY_SLOT_1)) - return SL_STATUS_INVALID_PARAMETER; - } - - if ((config->nonce_length < SL_SI91X_CCM_IV_MIN_SIZE) || (config->nonce_length > SL_SI91X_CCM_IV_MAX_SIZE)) { - return SL_STATUS_INVALID_PARAMETER; + status = sli_si91x_ccm_config_check(config); + if (status != SL_STATUS_OK) { + return status; } memset(request, 0, sizeof(sl_si91x_ccm_request_t)); @@ -172,18 +183,7 @@ static sl_status_t sli_si91x_ccm_side_band(sl_si91x_ccm_config_t *config, uint8_ request->nonce = (uint8_t *)config->nonce; request->tag = config->tag; - request->key_info.key_type = config->key_config.b0.key_type; - request->key_info.key_detail.key_size = config->key_config.b0.key_size; - request->key_info.key_detail.key_spec.key_slot = config->key_config.b0.key_slot; - request->key_info.key_detail.key_spec.wrap_iv_mode = config->key_config.b0.wrap_iv_mode; - request->key_info.reserved = config->key_config.b0.reserved; - if (config->key_config.b0.wrap_iv_mode) { - memcpy(request->key_info.key_detail.key_spec.wrap_iv, config->key_config.b0.wrap_iv, SL_SI91X_IV_SIZE); - } - memcpy(request->key_info.key_detail.key_spec.key_buffer, - config->key_config.b0.key_buffer, - config->key_config.b0.key_size); - + sli_si91x_ccm_get_key_info(request, config); request->output = output; status = sl_si91x_driver_send_side_band_crypto(RSI_COMMON_REQ_ENCRYPT_CRYPTO, diff --git a/components/device/silabs/si91x/wireless/crypto/ecdsa/src/sl_si91x_psa_ecdsa.c b/components/device/silabs/si91x/wireless/crypto/ecdsa/src/sl_si91x_psa_ecdsa.c index 86e49dcfa..a67f3e47d 100644 --- a/components/device/silabs/si91x/wireless/crypto/ecdsa/src/sl_si91x_psa_ecdsa.c +++ b/components/device/silabs/si91x/wireless/crypto/ecdsa/src/sl_si91x_psa_ecdsa.c @@ -31,14 +31,6 @@ #include "sl_si91x_driver.h" #include -// ----------------------------------------------------------------------------- -// Global Variables -// ----------------------------------------------------------------------------- -uint8_t r_size = 0; -uint8_t s_size = 0; -uint8_t r_bit = 0; -uint8_t s_bit = 0; - /** * \brief Validate that the curve and algorithm combination is supported by hardware * @@ -200,31 +192,49 @@ psa_status_t sli_si91x_crypto_sign_message(const psa_key_attributes_t *attribute status = SL_STATUS_INVALID_SIGNATURE; /* Convert DER format signature to compact format */ - r_size = sign_buf[3]; - s_size = sign_buf[5 + r_size]; + uint8_t r_size = sign_buf[3]; + uint8_t s_size = sign_buf[5 + r_size]; - uint8_t r_index = 4; - uint8_t s_index = 6 + r_size; + uint8_t r_index = 4; + uint8_t s_index = 6 + r_size; + uint8_t r_bit = 0; + uint8_t s_bit = 0; + uint8_t r_leading = 0; + uint8_t s_leading = 0; if (key_buffer_size == SL_SI91X_ECDSA_PRIV_KEY_SIZE_224) { if (r_size == SL_SI91X_ECDSA_SIGN_HALF_SIZE_P224R1 + 1) r_bit = 1; if (s_size == SL_SI91X_ECDSA_SIGN_HALF_SIZE_P224R1 + 1) s_bit = 1; - memcpy(signature, &sign_buf[r_index + r_bit], SL_SI91X_ECDSA_SIGN_HALF_SIZE_P224R1); - memcpy(&signature[SL_SI91X_ECDSA_SIGN_HALF_SIZE_P224R1], + if (r_size == SL_SI91X_ECDSA_SIGN_HALF_SIZE_P224R1 - 1) + r_leading = 1; + if (s_size == SL_SI91X_ECDSA_SIGN_HALF_SIZE_P224R1 - 1) + s_leading = 1; + + signature[0] = 0x00; + signature[SL_SI91X_ECDSA_SIGN_HALF_SIZE_P224R1] = 0x00; + memcpy(&signature[0 + r_leading], &sign_buf[r_index + r_bit], SL_SI91X_ECDSA_SIGN_HALF_SIZE_P224R1 - r_leading); + memcpy(&signature[SL_SI91X_ECDSA_SIGN_HALF_SIZE_P224R1 + s_leading], &sign_buf[s_index + s_bit], - SL_SI91X_ECDSA_SIGN_HALF_SIZE_P224R1); + SL_SI91X_ECDSA_SIGN_HALF_SIZE_P224R1 - s_leading); } else if (key_buffer_size == SL_SI91X_ECDSA_PRIV_KEY_SIZE_256) { if (r_size == SL_SI91X_ECDSA_SIGN_HALF_SIZE_P256R1 + 1) r_bit = 1; if (s_size == SL_SI91X_ECDSA_SIGN_HALF_SIZE_P256R1 + 1) s_bit = 1; - memcpy(signature, &sign_buf[r_index + r_bit], SL_SI91X_ECDSA_SIGN_HALF_SIZE_P256R1); - memcpy(&signature[SL_SI91X_ECDSA_SIGN_HALF_SIZE_P256R1], + if (r_size == SL_SI91X_ECDSA_SIGN_HALF_SIZE_P256R1 - 1) + r_leading = 1; + if (s_size == SL_SI91X_ECDSA_SIGN_HALF_SIZE_P256R1 - 1) + s_leading = 1; + + signature[0] = 0x00; + signature[SL_SI91X_ECDSA_SIGN_HALF_SIZE_P256R1] = 0x00; + memcpy(&signature[0 + r_leading], &sign_buf[r_index + r_bit], SL_SI91X_ECDSA_SIGN_HALF_SIZE_P256R1 - r_leading); + memcpy(&signature[SL_SI91X_ECDSA_SIGN_HALF_SIZE_P256R1 + s_leading], &sign_buf[s_index + s_bit], - SL_SI91X_ECDSA_SIGN_HALF_SIZE_P256R1); + SL_SI91X_ECDSA_SIGN_HALF_SIZE_P256R1 - s_leading); } /* gets the si91x error codes and returns its equivalent psa_status codes */ @@ -349,8 +359,55 @@ psa_status_t sli_si91x_crypto_verify_message(const psa_key_attributes_t *attribu config.key_config.a0.key_length = key_buffer_size; #endif + uint8_t r_size = 0; + uint8_t s_size = 0; + uint8_t r_bit = 0; + uint8_t s_bit = 0; + uint8_t r_leading = 0; + uint8_t s_leading = 0; + /* Convert compact format signature to DER format */ + if (key_buffer_size == SL_SI91X_ECDSA_PUB_KEY_SIZE_224) { + r_size = s_size = SL_SI91X_ECDSA_SIGN_HALF_SIZE_P224R1; + if (signature[0] >= 0x80) { + r_bit = 1; + r_size++; + } + if (signature[SL_SI91X_ECDSA_SIGN_HALF_SIZE_P224R1] >= 0x80) { + s_bit = 1; + s_size++; + } + if (signature[0] == 0x00) { + r_leading++; + r_size--; + } + if (signature[SL_SI91X_ECDSA_SIGN_HALF_SIZE_P224R1] == 0x00) { + s_leading++; + s_size--; + } + } + + else if (key_buffer_size == SL_SI91X_ECDSA_PUB_KEY_SIZE_256) { + r_size = s_size = SL_SI91X_ECDSA_SIGN_HALF_SIZE_P256R1; + if (signature[0] >= 0x80) { + r_bit = 1; + r_size++; + } + if (signature[SL_SI91X_ECDSA_SIGN_HALF_SIZE_P256R1] >= 0x80) { + s_bit = 1; + s_size++; + } + if (signature[0] == 0x00) { + r_leading++; + r_size--; + } + if (signature[SL_SI91X_ECDSA_SIGN_HALF_SIZE_P256R1] == 0x00) { + s_leading++; + s_size--; + } + } + uint8_t sign_size = r_size + s_size + 4; uint8_t total_size = sign_size + 2; uint8_t s_index = r_size + 6; @@ -369,17 +426,13 @@ psa_status_t sli_si91x_crypto_verify_message(const psa_key_attributes_t *attribu sign_buf[s_index] = 0; if (key_buffer_size == SL_SI91X_ECDSA_PUB_KEY_SIZE_224) { - memcpy(&sign_buf[r_index + r_bit], &signature[0], SL_SI91X_ECDSA_SIGN_HALF_SIZE_P224R1); - memcpy(&sign_buf[s_index + s_bit], - &signature[SL_SI91X_ECDSA_SIGN_HALF_SIZE_P224R1], - SL_SI91X_ECDSA_SIGN_HALF_SIZE_P224R1); + memcpy(&sign_buf[r_index + r_bit], &signature[0 + r_leading], r_size - r_bit); + memcpy(&sign_buf[s_index + s_bit], &signature[SL_SI91X_ECDSA_SIGN_HALF_SIZE_P224R1 + s_leading], s_size - s_bit); } else if (key_buffer_size == SL_SI91X_ECDSA_PUB_KEY_SIZE_256) { - memcpy(&sign_buf[r_index + r_bit], &signature[0], SL_SI91X_ECDSA_SIGN_HALF_SIZE_P256R1); - memcpy(&sign_buf[s_index + s_bit], - &signature[SL_SI91X_ECDSA_SIGN_HALF_SIZE_P256R1], - SL_SI91X_ECDSA_SIGN_HALF_SIZE_P256R1); + memcpy(&sign_buf[r_index + r_bit], &signature[0 + r_leading], r_size - r_bit); + memcpy(&sign_buf[s_index + s_bit], &signature[SL_SI91X_ECDSA_SIGN_HALF_SIZE_P256R1 + s_leading], s_size - s_bit); } uint8_t *output = (uint8_t *)malloc(sizeof(uint8_t)); diff --git a/components/device/silabs/si91x/wireless/crypto/gcm/src/sl_si91x_gcm.c b/components/device/silabs/si91x/wireless/crypto/gcm/src/sl_si91x_gcm.c index 7527e8db5..e5253f0a1 100644 --- a/components/device/silabs/si91x/wireless/crypto/gcm/src/sl_si91x_gcm.c +++ b/components/device/silabs/si91x/wireless/crypto/gcm/src/sl_si91x_gcm.c @@ -39,6 +39,22 @@ #endif #include +#ifdef SLI_SI917B0 +static void sli_si91x_gcm_get_key_info(sl_si91x_gcm_request_t *request, const sl_si91x_gcm_config_t *config) +{ + request->gcm_mode = config->gcm_mode; + request->key_info.key_type = config->key_config.b0.key_type; + request->key_info.key_detail.key_size = (config->key_config.b0.key_size) * 8; + request->key_info.key_detail.key_spec.key_slot = config->key_config.b0.key_slot; + request->key_info.key_detail.key_spec.wrap_iv_mode = config->key_config.b0.wrap_iv_mode; + request->key_info.reserved = config->key_config.b0.reserved; + if (config->key_config.b0.wrap_iv_mode) { + memcpy(request->key_info.key_detail.key_spec.wrap_iv, config->key_config.b0.wrap_iv, SL_SI91X_IV_SIZE); + } + memcpy(request->key_info.key_detail.key_spec.key_buffer, config->key_config.b0.key_buffer, SL_SI91X_KEY_BUFFER_SIZE); +} +#endif + #ifndef SL_SI91X_SIDE_BAND_CRYPTO static sl_status_t sli_si91x_gcm_pending(sl_si91x_gcm_config_t *config, uint16_t chunk_length, @@ -84,18 +100,7 @@ static sl_status_t sli_si91x_gcm_pending(sl_si91x_gcm_config_t *config, memcpy(request->msg, config->msg, chunk_length); #ifdef SLI_SI917B0 - request->gcm_mode = config->gcm_mode; - request->key_info.key_type = config->key_config.b0.key_type; - request->key_info.key_detail.key_size = (config->key_config.b0.key_size) * 8; - request->key_info.key_detail.key_spec.key_slot = config->key_config.b0.key_slot; - request->key_info.key_detail.key_spec.wrap_iv_mode = config->key_config.b0.wrap_iv_mode; - request->key_info.reserved = config->key_config.b0.reserved; - if (config->key_config.b0.wrap_iv_mode) { - memcpy(request->key_info.key_detail.key_spec.wrap_iv, config->key_config.b0.wrap_iv, SL_SI91X_IV_SIZE); - } - memcpy(request->key_info.key_detail.key_spec.key_buffer, - config->key_config.b0.key_buffer, - config->key_config.b0.key_size); + sli_si91x_gcm_get_key_info(request, config); #else memcpy(request->key, config->key_config.a0.key, request->key_length); @@ -165,18 +170,7 @@ static sl_status_t sli_si91x_gcm_side_band(sl_si91x_gcm_config_t *config, uint8_ request->msg = (uint8_t *)config->msg; request->output = output; - request->gcm_mode = config->gcm_mode; - request->key_info.key_type = config->key_config.b0.key_type; - request->key_info.key_detail.key_size = (config->key_config.b0.key_size) * 8; - request->key_info.key_detail.key_spec.key_slot = config->key_config.b0.key_slot; - request->key_info.key_detail.key_spec.wrap_iv_mode = config->key_config.b0.wrap_iv_mode; - request->key_info.reserved = config->key_config.b0.reserved; - if (config->key_config.b0.wrap_iv_mode) { - memcpy(request->key_info.key_detail.key_spec.wrap_iv, config->key_config.b0.wrap_iv, SL_SI91X_IV_SIZE); - } - memcpy(request->key_info.key_detail.key_spec.key_buffer, - config->key_config.b0.key_buffer, - config->key_config.b0.key_size); + sli_si91x_gcm_get_key_info(request, config); status = sl_si91x_driver_send_side_band_crypto(RSI_COMMON_REQ_ENCRYPT_CRYPTO, request, diff --git a/components/device/silabs/si91x/wireless/crypto/hmac/src/sl_si91x_hmac.c b/components/device/silabs/si91x/wireless/crypto/hmac/src/sl_si91x_hmac.c index e02da0de6..ec513da90 100644 --- a/components/device/silabs/si91x/wireless/crypto/hmac/src/sl_si91x_hmac.c +++ b/components/device/silabs/si91x/wireless/crypto/hmac/src/sl_si91x_hmac.c @@ -173,6 +173,10 @@ sl_status_t sl_si91x_hmac(sl_si91x_hmac_config_t *config, uint8_t *output) memcpy((data + key_length), config->msg, config->msg_length); // Copy message into data #ifdef SL_SI91X_SIDE_BAND_CRYPTO + // to avoid unused variable warning + UNUSED_VARIABLE(chunk_len); + UNUSED_VARIABLE(offset); + UNUSED_VARIABLE(hmac_sha_flags); status = sli_si91x_hmac_side_band(total_length, data, config, output); return status; #else diff --git a/components/device/silabs/si91x/wireless/crypto/sha/src/sl_si91x_sha.c b/components/device/silabs/si91x/wireless/crypto/sha/src/sl_si91x_sha.c index fc4fd7f1f..8846a6d4e 100644 --- a/components/device/silabs/si91x/wireless/crypto/sha/src/sl_si91x_sha.c +++ b/components/device/silabs/si91x/wireless/crypto/sha/src/sl_si91x_sha.c @@ -27,13 +27,13 @@ #include "sl_si91x_sha.h" #include +#ifndef SL_SI91X_SIDE_BAND_CRYPTO static const uint8_t sha_digest_len_table[] = { [SL_SI91x_SHA_1] = SL_SI91x_SHA_1_DIGEST_LEN, [SL_SI91x_SHA_256] = SL_SI91x_SHA_256_DIGEST_LEN, [SL_SI91x_SHA_384] = SL_SI91x_SHA_384_DIGEST_LEN, [SL_SI91x_SHA_512] = SL_SI91x_SHA_512_DIGEST_LEN, [SL_SI91x_SHA_224] = SL_SI91x_SHA_224_DIGEST_LEN }; -#ifndef SL_SI91X_SIDE_BAND_CRYPTO static sl_status_t sli_si91x_sha_pending(uint8_t sha_mode, uint8_t *msg, uint16_t msg_length, @@ -94,6 +94,9 @@ static sl_status_t sli_si91x_sha_pending(uint8_t sha_mode, packet = sl_si91x_host_get_buffer_data(buffer, 0, NULL); + if (pending_flag == (LAST_CHUNK | FIRST_CHUNK) || pending_flag == LAST_CHUNK) { + SL_ASSERT(packet->length == sha_digest_len_table[sha_mode]); + } memcpy(digest, packet->data, sha_digest_len_table[sha_mode]); free(request); @@ -147,12 +150,6 @@ sl_status_t sl_si91x_sha(uint8_t sha_mode, uint8_t *msg, uint16_t msg_length, ui { sl_status_t status = SL_STATUS_OK; SL_PRINTF(SL_SHA_ENTRY, CRYPTO, LOG_INFO); - uint16_t total_len = 0; - uint16_t chunk_len = 0; - uint16_t offset = 0; - uint8_t sha_flags = 0; - - total_len = msg_length; #if defined(SLI_MULTITHREAD_DEVICE_SI91X) if (crypto_sha_mutex == NULL) { @@ -165,7 +162,12 @@ sl_status_t sl_si91x_sha(uint8_t sha_mode, uint8_t *msg, uint16_t msg_length, ui status = sli_si91x_sha_side_band(sha_mode, msg, msg_length, digest); return status; #else + uint16_t total_len = 0; + uint16_t chunk_len = 0; + uint16_t offset = 0; + uint8_t sha_flags = 0; + total_len = msg_length; if (total_len != 0) { while (total_len) { // Check total length diff --git a/components/device/silabs/si91x/wireless/crypto/trng/src/sl_si91x_trng.c b/components/device/silabs/si91x/wireless/crypto/trng/src/sl_si91x_trng.c index 7102eb5bd..b5a0f0980 100644 --- a/components/device/silabs/si91x/wireless/crypto/trng/src/sl_si91x_trng.c +++ b/components/device/silabs/si91x/wireless/crypto/trng/src/sl_si91x_trng.c @@ -31,6 +31,39 @@ uint32_t trng_key[TRNG_KEY_SIZE] = { 0x16157E2B, 0xA6D2AE28, 0x8815F7AB, 0x3C4FCF09 }; #endif //SLI_TRNG_DEVICE_SI91X +#ifndef SL_SI91X_SIDE_BAND_CRYPTO +static sl_status_t sli_si91x_trng_send_command(sl_si91x_trng_request_t *request, sl_wifi_buffer_t **buffer) +{ + sl_status_t status = SL_STATUS_OK; + +#if defined(SLI_MULTITHREAD_DEVICE_SI91X) + if (crypto_trng_mutex == NULL) { + crypto_trng_mutex = sl_si91x_crypto_threadsafety_init(crypto_trng_mutex); + } + mutex_result = sl_si91x_crypto_mutex_acquire(crypto_trng_mutex); +#endif + + status = sl_si91x_driver_send_command(RSI_COMMON_REQ_ENCRYPT_CRYPTO, + SI91X_COMMON_CMD_QUEUE, + request, + sizeof(sl_si91x_trng_request_t), + SL_SI91X_WAIT_FOR_RESPONSE(32000), + NULL, + buffer); + if (status != SL_STATUS_OK) { + free(request); + if (*buffer != NULL) + sl_si91x_host_free_buffer(*buffer); +#if defined(SLI_MULTITHREAD_DEVICE_SI91X) + mutex_result = sl_si91x_crypto_mutex_release(crypto_trng_mutex); +#endif + } + VERIFY_STATUS_AND_RETURN(status); + + return status; +} +#endif + sl_status_t sl_si91x_trng_init(sl_si91x_trng_config_t *config, uint32_t *output) { sl_wifi_buffer_t *buffer = NULL; @@ -65,29 +98,11 @@ sl_status_t sl_si91x_trng_init(sl_si91x_trng_config_t *config, uint32_t *output) memcpy(request->trng_key, config->trng_key, TRNG_KEY_SIZE * 4); memcpy(request->msg, config->trng_test_data, config->input_length * 4); -#if defined(SLI_MULTITHREAD_DEVICE_SI91X) - if (crypto_trng_mutex == NULL) { - crypto_trng_mutex = sl_si91x_crypto_threadsafety_init(crypto_trng_mutex); - } - mutex_result = sl_si91x_crypto_mutex_acquire(crypto_trng_mutex); -#endif + status = sli_si91x_trng_send_command(request, &buffer); - status = sl_si91x_driver_send_command(RSI_COMMON_REQ_ENCRYPT_CRYPTO, - SI91X_COMMON_CMD_QUEUE, - request, - sizeof(sl_si91x_trng_request_t), - SL_SI91X_WAIT_FOR_RESPONSE(32000), - NULL, - &buffer); if (status != SL_STATUS_OK) { - free(request); - if (buffer != NULL) - sl_si91x_host_free_buffer(buffer); -#if defined(SLI_MULTITHREAD_DEVICE_SI91X) - mutex_result = sl_si91x_crypto_mutex_release(crypto_trng_mutex); -#endif + return status; } - VERIFY_STATUS_AND_RETURN(status); packet = sl_si91x_host_get_buffer_data(buffer, 0, NULL); memcpy(output, packet->data, packet->length); #endif @@ -172,30 +187,11 @@ sl_status_t sl_si91x_trng_program_key(uint32_t *trng_key, uint16_t key_length) #else memcpy(request->trng_key, trng_key, TRNG_KEY_SIZE * 4); -#if defined(SLI_MULTITHREAD_DEVICE_SI91X) - if (crypto_trng_mutex == NULL) { - crypto_trng_mutex = sl_si91x_crypto_threadsafety_init(crypto_trng_mutex); - } - mutex_result = sl_si91x_crypto_mutex_acquire(crypto_trng_mutex); -#endif + status = sli_si91x_trng_send_command(request, &buffer); - status = sl_si91x_driver_send_command(RSI_COMMON_REQ_ENCRYPT_CRYPTO, - SI91X_COMMON_CMD_QUEUE, - request, - sizeof(sl_si91x_trng_request_t), - SL_SI91X_WAIT_FOR_RESPONSE(32000), - NULL, - &buffer); if (status != SL_STATUS_OK) { - free(request); - if (buffer != NULL) - sl_si91x_host_free_buffer(buffer); -#if defined(SLI_MULTITHREAD_DEVICE_SI91X) - mutex_result = sl_si91x_crypto_mutex_release(crypto_trng_mutex); -#endif + return status; } - VERIFY_STATUS_AND_RETURN(status); - packet = sl_si91x_host_get_buffer_data(buffer, 0, NULL); memcpy(trng_key, packet->data, packet->length); #endif diff --git a/components/device/silabs/si91x/wireless/crypto/wrap/inc/sl_si91x_psa_wrap.h b/components/device/silabs/si91x/wireless/crypto/wrap/inc/sl_si91x_psa_wrap.h index 0dd1d4da0..d43f887ba 100644 --- a/components/device/silabs/si91x/wireless/crypto/wrap/inc/sl_si91x_psa_wrap.h +++ b/components/device/silabs/si91x/wireless/crypto/wrap/inc/sl_si91x_psa_wrap.h @@ -25,6 +25,10 @@ extern unsigned char WRAP_IV[]; #define PSA_KEY_VOLATILE_PERSISTENT_WRAPPED ((psa_key_location_t)0x000001) +// The PSA key is given in wrapped format to psa_import_key and other APIs + +#define PSA_KEY_VOLATILE_PERSISTENT_WRAP_IMPORT ((psa_key_location_t)0x800000) +// The PSA key is given in plain format, to be wrapped in psa_import_key API and used in wrapped format with other APIs /** * @brief diff --git a/components/device/silabs/si91x/wireless/crypto/wrap/src/sl_si91x_psa_wrap.c b/components/device/silabs/si91x/wireless/crypto/wrap/src/sl_si91x_psa_wrap.c index 0b817626f..fc5a0d36e 100644 --- a/components/device/silabs/si91x/wireless/crypto/wrap/src/sl_si91x_psa_wrap.c +++ b/components/device/silabs/si91x/wireless/crypto/wrap/src/sl_si91x_psa_wrap.c @@ -27,26 +27,44 @@ unsigned char WRAP_IV[] = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46 }; -psa_status_t sli_si91x_crypto_wrap_key(uint8_t *key_buffer, - size_t key_buffer_size, - uint32_t wrap_mode, - uint8_t *wrap_iv_var) +static psa_status_t sli_si91x_crypto_get_wrap_config_key_info(uint8_t *key_buffer, + size_t key_buffer_size, + uint32_t wrap_mode, + uint8_t *wrap_iv_var, + sl_si91x_wrap_config_t *wrap_config) { /* Input pointer check */ - if ((key_buffer == NULL) || (key_buffer_size == 0) || (wrap_iv_var == NULL) + if ((key_buffer == NULL) || (key_buffer_size == 0) || (wrap_iv_var == NULL) || (wrap_config == NULL) || ((wrap_mode != SL_SI91X_WRAP_IV_ECB_MODE) && (wrap_mode != SL_SI91X_WRAP_IV_CBC_MODE))) { return PSA_ERROR_INVALID_ARGUMENT; } - psa_status_t status = PSA_SUCCESS; - sl_status_t si91x_status = SL_STATUS_OK; - sl_si91x_wrap_config_t wrap_config = { 0 }; + /* Fill the key info */ /* We are passing plain key to get wrap key */ - wrap_config.key_type = SL_SI91X_TRANSPARENT_KEY; - wrap_config.key_size = key_buffer_size; - wrap_config.wrap_iv_mode = wrap_mode; + wrap_config->key_type = SL_SI91X_TRANSPARENT_KEY; + wrap_config->key_size = key_buffer_size; + wrap_config->wrap_iv_mode = wrap_mode; if (wrap_mode == SL_SI91X_WRAP_IV_CBC_MODE) { - memcpy(wrap_config.wrap_iv, wrap_iv_var, SL_SI91X_IV_SIZE); + memcpy(wrap_config->wrap_iv, wrap_iv_var, SL_SI91X_IV_SIZE); + } + + return PSA_SUCCESS; +} + +psa_status_t sli_si91x_crypto_wrap_key(uint8_t *key_buffer, + size_t key_buffer_size, + uint32_t wrap_mode, + uint8_t *wrap_iv_var) +{ + + psa_status_t status = PSA_SUCCESS; + sl_status_t si91x_status = SL_STATUS_OK; + sl_si91x_wrap_config_t wrap_config = { 0 }; + + status = sli_si91x_crypto_get_wrap_config_key_info(key_buffer, key_buffer_size, wrap_mode, wrap_iv_var, &wrap_config); + + if (status != PSA_SUCCESS) { + return PSA_ERROR_INVALID_ARGUMENT; } memcpy(wrap_config.key_buffer, key_buffer, wrap_config.key_size); @@ -67,23 +85,15 @@ psa_status_t sli_si91x_crypto_generate_symm_key(uint8_t *key_buffer, uint32_t wrap_mode, uint8_t *wrap_iv_var) { - if ((key_buffer == NULL) || (key_buffer_size == 0) || (wrap_iv_var == NULL) - || ((wrap_mode != SL_SI91X_WRAP_IV_ECB_MODE) && (wrap_mode != SL_SI91X_WRAP_IV_CBC_MODE))) { - return PSA_ERROR_INVALID_ARGUMENT; - } psa_status_t status = PSA_SUCCESS; sl_status_t si91x_status = SL_STATUS_OK; sl_si91x_wrap_config_t wrap_config = { 0 }; - /* Fill the key info */ - /* We are passing plain key to get wrap key */ - wrap_config.key_type = SL_SI91X_TRANSPARENT_KEY; - wrap_config.key_size = key_buffer_size; - wrap_config.wrap_iv_mode = wrap_mode; - if (wrap_mode == SL_SI91X_WRAP_IV_CBC_MODE) { - memcpy(wrap_config.wrap_iv, wrap_iv_var, SL_SI91X_IV_SIZE); - } + status = sli_si91x_crypto_get_wrap_config_key_info(key_buffer, key_buffer_size, wrap_mode, wrap_iv_var, &wrap_config); + if (status != PSA_SUCCESS) { + return PSA_ERROR_INVALID_ARGUMENT; + } /* Get Random dwords of desired length */ si91x_status = sl_si91x_trng_get_random_num((uint32_t *)wrap_config.key_buffer, (wrap_config.key_size)); status = convert_si91x_error_code_to_psa_status(si91x_status); diff --git a/components/device/silabs/si91x/wireless/firmware_upgrade/firmware_upgradation.c b/components/device/silabs/si91x/wireless/firmware_upgrade/firmware_upgradation.c index f5544c097..6dac8da4a 100644 --- a/components/device/silabs/si91x/wireless/firmware_upgrade/firmware_upgradation.c +++ b/components/device/silabs/si91x/wireless/firmware_upgrade/firmware_upgradation.c @@ -29,14 +29,16 @@ ******************************************************/ // Macro to check if malloc failed #define VERIFY_MALLOC_AND_RETURN(ptr) \ - { \ + do { \ if (ptr == NULL) { \ return SL_STATUS_ALLOCATION_FAILED; \ } \ - } + } while (0) #define MIN(a, b) ((a) < (b) ? (a) : (b)) +#define IP_VERSION_6 BIT(1) + /****************************************************** * Global Variables ******************************************************/ @@ -54,9 +56,9 @@ extern bool device_initialized; * @return * sl_status_t. See https://docs.silabs.com/gecko-platform/4.1/common/api/group-status for details. ******************************************************************************/ -static sl_status_t sl_si91x_fwup(uint16_t type, uint8_t *content, uint16_t length); +static sl_status_t sl_si91x_fwup(uint16_t type, const uint8_t *content, uint16_t length); -static sl_status_t sl_si91x_fwup(uint16_t type, uint8_t *content, uint16_t length) +static sl_status_t sl_si91x_fwup(uint16_t type, const uint8_t *content, uint16_t length) { sl_status_t status = SL_STATUS_FAIL; sl_si91x_req_fwup_t fwup = { 0 }; @@ -78,7 +80,7 @@ static sl_status_t sl_si91x_fwup(uint16_t type, uint8_t *content, uint16_t lengt SI91X_WLAN_CMD_QUEUE, &fwup, sizeof(sl_si91x_req_fwup_t), - SL_SI91X_WAIT_FOR_COMMAND_SUCCESS, + SL_SI91X_WAIT_FOR_RESPONSE(5000), NULL, NULL); @@ -105,7 +107,7 @@ sl_status_t sl_si91x_fwup_abort() } sl_status_t sl_si91x_http_otaf(uint8_t type, - uint8_t flags, + uint16_t flags, uint8_t *ip_address, uint16_t port, uint8_t *resource, @@ -113,7 +115,7 @@ sl_status_t sl_si91x_http_otaf(uint8_t type, uint8_t *extended_header, uint8_t *user_name, uint8_t *password, - uint8_t *post_data, + const uint8_t *post_data, uint32_t post_data_length) { sl_status_t status = SL_STATUS_FAIL; @@ -121,16 +123,18 @@ sl_status_t sl_si91x_http_otaf(uint8_t type, uint32_t send_size = 0; uint16_t http_length = 0; uint16_t length = 0; - uint8_t https_enable = 0; + uint16_t https_enable = 0; uint8_t packet_identifier = 0; sl_si91x_http_client_request_t *packet_buffer = NULL; - uint16_t offset = 0, rem_length = 0, chunk_size = 0; + uint16_t offset = 0; + uint16_t rem_length = 0; + uint16_t chunk_size = 0; if (!device_initialized) { return SL_STATUS_NOT_INITIALIZED; } - if (flags & SL_IPV6) { + if (flags & IP_VERSION_6) { http_client.ip_version = SL_IPV6_VERSION; } else { http_client.ip_version = SL_IPV4_VERSION; @@ -153,10 +157,23 @@ sl_status_t sl_si91x_http_otaf(uint8_t type, https_enable |= SL_SI91X_TLS_V_1_1; } + if (flags & SL_SI91X_TLS_V_1_2) { + https_enable |= SL_SI91X_TLS_V_1_2; + } + // Set HTTP version 1.1 feature bit if (flags & SL_SI91X_HTTP_V_1_1) { https_enable |= SL_SI91X_HTTP_V_1_1; } + + if (flags & SL_SI91X_HTTPS_CERTIFICATE_INDEX_1) { + https_enable |= SL_SI91X_HTTPS_CERTIFICATE_INDEX_1; + } + + if (flags & SL_SI91X_HTTPS_CERTIFICATE_INDEX_2) { + https_enable |= SL_SI91X_HTTPS_CERTIFICATE_INDEX_2; + } + // Fill https features parameters http_client.https_enable = https_enable; @@ -165,12 +182,12 @@ sl_status_t sl_si91x_http_otaf(uint8_t type, memset(http_client.buffer, 0, sizeof(http_client.buffer)); // Fill username - length = MIN((sizeof(http_client.buffer) - 1), strlen((char *)user_name)); + length = (uint16_t)MIN((sizeof(http_client.buffer) - 1), strlen((char *)user_name)); memcpy(http_client.buffer, user_name, length); http_length += length + 1; // Fill password - length = MIN((sizeof(http_client.buffer) - 1 - http_length), strlen((char *)password)); + length = (uint16_t)MIN((sizeof(http_client.buffer) - 1 - http_length), strlen((char *)password)); memcpy(((http_client.buffer) + http_length), password, length); http_length += length + 1; @@ -180,23 +197,23 @@ sl_status_t sl_si91x_http_otaf(uint8_t type, } // Copy Host name - length = MIN((sizeof(http_client.buffer) - 1 - http_length), strlen((char *)host_name)); + length = (uint16_t)MIN((sizeof(http_client.buffer) - 1 - http_length), strlen((char *)host_name)); memcpy(((http_client.buffer) + http_length), host_name, length); http_length += length + 1; // Copy IP address - length = MIN((sizeof(http_client.buffer) - 1 - http_length), strlen((char *)ip_address)); + length = (uint16_t)MIN((sizeof(http_client.buffer) - 1 - http_length), strlen((char *)ip_address)); memcpy(((http_client.buffer) + http_length), ip_address, length); http_length += length + 1; // Copy URL resource - length = MIN((sizeof(http_client.buffer) - 1 - http_length), strlen((char *)resource)); + length = (uint16_t)MIN((sizeof(http_client.buffer) - 1 - http_length), strlen((char *)resource)); memcpy(((http_client.buffer) + http_length), resource, length); http_length += length + 1; // Copy Extended header if (extended_header != NULL) { - length = MIN((sizeof(http_client.buffer) - 1 - http_length), strlen((char *)extended_header)); + length = (uint16_t)MIN((sizeof(http_client.buffer) - 1 - http_length), strlen((char *)extended_header)); memcpy(((http_client.buffer) + http_length), extended_header, length); http_length += length; } @@ -264,4 +281,4 @@ sl_status_t sl_si91x_http_otaf(uint8_t type, } VERIFY_STATUS_AND_RETURN(status); return status; -} +} \ No newline at end of file diff --git a/components/device/silabs/si91x/wireless/firmware_upgrade/firmware_upgradation.h b/components/device/silabs/si91x/wireless/firmware_upgrade/firmware_upgradation.h index c2cc704b1..ca3e55a88 100644 --- a/components/device/silabs/si91x/wireless/firmware_upgrade/firmware_upgradation.h +++ b/components/device/silabs/si91x/wireless/firmware_upgrade/firmware_upgradation.h @@ -35,47 +35,52 @@ * \ingroup SI91X_FIRMWARE_UPDATE_FUNCTIONS * @{ */ -/***************************************************************************/ /** +/***************************************************************************/ +/** * @brief - * Post the HTTP data for the requested URL to HTTP server.This is a non-blocking API. + * Sends an HTTP request to a specified server URL with optional data and headers, + * and facilitates firmware downloads from the server. This API is non-blocking API. * @param[in] type - * Valid values are: 0 - HTTPGET, 1 - HTTPPOST + * Valid values are: 2 - HTTP_OTAF * @param[in] flags - * Select version and security: -* - * |Flags | Macro | Description | - * |:------|:----------------|:-----------------------------------------------------------------------| - * |BIT(0) | HTTPS_SUPPORT | Set this bit to enable HTTPS_SUPPORT to use HTTPS feature. | - * |BIT(1) | SSL_ENABLE | Set this bit to enable SSL feature. | - * |BIT(2) | SI91X_TLS_V_1_0 | Set this bit to support SSL TLS Version 1.0 if HTTPS is enabled. | - * |BIT(3) | IPV6 | Set this bit to enable IPv6, by default it is configured to IPv4. | - * |BIT(4) | SI91X_TLS_V_1_1 | Set this bit to support SSL_TLS Version 1.1 if HTTPS is enabled. | - * |BIT(5) | HTTP_POST_DATA | Set this bit to enable Http_post large data feature.| - * |BIT(6) | HTTP_V_1_1 | Set this bit to use HTTP version 1.1 | + * Configuration flags. See the table below for details. * @param[in] ip_address * Server IP address. * @param[in] port - * Port number. Default : 80 - HTTP, 443 - HTTPS + * Port number. Default: 80 - HTTP, 443 - HTTPS * @param[in] resource * Requested resource URL in string format. * @param[in] host_name * Host name. * @param[in] extended_header - * Extender header if present, after each header member append \r\c -* + * Extended header if present, each header member should end with \r\n. * @param[in] username * Username for server authentication. * @param[in] password * Password for server authentication. * @param[in] post_data - * HTTP data to be posted to server. + * HTTP data to be posted to the server. * @param[in] post_data_length - * HTTP data length to be posted to server. + * HTTP data length to be posted to the server. * @return * sl_status_t. See https://docs.silabs.com/gecko-platform/4.1/common/api/group-status for details. + * + * @details + * The following table lists the flags that can be used with this function: + * + * | Flags | Macro | Description | + * |:-------|:------------------------------------|:-----------------------------------------------------------------------| + * | BIT(0) | HTTPS_SUPPORT | Set this bit to enable HTTPS_SUPPORT to use HTTPS feature. | + * | BIT(1) | IP_VERSION_6 | Set this bit to enable IPv6. By default, it is configured to IPv4. | + * | BIT(2) | SI91X_TLS_V_1_0 | Set this bit to support SSL TLS Version 1.0 if HTTPS is enabled. | + * | BIT(3) | SI91X_TLS_V_1_2 | Set this bit to support SSL TLS Version 1.2 if HTTPS is enabled. | + * | BIT(4) | SI91X_TLS_V_1_1 | Set this bit to support SSL_TLS Version 1.1 if HTTPS is enabled. | + * | BIT(6) | HTTP_V_1_1 | Set this bit to use HTTP version 1.1 | + * | BIT(9) | SL_SI91X_HTTPS_CERTIFICATE_INDEX_1 | Set this bit to specify index of SSL cert to be used for HTTPS. | + * | BIT(10) | SL_SI91X_HTTPS_CERTIFICATE_INDEX_2 | Set this bit to specify index of SSL cert to be used for HTTPS. ******************************************************************************/ sl_status_t sl_si91x_http_otaf(uint8_t type, - uint8_t flags, + uint16_t flags, uint8_t *ip_address, uint16_t port, uint8_t *resource, @@ -83,7 +88,7 @@ sl_status_t sl_si91x_http_otaf(uint8_t type, uint8_t *extended_header, uint8_t *user_name, uint8_t *password, - uint8_t *post_data, + const uint8_t *post_data, uint32_t post_data_length); /** @} */ diff --git a/components/device/silabs/si91x/wireless/host_mcu/efr32fg25/efx32_ncp_host.c b/components/device/silabs/si91x/wireless/host_mcu/efr32fg25/efx32_ncp_host.c index f79110def..0051d508c 100644 --- a/components/device/silabs/si91x/wireless/host_mcu/efr32fg25/efx32_ncp_host.c +++ b/components/device/silabs/si91x/wireless/host_mcu/efr32fg25/efx32_ncp_host.c @@ -39,7 +39,7 @@ static bool dma_callback(unsigned int channel, unsigned int sequenceNo, void *us unsigned int rx_ldma_channel; unsigned int tx_ldma_channel; -osMutexId_t spi_transfer_mutex = 0; +osMutexId_t spi_transfer_mutex = NULL; static uint32_t dummy_buffer; static uint8_t host_initialized = 0; @@ -141,7 +141,7 @@ sl_status_t sl_si91x_host_init(sl_si91x_host_init_configuration *config) transfer_done_semaphore = osSemaphoreNew(1, 0, NULL); } - if (spi_transfer_mutex == 0) { + if (spi_transfer_mutex == NULL) { spi_transfer_mutex = osMutexNew(NULL); } @@ -150,7 +150,7 @@ sl_status_t sl_si91x_host_init(sl_si91x_host_init_configuration *config) DMADRV_AllocateChannel(&tx_ldma_channel, NULL); // Start reset line low - GPIO_PinModeSet(RESET_PIN.port, RESET_PIN.pin, gpioModePushPull, 0); + GPIO_PinModeSet(RESET_PIN.port, RESET_PIN.pin, gpioModeWiredAnd, 0); // configure packet pending interrupt priority NVIC_SetPriority(GPIO_ODD_IRQn, PACKET_PENDING_INT_PRI); @@ -162,7 +162,12 @@ sl_status_t sl_si91x_host_init(sl_si91x_host_init_configuration *config) GPIO_PinModeSet(SLEEP_CONFIRM_PIN.port, SLEEP_CONFIRM_PIN.pin, gpioModeWiredOrPullDown, 1); GPIO_PinModeSet(WAKE_INDICATOR_PIN.port, WAKE_INDICATOR_PIN.pin, gpioModeWiredOrPullDown, 0); host_initialized = 1; + } else { + if (spi_transfer_mutex == NULL) { + spi_transfer_mutex = osMutexNew(NULL); + } } + return SL_STATUS_OK; } @@ -254,13 +259,12 @@ sl_status_t sl_si91x_host_spi_transfer(const void *tx_buffer, void *rx_buffer, u void sl_si91x_host_hold_in_reset(void) { - GPIO_PinModeSet(RESET_PIN.port, RESET_PIN.pin, gpioModePushPull, 1); GPIO_PinOutClear(RESET_PIN.port, RESET_PIN.pin); } void sl_si91x_host_release_from_reset(void) { - GPIO_PinModeSet(RESET_PIN.port, RESET_PIN.pin, gpioModeWiredOrPullDown, 1); + GPIO_PinOutSet(RESET_PIN.port, RESET_PIN.pin); } void sl_si91x_host_enable_bus_interrupt(void) diff --git a/components/device/silabs/si91x/wireless/host_mcu/efx32/efx32_ncp_host.c b/components/device/silabs/si91x/wireless/host_mcu/efx32/efx32_ncp_host.c index da3ce6bce..a5b200867 100644 --- a/components/device/silabs/si91x/wireless/host_mcu/efx32/efx32_ncp_host.c +++ b/components/device/silabs/si91x/wireless/host_mcu/efx32/efx32_ncp_host.c @@ -36,6 +36,16 @@ #define LDMA_MAX_TRANSFER_LENGTH 4096 #define LDMA_DESCRIPTOR_ARRAY_LENGTH (LDMA_MAX_TRANSFER_LENGTH / 2048) +#ifndef SL_SI91X_NCP_UART_BAUDRATE +// ToDo: This Macro is depricated and should be removed in upcoming releases. +// Keeping this macro functionality intact due to backward compatability. +#if SL_SI91X_UART_HIGH_SPEED_ENABLE == 1 +#define SL_SI91X_NCP_UART_BAUDRATE 921600 +#else +#define SL_SI91X_NCP_UART_BAUDRATE 115200 +#endif +#endif + #ifndef SL_NCP_UART_INTERFACE #include "spidrv.h" @@ -220,7 +230,14 @@ static void efx32_spi_init(void) NVIC_SetPriority(NCP_RX_IRQ, PACKET_PENDING_INT_PRI); GPIOINT_CallbackRegister(SI91X_NCP_INTERRUPT_PIN, gpio_interrupt); GPIO_PinModeSet(SI91X_NCP_INTERRUPT_PORT, SI91X_NCP_INTERRUPT_PIN, gpioModeInputPullFilter, 0); - GPIO_ExtIntConfig(SI91X_NCP_INTERRUPT_PORT, SI91X_NCP_INTERRUPT_PIN, SI91X_NCP_INTERRUPT_PIN, true, false, true); + + // Check if the boot option is set to LOAD_DEFAULT_NWP_FW_ACTIVE_LOW + if (init_config.boot_option == LOAD_DEFAULT_NWP_FW_ACTIVE_LOW) + // Configure the GPIO external interrupt for active low configuration + GPIO_ExtIntConfig(SI91X_NCP_INTERRUPT_PORT, SI91X_NCP_INTERRUPT_PIN, SI91X_NCP_INTERRUPT_PIN, false, true, true); + else + // Configure the GPIO external interrupt for active high configuration + GPIO_ExtIntConfig(SI91X_NCP_INTERRUPT_PORT, SI91X_NCP_INTERRUPT_PIN, SI91X_NCP_INTERRUPT_PIN, true, false, true); return; } @@ -278,8 +295,9 @@ uint32_t sl_si91x_host_get_wake_indicator(void) sl_status_t sl_si91x_host_init(sl_si91x_host_init_configuration *config) { - init_config.rx_irq = config->rx_irq; - init_config.rx_done = config->rx_done; + init_config.rx_irq = config->rx_irq; + init_config.rx_done = config->rx_done; + init_config.boot_option = config->boot_option; // Enable clock (not needed on xG21) CMU_ClockEnable(cmuClock_GPIO, true); @@ -299,7 +317,7 @@ sl_status_t sl_si91x_host_init(sl_si91x_host_init_configuration *config) #endif // Start reset line low - GPIO_PinModeSet(SI91X_NCP_RESET_PORT, SI91X_NCP_RESET_PIN, gpioModePushPull, 0); + GPIO_PinModeSet(SI91X_NCP_RESET_PORT, SI91X_NCP_RESET_PIN, gpioModeWiredAnd, 0); // Configure interrupt, sleep and wake confirmation pins GPIO_PinModeSet(SI91X_NCP_SLEEP_CONFIRM_PORT, SI91X_NCP_SLEEP_CONFIRM_PIN, gpioModeWiredOrPullDown, 1); @@ -319,7 +337,7 @@ sl_status_t sl_si91x_host_deinit(void) void sl_si91x_host_enable_high_speed_bus() { #ifdef SL_NCP_UART_INTERFACE - efx32_ncp_uart_init(921600, false); + efx32_ncp_uart_init(SL_SI91X_NCP_UART_BAUDRATE, false); #else //SPI_USART->CTRL_SET |= USART_CTRL_SMSDELAY | USART_CTRL_SSSEARLY; #endif @@ -445,7 +463,7 @@ void sl_si91x_host_flush_uart_rx(void) void sl_si91x_host_uart_enable_hardware_flow_control(void) { #ifdef SL_NCP_UART_INTERFACE - efx32_ncp_uart_init(921600, true); + efx32_ncp_uart_init(SL_SI91X_NCP_UART_BAUDRATE, true); #endif return; @@ -453,13 +471,12 @@ void sl_si91x_host_uart_enable_hardware_flow_control(void) void sl_si91x_host_hold_in_reset(void) { - GPIO_PinModeSet(SI91X_NCP_RESET_PORT, SI91X_NCP_RESET_PIN, gpioModePushPull, 1); GPIO_PinOutClear(SI91X_NCP_RESET_PORT, SI91X_NCP_RESET_PIN); } void sl_si91x_host_release_from_reset(void) { - GPIO_PinModeSet(SI91X_NCP_RESET_PORT, SI91X_NCP_RESET_PIN, gpioModeWiredOrPullDown, 1); + GPIO_PinOutSet(SI91X_NCP_RESET_PORT, SI91X_NCP_RESET_PIN); } void sl_si91x_host_enable_bus_interrupt(void) diff --git a/components/device/silabs/si91x/wireless/host_mcu/stm32/stm32_ncp_host.c b/components/device/silabs/si91x/wireless/host_mcu/stm32/stm32_ncp_host.c index c50f44c6f..bbaad48f2 100644 --- a/components/device/silabs/si91x/wireless/host_mcu/stm32/stm32_ncp_host.c +++ b/components/device/silabs/si91x/wireless/host_mcu/stm32/stm32_ncp_host.c @@ -69,7 +69,7 @@ static void MX_SPI1_Init(void) hspi1.Init.CLKPolarity = SPI_POLARITY_LOW; hspi1.Init.CLKPhase = SPI_PHASE_1EDGE; hspi1.Init.NSS = SPI_NSS_HARD_OUTPUT; - hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2; + hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8; hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB; hspi1.Init.TIMode = SPI_TIMODE_DISABLE; hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; @@ -223,6 +223,22 @@ sl_status_t sl_si91x_host_spi_transfer(const void *tx_buffer, void *rx_buffer, u void sl_si91x_host_enable_high_speed_bus() { + /* SPI1 parameter configuration*/ + hspi1.Instance = SPI1; + hspi1.Init.Mode = SPI_MODE_MASTER; + hspi1.Init.Direction = SPI_DIRECTION_2LINES; + hspi1.Init.DataSize = SPI_DATASIZE_8BIT; + hspi1.Init.CLKPolarity = SPI_POLARITY_LOW; + hspi1.Init.CLKPhase = SPI_PHASE_1EDGE; + hspi1.Init.NSS = SPI_NSS_HARD_OUTPUT; + hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2; + hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB; + hspi1.Init.TIMode = SPI_TIMODE_DISABLE; + hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; + hspi1.Init.CRCPolynomial = 10; + if (HAL_SPI_Init(&hspi1) != HAL_OK) { + Error_Handler(); + } } void sl_si91x_host_enable_bus_interrupt(void) diff --git a/components/device/silabs/si91x/wireless/inc/mqtt/inc/si91x_mqtt_client_utility.h b/components/device/silabs/si91x/wireless/inc/mqtt/inc/si91x_mqtt_client_utility.h index 3213a926f..b84f0fe64 100644 --- a/components/device/silabs/si91x/wireless/inc/mqtt/inc/si91x_mqtt_client_utility.h +++ b/components/device/silabs/si91x/wireless/inc/mqtt/inc/si91x_mqtt_client_utility.h @@ -25,7 +25,7 @@ * @param client Client address that needs to be stored in context. * @param user_context user_context provided by user while calling API. * @param timeout timeout which determines if API needs to be executed in sync or async mode. - * @param si91x_mqtt_client_context_t** A double pointer to client context.This function allocate memory and initializes members if timeout is greater than 0 else pointer is initialized with null + * @param si91x_mqtt_client_context_t** A double pointer to client context.This function allocates memory and initializes members if timeout is greater than 0 else pointer is initialized with null. * @return return SL_STATUS_OK in case of success or appropriate status. */ sl_status_t sli_si91x_build_mqtt_sdk_context_if_async(sl_mqtt_client_event_t event, @@ -42,3 +42,15 @@ sl_status_t sli_si91x_build_mqtt_sdk_context_if_async(sl_mqtt_client_event_t eve * Note: client would be NULL if this function is called before sl_mqtt_client_init or after sl_mqtt_client_deint */ void sli_si91x_get_mqtt_client(sl_mqtt_client_t **client); + +/** + * Cleans up resources used by the MQTT client. + * + * This function is responsible for releasing any resources allocated to the MQTT client, + * ensuring a clean shutdown of the client instance. It should be called when the MQTT + * client is no longer needed, typically at the end of the application or before a restart + * of the MQTT client. + * + * Note: It is important to call this function to prevent resource leaks. + */ +void sli_mqtt_client_cleanup(); diff --git a/components/device/silabs/si91x/wireless/inc/sl_rsi_utility.h b/components/device/silabs/si91x/wireless/inc/sl_rsi_utility.h index da09d0f9b..bffe43a11 100644 --- a/components/device/silabs/si91x/wireless/inc/sl_rsi_utility.h +++ b/components/device/silabs/si91x/wireless/inc/sl_rsi_utility.h @@ -126,7 +126,7 @@ bool get_card_ready_required(); /*Function used to check void save_max_tx_power(uint8_t max_scan_tx_power, uint8_t max_join_tx_power); /*Function used to set the maximum transmission power*/ sl_wifi_max_tx_power_t get_max_tx_power(); /*Function used to get maximum transmission power*/ -void reset_max_tx_power(); /*Function used to set maximum transmission power to default value(31dBm) */ +void reset_max_tx_power(); /*Function used to set maximum transmission power to default value(31 dBm) */ void save_wifi_current_performance_profile( const sl_wifi_performance_profile_t *profile); /*Function used to set the current performance profile*/ @@ -156,11 +156,11 @@ sl_status_t convert_sl_wifi_to_sl_si91x_encryption( /********************************************************************************************* * @brief - * An utility function computes coex performance profile internally and converts into sl_si91x_power_save_request_t. + * A utility function computes coex performance profile internally and converts into sl_si91x_power_save_request_t. * @param profile - * performance profile which needs to be converted to its equivalent si91x_power_save_request structure. + * Performance profile which needs to be converted to its equivalent si91x_power_save_request structure. * @param power_save_request - * si91x specific structure that holds required configuration for the given performance profile. + * Si91x specific structure that holds required configuration for the given performance profile. * This is optional parameter. * @return coex_profile * Coex power profile @@ -212,7 +212,7 @@ void sl_si91x_get_efuse_data(sl_si91x_efuse_data_t *efuse_data); void sl_si91x_set_efuse_data(const sl_si91x_efuse_data_t *efuse_data); /** - * An utility function to convert dBm value to si91x specific power value + * A utility function to convert dBm value to si91x specific power value * @param wifi_max_tx_power which holds the join power value with dBm as units. * @return si91x power level */ @@ -314,8 +314,8 @@ sl_status_t sl_si91x_host_flush_nodes_from_queue(sl_si91x_queue_type_t queue, sl_si91x_node_free_function_t node_free_function); /* Function used to flush all the pending TX packets from the specified queue */ -sl_status_t sl_si91x_flush_queue_based_on_type(sl_si91x_queue_type_t queue, - sl_si91x_node_free_function_t node_free_function); +sl_status_t sli_si91x_flush_queue_based_on_type(sl_si91x_queue_type_t queue, + sl_si91x_node_free_function_t node_free_function); uint32_t sl_si91x_host_queue_status( sl_si91x_queue_type_t queue); /*Function used to check whether queue is empty or not*/ @@ -365,7 +365,7 @@ uint8_t sli_lmac_crc8_c(uint8_t crc8_din, uint8_t crc8_state, uint8_t end); * @return 6-bit Hash value * */ -uint8_t sli_multicast_mac_hash(uint8_t *mac); +uint8_t sli_multicast_mac_hash(const uint8_t *mac); /*==============================================*/ /** @@ -385,7 +385,7 @@ sl_status_t sl_si91x_boot_instruction(uint8_t type, uint16_t *data); * The @ref sl_si91x_bus_enable_high_speed() should be called only if the SPI clock frequency is more than 25 MHz. * @note * SPI initialization has to be done in low-speed mode only. - * After device SPI is configured this API is been used for high-speed mode (>25 MHz). + * After device SPI is configured, this API is used for high-speed mode (>25 MHz). * In addition to this API, the following API sl_si91x_host_enable_high_speed_bus has to be ported by the user to implement the host clock switch. * @return * sl_status_t. See https://docs.silabs.com/gecko-platform/4.1/common/api/group-status for details. @@ -406,7 +406,7 @@ void sl_si91x_ulp_wakeup_init(void); /*Function used to initialize SPI interface * @param type * It specifies type of credential. * @param cred - * Pointer to store the WiFi credential information of type [sl_wifi_credential_t](../wiseconnect-api-reference-guide-wi-fi/sl-wifi-credential-t) + * Pointer to store the wifi credential information of type [sl_wifi_credential_t](../wiseconnect-api-reference-guide-wi-fi/sl-wifi-credential-t) * @return sl_status_t. See https://docs.silabs.com/gecko-platform/4.1/common/api/group-status for details. */ sl_status_t sl_si91x_host_get_credentials(sl_wifi_credential_id_t id, uint8_t type, sl_wifi_credential_t *cred); @@ -417,4 +417,20 @@ void sli_si91x_update_flash_command_status(bool flag); bool sli_si91x_is_sdk_ok_to_sleep(); +/** +* @addtogroup EXTERNAL_HOST_INTERFACE_FUNCTIONS +* @{ +*/ + +/** + * @brief Checks if the device is initialized. + * + * This function is used to verify if the device has been properly initialized. + * + * @return bool. Returns true if the device is initialized, false otherwise. + */ +bool sl_si91x_is_device_initialized(void); + +/** @} */ + #endif // _SL_RSI_UTILITY_H_ diff --git a/components/device/silabs/si91x/wireless/inc/sl_si91x_constants.h b/components/device/silabs/si91x/wireless/inc/sl_si91x_constants.h index 33bc658ce..adc9280f7 100644 --- a/components/device/silabs/si91x/wireless/inc/sl_si91x_constants.h +++ b/components/device/silabs/si91x/wireless/inc/sl_si91x_constants.h @@ -204,6 +204,11 @@ #define SL_SI91X_SIGNATURE_MAX_SIZE 128 #define SL_SI91X_ECDSA_MSG_MAX_SIZE 1000 +// NWP Configuration defines +#define SL_SI91X_XO_CTUNE_FROM_HOST BIT(0) +#define SL_SI91X_ENABLE_NWP_WDT_FROM_HOST BIT(1) +#define SL_SI91X_DISABLE_NWP_WDT_FROM_HOST BIT(2) + //***************************** Macros for Crypto End **********************************/ typedef struct { @@ -234,17 +239,17 @@ typedef enum { typedef enum { SL_SI91X_RETURN_IMMEDIATELY = 0, - SL_SI91X_WAIT_FOR_EVER = 1, SL_SI91X_WAIT_FOR_RESPONSE_BIT = (1 << 30), + SL_SI91X_WAIT_FOR_EVER = (1 << 31), SL_SI91X_WAIT_FOR_SYNC_SCAN_RESULTS = (SL_SI91X_WAIT_FOR_RESPONSE_BIT | 12000), SL_SI91X_WAIT_FOR_COMMAND_RESPONSE = (SL_SI91X_WAIT_FOR_RESPONSE_BIT | 1000), SL_SI91X_WAIT_FOR_SOCKET_ACCEPT_RESPONSE = (SL_SI91X_WAIT_FOR_RESPONSE_BIT | 5000), #ifdef SLI_SI91X_MCU_INTERFACE - SL_SI91X_WAIT_FOR_COMMAND_SUCCESS = (3000), + SL_SI91X_WAIT_FOR_COMMAND_SUCCESS = 3000, #else - SL_SI91X_WAIT_FOR_COMMAND_SUCCESS = (1000), + SL_SI91X_WAIT_FOR_COMMAND_SUCCESS = 1000, #endif - SL_SI91X_WAIT_FOR_DNS_RESOLUTION = (20000), + SL_SI91X_WAIT_FOR_DNS_RESOLUTION = 20000, } sl_si91x_wait_period_t; #define SL_SI91X_WAIT_FOR(x) (sl_si91x_wait_period_t)(x) @@ -265,11 +270,10 @@ typedef enum { /*====================================================*/ // Constant Defines // SPI Status -#define RSI_SPI_SUCCESS 0x58 -#define RSI_SPI_BUSY 0x54 -#define RSI_SPI_FAIL 0x52 -#define RSI_SUCCESS 0 -//#define RSI_ERROR_SPI_BUSY (-1) +#define RSI_SPI_SUCCESS 0x58 +#define RSI_SPI_BUSY 0x54 +#define RSI_SPI_FAIL 0x52 +#define RSI_SUCCESS 0 #define RSI_ERROR_BUFFER_FULL -3 // module buffer full error code #define RSI_ERROR_IN_SLEEP -4 // module in sleep error code @@ -430,7 +434,8 @@ typedef enum { RSI_COMMON_RSP_GET_RAM_DUMP = 0x92, RSI_COMMON_RSP_ASSERT = 0xE1, RSI_COMMON_RSP_SET_RTC_TIMER = 0xE9, - RSI_COMMON_RSP_GET_RTC_TIMER = 0xF2 + RSI_COMMON_RSP_GET_RTC_TIMER = 0xF2, + RSI_COMMON_RSP_SET_CONFIG = 0xBA #ifdef CONFIGURE_GPIO_FROM_HOST , RSI_COMMON_RSP_GPIO_CONFIG = 0x28 diff --git a/components/device/silabs/si91x/wireless/inc/sl_si91x_driver.h b/components/device/silabs/si91x/wireless/inc/sl_si91x_driver.h index b341b1a07..ad6490795 100644 --- a/components/device/silabs/si91x/wireless/inc/sl_si91x_driver.h +++ b/components/device/silabs/si91x/wireless/inc/sl_si91x_driver.h @@ -241,55 +241,37 @@ sl_status_t sl_si91x_wifi_set_certificate_index(uint8_t certificate_type, uint8_t certificate_index, const uint8_t *buffer, uint32_t certificate_length); - +/** \addtogroup SI91X_DRIVER_FUNCTIONS + * \ingroup SL_SI91X_API + * @{ */ /***************************************************************************/ /** * @brief - * Set the host rtc timer. This is a blocking API. + * Sets the Real Time Clock (RTC) of the module.This is a blocking API. * @param[in] timer - * @ref sl_si91x_module_rtc_time_t Pointer to fill RTC time. - * second --> seconds [0-59] - * minute --> minutes [0-59] - * hour --> hours since midnight [0-23] - * day --> day of the month [1-31] - * month --> months since January [0-11] - * year --> year since 1990. - * Weekday--> Weekday from Sunday to Saturday [1-7]. - * @note Hour is 24-hour format only (valid values are 0 to 23). - * Valid values for Month are 0 to 11 (January to December). + * Pointer to an @ref sl_si91x_module_rtc_time_t structure that contains the RTC time to be set. * @pre Pre-conditions: - * - - * @ref sl_si91x_driver_init() API needs to be called before this API + * - The [sl_wifi_init()](../wiseconnect-api-reference-guide-wi-fi/wifi-common-api#sl-wifi-init) API must be called prior to this API. + * - The @ref SL_SI91X_CUSTOM_FEAT_RTC_FROM_HOST bit must be enabled in the @ref SI91X_CUSTOM_FEATURE_BITMAP during the [sl_wifi_init()](../wiseconnect-api-reference-guide-wi-fi/wifi-common-api#sl-wifi-init) process. * @return * sl_status_t. See https://docs.silabs.com/gecko-platform/4.1/common/api/group-status for details. + * @note + * Ensure that the Real-Time Clock (RTC) timer is configured to enable certificate validation. ******************************************************************************/ -sl_status_t sl_si91x_set_rtc_timer(sl_si91x_module_rtc_time_t *timer); +sl_status_t sl_si91x_set_rtc_timer(const sl_si91x_module_rtc_time_t *timer); /***************************************************************************/ /** * @brief - * Fetch current time from hardware Real Time Clock. This is a blocking API. + * Retrieves the current time from the module's Real Time Clock (RTC).This is a blocking API. * @param[out] response - * @ref sl_si91x_module_rtc_time_t Response of the requested command. - - - * @note Response parameters: - - - * * Pointer to fill RTC time. - * second --> seconds [0-59] - * minute --> minutes [0-59] - * hour --> hours since midnight [0-23] - * day --> day of the month [1-31] - * month --> months since January [0-11] - * year --> year since 1990. - * Weekday--> Weekday from Sunday to Saturday [1-7]. - * @note Hour is 24-hour format only (valid values are 0 to 23). - * Valid values for Month are 0 to 11 (January to December). + * Pointer to an @ref sl_si91x_module_rtc_time_t structure where the RTC's current time will be stored. * @pre Pre-conditions: - * - - * @ref sl_si91x_set_rtc_timer() API needs to be called before this API. - * @ref sl_si91x_driver_init() API needs to be called before this API also. + * - The @ref sl_si91x_set_rtc_timer() API must be called to set the RTC time before attempting to retrieve it. + * - The @ref SL_SI91X_CUSTOM_FEAT_RTC_FROM_HOST bit must be enabled in the @ref SI91X_CUSTOM_FEATURE_BITMAP during the [sl_wifi_init()](../wiseconnect-api-reference-guide-wi-fi/wifi-common-api#sl-wifi-init) process to allow RTC time setting and retrieval from the host. * @return * sl_status_t. See https://docs.silabs.com/gecko-platform/4.1/common/api/group-status for details. ******************************************************************************/ sl_status_t sl_si91x_get_rtc_timer(sl_si91x_module_rtc_time_t *response); +/** @} */ /***************************************************************************/ /** * @brief @@ -319,7 +301,7 @@ sl_status_t sl_si91x_write_calibration_data(const si91x_calibration_data_t *data * @return * sl_status_t. See https://docs.silabs.com/gecko-platform/4.1/common/api/group-status for details. ******************************************************************************/ -sl_status_t sl_si91x_transmit_test_start(sl_si91x_request_tx_test_info_t *tx_test_info); +sl_status_t sl_si91x_transmit_test_start(const sl_si91x_request_tx_test_info_t *tx_test_info); /***************************************************************************/ /** * @brief * Stop the transmit test. This is a blocking API. @@ -446,7 +428,38 @@ sl_status_t sl_si91x_dpd_calibration(const sl_si91x_get_dpd_calib_data_t *dpd_ca * @return * sl_status_t. See https://docs.silabs.com/gecko-platform/4.1/common/api/group-status for details. *******************************************************************************/ -sl_status_t sl_si91x_efuse_read(sl_si91x_efuse_read_t *efuse_read, uint8_t *efuse_read_buf); +sl_status_t sl_si91x_efuse_read(const sl_si91x_efuse_read_t *efuse_read, uint8_t *efuse_read_buf); + +/***************************************************************************/ /** + * @brief + * Enable wireless radio. + * @pre Pre-conditions: + * - + * @ref sl_si91x_driver_init should be called before this API. + * @return + * sl_status_t. See https://docs.silabs.com/gecko-platform/4.1/common/api/group-status for details. + ******************************************************************************/ +sl_status_t sl_si91x_enable_radio(void); + +/***************************************************************************/ /** + * @brief + * Disable wireless radio. + * @pre Pre-conditions: + * - + * @ref sl_si91x_driver_init should be called before this API. + * @return + * sl_status_t. See https://docs.silabs.com/gecko-platform/4.1/common/api/group-status for details. + ******************************************************************************/ +sl_status_t sl_si91x_disable_radio(void); + +/***************************************************************************/ /** + * @brief + * Set specific Wi-Fi listen interval in low-power mode + * @param[in] listen_interval + * Wi-Fi Listen interval. + * @return none + *******************************************************************************/ +void sl_si91x_set_listen_interval(uint32_t listen_interval); /** @} */ @@ -500,28 +513,6 @@ sl_status_t sl_si91x_register_event_handler(sl_net_event_handler_t function); ******************************************************************************/ sl_status_t sl_si91x_default_handler(sl_net_event_t event, sl_wifi_buffer_t *buffer); -/***************************************************************************/ /** - * @brief - * Enable wireless radio. - * @pre Pre-conditions: - * - - * @ref sl_si91x_driver_init should be called before this API. - * @return - * sl_status_t. See https://docs.silabs.com/gecko-platform/4.1/common/api/group-status for details. - ******************************************************************************/ -sl_status_t sl_si91x_enable_radio(void); - -/***************************************************************************/ /** - * @brief - * Disable wireless radio. - * @pre Pre-conditions: - * - - * @ref sl_si91x_driver_init should be called before this API. - * @return - * sl_status_t. See https://docs.silabs.com/gecko-platform/4.1/common/api/group-status for details. - ******************************************************************************/ -sl_status_t sl_si91x_disable_radio(void); - /***************************************************************************/ /** * @brief * Set device power configuration. @@ -537,8 +528,6 @@ sl_status_t sl_si91x_disable_radio(void); ******************************************************************************/ sl_status_t sl_si91x_set_power_mode(sl_si91x_power_mode_t mode, const sl_si91x_power_configuration_t *config); -/** @} */ - /** \addtogroup SI91X_FIRMWARE_UPDATE_FROM_HOST_FUNCTIONS Firmware Update From Host * \ingroup SI91X_FIRMWARE_UPDATE_FUNCTIONS * @{ */ @@ -567,9 +556,14 @@ sl_status_t sl_si91x_fwup_load(uint8_t *content, uint16_t length); /***************************************************************************/ /** * @brief - * This API is used to abort the firmware update process on the SI91x device. This is a blocking API. + * This API is used to abort the firmware update process on the SiWx91x device. This is a blocking API. + * @pre Pre-conditions: + * - + * @ref sl_si91x_fwup_load should be called before this API. * @return * sl_status_t. See https://docs.silabs.com/gecko-platform/4.1/common/api/group-status for details. + * @note Only after successful completion of firmware download using sl_si91x_fwup_load API, the user can call the sl_si91x_fwup_abort API. + * @note Ensure to call this abort API before performing a Soft / Hard reset of the SiWx91x device. if not called before soft/hard reset firmware update process won't be aborted. ******************************************************************************/ sl_status_t sl_si91x_fwup_abort(); /** @} */ @@ -593,9 +587,9 @@ sl_status_t sl_si91x_fwup_abort(); */ sl_status_t sl_si91x_m4_ta_secure_handshake(uint8_t sub_cmd_type, uint8_t input_len, - uint8_t *input_data, + const uint8_t *input_data, uint8_t output_len, - uint8_t *output_data); + const uint8_t *output_data); #endif /***************************************************************************/ /** @@ -657,7 +651,7 @@ sl_status_t sl_si91x_configure_timeout(sl_si91x_timeout_type_t timeout_type, uin * @note * This API should ONLY be called before [sl_wifi_init](../wiseconnect-api-reference-guide-wi-fi/wifi-common-api#sl-wifi-init) and repeated call to this API will overwrite timeout values stored in SDK, will be applied on next call to [sl_wifi_init](../wiseconnect-api-reference-guide-wi-fi/wifi-common-api#sl-wifi-init). *******************************************************************************/ -void sl_si91x_set_timeout(sl_si91x_timeout_t *timeout_config); +void sl_si91x_set_timeout(const sl_si91x_timeout_t *timeout_config); /** @} */ @@ -720,7 +714,7 @@ sl_status_t sl_si91x_ota_firmware_upgradation(sl_ip_address_t server_ip, * @return sl_status_t. Refer to https://docs.silabs.com/gecko-platform/4.1/common/api/group-status for details. ******************************************************************************/ sl_status_t sl_si91x_command_to_write_common_flash(uint32_t write_address, - uint8_t *write_data, + const uint8_t *write_data, uint16_t write_data_length, uint8_t flash_sector_erase_enable); @@ -748,15 +742,6 @@ sl_status_t sl_si91x_command_to_read_common_flash(uint32_t read_address, size_t ******************************************************************************/ sl_si91x_operation_mode_t get_opermode(void); -/***************************************************************************/ /** - * @brief - * Si91X specific set listen interval - * @param[in] listen_interval - * Wi-Fi Listen interval. - * @return none - *******************************************************************************/ -void sl_si91x_set_listen_interval(uint32_t listen_interval); - /***************************************************************************/ /** * @brief * Si91X specific get listen interval @@ -798,7 +783,7 @@ sl_status_t sl_si91x_get_ram_log(uint32_t address, uint32_t length); * @return sl_status_t. See https://docs.silabs.com/gecko-platform/4.1/common/api/group-status for details. *******************************************************************************/ sl_status_t sl_si91x_driver_send_transceiver_data(sl_wifi_transceiver_tx_data_control_t *control, - uint8_t *payload, + const uint8_t *payload, uint16_t payload_len, uint32_t wait_time); @@ -866,3 +851,90 @@ sl_status_t sl_si91x_bl_upgrade_firmware(uint8_t *firmware_image, uint32_t fw_im sl_status_t sl_si91x_set_fast_fw_up(void); /** @} */ + +/** \addtogroup SL_SI91X_TYPES + * @{ */ +/// Firmware version information +typedef struct { + uint8_t chip_id; ///< Chip ID + uint8_t rom_id; ///< ROM ID + uint8_t major; ///< Major version number + uint8_t minor; ///< Minor version number + uint8_t security_version; ///< Security enabled or disabled + uint8_t patch_num; ///< Patch number + uint8_t customer_id; ///< Customer ID + uint16_t build_num; ///< Build number +} sl_si91x_firmware_version_t; + +/// NWP configuration structure +typedef struct { + /* configuration code. The possible values are: + * SL_SI91X_XO_CTUNE_FROM_HOST + * SL_SI91X_ENABLE_NWP_WDT_FROM_HOST + * SL_SI91X_DISABLE_NWP_WDT_FROM_HOST + */ + uint32_t code; + union { + uint8_t config_val; ///< config value as per the code selected above. + // Below structure is used in case of SL_SI91X_ENABLE_NWP_WDT_FROM_HOST + struct { + uint8_t wdt_timer_val; ///< timer values in seconds + uint8_t wdt_enable_in_ps; ///< enable WDT in power save + }; + } values; +} sl_si91x_nwp_configuration_t; + +/** @} */ + +/** \addtogroup SI91X_DRIVER_FUNCTIONS Core + * \ingroup SL_SI91X_API + * @{ */ + +/***************************************************************************/ /** + * @brief + * Get/retrieve the firmware version currently available on the SiWx91x device. This is a blocking API. + * @pre Pre-conditions: + * - + * @ref sl_wifi_init should be called before this API. + * @param[out] version + * @ref sl_si91x_firmware_version_t object that contains the version string. + * @return + * sl_status_t. See https://docs.silabs.com/gecko-platform/4.1/common/api/group-status for details. + ******************************************************************************/ +sl_status_t sl_si91x_get_firmware_version(sl_si91x_firmware_version_t *version); + +/***************************************************************************/ /** + * @brief + * Return the firmware image size from firmware image file, this is a non-blocking API. + * @param[in] buffer + * Buffer pointing to firmware image file. + * @param[out] fw_image_size + * Size of the firmware image passed in the input buffer param. The value returned in this param is valid only if this API returns SL_STATUS_OK(0). + * @return + * sl_status_t. See https://docs.silabs.com/gecko-platform/4.1/common/api/group-status for details. + ******************************************************************************/ +sl_status_t sl_si91x_get_firmware_size(void *buffer, uint32_t *fw_image_size); + +/***************************************************************************/ /** + * @brief + * Set configuration to NWP. The configuration value can be set based on the code element of sl_si91x_nwp_configuration_t structure. + * @pre Pre-conditions: + * - + * @ref sl_wifi_init should be called before this API. + * @param[in] nwp_config + * Configuration as identified by @ref sl_si91x_nwp_configuration_t. + * Possible values for config.code are defined below: + * - For SL_SI91X_XO_CTUNE_FROM_HOST: + * - nwp_config.values.config_val is used to configure NWP's XO Ctune value. + * - For SL_SI91X_ENABLE_NWP_WDT_FROM_HOST: + * - nwp_config.values.wdt_timer_val is used to configure the NWP WDT ISR timer. Currently, the value for this timer is set to 32 seconds. + * - nwp_config.values.wdt_enable_in_ps is used to enable WDT in powersave. + * - For SL_SI91X_DISABLE_NWP_WDT_FROM_HOST: + * - Disables NWP WDT ISR timer. nwp_config.values.config_val is not utilized by the NWP. + * - All other values are NOT SUPPORTED. + * @return + * sl_status_t. See https://docs.silabs.com/gecko-platform/4.1/common/api/group-status for details. + ******************************************************************************/ +sl_status_t sl_si91x_set_nwp_config_request(sl_si91x_nwp_configuration_t nwp_config); + +/** @} */ diff --git a/components/device/silabs/si91x/wireless/inc/sl_si91x_host_interface.h b/components/device/silabs/si91x/wireless/inc/sl_si91x_host_interface.h index d0fa4d0e2..27a851c05 100644 --- a/components/device/silabs/si91x/wireless/inc/sl_si91x_host_interface.h +++ b/components/device/silabs/si91x/wireless/inc/sl_si91x_host_interface.h @@ -43,6 +43,7 @@ typedef void (*sl_si91x_host_rx_done_handler)(void); typedef struct { sl_si91x_host_rx_irq_handler rx_irq; sl_si91x_host_rx_done_handler rx_done; + uint8_t boot_option; } sl_si91x_host_init_configuration; /** @@ -150,4 +151,4 @@ void sl_si91x_host_uart_enable_hardware_flow_control(void); /*Function to enable * @return true * @return false */ -bool sl_si91x_host_is_in_irq_context(void); \ No newline at end of file +bool sl_si91x_host_is_in_irq_context(void); diff --git a/components/device/silabs/si91x/wireless/inc/sl_si91x_protocol_types.h b/components/device/silabs/si91x/wireless/inc/sl_si91x_protocol_types.h index 55dd2ca56..3d9bab334 100644 --- a/components/device/silabs/si91x/wireless/inc/sl_si91x_protocol_types.h +++ b/components/device/silabs/si91x/wireless/inc/sl_si91x_protocol_types.h @@ -233,7 +233,7 @@ typedef struct { // Enable or disable set region from user: 1-take from user configuration,0-Take from Beacons uint8_t set_region_code_from_user_cmd; - // region code(1-US,2-EU,3-JP,4-World Domain,5-KR)*/ + // region code(1-US,2-EU,3-JP,4-World Domain,5-KR) uint8_t region_code; // module type (0- Without on board antenna, 1- With on board antenna) @@ -258,7 +258,7 @@ typedef struct { } sl_si91x_set_region_ap_request_t; // Scan command request structure -// channel: RF channel to scan, 0=All, 1-14 for 2.5GHz channels 1-14 +// channel: RF channel to scan, 0=All, 1-14 for 2.4GHz channels 1-14 typedef struct { uint8_t channel[4]; uint8_t ssid[RSI_SSID_LEN]; @@ -515,22 +515,15 @@ typedef struct { uint8_t content[SL_MAX_FWUP_CHUNK_SIZE]; } sl_si91x_req_fwup_t; -// RTC time from host -typedef struct { - // seconds [0-59] - uint32_t tm_sec; - // minutes [0-59] - uint32_t tm_min; - // hours since midnight [0-23] - uint32_t tm_hour; - // day of the month [1-31] - uint32_t tm_mday; - // months since January [0-11] - uint32_t tm_mon; - // year since 1990 - uint32_t tm_year; - // Weekday from Sunday to Saturday [1-7] - uint32_t tm_wday; +/// Si91x specific module RTC time +typedef struct { + uint32_t tm_sec; ///< Seconds [0-59] + uint32_t tm_min; ///< Minutes [0-59] + uint32_t tm_hour; ///< Hours since midnight [0-23] + uint32_t tm_mday; ///< Day of the month [1-31] + uint32_t tm_mon; ///< Months since January [0-11] + uint32_t tm_year; ///< Years since 1990 + uint32_t tm_wday; ///< Weekday from Sunday to Saturday [1-7] } sl_si91x_module_rtc_time_t; // wireless information @@ -551,8 +544,8 @@ typedef struct { // security type uint8_t sec_type; - // PSK - uint8_t psk[64]; + // PSK for AP mode, PMK for Client mode + uint8_t psk_pmk[64]; // uint8[4], Module IP Address uint8_t ipv4_address[4]; @@ -1135,6 +1128,27 @@ typedef struct { uint8_t ipv6_address[16]; } ip_address[SI91X_DNS_RESPONSE_MAX_ENTRIES]; } sl_si91x_dns_response_t; + +/** + * @brief DNS Server add request structure. + * + * This structure holds the information needed to add DNS servers, supporting both IPv4 and IPv6 addresses. + */ +typedef struct { + uint8_t ip_version[2]; ///< IP version value. The second byte is reserved for future use. + uint8_t dns_mode[2]; ///< DNS mode to use. The second byte is reserved for future use. + + union { + uint8_t primary_dns_ipv4[4]; ///< Primary DNS address in IPv4 format. + uint8_t primary_dns_ipv6[16]; ///< Primary DNS address in IPv6 format. + } sli_ip_address1; ///< Primary DNS address. + + union { + uint8_t secondary_dns_ipv4[4]; ///< Secondary DNS address in IPv4 format. + uint8_t secondary_dns_ipv6[16]; ///< Secondary DNS address in IPv6 format. + } sli_ip_address2; ///< Secondary DNS address. +} sli_dns_server_add_request_t; + // Structure for TCP ACK indication typedef struct { // Socket ID @@ -1166,31 +1180,6 @@ typedef struct { uint8_t read_timeout[2]; } sl_si91x_req_socket_read_t; -typedef struct { - // 2 bytes, the ip version of the ip address , 4 or 6 - uint16_t ip_version; - - // 2 bytes, the socket number associated with this read event - uint16_t socket_id; - - // 4 bytes, length of data received - uint32_t length; - - // 2 bytes, offset of data from start of buffer - uint16_t offset; - - // 2 bytes, port number of the device sending the data to us - uint16_t dest_port; - - union { - // 4 bytes, IPv4 Address of the device sending the data to us - uint8_t ipv4_address[4]; - - // 4 bytes, IPv6 Address of the device sending the data to us - uint8_t ipv6_address[16]; - } dest_ip_addr; -} si91x_rsp_socket_recv_t; - typedef struct { uint32_t tv_sec; /* Seconds */ uint32_t tv_usec; /* Microseconds */ @@ -1698,10 +1687,11 @@ typedef struct { } sl_si91x_efuse_read_t; typedef struct { - uint32_t max_retry_attempts; ///< Maximum number of retries before indicating join failure - uint32_t scan_interval; ///< Scan interval between each retry - uint32_t beacon_missed_count; ///< Number of missed beacons that will trigger rejoin - uint32_t first_time_retry_enable; ///< Retry enable or disable for first time joining + uint32_t max_retry_attempts; ///< Maximum number of retries before indicating join failure. + uint32_t scan_interval; ///< Scan interval between each retry. + uint32_t + beacon_missed_count; ///< Number of missed beacons that will trigger rejoin. Minimum value of beacon_missed_count is 40. + uint32_t first_time_retry_enable; ///< Retry enable or disable for first time joining. } sl_si91x_rejoin_params_t; /** \addtogroup SL_SI91X_TYPES diff --git a/components/device/silabs/si91x/wireless/inc/sl_si91x_types.h b/components/device/silabs/si91x/wireless/inc/sl_si91x_types.h index 979b902f2..225564c15 100644 --- a/components/device/silabs/si91x/wireless/inc/sl_si91x_types.h +++ b/components/device/silabs/si91x/wireless/inc/sl_si91x_types.h @@ -33,13 +33,13 @@ #include "sl_wifi_host_interface.h" #include -/// Flag to indicate that the response status of the command is expected +/// Flag to indicate that the response status of the command is expected. #define SI91X_PACKET_RESPONSE_STATUS (1 << 0) -/// Flag to indicate that the response packet of the command is expected +/// Flag to indicate that the response packet of the command is expected. #define SI91X_PACKET_RESPONSE_PACKET (1 << 1) -/// Flag to indicate that all the packet tx has to be suspended until the corresponding command response is received +/// Flag to indicate that all the packet tx has to be suspended until the corresponding command response is received. #define SI91X_PACKET_GLOBAL_QUEUE_BLOCK (1 << 3) /// Flag to indicate that host would receive the response from firmware in asynchronous manner. @@ -60,7 +60,7 @@ typedef enum { // SI91X command queue types // Note: The values of the command queue type should be // in sync with that of sl_si91x_command_type_t - SI91X_COMMON_CMD_QUEUE = 0, ///< SI91X common Command queue + SI91X_COMMON_CMD_QUEUE = 0, ///< SI91X Common Command queue SI91X_WLAN_CMD_QUEUE = 1, ///< SI91X Wireless LAN Command queue SI91X_NETWORK_CMD_QUEUE = 2, ///< SI91X Network Command queue SI91X_SOCKET_CMD_QUEUE = 3, ///< SI91X Socket Command queue @@ -68,7 +68,7 @@ typedef enum { SI91X_SOCKET_DATA_QUEUE = 5, ///< SI91X Socket Command queue // SI91X response queue types - SI91X_COMMON_RESPONSE_QUEUE = 6, ///< SI91X common Command response queue + SI91X_COMMON_RESPONSE_QUEUE = 6, ///< SI91X Common Command response queue SI91X_WLAN_RESPONSE_QUEUE = 7, ///< SI91X Wireless LAN Command response queue SI91X_NETWORK_RESPONSE_QUEUE = 8, ///< SI91X Network Command response queue SI91X_SOCKET_RESPONSE_QUEUE = 9, ///< SI91X Socket Command response queue @@ -91,12 +91,12 @@ typedef enum { * @{ * */ /// Si91x command types -/// Si91x band mode. +/// Si91x band mode /// @note Only 2.4 GHz currently supported. typedef enum { - SL_SI91X_WIFI_BAND_2_4GHZ = 0, ///< 2.4GHz WiFi band - SL_SI91X_WIFI_BAND_5GHZ = 1, ///< 5GHz WiFi band (not currently supported) - SL_SI91X_WIFI_DUAL_BAND = 2 ///< both 2.4GHz and 5GHZ WiFi band (not currently supported) + SL_SI91X_WIFI_BAND_2_4GHZ = 0, ///< 2.4 GHz WiFi band + SL_SI91X_WIFI_BAND_5GHZ = 1, ///< 5 GHz WiFi band (not currently supported) + SL_SI91X_WIFI_DUAL_BAND = 2 ///< Both 2.4 GHz and 5 GHZ WiFi band (not currently supported) } sl_si91x_band_mode_t; /// Si91x region code. @@ -106,18 +106,19 @@ typedef enum { US, ///< United States EU, ///< European Union JP, ///< Japan - WORLD_DOMAIN, ///< World wide domain + WORLD_DOMAIN, ///< Worldwide domain KR, ///< Korea - SG ///< Singapore (not currently supported) + SG, ///< Singapore (not currently supported) + IGNORE_REGION ///< Do not update region code during initialization } sl_si91x_region_code_t; /// Si91x Timeout types typedef enum { SL_SI91X_AUTHENTICATION_ASSOCIATION_TIMEOUT = 0, ///< Used for setting association and authentication timeout request in millisecs - SL_SI91X_CHANNEL_ACTIVE_SCAN_TIMEOUT, ///< Used for setting dwell time per channel in milli seconds during active scan + SL_SI91X_CHANNEL_ACTIVE_SCAN_TIMEOUT, ///< Used for setting dwell time per channel in milliseconds during active scan SL_SI91X_KEEP_ALIVE_TIMEOUT, ///< Used for setting WLAN keep alive time in seconds - SL_SI91X_CHANNEL_PASSIVE_SCAN_TIMEOUT ///< Used for setting dwell time per channel in milli seconds during passive scan + SL_SI91X_CHANNEL_PASSIVE_SCAN_TIMEOUT ///< Used for setting dwell time per channel in milliseconds during passive scan } sl_si91x_timeout_type_t; /// Si91x Wi-Fi VAP ID @@ -130,17 +131,17 @@ typedef enum { // Note: refer sl_wifi_device.h for complete bit map details /// Si91x boot configuration structure typedef struct { - uint16_t oper_mode; ///< operation mode, one of the values from @ref sl_si91x_operation_mode_t. - uint16_t coex_mode; ///< coex mode, one of the values from @ref sl_si91x_coex_mode_t. - uint32_t feature_bit_map; ///< Feature bit map, @ref SI91X_FEATURE_BITMAP - uint32_t tcp_ip_feature_bit_map; ///< TCP/IP feature bit map, @ref SI91X_TCP_IP_FEATURE_BITMAP - uint32_t custom_feature_bit_map; ///< Custom feature bit map, @ref SI91X_CUSTOM_FEATURE_BITMAP - uint32_t ext_custom_feature_bit_map; ///< Extended custom feature bit map, @ref SI91X_EXTENDED_CUSTOM_FEATURE_BITMAP - uint32_t bt_feature_bit_map; ///< BT featured bit map, @ref SI91X_BT_FEATURE_BITMAP - uint32_t ext_tcp_ip_feature_bit_map; ///< Extended tcp/ip feature bit map, @ref SI91X_EXTENDED_TCP_IP_FEATURE_BITMAP + uint16_t oper_mode; ///< operation mode, one of the values from @ref sl_si91x_operation_mode_t + uint16_t coex_mode; ///< coex mode, one of the values from @ref sl_si91x_coex_mode_t + uint32_t feature_bit_map; ///< Feature bitmap, @ref SI91X_FEATURE_BITMAP + uint32_t tcp_ip_feature_bit_map; ///< TCP/IP feature bitmap, @ref SI91X_TCP_IP_FEATURE_BITMAP + uint32_t custom_feature_bit_map; ///< Custom feature bitmap, @ref SI91X_CUSTOM_FEATURE_BITMAP + uint32_t ext_custom_feature_bit_map; ///< Extended custom feature bitmap, @ref SI91X_EXTENDED_CUSTOM_FEATURE_BITMAP + uint32_t bt_feature_bit_map; ///< BT featured bitmap, @ref SI91X_BT_FEATURE_BITMAP + uint32_t ext_tcp_ip_feature_bit_map; ///< Extended tcp/ip feature bitmap, @ref SI91X_EXTENDED_TCP_IP_FEATURE_BITMAP uint32_t ble_feature_bit_map; ///< BLE feature bitmap, @ref SI91X_BLE_FEATURE_BITMAP - uint32_t ble_ext_feature_bit_map; ///< BLE extended feature bit map, @ref SI91X_EXTENDED_BLE_CUSTOM_FEATURE_BITMAP - uint32_t config_feature_bit_map; ///< Config feature bit map, @ref SI91X_CONFIG_FEATURE_BITMAP + uint32_t ble_ext_feature_bit_map; ///< BLE extended feature bitmap, @ref SI91X_EXTENDED_BLE_CUSTOM_FEATURE_BITMAP + uint32_t config_feature_bit_map; ///< Config feature bitmap, @ref SI91X_CONFIG_FEATURE_BITMAP } sl_si91x_boot_configuration_t; /// Timeout Configuration Structure @@ -150,7 +151,7 @@ typedef struct { uint16_t auth_assoc_timeout_value; ///< Authentication and association timeout value. Default value of 300 millisecs is used when SL_WIFI_DEFAULT_AUTH_ASSOCIATION_TIMEOUT is passed. uint16_t - keep_alive_timeout_value; ///< Keep Alive Timeout value. Default value of 30 secs is used when SL_WIFI_DEFAULT_KEEP_ALIVE_TIMEOUT is passed + keep_alive_timeout_value; ///< Keep Alive Timeout value. Default value of 30 secs is used when SL_WIFI_DEFAULT_KEEP_ALIVE_TIMEOUT is passed. uint16_t passive_scan_timeout_value; ///