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,名稱及調用函數結構體