int can_Command(struct inode *inode, struct file *file, Command_par_t * argp) { unsigned int minor = iminor(inode); int cmd; int rx_fifo = ((struct _instance_data *)(file->private_data))->rx_index; cmd = argp->cmd; DBGprint(DBG_DATA,("%s: cmd=%d", __func__, cmd)); switch (cmd) { case CMD_START: CAN_StartChip(minor); break; case CMD_STOP: CAN_StopChip(minor); break; case CMD_RESET: CAN_ChipReset(minor); break; case CMD_CLEARBUFFERS: { Can_TxFifoInit(minor); Can_RxFifoInit(minor, rx_fifo); #if 0 if( argp->target = CMD_CLEAR_RX) { } else if( argp->target = CMD_CLEAR_TX) { } else { DBGout(); return(-EINVAL); } #endif } break; default: DBGout(); return(-EINVAL); } return 0; }
int can_Command(struct inode *inode, int cmd) { unsigned int minor = MINOR(inode->i_rdev); DBGprint(DBG_DATA,("cmd=%d", cmd)); switch (cmd) { case CMD_START: CAN_StartChip(minor); break; case CMD_STOP: CAN_StopChip(minor); break; case CMD_RESET: CAN_ChipReset(minor); break; default: DBGout(); return(-EINVAL); } return 0; }
/** * * \brief int open(const char *pathname, int flags); * opens the CAN device for following operations * \param pathname device pathname, usual /dev/can? * \param flags is one of \c O_RDONLY, \c O_WRONLY or \c O_RDWR which request * opening the file read-only, write-only or read/write, * respectively. * * * The open call is used to "open" the device. * Doing a first initialization according the to values in the /proc/sys/Can * file system. * Additional an ISR function is assigned to the IRQ. * * The CLK OUT pin is configured for creating the same frequency * like the chips input frequency fclk (XTAL). * * If Vendor Option \a VendOpt is set to 's' the driver performs * an hardware reset befor initializing the chip. * * \returns * open return the new file descriptor, * or -1 if an error occurred (in which case, errno is set appropriately). * * \par ERRORS * the following errors can occur * \arg \c ENXIO the file is a device special file * and no corresponding device exists. * \arg \c EINVAL illegal \b minor device number * \arg \c EINVAL wrong IO-model format in /proc/sys/Can/IOmodel * \arg \c EBUSY IRQ for hardware is not available * \arg \c EBUSY I/O region for hardware is not available */ int can_open( __LDDK_OPEN_PARAM ) { int retval = 0; DBGin("can_open"); { int lasterr; unsigned int minor = iminor(inode); if( minor > MAX_CHANNELS ) { printk(KERN_ERR "CAN: Illegal minor number %d\n", minor); DBGout(); return -EINVAL; } /* check if device is already open, should be used only by one process */ if(Can_isopen[minor] == 1) { DBGout(); return -ENXIO; } if( Base[minor] == 0x00) { /* No device available */ printk(KERN_ERR "CAN[%d]: no device available\n", minor); DBGout(); return -ENXIO; } /* the following does all the board specific things also memory remapping if necessary */ if( (lasterr = CAN_VendorInit(minor)) < 0 ){ DBGout(); return lasterr; } /* Access macros based in can_base[] should work now */ /* CAN_ShowStat(minor); */ /* controller_available(curr + 0x400, 4); */ Can_WaitInit(minor); /* initialize wait queue for select() */ Can_FifoInit(minor); #if CAN_USE_FILTER Can_FilterInit(minor); #endif if( CAN_ChipReset(minor) < 0 ) { DBGout(); return -EINVAL; } CAN_StartChip(minor); #if DEBUG CAN_ShowStat(minor); #endif ++Can_isopen[minor]; /* flag device in use */ } DBGout(); return retval; }