Line 3... |
Line 3... |
#include "spr_defs.h"
|
#include "spr_defs.h"
|
#include "support.h"
|
#include "support.h"
|
#include "int.h"
|
#include "int.h"
|
|
|
/* Relative Register Addresses */
|
/* Relative Register Addresses */
|
#define RGPIO_IN (4 * 0x00)
|
#define RGPIO_IN 0x00
|
#define RGPIO_OUT (4 * 0x01)
|
#define RGPIO_OUT 0x04
|
#define RGPIO_OE (4 * 0x02)
|
#define RGPIO_OE 0x08
|
#define RGPIO_INTE (4 * 0x03)
|
#define RGPIO_INTE 0x0C
|
#define RGPIO_PTRIG (4 * 0x04)
|
#define RGPIO_PTRIG 0x10
|
#define RGPIO_AUX (4 * 0x05)
|
#define RGPIO_AUX 0x14
|
#define RGPIO_CTRL (4 * 0x06)
|
#define RGPIO_CTRL 0x18
|
|
#define RGPIO_INTS 0x1C
|
|
|
/* Fields inside RGPIO_CTRL */
|
/* Fields inside RGPIO_CTRL */
|
#define RGPIO_CTRL_ECLK 0x00000001
|
#define RGPIO_CTRL_ECLK 0x00000001
|
#define RGPIO_CTRL_NEC 0x00000002
|
#define RGPIO_CTRL_NEC 0x00000002
|
#define RGPIO_CTRL_INTE 0x00000004
|
#define RGPIO_CTRL_INTE 0x00000004
|
#define RGPIO_CTRL_INT 0x00000008
|
#define RGPIO_CTRL_INTS 0x00000008
|
|
|
#define GPIO_BASE 0xB0000000LU
|
#define GPIO_BASE 0xB0000000LU
|
|
|
#define GPIO_INT_LINE 23 /* To which interrupt is GPIO connected */
|
#define GPIO_INT_LINE 23 /* To which interrupt is GPIO connected */
|
|
|
Line 29... |
Line 30... |
rgpio_out = (unsigned long *)(GPIO_BASE + RGPIO_OUT),
|
rgpio_out = (unsigned long *)(GPIO_BASE + RGPIO_OUT),
|
rgpio_oe = (unsigned long *)(GPIO_BASE + RGPIO_OE),
|
rgpio_oe = (unsigned long *)(GPIO_BASE + RGPIO_OE),
|
rgpio_inte = (unsigned long *)(GPIO_BASE + RGPIO_INTE),
|
rgpio_inte = (unsigned long *)(GPIO_BASE + RGPIO_INTE),
|
rgpio_ptrig = (unsigned long *)(GPIO_BASE + RGPIO_PTRIG),
|
rgpio_ptrig = (unsigned long *)(GPIO_BASE + RGPIO_PTRIG),
|
rgpio_aux = (unsigned long *)(GPIO_BASE + RGPIO_AUX),
|
rgpio_aux = (unsigned long *)(GPIO_BASE + RGPIO_AUX),
|
rgpio_ctrl = (unsigned long *)(GPIO_BASE + RGPIO_CTRL);
|
rgpio_ctrl = (unsigned long *)(GPIO_BASE + RGPIO_CTRL),
|
|
rgpio_ints = (unsigned long *)(GPIO_BASE + RGPIO_INTS);
|
|
|
/* fails if x is false */
|
/* fails if x is false */
|
#define ASSERT(x) ((x)?1: fail (__FILE__, __LINE__))
|
#define ASSERT(x) ((x)?1: fail (__FILE__, __LINE__))
|
|
|
static void fail (char *file, int line)
|
static void fail (char *file, int line)
|
Line 84... |
Line 86... |
printf( "Testing initial values of all registers\n" );
|
printf( "Testing initial values of all registers\n" );
|
ASSERT( *rgpio_oe == 0 );
|
ASSERT( *rgpio_oe == 0 );
|
ASSERT( *rgpio_inte == 0 );
|
ASSERT( *rgpio_inte == 0 );
|
ASSERT( *rgpio_ptrig == 0 );
|
ASSERT( *rgpio_ptrig == 0 );
|
ASSERT( *rgpio_ctrl == 0 );
|
ASSERT( *rgpio_ctrl == 0 );
|
|
ASSERT( *rgpio_ints == 0 );
|
|
|
printf( "Verifying that RGPIO_IN is read-only\n" );
|
printf( "Verifying that RGPIO_IN is read-only\n" );
|
{
|
{
|
unsigned long value = *rgpio_in;
|
unsigned long value = *rgpio_in;
|
unsigned i;
|
unsigned i;
|
Line 118... |
Line 121... |
wait_input( 0x00000000 );
|
wait_input( 0x00000000 );
|
}
|
}
|
}
|
}
|
|
|
|
|
|
static void clear_interrupt_status( void )
|
|
{
|
|
*rgpio_ctrl &= ~RGPIO_CTRL_INTS;
|
|
*rgpio_ints = 0;
|
|
}
|
|
|
|
static void assert_good_interrupt( unsigned expected_count, unsigned long expected_mask )
|
|
{
|
|
ASSERT( int_count == expected_count );
|
|
ASSERT( (*rgpio_ctrl & RGPIO_CTRL_INTS) == RGPIO_CTRL_INTS );
|
|
ASSERT( (*rgpio_in & ~*rgpio_oe) == expected_mask );
|
|
ASSERT( (*rgpio_ints & ~*rgpio_oe) == expected_mask );
|
|
}
|
|
|
static void test_interrupts( void )
|
static void test_interrupts( void )
|
{
|
{
|
unsigned i;
|
unsigned i;
|
|
|
printf( "Testing interrupts\n" );
|
printf( "Testing interrupts\n" );
|
Line 132... |
Line 149... |
*rgpio_ptrig = 0x7fffffff;
|
*rgpio_ptrig = 0x7fffffff;
|
*rgpio_ctrl = RGPIO_CTRL_INTE;
|
*rgpio_ctrl = RGPIO_CTRL_INTE;
|
|
|
*rgpio_out = 0x80000000;
|
*rgpio_out = 0x80000000;
|
for ( i = 0; i < 31; ++ i ) {
|
for ( i = 0; i < 31; ++ i ) {
|
|
/* Wait for interrupt */
|
while ( int_count <= i );
|
while ( int_count <= i );
|
ASSERT( int_count == i + 1 );
|
assert_good_interrupt( i + 1, 1LU << i );
|
ASSERT( (*rgpio_ctrl & RGPIO_CTRL_INT) == RGPIO_CTRL_INT );
|
clear_interrupt_status();
|
ASSERT( (*rgpio_in & 0x7fffffff) == (1LU << i) );
|
|
ASSERT( (*rgpio_ctrl & RGPIO_CTRL_INT) == 0 );
|
|
*rgpio_out = (i % 2) ? 0x80000000 : 0;
|
*rgpio_out = (i % 2) ? 0x80000000 : 0;
|
}
|
}
|
|
|
/* Return things to normal */
|
/* Return things to normal */
|
*rgpio_ctrl = 0;
|
*rgpio_ctrl = 0;
|
Line 159... |
Line 175... |
int_count = 0;
|
int_count = 0;
|
*rgpio_ctrl = RGPIO_CTRL_INTE;
|
*rgpio_ctrl = RGPIO_CTRL_INTE;
|
*rgpio_out = 0x80000000;
|
*rgpio_out = 0x80000000;
|
for ( i = 0; i < 31; ++ i ) {
|
for ( i = 0; i < 31; ++ i ) {
|
while ( int_count <= i );
|
while ( int_count <= i );
|
ASSERT( int_count == i + 1 );
|
assert_good_interrupt( i + 1, 1LU << i );
|
ASSERT( (*rgpio_ctrl & RGPIO_CTRL_INT) == RGPIO_CTRL_INT );
|
clear_interrupt_status();
|
ASSERT( (*rgpio_in & 0x7fffffff) == (1LU << i) );
|
|
ASSERT( (*rgpio_ctrl & RGPIO_CTRL_INT) == 0 );
|
|
*rgpio_out = (i % 2) ? 0x80000000 : 0;
|
*rgpio_out = (i % 2) ? 0x80000000 : 0;
|
}
|
}
|
|
|
/* Test negative edge */
|
/* Test negative edge */
|
int_count = 0;
|
int_count = 0;
|
*rgpio_ctrl = RGPIO_CTRL_INTE | RGPIO_CTRL_NEC;
|
*rgpio_ctrl = RGPIO_CTRL_INTE | RGPIO_CTRL_NEC;
|
*rgpio_out = 0x80000000;
|
*rgpio_out = 0x80000000;
|
for ( i = 0; i < 31; ++ i ) {
|
for ( i = 0; i < 31; ++ i ) {
|
while ( int_count <= i );
|
while ( int_count <= i );
|
ASSERT( int_count == i + 1 );
|
assert_good_interrupt( i + 1, 1LU << i );
|
ASSERT( (*rgpio_ctrl & RGPIO_CTRL_INT) == RGPIO_CTRL_INT );
|
clear_interrupt_status();
|
ASSERT( (*rgpio_in & 0x7fffffff) == (1LU << i) );
|
|
ASSERT( (*rgpio_ctrl & RGPIO_CTRL_INT) == 0 );
|
|
*rgpio_out = (i % 2) ? 0x80000000 : 0;
|
*rgpio_out = (i % 2) ? 0x80000000 : 0;
|
}
|
}
|
|
|
/* Return things to normal */
|
/* Return things to normal */
|
*rgpio_ctrl = 0;
|
*rgpio_ctrl = 0;
|