]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - tas2557sw-android/tas2557-ftc.git/blobdiff - tas2557.c
Correct copyright information
[tas2557sw-android/tas2557-ftc.git] / tas2557.c
index 4d93ecd26ae23072a9b37991173619dc779ab19a..e052cb20f7a58709e6317ac51bda9df70044d84f 100755 (executable)
--- a/tas2557.c
+++ b/tas2557.c
@@ -2,18 +2,6 @@
 ** =============================================================================
 ** 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
 **
@@ -116,12 +104,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();
 
@@ -133,29 +124,40 @@ uint32_t tas2557_coeff_read(uint8_t book, uint8_t page, uint8_t reg)
        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)
+
+#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;
 
+       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 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;
+                       unsigned int index = gnDevABlockIndex*4;
+
+                       gpDevABlock[index] = 0;
+                       gpDevABlock[index + 1] = 4;
+                       gpDevABlock[index + 2] = 0x85;
+                       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 {
                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();
 
@@ -164,10 +166,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;
@@ -178,10 +180,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;
@@ -312,10 +314,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
        };
 
@@ -368,4 +370,4 @@ void tas2557_ftc_release(void)
                close(gTILoad);
                gTILoad = 0;
        }
-}
\ No newline at end of file
+}