Sorry, thought it would turn up inline.
Yes, NOCACHE is enabled, but it almost seems
that it’s caching anyway when reading.
Tom
8<-----------------------------------------------------------------------
FPGA read test:
8<-----------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <errno.h>
#include <sys/mman.h>
#include <sys/neutrino.h>
#define STATIC_REG_OFF 0x7E
#define MIN_DELAY 200000
static volatile uint16_t* Static_reg;
static volatile uint16_t value ;
int main (int argc, char* argv[] )
{
int delay = 500000;
int verbose = 1;
uint8_t* BaseAddr;
w_value = 0xdcba ;
switch (argc)
{
case 3:
verbose = strtol( argv[2], NULL, 0 );
/* fall through to next case */
case 2:
if (strcmp( “help”, argv[1] ) == 0)
{
printf( “Usage: %s [delay in micro sec (min %d if verbose)] [Be verbose (1/0)]\n”, argv[0], MIN_DELAY );
return EXIT_FAILURE;
}
delay = strtol( argv[1], NULL, 0 );
if (verbose != 0 && delay < MIN_DELAY) // Don’t kill the console!
delay = MIN_DELAY;
/* fall through to next case */
case 1:
break;
default:
printf( “Usage: %s [delay in micro sec (min %d if verbose)] [Be verbose (1/0)]\n”, argv[0], MIN_DELAY );
return EXIT_FAILURE;
}
if (ThreadCtl(_NTO_TCTL_IO, 0) == -1)
{
perror( “Error when setting thread IO privilege, must be root to run this code” );
exit( EXIT_FAILURE );
}
BaseAddr = (uint8_t*)mmap_device_memory( NULL, 0x0100, PROT_READ | PROT_WRITE | PROT_NOCACHE, 0, 0x0fff00 );
if ( BaseAddr == MAP_FAILED )
{
perror( “Mapping device memory area to process failed” );
exit( EXIT_FAILURE );
}
Static_reg = (volatile uint16_t*) (BaseAddr + STATIC_REG_OFF);
printf( “\nMapped static register to %lx\n”, Static_reg );
printf( “Read test starting (Hit Ctrl+C to exit)…\n\n” );
sleep(1);
while(1)
{
value = *Static_reg;
if (verbose != 0)
printf( “Register value: %X\n”, value );
usleep(delay);
}
return 0;
}
8<-----------------------------------------------------------------------
FPGA write test:
8<-----------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <errno.h>
#include <sys/mman.h>
#include <sys/neutrino.h>
#define STATIC_REG_OFF 0x7E
#define MIN_DELAY 200000
int main ( int argc, char* argv[] )
{
uint8_t* BaseAddr;
uint16_t* Static_reg;
uint16_t value = 0xABCD;
int delay = 500000;
int verbose = 1;
switch (argc)
{
case 4:
verbose = strtol( argv[3], NULL, 0 );
/* fall through to next case */
case 3:
delay = strtol( argv[2], NULL, 0 );
if (verbose != 0 && delay < MIN_DELAY) // Don’t kill the console!
delay = MIN_DELAY;
/* fall through to next case */
case 2:
if (strcmp( “help”, argv[1] ) == 0)
{
printf( “Usage: %s [value] [delay in micro sec (min %d if verbose)] [Be verbose (1/0)]\n”, argv[0], MIN_DELAY );
return EXIT_FAILURE;
}
value = strtol( argv[1], NULL, 0 );
break;
case 1:
break;
default:
printf( “Usage: %s [value] [delay in micro sec (min %d if verbose)] [Be verbose (1/0)]\n”, argv[0], MIN_DELAY );
return EXIT_FAILURE;
}
if (ThreadCtl(_NTO_TCTL_IO, 0) == -1)
{
perror( “Error when setting thread IO privilege, must be root to run this code” );
exit( EXIT_FAILURE );
}
BaseAddr = (uint8_t*)mmap_device_memory( NULL, 0x0100, PROT_READ | PROT_WRITE | PROT_NOCACHE, 0, 0x0fff00 );
if ( BaseAddr == MAP_FAILED )
{
perror( “Mapping device memory area to process failed” );
exit( EXIT_FAILURE );
}
Static_reg = (uint16_t*) (BaseAddr + STATIC_REG_OFF);
printf( “\nMapped static register to %lx\n”, Static_reg );
printf( “Write test starting (Hit Ctrl+C to exit)…\n\n” );
sleep(1);
while(1)
{
if (verbose != 0)
printf( “Writing value: %X\n”, value );
*Static_reg = value;
usleep(delay);
}
return 0;
}