@mchp-mcc/scf-pic8-pwm-v2 4.2.9 → 4.2.11

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.
@@ -1,346 +0,0 @@
1
- import {
2
- AppModel,
3
- DerivedData,
4
- DerivedFunctions,
5
- } from "../generated_module/src/types/AutoModuleTypes";
6
- import * as Processor from "@microchip/scf-common/lib/Processor";
7
- import { PwmCalculator } from "./PwmCalculator";
8
- import * as pwm_general from "./interfaces/pwm_general_parameters";
9
- import * as initializer_system from "@microchip/initializer-system";
10
- import { Interface, Arguments } from "@microchip/scf-interface";
11
- import { getGeneratorModel, getHeaderFiles } from "./GeneratorModel";
12
- import { MyComponentNames, MyExportNames } from "../generated_module/src/types";
13
- import { getAutoSdlHelp } from "@microchip/scf-automodule-impl/lib/autoModule/ContextualHelp";
14
- import { getPinsLogic } from "../generated_module/src/pins/PCPHelper";
15
- import { MyImports } from "../generated_module/src/types";
16
- import { getCFunctionValidator, PatternValidator } from "@microchip/scf-validators/lib";
17
- import { QueryAdapterKey, intf_args } from "@microchip/pin-standard/lib/pin-standard";
18
-
19
- export const getDerivedData = (dataModel: AppModel): DerivedData => {
20
- if (dataModel) {
21
- return new MyDerivedData(dataModel);
22
- }
23
- return new EmptyDerivedData();
24
- };
25
-
26
- //This data will be used at the creator stage and relies on only the state
27
- class EmptyDerivedData implements DerivedData {
28
- getMyFunctions = (): DerivedFunctions => {
29
- return {};
30
- };
31
- getModel = (): AppModel | undefined => {
32
- return undefined;
33
- };
34
- }
35
-
36
- //This data will be used at the processor stage
37
- class MyDerivedData implements DerivedData {
38
- private dataModel: AppModel;
39
- private pwmCalculator: PwmCalculator;
40
- private cValidator: PatternValidator = getCFunctionValidator();
41
-
42
- constructor(dataModel: AppModel) {
43
- this.dataModel = dataModel;
44
- }
45
-
46
- private getPwmCalculator = (): PwmCalculator => {
47
- if (!this.pwmCalculator) {
48
- this.pwmCalculator = new PwmCalculator(
49
- this.getTimerPrValue(),
50
- this.getTimerPrescaler(),
51
- this.dataModel.getImportValue("osc_clocks")?.fosc ?? 0,
52
- Number(this.dataModel.getComponentValue("dutyCycle")),
53
- );
54
- }
55
- return this.pwmCalculator;
56
- };
57
-
58
- getMyFunctions = (): DerivedFunctions => {
59
- return {
60
- overrideDefaultValues: this.overrideDefaultValues,
61
- overrideOptions: this.overrideDefaultOptions,
62
- moduleName: (): string | undefined => this.dataModel.getHardware()?.getName(),
63
- pinData: this.getMyPinData,
64
- alerts: this.getMyAlerts,
65
-
66
- pwm_general_parameters_payload: this.pwm_general_parameters_payload,
67
- initializer_system_results: this.initializer_system_results,
68
-
69
- dutyCycleValidator: this.dutyCycleValidator,
70
-
71
- componentName: this.componentName,
72
- pwmdcValue: (): number => this.getPwmCalculator().getCCPRValue(),
73
- pwmPeriod: (): number => this.getPwmCalculator().getPwmPeriod(),
74
- pwmFrequency: (): number => this.getPwmCalculator().getPwmFrequency(),
75
- pwmResolution: (): number => this.getPwmCalculator().getPwmResolution(),
76
-
77
- ctselCcptmrs1: this.ctselTimerSetting,
78
- ctselCcptmrs: this.ctselTimerSetting,
79
- ctselPwmtmrs: this.ctselTimerSetting,
80
- pwmdchPwmdch: (): number =>
81
- Number(this.dataModel.getComponentValue("pwmdcValue")) >> 2,
82
- pwmdclPwmdcl: (): number =>
83
- Number(this.dataModel.getComponentValue("pwmdcValue")) & 3,
84
-
85
- templateData: (): any => getGeneratorModel(this.dataModel),
86
- getHelpUrl: this.getSdlHelpOverride,
87
- filterImports: this.filterImports,
88
- getPinsLogic: getPinsLogic,
89
- importName: this.friendlyImportName,
90
- componentNameValidator: this.componentNameValidator,
91
- getCustomUiErrors: this.getCustomUiErrors,
92
- pin_standard_args: this.getPinstandardArgs,
93
- };
94
- };
95
-
96
- private friendlyImportName = (importKey: string): string => {
97
- if (importKey === "scf_pic8_pwm_v2") return "PWM Hardware";
98
- if (importKey === "osc_clocks") return "Oscillator Clock";
99
- if (importKey === "initializer_system") return "system.c Initialize()";
100
- if (importKey === "pin_standard") return "Pins";
101
- return importKey;
102
- };
103
-
104
- private overrideDefaultValues = (componentName: string): any => {
105
- switch (componentName) {
106
- case "componentName":
107
- return this.dataModel.getHardware()?.getName();
108
- default:
109
- return undefined;
110
- }
111
- };
112
-
113
- private componentNameValidator = (): any => {
114
- return {
115
- pattern: this.cValidator.getRjsfValidation().pattern,
116
- };
117
- };
118
-
119
- private getCustomUiErrors = (componentName: string): Error[] | undefined => {
120
- switch (componentName) {
121
- case "componentName":
122
- return [
123
- {
124
- name: "pattern",
125
- message: this.cValidator.getCustomErrorMessage(),
126
- },
127
- ];
128
- default:
129
- return undefined;
130
- }
131
- };
132
-
133
- private readonly getPinstandardArgs = (): intf_args => {
134
- const args: intf_args = {
135
- queryAdapters: ["pps", "apfcon"],
136
- queryAdapterMap: {
137
- [QueryAdapterKey.ALLPINS]: "^PWM[0-9]{0,1}$",
138
- },
139
- };
140
-
141
- return args;
142
- };
143
-
144
- private overrideDefaultOptions = (componentName: string): any[] => {
145
- switch (componentName) {
146
- case "timerSelection": {
147
- const result: any[] = [];
148
- const CCPTMRSREG =
149
- this.dataModel.getPeripheralDescription()?.registers?.CCPTMRS1 ??
150
- this.dataModel.getPeripheralDescription()?.registers?.CCPTMRS;
151
- const PWMTMRSREG = this.dataModel.getPeripheralDescription()?.registers
152
- ?.PWMTMRS;
153
- if (CCPTMRSREG) {
154
- const CTSELSETT = CCPTMRSREG.settings?.CTSEL;
155
- for (const eachoptn of CTSELSETT?.options ?? []) {
156
- const timeroptnregex = /^pwm\d+timer(\d)$/i;
157
- const optnmatch = eachoptn.alias.match(timeroptnregex);
158
- const correctOptnName =
159
- (optnmatch?.length ?? 0) > 1 ? "TMR" + optnmatch?.[1] : "";
160
- result.push(correctOptnName);
161
- }
162
- }
163
- if (PWMTMRSREG) {
164
- const CTSELSETT = PWMTMRSREG.settings?.CTSEL;
165
- for (const eachoptn of CTSELSETT?.options ?? []) {
166
- const timeroptnregex = /^pwm\d+timer(\d)$/i;
167
- const optnmatch = eachoptn.alias.match(timeroptnregex);
168
- const correctOptnName =
169
- (optnmatch?.length ?? 0) > 1 ? "TMR" + optnmatch?.[1] : "";
170
- result.push(correctOptnName);
171
- }
172
- }
173
- if (!CCPTMRSREG && !PWMTMRSREG) {
174
- result.push("TMR2");
175
- }
176
- return result;
177
- }
178
- default:
179
- return [] /*for other fields - undefined as take options from moduleconfig.json*/;
180
- }
181
- };
182
-
183
- public getModel = (): AppModel => {
184
- return this.dataModel;
185
- };
186
-
187
- private getMyPinData = (): any => {
188
- return {};
189
- };
190
-
191
- private filterImports = (imports: MyImports): MyImports => {
192
- let filteredImports: MyImports = imports;
193
- const ImportKeys = ["Timer"];
194
-
195
- ImportKeys.forEach((importKey) => {
196
- filteredImports = this.getModel().filterImportBySetting(
197
- filteredImports,
198
- importKey,
199
- (option: Processor.Option<any>): any => {
200
- if (option.payload !== undefined) {
201
- const rstSource =
202
- this.dataModel.getComponentValue("timerSelection") ??
203
- "disabled";
204
- const regexpNumber = /\d/;
205
- const inst = rstSource.match(regexpNumber);
206
- if (rstSource.indexOf("TMR") !== -1) {
207
- return option.payload.moduleName === "TMR" + inst;
208
- }
209
- }
210
- },
211
- ) as MyImports;
212
- });
213
- return filteredImports;
214
- };
215
-
216
- private getMyAlerts = (): Processor.Alert[] => {
217
- const alerts: Processor.Alert[] = [];
218
-
219
- const timerSelection: string =
220
- this.dataModel.getComponentValue("timerSelection") ?? "";
221
- const groupmatch = timerSelection.match(/^TMR([0-9])$/) ?? "";
222
- const timersuffix = groupmatch?.length > 1 ? groupmatch[1] : "";
223
- if (
224
- this.dataModel.getAssignedImport("Timer") == undefined ||
225
- this.dataModel.getAssignedImport("Timer")?.handle?.label !==
226
- "TMR" + timersuffix
227
- ) {
228
- alerts.push({
229
- text: `Please select ${timerSelection} as the Timer Dependency.`,
230
- type: Processor.AlertTypes.Warning,
231
- });
232
- } else {
233
- alerts.push({
234
- text: `${this.dataModel.getName()} uses ${timerSelection}.`,
235
- type: Processor.AlertTypes.Hint,
236
- });
237
- alerts.push({
238
- text: `Postscaler setting in ${timerSelection} does not affect the calculated parameters in PWM module.`,
239
- type: Processor.AlertTypes.Hint,
240
- });
241
- if (
242
- Number(this.dataModel.getComponentValue("pwmdcValue")) / 4 >
243
- this.getTimerPrValue()
244
- ) {
245
- alerts.push({
246
- text: `The value for Duty Cycle percentage is crossing 100 because the period value set in tmr is greater than the dutycycle value set in PWM. Set the duty cycle to be less than 100 percent.`,
247
- type: Processor.AlertTypes.Warning,
248
- });
249
- }
250
- }
251
-
252
- return alerts;
253
- };
254
-
255
- private getSdlHelpOverride = (
256
- componentName: MyComponentNames,
257
- helpUrl: string,
258
- ): string => {
259
- if (componentName === "timerSelection") {
260
- if (this.getModel().getPeripheralDescription()?.registers?.CCPTMRS1) {
261
- componentName = "ctselCcptmrs1";
262
- } else if (this.getModel().getPeripheralDescription()?.registers?.CCPTMRS) {
263
- componentName = "ctselCcptmrs";
264
- } else if (this.getModel().getPeripheralDescription()?.registers?.PWMTMRS) {
265
- componentName = "ctselPwmtmrs";
266
- }
267
- } else if (componentName === "dutyCycle" || componentName === "pwmdcValue") {
268
- helpUrl = helpUrl?.replace(
269
- "${instance}",
270
- this.getModel().getHardware()?.getName() ?? "",
271
- );
272
- }
273
-
274
- return getAutoSdlHelp(this.getModel() as any, componentName, helpUrl);
275
- };
276
-
277
- private pwm_general_parameters_payload = (): pwm_general.ProcessedPayload => {
278
- return {
279
- interfaceApi: pwm_general.Interface.createFirmwareApi(
280
- this.dataModel.getComponentValue("componentName") ?? "",
281
- getHeaderFiles(this.dataModel),
282
- ),
283
- customName: this.dataModel.getComponentValue("componentName"),
284
- modulename: this.dataModel.getName(),
285
- isdriverisr: false,
286
- ispwmi_enabled: false,
287
- ispwmpi_enabled: false,
288
- moduleName: this.dataModel.getName(),
289
- };
290
- };
291
-
292
- private initializer_system_results = (): initializer_system.Results => {
293
- return {
294
- initializer: {
295
- name: this.dataModel.getComponentValue("componentName") + "_Initialize",
296
- header: getHeaderFiles(this.dataModel)[0],
297
- },
298
- };
299
- };
300
-
301
- private dutyCycleValidator = (): any => {
302
- return {
303
- minimum: 0,
304
- maximum: 100,
305
- };
306
- };
307
-
308
- private componentName = (): string | undefined => {
309
- const arg = this.getArg("pwm_general", pwm_general.Interface);
310
- if (arg) {
311
- const pwmArg: pwm_general.Arguments = arg;
312
- return pwmArg.customName;
313
- }
314
- return undefined;
315
- };
316
-
317
- private ctselTimerSetting = (): string | undefined => {
318
- const timerSelection: string =
319
- this.dataModel.getComponentValue("timerSelection") ?? "";
320
- const groupmatch = timerSelection.match(/^TMR([0-9])$/) ?? "";
321
- if (groupmatch.length > 1) {
322
- const timersuffix = groupmatch?.length > 1 ? groupmatch[1] : "";
323
- return this.dataModel.getHardware()?.getName() + "timer" + timersuffix;
324
- } else {
325
- return undefined;
326
- }
327
- };
328
-
329
- private getTimerPrValue = (): number => {
330
- return this.dataModel.getImportValue("Timer")?.periodRegisterValue ?? 255;
331
- };
332
-
333
- private getTimerPrescaler = (): number => {
334
- return this.dataModel.getImportValue("Timer")?.prescaleValue ?? 1;
335
- };
336
-
337
- private getArg = (key: MyExportNames, id: Interface): Arguments => {
338
- const exportInterface = this.dataModel
339
- .getExportInterfaces()
340
- .getInterface(key, id.getInterfaceId());
341
- if (exportInterface?.args) {
342
- // choose the first requester for now
343
- return exportInterface.args[Object.keys(exportInterface.args)[0]];
344
- }
345
- };
346
- }
@@ -1,39 +0,0 @@
1
- //import { getModel } from "../generated_module/src/App/AppModel";
2
- import { AppModel } from "../generated_module/src/types/AutoModuleTypes";
3
- import { getModel, mockState } from "../generated_module/tests/AppModel.test";
4
- import { mockAssignedModule } from "../generated_module/tests/processor.test";
5
- import * as MyDerivedData from "./DerivedData";
6
- import * as GenertorModel from "./GeneratorModel";
7
-
8
- describe("GeneratorModel", () => {
9
- describe("getGeneratorModel", () => {
10
- test("componentName is undefined", () => {
11
- const mockModule = mockAssignedModule(mockState());
12
- const model = getModel(mockModule, MyDerivedData.getDerivedData as any);
13
- if (model) {
14
- model.getComponentValue = (comp_name: string): any => {
15
- const compData = {
16
- componentName: undefined,
17
- };
18
- return compData[comp_name];
19
- };
20
- expect(
21
- GenertorModel.getGeneratorModel(model as any).customName,
22
- ).toBeUndefined();
23
- }
24
- });
25
-
26
- test("PeripheralDescription is undefined", () => {
27
- const mockModule = mockAssignedModule(mockState());
28
- const model = getModel(mockModule, MyDerivedData.getDerivedData as any);
29
- if (model) {
30
- model.getPeripheralDescription = (): any => {
31
- return undefined;
32
- };
33
- expect(
34
- GenertorModel.getGeneratorModel(model as AppModel).hardwareSettings,
35
- ).toBeDefined;
36
- }
37
- });
38
- });
39
- });
@@ -1,65 +0,0 @@
1
- import { AppModel } from "../generated_module/src/types/AutoModuleTypes";
2
- import * as pwm_general from "./interfaces/pwm_general_parameters";
3
- import * as InterfaceTypes from "@microchip/scf-interface";
4
- import { getOptionValueByName } from "../generated_module/src/autoModule/AutoModuleHelpers";
5
- import { getTemplateSettings } from "../generated_module/src/autoModule/AutoModuleTemplates";
6
- import { values } from "../generated_module/src/Utils";
7
-
8
- export const getGeneratorModel = (model: AppModel): any => {
9
- if (!model.getHardware()) return {};
10
-
11
- const pwmInterface = pwm_general.Interface.createFirmwareApi(
12
- model.getComponentValue("componentName") ?? "",
13
- getHeaderFiles(model),
14
- );
15
-
16
- const templateSettings = getTemplateSettings(model);
17
-
18
- const registerValues = templateSettings?.registers;
19
- const initRegisters: any[] = values(registerValues ?? {});
20
-
21
- const ctsel = model.getPeripheralDescription()?.registers?.CCPTMRS1?.settings?.CTSEL;
22
- const CTSELvalue = ctsel
23
- ? getOptionValueByName(ctsel, model.getDerivedFunction("ctselCcptmrs1"))
24
- : 1;
25
-
26
- return {
27
- moduleNameLowerCase: model.getName()?.toLowerCase(),
28
- moduleNameUpperCase: model.getName()?.toUpperCase(),
29
- header: pwmInterface.headerFiles?.[0],
30
- api: pwmInterface.api,
31
- simpleApi: pwmInterface.simpleApi,
32
-
33
- productName: "",
34
- productVersion: "",
35
- selectedDevice: "PIC18F47Q10",
36
- compiler: "XC8 v2.20",
37
- tool: "MPLABX v5.40",
38
-
39
- //From System Manager
40
- useWatchdog: model.getImportValue("wdtEnable") ?? false, //TODO
41
-
42
- //Registers and Settings
43
- initRegisters: initRegisters,
44
- // PWMDCH: templateSettings?.registers?.PWMDCH.name ?? "",
45
- // PWMDCL: templateSettings?.registers?.PWMDCL?.name ?? "",
46
- CCPTMRSregname: templateSettings?.registers?.CCPTMRS1?.name ?? "",
47
- CTSELsettingname:
48
- templateSettings?.registers?.CCPTMRS1?.settings?.CTSEL.name ?? "",
49
- CTSELvalue: CTSELvalue,
50
- timerselpresence:
51
- (ctsel?.options?.length ?? 0) > 0 ? "timerselpresent" : "timerselabsent",
52
-
53
- pwmdcValue: model.getComponentValue("pwmdcValue"),
54
- ...registerValues,
55
- };
56
- };
57
-
58
- export const getHeaderFiles = (model: AppModel): InterfaceTypes.HeaderFile[] => {
59
- return [
60
- {
61
- name: model.getName().toLowerCase() + ".h",
62
- path: "pwm/",
63
- },
64
- ];
65
- };