All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai] xeno_16550A: only 115200 Baud possible
@ 2013-04-19 12:37 Christopher Hahn
  2013-04-19 12:42 ` Jan Kiszka
  0 siblings, 1 reply; 2+ messages in thread
From: Christopher Hahn @ 2013-04-19 12:37 UTC (permalink / raw)
  To: xenomai

Hello,

I tried to send a message over a rt serial interface. Without the 
xeno_16550A module loaded everything works fine.

My steps are:

# deactive default serial port
setserial /dev/ttyS1 uart none

# load real-time serial driver module
modprobe xeno_16550A io=0x2f8 irq=3 baud_base=9600

then I get my rtser0 interface.

Then I try to configure the serial interface with:

static const struct rtser_config serial_config = {
         .config_mask       = 0xFFFF,
         .baud_rate         = 9600,
         .parity            = RTSER_NO_PARITY,
         .data_bits         = RTSER_8_BITS,
         .stop_bits         = RTSER_1_STOPB,
         .handshake         = RTSER_DEF_HAND,
         .fifo_depth        = RTSER_DEF_FIFO_DEPTH,
         .rx_timeout        = RTSER_DEF_TIMEOUT,
         .tx_timeout        = RTSER_DEF_TIMEOUT,
         .event_timeout     = RTSER_DEF_TIMEOUT,
         .timestamp_history = RTSER_DEF_TIMESTAMP_HISTORY,
         .event_mask        = RTSER_EVENT_RXPEND,
     };


and send a message with

written = rt_dev_write(serial_fd, sendmsg, sizeof(sendmsg));


Now I connect the other end of my serial cable to my notebook, start 
putty with COM1 9600-8-N-1 and only get rubbish. I have to change the 
baudrate in putty to 115200 to receive the correct message!

So far, so bad, BUT now I reset everything... unload xeno_16550A module 
and configure the serial port again:
#unload xeno_16550A module
rmmod xeno_16550A

#configure ttyS1
setserial /dev/ttyS1 uart 16550A base_baud 9600

and try to send again with 9600 baud and with the ordinary serial driver 
-> only rubbish on the other side (9600 Baud)

I also have to configure putty to 115200 baud to receive the message.

Do you have any idea?







-------------- next part --------------
#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/mman.h>


#include <rtdk.h>
#include <rtdm/rtserial.h>
#include <native/task.h>


static const struct rtser_config serial_config = {
		.config_mask       = 0xFFFF,
		.baud_rate         = 9600,
		.parity            = RTSER_NO_PARITY,
		.data_bits         = RTSER_8_BITS,
		.stop_bits         = RTSER_1_STOPB,
		.handshake         = RTSER_DEF_HAND,
		.fifo_depth        = RTSER_DEF_FIFO_DEPTH,
		.rx_timeout        = RTSER_DEF_TIMEOUT,
		.tx_timeout        = RTSER_DEF_TIMEOUT,
		.event_timeout     = RTSER_DEF_TIMEOUT, /* 1 s */
		.timestamp_history = RTSER_DEF_TIMESTAMP_HISTORY,
		.event_mask        = RTSER_EVENT_RXPEND,
	};

#define WRITE_FILE     "rtser0"

#define DEBUG 1
#define TASK_PREFIX "Serial_write: "

int serial_fd = -1;

RT_TASK write_task;

void catch_signal(int sig) {
	rt_printf("exit\n");
	exit(0);
}

void write_task_proc(void *arg) {
	int err;
	unsigned long ov;
	char sendmsg[5] = "G3\r";
	ssize_t written = 0;

	/*
	 * make this task periodic
	 */
	rt_task_set_periodic(NULL, TM_NOW, (1000 * 1e6)); // 1000ms

	while (1) {

		written = rt_dev_write(serial_fd, sendmsg, sizeof(sendmsg));
		if (written < 0) {
			rt_printf(TASK_PREFIX "error on rt_dev_write, %s\n", strerror(-err));
			break;
		} else if (written != sizeof(sendmsg)) {
			rt_printf(TASK_PREFIX "only %d / %d byte transmitted\n", written, sizeof(sendmsg));
			break;
		}

		if (DEBUG)
			rt_printf("send: '%s'\n", sendmsg);

		err = rt_task_wait_period(&ov);
		if (err) {
			rt_fprintf(stderr, TASK_PREFIX "rt_task_wait_period: %s\n", strerror(-err));
		}

		if (ov >= 1) {
			rt_printf(TASK_PREFIX "OVERRUN!\n");
			break;
		}

	}

	rt_printf(TASK_PREFIX "exit\n");
}

int initSerial(void) {
	int err = 0;

	/* open rtser0 */
	serial_fd = rt_dev_open(WRITE_FILE, 0);
	if (serial_fd < 0) {

		rt_printf(TASK_PREFIX "can't open %s (read), %s\n", WRITE_FILE, strerror(-serial_fd));

		return -serial_fd;
	}

	if (DEBUG)
		rt_printf(TASK_PREFIX "read-file opened\n");

	/* writing serial-config */
	err = rt_dev_ioctl(serial_fd, RTSER_RTIOC_SET_CONFIG, &serial_config);
	if (err) {

		rt_printf(TASK_PREFIX "error while rt_dev_ioctl, %s\n", strerror(-err));

		return err;
	}

	if (DEBUG)
		rt_printf(TASK_PREFIX "serial_config_init written\n");

	return 0;
}

int main(void) {
    int err = 0;

    signal(SIGTERM, catch_signal);
	signal(SIGINT, catch_signal);

	/* Perform auto-init of rt_print buffers if the task doesn't do so */
	rt_print_auto_init(1);

	/* no memory-swapping for this programm */
	mlockall(MCL_CURRENT | MCL_FUTURE);

	/*
	 * initalize serial device
	 */
	err = initSerial();
	if (err) {
		rt_printf(TASK_PREFIX "failed to initialize serial port, %s\n", strerror(-err));
		return 0;
	}

	/* create write_task */
	err = rt_task_create(&write_task, "write_task", 0, 99, 0);
	if (err) {
		rt_printf(TASK_PREFIX "failed to create read_task, %s\n", strerror(-err));
		return 0;
	}
	if (DEBUG) rt_printf(TASK_PREFIX "write-task created\n");

	/* start write_task */
	if (DEBUG) rt_printf(TASK_PREFIX "starting write-task\n");
	err = rt_task_start(&write_task, &write_task_proc, NULL );
	if (err) {
		rt_printf(TASK_PREFIX "failed to start write_task, %s\n", strerror(-err));
		return 0;
	}
	if (DEBUG) rt_printf(TASK_PREFIX "write-task started\n");

	pause();
	return 0;

}





^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Xenomai] xeno_16550A: only 115200 Baud possible
  2013-04-19 12:37 [Xenomai] xeno_16550A: only 115200 Baud possible Christopher Hahn
@ 2013-04-19 12:42 ` Jan Kiszka
  0 siblings, 0 replies; 2+ messages in thread
From: Jan Kiszka @ 2013-04-19 12:42 UTC (permalink / raw)
  To: Christopher Hahn; +Cc: xenomai

On 2013-04-19 14:37, Christopher Hahn wrote:
> Hello,
> 
> I tried to send a message over a rt serial interface. Without the
> xeno_16550A module loaded everything works fine.
> 
> My steps are:
> 
> # deactive default serial port
> setserial /dev/ttyS1 uart none
> 
> # load real-time serial driver module
> modprobe xeno_16550A io=0x2f8 irq=3 baud_base=9600

Unless you have a very special UART adapter (I would say, you don't),
there is no need to play with baud_base. Check modinfo regarding the
semantic of the parameter.

Jan

-- 
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE
Corporate Competence Center Embedded Linux


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-04-19 12:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-19 12:37 [Xenomai] xeno_16550A: only 115200 Baud possible Christopher Hahn
2013-04-19 12:42 ` Jan Kiszka

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.