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

📄 u110_bak.c

📁 linux下打印驱动源代码 适用于双步进针打驱动
💻 C
📖 第 1 页 / 共 3 页
字号:
/******************************************************************** *  fcr12-printer/linux-driver/u110.c * *  Arca FCR1.2 platform PRN Driver. (Epson U110) *  Author: Seeger Chin *   Owner: ARCA Technology Corp. *    Date: 2003.08.19 ********************************************************************/#include <linux/config.h>#include <linux/module.h>#include <linux/errno.h>#include <linux/signal.h>#include <linux/sched.h>#include <linux/timer.h>#include <linux/interrupt.h>#include <linux/serial.h>#include <linux/major.h>#include <linux/string.h>#include <linux/fcntl.h>#include <linux/ptrace.h>#include <linux/ioport.h>#include <linux/mm.h>#include <linux/slab.h>#include <linux/init.h>#include <linux/delay.h>#include <linux/fs.h>#include <linux/slab.h>#include <linux/spinlock.h>#include <linux/arca-chars.h>#include <asm/system.h>#include <asm/io.h>#include <asm/irq.h>#include <asm/uaccess.h>#include <asm/bitops.h>#include <asm/processor.h>#include <asm/hardware.h>/******************************************************************* ** ** *******************************************************************/#define PRNIORESET      0x19750000#define PRNIOBLKMARK    0x19750001#define PRNIONEWLINE    0x19750002#define PRNIOPAPERFW    0x19750003#define PRNIOPAPERFB    0x19750004#define PRNIOPOWEROFF	0x19750005#define PRN_TIMER (1 * HZ)#define DEBUG 0#if DEBUG#define dprintk(x...)	if (DEBUG) printk(x)#else#define dprintk(x...)#endif#if defined(CONFIG_ARCA_FCR12_PLATFORM)#define PRN_COIL_REG     0xaf000000#define PRN_CMOTOR_PORT1 0xaf400000#define PRN_CMOTOR_PORT2 0xaf600000#define PRN_PMOTOR_PORT1 0xaf800000#define PRN_PMOTOR_PORT2 0xafa00000#define PRN_STATUS_REG   0xafc00000#define PRN_IRQM_REG     0xafc00000#define STATUS_PMOTOR_READY  (1 << 6)//40H#define STATUS_CMOTOR_READY  (1 << 5)//20H#define STATUS_COIL_READY    (1 << 4)//10H#define STATUS_BLACKMARK     (1 << 3)//08H#define STATUS_PAPER_END     (1 << 2)//04H#define STATUS_HOME_POSITION (1 << 1)//02H#define STATUS_CARRIAGE_HOT  (1 << 0)//01H#ifndef REG8#define REG8(n)          (*(volatile unsigned char *)(n))#endif#define __prn_home_position() (!(REG8(PRN_STATUS_REG) & STATUS_HOME_POSITION))//02H// 当关pf中断时PRN_STATUS_REG=02H,则返回0;其他否则返回1 #define __prn_pmotor_ready()  (REG8(PRN_STATUS_REG) & STATUS_PMOTOR_READY)//恒等于0??????#define __prn_cmotor_ready()  (REG8(PRN_STATUS_REG) & STATUS_CMOTOR_READY)//恒等于0??????#define __prn_coil_ready()    (REG8(PRN_STATUS_REG) & STATUS_COIL_READY)  //10H//恒等于0??????#define __prn_blackmark()     (!(REG8(PRN_STATUS_REG) & STATUS_BLACKMARK)) //08H //恒等于1?????  #define __prn_paper_end()     (!(REG8(PRN_STATUS_REG) & STATUS_PAPER_END)) //04H // 当关cm的data2中断时PRN_STATUS_REG=04H,则返回0;否则返回1  #define __prn_carriage_hot()  (REG8(PRN_STATUS_REG) & STATUS_CARRIAGE_HOT) //01H// 当关cm中断时PRN_STATUS_REG=01H,则返回1;否则返回0static volatile unsigned char prn_irq = 0;static unsigned char old_val=0;   /* For test */static unsigned char tmpp=0;      /* Nick *//* How many steps the c-motor will walk to print the current line. */static volatile int prn_line_max_steps=0;  #define _NEVER_BLOCK    (sigmask(SIGKILL) | sigmask(SIGSTOP))#define _DONT_BLOCK     (_NEVER_BLOCK | sigmask(SIGINT))/******************************************************************* ** ** *******************************************************************/#define __prn_cmotor_irq_mask()			\do {						\	prn_irq |= 0x01;			\/*  |=  位或运算   */	REG8(PRN_STATUS_REG) = prn_irq;		\	udelay(1);				\} while (0)#define __prn_cmotor_irq_unmask()		\do {						\	prn_irq &= ~0x01;			\/*  &=  位与运算  ~位取反运算 */	REG8(PRN_STATUS_REG) = prn_irq;		\	udelay(1);				\} while (0)//CM的data2中断,用于打印时字车超出最大步数时,关CM中断#define __prn_cmotor_data2irq_mask()		\do {						\	prn_irq |= 0x04;			\	REG8(PRN_STATUS_REG) = prn_irq;		\	udelay(1);				\} while (0)#define __prn_cmotor_data2irq_unmask()		\do {						\	prn_irq &= ~0x04;			\	REG8(PRN_STATUS_REG) = prn_irq;		\	udelay(1);				\} while (0)#define __prn_pmotor_irq_mask()			\do {						\	prn_irq |= 0x02;			\	REG8(PRN_STATUS_REG) = prn_irq;		\	udelay(1);				\} while (0)#define __prn_pmotor_irq_unmask()		\do {						\	prn_irq &= ~0x02;			\	REG8(PRN_STATUS_REG) = prn_irq;		\	udelay(1);				\} while (0)#define __prn_irq_mask()			\do {						\	prn_irq |= 0x07;			\	REG8(PRN_STATUS_REG) = prn_irq;		\	udelay(1);				\} while (0)#define __prn_pin_init()			\do {						\	__gpiob_as_intr(7);			\///????????	__gpiob_set_irq_high_level(7);		\	udelay(1);				\} while(0)/******************************************************************* ** ** *******************************************************************/#define PRN_IRQ INTC_IRQ7#else#error "Not supported platform"#endifstatic unsigned char off_i = 0x0c;static unsigned char hold_i = 0x08;static unsigned char prun_i  = 0x00;//给纸电机运行标志static unsigned char crun_i  = 0x00;//字车电机运行标志static volatile unsigned int cmotor_step = 0x80000000; /*volatile 在每次访问时,其值被重载  */static volatile unsigned int pmotor_step = 0x80000000;static volatile unsigned char prn_state;static volatile unsigned char cmotor_direction = 0;static volatile unsigned char pmotor_direction = 0;static volatile unsigned int pmotor_steps;static unsigned char cmotor_const_param = 0;#define PRN_RST0             0x10#define PRN_RST1             0x20#define PRN_STANDBY          0x30#define PRN_BLACKMARK        0x40#define PRN_NEWLINE          0x50#define PRN_PRINTING         0x60#define PRN_PAPERFETCH0      0x70#define PRN_PAPERFETCH1      0x80#define PRN_PAPERFETCH2      0x90 //paperfetch#define MOTOR_STAT_STOP      0x00#define MOTOR_STAT_ACC       0x01#define MOTOR_STAT_CONST     0x02#define MOTOR_STAT_COIL      0x03#define MOTOR_STAT_DEC       0x04#define MOTOR_STAT_WORKRUSH  0x05#define MOTOR_STAT_HOLDRUSH  0x06#define MOTOR_STAT_STEP      0x07#define NPMOTOR              0x01#define NCMOTOR              0x00#define PRN_STATUS()         ((prn_state) & 0xf0)#define MOTOR_STATUS()       (((prn_state) & 0x0f) >> 1)#define MOTOR_NUM()          ((prn_state) & 0x01)#define DATA2INTERUPT()        ((prn_state) & 0x10)#define ENCODE_STATUS(prns, motors, motor)				\do {									\	prn_state = (prns) | ((motors) << 1) | ((motor) & 0x01);	\       //    或运算,根据工作状态,速度状态,字车,成为一个状态标志} while (0)static unsigned char prn_buffer[4096];/******************************************************************* ** ** *******************************************************************/static unsigned char motor_steps[] = { 0x00, 0x02, 0x03, 0x01 };//含义??static unsigned char cmotor_acc[11] = {	58, 28, 22, 19, 17, 16, 15, 15, 14, 13, 12};static unsigned char cmotor_dec[11] = {	12, 13, 13, 14, 15, 17, 18, 21, 25, 32, 78};static unsigned char pmotor_acc[21] = {	82, 54, 42, 35, 31, 28, 26, 24, 23, 21, 20, 19, 19, 18, 17, 17,	16, 16, 15, 15, 15};static unsigned char pmotor_dec[3] = {	15, 20, 29};static volatile unsigned int coil_counter = 0;/******************************************************************* **  For Function defines ** *******************************************************************//* HomePosition function defines */static void arca_prn_hold_rush(void);/* 后rush */static void arca_prn_work_rush(void);/* 前rush */static int arca_prn_home_position(void);/* For Carriage Motor function defines  */static void prn_cmotor_work_rush(unsigned char direction);/* 后rush */static void prn_cmotor_hold_rush(unsigned char direction);/* 前rush */static void prn_cmotor_stop(unsigned char direction);static void prn_cmotor_coil(unsigned char direction);/* 会不会是慢速或失步???? */static void prn_cmotor_acc(unsigned char direction);static void prn_cmotor_dec(unsigned char direction);/* For Page Motor function defines  */static void prn_pmotor_coil(unsigned char direction);static void prn_pmotor_dec(unsigned char direction);static void prn_pmotor_const(unsigned char direction);static void prn_pmotor_stop(unsigned char direction);static void prn_pmotor_step(unsigned char direction);/* Motor state mechanism   */static void prn_decode_motor_state(unsigned char status, unsigned char motor);static void arca_prn_hp_hold(void){	unsigned char port2;	port2 = hold_i | motor_steps[cmotor_step % 4]; //must hold motor state  hold_i = 0x08	while (!__prn_cmotor_ready())  //查询中断方式?		udelay(500);	REG8(PRN_CMOTOR_PORT2) = port2;        udelay (12000);	return;}/***************************************************************** * Used for cmotor const detection用于位置初始化 *****************************************************************/static void prn_cmotor_test_acc(unsigned char direction){	unsigned char port1, port2;	int step = (direction) ? 1 : -1;//正向时 step=1 反向时 step=-1	int i;	arca_prn_work_rush();  //open power for motor 启动6ms rush	for (i=0;i<11;i++) {        //加速11步		cmotor_step += step;//加速步自增		port1 = cmotor_acc[i];//给加速时间		port2 = crun_i | motor_steps[cmotor_step % 4];		while (!__prn_cmotor_ready())			udelay(500);		REG8(PRN_CMOTOR_PORT1) = port1;		REG8(PRN_CMOTOR_PORT2) = port2;	}}static int prn_cmotor_test_const(int steps, unsigned char direction,			       unsigned char test){	unsigned char port1, port2;	//direction=1为反向从右到左	int step = (direction) ? 1 : -1;//direction=0为正向从左到右	int i;//一旦	for (i=0;i<steps;i++) {		if ((test == 1) && (__prn_home_position()))		//test=1且HPS为H时			return i;		else if ((test == 2) && (!__prn_home_position()))	//test=2且HPS为L时				return i;                               //若test=0则返回最大步数				cmotor_step += step;		port1 = 12;		port2 = crun_i | motor_steps[cmotor_step % 4];		while (!__prn_cmotor_ready())			udelay(500);		REG8(PRN_CMOTOR_PORT1) = port1;		REG8(PRN_CMOTOR_PORT2) = port2;	}	return steps;			}static void prn_cmotor_test_dec(unsigned char direction){	unsigned char port1, port2;	int step = (direction) ? 1 : -1;	int i;	for (i=0;i<11;i++) {		cmotor_step += step;		port1 = cmotor_dec[i];		port2 = crun_i | motor_steps[cmotor_step % 4];		while (!__prn_cmotor_ready())			udelay(500);		REG8(PRN_CMOTOR_PORT1) = port1;		REG8(PRN_CMOTOR_PORT2) = port2;	}	arca_prn_hold_rush();	arca_prn_hp_hold();	return;}/******************************************************************* ** ** *******************************************************************/static void arca_prn_hold_rush(void){	unsigned char port2;	port2 = crun_i | motor_steps[cmotor_step % 4]; //must hold motor state	while (!__prn_cmotor_ready())		udelay(500);	REG8(PRN_CMOTOR_PORT2) = port2;        udelay (6000);	return;}/******************************************************************* ** ** *******************************************************************/static void arca_prn_work_rush(void){	unsigned char port2;	port2 = crun_i | motor_steps[cmotor_step % 4];  //must hold motor state	while (!__prn_cmotor_ready())		udelay(500);	REG8(PRN_CMOTOR_PORT2) = port2;        udelay (6000);	return;}/******************************************************************* ** ** *******************************************************************/static int arca_prn_home_position(void){	int r=0;	if (!__prn_home_position()) {		prn_cmotor_test_acc(1);		r = prn_cmotor_test_const(230, 1, 1);		prn_cmotor_test_dec(1);			}	prn_cmotor_test_acc(0);	prn_cmotor_test_const(29, 0, 2);	prn_cmotor_test_const(29, 0, 0);	prn_cmotor_test_dec(0);	prn_cmotor_test_acc(1);	r = prn_cmotor_test_const(50, 1, 1);	prn_cmotor_test_dec(1);	if (r == 50) {		printk ("Error: motor can not reset home position!\n");		return -EIO;	}	cmotor_const_param = 3;	printk("cmotor const parameter = %d\n", cmotor_const_param);	return 0;}/* * Two motor's primitives. */                    DECLARE_WAIT_QUEUE_HEAD (prn_wait_queue);/******************************************************************* ** ** *******************************************************************/static volatile unsigned char cstep_const = 0;static void prn_cmotor_const(unsigned char direction){	unsigned char port1 = 12;	unsigned char port2;	int step = (direction) ? 1 : -1;	cmotor_step += step;	port2 = crun_i | motor_steps[cmotor_step % 4];	REG8(PRN_CMOTOR_PORT1) = port1;	REG8(PRN_CMOTOR_PORT2) = port2;

⌨️ 快捷键说明

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