LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Serial loopback test (uart) (https://www.linuxquestions.org/questions/linux-newbie-8/serial-loopback-test-uart-912623/)

shankar.489 11-09-2011 06:05 AM

Serial loopback test (uart)
 
Hello Folk,

iam trying to write a loopback test for serial port(COM1)

for this i have done below coding, this code is working fine in my pc(redhat), same is not working in windriver kernel 4.1. Could anybody please correct where iam doing wrong.

also please suggest me a best way of writing serial loopback test.

the UART driver is properly loaded and iam able to telnet the pc(with kernel wind river4.1).

since iam directly reading/writing UART the registers iam thinking that no need to consider baudrate. iam not at all changing any system baudrate(using system default baudrate).


below is the code.

#define BASE_ADDR 0x3f8
int WriteAdrPort(void)
{
int iOut=1;
char Byte=0;
char i=0;
for(i=0;i<26;i++)
{
outb((65+i),BASE_ADDR);
sleep(2);
Byte=inb(BASE_ADDR);
printf("byte read= %c\n",Byte);
if(Byte == 65+i)
{
iOut=0;
}
else
{
printf("TX and Rx Data not matching\n");
return iOut;
}
}

return iOut;
}


int main(int argc, char *argv[])
{
unsigned char byte=0;
unsigned char old=0;
ioperm(BASE_ADDR,7,1);
old=inb(BASE_ADDR+4);
byte=old;

byte=(unsigned char)(inb(BASE_ADDR+4)); // address of MCR

printf("setting loopback bit\n");//bit 4 of MCR reg
byte=(byte|16);// setting the loop back bit

outb(byte,(BASE_ADDR+4));//setting the loopback bit

WriteAdrPort() ;
outb(old,(BASE_ADDR+4));// resetting the MCR to default value
return 0;
}//main ends


thanks for your help in advance..:hattip:
regards,
shankar.

akuthia 11-09-2011 09:22 AM

I cant help you with coding, but please put the code in [ code ] tags so it keeps formatting, and doesnt take up a mile worth of space :)


All times are GMT -5. The time now is 03:22 AM.