Skip to content

Commit

Permalink
Merge pull request #2764 from particle-iot/fix/rtl872x-wifi-ble-coex
Browse files Browse the repository at this point in the history
[Gen 4] change coexistence behavior in wifi connecting or wifi connected states with background BLE low prio activity
  • Loading branch information
scott-brust authored Jun 13, 2024
2 parents 44e4f6d + cbdf67a commit fdc25ca
Show file tree
Hide file tree
Showing 45 changed files with 1,894 additions and 627 deletions.
12 changes: 12 additions & 0 deletions bootloader/prebootloader/src/rtl872x/part1/include.mk
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
MAIN_STACK_SIZE = 4096

# # FIXME
# ifeq ("$(MODULE)","prebootloader-part1")
# EXTRA_DEPS = third_party/freertos
# EXTRA_DEPS_INCLUDE_SCRIPTS =$(foreach module,$(EXTRA_DEPS),$(PROJECT_ROOT)/$(module)/import.mk)
# include $(EXTRA_DEPS_INCLUDE_SCRIPTS)

# EXTRA_LIB_DEP += $(FREERTOS_LIB_DEP)
# LIBS += $(notdir $(EXTRA_DEPS))
# LIB_DIRS += $(FREERTOS_LIB_DIR)
# endif

ASFLAGS += -D__STACKSIZE__=$(MAIN_STACK_SIZE) -D__STACK_SIZE=$(MAIN_STACK_SIZE)

LDFLAGS += -L$(COMMON_BUILD)/arm/linker/rtl872x
LDFLAGS += -L$(BOOTLOADER_SHARED_MODULAR)
LDFLAGS += -Wl,--defsym,__STACKSIZE__=$(MAIN_STACK_SIZE)
LDFLAGS += -Wl,--defsym,__STACK_SIZE=$(MAIN_STACK_SIZE)
LDFLAGS += -u uxTopUsedPriority
42 changes: 37 additions & 5 deletions bootloader/prebootloader/src/rtl872x/part1/linker.ld
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ MEMORY
SRAM (xrw) : ORIGIN = platform_km0_part1_ram_start, LENGTH = platform_km0_part1_ram_size
APP_FLASH (rx) : ORIGIN = platform_km0_part1_flash_start, LENGTH = platform_km0_part1_flash_size
RETENTION_RAM (xrw) : ORIGIN = platform_retention_ram_start, LENGTH = platform_retention_ram_size
WIFI_FW_RAM (rwx) : ORIGIN = platform_km0_part1_wifi_fw_ram_start, LENGTH = platform_km0_part1_wifi_fw_ram_size
}

SECTIONS
Expand Down Expand Up @@ -42,14 +43,46 @@ SECTIONS

INCLUDE linker_build_id.ld

.wifi_fw_bss (NOLOAD):
{
. = ALIGN(4);
link_wifi_fw_bss_start = . ;
*lib_wifi_fw.a: (.bss .bss.* .FW.ram.bss .FW.ram.bss.*)
link_wifi_fw_bss_end = . ;
. = ALIGN(4);
} > WIFI_FW_RAM AT> WIFI_FW_RAM

.wifi_fw_text :
{
. = ALIGN(4);
link_wifi_fw_text_start = . ;
link_wifi_fw_text_flash_start = LOADADDR ( .wifi_fw_text );
link_code_start = .;
*lib_wifi_fw.a: (.text .text.* .rodata .rodata.*)
*(.wifi_fw_text)
*(.wifi_fw_text*)
link_wifi_fw_text_end = . ;
. = ALIGN(4);
} > WIFI_FW_RAM AT> APP_FLASH

.wifi_fw_data :
{
. = ALIGN(4);
link_wifi_fw_data_start = . ;
link_wifi_fw_data_flash_start = LOADADDR ( .wifi_fw_data );
*lib_wifi_fw.a: (.data .data.*)
link_wifi_fw_data_end = . ;
. = ALIGN(4);
link_wifi_fw_used_end = . ;
} > WIFI_FW_RAM AT> APP_FLASH

.ram_text :
{
link_ram_copy_flash_start = LOADADDR( .ram_text );
. = ALIGN(4);
link_ram_copy_start = .;

/* Code */
link_code_start = .;
*(.flashtext) /* Realtek specific */
*(.text)
*(.text.*)
Expand Down Expand Up @@ -89,8 +122,8 @@ SECTIONS
KEEP (*(SORT(.dtors.*)))
KEEP (*crtend.o(.dtors))
link_destructors_end = .;

. = ALIGN(4);
link_ram_copy_end = .;
} > SRAM AT> APP_FLASH

/* Static RAM start */
Expand Down Expand Up @@ -119,7 +152,6 @@ SECTIONS
. = ALIGN(4);
/* This is used by the startup in order to initialize the .data secion */
link_global_data_end = .;
link_ram_copy_end = .;
} > SRAM AT> APP_FLASH

/* Zero initialised memory used for zero initialised variables */
Expand Down Expand Up @@ -180,8 +212,8 @@ SECTIONS
}

/* Heap location */
link_heap_location = link_bss_end;
link_heap_location_end = platform_km0_ram_end - platform_km0_bootloader_stack_size;
link_heap_location = link_wifi_fw_used_end;
link_heap_location_end = platform_km0_part1_wifi_fw_ram_end;

/* Stack , used by startup*/
link_stack_size = platform_km0_bootloader_stack_size;
Expand Down
10 changes: 5 additions & 5 deletions bootloader/prebootloader/src/rtl872x/part1/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ BOOTLOADER_SHARED_MODULAR = ../shared
BUILD_PATH_EXT = $(PREBOOTLOADER_PART1_BUILD_PATH_EXT)
RTL_BINARY_FLASH_START = 0x14000

DEPENDENCIES = hal platform dynalib services wiring
MAKE_DEPENDENCIES = $(PLATFORM_DEPS)
# dependent on headers, but not the libraries
# LIBS +=
LIB_DEPS += $(PLATFORM_LIB_DEPS)
DEPENDENCIES = hal platform dynalib services wiring third_party/freertos
MAKE_DEPENDENCIES = $(PLATFORM_DEPS) third_party/freertos

LIBS += $(notdir third_party/freertos)
LIB_DEPS += $(PLATFORM_LIB_DEPS) $(FREERTOS_LIB_DEP)
LIB_DIRS += $(dir $(LIB_DEPS))

BOOTLOADER_USE_LTO?=y
Expand Down
16 changes: 15 additions & 1 deletion bootloader/prebootloader/src/rtl872x/part1/part1_export.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "km0_km4_ipc.h"
#include "sleep_handler.h"
#include "update_handler.h"
#include "wififw_handler.h"

extern uintptr_t link_dynalib_flash_start;
extern uintptr_t link_dynalib_start;
Expand All @@ -35,17 +36,26 @@ extern uintptr_t link_ram_copy_start;
extern uintptr_t link_ram_copy_end;
#define link_ram_copy_size ((uintptr_t)&link_ram_copy_end - (uintptr_t)&link_ram_copy_start)

extern uintptr_t link_global_data_initial_values;
extern uintptr_t link_global_data_start;
extern uintptr_t link_global_data_end;
#define link_global_data_size ((uintptr_t)&link_global_data_end - (uintptr_t)&link_global_data_start)

__attribute__((section(".xip.text"), used)) int bootloader_part1_preinit(void) {
// Copy the dynalib table to SRAM
if ((&link_dynalib_start != &link_dynalib_flash_start) && (link_dynalib_table_size != 0)) {
_memcpy(&link_dynalib_start, &link_dynalib_flash_start, link_dynalib_table_size);
}
// Initialize .bss
_memset(&link_bss_location, 0, link_bss_size );
// Copy RAM code and static data
// Copy .text
if ((&link_ram_copy_start != &link_ram_copy_flash_start) && (link_ram_copy_size != 0)) {
_memcpy(&link_ram_copy_start, &link_ram_copy_flash_start, link_ram_copy_size);
}
// Copy .data
if ((&link_global_data_start != &link_global_data_initial_values) && (link_global_data_size != 0)) {
_memcpy(&link_global_data_start, &link_global_data_initial_values, link_global_data_size);
}
return 0;
}

Expand Down Expand Up @@ -74,12 +84,16 @@ int bootloader_part1_init(void) {
int bootloader_part1_setup(void) {
sleepInit();
bootloaderUpdateInit();
wifiFwInit();

return 0;
}

int bootloader_part1_loop(void) {
sleepProcess();
bootloaderUpdateProcess();
wifiFwProcess();

return 0;
}

Expand Down
77 changes: 77 additions & 0 deletions bootloader/prebootloader/src/rtl872x/part1/rtos_hook.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright (c) 2024 Particle Industries, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHAN'TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/

#include "FreeRTOS.h"
#include "task.h"

#if configSUPPORT_STATIC_ALLOCATION == 1

#define IDLE_TASK_STACK_SIZE (4096 / sizeof(portSTACK_TYPE))

/* configSUPPORT_STATIC_ALLOCATION is set to 1, so the application must provide an
implementation of vApplicationGetIdleTaskMemory() to provide the memory that is
used by the Idle task. */
extern "C" void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer,
StackType_t **ppxIdleTaskStackBuffer,
uint32_t *pulIdleTaskStackSize )
{
/* If the buffers to be provided to the Idle task are declared inside this
function then they must be declared static - otherwise they will be allocated on
the stack and so not exists after this function exits. */
static StaticTask_t xIdleTaskTCB;
static StackType_t uxIdleTaskStack[ IDLE_TASK_STACK_SIZE ];

/* Pass out a pointer to the StaticTask_t structure in which the Idle task's
state will be stored. */
*ppxIdleTaskTCBBuffer = &xIdleTaskTCB;

/* Pass out the array that will be used as the Idle task's stack. */
*ppxIdleTaskStackBuffer = uxIdleTaskStack;

/* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer.
Note that, as the array is necessarily of type StackType_t,
configMINIMAL_STACK_SIZE is specified in words, not bytes. */
*pulIdleTaskStackSize = IDLE_TASK_STACK_SIZE;
}
/*-----------------------------------------------------------*/

/* configSUPPORT_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the
application must provide an implementation of vApplicationGetTimerTaskMemory()
to provide the memory that is used by the Timer service task. */
extern "C" void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer,
StackType_t **ppxTimerTaskStackBuffer,
uint32_t *pulTimerTaskStackSize )
{
/* If the buffers to be provided to the Timer task are declared inside this
function then they must be declared static - otherwise they will be allocated on
the stack and so not exists after this function exits. */
static StaticTask_t xTimerTaskTCB;
static StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ];

/* Pass out a pointer to the StaticTask_t structure in which the Timer
task's state will be stored. */
*ppxTimerTaskTCBBuffer = &xTimerTaskTCB;

/* Pass out the array that will be used as the Timer task's stack. */
*ppxTimerTaskStackBuffer = uxTimerTaskStack;

/* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer.
Note that, as the array is necessarily of type StackType_t,
configTIMER_TASK_STACK_DEPTH is specified in words, not bytes. */
*pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
}
#endif /* configSUPPORT_STATIC_ALLOCATION == 1 */
10 changes: 10 additions & 0 deletions bootloader/prebootloader/src/rtl872x/part1/sleep_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ extern "C" {
#include "simple_pool_allocator.h"
#include "scope_guard.h"
#include "sleep_handler.h"
#include "FreeRTOS.h"
#include "task.h"

extern "C" void km4_clock_gate(void);
extern "C" void km4_clock_on(void);
Expand Down Expand Up @@ -324,10 +326,15 @@ void sleepProcess(void) {
*/
auto config = sleepConfigShadow.config();
if (config->mode == HAL_SLEEP_MODE_HIBERNATE) {
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
taskENTER_CRITICAL();
configureDeepSleepWakeupSource(config);
enterDeepSleep();
// It should not reach here
} else {
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
taskENTER_CRITICAL();

// Copy and paste from km4_tickless_ipc_int()
km4_sleep_type = SLEEP_CG;
km4_clock_gate();
Expand All @@ -354,8 +361,11 @@ void sleepProcess(void) {
SOCPS_SleepCG();
SOCPS_SWRLDO_Suspend(DISABLE);

taskEXIT_CRITICAL();

SOCPS_AONTimerCmd(DISABLE);


#if PLATFORM_ID != PLATFORM_TRACKERM
if (swdEnabled) {
PAD_PullCtrl(27, GPIO_PuPd_UP);
Expand Down
2 changes: 2 additions & 0 deletions bootloader/prebootloader/src/rtl872x/part1/sources.mk
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ CPPSRC += $(PROJECT_ROOT)/hal/src/rtl872x/pinmap_hal.cpp

CPPSRC += $(PROJECT_ROOT)/hal/src/$(PLATFORM_NAME)/pinmap_defines.cpp

CSRC += $(PROJECT_ROOT)/hal/src/portable/FreeRTOS/heap_4_lock.c

LDFLAGS += -T$(PREBOOTLOADER_PART1_SRC_PATH)/linker.ld
LINKER_DEPS += $(PREBOOTLOADER_PART1_SRC_PATH)/linker.ld
Loading

0 comments on commit fdc25ca

Please sign in to comment.