📄 st16c554.c
字号:
static int ST0B_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg){ int nRet = 0; switch(cmd) { case ST_INIT: copy_from_user(&st0B_init, (struct tagST_INIT *)arg, sizeof(struct tagST_INIT)); Init_ST0B(st0B_init.nBaud, st0B_init.byMode); break; default: return -EINVAL; } return nRet;}static int ST0B_read(struct file *filp, char *buf, size_t count, loff_t *ppos){ int i; int nLen; unsigned char abyRecv[ST_RECV_LEN]; nLen = get_ST0B_rxLen(); nLen = nLen>count ? count : nLen; for(i=0; i<nLen; i++){ abyRecv[i] = st0B.abyRecvData[st0B.sRecvHead]; if(st0B.sRecvHead != st0B.sRecvTail){ st0B.sRecvHead++; st0B.sRecvHead %= ST_RECV_LEN; } else break; } copy_to_user((void *)buf, &abyRecv, i); return i;}static int ST0B_write (struct file *file, const char *buf, size_t count, loff_t *ppos){ return st16c554_ComWrite(buf,count,&st0B); }static int ST0B_release(struct inode *inode, struct file *filp){ int nRet = 0; MOD_DEC_USE_COUNT; return nRet;}static int ST0C_open(struct inode *inode, struct file *filp){ int nRet = 0; MOD_INC_USE_COUNT; return nRet;}static int ST0C_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg){ int nRet = 0; switch(cmd) { case ST_INIT: copy_from_user(&st0C_init, (struct tagST_INIT *)arg, sizeof(struct tagST_INIT)); Init_ST0C(st0C_init.nBaud, st0C_init.byMode); break; default: return -EINVAL; } return nRet;}static int ST0C_read(struct file *filp, char *buf, size_t count, loff_t *ppos){ int i; int nLen; unsigned char abyRecv[ST_RECV_LEN]; nLen = get_ST0C_rxLen(); nLen = nLen>count ? count : nLen; for(i=0; i<nLen; i++){ abyRecv[i] = st0C.abyRecvData[st0C.sRecvHead]; if(st0C.sRecvHead != st0C.sRecvTail){ st0C.sRecvHead++; st0C.sRecvHead %= ST_RECV_LEN; } else break; } copy_to_user((void *)buf, &abyRecv, i); return i;}static int ST0C_write (struct file *file, const char *buf, size_t count, loff_t *ppos){ return st16c554_ComWrite(buf,count,&st0C); }static int ST0C_release(struct inode *inode, struct file *filp){ int nRet = 0; MOD_DEC_USE_COUNT; return nRet;}static int ST0D_open(struct inode *inode, struct file *filp){ int nRet = 0; MOD_INC_USE_COUNT; return nRet;}static int ST0D_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg){ int nRet = 0; switch(cmd) { case ST_INIT: copy_from_user(&st0D_init, (struct tagST_INIT *)arg, sizeof(struct tagST_INIT)); Init_ST0D(st0D_init.nBaud, st0D_init.byMode); break; default: return -EINVAL; } return nRet;}static int ST0D_read(struct file *filp, char *buf, size_t count, loff_t *ppos){ int i; int nLen; unsigned char abyRecv[ST_RECV_LEN]; nLen = get_ST0D_rxLen(); nLen = nLen>count ? count : nLen; for(i=0; i<nLen; i++){ abyRecv[i] = st0D.abyRecvData[st0D.sRecvHead]; if(st0D.sRecvHead != st0D.sRecvTail){ st0D.sRecvHead++; st0D.sRecvHead %= ST_RECV_LEN; } else break;// printk("D-:%02X\n", abyRecv[i]); } copy_to_user((void *)buf, &abyRecv, i); return i;}static int ST0D_write (struct file *file, const char *buf, size_t count, loff_t *ppos){ return st16c554_ComWrite(buf,count,&st0D); }static int ST0D_release(struct inode *inode, struct file *filp){ int nRet = 0; MOD_DEC_USE_COUNT; return nRet;}static int ST0E_open(struct inode *inode, struct file *filp){ int nRet = 0; MOD_INC_USE_COUNT; return nRet;}static int ST0E_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg){ int nRet = 0; switch(cmd) { case ST_INIT: copy_from_user(&st0E_init, (struct tagST_INIT *)arg, sizeof(struct tagST_INIT)); Init_ST0E(st0E_init.nBaud, st0E_init.byMode); break; default: return -EINVAL; } return nRet;}static int ST0E_read(struct file *filp, char *buf, size_t count, loff_t *ppos){ int i; int nLen; unsigned char abyRecv[ST_RECV_LEN]; nLen = get_ST0E_rxLen(); nLen = nLen>count ? count : nLen; for(i=0; i<nLen; i++){ abyRecv[i] = st0E.abyRecvData[st0E.sRecvHead]; if(st0E.sRecvHead != st0E.sRecvTail){ st0E.sRecvHead++; st0E.sRecvHead %= ST_RECV_LEN; } else break; } copy_to_user((void *)buf, &abyRecv, i); return i;}static int ST0E_write (struct file *file, const char *buf, size_t count, loff_t *ppos){ return st16c554_ComWrite(buf,count,&st0E); }static int ST0E_release(struct inode *inode, struct file *filp){ int nRet = 0; MOD_DEC_USE_COUNT; return nRet;}static int ST0F_open(struct inode *inode, struct file *filp){ int nRet = 0; MOD_INC_USE_COUNT; return nRet;}static int ST0F_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg){ int nRet = 0; switch(cmd) { case ST_INIT: copy_from_user(&st0F_init, (struct tagST_INIT *)arg, sizeof(struct tagST_INIT)); Init_ST0F(st0F_init.nBaud, st0F_init.byMode); break; default: return -EINVAL; } return nRet;}static int ST0F_read(struct file *filp, char *buf, size_t count, loff_t *ppos){ int i; int nLen; unsigned char abyRecv[ST_RECV_LEN]; nLen = get_ST0F_rxLen(); nLen = nLen>count ? count : nLen; for(i=0; i<nLen; i++){ abyRecv[i] = st0F.abyRecvData[st0F.sRecvHead]; if(st0F.sRecvHead != st0F.sRecvTail){ st0F.sRecvHead++; st0F.sRecvHead %= ST_RECV_LEN; } else break; } copy_to_user((void *)buf, &abyRecv, i); return i;}static int ST0F_write (struct file *file, const char *buf, size_t count, loff_t *ppos){ return st16c554_ComWrite(buf,count,&st0F);}static int ST0F_release(struct inode *inode, struct file *filp){ int nRet = 0; MOD_DEC_USE_COUNT; return nRet;}static int ST0G_open(struct inode *inode, struct file *filp){ int nRet = 0; MOD_INC_USE_COUNT; return nRet;}static int ST0G_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg){ int nRet = 0; switch(cmd) { case ST_INIT: copy_from_user(&st0G_init, (struct tagST_INIT *)arg, sizeof(struct tagST_INIT)); Init_ST0G(st0G_init.nBaud, st0G_init.byMode); break; default: return -EINVAL; } return nRet;}static int ST0G_read(struct file *filp, char *buf, size_t count, loff_t *ppos){ int i; int nLen; unsigned char abyRecv[ST_RECV_LEN]; nLen = get_ST0G_rxLen(); nLen = nLen>count ? count : nLen; for(i=0; i<nLen; i++){ abyRecv[i] = st0G.abyRecvData[st0G.sRecvHead]; if(st0G.sRecvHead != st0G.sRecvTail){ st0G.sRecvHead++; st0G.sRecvHead %= ST_RECV_LEN; } else break; } copy_to_user((void *)buf, &abyRecv, i); return i;}static int ST0G_write (struct file *file, const char *buf, size_t count, loff_t *ppos){ return st16c554_ComWrite(buf,count,&st0G);}static int ST0G_release(struct inode *inode, struct file *filp){ int nRet = 0; MOD_DEC_USE_COUNT; return nRet;}static int ST0H_open(struct inode *inode, struct file *filp){ int nRet = 0; MOD_INC_USE_COUNT; return nRet;}static int ST0H_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg){ int nRet = 0; switch(cmd) { case ST_INIT: copy_from_user(&st0H_init, (struct tagST_INIT *)arg, sizeof(struct tagST_INIT)); Init_ST0H(st0H_init.nBaud, st0H_init.byMode); break; default: return -EINVAL; } return nRet;}static int ST0H_read(struct file *filp, char *buf, size_t count, loff_t *ppos){ int i; int nLen; unsigned char abyRecv[ST_RECV_LEN]; nLen = get_ST0H_rxLen(); nLen = nLen>count ? count : nLen; for(i=0; i<nLen; i++){ abyRecv[i] = st0H.abyRecvData[st0H.sRecvHead]; if(st0H.sRecvHead != st0H.sRecvTail){ st0H.sRecvHead++; st0H.sRecvHead %= ST_RECV_LEN; } else break;// printk("D-:%02X\n", abyRecv[i]); } copy_to_user((void *)buf, &abyRecv, i); return i;}static int ST0H_write (struct file *file, const char *buf, size_t count, loff_t *ppos){ return st16c554_ComWrite(buf,count,&st0H);}static int ST0H_release(struct inode *inode, struct file *filp){ int nRet = 0; MOD_DEC_USE_COUNT; return nRet;}static struct file_operations st16c554_fops = { owner: THIS_MODULE, open: st16c554_open, ioctl: st16c554_ioctl, read: st16c554_read, release: st16c554_release,};static struct file_operations ST0A_fops = { owner: THIS_MODULE, open: ST0A_open, ioctl: ST0A_ioctl, read: ST0A_read, write: ST0A_write, release: ST0A_release,};static struct file_operations ST0B_fops = { owner: THIS_MODULE, open: ST0B_open, ioctl: ST0B_ioctl, read: ST0B_read, write: ST0B_write, release: ST0B_release,};static struct file_operations ST0C_fops = { owner: THIS_MODULE, open: ST0C_open, ioctl: ST0C_ioctl, read: ST0C_read, write: ST0C_write, release: ST0C_release,};static struct file_operations ST0D_fops = { owner: THIS_MODULE, open: ST0D_open, ioctl: ST0D_ioctl, read: ST0D_read, write: ST0D_write, release: ST0D_release,};static struct file_operations ST0E_fops = { owner: THIS_MODULE, open: ST0E_open, ioctl: ST0E_ioctl, read: ST0E_read, write: ST0E_write, release: ST0E_release,};static struct file_operations ST0F_fops = { owner: THIS_MODULE, open: ST0F_open, ioctl: ST0F_ioctl, read: ST0F_read, write: ST0F_write, release: ST0F_release,};static struct file_operations ST0G_fops = { owner: THIS_MODULE, open: ST0G_open, ioctl: ST0G_ioctl, read: ST0G_read, write: ST0G_write, release: ST0G_release,};static struct file_operations ST0H_fops = { owner: THIS_MODULE, open: ST0H_open, ioctl: ST0H_ioctl, read: ST0H_read, write: ST0H_write, release: ST0H_release,};static devfs_handle_t devfs_st_dir, devfs_ST0A, devfs_ST0B, devfs_ST0C, devfs_ST0D;static devfs_handle_t devfs_ST0E, devfs_ST0F, devfs_ST0G, devfs_ST0H;static int __init st16c554_init(void){ int ret; printk(KERN_INFO "Init ST16C554 ......\n" ); mtdcr(DCRN_EBC0_CFGADDR, DCRN_EBC0_B3CR); printk(KERN_INFO "B3CR1=== %x\n",mfdcr(DCRN_EBC0_CFGDATA) ); mtdcr(DCRN_EBC0_CFGDATA, 0xf0218000); //SET PCS3 BASEADDR printk(KERN_INFO "B3CR2== %x\n",mfdcr(DCRN_EBC0_CFGDATA) ); ret = register_chrdev(DEVICE_MAJOR, DEVICE_NAME, &st16c554_fops); if (ret < 0) { printk(DEVICE_NAME " can't get major number\n"); return ret; } stMajor = ret; devfs_st_dir = devfs_mk_dir(NULL, DEVICE_NAME, NULL); if (devfs_st_dir == NULL) printk( " devfs_mk_dir() error! \n"); devfs_ST0A = devfs_register(devfs_st_dir, "0", DEVFS_FL_DEFAULT, // dev/st16c554/0 for ST0A stMajor, ST0A, S_IFCHR | S_IRUSR | S_IWUSR, &ST0A_fops, NULL); devfs_ST0B = devfs_register(devfs_st_dir, "1", DEVFS_FL_DEFAULT, // dev/st16c554/1 for ST0B stMajor, ST0B, S_IFCHR | S_IRUSR | S_IWUSR, &ST0B_fops, NULL); devfs_ST0C = devfs_register(devfs_st_dir, "2", DEVFS_FL_DEFAULT, // dev/st16c554/2 for ST0C stMajor, ST0C, S_IFCHR | S_IRUSR | S_IWUSR, &ST0C_fops, NULL); devfs_ST0D = devfs_register(devfs_st_dir, "3", DEVFS_FL_DEFAULT, // dev/st16c554/3 for ST0D stMajor, ST0D, S_IFCHR | S_IRUSR | S_IWUSR, &ST0D_fops, NULL); devfs_ST0E = devfs_register(devfs_st_dir, "4", DEVFS_FL_DEFAULT, // dev/st16c554/4 for ST0E stMajor, ST0E, S_IFCHR | S_IRUSR | S_IWUSR, &ST0E_fops, NULL); devfs_ST0F = devfs_register(devfs_st_dir, "5", DEVFS_FL_DEFAULT, // dev/st16c554/5 for ST0F stMajor, ST0F, S_IFCHR | S_IRUSR | S_IWUSR, &ST0F_fops, NULL); devfs_ST0G = devfs_register(devfs_st_dir, "6", DEVFS_FL_DEFAULT, // dev/st16c554/6 for ST0G stMajor, ST0G, S_IFCHR | S_IRUSR | S_IWUSR, &ST0G_fops, NULL); devfs_ST0H = devfs_register(devfs_st_dir, "7", DEVFS_FL_DEFAULT, // dev/st16c554/7 for ST0H stMajor, ST0H, S_IFCHR | S_IRUSR | S_IWUSR, &ST0H_fops, NULL); ret = request_irq(YC_mul232_IRQ0, UART0_interrupt, SA_INTERRUPT, "ST16C554_0_RX Ready", UART0_interrupt); if(ret) { printk("ST16C554: failed to register IRQ_EINT0(%d)\n", YC_mul232_IRQ0); goto UART0_failed; } ret = request_irq(YC_mul232_IRQ1, UART1_interrupt, SA_INTERRUPT, "ST16C554_1_RX Ready", UART1_interrupt); if(ret) { printk("ST16C554: failed to register IRQ_EINT1(%d)\n", YC_mul232_IRQ1); goto UART1_failed; } return 0;UART1_failed: free_irq(YC_mul232_IRQ1, NULL); UART0_failed: printk("ST16C554 DEVICE: failed to register \n"); devfs_unregister(devfs_ST0D); devfs_unregister(devfs_ST0C); devfs_unregister(devfs_ST0B); devfs_unregister(devfs_ST0A); devfs_unregister(devfs_ST0E); devfs_unregister(devfs_ST0F); devfs_unregister(devfs_ST0G); devfs_unregister(devfs_ST0H); devfs_unregister(devfs_st_dir); unregister_chrdev(stMajor, DEVICE_NAME); return 0;}static void __exit st16c554_exit(void){ free_irq(YC_mul232_IRQ0, NULL); free_irq(YC_mul232_IRQ1, NULL); devfs_unregister(devfs_ST0D); devfs_unregister(devfs_ST0C); devfs_unregister(devfs_ST0B); devfs_unregister(devfs_ST0A); devfs_unregister(devfs_ST0E); devfs_unregister(devfs_ST0F); devfs_unregister(devfs_ST0G); devfs_unregister(devfs_ST0H); devfs_unregister(devfs_st_dir); unregister_chrdev(stMajor, DEVICE_NAME); iounmap((void *) (st0A.pbyBase0)); iounmap((void *) (st0B.pbyBase0)); iounmap((void *) (st0C.pbyBase0)); iounmap((void *) (st0D.pbyBase0)); iounmap((void *) (st0E.pbyBase0)); iounmap((void *) (st0F.pbyBase0)); iounmap((void *) (st0G.pbyBase0)); iounmap((void *) (st0H.pbyBase0));}module_init(st16c554_init);module_exit(st16c554_exit);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -