Skip to content

Commit 556fd12

Browse files
committed
Fix Bluetooth init issue. 52X LCPU now could go sleep
1 parent 5bc331f commit 556fd12

3 files changed

Lines changed: 89 additions & 11 deletions

File tree

third_party/hal_sifli/lcpu_52x.c

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,3 +337,87 @@ void lcpu_img_install()
337337
memcpy((void*)(HCPU_LCPU_CODE_START_ADDR),g_lcpu_bin,sizeof(g_lcpu_bin));
338338
#endif
339339
}
340+
341+
int bt_mac_addr_generate_via_uid_v2(uint8_t *addr)
342+
{
343+
int result = -4;
344+
uint8_t uid[16] = {0};
345+
uint8_t pattern;
346+
int32_t ret = HAL_EFUSE_Read(0, uid, 16);
347+
uint8_t use_v2 = 0;
348+
uint32_t i;
349+
350+
if (!addr)
351+
return -1;
352+
353+
if (ret != 16)
354+
{
355+
return -2;
356+
}
357+
358+
for (i = 0; i < 16; i++)
359+
if (uid[i] != 0)
360+
break;
361+
362+
if (i >= 16)
363+
{
364+
return -3;
365+
}
366+
367+
pattern = uid[7];
368+
369+
if (pattern == 0xA5)
370+
{
371+
uint8_t chk_sum = uid[6];
372+
uint8_t chk_sum_cal = uid[0] + uid[1] + uid[2] + uid[3] + uid[4] + uid[5];
373+
374+
if (chk_sum == chk_sum_cal)
375+
use_v2 = 1;
376+
}
377+
378+
memcpy((void *)addr, (void *)&uid[0], 6);
379+
if (use_v2)
380+
{
381+
result = 0;
382+
}
383+
else
384+
result = -5;
385+
386+
return result;
387+
}
388+
389+
390+
#define NVDS_BUFF_START 0x2040FE00
391+
#define NVDS_BUFF_SIZE 512
392+
393+
/*
394+
* default value description:
395+
0x01, 0x06, 0x12, 0x34, 0x56, 0x78, 0x AB, 0xCD: The default bd addres
396+
0x0D, 02, 0x64, 0x19: Control pre-wakeup time for the sleep of BT subsysm in LCPU. The value is different in RC10K and LXT32K.
397+
0x12, 0x01, 0x01: Control maximum sleep duration of BT subsystem. the last 0x01 means 10s in BLE only and 30s in dual mode. 0 means 500ms.
398+
0x2F, 0x04, 0x20, 0x00, 0x00, 0x00: Control the log in Contoller and changed to 0x20, 0x00, 0x09, 0x0 will enable HCI log defautly.
399+
0x15, 0x01, 0x01: Internal usage, for scheduling.
400+
*/
401+
402+
403+
static uint8_t g_ble_slp_default_rc10k[] = {
404+
0x01, 0x06, 0x12, 0x34, 0x56, 0x78, 0xAB, 0xCD,
405+
0x0D, 0x02, 0x64, 0x19,
406+
0x12, 0x01, 0x01,
407+
0x2F, 0x04, 0x20, 0x00, 0x00, 0x00,
408+
0x15, 0x01, 0x01
409+
};
410+
411+
void lcpu_nvds_config(void)
412+
{
413+
int r=bt_mac_addr_generate_via_uid_v2(&(g_ble_slp_default_rc10k[2]));
414+
uint8_t *nvds_addr = (uint8_t *)NVDS_BUFF_START;//0x204FFD00;
415+
416+
*(uint32_t *)nvds_addr = 0x4E564453;
417+
*(uint16_t *)(nvds_addr+4) = sizeof(g_ble_slp_default_rc10k);
418+
*(uint16_t *)(nvds_addr+6) = 0;
419+
memcpy((void*)(nvds_addr+8), g_ble_slp_default_rc10k, sizeof(g_ble_slp_default_rc10k));
420+
HAL_DBG_printf("add: %d\r", r);
421+
HAL_DBG_print_data((char *)nvds_addr, 0, 8+sizeof(g_ble_slp_default_rc10k));
422+
}
423+

third_party/nimble/transport/hci_mbox.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include <system/passert.h>
3333
#include <util/math.h>
3434
#include "ipc_queue.h"
35+
36+
//#define DEBUG 1
3537

3638
static TaskHandle_t s_rx_task_handle;
3739
static SemaphoreHandle_t s_rx_data_ready;
@@ -70,15 +72,6 @@ static int32_t mbox_rx_ind(ipc_queue_handle_t handle, size_t size)
7072
{
7173
static BaseType_t xHigherPriorityTaskWoken = pdFALSE;
7274

73-
#if 1 // FIX ME: Currently LCPU could not sleep.
74-
{
75-
static int wake_lcpu=1;
76-
if (wake_lcpu) {
77-
HAL_HPAON_WakeCore(CORE_ID_LCPU);
78-
wake_lcpu=0;
79-
}
80-
}
81-
#endif
8275
xSemaphoreGiveFromISR(s_rx_data_ready, &xHigherPriorityTaskWoken);
8376
return 0;
8477
}
@@ -232,7 +225,8 @@ int ble_transport_to_ll_acl_impl(struct os_mbuf *om) {
232225
#if DEBUG
233226
HAL_DBG_print_data((char*)hci_acl, 0, OS_MBUF_PKTLEN(om)+1);
234227
#endif
235-
int written = ipc_queue_write(mbox_env.ipc_port, hci_acl, OS_MBUF_PKTLEN(om)+1, 10);
228+
int written = ipc_queue_write(mbox_env.ipc_port, hci_acl, OS_MBUF_PKTLEN(om)+1, 10);
229+
os_mbuf_free(om);
236230
return (written>=0)?0:-1;
237231
}
238232

third_party/nimble/wscript

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def build(bld):
7474
'transport/hci_mbox.c',
7575
]
7676
nimble_includes = [
77-
'port/include/nrf52',
77+
'port/include/cc2564x',
7878
] + nimble_includes
7979

8080
elif bld.env.bt_controller == 'nrf52':

0 commit comments

Comments
 (0)