make isr function save remove LOG

This commit is contained in:
Martijn Scheepers
2022-05-12 08:36:39 +02:00
parent 0a9197455a
commit 56d90c89a5
5 changed files with 38 additions and 79 deletions

View File

@@ -173,7 +173,7 @@ void h2201_a2dp_eventhandler(uint16_t event, void *p_param)
/* callback for A2DP sink */
void h2201_a2dp_callback(esp_a2d_cb_event_t event, esp_a2d_cb_param_t *param)
{
h2201_dispatcher_work_dispatch(h2201_a2dp_eventhandler, event, param, sizeof(esp_a2d_cb_param_t), NULL);
h2201_dispatcher_dowork(h2201_a2dp_eventhandler, event, param, sizeof(esp_a2d_cb_param_t), NULL);
}
void h2201_a2dp_create_sink(void)

View File

@@ -12,7 +12,6 @@
#include "H2201_a2dp.h"
void h2201_bluetooth_eventhandler(uint16_t event, void *p_param)
// void h2201_bluetooth_gap_register_callback(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
{
// ESP_LOGI(H2201_BLUETOOTH_TAG, "gap register event: %d", event);
esp_bt_gap_cb_param_t *param = (esp_bt_gap_cb_param_t *)(p_param);
@@ -65,7 +64,7 @@ void h2201_bluetooth_eventhandler(uint16_t event, void *p_param)
void h2201_bluetooth_gap_register_callback(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
{
h2201_dispatcher_work_dispatch(h2201_bluetooth_eventhandler, event, param, sizeof(esp_bt_gap_cb_param_t), NULL);
h2201_dispatcher_dowork(h2201_bluetooth_eventhandler, event, param, sizeof(esp_bt_gap_cb_param_t), NULL);
}
void h2201_bluetooth_init()

View File

@@ -15,8 +15,8 @@
// static QueueHandle_t H2201_button_event_queue = NULL;
// static QueueHandle_t H2201_encoder_volume_queue = NULL;
static QueueHandle_t h2201_encoder_queue = NULL;
static TaskHandle_t h2201_encoder_task_handle = NULL;
// static QueueHandle_t h2201_encoder_queue = NULL;
// static TaskHandle_t h2201_encoder_task_handle = NULL;
// static uint32_t encoder_pcnt_unit = 0;
//#define UP 1
@@ -109,13 +109,13 @@ bool H2201_dipswitch_read(int sw)
//******************* buttons ********************************
static void IRAM_ATTR gpio_isr_handler(void *arg)
static void IRAM_ATTR H2201_buttons_ISR(void *arg)
{
uint32_t io_num = (uint32_t)arg;
// if (gpio_get_level(io_num) == 0)
//{
// h2201_dispatcher_add_event(BUTTON_EVENTS, BUTTON_PRESS_EVENT, io_num);
h2201_dispatcher_work_dispatch_fromISR(h2201_buttons_eventhandler, BUTTON_PRESS_EVENT, &io_num);
h2201_dispatcher_dowork_fromISR(h2201_buttons_eventhandler, BUTTON_PRESS_EVENT, &io_num, sizeof(io_num));
// }
}
@@ -136,24 +136,22 @@ void H2201_buttons_init(void)
// but will remove the glitches on GPIO36 and GPIO39.
adc_power_acquire();
// gpio_install_isr_service((1L << ESP_INTR_FLAG_EDGE) | (1L << ESP_INTR_FLAG_LEVEL1));
// gpio_install_isr_service(ESP_INTR_FLAG_EDGE);
gpio_install_isr_service(0); // no flags needed
gpio_isr_handler_add(BUTTON_1, gpio_isr_handler, (void *)BUTTON_1);
gpio_isr_handler_add(BUTTON_2, gpio_isr_handler, (void *)BUTTON_2);
gpio_isr_handler_add(BUTTON_3, gpio_isr_handler, (void *)BUTTON_3);
gpio_isr_handler_add(BUTTON_4, gpio_isr_handler, (void *)BUTTON_4);
gpio_isr_handler_add(BUTTON_1, H2201_buttons_ISR, (void *)BUTTON_1);
gpio_isr_handler_add(BUTTON_2, H2201_buttons_ISR, (void *)BUTTON_2);
gpio_isr_handler_add(BUTTON_3, H2201_buttons_ISR, (void *)BUTTON_3);
gpio_isr_handler_add(BUTTON_4, H2201_buttons_ISR, (void *)BUTTON_4);
}
//******************* encoder ********************************
bool IRAM_ATTR example_pcnt_on_reach(pcnt_unit_handle_t unit, pcnt_watch_event_data_t *edata, void *user_ctx)
bool IRAM_ATTR H2201_encoder_ISR(pcnt_unit_handle_t unit, pcnt_watch_event_data_t *edata, void *user_ctx)
{
if (edata->watch_point_value == 1)
{
return h2201_dispatcher_dowork_fromISR(h2201_buttons_eventhandler, ENCODER_UP_EVENT);
return h2201_dispatcher_dowork_simple_fromISR(h2201_buttons_eventhandler, ENCODER_UP_EVENT);
}
else
{
return h2201_dispatcher_dowork_fromISR(h2201_buttons_eventhandler, ENCODER_DOWN_EVENT);
return h2201_dispatcher_dowork_simple_fromISR(h2201_buttons_eventhandler, ENCODER_DOWN_EVENT);
}
}
@@ -191,8 +189,6 @@ void H2201_encoder_init(void)
ESP_ERROR_CHECK(pcnt_channel_set_edge_action(pcnt_chan_b, PCNT_CHANNEL_EDGE_ACTION_INCREASE, PCNT_CHANNEL_EDGE_ACTION_DECREASE));
ESP_ERROR_CHECK(pcnt_channel_set_level_action(pcnt_chan_b, PCNT_CHANNEL_LEVEL_ACTION_KEEP, PCNT_CHANNEL_LEVEL_ACTION_INVERSE));
// ESP_LOGI(TAG, "add watch points and register callbacks");
// int watch_points[] = {ROTARY_LOW_LIMIT, -50, 0, 50, ROTARY_HIGH_LIMIT};
int watch_points[] = {ROTARY_LOW_LIMIT, ROTARY_HIGH_LIMIT};
for (size_t i = 0; i < sizeof(watch_points) / sizeof(watch_points[0]); i++)
{
@@ -200,15 +196,11 @@ void H2201_encoder_init(void)
}
pcnt_event_callbacks_t cbs = {
.on_reach = example_pcnt_on_reach,
.on_reach = H2201_encoder_ISR,
};
h2201_encoder_queue = xQueueCreate(10, sizeof(int));
// ESP_ERROR_CHECK(pcnt_unit_register_event_callbacks(pcnt_unit, &cbs, queue));
ESP_ERROR_CHECK(pcnt_unit_register_event_callbacks(pcnt_unit, &cbs, h2201_encoder_queue));
ESP_ERROR_CHECK(pcnt_unit_register_event_callbacks(pcnt_unit, &cbs, NULL));
ESP_ERROR_CHECK(pcnt_unit_clear_count(pcnt_unit));
ESP_ERROR_CHECK(pcnt_unit_start(pcnt_unit));
// xTaskCreate(H2201_encoder_task, "encoderT", 4096, NULL, configMAX_PRIORITIES - 3, &h2201_encoder_task_handle);
}

View File

@@ -7,31 +7,13 @@
#include "esp_heap_task_info.h"
#include "esp_log.h"
//#include "esp_hw_log.h"
//#include "esp_event_base.h"
#include "H2201_dispatcher.h"
static QueueHandle_t h2201_dispatcher_queue = NULL;
static TaskHandle_t h2201_dispatcher_task_handle = NULL;
// esp_event_loop_handle_t h2201_dispatcher_eventloop;
static bool h2201_dispatcher_send_msg(h2201_dispatcher_msg_t *msg)
{
if (msg == NULL)
{
return false;
}
if (xQueueSend(h2201_dispatcher_queue, msg, 10 / portTICK_PERIOD_MS) != pdTRUE)
{
ESP_LOGE(H2201_DISPATCHER_TAG, "%s xQueue send failed", __func__);
return false;
}
return true;
}
bool h2201_dispatcher_work_dispatch(h2201_dispatcher_cb_t p_cback, uint16_t event, void *p_params, int param_len, h2201_dispatcher_copy_cb_t p_copy_cback)
bool h2201_dispatcher_dowork(h2201_dispatcher_cb_t p_cback, uint16_t event, void *p_params, int param_len, h2201_dispatcher_copy_cb_t p_copy_cback)
{
ESP_LOGD(H2201_DISPATCHER_TAG, "%s event 0x%x, param len %d", __func__, event, param_len);
@@ -44,7 +26,12 @@ bool h2201_dispatcher_work_dispatch(h2201_dispatcher_cb_t p_cback, uint16_t even
if (param_len == 0)
{
return h2201_dispatcher_send_msg(&msg);
if (xQueueSend(h2201_dispatcher_queue, &msg, 10 / portTICK_PERIOD_MS) != pdTRUE)
{
ESP_LOGE(H2201_DISPATCHER_TAG, "%s xQueue send failed", __func__);
return false;
}
return true;
}
else if (p_params && param_len > 0)
{
@@ -56,17 +43,19 @@ bool h2201_dispatcher_work_dispatch(h2201_dispatcher_cb_t p_cback, uint16_t even
{
p_copy_cback(&msg, msg.param, p_params);
}
return h2201_dispatcher_send_msg(&msg);
if (xQueueSend(h2201_dispatcher_queue, &msg, 10 / portTICK_PERIOD_MS) != pdTRUE)
{
ESP_LOGE(H2201_DISPATCHER_TAG, "%s xQueue send failed", __func__);
return false;
}
return true;
}
}
return false;
}
void h2201_dispatcher_work_dispatch_fromISR(h2201_dispatcher_cb_t p_cback, uint16_t event, void *p_params) //, int param_len)
void h2201_dispatcher_dowork_fromISR(h2201_dispatcher_cb_t p_cback, uint16_t event, void *p_params, int param_len)
{
// ESP_LOGD(H2201_DISPATCHER_TAG, "%s event 0x%x, param len %d", __func__, event, param_len);
h2201_dispatcher_msg_t msg;
memset(&msg, 0, sizeof(h2201_dispatcher_msg_t));
@@ -74,17 +63,11 @@ void h2201_dispatcher_work_dispatch_fromISR(h2201_dispatcher_cb_t p_cback, uint1
msg.event = event;
msg.cb = p_cback;
int param_len = 0;
if (p_params)
{
param_len = sizeof(p_params);
}
if (param_len == 0)
{
if (xQueueSendFromISR(h2201_dispatcher_queue, &msg, NULL) != pdTRUE)
{
ESP_LOGE(H2201_DISPATCHER_TAG, "%s xQueue send failed", __func__);
esp_rom_printf("%s xQueue send failed\n", __func__);
return;
}
}
@@ -95,15 +78,14 @@ void h2201_dispatcher_work_dispatch_fromISR(h2201_dispatcher_cb_t p_cback, uint1
memcpy(msg.param, p_params, param_len);
if (xQueueSendFromISR(h2201_dispatcher_queue, &msg, NULL) != pdTRUE)
{
ESP_LOGE(H2201_DISPATCHER_TAG, "%s xQueue send failed", __func__);
esp_rom_printf("%s xQueue send failed\n", __func__);
return;
}
}
}
}
bool h2201_dispatcher_dowork_fromISR(h2201_dispatcher_cb_t p_cback, uint16_t event)
bool h2201_dispatcher_dowork_simple_fromISR(h2201_dispatcher_cb_t p_cback, uint16_t event)
{
h2201_dispatcher_msg_t msg;
// memset(&msg, 0, sizeof(h2201_dispatcher_msg_t));
@@ -116,7 +98,7 @@ bool h2201_dispatcher_dowork_fromISR(h2201_dispatcher_cb_t p_cback, uint16_t eve
BaseType_t high_task_wakeup;
if (xQueueSendFromISR(h2201_dispatcher_queue, &msg, &high_task_wakeup) != pdTRUE)
{
//ESP_HW_LOGE(H2201_DISPATCHER_TAG, "%s xQueue send failed", __func__);
// ESP_HW_LOGE(H2201_DISPATCHER_TAG, "%s xQueue send failed", __func__);
esp_rom_printf("%s xQueue send failed\n", __func__);
}
return (high_task_wakeup == pdTRUE);
@@ -191,6 +173,6 @@ static void H2201_dispatcher_task(void *arg)
void H2201_dispacther_init(void)
{
h2201_dispatcher_queue = xQueueCreate(20, sizeof(h2201_dispatcher_msg_t));
h2201_dispatcher_queue = xQueueCreate(H2201_DISPATCHER_QUEUE_SIZE, sizeof(h2201_dispatcher_msg_t));
xTaskCreate(H2201_dispatcher_task, "DispatcherT", 4096, NULL, configMAX_PRIORITIES - 3, &h2201_dispatcher_task_handle);
}

View File

@@ -5,21 +5,7 @@
#define H2201_DISPATCHER_TAG "H2201_DISPATCHER"
// ESP_EVENT_DECLARE_BASE(TASK_EVENTS); // declaration of the task events family
// enum
// {
// TASK_ITERATION_EVENT,
// TASK_BUTTON_EVENT
// };
/// void h2201_dispatcher_add_event(esp_event_base_t event_base, int32_t event_id, void *args);
enum
{
ENCODER_UP = 0,
ENCODER_DOWN = 1,
BUTTON_PRESS = 2,
};
#define H2201_DISPATCHER_QUEUE_SIZE 30
#define BT_APP_SIG_WORK_DISPATCH (0x01)
@@ -44,9 +30,9 @@ typedef void (*h2201_dispatcher_copy_cb_t)(h2201_dispatcher_msg_t *msg, void *p_
/**
* @brief work dispatcher for the application task
*/
bool h2201_dispatcher_work_dispatch(h2201_dispatcher_cb_t p_cback, uint16_t event, void *p_params, int param_len, h2201_dispatcher_copy_cb_t p_copy_cback);
void h2201_dispatcher_work_dispatch_fromISR(h2201_dispatcher_cb_t p_cback, uint16_t event, void *p_params); //, int param_len);
bool h2201_dispatcher_dowork_fromISR(h2201_dispatcher_cb_t p_cback, uint16_t event);
bool h2201_dispatcher_dowork(h2201_dispatcher_cb_t p_cback, uint16_t event, void *p_params, int param_len, h2201_dispatcher_copy_cb_t p_copy_cback);
void h2201_dispatcher_dowork_fromISR(h2201_dispatcher_cb_t p_cback, uint16_t event, void *p_params, int param_len);
bool h2201_dispatcher_dowork_simple_fromISR(h2201_dispatcher_cb_t p_cback, uint16_t event);
void H2201_dispacther_init(void);