[444] | 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 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
[191] | 10 | |
---|
[444] | 11 | #include <stdio.h> |
---|
| 12 | #include <hard_config.h> |
---|
[191] | 13 | |
---|
[444] | 14 | #define FILENAME "misc/images.raw" |
---|
| 15 | #define NPIXELS 128 |
---|
| 16 | #define NLINES 128 |
---|
| 17 | #define NIMAGES 10 |
---|
| 18 | #define NBLOCKS (NPIXELS*NLINES/512) // number of blocks per image |
---|
[249] | 19 | |
---|
[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 | |
---|
[444] | 37 | // parameters checking |
---|
| 38 | if ( (NPIXELS != FBUF_X_SIZE) || (NLINES != FBUF_Y_SIZE) ) |
---|
| 39 | { |
---|
| 40 | giet_exit("[DISPLAY ERROR] Frame buffer size does not fit image size"); |
---|
| 41 | } |
---|
[254] | 42 | |
---|
[444] | 43 | giet_shr_printf("\n[DISPLAY] Processor[%d,%d,%d] starts at cycle %d\n", |
---|
| 44 | x, y, lpid, giet_proctime() ); |
---|
[295] | 45 | |
---|
[444] | 46 | // open file |
---|
| 47 | fd = giet_fat_open( FILENAME , 0 ); |
---|
| 48 | if ( fd < 0 ) |
---|
| 49 | { |
---|
| 50 | giet_exit("echec giet_fat_open for misc/images.raw"); |
---|
| 51 | } |
---|
| 52 | else |
---|
| 53 | { |
---|
| 54 | giet_shr_printf("\n[DISPLAY] Proc[%d,%d,%d] open file %s at cycle %d\n", |
---|
| 55 | x, y, lpid, FILENAME, giet_proctime() ); |
---|
| 56 | } |
---|
[254] | 57 | |
---|
[444] | 58 | // get a Chained Buffer DMA channel |
---|
| 59 | giet_fbf_cma_alloc(); |
---|
[297] | 60 | |
---|
[444] | 61 | // start Chained Buffer DMA channel |
---|
| 62 | giet_fbf_cma_start( buf0, buf1, NPIXELS*NLINES ); |
---|
| 63 | |
---|
| 64 | giet_shr_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 ( image < NIMAGES ) |
---|
[191] | 69 | { |
---|
[480] | 70 | // load buf0 |
---|
[444] | 71 | giet_fat_read( fd, buf0, NBLOCKS, image*NBLOCKS ); |
---|
[191] | 72 | |
---|
[444] | 73 | giet_shr_printf("\n[DISPLAY] Proc[%d,%d,%d] load image %d to buf0 at cycle %d\n", |
---|
| 74 | x, y, lpid, image, giet_proctime() ); |
---|
[254] | 75 | |
---|
[480] | 76 | // display buf0 |
---|
[444] | 77 | giet_fbf_cma_display( 0 ); |
---|
[297] | 78 | |
---|
[444] | 79 | giet_shr_printf("\n[DISPLAY] Proc[%d,%d,%d] display image %d from buf0 at cycle %d\n", |
---|
| 80 | x, y, lpid, image, giet_proctime() ); |
---|
| 81 | |
---|
| 82 | image++; |
---|
| 83 | |
---|
[480] | 84 | // load buf1 |
---|
[444] | 85 | giet_fat_read( fd, buf1, NBLOCKS, image*NBLOCKS ); |
---|
| 86 | |
---|
| 87 | giet_shr_printf("\n[DISPLAY] Proc[%d,%d,%d] load image %d to buf1 at cycle %d\n", |
---|
| 88 | x, y, lpid, image, giet_proctime() ); |
---|
| 89 | |
---|
[480] | 90 | // display buf1 |
---|
[444] | 91 | giet_fbf_cma_display( 1 ); |
---|
| 92 | |
---|
| 93 | giet_shr_printf("\n[DISPLAY] Proc[%d,%d,%d] display image %d from buf1 at cycle %d\n", |
---|
| 94 | x, y, lpid, image, giet_proctime() ); |
---|
| 95 | |
---|
| 96 | image++; |
---|
[258] | 97 | } |
---|
[254] | 98 | |
---|
[444] | 99 | // stop Chained buffer DMA channel |
---|
| 100 | giet_fbf_cma_stop(); |
---|
| 101 | |
---|
| 102 | giet_exit("display completed"); |
---|
[191] | 103 | } |
---|