|
// // TMDX ALPHA RELEASE // Intended for product evaluation purposes // //########################################################################### // // FILE: Example_28xSpi_FFDLB.c // // TITLE: DSP28 Device Spi Digital Loop Back porgram. // All these tests will self validate the code and update the // Test status in Test_status array. // And PASS_Flag =0xDOBE for pass, 0xDEAD for fail // // Test 1 SPI 16-bit character, Internal loop back // In MASTER MODE Rising edge, baud rate =0x07f // // // // //########################################################################### // // Ver | dd mmm yyyy | Who | Description of changes // =====|=============|======|=============================================== // 0.56| 06 May 2002 | S.S. | EzDSP Alpha Release // 0.57| 27 May 2002 | L.H. | No change // 0.58| 03 July2002 | S.S. | SPI example //###########################################################################
#include "DSP28_Device.h" #include "DSP28_Globalprototypes.h"
// Prototype statements for functions found within this file. // interrupt void ISRTimer2(void); void delay_loop(void); void spi_dlb16(void); void spi_xmit(int a); void spi_fifo_init(void); void error(int); void program_stop(); unsigned int var1 = 0; unsigned int var2 = 0; unsigned int var3 = 0; unsigned int var4 = 0; unsigned int var5 = 0; unsigned int test_count = 0; unsigned int Test_flag1 = 0; unsigned int Test_flag2 = 0; unsigned int Test_flag3 = 0; unsigned int Test_flag4 = 0; unsigned int Test_var = 0; unsigned int Test_status[32]; unsigned int PASS_flag = 0;
void main(void) {
// Step 1. Initialize System Control registers, PLL, WatchDog, Clocks to default state: // This function is found in the DSP28_SysCtrl.c file. InitSysCtrl();
// Step 2. Select GPIO for the device or for the specific application: // This function is found in the DSP28_Gpio.c file. // InitGpio(); skip this as this is example selects the I/O for McBSP in this file itself EALLOW; GpioMuxRegs.GPFMUX.all=0x000F; // Select GPIOs to be SPI pins // Port F MUX - x000 0000 0000 1111 EDIS;
// Step 3. Initialize PIE vector table: // The PIE vector table is initialized with pointers to shell Interrupt // Service Routines (ISR). The shell routines are found in DSP28_DefaultIsr.c. // Insert user specific ISR code in the appropriate shell ISR routine in // the DSP28_DefaultIsr.c file.
// Disable and clear all CPU interrupts: DINT; IER = 0x0000; IFR = 0x0000;
// Initialize Pie Control Registers To Default State: // This function is found in the DSP28_PieCtrl.c file. InitPieCtrl();
// Initialize the PIE Vector Table To a Known State: // This function is found in DSP28_PieVect.c. // This function populates the PIE vector table with pointers // to the shell ISR functions found in DSP28_DefaultIsr.c. InitPieVectTable(); // Step 4. Initialize all the Device Peripherals to a known state: // This function is found in DSP28_InitPeripherals.c // InitPeripherals(); skip this for GPIO tests // Step 5. User specific functions, Reassign vectors (optional), Enable Interrupts:
spi_fifo_init(); // Initialize the Spi FIFO spi_dlb16(); // Digital loop back test
// Update Test status if(PASS_flag !=0) PASS_flag=0xDEAD; // Test code exit here.. else PASS_flag=0xD0BE; // Test code exit he // EALLOW; // This is needed to write to EALLOW protected registers // PieVectTable.TINT2 = &ISRTimer2; // EDIS; // This is needed to disable write to EALLOW protected registers
// Enable INT14 which is connected to CPU-Timer 2: // IER |= M_INT14;
// Enable global Interrupts and higher priority real-time debug events: // EINT; // Enable Global interrupt INTM // ERTM; // Enable Global realtime interrupt DBGM
// Step 6. IDLE loop. Just sit and loop forever (optional): asm(" ESTOP0"); // Break point for(;;);
}
// Step 7. Insert all local Interrupt Service Routines (ISRs) and functions here: // If local ISRs are used, reassign vector addresses in vector table as // shown in Step 5 /* // Interrupt function template interrupt void ISRTimer2(void) { } */
// Some Useful local functions void delay_loop() { long i; for (i = 0; i < 1000000; i++) {} }
void error(int ErrorFlag) { PASS_flag =0xDEAD; Test_status[ Test_var]= 0xDEAD; // asm(" ESTOP0"); // Test failed!! Stop! // for (;;);
}
// Test 1,SPI 16-bit character, Internal loop back // In MASTER MODE Rising edge, baud rate =0x07f void spi_dlb16() { SpiaRegs.SPICCR.all =0x000F; // Reset on, rising edge, 16-bit char bits SpiaRegs.SPICTL.all =0x0006; // Enable master mode, normal phase, // enable talk, and SPI int disabled. SpiaRegs.SPIBRR =0x007F;
// Bit changes to registers
// Release Reset for SPI SpiaRegs.SPICCR.all =0x009F; // Relinquish SPI from Reset // Bit 4 loop back mode enabled // Bit changes for the test var3 =0x4141; spi_xmit(var3); while(SpiaRegs.SPIFFRX.bit.RXFFST !=1) { } Test_flag4 = SpiaRegs.SPIRXBUF; if(Test_flag4 != 0x4141) error(1); Test_status[ Test_var]= 0x8000; // update Test_status test number Test_var++; }
void spi_xmit(int a) {
SpiaRegs.SPITXBUF =a;
}
void spi_fifo_init() { // Initialize SPI FIFO registers SpiaRegs.SPIFFTX.all=0xE040; SpiaRegs.SPIFFRX.all=0x204f; SpiaRegs.SPIFFCT.all=0x0; }
//=========================================================================== // No more. //===========================================================================
|