]> rtime.felk.cvut.cz Git - lincan.git/blobdiff - embedded/app/usbcan/ul_usb1.c
Embedded code and LinCAN driver now working
[lincan.git] / embedded / app / usbcan / ul_usb1.c
index 84e16325411fc9ce896de9d490981d3f2387c936..abb16268ec54c4d7c7e303a9589a677a494e34e9 100644 (file)
@@ -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
 
  */
 #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;slowdown<SJA1000_SCLK;slowdown++);
-       //SET_OUT_PIN(IO0,P0_SJA1000_ALE_PIN); // Start command
-
-       // Set memory address
-       IO1SET=__val2mfld(0x00FF0000,address&0xFF); // Shift data to SJA pins and output them
-       for (slowdown=0;slowdown<SJA1000_SCLK;slowdown++);
-       //CLR_OUT_PIN(IO0,P0_SJA1000_ALE_PIN); // Makes address active
-       CLR_OUT_PIN(IO0,P0_SJA1000_CS_PIN);
-       for (slowdown=0;slowdown<SJA1000_SCLK;slowdown++);
-
-       // Setting data
-       CLR_OUT_PIN(IO0,P0_SJA1000_WR_PIN);
-
-       IO1CLR=0x00FF0000;
-       IO1SET=__val2mfld(0x00FF0000,data&0xFF);
-       for (slowdown=0;slowdown<SJA1000_SCLK;slowdown++);
-       SET_OUT_PIN(IO0,P0_SJA1000_WR_PIN); // Data should be accepted by now
-       SET_OUT_PIN(IO0,P0_SJA1000_CS_PIN);
-       for (slowdown=0;slowdown<SJA1000_SCLK;slowdown++);
-
-//     struct usb_ul_usb1 *dev;
-//     int retval;
-//     int bytes_transferred;
-//     unsigned char buffer[2];
-//     buffer[0]=((unsigned char)address & ~CAN_OP_MASK)+CAN_OP_WRITE;
-//     buffer[1]=(unsigned char)data;
-//
-//     dev = (struct usb_ul_usb1 *)candev->sysdevptr.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;slowdown<SJA1000_SCLK;slowdown++);
-       //SET_OUT_PIN(IO0,P0_SJA1000_ALE_PIN);
-
-       // Request memory address
-       IO1SET=__val2mfld(0x00FF0000,address&0xFF);
-       for (slowdown=0;slowdown<SJA1000_SCLK;slowdown++);
-       //CLR_OUT_PIN(IO0,P0_SJA1000_ALE_PIN);
-       CLR_OUT_PIN(IO0,P0_SJA1000_CS_PIN);
-
-       // Get data
-
-       IO1DIR&=~0x00FF0000; // Sets port as input
-       CLR_OUT_PIN(IO0,P0_SJA1000_RD_PIN);
-       for (slowdown=0;slowdown<SJA1000_SCLK;slowdown++);
-       data=__mfld2val(0x00FF0000,IO1PIN);
-       SET_OUT_PIN(IO0,P0_SJA1000_RD_PIN);
-       SET_OUT_PIN(IO0,P0_SJA1000_CS_PIN);
-       for (slowdown=0;slowdown<SJA1000_SCLK;slowdown++);
+       uint8_t data;
+       can_read((uint8_t)(address & 0xFF), (uint8_t *)&data);
        return data;
-
-//     struct usb_ul_usb1 *dev;
-//     int retval;
-//     int bytes_transferred;
-//     unsigned char buffer[2];
-//     buffer[0]=((unsigned char)address & ~CAN_OP_MASK)+CAN_OP_READ;
-//     buffer[1]=0x00;
-//
-//     dev = (struct usb_ul_usb1 *)candev->sysdevptr.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 !!! */