![]() |
| | #1 |
| Registered User Join Date: Sep 2009 Location: Zagreb, Croatia
Posts: 179
| |
| yann is offline | |
| | #2 |
| subminimalist Join Date: Jul 2008 Location: NYC
Posts: 3,944
| Pretty sure you will have to write a kernel module. Have a look at this thread from today: About Device Driver Programming And Socket Programming And maybe you will find this interesting: Writing a Simple USB Driver I do remember getting slightly peeved about that last one since there is some crucial information absent from it* which you will realize after being frustrated by it (the nastiest kind of hole you can leave in a demo, I know!), but it does provide a nice clear acurate (IMO) perspective. * even worse I can't remember what it was and am doing totally unrelated things right now, so don't have the headspace to figure it out...sorry
__________________ Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS Last edited by MK27; 09-01-2009 at 04:34 PM. |
| MK27 is offline | |
| | #3 |
| Confused Join Date: Sep 2001 Location: Sweden
Posts: 3,122
| Technically USB is not a port, it's a bus.
__________________ MagosX.com Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime. |
| Magos is offline | |
| | #4 |
| Rampaging 35 Stone Welsh Join Date: Apr 2007
Posts: 2,924
| Internally its a bus, externally it has a port, electronically its accessed through a logical port.
__________________ He is free, you say. Ah! That is his misfortune… These men… [have] the most terrible, the most imperious of masters, that is, need. … They must therefore find someone to hire them, or die of hunger. Is that to be free? - Simon Linguet |
| abachler is offline | |
| | #5 | |
| Registered User Join Date: Sep 2009 Location: Zagreb, Croatia
Posts: 179
| Quote:
Code: static struct usb_driver led_driver = {
.owner = THIS_MODULE,
.name = "usbled",
.probe = led_probe,
.disconnect = led_disconnect,
.id_table = id_table,
};
and others
| |
| yann is offline | |
| | #6 |
| subminimalist Join Date: Jul 2008 Location: NYC
Posts: 3,944
| No, it is a C structure assignment. (You will need to read up about structs in C if you do not know what they are). struct usb_driver is defined somewhere else (in one of the kernel headers). led_driver is a struct usb_driver. Here's a parallel example: Code: #include <stdio.h>
struct form { /* struct form definition */
const char *name;
};
int main() {
struct form eg = { /* struct form eg declaration and assignment */
.name = "hello world",
};
printf("%s\n",eg.name);
return 0;
}
__________________ Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS |
| MK27 is offline | |
| | #7 | |
| Registered User Join Date: Sep 2009 Location: Zagreb, Croatia
Posts: 179
| Thanks Quote:
| |
| yann is offline | |
| | #8 | |
| subminimalist Join Date: Jul 2008 Location: NYC
Posts: 3,944
| Quote:
That's all one C program. However, kernel programming does not use the standard C libraries and is specially compiled, so there are some significant differences. For example, there is no main(). This is because a module runs as part of the kernel process, and is not really an independent executable. When the module is loaded* -- ie, the program is started -- it registers a number of callback functions and other information with the kernel. A callback is a function which is called in response to some event, eg, in a user interactive program, you could have a callback for when the mouse is moved. Callbacks in modules are called by the kernel itself when, for example, the kernel detects a USB device plugged into the system. So an individual USB module must first register the ID of the device for which it was written, and some functions to deal with generic USB events (that is, basic events common to all USB devices, such as being plugged and probed by the OS). Those functions are a struct usb_driver, the ID is in a struct usb_device_id. These should be global to the scope of the module, eg, they are not assigned in any function. Notice there is a pointer in the usb_driver struct to a usb_device_id struct. What does go in an actual function is a call to usb_register(), which takes a pointer to the usb_driver struct which is declared globally (and has a pointer to the device_id struct). That function is the module's initialization function, and it is defined as such at compilation by including this line at the end of the module code: module_init (my_inititialization_function); I haven't done this stuff in a while. This is the simple part; USB module programming gets quite complex. Don't feel you have to go through with it at this point, it may be "counter productive" for you until you have more experience with the C language -- there is a lot of need for looping thru arrays of nested structs: Code: for (i=0;i<dev->actconfig->desc.bNumInterfaces;i++) {
tmp=dev->actconfig->interface[i];
printk("usbgetinfo: Configuration %d of %d\n",i+1,dev->actconfig->desc.bNumInterfaces);
for (j=0;j<tmp->num_altsetting; j++) {
hinfc=&tmp->altsetting[j];
printk("\tInterface %d of %d\n",j+1,tmp->num_altsetting);
for (k=0; k<hinfc->desc.bNumEndpoints; k++) {
endpoint = &hinfc->endpoint[k];
/* endpoint->desc is a struct usb_endpoint_descriptor */
printk("\t\tEndpoint: %d",endpoint->desc.bEndpointAddress);
if (endpoint->desc.bEndpointAddress & USB_DIR_IN) printk(" (in) ");
if (endpoint->desc.bEndpointAddress & USB_DIR_OUT) printk(" (out) ");
type = endpoint->desc.bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
switch (type) {
case (USB_ENDPOINT_XFER_BULK): printk("BULK\n"); break;
case (USB_ENDPOINT_XFER_ISOC): printk("ISOCHRONOUS\n"); break;
case (USB_ENDPOINT_XFER_INT): printk("INTERRUPT\n"); break;
default: printk("??\n"); break;
}
}
}
}
![]() Here is an online book you may want to look at: Linux Device Drivers, 2nd Edition: Online Book Unfortunately, the kernel changes all the time and there were some significant changes to some of the names of usb functions in the past year or so, meaning some material may contain the old function names. But the general idea remains the same. * the module can also be placed "in tree" with the other modules and added to a database with the depmod shell command; the kernel can then load the module on the basis of the info in the database (the device ID, etc).
__________________ Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS Last edited by MK27; 09-13-2009 at 08:12 AM. | |
| MK27 is offline | |
![]() |
| Tags |
| linux, port, ports, usb |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| USB Linux - live or no? | sean | General Discussions | 7 | 12-23-2008 10:56 AM |
| FTP program | jakemott | Linux Programming | 14 | 10-06-2008 01:58 PM |
| brace-enclosed error | jdc18 | C++ Programming | 53 | 05-03-2007 05:49 PM |
| Port app from Windows to Linux | BobS0327 | Linux Programming | 12 | 02-12-2006 02:35 AM |
| Stencil Buffer Tutorial Port.. test me! (linux) | Perspective | Game Programming | 3 | 08-15-2004 09:35 PM |