|
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include <fcntl.h>
|
|
#include <sys/mman.h>
|
|
#include "hwlib.h"
|
|
#include "socal/socal.h"
|
|
#include "socal/hps.h"
|
|
#include "socal/alt_gpio.h"
|
|
#include "hps_0.h"
|
|
#include <stdlib.h>
|
|
#include <math.h>
|
|
#include <string.h>
|
|
|
|
#define HW_REGS_BASE ( ALT_STM_OFST )
|
|
#define HW_REGS_SPAN ( 0x04000000 )
|
|
#define HW_REGS_MASK ( HW_REGS_SPAN - 1 )
|
|
|
|
int main(int argc,char *argv[]) {
|
|
|
|
void *virtual_base;
|
|
int fd;
|
|
void *h2p_lw1_led_addr;
|
|
void *h2p_lw4_led_addr;
|
|
|
|
unsigned long i;
|
|
|
|
|
|
|
|
// map the address space for the LED registers into user space so we can interact with them.
|
|
// we'll actually map in the entire CSR span of the HPS since we want to access various registers within that span
|
|
//exit(0);
|
|
if( ( fd = open( "/dev/mem", ( O_RDWR | O_SYNC ) ) ) == -1 ) {
|
|
printf( "ERROR: could not open \"/dev/mem\"...\n" );
|
|
return( 1 );
|
|
}
|
|
|
|
virtual_base = mmap( NULL, HW_REGS_SPAN, ( PROT_READ | PROT_WRITE ), MAP_SHARED, fd, HW_REGS_BASE );
|
|
|
|
if( virtual_base == MAP_FAILED ) {
|
|
printf( "ERROR: mmap() failed...\n" );
|
|
close( fd );
|
|
return( 1 );
|
|
}
|
|
|
|
h2p_lw1_led_addr=virtual_base + ( ( unsigned long )( ALT_LWFPGASLVS_OFST + REG32_WRITE_0_BASE ) & ( unsigned long)( HW_REGS_MASK ) );//adresse de base = 0x10
|
|
h2p_lw4_led_addr=virtual_base + ( ( unsigned long )( ALT_LWFPGASLVS_OFST + REG_READ_0_BASE +0x0C ) & ( unsigned long)( HW_REGS_MASK ) );
|
|
|
|
|
|
unsigned int min = 0;
|
|
unsigned int max = 65535;
|
|
unsigned int ecart = 0;
|
|
|
|
|
|
while(1){
|
|
unsigned int i;
|
|
/*
|
|
//Incrementation
|
|
for(i=min+ecart; i<max-ecart; i++){
|
|
*(uint32_t *)h2p_lw1_led_addr = i;
|
|
}*/
|
|
|
|
//Décrementation
|
|
for(i=max; i>min; i--){
|
|
*(uint32_t *)h2p_lw1_led_addr = i;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// clean up our memory mapping and exit
|
|
|
|
if( munmap( virtual_base, HW_REGS_SPAN ) != 0 ) {
|
|
printf( "ERROR: munmap() failed...\n" );
|
|
close( fd );
|
|
return( 1 );
|
|
}
|
|
|
|
close( fd );
|
|
|
|
return( 0 );
|
|
}
|