Niranjan Yadla | 88a93e4 | 2017-08-29 15:22:40 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #define LOG_TAG "debug-hifi" |
| 18 | #include <errno.h> |
| 19 | #include <fcntl.h> |
| 20 | #include <unistd.h> |
| 21 | #include <poll.h> |
| 22 | #include <pthread.h> |
| 23 | #include <sys/ioctl.h> |
| 24 | #include <sys/prctl.h> |
| 25 | #include <stdio.h> |
| 26 | #include <cutils/log.h> |
| 27 | #include <cutils/uevent.h> |
| 28 | #include <stdlib.h> |
| 29 | #include <linux/audio_hifi.h> |
| 30 | |
| 31 | int main(int argc, char *argv[]) |
| 32 | { |
| 33 | char *buffer; |
| 34 | int hifi_dsp_fd; |
| 35 | int ret = -1; |
| 36 | int i = 0; |
| 37 | unsigned int memsize = DRV_DSP_UART_TO_MEM_SIZE; |
| 38 | unsigned int clear = 0; |
| 39 | struct misc_io_dump_buf_param dump_buf; |
| 40 | |
| 41 | ALOGI("Enter hifi-dsp Audio Framework - sample application\n"); |
| 42 | if (argc > 1) |
| 43 | memsize = strtoul(argv[1], NULL, 0); |
| 44 | if (argc > 2) |
| 45 | clear = 1; |
| 46 | hifi_dsp_fd = open(HIFI_DSP_MISC_DRIVER, O_RDWR, 0); |
| 47 | if (hifi_dsp_fd < 0) { |
| 48 | ALOGE("Error %d opening hifi dsp device", errno); |
| 49 | return ret; |
| 50 | } |
| 51 | buffer = malloc(memsize); |
| 52 | if (!buffer) { |
| 53 | ALOGE("Error allocating buffer"); |
| 54 | goto out0; |
| 55 | } |
| 56 | dump_buf.user_buf = (uint64_t)buffer; |
| 57 | dump_buf.buf_size = memsize; |
| 58 | dump_buf.clear = clear; |
| 59 | ret = ioctl(hifi_dsp_fd, HIFI_MISC_IOCTL_DISPLAY_MSG, &dump_buf); |
Dmitry Shmidt | 06a976a | 2017-09-21 15:18:27 -0700 | [diff] [blame] | 60 | if (ret < 0) { /* This IOCTL returns buffer size */ |
Niranjan Yadla | 88a93e4 | 2017-08-29 15:22:40 -0700 | [diff] [blame] | 61 | ALOGE("Error %d accessing message buffer", errno); |
| 62 | } else { |
Dmitry Shmidt | 06a976a | 2017-09-21 15:18:27 -0700 | [diff] [blame] | 63 | printf("%s\n", ret > 0 ? buffer : "Buffer is empty"); |
Niranjan Yadla | 88a93e4 | 2017-08-29 15:22:40 -0700 | [diff] [blame] | 64 | } |
| 65 | free(buffer); |
| 66 | out0: |
| 67 | close(hifi_dsp_fd); |
| 68 | ALOGI("Exit hifi-dsp Audio Framework - sample application\n"); |
| 69 | return ret; |
| 70 | } |