Search
lxdream.org :: lxdream/test/asic.c
lxdream 0.9.1
released Jun 29
Download Now
filename test/asic.c
changeset 753:1fe39c3a9bbc
prev561:533f6b478071
next815:866c103d72cd
author nkeynes
date Sun Jul 20 11:36:48 2008 +0000 (11 years ago)
permissions -rw-r--r--
last change Initial implementation for sort-dma channel
file annotate diff log raw
nkeynes@185
     1
/**
nkeynes@561
     2
 * $Id$
nkeynes@185
     3
 * 
nkeynes@185
     4
 * General ASIC support code
nkeynes@185
     5
 *
nkeynes@185
     6
 * Copyright (c) 2006 Nathan Keynes.
nkeynes@185
     7
 *
nkeynes@185
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@185
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@185
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@185
    11
 * (at your option) any later version.
nkeynes@185
    12
 *
nkeynes@185
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@185
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@185
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@185
    16
 * GNU General Public License for more details.
nkeynes@185
    17
 */
nkeynes@185
    18
nkeynes@185
    19
#include "lib.h"
nkeynes@185
    20
nkeynes@185
    21
#define ASIC_BASE 0xA05F6000
nkeynes@185
    22
#define ASIC_PIRQ(n) (ASIC_BASE + 0x900 + (n<<2))
nkeynes@185
    23
#define ASIC_IRQA(n) (ASIC_BASE + 0x910 + (n<<2))
nkeynes@185
    24
#define ASIC_IRQB(n) (ASIC_BASE + 0x920 + (n<<2))
nkeynes@185
    25
#define ASIC_IRQC(n) (ASIC_BASE + 0x930 + (n<<2))
nkeynes@185
    26
#define TIMEOUT 10000000
nkeynes@185
    27
nkeynes@185
    28
/**
nkeynes@185
    29
 * Wait for an ASIC event. 
nkeynes@185
    30
 * @return 0 if the event occurred, otherwise -1 if the wait timed out.
nkeynes@185
    31
 */
nkeynes@185
    32
int asic_wait( int event )
nkeynes@185
    33
{
nkeynes@185
    34
    int n = event >> 5;
nkeynes@185
    35
    unsigned int mask = (1<< (event&0x1f));
nkeynes@185
    36
    int i;
nkeynes@185
    37
    for( i=0; i<TIMEOUT; i++ ) {
nkeynes@185
    38
	if( long_read(ASIC_PIRQ(n)) & mask ) {
nkeynes@185
    39
	    return 0;
nkeynes@185
    40
	}
nkeynes@185
    41
    }
nkeynes@185
    42
    return -1; /* Timeout */
nkeynes@185
    43
}
nkeynes@185
    44
nkeynes@185
    45
/**
nkeynes@753
    46
 * Wait for either of 2 ASIC events. 
nkeynes@753
    47
 * @return the event id if the event occurred, otherwise -1 if the wait timed out.
nkeynes@753
    48
 */
nkeynes@753
    49
int asic_wait2( int event1, int event2 )
nkeynes@753
    50
{
nkeynes@753
    51
    int n1 = event1 >> 5;
nkeynes@753
    52
    int n2 = event2 >> 5;
nkeynes@753
    53
    unsigned int mask1 = (1<< (event1&0x1f));
nkeynes@753
    54
    unsigned int mask2 = (1<< (event2&0x1f));
nkeynes@753
    55
    int i;
nkeynes@753
    56
    for( i=0; i<TIMEOUT; i++ ) {
nkeynes@753
    57
	if( long_read(ASIC_PIRQ(n1)) & mask1 ) {
nkeynes@753
    58
	    return event1;
nkeynes@753
    59
	}
nkeynes@753
    60
	if( long_read(ASIC_PIRQ(n2)) & mask2 ) {
nkeynes@753
    61
            return event2;
nkeynes@753
    62
        }
nkeynes@753
    63
    }
nkeynes@753
    64
    return -1; /* Timeout */
nkeynes@753
    65
}
nkeynes@753
    66
nkeynes@753
    67
/**
nkeynes@185
    68
 * Clear all asic events
nkeynes@185
    69
 */
nkeynes@185
    70
void asic_clear()
nkeynes@185
    71
{
nkeynes@185
    72
    long_write(ASIC_PIRQ(0), 0xFFFFFFFF);
nkeynes@185
    73
    long_write(ASIC_PIRQ(1), 0xFFFFFFFF);
nkeynes@185
    74
    long_write(ASIC_PIRQ(2), 0xFFFFFFFF);
nkeynes@185
    75
}
nkeynes@185
    76
nkeynes@193
    77
int asic_check( int event ) 
nkeynes@193
    78
{
nkeynes@193
    79
    int n = event >> 5;
nkeynes@193
    80
    unsigned int mask = (1<< (event&0x1f));
nkeynes@193
    81
    return (long_read(ASIC_PIRQ(n)) & mask) != 0;
nkeynes@193
    82
}
nkeynes@193
    83
nkeynes@185
    84
void asic_mask_all()
nkeynes@185
    85
{
nkeynes@185
    86
    long_write(ASIC_IRQA(0), 0);
nkeynes@185
    87
    long_write(ASIC_IRQA(1), 0);
nkeynes@185
    88
    long_write(ASIC_IRQA(2), 0);
nkeynes@185
    89
    long_write(ASIC_IRQB(0), 0);
nkeynes@185
    90
    long_write(ASIC_IRQB(1), 0);
nkeynes@185
    91
    long_write(ASIC_IRQB(2), 0);
nkeynes@185
    92
    long_write(ASIC_IRQC(0), 0);
nkeynes@185
    93
    long_write(ASIC_IRQC(1), 0);
nkeynes@185
    94
    long_write(ASIC_IRQC(2), 0);
nkeynes@185
    95
}
nkeynes@185
    96
nkeynes@185
    97
/**
nkeynes@185
    98
 * Print the contents of the ASIC event registers to the supplied FILE
nkeynes@185
    99
 */
nkeynes@185
   100
void asic_dump( FILE *f )
nkeynes@185
   101
{
nkeynes@185
   102
    int i,j;
nkeynes@185
   103
    fprintf( f, "Events: " );
nkeynes@185
   104
    for( i=0; i<3; i++ ) {
nkeynes@185
   105
	uint32_t val = long_read(ASIC_PIRQ(i));
nkeynes@185
   106
	for( j=0; j<32; j++ ) {
nkeynes@185
   107
	    if( val & (1<<j) ) {
nkeynes@185
   108
		fprintf( f, "%d ", (i<<5)+j );
nkeynes@185
   109
	    }
nkeynes@185
   110
	}
nkeynes@185
   111
    }
nkeynes@185
   112
    fprintf( f, "\n" );
nkeynes@185
   113
}
.