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

📄 at2042_inf.c.bak

📁 这个是Linux下的关于2042的程序
💻 BAK
📖 第 1 页 / 共 4 页
字号:
/*
 *  Copyright(C) 2004, Pentamicro Inc. All Right Reserved.           
 *                                      
 *  Filename    :  at2041_inf.c
 *  Description :  Linux device driver of AT2041
 *                     
 *  Project     :  MPEG-4 4-channel SDVR
 *                             
 *  Date        :  Apr., 20. 2004.
 *  Company     :  Advanced Technology R&D Center
 *                 Pentamicro Inc.
 *   
 *  Linux version      :  
 */            
 

/** ************************************************************************* ** 
 ** includes
 ** ************************************************************************* **/
#include <linux/config.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/vmalloc.h>
#include <linux/init.h>
#include <linux/ioctl.h>
#include <linux/major.h>
#include <linux/delay.h>
#include <asm/errno.h>
#include <asm/irq.h>
#include <asm/uaccess.h>
#include <asm/io.h>
#include <asm/delay.h>


#include "at2041_inf.h"

#include <asm/irq.h>		/*netbsd*/	
#include <asm/arch/s3c2410.h>	/*netbsd*/
#include <asm/arch/io.h>

#include <asm/semaphore.h>		/*netbsd*/

#define printk_netbsd(args...) {printk(args);}
#define printk_netbsd2(args...) {}

unsigned short *mux_buf[MAX_BUF_NUM];
unsigned short *demux_buf[MAX_BUF_NUM];

#define 	__EXT_CODE__		/*2005-03-09 netbsd*/		
#ifdef 	__EXT_CODE__		/*2005-03-09 netbsd*/		
unsigned short *ext_mux_buf[MAX_BUF_NUM];
unsigned short *ext_demux_buf[MAX_BUF_NUM];
#endif

// pentamicro 2005.07.28
#define STC_UP_CONTROL

/*2005-03-09 netbsd*/
#define HIGH_QUALITY	4
#define HIGH_RATE		170

unsigned short *      tx_buf[MAX_TXBUF_NUM];

/*netbsd*/
//unsigned short *      size_buf[MAX_BUF_NUM];
unsigned int 	*size_buf[MAX_BUF_NUM];
unsigned int 	demux_size_buf[MAX_BUF_NUM];
unsigned short        enc_txmsg_size = 4;

#if 0		/*netbsd*/
volatile static unsigned short mux_ring_cnt = 0;
volatile static unsigned short mux_rd_cnt = 0;
volatile static unsigned short mux_wr_cnt = 0; 
volatile static unsigned short mux_full = 0;

volatile static unsigned short demux_ring_cnt = 0;
volatile static unsigned short demux_rd_cnt = 0;
volatile static unsigned short demux_wr_cnt = 0; 
//volatile static unsigned short demux_empty = 0;
#else
#define 	INIT_CNT	(0x00000000)
#define 	MAX_CNT	(0xfffffff0)
volatile unsigned long mux_ring_cnt = INIT_CNT;
volatile unsigned long mux_rd_cnt = INIT_CNT;
volatile unsigned long mux_wr_cnt = INIT_CNT; 
volatile unsigned long mux_full = INIT_CNT;

volatile unsigned long demux_ring_cnt = INIT_CNT;
volatile unsigned long demux_rd_cnt = INIT_CNT;
volatile unsigned long demux_wr_cnt = INIT_CNT; 
#endif

volatile static unsigned short txfifo_rd_cnt = 0;
volatile static unsigned short txfifo_wr_cnt = 0;
volatile static unsigned short txfifo_ring_cnt = 0;

static struct semaphore muxfifo_read_sem;
static struct semaphore demuxfifo_write_sem;

volatile unsigned short *fifo_reg;

//volatile unsigned int ii;

static int PAL_NTSC=NTSC;

// pentamicro 2005.07.28
#ifdef STC_UP_CONTROL
int stc_up_flag= 0;
unsigned int stc_update_count= 0;
#endif

#if 0		/*JMP 2005-01-10 netbsd*/
typedef struct __AT2042_CUR__{
	int RATE_CNT;
	int BIT_RATE;
	int QUALITY;
	int RESOL;
	int ENC_OPT;	
}AT2042_CUR;
static AT2042_CUR at2042_cur;
#endif

typedef enum {
	RES_MODE_CIF,
	RES_MODE_DI
} RES_MODE;

#define AT2042_DELAY(x)		udelay(x)

static void do_mw32 ( _SET_REG_STR_  mw32_str)		/*netbsd*/
{
	volatile unsigned int cmd_cnt=0;
	
	for (cmd_cnt=0;cmd_cnt<mw32_str.cmd_num+1;cmd_cnt++) {
		*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = mw32_str.value[cmd_cnt];
	}
	
	return ;
}

void at2041_ioctl_init() 
{
	volatile int count;
	volatile unsigned short status, temp;
	
	/* check tx fifo empty */
	printk_netbsd("at2041_ioctl_init_0\n");
	
	count = 0;

	do {
		status = *((unsigned short *)((unsigned int)fifo_reg + AT2041_STATUS_REG));
		count ++;
		AT2042_DELAY(10);
	} while ((status & 0x100) && (count < 1000));

	if (count == 1000) {
		printk_netbsd("AT2041_STATUS_REG : 0x%x\n", status);
	} 
	else {		
		printk_netbsd("AT2041_STATUS_REG : 0x%x\n", status);

		/* data read from Tx_FIFO of the AT2041 */
		temp = *((unsigned short *)((unsigned int)fifo_reg + AT2041_TX_FIFO));

		if (temp != 0x8003) {
			printk_netbsd("AT2041_TX_FIFO : 0x%x\n", temp);
			return;		
		}
		else {
			printk_netbsd("AT2041_TX_FIFO : 0x%x\n", temp);
		}
		
		/* TxACK command */
		*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 0x8003;
	}

	printk_netbsd("at2041_ioctl_init_1\n");

}

void  pre_enc_config(void) // dec part(1) (set video output)
{
	volatile unsigned short id_conf;
	
	printk_netbsd ("pre_enc_config started\n"); /*netbsd*/

// pentamicro 2005.07.28
#if 0
	/*Global parameter */
	id_conf= RxID(GID_GLOBAL, 0x00, 0x02, W_FLAG);		
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = id_conf;
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 2;
	
	id_conf= RxID(GID_GLOBAL, 0x00, 0x03, W_FLAG);		
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = id_conf;
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 128;
		
	id_conf= RxID(GID_GLOBAL, 0x00, 0x05, W_FLAG);		
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = id_conf;
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 1;
		
	id_conf= RxID(GID_GLOBAL, 0x00, 0x06, W_FLAG);		
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = id_conf;
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 3;
#endif	
	
	/* Normal embbedded sync */
	id_conf= RxID(GID_ENC_VIDEO, 0x00, 0x03, W_FLAG);		
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = id_conf;
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 0;

	/* maximum output data size */
	id_conf = RxID(GID_ENCODER, 0, 0x05, W_FLAG);	
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = id_conf;
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 512;

	/* Rate Control Mode : CBR ==> VBR */
	id_conf = RxID(GID_ENC_VIDEO_CH, 0x00, 0x04, W_FLAG);		
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = id_conf;
// pentamicro 2005.07.28
//	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 1; /*0:VBR  1~2:CBR*/
printk("[swpark:at2042-dd : now in setting cbr mode2\n");
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 2; /*0:VBR  1~2:CBR*/
	
	id_conf = RxID(GID_ENC_VIDEO_CH, 0, 0x03, W_FLAG);	
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = id_conf;
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 4;	//MPEG4

	/* Rate Control Parameter Setting */
	id_conf = RxID(GID_ENC_VIDEO_CH, 0x00, 0x06, W_FLAG);	
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = id_conf;
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = (1024/30);

	/* Quality Setting */
	id_conf = RxID(GID_ENC_VIDEO_CH, 0x00, 0x05, W_FLAG);	// set channel 1 
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = id_conf;
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 5;	

	/* GOP Structure : 0x07 */
	id_conf = RxID(GID_ENC_VIDEO_CH, 0x00, 0x07, W_FLAG);
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = id_conf;
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 1; // closed gop
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 15; // n/m	//IPPPPP
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 1; // m	

	/* Encoding Region Information : 0x23 */
	id_conf = RxID(GID_ENC_VIDEO_CH,0x00, 0x23, W_FLAG);
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = id_conf;
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 0; // hor offset(must be 0)
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 0;// ver offset(must be 0)
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = (720>>4); // hor mb	
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = (480>>4);	// ver mb
	
	/* Output video format NTSC */
	id_conf = RxID(GID_DEC_VIDEO, 0x00, 0x01, W_FLAG);		
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = id_conf;
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = NTSC;

	/* Input Video Format : 0x01 */
	id_conf = RxID(GID_ENC_VIDEO, 0x00, 0x01, W_FLAG);
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = id_conf;
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 720; // hor_size
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 480; // ver_size
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 4;  	// video_input_rate	// video_input_rate 30000/10001
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 0;	// field_mode (d1=>interlaced '0')
	
	/*Encoding video size*/
	id_conf = RxID(GID_ENC_VIDEO_CH, 0x00, 0x22, W_FLAG);
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = id_conf;
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 2;
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 1;

	id_conf = RxID(GID_ENC_VIDEO_CH, 0x00, 0x23, W_FLAG);
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = id_conf;
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 0;
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 0;
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 22;
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 15;

	/* Display ON/OFF */
	id_conf = RxID(GID_DEC_VIDEO_CH, 0, 0x04, W_FLAG);	
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = id_conf;
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 4;

	/* Live ON/OFF */
	id_conf = RxID(GID_DEC_VIDEO, 0, 0x1e, W_FLAG);	
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = id_conf;
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 1;	/*Not 2*/

	/* Zoom in */
	id_conf = RxID(GID_DEC_VIDEO, 0, 0x10, W_FLAG);	
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = id_conf;
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 3;

#if 1
	/*20041004_1*/
 	/*adds "reference picture selection" function for network camera application*/
    	/*GID=4,CID=0,PID=0x11*/
      	/*Data0[0]*/
      	/*0 : Last I/P-Picture Reference mode (default, ISO standard)*/
      	/*1 : I-Picture Reference mode (non ISO standard)*/
	id_conf = RxID(GID_ENC_VIDEO, 0, 0x11, W_FLAG);	
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = id_conf;
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 1;
	printk_netbsd ("[I-Picture Reference mode]\n"); 
#endif	

	printk_netbsd ("pre_enc_config end\n");
	AT2042_DELAY(100000);
}

static  void set_cbr (unsigned short cbr)
{
	volatile unsigned short id_conf;
	volatile unsigned short CBR_RATE=1024;
	
	//if (cbr>=1023) CBR_RATE=1023;
	if (cbr>=HIGH_RATE) CBR_RATE=HIGH_RATE;
	else if (cbr<=1) CBR_RATE=1;
	else CBR_RATE=cbr;
	id_conf = RxID(GID_ENC_VIDEO_CH, 0x00, 0x06, W_FLAG);	
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = id_conf;
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = CBR_RATE;
	
	printk_netbsd ("[CBR_RATE : %d Kbps]\n" , CBR_RATE*30); 
	return ;
}

static  void set_quality (unsigned short quality)
{
	volatile unsigned short id_conf;
	volatile unsigned short QUATLITY=5;
	
	if (quality>=31) QUATLITY=31;
	else if (quality<=HIGH_QUALITY) QUATLITY=HIGH_QUALITY;
	else QUATLITY=quality;
	id_conf = RxID(GID_ENC_VIDEO_CH, 0x00, 0x05, W_FLAG);	
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = id_conf;
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = QUATLITY;
	
	printk_netbsd ("[VBR_QUALITY : %d ]\n" , QUATLITY); 
	return ;
}

#define MAX_FRAME_IPB		15

static  void set_enc_opt (unsigned short opt)
{
	volatile unsigned short id_conf;
	volatile unsigned short OPT=1;
	
	/*20041004_1*/
 	/*adds "reference picture selection" function for network camera application*/
    	/*GID=4,CID=0,PID=0x11*/
      	/*Data0[0]*/
      	/*0 : Last I/P-Picture Reference mode (default, ISO standard)*/
      	/*1 : I-Picture Reference mode (non ISO standard)*/
	
	if (opt<=0) {
		OPT=0;
		/* GOP Structure : 0x07 */
		id_conf = RxID(GID_ENC_VIDEO_CH, 0x00, 0x07, W_FLAG);
		*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = id_conf;
		*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 1;		// closed gop
		*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = MAX_FRAME_IPB;		// n/m	//IP
		*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 1;		// m
		printk_netbsd ("[I-Picture Reference mode OFF]\n");
	}
	else {
		OPT=1;
		/* GOP Structure : 0x07 */
		id_conf = RxID(GID_ENC_VIDEO_CH, 0x00, 0x07, W_FLAG);
		*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = id_conf;
		*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 1;		// closed gop
		*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = MAX_FRAME_IPB;		// n/m	//IP
		*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 1;		// m
		printk_netbsd ("[I-Picture Reference mode ON]\n"); 
	}
	
	id_conf = RxID(GID_ENC_VIDEO, 0x00, 0x11, W_FLAG);	
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = id_conf;
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = OPT;
	
	return ;
}

static  void set_enc_mode (unsigned short mode)
{
	volatile unsigned short id_conf;
	volatile unsigned short MODE=1;
	
	if (mode<=0) {
		MODE=0;
		printk_netbsd ("[ENC_MODE : VBR]\n"); 
	}
	else {
// pentamicro 2005.07.28
//		MODE=1;
		MODE= 2;
		printk_netbsd ("[ENC_MODE : CBR]\n"); 
	}
	/* Rate Control Mode : CBR : VBR */
	id_conf = RxID(GID_ENC_VIDEO_CH, 0x00, 0x04, W_FLAG);		
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = id_conf;
	*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = MODE;	//0:VBR  1~2:CBR
	
	return ;
}

/*2005-02-24 netbsd*/
//#define __PIP__
/* 2005-04-07 netbsd */
//#define __VIDEO_OUT_EXTERNAL_SYNC__	1
//#define __ZOOM_IN__	1
#ifndef __ZOOM_IN__	

⌨️ 快捷键说明

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