This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How, in a c program, do I change the data direction in a bi-directional PIO peripheral register ?

Hi,

I am working with a Terasic DE0-Nano-SoC board, and am working in DS-5 Community Edition 17.1.

I have created some PIO peripheral registers in Qsys / Platform Designer, connected to some well tested firmware, containing registers;

This data register PIO is bidirectional :

PIO with I/O Data

So  in a c program, how do I change the data  transfer direction ?

I appear to be able to write from an output only PIO, but so far only read from this bi-directional PIO.

Works when reading a read only register in my firmware :

SkelData_read = *(uint32_t *)h2p_lw_pio_d_addr;

Writing then reading a R/W register in my firmware always returns 0 :

*(uint32_t *)h2p_lw_pio_d_addr = Data;

SkelData_read = *(uint32_t *)h2p_lw_pio_d_addr;

Help appreciate,

Beau

Parents
  • OK, I have found information that has helped, but I still have problems outputting data.

    Below is the crucial code, I am hoping someone can see where I am going wrong.
    Is it the address calculation for the Data Direction register ?

    This is for the Data register (which works for the output only PIOs) :
    h2p_lw_pio_d_addr=virtual_base + ( ( unsigned long )( ALT_LWFPGASLVS_OFST + PIO_D_BASE ) & ( unsigned long)( HW_REGS_MASK ) );

    Is this right for the Data Direction register ?
    h2p_lw_pio_d_dirn = virtual_base + ( ( unsigned long )( ALT_LWFPGASLVS_OFST + PIO_D_BASE + 1 ) & ( unsigned long)( HW_REGS_MASK ) );

    PIO Registers

    I am setting this as :
    Write :
    Set Data (8 bit) : 
    Data = strtol(argv[4], &strptr, 10); // Data to write
    *(uint32_t *)h2p_lw_pio_d_addr = Data;
    Output it :
    *(uint32_t *)h2p_lw_pio_d_dirn = 0xff ; // All PIO Data bits set to output (write)


    Set Input :
    *(uint32_t *)h2p_lw_pio_d_dirn = 0x00 ; // All PIO Data bits set to input (read)
    Read Data :
    SkelData_read = *(uint32_t *)h2p_lw_pio_d_addr;

    Thanks,
    Beau Webber

Reply
  • OK, I have found information that has helped, but I still have problems outputting data.

    Below is the crucial code, I am hoping someone can see where I am going wrong.
    Is it the address calculation for the Data Direction register ?

    This is for the Data register (which works for the output only PIOs) :
    h2p_lw_pio_d_addr=virtual_base + ( ( unsigned long )( ALT_LWFPGASLVS_OFST + PIO_D_BASE ) & ( unsigned long)( HW_REGS_MASK ) );

    Is this right for the Data Direction register ?
    h2p_lw_pio_d_dirn = virtual_base + ( ( unsigned long )( ALT_LWFPGASLVS_OFST + PIO_D_BASE + 1 ) & ( unsigned long)( HW_REGS_MASK ) );

    PIO Registers

    I am setting this as :
    Write :
    Set Data (8 bit) : 
    Data = strtol(argv[4], &strptr, 10); // Data to write
    *(uint32_t *)h2p_lw_pio_d_addr = Data;
    Output it :
    *(uint32_t *)h2p_lw_pio_d_dirn = 0xff ; // All PIO Data bits set to output (write)


    Set Input :
    *(uint32_t *)h2p_lw_pio_d_dirn = 0x00 ; // All PIO Data bits set to input (read)
    Read Data :
    SkelData_read = *(uint32_t *)h2p_lw_pio_d_addr;

    Thanks,
    Beau Webber

Children