@mchp-mcc/scf-pic8-pwm-v2 4.2.4 → 4.2.6

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.
@@ -11,6 +11,9 @@ import { Interface, Arguments } from "@microchip/scf-interface";
11
11
  import { getGeneratorModel, getHeaderFiles } from "./GeneratorModel";
12
12
  import { MyComponentNames, MyExportNames } from "../generated_module/src/types";
13
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";
14
17
 
15
18
  export const getDerivedData = (dataModel: AppModel): DerivedData => {
16
19
  if (dataModel) {
@@ -33,6 +36,7 @@ class EmptyDerivedData implements DerivedData {
33
36
  class MyDerivedData implements DerivedData {
34
37
  private dataModel: AppModel;
35
38
  private pwmCalculator: PwmCalculator;
39
+ private cValidator: PatternValidator = getCFunctionValidator();
36
40
 
37
41
  constructor(dataModel: AppModel) {
38
42
  this.dataModel = dataModel;
@@ -69,7 +73,8 @@ class MyDerivedData implements DerivedData {
69
73
  pwmFrequency: (): number => this.getPwmCalculator().getPwmFrequency(),
70
74
  pwmResolution: (): number => this.getPwmCalculator().getPwmResolution(),
71
75
 
72
- ctselCcptmrs1: this.ctselCcptmrs1,
76
+ ctselCcptmrs1: this.ctselTimerSetting,
77
+ ctselPwmtmrs: this.ctselTimerSetting,
73
78
  pwmdchPwmdch: (): number =>
74
79
  Number(this.dataModel.getComponentValue("pwmdcValue")) >> 2,
75
80
  pwmdclPwmdcl: (): number =>
@@ -77,9 +82,22 @@ class MyDerivedData implements DerivedData {
77
82
 
78
83
  templateData: (): any => getGeneratorModel(this.dataModel),
79
84
  getHelpUrl: this.getSdlHelpOverride,
85
+ filterImports: this.filterImports,
86
+ getPinsLogic: getPinsLogic,
87
+ importName: this.friendlyImportName,
88
+ componentNameValidator: this.componentNameValidator,
89
+ getCustomUiErrors: this.getCustomUiErrors,
80
90
  };
81
91
  };
82
92
 
93
+ private friendlyImportName = (importKey: string): string => {
94
+ if (importKey === "scf_pic8_pwm_v2") return "PWM Hardware";
95
+ if (importKey === "osc_clocks") return "Oscillator Clock";
96
+ if (importKey === "initializer_system") return "system.c Initialize()";
97
+ if (importKey === "pin_standard") return "Pins";
98
+ return importKey;
99
+ };
100
+
83
101
  private overrideDefaultValues = (componentName: string): any => {
84
102
  switch (componentName) {
85
103
  case "componentName":
@@ -89,12 +107,34 @@ class MyDerivedData implements DerivedData {
89
107
  }
90
108
  };
91
109
 
110
+ private componentNameValidator = (): any => {
111
+ return {
112
+ pattern: this.cValidator.getRjsfValidation().pattern,
113
+ };
114
+ };
115
+
116
+ private getCustomUiErrors = (componentName: string): Error[] | undefined => {
117
+ switch (componentName) {
118
+ case "componentName":
119
+ return [
120
+ {
121
+ name: "pattern",
122
+ message: this.cValidator.getCustomErrorMessage(),
123
+ },
124
+ ];
125
+ default:
126
+ return undefined;
127
+ }
128
+ };
129
+
92
130
  private overrideDefaultOptions = (componentName: string): any[] => {
93
131
  switch (componentName) {
94
132
  case "timerSelection": {
95
133
  const result: any[] = [];
96
134
  const CCPTMRSREG = this.dataModel.getPeripheralDescription()?.registers
97
135
  ?.CCPTMRS1;
136
+ const PWMTMRSREG = this.dataModel.getPeripheralDescription()?.registers
137
+ ?.PWMTMRS;
98
138
  if (CCPTMRSREG) {
99
139
  const CTSELSETT = CCPTMRSREG.settings?.CTSEL;
100
140
  for (const eachoptn of CTSELSETT?.options ?? []) {
@@ -104,7 +144,18 @@ class MyDerivedData implements DerivedData {
104
144
  (optnmatch?.length ?? 0) > 1 ? "TMR" + optnmatch?.[1] : "";
105
145
  result.push(correctOptnName);
106
146
  }
107
- } else {
147
+ }
148
+ if (PWMTMRSREG) {
149
+ const CTSELSETT = PWMTMRSREG.settings?.CTSEL;
150
+ for (const eachoptn of CTSELSETT?.options ?? []) {
151
+ const timeroptnregex = /^pwm[0-9]timer([0-9])$/i;
152
+ const optnmatch = eachoptn.alias.match(timeroptnregex);
153
+ const correctOptnName =
154
+ (optnmatch?.length ?? 0) > 1 ? "TMR" + optnmatch?.[1] : "";
155
+ result.push(correctOptnName);
156
+ }
157
+ }
158
+ if (!CCPTMRSREG && !PWMTMRSREG) {
108
159
  result.push("TMR2");
109
160
  }
110
161
  return result;
@@ -122,6 +173,31 @@ class MyDerivedData implements DerivedData {
122
173
  return {};
123
174
  };
124
175
 
176
+ private filterImports = (imports: MyImports): MyImports => {
177
+ let filteredImports: MyImports = imports;
178
+ const ImportKeys = ["Timer"];
179
+
180
+ ImportKeys.forEach((importKey) => {
181
+ filteredImports = this.getModel().filterImportBySetting(
182
+ filteredImports,
183
+ importKey,
184
+ (option: Processor.Option<any>): any => {
185
+ if (option.payload !== undefined) {
186
+ const rstSource =
187
+ this.dataModel.getComponentValue("timerSelection") ??
188
+ "disabled";
189
+ const regexpNumber = /\d/;
190
+ const inst = rstSource.match(regexpNumber);
191
+ if (rstSource.indexOf("TMR") !== -1) {
192
+ return option.payload.moduleName === "TMR" + inst;
193
+ }
194
+ }
195
+ },
196
+ ) as MyImports;
197
+ });
198
+ return filteredImports;
199
+ };
200
+
125
201
  private getMyAlerts = (): Processor.Alert[] => {
126
202
  const alerts: Processor.Alert[] = [];
127
203
 
@@ -170,6 +246,8 @@ class MyDerivedData implements DerivedData {
170
246
  componentName = "ctselCcptmrs1";
171
247
  } else if (this.getModel().getPeripheralDescription()?.registers?.CCPTMRS) {
172
248
  componentName = "ctselCcptmrs";
249
+ } else if (this.getModel().getPeripheralDescription()?.registers?.PWMTMRS) {
250
+ componentName = "ctselPwmtmrs";
173
251
  }
174
252
  } else if (componentName === "dutyCycle" || componentName === "pwmdcValue") {
175
253
  helpUrl = helpUrl?.replace(
@@ -221,14 +299,14 @@ class MyDerivedData implements DerivedData {
221
299
  return undefined;
222
300
  };
223
301
 
224
- private ctselCcptmrs1 = (): string | undefined => {
302
+ private ctselTimerSetting = (): string | undefined => {
225
303
  switch (this.dataModel.getComponentValue("timerSelection")) {
226
304
  case "TMR2":
227
- return this.dataModel.getHardware()?.getName() + "TMR2";
305
+ return this.dataModel.getHardware()?.getName() + "timer2";
228
306
  case "TMR4":
229
- return this.dataModel.getHardware()?.getName() + "TMR4";
307
+ return this.dataModel.getHardware()?.getName() + "timer4";
230
308
  case "TMR6":
231
- return this.dataModel.getHardware()?.getName() + "TMR6";
309
+ return this.dataModel.getHardware()?.getName() + "timer6";
232
310
  default:
233
311
  return undefined;
234
312
  }
@@ -0,0 +1,69 @@
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);
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);
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
+ // describe("convertToTemplate", () => {
40
+ // test("Hardware is undefined", () => {
41
+ // const mockModule = mockAssignedModule(mockState());
42
+ // const model = getModel(mockModule, MyDerivedData.getDerivedData);
43
+
44
+ // if (model) {
45
+ // model.getHardware = (): any => {
46
+ // return undefined;
47
+ // };
48
+ // const result1 = GenertorModel.convertToTemplate(
49
+ // model as AppModel,
50
+ // "positive",
51
+ // [],
52
+ // );
53
+ // expect(result1.length).toBe(0);
54
+ // const result2 = GenertorModel.convertToTemplate(
55
+ // model as AppModel,
56
+ // "negative",
57
+ // [],
58
+ // );
59
+ // expect(result2.length).toBe(0);
60
+ // const result3 = GenertorModel.convertToTemplate(
61
+ // model as AppModel,
62
+ // "none",
63
+ // [],
64
+ // );
65
+ // expect(result3.length).toBe(0);
66
+ // }
67
+ // });
68
+ // });
69
+ });
@@ -0,0 +1,155 @@
1
+ import { behaviour, direction, pin_row } from "@microchip/pin-standard";
2
+ //import { getModel } from "../generated_module/src/App/AppModel";
3
+ import { MyState } from "../generated_module/src/types/AutoModuleTypes";
4
+ import { getModel, mockState } from "../generated_module/tests/AppModel.test";
5
+ import { mockAssignedModule } from "../generated_module/tests/processor.test";
6
+ import { getDerivedData } from "./DerivedData";
7
+ import { getRowData } from "./PinsLogic";
8
+
9
+ // export const getMockState = (ccpMode: string | undefined): MyState => {
10
+ // return {
11
+ // main: {
12
+ // software: {
13
+ // componentName: "CCP1",
14
+ // scf_pic8_ccp_v1: "CCP1",
15
+ // },
16
+ // interrupt: {
17
+ // interruptEnable: false,
18
+ // },
19
+ // hardware: {
20
+ // ccpMode: ccpMode,
21
+ // captureMode: "Every edge",
22
+ // compareMode: "Toggle_cleartmr",
23
+ // dutyCycle: 0,
24
+ // ccprValue: "0",
25
+ // pwmPeriod: "0",
26
+ // pwmFrequency: "0",
27
+ // pwmResolution: "0",
28
+ // ccpTimer: "Timer 1",
29
+ // pwmTimer: "Timer 2",
30
+ // enCcpcon: true,
31
+ // fmtCcpcon: "right_aligned",
32
+ // ctsCcpcap: "CCP1 pin",
33
+ // },
34
+ // },
35
+ // };
36
+ // };
37
+
38
+ export const getMockState = (): MyState => {
39
+ return {
40
+ main: {
41
+ software: {
42
+ componentName: "PWM4",
43
+ tmr2Dependency: "TMR2",
44
+ },
45
+ hardware: {
46
+ timerSelection: "TMR2",
47
+ dutyCycle: 50,
48
+ pwmdcValue: 511,
49
+ pwmPeriod: 0.001024,
50
+ pwmFrequency: 976.56,
51
+ pwmResolution: 10,
52
+ pwmpolPwmcon: "active_hi",
53
+ pwmenPwmcon: true,
54
+ },
55
+ },
56
+ };
57
+ };
58
+
59
+ describe("PinsLogic --> Test Cases ", () => {
60
+ describe("getRowData() test case ", () => {
61
+ const mockModule = mockAssignedModule(getMockState());
62
+ const model = getModel(mockModule, getDerivedData);
63
+
64
+ const pwmPpsData: pin_row = {
65
+ name: "pwmPps",
66
+ module: "PWM6",
67
+ function: "PWM6OUT",
68
+ direction: direction.output,
69
+ filter: {
70
+ module: "PWM6",
71
+ aliasReEx: "PWM[0-9]",
72
+ },
73
+ behaviour: behaviour.PPS,
74
+ };
75
+ it("Test for pwmPpsData pin data: PWM mode", () => {
76
+ if (model) {
77
+ expect(getRowData(model as any, pwmPpsData)).toMatchObject(pwmPpsData);
78
+ expect(getRowData(model as any, pwmPpsData)?.actions).toBeUndefined();
79
+ } else {
80
+ throw "Model not configured for testcase";
81
+ }
82
+ });
83
+ });
84
+ // describe("getRowData() test case : CCP in no mode", () => {
85
+ // const mockModule = mockAssignedModule(getMockState(""));
86
+ // const model = getModel(mockModule, getDerivedData);
87
+
88
+ // const ccpPpsData: pin_row = {
89
+ // name: "ccpPps",
90
+ // module: "CCP3",
91
+ // function: "CCP3",
92
+ // direction: direction.output,
93
+ // filter: {
94
+ // module: "CCP3",
95
+ // aliasReEx: "CCP[0-9]",
96
+ // },
97
+ // behaviour: behaviour.PPS,
98
+ // };
99
+ // it("Test for ccpPpsData pin data: no mode", () => {
100
+ // if (model) {
101
+ // expect(getRowData(model, ccpPpsData)).toMatchObject(ccpPpsData);
102
+ // expect(getRowData(model, ccpPpsData)?.actions).toBeUndefined();
103
+ // } else {
104
+ // throw "Model not configured for testcase";
105
+ // }
106
+ // });
107
+ // });
108
+ describe("getRowData() test case : invalid", () => {
109
+ const mockModule = mockAssignedModule(mockState());
110
+ const model = getModel(mockModule, getDerivedData);
111
+
112
+ const pwmPpsData: pin_row = {
113
+ name: "dummy",
114
+ module: "PWM6",
115
+ function: "PWM6OUT",
116
+ direction: direction.output,
117
+ filter: {
118
+ module: "PWM6",
119
+ aliasReEx: "PWM[0-9]",
120
+ },
121
+ behaviour: behaviour.PPS,
122
+ };
123
+ it("Test for pwmPpsData pin data: invalid", () => {
124
+ if (model) {
125
+ expect(getRowData(model as any, pwmPpsData)).toMatchObject(pwmPpsData);
126
+ expect(getRowData(model as any, pwmPpsData)?.actions).toBeUndefined();
127
+ } else {
128
+ throw "Model not configured for testcase";
129
+ }
130
+ });
131
+ it("Test for ccpPpsData pin data, undefined registers", () => {
132
+ let mockAssignedMod = mockAssignedModule(mockState());
133
+ mockAssignedMod = {
134
+ ...(mockAssignedMod ?? {}),
135
+ imports: {
136
+ ...(mockAssignedMod?.imports ?? {}),
137
+ scf_pic8_pwm_v2: {
138
+ ...(mockAssignedMod?.imports?.scf_pic8_pwm_v2 ?? {}),
139
+ handle: undefined,
140
+ payload: undefined,
141
+ },
142
+ },
143
+ };
144
+ const mockModel = getModel(mockAssignedMod, getDerivedData);
145
+ if (mockModel) {
146
+ expect(getRowData(mockModel as any, pwmPpsData)).toMatchObject(
147
+ pwmPpsData,
148
+ ); // check if the same data is returned
149
+ expect(getRowData(mockModel as any, pwmPpsData)?.actions).toBeUndefined();
150
+ } else {
151
+ throw "Model not configured for testcase";
152
+ }
153
+ });
154
+ });
155
+ });
@@ -55,3 +55,59 @@ describe("Pwm Calculations: PR = 0x4d, Prescaler = 0x5, fosc = 1M, DC = 60", ()
55
55
  expect(pwmCalculator2.getActualPulseWidth()).toBe(0.005952);
56
56
  });
57
57
  });
58
+
59
+ describe("Pwm Calculations: PR = 0x0, Prescaler = 0x0, fosc = 1M, DC = 0", () => {
60
+ const pwmCalculator2 = new PwmCalculator(0x0, 0, 1000000, 0);
61
+
62
+ test("getPwmPeriod", () => {
63
+ expect(pwmCalculator2.getPwmPeriod()).toBe(0);
64
+ });
65
+
66
+ test("getPwmFrequency", () => {
67
+ expect(pwmCalculator2.getPwmFrequency()).toBe(0);
68
+ });
69
+
70
+ test("getPwmResolution", () => {
71
+ expect(pwmCalculator2.getPwmResolution()).toBe(2);
72
+ });
73
+
74
+ test("getCCPRValue", () => {
75
+ expect(pwmCalculator2.getCCPRValue()).toBe(0);
76
+ });
77
+
78
+ test("getActualDutyCycle", () => {
79
+ expect(pwmCalculator2.getActualDutyCycle()).toBe(0);
80
+ });
81
+
82
+ test("getActualPulseWidth", () => {
83
+ expect(pwmCalculator2.getActualPulseWidth()).toBe(0);
84
+ });
85
+ });
86
+
87
+ describe("Pwm Calculations: PR = 0x0, Prescaler = 0x0, fosc = 0, DC = 0", () => {
88
+ const pwmCalculator2 = new PwmCalculator(0x0, 0, 0, 0);
89
+
90
+ test("getPwmPeriod", () => {
91
+ expect(pwmCalculator2.getPwmPeriod()).toBe(0);
92
+ });
93
+
94
+ test("getPwmFrequency", () => {
95
+ expect(pwmCalculator2.getPwmFrequency()).toBe(0);
96
+ });
97
+
98
+ test("getPwmResolution", () => {
99
+ expect(pwmCalculator2.getPwmResolution()).toBe(2);
100
+ });
101
+
102
+ test("getCCPRValue", () => {
103
+ expect(pwmCalculator2.getCCPRValue()).toBe(0);
104
+ });
105
+
106
+ test("getActualDutyCycle", () => {
107
+ expect(pwmCalculator2.getActualDutyCycle()).toBe(0);
108
+ });
109
+
110
+ test("getActualPulseWidth", () => {
111
+ expect(pwmCalculator2.getActualPulseWidth()).toBe(0);
112
+ });
113
+ });
@@ -0,0 +1,40 @@
1
+ import { ProcessedExportInterface, Interface } from "./pwm_general_parameters";
2
+
3
+ describe("The pwm_general_parameters interface", () => {
4
+ it("doesn't explode", () => {
5
+ expect(Interface.getInterfaceId()).toBeDefined();
6
+ expect(Interface.createPrototypeImport()).toBeDefined();
7
+ expect(Interface.createPrototypeExport()).toBeDefined();
8
+ expect(
9
+ Interface.createFirmwareApi("MyModule", [
10
+ { name: "mymodule.h", path: "include/" },
11
+ ]),
12
+ ).toBeDefined();
13
+ expect(Interface.createMock()).toBeDefined();
14
+ });
15
+
16
+ it("Checks Interface ID", () => {
17
+ expect(Interface.getInterfaceId().name).toBe("pwm_general_parameters");
18
+ expect(Interface.getInterfaceId().version).toBe("0.1.0");
19
+ });
20
+
21
+ it("Create's api with name, headers, or custom API undefined", () => {
22
+ expect(Interface.createFirmwareApi("", [{ name: "", path: "" }])).toBeDefined();
23
+ });
24
+ });
25
+
26
+ export const createMock = (): ProcessedExportInterface => {
27
+ return {
28
+ interfaceId: Interface.getInterfaceId(),
29
+ payload: {
30
+ interfaceApi: Interface.createFirmwareApi("MyModule", [
31
+ { name: "mymodule.h", path: "include/" },
32
+ ]),
33
+ },
34
+ args: {
35
+ requestId: {
36
+ customName: "MyModule",
37
+ },
38
+ },
39
+ };
40
+ };
@@ -30,6 +30,10 @@
30
30
  "main": "Easy View",
31
31
  "register": "Register Initialization"
32
32
  },
33
+ "help": {
34
+ "url": "v2/keyword-lookup?keyword=scf-pic8-pwm-v2&redirect=true",
35
+ "tooltip": "Click here to open documentation."
36
+ },
33
37
  "analytics": {
34
38
  "logAlwaysComps": [
35
39
  "pwmenPwmcon",
@@ -132,7 +136,19 @@
132
136
  "tabs": [
133
137
  "main"
134
138
  ],
135
- "category": "software"
139
+ "category": "software",
140
+ "validation": true
141
+ },
142
+ "tmr2Dependency": {
143
+ "name": "tmr2Dependency",
144
+ "description": "Timer Dependency Selector",
145
+ "category": "import",
146
+ "type": "ComboBox",
147
+ "group": "software",
148
+ "tabs": [
149
+ "main"
150
+ ],
151
+ "importId": "Timer"
136
152
  },
137
153
  "timerSelection": {
138
154
  "name": "timerSelection",
@@ -240,6 +256,19 @@
240
256
  "version": "1.0.0"
241
257
  },
242
258
  "registers": {
259
+ "PWMTMRS": [
260
+ {
261
+ "setting": "CTSEL",
262
+ "name": "ctselPwmtmrs",
263
+ "category": "hardware",
264
+ "description": "Insert Description Here",
265
+ "type": "ComboBox",
266
+ "group": "hardware",
267
+ "tabs": [
268
+ "register"
269
+ ]
270
+ }
271
+ ],
243
272
  "CCPTMRS1": [
244
273
  {
245
274
  "setting": "CTSEL",