📄 at2042_inf-old.c
字号:
/*
* 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>
unsigned short * mux_buf[MAX_BUF_NUM];
unsigned short * demux_buf[MAX_BUF_NUM];
unsigned short * tx_buf[MAX_TXBUF_NUM];
unsigned short * size_buf[MAX_BUF_NUM];
unsigned int demux_size_buf[MAX_BUF_NUM];
volatile unsigned short enc_txmsg_size = 4;
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 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;
#if 0 /*JMP 2005-01-10*/
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 VIDEO_ONLY 0x0001 /*VIDEO ENC/DEC*/
//#define AUDIO_ONLY 0x0002 /*AUDIO ENC/DEC*/
#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];
//printk ("do_mw32 : 0x%08x, 0x%08x\n", reg_ad, reg_val); /*netbsd*/
}
return ;
}
void at2041_ioctl_init()
{
volatile int count;
volatile unsigned short status, temp;
/* check tx fifo empty */
printk("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("AT2041_STATUS_REG : 0x%x\n", status);
}
else {
printk("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("AT2041_TX_FIFO : 0x%x\n", temp);
return;
}
else {
printk("AT2041_TX_FIFO : 0x%x\n", temp);
}
/* TxACK command */
*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 0x8003;
}
printk("at2041_ioctl_init_1\n");
}
void pre_enc_config(void) // dec part(1) (set video output)
{
volatile unsigned short id_conf;
printk ("pre_enc_config started\n"); /*netbsd*/
/*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;
/* 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;
*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 1; /*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 ("[I-Picture Reference mode]\n");
#endif
printk ("pre_enc_config end\n"); /*netbsd*/
AT2042_DELAY(100000);
}
static void set_cbr (unsigned short cbr)
{
volatile unsigned short id_conf;
volatile unsigned short CBR_RATE=1024;
#ifdef VIDEO_ONLY
id_conf = RxID(GID_ENCODER, 0x00, 0x03, W_FLAG);
*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = id_conf;
*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = VIDEO_ONLY;
#endif
AT2042_DELAY(100000);
//if (cbr>=1023) CBR_RATE=1023;
if (cbr>=150) CBR_RATE=150;
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;
AT2042_DELAY(100000);
#ifdef VIDEO_ONLY
id_conf = RxID(GID_ENCODER, 0x00, 0x02, W_FLAG);
*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = id_conf;
*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = VIDEO_ONLY;
#endif
printk ("[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;
#ifdef VIDEO_ONLY
id_conf = RxID(GID_ENCODER, 0x00, 0x03, W_FLAG);
*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = id_conf;
*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = VIDEO_ONLY;
#endif
AT2042_DELAY(100000);
if (quality>=31) QUATLITY=31;
else if (quality<=3) QUATLITY=3;
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;
AT2042_DELAY(100000);
#ifdef VIDEO_ONLY
id_conf = RxID(GID_ENCODER, 0x00, 0x02, W_FLAG);
*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = id_conf;
*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = VIDEO_ONLY;
#endif
printk ("[VBR_QUALITY : %d ]\n" , QUATLITY);
return ;
}
#define MAX_FRAME_IPB 15
static void set_enc_opt (unsigned short opt)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -