[708] | 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 | |
---|
| 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 | char byte; |
---|
[712] | 40 | unsigned int fbuf_x_size; |
---|
| 41 | unsigned int fbuf_y_size; |
---|
[708] | 42 | |
---|
[712] | 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"); |
---|
[708] | 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 | |
---|
[712] | 65 | // get Frame Buffer ownership |
---|
| 66 | giet_fbf_alloc(); |
---|
| 67 | |
---|
[724] | 68 | // get a Chained Buffer DMA channel for two user buffers |
---|
| 69 | giet_fbf_cma_alloc( 2 ); |
---|
[708] | 70 | |
---|
[724] | 71 | // register the two user buffers |
---|
| 72 | giet_fbf_cma_init_buf( 0 , buf0 , sts0 ); |
---|
| 73 | giet_fbf_cma_init_buf( 1 , buf1 , sts1 ); |
---|
[708] | 74 | |
---|
[724] | 75 | // start CMA peripheral |
---|
| 76 | giet_fbf_cma_start(); |
---|
[708] | 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 | { |
---|
[724] | 84 | ////// handling buf0 |
---|
| 85 | giet_fbf_cma_check( 0 ); // check buf0 empty |
---|
| 86 | giet_fat_read( fd, buf0, NPIXELS*NLINES ); // load buf0 from disk |
---|
| 87 | giet_fbf_cma_display( 0 ); // display buf0 |
---|
[708] | 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 | image++; |
---|
| 92 | |
---|
| 93 | if ( image == NIMAGES ) |
---|
| 94 | { |
---|
| 95 | image = 0; |
---|
[724] | 96 | giet_fat_lseek( fd , 0 , SEEK_SET ); |
---|
[708] | 97 | } |
---|
| 98 | |
---|
| 99 | if ( INTERACTIVE ) giet_tty_getc( &byte ); |
---|
| 100 | |
---|
[724] | 101 | ////// handling buf1 |
---|
| 102 | giet_fbf_cma_check( 1 ); // check buf1 empty |
---|
| 103 | giet_fat_read( fd, buf1, NPIXELS*NLINES ); // load buf1 from disk |
---|
| 104 | giet_fbf_cma_display( 1 ); // display buf1 |
---|
[708] | 105 | |
---|
| 106 | giet_tty_printf("\n[DISPLAY] Proc[%d,%d,%d] display image %d at cycle %d\n", |
---|
| 107 | x, y, p, image, giet_proctime() ); |
---|
| 108 | image++; |
---|
| 109 | |
---|
| 110 | if ( image == NIMAGES ) |
---|
| 111 | { |
---|
| 112 | image = 0; |
---|
[724] | 113 | giet_fat_lseek( fd , 0 , SEEK_SET ); |
---|
[708] | 114 | } |
---|
| 115 | |
---|
| 116 | if ( INTERACTIVE ) giet_tty_getc( &byte ); |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | // stop Chained buffer DMA channel |
---|
| 120 | giet_fbf_cma_stop(); |
---|
| 121 | |
---|
| 122 | giet_pthread_exit("completed"); |
---|
| 123 | } |
---|