Building a software serial driver
Greetings fellow newbies.
I'm toying around with a Raspberry PI and trying to create a driver that takes a single GPIO pin and turns it into a read-only TTY device because using the userspace GPIO sysfs API is too slow for me.
Here's my current code:
https://github.com/tdfischer/gpio_serial
It is based off of the tiny_serial example driver in the LDD3 repo:
https://github.com/martinezjavier/ldd3/blob/master/tty/tiny_serial.c
It builds and loads just fine, and even creates a /dev/ttyGPIO0 device. However, reading from it returns -EIO. Running strace on cat shows that it opens up the device successfully, but fails on the first call to read().
Any idea what I'm missing here? I'm fairly certain it is something obvious. -------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20140623/f42481d0/attachment.bin
Hi Torrie
Quoted 6 lines · Torrie Fischer
Greetings fellow newbies.
I'm toying around with a Raspberry PI and trying to create a driver that takes a single GPIO pin and turns it into a read-only TTY device because using the userspace GPIO sysfs API is too slow for me.
Quoted 8 lines
Here's my current code:
https://github.com/tdfischer/gpio_serial
It is based off of the
tiny_serialexample driver in the LDD3 repo:https://github.com/martinezjavier/ldd3/blob/master/tty/tiny_serial.c
I looked at uart_register code, it seems there's no read callback so that's why you are getting that -EIO.
I don't think you've to change a lot of code but I looked up and found
tty_flip_buffer_push
For the above you can get the tty from the uart_driver->tty_driver. It uses the tty_port as an argument which you can get with your line as index into the uart_driver->tty_driver->ports[line_number].
Your data would be going into a circular buffer for this uart so I think all you need to do is push this. See the uart_ops structure you can see there which ones are being called.
The buffer you would be writing to seems to be a page and is circular buffer. So you'll need to check when you are about to write the last byte then you'll need to flush it. You just need to provide the flushing part in start_xmit since that is taken care of by uart_write as I see.
I think you can put this call in your start_tx since uart_start is calling port->start_tx at the end so i guess you should be good there.
I don't have much idea how will you read from it though.
Quoted 10 lines
It builds and loads just fine, and even creates a
/dev/ttyGPIO0device. However, reading from it returns-EIO. Running strace on cat shows that it opens up the device successfully, but fails on the first call toread().Any idea what I'm missing here? I'm fairly certain it is something obvious.
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies at kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Signature · 1 line
---P.K.S
Hi, Pranay.
Thanks for having a look.
Quoted 5 lines · On Tuesday, June 24, 2014 13:42:35 Pranay Srivastava wrote:
I looked at
uart_registercode, it seems there's no read callback so that's why you are getting that-EIO.From what I understand, I'm supposed to set up the interrupts needed in the
startup function which is called when the device is opened. This never happens though, as adding a printk results in no output.
Quoted 2 lines
I think you can put this call in your
start_txsinceuart_startis callingport->start_txat the end so i guess you should be good there.
I suspect that start_tx is not getting called since adding a printk in my start_tx function doesn't result in any output.
Quoted 2 lines
I don't have much idea how will you read from it though.
I'm able to read from it by waiting for a rising edge interrupt and then bit-
banging the GPIO line in userspace, though at a slow baud that is unusable. I
need 9600 to read from my device :)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20140624/8352ed4f/attachment.bin
Hi Torrie,
Quoted 4 lines · Torrie Fischer
Hi, Pranay.
Thanks for having a look.
Quoted 8 lines
Quoted 3 lines · On Tuesday, June 24, 2014 13:42:35 Pranay Srivastava wrote:
I looked at
uart_registercode, it seems there's no read callback so that's why you are getting that-EIO.From what I understand, I'm supposed to set up the interrupts needed in the startup function which is called when the device is opened. This never happens though, as adding a printk results in no output.
I think this might be causing it, if you see tty_open then it has a call to ,
tty_open_current_tty , this seems to be the only one which I think is not making the driver being looked up and hence no uport->open
so in case there's an already a tty attached to current then i think it isn't opening
a new one. Maybe you need to detach this tty? Not so sure I'll look again what can be done.
Quoted 8 lines
Quoted 3 lines
I think you can put this call in your
start_txsinceuart_startis callingport->start_txat the end so i guess you should be good there.I suspect that
start_txis not getting called since adding a printk in mystart_txfunction doesn't result in any output.Quoted 1 line
Quoted 5 lines
Quoted 1 line
I don't have much idea how will you read from it though.
I'm able to read from it by waiting for a rising edge interrupt and then bit- banging the GPIO line in userspace, though at a slow baud that is unusable. I need 9600 to read from my device :)
Ok good!. I don't have much idea about GPIO. While searching I found there's a GPIO library for Raspi. I don't know how much help that would be but i
guess you don't want to use it.
Signature · 1 line
---P.K.S
Apparently all I had to do was set the type attribute on the uart_port structure to anything that isn't PORT_UNKNOWN.
Here's a functional driver that takes a GPIO pin and creates a read-only serial TTY:
https://github.com/tdfischer/gpio_serial/blob/master/gpiotty.c
:)
Quoted 37 lines · On Tuesday, June 24, 2014 21:27:46 Pranay Srivastava wrote:
Hi Torrie,
On Tue, Jun 24, 2014 at 6:26 PM, Torrie Fischer
Quoted 4 lines · <[email protected]> wrote:
Hi, Pranay.
Thanks for having a look.
Quoted 8 lines
Quoted 2 lines · On Tuesday, June 24, 2014 13:42:35 Pranay Srivastava wrote:
I looked at
uart_registercode, it seems there's no read callback so that's why you are getting that-EIO.From what I understand, I'm supposed to set up the interrupts needed in the
startup function which is called when the device is opened. This never happens though, as adding a printk results in no output.I think this might be causing it, if you see
tty_openthen it has a call to ,
tty_open_current_tty, this seems to be the only one which I think is not making the driver being looked up and hence nouport->openso in case there's an already a tty attached to current then i think it isn't opening
a new one. Maybe you need to detach this tty? Not so sure I'll look again what can be done.Quoted 8 lines
Quoted 2 lines
I think you can put this call in your
start_txsinceuart_startis callingport->start_txat the end so i guess you should be good there.I suspect that
start_txis not getting called since adding a printk in mystart_txfunction doesn't result in any output.Quoted 1 line
I don't have much idea how will you read from it though.
Quoted 8 lines
Quoted 3 lines
I'm able to read from it by waiting for a rising edge interrupt and then bit- banging the GPIO line in userspace, though at a slow baud that is unusable. I need 9600 to read from my device :)
Ok good!. I don't have much idea about GPIO. While searching I found there's a GPIO library for Raspi. I don't know how much help that would be but i
guess you don't want to use it.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20140624/855dadf3/attachment.bin
Quoted 3 lines · Torrie Fischer
Apparently all I had to do was set the type attribute on the
uart_portstructure to anything that isn'tPORT_UNKNOWN.
Arhh.. I see. I overlooked that since tty->type was being set. Good to know you got it working.
Quoted 2 lines
Here's a functional driver that takes a GPIO pin and creates a read-only serial TTY:
So multiple open don't harm? The startup routine is called only once is that right?
Quoted 51 lines
https://github.com/tdfischer/gpio_serial/blob/master/gpiotty.c
:)
Quoted 45 lines · On Tuesday, June 24, 2014 21:27:46 Pranay Srivastava wrote:
Hi Torrie,
On Tue, Jun 24, 2014 at 6:26 PM, Torrie Fischer
Quoted 4 lines · <[email protected]> wrote:
Hi, Pranay.
Thanks for having a look.
Quoted 8 lines
Quoted 2 lines · On Tuesday, June 24, 2014 13:42:35 Pranay Srivastava wrote:
I looked at
uart_registercode, it seems there's no read callback so that's why you are getting that-EIO.From what I understand, I'm supposed to set up the interrupts needed in the
startup function which is called when the device is opened. This never happens though, as adding a printk results in no output.I think this might be causing it, if you see
tty_openthen it has a call to ,
tty_open_current_tty, this seems to be the only one which I think is not making the driver being looked up and hence nouport->openso in case there's an already a tty attached to current then i think it isn't opening
a new one. Maybe you need to detach this tty? Not so sure I'll look again what can be done.Quoted 11 lines
Quoted 2 lines
I think you can put this call in your
start_txsinceuart_startis callingport->start_txat the end so i guess you should be good there.I suspect that
start_txis not getting called since adding a printk in mystart_txfunction doesn't result in any output.Quoted 1 line
I don't have much idea how will you read from it though.
I'm able to read from it by waiting for a rising edge interrupt and then bit- banging the GPIO line in userspace, though at a slow baud that is unusable. I need 9600 to read from my device :)
Ok good!. I don't have much idea about GPIO. While searching I found there's a GPIO library for Raspi. I don't know how much help that would be but i
guess you don't want to use it.
Signature · 1 line
---P.K.S