source: trunk/user/display/display.c @ 645

Last change on this file since 645 was 644, checked in by alain, 4 years ago

Introducing application "display".

File size: 3.8 KB
Line 
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 <stdlib.h>
13#include <fcntl.h>
14#include <unistd.h>
15#include <almosmkh.h>
16
17#define FILENAME    "misc/images_128.raw"
18#define FBF_TYPE    420         
19#define NPIXELS     128
20#define NLINES      128
21
22/////////// Global variables  ///////////////////////////////////////
23
24char    buffer[NPIXELS * NLINES] __attribute__((aligned(512)));
25
26/////////////////////////
27void build( char * base )
28{
29    int    line;
30    int    pixel;
31    char * buf;
32
33    for( line = 0 ; line < NLINES ; line++ )
34    {
35        for( pixel = 0 ;  pixel < NPIXELS ; pixel++ )
36        {
37            buf = base + (line * NPIXELS) + pixel;
38
39            *buf = ( ((pixel <  (NPIXELS>>1)) && (line <  (NLINES>>1))) ||
40                     ((pixel >= (NPIXELS>>1)) && (line >= (NLINES>>1))) ) ? 0xFF : 0;
41        }
42    }
43}
44
45//////////////////////////////////////     
46void print_block( unsigned int * buf )
47{
48    int offset;    // word index in array of words
49   
50    printf("\n***** content of buffer %x *****\n", buf );
51    for( offset = 0 ; offset < 128 ; offset += 8 )
52    {
53        printf(" - %d\t: %x | %x | %x | %x | %x | %x | %x | %x\n",
54        offset<<2, buf[offset+0], buf[offset+1], buf[offset+2], buf[offset+3], 
55                   buf[offset+4], buf[offset+5], buf[offset+6], buf[offset+7] );
56    }
57}       
58////////////
59void main()
60{
61
62    unsigned int    fbf_width;
63    unsigned int    fbf_height;
64    unsigned int    fbf_type;
65    unsigned int    nbytes;
66    unsigned int    image = 0;
67    int             val;
68    int             error;
69
70    unsigned long long start_cycle;
71
72    // get  start cycle
73    get_cycle( &start_cycle );
74
75    printf("\n[display] starts at cycle %d\n", (unsigned int)start_cycle );
76
77    // check frame buffer size
78    fbf_get_config( &fbf_width , &fbf_height , &fbf_type );
79
80    if( (NPIXELS != fbf_width) || (NLINES != fbf_height) )
81    {
82        printf("\n[display error] FBF size [%d,%d] does not fit image size[%d,%d]\n",
83        fbf_width, fbf_height, NPIXELS, NLINES );
84        exit( 0 );
85    }
86
87    if( fbf_type != FBF_TYPE )
88    {
89        printf("\n[display error] FBF type [%d] does not fit image type [%d]\n",
90        fbf_type, FBF_TYPE);
91        exit( 0 );
92    }
93
94    // open file
95
96    FILE * f = fopen( FILENAME , NULL );
97//  int fd = open( FILENAME, O_RDONLY , 0 );
98
99    if( f == NULL )
100    {
101        printf("\n[display error] Cannot open file <%s>\n", FILENAME );
102        exit( 0 );
103    }
104
105    printf("\n[display] open file <%s>\n", FILENAME );
106
107    // loop on images
108    while ( 1 )
109    {
110        // load image from file
111        nbytes = fread( buffer , 1 , NPIXELS * NLINES , f );
112//      nbytes = read( fd , buffer , NPIXELS * NLINES );
113        if( nbytes != NPIXELS * NLINES )
114        {
115            printf("\n[display error] Cannot load image %d\n", image );
116            exit( 0 );
117        }
118
119        printf("\n[display] load image %d in buffer %x\n", image, buffer );
120 
121        // display image
122        error = fbf_write( buffer , NPIXELS * NLINES , 0 );
123
124        if( error )
125        {
126            printf("\n[display error] Cannot access frame buffer\n");
127            exit( 0 );
128        }
129
130        printf("\n[display] display image %d\n", image );
131
132        image++;
133
134        // interactive behaviour
135        val = getchar();
136    }
137
138    // close file
139   fclose( f );
140// close( fd );
141   
142    exit(0);
143}
Note: See TracBrowser for help on using the repository browser.