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

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

Adapt the router application to the POSIX API.

File size: 4.0 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
69    giet_fbf_cma_alloc();
70
71    // initialize the source and destination chbufs
72    giet_fbf_cma_init_buf( buf0 , buf1 , sts0 , sts1 );
73
74    // start Chained Buffer DMA channel
75    giet_fbf_cma_start( NPIXELS*NLINES );
76   
77    giet_tty_printf("\n[DISPLAY] Proc[%d,%d,%d] starts CMA at cycle %d\n", 
78                    x, y, p, giet_proctime() );
79
80    // Main loop on images
81    while ( 1 )
82    {
83        // load buf0
84        giet_fat_read( fd, buf0, NPIXELS*NLINES );
85
86        giet_tty_printf("\n[DISPLAY] Proc[%d,%d,%d] load image %d at cycle %d\n", 
87                        x, y, p, image, giet_proctime() );
88
89        // display buf0
90        giet_fbf_cma_display( 0 );
91
92        giet_tty_printf("\n[DISPLAY] Proc[%d,%d,%d] display image %d at cycle %d\n", 
93                        x, y, p, image, giet_proctime() );
94
95        image++;
96
97        if ( image == NIMAGES )
98        {
99            image = 0;
100            giet_fat_lseek( fd , 0 , 0 );
101        }
102
103        if ( INTERACTIVE ) giet_tty_getc( &byte );
104
105        // load buf1
106        giet_fat_read( fd, buf1, NPIXELS*NLINES );
107
108        giet_tty_printf("\n[DISPLAY] Proc[%d,%d,%d] load image %d at cycle %d\n", 
109                        x, y, p, image, giet_proctime() );
110
111        // display buf1
112        giet_fbf_cma_display( 1 );
113
114        giet_tty_printf("\n[DISPLAY] Proc[%d,%d,%d] display image %d at cycle %d\n", 
115                        x, y, p, image, giet_proctime() );
116
117        image++;
118
119        if ( image == NIMAGES )
120        {
121            image = 0;
122            giet_fat_lseek( fd , 0 , 0 );
123        }
124
125        if ( INTERACTIVE ) giet_tty_getc( &byte );
126    }
127
128    // stop Chained buffer DMA channel
129    giet_fbf_cma_stop();
130
131    giet_pthread_exit("completed");
132}
Note: See TracBrowser for help on using the repository browser.