?? dm642main.c
字號:
/********************************************************************/
/* Copyright 2004 by SEED Incorporated. */
/* All rights reserved. Property of SEED Incorporated. */
/* Restricted rights to use, duplicate or disclose this code are */
/* granted through contract. */
/* */
/********************************************************************/
/********************************************************************/
/* 圖像的平滑(平均模板) */
/********************************************************************/
#include <csl.h>
#include <csl_emifa.h>
#include <csl_i2c.h>
#include <csl_gpio.h>
#include <csl_irq.h>
#include <csl_chip.h>
#include <csl_dat.h>
#include "iic.h"
#include "vportcap.h"
#include "vportdis.h"
#include "sa7121h.h"
#include "TVP51xx.h"
/*SEEDDM642的emifa的設置結構*/
EMIFA_Config Seeddm642ConfigA ={
0x00052078,/*gblctl EMIFA(B)global control register value */
/*將CLK6、4、1使能;將MRMODE置1;使能EK2EN,EK2RATE*/
0xffffffd3,/*cectl0 CE0 space control register value*/
/*將CE0空間設為SDRAM*/
0x73a28e01,/*cectl1 CE1 space control register value*/
/*Read hold: 1 clock;
MTYPE : 0000,選擇8位的異步接口
Read strobe :001110;14個clock寬度
TA:2 clock; Read setup 2 clock;
Write hold :2 clock; Write strobe: 14 clock
Write setup :7 clock
-- ---------------
\ 14c /1c
\----------------/ */
0x22a28a22, /*cectl2 CE2 space control register value*/
0x22a28a42, /*cectl3 CE3 space control register value*/
0x57115000, /*sdctl SDRAM control register value*/
0x0000081b, /*sdtim SDRAM timing register value*/
0x001faf4d, /*sdext SDRAM extension register value*/
0x00000002, /*cesec0 CE0 space secondary control register value*/
0x00000002, /*cesec1 CE1 space secondary control register value*/
0x00000002, /*cesec2 CE2 space secondary control register value*/
0x00000073 /*cesec3 CE3 space secondary control register value*/
};
/*SEEDDM642的IIC的設置結構*/
I2C_Config SEEDDM642IIC_Config = {
0, /* master mode, i2coar;采用主模式 */
0, /* no interrupt, i2cimr;只寫,不讀,采用無中斷方式*/
(20-5), /* scl low time, i2cclkl; */
(20-5), /* scl high time,i2cclkh; */
1, /* configure later, i2ccnt;*/
0, /* configure later, i2csar;*/
0x4ea0, /* master tx mode, */
/* i2c runs free, */
/* 8-bit data + NACK */
/* no repeat mode */
(75-1), /* 4MHz clock, i2cpsc */
};
CHIP_Config SEEDDM642percfg = {
CHIP_VP2+\
CHIP_VP1+\
CHIP_VP0+\
CHIP_I2C
};
I2C_Handle hSeeddm642i2c;
int portNumber;
extern SA7121H_ConfParams sa7121hPAL[45];
extern SA7121H_ConfParams sa7121hNTSC[45];
Uint8 vFromat = 0;
Uint8 misc_ctrl = 0x6D;
Uint8 output_format = 0x47;
// 地址為0 for cvbs port1,選擇復合信號做為輸入
Uint8 input_sel = 0x00;
/*地址為0xf,將Pin27設置成為CAPEN功能*/
Uint8 pin_cfg = 0x02;
/*地址為1B*/
Uint8 chro_ctrl_2 = 0x14;
/*圖像句柄的聲明*/
VP_Handle vpHchannel0;
VP_Handle vpHchannel1;
VP_Handle vpHchannel2;
/*確定圖像的參數*/
int numPixels = 720;//每行720個像素
int numLines = 576;//每幀576行(PAL)
/*確定處理的范圍*/
/*A */
/* */
/* D*/
int intAPixels = 190;
int intALines = 59;
int intDPixels = 530;
int intDLines = 229;
/*******************/
/*****畫矩形邊框函數的聲明*****/
void drawRectangle();
/*平滑處理(平均模板)*/
void AverageSmooth();
/*采集與顯示緩沖區的首址*/
Uint32 capYbuffer = 0x80000000;
Uint32 capCbbuffer = 0x800675c0;
Uint32 capCrbuffer = 0x8009b0a0;
Uint32 disYbuffer = 0x80100000;
Uint32 disCbbuffer = 0x801675c0;
Uint32 disCrbuffer = 0x8019b0a0;
Uint32 tempSrcYbuffer = 0x80200000; //臨時
Uint32 tempDisYbuffer = 0x80300000; //臨時
/*圖像格式標志*/
Uint8 NTSCorPAL = 0;
extern far void vectors();
extern volatile Uint32 capNewFrame;
extern volatile Uint32 disNewFrame;
/*此程序可將四個采集口的數據經過Video Port0送出*/
void main()
{
Uint8 addrI2C;
int i;
/*-------------------------------------------------------*/
/* perform all initializations */
/*-------------------------------------------------------*/
/*Initialise CSL,初始化CSL庫*/
CSL_init();
CHIP_config(&SEEDDM642percfg);
/*----------------------------------------------------------*/
/*EMIFA的初始化,將CE0設為SDRAM空間,CE1設為異步空間
注,DM642支持的是EMIFA,而非EMIF*/
EMIFA_config(&Seeddm642ConfigA);
/*----------------------------------------------------------*/
/*中斷向量表的初始化*/
//Point to the IRQ vector table
IRQ_setVecs(vectors);
IRQ_nmiEnable();
IRQ_globalEnable();
IRQ_map(IRQ_EVT_VINT1, 11);
IRQ_map(IRQ_EVT_VINT0, 12);
IRQ_reset(IRQ_EVT_VINT1);
IRQ_reset(IRQ_EVT_VINT1);
/*打開一個數據拷貝的數據通路*/
DAT_open(DAT_CHAANY, DAT_PRI_LOW, DAT_OPEN_2D);
/*----------------------------------------------------------*/
/*進行IIC的初始化*/
hSeeddm642i2c = I2C_open(I2C_PORT0,I2C_OPEN_RESET);
I2C_config(hSeeddm642i2c,&SEEDDM642IIC_Config);
/*----------------------------------------------------------*/
/*進行TVP5150pbs的初始化*/
/*選擇TVP5150,設置第三通路*/
GPIO_RSET(GPGC,0x0);/*將GPIO0不做為GPINT使用*/
GPIO_RSET(GPDIR,0x1);/*將GPIO0做為輸出*/
GPIO_RSET(GPVAL,0x0);/*GPIO0輸出為高,選擇IIC1總線,配置
第二路,即為U21*/
addrI2C = 0xBA >>1;
_IIC_write(hSeeddm642i2c, addrI2C,0x00, input_sel);
_IIC_write(hSeeddm642i2c, addrI2C,0x03, misc_ctrl);
_IIC_write(hSeeddm642i2c, addrI2C,0x0D, output_format);
_IIC_write(hSeeddm642i2c, addrI2C,0x0F, pin_cfg);
_IIC_write(hSeeddm642i2c, addrI2C,0x1B, chro_ctrl_2);
/*回讀當前攝像設備的格式*/
_IIC_read(hSeeddm642i2c, addrI2C,0x8c, &vFromat);
vFromat = vFromat & 0xff;
switch (vFromat)
{
case TVP51XX_NTSCM:
case TVP51XX_NTSC443:
NTSCorPAL = 1;/*系統為NTSC的模式*/
break;
case TVP51XX_PALBGHIN:
case TVP51XX_PALM:
NTSCorPAL = 0;/*系統為PAL的模式*/
break;
default:
NTSCorPAL = 2;/*系統為不支持的模式*/
break;
}
if(NTSCorPAL ==2)
{
/*系統不支持的模式,重新配置*/
for(;;)
{}
}
/*----------------------------------------------------------*/
/*進行SAA7121H的初始化*/
GPIO_RSET(GPVAL,0x0);/*GPIO0輸出為低,選擇IIC1總線,配置圖像輸出*/
addrI2C = 0xB8 >>1; /*選擇第0路的I2C的地址*/
/*將第0路的視頻輸入口的數據口設為高阻狀態,
使能SCLK,將第27腳設為輸入*/
_IIC_write(hSeeddm642i2c, addrI2C,0x03, 0x1);
/*配置SAA7121H*/
GPIO_RSET(GPVAL,0x1);/*GPIO0輸出為低,選擇IIC1總線,配置圖像輸出*/
/*初始化Video Port0*/
/*將Vedio Port1設為encoder輸出*/
portNumber = 0;
vpHchannel0 = bt656_8bit_ncfd(portNumber);
addrI2C = 0x88 >>1;
for(i =0; i<43; i++)
{
if(NTSCorPAL == 1)
{
_IIC_write(hSeeddm642i2c,
addrI2C,
(sa7121hNTSC[i].regsubaddr),
(sa7121hNTSC[i].regvule));
}
else
{
_IIC_write(hSeeddm642i2c,
addrI2C,
(sa7121hPAL[i].regsubaddr),
(sa7121hPAL[i].regvule));
}
}
/*----------------------------------------------------------*/
/*初始化Video Port1*/
/*將Vedio Port1設為采集輸入*/
portNumber = 1;
vpHchannel1 = bt656_8bit_ncfc(portNumber);
bt656_capture_start(vpHchannel1);
/*等待第一幀數據采集完成*/
while(capNewFrame == 0){}
/*將數據存入顯示緩沖區,并清采集完成的標志*/
capNewFrame =0;
for(i=0;i<numLines;i++)
{
/*傳送臨時Y緩沖區*/
DAT_copy((void *)(capYbuffer + i * numPixels),
(void *)(tempSrcYbuffer + i * numPixels),
numPixels);
/*傳送臨時Y緩沖區*/
DAT_copy((void *)(capYbuffer + i * numPixels),
(void *)(tempDisYbuffer + i * numPixels),
numPixels);
}
/*平滑處理(平均模板)*/
AverageSmooth();
/*畫邊框*/
drawRectangle();
for(i=0;i<numLines;i++)
{
/*傳送Y緩沖區*/
DAT_copy((void *)(tempDisYbuffer + i * numPixels),
(void *)(disYbuffer + i * numPixels),
numPixels);
}
//清除彩色信號
for(i=0;i<0x33ae0;i++)
{
*((Uint8 *)(disCrbuffer +i)) =0x80;
*((Uint8 *)(disCbbuffer +i)) =0x80;
}
/*啟動顯示模塊*/
bt656_display_start(vpHchannel0);
/*建立顯示的實時循環*/
for(;;)
{
/*當采集區的數據已經采集好,而顯示緩沖區的數據已空*/
if((capNewFrame == 1)&&(disNewFrame == 1))
{
/*將數據裝入顯示緩沖區,并清采集完成的標志*/
capNewFrame =0;
disNewFrame =0;
for(i=0;i<numLines;i++)
{
/*傳送臨時Y緩沖區*/
DAT_copy((void *)(capYbuffer + i * numPixels),
(void *)(tempSrcYbuffer + i * numPixels),
numPixels);
/*傳送臨時Y緩沖區*/
DAT_copy((void *)(capYbuffer + i * numPixels),
(void *)(tempDisYbuffer + i * numPixels),
numPixels);
}
/*平滑處理(平均模板)*/
AverageSmooth();
/*畫邊框*/
drawRectangle();
for(i=0;i<numLines;i++)
{
/*傳送Y緩沖區*/
DAT_copy((void *)(tempDisYbuffer + i * numPixels),
(void *)(disYbuffer + i * numPixels),
numPixels);
}
}
}
for(;;)
{}
/*----------------------------------------------------------*/
/*采集與回放*/
}
/*畫矩形邊框函數的定義*/
void drawRectangle()
{
int i,j;
/*畫上邊*/
//奇數行
for(i=intALines-4;i<intALines;i++)
{
for(j=intAPixels-6;j<intDPixels+6;j++)
{
*(Uint8 *)(tempDisYbuffer + i*numPixels + j) = 0x00;
}
}
//偶數行
for(i=numLines/2+intALines-4;i<numLines/2+intALines;i++)
{
for(j=intAPixels-6;j<intDPixels+6;j++)
{
*(Uint8 *)(tempDisYbuffer + i*numPixels + j) = 0x00;
}
}
/*畫下邊*/
//奇數行
for(i=intDLines;i<intDLines+4;i++)
{
for(j=intAPixels-6;j<intDPixels+6;j++)
{
*(Uint8 *)(tempDisYbuffer + i*numPixels + j) = 0x00;
}
}
//偶數行
for(i=numLines/2+intDLines;i<numLines/2+intDLines+4;i++)
{
for(j=intAPixels-6;j<intDPixels+6;j++)
{
*(Uint8 *)(tempDisYbuffer + i*numPixels + j) = 0x00;
}
}
/*畫左邊*/
//奇數行
for(i=intALines;i<intDLines;i++)
{
for(j=intAPixels-6;j<intAPixels;j++)
{
*(Uint8 *)(tempDisYbuffer + i*numPixels + j) = 0x00;
}
}
//偶數行
for(i=numLines/2+intALines;i<numLines/2+intDLines;i++)
{
for(j=intAPixels-6;j<intAPixels;j++)
{
*(Uint8 *)(tempDisYbuffer + i*numPixels + j) = 0x00;
}
}
/*畫右邊*/
//奇數行
for(i=intALines;i<intDLines;i++)
{
for(j=intDPixels;j<intDPixels+6;j++)
{
*(Uint8 *)(tempDisYbuffer + i*numPixels + j) = 0x00;
}
}
//偶數行
for(i=numLines/2+intALines;i<numLines/2+intDLines;i++)
{
for(j=intDPixels;j<intDPixels+6;j++)
{
*(Uint8 *)(tempDisYbuffer + i*numPixels + j) = 0x00;
}
}
}
/*平滑處理(平均模板) */
void AverageSmooth()
{
int i,j;
float fTemp;
int intTemp;
for(i=intALines;i<intDLines;i++)
{
for(j=intAPixels;j<intDPixels;j++)
{
/*屏幕上奇數行進行處理*/
/*用平均模板進行處理*/
fTemp = (*(Uint8 *)(tempSrcYbuffer + (numLines/2+i-1)*numPixels + (j-1))) +
(*(Uint8 *)(tempSrcYbuffer + (numLines/2+i-1)*numPixels + j)) +
(*(Uint8 *)(tempSrcYbuffer + (numLines/2+i-1)*numPixels + (j+1))) +
(*(Uint8 *)(tempSrcYbuffer + i*numPixels + (j-1))) +
(*(Uint8 *)(tempSrcYbuffer + i*numPixels + j)) +
(*(Uint8 *)(tempSrcYbuffer + i*numPixels + (j+1))) +
(*(Uint8 *)(tempSrcYbuffer + (numLines/2+i)*numPixels + (j-1))) +
(*(Uint8 *)(tempSrcYbuffer + (numLines/2+i)*numPixels + j)) +
(*(Uint8 *)(tempSrcYbuffer + (numLines/2+i)*numPixels + (j+1)));
intTemp = (int)(fTemp/9 + 0.5);
if(intTemp<0)
{
intTemp = 0;
}
if(intTemp>255)
{
intTemp = 255;
}
//屏幕上奇數行進行處理
*(Uint8 *)(tempDisYbuffer + i*numPixels + j) = intTemp;
/*屏幕上偶數行進行處理*/
/*用平均模板進行處理*/
fTemp = (*(Uint8 *)(tempSrcYbuffer + i*numPixels + (j-1))) +
(*(Uint8 *)(tempSrcYbuffer + i*numPixels + j)) +
(*(Uint8 *)(tempSrcYbuffer + i*numPixels + (j+1))) +
(*(Uint8 *)(tempSrcYbuffer + (i+numLines/2)*numPixels + (j-1))) +
(*(Uint8 *)(tempSrcYbuffer + (i+numLines/2)*numPixels + j)) +
(*(Uint8 *)(tempSrcYbuffer + (i+numLines/2)*numPixels + (j+1))) +
(*(Uint8 *)(tempSrcYbuffer + (i+1)*numPixels + (j-1))) +
(*(Uint8 *)(tempSrcYbuffer + (i+1)*numPixels + j)) +
(*(Uint8 *)(tempSrcYbuffer + (i+1)*numPixels + (j+1)));
intTemp = (int)(fTemp/9 + 0.5);
if(intTemp<0)
{
intTemp = 0;
}
if(intTemp>255)
{
intTemp = 255;
}
//屏幕上偶數行進行處理
*(Uint8 *)(tempDisYbuffer + (i+numLines/2)*numPixels + j) = intTemp;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -