From 500e2be5feef557f8daabe02d808411d20b1cfa3 Mon Sep 17 00:00:00 2001 From: Peter Li Date: Thu, 9 Mar 2017 01:13:29 +0800 Subject: [PATCH] update TAS2557 mono FTC --- Android.mk | 24 +++ CleanSpec.mk | 49 ++++++ factorytest.c | 252 +++++++++++++++++++++++++++++++ lib/Android.mk | 10 ++ lib/libftc32.a | Bin 0 -> 6176 bytes lib/libftc64.a | Bin 0 -> 6200 bytes readme.txt | 1 + speaker.ftcfg | 27 ++++ system.c | 80 ++++++++++ system.h | 42 ++++++ tas2557.c | 371 ++++++++++++++++++++++++++++++++++++++++++++++ tas2557.h | 56 +++++++ tas2557_ftc.c | 124 ++++++++++++++++ tas2557_ftc.h | 58 ++++++++ tas2557_ftc_lib.h | 42 ++++++ 15 files changed, 1136 insertions(+) create mode 100755 Android.mk create mode 100755 CleanSpec.mk create mode 100755 factorytest.c create mode 100755 lib/Android.mk create mode 100755 lib/libftc32.a create mode 100755 lib/libftc64.a create mode 100755 readme.txt create mode 100755 speaker.ftcfg create mode 100755 system.c create mode 100755 system.h create mode 100755 tas2557.c create mode 100755 tas2557.h create mode 100755 tas2557_ftc.c create mode 100755 tas2557_ftc.h create mode 100755 tas2557_ftc_lib.h diff --git a/Android.mk b/Android.mk new file mode 100755 index 0000000..7314c51 --- /dev/null +++ b/Android.mk @@ -0,0 +1,24 @@ +LOCAL_PATH := $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_SRC_FILES += \ + factorytest.c \ + system.c \ + tas2557.c \ + tas2557_ftc.c + +LOCAL_C_INCLUDES += ${LOCAL_PATH}/ + +LOCAL_CFLAGS += -Wno-unused-parameter + +LOCAL_SHARED_LIBRARIES += libm + +LOCAL_STATIC_LIBRARIES += libftc + +LOCAL_MODULE := factorytest + +include $(BUILD_EXECUTABLE) + +#include $(CLEAR_VARS) + +include $(call all-makefiles-under,$(LOCAL_PATH)) diff --git a/CleanSpec.mk b/CleanSpec.mk new file mode 100755 index 0000000..b84e1b6 --- /dev/null +++ b/CleanSpec.mk @@ -0,0 +1,49 @@ +# Copyright (C) 2007 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# If you don't need to do a full clean build but would like to touch +# a file or delete some intermediate files, add a clean step to the end +# of the list. These steps will only be run once, if they haven't been +# run before. +# +# E.g.: +# $(call add-clean-step, touch -c external/sqlite/sqlite3.h) +# $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libz_intermediates) +# +# Always use "touch -c" and "rm -f" or "rm -rf" to gracefully deal with +# files that are missing or have been moved. +# +# Use $(PRODUCT_OUT) to get to the "out/target/product/blah/" directory. +# Use $(OUT_DIR) to refer to the "out" directory. +# +# If you need to re-do something that's already mentioned, just copy +# the command and add it to the bottom of the list. E.g., if a change +# that you made last week required touching a file and a change you +# made today requires touching the same file, just copy the old +# touch step and add it to the end of the list. +# +# ************************************************ +# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST +# ************************************************ + +# For example: +#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/AndroidTests_intermediates) +#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/core_intermediates) +#$(call add-clean-step, find $(OUT_DIR) -type f -name "IGTalkSession*" -print0 | xargs -0 rm -f) +#$(call add-clean-step, rm -rf $(PRODUCT_OUT)/data/*) + +# ************************************************ +# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST +# ************************************************ diff --git a/factorytest.c b/factorytest.c new file mode 100755 index 0000000..3290e05 --- /dev/null +++ b/factorytest.c @@ -0,0 +1,252 @@ +/* +** ============================================================================= +** Copyright (c) 2016 Texas Instruments Inc. +** +** This program is free software; you can redistribute it and/or modify it under +** the terms of the GNU General Public License as published by the Free Software +** Foundation; version 2. +** +** This program is distributed in the hope that it will be useful, but WITHOUT +** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +** FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License along with +** this program; if not, write to the Free Software Foundation, Inc., 51 Franklin +** Street, Fifth Floor, Boston, MA 02110-1301, USA. +** +** File: +** factorytest.c +** +** Description: +** main program for TAS2555 factory test +** +** ============================================================================= +*/ + +#include +#include +#include +#include +#include +#include +#include + +#include "tas2557_ftc.h" + +// ================================================================ Definitions +// Obtained from Speaker Manufacturer +#define SPK_T_MAX 100 // Speaker Maximum Temperature (C) +#define SPK_RE_TOL_PER 10 // Re +/- tolerance (%) +#define SPK_RE_ALPHA 0.0039 // Temperature coefficient alpha (1/K) + +// Obtained from PurePath Console 3 (PPC3) +#define PPC3_RE0 7.41 // Re0 (ohm) +#define PPC3_RTV 46.5 // Rtv (K/W) +#define PPC3_RTM 78.2 // Rtm (K/W) +#define PPC3_RTVA 2460 // Rtva (K/W) +#define PPC3_SYSGAIN 9.35 // System Gain (V/FS) +#define PPC3_DEV_NONLIN_PER 1.5 // Device Non-linearity (%) + +void ExitWithHint(char *pHint) +{ + printf("factorytest: invalid command line: %s\n\r\n\r", pHint); + + printf("usage: factorytest [-t temperature] [-c configuration file] [-l load calibration] [-v verbose]\n\r"); + exit(-1); +} + +void InitFTCC(struct TFTCConfiguration *pFTCC) +{ + pFTCC->nCalibrationTime = 4000; + + pFTCC->bVerbose = false; + pFTCC->bLoadCalibration = false; + + pFTCC->nTSpkCharDevA.nSpkTMax = SPK_T_MAX; + pFTCC->nTSpkCharDevA.nSpkReTolPer = SPK_RE_TOL_PER; + pFTCC->nTSpkCharDevA.nSpkReAlpha = SPK_RE_ALPHA; + pFTCC->nTSpkCharDevA.nReHi = PPC3_RE0*1.15; + pFTCC->nTSpkCharDevA.nReLo = PPC3_RE0*0.85; + pFTCC->nTSpkCharDevA.nPPC3_Re0 = PPC3_RE0; + pFTCC->nTSpkCharDevA.nPPC3_RTV = PPC3_RTV; + pFTCC->nTSpkCharDevA.nPPC3_RTM = PPC3_RTM; + pFTCC->nTSpkCharDevA.nPPC3_RTVA = PPC3_RTVA; + pFTCC->nTSpkCharDevA.nPPC3_SysGain = PPC3_SYSGAIN; + pFTCC->nTSpkCharDevA.nPPC3_DevNonlinPer = PPC3_DEV_NONLIN_PER; +} + +unsigned int SkipCharacter(char *pData, char cCharacter, unsigned int nSize) +{ + unsigned int nRIndex; + unsigned int nWIndex = 0; + + for (nRIndex = 0; nRIndex < nSize; nRIndex++) + if (pData[nRIndex] != cCharacter) pData[nWIndex++] = pData[nRIndex]; + + return nWIndex; +} + +unsigned int RemoveComments(char *pData, char cCharacter, unsigned int nSize) +{ + unsigned int nRIndex; + unsigned int nWIndex = 0; + + for (nRIndex = 0; nRIndex < nSize; nRIndex++) + { + if (pData[nRIndex] == cCharacter) + while ((nRIndex < nSize) && (pData[nRIndex] != '\r')) nRIndex++; + pData[nWIndex++] = pData[nRIndex]; + } + + return nWIndex; +} + +void ReadValue(struct TFTCConfiguration *pFTCC, struct TSPKCharData *pSpk, char *pLine, char *pValue) +{ + if (!strcmp(pLine, "CALIBRATION_TIME")) {pFTCC->nCalibrationTime = atoi(pValue); return;}; + if (!strcmp(pLine, "SPK_T_MAX")) {pSpk->nSpkTMax = atof(pValue); return;}; + if (!strcmp(pLine, "SPK_RE_TOL_PER")) {pSpk->nSpkReTolPer = atof(pValue); return;}; + if (!strcmp(pLine, "SPK_RE_ALPHA")) {pSpk->nSpkReAlpha = atof(pValue); return;}; + if (!strcmp(pLine, "PPC3_RE0")) {pSpk->nPPC3_Re0 = atof(pValue); return;}; + if (!strcmp(pLine, "PPC3_RTV")) {pSpk->nPPC3_RTV = atof(pValue); return;}; + if (!strcmp(pLine, "PPC3_RTM")) {pSpk->nPPC3_RTM = atof(pValue); return;}; + if (!strcmp(pLine, "PPC3_RTVA")) {pSpk->nPPC3_RTVA = atof(pValue); return;}; + if (!strcmp(pLine, "PPC3_SYSGAIN")) {pSpk->nPPC3_SysGain = atof(pValue); return;}; + if (!strcmp(pLine, "PPC3_DEV_NONLIN_PER")) {pSpk->nPPC3_DevNonlinPer = atof(pValue); return;}; + if (!strcmp(pLine, "RE_HI")) {pSpk->nReHi = atof(pValue); return;}; + if (!strcmp(pLine, "RE_LO")) {pSpk->nReLo = atof(pValue); return;}; +} + +void ftcc_print(struct TFTCConfiguration *pFTCC) +{ + printf("factorytest configuration: \n\r"); + + printf(" CALIBRATION_TIME = %d\n\r", pFTCC->nCalibrationTime); + printf(" SPKA SPK_T_MAX = %2.2f\n\r", pFTCC->nTSpkCharDevA.nSpkTMax); + printf(" SPKA SPK_RE_TOL_PER = %2.2f\n\r", pFTCC->nTSpkCharDevA.nSpkReTolPer); + printf(" SPKA SPK_RE_ALPHA = %2.4f\n\r\n\r", pFTCC->nTSpkCharDevA.nSpkReAlpha); + printf(" SPKA PPC3_RE0 = %2.2f\n\r", pFTCC->nTSpkCharDevA.nPPC3_Re0); + printf(" SPKA PPC3_RTV = %2.2f\n\r", pFTCC->nTSpkCharDevA.nPPC3_RTV); + printf(" SPKA PPC3_RTM = %2.2f\n\r", pFTCC->nTSpkCharDevA.nPPC3_RTM); + printf(" SPKA PPC3_RTVA = %2.2f\n\r", pFTCC->nTSpkCharDevA.nPPC3_RTVA); + printf(" SPKA PPC3_SYSGAIN = %2.2f\n\r", pFTCC->nTSpkCharDevA.nPPC3_SysGain); + printf(" SPKA PPC3_DEV_NONLIN_PER = %2.2f\n\r", pFTCC->nTSpkCharDevA.nPPC3_DevNonlinPer); +} + +int ftcc_parse(struct TFTCConfiguration *pFTCC, struct TSPKCharData *pSpk, char *pData, unsigned int nSize) +{ + unsigned int nRIndex = 0; + char *pLine; + char *pEqual; + double nTest; + + nSize = SkipCharacter(pData, ' ', nSize); + nSize = RemoveComments(pData, ';', nSize); + + pData[nSize] = 0; + + pLine = strtok(pData, "\n\r"); + +// printf("ftcc_parse: pData = %s\n\r", pData); + +// printf("ftcc_parse: size = %d, pLine = 0x%08x\n\r", nSize, pLine); + while (pLine) { +// printf("ftcc_parse: pLine = 0x%08x\n\r", pLine); + if (pLine[0]) { + printf("Line = %s\n\r", pLine); + pEqual = strstr(pLine, "="); + if ((pEqual) && (strlen(pEqual) > 1)) { + pEqual[0] = 0; + ReadValue(pFTCC, pSpk, pLine, pEqual + 1); + pEqual[0] = '='; + } + } + pLine = strtok(NULL, "\n\r"); + } + + return 0; +} + +void LoadFTCC(char *pFileName, struct TFTCConfiguration *pFTCC, struct TSPKCharData *pSpk) +{ + struct stat st; + char *pData; + int nFile; + +// printf("LoadFTCC: %s\n\r", pFileName); + + if (stat(pFileName, &st) < 0) ExitWithHint("configuration file doesn't exist"); + + pData = malloc(st.st_size); + if (!pData) ExitWithHint("cannot allocate memory for configuation file"); + + nFile = open(pFileName, O_RDONLY); + if (nFile < 0) ExitWithHint("cannot open configuration file"); + + read(nFile, pData, st.st_size); + close(nFile); + + ftcc_parse(pFTCC, pSpk, pData, st.st_size); + + free(pData); +} + +int main(int argc, char *argv[]) +{ + double nTemp = 20.0; + int nArg = 1; + bool bValidArg; + char pHint[256]; + struct TFTCConfiguration sFTCC; + + printf("\nTI TAS2557 factory test calibration sequence V1.0\n"); + + InitFTCC(&sFTCC); +// printf("argc = %d\n\r", argc); + while (nArg < argc) + { +// printf("argv[%d] = %s: ", nArg, argv[nArg]); + bValidArg = false; + if (!strcmp(argv[nArg], "-t")) { + printf("nArg = %d, argc = %d\n\r", nArg, argc); + if (argc <= (nArg + 1)) + ExitWithHint("temperature parameter is missing"); + nTemp = atof(argv[nArg + 1]); + nArg++; + bValidArg = true; + } + + if (!strcmp(argv[nArg], "-c")) { +// printf("found configuration file argument\n\r"); + if (argc <= (nArg + 1)) + ExitWithHint("configuration file name is missing"); + LoadFTCC(argv[nArg + 1], &sFTCC, &(sFTCC.nTSpkCharDevA)); + nArg++; + bValidArg = true; + } + + if (!strcmp(argv[nArg], "-v")) { + sFTCC.bVerbose = true; + bValidArg = true; + } + + if (!strcmp(argv[nArg], "-u")) { + sFTCC.bLoadCalibration = true; + bValidArg = true; + } + + if (!bValidArg) { + sprintf(pHint, "don't know argument %s", argv[nArg]); + ExitWithHint(pHint); + } + nArg++; + } + + if (sFTCC.bVerbose) { + printf("\n\rambient temperature = %2.1f\n\r", nTemp); + ftcc_print(&sFTCC); + } + + tas2557_ftc(nTemp, &sFTCC); + return 0; +} diff --git a/lib/Android.mk b/lib/Android.mk new file mode 100755 index 0000000..9b2cff6 --- /dev/null +++ b/lib/Android.mk @@ -0,0 +1,10 @@ +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) +LOCAL_MODULE := libftc +LOCAL_SRC_FILES_32 := libftc32.a +LOCAL_SRC_FILES_64 := libftc64.a +LOCAL_MULTILIB := both +LOCAL_MODULE_CLASS := STATIC_LIBRARIES +LOCAL_MODULE_SUFFIX := .a +include $(BUILD_PREBUILT) \ No newline at end of file diff --git a/lib/libftc32.a b/lib/libftc32.a new file mode 100755 index 0000000000000000000000000000000000000000..8113f0c51c249baf0b339c42e3d2026585640ca0 GIT binary patch literal 6176 zcmbVQO>7&-6@C;Yo0iyi<1#Q43(lry8mg5jN}+8fP#d~YYZ+1up>==+bwN=iWf7$$ zmRcoh5uiT!;K0hEXbx&)Ks=LLL!0KLD%JilPMJ^GH(|u;$-LgPn|lGnRIfQIq=8MogdoIbg~skD5?~MGXc45 zDVHf%rZeT)cN&CKDoz*cs!n0LoPm}|uYWW9xAq09zrHo_$J!3 zvFS@DA@zO{Fxx&g(653s-u~+!j{YbR2p~lD5sQ-BFq-H_4&Hiak?7!DceRtX6o_noW zFADuYUv(#%?5GhVz?Qzv9ZS(+;9aZ}0&W5&`L9}4ezNn7$g_)5-RZHaJMY?@f4uhj z-rjxk65xfvix|9K@JirW29J6+cwrwe4qiy{q9UJZJ5%7Bc4(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?mU;v3!4TyfT! zTNL--@k^i5>C1khHs@B1uYXZSt>VBC{e$50bNFBwAo8mqY^&CUpzzzE@^vr#qeo4j z-2UAL{!@vY{89|RF7W}#IVSJ9TZ_SO$KZUP+)OztZcO|?KD~|qRSe!EsQ`ToXo^f(-e!R;9Qd<_0IMCKhQ literal 0 HcmV?d00001 diff --git a/readme.txt b/readme.txt new file mode 100755 index 0000000..9143623 --- /dev/null +++ b/readme.txt @@ -0,0 +1 @@ +./factorytest -t 25 -c speaker.ftcfg -v \ No newline at end of file diff --git a/speaker.ftcfg b/speaker.ftcfg new file mode 100755 index 0000000..52140ab --- /dev/null +++ b/speaker.ftcfg @@ -0,0 +1,27 @@ + +; TAS2557 Factory Test and Calibration Configuration File +; ----------------------------------------------------------------------------- +; PPC3 File: example.ppc3 +; DDC Name: N48M1V2 +; Comments: [Write Comments Here] + +; FTC Settings +CALIBRATION_TIME = 6000 ; Duration (in ms) of calibration phase + +; Obtained from Speaker Manufacturer +SPK_T_MAX = 80 ; Speaker Maximum Temperature (C) +SPK_RE_TOL_PER = 10 ; Re +/- tolerance (%) +SPK_RE_ALPHA = 0.0039 ; Temperature coefficient alpha (1/K) + +; Pass/Fail Limits +RE_HI = 8.0 +RE_LO = 6.0 + +; Obtained from PurePath Console 3 (PPC3) +PPC3_RE0 = 7.0 ; Re0 (ohm) +PPC3_RTV = 44.9 ; Rtv (K/W) +PPC3_RTM = 80.7 ; Rtm (K/W) +PPC3_RTVA = 1723 ; Rtva (K/W) +PPC3_SYSGAIN = 9.35 ; System Gain (V/FS) +PPC3_DEV_NONLIN_PER = 1.5 ; Device Non-linearity (%) + diff --git a/system.c b/system.c new file mode 100755 index 0000000..18fc3d9 --- /dev/null +++ b/system.c @@ -0,0 +1,80 @@ +/* +** ============================================================================= +** Copyright (c) 2016 Texas Instruments Inc. +** +** This program is free software; you can redistribute it and/or modify it under +** the terms of the GNU General Public License as published by the Free Software +** Foundation; version 2. +** +** This program is distributed in the hope that it will be useful, but WITHOUT +** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +** FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License along with +** this program; if not, write to the Free Software Foundation, Inc., 51 Franklin +** Street, Fifth Floor, Boston, MA 02110-1301, USA. +** +** File: +** system.c +** +** Description: +** system functions for TAS2555 factory test program +** +** ============================================================================= +*/ + +#include "system.h" + +#include +#include +#include +#include +#include + +pid_t sys_play_wav(char * pFile, char * pMode) +{ + pid_t nProcess; + int nStatus, nTimeout; + char *pArgs[] = {AUDIO_PLAYER, pFile, NULL}; + char *pEnv[] = {NULL}; + + if (0 == (nProcess = fork())) + { + if (execve(AUDIO_PLAYER, pArgs, pEnv) == -1) + { + printf("factorytest: Can't play %s. Please install %s. \n\r", pFile, AUDIO_PLAYER); + exit(-1); + } + } + + sys_delay(500); + + printf("factorytest: Started playback of %s\n\r", pFile); + + return nProcess; +} + +extern void sys_stop_wav(pid_t nProcess) +{ + char *pEnv[] = {NULL}; + + printf("factorytest: Stop playback.\n\r"); + + kill(nProcess, SIGKILL); +} + +extern void sys_delay(uint32_t delay_ms) +{ + usleep(delay_ms * 1000); +} + +extern double sys_get_ambient_temp(void) +{ + return 0.0; +} + +extern int sys_is_valid(char * pFile) +{ + return 0; +} + diff --git a/system.h b/system.h new file mode 100755 index 0000000..bad47c1 --- /dev/null +++ b/system.h @@ -0,0 +1,42 @@ +/* +** ============================================================================= +** Copyright (c) 2016 Texas Instruments Inc. +** +** This program is free software; you can redistribute it and/or modify it under +** the terms of the GNU General Public License as published by the Free Software +** Foundation; version 2. +** +** This program is distributed in the hope that it will be useful, but WITHOUT +** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +** FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License along with +** this program; if not, write to the Free Software Foundation, Inc., 51 Franklin +** Street, Fifth Floor, Boston, MA 02110-1301, USA. +** +** File: +** system.h +** +** Description: +** header file for system.c +** +** ============================================================================= +*/ + +#ifndef SYSTEM_H_ +#define SYSTEM_H_ + +#include +#include + +#define AUDIO_PLAYER "/system/bin/tinyplay" +#define AUDIO_MIXER "/system/bin/tinymix" + +// Hypothetical System Functions +extern pid_t sys_play_wav(char * pFile, char * pMode); +extern void sys_stop_wav(pid_t nProcess); +extern void sys_delay(uint32_t delay_ms); +extern double sys_get_ambient_temp(void); +extern int sys_is_valid(char * pFile); + +#endif /* SYSTEM_H_ */ diff --git a/tas2557.c b/tas2557.c new file mode 100755 index 0000000..4d93ecd --- /dev/null +++ b/tas2557.c @@ -0,0 +1,371 @@ +/* +** ============================================================================= +** Copyright (c) 2016 Texas Instruments Inc. +** +** This program is free software; you can redistribute it and/or modify it under +** the terms of the GNU General Public License as published by the Free Software +** Foundation; version 2. +** +** This program is distributed in the hope that it will be useful, but WITHOUT +** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +** FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License along with +** this program; if not, write to the Free Software Foundation, Inc., 51 Franklin +** Street, Fifth Floor, Boston, MA 02110-1301, USA. +** +** File: +** tas2555.c +** +** Description: +** functions for configurating TAS2555 Android device +** +** ============================================================================= +*/ + +#include "tas2557.h" +#include "system.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define TILOAD_NODE "/dev/tiload_node" + +static int gTILoad = 0; +static int gBinFile = 0; + +#define MAX_BIN_SIZE 2048 +static char gpBin[MAX_BIN_SIZE]; +static unsigned int gnBinIndex = 0; +static unsigned int gnBinBlockIndex = 0; +static char gpDevABlock[MAX_BIN_SIZE/2]; +static unsigned int gnDevABlockIndex = 0; +static unsigned char gnDevA; +static unsigned char gnDev; + +static void tas2557_check_node(void); + +void tas2557_mixer_command(char *pCommand, int nData) +{ + char *pMixer[] = {AUDIO_MIXER, pCommand, "0", NULL}; + char *pEnv[] = {NULL}; + + char pData[16]; + + printf("TAS2557 mixer command %s = %d.\n\r", pCommand, nData); + + sprintf(pData, "%d", nData); + pMixer[2] = pData; + + if (0 == (fork())) + { + if (execve(AUDIO_MIXER, pMixer, pEnv) == -1) + { + printf("factorytest: Can't find mixer. Please install %s. \n\r", AUDIO_MIXER); + exit(-1); + } + } + + sys_delay(500); +} + +void tas2557_load_calibration(int nCalibration) +{ + tas2557_check_node(); + + ioctl(gTILoad, TILOAD_IOCTL_SET_CALIBRATION, &nCalibration); + sys_delay(500); +} + +static void tas2557_check_node(void) +{ + if (gTILoad) return; + + gTILoad = open(TILOAD_NODE, O_RDWR); + + if (gTILoad < 0) + { + printf("factorytest: Can't find tiload. Please create %s. \n\r", TILOAD_NODE); + exit(-1); + } + + printf("factorytest: %s handle = %d\n\r", TILOAD_NODE, gTILoad); +} + +uint8_t tas2557_get_PGID(void) +{ + unsigned char pPageZero[] = {0x00, 0x00}; + unsigned char pBook[] = {0x7F, 0x00}; + unsigned char pPage[] = {0x00, 0x00}; + unsigned char pData[] = {0x03, 0x00, 0x00, 0x00, 0x00}; + + tas2557_check_node(); + + write(gTILoad, pPageZero, 2); + write(gTILoad, pBook, 2); + write(gTILoad, pPage, 2); + read(gTILoad, pData, 1); + + return pData[0]; +} + +uint32_t tas2557_coeff_read(uint8_t book, uint8_t page, uint8_t reg) +{ + unsigned char pPageZero[] = {0x00, 0x00}; + unsigned char pBook[] = {0x7F, book}; + unsigned char pPage[] = {0x00, page}; + unsigned char pData[] = {reg, 0x00, 0x00, 0x00, 0x00}; + + tas2557_check_node(); + + write(gTILoad, pPageZero, 2); + write(gTILoad, pBook, 2); + write(gTILoad, pPage, 2); + read(gTILoad, pData, 4); + + return ((pData[0] << 24) | (pData[1] << 16) | (pData[2] << 8) | (pData[3])); +} + +void tas2557_coeff_write(uint8_t book, uint8_t page, uint8_t reg, uint32_t data) +{ + unsigned int nByte; + + if (gBinFile) { + /* if the bin file is open, write the coefficients to the bin file */ + unsigned int index = gnDevABlockIndex*4; + gpDevABlock[index] = 0; + gpDevABlock[index + 1] = 4; + gpDevABlock[index + 2] = 0x85; + gpDevABlock[index + 4] = book; + gpDevABlock[index + 5] = page; + gpDevABlock[index + 6] = reg; + + for (nByte = 0; nByte < 4; nByte++) + gpDevABlock[index + 7 + nByte] = (data >> ((3 - nByte) * 8)) & 0xFF; + + gnDevABlockIndex += 3; + } else { + unsigned char pPageZero[] = {0x00, 0x00}; + unsigned char pBook[] = {0x7F, book}; + unsigned char pPage[] = {0x00, page}; + unsigned char pData[] = {reg, (data & 0xFF000000) >> 24, (data & 0x00FF0000) >> 16, (data & 0x0000FF00) >> 8, data & 0x000000FF}; + + tas2557_check_node(); + + write(gTILoad, pPageZero, 2); + write(gTILoad, pBook, 2); + write(gTILoad, pPage, 2); + write(gTILoad, pData, 5); + + pBook[1] = 0x8C; + pPage[1] = 0x19; + + pData[0] = 0x7C; + pData[1] = 0x00; + pData[2] = 0x00; + pData[3] = 0x00; + pData[4] = 0x01; + + write(gTILoad, pPageZero, 2); + write(gTILoad, pBook, 2); + write(gTILoad, pPage, 2); + write(gTILoad, pData, 5); + + pBook[1] = 0x00; + pPage[1] = 0x35; + + pData[0] = 0x2c; + pData[1] = 0x00; + pData[2] = 0x00; + pData[3] = 0x00; + pData[4] = 0x01; + + write(gTILoad, pPageZero, 2); + write(gTILoad, pBook, 2); + write(gTILoad, pPage, 2); + write(gTILoad, pData, 5); + } +} + +void tas2557_save_cal(struct TFTCConfiguration *pFTCC, + double dev_a_re, uint32_t dev_a_rms_pow, uint32_t dev_a_t_limit, + double t_cal, uint32_t nResult, char * pFileName) +{ + printf("TAS2557 calibration values:\n\r"); + printf(" DevA Re = %1.2f Ohm\n\r", dev_a_re); + printf(" DevA rms_pow = 0x%08X\n\r", dev_a_rms_pow); + printf(" DevA t_limit = 0x%08X\n\r", dev_a_t_limit); + + if((nResult & RE1_CHK_MSK) == RESULT_PASS) + printf(" SPK A calibration success! \n\r"); + else { + if(nResult & RE1_FAIL_HI) + printf(" SPK A Calibration fail : Re is too high (limit: %1.2f).\n\r", pFTCC->nTSpkCharDevA.nReHi); + else + printf(" SPK A Calibration fail : Re is too low (limit: %1.2f).\n\r", pFTCC->nTSpkCharDevA.nReLo); + } + + FILE *pFile = fopen(pFileName, "w+"); + + fprintf(pFile, "DevA Re = %1.2f\n\r", dev_a_re); + fprintf(pFile, "DevA rms_pow = 0x%08X\n\r", dev_a_rms_pow); + fprintf(pFile, "DevA t_limit = 0x%08X\n\r", dev_a_t_limit); + fprintf(pFile, "Ambient temperature = %2.2f\n\r\n\r", t_cal); + fprintf(pFile, "Result = 0x%x\n\r\n\r", nResult); + + fclose(pFile); +} + +#define DDC_DESCRIPTION "Calibration Data File for TAS2557 Mono" +#define CALIBRATION_DESCRIPTION "Calibration snapshot for TAS2557 Mono" +#define DATA_DESCRIPTION "data blocks for TAS2557 Mono FTC" + +void tas2557_open_bin(char * pFileName) +{ + time_t timestamp; + + gBinFile = open(pFileName, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IROTH | S_IWOTH); + + gnBinIndex = 0; + memset(gpBin, 0, MAX_BIN_SIZE); + memset(gpDevABlock, 0, MAX_BIN_SIZE/2); + gnDevABlockIndex = 0; + + //magic number + gpBin[gnBinIndex++] = '5'; + gpBin[gnBinIndex++] = '5'; + gpBin[gnBinIndex++] = '5'; + gpBin[gnBinIndex++] = '2'; + + gnBinIndex += 4; /* bypass size int */ + gnBinIndex += 4; /* bypass checksum int */ + gnBinIndex += 4; /* bypass PPC3 version int */ + gnBinIndex += 4; /* bypass DSP version int */ + + gpBin[gnBinIndex++] = 0; + gpBin[gnBinIndex++] = 0; + gpBin[gnBinIndex++] = 1; + gpBin[gnBinIndex++] = 0; /* driver version 0x00000100 */ + + time(×tamp); + gpBin[gnBinIndex++] = (unsigned char)((timestamp&0xff000000)>>24); + gpBin[gnBinIndex++] = (unsigned char)((timestamp&0x00ff0000)>>16);; + gpBin[gnBinIndex++] = (unsigned char)((timestamp&0x0000ff00)>>8);; + gpBin[gnBinIndex++] = (unsigned char)((timestamp&0x000000ff));; + + strcpy(&gpBin[gnBinIndex], "Calibration Data File"); /* DDC name */ + gnBinIndex += 64; + + strcpy(&gpBin[gnBinIndex], DDC_DESCRIPTION); + gnBinIndex += strlen(DDC_DESCRIPTION) + 1; + + gnBinIndex += 4; /* device family index */ + + gpBin[gnBinIndex++] = 0; /* device index */ + gpBin[gnBinIndex++] = 0; /* device index */ + gpBin[gnBinIndex++] = 0; /* device index */ + gpBin[gnBinIndex++] = 2; /* device index, TAS2557 Mono */ + + gnBinIndex += + 2 + /* num PLL index */ + 0 + /* array PLL index */ + 2 + /* num programs index */ + 0 + /* array programs index */ + 2 + /* num configurations index */ + 0; /* array configurations index */ + + gpBin[gnBinIndex++] = 0x00; + gpBin[gnBinIndex++] = 0x01; /* one calibration data block */ + + strcpy(&gpBin[gnBinIndex], "Calibration snapshot"); + gnBinIndex += 64; + strcpy(&gpBin[gnBinIndex], CALIBRATION_DESCRIPTION); + gnBinIndex += strlen(CALIBRATION_DESCRIPTION) + 1; + + gpBin[gnBinIndex++] = 0x00; /* compatible program = smart amp (index 0) */ + gpBin[gnBinIndex++] = 0x00; /* compatible configuration */ + + strcpy(&gpBin[gnBinIndex], "Calibration Data"); + gnBinIndex += 64; + strcpy(&gpBin[gnBinIndex], DATA_DESCRIPTION); + gnBinIndex += strlen(DATA_DESCRIPTION) + 1; + + gpBin[gnBinIndex++] = 0x00; + gpBin[gnBinIndex++] = 1; /* one blocks */ + + gpDevABlock[0] = 0; + gpDevABlock[1] = 0; + gpDevABlock[2] = 0; + gpDevABlock[3] = 0x03; /* COEFF_DEVICE_A – 0x03 */ + gnDevABlockIndex = 2; +} + +void tas2557_close_bin(void) +{ + unsigned int nCommands; + unsigned char pCommit[] = { + 0x00, 0x04, 0x85, 0x00, + 0x8C, 0x19, 0x7C, 0x00, + 0x00, 0x00, 0x01, 0x00, + 0x00, 0x04, 0x85, 0x00, + 0x00, 0x35, 0x2c, 0x00, + 0x00, 0x00, 0x01, 0x00 + }; + + /* write the commit sequence */ + memcpy(&gpDevABlock[gnDevABlockIndex*4], pCommit, 24); + gnDevABlockIndex += 6; + + /* write number of commands for calibration block */ + gpDevABlock[4] = ((gnDevABlockIndex-2) & 0xFF000000) >> 24; + gpDevABlock[5] = ((gnDevABlockIndex-2) & 0x00FF0000) >> 16; + gpDevABlock[6] = ((gnDevABlockIndex-2) & 0x0000FF00) >> 8; + gpDevABlock[7] = ((gnDevABlockIndex-2) & 0x000000FF); + + memcpy(&gpBin[gnBinIndex], gpDevABlock, gnDevABlockIndex*4); + gnBinIndex += (gnDevABlockIndex*4); + + /* write bin file size */ + gpBin[4] = (gnBinIndex & 0xFF000000) >> 24; + gpBin[5] = (gnBinIndex & 0x00FF0000) >> 16; + gpBin[6] = (gnBinIndex & 0x0000FF00) >> 8; + gpBin[7] = (gnBinIndex & 0x000000FF); + + write(gBinFile, gpBin, gnBinIndex); + close(gBinFile); + + gBinFile = 0; +} + +// ----------------------------------------------------------------------------- +// check_spk_bounds +// ----------------------------------------------------------------------------- +// Description: +// Checks if speaker paramters are within bounds. +// ----------------------------------------------------------------------------- +uint32_t check_spk_bounds(struct TFTCConfiguration *pFTCC, double re1) +{ + uint32_t result = RESULT_PASS; + + if(re1>pFTCC->nTSpkCharDevA.nReHi) + result |= RE1_FAIL_HI; + if(re1nTSpkCharDevA.nReLo) + result |= RE1_FAIL_LO; + + return result; +} + +void tas2557_ftc_release(void) +{ + if (gTILoad > 0) { + close(gTILoad); + gTILoad = 0; + } +} \ No newline at end of file diff --git a/tas2557.h b/tas2557.h new file mode 100755 index 0000000..b6cfc59 --- /dev/null +++ b/tas2557.h @@ -0,0 +1,56 @@ +/* +** ============================================================================= +** Copyright (c) 2016 Texas Instruments Inc. +** +** This program is free software; you can redistribute it and/or modify it under +** the terms of the GNU General Public License as published by the Free Software +** Foundation; version 2. +** +** This program is distributed in the hope that it will be useful, but WITHOUT +** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +** FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License along with +** this program; if not, write to the Free Software Foundation, Inc., 51 Franklin +** Street, Fifth Floor, Boston, MA 02110-1301, USA. +** +** File: +** tas2557.h +** +** Description: +** header file for tas2557.c +** +** ============================================================================= +*/ + +#ifndef TAS2557_H_ +#define TAS2557_H_ + +#include +#include "tas2557_ftc.h" + +#define TILOAD_IOC_MAGIC 0xE0 + +#define TILOAD_IOCTL_SET_CHL _IOW(TILOAD_IOC_MAGIC, 5, int) +#define TILOAD_IOCTL_SET_CONFIG _IOW(TILOAD_IOC_MAGIC, 6, int) +#define TILOAD_IOCTL_SET_CALIBRATION _IOW(TILOAD_IOC_MAGIC, 7, int) + +#define RESULT_PASS 0x00000000 +#define RE1_FAIL_HI 0x00000001 +#define RE1_FAIL_LO 0x00000010 +#define RE1_CHK_MSK 0x00000011 + +uint8_t tas2557_get_PGID(void); +void tas2557_mixer_command(char *pCommand, int nData); +uint32_t tas2557_coeff_read(uint8_t book, uint8_t page, uint8_t reg); +void tas2557_coeff_write(uint8_t book, uint8_t page, uint8_t reg, uint32_t data); +void tas2557_save_cal(struct TFTCConfiguration *pFTCC, + double dev_a_re, uint32_t dev_a_rms_pow, uint32_t dev_a_t_limit, + double t_cal, uint32_t,char * pFileName); +uint32_t check_spk_bounds(struct TFTCConfiguration *pFTCC, double re1); +void tas2557_load_calibration(int nCalibration); +void tas2557_open_bin(char * pFileName); +void tas2557_close_bin(void); +void tas2557_ftc_release(void); + +#endif /* TAS2557_H_ */ diff --git a/tas2557_ftc.c b/tas2557_ftc.c new file mode 100755 index 0000000..b0686ad --- /dev/null +++ b/tas2557_ftc.c @@ -0,0 +1,124 @@ +/* +** ============================================================================= +** Copyright (c) 2016 Texas Instruments Inc. +** +** This program is free software; you can redistribute it and/or modify it under +** the terms of the GNU General Public License as published by the Free Software +** Foundation; version 2. +** +** This program is distributed in the hope that it will be useful, but WITHOUT +** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +** FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License along with +** this program; if not, write to the Free Software Foundation, Inc., 51 Franklin +** Street, Fifth Floor, Boston, MA 02110-1301, USA. +** +** File: +** tas2557_ftc.c +** +** Description: +** factory test program for TAS2557 Android devices +** +** ============================================================================= +*/ + +#include +#include +#include +#include + +#include "system.h" +#include "tas2557.h" // TAS2557 Driver +#include "tas2557_ftc_lib.h" +#include "tas2557_ftc.h" // TAS2557 Factory Test and Calibration Tool + +#define PI 3.14159 + +static struct TFTCConfiguration *gpFTCC; + +// ----------------------------------------------------------------------------- +// tas2557_ftc +// ----------------------------------------------------------------------------- +// Description: +// Obtains Re, f0, Q and T_cal from the speaker. This only needs to be +// executed once during production line test. +// ----------------------------------------------------------------------------- +uint32_t tas2557_ftc(double t_cal, struct TFTCConfiguration *pFTCC) +{ + int nResult = 0; + double dev_a_re = pFTCC->nTSpkCharDevA.nPPC3_Re0; // Default Re + uint32_t dev_a_prm_pow = 0; // Total RMS power coefficient + uint32_t dev_a_prm_tlimit = 0; // Delta temperature limit coefficient + uint8_t nPGID; + uint32_t libVersion; + uint32_t result = 0; + pid_t nPlaybackProcess; + + gpFTCC = pFTCC; + + libVersion = get_lib_ver(); + printf("libVersion=0x%x\r\n", libVersion); + + /* get device PGID */ + nPGID = tas2557_get_PGID(); + printf("PGID=0x%x\r\n", nPGID); + + /* set device PGID to FTC process */ + tas2557_ftc_set_PGID(nPGID); + + /* STEP 1: Play calibration signal */ + tas2557_mixer_command("PRI_MI2S_RX Audio Mixer MultiMedia1", 1); //platform dependent + nPlaybackProcess = sys_play_wav("silense.wav", "loop"); + + /* STEP 2: start calibration process */ + tas2557_ftc_start(); + + /* STEP 3: Wait for algorithm to converge */ + sys_delay(gpFTCC->nCalibrationTime); + + /* STEP 4: Get actual Re from TAS2557 */ + dev_a_re = get_re(gpFTCC->nTSpkCharDevA.nPPC3_Re0); + + /* STEP 5: check speaker bounds */ + nResult = check_spk_bounds(gpFTCC, dev_a_re); + + /* STEP 6: Set temperature limit to target TMAX */ + if((nResult& RE1_CHK_MSK) == RESULT_PASS){ + dev_a_prm_pow = calc_prm_pow (dev_a_re, + gpFTCC->nTSpkCharDevA.nSpkTMax - t_cal, + gpFTCC->nTSpkCharDevA.nPPC3_RTV, + gpFTCC->nTSpkCharDevA.nPPC3_RTM, + gpFTCC->nTSpkCharDevA.nPPC3_RTVA, + gpFTCC->nTSpkCharDevA.nPPC3_SysGain); + dev_a_prm_tlimit = calc_prm_tlimit(gpFTCC->nTSpkCharDevA.nSpkTMax - t_cal, + gpFTCC->nTSpkCharDevA.nSpkReAlpha, + gpFTCC->nTSpkCharDevA.nPPC3_DevNonlinPer, + gpFTCC->nTSpkCharDevA.nPPC3_RTV, + gpFTCC->nTSpkCharDevA.nPPC3_RTM, + gpFTCC->nTSpkCharDevA.nPPC3_RTVA); + set_re(gpFTCC->nTSpkCharDevA.nPPC3_Re0, dev_a_re, gpFTCC->nTSpkCharDevA.nSpkReAlpha); + set_temp_cal(dev_a_prm_pow, dev_a_prm_tlimit); + } + + sys_stop_wav(nPlaybackProcess); + + /* STEP 7: Save Re, and Cal Temp into a file */ + tas2557_save_cal(gpFTCC, dev_a_re, dev_a_prm_pow, dev_a_prm_tlimit, t_cal, nResult, "tas2557_cal.txt"); + + /* STEP 8: Save .bin file for TAS2555 driver */ + if ((nResult & RE1_CHK_MSK) == RESULT_PASS) { + tas2557_open_bin("tas2557_cal.bin"); + set_re(gpFTCC->nTSpkCharDevA.nPPC3_Re0, dev_a_re, gpFTCC->nTSpkCharDevA.nSpkReAlpha); + set_temp_cal(dev_a_prm_pow, dev_a_prm_tlimit); + + tas2557_close_bin(); + } + + if (gpFTCC->bLoadCalibration) + tas2557_load_calibration(0xFF); + + tas2557_ftc_release(); + + return result; +} diff --git a/tas2557_ftc.h b/tas2557_ftc.h new file mode 100755 index 0000000..269d7a3 --- /dev/null +++ b/tas2557_ftc.h @@ -0,0 +1,58 @@ +/* +** ============================================================================= +** Copyright (c) 2016 Texas Instruments Inc. +** +** This program is free software; you can redistribute it and/or modify it under +** the terms of the GNU General Public License as published by the Free Software +** Foundation; version 2. +** +** This program is distributed in the hope that it will be useful, but WITHOUT +** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +** FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License along with +** this program; if not, write to the Free Software Foundation, Inc., 51 Franklin +** Street, Fifth Floor, Boston, MA 02110-1301, USA. +** +** File: +** tas2557_ftc.h +** +** Description: +** header file for tas2557_ftc.c +** +** ============================================================================= +*/ + +#ifndef TAS2557_FTC_H_ +#define TAS2557_FTC_H_ + +#include +#include + +struct TSPKCharData { + double nSpkTMax; + double nSpkReTolPer; + double nSpkReAlpha; + + double nPPC3_Re0; + double nPPC3_RTV; + double nPPC3_RTM; + double nPPC3_RTVA; + double nPPC3_SysGain; + double nPPC3_DevNonlinPer; + + double nReHi; + double nReLo; +}; + +struct TFTCConfiguration { + bool bVerbose; + bool bLoadCalibration; + unsigned int nCalibrationTime; + + struct TSPKCharData nTSpkCharDevA; +}; + +uint32_t tas2557_ftc(double t_cal, struct TFTCConfiguration *pFTCC); + +#endif /* TAS2557_FTC_H_ */ diff --git a/tas2557_ftc_lib.h b/tas2557_ftc_lib.h new file mode 100755 index 0000000..de688e6 --- /dev/null +++ b/tas2557_ftc_lib.h @@ -0,0 +1,42 @@ +/* +** ============================================================================= +** Copyright (c) 2016 Texas Instruments Inc. +** +** This program is free software; you can redistribute it and/or modify it under +** the terms of the GNU General Public License as published by the Free Software +** Foundation; version 2. +** +** This program is distributed in the hope that it will be useful, but WITHOUT +** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +** FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License along with +** this program; if not, write to the Free Software Foundation, Inc., 51 Franklin +** Street, Fifth Floor, Boston, MA 02110-1301, USA. +** +** File: +** tas2557_lib_ftc.h +** +** Description: +** header file for tas2557_lib_ftc.c +** +** ============================================================================= +*/ + +#ifndef TAS2557_LIB_FTC_H_ +#define TAS2557_LIB_FTC_H_ + +#include +#include + +#include "tas2557.h" + +int get_lib_ver(void); +void tas2557_ftc_set_PGID(unsigned char nPGID); +void tas2557_ftc_start(void); +void set_re(double re_ppc3, double re, double alpha); +void set_temp_cal(uint32_t prm_pow, uint32_t prm_tlimit); +double get_re(double re_ppc3); +uint32_t calc_prm_pow(double re, double delta_t_max, double nRTV, double nRTM, double nRTVA, double nSysGain); +uint32_t calc_prm_tlimit(double delta_t_max, double alpha, double nDevNonlinPer, double nRTV, double nRTM, double nRTVA); +#endif /* TAS2557_LIB_FTC_H_ */ -- 2.39.2