[555] | 1 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
[444] | 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 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
[191] | 10 | |
---|
[444] | 11 | #include <stdio.h> |
---|
[555] | 12 | #include <hard_config.h> // To check Frame Buffer size |
---|
[191] | 13 | |
---|
[574] | 14 | #define FILENAME "misc/lena.raw" |
---|
| 15 | #define NPIXELS 256 |
---|
| 16 | #define NLINES 256 |
---|
| 17 | #define NIMAGES 1 |
---|
[249] | 18 | |
---|
[544] | 19 | #define INTERACTIVE 1 |
---|
[444] | 20 | |
---|
| 21 | unsigned char buf0[NPIXELS*NLINES] __attribute__((aligned(512))); |
---|
| 22 | unsigned char buf1[NPIXELS*NLINES] __attribute__((aligned(512))); |
---|
| 23 | |
---|
| 24 | //////////////////////////////////////////// |
---|
[258] | 25 | __attribute__((constructor)) void main() |
---|
[444] | 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 | |
---|
[295] | 34 | int fd; |
---|
[444] | 35 | unsigned int image = 0; |
---|
[207] | 36 | |
---|
[544] | 37 | char byte; |
---|
| 38 | |
---|
[444] | 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 | } |
---|
[254] | 44 | |
---|
[544] | 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", |
---|
[444] | 49 | x, y, lpid, giet_proctime() ); |
---|
[295] | 50 | |
---|
[444] | 51 | // open file |
---|
| 52 | fd = giet_fat_open( FILENAME , 0 ); |
---|
[544] | 53 | |
---|
| 54 | giet_tty_printf("\n[DISPLAY] Proc[%d,%d,%d] open file %s at cycle %d\n", |
---|
[444] | 55 | x, y, lpid, FILENAME, giet_proctime() ); |
---|
[254] | 56 | |
---|
[444] | 57 | // get a Chained Buffer DMA channel |
---|
| 58 | giet_fbf_cma_alloc(); |
---|
[297] | 59 | |
---|
[444] | 60 | // start Chained Buffer DMA channel |
---|
| 61 | giet_fbf_cma_start( buf0, buf1, NPIXELS*NLINES ); |
---|
| 62 | |
---|
[544] | 63 | giet_tty_printf("\n[DISPLAY] Proc[%d,%d,%d] starts CMA at cycle %d\n", |
---|
[444] | 64 | x, y, lpid, giet_proctime() ); |
---|
| 65 | |
---|
| 66 | // Main loop (on images) |
---|
[544] | 67 | while ( 1 ) |
---|
[191] | 68 | { |
---|
[480] | 69 | // load buf0 |
---|
[589] | 70 | giet_fat_read( fd, buf0, NPIXELS*NLINES ); |
---|
[191] | 71 | |
---|
[544] | 72 | giet_tty_printf("\n[DISPLAY] Proc[%d,%d,%d] load image %d at cycle %d\n", |
---|
[444] | 73 | x, y, lpid, image, giet_proctime() ); |
---|
[254] | 74 | |
---|
[480] | 75 | // display buf0 |
---|
[444] | 76 | giet_fbf_cma_display( 0 ); |
---|
[297] | 77 | |
---|
[544] | 78 | giet_tty_printf("\n[DISPLAY] Proc[%d,%d,%d] display image %d at cycle %d\n", |
---|
[444] | 79 | x, y, lpid, image, giet_proctime() ); |
---|
| 80 | |
---|
[544] | 81 | image = (image + 1) % NIMAGES; |
---|
[444] | 82 | |
---|
[544] | 83 | if ( INTERACTIVE ) giet_tty_getc( &byte ); |
---|
| 84 | |
---|
[480] | 85 | // load buf1 |
---|
[589] | 86 | giet_fat_read( fd, buf1, NPIXELS*NLINES ); |
---|
[444] | 87 | |
---|
[544] | 88 | giet_tty_printf("\n[DISPLAY] Proc[%d,%d,%d] load image %d at cycle %d\n", |
---|
[444] | 89 | x, y, lpid, image, giet_proctime() ); |
---|
| 90 | |
---|
[480] | 91 | // display buf1 |
---|
[444] | 92 | giet_fbf_cma_display( 1 ); |
---|
| 93 | |
---|
[544] | 94 | giet_tty_printf("\n[DISPLAY] Proc[%d,%d,%d] display image %d at cycle %d\n", |
---|
[444] | 95 | x, y, lpid, image, giet_proctime() ); |
---|
| 96 | |
---|
[544] | 97 | image = (image + 1) % NIMAGES; |
---|
| 98 | |
---|
| 99 | if ( INTERACTIVE ) giet_tty_getc( &byte ); |
---|
[258] | 100 | } |
---|
[254] | 101 | |
---|
[444] | 102 | // stop Chained buffer DMA channel |
---|
| 103 | giet_fbf_cma_stop(); |
---|
| 104 | |
---|
| 105 | giet_exit("display completed"); |
---|
[191] | 106 | } |
---|