这个文件是在模型生成代码的各个过程都会存在作用.这个函数的作用就是规定编译的过程
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 雨的旋律汽车电子开发板
% 网店地址:http://shop108493800.taobao.com/
% 技术支持QQ群:153167747
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function MC9S12XEP100_make_rtw_hook(method, modelName, rtwRoot, tmf, buildOpts, buildArgs, rtwDepTable)
%fprintf(1, ‘\n### %s: %s (%s)\n’, mfilename, method, modelName);
switch method
case ‘entry’
disp(['### Starting Real-Time Workshop build procedure for ', …
'model: ’ modelName]);
case ‘before_tlc’
% No action
case ‘after_tlc’
% No action
case ‘before_make’
% No action
case ‘after_make’
% No action
case ‘exit’
% Get codewarrior project file
srcMCPProjectPathAndFile=‘F:\资料\单片机\MC9S12XEP100单片机\MC9S12XEP100\MC9S12XEP100\MC9S12XEP100.mcp’;
//上面是CW的路径
% Get the action
cs = getActiveConfigSet(modelName);
//上面那个modelName就是simulink自己起的名字
action = lower(get_param(cs,‘BuildAction’));
//上面的action 其实就是你添加的Action设置的是RUN还是BUILD
cwautomation(srcMCPProjectPathAndFile, action);
**//调用CW的函数**
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Abstract: Copy project from the location specified by targetPrefs entry and
% place entire duplicate in a directory relative to current “pwd”
%
function cwautomation(srcMCPProjectPathAndFile, action)
[srcProjDir, srcProjFile, projSuffix] = fileparts(srcMCPProjectPathAndFile);
**//上面三个参数的意思是把的路径,文件名,扩展名分解开**
dstProjDir = rtw_alt_pathname(pwd);
//pwd是代码生成目录,就是把文件路径给dstProjDir
dstMCPProjectPathAndFile = [pwd,'\',srcProjFile,projSuffix];
cFileList = dir([pwd '\*.c']);
**//列出所有的C文件**
hFileList = dir([pwd '\*.h']);
**//列出所有的h文件**
Files = {cFileList(:).name,hFileList(:).name};
//所有的C文件和H文件添加到
dosCommand = 'xcopy /S /Y';
**//复制所有的文件和文件夹到当前的文件夹里**
dosCmdString = [dosCommand,' ',srcProjDir,' ',dstProjDir];
[~, ~] = dos(dosCmdString);
% 将生成的代码添加到Codewarrior工程中
ICodeWarriorApp = actxserver('CodeWarrior.CodeWarriorApp');
**//打开CW编译器**
ICodeWarriorProject = invoke(ICodeWarriorApp.Application,'OpenProject',dstMCPProjectPathAndFile,1,0,0);
**//调用CW中的OpenProject,打开dstMCPProjectPathAndFile这个路径中的文件**
ICodeWarriorApp.DefaultProject.Close;
ICodeWarriorProject = invoke(ICodeWarriorApp.Application,'OpenProject',dstMCPProjectPathAndFile,1,0,0);
% targets = ICodeWarriorProject.Targets
% numtargets = targets.Count;
% for i=0:(numtargets-1)
for j = 1:length(Files)
ICodeWarriorProject.Targets.Item(0).AddFile([pwd ‘’ Files{j}], ‘RTWSources’);
//上面是将C文件和H文件添加到RTWSources文件夹中去
end
% end
**% 根据模型配置选择编译方式//根据设置的是RUN还是BUILD来执行**
disp(['### Invoking CodeWarrior with ', upper(action),' action.'])
disp(['### Target project: ',dstMCPProjectPathAndFile])
ICodeWarriorApp.DefaultProject.RemoveObjectCode(0,1);
//上面代码的作用是
switch action
case 'build'
ICodeWarriorApp.DefaultProject.BuildAndWaitToComplete;
//上面就是工程文件的CW编译MAKE
case 'run'
ICodeWarriorApp.DefaultProject.BuildWithOptions(0,2);
//上面就是在CW里面下程序的按键debug
end
disp(['### Completed target action: ',action]);