Skip to contentSkip to conversation

16550A driver and Moxa card / solved

Xenomai-core CHABAL David 3 participants 20 messages May 11, 2007

lore
Share & tools
lore
#0 lore raw

Hello,

I met some trouble with the 16550A driver provided in Xenomai 2.3.1 and my Moxa cards (PCI / 8 * RS232 / 168U ).

It was a problem of baudrate computation before setting the LCR_DLAB register.

The formula implemented by the Xenomai driver is different from the one provided by Moxa. So I copy/paste the formula from the mxser.c file (present in the
kernel distro), and it seems to work fine.

I think it's Moxa card dependant, may be caused by the high default baud rate of this card.

I post here my patch below, it may interest someone.

David

----------------------------------------------

@@ -29,7 +29,7 @@
#define IN_BUFFER_SIZE 4096
#define OUT_BUFFER_SIZE 4096

-#define DEFAULT_BAUD_BASE   115200
+#define DEFAULT_BAUD_BASE   921600
 #define DEFAULT_TX_FIFO     16

#define PARITY_MASK 0x03
@@ -316,8 +316,23 @@

     if (testbits(config->config_mask, RTSER_SET_BAUD)) {
         ctx->config.baud_rate = config->baud_rate;

- baud_div = (baud_base[dev_id] + (ctx->config.baud_rate >> 1)) /
- ctx->config.baud_rate;
+ if (ctx->config.baud_rate == 134)
+ {
+ baud_div = (2 * baud_base[dev_id] / 269);

+        }
+        else
+        {

+ if (ctx->config.baud_rate)
+ {
+ baud_div = baud_base[dev_id] / ctx->config.baud_rate;
+ if (baud_div == 0)
+ baud_div = 1;
+ }
+ else
+ {
+ baud_div = 0;
+ }
+ }

         outb(LCR_DLAB,        LCR(dev_id));
         outb(baud_div & 0xff, DLL(dev_id));
         outb(baud_div >> 8,   DLM(dev_id));
#1 lore raw
Quoted 13 lines · CHABAL David

Hello,

I met some trouble with the 16550A driver provided in Xenomai 2.3.1 and my Moxa cards (PCI / 8 * RS232 / 168U ).

It was a problem of baudrate computation before setting the LCR_DLAB register.

The formula implemented by the Xenomai driver is different from the one provided by Moxa. So I copy/paste the formula from the mxser.c file (present in the
kernel distro), and it seems to work fine.

Quoted 4 lines

I think it's Moxa card dependant, may be caused by the high default baud rate of this card.

I post here my patch below, it may interest someone.

Thanks for sharing your findings. Will check if/how we can integrate them. See some comments below already.

[Reminds me that there are more 16550A patches pending in my inbox... :-/]

Review line 32

Quoted 13 lines

David

----------------------------------------------

(quoted diff) +1 -1
@@ -29,7 +29,7 @@
 #define IN_BUFFER_SIZE      4096
 #define OUT_BUFFER_SIZE     4096
 
-#define DEFAULT_BAUD_BASE   115200
+#define DEFAULT_BAUD_BASE   921600

OK, that's for your convenience right now. We also have a module parameter to set the base.

Review line 322

Quoted 13 lines
(quoted diff) +4 -2
 #define DEFAULT_TX_FIFO     16
 
 #define PARITY_MASK         0x03
@@ -316,8 +316,23 @@
 
     if (testbits(config->config_mask, RTSER_SET_BAUD)) {
         ctx->config.baud_rate = config->baud_rate;
-        baud_div = (baud_base[dev_id] + (ctx->config.baud_rate >> 1)) /
-                   ctx->config.baud_rate;
+        if (ctx->config.baud_rate == 134)
+        {
+          baud_div = (2 * baud_base[dev_id] / 269);
+        }

Well, whoever needs such low rates in practice these days... :)

Review line 325

Quoted 3 lines
(quoted diff) +3 -0
+        else
+        {
+          if (ctx->config.baud_rate)

Oops, that check protects us from dividing by zero - should be fixed in any case! Or is baud_div = 0 a special mode with Moxa?

Review line 327

Quoted 2 lines
(quoted diff) +2 -0
+          {
+            baud_div = baud_base[dev_id] / ctx->config.baud_rate;

So this means dividing with round down instead of round up. We could enable this mode with an additional module parameter, something like variant = {0: standard, 1: moxa, ...}. That could also raise the default baudbase for the particular port.

Review line 329

Quoted 2 lines
(quoted diff) +2 -0
+                 if (baud_div == 0)
+              baud_div = 1;

That shouldn't trigger with xeno_16550A because we catch baud_rate > baud_base already in rt_16550_ioctl.

Review line 338

Quoted 10 lines
(quoted diff) +6 -0
+               }
+          else
+          {
+                 baud_div = 0;
+          }
+        }
         outb(LCR_DLAB,        LCR(dev_id));
         outb(baud_div & 0xff, DLL(dev_id));
         outb(baud_div >> 8,   DLM(dev_id));

Jan

#2 lore raw
In reply to CHABAL David

CHABAL David пишет:

Quoted 6 lines

I met some trouble with the 16550A driver provided in Xenomai 2.3.1 and my Moxa cards (PCI / 8 * RS232 / 168U ).

It was a problem of baudrate computation before setting the LCR_DLAB register.

Quoted 7 lines

The formula implemented by the Xenomai driver is different from the one provided by Moxa. So I copy/paste the formula from the mxser.c file (present in the
kernel distro), and it seems to work fine.

I think it's Moxa card dependant, may be caused by the high default baud rate of this card.

I have two Moxa boards with no problem, possible you need to specify 'baud_base' param.

I my case :

# 8 ports board:
/sbin/modprobe xeno_16550A \
ioaddr=0x1000,0x1008,0x1010,0x1018,0x1020,0x1028,0x1030,0x1038 \
irq=9,9,9,9,9,9,9,9 \
baud_base=921600,921600,921600,921600,921600,921600,921600,921600

# 2 ports board + onboards:
/sbin/modprobe xeno_16550A ioaddr=0x3f8,0x2f8,0xdf00,0xdf08 irq=4,3,11,11 baud_base=115200,115200,921600,921600

Signature · 2 lines
________________________________________
Maksym Veremeyenko
#3 lore raw
Quoted 27 lines · Maksym Veremeyenko

CHABAL David пишет:

Quoted 6 lines

I met some trouble with the 16550A driver provided in Xenomai 2.3.1 and my Moxa cards (PCI / 8 * RS232 / 168U ).

It was a problem of baudrate computation before setting the LCR_DLAB register.

Quoted 7 lines

The formula implemented by the Xenomai driver is different from the one provided by Moxa. So I copy/paste the formula from the mxser.c file (present in the
kernel distro), and it seems to work fine.

I think it's Moxa card dependant, may be caused by the high default baud rate of this card.

I have two Moxa boards with no problem, possible you need to specify 'baud_base' param.

I my case :

# 8 ports board:
/sbin/modprobe xeno_16550A \
ioaddr=0x1000,0x1008,0x1010,0x1018,0x1020,0x1028,0x1030,0x1038 \
irq=9,9,9,9,9,9,9,9 \
baud_base=921600,921600,921600,921600,921600,921600,921600,921600

Quoted 4 lines

# 2 ports board + onboards:
/sbin/modprobe xeno_16550A ioaddr=0x3f8,0x2f8,0xdf00,0xdf08 irq=4,3,11,11 baud_base=115200,115200,921600,921600

Interesting. That would leave us just with the generic fix to catch baud_rate==0. Far more attractive. :)

David, can you confirm this? Weren't you just aware of the baud_base parameter?

Jan

#4 lore raw
Quoted 33 lines · Jan Kiszka
Quoted 27 lines · Maksym Veremeyenko

CHABAL David пишет:

Quoted 6 lines

I met some trouble with the 16550A driver provided in Xenomai 2.3.1 and my Moxa cards (PCI / 8 * RS232 / 168U ).

It was a problem of baudrate computation before setting the LCR_DLAB register.

Quoted 7 lines

The formula implemented by the Xenomai driver is different from the one provided by Moxa. So I copy/paste the formula from the mxser.c file (present in the
kernel distro), and it seems to work fine.

I think it's Moxa card dependant, may be caused by the high default baud rate of this card.

I have two Moxa boards with no problem, possible you need to specify 'baud_base' param.

I my case :

# 8 ports board:
/sbin/modprobe xeno_16550A \
ioaddr=0x1000,0x1008,0x1010,0x1018,0x1020,0x1028,0x1030,0x1038 \
irq=9,9,9,9,9,9,9,9 \
baud_base=921600,921600,921600,921600,921600,921600,921600,921600

Quoted 4 lines

# 2 ports board + onboards:
/sbin/modprobe xeno_16550A ioaddr=0x3f8,0x2f8,0xdf00,0xdf08 irq=4,3,11,11 baud_base=115200,115200,921600,921600

Quoted 5 lines

Interesting. That would leave us just with the generic fix to catch baud_rate==0. Far more attractive. :)

David, can you confirm this? Weren't you just aware of the baud_base parameter?

I'm not totally convinced because if I compute by hand the DLAB register with the 19200 value (my config):

With the moxa driver:
baud_div = 912.600 / 19.200 = 47

With the Xeno driver:
baud_div = (912.600 - 9600) / 19.200 = 47

Grrr, it's ok here because the rounded values are the same because the baud base is biggest than the speed requested, but I think a problem can occur with 115200 or more, example:

moxa: 912.600/115.200 = 8
xeno: = 7

Maksym, what is the kind of yours connections ? (PC <-> PC with the same moxa cards inside the 2 boxes, or PC <-> other device ) ? (In the 1st the case the both clocks are configured with the same value.)

I find the pb by seeing the signals with an oscilloscope

David

Quoted 3 lines

Jan

#5 lore raw

CHABAL David пишет:

Quoted 3 lines

Maksym, what is the kind of yours connections ? (PC <-> PC with the same moxa cards inside the 2 boxes, or PC <-> other device ) ? (In the 1st the case the both clocks are configured with the same value.)

in first case (8 ports board):
- 2 ports (at 38400) to linux host, 2.6.19.2, mxser
- 1 port (at 115200) to winxp host
- 1 port (at 19200) to switcher/mixer (wxworks perhaps inside)

in second case
- 1 port (moxa port at 38400) to videoserver
- 1 port (onboard at 19200) to to switcher/mixer

I had some difficults first time when no specifying base - 2 ports has connectivity but no connectivity (or broken data) from another non RT host :-))

Signature · 2 lines
________________________________________
Maksym Veremeyenko
#6 lore raw
In reply to CHABAL David
Quoted 48 lines · CHABAL David
Quoted 31 lines · Jan Kiszka
Quoted 26 lines · Maksym Veremeyenko

CHABAL David пишет:

Quoted 6 lines

I met some trouble with the 16550A driver provided in Xenomai 2.3.1 and my Moxa cards (PCI / 8 * RS232 / 168U ).

It was a problem of baudrate computation before setting the LCR_DLAB register.

Quoted 7 lines

The formula implemented by the Xenomai driver is different from the one provided by Moxa. So I copy/paste the formula from the mxser.c file (present in the
kernel distro), and it seems to work fine.

I think it's Moxa card dependant, may be caused by the high default baud rate of this card.

I have two Moxa boards with no problem, possible you need to specify 'baud_base' param.

I my case :

# 8 ports board:
/sbin/modprobe xeno_16550A \
ioaddr=0x1000,0x1008,0x1010,0x1018,0x1020,0x1028,0x1030,0x1038 \
irq=9,9,9,9,9,9,9,9 \
baud_base=921600,921600,921600,921600,921600,921600,921600,921600

Quoted 4 lines

# 2 ports board + onboards:
/sbin/modprobe xeno_16550A ioaddr=0x3f8,0x2f8,0xdf00,0xdf08 irq=4,3,11,11 baud_base=115200,115200,921600,921600

Quoted 5 lines

Interesting. That would leave us just with the generic fix to catch baud_rate==0. Far more attractive. :)

David, can you confirm this? Weren't you just aware of the baud_base parameter?

I'm not totally convinced because if I compute by hand the DLAB register with the 19200 value (my config):

With the moxa driver:
baud_div = 912.600 / 19.200 = 47

With the Xeno driver:
baud_div = (912.600 - 9600) / 19.200 = 47

Quoted 6 lines

Grrr, it's ok here because the rounded values are the same because the baud base is biggest than the speed requested, but I think a problem can occur with 115200 or more, example:

moxa: 912.600/115.200 = 8
xeno: = 7

Yeah, hard arguments. This really cries for a moxa tweak. (The alternative would be to pass an artificially increased baud_base - but that would be _really_ ugly and we could also ask the user for the divider directly...)

Jan

#7 lore raw
Quoted 52 lines · Jan Kiszka
Quoted 51 lines · CHABAL David
Quoted 31 lines · Jan Kiszka
Quoted 26 lines · Maksym Veremeyenko

CHABAL David пишет:

Quoted 6 lines

I met some trouble with the 16550A driver provided in Xenomai 2.3.1 and my Moxa cards (PCI / 8 * RS232 / 168U ).

It was a problem of baudrate computation before setting the LCR_DLAB register.

Quoted 7 lines

The formula implemented by the Xenomai driver is different from the one provided by Moxa. So I copy/paste the formula from the mxser.c file (present in the
kernel distro), and it seems to work fine.

I think it's Moxa card dependant, may be caused by the high default baud rate of this card.

I have two Moxa boards with no problem, possible you need to specify 'baud_base' param.

I my case :

# 8 ports board:
/sbin/modprobe xeno_16550A \
ioaddr=0x1000,0x1008,0x1010,0x1018,0x1020,0x1028,0x1030,0x1038 \
irq=9,9,9,9,9,9,9,9 \
baud_base=921600,921600,921600,921600,921600,921600,921600,921600

Quoted 4 lines

# 2 ports board + onboards:
/sbin/modprobe xeno_16550A ioaddr=0x3f8,0x2f8,0xdf00,0xdf08 irq=4,3,11,11 baud_base=115200,115200,921600,921600

Quoted 5 lines

Interesting. That would leave us just with the generic fix to catch baud_rate==0. Far more attractive. :)

David, can you confirm this? Weren't you just aware of the baud_base parameter?

I'm not totally convinced because if I compute by hand the DLAB register with the 19200 value (my config):

With the moxa driver:
baud_div = 912.600 / 19.200 = 47

With the Xeno driver:
baud_div = (912.600 - 9600) / 19.200 = 47

Grrr, it's ok here because the rounded values are the same because the baud base is biggest than the speed requested, but I think a problem can occur with 115200 or more, example:

Quoted 7 lines
Quoted 2 lines

moxa: 912.600/115.200 = 8
xeno: = 7

Yeah, hard arguments. This really cries for a moxa tweak. (The alternative would be to pass an artificially increased baud_base - but that would be _really_ ugly and we could also ask the user for the divider directly...)

Here we go. This patch should add the most essential changes of your patch to SVN trunk (backport not officially planned, but it should not be tricky). The idea is to pass "variant=1" to xeno_16550A on load. That will kick out rounding on divider calculation and even switches the default baud base.

Comments/test reports welcome.

Jan

drivers/serial/16550A.c +21 -10
Index: ksrc/drivers/serial/16550A.c
===================================================================
@@ -28,10 +28,14 @@
 
 #define MAX_DEVICES		8
 
+#define VARIANT_STANDARD	0
+#define VARIANT_MOXA		1
+
 #define IN_BUFFER_SIZE		4096
 #define OUT_BUFFER_SIZE		4096
 
 #define DEFAULT_BAUD_BASE	115200
+#define DEFAULT_BAUD_BASE_MOXA	921600
 #define DEFAULT_TX_FIFO		16
 
 #define PARITY_MASK		0x03
@@ -121,11 +125,13 @@ static struct rtdm_device *device[MAX_DE
 static unsigned int irq[MAX_DEVICES];
 static unsigned int baud_base[MAX_DEVICES];
 static int tx_fifo[MAX_DEVICES];
+static int variant[MAX_DEVICES];
 static unsigned int start_index;
 
 compat_module_param_array(irq, uint, MAX_DEVICES, 0400);
 compat_module_param_array(baud_base, uint, MAX_DEVICES, 0400);
 compat_module_param_array(tx_fifo, int, MAX_DEVICES, 0400);
+compat_module_param_array(variant, int, MAX_DEVICES, 0400);
 
 MODULE_PARM_DESC(irq, "IRQ numbers of the serial devices");
 MODULE_PARM_DESC(baud_base, "Maximum baud rate of the serial device "
@@ -302,20 +308,24 @@ static int rt_16550_set_config(struct rt
 	rtdm_lockctx_t lock_ctx;
 	unsigned long base = ctx->base_addr;
 	int mode = rt_16550_io_mode_from_ctx(ctx);
-	int dev_id;
 	int err = 0;
-	int baud_div = 0;
 
 	/* make line configuration atomic and IRQ-safe */
 	rtdm_lock_get_irqsave(&ctx->lock, lock_ctx);
 
 	if (testbits(config->config_mask, RTSER_SET_BAUD)) {
-		dev_id = container_of(((void *)ctx), struct rtdm_dev_context,
-				      dev_private)->device->device_id;
+		int dev_id = container_of(((void *)ctx),
+					  struct rtdm_dev_context,
+					  dev_private)->device->device_id;
+		int rounding = ctx->config.baud_rate >> 1;
+		int baud_div = 0;
+
+		if (variant[dev_id] == VARIANT_MOXA)
+			rounding = 0;
 
 		ctx->config.baud_rate = config->baud_rate;
-		baud_div = (baud_base[dev_id] + (ctx->config.baud_rate >> 1)) /
-		    ctx->config.baud_rate;
+		baud_div = (baud_base[dev_id] + rounding) /
+			ctx->config.baud_rate;
 		rt_16550_reg_out(mode, base, LCR, LCR_DLAB);
 		rt_16550_reg_out(mode, base, DLL, baud_div & 0xff);
 		rt_16550_reg_out(mode, base, DLM, baud_div >> 8);
@@ -595,10 +605,10 @@ int rt_16550_ioctl(struct rtdm_dev_conte
 
 		if (testbits(config->config_mask, RTSER_SET_BAUD) &&
 		    (config->baud_rate >
-		     baud_base[context->device->device_id])) {
-			/* the baudrate is to high for this port */
+		     baud_base[context->device->device_id] ||
+		     config->baud_rate <= 0))
+			/* invalid baudrate for this port */
 			return -EINVAL;
-		}
 
 		if (testbits(config->config_mask,
 			     RTSER_SET_TIMESTAMP_HISTORY)) {
@@ -1164,7 +1174,8 @@ int __init rt_16550_init(void)
 			goto kfree_out;
 
 		if (baud_base[i] == 0)
-			baud_base[i] = DEFAULT_BAUD_BASE;
+			baud_base[i] = (variant[i] == VARIANT_MOXA) ?
+				DEFAULT_BAUD_BASE_MOXA : DEFAULT_BAUD_BASE;
 
 		if (tx_fifo[i] == 0)
 			tx_fifo[i] = DEFAULT_TX_FIFO;
#8 lore raw
Quoted 152 lines · Jan Kiszka
Quoted 52 lines · Jan Kiszka
Quoted 51 lines · CHABAL David

Le 11/5/2007, "Jan Kiszka" <[email protected]> a écrit:

Quoted 31 lines
Quoted 26 lines · Maksym Veremeyenko

CHABAL David �¿�¸Ñˆ�µÑ‚:

Quoted 6 lines

I met some trouble with the 16550A driver provided in Xenomai 2.3.1 and my Moxa cards (PCI / 8 * RS232 / 168U ).

It was a problem of baudrate computation before setting the LCR_DLAB register.

Quoted 7 lines

The formula implemented by the Xenomai driver is different from the one provided by Moxa. So I copy/paste the formula from the mxser.c file (present in the
kernel distro), and it seems to work fine.

I think it's Moxa card dependant, may be caused by the high default baud rate of this card.

I have two Moxa boards with no problem, possible you need to specify 'baud_base' param.

I my case :

# 8 ports board:
/sbin/modprobe xeno_16550A \
ioaddr=0x1000,0x1008,0x1010,0x1018,0x1020,0x1028,0x1030,0x1038 \
irq=9,9,9,9,9,9,9,9 \
baud_base=921600,921600,921600,921600,921600,921600,921600,921600

Quoted 4 lines

# 2 ports board + onboards:
/sbin/modprobe xeno_16550A ioaddr=0x3f8,0x2f8,0xdf00,0xdf08 irq=4,3,11,11 baud_base=115200,115200,921600,921600

Quoted 5 lines

Interesting. That would leave us just with the generic fix to catch baud_rate==0. Far more attractive. :)

David, can you confirm this? Weren't you just aware of the baud_base parameter?

I'm not totally convinced because if I compute by hand the DLAB register with the 19200 value (my config):

With the moxa driver:
baud_div = 912.600 / 19.200 = 47

With the Xeno driver:
baud_div = (912.600 - 9600) / 19.200 = 47

Grrr, it's ok here because the rounded values are the same because the baud base is biggest than the speed requested, but I think a problem can occur with 115200 or more, example:

Quoted 7 lines
Quoted 2 lines

moxa: 912.600/115.200 = 8
xeno: = 7

Yeah, hard arguments. This really cries for a moxa tweak. (The alternative would be to pass an artificially increased baud_base - but that would be _really_ ugly and we could also ask the user for the divider directly...)

Here we go. This patch should add the most essential changes of your patch to SVN trunk (backport not officially planned, but it should not be tricky). The idea is to pass "variant=1" to xeno_16550A on load. That will kick out rounding on divider calculation and even switches the default baud base.

Comments/test reports welcome.

Jan

Index: ksrc/drivers/serial/16550A.c
===================================================================

drivers/serial/16550A.c +6 -0
@@ -28,10 +28,14 @@
 
 #define MAX_DEVICES		8
 
+#define VARIANT_STANDARD	0
+#define VARIANT_MOXA		1
+
 #define IN_BUFFER_SIZE		4096
 #define OUT_BUFFER_SIZE		4096
 
 #define DEFAULT_BAUD_BASE	115200
+#define DEFAULT_BAUD_BASE_MOXA	921600
 #define DEFAULT_TX_FIFO		16
 
 #define PARITY_MASK		0x03
@@ -121,11 +125,13 @@ static struct rtdm_device *device[MAX_DE
 static unsigned int irq[MAX_DEVICES];
 static unsigned int baud_base[MAX_DEVICES];
 static int tx_fifo[MAX_DEVICES];
+static int variant[MAX_DEVICES];
 static unsigned int start_index;
 
 compat_module_param_array(irq, uint, MAX_DEVICES, 0400);
 compat_module_param_array(baud_base, uint, MAX_DEVICES, 0400);
 compat_module_param_array(tx_fifo, int, MAX_DEVICES, 0400);
+compat_module_param_array(variant, int, MAX_DEVICES, 0400);
 
 MODULE_PARM_DESC(irq, "IRQ numbers of the serial devices");

MODULE_PARM_DESC(baud_base, "Maximum baud rate of the serial device "

drivers/serial/16550A.c +13 -9
@@ -302,20 +308,24 @@ static int rt_16550_set_config(struct rt
 	rtdm_lockctx_t lock_ctx;
 	unsigned long base = ctx->base_addr;
 	int mode = rt_16550_io_mode_from_ctx(ctx);
-	int dev_id;
 	int err = 0;
-	int baud_div = 0;
 
 	/* make line configuration atomic and IRQ-safe */
 	rtdm_lock_get_irqsave(&ctx->lock, lock_ctx);
 
 	if (testbits(config->config_mask, RTSER_SET_BAUD)) {
-		dev_id = container_of(((void *)ctx), struct rtdm_dev_context,
-				      dev_private)->device->device_id;
+		int dev_id = container_of(((void *)ctx),
+					  struct rtdm_dev_context,
+					  dev_private)->device->device_id;
+		int rounding = ctx->config.baud_rate >> 1;
+		int baud_div = 0;
+
+		if (variant[dev_id] == VARIANT_MOXA)
+			rounding = 0;
 
 		ctx->config.baud_rate = config->baud_rate;
-		baud_div = (baud_base[dev_id] + (ctx->config.baud_rate >> 1)) /
-		    ctx->config.baud_rate;
+		baud_div = (baud_base[dev_id] + rounding) /
+			ctx->config.baud_rate;
 		rt_16550_reg_out(mode, base, LCR, LCR_DLAB);
 		rt_16550_reg_out(mode, base, DLL, baud_div & 0xff);
 		rt_16550_reg_out(mode, base, DLM, baud_div >> 8);
@@ -595,10 +605,10 @@ int rt_16550_ioctl(struct rtdm_dev_conte
 
 		if (testbits(config->config_mask, RTSER_SET_BAUD) &&
 		    (config->baud_rate >
-		     baud_base[context->device->device_id])) {
-			/* the baudrate is to high for this port */
+		     baud_base[context->device->device_id] ||
+		     config->baud_rate <= 0))
+			/* invalid baudrate for this port */
 			return -EINVAL;
-		}
 
 		if (testbits(config->config_mask,
 			     RTSER_SET_TIMESTAMP_HISTORY)) {

drivers/serial/16550A.c int __init rt_16550_init(void) · line 1181

Quoted 9 lines
drivers/serial/16550A.c +2 -1
@@ -1164,7 +1174,8 @@ int __init rt_16550_init(void)
 			goto kfree_out;
 
 		if (baud_base[i] == 0)
-			baud_base[i] = DEFAULT_BAUD_BASE;
+			baud_base[i] = (variant[i] == VARIANT_MOXA) ?
+				DEFAULT_BAUD_BASE_MOXA : DEFAULT_BAUD_BASE;
 
 		if (tx_fifo[i] == 0)
 			tx_fifo[i] = DEFAULT_TX_FIFO;

I think the DEFAULT_BAUD_BASE_MOXA constant shouldn't be added. May be other Moxa cards work slowly (or will be faster) and include this computation, I would keep this parameter free and ever modifiable by the boot line.

David

#9 lore raw
In reply to Jan Kiszka

Jan Kiszka пишет:

Quoted 7 lines
Quoted 2 lines

moxa: 912.600/115.200 = 8
xeno: = 7

Yeah, hard arguments. This really cries for a moxa tweak. (The alternative would be to pass an artificially increased baud_base - but that would be _really_ ugly and we could also ask the user for the divider directly...)

As i correctly understand mxser use formula:

      +-
      | base/baud, baud <> 134
div = |
      | 2*base/(2*base + 1), baud == 134
      +-

Jan's driver use:

div = (base + baud/2)/baud

What is actual

div = base/baud + 0.5

That seems more correct for rounding....

In additional:
1. You should use 921600 value instead of 912.600.
2. Interface is asynchronous and (IMHO) data could be transfered in a range of frequencies (BAUD +/- RANGE%)

Signature · 2 lines
________________________________________
Maksym Veremeyenko
#10 lore raw
Quoted 22 lines · Maksym Veremeyenko

Jan Kiszka пишет:

Quoted 7 lines
Quoted 2 lines

moxa: 912.600/115.200 = 8
xeno: = 7

Yeah, hard arguments. This really cries for a moxa tweak. (The alternative would be to pass an artificially increased baud_base - but that would be _really_ ugly and we could also ask the user for the divider directly...)

As i correctly understand mxser use formula:

      +-
      | base/baud, baud <> 134
div = |
      | 2*base/(2*base + 1), baud == 134
      +-

Jan's driver use:

div = (base + baud/2)/baud

What is actual

Quoted 7 lines

div = base/baud + 0.5

That seems more correct for rounding....

In additional:
1. You should use 921600 value instead of 912.600.

(921600 + (115200 div 2)) div 115200 = 8

So back to square #1: misconfiguration? David, please check with the correct baud base again if you still see relevant divider variations.

Quoted 3 lines

2. Interface is asynchronous and (IMHO) data could be transfered in a range of frequencies (BAUD +/- RANGE%)

Jan

#11 lore raw
Quoted 4 lines
Quoted 3 lines

In additional:
1. You should use 921600 value instead of 912.600.

The "." was here for reading facility only, I consider it as an integer in my computations.

Quoted 5 lines

(921600 + (115200 div 2)) div 115200 = 8

So back to square #1: misconfiguration? David, please check with the correct baud base again if you still see relevant divider variations.

moxa: 921600/115200 = 8 (not 7, I apologize for this mistake but we guess here that the baud base is always 921600 and according to the mxser file it can be 230400 for some cards)

xeno: (921600+57600)/115200 = 8.5 rounded to 8

David

#12 lore raw
Quoted 5 lines · CHABAL David
Quoted 2 lines
Quoted 2 lines

In additional:
1. You should use 921600 value instead of 912.600.

The "." was here for reading facility only, I consider it as an integer in my computations.

The point was not the point, but the flipped digits.

Quoted 10 lines
Quoted 6 lines

(921600 + (115200 div 2)) div 115200 = 8

So back to square #1: misconfiguration? David, please check with the correct baud base again if you still see relevant divider variations.

moxa: 921600/115200 = 8 (not 7, I apologize for this mistake but we guess here that the baud base is always 921600 and according to the mxser file it can be 230400 for some cards)

(230400+57600)/115200=2,5 => 2

230400/115200=2

???

Quoted 2 lines

xeno: (921600+57600)/115200 = 8.5 rounded to 8

So we have the same results for both formulas and I don't see the need for a patch anymore. Do you? Otherwise I would just commit the div-by-zero fix to trunk now and keep the rest as is.

Jan

#13 lore raw

Jan Kiszka пишет:

Quoted 3 lines

(230400+57600)/115200=2,5 => 2

230400/115200=2

IMHO - even if result was '3' - i would suggest to use formula that gives '3' because it's more correct.

Quoted 3 lines

So we have the same results for both formulas and I don't see the need for a patch anymore. Do you? Otherwise I would just commit the div-by-zero fix to trunk now and keep the rest as is.

i think 'div-by-zero fix' is enough.

Signature · 2 lines
________________________________________
Maksym Veremeyenko
#14 lore raw
In reply to Jan Kiszka
Quoted 20 lines · Jan Kiszka
Quoted 5 lines · CHABAL David
Quoted 2 lines
Quoted 2 lines

In additional:
1. You should use 921600 value instead of 912.600.

The "." was here for reading facility only, I consider it as an integer in my computations.

The point was not the point, but the flipped digits.

Quoted 10 lines
Quoted 6 lines

(921600 + (115200 div 2)) div 115200 = 8

So back to square #1: misconfiguration? David, please check with the correct baud base again if you still see relevant divider variations.

moxa: 921600/115200 = 8 (not 7, I apologize for this mistake but we guess here that the baud base is always 921600 and according to the mxser file it can be 230400 for some cards)

Quoted 5 lines

(230400+57600)/115200=2,5 => 2

230400/115200=2

???

Oupsss, I'm beaten :-(

The only case with a different value that I found is for 1200:
(230400+1200)/1200 = 193
230400/1200 = 192

I think it's not relevant for this speed.

David

Quoted 10 lines
Quoted 3 lines

xeno: (921600+57600)/115200 = 8.5 rounded to 8

So we have the same results for both formulas and I don't see the need for a patch anymore. Do you? Otherwise I would just commit the div-by-zero fix to trunk now and keep the rest as is.

Jan

#15 lore raw
Quoted 23 lines · CHABAL David
Quoted 12 lines · Jan Kiszka
Quoted 4 lines · CHABAL David
Quoted 2 lines
Quoted 2 lines

In additional:
1. You should use 921600 value instead of 912.600.

The "." was here for reading facility only, I consider it as an integer in my computations.

The point was not the point, but the flipped digits.

Quoted 5 lines
Quoted 5 lines

(921600 + (115200 div 2)) div 115200 = 8

So back to square #1: misconfiguration? David, please check with the correct baud base again if you still see relevant divider variations.

Quoted 8 lines
Quoted 3 lines

moxa: 921600/115200 = 8 (not 7, I apologize for this mistake but we guess here that the baud base is always 921600 and according to the mxser file it can be 230400 for some cards)

(230400+57600)/115200=2,5 => 2

230400/115200=2

???

Quoted 8 lines

Oupsss, I'm beaten :-(

The only case with a different value that I found is for 1200:
(230400+1200)/1200 = 193
230400/1200 = 192

I think it's not relevant for this speed.

Fine - issue solved without adding tweaks, and everybody is happy. :)

Jan

#16 lore raw
In reply to CHABAL David

CHABAL David пишет:

Quoted 6 lines

Oupsss, I'm beaten :-(

The only case with a different value that I found is for 1200:

(230400+1200)/1200 = 193
230400/1200 = 192

(230400+600)/1200 = [192,5] = 192
230400/1200 = 192

Signature · 2 lines
________________________________________
Maksym Veremeyenko
#17 lore raw
Quoted 16 lines · Maksym Veremeyenko

CHABAL David ÐÉÛÅÔ:

Quoted 6 lines

Oupsss, I'm beaten :-(

The only case with a different value that I found is for 1200:

(230400+1200)/1200 = 193
230400/1200 = 192

(230400+600)/1200 = [192,5] = 192
230400/1200 = 192

Signature · 2 lines
________________________________________
Maksym Veremeyenko

argh, beaten ... again

Sorry for this useless thread.

David

#18 lore raw
Quoted 12 lines · CHABAL David
Quoted 10 lines · Maksym Veremeyenko

CHABAL David ÐÉÛÅÔ:

Quoted 5 lines

Oupsss, I'm beaten :-(

The only case with a different value that I found is for 1200:
(230400+1200)/1200 = 193
230400/1200 = 192

(230400+600)/1200 = [192,5] = 192
230400/1200 = 192

Quoted 8 lines
Quoted 4 lines
Signature · 2 lines
________________________________________
Maksym Veremeyenko

argh, beaten ... again

Sorry for this useless thread.

I wouldn't call it useless: Try to ask $your_favourite_search_engine for "xenomai 16550 moxa" in a few days, and you'll find some more hints on how to configure that hardware and that it works (once worked) for Xenomai.

However, the Maksym's suggestion to enhance the wiki is welcome. Anyone, please check the existing page http://www.xenomai.org/index.php/16550A
and add what you think is missing or fix what is unclear.

Jan

#19 lore raw
In reply to CHABAL David

CHABAL David пишет:

Quoted 3 lines

moxa: 921600/115200 = 8 (not 7, I apologize for this mistake but we guess here that the baud base is always 921600 and according to the mxser file it can be 230400 for some cards)

Then for 'some cards' it's possible to specify 'baud_base' parameter.

What can i suggest/recommend is add to Xenomai wiki some information about using xeno_16550A with some boards (also may be reasonable to add information for proper 'ioaddr' findings for multiports board).

Signature · 2 lines
________________________________________
Maksym Veremeyenko