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 <stdlib.h> |
---|
13 | #include <hard_config.h> // To check Frame Buffer size |
---|
14 | |
---|
15 | #define FILENAME "misc/images_128.raw" |
---|
16 | #define NPIXELS 128 |
---|
17 | #define NLINES 128 |
---|
18 | #define NIMAGES 10 |
---|
19 | |
---|
20 | #define INTERACTIVE 0 |
---|
21 | |
---|
22 | unsigned char buf0[NPIXELS*NLINES] __attribute__((aligned(64))); |
---|
23 | unsigned char buf1[NPIXELS*NLINES] __attribute__((aligned(64))); |
---|
24 | |
---|
25 | unsigned int sts0[16] __attribute__((aligned(64))); |
---|
26 | unsigned int sts1[16] __attribute__((aligned(64))); |
---|
27 | |
---|
28 | //////////////////////////////////////////// |
---|
29 | __attribute__((constructor)) void main() |
---|
30 | //////////////////////////////////////////// |
---|
31 | { |
---|
32 | // get processor identifiers |
---|
33 | unsigned int x; |
---|
34 | unsigned int y; |
---|
35 | unsigned int p; |
---|
36 | giet_proc_xyp( &x, &y, &p ); |
---|
37 | |
---|
38 | int fd; |
---|
39 | unsigned int image = 0; |
---|
40 | char byte; |
---|
41 | unsigned int fbuf_x_size; |
---|
42 | unsigned int fbuf_y_size; |
---|
43 | |
---|
44 | // checking frame buffer size |
---|
45 | giet_fbf_size( &fbuf_x_size , &fbuf_y_size ); |
---|
46 | giet_pthread_assert( ((NPIXELS == fbuf_x_size) && (NLINES == fbuf_y_size)), |
---|
47 | "[DISPLAY ERROR] Frame buffer size does not fit image size"); |
---|
48 | |
---|
49 | // get a private TTY |
---|
50 | giet_tty_alloc(0); |
---|
51 | |
---|
52 | giet_tty_printf("\n[DISPLAY] P[%d,%d,%d] starts at cycle %d\n" |
---|
53 | " - buf0_vaddr = %x\n" |
---|
54 | " - buf1_vaddr = %x\n" |
---|
55 | " - sts0_vaddr = %x\n" |
---|
56 | " - sts1_vaddr = %x\n", |
---|
57 | x, y, p, giet_proctime(), |
---|
58 | buf0, buf1, sts0, sts1 ); |
---|
59 | |
---|
60 | // open file |
---|
61 | fd = giet_fat_open( FILENAME , 0 ); |
---|
62 | |
---|
63 | giet_tty_printf("\n[DISPLAY] P[%d,%d,%d] open file %s at cycle %d\n", |
---|
64 | x, y, p, FILENAME, giet_proctime() ); |
---|
65 | |
---|
66 | // get Frame Buffer ownership |
---|
67 | giet_fbf_alloc(); |
---|
68 | |
---|
69 | // get a Chained Buffer DMA channel |
---|
70 | giet_fbf_cma_alloc(); |
---|
71 | |
---|
72 | // initialize the source and destination chbufs |
---|
73 | giet_fbf_cma_init_buf( buf0 , buf1 , sts0 , sts1 ); |
---|
74 | |
---|
75 | // start Chained Buffer DMA channel |
---|
76 | giet_fbf_cma_start( NPIXELS*NLINES ); |
---|
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 | // load buf0 |
---|
85 | giet_fat_read( fd, buf0, NPIXELS*NLINES ); |
---|
86 | |
---|
87 | giet_tty_printf("\n[DISPLAY] Proc[%d,%d,%d] load image %d at cycle %d\n", |
---|
88 | x, y, p, image, giet_proctime() ); |
---|
89 | |
---|
90 | // display buf0 |
---|
91 | giet_fbf_cma_display( 0 ); |
---|
92 | |
---|
93 | giet_tty_printf("\n[DISPLAY] Proc[%d,%d,%d] display image %d at cycle %d\n", |
---|
94 | x, y, p, image, giet_proctime() ); |
---|
95 | |
---|
96 | image++; |
---|
97 | |
---|
98 | if ( image == NIMAGES ) |
---|
99 | { |
---|
100 | image = 0; |
---|
101 | giet_fat_lseek( fd , 0 , 0 ); |
---|
102 | } |
---|
103 | |
---|
104 | if ( INTERACTIVE ) giet_tty_getc( &byte ); |
---|
105 | |
---|
106 | // load buf1 |
---|
107 | giet_fat_read( fd, buf1, NPIXELS*NLINES ); |
---|
108 | |
---|
109 | giet_tty_printf("\n[DISPLAY] Proc[%d,%d,%d] load image %d at cycle %d\n", |
---|
110 | x, y, p, image, giet_proctime() ); |
---|
111 | |
---|
112 | // display buf1 |
---|
113 | giet_fbf_cma_display( 1 ); |
---|
114 | |
---|
115 | giet_tty_printf("\n[DISPLAY] Proc[%d,%d,%d] display image %d at cycle %d\n", |
---|
116 | x, y, p, image, giet_proctime() ); |
---|
117 | |
---|
118 | image++; |
---|
119 | |
---|
120 | if ( image == NIMAGES ) |
---|
121 | { |
---|
122 | image = 0; |
---|
123 | giet_fat_lseek( fd , 0 , 0 ); |
---|
124 | } |
---|
125 | |
---|
126 | if ( INTERACTIVE ) giet_tty_getc( &byte ); |
---|
127 | } |
---|
128 | |
---|
129 | // stop Chained buffer DMA channel |
---|
130 | giet_fbf_cma_stop(); |
---|
131 | |
---|
132 | giet_pthread_exit("completed"); |
---|
133 | } |
---|