msp432/
flctl.rs

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
// Licensed under the Apache License, Version 2.0 or the MIT License.
// SPDX-License-Identifier: Apache-2.0 OR MIT
// Copyright Tock Contributors 2022.

//! Flash Controller (FLCTL)

use kernel::utilities::registers::interfaces::ReadWriteable;
use kernel::utilities::registers::{register_bitfields, register_structs, ReadOnly, ReadWrite};
use kernel::utilities::StaticRef;

const FLCTL_BASE: StaticRef<FlCtlRegisters> =
    unsafe { StaticRef::new(0x4001_1000u32 as *const FlCtlRegisters) };

register_structs! {
    /// FLCTL
    FlCtlRegisters {
        /// Power Status Register
        (0x000 => power_stat: ReadOnly<u32, FLCTL_POWER_STAT::Register>),
        (0x004 => _reserved0),
        /// Bank0 Read Control Register
        (0x010 => bank0_rdctl: ReadWrite<u32, FLCTL_BANK0_RDCTL::Register>),
        /// Bank1 Read Control Register
        (0x014 => bank1_rdctl: ReadWrite<u32, FLCTL_BANK1_RDCTL::Register>),
        (0x018 => _reserved1),
        /// Read Burst/Compare Control and Status Register
        (0x020 => rdbrst_ctlstat: ReadWrite<u32, FLCTL_RDBRST_CTLSTAT::Register>),
        /// Read Burst/Compare Start Address Register
        (0x024 => rdbrst_startaddr: ReadWrite<u32>),
        /// Read Burst/Compare Length Register
        (0x028 => rdbrst_len: ReadWrite<u32>),
        (0x02C => _reserved2),
        /// Read Burst/Compare Fail Address Register
        (0x03C => rdbrst_failaddr: ReadWrite<u32>),
        /// Read Burst/Compare Fail Count Register
        (0x040 => rdbrst_failcnt: ReadWrite<u32>),
        (0x044 => _reserved3),
        /// Program Control and Status Register
        (0x050 => prg_ctlstat: ReadWrite<u32, FLCTL_PRG_CTLSTAT::Register>),
        /// Program Burst Control and Status Register
        (0x054 => prgbrst_ctlstat: ReadWrite<u32, FLCTL_PRGBRST_CTLSTAT::Register>),
        /// Program Burst Start Address Register
        (0x058 => prgbrst_startaddr: ReadWrite<u32>),
        (0x05C => _reserved4),
        /// Program Burst Data0 Register0
        (0x060 => prgbrst_data0_0: ReadWrite<u32>),
        /// Program Burst Data0 Register1
        (0x064 => prgbrst_data0_1: ReadWrite<u32>),
        /// Program Burst Data0 Register2
        (0x068 => prgbrst_data0_2: ReadWrite<u32>),
        /// Program Burst Data0 Register3
        (0x06C => prgbrst_data0_3: ReadWrite<u32>),
        /// Program Burst Data1 Register0
        (0x070 => prgbrst_data1_0: ReadWrite<u32>),
        /// Program Burst Data1 Register1
        (0x074 => prgbrst_data1_1: ReadWrite<u32>),
        /// Program Burst Data1 Register2
        (0x078 => prgbrst_data1_2: ReadWrite<u32>),
        /// Program Burst Data1 Register3
        (0x07C => prgbrst_data1_3: ReadWrite<u32>),
        /// Program Burst Data2 Register0
        (0x080 => prgbrst_data2_0: ReadWrite<u32>),
        /// Program Burst Data2 Register1
        (0x084 => prgbrst_data2_1: ReadWrite<u32>),
        /// Program Burst Data2 Register2
        (0x088 => prgbrst_data2_2: ReadWrite<u32>),
        /// Program Burst Data2 Register3
        (0x08C => prgbrst_data2_3: ReadWrite<u32>),
        /// Program Burst Data3 Register0
        (0x090 => prgbrst_data3_0: ReadWrite<u32>),
        /// Program Burst Data3 Register1
        (0x094 => prgbrst_data3_1: ReadWrite<u32>),
        /// Program Burst Data3 Register2
        (0x098 => prgbrst_data3_2: ReadWrite<u32>),
        /// Program Burst Data3 Register3
        (0x09C => prgbrst_data3_3: ReadWrite<u32>),
        /// Erase Control and Status Register
        (0x0A0 => erase_ctlstat: ReadWrite<u32, FLCTL_ERASE_CTLSTAT::Register>),
        /// Erase Sector Address Register
        (0x0A4 => erase_sectaddr: ReadWrite<u32>),
        (0x0A8 => _reserved5),
        /// Information Memory Bank0 Write/Erase Protection Register
        (0x0B0 => bank0_info_weprot: ReadWrite<u32, FLCTL_BANK0_INFO_WEPROT::Register>),
        /// Main Memory Bank0 Write/Erase Protection Register
        (0x0B4 => bank0_main_weprot: ReadWrite<u32, FLCTL_BANK0_MAIN_WEPROT::Register>),
        (0x0B8 => _reserved6),
        /// Information Memory Bank1 Write/Erase Protection Register
        (0x0C0 => bank1_info_weprot: ReadWrite<u32, FLCTL_BANK1_INFO_WEPROT::Register>),
        /// Main Memory Bank1 Write/Erase Protection Register
        (0x0C4 => bank1_main_weprot: ReadWrite<u32, FLCTL_BANK1_MAIN_WEPROT::Register>),
        (0x0C8 => _reserved7),
        /// Benchmark Control and Status Register
        (0x0D0 => bmrk_ctlstat: ReadWrite<u32, FLCTL_BMRK_CTLSTAT::Register>),
        /// Benchmark Instruction Fetch Count Register
        (0x0D4 => bmrk_ifetch: ReadWrite<u32>),
        /// Benchmark Data Read Count Register
        (0x0D8 => bmrk_dread: ReadWrite<u32>),
        /// Benchmark Count Compare Register
        (0x0DC => bmrk_cmp: ReadWrite<u32>),
        (0x0E0 => _reserved8),
        /// Interrupt Flag Register
        (0x0F0 => ifg: ReadWrite<u32, FLCTL_IFG::Register>),
        /// Interrupt Enable Register
        (0x0F4 => ie: ReadWrite<u32, FLCTL_IE::Register>),
        /// Clear Interrupt Flag Register
        (0x0F8 => clrifg: ReadWrite<u32, FLCTL_CLRIFG::Register>),
        /// Set Interrupt Flag Register
        (0x0FC => setifg: ReadWrite<u32, FLCTL_SETIFG::Register>),
        /// Read Timing Control Register
        (0x100 => read_timctl: ReadOnly<u32, FLCTL_READ_TIMCTL::Register>),
        /// Read Margin Timing Control Register
        (0x104 => readmargin_timctl: ReadOnly<u32>),
        /// Program Verify Timing Control Register
        (0x108 => prgver_timctl: ReadOnly<u32, FLCTL_PRGVER_TIMCTL::Register>),
        /// Erase Verify Timing Control Register
        (0x10C => ersver_timctl: ReadOnly<u32>),
        /// Leakage Verify Timing Control Register
        (0x110 => lkgver_timctl: ReadOnly<u32>),
        /// Program Timing Control Register
        (0x114 => program_timctl: ReadOnly<u32, FLCTL_PROGRAM_TIMCTL::Register>),
        /// Erase Timing Control Register
        (0x118 => erase_timctl: ReadOnly<u32, FLCTL_ERASE_TIMCTL::Register>),
        /// Mass Erase Timing Control Register
        (0x11C => masserase_timctl: ReadOnly<u32, FLCTL_MASSERASE_TIMCTL::Register>),
        /// Burst Program Timing Control Register
        (0x120 => burstprg_timctl: ReadOnly<u32>),
        (0x124 => @END),
    }
}

register_bitfields![u32,
    FLCTL_POWER_STAT [
        /// Flash power status
        PSTAT OFFSET(0) NUMBITS(3) [
            /// Flash IP in power-down mode
            FlashIPInPowerDownMode = 0,
            /// Flash IP Vdd domain power-up in progress
            FlashIPVddDomainPowerUpInProgress = 1,
            /// PSS LDO_GOOD, IREF_OK and VREF_OK check in progress
            PSSLDO_GOODIREF_OKAndVREF_OKCheckInProgress = 2,
            /// Flash IP SAFE_LV check in progress
            FlashIPSAFE_LVCheckInProgress = 3,
            /// Flash IP Active
            FlashIPActive = 4,
            /// Flash IP Active in Low-Frequency Active and Low-Frequency LPM0 modes.
            FlashIPActiveInLowFrequencyActiveAndLowFrequencyLPM0Modes = 5,
            /// Flash IP in Standby mode
            FlashIPInStandbyMode = 6,
            /// Flash IP in Current mirror boost state
            FlashIPInCurrentMirrorBoostState = 7
        ],
        /// PSS FLDO GOOD status
        LDOSTAT OFFSET(3) NUMBITS(1) [
            /// FLDO not GOOD
            FLDONotGOOD = 0,
            /// FLDO GOOD
            FLDOGOOD = 1
        ],
        /// PSS VREF stable status
        VREFSTAT OFFSET(4) NUMBITS(1) [
            /// Flash LDO not stable
            FlashLDONotStable = 0,
            /// Flash LDO stable
            FlashLDOStable = 1
        ],
        /// PSS IREF stable status
        IREFSTAT OFFSET(5) NUMBITS(1) [
            /// IREF not stable
            IREFNotStable = 0,
            /// IREF stable
            IREFStable = 1
        ],
        /// PSS trim done status
        TRIMSTAT OFFSET(6) NUMBITS(1) [
            /// PSS trim not complete
            PSSTrimNotComplete = 0,
            /// PSS trim complete
            PSSTrimComplete = 1
        ],
        /// Indicates if Flash is being accessed in 2T mode
        RD_2T OFFSET(7) NUMBITS(1) [
            /// Flash reads are in 1T mode
            FlashReadsAreIn1TMode = 0,
            /// Flash reads are in 2T mode
            FlashReadsAreIn2TMode = 1
        ]
    ],
    FLCTL_BANK0_RDCTL [
        /// Flash read mode control setting for Bank 0
        RD_MODE OFFSET(0) NUMBITS(4) [
            /// Normal read mode
            NormalReadMode = 0,
            /// Read Margin 0
            ReadMargin0 = 1,
            /// Read Margin 1
            ReadMargin1 = 2,
            /// Program Verify
            ProgramVerify = 3,
            /// Erase Verify
            EraseVerify = 4,
            /// Leakage Verify
            LeakageVerify = 5,
            /// Read Margin 0B
            ReadMargin0B = 9,
            /// Read Margin 1B
            ReadMargin1B = 10
        ],
        /// Enables read buffering feature for instruction fetches to this Bank
        BUFI OFFSET(4) NUMBITS(1) [],
        /// Enables read buffering feature for data reads to this Bank
        BUFD OFFSET(5) NUMBITS(1) [],
        /// Number of wait states for read
        WAIT OFFSET(12) NUMBITS(4) [
            /// 0 wait states
            _0WaitStates = 0,
            /// 1 wait states
            _1WaitStates = 1,
            /// 2 wait states
            _2WaitStates = 2,
            /// 3 wait states
            _3WaitStates = 3,
            /// 4 wait states
            _4WaitStates = 4,
            /// 5 wait states
            _5WaitStates = 5,
            /// 6 wait states
            _6WaitStates = 6,
            /// 7 wait states
            _7WaitStates = 7,
            /// 8 wait states
            _8WaitStates = 8,
            /// 9 wait states
            _9WaitStates = 9,
            /// 10 wait states
            _10WaitStates = 10,
            /// 11 wait states
            _11WaitStates = 11,
            /// 12 wait states
            _12WaitStates = 12,
            /// 13 wait states
            _13WaitStates = 13,
            /// 14 wait states
            _14WaitStates = 14,
            /// 15 wait states
            _15WaitStates = 15
        ],
        /// Read mode
        RD_MODE_STATUS OFFSET(16) NUMBITS(4) [
            /// Normal read mode
            NormalReadMode = 0,
            /// Read Margin 0
            ReadMargin0 = 1,
            /// Read Margin 1
            ReadMargin1 = 2,
            /// Program Verify
            ProgramVerify = 3,
            /// Erase Verify
            EraseVerify = 4,
            /// Leakage Verify
            LeakageVerify = 5,
            /// Read Margin 0B
            ReadMargin0B = 9,
            /// Read Margin 1B
            ReadMargin1B = 10
        ]
    ],
    FLCTL_BANK1_RDCTL [
        /// Flash read mode control setting for Bank 0
        RD_MODE OFFSET(0) NUMBITS(4) [
            /// Normal read mode
            NormalReadMode = 0,
            /// Read Margin 0
            ReadMargin0 = 1,
            /// Read Margin 1
            ReadMargin1 = 2,
            /// Program Verify
            ProgramVerify = 3,
            /// Erase Verify
            EraseVerify = 4,
            /// Leakage Verify
            LeakageVerify = 5,
            /// Read Margin 0B
            ReadMargin0B = 9,
            /// Read Margin 1B
            ReadMargin1B = 10
        ],
        /// Enables read buffering feature for instruction fetches to this Bank
        BUFI OFFSET(4) NUMBITS(1) [],
        /// Enables read buffering feature for data reads to this Bank
        BUFD OFFSET(5) NUMBITS(1) [],
        /// Read mode
        RD_MODE_STATUS OFFSET(16) NUMBITS(4) [
            /// Normal read mode
            NormalReadMode = 0,
            /// Read Margin 0
            ReadMargin0 = 1,
            /// Read Margin 1
            ReadMargin1 = 2,
            /// Program Verify
            ProgramVerify = 3,
            /// Erase Verify
            EraseVerify = 4,
            /// Leakage Verify
            LeakageVerify = 5,
            /// Read Margin 0B
            ReadMargin0B = 9,
            /// Read Margin 1B
            ReadMargin1B = 10
        ],
        /// Number of wait states for read
        WAIT OFFSET(12) NUMBITS(4) [
            /// 0 wait states
            _0WaitStates = 0,
            /// 1 wait states
            _1WaitStates = 1,
            /// 2 wait states
            _2WaitStates = 2,
            /// 3 wait states
            _3WaitStates = 3,
            /// 4 wait states
            _4WaitStates = 4,
            /// 5 wait states
            _5WaitStates = 5,
            /// 6 wait states
            _6WaitStates = 6,
            /// 7 wait states
            _7WaitStates = 7,
            /// 8 wait states
            _8WaitStates = 8,
            /// 9 wait states
            _9WaitStates = 9,
            /// 10 wait states
            _10WaitStates = 10,
            /// 11 wait states
            _11WaitStates = 11,
            /// 12 wait states
            _12WaitStates = 12,
            /// 13 wait states
            _13WaitStates = 13,
            /// 14 wait states
            _14WaitStates = 14,
            /// 15 wait states
            _15WaitStates = 15
        ]
    ],
    FLCTL_RDBRST_CTLSTAT [
        /// Start of burst/compare operation
        START OFFSET(0) NUMBITS(1) [],
        /// Type of memory that burst is carried out on
        MEM_TYPE OFFSET(1) NUMBITS(2) [
            /// Main Memory
            MainMemory = 0,
            /// Information Memory
            InformationMemory = 1,
            /// Engineering Memory
            EngineeringMemory = 3
        ],
        /// Terminate burst/compare operation
        STOP_FAIL OFFSET(3) NUMBITS(1) [],
        /// Data pattern used for comparison against memory read data
        DATA_CMP OFFSET(4) NUMBITS(1) [
            /// 0000_0000_0000_0000_0000_0000_0000_0000
            _0000_0000_0000_0000_0000_0000_0000_0000 = 0,
            /// FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF
            FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF = 1
        ],
        /// Enable comparison against test data compare registers
        TEST_EN OFFSET(6) NUMBITS(1) [],
        /// Status of Burst/Compare operation
        BRST_STAT OFFSET(16) NUMBITS(2) [
            /// Idle
            Idle = 0,
            /// Burst/Compare START bit written, but operation pending
            BurstCompareSTARTBitWrittenButOperationPending = 1,
            /// Burst/Compare in progress
            BurstCompareInProgress = 2,
            /// Burst complete (status of completed burst remains in this state unless explicitl
            BRST_STAT_3 = 3
        ],
        /// Burst/Compare Operation encountered atleast one data
        CMP_ERR OFFSET(18) NUMBITS(1) [],
        /// Burst/Compare Operation was terminated due to access to
        ADDR_ERR OFFSET(19) NUMBITS(1) [],
        /// Clear status bits 19-16 of this register
        CLR_STAT OFFSET(23) NUMBITS(1) []
    ],
    FLCTL_PRG_CTLSTAT [
        /// Master control for all word program operations
        ENABLE OFFSET(0) NUMBITS(1) [
            /// Word program operation disabled
            WordProgramOperationDisabled = 0,
            /// Word program operation enabled
            WordProgramOperationEnabled = 1
        ],
        /// Write mode
        MODE OFFSET(1) NUMBITS(1) [
            /// Write immediate mode. Starts program operation immediately on each write to the
            WriteImmediateModeStartsProgramOperationImmediatelyOnEachWriteToTheFlash = 0,
            /// Full word write mode. Flash controller collates data over multiple writes to com
            MODE_1 = 1
        ],
        /// Controls automatic pre program verify operations
        VER_PRE OFFSET(2) NUMBITS(1) [
            /// No pre program verification
            NoPreProgramVerification = 0,
            /// Pre verify feature automatically invoked for each write operation (irrespective
            PreVerifyFeatureAutomaticallyInvokedForEachWriteOperationIrrespectiveOfTheMode = 1
        ],
        /// Controls automatic post program verify operations
        VER_PST OFFSET(3) NUMBITS(1) [
            /// No post program verification
            NoPostProgramVerification = 0,
            /// Post verify feature automatically invoked for each write operation (irrespective
            PostVerifyFeatureAutomaticallyInvokedForEachWriteOperationIrrespectiveOfTheMode = 1
        ],
        /// Status of program operations in the Flash memory
        STATUS OFFSET(16) NUMBITS(2) [
            /// Idle (no program operation currently active)
            IdleNoProgramOperationCurrentlyActive = 0,
            /// Single word program operation triggered, but pending
            SingleWordProgramOperationTriggeredButPending = 1,
            /// Single word program in progress
            SingleWordProgramInProgress = 2
        ],
        /// Bank active
        BNK_ACT OFFSET(18) NUMBITS(1) [
            /// Word in Bank0 being programmed
            WordInBank0BeingProgrammed = 0,
            /// Word in Bank1 being programmed
            WordInBank1BeingProgrammed = 1
        ]
    ],
    FLCTL_PRGBRST_CTLSTAT [
        /// Trigger start of burst program operation
        START OFFSET(0) NUMBITS(1) [],
        /// Type of memory that burst program is carried out on
        TYPE OFFSET(1) NUMBITS(2) [
            /// Main Memory
            MainMemory = 0,
            /// Information Memory
            InformationMemory = 1,
            /// Engineering Memory
            EngineeringMemory = 3
        ],
        /// Length of burst
        LEN OFFSET(3) NUMBITS(3) [
            /// No burst operation
            NoBurstOperation = 0,
            /// 1 word burst of 128 bits, starting with address in the FLCTL_PRGBRST_STARTADDR R
            _1WordBurstOf128BitsStartingWithAddressInTheFLCTL_PRGBRST_STARTADDRRegister = 1,
            /// 2*128 bits burst write, starting with address in the FLCTL_PRGBRST_STARTADDR Reg
            _2128BitsBurstWriteStartingWithAddressInTheFLCTL_PRGBRST_STARTADDRRegister = 2,
            /// 3*128 bits burst write, starting with address in the FLCTL_PRGBRST_STARTADDR Reg
            _3128BitsBurstWriteStartingWithAddressInTheFLCTL_PRGBRST_STARTADDRRegister = 3,
            /// 4*128 bits burst write, starting with address in the FLCTL_PRGBRST_STARTADDR Reg
            _4128BitsBurstWriteStartingWithAddressInTheFLCTL_PRGBRST_STARTADDRRegister = 4
        ],
        /// Auto-Verify operation before the Burst Program
        AUTO_PRE OFFSET(6) NUMBITS(1) [
            /// No program verify operations carried out
            NoProgramVerifyOperationsCarriedOut = 0,
            /// Causes an automatic Burst Program Verify after the Burst Program Operation
            CausesAnAutomaticBurstProgramVerifyAfterTheBurstProgramOperation = 1
        ],
        /// Auto-Verify operation after the Burst Program
        AUTO_PST OFFSET(7) NUMBITS(1) [
            /// No program verify operations carried out
            NoProgramVerifyOperationsCarriedOut = 0,
            /// Causes an automatic Burst Program Verify before the Burst Program Operation
            CausesAnAutomaticBurstProgramVerifyBeforeTheBurstProgramOperation = 1
        ],
        /// Status of a Burst Operation
        BURST_STATUS OFFSET(16) NUMBITS(3) [
            /// Idle (Burst not active)
            IdleBurstNotActive = 0,
            /// Burst program started but pending
            BurstProgramStartedButPending = 1,
            /// Burst active, with 1st 128 bit word being written into Flash
            BurstActiveWith1st128BitWordBeingWrittenIntoFlash = 2,
            /// Burst active, with 2nd 128 bit word being written into Flash
            BurstActiveWith2nd128BitWordBeingWrittenIntoFlash = 3,
            /// Burst active, with 3rd 128 bit word being written into Flash
            BurstActiveWith3rd128BitWordBeingWrittenIntoFlash = 4,
            /// Burst active, with 4th 128 bit word being written into Flash
            BurstActiveWith4th128BitWordBeingWrittenIntoFlash = 5,
            /// Burst Complete (status of completed burst remains in this state unless explicitl
            BURST_STATUS_7 = 7
        ],
        /// Burst Operation encountered preprogram auto-verify errors
        PRE_ERR OFFSET(19) NUMBITS(1) [],
        /// Burst Operation encountered postprogram auto-verify errors
        PST_ERR OFFSET(20) NUMBITS(1) [],
        /// Burst Operation was terminated due to attempted program of reserved memory
        ADDR_ERR OFFSET(21) NUMBITS(1) [],
        /// Clear status bits 21-16 of this register
        CLR_STAT OFFSET(23) NUMBITS(1) []
    ],
    FLCTL_ERASE_CTLSTAT [
        /// Start of Erase operation
        START OFFSET(0) NUMBITS(1) [],
        /// Erase mode selected by application
        MODE OFFSET(1) NUMBITS(1) [
            /// Sector Erase (controlled by FLTCTL_ERASE_SECTADDR)
            SectorEraseControlledByFLTCTL_ERASE_SECTADDR = 0,
            /// Mass Erase (includes all Main and Information memory sectors that don't have cor
            MODE_1 = 1
        ],
        /// Type of memory that erase operation is carried out on
        TYPE OFFSET(2) NUMBITS(2) [
            /// Main Memory
            MainMemory = 0,
            /// Information Memory
            InformationMemory = 1,
            /// Engineering Memory
            EngineeringMemory = 3
        ],
        /// Status of erase operations in the Flash memory
        STATUS OFFSET(16) NUMBITS(2) [
            /// Idle (no program operation currently active)
            IdleNoProgramOperationCurrentlyActive = 0,
            /// Erase operation triggered to START but pending
            EraseOperationTriggeredToSTARTButPending = 1,
            /// Erase operation in progress
            EraseOperationInProgress = 2,
            /// Erase operation completed (status of completed erase remains in this state unles
            STATUS_3 = 3
        ],
        /// Erase Operation was terminated due to attempted erase of reserved memory address
        ADDR_ERR OFFSET(18) NUMBITS(1) [],
        /// Clear status bits 18-16 of this register
        CLR_STAT OFFSET(19) NUMBITS(1) []
    ],
    FLCTL_BANK0_INFO_WEPROT [
        /// Protects Sector 0 from program or erase
        PROT0 OFFSET(0) NUMBITS(1) [],
        /// Protects Sector 1 from program or erase
        PROT1 OFFSET(1) NUMBITS(1) []
    ],
    FLCTL_BANK0_MAIN_WEPROT [
        /// Protects Sector 0 from program or erase
        PROT0 OFFSET(0) NUMBITS(1) [],
        /// Protects Sector 1 from program or erase
        PROT1 OFFSET(1) NUMBITS(1) [],
        /// Protects Sector 2 from program or erase
        PROT2 OFFSET(2) NUMBITS(1) [],
        /// Protects Sector 3 from program or erase
        PROT3 OFFSET(3) NUMBITS(1) [],
        /// Protects Sector 4 from program or erase
        PROT4 OFFSET(4) NUMBITS(1) [],
        /// Protects Sector 5 from program or erase
        PROT5 OFFSET(5) NUMBITS(1) [],
        /// Protects Sector 6 from program or erase
        PROT6 OFFSET(6) NUMBITS(1) [],
        /// Protects Sector 7 from program or erase
        PROT7 OFFSET(7) NUMBITS(1) [],
        /// Protects Sector 8 from program or erase
        PROT8 OFFSET(8) NUMBITS(1) [],
        /// Protects Sector 9 from program or erase
        PROT9 OFFSET(9) NUMBITS(1) [],
        /// Protects Sector 10 from program or erase
        PROT10 OFFSET(10) NUMBITS(1) [],
        /// Protects Sector 11 from program or erase
        PROT11 OFFSET(11) NUMBITS(1) [],
        /// Protects Sector 12 from program or erase
        PROT12 OFFSET(12) NUMBITS(1) [],
        /// Protects Sector 13 from program or erase
        PROT13 OFFSET(13) NUMBITS(1) [],
        /// Protects Sector 14 from program or erase
        PROT14 OFFSET(14) NUMBITS(1) [],
        /// Protects Sector 15 from program or erase
        PROT15 OFFSET(15) NUMBITS(1) [],
        /// Protects Sector 16 from program or erase
        PROT16 OFFSET(16) NUMBITS(1) [],
        /// Protects Sector 17 from program or erase
        PROT17 OFFSET(17) NUMBITS(1) [],
        /// Protects Sector 18 from program or erase
        PROT18 OFFSET(18) NUMBITS(1) [],
        /// Protects Sector 19 from program or erase
        PROT19 OFFSET(19) NUMBITS(1) [],
        /// Protects Sector 20 from program or erase
        PROT20 OFFSET(20) NUMBITS(1) [],
        /// Protects Sector 21 from program or erase
        PROT21 OFFSET(21) NUMBITS(1) [],
        /// Protects Sector 22 from program or erase
        PROT22 OFFSET(22) NUMBITS(1) [],
        /// Protects Sector 23 from program or erase
        PROT23 OFFSET(23) NUMBITS(1) [],
        /// Protects Sector 24 from program or erase
        PROT24 OFFSET(24) NUMBITS(1) [],
        /// Protects Sector 25 from program or erase
        PROT25 OFFSET(25) NUMBITS(1) [],
        /// Protects Sector 26 from program or erase
        PROT26 OFFSET(26) NUMBITS(1) [],
        /// Protects Sector 27 from program or erase
        PROT27 OFFSET(27) NUMBITS(1) [],
        /// Protects Sector 28 from program or erase
        PROT28 OFFSET(28) NUMBITS(1) [],
        /// Protects Sector 29 from program or erase
        PROT29 OFFSET(29) NUMBITS(1) [],
        /// Protects Sector 30 from program or erase
        PROT30 OFFSET(30) NUMBITS(1) [],
        /// Protects Sector 31 from program or erase
        PROT31 OFFSET(31) NUMBITS(1) []
    ],
    FLCTL_BANK1_INFO_WEPROT [
        /// Protects Sector 0 from program or erase operations
        PROT0 OFFSET(0) NUMBITS(1) [],
        /// Protects Sector 1 from program or erase operations
        PROT1 OFFSET(1) NUMBITS(1) []
    ],
    FLCTL_BANK1_MAIN_WEPROT [
        /// Protects Sector 0 from program or erase operations
        PROT0 OFFSET(0) NUMBITS(1) [],
        /// Protects Sector 1 from program or erase operations
        PROT1 OFFSET(1) NUMBITS(1) [],
        /// Protects Sector 2 from program or erase operations
        PROT2 OFFSET(2) NUMBITS(1) [],
        /// Protects Sector 3 from program or erase operations
        PROT3 OFFSET(3) NUMBITS(1) [],
        /// Protects Sector 4 from program or erase operations
        PROT4 OFFSET(4) NUMBITS(1) [],
        /// Protects Sector 5 from program or erase operations
        PROT5 OFFSET(5) NUMBITS(1) [],
        /// Protects Sector 6 from program or erase operations
        PROT6 OFFSET(6) NUMBITS(1) [],
        /// Protects Sector 7 from program or erase operations
        PROT7 OFFSET(7) NUMBITS(1) [],
        /// Protects Sector 8 from program or erase operations
        PROT8 OFFSET(8) NUMBITS(1) [],
        /// Protects Sector 9 from program or erase operations
        PROT9 OFFSET(9) NUMBITS(1) [],
        /// Protects Sector 10 from program or erase operations
        PROT10 OFFSET(10) NUMBITS(1) [],
        /// Protects Sector 11 from program or erase operations
        PROT11 OFFSET(11) NUMBITS(1) [],
        /// Protects Sector 12 from program or erase operations
        PROT12 OFFSET(12) NUMBITS(1) [],
        /// Protects Sector 13 from program or erase operations
        PROT13 OFFSET(13) NUMBITS(1) [],
        /// Protects Sector 14 from program or erase operations
        PROT14 OFFSET(14) NUMBITS(1) [],
        /// Protects Sector 15 from program or erase operations
        PROT15 OFFSET(15) NUMBITS(1) [],
        /// Protects Sector 16 from program or erase operations
        PROT16 OFFSET(16) NUMBITS(1) [],
        /// Protects Sector 17 from program or erase operations
        PROT17 OFFSET(17) NUMBITS(1) [],
        /// Protects Sector 18 from program or erase operations
        PROT18 OFFSET(18) NUMBITS(1) [],
        /// Protects Sector 19 from program or erase operations
        PROT19 OFFSET(19) NUMBITS(1) [],
        /// Protects Sector 20 from program or erase operations
        PROT20 OFFSET(20) NUMBITS(1) [],
        /// Protects Sector 21 from program or erase operations
        PROT21 OFFSET(21) NUMBITS(1) [],
        /// Protects Sector 22 from program or erase operations
        PROT22 OFFSET(22) NUMBITS(1) [],
        /// Protects Sector 23 from program or erase operations
        PROT23 OFFSET(23) NUMBITS(1) [],
        /// Protects Sector 24 from program or erase operations
        PROT24 OFFSET(24) NUMBITS(1) [],
        /// Protects Sector 25 from program or erase operations
        PROT25 OFFSET(25) NUMBITS(1) [],
        /// Protects Sector 26 from program or erase operations
        PROT26 OFFSET(26) NUMBITS(1) [],
        /// Protects Sector 27 from program or erase operations
        PROT27 OFFSET(27) NUMBITS(1) [],
        /// Protects Sector 28 from program or erase operations
        PROT28 OFFSET(28) NUMBITS(1) [],
        /// Protects Sector 29 from program or erase operations
        PROT29 OFFSET(29) NUMBITS(1) [],
        /// Protects Sector 30 from program or erase operations
        PROT30 OFFSET(30) NUMBITS(1) [],
        /// Protects Sector 31 from program or erase operations
        PROT31 OFFSET(31) NUMBITS(1) []
    ],
    FLCTL_BMRK_CTLSTAT [
        /// When 1, increments the Instruction Benchmark count register on each instruction
        I_BMRK OFFSET(0) NUMBITS(1) [],
        /// When 1, increments the Data Benchmark count register on each data read access to
        D_BMRK OFFSET(1) NUMBITS(1) [],
        /// When 1, enables comparison of the Instruction or Data Benchmark Registers agains
        CMP_EN OFFSET(2) NUMBITS(1) [],
        /// Selects which benchmark register should be compared against the threshold
        CMP_SEL OFFSET(3) NUMBITS(1) [
            /// Compares the Instruction Benchmark Register against the threshold value
            ComparesTheInstructionBenchmarkRegisterAgainstTheThresholdValue = 0,
            /// Compares the Data Benchmark Register against the threshold value
            ComparesTheDataBenchmarkRegisterAgainstTheThresholdValue = 1
        ]
    ],
    FLCTL_IFG [
        /// If set to 1, indicates that the Read Burst/Compare operation is complete
        RDBRST OFFSET(0) NUMBITS(1) [],
        /// If set to 1, indicates that the pre-program verify operation has detected an err
        AVPRE OFFSET(1) NUMBITS(1) [],
        /// If set to 1, indicates that the post-program verify operation has failed compari
        AVPST OFFSET(2) NUMBITS(1) [],
        /// If set to 1, indicates that a word Program operation is complete
        PRG OFFSET(3) NUMBITS(1) [],
        /// If set to 1, indicates that the configured Burst Program operation is complete
        PRGB OFFSET(4) NUMBITS(1) [],
        /// If set to 1, indicates that the Erase operation is complete
        ERASE OFFSET(5) NUMBITS(1) [],
        /// If set to 1, indicates that a Benchmark Compare match occurred
        BMRK OFFSET(8) NUMBITS(1) [],
        /// If set to 1, indicates a word composition error in full word write mode (possibl
        PRG_ERR OFFSET(9) NUMBITS(1) []
    ],
    FLCTL_IE [
        /// If set to 1, enables the Controller to generate an interrupt based on the corres
        RDBRST OFFSET(0) NUMBITS(1) [],
        /// If set to 1, enables the Controller to generate an interrupt based on the corres
        AVPRE OFFSET(1) NUMBITS(1) [],
        /// If set to 1, enables the Controller to generate an interrupt based on the corres
        AVPST OFFSET(2) NUMBITS(1) [],
        /// If set to 1, enables the Controller to generate an interrupt based on the corres
        PRG OFFSET(3) NUMBITS(1) [],
        /// If set to 1, enables the Controller to generate an interrupt based on the corres
        PRGB OFFSET(4) NUMBITS(1) [],
        /// If set to 1, enables the Controller to generate an interrupt based on the corres
        ERASE OFFSET(5) NUMBITS(1) [],
        /// If set to 1, enables the Controller to generate an interrupt based on the corres
        BMRK OFFSET(8) NUMBITS(1) [],
        /// If set to 1, enables the Controller to generate an interrupt based on the corres
        PRG_ERR OFFSET(9) NUMBITS(1) []
    ],
    FLCTL_CLRIFG [
        /// Write 1 clears the corresponding interrupt flag bit in the FLCTL_IFG
        RDBRST OFFSET(0) NUMBITS(1) [],
        /// Write 1 clears the corresponding interrupt flag bit in the FLCTL_IFG
        AVPRE OFFSET(1) NUMBITS(1) [],
        /// Write 1 clears the corresponding interrupt flag bit in the FLCTL_IFG
        AVPST OFFSET(2) NUMBITS(1) [],
        /// Write 1 clears the corresponding interrupt flag bit in the FLCTL_IFG
        PRG OFFSET(3) NUMBITS(1) [],
        /// Write 1 clears the corresponding interrupt flag bit in the FLCTL_IFG
        PRGB OFFSET(4) NUMBITS(1) [],
        /// Write 1 clears the corresponding interrupt flag bit in the FLCTL_IFG
        ERASE OFFSET(5) NUMBITS(1) [],
        /// Write 1 clears the corresponding interrupt flag bit in the FLCTL_IFG
        BMRK OFFSET(8) NUMBITS(1) [],
        /// Write 1 clears the corresponding interrupt flag bit in the FLCTL_IFG
        PRG_ERR OFFSET(9) NUMBITS(1) []
    ],
    FLCTL_SETIFG [
        /// Write 1 clears the corresponding interrupt flag bit in the FLCTL_IFG
        RDBRST OFFSET(0) NUMBITS(1) [],
        /// Write 1 clears the corresponding interrupt flag bit in the FLCTL_IFG
        AVPRE OFFSET(1) NUMBITS(1) [],
        /// Write 1 clears the corresponding interrupt flag bit in the FLCTL_IFG
        AVPST OFFSET(2) NUMBITS(1) [],
        /// Write 1 clears the corresponding interrupt flag bit in the FLCTL_IFG
        PRG OFFSET(3) NUMBITS(1) [],
        /// Write 1 clears the corresponding interrupt flag bit in the FLCTL_IFG
        PRGB OFFSET(4) NUMBITS(1) [],
        /// Write 1 clears the corresponding interrupt flag bit in the FLCTL_IFG
        ERASE OFFSET(5) NUMBITS(1) [],
        /// Write 1 clears the corresponding interrupt flag bit in the FLCTL_IFG
        BMRK OFFSET(8) NUMBITS(1) [],
        /// Write 1 clears the corresponding interrupt flag bit in the FLCTL_IFG
        PRG_ERR OFFSET(9) NUMBITS(1) []
    ],
    FLCTL_READ_TIMCTL [
        /// Configures the length of the Setup phase for this operation
        SETUP OFFSET(0) NUMBITS(8) [],
        /// Length of the IREF_BOOST1 signal of the IP
        IREF_BOOST1 OFFSET(12) NUMBITS(4) [],
        /// Length of the Setup time into read mode when the device is recovering from one o
        SETUP_LONG OFFSET(16) NUMBITS(8) []
    ],
    FLCTL_PRGVER_TIMCTL [
        /// Length of the Setup phase for this operation
        SETUP OFFSET(0) NUMBITS(8) [],
        /// Length of the Active phase for this operation
        ACTIVE OFFSET(8) NUMBITS(4) [],
        /// Length of the Hold phase for this operation
        HOLD OFFSET(12) NUMBITS(4) []
    ],
    FLCTL_PROGRAM_TIMCTL [
        /// Length of the Setup phase for this operation
        SETUP OFFSET(0) NUMBITS(8) [],
        /// Length of the Active phase for this operation
        ACTIVE OFFSET(8) NUMBITS(20) [],
        /// Length of the Hold phase for this operation
        HOLD OFFSET(28) NUMBITS(4) []
    ],
    FLCTL_ERASE_TIMCTL [
        /// Length of the Setup phase for this operation
        SETUP OFFSET(0) NUMBITS(8) [],
        /// Length of the Active phase for this operation
        ACTIVE OFFSET(8) NUMBITS(20) [],
        /// Length of the Hold phase for this operation
        HOLD OFFSET(28) NUMBITS(4) []
    ],
    FLCTL_MASSERASE_TIMCTL [
        /// Length of the time for which LDO Boost Signal is kept active
        BOOST_ACTIVE OFFSET(0) NUMBITS(8) [],
        /// Length for which Flash deactivates the LDO Boost signal before processing any ne
        BOOST_HOLD OFFSET(8) NUMBITS(8) []
    ]
];

/// Wait states.
///
/// If the clock runs with a higher frequency than the flash is able to operate, it's possible to
/// configure a certain amount of wait-states which stall the CPU in order to access the data within
/// the flash in a reliable way.
/// For a detailed description check the datasheet at page 458 section 9.2.2.1.
#[repr(u32)]
#[derive(Copy, Clone)]
pub enum WaitStates {
    _0 = 0,
    _1 = 1,
    _2 = 2,
    _3 = 3,
    _4 = 4,
    _5 = 5,
    _6 = 6,
    _7 = 7,
    _8 = 8,
    _9 = 9,
    _10 = 10,
    _11 = 11,
    _12 = 12,
    _13 = 13,
    _14 = 14,
    _15 = 15,
}

pub struct FlCtl {
    registers: StaticRef<FlCtlRegisters>,
}

impl FlCtl {
    pub const fn new() -> FlCtl {
        FlCtl {
            registers: FLCTL_BASE,
        }
    }

    pub fn set_waitstates(&self, ws: WaitStates) {
        self.registers
            .bank0_rdctl
            .modify(FLCTL_BANK0_RDCTL::WAIT.val(ws as u32));
        self.registers
            .bank1_rdctl
            .modify(FLCTL_BANK1_RDCTL::WAIT.val(ws as u32));
    }

    pub fn set_buffering(&self, enable: bool) {
        self.registers.bank0_rdctl.modify(
            FLCTL_BANK0_RDCTL::BUFD.val(enable as u32) + FLCTL_BANK0_RDCTL::BUFI.val(enable as u32),
        );
        self.registers.bank1_rdctl.modify(
            FLCTL_BANK1_RDCTL::BUFD.val(enable as u32) + FLCTL_BANK1_RDCTL::BUFI.val(enable as u32),
        );
    }
}