📄 at2042_inf.c.bak
字号:
default :
break;
}
return 0;
}
volatile unsigned long MXV=0;
volatile unsigned long MXA=0;
unsigned long DXV=0;
unsigned long DXA=0;
/*2005-03-09 entbsd*/
#if 1
volatile unsigned long MXJ=0;
unsigned long DXJ=0;
#endif
static ssize_t muxfifo_read(struct file *file, char *buffer,size_t length,loff_t * offset)
{
/* copy mux_buf to user space */
/* real transfer size is size_buf[mux_rd_cnt] * 256bit.
* third parameter of copy_to_user() is the 'byte' number to transfer
* so, it's calculated size_buf[mux_rd_cnt] * 32
*/
volatile unsigned int size;
/*2005-02-14 netbsd*/
volatile unsigned long MUX_RD_COUNT=(mux_rd_cnt%MAX_BUF_NUM);
down(&muxfifo_read_sem);
size =((*size_buf[MUX_RD_COUNT])*16 + enc_txmsg_size)*2;
//copy_to_user(buffer, mux_buf[MUX_RD_COUNT], size);
if (size>MAX_BUF_SIZE) {
#ifdef __EXT_CODE__ /*2005-03-09 netbsd*/
copy_to_user(buffer, ext_mux_buf[MUX_RD_COUNT], size);
vfree(ext_mux_buf[MUX_RD_COUNT]);
#endif
}
else {
copy_to_user(buffer, mux_buf[MUX_RD_COUNT], size);
}
mux_rd_cnt++;
if (mux_rd_cnt>MAX_CNT) {
mux_rd_cnt=(mux_rd_cnt%MAX_BUF_NUM);
printk_netbsd ("[### RETURN mux_rd_cnt ###]\n");
}
if (mux_full) {
/*2005-03-17 netbsd*/
//*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO_ADDR)) = 0x8803;
/* acknowledge for data ready message */
*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 0x8803;
mux_full = 0;
printk_netbsd ("F");
}
return 0;
}
/*2005-04-22 netbsd*/
#define DEC_DUMMY 1024
#define DEC_DUMMY2 1024
static ssize_t demuxfifo_write(struct file *file,const char *buffer, size_t length, loff_t * offset)
{
/*2005-02-14 netbsd*/
volatile unsigned long DEMUX_WR_COUNT= (demux_wr_cnt%MAX_BUF_NUM);
// pentamicro 2005.07.28
volatile unsigned short id_conf;
down(&demuxfifo_write_sem);
//copy_from_user(demux_buf[DEMUX_WR_COUNT], buffer, length);
if (length>MAX_BUF_SIZE) {
#ifdef __EXT_CODE__ /*2005-03-09 netbsd*/
if (!(ext_demux_buf[DEMUX_WR_COUNT] = (unsigned short *) vmalloc(length+DEC_DUMMY))) {
printk_netbsd("AT2042 : ext_demux_buf vmalloc failed...\n");
return -ENOMEM;
}
copy_from_user(ext_demux_buf[DEMUX_WR_COUNT], buffer, length);
#endif
}
else {
copy_from_user(demux_buf[DEMUX_WR_COUNT], buffer, length);
}
demux_size_buf[DEMUX_WR_COUNT] = length;
stc_update_count++;
// pentamicro 2005.07.28
//#ifdef STC_UP_CONTROL
#if 1
//if (stc_update_count == 10) {
//printk("%ld:%ld\n", demux_wr_cnt, demux_rd_cnt);
if ((demux_wr_cnt != MAX_CNT) && (demux_rd_cnt != MAX_CNT)) {
if (demux_wr_cnt >= demux_rd_cnt) {
if (((demux_wr_cnt - demux_rd_cnt) >= 11) && (stc_up_flag != 1)){
id_conf = RxID(GID_DECODER, 0x00, PID_DEC_STC_SPEED_CONTROL, W_FLAG);
*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = id_conf;
*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 1;
stc_up_flag= 1;
// printk("stc up: %ld, %ld\n", demux_wr_cnt, demux_rd_cnt);
}
else if (((demux_wr_cnt - demux_rd_cnt) <= 3) && (stc_up_flag != 0xffff)){
id_conf = RxID(GID_DECODER, 0x00, PID_DEC_STC_SPEED_CONTROL, W_FLAG);
*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = id_conf;
*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 0xffff;
stc_up_flag= 0xffff;
// printk("stc down: %ld, %ld\n", demux_wr_cnt, demux_rd_cnt);
}
else if (((demux_wr_cnt - demux_rd_cnt) >= 6) && ((demux_wr_cnt - demux_rd_cnt) <= 8)
&& (stc_up_flag != 0)){
id_conf = RxID(GID_DECODER, 0x00, PID_DEC_STC_SPEED_CONTROL, W_FLAG);
*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = id_conf;
*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 0;
stc_up_flag= 0;
// printk("stc normal: %ld, %ld\n", demux_wr_cnt, demux_rd_cnt);
}
}
else if (demux_wr_cnt < demux_rd_cnt) {
if (((demux_rd_cnt - demux_wr_cnt) >= 11) && (stc_up_flag != 1)){
id_conf = RxID(GID_DECODER, 0x00, PID_DEC_STC_SPEED_CONTROL, W_FLAG);
*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = id_conf;
*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 1;
stc_up_flag= 1;
// printk("stc up: %ld, %ld\n", demux_wr_cnt, demux_rd_cnt);
}
else if (((demux_rd_cnt - demux_wr_cnt) <= 3) && (stc_up_flag != 0xffff)){
id_conf = RxID(GID_DECODER, 0x00, PID_DEC_STC_SPEED_CONTROL, W_FLAG);
*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = id_conf;
*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 0xffff;
stc_up_flag= 0xffff;
// printk("stc down: %ld, %ld\n", demux_wr_cnt, demux_rd_cnt);
}
else if (((demux_rd_cnt - demux_wr_cnt) >= 6) && ((demux_wr_cnt - demux_rd_cnt) <= 8)
&& (stc_up_flag != 0)){
id_conf = RxID(GID_DECODER, 0x00, PID_DEC_STC_SPEED_CONTROL, W_FLAG);
*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = id_conf;
*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 0;
stc_up_flag= 0;
// printk("stc normal: %ld, %ld\n", demux_wr_cnt, demux_rd_cnt);
}
}
}
stc_update_count= 0;
//}
#endif
DEMUX_FULL_EVENT:
if ((demux_wr_cnt-demux_rd_cnt)<MAX_BUF_NUM) {
demux_wr_cnt++;
}
else {
printk_netbsd ("\n[write][demux_wr_cnt:%lu, demux_rd_cnt:%lu]\n", demux_wr_cnt, demux_rd_cnt);
AT2042_DELAY(10000);
goto DEMUX_FULL_EVENT;
}
if (demux_wr_cnt>MAX_CNT) {
demux_wr_cnt=(demux_wr_cnt%MAX_BUF_NUM);
printk_netbsd ("[### RETURN demux_wr_cnt ###]\n");
}
return 0;
}
static int at2041_open(struct inode* inode, struct file* filp)
{
printk_netbsd ("[### AT2042 Open ###]\n");
MOD_INC_USE_COUNT;
return 0;
}
static int at2041_release(struct inode* inode, struct file* filp)
{
printk_netbsd ("[### AT2042 Release ###]\n");
MOD_DEC_USE_COUNT;
return 0;
}
/* the AT2041 file operations */
static struct file_operations at2041_fops = {
read: muxfifo_read,
write: demuxfifo_write,
ioctl: at2041_ioctl,
open: at2041_open,
release: at2041_release,
};
/*2005-04-21 netbsd*/
#if 0 /*__DMA_ENABLE__*/
volatile unsigned short DMA_TEST;
static void at2042_dma_handle(int irq, void *dev_id, struct pt_regs * regs)
{
if((mfdcr(DMA1SR0) & DMASR_CH0_TC)== DMASR_CH0_TC) {
DMA_TEST = *((volatile unsigned short *)((unsigned long)pt + 0x00600000));
mtdcr(DMA1SR0,mfdcr(DMA1SR0) |DMASR_CH0_TC|DMASR_CH0_EOT|DMASR_CH0_ERR|DMASR_CH0_IR|DMASR_CH0_ER|DMASR_CH0_CB|DMASR_CH0_CT);
if ((FULL_FLAG == 0 && !(RD_CNT == 0 && (CNT == MAX_BUF_NUM - 1)))
|| ((FULL_FLAG == 1) && (RD_CNT > (CNT + 2)))) {
CNT ++;
/* Issue ACK command */
*((unsigned short *)((unsigned long)pt + 0x00100000)) = 0x00;
*((unsigned short *)((unsigned long)pt + 0x00180000)) = 0x00;
}
else {
FULL_EVENT = 1;
printk("F");
}
if (CNT == MAX_BUF_NUM ) {
CNT = 0;
FULL_FLAG++;
}
}
else
{
mtdcr(DMA1SR0,mfdcr(DMA1SR0) |DMASR_CH0_EOT|DMASR_CH0_ERR|DMASR_CH0_IR|DMASR_CH0_ER|DMASR_CH0_CB|DMASR_CH0_CT);
}
mtdcr(DMA1CR0, mfdcr(DMA1CR0) | DMACR_CE);
}
#endif
static void at2041_interrupt_handle(int irq, void *dev_id, struct pt_regs * regs)
{
volatile unsigned int tx_data=0;
volatile unsigned int data_size = 0;
volatile unsigned short temp;
#if 0
int tmp=0;
unsigned short temp;
unsigned char picture_type[]={'I', 'P', 'B'};
#endif
volatile unsigned short mux_data;
volatile unsigned short demux_data;
volatile unsigned short mux_swap;
volatile unsigned short demux_swap;
volatile unsigned short id_conf = RxID(GID_ENC_VIDEO, 0x00, 0x01, R_FLAG);
/*2005-02-14 netbsd*/
volatile unsigned long MUX_WR_COUNT;
volatile unsigned long DEMUX_RD_COUNT;
/*2005-03-09 netbsd*/
volatile unsigned int ii;
#if 0 /*JMP 2005-01-10*/
/*RATE_CNT_ID*/
volatile unsigned short id_conf0 = RxID(GID_ENC_VIDEO_CH, 0x00, 0x04, R_FLAG);
/*QUALITY_ID*/
volatile unsigned short id_conf1 = RxID(GID_ENC_VIDEO_CH, 0x00, 0x05, R_FLAG);
/*CBR_RATE_ID*/
volatile unsigned short id_conf2 = RxID(GID_ENC_VIDEO_CH, 0x00, 0x06, R_FLAG);
/*ENC_OPT_ID*/
volatile unsigned short id_conf3 = RxID(GID_ENC_VIDEO, 0x00, 0x11, R_FLAG);
/*RESOL_ID*/
volatile unsigned short id_conf4 = RxID(GID_ENC_VIDEO_CH, 0x00, 0x22, R_FLAG);
#endif
/* data read from Tx_FIFO of the AT2041 */
tx_data = *((unsigned short *)((unsigned int)fifo_reg + AT2041_TX_FIFO));
#if 0 /*JMP 2005-01-10*/
if (tx_data ==id_conf0) { /*RATE_CNT_ID*/
//0:VBR 1~2:CBR
tx_data = *((unsigned short *)((unsigned int)fifo_reg + AT2041_TX_FIFO));
at2042_cur.RATE_CNT=tx_data;
printk ("## RATE_CNT_ID 0x%04x:%d ##\n" , id_conf0, tx_data);
}
else if (tx_data ==id_conf1) { /*QUALITY_ID*/
tx_data = *((unsigned short *)((unsigned int)fifo_reg + AT2041_TX_FIFO));
at2042_cur.QUALITY=tx_data;
printk ("## QUALITY_ID 0x%04x:%d ##\n" , id_conf1, tx_data);
}
else if (tx_data ==id_conf2) { /*CBR_RATE_ID*/
tx_data = *((unsigned short *)((unsigned int)fifo_reg + AT2041_TX_FIFO));
at2042_cur.BIT_RATE=tx_data;
printk ("## CBR_RATE_ID 0x%04x:%d ##\n" , id_conf2, tx_data);
}
else if (tx_data ==id_conf3) { /*ENC_OPT_ID*/
tx_data = *((unsigned short *)((unsigned int)fifo_reg + AT2041_TX_FIFO));
at2042_cur.ENC_OPT=tx_data;
printk ("## ENC_OPT_ID 0x%04x:%d ##\n" , id_conf3, tx_data);
}
else if (tx_data ==id_conf4) { /*RESOL_ID*/
tx_data =*((unsigned short *)((unsigned int)fifo_reg + AT2041_TX_FIFO));
if (tx_data==2) at2042_cur.RESOL=0; /*CIF*/
else at2042_cur.RESOL=1; /*D1*/
printk ("## RESOL_ID 0x%04x:%d ##\n" , id_conf4, tx_data);
tx_data =*((unsigned short *)((unsigned int)fifo_reg + AT2041_TX_FIFO));
}
#endif
if (tx_data ==id_conf) /*RESOLUTION*/
{
/* ID data read from Tx_FIFO of the AT2041 */
//tx_data = *((unsigned short *)((unsigned int)fifo_reg + AT2041_TX_FIFO));
/* 1ST data read from Tx_FIFO of the AT2041 */
tx_data = *((unsigned short *)((unsigned int)fifo_reg + AT2041_TX_FIFO));
/* 2ND data read from Tx_FIFO of the AT2041 */
tx_data = *((unsigned short *)((unsigned int)fifo_reg + AT2041_TX_FIFO));
if (tx_data==576) {
PAL_NTSC=PAL;
printk_netbsd ("## PAL INPUT VIDEO DETECTEDT : %d ##\n" , tx_data);
}
else {
PAL_NTSC=NTSC;
printk_netbsd ("## NTSC INPUT VIDEO DETECTEDT : %d ##\n", tx_data);
}
/* 3RD data read from Tx_FIFO of the AT2041 */
tx_data = *((unsigned short *)((unsigned int)fifo_reg + AT2041_TX_FIFO));
/* 4TH data read from Tx_FIFO of the AT2041 */
tx_data = *((unsigned short *)((unsigned int)fifo_reg + AT2041_TX_FIFO));
/* TxACK command */
*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 0x8003;
}
/* check whether first tx message is 'data ready message'
* or 'data request message'
*/
else if ((tx_data & 0x0001) == 0x0000) {
// read data from tx_fifo
/* check tx fifo empty */
if ( !(*((unsigned short *)((unsigned int)fifo_reg + AT2041_STATUS_REG)) & 0x100) ) {
// read DATA
/* data read from Tx_FIFO of the AT2041 */
tx_data = *((unsigned short *)((unsigned int)fifo_reg + AT2041_TX_FIFO));
}
/* TxACK command */
*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 0x8003;
}
else if (tx_data == 0x8803)
{
// read message from tx_fifo : data ready message(Encoder)
/* if first tx message is 'data ready message',
* read three tx message sequentially.
* the contents of second tx_message are 'data type', 'channel ID',
* 'skip', 'loss' and 'output buffer full', etc.
*/
MUX_WR_COUNT=(mux_wr_cnt%MAX_BUF_NUM);
/* check tx fifo empty */
if ( !(*((unsigned short *)((unsigned int)fifo_reg + AT2041_STATUS_REG)) & 0x100) ) {
/* read the second parameter of Tx_FIFO */
mux_buf[MUX_WR_COUNT][0] = *((unsigned short *)((unsigned int)fifo_reg + AT2041_TX_FIFO));
}
else {
printk_netbsd("[at2042 : 0x8803] It can't read tx0 register\n");
/* TxACK command */
//*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 0x8003;
}
if ( !(*((unsigned short *)((unsigned int)fifo_reg + AT2041_STATUS_REG)) & 0x100) ) {
/* read the third parameter of Tx_FIFO */
/* the contents of the third tx_message are 'output data size' */
mux_buf[MUX_WR_COUNT][1] = *((unsigned short *)((unsigned int)fifo_reg + AT2041_TX_FIFO));
}
else {
printk_netbsd("[at2042 : 0x8803] It can't read tx1 register\n");
/* TxACK command */
//*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 0x8003;
}
if ( !(*((unsigned short *)((unsigned int)fifo_reg + AT2041_STATUS_REG)) & 0x100) ) {
/* read the fourth parameter of Tx_FIFO */
/* the contents of the fourth tx_message are 'reserved' */
mux_buf[MUX_WR_COUNT][2] = *((unsigned short *)((unsigned int)fifo_reg + AT2041_TX_FIFO));
}
else {
printk_netbsd("[at2042 : 0x8803] It can't read tx2 register\n");
/* TxACK command */
//*((unsigned short *)((unsigned int)fifo_reg + AT2041_RX_FIFO)) = 0x8003;
}
/* calculate data size to transfer */
*size_buf[MUX_WR_COUNT] = mux_buf[MUX_WR_COUNT][1];
//data_size = ((*size_buf[mux_rd_cnt] << 5) + (enc_txmsg_size << 1))/2;
//data_size = ((*size_buf[mux_wr_cnt] & 0xffff) << 4) + enc_txmsg_size;
data_size = *size_buf[MUX_WR_COUNT]*16 + enc_txmsg_size;
if (*size_buf[MUX_WR_COUNT]*32>MAX_BUF_SIZE)
{
printk_netbsd ("[##### ENCODER SIZE_OVER : %08d #####]\n", *size_buf[MUX_WR_COUNT]*32);
#ifdef __EXT_CODE__ /*2005-03-09 netbsd*/
if (!(ext_mux_buf[MUX_WR_COUNT] = (unsigned short *) vmalloc(data_size*2))) {
printk_netbsd("AT2042 : ext_mux_buf vmalloc failed...\n");
return ;
}
for (ii=0;ii<enc_txmsg_size;ii++) {
ext_mux_buf[MUX_WR_COUNT][ii]=mux_buf[MUX_WR_COUNT][ii];
}
for (ii = enc_txmsg_size; ii < data_size; ii ++) {
mux_data=*((unsigned short *)((unsigned int)fifo_reg + AT2041_MUX_FIFO));
mux_swap= (((mux_data<<8)&0xFF00) | ((mux_data>>8)&0x00FF));
ext_mux_buf[MUX_WR_COUNT][ii]=mux_swap;
}
#endif
}
else
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -