PIO Program Example

Download: pio.zip

This example is designed to run on the nios2lab1 system.

The input port is mapped as follows:

wire [31:0] inport, outport;
assign inport[20:18] = KEY[3:1];
assign inport[17:0] = SW;
assign inport[31:21] = 0;

The output port is mapped to the 7-segment displays, with leading-zero blanking.

main.c


/* 
 * PIO Example
 *
 *    - Use ALT versions of stdio routines:
 *
 *           Function                  Description
 *        ===============  =====================================
 *        alt_printf       Only supports %s, %x, and %c ( < 1 Kbyte)
 *        alt_putstr       Smaller overhead than puts with direct drivers
 *                         Note this function doesn't add a newline.
 *        alt_putchar      Smaller overhead than putchar with direct drivers
 *        alt_getchar      Smaller overhead than getchar with direct drivers
 *
 */

main program

#include <stdio.h>
#include "system.h"
#include "altera_avalon_pio_regs.h"


void test1(), test2();

int main()
{ 
  printf("starting program ...\n");

  test2();
  
  printf("ending program\n");

  return 0;
}

test1

void test1()
{
    printf("writing to PIO\n");
    int data = 42;
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_BASE,data);
}

test2

void test2()
{
    int inp, key3_up, n;
    key3_up = 1;
    printf("press KEY3 to input a number\n");
    while (key3_up) {
        inp = IORD_ALTERA_AVALON_PIO_DATA(PIO_BASE);
        key3_up = (inp>>20)&1;
    }
    n = inp & 0x3ffff;
    printf("input: %d (hex %x)\n",n,n);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_BASE,n);
}    
        


Maintained by John Loomis, updated Tue Jan 15 21:11:53 2008