diff options
author | a0220410 | 2016-11-25 18:57:02 -0600 |
---|---|---|
committer | a0220410 | 2016-11-25 18:57:02 -0600 |
commit | b5df11be83a2cc2b674d32f93daf5ab1dc2632ee (patch) | |
tree | cd9241e85229f23317f97f74b900e2350cb76652 | |
download | tas2557-utility-mono-b5df11be83a2cc2b674d32f93daf5ab1dc2632ee.tar.gz tas2557-utility-mono-b5df11be83a2cc2b674d32f93daf5ab1dc2632ee.tar.xz tas2557-utility-mono-b5df11be83a2cc2b674d32f93daf5ab1dc2632ee.zip |
-rwxr-xr-x | ti_audio/Android.mk | 19 | ||||
-rwxr-xr-x | ti_audio/CleanSpec.mk | 49 | ||||
-rwxr-xr-x | ti_audio/main.c | 786 | ||||
-rwxr-xr-x | ti_audio/ti_audio.h | 66 |
4 files changed, 920 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 @@ | |||
1 | ifneq ($(TARGET_SIMULATOR), true) | ||
2 | |||
3 | LOCAL_PATH := $(call my-dir) | ||
4 | |||
5 | include $(CLEAR_VARS) | ||
6 | |||
7 | LOCAL_SRC_FILES := main.c | ||
8 | |||
9 | LOCAL_C_INCLUDES := external/ti_audio/ | ||
10 | |||
11 | LOCAL_CFLAGS := -O2 -g -W -Wall -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 | ||
12 | |||
13 | LOCAL_MODULE := ti_audio | ||
14 | LOCAL_MODULE_TAGS := debug | ||
15 | LOCAL_SYSTEM_SHARED_LIBRARIES := libc libm | ||
16 | |||
17 | include $(BUILD_EXECUTABLE) | ||
18 | |||
19 | endif | ||
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..9364ba8 --- /dev/null +++ b/ti_audio/main.c | |||
@@ -0,0 +1,786 @@ | |||
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 | |||
40 | static 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", | ||
43 | "usage: ti_audio -r book page register [count] (read, hexdecimal)", | ||
44 | " ti_audio -w book page register value1 [value2 ...] (write, hexdecimal)", | ||
45 | " ti_audio -d on (turn on the debug msg, bool)", | ||
46 | " ti_audio -p [n] (get/[set] DSP program, decimal)", | ||
47 | " ti_audio -c [n] (get/[set] DSP configuration, decimal)", | ||
48 | " ti_audio -s [n] (get/[set] sample rate, decimal)", | ||
49 | " ti_audio -b [n] (get/[set] bit rate, decimal)", | ||
50 | " ti_audio -v [n] (get/[set] volume, decimal)", | ||
51 | " ti_audio -f (trigger firmware reload)", | ||
52 | " ti_audio -o on (turn on/off TAS2555, bool)", | ||
53 | " ti_audio -t (get firmware timestamp)", | ||
54 | TIAUDIO_VERSION); | ||
55 | } | ||
56 | |||
57 | static int str2hexchar(char *argv, unsigned char *pUInt8_Val){ | ||
58 | int str_len = strlen(argv), i, result = -1, j; | ||
59 | unsigned char val[2] = {0}; | ||
60 | |||
61 | if(str_len > 2){ | ||
62 | fprintf(stderr, "invalid parameters\n"); | ||
63 | goto err; | ||
64 | } | ||
65 | |||
66 | for(i = (str_len-1), j=0; i >= 0; i--, j++){ | ||
67 | if((argv[i] <= '9')&&(argv[i] >= '0')){ | ||
68 | val[j] = argv[i] - 0x30; | ||
69 | }else if((argv[i] <='f')&&(argv[i]>= 'a')){ | ||
70 | val[j] = argv[i] - 0x57; | ||
71 | }else if((argv[i] <='F')&&(argv[i]>= 'A')){ | ||
72 | val[j] = argv[i] - 0x37; | ||
73 | }else{ | ||
74 | fprintf(stderr, "reg/data out of range\n"); | ||
75 | goto err; | ||
76 | } | ||
77 | } | ||
78 | |||
79 | *pUInt8_Val = (unsigned char)(val[0]|(val[1]<<4)); | ||
80 | result = 0; | ||
81 | |||
82 | err: | ||
83 | return result; | ||
84 | } | ||
85 | |||
86 | /* | ||
87 | static int str2hexshort(char *argv, unsigned short *pUInt16_Val){ | ||
88 | int str_len = strlen(argv), i, j, result = -1; | ||
89 | unsigned char val[4] = {0}; | ||
90 | |||
91 | if(str_len > 4){ | ||
92 | fprintf(stderr, "invalid parameters\n"); | ||
93 | goto err; | ||
94 | } | ||
95 | |||
96 | for(i = (str_len-1), j=0; i >= 0; i--, j++){ | ||
97 | if((argv[i] <= '9')&&(argv[i] >= '0')){ | ||
98 | val[j] = argv[i] - 0x30; | ||
99 | }else if((argv[i] <='f')&&(argv[i]>= 'a')){ | ||
100 | val[j] = argv[i] - 0x57; | ||
101 | }else if((argv[i] <='F')&&(argv[i]>= 'A')){ | ||
102 | val[j] = argv[i] - 0x37; | ||
103 | }else{ | ||
104 | fprintf(stderr, "reg/data out of range\n"); | ||
105 | goto err; | ||
106 | } | ||
107 | } | ||
108 | |||
109 | *pUInt16_Val = (unsigned short)(val[0]|(val[1]<<4)|(val[2]<<8)|(val[3]<<12)); | ||
110 | result = 0; | ||
111 | |||
112 | err: | ||
113 | return result; | ||
114 | } | ||
115 | */ | ||
116 | |||
117 | static int str2decimal(char *argv, unsigned int *pUInt32_Val){ | ||
118 | int max_len = strlen(MAX_INT_STR), i, result = -1, j; | ||
119 | int str_len = strlen(argv); | ||
120 | unsigned int nValue = 0; | ||
121 | unsigned char temp; | ||
122 | |||
123 | if(str_len > max_len){ | ||
124 | fprintf(stderr, "invalid parameters\n"); | ||
125 | goto err; | ||
126 | } | ||
127 | |||
128 | for(i = (str_len-1), j=0; i >= 0; i--, j++){ | ||
129 | if((argv[i] <= '9')&&(argv[i] >= '0')){ | ||
130 | temp = argv[i] - 0x30; | ||
131 | nValue += (temp * pow(10, j)); | ||
132 | }else{ | ||
133 | fprintf(stderr, "reg/data out of range\n"); | ||
134 | goto err; | ||
135 | } | ||
136 | } | ||
137 | |||
138 | *pUInt32_Val = nValue; | ||
139 | result = 0; | ||
140 | |||
141 | err: | ||
142 | return result; | ||
143 | } | ||
144 | |||
145 | static int TiAudio_Reg_Write(int fileHandle, int argc, char **argv){ | ||
146 | int err = -1; | ||
147 | unsigned char *pBuff = NULL, book, page, reg,value; | ||
148 | unsigned int whole_reg = 0; | ||
149 | unsigned int temp_reg = 0; | ||
150 | int i=0, reg_count = 0; | ||
151 | |||
152 | if(argc < 6){ | ||
153 | fprintf(stderr, "invalid para numbers\n"); | ||
154 | goto err; | ||
155 | } | ||
156 | |||
157 | reg_count = argc - 5; | ||
158 | |||
159 | pBuff = (unsigned char *)malloc(reg_count + 5); | ||
160 | if(pBuff == NULL){ | ||
161 | fprintf(stderr, "not enough mem\n"); | ||
162 | goto err; | ||
163 | } | ||
164 | |||
165 | pBuff[0] = TIAUDIO_CMD_REG_WITE; | ||
166 | |||
167 | err = str2hexchar(argv[2], &book); | ||
168 | if(err < 0){ | ||
169 | goto err; | ||
170 | } | ||
171 | |||
172 | err = str2hexchar(argv[3], &page); | ||
173 | if(err < 0){ | ||
174 | goto err; | ||
175 | } | ||
176 | |||
177 | err = str2hexchar(argv[4], ®); | ||
178 | if(err < 0){ | ||
179 | goto err; | ||
180 | } | ||
181 | |||
182 | whole_reg = TAS2555_REG(book, page, reg); | ||
183 | pBuff[1] = (whole_reg & 0xff000000) >> 24; | ||
184 | pBuff[2] = (whole_reg & 0x00ff0000) >> 16; | ||
185 | pBuff[3] = (whole_reg & 0x0000ff00) >> 8; | ||
186 | pBuff[4] = (whole_reg & 0x000000ff) ; | ||
187 | |||
188 | for(i=0; i< reg_count; i++){ | ||
189 | err = str2hexchar(argv[i+5], &value); | ||
190 | if(err < 0){ | ||
191 | goto err; | ||
192 | } | ||
193 | pBuff[i + 5] = value; | ||
194 | } | ||
195 | |||
196 | err = write(fileHandle, pBuff, reg_count+5); | ||
197 | if(err != (reg_count+5)){ | ||
198 | fprintf(stderr, "write err=%d\n", err); | ||
199 | }else{ | ||
200 | for(i=0; i< reg_count; i++){ | ||
201 | temp_reg = whole_reg + i; | ||
202 | 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] ); | ||
203 | } | ||
204 | } | ||
205 | |||
206 | err: | ||
207 | if(pBuff != NULL) | ||
208 | free(pBuff); | ||
209 | |||
210 | return err; | ||
211 | } | ||
212 | |||
213 | static int TiAudio_Reg_Read(int fileHandle, int argc, char **argv){ | ||
214 | int err = -1; | ||
215 | unsigned char *pBuff = NULL, book, page, reg, len; | ||
216 | unsigned int whole_reg = 0; | ||
217 | unsigned int temp_reg = 0; | ||
218 | int i=0, reg_count = 0; | ||
219 | |||
220 | if((argc != 5) &&(argc != 6)) { | ||
221 | fprintf(stderr, "invalid para numbers\n"); | ||
222 | goto err; | ||
223 | } | ||
224 | |||
225 | if(argc == 5) | ||
226 | reg_count = 1; | ||
227 | else{ | ||
228 | err = str2hexchar(argv[5], &len); | ||
229 | if(err < 0){ | ||
230 | goto err; | ||
231 | } | ||
232 | reg_count = len; | ||
233 | } | ||
234 | |||
235 | pBuff = (unsigned char *)malloc(reg_count + 5); | ||
236 | if(pBuff == NULL){ | ||
237 | fprintf(stderr, "not enough mem\n"); | ||
238 | goto err; | ||
239 | } | ||
240 | |||
241 | pBuff[0] = TIAUDIO_CMD_REG_READ; | ||
242 | |||
243 | err = str2hexchar(argv[2], &book); | ||
244 | if(err < 0){ | ||
245 | goto err; | ||
246 | } | ||
247 | |||
248 | err = str2hexchar(argv[3], &page); | ||
249 | if(err < 0){ | ||
250 | goto err; | ||
251 | } | ||
252 | |||
253 | err = str2hexchar(argv[4], ®); | ||
254 | if(err < 0){ | ||
255 | goto err; | ||
256 | } | ||
257 | |||
258 | whole_reg = TAS2555_REG(book, page, reg); | ||
259 | pBuff[1] = (whole_reg & 0xff000000) >> 24; | ||
260 | pBuff[2] = (whole_reg & 0x00ff0000) >> 16; | ||
261 | pBuff[3] = (whole_reg & 0x0000ff00) >> 8; | ||
262 | pBuff[4] = (whole_reg & 0x000000ff) ; | ||
263 | |||
264 | err = write(fileHandle, pBuff, 5); | ||
265 | if(err != 5){ | ||
266 | fprintf(stderr, "read err=%d\n", err); | ||
267 | goto err; | ||
268 | } | ||
269 | |||
270 | err = read(fileHandle, pBuff, reg_count); | ||
271 | if(err != reg_count){ | ||
272 | fprintf(stderr, "read err=%d\n", err); | ||
273 | goto err; | ||
274 | }else{ | ||
275 | for(i=0; i< reg_count; i++){ | ||
276 | temp_reg = whole_reg + i; | ||
277 | 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]); | ||
278 | } | ||
279 | } | ||
280 | |||
281 | err: | ||
282 | if(pBuff != NULL) | ||
283 | free(pBuff); | ||
284 | |||
285 | return err; | ||
286 | } | ||
287 | |||
288 | static int TiAudio_Debug_On(int fileHandle, int argc, char **argv){ | ||
289 | int err = -1; | ||
290 | unsigned char pBuff[2], on; | ||
291 | |||
292 | if(argc != 3) { | ||
293 | fprintf(stderr, "invalid para numbers\n"); | ||
294 | goto err; | ||
295 | } | ||
296 | |||
297 | pBuff[0] = TIAUDIO_CMD_DEBUG_ON; | ||
298 | |||
299 | err = str2hexchar(argv[2], &on); | ||
300 | if(err < 0){ | ||
301 | goto err; | ||
302 | } | ||
303 | |||
304 | pBuff[1] = on; | ||
305 | |||
306 | err = write(fileHandle, pBuff, 2); | ||
307 | if(err != 2){ | ||
308 | fprintf(stderr, "set err=%d\n", err); | ||
309 | goto err; | ||
310 | } | ||
311 | |||
312 | if(on == 0){ | ||
313 | fprintf(stderr, "DBG msg Off\n"); | ||
314 | }else{ | ||
315 | fprintf(stderr, "DBG msg On\n"); | ||
316 | } | ||
317 | |||
318 | err: | ||
319 | |||
320 | return err; | ||
321 | } | ||
322 | |||
323 | static int TiAudio_Program(int fileHandle, int argc, char **argv){ | ||
324 | int err = -1; | ||
325 | unsigned char pBuff[PROGRAM_BUF_SIZE], bSet = 0; | ||
326 | unsigned int nProgram; | ||
327 | |||
328 | if(argc == 2){ | ||
329 | bSet = 0; | ||
330 | }else if(argc == 3){ | ||
331 | bSet = 1; | ||
332 | }else{ | ||
333 | fprintf(stderr, "invalid para numbers\n"); | ||
334 | goto err; | ||
335 | } | ||
336 | |||
337 | pBuff[0] = TIAUDIO_CMD_PROGRAM; | ||
338 | |||
339 | if(bSet == 1){ | ||
340 | err = str2decimal(argv[2], &nProgram); | ||
341 | if(err < 0){ | ||
342 | fprintf(stderr, "invalid para numbers\n"); | ||
343 | goto err; | ||
344 | } | ||
345 | |||
346 | pBuff[1] = nProgram; | ||
347 | } | ||
348 | |||
349 | err = write(fileHandle, pBuff, (1+bSet)); | ||
350 | if(err != (bSet+1)){ | ||
351 | fprintf(stderr, "write err=%d\n", err); | ||
352 | goto err; | ||
353 | } | ||
354 | |||
355 | if(bSet == 1){ | ||
356 | fprintf(stderr, "Program Set to %d\n", nProgram); | ||
357 | }else{ | ||
358 | err = read(fileHandle, pBuff, PROGRAM_BUF_SIZE); | ||
359 | if(err != PROGRAM_BUF_SIZE){ | ||
360 | fprintf(stderr, "read err=%d\n", err); | ||
361 | goto err; | ||
362 | }else{ | ||
363 | unsigned char nPrograms = pBuff[0]; | ||
364 | unsigned char nCurProgram = pBuff[1]; | ||
365 | unsigned char nAppMode = pBuff[2]; | ||
366 | unsigned short nBoost = ((unsigned short)pBuff[3]<<8) + pBuff[4]; | ||
367 | unsigned char *pName = &pBuff[5]; | ||
368 | unsigned char *pDescription = &pBuff[5 + FW_NAME_SIZE]; | ||
369 | fprintf(stderr, "Total Programs : %d\n", nPrograms); | ||
370 | fprintf(stderr, "Current Programs : %d\n", nCurProgram); | ||
371 | if(nAppMode == 0) | ||
372 | fprintf(stderr, "\t AppMode : %s\n", "ROM1"); | ||
373 | else if(nAppMode == 1) | ||
374 | fprintf(stderr, "\t AppMode : %s\n", "ROM2"); | ||
375 | else if(nAppMode == 2) | ||
376 | fprintf(stderr, "\t AppMode : %s\n", "Tuning Mode"); | ||
377 | fprintf(stderr, "\t Boost: %s\n", (nBoost==0)?"Off":"On"); | ||
378 | fprintf(stderr, "\t Name: %s\n", pName); | ||
379 | fprintf(stderr, "\t Description : %s\n", pDescription); | ||
380 | } | ||
381 | } | ||
382 | |||
383 | err: | ||
384 | |||
385 | return err; | ||
386 | } | ||
387 | |||
388 | static int TiAudio_Configuration(int fileHandle, int argc, char **argv){ | ||
389 | int err = -1; | ||
390 | unsigned char pBuff[CONFIGURATION_BUF_SIZE], bSet = 0; | ||
391 | unsigned int nConfiguration; | ||
392 | |||
393 | if(argc == 2){ | ||
394 | bSet = 0; | ||
395 | }else if(argc == 3){ | ||
396 | bSet = 1; | ||
397 | }else{ | ||
398 | fprintf(stderr, "invalid para numbers\n"); | ||
399 | goto err; | ||
400 | } | ||
401 | |||
402 | pBuff[0] = TIAUDIO_CMD_CONFIGURATION; | ||
403 | |||
404 | if(bSet == 1){ | ||
405 | err = str2decimal(argv[2], &nConfiguration); | ||
406 | if(err < 0){ | ||
407 | goto err; | ||
408 | } | ||
409 | |||
410 | pBuff[1] = nConfiguration; | ||
411 | } | ||
412 | |||
413 | err = write(fileHandle, pBuff, (1+bSet)); | ||
414 | if(err != (bSet+1)){ | ||
415 | fprintf(stderr, "write err=%d\n", err); | ||
416 | goto err; | ||
417 | } | ||
418 | |||
419 | if(bSet == 1){ | ||
420 | fprintf(stderr, "Configuration Set to %d\n", nConfiguration); | ||
421 | }else{ | ||
422 | err = read(fileHandle, pBuff, CONFIGURATION_BUF_SIZE); | ||
423 | if(err != CONFIGURATION_BUF_SIZE){ | ||
424 | fprintf(stderr, "read err=%d\n", err); | ||
425 | goto err; | ||
426 | }else{ | ||
427 | unsigned char nConfigurations = pBuff[0]; | ||
428 | unsigned char nCurConfiguration = pBuff[1]; | ||
429 | unsigned char *pName = &pBuff[2]; | ||
430 | unsigned char nProgram = pBuff[2 + FW_NAME_SIZE]; | ||
431 | unsigned char nPLL = pBuff[3 + FW_NAME_SIZE]; | ||
432 | unsigned int nSampleRate = pBuff[4 + FW_NAME_SIZE] + | ||
433 | ((unsigned int)pBuff[5 + FW_NAME_SIZE] << 8) + | ||
434 | ((unsigned int)pBuff[6 + FW_NAME_SIZE] << 16) + | ||
435 | ((unsigned int)pBuff[7 + FW_NAME_SIZE] << 24); | ||
436 | unsigned char *pDescription = &pBuff[8 + FW_NAME_SIZE]; | ||
437 | fprintf(stderr, "Total Configurations : %d\n", nConfigurations); | ||
438 | fprintf(stderr, "Current Configuration: %d\n", nCurConfiguration); | ||
439 | fprintf(stderr, "\t Name: %s\n", pName); | ||
440 | fprintf(stderr, "\t Description : %s\n", pDescription); | ||
441 | fprintf(stderr, "\t nProgram: %d\n", nProgram); | ||
442 | fprintf(stderr, "\t nPLL: %d\n", nPLL); | ||
443 | fprintf(stderr, "\t nSampleRate: %d\n", nSampleRate); | ||
444 | } | ||
445 | } | ||
446 | |||
447 | err: | ||
448 | |||
449 | return err; | ||
450 | } | ||
451 | |||
452 | static int TiAudio_SampleRate(int fileHandle, int argc, char **argv){ | ||
453 | int err = -1; | ||
454 | unsigned char pBuff[5]; | ||
455 | unsigned char bSet = 0; | ||
456 | unsigned int nSampleRate; | ||
457 | int nLen; | ||
458 | |||
459 | if(argc == 2){ | ||
460 | bSet = 0; | ||
461 | }else if(argc == 3){ | ||
462 | bSet = 1; | ||
463 | }else{ | ||
464 | fprintf(stderr, "invalid para numbers\n"); | ||
465 | goto err; | ||
466 | } | ||
467 | |||
468 | pBuff[0] = TIAUDIO_CMD_SAMPLERATE; | ||
469 | |||
470 | if(bSet == 1){ | ||
471 | if(strcmp(argv[2], SR_STR_48K) == 0) | ||
472 | nSampleRate = SR_NUM_48K; | ||
473 | else if(strcmp(argv[2], SR_STR_44K) == 0) | ||
474 | nSampleRate = SR_NUM_44K; | ||
475 | else if(strcmp(argv[2], SR_STR_16K) == 0) | ||
476 | nSampleRate = SR_NUM_16K; | ||
477 | else{ | ||
478 | fprintf(stderr, "invalid para numbers\n"); | ||
479 | goto err; | ||
480 | } | ||
481 | |||
482 | pBuff[1] = (nSampleRate&0xff000000)>>24; | ||
483 | pBuff[2] = (nSampleRate&0x00ff0000)>>16; | ||
484 | pBuff[3] = (nSampleRate&0x0000ff00)>>8; | ||
485 | pBuff[4] = (nSampleRate&0x000000ff); | ||
486 | } | ||
487 | |||
488 | if(bSet) nLen = 5; | ||
489 | else nLen = 1; | ||
490 | |||
491 | err = write(fileHandle, pBuff, nLen); | ||
492 | if(err != nLen){ | ||
493 | fprintf(stderr, "write err=%d\n", err); | ||
494 | goto err; | ||
495 | } | ||
496 | |||
497 | if(bSet == 1){ | ||
498 | fprintf(stderr, "Sample Rate Set to %d\n", nSampleRate); | ||
499 | }else{ | ||
500 | err = read(fileHandle, pBuff, 4); | ||
501 | if(err != 4){ | ||
502 | fprintf(stderr, "read err=%d\n", err); | ||
503 | goto err; | ||
504 | }else{ | ||
505 | nSampleRate = pBuff[0] + | ||
506 | ((unsigned int)pBuff[1] << 8) + | ||
507 | ((unsigned int)pBuff[2] << 16) + | ||
508 | ((unsigned int)pBuff[3] << 24); | ||
509 | fprintf(stderr, "\t nSampleRate: %d\n", nSampleRate); | ||
510 | } | ||
511 | } | ||
512 | |||
513 | err: | ||
514 | |||
515 | return err; | ||
516 | } | ||
517 | |||
518 | static int TiAudio_BitRate(int fileHandle, int argc, char **argv){ | ||
519 | int err = -1; | ||
520 | unsigned char pBuff[5]; | ||
521 | unsigned char bSet = 0; | ||
522 | unsigned int nBitRate; | ||
523 | |||
524 | if(argc == 2){ | ||
525 | bSet = 0; | ||
526 | }else if(argc == 3){ | ||
527 | bSet = 1; | ||
528 | }else{ | ||
529 | fprintf(stderr, "invalid para numbers\n"); | ||
530 | goto err; | ||
531 | } | ||
532 | |||
533 | pBuff[0] = TIAUDIO_CMD_BITRATE; | ||
534 | |||
535 | if(bSet == 1){ | ||
536 | if(strcmp(argv[2], "32") == 0) | ||
537 | nBitRate = 32; | ||
538 | else if(strcmp(argv[2], "24") == 0) | ||
539 | nBitRate = 24; | ||
540 | else if(strcmp(argv[2], "20") == 0) | ||
541 | nBitRate = 20; | ||
542 | else if(strcmp(argv[2], "16") == 0) | ||
543 | nBitRate = 16; | ||
544 | else{ | ||
545 | fprintf(stderr, "invalid para numbers\n"); | ||
546 | goto err; | ||
547 | } | ||
548 | |||
549 | pBuff[1] = nBitRate; | ||
550 | } | ||
551 | |||
552 | err = write(fileHandle, pBuff, (1+bSet)); | ||
553 | if(err != (1+bSet)){ | ||
554 | fprintf(stderr, "write err=%d\n", err); | ||
555 | goto err; | ||
556 | } | ||
557 | |||
558 | if(bSet == 1){ | ||
559 | fprintf(stderr, "BitRate Set to %d\n", nBitRate); | ||
560 | }else{ | ||
561 | err = read(fileHandle, pBuff, 1); | ||
562 | if(err != 1){ | ||
563 | fprintf(stderr, "read err=%d\n", err); | ||
564 | goto err; | ||
565 | }else{ | ||
566 | nBitRate = pBuff[0]; | ||
567 | fprintf(stderr, "\t BitRate: %d\n", nBitRate); | ||
568 | } | ||
569 | } | ||
570 | |||
571 | err: | ||
572 | |||
573 | return err; | ||
574 | } | ||
575 | |||
576 | static int TiAudio_DACVolume(int fileHandle, int argc, char **argv){ | ||
577 | int err = -1; | ||
578 | unsigned char pBuff[5]; | ||
579 | unsigned char bSet = 0; | ||
580 | unsigned int nVol; | ||
581 | |||
582 | if(argc == 2){ | ||
583 | bSet = 0; | ||
584 | }else if(argc == 3){ | ||
585 | bSet = 1; | ||
586 | }else{ | ||
587 | fprintf(stderr, "invalid para numbers\n"); | ||
588 | goto err; | ||
589 | } | ||
590 | |||
591 | pBuff[0] = TIAUDIO_CMD_DACVOLUME; | ||
592 | |||
593 | if(bSet == 1){ | ||
594 | err = str2decimal(argv[2], &nVol); | ||
595 | if(err < 0){ | ||
596 | goto err; | ||
597 | } | ||
598 | |||
599 | pBuff[1] = nVol; | ||
600 | } | ||
601 | |||
602 | err = write(fileHandle, pBuff, (1+bSet)); | ||
603 | if(err != (1+bSet)){ | ||
604 | fprintf(stderr, "write err=%d\n", err); | ||
605 | goto err; | ||
606 | } | ||
607 | |||
608 | if(bSet == 1){ | ||
609 | fprintf(stderr, "DAC Volume Set to %d\n", nVol); | ||
610 | }else{ | ||
611 | err = read(fileHandle, pBuff, 1); | ||
612 | if(err != 1){ | ||
613 | fprintf(stderr, "read err=%d\n", err); | ||
614 | goto err; | ||
615 | }else{ | ||
616 | nVol = pBuff[0]; | ||
617 | fprintf(stderr, "\t DAC Volume: %d\n", nVol); | ||
618 | } | ||
619 | } | ||
620 | |||
621 | err: | ||
622 | |||
623 | return err; | ||
624 | } | ||
625 | |||
626 | static int TiAudio_SpeakerOn(int fileHandle, int argc, char **argv){ | ||
627 | int err = -1; | ||
628 | unsigned char pBuff[2], on; | ||
629 | |||
630 | if(argc != 3) { | ||
631 | fprintf(stderr, "invalid para numbers\n"); | ||
632 | goto err; | ||
633 | } | ||
634 | |||
635 | pBuff[0] = TIAUDIO_CMD_SPEAKER; | ||
636 | |||
637 | err = str2hexchar(argv[2], &on); | ||
638 | if(err < 0){ | ||
639 | goto err; | ||
640 | } | ||
641 | |||
642 | pBuff[1] = on; | ||
643 | |||
644 | err = write(fileHandle, pBuff, 2); | ||
645 | if(err != 2){ | ||
646 | fprintf(stderr, "set err=%d\n", err); | ||
647 | goto err; | ||
648 | } | ||
649 | |||
650 | if(on == 0){ | ||
651 | fprintf(stderr, "TAS2555 Power Off\n"); | ||
652 | }else{ | ||
653 | fprintf(stderr, "TAS2555 Power On\n"); | ||
654 | } | ||
655 | |||
656 | err: | ||
657 | |||
658 | return err; | ||
659 | } | ||
660 | |||
661 | static int TiAudio_Timestamp(int fileHandle){ | ||
662 | int err = -1; | ||
663 | unsigned char pBuff[4]; | ||
664 | |||
665 | pBuff[0] = TIAUDIO_CMD_FW_TIMESTAMP; | ||
666 | |||
667 | err = write(fileHandle, pBuff, 1); | ||
668 | if(err != 1){ | ||
669 | fprintf(stderr, "write err=%d\n", err); | ||
670 | goto err; | ||
671 | } | ||
672 | |||
673 | err = read(fileHandle, pBuff, 4); | ||
674 | if(err != 4){ | ||
675 | fprintf(stderr, "read err=%d\n", err); | ||
676 | goto err; | ||
677 | }else{ | ||
678 | unsigned int nTimestamp = pBuff[0] + | ||
679 | ((unsigned int)pBuff[1] << 8) + | ||
680 | ((unsigned int)pBuff[2] << 16) + | ||
681 | ((unsigned int)pBuff[3] << 24); | ||
682 | |||
683 | time_t t = (time_t)nTimestamp; | ||
684 | struct tm *p; | ||
685 | p=localtime(&t); | ||
686 | char s[100]; | ||
687 | strftime(s, sizeof(s), "%Y-%m-%d %H:%M:%S", p); | ||
688 | fprintf(stderr, "FW Timestamp : %d: %s\n", (int)t, s); | ||
689 | } | ||
690 | |||
691 | err: | ||
692 | |||
693 | return err; | ||
694 | } | ||
695 | |||
696 | static int TiAudio_TriggerFWReload(int fileHandle){ | ||
697 | int err = -1; | ||
698 | unsigned char pBuff[4]; | ||
699 | pBuff[0] = TIAUDIO_CMD_FW_RELOAD; | ||
700 | |||
701 | err = write(fileHandle, pBuff, 1); | ||
702 | if(err != 1){ | ||
703 | fprintf(stderr, "write err=%d\n", err); | ||
704 | goto err; | ||
705 | } | ||
706 | |||
707 | fprintf(stderr, "Firmware Reload Triggered\n"); | ||
708 | |||
709 | err: | ||
710 | |||
711 | return err; | ||
712 | } | ||
713 | |||
714 | static int getDevHandle(){ | ||
715 | int fileHandle = -1; | ||
716 | fileHandle = open(TI_AUDIO_NAME, O_RDWR); | ||
717 | if(fileHandle < 0 ){ | ||
718 | fprintf(stderr, "[ERROR]file(%s) open_RDWR error\n", TI_AUDIO_NAME); | ||
719 | } | ||
720 | |||
721 | return fileHandle; | ||
722 | } | ||
723 | |||
724 | int main(int argc, char **argv) | ||
725 | { | ||
726 | int ret = 0; | ||
727 | int ch; | ||
728 | int fileHandle = -1; | ||
729 | |||
730 | fileHandle = getDevHandle(); | ||
731 | if(fileHandle < 0 ){ | ||
732 | fprintf(stderr, " file handle err=%d\n", fileHandle); | ||
733 | return ret; | ||
734 | } | ||
735 | |||
736 | if(argc == 1){ | ||
737 | usage(); | ||
738 | return 0; | ||
739 | } | ||
740 | |||
741 | while ((ch = getopt(argc, argv, "wrdpcsbvotf")) != -1) { | ||
742 | switch (ch) { | ||
743 | case 'w': | ||
744 | ret = TiAudio_Reg_Write(fileHandle, argc, argv); | ||
745 | break; | ||
746 | case 'r': | ||
747 | ret = TiAudio_Reg_Read(fileHandle, argc, argv); | ||
748 | break; | ||
749 | case 'd': | ||
750 | ret = TiAudio_Debug_On(fileHandle, argc, argv); | ||
751 | break; | ||
752 | case 'p': | ||
753 | ret = TiAudio_Program(fileHandle, argc, argv); | ||
754 | break; | ||
755 | case 'c': | ||
756 | ret = TiAudio_Configuration(fileHandle, argc, argv); | ||
757 | break; | ||
758 | case 's': | ||
759 | ret = TiAudio_SampleRate(fileHandle, argc, argv); | ||
760 | break; | ||
761 | case 'b': | ||
762 | ret = TiAudio_BitRate(fileHandle, argc, argv); | ||
763 | break; | ||
764 | case 'v': | ||
765 | ret = TiAudio_DACVolume(fileHandle, argc, argv); | ||
766 | break; | ||
767 | case 'o': | ||
768 | ret = TiAudio_SpeakerOn(fileHandle, argc, argv); | ||
769 | break; | ||
770 | case 't': | ||
771 | ret = TiAudio_Timestamp(fileHandle); | ||
772 | break; | ||
773 | case 'f': | ||
774 | ret = TiAudio_TriggerFWReload(fileHandle); | ||
775 | break; | ||
776 | default: | ||
777 | usage(); | ||
778 | break; | ||
779 | } | ||
780 | } | ||
781 | |||
782 | if(fileHandle > 0 ) | ||
783 | close(fileHandle); | ||
784 | |||
785 | return ret; | ||
786 | } | ||
diff --git a/ti_audio/ti_audio.h b/ti_audio/ti_audio.h new file mode 100755 index 0000000..5160e33 --- /dev/null +++ b/ti_audio/ti_audio.h | |||
@@ -0,0 +1,66 @@ | |||
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.1 (20th, May, 2016)" | ||
29 | #define TI_AUDIO_NAME "/dev/tas2557" | ||
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 FW_NAME_SIZE 64 | ||
41 | #define FW_DESCRIPTION_SIZE 256 | ||
42 | #define PROGRAM_BUF_SIZE (5 + FW_NAME_SIZE + FW_DESCRIPTION_SIZE) | ||
43 | #define CONFIGURATION_BUF_SIZE (8 + FW_NAME_SIZE + FW_DESCRIPTION_SIZE) | ||
44 | |||
45 | #define TIAUDIO_CMD_REG_WITE 1 | ||
46 | #define TIAUDIO_CMD_REG_READ 2 | ||
47 | #define TIAUDIO_CMD_DEBUG_ON 3 | ||
48 | #define TIAUDIO_CMD_PROGRAM 4 | ||
49 | #define TIAUDIO_CMD_CONFIGURATION 5 | ||
50 | #define TIAUDIO_CMD_FW_TIMESTAMP 6 | ||
51 | #define TIAUDIO_CMD_CALIBRATION 7 | ||
52 | #define TIAUDIO_CMD_SAMPLERATE 8 | ||
53 | #define TIAUDIO_CMD_BITRATE 9 | ||
54 | #define TIAUDIO_CMD_DACVOLUME 10 | ||
55 | #define TIAUDIO_CMD_SPEAKER 11 | ||
56 | #define TIAUDIO_CMD_FW_RELOAD 12 | ||
57 | |||
58 | #define TAS2555_REG(book, page, reg) (((book * 256 * 128) + \ | ||
59 | (page * 128)) + reg) | ||
60 | |||
61 | #define TAS2555_BOOK_ID(reg) (reg / (256 * 128)) | ||
62 | #define TAS2555_PAGE_ID(reg) ((reg % (256 * 128)) / 128) | ||
63 | #define TAS2555_BOOK_REG(reg) (reg % (256 * 128)) | ||
64 | #define TAS2555_PAGE_REG(reg) ((reg % (256 * 128)) % 128) | ||
65 | |||
66 | #define ARRAY_LEN(x) ((int)(sizeof(x)/sizeof((x)[0]))) | ||