X-Git-Url: http://rtime.felk.cvut.cz/gitweb/lincan.git/blobdiff_plain/8fd565c492003b545ab6b2353d1337d166c773da..dfdc60b200ea4395b79c02964f6aa0f043c1f372:/lincan/include/usbcan.h diff --git a/lincan/include/usbcan.h b/lincan/include/usbcan.h index 80566cd..5ddbb12 100644 --- a/lincan/include/usbcan.h +++ b/lincan/include/usbcan.h @@ -16,6 +16,8 @@ #include #include +#include "../include/kthread.h" + /* our private defines. if this grows any larger, use your own .h file */ #define MAX_TRANSFER (PAGE_SIZE - 512) /* MAX_TRANSFER is chosen so that the VM is not stressed by @@ -61,106 +63,100 @@ int usbcan_send_msg(struct canchip_t *chip, struct msgobj_t *obj, int usbcan_fill_chipspecops(struct canchip_t *chip); int usbcan_irq_handler(int irq, struct canchip_t *chip); -void usbcan_read_kthread(kthread_t *kthread); -int usbcan_chip_queue_status(struct canchip_t *chip); - int usbcan_init(void); void usbcan_exit(void); -static int usbcan_probe(struct usb_interface *interface, const struct usb_device_id *id); -static void usbcan_disconnect(struct usb_interface *interface); -#ifdef CONFIG_OC_LINCAN_DETAILED_ERRORS +int usbcan_read_kthread(void *data); +int usbcan_chip_queue_status(struct canchip_t *chip); -static const char *sja1000_ecc_errc_str[]={ - "bit error", - "form error", - "stuff error", - "other type of error" -}; +#ifdef CONFIG_OC_LINCAN_DETAILED_ERRORS -static const char *sja1000_ecc_seg_str[]={ - "?0?", - "?1?", - "ID.28 to ID.21", - "start of frame", - "bit SRTR", - "bit IDE", - "ID.20 to ID.18", - "ID.17 to ID.13", - "CRC sequence", - "reserved bit 0", - "data field", - "data length code", - "bit RTR", - "reserved bit 1", - "ID.4 to ID.0", - "ID.12 to ID.5", - "?16?" - "active error flag", - "intermission", - "tolerate dominant bits", - "?20?", - "?21?", - "passive error flag", - "error delimiter", - "CRC delimiter", - "acknowledge slot", - "end of frame", - "acknowledge delimiter", - "overload flag", - "?29?", - "?30?", - "?31?" -}; +// static const char *sja1000_ecc_errc_str[]={ +// "bit error", +// "form error", +// "stuff error", +// "other type of error" +// }; +// +// static const char *sja1000_ecc_seg_str[]={ +// "?0?", +// "?1?", +// "ID.28 to ID.21", +// "start of frame", +// "bit SRTR", +// "bit IDE", +// "ID.20 to ID.18", +// "ID.17 to ID.13", +// "CRC sequence", +// "reserved bit 0", +// "data field", +// "data length code", +// "bit RTR", +// "reserved bit 1", +// "ID.4 to ID.0", +// "ID.12 to ID.5", +// "?16?" +// "active error flag", +// "intermission", +// "tolerate dominant bits", +// "?20?", +// "?21?", +// "passive error flag", +// "error delimiter", +// "CRC delimiter", +// "acknowledge slot", +// "end of frame", +// "acknowledge delimiter", +// "overload flag", +// "?29?", +// "?30?", +// "?31?" +// }; #endif /*CONFIG_OC_LINCAN_DETAILED_ERRORS*/ -/* CAN message over usb */ -struct usbcan_canmsg_t{ - __u8 chip_id; - __u16 flags; - __u8 id[4]; - __u8 length; - __u8 data[8]; +struct usbcan_message { + struct urb *u; + u8 msg[16]; + spinlock_t acc; /* access lock */ + volatile long flags; }; -/* CAN extended mask */ -struct usbcan_mask_t{ - __u32 code; - __u32 mask; -}; +#define USBCAN_MESSAGE_FREE (1) +#define USBCAN_MESSAGE_READY_TO_SEND (2) +#define USBCAN_MESSAGE_SENDING (3) +#define USBCAN_MESSAGE_TERMINATE (4) +#define USBCAN_MESSAGE_ERROR (5) +#define USBCAN_MESSAGE_DATA_READ (6) + +#define USBCAN_TOT_RX_URBS 8 +#define USBCAN_TOT_TX_URBS 8 /* Structure to hold all of our device specific stuff */ struct usbcan_usb { struct usb_device *udev; /* the usb device for this device */ struct usb_interface *interface; /* the interface for this device */ - struct semaphore limit_sem; /* limiting the number of writes in progress */ - struct usb_anchor submitted; /* in case we need to retract our submissions */ unsigned char *bulk_in_buffer; /* the buffer to receive data */ - unsigned char *ctl_in_buffer; /* the buffer to receive data */ size_t bulk_in_size; /* the size of the receive buffer */ - size_t ctl_in_size; /* the size of the receive buffer */ - __u8 ctl_in_endpointAddr; /* the address of the bulk in endpoint */ - __u8 ctl_out_endpointAddr; /* the address of the bulk in endpoint */ - __u8 bulk_in_endpointAddr; /* the address of the bulk in endpoint */ - __u8 bulk_out_endpointAddr; /* the address of the bulk out endpoint */ - int errors; /* the last request tanked */ - int open_count; /* count the number of openers */ - spinlock_t err_lock; /* lock for errors */ + u8 bulk_in_endpointAddr; /* the address of the bulk in endpoint */ + u8 bulk_out_endpointAddr; /* the address of the bulk out endpoint */ struct mutex io_mutex; /* synchronize I/O with disconnect */ - struct urb *rcv; - struct usbcan_canmsg_t rcv_msg; - struct usbcan_canmsg_t tx_msg; - kthread_t rcvthread; /* usb receive kernel thread */ + struct urb *rx; + struct urb *tx; + u8 rx_msg[16]; + u8 tx_msg[16]; - struct candevice_t *candev; - long flags; + struct task_struct *comthread; /* usb communication kernel thread */ + + struct canchip_t *chip; + volatile long flags; }; -#define USBCAN_DATA_READ (1) -#define USBCAN_TERMINATE (2) -#define USBCAN_ERROR (3) -#define USBCAN_TX_PENDING (4) +#define USBCAN_DATA_READ (1) +#define USBCAN_TERMINATE (2) +#define USBCAN_ERROR (3) +#define USBCAN_TX_PENDING (4) +#define USBCAN_THREAD_RUNNING (5) #define USBCAN_VENDOR_BAUD_RATE_SET (1) #define USBCAN_VENDOR_BAUD_RATE_STATUS (2) @@ -168,21 +164,14 @@ struct usbcan_usb { #define USBCAN_VENDOR_CHECK_TX_STAT (4) #define USBCAN_VENDOR_START_CHIP (5) #define USBCAN_VENDOR_STOP_CHIP (6) +#define USBCAN_VENDOR_EXT_MASK_SET (7) +#define USBCAN_VENDOR_EXT_MASK_STATUS (8) -/* table of devices that work with this driver */ -static struct usb_device_id usbcan_table [] = { - { USB_DEVICE(USBCAN_VENDOR_ID, USBCAN_PRODUCT_ID) }, - { } /* Terminating entry */ -}; -MODULE_DEVICE_TABLE(usb, usbcan_table); - -static struct usb_driver usbcan_driver = { - .name = "usbcan", - .id_table = usbcan_table, - .probe = usbcan_probe, - .disconnect = usbcan_disconnect, +struct usbcan_devs { + struct usbcan_usb **devs; + int count; + struct candevice_t *candev; }; - #endif /*USBCAN_H*/