Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
324 views
in Technique[技术] by (71.8m points)

freertos - acquire a semaphore for the esp32 antenna (bluetooth/wifi dualmode)

I am trying to build a esp32 application, where I have bluetooth and wifi enabled at the same time.

Bluetooth is used with the a2dp profile, where the esp is a sink. After receiving the data, it should be published over a UDP socket as a broadcast to the network.

The problem is the antenna. Both bt and wifi are sharing it. The a2dp stream seems to permanently acquiring the antenna and releasing it very rarely (~2 packages/min, I have ~3000 packages/min).

So my question: Is there some kind of semaphore, which can be acquired to have the full control over the antenna? So my socket would be able to send the data to the network?

I am using my esp32 with freeRTOS. The freeRTOS lib is written in C, but I am trying to wrap everything in C++. Still I think this problem is related to a C lib so I tag it with C.

I am open for any suggestions how to build that. Thanks in advance.

UPDATE:

I am using release/v3.3 from the official esp-idf repo.

I have: CONFIG_SW_COEXIST_ENABLE=y and CONFIG_SW_COEXIST_PREFERENCE_WIFI=y

I can't find CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE in my config.

The mentioned configuration doesn't work.

I tried reading the post, but can't find any "scan_window" or "scan_interval" in my lib. It was written that it is somewhere in the gap_api but can't find it.

Here is my code + config: https://github.com/Dimfred/esp32_bt_streamer

The socket client task, which should broadcast the a2dp_msg, is started here: https://github.com/Dimfred/esp32_bt_streamer/blob/master/main/app/event_handler.cpp#L22

All events popped from station/access point/bluetooth/a2dp are all caught in event_handler.hpp/cpp

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As you saw, Bluetooth has higher priority on WIFI.

Have a look at CONFIG_SW_COEXIST_ENABLE and make sure it is enabled. You also need to configure CONFIG_SW_COEXIST_PREFERENCE to WIFI. Please see the page for additional flags that you could update depending on your application.

If you want to leave the hardware responsible for handling the co-existing devices (BL and WIFI), you can disable CONFIG_SW_COEXIST_ENABLE and reduce the scan window and increase the scan interval of the BL to leave time for WIFI to get access to the antenna. See this post for more details.

To answer your original question about a possible semaphore/mutex. I doubt there is one accessible for you to use and I would leave the API (software) handling the co-existing modules accessing the antenna. But you can always checkout what the code is doing once CONFIG_SW_COEXIST_ENABLE is set (the flag is renamed to CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE). See https://github.com/espressif/esp-idf/blob/81ca1c01395f604972fbf141cfbe49764a746023/components/esp_wifi/src/phy_init.c


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...