Line 1... |
Line 1... |
/* GPIO test */
|
/* GPIO test */
|
|
|
|
#include "spr_defs.h"
|
#include "support.h"
|
#include "support.h"
|
|
|
/* Relative Register Addresses */
|
/* Relative Register Addresses */
|
#define RGPIO_IN (4 * 0x00)
|
#define RGPIO_IN (4 * 0x00)
|
#define RGPIO_OUT (4 * 0x01)
|
#define RGPIO_OUT (4 * 0x01)
|
Line 17... |
Line 18... |
#define RGPIO_CTRL_INTE 0x00000004
|
#define RGPIO_CTRL_INTE 0x00000004
|
#define RGPIO_CTRL_INT 0x00000008
|
#define RGPIO_CTRL_INT 0x00000008
|
|
|
#define GPIO_BASE 0xB0000000LU
|
#define GPIO_BASE 0xB0000000LU
|
|
|
|
#define GPIO_INT_LINE 23 /* To which interrupt is GPIO connected */
|
|
|
typedef volatile unsigned long *GPIO_REG;
|
typedef volatile unsigned long *GPIO_REG;
|
|
|
GPIO_REG rgpio_in = (unsigned long *)(GPIO_BASE + RGPIO_IN),
|
GPIO_REG rgpio_in = (unsigned long *)(GPIO_BASE + RGPIO_IN),
|
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);
|
|
|
|
/* 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 interrupt_handler( void )
|
|
{
|
|
++ int_count;
|
|
mtspr( SPR_PICSR, 0 );
|
|
}
|
|
|
|
static void init_interrupts( void )
|
|
{
|
|
/* Use our low priority interrupt handler */
|
|
excpt_lpint = (unsigned long)interrupt_handler;
|
|
|
|
/* Enable interrupts */
|
|
mtspr( SPR_SR, mfspr(SPR_SR) | SPR_SR_EXR | SPR_SR_EIR );
|
|
mtspr( SPR_PICMR, mfspr(SPR_PICMR) | (0x00000001L << GPIO_INT_LINE) );
|
|
}
|
|
|
|
|
|
|
|
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()
|
int main()
|
{
|
{
|
printf( "Starting GPIO test\n" );
|
printf( "Starting GPIO test\n" );
|
|
|
while ( *rgpio_in != 0x01234567 )
|
init_interrupts();
|
;
|
|
*rgpio_oe = 0xffffffff;
|
test_registers();
|
*rgpio_out = 0x89abcdef;
|
test_simple_io();
|
|
test_interrupts();
|
|
test_external_clock();
|
|
endshake();
|
|
|
printf( "Ending GPIO test\n" );
|
printf( "Ending GPIO test\n" );
|
|
|
report (0xdeaddead);
|
report (0xdeaddead);
|
return 0;
|
return 0;
|