display_driver_a

// uses DMA to display sections of SDRAM//

#include <stdio.h>#include "altera_avalon_pio_regs.h"#include <altera_avalon_sgdma.h>#include <altera_avalon_sgdma_descriptor.h>#include <altera_avalon_sgdma_regs.h>// DMA descriptors// alt_sgdma_descriptor dmaDescA[8]; alt_sgdma_descriptor dmaDescEND; // we locate our first framebuffer at the beginning of the SDRAM// alt_u32* frameBufferA = (alt_u32*)SDRAM_BASE; // this subroutine initializes a chain of descriptors//void init_framebuffer(alt_sgdma_dev *dma) { // 480*272 lines * 4 bytes = 522240 bytes // 65532 (0xfffc) bytes * 7 = 458724 // +63516 (0xf81c) bytes // frame buffer A alt_u8* buff = (alt_u8*)frameBufferA; int i; for(i = 0; i < 8; ++i) {

alt_u16 size = (i<7)?0xfffc:0xf81c; alt_avalon_sgdma_construct_mem_to_stream_desc( &dmaDescA[i], (i<7) ? (&dmaDescA[i+1]) : &dmaDescEND, (alt_u32*)buff, size, 0, i==0, i==7, 0); buff+= size; } } int main() { // switch on the backlight // IOWR_ALTERA_AVALON_PIO_DATA(PIO_LED_BASE, 64); // initialize the DMA and get a device handle //

alt_sgdma_dev *dma = alt_avalon_sgdma_open("/dev/sgdma"); printf("open dma returned %ld\n", (alt_u32)dma); printf("framebuffer 1 at %lx\n", (alt_u32)frameBufferA); // assert the DISP signal // IOWR_ALTERA_AVALON_PIO_DATA(PIO_LED_BASE, 128+64); // now we just continuously copy framebufferA to the Video Sync Generator // int count = 1; while(1) { // blink an led to see the program running IOWR_ALTERA_AVALON_PIO_DATA(PIO_LED_BASE, (count & 0x0001)+128+64); // init the descriptors // init_framebuffer(dma); // transfer alt_avalon_sgdma_do_sync_transfer(dma, dmaDescA); count++; } return 0; }