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

Last change on this file since 568 was 555, checked in by alain, 10 years ago

Update coproc application to use the newly defined coprocessor system calls.

File size: 3.3 KB
RevLine 
[555]1///////////////////////////////////////////////////////////////////////////////////////
[444]2//  file   : main.c  (for display application)
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
[444]14#define FILENAME    "misc/images.raw"
15#define NPIXELS     128
16#define NLINES      128
[544]17#define NIMAGES     20                 
[444]18#define NBLOCKS     (NPIXELS*NLINES/512)   // number of blocks per image
[249]19
[544]20#define INTERACTIVE 1
[444]21
22unsigned char buf0[NPIXELS*NLINES] __attribute__((aligned(512)));
23unsigned char buf1[NPIXELS*NLINES] __attribute__((aligned(512)));
24
25////////////////////////////////////////////
[258]26__attribute__((constructor)) void main()
[444]27////////////////////////////////////////////
28{
29    // get processor identifiers
30    unsigned int    x;
31    unsigned int    y; 
32    unsigned int    lpid;
33    giet_proc_xyp( &x, &y, &lpid );
34
[295]35    int             fd;
[444]36    unsigned int    image = 0;
[207]37
[544]38    char            byte;
39
[444]40    // parameters checking
41    if ( (NPIXELS != FBUF_X_SIZE) || (NLINES != FBUF_Y_SIZE) )
42    {
43        giet_exit("[DISPLAY ERROR] Frame buffer size does not fit image size");
44    }
[254]45
[544]46    // get a private TTY
47    giet_tty_alloc();
48
49    giet_tty_printf("\n[DISPLAY] Processor[%d,%d,%d] starts at cycle %d\n",
[444]50                    x, y, lpid, giet_proctime() );
[295]51
[444]52    // open file
53    fd = giet_fat_open( FILENAME , 0 );
[544]54
55    giet_tty_printf("\n[DISPLAY] Proc[%d,%d,%d] open file %s at cycle %d\n", 
[444]56                    x, y, lpid, FILENAME, giet_proctime() );
[254]57
[444]58    // get a Chained Buffer DMA channel
59    giet_fbf_cma_alloc();
[297]60
[444]61    // start Chained Buffer DMA channel
62    giet_fbf_cma_start( buf0, buf1, NPIXELS*NLINES );
63   
[544]64    giet_tty_printf("\n[DISPLAY] Proc[%d,%d,%d] starts CMA at cycle %d\n", 
[444]65                    x, y, lpid, giet_proctime() );
66
67    // Main loop (on images)
[544]68    while ( 1 )
[191]69    {
[480]70        // load buf0
[444]71        giet_fat_read( fd, buf0, NBLOCKS, image*NBLOCKS );
[191]72
[544]73        giet_tty_printf("\n[DISPLAY] Proc[%d,%d,%d] load image %d at cycle %d\n", 
[444]74                        x, y, lpid, image, giet_proctime() );
[254]75
[480]76        // display buf0
[444]77        giet_fbf_cma_display( 0 );
[297]78
[544]79        giet_tty_printf("\n[DISPLAY] Proc[%d,%d,%d] display image %d at cycle %d\n", 
[444]80                        x, y, lpid, image, giet_proctime() );
81
[544]82        image = (image + 1) % NIMAGES;
[444]83
[544]84        if ( INTERACTIVE ) giet_tty_getc( &byte );
85
[480]86        // load buf1
[444]87        giet_fat_read( fd, buf1, NBLOCKS, image*NBLOCKS );
88
[544]89        giet_tty_printf("\n[DISPLAY] Proc[%d,%d,%d] load image %d at cycle %d\n", 
[444]90                        x, y, lpid, image, giet_proctime() );
91
[480]92        // display buf1
[444]93        giet_fbf_cma_display( 1 );
94
[544]95        giet_tty_printf("\n[DISPLAY] Proc[%d,%d,%d] display image %d at cycle %d\n", 
[444]96                        x, y, lpid, image, giet_proctime() );
97
[544]98        image = (image + 1) % NIMAGES;
99
100        if ( INTERACTIVE ) giet_tty_getc( &byte );
[258]101    }
[254]102
[444]103    // stop Chained buffer DMA channel
104    giet_fbf_cma_stop();
105
106    giet_exit("display completed");
[191]107}
Note: See TracBrowser for help on using the repository browser.