aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/platforms/SPC5xx/FlexPWM_v1/spc5_flexpwm.h
blob: 5be53d949297c625a820e4ac9401c33c0c617990 (plain)
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
/*
    SPC5 HAL - Copyright (C) 2013 STMicroelectronics

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/

/**
 * @file    FlexPWM_v1/spc5_flexpwm.h
 * @brief   SPC5xx FlexPWM header file.
 *
 * @addtogroup PWM
 * @{
 */

#ifndef _SPC5_FLEXPWM_H_
#define _SPC5_FLEXPWM_H_

/*===========================================================================*/
/* Driver constants.                                                         */
/*===========================================================================*/

/*===========================================================================*/
/* Driver pre-compile time settings.                                         */
/*===========================================================================*/

/*===========================================================================*/
/* Derived constants and error checks.                                       */
/*===========================================================================*/

/*===========================================================================*/
/* Driver data structures and types.                                         */
/*===========================================================================*/

/**
 * @brief   SPC5 FlexPWM registers block.
 * @note    Redefined from the SPC5 headers because the non uniform
 *          declaration of the SubModules registers among the various
 *          sub-families.
 */
struct spc5_flexpwm_submodule {

  union {
    vuint16_t R;
  } CNT; /* Counter Register */

  union {
    vuint16_t R;
  } INIT; /* Initial Count Register */

  union {
    vuint16_t R;
    struct {
      vuint16_t DBGEN :1;
      vuint16_t WAITEN :1;
      vuint16_t INDEP :1;
      vuint16_t PWMA_INIT :1;
      vuint16_t PWMB_INIT :1;
      vuint16_t PWMX_INIT :1;
      vuint16_t INIT_SEL :2;
      vuint16_t FRCEN :1;
      vuint16_t FORCE :1;
      vuint16_t FORCE_SEL :3;
      vuint16_t RELOAD_SEL :1;
      vuint16_t CLK_SEL :2;
    } B;
  } CTRL2; /* Control 2 Register */

  union {
    vuint16_t R;
    struct {
      vuint16_t LDFQ :4;
      vuint16_t HALF :1;
      vuint16_t FULL :1;
      vuint16_t DT :2;
      vuint16_t :1;
      vuint16_t PRSC :3;
      vuint16_t :3;
      vuint16_t DBLEN :1;
    } B;
  } CTRL; /* Control Register */

  union {
    vuint16_t R;
  } VAL[6]; /* Value Register 0->5 */

  union {
    vuint16_t R;
    struct {
      vuint16_t FRACAEN :1;
      vuint16_t :10;
      vuint16_t FRACADLY :5;
    } B;
  } FRACA; /* Fractional Delay Register A */

  union {
    vuint16_t R;
    struct {
      vuint16_t FRACBEN :1;
      vuint16_t :10;
      vuint16_t FRACBDLY :5;
    } B;
  } FRACB; /* Fractional Delay Register B */

  union {
    vuint16_t R;
    struct {
      vuint16_t PWMA_IN :1;
      vuint16_t PWMB_IN :1;
      vuint16_t PWMX_IN :1;
      vuint16_t :2;
      vuint16_t POLA :1;
      vuint16_t POLB :1;
      vuint16_t POLX :1;
      vuint16_t :2;
      vuint16_t PWMAFS :2;
      vuint16_t PWMBFS :2;
      vuint16_t PWMXFS :2;
    } B;
  } OCTRL; /* Output Control Register */

  union {
    vuint16_t R;
    struct {
      vuint16_t :1;
      vuint16_t RUF :1;
      vuint16_t REF :1;
      vuint16_t RF :1;
      vuint16_t CFA1 :1;
      vuint16_t CFA0 :1;
      vuint16_t CFB1 :1;
      vuint16_t CFB0 :1;
      vuint16_t CFX1 :1;
      vuint16_t CFX0 :1;
      vuint16_t CMPF :6;
    } B;
  } STS; /* Status Register */

  union {
    vuint16_t R;
    struct {
      vuint16_t :2;
      vuint16_t REIE :1;
      vuint16_t RIE :1;
      vuint16_t :4;
      vuint16_t CX1IE :1;
      vuint16_t CX0IE :1;
      vuint16_t CMPIE :6;
    } B;
  } INTEN; /* Interrupt Enable Register */

  union {
    vuint16_t R;
    struct {
      vuint16_t :6;
      vuint16_t VALDE :1;
      vuint16_t FAND :1;
      vuint16_t CAPTDE :2;
      vuint16_t CA1DE :1;
      vuint16_t CA0DE :1;
      vuint16_t CB1DE :1;
      vuint16_t CB0DE :1;
      vuint16_t CX1DE :1;
      vuint16_t CX0DE :1;
    } B;
  } DMAEN; /* DMA Enable Register */

  union {
    vuint16_t R;
    struct {
      vuint16_t :10;
      vuint16_t OUT_TRIG_EN :6;
    } B;
  } TCTRL; /* Output Trigger Control Register */

  union {
    vuint16_t R;
    struct {
      vuint16_t :4;
      vuint16_t DISX :4;
      vuint16_t DISB :4;
      vuint16_t DISA :4;
    } B;
  } DISMAP; /* Fault Disable Mapping Register */

  union {
    vuint16_t R;
    struct {
      vuint16_t :5;
      vuint16_t DTCNT0 :11;
    } B;
  } DTCNT0; /* Deadtime Count Register 0 */

  union {
    vuint16_t R;
    struct {
      vuint16_t :5;
      vuint16_t DTCNT1 :11;
    } B;
  } DTCNT1; /* Deadtime Count Register 1 */

  union {
    vuint16_t R;
    struct {
      vuint16_t CA1CNT :3;
      vuint16_t CA0CNT :3;
      vuint16_t CFAWM :2;
      vuint16_t EDGCNTAEN :1;
      vuint16_t INPSELA :1;
      vuint16_t EDGA1 :2;
      vuint16_t EDGA0 :2;
      vuint16_t ONESHOTA :1;
      vuint16_t ARMA :1;
    } B;
  } CAPTCTRLA; /* Capture Control Register A */

  union {
    vuint16_t R;
    struct {
      vuint16_t EDGCNTA :8;
      vuint16_t EDGCMPA :8;
    } B;
  } CAPTCOMPA; /* Capture Compare Register A */

  union {
    vuint16_t R;
    struct {
      vuint16_t CB1CNT :3;
      vuint16_t CB0CNT :3;
      vuint16_t CFBWM :2;
      vuint16_t EDGCNTBEN :1;
      vuint16_t INPSELB :1;
      vuint16_t EDGB1 :2;
      vuint16_t EDGB0 :2;
      vuint16_t ONESHOTB :1;
      vuint16_t ARMB :1;
    } B;
  } CAPTCTRLB; /* Capture Control Register B */

  union {
    vuint16_t R;
    struct {
      vuint16_t EDGCNTB :8;
      vuint16_t EDGCMPB :8;
    } B;
  } CAPTCOMPB; /* Capture Compare Register B */

  union {
    vuint16_t R;
    struct {
      vuint16_t CX1CNT :3;
      vuint16_t CX0CNT :3;
      vuint16_t CFXWM :2;
      vuint16_t EDGCNTX_EN :1;
      vuint16_t INP_SELX :1;
      vuint16_t EDGX1 :2;
      vuint16_t EDGX0 :2;
      vuint16_t ONESHOTX :1;
      vuint16_t ARMX :1;
    } B;
  } CAPTCTRLX; /* Capture Control Register B */

  union {
    vuint16_t R;
    struct {
      vuint16_t EDGCNTX :8;
      vuint16_t EDGCMPX :8;
    } B;
  } CAPTCOMPX; /* Capture Compare Register X */

  union {
    vuint16_t R;
    struct {
      vuint16_t CAPTVAL0 :16;
    } B;
  } CVAL0; /* Capture Value 0 Register */

  union {
    vuint16_t R;
    struct {
      vuint16_t :12;
      vuint16_t CVAL0CYC :4;
    } B;
  } CVAL0C; /* Capture Value 0 Cycle Register */

  union {
    vuint16_t R;
    struct {
      vuint16_t CAPTVAL1 :16;
    } B;
  } CVAL1; /* Capture Value 1 Register */

  union {
    vuint16_t R;
    struct {
      vuint16_t :12;
      vuint16_t CVAL1CYC :4;
    } B;
  } CVAL1C; /* Capture Value 1 Cycle Register */

  union {
    vuint16_t R;
    struct {
      vuint16_t CAPTVAL2 :16;
    } B;
  } CVAL2; /* Capture Value 2 Register */

  union {
    vuint16_t R;
    struct {
      vuint16_t :12;
      vuint16_t CVAL2CYC :4;
    } B;
  } CVAL2C; /* Capture Value 2 Cycle Register */

  union {
    vuint16_t R;
    struct {
      vuint16_t CAPTVAL3 :16;
    } B;
  } CVAL3; /* Capture Value 3 Register */

  union {
    vuint16_t R;
    struct {
      vuint16_t :12;
      vuint16_t CVAL3CYC :4;
    } B;
  } CVAL3C; /* Capture Value 3 Cycle Register */

  union {
    vuint16_t R;
    struct {
      vuint16_t CAPTVAL4 :16;
    } B;
  } CVAL4; /* Capture Value 4 Register */

  union {
    vuint16_t R;
    struct {
      vuint16_t :12;
      vuint16_t CVAL4CYC :4;
    } B;
  } CVAL4C; /* Capture Value 4 Cycle Register */

  union {
    vuint16_t R;
    struct {
      vuint16_t CAPTVAL5 :16;
    } B;
  } CVAL5; /* Capture Value 5 Register */

  union {
    vuint16_t R;
    struct {
      vuint16_t :12;
      vuint16_t CVAL5CYC :4;
    } B;
  } CVAL5C; /* Capture Value 5 Cycle Register */

  uint32_t FLEXPWM_SUB_reserved0; /* (0x04A - 0x050)/4 = 0x01 */

};
/* end of FLEXPWM_SUB_tag */

struct spc5_flexpwm {

  struct spc5_flexpwm_submodule SUB[4];

  union {
    vuint16_t R;
    struct {
      vuint16_t :4;
      vuint16_t PWMA_EN :4;
      vuint16_t PWMB_EN :4;
      vuint16_t PWMX_EN :4;
    } B;
  } OUTEN; /* Output Enable Register */

  union {
    vuint16_t R;
    struct {
      vuint16_t :4;
      vuint16_t MASKA :4;
      vuint16_t MASKB :4;
      vuint16_t MASKX :4;
    } B;
  } MASK; /* Output Mask Register */

  union {
    vuint16_t R;
    struct {
      vuint16_t :8;
      vuint16_t OUTA_3 :1;
      vuint16_t OUTB_3 :1;
      vuint16_t OUTA_2 :1;
      vuint16_t OUTB_2 :1;
      vuint16_t OUTA_1 :1;
      vuint16_t OUTB_1 :1;
      vuint16_t OUTA_0 :1;
      vuint16_t OUTB_0 :1;
    } B;
  } SWCOUT; /* Software Controlled Output Register */

  union {
    vuint16_t R;
    struct {
      vuint16_t SELA_3 :2;
      vuint16_t SELB_3 :2;
      vuint16_t SELA_2 :2;
      vuint16_t SELB_2 :2;
      vuint16_t SELA_1 :2;
      vuint16_t SELB_1 :2;
      vuint16_t SELA_0 :2;
      vuint16_t SELB_0 :2;
    } B;
  } DTSRCSEL; /* Deadtime Source Select Register */

  union {
    vuint16_t R;
    struct {
      vuint16_t IPOL :4;
      vuint16_t RUN :4;
      vuint16_t CLDOK :4;
      vuint16_t LDOK :4;
    } B;
  } MCTRL; /* Master Control Register */

  int16_t FLEXPWM_reserved1;

  union {
    vuint16_t R;
    struct {
      vuint16_t FLVL :4;
      vuint16_t FAUTO :4;
      vuint16_t FSAFE :4;
      vuint16_t FIE :4;
    } B;
  } FCTRL; /* Fault Control Register */

  union {
    vuint16_t R;
    struct {
      vuint16_t :3;
      vuint16_t FTEST :1;
      vuint16_t FFPIN :4;
      vuint16_t :4;
      vuint16_t FFLAG :4;
    } B;
  } FSTS; /* Fault Status Register */

  union {
    vuint16_t R;
    struct {
      vuint16_t :5;
      vuint16_t FILT_CNT :3;
      vuint16_t FILT_PER :8;
    } B;
  } FFILT; /* Fault FilterRegister */

};

/*===========================================================================*/
/* Driver macros.                                                            */
/*===========================================================================*/

/**
 * @name    FlexPWM units references
 * @{
 */
#if SPC5_HAS_FLEXPWM0 || defined(__DOXYGEN__)
#define SPC5_FLEXPWM_0      (*(volatile struct spc5_flexpwm *)0xFFE24000UL)
#endif

#if SPC5_HAS_FLEXPWM1 || defined(__DOXYGEN__)
#define SPC5_FLEXPWM_1      (*(volatile struct spc5_flexpwm *)0xFFE28000UL)
#endif
/** @} */

#endif /* _SPC5_FLEXPWM_H_ */

/** @} */