94 lines
2.8 KiB
C
94 lines
2.8 KiB
C
/*----------------------------------------------------------------------------
|
|
* Copyright (c) TJD Technologies Co., Ltd. 2024. All rights reserved.
|
|
*
|
|
* Description: ate_task.c
|
|
*
|
|
* Author: luziquan@ss-tjd.com
|
|
*
|
|
* Create: 2024-04-19
|
|
*--------------------------------------------------------------------------*/
|
|
|
|
#include "ate_rx_manager.h"
|
|
#include "ate_cmd_manager.h"
|
|
#include "ate_at_process.h"
|
|
#include "ate_msg_manager.h"
|
|
#include "cmsis_os2.h"
|
|
#include "common_def.h"
|
|
#include "debug_print.h"
|
|
#include "soc_osal.h"
|
|
|
|
#define ATE_MSG_COUNT 16
|
|
|
|
static unsigned long g_ate_at_queue;
|
|
|
|
unsigned long get_ate_at_queue_id(void)
|
|
{
|
|
return g_ate_at_queue;
|
|
}
|
|
|
|
static void ate_at_task_process_handler(void *param)
|
|
{
|
|
unused(param);
|
|
int32_t ret = OSAL_FAILURE;
|
|
at_cmd_msg_info_t msg_data;
|
|
uint32_t msg_size = sizeof(at_cmd_msg_info_t);
|
|
uint32_t sync_ret = ate_get_cmd_table();
|
|
if (sync_ret != ERRCODE_SUCC) {
|
|
wstp_print("ate_get_cmd_table failed!" NEWLINE);
|
|
return;
|
|
}
|
|
ate_module_api_init();
|
|
tjd_ate_msg_task_init();
|
|
wstp_print("ate_at_task_process_handler start\n");
|
|
|
|
while (1) {
|
|
(void)memset_s(&msg_data, sizeof(msg_data), 0, sizeof(msg_data));
|
|
ret = osal_msg_queue_read_copy(g_ate_at_queue, &msg_data, &msg_size, OSAL_MSGQ_WAIT_FOREVER);
|
|
if (ret != OSAL_SUCCESS) {
|
|
continue;
|
|
}
|
|
|
|
ate_at_process(msg_data.payload, msg_data.payload_len);
|
|
osal_kfree(msg_data.payload);
|
|
}
|
|
}
|
|
|
|
void tjd_ate_at_task_init(void)
|
|
{
|
|
osThreadAttr_t task_attr = { "tjd_ate_at_task", 0, NULL, 0, NULL, 0x2000, 17, 0, 0};
|
|
task_attr.stack_mem = memalign(16, task_attr.stack_size);
|
|
osal_msg_queue_create("ate_at_service_queue", ATE_MSG_COUNT, &g_ate_at_queue, 0, sizeof(at_cmd_msg_info_t));
|
|
osThreadNew(ate_at_task_process_handler, NULL, &task_attr);
|
|
}
|
|
|
|
void tjd_ate_send_at_msg(uint8_t *data, uint32_t data_len)
|
|
{
|
|
if (data == NULL) {
|
|
wstp_print("tjd_ate_send_at_msg data is null!" NEWLINE);
|
|
return;
|
|
}
|
|
|
|
/* +3是为字符串结束符和\r\n多申请内存 */
|
|
uint8_t* msg = osal_kmalloc(data_len + 3, OSAL_GFP_KERNEL);
|
|
if (msg == NULL) {
|
|
wstp_print("tjd_ate_send_at_msg payload memory alloc fail, length is " NEWLINE, data_len);
|
|
return;
|
|
}
|
|
|
|
(void)memset_s(msg, data_len + 3, 0, data_len + 3);
|
|
if (memcpy_s(msg, data_len, (const void *)data, data_len) != EOK) {
|
|
wstp_print("tjd_ate_send_at_msg receive data memcpy error!" NEWLINE);
|
|
osal_kfree(msg);
|
|
msg = NULL;
|
|
return;
|
|
}
|
|
|
|
/* 在数据末尾添加\r\n */
|
|
msg[data_len] = '\r';
|
|
msg[data_len + 1] = '\n';
|
|
|
|
at_cmd_msg_receive_handler(msg, data_len + 3);
|
|
|
|
osal_kfree(msg);
|
|
}
|