⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 core.c

📁 can4linux-3.5.3.gz can4 linux
💻 C
📖 第 1 页 / 共 2 页
字号:
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0) static int __init can_init(void)#elsestatic int init_module(void)#endif{int i, j, err = 0;int minor = -1;    /* do you want do see debug message already while loading the driver ?     * Then enable this line and set the mask != 0     */    /* dbgMask = 7; */    DBGin();    /* try udev support */    if( (i = register_chrdev(Can_major, CANREGDEVNAME, &can_fops))) {	printk(KERN_ERR "-> can't get Major %d = %d\n", Can_major, i);	return(-EIO);    }    /* udev support */    can_class = class_create(THIS_MODULE, CANREGDEVNAME);    if( IS_ERR(can_class)) {	printk("No udev support.\n");	err = PTR_ERR(can_class);	goto out_devfs;    }    /*    extern struct device *device_create(    		struct class *cls, struct device *parent,		dev_t devt, const char *fmt, ...)		__attribute__((format(printf, 4, 5)));    */    for (i = 0; i < MAX_CHANNELS; i++) {	device_create(can_class, NULL, MKDEV(Can_major, i),		"can%d", i);    }    printk(KERN_INFO __CAN_TYPE__ "CAN Driver " VERSION " (c) "    					__DATE__ " " __TIME__ "\n");#if defined(MCF5282)    printk(KERN_INFO " FlexCAN port by H.J. Oertel (oe@port.de)\n");#elif defined(AD_BLACKFIN)    printk(KERN_INFO " BlackFin port by H.J. Oertel (oe@port.de)\n");#elif defined(ATMEL_SAM9)    printk(KERN_INFO " Atmel AT919263 port by H.J. Oertel (oe@port.de)\n");#elif defined(SSV_MCP2515)    printk(KERN_INFO " Atmel AT91 and MCP2515 port by H.J. Oertel (oe@port.de)\n");#else    printk(KERN_INFO " H.J. Oertel (oe@port.de)\n");#endif	        printk(KERN_INFO " MAX_CHANNELS %d\n", MAX_CHANNELS);    printk(KERN_INFO " CAN_MAX_OPEN %d\n", CAN_MAX_OPEN);    /*    initialize the variables layed down in /proc/sys/Can    ====================================================    */    for (i = 0; i < MAX_CHANNELS; i++) {        atomic_set(&Can_isopen[i], 0);	for(j=0; j < CAN_MAX_OPEN; j++) {	    selfreception[i][j] = 1;	}	use_timestamp[i] = 1;	IOModel[i]       = IO_MODEL;	Baud[i]          = 125;	AccCode[i]       = AccMask[i] =  STD_MASK;	Timeout[i]       = 100;	Outc[i]          = CAN_OUTC_VAL;	IRQ_requested[i] = 0;	Can_minors[i]    = i;		/* used as IRQ dev_id */	spin_lock_init(&write_splock[i]);#if defined(MCF5282)	/* we have a really fixed address here */	Base[i] = (MCF_MBAR + 0x1c0000);	/* Because the MCF FlexCAN is using more then 1 Interrupt vector,	 * what should be specified here ?	 * For information purpose let's only specify  the first used here	 */	IRQ[i] = 136;#endif#if defined(AD_BLACKFIN)	/* we have a really fixed address here */	/* starting with Mailbox config reg 1  */	Base[i] = BFCAN_BASE;	/* Because the AD BlackFin CAN is using more then 1 Interrupt vector,	 * what should be specified here ?	 * For information purpose let's only specify  the first used here.	 * Next one is +1	 */	IRQ[i] = IRQ_CAN_RX;#endif#if defined(ATMEL_SAM9)	/* we have a really fixed address here */	Base[i] = (AT91SAM9263_BASE_CAN);	/* 	 */	IRQ[i] = AT91SAM9263_ID_CAN;#endif#if defined(VCMA9)	Base[i] = 0x28000000;	can_sysctl_table[CAN_SYSCTL_IRQ  - 1].mode = 0444;	can_sysctl_table[CAN_SYSCTL_BASE - 1].mode = 0444;# if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))	IRQ[i] = 37 + 16;# else	IRQ[i] = 37;# endif#endif#if defined(CCPC104)        pc104_irqsetup();        IRQ[i]           = 67;          /* The only possible vector on CTRLink's 5282 CPU */        Base[i]          = 0x40000280;#endif#if defined(MMC_SJA1000)	Base[i]          = 0x30000000 + (2 * i);        /* IRQ[i]           = gpio_to_irq(CAN_IRQ_PIN); */        IRQ[i]           =  AT91SAM9260_ID_IRQ0;#endif    } /* end of for loop initializing all CAN channels */    /*    ====================================================    */#if defined(VCMA9)    /* only one SJA1000 available     * we can check if it is available when loading the module     */     if(!controller_available(0x28000000, 1)) {	err =  -EIO;	goto out_class;     }#endif    /* after initializing channel based parameters     * finish some entries      * and do drivers specific initialization     */    IOModel[i] = '\0';#if CAN4LINUX_PCI    /* make some syctl entries read only     * IRQ number     * Base address     * and access mode     * are fixed and provided by the PCI BIOS     */    can_sysctl_table[CAN_SYSCTL_IRQ  - 1].mode = 0444;    can_sysctl_table[CAN_SYSCTL_BASE - 1].mode = 0444;    /* printk(KERN_INFO "CAN pci test loaded\n"); */    /* dbgMask = 0; */    if(pcimod_scan()) {        err("bin ich hier ?");	err = -EIO;	goto out_class;    }    err("pci scan success");#endif#if defined(CCPC104)    /* The only possible interrupt could be IRQ4 on the PC104 Board */    can_sysctl_table[CAN_SYSCTL_IRQ - 1].mode = 0444;#endif#if defined(MCF5282)    can_sysctl_table[CAN_SYSCTL_BASE - 1].mode = 0444; #endif#if defined(MMC_SJA1000)    init_mmc_hw();#endif#if LDDK_USE_PROCINFO    register_procinfo();#endif#if LDDK_USE_SYSCTL    register_systables();#endif    DBGout();    return 0;out_class:    class_destroy(can_class);out_devfs:    unregister_chrdev(Can_major, CANREGDEVNAME);    DBGout();    return err;}#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0) static void __exit can_exit(void)#elsestatic void cleanup_module(void)#endif{#if defined(KVASER_PCICAN)int i;void *ptr;#endifint minor = -1;        DBGin();#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)   if (MOD_IN_USE) {    printk(KERN_WARNING "Can : device busy, remove delayed\n");  }#endif#ifdef KVASER_PCICAN    i = 0;    ptr = NULL;    /* The pointer to dev can be used up to four times,     * but we have to release the region only once */    while(Can_pcidev[i]) {	if( ptr !=  Can_pcidev[i]) { printk(KERN_INFO " release\n");	    /* disable PCI board interrupts */	    disable_pci_interrupt(pci_resource_start(Can_pcidev[i], 0));	    /* printk(KERN_DEBUG "release Kvaser CAN region 2 (XILINX)\n"); */	    pci_release_region(Can_pcidev[i], 2);   /*release xilinx */	    /* printk(KERN_DEBUG "release Kvaser CAN region 1 (CAN)\n"); */	    pci_release_region(Can_pcidev[i], 1); /*release i/o */	    /* printk(KERN_DEBUG "release Kvaser CAN region 0 (PCI)\n"); */	    pci_release_region(Can_pcidev[i], 0);   /*release pci */	}	ptr = Can_pcidev[i];	i++;    }#endif    unregister_chrdev(Can_major, CANREGDEVNAME);    printk(KERN_INFO CANREGDEVNAME ": successfully removed\n");    if( !IS_ERR(can_class)) {	int i;	for (i = 0; i < MAX_CHANNELS; i++) {	    device_destroy(can_class, MKDEV(Can_major, i));	}	class_destroy(can_class);    }#if LDDK_USE_PROCINFO    unregister_procinfo();#endif#if LDDK_USE_SYSCTL    unregister_systables();#endif    DBGout();}#endif /* DOXYGEN_SHOULD_SKIP_THIS */#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0) module_init(can_init);module_exit(can_exit);/* EXPORT_NO_SYMBOLS; */#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -