This file contains the functions to manipulate every connected elomax unit from user space. More...
Classes | |
struct | elomax_instance |
Maintains the status of the elomax unit it represents. More... | |
Functions | |
static void | elomax_instance_read_complete (struct urb *urb) |
When the instance's read urb is finished, this function saves the received data and resubmits the read urb for the next incoming data. | |
static void | elomax_instance_write_complete (struct urb *urb) |
When this instance's write urb is finished, this function releases the instance's lock (semaphore) to allow the next writer. | |
static ssize_t | elomax_instance_read (struct file *file, char *buffer, size_t count, loff_t *ppos) |
Deliver data from the device to the user. | |
static ssize_t | elomax_instance_write (struct file *file, const char *buffer, size_t count, loff_t *ppos) |
Deliver data from the user to the device. | |
static int | elomax_instance_open (struct inode *inode, struct file *file) |
Open the device file, so that the user can read/write to the device. | |
static int | elomax_instance_close (struct inode *inode, struct file *file) |
Close the given file, so that the user no longer can read or write to it. |
This file contains the functions to manipulate every connected elomax unit from user space.
The functions elomax_instance_read_complete() and elomax_instance_write_complete() are 'internal' functions to the instance. They are called by the usb-core when an urb read resp. write is complete. The other functions in this file are called when an user application manipulates the connected elomax unit via its device file. The user can open, read, write and close the device file.
When the user does so, the kernel calls elomax_instance_open(), elomax_instance_read(), elomax_instance_write() respectively elomax_instance_close(). The kernel knows to call these functions, because they are pointed to by the 'file operation table', which via the 'class driver table' was made known to the usb-core, when the unit was connected to the usb-bus (and the 'class driver table' announced via elomax_instance_construct()).
static int elomax_instance_close | ( | struct inode * | inode, | |
struct file * | file | |||
) | [static] |
Close the given file, so that the user no longer can read or write to it.
This function clears the file's private_data (filled by elomax_instance_open()) and decrements the usage count (smartptr, reference counter) and possibly destroys the instance.
[in] | inode | The inode of the device file to be closed. |
[in] | file | The device file to be closed. |
static int elomax_instance_open | ( | struct inode * | inode, | |
struct file * | file | |||
) | [static] |
Open the device file, so that the user can read/write to the device.
With the minor stored in the inode, this function retrieves the usb interface coupled to this device file. This interface is then asked for its instance, its attachment (via elomax_driver_instance_from_minor()).
When found, this instance is coupled to the file (by storing it in the file's private_data), so that following reads and writes can find the instance. Also the smartptr reference counter is incremented.
[in] | inode | The inode of the file requested for opening (the device file). |
[in] | file | The file requested for opening (the device file). |
static ssize_t elomax_instance_read | ( | struct file * | file, | |
char * | buffer, | |||
size_t | count, | |||
loff_t * | ppos | |||
) | [static] |
Deliver data from the device to the user.
This read function only wants to deliver certain amounts (and therefore types) of data. These data formats are described in elomax.h.
When the user requested a valid amount (type) of data, this function checks if no destruct announcement has been made.
With all checks ok, it copies the data, gathered by the elomax_instance_read_complete() (and elomax_instance_write_complete()) functions to the user.
[in] | file | The file from which the user wants to read. This file 'points' to our device file. |
[in] | buffer | The buffer in which the user wants to receive the data. This buffer is in user-space, not in kernel-space. |
[in] | count | The count of databytes the user wants to receive. This count is used to differentiate between the 'types of data' this driver can deliver. |
[in] | ppos | The position at which the user wants to start the read. This parameter is ignored in this package. |
static void elomax_instance_read_complete | ( | struct urb * | urb | ) | [static] |
When the instance's read urb is finished, this function saves the received data and resubmits the read urb for the next incoming data.
The read urb is marked with this function as completion function, therefore this function is called by the usb-core when the read finishes. This function retrieves the instance from the urb's context, checks the urb's status (the succesfullness of the read) and then stores the received data in the instance.
The last action of this function is to submit this read urb again to the usb-core (via usb_submit_urb), so that this package is continously prepared for receiving the latest data of the unit.
[in] | urb | The urb which is just finished. This urb is marked with this function as completion-function, hence this function is called. The urb contains the instance for which it did the write in its context (placed there upon submission of the urb). |
static ssize_t elomax_instance_write | ( | struct file * | file, | |
const char * | buffer, | |||
size_t | count, | |||
loff_t * | ppos | |||
) | [static] |
Deliver data from the user to the device.
This write function only accepts one 'data format'. This data format for each type of 'solution' is described in elomax.h.
When the user requested the right amount of data to be written, this function requests the instance for permission to write, by down() the instance's write_semaphore. This may put the calling thread to sleep.
With permission granted, it checks that the instance is not announced for destruction, fills the write-urb with the user's data and sends it to the unit (via the usb-core's usb_submit_urb()).
The semaphore is kept until the usb-core calls the elomax_instance_write_complete(). That function releases (up()) the semaphore (this may wakeup a waiting thread).
[in] | file | The file to which the user wants to write, it points to our device file. |
[in] | buffer | The data the user wants to write. |
[in] | count | The amount of databytes the user wants to write. This parameter is used to check the 'data type' for the write. |
[in] | ppos | The position at which the user wants to write the data. This parameter is ignored by this package. |
static void elomax_instance_write_complete | ( | struct urb * | urb | ) | [static] |
When this instance's write urb is finished, this function releases the instance's lock (semaphore) to allow the next writer.
The instance is retrieved from the urb's context, after which this function the status of the urb (succesfullness of the write) checks. It then releases (up() of the instance's elomax_instance::write_semaphore) to allow the next writer.
[in] | urb | The urb which is just finished. This urb is marked with this function as completion-function, hence this function is called. The urb contains the instance for which it did the write in its context (placed there upon submission of the urb). |