Search
lxdream.org :: lxdream/test/testdisp.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename test/testdisp.c
changeset 263:6f641270b2aa
next267:e59e36950761
author nkeynes
date Wed Jan 03 09:05:13 2007 +0000 (13 years ago)
permissions -rw-r--r--
last change Extract test runner from testide into the generic testdata.c
Add initial display tests (PAL timings)
file annotate diff log raw
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/test/testdisp.c Wed Jan 03 09:05:13 2007 +0000
1.3 @@ -0,0 +1,166 @@
1.4 +/**
1.5 + * $Id: testdisp.c,v 1.1 2007-01-03 09:05:13 nkeynes Exp $
1.6 + *
1.7 + * Display (2D) tests. Mainly tests video timing / sync (obviously
1.8 + * it can't actually test display output since there's no way of
1.9 + * reading the results)
1.10 + *
1.11 + * These tests use TMU2 to determine absolute time
1.12 + * Copyright (c) 2006 Nathan Keynes.
1.13 + *
1.14 + * This program is free software; you can redistribute it and/or modify
1.15 + * it under the terms of the GNU General Public License as published by
1.16 + * the Free Software Foundation; either version 2 of the License, or
1.17 + * (at your option) any later version.
1.18 + *
1.19 + * This program is distributed in the hope that it will be useful,
1.20 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.21 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.22 + * GNU General Public License for more details.
1.23 + */
1.24 +#include <stdlib.h>
1.25 +#include <stdio.h>
1.26 +#include "lib.h"
1.27 +#include "asic.h"
1.28 +
1.29 +#define PVR_BASE 0xA05F8000
1.30 +
1.31 +#define BORDERCOL (PVR_BASE+0x040)
1.32 +#define DISPCFG1 (PVR_BASE+0x044)
1.33 +#define DISPADDR1 (PVR_BASE+0x050)
1.34 +#define DISPADDR2 (PVR_BASE+0x054)
1.35 +#define DISPSIZE (PVR_BASE+0x05C)
1.36 +#define HPOSEVENT (PVR_BASE+0x0C8)
1.37 +#define VPOSEVENT (PVR_BASE+0x0CC)
1.38 +#define DISPCFG2 (PVR_BASE+0x0D0)
1.39 +#define HBORDER (PVR_BASE+0x0D4)
1.40 +#define VSYNC (PVR_BASE+0x0D8)
1.41 +#define VBORDER (PVR_BASE+0x0DC)
1.42 +#define HSYNC (PVR_BASE+0x0E0)
1.43 +#define DISPCFG3 (PVR_BASE+0x0E8)
1.44 +#define HPOS (PVR_BASE+0x0EC)
1.45 +#define VPOS (PVR_BASE+0x0F0)
1.46 +#define SYNCSTAT (PVR_BASE+0x10C)
1.47 +
1.48 +#define MAX_FRAME_WAIT 0x10000000
1.49 +
1.50 +#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.51 +#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.52 +
1.53 +void dump_display_regs( FILE *out )
1.54 +{
1.55 + fprintf( out, "%08X DISPCFG1: %08X\n", DISPCFG1, long_read(DISPCFG1) );
1.56 + fprintf( out, "%08X DISPCFG2: %08X\n", DISPCFG2, long_read(DISPCFG2) );
1.57 + fprintf( out, "%08X DISPCFG3: %08X\n", DISPCFG3, long_read(DISPCFG3) );
1.58 + fprintf( out, "%08X DISPSIZE: %08X\n", DISPSIZE, long_read(DISPSIZE) );
1.59 + fprintf( out, "%08X HBORDER: %08X\n", HBORDER, long_read(HBORDER) );
1.60 + fprintf( out, "%08X VBORDER: %08X\n", VBORDER, long_read(VBORDER) );
1.61 + fprintf( out, "%08X HSYNC: %08X\n", HSYNC, long_read(HSYNC) );
1.62 + fprintf( out, "%08X VSYNC: %08X\n", VSYNC, long_read(VSYNC) );
1.63 + fprintf( out, "%08X DISPADDR1: %08X\n", DISPADDR1, long_read(DISPADDR1) );
1.64 + fprintf( out, "%08X DISPADDR2: %08X\n", DISPADDR2, long_read(DISPADDR2) );
1.65 + fprintf( out, "%08X HPOSEVENT: %08X\n", HPOSEVENT, long_read(HPOSEVENT) );
1.66 + fprintf( out, "%08X VPOSEVENT: %08X\n", VPOSEVENT, long_read(VPOSEVENT) );
1.67 + fprintf( out, "%08X HPOS: %08X\n", HPOS, long_read(HPOS) );
1.68 + fprintf( out, "%08X VPOS: %08X\n", VPOS, long_read(VPOS) );
1.69 + fprintf( out, "%08X SYNCSTAT: %08X\n", SYNCSTAT, long_read(SYNCSTAT) );
1.70 +}
1.71 +
1.72 +uint32_t pal_settings[] = {
1.73 + DISPCFG1, 0x00000001,
1.74 + DISPCFG2, 0x00000150,
1.75 + DISPCFG3, 0x00160000,
1.76 + DISPSIZE, 0x1413BD3F,
1.77 + HBORDER, 0x008D034B,
1.78 + VBORDER, 0x00120102,
1.79 + VSYNC, 0x0270035F,
1.80 + HSYNC, 0x07D6A53F,
1.81 + HPOS, 0x000000A4,
1.82 + VPOS, 0x00120012,
1.83 + 0, 0 };
1.84 +
1.85 +void apply_display_settings( uint32_t *regs ) {
1.86 + int i;
1.87 + for( i=0; regs[i] != 0; i+=2 ) {
1.88 + long_write( regs[i], regs[i+1] );
1.89 + }
1.90 +}
1.91 +
1.92 +/**
1.93 + * Wait until the given line is being displayed (ie is set in the syncstat
1.94 + * register).
1.95 + * @return 0 if the line is reached before timeout, otherwise -1.
1.96 + */
1.97 +int wait_line( int line )
1.98 +{
1.99 + int i;
1.100 + for( i=0; i< MAX_FRAME_WAIT; i++ ) {
1.101 + uint32_t sync = long_read(SYNCSTAT) & 0x03FF;
1.102 + if( sync == line ) {
1.103 + return 0;
1.104 + }
1.105 + }
1.106 + return -1;
1.107 +}
1.108 +
1.109 +/**
1.110 + * Wait until just after the last line of the frame is being displayed (according
1.111 + * to the syncstat register). After this function the current line will be 0.
1.112 + * @return 0 if the last line is the given line, otherwise -1.
1.113 + */
1.114 +int wait_lastline( int line )
1.115 +{
1.116 + int lastline = -1, i;
1.117 + for( i=0; i< MAX_FRAME_WAIT; i++ ) {
1.118 + uint32_t sync = long_read(SYNCSTAT) & 0x03FF;
1.119 + if( sync == 0 && lastline != -1 ) {
1.120 + CHECK_IEQUALS( line, lastline );
1.121 + return 0;
1.122 + }
1.123 + lastline = sync;
1.124 + }
1.125 + fprintf( stderr, "Timeout waiting for line %d\n", line );
1.126 + return -1;
1.127 +}
1.128 +
1.129 +int test_ntsc_timing() {
1.130 +
1.131 + return 0;
1.132 +}
1.133 +
1.134 +
1.135 +int test_pal_timing()
1.136 +{
1.137 + uint32_t line_time, field_time;
1.138 + /* Set PAL display mode */
1.139 + apply_display_settings( pal_settings );
1.140 +
1.141 + asic_clear();
1.142 +
1.143 + /* Check basic frame timings: 31.919 us per line, 19.945 ms per field */
1.144 + /* Wait for a line 0 (either frame) */
1.145 + WAIT_LINE(0);
1.146 + timer_start();
1.147 + WAIT_LINE(1);
1.148 + line_time = timer_gettime_us();
1.149 + WAIT_LASTLINE(624);
1.150 + field_time = timer_gettime_us();
1.151 + fprintf( stdout, "Line time: %dus, frame time: %dus\n", line_time, field_time );
1.152 + // CHECK_IEQUALS( 31, line_time );
1.153 + CHECK_IEQUALS( 19949, field_time );
1.154 + dump_display_regs( stdout );
1.155 + return 0;
1.156 +}
1.157 +
1.158 +
1.159 +/********************************* Main **************************************/
1.160 +
1.161 +typedef int (*test_func_t)();
1.162 +
1.163 +test_func_t test_fns[] = { test_ntsc_timing, test_pal_timing,
1.164 + NULL };
1.165 +
1.166 +int main()
1.167 +{
1.168 + return run_tests( test_fns );
1.169 +}
.