samples: boards: add sample for Altera Nios-II PIO core

Add a sample application for Nios-II PIO core on Altera MAX10 board.

Signed-off-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
This commit is contained in:
Ramakrishna Pallala 2017-12-19 11:48:00 +05:30 committed by Andrew Boie
commit b82dfb479b
6 changed files with 129 additions and 0 deletions

View file

@ -0,0 +1,10 @@
.. _altera_max10_devkit-samples:
Altera MAX10 Development Kit Samples
#####################################
.. toctree::
:maxdepth: 1
:glob:
**/*

View file

@ -0,0 +1,4 @@
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(NONE)
target_sources(app PRIVATE src/main.c)

View file

@ -0,0 +1,39 @@
.. _altera_max10_pio-sample:
Altera Nios-II PIO sample
###############################
Overview
********
This sample application demonstrates the usage of Nios-II
Parallel Input/Output (PIO) soft IP by controlling the LEDs
on an Altera MAX10 board.
Requirements
************
This application uses an Altera MAX10 development board for the demo.
Building
********
.. zephyr-app-commands::
:zephyr-app: samples/boards/altera_max10/pio
:board: altera_max10
:goals: build
:compact:
Sample Output
=============
nios2 core output
-----------------
.. code-block:: console
Turning off all LEDs
Turn On LED[0]
Turn On LED[1]
Turn On LED[2]
Turn On LED[3]
Turning on all LEDs

View file

@ -0,0 +1,4 @@
CONFIG_GPIO=y
CONFIG_GPIO_ALTERA_NIOS2=y
CONFIG_GPIO_ALTERA_NIOS2_OUTPUT=y
CONFIG_GPIO_ALTERA_NIOS2_OUTPUT_DEV_NAME="PIO_OUTPUT"

View file

@ -0,0 +1,9 @@
sample:
description: Sample application to verify the Nios-II based
PIO soft IP block.
name: Nios-II Parallel Input/Output (PIO)
tests:
test:
build_only: true
platform_whitelist: altera_max10
tags: samples pio

View file

@ -0,0 +1,63 @@
/*
* Copyright (c) 2017 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr.h>
#include <device.h>
#include <gpio.h>
#include <misc/printk.h>
#include <misc/util.h>
/* GPIO driver name */
#define GPIO_DRV_NAME CONFIG_GPIO_ALTERA_NIOS2_OUTPUT_DEV_NAME
/* PIO pins[0:3] are wired to LED's */
#define LED_PINS_WIRED 4
#define LED_PIN_MASK 0xf
void main(void)
{
struct device *gpio_dev;
int i, ret;
gpio_dev = device_get_binding(GPIO_DRV_NAME);
if (!gpio_dev) {
printk("Cannot find %s!\n", GPIO_DRV_NAME);
return;
}
/* Setup GPIO output */
ret = gpio_port_configure(gpio_dev, GPIO_DIR_OUT);
if (ret) {
printk("Error configuring GPIO PORT\n");
}
/*
* Note: the LED's are connected in inverse logic
* to the Nios-II PIO core.
*/
printk("Turning off all LEDs\n");
ret = gpio_port_write(gpio_dev, LED_PIN_MASK);
if (ret) {
printk("Error set GPIO port\n");
}
k_sleep(MSEC_PER_SEC * 5);
for (i = 0; i < LED_PINS_WIRED; i++) {
printk("Turn On LED[%d]\n", i);
ret = gpio_port_write(gpio_dev, LED_PIN_MASK & ~(1 << i));
if (ret) {
printk("Error in seting GPIO port\n");
}
k_sleep(MSEC_PER_SEC * 5);
}
printk("Turning on all LEDs\n");
ret = gpio_port_write(gpio_dev, 0x0);
if (ret) {
printk("Error set GPIO port\n");
}
}