- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi!
I am using a Nios II in my Cyclone II FPGA. I configured the Nios with a 18bit output-PIO. When i use the macro IOWR_ALTERA_AVALON_PIO_DATA() i can easily turn my leds on and off. Looking at the BSP file "altera_avalon_pio_regs.h" i find the following additional macros: IOWR_ALTERA_AVALON_PIO_SET_BITS() and IOWR_ALTERA_AVALON_PIO_CLEAR_BITS(). These functions have no effect on my leds (of course i am using the same base-address as in the macro IOWR_ALTERA_AVALON_PIO_DATA()). Does anybody have an explanation why these two macros seem to have no effect on my leds / the PIO? Searching this forum these macros are not meantioned at all. Even google is no help. ThanksLink Copied
10 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Make sure you enabled the "Enable individual bit setting/clearing" option in the pio properties in sopc builder.
Cris- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Cris!
Yes, thanks a lot for your quick reply. You are right: i did not enable the individual bit setting and clearing in the SOPC builder. I will report to this forum if this has the desired effect. FredFlintstone- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ok, now the "Enable individual bit setting/clearing" option in the sopc builder is checked for my pio (it must be the right pio because i only have one).
I regenerated the BSP in the "Nios II 9.1 Software Build Tools for Eclipse". Afterwards i did a full rebuild. Result: The macros IOWR_ALTERA_AVALON_PIO_SET_BITS() and IOWR_ALTERA_AVALON_PIO_CLEAR_BITS() still do not work. From the debug messages i can see that they must have been called ("Msg = set_bits", "Msg = clear_bits"). Is there any possibility to check if the pio now really has the set/clear registers? My source code: # include "sys/alt_stdio.h"# include "sys/alt_sys_wrappers.h"# include "system.h"# include "altera_avalon_pio_regs.h"# include "Msg.h"# include "Str.h"# include "io.h" static char c; static int n; int main() { alt_putstr("\n\nNios ii speaking...\n"); /* Event loop never exits. */ while (1) { n = read(0,&c,1); // read one char from stdin/0 if( n == 1 ) { Msg_DataIn(c); } if( Msg_Available() ) { alt_printf("The message is: %s\n",Msg()); if( Str_Equal(Msg(),"set_bits") ) { alt_putstr("Msg = set_bits\n"); IOWR_ALTERA_AVALON_PIO_SET_BITS(PIO_0_BASE, 0x0003FFFF); } if( Str_Equal(Msg(),"clear_bits") ) { alt_putstr("Msg = clear_bits\n"); IOWR_ALTERA_AVALON_PIO_CLEAR_BITS(PIO_0_BASE, 0x0003FFFF); } if( Str_Equal(Msg(),"on") ) { alt_putstr("Msg = on\n"); IOWR_ALTERA_AVALON_PIO_DATA(PIO_0_BASE, 0x0003FFFF); } if( Str_Equal(Msg(),"off") ) { alt_putstr("Msg = off\n"); IOWR_ALTERA_AVALON_PIO_DATA(PIO_0_BASE, 0x00000000); } Msg_Clear(); // alt_putchar(c); // write(1,&c,1); // write one char to stdout/1 } } return 0; }- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I never used this feature, anyway you can check system.h file. I think you should have this define: # define PIO_0_BIT_MODIFYING_OUTPUT_REGISTER 1
It would be 0 if individual set/clear is not enabled. Enabling individual set/clear in sopc builder, generates two extra pio registers at offset 4 and 5. You'll find complete (and more reliable than mine...) information in Nios reference handbook, vol 5, chapter 9 http://www.altera.com/literature/hb/nios2/n2cpu_nii51007.pdf Cris- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Another idea; probably you already tried it.
Did you try to set/clear a single bit instead of the complete 18bit pio?- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Chris!
Ok, i checked this my system.h file: Before enabling "Enable individual bit setting/clearing" ==># define PIO_0_BIT_MODIFYING_OUTPUT_REGISTER 0 Now after enabling "Enable individual bit setting/clearing" ==># define PIO_0_BIT_MODIFYING_OUTPUT_REGISTER 1 So the registers for setting and clearing the pio should be there... > Did you try to set/clear a single bit instead of the complete 18bit pio? Yes, i also tried this but it did not have any effect. FredFlintstone- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I tried with pio on my system and the bit set/clear feature works.
I only had to enable individual bit setting/clearing in sopc builder.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Cris!
Thank you for your efforts! It still does not work for me. I think i will try to rebuild the nios in sopc builder from scratch. But just another though: Could it be that the IOWR_ALTERA_AVALON_PIO_SET_BITS() and IOWR_ALTERA_AVALON_PIO_CLEAR_BITS() macro do not work because i derived my project from the "Hello World Small" template? Regards FredFlintstone- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- Could it be that the IOWR_ALTERA_AVALON_PIO_SET_BITS() and IOWR_ALTERA_AVALON_PIO_CLEAR_BITS() macro do not work because i derived my project from the "Hello World Small" template? Regards FredFlintstone --- Quote End --- I don't think so. I can't see any relation with the template. No OS or drivers are involved. This is only a matter of writing a register. Further suggestions: - try to write the actual set/clear registers (base+4, base+5) instead of using the macros - make sure you are loading the correct fpga configuration which includes the sopc where you enabled the bit set feature. - try with another pio port, 8bit wide (if you don't have free fpga pins for the new pio, add one more pio for reading the status with a loopback )
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Cris!
Yes, now it works (The macros IOWR_ALTERA_AVALON_PIO_SET_BITS() and IOWR_ALTERA_AVALON_PIO_CLEAR_BITS() work). After i have recreated my nios with sopc builder from scratch it suddenly worked. No change to my c-code. My pio still has a width of 18 bit. Just to sum it up for the thread followers: The macros IOWR_ALTERA_AVALON_PIO_SET_BITS() and IOWR_ALTERA_AVALON_PIO_CLEAR_BITS() did not work because i missed to enable the individual bit setting/clearing when i set up the pio in the sopc builder. After enabling it and a nios rebuild the macros work fine. Thanks for that advice Cris! Best regards FredFlintstone
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page