Correct copyright information
[tas2557sw-android/tas2557-ftc.git] / tas2557_ftc.c
1 /*\r
2 ** =============================================================================\r
3 ** Copyright (c) 2016  Texas Instruments Inc.\r
4 **\r
5 ** File:\r
6 **     tas2557_ftc.c\r
7 **\r
8 ** Description:\r
9 **     factory test program for TAS2557 Android devices\r
10 **\r
11 ** =============================================================================\r
12 */\r
13 \r
14 #include <stdio.h>\r
15 #include <stdint.h>\r
16 #include <math.h>\r
17 #include <sys/types.h>\r
18 \r
19 #include "system.h"\r
20 #include "tas2557.h"        // TAS2557 Driver\r
21 #include "tas2557_ftc_lib.h"    \r
22 #include "tas2557_ftc.h"    // TAS2557 Factory Test and Calibration Tool\r
23 \r
24 #define PI                   3.14159\r
25 \r
26 static struct TFTCConfiguration *gpFTCC;\r
27 \r
28 // -----------------------------------------------------------------------------\r
29 // tas2557_ftc\r
30 // -----------------------------------------------------------------------------\r
31 // Description:\r
32 //      Obtains Re, f0, Q and T_cal from the speaker. This only needs to be\r
33 //      executed once during production line test.\r
34 // -----------------------------------------------------------------------------\r
35 uint32_t tas2557_ftc(double t_cal, struct TFTCConfiguration *pFTCC)\r
36 {\r
37         int nResult = 0;\r
38         double dev_a_re = pFTCC->nTSpkCharDevA.nPPC3_Re0;   // Default Re\r
39         uint32_t dev_a_prm_pow = 0;           // Total RMS power coefficient\r
40         uint32_t dev_a_prm_tlimit = 0;        // Delta temperature limit coefficient\r
41         uint8_t nPGID;\r
42         uint32_t libVersion;\r
43         uint32_t result = 0;\r
44         pid_t nPlaybackProcess;\r
45 \r
46         gpFTCC = pFTCC;\r
47 \r
48         libVersion = get_lib_ver();\r
49         printf("libVersion=0x%x\r\n", libVersion);\r
50 \r
51         /* get device PGID */\r
52         nPGID = tas2557_get_PGID();\r
53         printf("PGID=0x%x\r\n", nPGID);\r
54 \r
55         /* set device PGID to FTC process */\r
56         tas2557_ftc_set_PGID(nPGID);\r
57 \r
58         /* STEP 1: Play calibration signal */\r
59         tas2557_mixer_command("PRI_MI2S_RX Audio Mixer MultiMedia1", 1); //platform dependent\r
60         nPlaybackProcess = sys_play_wav("silense.wav", "loop");\r
61 \r
62         /* STEP 2: start calibration process */\r
63         tas2557_ftc_start();\r
64 \r
65         /* STEP 3: Wait for algorithm to converge */\r
66         sys_delay(gpFTCC->nCalibrationTime); \r
67 \r
68         /* STEP 4: Get actual Re from TAS2557 */\r
69         dev_a_re = get_re(gpFTCC->nTSpkCharDevA.nPPC3_Re0);\r
70 \r
71         /* STEP 5: check speaker bounds */\r
72         nResult = check_spk_bounds(gpFTCC, dev_a_re);\r
73 \r
74         /* STEP 6: Set temperature limit to target TMAX */\r
75         if((nResult& RE1_CHK_MSK) == RESULT_PASS){\r
76                 dev_a_prm_pow = calc_prm_pow (dev_a_re, \r
77                         gpFTCC->nTSpkCharDevA.nSpkTMax - t_cal, \r
78                         gpFTCC->nTSpkCharDevA.nPPC3_RTV, \r
79                         gpFTCC->nTSpkCharDevA.nPPC3_RTM, \r
80                         gpFTCC->nTSpkCharDevA.nPPC3_RTVA, \r
81                         gpFTCC->nTSpkCharDevA.nPPC3_SysGain);\r
82                 dev_a_prm_tlimit = calc_prm_tlimit(gpFTCC->nTSpkCharDevA.nSpkTMax - t_cal, \r
83                         gpFTCC->nTSpkCharDevA.nSpkReAlpha, \r
84                         gpFTCC->nTSpkCharDevA.nPPC3_DevNonlinPer, \r
85                         gpFTCC->nTSpkCharDevA.nPPC3_RTV, \r
86                         gpFTCC->nTSpkCharDevA.nPPC3_RTM, \r
87                         gpFTCC->nTSpkCharDevA.nPPC3_RTVA,\r
88                         gpFTCC->nTSpkCharDevA.nPPC3_PIG);\r
89                 set_re(gpFTCC->nTSpkCharDevA.nPPC3_Re0, dev_a_re, gpFTCC->nTSpkCharDevA.nSpkReAlpha);\r
90                 set_temp_cal(dev_a_prm_pow, dev_a_prm_tlimit);\r
91         }\r
92 \r
93         tas2557_ftc_stop();\r
94 \r
95         sys_stop_wav(nPlaybackProcess);\r
96 \r
97         /* STEP 7: Save Re, and Cal Temp into a file */\r
98         tas2557_save_cal(gpFTCC, dev_a_re, dev_a_prm_pow, dev_a_prm_tlimit, t_cal, nResult, "tas2557_cal.txt");\r
99 \r
100         /* STEP 8: Save .bin file for TAS2555 driver */\r
101         if ((nResult & RE1_CHK_MSK) == RESULT_PASS) {\r
102                 tas2557_open_bin("tas2557_cal.bin");\r
103                 set_re(gpFTCC->nTSpkCharDevA.nPPC3_Re0, dev_a_re, gpFTCC->nTSpkCharDevA.nSpkReAlpha);\r
104                 set_temp_cal(dev_a_prm_pow, dev_a_prm_tlimit);\r
105 \r
106                 tas2557_close_bin();\r
107         }\r
108 \r
109         if (gpFTCC->bLoadCalibration)\r
110                 tas2557_load_calibration(0xFF);\r
111 \r
112         tas2557_ftc_release();\r
113 \r
114         return result;\r
115 }\r