]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - tas2557sw-android/tas2557dm-ftc.git/blob - factorytest.c
print out PGID and libversion
[tas2557sw-android/tas2557dm-ftc.git] / factorytest.c
1 /*
2 ** =============================================================================
3 ** Copyright (c) 2016  Texas Instruments Inc.
4 **
5 ** This program is free software; you can redistribute it and/or modify it under
6 ** the terms of the GNU General Public License as published by the Free Software 
7 ** Foundation; version 2.
8 **
9 ** This program is distributed in the hope that it will be useful, but WITHOUT
10 ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 ** FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12 **
13 ** You should have received a copy of the GNU General Public License along with
14 ** this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15 ** Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 **
17 ** File:
18 **     factorytest.c
19 **
20 ** Description:
21 **     main program for TAS2555 factory test 
22 **
23 ** =============================================================================
24 */
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <stdbool.h>
29 #include <sys/types.h>
30 #include <sys/stat.h>
31 #include <string.h>
32 #include <fcntl.h>
34 #include "tas2557_ftc.h"
36 // ================================================================ Definitions
37 // Obtained from Speaker Manufacturer
38 #define SPK_T_MAX            100    // Speaker Maximum Temperature (C)
39 #define SPK_RE_TOL_PER       10     // Re +/- tolerance (%)
40 #define SPK_RE_ALPHA         0.0039 // Temperature coefficient alpha (1/K)
42 // Obtained from PurePath Console 3 (PPC3)
43 #define PPC3_RE0             7.41   // Re0 (ohm)
44 #define PPC3_RTV             46.5   // Rtv (K/W)
45 #define PPC3_RTM             78.2   // Rtm (K/W)
46 #define PPC3_RTVA            2460   // Rtva (K/W)
47 #define PPC3_SYSGAIN         9.35   // System Gain (V/FS)
48 #define PPC3_DEV_NONLIN_PER  1.5    // Device Non-linearity (%)
50 #define DEV_A_I2C_ADDR           0x98
51 #define DEV_B_I2C_ADDR           0x9a
53 void ExitWithHint(char *pHint)
54 {
55         printf("factorytest: invalid command line: %s\n\r\n\r", pHint);
57         printf("usage: factorytest [-t temperature] [-c configuration file] [-l load calibration] [-v verbose]\n\r");
58         exit(-1);
59 }
61 void InitFTCC(TFTCConfiguration *pFTCC)
62 {
63         pFTCC->nCalibrationTime = 4000;
65         pFTCC->bVerbose = false;
66         pFTCC->bLoadCalibration = false;
67         pFTCC->nConfiguration = 0;
68         pFTCC->nConfigurationCalibration = 1;
69         
70         pFTCC->nTSpkCharDevA.nSpkTMax = SPK_T_MAX;
71         pFTCC->nTSpkCharDevA.nSpkReTolPer = SPK_RE_TOL_PER;
72         pFTCC->nTSpkCharDevA.nSpkReAlpha = SPK_RE_ALPHA;
73         pFTCC->nTSpkCharDevA.nReHi = PPC3_RE0*1.15;
74         pFTCC->nTSpkCharDevA.nReLo = PPC3_RE0*0.85;
75         pFTCC->nTSpkCharDevA.nPPC3_Re0 = PPC3_RE0;
76         pFTCC->nTSpkCharDevA.nPPC3_RTV = PPC3_RTV;
77         pFTCC->nTSpkCharDevA.nPPC3_RTM = PPC3_RTM;
78         pFTCC->nTSpkCharDevA.nPPC3_RTVA = PPC3_RTVA;
79         pFTCC->nTSpkCharDevA.nPPC3_SysGain = PPC3_SYSGAIN;
80         pFTCC->nTSpkCharDevA.nPPC3_DevNonlinPer = PPC3_DEV_NONLIN_PER;
81         pFTCC->nTSpkCharDevA.nDevAddr = DEV_A_I2C_ADDR;
82         
83         pFTCC->nTSpkCharDevB.nSpkTMax = SPK_T_MAX;
84         pFTCC->nTSpkCharDevB.nSpkReTolPer = SPK_RE_TOL_PER;
85         pFTCC->nTSpkCharDevB.nSpkReAlpha = SPK_RE_ALPHA;
86         pFTCC->nTSpkCharDevB.nReHi = PPC3_RE0*1.15;
87         pFTCC->nTSpkCharDevB.nReLo = PPC3_RE0*0.85;     
88         pFTCC->nTSpkCharDevB.nPPC3_Re0 = PPC3_RE0;
89         pFTCC->nTSpkCharDevB.nPPC3_RTV = PPC3_RTV;
90         pFTCC->nTSpkCharDevB.nPPC3_RTM = PPC3_RTM;
91         pFTCC->nTSpkCharDevB.nPPC3_RTVA = PPC3_RTVA;
92         pFTCC->nTSpkCharDevB.nPPC3_SysGain = PPC3_SYSGAIN;
93         pFTCC->nTSpkCharDevB.nPPC3_DevNonlinPer = PPC3_DEV_NONLIN_PER;
94         pFTCC->nTSpkCharDevB.nDevAddr = DEV_B_I2C_ADDR;
95 }
97 unsigned int SkipCharacter(char *pData, char cCharacter, unsigned int nSize)
98 {
99         unsigned int nRIndex;
100         unsigned int nWIndex = 0;
102         for (nRIndex = 0; nRIndex < nSize; nRIndex++)
103                 if (pData[nRIndex] != cCharacter) pData[nWIndex++] = pData[nRIndex];
105         return nWIndex;
108 unsigned int RemoveComments(char *pData, char cCharacter, unsigned int nSize)
110         unsigned int nRIndex;
111         unsigned int nWIndex = 0;
113         for (nRIndex = 0; nRIndex < nSize; nRIndex++)
114         {
115                 if (pData[nRIndex] == cCharacter)
116                         while ((nRIndex < nSize) && (pData[nRIndex] != '\r')) nRIndex++;
117                 pData[nWIndex++] = pData[nRIndex];
118         }
120         return nWIndex;
123 void ReadValue(TFTCConfiguration *pFTCC, TSPKCharData *pSpk, char *pLine, char *pValue)
125         if (!strcmp(pLine, "CALIBRATION_TIME")) {pFTCC->nCalibrationTime = atoi(pValue); return;};
126         if (!strcmp(pLine, "CONFIGURATION")) {pFTCC->nConfiguration = atoi(pValue); return;};
127         if (!strcmp(pLine, "CONFIGURATION_CALIBRATION")) {pFTCC->nConfigurationCalibration = atoi(pValue); return;};
128         if (!strcmp(pLine, "SPK_T_MAX")) {pSpk->nSpkTMax = atof(pValue); return;};
129         if (!strcmp(pLine, "SPK_RE_TOL_PER")) {pSpk->nSpkReTolPer = atof(pValue); return;};
130         if (!strcmp(pLine, "SPK_RE_ALPHA")) {pSpk->nSpkReAlpha = atof(pValue); return;};
131         if (!strcmp(pLine, "PPC3_RE0")) {pSpk->nPPC3_Re0 = atof(pValue); return;};
132         if (!strcmp(pLine, "PPC3_RTV")) {pSpk->nPPC3_RTV = atof(pValue); return;};
133         if (!strcmp(pLine, "PPC3_RTM")) {pSpk->nPPC3_RTM = atof(pValue); return;};
134         if (!strcmp(pLine, "PPC3_RTVA")) {pSpk->nPPC3_RTVA = atof(pValue); return;};
135         if (!strcmp(pLine, "PPC3_SYSGAIN")) {pSpk->nPPC3_SysGain = atof(pValue); return;};
136         if (!strcmp(pLine, "PPC3_DEV_NONLIN_PER")) {pSpk->nPPC3_DevNonlinPer = atof(pValue); return;};
137         if (!strcmp(pLine, "RE_HI")) {pSpk->nReHi = atof(pValue); return;};
138         if (!strcmp(pLine, "RE_LO")) {pSpk->nReLo = atof(pValue); return;};
139         if (!strcmp(pLine, "DEV_ADDR")){        
140                 char *endptr;
141                 pSpk->nDevAddr = strtol(pValue, &endptr, 16); 
142                 return;
143         };
146 void ftcc_print(TFTCConfiguration *pFTCC)
148         printf("factorytest configuration: \n\r");
150         printf("  CALIBRATION_TIME   = %d\n\r", pFTCC->nCalibrationTime);
151         printf("  CONFIGURATION             = %d\n\r", pFTCC->nConfiguration);
152         printf("  CONFIGURATION_CALIBRATION = %d\n\r\n\r", pFTCC->nConfigurationCalibration);
153         
154         printf("Speaker A characterization data: \n\r");
156         printf(" SPKA SPK_T_MAX      = %2.2f\n\r", pFTCC->nTSpkCharDevA.nSpkTMax);
157         printf(" SPKA SPK_RE_TOL_PER = %2.2f\n\r", pFTCC->nTSpkCharDevA.nSpkReTolPer);
158         printf(" SPKA SPK_RE_ALPHA   = %2.4f\n\r\n\r", pFTCC->nTSpkCharDevA.nSpkReAlpha);
159         
160         printf(" SPKA PPC3_RE0            = %2.2f\n\r", pFTCC->nTSpkCharDevA.nPPC3_Re0);
161         printf(" SPKA PPC3_RTV            = %2.2f\n\r", pFTCC->nTSpkCharDevA.nPPC3_RTV);
162         printf(" SPKA PPC3_RTM            = %2.2f\n\r", pFTCC->nTSpkCharDevA.nPPC3_RTM);
163         printf(" SPKA PPC3_RTVA           = %2.2f\n\r", pFTCC->nTSpkCharDevA.nPPC3_RTVA);
164         printf(" SPKA PPC3_SYSGAIN        = %2.2f\n\r", pFTCC->nTSpkCharDevA.nPPC3_SysGain);
165         printf(" SPKA PPC3_DEV_NONLIN_PER = %2.2f\n\r", pFTCC->nTSpkCharDevA.nPPC3_DevNonlinPer);
166         printf(" DEVA ADDR                = 0x%x\n\r", pFTCC->nTSpkCharDevA.nDevAddr);
167         
168         printf("Speaker B characterization data: \n\r");
170         printf(" SPKB SPK_T_MAX      = %2.2f\n\r", pFTCC->nTSpkCharDevB.nSpkTMax);
171         printf(" SPKB SPK_RE_TOL_PER = %2.2f\n\r", pFTCC->nTSpkCharDevB.nSpkReTolPer);
172         printf(" SPKB SPK_RE_ALPHA   = %2.4f\n\r\n\r", pFTCC->nTSpkCharDevB.nSpkReAlpha);
173         
174         printf(" SPKB PPC3_RE0            = %2.2f\n\r", pFTCC->nTSpkCharDevB.nPPC3_Re0);
175         printf(" SPKB PPC3_RTV            = %2.2f\n\r", pFTCC->nTSpkCharDevB.nPPC3_RTV);
176         printf(" SPKB PPC3_RTM            = %2.2f\n\r", pFTCC->nTSpkCharDevB.nPPC3_RTM);
177         printf(" SPKB PPC3_RTVA           = %2.2f\n\r", pFTCC->nTSpkCharDevB.nPPC3_RTVA);
178         printf(" SPKB PPC3_SYSGAIN        = %2.2f\n\r", pFTCC->nTSpkCharDevB.nPPC3_SysGain);
179         printf(" SPKB PPC3_DEV_NONLIN_PER = %2.2f\n\r", pFTCC->nTSpkCharDevB.nPPC3_DevNonlinPer);
180         printf(" DEVB ADDR                = 0x%x\n\r", pFTCC->nTSpkCharDevB.nDevAddr);  
184 int ftcc_parse(TFTCConfiguration *pFTCC, TSPKCharData *pSpk, char *pData, unsigned int nSize)
186         unsigned int nRIndex = 0;
187         char *pLine;
188         char *pEqual;
189         double nTest;
191         nSize = SkipCharacter(pData, ' ', nSize);
192         nSize = RemoveComments(pData, ';', nSize);
194         pData[nSize] = 0;
196         pLine = strtok(pData, "\n\r");
198 //      printf("ftcc_parse: pData = %s\n\r", pData);
200 //      printf("ftcc_parse: size = %d, pLine = 0x%08x\n\r", nSize, pLine);
201         while (pLine)
202         {
203 //              printf("ftcc_parse: pLine = 0x%08x\n\r", pLine);
204                 if (pLine[0])
205                 {
206                         printf("Line = %s\n\r", pLine);
207                         pEqual = strstr(pLine, "=");
208                         if ((pEqual) && (strlen(pEqual) > 1))
209                         {
210                                 pEqual[0] = 0;
211                                 ReadValue(pFTCC, pSpk, pLine, pEqual + 1);
212                                 pEqual[0] = '=';
213                         }
214                 }
215                 pLine = strtok(NULL, "\n\r");
216         }
217         
218         return 0;
221 void LoadFTCC(char *pFileName, TFTCConfiguration *pFTCC, TSPKCharData *pSpk)
223         struct stat st;
224         char *pData;
225         int nFile;
226         
227 //      printf("LoadFTCC: %s\n\r", pFileName);
229         if (stat(pFileName, &st) < 0) ExitWithHint("configuration file doesn't exist");
231         pData = malloc(st.st_size);
232         if (!pData) ExitWithHint("cannot allocate memory for configuation file");
234     nFile = open(pFileName, O_RDONLY);
235         if (nFile < 0) ExitWithHint("cannot open configuration file"); 
237         read(nFile, pData, st.st_size);
238         close(nFile);
240         ftcc_parse(pFTCC, pSpk, pData, st.st_size); 
242         free(pData);
245 int main(int argc, char *argv[])
247         double nTemp = 20.0;
248         int nArg = 1;
249         bool bValidArg;
250         char pHint[256];
251         TFTCConfiguration sFTCC;
253         printf("\nTI TAS2557 factory test calibration sequence V1.0\n");
255         InitFTCC(&sFTCC);
256 //      printf("argc = %d\n\r", argc);
257         while (nArg < argc)
258         {
259 //              printf("argv[%d] = %s: ", nArg, argv[nArg]);
260                 bValidArg = false;
261                 if (!strcmp(argv[nArg], "-t"))
262                 {
263                         printf("nArg = %d, argc = %d\n\r", nArg, argc);
264                         if (argc <= (nArg + 1)) ExitWithHint("temperature parameter is missing");
265                         nTemp = atof(argv[nArg + 1]);
266                         nArg++;
267                         bValidArg = true;
268                 }
270                 if (!strcmp(argv[nArg], "-l"))
271                 {
272 //                      printf("found configuration file argument\n\r");
273                         if (argc <= (nArg + 1)) ExitWithHint("configuration file name is missing");
274                         LoadFTCC(argv[nArg + 1], &sFTCC, &(sFTCC.nTSpkCharDevA));
275                         nArg++;
276                         bValidArg = true;
277                 }
278                 
279                 if (!strcmp(argv[nArg], "-r"))
280                 {
281 //                      printf("found configuration file argument\n\r");
282                         if (argc <= (nArg + 1)) ExitWithHint("configuration file name is missing");
283                         LoadFTCC(argv[nArg + 1], &sFTCC, &(sFTCC.nTSpkCharDevB));
284                         nArg++;
285                         bValidArg = true;
286                 }
288                 if (!strcmp(argv[nArg], "-v"))
289                 {
290                         sFTCC.bVerbose = true;
291                         bValidArg = true;
292                 }
294                 if (!strcmp(argv[nArg], "-u"))
295                 {
296                         sFTCC.bLoadCalibration = true;
297                         bValidArg = true;
298                 }
300                 if (!bValidArg)
301                 {
302                         sprintf(pHint, "don't know argument %s", argv[nArg]);
303                         ExitWithHint(pHint);
304                 }
305                 nArg++;
306         }
308         if (sFTCC.bVerbose) 
309         {
310                 printf("\n\rambient temperature = %2.1f\n\r", nTemp);
311                 ftcc_print(&sFTCC);
312         }
313         tas2557_ftc(nTemp, &sFTCC);
314         return 0;