#include <stdio.h>
#include <inttypes.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"
#include "driver/gpio.h"
#include "hal/gpio_ll.h"
#include "driver/dedic_gpio.h"
#define DEBUG 0
#ifdef CONFIG_IDF_TARGET_ESP32
int GPIO_PIN[] = {12, 13, 14, 15, 16, 17, 18, 19};
#else
int GPIO_PIN[] = {21, 46, 18, 17, 19, 20, 3, 14};
#endif
#define gpio_digital_write(GPIO_PIN, data) \
do { \
if (data) { \
gpio_set_level( GPIO_PIN, 1 ); \
} else { \
gpio_set_level( GPIO_PIN, 0 ); \
} \
} while (0)
#define reg_digital_write(GPIO_PIN, data) \
do { \
if (data) { \
if ( GPIO_PIN < 32 ) GPIO.out_w1ts = (1 <<
GPIO_PIN); \
else GPIO.out1_w1ts.val = (1 << (GPIO_PIN - 32)); \
} else { \
if ( GPIO_PIN < 32 ) GPIO.out_w1tc = (1 <<
GPIO_PIN); \
else GPIO.out1_w1tc.val = (1 << (GPIO_PIN - 32)); \
} \
} while (0)
void task1(void *pvParameters)
{
TaskHandle_t
taskHandle = (TaskHandle_t)pvParameters;
for (int
io=0;io<8;io++) {
gpio_reset_pin( GPIO_PIN[io] );
gpio_set_direction( GPIO_PIN[io], GPIO_MODE_OUTPUT );
gpio_set_level( GPIO_PIN[io], 0 );
}
uint32_t value
= 0;
int32_t counter
= 1000000;
int direction =
1;
TickType_t
start = xTaskGetTickCount();
for (int
i=0;i<counter;i++) {
gpio_digital_write(GPIO_PIN[0], value & 0x01);
gpio_digital_write(GPIO_PIN[1], value & 0x02);
gpio_digital_write(GPIO_PIN[2], value & 0x04);
gpio_digital_write(GPIO_PIN[3], value & 0x08);
gpio_digital_write(GPIO_PIN[4], value & 0x10);
gpio_digital_write(GPIO_PIN[5], value & 0x20);
gpio_digital_write(GPIO_PIN[6], value & 0x40);
gpio_digital_write(GPIO_PIN[7], value & 0x80);
if (DEBUG) {
ESP_LOGI(pcTaskGetName(NULL), "value=0x%"PRIx32, value);
vTaskDelay(50);
if (direction == 1) {
value = (value << 1) + 1;
if (value == 0xff) direction = -1;
} else {
value = value >> 1;
if (value == 0) direction = 1;
}
} else {
value++;
if (value == 0x100) value = 0;
}
}
TickType_t end
= xTaskGetTickCount();
TickType_t diff
= end - start;
ESP_LOGI(pcTaskGetName(NULL),"diff=%"PRIu32, diff);
xTaskNotifyGive( taskHandle );
vTaskDelete(NULL);
}
void task2(void *pvParameters)
{
TaskHandle_t
taskHandle = (TaskHandle_t)pvParameters;
for (int
io=0;io<8;io++) {
gpio_reset_pin( GPIO_PIN[io] );
gpio_set_direction( GPIO_PIN[io], GPIO_MODE_OUTPUT );
gpio_set_level( GPIO_PIN[io], 0 );
}
uint32_t value
= 0;
int32_t counter
= 1000000;
int direction =
1;
TickType_t
start = xTaskGetTickCount();
for (int
i=0;i<counter;i++) {
reg_digital_write(GPIO_PIN[0], value & 0x01);
reg_digital_write(GPIO_PIN[1], value & 0x02);
reg_digital_write(GPIO_PIN[2], value & 0x04);
reg_digital_write(GPIO_PIN[3], value & 0x08);
reg_digital_write(GPIO_PIN[4], value & 0x10);
reg_digital_write(GPIO_PIN[5], value & 0x20);
reg_digital_write(GPIO_PIN[6], value & 0x40);
reg_digital_write(GPIO_PIN[7], value & 0x80);
if (DEBUG) {
ESP_LOGI(pcTaskGetName(NULL), "value=0x%"PRIx32, value);
vTaskDelay(50);
if (direction == 1) {
value = (value << 1) + 1;
if (value == 0xff) direction = -1;
} else {
value = value >> 1;
if (value == 0) direction = 1;
}
} else {
value++;
if (value == 0x100) value = 0;
}
}
TickType_t end
= xTaskGetTickCount();
TickType_t diff
= end - start;
ESP_LOGI(pcTaskGetName(NULL),"diff=%"PRIu32, diff);
xTaskNotifyGive( taskHandle );
vTaskDelete(NULL);
}
void task3(void *pvParameters)
{
TaskHandle_t
taskHandle = (TaskHandle_t)pvParameters;
for (int
io=0;io<8;io++) {
gpio_reset_pin( GPIO_PIN[io] );
gpio_set_direction( GPIO_PIN[io], GPIO_MODE_OUTPUT );
gpio_set_level( GPIO_PIN[io], 0 );
}
ESP_LOGI(pcTaskGetName(NULL), "Install fast GPIO bundle
for line address control");
dedic_gpio_bundle_config_t dedic_gpio_conf = {
.flags.out_en = true,
.gpio_array = (int[])
{
GPIO_PIN[0], GPIO_PIN[1], GPIO_PIN[2], GPIO_PIN[3],
GPIO_PIN[4], GPIO_PIN[5], GPIO_PIN[6], GPIO_PIN[7]
},
.array_size = 8,
};
dedic_gpio_bundle_handle_t dedic_gpio_bundle_handle;
ESP_ERROR_CHECK(dedic_gpio_new_bundle(&dedic_gpio_conf,
&dedic_gpio_bundle_handle));
uint32_t value
= 0;
int32_t counter
= 1000000;
int direction =
1;
TickType_t
start = xTaskGetTickCount();
for (int
i=0;i<counter;i++) {
dedic_gpio_bundle_write(dedic_gpio_bundle_handle, 0xFF,
value);
if (DEBUG) {
ESP_LOGI(pcTaskGetName(NULL), "value=0x%"PRIx32, value);
vTaskDelay(50);
if (direction == 1) {
value = (value << 1) + 1;
if (value == 0xff) direction = -1;
} else {
value = value >> 1;
if (value == 0) direction = 1;
}
} else {
value++;
if (value == 0x100) value = 0;
}
}
TickType_t end
= xTaskGetTickCount();
TickType_t diff
= end - start;
ESP_LOGI(pcTaskGetName(NULL),"diff=%"PRIu32, diff);
xTaskNotifyGive( taskHandle );
vTaskDelete(NULL);
}
void app_main()
{
TaskHandle_t
taskHandle = xTaskGetCurrentTaskHandle();
uint32_t value;
#if 0
xTaskCreate(&task1, "TASK1", 1024*4, (void
*)taskHandle, 2, NULL);
value =
ulTaskNotifyTake( pdTRUE, portMAX_DELAY );
ESP_LOGI(pcTaskGetName(NULL), "ulTaskNotifyTake
value=%"PRIu32, value);
#endif
#if 1
xTaskCreate(&task2, "TASK2", 1024*4, (void
*)taskHandle, 2, NULL);
value =
ulTaskNotifyTake( pdTRUE, portMAX_DELAY );
ESP_LOGI(pcTaskGetName(NULL), "ulTaskNotifyTake
value=%"PRIu32, value);
#endif
#if 0
xTaskCreate(&task3, "TASK3", 1024*4, (void
*)taskHandle, 2, NULL);
value =
ulTaskNotifyTake( pdTRUE, portMAX_DELAY );
ESP_LOGI(pcTaskGetName(NULL), "ulTaskNotifyTake
value=%"PRIu32, value);
#endif
}
|