#include <linux/can/dev.h>
#include <linux/can/error.h>
+// lpc17xx debug
+#define USBCAN_VENDOR_SET_CANBTR (9)
+#define CTU_USBCAN_CAN_CLOCK 18000000
+// lpc17xx debug - end
+
#define CTU_USBCAN_VENDOR_ID 0x1669
#define CTU_USBCAN_PRODUCT_ID 0x1011
wait_queue_head_t queue;
volatile long flags;
+
};
u16 flags = 0;
struct net_device_stats *stats = &m->dev->netdev->stats;
-
+/*
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,32)
skb = alloc_can_skb(m->dev->netdev, &cf);
#else
skb->protocol = htons(ETH_P_CAN);
cf = (struct can_frame *)skb_put(skb, sizeof(struct can_frame));
#endif
+*/
+ skb = alloc_can_skb(m->dev->netdev, &cf);
if (skb == NULL){
err("RX: error alloc skb\n");
static int ctu_usbcan_open(struct net_device *netdev)
{
+ int err;
struct ctu_usbcan_usb *dev = netdev_priv(netdev);
+ /* common open */
+ err = open_candev(netdev);
+ if (err)
+ return err;
+
/* start kernel thread */
dev->comthread = kthread_run(usbcan_kthread, (void *)dev, "usbcan_1");
struct ctu_usbcan_usb *dev = netdev_priv(netdev);
kthread_stop(dev->comthread);
+
+ close_candev(netdev);
return 0;
}
.ndo_start_xmit = ctu_usbcan_start_xmit,
};
+static struct can_bittiming_const ctu_usbcan_bittiming_const = {
+ .name = "lpc17xx_can",
+ .tseg1_min = 1,
+ .tseg1_max = 16,
+ .tseg2_min = 1,
+ .tseg2_max = 8,
+ .sjw_max = 4,
+ .brp_min = 1,
+ .brp_max = 1024,
+ .brp_inc = 1,
+};
+
+static int ctu_usbcan_set_mode(struct net_device *netdev, enum can_mode mode)
+{
+ struct ems_usb *dev = netdev_priv(netdev);
+
+ printk("SET MODE\n");
+
+ return 0;
+}
+
+static int ctu_usbcan_set_bittiming(struct net_device *netdev)
+{
+ struct ctu_usbcan_usb *dev = netdev_priv(netdev);
+ struct can_bittiming *bt = &dev->can.bittiming;
+ int retval;
+
+ u8 usbbuf[USBCAN_TRANSFER_SIZE];
+
+ printk("BRP: %d, SJW: %d, TSEG1: %d, TSEG2: %d - ", bt->brp, bt->sjw, ( bt->prop_seg + bt->phase_seg1), bt->phase_seg2);
+
+
+ if (!dev)
+ return -ENODEV;
+
+ *(uint32_t *)(usbbuf)=cpu_to_le32(bt->brp); // baudrate prescaler
+ *(uint32_t *)(usbbuf+4)=cpu_to_le32(bt->sjw); // sjw
+ *(uint32_t *)(usbbuf+8)=cpu_to_le32(bt->prop_seg + bt->phase_seg1); // TSEG1
+ *(uint32_t *)(usbbuf+12)=cpu_to_le32(bt->phase_seg2); // TSEG2
+
+ retval = usb_control_msg(dev->udev,
+ usb_sndctrlpipe(dev->udev, 0),
+ USBCAN_VENDOR_SET_CANBTR,
+ USB_TYPE_VENDOR,
+ cpu_to_le16(0), cpu_to_le16(0),
+ &usbbuf, USBCAN_TRANSFER_SIZE,
+ 1000);
+
+ if(retval){
+ printk("OK\n");
+ return 0;
+ }
+ else{
+ printk("KO\n");
+ return retval;
+ }
+
+}
+
+
static int ctu_usbcan_probe(struct usb_interface *intf,
const struct usb_device_id *id)
{
printk(KERN_INFO "CTU USBCAN device now attached\n");
+/*
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,32)
netdev = alloc_candev(sizeof(struct ctu_usbcan_usb), USBCAN_TOT_TX_URBS);
#else
netdev = alloc_candev(sizeof(struct ctu_usbcan_usb));
#endif
+*/
+ netdev = alloc_candev(sizeof(struct ctu_usbcan_usb), USBCAN_TOT_TX_URBS);
if (!netdev) {
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,33)
dev->udev = interface_to_usbdev(intf);
dev->netdev = netdev;
+ dev->can.clock.freq = CTU_USBCAN_CAN_CLOCK;
+ dev->can.bittiming_const = &ctu_usbcan_bittiming_const;
+ dev->can.do_set_bittiming = ctu_usbcan_set_bittiming;
+ dev->can.do_set_mode = ctu_usbcan_set_mode;
+
+
netdev->netdev_ops = &ctu_usbcan_netdev_ops;
netdev->flags |= IFF_ECHO;