Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Novice
376 Views

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; }

qsys design.JPG

0 Kudos
4 Replies
Highlighted
Employee
6 Views

Hello,

I am a bit confused regarding your request.

HWLIB is not supported to run on linux.

You are trying to send a value to HPS via putty, this value will be stored in a register, I assume this register is routed to LEDs through pin planner.

If you write any value to this register, you need to see some LED blinks, am I right?

usually we use GPIO to control LEDs. It is simpler.

is this regget custom component?

 

Thanks

Highlighted
Novice
6 Views

Hi,

I am running quartus software in windows so my host computer is running on windows 10.

Yes regget is a custom component.

I solved the problem. So, I was trying to print ascii values using %c in my printf(), that was the reason that I was not able to get output. I used %d and now I am getting correct outputs.

Yes you are right we usually use GPIO for LEDS that is much simpler but I didn't wanted to use LEDS. So the concept is that you connect your register to AVALON MM bus so whatever you want to read and write on AVALON MM, you just write on it using virtual memory mapping and that will be printed on output of putty.

0 Kudos
Highlighted
Novice
6 Views

you can also see my code above but dont forget to replace %c with %d in above.

Highlighted
Employee
6 Views

Thanks for your reply,

Glad to hear your issue was solved. Please let me know if you need further assistance.

 

 

Thanks