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> // To check Frame Buffer size |
---|
13 | |
---|
14 | #define FILENAME "misc/lena.raw" |
---|
15 | #define NPIXELS 256 |
---|
16 | #define NLINES 256 |
---|
17 | #define NIMAGES 1 |
---|
18 | |
---|
19 | #define INTERACTIVE 1 |
---|
20 | |
---|
21 | unsigned char buf0[NPIXELS*NLINES] __attribute__((aligned(512))); |
---|
22 | unsigned 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 | char byte; |
---|
38 | |
---|
39 | // parameters checking |
---|
40 | if ( (NPIXELS != FBUF_X_SIZE) || (NLINES != FBUF_Y_SIZE) ) |
---|
41 | { |
---|
42 | giet_exit("[DISPLAY ERROR] Frame buffer size does not fit image size"); |
---|
43 | } |
---|
44 | |
---|
45 | // get a private TTY |
---|
46 | giet_tty_alloc(); |
---|
47 | |
---|
48 | giet_tty_printf("\n[DISPLAY] Processor[%d,%d,%d] starts at cycle %d\n", |
---|
49 | x, y, lpid, giet_proctime() ); |
---|
50 | |
---|
51 | // open file |
---|
52 | fd = giet_fat_open( FILENAME , 0 ); |
---|
53 | |
---|
54 | giet_tty_printf("\n[DISPLAY] Proc[%d,%d,%d] open file %s at cycle %d\n", |
---|
55 | x, y, lpid, FILENAME, giet_proctime() ); |
---|
56 | |
---|
57 | // get a Chained Buffer DMA channel |
---|
58 | giet_fbf_cma_alloc(); |
---|
59 | |
---|
60 | // start Chained Buffer DMA channel |
---|
61 | giet_fbf_cma_start( buf0, buf1, NPIXELS*NLINES ); |
---|
62 | |
---|
63 | giet_tty_printf("\n[DISPLAY] Proc[%d,%d,%d] starts CMA at cycle %d\n", |
---|
64 | x, y, lpid, giet_proctime() ); |
---|
65 | |
---|
66 | // Main loop (on images) |
---|
67 | while ( 1 ) |
---|
68 | { |
---|
69 | // load buf0 |
---|
70 | giet_fat_read( fd, buf0, NPIXELS*NLINES ); |
---|
71 | |
---|
72 | giet_tty_printf("\n[DISPLAY] Proc[%d,%d,%d] load image %d at cycle %d\n", |
---|
73 | x, y, lpid, image, giet_proctime() ); |
---|
74 | |
---|
75 | // display buf0 |
---|
76 | giet_fbf_cma_display( 0 ); |
---|
77 | |
---|
78 | giet_tty_printf("\n[DISPLAY] Proc[%d,%d,%d] display image %d at cycle %d\n", |
---|
79 | x, y, lpid, image, giet_proctime() ); |
---|
80 | |
---|
81 | image = (image + 1) % NIMAGES; |
---|
82 | |
---|
83 | if ( INTERACTIVE ) giet_tty_getc( &byte ); |
---|
84 | |
---|
85 | // load buf1 |
---|
86 | giet_fat_read( fd, buf1, NPIXELS*NLINES ); |
---|
87 | |
---|
88 | giet_tty_printf("\n[DISPLAY] Proc[%d,%d,%d] load image %d at cycle %d\n", |
---|
89 | x, y, lpid, image, giet_proctime() ); |
---|
90 | |
---|
91 | // display buf1 |
---|
92 | giet_fbf_cma_display( 1 ); |
---|
93 | |
---|
94 | giet_tty_printf("\n[DISPLAY] Proc[%d,%d,%d] display image %d at cycle %d\n", |
---|
95 | x, y, lpid, image, giet_proctime() ); |
---|
96 | |
---|
97 | image = (image + 1) % NIMAGES; |
---|
98 | |
---|
99 | if ( INTERACTIVE ) giet_tty_getc( &byte ); |
---|
100 | } |
---|
101 | |
---|
102 | // stop Chained buffer DMA channel |
---|
103 | giet_fbf_cma_stop(); |
---|
104 | |
---|
105 | giet_exit("display completed"); |
---|
106 | } |
---|