-
-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathEIDEProjectModules.ts
More file actions
3064 lines (2702 loc) · 90.4 KB
/
EIDEProjectModules.ts
File metadata and controls
3064 lines (2702 loc) · 90.4 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import * as events from 'events';
import * as os from 'os';
import * as fs from 'fs';
import * as vscode from 'vscode';
import * as NodePath from 'path';
import { jsonc } from 'jsonc';
import { isNullOrUndefined } from "util";
import * as child_process from 'child_process';
import { File } from "../lib/node-utility/File";
import {
view_str$compile$storageLayout,
view_str$compile$useCustomScatterFile, view_str$compile$scatterFilePath, view_str$compile$scatterFilePath_mdk,
view_str$compile$floatingPointHardware, view_str$compile$cpuType, view_str$compile$deprecated,
view_str$compile$options,
view_str$flasher$binPath,
view_str$flasher$eepromPath,
view_str$flasher$options,
view_str$flasher$interfaceType,
view_str$flasher$cpuName,
view_str$flasher$downloadSpeed,
view_str$flasher$baseAddr,
view_str$flasher$optionBytesPath,
view_str$flasher$launchApp,
view_str$flasher$targetName,
view_str$flasher$flashCommandLine,
view_str$flasher$eraseChipCommandLine,
view_str$flasher$openocd_target_cfg,
view_str$flasher$openocd_interface_cfg,
view_str$flasher$optionBytesConfig,
view_str$flasher$external_loader,
view_str$flasher$resetMode,
view_str$flasher$other_cmds,
view_str$flasher$stcgalOptions,
view_str$compile$archExtensions,
view_str$flasher$eraseAll
} from "./StringTable";
import { ResManager } from "./ResManager";
import { ArrayDelRepetition } from "../lib/node-utility/Utility";
import { GlobalEvent } from "./GlobalEvents";
import { ExceptionToMessage, newMessage } from "./Message";
import { ToolchainName, IToolchian, ToolchainManager } from './ToolchainManager';
import {
HexUploaderType, STLinkOptions, STVPFlasherOptions,
StcgalFlashOption, JLinkOptions, JLinkProtocolType,
PyOCDFlashOptions, OpenOCDFlashOptions, STLinkProtocolType,
ProbeRSFlashOptions,
CustomFlashOptions
} from "./HexUploader";
import { AbstractProject } from "./EIDEProject";
import { SettingManager } from "./SettingManager";
import { WorkspaceManager } from "./WorkspaceManager";
import * as utility from './utility';
import * as ArmCpuUtils from './ArmCpuUtils';
import {
BuilderOptions,
ProjectConfiguration,
ProjectConfigData, BuilderConfigData, ProjectBaseApi
} from './EIDETypeDefine';
export interface Memory {
startAddr: string;
size: string;
}
export interface ComponentFileItem {
attr?: string;
condition?: string;
path: string;
}
// XML define example:
// ---
// <component Cgroup="Drivers" Csub="Touch Screen" condition="STM32F746G-Discovery BSP TS">
// <description>Touch Screen for STMicroelectronics STM32F746G-Discovery Kit</description>
// <files>
// <file category="header" name="Drivers/BSP/STM32746G-Discovery/stm32746g_discovery_ts.h"/>
// <file category="source" name="Drivers/BSP/STM32746G-Discovery/stm32746g_discovery_ts.c"/>
// <file category="source" name="Drivers/BSP/Components/ft5336/ft5336.c"/>
// </files>
// </component>
export interface Component {
groupName: string; // value is: ${Cgroup} + '.' + ${Csub}, and remove whitespace
description?: string;
enable: boolean;
RTE_define?: string;
incDirList: ComponentFileItem[];
headerList: ComponentFileItem[];
cFileList: ComponentFileItem[];
asmList: ComponentFileItem[];
libList?: ComponentFileItem[];
linkerList?: ComponentFileItem[];
defineList?: string[];
condition?: string;
}
export function getComponentKeyDescription(key: string): string {
switch (key) {
case 'incDirList':
return 'Include Path List';
case 'headerList':
return 'Header File List';
case 'cFileList':
return 'Source File List';
case 'asmList':
return 'Assembly File List';
case 'libList':
return 'Library Path List';
case 'linkerList':
return 'Linker File List';
default:
return 'Other List';
}
}
export interface Condition {
condition?: string;
Dvendor?: string;
Dname?: RegExp;
compiler?: string;
compilerOption?: string;
component?: string;
}
export interface ConditionGroup {
acceptList: Condition[];
requireList: Condition[];
}
export type ConditionMap = Map<string, ConditionGroup>;
export interface PackInfo {
vendor: string;
name: string;
familyList: DeviceFamily[];
components: Component[];
conditionMap: ConditionMap;
}
export interface CurrentDevice {
packInfo: PackInfo;
familyIndex: number;
subFamilyIndex: number;
deviceIndex: number;
}
export interface DeviceInfo {
name: string;
devClassName: string;
core?: string;
define?: string;
endian?: string;
svdPath?: string;
storageLayout: ARMStorageLayout;
}
export interface SubFamily {
name: string;
core?: string;
description?: string;
deviceList: DeviceInfo[];
}
export interface DeviceFamily {
name: string;
vendor: string;
core?: string;
series: string;
description?: string;
deviceList: DeviceInfo[];
subFamilyList: SubFamily[];
}
// ======================== config base =============================
type FieldType = 'INPUT' | 'INPUT_INTEGER' | 'SELECTION' | 'OPEN_FILE' | 'EVENT' | 'Disable';
/*
'hex file': ['hex'],
'bin file': ['bin'],
*/
type OpenFileFilter = { [name: string]: string[] };
interface CompileConfigPickItem extends vscode.QuickPickItem {
/**
* 如果 label 和 最终值 不同,则 val 用于存放最终的赋值。否则 val 应为 undefined 或者 null
*/
val?: any;
}
export interface EventData {
event: 'openCompileOptions' | 'openMemLayout' | 'openUploadOptions';
data?: any;
}
export type KeyIcon =
'ConnectUnplugged_16x.svg' |
'BinaryFile_16x.svg' |
'Property_16x.svg' |
'Memory_16x.svg' |
'ConfigurationEditor_16x.svg' |
'CPU_16x.svg' |
'ImmediateWindow_16x.svg';
export abstract class ConfigModel<DataType> {
data: DataType;
readonly boolList = [
false,
true
];
protected _event: events.EventEmitter;
constructor() {
this._event = new events.EventEmitter();
this.data = this.GetDefault();
}
on(event: 'dataChanged', listener: () => void): void; // 当对象本身的属性发生改变后,会产生该事件
on(event: 'event', listener: (event: EventData) => void): void; // 需要打开自定义的GUI界面给用户进行操作时,会产生该事件
on(event: 'NotifyUpdate', listener: (prjConfig: ProjectConfiguration<any>) => void): void;
on(event: any, listener: (arg?: any) => void): void {
this._event.on(event, listener);
}
// 当其他对象更新时,发送该事件通知该对象需要更新自身的相关属性
emit(event: 'NotifyUpdate', prjConfig: ProjectConfiguration<any>): void;
emit(event: any, arg?: any): void {
this._event.emit(event, arg);
}
copyListenerFrom(model: ConfigModel<any>) {
// delete some current listeners
this._event.eventNames().forEach((event) => {
if (event == 'NotifyUpdate') return; // skip 'NotifyUpdate' event
this._event.rawListeners(event).forEach((func) => {
this._event.removeListener(event, <any>func);
});
});
// copy some listeners from old
model._event.eventNames().forEach((event) => {
if (event == 'NotifyUpdate') return; // skip 'NotifyUpdate' event
model._event.rawListeners(event).forEach((func) => {
this._event.addListener(event, <any>func);
});
});
}
async ShowModifyWindow(key: string, prjRootDir: File) {
let keyType = this.GetKeyType(key);
// redirect empty quick pick
let selections: CompileConfigPickItem[] | undefined;
if (this.redirectEmptyQuickPick) {
const nType = this.redirectEmptyQuickPick(key);
if (keyType == 'SELECTION' && nType) {
selections = this.GetSelectionList(key);
if (selections == undefined ||
selections.length == 0) {
keyType = nType;
}
}
}
switch (keyType) {
case 'INPUT':
case 'INPUT_INTEGER':
{
const val = await vscode.window.showInputBox({
value: (<any>this.data)[key],
ignoreFocusOut: true,
validateInput: (input: string): string | undefined => {
return this.VerifyString(key, input);
}
});
switch (keyType) {
case 'INPUT':
this.SetKeyValue(key, val?.trim());
break;
case 'INPUT_INTEGER':
if (val) {
const num = parseInt(val.trim());
if (num !== NaN) {
this.SetKeyValue(key, num);
}
}
break;
default:
break;
}
}
break;
case 'SELECTION':
{
const itemList = selections || this.GetSelectionList(key) || [];
const pickItems = await vscode.window.showQuickPick(itemList, {
canPickMany: this.canSelectMany(key),
matchOnDescription: true,
placeHolder: `found ${itemList.length} results`
});
if (Array.isArray(pickItems)) {
const val = pickItems.map(item => item.val !== undefined ? item.val : item.label).join(',');
this.SetKeyValue(key, val);
} else if (pickItems) {
const val = pickItems.val !== undefined ? pickItems.val : pickItems.label;
this.SetKeyValue(key, val);
}
}
break;
case 'OPEN_FILE':
{
const uri = await vscode.window.showOpenDialog({
defaultUri: vscode.Uri.file(prjRootDir.path),
filters: this.GetOpenFileFilters(key) || { '*.*': ['*'] },
canSelectFiles: true,
canSelectMany: this.canSelectMany(key)
});
if (uri && uri.length > 0) {
const path = uri
.map((uri_item) => { return prjRootDir.ToRelativePath(uri_item.fsPath) || uri_item.fsPath; })
.join(',');
this.SetKeyValue(key, path);
}
}
break;
case 'EVENT':
const eData = this.getEventData(key);
if (eData) {
this._event.emit('event', eData);
}
break;
default:
break;
}
}
SetKeyValue(key: string, value: any) {
if (value !== undefined) {
(<any>this.data)[key] = value;
this.onPropertyChanged(key);
this._event.emit('dataChanged');
}
}
Update(newConfig?: DataType): void {
this.data = this.UpdateConfigData(newConfig);
this._event.emit('dataChanged');
}
isKeyEnable(key: string): boolean {
return true;
}
getKeyIcon(key: string): KeyIcon | undefined {
return 'Property_16x.svg';
}
protected UpdateConfigData(newConfig?: DataType): DataType {
const _default: any = this.GetDefault();
if (newConfig) {
// clear invalid property
for (const key in (<any>newConfig)) {
if (_default[key] === undefined) {
(<any>newConfig)[key] = undefined;
}
}
// set default value
for (const key in _default) {
if (!isNullOrUndefined(_default[key])) {
if (typeof (<any>newConfig)[key] !== typeof _default[key]) {
(<any>newConfig)[key] = _default[key];
}
}
}
return newConfig;
}
return _default;
}
protected onPropertyChanged(key: string) {
// TODO
}
protected canSelectMany(key: string): boolean {
return false;
}
abstract GetKeyDescription(key: string): string;
/**
* @note 注意这个方法当前的含义是获取 display value,用于在UI中显示
* 因此得到的可能不是实际的值(由于历史原因暂时不做修改)
*/
abstract getKeyValue(key: string): string;
protected abstract GetKeyType(key: string): FieldType;
protected abstract GetOpenFileFilters(key: string): OpenFileFilter | undefined;
protected abstract VerifyString(key: string, input: string): string | undefined;
protected abstract GetSelectionList(key: string): CompileConfigPickItem[] | undefined;
protected redirectEmptyQuickPick?: (key: string) => FieldType | undefined;
protected abstract getEventData(key: string): EventData | undefined;
/**
* 获取配置的初始值
* @note 这个方法返回的 object 必须是一个完整的配置对象,
* 包含所有的字段和默认值。其中 key 的顺序决定了 UI 中的显示顺序
*/
abstract GetDefault(): DataType;
}
//////////////////////////////////////////////////////////////////////////////////
// Compiler Models
//////////////////////////////////////////////////////////////////////////////////
export abstract class CompileConfigModel<T> extends ConfigModel<T> {
protected prjConfigData: ProjectConfigData<any>;
constructor(config: ProjectConfigData<any>) {
super();
this.prjConfigData = config;
}
static getInstance<T extends BuilderConfigData>(prjConfigData: ProjectConfigData<any>): CompileConfigModel<T> {
switch (prjConfigData.toolchain) {
case 'SDCC':
return <any>new SdccCompileConfigModel(prjConfigData);
case 'Keil_C51':
return <any>new Keil51CompileConfigModel(prjConfigData);
case 'IAR_STM8':
return <any>new Iarstm8CompileConfigModel(prjConfigData);
case 'COSMIC_STM8':
return <any>new CosmicStm8CompileConfigModel(prjConfigData);
case 'IAR_ARM':
return <any>new IarArmCompileConfigModel(prjConfigData);
case 'AC5':
return <any>new Armcc5CompileConfigModel(prjConfigData);
case 'AC6':
return <any>new Armcc6CompileConfigModel(prjConfigData);
case 'GCC':
return <any>new GccCompileConfigModel(prjConfigData);
case 'RISCV_GCC':
return <any>new RiscvCompileConfigModel(prjConfigData);
case 'ANY_GCC':
return <any>new AnyGccCompileConfigModel(prjConfigData);
case 'GNU_SDCC_STM8':
return <any>new SdccGnuStm8CompileConfigModel(prjConfigData);
case 'GNU_SDCC_MCS51':
return <any>new SdccGnuMcs51CompileConfigModel(prjConfigData);
case 'MTI_GCC':
return <any>new MipsCompileConfigModel(prjConfigData);
case 'LLVM_ARM':
return <any>new LLVMArmCompileConfigModel(prjConfigData);
default:
throw new Error('Unsupported toolchain: ' + prjConfigData.toolchain);
}
}
getOptions(targetName?: string, toolchainName?: ToolchainName): BuilderOptions {
const _targetName = targetName || this.prjConfigData.mode;
const _toolchain = toolchainName || this.prjConfigData.toolchain;
if (this.prjConfigData.targets[_targetName] == undefined) {
return ToolchainManager.getInstance()
.getToolchain(this.prjConfigData.type, _toolchain)
.getDefaultConfig();
}
const allOptions = this.prjConfigData.targets[_targetName].builderOptions;
if (allOptions[_toolchain] == undefined) {
const toolchain = ToolchainManager.getInstance().getToolchain(this.prjConfigData.type, _toolchain);
allOptions[_toolchain] = toolchain.getDefaultConfig();
this._event.emit('dataChanged');
}
return utility.deepCloneObject(allOptions[_toolchain]);
}
setOptions(newBuilderOptions: BuilderOptions, targetName?: string, toolchainName?: ToolchainName) {
const _targetName = targetName || this.prjConfigData.mode;
const _toolchain = toolchainName || this.prjConfigData.toolchain;
if (this.prjConfigData.targets[_targetName] == undefined) {
GlobalEvent.log_warn(`target '${_targetName}' not exist !`);
GlobalEvent.emit('globalLog.show');
return;
}
const allOptions = this.prjConfigData.targets[_targetName].builderOptions;
allOptions[_toolchain] = newBuilderOptions;
this._event.emit('dataChanged');
}
copyCommonCompileConfigFrom(from_toolchain: ToolchainName, from_model: CompileConfigModel<T>) {
// do nothing
}
}
// ------ ARM -------
export type RAMTag = 'IRAM' | 'RAM';
export type ROMTag = 'IROM' | 'ROM';
export interface ARMRamItem {
tag: RAMTag;
id: number;
mem: Memory;
isChecked: boolean;
noInit: boolean;
}
export interface ARMRomItem {
tag: ROMTag;
id: number;
mem: Memory;
isChecked: boolean;
isStartup: boolean;
}
export function getRamRomName(item: ARMRamItem | ARMRomItem): string {
return `${item.tag}${item.id}`;
}
export function getRamRomRange(item: ARMRamItem | ARMRomItem): string {
return `0x${Number(item.mem.startAddr).toString(16).toUpperCase()} - 0x${(Number(item.mem.startAddr) + Number(item.mem.size)).toString(16).toUpperCase()}`
}
export interface ARMStorageLayout {
RAM: ARMRamItem[];
ROM: ARMRomItem[];
}
export type FloatingHardwareOption = 'none' | 'single' | 'double';
/**
* @note 注意,如果后续需要新增字段,则字段必须带有 '| undefined' 的类型,表示可能是未定义的,
* 因为旧的工程可能没有这些字段,会导致报错
*/
export interface ArmBaseCompileData extends BuilderConfigData {
/**
* ARM CPU 类型,可选值包括:
* 'Cortex-M0', 'Cortex-M0+', 'Cortex-M3', 'Cortex-M4', 'Cortex-M7' 等
*/
cpuType: string;
/**
* 是否使用浮点硬件,可选值包括:'single', 'double', 'none'
* 默认为 'none',表示不使用浮点硬件
* @note 这个选项会根据你选择的 cpuType 自动调整,
* 如果你选择的 cpuType 不支持浮点硬件,则会自动设置为 'none'。
*/
floatingPointHardware: FloatingHardwareOption;
/**
* 当 cpuType 是一个 arch 名称时,
* 可以使用这个选项指定该 arch 的扩展功能,
* 例如 'armv8-m.main' 可以使用 '+dsp' 来启用 DSP 指令集。
* 当 cpuType 是一个确切的 cpu 名称时,比如 'Cortex-M4',
* 则这个选项会被忽略。
* @note 如果有多个选项,则选项之间以 ‘,’ 进行分隔
*/
archExtensions?: string;
/**
* 是否使用自定义的链接脚本文件
* @note 这个选项是为 armcc 准备的,
* 如果为 false,则提供一个类似于keil风格的GUI界面来设置存储器布局信息,
* 这个界面会自动生成一个链接脚本文件,并在编译时使用。
* 如果为 true,则需要在 `scatterFilePath` 中指定链接脚本文件的路径
*/
useCustomScatterFile: boolean;
/**
* 这个配置文件用来描述地址重定位信息,编译时作为链接器的参数
* @note 这个参数可能包含多个文件,当包含多个文件时,以逗号 `,` 作为分隔
*/
scatterFilePath: string;
/**
* 这个选项是为 armcc 准备的,
* 如果 useCustomScatterFile 为 false,则提供一个类似于keil风格的GUI界面来设置存储器布局信息,
* 这个界面会自动生成一个链接脚本文件,并在编译时使用。
*/
storageLayout: ARMStorageLayout;
/**
* 由此打开一个更详细的配置,用于设置更多的编译期配置。
* 这个选项的值根据实现而定,多数情况下是空的。
*/
options: string;
}
export type ArmBaseBuilderConfigData = ArmBaseCompileData;
/**
* @note We need export this class, becasue we need export internal functions
* */
export abstract class ArmBaseCompileConfigModel
extends CompileConfigModel<ArmBaseCompileData> {
protected readonly DIV_TAG: string = '<div>:';
protected cpuTypeList = [
'Cortex-M0',
'Cortex-M0+',
'Cortex-M3',
'Cortex-M4',
'Cortex-M7'
];
protected hardwareOptionList: { name: FloatingHardwareOption, desc: string }[] = [
{ name: 'none', desc: 'not use' },
{ name: 'single', desc: 'single precision' },
{ name: 'double', desc: 'double precision' }
];
getValidCpus(): string[] {
return this.cpuTypeList.filter(n => !n.startsWith(this.DIV_TAG));
}
onPropertyChanged(key: string) {
switch (key) {
case 'cpuType':
if (!this.verifyHardwareOption(this.data.floatingPointHardware)) {
this.data.floatingPointHardware = 'none';
}
break;
default:
break;
}
}
copyCommonCompileConfigFrom(from_toolchain: ToolchainName, from_model: ArmBaseCompileConfigModel) {
this.data.floatingPointHardware = from_model.data.floatingPointHardware;
if (this.cpuTypeList.includes(from_model.data.cpuType)) { // found target cpu, update it
this.data.cpuType = from_model.data.cpuType;
} else { // not found, set default
this.data.cpuType = 'Cortex-M3';
GlobalEvent.emit('msg', newMessage('Warning',
`This toolchain not support "${from_model.data.cpuType}". Use default value.`));
}
const cur_toolchain = this.prjConfigData.toolchain;
if (utility.isGccOptionsCompatibleToolchain(from_toolchain) &&
utility.isGccOptionsCompatibleToolchain(cur_toolchain)) {
this.data.scatterFilePath = from_model.data.scatterFilePath;
}
this.onPropertyChanged('cpuType');
}
GetKeyDescription(key: string): string {
const toolchain = this.prjConfigData.toolchain;
switch (key) {
case 'cpuType':
return view_str$compile$cpuType;
case 'archExtensions':
return view_str$compile$archExtensions;
case 'storageLayout':
return view_str$compile$storageLayout;
case 'useCustomScatterFile':
return view_str$compile$useCustomScatterFile;
case 'scatterFilePath':
return (toolchain == 'AC5' || toolchain == 'AC6')
? view_str$compile$scatterFilePath_mdk
: view_str$compile$scatterFilePath;
case 'floatingPointHardware':
return view_str$compile$floatingPointHardware;
case 'options':
return view_str$compile$options;
default:
return view_str$compile$deprecated;
}
}
getKeyIcon(key: string): KeyIcon | undefined {
switch (key) {
case 'cpuType':
return 'CPU_16x.svg';
case 'storageLayout':
return 'Memory_16x.svg';
case 'options':
return 'ConfigurationEditor_16x.svg';
default:
return 'Property_16x.svg';
}
}
getKeyValue(key: string): string {
switch (key) {
case 'storageLayout':
return 'View {...}';
case 'useCustomScatterFile':
return this.data.useCustomScatterFile ? 'true' : 'false';
case 'options':
return 'Object {...}';
default:
return (<any>this.data)[key] || 'null';
}
}
isKeyEnable(key: string): boolean {
const toolchain = this.prjConfigData.toolchain;
if (toolchain === 'AC5' || toolchain === 'AC6') {
// AC6 中的 armv8.1-m 已经含有 arch 扩展,无需额外指定 floatingPointHardware
const is_arm_v8_1_m = this.data.cpuType.toLowerCase().startsWith('armv8.1-m.');
switch (key) {
case 'cpuType':
case 'useCustomScatterFile':
case 'options':
return true;
case 'archExtensions':
return ArmCpuUtils.getArchExtensions(this.data.cpuType, toolchain).length > 0;
case 'floatingPointHardware':
return !is_arm_v8_1_m && ArmCpuUtils.hasFpu(this.data.cpuType);
case 'storageLayout':
return !this.data.useCustomScatterFile;
case 'scatterFilePath':
return this.data.useCustomScatterFile;
default:
return false;
}
} else {
switch (key) {
case 'cpuType':
case 'scatterFilePath':
case 'options':
return true;
case 'archExtensions':
return ArmCpuUtils.getArchExtensions(this.data.cpuType, toolchain).length > 0;
case 'floatingPointHardware':
return ArmCpuUtils.hasFpu(this.data.cpuType) && !ArmCpuUtils.isArmArchName(this.data.cpuType);
default:
return false;
}
}
}
Update(newConfig?: ArmBaseCompileData) {
this.data = this.UpdateConfigData(newConfig);
this.sortStorage(this.data.storageLayout);
this._event.emit('dataChanged');
}
getIRAMx(id: number): Memory | undefined {
for (const ram of this.data.storageLayout.RAM) {
if (ram.tag === 'IRAM' && ram.id === id) {
return ram.mem;
}
}
return undefined;
}
getIROMx(id: number): Memory | undefined {
for (const rom of this.data.storageLayout.ROM) {
if (rom.tag === 'IROM' && id === rom.id) {
return rom.mem;
}
}
return undefined;
}
updateStorageLayout(newLayout: ARMStorageLayout) {
this.data.storageLayout = this.sortStorage(newLayout);
this._event.emit('dataChanged');
}
private parseIntNumber(str: string): number {
if (/^\s*0x/i.test(str) || /[a-f]/i.test(str)) {
return parseInt(str.replace('0X', ''), 16);
} else {
return parseInt(str);
}
}
private sortStorage(storageLayout: ARMStorageLayout): ARMStorageLayout {
storageLayout.RAM = storageLayout.RAM.sort((a, b): number => {
if (a.tag === 'IRAM' && b.tag === 'IRAM') {
return a.id - b.id;
}
if (a.tag === 'IRAM' || b.tag === 'IRAM') {
return a.tag === 'IRAM' ? 1 : -1;
}
if (a.id !== -1 && b.id !== -1) {
return a.id - b.id;
}
return this.parseIntNumber(a.mem.startAddr) < this.parseIntNumber(b.mem.startAddr) ? -1 : 1;
});
let id = 1;
storageLayout.RAM.forEach((ram) => {
if (ram.tag === 'RAM') {
ram.id = id++;
}
});
storageLayout.ROM = storageLayout.ROM.sort((a, b): number => {
if (a.tag === 'IROM' && b.tag === 'IROM') {
return a.id - b.id;
}
if (a.tag === 'IROM' || b.tag === 'IROM') {
return a.tag === 'IROM' ? 1 : -1;
}
if (a.id !== -1 && b.id !== -1) {
return a.id - b.id;
}
return this.parseIntNumber(a.mem.startAddr) < this.parseIntNumber(b.mem.startAddr) ? -1 : 1;
});
id = 1;
storageLayout.ROM.forEach((rom) => {
if (rom.tag === 'ROM') {
rom.id = id++;
}
});
return storageLayout;
}
protected VerifyString(key: string, input: string): string | undefined {
return undefined;
}
protected verifyHardwareOption(optionName: string): boolean {
switch (optionName) {
case 'single':
case 'none': // if mcu have fpu, we need a 'none' option
return ArmCpuUtils.hasFpu(this.data.cpuType);
case 'double':
return ArmCpuUtils.hasFpu(this.data.cpuType, true);
default:
return false;
}
}
protected GetSelectionList(key: string): CompileConfigPickItem[] {
const res: CompileConfigPickItem[] = [];
switch (key) {
case 'cpuType':
this.cpuTypeList.forEach((name) => {
if (name.startsWith(this.DIV_TAG)) {
res.push({
label: name.replace(this.DIV_TAG, ''),
kind: vscode.QuickPickItemKind.Separator
});
} else {
if (ArmCpuUtils.isArmArchName(name)) { // for arch
let descp = '';
let family = ArmCpuUtils.getArchFamily(name);
if (family) descp += family + ', ';
let cpus = ArmCpuUtils.getArchExampleCpus(name);
if (cpus) descp += 'like: ' + cpus.join(',') + '...';
res.push({
label: name,
description: descp
});
} else { // for cpu
res.push({
label: name,
description: `${ArmCpuUtils.getArmCpuArch(name) || ''}`
});
}
}
});
break;
case 'archExtensions':
ArmCpuUtils.getArchExtensions(this.data.cpuType, this.prjConfigData.toolchain).forEach((ext) => {
res.push({
label: ext.name,
detail: ext.description
});
});
break;
case 'floatingPointHardware':
this.hardwareOptionList.filter((option) => {
return this.verifyHardwareOption(option.name);
}).forEach((option) => {
res.push({
label: option.name,
description: option.desc
});
});
break;
default:
this.boolList.forEach((val) => {
res.push({
label: JSON.stringify(val),
val: val
});
});
break;
}
return res;
}
protected GetKeyType(key: string): FieldType {
switch (key) {
case 'scatterFilePath':
return 'INPUT';
case 'cpuType':
case 'floatingPointHardware':
case 'useCustomScatterFile':
case 'archExtensions':
return 'SELECTION';
case 'storageLayout':
case 'options':
return 'EVENT';
default:
return 'Disable';
}
}
protected getEventData(key: string): EventData | undefined {
switch (key) {
case 'storageLayout':
return {
event: 'openMemLayout'
};
case 'options':
return {
event: 'openCompileOptions'
};
default:
return undefined;
}
}
protected canSelectMany(key: string): boolean {
switch (key) {
case 'scatterFilePath':
return true;
case 'archExtensions':
return true;
default:
return super.canSelectMany(key);
}
}
protected GetOpenFileFilters(key: string): OpenFileFilter | undefined {
switch (key) {
case 'scatterFilePath':
return {
'gcc': ['ld', 'lds'],
'armcc': ['sct'],
'all': ['*']
};
default:
return undefined;
}
}
static getDefaultConfig(): ArmBaseCompileData {
return {
cpuType: 'Cortex-M3',
archExtensions: '',
floatingPointHardware: 'none',
useCustomScatterFile: false,
scatterFilePath: '<YOUR_SCATTER_FILE>.sct',
storageLayout: {
RAM: [
{
tag: 'IRAM',
id: 1,
mem: {
startAddr: '0x20000000',
size: '0x5000'
},
isChecked: true,
noInit: false