summaryrefslogtreecommitdiff
path: root/msp340/Blink/driverlib/MSP430FR5xx_6xx/esi.h
blob: 83f07c7a1c30d1498367a4e09fa36c529b5aa10f (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
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
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
/* --COPYRIGHT--,BSD
 * Copyright (c) 2014, Texas Instruments Incorporated
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * *  Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * *  Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * *  Neither the name of Texas Instruments Incorporated nor the names of
 *    its contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 * --/COPYRIGHT--*/
//*****************************************************************************
//
// esi.h - Driver for the ESI Module.
//
//*****************************************************************************

#ifndef __MSP430WARE_ESI_H__
#define __MSP430WARE_ESI_H__

#include "inc/hw_memmap.h"

#ifdef __MSP430_HAS_ESI__

//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif

uint16_t ESI_getCounter0(void);
uint16_t ESI_getCounter1(void);
uint16_t ESI_getCounter2(void);
uint16_t ESI_getOscCounter(void);

//*****************************************************************************
//
//The following are values that can be passed to excitationCircuitSelect
//parameter in ESI_AFE_InitParams
//
//*****************************************************************************
#define ESI_EXCITATION_CIRCUIT_DISABLED 0x0
#define ESI_EXCITATION_CIRCUIT_ENABLED  ESITEN

//*****************************************************************************
//
//The following are values that can be passed to sampleAndHoldSelect
//parameter in ESI_AFE_InitParams
//
//*****************************************************************************
#define ESI_SAMPLE_HOLD_DISABLED 0x0
#define ESI_SAMPLE_HOLD_ENABLED  ESISH

//*****************************************************************************
//
//The following are values that can be passed to midVoltageGeneratorSelect
//parameter in ESI_AFE_InitParams
//
//*****************************************************************************
#define ESI_MID_VOLTAGE_GENERATOR_DISABLED 0x0
#define ESI_MID_VOLTAGE_GENERATOR_ENABLED  ESIVCC2

//*****************************************************************************
//
//The following are values that can be passed to sampleAndHoldVSSConnect
//parameter in ESI_AFE_InitParams
//
//*****************************************************************************
#define ESI_SAMPLE_HOLD_VSS_TO_ESIVSS   0x0
#define ESI_SAMPLE_HOLD_VSS_BY_TSM      ESIVSS

//*****************************************************************************
//
//The following are values that can be passed to
//inputSelectAFE1 parameter in ESI_AFE1_InitParams
//
//*****************************************************************************
#define ESI_AFE1_INPUT_SELECT_CHx        0
#define ESI_AFE1_INPUT_SELECT_CIx        1
#define ESI_AFE1_INPUT_SELECT_CI3        2
#define ESI_AFE1_INPUT_SELECT_CI         3

//*****************************************************************************
//
//The following are values that can be passed to
//inputSelectAFE2 parameter in ESI_AFE2_InitParams
//
//*****************************************************************************
#define ESI_AFE2_INPUT_SELECT_CHx        0
#define ESI_AFE2_INPUT_SELECT_CIx        ESICA2X

//*****************************************************************************
//
//The following are values that can be passed to
//inverterSelectOutputAFE1 parameter in ESI_AFE1_InitParams
//
//*****************************************************************************
#define ESI_INVERTER_FOR_AFE1_DISABLE   0x0
#define ESI_INVERTER_FOR_AFE1_ENABLE    ESICA1INV

//*****************************************************************************
//
//The following are values that can be passed to
//inverterSelectOutputAFE2 parameter in ESI_AFE2_InitParams
//
//*****************************************************************************
#define ESI_INVERTER_FOR_AFE2_DISABLE   0x0
#define ESI_INVERTER_FOR_AFE2_ENABLE    ESICA2INV

//*****************************************************************************
//
//The following are values that can be passed to
//tsmControlOfComparatorAFE2 parameter in ESI_AFE2_InitParams
//
//*****************************************************************************
#define ESI_TSM_COMPARATOR_CONTROL_AFE2_DISABLE    0x0
#define ESI_TSM_COMPARATOR_CONTROL_AFE2_ENABLE     ESICA2EN

//*****************************************************************************
//
//The following are values that can be passed to
//tsmControlDacAFE2 parameter in ESI_AFE2_InitParams
//
//*****************************************************************************
#define ESI_TSM_DAC_CONTROL_AFE2_DISABLE    0x0
#define ESI_TSM_DAC_CONTROL_AFE2_ENABLE     ESIDAC2EN

typedef struct ESI_AFE1_InitParams
{
    uint16_t excitationCircuitSelect;
    uint16_t sampleAndHoldSelect;
    uint16_t midVoltageGeneratorSelect;
    uint16_t sampleAndHoldVSSConnect;
    uint16_t inputSelectAFE1;
    uint16_t inverterSelectOutputAFE1;
} ESI_AFE1_InitParams;

extern const ESI_AFE1_InitParams ESI_AFE1_INITPARAMS_DEFAULT;

void ESI_AFE1_init(ESI_AFE1_InitParams *params);

typedef struct ESI_AFE2_InitParams
{
    uint16_t inputSelectAFE2;
    uint16_t inverterSelectOutputAFE2;
    uint16_t tsmControlComparatorAFE2;
    uint16_t tsmControlDacAFE2;
} ESI_AFE2_InitParams;

extern const ESI_AFE2_InitParams ESI_AFE2_INITPARAMS_DEFAULT;

void ESI_AFE2_init(ESI_AFE2_InitParams *params);

//*****************************************************************************
//
//The following are values that can be passed to
//channelSelect parameter in ESI_getLatchedComparatorOutput
//
//*****************************************************************************
#define ESI_AFE1_CHANNEL0_SELECT            ESIOUT0
#define ESI_AFE1_CHANNEL1_SELECT            ESIOUT1
#define ESI_AFE1_CHANNEL2_SELECT            ESIOUT2
#define ESI_AFE1_CHANNEL3_SELECT            ESIOUT3
#define ESI_AFE2_CHANNEL0_SELECT            ESIOUT4
#define ESI_AFE2_CHANNEL1_SELECT            ESIOUT5
#define ESI_AFE2_CHANNEL2_SELECT            ESIOUT6
#define ESI_AFE2_CHANNEL3_SELECT            ESIOUT7
#define ESI_AFE1_TEST_CHANNEL0_SELECT       ESITCHOUT0
#define ESI_AFE1_TEST_CHANNEL1_SELECT       ESITCHOUT1

//*****************************************************************************
//
//The following are values that are returned by ESI_getLatchedComparatorOutput
//
//*****************************************************************************
#define ESI_AFE_OUTPUT_HIGH   0x1
#define ESI_AFE_OUTPUT_LOW  0x0

uint16_t ESI_getLatchedComparatorOutput(uint16_t channelSelect);

//*****************************************************************************
//
//The following are values that can be passed to
//smclkDivider parameter in ESI_TSM_InitParams
//
//*****************************************************************************
#define ESI_TSM_SMCLK_DIV_1     0x0
#define ESI_TSM_SMCLK_DIV_2     ESIDIV10
#define ESI_TSM_SMCLK_DIV_4     ESIDIV11
#define ESI_TSM_SMCLK_DIV_8     ESIDIV10 + ESIDIV11

//*****************************************************************************
//
//The following are values that can be passed to
//aclkDivider parameter in ESI_TSM_InitParams
//
//*****************************************************************************
#define ESI_TSM_ACLK_DIV_1     0x0
#define ESI_TSM_ACLK_DIV_2     ESIDIV20
#define ESI_TSM_ACLK_DIV_4     ESIDIV21
#define ESI_TSM_ACLK_DIV_8     ESIDIV20 + ESIDIV21

//*****************************************************************************
//
//The following are values that can be passed to
//startTriggerAclkDivider parameter in ESI_TSM_InitParams
//
//*****************************************************************************
#define ESI_TSM_START_TRIGGER_DIV_2     0x0
#define ESI_TSM_START_TRIGGER_DIV_6     ESIDIV3A0
#define ESI_TSM_START_TRIGGER_DIV_10    ESIDIV3A1
#define ESI_TSM_START_TRIGGER_DIV_14    ESIDIV3A0 + ESIDIV3A1
#define ESI_TSM_START_TRIGGER_DIV_18    ESIDIV3A2
#define ESI_TSM_START_TRIGGER_DIV_22    ESIDIV3A2 + ESIDIV3A0
#define ESI_TSM_START_TRIGGER_DIV_26    ESIDIV3A2 + ESIDIV3A1
#define ESI_TSM_START_TRIGGER_DIV_30    ESIDIV3A2 + ESIDIV3A1 + ESIDIV3A0
#define ESI_TSM_START_TRIGGER_DIV_42    ESIDIV3A0 + ESIDIV3A1 + ESIDIV3B0
#define ESI_TSM_START_TRIGGER_DIV_50    ESIDIV3A1 + ESIDIV3B1
#define ESI_TSM_START_TRIGGER_DIV_54    ESIDIV3A2 + ESIDIV3B0
#define ESI_TSM_START_TRIGGER_DIV_66    ESIDIV3A2 + ESIDIV3A0 + ESIDIV3B0
#define ESI_TSM_START_TRIGGER_DIV_70    ESIDIV3A1 + ESIDIV3A0 + ESIDIV3B1
#define ESI_TSM_START_TRIGGER_DIV_78    ESIDIV3A2 + ESIDIV3A1 + ESIDIV3B0
#define ESI_TSM_START_TRIGGER_DIV_90    ESIDIV3A2 + ESIDIV3A1 + ESIDIV3A0 + \
    ESIDIV3B0
#define ESI_TSM_START_TRIGGER_DIV_98    ESIDIV3A0 + ESIDIV3A1 + ESIDIV3B0 + \
    ESIDIV3B1
#define ESI_TSM_START_TRIGGER_DIV_110   ESIDIV3A2 + ESIDIV3A0 + ESIDIV3B1
#define ESI_TSM_START_TRIGGER_DIV_126   ESIDIV3A2 + ESIDIV3B0 + ESIDIV3B1
#define ESI_TSM_START_TRIGGER_DIV_130   ESIDIV3A2 + ESIDIV3A1 + ESIDIV3B1
#define ESI_TSM_START_TRIGGER_DIV_150   ESIDIV3A2 + ESIDIV3A1 + ESIDIV3A0 + \
    ESIDIV3B1
#define ESI_TSM_START_TRIGGER_DIV_154   ESIDIV3A2 + ESIDIV3A0 + ESIDIV3B0 + \
    ESIDIV3B1
#define ESI_TSM_START_TRIGGER_DIV_162   ESIDIV3A2 + ESIDIV3B2
#define ESI_TSM_START_TRIGGER_DIV_182   ESIDIV3A2 + ESIDIV3A1 + ESIDIV3B0 + \
    ESIDIV3B1
#define ESI_TSM_START_TRIGGER_DIV_198   ESIDIV3A2 + ESIDIV3A0 + ESIDIV3B2
#define ESI_TSM_START_TRIGGER_DIV_210   ESIDIV3A2 + ESIDIV3A1 + ESIDIV3A0 + \
    ESIDIV3B0 + ESIDIV3B1
#define ESI_TSM_START_TRIGGER_DIV_234   ESIDIV3A2 + ESIDIV3A1 + ESIDIV3B2
#define ESI_TSM_START_TRIGGER_DIV_242   ESIDIV3A2 + ESIDIV3A0 + ESIDIV3B2 + \
    ESIDIV3B0
#define ESI_TSM_START_TRIGGER_DIV_270   ESIDIV3A2 + ESIDIV3A1 + ESIDIV3A0 + \
    ESIDIV3B2
#define ESI_TSM_START_TRIGGER_DIV_286   ESIDIV3A2 + ESIDIV3A1 + ESIDIV3B2 + \
    ESIDIV3B0
#define ESI_TSM_START_TRIGGER_DIV_330   ESIDIV3A2 + ESIDIV3A1 + ESIDIV3A0 + \
    ESIDIV3B2 + ESIDIV3B0
#define ESI_TSM_START_TRIGGER_DIV_338   ESIDIV3A2 + ESIDIV3A1 + ESIDIV3B2 + \
    ESIDIV3B1
#define ESI_TSM_START_TRIGGER_DIV_390   ESIDIV3A2 + ESIDIV3A1 + ESIDIV3A0 + \
    ESIDIV3B2 + ESIDIV3B1
#define ESI_TSM_START_TRIGGER_DIV_450   ESIDIV3A2 + ESIDIV3A1 + ESIDIV3A0 + \
    ESIDIV3B2 + ESIDIV3B1 + ESIDIV3B0

//*****************************************************************************
//
//The following are values that can be passed to
//repeatMode parameter in ESI_TSM_InitParams
//
//*****************************************************************************
#define ESI_TSM_REPEAT_NEW_TRIGGER          0x0
#define ESI_TSM_REPEAT_END_OF_PREVIOUS_SEQ  ESITSMRP

//*****************************************************************************
//
//The following are values that can be passed to
//startTriggerSelection parameter in ESI_TSM_InitParams
//
//*****************************************************************************
#define ESI_TSM_STOP_SEQUENCE                   0x0
#define ESI_TSM_START_TRIGGER_ACLK              ESITSMTRG0
#define ESI_TSM_START_TRIGGER_SOFTWARE          ESITSMTRG1
#define ESI_TSM_START_TRIGGER_ACLK_OR_SOFTWARE  ESITSMTRG1 + ESITSMTRG0

//*****************************************************************************
//
//The following are values that can be passed to
//tsmFunctionalitySelection parameter in ESI_TSM_InitParams
//
//*****************************************************************************
#define ESI_TSM_HIGH_FREQ_CLK_FUNCTION_ON   0x0
#define ESI_TSM_AUTOZERO_CYCLE_FUNCTION_ON  ESICLKAZSEL

typedef struct ESI_TSM_InitParams
{
    uint16_t smclkDivider;
    uint16_t aclkDivider;
    uint16_t startTriggerAclkDivider;
    uint16_t repeatMode;
    uint16_t startTriggerSelection;
    uint16_t tsmFunctionSelection;
} ESI_TSM_InitParams;

extern const ESI_TSM_InitParams ESI_TSM_INITPARAMS_DEFAULT;

void ESI_TSM_init(ESI_TSM_InitParams *params);

void ESI_TSM_clearTable(void);

void ESI_TSM_copyTable(uint16_t* tsmTable,
                       uint16_t size);

void ESI_TSM_softwareTrigger(void);

uint8_t ESI_TSM_getTSMStateDuration(uint8_t stateRegNum);

void ESI_TSM_setTSMStateDuration(uint8_t stateRegNum,
                                 uint8_t duration);

//*****************************************************************************
//
//The following are values that can be passed to
//Q6Select parameter in ESI_PSM_InitParams
//
//*****************************************************************************
#define ESI_PSM_Q6_DISABLE  0x0
#define ESI_PSM_Q6_ENABLE   ESIQ6EN

//*****************************************************************************
//
//The following are values that can be passed to
//Q7TriggerSelect parameter in ESI_PSM_InitParams
//
//*****************************************************************************
#define ESI_PSM_Q7_TRIGGER_DISABLE  0x0
#define ESI_PSM_Q7_TRIGGER_ENABLE   ESIQ7TRG

//*****************************************************************************
//
//The following are values that can be passed to
//count0Select parameter in ESI_PSM_InitParams
//
//*****************************************************************************
#define ESI_PSM_CNT0_DISABLE 0x0
#define ESI_PSM_CNT0_ENABLE ESICNT0EN

//*****************************************************************************
//
//The following are values that can be passed to
//count0Reset parameter in ESI_PSM_InitParams
//
//*****************************************************************************
#define ESI_PSM_CNT0_NO_RESET 0x0
#define ESI_PSM_CNT0_RESET ESICNT0RST

//*****************************************************************************
//
//The following are values that can be passed to
//count1Select parameter in ESI_PSM_InitParams
//
//*****************************************************************************
#define ESI_PSM_CNT1_DISABLE 0x0
#define ESI_PSM_CNT1_ENABLE ESICNT1EN

//*****************************************************************************
//
//The following are values that can be passed to
//count1Reset parameter in ESI_PSM_InitParams
//
//*****************************************************************************
#define ESI_PSM_CNT1_NO_RESET 0x0
#define ESI_PSM_CNT1_RESET ESICNT1RST

//*****************************************************************************
//
//The following are values that can be passed to
//count2Select parameter in ESI_PSM_InitParams
//
//*****************************************************************************
#define ESI_PSM_CNT2_DISABLE 0x0
#define ESI_PSM_CNT2_ENABLE ESICNT2EN

//*****************************************************************************
//
//The following are values that can be passed to
//count2Reset parameter in ESI_PSM_InitParams
//
//*****************************************************************************
#define ESI_PSM_CNT2_NO_RESET 0x0
#define ESI_PSM_CNT2_RESET ESICNT2RST

//*****************************************************************************
//
//The following are values that can be passed to
//V2Select parameter in ESI_PSM_InitParams
//
//*****************************************************************************
#define ESI_PSM_S3_SELECT   0x0
#define ESI_PSM_Q0_SELECT   ESIV2SEL

//*****************************************************************************
//
//The following are values that can be passed to
//TEST4Select parameter in ESI_PSM_InitParams
//
//*****************************************************************************
#define ESI_PSM_TEST4_IS_Q2         0x0
#define ESI_PSM_TEST4_IS_Q1         ESITEST4SEL0
#define ESI_PSM_TEST4_IS_TSM_CLK    ESITEST4SEL1
#define ESI_PSM_TEST4_IS_AFE1_COMPARATOR   ESITEST4SEL0 + ESITEST4SEL1

typedef struct ESI_PSM_InitParams
{
    uint16_t Q6Select;
    uint16_t Q7TriggerSelect;
    uint16_t count0Select;
    uint16_t count0Reset;
    uint16_t count1Select;
    uint16_t count1Reset;
    uint16_t count2Select;
    uint16_t count2Reset;
    uint16_t V2Select;
    uint16_t TEST4Select;
} ESI_PSM_InitParams;

extern const ESI_PSM_InitParams ESI_PSM_INITPARAMS_DEFAULT;

void ESI_PSM_init(ESI_PSM_InitParams *params);

void ESI_PSM_clearTable(void);
void ESI_PSM_copyTable(uint8_t * psmTable,
                       uint8_t size);

//*****************************************************************************
//
//The following are values that can be passed to
//counterToReset parameter in ESI_PSM_counterReset
//
//*****************************************************************************
#define ESI_PSM_CNT0_RST    ESICNT0RST
#define ESI_PSM_CNT1_RST    ESICNT1RST
#define ESI_PSM_CNT2_RST    ESICNT2RST

void ESI_PSM_resetCounter(uint16_t counterToReset);

//*****************************************************************************
//
//The following are values that can be passed to
//testCycleInsertion parameter in ESI_InitParams
//
//*****************************************************************************
#define ESI_TEST_CYCLE_INSERTION_DISABLE    0x0
#define ESI_TEST_CYCLE_INSERTION_ENABLE     ESITESTD

//*****************************************************************************
//
//The following are values that can be passed to
//timerAInputSelection parameter in ESI_InitParams
//
//*****************************************************************************
#define ESI_TIMERA_INPUT_TSM_COMPOUT    0x0
#define ESI_TIMERA_INPUT_TSM_PPUSRC     ESICS

//*****************************************************************************
//
//The following are values that can be passed to
//testChannel0Select parameter in ESI_InitParams
//
//*****************************************************************************
#define ESI_TEST_CHANNEL0_SOURCE_IS_CH0_CI0 0x0
#define ESI_TEST_CHANNEL0_SOURCE_IS_CH1_CI1 ESITCH00
#define ESI_TEST_CHANNEL0_SOURCE_IS_CH2_CI2 ESITCH01
#define ESI_TEST_CHANNEL0_SOURCE_IS_CH3_CI3 ESITCH00 + ESITCH01

//*****************************************************************************
//
//The following are values that can be passed to
//testChannel1Select parameter in ESI_InitParams
//
//*****************************************************************************
#define ESI_TEST_CHANNEL1_SOURCE_IS_CH0_CI0 0x0
#define ESI_TEST_CHANNEL1_SOURCE_IS_CH1_CI1 ESITCH10
#define ESI_TEST_CHANNEL1_SOURCE_IS_CH2_CI2 ESITCH11
#define ESI_TEST_CHANNEL1_SOURCE_IS_CH3_CI3 ESITCH10 + ESITCH11

//*****************************************************************************
//
//The following are values that can be passed to
//internalOscSelect parameter in ESI_InitParams
//
//*****************************************************************************
#define ESI_INTERNAL_OSC_DISABLE    0x0
#define ESI_INTERNAL_OSC_ENABLE     ESIHFSEL

//*****************************************************************************
//
//The following are values that can be passed to
//sourceNum parameter in ESI_psmSourceSelect
//
//*****************************************************************************
#define PSM_S1_SOURCE   1
#define PSM_S2_SOURCE   2
#define PSM_S3_SOURCE   3

//*****************************************************************************
//
//The following are values that can be passed to
//sourceSelect parameter in ESI_psmSourceSelect
//
//*****************************************************************************
#define ESI_PSM_SOURCE_IS_ESIOUT0    0
#define ESI_PSM_SOURCE_IS_ESIOUT1    1
#define ESI_PSM_SOURCE_IS_ESIOUT2    2
#define ESI_PSM_SOURCE_IS_ESIOUT3    3
#define ESI_PSM_SOURCE_IS_ESIOUT4    4
#define ESI_PSM_SOURCE_IS_ESIOUT5    5
#define ESI_PSM_SOURCE_IS_ESIOUT6    6
#define ESI_PSM_SOURCE_IS_ESIOUT7    7

void ESI_timerAInputSelect(uint16_t select);
void ESI_psmSourceSelect(uint16_t sourceNum,
                         uint16_t sourceSelect);
void ESI_testChannel0SourceSelect(uint16_t sourceSelect);
void ESI_testChannel1SourceSelect(uint16_t sourceSelect);
void ESI_enable(void);
void ESI_disable(void);

void ESI_enableInternalOscillator();
void ESI_disableInternalOscillator();
void ESI_startInternalOscCal(void);
void ESI_stopInternalOscCal(void);

//*****************************************************************************
//
//The following are values that can be passed to
//oversample parameter in ESI_measureESIOSCOversample
//
//*****************************************************************************
#define ESI_ESIOSC_NO_OVERSAMPLE                        0
#define ESI_ESIOSC_OVERSAMPLE_2                         2
#define ESI_ESIOSC_OVERSAMPLE_4                         4
#define ESI_ESIOSC_OVERSAMPLE_8                         8
uint16_t ESI_measureESIOSC(uint8_t oversample);
uint8_t ESI_getESICLKFQ(void);

//*****************************************************************************
//
//The following are values that can be passed to
//incOrDec parameter in ESI_adjustInternalOscFreq
//
//*****************************************************************************
#define ESI_INTERNAL_OSC_FREQ_DECREASE  0x0
#define ESI_INTERNAL_OSC_FREQ_INCREASE  0x1

void ESI_adjustInternalOscFreq(uint16_t incOrDec);
void ESI_setNominalInternalOscFreq(void);
void ESI_calibrateInternalOscFreq(uint16_t targetAclkCounts);
void ESI_setPSMCounter1IncreaseThreshold(uint16_t threshold);

void ESI_setPSMCounter1DecreaseThreshold(uint16_t threshold);

//*****************************************************************************
//
//The following are values that can be passed to
//resultNum parameter in ESI_getConversionResult
//
//*****************************************************************************
#define ESI_CONVERSION_RESULT_1 ESIADMEM1
#define ESI_CONVERSION_RESULT_2 ESIADMEM2
#define ESI_CONVERSION_RESULT_3 ESIADMEM3
#define ESI_CONVERSION_RESULT_4 ESIADMEM4

uint16_t ESI_getConversionResult(uint16_t resultNum);

//*****************************************************************************
//
//The following are values that can be passed to
//dacRegNum parameter in ESI_setAFE1DACValue and ESI_getAFE1DACValue
//
//*****************************************************************************
#define ESI_DAC1_REG0   0
#define ESI_DAC1_REG1   1
#define ESI_DAC1_REG2   2
#define ESI_DAC1_REG3   3
#define ESI_DAC1_REG4   4
#define ESI_DAC1_REG5   5
#define ESI_DAC1_REG6   6
#define ESI_DAC1_REG7   7

void ESI_setAFE1DACValue(uint16_t dacValue,
                         uint8_t dacRegNum);
uint16_t ESI_getAFE1DACValue(uint8_t dacRegNum);

//*****************************************************************************
//
//The following are values that can be passed to
//dacRegNum parameter in ESI_setAFE2DACValue and ESI_getAFE2DACValue
//
//*****************************************************************************
#define ESI_DAC2_REG0   0
#define ESI_DAC2_REG1   1
#define ESI_DAC2_REG2   2
#define ESI_DAC2_REG3   3
#define ESI_DAC2_REG4   4
#define ESI_DAC2_REG5   5
#define ESI_DAC2_REG6   6
#define ESI_DAC2_REG7   7

void ESI_setAFE2DACValue(uint16_t dacValue,
                         uint8_t dacRegNum);
uint16_t ESI_getAFE2DACValue(uint8_t dacRegNum);

//*****************************************************************************
//
//The following are values that can be passed to
//stateRegNum parameter in ESI_setTSMstateReg
//
//*****************************************************************************
#define ESI_TSM_STATE_REG_0 0
#define ESI_TSM_STATE_REG_1 1
#define ESI_TSM_STATE_REG_2 2
#define ESI_TSM_STATE_REG_3 3
#define ESI_TSM_STATE_REG_4 4
#define ESI_TSM_STATE_REG_5 5
#define ESI_TSM_STATE_REG_6 6
#define ESI_TSM_STATE_REG_7 7
#define ESI_TSM_STATE_REG_8 8
#define ESI_TSM_STATE_REG_9 9
#define ESI_TSM_STATE_REG_10 10
#define ESI_TSM_STATE_REG_11 11
#define ESI_TSM_STATE_REG_12 12
#define ESI_TSM_STATE_REG_13 13
#define ESI_TSM_STATE_REG_14 14
#define ESI_TSM_STATE_REG_15 15
#define ESI_TSM_STATE_REG_16 16
#define ESI_TSM_STATE_REG_17 17
#define ESI_TSM_STATE_REG_18 18
#define ESI_TSM_STATE_REG_19 19
#define ESI_TSM_STATE_REG_20 20
#define ESI_TSM_STATE_REG_21 21
#define ESI_TSM_STATE_REG_22 22
#define ESI_TSM_STATE_REG_23 23
#define ESI_TSM_STATE_REG_24 24
#define ESI_TSM_STATE_REG_25 25
#define ESI_TSM_STATE_REG_26 26
#define ESI_TSM_STATE_REG_27 27
#define ESI_TSM_STATE_REG_28 28
#define ESI_TSM_STATE_REG_29 29
#define ESI_TSM_STATE_REG_30 30
#define ESI_TSM_STATE_REG_31 31

//*****************************************************************************
//
//The following are values that can be passed to
//inputChannelSelect parameter in ESI_TSM_StateParams
//
//*****************************************************************************
#define ESI_TSM_STATE_CHANNEL_SELECT_CH0 0
#define ESI_TSM_STATE_CHANNEL_SELECT_CH1 ESICH0
#define ESI_TSM_STATE_CHANNEL_SELECT_CH2 ESICH1
#define ESI_TSM_STATE_CHANNEL_SELECT_CH3 (ESICH1 | ESICH0)

//*****************************************************************************
//
//The following are values that can be passed to
//LCDampingSelect parameter in ESI_TSM_StateParams
//
//*****************************************************************************
#define ESI_TSM_STATE_LC_DAMPING_DISABLE  0x0
#define ESI_TSM_STATE_LC_DAMPING_ENABLE  ESILCEN

//*****************************************************************************
//
//The following are values that can be passed to
//excitationSelect parameter in ESI_TSM_StateParams
//
//*****************************************************************************
#define ESI_TSM_STATE_EXCITATION_DISABLE    0x0
#define ESI_TSM_STATE_EXCITATION_ENABLE     ESIEX

//*****************************************************************************
//
//The following are values that can be passed to
//comparatorSelect parameter in ESI_TSM_StateParams
//
//*****************************************************************************
#define ESI_TSM_STATE_COMPARATOR_DISABLE    0x0
#define ESI_TSM_STATE_COMPARATOR_ENABLE     ESICA

//*****************************************************************************
//
//The following are values that can be passed to
//highFreqClkOn_or_compAutoZeroCycle parameter in ESI_TSM_StateParams
//
//*****************************************************************************
#define ESI_TSM_STATE_HIGH_FREQ_CLK_ON        0x0
#define ESI_TSM_STATE_COMP_AUTOZERO_CYCLE     ESICLKON

//*****************************************************************************
//
//The following are values that can be passed to
//outputLatchSelect parameter in ESI_TSM_StateParams
//
//*****************************************************************************
#define ESI_TSM_STATE_OUTPUT_LATCH_DISABLE  0x0
#define ESI_TSM_STATE_OUTPUT_LATCH_ENABLE   ESIRSON

//*****************************************************************************
//
//The following are values that can be passed to
//testCycleSelect parameter in ESI_TSM_StateParams
//
//*****************************************************************************
#define ESI_TSM_STATE_TEST_CYCLE_DISABLE    0x0
#define ESI_TSM_STATE_TEST_CYCLE_ENABLE     ESITESTS1

//*****************************************************************************
//
//The following are values that can be passed to
//dacSelect parameter in ESI_TSM_StateParams
//
//*****************************************************************************
#define ESI_TSM_STATE_DAC_DISABLE   0x0
#define ESI_TSM_STATE_DAC_ENABLE    ESIDAC

//*****************************************************************************
//
//The following are values that can be passed to
//tsmStop parameter in ESI_TSM_StateParams
//
//*****************************************************************************
#define ESI_TSM_STATE_CONTINUE  0x0
#define ESI_TSM_STATE_STOP      ESISTOP

//*****************************************************************************
//
//The following are values that can be passed to
//tsmClkSrc parameter in ESI_TSM_StateParams
//
//*****************************************************************************
#define ESI_TSM_STATE_HIGH_FREQ_CLK 0x0
#define ESI_TSM_STATE_ACLK          ESICLK

//*****************************************************************************
//
//Values between these min and max can be pased to
//duration parameter in ESI_TSM_StateParams
//
//*****************************************************************************
#define ESI_TSM_STATE_DURATION_MIN  0x00
#define ESI_TSM_STATE_DURATION_MAX  0x1F

typedef struct ESI_TSM_StateParams
{
    uint16_t inputChannelSelect;
    uint16_t LCDampingSelect;
    uint16_t excitationSelect;
    uint16_t comparatorSelect;
    uint16_t highFreqClkOn_or_compAutoZeroCycle;
    uint16_t outputLatchSelect;
    uint16_t testCycleSelect;
    uint16_t dacSelect;
    uint16_t tsmStop;
    uint16_t tsmClkSrc;
    uint16_t duration;
} ESI_TSM_StateParams;

void ESI_setTSMstateReg(ESI_TSM_StateParams *params,
                        uint8_t stateRegNum);

uint16_t ESIgetInterruptVectorRegister(void);

//*****************************************************************************
//
//The following values can be be used to form the interrupt mask for
//ESI_enableInterrupt and ESI_disableInterrupt
//
//*****************************************************************************
#define ESI_INTERRUPT_AFE1_ESIOUTX \
    ESIIE0
#define ESI_INTERRUPT_ESISTOP                                       ESIIE1
#define ESI_INTERRUPT_ESISTART                                      ESIIE2
#define ESI_INTERRUPT_ESICNT1                                       ESIIE3
#define ESI_INTERRUPT_ESICNT2                                       ESIIE4
#define ESI_INTERRUPT_Q6_BIT_SET                                    ESIIE5
#define ESI_INTERRUPT_Q7_BIT_SET                                    ESIIE6
#define ESI_INTERRUPT_ESICNT0_COUNT_INTERVAL                ESIIE7
#define ESI_INTERRUPT_AFE2_ESIOUTX \
    ESIIE8

void ESI_enableInterrupt(uint16_t interruptMask);
void ESI_disableInterrupt(uint16_t interruptMask);

//*****************************************************************************
//
//Return values for ESI_getInterruptStatus
//
//*****************************************************************************
#define ESI_INTERRUPT_FLAG_AFE1_ESIOUTX                             ESIIFG0
#define ESI_INTERRUPT_FLAG_ESISTOP                                      ESIIFG1
#define ESI_INTERRUPT_FLAG_ESISTART                                     ESIIFG2
#define ESI_INTERRUPT_FLAG_ESICNT1                                      ESIIFG3
#define ESI_INTERRUPT_FLAG_ESICNT2                                      ESIIFG4
#define ESI_INTERRUPT_FLAG_Q6_BIT_SET                           ESIIFG5
#define ESI_INTERRUPT_FLAG_Q7_BIT_SET                           ESIIFG6
#define ESI_INTERRUPT_FLAG_ESICNT0_COUNT_INTERVAL               ESIIFG7
#define ESI_INTERRUPT_FLAG_AFE2_ESIOUTX                                 ESIIFG8

uint16_t ESI_getInterruptStatus(uint16_t interruptMask);
void ESI_clearInterrupt(uint16_t interruptMask);

//*****************************************************************************
//
//Values for ifg0Src in ESI_setIFG0Source
//
//*****************************************************************************
#define ESI_IFG0_SET_WHEN_ESIOUT0_SET       ESIIFGSET1_0
#define ESI_IFG0_SET_WHEN_ESIOUT0_RESET     ESIIFGSET1_1
#define ESI_IFG0_SET_WHEN_ESIOUT1_SET       ESIIFGSET1_2
#define ESI_IFG0_SET_WHEN_ESIOUT1_RESET     ESIIFGSET1_3
#define ESI_IFG0_SET_WHEN_ESIOUT2_SET       ESIIFGSET1_4
#define ESI_IFG0_SET_WHEN_ESIOUT2_RESET     ESIIFGSET1_5
#define ESI_IFG0_SET_WHEN_ESIOUT3_SET       ESIIFGSET1_6
#define ESI_IFG0_SET_WHEN_ESIOUT3_RESET     ESIIFGSET1_7

void ESI_setIFG0Source(uint16_t ifg0Src);

//*****************************************************************************
//
//Values for ifg8Src in ESI_setIFG8Source
//
//*****************************************************************************
#define ESI_IFG8_SET_WHEN_ESIOUT4_SET       ESIIFGSET2_0
#define ESI_IFG8_SET_WHEN_ESIOUT4_RESET     ESIIFGSET2_1
#define ESI_IFG8_SET_WHEN_ESIOUT5_SET       ESIIFGSET2_2
#define ESI_IFG8_SET_WHEN_ESIOUT5_RESET     ESIIFGSET2_3
#define ESI_IFG8_SET_WHEN_ESIOUT6_SET       ESIIFGSET2_4
#define ESI_IFG8_SET_WHEN_ESIOUT6_RESET     ESIIFGSET2_5
#define ESI_IFG8_SET_WHEN_ESIOUT7_SET       ESIIFGSET2_6
#define ESI_IFG8_SET_WHEN_ESIOUT7_RESET     ESIIFGSET2_7

void ESI_setIFG8Source(uint16_t ifg8Src);

//*****************************************************************************
//
//Values for ifg7Src in ESI_setIFG7Source
//
//*****************************************************************************
#define ESI_IFG7_SOURCE_EVERY_COUNT_OF_CNT0     ESIIS0_0
#define ESI_IFG7_SOURCE_CNT0_MOD4               ESIIS0_1
#define ESI_IFG7_SOURCE_CNT0_MOD256             ESIIS0_2
#define ESI_IFG7_SOURCE_CNT0_ROLLOVER           ESIIS0_3

void ESI_setIFG7Source(uint16_t ifg7Src);

//*****************************************************************************
//
//Values for ifg4Src in ESI_setIFG4Source
//
//*****************************************************************************
#define ESI_IFG4_SOURCE_EVERY_COUNT_OF_CNT2     ESIIS2_0
#define ESI_IFG4_SOURCE_CNT2_MOD4               ESIIS2_1
#define ESI_IFG4_SOURCE_CNT2_MOD256             ESIIS2_2
#define ESI_IFG4_SOURCE_CNT2_ROLLOVER           ESIIS2_3

void ESI_setIFG4Source(uint16_t ifg4Src);

void ESI_setPSMCounter1UpperThreshold(uint16_t threshold);
void ESI_setPSMCounter1LowerThreshold(uint16_t threshold);

//*****************************************************************************
//
// Set correct DAC values for LC sensors
//
//*****************************************************************************
void ESI_LC_DAC_calibration(uint8_t selected_channel);

//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif

#endif
#endif