码迷,mamicode.com
首页 > 其他好文 > 详细

舒适系统设计-功能模块生成模板-说明

时间:2016-06-18 11:23:30      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:

1.自定义模板

在IAR系统中,edit->code templates  可以编辑与使用自定义模板

通过使用生成 H文件与C文件来生成各个功能模块

2.模块文件

################################################################################
##
## This is an example file for defining your own code templates.
##
## The syntax for defining a code template is:
## #TEMPLATE <template name>,<field>[=default value], <field>...
##
## The template name, the fields and their default values should be defined 
## within quotes if they contain non-alphanumeric characters.
## Use "&" in front of a letter in the template name to make the letter become 
## a shortcut, which means that you can use ALT+<letter> to select the template 
## or jump to the field in the dialog box.
## Use ">" in the template to organize the template names in submenus.
##
################################################################################
#TEMPLATE "&Statement>&if"
if( %c )
{
  
}

#TEMPLATE &Statement>&for,"&End Value"=10,&Variable=i
for(int %2 = 0; %2 < %1; ++%2)
{
  %c
}

#TEMPLATE &Statement>&optimize,&optimize
#pragma optimize=%1


#TEMPLATE &Corporate>&class,"Class &name",&Description=--,&Created="$DATE$, by $USER_NAME$"
//******************
// CLASS: %1
//
// DESCRIPTION:
//  %2
//
// CREATED: %3
//
// FILE: $FILE_FNAME$
//
class %1
{
public:
  %1();
  ~%1();
  %c
};

#TEMPLATE &Corporate>&class,"Class &name",&Description=--,&Created="$DATE$, by $USER_NAME$"
//******************
// CLASS: %1
//
// DESCRIPTION:
//  %2
//
// CREATED: %3
//
// FILE: $FILE_FNAME$
//
class %1
{
public:
  %1();
  ~%1();
  %c
};

#TEMPLATE &Corporate>&Task,"Task &name",&Description=--

Task_RET_E %1_Task_Temp(uint32 para1,uint32 para2,void* pt);

const Task_S g_st%1Task[]=
{
   {MSG_ID_TEMPLATE_DEFAULT,"task_temp",%1_Task_Temp}
}

/**
  * @brief   消息处理 
  * %2         
  * @param   
  *          para1 参数1,para2 参数2
             pt   参数指针传递
  * @retval bool -true  消息已处理 false 消息未处理
  */
Task_RET_E %1_Task_Temp(uint32 para1,uint32 para2,void* pt)
{
}

#TEMPLATE &Corporate>&Funtion,"Funtion &name",&Description=-- ,&Para ,&ret
/**
  * @brief   %2
  *
  * @param
  *
  * @retval void
  */

%4 %1(%3)
{
    return ;
}



#TEMPLATE &File>&file_h,"&file name",&Description=--,&Created="$DATE$, by $USER_NAME$"

/**
  ******************************************************************************
  * File Name          : %1.h
  * Description        : %2
  * Created            : %3
  ******************************************************************************
  *
  ******************************************************************************
  */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __%1_H
#define __%1_H
#ifdef __cplusplus
 extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "stm32f3xx_hal.h"
#include "datatype.h"
#include "osal.h"  
/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

/* USER CODE BEGIN Private defines */

/* USER CODE END Private defines */

/* USER CODE BEGIN Prototypes */
extern const  OsalFnx_S g_st%1OsalFn;
/* USER CODE END Prototypes */

#ifdef __cplusplus
}
#endif
#endif /*__ %1_H */

/**
  * @}
  */

/************************ (C) COPYRIGHT Chongqingfuzik *****END OF FILE****/

#TEMPLATE &File>&file_c,"&file name",&Created="$DATE$, by $USER_NAME$"
/**
  ******************************************************************************
  * @file    %1.c
  * @created: %2
  * @brief   
  *           
  *          
  *          
  *          
  *           
  ==============================================================================
                      ##### %1 specific features #####
  ==============================================================================
  [..] 
    

                     ##### How to use this file #####
  ==============================================================================
  [..]
    
  ******************************************************************************
  */

/* Includes ------------------------------------------------------------------*/
#include  "%1.h"
#include  "msg_def.h"
#include  "trace.h"  

#define _use_%1_module
#ifdef _use_%1_module
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
void   %1_Init(void);
void   %1_Start(void);
void   %1_Tick(void);
void   %1_Process(void);
void   %1_Process_1s(void);
void   %1_Process_1min(void);
BOOL   %1_Trace(void);
RESP_E
%1_Debug(const uint8* in);
BOOL   %1_Message_Deal(Msg_Id_E msg,uint32 para1,uint32 para2,void* pt);
uint16  %1_Trace_Pwr(void);
/* Exported functions --------------------------------------------------------*/
const  OsalFnx_S g_st%1OsalFn=
{
    %1_Init,
    %1_Start,
    %1_Tick,
    %1_Process,
    %1_Process_1s,
    %1_Process_1min,
    %1_Debug,
    %1_Message_Deal,
    %1_Trace_Pwr
};
/** 
  ==============================================================================
          ##### Initialization and de-initialization functions #####
  ==============================================================================
  [..]  

  */

/**
  * @brief   模块初始化
  *          
  * @param   
  *               
  * @retval 
  */
void   %1_Init(void)
{
    Trace_Stack(%1_Init);
}

/**
  * @brief   模块开始运行
  *          
  * @param   
  *               
  * @retval 
  */
void   %1_Start(void)
{
    Trace_Stack(%1_Start);
}

/**
  * @brief   10ms中断处理,处理实时任务
  *          
  * @param   
  *               
  * @retval 
  */
void   %1_Tick(void)
{
    Trace_Stack(%1_Tick);
}

/**
  * @brief   10ms过程处理,处理非实时任务
  *          
  * @param   
  *               
  * @retval 
  */
void   %1_Process(void)
{
    Trace_Stack(%1_Process);
}

/**
  * @brief   1s过程处理,处理非实时任务
  *          
  * @param   
  *               
  * @retval 
  */
void   %1_Process_1s(void)
{
    Trace_Stack(%1_Process_1s);
}

/**
  * @brief   1min过程处理,处理非实时任务
  *          
  * @param   
  *               
  * @retval 
  */
void   %1_Process_1min(void)
{
    Trace_Stack(%1_Process_1min);
}

/**
  * @brief   调试接口
  *          
  * @param   in 需要处理的字符串
  *               
  * @retval  处理结果,参RESP_E
  */
RESP_E   %1_Debug(const uint8* in)
{
    Trace_Stack(%1_Debug);
    return RESP_NULL;
}

/**
  * @brief   消息处理
  *          
  * @param   msg 消息id
  *          para1 参数1,para2 参数2
             pt   参数指针传递
  * @retval bool -true  消息已处理 false 消息未处理
  */
BOOL   %1_Message_Deal(Msg_Id_E msg,uint32 para1,uint32 para2,void* pt)
{
     if(!Msg_Id_IsValid(msg)){return FALSE;}
     Trace_Stack(%1_Message_Deal);
     
     return TRUE;
}

/**
  * @brief   电源管理
  *
  * @param
  *
  * @retval uint16 -禁止进入STOP模式的时间,以10ms为单
  */
uint16  %1_Trace_Pwr(void)
{
    Trace_Stack(%1_Trace_Pwr);
    return 0;
}

#endif /* %1_MODULE_ENABLED */
/**
  * @}
  */

/**
  * @}
  */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

3.使用模块

1.在msg_def.c中 包含模板的头文件

2.在

const FileModoule_S g_stFileModoule[Modoule_ID_MAX+1]=
{
    {Modoule_ID_NULL,NULL,NULL},
    {Modoule_ID_TRACE,"trace",&g_stTraceOsalFn},
    {Modoule_ID_HWDPT,"hwdpt",&g_sthwdptOsalFn}, 

    {Modoule_ID_MAX,NULL,NULL}
};

关联模块ID,名称及调用函数结构体

舒适系统设计-功能模块生成模板-说明

标签:

原文地址:http://www.cnblogs.com/jiangbo1980/p/5595749.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!