diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/Common/fwk_hal_macros.h b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/Common/fwk_hal_macros.h new file mode 100644 index 0000000000..b4766735ca --- /dev/null +++ b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/Common/fwk_hal_macros.h @@ -0,0 +1,215 @@ +/*! ********************************************************************************* + * Copyright 2022-2025 NXP + * SPDX-License-Identifier: BSD-3-Clause + ********************************************************************************** */ +#ifndef _HAL_MACROS_H_ +#define _HAL_MACROS_H_ + +#include + +/* Required for __REV definition */ +#include "cmsis_compiler.h" + +/*============================================================================ + USEFUL MACROS +=============================================================================*/ + +/*! + **************************************************************************************** + * @brief + * HAL_CLZ implementation : count leading zeroes from MSB + * HAL_CTZ implementation : count trailing zeroes from LSB + * HAL_RBIT implementation : bit mirror 32-bit operation:bit n moves to bit (31-n) + * + *****************************************************************************************/ +#if defined(__GNUC__) + +#define HAL_CLZ(x) ((uint8_t)(__builtin_clz(x) & 0x3fUL)) +#define HAL_CTZ(x) ((uint8_t)(__builtin_ctz(x) & 0x3fUL)) +static inline uint32_t __hal_revb(uint32_t x) +{ + unsigned int res; + __asm volatile("rbit %0, %1 \n\t" : "=r"(res) : "r"(x)); + return res; +} +#define HAL_RBIT(x) __hal_revb(x) + +#elif defined(__IAR_SYSTEMS_ICC__) + +#define HAL_CLZ(x) ((uint8_t)(__iar_builtin_CLZ(x) & 0x3fUL)) +#define HAL_RBIT(x) ((uint32_t)(__iar_builtin_RBIT(x))) + +static inline uint8_t __hal_ctz(uint32_t x) +{ + uint8_t res; + x = HAL_RBIT((unsigned int)x); + res = HAL_CLZ((unsigned int)x); + return res; +} + +#define HAL_CTZ(x) __hal_ctz(x) + +#else +#define HAL_CLZ(x) HAL_CLZ_UNDEFINED(x) +#define HAL_CTZ(x) HAL_CTZ_UNDEFINED(x) +#endif + +/*! + **************************************************************************************** + * @brief + * HAL_BSR Bit Scan Reverse ( find MSB bit set in a bit field ) + * HAL_BSF Bit Scan Forward ( find LSB bit set in a bit field ) + * HAL_FFS Find First Bit Set Find LSB bit position + 1 per standard ffs definition + * + **************************************************************************************** + */ +#define HAL_BSR(x) (((x) != 0UL) ? (uint8_t)(31U - (HAL_CLZ(x) & 0x1fU)) : 0xffU) +#define HAL_BSF(x) HAL_CTZ(x) +#define HAL_FFS(x) (HAL_CTZ(x) + 1U) + +/*! + **************************************************************************************** + * @brief + * HAL_REV16 swap bytes in a 16 bit word : useful for htons/ntohs and all endianness conversions + * HAL_REV32 swap bytes in a 32 bit word : useful for htonl/ntohl and all endianness conversions + **************************************************************************************** + */ +#if defined(__GNUC__) +#define HAL_REV16(x) ((uint32_t)__builtin_bswap16(x)) +#define HAL_REV32(x) ((uint32_t)__builtin_bswap32(x)) + +#elif defined(__IAR_SYSTEMS_ICC__) || defined(__CC_ARM) + +#define HAL_REV16(x) ((uint32_t)__REV16(x)) +#define HAL_REV32(x) ((uint32_t)__REV(x)) + +#endif + +#define HAL_HTONS(_x_) HAL_REV16((_x_)) +#define HAL_NTOHS(_x_) HAL_REV16((_x_)) + +#define HAL_HTONL(_x_) HAL_REV32((_x_)) +#define HAL_NTOHL(_x_) HAL_REV32((_x_)) + +#define HAL_BSWAP16(_x_) HAL_REV16((_x_)) +#define HAL_BSWAP32(_x_) HAL_REV32((_x_)) + +/*! + **************************************************************************************** + * @brief + * KB used to define memory sizes expressed in kilobytes + * MB used to define memory sizes expressed in megabytes + **************************************************************************************** + */ +#ifndef KB +#define KB(x) (((uint32_t)x) << 10U) +#endif +#ifndef MB +#define MB(x) (((uint32_t)x) << 20U) +#endif + +/*! + **************************************************************************************** + * @brief + * KHz used to define frequencies in kHz + * MHz used to define frequencies in MHz + **************************************************************************************** + */ +#define KHz(x) (((uint32_t)x) * 1000U) +#define MHz(x) (((uint32_t)x) * 1000000U) + +#define SET_BIT(bitmap, i) bitmap[((i) >> 5U)] |= (1U << ((i)&0x1fU)) +#define CLR_BIT(bitmap, i) bitmap[((i) >> 5U)] &= ~(1U << ((i)&0x1fU)) +#define GET_BIT(bitmap, i) (((bitmap[(i) >> 5U] & (1U << ((i)&0x1fU))) >> ((i)&0x1f)) != 0U) + +/* LOG_1, LOG_2, LOG_4, LOG_8: used by LOG macro */ +#define LOG_1(n) (((n) >= (1u << 1U)) ? 1U : 0U) +#define LOG_2(n) (((n) >= (1u << 2U)) ? (2U + LOG_1((n) >> 2U)) : LOG_1(n)) +#define LOG_4(n) (((n) >= (1u << 4U)) ? (4U + LOG_2((n) >> 4U)) : LOG_2(n)) +#define LOG_8(n) (((n) >= (1u << 8U)) ? (8U + LOG_4((n) >> 8U)) : LOG_4(n)) +/* + * Macro to compute log2 (logarithm) of a constant at compile time. + * Does not make sense for runtime log2 calculation. + * Computation should be based on __builtin_clz. + * For in + * + */ +#define LOG(n) (((n) >= (1U << 16U)) ? (16U + LOG_8((n) >> 16U)) : LOG_8(n)) + +#if !defined(__IAR_SYSTEMS_ICC__) +#undef BUILD_ASSERT /* clear out common version */ +/* C++11 has static_assert built in */ +#if defined(__cplusplus) && (__cplusplus >= 201103L) +#define BUILD_ASSERT(EXPR, MSG...) static_assert(EXPR, "" MSG) + +/* + * GCC 4.6 and higher have the C11 _Static_assert built in and its + * output is easier to understand than the common BUILD_ASSERT macros. + * Don't use this in C++98 mode though (which we can hit, as + * static_assert() is not available) + */ +#elif !defined(__cplusplus) && \ + ((__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || (__STDC_VERSION__) >= 201100) +#define BUILD_ASSERT(EXPR, MSG...) _Static_assert(EXPR, "" MSG) +#else +#define BUILD_ASSERT(EXPR, MSG...) +#endif + +/** + * @brief Validate if two entities have a compatible type + * + * @param a the first entity to be compared + * @param b the second entity to be compared + * @return 1 if the two elements are compatible, 0 if they are not + */ +#define SAME_TYPE(a, b) __builtin_types_compatible_p(__typeof__(a), __typeof__(b)) + +/** + * @brief Validate CONTAINER_OF parameters, only applies to C mode. + */ +#ifndef __cplusplus +#define CONTAINER_OF_VALIDATE(ptr, type, field) \ + BUILD_ASSERT(SAME_TYPE(*(ptr), ((type *)0)->field) || SAME_TYPE(*(ptr), void), \ + "pointer type mismatch in CONTAINER_OF"); +#else /* __cplusplus */ +#define CONTAINER_OF_VALIDATE(ptr, type, field) +#endif /* __cplusplus */ +#else /* __IAR_SYSTEMS_ICC__ */ +/* No CONTAINER_OF_VALIDATE macros for IAR */ +#define CONTAINER_OF_VALIDATE(ptr, type, field) +/* Neither BUILD_ASSERT nor SAME_TYPE defined for IAR */ +#endif /* __IAR_SYSTEMS_ICC__ */ + +#define _DO_CONCAT(x, y) x##y +#define _CONCAT(x, y) _DO_CONCAT(x, y) + +#define DECL_ALIGN(type) __aligned(__alignof(type)) type + +/** + * @brief Get a pointer to a structure containing the element + * + * Example: + * + * struct foo { + * int bar; + * }; + * + * struct foo my_foo; + * int *ptr = &my_foo.bar; + * + * struct foo *container = CONTAINER_OF(ptr, struct foo, bar); + * + * Above, @p container points at @p my_foo. + * + * @param ptr pointer to a structure element + * @param type name of the type that @p ptr is an element of + * @param field the name of the field within the struct @p ptr points to + * @return a pointer to the structure that contains @p ptr + */ +#define CONTAINER_OF(_PTR_, _TYPE_, _FIELD_) \ + ({ \ + CONTAINER_OF_VALIDATE(_PTR_, _TYPE_, _FIELD_) \ + ((_TYPE_ *)(void *)(((char *)(_PTR_)) - offsetof(_TYPE_, _FIELD_))); \ + }) + +#endif diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/LICENSE_BSD-3-Clause.txt b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/LICENSE_BSD-3-Clause.txt new file mode 100644 index 0000000000..a7823b2768 --- /dev/null +++ b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/LICENSE_BSD-3-Clause.txt @@ -0,0 +1,28 @@ +The BSD 3 Clause License + +Copyright 2016-2024 NXP + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation +and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its contributors +may be used to endorse or promote products derived from this software without +specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/SCR.txt b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/SCR.txt new file mode 100644 index 0000000000..417e2fdb64 --- /dev/null +++ b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/SCR.txt @@ -0,0 +1,12 @@ +NXP Software Content Register + +Package: FWK except above packages +Version: 7.0.1 +Outgoing License: BSD-3-Clause +License File: LICENSE_BSD-3-Clause.txt +Type of Content: source code & header files +Description and comments: Connectivity Framework middleware for Connectivity stacks +Release Location: https://github.com/nxp-mcuxpresso/mcux-sdk-middleware-connectivity-framework +URL: None +Origin: + NXP \ No newline at end of file diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/SW-Content-Register.txt b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/SW-Content-Register.txt deleted file mode 100644 index b0d0ba3053..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/SW-Content-Register.txt +++ /dev/null @@ -1,12 +0,0 @@ -Release Name: MCUXpresso Software Development Kit (SDK) Framework Middleware -Release Version: 6.1.0 -Package License: LA_OPT_NXP_Software_License.htm - Additional Distribution License, Section 2.3 applies - -FWK version: 6.1.0 - Location: / - Description: Connectivity Framework middleware for - Connectivity stacks - License: Open Source - BSD-3-Clause - Author: NXP - name: Connectivity Framework - Format: source code and header Files diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/connectivity_framework.cmake b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/connectivity_framework.cmake index b65576ce0f..8c1bc83f29 100644 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/connectivity_framework.cmake +++ b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/connectivity_framework.cmake @@ -37,16 +37,27 @@ endif() if(CONFIG_SOC_SERIES_MCXW) target_sources(${MCUX_SDK_PROJECT_NAME} PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/platform/connected_mcu/fwk_platform.c - ${CMAKE_CURRENT_LIST_DIR}/platform/connected_mcu/fwk_platform_ics.c - ${CMAKE_CURRENT_LIST_DIR}/platform/connected_mcu/fwk_platform_ot.c - ${CMAKE_CURRENT_LIST_DIR}/platform/connected_mcu/fwk_platform_ble.c + ${CMAKE_CURRENT_LIST_DIR}/platform/wireless_mcu/fwk_platform.c + ${CMAKE_CURRENT_LIST_DIR}/platform/wireless_mcu/fwk_platform_ics.c + ${CMAKE_CURRENT_LIST_DIR}/platform/wireless_mcu/fwk_platform_ot.c + ${CMAKE_CURRENT_LIST_DIR}/platform/wireless_mcu/fwk_platform_ble.c + ${CMAKE_CURRENT_LIST_DIR}/services/FunctionLib/FunctionLib.c ) + zephyr_compile_definitions(gUseToolchainMemFunc_d=1) + + if(CONFIG_SOC_MCXW716C) + set(platform "kw45_k32w1_mcxw71") + elseif(CONFIG_SOC_MCXW727C) + set(platform "kw47_mcxw72") + endif() + zephyr_include_directories( ${CMAKE_CURRENT_LIST_DIR}/Common - ${CMAKE_CURRENT_LIST_DIR}/platform/connected_mcu - ${CMAKE_CURRENT_LIST_DIR}/platform/connected_mcu/configs + ${CMAKE_CURRENT_LIST_DIR}/services/FunctionLib + ${CMAKE_CURRENT_LIST_DIR}/platform/wireless_mcu + ${CMAKE_CURRENT_LIST_DIR}/platform/${platform} + ${CMAKE_CURRENT_LIST_DIR}/platform/${platform}/configs ) if(DEFINED CONFIG_SOC_SDKNG_UNSUPPORTED) diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/CMakeLists.txt b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/CMakeLists.txt deleted file mode 100644 index 517248f057..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -# Configure the platform lib -add_subdirectory(${CONNFWK_PLATFORM}) - -if(CONNFWK_PLATFORM_FAMILY) - target_include_directories(connfwk-config INTERFACE - ${CMAKE_CURRENT_SOURCE_DIR}/${CONNFWK_PLATFORM_FAMILY}/${CONNFWK_PLATFORM} - ) - add_subdirectory(${CONNFWK_PLATFORM_FAMILY}) -endif() diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/Common/fwk_platform_mcuboot_ota.ch b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/Common/fwk_platform_mcuboot_ota.ch deleted file mode 100644 index 3b5602ef38..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/Common/fwk_platform_mcuboot_ota.ch +++ /dev/null @@ -1,521 +0,0 @@ -/* - * Copyright 2020 - 2023 NXP - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ -#include "fsl_common.h" -#include "fwk_hal_macros.h" -#include "fwk_platform_ota.h" -#include "fwk_platform_extflash.h" -#include "fwk_config.h" -#include "FunctionLib.h" -#include "fsl_debug_console.h" - -/************************************************************************************ -************************************************************************************* -* Private type definitions and macros -************************************************************************************* -************************************************************************************/ -/*! - * \brief The following symbols give information on the firmware update storage section location - * and size must be provided by the linker. - * FW_UPDATE_STORAGE_OFFSET: Offset address of the firmware update storage - * relative to the start address of the flash - * FW_UPDATE_STORAGE_SIZE: Size of the whole firmware update storage section. - * - */ -extern uint32_t FW_UPDATE_STORAGE_OFFSET[]; -extern uint32_t FW_UPDATE_STORAGE_SIZE[]; -extern uint32_t FW_ACTIVE_APP_OFFSET[]; -extern uint32_t FW_ACTIVE_APP_SIZE[]; - -#define gExtFlash_StartOffset_c ((uint32_t)FW_UPDATE_STORAGE_OFFSET) -#define gExtFlash_TotalSize_c ((uint32_t)FW_UPDATE_STORAGE_SIZE) -#define gExtFlash_SectorSize_c KB(4) - -#define _SECTOR_ADDR(x) (((x) & ~(PLATFORM_EXTFLASH_SECTOR_SIZE - 1U))) -#define _PAGE_ADDR(x) (((x) & ~(PLATFORM_EXTFLASH_PAGE_SIZE - 1U))) -#define _ROUND_TO_UPPER_SECT(x) _SECTOR_ADDR(((x) + (PLATFORM_EXTFLASH_SECTOR_SIZE - 1U))) -#define _ROUND_TO_LOWER_SECT(x) _SECTOR_ADDR((x)) - -/* Stuff related to OTA */ -#define FLASH_CONFIG_OFFSET 0x400U /* The Flash Config is placed in the 1rst sector */ -#define BOOTLOADER_OFFSET 0U /* MCU boot is located at a sector frontier */ -#define BOOTLOADER_SIZE KB(128) /* MCU boot Stated size */ - -/* Start address of the primary application partition (Active App) */ -#define ACTIVE_IMAGE_OFFSET ((uint32_t)FW_ACTIVE_APP_OFFSET) - -/* Image size if rounded to a size multiple of sectors size (4kB) */ -#define IMAGE_SIZE ((uint32_t)FW_ACTIVE_APP_SIZE) - -/* Start address of the secondary application partition (Candidate App) */ -#define CANDIDATE_IMAGE_OFFSET ((uint32_t)FW_UPDATE_STORAGE_OFFSET) - -#define FLASH_AREA_IMAGE_1_OFFSET ACTIVE_IMAGE_OFFSET -#define FLASH_AREA_IMAGE_1_SIZE IMAGE_SIZE -#define FLASH_AREA_IMAGE_2_OFFSET CANDIDATE_IMAGE_OFFSET -#define FLASH_AREA_IMAGE_2_SIZE IMAGE_SIZE /* But slots are equally sized */ - -/* Image Header */ -#define IMAGE_MAGIC 0x96f3b83dU -#define IMAGE_HEADER_SIZE 32 - -/* Image trailer */ -#define BOOT_MAX_ALIGN 8 -#define BOOT_FLAG_SET 1 - -struct image_version -{ - uint8_t iv_major; - uint8_t iv_minor; - uint16_t iv_revision; - uint32_t iv_build_num; -}; - -/** Image header. All fields are in little endian byte order. */ -struct image_header -{ - uint32_t ih_magic; - uint32_t ih_load_addr; - uint16_t ih_hdr_size; /* Size of image header (bytes). */ - uint16_t ih_protect_tlv_size; /* Size of protected TLV area (bytes). */ - uint32_t ih_img_size; /* Does not include header. */ - uint32_t ih_flags; /* IMAGE_F_[...]. */ - struct image_version ih_ver; - uint32_t _pad1; -}; - -#define IMAGE_TLV_INFO_MAGIC 0x6907 -#define IMAGE_TLV_PROT_INFO_MAGIC 0x6908 - -/** Image TLV header. All fields in little endian. */ -struct image_tlv_info -{ - uint16_t it_magic; - uint16_t it_tlv_tot; /* size of TLV area (including tlv_info header) */ -}; - -struct image_trailer -{ - uint8_t swap_type; - uint8_t pad1[BOOT_MAX_ALIGN - 1]; - uint8_t copy_done; - uint8_t pad2[BOOT_MAX_ALIGN - 1]; - uint8_t image_ok; - uint8_t pad3[BOOT_MAX_ALIGN - 1]; - uint8_t magic[16]; -}; - -#define TRAILER1_OFFSET (FLASH_AREA_IMAGE_1_OFFSET + FLASH_AREA_IMAGE_1_SIZE - sizeof(struct image_trailer)) -#define TRAILER2_OFFSET (FLASH_AREA_IMAGE_2_OFFSET + FLASH_AREA_IMAGE_2_SIZE - sizeof(struct image_trailer)) - -/************************************************************************************ - * Private memory declarations - ************************************************************************************/ - -const uint32_t trailer_img_magic[] = { - 0xf395c277, - 0x7fefd260, - 0x0f505235, - 0x8079b62c, -}; - -static const OtaPartition_t ota_partition_cfg = {.start_offset = gExtFlash_StartOffset_c, - .size = gExtFlash_TotalSize_c, - .sector_size = gExtFlash_SectorSize_c, - .page_size = 256u, - .internal_flash = false}; - -/************************************************************************************ -************************************************************************************* -* Private functions -************************************************************************************* -************************************************************************************/ - -static int trailer_img_magic_check(uint8_t *p) -{ - return FLib_MemCmp(p, (uint8_t *)trailer_img_magic, sizeof(trailer_img_magic)); -} - -static int check_unset(uint8_t *p, uint32_t length) -{ - return FLib_MemCmpToVal(p, 0xFFU, length); -} - -static status_t boot_wipe_candidate_trailer(void) -{ - return PLATFORM_EraseExternalFlash(TRAILER2_OFFSET, PLATFORM_EXTFLASH_SECTOR_SIZE); -} - -static status_t boot_swap_test(void) -{ - uint32_t off; - status_t status; - - uint32_t buf[PLATFORM_EXTFLASH_PAGE_SIZE / 4]; /* ensure the buffer is word aligned */ - struct image_trailer *image_trailer_p = - (struct image_trailer *)((uint8_t *)buf + PLATFORM_EXTFLASH_PAGE_SIZE - sizeof(struct image_trailer)); - do - { - off = TRAILER2_OFFSET; - - memset(buf, 0xff, PLATFORM_EXTFLASH_PAGE_SIZE); - memcpy(image_trailer_p->magic, trailer_img_magic, sizeof(trailer_img_magic)); - - PRINTF("write magic number offset = 0x%x\r\n", off); - - status = PLATFORM_EraseExternalFlash(off, sizeof(trailer_img_magic)); - if (status != kStatus_Success) - { - PRINTF("%s: failed to erase trailer2\r\n", __FUNCTION__); - break; - } - - status = PLATFORM_WriteExternalFlash((uint8_t *)buf, PLATFORM_EXTFLASH_PAGE_SIZE, _PAGE_ADDR(off)); - if (status != kStatus_Success) - { - PRINTF("%s: failed to write trailer2\r\n", __FUNCTION__); - break; - } - else - { - PRINTF("%s: Wrote trailer at offset %08x %08x", __FUNCTION__, off, _PAGE_ADDR(off)); - } - } while (false); - return status; -} - -status_t boot_swap_perm(void) -{ - uint32_t off; - status_t status; - - uint32_t buf[PLATFORM_EXTFLASH_PAGE_SIZE / 4]; /* ensure the buffer is word aligned */ - struct image_trailer *image_trailer_p = - (struct image_trailer *)((uint8_t *)buf + PLATFORM_EXTFLASH_PAGE_SIZE - sizeof(struct image_trailer)); - - off = TRAILER2_OFFSET; - - memset(buf, 0xff, PLATFORM_EXTFLASH_PAGE_SIZE); - memcpy(image_trailer_p->magic, trailer_img_magic, sizeof(trailer_img_magic)); - image_trailer_p->image_ok = BOOT_FLAG_SET; - - do - { - status = PLATFORM_EraseExternalFlash(off, sizeof(trailer_img_magic)); - if (status != kStatus_Success) - { - PRINTF("%s: failed to erase trailer2\r\n", __FUNCTION__); - break; - } - - status = PLATFORM_WriteExternalFlash((uint8_t *)buf, PLATFORM_EXTFLASH_PAGE_SIZE, _PAGE_ADDR(off)); - if (status != kStatus_Success) - { - PRINTF("%s: failed to write trailer2\r\n", __FUNCTION__); - break; - } - } while (false); - - return status; -} - -static status_t boot_swap_ok(void) -{ - uint32_t page_off; - status_t status; - - uint32_t buf[PLATFORM_EXTFLASH_PAGE_SIZE / 4]; /* ensure the buffer is word aligned */ - struct image_trailer *image_trailer_p = - (struct image_trailer *)((uint8_t *)buf + PLATFORM_EXTFLASH_PAGE_SIZE - sizeof(struct image_trailer)); - - do - { - page_off = _PAGE_ADDR(TRAILER1_OFFSET); - status = PLATFORM_ReadExternalFlash((uint8_t *)buf, PLATFORM_EXTFLASH_PAGE_SIZE, page_off, false); - if (status != kStatus_Success) - { - PRINTF("%s: failed to read trailer\r\n", __FUNCTION__); - break; - } - - if ((trailer_img_magic_check(image_trailer_p->magic) == 0) || (image_trailer_p->copy_done != 0x01)) - { - /* the image in the slot is likely incomplete (or none) */ - PRINTF("%s: no image awaiting confirmation\r\n", __FUNCTION__); - status = kStatus_Fail; /* No data */ - break; - } - - if (image_trailer_p->image_ok == BOOT_FLAG_SET) - { - /* nothing to be done, report it and return */ - PRINTF("%s: image already confirmed\r\n", __FUNCTION__); - status = kStatus_Success; /* set it explicitly */ - break; - } - - /* mark image ok */ - image_trailer_p->image_ok = BOOT_FLAG_SET; - - /* erase trailer */ - status = PLATFORM_EraseExternalFlash(_SECTOR_ADDR(page_off), PLATFORM_EXTFLASH_SECTOR_SIZE); - if (status != kStatus_Success) - { - PRINTF("%s: failed to erase trailer\r\n", __FUNCTION__); - break; - } - - /* write trailer */ - status = PLATFORM_WriteExternalFlash((uint8_t *)buf, PLATFORM_EXTFLASH_PAGE_SIZE, page_off); - if (status != kStatus_Success) - { - PRINTF("%s: failed to write trailer\r\n", __FUNCTION__); - break; - } - } while (false); - return status; -} - -/*! ********************************************************************************* - * \brief Patch candidate image's trailer to mark it 'ready for test' or 'permanent' - * - * \param[in] img_state: kPlatOtaImg_CandidateRdy or kPlatOtaImg_Permanent are expected - * - * \return kStatus_InvalidArgument is cur_state out of expected set. - * k_Status_Success if flash operations succeed. - *********************************************************************************** */ -int PLATFORM_OtaUpdateImageState(uint8_t img_state) -{ - status_t ret; - - switch (img_state) - { - case kPlatOtaImg_CandidateRdy: - ret = boot_swap_test(); - break; - - case kPlatOtaImg_Permanent: - ret = boot_swap_ok(); - break; - - default: - ret = kStatus_InvalidArgument; - break; - } - - return (int)ret; -} - -/*! ********************************************************************************* - * \brief Read the active and candidate image trailer and determine image state - * checking the contents. - * - * \param[in] p_state: pointer on state enum to pass value deduved from current and - * candidate application trailer contents. - * The value returned in p_state can be one of: - * - kPlatOtaImg_CandidateRdy: if candidate trailer is correct but the remainder unset. - * - kPlatOtaImg_Permanent: if candidate trailer's magic is correct and image marked OK. - * - kPlatOtaImg_RunCandidate: if candidate trailer's magic is unset and active trailer - * is valid, and active trailer's copy done is marked. (revert back) - * - kPlatOtaImg_None in other cases if no error. - * - kPlatOtaImg_Fail if an error occurs while reading the external flash - *. - * - * \return kStatus_Success if flash operations suceed otherwise status of failing operation. - * Disregard *p_state if not kStatus_Success. - *********************************************************************************** */ -int PLATFORM_OtaGetImageState(uint8_t *p_state) -{ - int ret = -1; - - struct image_trailer image_trailer1; - struct image_trailer image_trailer2; - - do - { - PlatOtaImgState_t state; - if (p_state == NULL) - { - ret = kStatus_InvalidArgument; - break; - } - state = (PlatOtaImgState_t)*p_state; - if (state == kPlatOtaImg_None) - { - *p_state = kPlatOtaImg_Fail; - ret = PLATFORM_ReadExternalFlash((uint8_t *)&image_trailer1, sizeof(struct image_trailer), TRAILER1_OFFSET, - false); - if (ret != kStatus_Success) - { - PRINTF("%s: failed to read trailer%d\r\n", __FUNCTION__, 1); - break; - } - - ret = PLATFORM_ReadExternalFlash((uint8_t *)&image_trailer2, sizeof(struct image_trailer), TRAILER2_OFFSET, - false); - if (ret != kStatus_Success) - { - PRINTF("%s: failed to read trailer$d\r\n", __FUNCTION__, 2); - break; - } - - if (trailer_img_magic_check(image_trailer2.magic)) - { - if (check_unset(&image_trailer2.image_ok, sizeof(image_trailer2.image_ok))) - { - /* State I (request for swapping upon next reboot) */ - *p_state = kPlatOtaImg_CandidateRdy; - ret = kStatus_Success; - break; - } - else if (image_trailer2.image_ok == 0x01) - { - /* State II (image marked for permanent change) */ - *p_state = kPlatOtaImg_Permanent; - ret = kStatus_Success; - break; - } - } - else if (check_unset(image_trailer2.magic, sizeof(image_trailer2.magic))) - { - if (trailer_img_magic_check(image_trailer1.magic) && (image_trailer1.image_ok == 0xff) && - (image_trailer1.copy_done == 0x01)) - { - /* State III (revert scheduled for next reboot => image is under test) */ - *p_state = kPlatOtaImg_RunCandidate; - ret = kStatus_Success; - break; - } - } - *p_state = kPlatOtaImg_None; /* State IV default */ - } - ret = kStatus_Success; - } while (false); - - return ret; -} - -/************************************************************************************ -************************************************************************************* -* Public functions -************************************************************************************* -************************************************************************************/ - -int PLATFORM_OtaBootDataUpdateOnCommit(const OtaLoaderInfo_t *ota_loader_info) -{ - uint32_t size = ota_loader_info->image_sz; - return PLATFORM_OtaCheckImageValidity((const uint8_t *)ota_loader_info->image_addr, size); -} - -int PLATFORM_OtaNotifyNewImageReady(const OtaLoaderInfo_t *ota_loader_info) -{ - int st = -1; - NOT_USED(ota_loader_info); - status_t status; - status = PLATFORM_OtaUpdateImageState(kPlatOtaImg_CandidateRdy); - if (status == kStatus_Success) - { - st = 0; - } - return st; -} - -int PLATFORM_OtaClearBootFlags(void) -{ - int st = -1; - if (boot_wipe_candidate_trailer() == kStatus_Success) - { - st = 0; - } - return st; -} - -uint32_t PLATFORM_OtaGetImageOffset(void) -{ - return 0u; -} - -const OtaPartition_t *PLATFORM_OtaGetOtaInternalPartitionConfig(void) -{ - return NULL; -} - -const OtaPartition_t *PLATFORM_OtaGetOtaExternalPartitionConfig(void) -{ - return &ota_partition_cfg; -} - -/*! ********************************************************************************* - * \brief Perform validity checks on candidate image header - * - * \param[in] data: byte pointer on candidate image - * \param[in] size: image size including header. - * - * \return 0 if image is valid , -1 otherwise - * - *********************************************************************************** */ -int PLATFORM_OtaCheckImageValidity(const uint8_t *img_addr, uint32_t size) -{ - struct image_header * ih; - struct image_tlv_info *it; - uint32_t decl_size; - uint32_t tlv_size; - int ret = -1; - uint8_t * data = FLASH_SOC_ADDR(img_addr); - ih = (struct image_header *)data; - do - { - /* do we have at least the header */ - if (size < sizeof(struct image_header)) - { - break; - } - /* check magic number in image header */ - if (ih->ih_magic != IMAGE_MAGIC) - { - break; - } - - /* check that we have at least the amount of data declared by the header */ - decl_size = ih->ih_img_size + ih->ih_hdr_size + ih->ih_protect_tlv_size; - if (size < decl_size) - { - break; - } - /* check protected TLVs if any */ - if (ih->ih_protect_tlv_size > 0) - { - if (ih->ih_protect_tlv_size < sizeof(struct image_tlv_info)) - { - break; - } - it = (struct image_tlv_info *)(data + ih->ih_img_size + ih->ih_hdr_size); - if ((it->it_magic != IMAGE_TLV_PROT_INFO_MAGIC) || (it->it_tlv_tot != ih->ih_protect_tlv_size)) - { - break; - } - } - - /* check for optional TLVs following the image as declared by the header */ - tlv_size = size - decl_size; - if (tlv_size > 0) - { - if (tlv_size < sizeof(struct image_tlv_info)) - { - break; - } - it = (struct image_tlv_info *)(data + decl_size); - if ((it->it_magic != IMAGE_TLV_INFO_MAGIC) || (it->it_tlv_tot != tlv_size)) - { - break; - } - } - - ret = 0; - - } while (false); - return ret; -} diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/Common/fwk_platform_mflash.ch b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/Common/fwk_platform_mflash.ch deleted file mode 100644 index 89bde9d313..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/Common/fwk_platform_mflash.ch +++ /dev/null @@ -1,374 +0,0 @@ -/* - * Copyright 2018-2024 NXP - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#include "fwk_config.h" -#include "fwk_platform_extflash.h" -#include "fsl_os_abstraction.h" -#include "mflash_drv.h" - -/******************************************************************************* - * Macros - ******************************************************************************/ -/* _SECTOR_ADDR returns the address of sector containing address */ -#define _SECTOR_ADDR(addr) (((addr) & ~(PLATFORM_EXTFLASH_SECTOR_SIZE - 1U))) -/* _PAGE_ADDR returns the address of page containing address */ -#define _PAGE_ADDR(addr) (((addr) & ~(PLATFORM_EXTFLASH_PAGE_SIZE - 1U))) - -#if !defined PLATFORM_ACCESS_ALIGNMENT_CONSTRAINT_LOG -#define PLATFORM_ACCESS_ALIGNMENT_CONSTRAINT_LOG 0u -#endif - -#define PLATFORM_ACCESS_UNIT_SZ (1u << PLATFORM_ACCESS_ALIGNMENT_CONSTRAINT_LOG) -#define PLATFORM_ACCESS_UNIT_MSK (PLATFORM_ACCESS_UNIT_SZ - 1u) - -#define _SZ_MULTIPLE_OF_ACCESS_UNIT(sz) (((sz)&PLATFORM_ACCESS_UNIT_MSK) == 0u) -#define _ROUND_UP_MULTIPLE_OF_ACCESS_UNIT(length) ((length + PLATFORM_ACCESS_UNIT_MSK) & ~PLATFORM_ACCESS_UNIT_MSK) - -/* - * EXTFLASH_ALLOW_DIRECT_AHB_ACCESS is defined by default because performing direct AHB read is faster than - * the explicit FlexSPI command method. - * However keeping alternate code undefined because it may turn out useful when using remap feature for instance. - */ -#define EXTFLASH_ALLOW_DIRECT_AHB_ACCESS 1 -/* -------------------------------------------------------------------------- */ -/* Private functions */ -/* -------------------------------------------------------------------------- */ - -static bool MemCmpToEraseValue(uint8_t *ptr, uint32_t blen) -{ - bool ret = true; - uint32_t remaining_blen = blen; - do - { - uint8_t *p_8 = ptr; - uint32_t unaligned_bytes = (uint32_t)ptr % 4; - uint32_t *p_32; - /* Compare byte by byte to 0xff till alignment */ - for (uint32_t i = 0u; i < unaligned_bytes; i++) - { - if (*p_8++ != 0xff) - { - ret = false; - break; /* for */ - } - remaining_blen--; - } - if (!ret) - { - break; /* do .. while */ - } - /* offset_32b is at the word alignment offset in buffer */ - p_32 = (uint32_t *)&p_8[0]; - while (remaining_blen >= sizeof(uint32_t)) - { - /* read word by word to compare to 0xffffffff */ - if (*p_32++ != ~0UL) - { - /* while */ - ret = false; - break; - } - remaining_blen -= sizeof(uint32_t); - } - if (!ret) - { - /* do .. while */ - break; - } - p_8 = (uint8_t *)p_32; - for (uint32_t i = 0u; i < remaining_blen; i++) - { - /* Unaligned trailing bytes */ - if (*p_8 != 0xffu) - { - ret = false; - break; - } - } - } while (false); - return ret; -} - -/******************************************************************************* - * Public functions - ******************************************************************************/ - -int PLATFORM_InitExternalFlash(void) -{ - status_t st = kStatus_Success; - static bool init_done = false; - if (!init_done) - { - st = mflash_drv_init(); - if (st == kStatus_Success) - { - init_done = true; - } - } - return (int)st; -} - -int PLATFORM_EraseExternalFlash(uint32_t address, uint32_t size) -{ - status_t st = kStatus_Success; - uint32_t endAddr = address + size; - uint32_t startBlock, endBlock; - uint32_t index; - if ((endAddr & (PLATFORM_EXTFLASH_SECTOR_SIZE - 1U)) != 0U) - { - /* If the address is in the middle of a block, round up to the next block - * This gives the upper block limit, every blocks before this one will be erased */ - endAddr = ((endAddr / PLATFORM_EXTFLASH_SECTOR_SIZE) + 1U) * PLATFORM_EXTFLASH_SECTOR_SIZE; - } - - startBlock = address / PLATFORM_EXTFLASH_SECTOR_SIZE; - endBlock = endAddr / PLATFORM_EXTFLASH_SECTOR_SIZE; - index = startBlock; - for (index = startBlock; (index < endBlock); index++) - { - uint32_t addr; - - /* The external flash driver is MFLASH, which has no Block Erase API, so limit to sector erase use only. - * This is less optimal and operations take around 15% longer when erasing sectors one by one */ - addr = index * PLATFORM_EXTFLASH_SECTOR_SIZE; - /* No address conversion to physical address */ - st = mflash_drv_sector_erase(addr); - if (st != kStatus_Success) - { - break; - } - } - return (int)st; -} - -/* \brief Read from external flash to RAM buffer - * - * \dest[in/out] pointer of RAM destination to copy flash contents - arbitrary alignment - * \param[in] length number of bytes - arbitrary byte length. - * \param[in] address offset relative to the start of the flash device - not AHB address - * - * \return int return status: 0 for success, otherwise an error was raised. - */ -int PLATFORM_ReadExternalFlash(uint8_t *dest, uint32_t length, uint32_t address, bool requestFastRead) -{ - status_t st; - (void)(requestFastRead); -#ifdef EXTFLASH_ALLOW_DIRECT_AHB_ACCESS - memcpy(dest, (uint8_t *)EXTFLASH_PHYS_ADDR(address), length); - st = 0; -#else - do - { - uint8_t *p_dst; - uint32_t read_sz; - uint8_t page_buf[PLATFORM_EXTFLASH_PAGE_SIZE + 4u]; - if ((uint32_t)dest % sizeof(uint32_t) == 0u) - { - read_sz = length & ~(sizeof(uint32_t) - 1); - p_dst = dest; - st = mflash_drv_read(address, (uint32_t *)p_dst, read_sz); - if (kStatus_Success != st) - { - st = -1; - break; - } - length -= read_sz; - p_dst += read_sz; /* increased by read_sz that is necessarily a multiple of 4 */ - address += read_sz; - if (length > 0u) - { - /* we cannot know whether the caller has left space for extra bytes to allow - * rounding size to next multiple of 4, so copy to page_buf and then memcpy the - * trailing bytes to the destination buffer */ - read_sz = (length + 3u) >> 2u << 2u; - st = mflash_drv_read(address, (uint32_t *)&page_buf[0], read_sz); - if (kStatus_Success != st) - { - st = -1; - break; - } - memcpy(p_dst, &page_buf[0], length); - } - st = 0; - } - else - { - uint32_t remaining_sz = length; - - while (remaining_sz > PLATFORM_EXTFLASH_PAGE_SIZE) - { - read_sz = PLATFORM_EXTFLASH_PAGE_SIZE; - st = mflash_drv_read(address, (uint32_t *)&page_buf[0], read_sz); - if (kStatus_Success != st) - { - st = -1; - break; - } - remaining_sz -= read_sz; - address += read_sz; - memcpy(dest, &page_buf[0], read_sz); - dest += read_sz; - } - if (st < 0) - { - break; - } - if (remaining_sz > 0) - { - read_sz = (remaining_sz + 3u) >> 2u << 2u; - st = mflash_drv_read(address, (uint32_t *)&page_buf[0], read_sz); - if (kStatus_Success != st) - { - st = -1; - break; - } - memcpy(dest, &page_buf[0], remaining_sz); - } - } - st = 0; - } while (false); - -#endif - return (int)st; -} - -/* - * If address is not aligned, previous content may have been written to flash already. - * Copy contents of partial page in RAM, add the new values at right offset in page buffer (256 bytes), then program - * page. From that point on the remainder, if any, is page aligned. if any. - */ -int PLATFORM_WriteExternalFlash(uint8_t *data, uint32_t length, uint32_t address) -{ - status_t status; - - do - { - uint8_t page_buf[PLATFORM_EXTFLASH_PAGE_SIZE]; - uint32_t page_addr; - uint8_t *src; - uint32_t write_len; - uint32_t remaining_sz; - - src = (uint8_t *)data; - - remaining_sz = length; - - page_addr = address & ~(PLATFORM_EXTFLASH_PAGE_SIZE - 1U); - if (page_addr != address) - { - uint32_t write_offset; - /* copy partial contents of page - if any to RAM */ - /* The buffer receiving the contents of flash in RAM has alignment constraints dur to mflash / SPI - programming. page_buf matches this condition */ - status = mflash_drv_read(page_addr, (uint32_t *)page_buf, PLATFORM_EXTFLASH_PAGE_SIZE); - if (kStatus_Success != status) - { - break; - } - write_offset = (address - page_addr); - write_len = PLATFORM_EXTFLASH_PAGE_SIZE - write_offset; - if (write_len > length) - { - write_len = length; - } - memcpy(&page_buf[write_offset], src, write_len); - status = mflash_drv_page_program(page_addr, (uint32_t *)&page_buf[0]); - if (kStatus_Success != status) - { - break; - } - src += write_len; - page_addr += PLATFORM_EXTFLASH_PAGE_SIZE; - remaining_sz -= write_len; - } - /* From now the address in flash is page aligned */ - - while (remaining_sz >= PLATFORM_EXTFLASH_PAGE_SIZE) - { - memcpy(page_buf, src, PLATFORM_EXTFLASH_PAGE_SIZE); - status = mflash_drv_page_program(page_addr, (uint32_t *)&page_buf[0]); - if (status != kStatus_Success) - { - break; - } - remaining_sz -= PLATFORM_EXTFLASH_PAGE_SIZE; - src += PLATFORM_EXTFLASH_PAGE_SIZE; - page_addr += PLATFORM_EXTFLASH_PAGE_SIZE; - } - /* If a partial page has to be written, pad remainder with 0xff */ - if (remaining_sz > 0u) - { - /* partial page left*/ - memcpy(page_buf, src, remaining_sz); - memset(&page_buf[remaining_sz], 0xffu, PLATFORM_EXTFLASH_PAGE_SIZE - remaining_sz); - status = mflash_drv_page_program(page_addr, (uint32_t *)page_buf); - if (status != kStatus_Success) - { - break; - } - } - status = kStatus_Success; - } while (0 != 0); - - return (int)status; -} - -int PLATFORM_IsExternalFlashBusy(bool *isBusy) -{ - uint32_t dummy; - status_t st; - st = mflash_drv_read(0U, (void *)&dummy, sizeof(uint32_t)); - *isBusy = (kStatus_Busy == st) ? 1U : 0U; - return (int)st; -} - -bool PLATFORM_ExternalFlashAreaIsBlank(uint32_t address, uint32_t len) -{ -#ifdef EXTFLASH_ALLOW_DIRECT_AHB_ACCESS - /* - * Direct access to flash contents requires conversion from offset in flash to AHB address. - */ - return MemCmpToEraseValue((uint8_t *)EXTFLASH_PHYS_ADDR(address), len); -#else - bool ret = false; - uint8_t page_buf[PLATFORM_EXTFLASH_PAGE_SIZE]; - uint32_t remaining_len = len; - while (remaining_len > 0u) - { - uint32_t read_sz = MIN(PLATFORM_EXTFLASH_PAGE_SIZE, remaining_len); - if (0 == PLATFORM_ReadExternalFlash(&page_buf[0], read_sz, address, true)) - { - if (!MemCmpToEraseValue(&page_buf[0], read_sz)) - { - break; - } - } - else - { - assert(0); - break; - } - remaining_len -= read_sz; - } - ret = (remaining_len == 0u); - return ret; -#endif -} - -bool PLATFORM_IsExternalFlashPageBlank(uint32_t address) -{ - /* Start from address of page containing argument address */ - uint32_t page_addr = _PAGE_ADDR(address); - return PLATFORM_ExternalFlashAreaIsBlank(page_addr, PLATFORM_EXTFLASH_PAGE_SIZE); -} - -bool PLATFORM_IsExternalFlashSectorBlank(uint32_t address) -{ - /* Start from address of sector containing argument address */ - uint32_t sect_addr = _SECTOR_ADDR(address); - return PLATFORM_ExternalFlashAreaIsBlank(sect_addr, PLATFORM_EXTFLASH_SECTOR_SIZE); -} \ No newline at end of file diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/MIMXRT595S/fwk_platform.c b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/MIMXRT595S/fwk_platform.c deleted file mode 100644 index 5e718591b4..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/MIMXRT595S/fwk_platform.c +++ /dev/null @@ -1,79 +0,0 @@ -/* -------------------------------------------------------------------------- */ -/* Copyright 2023 NXP */ -/* All rights reserved. */ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* -------------------------------------------------------------------------- */ - -/* -------------------------------------------------------------------------- */ -/* Includes */ -/* -------------------------------------------------------------------------- */ - -#include - -#include "fwk_platform.h" -#include "fsl_adapter_time_stamp.h" - -/* -------------------------------------------------------------------------- */ -/* Private memory */ -/* -------------------------------------------------------------------------- */ - -static TIME_STAMP_HANDLE_DEFINE(timestampHandle); -static bool timestampInitialized = false; - -/* -------------------------------------------------------------------------- */ -/* Public functions */ -/* -------------------------------------------------------------------------- */ - -void PLATFORM_InitTimeStamp(void) -{ - hal_time_stamp_config_t config; - - if (timestampInitialized == false) - { - /* Set 32k_clk for ostimer_clk. */ - CLOCK_EnableOsc32K(true); - CLOCK_EnableClock(kCLOCK_Rtc); - CLOCK_AttachClk(PLATFORM_OSTIMER_CLK); - - config.instance = 0; - /* Refer to Clock Tree. */ - config.srcClock_Hz = CLOCK_GetOsc32KFreq(); - config.clockSrcSelect = 1; - - HAL_TimeStampInit(timestampHandle, &config); - - timestampInitialized = true; - } -} - -uint64_t PLATFORM_GetTimeStamp(void) -{ - return HAL_GetTimeStamp(timestampHandle); -} - -uint64_t PLATFORM_GetMaxTimeStamp(void) -{ - /* The timestamp module always converts the timer counter to microsec - * as the OSTIMER is a 64bits timer, the conversion can overflow after a certain counter value - * So the timestamp module discards the 20 MSB to avoid this, so the max value of the counter is - * 0xFFFFFFFFFFFU */ - return (uint64_t)COUNT_TO_USEC(0xFFFFFFFFFFFU, PLATFORM_OSTIMER_CLK); -} - -void PLATFORM_TimeStampEnterLowPower(void) -{ - if (timestampInitialized == true) - { - HAL_TimeStampEnterLowpower(timestampHandle); - CLOCK_AttachClk(kNONE_to_OSTIMER_CLK); - } -} - -void PLATFORM_TimeStampExitPowerDown(void) -{ - if (timestampInitialized == true) - { - CLOCK_AttachClk(PLATFORM_OSTIMER_CLK); - HAL_TimeStampExitLowpower(timestampHandle); - } -} diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/MIMXRT595S/fwk_platform.h b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/MIMXRT595S/fwk_platform.h deleted file mode 100644 index 0f095ee403..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/MIMXRT595S/fwk_platform.h +++ /dev/null @@ -1,59 +0,0 @@ -/* -------------------------------------------------------------------------- */ -/* Copyright 2023 NXP */ -/* All rights reserved. */ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* -------------------------------------------------------------------------- */ - -#ifndef _FWK_PLATFORM_H_ -#define _FWK_PLATFORM_H_ - -/* -------------------------------------------------------------------------- */ -/* Includes */ -/* -------------------------------------------------------------------------- */ - -#include - -/* -------------------------------------------------------------------------- */ -/* Public macros */ -/* -------------------------------------------------------------------------- */ - -#define PLATFORM_OSTIMER_CLK kOSC32K_to_OSTIMER_CLK - -/* -------------------------------------------------------------------------- */ -/* Public prototypes */ -/* -------------------------------------------------------------------------- */ - -/*! - * \brief Initializes timestamp module - * - */ -void PLATFORM_InitTimeStamp(void); - -/*! - * \brief Returns current timestamp in us - * - * \return uint64_t timestamp in us - */ -uint64_t PLATFORM_GetTimeStamp(void); - -/*! - * \brief Returns the max timestamp value that can be returned by PLATFORM_GetTimeStamp - * Can be used by the user to handle timestamp wrapping - * - * \return uint64_t the max timestamp value - */ -uint64_t PLATFORM_GetMaxTimeStamp(void); - -/*! - * \brief Save timestamp module before entering power down - * - */ -void PLATFORM_TimeStampEnterLowPower(void); - -/*! - * \brief Restore timestamp module after exit from power down - * - */ -void PLATFORM_TimeStampExitPowerDown(void); - -#endif /* _FWK_PLATFORM_H_ */ diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/MIMXRT595S/fwk_platform_lowpower.c b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/MIMXRT595S/fwk_platform_lowpower.c deleted file mode 100644 index da3ff4f89e..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/MIMXRT595S/fwk_platform_lowpower.c +++ /dev/null @@ -1,322 +0,0 @@ -/* -------------------------------------------------------------------------- */ -/* Copyright 2023 NXP */ -/* All rights reserved. */ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* -------------------------------------------------------------------------- */ - -/* -------------------------------------------------------------------------- */ -/* Includes */ -/* -------------------------------------------------------------------------- */ - -#include "fwk_platform.h" -#include "fwk_platform_lowpower.h" - -/* SDK components */ -#include "fsl_pm_core.h" -#include "fsl_pm_device.h" -#include "fsl_power.h" -#include "fsl_debug_console.h" -#include "fsl_usart.h" -#include "fsl_rtc.h" -#include "board.h" -#include "fsl_os_abstraction.h" -#include "pmic_support.h" -#include "controller_low_power.h" - -/* -------------------------------------------------------------------------- */ -/* Private macros */ -/* -------------------------------------------------------------------------- */ -static USART_Type *const s_HciUsartBase[] = USART_BASE_PTRS; -/* -------------------------------------------------------------------------- */ -/* Private prototypes */ -/* -------------------------------------------------------------------------- */ - -/*! - * \brief Initialize RTC to be used as a wake up source - * - */ -static void PLATFORM_InitRtc(void); - -/*! - * \brief Initialize Pmic - * - */ -static void PLATFORM_InitPmic(void); -static void PLATFORM_ConfigPMICMode(pca9420_modecfg_t *cfg); - -/*! - * \brief Initializes wake up sources - * - */ -static void PLATFORM_InitWakeUpSources(void); - -/*! - * \brief Callback registered to SDK Power Manager to get notified of entry/exit of low power modes - * - * \param[in] eventType event specifying if we entered or exited from low power mode - * \param[in] powerState low power mode used during low power period - * \param[in] data Optional data passed when the callback got registered (not used currently) - * \return status_t - */ -static status_t PLATFORM_LowPowerCallback(pm_event_type_t eventType, uint8_t powerState, void *data); - -void RTC_IRQHandler(void); -/* -------------------------------------------------------------------------- */ -/* Private variables */ -/* -------------------------------------------------------------------------- */ - -static pm_notify_element_t platformLpNotifyGroup = { - .notifyCallback = PLATFORM_LowPowerCallback, - .data = NULL, -}; - -static pm_wakeup_source_t C2HWakeupSource; -static pm_wakeup_source_t timerWakeupSource; - -static uint16_t wakeUpTimerStartCount = 0U; -static uint16_t wakeUpTimerStopCount = 0U; - -/* -------------------------------------------------------------------------- */ -/* Public functions */ -/* -------------------------------------------------------------------------- */ - -void PLATFORM_LowPowerInit(void) -{ - status_t status; - - POWER_ClearEventFlags(POWER_GetEventFlags()); - - /* Init Pmic */ - PLATFORM_InitPmic(); - - /* Register the low power Notify callback as high priority. */ - status = PM_RegisterNotify(kPM_NotifyGroup2, &platformLpNotifyGroup); - assert(status == kStatus_Success); - (void)status; - - /* Init mandatory wake up sources such as BLE wake up. */ - PLATFORM_InitWakeUpSources(); -} - -void PLATFORM_InitWakeUpTimer(void) -{ - /* Init RTC to be used as wake up source. */ - PLATFORM_InitRtc(); - - /* Init timestamp module to measure low power duration. */ - PLATFORM_InitTimeStamp(); -} - -uint8_t PLATFORM_ControllerLowPowerInit(void) -{ - return controller_low_power_init(); -} - -void PLATFORM_StartWakeUpTimer(uint64_t timeOutUs) -{ - RTC_EnableTimer(RTC, false); - /* clockFreqInHz shoule be equal to configTICK_RATE_HZ. */ - wakeUpTimerStartCount = (uint16_t)USEC_TO_COUNT(timeOutUs, 1000U); - RTC_SetWakeupCount(RTC, wakeUpTimerStartCount); - RTC_EnableWakeupTimer(RTC, true); - RTC_EnableTimer(RTC, true); -} - -void PLATFORM_StopWakeUpTimer(void) -{ - do - { - wakeUpTimerStopCount = RTC_GetWakeupCount(RTC); - } while (wakeUpTimerStopCount > wakeUpTimerStartCount); - - RTC_ClearStatusFlags(RTC, RTC_GetStatusFlags(RTC)); - /* Clear all FLAGS. */ - POWER_ClearEventFlags(POWER_GetEventFlags()); - NVIC_ClearPendingIRQ(RTC_IRQn); - RTC_EnableWakeupTimer(RTC, false); - RTC_EnableTimer(RTC, false); -} - -uint64_t PLATFORM_GetLowPowerTimestampUs(void) -{ - return PLATFORM_GetTimeStamp(); -} - -uint64_t PLATFORM_GetLowPowerDurationUs(uint64_t enterLowPowerTimestamp, uint64_t exitLowPowerTimestamp) -{ - uint64_t durationUs; - - if (exitLowPowerTimestamp < enterLowPowerTimestamp) - { - durationUs = PLATFORM_GetMaxTimeStamp() - enterLowPowerTimestamp + exitLowPowerTimestamp; - } - else - { - durationUs = exitLowPowerTimestamp - enterLowPowerTimestamp; - } - - return durationUs; -} - -void PLATFORM_EnterLowPower(void) -{ - /* If do not disable BT UART, host RTS will stay low even when enters low power mode. - * There might be a risk that controller will send data to host even when host is not totally waken up. */ - s_HciUsartBase[BOARD_BT_UART_INSTANCE]->CFG &= ~((uint32_t)USART_CFG_ENABLE_MASK); - controller_enter_low_power(); -} - -void PLATFORM_ExitLowPower(void) -{ - controller_exit_low_power(); - for (uint32_t i = 0; i < 2000; i++) - { - __NOP(); - } - s_HciUsartBase[BOARD_BT_UART_INSTANCE]->CFG |= ((uint32_t)USART_CFG_ENABLE_MASK); -} - -void PLATFORM_EnterDeepSleep(void) -{ -} - -void PLATFORM_ExitDeepSleep(void) -{ -} - -void PLATFORM_EnterPowerDown(void) -{ -} - -void PLATFORM_ExitPowerDown(void) -{ - /* Note that this code is never reached, - * because device re-boot according to power driver. */ -} - -void PLATFORM_EnterDeepPowerDown(void) -{ - /* Note that this code is never reached, - * because device re-boot according to power driver. */ -} - -uint32_t PLATFORM_GetDefaultRamBanksRetained(void) -{ - /* Retain everything by default. */ - uint8_t bank_mask = 0xFFU; - return bank_mask; -} - -void PLATFORM_SetRamBanksRetained(uint32_t bank_mask) -{ -} - -uint8_t PLATFORM_AllowEnterLowPower(void) -{ - return controller_power_state(); -} - -void RTC_IRQHandler(void) -{ - RTC_ClearStatusFlags(RTC, RTC_GetStatusFlags(RTC)); - SDK_ISR_EXIT_BARRIER; -} -/* -------------------------------------------------------------------------- */ -/* Private functions */ -/* -------------------------------------------------------------------------- */ - -static void PLATFORM_InitWakeUpSources(void) -{ - /* Enable wake up source from BLE controller to wake up the device. */ - PM_InitWakeupSource(&C2HWakeupSource, (uint32_t)GPIO_INTA_IRQn, NULL, true); -} - -static void PLATFORM_InitRtc(void) -{ - RTC_Init(RTC); - RTC_EnableTimer(RTC, false); - EnableIRQ(RTC_IRQn); - RTC_EnableWakeUpTimerInterruptFromDPD(RTC, true); - NVIC_ClearPendingIRQ(RTC_IRQn); - - /* Enable RTC as wakeup source. */ - PM_InitWakeupSource(&timerWakeupSource, (uint32_t)RTC_IRQn, NULL, true); -} - -static void PLATFORM_InitPmic(void) -{ - /* PMIC PCA9420 */ - pca9420_modecfg_t pca9420ModeCfg[4]; - uint32_t i; - - /* BE CAUTIOUS TO SET CORRECT VOLTAGE RANGE ACCORDING TO YOUR BOARD/APPLICATION. PAD SUPPLY BEYOND THE RANGE DO - HARM TO THE SILICON. */ - power_pad_vrange_t vrange = {.Vdde0Range = kPadVol_171_198, - .Vdde1Range = kPadVol_171_198, - .Vdde2Range = kPadVol_171_198, - .Vdde3Range = kPadVol_300_360, - .Vdde4Range = kPadVol_171_198}; - - /* Initialize the PMIC. */ - BOARD_InitPmic(); - - /* Indicate to power library that an external PMIC is used. */ - POWER_UpdatePmicRecoveryTime(1); - - /* Set PMIC configurations. */ - for (i = 0; i < ARRAY_SIZE(pca9420ModeCfg); i++) - { - PCA9420_GetDefaultModeConfig(&pca9420ModeCfg[i]); - } - PLATFORM_ConfigPMICMode(pca9420ModeCfg); - - /* Send new configuration to PMIC. */ - PCA9420_WriteModeConfigs(&pca9420Handle, kPCA9420_Mode0, &pca9420ModeCfg[0], ARRAY_SIZE(pca9420ModeCfg)); - - /* Configure PMIC Vddcore value according to CM33 clock. */ - BOARD_SetPmicVoltageForFreq(CLOCK_GetFreq(kCLOCK_CoreSysClk), 0U); - - /* Configure pads voltage ranges according to PMIC settings. */ - POWER_SetPadVolRange(&vrange); - - RESET_SetPeripheralReset(kFC15_RST_SHIFT_RSTn); - CLOCK_AttachClk(kNONE_to_FLEXCOMM15); -} - -static void PLATFORM_ConfigPMICMode(pca9420_modecfg_t *cfg) -{ - assert(cfg); - - /* Configuration PMIC mode to align with power lib like below: - * 0b00 active mode vddcore 0.9V - * 0b01 deep sleep mode vddcore 0.6V - * 0b10 deep powerdown mode vddcore power off - * 0b11 full deep powerdown mode power off */ - - /* Mode 0: VDDCORE 0.9V. */ - cfg[0].sw1OutVolt = kPCA9420_Sw1OutVolt0V900; - /* Mode 1: VDDCORE 0.6V. */ - cfg[1].sw1OutVolt = kPCA9420_Sw1OutVolt0V600; - /* Mode 2: VDDCORE off. */ - cfg[2].enableSw1Out = false; - /* Mode 3: VDDCORE, VDD1V8 and VDDIO off. */ - cfg[3].enableSw1Out = false; - cfg[3].enableSw2Out = false; - cfg[3].enableLdo2Out = false; -} - -static status_t PLATFORM_LowPowerCallback(pm_event_type_t eventType, uint8_t powerState, void *data) -{ - (void)data; - - if (eventType == kPM_EventEnteringSleep) - { - PLATFORM_EnterLowPower(); - } - else - { - PLATFORM_ExitLowPower(); - } - - return kStatus_Success; -} diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/MIMXRT595S/fwk_platform_lowpower.h b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/MIMXRT595S/fwk_platform_lowpower.h deleted file mode 100644 index f8f81c66bc..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/MIMXRT595S/fwk_platform_lowpower.h +++ /dev/null @@ -1,198 +0,0 @@ -/* -------------------------------------------------------------------------- */ -/* Copyright 2023 NXP */ -/* All rights reserved. */ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* -------------------------------------------------------------------------- */ - -#ifndef _FWK_PLATFORM_LOWPOWER_H_ -#define _FWK_PLATFORM_LOWPOWER_H_ - -/*! - * @addtogroup FWK_Platform_module - * @{ - */ -/*! - * @addtogroup FWK_Platform_LowPower - * The FWK_Platform_LowPower module - * - * FWK_Platform_LowPower module provides APIs to handle Low Power . - * @{ - */ -/* -------------------------------------------------------------------------- */ -/* Includes */ -/* -------------------------------------------------------------------------- */ - -#include -#include "fsl_pm_device.h" - -/* -------------------------------------------------------------------------- */ -/* Public macros */ -/* -------------------------------------------------------------------------- */ - -#define PLATFORM_WFI_STATE PM_LP_STATE_SLEEP -#define PLATFORM_SLEEP_STATE PM_LP_STATE_SLEEP -#define PLATFORM_DEEP_SLEEP_STATE PM_LP_STATE_DEEP_SLEEP -#define PLATFORM_POWER_DOWN_STATE PM_LP_STATE_DEEP_POWER_DOWN -#define PLATFORM_DEEP_POWER_DOWN_STATE PM_LP_STATE_FULL_DEEP_POWER_DOWN - -/* No constraints in WFI mode, all peripherals are available */ -#define PLATFORM_WFI_CONSTRAINTS \ - 17U, PM_RESC_MAIN_CLK_ON, PM_RESC_SYSXTAL_ON, PM_RESC_SYSPLLLDO_ON, PM_RESC_SYSPLLANA_ON, \ - PM_RESC_FLEXSPI0_SRAM_ACTIVE, PM_RESC_SRAM12_128KB_ACTIVE, PM_RESC_SRAM13_128KB_ACTIVE, \ - PM_RESC_SRAM14_128KB_ACTIVE, PM_RESC_SRAM15_128KB_ACTIVE, PM_RESC_SRAM16_256KB_ACTIVE, \ - PM_RESC_SRAM17_256KB_ACTIVE, PM_RESC_SRAM18_256KB_ACTIVE, PM_RESC_SRAM19_256KB_ACTIVE, \ - PM_RESC_SRAM20_256KB_ACTIVE, PM_RESC_SRAM21_256KB_ACTIVE, PM_RESC_SRAM22_256KB_ACTIVE, \ - PM_RESC_SRAM23_256KB_ACTIVE - -/* No constraints in SLEEP mode, all peripherals are available */ -#define PLATFORM_SLEEP_CONSTRAINTS \ - 17U, PM_RESC_MAIN_CLK_ON, PM_RESC_SYSXTAL_ON, PM_RESC_SYSPLLLDO_ON, PM_RESC_SYSPLLANA_ON, \ - PM_RESC_FLEXSPI0_SRAM_ACTIVE, PM_RESC_SRAM12_128KB_ACTIVE, PM_RESC_SRAM13_128KB_ACTIVE, \ - PM_RESC_SRAM14_128KB_ACTIVE, PM_RESC_SRAM15_128KB_ACTIVE, PM_RESC_SRAM16_256KB_ACTIVE, \ - PM_RESC_SRAM17_256KB_ACTIVE, PM_RESC_SRAM18_256KB_ACTIVE, PM_RESC_SRAM19_256KB_ACTIVE, \ - PM_RESC_SRAM20_256KB_ACTIVE, PM_RESC_SRAM21_256KB_ACTIVE, PM_RESC_SRAM22_256KB_ACTIVE, \ - PM_RESC_SRAM23_256KB_ACTIVE - -/* Use selective RAM retention mechanism. */ -#define PLATFORM_DEEP_SLEEP_CONSTRAINTS \ - 13U, PM_RESC_FLEXSPI0_SRAM_RETENTION, PM_RESC_SRAM12_128KB_RETENTION, PM_RESC_SRAM13_128KB_RETENTION, \ - PM_RESC_SRAM14_128KB_RETENTION, PM_RESC_SRAM15_128KB_RETENTION, PM_RESC_SRAM16_256KB_RETENTION, \ - PM_RESC_SRAM17_256KB_RETENTION, PM_RESC_SRAM18_256KB_RETENTION, PM_RESC_SRAM19_256KB_RETENTION, \ - PM_RESC_SRAM20_256KB_RETENTION, PM_RESC_SRAM21_256KB_RETENTION, PM_RESC_SRAM22_256KB_RETENTION, \ - PM_RESC_SRAM23_256KB_RETENTION - -/* POWER DOWN mode has no configuration options. */ -#define PLATFORM_POWER_DOWN_CONSTRAINTS 0 - -/* DEEP POWER DOWN mode has no configuration options. */ -#define PLATFORM_DEEP_POWER_DOWN_CONSTRAINTS 0 - -/* -------------------------------------------------------------------------- */ -/* Public type definition */ -/* -------------------------------------------------------------------------- */ - -/* -------------------------------------------------------------------------- */ -/* Public prototypes */ -/* -------------------------------------------------------------------------- */ - -/*! - * \brief Initialize platform specific resources for low power support. - * - */ -void PLATFORM_LowPowerInit(void); - -/*! - * \brief Initialize a wake up timer - * Should be called during low power initialization. - * - */ -void PLATFORM_InitWakeUpTimer(void); - -/*! - * \brief Initialize wireless chip module. - * - */ -uint8_t PLATFORM_ControllerLowPowerInit(void); - -/*! - * \brief Start a wake up timer for next tickless idle period - * Should be called during low power entry procedure. - * - * \param[in] timeOutUs maximum timeout in microsec - */ -void PLATFORM_StartWakeUpTimer(uint64_t timeOutUs); - -/*! - * \brief Stops previously started wake up timer if the tickless period ended - * earlier than expected. Should be called after exiting low power. - * - */ -void PLATFORM_StopWakeUpTimer(void); - -/*! - * \brief Returns current timestamp in us, usually called before and after tickless - * period to compute the number of ticks to update RTOS timebase. - * - * \return uint64_t Timestamp value in us - */ -uint64_t PLATFORM_GetLowPowerTimestampUs(void); - -/*! - * \brief Converts timestamp values returned by PLATFORM_GetLowPowerTimestamp to - * a duration in us and handles counter wrapping. - * - * \param[in] enterLowPowerTimestamp Timestamp measured before entering tickless period - * \param[in] exitLowPowerTimestamp Timestamp measured after exiting tickless period - * \return uint64_t Computed duration in us - */ -uint64_t PLATFORM_GetLowPowerDurationUs(uint64_t enterLowPowerTimestamp, uint64_t exitLowPowerTimestamp); - -/*! - * \brief Platform module can implement platform specific methods to execute - * when entering and exiting any low power mode. \n - * Those methods should implement only mandatory procedures for the - * platform, compatible with any connectivity protocol. - */ -void PLATFORM_EnterLowPower(void); - -/*! - * \brief Platform specific procedures to execute when exiting any low power mode - * - */ -void PLATFORM_ExitLowPower(void); - -/*! - * \brief Power gated low power modes often require specific - * entry/exit low power procedures, those should be implemented - * in the following API. - * - */ -void PLATFORM_EnterPowerDown(void); - -/*! - * \brief Power gated low power modes often require specific - * entry/exit low power procedures, those should be implemented - * in the following API. - * - */ -void PLATFORM_ExitPowerDown(void); - -/*! - * \brief Specific low power entry procedure when going to Deep Power Down mode (RAMOFF) - * - */ -void PLATFORM_EnterDeepPowerDown(void); - -/*! - * \brief Check which banks need to be retained - * \note This function is linker script specific.\n - * Amelioration handle by this function :\n - * - There is a free block at the end of the heap, so if the heap is on - * the top of the RAM. No need to retain all banks upper that the last one - * used by the heap. - * - * \return uint32_t mask of which bank needs to be retained - */ -uint32_t PLATFORM_GetDefaultRamBanksRetained(void); - -/*! - * \brief Set the banks that need to be retained in lowpower - * - * \param[in] uint32_t mask of which bank needs to be retained - */ -void PLATFORM_SetRamBanksRetained(uint32_t bank_mask); - -/*! - * \brief Check if device is allowed to enter low power mode. - * - * \param[in] uint8_t Zero on allowed or one on not allowed. - */ -uint8_t PLATFORM_AllowEnterLowPower(void); -/*! - * @} end of FWK_Platform_LowPower addtogroup - */ -/*! - * @} end of FWK_Platform_module addtogroup - */ - -#endif /* _FWK_PLATFORM_LOWPOWER_H_ */ diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/MIMXRT595S/fwk_platform_lowpower_timer.h b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/MIMXRT595S/fwk_platform_lowpower_timer.h deleted file mode 100644 index d2d9a71c34..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/MIMXRT595S/fwk_platform_lowpower_timer.h +++ /dev/null @@ -1,10 +0,0 @@ -/* -------------------------------------------------------------------------- */ -/* Copyright 2023 NXP */ -/* All rights reserved. */ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* -------------------------------------------------------------------------- */ - -#ifndef _FWK_PLATFORM_LOWPOWER_TIMER_H_ -#define _FWK_PLATFORM_LOWPOWER_TIMER_H_ - -#endif /* _FWK_PLATFORM_LOWPOWER_TIMER_H_ */ diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/connected_mcu/fwk_platform_definitions.h b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/connected_mcu/fwk_platform_definitions.h deleted file mode 100644 index c21482de12..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/connected_mcu/fwk_platform_definitions.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2022-2024 NXP - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#ifndef _FWK_PLAT_DEFS_H_ -#define _FWK_PLAT_DEFS_H_ - -#include "fsl_device_registers.h" - -#ifndef KB -#define KB(x) (((uint32_t)x) << 10u) -#endif -#ifndef MB -#define MB(x) (((uint32_t)x) << 20u) -#endif - -#define gPlatformRamStartAddress_c (0x20000000U) -#define gPlatformRamEndAddress_c (0x2001BFFFU) - -#define gPlatformFlashStartAddress_c (FSL_FEATURE_FLASH_PFLASH_START_ADDRESS) -#define gPlatformFlashEndAddress_c (FSL_FEATURE_FLASH_PFLASH_BLOCK_SIZE) - -/* - * External Flash geometry characteristics. SPI NOR Flash Part is AT25XE161D (16Mb) - */ -#define PLATFORM_EXTFLASH_SECTOR_SIZE KB(4U) -#define PLATFORM_EXTFLASH_PAGE_SIZE 256U -#define PLATFORM_EXTFLASH_TOTAL_SIZE MB(2U) - -#define PLATFORM_INTFLASH_SECTOR_SIZE FSL_FEATURE_FLASH_PFLASH_SECTOR_SIZE - -/* IFR has 4 sectors */ -#define IFR_SECT_ROMCFG 0u /* ROM Bootload configurations */ -#define IFR_SECT_USER 1u /* Reserved for customer usage */ -#define IFR_SECT_CMAC 2u /* Reserved CMAC */ -#define IFR_SECT_OTA_CFG 3u /* OTACFG */ -#ifndef FSL_FEATURE_IFR0_START_ADDRESS -#define FSL_FEATURE_IFR0_START_ADDRESS (0x02000000U) -#endif - -#define IFR_SECTOR_SIZE FSL_FEATURE_FLASH_PFLASH_SECTOR_SIZE - -#define IFR0_BASE FSL_FEATURE_IFR0_START_ADDRESS -//#define IFR1_BASE FSL_FEATURE_FLASH_BLOCK0_IFR1_START - -#define IFR_SECTOR_OFFSET(n) ((n)*IFR_SECTOR_SIZE) - -/* OTA CFG is in sector 3 of IFR */ -#define IFR_OTA_CFG_ADDR (IFR0_BASE + IFR_SECTOR_OFFSET(IFR_SECT_OTA_CFG)) -#define IFR_USER_ADDR (IFR0_BASE + IFR_SECTOR_OFFSET(IFR_SECT_USER)) -#define IFR_W_ONCE_DATA (IFR0_BASE + IFR_SECTOR_OFFSET(IFR_SECT_ROMCFG) + 0x1000) - -#define APP_FACTORY_DATA_MAX_LEN 0x800U -#define PROD_DATA_LEN 0x80U - -#define PROD_DATA_OFFSET 0U -#define APP_FACTORY_DATA_OFFSET (PROD_DATA_OFFSET + PROD_DATA_LEN) - -#if defined(__CC_ARM) || defined(__ARMCC_VERSION) -extern uint32_t Image$$PROD_DATA_REGION$$Base; -#define PROD_DATA_BASE_ADDR &Image$$PROD_DATA_REGION$$Base -#else -extern uint32_t PROD_DATA_BASE_ADDR[]; -#endif /* defined(__CC_ARM) */ - -#define MAIN_FLASH_PROD_DATA_ADDR ((uint32_t)PROD_DATA_BASE_ADDR) - -/* Connected MCU uses NOR Flash driver not mflash. NV storage is by default placed in internal flash */ -/* If one means to place NVS instance in external flash, need to define NV_STORAGE_EXTFLASH_START_OFFSET at the right - * offset in - * external flash. It could be done using NV_STORAGE_START_ADDRESS provided that it is defined accordingly in linker - * script */ -#ifdef NV_STORAGE_EXTFLASH_START_OFFSET -#define NV_EXTFLASH_OFFSET(offset) (NV_EXTFLASH_PHYS_ADDR(offset) - NV_STORAGE_EXTFLASH_START_OFFSET) -#define NV_STORAGE_START_OFFSET NV_STORAGE_EXTFLASH_START_OFFSET -#else -/* - * NV_STORAGE_START_ADDRESS is defined by linker script. Dwells in external flash for RW61x - */ -#define NV_STORAGE_INTFLASH_START_OFFSET ((uint32_t)NV_STORAGE_START_ADDRESS - gPlatformFlashStartAddress_c) -#define NV_STORAGE_START_OFFSET NV_STORAGE_INTFLASH_START_OFFSET -#endif - -#endif /* _FWK_PLAT_DEFS_H_ */ diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/imx_rt/CMakeLists.txt b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/imx_rt/CMakeLists.txt deleted file mode 100644 index 146a830d25..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/imx_rt/CMakeLists.txt +++ /dev/null @@ -1,65 +0,0 @@ -list(APPEND SOURCES - fwk_platform_hdlc.c - fwk_platform_ot.c - configs/fwk_lfs_config.c -) - -list(APPEND LINK_LIBRARIES) -list(APPEND COMPILE_PRIVATE_DEFINITIONS) - -##Check if the k32w0 transceiver is enabled -string(FIND ${CONNFWK_TRANSCEIVER} "k32w0" outString) -if (${outString} GREATER_EQUAL 0) - if (NOT CONNFWK_OTW) - message(FATAL_ERROR "CONNFWK_OTW must be set to ON when k32w0 transceiver is supported") - endif() - if (CONNFWK_TRANSCEIVER_BIN_PATH) - get_filename_component(CONNFWK_TRANSCEIVER_BIN_PATH "${CONNFWK_TRANSCEIVER_BIN_PATH}" ABSOLUTE) - list(APPEND COMPILE_PRIVATE_DEFINITIONS - -DK32W0_RCP_BINARY_H_FILE="${CONNFWK_TRANSCEIVER_BIN_PATH}" - ) - else () - message(FATAL_ERROR "CONNFWK_TRANSCEIVER_BIN_PATH option missing. Example -DCONNFWK_TRANSCEIVER_BIN_PATH=~/Desktop/imx_rt/ot-nxp/build_k32w061/rcp_only_uart_flow_control/bin/ot-rcp.elf.bin.h") - endif() - list(APPEND LINK_LIBRARIES - connfwk-OTW - ) -endif() - -#Build the correct coex files depending of the transceiver chosen - -if(${CONNFWK_TRANSCEIVER} STREQUAL "") -else() -if(${CONNFWK_TRANSCEIVER} STREQUAL "k32w0") - list(APPEND SOURCES - k32w0/fwk_platform_coex.c - ) -elseif(${CONNFWK_TRANSCEIVER} STREQUAL "iwx12") - list(APPEND SOURCES - iw612/fwk_platform_coex.c - ) -endif() - -add_library(connfwk-platform-${CONNFWK_PLATFORM_FAMILY} ${SOURCES}) - -# Making those includes PUBLIC will share them to the other targets linking this lib -target_include_directories(connfwk-platform-${CONNFWK_PLATFORM_FAMILY} - PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/../include - ${CMAKE_CURRENT_SOURCE_DIR} - configs -) - -target_compile_definitions(connfwk-platform-${CONNFWK_PLATFORM_FAMILY} PRIVATE ${COMPILE_PRIVATE_DEFINITIONS}) - -# Get common configs from the connfwk-config interface -target_link_libraries(connfwk-platform-${CONNFWK_PLATFORM_FAMILY} - PRIVATE - connfwk-config - ${LINK_LIBRARIES} - ${CONNFWK_MCUX_SDK_LIB} -) - -#Some framework config files are required by SDK component: example littlefs -target_link_libraries(connfwk-config INTERFACE connfwk-platform-${CONNFWK_PLATFORM_FAMILY}) -endif() diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/imx_rt/configs/fwk_lfs_config.c b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/imx_rt/configs/fwk_lfs_config.c deleted file mode 100644 index 1f37803636..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/imx_rt/configs/fwk_lfs_config.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * lfs util functions - * - * Copyright (c) 2017, Arm Limited. All rights reserved. - * SPDX-License-Identifier: BSD-3-Clause - */ -#include "lfs_util.h" - -// Software CRC implementation with small lookup table -uint32_t lfs_crc(uint32_t crc, const void *buffer, size_t size) -{ - static const uint32_t rtable[16] = { - 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac, 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c, - 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c, - }; - - const uint8_t *data = buffer; - - for (size_t i = 0; i < size; i++) - { - crc = (crc >> 4) ^ rtable[(crc ^ (data[i] >> 0)) & 0xf]; - crc = (crc >> 4) ^ rtable[(crc ^ (data[i] >> 4)) & 0xf]; - } - - return crc; -} diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/imx_rt/configs/fwk_lfs_config.h b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/imx_rt/configs/fwk_lfs_config.h deleted file mode 100644 index 3b0ddda0c7..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/imx_rt/configs/fwk_lfs_config.h +++ /dev/null @@ -1,201 +0,0 @@ -/* -------------------------------------------------------------------------- */ -/* Copyright 2023 NXP */ -/* All rights reserved. */ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* -------------------------------------------------------------------------- */ - -#ifndef _FWK_LFS_CONFIG_ -#define _FWK_LFS_CONFIG_ - -/* -------------------------------------------------------------------------- */ -/* Includes */ -/* -------------------------------------------------------------------------- */ -#include - -#include "fsl_common.h" -#include "fsl_debug_console.h" -#include - -/* -------------------------------------------------------------------------- */ -/* Macros */ -/* -------------------------------------------------------------------------- */ -#ifdef LFS_DEBUG_ENABLE -#define LFS_TRACE_(fmt, ...) PRINTF("[LFS_TRACE] " fmt "%s\n", __VA_ARGS__) -#define LFS_TRACE(...) LFS_TRACE_(__VA_ARGS__, "") - -#define LFS_DEBUG_(fmt, ...) PRINTF("[LFS_DEBUG] " fmt "%s\n", __VA_ARGS__) -#define LFS_DEBUG(...) LFS_DEBUG_(__VA_ARGS__, "") - -#define LFS_WARN_(fmt, ...) PRINTF("[LFS_WARN] " fmt "%s\n", __VA_ARGS__) -#define LFS_WARN(...) LFS_WARN_(__VA_ARGS__, "") - -#define LFS_ERROR_(fmt, ...) PRINTF("[LFS_ERROR] " fmt "%s\n", __VA_ARGS__) -#define LFS_ERROR(...) LFS_ERROR_(__VA_ARGS__, "") -#else -#define LFS_TRACE(...) -#define LFS_DEBUG(...) -#define LFS_WARN(...) -#define LFS_ERROR(...) -#endif /* LFS_DEBUG_ENABLE */ - -#define LFS_ASSERT(test) assert(test) - -/* -------------------------------------------------------------------------- */ -/* Public functions */ -/* -------------------------------------------------------------------------- */ - -/* Builtin functions, these may be replaced by more efficient - * toolchain-specific implementations. LFS_NO_INTRINSICS falls back to a more - * expensive basic C implementation for debugging purposes */ - -// Min/max functions for unsigned 32-bit numbers -static inline uint32_t lfs_max(uint32_t a, uint32_t b) -{ - return (a > b) ? a : b; -} - -static inline uint32_t lfs_min(uint32_t a, uint32_t b) -{ - return (a < b) ? a : b; -} - -// Align to nearest multiple of a size -static inline uint32_t lfs_aligndown(uint32_t a, uint32_t alignment) -{ - return a - (a % alignment); -} - -static inline uint32_t lfs_alignup(uint32_t a, uint32_t alignment) -{ - return lfs_aligndown(a + alignment - 1, alignment); -} - -// Find the smallest power of 2 greater than or equal to a -static inline uint32_t lfs_npw2(uint32_t a) -{ -#if !defined(LFS_NO_INTRINSICS) && (defined(__GNUC__) || defined(__CC_ARM)) - return 32 - __builtin_clz(a - 1); -#else - uint32_t r = 0; - uint32_t s; - a -= 1; - s = (a > 0xffff) << 4; - a >>= s; - r |= s; - s = (a > 0xff) << 3; - a >>= s; - r |= s; - s = (a > 0xf) << 2; - a >>= s; - r |= s; - s = (a > 0x3) << 1; - a >>= s; - r |= s; - return (r | (a >> 1)) + 1; -#endif -} - -// Count the number of trailing binary zeros in a -// lfs_ctz(0) may be undefined -static inline uint32_t lfs_ctz(uint32_t a) -{ -#if !defined(LFS_NO_INTRINSICS) && defined(__GNUC__) - return __builtin_ctz(a); -#else - return lfs_npw2((a & -a) + 1) - 1; -#endif -} - -// Count the number of binary ones in a -static inline uint32_t lfs_popc(uint32_t a) -{ -#if !defined(LFS_NO_INTRINSICS) && (defined(__GNUC__) || defined(__CC_ARM)) - return __builtin_popcount(a); -#else - a = a - ((a >> 1) & 0x55555555); - a = (a & 0x33333333) + ((a >> 2) & 0x33333333); - return (((a + (a >> 4)) & 0xf0f0f0f) * 0x1010101) >> 24; -#endif -} - -// Find the sequence comparison of a and b, this is the distance -// between a and b ignoring overflow -static inline int lfs_scmp(uint32_t a, uint32_t b) -{ - return (int)(unsigned)(a - b); -} - -// Convert between 32-bit little-endian and native order -static inline uint32_t lfs_fromle32(uint32_t a) -{ -#if !defined(LFS_NO_INTRINSICS) && \ - ((defined(BYTE_ORDER) && defined(ORDER_LITTLE_ENDIAN) && BYTE_ORDER == ORDER_LITTLE_ENDIAN) || \ - (defined(__BYTE_ORDER) && defined(__ORDER_LITTLE_ENDIAN) && __BYTE_ORDER == __ORDER_LITTLE_ENDIAN) || \ - (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)) - return a; -#elif !defined(LFS_NO_INTRINSICS) && \ - ((defined(BYTE_ORDER) && defined(ORDER_BIG_ENDIAN) && BYTE_ORDER == ORDER_BIG_ENDIAN) || \ - (defined(__BYTE_ORDER) && defined(__ORDER_BIG_ENDIAN) && __BYTE_ORDER == __ORDER_BIG_ENDIAN) || \ - (defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)) - return __builtin_bswap32(a); -#else - return (((uint8_t *)&a)[0] << 0) | (((uint8_t *)&a)[1] << 8) | (((uint8_t *)&a)[2] << 16) | - (((uint8_t *)&a)[3] << 24); -#endif -} - -static inline uint32_t lfs_tole32(uint32_t a) -{ - return lfs_fromle32(a); -} - -// Convert between 32-bit big-endian and native order -static inline uint32_t lfs_frombe32(uint32_t a) -{ -#if !defined(LFS_NO_INTRINSICS) && \ - ((defined(BYTE_ORDER) && defined(ORDER_LITTLE_ENDIAN) && BYTE_ORDER == ORDER_LITTLE_ENDIAN) || \ - (defined(__BYTE_ORDER) && defined(__ORDER_LITTLE_ENDIAN) && __BYTE_ORDER == __ORDER_LITTLE_ENDIAN) || \ - (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)) - return __builtin_bswap32(a); -#elif !defined(LFS_NO_INTRINSICS) && \ - ((defined(BYTE_ORDER) && defined(ORDER_BIG_ENDIAN) && BYTE_ORDER == ORDER_BIG_ENDIAN) || \ - (defined(__BYTE_ORDER) && defined(__ORDER_BIG_ENDIAN) && __BYTE_ORDER == __ORDER_BIG_ENDIAN) || \ - (defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)) - return a; -#else - return (((uint8_t *)&a)[0] << 24) | (((uint8_t *)&a)[1] << 16) | (((uint8_t *)&a)[2] << 8) | - (((uint8_t *)&a)[3] << 0); -#endif -} - -static inline uint32_t lfs_tobe32(uint32_t a) -{ - return lfs_frombe32(a); -} - -// Allocate memory, only used if buffers are not provided to littlefs -// Note, memory must be 64-bit aligned -static inline void *lfs_malloc(size_t size) -{ -#ifndef LFS_NO_MALLOC - return pvPortMalloc(size); -#else - (void)size; - return NULL; -#endif -} - -// Deallocate memory, only used if buffers are not provided to littlefs -static inline void lfs_free(void *p) -{ -#ifndef LFS_NO_MALLOC - vPortFree(p); -#else - (void)p; -#endif -} - -// Calculate CRC-32 with polynomial = 0x04c11db7 -uint32_t lfs_crc(uint32_t crc, const void *buffer, size_t size); - -#endif /* _FWK_LFS_CONFIG_ */ diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/imx_rt/fwk_platform_hdlc.c b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/imx_rt/fwk_platform_hdlc.c deleted file mode 100644 index 3bb0085da8..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/imx_rt/fwk_platform_hdlc.c +++ /dev/null @@ -1,330 +0,0 @@ -/* -------------------------------------------------------------------------- */ -/* Copyright 2021-2023 NXP */ -/* All rights reserved. */ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* -------------------------------------------------------------------------- */ - -/* -------------------------------------------------------------------------- */ -/* Includes */ -/* -------------------------------------------------------------------------- */ - -#include -#include - -#include "fwk_platform_hdlc.h" -#include "fsl_component_serial_manager.h" -#include "board.h" -#include "fwk_platform_coex.h" - -/* -------------------------------------------------------------------------- */ -/* Private macros */ -/* -------------------------------------------------------------------------- */ - -#ifndef SPINEL_UART_INSTANCE -#define SPINEL_UART_INSTANCE 3 -#endif -#ifndef SPINEL_ENABLE_RX_RTS -#define SPINEL_ENABLE_RX_RTS 1 -#endif -#ifndef SPINEL_ENABLE_TX_RTS -#define SPINEL_ENABLE_TX_RTS 1 -#endif - -#ifndef SPINEL_UART_BAUD_RATE -#define SPINEL_UART_BAUD_RATE 1000000 -#endif - -#ifndef SPINEL_UART_CLOCK_RATE -#define SPINEL_UART_CLOCK_RATE BOARD_BT_UART_CLK_FREQ -#endif - -#define SPINEL_HDLC_MALLOC pvPortMalloc -#define SPINEL_HDLC_FREE vPortFree - -/* -------------------------------------------------------------------------- */ -/* Private types */ -/* -------------------------------------------------------------------------- */ - -enum -{ - /* Ring buffer size should be >= to the RCP max TX buffer size value which is 2048 */ - kMaxRingBufferSize = 2048, -}; - -/* -------------------------------------------------------------------------- */ -/* Private memory */ -/* -------------------------------------------------------------------------- */ - -static SERIAL_MANAGER_HANDLE_DEFINE(otTransceiverSerialHandle); -static SERIAL_MANAGER_READ_HANDLE_DEFINE(otTransceiverSerialReadHandle); - -static uint8_t s_ringBuffer[kMaxRingBufferSize]; - -static platform_hdlc_rx_callback_t hdlcRxCallback; -static void * callbackParam = NULL; - -#if (defined(HAL_UART_DMA_ENABLE) && (HAL_UART_DMA_ENABLE > 0U)) -static serial_port_uart_dma_config_t uartConfig = { -#else -static serial_port_uart_config_t uartConfig = { -#endif - .baudRate = SPINEL_UART_BAUD_RATE, - .parityMode = kSerialManager_UartParityDisabled, - .stopBitCount = kSerialManager_UartOneStopBit, - .enableRx = 1, - .enableTx = 1, - .enableRxRTS = SPINEL_ENABLE_RX_RTS, - .enableTxCTS = SPINEL_ENABLE_TX_RTS, - .instance = SPINEL_UART_INSTANCE, - .txFifoWatermark = 0, - .rxFifoWatermark = 0, -}; - -static const serial_manager_config_t serialManagerConfig = { - .ringBuffer = &s_ringBuffer[0], - .ringBufferSize = sizeof(s_ringBuffer), - .type = kSerialPort_Uart, - .blockType = kSerialManager_NonBlocking, - .portConfig = (serial_port_uart_config_t *)&uartConfig, -}; - -static bool hdlcUartInitialized = false; - -/* -------------------------------------------------------------------------- */ -/* Private prototypes */ -/* -------------------------------------------------------------------------- */ - -int PLATFORM_InitHdlcUart(void); -static int PLATFORM_TerminateHdlcUart(void); -static void PLATFORM_HdlcSerialManagerTxCallback(void * pData, - serial_manager_callback_message_t *message, - serial_manager_status_t status); -static void PLATFORM_HdlcSerialManagerRxCallback(void * pData, - serial_manager_callback_message_t *message, - serial_manager_status_t status); - -/* -------------------------------------------------------------------------- */ -/* Public functions */ -/* -------------------------------------------------------------------------- */ - -int PLATFORM_InitHdlcInterface(platform_hdlc_rx_callback_t callback, void *param) -{ - int ret = 0; - - hdlcRxCallback = callback; - callbackParam = param; - - do - { - /* Init controllers - * The hdlc interface will be initialized at the end of the controller initialization - * and before doing a reset. - */ - if (PLATFORM_InitControllers(conn802_15_4_c) != 0) - { - ret = -1; - break; - } - if (PLATFORM_InitHdlcUart() != 0) - { - ret = -1; - break; - } - } while (false); - - if (ret < 0) - { - hdlcRxCallback = NULL; - callbackParam = NULL; - } - - return ret; -} - -int PLATFORM_TerminateHdlcInterface(void) -{ - int ret = 0; - - hdlcRxCallback = NULL; - callbackParam = NULL; - - if (PLATFORM_TerminateHdlcUart() != 0) - { - ret = -1; - } - - return ret; -} - -int PLATFORM_SendHdlcMessage(uint8_t *msg, uint32_t len) -{ - serial_manager_status_t serialManagerStatus; - uint8_t * pWriteHandleAndFrame = NULL; - uint8_t * pNewFrameBuffer = NULL; - int ret = 0; - - /* Disable IRQs to prevent concurrent accesses to class fields or - * serial manager global variables that could be accessed in the - * Write function - */ - OSA_InterruptDisable(); - - do - { - pWriteHandleAndFrame = (uint8_t *)SPINEL_HDLC_MALLOC(SERIAL_MANAGER_WRITE_HANDLE_SIZE + len); - if (pWriteHandleAndFrame == NULL) - { - ret = -1; - break; - } - - pNewFrameBuffer = pWriteHandleAndFrame + SERIAL_MANAGER_WRITE_HANDLE_SIZE; - memcpy(pNewFrameBuffer, msg, len); - - serialManagerStatus = SerialManager_OpenWriteHandle((serial_handle_t)otTransceiverSerialHandle, - (serial_write_handle_t)pWriteHandleAndFrame); - if (serialManagerStatus != kStatus_SerialManager_Success) - { - ret = -2; - break; - } - - serialManagerStatus = SerialManager_InstallTxCallback( - (serial_write_handle_t)pWriteHandleAndFrame, PLATFORM_HdlcSerialManagerTxCallback, pWriteHandleAndFrame); - if (serialManagerStatus != kStatus_SerialManager_Success) - { - ret = -3; - break; - } - - serialManagerStatus = - SerialManager_WriteNonBlocking((serial_write_handle_t)pWriteHandleAndFrame, pNewFrameBuffer, len); - if (serialManagerStatus != kStatus_SerialManager_Success) - { - ret = -4; - break; - } - } while (false); - - if (ret != 0) - { - SPINEL_HDLC_FREE(pWriteHandleAndFrame); - } - - OSA_InterruptEnable(); - - return ret; -} - -int PLATFORM_InitHdlcUart(void) -{ - serial_manager_status_t status; - int ret = 0; - - /* - * Make sure to disable interrupts while initializating the serial manager interface - * Some issues could happen a UART IRQ is fired during serial manager initialization - */ - OSA_InterruptDisable(); - do - { - if (hdlcUartInitialized) - break; - /* Retrieve the UART clock rate at runtime as it can depend on clock config */ - uartConfig.clockRate = SPINEL_UART_CLOCK_RATE; - - status = SerialManager_Init((serial_handle_t)otTransceiverSerialHandle, &serialManagerConfig); - if (status != kStatus_SerialManager_Success) - { - ret = -1; - break; - } - - status = SerialManager_OpenReadHandle((serial_handle_t)otTransceiverSerialHandle, - (serial_read_handle_t)otTransceiverSerialReadHandle); - if (status != kStatus_SerialManager_Success) - { - ret = -2; - break; - } - - status = SerialManager_InstallRxCallback((serial_read_handle_t)otTransceiverSerialReadHandle, - PLATFORM_HdlcSerialManagerRxCallback, NULL); - if (status != kStatus_SerialManager_Success) - { - ret = -3; - break; - } - hdlcUartInitialized = true; - } while (false); - OSA_InterruptEnable(); - assert(status == kStatus_SerialManager_Success); - - return ret; -} - -/* -------------------------------------------------------------------------- */ -/* Private functions */ -/* -------------------------------------------------------------------------- */ - -static int PLATFORM_TerminateHdlcUart(void) -{ - serial_manager_status_t status; - int ret = 0; - - do - { - if (!hdlcUartInitialized) - break; - status = SerialManager_CloseReadHandle((serial_read_handle_t)otTransceiverSerialReadHandle); - if (status != kStatus_SerialManager_Success) - { - ret = -1; - break; - } - - status = SerialManager_Deinit((serial_handle_t)otTransceiverSerialHandle); - if (status != kStatus_SerialManager_Success) - { - ret = -2; - break; - } - hdlcUartInitialized = false; - } while (false); - - return ret; -} - -static void PLATFORM_HdlcSerialManagerTxCallback(void * pData, - serial_manager_callback_message_t *message, - serial_manager_status_t status) -{ - OSA_InterruptDisable(); - /* Close the write handle */ - SerialManager_CloseWriteHandle((serial_write_handle_t)pData); - OSA_InterruptEnable(); - /* Free the buffer */ - SPINEL_HDLC_FREE(pData); -} - -static void PLATFORM_HdlcSerialManagerRxCallback(void * param, - serial_manager_callback_message_t *message, - serial_manager_status_t status) -{ - uint8_t mUartRxBuffer[256]; - uint32_t bytesRead = 0U; - serial_manager_status_t smStatus; - - do - { - OSA_InterruptDisable(); - smStatus = SerialManager_TryRead((serial_read_handle_t)otTransceiverSerialReadHandle, mUartRxBuffer, - sizeof(mUartRxBuffer), &bytesRead); - OSA_InterruptEnable(); - - if ((hdlcRxCallback != NULL) && (bytesRead > 0U) && (smStatus == kStatus_SerialManager_Success)) - { - hdlcRxCallback(mUartRxBuffer, bytesRead, callbackParam); - } - } while (bytesRead != 0U); -} diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/imx_rt/fwk_platform_ot.c b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/imx_rt/fwk_platform_ot.c deleted file mode 100644 index 463d8a5989..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/imx_rt/fwk_platform_ot.c +++ /dev/null @@ -1,39 +0,0 @@ -/* -------------------------------------------------------------------------- */ -/* Copyright 2021-2022 NXP */ -/* All rights reserved. */ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* -------------------------------------------------------------------------- */ - -/* -------------------------------------------------------------------------- */ -/* Includes */ -/* -------------------------------------------------------------------------- */ - -#include - -#include "fwk_platform_coex.h" - -/* -------------------------------------------------------------------------- */ -/* Private macros */ -/* -------------------------------------------------------------------------- */ - -/* -------------------------------------------------------------------------- */ -/* Private types */ -/* -------------------------------------------------------------------------- */ - -/* -------------------------------------------------------------------------- */ -/* Private memory */ -/* -------------------------------------------------------------------------- */ - -/* -------------------------------------------------------------------------- */ -/* Public functions */ -/* -------------------------------------------------------------------------- */ - -int PLATFORM_InitOt(void) -{ - int ret = 0; - - /* Reset and Download firmware to controller */ - ret = PLATFORM_InitControllers((uint8_t)conn802_15_4_c); - - return ret; -} diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/imx_rt/iw612/fwk_platform_coex.c b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/imx_rt/iw612/fwk_platform_coex.c deleted file mode 100644 index c181bba63c..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/imx_rt/iw612/fwk_platform_coex.c +++ /dev/null @@ -1,187 +0,0 @@ -/* -------------------------------------------------------------------------- */ -/* Copyright 2022-2023 NXP */ -/* All rights reserved. */ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* -------------------------------------------------------------------------- */ - -/* -------------------------------------------------------------------------- */ -/* Includes */ -/* -------------------------------------------------------------------------- */ -#include -#include "fwk_platform_coex.h" -#include "fsl_adapter_gpio.h" -#include "fsl_common.h" -#include "wifi-decl.h" -#include "sduart_nw61x_se.h" -#include "firmware_dnld.h" -#include "fwdnld_intf_abs.h" -#include "fsl_os_abstraction.h" -#include "fwk_platform.h" - -/* -------------------------------------------------------------------------- */ -/* Private macros */ -/* -------------------------------------------------------------------------- */ -#ifndef PLATFORM_CONFIG_DEFAULT_RESET_DELAY_MS -// Default delay after RÌ…EÌ…SÌ…EÌ…TÌ… assertion, in miliseconds. -#define PLATFORM_CONFIG_DEFAULT_RESET_DELAY_MS 200 -#endif - -#ifndef PLATFORM_RESET_PIN_PORT -#define PLATFORM_RESET_PIN_PORT 3 -#endif - -#ifndef PLATFORM_RESET_PIN_NUM -#define PLATFORM_RESET_PIN_NUM 9 -#endif - -#ifndef PLATFORM_RESET_PIN_LVL_ON -#define PLATFORM_RESET_PIN_LVL_ON 1U -#endif - -#ifndef PLATFORM_RESET_PIN_LVL_OFF -#define PLATFORM_RESET_PIN_LVL_OFF 0U -#endif - -/* Weak function. */ -#if defined(__GNUC__) -#define __WEAK_FUNC __attribute__((weak)) -#elif defined(__ICCARM__) -#define __WEAK_FUNC __weak -#elif defined(__CC_ARM) || defined(__ARMCC_VERSION) -#define __WEAK_FUNC __attribute__((weak)) -#endif - -#define PLATFORM_IOEXP_I2C_ADDR_7BIT 0x20U -#define PLATFORM_IOEXP_CONFIGURATION_REG 0x03U -#define PLATFORM_IOEXP_CONFIGURATION_SPI_ENABLE 0xFEU - -/* -------------------------------------------------------------------------- */ -/* Private types */ -/* -------------------------------------------------------------------------- */ - -/* -------------------------------------------------------------------------- */ -/* Private memory */ -/* -------------------------------------------------------------------------- */ - -static GPIO_HANDLE_DEFINE(otGpioResetHandle); - -static const hal_gpio_pin_config_t resetPinConfig = { - .direction = kHAL_GpioDirectionOut, - .level = PLATFORM_RESET_PIN_LVL_OFF, - .port = PLATFORM_RESET_PIN_PORT, - .pin = PLATFORM_RESET_PIN_NUM, -}; - -static bool isOtControllerUp = false; - -/* -------------------------------------------------------------------------- */ -/* Private prototypes */ -/* -------------------------------------------------------------------------- */ - -static int PLATFORM_ResetController(void); - -/* -------------------------------------------------------------------------- */ -/* Public functions */ -/* -------------------------------------------------------------------------- */ - -extern int wlan_init(const uint8_t *fw_start_addr, const size_t size); - -int PLATFORM_InitControllers(uint8_t controllersMask) -{ - (void)controllersMask; - - hal_gpio_status_t status; - int ret = 0; - - /* initialize controller if not done */ - if (isOtControllerUp == false) - { - do - { - /* Init the reset output gpio */ - status = HAL_GpioInit((hal_gpio_handle_t)otGpioResetHandle, (hal_gpio_pin_config_t *)&resetPinConfig); - if (status != kStatus_HAL_GpioSuccess) - { - ret = -1; - break; - } - (void)status; - - /* Reset RCP chip. */ - if (PLATFORM_ResetController() != 0) - { - ret = -2; - break; - } - - /* check if Wi-Fi is supported */ - if ((controllersMask & connWlan_c) != 0) - { - ret = wlan_init(wlan_fw_bin, wlan_fw_bin_len); - assert(WM_SUCCESS == ret); - } - else - { - /* Download firmware */ - fwdnld_intf_t *intf; - intf = fwdnld_intf_init(FWDNLD_INTF_SDIO, NULL); - ret = firmware_download(wlan_fw_bin, wlan_fw_bin_len, intf, 0); - assert(WM_SUCCESS == ret); - } - - /* Waiting for the RCP chip starts up */ - OSA_TimeDelay(PLATFORM_CONFIG_DEFAULT_RESET_DELAY_MS); - - if ((controllersMask & conn802_15_4_c) != 0) - { - /* Configure IO_Expander to enable SPI interface through M.2 connector */ - PLATFORM_IOEXP_I2C_program(PLATFORM_IOEXP_I2C_ADDR_7BIT, PLATFORM_IOEXP_CONFIGURATION_REG, - PLATFORM_IOEXP_CONFIGURATION_SPI_ENABLE); - } - - isOtControllerUp = true; - } while (false); - } - - return ret; -} - -/* - * Empty wlan function that could be redefined if Wi-Fi is supported - */ -__WEAK_FUNC int wlan_init(const uint8_t *fw_start_addr, const size_t size) -{ - return WM_SUCCESS; -} - -/* -------------------------------------------------------------------------- */ -/* Private functions */ -/* -------------------------------------------------------------------------- */ -static int PLATFORM_ResetController(void) -{ - hal_gpio_status_t status; - int ret = 0; - - do - { - // Set Reset pin to low level. - status = HAL_GpioSetOutput((hal_gpio_handle_t)otGpioResetHandle, PLATFORM_RESET_PIN_LVL_OFF); - if (status != kStatus_HAL_GpioSuccess) - { - ret = -1; - break; - } - - OSA_TimeDelay(PLATFORM_CONFIG_DEFAULT_RESET_DELAY_MS); - - // Set Reset pin to high level. - status = HAL_GpioSetOutput((hal_gpio_handle_t)otGpioResetHandle, PLATFORM_RESET_PIN_LVL_ON); - if (status != kStatus_HAL_GpioSuccess) - { - ret = -2; - break; - } - } while (false); - - return ret; -} diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/imx_rt/k32w0/fwk_platform_coex.c b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/imx_rt/k32w0/fwk_platform_coex.c deleted file mode 100644 index d57c8caec3..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/imx_rt/k32w0/fwk_platform_coex.c +++ /dev/null @@ -1,80 +0,0 @@ -/* -------------------------------------------------------------------------- */ -/* Copyright 2022-2023 NXP */ -/* All rights reserved. */ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* -------------------------------------------------------------------------- */ - -/* -------------------------------------------------------------------------- */ -/* Includes */ -/* -------------------------------------------------------------------------- */ - -#include -#include - -#include "fsl_os_abstraction.h" -#include "fwk_otw.h" - -#ifndef K32W0_RCP_BINARY_H_FILE -#define K32W0_RCP_BINARY_H_FILE "rcp_name.bin.h" -#endif - -#include K32W0_RCP_BINARY_H_FILE - -/* -------------------------------------------------------------------------- */ -/* Private macros */ -/* -------------------------------------------------------------------------- */ - -/* -------------------------------------------------------------------------- */ -/* Private types */ -/* -------------------------------------------------------------------------- */ - -/* -------------------------------------------------------------------------- */ -/* Private memory */ -/* -------------------------------------------------------------------------- */ - -static bool isOtControllerUp = false; - -/* -------------------------------------------------------------------------- */ -/* Private prototypes */ -/* -------------------------------------------------------------------------- */ - -/* -------------------------------------------------------------------------- */ -/* Public functions */ -/* -------------------------------------------------------------------------- */ - -int PLATFORM_InitControllers(uint8_t controllersMask) -{ - (void)controllersMask; - - eOtwStatus otwStatus; - int ret = 0; - - do - { - /* initialize controller if not done */ - if (isOtControllerUp) - break; - - otwStatus = Otw_FirmwareDownload(ot_rcp, sizeof(ot_rcp), false); - if (otwStatus != E_OTW_OK && otwStatus != E_OTW_FIRMWARE_UPDATE_NOT_REQUIRED) - { - ret = -1; - break; - } - otwStatus = Otw_Reset(); - if (otwStatus != E_OTW_OK) - { - ret = -1; - break; - } - isOtControllerUp = true; - - } while (false); - - assert(ret == 0); - - return ret; -} -/* -------------------------------------------------------------------------- */ -/* Private functions */ -/* -------------------------------------------------------------------------- */ \ No newline at end of file diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/connected_mcu/configs/fwk_config.h b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/kw45_k32w1_mcxw71/configs/fwk_config.h similarity index 72% rename from mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/connected_mcu/configs/fwk_config.h rename to mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/kw45_k32w1_mcxw71/configs/fwk_config.h index 9c230336f5..433e858542 100644 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/connected_mcu/configs/fwk_config.h +++ b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/kw45_k32w1_mcxw71/configs/fwk_config.h @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 NXP + * Copyright 2022-2025 NXP * * SPDX-License-Identifier: BSD-3-Clause */ @@ -19,7 +19,7 @@ /* * KW45/K32W148 CM33 core has the DSP extension (__DSP_PRESENT), which allows the use of the NXP UltraFast EC P256 - * library The flags may be set to 0 if this library is not required. It mainly makes sense for Matter SPAKE2P + * library. The flags may be set to 0 if this library is not required. It mainly makes sense for Matter SPAKE2P * procedures and for BLE point validation. */ #define gSecLibUseDspExtension_d 1 @@ -75,8 +75,8 @@ * flash space reserved for PROD_DATA. */ #ifndef gHwParamsProdDataPlacement_c -#define gHwParamsProdDataPlacement_c gHwParamsProdDataMainFlashMode_c -//#define gHwParamsProdDataPlacement_c gHwParamsProdDataMainFlash2IfrMode_c +//#define gHwParamsProdDataPlacement_c gHwParamsProdDataMainFlashMode_c +#define gHwParamsProdDataPlacement_c gHwParamsProdDataMainFlash2IfrMode_c //#define gHwParamsProdDataPlacement_c gHwParamsProdDataIfrMode_c #endif @@ -143,14 +143,43 @@ * RNG source of entropy *********************************************************************/ -/* On connected_mcu platform the only source of entropy disponible is the S200 */ +/* On wireless_mcu platform the only source of entropy disponible is the S200 */ #ifndef gRngUseSecureSubSystem_d #define gRngUseSecureSubSystem_d 1 #endif -#if defined(gRngUseSecureSubSystem_d) && (gRngUseSecureSubSystem_d == 0) -#warning \ - "On connected_mcu the only source of entropy is the S200, RNG will not be properly initialized if this flag is not enabled" +/********************************************************************* + * SecLib + *********************************************************************/ +/* If SecLib.c is used, prevent from using LTC HW as this module is located on NBU side and is used exclusively + by Ble controller and 15.4 MAC/Phy code */ +#undef FSL_FEATURE_SOC_LTC_COUNT + +/********************************************************************* + * NBU debuggability + *********************************************************************/ +/* Enable NBU access to GPIO PORT D - This allows easier debugging when an issue is reported with a specific main core + * binary. + * \warning: Disabling this compile macro can impair the debug capability of the NBU for a specific main core binary. + * \warning: This part of code can generate bus fault when trustzone is enabled (code executed in non secure mode). + * Reason is that TRDC_IDAU_CR can not be read. In this case, user shall disable this compile macro when running + * in non secure mode. + * */ +#if !defined(gPlatformNbuDebugGpioDAccessEnabled_d) +#define gPlatformNbuDebugGpioDAccessEnabled_d 0 +#endif + +/********************************************************************* + * PLATFORM + *********************************************************************/ +/* Enable ICS RX processing in the system workqueue thread + * If enabled, the ICS will use the system workqueue to process its received data. This allows to reduce the time spent + * in the ISR and reduces impact on system activities. + * Note: the system workqueue requires a dedicated thread, so enabling this feature will consume a bit of RAM for the + * thread stack (this can be configured). + */ +#ifndef gPlatformIcsUseWorkqueueRxProcessing_d +#define gPlatformIcsUseWorkqueueRxProcessing_d 0 #endif #endif /* _FWK_CONFIG_H_ */ diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/connected_mcu/configs/rpmsg_config.h b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/kw45_k32w1_mcxw71/configs/rpmsg_config.h similarity index 100% rename from mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/connected_mcu/configs/rpmsg_config.h rename to mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/kw45_k32w1_mcxw71/configs/rpmsg_config.h diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/kw45_k32w1_mcxw71/fwk_platform_definitions.h b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/kw45_k32w1_mcxw71/fwk_platform_definitions.h new file mode 100644 index 0000000000..c7411c10a1 --- /dev/null +++ b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/kw45_k32w1_mcxw71/fwk_platform_definitions.h @@ -0,0 +1,152 @@ +/* + * Copyright 2022-2024 NXP + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _FWK_PLAT_DEFS_H_ +#define _FWK_PLAT_DEFS_H_ + +#include "fsl_device_registers.h" + +#ifndef KB +#define KB(x) (((uint32_t)x) << 10u) +#endif +#ifndef MB +#define MB(x) (((uint32_t)x) << 20u) +#endif + +#define gPlatformFlashStartAddress_c (FSL_FEATURE_FLASH_PFLASH_START_ADDRESS) +#define gPlatformFlashEndAddress_c (FSL_FEATURE_FLASH_PFLASH_BLOCK_SIZE) + +/* + * External Flash geometry characteristics. SPI NOR Flash Part is AT25XE161D (16Mb) + */ +#define PLATFORM_EXTFLASH_SECTOR_SIZE KB(4U) +#define PLATFORM_EXTFLASH_PAGE_SIZE 256U +#define PLATFORM_EXTFLASH_TOTAL_SIZE MB(2U) + +#define PLATFORM_INTFLASH_SECTOR_SIZE FSL_FEATURE_FLASH_PFLASH_SECTOR_SIZE + +/* IFR has 4 sectors */ +#define IFR_SECT_ROMCFG 0u /* ROM Bootload configurations */ +#define IFR_SECT_USER 1u /* Reserved for customer usage */ +#define IFR_SECT_CMAC 2u /* Reserved CMAC */ +#define IFR_SECT_OTA_CFG 3u /* OTACFG */ +#ifndef FSL_FEATURE_IFR0_START_ADDRESS +#define FSL_FEATURE_IFR0_START_ADDRESS (0x02000000U) +#endif + +#define IFR_SECTOR_SIZE FSL_FEATURE_FLASH_PFLASH_SECTOR_SIZE + +#define IFR0_BASE FSL_FEATURE_IFR0_START_ADDRESS +//#define IFR1_BASE FSL_FEATURE_FLASH_BLOCK0_IFR1_START + +#define IFR_SECTOR_OFFSET(n) ((n)*IFR_SECTOR_SIZE) + +/* OTA CFG is in sector 3 of IFR */ +#define IFR_OTA_CFG_ADDR (IFR0_BASE + IFR_SECTOR_OFFSET(IFR_SECT_OTA_CFG)) +#define IFR_USER_ADDR (IFR0_BASE + IFR_SECTOR_OFFSET(IFR_SECT_USER)) +#define IFR_W_ONCE_DATA (IFR0_BASE + IFR_SECTOR_OFFSET(IFR_SECT_ROMCFG) + 0x1000) + +#define APP_FACTORY_DATA_MAX_LEN 0x800U +#define PROD_DATA_LEN 0x80U + +#define PROD_DATA_OFFSET 0U +#define APP_FACTORY_DATA_OFFSET (PROD_DATA_OFFSET + PROD_DATA_LEN) + +#if defined(__CC_ARM) || defined(__ARMCC_VERSION) +extern uint32_t Image$$PROD_DATA_REGION$$Base; +#define PROD_DATA_BASE_ADDR &Image$$PROD_DATA_REGION$$Base +#else +extern uint32_t PROD_DATA_BASE_ADDR[]; +#endif /* defined(__CC_ARM) */ + +#define MAIN_FLASH_PROD_DATA_ADDR ((uint32_t)PROD_DATA_BASE_ADDR) + +/* Connected MCU uses NOR Flash driver not mflash. NV storage is by default placed in internal flash */ +/* If one means to place NVS instance in external flash, need to define NV_STORAGE_EXTFLASH_START_OFFSET at the right + * offset in + * external flash. It could be done using NV_STORAGE_START_ADDRESS provided that it is defined accordingly in linker + * script */ +#ifdef NV_STORAGE_EXTFLASH_START_OFFSET +#define NV_EXTFLASH_OFFSET(offset) (NV_EXTFLASH_PHYS_ADDR(offset) - NV_STORAGE_EXTFLASH_START_OFFSET) +#define NV_STORAGE_START_OFFSET NV_STORAGE_EXTFLASH_START_OFFSET +#else +/* + * NV_STORAGE_START_ADDRESS is defined by linker script. Dwells in external flash for RW61x + */ +#define NV_STORAGE_INTFLASH_START_OFFSET ((uint32_t)NV_STORAGE_START_ADDRESS - gPlatformFlashStartAddress_c) +#define NV_STORAGE_START_OFFSET NV_STORAGE_INTFLASH_START_OFFSET +#endif + +/********************************************************************* + * RAM settings + *********************************************************************/ + +/*! Enable/Disable shutdown of ECC RAM banks during low power period like Deep Sleep or Power Down + * Shutting down ECC RAM banks allows to save about 1uA + * The RAM banks can be selectively reinitialized by calling MEM_ReinitRamBank API + * The MemoryManagerLight will call this API when allocating a new block in the heap + * Defining this flag to 0 will make the system shutdown only the non-ecc banks */ +#ifndef gPlatformShutdownEccRamInLowPower +#define gPlatformShutdownEccRamInLowPower 1 +#endif + +#define PLATFORM_ADDRESS_SECURE_MASK (0x10000000U) + +#define gPlatformRamStartAddress_c (0x20000000U) +#define gPlatformRamEndAddress_c (0x2001BFFFU) + +#define PLATFORM_CTCM0_IDX 0U +#define PLATFORM_CTCM1_IDX 1U +#define PLATFORM_STCM0_IDX 2U +#define PLATFORM_STCM1_IDX 3U +#define PLATFORM_STCM2_IDX 4U +#define PLATFORM_STCM3_IDX 5U +#define PLATFORM_STCM4_IDX 6U +#define PLATFORM_STCM5_IDX 7U + +#define PLATFORM_CTCM0_START_ADDR (0x04000000U) +#define PLATFORM_CTCM0_END_ADDR (0x04001FFFU) +#define PLATFORM_CTCM1_START_ADDR (0x04002000U) +#define PLATFORM_CTCM1_END_ADDR (0x04003FFFU) +#define PLATFORM_STCM0_START_ADDR (0x20000000U) +#define PLATFORM_STCM0_END_ADDR (0x20003FFFU) +#define PLATFORM_STCM1_START_ADDR (0x20004000U) +#define PLATFORM_STCM1_END_ADDR (0x20007FFFU) +#define PLATFORM_STCM2_START_ADDR (0x20008000U) +#define PLATFORM_STCM2_END_ADDR (0x2000FFFFU) +#define PLATFORM_STCM3_START_ADDR (0x20010000U) +#define PLATFORM_STCM3_END_ADDR (0x20017FFFU) +#define PLATFORM_STCM4_START_ADDR (0x20018000U) +#define PLATFORM_STCM4_END_ADDR (0x20019FFFU) +#define PLATFORM_STCM5_START_ADDR (0x2001A000U) +#define PLATFORM_STCM5_END_ADDR (0x2001BFFFU) + +#define PLATFORM_BANK_START_ADDR \ + PLATFORM_CTCM0_START_ADDR, PLATFORM_CTCM1_START_ADDR, PLATFORM_STCM0_START_ADDR, PLATFORM_STCM1_START_ADDR, \ + PLATFORM_STCM2_START_ADDR, PLATFORM_STCM3_START_ADDR, PLATFORM_STCM4_START_ADDR, PLATFORM_STCM5_START_ADDR + +#define PLATFORM_BANK_END_ADDR \ + PLATFORM_CTCM0_END_ADDR, PLATFORM_CTCM1_END_ADDR, PLATFORM_STCM0_END_ADDR, PLATFORM_STCM1_END_ADDR, \ + PLATFORM_STCM2_END_ADDR, PLATFORM_STCM3_END_ADDR, PLATFORM_STCM4_END_ADDR, PLATFORM_STCM5_END_ADDR + +#define PLATFORM_BANK_IS_ECC TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE + +#define PLATFORM_VBAT_LDORAM_IDX PLATFORM_STCM5_IDX + +#if defined(gPlatformShutdownEccRamInLowPower) && (gPlatformShutdownEccRamInLowPower > 0) +/* In this configuration, all RAM banks can be shutdown during low power if not used + * The ECC RAM banks can be selectively reinitialized with MEM_ReinitRamBank API + * This API is also used by the Memory Manager Light */ +#define PLATFORM_SELECT_RAM_RET_START_IDX 0U +#define PLATFORM_SELECT_RAM_RET_END_IDX 7U + +#else +/* STCM3 and STCM4 only are non-ECC RAM banks */ +#define PLATFORM_SELECT_RAM_RET_START_IDX 5U +#define PLATFORM_SELECT_RAM_RET_END_IDX 6U +#endif /* gPlatformShutdownEccRamInLowPower */ + +#endif /* _FWK_PLAT_DEFS_H_ */ diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/kw47_mcxw72/configs/fwk_config.h b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/kw47_mcxw72/configs/fwk_config.h new file mode 100644 index 0000000000..18a16e34df --- /dev/null +++ b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/kw47_mcxw72/configs/fwk_config.h @@ -0,0 +1,186 @@ +/* + * Copyright 2022-2025 NXP + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _FWK_CONFIG_H_ +#define _FWK_CONFIG_H_ + +#include "fwk_platform_definitions.h" + +/********************************************************************* + * General + *********************************************************************/ + +/* Defines the calibration duration of the ADC, it will block the task during this time in milisec before trigger the + * ADC on a channel*/ +#define gSensorsAdcCalibrationDurationInMs_c 4U + +/* + * KW45/K32W148 CM33 core has the DSP extension (__DSP_PRESENT), which allows the use of the NXP UltraFast EC P256 + * library. The flags may be set to 0 if this library is not required. It mainly makes sense for Matter SPAKE2P + * procedures and for BLE point validation. + */ +#define gSecLibUseDspExtension_d 1 + +/********************************************************************* + * HW parameters enablement and placement + *********************************************************************/ + +#if !defined(gPlatformUseHwParameter_d) +#define gPlatformUseHwParameter_d 1 +#endif +/* + * gHwParamsProdDataMainFlashMode_c HWParameters PROD_DATA remain at top of main flash, + * where the linker script defines PROD_DATA_BASE_ADDR. + * When transiting from MainFlashMode to IfrMode, an interim mode MainFlash2IfrMode is used to + * enable the transfer of HWParameters from the main flash to the IFR. + * After this has been applied the size of the PROD_DATA reserved space in the linker script + * will be made 0 in order to gain a sector. + * These modes are used to configure gHwParamsProdDataPlacement_c + */ +#define gHwParamsProdDataMainFlashMode_c 0 +#define gHwParamsProdDataMainFlash2IfrMode_c 1 +#define gHwParamsProdDataIfrMode_c 2 + +/* + * Place Application FactoryData in same sector as ProdData. + * HWParameters and App Factory Data being colocated has an implication on the life cycle of information stored in the + * sector. + */ +#ifndef gHwParamsAppFactoryDataExtension_d +#define gHwParamsAppFactoryDataExtension_d 0 +#endif + +/* + * To be defined as 1 if NV_WriteHWParameters is liable to be invoked after Application Factory Data were written, + * and you intend not to have to preprogram them. Default to 0, assuming that this can happne in the context of + * a factory reset. Not needed if gHwParamsAppFactoryDataExtension_d is not set. + */ +#if (gHwParamsAppFactoryDataExtension_d != 0) +#ifndef gHwParamsAppFactoryDataPreserveOnHwParamUpdate_d +#define gHwParamsAppFactoryDataPreserveOnHwParamUpdate_d 0 +#endif +#else +#define gHwParamsAppFactoryDataPreserveOnHwParamUpdate_d 0 +#endif +/* + * Define gHwParamsProdDataPlacement_c as : + * - gHwParamsProdDataMainFlash_c if you mean to remain backward compatible. + * - gHwParamsProdDataMainFlash2IfrMode_c if you wish to conserve previous + * HWParameter setting (MAC addresses, xtal trimming data) during migration phase. + * - gHwParamsProdDataPlacementIfrMode_c for new devices or once gHwParamsProdDataMainFlash2IfrMode_c + * mode has populated the IFR with legacy values. -> after this phase update linker script to remove + * flash space reserved for PROD_DATA. + */ +#ifndef gHwParamsProdDataPlacement_c +/* Place HW Parameter section to IFR on KW47,MCXW72 */ +//#define gHwParamsProdDataPlacement_c gHwParamsProdDataMainFlashMode_c +//#define gHwParamsProdDataPlacement_c gHwParamsProdDataMainFlash2IfrMode_c +#define gHwParamsProdDataPlacement_c gHwParamsProdDataIfrMode_c +#endif + +#if (gHwParamsProdDataPlacement_c == gHwParamsProdDataMainFlashMode_c) +#define PROD_DATA_FLASH_ADDR (MAIN_FLASH_PROD_DATA_ADDR + PROD_DATA_OFFSET) +#define USER_DATA_SECTOR PROD_DATA_FLASH_ADDR +#else +/* + * IFR_RSVD_SZ may be undefined or set to 0 if no reserved space is required. + * However keep it as 0x600 during the internal development phase. + */ +#define IFR_RSVD_SZ 0x600 + +#if (defined IFR_RSVD_SZ) && (IFR_RSVD_SZ > 0) +#define PROD_DATA_FLASH_ADDR (IFR_USER_ADDR + IFR_RSVD_SZ + PROD_DATA_OFFSET) +#else +#define PROD_DATA_FLASH_ADDR (IFR_USER_ADDR + PROD_DATA_OFFSET) +#endif +#define USER_DATA_SECTOR PROD_DATA_FLASH_ADDR +#endif + +#ifdef gHwParamsAppFactoryDataExtension_d +#define APP_FACTORY_DATA_FLASH_ADDR (PROD_DATA_FLASH_ADDR + APP_FACTORY_DATA_OFFSET) +#endif + +/********************************************************************* + * Reset Method + * Define the alternative method from warm reset to use for Device reset + * when calling PLATFORM_ResetCpu() + *********************************************************************/ +#define gUseResetByNvicReset_c 1 +#define gUseResetByLvdForce_c 2 +#define gUseResetByDeepPowerDown_c 3 + +#if !defined(gPlatResetMethod_c) +#if defined(FPGA_SUPPORT) && (FPGA_SUPPORT == 1) +#define gPlatResetMethod_c gUseResetByNvicReset_c +#else +#define gPlatResetMethod_c gUseResetByDeepPowerDown_c +#endif +#endif + +/********************************************************************* + * Flash check for ECC error after IFR OT_CFG programming. + * + * Defaults to 1 to avoid bus fault in case of error + * Temporarily leave as 0 to before full OTA testing is done. + *********************************************************************/ +#ifndef gOtaCheckEccFaults_d +#define gOtaCheckEccFaults_d 1 +#endif + +/********************************************************************* + * NVS Sector size is necessarily a multiple of physical flash sector size. + * + * Defaults to 1 because 8kB is already pretty large. cannot exceed 8 sectors. + * + *********************************************************************/ +#ifndef gPlatNvsSectorSize_c +#define gPlatNvsSectorSize_c (PLATFORM_INTFLASH_SECTOR_SIZE * 1u) +#endif + +/********************************************************************* + * RNG source of entropy + *********************************************************************/ + +/* On wireless_mcu platform the only source of entropy disponible is the S200 */ +#ifndef gRngUseSecureSubSystem_d +#define gRngUseSecureSubSystem_d 1 +#endif + +/********************************************************************* + * SecLib + *********************************************************************/ +/* If SecLib.c is used, prevent from using LTC HW as this module is located on NBU side and is used exclusively + by Ble controller and 15.4 MAC/Phy code */ +#undef FSL_FEATURE_SOC_LTC_COUNT + +/********************************************************************* + * NBU debuggability + *********************************************************************/ +/* Enable NBU access to GPIO PORT D - This allows easier debugging when an issue is reported with a specific main core + * binary. + * \warning: Disabling this compile macro can impair the debug capability of the NBU for a specific main core binary. + * \warning: This part of code can generate bus fault when trustzone is enabled (code executed in non secure mode). + * Reason is that TRDC_IDAU_CR can not be read. In this case, user shall disable this compile macro when running + * in non secure mode. + * */ +#if !defined(gPlatformNbuDebugGpioDAccessEnabled_d) +#define gPlatformNbuDebugGpioDAccessEnabled_d 0 +#endif + +/********************************************************************* + * PLATFORM + *********************************************************************/ +/* Enable ICS RX processing in the system workqueue thread + * If enabled, the ICS will use the system workqueue to process its received data. This allows to reduce the time spent + * in the ISR and reduces impact on system activities. + * Note: the system workqueue requires a dedicated thread, so enabling this feature will consume a bit of RAM for the + * thread stack (this can be configured). + */ +#ifndef gPlatformIcsUseWorkqueueRxProcessing_d +#define gPlatformIcsUseWorkqueueRxProcessing_d 0 +#endif + +#endif /* _FWK_CONFIG_H_ */ diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/kw47_mcxw72/configs/rpmsg_config.h b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/kw47_mcxw72/configs/rpmsg_config.h new file mode 100644 index 0000000000..95a83c11bd --- /dev/null +++ b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/kw47_mcxw72/configs/rpmsg_config.h @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2014, Mentor Graphics Corporation + * All rights reserved. + * Copyright (c) 2015 Xilinx, Inc. All rights reserved. + * Copyright 2016 Freescale Semiconductor, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of Mentor Graphics Corporation nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _RPMSG_CONFIG_H +#define _RPMSG_CONFIG_H + +#include +#if defined(SDK_OS_FREE_RTOS) +#include +#endif +/* RPMsg config values */ +/* START { */ +#define RL_MS_PER_INTERVAL (1) + +#define RL_BUFFER_PAYLOAD_SIZE (496) + +#define RL_BUFFER_COUNT (4U) + +#define RL_API_HAS_ZEROCOPY (1) + +#if defined(SDK_OS_FREE_RTOS) && !(defined(configSUPPORT_STATIC_ALLOCATION) && configSUPPORT_STATIC_ALLOCATION) +#define RL_USE_STATIC_API (0) +#else +#define RL_USE_STATIC_API (1) +#endif + +#define RL_USE_MCMGR_IPC_ISR_HANDLER (1) + +#define RL_ASSERT(x) \ + do \ + { \ + if (!(x)) \ + while (true) \ + ; \ + } while (false); +/* } END */ + +#endif /* _RPMSG_CONFIG_H */ diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/kw47_mcxw72/fwk_platform_definitions.h b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/kw47_mcxw72/fwk_platform_definitions.h new file mode 100644 index 0000000000..f439345a57 --- /dev/null +++ b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/kw47_mcxw72/fwk_platform_definitions.h @@ -0,0 +1,164 @@ +/* + * Copyright 2022-2024 NXP + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _FWK_PLAT_DEFS_H_ +#define _FWK_PLAT_DEFS_H_ + +#include "fsl_device_registers.h" + +#define FWK_KW47_MCXW72_FAMILIES 1 + +#ifndef KB +#define KB(x) (((uint32_t)x) << 10u) +#endif +#ifndef MB +#define MB(x) (((uint32_t)x) << 20u) +#endif + +#define gPlatformFlashStartAddress_c (FSL_FEATURE_FLASH_PFLASH_START_ADDRESS) +#define gPlatformFlashEndAddress_c (FSL_FEATURE_FLASH_PFLASH_BLOCK_SIZE) + +/* + * External Flash geometry characteristics. SPI NOR Flash Part is AT25XE161D (16Mb) + */ +#define PLATFORM_EXTFLASH_SECTOR_SIZE KB(4U) +#define PLATFORM_EXTFLASH_PAGE_SIZE 256U +#define PLATFORM_EXTFLASH_TOTAL_SIZE MB(2U) + +#define PLATFORM_INTFLASH_SECTOR_SIZE FSL_FEATURE_FLASH_PFLASH_SECTOR_SIZE + +/* IFR has 4 sectors */ +#define IFR_SECT_ROMCFG 0u /* ROM Bootload configurations */ +#define IFR_SECT_USER 1u /* Reserved for customer usage */ +#define IFR_SECT_CMAC 2u /* Reserved CMAC */ +#define IFR_SECT_OTA_CFG 3u /* OTACFG */ +#ifndef FSL_FEATURE_IFR0_START_ADDRESS +#define FSL_FEATURE_IFR0_START_ADDRESS (0x02000000U) +#endif + +#define IFR_SECTOR_SIZE FSL_FEATURE_FLASH_PFLASH_SECTOR_SIZE + +#define IFR0_BASE FSL_FEATURE_IFR0_START_ADDRESS +//#define IFR1_BASE FSL_FEATURE_FLASH_BLOCK0_IFR1_START + +#define IFR_SECTOR_OFFSET(n) ((n)*IFR_SECTOR_SIZE) + +/* OTA CFG is in sector 3 of IFR */ +#define IFR_OTA_CFG_ADDR (IFR0_BASE + IFR_SECTOR_OFFSET(IFR_SECT_OTA_CFG)) +#define IFR_USER_ADDR (IFR0_BASE + IFR_SECTOR_OFFSET(IFR_SECT_USER)) +#define IFR_W_ONCE_DATA (IFR0_BASE + IFR_SECTOR_OFFSET(IFR_SECT_ROMCFG) + 0x1000) + +#define APP_FACTORY_DATA_MAX_LEN 0x800U +#define PROD_DATA_LEN 0x80U + +#define PROD_DATA_OFFSET 0U +#define APP_FACTORY_DATA_OFFSET (PROD_DATA_OFFSET + PROD_DATA_LEN) + +#if defined(__CC_ARM) || defined(__ARMCC_VERSION) +extern uint32_t Image$$PROD_DATA_REGION$$Base; +#define PROD_DATA_BASE_ADDR &Image$$PROD_DATA_REGION$$Base +#else +extern uint32_t PROD_DATA_BASE_ADDR[]; +#endif /* defined(__CC_ARM) */ + +#define MAIN_FLASH_PROD_DATA_ADDR ((uint32_t)PROD_DATA_BASE_ADDR) + +/* Connected MCU uses NOR Flash driver not mflash. NV storage is by default placed in internal flash */ +/* If one means to place NVS instance in external flash, need to define NV_STORAGE_EXTFLASH_START_OFFSET at the right + * offset in + * external flash. It could be done using NV_STORAGE_START_ADDRESS provided that it is defined accordingly in linker + * script */ +#ifdef NV_STORAGE_EXTFLASH_START_OFFSET +#define NV_EXTFLASH_OFFSET(offset) (NV_EXTFLASH_PHYS_ADDR(offset) - NV_STORAGE_EXTFLASH_START_OFFSET) +#define NV_STORAGE_START_OFFSET NV_STORAGE_EXTFLASH_START_OFFSET +#else +/* + * NV_STORAGE_START_ADDRESS is defined by linker script. Dwells in external flash for RW61x + */ +#define NV_STORAGE_INTFLASH_START_OFFSET ((uint32_t)NV_STORAGE_START_ADDRESS - gPlatformFlashStartAddress_c) +#define NV_STORAGE_START_OFFSET NV_STORAGE_INTFLASH_START_OFFSET +#endif + +/********************************************************************* + * RAM settings + *********************************************************************/ + +/*! Enable/Disable shutdown of ECC RAM banks during low power period like Deep Sleep or Power Down + * Shutting down ECC RAM banks allows to save about 1uA + * The RAM banks can be selectively reinitialized by calling MEM_ReinitRamBank API + * The MemoryManagerLight will call this API when allocating a new block in the heap + * Defining this flag to 0 will make the system shutdown only the non-ecc banks */ +#ifndef gPlatformShutdownEccRamInLowPower +#define gPlatformShutdownEccRamInLowPower 1 +#endif + +#define PLATFORM_ADDRESS_SECURE_MASK (0x10000000U) + +#define gPlatformRamStartAddress_c (0x20000000U) +#define gPlatformRamEndAddress_c (0x2003FFFFU) + +#define PLATFORM_CTCM0_IDX 0U +#define PLATFORM_CTCM1_IDX 1U +#define PLATFORM_STCM0_IDX 2U +#define PLATFORM_STCM1_IDX 3U +#define PLATFORM_STCM2_IDX 4U +#define PLATFORM_STCM3_IDX 5U +#define PLATFORM_STCM4_IDX 6U +#define PLATFORM_STCM5_IDX 7U +#define PLATFORM_STCM6_IDX 8U +#define PLATFORM_STCM7_IDX 9U +#define PLATFORM_STCM8_IDX 10U + +#define PLATFORM_CTCM0_START_ADDR (0x04000000U) +#define PLATFORM_CTCM0_END_ADDR (0x04003FFFU) +#define PLATFORM_CTCM1_START_ADDR (0x04004000U) +#define PLATFORM_CTCM1_END_ADDR (0x04007FFFU) +#define PLATFORM_STCM0_START_ADDR (0x20000000U) +#define PLATFORM_STCM0_END_ADDR (0x20003FFFU) +#define PLATFORM_STCM1_START_ADDR (0x20004000U) +#define PLATFORM_STCM1_END_ADDR (0x20007FFFU) +#define PLATFORM_STCM2_START_ADDR (0x20008000U) +#define PLATFORM_STCM2_END_ADDR (0x2000FFFFU) +#define PLATFORM_STCM3_START_ADDR (0x20010000U) +#define PLATFORM_STCM3_END_ADDR (0x20017FFFU) +#define PLATFORM_STCM4_START_ADDR (0x20018000U) +#define PLATFORM_STCM4_END_ADDR (0x2001FFFFU) +#define PLATFORM_STCM5_START_ADDR (0x20020000U) +#define PLATFORM_STCM5_END_ADDR (0x20027FFFU) +#define PLATFORM_STCM6_START_ADDR (0x20028000U) +#define PLATFORM_STCM6_END_ADDR (0x2002FFFFU) +#define PLATFORM_STCM7_START_ADDR (0x20030000U) +#define PLATFORM_STCM7_END_ADDR (0x20037FFFU) +#define PLATFORM_STCM8_START_ADDR (0x20038000U) +#define PLATFORM_STCM8_END_ADDR (0x20039FFFU) + +#define PLATFORM_BANK_START_ADDR \ + PLATFORM_CTCM0_START_ADDR, PLATFORM_CTCM1_START_ADDR, PLATFORM_STCM0_START_ADDR, PLATFORM_STCM1_START_ADDR, \ + PLATFORM_STCM2_START_ADDR, PLATFORM_STCM3_START_ADDR, PLATFORM_STCM4_START_ADDR, PLATFORM_STCM5_START_ADDR, \ + PLATFORM_STCM6_START_ADDR, PLATFORM_STCM7_START_ADDR, PLATFORM_STCM8_START_ADDR + +#define PLATFORM_BANK_END_ADDR \ + PLATFORM_CTCM0_END_ADDR, PLATFORM_CTCM1_END_ADDR, PLATFORM_STCM0_END_ADDR, PLATFORM_STCM1_END_ADDR, \ + PLATFORM_STCM2_END_ADDR, PLATFORM_STCM3_END_ADDR, PLATFORM_STCM4_END_ADDR, PLATFORM_STCM5_END_ADDR, \ + PLATFORM_STCM6_END_ADDR, PLATFORM_STCM7_END_ADDR, PLATFORM_STCM8_END_ADDR + +#define PLATFORM_BANK_IS_ECC TRUE, FALSE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE + +#define PLATFORM_VBAT_LDORAM_IDX PLATFORM_STCM8_IDX + +#if defined(gPlatformShutdownEccRamInLowPower) && (gPlatformShutdownEccRamInLowPower > 0) +/* In this configuration, all RAM banks can be shutdown during low power if not used + * The ECC RAM banks can be selectively reinitialized with MEM_ReinitRamBank API + * This API is also used by the Memory Manager Light */ +#define PLATFORM_SELECT_RAM_RET_START_IDX 0U +#define PLATFORM_SELECT_RAM_RET_END_IDX 10U +#else +/* STCM3, STCM4, STCM5, STCM6, STCM7 are non-ECC RAM banks*/ +#define PLATFORM_SELECT_RAM_RET_START_IDX 5U +#define PLATFORM_SELECT_RAM_RET_END_IDX 9U +#endif /* gPlatformShutdownEccRamInLowPower */ + +#endif /* _FWK_PLAT_DEFS_H_ */ diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1060/CMakeLists.txt b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1060/CMakeLists.txt deleted file mode 100644 index 5041b2ef00..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1060/CMakeLists.txt +++ /dev/null @@ -1,30 +0,0 @@ -set(SOURCES - fwk_platform.c - fwk_platform_flash.c -) - -add_library(${CONNFWK_PLATFORM_LIB} ${SOURCES}) - -# Making those includes PUBLIC will share them to the other targets linking this lib -target_include_directories(${CONNFWK_PLATFORM_LIB} - PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/../include - ${CMAKE_CURRENT_SOURCE_DIR} - configs -) - -# Get common configs from the connfwk-config interface -target_link_libraries(${CONNFWK_PLATFORM_LIB} - PRIVATE - connfwk-config - connfwk-platform-${CONNFWK_PLATFORM_FAMILY} - PUBLIC - ${CONNFWK_MCUX_SDK_LIB} -) - -if(PROJECT_IS_TOP_LEVEL) - connfwk_target_set_linker_script(${CONNFWK_PLATFORM_LIB} PUBLIC ${CONNFWK_PLATFORM_LINKER_FILE}) - # Rebuild executables if the linker script is changed - set_target_properties(connfwk-config PROPERTIES INTERFACE_LINK_DEPENDS ${CONNFWK_PLATFORM_LINKER_FILE}) - connfwk_target_generate_map_file(${CONNFWK_PLATFORM_LIB} PUBLIC ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$.map) -endif() diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1060/fwk_platform.c b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1060/fwk_platform.c deleted file mode 100644 index 484b79db07..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1060/fwk_platform.c +++ /dev/null @@ -1,81 +0,0 @@ -/* -------------------------------------------------------------------------- */ -/* Copyright 2023 NXP */ -/* All rights reserved. */ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* -------------------------------------------------------------------------- */ - -/* -------------------------------------------------------------------------- */ -/* Includes */ -/* -------------------------------------------------------------------------- */ - -#include "fwk_platform.h" -#include "fsl_adapter_time_stamp.h" -#include "fsl_clock.h" - -/* -------------------------------------------------------------------------- */ -/* Private memory */ -/* -------------------------------------------------------------------------- */ - -static TIME_STAMP_HANDLE_DEFINE(timestampHandle); -static volatile bool timerManagerInitialized = false; -static volatile bool timestampInitialized = false; - -/* -------------------------------------------------------------------------- */ -/* Public functions */ -/* -------------------------------------------------------------------------- */ - -timer_status_t PLATFORM_InitTimerManager(void) -{ - /* Initialize timer manager */ - timer_config_t timerConfig; - timer_status_t status; - - if (timerManagerInitialized == false) - { - timerConfig.instance = PLATFORM_TM_INSTANCE; - timerConfig.srcClock_Hz = CLOCK_GetFreq(kCLOCK_OscClk); - - status = TM_Init(&timerConfig); - if (status == kStatus_TimerSuccess) - { - timerManagerInitialized = true; - } - } - return status; -} - -void PLATFORM_DeinitTimerManager(void) -{ - if (timerManagerInitialized == true) - { - TM_Deinit(); - timerManagerInitialized = false; - } -} - -void PLATFORM_InitTimeStamp(void) -{ - hal_time_stamp_config_t config; - - if (timestampInitialized == false) - { - config.instance = 0U; - config.srcClock_Hz = CLOCK_GetPerClkFreq(); - - HAL_TimeStampInit(timestampHandle, &config); - - timestampInitialized = true; - } -} - -uint64_t PLATFORM_GetTimeStamp(void) -{ - return HAL_GetTimeStamp(timestampHandle); -} - -uint64_t PLATFORM_GetMaxTimeStamp(void) -{ - /* The timestamp module always converts the timer counter to microsec. As the GPT is a 32bits timer, - * and the calculations are 64 bit, no overflow is to be taken into account */ - return (uint64_t)COUNT_TO_USEC(~0UL, CLOCK_GetPerClkFreq()); -} diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1060/fwk_platform.h b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1060/fwk_platform.h deleted file mode 100644 index abaa1db3ea..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1060/fwk_platform.h +++ /dev/null @@ -1,100 +0,0 @@ -/* -------------------------------------------------------------------------- */ -/* Copyright 2022-2023 NXP */ -/* All rights reserved. */ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* -------------------------------------------------------------------------- */ - -#ifndef _FWK_PLATFORM_H_ -#define _FWK_PLATFORM_H_ - -/*! - * @addtogroup FWK_Platform_module - * The FWK_Platform module - * - * FWK_Platform module provides APIs to set platform parameters. - * @{ - */ -/*! - * @addtogroup FWK_Platform - * The FWK_Platform main module - * - * FWK_Platform main module provides APIs to set main platform parameters. - * @{ - */ - -/* -------------------------------------------------------------------------- */ -/* Includes */ -/* -------------------------------------------------------------------------- */ -#include "fsl_clock.h" -#include "fsl_component_timer_manager.h" - -/* -------------------------------------------------------------------------- */ -/* Definitions */ -/* -------------------------------------------------------------------------- */ - -/*! @brief The configuration of timer. */ - -#ifndef PLATFORM_TM_INSTANCE -#define PLATFORM_TM_INSTANCE 0 -#endif - -/* -------------------------------------------------------------------------- */ -/* Public memory declarations */ -/* -------------------------------------------------------------------------- */ - -#if defined(__cplusplus) -extern "C" { -#endif /* __cplusplus */ - -/* -------------------------------------------------------------------------- */ -/* Public functions declaration */ -/* -------------------------------------------------------------------------- */ - -/*! - * \brief Initialize Timer Manager - * - * This API will initialize the Timer Manager and the required clocks - * - */ -timer_status_t PLATFORM_InitTimerManager(void); - -/*! - * \brief Deinitialize Timer Manager - * - * This API will deinitialize the Timer Manager - * - */ -void PLATFORM_DeinitTimerManager(void); - -/*! - * \brief Initializes timestamp module - * - */ -void PLATFORM_InitTimeStamp(void); - -/*! - * \brief Returns current timestamp in us - * - * \return uint64_t timestamp in us - */ -uint64_t PLATFORM_GetTimeStamp(void); - -/*! - * \brief Returns the max timestamp value that can be returned by PLATFORM_GetTimeStamp - * Can be used by the user to handle timestamp wrapping - * - * \return uint64_t the max timestamp value - */ -uint64_t PLATFORM_GetMaxTimeStamp(void); - -#if defined(__cplusplus) -} -#endif /* __cplusplus */ - -/*! - * @} end of FWK_Platform addtogroup - */ -/*! - * @} end of FWK_Platform_module addtogroup - */ -#endif /* _FWK_PLATFORM_H_ */ \ No newline at end of file diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1060/fwk_platform_flash.c b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1060/fwk_platform_flash.c deleted file mode 100644 index 2c0c21929e..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1060/fwk_platform_flash.c +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright 2018-2022 NXP - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#include "fwk_platform_flash.h" -#include "fsl_debug_console.h" -#include "peripherals.h" -#include "fsl_os_abstraction.h" - -/******************************************************************************* - * Variables - ******************************************************************************/ - -struct lfs_mflash_ctx LittleFS_ctx = {LITTLEFS_START_ADDR}; - -static OSA_MUTEX_HANDLE_DEFINE(mLfsMutexId); - -/******************************************************************************* - * Code - ******************************************************************************/ - -int lfs_mflash_read(const struct lfs_config *lfsc, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size) -{ - struct lfs_mflash_ctx *ctx; - uint32_t flash_addr; - - assert(lfsc); - ctx = (struct lfs_mflash_ctx *)lfsc->context; - assert(ctx); - - flash_addr = ctx->start_addr + block * lfsc->block_size + off; - - if (mflash_drv_read(flash_addr, buffer, size) != kStatus_Success) - return LFS_ERR_IO; - - return LFS_ERR_OK; -} - -int lfs_mflash_prog( - const struct lfs_config *lfsc, lfs_block_t block, lfs_off_t off, const void *buffer, lfs_size_t size) -{ - status_t status = kStatus_Success; - struct lfs_mflash_ctx *ctx; - uint32_t flash_addr; - - assert(lfsc); - ctx = (struct lfs_mflash_ctx *)lfsc->context; - assert(ctx); - - flash_addr = ctx->start_addr + block * lfsc->block_size + off; - - assert(mflash_drv_is_page_aligned(size)); - - for (uint32_t page_ofs = 0; page_ofs < size; page_ofs += MFLASH_PAGE_SIZE) - { - status = mflash_drv_page_program(flash_addr + page_ofs, (void *)((uintptr_t)buffer + page_ofs)); - if (status != kStatus_Success) - break; - } - - if (status != kStatus_Success) - return LFS_ERR_IO; - - return LFS_ERR_OK; -} - -int lfs_mflash_erase(const struct lfs_config *lfsc, lfs_block_t block) -{ - status_t status = kStatus_Success; - struct lfs_mflash_ctx *ctx; - uint32_t flash_addr; - - assert(lfsc); - ctx = (struct lfs_mflash_ctx *)lfsc->context; - assert(ctx); - - flash_addr = ctx->start_addr + block * lfsc->block_size; - - for (uint32_t sector_ofs = 0; sector_ofs < lfsc->block_size; sector_ofs += MFLASH_SECTOR_SIZE) - { - status = mflash_drv_sector_erase(flash_addr + sector_ofs); - if (status != kStatus_Success) - break; - } - - if (status != kStatus_Success) - return LFS_ERR_IO; - - return LFS_ERR_OK; -} - -int lfs_mflash_sync(const struct lfs_config *lfsc) -{ - return LFS_ERR_OK; -} - -int lfs_get_default_config(struct lfs_config *lfsc) -{ - *lfsc = LittleFS_config; /* copy pre-initialized lfs config structure */ - return 0; -} - -int lfs_storage_init(const struct lfs_config *lfsc) -{ - status_t status; - - /* Mutex create */ - (void)OSA_MutexCreate(mLfsMutexId); - assert(NULL != mLfsMutexId); - - /* initialize mflash */ - status = mflash_drv_init(); - - return status; -} - -int lfs_mutex_lock(const struct lfs_config *lfsc) -{ - (void)OSA_MutexLock((osa_mutex_handle_t)mLfsMutexId, osaWaitForever_c); - - return LFS_ERR_OK; -} - -int lfs_mutex_unlock(const struct lfs_config *lfsc) -{ - (void)OSA_MutexUnlock((osa_mutex_handle_t)mLfsMutexId); - - return LFS_ERR_OK; -} diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1060/fwk_platform_flash.h b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1060/fwk_platform_flash.h deleted file mode 100644 index 7a902dd8d1..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1060/fwk_platform_flash.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2018-2022 NXP - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#ifndef _LFS_MFLASH_H_ -#define _LFS_MFLASH_H_ - -#include "lfs.h" -#include "mflash_drv.h" - -#if defined(__cplusplus) -extern "C" { -#endif /* __cplusplus */ - -struct lfs_mflash_ctx -{ - uint32_t start_addr; -}; - -extern int lfs_get_default_config(struct lfs_config *lfsc); -extern int lfs_storage_init(const struct lfs_config *lfsc); - -#if defined(__cplusplus) -} -#endif /* __cplusplus */ - -#endif diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1060/fwk_platform_ota.c b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1060/fwk_platform_ota.c deleted file mode 100644 index 88cee3fa20..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1060/fwk_platform_ota.c +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2022 NXP - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#include "fwk_platform_ota.h" -#include "FunctionLib.h" - -extern uint32_t OTA_STORAGE_SIZE[]; -#define PARTITION_SIZE ((uint32_t)OTA_STORAGE_SIZE) - -/* TODO : Define Platform Ota bootloader functions */ - -int PLATFORM_OtaUpdateBootFlags(const OtaLoaderInfo_t *ota_load_info) -{ - return 0; -} - -int PLATFORM_OtaBootDataUpdateOnCommit(const OtaLoaderInfo_t *ota_loader_info) -{ - return 0; -} - -int PLATFORM_OtaClearBootFlags(void) -{ - return 0; -} - -uint32_t PLATFORM_OtaGetImageOffset(bool internal_storage) -{ - NOT_USED(internal_storage); - return 0U; -} - -uint32_t PLATFORM_OtaGetMaxImageSize(bool internal_storage) -{ - NOT_USED(internal_storage); - return PARTITION_SIZE; -} -status_t PLATFORM_OtaGetOtaPartitionConfig(OtaPartition_t *partition, bool internal_storage) -{ - status_t st = kStatus_InvalidArgument; - NOT_USED(internal_storage); - if (partition) - { - memset(partition, 0x0, sizeof(OtaPartition_t)); -#if 0 /* TODO populate with right values */ - partition->start_offset = (uint32_t)FW_UPDATE_STORAGE_OFFSET; -#endif - - partition->size = PARTITION_SIZE; - partition->sector_size = KB(4); - st = kStatus_Success; - } - return st; -} - -void PLATFORM_InitSPIFlash(void) -{ -} - -//#endif /*(!gEnableOTAServer_d || (gEnableOTAServer_d && gUpgradeImageOnCurrentDevice_d)) */ diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1060/fwk_platform_ota.h b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1060/fwk_platform_ota.h deleted file mode 100644 index a1f0a9c138..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1060/fwk_platform_ota.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2022-2023 NXP - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#ifndef __FWK_PLATFORM_OTA_H__ -#define __FWK_PLATFORM_OTA_H__ - -#include "fsl_common.h" - -typedef struct -{ - uint32_t image_addr; /*!< Image physical address */ - uint32_t image_sz; /*!< Image size in bytes */ - bool sb_arch_in_ext_flash; /*!< Image stored in external flash */ - uint32_t spi_baudrate; /*!< SPI baudrate - only necessary if loader has to access image in external SPI flash */ - uint8_t *pBitMap; /*!< Downloaded image bitmap in flash potentiall NULL if no bit map used */ -} OtaLoaderInfo_t; - -/*! ********************************************************************************* - * \brief Boot with the Update data on commit - * - * \param[in] ota_loader_info pointer on start of the archive start address - * - * \return < 0 if error, 0 otherwise - ********************************************************************************** */ -int PLATFORM_OtaBootDataUpdateOnCommit(const OtaLoaderInfo_t *ota_loader_info); - -/*! ********************************************************************************* - * \brief Set necessary information to indicate a new image is ready after an OTA - * - * \param[in] ota_loader_info pointer on start of the archive start address - * - * \return < 0 if error, 0 otherwise - ********************************************************************************** */ -int PLATFORM_OtaUpdateBootFlags(const OtaLoaderInfo_t *ota_loader_info); - -/*! ********************************************************************************* -* \brief Post FW update clear boot flags -* -* \return -1: Flash erase procedure failed -* 0 : Erase successful and FW update succeeded -* 1 : no erase was required -* 2: erase succeeded but FW update has failed - 3: Flash was erased but update status was reporting an unexpected value -********************************************************************************** */ -int PLATFORM_OtaClearBootFlags(void); - -/*! ********************************************************************************* - * \brief Returns Image offset : leave space for BooData section when needed. - * - * \param[in] internal_storage true if OTA in internal flash, false otherwise not used - * \param[in] partition_offset offset to be added to base address to place OTA - * partition, usually 0. - * \return offset where OTA partition should start - ********************************************************************************** */ -uint32_t PLATFORM_OtaGetImageOffset(bool internal_storage, uint32_t partition_offset); - -/*! ********************************************************************************* -* \brief Returns maximum possible size of the OTAed image depends on whether the OTA -* storage is internal flash or external -* -* \param[in] internal_storage true if OTA in internal flash, false otherwise not used - -* \return Internal flash capacity minus the NVM reserved size if external OTA, half -* of that if internal flash OTA -*********************************************************************************** */ -uint32_t PLATFORM_OtaGetMaxImageSize(bool internal_storage); - -/*! ********************************************************************************* -* \brief Set pin muxing and clock to make SPI Flash module ready. - -* \return None -*********************************************************************************** */ -void PLATFORM_InitSPIFlash(void); - -/*! - * @} end of FWK_Platform_OTA - */ -/*! - * @} end of FWK_Platform_module addtogroup - */ -#endif /* __FWK_PLATFORM_OTA_H__ */ \ No newline at end of file diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1170/CMakeLists.txt b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1170/CMakeLists.txt deleted file mode 100644 index fb271a14fc..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1170/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -set(SOURCES - fwk_platform.c - fwk_platform_flash.c - fwk_platform_extflash.c - fwk_platform_ota.c -) - -set(INCLUDES - ${CMAKE_CURRENT_SOURCE_DIR} - configs -) - -add_library(${CONNFWK_PLATFORM_LIB} ${SOURCES}) - -# Making those includes PUBLIC will share them to the other targets linking this lib -target_include_directories(${CONNFWK_PLATFORM_LIB} PUBLIC ${INCLUDES}) - -# Get common configs from the connfwk-config interface -target_link_libraries(${CONNFWK_PLATFORM_LIB} - PRIVATE - connfwk-config - connfwk-platform-${CONNFWK_PLATFORM_FAMILY} - PUBLIC - ${CONNFWK_MCUX_SDK_LIB} - connfwk-FunctionLib -) - -if(PROJECT_IS_TOP_LEVEL) - connfwk_target_set_linker_script(${CONNFWK_PLATFORM_LIB} PUBLIC ${CONNFWK_PLATFORM_LINKER_FILE}) - # Rebuild executables if the linker script is changed - set_target_properties(connfwk-config PROPERTIES INTERFACE_LINK_DEPENDS ${CONNFWK_PLATFORM_LINKER_FILE}) - connfwk_target_generate_map_file(${CONNFWK_PLATFORM_LIB} PUBLIC ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$.map) -endif() diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1170/configs/fwk_config.h b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1170/configs/fwk_config.h deleted file mode 100644 index 5fce49f2d1..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1170/configs/fwk_config.h +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Copyright 2022-2023 NXP - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#ifndef _FWK_CONFIG_H_ -#define _FWK_CONFIG_H_ - -#include "fwk_platform_definitions.h" - -#endif /* _FWK_CONFIG_H_ */ diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1170/fwk_platform.c b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1170/fwk_platform.c deleted file mode 100644 index 099ac3c779..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1170/fwk_platform.c +++ /dev/null @@ -1,64 +0,0 @@ -/* -------------------------------------------------------------------------- */ -/* Copyright 2023 NXP */ -/* All rights reserved. */ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* -------------------------------------------------------------------------- */ - -/* -------------------------------------------------------------------------- */ -/* Includes */ -/* -------------------------------------------------------------------------- */ - -#include "fwk_platform.h" -#include "fsl_adapter_time_stamp.h" -#include "fsl_gpt.h" - -/* -------------------------------------------------------------------------- */ -/* Private definitions */ -/* -------------------------------------------------------------------------- */ -#define GPT_INDEX(x) ((x)-1u) - -#ifndef TIMESTAMP_GPT_INST -/* Unless otherwise defined, allocate GPT6 arbitrarily among the 6 GPT instances - * for the CM7 core timestamp. - */ -#define TIMESTAMP_GPT_INST GPT_INDEX(6) -#endif - -/* -------------------------------------------------------------------------- */ -/* Private memory */ -/* -------------------------------------------------------------------------- */ - -static TIME_STAMP_HANDLE_DEFINE(timestampHandle); -static bool timestampInitialized = false; - -/* -------------------------------------------------------------------------- */ -/* Public functions */ -/* -------------------------------------------------------------------------- */ - -void PLATFORM_InitTimeStamp(void) -{ - hal_time_stamp_config_t config; - - if (timestampInitialized == false) - { - config.instance = TIMESTAMP_GPT_INST; - config.srcClock_Hz = 32768U; /* 32kHz */ - config.clockSrcSelect = kGPT_ClockSource_LowFreq; - - HAL_TimeStampInit(timestampHandle, &config); - - timestampInitialized = true; - } -} - -uint64_t PLATFORM_GetTimeStamp(void) -{ - return HAL_GetTimeStamp(timestampHandle); -} - -uint64_t PLATFORM_GetMaxTimeStamp(void) -{ - /* The timestamp module always converts the timer counter to microsec. As the GPT is a 32bits timer, - * and the calculations are 64 bit, no overflow is to be taken into account */ - return (uint64_t)COUNT_TO_USEC(~0UL, 32768U); -} \ No newline at end of file diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1170/fwk_platform.h b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1170/fwk_platform.h deleted file mode 100644 index 27fb197e0b..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1170/fwk_platform.h +++ /dev/null @@ -1,41 +0,0 @@ -/* -------------------------------------------------------------------------- */ -/* Copyright 2023 NXP */ -/* All rights reserved. */ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* -------------------------------------------------------------------------- */ - -#ifndef _FWK_PLATFORM_H_ -#define _FWK_PLATFORM_H_ - -/* -------------------------------------------------------------------------- */ -/* Includes */ -/* -------------------------------------------------------------------------- */ - -#include - -/* -------------------------------------------------------------------------- */ -/* Public prototypes */ -/* -------------------------------------------------------------------------- */ - -/*! - * \brief Initializes timestamp module - * - */ -void PLATFORM_InitTimeStamp(void); - -/*! - * \brief Returns current timestamp in us - * - * \return uint64_t timestamp in us - */ -uint64_t PLATFORM_GetTimeStamp(void); - -/*! - * \brief Returns the max timestamp value that can be returned by PLATFORM_GetTimeStamp - * Can be used by the user to handle timestamp wrapping - * - * \return uint64_t the max timestamp value - */ -uint64_t PLATFORM_GetMaxTimeStamp(void); - -#endif /* _FWK_PLATFORM_H_ */ diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1170/fwk_platform_definitions.h b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1170/fwk_platform_definitions.h deleted file mode 100644 index d319ffb3b5..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1170/fwk_platform_definitions.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2022-2023 NXP - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#ifndef _FWK_PLAT_DEFS_H_ -#define _FWK_PLAT_DEFS_H_ - -#ifndef KB -#define KB(x) (((uint32_t)x) << 10u) -#endif -#ifndef MB -#define MB(x) (((uint32_t)x) << 20u) -#endif - -/* SPI NOR Flash is an 16MBytes on RT1170 evk */ -#define FLASH_SIZE MB(16U) - -#ifndef MFLASH_SECTOR_SIZE -#define MFLASH_SECTOR_SIZE KB(4U) -#endif - -#ifndef MFLASH_PAGE_SIZE -#define MFLASH_PAGE_SIZE 256u -#endif - -#define PLATFORM_EXTFLASH_SECTOR_SIZE MFLASH_SECTOR_SIZE -#define PLATFORM_EXTFLASH_PAGE_SIZE MFLASH_PAGE_SIZE -#define PLATFORM_EXTFLASH_TOTAL_SIZE FLASH_SIZE - -#endif /* _FWK_PLAT_DEFS_H_ */ diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1170/fwk_platform_extflash.c b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1170/fwk_platform_extflash.c deleted file mode 100644 index 4393bc51c8..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1170/fwk_platform_extflash.c +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Copyright 2018-2023 NXP - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -/* RT1170 MFLASH driver imposes that all accesses be multiple of 32 bits */ -#define PLATFORM_ACCESS_ALIGNMENT_CONSTRAINT_LOG 2u - -#include "../Common/fwk_platform_mflash.ch" diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1170/fwk_platform_flash.c b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1170/fwk_platform_flash.c deleted file mode 100644 index 2c0c21929e..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1170/fwk_platform_flash.c +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright 2018-2022 NXP - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#include "fwk_platform_flash.h" -#include "fsl_debug_console.h" -#include "peripherals.h" -#include "fsl_os_abstraction.h" - -/******************************************************************************* - * Variables - ******************************************************************************/ - -struct lfs_mflash_ctx LittleFS_ctx = {LITTLEFS_START_ADDR}; - -static OSA_MUTEX_HANDLE_DEFINE(mLfsMutexId); - -/******************************************************************************* - * Code - ******************************************************************************/ - -int lfs_mflash_read(const struct lfs_config *lfsc, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size) -{ - struct lfs_mflash_ctx *ctx; - uint32_t flash_addr; - - assert(lfsc); - ctx = (struct lfs_mflash_ctx *)lfsc->context; - assert(ctx); - - flash_addr = ctx->start_addr + block * lfsc->block_size + off; - - if (mflash_drv_read(flash_addr, buffer, size) != kStatus_Success) - return LFS_ERR_IO; - - return LFS_ERR_OK; -} - -int lfs_mflash_prog( - const struct lfs_config *lfsc, lfs_block_t block, lfs_off_t off, const void *buffer, lfs_size_t size) -{ - status_t status = kStatus_Success; - struct lfs_mflash_ctx *ctx; - uint32_t flash_addr; - - assert(lfsc); - ctx = (struct lfs_mflash_ctx *)lfsc->context; - assert(ctx); - - flash_addr = ctx->start_addr + block * lfsc->block_size + off; - - assert(mflash_drv_is_page_aligned(size)); - - for (uint32_t page_ofs = 0; page_ofs < size; page_ofs += MFLASH_PAGE_SIZE) - { - status = mflash_drv_page_program(flash_addr + page_ofs, (void *)((uintptr_t)buffer + page_ofs)); - if (status != kStatus_Success) - break; - } - - if (status != kStatus_Success) - return LFS_ERR_IO; - - return LFS_ERR_OK; -} - -int lfs_mflash_erase(const struct lfs_config *lfsc, lfs_block_t block) -{ - status_t status = kStatus_Success; - struct lfs_mflash_ctx *ctx; - uint32_t flash_addr; - - assert(lfsc); - ctx = (struct lfs_mflash_ctx *)lfsc->context; - assert(ctx); - - flash_addr = ctx->start_addr + block * lfsc->block_size; - - for (uint32_t sector_ofs = 0; sector_ofs < lfsc->block_size; sector_ofs += MFLASH_SECTOR_SIZE) - { - status = mflash_drv_sector_erase(flash_addr + sector_ofs); - if (status != kStatus_Success) - break; - } - - if (status != kStatus_Success) - return LFS_ERR_IO; - - return LFS_ERR_OK; -} - -int lfs_mflash_sync(const struct lfs_config *lfsc) -{ - return LFS_ERR_OK; -} - -int lfs_get_default_config(struct lfs_config *lfsc) -{ - *lfsc = LittleFS_config; /* copy pre-initialized lfs config structure */ - return 0; -} - -int lfs_storage_init(const struct lfs_config *lfsc) -{ - status_t status; - - /* Mutex create */ - (void)OSA_MutexCreate(mLfsMutexId); - assert(NULL != mLfsMutexId); - - /* initialize mflash */ - status = mflash_drv_init(); - - return status; -} - -int lfs_mutex_lock(const struct lfs_config *lfsc) -{ - (void)OSA_MutexLock((osa_mutex_handle_t)mLfsMutexId, osaWaitForever_c); - - return LFS_ERR_OK; -} - -int lfs_mutex_unlock(const struct lfs_config *lfsc) -{ - (void)OSA_MutexUnlock((osa_mutex_handle_t)mLfsMutexId); - - return LFS_ERR_OK; -} diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1170/fwk_platform_flash.h b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1170/fwk_platform_flash.h deleted file mode 100644 index 7a902dd8d1..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1170/fwk_platform_flash.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2018-2022 NXP - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#ifndef _LFS_MFLASH_H_ -#define _LFS_MFLASH_H_ - -#include "lfs.h" -#include "mflash_drv.h" - -#if defined(__cplusplus) -extern "C" { -#endif /* __cplusplus */ - -struct lfs_mflash_ctx -{ - uint32_t start_addr; -}; - -extern int lfs_get_default_config(struct lfs_config *lfsc); -extern int lfs_storage_init(const struct lfs_config *lfsc); - -#if defined(__cplusplus) -} -#endif /* __cplusplus */ - -#endif diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1170/fwk_platform_ota.c b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1170/fwk_platform_ota.c deleted file mode 100644 index f733318d47..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rt1170/fwk_platform_ota.c +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright 2018-2023 NXP - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ -#define FLASH_SOC_ADDR(x) (uint8_t *)(((uint32_t)x) + 0x30000000U) - -#include "../Common/fwk_platform_mcuboot_ota.ch" diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/CMakeLists.txt b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/CMakeLists.txt deleted file mode 100644 index 0d75a7fc72..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/CMakeLists.txt +++ /dev/null @@ -1,81 +0,0 @@ -set(SOURCES - fwk_platform.c - fwk_platform_ble.c - fwk_platform_lowpower.c - fwk_platform_sensors.c - fwk_platform_hdlc.c - fwk_platform_ot.c - fwk_platform_coex.c - fwk_platform_extflash.c - fwk_platform_ota.c - configs/fwk_lfs_config.c -) - -if(CONNFWK_IGNORE_PLATFORM) - list(REMOVE_ITEM SOURCES fwk_platform.c) -endif() - -if(CONNFWK_IGNORE_PLATFORM_BLE) - list(REMOVE_ITEM SOURCES fwk_platform_ble.c) -endif() - -if(CONNFWK_IGNORE_PLATFORM_LOWPOWER) - list(REMOVE_ITEM SOURCES fwk_platform_lowpower.c) -endif() - -if(CONNFWK_IGNORE_PLATFORM_SENSORS) - list(REMOVE_ITEM SOURCES fwk_platform_sensors.c) -endif() - -if(CONNFWK_IGNORE_PLATFORM_HDLC) - list(REMOVE_ITEM SOURCES fwk_platform_hdlc.c) -endif() - -if(CONNFWK_IGNORE_PLATFORM_OT) - list(REMOVE_ITEM SOURCES fwk_platform_ot.c) -endif() - -if(CONNFWK_IGNORE_PLATFORM_COEX) - list(REMOVE_ITEM SOURCES fwk_platform_coex.c) -endif() - -if(CONNFWK_IGNORE_PLATFORM_EXTFLASH) - list(REMOVE_ITEM SOURCES fwk_platform_extflash.c) -endif() - -if(CONNFWK_IGNORE_PLATFORM_OTA) - list(REMOVE_ITEM SOURCES fwk_platform_ota.c) -endif() - -add_library(${CONNFWK_PLATFORM_LIB} ${SOURCES}) - -# Making those includes PUBLIC will share them to the other targets linking this lib -target_include_directories(${CONNFWK_PLATFORM_LIB} - PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/../include - ${CMAKE_CURRENT_SOURCE_DIR} - configs -) - -# Get common configs from the connfwk-config interface -target_link_libraries(${CONNFWK_PLATFORM_LIB} - PRIVATE - connfwk-config - connfwk-FunctionLib - PUBLIC - ${CONNFWK_MCUX_SDK_LIB} -) - -if(MCUBOOT_MONOLITHIC_OTA) - target_compile_definitions(${CONNFWK_PLATFORM_LIB} - PUBLIC - gPlatformMonolithicApp_d=1 - ) -endif() - -if(PROJECT_IS_TOP_LEVEL) - connfwk_target_set_linker_script(${CONNFWK_PLATFORM_LIB} PUBLIC ${CONNFWK_PLATFORM_LINKER_FILE}) - # Rebuild executables if the linker script is changed - set_target_properties(connfwk-config PROPERTIES INTERFACE_LINK_DEPENDS ${CONNFWK_PLATFORM_LINKER_FILE}) - connfwk_target_generate_map_file(${CONNFWK_PLATFORM_LIB} PUBLIC ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$.map) -endif() diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/configs/fwk_config.h b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/configs/fwk_config.h index 26b0ea8405..2a83c39926 100644 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/configs/fwk_config.h +++ b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/configs/fwk_config.h @@ -33,6 +33,22 @@ #define gPlatformEnableTxPowerChangeWithCountry_d 0 #endif +/********************************************************************* + * gPlatformDisableLEPCTimer_d LEPC(LE power control) is a generic + * BLE feature introduced from Core5.2, LE power control timer is the + * timer initiated by controller periodically to monitor RSSI of peer + * device, and trigger power control procedure if needed, disable this + * timer can save some power consumption for BLE controller. + * + * LEPC feature will not work after disable LEPC timer since the supported + * feature bits in controller will also be cleaned. + * Defaults to 0 means not disable LEPC timer, 1 to disable LEPC timer. + * + *********************************************************************/ +#ifndef gPlatformDisableLEPCTimer_d +#define gPlatformDisableLEPCTimer_d 0 +#endif + /* * gPlatformSetAntDiversity_d * value is 0, enable ant1(share antenna with annex100),or enable ant2 with external FEM(ble only case) @@ -43,15 +59,6 @@ #define gPlatformSetAntDiversity_d 0 #endif -/* - * gBoardUseFro32k_d diversity - * value is 0, enable external XTAL32K - * value is 1, enable internal FRO32K - */ -#ifndef gBoardUseFro32k_d -#define gBoardUseFro32k_d 0 -#endif - /********************************************************************* * gPlatNvsSectorSize_c NVS Sector size is necessarily a multiple of * physical flash sector size. @@ -64,4 +71,15 @@ #define gPlatNvsSectorSize_c (PLATFORM_EXTFLASH_SECTOR_SIZE * 2u) #endif +/********************************************************************* + * gPlatformMcuBootUseRemap_d If MCU boot uses remapping, image trailers + * are expected at a different offset than when it uses swap mode. + * + * Defaults to 1. If changed to 0, MCU boot must be changed too. + * + *********************************************************************/ +#ifndef gPlatformMcuBootUseRemap_d +#define gPlatformMcuBootUseRemap_d 1 +#endif + #endif /* _FWK_CONFIG_H_ */ diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/configs/fwk_lfs_config.c b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/configs/fwk_lfs_config.c deleted file mode 100644 index f4c6d18f61..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/configs/fwk_lfs_config.c +++ /dev/null @@ -1,31 +0,0 @@ -/* -------------------------------------------------------------------------- */ -/* Copyright 2022 NXP */ -/* All rights reserved. */ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* -------------------------------------------------------------------------- */ - -/* -------------------------------------------------------------------------- */ -/* Includes */ -/* -------------------------------------------------------------------------- */ -#include "fwk_lfs_config.h" - -/* -------------------------------------------------------------------------- */ -/* Public functions */ -/* -------------------------------------------------------------------------- */ -uint32_t lfs_crc(uint32_t crc, const void *buffer, size_t size) -{ - static const uint32_t rtable[16] = { - 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac, 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c, - 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c, - }; - - const uint8_t *data = buffer; - - for (size_t i = 0; i < size; i++) - { - crc = (crc >> 4) ^ rtable[(crc ^ (data[i] >> 0)) & 0xf]; - crc = (crc >> 4) ^ rtable[(crc ^ (data[i] >> 4)) & 0xf]; - } - - return crc; -} diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/configs/fwk_lfs_config.h b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/configs/fwk_lfs_config.h deleted file mode 100644 index 8156c2b4d1..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/configs/fwk_lfs_config.h +++ /dev/null @@ -1,202 +0,0 @@ -/* -------------------------------------------------------------------------- */ -/* Copyright 2022 NXP */ -/* All rights reserved. */ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* -------------------------------------------------------------------------- */ - -#ifndef _FWK_LFS_CONFIG_ -#define _FWK_LFS_CONFIG_ - -/* -------------------------------------------------------------------------- */ -/* Includes */ -/* -------------------------------------------------------------------------- */ -#include - -#include "fsl_common.h" -#include "fsl_debug_console.h" -#include "portable.h" -#include "fwk_hal_macros.h" - -/* -------------------------------------------------------------------------- */ -/* Macros */ -/* -------------------------------------------------------------------------- */ -#ifdef LFS_DEBUG_ENABLE -#define LFS_TRACE_(fmt, ...) PRINTF("[LFS_TRACE] " fmt "%s\n", __VA_ARGS__) -#define LFS_TRACE(...) LFS_TRACE_(__VA_ARGS__, "") - -#define LFS_DEBUG_(fmt, ...) PRINTF("[LFS_DEBUG] " fmt "%s\n", __VA_ARGS__) -#define LFS_DEBUG(...) LFS_DEBUG_(__VA_ARGS__, "") - -#define LFS_WARN_(fmt, ...) PRINTF("[LFS_WARN] " fmt "%s\n", __VA_ARGS__) -#define LFS_WARN(...) LFS_WARN_(__VA_ARGS__, "") - -#define LFS_ERROR_(fmt, ...) PRINTF("[LFS_ERROR] " fmt "%s\n", __VA_ARGS__) -#define LFS_ERROR(...) LFS_ERROR_(__VA_ARGS__, "") -#else -#define LFS_TRACE(...) -#define LFS_DEBUG(...) -#define LFS_WARN(...) -#define LFS_ERROR(...) -#endif /* LFS_DEBUG_ENABLE */ - -#define LFS_ASSERT(test) assert(test) - -/* -------------------------------------------------------------------------- */ -/* Public functions */ -/* -------------------------------------------------------------------------- */ - -/* Builtin functions, these may be replaced by more efficient - * toolchain-specific implementations. LFS_NO_INTRINSICS falls back to a more - * expensive basic C implementation for debugging purposes */ - -// Min/max functions for unsigned 32-bit numbers -static inline uint32_t lfs_max(uint32_t a, uint32_t b) -{ - return (a > b) ? a : b; -} - -static inline uint32_t lfs_min(uint32_t a, uint32_t b) -{ - return (a < b) ? a : b; -} - -// Align to nearest multiple of a size -static inline uint32_t lfs_aligndown(uint32_t a, uint32_t alignment) -{ - return a - (a % alignment); -} - -static inline uint32_t lfs_alignup(uint32_t a, uint32_t alignment) -{ - return lfs_aligndown(a + alignment - 1, alignment); -} - -// Find the smallest power of 2 greater than or equal to a -static inline uint32_t lfs_npw2(uint32_t a) -{ -#if !defined(LFS_NO_INTRINSICS) && (defined(__GNUC__) || defined(__CC_ARM)) - return (32u - HAL_CLZ(a - 1)); -#else - uint32_t r = 0; - uint32_t s; - a -= 1; - s = (a > 0xffff) << 4; - a >>= s; - r |= s; - s = (a > 0xff) << 3; - a >>= s; - r |= s; - s = (a > 0xf) << 2; - a >>= s; - r |= s; - s = (a > 0x3) << 1; - a >>= s; - r |= s; - return (r | (a >> 1)) + 1; -#endif -} - -// Count the number of trailing binary zeros in a -// lfs_ctz(0) may be undefined -static inline uint32_t lfs_ctz(uint32_t a) -{ -#if !defined(LFS_NO_INTRINSICS) && defined(__GNUC__) - return (uint32_t)HAL_CTZ(a); -#else - return lfs_npw2((a & -a) + 1) - 1; -#endif -} - -// Count the number of binary ones in a -static inline uint32_t lfs_popc(uint32_t a) -{ -#if !defined(LFS_NO_INTRINSICS) && (defined(__GNUC__) || defined(__CC_ARM)) - return (uint32_t)__builtin_popcount(a); -#else - a = a - ((a >> 1) & 0x55555555); - a = (a & 0x33333333) + ((a >> 2) & 0x33333333); - return (((a + (a >> 4)) & 0xf0f0f0f) * 0x1010101) >> 24; -#endif -} - -// Find the sequence comparison of a and b, this is the distance -// between a and b ignoring overflow -static inline int lfs_scmp(uint32_t a, uint32_t b) -{ - return (int)(unsigned)(a - b); -} - -// Convert between 32-bit little-endian and native order -static inline uint32_t lfs_fromle32(uint32_t a) -{ -#if !defined(LFS_NO_INTRINSICS) && \ - ((defined(BYTE_ORDER) && defined(ORDER_LITTLE_ENDIAN) && BYTE_ORDER == ORDER_LITTLE_ENDIAN) || \ - (defined(__BYTE_ORDER) && defined(__ORDER_LITTLE_ENDIAN) && __BYTE_ORDER == __ORDER_LITTLE_ENDIAN) || \ - (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)) - return a; -#elif !defined(LFS_NO_INTRINSICS) && \ - ((defined(BYTE_ORDER) && defined(ORDER_BIG_ENDIAN) && BYTE_ORDER == ORDER_BIG_ENDIAN) || \ - (defined(__BYTE_ORDER) && defined(__ORDER_BIG_ENDIAN) && __BYTE_ORDER == __ORDER_BIG_ENDIAN) || \ - (defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)) - return HAL_REV32(a); -#else - return (((uint8_t *)&a)[0] << 0) | (((uint8_t *)&a)[1] << 8) | (((uint8_t *)&a)[2] << 16) | - (((uint8_t *)&a)[3] << 24); -#endif -} - -static inline uint32_t lfs_tole32(uint32_t a) -{ - return lfs_fromle32(a); -} - -// Convert between 32-bit big-endian and native order -static inline uint32_t lfs_frombe32(uint32_t a) -{ -#if !defined(LFS_NO_INTRINSICS) && \ - ((defined(BYTE_ORDER) && defined(ORDER_LITTLE_ENDIAN) && BYTE_ORDER == ORDER_LITTLE_ENDIAN) || \ - (defined(__BYTE_ORDER) && defined(__ORDER_LITTLE_ENDIAN) && __BYTE_ORDER == __ORDER_LITTLE_ENDIAN) || \ - (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)) - return HAL_REV32(a); -#elif !defined(LFS_NO_INTRINSICS) && \ - ((defined(BYTE_ORDER) && defined(ORDER_BIG_ENDIAN) && BYTE_ORDER == ORDER_BIG_ENDIAN) || \ - (defined(__BYTE_ORDER) && defined(__ORDER_BIG_ENDIAN) && __BYTE_ORDER == __ORDER_BIG_ENDIAN) || \ - (defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)) - return a; -#else - return (((uint8_t *)&a)[0] << 24) | (((uint8_t *)&a)[1] << 16) | (((uint8_t *)&a)[2] << 8) | - (((uint8_t *)&a)[3] << 0); -#endif -} - -static inline uint32_t lfs_tobe32(uint32_t a) -{ - return lfs_frombe32(a); -} - -// Allocate memory, only used if buffers are not provided to littlefs -// Note, memory must be 64-bit aligned -static inline void *lfs_malloc(size_t size) -{ -#ifndef LFS_NO_MALLOC - return pvPortMalloc(size); -#else - (void)size; - return NULL; -#endif -} - -// Deallocate memory, only used if buffers are not provided to littlefs -static inline void lfs_free(void *p) -{ -#ifndef LFS_NO_MALLOC - vPortFree(p); -#else - (void)p; -#endif -} - -// Calculate CRC-32 with polynomial = 0x04c11db7 -uint32_t lfs_crc(uint32_t crc, const void *buffer, size_t size); - -#endif /* _FWK_LFS_CONFIG_ */ diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform.c b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform.c deleted file mode 100644 index d150b84993..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform.c +++ /dev/null @@ -1,75 +0,0 @@ -/* -------------------------------------------------------------------------- */ -/* Copyright 2021-2023 NXP */ -/* All rights reserved. */ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* -------------------------------------------------------------------------- */ - -/* -------------------------------------------------------------------------- */ -/* Includes */ -/* -------------------------------------------------------------------------- */ - -#include - -#include "fwk_platform.h" -#include "fsl_adapter_time_stamp.h" - -/* -------------------------------------------------------------------------- */ -/* Private memory */ -/* -------------------------------------------------------------------------- */ - -static TIME_STAMP_HANDLE_DEFINE(timestampHandle); -static bool timestampInitialized = false; - -/* -------------------------------------------------------------------------- */ -/* Public functions */ -/* -------------------------------------------------------------------------- */ - -void PLATFORM_InitTimeStamp(void) -{ - hal_time_stamp_config_t config; - - if (timestampInitialized == false) - { - CLOCK_AttachClk(kCLK32K_to_OSTIMER_CLK); - - config.instance = 0; - config.srcClock_Hz = CLOCK_GetOSTimerClkFreq(); - config.clockSrcSelect = 1; - - HAL_TimeStampInit(timestampHandle, &config); - - timestampInitialized = true; - } -} - -uint64_t PLATFORM_GetTimeStamp(void) -{ - return HAL_GetTimeStamp(timestampHandle); -} - -uint64_t PLATFORM_GetMaxTimeStamp(void) -{ - /* The timestamp module always converts the timer counter to microsec - * as the OSTIMER is a 64bits timer, the conversion can overflow after a certain counter value - * So the timestamp module discards the 20 MSB to avoid this, so the max value of the counter is - * 0xFFFFFFFFFFFU */ - return (uint64_t)COUNT_TO_USEC(0xFFFFFFFFFFFU, CLOCK_GetOSTimerClkFreq()); -} - -void PLATFORM_TimeStampEnterLowPower(void) -{ - if (timestampInitialized == true) - { - HAL_TimeStampEnterLowpower(timestampHandle); - CLOCK_AttachClk(kNONE_to_OSTIMER_CLK); - } -} - -void PLATFORM_TimeStampExitPowerDown(void) -{ - if (timestampInitialized == true) - { - CLOCK_AttachClk(kCLK32K_to_OSTIMER_CLK); - HAL_TimeStampExitLowpower(timestampHandle); - } -} diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform.h b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform.h index 8c7826fc44..ad4e05ac15 100644 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform.h +++ b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform.h @@ -1,8 +1,11 @@ -/* -------------------------------------------------------------------------- */ -/* Copyright 2021-2023 NXP */ -/* All rights reserved. */ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* -------------------------------------------------------------------------- */ +/*! + * Copyright 2021-2024 NXP + * SPDX-License-Identifier: BSD-3-Clause + * + * \file fwk_platform.h + * \brief PLATFORM abstraction for general purpose use + * + */ #ifndef _FWK_PLATFORM_H_ #define _FWK_PLATFORM_H_ @@ -13,10 +16,27 @@ #include +/* -------------------------------------------------------------------------- */ +/* Public macros */ +/* -------------------------------------------------------------------------- */ + +#ifndef PLATFORM_TM_INSTANCE +#define PLATFORM_TM_INSTANCE 0U +#endif + /* -------------------------------------------------------------------------- */ /* Public prototypes */ /* -------------------------------------------------------------------------- */ +/*! + * \brief Initialize Timer Manager + * + * This API will initialize the Timer Manager and the required clocks + * + * \return int 0 if success, 1 if already initialized, negative value if error. + */ +int PLATFORM_InitTimerManager(void); + /*! * \brief Initializes timestamp module * diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_ble.c b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_ble.c index 810c4dc018..7629853190 100644 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_ble.c +++ b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_ble.c @@ -13,7 +13,7 @@ #ifndef CONFIG_PRINTK /* Zephyr already has print support */ #include "fsl_debug_console.h" -#endif /* CONFIG_PRINTK */ +#endif /* CONFIG_PRINTK */ #include "fsl_loader.h" #include "fsl_power.h" @@ -59,6 +59,9 @@ #define HCI_CMD_BT_HOST_SLEEP_CONFIG_OCF 0x59U #define HCI_CMD_BT_HOST_SLEEP_CONFIG_PARAM_LENGTH 2U +#define HCI_CMD_BT_DISABLE_LEPC_TIMER_OCF 0x9FU +#define HCI_CMD_BT_DISABLE_LEPC_CONFIG_PARAM_LENGTH 0 + #define HCI_EVT_PS_SLEEP_OCF 0x20U #define get_opcode(ocg, ocf) (((uint16_t)(ocg) & (uint16_t)0x3FU) << 10) | (uint16_t)((ocf)&0x3FFU) @@ -245,9 +248,18 @@ static int PLATFORM_HandleBlePowerStateEvent(ble_ps_event_t psEvent); */ static int PLATFORM_BleSetHostSleepConfig(void); +#if defined(gPlatformDisableLEPCTimer_d) && (gPlatformDisableLEPCTimer_d > 0) +/*! + * \brief Disable Controller LE Power Control timer and the supported feature bits + * + * \return int return status: >=0 for success, <0 for errors + */ +static int PLATFORM_DisableLEPCTimer(void); +#endif + void BLE_MCI_WAKEUP_DONE0_DriverIRQHandler(void); -static void PLATFORM_FillInHciCmdMsg(uint8_t *pbuf, uint16_t opcode, uint8_t msg_sz, const uint8_t *msg_payload); +static void PLATFORM_FillInHciCmdMsg(uint8_t *pmsg, uint16_t opcode, uint8_t msg_sz, const uint8_t *msg_payload); /* -------------------------------------------------------------------------- */ /* Private memory */ @@ -316,10 +328,10 @@ const uint8_t hci_cal_data_params[HCI_CMD_STORE_BT_CAL_DATA_PARAM_LENGTH] = { 0xF0U, // Encr_Key_Len[3:0]: MinEncrKeyLen = 0x0 // Encr_Key_Len[7:4]: MaxEncrKeyLen = 0xF #if defined(gPlatformEnableTxPowerChangeWithCountry_d) && (gPlatformEnableTxPowerChangeWithCountry_d == 0) - 0x00U, // RegionCode : 0x00 + 0x00U, // RegionCode : 0x00 #else 0x00U, // Reserved : 0x00 -#endif /* gPlatformEnableTxPowerChangeWithCountry_d */ +#endif /* gPlatformEnableTxPowerChangeWithCountry_d */ }; #if !defined(gPlatformDisableSetBtCalDataAnnex100_d) || (gPlatformDisableSetBtCalDataAnnex100_d == 0) @@ -331,17 +343,17 @@ const uint8_t hci_cal_data_params[HCI_CMD_STORE_BT_CAL_DATA_PARAM_LENGTH] = { */ const uint8_t hci_cal_data_annex100_params[HCI_CMD_STORE_BT_CAL_DATA_PARAM_ANNEX100_LENGTH] = { /* BT_HW_INFO START */ - 0x64U, // Annex Type : 0x64 - 0x00U, // CheckSum: Annex100 ignores checksum - 0x10U, // Length-In-Byte : 0x0010 - 0x00U, // Length-In-Byte : 0x0010 - 0xFFU, // Pointer for next annex structure : 0xFFFFFFFF - 0xFFU, // Pointer for next annex structure : 0xFFFFFFFF - 0xFFU, // Pointer for next annex structure : 0xFFFFFFFF - 0xFFU, // Pointer for next annex structure : 0xFFFFFFFF - 0x01U, // Ext_PA Gain : Bit[7:1] Ext_PA Present : Bit[0] + 0x64U, // Annex Type : 0x64 + 0x00U, // CheckSum: Annex100 ignores checksum + 0x10U, // Length-In-Byte : 0x0010 + 0x00U, // Length-In-Byte : 0x0010 + 0xFFU, // Pointer for next annex structure : 0xFFFFFFFF + 0xFFU, // Pointer for next annex structure : 0xFFFFFFFF + 0xFFU, // Pointer for next annex structure : 0xFFFFFFFF + 0xFFU, // Pointer for next annex structure : 0xFFFFFFFF + 0x01U, // Ext_PA Gain : Bit[7:1] Ext_PA Present : Bit[0] #if defined(gPlatformEnableTxPowerChangeWithCountry_d) && (gPlatformEnableTxPowerChangeWithCountry_d == 0) - 0x00U, // Ext_Ant Gain : Bit[4:1] Ext_Ant Present : Bit[0] + 0x00U, // Ext_Ant Gain : Bit[4:1] Ext_Ant Present : Bit[0] #else 0x00U, // Reserved #endif /* gPlatformEnableTxPowerChangeWithCountry_d */ @@ -429,6 +441,11 @@ void PLATFORM_VendorSpecificInit(void) (void)PLATFORM_BleSetHostSleepConfig(); +#if defined(gPlatformDisableLEPCTimer_d) && (gPlatformDisableLEPCTimer_d == 1) + /* Allow Controller to disable LEPC*/ + (void)PLATFORM_DisableLEPCTimer(); +#endif + #if !defined(gPlatformDisableBleLowPower_d) || (gPlatformDisableBleLowPower_d == 0) /* Allow Controller to enter low power */ (void)PLATFORM_EnableBleLowPower(); @@ -446,13 +463,14 @@ int PLATFORM_TerminateBle(void) break; } - if (PLATFORM_TerminateHciLink() != 0) + /* Power off CPU2 first */ + if (PLATFORM_TerminateControllers((uint8_t)connBle_c) != 0) /* MISRA CID 26829044 */ { ret = -1; break; } - if (PLATFORM_TerminateControllers((uint8_t)connBle_c) != 0) /* MISRA CID 26829044 */ + if (PLATFORM_TerminateHciLink() != 0) { ret = -2; break; @@ -487,7 +505,7 @@ int PLATFORM_ResetBle(void) if ((PLATFORM_GetRunningControllers() & conn802_15_4_c) != 0U) { /* Currently the CPU2 is running the combo firmware, so we should reset using this firmware */ - PLATFORM_ResetOt(); + ret = PLATFORM_ResetOt(); } else { @@ -655,6 +673,12 @@ int PLATFORM_RequestBleWakeUp(void) * completely awake and ready to receive a message */ NVIC_EnableIRQ(BLE_MCI_WAKEUP_DONE0_IRQn); + /* Make sure to clear wake up event */ + if (OSA_EventClear((osa_event_handle_t)wakeUpEventGroup, (uint32_t)ble_awake_event) != KOSA_StatusSuccess) + { + ret = -1; + } + /* Wake up BLE core with PMU BLE_WAKEUP bit * This bit is maintained until we receive a BLE_MCI_WAKEUP_DONE0 * interrupt */ @@ -680,20 +704,17 @@ int PLATFORM_RequestBleWakeUp(void) int PLATFORM_ReleaseBleWakeUp(void) { int ret = 0; - /* Nothing to do, the BLE controller awakes with a one shot interrupt from PMU - * For now, there's no mechanism to force it active for a defined period of time - * The only concern is if the CPU2 has time to re-enter sleep while CPU3 still - * needs CPU2 power domain ressources such as IMU/SMU - * TODO: Use GPIO output from CPU2 to track sleep/active periods and measure - * the minimal time before CPU2 re-enters sleep after a wake up */ + + /* Clear BLE wake up interrupt */ + PMU_DisableBleWakeup(0x1U); + NVIC_DisableIRQ(BLE_MCI_WAKEUP_DONE0_IRQn); + return ret; } void BLE_MCI_WAKEUP_DONE0_DriverIRQHandler(void) { - /* The Controller is awake, we can clear BLE wake up interrupt */ - PMU_DisableBleWakeup(0x1U); - NVIC_DisableIRQ(BLE_MCI_WAKEUP_DONE0_IRQn); + /* Nothing to do */ } int PLATFORM_HandleControllerPowerState(void) @@ -713,6 +734,11 @@ int PLATFORM_HandleControllerPowerState(void) return ret; } +bool PLATFORM_IsControllerActive(void) +{ + return ((blePowerState == ble_awake_state) && (hciInitialized == true)); +} + /* -------------------------------------------------------------------------- */ /* Private functions */ /* -------------------------------------------------------------------------- */ @@ -740,15 +766,9 @@ static int PLATFORM_TerminateHciLink(void) do { - /* Force wake up CPU2 before send IMU_MSG_CONTROL_SHUTDOWN in HAL_ImuDeinit() */ - PMU_EnableBleWakeup(0x1U); - /* Deinitialize IMU first * Ignoring return value because kStatus_HAL_ImumcError means it was already deinitialize */ - (void)HAL_ImuDeinit(kIMU_LinkCpu2Cpu3, 0); - - /* Clear CPU2 wake up bit after HAL_ImuDeinit() */ - PMU_DisableBleWakeup(0x1U); + (void)HAL_ImuDeinit(kIMU_LinkCpu2Cpu3, 1); /* Deinitialize IMUMC first */ if (HAL_ImumcDeinit(hci_imumc_handle) != kStatus_HAL_ImumcSuccess) @@ -768,6 +788,14 @@ static bool PLATFORM_IsHciLinkReady(void) static bool PLATFORM_IsBleAwake(void) { + /* The power state information of CPU2 is managed by a software state machine. + * This is an additional hardware check to make sure of the CPU2 power state + * Sending a HCI message while CPU2 is in low power causes message loss + */ + if (BLE_POWER_STATUS() != BLE_POWER_ON) + { + blePowerState = ble_asleep_state; + } return (blePowerState != ble_asleep_state); } @@ -886,15 +914,10 @@ static int PLATFORM_HandleBlePowerStateEvent(ble_ps_event_t psEvent) { case ble_asleep_event: blePowerState = ble_asleep_state; - /* Make sure to clear wake up event */ - if (OSA_EventClear((osa_event_handle_t)wakeUpEventGroup, (uint32_t)ble_awake_event) != - KOSA_StatusSuccess) - { - ret = -1; - } break; default: + /* nothing to do */ break; } } @@ -909,6 +932,7 @@ static int PLATFORM_HandleBlePowerStateEvent(ble_ps_event_t psEvent) break; default: + /* nothing to do */ break; } } @@ -945,11 +969,33 @@ static int PLATFORM_BleSetHostSleepConfig(void) return ret; } -static void PLATFORM_FillInHciCmdMsg(uint8_t *pbuf, uint16_t opcode, uint8_t msg_sz, const uint8_t *msg_payload) +#if defined(gPlatformDisableLEPCTimer_d) && (gPlatformDisableLEPCTimer_d == 1) +static int PLATFORM_DisableLEPCTimer(void) +{ + int ret = 0; + /* This command must be sent before any LE connection, likely + * after HCI init */ + uint8_t buffer[1 + HCI_CMD_PACKET_HEADER_LENGTH + HCI_CMD_BT_DISABLE_LEPC_CONFIG_PARAM_LENGTH]; + uint16_t opcode = get_opcode(HCI_CMD_VENDOR_OCG, HCI_CMD_BT_DISABLE_LEPC_TIMER_OCF); + + PLATFORM_FillInHciCmdMsg(&buffer[0], opcode, 0, NULL); + + ret = PLATFORM_SendHciMessage(buffer, sizeof(buffer)); + + if (ret != 0) + { + ret = -1; + } + + return ret; +} +#endif /* gPlatformDisableLEPCTimer_d */ + +static void PLATFORM_FillInHciCmdMsg(uint8_t *pmsg, uint16_t opcode, uint8_t msg_sz, const uint8_t *msg_payload) { - pbuf[0] = HCI_COMMAND_PACKET; - pbuf[1] = (uint8_t)(opcode & 0xff); - pbuf[2] = (uint8_t)((uint32_t)(opcode >> 8) & 0xff); - pbuf[3] = msg_sz; - (void)memcpy(&pbuf[4], msg_payload, msg_sz); + pmsg[0] = HCI_COMMAND_PACKET; + pmsg[1] = (uint8_t)(opcode & 0xffu); + pmsg[2] = (uint8_t)((opcode >> 8) & 0xffu); + pmsg[3] = msg_sz; + (void)memcpy(&pmsg[4], msg_payload, msg_sz); } diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_ble.h b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_ble.h index e33fc44a04..484fbd300f 100644 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_ble.h +++ b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_ble.h @@ -11,6 +11,7 @@ /* Includes */ /* -------------------------------------------------------------------------- */ #include +#include /* -------------------------------------------------------------------------- */ /* Public functions */ @@ -114,4 +115,12 @@ int PLATFORM_ReleaseBleWakeUp(void); */ int PLATFORM_HandleControllerPowerState(void); +/*! + * \brief Return Controller status + * + * \return true Controller is at active, and finish HCI initialization + * \return false Controller is at sleep or not do HCI initialization + */ +bool PLATFORM_IsControllerActive(void); + #endif /* _FWK_PLATFORM_BLE_H_ */ diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_coex.c b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_coex.c index d447b76eff..cf5e3599a1 100644 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_coex.c +++ b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_coex.c @@ -22,22 +22,28 @@ #endif #if (defined gPlatformMonolithicApp_d && (gPlatformMonolithicApp_d != 0)) +#define WIFI_LD_TARGET LOAD_WIFI_FIRMWARE #ifndef WIFI_FW_ADDRESS extern const uint32_t fw_cpu1[]; -#define WIFI_FW_ADDRESS (uint32_t) & fw_cpu1[0] +#define WIFI_FW_ADDRESS ((uint32_t)&fw_cpu1[0]) #endif +#define BLE_LD_TARGET LOAD_BLE_FIRMWARE #ifndef BLE_FW_ADDRESS extern const uint32_t fw_cpu2_ble[]; -#define BLE_FW_ADDRESS (uint32_t) & fw_cpu2_ble[0] +#define BLE_FW_ADDRESS ((uint32_t)&fw_cpu2_ble[0]) #endif +#define COMBO_LD_TARGET LOAD_15D4_FIRMWARE #ifndef COMBO_FW_ADDRESS extern const uint32_t fw_cpu2_combo[]; -#define COMBO_FW_ADDRESS (uint32_t) & fw_cpu2_combo[0] +#define COMBO_FW_ADDRESS ((uint32_t)&fw_cpu2_combo[0]) #endif #else #define WIFI_FW_ADDRESS 0U +#define WIFI_LD_TARGET LOAD_WIFI_FIRMWARE #define BLE_FW_ADDRESS 0U +#define BLE_LD_TARGET LOAD_BLE_FIRMWARE #define COMBO_FW_ADDRESS 0U +#define COMBO_LD_TARGET LOAD_15D4_FIRMWARE #endif /* -------------------------------------------------------------------------- */ @@ -67,7 +73,7 @@ int PLATFORM_InitControllers(uint8_t controllersMask) /* Wifi controller runs on CPU1 */ if (((protocols & connWlan_c) != 0U) && ((runningControllers & connWlan_c) == 0U)) { - if (sb3_fw_reset(LOAD_WIFI_FIRMWARE, 1, WIFI_FW_ADDRESS) != kStatus_Success) + if (sb3_fw_reset(WIFI_LD_TARGET, 1, WIFI_FW_ADDRESS) != kStatus_Success) { ret = -1; break; @@ -81,7 +87,7 @@ int PLATFORM_InitControllers(uint8_t controllersMask) if (((controllersMask & connBle_c) != 0U) && ((controllersMask & conn802_15_4_c) == 0U)) { /* BLE only */ - if (sb3_fw_reset(LOAD_BLE_FIRMWARE, 1, BLE_FW_ADDRESS) != kStatus_Success) + if (sb3_fw_reset(BLE_LD_TARGET, 1, BLE_FW_ADDRESS) != kStatus_Success) { ret = -2; break; @@ -91,7 +97,7 @@ int PLATFORM_InitControllers(uint8_t controllersMask) else { /* BLE/15.4 combo */ - if (sb3_fw_reset(LOAD_15D4_FIRMWARE, 1, COMBO_FW_ADDRESS) != kStatus_Success) + if (sb3_fw_reset(COMBO_LD_TARGET, 1, COMBO_FW_ADDRESS) != kStatus_Success) { ret = -3; break; diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_definitions.h b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_definitions.h index 7d3e2bee7b..6db18ae0af 100644 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_definitions.h +++ b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_definitions.h @@ -7,12 +7,12 @@ #ifndef _FWK_PLAT_DEFS_H_ #define _FWK_PLAT_DEFS_H_ -#include "mflash_drv.h" /* TODO remove this dependency */ +#include "mflash_drv.h" /* TODO remove this dependency */ #define PLATFORM_EXTFLASH_START_ADDR 0x08000000UL /* FlexSPI AMBA non secure */ #define PLATFORM_EXTFLASH_SECTOR_SIZE MFLASH_SECTOR_SIZE #define PLATFORM_EXTFLASH_PAGE_SIZE MFLASH_PAGE_SIZE -#define PLATFORM_EXTFLASH_TOTAL_SIZE FLASH_SIZE /* SPI NOR Flash is an MX25U51245G (512Mb) */ +#define PLATFORM_EXTFLASH_TOTAL_SIZE MFLASH_BSIZE /* SPI NOR Flash is an MX25U51245G (512Mb) */ /* * NV_STORAGE_START_ADDRESS is defined by linker script. Dwells in external flash for RW61x diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_extflash.c b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_extflash.c deleted file mode 100644 index 708d9be4c9..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_extflash.c +++ /dev/null @@ -1,8 +0,0 @@ -/* - * Copyright 2018-2023 NXP - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#include "../Common/fwk_platform_mflash.ch" diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_flash.c b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_flash.c deleted file mode 100644 index e44225d0d3..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_flash.c +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright 2018-2022 NXP - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#include "fwk_platform_flash.h" -#include "peripherals.h" -#include "fsl_os_abstraction.h" - -/******************************************************************************* - * Variables - ******************************************************************************/ - -struct lfs_mflash_ctx LittleFS_ctx = {LITTLEFS_START_ADDR}; - -static OSA_MUTEX_HANDLE_DEFINE(mLfsMutexId); - -/******************************************************************************* - * Code - ******************************************************************************/ - -int lfs_mflash_read(const struct lfs_config *lfsc, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size) -{ - struct lfs_mflash_ctx *ctx; - uint32_t flash_addr; - - assert(lfsc); - ctx = (struct lfs_mflash_ctx *)lfsc->context; - assert(ctx); - - flash_addr = ctx->start_addr + block * lfsc->block_size + off; - - if (mflash_drv_read(flash_addr, buffer, size) != kStatus_Success) - return LFS_ERR_IO; - - return LFS_ERR_OK; -} - -int lfs_mflash_prog( - const struct lfs_config *lfsc, lfs_block_t block, lfs_off_t off, const void *buffer, lfs_size_t size) -{ - status_t status = kStatus_Success; - struct lfs_mflash_ctx *ctx; - uint32_t flash_addr; - - assert(lfsc); - ctx = (struct lfs_mflash_ctx *)lfsc->context; - assert(ctx); - - flash_addr = ctx->start_addr + block * lfsc->block_size + off; - - assert(mflash_drv_is_page_aligned(size)); - - for (uint32_t page_ofs = 0; page_ofs < size; page_ofs += MFLASH_PAGE_SIZE) - { - status = mflash_drv_page_program(flash_addr + page_ofs, (void *)((uintptr_t)buffer + page_ofs)); - if (status != kStatus_Success) - break; - } - - if (status != kStatus_Success) - return LFS_ERR_IO; - - return LFS_ERR_OK; -} - -int lfs_mflash_erase(const struct lfs_config *lfsc, lfs_block_t block) -{ - status_t status = kStatus_Success; - struct lfs_mflash_ctx *ctx; - uint32_t flash_addr; - - assert(lfsc); - ctx = (struct lfs_mflash_ctx *)lfsc->context; - assert(ctx); - - flash_addr = ctx->start_addr + block * lfsc->block_size; - - for (uint32_t sector_ofs = 0; sector_ofs < lfsc->block_size; sector_ofs += MFLASH_SECTOR_SIZE) - { - status = mflash_drv_sector_erase(flash_addr + sector_ofs); - if (status != kStatus_Success) - break; - } - - if (status != kStatus_Success) - return LFS_ERR_IO; - - return LFS_ERR_OK; -} - -int lfs_mflash_sync(const struct lfs_config *lfsc) -{ - return LFS_ERR_OK; -} - -int lfs_get_default_config(struct lfs_config *lfsc) -{ - *lfsc = LittleFS_config; /* copy pre-initialized lfs config structure */ - return 0; -} - -int lfs_storage_init(const struct lfs_config *lfsc) -{ - status_t status; - - /* Mutex create */ - (void)OSA_MutexCreate(mLfsMutexId); - assert(NULL != mLfsMutexId); - - /* initialize mflash */ - status = mflash_drv_init(); - - return status; -} - -int lfs_mutex_lock(const struct lfs_config *lfsc) -{ - (void)OSA_MutexLock((osa_mutex_handle_t)mLfsMutexId, osaWaitForever_c); - - return LFS_ERR_OK; -} - -int lfs_mutex_unlock(const struct lfs_config *lfsc) -{ - (void)OSA_MutexUnlock((osa_mutex_handle_t)mLfsMutexId); - - return LFS_ERR_OK; -} diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_flash.h b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_flash.h deleted file mode 100644 index 7a902dd8d1..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_flash.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2018-2022 NXP - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#ifndef _LFS_MFLASH_H_ -#define _LFS_MFLASH_H_ - -#include "lfs.h" -#include "mflash_drv.h" - -#if defined(__cplusplus) -extern "C" { -#endif /* __cplusplus */ - -struct lfs_mflash_ctx -{ - uint32_t start_addr; -}; - -extern int lfs_get_default_config(struct lfs_config *lfsc); -extern int lfs_storage_init(const struct lfs_config *lfsc); - -#if defined(__cplusplus) -} -#endif /* __cplusplus */ - -#endif diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_hdlc.c b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_hdlc.c index 59ee25c846..793679cb19 100644 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_hdlc.c +++ b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_hdlc.c @@ -15,6 +15,8 @@ #include "fwk_platform_ble.h" #include "fwk_platform_hdlc.h" #include "fwk_platform_ot.h" + +#include "fsl_power.h" #include "fsl_adapter_imu.h" #include "fsl_os_abstraction.h" @@ -87,13 +89,13 @@ static bool PLATFORM_IsHdlcLinkReady(void); /* -------------------------------------------------------------------------- */ static platform_hdlc_rx_callback_t hdlcRxCallback; -static void * callbackParam = NULL; +static void *callbackParam = NULL; static IMUMC_HANDLE_DEFINE(hdlcImumcHandle); static const hal_imumc_config_t hdlcImumcConfig = { .local_addr = PLATFORM_HDLC_IMUMC_LOCAL_ADDR, .remote_addr = PLATFORM_HDLC_IMUMC_REMOTE_ADDR, - .imuLink = kIMU_LinkCpu2Cpu3, + .imuLink = (uint8_t)kIMU_LinkCpu2Cpu3, .callback = &PLATFORM_HdlcImumcRxCallback, .param = NULL, }; @@ -141,15 +143,13 @@ int PLATFORM_TerminateHdlcInterface(void) do { - /* Make sure the controller is awake */ - ret = PLATFORM_RequestBleWakeUp(); - if (ret != 0) + if (PLATFORM_TerminateControllers(conn802_15_4_c) != 0) { ret = -1; break; } - if (HAL_ImuDeinit(kIMU_LinkCpu2Cpu3, 0) != kStatus_HAL_ImumcSuccess) + if (HAL_ImuDeinit(kIMU_LinkCpu2Cpu3, 1) != kStatus_HAL_ImumcSuccess) { ret = -2; break; @@ -160,20 +160,6 @@ int PLATFORM_TerminateHdlcInterface(void) ret = -3; break; } - - if (PLATFORM_TerminateControllers((uint32_t)conn802_15_4_c) != 0) - { - ret = -4; - break; - } - - /* Release the wake up request now */ - ret = PLATFORM_ReleaseBleWakeUp(); - if (ret != 0) - { - ret = -5; - break; - } } while (false); return ret; @@ -198,8 +184,8 @@ int PLATFORM_SendHdlcMessage(uint8_t *msg, uint32_t len) int ret = 0; int hdlcLinkReadyRetry = 0; uint32_t remainingBytes = len; - uint8_t * pMsg = msg; - uint8_t * pImumcBuffer = NULL; + uint8_t *pMsg = msg; + uint8_t *pImumcBuffer = NULL; do { @@ -224,7 +210,7 @@ int PLATFORM_SendHdlcMessage(uint8_t *msg, uint32_t len) /* Send HDLC Packet through IMUMC channel * If the size if larger than the maximum IMUMC buffer size, we have to send chunks of the packet */ - while (remainingBytes > 0) + while (remainingBytes > 0u) { uint32_t sizeToSend; diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_lowpower.c b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_lowpower.c deleted file mode 100644 index f1aad6b40d..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_lowpower.c +++ /dev/null @@ -1,305 +0,0 @@ -/* -------------------------------------------------------------------------- */ -/* Copyright 2021-2023 NXP */ -/* All rights reserved. */ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* -------------------------------------------------------------------------- */ - -/* -------------------------------------------------------------------------- */ -/* Includes */ -/* -------------------------------------------------------------------------- */ - -#include "fwk_platform.h" -#include "fwk_config.h" -#include "fwk_platform_lowpower.h" -#include "fwk_platform_ble.h" - -/* SDK components */ -#include "fsl_pm_core.h" -#include "fsl_pm_device.h" -#include "fsl_power.h" -#include "fsl_debug_console.h" -#include "fsl_usart.h" -#include "fsl_rtc.h" -#include "fsl_os_abstraction.h" -#include "fsl_loader.h" - -/* -------------------------------------------------------------------------- */ -/* Private macros */ -/* -------------------------------------------------------------------------- */ - -#define PLATFORM_MAX_WAKE_UP_TIMER_COUNT ((uint64_t)0xFFFFU) - -/* -------------------------------------------------------------------------- */ -/* Private prototypes */ -/* -------------------------------------------------------------------------- */ - -/*! - * \brief Initializes wake up sources - * - */ -static void PLATFORM_InitWakeUpSources(void); - -/*! - * \brief Callback registered to SDK Power Manager to get notified of entry/exit of low power modes - * - * \param[in] eventType event specifying if we entered or exited from low power mode - * \param[in] powerState low power mode used during low power period - * \param[in] data Optional data passed when the callback got registered (not used currently) - * \return status_t - */ -static status_t PLATFORM_LowPowerCallback(pm_event_type_t eventType, uint8_t powerState, void *data); - -/*! - * \brief Initialize RTC to be used as a wake up source - * - */ -static void PLATFORM_InitRtc(void); - -void RTC_IRQHandler(void); - -/* -------------------------------------------------------------------------- */ -/* Private variables */ -/* -------------------------------------------------------------------------- */ - -static pm_notify_element_t platformLpNotifyGroup = { - .notifyCallback = PLATFORM_LowPowerCallback, - .data = NULL, -}; - -static pm_wakeup_source_t bleWakeUpSourceImu; -static pm_wakeup_source_t timerWakeupSource; -static pm_wakeup_source_t wlanWakeupSource; - -static uint16_t wakeUpTimerStartCount = 0U; -static uint16_t wakeUpTimerStopCount = 0U; - -static power_init_config_t initCfg = { - /* VCORE AVDD18 supplied from iBuck on RD board. */ - .iBuck = true, - /* CAU_SOC_SLP_REF_CLK not needed. */ - .gateCauRefClk = true, -}; - -static bool wasPowerDown = false; - -/* -------------------------------------------------------------------------- */ -/* Public functions */ -/* -------------------------------------------------------------------------- */ - -void PLATFORM_LowPowerInit(void) -{ - status_t status; - uint32_t resetSrc = POWER_GetResetCause(); - POWER_ClearResetCause(resetSrc); - POWER_InitPowerConfig(&initCfg); - - /* Register the low power Notify callback as high priority (kPM_NotifyGroup2) */ - status = PM_RegisterNotify(kPM_NotifyGroup2, &platformLpNotifyGroup); - assert(status == kStatus_Success); - (void)status; - - /* Init mandatory wake up sources such as BLE wake up and RTC */ - PLATFORM_InitWakeUpSources(); -} - -void PLATFORM_InitWakeUpTimer(void) -{ - /* Init RTC to be used as wake up source */ - PLATFORM_InitRtc(); - - /* Init timestamp module to measure low power duration (Only for PM0/1/2) */ - PLATFORM_InitTimeStamp(); -} - -void PLATFORM_StartWakeUpTimer(uint64_t timeOutUs) -{ - uint64_t timeOutCount = USEC_TO_COUNT(timeOutUs, 1000U); - - /* Wake up count is only coded on 16bits, so we have to be careful and handle any overlap */ - if (timeOutCount >= PLATFORM_MAX_WAKE_UP_TIMER_COUNT) - { - timeOutCount = PLATFORM_MAX_WAKE_UP_TIMER_COUNT; - } - - wakeUpTimerStartCount = (uint16_t)timeOutCount; - RTC_SetWakeupCount(RTC, wakeUpTimerStartCount); -} - -void PLATFORM_StopWakeUpTimer(void) -{ - /* MCRED-99: The RTC wake up count shall always be equal or less than the count value set in - * PLATFORM_StartWakeUpTimer as the RTC wake up timer is a count-down timer It happens this read is not correct the - * first time and we get a higher value that the initial count so it corrupts the elapsed time - * To workaround this, we make sure the count is lower than the initial value, otherwise we read again */ - do - { - wakeUpTimerStopCount = RTC_GetWakeupCount(RTC); - } while (wakeUpTimerStopCount > wakeUpTimerStartCount); - - RTC_EnableWakeupTimer(RTC, false); - RTC_ClearStatusFlags(RTC, RTC_GetStatusFlags(RTC)); - POWER_ClearWakeupStatus(RTC_IRQn); - NVIC_ClearPendingIRQ(RTC_IRQn); -} - -uint64_t PLATFORM_GetLowPowerTimestampUs(void) -{ - return PLATFORM_GetTimeStamp(); -} - -uint64_t PLATFORM_GetLowPowerDurationUs(uint64_t enterLowPowerTimestamp, uint64_t exitLowPowerTimestamp) -{ - uint64_t durationUs; - - if (wasPowerDown == true) - { - durationUs = (uint64_t)COUNT_TO_USEC((uint64_t)wakeUpTimerStartCount, 1000U) - - (uint64_t)COUNT_TO_USEC((uint64_t)wakeUpTimerStopCount, 1000U); - wasPowerDown = false; - } - else if (exitLowPowerTimestamp < enterLowPowerTimestamp) - { - durationUs = PLATFORM_GetMaxTimeStamp() - enterLowPowerTimestamp + exitLowPowerTimestamp; - } - else - { - durationUs = exitLowPowerTimestamp - enterLowPowerTimestamp; - } - - return durationUs; -} - -void PLATFORM_EnterLowPower(void) -{ - /* Placeholder RFU */ - ; -} - -void PLATFORM_ExitLowPower(void) -{ - /* Placeholder RFU */ /* MISRA CID 28201050 */ - ; -} - -void PLATFORM_EnterPowerDown(void) -{ - wasPowerDown = true; -} - -void PLATFORM_ExitPowerDown(void) -{ - POWER_InitPowerConfig(&initCfg); - PLATFORM_TimeStampExitPowerDown(); - RTC_Init(RTC); -} - -void PLATFORM_EnterDeepPowerDown(void) -{ - power_off_device(LOAD_BLE_FIRMWARE); - power_off_device(LOAD_WIFI_FIRMWARE); -} - -uint8_t PLATFORM_GetDefaultRamBanksRetained(void) -{ - uint8_t bank_mask = 0xFFU; // Retain everything by default - - return bank_mask; -} - -void PLATFORM_SetRamBanksRetained(uint8_t bank_mask) -{ -} - -void RTC_IRQHandler(void) -{ - RTC_ClearStatusFlags(RTC, RTC_GetStatusFlags(RTC)); - POWER_ClearWakeupStatus(RTC_IRQn); -} - -/* -------------------------------------------------------------------------- */ -/* Private functions */ -/* -------------------------------------------------------------------------- */ - -static void PLATFORM_InitWakeUpSources(void) -{ - /* Enable wake up source from BLE and WIFI controller (IMU interrupt) */ - PM_InitWakeupSource(&bleWakeUpSourceImu, (uint32_t)BLE_MCI_WAKEUP0_IRQn, NULL, true); - PM_InitWakeupSource(&wlanWakeupSource, (uint32_t)WL_MCI_WAKEUP0_IRQn, NULL, true); -} - -static status_t PLATFORM_LowPowerCallback(pm_event_type_t eventType, uint8_t powerState, void *data) -{ - (void)data; - - /* Nothing to do on Sleep state (WFI) but only Deeper low power mode */ - if (powerState < PLATFORM_DEEP_SLEEP_STATE) - { - /* Nothing to do when entering WFI or Sleep low power state - NVIC fully functionnal to trigger upcoming interrupts */ - } - else - { - if (eventType == kPM_EventEnteringSleep) - { - /* Platform module can implement platform specific methods to execute - * when entering and exiting any low power mode. - * Those methods should implement only mandatory procedures for the - * platform, compatible with any connectivity protocol */ - PLATFORM_EnterLowPower(); - - if (powerState >= PLATFORM_POWER_DOWN_STATE) - { - /* Power gated low power modes often require extra specific - * entry/exit low power procedures, those should be implemented - * in the following PLATFORM API */ - PLATFORM_EnterPowerDown(); - } - - if (powerState == PLATFORM_DEEP_POWER_DOWN_STATE) - { - /* Perform specific procedures when entering RAMOFF such as - * powering off the radio domain */ - PLATFORM_EnterDeepPowerDown(); - } - } - else - { - if (powerState >= PLATFORM_POWER_DOWN_STATE) - { - /* Power gated low power modes often require specific - * entry/exit low power procedures, those should be implemented - * in the following PLATFORM API */ - PLATFORM_ExitPowerDown(); - } - - /* Platform specific procedures to execute when exiting low power mode - * any low power mode */ - PLATFORM_ExitLowPower(); - } - } - - return kStatus_Success; -} - -static void PLATFORM_InitRtc(void) -{ - (void)DisableIRQ(RTC_IRQn); /* MISRA CID 28201062 */ - POWER_ClearWakeupStatus(RTC_IRQn); - POWER_DisableWakeup(RTC_IRQn); - -#if defined(gBoardUseFro32k_d) && (gBoardUseFro32k_d > 0) - CLOCK_AttachClk(kRC32K_to_CLK32K); -#else - CLOCK_EnableXtal32K(true); - CLOCK_AttachClk(kXTAL32K_to_CLK32K); -#endif - - RTC_Init(RTC); - RTC_Reset(RTC); - RTC_StartTimer(RTC); - RTC_EnableWakeUpTimerInterruptFromDPD(RTC, true); - NVIC_ClearPendingIRQ(RTC_IRQn); - - /* Enable RTC as wake up source */ - PM_InitWakeupSource(&timerWakeupSource, (uint32_t)RTC_IRQn, NULL, true); -} diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_lowpower.h b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_lowpower.h deleted file mode 100644 index c91063cce8..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_lowpower.h +++ /dev/null @@ -1,175 +0,0 @@ -/* -------------------------------------------------------------------------- */ -/* Copyright 2021-2023 NXP */ -/* All rights reserved. */ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* -------------------------------------------------------------------------- */ - -#ifndef _FWK_PLATFORM_LOWPOWER_H_ -#define _FWK_PLATFORM_LOWPOWER_H_ - -/*! - * @addtogroup FWK_Platform_module - * @{ - */ -/*! - * @addtogroup FWK_Platform_LowPower - * The FWK_Platform_LowPower module - * - * FWK_Platform_LowPower module provides APIs to handle Low Power . - * @{ - */ -/* -------------------------------------------------------------------------- */ -/* Includes */ -/* -------------------------------------------------------------------------- */ - -#include -#include "fsl_pm_device.h" - -/* -------------------------------------------------------------------------- */ -/* Public macros */ -/* -------------------------------------------------------------------------- */ - -#define PLATFORM_WFI_STATE PM_LP_STATE_PM1 -#define PLATFORM_SLEEP_STATE PM_LP_STATE_PM2 -#define PLATFORM_DEEP_SLEEP_STATE PM_LP_STATE_PM2 -#define PLATFORM_POWER_DOWN_STATE PM_LP_STATE_PM3 -#define PLATFORM_DEEP_POWER_DOWN_STATE PM_LP_STATE_PM4 - -/* No constraints in WFI mode, all peripherals are available */ -#define PLATFORM_WFI_CONSTRAINTS 0 - -/* No specific constraints necessary for Sleep (PM2) - * RAM cannot be shutdown in this mode - */ -#define PLATFORM_SLEEP_CONSTRAINTS 0 - -/* No specific constraints necessary for DeepSleep (PM2) - * RAM cannot be shutdown in this mode - */ -#define PLATFORM_DEEP_SLEEP_CONSTRAINTS 0 - -/* TODO: Remove the RAM retention constraints to use selective RAM retention mechanism */ -#define PLATFORM_POWER_DOWN_CONSTRAINTS \ - 7, PM_RESC_SRAM_0K_384K_RETENTION, PM_RESC_SRAM_384K_448K_RETENTION, PM_RESC_SRAM_448K_512K_RETENTION, \ - PM_RESC_SRAM_512K_640K_RETENTION, PM_RESC_SRAM_640K_896K_RETENTION, PM_RESC_SRAM_896K_1216K_RETENTION, \ - PM_RESC_CAU_SOC_SLP_REF_CLK_ON - -#define PLATFORM_DEEP_POWER_DOWN_CONSTRAINTS 0 - -/* -------------------------------------------------------------------------- */ -/* Public type definition */ -/* -------------------------------------------------------------------------- */ - -/* -------------------------------------------------------------------------- */ -/* Public prototypes */ -/* -------------------------------------------------------------------------- */ - -/*! - * \brief Initialize platform specific ressources for low power support - * - */ -void PLATFORM_LowPowerInit(void); - -/*! - * \brief Initialize a wake up timer - * Should be called during low power initialization. - * - */ -void PLATFORM_InitWakeUpTimer(void); - -/*! - * \brief Start a wake up timer for next tickless idle period - * Should be called during low power entry procedure. - * - * \param[in] timeOutUs maximum timeout in microsec - */ -void PLATFORM_StartWakeUpTimer(uint64_t timeOutUs); - -/*! - * \brief Stops previously started wake up timer if the tickless period ended - * earlier than expected. Should be called after exiting low power. - * - */ -void PLATFORM_StopWakeUpTimer(void); - -/*! - * \brief Returns current timestamp in us, usually called before and after tickless - * period to compute the number of ticks to update RTOS timebase. - * - * \return uint64_t Timestamp value in us - */ -uint64_t PLATFORM_GetLowPowerTimestampUs(void); - -/*! - * \brief Converts timestamp values returned by PLATFORM_GetLowPowerTimestamp to - * a duration in us and handles counter wrapping. - * - * \param[in] enterLowPowerTimestamp Timestamp measured before entering tickless period - * \param[in] exitLowPowerTimestamp Timestamp measured after exiting tickless period - * \return uint64_t Computed duration in us - */ -uint64_t PLATFORM_GetLowPowerDurationUs(uint64_t enterLowPowerTimestamp, uint64_t exitLowPowerTimestamp); - -/*! - * \brief Platform module can implement platform specific methods to execute - * when entering and exiting any low power mode. \n - * Those methods should implement only mandatory procedures for the - * platform, compatible with any connectivity protocol. - */ -void PLATFORM_EnterLowPower(void); - -/*! - * \brief Platform specific procedures to execute when exiting any low power mode - * - */ -void PLATFORM_ExitLowPower(void); - -/*! - * \brief Power gated low power modes often require specific - * entry/exit low power procedures, those should be implemented - * in the following API. - * - */ -void PLATFORM_EnterPowerDown(void); - -/*! - * \brief Power gated low power modes often require specific - * entry/exit low power procedures, those should be implemented - * in the following API. - * - */ -void PLATFORM_ExitPowerDown(void); - -/*! - * \brief Specific low power entry procedure when going to Deep Power Down mode (RAMOFF) - * - */ -void PLATFORM_EnterDeepPowerDown(void); - -/*! - * \brief Check which banks need to be retained - * \note This function is linker script specific.\n - * Amelioration handle by this function :\n - * - There is a free block at the end of the heap, so if the heap is on - * the top of the RAM. No need to retain all banks upper that the last one - * used by the heap. - * - * \return uint8_t mask of which bank needs to be retained - */ -uint8_t PLATFORM_GetDefaultRamBanksRetained(void); - -/*! - * \brief Set the banks that need to be retained in lowpower - * - * \param[in] uint8_t mask of which bank needs to be retained - */ -void PLATFORM_SetRamBanksRetained(uint8_t bank_mask); - -/*! - * @} end of FWK_Platform_LowPower addtogroup - */ -/*! - * @} end of FWK_Platform_module addtogroup - */ - -#endif /* _FWK_PLATFORM_LOWPOWER_H_ */ diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_lowpower_timer.h b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_lowpower_timer.h deleted file mode 100644 index d2d9a71c34..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_lowpower_timer.h +++ /dev/null @@ -1,10 +0,0 @@ -/* -------------------------------------------------------------------------- */ -/* Copyright 2023 NXP */ -/* All rights reserved. */ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* -------------------------------------------------------------------------- */ - -#ifndef _FWK_PLATFORM_LOWPOWER_TIMER_H_ -#define _FWK_PLATFORM_LOWPOWER_TIMER_H_ - -#endif /* _FWK_PLATFORM_LOWPOWER_TIMER_H_ */ diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_ot.c b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_ot.c index 88fe200d8d..3454c8d9f2 100644 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_ot.c +++ b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_ot.c @@ -95,12 +95,6 @@ int PLATFORM_TerminateOt(void) break; } - if (PLATFORM_TerminateControllers((uint8_t)conn802_15_4_c) != 0) - { - ret = -3; - break; - } - } while (false); return ret; diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_ota.c b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_ota.c deleted file mode 100644 index ec1db472be..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_ota.c +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright 2020 - 2023 NXP - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ -#define FLASH_SOC_ADDR(x) (uint8_t *)(((uint32_t)x) + 0x08000000U) - -#include "../Common/fwk_platform_mcuboot_ota.ch" diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_sensors.c b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_sensors.c deleted file mode 100644 index b3811e3cb9..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_sensors.c +++ /dev/null @@ -1,158 +0,0 @@ -/*! - * Copyright 2021-2022 NXP - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#include "fsl_common.h" -#include "fsl_clock.h" -#include "fsl_power.h" -#include "fsl_adc.h" - -#include "fwk_platform_sensors.h" -#include "fwk_debug.h" - -#define ADC_TS_GAIN 6295U /* 6.295f made integer arithmetics */ -#define ADC_TS_OFFSET 305U /* 305.0f */ - -/************************************************************************************ - * Private memory declarations - ************************************************************************************/ - -static bool adcInitialized = false; -static volatile bool adcDataReady = false; - -/************************************************************************************ -************************************************************************************* -* Private functions prototype -************************************************************************************* -************************************************************************************/ - -void GAU_GPADC0_INT_FUNC11_IRQHandler(void); - -/************************************************************************************ -************************************************************************************* -* Public functions -************************************************************************************* -************************************************************************************/ -bool PLATFORM_IsAdcInitialized(void) -{ - return adcInitialized; -} - -void PLATFORM_InitAdc(void) -{ - adc_config_t adcConfig; - - CLOCK_AttachClk(kMAIN_CLK_to_GAU_CLK); - CLOCK_SetClkDiv(kCLOCK_DivGauClk, 4U); - CLOCK_EnableClock(kCLOCK_Gau); - RESET_PeripheralReset(kGAU_RST_SHIFT_RSTn); - - POWER_PowerOnGau(); - - /* - * config->clockDivider = kADC_ClockDivider1; - * config->powerMode = kADC_PowerModeFullBiasingCurrent; - * config->resolution = kADC_Resolution12Bit; - * config->warmupTime = kADC_WarmUpTime16us; - * config->vrefSource = kADC_Vref1P2V; - * config->inputMode = kADC_InputSingleEnded; - * config->conversionMode = kADC_ConversionContinuous; - * config->scanLength = kADC_ScanLength_1; - * config->averageLength = kADC_AverageNone; - * config->triggerSource = kADC_TriggerSourceSoftware; - * config->inputGain = kADC_InputGain1; - * config->enableInputGainBuffer = false; - * config->resultWidth = kADC_ResultWidth16; - * config->fifoThreshold = kADC_FifoThresholdData1; - * config->enableInputBufferChop = true; - * config->enableDMA = false; - * config->enableADC = false; - */ - ADC_GetDefaultConfig(&adcConfig); - adcConfig.vrefSource = kADC_Vref1P2V; - adcConfig.inputMode = kADC_InputSingleEnded; - adcConfig.conversionMode = kADC_ConversionOneShot; - adcConfig.inputGain = kADC_InputGain1; - adcConfig.resolution = kADC_Resolution16BitAudio; - adcConfig.fifoThreshold = kADC_FifoThresholdData1; - adcConfig.scanLength = kADC_ScanLength_1; - adcConfig.averageLength = kADC_Average16; - adcConfig.enableInputGainBuffer = true; - adcConfig.enableInputBufferChop = false; - adcConfig.enableADC = true; - adcConfig.enableChop = false; - - ADC_Init(GAU_GPADC0, &adcConfig); - ADC_EnableTemperatureSensor(GAU_GPADC0, true); - ADC_SetTemperatureSensorMode(GAU_GPADC0, kADC_TSensorInternal); - - if (ADC_DoAutoCalibration(GAU_GPADC0, kADC_CalibrationVrefInternal) != kStatus_Success) - { - assert(0); - } - - ADC_ClearStatusFlags(GAU_GPADC0, (uint32_t)kADC_DataReadyInterruptFlag); - ADC_SetScanChannel(GAU_GPADC0, kADC_ScanChannel0, kADC_TEMPP); - ADC_EnableInterrupts(GAU_GPADC0, (uint32_t)kADC_DataReadyInterruptEnable); - (void)EnableIRQ(GAU_GPADC0_INT_FUNC11_IRQn); /* MISRA CID 23793822 */ - adcInitialized = true; -} - -void PLATFORM_DeinitAdc(void) -{ - adcInitialized = false; -} - -void PLATFORM_StartBatteryMonitor(void) -{ - __NOP(); /* placeholder for implemetation */ -} - -void PLATFORM_GetBatteryLevel(uint8_t *battery_level) -{ - *battery_level = 100U; -} - -void PLATFORM_StartTemperatureMonitor(void) -{ - ADC_SetScanChannel(GAU_GPADC0, kADC_ScanChannel0, kADC_TEMPP); - ADC_DoSoftwareTrigger(GAU_GPADC0); -} - -void PLATFORM_GetTemperatureValue(int32_t *temperature_value) -{ - uint32_t temperature = 0U; - uint32_t conversionResult; - - while (adcDataReady == false) - { - __NOP(); - } - - conversionResult = ADC_GetConversionResult(GAU_GPADC0); - conversionResult &= 0x0000ffffU; - temperature = conversionResult * 1000u / ADC_TS_GAIN; - temperature -= ADC_TS_OFFSET; - - adcDataReady = false; - ADC_StopConversion(GAU_GPADC0); - - *temperature_value = (int32_t)temperature; -} - -void GAU_GPADC0_INT_FUNC11_IRQHandler(void) -{ - if ((ADC_GetStatusFlags(GAU_GPADC0) & (uint32_t)kADC_DataReadyInterruptFlag) != 0UL) - { - adcDataReady = true; - ADC_ClearStatusFlags(GAU_GPADC0, (uint32_t)kADC_DataReadyInterruptFlag); - } -} - -/************************************************************************************ -************************************************************************************* -* Private functions -************************************************************************************* -************************************************************************************/ diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_sensors.h b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_sensors.h deleted file mode 100644 index 34052d6768..0000000000 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/rw61x/fwk_platform_sensors.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 2021-2022 NXP - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#ifndef _FWK_PLATFORM_SENSORS_H_ -#define _FWK_PLATFORM_SENSORS_H_ - -/*! - * @addtogroup FWK_Platform_module - * @{ - */ -/*! - * @addtogroup FWK_Platform_Sensors - * The FWK_Platform_Sensors module - * - * FWK_Platform_Sensors module provides APIs for temperature and battery measurement. - * - * \details FWK_Platform_Sensors API are used by Sensors module. - * @{ - */ - -#include - -/************************************************************************************ -************************************************************************************* -* API -************************************************************************************* -************************************************************************************/ - -/*! - * \brief Check if the ADC driver is initialized. - * - * \retval bool Is the ADC initialized or not. - * - */ -bool PLATFORM_IsAdcInitialized(void); - -/*! - * \brief Init ADC driver. - * - */ -void PLATFORM_InitAdc(void); - -/*! - * \brief Reset ADC init flag. - * - */ -void PLATFORM_DeinitAdc(void); - -/*! - * \brief Trig the ADC on the battery. - * - */ -void PLATFORM_StartBatteryMonitor(void); - -/*! - * \brief Get battery level from the ADC in percentage. - * - * \details 3V or more = 100% - * 1.8V or less = 0% - * - * \param [out] battery_level The battery level is returned by reference - */ -void PLATFORM_GetBatteryLevel(uint8_t *battery_level); - -/*! - * \brief Trig the ADC on the temperature. - * - */ -void PLATFORM_StartTemperatureMonitor(void); - -/*! - * \brief Get temperature value from the ADC, if the value change significantly the - * result is send to the CM3. - * - * \param [out] temperature_value The temperature value is returned by reference in tenths of degree celsius - */ -void PLATFORM_GetTemperatureValue(int32_t *temperature_value); - -/*! - * @} end of FWK_Platform_Sensors addtogroup - */ -/*! - * @} end of FWK_Platform_module addtogroup - */ -#endif /* _FWK_PLATFORM_SENSORS_H_ */ diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/connected_mcu/fwk_platform.c b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/wireless_mcu/fwk_platform.c similarity index 56% rename from mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/connected_mcu/fwk_platform.c rename to mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/wireless_mcu/fwk_platform.c index 9bca0dfd4c..c0b2548bf9 100644 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/connected_mcu/fwk_platform.c +++ b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/wireless_mcu/fwk_platform.c @@ -7,20 +7,26 @@ /* -------------------------------------------------------------------------- */ /* Includes */ /* -------------------------------------------------------------------------- */ +#include "fsl_os_abstraction.h" -#include #include "fwk_platform.h" +#include "fwk_config.h" #include "fwk_platform_ics.h" #if defined(FPGA_SUPPORT) && (FPGA_SUPPORT == 1) #include "fwk_platform_fpga.h" #endif -#include "fsl_os_abstraction.h" +#include "FunctionLib.h" #include "fsl_adapter_rpmsg.h" +#include "fsl_ccm32k.h" #include "fsl_spc.h" #include "rpmsg_platform.h" +#if defined(gMWS_Enabled_d) && (gMWS_Enabled_d > 0) +#include "fwk_platform_mws.h" +#endif + #include "mcmgr_imu_internal.h" /* -------------------------------------------------------------------------- */ @@ -32,27 +38,64 @@ #define FWK_PLATFORM_XTAL32M_STARTUP_TIMEOUT 1000000 #endif /* FWK_PLATFORM_XTAL32M_STARTUP_TIMEOUT */ +/*! @brief Default load capacitance config for 32KHz crystal, + can be overidden from board_platform.h, + user shall define this flag in board_platform.h file to set an other default value + Values must be adjust to minimize the jitter on the crystal. This is to avoid + a shift of 31.25us on the link layer timebase in NBU. +*/ +#if !defined(BOARD_32KHZ_XTAL_CLOAD_DEFAULT) +#define BOARD_32KHZ_XTAL_CLOAD_DEFAULT 8U +#endif + +/*! @brief Default coarse adjustement config for 32KHz crystal, + can be overidden from board_platform.h, + user shall define this flag in board_platform.h file to set an other default value + Values must be adjusted depending the equivalent series resistance (ESR) of the crystal on the board +*/ +#if !defined(BOARD_32KHZ_XTAL_COARSE_ADJ_DEFAULT) +#if defined(FWK_KW47_MCXW72_FAMILIES) && (FWK_KW47_MCXW72_FAMILIES == 1) +#define BOARD_32KHZ_XTAL_COARSE_ADJ_DEFAULT 3U +#else +#define BOARD_32KHZ_XTAL_COARSE_ADJ_DEFAULT 1U +#endif +#endif + +#if !defined(BOARD_32KHZ_XTAL_CAPACITANCE_MAX_VALUE) +#define BOARD_32KHZ_XTAL_CAPACITANCE_MAX_VALUE (uint8_t) kCCM32K_OscExtal30pFCap +#endif + /*! @brief Delay from the 32MHz wake up of the LL to wake up the radio domain in number of 30.5us period */ #if !defined(BOARD_RADIO_DOMAIN_WAKE_UP_DELAY) #define BOARD_RADIO_DOMAIN_WAKE_UP_DELAY 0x10U #endif +#if !defined(TSTMR_CLOCK_FREQUENCY_MHZ) || (TSTMR_CLOCK_FREQUENCY_MHZ != 1U) +#warning "Warning: TSTMR freq is not 1MHz !" +#endif + +/*! @brief XTAL 32Khz clock source start up timeout */ +#ifndef FWK_PLATFORM_XTAL32K_STARTUP_TIMEOUT +#define FWK_PLATFORM_XTAL32K_STARTUP_TIMEOUT 10000000 +#endif /* FWK_PLATFORM_XTAL32K_STARTUP_TIMEOUT */ + /*! @brief Remote active request timeout */ #ifndef FWK_PLATFORM_ACTIVE_REQ_TIMEOUT_US #define FWK_PLATFORM_ACTIVE_REQ_TIMEOUT_US 10000U #endif /* FWK_PLATFORM_ACTIVE_REQ_TIMEOUT_US */ /* Raise error with status update , shift previous status by 4 bits and OR with new error code. - * the returned status will be negative - * Note: this macros is defined in sss_crypto.h, we need to undef it to make sure we use our implementation */ -#undef RAISE_ERROR + * the returned status will be negative */ #define RAISE_ERROR(__st, __error_code) -(int)((uint32_t)(((uint32_t)(__st) << 4) | (uint32_t)(__error_code))); /* -------------------------------------------------------------------------- */ /* Private memory declarations */ /* -------------------------------------------------------------------------- */ -static int nbu_init = 0; +static volatile int timer_manager_initialized = 0; + +static int nbu_init = 0; +static int nbu_started = 0; /****************** LOWPOWER ***********************/ /* Number of request for CM3 to remain active */ @@ -87,8 +130,9 @@ static uint64_t u64ReadTimeStamp(void) /* -------------------------------------------------------------------------- */ int PLATFORM_IsNbuStarted(void) { - return nbu_init; + return nbu_started; } + int PLATFORM_InitNbu(void) { int status = 0; @@ -98,6 +142,15 @@ int PLATFORM_InitNbu(void) uint32_t rfmc_ctrl; int cnt = 0; +#if defined(gPlatformNbuDebugGpioDAccessEnabled_d) && (gPlatformNbuDebugGpioDAccessEnabled_d == 1) + /* Init TRDC for NBU - Allow NBU to access GPIOD*/ + trdc_non_processor_domain_assignment_t domainAssignment; + TRDC_SetDacGlobalValid(TRDC); + TRDC_GetDefaultNonProcessorDomainAssignment(&domainAssignment); + domainAssignment.privilegeAttr = (uint8_t)kTRDC_ForcePrivilege; + TRDC_SetNonProcessorDomainAssignment(TRDC, (uint8_t)kTRDC_MasterRadioNBU, &domainAssignment); +#endif + rfmc_ctrl = RFMC->RF2P4GHZ_CTRL; /* Enables BLE Power Controller on NBU side AND sets LP mode to DeepSleep */ @@ -109,6 +162,12 @@ int PLATFORM_InitNbu(void) RFMC->RF2P4GHZ_CTRL = rfmc_ctrl; RFMC->RF2P4GHZ_TIMER |= RFMC_RF2P4GHZ_TIMER_TIM_EN(0x1U); +#if defined(FWK_KW47_MCXW72_FAMILIES) && (FWK_KW47_MCXW72_FAMILIES == 1) + /* Allow the debugger to wakeup the target */ + RFMC->RF2P4GHZ_CFG |= RFMC_RF2P4GHZ_CFG_FORCE_DBG_PWRUP_ACK_MASK; + CMC0->DBGCTL &= ~CMC_DBGCTL_SOD_MASK; +#endif + /* Enabling BLE Power Controller (BLE_LP_EN) will automatically start the XTAL * According to RM, we need to wait for the XTAL to be ready before accessing * Radio domain ressources. @@ -143,22 +202,24 @@ int PLATFORM_InitMulticore(void) { int status = 0; hal_rpmsg_status_t rpmsg_status; - static bool first_call = true; - if (first_call) + + if (nbu_started == 0) { /* Write in SMU2 the static shared memory config that we have for NBU to use it */ platform_set_static_shmem_config(); } - first_call = false; - - /* Start CM3 core and Initializes the RPMSG adapter module for dual core communication */ + /* Start NBU core and Initializes the RPMSG adapter module for dual core communication */ rpmsg_status = HAL_RpmsgMcmgrInit(); if (rpmsg_status != kStatus_HAL_RpmsgSuccess) { status = RAISE_ERROR(rpmsg_status, 1); assert(0); } + else + { + nbu_started = 1; + } #if defined(FPGA_SUPPORT) && (FPGA_SUPPORT == 1) PLATFORM_InitRadio(); @@ -167,6 +228,10 @@ int PLATFORM_InitMulticore(void) return status; } +void PLATFORM_LoadHwParams(void) +{ +} + /* get 4 words of information that uniquely identifies the MCU */ void PLATFORM_GetMCUUid(uint8_t *aOutUid16B, uint8_t *pOutLen) { @@ -178,13 +243,145 @@ void PLATFORM_GetMCUUid(uint8_t *aOutUid16B, uint8_t *pOutLen) uid[2] = MSCM->UID[2]; uid[3] = MSCM->UID[3]; - memcpy(aOutUid16B, (uint8_t *)uid, sizeof(uid)); + FLib_MemCpy(aOutUid16B, (uint8_t *)uid, sizeof(uid)); /* Get the uid length */ *pOutLen = (uint8_t)sizeof(uid); return; } +int PLATFORM_InitFro32K(void) +{ + /* Enable the fro32k and select it as 32k clock source and disable osc32k + * The NBU firmware embeds a module capable of trimming the fro32k to get it as close as possible from 32768Hz + * */ + CCM32K_Enable32kFro(CCM32K, true); + CCM32K_SelectClockSource(CCM32K, kCCM32K_ClockSourceSelectFro32k); + while ((CCM32K_GetStatusFlag(CCM32K) & (uint32_t)kCCM32K_32kFroActiveStatusFlag) == 0U) + { + /* wait for the switch to fro32k to be effective before disabling osc32k */ + } + + /* Turning off the XTAL32K will indicate to the NBU that the 32K source is from FRO32K */ + CCM32K_Set32kOscConfig(CCM32K, kCCM32K_Disable32kHzCrystalOsc, NULL); + + return 0; +} + +int PLATFORM_InitOsc32K(void) +{ + int status; + uint32_t osc32k_ctrl; + uint8_t xtalCap32K = BOARD_32KHZ_XTAL_CLOAD_DEFAULT; + + status = PLATFORM_GetOscCap32KValue(&xtalCap32K); + + osc32k_ctrl = CCM32K->OSC32K_CTRL; + + /* Clear OSC32K configuration */ + osc32k_ctrl &= ~(CCM32K_OSC32K_CTRL_OSC_EN_MASK | CCM32K_OSC32K_CTRL_SOX_EN_MASK | + CCM32K_OSC32K_CTRL_CAP_SEL_EN_MASK | CCM32K_OSC32K_CTRL_XTAL_CAP_SEL_MASK | + CCM32K_OSC32K_CTRL_EXTAL_CAP_SEL_MASK | CCM32K_OSC32K_CTRL_COARSE_AMP_GAIN_MASK); + + /* Set Cload and trimming config to achieve 32768 Hz + * Tests showed about 20 - 70 ppm with this config on EVK boards */ + osc32k_ctrl |= (CCM32K_OSC32K_CTRL_XTAL_CAP_SEL(xtalCap32K) | CCM32K_OSC32K_CTRL_EXTAL_CAP_SEL(xtalCap32K)); + + /* Set amplifier gain adjustement to select external crystal ESR range */ + osc32k_ctrl &= ~(CCM32K_OSC32K_CTRL_COARSE_AMP_GAIN_MASK); + osc32k_ctrl |= CCM32K_OSC32K_CTRL_COARSE_AMP_GAIN(BOARD_32KHZ_XTAL_COARSE_ADJ_DEFAULT); + + /* Enable crystal load capacitance and SOX mode */ + osc32k_ctrl |= CCM32K_OSC32K_CTRL_CAP_SEL_EN(0x1U) | CCM32K_OSC32K_CTRL_SOX_EN(0x1U); + + CCM32K->OSC32K_CTRL = osc32k_ctrl; + + /* Enable OSC32K */ + osc32k_ctrl |= CCM32K_OSC32K_CTRL_OSC_EN(0x1U); + CCM32K->OSC32K_CTRL = osc32k_ctrl; + + return status; +} + +int PLATFORM_GetOscCap32KValue(uint8_t *xtalCap32K) +{ + return -1; +} + +int PLATFORM_SetOscCap32KValue(uint8_t xtalCap32K) +{ + return -1; +} + +int PLATFORM_SwitchToOsc32k(void) +{ + int status = 0; + int cnt = 0; + + assert((CCM32K->OSC32K_CTRL & CCM32K_OSC32K_CTRL_OSC_EN_MASK) != 0); + + do + { + /* wait for the 32k OSC to be ready */ + while ((cnt++ < FWK_PLATFORM_XTAL32K_STARTUP_TIMEOUT) && + ((CCM32K->STATUS & CCM32K_STATUS_OSC32K_RDY_MASK) == 0U)) + { + } + if (cnt > FWK_PLATFORM_XTAL32K_STARTUP_TIMEOUT) + { + status = RAISE_ERROR(status, 1); + break; + } + + CCM32K_SelectClockSource(CCM32K, kCCM32K_ClockSourceSelectOsc32k); + + /* Disable FRO32K (to save some power) */ + CCM32K->FRO32K_CTRL &= ~(CCM32K_FRO32K_CTRL_FRO_EN_MASK); + +#if 0 + /* Debug only : output 32k clock on ptc7 for frequency measurement + * (need to include fsl_port.h) */ + CLOCK_EnableClock(kCLOCK_PortC); + PORT_SetPinMux(PORTC, 7u, kPORT_MuxAlt7); + SCG0->CLKOUTCNFG = SCG_CLKOUTCNFG_CLKOUTSEL(0x4); +#endif + } while (false); + + return status; +} + +void PLATFORM_UninitOsc32K(void) +{ + ccm32k_state_t osc32k_state = CCM32K_GetCurrentState(CCM32K); + + if ((osc32k_state == kCCM32K_Only32kOscEnabled) || (osc32k_state == kCCM32K_Both32kFro32kOscEnabled)) + { + /* Disable 32k OSC */ + CCM32K->OSC32K_CTRL &= ~(CCM32K_OSC32K_CTRL_OSC_EN_MASK); + } +} + +uint8_t PLATFORM_GetXtal32MhzTrim(bool_t regRead) +{ + uint8_t xtal32MhzTrim; + xtal32MhzTrim = (uint8_t)((RFMC->XO_TEST & RFMC_XO_TEST_CDAC_MASK) >> RFMC_XO_TEST_CDAC_SHIFT); + return xtal32MhzTrim; +} + +/* Calling this function assumes HWParameters in flash have been read */ +void PLATFORM_SetXtal32MhzTrim(uint8_t trimValue, bool_t saveToHwParams) +{ +} + +int PLATFORM_InitTimerManager(void) +{ + return -1; +} + +void PLATFORM_DeinitTimerManager(void) +{ +} + uint64_t PLATFORM_GetTimeStamp(void) { /* u64ReadTimeStamp mimics TSTMR_ReadTimeStamp(TSTMR0) but copied to avoid dependency @@ -231,6 +428,24 @@ void PLATFORM_Delay(uint64_t delayUs) PLATFORM_WaitTimeout(PLATFORM_GetTimeStamp(), delayUs); } +void PLATFORM_DisableControllerLowPower(void) +{ + /* Increase active request number so it is always asserted while Controller + * is not allowed to go to low power + * This will avoid going through the wake up procedure each time + * PLATFORM_RemoteActiveReq is called + * Note: this must be called before accessing RF_CMC, as it is in NBU domain + */ + PLATFORM_RemoteActiveReq(); + + /* Disallow NBU to go to low power + * NBU FW will check this bit before going to low power + * if it is set, NBU will go to WFI only + * Note: If NBU is already in low power, this will apply to next Idle period + */ + RF_CMC1->RADIO_LP |= RF_CMC1_RADIO_LP_BLE_WKUP_MASK; +} + void PLATFORM_RemoteActiveReq(void) { OSA_InterruptDisable(); @@ -249,11 +464,11 @@ void PLATFORM_RemoteActiveReq(void) rfmc_ctrl |= RFMC_RF2P4GHZ_CTRL_LP_WKUP_DLY(0U); RFMC->RF2P4GHZ_CTRL = rfmc_ctrl; - /* CM3 writes to WKUP_TIME register to notify CM33 it's going to low + /* NBU writes to WKUP_TIME register to notify application core it's going to low * power, this is a software protocol to sync both cores */ while ((RFMC->RF2P4GHZ_MAN2 & RFMC_RF2P4GHZ_MAN2_WKUP_TIME_MASK) != 0U) { - /* CM3 started low power entry, to workaround HW issues, we need to + /* NBU started low power entry, to workaround HW issues, we need to * wait for the radio to fully enter low power before waking it up */ if ((RFMC->RF2P4GHZ_STAT & RFMC_RF2P4GHZ_STAT_BLE_STATE_MASK) == RFMC_RF2P4GHZ_STAT_BLE_STATE(0x2U)) { @@ -261,6 +476,15 @@ void PLATFORM_RemoteActiveReq(void) remote_in_lp = true; break; } + if (((RFMC->RF2P4GHZ_STAT & RFMC_RF2P4GHZ_STAT_BLE_STATE_MASK) == RFMC_RF2P4GHZ_STAT_BLE_STATE(0x3U)) || + /* Radio is currently waking up*/ + ((RFMC->RF2P4GHZ_STAT & RFMC_RF2P4GHZ_STAT_BLE_WKUP_STAT_MASK) != 0U)) + /* Radio will exit lowpower or will not be able to enter lowpower because a BLE event will soon expire */ + { + /* We can exit the loop without waiting for the NBU to re-write WKUP_TIME register, as the radio will + * not enter lowpower or is already in the wakeup procedure */ + break; + } /* Error callback set by PLATFORM_RegisterBleErrorCallback() */ if (PLATFORM_IsTimeoutExpired(timestamp, FWK_PLATFORM_ACTIVE_REQ_TIMEOUT_US) && (pfPlatformErrorCallback != NULL)) @@ -307,7 +531,6 @@ void PLATFORM_RemoteActiveReq(void) active_request_nb++; OSA_InterruptEnable(); - } void PLATFORM_RemoteActiveRel(void) @@ -328,6 +551,25 @@ void PLATFORM_RemoteActiveRel(void) OSA_InterruptEnable(); } +void PLATFORM_GetResetCause(PLATFORM_ResetStatus_t *reset_status) +{ + uint32_t SSRS_value; + SSRS_value = CMC0->SSRS; + + if (((SSRS_value & CMC_SSRS_WAKEUP_MASK) == CMC_SSRS_WAKEUP_MASK) && + !((SSRS_value & CMC_SSRS_PIN_MASK) == CMC_SSRS_PIN_MASK) && + !((SSRS_value & CMC_SSRS_DAP_MASK) == CMC_SSRS_DAP_MASK)) + { + *reset_status = PLATFORM_LowPowerWakeup; + } + else + { + *reset_status = PLATFORM_DeviceReset; + } + + CMC0->SSRS = 0xFFFFFFFFu; /* clear SSRS register */ +} + void mcmgr_imu_remote_active_rel(void) { PLATFORM_RemoteActiveRel(); diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/connected_mcu/fwk_platform.h b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/wireless_mcu/fwk_platform.h similarity index 62% rename from mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/connected_mcu/fwk_platform.h rename to mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/wireless_mcu/fwk_platform.h index 9298c42d58..59b304a693 100644 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/connected_mcu/fwk_platform.h +++ b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/wireless_mcu/fwk_platform.h @@ -1,5 +1,5 @@ /* -------------------------------------------------------------------------- */ -/* Copyright 2020-2024 NXP */ +/* Copyright 2020-2023 NXP */ /* All rights reserved. */ /* SPDX-License-Identifier: BSD-3-Clause */ /* -------------------------------------------------------------------------- */ @@ -33,6 +33,16 @@ /* Definitions */ /* -------------------------------------------------------------------------- */ +/*! + * \brief type definition for the list of reset status + * + */ +typedef enum +{ + PLATFORM_LowPowerWakeup, + PLATFORM_DeviceReset, +} PLATFORM_ResetStatus_t; + /*! * \brief type definition for the list of constraint frequency available on the nbu * @@ -98,6 +108,109 @@ int PLATFORM_InitMulticore(void); */ void PLATFORM_GetMCUUid(uint8_t *aOutUid16B, uint8_t *pOutLen); +/*! + * \brief Initialize 32K Free Running osciallator (FRO32K) and disable the XTAL 32K (osc32k) + * + * \note Turning off the XTAL32K will indicate to the NBU that the 32K source is from FRO32K. + * + * \return int 0 successful + */ +int PLATFORM_InitFro32K(void); + +/*! + * \brief Initialize 32K oscillator but doesn't select it as clock source + * To switch to 32K crystal, you need to call PLATFORM_SwitchToOsc32k() + * This allows to perform other initialization before the 32k clock is + * actually needed. Should be called as early as possible. + * + * \return int 0 if success, negative value if error. + */ +int PLATFORM_InitOsc32K(void); + +/*! + * \brief Waits for the osc32k to be ready and then selects it as 32k clock + * source. It is mandatory to call PLATFORM_InitOsc32K before, + * otherwise this function never returns. + * + * \return int 0 if success, 1 if already initialized, negative value if error. + */ +int PLATFORM_SwitchToOsc32k(void); + +/*! + * \brief Uninitialize 32K oscillator + * + */ +void PLATFORM_UninitOsc32K(void); + +/*! + * \brief Get the oscillator capacitance value set in the HWparameters. + * If no value is set it will return value by default. + * + * \param[out] pointer to the capacitance value + * + * \return int 0 if success, other if error. + */ +int PLATFORM_GetOscCap32KValue(uint8_t *xtalCap32K); + +/*! + * \brief Set in HWparameters and in CCM32K register capacitance value that we want to set. + * + * \param[in] capacitance value + * + * \return int 0 if success, other if error. + */ +int PLATFORM_SetOscCap32KValue(uint8_t xtalCap32K); + +/*! + * \brief get the XTAL trim value + * + * \param[in] regRead boolean to read value from Radio register or from HW parameters + * + * \return XTAL trim value + */ +uint8_t PLATFORM_GetXtal32MhzTrim(bool_t regRead); + +/*! + * \brief Set the XTAL trim value + * Calling this function assumes HWParameters in flash have been read + * + * \param[in] trimValue Trim value to be set + * \param[in] saveToHwParams boolean to update value in HW parameters + */ +void PLATFORM_SetXtal32MhzTrim(uint8_t trimValue, bool_t saveToHwParams); + +/*! + * \brief Update 32MHz trim value with the one stored in HW parameters. + * + */ +void PLATFORM_LoadHwParams(void); + +/*! + * \brief Initialize Timer Manager + * + * This API will initialize the Timer Manager and the required clocks + * + * \return int 0 if success, 1 if already initialized, negative value if error. + */ +int PLATFORM_InitTimerManager(void); + +/*! + * \brief Deinitialize Timer Manager + * + * This API will deinitialize the Timer Manager + * + */ +void PLATFORM_DeinitTimerManager(void); + +/*! + * \brief Disable Controller low power entry + * Depending on the platform, this can concern multiple controllers + * Controller low power is always enabled by default, so this should be + * called mainly for debug purpose + * + */ +void PLATFORM_DisableControllerLowPower(void); + /*! * \brief Request Radio domain to be active * @@ -117,6 +230,14 @@ void PLATFORM_RemoteActiveReq(void); */ void PLATFORM_RemoteActiveRel(void); +/*! + * \brief Get the reset cause, the reason why the chip is awake + * + * \param[out] reset_status Reason of the last reset + * + */ +void PLATFORM_GetResetCause(PLATFORM_ResetStatus_t *reset_status); + /*! * \brief Returns current timestamp in us * @@ -202,6 +323,17 @@ int PLATFORM_IsNbuStarted(void); */ int PLATFORM_ClearIoIsolationFromLowPower(void); +/*! + * \brief Set LowPower synchronization flag so as to notify NBU core#1 that Host core#0 + * has initiated Power Down procedure. + * + * \param[in] PwrDownOngoing, if true, write PLATFORM_HOST_USE_POWER_DOWN value if false, write 0. + * + * \return none. + * + */ +void PLATFORM_SetLowPowerFlag(bool PwrDownOngoing); + #if defined(__cplusplus) } #endif /* __cplusplus */ diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/connected_mcu/fwk_platform_ble.c b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/wireless_mcu/fwk_platform_ble.c similarity index 92% rename from mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/connected_mcu/fwk_platform_ble.c rename to mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/wireless_mcu/fwk_platform_ble.c index 739cada6ce..ec6e55e31a 100644 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/connected_mcu/fwk_platform_ble.c +++ b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/wireless_mcu/fwk_platform_ble.c @@ -1,6 +1,5 @@ /* -------------------------------------------------------------------------- */ -/* Copyright 2021-2024 NXP */ -/* All rights reserved. */ +/* Copyright 2021-2023, 2025 NXP */ /* SPDX-License-Identifier: BSD-3-Clause */ /* -------------------------------------------------------------------------- */ @@ -23,12 +22,9 @@ /* -------------------------------------------------------------------------- */ #ifndef PLATFORM_BLE_HCI_TIMEOUT_MS -#define PLATFORM_BLE_HCI_TIMEOUT_MS 500U +#define PLATFORM_BLE_HCI_TIMEOUT_MS 200U #endif -#define HciCommand(opCodeGroup, opCodeCommand) \ - (((uint16_t)(opCodeGroup) & (uint16_t)0x3FU) << (uint16_t)SHIFT10) | (uint16_t)((opCodeCommand)&0x3FFU) - /* Check if __st is negative, if true, apply 4 bits shift and add new __error_code, assert in debug and break Shall be called in a do while(0) bracket */ @@ -64,6 +60,7 @@ static const hal_rpmsg_config_t hciRpmsgConfig = { static void (*hci_rx_callback)(uint8_t packetType, uint8_t *data, uint16_t len); static bool is_initialized = false; + /* -------------------------------------------------------------------------- */ /* Public memory declarations */ /* -------------------------------------------------------------------------- */ @@ -104,6 +101,7 @@ int PLATFORM_InitBle(void) status = 1; break; } + /* When waking up from deep power down mode (following Deep power down reset), it is necessary to release IO * isolations. this is usually done in Low power initialization but it is necessay also * to be done if the Application does not support low power */ @@ -134,25 +132,23 @@ int PLATFORM_InitBle(void) CHECK_AND_RAISE_ERROR(status, -6); #endif + is_initialized = true; } while (false); /* Error callback set by PLATFORM_RegisterBleErrorCallback() */ - if ((status < 0) && (pfPlatformErrorCallback != NULL)) + if ((status != 0) && (pfPlatformErrorCallback != NULL)) { pfPlatformErrorCallback(PLATFORM_INIT_BLE_ID, status); } - is_initialized = true; return status; } int PLATFORM_SetHciRxCallback(void (*callback)(uint8_t packetType, uint8_t *data, uint16_t len)) { - int ret = 0; - hci_rx_callback = callback; - return ret; + return 0; } int PLATFORM_SendHciMessage(uint8_t *msg, uint32_t len) @@ -237,19 +233,21 @@ static int PLATFORM_InitHciLink(void) static hal_rpmsg_return_status_t PLATFORM_HciRpmsgRxCallback(void *param, uint8_t *data, uint32_t len) { - PLATFORM_RemoteActiveReq(); + /* len shall be strictly positive as message shall not be empty */ + assert((len > 0u) && (len <= (uint16_t)UINT16_MAX)); - if (hci_rx_callback != NULL) + if ((len > 0u) && (len <= (uint16_t)UINT16_MAX) && (hci_rx_callback != NULL)) { - hci_rx_callback(data[0], &data[1], len - 1U); - } + PLATFORM_RemoteActiveReq(); + + hci_rx_callback(data[0], &data[1], (uint16_t)(len - 1U)); #ifdef SERIAL_BTSNOOP - sbtsnoop_write_hci_pkt(data[0U], 1U, &data[1], len - 1U); + sbtsnoop_write_hci_pkt(data[0U], 1U, &data[1], (uint16_t)(len - 1U)); #endif - PLATFORM_RemoteActiveRel(); - + PLATFORM_RemoteActiveRel(); + } (void)param; return kStatus_HAL_RL_RELEASE; diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/connected_mcu/fwk_platform_ble.h b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/wireless_mcu/fwk_platform_ble.h similarity index 97% rename from mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/connected_mcu/fwk_platform_ble.h rename to mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/wireless_mcu/fwk_platform_ble.h index 5e384abe2b..1ab412934c 100644 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/connected_mcu/fwk_platform_ble.h +++ b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/wireless_mcu/fwk_platform_ble.h @@ -1,5 +1,5 @@ /* -------------------------------------------------------------------------- */ -/* Copyright 2021-2022,2024 NXP */ +/* Copyright 2021-2022 NXP */ /* All rights reserved. */ /* SPDX-License-Identifier: BSD-3-Clause */ /* -------------------------------------------------------------------------- */ diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/connected_mcu/fwk_platform_ics.c b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/wireless_mcu/fwk_platform_ics.c similarity index 76% rename from mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/connected_mcu/fwk_platform_ics.c rename to mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/wireless_mcu/fwk_platform_ics.c index 6bc1f91e9f..b589b4e741 100644 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/connected_mcu/fwk_platform_ics.c +++ b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/wireless_mcu/fwk_platform_ics.c @@ -1,22 +1,27 @@ /* - * Copyright 2021-2024 NXP - * All rights reserved. - * - * + * Copyright 2021-2025 NXP * SPDX-License-Identifier: BSD-3-Clause + * */ /* -------------------------------------------------------------------------- */ /* Includes */ /* -------------------------------------------------------------------------- */ -#include - #include "fsl_common.h" +#include "fwk_config.h" #include "fwk_platform_ics.h" #include "fwk_platform.h" +#include "FunctionLib.h" #include "fsl_adapter_rpmsg.h" +#if defined(gPlatformIcsUseWorkqueueRxProcessing_d) && (gPlatformIcsUseWorkqueueRxProcessing_d > 0) +#include "fwk_workq.h" +#include "fsl_component_generic_list.h" +#include "fsl_component_mem_manager.h" +#include "fwk_hal_macros.h" +#endif + #if defined(NBU_VERSION_DBG) && (NBU_VERSION_DBG == 1) #include "fsl_debug_console.h" #endif @@ -31,6 +36,25 @@ /* API wait loop counter */ #define MAX_WAIT_NBU_API_RESPONSE_LOOPS 100000000U +/* -------------------------------------------------------------------------- */ +/* Private types */ +/* -------------------------------------------------------------------------- */ + +#if defined(gPlatformIcsUseWorkqueueRxProcessing_d) && (gPlatformIcsUseWorkqueueRxProcessing_d > 0) +typedef struct +{ + list_element_t node; + uint32_t len; + uint8_t *data; +} rx_data_t; + +typedef struct +{ + fwk_work_t work; + list_label_t pending; +} rx_work_t; +#endif + /* -------------------------------------------------------------------------- */ /* Private prototypes */ /* -------------------------------------------------------------------------- */ @@ -50,6 +74,11 @@ static void PLATFORM_RxFroNotificationService(uint8_t *data, uint32_t len); static void PLATFORM_RxFwkSrvNbuIssueIndicationService(uint8_t *data, uint32_t len); static void PLATFORM_RxNbuSecurityEventIndicationService(uint8_t *data, uint32_t len); static void PLATFORM_RxNbuRequestRngSeedService(uint8_t *data, uint32_t len); +static void PLATFORM_RxNbuRequestTemperature(uint8_t *data, uint32_t len); + +#if defined(gPlatformIcsUseWorkqueueRxProcessing_d) && (gPlatformIcsUseWorkqueueRxProcessing_d > 0) +static void PLATFORM_RxWorkHandler(fwk_work_t *work); +#endif /* -------------------------------------------------------------------------- */ /* Private memory declarations */ @@ -65,7 +94,7 @@ static const hal_rpmsg_config_t fwkRpmsgConfig = { /* flag notifying of NBU Infor reception from CM3 */ static volatile bool g_nbu_info_resp_received = false; -static NbuInfo_t * g_nbu_info_p = (NbuInfo_t *)NULL; +static NbuInfo_t *g_nbu_info_p = (NbuInfo_t *)NULL; static volatile bool g_nbu_init_done = false; static uint32_t m_nbu_api_dbg_max_wait_loop = 0; /* maximum loop counter logged */ @@ -73,17 +102,18 @@ static volatile bool m_nbu_api_ind_received; static volatile bool m_nbu_api_rpmsg_status; static volatile uint32_t m_nbu_api_return_param_len; static uint8_t m_nbu_api_return_param[NBU_API_MAX_RETURN_PARAM_LENGTH]; -static nbu_memory_error_callback_t nbu_mem_error_callback = (nbu_memory_error_callback_t)NULL; -static nbu_issue_callback_t nbu_issue_callback = (nbu_issue_callback_t)NULL; -static nbu_security_event_callback_t nbu_security_event_callback = (nbu_security_event_callback_t)NULL; +static nbu_memory_error_callback_t nbu_mem_error_callback = (nbu_memory_error_callback_t)NULL; +static nbu_issue_callback_t nbu_issue_callback = (nbu_issue_callback_t)NULL; +static nbu_security_event_callback_t nbu_security_event_callback = (nbu_security_event_callback_t)NULL; +static nbu_temp_req_event_callback_t nbu_request_temperature_callback = (nbu_temp_req_event_callback_t)NULL; static const FwkSrv_LowPowerConstraintCallbacks_t *pLowPowerConstraintCallbacks = (const FwkSrv_LowPowerConstraintCallbacks_t *)NULL; -__attribute__((weak)) void RNG_TriggerReseed(void); -__attribute__((weak)) void RNG_TriggerReseed(void) +__attribute__((weak)) int RNG_NotifyReseedNeeded(void); +__attribute__((weak)) int RNG_NotifyReseedNeeded(void) { - ; /* Stub of the RNG_TriggerReseed() function */ + return 1; /* Stub of the RNG_NotifyReseedNeeded() function */ } /* Array of pointer of function used in PLATFORM_FwkSrv_RxCallBack() */ @@ -99,7 +129,15 @@ static void (*PLATFORM_RxCallbackService[gFwkSrvNbu2HostLast_c - gFwkSrvNbu2Host PLATFORM_RxFwkSrvNbuIssueIndicationService, PLATFORM_RxNbuSecurityEventIndicationService, PLATFORM_RxNbuRequestRngSeedService, + PLATFORM_RxNbuRequestTemperature, }; + +#if defined(gPlatformIcsUseWorkqueueRxProcessing_d) && (gPlatformIcsUseWorkqueueRxProcessing_d > 0) +static rx_work_t rx_work = { + .work.handler = PLATFORM_RxWorkHandler, +}; +#endif + /* -------------------------------------------------------------------------- */ /* Public functions */ /* -------------------------------------------------------------------------- */ @@ -120,11 +158,18 @@ int PLATFORM_FwkSrvInit(void) result = 1; break; } + +#if defined(gPlatformIcsUseWorkqueueRxProcessing_d) && (gPlatformIcsUseWorkqueueRxProcessing_d > 0) + LIST_Init(&rx_work.pending, 0U); + (void)WORKQ_InitSysWorkQ(); +#endif + if (kStatus_HAL_RpmsgSuccess != HAL_RpmsgInit((hal_rpmsg_handle_t)fwkRpmsgHandle, &rpmsg_config)) { result = -2; break; } + /* Flag initialization on module */ mFwkSrvInit = TRUE; } while (false); @@ -162,7 +207,7 @@ int PLATFORM_FwkSrvSendPacket(eFwkSrvMsgType msg_type, void *msg, uint16_t msg_l if (msg != NULL && msg_lg != 0U) { - memcpy(&buf[1], (uint8_t *)msg, msg_lg); + FLib_MemCpy(&buf[1], (uint8_t *)msg, msg_lg); } if (kStatus_HAL_RpmsgSuccess != HAL_RpmsgNoCopySend((hal_rpmsg_handle_t)fwkRpmsgHandle, buf, (uint32_t)sz)) @@ -367,7 +412,7 @@ bool_t PLATFORM_NbuApiReq(uint8_t *api_return, uint16_t api_id, const uint8_t *f /* API executed */ assert(m_nbu_api_return_param_len == nb_returns); - memcpy(api_return, (void *)&m_nbu_api_return_param[0], m_nbu_api_return_param_len); + FLib_MemCpy(api_return, (void *)&m_nbu_api_return_param[0], m_nbu_api_return_param_len); } while (0U != 0U); /* Release wake up to other CPU */ @@ -415,10 +460,39 @@ void PLATFORM_RegisterSecurityEventCb(nbu_security_event_callback_t cb) nbu_security_event_callback = cb; } +void PLATFORM_RegisterNbuTemperatureRequestEventCb(nbu_temp_req_event_callback_t cb) +{ +#if defined(gPlatformIcsUseWorkqueueRxProcessing_d) && (gPlatformIcsUseWorkqueueRxProcessing_d > 0) + nbu_request_temperature_callback = cb; +#else + /* NBU temperature request handling is only supported when gPlatformIcsUseWorkqueueRxProcessing_d is enabled */ + cb = NULL; +#endif +} + /* -------------------------------------------------------------------------- */ /* Private functions */ /* -------------------------------------------------------------------------- */ +#if defined(gPlatformIcsUseWorkqueueRxProcessing_d) && (gPlatformIcsUseWorkqueueRxProcessing_d > 0) +static void PLATFORM_RxWorkHandler(fwk_work_t *work) +{ + list_element_t *node; + rx_data_t *rx_data; + (void)work; + + node = LIST_RemoveHead(&rx_work.pending); + + while (node != NULL) + { + rx_data = CONTAINER_OF(node, rx_data_t, node); + PLATFORM_RxCallbackService[rx_data->data[0] - 1U](rx_data->data, rx_data->len); + (void)MEM_BufferFree(rx_data); + node = LIST_RemoveHead(&rx_work.pending); + } +} +#endif + static hal_rpmsg_return_status_t PLATFORM_FwkSrv_RxCallBack(void *param, uint8_t *data, uint32_t len) { hal_rpmsg_return_status_t res = kStatus_HAL_RL_RELEASE; @@ -427,7 +501,46 @@ static hal_rpmsg_return_status_t PLATFORM_FwkSrv_RxCallBack(void *param, uint8_t if (FwkSrv_MsgTypeInExpectedSet(msg_type)) { - PLATFORM_RxCallbackService[msg_type - 1U](data, len); +#if defined(gPlatformIcsUseWorkqueueRxProcessing_d) && (gPlatformIcsUseWorkqueueRxProcessing_d > 0) + bool process_now = false; + do + { + if ((msg_type != (uint8_t)gFwkSrvNbuVersionIndication_c) && + (msg_type != (uint8_t)gFwkSrvNbuApiIndication_c)) + { + rx_data_t *rx_data = MEM_BufferAlloc(sizeof(rx_data_t) + len); + + if (rx_data == NULL) + { + /* allocation failed - process in the ISR to avoid losing the data + * TODO: use the error callback mechanism to forward the error to the application */ + process_now = true; + break; + } + + rx_data->data = (uint8_t *)rx_data + sizeof(rx_data_t); + rx_data->len = len; + (void)memcpy(rx_data->data, data, len); + (void)LIST_AddTail(&rx_work.pending, &rx_data->node); + if (WORKQ_Submit(&rx_work.work) < 0) + { + process_now = true; + break; + } + } + else + { + process_now = true; + break; + } + } while (false); + + if (process_now == true) +#endif + { + /* some messages must be serviced in the ISR */ + PLATFORM_RxCallbackService[msg_type - 1U](data, len); + } } return res; } @@ -437,7 +550,7 @@ static void PLATFORM_RxNbuVersionIndicationService(uint8_t *data, uint32_t len) if (g_nbu_info_p != NULL) { g_nbu_info_resp_received = true; - memcpy(g_nbu_info_p, &data[1], sizeof(NbuInfo_t)); + FLib_MemCpy(g_nbu_info_p, &data[1], sizeof(NbuInfo_t)); #if defined(NBU_VERSION_DBG) && (NBU_VERSION_DBG == 1) PRINTF("NBU v%d.%d.%d\r\n", g_nbu_info_p->versionNumber[0], g_nbu_info_p->versionNumber[1], @@ -465,7 +578,7 @@ static void PLATFORM_RxNbuMemFullIndicationService(uint8_t *data, uint32_t len) if (nbu_mem_error_callback != NULL) { NbuDbgMemInfo_t memInfo; - memcpy(&memInfo, &data[1], sizeof(NbuDbgMemInfo_t)); + FLib_MemCpy(&memInfo, &data[1], sizeof(NbuDbgMemInfo_t)); (*nbu_mem_error_callback)((void *)&memInfo); } NOT_USED(len); @@ -479,7 +592,7 @@ static void PLATFORM_RxNbuApiIndicationService(uint8_t *data, uint32_t len) m_nbu_api_rpmsg_status = (data[1] == 0U) ? false : true; m_nbu_api_return_param_len = len - 2U; - memcpy((void *)&m_nbu_api_return_param[0U], &data[2U], m_nbu_api_return_param_len); + FLib_MemCpy((void *)&m_nbu_api_return_param[0U], &data[2U], m_nbu_api_return_param_len); } static void PLATFORM_RxHostSetLowPowerConstraintService(uint8_t *data, uint32_t len) @@ -515,6 +628,7 @@ static void PLATFORM_RxFroNotificationService(uint8_t *data, uint32_t len) pfPlatformDebugCallback(freq, (int16_t)ppm_mean, (int16_t)ppm, fro_trim); NOT_USED(len); } + static void PLATFORM_RxFwkSrvNbuIssueIndicationService(uint8_t *data, uint32_t len) { if (nbu_issue_callback != NULL) @@ -530,7 +644,7 @@ static void PLATFORM_RxNbuSecurityEventIndicationService(uint8_t *data, uint32_t if (nbu_security_event_callback != NULL) { uint32_t securityEventBitmask; - memcpy(&securityEventBitmask, &data[1], sizeof(uint32_t)); + FLib_MemCpy(&securityEventBitmask, &data[1], sizeof(uint32_t)); (*nbu_security_event_callback)(securityEventBitmask); } NOT_USED(len); @@ -538,11 +652,25 @@ static void PLATFORM_RxNbuSecurityEventIndicationService(uint8_t *data, uint32_t static void PLATFORM_RxNbuRequestRngSeedService(uint8_t *data, uint32_t len) { - RNG_TriggerReseed(); + RNG_NotifyReseedNeeded(); NOT_USED(data); NOT_USED(len); } +static void PLATFORM_RxNbuRequestTemperature(uint8_t *data, uint32_t len) +{ + if (nbu_request_temperature_callback != NULL) + { + assert(len == (sizeof(uint32_t) + 1)); + /* Data buffer can contain a periodic interval parameter + * Ignoring this data as periodic measurement is not supported yet + */ + (*nbu_request_temperature_callback)(0U); + } + (void)len; + (void)data; +} + static bool FwkSrv_MsgTypeInExpectedSet(uint8_t msg_type) { return (msg_type > (uint8_t)gFwkSrvNbu2HostFirst_c && msg_type < (uint8_t)gFwkSrvNbu2HostLast_c); diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/connected_mcu/fwk_platform_ics.h b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/wireless_mcu/fwk_platform_ics.h similarity index 93% rename from mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/connected_mcu/fwk_platform_ics.h rename to mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/wireless_mcu/fwk_platform_ics.h index 436018f052..e29500c920 100644 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/connected_mcu/fwk_platform_ics.h +++ b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/wireless_mcu/fwk_platform_ics.h @@ -1,7 +1,5 @@ /* - * Copyright 2021-2022, 2024 NXP - * All rights reserved. - * + * Copyright 2021-2025 NXP * * SPDX-License-Identifier: BSD-3-Clause */ @@ -90,7 +88,8 @@ typedef enum gFwkSrvNbuIssueIndication_c = 0x8U, gFwkSrvNbuSecurityEventIndication_c = 0x9U, gFwkSrvNbuRequestRngSeed_c = 0xAU, - gFwkSrvNbu2HostLast_c = 0xBU, + gFwkSrvNbuRequestNewTemperature_c = 0xBU, + gFwkSrvNbu2HostLast_c = 0xCU, gFwkSrvHost2NbuFirst_c = 0x80U, gFwkSrvNbuVersionRequest_c = 0x81U, gFwkSrvXtal32MTrimIndication_c = 0x82U, @@ -115,11 +114,9 @@ typedef struct } FwkSrv_LowPowerConstraintCallbacks_t; typedef void (*nbu_memory_error_callback_t)(NbuDbgMemInfo_t *memInfo); - typedef void (*nbu_issue_callback_t)(void); - typedef void (*nbu_security_event_callback_t)(uint32_t securityEventBitmask); - +typedef void (*nbu_temp_req_event_callback_t)(uint32_t periodic_interval_ms); typedef void (*PLATFORM_FroDebugCallback_t)(uint16_t freq, int16_t ppm_mean, int16_t ppm, uint16_t fro_trim); /* -------------------------------------------------------------------------- */ @@ -220,6 +217,15 @@ void PLATFORM_RegisterNbuIssueCb(nbu_issue_callback_t cb); */ void PLATFORM_RegisterSecurityEventCb(nbu_security_event_callback_t cb); +/*! + * \brief Register function callback called when nbu request a temperature measurement + * \note gPlatformIcsUseWorkqueueRxProcessing_d should be enabled to support this. + * + * \param[in] cb callback that will be executed when nbu requests a temperature measurement + * + */ +void PLATFORM_RegisterNbuTemperatureRequestEventCb(nbu_temp_req_event_callback_t cb); + /*! * \brief Sends a a message to the RF_SFC module to enable notifications. The RF_SFC module will send a message to the * host to update some values, see PLATFORM_FroDebugCallback_t to know what are these values. diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/connected_mcu/fwk_platform_ot.c b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/wireless_mcu/fwk_platform_ot.c similarity index 97% rename from mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/connected_mcu/fwk_platform_ot.c rename to mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/wireless_mcu/fwk_platform_ot.c index 504621647d..57e5646cd4 100644 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/connected_mcu/fwk_platform_ot.c +++ b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/wireless_mcu/fwk_platform_ot.c @@ -1,5 +1,5 @@ /*! - * Copyright 2021-2025 NXP + * Copyright 2021-2023 NXP * * SPDX-License-Identifier: BSD-3-Clause */ @@ -9,6 +9,7 @@ #include "fwk_platform.h" #include "fwk_platform_ics.h" #include "fwk_platform_ot.h" +#include "FunctionLib.h" /* Check if __st is negative, if true, apply 4 bits shit and add new __error_code, assert in debug and break diff --git a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/connected_mcu/fwk_platform_ot.h b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/wireless_mcu/fwk_platform_ot.h similarity index 55% rename from mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/connected_mcu/fwk_platform_ot.h rename to mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/wireless_mcu/fwk_platform_ot.h index 9c0e20a248..63e38d545e 100644 --- a/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/connected_mcu/fwk_platform_ot.h +++ b/mcux/middleware/mcux-sdk-middleware-connectivity-framework/platform/wireless_mcu/fwk_platform_ot.h @@ -1,5 +1,5 @@ /*! - * Copyright 2021-2025 NXP + * Copyright 20021-2024 NXP * * SPDX-License-Identifier: BSD-3-Clause */ @@ -26,19 +26,6 @@ extern "C" { */ int PLATFORM_InitOT(void); -/*! - * \brief Return OpenThread / iEEE 802.15.4 MAC address - * - * If MAC address already programmed return its value. - * If not yet programmed generate one using the OUI defined by the IEEE_15_4_ADDR_OUI - * macro. The remaining 5 bytes are picked either from the Radio UID or generated - * randomly. - * \param eui64_address pointer on buffer storage supplied by caller to receive the 8 - * bytes of EUI-64 MAC address. - * - */ -void PLATFORM_GetIeee802_15_4Addr(uint8_t *eui64_address); - #ifdef __cplusplus } #endif diff --git a/zephyr/module.yml b/zephyr/module.yml index 0947b602d9..17ea3aa309 100644 --- a/zephyr/module.yml +++ b/zephyr/module.yml @@ -39,18 +39,18 @@ blobs: description: "WiFi firmware for RW612 A2 boards" doc-url: https://github.com/NXP/wifi_nb_fw/blob/nxp-v4.1.1/readme.txt - path: mcxw71/mcxw71_nbu_ble.sb3 - sha256: f952d3df86b781982586d0737f29d46c4b7480b6b6e7905c002625f807ac60f4 + sha256: daaed5f823ed424fde0ffd0906f094cf8e9074143f23534b7c8bcce1a9b3970c type: img - version: '24.12.00' + version: '25.03.00' license-path: zephyr/blobs/license/LA_OPT_NXP_Online_Code_Hosting.txt - url: https://github.com/nxp-mcuxpresso/mcuxsdk-middleware-bluetooth-controller/raw/36fec038f52171d46a0804434144c600c4233e9f/bin/mcxw71_nbu_ble_hosted.sb3 + url: https://github.com/nxp-mcuxpresso/mcuxsdk-middleware-bluetooth-controller/raw/3136d92bbb87498dc71a3c17cff46be843352d3c/bin/mcxw71_nbu_ble_hosted.sb3 description: "BLE Controller for MCXW71 boards" - path: mcxw72/mcxw72_nbu_ble_all_hosted.bin - sha256: 753705fa39971bc0350ed2db220814b702792f42db2ea0047f7f8bfb8bf09830 + sha256: d10859095a49fb0ae56837a0cdd7801fa16a4b72b3162b841fb046e2a0b5d380 type: img - version: '24.12.00' + version: '25.03.00' license-path: zephyr/blobs/license/LA_OPT_NXP_Online_Code_Hosting.txt - url: https://github.com/nxp-mcuxpresso/mcuxsdk-middleware-bluetooth-controller/raw/36fec038f52171d46a0804434144c600c4233e9f/bin/mcxw72_nbu_ble_all_hosted.bin + url: https://github.com/nxp-mcuxpresso/mcuxsdk-middleware-bluetooth-controller/raw/3136d92bbb87498dc71a3c17cff46be843352d3c/bin/mcxw72_nbu_ble_all_hosted.bin description: "BLE Controller for MCXW72 boards" - path: mcxw71/mcxw71_nbu_ble_15_4_dyn.sb3 sha256: 42429eaca2ecaa9a0c8dd3d6dcb50f1e34b88946436be7ee99d15b8096d553dc