first commit
authora0220410 <peter-li@ti.com>
Wed, 18 May 2016 00:40:34 +0000 (08:40 +0800)
committera0220410 <peter-li@ti.com>
Wed, 18 May 2016 00:40:34 +0000 (08:40 +0800)
Android.mk [new file with mode: 0755]
CleanSpec.mk [new file with mode: 0755]
main.c [new file with mode: 0755]
ti_audio.h [new file with mode: 0755]

diff --git a/Android.mk b/Android.mk
new file mode 100755 (executable)
index 0000000..6597f47
--- /dev/null
@@ -0,0 +1,19 @@
+ifneq ($(TARGET_SIMULATOR), true)
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := main.c
+
+LOCAL_C_INCLUDES := external/ti_audio/
+
+LOCAL_CFLAGS := -O2 -g -W -Wall -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
+
+LOCAL_MODULE := ti_audio
+LOCAL_MODULE_TAGS := debug
+LOCAL_SYSTEM_SHARED_LIBRARIES := libc libm
+
+include $(BUILD_EXECUTABLE)
+
+endif
diff --git a/CleanSpec.mk b/CleanSpec.mk
new file mode 100755 (executable)
index 0000000..b84e1b6
--- /dev/null
@@ -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/main.c b/main.c
new file mode 100755 (executable)
index 0000000..a7402b8
--- /dev/null
+++ b/main.c
@@ -0,0 +1,757 @@
+/*
+** =============================================================================
+** 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:
+**     main.c
+**
+** Description:
+**     test program for TAS2555 Android Linux drivers
+**
+** =============================================================================
+*/
+
+#include <sys/cdefs.h>
+#include <sys/stat.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <math.h>
+#include <ctype.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdarg.h>
+#include <fcntl.h>
+#include "ti_audio.h"
+
+static void usage(){
+
+       fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
+               "usage: ti_audio -r book page register [count]               (read, hexdecimal)",
+               "       ti_audio -w book page register value1 [value2 ...]  (write, hexdecimal)",
+               "       ti_audio -d on                            (turn on the debug msg, bool)",
+               "       ti_audio -p [n]                                 (get/[set] DSP program)",
+               "       ti_audio -c [n]                           (get/[set] DSP configuration)",
+               "       ti_audio -s [n]                        (get/[set] sample rate, decimal)",
+               "       ti_audio -b [n]                           (get/[set] bit rate, decimal)",
+               "       ti_audio -v [n]                             (get/[set] volume, decimal)",
+               "       ti_audio -o on                              (turn on/off TAS2555, bool)",
+               "       ti_audio -t                                            (get firmware timestamp)",
+               "NOTE: 1. all numbers are Hexadecimal numbers without prefix 0x .",
+               TIAUDIO_VERSION);       
+}
+
+static int str2hexchar(char *argv, unsigned char *pUInt8_Val){
+       int str_len = strlen(argv), i, result = -1, j;
+       unsigned char val[2] = {0};
+
+       if(str_len > 2){
+               fprintf(stderr, "invalid parameters\n");
+               goto err;
+       }
+
+       for(i = (str_len-1), j=0; i >= 0; i--, j++){
+               if((argv[i] <= '9')&&(argv[i] >= '0')){
+                       val[j] = argv[i] - 0x30;
+               }else if((argv[i] <='f')&&(argv[i]>= 'a')){
+                       val[j] = argv[i] - 0x57;
+               }else if((argv[i] <='F')&&(argv[i]>= 'A')){
+                       val[j] = argv[i] - 0x37;
+               }else{
+                       fprintf(stderr, "reg/data out of range\n");
+                       goto err;
+               }
+       }
+       
+       *pUInt8_Val = (unsigned char)(val[0]|(val[1]<<4));
+       result = 0;
+       
+err:
+       return result;
+}
+
+static int str2hexshort(char *argv, unsigned short *pUInt16_Val){
+       int str_len = strlen(argv), i, j, result = -1;
+       unsigned char val[4] = {0};
+
+       if(str_len > 4){
+               fprintf(stderr, "invalid parameters\n");
+               goto err;
+       }
+
+       for(i = (str_len-1), j=0; i >= 0; i--, j++){
+               if((argv[i] <= '9')&&(argv[i] >= '0')){
+                       val[j] = argv[i] - 0x30;
+               }else if((argv[i] <='f')&&(argv[i]>= 'a')){
+                       val[j] = argv[i] - 0x57;
+               }else if((argv[i] <='F')&&(argv[i]>= 'A')){
+                       val[j] = argv[i] - 0x37;
+               }else{
+                       fprintf(stderr, "reg/data out of range\n");
+                       goto err;
+               }
+       }
+       
+       *pUInt16_Val = (unsigned short)(val[0]|(val[1]<<4)|(val[2]<<8)|(val[3]<<12));
+       result = 0;
+
+err:
+       return result;
+}
+
+static int str2decimal(char *argv, unsigned int *pUInt32_Val){
+       int max_len = strlen(MAX_INT_STR), i, result = -1, j;
+       int str_len = strlen(argv);
+       unsigned int nValue = 0;
+       unsigned char temp;
+
+       if(str_len > max_len){
+               fprintf(stderr, "invalid parameters\n");
+               goto err;
+       }
+       
+       for(i = 0; i <str_len; i++){
+               if((argv[i] <= '9')&&(argv[i] >= '0')){
+                       temp = argv[i] - 0x30;
+                       nValue += (temp * pow(10, i));
+               }else{
+                       fprintf(stderr, "reg/data out of range\n");
+                       goto err;
+               }
+       }
+       
+       *pUInt32_Val = nValue;
+       result = 0;
+       
+err:
+       return result;
+}
+
+static int TiAudio_Reg_Write(int fileHandle, int argc, char **argv){
+       int err = -1;
+       unsigned char *pBuff = NULL, book, page, reg,value, len;
+       unsigned int whole_reg = 0;
+       unsigned int temp_reg = 0;
+       int i=0, reg_count = 0;
+       
+       if(argc < 6){
+               fprintf(stderr, "invalid para numbers\n");
+               goto err;
+       }
+       
+       reg_count = argc - 5;
+
+       pBuff = (unsigned char *)malloc(reg_count + 5);
+       if(pBuff == NULL){
+               fprintf(stderr, "not enough mem\n");
+               goto err;               
+       }
+       
+       pBuff[0] = TIAUDIO_CMD_REG_WITE;
+       
+       err = str2hexchar(argv[2], &book);
+       if(err < 0){
+               goto err;
+       }
+       
+       err = str2hexchar(argv[3], &page);
+       if(err < 0){
+               goto err;
+       }
+       
+       err = str2hexchar(argv[4], &reg);
+       if(err < 0){
+               goto err;
+       }
+       
+       whole_reg = TAS2555_REG(book, page, reg);
+       pBuff[1] = (whole_reg & 0xff000000) >> 24;
+       pBuff[2] = (whole_reg & 0x00ff0000) >> 16;
+       pBuff[3] = (whole_reg & 0x0000ff00) >> 8;
+       pBuff[4] = (whole_reg & 0x000000ff) ;
+       
+       for(i=0; i< reg_count; i++){
+               err = str2hexchar(argv[i+5], &value);
+               if(err < 0){
+                       goto err;
+               }
+               pBuff[i + 5] = value;
+       }
+       
+       err = write(fileHandle, pBuff, reg_count+5);
+       if(err != (reg_count+5)){
+               fprintf(stderr, "write err=%d\n", err);
+       }else{
+               for(i=0; i< reg_count; i++){
+                       temp_reg = whole_reg + i;
+                       fprintf(stderr, "W B[%d]P[%d]R[%d]=0x%x\n", TAS2555_BOOK_ID(temp_reg), TAS2555_PAGE_ID(temp_reg), TAS2555_PAGE_REG(temp_reg), pBuff[i + 5] );
+               }
+       }       
+
+err:
+       if(pBuff != NULL)
+               free(pBuff);    
+       
+       return err;
+}
+
+static int TiAudio_Reg_Read(int fileHandle, int argc, char **argv){
+       int err = -1;
+       unsigned char *pBuff = NULL, book, page, reg,value, len;
+       unsigned int whole_reg = 0;
+       unsigned int temp_reg = 0;
+       int i=0, reg_count = 0;
+       
+       if((argc != 5) &&(argc != 6))  {
+               fprintf(stderr, "invalid para numbers\n");
+               goto err;
+       }
+       
+       if(argc == 5)
+               reg_count = 1;
+       else{
+               err = str2hexchar(argv[5], &len);
+               if(err < 0){
+                       goto err;
+               }
+               reg_count = len;
+       }
+       
+       pBuff = (unsigned char *)malloc(reg_count + 5);
+       if(pBuff == NULL){
+               fprintf(stderr, "not enough mem\n");
+               goto err;               
+       }
+       
+       pBuff[0] = TIAUDIO_CMD_REG_READ;
+       
+       err = str2hexchar(argv[2], &book);
+       if(err < 0){
+               goto err;
+       }
+       
+       err = str2hexchar(argv[3], &page);
+       if(err < 0){
+               goto err;
+       }
+       
+       err = str2hexchar(argv[4], &reg);
+       if(err < 0){
+               goto err;
+       }
+       
+       whole_reg = TAS2555_REG(book, page, reg);
+       pBuff[1] = (whole_reg & 0xff000000) >> 24;
+       pBuff[2] = (whole_reg & 0x00ff0000) >> 16;
+       pBuff[3] = (whole_reg & 0x0000ff00) >> 8;
+       pBuff[4] = (whole_reg & 0x000000ff) ;
+               
+       err = write(fileHandle, pBuff, 5);
+       if(err != 5){
+               fprintf(stderr, "read err=%d\n", err);
+               goto err;
+       }
+       
+       err = read(fileHandle, pBuff, reg_count);
+       if(err != reg_count){
+               fprintf(stderr, "read err=%d\n", err);
+               goto err;
+       }else{
+               for(i=0; i< reg_count; i++){
+                       temp_reg = whole_reg + i;
+                       fprintf(stderr, "R B[%d]P[%d]R[%d]=0x%x\n", TAS2555_BOOK_ID(temp_reg), TAS2555_PAGE_ID(temp_reg), TAS2555_PAGE_REG(temp_reg), pBuff[i]);
+               }
+       }       
+
+err:
+       if(pBuff != NULL)
+               free(pBuff);    
+       
+       return err;
+}
+
+static int TiAudio_Debug_On(int fileHandle, int argc, char **argv){
+       int err = -1;
+       unsigned char pBuff[2], on;
+       unsigned int whole_reg = 0;
+       unsigned int temp_reg = 0;
+       int i=0, reg_count = 0;
+       
+       if(argc != 3) {
+               fprintf(stderr, "invalid para numbers\n");
+               goto err;
+       }
+       
+       pBuff[0] = TIAUDIO_CMD_DEBUG_ON;
+       
+       err = str2hexchar(argv[2], &on);
+       if(err < 0){
+               goto err;
+       }
+       
+       pBuff[1] = on; 
+       
+       err = write(fileHandle, pBuff, 2);
+       if(err != 2){
+               fprintf(stderr, "set err=%d\n", err);
+               goto err;
+       }
+       
+       if(on == 0){
+               fprintf(stderr, "DBG msg Off\n");
+       }else{
+               fprintf(stderr, "DBG msg On\n");
+       }
+       
+err:
+
+       return err;
+}
+
+static int TiAudio_Program(int fileHandle, int argc, char **argv){
+       int err = -1;
+       unsigned char pBuff[PROGRAM_BUF_SIZE], bSet = 0, nProgram;
+       
+       if(argc == 2){
+               bSet = 0;
+       }else if(argc == 3){
+               bSet = 1;
+       }else{
+               fprintf(stderr, "invalid para numbers\n");
+               goto err;
+       }
+       
+       pBuff[0] = TIAUDIO_CMD_PROGRAM;
+       
+       if(bSet == 1){
+               err = str2hexchar(argv[2], &nProgram);
+               if(err < 0){
+                       goto err;
+               }
+               
+               pBuff[1] = nProgram;
+       }
+       
+       err = write(fileHandle, pBuff, (1+bSet));
+       if(err != (bSet+1)){
+               fprintf(stderr, "write err=%d\n", err);
+               goto err;
+       }
+       
+       if(bSet == 1){
+               fprintf(stderr, "Program Set to %d\n", nProgram);
+       }else{
+               err = read(fileHandle, pBuff, PROGRAM_BUF_SIZE);
+               if(err != PROGRAM_BUF_SIZE){
+                       fprintf(stderr, "read err=%d\n", err);
+                       goto err;
+               }else{
+                       unsigned char nPrograms = pBuff[0];
+                       unsigned char nCurProgram = pBuff[1];
+                       unsigned char *pName = &pBuff[2];
+                       unsigned char *pDescription = &pBuff[2 + FW_NAME_SIZE];
+                       fprintf(stderr, "Total Programs   : %d\n", nPrograms);
+                       fprintf(stderr, "Current Programs : %d\n", nCurProgram);
+                       fprintf(stderr, "\t Name: %s\n", pName);
+                       fprintf(stderr, "\t Description : %s\n", pDescription);
+               }
+       }
+
+err:
+
+       return err;
+}
+
+static int TiAudio_Configuration(int fileHandle, int argc, char **argv){
+       int err = -1;
+       unsigned char pBuff[CONFIGURATION_BUF_SIZE], bSet = 0, nConfiguration;
+       
+       if(argc == 2){
+               bSet = 0;
+       }else if(argc == 3){
+               bSet = 1;
+       }else{
+               fprintf(stderr, "invalid para numbers\n");
+               goto err;
+       }
+       
+       pBuff[0] = TIAUDIO_CMD_CONFIGURATION;
+       
+       if(bSet == 1){
+               err = str2hexchar(argv[2], &nConfiguration);
+               if(err < 0){
+                       goto err;
+               }
+               
+               pBuff[1] = nConfiguration;
+       }
+       
+       err = write(fileHandle, pBuff, (1+bSet));
+       if(err != (bSet+1)){
+               fprintf(stderr, "write err=%d\n", err);
+               goto err;
+       }
+       
+       if(bSet == 1){
+               fprintf(stderr, "Configuration Set to %d\n", nConfiguration);
+       }else{
+               err = read(fileHandle, pBuff, CONFIGURATION_BUF_SIZE);
+               if(err != CONFIGURATION_BUF_SIZE){
+                       fprintf(stderr, "read err=%d\n", err);
+                       goto err;
+               }else{
+                       unsigned char nConfigurations = pBuff[0];
+                       unsigned char nCurConfiguration = pBuff[1];
+                       unsigned char *pName = &pBuff[2];
+                       unsigned char nProgram = pBuff[2 + FW_NAME_SIZE];
+                       unsigned char nPLL = pBuff[3 + FW_NAME_SIZE];
+                       unsigned int nSampleRate = pBuff[4 + FW_NAME_SIZE] + 
+                               ((unsigned int)pBuff[5 + FW_NAME_SIZE] << 8) +
+                               ((unsigned int)pBuff[6 + FW_NAME_SIZE] << 16) +
+                               ((unsigned int)pBuff[7 + FW_NAME_SIZE] << 24);                  
+                       unsigned char *pDescription = &pBuff[8 + FW_NAME_SIZE];
+                       fprintf(stderr, "Total Configurations : %d\n", nConfigurations);
+                       fprintf(stderr, "Current Configuration: %d\n", nCurConfiguration);
+                       fprintf(stderr, "\t Name: %s\n", pName);
+                       fprintf(stderr, "\t Description : %s\n", pDescription);
+                       fprintf(stderr, "\t nProgram: %d\n", nProgram);
+                       fprintf(stderr, "\t nPLL: %d\n", nPLL);
+                       fprintf(stderr, "\t nSampleRate: %d\n", nSampleRate);
+               }
+       }
+
+err:
+
+       return err;
+}
+
+static int TiAudio_SampleRate(int fileHandle, int argc, char **argv){
+       int err = -1;
+       unsigned char pBuff[5];
+       unsigned char bSet = 0;
+       unsigned int nSampleRate;
+       
+       if(argc == 2){
+               bSet = 0;
+       }else if(argc == 3){
+               bSet = 1;
+       }else{
+               fprintf(stderr, "invalid para numbers\n");
+               goto err;
+       }
+       
+       pBuff[0] = TIAUDIO_CMD_SAMPLERATE;
+       
+       if(bSet == 1){
+               if(strcmp(argv[2], SR_STR_48K) == 0)
+                       nSampleRate = SR_NUM_48K;
+               else if(strcmp(argv[2], SR_STR_44K) == 0)
+                       nSampleRate = SR_NUM_44K;
+               else if(strcmp(argv[2], SR_STR_16K) == 0)
+                       nSampleRate = SR_NUM_16K;
+               else{
+                       fprintf(stderr, "invalid para numbers\n");
+                       goto err;
+               }
+               
+               pBuff[1] = (nSampleRate&0xff000000)>>24;
+               pBuff[2] = (nSampleRate&0x00ff0000)>>16;
+               pBuff[3] = (nSampleRate&0x0000ff00)>>8;
+               pBuff[4] = (nSampleRate&0x000000ff);
+       }
+       
+       err = write(fileHandle, pBuff, 1+(bSet?4:0));
+       if(err != (1+bSet?(4):(0))){
+               fprintf(stderr, "write err=%d\n", err);
+               goto err;
+       }
+       
+       if(bSet == 1){
+               fprintf(stderr, "Sample Rate Set to %d\n", nSampleRate);
+       }else{
+               err = read(fileHandle, pBuff, 4);
+               if(err != 4){
+                       fprintf(stderr, "read err=%d\n", err);
+                       goto err;
+               }else{
+                       nSampleRate = pBuff[0] + 
+                               ((unsigned int)pBuff[1] << 8) +
+                               ((unsigned int)pBuff[2] << 16) +
+                               ((unsigned int)pBuff[3] << 24);                 
+                       fprintf(stderr, "\t nSampleRate: %d\n", nSampleRate);
+               }
+       }
+
+err:
+
+       return err;
+}
+
+static int TiAudio_BitRate(int fileHandle, int argc, char **argv){
+       int err = -1;
+       unsigned char pBuff[5];
+       unsigned char bSet = 0;
+       unsigned int nBitRate;
+       
+       if(argc == 2){
+               bSet = 0;
+       }else if(argc == 3){
+               bSet = 1;
+       }else{
+               fprintf(stderr, "invalid para numbers\n");
+               goto err;
+       }
+       
+       pBuff[0] = TIAUDIO_CMD_BITRATE;
+       
+       if(bSet == 1){
+               if(strcmp(argv[2], "32") == 0)
+                       nBitRate = 32;
+               else if(strcmp(argv[2], "24") == 0)
+                       nBitRate = 24;
+               else if(strcmp(argv[2], "20") == 0)
+                       nBitRate = 20;
+               else if(strcmp(argv[2], "16") == 0)
+                       nBitRate = 16;                  
+               else{
+                       fprintf(stderr, "invalid para numbers\n");
+                       goto err;
+               }
+               
+               pBuff[1] = nBitRate;
+       }
+       
+       err = write(fileHandle, pBuff, (1+bSet));
+       if(err != (1+bSet)){
+               fprintf(stderr, "write err=%d\n", err);
+               goto err;
+       }
+       
+       if(bSet == 1){
+               fprintf(stderr, "BitRate Set to %d\n", nBitRate);
+       }else{
+               err = read(fileHandle, pBuff, 4);
+               if(err != 4){
+                       fprintf(stderr, "read err=%d\n", err);
+                       goto err;
+               }else{
+                       nBitRate = pBuff[0] + 
+                               ((unsigned int)pBuff[1] << 8) +
+                               ((unsigned int)pBuff[2] << 16) +
+                               ((unsigned int)pBuff[3] << 24);                 
+                       fprintf(stderr, "\t BitRate: %d\n", nBitRate);
+               }
+       }
+
+err:
+
+       return err;
+}
+
+static int TiAudio_DACVolume(int fileHandle, int argc, char **argv){
+       int err = -1;
+       unsigned char pBuff[5];
+       unsigned char bSet = 0;
+       unsigned int nVol;
+       
+       if(argc == 2){
+               bSet = 0;
+       }else if(argc == 3){
+               bSet = 1;
+       }else{
+               fprintf(stderr, "invalid para numbers\n");
+               goto err;
+       }
+       
+       pBuff[0] = TIAUDIO_CMD_DACVOLUME;
+       
+       if(bSet == 1){
+               err = str2decimal(argv[2], &nVol);
+               if(err < 0){
+                       goto err;
+               }
+               
+               pBuff[1] = nVol;
+       }
+       
+       err = write(fileHandle, pBuff, (1+bSet));
+       if(err != (1+bSet)){
+               fprintf(stderr, "write err=%d\n", err);
+               goto err;
+       }
+       
+       if(bSet == 1){
+               fprintf(stderr, "DAC Volume Set to %d\n", nVol);
+       }else{
+               err = read(fileHandle, pBuff, 1);
+               if(err != 1){
+                       fprintf(stderr, "read err=%d\n", err);
+                       goto err;
+               }else{
+                       nVol = pBuff[0];                
+                       fprintf(stderr, "\t nSampleRate: %d\n", nVol);
+               }
+       }
+
+err:
+
+       return err;
+}
+
+static int TiAudio_SpeakerOn(int fileHandle, int argc, char **argv){
+       int err = -1;
+       unsigned char pBuff[2], on;
+       unsigned int whole_reg = 0;
+       unsigned int temp_reg = 0;
+       int i=0, reg_count = 0;
+       
+       if(argc != 3) {
+               fprintf(stderr, "invalid para numbers\n");
+               goto err;
+       }
+       
+       pBuff[0] = TIAUDIO_CMD_SPEAKER;
+       
+       err = str2hexchar(argv[2], &on);
+       if(err < 0){
+               goto err;
+       }
+       
+       pBuff[1] = on; 
+       
+       err = write(fileHandle, pBuff, 2);
+       if(err != 2){
+               fprintf(stderr, "set err=%d\n", err);
+               goto err;
+       }
+       
+       if(on == 0){
+               fprintf(stderr, "TAS2555 Power Off\n");
+       }else{
+               fprintf(stderr, "TAS2555 Power On\n");
+       }
+       
+err:
+
+       return err;
+}
+
+static int TiAudio_Timestamp(int fileHandle, int argc, char **argv){
+       int err = -1;
+       unsigned char pBuff[4];
+       unsigned int nTimestamp = 0;
+       
+       pBuff[0] = TIAUDIO_CMD_FW_TIMESTAMP;
+       
+       err = write(fileHandle, pBuff, 1);
+       if(err != 1){
+               fprintf(stderr, "write err=%d\n", err);
+               goto err;
+       }
+       
+       err = read(fileHandle, pBuff, 4);
+       if(err != 4){
+               fprintf(stderr, "read err=%d\n", err);
+               goto err;
+       }else{
+               unsigned int nTimestamp = pBuff[0] + 
+                       ((unsigned int)pBuff[1] << 8) +
+                       ((unsigned int)pBuff[2] << 16) +
+                       ((unsigned int)pBuff[3] << 24);
+       
+               time_t t = (time_t)nTimestamp;  
+               struct tm *p;  
+               p=gmtime(&t);  
+               char s[100];  
+               strftime(s, sizeof(s), "%Y-%m-%d %H:%M:%S", p);  
+               fprintf(stderr, "FW Timestamp : %d: %s\n", (int)t, s); 
+       }
+
+err:
+
+       return err;
+}
+
+static int getDevHandle(){
+       int fileHandle = -1, i;
+       fileHandle = open(TI_AUDIO_NAME, O_RDWR);
+       if(fileHandle < 0 ){
+               fprintf(stderr, "[ERROR]file(%s) open_RDWR error\n", TI_AUDIO_NAME);
+       }               
+
+       return fileHandle;
+}
+
+int main(int argc, char **argv)
+{
+       int ret = 0;
+       int ch;
+       int fileHandle = -1;
+
+       fileHandle = getDevHandle();
+       if(fileHandle < 0 ){
+               fprintf(stderr, " file handle err=%d\n", fileHandle);
+               return ret;
+       }
+       
+       if(argc == 1){
+               usage();
+               return 0;
+       }
+
+       while ((ch = getopt(argc, argv, "wrdpcsbvot")) != -1) {
+               switch (ch) {
+               case 'w': 
+                       ret = TiAudio_Reg_Write(fileHandle, argc, argv);                        
+                       break;
+               case 'r':
+                       ret = TiAudio_Reg_Read(fileHandle, argc, argv);
+                       break;
+               case 'd':
+                       ret = TiAudio_Debug_On(fileHandle, argc, argv);
+                       break;          
+               case 'p':
+                       ret = TiAudio_Program(fileHandle, argc, argv);
+                       break;                                  
+               case 'c':
+                       ret = TiAudio_Configuration(fileHandle, argc, argv);
+                       break;          
+               case 's':
+                       ret = TiAudio_SampleRate(fileHandle, argc, argv);
+                       break;          
+               case 'b':
+                       ret = TiAudio_BitRate(fileHandle, argc, argv);
+                       break;
+               case 'v':
+                       ret = TiAudio_DACVolume(fileHandle, argc, argv);
+                       break;          
+               case 'o':
+                       ret = TiAudio_SpeakerOn(fileHandle, argc, argv);
+                       break;                          
+               case 't':
+                       ret = TiAudio_Timestamp(fileHandle, argc, argv);
+                       break;                                  
+               default:
+                       usage();
+                       break;
+               }
+       }
+
+       if(fileHandle > 0 )
+               close(fileHandle);
+       
+       return ret;
+}
diff --git a/ti_audio.h b/ti_audio.h
new file mode 100755 (executable)
index 0000000..5ec7592
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+** =============================================================================
+** 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:
+**     ti_audio.h
+**
+** Description:
+**     header file for the test program of TAS2555 Android Linux drivers
+**
+** =============================================================================
+*/
+#include <stdlib.h>
+#include <string.h>
+
+#define        TIAUDIO_VERSION         "Version : 3.0 (23th, March, 2016)"
+#define        TI_AUDIO_NAME           "/dev/tas2555"
+
+#define MAX_INT_STR    "4294967295"
+
+#define        SR_STR_48K      "48000"
+#define        SR_STR_44K      "44100"
+#define        SR_STR_16K      "16000"
+#define        SR_NUM_48K      48000
+#define        SR_NUM_44K      44100
+#define        SR_NUM_16K      16000
+
+#define        FW_NAME_SIZE                    64
+#define        FW_DESCRIPTION_SIZE             256
+#define        PROGRAM_BUF_SIZE                (2 + FW_NAME_SIZE + FW_DESCRIPTION_SIZE)
+#define        CONFIGURATION_BUF_SIZE  (8 + FW_NAME_SIZE + FW_DESCRIPTION_SIZE)
+
+#define        TIAUDIO_CMD_REG_WITE                    1
+#define        TIAUDIO_CMD_REG_READ                    2
+#define        TIAUDIO_CMD_DEBUG_ON                    3
+#define        TIAUDIO_CMD_PROGRAM                             4
+#define        TIAUDIO_CMD_CONFIGURATION               5
+#define        TIAUDIO_CMD_FW_TIMESTAMP                6
+#define        TIAUDIO_CMD_CALIBRATION                 7
+#define        TIAUDIO_CMD_SAMPLERATE                  8
+#define        TIAUDIO_CMD_BITRATE                             9
+#define        TIAUDIO_CMD_DACVOLUME                   10
+#define        TIAUDIO_CMD_SPEAKER                             11
+
+#define TAS2555_REG(book, page, reg)           (((book * 256 * 128) + \
+                                                (page * 128)) + reg)
+
+#define TAS2555_BOOK_ID(reg)                   (reg / (256 * 128))
+#define TAS2555_PAGE_ID(reg)                   ((reg % (256 * 128)) / 128)
+#define TAS2555_BOOK_REG(reg)                  (reg % (256 * 128))
+#define TAS2555_PAGE_REG(reg)                  ((reg % (256 * 128)) % 128)
+
+#define ARRAY_LEN(x) ((int)(sizeof(x)/sizeof((x)[0])))