X-Git-Url: http://rtime.felk.cvut.cz/gitweb/lincan.git/blobdiff_plain/5a5faefde7751e7fec5016059175b6f1109b914a..1a157d7de03aaf7887a59fae6fbd62eec854aede:/lincan/include/usbcan.h diff --git a/lincan/include/usbcan.h b/lincan/include/usbcan.h index e69de29..f29f9b8 100644 --- a/lincan/include/usbcan.h +++ b/lincan/include/usbcan.h @@ -0,0 +1,194 @@ +/* usbcan.h + * Header file for the Linux CAN-bus driver. + * Written by Jan Kriz email:johen@post.cz + * This software is released under the GPL-License. + * Version lincan-0.3 17 Jul 2008 + */ + +#ifndef USBCAN_H +#define USBCAN_H + +#include +#include +#include +#include +#include +#include +#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 + allocations > PAGE_SIZE and the number of packets in a page + is an integer 512 is the largest possible packet on EHCI */ +#define WRITES_IN_FLIGHT 8 +/* arbitrarily chosen */ + +/* Define these values to match your devices */ +#define USBCAN_VENDOR_ID 0x1669 +#define USBCAN_PRODUCT_ID 0x1011 + +#define RESET_ADDR 0x0 + +/* + * IO_RANGE is the io-memory range that gets reserved, please adjust according + * your hardware. Example: #define IO_RANGE 0x100 for i82527 chips or + * #define IO_RANGE 0x20 for sja1000 chips in basic CAN mode. + */ +#define IO_RANGE 0x100 + + +int usbcan_request_io(struct candevice_t *candev); +int usbcan_release_io(struct candevice_t *candev); +int usbcan_reset(struct candevice_t *candev); +int usbcan_init_hw_data(struct candevice_t *candev); +int usbcan_init_chip_data(struct candevice_t *candev, int chipnr); +int usbcan_init_obj_data(struct canchip_t *chip, int objnr); +void usbcan_write_register(unsigned data, unsigned long address); +unsigned usbcan_read_register(unsigned long address); +int usbcan_program_irq(struct candevice_t *candev); +int usbcan_register(struct hwspecops_t *hwspecops); + +int usbcan_chip_config(struct canchip_t *chip); +int usbcan_extended_mask(struct canchip_t *chip, unsigned long code, unsigned long mask); +int usbcan_baud_rate(struct canchip_t *chip, int rate, int clock, int sjw, + int sampl_pt, int flags); +int usbcan_pre_read_config(struct canchip_t *chip, struct msgobj_t *obj); +int usbcan_pre_write_config(struct canchip_t *chip, struct msgobj_t *obj, + struct canmsg_t *msg); +int usbcan_send_msg(struct canchip_t *chip, struct msgobj_t *obj, + struct canmsg_t *msg); +int usbcan_fill_chipspecops(struct canchip_t *chip); +int usbcan_irq_handler(int irq, struct canchip_t *chip); + +int usbcan_init(void); +void usbcan_exit(void); + +int usbcan_kthread(void *data); +int usbcan_chip_queue_status(struct canchip_t *chip); + +#ifdef CONFIG_OC_LINCAN_DETAILED_ERRORS + +// 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*/ + +struct usbcan_usb; + +#define USBCAN_TOT_RX_URBS 8 +#define USBCAN_TOT_TX_URBS 8 + +#define USBCAN_TRANSFER_SIZE 16 + +struct usbcan_message { + struct urb *u; + struct usbcan_usb *dev; + u8 msg[USBCAN_TRANSFER_SIZE]; + struct canque_edge_t *qedge; + struct canque_slot_t *slot; + struct list_head list_node; + volatile long flags; +}; + +#define USBCAN_MESSAGE_FREE (1) +#define USBCAN_MESSAGE_URB_PENDING (2) +#define USBCAN_MESSAGE_TERMINATE (3) +#define USBCAN_MESSAGE_ERROR (4) +#define USBCAN_MESSAGE_DATA_OK (5) +#define USBCAN_MESSAGE_TYPE_RX (6) +#define USBCAN_MESSAGE_TYPE_TX (7) + +/* 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 */ + unsigned char *bulk_in_buffer; /* the buffer to receive data */ + size_t bulk_in_size; /* the size of the receive buffer */ + 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 list_head rx_pend_list; /* URBs waiting for data receive */ + struct list_head rx_ready_list; /* URBs with valid received data */ + struct list_head tx_idle_list; /* URBs prepared to hold Tx messages */ + struct list_head tx_pend_list; /* URBs holding Tx messages in progress */ + struct list_head tx_ready_list; /* URBs with yet confirmed Tx messages */ + + spinlock_t list_lock; /* list lock */ + + struct task_struct *comthread; /* usb communication kernel thread */ + wait_queue_head_t queue; + + struct canchip_t *chip; + volatile long flags; +}; + +#define USBCAN_DATA_OK (1) +#define USBCAN_DATA_RX (2) +#define USBCAN_DATA_TX (3) +#define USBCAN_TERMINATE (4) +#define USBCAN_ERROR (5) +#define USBCAN_TX_PENDING (6) +#define USBCAN_THREAD_RUNNING (7) +#define USBCAN_FREE_TX_URB (8) + +#define USBCAN_VENDOR_BAUD_RATE_SET (1) +#define USBCAN_VENDOR_BAUD_RATE_STATUS (2) +#define USBCAN_VENDOR_SET_BTREGS (3) +#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) + +struct usbcan_devs { + struct usbcan_usb **devs; + int count; + struct candevice_t *candev; +}; + + +#endif /*USBCAN_H*/