Acromag, Inc. 30765 S.Wixom Road P.O. Box 437 Wixom, Michigan 48393-7037 Phone: (248)295-0310 FAX: (248)624-9234 VxWorks Software Library Information File for the IP470/IP440 Boards V3.0 10/01/01 The information in this manual is subject to change without notice. Acromag, Inc. makes no warranty of any kind with regard to this material and accompanying software, including, but not limited to , the implied warranties of merchantability and fitness for a particular purpose. Acromag, Inc. assumes no responsibility for any errors that may appear in this manual and accompanying software. Copyright 1998-2006, Acromag, Inc. Tornado, VxWorks, and the wind kernel are trademarks or registered trademarks of, and developed by Wind River Systems, Inc., Alameda, California, U.S.A. 1. Overview This "information" file contains a description of the library programs used for the following models of Acromag Industrial I/O Boards: IP470 Digital I/O Board IP440 Isolated Digital Input Board (32 isolated inputs only) same functionality as IP470 inputs and uses the IP470 "C" library. 2. Introduction The software for the IP470/IP440 board is implemented as a library of "C" functions. This will make it possible to utilize the board by simply linking the user's code with the provided library and making function calls for each "command" to be accomplished. Most of the function calls will require a few parameters or the address of a parameter block to be passed. The parameters will include the board address, configuration information, data storage addresses, and status information. These functions accomplish the following tasks: - Configuration - Read Status and ID - Read Input - Write Output - Interrupts Also included is a demonstration program which shows how the library routines are used. It is also a helpful program to use when first installing the board, checking it out, and learning how it works. 3. List of Files The library software for each Acromag I/O board is in a correspondingly named subdirectory on the supplied media. The files which make up the library for the IP470/IP440 board are stored in the subdirectory named "IP470". There are two types of program files provided. Library program files are the files which make up the "library". Support program files contain example programs which show how to use the library. 1 3.1 Library Program Files The following files are included on the supplied media and make up the actual "library" software. ip470.h - include file. cnfg470.c - configure. rsts470.c - read status and ID. rpnt470.c - read an input point. rprt470.c - read an input port. wpnt470.c - write an output point. wprt470.c - write an output port. isr470.c - interrupt service routine 3.2 Support Program Files The following files are included on the supplied media. The test program demonstrates how the library programs may be used. drvr470.c - test program to demonstrate library programs. carrier.h - generic include file for carrier support. carrier.c - generic source - carrier support see infoCarrier.txt. bsp - source file that provides specific board support. 4. Software Installation It is strongly advised that the user make a backup copy of the distribution media and that the original media be stored in a safe place. The software is installed by simply copying the library files to the user's work directory and compiling and linking with the user's application program. 5. Hardware Installation For proper installation of each Acromag I/O board the user should refer to the appropriate user's manual. 6. Usage of the Library and Support Programs The software is installed by copying the supplied files to your work directory and compiling and linking with your application program. It is recommended that the user read the User's Manual for the board and thoroughly familiarize themselves with the hardware. For a new user to become familiar with the Acromag Library it may be most "straight forward" to proceed in the following manner: (a) Become familiar with VxWorks Programmer's Guide and Tornado User's Guide. Of interest is the Chapter "Shell". (b) Build and execute the Acromag Library Demonstration as a task by following the steps outlined in the "Shell" section of the VxWorks Tornado Users Guide. 2 i) Copy the Acromag Library routines from the "Ip470" directory of the source media to a new directory under .\target\src\ip470 for VxWorks 5.5 or .\workspace\src\bsp for VxWorks 6.x. Edit the include file Ip470.h. Include or exclude ( by commenting in or out ) the definition of "BIG_ENDIAN" depending on the target architecture. ii) Copy the carrier support routines from the "carriers" directory of the source media to a new directory under .\target\src\carriers for VxWorks 5.5 or .\workspace\src\carriers for VxWorks 6.x. Selecting carrier support is accomplished by copying the specific carrier's source files to the generic names "carrier.c" and "carrier.h" in the carriers subdirectory. iii) Copy the board support files from the "bsp" directory of the source media to a new directory under .\target\src\bsp for VxWorks 5.5 or .\workspace\src\bsp for VxWorks 6.x. iv) Open a new project workspace. Select 'Create downloadable application modules for VxWorks'. Change project name to 'Ip470', change the project location name to 'Ip470' and change the workspace name to 'Ip470'. Select a toolchain that corresponds to the target under development. Next, from the Project dropdown select 'Add/Include' then 'File'. Use the navigation controls to locate the Ip470 library directory. Highlight and add all of the Ip470 'C' source files to the project. Next, from the Project dropdown select 'Add/Include' then 'File'. Use the navigation controls to locate the carriers directory. Highlight and add the generic "carrier.c" 'C' source file to the project. Now, from the Project dropdown select 'Add/Include' then 'File'. Use the navigation controls to locate the bsp directory. Highlight and add one board support 'C' source file to the project. To add files to a VxWorks 6.x project use 'File->Import->File system' then browse to the file location. Also generate a 'include search path' like '$(WIND_HOME)/workspace/src/carriers' to the location of the 'carrier.h' include file. v) From the Build dropdown select 'Build All'. vi) From the 'Files' tab of the Project workspace right click and select Download Ip470.out. vii) Launch the VxWorks shell, use the lkup "drvr470" command to locate the entry point of the demonstration program on the target. viii) Use the sp 0xZZZZ command ( where ZZZZ is the entry point) to spawn the Acromag Demonstration program. ix) The Acromag Demonstration program menu should appear on the target processor's console terminal. 3 The following menu is displayed: IP470 Library Demonstration Version A 1. Exit this Program 2. Set Carrier Base Address 3. Set IP Module Base Address 4. Set Up Configuration Parameters 5. Configure Board Command 6. Read Status Command and ID 7. Attach Exception Handler 8. Detach Exception Handler 9. Read Input Point 10. Read Input Port 11. Write Output Point 12. Write Output Port Select: To perform digital I/O, follow this sequence of menu selections: Select 2: To set the Carrier base address. Select 3: To set the IP Slot Letter. Select 6: To read the board's status and ID. Select 9 or 10: To read input. Select 11 or 12: To write output To use the example interrupt routines provided, follow this sequence of main menu selections: Select 2: To set the Carrier base address. Select 3: To set the IP Slot Letter. Select 7: To attach the interrupt exception handler. Select 4: To set up Configuration through the Configuration Parameter Menu. This Menu will allow the user to set the board up for interrupts. Following are typical values for the Configuration parameters when using the example routines: Configuration Parameters Board Pointer: FFFF0100 (use your own) Parameter Mask: FF Enhanced Mode Flag: 01 Write Mask: 00 Event Control: 00 00 Debounce Clock: 01 Debounce Control: 00 Debounce Duration: 00 00 Reset/Int. Enable: 03 Interrupt Vector: b0 Select 5: To configure the board using the information in the Configuration Block. Select 6: To read the board's status information. Select 9, or 10: To read port data. Select 11, or 12: To write port data. 4 The interrupt service routine writes the interrupting channel information to variable 'event_status[5]' as an indication that the interrupt has been serviced. To view the interrupting channel information select the "Read Status" command from the main demonstration menu. If the interrupt vector is changed the user must attach the exception handler again. 6.1 Explanation of Main Demonstration Menu Following is an explanation of each menu selection: 1. Exit this Program This selection causes execution to be returned to the shell. 2. Set Carrier Base Address This selection allows the user to set address of the carrier board being used. 3. Set IP Slot Letter This selection allows the user to set or change the slot letter of the IP module being used. The value entered here will automatically be entered in the Configuration and Status Block structures. 4. Set Up Configuration Parameters This selection will cause the Configuration Parameter Menu to be displayed. Through that menu it will be possible to enter values into the various structure members of the Configuration structure. See section 6.2 for details on the Configuration Parameter Menu which follows. 5. Configure Board Command This menu selection will call the cnfg470() function and pass a pointer which points to the Configuration structure. Information in the Configuration is written to the board. 6. Read Status & ID Command This menu selection will call the rsts470() function and pass a pointer which points to the Configuration structure. The current status information is read from the board and written into this structure by the rsts470() function. The status information is then displayed by the example program. 5 7. Attach Exception Handler This menu selection allows the user to attach the interrupt exception handler for use with the demonstration program. The exception vector used is specified in the Configuration structure. Please see the descriptions in this document of the interrupt handler routines and the extensive comments in the source code of the routines. 8. Detach Exception Handler This menu selection is not implemented at this time and is not generally needed. 9. Read Input Point This command is used to read a single input point. The user enters the port number (0 thru 5) and point number (0 to 7). The rpnt470() function is called, then the result is displayed. 10. Read Input Port This command is used to read a port. The user enters the port number (0 thru 5). The rprt470() function is called, then the result is displayed. 11. Write Output Point This command is used to write a single output point. The user enters the port number (0 thru 5), the point number (0 to 7), and the value to write (0 or 1), then the wpnt470() function is called. 12. Write Output Port This command is used to write a port of 8 points. The user enters the port number (0 thru 5). The user is prompted to enter the value to write (0 to FF hex), then wprt470() function is called. 6.2 Explanation of the Configuration Menu This menu is displayed when the user selects the "Set Up Configuration" menu item from the Main Demonstration Menu. Through the Configuration Parameter Menu it will be possible for the user to enter values into the Configuration structure. The Configuration structure is used by the cnfg470() function. Following is the "Set Up Configuration Parameters" menu. All numbers are displayed and entered in hexadecimal. 6 Configuration Parameters 1. Return to Previous Menu 2. Board Pointer: FFFF0100 3. Parameter Mask: 00 4. Enhanced Mode Flag: 00 5. Write Mask: 00 6. Event Control: 00 00 7. Debounce Clock: 01 8. Debounce Control: 00 9. Debounce Duration: 00 00 10. Reset/Int. Enable: 00 11. Interrupt Vector: b0 Select: (Note that the values in the menu will differ depending on your system.) Following is an explanation of each menu selection: 1. Return to Previous Menu This selection returns the user to the Main Demonstration Menu. 2. Board Pointer The board base address is displayed, however, the base address can only be changed through the Main Demonstration Menu. This parameter is automatically updated in the Configuration structure when the user selects the "Set Board Base Address" item in the Main Demonstration Menu. 3. Parameter Mask This selection allows the user to enter a value for the Parameter Mask. The Parameter Mask is used by the cnfg470() function to determine which parameters to update in various registers of the board. The individual bits correspond to various parameters in the Configuration structure. A "1" in the bit position means to use the respective parameter field to update a register on the board. A "0" means not to use the parameter field. bit 0 - Enhanced Mode Parameter. bit 1 - Write Mask Register Parameter. bit 2 - Event Control Register Parameter. bit 3 - Debounce Clock Register Parameter. bit 4 - Debounce Control Register Parameter. bit 5 - Debounce Duration Register Parameter. bit 6 - Reset/Interrupt Enable Register Parameter. bit 7 - Interrupt Vector Register Parameter. 7 4. Enhanced Flag This selection allows the user to enter a value for the Enhanced Flag. A "1" in bit position 0 selects the Enhanced Mode of operation. A "0" in bit position 0 causes the cnfg470() function to skip the procedure that configures the device for enhanced mode. 5. Write Mask This selection allows the user to enter a value for the Write Mask Register. This register is used to mask the ability to write data to the six output ports. A "1" in any bit position will mask writes to the output port. A "0" in any bit position will unmask (allow) writes to the port. 6. Event Control This selection allows the user to enter values for the Event Control Registers. Event Control Registers select the polarity of the input sense event in nibbles for each of the input ports. A value of "0" in a bit position selects events on high to low transitions for four bits of a port. A value of "1" in a bit position selects events on low to high transitions for four bits of a port. Note: The IP440 board's isolating input stage inverts the input signal presented to the digital ASIC chip. This requires that the event control polarities be inverted to flag transitions correctly. 7. Debounce Clock This selection allows the user to enter a value for the Debounce Clock Register. If bit 0 of this register is 0, then the debounce clock is taken from I/O47 (pin 41 of P2). If bit 0 of this register is 1, then the 8MHz IP bus clock is used (recommended). 8. Debounce Control This selection allows the user to enter a value for the Debounce Control Register. A value of "1" in a bit position enables debounced operation for all bits of a port. A value of "0" in a bit position disables the debounce logic for all bits of a port. 9. Debounce Duration This selection allows the user to enter values for the Debounce Duration Registers. Two bits are used to select one of four debounce values for each port. A debounce value of 00 selects 3-4us, 01 selects 48-64us, 10 selects 0.75-1ms and 11 selects 6-8 ms. 8 10. Reset/Interrupt Enable This selection allows the user to enter a value for the Reset/Interrupt Enable Register. Writing a "1" to bit position 1 causes a reset of the digital I/O ASIC chip. Writing A "1" to bit position 0 will allow interrupts to be generated by the IP470 board. A "0" in bit position 0 disables interrupts for the entire IP470 board. 11. Interrupt Vector This selection allows the user to enter a value for the interrupt exception vector. 7. Description of Library Programs. Following are descriptions of the programs and files which make up the library. ip470.h - This module contains the definitions and structures used by the library. cnfg470.c - This module is used to perform the "Configure Board" function for the IP470 board. A pointer to the Configuration Block is passed to this routine. The routine will use a pointer within the Configuration Block to reference the registers on the board. Based on flag bits in the Parameter Mask word in the Configuration Block, the board will be configured and various registers will be updated with new information which will be transferred from the Configuration Block structure. calling sequence: cnfg470(ptr); where: ptr - (structure pointer) This is a pointer to the Configuration Block structure. rsts470.c - This module is used to perform the "Read Status and ID" function for the IP470 board. A pointer to the Status Block is passed to this routine. The routine uses a pointer within the Status Block to reference registers on the board and transfers information from the board to the Status Block. calling sequence: rsts470(ptr); where: ptr - (structure pointer) This is a pointer to the Status Block structure. 9 rpnt470.c - This module is used to perform the "Read Input Point" function for the IP470 board. A pointer to the board configuration structure, the port number and the point number are passed to this routine. This information is used to read the point value from the board. calling sequence: status = rpnt470(c_blk,port,point); where: status - (long) Returned value of the input point. c_blk - (structure pointer) Pointer to the board configuration structure. port - (byte) Target input port number. point - (byte) Target input point number. rprt470.c - This module is used to perform the "Read Input Port" function for the IP470 board. A pointer to the board configuration structure and port number (0 or 1) are passed to this routine. This information is used to read the input port data value from the board. calling sequence: status = rprt470(c_blk,port); where: status - (long) Returned value of the input port. c_blk - (structure pointer) Pointer to the board configuration structure. port - (byte) Target input port number. wpnt470.c - This module is used to perform the "Write Output Point" function for the IP470 board. A pointer to the board configuration structure, the port number, the point number and point value to write are passed to this routine. calling sequence: status = wpnt470(c_blk,port,point,value); where: status - (long) Returned error status of the function. c_blk - (structure pointer) Pointer to the board configuration structure. port - (byte) Target input port number. point - (byte) Target input point number. value - (byte) Value to write to output point. 10 wprt470.c - This module is used to perform the "Write Output Port" function for the IP470 board. A pointer to the board configuration structure, the port number and port value to write are passed to this routine. calling sequence: status = wprt470(c_blk,port,value); where: status - (long) Returned error status of the function. c_blk - (structure pointer) Pointer to the board configuration structure. port - (byte) Target input port number. value - (byte) Value to write to output port. isr470() - This function is used to perform interrupt handling. This routine must be attached to the appropriate interrupt exception vector before trying to use this interrupt. See the supplied example program "drvr470.c" and "isr470.c" for an explanation of attaching this routine to an interrupt vector. calling sequence: This module is not called directly. The included routines are attached to interrupt exception vectors and are used to service interrupts. 8. Description of Support Programs Following is a description of the support files and program modules which provide examples for the use of the library programs. bsp - Source files in the board support directory provide an interface to specific VxWorks board support package. carrier.c - This file provides carrier support routines. Selecting carrier support is accomplished by copying the specific carrier's source files to the generic names "carrier.c" and "carrier.h" in the carriers subdirectory. drvr470.c - This is a program which demonstrates the usage of the library modules. This program is menu driven and allows the user to become familiar with the IP470 board and the library software. The user may, through menu selections, configure, read from and write to the board. 11