Forum Discussion

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

defining Qsys input on DE0

Hi, I'm new to embedded processor development and a novice in C and C++ programming.

I'm working on design for a senior project, and am currently using a DE0 development board with quartus 11.0 and nios ii 11.0.

After setting up my system, I am trying to figure out how to reference a GPIO input I created with Qsys in my source code. I'm doing a# include<system.h> which is the header file nios created from my sopc that defines the input. I don't know what to define the input as so my source code recognizes it, or if it is more complicated then that. Any advice, or references to a tutorial or document which describes this process would be greatly appreciated. Below is the code in system.h# define ALT_MODULE_CLASS_input_pio altera_avalon_pio# define INPUT_PIO_BASE 0x11030# define INPUT_PIO_BIT_CLEARING_EDGE_REGISTER 0# define INPUT_PIO_BIT_MODIFYING_OUTPUT_REGISTER 0# define INPUT_PIO_CAPTURE 0# define INPUT_PIO_DATA_WIDTH 4# define INPUT_PIO_DO_TEST_BENCH_WIRING 1# define INPUT_PIO_DRIVEN_SIM_VALUE 0x0# define INPUT_PIO_EDGE_TYPE "NONE"# define INPUT_PIO_FREQ 50000000u# define INPUT_PIO_HAS_IN 1# define INPUT_PIO_HAS_OUT 0# define INPUT_PIO_HAS_TRI 0# define INPUT_PIO_IRQ -1# define INPUT_PIO_IRQ_INTERRUPT_CONTROLLER_ID -1# define INPUT_PIO_IRQ_TYPE "NONE"# define INPUT_PIO_NAME "/dev/input_pio"# define INPUT_PIO_RESET_VALUE 0x0# define INPUT_PIO_SPAN 16# define INPUT_PIO_TYPE "altera_avalon_pio"

I'm using the nios II application and BSP from template, THANKS!

4 Replies

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

    try this code.

    when you run the code, press button / switch.

    each return value on PIOi represent condition of button / switch.

    try it anyway.

    //--------------------------------------------------------------------------------

    # include <stdio.h>

    # include "system.h"

    # include <io.h>

    int main()

    {

    unsigned char PIOi;

    PIOi = IORD_8DIRECT(LED_BASE,0);

    printf("NiosII's got 0x%02X\n",PIOi);

    return 0;

    }

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

    Thanks for your reply, can you elaborate a little on how this program works?

    I'm running as nios ii hardware and the program does not respond to the switch or button states, it always returns NIOSII's got 0x00. I tried looking at the io.h file but it wasn't much help.

    I'm wondering how PIOi = IORD_8DIRECT(LED_BASE,0); works, and if I should set my Qsys system to correspond to the program.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I see from the system.h file that PIOi appears to my my input bus, I'll keep playing with it thanks