update to version v1.0.0.2 : add "restore original state after FTC"
authorPeter Li <peter-li@ti.com>
Fri, 17 Mar 2017 11:14:13 +0000 (19:14 +0800)
committerPeter Li <peter-li@ti.com>
Fri, 17 Mar 2017 11:14:13 +0000 (19:14 +0800)
lib/libftc32.a
lib/libftc64.a
tas2557.c
tas2557.h
tas2557_ftc_lib.h
tas2557dm_ftc.c

index 8113f0c51c249baf0b339c42e3d2026585640ca0..d4c74020122e880259858f05450ec713869af4cd 100644 (file)
Binary files a/lib/libftc32.a and b/lib/libftc32.a differ
index a1708c29dcb9fa939140570a2925c1cad1fc8660..db6f3617bcbf511a639b54f04e248b4bb4318b6e 100644 (file)
Binary files a/lib/libftc64.a and b/lib/libftc64.a differ
index 1779380caa08eecfb2c7eb99905e6358ae89e860..d55b81366335867e871dd6f5424ebd0ef8423123 100755 (executable)
--- a/tas2557.c
+++ b/tas2557.c
@@ -119,12 +119,15 @@ uint8_t tas2557_get_PGID(void)
        return pData[0];
 }
 
-uint32_t tas2557_coeff_read(uint8_t book, uint8_t page, uint8_t reg)
+uint32_t tas2557_coeff_read(uint32_t reg)
 {
+       uint8_t nbook = TAS2557_BOOK_ID(reg);
+       uint8_t npage = TAS2557_PAGE_ID(reg);
+       uint8_t nreg = TAS2557_PAGE_REG(reg);
        unsigned char pPageZero[] = {0x00, 0x00};
-       unsigned char pBook[] = {0x7F, book};
-       unsigned char pPage[] = {0x00, page};
-       unsigned char pData[] = {reg, 0x00, 0x00, 0x00, 0x00};
+       unsigned char pBook[] = {0x7F, nbook};
+       unsigned char pPage[] = {0x00, npage};
+       unsigned char pData[] = {nreg, 0x00, 0x00, 0x00, 0x00};
 
        tas2557_check_node();
 
@@ -149,52 +152,54 @@ uint32_t tas2557_switch_device(uint8_t i2cslave)
        return 0;
 }
 
-void tas2557_coeff_write(uint8_t book, uint8_t page, uint8_t reg, uint32_t data)
+#define TAS2557_mCDSP_SWAP_REG TAS2557_REG(0x8c, 0x19, 0x7c)
+#define TAS2557_uCDSP_SWAP_REG TAS2557_REG(0x00, 0x35, 0x2c)
+
+void tas2557_coeff_write(uint32_t reg, uint32_t data)
 {
        unsigned int nByte;
+       uint8_t nbook, npage, nreg;
 
-       if (gBinFile) // if the bin file is open, write the coefficients to the bin file
-       {
-               if(gnDev == gnDevA){
+       nbook = TAS2557_BOOK_ID(reg);
+       npage = TAS2557_PAGE_ID(reg);
+       nreg = TAS2557_PAGE_REG(reg);
+
+       // if the bin file is open, write the coefficients to the bin file
+       if (gBinFile) {
+               if (gnDev == gnDevA) {
                        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;
-                       
+                       gpDevABlock[index + 4] = nbook;
+                       gpDevABlock[index + 5] = npage;
+                       gpDevABlock[index + 6] = nreg;
+
                        for (nByte = 0; nByte < 4; nByte++)
-                       {
                                gpDevABlock[index + 7 + nByte] = (data >> ((3 - nByte) * 8)) & 0xFF;
-                       }
-                       
-                       gnDevABlockIndex += 3;                  
-               }
-               else if(gnDev == gnDevB)
-               {
+
+                       gnDevABlockIndex += 3;
+               } else if (gnDev == gnDevB) {
                        unsigned int index = gnDevBBlockIndex*4;
+
                        gpDevBBlock[index] = 0;
                        gpDevBBlock[index + 1] = 4;
                        gpDevBBlock[index + 2] = 0x85;
-                       gpDevBBlock[index + 4] = book;
-                       gpDevBBlock[index + 5] = page;
-                       gpDevBBlock[index + 6] = reg;
-                       
+                       gpDevBBlock[index + 4] = nbook;
+                       gpDevBBlock[index + 5] = npage;
+                       gpDevBBlock[index + 6] = nreg;
+
                        for (nByte = 0; nByte < 4; nByte++)
-                       {
                                gpDevBBlock[index + 7 + nByte] = (data >> ((3 - nByte) * 8)) & 0xFF;
-                       }
-                       
-                       gnDevBBlockIndex += 3;  
-               }               
-       }
-       else
-       {
+
+                       gnDevBBlockIndex += 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};
+               unsigned char pBook[] = {0x7F, nbook};
+               unsigned char pPage[] = {0x00, npage};
+               unsigned char pData[] = {nreg, (data & 0xFF000000) >> 24, (data & 0x00FF0000) >> 16, (data & 0x0000FF00) >> 8, data & 0x000000FF};
 
                tas2557_check_node();
 
@@ -203,10 +208,10 @@ void tas2557_coeff_write(uint8_t book, uint8_t page, uint8_t reg, uint32_t data)
                write(gTILoad, pPage, 2);
                write(gTILoad, pData, 5);
 
-               pBook[1] = 0x8C;
-               pPage[1] = 0x19;
+               pBook[1] = TAS2557_BOOK_ID(TAS2557_mCDSP_SWAP_REG);
+               pPage[1] = TAS2557_PAGE_ID(TAS2557_mCDSP_SWAP_REG);
 
-               pData[0] = 0x7C;
+               pData[0] = TAS2557_PAGE_REG(TAS2557_mCDSP_SWAP_REG);
                pData[1] = 0x00;
                pData[2] = 0x00;
                pData[3] = 0x00;
@@ -217,10 +222,10 @@ void tas2557_coeff_write(uint8_t book, uint8_t page, uint8_t reg, uint32_t data)
                write(gTILoad, pPage, 2);
                write(gTILoad, pData, 5);
 
-               pBook[1] = 0x00;
-               pPage[1] = 0x35;
+               pBook[1] = TAS2557_BOOK_ID(TAS2557_uCDSP_SWAP_REG);;
+               pPage[1] = TAS2557_PAGE_ID(TAS2557_uCDSP_SWAP_REG);
 
-               pData[0] = 0x2c;
+               pData[0] = TAS2557_PAGE_REG(TAS2557_uCDSP_SWAP_REG);
                pData[1] = 0x00;
                pData[2] = 0x00;
                pData[3] = 0x00;
@@ -378,10 +383,10 @@ void tas2557_close_bin(void)
        unsigned int nCommands;
        unsigned char pCommit[] = {
                0x00, 0x04, 0x85, 0x00,
-               0x8C, 0x19, 0x7C, 0x00,
+               TAS2557_BOOK_ID(TAS2557_mCDSP_SWAP_REG), TAS2557_PAGE_ID(TAS2557_mCDSP_SWAP_REG), TAS2557_PAGE_REG(TAS2557_mCDSP_SWAP_REG), 0x00,
                0x00, 0x00, 0x01, 0x00,
                0x00, 0x04, 0x85, 0x00,
-               0x00, 0x35, 0x2c, 0x00,
+               TAS2557_BOOK_ID(TAS2557_uCDSP_SWAP_REG), TAS2557_PAGE_ID(TAS2557_uCDSP_SWAP_REG), TAS2557_PAGE_REG(TAS2557_uCDSP_SWAP_REG), 0x00,
                0x00, 0x00, 0x01, 0x00
        };
 
index 01d8b793779770ae1b760a8e4d786c49536ba58f..90568ffe0146b8c91e39a28420dea704f0aad7d6 100755 (executable)
--- a/tas2557.h
+++ b/tas2557.h
 #include <stdint.h>\r
 #include "tas2557_ftc.h"\r
 \r
+/* 0000 0000 0BBB BBBB BPPP PPPP PRRR RRRR */\r
+\r
+#define TAS2557_REG(book, page, reg)           ((((unsigned int)book * 256 * 128) + \\r
+                                                ((unsigned int)page * 128)) + reg)\r
+\r
+#define TAS2557_BOOK_ID(reg)                   ((unsigned char)(reg / (256 * 128)))\r
+#define TAS2557_PAGE_ID(reg)                   ((unsigned char)((reg % (256 * 128)) / 128))\r
+#define TAS2557_BOOK_REG(reg)                  ((unsigned char)(reg % (256 * 128)))\r
+#define TAS2557_PAGE_REG(reg)                  ((unsigned char)((reg % (256 * 128)) % 128))\r
+\r
 #define TILOAD_IOC_MAGIC   0xE0\r
 \r
 #define TILOAD_IOCTL_SET_CHL                   _IOW(TILOAD_IOC_MAGIC, 5, int)\r
@@ -46,8 +56,8 @@
 uint8_t tas2557_get_PGID(void);\r
 void tas2557_mixer_command(char *pCommand, int nData);\r
 uint32_t tas2557_switch_device(uint8_t i2cslave);\r
-uint32_t tas2557_coeff_read(uint8_t book, uint8_t page, uint8_t reg);\r
-void tas2557_coeff_write(uint8_t book, uint8_t page, uint8_t reg, uint32_t data);\r
+uint32_t tas2557_coeff_read(uint32_t reg);\r
+void tas2557_coeff_write(uint32_t reg, uint32_t data);\r
 void tas2557_save_cal(struct TFTCConfiguration *pFTCC,\r
        double dev_a_re, uint32_t dev_a_rms_pow, uint32_t dev_a_t_limit, \r
        double dev_b_re, uint32_t dev_b_rms_pow, uint32_t dev_b_t_limit, \r
index de688e6e0675827cf834ecc12a4436bf02f069b0..a7f96f7a2ae73851cb7d0bade78081e2a0bf94fc 100755 (executable)
@@ -39,4 +39,5 @@ void set_temp_cal(uint32_t prm_pow, uint32_t prm_tlimit);
 double get_re(double re_ppc3);\r
 uint32_t calc_prm_pow(double re, double delta_t_max, double nRTV, double nRTM, double nRTVA, double nSysGain);\r
 uint32_t calc_prm_tlimit(double delta_t_max, double alpha, double nDevNonlinPer, double nRTV, double nRTM, double nRTVA);\r
+void tas2557_ftc_stop(void);\r
 #endif /* TAS2557_LIB_FTC_H_ */\r
index 0cd88f831fdf0b481d60dd2bbf61e354bae2cdab..9a125a048913decbc96ac497391aea1918ffc9da 100755 (executable)
@@ -47,18 +47,18 @@ static struct TFTCConfiguration *gpFTCC;
 uint32_t tas2557_ftc(double t_cal, struct TFTCConfiguration *pFTCC)\r
 {\r
        int nResult = 0;\r
-    double dev_a_re = pFTCC->nTSpkCharDevA.nPPC3_Re0;   // Default Re\r
-    uint32_t dev_a_prm_pow = 0;           // Total RMS power coefficient\r
-    uint32_t dev_a_prm_tlimit = 0;        // Delta temperature limit coefficient\r
-    double dev_b_re = pFTCC->nTSpkCharDevB.nPPC3_Re0;   // Default Re\r
-    uint32_t dev_b_prm_pow = 0;           // Total RMS power coefficient\r
-    uint32_t dev_b_prm_tlimit = 0;        // Delta temperature limit coefficient       \r
+       double dev_a_re = pFTCC->nTSpkCharDevA.nPPC3_Re0;   // Default Re\r
+       uint32_t dev_a_prm_pow = 0;           // Total RMS power coefficient\r
+       uint32_t dev_a_prm_tlimit = 0;        // Delta temperature limit coefficient\r
+       double dev_b_re = pFTCC->nTSpkCharDevB.nPPC3_Re0;   // Default Re\r
+       uint32_t dev_b_prm_pow = 0;           // Total RMS power coefficient\r
+       uint32_t dev_b_prm_tlimit = 0;        // Delta temperature limit coefficient\r
        uint8_t nPGID;\r
        uint32_t libVersion;\r
-    uint32_t result = 0;\r
-    pid_t nPlaybackProcess;\r
+       uint32_t result = 0;\r
+       pid_t nPlaybackProcess;\r
 \r
-    gpFTCC = pFTCC;\r
+       gpFTCC = pFTCC;\r
 \r
        libVersion = get_lib_ver();\r
        printf("libVersion=0x%x\r\n", libVersion);\r
@@ -71,30 +71,30 @@ uint32_t tas2557_ftc(double t_cal, struct TFTCConfiguration *pFTCC)
        /* set device PGID to FTC process */\r
        tas2557_ftc_set_PGID(nPGID);\r
 \r
-    // STEP 1: Play calibration signal\r
+       // STEP 1: Play calibration signal\r
        tas2557_mixer_command("PRI_MI2S_RX Audio Mixer MultiMedia1", 1); //platform dependent\r
-    nPlaybackProcess = sys_play_wav("silense.wav", "loop");\r
+       nPlaybackProcess = sys_play_wav("silense.wav", "loop");\r
 \r
        // STEP 2: start calibration process\r
        tas2557_switch_device(gpFTCC->nTSpkCharDevA.nDevAddr);\r
     tas2557_ftc_start();\r
        tas2557_switch_device(gpFTCC->nTSpkCharDevB.nDevAddr);\r
        tas2557_ftc_start();\r
-       \r
-    // STEP 3: Wait for algorithm to converge\r
-    sys_delay(gpFTCC->nCalibrationTime); // Delay \r
 \r
-    // STEP 4: Get actual Re from TAS2557\r
+       // STEP 3: Wait for algorithm to converge\r
+       sys_delay(gpFTCC->nCalibrationTime); // Delay \r
+\r
+       // STEP 4: Get actual Re from TAS2557\r
        tas2557_switch_device(gpFTCC->nTSpkCharDevA.nDevAddr);\r
-    dev_a_re = get_re(gpFTCC->nTSpkCharDevA.nPPC3_Re0);\r
+       dev_a_re = get_re(gpFTCC->nTSpkCharDevA.nPPC3_Re0);\r
        tas2557_switch_device(gpFTCC->nTSpkCharDevB.nDevAddr);\r
        dev_b_re = get_re(gpFTCC->nTSpkCharDevB.nPPC3_Re0);\r
 \r
        // STEP 5: check speaker bounds\r
        nResult = check_spk_bounds(gpFTCC, dev_a_re, dev_b_re);\r
-       \r
+\r
        // STEP 6: Set temperature limit to target TMAX\r
-       if((nResult& RE1_CHK_MSK) == RESULT_PASS){\r
+       if ((nResult& RE1_CHK_MSK) == RESULT_PASS) {\r
                tas2557_switch_device(gpFTCC->nTSpkCharDevA.nDevAddr);\r
                dev_a_prm_pow = calc_prm_pow (dev_a_re, \r
                        gpFTCC->nTSpkCharDevA.nSpkTMax - t_cal, \r
@@ -111,8 +111,8 @@ uint32_t tas2557_ftc(double t_cal, struct TFTCConfiguration *pFTCC)
                set_re(gpFTCC->nTSpkCharDevA.nPPC3_Re0, dev_a_re, gpFTCC->nTSpkCharDevA.nSpkReAlpha);\r
                set_temp_cal(dev_a_prm_pow, dev_a_prm_tlimit);\r
        }\r
-       \r
-       if((nResult& RE2_CHK_MSK) == RESULT_PASS){\r
+\r
+       if ((nResult& RE2_CHK_MSK) == RESULT_PASS) {\r
                tas2557_switch_device(gpFTCC->nTSpkCharDevB.nDevAddr);\r
                dev_b_prm_pow = calc_prm_pow (dev_b_re, \r
                        gpFTCC->nTSpkCharDevB.nSpkTMax - t_cal, \r
@@ -127,26 +127,32 @@ uint32_t tas2557_ftc(double t_cal, struct TFTCConfiguration *pFTCC)
                        gpFTCC->nTSpkCharDevB.nPPC3_RTM, \r
                        gpFTCC->nTSpkCharDevB.nPPC3_RTVA);\r
                set_re(gpFTCC->nTSpkCharDevB.nPPC3_Re0, dev_b_re, gpFTCC->nTSpkCharDevB.nSpkReAlpha);\r
-               set_temp_cal(dev_b_prm_pow, dev_b_prm_tlimit);  \r
+               set_temp_cal(dev_b_prm_pow, dev_b_prm_tlimit);\r
        }\r
 \r
-    sys_stop_wav(nPlaybackProcess);\r
+       // STEP 7: start calibration process\r
+       tas2557_switch_device(gpFTCC->nTSpkCharDevA.nDevAddr);\r
+       tas2557_ftc_stop();\r
+       tas2557_switch_device(gpFTCC->nTSpkCharDevB.nDevAddr);\r
+       tas2557_ftc_stop();\r
+\r
+       sys_stop_wav(nPlaybackProcess);\r
 \r
-    // STEP 8: Save Re, and Cal Temp into a file\r
-    tas2557_save_cal(gpFTCC, dev_a_re, dev_a_prm_pow, dev_a_prm_tlimit, \r
+       // STEP 8: Save Re, and Cal Temp into a file\r
+       tas2557_save_cal(gpFTCC, dev_a_re, dev_a_prm_pow, dev_a_prm_tlimit, \r
                dev_b_re, dev_b_prm_pow, dev_b_prm_tlimit, \r
                t_cal, nResult, "tas2557_cal.txt");\r
 \r
     // STEP 9: Save .bin file for TAS2555 driver\r
-       if((nResult & (RE1_CHK_MSK|RE2_CHK_MSK)) == RESULT_PASS){\r
+       if ((nResult & (RE1_CHK_MSK | RE2_CHK_MSK)) == RESULT_PASS) {\r
                tas2557_open_bin("tas2557_cal.bin", gpFTCC->nTSpkCharDevA.nDevAddr, gpFTCC->nTSpkCharDevB.nDevAddr);\r
-               if((nResult&RE1_CHK_MSK) == RESULT_PASS){\r
+               if ((nResult & RE1_CHK_MSK) == RESULT_PASS) {\r
                        tas2557_switch_device(gpFTCC->nTSpkCharDevA.nDevAddr);\r
                        set_re(gpFTCC->nTSpkCharDevA.nPPC3_Re0, dev_a_re, gpFTCC->nTSpkCharDevA.nSpkReAlpha);\r
                        set_temp_cal(dev_a_prm_pow, dev_a_prm_tlimit);\r
                }\r
 \r
-               if((nResult&RE2_CHK_MSK) == RESULT_PASS){\r
+               if ((nResult & RE2_CHK_MSK) == RESULT_PASS) {\r
                        tas2557_switch_device(gpFTCC->nTSpkCharDevB.nDevAddr);\r
                        set_re(gpFTCC->nTSpkCharDevB.nPPC3_Re0, dev_b_re, gpFTCC->nTSpkCharDevB.nSpkReAlpha);\r
                        set_temp_cal(dev_b_prm_pow, dev_b_prm_tlimit);\r
@@ -155,7 +161,8 @@ uint32_t tas2557_ftc(double t_cal, struct TFTCConfiguration *pFTCC)
                tas2557_close_bin();\r
        }\r
 \r
-       if (gpFTCC->bLoadCalibration) tas2557_load_calibration(0xFF);\r
+       if (gpFTCC->bLoadCalibration)\r
+               tas2557_load_calibration(0xFF);\r
 \r
        tas2557_ftc_release();\r
 \r