mirror of
https://github.com/pvvx/RTL00MP3.git
synced 2025-07-31 12:41:06 +00:00
add example
This commit is contained in:
parent
0cd01e4dc1
commit
5cd34b0c9f
75 changed files with 6023 additions and 217 deletions
|
|
@ -4,10 +4,10 @@
|
|||
*
|
||||
*
|
||||
******************************************************************************/
|
||||
#include "platform_opts.h"
|
||||
#include <platform_opts.h>
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "platform/platform_stdlib.h"
|
||||
#include <platform/platform_stdlib.h>
|
||||
#include "semphr.h"
|
||||
#include "device.h"
|
||||
#include "serial_api.h"
|
||||
|
|
@ -18,17 +18,12 @@
|
|||
#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1)
|
||||
#include "freertos_pmu.h"
|
||||
#endif
|
||||
#include "osdep_api.h"
|
||||
#include "osdep_service.h"
|
||||
#include "serial_ex_api.h"
|
||||
#include "at_cmd/atcmd_wifi.h"
|
||||
#include "at_cmd/atcmd_lwip.h"
|
||||
#include "pinmap.h"
|
||||
|
||||
#ifdef USE_FLASH_EEP
|
||||
#include "flash_eep.h"
|
||||
#endif
|
||||
|
||||
#if CONFIG_EXAMPLE_UART_ATCMD
|
||||
|
||||
typedef int (*init_done_ptr)(void);
|
||||
|
|
@ -41,8 +36,8 @@ extern int atcmd_lwip_restore_from_flash(void);
|
|||
|
||||
serial_t at_cmd_sobj;
|
||||
char at_string[ATSTRING_LEN];
|
||||
//xSemaphoreHandle at_printf_sema;
|
||||
_Sema uart_at_dma_tx_sema;
|
||||
//_sema at_printf_sema;
|
||||
_sema uart_at_dma_tx_sema;
|
||||
unsigned char gAT_Echo = 1; // default echo on
|
||||
|
||||
#define UART_AT_MAX_DELAY_TIME_MS 20
|
||||
|
|
@ -53,13 +48,6 @@ unsigned char gAT_Echo = 1; // default echo on
|
|||
#define UART_AT_USE_DMA_TX 0
|
||||
|
||||
void atcmd_update_partition_info(AT_PARTITION id, AT_PARTITION_OP ops, u8 *data, u16 len){
|
||||
#ifdef USE_FLASH_EEP
|
||||
if(id == AT_PARTITION_UART || id == AT_PARTITION_LWIP || id == AT_PARTITION_WIFI) {
|
||||
if(ops == AT_PARTITION_READ) flash_read_cfg(data, id, len);
|
||||
else if (ops == AT_PARTITION_WRITE) flash_write_cfg(data, id, len);
|
||||
else if (ops == AT_PARTITION_ERASE) flash_write_cfg(data, id, 0);
|
||||
}
|
||||
#else
|
||||
flash_t flash;
|
||||
int size, offset, i;
|
||||
u32 read_data;
|
||||
|
|
@ -87,6 +75,7 @@ void atcmd_update_partition_info(AT_PARTITION id, AT_PARTITION_OP ops, u8 *data,
|
|||
}
|
||||
|
||||
device_mutex_lock(RT_DEV_LOCK_FLASH);
|
||||
|
||||
if(id == AT_PARTITION_ALL && ops == AT_PARTITION_ERASE){
|
||||
flash_erase_sector(&flash, UART_SETTING_SECTOR);
|
||||
goto exit;
|
||||
|
|
@ -132,7 +121,6 @@ void atcmd_update_partition_info(AT_PARTITION id, AT_PARTITION_OP ops, u8 *data,
|
|||
exit:
|
||||
device_mutex_unlock(RT_DEV_LOCK_FLASH);
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
|
||||
int read_uart_atcmd_setting_from_system_data(UART_LOG_CONF* uartconf)
|
||||
|
|
@ -145,7 +133,7 @@ int read_uart_atcmd_setting_from_system_data(UART_LOG_CONF* uartconf)
|
|||
// flash_stream_read(&flash, UART_AT_DATA,sizeof(UART_LOG_CONF), (u8 *)&conf);
|
||||
atcmd_update_partition_info(AT_PARTITION_UART, AT_PARTITION_READ, (u8 *)&conf, sizeof(UART_LOG_CONF));
|
||||
do{
|
||||
if(conf.FlowControl != AUTOFLOW_DISABLE && conf.FlowControl != AUTOFLOW_ENABLE)
|
||||
if(conf.FlowControl != DISABLE && conf.FlowControl != ENABLE)
|
||||
break;
|
||||
|
||||
if(conf.DataBits != 5
|
||||
|
|
@ -156,7 +144,7 @@ int read_uart_atcmd_setting_from_system_data(UART_LOG_CONF* uartconf)
|
|||
|
||||
if(conf.Parity != ParityNone && conf.Parity != ParityOdd && conf.Parity != ParityEven)
|
||||
break;
|
||||
|
||||
|
||||
if(conf.StopBits != 1 && conf.StopBits != 2)
|
||||
break;
|
||||
|
||||
|
|
@ -165,11 +153,11 @@ int read_uart_atcmd_setting_from_system_data(UART_LOG_CONF* uartconf)
|
|||
|
||||
if(load_default == _TRUE){
|
||||
// load default setting
|
||||
uartconf->BaudRate = DEFAULT_BAUDRATE;
|
||||
uartconf->BaudRate = 38400;
|
||||
uartconf->DataBits = 8;
|
||||
uartconf->Parity = ParityNone;
|
||||
uartconf->StopBits = 1;
|
||||
uartconf->FlowControl = AUTOFLOW_DISABLE;
|
||||
uartconf->FlowControl = DISABLE;
|
||||
}
|
||||
else{
|
||||
uartconf->BaudRate = conf.BaudRate;
|
||||
|
|
@ -199,13 +187,13 @@ int write_uart_atcmd_setting_to_system_data(UART_LOG_CONF* uartconf)
|
|||
|
||||
u32 data,i;
|
||||
|
||||
memset(data2, 0xFF, sizeof(UART_LOG_CONF));
|
||||
rtw_memset(data2, 0xFF, sizeof(UART_LOG_CONF));
|
||||
|
||||
//Get upgraded image 2 addr from offset
|
||||
device_mutex_lock(RT_DEV_LOCK_FLASH);
|
||||
flash_stream_read(&flash, UART_AT_DATA,sizeof(UART_LOG_CONF), data1);
|
||||
|
||||
if(memcmp(data1,data2,sizeof(UART_LOG_CONF)) == 0){
|
||||
if(rtw_memcmp(data1,data2,sizeof(UART_LOG_CONF)) == _TRUE){
|
||||
flash_stream_write(&flash, UART_AT_DATA, sizeof(UART_LOG_CONF),(u8*)uartconf);
|
||||
}else{
|
||||
//erase backup sector
|
||||
|
|
@ -245,13 +233,13 @@ int reset_uart_atcmd_setting(){
|
|||
|
||||
u32 data,i;
|
||||
|
||||
memset(data2, 0xFF, sizeof(UART_LOG_CONF));
|
||||
rtw_memset(data2, 0xFF, sizeof(UART_LOG_CONF));
|
||||
|
||||
//Get upgraded image 2 addr from offset
|
||||
device_mutex_lock(RT_DEV_LOCK_FLASH);
|
||||
flash_stream_read(&flash, UART_AT_DATA,sizeof(UART_LOG_CONF), data1);
|
||||
|
||||
if(memcmp(data1,data2,sizeof(UART_LOG_CONF)) == 0){
|
||||
if(rtw_memcmp(data1,data2,sizeof(UART_LOG_CONF)) == _TRUE){
|
||||
;
|
||||
}else{
|
||||
//erase backup sector
|
||||
|
|
@ -275,42 +263,33 @@ int reset_uart_atcmd_setting(){
|
|||
flash_erase_sector(&flash, BACKUP_SECTOR);
|
||||
}
|
||||
device_mutex_unlock(RT_DEV_LOCK_FLASH);
|
||||
#else
|
||||
#ifdef USE_FLASH_EEP
|
||||
flash_write_cfg(NULL, AT_PARTITION_UART, 0);
|
||||
flash_write_cfg(NULL, AT_PARTITION_WIFI, 0);
|
||||
flash_write_cfg(NULL, AT_PARTITION_LWIP, 0);
|
||||
#else
|
||||
atcmd_update_partition_info(AT_PARTITION_ALL, AT_PARTITION_ERASE, NULL, 0);
|
||||
#endif
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if ATCMD_RX_GPIO_WAKEUP
|
||||
#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1)
|
||||
#include "gpio_irq_api.h"
|
||||
#define UART_AT_RX_WAKE UART_RX
|
||||
void gpio_uart_at_rx_irq_callback (uint32_t id, gpio_irq_event event)
|
||||
{
|
||||
/* WAKELOCK_LOGUART is also handled in log service.
|
||||
/* PMU_LOGUART_DEVICE is also handled in log service.
|
||||
* It is release after a complete command is sent.
|
||||
**/
|
||||
//acquire_wakelock(WAKELOCK_LOGUART);
|
||||
//pmu_acquire_wakelock(BIT(PMU_LOGUART_DEVICE));
|
||||
}
|
||||
|
||||
void uart_at_rx_wakeup()
|
||||
{
|
||||
gpio_irq_t gpio_rx_wake;
|
||||
#ifdef RTL8711AM
|
||||
#if (UART_AT_RX_WAKE!=PA_0)||(UART_AT_RX_WAKE!=PE_3)
|
||||
#error "Set pin rx_wakeup!"
|
||||
#endif
|
||||
#endif
|
||||
gpio_irq_init(&gpio_rx_wake, UART_AT_RX_WAKE, gpio_uart_at_rx_irq_callback, 0);
|
||||
gpio_irq_init(&gpio_rx_wake, UART_AT_RX_WAKE, gpio_uart_at_rx_irq_callback, NULL);
|
||||
gpio_irq_set(&gpio_rx_wake, IRQ_FALL, 1); // Falling Edge Trigger
|
||||
gpio_irq_enable(&gpio_rx_wake);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void uart_atcmd_reinit(UART_LOG_CONF* uartconf){
|
||||
serial_baud(&at_cmd_sobj,uartconf->BaudRate);
|
||||
|
|
@ -342,7 +321,7 @@ static void uart_at_send_buf_done(uint32_t id)
|
|||
{
|
||||
//serial_t *sobj = (serial_t *)id;
|
||||
|
||||
RtlUpSemaFromISR(&uart_at_dma_tx_sema);
|
||||
rtw_up_sema_from_isr(&uart_at_dma_tx_sema);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -354,10 +333,10 @@ void uart_at_send_buf(u8 *buf, u32 len)
|
|||
}
|
||||
#if UART_AT_USE_DMA_TX
|
||||
int ret;
|
||||
while(RtlDownSema(&uart_at_dma_tx_sema) == pdTRUE){
|
||||
while(rtw_down_sema(&uart_at_dma_tx_sema) == _TRUE){
|
||||
ret = serial_send_stream_dma(&at_cmd_sobj, st_p, len);
|
||||
if(ret != HAL_OK){
|
||||
RtlUpSema(&uart_at_dma_tx_sema);
|
||||
rtw_up_sema(&uart_at_dma_tx_sema);
|
||||
return;
|
||||
}else{
|
||||
return;
|
||||
|
|
@ -374,16 +353,16 @@ void uart_at_send_buf(u8 *buf, u32 len)
|
|||
/*
|
||||
void uart_at_lock(void)
|
||||
{
|
||||
RtlDownSema(&at_printf_sema);
|
||||
rtw_down_sema(&at_printf_sema);
|
||||
}
|
||||
|
||||
void uart_at_unlock(void)
|
||||
{
|
||||
RtlUpSema(&at_printf_sema);
|
||||
rtw_up_sema(&at_printf_sema);
|
||||
}
|
||||
|
||||
void uart_at_lock_init(){
|
||||
RtlInitSema(&at_printf_sema, 1);
|
||||
rtw_init_sema(&at_printf_sema, 1);
|
||||
}
|
||||
*/
|
||||
void uart_irq(uint32_t id, SerialIrq event)
|
||||
|
|
@ -401,10 +380,14 @@ void uart_irq(uint32_t id, SerialIrq event)
|
|||
rc = serial_getc(sobj);
|
||||
|
||||
if(atcmd_lwip_is_tt_mode()){
|
||||
log_buf[atcmd_lwip_tt_datasize++] = rc;
|
||||
atcmd_lwip_tt_lasttickcnt = xTaskGetTickCountFromISR();
|
||||
if(atcmd_lwip_tt_datasize < LOG_SERVICE_BUFLEN){
|
||||
log_buf[atcmd_lwip_tt_datasize++] = rc;
|
||||
atcmd_lwip_tt_lasttickcnt = xTaskGetTickCountFromISR();
|
||||
}else{
|
||||
//log_buf is overflow, the following data is drop here
|
||||
}
|
||||
if(atcmd_lwip_tt_datasize == 1)
|
||||
RtlUpSemaFromISR((_Sema *)&atcmd_lwip_tt_sema);
|
||||
rtw_up_sema_from_isr(&atcmd_lwip_tt_sema);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -428,7 +411,7 @@ void uart_irq(uint32_t id, SerialIrq event)
|
|||
}else{
|
||||
if(rc == ':'){ //data will start after this delimeter ':'
|
||||
strncpy(log_buf, (char *)temp_buf, buf_count);
|
||||
memset(temp_buf,'\0',buf_count);
|
||||
rtw_memset(temp_buf,'\0',buf_count);
|
||||
last_tickcnt = xTaskGetTickCountFromISR();
|
||||
data_cmd_sz = buf_count + 1 + data_sz;
|
||||
}
|
||||
|
|
@ -437,7 +420,7 @@ void uart_irq(uint32_t id, SerialIrq event)
|
|||
|
||||
if(data_cmd_sz){
|
||||
if((!gAT_Echo) && (rtw_systime_to_ms(xTaskGetTickCountFromISR() - last_tickcnt) > UART_AT_MAX_DELAY_TIME_MS)){
|
||||
uart_at_send_string("\r\nERROR:data timeout\r\n\n# ");
|
||||
uart_at_send_string("\r\nERROR: data timeout\r\n\n# ");
|
||||
memset(log_buf, 0, buf_count);
|
||||
is_data_cmd = _FALSE;
|
||||
data_sz = 0;
|
||||
|
|
@ -458,7 +441,7 @@ void uart_irq(uint32_t id, SerialIrq event)
|
|||
data_cmd_sz = 0;
|
||||
buf_count=0;
|
||||
last_tickcnt = 0;
|
||||
RtlUpSemaFromISR((_Sema *)&log_rx_interrupt_sema);
|
||||
rtw_up_sema_from_isr(&log_rx_interrupt_sema);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
@ -482,10 +465,10 @@ void uart_irq(uint32_t id, SerialIrq event)
|
|||
}
|
||||
else if(rc == KEY_ENTER){
|
||||
if(buf_count>0){
|
||||
memset(log_buf,'\0',LOG_SERVICE_BUFLEN);
|
||||
rtw_memset(log_buf,'\0',LOG_SERVICE_BUFLEN);
|
||||
strncpy(log_buf,(char *)&temp_buf[0],buf_count);
|
||||
RtlUpSemaFromISR((_Sema *)&log_rx_interrupt_sema);
|
||||
memset(temp_buf,'\0',buf_count);
|
||||
rtw_up_sema_from_isr(&log_rx_interrupt_sema);
|
||||
rtw_memset(temp_buf,'\0',buf_count);
|
||||
is_data_cmd = _FALSE;
|
||||
data_sz = 0;
|
||||
data_cmd_sz = 0;
|
||||
|
|
@ -509,7 +492,9 @@ void uart_irq(uint32_t id, SerialIrq event)
|
|||
else{
|
||||
// skip characters until "A"
|
||||
if((buf_count == 0) && (rc != 'A')){
|
||||
if(gAT_Echo == 1){
|
||||
// some consoles send "\r\n" for enter,
|
||||
//so skip '\n' here to prevent ERROR message each time it sends command
|
||||
if(gAT_Echo == 1 && rc != KEY_NL){
|
||||
uart_at_send_string("\r\nERROR:command should start with 'A'"STR_END_OF_ATCMD_RET);
|
||||
}
|
||||
return;
|
||||
|
|
@ -536,7 +521,8 @@ void uart_atcmd_main(void)
|
|||
UART_LOG_CONF uartconf;
|
||||
|
||||
read_uart_atcmd_setting_from_system_data(&uartconf);
|
||||
serial_init(&at_cmd_sobj, UART_TX, UART_RX);
|
||||
|
||||
serial_init(&at_cmd_sobj,UART_TX,UART_RX);
|
||||
serial_baud(&at_cmd_sobj,uartconf.BaudRate);
|
||||
serial_format(&at_cmd_sobj, uartconf.DataBits, (SerialParity)uartconf.Parity, uartconf.StopBits);
|
||||
serial_rx_fifo_level(&at_cmd_sobj, FifoLvHalf);
|
||||
|
|
@ -554,35 +540,29 @@ void uart_atcmd_main(void)
|
|||
/*uart_at_lock_init();*/
|
||||
|
||||
#if UART_AT_USE_DMA_TX
|
||||
RtlInitSema(&uart_at_dma_tx_sema, 1);
|
||||
rtw_init_sema(&uart_at_dma_tx_sema, 1);
|
||||
#endif
|
||||
|
||||
#if UART_AT_USE_DMA_TX
|
||||
serial_send_comp_handler(&at_cmd_sobj, (void*)uart_at_send_buf_done, (uint32_t)&at_cmd_sobj);
|
||||
serial_send_comp_handler(&at_cmd_sobj, (void*)uart_at_send_buf_done, (uint32_t)&at_cmd_sobj);
|
||||
#endif
|
||||
|
||||
|
||||
serial_irq_handler(&at_cmd_sobj, uart_irq, (uint32_t)&at_cmd_sobj);
|
||||
serial_irq_set(&at_cmd_sobj, RxIrq, 1);
|
||||
|
||||
#if ATCMD_RX_GPIO_WAKEUP
|
||||
#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1)
|
||||
uart_at_rx_wakeup();
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
static void uart_atcmd_thread(void *param)
|
||||
{
|
||||
p_wlan_init_done_callback = NULL;
|
||||
#if CONFIG_DEBUG_LOG > 3
|
||||
ConfigDebugErr = -1;
|
||||
ConfigDebugInfo = ~_DBG_SPI_FLASH_;
|
||||
ConfigDebugWarn = -1;
|
||||
CfgSysDebugErr = -1;
|
||||
CfgSysDebugInfo = -1;
|
||||
CfgSysDebugWarn = -1;
|
||||
#endif
|
||||
atcmd_wifi_restore_from_flash();
|
||||
atcmd_lwip_restore_from_flash();
|
||||
vTaskDelay(20); //rtw_msleep_os(20);
|
||||
rtw_msleep_os(20);
|
||||
uart_atcmd_main();
|
||||
at_printf("\r\nAT COMMAND READY");
|
||||
if(atcmd_lwip_is_tt_mode())
|
||||
|
|
@ -594,10 +574,7 @@ static void uart_atcmd_thread(void *param)
|
|||
}
|
||||
|
||||
int uart_atcmd_module_init(void){
|
||||
#if CONFIG_DEBUG_LOG > 3
|
||||
printf("Time at start %d ms.\n", xTaskGetTickCount());
|
||||
#endif
|
||||
if(xTaskCreate(uart_atcmd_thread, ((const char*)"uart_atcmd_thread"), 1024, NULL, tskIDLE_PRIORITY + 1 , NULL) != pdPASS) // tskIDLE_PRIORITY + 1
|
||||
if(xTaskCreate(uart_atcmd_thread, ((const char*)"uart_atcmd_thread"), 1024, NULL, tskIDLE_PRIORITY+1 , NULL) != pdPASS)
|
||||
printf("\n\r%s xTaskCreate(uart_atcmd_thread) failed", __FUNCTION__);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,55 +10,33 @@
|
|||
#if CONFIG_EXAMPLE_UART_ATCMD
|
||||
#include "FreeRTOS.h"
|
||||
#include "semphr.h"
|
||||
#include "osdep_api.h"
|
||||
|
||||
|
||||
#if defined(RTL8710AF)
|
||||
// RTL8710AF
|
||||
#define UART_TX PA_4 // PC_3
|
||||
#define UART_RX PA_0 // PC_0
|
||||
#define UART_RTS PA_2 // PC_2
|
||||
#define UART_CTS PA_1 // PC_1
|
||||
|
||||
#elif 0 // defined(RTL8711AM)
|
||||
// RTL8711AM
|
||||
#define UART_TX PA_7
|
||||
#define UART_RX PA_6 // no Interrupt!
|
||||
#define UART_RTS PA_3
|
||||
#define UART_CTS PA_5
|
||||
|
||||
#elif 0 // else
|
||||
// RTL8711AM + RTL8710AF
|
||||
#define UART_TX PC_3
|
||||
#define UART_RX PC_0 // no Interrupt!
|
||||
#define UART_RTS PC_2
|
||||
#define UART_CTS PC_1
|
||||
|
||||
#elif defined(RTL8711AM)
|
||||
// RTL8711AM + RTL8710AF
|
||||
#define UART_TX PE_0
|
||||
#define UART_RX PE_3
|
||||
#define UART_RTS PE_1
|
||||
#define UART_CTS PE_2
|
||||
|
||||
/*UART Pinmux*/
|
||||
#define CONFIG_AMEBA1 1
|
||||
#if CONFIG_AMEBA1
|
||||
#define UART_TX PA_4
|
||||
#define UART_RX PA_0
|
||||
#define UART_RTS PA_2
|
||||
#define UART_CTS PA_1
|
||||
#else
|
||||
#define UART_TX PA_23
|
||||
#define UART_RX PA_18
|
||||
#define UART_RTS PA_22
|
||||
#define UART_CTS PA_19
|
||||
#endif
|
||||
|
||||
#define KEY_ENTER 0xd
|
||||
#define KEY_BS 0x8
|
||||
#define KEY_ESC 0x1B
|
||||
#define KEY_LBRKT 0x5B
|
||||
#define ATCMD_RX_GPIO_WAKEUP 0
|
||||
#define KEY_NL 0xa // '\n'
|
||||
#define KEY_ENTER 0xd // '\r'
|
||||
#define KEY_BS 0x8
|
||||
#define KEY_ESC 0x1B
|
||||
#define KEY_LBRKT 0x5B
|
||||
|
||||
void uart_at_lock(void);
|
||||
void uart_at_unlock(void);
|
||||
void uart_at_send_string(char *str);
|
||||
void uart_at_send_buf(u8 *buf, u32 len);
|
||||
void example_uart_atcmd(void);
|
||||
|
||||
#include "at_cmd/atcmd_wifi.h"
|
||||
|
||||
void uart_atcmd_reinit(UART_LOG_CONF* uartconf);
|
||||
int write_uart_atcmd_setting_to_system_data(UART_LOG_CONF* uartconf);
|
||||
|
||||
extern u8 key_2char2num(u8 hch, u8 lch);
|
||||
static void at_hex2str(const u8 *start, u32 size, u8 *out, u32 out_size)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue