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

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

Introducing application "display"

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