URL
https://opencores.org/ocsvn/or1k/or1k/trunk
Subversion Repositories or1k
[/] [or1k/] [tags/] [nog_patch_60/] [or1ksim/] [testbench/] [acv_gpio.c] - Rev 499
Go to most recent revision | Compare with Previous | Blame | View Log
/* GPIO test */ #include "spr_defs.h" #include "support.h" #include "int.h" /* Relative Register Addresses */ #define RGPIO_IN (4 * 0x00) #define RGPIO_OUT (4 * 0x01) #define RGPIO_OE (4 * 0x02) #define RGPIO_INTE (4 * 0x03) #define RGPIO_PTRIG (4 * 0x04) #define RGPIO_AUX (4 * 0x05) #define RGPIO_CTRL (4 * 0x06) /* Fields inside RGPIO_CTRL */ #define RGPIO_CTRL_ECLK 0x00000001 #define RGPIO_CTRL_NEC 0x00000002 #define RGPIO_CTRL_INTE 0x00000004 #define RGPIO_CTRL_INT 0x00000008 #define GPIO_BASE 0xB0000000LU #define GPIO_INT_LINE 23 /* To which interrupt is GPIO connected */ typedef volatile unsigned long *GPIO_REG; GPIO_REG rgpio_in = (unsigned long *)(GPIO_BASE + RGPIO_IN), rgpio_out = (unsigned long *)(GPIO_BASE + RGPIO_OUT), rgpio_oe = (unsigned long *)(GPIO_BASE + RGPIO_OE), rgpio_inte = (unsigned long *)(GPIO_BASE + RGPIO_INTE), rgpio_ptrig = (unsigned long *)(GPIO_BASE + RGPIO_PTRIG), rgpio_aux = (unsigned long *)(GPIO_BASE + RGPIO_AUX), rgpio_ctrl = (unsigned long *)(GPIO_BASE + RGPIO_CTRL); /* fails if x is false */ #define ASSERT(x) ((x)?1: fail (__FILE__, __LINE__)) static void fail (char *file, int line) { printf( "Test failed in %s:%i\n", file, line ); report( 0xeeeeeeee ); exit( 1 ); } static void wait_input( unsigned long value ) { unsigned long first = *rgpio_in; if ( first == value ) return; while ( 1 ) { unsigned long curr = *rgpio_in; if ( curr == value ) return; if ( curr != first ) { printf( "While waiting for 0x%08lX, input changed from 0x%08lX to 0x%08lX\n", value, first, curr ); ASSERT( 0 ); } } } static volatile unsigned int_count = 0; static void gpio_interrupt( void *arg ) { ++ int_count; } static void init_interrupts( void ) { int_init(); int_add( GPIO_INT_LINE, gpio_interrupt, 0, INT_LOW_PRI ); /* Enable interrupts */ mtspr( SPR_SR, mfspr(SPR_SR) | SPR_SR_EXR | SPR_SR_EIR ); } static void test_registers( void ) { printf( "Testing initial values of all registers\n" ); ASSERT( *rgpio_oe == 0 ); ASSERT( *rgpio_inte == 0 ); ASSERT( *rgpio_ptrig == 0 ); ASSERT( *rgpio_ctrl == 0 ); printf( "Verifying that RGPIO_IN is read-only\n" ); { unsigned long value = *rgpio_in; unsigned i; *rgpio_in = ~value; ASSERT( *rgpio_in == value ); for ( i = 0; i < 32; ++ i ) { *rgpio_in = 1LU << i; ASSERT( *rgpio_in == value ); } } } static void test_simple_io( void ) { unsigned i; unsigned long oe; printf( "Testing simple I/O\n" ); for ( i = 1, oe = 1; i < 31; ++ i, oe = (oe << 1) | 1 ) { *rgpio_oe = oe; *rgpio_out = 0xFFFFFFFF; wait_input( 0xFFFFFFFF ); *rgpio_out = 0x00000000; wait_input( 0x00000000 ); } } static void test_interrupts( void ) { unsigned i; printf( "Testing interrupts\n" ); *rgpio_oe = 0x80000000; int_count = 0; *rgpio_inte = 0x7fffffff; *rgpio_ptrig = 0x7fffffff; *rgpio_ctrl = RGPIO_CTRL_INTE; *rgpio_out = 0x80000000; for ( i = 0; i < 31; ++ i ) { while ( int_count <= i ); ASSERT( int_count == i + 1 ); ASSERT( (*rgpio_ctrl & RGPIO_CTRL_INT) == RGPIO_CTRL_INT ); ASSERT( (*rgpio_in & 0x7fffffff) == (1LU << i) ); ASSERT( (*rgpio_ctrl & RGPIO_CTRL_INT) == 0 ); *rgpio_out = (i % 2) ? 0x80000000 : 0; } /* Return things to normal */ *rgpio_ctrl = 0; } static void test_external_clock( void ) { unsigned i; printf( "Testing external clock\n" ); *rgpio_oe = 0x80000000; *rgpio_inte = 0x7fffffff; *rgpio_ptrig = 0x7fffffff; /* Test positive edge */ int_count = 0; *rgpio_ctrl = RGPIO_CTRL_INTE; *rgpio_out = 0x80000000; for ( i = 0; i < 31; ++ i ) { while ( int_count <= i ); ASSERT( int_count == i + 1 ); ASSERT( (*rgpio_ctrl & RGPIO_CTRL_INT) == RGPIO_CTRL_INT ); ASSERT( (*rgpio_in & 0x7fffffff) == (1LU << i) ); ASSERT( (*rgpio_ctrl & RGPIO_CTRL_INT) == 0 ); *rgpio_out = (i % 2) ? 0x80000000 : 0; } /* Test negative edge */ int_count = 0; *rgpio_ctrl = RGPIO_CTRL_INTE | RGPIO_CTRL_NEC; *rgpio_out = 0x80000000; for ( i = 0; i < 31; ++ i ) { while ( int_count <= i ); ASSERT( int_count == i + 1 ); ASSERT( (*rgpio_ctrl & RGPIO_CTRL_INT) == RGPIO_CTRL_INT ); ASSERT( (*rgpio_in & 0x7fffffff) == (1LU << i) ); ASSERT( (*rgpio_ctrl & RGPIO_CTRL_INT) == 0 ); *rgpio_out = (i % 2) ? 0x80000000 : 0; } /* Return things to normal */ *rgpio_ctrl = 0; } static void endshake( void ) { printf( "Finishing simulation\n" ); *rgpio_oe = 0xffff0000; *rgpio_out = 0x12340000; wait_input( 0x12345678 ); *rgpio_oe = 0xffffffff; *rgpio_out = 0xDeadDead; } int main() { printf( "Starting GPIO test\n" ); init_interrupts(); test_registers(); test_simple_io(); test_interrupts(); test_external_clock(); endshake(); printf( "Ending GPIO test\n" ); report (0xdeaddead); return 0; }
Go to most recent revision | Compare with Previous | Blame | View Log