- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
this is my code below,
its self explanatory, i am unable to get the IOWR_ALTERA_AVALON_PIO_SET_BITS(base) to work as the output is confirming it. My PIO is set to 1 # define ALT_MODULE_CLASS_GPIO_0 altera_avalon_pio # define GPIO_0_BIT_MODIFYING_OUTPUT_REGISTER 1 CODE::: # include <stdio.h> # include <unistd.h> # include "altera_avalon_pio_regs.h" # include "system.h" # include <strings.h> // Time in microseconds to wait for switch debounce int main(void) { printf("Simple\n"); // print a message to show that program is running int data1 = 0x00000309; int val,val2; //while(1){ IOWR_ALTERA_AVALON_PIO_DATA(GPIO_0_BASE,data1); val = IORD_ALTERA_AVALON_PIO_DATA(GPIO_0_BASE); printf("previous value = %x \n",val); IOWR_ALTERA_AVALON_PIO_SET_BITS(GPIO_0_BASE+4, 0x02); val2 =IORD_ALTERA_AVALON_PIO_DATA(GPIO_0_BASE); printf("value after setting the bit = %x " , val2); //} } -----------------OUTPUT------------------ Simple previous value = 309 value after setting the bit = 309Link Copied
6 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You shouldn't call IOWR_ALTERA_AVALON_PIO_SET_BITS with an Offset, as the offset is already added inside the Macro.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for your help
I got this working # include <stdio.h> # include <unistd.h> # include "altera_avalon_pio_regs.h" # include "system.h" int main(void){ int val; //IOWR_ALTERA_AVALON_PIO_DATA(GPIO_1_BASE,0x0000); //printf( " GPIO default values are set at 0 \n"); IOWR_ALTERA_AVALON_PIO_SET_BITS(GPIO_1_BASE,0x0003); val = IORD_ALTERA_AVALON_PIO_DATA(GPIO_1_BASE); IOWR_ALTERA_AVALON_PIO_DATA(LEDR_BASE, val); usleep(10000000); IOWR_ALTERA_AVALON_PIO_CLEAR_BITS(GPIO_1_BASE, 0x0001); val = IORD_ALTERA_AVALON_PIO_DATA(GPIO_1_BASE); IOWR_ALTERA_AVALON_PIO_DATA(LEDR_BASE, val); //set latch //printf(" GPIO 1st bit set to 1\n"); // IOWR_ALTERA_AVALON_PIO_CLEAR_BITS(GPIO_0_BASE,0x1000);//oe enable // IOWR_ALTERA_AVALON_PIO_CLEAR_BITS(GPIO_0_BASE,0x200);//clear latch }- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What's the advantage of using this approach instead of the IOWR_32DIRECT and IORD_32DIRECT?
(or just IOWR and IORD_- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Readability.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hmmm... IMHO any code that uses any of the IOWR* defines is inherently unreadable and difficult to maintain.
In this case you are also forcing 3 io/memory cycles when (probably) 2 are needed. I'd also tend to recommend using 'write 1 to set' and 'write 1 to clear' registers for general pio in order to remove the need for read-modify-write cycles on shared resources (save the need to disable interrupts).- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- Readability. --- Quote End --- Nice comment! Seriously can we have smaller, readable not-all capitals macros please.
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