?? open.c
字號:
/* open.c * Linux CAN-bus device driver. * Written by Arnaud Westenberg email:arnaud@wanadoo.nl * This software is released under the GPL-License. * Version 0.7 6 Aug 2001 */#define __NO_VERSION__#include <linux/module.h> #include <linux/autoconf.h>#if defined (CONFIG_MODVERSIONS) && !defined (MODVERSIONS)#define MODVERSIONS#endif#if defined (MODVERSIONS)#include <linux/modversions.h>#endif#include <linux/fs.h>#include <linux/malloc.h>#include <linux/version.h>#include "../include/main.h"#include "../include/open.h"#include "../include/i82527.h"#include "../include/setup.h"int can_open(struct inode *inode, struct file *file){ struct msgobj_t *obj; struct chip_t *chip; struct canfifo_t *fifo; if ( ((obj=objects_p[MINOR_NR]) == NULL) || ((chip=objects_p[MINOR_NR]->hostchip) == NULL) ) { CANMSG("There is no hardware support for the device file with minor nr.: %d\n",MINOR_NR); return -ENODEV; } if (objects_p[MINOR_NR]->flags & OPENED) { CANMSG("Sorry, only single open per device file.\n"); return -EBUSY; } else objects_p[MINOR_NR]->flags |= OPENED; if (chip->flags & CONFIGURED) DEBUGMSG("Device is already configured.\n"); else { if (chip->chipspecops->chip_config(chip)) CANMSG("Error configuring chip.\n"); else chip->flags |= CONFIGURED; } /* End of chip configuration */ /* Allocate output buffer memory for the opened device */ fifo = objects_p[MINOR_NR]->fifo; fifo->buf_tx_entry=(struct canmsg_t *)kmalloc(MAX_BUF_LENGTH * sizeof(struct canmsg_t), GFP_KERNEL); if (fifo->buf_tx_entry == NULL) return -ENOMEM; else if ( add_mem_to_list(fifo->buf_tx_entry) ) return -ENOMEM; /* Allocate input buffer memory for the opened device */ fifo->buf_rx_entry=(struct canmsg_t *)kmalloc(MAX_BUF_LENGTH * sizeof(struct canmsg_t), GFP_KERNEL); if (fifo->buf_rx_entry == NULL) return -ENOMEM; else if ( add_mem_to_list(fifo->buf_rx_entry) ) return -ENOMEM; /* In- and output buffer initialization */ fifo->tx_readp = fifo->buf_tx_entry; fifo->tx_writep = fifo->buf_tx_entry; fifo->rx_readp = fifo->buf_rx_entry; fifo->rx_writep = fifo->buf_rx_entry; fifo->rx_size = MAX_BUF_LENGTH * sizeof(struct canmsg_t); fifo->tx_size = fifo->rx_size;#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,2,19)) init_waitqueue(&fifo->readq); init_waitqueue(&fifo->writeq);#else init_waitqueue_head(&fifo->readq); init_waitqueue_head(&fifo->writeq);#endif fifo->rx_in_progress = 0; fifo->tx_in_progress = 0; fifo->head = fifo->tail = 0; //TEMP!! if (chip->chipspecops->pre_read_config(chip,obj)<0) CANMSG("Error initializing chip for receiving\n"); MOD_INC_USE_COUNT; return 0;}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -