USB Communication and ioctl macros
Posted: Wed Jul 22, 2009 5:44 pm
I’m trying to communicate with a usb device (microcontroller 18F2550) and used libhid to control it but I have some issues with this library like bad connections, (random) read and write errors. I want to try the ioctl api’s but stumbled on some macro translations (_IO, _IOC, _IOR,….) in the ioctl.h (located somewhere in the /usr/src/…..)
This is part of the header file:
Does anyone have an translation, example or a good alternative to use usb in pb Linux?
This is part of the header file:
Code: Select all
.........
#define _IOC(dir,type,nr,size) \
(((dir) << _IOC_DIRSHIFT) | \
((type) << _IOC_TYPESHIFT) | \
((nr) << _IOC_NRSHIFT) | \
((size) << _IOC_SIZESHIFT))
#ifdef __KERNEL__
/* provoke compile error for invalid uses of size argument */
extern unsigned int __invalid_size_argument_for_IOC;
#define _IOC_TYPECHECK(t) \
((sizeof(t) == sizeof(t[1]) && \
sizeof(t) < (1 << _IOC_SIZEBITS)) ? \
sizeof(t) : __invalid_size_argument_for_IOC)
#else
#define _IOC_TYPECHECK(t) (sizeof(t))
#endif
/* used to create numbers */
#define _IO(type,nr) _IOC(_IOC_NONE,(type),(nr),0)
#define _IOR(type,nr,size) _IOC(_IOC_READ,(type),(nr),(_IOC_TYPECHECK(size)))
#define _IOW(type,nr,size) _IOC(_IOC_WRITE,(type),(nr),(_IOC_TYPECHECK(size)))
.............