Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

c programming for Pin pio

Altera_Forum
Honored Contributor II
1,455 Views

Hi there...i'm currently having problem of understanding the pin input pio.... 

 

my nios is connected to the 16 bits pio pin in the development board...how to write a c code to retrieve the inputs from this pio.. 

 

since this inputs are in binary, do i need to convert to decimal or the system itself will convert for me in C language. 

 

thnaks and regards 

wayne
0 Kudos
5 Replies
Altera_Forum
Honored Contributor II
478 Views

 

--- Quote Start ---  

originally posted by niceguylow@Dec 7 2005, 02:56 PM 

hi there...i'm currently having problem of understanding the pin input pio.... 

 

my nios is connected to the 16 bits pio pin in the development board...how to write a c code to retrieve the inputs from this pio.. 

 

since this inputs are in binary, do i need to convert to decimal or the system itself will convert for me in c language. 

 

thnaks and regards 

wayne 

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=11393) 

--- quote end ---  

 

--- Quote End ---  

 

 

You can try using the PIO functions made available by Altera... like the one used in the count_binary example of the HAL... 

 

The numbers you&#39;ll read from the PIO have to be interpreted as a set of bits inside a 32-bit integer... For example, if you have a 2 bit PIO, you&#39;ll end up having the 2 bits valies inside the 2 less significant bits of the integer you read from the peripheral. 

 

 

bye 

 

Paolo
0 Kudos
Altera_Forum
Honored Contributor II
478 Views

 

--- Quote Start ---  

originally posted by paolo.gai+dec 7 2005, 08:38 am--><div class='quotetop'>quote (paolo.gai @ dec 7 2005, 08:38 am)</div> 

--- quote start ---  

<!--quotebegin-niceguylow@Dec 7 2005, 02:56 PM 

hi there...i&#39;m currently having problem of understanding the pin input pio.... 

 

my nios is connected to the 16 bits pio pin in the development board...how to write a c code to retrieve the inputs from this pio.. 

 

since this inputs are in binary, do i need to convert to decimal or the system itself will convert for me in c language. 

 

thnaks and regards 

wayne 

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=11393) 

--- quote end ---  

 

--- Quote End ---  

 

 

You can try using the PIO functions made available by Altera... like the one used in the count_binary example of the HAL... 

 

The numbers you&#39;ll read from the PIO have to be interpreted as a set of bits inside a 32-bit integer... For example, if you have a 2 bit PIO, you&#39;ll end up having the 2 bits valies inside the 2 less significant bits of the integer you read from the peripheral. 

 

 

bye 

 

Paolo 

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=11396)</div> 

[/b] 

--- Quote End ---  

 

 

 

 

this is my sample of the c ....will it work ? 

 

let say my pio is a 16 bit input...would it put receive the 16 bits input. 

since np_pio is defined as int...the 16 bits are automatically converted into integer? 

 

 

 

np_pio *pio = na_pio; 

 

if i want to access obtain the data... 

 

pio->np_piodata;
0 Kudos
Altera_Forum
Honored Contributor II
478 Views

Are you using IORD_ALTERA_AVALON_PIO_DATA(base) ? 

 

Paolo
0 Kudos
Altera_Forum
Honored Contributor II
478 Views

Hello niceguylow, 

 

the PIO Core is described in the Quartus II Development Software Handbook Volume 5: Embedded Peripherals (http://www.altera.com/literature/quartus2/lit-qts-peripherals.jsp). For accesing the PIO registers there are some macros which are included in “altera_avalon_pio_regs.h”: 

 

#define IOADDR_ALTERA_AVALON_PIO_DATA(base)           __IO_CALC_ADDRESS_NATIVE(base, 0)# define IORD_ALTERA_AVALON_PIO_DATA(base)             IORD(base, 0) # define IOWR_ALTERA_AVALON_PIO_DATA(base, data)       IOWR(base, 0, data) # define IOADDR_ALTERA_AVALON_PIO_DIRECTION(base)      __IO_CALC_ADDRESS_NATIVE(base, 1)# define IORD_ALTERA_AVALON_PIO_DIRECTION(base)        IORD(base, 1) # define IOWR_ALTERA_AVALON_PIO_DIRECTION(base, data)  IOWR(base, 1, data) # define IOADDR_ALTERA_AVALON_PIO_IRQ_MASK(base)       __IO_CALC_ADDRESS_NATIVE(base, 2)# define IORD_ALTERA_AVALON_PIO_IRQ_MASK(base)         IORD(base, 2) # define IOWR_ALTERA_AVALON_PIO_IRQ_MASK(base, data)   IOWR(base, 2, data) # define IOADDR_ALTERA_AVALON_PIO_EDGE_CAP(base)       __IO_CALC_ADDRESS_NATIVE(base, 3)# define IORD_ALTERA_AVALON_PIO_EDGE_CAP(base)         IORD(base, 3) # define IOWR_ALTERA_AVALON_PIO_EDGE_CAP(base, data)   IOWR(base, 3, data) 

 

Regards, 

niosIIuser
0 Kudos
Altera_Forum
Honored Contributor II
478 Views

....... 

alt_16 my_data; 

..... 

my_data = IORD(YOUR_PIO_BASE_ADDRESS,0); 

......
0 Kudos
Reply