1 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
2 | // file : main.c (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_128.raw" |
---|
15 | #define NPIXELS 128 |
---|
16 | #define NLINES 128 |
---|
17 | #define NIMAGES 10 |
---|
18 | |
---|
19 | #define INTERACTIVE 0 |
---|
20 | |
---|
21 | unsigned char buf0[NPIXELS*NLINES] __attribute__((aligned(64))); |
---|
22 | unsigned char buf1[NPIXELS*NLINES] __attribute__((aligned(64))); |
---|
23 | |
---|
24 | unsigned int sts0[16] __attribute__((aligned(64))); |
---|
25 | unsigned 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 | |
---|
40 | char byte; |
---|
41 | |
---|
42 | // parameters checking |
---|
43 | if ( (NPIXELS != FBUF_X_SIZE) || (NLINES != FBUF_Y_SIZE) ) |
---|
44 | { |
---|
45 | giet_exit("[DISPLAY ERROR] Frame buffer size does not fit image size"); |
---|
46 | } |
---|
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 a Chained Buffer DMA channel |
---|
66 | giet_fbf_cma_alloc(); |
---|
67 | |
---|
68 | // initialize the source and destination chbufs |
---|
69 | giet_fbf_cma_init_buf( buf0 , buf1 , sts0 , sts1 ); |
---|
70 | |
---|
71 | // start Chained Buffer DMA channel |
---|
72 | giet_fbf_cma_start( NPIXELS*NLINES ); |
---|
73 | |
---|
74 | giet_tty_printf("\n[DISPLAY] Proc[%d,%d,%d] starts CMA at cycle %d\n", |
---|
75 | x, y, p, giet_proctime() ); |
---|
76 | |
---|
77 | // Main loop on images |
---|
78 | while ( 1 ) |
---|
79 | { |
---|
80 | // load buf0 |
---|
81 | giet_fat_read( fd, buf0, NPIXELS*NLINES ); |
---|
82 | |
---|
83 | giet_tty_printf("\n[DISPLAY] Proc[%d,%d,%d] load image %d at cycle %d\n", |
---|
84 | x, y, p, image, giet_proctime() ); |
---|
85 | |
---|
86 | // display buf0 |
---|
87 | giet_fbf_cma_display( 0 ); |
---|
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 | |
---|
92 | image++; |
---|
93 | |
---|
94 | if ( image == NIMAGES ) |
---|
95 | { |
---|
96 | image = 0; |
---|
97 | giet_fat_lseek( fd , 0 , 0 ); |
---|
98 | } |
---|
99 | |
---|
100 | if ( INTERACTIVE ) giet_tty_getc( &byte ); |
---|
101 | |
---|
102 | // load buf1 |
---|
103 | giet_fat_read( fd, buf1, NPIXELS*NLINES ); |
---|
104 | |
---|
105 | giet_tty_printf("\n[DISPLAY] Proc[%d,%d,%d] load image %d at cycle %d\n", |
---|
106 | x, y, p, image, giet_proctime() ); |
---|
107 | |
---|
108 | // display buf1 |
---|
109 | giet_fbf_cma_display( 1 ); |
---|
110 | |
---|
111 | giet_tty_printf("\n[DISPLAY] Proc[%d,%d,%d] display image %d at cycle %d\n", |
---|
112 | x, y, p, image, giet_proctime() ); |
---|
113 | |
---|
114 | image++; |
---|
115 | |
---|
116 | if ( image == NIMAGES ) |
---|
117 | { |
---|
118 | image = 0; |
---|
119 | giet_fat_lseek( fd , 0 , 0 ); |
---|
120 | } |
---|
121 | |
---|
122 | if ( INTERACTIVE ) giet_tty_getc( &byte ); |
---|
123 | } |
---|
124 | |
---|
125 | // stop Chained buffer DMA channel |
---|
126 | giet_fbf_cma_stop(); |
---|
127 | |
---|
128 | giet_exit("display completed"); |
---|
129 | } |
---|