Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
14 years ago

PIO Direction

hi all,

I am using bidirectional pio for my design.Can some one tell me how to set the directions.

I am using IOWR_ALTERA_AVALON_PIO_DIRECTION(PIO_DATA_BASE, 0);

for using pio as output and

IOWR_ALTERA_AVALON_PIO_DIRECTION(PIO_DATA_BASE, 1);

for input.

is it correct or not,because my design is not working as expected.

Thanks in advance,

Sarat

5 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Actually they are inverted: 0 is for input and 1 for output.

    Moreover this is correct only for single I/O pio: if your pio is wider, you need to set all the required bits.

    Last thing you need to check is if you enabled the bidirecitonal feature in sopc/Qsys pio properties
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi,

    Thank you for your reply.

    I am using 8 bit PIO for my design.I have set it as bidirectional in QSYS.

    What I understood from your post is,if I have to write 8 bits from the bus I have to write like this

    IOWR_ALTERA_AVALON_PIO_DIRECTION(PIO_DATA_BASE, 0);

    IOWR_ALTERA_AVALON_PIO_DIRECTION(PIO_DATA_BASE+2, 0);

    IOWR_ALTERA_AVALON_PIO_DIRECTION(PIO_DATA_BASE+4, 0);

    IOWR_ALTERA_AVALON_PIO_DIRECTION(PIO_DATA_BASE+6, 0);

    IOWR_ALTERA_AVALON_PIO_DIRECTION(PIO_DATA_BASE+8, 0);

    IOWR_ALTERA_AVALON_PIO_DIRECTION(PIO_DATA_BASE+10, 0);

    IOWR_ALTERA_AVALON_PIO_DIRECTION(PIO_DATA_BASE+12, 0);

    IOWR_ALTERA_AVALON_PIO_DIRECTION(PIO_DATA_BASE+14, 0);

    IOWR_ALTERA_AVALON_PIO_DATA ( PIO_DATA_BASE , address );

    and for reading

    IOWR_ALTERA_AVALON_PIO_DIRECTION(PIO_DATA_BASE, 1);

    IOWR_ALTERA_AVALON_PIO_DIRECTION(PIO_DATA_BASE+2, 1);

    IOWR_ALTERA_AVALON_PIO_DIRECTION(PIO_DATA_BASE+4, 1);

    IOWR_ALTERA_AVALON_PIO_DIRECTION(PIO_DATA_BASE+6, 1);

    IOWR_ALTERA_AVALON_PIO_DIRECTION(PIO_DATA_BASE+8, 1);

    IOWR_ALTERA_AVALON_PIO_DIRECTION(PIO_DATA_BASE+10, 1);

    IOWR_ALTERA_AVALON_PIO_DIRECTION(PIO_DATA_BASE+12, 1);

    IOWR_ALTERA_AVALON_PIO_DIRECTION(PIO_DATA_BASE+14, 1);

    data = IORD_ALTERA_AVALON_PIO_DATA(PIO_DATA_BASE);

    am I correct?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Wrong!

    You must write the same register but different bits

    bit 0 = I/O nr. 1

    bit 1 = I/O nr. 2

    ...

    bit 7 = I/O nr. 8

    For example:

    IOWR_ALTERA_AVALON_PIO_DIRECTION(PIO_DATA_BASE, 0x43);

    sets I/O 1,2 and 7 as outputs and all the others as inputs, since

    0x43 is binary 01000011

    The same applies for writing output values or reading inputs

    In Qsys you have the option "Enable individual bit set/clear output register"; if you selected it, you can set/clear a single output through outset/outclear registers, otherwise you must write all of them jointly.

    i.e. IOWR_ALTERA_AVALON_PIO_DATA(PIO_DATA_BASE, 0x42)

    sets an high level on lines 2 and 7 (clearly they must have been previously set as outputs)

    Reading is simpler: you call data = IORD_ALTERA_AVALON_PIO_DATA(PIO_DATA_BASE)

    and simply test the required bits of data.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thank you very much for reply,

    It is working.you really saved my life :).
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I have almost the same problem.

    I created a component in Qsys with 3 differently Conduits (sd_clk, sd_cmd and sd_dat) and for this component I have just one Base.

    How can I use the function IOWR_ALTERA_AVALON_PIO_DIRECTION(component_base, _____) to write output and input for each of the conduits?

    Does anyone have an idea?

    Thank a lot in advance!!!