我在PXA270 RISC PC/104上的RS232通信中经历了长时间的延迟(1.5ms - 9.5ms).我想尽量减少长时间的延迟,但我是嵌入式设备和C++的初学者,所以我觉得我错过了一些东西.
上述延迟是在PXA板通过RS232(115200波特)从外部设备接收数据包之前,直到它将ACK自定义数据包发送回外部设备.我用示波器测量了PXA板上的延迟,一个通道位于Rx,另一个通道位于Tx.
PXA板运行的是Arcom嵌入式Linux(AEL).我知道,它不是一个实时操作系统,但我仍然认为,4.5ms的平均延迟对于提取接收到的数据包来说太高了,验证它是CRC16,构造一个ACK数据包(带CRC)并将其发送回串行线.我还故意将CPU置于高负载(一些并行gzip操作)但延迟时间根本没有增加.接收数据包的最大大小为30个字节.
C++应用程序(另一位前同事写的)处理数据包的接收及其确认.一个线程正在发送,另一个正在接收数据包.
我认为PXA板上的RTC分辨率非常差,AEL无法将时序与内部RTC分辨率对齐.但RTC的频率为32.768 kHz.分辨率足够,仍然不解释高延迟.顺便说一句,我认为操作系统正在使用内部PXA时钟(也具有足够的分辨率)而不是RTC用于时序.
因此问题必须出在C++应用程序或RS232接口的驱动程序/ OS设置中.
根据POSIX操作系统的串行编程指南,以下控制标志用于C++应用程序中的RS232通信:
// Open RS232 on COM1
mPhysicalComPort = open(aPort, O_RDWR | O_NOCTTY | O_NDELAY);
// Force read call to block if no data available
int f = fcntl(mPhysicalComPort, F_GETFL, 0);
f &= ~O_NONBLOCK;
fcntl(mPhysicalComPort, F_SETFL, f);
// Get the current options for the port...
tcgetattr(mPhysicalComPort, &options);
// ... and set them to the desired values
cfsetispeed(&options, baudRate);
cfsetospeed(&options, baudRate);
// …Run Code Online (Sandbox Code Playgroud) 我在Android上的OrmLite有一个小问题.
当我增加数据库版本时,onUpgrade在我的OrmLite Helper中按预期调用该方法.升级后,onCreate调用该方法,我得到以下异常:
11-24 10:09:45.720: ERROR/AndroidConnectionSource(390): connection saved
com.j256.ormlite.android.AndroidDatabaseConnection@44f0f478 is not the one
being cleared com.j256.ormlite.android.AndroidDatabaseConnection@44f5d310
Run Code Online (Sandbox Code Playgroud)
我不清楚为什么清除的连接与保存的连接不一样.
我还将我的数据库函数(插入...)放入OrmLite Helper类中.也许这可能是个问题?!?
来自我的助手类的片段:
public class OrmLiteDBProvider extends OrmLiteSqliteOpenHelper
implements IEntityProvider, IDBProvider {
//snip
@Override
public void onCreate(SQLiteDatabase db, ConnectionSource connectionSource) {
try {
Log.i(OrmLiteDBProvider.class.getName(), "Creating database and tables");
TableUtils.createTable(connectionSource, OrgManaged.class);
} catch (SQLException e) {
Log.e(OrmLiteDBProvider.class.getName(),
"Can't create database and tables", e);
throw new RuntimeException(e);
}
}
@Override
public void onUpgrade(SQLiteDatabase db, ConnectionSource connectionSource,
int oldVersion, int newVersion) { …Run Code Online (Sandbox Code Playgroud)