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

📄 fs44b0mu110.c

📁 uClinux基于S3C44B0X打印机驱动
💻 C
📖 第 1 页 / 共 4 页
字号:

#include <linux/version.h>
#include <linux/kernel.h>     /* We're doing kernel work */
#include <linux/module.h>     /* Specifically, a module */ 
#include <linux/interrupt.h>  /* We want interrupts */

#include <linux/miscdevice.h> /* for misc_register() and misc_deregister() */

#include <linux/fs.h>         /* for struct 'file_operations' */

#include <linux/timer.h>     /* for timeout interrupts */
#include <linux/param.h>     /* for HZ. HZ = 100 and the timer step is 1/100 */
#include <linux/sched.h>     /* for jiffies definition. jiffies is incremented
                              * once for each clock tick; thus it's incremented
			      * HZ times per secondes.*/
#include <linux/fs44b0mu110.h>
#include <linux/mm.h>        /* for verify_area */
#include <linux/types.h>
#include <linux/slab.h>
#include <linux/sched.h>
#include <linux/init.h>

#include <asm/irq.h>         /* For IRQ_MACHSPEC */
#include <asm/io.h>
#include <asm/uaccess.h>

#include <asm/arch/irqs.h>
#include <asm/arch/hardware.h>
#include <asm/arch/44b.h>
#include <asm/arch/def.h>
//#include <asm/arch/board.h>
//#include <asm/arch/config.h>

#include "font.h"
//#include "hzk16.h"
//#include <asm/arch/utils.h>

static const char* __file__ = __FILE__;

#ifdef CONFIG_DEVFS_FS 
	static devfs_handle_t devfs_mu110_dir,devfs_mu110raw;
#endif

#define MU110_MAJOR   126
#define MU110_MINOR   0
#define DEVICE_NAME    "s3c44b0mu110"

#define	PF_Phase0	      (1<<1)
#define	PF_Phase1				(1<<0)
#define	PF_I0		  			(1<<3)
#define	PF_I1		  			(1<<2)



#define	CR_Phase0				(1<<5)
#define	CR_Phase1				(1<<4)
#define	CR_I0		  			(1<<7)
#define	CR_I1		  			(1<<6)

#define	PF_MOTOR				0X01
#define	CR_MOTOR				0X02
#define	ALL_MOTOR				0X03

#define	NORMAL_CURRENT	0X01
#define	HOLD_CURRENT		0X02
#define	MID_CURRENT			0x03

#define	HEAD_TEMP_CHECK		(1<<0)
#define	HOME_CHECK				(1<<4)
#define	BLACK_MARK_CHECK	(1<<7)
#define	PAPE_CHECK				(1<<2)

#define	CR_MAX_STEP				242		//0-241
#define	FONT_HZ16					0x01
#define	FONT_ASC79				0X02
#define	FONT_ASC88				0x03
#define	FONT_ASC816				0x04


#define 	mHZK16_ADDR 	0x300000
#define 	mHZK12_ADDR 	0x350000

#define   init_timeout    0x500
static U8	 *g_auc_HZK16_Dot;

static int mu110_device_open ;
struct MU110_status printer_ststus;
int state;
u8	M110_Motor_Status=0;
u16	PrintLen =0;	//打印缓冲区中数据长度
extern	const unsigned char ASC_font[];
extern  const unsigned char Asc79[];
extern	const unsigned char g_auc_ASCII_Dot[];

//extern	const unsigned char HZK16[];

static signed char	GoHomePosition(void);


static u8	PrintBuf[2][16*26];
             //static u8 PrintBuf[32*26];	//打印缓冲区 ,最大支持每行26个汉字,42个ASCII,混合缓冲区
						//打印过程:打印之前,先对欲打印内容(汉字+ASCII混合)做预处理
						//即,取模并进行转换,然后按打印先后顺序放到打印缓冲区,并且确定打印
						 // 长度。
						//打印时,不再区分汉字和ASCII,一律按汉字方式对待,打印两次
						//分别打印奇数点和偶数点,ASCII字符只在第一次打印,第二次全部为空
						//
					
//u8	*DestFont16[13*32];
//static u8	*PrintBuf	;
static u8	*DestFont16;
static u8  *print_img;
#define PrintBuf_len  32*26
#define DestFont16_len 13*32 

static u8		CR_Step = 120;		// 0-241
static u16		PF_A_Step = 0, PF_B_Step = 0;

static u16 Right_limit = 0;
static u8   ram_spack;
static const u16	PF_Acceleration[14] = {
	
	7000,
	3880,
	2980,
	2510,
	2210,
	2000,
	1840,
	1710,
	1610,
	1520,
	1450,
	1380,
	1330,
	1280
	
};

static const 	u16	PF_ConstSpeed = 1250;

static const	u16	PF_Deceleration[2] = {

	1670,
	
	2500
};
static const	u16	PF_Lash = 7000;

static const	u16	CR_Acc_A[11] = {
	
	4900,
	2200,
	1690,
	1420,
	1250,
	1130,
	1040,
	970,
	910,
	860,
	860
	
};
	
static const	u16	CR_ConstSpeed = 826;
static const	u16	CR_Dec_A[12] = {
	826,
	826,
	860,
	820,
	1000,
	1090,
	1200,
	1350,
	1560,
	1890,
	2530,
	6000
};
static const	u16	CR_Lash = 7000;

static const	u16	CR_Acc_B[8] = {

	4900,
	1920,
	1470,
	1240,
	1090,
	990,
	910,
	850
	
};

static const	u16	CR_Dec_B[12] = {

	826,
	826,
	860,
	920,
	1000,
	1090,
	1200,
	1350,
	1560,
	1890,
	2530,
	6000
};


//*******************************************************
//*******************************************************
static void mu110_port_init(void)
{
		u_int32_t tmod;
		tmod = inl(S3C44B0X_PCONF);
		tmod &= ~(0x03<<4);   //GPF2 input
		outl(tmod,S3C44B0X_PCONF);
		
		outl(inl(S3C44B0X_PUPF)& 0xfd,S3C44B0X_PUPF); //Enable pull up
		
		tmod = inl(S3C44B0X_PCONG);
		tmod &= ~(0x03<<0);   //GPG0 input
		tmod &= ~(0x03<<8);   //GPG4 input
		tmod &= ~(0x03<<14);  //GPG7 input 
		outl(tmod,S3C44B0X_PCONG);
		outl(inl(S3C44B0X_PUPG)& 0xae,S3C44B0X_PUPG);	
		CPLD_M110_PrintTrigger_Addr = 0X05;	// low				
}
//功能:
//		1)把标准字库的横向字模改为纵向字模
//		2)按奇数点和偶数点把原来字模进行拆分处理
static void	PreHZ(u8	*sFontStr, u8 *dFontStr)
{
	u8	i,c1[9],j,tmp,k;
	// 
	for (k=0; k<4; k++)
	{
		memset (c1, 0x00, 9);	
		for (i = 0; i<8; i++)
		{
			c1[i] = *(sFontStr+i*4+k);			
		}
		for (i=0; i<8; i++)
		{			
			tmp = 0;
			for (j=0; j<8; j++)
			{
				if (c1[j] & (1<<(7-i)))
				{
					tmp = tmp + (1<<j);
				}	
			}
			*(dFontStr+i + k*8) = ~tmp;
		}
	}		
}

//功能:把字模(汉字或ASCII)放入打印缓冲区
static void	PreFont(u8	FontType,u16	pos, u8 *ZiMo)
{
	if (FontType == FONT_HZ16)
	{ // HZ
		memcpy(&PrintBuf[0][pos], ZiMo, 16);
		memcpy(&PrintBuf[1][pos], ZiMo+16, 16);
	}
	else
	{ // ASCII
		memcpy(&PrintBuf[0][pos], ZiMo, 10);
		memset(&PrintBuf[1][pos], 0xff, 10);	
	}
}
//********************************************************
//********************************************************
static void	Mdelay2US(void)
{	// about 1us	//61MHz
	int i;
	for(i = 0; i < 59; i++);//33 101
}
//********************************************************
//********************************************************
static void	Mdelay5US(void)
{
	int i;
	for(i = 0; i < 142; i++);//79 101
}
//********************************************************
//********************************************************
static void	Mdelay10US(void)
{
	int i;
	for(i = 0 ; i < 279; i++);//155 101
}
//********************************************************
//********************************************************
static void	Mdelay20US(void)
{
	int i;
	for(i = 0; i < 552; i++);//307 101
}
//********************************************************
//********************************************************
static void	Mdelay50US(void)
{
	int i;
	for(i = 0; i < 1386; i++);//770 101
}
//********************************************************
//********************************************************
static void	Mdelay67US(void)
{
	int i;
	for(i = 0; i < 1857; i++);//770 101
}
//********************************************************
//********************************************************
static void	Mdelay100US(void)
{
	int i;
	for(i = 0; i < 2736; i++);//1520  199us
}
//********************************************************
//********************************************************
static void	Mdelay200US(void)
{
	int i;
	for(i = 0; i < 5472; i++);//1520  199us
}
//********************************************************
//********************************************************
static void	Mdelay194US(void)
{
	int i;
	for(i = 0; i < 5307; i++);//1520  199us
}
//********************************************************
//********************************************************
static void	Mdelay216US(void)
{
	int i;
	for(i = 0; i < 5909; i++);//1520  199us
}
//********************************************************
//********************************************************
static void	Mdelay300US(void)
{
	int i;
	for(i = 0; i < 8207; i++);//1520  199us
}
//********************************************************
//********************************************************
static void	Mdelay526US(void)
{
	int i;
	for(i = 0; i < 14436; i++);//1520  199us
}
//********************************************************
//********************************************************
static void	Mdelay626US(void)
{
	int i;
	for(i = 0; i < 17180; i++);//1520  199us
}
//********************************************************
//********************************************************
static void	Mdelay1MS(U32	time)
{	// about 1Ms	//40MHz

	U32	m;
	int i;
		
	for(m=0; m<time;m++)
	{
		for(i = 0;i < 27450; i++);//15250  199us
	}
}
//********************************************************
//********************************************************
static void	Mdelay826US(void)
{	// about 1Ms	//40MHz
  int i;
	for(i = 0; i < 22712; i++);//12593 
}
//********************************************************
//********************************************************
static void	Mdelay413US(void)
{	// about 1Ms	//40MHz
  int i;
	for(i = 0; i < 11335; i++);//6290  
}
//********************************************************
//********************************************************
static void	Mdelay346US(void)
{	// about 1Ms	//40MHz
  int i;
	for(i = 0; i < 9495; i++);//6290  
}
//********************************************************
//********************************************************
static void	Mdelay100us(u8	n)
{
	u8	i;	
	for (i = 0; i < n; i++)
	{
		Mdelay100US();	
	}
}
//********************************************************
//********************************************************
static void	MdelayTime(u16 nUs)
{
	u16	n=0;
	
	n = nUs/1000;
	Mdelay1MS(n);
	
	n = (nUs%1000)/100;
	Mdelay100us(n);
	n = (nUs%100)/10;
	switch(n)
	{	
		case	1:
			Mdelay10US();
			break;	
		case	2:
			Mdelay20US();
			break;	
		case	3:
			Mdelay20US();
			Mdelay10US();						
			break;	
		case	4:
			Mdelay20US();
			Mdelay20US();					
			break;	
		case	5:
			Mdelay50US();
			break;	
		case	6:
			Mdelay50US();
			Mdelay10US();			
			break;	
		case	7:
			Mdelay50US();
			Mdelay20US();			
			break;	
		case	8:
			Mdelay50US();
			Mdelay20US();
			Mdelay10US();			
			break;						
		case	9:
			Mdelay50US();
			Mdelay20US();
			Mdelay20US();	
			break;	
	}
	n = nUs%10;
	if(n>5)
	{
		Mdelay5US();
		Mdelay2US();
	}
	else
		Mdelay2US();
}
//********************************************************
// Function:	Cut off the motor power
//********************************************************
static void	Motor_Off(u8	Type)
{
	if (Type == PF_MOTOR)
	{
		M110_Motor_Status = M110_Motor_Status |(PF_I1 | PF_I0);
	}
	else if (Type == CR_MOTOR)
	{
		M110_Motor_Status = M110_Motor_Status |(CR_I1 | CR_I0);
	}
	else
	{// ALL Motor off
		M110_Motor_Status = M110_Motor_Status |(CR_I1 | CR_I0|PF_I1 | PF_I0);	
	}
	CPLD_M110_Motor_Addr = M110_Motor_Status;
}
//********************************************************
//********************************************************
static void	SetWorkCurrent(u8	Type,u8	Mode)
{
	if (Type == PF_MOTOR)
	{
		switch(Mode)
		{
			case	NORMAL_CURRENT:
				M110_Motor_Status = M110_Motor_Status & (~(PF_I1 |PF_I0));
				break;
			case	HOLD_CURRENT:
				M110_Motor_Status = (M110_Motor_Status & (~PF_I0)) |PF_I1;
				break;				
			case	MID_CURRENT:
				M110_Motor_Status = (M110_Motor_Status & (~PF_I1)) |PF_I0;
				break;		
		}
	}
	else if (Type == CR_MOTOR)
	{
			switch(Mode)
			{
				case	NORMAL_CURRENT:
					M110_Motor_Status = M110_Motor_Status & (~(CR_I1 |CR_I0));
					break;
				case	HOLD_CURRENT:

⌨️ 快捷键说明

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