X-Git-Url: http://rtime.felk.cvut.cz/gitweb/lincan.git/blobdiff_plain/3c6d0376edd06bad63e861415974556259f593cd..f6c113a5fb217e7495b93053cf29fa6966923445:/embedded/app/usbcan/ul_usb1.c diff --git a/embedded/app/usbcan/ul_usb1.c b/embedded/app/usbcan/ul_usb1.c index 84e1632..abb1626 100644 --- a/embedded/app/usbcan/ul_usb1.c +++ b/embedded/app/usbcan/ul_usb1.c @@ -18,7 +18,6 @@ * */ -#include "./can/ul_usb1.h" #include "./can/can.h" #include "./can/can_sysdep.h" #include "./can/main.h" @@ -31,6 +30,8 @@ #include "./can/errno.h" +#include "./can/ul_usb1.h" + /* Get a minor range for your devices from the usb maintainer */ #define USB_SKEL_MINOR_BASE 192 @@ -72,30 +73,6 @@ */ #define IO_RANGE 0x100 -/* Structure to hold all of our device specific stuff */ -// struct usb_ul_usb1 { -// 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 */ -// size_t bulk_in_size; /* the size of the receive buffer */ -// unsigned char *int_in_buffer; /* the buffer to receive data */ -// size_t int_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 */ -// __u8 int_in_endpointAddr; /* the address of the interrupt in endpoint */ -// int int_in_interval; -// int errors; /* the last request tanked */ -// int open_count; /* count the number of openers */ -// spinlock_t err_lock; /* lock for errors */ -// struct mutex io_mutex; /* synchronize I/O with disconnect */ -// struct urb *irq; -// struct candevice_t *candev; -// }; -// -// static struct usb_driver ul_usb1_driver; - /** ul_usb1_request_io * ul_usb1_request_io: - reserve io or memory range for can board * @candev: pointer to candevice/board which asks for io. Field @io_addr @@ -300,63 +277,7 @@ int ul_usb1_program_irq(struct candevice_t *candev) */ void ul_usb1_write_register(unsigned data, unsigned long address) { - IO1DIR|=0x00FF0000; // Port as output to send data - IO1CLR=0x00FF0000; // Clear all data on port - // Init - SET_OUT_PIN(IO0,P0_SJA1000_RD_PIN); // Stays high on write - SET_OUT_PIN(IO0,P0_SJA1000_WR_PIN); // Stays high on address write - SET_OUT_PIN(IO0,P0_SJA1000_CS_PIN); // Sets output buffers to third state - for (slowdown=0;slowdownsysdevptr.anydev; - -// mutex_lock(&dev->io_mutex); -// if (!dev) { /* disconnect() was called */ -// CANMSG("Sending %lu:%X : ERR No device\n",address,(uint8_t)data); -// retval = -ENODEV; -// goto exit; -// } -// if (!dev->interface) { /* disconnect() was called */ -// CANMSG("Sending %lu:%X : ERR No interface\n",address,(uint8_t)data); -// retval = -ENODEV; -// goto exit; -// } - - /* do a blocking bulk write to send data to the device */ -/* retval = usb_bulk_msg(dev->udev, - usb_sndbulkpipe(dev->udev, dev->bulk_out_endpointAddr), - buffer, - 2, - &bytes_transferred, 10000); - CANMSG("Sending %lu:%X : retval %d, transferred %d bytes\n",address,(uint8_t)data,retval,bytes_transferred); - -exit: - mutex_unlock(&dev->io_mutex);*/ + can_write((uint8_t)(address & 0xFF), (uint8_t *)&data); } /** ul_usb1_read_register @@ -371,84 +292,9 @@ exit: */ unsigned ul_usb1_read_register(unsigned long address) { - unsigned data; - IO1DIR|=0x00FF0000; // Port as output to set address - IO1CLR=0x00FF0000; // Clear all data - // Init - SET_OUT_PIN(IO0,P0_SJA1000_WR_PIN); // Stays high on read - SET_OUT_PIN(IO0,P0_SJA1000_RD_PIN); // Stays high while entering address - SET_OUT_PIN(IO0,P0_SJA1000_CS_PIN); - for (slowdown=0;slowdownsysdevptr.anydev; - -// mutex_lock(&dev->io_mutex); -// if (!dev) { /* disconnect() was called */ -// retval = -ENODEV; -// goto exit; -// } -// if (!dev->interface) { /* disconnect() was called */ -// retval = -ENODEV; -// goto exit; -// } - - /* do a blocking bulk write to send data to the device */ -/* retval = usb_bulk_msg(dev->udev, - usb_sndbulkpipe(dev->udev, dev->bulk_out_endpointAddr), - buffer, - 2, - &bytes_transferred, 10000); - - CANMSG("Requested: %ld : retval %d, transferred %d bytes\n",address,retval,bytes_transferred); - if ((retval)||(bytes_transferred!=2)){ - retval = -EFAULT; - goto exit; - } -*/ - /* do a blocking bulk read to get data from the device */ -// retval = usb_bulk_msg(dev->udev, -// usb_rcvbulkpipe(dev->udev, dev->bulk_in_endpointAddr), -// dev->bulk_in_buffer, -// dev->bulk_in_size, -// &bytes_transferred, 10000); - - /* if the read was successful, copy the data to userspace */ -/* CANMSG("Received %d bytes : %u:%X\n",bytes_transferred,(dev->bulk_in_buffer[0] & 0x7F),dev->bulk_in_buffer[1]); - if (!retval) { - if (bytes_transferred!=2) - retval = -EFAULT; - else - retval = dev->bulk_in_buffer[1]; - } - -exit: - mutex_unlock(&dev->io_mutex); - return retval;*/ } /* !!! Don't change this function !!! */