Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
micropython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
micropython
Commits
633c6047
Commit
633c6047
authored
Nov 14, 2023
by
Damien George
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rp2/mpbthciport: Rework HCI polling timer to use soft_timer.
Signed-off-by:
Damien George
<
damien@micropython.org
>
parent
c9a9b2e6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
20 deletions
+18
-20
ports/rp2/mpbthciport.c
ports/rp2/mpbthciport.c
+16
-17
ports/rp2/mpnimbleport.c
ports/rp2/mpnimbleport.c
+2
-3
No files found.
ports/rp2/mpbthciport.c
View file @
633c6047
...
...
@@ -30,36 +30,37 @@
#include "extmod/modbluetooth.h"
#include "extmod/modmachine.h"
#include "extmod/mpbthci.h"
#include "shared/runtime/softtimer.h"
#include "modmachine.h"
#include "mpbthciport.h"
#include "pico/stdlib.h"
#if MICROPY_PY_BLUETOOTH
#define debug_printf(...) // mp_printf(&mp_plat_print, "mpbthciport.c: " __VA_ARGS__)
#define error_printf(...) mp_printf(&mp_plat_print, "mpbthciport.c: " __VA_ARGS__)
// Poll timer ID.
static
alarm_id_t
poll_timer_id
=
0
;
uint8_t
mp_bluetooth_hci_cmd_buf
[
4
+
256
];
// Soft timer and scheduling node for scheduling a HCI poll.
static
soft_timer_entry_t
mp_bluetooth_hci_soft_timer
;
static
mp_sched_node_t
mp_bluetooth_hci_sched_node
;
void
mp_bluetooth_hci_init
(
void
)
{
// This is called by soft_timer and executes at PendSV level.
static
void
mp_bluetooth_hci_soft_timer_callback
(
soft_timer_entry_t
*
self
)
{
mp_bluetooth_hci_poll_now
();
}
static
int64_t
mp_bluetooth_hci_timer_callback
(
alarm_id_t
id
,
void
*
user_data
)
{
poll_timer_id
=
0
;
mp_bluetooth_hci_poll_now
();
return
0
;
void
mp_bluetooth_hci_init
(
void
)
{
soft_timer_static_init
(
&
mp_bluetooth_hci_soft_timer
,
SOFT_TIMER_MODE_ONE_SHOT
,
0
,
mp_bluetooth_hci_soft_timer_callback
);
}
void
mp_bluetooth_hci_poll_in_ms
(
uint32_t
ms
)
{
if
(
poll_timer_id
!=
0
)
{
cancel_alarm
(
poll_timer_id
);
}
poll_timer_id
=
add_alarm_in_ms
(
ms
,
mp_bluetooth_hci_timer_callback
,
NULL
,
true
);
soft_timer_reinsert
(
&
mp_bluetooth_hci_soft_timer
,
ms
);
}
// For synchronous mode, we run all BLE stack code inside a scheduled task.
...
...
@@ -110,10 +111,8 @@ int mp_bluetooth_hci_uart_deinit(void) {
debug_printf
(
"mp_bluetooth_hci_uart_deinit
\n
"
);
// If a poll callback is set cancel it now.
if
(
poll_timer_id
>
0
)
{
cancel_alarm
(
poll_timer_id
);
}
poll_timer_id
=
0
;
soft_timer_remove
(
&
mp_bluetooth_hci_soft_timer
);
return
0
;
}
...
...
ports/rp2/mpnimbleport.c
View file @
633c6047
...
...
@@ -69,9 +69,8 @@ void mp_bluetooth_hci_poll(void) {
// --- Port-specific helpers for the generic NimBLE bindings. -----------------
void
mp_bluetooth_nimble_hci_uart_wfi
(
void
)
{
#if defined(__WFI)
__WFI
();
#endif
best_effort_wfe_or_timeout
(
make_timeout_time_ms
(
1
));
// This is called while NimBLE is waiting in ble_npl_sem_pend, i.e. waiting for an HCI ACK.
// Do not need to run events here (it must not invoke Python code), only processing incoming HCI data.
mp_bluetooth_nimble_hci_uart_process
(
false
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment