@mchp-mcc/dspic33a-flash 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,975 @@
1
+ import * as Processor from "@microchip/scf-common/lib/Processor";
2
+ import {
3
+ AppModel,
4
+ DerivedData,
5
+ DerivedFunctions,
6
+ } from "../generated_module/src/types/AutoModuleTypes";
7
+ import { InterfaceId } from "@microchip/scf-common/lib/InterfaceId";
8
+ import * as flash_interface from "@microchip/flash-interface";
9
+ import { ExportArg } from "@microchip/melody-automodule-interface/lib/src/InterfaceTypes";
10
+ import * as config_16bit_interface from "@microchip/config-16bit-interface";
11
+ import * as interrupt16bitInterface from "@microchip/interrupt-16bit-interface";
12
+ import * as system_16bit_initializer from "@microchip/system-16bit-initializer";
13
+ import { nvm_ctrl_32bit_upb_v1 } from "@mchp-mcc/pic-16bit-types/types/nvm_ctrl_32bit_upb_v1/nvm_ctrl_32bit_upb_v1";
14
+ import { generatableItems } from "./GeneratorModel";
15
+ import _find from "lodash.find";
16
+ import { HeaderFile } from "@microchip/scf-interface";
17
+
18
+ const FLASH_UNLOCK_KEY = "0x00AA0055";
19
+ export const FLASH_INSTRUCTION_TYPE = "uint32_t";
20
+ export const MODULE_NAME = "FLASH";
21
+ const FLASH_WRITE_INSTRUCTION_COUNT = "flashWriteInstructionCount";
22
+ const DEFAULT_WRITE_SIZE = 4;
23
+ const OPTION_BLOCKING = "Blocking";
24
+ const OPTION_NON_BLOCKING = "Non-Blocking";
25
+ const CONFIG_16BIT_INTERFACE = "config_16bit_interface";
26
+ export const ARGUMENT_GENERATE_API = "generateAPI";
27
+ export const ARGUMENT_INTERRUPT_DRIVEN = "interruptDriven";
28
+
29
+ export const getDerivedData = (dataModel: AppModel): DerivedData => {
30
+ if (dataModel) {
31
+ return new MyDerivedData(dataModel);
32
+ }
33
+ return new EmptyDerivedData();
34
+ };
35
+
36
+ export const getMyDerivedData = (dataModel: AppModel): MyDerivedData | DerivedData => {
37
+ if (dataModel) {
38
+ return new MyDerivedData(dataModel);
39
+ }
40
+ return new EmptyDerivedData();
41
+ };
42
+
43
+ //This data will be used at the creator stage and relies on only the state
44
+ class EmptyDerivedData implements DerivedData {
45
+ getMyFunctions = (): DerivedFunctions => {
46
+ return {};
47
+ };
48
+ getModel = (): AppModel | undefined => {
49
+ return undefined;
50
+ };
51
+ }
52
+
53
+ //This data will be used at the processor stage
54
+ export class MyDerivedData implements DerivedData {
55
+ private dataModel: AppModel;
56
+
57
+ constructor(dataModel: AppModel) {
58
+ this.dataModel = dataModel;
59
+ }
60
+
61
+ getMyFunctions = (): DerivedFunctions => {
62
+ return {
63
+ exportApi: this.getMyExportApi,
64
+ templateData: this.getMyTemplateData,
65
+ alerts: this.getMyAlerts,
66
+ blockingAPIGenerate: this.getBlockingAPIGenerationStatus,
67
+ nonBlockingAPIGenerate: this.getNonBlockingAPIGenerationStatus,
68
+ overrideOptions: this.overrideOptions,
69
+ overrideDefaultValues: this.overrideDefaultValue,
70
+ "flash-interface_payload": this.basic_flash_payload,
71
+ importName: this.friendlyImportName,
72
+ exportName: this.friendlyExportName,
73
+ isInterfaceUsed: this.isFlashInterfaceUsed,
74
+ enableInterfaceDefinitionGeneration: this.enableInterfaceDefinitionGeneration,
75
+ interrupt_service_results: this.getFlashInterruptData,
76
+ system_16bit_initializer_results: this.system_16bit_initializer_results,
77
+ config_16bit_interface_args: this.getConfigBitArgs,
78
+ config_16bit_interface_results: this.getConfigBitArgs,
79
+ calculatedFunction: this.calculatedFunction,
80
+ };
81
+ };
82
+
83
+ private getMyExportApi = (interfaceId: InterfaceId): any => {
84
+ if (
85
+ interfaceId.name === flash_interface.Interface.getInterfaceId().name &&
86
+ interfaceId.version === flash_interface.Interface.getInterfaceId().version
87
+ ) {
88
+ const firmwareApi = flash_interface.Interface.createFirmwareApi(MODULE_NAME);
89
+ return {
90
+ api: firmwareApi.api,
91
+ headerFiles: firmwareApi.headerFiles,
92
+ };
93
+ }
94
+ };
95
+
96
+ private getMyTemplateData = (): any => {
97
+ return generatableItems(this.dataModel).getGeneratableItems();
98
+ };
99
+
100
+ getMyProcessedArgValue = (
101
+ componentName: string,
102
+ exportArg: ExportArg[],
103
+ ): ExportArg | undefined => {
104
+ let processedArg: ExportArg | undefined;
105
+ exportArg.some((arg) => {
106
+ if (arg.interface === flash_interface.Interface.getInterfaceId().name) {
107
+ processedArg = this.basic_flash_args(componentName, arg);
108
+ if (processedArg != undefined) {
109
+ return true;
110
+ }
111
+ }
112
+ });
113
+ return processedArg;
114
+ };
115
+
116
+ private overrideOptions = (componentName: string): any[] => {
117
+ const defaultValue = [];
118
+ switch (componentName) {
119
+ case FLASH_WRITE_INSTRUCTION_COUNT: {
120
+ const flashWriteSize = String(this.getFlashWordWriteSizeInInstructions());
121
+ const flashRowWriteSize = String(
122
+ this.getFlashWriteRowSizeInInstructions(),
123
+ );
124
+ return [flashWriteSize, flashRowWriteSize];
125
+ }
126
+ default:
127
+ return defaultValue;
128
+ }
129
+ };
130
+
131
+ private overrideDefaultValue = (componentName: string): any => {
132
+ let retValue;
133
+ switch (componentName) {
134
+ case FLASH_WRITE_INSTRUCTION_COUNT: {
135
+ retValue = String(this.getFlashWordWriteSizeInInstructions());
136
+ break;
137
+ }
138
+ default: {
139
+ break;
140
+ }
141
+ }
142
+ return retValue;
143
+ };
144
+
145
+ private friendlyImportName = (importKey: string): string => {
146
+ let importName: string;
147
+ switch (importKey) {
148
+ case "nvm_ctrl_32bit_v1":
149
+ importName = "Flash Hardware";
150
+ break;
151
+ case "system_16bit_initializer":
152
+ importName = "System Initializer";
153
+ break;
154
+ case "config_16bit_interface":
155
+ importName = "Configuration Bits";
156
+ break;
157
+ default:
158
+ importName = importKey;
159
+ }
160
+ return importName;
161
+ };
162
+
163
+ private friendlyExportName = (exportKey: string): string => {
164
+ let exportName = exportKey;
165
+ if (exportKey === "flash") {
166
+ exportName = "Flash";
167
+ }
168
+ return exportName;
169
+ };
170
+
171
+ private getActiveName = (): string => {
172
+ return "Flash PLIB";
173
+ };
174
+
175
+ private isFlashInterfaceUsed = (): boolean => {
176
+ const exportData:
177
+ | ExportArg[]
178
+ | undefined = this.dataModel.getExportInterfaces().getInterfaceData();
179
+ const interfaceData = _find(
180
+ exportData,
181
+ (i) => i.interface === flash_interface.Interface.getInterfaceId().name,
182
+ );
183
+ const result = this.dataModel
184
+ ?.getExportInterfaces()
185
+ .getInterface("flash_interface", flash_interface.Interface.getInterfaceId())
186
+ ?.results;
187
+ if (interfaceData || result) {
188
+ return true;
189
+ }
190
+ return false;
191
+ };
192
+
193
+ private getModuleNameForInterrupt = (): string => {
194
+ return this.getFlashHardwareData()?.name.toLocaleUpperCase() ?? "FLASH";
195
+ };
196
+
197
+ private getInterruptData = (
198
+ interruptAliasList: string[],
199
+ ): interrupt16bitInterface.InterruptParameter[] => {
200
+ const interruptData: interrupt16bitInterface.InterruptParameter[] = [];
201
+ const isInterruptDriven = this.isInterruptMode();
202
+ interruptAliasList.forEach((interruptAlias) => {
203
+ interruptData.push({
204
+ interruptName:
205
+ this.dataModel?.getHardware()?.getPeripheral()?.interrupts?.[
206
+ interruptAlias
207
+ ]?.name ?? "",
208
+ isEnabled: isInterruptDriven,
209
+ });
210
+ });
211
+ return interruptData;
212
+ };
213
+
214
+ private getFlashHardwareData = (): nvm_ctrl_32bit_upb_v1 | undefined => {
215
+ return this.getModel().getImportValue("nvm_ctrl_32bit_upb_v1");
216
+ };
217
+
218
+ private basic_flash_args = (
219
+ componentName: string,
220
+ arg: ExportArg | undefined,
221
+ ): ExportArg | undefined => {
222
+ let processedArg: ExportArg | undefined;
223
+ switch (componentName) {
224
+ case FLASH_WRITE_INSTRUCTION_COUNT:
225
+ if (arg != undefined && arg.name === FLASH_WRITE_INSTRUCTION_COUNT) {
226
+ processedArg = {
227
+ interface: arg.interface,
228
+ name: arg.name,
229
+ value: this.getFlashWriteInstructionCountToImpl(arg.value),
230
+ module: arg.module,
231
+ };
232
+ }
233
+ break;
234
+ default:
235
+ break;
236
+ }
237
+
238
+ return processedArg;
239
+ };
240
+
241
+ private getFlashWriteInstructionCountToImpl = (flashWriteInstCount: any): number => {
242
+ if (flashWriteInstCount != undefined) {
243
+ let flashWriteCount = flashWriteInstCount;
244
+ const minFlashWordSize = this.getFlashWordWriteSizeInInstructions();
245
+ const flashRowWriteSize = this.getFlashWriteRowSizeInInstructions();
246
+ if (
247
+ flashWriteInstCount != minFlashWordSize &&
248
+ flashWriteInstCount != flashRowWriteSize
249
+ ) {
250
+ flashWriteCount = minFlashWordSize;
251
+ }
252
+ return flashWriteCount;
253
+ } else {
254
+ return DEFAULT_WRITE_SIZE;
255
+ }
256
+ };
257
+
258
+ private isGenerateNonBlockingAPI = (): boolean => {
259
+ let generateNonBlockingAPI = false;
260
+ const flashInterfaceResult = this.getFlashResults(ARGUMENT_GENERATE_API);
261
+ if (flashInterfaceResult != undefined) {
262
+ if (flashInterfaceResult != OPTION_BLOCKING) {
263
+ generateNonBlockingAPI = true;
264
+ } else {
265
+ generateNonBlockingAPI = false;
266
+ }
267
+ }
268
+ return generateNonBlockingAPI;
269
+ };
270
+
271
+ private system_16bit_initializer_results = (): system_16bit_initializer.Results => {
272
+ if (this.isFlashInterfaceUsed()) {
273
+ if (
274
+ this.getNonBlockingAPIGenerationStatus() &&
275
+ this.getInterruptDrivenStatus()
276
+ ) {
277
+ return {
278
+ initializer: [
279
+ {
280
+ funcName: "FLASH_Initialize",
281
+ header: {
282
+ name: "flash_nonblocking.h",
283
+ path: "../flash/",
284
+ },
285
+ },
286
+ ],
287
+ };
288
+ }
289
+ }
290
+ return {};
291
+ };
292
+
293
+ private getExportArg = (componentName: string): ExportArg | undefined => {
294
+ const exportData:
295
+ | ExportArg[]
296
+ | undefined = this.dataModel.getExportInterfaces().getInterfaceData();
297
+ const expArg = _find(
298
+ exportData,
299
+ (i) =>
300
+ i.interface === flash_interface.Interface.getInterfaceId().name &&
301
+ i.name === componentName,
302
+ );
303
+ return expArg;
304
+ };
305
+
306
+ private getConfigBitArgs = (): config_16bit_interface.Arguments => {
307
+ return {
308
+ configBitByAliasFilter: ["BTMODE"],
309
+ configBitSet: {},
310
+ };
311
+ };
312
+
313
+ private getDualPartitionDetails = ():
314
+ | flash_interface.DualPartitionDetails
315
+ | undefined => {
316
+ const hasDualPartition = this.getFlashHasDualPartition();
317
+ if (hasDualPartition) {
318
+ return {
319
+ flashFirstPartitionEndAddress: this.getFlashFirstPartitionEndAddress(),
320
+ flashSecondPartitionBeginAddress: this.getFlashSecondPartitionStartAddress(),
321
+ flashSecondPartitionProgramBeginAddress: this.getFlashSecondPartitionProgramStartAddress(),
322
+ flashSecondPartitionEndAddress: this.getFlashSecondPartitionEndAddress(),
323
+ };
324
+ }
325
+ };
326
+
327
+ private getMyAlerts = (): Processor.Alert[] => {
328
+ return [];
329
+ };
330
+
331
+ private calculatedFunction = (): any => {
332
+ return;
333
+ };
334
+
335
+ /********************public functions ************************** */
336
+
337
+ public basic_flash_payload = (): any => {
338
+ let headerFiles: HeaderFile[] | undefined = [];
339
+ if (this.getFlashHasDualPartition() && this.getFlashDualPartitionEnabled()) {
340
+ headerFiles = [{ name: "flash_nonblocking.h", path: "flash/" }];
341
+ } else {
342
+ headerFiles = flash_interface.Interface.createFirmwareApi(
343
+ this.dataModel.getName(),
344
+ ).headerFiles;
345
+ }
346
+ return {
347
+ interfaceApi: flash_interface.Interface.createFirmwareApi(
348
+ this.dataModel.getName(),
349
+ headerFiles,
350
+ ),
351
+ flashWriteInstructionCount: this.getFlashWriteInstructionCount(),
352
+ flashInterface: this.getFlashInterface(),
353
+ flashWordWriteSizeInInstructions: this.getFlashWordWriteSizeInInstructions(),
354
+ flashEraseInstructionCount: this.getFlashEraseInstructionCount(),
355
+ flashHasAuxiliary: this.getFlashHasAuxiliary(),
356
+ flashEnduranceMinimum: this.getFlashEnduranceMinimum(),
357
+ flashBytesPerInstruction: this.getFlashBytesPerInstruction(),
358
+ flashPcUnitsPerInstruction: this.getFlashPcUnitsPerInstruction(),
359
+ flashWordWriteOpCode: this.getFlashWordWriteOpCode(),
360
+ flashOpCodeMask: this.getFlashOpCodeMask(),
361
+ flashErasePageSizeInInstructions: this.getFlashErasePageSizeInInstructions(),
362
+ flashErasePageOpCode: this.getFlashErasePageOpCode(),
363
+ flashHasEcc: this.getFlashHasEcc(),
364
+ flashHasRowProgramming: this.getFlashHasRowProgramming(),
365
+ flashWriteRowSizeInInstructions: this.getFlashWriteRowSizeInInstructions(),
366
+ flashWriteRowOpCode: this.getFlashWriteRowOpCode(),
367
+ flashEndAddress: this.getFlashEndAddress(),
368
+ flashProgramBeginAddress: this.getFlashProgramBeginAddress(),
369
+ flashUnlockKey: this.getFlashUnlockKey(),
370
+ flashHasDualPartition: this.getFlashHasDualPartition(),
371
+ flashBootMode: this.getFlashBootModeValue(),
372
+ flashDualPartitionDetails: this.getDualPartitionDetails(),
373
+ };
374
+ };
375
+
376
+ public getFlashInterface = (): string => {
377
+ return "FLASH_UNIFIED_MEMORY_MAP_QUAD_WORD_v1.0";
378
+ };
379
+
380
+ public enableInterfaceDefinitionGeneration = (): boolean => {
381
+ let enableInterfaceGeneration = false;
382
+ if (
383
+ this.isFlashInterfaceUsed() &&
384
+ this.dataModel?.getImportValue("system_16bit_initializer")
385
+ ?.enableInterfaceDefinitionGeneration
386
+ ) {
387
+ enableInterfaceGeneration = true;
388
+ }
389
+ return enableInterfaceGeneration;
390
+ };
391
+
392
+ public getFlashInterruptData = (): interrupt16bitInterface.Results => {
393
+ const interruptList: string[] = [];
394
+ const interrupts = this.getFlashHardwareData()?.interrupts;
395
+ for (const key in interrupts) {
396
+ interruptList.push(key);
397
+ }
398
+ return {
399
+ moduleName: this.getModuleNameForInterrupt(),
400
+ interruptData: this.getInterruptData(interruptList),
401
+ };
402
+ };
403
+
404
+ public isInterruptMode = (): boolean => {
405
+ if (this.isFlashInterfaceUsed()) {
406
+ return this.getInterruptDrivenStatus();
407
+ } else {
408
+ return false;
409
+ }
410
+ };
411
+
412
+ public getInterruptDrivenStatus = (): boolean => {
413
+ let interruptDriven = false;
414
+ const flashInterfaceResult = this.getFlashResults(ARGUMENT_INTERRUPT_DRIVEN);
415
+ if (flashInterfaceResult != undefined) {
416
+ interruptDriven = flashInterfaceResult;
417
+ }
418
+ return interruptDriven;
419
+ };
420
+
421
+ public getFlashWordWriteSizeInInstructions = (): number | undefined => {
422
+ return this.getFlashWordWriteSizeInInstructionsValue(this.dataModel);
423
+ };
424
+
425
+ public getFlashWordWriteSizeInInstructionsValue = (
426
+ model: AppModel | undefined,
427
+ ): number | undefined => {
428
+ let flashWordWriteSizeInInstructions: number | undefined;
429
+ if (
430
+ model?.getHardware()?.getPeripheral()?.properties
431
+ ?.FLASH_WORD_WRITE_SIZE_IN_INSTRUCTIONS?.value != undefined
432
+ ) {
433
+ flashWordWriteSizeInInstructions = Number(
434
+ model.getHardware()?.getPeripheral()?.properties
435
+ ?.FLASH_WORD_WRITE_SIZE_IN_INSTRUCTIONS?.value,
436
+ );
437
+ }
438
+ return flashWordWriteSizeInInstructions;
439
+ };
440
+
441
+ public getFlashEraseInstructionCount = (): number | undefined => {
442
+ return this.getFlashEraseInstructionCountValue(this.dataModel);
443
+ };
444
+
445
+ public getFlashEraseInstructionCountValue = (
446
+ model: AppModel | undefined,
447
+ ): number | undefined => {
448
+ let flashEraseInstructionCount: number | undefined;
449
+ if (
450
+ model?.getHardware()?.getPeripheral()?.properties
451
+ ?.FLASH_ERASE_PAGE_SIZE_IN_INSTRUCTIONS?.value != undefined
452
+ ) {
453
+ flashEraseInstructionCount = Number(
454
+ model?.getHardware()?.getPeripheral()?.properties
455
+ ?.FLASH_ERASE_PAGE_SIZE_IN_INSTRUCTIONS?.value,
456
+ );
457
+ }
458
+ return flashEraseInstructionCount;
459
+ };
460
+
461
+ public getFlashHasAuxiliary = (): number | undefined => {
462
+ return this.getFlashHasAuxiliaryValue(this.dataModel);
463
+ };
464
+
465
+ public getFlashHasAuxiliaryValue = (
466
+ model: AppModel | undefined,
467
+ ): number | undefined => {
468
+ let flashHasAuxiliary: number | undefined;
469
+ if (
470
+ model?.getHardware()?.getPeripheral()?.properties?.FLASH_HAS_AUXILIARY
471
+ ?.value != undefined
472
+ ) {
473
+ flashHasAuxiliary =
474
+ model?.getHardware()?.getPeripheral()?.properties?.FLASH_HAS_AUXILIARY
475
+ ?.value == "TRUE"
476
+ ? 1
477
+ : 0;
478
+ }
479
+ return flashHasAuxiliary;
480
+ };
481
+
482
+ public getFlashEnduranceMinimum = (): number | undefined => {
483
+ return this.getFlashEnduranceMinimumValue(this.dataModel);
484
+ };
485
+
486
+ public getFlashEnduranceMinimumValue = (
487
+ model: AppModel | undefined,
488
+ ): number | undefined => {
489
+ let flashMinEndurance: number | undefined;
490
+ if (
491
+ model?.getHardware()?.getPeripheral()?.properties?.FLASH_ENDURANCE_MINIMUM
492
+ ?.value != undefined
493
+ ) {
494
+ flashMinEndurance = Number(
495
+ model.getHardware()?.getPeripheral()?.properties?.FLASH_ENDURANCE_MINIMUM
496
+ ?.value,
497
+ );
498
+ }
499
+ return flashMinEndurance;
500
+ };
501
+
502
+ public getFlashBytesPerInstruction = (): number | undefined => {
503
+ return this.getFlashBytesPerInstructionValue(this.dataModel);
504
+ };
505
+
506
+ public getFlashBytesPerInstructionValue = (
507
+ model: AppModel | undefined,
508
+ ): number | undefined => {
509
+ let flashBytesPerInstruction = 4;
510
+ if (
511
+ model?.getHardware()?.getPeripheral()?.properties?.FLASH_BYTES_PER_INSTRUCTION
512
+ ?.value != undefined
513
+ ) {
514
+ flashBytesPerInstruction = Number(
515
+ model.getHardware()?.getPeripheral()?.properties
516
+ ?.FLASH_BYTES_PER_INSTRUCTION?.value,
517
+ );
518
+ }
519
+ return flashBytesPerInstruction;
520
+ };
521
+
522
+ public getFlashPcUnitsPerInstruction = (): number | undefined => {
523
+ return this.getFlashPcUnitsPerInstructionValue(this.dataModel);
524
+ };
525
+
526
+ public getFlashPcUnitsPerInstructionValue = (
527
+ model: AppModel | undefined,
528
+ ): number | undefined => {
529
+ let flashPcUnitsPerInstruction = 1;
530
+ if (
531
+ model?.getHardware()?.getPeripheral()?.properties
532
+ ?.FLASH_PC_UNITS_PER_INSTRUCTION?.value != undefined
533
+ ) {
534
+ flashPcUnitsPerInstruction = Number(
535
+ model.getHardware()?.getPeripheral()?.properties
536
+ ?.FLASH_PC_UNITS_PER_INSTRUCTION?.value,
537
+ );
538
+ }
539
+ return flashPcUnitsPerInstruction;
540
+ };
541
+
542
+ public getFlashWordWriteOpCode = (): number | undefined => {
543
+ return this.getFlashWordWriteOpCodeValue(this.dataModel);
544
+ };
545
+
546
+ public getFlashWordWriteOpCodeValue = (
547
+ model: AppModel | undefined,
548
+ ): number | undefined => {
549
+ let flashWordWriteOpcode: number | undefined;
550
+ if (
551
+ model?.getHardware()?.getPeripheral()?.properties?.FLASH_WORD_WRITE_OP_CODE
552
+ ?.value != undefined
553
+ ) {
554
+ flashWordWriteOpcode = Number(
555
+ model.getHardware()?.getPeripheral()?.properties?.FLASH_WORD_WRITE_OP_CODE
556
+ ?.value,
557
+ );
558
+ }
559
+ return flashWordWriteOpcode;
560
+ };
561
+
562
+ public getFlashOpCodeMask = (): number | undefined => {
563
+ return this.getFlashOpCodeMaskValue(this.dataModel);
564
+ };
565
+
566
+ public getFlashOpCodeMaskValue = (
567
+ model: AppModel | undefined,
568
+ ): number | undefined => {
569
+ let flashOpcodeMaks: number | undefined;
570
+ if (
571
+ model?.getHardware()?.getPeripheral()?.properties?.FLASH_OP_CODE_MASK
572
+ ?.value != undefined
573
+ ) {
574
+ flashOpcodeMaks = Number(
575
+ model.getHardware()?.getPeripheral()?.properties?.FLASH_OP_CODE_MASK
576
+ ?.value,
577
+ );
578
+ }
579
+ return flashOpcodeMaks;
580
+ };
581
+
582
+ public getFlashErasePageSizeInInstructions = (): number | undefined => {
583
+ return this.getFlashErasePageSizeInInstructionsValue(this.dataModel);
584
+ };
585
+
586
+ public getFlashErasePageSizeInInstructionsValue = (
587
+ model: AppModel | undefined,
588
+ ): number | undefined => {
589
+ let flashErasePageSizeInInstructions: number | undefined;
590
+ if (
591
+ model?.getHardware()?.getPeripheral()?.properties
592
+ ?.FLASH_ERASE_PAGE_SIZE_IN_INSTRUCTIONS?.value != undefined
593
+ ) {
594
+ flashErasePageSizeInInstructions = Number(
595
+ model.getHardware()?.getPeripheral()?.properties
596
+ ?.FLASH_ERASE_PAGE_SIZE_IN_INSTRUCTIONS?.value,
597
+ );
598
+ }
599
+ return flashErasePageSizeInInstructions;
600
+ };
601
+
602
+ public getFlashErasePageOpCode = (): number | undefined => {
603
+ return this.getFlashErasePageOpCodeValue(this.dataModel);
604
+ };
605
+
606
+ public getFlashErasePageOpCodeValue = (
607
+ model: AppModel | undefined,
608
+ ): number | undefined => {
609
+ let flashErasePageOpCode: number | undefined;
610
+ if (
611
+ model?.getHardware()?.getPeripheral()?.properties?.FLASH_ERASE_PAGE_OP_CODE
612
+ ?.value != undefined
613
+ ) {
614
+ flashErasePageOpCode = Number(
615
+ model.getHardware()?.getPeripheral()?.properties?.FLASH_ERASE_PAGE_OP_CODE
616
+ ?.value,
617
+ );
618
+ }
619
+ return flashErasePageOpCode;
620
+ };
621
+
622
+ public getFlashHasEcc = (): number | undefined => {
623
+ return this.getFlashHasEccValue(this.dataModel);
624
+ };
625
+
626
+ public getFlashHasEccValue = (model: AppModel | undefined): number | undefined => {
627
+ let flashHasEcc: number | undefined;
628
+ if (
629
+ model?.getHardware()?.getPeripheral()?.properties?.FLASH_HAS_ECC?.value !=
630
+ undefined
631
+ ) {
632
+ flashHasEcc =
633
+ model.getHardware()?.getPeripheral()?.properties?.FLASH_HAS_ECC?.value ==
634
+ "TRUE"
635
+ ? 1
636
+ : 0;
637
+ }
638
+ return flashHasEcc;
639
+ };
640
+
641
+ public getFlashHasRowProgramming = (): number | undefined => {
642
+ return this.getFlashHasRowProgrammingValue(this.dataModel);
643
+ };
644
+
645
+ public getFlashHasRowProgrammingValue = (
646
+ model: AppModel | undefined,
647
+ ): number | undefined => {
648
+ let flashHasRowProgramming: number | undefined;
649
+ if (
650
+ model?.getHardware()?.getPeripheral()?.properties?.FLASH_HAS_ROW_PROGRAMMING
651
+ ?.value != undefined
652
+ ) {
653
+ flashHasRowProgramming =
654
+ model.getHardware()?.getPeripheral()?.properties
655
+ ?.FLASH_HAS_ROW_PROGRAMMING?.value == "TRUE"
656
+ ? 1
657
+ : 0;
658
+ }
659
+ return flashHasRowProgramming;
660
+ };
661
+
662
+ public getFlashWriteRowSizeInInstructions = (): number | undefined => {
663
+ return this.getFlashWriteRowSizeInInstructionsValue(this.dataModel);
664
+ };
665
+
666
+ public getFlashWriteRowSizeInInstructionsValue = (
667
+ model: AppModel | undefined,
668
+ ): number | undefined => {
669
+ let flashWriteRowSizeInInstructions: number | undefined;
670
+ if (
671
+ model?.getHardware()?.getPeripheral()?.properties
672
+ ?.FLASH_WRITE_ROW_SIZE_IN_INSTRUCTIONS?.value != undefined
673
+ ) {
674
+ flashWriteRowSizeInInstructions = Number(
675
+ model?.getHardware()?.getPeripheral()?.properties
676
+ ?.FLASH_WRITE_ROW_SIZE_IN_INSTRUCTIONS?.value,
677
+ );
678
+ }
679
+ return flashWriteRowSizeInInstructions;
680
+ };
681
+
682
+ public getFlashWriteRowOpCode = (): number | undefined => {
683
+ return this.getFlashWriteRowOpCodeValue(this.dataModel);
684
+ };
685
+
686
+ public getFlashWriteRowOpCodeValue = (
687
+ model: AppModel | undefined,
688
+ ): number | undefined => {
689
+ let flashWriteRowOpCode;
690
+ if (
691
+ model?.getHardware()?.getPeripheral()?.properties?.FLASH_WRITE_ROW_OP_CODE
692
+ ?.value != undefined
693
+ ) {
694
+ flashWriteRowOpCode = Number(
695
+ model?.getHardware()?.getPeripheral()?.properties?.FLASH_WRITE_ROW_OP_CODE
696
+ ?.value,
697
+ );
698
+ }
699
+ return flashWriteRowOpCode;
700
+ };
701
+
702
+ public getFlashEndAddress = (): number | undefined => {
703
+ return this.getFlashEndAddressValue(this.dataModel);
704
+ };
705
+
706
+ public getFlashEndAddressValue = (
707
+ model: AppModel | undefined,
708
+ ): number | undefined => {
709
+ let flashEndAddress: number | undefined;
710
+ if (
711
+ model?.getHardware()?.getPeripheral()?.properties?.FLASH_END_ADDRESS?.value !=
712
+ undefined
713
+ ) {
714
+ flashEndAddress = Number(
715
+ model.getHardware()?.getPeripheral()?.properties?.FLASH_END_ADDRESS
716
+ ?.value,
717
+ );
718
+ }
719
+ return flashEndAddress;
720
+ };
721
+
722
+ public getFlashProgramBeginAddress = (): number | undefined => {
723
+ return this.getFlashProgramBeginAddressValue(this.dataModel);
724
+ };
725
+
726
+ public getFlashProgramBeginAddressValue = (
727
+ model: AppModel | undefined,
728
+ ): number | undefined => {
729
+ let flashProgramBeginAddress: number | undefined;
730
+ if (
731
+ model?.getHardware()?.getPeripheral()?.properties?.PROGRAM_BEGIN_ADDRESS
732
+ ?.value != undefined
733
+ ) {
734
+ flashProgramBeginAddress = Number(
735
+ model.getHardware()?.getPeripheral()?.properties?.PROGRAM_BEGIN_ADDRESS
736
+ ?.value,
737
+ );
738
+ }
739
+ return flashProgramBeginAddress;
740
+ };
741
+
742
+ public getFlashUnlockKey = (): string => {
743
+ return FLASH_UNLOCK_KEY;
744
+ };
745
+
746
+ public getFlashHasDualPartition = (): boolean | undefined => {
747
+ return this.getHasDualPartitionValue(this.dataModel);
748
+ };
749
+
750
+ public getHasDualPartitionValue = (
751
+ model: AppModel | undefined,
752
+ ): boolean | undefined => {
753
+ let flashHasDualPartition: boolean | undefined;
754
+ const hasDualPartition = model?.getHardware()?.getPeripheral()?.properties
755
+ ?.FLASH_HAS_DUAL_PARTITION?.value;
756
+ if (hasDualPartition != undefined) {
757
+ if (hasDualPartition == "TRUE") {
758
+ flashHasDualPartition = true;
759
+ } else {
760
+ flashHasDualPartition = false;
761
+ }
762
+ }
763
+ return flashHasDualPartition;
764
+ };
765
+
766
+ public getFlashBootModeValue = (): string | undefined => {
767
+ let btMode: string | undefined;
768
+ const interfaceData: config_16bit_interface.ProcessedPayload = this.dataModel.getImportValue(
769
+ CONFIG_16BIT_INTERFACE,
770
+ );
771
+ if (interfaceData != undefined) {
772
+ btMode = interfaceData.configBitSettingValueAliasMap["BTMODE"];
773
+ }
774
+ return btMode;
775
+ };
776
+
777
+ public getFlashFirstPartitionEndAddress = (): number | undefined => {
778
+ return this.getFlashFirstPartitionEndAddressValue(this.dataModel);
779
+ };
780
+
781
+ public getFlashFirstPartitionEndAddressValue = (
782
+ model: AppModel | undefined,
783
+ ): number | undefined => {
784
+ let flashFirstPartitionEndAddress: number | undefined;
785
+ if (
786
+ model?.getHardware()?.getPeripheral()?.properties
787
+ ?.FLASH_FIRST_PARTITION_END_ADDRESS?.value != undefined
788
+ ) {
789
+ flashFirstPartitionEndAddress = Number(
790
+ model.getHardware()?.getPeripheral()?.properties
791
+ ?.FLASH_FIRST_PARTITION_END_ADDRESS?.value,
792
+ );
793
+ }
794
+ return flashFirstPartitionEndAddress;
795
+ };
796
+
797
+ public getFlashSecondPartitionStartAddress = (): number | undefined => {
798
+ return this.getFlashSecondPartitionStartAddressValue(this.getModel());
799
+ };
800
+
801
+ public getFlashSecondPartitionStartAddressValue = (
802
+ model: AppModel | undefined,
803
+ ): number | undefined => {
804
+ let flashSecondPartitionStartAddress: number | undefined;
805
+ if (
806
+ model?.getHardware()?.getPeripheral()?.properties
807
+ ?.FLASH_SECOND_PARTITION_START_ADDRESS?.value != undefined
808
+ ) {
809
+ flashSecondPartitionStartAddress = Number(
810
+ model.getHardware()?.getPeripheral()?.properties
811
+ ?.FLASH_SECOND_PARTITION_START_ADDRESS?.value,
812
+ );
813
+ }
814
+ return flashSecondPartitionStartAddress;
815
+ };
816
+
817
+ public getFlashSecondPartitionProgramStartAddress = (): number | undefined => {
818
+ return this.getFlashSecondPartitionProgramStartAddressValue(this.getModel());
819
+ };
820
+
821
+ public getFlashSecondPartitionProgramStartAddressValue = (
822
+ model: AppModel | undefined,
823
+ ): number | undefined => {
824
+ let flashSecondPartitionProgramStartAddress: number | undefined;
825
+ if (
826
+ model?.getHardware()?.getPeripheral()?.properties
827
+ ?.FLASH_SECOND_PARTITION_PROGRAM_START_ADDRESS?.value != undefined
828
+ ) {
829
+ flashSecondPartitionProgramStartAddress = Number(
830
+ model.getHardware()?.getPeripheral()?.properties
831
+ ?.FLASH_SECOND_PARTITION_PROGRAM_START_ADDRESS?.value,
832
+ );
833
+ }
834
+ return flashSecondPartitionProgramStartAddress;
835
+ };
836
+
837
+ public getFlashSecondPartitionEndAddress = (): number | undefined => {
838
+ return this.getFlashSecondPartitionEndAddressValue(this.getModel());
839
+ };
840
+
841
+ public getFlashSecondPartitionEndAddressValue = (
842
+ model: AppModel | undefined,
843
+ ): number | undefined => {
844
+ let flashSecondPartitionEndAddress: number | undefined;
845
+ if (
846
+ model?.getHardware()?.getPeripheral()?.properties
847
+ ?.FLASH_SECOND_PARTITION_END_ADDRESS?.value != undefined
848
+ ) {
849
+ flashSecondPartitionEndAddress = Number(
850
+ model.getHardware()?.getPeripheral()?.properties
851
+ ?.FLASH_SECOND_PARTITION_END_ADDRESS?.value,
852
+ );
853
+ }
854
+ return flashSecondPartitionEndAddress;
855
+ };
856
+
857
+ public getFlashDualPartitionEnabled = (): boolean | undefined => {
858
+ return this.getDualPartitionEnabledValue(this.dataModel);
859
+ };
860
+
861
+ public getDualPartitionEnabledValue = (
862
+ model: AppModel | undefined,
863
+ ): boolean | undefined => {
864
+ let flashIsDualPartitionEnabled: boolean | undefined = false;
865
+ const btMode = this.getFlashBootModeValue();
866
+ if (btMode != undefined) {
867
+ if (btMode != "SINGLE") {
868
+ flashIsDualPartitionEnabled = true;
869
+ }
870
+ }
871
+ return flashIsDualPartitionEnabled;
872
+ };
873
+
874
+ public getFlashWriteInstructionCount = (): number => {
875
+ const flashWriteInstCount = this.basic_flash_args(
876
+ FLASH_WRITE_INSTRUCTION_COUNT,
877
+ this.getExportArg(FLASH_WRITE_INSTRUCTION_COUNT),
878
+ );
879
+ if (flashWriteInstCount != undefined) {
880
+ return Number(flashWriteInstCount.value);
881
+ } else {
882
+ return Number(this.getFlashWordWriteSizeInInstructions());
883
+ }
884
+ };
885
+
886
+ public getBlockingAPIGenerationStatus = (): boolean => {
887
+ let generateBlockingAPI = true;
888
+ const flashInterfaceResult = this.getFlashResults(ARGUMENT_GENERATE_API);
889
+ if (flashInterfaceResult != undefined) {
890
+ if (flashInterfaceResult != OPTION_NON_BLOCKING) {
891
+ generateBlockingAPI = true;
892
+ } else {
893
+ generateBlockingAPI = false;
894
+ }
895
+ }
896
+ return generateBlockingAPI;
897
+ };
898
+
899
+ public getNonBlockingAPIGenerationStatus = (): boolean | undefined => {
900
+ let nonBlockingAPIGenerate = this.isGenerateNonBlockingAPI();
901
+ if (nonBlockingAPIGenerate) {
902
+ if (this.getFlashHasDualPartition() == undefined) {
903
+ nonBlockingAPIGenerate = false;
904
+ }
905
+ }
906
+ return nonBlockingAPIGenerate;
907
+ };
908
+
909
+ public getFlashResults = (resultsArg: string): any => {
910
+ let result: any;
911
+ const flashResults = this.dataModel
912
+ ?.getExportInterfaces()
913
+ .getInterface("flash_interface", flash_interface.Interface.getInterfaceId())
914
+ ?.results;
915
+ if (flashResults != undefined) {
916
+ for (const moduleId in flashResults) {
917
+ result = flashResults[moduleId]?.[resultsArg];
918
+ }
919
+ }
920
+ return result;
921
+ };
922
+
923
+ public getProperties = (): any => {
924
+ return this.getPropertiesValue(this.dataModel);
925
+ };
926
+
927
+ public getPropertiesValue = (model: AppModel | undefined): any => {
928
+ if (model?.getHardware() != undefined) {
929
+ return model.getHardware()?.getPeripheral()?.properties;
930
+ }
931
+ };
932
+
933
+ public getFlashWordWriteOpCodeHexString = (): string => {
934
+ const opcode = this.getFlashWordWriteOpCode();
935
+ return this.getHexaDecimalString(opcode);
936
+ };
937
+
938
+ public getFlashOpCodeMaskHexString = (): string => {
939
+ const opcode = this.getFlashOpCodeMask();
940
+ return this.getHexaDecimalString(opcode);
941
+ };
942
+
943
+ public getFlashErasePageOpCodeHexString = (): string => {
944
+ const opcode = this.getFlashErasePageOpCode();
945
+ return this.getHexaDecimalString(opcode);
946
+ };
947
+
948
+ public getFlashWriteRowOpCodeHexString = (): string => {
949
+ const opcode = this.getFlashWriteRowOpCode();
950
+ return this.getHexaDecimalString(opcode);
951
+ };
952
+
953
+ public getFlashEndAddressHexString = (): string => {
954
+ const opcode = this.getFlashEndAddress();
955
+ return this.getHexaDecimalString(opcode);
956
+ };
957
+
958
+ public getFlashProgramBeginAddressHexString = (): string => {
959
+ const opcode = this.getFlashProgramBeginAddress();
960
+ return this.getHexaDecimalString(opcode);
961
+ };
962
+
963
+ private getHexaDecimalString = (opcode: number | undefined): string => {
964
+ if (opcode != undefined) {
965
+ return "0x" + opcode.toString(16);
966
+ } else {
967
+ opcode = 0;
968
+ return "0x" + opcode.toString(16);
969
+ }
970
+ };
971
+
972
+ public getModel = (): AppModel => {
973
+ return this.dataModel;
974
+ };
975
+ }