source: soft/giet_vm/applications/display/main.c @ 669

Last change on this file since 669 was 669, checked in by alain, 9 years ago

Introduce support for the "shared" argument in the giet_tty_alloc() system call,
and replace the giet_shr_printf() system call by giet_tty_printf().

File size: 3.8 KB
RevLine 
[555]1///////////////////////////////////////////////////////////////////////////////////////
[644]2//  file   : main.c     (display application)
[444]3//  date   : may 2014
4//  author : Alain Greiner
5///////////////////////////////////////////////////////////////////////////////////////
6//  This file describes the single thread "display" application.
7//  It uses the external chained buffer DMA to display a stream
8//  of images on the frame buffer. 
9///////////////////////////////////////////////////////////////////////////////////////
[191]10
[444]11#include <stdio.h>
[555]12#include <hard_config.h>     // To check Frame Buffer size
[191]13
[644]14#define FILENAME    "misc/images_128.raw"
15#define NPIXELS     128
16#define NLINES      128
17#define NIMAGES     10                 
[249]18
[669]19#define INTERACTIVE 0
[444]20
[644]21unsigned char buf0[NPIXELS*NLINES] __attribute__((aligned(64)));
22unsigned char buf1[NPIXELS*NLINES] __attribute__((aligned(64)));
[444]23
[644]24unsigned int  sts0[16]  __attribute__((aligned(64)));
25unsigned int  sts1[16]  __attribute__((aligned(64)));
26
[444]27////////////////////////////////////////////
[258]28__attribute__((constructor)) void main()
[444]29////////////////////////////////////////////
30{
31    // get processor identifiers
32    unsigned int    x;
33    unsigned int    y; 
[644]34    unsigned int    p;
35    giet_proc_xyp( &x, &y, &p );
[444]36
[295]37    int             fd;
[444]38    unsigned int    image = 0;
[207]39
[544]40    char            byte;
41
[444]42    // parameters checking
43    if ( (NPIXELS != FBUF_X_SIZE) || (NLINES != FBUF_Y_SIZE) )
44    {
45        giet_exit("[DISPLAY ERROR] Frame buffer size does not fit image size");
46    }
[254]47
[544]48    // get a private TTY
[669]49    giet_tty_alloc(0);
[544]50
[644]51    giet_tty_printf("\n[DISPLAY] P[%d,%d,%d] starts at cycle %d\n"
52                    "  - buf0_vaddr = %x\n" 
53                    "  - buf1_vaddr = %x\n" 
54                    "  - sts0_vaddr = %x\n" 
55                    "  - sts1_vaddr = %x\n",
56                    x, y, p, giet_proctime(),
57                    buf0, buf1, sts0, sts1 );
[295]58
[444]59    // open file
60    fd = giet_fat_open( FILENAME , 0 );
[544]61
[644]62    giet_tty_printf("\n[DISPLAY] P[%d,%d,%d] open file %s at cycle %d\n", 
63                    x, y, p, FILENAME, giet_proctime() );
[254]64
[444]65    // get a Chained Buffer DMA channel
66    giet_fbf_cma_alloc();
[297]67
[644]68    // initialize the source and destination chbufs
69    giet_fbf_cma_init_buf( buf0 , buf1 , sts0 , sts1 );
70
[444]71    // start Chained Buffer DMA channel
[644]72    giet_fbf_cma_start( NPIXELS*NLINES );
[444]73   
[544]74    giet_tty_printf("\n[DISPLAY] Proc[%d,%d,%d] starts CMA at cycle %d\n", 
[644]75                    x, y, p, giet_proctime() );
[444]76
[644]77    // Main loop on images
[544]78    while ( 1 )
[191]79    {
[480]80        // load buf0
[589]81        giet_fat_read( fd, buf0, NPIXELS*NLINES );
[191]82
[544]83        giet_tty_printf("\n[DISPLAY] Proc[%d,%d,%d] load image %d at cycle %d\n", 
[644]84                        x, y, p, image, giet_proctime() );
[254]85
[480]86        // display buf0
[444]87        giet_fbf_cma_display( 0 );
[297]88
[544]89        giet_tty_printf("\n[DISPLAY] Proc[%d,%d,%d] display image %d at cycle %d\n", 
[644]90                        x, y, p, image, giet_proctime() );
[444]91
[644]92        image++;
[444]93
[644]94        if ( image == NIMAGES )
95        {
96            image = 0;
97            giet_fat_lseek( fd , 0 , 0 );
98        }
99
[544]100        if ( INTERACTIVE ) giet_tty_getc( &byte );
101
[480]102        // load buf1
[589]103        giet_fat_read( fd, buf1, NPIXELS*NLINES );
[444]104
[544]105        giet_tty_printf("\n[DISPLAY] Proc[%d,%d,%d] load image %d at cycle %d\n", 
[644]106                        x, y, p, image, giet_proctime() );
[444]107
[480]108        // display buf1
[444]109        giet_fbf_cma_display( 1 );
110
[544]111        giet_tty_printf("\n[DISPLAY] Proc[%d,%d,%d] display image %d at cycle %d\n", 
[644]112                        x, y, p, image, giet_proctime() );
[444]113
[644]114        image++;
[544]115
[644]116        if ( image == NIMAGES )
117        {
118            image = 0;
119            giet_fat_lseek( fd , 0 , 0 );
120        }
121
[544]122        if ( INTERACTIVE ) giet_tty_getc( &byte );
[258]123    }
[254]124
[444]125    // stop Chained buffer DMA channel
126    giet_fbf_cma_stop();
127
128    giet_exit("display completed");
[191]129}
Note: See TracBrowser for help on using the repository browser.