summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Li2017-04-19 18:11:18 -0500
committerPeter Li2017-04-19 18:11:18 -0500
commitb1eaea6c7d7b275aa21335781a07e1dc6aa32b8e (patch)
tree6ebf08f39e8e0b02748744ef6fbc1a49a29f8589
downloadtas2559-utility-master.tar.gz
tas2559-utility-master.tar.xz
tas2559-utility-master.zip
debug toolHEADmaster
-rwxr-xr-xti_audio/Android.mk19
-rwxr-xr-xti_audio/CleanSpec.mk49
-rwxr-xr-xti_audio/main.c996
-rwxr-xr-xti_audio/ti_audio.h71
4 files changed, 1135 insertions, 0 deletions
diff --git a/ti_audio/Android.mk b/ti_audio/Android.mk
new file mode 100755
index 0000000..6597f47
--- /dev/null
+++ b/ti_audio/Android.mk
@@ -0,0 +1,19 @@
1ifneq ($(TARGET_SIMULATOR), true)
2
3LOCAL_PATH := $(call my-dir)
4
5include $(CLEAR_VARS)
6
7LOCAL_SRC_FILES := main.c
8
9LOCAL_C_INCLUDES := external/ti_audio/
10
11LOCAL_CFLAGS := -O2 -g -W -Wall -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
12
13LOCAL_MODULE := ti_audio
14LOCAL_MODULE_TAGS := debug
15LOCAL_SYSTEM_SHARED_LIBRARIES := libc libm
16
17include $(BUILD_EXECUTABLE)
18
19endif
diff --git a/ti_audio/CleanSpec.mk b/ti_audio/CleanSpec.mk
new file mode 100755
index 0000000..b84e1b6
--- /dev/null
+++ b/ti_audio/CleanSpec.mk
@@ -0,0 +1,49 @@
1# Copyright (C) 2007 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14#
15
16# If you don't need to do a full clean build but would like to touch
17# a file or delete some intermediate files, add a clean step to the end
18# of the list. These steps will only be run once, if they haven't been
19# run before.
20#
21# E.g.:
22# $(call add-clean-step, touch -c external/sqlite/sqlite3.h)
23# $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libz_intermediates)
24#
25# Always use "touch -c" and "rm -f" or "rm -rf" to gracefully deal with
26# files that are missing or have been moved.
27#
28# Use $(PRODUCT_OUT) to get to the "out/target/product/blah/" directory.
29# Use $(OUT_DIR) to refer to the "out" directory.
30#
31# If you need to re-do something that's already mentioned, just copy
32# the command and add it to the bottom of the list. E.g., if a change
33# that you made last week required touching a file and a change you
34# made today requires touching the same file, just copy the old
35# touch step and add it to the end of the list.
36#
37# ************************************************
38# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
39# ************************************************
40
41# For example:
42#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/AndroidTests_intermediates)
43#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/core_intermediates)
44#$(call add-clean-step, find $(OUT_DIR) -type f -name "IGTalkSession*" -print0 | xargs -0 rm -f)
45#$(call add-clean-step, rm -rf $(PRODUCT_OUT)/data/*)
46
47# ************************************************
48# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
49# ************************************************
diff --git a/ti_audio/main.c b/ti_audio/main.c
new file mode 100755
index 0000000..15c3776
--- /dev/null
+++ b/ti_audio/main.c
@@ -0,0 +1,996 @@
1/*
2** =============================================================================
3** Copyright (c) 2016 Texas Instruments Inc.
4**
5** This program is free software; you can redistribute it and/or modify it under
6** the terms of the GNU General Public License as published by the Free Software
7** Foundation; version 2.
8**
9** This program is distributed in the hope that it will be useful, but WITHOUT
10** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11** FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12**
13** You should have received a copy of the GNU General Public License along with
14** this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15** Street, Fifth Floor, Boston, MA 02110-1301, USA.
16**
17** File:
18** main.c
19**
20** Description:
21** test program for TAS2557 Android Linux drivers
22**
23** =============================================================================
24*/
25
26#include <sys/cdefs.h>
27#include <sys/stat.h>
28#include <stdlib.h>
29#include <string.h>
30#include <time.h>
31#include <math.h>
32#include <ctype.h>
33#include <stdio.h>
34#include <unistd.h>
35#include <errno.h>
36#include <stdarg.h>
37#include <fcntl.h>
38#include "ti_audio.h"
39
40static void usage(){
41
42 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%s\n",
43 "usage: ti_audio_s -r channel book page register [count] (read, hexdecimal)",
44 " ti_audio_s -w channel book page register value1 [value2 ...] (write, hexdecimal)",
45 " ti_audio_s -d on (turn on the debug msg, bool)",
46 " ti_audio_s -p [n] (get/[set] DSP program, decimal)",
47 " ti_audio_s -c [n] (get/[set] DSP configuration, decimal)",
48 " ti_audio_s -s [n] (get/[set] sample rate, decimal)",
49 " ti_audio_s -b channel [n] (get/[set] bit rate, decimal)",
50 " ti_audio_s -v channel [n] (get/[set] volume, decimal)",
51 " ti_audio_s -f (trigger firmware reload)",
52 " ti_audio_s -o on (turn on/off TAS2559, bool)",
53 " ti_audio_s -m channel mute (mute or unmute device(s))",
54 " ti_audio_s -t (get firmware timestamp)",
55 " channel: 1 - DevA, 2 - DevB, 3 - both",
56 TIAUDIO_VERSION);
57}
58
59static int str2hexchar(char *argv, unsigned char *pUInt8_Val){
60 int str_len = strlen(argv), i, result = -1, j;
61 unsigned char val[2] = {0};
62
63 if(str_len > 2){
64 fprintf(stderr, "invalid parameters\n");
65 goto err;
66 }
67
68 for(i = (str_len-1), j=0; i >= 0; i--, j++){
69 if((argv[i] <= '9')&&(argv[i] >= '0')){
70 val[j] = argv[i] - 0x30;
71 }else if((argv[i] <='f')&&(argv[i]>= 'a')){
72 val[j] = argv[i] - 0x57;
73 }else if((argv[i] <='F')&&(argv[i]>= 'A')){
74 val[j] = argv[i] - 0x37;
75 }else{
76 fprintf(stderr, "reg/data out of range\n");
77 goto err;
78 }
79 }
80
81 *pUInt8_Val = (unsigned char)(val[0]|(val[1]<<4));
82 result = 0;
83
84err:
85 return result;
86}
87
88/*
89static int str2hexshort(char *argv, unsigned short *pUInt16_Val){
90 int str_len = strlen(argv), i, j, result = -1;
91 unsigned char val[4] = {0};
92
93 if(str_len > 4){
94 fprintf(stderr, "invalid parameters\n");
95 goto err;
96 }
97
98 for(i = (str_len-1), j=0; i >= 0; i--, j++){
99 if((argv[i] <= '9')&&(argv[i] >= '0')){
100 val[j] = argv[i] - 0x30;
101 }else if((argv[i] <='f')&&(argv[i]>= 'a')){
102 val[j] = argv[i] - 0x57;
103 }else if((argv[i] <='F')&&(argv[i]>= 'A')){
104 val[j] = argv[i] - 0x37;
105 }else{
106 fprintf(stderr, "reg/data out of range\n");
107 goto err;
108 }
109 }
110
111 *pUInt16_Val = (unsigned short)(val[0]|(val[1]<<4)|(val[2]<<8)|(val[3]<<12));
112 result = 0;
113
114err:
115 return result;
116}
117*/
118
119static int str2decimal(char *argv, unsigned int *pUInt32_Val){
120 int max_len = strlen(MAX_INT_STR), i, result = -1, j;
121 int str_len = strlen(argv);
122 unsigned int nValue = 0;
123 unsigned char temp;
124
125 if(str_len > max_len){
126 fprintf(stderr, "invalid parameters\n");
127 goto err;
128 }
129
130 for(i = (str_len-1), j=0; i >= 0; i--, j++){
131 if((argv[i] <= '9')&&(argv[i] >= '0')){
132 temp = argv[i] - 0x30;
133 nValue += (temp * pow(10, j));
134 }else{
135 fprintf(stderr, "reg/data out of range\n");
136 goto err;
137 }
138 }
139
140 *pUInt32_Val = nValue;
141 result = 0;
142
143err:
144 return result;
145}
146
147static int TiAudio_Reg_Write(int fileHandle, int argc, char **argv){
148 int err = -1;
149 unsigned char *pBuff = NULL, book, page, reg,value;
150 unsigned char channel;
151 unsigned int whole_reg = 0;
152 unsigned int temp_reg = 0;
153 int i=0, reg_count = 0;
154 char *pChannel;
155
156 if(argc < 7){
157 fprintf(stderr, "invalid para numbers\n");
158 goto err;
159 }
160
161 reg_count = argc - 6;
162
163 pBuff = (unsigned char *)malloc(reg_count + 5);
164 if(pBuff == NULL){
165 fprintf(stderr, "not enough mem\n");
166 goto err;
167 }
168
169 pBuff[0] = TIAUDIO_CMD_REG_WITE;
170
171 err = str2hexchar(argv[2], &channel);
172 if(err < 0){
173 goto err;
174 }
175
176 err = str2hexchar(argv[3], &book);
177 if(err < 0){
178 goto err;
179 }
180
181 err = str2hexchar(argv[4], &page);
182 if(err < 0){
183 goto err;
184 }
185
186 err = str2hexchar(argv[5], &reg);
187 if(err < 0){
188 goto err;
189 }
190
191 pBuff[1] = channel;
192 if(channel == 1)
193 pChannel = LEFT_CHANNEL_STR;
194 else if(channel == 2)
195 pChannel = RIGHT_CHANNEL_STR;
196 else if(channel == 3){
197 pChannel = BOTH_CHANNELS_STR;
198 }
199 else{
200 fprintf(stderr, "chanel err=%d\n", channel);
201 goto err;
202 }
203
204 whole_reg = TAS2555_REG(book, page, reg);
205 pBuff[2] = (whole_reg & 0xff000000) >> 24;
206 pBuff[3] = (whole_reg & 0x00ff0000) >> 16;
207 pBuff[4] = (whole_reg & 0x0000ff00) >> 8;
208 pBuff[5] = (whole_reg & 0x000000ff) ;
209
210 for(i=0; i< reg_count; i++){
211 err = str2hexchar(argv[i+6], &value);
212 if(err < 0){
213 goto err;
214 }
215 pBuff[i + 6] = value;
216 }
217
218 err = write(fileHandle, pBuff, reg_count+6);
219 if(err != (reg_count+6)){
220 fprintf(stderr, "write err=%d\n", err);
221 }else{
222 for(i=0; i< reg_count; i++){
223 temp_reg = whole_reg + i;
224 fprintf(stderr, "W CHL[%s] B[%d]P[%d]R[%d]=0x%x\n", pChannel,
225 TAS2555_BOOK_ID(temp_reg), TAS2555_PAGE_ID(temp_reg), TAS2555_PAGE_REG(temp_reg), pBuff[i + 6] );
226 }
227 }
228
229err:
230 if(pBuff != NULL)
231 free(pBuff);
232
233 return err;
234}
235
236static int TiAudio_Reg_Read(int fileHandle, int argc, char **argv){
237 int err = -1;
238 unsigned char cmd[6];
239 unsigned char *pBuff = NULL, book, page, reg, len;
240 unsigned int whole_reg = 0;
241 unsigned char channel;
242 unsigned int temp_reg = 0;
243 int i=0, reg_count = 0;
244 char *pChannel;
245
246 if((argc != 6) &&(argc != 7)) {
247 fprintf(stderr, "invalid para numbers\n");
248 goto err;
249 }
250
251 if(argc == 6)
252 reg_count = 1;
253 else{
254 err = str2hexchar(argv[6], &len);
255 if(err < 0){
256 goto err;
257 }
258 reg_count = len;
259 }
260
261 pBuff = (unsigned char *)malloc(reg_count);
262 if(pBuff == NULL){
263 fprintf(stderr, "not enough mem\n");
264 goto err;
265 }
266
267 cmd[0] = TIAUDIO_CMD_REG_READ;
268
269 err = str2hexchar(argv[2], &channel);
270 if(err < 0){
271 goto err;
272 }
273
274 err = str2hexchar(argv[3], &book);
275 if(err < 0){
276 goto err;
277 }
278
279 err = str2hexchar(argv[4], &page);
280 if(err < 0){
281 goto err;
282 }
283
284 err = str2hexchar(argv[5], &reg);
285 if(err < 0){
286 goto err;
287 }
288
289 if((channel >= 1)&&(channel <=3))
290 {
291
292 }else{
293 fprintf(stderr, "chanel err=%d\n", channel);
294 goto err;
295 }
296
297 whole_reg = TAS2555_REG(book, page, reg);
298 cmd[2] = (whole_reg & 0xff000000) >> 24;
299 cmd[3] = (whole_reg & 0x00ff0000) >> 16;
300 cmd[4] = (whole_reg & 0x0000ff00) >> 8;
301 cmd[5] = (whole_reg & 0x000000ff) ;
302
303
304 if(channel&0x01){
305 cmd[1] = 1;
306 pChannel = LEFT_CHANNEL_STR;
307 err = write(fileHandle, cmd, 6);
308 if(err != 6){
309 fprintf(stderr, "read err=%d\n", err);
310 goto err;
311 }
312
313 err = read(fileHandle, pBuff, reg_count);
314 if(err != reg_count){
315 fprintf(stderr, "read err=%d\n", err);
316 goto err;
317 }else{
318 for(i=0; i< reg_count; i++){
319 temp_reg = whole_reg + i;
320 fprintf(stderr, "R CHL[%s] B[%d]P[%d]R[%d]=0x%x\n", pChannel,
321 TAS2555_BOOK_ID(temp_reg), TAS2555_PAGE_ID(temp_reg), TAS2555_PAGE_REG(temp_reg), pBuff[i]);
322 }
323 }
324 }
325
326 if(channel&0x02){
327 cmd[1] = 2;
328 pChannel = RIGHT_CHANNEL_STR;
329 err = write(fileHandle, cmd, 6);
330 if(err != 6){
331 fprintf(stderr, "read err=%d\n", err);
332 goto err;
333 }
334
335 err = read(fileHandle, pBuff, reg_count);
336 if(err != reg_count){
337 fprintf(stderr, "read err=%d\n", err);
338 goto err;
339 }else{
340 for(i=0; i< reg_count; i++){
341 temp_reg = whole_reg + i;
342 fprintf(stderr, "R CHL[%s] B[%d]P[%d]R[%d]=0x%x\n", pChannel,
343 TAS2555_BOOK_ID(temp_reg), TAS2555_PAGE_ID(temp_reg), TAS2555_PAGE_REG(temp_reg), pBuff[i]);
344 }
345 }
346 }
347
348
349err:
350 if(pBuff != NULL)
351 free(pBuff);
352
353 return err;
354}
355
356static int TiAudio_Debug_On(int fileHandle, int argc, char **argv){
357 int err = -1;
358 unsigned char pBuff[2], on;
359
360 if(argc != 3) {
361 fprintf(stderr, "invalid para numbers\n");
362 goto err;
363 }
364
365 pBuff[0] = TIAUDIO_CMD_DEBUG_ON;
366
367 err = str2hexchar(argv[2], &on);
368 if(err < 0){
369 goto err;
370 }
371
372 pBuff[1] = on;
373
374 err = write(fileHandle, pBuff, 2);
375 if(err != 2){
376 fprintf(stderr, "set err=%d\n", err);
377 goto err;
378 }
379
380 if(on == 0){
381 fprintf(stderr, "DBG msg Off\n");
382 }else{
383 fprintf(stderr, "DBG msg On\n");
384 }
385
386err:
387
388 return err;
389}
390
391static int TiAudio_Program(int fileHandle, int argc, char **argv){
392 int err = -1;
393 unsigned char pBuff[PROGRAM_BUF_SIZE], bSet = 0;
394 unsigned int nProgram;
395
396 if(argc == 2){
397 bSet = 0;
398 }else if(argc == 3){
399 bSet = 1;
400 }else{
401 fprintf(stderr, "invalid para numbers\n");
402 goto err;
403 }
404
405 pBuff[0] = TIAUDIO_CMD_PROGRAM;
406
407 if(bSet == 1){
408 err = str2decimal(argv[2], &nProgram);
409 if(err < 0){
410 fprintf(stderr, "invalid para numbers\n");
411 goto err;
412 }
413
414 pBuff[1] = nProgram;
415 }
416
417 err = write(fileHandle, pBuff, (1+bSet));
418 if(err != (bSet+1)){
419 fprintf(stderr, "write err=%d\n", err);
420 goto err;
421 }
422
423 if(bSet == 1){
424 fprintf(stderr, "Program Set to %d\n", nProgram);
425 }else{
426 err = read(fileHandle, pBuff, PROGRAM_BUF_SIZE);
427 if(err != PROGRAM_BUF_SIZE){
428 fprintf(stderr, "read err=%d\n", err);
429 goto err;
430 }else{
431 unsigned char nPrograms = pBuff[0];
432 unsigned char nCurProgram = pBuff[1];
433 unsigned char nAppMode = pBuff[2];
434 unsigned short nBoost = ((unsigned short)pBuff[3]<<8) + pBuff[4];
435 unsigned char *pName = &pBuff[5];
436 unsigned char *pDescription = &pBuff[5 + FW_NAME_SIZE];
437
438 if(nAppMode == 0)
439 fprintf(stderr, "\t AppMode : %s\n", "ROM1");
440 else if(nAppMode == 1)
441 fprintf(stderr, "\t AppMode : %s\n", "ROM2");
442 else if(nAppMode == 2)
443 fprintf(stderr, "\t AppMode : %s\n", "Tuning Mode");
444 else
445 fprintf(stderr, "\t AppMode : %d (unknown)\n", nAppMode);
446
447 if (nBoost == 0)
448 fprintf(stderr, "\t BoostMode : %s\n", "BOOST_OFF");
449 else if (nBoost == 1)
450 fprintf(stderr, "\t BoostMode : %s\n", "ROOST_ON_DEV_A");
451 else if (nBoost == 2)
452 fprintf(stderr, "\t BoostMode : %s\n", "ROOST_ON_DEV_B");
453 else if (nBoost == 3)
454 fprintf(stderr, "\t BoostMode : %s\n", "ROOST_ON_BOTH");
455 else
456 fprintf(stderr, "\t BoostMode : %d(unknown)\n", nBoost);
457
458 fprintf(stderr, "Total Programs : %d\n", nPrograms);
459 fprintf(stderr, "Current Programs : %d\n", nCurProgram);
460 fprintf(stderr, "\t Name: %s\n", pName);
461 fprintf(stderr, "\t Description : %s\n", pDescription);
462 }
463 }
464
465err:
466
467 return err;
468}
469
470static int TiAudio_Configuration(int fileHandle, int argc, char **argv){
471 int err = -1;
472 unsigned char pBuff[CONFIGURATION_BUF_SIZE], bSet = 0;
473 unsigned int nConfiguration;
474
475 if(argc == 2){
476 bSet = 0;
477 }else if(argc == 3){
478 bSet = 1;
479 }else{
480 fprintf(stderr, "invalid para numbers\n");
481 goto err;
482 }
483
484 pBuff[0] = TIAUDIO_CMD_CONFIGURATION;
485
486 if(bSet == 1){
487 err = str2decimal(argv[2], &nConfiguration);
488 if(err < 0){
489 goto err;
490 }
491
492 pBuff[1] = nConfiguration;
493 }
494
495 err = write(fileHandle, pBuff, (1+bSet));
496 if(err != (bSet+1)){
497 fprintf(stderr, "write err=%d\n", err);
498 goto err;
499 }
500
501 if(bSet == 1){
502 fprintf(stderr, "Configuration Set to %d\n", nConfiguration);
503 }else{
504 err = read(fileHandle, pBuff, CONFIGURATION_BUF_SIZE);
505 if(err != CONFIGURATION_BUF_SIZE){
506 fprintf(stderr, "read err=%d\n", err);
507 goto err;
508 }else{
509 unsigned char nConfigurations = pBuff[0];
510 unsigned char nCurConfiguration = pBuff[1];
511 unsigned char *pName = &pBuff[2];
512 unsigned char nProgram = pBuff[2 + FW_NAME_SIZE];
513 unsigned char nPLL = pBuff[3 + FW_NAME_SIZE];
514 unsigned int nSampleRate = pBuff[4 + FW_NAME_SIZE] +
515 ((unsigned int)pBuff[5 + FW_NAME_SIZE] << 8) +
516 ((unsigned int)pBuff[6 + FW_NAME_SIZE] << 16) +
517 ((unsigned int)pBuff[7 + FW_NAME_SIZE] << 24);
518 unsigned char *pDescription = &pBuff[8 + FW_NAME_SIZE];
519 fprintf(stderr, "Total Configurations : %d\n", nConfigurations);
520 fprintf(stderr, "Current Configuration: %d\n", nCurConfiguration);
521 fprintf(stderr, "\t Name: %s\n", pName);
522 fprintf(stderr, "\t Description : %s\n", pDescription);
523 fprintf(stderr, "\t nProgram: %d\n", nProgram);
524 fprintf(stderr, "\t nPLL: %d\n", nPLL);
525 fprintf(stderr, "\t nSampleRate: %d\n", nSampleRate);
526 }
527 }
528
529err:
530
531 return err;
532}
533
534static int TiAudio_SampleRate(int fileHandle, int argc, char **argv){
535 int err = -1;
536 unsigned char pBuff[5];
537 unsigned char bSet = 0;
538 unsigned int nSampleRate;
539 int nLen;
540
541 if(argc == 2){
542 bSet = 0;
543 }else if(argc == 3){
544 bSet = 1;
545 }else{
546 fprintf(stderr, "invalid para numbers\n");
547 goto err;
548 }
549
550 pBuff[0] = TIAUDIO_CMD_SAMPLERATE;
551
552 if(bSet == 1){
553 if(strcmp(argv[2], SR_STR_48K) == 0)
554 nSampleRate = SR_NUM_48K;
555 else if(strcmp(argv[2], SR_STR_44K) == 0)
556 nSampleRate = SR_NUM_44K;
557 else if(strcmp(argv[2], SR_STR_16K) == 0)
558 nSampleRate = SR_NUM_16K;
559 else{
560 fprintf(stderr, "invalid para numbers\n");
561 goto err;
562 }
563
564 pBuff[1] = (nSampleRate&0xff000000)>>24;
565 pBuff[2] = (nSampleRate&0x00ff0000)>>16;
566 pBuff[3] = (nSampleRate&0x0000ff00)>>8;
567 pBuff[4] = (nSampleRate&0x000000ff);
568 }
569
570 if(bSet) nLen = 5;
571 else nLen = 1;
572
573 err = write(fileHandle, pBuff, nLen);
574 if(err != nLen){
575 fprintf(stderr, "write err=%d\n", err);
576 goto err;
577 }
578
579 if(bSet == 1){
580 fprintf(stderr, "Sample Rate Set to %d\n", nSampleRate);
581 }else{
582 err = read(fileHandle, pBuff, 4);
583 if(err != 4){
584 fprintf(stderr, "read err=%d\n", err);
585 goto err;
586 }else{
587 nSampleRate = pBuff[0] +
588 ((unsigned int)pBuff[1] << 8) +
589 ((unsigned int)pBuff[2] << 16) +
590 ((unsigned int)pBuff[3] << 24);
591 fprintf(stderr, "\t nSampleRate: %d\n", nSampleRate);
592 }
593 }
594
595err:
596
597 return err;
598}
599
600static int TiAudio_BitRate(int fileHandle, int argc, char **argv){
601 int err = -1;
602 unsigned char cmd[3];
603 unsigned char pBuff[5];
604 unsigned char bSet = 0;
605 unsigned char channel;
606 int nBitRate = -1;
607 char *pChannel;
608
609 if(argc == 3){
610 bSet = 0;
611 }else if(argc == 4){
612 bSet = 1;
613 }else{
614 fprintf(stderr, "invalid para numbers\n");
615 goto err;
616 }
617
618 cmd[0] = TIAUDIO_CMD_BITRATE;
619 err = str2hexchar(argv[2], &channel);
620 if(err < 0){
621 goto err;
622 }
623
624 if((channel >= 1)&&(channel <=3))
625 {
626
627 }else{
628 fprintf(stderr, "chanel err=%d\n", channel);
629 goto err;
630 }
631
632 if(bSet == 1){
633 if(strcmp(argv[3], "32") == 0)
634 nBitRate = 32;
635 else if(strcmp(argv[3], "24") == 0)
636 nBitRate = 24;
637 else if(strcmp(argv[3], "20") == 0)
638 nBitRate = 20;
639 else if(strcmp(argv[3], "16") == 0)
640 nBitRate = 16;
641 else{
642 fprintf(stderr, "invalid para numbers\n");
643 goto err;
644 }
645
646 cmd[2] = nBitRate;
647 }
648
649 if(channel&0x01){
650 cmd[1] = 1;
651 pChannel = LEFT_CHANNEL_STR;
652 err = write(fileHandle, cmd, (2+bSet));
653 if(err != (2+bSet)){
654 fprintf(stderr, "write err=%d\n", err);
655 goto err;
656 }
657
658 if(bSet == 1){
659 fprintf(stderr, "CHL[%s] BitRate Set to %d\n", pChannel, nBitRate);
660 }else{
661 err = read(fileHandle, pBuff, 1);
662 if(err != 1){
663 fprintf(stderr, "read err=%d\n", err);
664 goto err;
665 }else{
666 nBitRate = pBuff[0];
667 fprintf(stderr, "\t CHL[%s] BitRate: %d\n", pChannel, nBitRate);
668 }
669 }
670 }
671
672 if(channel&0x02){
673 cmd[1] = 2;
674 pChannel = RIGHT_CHANNEL_STR;
675 err = write(fileHandle, cmd, (2+bSet));
676 if(err != (2+bSet)){
677 fprintf(stderr, "write err=%d\n", err);
678 goto err;
679 }
680
681 if(bSet == 1){
682 fprintf(stderr, "CHL[%s] BitRate Set to %d\n", pChannel, nBitRate);
683 }else{
684 err = read(fileHandle, pBuff, 1);
685 if(err != 1){
686 fprintf(stderr, "read err=%d\n", err);
687 goto err;
688 }else{
689 nBitRate = pBuff[0];
690 fprintf(stderr, "\t CHL[%s] BitRate: %d\n", pChannel, nBitRate);
691 }
692 }
693 }
694
695err:
696
697 return err;
698}
699
700static int TiAudio_DACVolume(int fileHandle, int argc, char **argv){
701 int err = -1;
702 unsigned char cmd[3];
703 unsigned char pBuff[5];
704 unsigned char bSet = 0;
705 unsigned int nVol;
706 unsigned char channel;
707 char *pChannel;
708
709 if(argc == 3){
710 bSet = 0;
711 }else if(argc == 4){
712 bSet = 1;
713 }else{
714 fprintf(stderr, "invalid para numbers\n");
715 goto err;
716 }
717
718 cmd[0] = TIAUDIO_CMD_DACVOLUME;
719
720 err = str2hexchar(argv[2], &channel);
721 if(err < 0){
722 goto err;
723 }
724
725 if((channel >= 1)&&(channel <=3))
726 {
727
728 }else{
729 fprintf(stderr, "chanel err=%d\n", channel);
730 goto err;
731 }
732
733 if(bSet == 1){
734 err = str2decimal(argv[3], &nVol);
735 if(err < 0){
736 goto err;
737 }
738
739 cmd[2] = nVol;
740 }
741
742 if(channel&0x01){
743 cmd[1] = 1;
744 pChannel = LEFT_CHANNEL_STR;
745 err = write(fileHandle, cmd, (2+bSet));
746 if(err != (2+bSet)){
747 fprintf(stderr, "write err=%d\n", err);
748 goto err;
749 }
750
751 if(bSet == 1){
752 fprintf(stderr, "CHL[%s] DAC Volume Set to %d\n", pChannel, nVol);
753 }else{
754 err = read(fileHandle, pBuff, 1);
755 if(err != 1){
756 fprintf(stderr, "read err=%d\n", err);
757 goto err;
758 }else{
759 nVol = pBuff[0];
760 fprintf(stderr, "\tCHL[%s] DAC Volume: %d\n", pChannel, nVol);
761 }
762 }
763 }
764
765 if(channel&0x02){
766 cmd[1] = 2;
767 pChannel = RIGHT_CHANNEL_STR;
768 err = write(fileHandle, cmd, (2+bSet));
769 if(err != (2+bSet)){
770 fprintf(stderr, "write err=%d\n", err);
771 goto err;
772 }
773
774 if(bSet == 1){
775 fprintf(stderr, "CHL[%s] DAC Volume Set to %d\n", pChannel, nVol);
776 }else{
777 err = read(fileHandle, pBuff, 1);
778 if(err != 1){
779 fprintf(stderr, "read err=%d\n", err);
780 goto err;
781 }else{
782 nVol = pBuff[0];
783 fprintf(stderr, "\tCHL[%s] DAC Volume: %d\n", pChannel, nVol);
784 }
785 }
786 }
787
788err:
789
790 return err;
791}
792
793static int TiAudio_SpeakerOn(int fileHandle, int argc, char **argv){
794 int err = -1;
795 unsigned char pBuff[2], on;
796
797 if(argc != 3) {
798 fprintf(stderr, "invalid para numbers\n");
799 goto err;
800 }
801
802 pBuff[0] = TIAUDIO_CMD_SPEAKER;
803
804 err = str2hexchar(argv[2], &on);
805 if(err < 0){
806 goto err;
807 }
808
809 pBuff[1] = on;
810
811 err = write(fileHandle, pBuff, 2);
812 if(err != 2){
813 fprintf(stderr, "set err=%d\n", err);
814 goto err;
815 }
816
817 if(on == 0){
818 fprintf(stderr, "TAS2555 Power Off\n");
819 }else{
820 fprintf(stderr, "TAS2555 Power On\n");
821 }
822
823err:
824
825 return err;
826}
827
828static int TiAudio_Timestamp(int fileHandle){
829 int err = -1;
830 unsigned char pBuff[4];
831
832 pBuff[0] = TIAUDIO_CMD_FW_TIMESTAMP;
833
834 err = write(fileHandle, pBuff, 1);
835 if(err != 1){
836 fprintf(stderr, "write err=%d\n", err);
837 goto err;
838 }
839
840 err = read(fileHandle, pBuff, 4);
841 if(err != 4){
842 fprintf(stderr, "read err=%d\n", err);
843 goto err;
844 }else{
845 unsigned int nTimestamp = pBuff[0] +
846 ((unsigned int)pBuff[1] << 8) +
847 ((unsigned int)pBuff[2] << 16) +
848 ((unsigned int)pBuff[3] << 24);
849
850 time_t t = (time_t)nTimestamp;
851 struct tm *p;
852 p=localtime(&t);
853 char s[100];
854 strftime(s, sizeof(s), "%Y-%m-%d %H:%M:%S", p);
855 fprintf(stderr, "FW Timestamp : %d: %s\n", (int)t, s);
856 }
857
858err:
859
860 return err;
861}
862
863static int TiAudio_TriggerFWReload(int fileHandle){
864 int err = -1;
865 unsigned char pBuff[4];
866 pBuff[0] = TIAUDIO_CMD_FW_RELOAD;
867
868 err = write(fileHandle, pBuff, 1);
869 if(err != 1){
870 fprintf(stderr, "write err=%d\n", err);
871 goto err;
872 }
873
874 fprintf(stderr, "Firmware Reload Triggered\n");
875
876err:
877
878 return err;
879}
880
881static int TiAudio_Mute(int fileHandle, int argc, char **argv){
882 int err = -1;
883 unsigned char pBuff[3], dev, mute;
884
885 if (argc != 4) {
886 fprintf(stderr, "invalid para numbers\n");
887 goto err;
888 }
889
890 pBuff[0] = TIAUDIO_CMD_MUTE;
891
892 err = str2hexchar(argv[2], &dev);
893 if (err < 0) {
894 goto err;
895 }
896 pBuff[1] = dev;
897
898 err = str2hexchar(argv[3], &mute);
899 if (err < 0) {
900 goto err;
901 }
902 pBuff[2] = mute;
903
904 err = write(fileHandle, pBuff, 3);
905 if (err != 3) {
906 fprintf(stderr, "set err=%d\n", err);
907 goto err;
908 }
909
910 if (mute == 0) {
911 fprintf(stderr, "TAS2559 Dev(%d) UnMute!\n", dev);
912 } else {
913 fprintf(stderr, "TAS2559 Dev(%d) Mute!\n", dev);
914 }
915
916err:
917
918 return err;
919}
920
921static int getDevHandle(){
922 int fileHandle = -1;
923 fileHandle = open(TI_AUDIO_NAME, O_RDWR);
924 if(fileHandle < 0 ){
925 fprintf(stderr, "[ERROR]file(%s) open_RDWR error\n", TI_AUDIO_NAME);
926 }
927
928 return fileHandle;
929}
930
931int main(int argc, char **argv)
932{
933 int ret = 0;
934 int ch;
935 int fileHandle = -1;
936
937 fileHandle = getDevHandle();
938 if(fileHandle < 0 ){
939 fprintf(stderr, " file handle err=%d\n", fileHandle);
940 return ret;
941 }
942
943 if(argc == 1){
944 usage();
945 return 0;
946 }
947
948 while ((ch = getopt(argc, argv, "wrdpcsbvotfm")) != -1) {
949 switch (ch) {
950 case 'w':
951 ret = TiAudio_Reg_Write(fileHandle, argc, argv);
952 break;
953 case 'r':
954 ret = TiAudio_Reg_Read(fileHandle, argc, argv);
955 break;
956 case 'd':
957 ret = TiAudio_Debug_On(fileHandle, argc, argv);
958 break;
959 case 'p':
960 ret = TiAudio_Program(fileHandle, argc, argv);
961 break;
962 case 'c':
963 ret = TiAudio_Configuration(fileHandle, argc, argv);
964 break;
965 case 's':
966 ret = TiAudio_SampleRate(fileHandle, argc, argv);
967 break;
968 case 'b':
969 ret = TiAudio_BitRate(fileHandle, argc, argv);
970 break;
971 case 'v':
972 ret = TiAudio_DACVolume(fileHandle, argc, argv);
973 break;
974 case 'o':
975 ret = TiAudio_SpeakerOn(fileHandle, argc, argv);
976 break;
977 case 't':
978 ret = TiAudio_Timestamp(fileHandle);
979 break;
980 case 'f':
981 ret = TiAudio_TriggerFWReload(fileHandle);
982 break;
983 case 'm':
984 ret = TiAudio_Mute(fileHandle, argc, argv);
985 break;
986 default:
987 usage();
988 break;
989 }
990 }
991
992 if(fileHandle > 0 )
993 close(fileHandle);
994
995 return ret;
996}
diff --git a/ti_audio/ti_audio.h b/ti_audio/ti_audio.h
new file mode 100755
index 0000000..2429916
--- /dev/null
+++ b/ti_audio/ti_audio.h
@@ -0,0 +1,71 @@
1/*
2** =============================================================================
3** Copyright (c) 2016 Texas Instruments Inc.
4**
5** This program is free software; you can redistribute it and/or modify it under
6** the terms of the GNU General Public License as published by the Free Software
7** Foundation; version 2.
8**
9** This program is distributed in the hope that it will be useful, but WITHOUT
10** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11** FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12**
13** You should have received a copy of the GNU General Public License along with
14** this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15** Street, Fifth Floor, Boston, MA 02110-1301, USA.
16**
17** File:
18** ti_audio.h
19**
20** Description:
21** header file for the test program of TAS2557 Android Linux drivers
22**
23** =============================================================================
24*/
25#include <stdlib.h>
26#include <string.h>
27
28#define TIAUDIO_VERSION "Version : 3.2 (19th, April, 2017)"
29#define TI_AUDIO_NAME "/dev/tas2559"
30
31#define MAX_INT_STR "4294967295"
32
33#define SR_STR_48K "48000"
34#define SR_STR_44K "44100"
35#define SR_STR_16K "16000"
36#define SR_NUM_48K 48000
37#define SR_NUM_44K 44100
38#define SR_NUM_16K 16000
39
40#define LEFT_CHANNEL_STR "DevA"
41#define RIGHT_CHANNEL_STR "DevB"
42#define BOTH_CHANNELS_STR "DevBoth"
43
44#define FW_NAME_SIZE 64
45#define FW_DESCRIPTION_SIZE 256
46#define PROGRAM_BUF_SIZE (5 + FW_NAME_SIZE + FW_DESCRIPTION_SIZE)
47#define CONFIGURATION_BUF_SIZE (8 + FW_NAME_SIZE + FW_DESCRIPTION_SIZE)
48
49#define TIAUDIO_CMD_REG_WITE 1
50#define TIAUDIO_CMD_REG_READ 2
51#define TIAUDIO_CMD_DEBUG_ON 3
52#define TIAUDIO_CMD_PROGRAM 4
53#define TIAUDIO_CMD_CONFIGURATION 5
54#define TIAUDIO_CMD_FW_TIMESTAMP 6
55#define TIAUDIO_CMD_CALIBRATION 7
56#define TIAUDIO_CMD_SAMPLERATE 8
57#define TIAUDIO_CMD_BITRATE 9
58#define TIAUDIO_CMD_DACVOLUME 10
59#define TIAUDIO_CMD_SPEAKER 11
60#define TIAUDIO_CMD_FW_RELOAD 12
61#define TIAUDIO_CMD_MUTE 13
62
63#define TAS2555_REG(book, page, reg) (((book * 256 * 128) + \
64 (page * 128)) + reg)
65
66#define TAS2555_BOOK_ID(reg) (reg / (256 * 128))
67#define TAS2555_PAGE_ID(reg) ((reg % (256 * 128)) / 128)
68#define TAS2555_BOOK_REG(reg) (reg % (256 * 128))
69#define TAS2555_PAGE_REG(reg) ((reg % (256 * 128)) % 128)
70
71#define ARRAY_LEN(x) ((int)(sizeof(x)/sizeof((x)[0])))