在 Snapdragon Flight DSP 上打开的文件返回可疑的大量数字
File open on Snapdragon Flight DSP returning suspiciously large number
为什么调用open("/dev/tty-2",O_RDWR);
时打开的文件号是268435355(如-1+2^28)?这是从实时操作系统(如 android DSP 端)上的 open() 调用输出的正常大小的数字吗?好像太大了。
DSP 处理器 运行 高通实时 OS。其他处理器 运行 Linaro Linux.
来自 mini-dm
、DSP(数字信号处理器)运行时调试器的相关输出:
Running mini-dm version: 3.0
Device found with Product ID 0x9025. Continuing...
mini-dm is waiting for a DMSS connection...
DMSS is connected. Running mini-dm...
[08500/03] 00:40.640 HAP:63:HAP_debug_v2 weak ref not found, return _rtld_sym_zero@_rtld_objmain 0294 symbol.c
[08500/03] 00:40.640 HAP:63:HAP_debug_v2 weak ref not found, return _rtld_sym_zero@_rtld_objmain 0294 symbol.c
[08500/02] 00:40.640 HAP:63:Opening serial port 0062 helloworld_dsp.c
[08500/00] 00:40.640 configuring UART for 4-wire mode, DAL id: 0x2001005 0852 DalUart.c
[08500/02] 00:40.641 HAP:63:Opened serial port number 268435455 0065 helloworld_dsp.c
[08500/02] 00:40.641 HAP:63:Closing serial port 0075 helloworld_dsp.c
[08500/02] 00:40.641 HAP:63:Successfully closed serial port number 268435455 0078 helloworld_dsp.c
[08500/02] 00:40.641 HAP:63:Opening serial port 0062 helloworld_dsp.c
[08500/02] 00:40.642 HAP:63:workaround: reopening an existing serial port 0351 serial.c
[08500/02] 00:40.642 HAP:63:Opened serial port number 268435455 0065 helloworld_dsp.c
[08500/02] 00:40.642 HAP:63:Beginning serial read 0123 helloworld_dsp.c
[08500/02] 00:40.642 HAP:63:/dev/tty-2 read bytes [0]: 0129 helloworld_dsp.c
[08500/02] 00:40.642 HAP:63:Closing serial port 0075 helloworld_dsp.c
[08500/02] 00:40.642 HAP:63:Successfully closed serial port number 268435455 0078 helloworld_dsp.c
相关 DSP 代码:
int example_interface_serial_open()
{
LOG_INFO("Opening serial port");
serial_fds[0] = open(serial_path[0],O_RDWR);
if (serial_fds[0] >= SUCCESS) {
LOG_INFO("Opened serial port number %d", serial_fds[0]);
} else {
//FIXME log error!
LOG_INFO("Error opening serial port");
serial_fds[0] = ERROR;
}
return serial_fds[0];
}
int example_interface_serial_close(int fd) {
LOG_INFO("Closing serial port");
if (!close(fd)) {
LOG_INFO("Successfully closed serial port number %d", fd);
} else {
LOG_INFO("Error closing serial port");
fd = ERROR;
}
return fd;
}
int example_interface_serial_read(int fd) {
int res = SUCCESS;
char rx_buffer[SERIAL_SIZE_OF_DATA_BUFFER];
unsigned int num_bytes_read;
int active_devices = 0;
int runs, i;
LOG_INFO("Beginning serial read");
memset(rx_buffer, 0, SERIAL_SIZE_OF_DATA_BUFFER);
num_bytes_read = read(fd, rx_buffer,
SERIAL_SIZE_OF_DATA_BUFFER);
LOG_INFO("%s read bytes [%d]: %s",
serial_path[0], num_bytes_read, rx_buffer);
if (res < SUCCESS) {
LOG_INFO("Closing file %s",
serial_path[0]);
close(fd);
fd = ERROR;
}
return fd;
}
编辑:包括 LOG_INFO()
的定义
/****************************************************************************
* Copyright (C) 2015 Mark Charlebois. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name ATLFlight nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __hexagon__
// Debug output on the aDSP
#include <HAP_farf.h>
#define LOG_INFO(...) FARF(ALWAYS, __VA_ARGS__);
#define LOG_ERR(...) FARF(ALWAYS, __VA_ARGS__);
#define LOG_DEBUG(...) FARF(MEDIUM, __VA_ARGS__);
#else
// Debug output on the apps processor
#include <stdio.h>
#define LOG_INFO(...) do{ printf(__VA_ARGS__); printf("\n"); } while (0)
#define LOG_ERR(...) do{ printf(__VA_ARGS__); printf("\n"); } while (0)
#define LOG_DEBUG(...) do{ printf(__VA_ARGS__); printf("\n"); } while (0)
#endif
#ifdef __cplusplus
}
#endif
输出
int i=-1; LOG_INFO("%d\n",1);
DSP端:
[08500/02] 02:27.822 HAP:24639: -1 0063 helloworld_dsp.c
Linux-方:
-1
来自设备开发者:
The return value from the open() functions is a signed int, and is >=
zero for success, and less than zero for failure.
The reason the return value is so large is because it is offset by a
known constant of 0x0FFFFFFF. This is done to differentiate device
handles from file system handles (file system handles are always less
than 0x0FFFFFFF), which are processed differently in the aDSP code.
古怪! :P
为什么调用open("/dev/tty-2",O_RDWR);
时打开的文件号是268435355(如-1+2^28)?这是从实时操作系统(如 android DSP 端)上的 open() 调用输出的正常大小的数字吗?好像太大了。
DSP 处理器 运行 高通实时 OS。其他处理器 运行 Linaro Linux.
来自 mini-dm
、DSP(数字信号处理器)运行时调试器的相关输出:
Running mini-dm version: 3.0
Device found with Product ID 0x9025. Continuing...
mini-dm is waiting for a DMSS connection...
DMSS is connected. Running mini-dm...
[08500/03] 00:40.640 HAP:63:HAP_debug_v2 weak ref not found, return _rtld_sym_zero@_rtld_objmain 0294 symbol.c
[08500/03] 00:40.640 HAP:63:HAP_debug_v2 weak ref not found, return _rtld_sym_zero@_rtld_objmain 0294 symbol.c
[08500/02] 00:40.640 HAP:63:Opening serial port 0062 helloworld_dsp.c
[08500/00] 00:40.640 configuring UART for 4-wire mode, DAL id: 0x2001005 0852 DalUart.c
[08500/02] 00:40.641 HAP:63:Opened serial port number 268435455 0065 helloworld_dsp.c
[08500/02] 00:40.641 HAP:63:Closing serial port 0075 helloworld_dsp.c
[08500/02] 00:40.641 HAP:63:Successfully closed serial port number 268435455 0078 helloworld_dsp.c
[08500/02] 00:40.641 HAP:63:Opening serial port 0062 helloworld_dsp.c
[08500/02] 00:40.642 HAP:63:workaround: reopening an existing serial port 0351 serial.c
[08500/02] 00:40.642 HAP:63:Opened serial port number 268435455 0065 helloworld_dsp.c
[08500/02] 00:40.642 HAP:63:Beginning serial read 0123 helloworld_dsp.c
[08500/02] 00:40.642 HAP:63:/dev/tty-2 read bytes [0]: 0129 helloworld_dsp.c
[08500/02] 00:40.642 HAP:63:Closing serial port 0075 helloworld_dsp.c
[08500/02] 00:40.642 HAP:63:Successfully closed serial port number 268435455 0078 helloworld_dsp.c
相关 DSP 代码:
int example_interface_serial_open()
{
LOG_INFO("Opening serial port");
serial_fds[0] = open(serial_path[0],O_RDWR);
if (serial_fds[0] >= SUCCESS) {
LOG_INFO("Opened serial port number %d", serial_fds[0]);
} else {
//FIXME log error!
LOG_INFO("Error opening serial port");
serial_fds[0] = ERROR;
}
return serial_fds[0];
}
int example_interface_serial_close(int fd) {
LOG_INFO("Closing serial port");
if (!close(fd)) {
LOG_INFO("Successfully closed serial port number %d", fd);
} else {
LOG_INFO("Error closing serial port");
fd = ERROR;
}
return fd;
}
int example_interface_serial_read(int fd) {
int res = SUCCESS;
char rx_buffer[SERIAL_SIZE_OF_DATA_BUFFER];
unsigned int num_bytes_read;
int active_devices = 0;
int runs, i;
LOG_INFO("Beginning serial read");
memset(rx_buffer, 0, SERIAL_SIZE_OF_DATA_BUFFER);
num_bytes_read = read(fd, rx_buffer,
SERIAL_SIZE_OF_DATA_BUFFER);
LOG_INFO("%s read bytes [%d]: %s",
serial_path[0], num_bytes_read, rx_buffer);
if (res < SUCCESS) {
LOG_INFO("Closing file %s",
serial_path[0]);
close(fd);
fd = ERROR;
}
return fd;
}
编辑:包括 LOG_INFO()
/****************************************************************************
* Copyright (C) 2015 Mark Charlebois. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name ATLFlight nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __hexagon__
// Debug output on the aDSP
#include <HAP_farf.h>
#define LOG_INFO(...) FARF(ALWAYS, __VA_ARGS__);
#define LOG_ERR(...) FARF(ALWAYS, __VA_ARGS__);
#define LOG_DEBUG(...) FARF(MEDIUM, __VA_ARGS__);
#else
// Debug output on the apps processor
#include <stdio.h>
#define LOG_INFO(...) do{ printf(__VA_ARGS__); printf("\n"); } while (0)
#define LOG_ERR(...) do{ printf(__VA_ARGS__); printf("\n"); } while (0)
#define LOG_DEBUG(...) do{ printf(__VA_ARGS__); printf("\n"); } while (0)
#endif
#ifdef __cplusplus
}
#endif
输出
int i=-1; LOG_INFO("%d\n",1);
DSP端:
[08500/02] 02:27.822 HAP:24639: -1 0063 helloworld_dsp.c
Linux-方:
-1
来自设备开发者:
The return value from the open() functions is a signed int, and is >= zero for success, and less than zero for failure.
The reason the return value is so large is because it is offset by a known constant of 0x0FFFFFFF. This is done to differentiate device handles from file system handles (file system handles are always less than 0x0FFFFFFF), which are processed differently in the aDSP code.
古怪! :P