1818// clang-format off
1919#include <os/os_mbuf.h>
2020// clang-format on
21-
21+ #include <stdio.h>
2222#include <board/board.h>
2323#include <drivers/uart.h>
2424#include <kernel/pebble_tasks.h>
@@ -69,8 +69,16 @@ static void prv_rx_task_main(void *unused) {
6969static int32_t mbox_rx_ind (ipc_queue_handle_t handle , size_t size )
7070{
7171 static BaseType_t xHigherPriorityTaskWoken = pdFALSE ;
72-
73- HAL_HPAON_WakeCore (CORE_ID_LCPU );
72+
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
7482 xSemaphoreGiveFromISR (s_rx_data_ready , & xHigherPriorityTaskWoken );
7583 return 0 ;
7684}
@@ -118,7 +126,8 @@ int pb_config_mbox(void)
118126 if (ipc_queue_open (mbox_env .ipc_port ))
119127 PBL_ASSERT (0 ,"Could not open IPC" );
120128 NVIC_EnableIRQ (LCPU2HCPU_IRQn );
121-
129+ NVIC_SetPriority (LCPU2HCPU_IRQn , 5 );
130+
122131 mbox_env .is_init = 1 ;
123132 return 0 ;
124133}
@@ -132,15 +141,23 @@ hci_uart_frame_cb(uint8_t pkt_type, void *data)
132141 {
133142 struct ble_hci_ev * ev = data ;
134143 struct ble_hci_ev_command_complete * cmd_complete = (void * ) ev -> data ;
135-
144+ #if DEBUG
145+ HAL_DBG_print_data (data , 0 , ev -> length + sizeof (* ev ));
146+ PBL_LOG (LOG_LEVEL_INFO , "Event %x" , ev -> opcode );
147+ #endif
136148 if (ev -> opcode == BLE_HCI_EVCODE_COMMAND_COMPLETE )
137- PBL_LOG (LOG_LEVEL_INFO , "CMD complete %x" , cmd_complete -> opcode );
149+ PBL_LOG (LOG_LEVEL_INFO , "\tCMD complete %x" , cmd_complete -> opcode );
138150
139151 if (ev -> opcode == BLE_HCI_EVCODE_COMMAND_COMPLETE && cmd_complete -> opcode == 0xFC11 )
140152 break ;
141153 }
142154 return ble_transport_to_hs_evt (data );
143155 case HCI_H4_ACL :
156+ struct os_mbuf * om = (struct os_mbuf * )data ;
157+ PBL_LOG (LOG_LEVEL_INFO , "ACL IND %x" , OS_MBUF_PKTLEN (om ));
158+ #if DEBUG
159+ HAL_DBG_print_data ((char * )data , 0 , OS_MBUF_PKTLEN (om ));
160+ #endif
144161 return ble_transport_to_hs_acl (data );
145162 default :
146163 assert (0 );
@@ -149,7 +166,7 @@ hci_uart_frame_cb(uint8_t pkt_type, void *data)
149166
150167 return -1 ;
151168}
152- #if 0
169+ #if DEBUG
153170void HAL_DBG_printf (const char * fmt , ...)
154171{
155172 va_list args ;
@@ -197,15 +214,25 @@ int ble_transport_to_ll_cmd_impl(void *buf) {
197214 struct ble_hci_cmd * cmd = buf ;
198215 hci_cmd [0 ]= 1 ;
199216 memcpy (& (hci_cmd [1 ]), buf , 3 + cmd -> length );
217+ PBL_LOG (LOG_LEVEL_INFO , "BLE TX CMD %x, len=%d" , cmd -> opcode , 3 + cmd -> length + 1 );
218+ #if DEBUG
219+ HAL_DBG_print_data ((char * )hci_cmd , 0 , 3 + cmd -> length + 1 );
220+ #endif
200221 int written = ipc_queue_write (mbox_env .ipc_port , hci_cmd , 3 + cmd -> length + 1 , 10 );
201- PBL_LOG (LOG_LEVEL_INFO , "BLE TX CMD %x" , cmd -> opcode );
202222 ble_transport_free (buf );
203223 return (written >=0 )?0 :-1 ;
204224}
205-
225+
226+ static uint8_t hci_acl [256 ];
206227int ble_transport_to_ll_acl_impl (struct os_mbuf * om ) {
207228 uint8_t * data = OS_MBUF_DATA (om , uint8_t * );
208- int written = ipc_queue_write (mbox_env .ipc_port , data , OS_MBUF_PKTLEN (om ), 10 );
229+ PBL_LOG (LOG_LEVEL_INFO , "BLE TX ACL len=%d" , OS_MBUF_PKTLEN (om ));
230+ hci_acl [0 ]= 2 ;
231+ memcpy (& (hci_acl [1 ]), data , OS_MBUF_PKTLEN (om ));
232+ #if DEBUG
233+ HAL_DBG_print_data ((char * )hci_acl , 0 , OS_MBUF_PKTLEN (om )+ 1 );
234+ #endif
235+ int written = ipc_queue_write (mbox_env .ipc_port , hci_acl , OS_MBUF_PKTLEN (om )+ 1 , 10 );
209236 return (written >=0 )?0 :-1 ;
210237}
211238
0 commit comments