-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcy_capsense_selftest_v2.c
4514 lines (4178 loc) · 204 KB
/
cy_capsense_selftest_v2.c
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
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***************************************************************************//**
* \file cy_capsense_selftest_v2.c
* \version 5.0
*
* \brief
* This file provides the source code to the Built-in Self-test (BIST)
* functions.
*
********************************************************************************
* \copyright
* Copyright 2019-2024, Cypress Semiconductor Corporation (an Infineon company)
* or an affiliate of Cypress Semiconductor Corporation. All rights reserved.
* You may use this file only in accordance with the license, terms, conditions,
* disclaimers, and limitations in the end user license agreement accompanying
* the software package with which this file was provided.
*******************************************************************************/
#include <stddef.h>
#include <string.h>
#include "cycfg_capsense_defines.h"
#include "cy_syslib.h"
#include "cy_capsense_common.h"
#include "cy_capsense_structure.h"
#include "cy_capsense_sensing.h"
#include "cy_capsense_sensing_v2.h"
#include "cy_capsense_lib.h"
#include "cy_capsense_selftest_v2.h"
#include "cy_gpio.h"
#if (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2))
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_BIST_EN)
/*******************************************************************************
* Common local definitions for self-test
*******************************************************************************/
/* Port Data Register macros for BIST */
#define CY_CAPSENSE_BIST_DR_PIN2GND (0u)
#define CY_CAPSENSE_BIST_DR_PIN2VDD (1u)
#define CY_CAPSENSE_BIST_CP_MAX_VALUE (400000u)
#define CY_CAPSENSE_BIST_PROMILLE_FACTOR (1000u)
#define CY_CAPSENSE_BIST_SNS_CLK_MIN_DIVIDER (4u)
#define CY_CAPSENSE_BIST_SNS_CLK_MAX_DIVIDER (4096u)
/* Macros for the electrode capacitance measurement test */
#define CY_CAPSENSE_BIST_ELTD_CAP_MAX_RAW_PROMILLE (450u)
#define CY_CAPSENSE_BIST_ELTD_CAP_MIN_RAW_PROMILLE (75u)
#define CY_CAPSENSE_BIST_ELTD_CAP_MAX_RESOLUTION (15u)
#define CY_CAPSENSE_BIST_ELTD_CAP_MIN_RESOLUTION (8u)
#define CY_CAPSENSE_BIST_ELTD_CAP_CYCLES_NUM (4u)
#define CY_CAPSENSE_BIST_ELTD_CAP_MAX_MODCLK (50000000u)
#define CY_CAPSENSE_BIST_SW_DSI_SEL_DEFAULT (0x00000000uL)
/* IDAC register mask */
#define CY_CAPSENSE_BIST_IDAC_BITS_TO_WRITE (CSD_IDACA_VAL_Msk |\
CSD_IDACA_RANGE_Msk |\
CSD_IDACA_LEG1_EN_Msk |\
CSD_IDACA_LEG2_EN_Msk |\
CSD_IDACA_LEG1_MODE_Msk |\
CSD_IDACA_LEG2_MODE_Msk)
#define CY_CAPSENSE_BIST_FSM_AZ0_SKIP (0x100u)
#define CY_CAPSENSE_BIST_FSM_AZ1_SKIP (0x200u)
/*******************************************************************************
* Macros for the external capacitor capacitance measurement test
*******************************************************************************/
#define CY_CAPSENSE_BIST_CAP_MEAS_DUTY_WIDTH (10u)
#define CY_CAPSENSE_BIST_CAP_MEAS_MAX_MODCLK (12500000u)
#define CY_CAPSENSE_BIST_CAP_MEAS_ACCURACY_FACTOR (1150u)
#define CY_CAPSENSE_BIST_CAP_MEAS_MIN_RAWCOUNT (10u)
#define CY_CAPSENSE_BIST_CAP_MEAS_MAX_CAP (25u)
#define CY_CAPSENSE_BIST_CAP_MEAS_CMOD_MAX_VALUE (5u)
#define CY_CAPSENSE_BIST_CAP_MEAS_CINT_MAX_VALUE (1u)
#define CY_CAPSENSE_BIST_CAP_MEAS_CSH_MAX_VALUE (20u)
#define CY_CAPSENSE_BIST_CAP_MEAS_VREF_MV_DEFAULT (1200u)
#define CY_CAPSENSE_BIST_CAP_MEAS_WDT_CYCLES_PER_LOOP (5u)
#define CY_CAPSENSE_BIST_CAP_MEAS_WDT_TIMEOUT (3000u)
#define CY_CAPSENSE_BIST_PRECHARGE_MAX_TIME_US (6000u)
#define CY_CAPSENSE_BIST_WATCHDOG_MARGIN_COEFF (3u)
#define CY_CAPSENSE_BIST_PRECHARGE_WATCHDOG_TIME_US (CY_CAPSENSE_BIST_PRECHARGE_MAX_TIME_US *\
CY_CAPSENSE_BIST_WATCHDOG_MARGIN_COEFF)
/* HW block register values */
#define CY_CAPSENSE_BIST_CAP_SEQ_START_DEFAULT (CY_CAPSENSE_CSD_SEQ_START_AZ0_SKIP_MSK | \
CY_CAPSENSE_CSD_SEQ_START_AZ1_SKIP_MSK | \
CY_CAPSENSE_CSD_SEQ_START_START_MSK)
#define CY_CAPSENSE_BIST_CAP_CSDCMP_DEFAULT (CY_CAPSENSE_CSD_CSDCMP_CMP_PHASE_PHI2_MSK | \
CY_CAPSENSE_CSD_CSDCMP_CSDCMP_EN_MSK)
#define CY_CAPSENSE_BIST_CAP_SENSE_DUTY_DEFAULT (CSD_SENSE_DUTY_OVERLAP_PHI1_Msk | \
CSD_SENSE_DUTY_OVERLAP_PHI2_Msk | \
CY_CAPSENSE_BIST_CAP_MEAS_DUTY_WIDTH)
#define CY_CAPSENSE_BIST_CAP_SW_BYP_SEL_DEFAULT (CY_CAPSENSE_CSD_SW_BYP_SEL_SW_BYA_MSK)
#define CY_CAPSENSE_BIST_CAP_SW_CMP_N_SEL_DEFAULT (CY_CAPSENSE_CSD_SW_CMP_N_SEL_SW_SCRH_STATIC_CLOSE)
#define CY_CAPSENSE_BIST_CAP_SW_CMP_P_SEL_DEFAULT (CY_CAPSENSE_CSD_SW_CMP_P_SEL_SW_SFMA_STATIC_CLOSE)
#define CY_CAPSENSE_BIST_CAP_SW_REFGEN_SEL_SRSS_DEFAULT (CY_CAPSENSE_CSD_SW_REFGEN_SEL_SW_SGR_MSK)
#if (CY_CAPSENSE_PSOC6_FOURTH_GEN)
#define CY_CAPSENSE_BIST_CAP_SW_REFGEN_SEL_PASS_DEFAULT (CY_CAPSENSE_CSD_SW_REFGEN_SEL_SW_SGRP_MSK)
#define CY_CAPSENSE_BIST_CAP_IO_SEL_DEFAULT (CY_CAPSENSE_CSD_TX_N_OUT_EN_PHI1 | \
CY_CAPSENSE_CSD_TX_N_AMUXA_EN_PHI2)
#endif
#define CY_CAPSENSE_BIST_CAP_REFGEN_DEFAULT (CSD_REFGEN_REFGEN_EN_Msk | CSD_REFGEN_RES_EN_Msk)
#define CY_CAPSENSE_BIST_CAP_REFGEN_LOW_VOLTAGE_DEFAULT (CSD_REFGEN_REFGEN_EN_Msk | CSD_REFGEN_BYPASS_Msk)
#define CY_CAPSENSE_BIST_CAP_CONFIG_DEFAULT (CY_CAPSENSE_CSD_CONFIG_FILTER_DELAY_48MHZ | \
CSD_CONFIG_SENSE_EN_Msk | \
CSD_CONFIG_ENABLE_Msk)
#if (CY_CAPSENSE_PSOC6_FOURTH_GEN)
#define CY_CAPSENSE_BIST_CAP_CONFIG_IREF_DEFAULT (CY_CAPSENSE_BIST_CAP_CONFIG_DEFAULT | \
CY_CAPSENSE_CSD_CONFIG_IREF_SEL_MSK)
#endif
#define CY_CAPSENSE_BIST_CAP_IDAC_MODE_DEFAULT (CSD_IDACA_LEG1_MODE_Msk |\
CSD_IDACA_LEG2_MODE_Msk)
/*******************************************************************************
* Macros for the VDDA measurement test
*******************************************************************************/
/* SenseClkDivider value for VDDA measurement mode */
#define CY_CAPSENSE_BIST_VDDA_SENSE_DIV_DEFAULT (0x4u)
/* Minimal acceptable difference between the VDDA and VREF.
It is not allowed to have (VDDA - VREF) > CY_CAPSENSE_BIST_VDDA_MIN_DIFF. */
#define CY_CAPSENSE_BIST_VDDA_MIN_DIFF (600u)
/* VREF voltage value, used for the VDDA measurement */
#define CY_CAPSENSE_BIST_VDDA_VREF_MIN_MV (1200u)
/* VDDA measurement resolution */
#define CY_CAPSENSE_BIST_VDDA_RES (2047u)
/* The total capacitance value of reference capacitors */
#define CY_CAPSENSE_BIST_VDDA_CREF (21500u)
/* The IDAC gain value, used for the VDDA measurement */
#define CY_CAPSENSE_BIST_VDDA_IDAC_LSB (37500u)
/* The MAX possible IDAC code value. */
#define CY_CAPSENSE_BIST_IDAC_MAX (127u)
/* The number of initial conversions per sample, used for the VDDA measurement */
#define CY_CAPSENSE_BIST_VDDA_INIT_CYCLES_NUM (1u)
/* The number of normal conversions per sample, used for the VDDA measurement */
#define CY_CAPSENSE_BIST_VDDA_NORM_CYCLES_NUM (2u)
/* The duration of the Auto-zero stage in microseconds */
#define CY_CAPSENSE_BIST_VDDA_AZ_TIME_US (5u)
/* Acquisition time in microseconds */
#define CY_CAPSENSE_BIST_VDDA_ACQ_TIME_US (10u)
/* Acquisition time in microseconds */
#define CY_CAPSENSE_BIST_VDDA_MAX_MODCLK (50000000u)
/* Configures the count time A to bring Cref1 + Cref2 up from Vssa to Vrefhi with IDACB */
#define CY_CAPSENSE_BIST_VDDA_MEASMODE_VREF (0x1uL << CSD_ADC_CTL_ADC_MODE_Pos)
/*
* Configures count time B to bring Cref1 + Cref2 back up to Vrefhi with IDACB
* (after bringing them down for time A/2 cycles with IDACB sinking)
*/
#define CY_CAPSENSE_BIST_VDDA_MEASMODE_VREFBY2 (0x2uL << CSD_ADC_CTL_ADC_MODE_Pos)
/* Configures the HSCMP polarity and count time C to source/sink Cref1 + Cref2 from Vin to Vrefhi */
#define CY_CAPSENSE_BIST_VDDA_MEASMODE_VIN (0x3uL << CSD_ADC_CTL_ADC_MODE_Pos)
/* Default HW block operation settings that are required for VDDA measurement */
#define CY_CAPSENSE_BIST_VDDA_CONFIG_DEFAULT (CY_CAPSENSE_CSD_CONFIG_ENABLE_MSK |\
CY_CAPSENSE_CSD_CONFIG_SAMPLE_SYNC_MSK |\
CY_CAPSENSE_CSD_CONFIG_SENSE_EN_MSK |\
CY_CAPSENSE_CSD_CONFIG_DSI_COUNT_SEL_MSK)
#define CY_CAPSENSE_BIST_VDDA_AMBUF_DEFAULT (0u)
#define CY_CAPSENSE_BIST_VDDA_CSDCMP_DEFAULT (0u)
#define CY_CAPSENSE_BIST_VDDA_HSCMP_DEFAULT (CY_CAPSENSE_CSD_HSCMP_HSCMP_EN_MSK |\
CY_CAPSENSE_CSD_HSCMP_AZ_EN_MSK)
#define CY_CAPSENSE_BIST_VDDA_IDACA_DEFAULT (0u)
#define CY_CAPSENSE_BIST_VDDA_IDACB_DEFAULT ((CY_CAPSENSE_CSD_IDACB_POL_DYN_DYNAMIC << \
CY_CAPSENSE_CSD_IDACB_POL_DYN_POS) |\
CY_CAPSENSE_CSD_IDACB_LEG3_EN_MSK)
#define CY_CAPSENSE_BIST_VDDA_SW_RES_DEFAULT (0u)
#define CY_CAPSENSE_BIST_VDDA_SENSE_PERIOD_DEFAULT (CY_CAPSENSE_BIST_VDDA_SENSE_DIV_DEFAULT)
#define CY_CAPSENSE_BIST_VDDA_SENSE_DUTY_DEFAULT (0u)
#define CY_CAPSENSE_BIST_VDDA_SEQ_INIT_CNT_DEFAULT (CY_CAPSENSE_BIST_VDDA_INIT_CYCLES_NUM)
#define CY_CAPSENSE_BIST_VDDA_SEQ_NORM_CNT_DEFAULT (CY_CAPSENSE_BIST_VDDA_NORM_CYCLES_NUM)
#define CY_CAPSENSE_BIST_VDDA_IO_SEL_DEFAULT (0u)
#define CY_CAPSENSE_BIST_VDDA_SEQ_START_MEASURE (CY_CAPSENSE_CSD_SEQ_START_AZ0_SKIP_MSK |\
CY_CAPSENSE_CSD_SEQ_START_START_MSK)
#define CY_CAPSENSE_BIST_VDDA_SW_HS_P_SEL_DEFAULT (CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMRH_STATIC_CLOSE)
#define CY_CAPSENSE_BIST_VDDA_SW_HS_N_SEL_DEFAULT (CY_CAPSENSE_CSD_SW_HS_N_SEL_SW_HCCD_STATIC_CLOSE)
#define CY_CAPSENSE_BIST_VDDA_SW_SHIELD_SEL_DEFAULT (0u)
#define CY_CAPSENSE_BIST_VDDA_SW_AMUXBUF_SEL_DEFAULT (0u)
#define CY_CAPSENSE_BIST_VDDA_SW_BYP_SEL_DEFAULT (0u)
#define CY_CAPSENSE_BIST_VDDA_SW_CMP_P_SEL_DEFAULT (0u)
#define CY_CAPSENSE_BIST_VDDA_SW_CMP_N_SEL_DEFAULT (0u)
#define CY_CAPSENSE_BIST_VDDA_SW_DSI_SEL_DEFAULT (0u)
#define CY_CAPSENSE_BIST_VDDA_SW_FW_MOD_SEL_DEFAULT (CY_CAPSENSE_CSD_SW_FW_MOD_SEL_SW_C1CC_STATIC_CLOSE |\
CY_CAPSENSE_CSD_SW_FW_MOD_SEL_SW_C1CD_STATIC_CLOSE)
#define CY_CAPSENSE_BIST_VDDA_SW_FW_TANK_SEL_DEFAULT (CY_CAPSENSE_CSD_SW_FW_TANK_SEL_SW_C2CC_STATIC_CLOSE |\
CY_CAPSENSE_CSD_SW_FW_TANK_SEL_SW_C2CD_STATIC_CLOSE)
#define CY_CAPSENSE_BIST_VDDA_WDT_CYCLES_PER_LOOP (5u)
#define CY_CAPSENSE_BIST_VDDA_MAX_16_BITS (65535u)
/* In milliseconds */
#define CY_CAPSENSE_BIST_VDDA_WDT_TIMEOUT (10000u)
/*******************************************************************************
* Function Prototypes
*******************************************************************************/
/******************************************************************************/
/** \cond SECTION_CAPSENSE_INTERNAL */
/** \addtogroup group_capsense_internal *//** \{ */
/******************************************************************************/
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_WDGT_CRC_EN)
/* CRC test-related functions */
static cy_en_capsense_bist_status_t Cy_CapSense_CheckAllWidgetCRC(
cy_stc_capsense_context_t * context);
#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_WDGT_CRC_EN) */
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_SHORT_EN)
/* Check Integrity Sensor Pins test-related functions */
static cy_en_capsense_bist_status_t Cy_CapSense_SnsShortCheckSensor(
uint32_t widgetId,
uint32_t sensorId,
uint32_t mode,
cy_stc_capsense_context_t * context);
static cy_en_capsense_bist_status_t Cy_CapSense_SnsShortCheckElectrode(
uint32_t widgetId,
uint32_t ioSnsId,
uint32_t mode,
const cy_stc_capsense_context_t * context);
static void Cy_CapSense_SnsShortUpdateTestResult(
uint32_t widgetId,
uint32_t sensorId,
cy_stc_capsense_context_t * context);
static cy_en_capsense_bist_status_t Cy_CapSense_SnsShortCheckAllSensors(
cy_stc_capsense_context_t * context);
#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_SHORT_EN) */
#if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SH_CAP_EN) ||\
(CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN))
/* Measure Capacitance Sensor and Shield test-related functions */
static void Cy_CapSense_BistMeasureCapacitanceSensorInit(
cy_stc_capsense_context_t * context);
static void Cy_CapSense_BistMeasureCapacitanceSensorEnable(
cy_stc_capsense_context_t * context);
static cy_en_capsense_bist_status_t Cy_CapSense_BistMeasureCapacitanceSensor(
uint32_t * cpPtr,
cy_stc_capsense_context_t * context);
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
static void Cy_CapSense_BistMeasureCapacitanceSensorShieldEnable(
cy_stc_capsense_context_t * context);
#endif
static cy_en_capsense_bist_status_t Cy_CapSense_BistMeasureCapacitanceSensorRun(
cy_stc_capsense_context_t * context);
#endif /* ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SH_CAP_EN) ||\
(CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN)) */
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN)
static cy_en_capsense_bist_status_t Cy_CapSense_BistMeasureCapacitanceSensorAll(
cy_stc_capsense_context_t * context);
#endif
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_EXTERNAL_CAP_EN)
/* Measure Capacitance Capacitor test-related functions */
static void Cy_CapSense_BistMeasureCapacitanceCapInit(
cy_stc_capsense_context_t * context);
static void Cy_CapSense_BistMeasureCapacitanceCapEnable(
cy_stc_capsense_context_t * context);
static cy_en_capsense_bist_status_t Cy_CapSense_BistMeasureCapacitanceCapRun(
uint32_t * ptrExtCapValue,
cy_stc_capsense_context_t * context);
static cy_en_capsense_bist_status_t Cy_CapSense_BistMeasureCapacitanceCapAll(
cy_stc_capsense_context_t * context);
#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_EXTERNAL_CAP_EN) */
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_VDDA_EN)
/* Measure VDDA test-related functions */
static void Cy_CapSense_BistMeasureVddaInit(
cy_stc_capsense_context_t * context);
static void Cy_CapSense_BistMeasureVddaEnable(
cy_stc_capsense_context_t * context);
static cy_en_capsense_bist_status_t Cy_CapSense_BistMeasureVddaRun(
cy_stc_capsense_context_t * context);
#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_VDDA_EN) */
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_SHORT_EN)
static void Cy_CapSense_SetPinDr(
cy_stc_capsense_pin_config_t const *ioPtr,
uint32_t value);
static void Cy_CapSense_SetPinPc(
cy_stc_capsense_pin_config_t const *ioPtr,
uint32_t value);
#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_SHORT_EN) */
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_HW_GROUP_EN)
/* Common functions for all hardware-dependent tests */
static void Cy_CapSense_BistSwitchHwConfig(
cy_en_capsense_bist_hw_config_t hwCfg,
cy_stc_capsense_context_t * context);
static void Cy_CapSense_BistSwitchAllSnsPinState(
cy_en_capsense_bist_io_state_t desiredPinState,
const cy_stc_capsense_context_t * context);
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
static void Cy_CapSense_BistSwitchAllShieldPinState(
cy_en_capsense_bist_io_state_t desiredPinState,
const cy_stc_capsense_context_t * context);
static void Cy_CapSense_SetShieldPinState(
uint32_t desiredDriveMode,
uint32_t desiredPinOutput,
en_hsiom_sel_t desiredHsiom,
const cy_stc_capsense_context_t * context);
#endif
static void Cy_CapSense_BistSwitchAllExternalCapPinState(
cy_en_capsense_bist_io_state_t desiredPinState,
const cy_stc_capsense_context_t * context);
#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_HW_GROUP_EN) */
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN)
static void Cy_CapSense_BistConnectElectrode(
uint32_t widgetId,
uint32_t electrodeId,
const cy_stc_capsense_context_t * context);
static void Cy_CapSense_BistDisconnectElectrode(
uint32_t widgetId,
uint32_t electrodeId,
const cy_stc_capsense_context_t * context);
#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN) */
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN) || \
(CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SH_CAP_EN) || \
(CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_EXTERNAL_CAP_EN)
static uint32_t Cy_CapSense_BistWaitEndOfScan(
uint32_t watchdogCycleNum,
const cy_stc_capsense_context_t * context);
#endif
/** \} \endcond */
/*******************************************************************************
* Function Name: Cy_CapSense_RunSelfTest_V2
****************************************************************************//**
*
* Runs built-in self-tests specified by the test enable mask.
*
* The function performs various self-tests on all the enabled widgets
* and sensors in the project. Select the required set of tests
* using the bit-mask in testEnMask parameter.
*
* Use CY_CAPSENSE_TST_RUN_SELF_TEST_MASK to execute all the self-tests or
* any combination of the masks (defined in testEnMask parameter) to specify the
* desired test list.
*
* To execute a single-element test (i.e. for one widget or one sensor),
* the following low-level functions are available:
* - Cy_CapSense_CheckCRCWidget()
* - Cy_CapSense_CheckIntegritySensorPins()
* - Cy_CapSense_MeasureCapacitanceSensor()
* - Cy_CapSense_MeasureCapacitanceShield()
* - Cy_CapSense_MeasureCapacitanceCap_V2()
* - Cy_CapSense_MeasureVdda()
*
* Refer to these functions descriptions for detail information
* on the corresponding test.
*
* \note
* This function is available only for the fourth-generation CAPSENSE™.
*
* \param testEnMask
* Specifies the tests to be executed. Each bit corresponds to one test. It is
* possible to launch the function with any combination of the available tests.
* - CY_CAPSENSE_BIST_CRC_WDGT_MASK - Verifies the RAM widget structure CRC
* for all the widgets.
* - CY_CAPSENSE_BIST_SNS_INTEGRITY_MASK - Checks all the sensor pins for a short
* to GND / VDD / other sensors.
* - CY_CAPSENSE_BIST_SNS_CAP_MASK - Measures all the sensors capacitance.
* - CY_CAPSENSE_BIST_SHIELD_CAP_MASK - Measures the shield capacitance.
* - CY_CAPSENSE_BIST_EXTERNAL_CAP_MASK - Measures the capacitance of the
* available external capacitors.
* - CY_CAPSENSE_BIST_VDDA_MASK - Measures the VDDA voltage.
* - CY_CAPSENSE_BIST_RUN_AVAILABLE_SELF_TEST_MASK
* - Executes all available tests.
*
* \param context
* The pointer to the CAPSENSE™ context structure \ref cy_stc_capsense_context_t.
*
* \return
* Returns a bit-mask with a status of execution of the specified tests:
* - CY_CAPSENSE_BIST_SUCCESS_E - All the tests passed successfully.
* - CY_CAPSENSE_BIST_BAD_PARAM_E - A non-defined test was requested in the
* testEnMask parameter or the context is
* a NULL pointer. The function
* was not performed.
* - CY_CAPSENSE_BIST_HW_BUSY_E - The CSD HW block is busy with a previous
* operation. The function was not performed.
* - CY_CAPSENSE_BIST_ERROR_E - An unexpected fault occurred during
* the measurement, you may need to repeat
* the measurement.
* - CY_CAPSENSE_BIST_FAIL_E - Any of tests specified by the testEnMask
* parameters has faulted.
*
*******************************************************************************/
cy_en_capsense_bist_status_t Cy_CapSense_RunSelfTest_V2(
uint32_t testEnMask,
cy_stc_capsense_context_t * context)
{
cy_en_capsense_bist_status_t result = CY_CAPSENSE_BIST_BAD_PARAM_E;
#if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_WDGT_CRC_EN) || \
((CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_HW_GROUP_EN) && \
((CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_VDDA_EN) || \
(CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_EXTERNAL_CAP_EN) || \
((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN) && \
(CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SH_CAP_EN)) || \
(CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_SHORT_EN) || \
(CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN))))
cy_en_capsense_bist_status_t bistStatus;
#endif
#if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_HW_GROUP_EN) && \
((CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_VDDA_EN) || \
((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN) && \
(CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SH_CAP_EN))))
uint32_t tmpVal;
#endif
if (0u == (testEnMask & (~CY_CAPSENSE_BIST_RUN_AVAILABLE_SELF_TEST_MASK)))
{
if (NULL != context)
{
if (CY_CAPSENSE_NOT_BUSY == Cy_CapSense_IsBusy(context))
{
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_WDGT_CRC_EN)
if (0u != (CY_CAPSENSE_BIST_CRC_WDGT_MASK & testEnMask))
{
bistStatus = Cy_CapSense_CheckAllWidgetCRC(context);
if (CY_CAPSENSE_BIST_SUCCESS_E != bistStatus)
{
result = CY_CAPSENSE_BIST_FAIL_E;
context->ptrBistContext->testResultMask |= CY_CAPSENSE_BIST_CRC_WDGT_MASK;
}
}
#endif
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_HW_GROUP_EN)
/* The next group of tests is hardware-dependent, the request is to switch the sense method */
if (CY_CAPSENSE_SUCCESS_E == Cy_CapSense_SwitchSensingMode(CY_CAPSENSE_BIST_GROUP, context))
{
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_VDDA_EN)
if (0u != (CY_CAPSENSE_BIST_VDDA_MASK & testEnMask))
{
bistStatus = Cy_CapSense_MeasureVdda_V2(&tmpVal, context);
if (CY_CAPSENSE_BIST_SUCCESS_E != bistStatus)
{
result = CY_CAPSENSE_BIST_FAIL_E;
context->ptrBistContext->testResultMask |= CY_CAPSENSE_BIST_VDDA_MASK;
}
}
#endif
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_EXTERNAL_CAP_EN)
if (0u != (CY_CAPSENSE_BIST_EXTERNAL_CAP_MASK & testEnMask))
{
bistStatus = Cy_CapSense_BistMeasureCapacitanceCapAll(context);
if (CY_CAPSENSE_BIST_SUCCESS_E != bistStatus)
{
result = CY_CAPSENSE_BIST_FAIL_E;
context->ptrBistContext->testResultMask |= CY_CAPSENSE_BIST_EXTERNAL_CAP_MASK;
}
}
#endif
#if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN) && \
(CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SH_CAP_EN))
if (0u != (CY_CAPSENSE_BIST_SHIELD_CAP_MASK & testEnMask))
{
bistStatus = Cy_CapSense_MeasureCapacitanceShield(&tmpVal, context);
if (CY_CAPSENSE_BIST_SUCCESS_E != bistStatus)
{
result = CY_CAPSENSE_BIST_FAIL_E;
context->ptrBistContext->testResultMask |= CY_CAPSENSE_BIST_SHIELD_CAP_MASK;
}
}
#endif
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_SHORT_EN)
if (0u != (CY_CAPSENSE_BIST_SNS_INTEGRITY_MASK & testEnMask))
{
bistStatus = Cy_CapSense_SnsShortCheckAllSensors(context);
if (CY_CAPSENSE_BIST_SUCCESS_E != bistStatus)
{
result = CY_CAPSENSE_BIST_FAIL_E;
context->ptrBistContext->testResultMask |= CY_CAPSENSE_BIST_SNS_INTEGRITY_MASK;
}
}
#endif
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN)
if (0u != (CY_CAPSENSE_BIST_SNS_CAP_MASK & testEnMask))
{
bistStatus = Cy_CapSense_BistMeasureCapacitanceSensorAll(context);
if (CY_CAPSENSE_BIST_SUCCESS_E != bistStatus)
{
result = CY_CAPSENSE_BIST_FAIL_E;
context->ptrBistContext->testResultMask |= CY_CAPSENSE_BIST_SNS_CAP_MASK;
}
}
#endif
}
else
{
result = CY_CAPSENSE_BIST_ERROR_E;
}
#endif
if (CY_CAPSENSE_BIST_FAIL_E != result)
{
result = CY_CAPSENSE_BIST_SUCCESS_E;
}
}
else
{
result = CY_CAPSENSE_BIST_HW_BUSY_E;
}
}
}
return result;
}
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_WDGT_CRC_EN)
/*******************************************************************************
* Function Name: Cy_CapSense_CheckCRCWidget_V2
****************************************************************************//**
*
* Checks the stored CRC of the \ref cy_stc_capsense_widget_context_t data
* structure of the specified widget.
*
* This function validates the data integrity of the
* \ref cy_stc_capsense_widget_context_t data structure of the specified widget
* by calculating the CRC and comparing it with the stored CRC value of the
* specified widget.
*
* Initially, after the device power up, the Cy_CapSense_Enable() function
* calculates CRC for each widget and stores them in the .ptrWdgtCrc[] array
* of the \ref cy_stc_capsense_bist_context_t structure. The test execution
* compares this stored CRC value with the newly calculated and if the stored
* and calculated CRC values differ:
* 1. The calculated CRC is stored to the .wdgtCrcCalc field
* of the \ref cy_stc_capsense_bist_context_t data structure.
* 2. The widget ID is stored to the .crcWdgtId field.
* 3. The CY_CAPSENSE_BIST_CRC_WDGT_MASK bit is set in the .testResultMask field.
*
* The function never clears the CY_CAPSENSE_BIST_CRC_WDGT_MASK bit.
* If the CY_CAPSENSE_BIST_CRC_WDGT_MASK bit is set, the wdgtCrcCalc
* and .crcWdgtId fields are not updated.
*
* It is recommended to use the Cy_CapSense_SetParam() function to change
* the value of the \ref cy_stc_capsense_widget_context_t data structure elements
* as the CRC is updated by Cy_CapSense_SetParam() function.
*
* You can initiate this test by the Cy_CapSense_RunSelfTest() function with
* the CY_CAPSENSE_BIST_CRC_WDGT_MASK mask as an input.
*
* The function clears the CY_CAPSENSE_WD_WORKING_MASK bit of the .status
* field in \ref cy_stc_capsense_widget_context_t structure if the calculated
* CRC value differs to the stored CRC value.
* Those non-working widgets are skipped by the high-level scanning and
* processing functions. Restoring a widget to its working state should
* be done by the application level.
*
* For details of the used CRC algorithm, refer to the Cy_CapSense_GetCRC()
* function.
*
* \note
* This function is available only for the fourth-generation CAPSENSE™.
*
* \param widgetId
* Specifies the ID number of the widget.
* A macro for the widget ID can be found in the
* CAPSENSE™ Configuration header file (cycfg_capsense.h) defined as
* CY_CAPSENSE_<WidgetName>_WDGT_ID.
*
* \param context
* The pointer to the CAPSENSE™ context structure \ref cy_stc_capsense_context_t.
*
* \return
* Returns a status of the test execution:
* - CY_CAPSENSE_BIST_SUCCESS_E - The stored CRC matches
* the calculated CRC.
* - CY_CAPSENSE_BIST_FAIL_E - The widget CRC differs to
* the stored CRC.
* - CY_CAPSENSE_BIST_BAD_PARAM_E - The input parameters are invalid.
* The test was not executed.
*
*******************************************************************************/
cy_en_capsense_bist_status_t Cy_CapSense_CheckCRCWidget_V2(
uint32_t widgetId,
cy_stc_capsense_context_t * context)
{
uint16_t crcValue;
cy_en_capsense_bist_status_t result = CY_CAPSENSE_BIST_BAD_PARAM_E;
if (NULL != context)
{
if (context->ptrCommonConfig->numWd > widgetId)
{
crcValue = Cy_CapSense_GetCrcWidget(widgetId, context);
if ((context->ptrBistContext->ptrWdgtCrc[widgetId]) != crcValue)
{
/* Write to the self-test data structure widgetId of the first badly-tested widget */
if (0Lu == (context->ptrBistContext->testResultMask & CY_CAPSENSE_BIST_CRC_WDGT_MASK))
{
context->ptrBistContext->wdgtCrcCalc = crcValue;
context->ptrBistContext->crcWdgtId = (uint8_t)widgetId;
context->ptrBistContext->testResultMask |= CY_CAPSENSE_BIST_CRC_WDGT_MASK;
}
/* Marks widget non-working */
(void)Cy_CapSense_SetWidgetStatus(widgetId, 0u, CY_CAPSENSE_WD_WORKING_MASK, context);
result = CY_CAPSENSE_BIST_FAIL_E;
}
else
{
result = CY_CAPSENSE_BIST_SUCCESS_E;
}
}
}
return result;
}
/*******************************************************************************
* Function Name: Cy_CapSense_CheckAllWidgetCRC
****************************************************************************//**
*
* The internal function that checks CRC of all widget structures.
*
* The function calculates CRC of all widget structures and compare it
* to the stored CRCs. It is called by the Cy_CapSense_RunSelfTest() function.
* In the first case of failed comparison the function updates
* testResultMask and returns the status. Next widgets are not checked.
* The function use the Cy_CapSense_CheckCRCWidget() function.
*
* \param context
* The pointer to the CAPSENSE™ context structure \ref cy_stc_capsense_context_t.
*
* \return
* Returns the status of the test processing:
* - CY_CAPSENSE_BIST_SUCCESS_E if all widget CRC are OK;
* - CY_CAPSENSE_BIST_FAIL_E if any widget CRC is wrong.
*
*******************************************************************************/
static cy_en_capsense_bist_status_t Cy_CapSense_CheckAllWidgetCRC(
cy_stc_capsense_context_t * context)
{
cy_en_capsense_bist_status_t result = CY_CAPSENSE_BIST_SUCCESS_E;
uint32_t widgetId;
for (widgetId = 0u; widgetId < context->ptrCommonConfig->numWd; widgetId++)
{
if (CY_CAPSENSE_BIST_SUCCESS_E != (Cy_CapSense_CheckCRCWidget_V2(widgetId, context)))
{
result = CY_CAPSENSE_BIST_FAIL_E;
break;
}
}
return result;
}
/*******************************************************************************
* Function Name: Cy_CapSense_UpdateCrcWidget
****************************************************************************//**
*
* The internal function updates the CRC
* of the \ref cy_stc_capsense_widget_context_t data structure
* for the specified widget.
*
* The function implements the following functionality:
* - Executes the Cy_CapSense_GetCRC() routine for the specified widget.
* - Updates the self-test CRC array with the CRC value, calculated for the
* specified widget.
*
* The CRC value is stored in the special wdgtCrc[CY_CAPSENSE_WIDGET_COUNT] array
* declared in the cycfg_capsense.c file.
*
* \param widgetId
* Specifies the ID number of the widget.
* A macro for the widget ID can be found in the
* CAPSENSE™ Configuration header file (cycfg_capsense.h) defined as
* CY_CAPSENSE_<WidgetName>_WDGT_ID.
*
* \param context
* The pointer to the CAPSENSE™ context structure \ref cy_stc_capsense_context_t.
*
*******************************************************************************/
void Cy_CapSense_UpdateCrcWidget(
uint32_t widgetId,
cy_stc_capsense_context_t * context)
{
uint16_t crcValue;
crcValue = Cy_CapSense_GetCrcWidget(widgetId, context);
/* Write the calculated CRC value to the self-test CRC array */
context->ptrBistContext->ptrWdgtCrc[widgetId] = crcValue;
}
#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_WDGT_CRC_EN) */
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_BSLN_INTEGRITY_EN)
/*******************************************************************************
* Function Name: Cy_CapSense_CheckIntegritySensorBaseline_V2
****************************************************************************//**
*
* Checks if the baseline of the specified sensor is not corrupted
* by comparing it with its inverse copy and checks if the baseline is
* within the specified range.
*
* The function checks whether or not the baseline binary inverted to
* its inverse copy is saved to the self-test baseline-inverse structure
* and is within the user-defined limits. If the baseline does
* not match its inverse copy or if the baseline is out of the user-defined
* limits, the function sets the CY_CAPSENSE_BIST_BSLN_INTEGRITY_MASK bit
* in the .testResultMask field of the \ref cy_stc_capsense_bist_context_t
* structure.
*
* The test is integrated into the CAPSENSE™ Middleware. All CAPSENSE™
* processing functions like Cy_CapSense_ProcessAllWidgets()
* or Cy_CapSense_UpdateSensorBaseline() automatically verify the baseline
* value before using it and update its inverse copy after processing.
* If a baseline update fails, a CY_CAPSENSE_STATUS_BAD_DATA result
* is returned. The baseline initialization functions do not verify the
* baseline and update the baseline inverse copy.
*
* This function does not update the CY_CAPSENSE_WD_WORKING_MASK bit of
* the .status field in \ref cy_stc_capsense_widget_context_t structure
* and is not available in the Cy_CapSense_RunSelfTest() function.
*
* Use this function to verify the uniformity of sensors, for example, at
* mass-production or during an operation phase together with the
* Cy_CapSense_CheckIntegritySensorRawcount() function.
*
* \note
* This function is available only for the fourth-generation CAPSENSE™.
*
* \param widgetId
* Specifies the ID number of the widget.
* A macro for the widget ID can be found in the
* CAPSENSE™ Configuration header file (cycfg_capsense.h) defined as
* CY_CAPSENSE_<WidgetName>_WDGT_ID.
*
* \param sensorId
* Specifies the ID number of the sensor within the widget.
* A macro for the sensor ID within the specified widget can be found in
* the CAPSENSE™ Configuration header file (cycfg_capsense.h) defined as
* CY_CAPSENSE_<WidgetName>_SNS<SensorNumber>_ID.
*
* \param baselineHighLimit
* Specifies the upper limit for a baseline.
*
* \param baselineLowLimit
* Specifies the lower limit for a baseline.
*
* \param context
* The pointer to the CAPSENSE™ context structure \ref cy_stc_capsense_context_t.
*
* \return
* Returns a status of the test execution:
* - CY_CAPSENSE_BIST_SUCCESS_E - The baseline is within the
* specified range.
* - CY_CAPSENSE_BIST_FAIL_E - The test failed and the baseline
* is not binary inverted to its inverse
* copy or is out of the specified limits.
* - CY_CAPSENSE_BIST_BAD_PARAM_E - The input parameter is invalid.
* The test was not executed.
*
*******************************************************************************/
cy_en_capsense_bist_status_t Cy_CapSense_CheckIntegritySensorBaseline_V2(
uint32_t widgetId,
uint32_t sensorId,
uint16_t baselineHighLimit,
uint16_t baselineLowLimit,
cy_stc_capsense_context_t * context)
{
cy_en_capsense_bist_status_t result = CY_CAPSENSE_BIST_BAD_PARAM_E;
uint16_t bslnInv;
uint32_t freqChIndex;
uint32_t cxtOffset;
const cy_stc_capsense_sensor_context_t *ptrSnsCxt;
cy_stc_capsense_widget_config_t const *ptrWdgtCfg;
if (NULL != context)
{
if ((context->ptrCommonConfig->numWd > widgetId) &&
(context->ptrWdConfig[widgetId].numSns > sensorId))
{
/* Get a pointer to the specified widget configuration structure */
ptrWdgtCfg = &context->ptrWdConfig[widgetId];
/* Get a pointer to the specified sensor context structure */
ptrSnsCxt = &ptrWdgtCfg->ptrSnsContext[sensorId];
/* Check baselines for all frequencies */
for (freqChIndex = 0u; freqChIndex < CY_CAPSENSE_CONFIGURED_FREQ_NUM; freqChIndex++)
{
cxtOffset = sensorId + (freqChIndex * context->ptrCommonConfig->numSns);
bslnInv = (uint16_t)(~(ptrWdgtCfg->ptrBslnInv[cxtOffset]));
if ((ptrSnsCxt->bsln != bslnInv) ||
(ptrSnsCxt->bsln > baselineHighLimit) ||
(ptrSnsCxt->bsln < baselineLowLimit))
{
context->ptrBistContext->testResultMask |= CY_CAPSENSE_BIST_BSLN_INTEGRITY_MASK;
result = CY_CAPSENSE_BIST_FAIL_E;
break;
}
ptrSnsCxt += context->ptrCommonConfig->numSns;
}
if (CY_CAPSENSE_BIST_FAIL_E != result)
{
result = CY_CAPSENSE_BIST_SUCCESS_E;
}
}
}
return result;
}
#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_BSLN_INTEGRITY_EN) */
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_RAW_INTEGRITY_EN)
/*******************************************************************************
* Function Name: Cy_CapSense_CheckIntegritySensorRawcount_V2
****************************************************************************//**
*
* Checks the raw count of the specified widget/sensor is within the specified
* range.
*
* The raw count is within a specific range (based on the calibration target)
* for good units. The function checks whether or not the raw count is within
* the user-defined limits in the ranges function arguments.
* If the raw count is out of limits, this function sets the
* CY_CAPSENSE_BIST_RAW_INTEGRITY_MASK bit in the .testResultMask field of the
* \ref cy_stc_capsense_bist_context_t structure.
*
* This function does not update the CY_CAPSENSE_WD_WORKING_MASK bit of
* the .status field in \ref cy_stc_capsense_widget_context_t structure
* and is not available in the Cy_CapSense_RunSelfTest() function.
*
* Use this function to verify the uniformity of sensors, for example, at
* mass-production or during an operation phase together with the
* Cy_CapSense_CheckIntegritySensorBaseline() function.
*
* \note
* This function is available only for the fourth-generation CAPSENSE™.
*
* \param widgetId
* Specifies the ID number of the widget.
* A macro for the widget ID can be found in the
* CAPSENSE™ Configuration header file (cycfg_capsense.h) defined as
* CY_CAPSENSE_<WidgetName>_WDGT_ID.
*
* \param sensorId
* Specifies the ID number of the sensor within the widget.
* A macro for the sensor ID within the specified widget can be found in
* the CAPSENSE™ Configuration header file (cycfg_capsense.h) defined as
* CY_CAPSENSE_<WidgetName>_SNS<SensorNumber>_ID.
*
* \param rawcountHighLimit
* Specifies the upper limit for the widget/sensor raw count.
*
* \param rawcountLowLimit
* Specifies the lower limit for the widget/sensor raw count.
*
* \param context
* The pointer to the CAPSENSE™ context structure \ref cy_stc_capsense_context_t.
*
* \return
* Returns a status of the test execution:
* - CY_CAPSENSE_BIST_SUCCESS_E - The raw count is within the
* specified range.
* - CY_CAPSENSE_BIST_FAIL_E - The test failed and raw count is out
* of the specified limits.
* - CY_CAPSENSE_BIST_BAD_PARAM_E - The input parameter is invalid.
* The test was not executed.
*
*******************************************************************************/
cy_en_capsense_bist_status_t Cy_CapSense_CheckIntegritySensorRawcount_V2(
uint32_t widgetId,
uint32_t sensorId,
uint16_t rawcountHighLimit,
uint16_t rawcountLowLimit,
cy_stc_capsense_context_t * context)
{
cy_en_capsense_bist_status_t result = CY_CAPSENSE_BIST_BAD_PARAM_E;
uint32_t freqChIndex;
const cy_stc_capsense_sensor_context_t *ptrSnsCxt;
cy_stc_capsense_widget_config_t const *ptrWdgtCfg;
if (NULL != context)
{
if ((context->ptrCommonConfig->numWd > widgetId) &&
(context->ptrWdConfig[widgetId].numSns > sensorId))
{
/* Find a pointer to the specified widget configuration structure */
ptrWdgtCfg = &context->ptrWdConfig[widgetId];
/* Find a pointer to the specified sensor context structure */
ptrSnsCxt = &ptrWdgtCfg->ptrSnsContext[sensorId];
/* Check raw counts for all frequencies */
for (freqChIndex = 0u; freqChIndex < CY_CAPSENSE_CONFIGURED_FREQ_NUM; freqChIndex++)
{
if ((ptrSnsCxt->raw > rawcountHighLimit) ||
(ptrSnsCxt->raw < rawcountLowLimit))
{
context->ptrBistContext->testResultMask |= CY_CAPSENSE_BIST_RAW_INTEGRITY_MASK;
result = CY_CAPSENSE_BIST_FAIL_E;
break;
}
ptrSnsCxt += context->ptrCommonConfig->numSns;
}
if (CY_CAPSENSE_BIST_FAIL_E != result)
{
result = CY_CAPSENSE_BIST_SUCCESS_E;
}
}
}
return result;
}
#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_RAW_INTEGRITY_EN) */
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_SHORT_EN)
/*******************************************************************************
* Function Name: Cy_CapSense_CheckIntegritySensorPins_V2
****************************************************************************//**
*
* Checks the specified widget/sensor for shorts to GND, VDD or other sensors.
*
* This function performs several sub-tests to verify the specified sensor
* is not electrically shorted and is in a good condition to reliably detect
* user interactions.
*
* This function performs tests to check if the specified sensor is shorted to:
* * GND
* * VDD
* * Other GPIOs used by CAPSENSE™ (such as sensors, Tx, Rx,
* shield electrodes, and external capacitors)
* * Other non-CAPSENSE™ GPIOs (only if they are configured
* in a strong high or low state during the test execution).
*
* The absolute resistance of an electrical short must be less than 1500 Ohm
* including all series resistors on a sensor for a short to be detected
* to GND, VDD or GPIOs. For example, if a series resistor on a sensor is
* 560 Ohm (as recommended) and the sensor is shorted with another sensor,
* the function can detect a short with a short resistance up to 380 Ohm as
* there are two 560 ohm resistors between the shorted sensor GPIOs.
*
* The function executes the following flow to detect a short:
* * Configures all CAPSENSE™ controlled GPIOs to strong-drive-high,
* and the specified sensor GPIO to resistive pull down mode.
* * Waits for a delay (defined by .snsIntgShortSettlingTime field
* of the \ref cy_stc_capsense_bist_context_t structure) to get established
* all transient processes.
* * Checks the status of the specified sensor for the expected state
* (logic low).
* * Configures all CAPSENSE™ controlled GPIOs to strong-drive-low,
* and the specified sensor GPIO to resistive pull up mode.
* * Waits for the above mentioned delay.
* * Checks the status of the specified sensor for the expected state
* (logic high).
* * Stores the test result in the CAPSENSE™ Data Structure.
* A short is reported only when the sensor status check returns
* an unexpected state.
*
* Due to the sensor parasitic capacitance and internal pull-up/down resistance,
* logic high-to-low (and vice versa) transitions require a settling time before
* checking the sensor status. A 2us delay is used as a settling time and can
* be changed using the .snsIntgShortSettlingTime field
* of the cy_stc_capsense_bist_context_t structure.
*
* If a short is detected this function updates the following statuses:
* * The widget ID is stored to the .shortedWdId field
* of the \ref cy_stc_capsense_bist_context_t structure.
* * The sensor ID is stored to the .shortedSnsId field
* of the \ref cy_stc_capsense_bist_context_t structure.
* * The CY_CAPSENSE_BIST_SNS_INTEGRITY_MASK bit is set in the .testResultMask field
* of the \ref cy_stc_capsense_bist_context_t structure.
* * If CY_CAPSENSE_BIST_SNS_INTEGRITY_MASK is already set due to a previously
* detected fault on any of the sensor, this function does not update
* the .shortedWdId and .shortedSnsId fields. For this reason,
* clear the CY_CAPSENSE_BIST_SNS_INTEGRITY_MASK bit prior calling this function.
* * The widget is disabled by clearing the CY_CAPSENSE_WD_WORKING_MASK bit
* in the .status field of the \ref cy_stc_capsense_widget_context_t structure
* of the specified widget.
* The disabled widget is ignored by high-level functions of scanning / data