NET OS Appkit Rio

From Digi Developer

Jump to: navigation, search


Contents

Program for controlling the Rabbit RIO chip in NET+OS

Appkit RIO Test (For NET+OS 7.4.2 - 7.5.2 modules) A driver for controlling the Rabbit RIO chip.


Test Files

This sample program contains eight files. The main function is in root.c.


CPU Test Sample Application

The Appkit Rio Driver Test sample application can be found here: Media:RIO Appkit Driver.zip


Basic Usage

Test Hardware setup on RIO APPKIT board:
--With an LED (or Scope). Connect ground (neg) to P4.9(GND). Connect VCC(pos) 
	to P4.8(RC0P0). This LED is where the majority of all the tests will be
	performed
--With a STDP(single throw, double poll) switch. Connect the common pin to 
	P4.4(RC1P0). Connect one poll to VCC and the other poll to GND. This pin
	will be used for all the input tests.
BSP SETUP
 
Digi Connect ME 9210
Change the following in gpio.h:
#define BSP_GPIO_MUX_SERIAL_A                       BSP_GPIO_MUX_SERIAL_2_WIRE_UART
#define BSP_GPIO_MUX_IRQ_1                          BSP_GPIO_MUX_USE_PRIMARY_PATH
#define BSP_GPIO_MUX_IRQ_1_CONFIG					BSP_GPIO_MUX_IRQ_FALLING_EDGE
 
Right Click on your project. Go to properties. Select Net+OS from the list.
Under bsp_sys.h change 'Dialog Port' and 'STDIO Port' to 'Serial Port C'
 
 
ConnectCore 9P 9215
Change the following in gpio.h:
#define BSP_GPIO_MUX_IRQ_3                          BSP_GPIO_MUX_USE_3RD_ALTERNATE_PATH
#define BSP_GPIO_MUX_IRQ_3_CONFIG					BSP_GPIO_MUX_IRQ_FALLING_EDGE

Known Issues

The Input/Output pins on the RIO APPKIT board are all floating. This means that
any pin not pulled up or down and set for an input will report random state
changes due to cross talk and other interference.

Sample of root.c file:

#include <stdio.h>
#include <stdlib.h>
#include <tx_api.h>
#include "appconf.h"
 
#include "rio_appkit.h"
 
 
void applicationTcpDown (void)
{
	static int ticksPassed = 0;
	ticksPassed++;
}
 
void TestGPIO();
void TestPWM();
void TestGPIOInput();
void TestHardwareReset();
void TestSoftReset();
void TestPPM();
void TestInterrupt();
 
void applicationStart (void)
{
#if (PROCESSOR == ns9215)
	/* 
	 * ConnectCore 9P9215 Connections
	 * GPIO67 = X21.C9 - Reset Line
	 * GPIO101(IRQ3) = X21.D16 - Interrupt Line (IRQ3)
	 */
	naRIOInit(5,67,EXTERNAL3_INTERRUPT);
#elif (PROCESSOR == ns9210)
	/*
	 * Connect ME 9210 Setup
	 * GPIO13 = P3.20 - Reset Line
	 * GPIO2 = P3.12 - Interrupt Line (IRQ1)
	 */
	naRIOInit(5,13,EXTERNAL1_INTERRUPT);
#endif
 
	printf("Starting RIO Test\n");
 
	TestHardwareReset();
	TestSoftReset();
	TestGPIO();
	TestPWM();
	TestGPIOInput();
	TestPPM();
	TestInterrupt();
 
    tx_thread_suspend(tx_thread_identify());
}
 
void TestGPIO()
{
	int port,pin;
	int x;
	int retval;
 
	printf ("Starting GPIO Test...\n");
	for (x=0; x < 20; x++)
	{	
		for (port=0; port<8; port++)
			for (pin=0;pin<4; pin++)
				retval = naRIOSetOutput(port, pin, TRUE);
 
		printf("All are high\n");
		tx_thread_sleep(10);
 
		for (port=0; port<8; port++)
			for (pin=0;pin<4; pin++)
				retval = naRIOSetOutput(port, pin, FALSE);
 
		printf("All are low\n");
		tx_thread_sleep(10);
	}
	printf ("GPIO Test complete...\n");
}
 
void TestPWM()
{
	int retval;
	int x,i;
	/*	
	 * 16666666 = 60hz
	 *  20000000 = 50hz
	 *  10000000 = 100hz
	 */
	long period = 10000000;
 
	printf ("Starting PWM Test.\n");	
	retval = naRIOReset(TRUE);
	retval = naRIOSetPrescaler(period);
 
	retval = naRIOSetPWM(0,0,period,0);
	for (i = 0; i < 10; i++)
	{
		for (x = 1; x <= 100; x++)
		{
			retval = naRIOUpdatePWM(0,0, period * x/100.0);
			tx_thread_sleep(1);
		}
		for (x = 100; x >=1 ; x--)
		{
			retval = naRIOUpdatePWM(0,0, period * x/100.0);
			tx_thread_sleep(1);
		}
	}
	printf("PWM Test Complete...\n");
}
 
void TestHardwareReset()
{
	int retval;
	BYTE port, pin;
 
	printf("Start Hardware Reset Test. All Pins...\n");
 
	for (port=0; port<8; port++)
		for (pin=0;pin<4; pin++)
			retval = naRIOSetOutput(port, pin, TRUE);
 
	printf("All pins should be high for 5 seconds. Then the RIO should reset.\n");
	tx_thread_sleep(500);
	retval = naRIOReset(TRUE);
	printf("RIO has been reset!\n");
	printf("Hardware Reset Test complete...\n");
	tx_thread_sleep(500);	
}
 
void TestSoftReset()
{
	int retval;
	BYTE port, pin;
 
	printf("Start Software Reset Test. All Pins...\n");
 
	for (port=0; port<8; port++)
		for (pin=0;pin<4; pin++)
			retval = naRIOSetOutput(port, pin, TRUE);
 
	printf("All pins should be high for 5 seconds. Then the RIO should reset.\n");
	tx_thread_sleep(500);
	retval = naRIOReset(FALSE);
	printf("RIO has been reset!\n");
	printf("Software Reset Test Compelte...\n");
	tx_thread_sleep(500);	
}
 
void TestGPIOInput()
{
	BOOL val = FALSE;
	BOOL last = FALSE;
	int retval;
	int x;
 
	retval = naRIOReset(TRUE);	
 
	printf("Starting GPIO Input Test Port 1, Pin 0...\n");
 
	retval = naRIOSetInput(1,0);
	for (x=0; x<20; x++)
	{
		// wait for a state change
		while ( retval == last)
			val = naRIOReadInput(1,0);
 
		printf("Pin is now %d\n", retval);
		last = retval;
	}
 
	printf("GPIO Input Test Complete...\n");
}
 
void TestPPM()
{
	int retval;
	long period = 10000000;
	int x,i;
 
	naRIOReset(TRUE);
 
	printf("Starting PPM Test. Port 0, Pin 0...\n");
	retval = naRIOSetPrescaler(period);
 
	/* set pins 2,3 on port0 to a PWM */
	retval = naRIOSetPWM(0,2,period,period/3);
	retval = naRIOSetPWM(0,3,period,period/3);
 
	/* set pin0 to a PPM with a phase shift */
	retval = naRIOSetPPM(0,0,period,0,period/3);
 
	/* 
	 * set pin1 (the dead pin) to a GPIO.
	 * pin1's match register is being used, 
	 * so it can only be used for GPIO
	 */
	retval = naRIOSetOutput(0,1,FALSE);
 
	for (i = 0; i < 10; i++)
	{
		for (x = 1; x <= 360; x++)
		{
			retval = naRIOUpdatePPM(0,0, x/2, x*(period/720));
			tx_thread_sleep(1);
		}
		for (x = 360; x >=1 ; x--)
		{
			retval = naRIOUpdatePPM(0,0, x/2, x*(period/720));
			tx_thread_sleep(1);
		}
	}
 
	printf("PPM Test Complete...\n");
}
 
void InterruptCallBack(int port, int pin)
{
	int retval;
	printf("Callback called on port: %d, pin: %d\n", port, pin);
	retval = naRIOResetGPIOInterrupt(1,0);
}
 
void TestInterrupt()
{
	int retval;
	printf("Starting Interrupt Test. Port 1, Pin 0...\n");
	retval = naRIOReset(TRUE);
	retval = naRIOGPIOInterrupt(1,0, InterruptCallBack);
}
Personal tools
Wiki Editing