Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Altera_Forum
Honored Contributor I
712 Views

NIOS II CustomComponent Programming Problem

Hi all, 

 

I have created a LED register in vhdl and created qsys component out of that. Connected it to the nios processor as shown in below images. Created NIOS project and when I am trying to run the code the register is not updated. But if I access with the base address of the memory map generated, it is getting updated. Kindly someone let me know what could be the issue. 

 

I included system.h and written a simple program to edit the led base register. From memory I am able to access and blink led. But from C program I am not able to control it. 

# include <stdio.h> # include "system.h"  

int main()  

{  

unsigned int* ledbaseaddr =(unsigned int *) LEDREG_0_BASE;  

// unsigned int i;  

while(1)  

{  

*ledbaseaddr = 0xFF;  

//for(i=0;i<100;i++);  

*ledbaseaddr = 0x00;  

}  

 

http://www.alteraforum.com/forum/attachment.php?attachmentid=10302&stc=1 http://www.alteraforum.com/forum/attachment.php?attachmentid=10300&stc=1  

 

http://www.alteraforum.com/forum/attachment.php?attachmentid=10301&stc=1 http://www.alteraforum.com/forum/attachment.php?attachmentid=10302&stc=1  

 

 

 

 

Regards, 

Phaniendra
0 Kudos
2 Replies
Altera_Forum
Honored Contributor I
21 Views

I guess this happens because Nios uses byte addressing, while C code unsigned int* forces 32bit addressing. Try to cast with unsigned char* . 

Anyway the best way to access qsys component registers is through IOWR/IORD macros, which automatically take care of matching the device bus size.
Altera_Forum
Honored Contributor I
21 Views

Hi cris, 

 

thanks for the reply. I have used IOWR/IORD macros and problem got solved.
Reply