⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flasherase.m

📁 matlab给DSP编程的代码
💻 M
字号:
function flashEraseStatus=flashErase(ccLink,device,sectorEraseMask,flashApiLib,flashApiHeadersListStruct)
% FLASHERASE - Erase c28xx flash sectors
%
%   Copyright 2006 The MathWorks, Inc.
%   $Revision: 1.1.6.1 $
%   $Date: 2006/11/29 22:35:05 $

ccsProjectName = 'flashErtest';
outFileName = strcat(ccsProjectName,'.out'); % To load the .out from MATLAB

switch device
    case {'F2812' 'F2811' 'F2810'}
        flashdeviceHeader = fullfile(matlabroot,'toolbox','rtw','targets',...
            'ccslink','ccslink','inc','DSP281x_Device.h');
        flashApiExamplesHeader = fullfile(matlabroot,'toolbox','rtw','targets',...
            'ccslink','ccslink','inc','DSP281x_Examples.h');
        dspGlobalVariableDefsSrcFile = fullfile(matlabroot,'toolbox','rtw','targets',...
            'ccslink','ccslink','src','DSP281x_GlobalVariableDefs.c');
        dspSysCtrlSrcFile = fullfile(matlabroot,'toolbox','rtw','targets',...
            'ccslink','ccslink','src','DSP281x_SysCtrl.c');
        flashEraseCmdFile = fullfile(matlabroot,'toolbox','rtw','targets','tic2000',...
            'tic2000demos','flashSourceCode','flash281xprog.cmd');
    case {'F2801' 'F2802' 'F2806' 'F2808' 'F2809' 'F28015' 'F28016' 'F28044'}
        flashdeviceHeader = fullfile(matlabroot,'toolbox','rtw','targets',...
            'ccslink','ccslink','inc','DSP280x_Device.h');
        flashApiExamplesHeader = fullfile(matlabroot,'toolbox','rtw','targets',...
            'ccslink','ccslink','inc','DSP280x_Examples.h');
        dspGlobalVariableDefsSrcFile = fullfile(matlabroot,'toolbox','rtw','targets',...
            'ccslink','ccslink','src','DSP280x_GlobalVariableDefs.c');
        dspSysCtrlSrcFile = fullfile(matlabroot,'toolbox','rtw','targets',...
            'ccslink','ccslink','src','DSP280x_SysCtrl.c');
        flashEraseCmdFile = fullfile(matlabroot,'toolbox','rtw','targets','tic2000',...
            'tic2000demos','flashSourceCode','flash280xprog.cmd');
    otherwise
        error('Invalid device specified');
end

rtsLibFile = fullfile(ccLink.ccsappexe,'..','..','C2000','cgtools','lib','rts2800_ml.lib');

flashEraseSrcFile = fullfile(matlabroot,'toolbox','rtw','targets','tic2000',...
    'tic2000demos','flashSourceCode','testEraseFlash.c');

mwflashApiHeadersFile = 'tmwFlashApiHeaders.h'; % flash API headers

currDir = cd;

warning off;
mkdir(ccsProjectName);
warning on;

cd(ccLink,ccsProjectName);

% Creating a generic header files which includes the headers provided as
% function arguments

fpHeaders = fopen(fullfile(pwd,ccsProjectName,mwflashApiHeadersFile),'w');

%flashApiHeadersListStruct
fprintf(fpHeaders,'#include "%s"\n',flashApiHeadersListStruct.flashapiconfig);
fprintf(fpHeaders,'#include "%s"\n',flashApiHeadersListStruct.flashapilib);
fprintf(fpHeaders,'#include "%s"\n',flashdeviceHeader);
fprintf(fpHeaders,'#include "%s"\n',flashApiExamplesHeader);

fclose(fpHeaders);

try
    warning off;
    save(ccLink,ccsProjectName,'project');
    close(ccLink,ccsProjectName,'project');
    warning on;
catch
    warning on;
end
new(ccLink,ccsProjectName,'project');
% Adding files to the flashErase project

% Current CCS working directory

currentCcsWorkingDirectory = ccLink.cd;

add(ccLink,flashEraseSrcFile);
add(ccLink,flashEraseCmdFile);

add(ccLink,dspGlobalVariableDefsSrcFile);
add(ccLink,dspSysCtrlSrcFile);

% To set the build options to satisfy all dependencies

buopts = ccLink.getbuildopt;

compilerOptionString = strcat(buopts(4).optstring,'-i "."',' -i"',currentCcsWorkingDirectory,'"',...
    ' -i"',matlabroot,'\toolbox\rtw\targets\ccslink\ccslink\inc"');

setbuildopt(ccLink,'Compiler',compilerOptionString);

linkerOptionString = strcat('-c -m"',ccsProjectName,'.map" -o"',ccsProjectName,...
    '.out" -w -x',' -stack400',' -i"',matlabroot,...
    '\toolbox\rtw\targets\ccslink\rtlib"',' -l"',rtsLibFile,'"',...
    ' -l"',flashApiLib,'"');

setbuildopt(ccLink,'Linker',linkerOptionString);

% Saving the project in CCS
save(ccLink,ccsProjectName,'project');
build(ccLink,'all');
reset(ccLink);
load(ccLink,outFileName);
restart(ccLink);
run(ccLink,'main');

ccLink.write(ccLink.address('SectorMask'),uint16(hex2dec(sectorEraseMask)));
% sectorObj = createobj(ccLink,'SectorMask');
% sectorObj.write(uint16(hex2dec(sectorEraseMask)));

ffs = list(ccLink, 'function', 'main');
FuncAdd = ffs.main.address;
insert(ccLink,FuncAdd.end(1));

disp(['Erasing Flash sectors 0x' sectorEraseMask ' .......'])
run(ccLink,'runtohalt',1000);

flashEraseStatus = ccLink.read(ccLink.address('EraseStatus'),'uint16');

if flashEraseStatus
    cleanup;
    error(['Flash Erase API returned error code:' num2str(flashEraseStatus)]);
else
    disp(['Erasing Flash sectors 0x' sectorEraseMask ' successful!'])
end

cleanup;

    function cleanup

        try
            warnstate = warning;  % Save the current warning state
            warning off;
            delete(ccLink,'all');
            save(ccLink,ccsProjectName,'project');
            close(ccLink,ccsProjectName,'project');
            cd(ccsProjectName)
            delete('*.*');  % to delete all the files
            rmdir('*.*','s'); %  to delete all the directories
            cd(currDir);
            rmdir(ccsProjectName,'s');
            warning(warnstate);
        catch
        end
    end %cleanup function
end %function


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -