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/images.raw" |
---|
15 | #define NPIXELS 128 |
---|
16 | #define NLINES 128 |
---|
17 | #define NIMAGES 20 |
---|
18 | #define NBLOCKS (NPIXELS*NLINES/512) // number of blocks per image |
---|
19 | |
---|
20 | #define INTERACTIVE 1 |
---|
21 | |
---|
22 | unsigned char buf0[NPIXELS*NLINES] __attribute__((aligned(512))); |
---|
23 | unsigned char buf1[NPIXELS*NLINES] __attribute__((aligned(512))); |
---|
24 | |
---|
25 | //////////////////////////////////////////// |
---|
26 | __attribute__((constructor)) void main() |
---|
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 | |
---|
35 | int fd; |
---|
36 | unsigned int image = 0; |
---|
37 | |
---|
38 | char byte; |
---|
39 | |
---|
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 | } |
---|
45 | |
---|
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", |
---|
50 | x, y, lpid, giet_proctime() ); |
---|
51 | |
---|
52 | // open file |
---|
53 | fd = giet_fat_open( FILENAME , 0 ); |
---|
54 | |
---|
55 | giet_tty_printf("\n[DISPLAY] Proc[%d,%d,%d] open file %s at cycle %d\n", |
---|
56 | x, y, lpid, FILENAME, giet_proctime() ); |
---|
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_tty_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 ( 1 ) |
---|
69 | { |
---|
70 | // load buf0 |
---|
71 | giet_fat_read( fd, buf0, NBLOCKS, image*NBLOCKS ); |
---|
72 | |
---|
73 | giet_tty_printf("\n[DISPLAY] Proc[%d,%d,%d] load image %d at cycle %d\n", |
---|
74 | x, y, lpid, image, giet_proctime() ); |
---|
75 | |
---|
76 | // display buf0 |
---|
77 | giet_fbf_cma_display( 0 ); |
---|
78 | |
---|
79 | giet_tty_printf("\n[DISPLAY] Proc[%d,%d,%d] display image %d at cycle %d\n", |
---|
80 | x, y, lpid, image, giet_proctime() ); |
---|
81 | |
---|
82 | image = (image + 1) % NIMAGES; |
---|
83 | |
---|
84 | if ( INTERACTIVE ) giet_tty_getc( &byte ); |
---|
85 | |
---|
86 | // load buf1 |
---|
87 | giet_fat_read( fd, buf1, NBLOCKS, image*NBLOCKS ); |
---|
88 | |
---|
89 | giet_tty_printf("\n[DISPLAY] Proc[%d,%d,%d] load image %d at cycle %d\n", |
---|
90 | x, y, lpid, image, giet_proctime() ); |
---|
91 | |
---|
92 | // display buf1 |
---|
93 | giet_fbf_cma_display( 1 ); |
---|
94 | |
---|
95 | giet_tty_printf("\n[DISPLAY] Proc[%d,%d,%d] display image %d at cycle %d\n", |
---|
96 | x, y, lpid, image, giet_proctime() ); |
---|
97 | |
---|
98 | image = (image + 1) % NIMAGES; |
---|
99 | |
---|
100 | if ( INTERACTIVE ) giet_tty_getc( &byte ); |
---|
101 | } |
---|
102 | |
---|
103 | // stop Chained buffer DMA channel |
---|
104 | giet_fbf_cma_stop(); |
---|
105 | |
---|
106 | giet_exit("display completed"); |
---|
107 | } |
---|