filename | test/testdisp.c |
changeset | 263:6f641270b2aa |
next | 267:e59e36950761 |
author | nkeynes |
date | Sat Jan 06 04:06:36 2007 +0000 (14 years ago) |
permissions | -rw-r--r-- |
last change | Implement event queue. Fix pvr2 timing (yes, again). |
view | annotate | diff | log | raw |
1 /**
2 * $Id: testdisp.c,v 1.1 2007-01-03 09:05:13 nkeynes Exp $
3 *
4 * Display (2D) tests. Mainly tests video timing / sync (obviously
5 * it can't actually test display output since there's no way of
6 * reading the results)
7 *
8 * These tests use TMU2 to determine absolute time
9 * Copyright (c) 2006 Nathan Keynes.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 */
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include "lib.h"
24 #include "asic.h"
26 #define PVR_BASE 0xA05F8000
28 #define BORDERCOL (PVR_BASE+0x040)
29 #define DISPCFG1 (PVR_BASE+0x044)
30 #define DISPADDR1 (PVR_BASE+0x050)
31 #define DISPADDR2 (PVR_BASE+0x054)
32 #define DISPSIZE (PVR_BASE+0x05C)
33 #define HPOSEVENT (PVR_BASE+0x0C8)
34 #define VPOSEVENT (PVR_BASE+0x0CC)
35 #define DISPCFG2 (PVR_BASE+0x0D0)
36 #define HBORDER (PVR_BASE+0x0D4)
37 #define VSYNC (PVR_BASE+0x0D8)
38 #define VBORDER (PVR_BASE+0x0DC)
39 #define HSYNC (PVR_BASE+0x0E0)
40 #define DISPCFG3 (PVR_BASE+0x0E8)
41 #define HPOS (PVR_BASE+0x0EC)
42 #define VPOS (PVR_BASE+0x0F0)
43 #define SYNCSTAT (PVR_BASE+0x10C)
45 #define MAX_FRAME_WAIT 0x10000000
47 #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; }
48 #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; }
50 void dump_display_regs( FILE *out )
51 {
52 fprintf( out, "%08X DISPCFG1: %08X\n", DISPCFG1, long_read(DISPCFG1) );
53 fprintf( out, "%08X DISPCFG2: %08X\n", DISPCFG2, long_read(DISPCFG2) );
54 fprintf( out, "%08X DISPCFG3: %08X\n", DISPCFG3, long_read(DISPCFG3) );
55 fprintf( out, "%08X DISPSIZE: %08X\n", DISPSIZE, long_read(DISPSIZE) );
56 fprintf( out, "%08X HBORDER: %08X\n", HBORDER, long_read(HBORDER) );
57 fprintf( out, "%08X VBORDER: %08X\n", VBORDER, long_read(VBORDER) );
58 fprintf( out, "%08X HSYNC: %08X\n", HSYNC, long_read(HSYNC) );
59 fprintf( out, "%08X VSYNC: %08X\n", VSYNC, long_read(VSYNC) );
60 fprintf( out, "%08X DISPADDR1: %08X\n", DISPADDR1, long_read(DISPADDR1) );
61 fprintf( out, "%08X DISPADDR2: %08X\n", DISPADDR2, long_read(DISPADDR2) );
62 fprintf( out, "%08X HPOSEVENT: %08X\n", HPOSEVENT, long_read(HPOSEVENT) );
63 fprintf( out, "%08X VPOSEVENT: %08X\n", VPOSEVENT, long_read(VPOSEVENT) );
64 fprintf( out, "%08X HPOS: %08X\n", HPOS, long_read(HPOS) );
65 fprintf( out, "%08X VPOS: %08X\n", VPOS, long_read(VPOS) );
66 fprintf( out, "%08X SYNCSTAT: %08X\n", SYNCSTAT, long_read(SYNCSTAT) );
67 }
69 uint32_t pal_settings[] = {
70 DISPCFG1, 0x00000001,
71 DISPCFG2, 0x00000150,
72 DISPCFG3, 0x00160000,
73 DISPSIZE, 0x1413BD3F,
74 HBORDER, 0x008D034B,
75 VBORDER, 0x00120102,
76 VSYNC, 0x0270035F,
77 HSYNC, 0x07D6A53F,
78 HPOS, 0x000000A4,
79 VPOS, 0x00120012,
80 0, 0 };
82 void apply_display_settings( uint32_t *regs ) {
83 int i;
84 for( i=0; regs[i] != 0; i+=2 ) {
85 long_write( regs[i], regs[i+1] );
86 }
87 }
89 /**
90 * Wait until the given line is being displayed (ie is set in the syncstat
91 * register).
92 * @return 0 if the line is reached before timeout, otherwise -1.
93 */
94 int wait_line( int line )
95 {
96 int i;
97 for( i=0; i< MAX_FRAME_WAIT; i++ ) {
98 uint32_t sync = long_read(SYNCSTAT) & 0x03FF;
99 if( sync == line ) {
100 return 0;
101 }
102 }
103 return -1;
104 }
106 /**
107 * Wait until just after the last line of the frame is being displayed (according
108 * to the syncstat register). After this function the current line will be 0.
109 * @return 0 if the last line is the given line, otherwise -1.
110 */
111 int wait_lastline( int line )
112 {
113 int lastline = -1, i;
114 for( i=0; i< MAX_FRAME_WAIT; i++ ) {
115 uint32_t sync = long_read(SYNCSTAT) & 0x03FF;
116 if( sync == 0 && lastline != -1 ) {
117 CHECK_IEQUALS( line, lastline );
118 return 0;
119 }
120 lastline = sync;
121 }
122 fprintf( stderr, "Timeout waiting for line %d\n", line );
123 return -1;
124 }
126 int test_ntsc_timing() {
128 return 0;
129 }
132 int test_pal_timing()
133 {
134 uint32_t line_time, field_time;
135 /* Set PAL display mode */
136 apply_display_settings( pal_settings );
138 asic_clear();
140 /* Check basic frame timings: 31.919 us per line, 19.945 ms per field */
141 /* Wait for a line 0 (either frame) */
142 WAIT_LINE(0);
143 timer_start();
144 WAIT_LINE(1);
145 line_time = timer_gettime_us();
146 WAIT_LASTLINE(624);
147 field_time = timer_gettime_us();
148 fprintf( stdout, "Line time: %dus, frame time: %dus\n", line_time, field_time );
149 // CHECK_IEQUALS( 31, line_time );
150 CHECK_IEQUALS( 19949, field_time );
151 dump_display_regs( stdout );
152 return 0;
153 }
156 /********************************* Main **************************************/
158 typedef int (*test_func_t)();
160 test_func_t test_fns[] = { test_ntsc_timing, test_pal_timing,
161 NULL };
163 int main()
164 {
165 return run_tests( test_fns );
166 }
.