Цитата(Men @ Mar 26 2009, 15:51)

Поясните на примере как пользоватся этими инструкциями потому что в доках и примерах от alterы ничего не понятно.
CODE
#include <stdio.h>
#include "system.h"
#include "altera_avalon_video_dma.h"
#include "altera_avalon_video_out_dma.h"
#include "altera_avalon_video_dma_regs.h"
#include "altera_avalon_video_out_dma_regs.h"
#define PIXELS 512
#define LINES 512
int dma_base[2] = {VIDEO_DMA_0_BASE, VIDEO_DMA_1_BASE};
unsigned char * buf[2];
volatile int in_frame_ready[2];
//--------------------------------------- input video dma ----------------------------------------------------------------------------
static void handle_dma_0_interrupts(void* context, alt_u32 id)
{
volatile int* edge_capture_ptr = (volatile int*) context;
*edge_capture_ptr = IORD_ALTERA_AVALON_VIDEO_DMA_EDGE_CAPTURE(VIDEO_DMA_0_BASE);
// Reset edge capture register.
IOWR_ALTERA_AVALON_VIDEO_DMA_EDGE_CAPTURE(VIDEO_DMA_0_BASE, 0);
}
static void init_dma_0_interrupts()
{
void* edge_capture_ptr = (void*) &in_frame_ready[0];
// Enable interrupts.
IOWR_ALTERA_AVALON_VIDEO_DMA_IRQ_MASK(VIDEO_DMA_0_BASE, 1);
// Reset the edge capture register.
IOWR_ALTERA_AVALON_VIDEO_DMA_EDGE_CAPTURE(VIDEO_DMA_0_BASE, 0x0);
// Register the interrupt handler.
alt_irq_register( VIDEO_DMA_0_IRQ, edge_capture_ptr, handle_dma_0_interrupts );
}
static void handle_dma_1_interrupts(void* context, alt_u32 id)
{
volatile int* edge_capture_ptr = (volatile int*) context;
*edge_capture_ptr = IORD_ALTERA_AVALON_VIDEO_DMA_EDGE_CAPTURE(VIDEO_DMA_1_BASE);
// Reset edge capture register.
IOWR_ALTERA_AVALON_VIDEO_DMA_EDGE_CAPTURE(VIDEO_DMA_1_BASE, 0);
}
static void init_dma_1_interrupts()
{
void* edge_capture_ptr = (void*) &in_frame_ready[1];
// Enable interrupts.
IOWR_ALTERA_AVALON_VIDEO_DMA_IRQ_MASK(VIDEO_DMA_1_BASE, 1);
// Reset the edge capture register.
IOWR_ALTERA_AVALON_VIDEO_DMA_EDGE_CAPTURE(VIDEO_DMA_1_BASE, 0x0);
// Register the interrupt handler.
alt_irq_register( VIDEO_DMA_1_IRQ, edge_capture_ptr, handle_dma_1_interrupts );
}
//-------------------------------------------------------------------------------------------------------------------------
volatile int out_frame_ready;
//--------------------------------------------------------- output video dma -------------------------------------------
static void handle_dma_out_interrupts(void* context, alt_u32 id)
{
volatile int* edge_capture_ptr = (volatile int*) context;
*edge_capture_ptr = IORD_ALTERA_AVALON_VIDEO_OUT_DMA_EDGE_CAPTURE(VIDEO_OUT_DMA_0_BASE);
// Reset edge capture register.
IOWR_ALTERA_AVALON_VIDEO_OUT_DMA_EDGE_CAPTURE(VIDEO_OUT_DMA_0_BASE, 0);
}
static void init_dma_out_interrupts()
{
void* edge_capture_ptr = (void*) &out_frame_ready;
// Enable all 4 button interrupts.
IOWR_ALTERA_AVALON_VIDEO_OUT_DMA_IRQ_MASK(VIDEO_OUT_DMA_0_BASE, 1);
// Reset the edge capture register.
IOWR_ALTERA_AVALON_VIDEO_OUT_DMA_EDGE_CAPTURE(VIDEO_OUT_DMA_0_BASE, 0x0);
// Register the interrupt handler.
alt_irq_register( VIDEO_OUT_DMA_0_IRQ, edge_capture_ptr,
handle_dma_out_interrupts );
}
//------------------------------------------------------------------------------------------------------------------------------------------
int main()
{
int i;
// init input video dma
for(i=0; i<2; i++)
{
buf[i] = malloc(512*512*2); // 8MB SDRAM
reset_video_dma(dma_base[i]);
init_video_dma(dma_base[i], buf[i], PIXELS*LINES*2);
}
// init output video dma
reset_video_out_dma(VIDEO_OUT_DMA_0_BASE);
init_video_out_dma(VIDEO_OUT_DMA_0_BASE, buf[0], PIXELS, LINES);
// init interuupts
init_dma_0_interrupts();
init_dma_1_interrupts();
init_dma_out_interrupts();
// start input video dma
for(i=0; i<2; i++)
{
go_video_dma(dma_base[i]);
}
int curr_dma_base = dma_base[0];
out_frame_ready = 1;
while(1)
{
// Video input interrupts. Video out interrupts.
for(i=0; i<2; i++)
{
if(in_frame_ready[i] && out_frame_ready)
{
if(curr_dma_base == dma_base[i]) continue;
out_frame_ready = 0;
// change video buffer
IOWR_ALTERA_AVALON_VIDEO_OUT_DMA_ADDRESS(VIDEO_OUT_DMA_0_BASE, buf[i]);
// start output video dma
go_video_out_dma(VIDEO_OUT_DMA_0_BASE);
in_frame_ready[i] = 0;
// start input video dma
go_video_dma(curr_dma_base);
curr_dma_base = dma_base[i];
}
}
};
return 0;
}