Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[Gen 4] change coexistence behavior in wifi connecting or wifi connected states with background BLE low prio activity #2764

Merged
merged 30 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
e7ba7a6
[rtl872x] wlan/ble: fixup coex behavior in wifi connecting/scanning a…
avtolstoy Apr 22, 2024
78d02ad
[third_party] ambd_sdk: bump to coex-override
avtolstoy Apr 22, 2024
5c3d1f8
minor
avtolstoy Apr 22, 2024
144bdf6
minor
avtolstoy Apr 22, 2024
784ea95
minor
avtolstoy Apr 22, 2024
46f1179
[rtl872x] change tdma
avtolstoy Apr 23, 2024
a210a6d
[rtl872x] coex: change default tdma to 0x61, 0x20, 0x03, 0x11, 0x10
avtolstoy Apr 29, 2024
75fc358
wip
avtolstoy May 17, 2024
4be4b12
wip
avtolstoy May 20, 2024
5e3d64d
clean up a bit
avtolstoy May 22, 2024
0caa2c6
wip: integrate km0 wifi_fw
avtolstoy Jun 4, 2024
7de8cad
minor
avtolstoy Jun 4, 2024
b0949bd
minor fix
avtolstoy Jun 4, 2024
461656b
tune for busy aps
avtolstoy Jun 4, 2024
fbe4422
use latest results
avtolstoy Jun 6, 2024
91a766f
[gen4] fix sleep, a couple of wifi fw safety checks
avtolstoy Jun 7, 2024
07e58d7
[rtl872x] hal: defer freeing of memory under critical section to a de…
avtolstoy Jun 10, 2024
861899e
wip basic test working
scott-brust Apr 5, 2024
3575cc9
Add USB and OTA uncompressed busy tests. DRY js tests
scott-brust Apr 9, 2024
58f9207
Add wifi scanning, busy loop to high priority thread
scott-brust Apr 9, 2024
c4791ec
Run wifi and BLE scans concurrently
scott-brust Apr 12, 2024
9c8b176
Tweak for coex support
scott-brust Jun 5, 2024
d50f96b
fix build
scott-brust Jun 5, 2024
3b12cc3
Increase js test timeout to allow slow OTA to complete, tweak app timing
scott-brust Jun 5, 2024
67033f7
Raise OTA app flash timeout to 30 minutes
scott-brust Jun 6, 2024
deccf02
minor
scott-brust Jun 6, 2024
1ce0717
[rtl872x] clean up wifi fw linker files
avtolstoy Jun 10, 2024
27381fb
[rtl872x] cleanup
avtolstoy Jun 10, 2024
96d93cc
[rtl872x] coex: fix for monolithic builds
avtolstoy Jun 11, 2024
cbdf67a
[network] return ERR_RTE when interface is down to trigger EHOSTUNREACH
avtolstoy Jun 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
scott-brust marked this conversation as resolved.
Show resolved Hide resolved
# 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;
scott-brust marked this conversation as resolved.
Show resolved Hide resolved
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