// TI File $Revision: /main/1 $
// Checkin $Date: January 15, 2008 10:49:54 $
//###########################################################################
//
// FILE: Example_2823xSpi_FFDLB.c
//
// TITLE: DSP2823x Device Spi Digital Loop Back program.
//
// ASSUMPTIONS:
//
// This program requires the DSP2823x header files.
//
// This program uses the internal loop back test mode of the peripheral.
// Other then boot mode pin configuration, no other hardware configuration
// is required.
//
// As supplied, this project is configured for "boot to SARAM"
// operation. The 2823x Boot Mode table is shown below.
// For information on configuring the boot mode of an eZdsp,
// please refer to the documentation included with the eZdsp,
//
// $Boot_Table:
//
// GPIO87 GPIO86 GPIO85 GPIO84
// XA15 XA14 XA13 XA12
// PU PU PU PU
// ==========================================
// 1 1 1 1 Jump to Flash
// 1 1 1 0 SCI-A boot
// 1 1 0 1 SPI-A boot
// 1 1 0 0 I2C-A boot
// 1 0 1 1 eCAN-A boot
// 1 0 1 0 McBSP-A boot
// 1 0 0 1 Jump to XINTF x16
// 1 0 0 0 Jump to XINTF x32
// 0 1 1 1 Jump to OTP
// 0 1 1 0 Parallel GPIO I/O boot
// 0 1 0 1 Parallel XINTF boot
// 0 1 0 0 Jump to SARAM <- "boot to SARAM"
// 0 0 1 1 Branch to check boot mode
// 0 0 1 0 Boot to flash, bypass ADC cal
// 0 0 0 1 Boot to SARAM, bypass ADC cal
// 0 0 0 0 Boot to SCI-A, bypass ADC cal
// Boot_Table_End$
//
// DESCRIPTION:
//
// This program is a SPI example that uses the internal loopback of
// the peripheral. Interrupts are not used.
//
// A stream of data is sent and then compared to the recieved stream.
//
// The sent data looks like this:
// 0000 0001 0002 0003 0004 0005 0006 0007 .... FFFE FFFF
//
// This pattern is repeated forever.
//
// Watch Variables:
// sdata - sent data
// rdata - received data
//
////###########################################################################
// Original Author: S.S.
//
// $TI Release: DSP2833x Header Files V1.10 $
// $Release Date: February 15, 2008 $
//###########################################################################
#include "DSP2833x_Device.h" // DSP2823x Headerfile Include File
#include "DSP2833x_examples.h" // DSP2823x Examples Include File
//////////////////////////////////////
#define LED1_OFF GpioDataRegs.GPBSET.bit.GPIO60 = 1 //LED D10 点亮
#define LED1_ON GpioDataRegs.GPBCLEAR.bit.GPIO60 = 1 //LED D10 熄灭
#define LED2_OFF GpioDataRegs.GPBSET.bit.GPIO61 = 1 //LED D11 点亮
#define LED2_ON GpioDataRegs.GPBCLEAR.bit.GPIO61 = 1 //LED D11 熄灭
#define LED3_OFF GpioDataRegs.GPASET.bit.GPIO2 = 1 //LED D12 点亮
#define LED3_ON GpioDataRegs.GPACLEAR.bit.GPIO2 = 1 //LED D12 熄灭
#define LED4_OFF GpioDataRegs.GPASET.bit.GPIO3 = 1 //LED D13 点亮
#define LED4_ON GpioDataRegs.GPACLEAR.bit.GPIO3 = 1 //LED D13 熄灭
#define LED5_OFF GpioDataRegs.GPASET.bit.GPIO4 = 1 //LED D14 点亮
#define LED5_ON GpioDataRegs.GPACLEAR.bit.GPIO4 = 1 //LED D14 熄灭
#define LED6_OFF GpioDataRegs.GPASET.bit.GPIO5 = 1 //LED D15 点亮
#define LED6_ON GpioDataRegs.GPACLEAR.bit.GPIO5 = 1 //LED D15 熄灭
#define LED7_OFF GpioDataRegs.GPASET.bit.GPIO6 = 1 //LED D16 点亮
#define LED7_ON GpioDataRegs.GPACLEAR.bit.GPIO6 = 1 //LED D16 熄灭
#define LED8_OFF GpioDataRegs.GPASET.bit.GPIO7 = 1 //LED D17 点亮
#define LED8_ON GpioDataRegs.GPACLEAR.bit.GPIO7 = 1 //LED D17 熄灭
#define DELAY_TIME 2000000
void delay(Uint32 t);
void delay(Uint32 t)
{
Uint32 i = 0;
for (i = 0; i < t; i++);
}
//void delay(unsigned int);
//void ldelay(unsigned int);
///////////////////////////////////////
// Prototype statements for functions found within this file.
// interrupt void ISRTimer2(void);
Uint32 state=0;
Uint32 keylow=0;
Uint32 keyhigh=0;
Uint32 keyout=0;
//////////////////////////////////////
void a(void);
void b(void);
//////////////////////////////////////
void a(void)
{
EALLOW;
GpioCtrlRegs.GPAMUX1.bit.GPIO12 = 0; // GPIO
GpioCtrlRegs.GPADIR.bit.GPIO12 = 0; // input
EDIS;
//Uint32 H2L_F1=0;
//Uint32 H2L_F2=0;
//Uint32 H2L_sig=0;
if(GpioDataRegs.GPADAT.bit.GPIO12==0)
{for(keylow=0;keylow<2000000;keylow++);
keyout=0;
}
if(GpioDataRegs.GPADAT.bit.GPIO12==1)
{for(keyhigh=0;keyhigh<2000000;keyhigh++);
keyout=1;
}
/* H2L_F1 = keyout;
H2L_F2 = H2L_F1;
H2L_sig =!H2L_F1 & H2L_F2;
if ( H2L_sig==0 )
state=1;
else
state =0;*/
}
void b(void)
{
if(keyout==0)
while(1)
{
LED1_ON;
if(keyout==0)
break;
}
}
//////////////////////////////////////////////////
void main(void)
{
// Uint16 sdata; // send data
// Uint16 rdata; // received data
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP2833x_SysCtrl.c file.
InitSysCtrl();
// Step 2. Initalize GPIO:
// This example function is found in the DSP2833x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
// InitGpio(); // Skipped for this example
// Setup only the GP I/O only for SPI-A functionality
// This function is found in DSP2833x_Spi.c
// InitXintf();
// InitSpiaGpio();
// 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 DSP2833x_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 DSP2833x_DefaultIsr.c.
// This function is found in DSP2833x_PieVect.c.
InitPieVectTable();
// Configure GPIO60 and GPIO61 as a GPIO output pin
EALLOW;
GpioCtrlRegs.GPAMUX1.bit.GPIO4 = 0;
GpioCtrlRegs.GPADIR.bit.GPIO4 = 1;
GpioCtrlRegs.GPAMUX1.bit.GPIO5 = 0;
GpioCtrlRegs.GPADIR.bit.GPIO5 = 1;
GpioCtrlRegs.GPAMUX1.bit.GPIO6 = 0;
GpioCtrlRegs.GPADIR.bit.GPIO6 = 1;
GpioCtrlRegs.GPAMUX1.bit.GPIO7 = 0;
GpioCtrlRegs.GPADIR.bit.GPIO7 = 1;
EDIS;
// Configure GPIO58 and GPIO59 as a GPIO input pin
EALLOW;
GpioCtrlRegs.GPAMUX1.bit.GPIO12 = 0; // GPIO
GpioCtrlRegs.GPADIR.bit.GPIO12 = 0; // input
GpioCtrlRegs.GPAMUX1.bit.GPIO13 = 0; // GPIO
GpioCtrlRegs.GPADIR.bit.GPIO13 = 0; // input
GpioCtrlRegs.GPAMUX1.bit.GPIO14 = 0; // GPIO
GpioCtrlRegs.GPADIR.bit.GPIO14 = 0; // input
GpioCtrlRegs.GPAMUX1.bit.GPIO15 = 0; // GPIO
GpioCtrlRegs.GPADIR.bit.GPIO15 = 0; // input
EDIS;
////////////////////////////////////////////