How to output register value on PUTTY
Hi, I have made the following qsys system as shown in fig. I have assigned the outputs to the LEDS. So whatever number I sent via putty terminal, the corresponding LEDS are light up on the board. The header file I generate with generate script gives me the base address and offset address of the LEDS. Now, I don't want to use any hardware peripheral on board, I just want that whatever value I send to the register, the value saved in the register is simply shown at the putty terminal. I am just confused that I have used LEDs in my pin assignment editor of my Quartus software so that's why a header file is generated that tells me the base and offset addresses but how do I get base and offset address of my output terminal with out because these are the addresses that I am using to tell my c code that give me output at this address and write at this address.
/* this is my C code*/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdint.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "C:\altera\15.1\embedded\ip\altera\hps\altera_hps\hwlib\include\hwlib.h"
#include "C:\altera\15.1\embedded\ip\altera\hps\altera_hps\hwlib\include\soc_cv_av\socal\socal.h"
#include "C:\altera\15.1\embedded\ip\altera\hps\altera_hps\hwlib\include\soc_cv_av\socal\hps.h"
#include "C:\altera\15.1\embedded\ip\altera\hps\altera_hps\hwlib\include\soc_cv_av\socal\alt_gpio.h"
#include "D:\masterarbeit3\reginteraction\hps_0.h"
#define REG_BASE 0xFF200000
#define REG_SPAN 0x00200000
/* Pointers Theory
1. Normal variables stores values while pointers store the address of that variables
2. The content of C pointers will always be a whole number
3. C pointer is initialized to NULL. The value of NULL pointer is zero. If a pointer in C is assigned to NULL then that means that it is pointing to nothing
4. & symbol is used to get the address of the variables
5. * symbol is used to get the value of the variable that the pointer is pointing to
6. Two pointers can be subtracted to know how many elements are between them but pointer addition, multiplication and division is not allowed.
7. The size of pointer is 2 bytes in case of 16 bit compiler. */
volatile unsigned char *led_addr; /*this is the pointer that writes to the register. This is our write input*/
void* virtual_base; /*pointer to open device memory file*/
int main ()
{
int fd = EXIT_FAILURE;
int value; /*this is our input to the register*/
unsigned char led;
printf("Please enter a number from 1 to 15: ");
scanf("%d",&value);
printf("you entered the value :%d",value);
/*
value = atoi(&value);
*/
if (value < 1 || value > 15) {
printf("Put number from 1 to 15\n");
exit(EXIT_FAILURE);
}
fd=open("/dev/mem",(O_RDWR|O_SYNC));
if (fd < 0) {
perror("open");
exit(EXIT_FAILURE);
}
virtual_base=mmap(NULL,REG_SPAN,(PROT_READ|PROT_WRITE),MAP_SHARED,fd,REG_BASE);
/* get the delay_ctrl peripheral's base address */
led_addr = (unsigned char *) (virtual_base+REGGET_0_BASE);
/*is it possible if I give value with scanf function and just assign it to *led_addr?*/
/*writing the value*/
*led_addr=value;
led=*led_addr;
printf("%c\n",led);
return 0;
}