494 lines
16 KiB
C
494 lines
16 KiB
C
/*----------------------------------------------*
|
|
* 包含头文件 *
|
|
*----------------------------------------------*/
|
|
#include "am_mcu_apollo.h"
|
|
|
|
#include "FreeRTOS.h"
|
|
#include "task.h"
|
|
#include "queue.h"
|
|
#include "timers.h"
|
|
|
|
#include "wsf_types.h"
|
|
#include "wsf_os.h"
|
|
#include "wsf_trace.h"
|
|
|
|
#include "sys_config.h"
|
|
#include "sys_typedef.h"
|
|
#include "task_age.h"
|
|
#include "task_ui.h"
|
|
//#include "app_adapter.h"
|
|
|
|
//#include "charge_hal.h"
|
|
//#include "all_keys.h"
|
|
//#include "motor_api.h"
|
|
//#include "ppg_api.h"
|
|
//#include "user_gps.h"
|
|
//#include "port_psram.h"
|
|
//#include "port_flash.h"
|
|
//#include "port_touchpad.h"
|
|
//#include "port_display.h"
|
|
#include "debug_api.h"
|
|
#include "ate_pump_stress.h"
|
|
#include "ate_uart_cmd.h"
|
|
#include "pump_api.h"
|
|
#include "pressure_api.h"
|
|
///#include "ate_gsensor_psram_rtc.h"
|
|
|
|
//#include "ate_timer.h"
|
|
|
|
//#include "age_task.h"
|
|
#include "task_ate.h"
|
|
#include "config_ate.h"
|
|
#include "ate_production_order.h"
|
|
|
|
/*----------------------------------------------*
|
|
* 宏定义 *
|
|
*----------------------------------------------*/
|
|
|
|
/*----------------------------------------------*
|
|
* 外部变量说明 *
|
|
*----------------------------------------------*/
|
|
|
|
/*----------------------------------------------*
|
|
* 外部函数原型说明 *
|
|
*----------------------------------------------*/
|
|
|
|
extern void age_task_suspend(void);
|
|
//extern void tp_ate_task_suspend(void);
|
|
//extern void display_ate_task_suspend(void);
|
|
#if 0
|
|
extern void flash_age_chip(void);
|
|
extern void motor_start(uint16_t single_time, uint16_t interval_time, uint32_t run_times);
|
|
extern void gh30x_ate_test_Int_Msg_Handler(void);
|
|
extern void factory_ble_rx_data_proc(uint16_t len);
|
|
#endif
|
|
/*----------------------------------------------*
|
|
* 内部函数原型说明 *
|
|
*----------------------------------------------*/
|
|
|
|
/*----------------------------------------------*
|
|
* 全局变量 *
|
|
*----------------------------------------------*/
|
|
static TaskHandle_t ate_task_handle = NULL;
|
|
static QueueHandle_t ate_task_msgqueue_handle = NULL;
|
|
|
|
static TimerHandle_t g_ate_timer_hdl = NULL;
|
|
static ATETimerFuncPtr g_ate_timer_hdl_cb = NULL;
|
|
static uint16_t state = 0;
|
|
static uint32_t str_value = 0;
|
|
static uint32_t pump_time = 0;
|
|
/*----------------------------------------------*
|
|
* 模块级变量 *
|
|
*----------------------------------------------*/
|
|
|
|
/*----------------------------------------------*
|
|
* 常量定义 *
|
|
*----------------------------------------------*/
|
|
|
|
#define OVERTIME 45
|
|
//#define __factory_ate_user_test__
|
|
|
|
//#include "interface_comm.h"
|
|
|
|
/// factory_ate_user_test
|
|
#if 0
|
|
void factory_ate_user_test(void)
|
|
{
|
|
#ifdef __factory_ate_user_test__
|
|
int16_t tmp_indx = 0;
|
|
uint8_t send_buff[32] = {0};
|
|
|
|
mcu_rom_read(&send_buff[tmp_indx], GPS_EPHEMERIS_ROM_ADDR, 8);
|
|
tmp_indx += 8;
|
|
mcu_rom_read(&send_buff[tmp_indx], GPS_EPHEMERIS_ROM_ADDR + (24*1024), 8);
|
|
tmp_indx += 8;
|
|
factory_amotas_send_data(send_buff, tmp_indx);
|
|
#endif
|
|
|
|
// alg_gps_pos_proc_test();
|
|
}
|
|
|
|
void factory_ate_charge_check_usb_status(void)
|
|
{
|
|
static uint8_t count = 0;
|
|
bool is_usb_in = user_charge_is_usb_in();
|
|
|
|
count++;
|
|
if ( is_usb_in == false )
|
|
{
|
|
if( count >= 30 )
|
|
{
|
|
count = 0;
|
|
factory_charge_check_xtimer_stop();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
factory_charge_check_xtimer_stop();
|
|
charge_enable();
|
|
factory_charge_open_xtimer_start();
|
|
}
|
|
}
|
|
|
|
#endif
|
|
void factory_ate_sleep_mode(void)
|
|
{
|
|
age_task_suspend();
|
|
// tp_ate_task_suspend();
|
|
// display_ate_task_suspend();
|
|
vTaskSuspend(ate_task_handle);
|
|
}
|
|
|
|
void ate_pump_clear(uint32_t timestamp)
|
|
{
|
|
state = 0;
|
|
timestamp = 0;
|
|
ate_pump_stop_timer();
|
|
pressure_api_close();
|
|
pump_api_out_pwm_control(0,0);
|
|
}
|
|
|
|
#if 1
|
|
/// ate timer time out handle func
|
|
void ate_timer_hdlr(TimerHandle_t xTimer)
|
|
{
|
|
am_util_stdio_printf("ate_timer_hdlr cb: 0x%x \n", g_ate_timer_hdl_cb);
|
|
if ( g_ate_timer_hdl_cb != NULL )
|
|
{
|
|
g_ate_timer_hdl_cb();
|
|
}
|
|
}
|
|
|
|
/// start ate timer
|
|
void ate_start_timer(uint32_t time_ms, ATETimerFuncPtr timeout_cb)
|
|
{
|
|
if ( g_ate_timer_hdl != NULL )
|
|
{
|
|
g_ate_timer_hdl_cb = timeout_cb;
|
|
// xTimerStart(g_ate_timer_hdl, 0);
|
|
xTimerChangePeriod( g_ate_timer_hdl, pdMS_TO_TICKS(time_ms), 0 );
|
|
}
|
|
}
|
|
|
|
/// stop ate timer
|
|
void ate_stop_timer(void)
|
|
{
|
|
if ( g_ate_timer_hdl != NULL )
|
|
{
|
|
xTimerStop(g_ate_timer_hdl, 0);
|
|
}
|
|
g_ate_timer_hdl_cb = NULL;
|
|
}
|
|
|
|
/// creat ate timer
|
|
void ate_creat_timer(void)
|
|
{
|
|
g_ate_timer_hdl = xTimerCreate("ateTimer", pdMS_TO_TICKS(60*1000), true, NULL, ate_timer_hdlr);
|
|
if ( g_ate_timer_hdl == NULL )
|
|
{
|
|
am_util_stdio_printf("ate_creat_timer fail!!! \n");
|
|
}
|
|
}
|
|
#endif
|
|
|
|
/*****************************************************************************
|
|
函 数 名 : task_ate_notify
|
|
功能描述 : 任务事件通知
|
|
输入参数 : uint32_t msgID
|
|
uint32_t data
|
|
输出参数 : 无
|
|
返 回 值 :
|
|
调用函数 :
|
|
被调函数 :
|
|
|
|
修改历史 :
|
|
1.日 期 : 2021年3月26日
|
|
作 者 : Parker
|
|
修改内容 : 新生成函数
|
|
|
|
*****************************************************************************/
|
|
void task_ate_notify(uint32_t msgID, uint32_t data)
|
|
{
|
|
BaseType_t HigherPriorityTaskWoken = pdFALSE;
|
|
TaskMessage_t msg;
|
|
|
|
if(!((ate_task_msgqueue_handle) && (ate_task_handle)))
|
|
{
|
|
return;
|
|
}
|
|
|
|
msg.uMessageID = msgID;
|
|
msg.uData = data;
|
|
if(__get_IPSR() != 0) //判断当前是否在中断中,如果在中断中则调用中断发送事件函数
|
|
{
|
|
xQueueSendToBackFromISR( ate_task_msgqueue_handle, &msg, &HigherPriorityTaskWoken);
|
|
portYIELD_FROM_ISR(HigherPriorityTaskWoken);
|
|
}
|
|
else
|
|
{
|
|
xQueueSendToBack( ate_task_msgqueue_handle, &msg, pdMS_TO_TICKS(1000));
|
|
}
|
|
}
|
|
|
|
void task_ate_notify_ext(uint32_t msgID, uint32_t data, void* buf, uint32_t buf_len)
|
|
{
|
|
BaseType_t HigherPriorityTaskWoken = pdFALSE;
|
|
TaskMessage_t msg = {0};
|
|
|
|
if(!((ate_task_msgqueue_handle) && (ate_task_handle)))
|
|
{
|
|
return;
|
|
}
|
|
|
|
msg.uMessageID = msgID;
|
|
msg.uData = data;
|
|
msg.buf_len = buf_len;
|
|
#ifdef BLE_USE_PSRAM
|
|
msg.buffer = (uint8_t *)PSRAM_MALLOC(buf_len);
|
|
if(msg.buffer == NULL)
|
|
{
|
|
return;
|
|
}
|
|
memcpy(msg.buffer, buf, buf_len);
|
|
#else
|
|
msg.buffer = (uint8_t *)buf;
|
|
#endif
|
|
|
|
if ( __get_IPSR() != 0 )
|
|
{
|
|
xQueueSendToBackFromISR(ate_task_msgqueue_handle, &msg, &HigherPriorityTaskWoken);
|
|
portYIELD_FROM_ISR(HigherPriorityTaskWoken);
|
|
}
|
|
else
|
|
{
|
|
xQueueSendToBack(ate_task_msgqueue_handle, &msg, pdMS_TO_TICKS(1000));
|
|
}
|
|
}
|
|
|
|
|
|
/*****************************************************************************
|
|
函 数 名 : task_ate_entry
|
|
功能描述 : 1.创建任务队列
|
|
2.判断队列数据是否为空
|
|
不为空,则从队列数据接收数据
|
|
输入参数 : void *pvParameters
|
|
输出参数 : 无
|
|
返 回 值 :
|
|
调用函数 :
|
|
被调函数 :
|
|
|
|
修改历史 :
|
|
1.日 期 : 2021年3月26日
|
|
作 者 : Parker
|
|
修改内容 : 新生成函数
|
|
|
|
*****************************************************************************/
|
|
void task_ate_entry(void *pvParameters)
|
|
{
|
|
int32_t read_buff[64] = {0};
|
|
uint16_t read_len = 0;
|
|
uint16_t ret_crc;
|
|
uint8_t len = 8;
|
|
uint8_t buffer[32] = {0xFD, 0x01, 0x00, 0x27, 0x02, 0x04, 0x21, 0x06};
|
|
static uint32_t start_timestamp = 0;
|
|
uint32_t end_timestamp = 0;
|
|
uint32_t inflating_timestamp = 0;
|
|
uint32_t value = 0;
|
|
|
|
TaskMessage_t Msg = {0};
|
|
|
|
factory_uart_cmd_init();
|
|
|
|
ate_creat_timer();
|
|
// factory_mmi_xtimer_refresh_create();
|
|
// factory_charge_open_xtimer_create();
|
|
// factory_charge_check_xtimer_create();
|
|
|
|
while (1)
|
|
{
|
|
if (xQueueReceive( ate_task_msgqueue_handle, &Msg, portMAX_DELAY ) != pdPASS)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
// am_util_stdio_printf("ate task uMessageID: %d\n", Msg.uMessageID);
|
|
switch (Msg.uMessageID)
|
|
{
|
|
case ATE_MSG_AGE_ATSK_OPEN:
|
|
check_age_data();
|
|
creat_age_ate_task((4 * 256), 2);
|
|
break;
|
|
|
|
case ATE_MSG_AGE_FLASH_START:
|
|
// flash_age_chip();
|
|
break;
|
|
|
|
case ATE_MSG_CHG_CHECK_USB_STATUS:
|
|
// flash_age_chip();
|
|
break;
|
|
|
|
case ATE_MSG_PPG_ISR:
|
|
ppg_api_queue_irq_handler();
|
|
break;
|
|
|
|
case ATE_MSG_GPS_UART_ISR:
|
|
// nmea_handle();
|
|
break;
|
|
|
|
case ATE_MSG_BLE_RX_DATA:
|
|
//task_ui_notify(UI_MSG_DISPLAY_OPEN,0,NULL,0);
|
|
ate_production_ble_rx_data_proc(Msg.buf_len,Msg.buffer);
|
|
break;
|
|
|
|
case ATE_MSG_UART_RECV:
|
|
factory_uart_cmd_task_callback(pvParameters, &Msg);
|
|
break;
|
|
|
|
case ATE_MSG_USER_TEST:
|
|
// factory_ate_user_test();
|
|
break;
|
|
case ATE_MSG_GSENSOR_IRQ:
|
|
gsensor_api_queue_irq_handler();
|
|
break;
|
|
case ATE_MSG_TIMER:
|
|
pressure_api_read(read_buff, &read_len);
|
|
len = 8;
|
|
switch(state)
|
|
{
|
|
case PUMP_UP:
|
|
for(int i = 0; i < read_len;i++)
|
|
{
|
|
inflating_timestamp = calculate_inflating_time();
|
|
am_util_stdio_printf("inflating_timestamp == %d\r\n",inflating_timestamp);
|
|
if(inflating_timestamp >= OVERTIME)
|
|
{
|
|
buffer[len ] = read_buff[i] >> 24;
|
|
buffer[len + 1] = read_buff[i] >> 16;
|
|
buffer[len + 2] = read_buff[i] >> 8;
|
|
buffer[len + 3] = read_buff[i];
|
|
len += 4;
|
|
|
|
buffer[len ] = inflating_timestamp >> 24;
|
|
buffer[len + 1] = inflating_timestamp >> 16;
|
|
buffer[len + 2] = inflating_timestamp >> 8;
|
|
buffer[len + 3] = inflating_timestamp;
|
|
len += 4;
|
|
|
|
buffer[len ] = 0x00;
|
|
buffer[len + 1] = 0x00;
|
|
buffer[len + 2] = 0x00;
|
|
buffer[len + 3] = 0x00;
|
|
len += 4;
|
|
|
|
buffer[VALID_DATA_LENGTH_START_NUMBER] = len - INVALID_DATA_LENGTH;
|
|
ret_crc = crc16 ( ( const uint8_t * ) buffer, len );
|
|
buffer[len ] = ( uint8_t ) ( ret_crc >> 8 );
|
|
buffer[len + 1] = ( uint8_t ) ( ret_crc & 0xff );
|
|
len += 2;
|
|
factory_amotas_send_data ( buffer, len );
|
|
ate_pump_clear(start_timestamp);
|
|
break;
|
|
}
|
|
|
|
am_util_stdio_printf("read_buff == %d\r\n",read_buff[i]);
|
|
if(read_buff[i] >= 30000)// 300压强气泵关闭
|
|
{
|
|
start_timestamp = Get_pump_start_timer();
|
|
end_timestamp = rtc_api_get_utc_timestamp();
|
|
value = end_timestamp - start_timestamp;
|
|
am_util_stdio_printf("timestamp == %d\r\n",value);
|
|
|
|
str_value = read_buff[i];
|
|
pump_time = value;
|
|
|
|
pump_api_out_pwm_control(0,0);
|
|
state = 1;
|
|
break;
|
|
}
|
|
}
|
|
break;
|
|
case PUMP_DOWN_OPEN:
|
|
for(int i = 0; i < read_len;i++)
|
|
{
|
|
am_util_stdio_printf("read_buff == %d\r\n",read_buff[i]);
|
|
if(read_buff[i] <= 27000)
|
|
{
|
|
start_timestamp = xTaskGetTickCount();
|
|
state = 2;
|
|
break;
|
|
}
|
|
}
|
|
break;
|
|
case PUMP_DOWN_END:
|
|
for(int i = 0; i < read_len;i++)
|
|
{
|
|
am_util_stdio_printf("read_buff == %d\r\n",read_buff[i]);
|
|
if(read_buff[i] <= 1500)
|
|
{
|
|
end_timestamp = xTaskGetTickCount();
|
|
value = end_timestamp - start_timestamp;
|
|
am_util_stdio_printf("timestamp == %d\r\n",value);
|
|
|
|
buffer[len ] = str_value >> 24;
|
|
buffer[len + 1] = str_value >> 16;
|
|
buffer[len + 2] = str_value >> 8;
|
|
buffer[len + 3] = str_value;
|
|
len += 4;
|
|
|
|
buffer[len ] = pump_time >> 24;
|
|
buffer[len + 1] = pump_time >> 16;
|
|
buffer[len + 2] = pump_time >> 8;
|
|
buffer[len + 3] = pump_time;
|
|
len += 4;
|
|
|
|
buffer[len ] = value >> 24;
|
|
buffer[len + 1] = value >> 16;
|
|
buffer[len + 2] = value >> 8;
|
|
buffer[len + 3] = value;
|
|
len += 4;
|
|
buffer[VALID_DATA_LENGTH_START_NUMBER] = len - INVALID_DATA_LENGTH;
|
|
ret_crc = crc16 ( ( const uint8_t * ) buffer, len );
|
|
buffer[len ] = ( uint8_t ) ( ret_crc >> 8 );
|
|
buffer[len + 1] = ( uint8_t ) ( ret_crc & 0xff );
|
|
len += 2;
|
|
factory_amotas_send_data ( buffer, len );
|
|
state = 0;
|
|
start_timestamp = 0;
|
|
ate_pump_stop_timer();
|
|
pressure_api_close();
|
|
break;
|
|
}
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
/*****************************************************************************
|
|
函 数 名 : factory_create_ate_task
|
|
功能描述 : 创建任务
|
|
输入参数 : void
|
|
输出参数 : 无
|
|
返 回 值 :
|
|
调用函数 :
|
|
被调函数 :
|
|
修改历史 :
|
|
1.日 期 : 2021年3月26日
|
|
作 者 : Parker
|
|
修改内容 : 新生成函数
|
|
|
|
*****************************************************************************/
|
|
void task_ate_init(uint16_t stack_depth, uint16_t priority)
|
|
{
|
|
ate_task_msgqueue_handle = xQueueCreate(16, sizeof(TaskMessage_t));
|
|
|
|
xTaskCreate(task_ate_entry, "task_ate_entry", stack_depth, 0, priority, &ate_task_handle);
|
|
}
|
|
|