* RT_PREEMPT with RS232 and USB-RS232 adapter
[not found] <f599ebee-26a6-4db9-a47a-58524ee29b99@zmail.sgconsulting.it>
@ 2012-01-19 10:34 ` Forconi
2012-01-25 10:56 ` Thomas Gleixner
0 siblings, 1 reply; 3+ messages in thread
From: Forconi @ 2012-01-19 10:34 UTC (permalink / raw)
To: linux-rt-users
Hi,
I'm working on an RT_PREEMPT patched kernel to test a small C program that sends 39B of data on the serial line every 50ms.
I'm testing the timing accuracy using a scope on the TX pin of the serial cable.
When I run the application using /dev/ttyS0 as serial port I see data starting every 50ms, but when I run the application using a Prolific PL2303 USB-RS232 adapter on /dev/ttyUSB0 I see data out every 250ms.
Is this possible or I'm doing something wrong?
This is the source file of the program I'm using for my test (I modified the "Hello World" example on RT PREEMPT HOWTO page):
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <sched.h>
#include <sys/mman.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#define MY_PRIORITY (79)
#define MAX_SAFE_STACK (8*1024) /* The maximum stack size which is
guranteed safe to access without
faulting */
#define NSEC_PER_SEC (1000000000) /* The number of nsecs per sec. */
#define BAUDRATE B9600
#define _POSIX_SOURCE 1 /* POSIX compliant source */
void stack_prefault(void) {
unsigned char dummy[MAX_SAFE_STACK];
memset(dummy, 0, MAX_SAFE_STACK);
return;
}
int main(int argc, char* argv[])
{
struct timespec t;
struct sched_param param;
int interval = 50000000; /* 50ms*/
int fd, c;
struct termios oldtio, newtio;
char buf[39];
/* Declare ourself as a real time task */
printf("[1]\n");
param.sched_priority = MY_PRIORITY;
if(sched_setscheduler(0, SCHED_FIFO, ¶m) == -1) {
perror("sched_setscheduler failed");
exit(-1);
}
/* Lock memory */
if(mlockall(MCL_CURRENT|MCL_FUTURE) == -1) {
perror("mlockall failed");
exit(-2);
}
/* Pre-fault our stack */
printf("[2]\n");
stack_prefault();
clock_gettime(CLOCK_MONOTONIC ,&t);
/* start after one second */
t.tv_sec++;
/* open serial port */
fd = open(argv[1], O_WRONLY | O_NOCTTY);
if (fd <0) {
perror(argv[1]);
exit(-1);
}
tcgetattr(fd, &oldtio); /* save current port settings */
bzero(&newtio, sizeof(newtio));
newtio.c_cflag = BAUDRATE | CS8 | CLOCAL | CREAD;
newtio.c_iflag = IGNPAR;
newtio.c_oflag = 0;
newtio.c_lflag = 0;
/* set input mode (non-canonical, no echo,...) */
newtio.c_lflag = 0;
newtio.c_cc[VTIME] = 0; /* inter-character timer unused */
newtio.c_cc[VMIN] = 1; /* blocking read until 1 chars received */
printf("[3]\n");
tcflush(fd, TCIFLUSH);
tcsetattr(fd, TCSANOW, &newtio);
printf("[4]\n");
for(c = 0; c < 39; c++)
buf[c] = 0xFF;
printf("writing 39B to serial port %s\n",argv[1]);
while(1) {
/* wait until next shot */
clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &t, NULL);
/* do the stuff */
write(fd, buf, 39);
/* calculate next shot */
t.tv_nsec += interval;
while (t.tv_nsec >= NSEC_PER_SEC) {
t.tv_nsec -= NSEC_PER_SEC;
t.tv_sec++;
}
}
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* RT_PREEMPT with RS232 and USB-RS232 adapter
[not found] <ed1899ce-3cdb-4826-8a35-8b0e9ae1ed01@zmail.sgconsulting.it>
@ 2012-01-19 11:08 ` Forconi
0 siblings, 0 replies; 3+ messages in thread
From: Forconi @ 2012-01-19 11:08 UTC (permalink / raw)
To: linux-rt-users
Hi,
I'm working on an RT_PREEMPT patched kernel to test a small C program that sends 39B of data on the serial line every 50ms.
I'm testing the timing accuracy using a scope on the TX pin of the serial cable.
When I run the application using /dev/ttyS0 as serial port I see data starting every 50ms, but when I run the application using a Prolific PL2303 USB-RS232 adapter on /dev/ttyUSB0 I see data out every 250ms.
Is this possible or I'm doing something wrong?
This is the source file of the program I'm using for my test (I modified the "Hello World" example on RT PREEMPT HOWTO page):
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <sched.h>
#include <sys/mman.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#define MY_PRIORITY (79)
#define MAX_SAFE_STACK (8*1024) /* The maximum stack size which is
guranteed safe to access without
faulting */
#define NSEC_PER_SEC (1000000000) /* The number of nsecs per sec. */
#define BAUDRATE B9600
#define _POSIX_SOURCE 1 /* POSIX compliant source */
void stack_prefault(void) {
unsigned char dummy[MAX_SAFE_STACK];
memset(dummy, 0, MAX_SAFE_STACK);
return;
}
int main(int argc, char* argv[])
{
struct timespec t;
struct sched_param param;
int interval = 50000000; /* 50ms*/
int fd, c;
struct termios oldtio, newtio;
char buf[39];
/* Declare ourself as a real time task */
printf("[1]\n");
param.sched_priority = MY_PRIORITY;
if(sched_setscheduler(0, SCHED_FIFO, ¶m) == -1) {
perror("sched_setscheduler failed");
exit(-1);
}
/* Lock memory */
if(mlockall(MCL_CURRENT|MCL_FUTURE) == -1) {
perror("mlockall failed");
exit(-2);
}
/* Pre-fault our stack */
printf("[2]\n");
stack_prefault();
clock_gettime(CLOCK_MONOTONIC ,&t);
/* start after one second */
t.tv_sec++;
/* open serial port */
fd = open(argv[1], O_WRONLY | O_NOCTTY);
if (fd <0) {
perror(argv[1]);
exit(-1);
}
tcgetattr(fd, &oldtio); /* save current port settings */
bzero(&newtio, sizeof(newtio));
newtio.c_cflag = BAUDRATE | CS8 | CLOCAL | CREAD;
newtio.c_iflag = IGNPAR;
newtio.c_oflag = 0;
newtio.c_lflag = 0;
/* set input mode (non-canonical, no echo,...) */
newtio.c_lflag = 0;
newtio.c_cc[VTIME] = 0; /* inter-character timer unused */
newtio.c_cc[VMIN] = 1; /* blocking read until 1 chars received */
printf("[3]\n");
tcflush(fd, TCIFLUSH);
tcsetattr(fd, TCSANOW, &newtio);
printf("[4]\n");
for(c = 0; c < 39; c++)
buf[c] = 0xFF;
printf("writing 39B to serial port %s\n",argv[1]);
while(1) {
/* wait until next shot */
clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &t, NULL);
/* do the stuff */
write(fd, buf, 39);
/* calculate next shot */
t.tv_nsec += interval;
while (t.tv_nsec >= NSEC_PER_SEC) {
t.tv_nsec -= NSEC_PER_SEC;
t.tv_sec++;
}
}
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: RT_PREEMPT with RS232 and USB-RS232 adapter
2012-01-19 10:34 ` RT_PREEMPT with RS232 and USB-RS232 adapter Forconi
@ 2012-01-25 10:56 ` Thomas Gleixner
0 siblings, 0 replies; 3+ messages in thread
From: Thomas Gleixner @ 2012-01-25 10:56 UTC (permalink / raw)
To: Forconi; +Cc: linux-rt-users
On Thu, 19 Jan 2012, Forconi wrote:
> I'm working on an RT_PREEMPT patched kernel to test a small C
> program that sends 39B of data on the serial line every 50ms.
> I'm testing the timing accuracy using a scope on the TX pin of the
> serial cable.
> When I run the application using /dev/ttyS0 as serial port I see
> data starting every 50ms, but when I run the application using a
> Prolific PL2303 USB-RS232 adapter on /dev/ttyUSB0 I see data out
> every 250ms.
> Is this possible or I'm doing something wrong?
Why do you expect that USB is in any way deterministic?
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-01-25 10:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <f599ebee-26a6-4db9-a47a-58524ee29b99@zmail.sgconsulting.it>
2012-01-19 10:34 ` RT_PREEMPT with RS232 and USB-RS232 adapter Forconi
2012-01-25 10:56 ` Thomas Gleixner
[not found] <ed1899ce-3cdb-4826-8a35-8b0e9ae1ed01@zmail.sgconsulting.it>
2012-01-19 11:08 ` Forconi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).