| 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 | /////////////////////////////////////////////////////////////////////////////////////// |
|---|
| 10 | |
|---|
| 11 | #include <stdio.h> |
|---|
| 12 | #include <hard_config.h> |
|---|
| 13 | |
|---|
| 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 |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | unsigned char buf0[NPIXELS*NLINES] __attribute__((aligned(512))); |
|---|
| 22 | unsigned char buf1[NPIXELS*NLINES] __attribute__((aligned(512))); |
|---|
| 23 | |
|---|
| 24 | //////////////////////////////////////////// |
|---|
| 25 | __attribute__((constructor)) void main() |
|---|
| 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 | |
|---|
| 34 | int fd; |
|---|
| 35 | unsigned int image = 0; |
|---|
| 36 | |
|---|
| 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 | } |
|---|
| 42 | |
|---|
| 43 | giet_shr_printf("\n[DISPLAY] Processor[%d,%d,%d] starts at cycle %d\n", |
|---|
| 44 | x, y, lpid, giet_proctime() ); |
|---|
| 45 | |
|---|
| 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 | } |
|---|
| 57 | |
|---|
| 58 | // get a Chained Buffer DMA channel |
|---|
| 59 | giet_fbf_cma_alloc(); |
|---|
| 60 | |
|---|
| 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 ) |
|---|
| 69 | { |
|---|
| 70 | // load buf0 |
|---|
| 71 | giet_fat_read( fd, buf0, NBLOCKS, image*NBLOCKS ); |
|---|
| 72 | |
|---|
| 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() ); |
|---|
| 75 | |
|---|
| 76 | // display buf0 |
|---|
| 77 | giet_fbf_cma_display( 0 ); |
|---|
| 78 | |
|---|
| 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 | |
|---|
| 84 | // load buf1 |
|---|
| 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 | |
|---|
| 90 | // display buf1 |
|---|
| 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++; |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | // stop Chained buffer DMA channel |
|---|
| 100 | giet_fbf_cma_stop(); |
|---|
| 101 | |
|---|
| 102 | giet_exit("display completed"); |
|---|
| 103 | } |
|---|