Tải bản đầy đủ (.pdf) (21 trang)

BÁO CÁO ĐỒ ÁN TIN HỌC 2013

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (4.29 MB, 21 trang )

BÁO CÁO ĐỒ ÁN MÔN HỌC TIN HỌC
Trang 1


LỜI CẢM ƠN

Chúng em xin chân thành cám ơn thầy TS.Đặng Thành Tín và thầy Huỳnh Xuân Cảnh đã
tận tình hướng dẫn, chỉ bảo và nhắc nhở những thiếu sót trong đề tài. Chính sự nhiệt tình chỉ
dẫn của các thầy đã giúp chúng em hoàn thành đồ án khá tốt, đạt được những yêu cầu cơ bản
mà đề tài đặt ra. Và qua đó, chúng em đã hiểu thêm về card giao tiếp video qua máy tính…
Mặc dù có thể còn một vài thiếu sót nhưng dù sao chúng em cũng đã cố gắng hết sức để hoàn
thành đề tài này. Chúng em xin chân thành cám ơn các thầy.

Bên cạnh đó, chúng em xin chân thành gửi lời cám ơn đến Phòng máy tính – Khoa Điện -
Điện tử đã tạo điện kiện tốt nhất để nhóm chúng em có thể hoàn thành đồ án.
Chúng em xin gửi lời cám ơn đến tất cả.
Tp.Hồ Chí Minh, ngày 19 tháng 06 năm 2013
Nhóm sinh viên thực hiện
Thiều Hữu Trung
Lê Quang Long














BÁO CÁO ĐỒ ÁN MÔN HỌC TIN HỌC
Trang 2


MỤC LỤC

LỜI CẢM ƠN
…………………………………………………………………………………….
Trang1
MỤC LỤC………………………………………………………………………………… Trang2
Phần A: GIỚI THIỆU ĐỀ TÀI……………………………………………………… Trang3
I.YÊU CẦU ĐỀ TÀI …………………………………………………………………… Trang3
II.HƯỚNG TÌM HIỂU………………………………………………………………… Trang3
PHẦN B: NỘI DUNG ĐỀ TÀI……………………………………………………… Trang4
1. Tổng quan về ADSP BF533 Processor:………………………………………… Trang4
2. Sơ đồ mắc dây và cách vận hành sử dụng Card ADSP BF533…………………Trang6
3. Nội dung soure code ShowFrame.c:………………………………………… … Trang7
3.1Một vài thông số ban đầu:……………………………………………….……… Trang7
3.2main:…………………………………………………………………….……………Trang7
3.3InitSystemServices:………………………………………… …………… …… Trang9
3.4ezInit:………………………………………………………………………….…… Trang9
3.5StartADV7183……………………………………………………………….……. Trang13
3.6StartADV7171……………………………………………………………….…….Trang16
4. Kết quả thu được…………………………………………………………….…… Trang18




















BÁO CÁO ĐỒ ÁN MÔN HỌC TIN HỌC
Trang 3

Phần A: GIỚI THIỆU ĐỀ TÀI
I.Yêu cầu của đề tài :
Đề tài số 10: Tìm hiểu và viết chương trình cơ chế nhận và xuất tín hiệu video sử dụng
card ADSP BF533.
Yêu cầu:
- Ngôn ngữ lập trình sử dụng C/C++/Assemly…
- Chương trình cần phải nhận và xuất dòng dữ liệu video từ card trên.
II. Hướng tìm hiểu:
 Tìm hiểu tổng quan phần cứng và cách vận hành của card ADSP BF533
 Đọc tìm hiểu sour code ShowFrame.c
 Cách thức thay đổi thới gian bắt ảnh và cách bắt ảnh từ Dish video từ đầu DVD qua
card ADSP BF533





























BÁO CÁO ĐỒ ÁN MÔN HỌC TIN HỌC
Trang 4



Phần B : NỘI DUNG ĐỀ TÀI

1. Tổng quan về ADSP BF533 Processor:
ADSP – BF533 là một trong những bộ vi xử lý thuộc họ Blackfin (ADSP – BF532, ADSP –
BF532) có hiệu suất lớn hơn, công suất thấp sơn nhưng chúng dễ dàng tương thích code hơn
những bộ vi xử lý trước.
Hệ thống thiết bị ngoại vi liên quan đến bộ vi xử lý này:
➢ Parallel Peripheral Interface (PPI)
➢ Serial Ports (SPORTs)
➢ Serial Peripheral Interface (SPI)
➢ General-Purpose timers
➢ Universal Asynchronous Receiver Transmitter (UART)
➢ Real-Time Clock (RTC)
➢ Watchdog timer
➢ General-purpose I/O (programmable flags)
Sơ đồ khồi của bộ vi xử lý:
BÁO CÁO ĐỒ ÁN MÔN HỌC TIN HỌC
Trang 5









BÁO CÁO ĐỒ ÁN MÔN HỌC TIN HỌC

Trang 6

2. Sơ đồ mắc dây và cách vận hành sử dụng Card ADSP BF533:
2.1 Sơ đồ mắc dây vào Card ADSP BF533:



2.2 Cách vận hành :
Bước 1: Lắp dây như trên . Khởi động máy tính , đầu đĩa DVD và cấp nguồn
cho Card.
Bước 2: Cho chương trình VisualDSP+++ và đầu đĩa DVD chạy
Bước 3: Mở sourecode ShowFrame và chạy trên VisualDSP+++
Bước 4: Buid sourecode lên card và sau đó cho Run rồi quan sát kết quả thu
được. Nếu chưa có thì thực hiện lại các bước trên
Dây từ đầu CD
Dây từ card ra và
chuyển thành S-video
đ


v
ào

TV

SW1 và SW2 (ở mặt
sau) tất cả off.
SW3: 1-5
OFF


6 ON

SW9: 1-4 ON
5-6 OFF
Nguồn cho card
Cổng USB nối
với máy tính
BÁO CÁO ĐỒ ÁN MÔN HỌC TIN HỌC
Trang 7


2. Nội dung soure code ShowFrame.c:
3.1 Một vài thông số ban đầu:
#define USE_LOOPBACK // sử dụng vòng lặp
#define PAL_FRAME //sử dụng khung hình song song

=> set các thông số như sau:

#if defined(PAL_FRAME) // nếu sử dụng khung hình song song
#define FRAME_DATA_LEN 1728 // Chiều dài dữ liệu trên một hàng PAL video
#define NUM_LINES 625 // Số hàng trên một khung hình
#define ACTIVE_FIELD1 22 // số hàng của first active field1
#define ACTIVE_FIELD2 335 // số hàng của of first active field2
#define HORIZONTAL_BLANKING 72 // chiều rộng (32bits) của horizontal blanking
#define NUM_LINES_ACTIVE 288 // Số hàng chủ động trên một khung hình
#else
….
#endif

Kích thước của một khung hình=FRAME_DATA_LEN*NUM_LINES=1728*625

#define FRAME_SIZE FRAME_DATA_LEN*NUM_LINES

Chiều dài dữ liệu trên một hàng PAL video, 32 bit=FRAME_DATA_LEN/4=1728/4=432
#define FRAME_DATA_LEN_32BIT FRAME_DATA_LEN/4

3.2 main:
void main(void)
{
unsigned int j/*,Result*/;
// index
u32 ResponseCount;
int Resultat=0; // response count
// initialize the system services
InitSystemServices();
// enable all LED's
for(j=0;j<EZ_NUM_LEDS;j++)
BÁO CÁO ĐỒ ÁN MÔN HỌC TIN HỌC
Trang 8

{
ezInitLED(j);
}
// enable the first push button(SW4)
ezInitButton(EZ_FIRST_BUTTON);
// enable the last push button(SW7)
ezInitButton(EZ_LAST_BUTTON);

// initialize the device manager
Resultat = adi_dev_Init(DevMgrData, // pointer to data for the device manager to use
sizeof(DevMgrData), // size of the data in bytes

&ResponseCount, // location where the number of devices that
//can be managed will be stored
&DeviceManagerHandle,// location where the device manager
//handle will be stored
NULL); // parameter for adi_int_EnterCriticalRegion() function
//(always NULL for standalone and VDK)

StartADV7183();
StartADV7171();

//last button(SW7) isn't pushed => work
while (ezIsButtonPushed(EZ_LAST_BUTTON) == FALSE) ;

// close the device
ezErrorCheck(adi_dev_Close(AD7183DriverHandle));

// close the device
ezErrorCheck(adi_dev_Close(AD7171DriverHandle));

// close the Device Manager
ezErrorCheck(adi_dev_Terminate(DeviceManagerHandle));

// close down the DMA Manager
ezErrorCheck(adi_dma_Terminate(DMAManagerHandle));
}

BÁO CÁO ĐỒ ÁN MÔN HỌC TIN HỌC
Trang 9

3.3 InitSystemServices:

static void InitSystemServices(void)
{
u32 i;
u32 Result;

ezInit(1);

// initialize the interrupt manager
ezErrorCheck( adi_int_Init(IntMgrData, // pointer to memory for interrupt manager to use
sizeof(IntMgrData), // memory size (in bytes)
&i, // location where the number of secondary handlers
//that can be supported will be stored
NULL)); // parameter for adi_int_EnterCriticalRegion
//(always NULL for VDK and standalone systems)

// hook the exception and hardware error interrupts
ezErrorCheck( adi_int_CECHook(3, ExceptionHandler, NULL, FALSE));
ezErrorCheck( adi_int_CECHook(5, HWErrorHandler, NULL, FALSE));

// initialize the dma manager
ezErrorCheck(adi_dma_Init(DMAMgrData, // pointer to memory for the DMA manager to
//use
sizeof(DMAMgrData), // memory size (in bytes)
&i, // location where # of DMA channels is stored
&DMAManagerHandle,// location where DMA manager handle is
//stored
NULL)); // parameter for adi_int_EnterCriticalRegion
//(always NULL for VDK and standalone systems)
// return
}


3.4 ezInit:
*Thanh ghi pEBIU_AMGCTL
BÁO CÁO ĐỒ ÁN MÔN HỌC TIN HỌC
Trang 10


EBIU_AMGCTL = 0x00FF
AMCKEN=1: kích hoạt CLKOUT.
AMBEN=111: cả 4 bank0, bank1, bank2, bank3 kích hoạt.
CDPRIO=0: lõi được ưu tiên hơn DMA cho sự truy cập từ bên ngoài.

*Thanh ghi EBIU_AMGCTL0
BÁO CÁO ĐỒ ÁN MÔN HỌC TIN HỌC
Trang 11



*Thanh ghi EBIU_AMGCTL1
BÁO CÁO ĐỒ ÁN MÔN HỌC TIN HỌC
Trang 12



Giá trị: EBIU_AMGCTL0=0x7bb07bb0; EBIU_AMGCTL1=0x7bb07bb0
BxRDYEN và BxRDYPOL đều = 0: không có ARDY
BxTT=00: thời gian chuyển dịch của bank x: 4 chu kì
BxST=11: thời gian cài đặt cùa bank x: 3 chu kì
BxHT=10: thời gian chờ của bank x: 2 chu kì
BxRAT=b

16
=1011
2
: thời gian đọc của bank x: 11 chu kì
BxWAT=7
16
=0111
2
: thời gian ghi của bank x: 7 chu kì
x= 0,1,2,3.
code
BÁO CÁO ĐỒ ÁN MÔN HỌC TIN HỌC
Trang 13

void ezInit(u32 NumCores)
{
// configure async memory
#if defined(__ADSP_EDINBURGH__) // ADSP-BF533 EZ-Kit specific info
*pEBIU_AMBCTL0 = 0x7bb07bb0; // Write access time = 7 cycles, read access time = 11
//cycles, no ARDY
*pEBIU_AMBCTL1 = 0x7bb07bb0; // Hold time = 2 cycles, setup time = 3 cycles,
//transition time = 4 cycles
*pEBIU_AMGCTL = 0x00FF;
#endif

// configure flash
#if defined(__ADSP_EDINBURGH__) // ADSP-BF533 EZ-Kit specific info
*pFlashA_PortA_Out = 0; // resets port A to initial value
*pFlashA_PortA_Dir = 0xFF; // configure everything on port A as outputs
*pFlashA_PortB_Out = 0; // resets port B to initial value

*pFlashA_PortB_Dir = 0x3f; // configure everything on port B as outputs
#endif

#if defined(__ADSPBF561__)
*pEBIU_AMBCTL0 = 0x7bb07bb0; // Write access time = 7 cycles, read access
time = 11 cycles, no ARDY
*pEBIU_AMBCTL1 = 0x13d07bb0; // bank 3 for NETCHIP device
*pEBIU_AMGCTL = 0x00FF;
#endif
// configure power
ezInitPower(NumCores);
}
3.5 StartADV7183
static void StartADV7183(void)
{
ezEnableVideoDecoder();// enable AD7183
ezDelay(500); // wait for 7183 to come out of reset

// open the ad7183 driver
ezErrorCheck(adi_dev_Open(DeviceManagerHandle, // DevMgr handle
BÁO CÁO ĐỒ ÁN MÔN HỌC TIN HỌC
Trang 14

&ADIADV7183EntryPoint, // pdd entry point
0, // device instance
(void *)0x7183, // client handle (0x7183 will be
//given to the AD7183 decoder
//driver)
&AD7183DriverHandle, // DevMgr handle for this
//device

ADI_DEV_DIRECTION_INBOUND,// data direction for this device
DMAManagerHandle, // handle to DmaMgr for this
//device
NULL, // handle to deferred callback service
CallbackFunction)); // client's callback function

/********* open AD7183-PPI **************************************/
//Send Pseudo TWI Configuration table to AD7183 if register configuratian is needed

//ezErrorCheck(adi_dev_Control(AD7183DriverHandle,ADI_AD7183_CMD_SET_TWI_CON
FIG_TABLE,(void*)PseudoTWIConfig));

// open the AD7183-PPI device 0 (see Schematic)
ezErrorCheck(adi_dev_Control(AD7183DriverHandle, ADI_AD7183_CMD_OPEN_PPI,
(void *)0));

/******************* AD7183 Inbound Buffers ***************************/
// populate the buffers that we'll use for the PPI input
In1_Buffer2D.Data = (void*)sFrame0;
In1_Buffer2D.ElementWidth =sizeof(u32);
In1_Buffer2D.XCount = (FRAME_DATA_LEN/2);
In1_Buffer2D.XModify = 2;
In1_Buffer2D.YCount = NUM_LINES;
In1_Buffer2D.YModify = 2;
In1_Buffer2D.CallbackParameter = NULL;
In1_Buffer2D.pNext = &In2_Buffer2D;

In2_Buffer2D.Data = (void*)sFrame1;
In2_Buffer2D.ElementWidth = sizeof(u32);
In2_Buffer2D.XCount = (FRAME_DATA_LEN/2);

BÁO CÁO ĐỒ ÁN MÔN HỌC TIN HỌC
Trang 15

In2_Buffer2D.XModify = 2;
In2_Buffer2D.YCount = NUM_LINES;
In2_Buffer2D.YModify = 2;
In1_Buffer2D.CallbackParameter = NULL;
In2_Buffer2D.pNext = NULL;

// command PPI to work in PAL mode
ezErrorCheck(adi_dev_Control(AD7183DriverHandle,
ADI_AD7183_CMD_SET_VIDEO_FORMAT, (void *)PAL));

ezErrorCheck(adi_dev_Control(AD7183DriverHandle,
ADI_DEV_CMD_SET_DATAFLOW_METHOD, (void
*)ADI_DEV_MODE_CHAINED_LOOPBACK));

// give the PPI driver the buffer to process

printf("Before reading\n");
ezErrorCheck(adi_dev_Read(AD7183DriverHandle, ADI_DEV_2D, (ADI_DEV_BUFFER
*)&In1_Buffer2D));
printf("After reading\n");
/********* AD7183 registers access **************************************/
// Send Pseudo TWI Configuration table to AD7183 if register configuratian is needed

ezErrorCheck(adi_dev_Control(AD7183DriverHandle,ADI_AD7183_CMD_SET_TWI_CONF
IG_TABLE,(void*)PseudoTWIConfig));

// do the register configuration here if needed.

#if defined(READ_REG_VALUE)
// read AD7183 status register
Read7183StatusReg(AD7183DriverHandle);
#endif
// start capturing video data
ezErrorCheck(adi_dev_Control(AD7183DriverHandle, ADI_DEV_CMD_SET_DATAFLOW,
(void*)TRUE));
}


BÁO CÁO ĐỒ ÁN MÔN HỌC TIN HỌC
Trang 16

3.6 StartADV7171
static void StartADV7171(void)
{
u32 Result = 0;
ezEnableVideoEncoder();// enable AD7171
//ezDisableVideoEncoder();// enable AD7171
// open the ad7171 driver
ezErrorCheck(adi_dev_Open( DeviceManagerHandle, // device manager
//handle
&ADIADV7171EntryPoint, // entry point of device driver to open
0, // the device number (0th AD7171)
(void *)0x7171, // client handle (0x7171 will be given
//to the AD7171 encoder driver)
&AD7171DriverHandle, // location where AD7171 device
//driver handle will be stored
ADI_DEV_DIRECTION_OUTBOUND,// direction the device is
//to be opened

DMAManagerHandle, // DMA Manager handle
NULL, // DCB handle (NULL cause we want live
//callbacks)
CallbackFunction)); // address of callback function

// configure the AD7171 driver(Set PPI Device number)
ezErrorCheck(adi_dev_Control( AD7171DriverHandle,
ADI_ADV717x_CMD_SET_PPI_DEVICE_NUMBER, (void*)0 ));

// configure the AD7171 driver(Open PPI Device)
ezErrorCheck(adi_dev_Control( AD7171DriverHandle,
ADI_ADV717x_CMD_SET_PPI_STATUS, (void*)ADI_ADV717x_PPI_OPEN ));

// Send Pseudo TWI Configuration table to AD7171 driver
Result =
adi_dev_Control(AD7171DriverHandle,ADI_ADV717x_CMD_SET_TWI_CONFI
BÁO CÁO ĐỒ ÁN MÔN HỌC TIN HỌC
Trang 17

G_TABLE,(void*)PseudoTWIConfig);
if ( Result != ADI_DEV_RESULT_SUCCESS) printf("Set TWI-config table
failed\n");

#if defined(READ_REG_VALUE)
// Read AD7171 registers before configuration
ReadEncoderRegs(AD7171DriverHandle);;
#endif

//**********************************************
//Setting the encoder mode

SetEncoderMode(AD7171DriverHandle,PAL);

#if defined(READ_REG_VALUE)
// Read AD7171 register value after configuration
ReadEncoderRegs(AD7171DriverHandle);
#endif

// populate AD7171 outbound buffers
Out1_Buffer2D.Data = (void*)sFrame0;// address of the data storage
Out1_Buffer2D.ElementWidth = sizeof(u32);
Out1_Buffer2D.XCount = (FRAME_DATA_LEN/2);
Out1_Buffer2D.XModify = 2;
Out1_Buffer2D.YCount = NUM_LINES;
Out1_Buffer2D.YModify = 2;
Out1_Buffer2D.CallbackParameter = NULL;
Out1_Buffer2D.pNext = &Out2_Buffer2D;// point to the next buffer in the chain


Out2_Buffer2D.Data = (void*)sFrame1;// address of the data storage
Out2_Buffer2D.ElementWidth = sizeof(u32);
Out2_Buffer2D.XCount = (FRAME_DATA_LEN/2);
BÁO CÁO ĐỒ ÁN MÔN HỌC TIN HỌC
Trang 18

Out2_Buffer2D.XModify = 2;
Out2_Buffer2D.YCount = NUM_LINES;
Out2_Buffer2D.YModify = 2;
Out2_Buffer2D.CallbackParameter = NULL;
Out2_Buffer2D.pNext = NULL;// terminate the chain of buffers


// configure the ad7171 dataflow method

ezErrorCheck(adi_dev_Control(AD7171DriverHandle,
ADI_DEV_CMD_SET_DATAFLOW_METHOD, (void
*)ADI_DEV_MODE_CHAINED_LOOPBACK));
ezErrorCheck(adi_dev_Write(AD7171DriverHandle, ADI_DEV_2D,
(ADI_DEV_BUFFER *)&Out1_Buffer2D));

// start outputting video data
ezErrorCheck(adi_dev_Control(AD7171DriverHandle,
ADI_DEV_CMD_SET_DATAFLOW, (void*)TRUE));
}


4. Kết quả thu được :
Ảnh gốc và ảnh bắt được.











BÁO CÁO ĐỒ ÁN MÔN HỌC TIN HỌC
Trang 19



































BÁO CÁO ĐỒ ÁN MÔN HỌC TIN HỌC
Trang 20


































BÁO CÁO ĐỒ ÁN MÔN HỌC TIN HỌC
Trang 21


































×