From 3ce181656fb2a2e3517f14139f307abbeb875e85 Mon Sep 17 00:00:00 2001 From: Joe Kearney Date: Fri, 4 Jul 2025 21:56:40 -0500 Subject: [PATCH 1/8] Added BLE_StopScanning() to support testing. --- 2020TPCApp1.cydsn/COMM/BLE/COMM_BLE.c | 24 +++++++++++++++++++++++ 2020TPCApp1.cydsn/COMM/BLE/COMM_BLE.h | 1 + 2020TPCApp1.cydsn/SystemK | 2 +- 2020TPCAppNoDFU.cydsn/COMM/BLE/COMM_BLE.c | 24 +++++++++++++++++++++++ 2020TPCAppNoDFU.cydsn/COMM/BLE/COMM_BLE.h | 1 + 2020TPCAppNoDFU.cydsn/SystemK | 2 +- 6 files changed, 52 insertions(+), 2 deletions(-) diff --git a/2020TPCApp1.cydsn/COMM/BLE/COMM_BLE.c b/2020TPCApp1.cydsn/COMM/BLE/COMM_BLE.c index bb57994..1e61a04 100644 --- a/2020TPCApp1.cydsn/COMM/BLE/COMM_BLE.c +++ b/2020TPCApp1.cydsn/COMM/BLE/COMM_BLE.c @@ -192,6 +192,22 @@ void COMM_BLE_Task(void * pvParameters) switch (command.ID) { + case COMM_BLE_STOP_SCANNING: + { + cy_en_ble_api_result_t apiResult = Cy_BLE_GAPC_StopScan(); + + if (apiResult != CY_BLE_SUCCESS) + { +#ifdef TRACE_BLE + COMM_Console_Print_String("[BLE] Cy_BLE_GAPC_StopScan API Error: 0x"); + COMM_Console_Print_UInt32AsHex(apiResult); + COMM_Console_Print_String("\n"); +#endif // TRACE_BLE + } + COMM_BLE_RequestState(COMM_BLE_IDLE); + } + break; + case COMM_BLE_STOP_ADVERTISING: { cy_en_ble_api_result_t apiResult = Cy_BLE_GAPP_StopAdvertisement(); @@ -340,6 +356,14 @@ SystemKResult_T BLE_StopAdvertising(void) return SYSTEMK_RESULT_SUCCESS; } +SystemKResult_T BLE_StopScanning(void) +{ + COMM_BLE_Command_T command = { .ID = COMM_BLE_STOP_SCANNING, .Data = (void *)0x00 }; + xQueueSend(COMM_BLE_CommandQueue, &command, 0); + + return SYSTEMK_RESULT_SUCCESS; +} + void COMM_BLE_RequestState(COMM_BLE_StateID_T state) { Next_State = state; diff --git a/2020TPCApp1.cydsn/COMM/BLE/COMM_BLE.h b/2020TPCApp1.cydsn/COMM/BLE/COMM_BLE.h index 83701e6..e4921c5 100644 --- a/2020TPCApp1.cydsn/COMM/BLE/COMM_BLE.h +++ b/2020TPCApp1.cydsn/COMM/BLE/COMM_BLE.h @@ -43,6 +43,7 @@ typedef enum COMM_BLE_SCAN_FOR_KTAG_PACKETS, COMM_BLE_ADVERTISE_AS_BROADCASTER, COMM_BLE_ADVERTISE_AS_PERIPHERAL, + COMM_BLE_STOP_SCANNING, COMM_BLE_STOP_ADVERTISING, COMM_BLE_SCAN_AND_ADVERTISE, // COMM_BLE_COMMAND_IS_OUT_OF_RANGE is one more than the last valid command. diff --git a/2020TPCApp1.cydsn/SystemK b/2020TPCApp1.cydsn/SystemK index 7aa8275..fb1a4ab 160000 --- a/2020TPCApp1.cydsn/SystemK +++ b/2020TPCApp1.cydsn/SystemK @@ -1 +1 @@ -Subproject commit 7aa827563a00b9bfa74e89be60f8529259ddac99 +Subproject commit fb1a4ab07b990fef8f957ef7c5f806649e126d0f diff --git a/2020TPCAppNoDFU.cydsn/COMM/BLE/COMM_BLE.c b/2020TPCAppNoDFU.cydsn/COMM/BLE/COMM_BLE.c index bb57994..1e61a04 100644 --- a/2020TPCAppNoDFU.cydsn/COMM/BLE/COMM_BLE.c +++ b/2020TPCAppNoDFU.cydsn/COMM/BLE/COMM_BLE.c @@ -192,6 +192,22 @@ void COMM_BLE_Task(void * pvParameters) switch (command.ID) { + case COMM_BLE_STOP_SCANNING: + { + cy_en_ble_api_result_t apiResult = Cy_BLE_GAPC_StopScan(); + + if (apiResult != CY_BLE_SUCCESS) + { +#ifdef TRACE_BLE + COMM_Console_Print_String("[BLE] Cy_BLE_GAPC_StopScan API Error: 0x"); + COMM_Console_Print_UInt32AsHex(apiResult); + COMM_Console_Print_String("\n"); +#endif // TRACE_BLE + } + COMM_BLE_RequestState(COMM_BLE_IDLE); + } + break; + case COMM_BLE_STOP_ADVERTISING: { cy_en_ble_api_result_t apiResult = Cy_BLE_GAPP_StopAdvertisement(); @@ -340,6 +356,14 @@ SystemKResult_T BLE_StopAdvertising(void) return SYSTEMK_RESULT_SUCCESS; } +SystemKResult_T BLE_StopScanning(void) +{ + COMM_BLE_Command_T command = { .ID = COMM_BLE_STOP_SCANNING, .Data = (void *)0x00 }; + xQueueSend(COMM_BLE_CommandQueue, &command, 0); + + return SYSTEMK_RESULT_SUCCESS; +} + void COMM_BLE_RequestState(COMM_BLE_StateID_T state) { Next_State = state; diff --git a/2020TPCAppNoDFU.cydsn/COMM/BLE/COMM_BLE.h b/2020TPCAppNoDFU.cydsn/COMM/BLE/COMM_BLE.h index 83701e6..e4921c5 100644 --- a/2020TPCAppNoDFU.cydsn/COMM/BLE/COMM_BLE.h +++ b/2020TPCAppNoDFU.cydsn/COMM/BLE/COMM_BLE.h @@ -43,6 +43,7 @@ typedef enum COMM_BLE_SCAN_FOR_KTAG_PACKETS, COMM_BLE_ADVERTISE_AS_BROADCASTER, COMM_BLE_ADVERTISE_AS_PERIPHERAL, + COMM_BLE_STOP_SCANNING, COMM_BLE_STOP_ADVERTISING, COMM_BLE_SCAN_AND_ADVERTISE, // COMM_BLE_COMMAND_IS_OUT_OF_RANGE is one more than the last valid command. diff --git a/2020TPCAppNoDFU.cydsn/SystemK b/2020TPCAppNoDFU.cydsn/SystemK index 7aa8275..fb1a4ab 160000 --- a/2020TPCAppNoDFU.cydsn/SystemK +++ b/2020TPCAppNoDFU.cydsn/SystemK @@ -1 +1 @@ -Subproject commit 7aa827563a00b9bfa74e89be60f8529259ddac99 +Subproject commit fb1a4ab07b990fef8f957ef7c5f806649e126d0f -- 2.47.2 From 8b655d8be7a4276536f76dda2527a446003a264b Mon Sep 17 00:00:00 2001 From: Joe Kearney Date: Thu, 14 Aug 2025 20:21:39 -0500 Subject: [PATCH 2/8] BLE Task needs more stack! --- 2020TPCApp1.cydsn/COMM/BLE/COMM_BLE.c | 174 +++++++++++++++++++++- 2020TPCApp1.cydsn/COMM/BLE/COMM_BLE.h | 2 +- 2020TPCApp1.cydsn/SystemK | 2 +- 2020TPCAppNoDFU.cydsn/COMM/BLE/COMM_BLE.c | 174 +++++++++++++++++++++- 2020TPCAppNoDFU.cydsn/COMM/BLE/COMM_BLE.h | 2 +- 2020TPCAppNoDFU.cydsn/SystemK | 2 +- 6 files changed, 344 insertions(+), 12 deletions(-) diff --git a/2020TPCApp1.cydsn/COMM/BLE/COMM_BLE.c b/2020TPCApp1.cydsn/COMM/BLE/COMM_BLE.c index 1e61a04..6321035 100644 --- a/2020TPCApp1.cydsn/COMM/BLE/COMM_BLE.c +++ b/2020TPCApp1.cydsn/COMM/BLE/COMM_BLE.c @@ -22,11 +22,17 @@ TaskHandle_t COMM_BLE_Task_Handle; /* Private Variables */ +static const char *TAG = "BLE"; static const TickType_t BLE_Task_Delay = BLE_TASK_PERIOD_IN_ms / portTICK_PERIOD_MS; static COMM_BLE_StateID_T Current_State = COMM_BLE_DEFAULT; static COMM_BLE_StateID_T Next_State = COMM_BLE_INITIALIZING; static bool State_Changed = false; static TickType_t Time_At_State_Entry_In_Ticks; +static bool Is_Quiet = false; +static bool Was_Advertising = false; + +static TimerHandle_t BLEUnquietTimer = NULL; +static StaticTimer_t xBLEUnquietTimerBuffer; //! Immediate Alert Service alert level value. volatile uint8_t COMM_BLE_IASAlertLevel = 0; @@ -288,6 +294,69 @@ void COMM_BLE_Task(void * pvParameters) #endif // TRACE_BLE } } + + switch (command.ID) + { + case COMM_BLE_STOP_SCANNING: + { + cy_en_ble_api_result_t apiResult = Cy_BLE_GAPC_StopScan(); + + if (apiResult != CY_BLE_SUCCESS) + { +#ifdef TRACE_BLE + COMM_Console_Print_String("[BLE] Cy_BLE_GAPC_StopScan API Error: 0x"); + COMM_Console_Print_UInt32AsHex(apiResult); + COMM_Console_Print_String("\n"); +#endif // TRACE_BLE + } + + apiResult = Cy_BLE_GAPP_StopAdvertisement(); + + if (apiResult != CY_BLE_SUCCESS) + { +#ifdef TRACE_BLE + COMM_Console_Print_String("[BLE] Cy_BLE_GAPP_StopAdvertisement API Error: 0x"); + COMM_Console_Print_UInt32AsHex(apiResult); + COMM_Console_Print_String("\n"); +#endif // TRACE_BLE + } + + COMM_BLE_RequestState(COMM_BLE_ADVERTISING_AS_BROADCASTER); + } + break; + + case COMM_BLE_STOP_ADVERTISING: + { + cy_en_ble_api_result_t apiResult = Cy_BLE_GAPC_StopScan(); + + if (apiResult != CY_BLE_SUCCESS) + { +#ifdef TRACE_BLE + COMM_Console_Print_String("[BLE] Cy_BLE_GAPC_StopScan API Error: 0x"); + COMM_Console_Print_UInt32AsHex(apiResult); + COMM_Console_Print_String("\n"); +#endif // TRACE_BLE + } + + apiResult = Cy_BLE_GAPP_StopAdvertisement(); + + if (apiResult != CY_BLE_SUCCESS) + { +#ifdef TRACE_BLE + COMM_Console_Print_String("[BLE] Cy_BLE_GAPP_StopAdvertisement API Error: 0x"); + COMM_Console_Print_UInt32AsHex(apiResult); + COMM_Console_Print_String("\n"); +#endif // TRACE_BLE + } + + COMM_BLE_RequestState(COMM_BLE_SCANNING_FOR_KTAG_PACKETS); + } + break; + + default: + // All other commands are ignored in this state. + break; + } } break; } @@ -342,8 +411,17 @@ SystemKResult_T BLE_GetMyAddress(uint8_t * BD_ADDR) SystemKResult_T BLE_ScanAndAdvertise(void) { - COMM_BLE_Command_T command = { .ID = COMM_BLE_SCAN_AND_ADVERTISE, .Data = (void *)0x00 }; - xQueueSend(COMM_BLE_CommandQueue, &command, 0); + if (Is_Quiet == false) + { + COMM_BLE_Command_T command = { .ID = COMM_BLE_SCAN_AND_ADVERTISE, .Data = (void *)0x00 }; + xQueueSend(COMM_BLE_CommandQueue, &command, 0); + } + else + { + // If we are quiet, we don't want to advertise yet, + // but we will remember that we were asked to advertise. + Was_Advertising = true; + } return SYSTEMK_RESULT_SUCCESS; } @@ -364,6 +442,84 @@ SystemKResult_T BLE_StopScanning(void) return SYSTEMK_RESULT_SUCCESS; } +static void Unquiet_Timer_Callback(TimerHandle_t xTimer) +{ + KLOG_INFO(TAG, "Unquiet timer expired after %lu ms.", (xTimerGetPeriod(xTimer) / portTICK_PERIOD_MS)); + BLE_Unquiet(); +} + +SystemKResult_T BLE_Quiet(uint32_t duration_ms) +{ + SystemKResult_T result = SYSTEMK_RESULT_NOT_READY; + + if (Is_Quiet == true) + { + // Already quiet; no action needed. + return SYSTEMK_RESULT_SUCCESS; + } + else + { + Is_Quiet = true; + + if ((Current_State == COMM_BLE_SCANNING_AND_ADVERTISING) || + (Current_State == COMM_BLE_ADVERTISING_AS_BROADCASTER)) + { + result = BLE_StopAdvertising(); + Was_Advertising = true; + } + + if (duration_ms > 0) + { + // Set a timer to unquiet after the specified duration. + BLEUnquietTimer = xTimerCreateStatic( + "BLEUnquietTimer", + pdMS_TO_TICKS(duration_ms), + pdFALSE, + (void *)0, + Unquiet_Timer_Callback, + &xBLEUnquietTimerBuffer); + + if (BLEUnquietTimer == NULL) + { + KLOG_ERROR(TAG, "Couldn't create the BLEUnquietTimer!"); + } + else + { + if (xTimerStart(BLEUnquietTimer, 0) != pdPASS) + { + KLOG_ERROR(TAG, "Couldn't start the BLEUnquietTimer!"); + } + } + } + result = SYSTEMK_RESULT_SUCCESS; + } + + return result; +} + +SystemKResult_T BLE_Unquiet(void) +{ + SystemKResult_T result = SYSTEMK_RESULT_NOT_READY; + + if (Is_Quiet == false) + { + // Already unquiet; no action needed. + return SYSTEMK_RESULT_SUCCESS; + } + else + { + Is_Quiet = false; + if (Was_Advertising == true) + { + BLE_ScanAndAdvertise(); + Was_Advertising = false; + } + result = SYSTEMK_RESULT_SUCCESS; + } + + return result; +} + void COMM_BLE_RequestState(COMM_BLE_StateID_T state) { Next_State = state; @@ -396,6 +552,8 @@ SystemKResult_T BLE_SetAdvertisingData(BLE_AdvertisingData_T * data) COMM_Console_Print_String("[BLE] Cy_BLE_GAPP_UpdateAdvScanData Error: 0x"); COMM_Console_Print_UInt32AsHex(result); COMM_Console_Print_String("\n"); + + vTaskDelay(100); #endif // TRACE_BLE } } @@ -612,8 +770,8 @@ static void BLE_EventHandler(uint32_t event, void * eventParam) COMM_Console_Print_String(" KTag 'Instigate Game' packet found!"); break; - case BLE_PACKET_TYPE_JOIN_NOW: - COMM_Console_Print_String(" KTag 'Join Now' packet found!"); + case BLE_PACKET_TYPE_EVENT: + COMM_Console_Print_String(" KTag 'Event' packet found!"); break; case BLE_PACKET_TYPE_TAG: @@ -627,6 +785,14 @@ static void BLE_EventHandler(uint32_t event, void * eventParam) case BLE_PACKET_TYPE_STATUS: COMM_Console_Print_String(" KTag 'Status' packet found!"); break; + + case BLE_PACKET_TYPE_PARAMETERS: + COMM_Console_Print_String(" KTag 'Parameters' packet found!"); + break; + + case BLE_PACKET_TYPE_HELLO: + COMM_Console_Print_String(" KTag 'Hello' packet found!"); + break; default: COMM_Console_Print_String(" Unknown KTag packet found!"); diff --git a/2020TPCApp1.cydsn/COMM/BLE/COMM_BLE.h b/2020TPCApp1.cydsn/COMM/BLE/COMM_BLE.h index e4921c5..e358b48 100644 --- a/2020TPCApp1.cydsn/COMM/BLE/COMM_BLE.h +++ b/2020TPCApp1.cydsn/COMM/BLE/COMM_BLE.h @@ -22,7 +22,7 @@ extern "C" { //#define TRACE_BLE //#define VERBOSE_BLE_TRACE -#define COMM_BLE_TASK_STACK_SIZE_in_bytes 4096 +#define COMM_BLE_TASK_STACK_SIZE_in_bytes 6144 typedef enum { diff --git a/2020TPCApp1.cydsn/SystemK b/2020TPCApp1.cydsn/SystemK index fb1a4ab..bb91512 160000 --- a/2020TPCApp1.cydsn/SystemK +++ b/2020TPCApp1.cydsn/SystemK @@ -1 +1 @@ -Subproject commit fb1a4ab07b990fef8f957ef7c5f806649e126d0f +Subproject commit bb915121e8e9c8b2679397f4554fa9bc2d836b67 diff --git a/2020TPCAppNoDFU.cydsn/COMM/BLE/COMM_BLE.c b/2020TPCAppNoDFU.cydsn/COMM/BLE/COMM_BLE.c index 1e61a04..6321035 100644 --- a/2020TPCAppNoDFU.cydsn/COMM/BLE/COMM_BLE.c +++ b/2020TPCAppNoDFU.cydsn/COMM/BLE/COMM_BLE.c @@ -22,11 +22,17 @@ TaskHandle_t COMM_BLE_Task_Handle; /* Private Variables */ +static const char *TAG = "BLE"; static const TickType_t BLE_Task_Delay = BLE_TASK_PERIOD_IN_ms / portTICK_PERIOD_MS; static COMM_BLE_StateID_T Current_State = COMM_BLE_DEFAULT; static COMM_BLE_StateID_T Next_State = COMM_BLE_INITIALIZING; static bool State_Changed = false; static TickType_t Time_At_State_Entry_In_Ticks; +static bool Is_Quiet = false; +static bool Was_Advertising = false; + +static TimerHandle_t BLEUnquietTimer = NULL; +static StaticTimer_t xBLEUnquietTimerBuffer; //! Immediate Alert Service alert level value. volatile uint8_t COMM_BLE_IASAlertLevel = 0; @@ -288,6 +294,69 @@ void COMM_BLE_Task(void * pvParameters) #endif // TRACE_BLE } } + + switch (command.ID) + { + case COMM_BLE_STOP_SCANNING: + { + cy_en_ble_api_result_t apiResult = Cy_BLE_GAPC_StopScan(); + + if (apiResult != CY_BLE_SUCCESS) + { +#ifdef TRACE_BLE + COMM_Console_Print_String("[BLE] Cy_BLE_GAPC_StopScan API Error: 0x"); + COMM_Console_Print_UInt32AsHex(apiResult); + COMM_Console_Print_String("\n"); +#endif // TRACE_BLE + } + + apiResult = Cy_BLE_GAPP_StopAdvertisement(); + + if (apiResult != CY_BLE_SUCCESS) + { +#ifdef TRACE_BLE + COMM_Console_Print_String("[BLE] Cy_BLE_GAPP_StopAdvertisement API Error: 0x"); + COMM_Console_Print_UInt32AsHex(apiResult); + COMM_Console_Print_String("\n"); +#endif // TRACE_BLE + } + + COMM_BLE_RequestState(COMM_BLE_ADVERTISING_AS_BROADCASTER); + } + break; + + case COMM_BLE_STOP_ADVERTISING: + { + cy_en_ble_api_result_t apiResult = Cy_BLE_GAPC_StopScan(); + + if (apiResult != CY_BLE_SUCCESS) + { +#ifdef TRACE_BLE + COMM_Console_Print_String("[BLE] Cy_BLE_GAPC_StopScan API Error: 0x"); + COMM_Console_Print_UInt32AsHex(apiResult); + COMM_Console_Print_String("\n"); +#endif // TRACE_BLE + } + + apiResult = Cy_BLE_GAPP_StopAdvertisement(); + + if (apiResult != CY_BLE_SUCCESS) + { +#ifdef TRACE_BLE + COMM_Console_Print_String("[BLE] Cy_BLE_GAPP_StopAdvertisement API Error: 0x"); + COMM_Console_Print_UInt32AsHex(apiResult); + COMM_Console_Print_String("\n"); +#endif // TRACE_BLE + } + + COMM_BLE_RequestState(COMM_BLE_SCANNING_FOR_KTAG_PACKETS); + } + break; + + default: + // All other commands are ignored in this state. + break; + } } break; } @@ -342,8 +411,17 @@ SystemKResult_T BLE_GetMyAddress(uint8_t * BD_ADDR) SystemKResult_T BLE_ScanAndAdvertise(void) { - COMM_BLE_Command_T command = { .ID = COMM_BLE_SCAN_AND_ADVERTISE, .Data = (void *)0x00 }; - xQueueSend(COMM_BLE_CommandQueue, &command, 0); + if (Is_Quiet == false) + { + COMM_BLE_Command_T command = { .ID = COMM_BLE_SCAN_AND_ADVERTISE, .Data = (void *)0x00 }; + xQueueSend(COMM_BLE_CommandQueue, &command, 0); + } + else + { + // If we are quiet, we don't want to advertise yet, + // but we will remember that we were asked to advertise. + Was_Advertising = true; + } return SYSTEMK_RESULT_SUCCESS; } @@ -364,6 +442,84 @@ SystemKResult_T BLE_StopScanning(void) return SYSTEMK_RESULT_SUCCESS; } +static void Unquiet_Timer_Callback(TimerHandle_t xTimer) +{ + KLOG_INFO(TAG, "Unquiet timer expired after %lu ms.", (xTimerGetPeriod(xTimer) / portTICK_PERIOD_MS)); + BLE_Unquiet(); +} + +SystemKResult_T BLE_Quiet(uint32_t duration_ms) +{ + SystemKResult_T result = SYSTEMK_RESULT_NOT_READY; + + if (Is_Quiet == true) + { + // Already quiet; no action needed. + return SYSTEMK_RESULT_SUCCESS; + } + else + { + Is_Quiet = true; + + if ((Current_State == COMM_BLE_SCANNING_AND_ADVERTISING) || + (Current_State == COMM_BLE_ADVERTISING_AS_BROADCASTER)) + { + result = BLE_StopAdvertising(); + Was_Advertising = true; + } + + if (duration_ms > 0) + { + // Set a timer to unquiet after the specified duration. + BLEUnquietTimer = xTimerCreateStatic( + "BLEUnquietTimer", + pdMS_TO_TICKS(duration_ms), + pdFALSE, + (void *)0, + Unquiet_Timer_Callback, + &xBLEUnquietTimerBuffer); + + if (BLEUnquietTimer == NULL) + { + KLOG_ERROR(TAG, "Couldn't create the BLEUnquietTimer!"); + } + else + { + if (xTimerStart(BLEUnquietTimer, 0) != pdPASS) + { + KLOG_ERROR(TAG, "Couldn't start the BLEUnquietTimer!"); + } + } + } + result = SYSTEMK_RESULT_SUCCESS; + } + + return result; +} + +SystemKResult_T BLE_Unquiet(void) +{ + SystemKResult_T result = SYSTEMK_RESULT_NOT_READY; + + if (Is_Quiet == false) + { + // Already unquiet; no action needed. + return SYSTEMK_RESULT_SUCCESS; + } + else + { + Is_Quiet = false; + if (Was_Advertising == true) + { + BLE_ScanAndAdvertise(); + Was_Advertising = false; + } + result = SYSTEMK_RESULT_SUCCESS; + } + + return result; +} + void COMM_BLE_RequestState(COMM_BLE_StateID_T state) { Next_State = state; @@ -396,6 +552,8 @@ SystemKResult_T BLE_SetAdvertisingData(BLE_AdvertisingData_T * data) COMM_Console_Print_String("[BLE] Cy_BLE_GAPP_UpdateAdvScanData Error: 0x"); COMM_Console_Print_UInt32AsHex(result); COMM_Console_Print_String("\n"); + + vTaskDelay(100); #endif // TRACE_BLE } } @@ -612,8 +770,8 @@ static void BLE_EventHandler(uint32_t event, void * eventParam) COMM_Console_Print_String(" KTag 'Instigate Game' packet found!"); break; - case BLE_PACKET_TYPE_JOIN_NOW: - COMM_Console_Print_String(" KTag 'Join Now' packet found!"); + case BLE_PACKET_TYPE_EVENT: + COMM_Console_Print_String(" KTag 'Event' packet found!"); break; case BLE_PACKET_TYPE_TAG: @@ -627,6 +785,14 @@ static void BLE_EventHandler(uint32_t event, void * eventParam) case BLE_PACKET_TYPE_STATUS: COMM_Console_Print_String(" KTag 'Status' packet found!"); break; + + case BLE_PACKET_TYPE_PARAMETERS: + COMM_Console_Print_String(" KTag 'Parameters' packet found!"); + break; + + case BLE_PACKET_TYPE_HELLO: + COMM_Console_Print_String(" KTag 'Hello' packet found!"); + break; default: COMM_Console_Print_String(" Unknown KTag packet found!"); diff --git a/2020TPCAppNoDFU.cydsn/COMM/BLE/COMM_BLE.h b/2020TPCAppNoDFU.cydsn/COMM/BLE/COMM_BLE.h index e4921c5..e358b48 100644 --- a/2020TPCAppNoDFU.cydsn/COMM/BLE/COMM_BLE.h +++ b/2020TPCAppNoDFU.cydsn/COMM/BLE/COMM_BLE.h @@ -22,7 +22,7 @@ extern "C" { //#define TRACE_BLE //#define VERBOSE_BLE_TRACE -#define COMM_BLE_TASK_STACK_SIZE_in_bytes 4096 +#define COMM_BLE_TASK_STACK_SIZE_in_bytes 6144 typedef enum { diff --git a/2020TPCAppNoDFU.cydsn/SystemK b/2020TPCAppNoDFU.cydsn/SystemK index fb1a4ab..bb91512 160000 --- a/2020TPCAppNoDFU.cydsn/SystemK +++ b/2020TPCAppNoDFU.cydsn/SystemK @@ -1 +1 @@ -Subproject commit fb1a4ab07b990fef8f957ef7c5f806649e126d0f +Subproject commit bb915121e8e9c8b2679397f4554fa9bc2d836b67 -- 2.47.2 From e81336cec8a3c891080afad8b699d8ca5d69e2e1 Mon Sep 17 00:00:00 2001 From: Joe Kearney Date: Sat, 16 Aug 2025 11:32:26 -0500 Subject: [PATCH 3/8] BLE_Quiet() now resets the timer. --- 2020TPCApp1.cydsn/2020TPCApp1.cyprj | 2 +- 2020TPCApp1.cydsn/COMM/BLE/COMM_BLE.c | 75 ++++++++++++++++++++++- 2020TPCApp1.cydsn/SystemK | 2 +- 2020TPCAppNoDFU.cydsn/COMM/BLE/COMM_BLE.c | 75 ++++++++++++++++++++++- 2020TPCAppNoDFU.cydsn/SystemK | 2 +- 5 files changed, 147 insertions(+), 9 deletions(-) diff --git a/2020TPCApp1.cydsn/2020TPCApp1.cyprj b/2020TPCApp1.cydsn/2020TPCApp1.cyprj index cc78e20..3c25635 100644 --- a/2020TPCApp1.cydsn/2020TPCApp1.cyprj +++ b/2020TPCApp1.cydsn/2020TPCApp1.cyprj @@ -5976,7 +5976,7 @@ - + diff --git a/2020TPCApp1.cydsn/COMM/BLE/COMM_BLE.c b/2020TPCApp1.cydsn/COMM/BLE/COMM_BLE.c index 6321035..eef6641 100644 --- a/2020TPCApp1.cydsn/COMM/BLE/COMM_BLE.c +++ b/2020TPCApp1.cydsn/COMM/BLE/COMM_BLE.c @@ -411,6 +411,10 @@ SystemKResult_T BLE_GetMyAddress(uint8_t * BD_ADDR) SystemKResult_T BLE_ScanAndAdvertise(void) { +#ifdef TRACE_BLE + KLOG_TRACE(TAG, "BLE_ScanAndAdvertise()"); +#endif // TRACE_BLE + if (Is_Quiet == false) { COMM_BLE_Command_T command = { .ID = COMM_BLE_SCAN_AND_ADVERTISE, .Data = (void *)0x00 }; @@ -428,6 +432,10 @@ SystemKResult_T BLE_ScanAndAdvertise(void) SystemKResult_T BLE_StopAdvertising(void) { +#ifdef TRACE_BLE + KLOG_TRACE(TAG, "BLE_StopAdvertising()"); +#endif // TRACE_BLE + COMM_BLE_Command_T command = { .ID = COMM_BLE_STOP_ADVERTISING, .Data = (void *)0x00 }; xQueueSend(COMM_BLE_CommandQueue, &command, 0); @@ -436,6 +444,10 @@ SystemKResult_T BLE_StopAdvertising(void) SystemKResult_T BLE_StopScanning(void) { +#ifdef TRACE_BLE + KLOG_TRACE(TAG, "BLE_StopScanning()"); +#endif // TRACE_BLE + COMM_BLE_Command_T command = { .ID = COMM_BLE_STOP_SCANNING, .Data = (void *)0x00 }; xQueueSend(COMM_BLE_CommandQueue, &command, 0); @@ -450,12 +462,59 @@ static void Unquiet_Timer_Callback(TimerHandle_t xTimer) SystemKResult_T BLE_Quiet(uint32_t duration_ms) { +#ifdef TRACE_BLE + KLOG_TRACE(TAG, "BLE_Quiet(%lu)", duration_ms); +#endif // TRACE_BLE + SystemKResult_T result = SYSTEMK_RESULT_NOT_READY; if (Is_Quiet == true) { - // Already quiet; no action needed. - return SYSTEMK_RESULT_SUCCESS; + // Already quiet; reset timer with new duration if duration_ms > 0. + if (duration_ms > 0) + { + // Stop and delete existing timer if it exists. + if (BLEUnquietTimer != NULL) + { + xTimerStop(BLEUnquietTimer, 0); + xTimerDelete(BLEUnquietTimer, 0); + BLEUnquietTimer = NULL; + } + + // Create and start new timer with the new duration. + BLEUnquietTimer = xTimerCreateStatic( + "BLEUnquietTimer", + pdMS_TO_TICKS(duration_ms), + pdFALSE, + (void *)0, + Unquiet_Timer_Callback, + &xBLEUnquietTimerBuffer); + + if (BLEUnquietTimer == NULL) + { + KLOG_ERROR(TAG, "Couldn't create the BLEUnquietTimer!"); + result = SYSTEMK_RESULT_FAILED_TO_CREATE_RTOS_TIMER; + } + else + { + if (xTimerStart(BLEUnquietTimer, 0) != pdPASS) + { + KLOG_ERROR(TAG, "Couldn't start the BLEUnquietTimer!"); + result = SYSTEMK_RESULT_FAILED_TO_START_RTOS_TIMER; + } + } + } + else + { + // If duration_ms is 0, stop and delete the timer to stay quiet indefinitely. + if (BLEUnquietTimer != NULL) + { + xTimerStop(BLEUnquietTimer, 0); + xTimerDelete(BLEUnquietTimer, 0); + BLEUnquietTimer = NULL; + } + } + result = SYSTEMK_RESULT_SUCCESS; } else { @@ -482,12 +541,14 @@ SystemKResult_T BLE_Quiet(uint32_t duration_ms) if (BLEUnquietTimer == NULL) { KLOG_ERROR(TAG, "Couldn't create the BLEUnquietTimer!"); + result = SYSTEMK_RESULT_FAILED_TO_CREATE_RTOS_TIMER; } else { if (xTimerStart(BLEUnquietTimer, 0) != pdPASS) { KLOG_ERROR(TAG, "Couldn't start the BLEUnquietTimer!"); + result = SYSTEMK_RESULT_FAILED_TO_START_RTOS_TIMER; } } } @@ -499,6 +560,10 @@ SystemKResult_T BLE_Quiet(uint32_t duration_ms) SystemKResult_T BLE_Unquiet(void) { +#ifdef TRACE_BLE + KLOG_TRACE(TAG, "BLE_Unquiet()"); +#endif // TRACE_BLE + SystemKResult_T result = SYSTEMK_RESULT_NOT_READY; if (Is_Quiet == false) @@ -544,6 +609,10 @@ SystemKResult_T BLE_SetAdvertisingData(BLE_AdvertisingData_T * data) Advertising_Data.advDataLen = BLE_KTAG_PACKET_TOTAL_SIZE; memcpy(Advertising_Data.advData, data, BLE_KTAG_PACKET_TOTAL_SIZE); +#ifdef TRACE_BLE + KLOG_TRACE(TAG, "Setting advertising data for packet type %u", data->data[8]); +#endif // TRACE_BLE + cy_en_ble_api_result_t result = Cy_BLE_GAPP_UpdateAdvScanData(&Advertising_Info); if (result != CY_BLE_SUCCESS) @@ -795,7 +864,7 @@ static void BLE_EventHandler(uint32_t event, void * eventParam) break; default: - COMM_Console_Print_String(" Unknown KTag packet found!"); + KLOG_ERROR(TAG, " Unknown KTag packet found: 0x%02X", packet->Generic.type); break; } diff --git a/2020TPCApp1.cydsn/SystemK b/2020TPCApp1.cydsn/SystemK index bb91512..88c81dc 160000 --- a/2020TPCApp1.cydsn/SystemK +++ b/2020TPCApp1.cydsn/SystemK @@ -1 +1 @@ -Subproject commit bb915121e8e9c8b2679397f4554fa9bc2d836b67 +Subproject commit 88c81dc405ef5d10fcf67d80d349bc1a7924e6f9 diff --git a/2020TPCAppNoDFU.cydsn/COMM/BLE/COMM_BLE.c b/2020TPCAppNoDFU.cydsn/COMM/BLE/COMM_BLE.c index 6321035..eef6641 100644 --- a/2020TPCAppNoDFU.cydsn/COMM/BLE/COMM_BLE.c +++ b/2020TPCAppNoDFU.cydsn/COMM/BLE/COMM_BLE.c @@ -411,6 +411,10 @@ SystemKResult_T BLE_GetMyAddress(uint8_t * BD_ADDR) SystemKResult_T BLE_ScanAndAdvertise(void) { +#ifdef TRACE_BLE + KLOG_TRACE(TAG, "BLE_ScanAndAdvertise()"); +#endif // TRACE_BLE + if (Is_Quiet == false) { COMM_BLE_Command_T command = { .ID = COMM_BLE_SCAN_AND_ADVERTISE, .Data = (void *)0x00 }; @@ -428,6 +432,10 @@ SystemKResult_T BLE_ScanAndAdvertise(void) SystemKResult_T BLE_StopAdvertising(void) { +#ifdef TRACE_BLE + KLOG_TRACE(TAG, "BLE_StopAdvertising()"); +#endif // TRACE_BLE + COMM_BLE_Command_T command = { .ID = COMM_BLE_STOP_ADVERTISING, .Data = (void *)0x00 }; xQueueSend(COMM_BLE_CommandQueue, &command, 0); @@ -436,6 +444,10 @@ SystemKResult_T BLE_StopAdvertising(void) SystemKResult_T BLE_StopScanning(void) { +#ifdef TRACE_BLE + KLOG_TRACE(TAG, "BLE_StopScanning()"); +#endif // TRACE_BLE + COMM_BLE_Command_T command = { .ID = COMM_BLE_STOP_SCANNING, .Data = (void *)0x00 }; xQueueSend(COMM_BLE_CommandQueue, &command, 0); @@ -450,12 +462,59 @@ static void Unquiet_Timer_Callback(TimerHandle_t xTimer) SystemKResult_T BLE_Quiet(uint32_t duration_ms) { +#ifdef TRACE_BLE + KLOG_TRACE(TAG, "BLE_Quiet(%lu)", duration_ms); +#endif // TRACE_BLE + SystemKResult_T result = SYSTEMK_RESULT_NOT_READY; if (Is_Quiet == true) { - // Already quiet; no action needed. - return SYSTEMK_RESULT_SUCCESS; + // Already quiet; reset timer with new duration if duration_ms > 0. + if (duration_ms > 0) + { + // Stop and delete existing timer if it exists. + if (BLEUnquietTimer != NULL) + { + xTimerStop(BLEUnquietTimer, 0); + xTimerDelete(BLEUnquietTimer, 0); + BLEUnquietTimer = NULL; + } + + // Create and start new timer with the new duration. + BLEUnquietTimer = xTimerCreateStatic( + "BLEUnquietTimer", + pdMS_TO_TICKS(duration_ms), + pdFALSE, + (void *)0, + Unquiet_Timer_Callback, + &xBLEUnquietTimerBuffer); + + if (BLEUnquietTimer == NULL) + { + KLOG_ERROR(TAG, "Couldn't create the BLEUnquietTimer!"); + result = SYSTEMK_RESULT_FAILED_TO_CREATE_RTOS_TIMER; + } + else + { + if (xTimerStart(BLEUnquietTimer, 0) != pdPASS) + { + KLOG_ERROR(TAG, "Couldn't start the BLEUnquietTimer!"); + result = SYSTEMK_RESULT_FAILED_TO_START_RTOS_TIMER; + } + } + } + else + { + // If duration_ms is 0, stop and delete the timer to stay quiet indefinitely. + if (BLEUnquietTimer != NULL) + { + xTimerStop(BLEUnquietTimer, 0); + xTimerDelete(BLEUnquietTimer, 0); + BLEUnquietTimer = NULL; + } + } + result = SYSTEMK_RESULT_SUCCESS; } else { @@ -482,12 +541,14 @@ SystemKResult_T BLE_Quiet(uint32_t duration_ms) if (BLEUnquietTimer == NULL) { KLOG_ERROR(TAG, "Couldn't create the BLEUnquietTimer!"); + result = SYSTEMK_RESULT_FAILED_TO_CREATE_RTOS_TIMER; } else { if (xTimerStart(BLEUnquietTimer, 0) != pdPASS) { KLOG_ERROR(TAG, "Couldn't start the BLEUnquietTimer!"); + result = SYSTEMK_RESULT_FAILED_TO_START_RTOS_TIMER; } } } @@ -499,6 +560,10 @@ SystemKResult_T BLE_Quiet(uint32_t duration_ms) SystemKResult_T BLE_Unquiet(void) { +#ifdef TRACE_BLE + KLOG_TRACE(TAG, "BLE_Unquiet()"); +#endif // TRACE_BLE + SystemKResult_T result = SYSTEMK_RESULT_NOT_READY; if (Is_Quiet == false) @@ -544,6 +609,10 @@ SystemKResult_T BLE_SetAdvertisingData(BLE_AdvertisingData_T * data) Advertising_Data.advDataLen = BLE_KTAG_PACKET_TOTAL_SIZE; memcpy(Advertising_Data.advData, data, BLE_KTAG_PACKET_TOTAL_SIZE); +#ifdef TRACE_BLE + KLOG_TRACE(TAG, "Setting advertising data for packet type %u", data->data[8]); +#endif // TRACE_BLE + cy_en_ble_api_result_t result = Cy_BLE_GAPP_UpdateAdvScanData(&Advertising_Info); if (result != CY_BLE_SUCCESS) @@ -795,7 +864,7 @@ static void BLE_EventHandler(uint32_t event, void * eventParam) break; default: - COMM_Console_Print_String(" Unknown KTag packet found!"); + KLOG_ERROR(TAG, " Unknown KTag packet found: 0x%02X", packet->Generic.type); break; } diff --git a/2020TPCAppNoDFU.cydsn/SystemK b/2020TPCAppNoDFU.cydsn/SystemK index bb91512..88c81dc 160000 --- a/2020TPCAppNoDFU.cydsn/SystemK +++ b/2020TPCAppNoDFU.cydsn/SystemK @@ -1 +1 @@ -Subproject commit bb915121e8e9c8b2679397f4554fa9bc2d836b67 +Subproject commit 88c81dc405ef5d10fcf67d80d349bc1a7924e6f9 -- 2.47.2 From 871001f60bee9e168ddca0bc82903b5b94dfd3a8 Mon Sep 17 00:00:00 2001 From: Joe Kearney Date: Sat, 16 Aug 2025 14:50:28 -0500 Subject: [PATCH 4/8] Fixed the Hello packet hack needed for PSoC6. --- 2020TPCApp1.cydsn/COMM/BLE/COMM_BLE.c | 31 ++++++++++++++++++++++++++- 2020TPCApp1.cydsn/SystemK | 2 +- 2020TPCAppNoDFU.cydsn/SystemK | 2 +- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/2020TPCApp1.cydsn/COMM/BLE/COMM_BLE.c b/2020TPCApp1.cydsn/COMM/BLE/COMM_BLE.c index eef6641..621894a 100644 --- a/2020TPCApp1.cydsn/COMM/BLE/COMM_BLE.c +++ b/2020TPCApp1.cydsn/COMM/BLE/COMM_BLE.c @@ -30,6 +30,7 @@ static bool State_Changed = false; static TickType_t Time_At_State_Entry_In_Ticks; static bool Is_Quiet = false; static bool Was_Advertising = false; +static BLE_AdvertisingData_T Cached_Advertising_Data; static TimerHandle_t BLEUnquietTimer = NULL; static StaticTimer_t xBLEUnquietTimerBuffer; @@ -610,7 +611,7 @@ SystemKResult_T BLE_SetAdvertisingData(BLE_AdvertisingData_T * data) memcpy(Advertising_Data.advData, data, BLE_KTAG_PACKET_TOTAL_SIZE); #ifdef TRACE_BLE - KLOG_TRACE(TAG, "Setting advertising data for packet type %u", data->data[8]); + KLOG_TRACE(TAG, "Setting advertising data for packet type %u.", data->data[8]); #endif // TRACE_BLE cy_en_ble_api_result_t result = Cy_BLE_GAPP_UpdateAdvScanData(&Advertising_Info); @@ -625,6 +626,10 @@ SystemKResult_T BLE_SetAdvertisingData(BLE_AdvertisingData_T * data) vTaskDelay(100); #endif // TRACE_BLE } + + // Save a copy for later. + Cached_Advertising_Data.length = BLE_KTAG_PACKET_TOTAL_SIZE; + memcpy(&Cached_Advertising_Data, data, BLE_KTAG_PACKET_TOTAL_SIZE); } return result; @@ -983,6 +988,30 @@ static void BLE_EventHandler(uint32_t event, void * eventParam) COMM_Console_Print_String("\n"); #endif // TRACE_BLE + // Restore the previous;y set advertising packet. + if (Cy_BLE_GetAdvertisementState() == CY_BLE_ADV_STATE_ADVERTISING) + { + Advertising_Data.advDataLen = BLE_KTAG_PACKET_TOTAL_SIZE; + memcpy(Advertising_Data.advData, &Cached_Advertising_Data, BLE_KTAG_PACKET_TOTAL_SIZE); + +#ifdef TRACE_BLE + KLOG_TRACE(TAG, "Setting advertising data from cached copy for packet type %u.", Cached_Advertising_Data.data[8]); +#endif // TRACE_BLE + + cy_en_ble_api_result_t result = Cy_BLE_GAPP_UpdateAdvScanData(&Advertising_Info); + + if (result != CY_BLE_SUCCESS) + { +#ifdef TRACE_BLE + COMM_Console_Print_String("[BLE] Cy_BLE_GAPP_UpdateAdvScanData Error: 0x"); + COMM_Console_Print_UInt32AsHex(result); + COMM_Console_Print_String("\n"); + + vTaskDelay(100); +#endif // TRACE_BLE + } + } + #if 0 if (Cy_BLE_GetAdvertisementState() == CY_BLE_ADV_STATE_STOPPED) { diff --git a/2020TPCApp1.cydsn/SystemK b/2020TPCApp1.cydsn/SystemK index 88c81dc..6a3f128 160000 --- a/2020TPCApp1.cydsn/SystemK +++ b/2020TPCApp1.cydsn/SystemK @@ -1 +1 @@ -Subproject commit 88c81dc405ef5d10fcf67d80d349bc1a7924e6f9 +Subproject commit 6a3f12819c7b26f73cbf471e28c93ba610040ed4 diff --git a/2020TPCAppNoDFU.cydsn/SystemK b/2020TPCAppNoDFU.cydsn/SystemK index 88c81dc..6a3f128 160000 --- a/2020TPCAppNoDFU.cydsn/SystemK +++ b/2020TPCAppNoDFU.cydsn/SystemK @@ -1 +1 @@ -Subproject commit 88c81dc405ef5d10fcf67d80d349bc1a7924e6f9 +Subproject commit 6a3f12819c7b26f73cbf471e28c93ba610040ed4 -- 2.47.2 From 34e53acbf6b5be21a680eaae6d4c75f0cc3794b1 Mon Sep 17 00:00:00 2001 From: Joe Kearney Date: Sat, 16 Aug 2025 16:09:47 -0500 Subject: [PATCH 5/8] All BLE Quiet tests pass! --- 2020TPCApp1.cydsn/COMM/BLE/COMM_BLE.c | 2 +- 2020TPCApp1.cydsn/SystemK | 2 +- 2020TPCAppNoDFU.cydsn/COMM/BLE/COMM_BLE.c | 31 ++++++++++++++++++++++- 2020TPCAppNoDFU.cydsn/SystemK | 2 +- 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/2020TPCApp1.cydsn/COMM/BLE/COMM_BLE.c b/2020TPCApp1.cydsn/COMM/BLE/COMM_BLE.c index 621894a..db043ab 100644 --- a/2020TPCApp1.cydsn/COMM/BLE/COMM_BLE.c +++ b/2020TPCApp1.cydsn/COMM/BLE/COMM_BLE.c @@ -611,7 +611,7 @@ SystemKResult_T BLE_SetAdvertisingData(BLE_AdvertisingData_T * data) memcpy(Advertising_Data.advData, data, BLE_KTAG_PACKET_TOTAL_SIZE); #ifdef TRACE_BLE - KLOG_TRACE(TAG, "Setting advertising data for packet type %u.", data->data[8]); + KLOG_TRACE(TAG, "Setting advertising data for packet type %u.", data->data[8]); #endif // TRACE_BLE cy_en_ble_api_result_t result = Cy_BLE_GAPP_UpdateAdvScanData(&Advertising_Info); diff --git a/2020TPCApp1.cydsn/SystemK b/2020TPCApp1.cydsn/SystemK index 6a3f128..e0e7fdf 160000 --- a/2020TPCApp1.cydsn/SystemK +++ b/2020TPCApp1.cydsn/SystemK @@ -1 +1 @@ -Subproject commit 6a3f12819c7b26f73cbf471e28c93ba610040ed4 +Subproject commit e0e7fdf1aef151390c1e82d95e89e39038206bca diff --git a/2020TPCAppNoDFU.cydsn/COMM/BLE/COMM_BLE.c b/2020TPCAppNoDFU.cydsn/COMM/BLE/COMM_BLE.c index eef6641..db043ab 100644 --- a/2020TPCAppNoDFU.cydsn/COMM/BLE/COMM_BLE.c +++ b/2020TPCAppNoDFU.cydsn/COMM/BLE/COMM_BLE.c @@ -30,6 +30,7 @@ static bool State_Changed = false; static TickType_t Time_At_State_Entry_In_Ticks; static bool Is_Quiet = false; static bool Was_Advertising = false; +static BLE_AdvertisingData_T Cached_Advertising_Data; static TimerHandle_t BLEUnquietTimer = NULL; static StaticTimer_t xBLEUnquietTimerBuffer; @@ -610,7 +611,7 @@ SystemKResult_T BLE_SetAdvertisingData(BLE_AdvertisingData_T * data) memcpy(Advertising_Data.advData, data, BLE_KTAG_PACKET_TOTAL_SIZE); #ifdef TRACE_BLE - KLOG_TRACE(TAG, "Setting advertising data for packet type %u", data->data[8]); + KLOG_TRACE(TAG, "Setting advertising data for packet type %u.", data->data[8]); #endif // TRACE_BLE cy_en_ble_api_result_t result = Cy_BLE_GAPP_UpdateAdvScanData(&Advertising_Info); @@ -625,6 +626,10 @@ SystemKResult_T BLE_SetAdvertisingData(BLE_AdvertisingData_T * data) vTaskDelay(100); #endif // TRACE_BLE } + + // Save a copy for later. + Cached_Advertising_Data.length = BLE_KTAG_PACKET_TOTAL_SIZE; + memcpy(&Cached_Advertising_Data, data, BLE_KTAG_PACKET_TOTAL_SIZE); } return result; @@ -983,6 +988,30 @@ static void BLE_EventHandler(uint32_t event, void * eventParam) COMM_Console_Print_String("\n"); #endif // TRACE_BLE + // Restore the previous;y set advertising packet. + if (Cy_BLE_GetAdvertisementState() == CY_BLE_ADV_STATE_ADVERTISING) + { + Advertising_Data.advDataLen = BLE_KTAG_PACKET_TOTAL_SIZE; + memcpy(Advertising_Data.advData, &Cached_Advertising_Data, BLE_KTAG_PACKET_TOTAL_SIZE); + +#ifdef TRACE_BLE + KLOG_TRACE(TAG, "Setting advertising data from cached copy for packet type %u.", Cached_Advertising_Data.data[8]); +#endif // TRACE_BLE + + cy_en_ble_api_result_t result = Cy_BLE_GAPP_UpdateAdvScanData(&Advertising_Info); + + if (result != CY_BLE_SUCCESS) + { +#ifdef TRACE_BLE + COMM_Console_Print_String("[BLE] Cy_BLE_GAPP_UpdateAdvScanData Error: 0x"); + COMM_Console_Print_UInt32AsHex(result); + COMM_Console_Print_String("\n"); + + vTaskDelay(100); +#endif // TRACE_BLE + } + } + #if 0 if (Cy_BLE_GetAdvertisementState() == CY_BLE_ADV_STATE_STOPPED) { diff --git a/2020TPCAppNoDFU.cydsn/SystemK b/2020TPCAppNoDFU.cydsn/SystemK index 6a3f128..e0e7fdf 160000 --- a/2020TPCAppNoDFU.cydsn/SystemK +++ b/2020TPCAppNoDFU.cydsn/SystemK @@ -1 +1 @@ -Subproject commit 6a3f12819c7b26f73cbf471e28c93ba610040ed4 +Subproject commit e0e7fdf1aef151390c1e82d95e89e39038206bca -- 2.47.2 From 29ebbfbc07627ca8ae3fbbdb5f942f2f089c92e4 Mon Sep 17 00:00:00 2001 From: Joe Kearney Date: Sat, 16 Aug 2025 20:00:58 -0500 Subject: [PATCH 6/8] Repin SystemK. --- 2020TPCApp1.cydsn/SystemK | 2 +- 2020TPCAppNoDFU.cydsn/SystemK | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/2020TPCApp1.cydsn/SystemK b/2020TPCApp1.cydsn/SystemK index e0e7fdf..e914558 160000 --- a/2020TPCApp1.cydsn/SystemK +++ b/2020TPCApp1.cydsn/SystemK @@ -1 +1 @@ -Subproject commit e0e7fdf1aef151390c1e82d95e89e39038206bca +Subproject commit e914558e6396f66b61cc47bcf6da086a745807f6 diff --git a/2020TPCAppNoDFU.cydsn/SystemK b/2020TPCAppNoDFU.cydsn/SystemK index e0e7fdf..e914558 160000 --- a/2020TPCAppNoDFU.cydsn/SystemK +++ b/2020TPCAppNoDFU.cydsn/SystemK @@ -1 +1 @@ -Subproject commit e0e7fdf1aef151390c1e82d95e89e39038206bca +Subproject commit e914558e6396f66b61cc47bcf6da086a745807f6 -- 2.47.2 From 45fb361b551283d0625178335ca9f8e33b48d878 Mon Sep 17 00:00:00 2001 From: Joe Kearney Date: Mon, 1 Sep 2025 11:12:05 -0500 Subject: [PATCH 7/8] Repin SystemK. --- 2020TPCApp1.cydsn/2020TPCApp1.cyprj | 14 ++++++++++++++ 2020TPCApp1.cydsn/SystemK | 2 +- 2020TPCAppNoDFU.cydsn/2020TPCAppNoDFU.cyprj | 14 ++++++++++++++ 2020TPCAppNoDFU.cydsn/SystemK | 2 +- 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/2020TPCApp1.cydsn/2020TPCApp1.cyprj b/2020TPCApp1.cydsn/2020TPCApp1.cyprj index 3c25635..16ff818 100644 --- a/2020TPCApp1.cydsn/2020TPCApp1.cyprj +++ b/2020TPCApp1.cydsn/2020TPCApp1.cyprj @@ -1516,6 +1516,20 @@ + + + + + + + + + + + + + + diff --git a/2020TPCApp1.cydsn/SystemK b/2020TPCApp1.cydsn/SystemK index e914558..26cb24d 160000 --- a/2020TPCApp1.cydsn/SystemK +++ b/2020TPCApp1.cydsn/SystemK @@ -1 +1 @@ -Subproject commit e914558e6396f66b61cc47bcf6da086a745807f6 +Subproject commit 26cb24dfe1a98c89f2179419a045cf0e91ba3e9d diff --git a/2020TPCAppNoDFU.cydsn/2020TPCAppNoDFU.cyprj b/2020TPCAppNoDFU.cydsn/2020TPCAppNoDFU.cyprj index e090c8a..377efd5 100644 --- a/2020TPCAppNoDFU.cydsn/2020TPCAppNoDFU.cyprj +++ b/2020TPCAppNoDFU.cydsn/2020TPCAppNoDFU.cyprj @@ -1545,6 +1545,20 @@ + + + + + + + + + + + + + + diff --git a/2020TPCAppNoDFU.cydsn/SystemK b/2020TPCAppNoDFU.cydsn/SystemK index e914558..26cb24d 160000 --- a/2020TPCAppNoDFU.cydsn/SystemK +++ b/2020TPCAppNoDFU.cydsn/SystemK @@ -1 +1 @@ -Subproject commit e914558e6396f66b61cc47bcf6da086a745807f6 +Subproject commit 26cb24dfe1a98c89f2179419a045cf0e91ba3e9d -- 2.47.2 From d7c0efb5353041ca0f8804c7c28a9bcdbf432971 Mon Sep 17 00:00:00 2001 From: Joe Kearney Date: Mon, 1 Sep 2025 13:18:03 -0500 Subject: [PATCH 8/8] Repinned SystemK. --- 2020TPCApp1.cydsn/SystemK | 2 +- 2020TPCAppNoDFU.cydsn/SystemK | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/2020TPCApp1.cydsn/SystemK b/2020TPCApp1.cydsn/SystemK index 26cb24d..430aec5 160000 --- a/2020TPCApp1.cydsn/SystemK +++ b/2020TPCApp1.cydsn/SystemK @@ -1 +1 @@ -Subproject commit 26cb24dfe1a98c89f2179419a045cf0e91ba3e9d +Subproject commit 430aec54b8d6edde82c3bc9240e34b6a9e31aa09 diff --git a/2020TPCAppNoDFU.cydsn/SystemK b/2020TPCAppNoDFU.cydsn/SystemK index 26cb24d..430aec5 160000 --- a/2020TPCAppNoDFU.cydsn/SystemK +++ b/2020TPCAppNoDFU.cydsn/SystemK @@ -1 +1 @@ -Subproject commit 26cb24dfe1a98c89f2179419a045cf0e91ba3e9d +Subproject commit 430aec54b8d6edde82c3bc9240e34b6a9e31aa09 -- 2.47.2