Skip to content

Commit 0a9f1aa

Browse files
committed
feat(freertos): Add UART CTS wakeup to freertos
The freertos platform has been updated to support UART CTS wakeup, as already supported by the bare-metal embedded platform.
1 parent 097521e commit 0a9f1aa

File tree

1 file changed

+44
-3
lines changed

1 file changed

+44
-3
lines changed

platform/freertos/btstack_uart_block_freertos.c

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,11 @@ static btstack_data_source_t transport_data_source;
6565
// callbacks
6666
static void (*block_sent)(void);
6767
static void (*block_received)(void);
68+
static void (*wakeup_handler)(void);
6869

6970
static int send_complete;
7071
static int receive_complete;
72+
static int wakeup_event;
7173

7274
static void btstack_uart_block_freertos_received_isr(void){
7375
receive_complete = 1;
@@ -79,6 +81,11 @@ static void btstack_uart_block_freertos_sent_isr(void){
7981
btstack_run_loop_poll_data_sources_from_irq();
8082
}
8183

84+
static void btstack_uart_block_freertos_cts_pulse_isr(void){
85+
wakeup_event = 1;
86+
btstack_run_loop_poll_data_sources_from_irq();
87+
}
88+
8289
static void btstack_uart_block_freertos_process(btstack_data_source_t *ds, btstack_data_source_callback_type_t callback_type) {
8390
switch (callback_type){
8491
case DATA_SOURCE_CALLBACK_POLL:
@@ -94,6 +101,12 @@ static void btstack_uart_block_freertos_process(btstack_data_source_t *ds, btsta
94101
block_received();
95102
}
96103
}
104+
if (wakeup_event){
105+
wakeup_event = 0;
106+
if (wakeup_handler){
107+
wakeup_handler();
108+
}
109+
}
97110
break;
98111
default:
99112
break;
@@ -134,6 +147,10 @@ static void btstack_uart_block_freertos_set_block_sent( void (*block_handler)(vo
134147
block_sent = block_handler;
135148
}
136149

150+
static void btstack_uart_embedded_set_wakeup_handler( void (*the_wakeup_handler)(void)){
151+
wakeup_handler = the_wakeup_handler;
152+
}
153+
137154
static int btstack_uart_block_freertos_set_parity(int parity){
138155
return 0;
139156
}
@@ -144,6 +161,30 @@ static int btstack_uart_block_freertos_set_parity(int parity){
144161
// static void btstack_uart_block_freertos_set_csr_irq_handler( void (*csr_irq_handler)(void)){
145162
// }
146163

164+
static int btstack_uart_block_freertos_get_supported_sleep_modes(void){
165+
#ifdef HAVE_HAL_UART_DMA_SLEEP_MODES
166+
return hal_uart_dma_get_supported_sleep_modes();
167+
#else
168+
return BTSTACK_UART_SLEEP_MASK_RTS_HIGH_WAKE_ON_CTS_PULSE;
169+
#endif
170+
}
171+
172+
static void btstack_uart_block_freertos_set_sleep(btstack_uart_sleep_mode_t sleep_mode){
173+
log_info("set sleep %u", sleep_mode);
174+
if (sleep_mode == BTSTACK_UART_SLEEP_RTS_HIGH_WAKE_ON_CTS_PULSE){
175+
hal_uart_dma_set_csr_irq_handler(&btstack_uart_block_freertos_cts_pulse_isr);
176+
} else {
177+
hal_uart_dma_set_csr_irq_handler(NULL);
178+
}
179+
180+
#ifdef HAVE_HAL_UART_DMA_SLEEP_MODES
181+
hal_uart_dma_set_sleep_mode(sleep_mode);
182+
#else
183+
hal_uart_dma_set_sleep(sleep_mode != BTSTACK_UART_SLEEP_OFF);
184+
#endif
185+
log_info("done");
186+
}
187+
147188
static const btstack_uart_block_t btstack_uart_block_freertos = {
148189
/* int (*init)(hci_transport_config_uart_t * config); */ &btstack_uart_block_freertos_init,
149190
/* int (*open)(void); */ &btstack_uart_block_freertos_open,
@@ -159,9 +200,9 @@ static const btstack_uart_block_t btstack_uart_block_freertos = {
159200
#endif
160201
/* void (*receive_block)(uint8_t *buffer, uint16_t len); */ &hal_uart_dma_receive_block,
161202
/* void (*send_block)(const uint8_t *buffer, uint16_t length); */ &hal_uart_dma_send_block,
162-
/* int (*get_supported_sleep_modes); */ NULL,
163-
/* void (*set_sleep)(btstack_uart_sleep_mode_t sleep_mode); */ NULL,
164-
/* void (*set_wakeup_handler)(void (*wakeup_handler)(void)); */ NULL,
203+
/* int (*get_supported_sleep_modes); */ &btstack_uart_block_freertos_get_supported_sleep_modes,
204+
/* void (*set_sleep)(btstack_uart_sleep_mode_t sleep_mode); */ &btstack_uart_block_freertos_set_sleep,
205+
/* void (*set_wakeup_handler)(void (*wakeup_handler)(void)); */ &btstack_uart_embedded_set_wakeup_handler,
165206
NULL, NULL, NULL, NULL,
166207
};
167208

0 commit comments

Comments
 (0)