155 lines
4.0 KiB
C
155 lines
4.0 KiB
C
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
|
|
#include "ql_api_osi.h"
|
|
#include "ql_log.h"
|
|
#include "ql_gpio.h"
|
|
#include "ql_uart.h"
|
|
#include "inc/esp32_iap_sdmmc.h"
|
|
#include "ESP32_iap_demo.h"
|
|
|
|
|
|
#define QL_GPIODEMO_LOG_LEVEL QL_LOG_LEVEL_INFO
|
|
#define LOGI(msg, ...) QL_LOG(QL_GPIODEMO_LOG_LEVEL, "ql_esp32_iap_DEMO", msg, ##__VA_ARGS__)
|
|
|
|
#define LED_PIN 54
|
|
#define LED_FUN 0
|
|
#define LED_GPIO_NUM GPIO_13
|
|
|
|
static void ql_esp32_iap_demo_thread(void *param)
|
|
{
|
|
LOGI("esp32 iap demo thread enter, param 0x%x", param);
|
|
ql_event_t event;
|
|
int ret = 0;
|
|
|
|
/* GPIO初始化 */
|
|
ql_pin_set_func(LED_PIN, LED_FUN);
|
|
ql_gpio_deinit(LED_GPIO_NUM);
|
|
ql_gpio_init(LED_GPIO_NUM, GPIO_OUTPUT, 0xff, LVL_LOW);
|
|
|
|
while(1)
|
|
{
|
|
ql_event_wait(&event, 1);
|
|
|
|
ql_gpio_set_level(GPIO_13, LVL_HIGH);
|
|
ql_rtos_task_sleep_s(1);
|
|
ql_gpio_set_level(GPIO_13, LVL_LOW);
|
|
ql_rtos_task_sleep_s(1);
|
|
}
|
|
|
|
exit:
|
|
ql_rtos_task_delete(NULL);
|
|
}
|
|
|
|
|
|
#define ESP32_UART_PORT QL_UART_PORT_1
|
|
#define ESP32_UART_BAUDRATE QL_UART_BAUD_115200
|
|
#define QL_UART_RX_BUFF_SIZE 2048
|
|
#define QL_UART_TX_BUFF_SIZE 2048
|
|
|
|
#define MIN(a,b) ((a) < (b) ? (a) : (b))
|
|
|
|
|
|
void ql_esp32_uart_notify_cb(unsigned int ind_type, ql_uart_port_number_e port, unsigned int size)
|
|
{
|
|
LOGI("UART port %d receive ind type:0x%x, receive data size:%d", port, ind_type, size);
|
|
switch(ind_type)
|
|
{
|
|
case QUEC_UART_RX_OVERFLOW_IND: //rx buffer overflow
|
|
LOGI("uart rx overflow");
|
|
break;
|
|
case QUEC_UART_RX_RECV_DATA_IND:
|
|
LOGI("uart rx data");
|
|
break;
|
|
case QUEC_UART_TX_FIFO_COMPLETE_IND:
|
|
LOGI("uart tx fifo complete");
|
|
break;
|
|
}
|
|
}
|
|
|
|
static void ql_esp32_iap_uart_demo_thread(void *param)
|
|
{
|
|
LOGI("esp32 iap uart demo thread enter, param 0x%x", param);
|
|
int ret = 0;
|
|
ql_event_t event;
|
|
unsigned char data[] = "hello esp32 uart demo\r\n";
|
|
int write_len = 0;
|
|
unsigned char *recv_buff = calloc(1, QL_UART_RX_BUFF_SIZE+1);
|
|
int read_len = 0;
|
|
|
|
ql_uart_config_s uart_cfg = {0};
|
|
uart_cfg.baudrate = ESP32_UART_BAUDRATE;
|
|
uart_cfg.flow_ctrl = QL_FC_NONE;
|
|
uart_cfg.data_bit = QL_UART_DATABIT_8;
|
|
uart_cfg.stop_bit = QL_UART_STOP_1;
|
|
uart_cfg.parity_bit = QL_UART_PARITY_NONE;
|
|
ret = ql_uart_set_dcbconfig(ESP32_UART_PORT, &uart_cfg);
|
|
if (QL_UART_SUCCESS != ret)
|
|
{
|
|
LOGI("uart dcbconfig err, ret: 0x%x", ret);
|
|
goto exit;
|
|
}
|
|
|
|
/* uart1不用设置引脚复用功能 */
|
|
|
|
ret = ql_uart_open(ESP32_UART_PORT);
|
|
if (QL_UART_SUCCESS != ret)
|
|
{
|
|
LOGI("uart open err, ret: 0x%x", ret);
|
|
goto exit;
|
|
}
|
|
|
|
ret = ql_uart_register_cb(ESP32_UART_PORT, ql_esp32_uart_notify_cb);
|
|
if (QL_UART_SUCCESS != ret)
|
|
{
|
|
LOGI("uart open err, ret: 0x%x", ret);
|
|
ql_uart_close(ESP32_UART_PORT);
|
|
goto exit;
|
|
}
|
|
|
|
while(1)
|
|
{
|
|
ql_event_wait(&event, 1);
|
|
|
|
write_len = ql_uart_write(ESP32_UART_PORT, data, strlen((char *)data));
|
|
LOGI("write_len:%d", write_len);
|
|
|
|
ql_rtos_task_sleep_s(1);
|
|
|
|
read_len = ql_uart_read(ESP32_UART_PORT, recv_buff, QL_UART_RX_BUFF_SIZE);
|
|
recv_buff[read_len] = '\0';
|
|
LOGI("read_len=%d, recv_data=%s", read_len, recv_buff);
|
|
|
|
ql_rtos_task_sleep_s(1);
|
|
}
|
|
|
|
exit:
|
|
ql_rtos_task_delete(NULL);
|
|
}
|
|
|
|
|
|
|
|
void ql_esp32_iap_app_init(void)
|
|
{
|
|
QlOSStatus err = QL_OSI_SUCCESS;
|
|
|
|
ql_task_t esp32_iap_task = NULL;
|
|
err = ql_rtos_task_create(&esp32_iap_task, 1024, APP_PRIORITY_NORMAL, "ql_esp32iapdemo", ql_esp32_iap_demo_thread, NULL, 1);
|
|
if( err != QL_OSI_SUCCESS )
|
|
{
|
|
LOGI("esp32 iap demo task created failed");
|
|
}
|
|
|
|
ql_task_t esp32_iap_uart_task = NULL;
|
|
err = ql_rtos_task_create(&esp32_iap_uart_task, 1024, APP_PRIORITY_NORMAL, "ql_esp32iapuartdemo", ql_esp32_iap_uart_demo_thread, NULL, 1);
|
|
if( err != QL_OSI_SUCCESS )
|
|
{
|
|
LOGI("esp32 iap uart demo task created failed");
|
|
}
|
|
|
|
ql_sdmmc_app_init();
|
|
}
|
|
|
|
|