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

Code output on putty not correct?

#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 argc, char *argv[]) { int fd = EXIT_FAILURE; unsigned char value; /*this is our input to the register*/ unsigned char led; if (argc < 2) { fprintf(stderr, "Usage: %s number from 1 to 15\n", argv[0]); exit(EXIT_FAILURE); } value = atoi(argv[1]); if (value < 1 || value > 15) { fprintf(stderr, "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); /*writing the value*/ *led_addr=value; led=*led_addr; printf("%c\n",led); return 0; }

Hi, I want to display the values of LED on my putty terminal but whenever I try it always disply 173 or strange symbols. what is wrong with this code.

0 Kudos
5 Replies
Highlighted
New Contributor I
32 Views

​Using %c for the printf formatter prints the ASCII char for the value in led - it looks like this is expected to be 1-15 which are not in the alpha-numeric ASCII range.

Are you sure you want "%c" here ? Suggest that you use "%d" instead.

0 Kudos
Highlighted
Novice
32 Views

Hi, thanks for your answer. I also tried %d but everytime I run my program, the output is always 173. no matter whether I give input 10 , 11 or 12 , the output is always 173. Any ideas what is happening.?

0 Kudos
Highlighted
32 Views

Hi,

Did you try ‘memtool’ below?

https://gist.github.com/mike0/2910170

It is simple memory read/write program on Linux, and it also works fine on Cyclone V SoC.

0 Kudos
Highlighted
Novice
32 Views

@YS11​  Thank you so much for your reply. Just one more question, do you have any tutorial or resource on how to write a Linux application that can read or write from a FIFO on FPGA side? I have made FIFO in FPGA, everything is fine and working, I just dont know how do I write C application that can read or write data to this FIFO? I shall be really grateful to you if you can please suggest me something?

0 Kudos
Highlighted
32 Views

Hi,

I tried to find good example about FIFO. But, I was unable to find one.

Here is an example driver code for the following IP which has FIFO for TX and RX data.

15. Intel FPGA Avalon I2C(Master) Core

https://www.intel.com/content/dam/www/programmable/us/en/pdfs/literature/ug/ug_embedded_ip.pdf#page=...

i2c-axxia.c driver.

https://github.com/altera-opensource/linux-socfpga/blob/master/drivers/i2c/busses/i2c-altera.c

I hope it helps.