From ba275735ca663e884e19378b72406b9be1559bf3 Mon Sep 17 00:00:00 2001 From: a0220410 Date: Mon, 4 Jul 2016 05:45:08 +0800 Subject: [PATCH] test utility for stereo solution (dual TAS2555) --- Android.mk | 19 ++ CleanSpec.mk | 49 +++ main.c | 929 +++++++++++++++++++++++++++++++++++++++++++++++++++ ti_audio.h | 70 ++++ 4 files changed, 1067 insertions(+) create mode 100755 Android.mk create mode 100755 CleanSpec.mk create mode 100755 main.c create mode 100755 ti_audio.h diff --git a/Android.mk b/Android.mk new file mode 100755 index 0000000..6597f47 --- /dev/null +++ b/Android.mk @@ -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 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/main.c b/main.c new file mode 100755 index 0000000..d9478d0 --- /dev/null +++ b/main.c @@ -0,0 +1,929 @@ +/* +** ============================================================================= +** 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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%s\n", + "usage: ti_audio -r channel book page register [count] (read, hexdecimal)", + " ti_audio -w channel 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, decimal)", + " ti_audio -c [n] (get/[set] DSP configuration, decimal)", + " ti_audio -s [n] (get/[set] sample rate, decimal)", + " ti_audio -b channel [n] (get/[set] bit rate, decimal)", + " ti_audio -v channel [n] (get/[set] volume, decimal)", + " ti_audio -f (trigger firmware reload)", + " ti_audio -o on (turn on/off TAS2555, bool)", + " ti_audio -t (get firmware timestamp)", + " channel: 1 - left channel, 2 - right channel, 3 - both channels", + 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 = (str_len-1), j=0; i >= 0; i--, j++){ + if((argv[i] <= '9')&&(argv[i] >= '0')){ + temp = argv[i] - 0x30; + nValue += (temp * pow(10, j)); + }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; + unsigned char channel; + unsigned int whole_reg = 0; + unsigned int temp_reg = 0; + int i=0, reg_count = 0; + unsigned char *pChannel; + + if(argc < 7){ + fprintf(stderr, "invalid para numbers\n"); + goto err; + } + + reg_count = argc - 6; + + 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], &channel); + if(err < 0){ + goto err; + } + + err = str2hexchar(argv[3], &book); + if(err < 0){ + goto err; + } + + err = str2hexchar(argv[4], &page); + if(err < 0){ + goto err; + } + + err = str2hexchar(argv[5], ®); + if(err < 0){ + goto err; + } + + pBuff[1] = channel; + if(channel == 1) + pChannel = LEFT_CHANNEL_STR; + else if(channel == 2) + pChannel = RIGHT_CHANNEL_STR; + else if(channel == 3){ + pChannel = BOTH_CHANNELS_STR; + } + else{ + fprintf(stderr, "chanel err=%d\n", channel); + goto err; + } + + whole_reg = TAS2555_REG(book, page, reg); + pBuff[2] = (whole_reg & 0xff000000) >> 24; + pBuff[3] = (whole_reg & 0x00ff0000) >> 16; + pBuff[4] = (whole_reg & 0x0000ff00) >> 8; + pBuff[5] = (whole_reg & 0x000000ff) ; + + for(i=0; i< reg_count; i++){ + err = str2hexchar(argv[i+6], &value); + if(err < 0){ + goto err; + } + pBuff[i + 6] = value; + } + + err = write(fileHandle, pBuff, reg_count+6); + if(err != (reg_count+6)){ + fprintf(stderr, "write err=%d\n", err); + }else{ + for(i=0; i< reg_count; i++){ + temp_reg = whole_reg + i; + fprintf(stderr, "W CHL[%s] B[%d]P[%d]R[%d]=0x%x\n", pChannel, + TAS2555_BOOK_ID(temp_reg), TAS2555_PAGE_ID(temp_reg), TAS2555_PAGE_REG(temp_reg), pBuff[i + 6] ); + } + } + +err: + if(pBuff != NULL) + free(pBuff); + + return err; +} + +static int TiAudio_Reg_Read(int fileHandle, int argc, char **argv){ + int err = -1; + unsigned char cmd[6]; + unsigned char *pBuff = NULL, book, page, reg, len; + unsigned int whole_reg = 0; + unsigned char channel; + unsigned int temp_reg = 0; + int i=0, reg_count = 0; + unsigned char *pChannel; + + if((argc != 6) &&(argc != 7)) { + fprintf(stderr, "invalid para numbers\n"); + goto err; + } + + if(argc == 6) + reg_count = 1; + else{ + err = str2hexchar(argv[6], &len); + if(err < 0){ + goto err; + } + reg_count = len; + } + + pBuff = (unsigned char *)malloc(reg_count); + if(pBuff == NULL){ + fprintf(stderr, "not enough mem\n"); + goto err; + } + + cmd[0] = TIAUDIO_CMD_REG_READ; + + err = str2hexchar(argv[2], &channel); + if(err < 0){ + goto err; + } + + err = str2hexchar(argv[3], &book); + if(err < 0){ + goto err; + } + + err = str2hexchar(argv[4], &page); + if(err < 0){ + goto err; + } + + err = str2hexchar(argv[5], ®); + if(err < 0){ + goto err; + } + + if((channel >= 1)&&(channel <=3)) + { + + }else{ + fprintf(stderr, "chanel err=%d\n", channel); + goto err; + } + + whole_reg = TAS2555_REG(book, page, reg); + cmd[2] = (whole_reg & 0xff000000) >> 24; + cmd[3] = (whole_reg & 0x00ff0000) >> 16; + cmd[4] = (whole_reg & 0x0000ff00) >> 8; + cmd[5] = (whole_reg & 0x000000ff) ; + + + if(channel&0x01){ + cmd[1] = 1; + pChannel = LEFT_CHANNEL_STR; + err = write(fileHandle, cmd, 6); + if(err != 6){ + 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 CHL[%s] B[%d]P[%d]R[%d]=0x%x\n", pChannel, + TAS2555_BOOK_ID(temp_reg), TAS2555_PAGE_ID(temp_reg), TAS2555_PAGE_REG(temp_reg), pBuff[i]); + } + } + } + + if(channel&0x02){ + cmd[1] = 2; + pChannel = RIGHT_CHANNEL_STR; + err = write(fileHandle, cmd, 6); + if(err != 6){ + 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 CHL[%s] B[%d]P[%d]R[%d]=0x%x\n", pChannel, + 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; + + 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; + unsigned int 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 = str2decimal(argv[2], &nProgram); + if(err < 0){ + fprintf(stderr, "invalid para numbers\n"); + 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; + unsigned int 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 = str2decimal(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; + int nLen; + + 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); + } + + if(bSet) nLen = 5; + else nLen = 1; + + err = write(fileHandle, pBuff, nLen); + if(err != nLen){ + 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 cmd[3]; + unsigned char pBuff[5]; + unsigned char bSet = 0; + unsigned char channel; + unsigned int nBitRate; + unsigned char *pChannel; + + if(argc == 3){ + bSet = 0; + }else if(argc == 4){ + bSet = 1; + }else{ + fprintf(stderr, "invalid para numbers\n"); + goto err; + } + + cmd[0] = TIAUDIO_CMD_BITRATE; + err = str2hexchar(argv[2], &channel); + if(err < 0){ + goto err; + } + + if((channel >= 1)&&(channel <=3)) + { + + }else{ + fprintf(stderr, "chanel err=%d\n", channel); + goto err; + } + + if(bSet == 1){ + if(strcmp(argv[3], "32") == 0) + nBitRate = 32; + else if(strcmp(argv[3], "24") == 0) + nBitRate = 24; + else if(strcmp(argv[3], "20") == 0) + nBitRate = 20; + else if(strcmp(argv[3], "16") == 0) + nBitRate = 16; + else{ + fprintf(stderr, "invalid para numbers\n"); + goto err; + } + + cmd[2] = nBitRate; + } + + if(channel&0x01){ + cmd[1] = 1; + pChannel = LEFT_CHANNEL_STR; + err = write(fileHandle, cmd, (2+bSet)); + if(err != (2+bSet)){ + fprintf(stderr, "write err=%d\n", err); + goto err; + } + + if(bSet == 1){ + fprintf(stderr, "CHL[%s] BitRate Set to %d\n", pChannel, nBitRate); + }else{ + err = read(fileHandle, pBuff, 1); + if(err != 1){ + fprintf(stderr, "read err=%d\n", err); + goto err; + }else{ + nBitRate = pBuff[0]; + fprintf(stderr, "\t CHL[%s] BitRate: %d\n", pChannel, nBitRate); + } + } + } + + if(channel&0x02){ + cmd[1] = 2; + pChannel = RIGHT_CHANNEL_STR; + err = write(fileHandle, cmd, (2+bSet)); + if(err != (2+bSet)){ + fprintf(stderr, "write err=%d\n", err); + goto err; + } + + if(bSet == 1){ + fprintf(stderr, "CHL[%s] BitRate Set to %d\n", pChannel, nBitRate); + }else{ + err = read(fileHandle, pBuff, 1); + if(err != 1){ + fprintf(stderr, "read err=%d\n", err); + goto err; + }else{ + nBitRate = pBuff[0]; + fprintf(stderr, "\t CHL[%s] BitRate: %d\n", pChannel, nBitRate); + } + } + } + +err: + + return err; +} + +static int TiAudio_DACVolume(int fileHandle, int argc, char **argv){ + int err = -1; + unsigned char cmd[3]; + unsigned char pBuff[5]; + unsigned char bSet = 0; + unsigned int nVol; + unsigned char channel; + unsigned char *pChannel; + + if(argc == 3){ + bSet = 0; + }else if(argc == 4){ + bSet = 1; + }else{ + fprintf(stderr, "invalid para numbers\n"); + goto err; + } + + cmd[0] = TIAUDIO_CMD_DACVOLUME; + + err = str2hexchar(argv[2], &channel); + if(err < 0){ + goto err; + } + + if((channel >= 1)&&(channel <=3)) + { + + }else{ + fprintf(stderr, "chanel err=%d\n", channel); + goto err; + } + + if(bSet == 1){ + err = str2decimal(argv[3], &nVol); + if(err < 0){ + goto err; + } + + cmd[2] = nVol; + } + + if(channel&0x01){ + cmd[1] = 1; + pChannel = LEFT_CHANNEL_STR; + err = write(fileHandle, cmd, (2+bSet)); + if(err != (2+bSet)){ + fprintf(stderr, "write err=%d\n", err); + goto err; + } + + if(bSet == 1){ + fprintf(stderr, "CHL[%s] DAC Volume Set to %d\n", pChannel, 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, "\tCHL[%s] DAC Volume: %d\n", pChannel, nVol); + } + } + } + + if(channel&0x02){ + cmd[1] = 2; + pChannel = RIGHT_CHANNEL_STR; + err = write(fileHandle, cmd, (2+bSet)); + if(err != (2+bSet)){ + fprintf(stderr, "write err=%d\n", err); + goto err; + } + + if(bSet == 1){ + fprintf(stderr, "CHL[%s] DAC Volume Set to %d\n", pChannel, 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, "\tCHL[%s] DAC Volume: %d\n", pChannel, nVol); + } + } + } + +err: + + return err; +} + +static int TiAudio_SpeakerOn(int fileHandle, int argc, char **argv){ + int err = -1; + unsigned char pBuff[2], on; + + 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]; + + 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=localtime(&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 TiAudio_TriggerFWReload(int fileHandle, int argc, char **argv){ + int err = -1; + unsigned char pBuff[4]; + pBuff[0] = TIAUDIO_CMD_FW_RELOAD; + + err = write(fileHandle, pBuff, 1); + if(err != 1){ + fprintf(stderr, "write err=%d\n", err); + goto err; + } + + fprintf(stderr, "Firmware Reload Triggered\n"); + +err: + + return err; +} + +static int getDevHandle(){ + int fileHandle = -1; + 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, "wrdpcsbvotf")) != -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; + case 'f': + ret = TiAudio_TriggerFWReload(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 index 0000000..21d5dbd --- /dev/null +++ b/ti_audio.h @@ -0,0 +1,70 @@ +/* +** ============================================================================= +** 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 +#include + +#define TIAUDIO_VERSION "Version : 3.1 (20th, May, 2016)" +#define TI_AUDIO_NAME "/dev/tas2555s" + +#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 LEFT_CHANNEL_STR "L" +#define RIGHT_CHANNEL_STR "R" +#define BOTH_CHANNELS_STR "L R" + +#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 TIAUDIO_CMD_FW_RELOAD 12 + +#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]))) -- 2.39.2