Text Compare
Produced: 2/14/2020 4:06:10 PM
   
Mode:  All  
Left file: C:\ti\c2000\C2000Ware_2_00_00_03\device_support\f2837xd\examples\cpu1\sci_loopback\cpu01\Example_2837xDScia_FFDLB.c  
Right file: C:\Customer.txt  

//###########################################################################

=

//###########################################################################

//

 

//

// FILE:    Example_2837xDScia_FFDLB.c

 

// FILE:    Example_2837xDScia_FFDLB.c

//

 

//

// TITLE:   SCI FIFO Digital Loop Back Test.

 

// TITLE:   SCI FIFO Digital Loop Back Test.

//

 

//

//! \addtogroup cpu01_example_list

 

//! \addtogroup cpu01_example_list

//! <h1>SCI FIFO Digital Loop Back Test (sci_looback)</h1>

 

//! <h1>SCI FIFO Digital Loop Back Test (sci_looback)</h1>

//!

 

//!

//!  This program uses the internal loop back test mode of the peripheral.

 

//!  This program uses the internal loop back test mode of the peripheral.

//!  Other then boot mode pin configuration, no other hardware configuration

 

//!  Other then boot mode pin configuration, no other hardware configuration

//!  is required.

 

//!  is required.

//!

 

//!

//!  This test uses the loopback test mode of the SCI module to send

 

//!  This test uses the loopback test mode of the SCI module to send

//!  characters starting with 0x00 through 0xFF.  The test will send

 

//!  characters starting with 0x00 through 0xFF.  The test will send

//!  a character and then check the receive buffer for a correct match.

 

//!  a character and then check the receive buffer for a correct match.

//!

 

//!

//!  \b Watch \b Variables \n

 

//!  \b Watch \b Variables \n

//!  - \b LoopCount - Number of characters sent

 

//!  - \b LoopCount - Number of characters sent

//!  - \b ErrorCount - Number of errors detected

 

//!  - \b ErrorCount - Number of errors detected

//!  - \b SendChar - Character sent

 

//!  - \b SendChar - Character sent

//!  - \b ReceivedChar - Character received

 

//!  - \b ReceivedChar - Character received

//!

 

//!

//

 

//

//###########################################################################

 

//###########################################################################

// $TI Release: F2837xD Support Library v3.07.00.00 $

<> 

// $TI Release: F2837xD Support Library v3.06.00.00 $

// $Release Date: Sun Sep 29 07:34:54 CDT 2019 $

 

// $Release Date: Mon May 27 06:48:24 CDT 2019 $

// $Copyright:

=

// $Copyright:

// Copyright (C) 2013-2019 Texas Instruments Incorporated - http://www.ti.com/

 

// Copyright (C) 2013-2019 Texas Instruments Incorporated - http://www.ti.com/

//

 

//

// Redistribution and use in source and binary forms, with or without 

<> 

// Redistribution and use in source and binary forms, with or without

// modification, are permitted provided that the following conditions 

 

// modification, are permitted provided that the following conditions

// are met:

=

// are met:

// 

<> 

//

//   Redistributions of source code must retain the above copyright 

 

//   Redistributions of source code must retain the above copyright

//   notice, this list of conditions and the following disclaimer.

=

//   notice, this list of conditions and the following disclaimer.

// 

<> 

//

//   Redistributions in binary form must reproduce the above copyright

=

//   Redistributions in binary form must reproduce the above copyright

//   notice, this list of conditions and the following disclaimer in the 

<> 

//   notice, this list of conditions and the following disclaimer in the

//   documentation and/or other materials provided with the   

 

//   documentation and/or other materials provided with the

//   distribution.

=

//   distribution.

// 

<> 

//

//   Neither the name of Texas Instruments Incorporated nor the names of

=

//   Neither the name of Texas Instruments Incorporated nor the names of

//   its contributors may be used to endorse or promote products derived

 

//   its contributors may be used to endorse or promote products derived

//   from this software without specific prior written permission.

 

//   from this software without specific prior written permission.

// 

<> 

//

// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 

 

// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS

// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 

 

// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT

// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR

=

// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR

// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 

<> 

// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT

// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 

 

// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,

// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 

 

// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT

// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,

=

// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,

// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY

 

// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY

// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 

<> 

// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT

// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 

 

// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE

// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

=

// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

// $

 

// $

//###########################################################################

 

//###########################################################################

 

+-

 

//

=

//

// Included Files

 

// Included Files

//

 

//

#include "F28x_Project.h"

 

#include "F28x_Project.h"

 

+-

 

//

=

//

 

-+

    #define CPU_FREQ        200E6

 

 

    #define LSPCLK_FREQ     CPU_FREQ/2

 

 

    #define SCI_FREQ        2603

 

 

    #define SCI_PRD         ((LSPCLK_FREQ/(SCI_FREQ*8))-1)

// Globals

=

// Globals

//

 

//

Uint16 LoopCount;

 

Uint16 LoopCount;

Uint16 ErrorCount;

 

Uint16 ErrorCount;

 

+-

 

//

=

//

// Function Prototypes

 

// Function Prototypes

//

 

//

void scia_loopback_init(void);

 

void scia_loopback_init(void);

void scia_fifo_init(void);

 

void scia_fifo_init(void);

void scia_xmit(int a);

 

void scia_xmit(int a);

void error();

 

void error();

 

+-

 

//

=

//

// Main

 

// Main

//

 

//

void main(void)

 

void main(void)

{

 

{

    Uint16 SendChar;

 

    Uint16 SendChar;

    Uint16 ReceivedChar;

<> 

 //   Uint16 ReceivedChar;

 

 

    EALLOW;

 

 

      ClkCfgRegs.LOSPCP.bit.LSPCLKDIV =0x0001 ;

 

 

    EDIS;

//

=

//

// Step 1. Initialize System Control registers, PLL, WatchDog, Clocks to

 

// Step 1. Initialize System Control registers, PLL, WatchDog, Clocks to

// default state:

 

// default state:

// This function is found in the F2837xD_SysCtrl.c file.

 

// This function is found in the F2837xD_SysCtrl.c file.

//

 

//

    InitSysCtrl();

 

    InitSysCtrl();

 

+-

 

//

=

//

// Step 2. Initialize GPIO:

 

// Step 2. Initialize GPIO:

// This example function is found in the F2837xD_Gpio.c file and

 

// This example function is found in the F2837xD_Gpio.c file and

// illustrates how to set the GPIO to it's default state.

 

// illustrates how to set the GPIO to it's default state.

//

 

//

   InitGpio();

 

   InitGpio();

 

+-

 

//

=

//

// For this example, only init the pins for the SCI-A port.

 

// For this example, only init the pins for the SCI-A port.

//  GPIO_SetupPinMux() - Sets the GPxMUX1/2 and GPyMUX1/2 register bits

 

//  GPIO_SetupPinMux() - Sets the GPxMUX1/2 and GPyMUX1/2 register bits

//  GPIO_SetupPinOptions() - Sets the direction and configuration of the GPIOS

 

//  GPIO_SetupPinOptions() - Sets the direction and configuration of the GPIOS

// These functions are found in the F2837xD_Gpio.c file.

 

// These functions are found in the F2837xD_Gpio.c file.

//

 

//

   GPIO_SetupPinMux(28, GPIO_MUX_CPU1, 1);

<> 

   //GPIO_SetupPinMux(28, GPIO_MUX_CPU1, 1);

   GPIO_SetupPinOptions(28, GPIO_INPUT, GPIO_PUSHPULL);

 

  // GPIO_SetupPinOptions(28, GPIO_INPUT, GPIO_PUSHPULL);

   GPIO_SetupPinMux(29, GPIO_MUX_CPU1, 1);

=

   GPIO_SetupPinMux(29, GPIO_MUX_CPU1, 1);

   GPIO_SetupPinOptions(29, GPIO_OUTPUT, GPIO_ASYNC);

 

   GPIO_SetupPinOptions(29, GPIO_OUTPUT, GPIO_ASYNC);

 

+-

 

//

=

//

// Step 3. Initialize PIE vector table:

 

// Step 3. Initialize PIE vector table:

// The PIE vector table is initialized with pointers to shell Interrupt

 

// The PIE vector table is initialized with pointers to shell Interrupt

// Service Routines (ISR).  The shell routines are found in F2837xD_DefaultIsr.c.

 

// Service Routines (ISR).  The shell routines are found in F2837xD_DefaultIsr.c.

// Insert user specific ISR code in the appropriate shell ISR routine in

 

// Insert user specific ISR code in the appropriate shell ISR routine in

// the F2837xD_DefaultIsr.c file.

 

// the F2837xD_DefaultIsr.c file.

//

 

//

 

+-

 

//

=

//

// Disable and clear all CPU __interrupts:

 

// Disable and clear all CPU __interrupts:

//

 

//

    DINT;

 

    DINT;

    IER = 0x0000;

 

    IER = 0x0000;

    IFR = 0x0000;

 

    IFR = 0x0000;

 

 

 

//

 

//

// Initialize Pie Control Registers To Default State:

 

// Initialize Pie Control Registers To Default State:

// This function is found in the F2837xD_PieCtrl.c file.

 

// This function is found in the F2837xD_PieCtrl.c file.

//

 

//

// InitPieCtrl();  //PIE is not used for this example

 

// InitPieCtrl();  //PIE is not used for this example

 

 

 

//

 

//

// Initialize the PIE Vector Table To a Known State:

 

// Initialize the PIE Vector Table To a Known State:

// This function is found in F2837xD_PieVect.c.

 

// This function is found in F2837xD_PieVect.c.

// This function populates the PIE vector table with pointers

 

// This function populates the PIE vector table with pointers

// to the shell ISR functions found in F2837xD_DefaultIsr.c.

 

// to the shell ISR functions found in F2837xD_DefaultIsr.c.

//

 

//

    InitPieVectTable();

 

    InitPieVectTable();

 

 

 

//

 

//

// Enable CPU and PIE __interrupts

 

// Enable CPU and PIE __interrupts

// This example function is found in the F2837xD_PieCtrl.c file.

 

// This example function is found in the F2837xD_PieCtrl.c file.

//

 

//

    EnableInterrupts();

 

    EnableInterrupts();

 

 

 

//

 

//

// Step 4. User specific functions, Reassign vectors (optional),

 

// Step 4. User specific functions, Reassign vectors (optional),

// Enable Interrupts:

 

// Enable Interrupts:

//

 

//

    LoopCount = 0;

 

    LoopCount = 0;

    ErrorCount = 0;

 

    ErrorCount = 0;

 

 

 

    scia_fifo_init();       // Initialize the SCI FIFO

 

    scia_fifo_init();       // Initialize the SCI FIFO

    scia_loopback_init();  // Initialize SCI for digital loop back

 

    scia_loopback_init();  // Initialize SCI for digital loop back

 

 

 

    //

 

    //

    // Note: Autobaud lock is not required for this example

 

    // Note: Autobaud lock is not required for this example

    //

 

    //

 

 

 

//

 

//

// Send a character starting with 0

 

// Send a character starting with 0

//

 

//

    SendChar = 0;

 

    SendChar = 0;

 

 

 

//

 

//

// Step 5. Send Characters forever starting with 0x00 and going through

 

// Step 5. Send Characters forever starting with 0x00 and going through

// 0xFF.  After sending each, check the receive buffer for the correct value

 

// 0xFF.  After sending each, check the receive buffer for the correct value

//

 

//

 

-+

  //  Uint16 i=0;

    for(;;)

=

    for(;;)

    {

<> 

    {//  SendChar=!SendChar;

 

 

      // DELAY_US(100000);

       scia_xmit(SendChar);

=

       scia_xmit(SendChar);

 

-+

      // break;

 

 

       }

 

=

 

       //

 

       //

       // wait for RRDY/RXFFST =1 for 1 data available in FIFO

 

       // wait for RRDY/RXFFST =1 for 1 data available in FIFO

       //

 

       //

       while(SciaRegs.SCIFFRX.bit.RXFFST == 0) { }

<> 

     //  while(SciaRegs.SCIFFRX.bit.RXFFST == 0) { }

 

 

 

       //

=

       //

       // Check received character

 

       // Check received character

       //

 

       //

       ReceivedChar = SciaRegs.SCIRXBUF.all;

<> 

      /* ReceivedChar = SciaRegs.SCIRXBUF.all;

       if(ReceivedChar != SendChar)

 

       if(ReceivedChar != SendChar)

       {

 

       {

           error();

 

           error();

       }

 

       }

 

=

 

       //

<> 

       //

       // Move to the next character and repeat the test

 

       // Move to the next character and repeat the test

       //

 

       //

       SendChar++;

 

       SendChar++;

 

=

 

       //

<> 

       //

       // Limit the character to 8-bits

 

       // Limit the character to 8-bits

       //

 

       //

       SendChar &= 0x00FF;

 

       SendChar &= 0x00FF;

       LoopCount++;

 

       LoopCount++;

    }

 

    }*/

}

=

}

 

 

 

//

 

//

// error - Function to count errors

 

// error - Function to count errors

//

 

//

void error()

<> 

/*void error()

{

 

{

    ErrorCount++;

 

    ErrorCount++;

//   asm("     ESTOP0");  // Uncomment to stop the test here

=

//   asm("     ESTOP0");  // Uncomment to stop the test here

//   for (;;);

 

//   for (;;);

}

<> 

}*/

 

=

 

//

 

//

// scia_loopback_init - Configure SCIA settings

 

// scia_loopback_init - Configure SCIA settings

//

 

//

void scia_loopback_init()

 

void scia_loopback_init()

{

 

{

    //

 

    //

    // Note: Clocks were turned on to the SCIA peripheral

 

    // Note: Clocks were turned on to the SCIA peripheral

    // in the InitSysCtrl() function

 

    // in the InitSysCtrl() function

    //

 

    //

 

-+

    /////////////////////

 

=

 

 

-+

 

    SciaRegs.SCICCR.all = 0x0007;  // 1 stop bit,  No loopback

=

    SciaRegs.SCICCR.all = 0x0007;  // 1 stop bit,  No loopback

                                   // No parity,8 char bits,

 

                                   // No parity,8 char bits,

                                   // async mode, idle-line protocol

 

                                   // async mode, idle-line protocol

    SciaRegs.SCICTL1.all = 0x0003; // enable TX, RX, internal SCICLK,

 

    SciaRegs.SCICTL1.all = 0x0003; // enable TX, RX, internal SCICLK,

                                   // Disable RX ERR, SLEEP, TXWAKE

 

                                   // Disable RX ERR, SLEEP, TXWAKE

    SciaRegs.SCICTL2.all = 0x0003;

 

    SciaRegs.SCICTL2.all = 0x0003;

    SciaRegs.SCICTL2.bit.TXINTENA = 1;

 

    SciaRegs.SCICTL2.bit.TXINTENA = 1;

    SciaRegs.SCICTL2.bit.RXBKINTENA = 1;

 

    SciaRegs.SCICTL2.bit.RXBKINTENA = 1;

    SciaRegs.SCIHBAUD.all = 0x0000;

<> 

    //SciaRegs.SCIHBAUD.all = 0x002B;

    SciaRegs.SCILBAUD.all = 0x000F;

 

    //SciaRegs.SCILBAUD.all = 0x000A;

 

 

    SciaRegs.SCIHBAUD.all = ((uint16_t)SCI_PRD  & 0xFF00U) >> 8U;

 

 

    SciaRegs.SCILBAUD.all = (uint16_t)SCI_PRD  & 0x00FFU;

    SciaRegs.SCICCR.bit.LOOPBKENA = 1; // Enable loop back

 

    SciaRegs.SCICCR.bit.LOOPBKENA = 0; // Enable loop back

    SciaRegs.SCICTL1.all = 0x0023;     // Relinquish SCI from Reset

=

    SciaRegs.SCICTL1.all = 0x0023;     // Relinquish SCI from Reset

}

<> 

 }

 

=

 

//

 

//

// scia_xmit - Transmit a character from the SCI

 

// scia_xmit - Transmit a character from the SCI

//

 

//

void scia_xmit(int a)

 

void scia_xmit(int a)

{

 

{

    SciaRegs.SCITXBUF.all=a;

 

    SciaRegs.SCITXBUF.all=a;

}

 

}

 

 

 

//

 

//

// scia_fifo_init - Initialize the SCI FIFO

 

// scia_fifo_init - Initialize the SCI FIFO

//

 

//

void scia_fifo_init()

 

void scia_fifo_init()

{

 

{

    SciaRegs.SCIFFTX.all = 0xE040;

 

    SciaRegs.SCIFFTX.all = 0xE040;

    SciaRegs.SCIFFRX.all = 0x2044;

 

    SciaRegs.SCIFFRX.all = 0x2044;

    SciaRegs.SCIFFCT.all = 0x0;

 

    SciaRegs.SCIFFCT.all = 0x0;

}

 

}

 

 

 

//

 

//

// End of file

 

// End of file

//

 

//