IRC log for #elinux on 20090422

00:00.24chrisf_trying to do in-kernel rs485 support for a 16550A-compatible uart on a pxa270... any hints? has this been done before? is this a stupid idea? etc
00:01.06chrisf_i have an existing driver hack that exposes the uart state to userspace via /proc, but that's crap because you have to poll it
00:02.18roxfanwell, i would guess you'll need to either modify an existing (rs232?) driver or port one from another system
00:02.21MonMothachrisf_: what I've seen done usually is just a compile time option in the BSP definitions to dump a UART into the built in RS-485 mode
00:02.34MonMothaif the UART doesn't have a built-in RS-485 mode, just create something to manage it and again add BSP definitions
00:03.08MonMothain most cases, the board itself defines the medium type (RS-232 with or without handshaking, bare TTL, RS-422, RS-485, IrDA, etc.), so no need to make things like that userspace configurable
00:04.06chrisf_if i pastebin the hacked source for this driver, can you have a look and tell me whether that's doable?
00:04.53chrisf_$(KERNEL_SOURCE)/drivers/serial/pxa.c: http://pastebin.com/m3435e44b
00:05.24chrisf_you can clearly see the /proc hack there at the end - subtly broken as it is.
00:06.02chrisf_afaik, "rs485 mode" on these things is auto-toggling rts.
00:06.09chrisf_all i want to do is:
00:06.40chrisf_- just before tx start, assert RTS     - asap after tx end, deassert RTS
00:08.04chrisf_ive got the 16550 docs - it looks like MCR[RTS] controls the line, im just not sure where to put the code.
00:09.16chrisf_no doubt there's also some settle time requirements, on the order of a few microseconds, which i assume can be dealt with via udelay() or whatever
00:10.22roxfanit seems it has auto-flow which might handle rts and cts itself
00:11.16roxfanAuto-flow mode can be used in two ways: full auto-flow, automating both nCTS and nRTS; and
00:11.16roxfanhalf auto-flow, automating only nCTS. To enable full auto-flow, set bits MCR[1] and MCR[5]. To
00:11.16roxfanenable auto-nCTS-only mode, set MCR[5] and clear MCR[1].
00:11.16roxfanhm, "Auto-flow mode can be used only in conjunction with FIFO mode."
00:11.23roxfanmaybe not your case then
00:32.06roxfankilled the chat >.>
01:03.29chrisf_i dont want autoflow
01:03.54chrisf_i want to use the RTS to attach my transmitter to the rs485 bus
01:04.37chrisf_this is the same as the NT serial driver's RTS_CONTROL_TOGGLE mode
01:31.34*** join/#elinux thraxisp (n=thraxisp@24.139.16.154)
01:40.03*** join/#elinux SarahEmm (n=SarahEmm@meowcat.net)
02:08.51chrisf_roxfan: you still there?
02:09.08*** join/#elinux thraxisp1 (n=Adium@24.139.16.154)
02:22.52MonMothachrisf_: I don't see how this isn't doable.  Many SoC's already have an auto-485 mode, though.
02:23.23chrisf_ill pastebin my patch; tell me if im doing something really dumb
02:24.16chrisf_http://pastebin.com/m5c006f9e
02:24.31chrisf_ive not hacked the kernel before, so i may be doing something stupid.
02:25.26MonMothacan you just pastebin the whole file, rather than the diff?
02:25.44MonMothaI don't have enough context in that to figure out where you are since I'm not familiar with the PXA drivers.
02:26.29MonMothaI don't see any no-nos as long as that's all in user context.  Calling udelay from interrupt context is frowned upon (though it shouldn't deadlock or anything)
02:28.42chrisf_the original source is here: http://pastebin.com/m3435e44b
02:40.51chrisf_here's the patched sources http://pastebin.com/m48065bce
02:45.21MonMothachrisf_: looks like the routines you are patching are called from an interrupt handler.  You can use udelay in an interrupt handler, but it's frowned upon.  Be sure to keep the delays *REALLY* short.
02:45.42MonMothacalling udelay in an interrupt handler causes the CPU to just sit there doing absolutely NOTHING (not even servicing other interrupts)
02:45.57chrisf_i got that.
02:46.04MonMothathat said, build it and see if it works :)
02:46.12chrisf_i assume it does what i think it does - wait for N us?
02:46.23MonMothayup
02:46.27MonMothait's a busy wait
02:46.34MonMothai.e. it just sits there burning time in a calibrated loop
02:47.00chrisf_ok, cool.
02:47.01MonMothain an interrupt, that'll get you an exact wait (which could be what you need for your "line release" timing), but the CPU also isn't able to do ANYTHING else, so you have to keep them brief
02:47.30chrisf_it should just be a few us.
02:48.22chrisf_my rs485 transceiver is meant to be up & stable in <100ns.. add line impedance and its a bit more, but not much.
02:48.41MonMothathat should be OK
02:48.43chrisf_and awesomely, that code doesnt build, because i screwed up :)
02:48.51MonMothaanything more than about 100us tends to cause problems with interactivity
02:49.06chrisf_im a bit worried about the tx stop
02:49.12chrisf_since there's a fifo.
02:49.45chrisf_and that's potentially going to sit there from the last fill point until the uart is empty
02:49.54MonMothaum, that's very bad
02:50.04MonMothadon't you get a "TX FIFO empty" interrupt?
02:50.10chrisf_at halfway.
02:50.16MonMothaor, even better, a "transmit complete" interrupt
02:52.05chrisf_i havent found anything :( it's a pxa's 16550-compat BTUART
02:53.48MonMothalooks like a 16550 should have a "transmit holding register empty" interrupt.  You should get that right as the last character from the FIFO starts to be transmitted
02:54.25chrisf_ok, in response to that, transmit_chars() gets called.
02:55.52MonMothainteresting...that's not how I would have written the driver, but OK
02:56.09MonMothaunfortunately, it looks like if you want to avoid a busy wait of at least one character time, you'll need a timer
02:57.01MonMothagrab the "I'm on the last character in the FIFO" condition, set a timer for slightly less than one character length, let the timer interrupt handler busy wait out the remainder of the time (possibly polling the UART to see if it's done, if possible), then release the transceiver
02:57.07MonMothaugly, but 16550 UARTs aren't exactly modern
02:58.49chrisf_they are fairly well understood, though.
02:59.07chrisf_i guess id rather have a 16550 than some random thing
02:59.47MonMothaeh, UART drivers aren't exactly common
02:59.55MonMothaand most Linux-supported SoCs already have drivers for them
03:00.11MonMothaand most of them support some form of auto-485 operation in hardware (even if the Linux driver doesn't)
03:03.28chrisf_well apparently this doesnt :(
03:03.46chrisf_win, kernel builds now.
03:03.56chrisf_always a good start :)
03:38.34chrisf_MonMotha: how to print a debug message to the console from the kernel?
03:39.35MonMothakprintf(...)
03:39.46MonMothayou'll need to spec a loglevel for the print
03:40.40chrisf_ok, whats a good default?
03:40.58MonMothawell, it depends on what you're logging
03:41.28MonMothaif you're logging "I'm dead" conditions, critical is good, but if it's register dumps, debug might be better
03:42.19chrisf_its just debug stuff.
03:42.44MonMothaKERN_DEBUG would be appropriate, then
03:43.17chrisf_where do i find the docs for this?
03:43.42chrisf_google is sucking
03:44.30MonMothagoogle the "lxr"
03:44.41MonMothait's a big cross-reference thing automatically generated on the kernel source
03:44.46MonMothavery handy
03:57.03chrisf_cool.
04:01.04chrisf_ok, it sortof works
04:01.29chrisf_ended up just using printk
04:02.15chrisf_here's my current source: http://pastebin.com/m4cc98796
04:03.46chrisf_it stops after printing *rs485 start*.
04:04.51chrisf_for example,
04:05.42chrisf_$ echo "hello" > /dev/ttyS1
04:05.44chrisf_*rs485 start*
04:05.45chrisf_^C
04:05.47chrisf_*rs485 end*
04:05.48chrisf_*rs485 idle*
04:07.04chrisf_confirmed that this is caused by my code. prehack kernel works correctly (but no 485, obviously)
04:11.34MonMothasounds like you've got a deadlock
04:11.34MonMothaand yeah, it's printk, not kprintf
04:11.34MonMothabeen a while since I was in the kernel
04:15.05chrisf_kernel deadlocks dont take out the machine? nice.
04:15.12chrisf_(i can recover with ^C)
04:21.04chrisf_so why is that deadlocking?
04:22.18chrisf_i know its not the printk
05:17.01chrisf_MonMotha: if you're still there; the source of the problem was NOT a deadlock.
05:17.24chrisf_but stale bits in register image.
05:17.53chrisf_doing up->mcr = serial_in( up, UART_MCR ) before trying to turn on rts makes it work.
05:50.19*** join/#elinux pleemans (n=toi@d54C2AAB7.access.telenet.be)
06:06.18*** join/#elinux tsjsieb (n=tsjsieb@dejongbeheer.nl)
06:11.42*** join/#elinux lyakh (n=lyakh@p57BD1C08.dip0.t-ipconnect.de)
06:16.23*** join/#elinux hw__ (n=hw@87.139.57.5)
06:40.51*** join/#elinux harpal (n=Harpal@121.246.75.165)
06:47.48*** join/#elinux pytey (n=pytey@84.233.192.144)
06:58.01methril|workyo
08:35.12*** join/#elinux Madsy (n=madsy@ti0207a340-0714.bb.online.no)
10:16.40*** join/#elinux ibot (i=ibot@rikers.org)
10:16.40*** topic/#elinux is Embedded Linux || http://eLinux.org/ || cross compile, uClibc, busybox, handhelds, post-sale linux installs ;-), etc.
10:16.40*** mode/#elinux [+o ibot] by ChanServ
10:57.47*** join/#elinux pirho (i=pirho@gateway/gpg-tor/key-0x2CEEC9CB)
11:25.26*** join/#elinux tsjsieb (n=tsjsieb@dejongbeheer.nl)
12:11.07*** join/#elinux gustavoz (n=gustavoz@imhotep.toptech.com.ar)
12:50.03*** join/#elinux GPSFan (n=kenm@64.92.145.112)
13:44.32*** join/#elinux Dr_Who (n=tgall@gentoo/developer/dr-who)
14:42.29*** join/#elinux Othello (i=Othello@gateway/tor/x-3388951554aebbf9)
15:05.30*** join/#elinux TimRiker (i=timr@2002:ad75:2a64:0:0:0:0:1)
15:05.30*** mode/#elinux [+o TimRiker] by ChanServ
15:15.34*** join/#elinux thraxisp (n=thraxisp@century.precidia.com)
15:16.02*** join/#elinux thraxisp_ (n=thraxisp@century.precidia.com)
15:49.59*** join/#elinux Dr_Who (n=tgall@gentoo/developer/dr-who)
16:28.54*** join/#elinux Dr_Who (n=tgall@gentoo/developer/dr-who)
16:29.35*** join/#elinux linac (n=lin@123.249.160.78)
16:49.42*** join/#elinux pcgeil (n=steffen@p5B17F9E1.dip.t-dialin.net)
17:37.39*** join/#elinux pirho (i=pirho@gateway/gpg-tor/key-0x2CEEC9CB)
17:54.14*** join/#elinux albech_ (n=albech@119.42.76.2)
18:40.23*** join/#elinux markl (n=mark@tpsit.com)
19:21.43*** join/#elinux roxfan (n=dunno@165.44-244-81.adsl-dyn.isp.belgacom.be)
21:14.16*** join/#elinux flavioribeiro (n=avaty@189.71.70.187)
21:35.53chrisf_anyone who may have been listening to the rs485 stuff yesterday, here's a patch which works (not mine!) http://markmail.org/message/uyw4hqsipap5z4il
21:41.56*** join/#elinux CIA-53 (n=CIA@208.69.182.149.simpli.biz)
21:42.30*** join/#elinux gandhijee (i=akp@host-66-202-34-165.spr.choiceone.net)
22:14.15*** join/#elinux likewise (n=chatzill@82-171-51-231.ip.telfort.nl)
22:27.45*** join/#elinux jlg (n=jlg@lit75-2-87-91-59-235.dsl.club-internet.fr)
22:45.21*** join/#elinux jlg_ (n=jlg@lit75-2-87-91-59-235.dsl.club-internet.fr)
23:08.43*** join/#elinux thraxisp (n=thraxisp@24.139.16.154)
23:16.11*** join/#elinux SarahEmm (n=SarahEmm@meowcat.net)

Generated by irclog2html.pl Modified by Tim Riker to work with infobot.