📄 bfpga.c
字号:
/*
********************************************************************************
*
* Copyright 2004, Vineyard Technologies, Inc.
*
* Filename : bfpga.c
* Programmer: Steve KyeongHyeon Lee
* Created : 2004/09/29
* Modified :
*
* Description :
********************************************************************************
*/
#include "types.h"
/*
###############################################################################
File Include Section
###############################################################################
*/
#include "8052reg.h"
#include <stdio.h>
#include "gio.h"
#include "bfpga.h"
extern xdata u8 gv_NTSC_PAL;
xdata u8 vBFREG_SETUP = BFS_RCEN;
xdata u8 vBFREG_STATUS;
xdata u8 vBFREG_ENC_DCTH= 0x10; // 0x20 0x10
xdata u8 vBFREG_ENC_ACTH= 0x10; // 0x20 0x10
xdata u8 vBFREG_RC_DFR = 0x00;
xdata u8 vBFREG_RC_DQL = 0x33; // 0xF3 0x33
xdata u8 vBFREG_RC_PQL0 = 0x15;
xdata u8 vBFREG_RC_PQL1 = 0x24;
#ifdef DEBUG_G1PP_SETUP
void display_g1pp_setup(u8 reg);
#endif
//==============================================================================
//
//==============================================================================
void bfpga_init(void)
{
#ifdef DEBUG_G1PP_SETUP
u8 setup_reg;
#endif
gv_bfpga_move_done = 0;
gv_bfpga_move_start = 0;
lan_enable();
// Software reset
BFREG_SETUP = 0x00;
delay_time(100,1);
BFREG_SETUP = BFS_RST;
delay_time(100,1);
vBFREG_SETUP &= (~BFS_AEN); // default audio encoding is not enabled
BFREG_SETUP = (vBFREG_SETUP | (gv_NTSC_PAL?BFS_PAL:0));
#ifdef DEBUG_G1PP_SETUP
printf("\n\rbfpga_init:");
setup_reg = BFREG_SETUP;
display_g1pp_setup(setup_reg);
#endif
// Initiate FPGA register with default values
BFREG_ENC_DCTH = vBFREG_ENC_DCTH;
BFREG_ENC_ACTH = vBFREG_ENC_ACTH;
BFREG_RC_DFR = vBFREG_RC_DFR;
BFREG_RC_DQL = vBFREG_RC_DQL;
BFREG_RC_PQL0 = vBFREG_RC_PQL0;
BFREG_RC_PQL1 = vBFREG_RC_PQL1;
dv03_enable();
}
//==============================================================================
//
//==============================================================================
void bfpga_update_regs(u8 off, u8 val)
{
lan_enable();
XBYTE[FPGA_REG_BASE+off] = val;
dv03_enable();
}
//==============================================================================
//
//==============================================================================
void bfpga_update_setup(u8 new_setup)
{
u8 setup_reg;
lan_enable();
// stop every encoding, clear video buffer
setup_reg = (BFREG_SETUP & (~(BFS_VEN|BFS_AEN))) | BFS_VBC;
BFREG_SETUP = setup_reg;
#ifdef DEBUG_G1PP_SETUP
printf("\n\rbfpga_update_setup: stop encoding a/v, clear buffer");
display_g1pp_setup(setup_reg);
display_g1pp_setup(BFREG_SETUP);
#endif
// normal operation for clear buffer bit
setup_reg = BFREG_SETUP;
setup_reg = setup_reg & (~(BFS_VEN|BFS_AEN|BFS_VBC));
BFREG_SETUP = setup_reg;
#ifdef DEBUG_G1PP_SETUP
printf("\n\rbfpga_update_setup: VBC bit to normal(0)");
display_g1pp_setup(setup_reg);
display_g1pp_setup(BFREG_SETUP);
#endif
// restart
setup_reg = BFREG_SETUP;
// clear CIF, AEN, RCEN
setup_reg &= ~(BFS_CIF|BFS_AEN|BFS_RCEN);
// update the required value of CIF AEN RCEN
setup_reg = setup_reg |
BFS_VEN | // allways enable video encoding
(gv_NTSC_PAL?BFS_PAL:0) |
(new_setup & (BFS_CIF|BFS_AEN|BFS_RCEN));
BFREG_SETUP = setup_reg;
#ifdef DEBUG_G1PP_SETUP
printf("\n\rbfpga_update_setup: new conifg");
display_g1pp_setup(setup_reg);
display_g1pp_setup(BFREG_SETUP);
#endif
dv03_enable();
}
//==============================================================================
//
//==============================================================================
void bfpga_enable_encoding(u8 en)
{
u8 setup_reg;
lan_enable();
if(en)
{
setup_reg = BFREG_SETUP;
setup_reg |= BFS_VEN; // enable encoding video
BFREG_SETUP = setup_reg;
}
else
{
setup_reg = BFREG_SETUP;
setup_reg &= ~(BFS_VEN|BFS_AEN); // diable encoding audio and video
BFREG_SETUP = setup_reg;
}
#ifdef DEBUG_G1PP_SETUP
printf("\n\rbfpga_enable_encoding: (%d) ", (int)en);
display_g1pp_setup(setup_reg);
display_g1pp_setup(BFREG_SETUP);
#endif
dv03_enable();
}
//==============================================================================
//
//==============================================================================
u8 bfpga_txbuf_ready(void)
{
u8 ready = 0;
lan_enable();
ready = BFREG_STATUS;
dv03_enable();
ready &= 0x01;
return ready;
}
//==============================================================================
//
//==============================================================================
WORD gwAddr = 0, gwPktCnt = 0;
void bfpga_txstart(u8 addr_h, u8 addr_l)
{
union UWORD uwDA;
uwDA.bVal[0] = addr_h;
uwDA.bVal[1] = addr_l;
uwDA.wVal += 12;//6; // -- 2K network packet header size
lan_enable();
BFREG_LAN_DA0 = uwDA.bVal[1];
BFREG_LAN_DA1 = uwDA.bVal[0];
gv_bfpga_move_start = 1;
BFREG_SETUP |= BFS_START; // send command that say start moving
dv03_enable();
}
#ifdef RESET_VBOF
//==============================================================================
//
//==============================================================================
void bfpga_check_vbof(u8 doitnow)
{
xdata u8 vBFREG_STATUS;
lan_enable();
vBFREG_STATUS = BFREG_STATUS;
if((vBFREG_STATUS & VBOF) || doitnow )
{
// clear video encoder buffer
BFREG_STATUS |= VBOF;
BFREG_SETUP |= BFS_VBC;
BFREG_SETUP = BFREG_SETUP & (~BFS_VBC);
#ifdef DEBUG_VBOF
printf("\n\r-- clear G1PP video buf");
#endif
}
dv03_enable();
}
#endif
//==============================================================================
//
//==============================================================================
void bfpga_update_time(u8* cur_time)
{
xdata u8 i;
lan_enable();
// update year at first and second at last
for(i=0;i<6;i++)
{
XBYTE[FPGA_REG_BASE+BFREGOFF_TIME_YY+i] = cur_time[5-i];
}
dv03_enable();
}
#ifdef DEBUG_G1PP_SETUP
//===============================================================================
//
//===============================================================================
void display_g1pp_setup(u8 reg)
{
printf("\n\rVEN[%d] PAL[%d] CIF[%d] VBC[%d] AEN[%d] RCE[%d] RST[%d] STR[%d]",
(int)((reg&0x80)>>7),
(int)((reg&0x40)>>6),
(int)((reg&0x20)>>5),
(int)((reg&0x10)>>4),
(int)((reg&0x08)>>3),
(int)((reg&0x04)>>2),
(int)((reg&0x02)>>1),
(int) (reg&0x01)
);
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -