Questions about writing a device driver
Ian Caddy
ianc at goanna.iinet.net.au
Tue Mar 22 03:14:13 UTC 2005
Hi Simon,
(Changed email address, second attempt)
Simon Clubley wrote:
> I am looking at writing a device driver and would like to check
> several things before I start. The device driver will be a character
> style (but NOT tty) driver talking to a PCI controller and will have
> outstanding requests from several tasks at the same time.
>
> [BTW, are people aware that the mail list search function does not
> appear to be working ? You end up getting an empty screen regardless
> of the search query]
>
>
>
> 1) What is the preferred method for drivers to stall the caller
> while waiting for the ISR to trigger on I/O completion ?
>
> It appears to be a choice between waiting on an event or waiting on
> a semaphore. (Does the semaphore have a potential race problem with
> the ISR firing between the I/O been issued and the caller stalling
> on the semaphore ?)
>
This is a difficult one as it depends on how your ISR is triggered.
We use a binary semaphore for holding up tasks waiting on ISRs, but
normally have the task create and obtain the semaphore, start the
process for the ISR and then get the task to try to obtain the semaphore
again, with or without timeout. On completion of the ISR, it will
release the semaphore, allowing the task to grab it again.
We also use the message queue mechanism it the ISR is producing data,
the task will wait on the message queue (for ever or timeout, depending)
while the ISR on completion will send a message to the queue.
> 2) Does the rtems_device_driver_entry (ie read_entry) execute within
> the context of the calling task so that the driver can stall two
> seperate tasks with overlapping I/O requests by using the same event
> number ?
Yes, the the reads and the writes execute within the context of the
calling task, so you can do what you are proposing.
> 3) If you use mknod to create a device node /dev/simon with the
> major number of the device driver, can you access the device using
> the C open/close/read/write RTL calls, or do you have to use
> rtems_io_read and friends ?
>
We use the rtems call for naming device drivers: rtems_io_register_name
After this time, you can access the device using the C
open/close/read/write, etc calls with no problems.
I hope this helps.
regards,
Ian Caddy
More information about the users
mailing list