source: soft/giet_vm/applications/display/display.c @ 724

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

Update graphical applications.

File size: 3.9 KB
Line 
1///////////////////////////////////////////////////////////////////////////////////////
2//  file   : display.c 
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>     // To check Frame Buffer size
13
14#define FILENAME    "misc/images_128.raw"
15#define NPIXELS     128
16#define NLINES      128
17#define NIMAGES     10                 
18
19#define INTERACTIVE 0
20
21unsigned char buf0[NPIXELS*NLINES] __attribute__((aligned(64)));
22unsigned char buf1[NPIXELS*NLINES] __attribute__((aligned(64)));
23
24unsigned int  sts0[16]  __attribute__((aligned(64)));
25unsigned int  sts1[16]  __attribute__((aligned(64)));
26
27////////////////////////////////////////////
28__attribute__((constructor)) void main()
29////////////////////////////////////////////
30{
31    // get processor identifiers
32    unsigned int    x;
33    unsigned int    y; 
34    unsigned int    p;
35    giet_proc_xyp( &x, &y, &p );
36
37    int             fd;
38    unsigned int    image = 0;
39    char            byte;
40    unsigned int    fbuf_x_size;
41    unsigned int    fbuf_y_size;
42
43    // checking frame buffer size
44    giet_fbf_size( &fbuf_x_size , &fbuf_y_size );
45    giet_pthread_assert( ((NPIXELS == fbuf_x_size) && (NLINES == fbuf_y_size)),
46                         "[DISPLAY ERROR] Frame buffer size does not fit image size");
47
48    // get a private TTY
49    giet_tty_alloc(0);
50
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 );
58
59    // open file
60    fd = giet_fat_open( FILENAME , 0 );
61
62    giet_tty_printf("\n[DISPLAY] P[%d,%d,%d] open file %s at cycle %d\n", 
63                    x, y, p, FILENAME, giet_proctime() );
64
65    // get Frame Buffer ownership
66    giet_fbf_alloc();
67
68    // get a Chained Buffer DMA channel for two user buffers
69    giet_fbf_cma_alloc( 2 );
70
71    // register the two user buffers
72    giet_fbf_cma_init_buf( 0 , buf0 , sts0 );
73    giet_fbf_cma_init_buf( 1 , buf1 , sts1 );
74
75    // start CMA peripheral
76    giet_fbf_cma_start();
77   
78    giet_tty_printf("\n[DISPLAY] Proc[%d,%d,%d] starts CMA at cycle %d\n", 
79                    x, y, p, giet_proctime() );
80
81    // Main loop on images
82    while ( 1 )
83    {
84        //////   handling buf0
85        giet_fbf_cma_check( 0 );                       // check buf0 empty
86        giet_fat_read( fd, buf0, NPIXELS*NLINES );     // load buf0 from disk
87        giet_fbf_cma_display( 0 );                     // display buf0
88
89        giet_tty_printf("\n[DISPLAY] Proc[%d,%d,%d] display image %d at cycle %d\n", 
90                        x, y, p, image, giet_proctime() );
91        image++;
92
93        if ( image == NIMAGES )
94        {
95            image = 0;
96            giet_fat_lseek( fd , 0 , SEEK_SET );
97        }
98
99        if ( INTERACTIVE ) giet_tty_getc( &byte );
100
101        //////   handling buf1
102        giet_fbf_cma_check( 1 );                       // check buf1 empty
103        giet_fat_read( fd, buf1, NPIXELS*NLINES );     // load buf1 from disk
104        giet_fbf_cma_display( 1 );                     // display buf1
105
106        giet_tty_printf("\n[DISPLAY] Proc[%d,%d,%d] display image %d at cycle %d\n", 
107                        x, y, p, image, giet_proctime() );
108        image++;
109
110        if ( image == NIMAGES )
111        {
112            image = 0;
113            giet_fat_lseek( fd , 0 , SEEK_SET );
114        }
115
116        if ( INTERACTIVE ) giet_tty_getc( &byte );
117    }
118
119    // stop Chained buffer DMA channel
120    giet_fbf_cma_stop();
121
122    giet_pthread_exit("completed");
123}
Note: See TracBrowser for help on using the repository browser.