OpenCores
URL https://opencores.org/ocsvn/vapi/vapi/trunk

Subversion Repositories vapi

[/] [vapi/] [trunk/] [gpio.c] - Blame information for rev 14

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 erez
/* gpio.c -- test for GPIO, by using VAPI
2
   Copyright (C) 2001, Erez Volk, erez@opencores.org
3
 
4
   This file is part of OpenRISC 1000 Architectural Simulator.
5
 
6
   This program is free software; you can redistribute it and/or modify
7
   it under the terms of the GNU General Public License as published by
8
   the Free Software Foundation; either version 2 of the License, or
9
   (at your option) any later version.
10
 
11
   This program is distributed in the hope that it will be useful,
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
   GNU General Public License for more details.
15
 
16
   You should have received a copy of the GNU General Public License
17
   along with this program; if not, write to the Free Software
18
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
 
20
#include <stdio.h>
21
 
22
unsigned long num_vapi_ids = 8;
23
 
24 7 erez
#define ALL_ONES 0xFFFFFFFFLU
25
#define ALL_ZEROS 0x00000000LU
26
 
27
 
28
/* fails if x is false */
29
#define ASSERT(x) ((x)?1: fail (__FILE__, __LINE__))
30
 
31
static void fail (char *file, int line)
32
{
33
  printf( "Test failed in %s:%i\n", file, line );
34
  exit( 1 );
35
}
36
 
37
 
38
static void test_registers( void )
39
{
40
}
41
 
42
static void test_simple_io( void )
43
{
44
  unsigned i;
45
  unsigned long oe;
46
 
47
  for ( i = 1, oe = 1; i < 31; ++ i, oe = (oe << 1) | 1 ) {
48
    ASSERT( vapi_read() == oe );
49
    vapi_write( ~oe );
50
    ASSERT( vapi_read() == 0 );
51
    vapi_write( oe );
52
  }
53
}
54
 
55
 
56
static void test_interrupts( void )
57
{
58
  unsigned i;
59
 
60
  ASSERT( vapi_read() == 0x80000000 );
61
  for ( i = 0; i < 31; ++ i ) {
62
    vapi_write( 1LU << i );
63
    ASSERT( vapi_read() == ((i % 2) ? 0x80000000 : 0) );
64
  }
65
}
66
 
67
static void test_external_clock( void )
68
{
69
  unsigned i, j, edge;
70
  unsigned long junk = 0xdf662b5c;
71
 
72
  for ( edge = 0; edge < 2; ++ edge ) {
73
    ASSERT( vapi_read() == 0x80000000 );
74
    vapi_write_with_id( 2, !edge );
75
    for ( i = 0; i < 31; ++ i ) {
76
      for ( j = 0; j < 4; ++ j, junk = junk * 0xf7b1dfbd + 0x5bf9f28b )
77
        vapi_write( junk );
78
 
79
      vapi_write( 1LU << i );
80
      vapi_write_with_id( 2, edge );
81
 
82
      ASSERT( vapi_read() == ((i % 2) ? 0x80000000 : 0) );
83
 
84
      for ( j = 0; j < 4; ++ j, junk = junk * 0xf7b1dfbd + 0x5bf9f28b )
85
        vapi_write( junk );
86
      vapi_write_with_id( 2, !edge );
87
    }
88
  }
89
}
90
 
91
 
92
static void endshake( void )
93
{
94
  ASSERT( vapi_read() == 0x12340000 );
95
  vapi_write( 0x00005678 );
96
  ASSERT( vapi_read() == 0xDeadDead );
97
}
98
 
99 6 erez
int vapi_main( void )
100
{
101 7 erez
  test_registers();
102
  test_simple_io();
103
  test_interrupts();
104
  test_external_clock();
105
  endshake();
106 6 erez
 
107
  return 0;
108
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.