// TI File $Revision: /main/3 $
// Checkin $Date: December 3, 2004 13:39:29 $
// Modified by LSD_Hanbing to suit the LSD_EVM320F2801X, April 24,2007
//###########################################################################
//
// FILE: Example_281xGpioToggle.c
//
// TITLE: DSP280x Device GPIO toggle test program.
//
// ASSUMPTIONS:
//
// This program requires the DSP280x header files.
//
// GPIO0-7 TOGGLE IN THIS PROGRAM. MAKE SURE
// THIS WILL NOT DAMAGE YOUR HARDWARE BEFORE RUNNING THIS
// EXAMPLE.
//
// Monitor GPIO0-7 on the LED2-LED9.
//
// As supplied, this project is configured for "boot to SARAM"
// operation. The 280x Boot Mode table is shown below.
// For information on configuring the boot mode of an LSD_EVM320F2801X,
// please refer to the documentation included with the LSD_EVM320F2801X,
//
// Boot GPIO18 GPIO29 GPIO34
// Mode SPICLKA SCITXDA
// SCITXB
// -------------------------------------
// Flash 1 1 1
// SCI-A 1 1 0
// SPI-A 1 0 1
// I2C-A 1 0 0
// ECAN-A 0 1 1
// SARAM 0 1 0 <- "boot to SARAM"
// OTP 0 0 1
// I/0 0 0 0
//
//
// DESCRIPTION:
//
// Three different examples are included. Select the example
// (data, set/clear or toggle) to execute before compiling using
// the #define statements found at the top of the code.
//
//
//###########################################################################
// $TI Release: DSP280x, DSP2801x Header Files V1.41 $
// $Release Date: August 7th, 2006 $
//###########################################################################
#include "DSP280x_Device.h" // DSP280x Headerfile Include File
#include "DSP280x_Examples.h" // DSP280x Examples Include File
#include"math.h"
// Select the example to compile in. Only one example should be set as 1
// the rest should be set as 0.
#define EXAMPLE1 0 // Use DATA registers to toggle I/O's
#define EXAMPLE2 0 // Use SET/CLEAR registers to toggle I/O's
#define EXAMPLE3 1 // Use TOGGLE registers to toggle I/O's
// Prototype statements for functions found within this file.
void delay_loop(void);
void Gpio_select(void);
void Gpio_example1(void);
#define PI 3.1415926
#define SAMPLENUMBER 128
void InitForFFT();
void MakeWave();
//void FFT(float dataR[SAMPLENUMBER],float dataI[SAMPLENUMBER]);
int INPUT[SAMPLENUMBER],DATA[SAMPLENUMBER];
//float fWaveR[SAMPLENUMBER],fWaveI[SAMPLENUMBER];
float w[SAMPLENUMBER];
float sin_tab[SAMPLENUMBER],cos_tab[SAMPLENUMBER];
void FFT(float dataR[SAMPLENUMBER],float dataI[SAMPLENUMBER])
{
int x0,x1,x2,x3,x4,x5,x6,xx;
int i,j,k,b,p,L;
float TR,TI,temp;
/********** following code invert sequence ************/
for ( i=0;i<SAMPLENUMBER;i++ )
{
x0=x1=x2=x3=x4=x5=x6=0;
x0=i&0x01; x1=(i/2)&0x01; x2=(i/4)&0x01; x3=(i/8)&0x01;x4=(i/16)&0x01; x5=(i/32)&0x01; x6=(i/64)&0x01;
xx=x0*64+x1*32+x2*16+x3*8+x4*4+x5*2+x6;
dataI[xx]=dataR[i];
}
for ( i=0;i<SAMPLENUMBER;i++ )
{
dataR[i]=dataI[i]; dataI[i]=0;
}
/************** following code FFT *******************/
for ( L=1;L<=7;L++ )
{ /* for(1) */
b=1; i=L-1;
while ( i>0 )
{
b=b*2; i--;
} /* b= 2^(L-1) */
for ( j=0;j<=b-1;j++ ) /* for (2) */
{
p=1; i=7-L;
while ( i>0 ) /* p=pow(2,7-L)*j; */
{
p=p*2; i--;
}
p=p*j;
for ( k=j;k<128;k=k+2*b ) /* for (3) */
{
TR=dataR[k]; TI=dataI[k]; temp=dataR[k+b];
dataR[k]=dataR[k]+dataR[k+b]*cos_tab[p]+dataI[k+b]*sin_tab[p];
dataI[k]=dataI[k]-dataR[k+b]*sin_tab[p]+dataI[k+b]*cos_tab[p];
dataR[k+b]=TR-dataR[k+b]*cos_tab[p]-dataI[k+b]*sin_tab[p];
dataI[k+b]=TI+temp*sin_tab[p]-dataI[k+b]*cos_tab[p];
} /* END for (3) */
} /* END for (2) */
} /* END for (1) */
for ( i=0;i<SAMPLENUMBER/2;i++ )
{
w[i]=sqrt(dataR[i]*dataR[i]+dataI[i]*dataI[i]);
}
} /* END FFT */
void InitForFFT()
{
int i;
for ( i=0;i<SAMPLENUMBER;i++ )
{
sin_tab[i]=sin(PI*2*i/SAMPLENUMBER);
cos_tab[i]=cos(PI*2*i/SAMPLENUMBER);
}
}
void MakeWave()
{
int i;
for ( i=0;i<SAMPLENUMBER;i++ )
{
INPUT[i]=sin(PI*2*i/SAMPLENUMBER*3)*1024;
}
}
void main(void)
{
int i;
float fWaveR[SAMPLENUMBER],fWaveI[SAMPLENUMBER];
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP280x_SysCtrl.c file.
InitSysCtrl();
// Step 2. Initalize GPIO:
// This example function is found in the DSP280x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
// InitGpio(); // Skipped for this example
// For this example use the following configuration:
Gpio_select();
// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
DINT;
// Initialize PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the DSP280x_PieCtrl.c file.
InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example. This is useful for debug purposes.
// The shell ISR routines are found in DSP280x_DefaultIsr.c.
// This function is found in DSP280x_PieVect.c.
InitPieVectTable();
// Step 4. Initialize all the Device Peripherals:
// This function is found in DSP280x_InitPeripherals.c
// InitPeripherals(); // Not required for this example
InitForFFT();
MakeWave();
for ( i=0;i<SAMPLENUMBER;i++ )
{
fWaveR[i]=INPUT[i];
fWaveI[i]=0.0f;
w[i]=0.0f;
}
FFT(fWaveR,fWaveI);
for ( i=0;i<SAMPLENUMBER;i++ )
{
DATA[i]=w[i];
}
for(;;)
{
} //break point
}
void Gpio_select(void)
{
EALLOW;
GpioCtrlRegs.GPAMUX1.all = 0x00000000; // All GPIO
GpioCtrlRegs.GPAMUX2.all = 0x00000000; // All GPIO
GpioCtrlRegs.GPAMUX1.all = 0x00000000; // All GPIO
GpioCtrlRegs.GPADIR.all = 0xFF; // GPIO0-7 outputs
EDIS;
}
//===========================================================================
// No more.
//===========================================================================