Skip to content

Commit

Permalink
update fix wifi event post from ISR
Browse files Browse the repository at this point in the history
  • Loading branch information
strongwong committed Sep 13, 2023
1 parent 1c762f9 commit a29d68b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 22 deletions.
3 changes: 2 additions & 1 deletion cores/bl616/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ void loopTask(void *pvParameters){
setup();

for(;;){

loop();
// bflb_mtimer_delay_ms(1000);
// delay(1000);
Expand All @@ -63,7 +64,7 @@ int main(void)
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//freertos
xTaskCreate(loopTask, (char *)"loop_task", 512, NULL, configMAX_PRIORITIES - 1, &loop_task_handle);
xTaskCreate(loopTask, (char *)"loop_task", 512, NULL, 1, &loop_task_handle);

vTaskStartScheduler();

Expand Down
33 changes: 15 additions & 18 deletions libraries/WiFi/src/WiFiGeneric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,26 @@ int postArduinoEvent(arduino_event_t *data)
if(data == NULL){
return -1;
}
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
arduino_event_t * event = (arduino_event_t*)malloc(sizeof(arduino_event_t));
if(event == NULL){
LOG_E("Arduino Event Malloc Failed!");
return -1;
}
memcpy(event, data, sizeof(arduino_event_t));
if (xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED) {
printf("no started!\r\n");
} else if (xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED) {
printf("suspended!\r\n");
} else if (xTaskGetSchedulerState() == taskSCHEDULER_RUNNING) {
printf("running!\r\n");
}
if (xQueueSend(_arduino_event_queue, &event, portMAX_DELAY) != pdPASS) {

// if (xQueueSend(_arduino_event_queue, &event, portMAX_DELAY) != pdPASS) {
// LOG_E("Arduino Event Send Failed!");
// return -1;
// }
if (xQueueSendFromISR(_arduino_event_queue, &event, &xHigherPriorityTaskWoken) != pdTRUE) {
LOG_E("Arduino Event Send Failed!");
return -1;
}
if( xHigherPriorityTaskWoken )
{
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
return 0;
}

Expand Down Expand Up @@ -138,11 +141,8 @@ void wifi_event_handler(uint32_t code)
}
}

if (xTaskGetSchedulerState() == taskSCHEDULER_RUNNING) {
printf("post event!\r\n");
if(arduino_event.event_id < ARDUINO_EVENT_MAX){
postArduinoEvent(&arduino_event);
}
if(arduino_event.event_id < ARDUINO_EVENT_MAX){
postArduinoEvent(&arduino_event);
}

}
Expand Down Expand Up @@ -208,6 +208,7 @@ int WiFiGenericClass::_eventCallback(arduino_event_t *event)

static void _arduino_event_task(void *arg) {
arduino_event_t *data = NULL;

for (;;) {
if(xQueueReceive(_arduino_event_queue, &data, portMAX_DELAY) == pdTRUE){
WiFiGenericClass::_eventCallback(data);
Expand Down Expand Up @@ -237,10 +238,6 @@ static bool _start_network_event_task()
}
}

// while (xTaskGetSchedulerState() != taskSCHEDULER_RUNNING)
// {
// }

if(!_arduino_event_task_handle){
xTaskCreate(_arduino_event_task, "arduino_events", 4096, NULL, configMAX_PRIORITIES - 6, &_arduino_event_task_handle);
if(!_arduino_event_task_handle){
Expand All @@ -254,7 +251,7 @@ static bool _start_network_event_task()
static bool initialized = false;
void WiFiGenericClass::tcpip_init_done(void * arg)
{
printf("tcpip init done!\r\n");
LOG_I("tcpip init done!\r\n");
initialized = _start_network_event_task();
}

Expand Down
2 changes: 1 addition & 1 deletion libraries/WiFi/src/WiFiScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void WiFiScanClass::_scanDone()
{
(WiFiScanClass::_scanCount) = wifi_mgmr_sta_scanlist_nums_get();
if(WiFiScanClass::_scanCount) {
printf("scan done:%d\r\n", WiFiScanClass::_scanCount);
// printf("scan done:%d\r\n", WiFiScanClass::_scanCount);
// WiFiScanClass::_scanResult = new wifi_ap_record_t[WiFiScanClass::_scanCount];
// if(!WiFiScanClass::_scanResult || esp_wifi_scan_get_ap_records(&(WiFiScanClass::_scanCount), (wifi_ap_record_t*)_scanResult) != ESP_OK) {
// WiFiScanClass::_scanCount = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
#define configUSE_TICK_HOOK 0
#define configCPU_CLOCK_HZ ((uint32_t)(1 * 1000 * 1000))
#define configTICK_RATE_HZ ((TickType_t)1000)
#define configMAX_PRIORITIES (7)
#define configMAX_PRIORITIES (32)
#define configMINIMAL_STACK_SIZE ((unsigned short)128) /* Only needs to be this high as some demo tasks also use this constant. In production only the idle task would use this. */
#define configTOTAL_HEAP_SIZE ((size_t)24 * 1024)
#define configMAX_TASK_NAME_LEN (16)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
* included here. In this case the path to the correct portmacro.h header file
* must be set in the compiler's include path. */
#ifndef portENTER_CRITICAL
#include "../portable/GCC/RISC-V/c906/portmacro.h"
#include "../portable/GCC/RISC-V/common/portmacro.h"
#endif

#if portBYTE_ALIGNMENT == 128
Expand Down

0 comments on commit a29d68b

Please sign in to comment.