Search
lxdream.org :: lxdream/test/testdisp.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename test/testdisp.c
changeset 267:e59e36950761
prev263:6f641270b2aa
next272:fb6be85235e8
author nkeynes
date Sat Jan 06 04:08:11 2007 +0000 (16 years ago)
permissions -rw-r--r--
last change Add test for NTSC timing, retrace/scanline events
file annotate diff log raw
1.1 --- a/test/testdisp.c Wed Jan 03 09:05:13 2007 +0000
1.2 +++ b/test/testdisp.c Sat Jan 06 04:08:11 2007 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: testdisp.c,v 1.1 2007-01-03 09:05:13 nkeynes Exp $
1.6 + * $Id: testdisp.c,v 1.2 2007-01-06 04:08:11 nkeynes Exp $
1.7 *
1.8 * Display (2D) tests. Mainly tests video timing / sync (obviously
1.9 * it can't actually test display output since there's no way of
1.10 @@ -34,15 +34,17 @@
1.11 #define VPOSEVENT (PVR_BASE+0x0CC)
1.12 #define DISPCFG2 (PVR_BASE+0x0D0)
1.13 #define HBORDER (PVR_BASE+0x0D4)
1.14 -#define VSYNC (PVR_BASE+0x0D8)
1.15 +#define DISPTOTAL (PVR_BASE+0x0D8)
1.16 #define VBORDER (PVR_BASE+0x0DC)
1.17 -#define HSYNC (PVR_BASE+0x0E0)
1.18 +#define SYNCTIME (PVR_BASE+0x0E0)
1.19 #define DISPCFG3 (PVR_BASE+0x0E8)
1.20 #define HPOS (PVR_BASE+0x0EC)
1.21 #define VPOS (PVR_BASE+0x0F0)
1.22 #define SYNCSTAT (PVR_BASE+0x10C)
1.23
1.24 -#define MAX_FRAME_WAIT 0x10000000
1.25 +#define MAX_FRAME_WAIT 0x50000
1.26 +
1.27 +#define EVENT_RETRACE 5
1.28
1.29 #define WAIT_LINE( a ) if( wait_line(a) != 0 ) { fprintf(stderr, "Timeout at %s:%d:%s() waiting for line %d\n", __FILE__, __LINE__, __func__, a ); return -1; }
1.30 #define WAIT_LASTLINE( a ) if( wait_lastline(a) != 0 ) { fprintf(stderr, "Last line check failed at %s:%d:%s() waiting for line %d\n", __FILE__, __LINE__, __func__, a ); return -1; }
1.31 @@ -55,8 +57,8 @@
1.32 fprintf( out, "%08X DISPSIZE: %08X\n", DISPSIZE, long_read(DISPSIZE) );
1.33 fprintf( out, "%08X HBORDER: %08X\n", HBORDER, long_read(HBORDER) );
1.34 fprintf( out, "%08X VBORDER: %08X\n", VBORDER, long_read(VBORDER) );
1.35 - fprintf( out, "%08X HSYNC: %08X\n", HSYNC, long_read(HSYNC) );
1.36 - fprintf( out, "%08X VSYNC: %08X\n", VSYNC, long_read(VSYNC) );
1.37 + fprintf( out, "%08X SYNCTIME: %08X\n", SYNCTIME, long_read(SYNCTIME) );
1.38 + fprintf( out, "%08X DISPTOTAL: %08X\n", DISPTOTAL, long_read(DISPTOTAL) );
1.39 fprintf( out, "%08X DISPADDR1: %08X\n", DISPADDR1, long_read(DISPADDR1) );
1.40 fprintf( out, "%08X DISPADDR2: %08X\n", DISPADDR2, long_read(DISPADDR2) );
1.41 fprintf( out, "%08X HPOSEVENT: %08X\n", HPOSEVENT, long_read(HPOSEVENT) );
1.42 @@ -73,12 +75,42 @@
1.43 DISPSIZE, 0x1413BD3F,
1.44 HBORDER, 0x008D034B,
1.45 VBORDER, 0x00120102,
1.46 - VSYNC, 0x0270035F,
1.47 - HSYNC, 0x07D6A53F,
1.48 + DISPTOTAL, 0x0270035F,
1.49 + SYNCTIME, 0x07D6A53F,
1.50 HPOS, 0x000000A4,
1.51 VPOS, 0x00120012,
1.52 + VPOSEVENT, 0x00150136,
1.53 0, 0 };
1.54
1.55 +uint32_t ntsc_settings[] = {
1.56 + DISPCFG1, 0x00000001,
1.57 + DISPCFG2, 0x00000150,
1.58 + DISPCFG3, 0x00160000,
1.59 + DISPSIZE, 0x1413BD3F,
1.60 + HBORDER, 0x007e0345,
1.61 + VBORDER, 0x00120102,
1.62 + DISPTOTAL, 0x020C0359,
1.63 + SYNCTIME, 0x07d6c63f,
1.64 + HPOS, 0x000000A4,
1.65 + VPOS, 0x00120012,
1.66 + VPOSEVENT, 0x001501FE,
1.67 + 0, 0 };
1.68 +
1.69 +
1.70 +struct timing {
1.71 + uint32_t interlaced;
1.72 + uint32_t total_lines;
1.73 + uint32_t vsync_lines;
1.74 + uint32_t line_time_us;
1.75 + uint32_t field_time_us;
1.76 + uint32_t hsync_width_us;
1.77 + uint32_t front_porch_us;
1.78 + uint32_t back_porch_us;
1.79 +};
1.80 +
1.81 +struct timing ntsc_timing = { 1, 525, 6, 31, 16641, 4, 12, 4 };
1.82 +struct timing pal_timing = { 1, 625, 5, 31, 19949, 4, 12, 4 };
1.83 +
1.84 void apply_display_settings( uint32_t *regs ) {
1.85 int i;
1.86 for( i=0; regs[i] != 0; i+=2 ) {
1.87 @@ -110,10 +142,10 @@
1.88 */
1.89 int wait_lastline( int line )
1.90 {
1.91 - int lastline = -1, i;
1.92 + int lastline = 0, i;
1.93 for( i=0; i< MAX_FRAME_WAIT; i++ ) {
1.94 uint32_t sync = long_read(SYNCSTAT) & 0x03FF;
1.95 - if( sync == 0 && lastline != -1 ) {
1.96 + if( sync == 0 && lastline != 0 ) {
1.97 CHECK_IEQUALS( line, lastline );
1.98 return 0;
1.99 }
1.100 @@ -123,11 +155,103 @@
1.101 return -1;
1.102 }
1.103
1.104 -int test_ntsc_timing() {
1.105 +int check_events_interlaced( )
1.106 +{
1.107 + uint32_t status1, status2, status3;
1.108 + int i;
1.109 + for( i=0; i< MAX_FRAME_WAIT; i++ ) {
1.110 + status1 = long_read(SYNCSTAT) & 0x07FF;
1.111 + if( status1 == 0x04FF ) {
1.112 + break;
1.113 + }
1.114 + }
1.115 + asic_clear();
1.116 + asic_wait(EVENT_RETRACE);
1.117 + status1 = long_read(SYNCSTAT);
1.118 + asic_clear();
1.119 + asic_wait(EVENT_SCANLINE2);
1.120 + status2 = long_read(SYNCSTAT);
1.121 + asic_clear();
1.122 + asic_wait(EVENT_SCANLINE1);
1.123 + status3 = long_read(SYNCSTAT);
1.124 + CHECK_IEQUALS( 0x0000, status1 );
1.125 + CHECK_IEQUALS( 0x202A, status2 );
1.126 + CHECK_IEQUALS( 0x226C, status3 );
1.127 +
1.128 + for( i=0; i< MAX_FRAME_WAIT; i++ ) {
1.129 + status1 = long_read(SYNCSTAT) & 0x07FF;
1.130 + if( status1 == 0x00FF ) {
1.131 + break;
1.132 + }
1.133 + }
1.134 + asic_clear();
1.135 + asic_wait(EVENT_RETRACE);
1.136 + status1 = long_read(SYNCSTAT);
1.137 + asic_clear();
1.138 + asic_wait(EVENT_SCANLINE2);
1.139 + status2 = long_read(SYNCSTAT);
1.140 + asic_clear();
1.141 + asic_wait(EVENT_SCANLINE1);
1.142 + status3 = long_read(SYNCSTAT);
1.143 + fprintf( stderr, "%08X, %08X, %08X\n", status1, status2, status3 );
1.144 + CHECK_IEQUALS( 0x1400, status1 );
1.145 + CHECK_IEQUALS( 0x242B, status2 );
1.146 + CHECK_IEQUALS( 0x266D, status3 );
1.147
1.148 return 0;
1.149 }
1.150
1.151 +int check_timing( struct timing *t ) {
1.152 + uint32_t line_time, field_time;
1.153 + uint32_t stat;
1.154 + uint32_t last_line = t->total_lines - 1;
1.155 + int i;
1.156 +
1.157 + WAIT_LINE( t->total_lines - 1 );
1.158 + asic_clear();
1.159 + for( i=0; i< MAX_FRAME_WAIT; i++ ) {
1.160 + stat = long_read(SYNCSTAT) & 0x07FF;
1.161 + if( stat == 0 ) {
1.162 + break;
1.163 + } else if( (stat & 0x03FF) != last_line ) {
1.164 + asic_clear();
1.165 + last_line = stat & 0x03FF;
1.166 + }
1.167 + }
1.168 + if( stat != 0 ) {
1.169 + fprintf( stderr, "Timeout waiting for line 0 field 0\n" );
1.170 + return -1;
1.171 + }
1.172 + timer_start();
1.173 + asic_clear();
1.174 + if( asic_check( EVENT_RETRACE ) != 0 ) {
1.175 + fprintf( stderr, "Failed to clear retrace event ?\n" );
1.176 + return -1;
1.177 + }
1.178 + CHECK_IEQUALS( stat, 0 ); /* VSYNC, HSYNC, no display */
1.179 + WAIT_LINE(1);
1.180 + line_time = timer_gettime_us();
1.181 + WAIT_LASTLINE(t->total_lines-1);
1.182 + field_time = timer_gettime_us();
1.183 +
1.184 + if( line_time != t->line_time_us ||
1.185 + field_time != t->field_time_us ) {
1.186 + fprintf( stderr, "Assertion failed: Expected Timing %d,%d but was %d,%d\n",
1.187 + t->line_time_us, t->field_time_us, line_time, field_time );
1.188 + return -1;
1.189 + }
1.190 + return 0;
1.191 +}
1.192 +
1.193 +int test_ntsc_timing() {
1.194 + apply_display_settings( ntsc_settings );
1.195 + // check_events_interlaced();
1.196 + asic_clear();
1.197 + uint32_t result = check_timing( &ntsc_timing );
1.198 + dump_display_regs( stdout );
1.199 + return result;
1.200 +}
1.201 +
1.202
1.203 int test_pal_timing()
1.204 {
1.205 @@ -135,21 +259,11 @@
1.206 /* Set PAL display mode */
1.207 apply_display_settings( pal_settings );
1.208
1.209 + check_events_interlaced();
1.210 asic_clear();
1.211 -
1.212 - /* Check basic frame timings: 31.919 us per line, 19.945 ms per field */
1.213 - /* Wait for a line 0 (either frame) */
1.214 - WAIT_LINE(0);
1.215 - timer_start();
1.216 - WAIT_LINE(1);
1.217 - line_time = timer_gettime_us();
1.218 - WAIT_LASTLINE(624);
1.219 - field_time = timer_gettime_us();
1.220 - fprintf( stdout, "Line time: %dus, frame time: %dus\n", line_time, field_time );
1.221 - // CHECK_IEQUALS( 31, line_time );
1.222 - CHECK_IEQUALS( 19949, field_time );
1.223 + uint32_t result = check_timing( &pal_timing );
1.224 dump_display_regs( stdout );
1.225 - return 0;
1.226 + return result;
1.227 }
1.228
1.229
.