-
Notifications
You must be signed in to change notification settings - Fork 10
/
stellaris_setup.m
142 lines (133 loc) · 5.4 KB
/
stellaris_setup.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
function stellaris_setup()
cd('stellaris');
curpath = pwd;
tgtpath = curpath(1:end-length('/stellaris'));
addpath(fullfile(tgtpath, 'stellaris'));
addpath(fullfile(tgtpath, 'demos'));
addpath(fullfile(tgtpath, 'blocks'));
addpath(fullfile(tgtpath, 'help'));
savepath;
if ispref('stellaris')
rmpref('stellaris');
end
addpref('stellaris','TargetRoot',fix_slash(curpath));
addpref('stellaris','COMPort',setup_com_port);
[CCSRoot, CompilerRoot, StellarisWareRoot] = ccs_setup_paths;
addpref('stellaris','CCSRoot',CCSRoot);
addpref('stellaris','CompilerRoot',CompilerRoot);
addpref('stellaris','StellarisWareRoot',StellarisWareRoot);
% Generate blocks
cd('../blocks');
lct_genblocks;
cd(curpath);
% Generate help
cd('../help/source');
genhelp;
cd(curpath);
% External mode support
% % Compilation broken since 16a. Not fixing now, as External mode support is on hiatus anyway.
% if verLessThan('matlab', '8.2')
% ext_loc = ['"',fullfile(matlabroot,'rtw/ext_mode/')];
% else
% %R2013b files moved
% ext_loc = ['"',fullfile(matlabroot,'toolbox/coder/simulinkcoder_core/ext_mode/host/')];
% end
% rtwc_loc = ['"',fullfile(matlabroot,'rtw/c/src/')];
% if isunix
% mexcmd = [ext_loc,'common/ext_comm.c '...
% ext_loc,'common/ext_convert.c '...
% ext_loc,'serial/ext_serial_transport.c '...
% ext_loc,'serial/ext_serial_pkt.c '...
% ext_loc,'serial/rtiostream_serial_interface.c '...
% ext_loc,'common/ext_util.c '...
% '-Irtw/c/src -Irtw/c/src/rtiostream/utils '...
% '-Irtw/c/src/ext_mode/common '...
% '-Irtw/c/src/ext_mode/serial '...
% '-I',ext_loc,'common '...
% '-I',ext_loc,'common/include '...
% '-lmwrtiostreamutils -lmwsl_services '...
% '-DEXTMODE_SERIAL_TRANSPORT -DSL_EXT_SO '...
% '-output ',fullfile(curpath,'../blocks'),'/ext_stellaris_serial'];
% else
% ext_loc(ext_loc=='/')='\';
% mexcmd = [ext_loc,'common\ext_comm.c" '...
% ext_loc,'common\ext_convert.c" '...
% ext_loc,'serial\ext_serial_transport.c" '...
% ext_loc,'serial\ext_serial_pkt.c" '...
% ext_loc,'serial\rtiostream_serial_interface.c" '...
% ext_loc,'common\ext_util.c" '...
% '-I',rtwc_loc,'" -I',rtwc_loc,'rtiostream\utils" '...
% '-I',rtwc_loc,'ext_mode\common" '...
% '-I',rtwc_loc,'ext_mode\serial" '...
% '-I',ext_loc,'common" '...
% '-I',ext_loc,'common\include" '...
% '-lmwrtiostreamutils -lsl_services '...
% '-DEXTMODE_SERIAL_TRANSPORT -DSL_EXT_DLL '...
% '-output ',fullfile(curpath,'..\blocks'),'\ext_stellaris_serial'];
% end
% eval(['mex ',mexcmd]);
cd(fullfile(curpath,'..'));
sl_refresh_customizations;
disp('<strong>TI Stellaris LaunchPad</strong> Target setup is complete!');
disp('Explore <a href="matlab:cd([getpref(''stellaris'',''TargetRoot''),''/../demos''])">demos</a> directory and access <a href="matlab:web(fullfile(getpref(''stellaris'',''TargetRoot''),''../help'',''html'',''index.html''))">documentation</a>')
end
function [CCSRoot, CompilerRoot, StellarisWareRoot] = ccs_setup_paths()
% TODO: make it foolproof
CCSRoot = fix_slash(uigetdir(matlabroot,'CCS root directory: (the one with ccs_base, tools ...)'));
CompilerRoot = fix_slash(uigetdir(CCSRoot,'CCS Compiler root directory: (tools/compiler/arm_5.X.X)'));
StellarisWareRoot = fix_slash(uigetdir(CCSRoot,'StellarisWare root directory: (the one with boards, driverlib ...)'));
end
function COMPort = setup_com_port()
[ports, names] = find_com_ports;
% Choose COM port
[selection,ok] = listdlg('PromptString','Choose TI Stellaris LaunchPad COM port:',...
'SelectionMode','single',...
'ListSize',[260 160],...
'ListString',names);
if (ok == 1 && selection > 2) %have actually chosen COM port
COMPort = char(ports{selection-2}); % -2 for padding with names array
elseif (ok == 1 && selection > 1) %chosen to refresh COM Ports
COMPort = setup_com_port();
else %chosen to enter manually or canceled
COMPort = cell2mat(inputdlg('Enter COM port manually: (ex. COM3 or ttyACM0)','COM port',1));
end
end
function [ports, names] = find_com_ports()
%Find COM ports
names_string = {'Enter COM port manually...','Refresh COM ports list...'};
if isunix
%TODO
%check /dev/serial
unixCmd = 'ls -l /dev/serial/by-id/*';
[unixCmdStatus,unixCmdOutput]=system(unixCmd);
if (unixCmdStatus > 0)
ports = {};
names = {};
else
%names = regexp(unixCmdOutput,'(?<=/dev/serial/by-id/)\S+','match');
%ports = regexp(unixCmdOutput,'(?<=->.*/)tty\w+','match');
[names, ports] = regexp(unixCmdOutput,'(?<=/dev/serial/by-id/)\S.*?((?<=->.*/)tty\w+)','match','tokens');
end
else
wmiCmd = ['wmic /namespace:\\root\cimv2 '...
'path Win32_SerialPort get DeviceID,Name'];
%TODO catch error (wmic is not on WinXP Home for instance).
[~,wmiCmdOutput]=system(wmiCmd);
% in a single regexp call with tokens
[names, ports] = regexp(wmiCmdOutput,'(?<=COM\d+\s*)\S.*?\((COM\d+)\)','match','tokens');
% same in two regexp calls..
%ports = regexp(wmiCmdOutput,'COM\d+(?!\))','match');
%names = regexp(wmiCmdOutput,'(?<=COM\d+\s*)\S.*?\(COM\d+\)','match');
%regCmd=['reg query '...
% 'HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM'];
%[~,regCmdOutput]=system(regCmd);
%ports = regexp(regCmdOutput,'COM\d+','match');
end
names = [names_string,names];
end
function path = fix_slash(path0)
path = path0;
if ispc
path(path=='\')='/';
end
end