[英]How to Read data from RS232 port without RS232 task creation (Embedded FreeRTOS C)?
[英]C RS232 comm. How to compare CPU time?
第一次发布,因此可能会有更多不必要的信息,但我想更详尽:
在C语言中,我们的练习之一是创建发送程序和接收程序,这些程序将通过与空调制解调器的RS232串行通信交换数据。 我们使用了虚拟端口程序(如果要测试,我使用了eltima软件提供的虚拟串行端口的试用版)。 我们需要做4个版本:
1)使用由以前的学生创建的预定库,该库具有发送者和接收者等预制功能2)使用inportb和outportb函数3)使用OS中断int86并通过REGS联合提供寄存器值4)使用内联汇编
编译器:DevCPP(失血)。
一切正常,但是现在我们需要根据发送和接收字符所花费的CPU时间来比较所有不同的版本。 具体来说,我们必须找到以下内容:
平均值,标准偏差,最小值,最大值和99.5%
上课什么都没解释,所以我在这里有点迷路了……我猜想这些是经过多次正态分布试验后的统计数字吗? 但是即使如此,我该如何实际测量CPU周期呢? 我会继续搜索,但同时我会在此发布,因为截止日期为3天:D。
int86版本的代码示例:
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
#define RS232_INIT_FUNCTION 0
#define RS232_SEND_FUNCTION 1
#define RS232_GET_FUNCTION 2
#define RS232_STATUS_FUNCTION 3
#define DATA_READY 0x01
#define PARAM 0xEF
#define COM1 0
#define COM2 1
void rs232init (int port, unsigned init_code)
{
union REGS inregs;
inregs.x.dx=port;
inregs.h.ah=RS232_INIT_FUNCTION;
inregs.h.al=init_code;
int86(0x14,&inregs,&inregs);
}
unsigned char rs232transmit (int port, char ch)
{
union REGS inregs;
inregs.x.dx=port;
inregs.h.ah=RS232_SEND_FUNCTION;
inregs.h.al=ch;
int86(0x14,&inregs,&inregs);
return (inregs.h.ah);
}
unsigned char rs232status(int port){
union REGS inregs;
inregs.x.dx=port;
inregs.h.ah=RS232_STATUS_FUNCTION;
int86(0x14, &inregs, &inregs);
return (inregs.h.ah); //Because we want the second byte of ax
}
unsigned char rs232receive(int port)
{
int x,a;
union REGS inregs;
while(!(rs232status(port) & DATA_READY))
{
if(kbhit()){
getch();
exit(1);
}
};
inregs.x.dx=port;
inregs.h.ah=RS232_GET_FUNCTION;
int86(0x14,&inregs,&inregs);
if(inregs.h.ah & 0x80)
{
printf("ERROR");
return -1;
}
return (inregs.h.al);
}
int main(){
unsigned char ch;
int d,e,i;
do{
puts("What would you like to do?");
puts("1.Send data");
puts("2.Receive data");
puts("0.Exit");
scanf("%d",&i);
getchar();
if(i==1){
rs232init(COM1, PARAM);
puts("Which char would you like to send?");
scanf("%c",&ch);
getchar();
while(!rs232status(COM1));
d=rs232transmit(COM1,ch);
if(d & 0x80) puts("ERROR"); //Checks the bit 7 of ah for error
}
else if(i==2){
rs232init(COM1,PARAM);
puts("Receiving character...");
ch=rs232receive(COM1);
printf("%c\n",ch);
}
}while(i != 0);
system("pause");
return 0;
}
这里的问题有些不确定,因此需要一些猜测。
您列出了四种发送/接收字符的方法。 我怀疑您的讲师正在寻找的是从您调用给定方法(或输入内联汇编代码)到您从该方法返回(保留内联代码)的时间。 您将需要在通话之前和通话之后花费一些时间,以找到它们的区别。
不那么模糊的是CPU时间。 clock()方法是执行此操作的最直接方法,但是这可能不是讲师正在寻找的方法。
最后是统计信息,这很简单。 做一堆跑步,并根据时间运行一些统计数据
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.