Changeset 444 for soft/giet_vm/applications/display/main.c
- Timestamp:
- Nov 3, 2014, 12:40:50 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/applications/display/main.c
r297 r444 1 #include "stdio.h" 2 #include "hard_config.h" 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 /////////////////////////////////////////////////////////////////////////////////////// 3 10 4 #define NBLOCKS 32 // (128 * 128) / 512 11 #include <stdio.h> 12 #include <hard_config.h> 5 13 6 unsigned char buf[128*128] __attribute__((aligned(512))); 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 7 19 20 21 unsigned char buf0[NPIXELS*NLINES] __attribute__((aligned(512))); 22 unsigned char buf1[NPIXELS*NLINES] __attribute__((aligned(512))); 23 24 //////////////////////////////////////////// 8 25 __attribute__((constructor)) void main() 9 { 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 10 34 int fd; 11 int blocks; 12 unsigned int ko; 13 unsigned int blocks_to_skip = 8*NBLOCKS; 35 unsigned int image = 0; 14 36 15 unsigned int procid = giet_procid(); 16 unsigned int cluster_xy = procid/NB_PROCS_MAX; 17 unsigned int lpid = procid%NB_PROCS_MAX; 18 unsigned int x = cluster_xy >> Y_WIDTH; 19 unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); 20 21 giet_tty_printf( "*** Starting task display on processor[%d,%d,%d] at cycle %d\n\n", 22 x, y, lpid, giet_proctime() ); 23 24 /////////////////////////////////////////// 25 fd = giet_fat_open( "misc/images.raw", 0 ); 26 if ( fd < 0 ) giet_exit("echec giet_fat_open for misc/images.raw"); 27 28 giet_tty_printf("\ngiet_fat_open completed for misc/images.raw at cycle %d\n", 29 giet_proctime() ); 30 31 ///////////////////////////////////////// 32 while ( blocks_to_skip < (10 * NBLOCKS) ) 37 // parameters checking 38 if ( (NPIXELS != FBUF_X_SIZE) || (NLINES != FBUF_Y_SIZE) ) 33 39 { 34 // lecture image sur le disque 35 giet_fat_read( fd, buf, NBLOCKS, blocks_to_skip ); 36 37 giet_tty_printf("\ngiet_fat_read for image %d completed at cycle %d \n", 38 (blocks_to_skip>>5), giet_proctime()); 39 40 // transfert vers le frame buffer 41 giet_fb_sync_write( 0, buf, 128 * 128 ); 42 43 giet_tty_printf("\ndisplay completed for image %d at cycle %d \n", 44 (blocks_to_skip>>5), giet_proctime()); 45 46 blocks_to_skip = blocks_to_skip + NBLOCKS; 40 giet_exit("[DISPLAY ERROR] Frame buffer size does not fit image size"); 47 41 } 48 42 49 giet_exit("completed"); 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 giet_fat_read( fd, buf0, NBLOCKS, image*NBLOCKS ); 71 72 giet_shr_printf("\n[DISPLAY] Proc[%d,%d,%d] load image %d to buf0 at cycle %d\n", 73 x, y, lpid, image, giet_proctime() ); 74 75 giet_fbf_cma_display( 0 ); 76 77 giet_shr_printf("\n[DISPLAY] Proc[%d,%d,%d] display image %d from buf0 at cycle %d\n", 78 x, y, lpid, image, giet_proctime() ); 79 80 image++; 81 82 giet_fat_read( fd, buf1, NBLOCKS, image*NBLOCKS ); 83 84 giet_shr_printf("\n[DISPLAY] Proc[%d,%d,%d] load image %d to buf1 at cycle %d\n", 85 x, y, lpid, image, giet_proctime() ); 86 87 giet_fbf_cma_display( 1 ); 88 89 giet_shr_printf("\n[DISPLAY] Proc[%d,%d,%d] display image %d from buf1 at cycle %d\n", 90 x, y, lpid, image, giet_proctime() ); 91 92 93 image++; 94 } 95 96 // stop Chained buffer DMA channel 97 giet_fbf_cma_stop(); 98 99 giet_exit("display completed"); 50 100 }
Note: See TracChangeset
for help on using the changeset viewer.