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

create software for Altere PIO 's

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 = 309
0 Kudos
6 Replies
Altera_Forum
Honored Contributor I
49 Views

You shouldn't call IOWR_ALTERA_AVALON_PIO_SET_BITS with an Offset, as the offset is already added inside the Macro.

Altera_Forum
Honored Contributor I
49 Views

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 

 

 

 

}
Altera_Forum
Honored Contributor I
49 Views

What's the advantage of using this approach instead of the IOWR_32DIRECT and IORD_32DIRECT? 

 

(or just IOWR and IORD_
Altera_Forum
Honored Contributor I
49 Views

Readability.

Altera_Forum
Honored Contributor I
49 Views

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).
Altera_Forum
Honored Contributor I
49 Views

 

--- Quote Start ---  

Readability. 

--- Quote End ---  

 

 

Nice comment! 

 

Seriously can we have smaller, readable not-all capitals macros please.
Reply