LabVIEW Embedded for ARM Porting Guide - Chapter 3: Implementing Elemental I/O Part 1/2
Overview
The 32-bit RISC ARM processor architecture developed by ARM Limited is widely used across many embedded designs due to its low price, low power consumption, and wide variety of peripherals for many of the major silicon vendors. Today, the ARM family accounts for more than 75 percent of all 32-bit RISC CPUs. You can use the NI LabVIEW Embedded Module for ARM Microcontrollers for programming ARM microcontrollers with the RTX embedded operating system.
This document offers a general outline for targeting LabVIEW code to any custom ARM target. It is the third document in a five-part series that demonstrates the steps you need to take to port LabVIEW code to the Phytec LPC3180 ARM9 microcontroller. For additional information, read these chapters:
Chapter 1: Introduction
Chapter 2: Integration of LabVIEW and Keil Toolchains
Chapter 4: Porting the RTX Real-Time Kernel
Chapter 5: Integrating the Real-Time Agent
Table of Contents
Implementing Elemental I/O - Part (1/2)
Elemental I/O is a flexible, user-defined way to access analog and digital I/O peripherals from LabVIEW on embedded ARM targets. Elemental I/O nodes are portable across many targets, so even if the underlying implementation of the driver changes among targets, you do not need to modify the LabVIEW application when migrating code to another processor. Therefore, use elemental I/O to create block diagrams that you can reuse on many platforms.
Elemental I/O Devices, Classes, Pins, and Resources
I/O Devices
An I/O device is the software representation of hardware that performs I/O on an ARM target. It is a collection of I/O resources, pins, and plug-in VIs that define the elemental I/O for a target. You can reuse an I/O device on multiple targets so several similar targets can share a single I/O device. For example, an LPC3180 ARM ROM target and an LPC3180 ARM RAM target might share a single I/O device.
Elemental I/O Classes
Elemental I/O supports the following I/O classes:
- Analog In
- Analog Out
- Digital In
- Digital Out
- Digital Bank In
- Digital Bank Out
- Pulse Width Modulation Out
You can implement some or all of the supported I/O classes for an I/O device. For the LPC3180, Digital In, Digital Out, Analog In, and Pulse Width Modulation Out are implemented.
Pins
A pin is the software equivalent of a physical pin that connects an I/O device to the outside world. Resources can share pins because, typically, there are fewer pins than resources. Pins are optional. Use pins if you have conflicting devices.
In the following chapters, learn how to implement elemental I/O nodes for Digital In, Digital Out, Analog In, and Pulse Width Modulation Out. None of these resources share a common pin; therefore, you will not use pins.
Resources
An elemental I/O resource is the software equivalent of a circuit in the hardware that performs I/O. Resources use pins to connect the circuits to the outside world. An I/O device can have many resources. Elemental I/O resources bind the pins to the I/O classes. For example, the hardware an elemental I/O device runs on might have eight general-purpose I/O pins that you can use for analog input, analog output, digital input, and digital output. You can bind a pin to a resource.
Elemental I/O Node
Users place elemental I/O nodes on the block diagram by dragging the node from the project palette to the block diagram. A target’s elemental I/O palette contains an Elemental I/O Node for each supported I/O class: analog input, analog output, digital input, digital output, digital bank input, digital bank output, and pulse-width modulation output. When you create an elemental I/O device, you define which of the I/O classes users can use. For example, an embedded target might support only digital input and digital output. If the target you are creating is not compatible with certain I/O classes, you can remove the elemental I/O nodes from the palette. In the screenshot below, an example project shows that there are four elemental I/O classes supported by the LPC3180.
When the Elemental I/O Node executes on the embedded target, it executes LabVIEW code that the elemental I/O device defines. The elemental I/O device has plug-in VIs for each type of I/O the device supports. These VIs replace the Elemental I/O Node when executing on the embedded target. Most of the plug-in VIs have a pin number as an input, and compute the I/O result using an Inline C Node that accesses the I/O registers.
Create Elemental I/O
You implement elemental I/O by providing a set of configuration files, plug-in VIs, and XML files. Use the Elemental I/O Device Editor to define the I/O classes, pins, and resources for a device. The Elemental I/O Device Editor also takes the configuration files and plug-in VIs and creates the necessary files for implementing elemental I/O.
I/O Implementation VI
The I/O Node Implementation VI is the only required plug-in VI to implement an I/O resource. You must have at least one I/O Node Implementation VI for each I/O resource you define using the Elemental I/O Wizard. If you have multiple I/O Node Implementation VIs, the I/O Specify Node VI determines which I/O Node Implementation VI to call. The I/O Node Implementation VI runs on the embedded target, so anything that is valid for the target is allowed in this VI.
Logically, the I/O Node Implementation VI behaves as if the Elemental I/O Node has been replaced with a call to this VI with constants wired for the attributes and properties. The elemental I/O framework passes the project attributes and the node attributes to the I/O Implementation VIs for the I/O item.
Property Node VI
If you want to support programmatically setting I/O properties, you must include an I/O Property Node Implementation VI for each property. The I/O Property Node Implementation plug-in VIs are substituted for the Elemental I/O Property Node wherever you place an Elemental I/O Property Node on the block diagram. These VIs can communicate with hardware, call device drivers, set global variables used by the I/O Implementation VI, and so on. These VIs run on the embedded target, so anything that is valid for the target is allowed in these VIs. The elemental I/O framework passes the I/O Property Node Implementation VI to the project attributes for the selected I/O item.
Specify Node VI
Use the I/O Specify Node VI if you want to have elemental I/O nodes whose type is determined at edit time, as opposed to when you define the I/O through the Elemental I/O Wizard.
If you have multiple I/O Node Implementation VIs, you must include an I/O Specify Node VI to determine which one to use. If you have an I/O Implementation VI for reading and an I/O Implementation VI for writing with different data types, you must include an I/O Specify Node VI. These VIs run at edit time on the host computer.
The VI returns the type of I/O node, which is either the return type for elemental I/O nodes configured to read or the input type for elemental I/O nodes configured to write. If you use this VI, you must include an I/O Node Implementation VI for each type returned.
Project and Node Attribute Validator
Use I/O Project Node Attribute Validation plug-in VIs to validate the attributes of the I/O item in the Project Explorer window and the elemental I/O nodes on the block diagram. These VIs run at edit time on the host computer.
Writing Elemental I/O Plug-In VIs for the LPC3180
Use the plug-in VIs to define the behavior of I/O operations. You must create the plug-in VIs before you run the Elemental I/O Device Wizard because the wizard uses information from these VIs. If you do not create the plug-in VIs before running the wizard, you receive an error when you try to generate the eio.xml file, which is the file that defines how the elemental I/O is implemented for your target. If you modify the plug-in VIs in any way, you must run the wizard again and restart LabVIEW to ensure that the information in the target matches the VIs.
The template VIs include all possible controls and indicators for the plug-in VIs. Copy the template VIs for the target, replace the Project Attributes and Node Attributes cluster controls with type definitions or strict type definitions, and remove controls that you do not need.
The Project Attributes cluster control appears on the I/O Node Project Panel page of the Elemental I/O Properties dialog box when a user right-clicks an I/O item in the Project Explorer window and selects Properties from the shortcut menu. The values you set in the I/O Node Project Panel page apply to all nodes that refer to this I/O item. The elemental I/O framework passes the project attributes to the I/O Implementation VIs and the I/O Property Node Implementation VIs for this I/O item.
The Node Attributes control appears on the I/O Node Panel page of the Elemental I/O Node Properties dialog box when a user right-clicks an Elemental I/O Node on the block diagram and selects Properties from the shortcut menu. The values set in the I/O Node Panel page apply to this particular Elemental I/O Node only. The elemental I/O framework passes the node attributes to the I/O Implementation VIs.
You can find examples of Implementation VIs in the following directory labview\examples\lvemb\EDM\EIO\EIOSimulationExample.
Note: All plug-in VIs use the standard 12-terminal connector pane. You must wire controls and indicators as specified by the connector pane of each template VI.
Prepare Template Files
- Browse to the LabVIEW\Targets\Keil\Embedded\RealView\LPC3180\eio directory.
- Create four new folders in this directory:
- EIO
- AI
- GPIO
- PWM
- Browse to the LabVIEW\examples\lvemb\EDM\EIO\EIO User Plugin Templates\ directory.
- Copy the following files to the LabVIEW\Targets\Keil\Embedded\RealView\LPC3180\EIO directory. They will be used as a template for creating the various plug-in VIs.
- NodeAttr.ctl
- PrjAttr.ctl
- NodeAttrValidator.vi
- PrjAttrValidator.vi
- EIOImplementation – Read Scalar.vi
- EIO Specify Node.vi
- Open LabVIEW and select Tools»Embedded»Target Editor.
- Select File»Open and browse to the LabVIEW\Targets\Keil\Embedded\RealView\LPC3180\ directory.
- Locate and open the TgtSupp.xml file.
- Right-click the LPC3180 icon and select Properties.
- Change the Path to Elemental I/O directory to eio\EIO and click OK.
- Select File»Save and exit the Target Editor.
- Exit LabVIEW completely and open LabVIEW again so that the targets are renumerated.
Digital Output
The LPC3180 features 24 dedicated general-purpose output pins. There are no configurable properties for digital output; therefore, you need only a single Implementation VI.
- Make a copy of the EIOImplementation – Read Scalar.vi to the LabVIEW\Targets\Keil\Embedded\RealView\LPC3180\EIO\GPIO directory and rename it LPC3180_Implementation_GPO.vi.
- Open LPC3180_Implementation_GPO.vi in LabVIEW.
- On the block diagram, delete all of the comments and the following controls and indicators:
- Project attributes
- Node attributes
- IO Name (original)
- IO Name (alias)
- On the front panel, right-click the Data indicator and replace it with a Boolean control. Do not delete the Data indicator and place a Boolean control, or the terminal placement will be incorrect.
- There should be two error terminals: a Boolean control and an I8 control on the block diagram.
- Recreate the code as shown below and save the file.
- Be sure to add the LPC3180.h header file to the Inline C Node by right-clicking the Inline C Node border and selecting Add or Remove Header Files….
- Click Add File and browse to the /Keil/ARM/Inc/Philips/ directory and select the LPC3180.h file. Click OK twice to return to the block diagram.
- The Implementation VI for digital output is now complete.
Note: Consult the hardware manual for your target to determine the register-level programming necessary to configure and access peripherals and the I/O hardware.
Digital Input
The LPC3180 features 12 dedicated general-purpose input pins. There are no configurable properties for digital input; therefore, you need only a single Implementation VI.
- Make a copy of the LPC3180_Implementation_GPO.vi to the LabVIEW\Targets\Keil\Embedded\RealView\LPC3180\EIO\GPIO directory and rename it LPC3180_Implementation_GPI.vi.
- Open LPC3180_Implementation_GPI.vi in LabVIEW.
- On the block diagram, change the Boolean Data control to an indicator, and recreate the code as shown below.
Digital Input/Output
The LPC3180 features six dedicated general-purpose input/output pins. There are no configurable properties for digital input/output; therefore, you need two Implementation VIs, one for input and one for output.
- Make a copy of the LPC3180_Implementation_GPO.vi to the LabVIEW\Targets\Keil\Embedded\RealView\LPC3180\EIO\GPIO directory and rename it LPC3180_Implementation_GPIO_Write.vi.
- Open LPC3180_Implementation_GPIO_Write.vi in LabVIEW.
- On the block diagram, modify the Inline C Node code and the input values for the In Range and Coerce.vi as shown and save and close the VI.
- Make a copy of the LPC3180_Implementation_GPI.vi to the LabVIEW\Targets\Keil\Embedded\RealView\LPC3180\EIO\GPIO directory and rename it LPC3180_Implementation_GPIO_Read.vi.
- Open LPC3180_Implementation_GPIO_Read.vi in LabVIEW.
- On the block diagram, modify the Inline C Node code and the input values for the In Range and Coerce.vi as shown and save and close the VI.
Analog Input
The LPC3180 features three analog input pins. Users should be able to select whether they need the output of the read to be a raw binary value or a scaled value; therefore, you need two Implementation VIs, a single Specify Node, and a Node Attribute control.
- Browse to the LabVIEW\Targets\Keil\Embedded\RealView\LPC3180\EIO\ directory and make a copy of the NodeAttr.ctl to the LabVIEW\Targets\Keil\Embedded\RealView\LPC3180\EIO\AI directory.
- Rename the NodeAttr.ctl to LPC3180_AI_NodeAttr.ctl.
- Open LPC3180_AI_NodeAttr.ctl in LabVIEW.
- On the front panel, replace the numeric control with an enum with two entries:
- Raw binary
- Scaled voltage
- Save and close LPC3180_AI_NodeAttr.ctl.
- Make a copy of the EIOImplementation – Read Scalar.vi to the LabVIEW\Targets\Keil\Embedded\RealView\LPC3180\EIO\AI directory and rename it LPC3180_Implementation_AI_Scaled.vi.
- Open LPC3180_Implementation_AI_Scaled.vi in LabVIEW.
- On the block diagram, delete all of the comments and the following controls and indicators:
- Project attributes
- IO Name (original)
- IO Name (alias)
- Rename the IO Channel Number Control AI(1-3).
- Rename the Data indicator ADCValue and change its representation to Double.
- On the front panel, right-click the Node Attributes control and replace it with LPC3180_AI_NodeAttr.ctl. Do not delete the control and place LPC3180_AI_NodeAttr.ctl, or you will lose the terminal placement.
- There should be two error terminals, a Double indicator, an I8 control, and a Node Attributes control on the block diagram.
- Recreate the code as shown below and save the file. Be sure to add the LPC3180.h header file to the Inline C Node.
- Make a copy of the LPC3180_Implementation_AI_Scaled.vi to the LabVIEW\Targets\Keil\Embedded\RealView\LPC3180\EIO\AI directory and rename it LPC3180_Implementation_AI_Raw.vi.
- Open LPC3180_Implementation_AI_Raw.vi in LabVIEW.
- Change the representation of ADCValue to U32 and modify the block diagram as shown so that no scaling is done to ADCVal.
- Save and close LPC3180_Implementation_AI_Raw.
- Browse to the LabVIEW 8.5\Targets\NI\Embedded\eio\simulatedIOPlugins directory and make a copy of the IOImpl1 Specify Node.vi to the LabVIEW\Targets\Keil\Embedded\RealView\LPC3180\EIO\AI directory.
- Rename IOImpl1 Specify Node.vi as LPC3180 AI Specify Node.vi.
- On the front panel, right-click the Node Attributes control and replace it with LPC3180_AI_NodeAttr.ctl.
- Modify the block diagram as shown.
- Save and close LPC3180 AI Specify Node.vi.
Pulse-Width Modulation
The LPC3180 features two pulse-width modulation outputs. The user should be able to select the output frequency from a project property node; therefore, you need one Implementation VI, a single Project Attribute Validator, and a Project Attribute control.
- Browse to the LabVIEW\Targets\Keil\Embedded\RealView\LPC3180\EIO\ directory and make a copy of the PrjAttr.ctl to the LabVIEW\Targets\Keil\Embedded\RealView\LPC3180\EIO\PWM directory.
- Open PrjAttr.ctl in LabVIEW.
- On the front panel, delete all controls except for the Rate numeric control, and modify the front panel as shown below.
- Save and close PrjAttr.ctl.
- Make a copy of the EIOImplementation – Read Scalar.vi to the LabVIEW\Targets\Keil\Embedded\RealView\LPC3180\EIO\AI directory and rename it LPC3180_Implementation_PWM.vi.
- Open LPC3180_Implementation_PWM.vi in LabVIEW.
- On the block diagram, delete all of the comments and the following controls and indicators:
- Node attributes
- IO Name (original)
- IO Name (alias)
- Rename the IO Channel Number Control as PWMNum (1-2).
- Rename the Data indicator to Duty Cycle(0-100), change it to a control, and change its representation to U32.
- On the front panel, right-click the Attributes control and replace it with the PrjAttr.ctl that you created in the previous step. Do not delete the control and place PrjAttr.ctl, or you will lose the terminal placement.
- There should be two error terminals, a U32 control, an I8 control, and an Attributes control on the block diagram.
- Recreate the code as shown below and save the file. Be sure to add the LPC3180.h header file to the Inline C Node.
- PrjAttrValidator.vi to the LabVIEW\Targets\Keil\Embedded\RealView\LPC3180\EIO\PWM directory.
- Open PrjAttrValidator.vi in LabVIEW.
- On the front panel, right-click the Attributes control and replace it with PrjAttr.ctl in the LabVIEW\Targets\Keil\Embedded\RealView\LPC3180\EIO\PWM directory.
- Modify the block diagram as shown.
- Save and close PrjAttrValidator.vi.
Implementing Elemental I/O - Part (2/2)
Continue on to Chapter 3 : Implementing Elemental I/O - Part (2/2) to learn how to create Elemental I/O and verify proper operation.
Reader Comments | Submit a comment »
Legal
This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).
