Skip to content

Commit becb28c

Browse files
committed
Add option for restarting radio using callback function
1 parent 4e7c144 commit becb28c

9 files changed

Lines changed: 82 additions & 62 deletions

File tree

Kconfig

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,14 @@ menu "ESP-Hosted config"
257257

258258
menu "Host SPI GPIOs Config"
259259

260+
config ESP_HOSTED_SPI_RESET_SLAVE_USING_CALLBACK
261+
bool "Reset slave using callback function"
262+
default n
263+
help
264+
Select this option if you want to reset the slave device using a callback function instead of using a GPIO pin.
265+
This is useful if the reset line of the slave device is not connected to a GPIO pin of the host device.
266+
The callback function should be defined as int hosted_reset_slave_callback(void); in user code.
267+
260268
choice ESP_HOSTED_SPI_HANDSHAKE_GPIO_CONFIG
261269
bool "Handshake GPIO Config"
262270
default ESP_HOSTED_HS_ACTIVE_HIGH
@@ -278,6 +286,7 @@ menu "ESP-Hosted config"
278286
endchoice
279287

280288
choice ESP_HOSTED_SPI_RESET_GPIO_CONFIG
289+
depends on !ESP_HOSTED_SPI_RESET_SLAVE_USING_CALLBACK
281290
bool "Reset GPIO Config"
282291
default ESP_HOSTED_SPI_RESET_ACTIVE_HIGH
283292
help
@@ -563,6 +572,7 @@ menu "ESP-Hosted config"
563572
default 100
564573

565574
config ESP_HOSTED_SPI_GPIO_RESET_SLAVE
575+
depends on !ESP_HOSTED_SPI_RESET_SLAVE_USING_CALLBACK
566576
int "GPIO pin for Resetting slave ESP"
567577
default 54 if ESP_HOSTED_P4_C5_CORE_BOARD || ESP_HOSTED_P4_C6_CORE_BOARD || ESP_HOSTED_P4_C61_CORE_BOARD
568578
default 9 if ESP32P4_EYE_C6_BOARD
@@ -640,7 +650,16 @@ ESP32XX_SPI_CLK_FREQ_RANGE_MAX := 40
640650
menu "Hosted SDIO Configuration"
641651
depends on ESP_HOSTED_SDIO_HOST_INTERFACE
642652

653+
config ESP_HOSTED_SDIO_RESET_SLAVE_USING_CALLBACK
654+
bool "Reset slave using callback function"
655+
default n
656+
help
657+
Select this option if you want to reset the slave device using a callback function instead of using a GPIO pin.
658+
This is useful if the reset line of the slave device is not connected to a GPIO pin of the host device.
659+
The callback function should be defined as int hosted_reset_slave_callback(void); in user code.
660+
643661
choice ESP_HOSTED_SDIO_RESET_GPIO_CONFIG
662+
depends on !ESP_HOSTED_SDIO_RESET_SLAVE_USING_CALLBACK
644663
bool "RESET GPIO Config"
645664
default ESP_HOSTED_SDIO_RESET_ACTIVE_HIGH
646665
help
@@ -1048,6 +1067,7 @@ ESP32XX_SDIO_CLK_FREQ_KHZ_RANGE_MAX := 50000
10481067
endif
10491068

10501069
config ESP_HOSTED_SDIO_GPIO_RESET_SLAVE
1070+
depends on !ESP_HOSTED_SDIO_RESET_SLAVE_USING_CALLBACK
10511071
int "GPIO pin for Resetting slave ESP"
10521072
default 9 if ESP32P4_EYE_C6_BOARD
10531073
default 54 if IDF_TARGET_ESP32P4
@@ -1156,7 +1176,16 @@ ESP32XX_SDIO_CLK_FREQ_KHZ_RANGE_MAX := 50000
11561176
default 4 if ESP_HOSTED_SPI_HD_PRIV_INTERFACE_4_DATA_LINES
11571177
default 2 if ESP_HOSTED_SPI_HD_PRIV_INTERFACE_2_DATA_LINES
11581178

1179+
config ESP_HOSTED_SPI_HD_RESET_SLAVE_USING_CALLBACK
1180+
bool "Reset slave using callback function"
1181+
default n
1182+
help
1183+
Select this option if you want to reset the slave device using a callback function instead of using a GPIO pin.
1184+
This is useful if the reset line of the slave device is not connected to a GPIO pin of the host device.
1185+
The callback function should be defined as int hosted_reset_slave_callback(void); in user code.
1186+
11591187
choice ESP_HOSTED_SPI_HD_RESET_GPIO_CONFIG
1188+
depends on !ESP_HOSTED_SPI_HD_RESET_SLAVE_USING_CALLBACK
11601189
bool "RESET GPIO Config"
11611190
default ESP_HOSTED_SPI_HD_RESET_ACTIVE_HIGH
11621191
help
@@ -1432,6 +1461,7 @@ ESP32XX_SDIO_CLK_FREQ_KHZ_RANGE_MAX := 50000
14321461
default 100
14331462

14341463
config ESP_HOSTED_SPI_HD_GPIO_RESET_SLAVE
1464+
depends on !ESP_HOSTED_SPI_HD_RESET_SLAVE_USING_CALLBACK
14351465
int "GPIO pin for Resetting slave ESP"
14361466
default 54 if ESP_HOSTED_P4_C5_CORE_BOARD || ESP_HOSTED_P4_C6_CORE_BOARD || ESP_HOSTED_P4_C61_CORE_BOARD
14371467
default 9 if ESP32P4_EYE_C6_BOARD
@@ -1495,7 +1525,16 @@ ESP32XX_SPI_HD_CLK_FREQ_RANGE_MAX := 40
14951525
menu "UART Configuration"
14961526
depends on ESP_HOSTED_UART_HOST_INTERFACE
14971527

1528+
config ESP_HOSTED_UART_RESET_SLAVE_USING_CALLBACK
1529+
bool "Reset slave using callback function"
1530+
default n
1531+
help
1532+
Select this option if you want to reset the slave device using a callback function instead of using a GPIO pin.
1533+
This is useful if the reset line of the slave device is not connected to a GPIO pin of the host device.
1534+
The callback function should be defined as int hosted_reset_slave_callback(void); in user code.
1535+
14981536
choice ESP_HOSTED_UART_RESET_GPIO_CONFIG
1537+
depends on !ESP_HOSTED_UART_RESET_SLAVE_USING_CALLBACK
14991538
bool "RESET GPIO Config"
15001539
default ESP_HOSTED_UART_RESET_ACTIVE_HIGH
15011540
help
@@ -1637,6 +1676,7 @@ ESP32XX_SPI_HD_CLK_FREQ_RANGE_MAX := 40
16371676
default 2 if ESP_HOSTED_UART_PRIV_STOP_BITS_2
16381677

16391678
config ESP_HOSTED_UART_GPIO_RESET_SLAVE
1679+
depends on !ESP_HOSTED_UART_RESET_SLAVE_USING_CALLBACK
16401680
int "GPIO pin for Resetting slave ESP"
16411681
default 54 if ESP_HOSTED_P4_C5_CORE_BOARD || ESP_HOSTED_P4_C6_CORE_BOARD || ESP_HOSTED_P4_C61_CORE_BOARD
16421682
default 9 if ESP32P4_EYE_C6_BOARD
@@ -1722,6 +1762,11 @@ ESP32XX_SPI_HD_CLK_FREQ_RANGE_MAX := 40
17221762
default n if ESP_HOSTED_SDIO_RESET_ACTIVE_HIGH || ESP_HOSTED_SPI_RESET_ACTIVE_HIGH || ESP_HOSTED_SPI_HD_RESET_ACTIVE_HIGH || ESP_HOSTED_UART_RESET_ACTIVE_HIGH
17231763
default y if ESP_HOSTED_SDIO_RESET_ACTIVE_LOW || ESP_HOSTED_SPI_RESET_ACTIVE_LOW || ESP_HOSTED_SPI_HD_RESET_ACTIVE_LOW || ESP_HOSTED_UART_RESET_ACTIVE_LOW
17241764

1765+
config ESP_HOSTED_RESET_SLAVE_USING_CALLBACK
1766+
bool
1767+
default n if !ESP_HOSTED_SPI_RESET_SLAVE_USING_CALLBACK && !ESP_HOSTED_SDIO_RESET_SLAVE_USING_CALLBACK && !ESP_HOSTED_SPI_HD_RESET_SLAVE_USING_CALLBACK && !ESP_HOSTED_UART_RESET_SLAVE_USING_CALLBACK
1768+
default y if ESP_HOSTED_SPI_RESET_SLAVE_USING_CALLBACK || ESP_HOSTED_SDIO_RESET_SLAVE_USING_CALLBACK || ESP_HOSTED_SPI_HD_RESET_SLAVE_USING_CALLBACK || ESP_HOSTED_UART_RESET_SLAVE_USING_CALLBACK
1769+
17251770
menu "Bluetooth Support"
17261771

17271772
comment "Following options must be set before this option can be enabled"

host/drivers/power_save/power_save_drv.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ static int notify_slave_host_power_save_stop(void)
195195
int hold_slave_reset_gpio_pre_power_save(void)
196196
{
197197
#if H_HOST_PS_ALLOWED
198+
#ifndef CONFIG_ESP_HOSTED_RESET_SLAVE_USING_CALLBACK
198199
gpio_pin_t reset_pin = { .port = H_GPIO_PORT_RESET, .pin = H_GPIO_PIN_RESET };
199200

200201
if (ESP_TRANSPORT_OK != esp_hosted_transport_get_reset_config(&reset_pin)) {
@@ -208,13 +209,15 @@ int hold_slave_reset_gpio_pre_power_save(void)
208209
}
209210

210211
return g_h.funcs->_h_hold_gpio(reset_pin.port, reset_pin.pin, H_ENABLE);
212+
#endif
211213
#endif
212214
return 0;
213215
}
214216

215217
int release_slave_reset_gpio_post_wakeup(void)
216218
{
217219
#if H_HOST_PS_ALLOWED
220+
#ifndef CONFIG_ESP_HOSTED_RESET_SLAVE_USING_CALLBACK
218221
gpio_pin_t reset_pin = { .port = H_GPIO_PORT_RESET, .pin = H_GPIO_PIN_RESET };
219222

220223
if (ESP_TRANSPORT_OK != esp_hosted_transport_get_reset_config(&reset_pin)) {
@@ -228,6 +231,7 @@ int release_slave_reset_gpio_post_wakeup(void)
228231
}
229232

230233
return g_h.funcs->_h_hold_gpio(reset_pin.port, reset_pin.pin, H_DISABLE);
234+
#endif
231235
#endif
232236
return 0;
233237
}

host/drivers/transport/sdio/sdio_drv.c

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,14 +1509,9 @@ static esp_err_t transport_card_init(void *bus_handle, uint32_t timeout_ms)
15091509
return res;
15101510
}
15111511

1512-
static esp_err_t transport_gpio_reset(void *bus_handle, gpio_pin_t reset_pin)
1512+
static esp_err_t transport_gpio_reset(void *bus_handle)
15131513
{
1514-
g_h.funcs->_h_config_gpio(reset_pin.port, reset_pin.pin, H_GPIO_MODE_DEF_OUTPUT);
1515-
g_h.funcs->_h_write_gpio(reset_pin.port, reset_pin.pin, H_RESET_VAL_ACTIVE);
1516-
g_h.funcs->_h_msleep(10);
1517-
g_h.funcs->_h_write_gpio(reset_pin.port, reset_pin.pin, H_RESET_VAL_INACTIVE);
1518-
g_h.funcs->_h_msleep(10);
1519-
g_h.funcs->_h_write_gpio(reset_pin.port, reset_pin.pin, H_RESET_VAL_ACTIVE);
1514+
g_h.funcs->_h_restart_slave();
15201515
g_h.funcs->_h_msleep(H_HOST_SDIO_RESET_DELAY_MS);
15211516
return ESP_OK;
15221517
}
@@ -1526,14 +1521,6 @@ static esp_err_t transport_gpio_reset(void *bus_handle, gpio_pin_t reset_pin)
15261521
int ensure_slave_bus_ready(void *bus_handle)
15271522
{
15281523
int res = -1;
1529-
gpio_pin_t reset_pin = { .port = H_GPIO_PORT_RESET, .pin = H_GPIO_PIN_RESET };
1530-
1531-
if (ESP_TRANSPORT_OK != esp_hosted_transport_get_reset_config(&reset_pin)) {
1532-
ESP_LOGE(TAG, "Unable to get RESET config for transport");
1533-
return -1;
1534-
}
1535-
1536-
assert(reset_pin.pin != -1);
15371524

15381525
release_slave_reset_gpio_post_wakeup();
15391526

@@ -1552,7 +1539,7 @@ int ensure_slave_bus_ready(void *bus_handle)
15521539
/* Give a chance to reset and recover the slave */
15531540
if (res) {
15541541
ESP_LOGI(TAG, "Attempt slave reset");
1555-
transport_gpio_reset(bus_handle, reset_pin);
1542+
transport_gpio_reset(bus_handle);
15561543
}
15571544

15581545
res = transport_card_init(bus_handle, CARD_INIT_TIMEOUT_MS);

host/drivers/transport/spi/spi_drv.c

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -860,15 +860,10 @@ void check_if_max_freq_used(uint8_t chip_type)
860860
break;
861861
}
862862
}
863-
static esp_err_t transport_gpio_reset(void *bus_handle, gpio_pin_t reset_pin)
863+
static esp_err_t transport_gpio_reset(void *bus_handle)
864864
{
865-
ESP_LOGI(TAG, "Resetting slave on SPI bus with pin %d", reset_pin.pin);
866-
g_h.funcs->_h_config_gpio(reset_pin.port, reset_pin.pin, H_GPIO_MODE_DEF_OUTPUT);
867-
g_h.funcs->_h_write_gpio(reset_pin.port, reset_pin.pin, H_RESET_VAL_ACTIVE);
868-
g_h.funcs->_h_msleep(10);
869-
g_h.funcs->_h_write_gpio(reset_pin.port, reset_pin.pin, H_RESET_VAL_INACTIVE);
870-
g_h.funcs->_h_msleep(10);
871-
g_h.funcs->_h_write_gpio(reset_pin.port, reset_pin.pin, H_RESET_VAL_ACTIVE);
865+
ESP_LOGI(TAG, "Resetting slave on SPI bus");
866+
g_h.funcs->_h_restart_slave();
872867
/* Delay for a short while to allow co-processor to take control
873868
* of GPIO signals after reset. Otherwise, we may false detect on
874869
* the GPIOs going high during the reset.
@@ -880,22 +875,14 @@ static esp_err_t transport_gpio_reset(void *bus_handle, gpio_pin_t reset_pin)
880875
int ensure_slave_bus_ready(void *bus_handle)
881876
{
882877
esp_err_t res = ESP_OK;
883-
gpio_pin_t reset_pin = { .port = H_GPIO_PORT_RESET, .pin = H_GPIO_PIN_RESET };
884-
885-
if (ESP_TRANSPORT_OK != esp_hosted_transport_get_reset_config(&reset_pin)) {
886-
ESP_LOGE(TAG, "Unable to get RESET config for transport");
887-
return ESP_FAIL;
888-
}
889-
890-
assert(reset_pin.pin != -1);
891878

892879
release_slave_reset_gpio_post_wakeup();
893880

894881
if (esp_hosted_woke_from_power_save()) {
895882
stop_host_power_save();
896883
} else {
897884
ESP_LOGI(TAG, "Resetting slave");
898-
transport_gpio_reset(bus_handle, reset_pin);
885+
transport_gpio_reset(bus_handle);
899886
}
900887

901888
return res;

host/drivers/transport/spi_hd/spi_hd_drv.c

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -895,26 +895,13 @@ void check_if_max_freq_used(uint8_t chip_type)
895895
int ensure_slave_bus_ready(void *bus_handle)
896896
{
897897
esp_err_t res = ESP_OK;
898-
gpio_pin_t reset_pin = { .port = H_GPIO_PORT_RESET, .pin = H_GPIO_PIN_RESET };
899-
900-
if (ESP_TRANSPORT_OK != esp_hosted_transport_get_reset_config(&reset_pin)) {
901-
ESP_LOGE(TAG, "Unable to get RESET config for transport");
902-
return ESP_FAIL;
903-
}
904-
905-
assert(reset_pin.pin != -1);
906898

907899
release_slave_reset_gpio_post_wakeup();
908900

909901
if (!esp_hosted_woke_from_power_save()) {
910902
/* Reset the slave */
911-
ESP_LOGI(TAG, "Resetting slave on SPI HD bus with pin %d", reset_pin.pin);
912-
g_h.funcs->_h_config_gpio(reset_pin.port, reset_pin.pin, H_GPIO_MODE_DEF_OUTPUT);
913-
g_h.funcs->_h_write_gpio(reset_pin.port, reset_pin.pin, H_RESET_VAL_ACTIVE);
914-
g_h.funcs->_h_msleep(10);
915-
g_h.funcs->_h_write_gpio(reset_pin.port, reset_pin.pin, H_RESET_VAL_INACTIVE);
916-
g_h.funcs->_h_msleep(10);
917-
g_h.funcs->_h_write_gpio(reset_pin.port, reset_pin.pin, H_RESET_VAL_ACTIVE);
903+
ESP_LOGI(TAG, "Resetting slave on SPI HD bus");
904+
g_h.funcs->_h_restart_slave();
918905
} else {
919906
stop_host_power_save();
920907
}

host/drivers/transport/uart/uart_drv.c

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -660,26 +660,13 @@ void bus_deinit_internal(void *bus_handle)
660660
int ensure_slave_bus_ready(void *bus_handle)
661661
{
662662
esp_err_t res = ESP_OK;
663-
gpio_pin_t reset_pin = { .port = H_GPIO_PORT_RESET, .pin = H_GPIO_PIN_RESET };
664-
665-
if (ESP_TRANSPORT_OK != esp_hosted_transport_get_reset_config(&reset_pin)) {
666-
ESP_LOGE(TAG, "Unable to get RESET config for transport");
667-
return ESP_FAIL;
668-
}
669-
670-
assert(reset_pin.pin != -1);
671663

672664
release_slave_reset_gpio_post_wakeup();
673665

674666
if (!esp_hosted_woke_from_power_save()) {
675667
/* Reset the slave */
676668
ESP_LOGI(TAG, "Resetting slave on UART bus with pin %d", reset_pin.pin);
677-
g_h.funcs->_h_config_gpio(reset_pin.port, reset_pin.pin, H_GPIO_MODE_DEF_OUTPUT);
678-
g_h.funcs->_h_write_gpio(reset_pin.port, reset_pin.pin, H_RESET_VAL_ACTIVE);
679-
g_h.funcs->_h_msleep(10);
680-
g_h.funcs->_h_write_gpio(reset_pin.port, reset_pin.pin, H_RESET_VAL_INACTIVE);
681-
g_h.funcs->_h_msleep(10);
682-
g_h.funcs->_h_write_gpio(reset_pin.port, reset_pin.pin, H_RESET_VAL_ACTIVE);
669+
g_h.funcs->_h_restart_slave();
683670
// flush input
684671
if (uart_handle) {
685672
g_h.funcs->_h_uart_flush_input(uart_handle);

host/esp_hosted_os_abstraction.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ typedef struct {
121121
/* 64 */ int (*_h_config_host_power_save_hal_impl)(uint32_t power_save_type, void* gpio_port, uint32_t gpio_num, int level);
122122
/* 65 */ int (*_h_start_host_power_save_hal_impl)(uint32_t power_save_type);
123123
/* 66 */ int (*_h_event_post)(esp_event_base_t event_base, int32_t event_id, void* event_data, size_t event_data_size, uint32_t ticks_to_wait);
124+
125+
/* 67 */ int (*_h_restart_slave)(void);
124126
} hosted_osi_funcs_t;
125127

126128
struct hosted_config_t {

host/port/esp/freertos/include/port_esp_hosted_host_config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,11 @@ enum {
397397
#endif
398398

399399
/* Generic reset pin config */
400+
#ifdef CONFIG_ESP_HOSTED_SDIO_RESET_SLAVE_USING_CALLBACK
401+
#define H_GPIO_PIN_RESET -1
402+
#else
400403
#define H_GPIO_PIN_RESET CONFIG_ESP_HOSTED_GPIO_SLAVE_RESET_SLAVE
404+
#endif
401405
#define H_GPIO_PORT_RESET NULL
402406

403407
/* If Reset pin is Enable, it is Active High.

host/port/esp/freertos/src/port_esp_hosted_host_os.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,22 @@ int hosted_event_post(esp_event_base_t event_base, int32_t event_id,
834834
return esp_event_post(event_base, event_id, event_data, event_data_size, ticks_to_wait);
835835
}
836836

837+
int hosted_restart_slave(void)
838+
{
839+
#ifndef CONFIG_ESP_HOSTED_RESET_SLAVE_USING_CALLBACK
840+
hosted_config_gpio(H_GPIO_PORT_RESET, H_GPIO_PIN_RESET, H_GPIO_MODE_DEF_OUTPUT);
841+
hosted_write_gpio(H_GPIO_PORT_RESET, H_GPIO_PIN_RESET, H_RESET_VAL_ACTIVE);
842+
hosted_msleep(10);
843+
hosted_write_gpio(H_GPIO_PORT_RESET, H_GPIO_PIN_RESET, H_RESET_VAL_INACTIVE);
844+
hosted_msleep(10);
845+
hosted_write_gpio(H_GPIO_PORT_RESET, H_GPIO_PIN_RESET, H_RESET_VAL_ACTIVE);
846+
return 0;
847+
#else
848+
extern int hosted_reset_slave_callback(void);
849+
return hosted_reset_slave_callback();
850+
#endif
851+
}
852+
837853
void hosted_log_write(int level,
838854
const char *tag,
839855
const char *format, ...)
@@ -1002,4 +1018,5 @@ hosted_osi_funcs_t g_hosted_osi_funcs = {
10021018
._h_config_host_power_save_hal_impl = hosted_config_host_power_save,
10031019
._h_start_host_power_save_hal_impl = hosted_start_host_power_save,
10041020
._h_event_post = hosted_event_post ,
1021+
._h_restart_slave = hosted_restart_slave ,
10051022
};

0 commit comments

Comments
 (0)