一个好用的Debug轮询任务框架

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)
{

}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值