1 /* -------------------------------------------------------------------------- */ 2 /* Copyright 2021-2024 NXP */ 3 /* All rights reserved. */ 4 /* SPDX-License-Identifier: BSD-3-Clause */ 5 /* -------------------------------------------------------------------------- */ 6 7 /* -------------------------------------------------------------------------- */ 8 /* Includes */ 9 /* -------------------------------------------------------------------------- */ 10 11 #include <stdint.h> 12 #include <stdbool.h> 13 14 #include "fwk_platform_coex.h" 15 #include "fsl_loader.h" 16 17 /* -------------------------------------------------------------------------- */ 18 /* Private macros */ 19 /* -------------------------------------------------------------------------- */ 20 #ifndef gPlatformMonolithicApp_d 21 #define gPlatformMonolithicApp_d 0 22 #endif 23 24 #if (defined gPlatformMonolithicApp_d && (gPlatformMonolithicApp_d != 0)) 25 #ifndef WIFI_FW_ADDRESS 26 extern const uint32_t fw_cpu1[]; 27 #define WIFI_FW_ADDRESS (uint32_t) & fw_cpu1[0] 28 #endif 29 #ifndef BLE_FW_ADDRESS 30 extern const uint32_t fw_cpu2_ble[]; 31 #define BLE_FW_ADDRESS (uint32_t) & fw_cpu2_ble[0] 32 #endif 33 #ifndef COMBO_FW_ADDRESS 34 extern const uint32_t fw_cpu2_combo[]; 35 #define COMBO_FW_ADDRESS (uint32_t) & fw_cpu2_combo[0] 36 #endif 37 #else 38 #define WIFI_FW_ADDRESS 0U 39 #define BLE_FW_ADDRESS 0U 40 #define COMBO_FW_ADDRESS 0U 41 #endif 42 43 /* -------------------------------------------------------------------------- */ 44 /* Private types */ 45 /* -------------------------------------------------------------------------- */ 46 47 /* -------------------------------------------------------------------------- */ 48 /* Private memory */ 49 /* -------------------------------------------------------------------------- */ 50 51 static uint8_t runningControllers = 0U; 52 53 /* -------------------------------------------------------------------------- */ 54 /* Private prototypes */ 55 /* -------------------------------------------------------------------------- */ 56 57 /* -------------------------------------------------------------------------- */ 58 /* Public functions */ 59 /* -------------------------------------------------------------------------- */ 60 PLATFORM_InitControllers(uint8_t controllersMask)61int PLATFORM_InitControllers(uint8_t controllersMask) 62 { 63 int ret = 0; 64 uint8_t protocols = controllersMask & connAll_c; 65 do 66 { 67 /* Wifi controller runs on CPU1 */ 68 if (((protocols & connWlan_c) != 0U) && ((runningControllers & connWlan_c) == 0U)) 69 { 70 if (sb3_fw_reset(LOAD_WIFI_FIRMWARE, 1, WIFI_FW_ADDRESS) != kStatus_Success) 71 { 72 ret = -1; 73 break; 74 } 75 runningControllers |= connWlan_c; 76 } 77 /* BLE/15.4 share the same core (CPU2) so check if there's as least one of those required */ 78 if (((controllersMask & (connBle_c | conn802_15_4_c)) != 0U) && 79 ((runningControllers & (connBle_c | conn802_15_4_c)) == 0U)) 80 { 81 if (((controllersMask & connBle_c) != 0U) && ((controllersMask & conn802_15_4_c) == 0U)) 82 { 83 /* BLE only */ 84 if (sb3_fw_reset(LOAD_BLE_FIRMWARE, 1, BLE_FW_ADDRESS) != kStatus_Success) 85 { 86 ret = -2; 87 break; 88 } 89 runningControllers |= connBle_c; 90 } 91 else 92 { 93 /* BLE/15.4 combo */ 94 if (sb3_fw_reset(LOAD_15D4_FIRMWARE, 1, COMBO_FW_ADDRESS) != kStatus_Success) 95 { 96 ret = -3; 97 break; 98 } 99 runningControllers |= connBle_c | conn802_15_4_c; 100 } 101 } 102 } while (false); 103 104 return ret; 105 } 106 PLATFORM_TerminateControllers(uint8_t controllersMask)107int PLATFORM_TerminateControllers(uint8_t controllersMask) 108 { 109 uint8_t protocols = controllersMask & connAll_c; 110 111 if (((protocols & connWlan_c) != 0U) && ((runningControllers & connWlan_c) != 0U)) 112 { 113 /* Power off CPU1 */ 114 power_off_device(LOAD_WIFI_FIRMWARE); 115 runningControllers &= ~connWlan_c; 116 } 117 118 /* BLE/15.4 share the same core (CPU2) */ 119 if (((protocols & (connBle_c | conn802_15_4_c)) != 0U) && 120 ((runningControllers & (connBle_c | conn802_15_4_c)) != 0U)) 121 { 122 /* Power off CPU2 */ 123 power_off_device(LOAD_BLE_FIRMWARE); 124 runningControllers &= ~(connBle_c | conn802_15_4_c); 125 } 126 127 return 0; 128 } 129 PLATFORM_GetRunningControllers(void)130uint8_t PLATFORM_GetRunningControllers(void) 131 { 132 return runningControllers; 133 } 134 135 /* -------------------------------------------------------------------------- */ 136 /* Private functions */ 137 /* -------------------------------------------------------------------------- */ 138