1.任务层
/*********************************************************************
* @fn Task_Debug
*
* @brief Debug任务.
*
* @param none
*
* @return none
*/
void Task_Debug(void)
{
/* 执行命令任务 */
if(Command_Debug_Set_Function() == Command_OK)
{
}
}
2.命令层
/**
* @brief debug控制命令
*/
typedef struct
{
Ctrl_StatusTypeDef Ctrl;
uint8_t Timer;
uint8_t Timer_BackUps;
void (* Command)(void);
} Command_Debug;
/* Private define ------------------------------------------------------------*/
#define Command_Debug_Tx(pdata, len) Driver_UART_DMA_Tx(pdata, len)
/* Private function prototypes -----------------------------------------------*/
static void Command_Debug_ADC_Val_String(void);
static void Command_Debug_ADC_Val_Hex(void);
/* Private variables ---------------------------------------------------------*/
static Command_Debug Cmd_Debug[] =
{
// 控制位 运行时间 计数时间 任务命令
{Ctrl_Disable, 0, 10, Command_Debug_ADC_Val_String},
{Ctrl_Disable, 0, 10, Command_Debug_ADC_Val_Hex},
};
/* Private user code ---------------------------------------------------------*/
/*********************************************************************
* @fn Command_Debug_Set_Function
*
* @brief Debug功能命令设置函数.
*
* @param ID:功能ID号.
*
* @return Command_StatusTypeDef:状态标志位
*/
Command_StatusTypeDef Command_Debug_Set_Function(void)
{
for(uint8_t i = 0; i < (sizeof(Cmd_Debug)/sizeof(Cmd_Debug[0])); i++)
{
if(Cmd_Debug[i].Ctrl == Ctrl_Enable)
{
if(++Cmd_Debug[i].Timer >= Cmd_Debug[i].Timer_BackUps)
{
Cmd_Debug[i].Command();
Cmd_Debug[i].Timer = 0;
return Command_OK;
}
}
else
{
Cmd_Debug[i].Timer = 0;
}
}
return Command_ERROR;
}
/*********************************************************************
* @fn Command_Debug_Set_Function_Ctrl
*
* @brief 设置Debug功能命令控制.
*
* @param ID:功能ID号.
*
* @param Ctrl_StatusTypeDef:控制命令
*
* @return none
*/
void Command_Debug_Set_Function_Ctrl(uint8_t ID, Ctrl_StatusTypeDef Ctrl)
{
if(ID < (sizeof(Cmd_Debug)/sizeof(Cmd_Debug[0])))
{
Cmd_Debug[ID].Ctrl = Ctrl;
}
}
/*********************************************************************
* @fn Command_Debug_Set_Function_Timer
*
* @brief 设置Debug功能命令输出时间.
*
* @param ID:功能ID号.
*
* @param time:控制时间
*
* @return none
*/
void Command_Debug_Set_Function_Timer(uint8_t ID, uint8_t time)
{
if(ID < (sizeof(Cmd_Debug)/sizeof(Cmd_Debug[0])))
{
if(Cmd_Debug[ID].Timer_BackUps != time)
{
Cmd_Debug[ID].Timer_BackUps = time;
//将发送时间写入flash
Driver_Write_DFlash_Data(DFlash_Debug_Read_AD, Cmd_Debug[ID].Timer_BackUps, Ctrl_Enable);
}
}
}
/*********************************************************************
* @fn Command_Debug_Init
*
* @brief debug init.
*
* @param none
*
* @return none
*/
static void Command_Debug_Init(void)
{
for(uint8_t i = 0; i < (sizeof(Cmd_Debug)/sizeof(Cmd_Debug[0])); i++)
{
Cmd_Debug[i].Timer_BackUps = Driver_Read_DFlash_Data(DFlash_Debug_Read_AD);
}
}
__Function_AUTOInit_Command(Command_Debug_Init);
/*********************************************************************
* @fn Command_Debug_ADC_Val_String
*
* @brief ADC读取数据 -- 字符串模式.
*
* @param none
*
* @return none
*/
static void Command_Debug_ADC_Val_String(void)
{
Debug("{AD}%d, %d, %d, %d, %d, %d\r\n", \
Task_Get_ADC_Val(Valve_AD_A11), Task_Get_ADC_Val(Valve_AD_B11), \
Task_Get_ADC_Val(Valve_AD_A12), Task_Get_ADC_Val(Valve_AD_B12), \
Task_Get_ADC_Val(Valve_AD_A13), Task_Get_ADC_Val(Valve_AD_B13));
}
/*********************************************************************
* @fn Command_Debug_ADC_Val_Hex
*
* @brief ADC读取数据 -- hex模式.
*
* @param none
*
* @return none
*/
static void Command_Debug_ADC_Val_Hex(void)
{
}