//---------------------------------------------------------------------------------------------------------------------
//  Copyright (C) {2019-2022} Texas Instruments Incorporated - http://www.ti.com/
//---------------------------------------------------------------------------------------------------------------------
//
//  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
//  following conditions are met:
//
//  - Redistributions of source code must retain the above copyright notice, this list of conditions and the following
//    disclaimer.
//  - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
//    following disclaimer in the documentation and/or other materials provided with the distribution.
//  - Neither the name of Texas Instruments Incorporated nor the names of its contributors may be used to endorse or
//    promote products derived from this software without specific prior written permission.
//
//  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
//  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
//  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
//  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
//  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
//  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
//  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//---------------------------------------------------------------------------------------------------------------------
//
// \file   stl_cla.h
//
//
// \brief  The CLA Self Test Library implements the Safety Mechanism called CLA2-Software Test of CLA for the F28003x
//
//         This file contains the top level APIs for the CLA Self Test Library (STL).   
//
//         Device Family:     TMS320F28003x
//         Platform:          F28003x ControlCARD
//
// \References: Safety Manual: https://www.ti.com/lit/pdf/sffs277  (under development)
//              Data Sheet   : https://www.ti.com/lit/pdf/sprsp61
//              TRM          : https://www.ti.com/lit/pdf/spruiw9
//              LDRA         : https://www.ldra.com/  Tool used to demonstrate systematic capability of ISO26262/ASIL B
//
//---------------------------------------------------------------------------------------------------------------------
//                                                   VERSION HISTORY
//---------------------------------------------------------------------------------------------------------------------
// DATE         AUTHOR(ID)     JIRA ID           Description
//---------------------------------------------------------------------------------------------------------------------
// 12/11/2019   a0322200       C2000DL-135       Migrate the F2837xx CLA_STL to achieve a F2837xx equivalent 
//                                               functionality on the F28004x CLA_STL 
// 02/25/2020   a0322200       C2000DL-121       Create test vector to support F28004x CLA_TYPE_2
// 03/26/2020   a0322200       C2000DL-164       Migrate new tests from cla_type2 into the PDL repository
// 05/31/2020   a0322200       C2000DL-188       Perform Dynamic Coverage Analysis
// 06/29/2020   a0322200       C2000DL-203       CLA_STL - Implement memcpy to remove dependency on the RTS
// 07/13/2020   a0322200       C2000DL-222       C28x_STL - Prepare for RTM release, performance and resource data
//
// 06/01/2021   a0322200       C2000DL-294       CLA_STL - F2838x, Build STL and STA
// 08/15/2022   a0322200       C2000DL-312       CLA_STL - F2838x Evaluate and Resolve STL_CLA_PEST_VECTOR_16
// 12/18/2022   a0322200       C2000DL-354       CLA_STL - F28003x - Migrate all updates from F2838x
//
//---------------------------------------------------------------------------------------------------------------------

#ifndef STL_CLA_H
#define STL_CLA_H


#ifdef __cplusplus
extern "C"                                       // If building with a C++ compiler, make all definitions in this header
{                                                // have a C binding.
#endif


//*****************************************************************************
//
//! \addtogroup stl_cla CLA STL API Functions
//!
//! The code for this module is contained in <tt>source/stl_cla.c</tt>,
//! <tt>source/stl_cla_s.asm</tt>, and <tt>source/stl_claswbist_s.asm</tt> with
//! <tt>include/stl_cla.h</tt> containing the API declarations for use by
//! applications.
//!
//! # Error Injection #
//!
//! Here are techniques to inject error:
//!
//! \b STL_CLA_runPOSTMicro(), \b STL_CLA_runPESTMicro()
//! - Use a small delay value (i.e. delay < 2) to cause timeout.
//!
//! \b STL_CLA_testRegisters1(), \b STL_CLA_testRegisters2() and
//! \b STL_CLA_testRegisters3()
//! - Set claBasex to an incorrect value i.e. Flash address.
//!
//! @{
//
//*****************************************************************************
#include "Std_Types.h"
//---------------------------------------------------------------------------------------------------------------------
//                                                   DEFINE MACROS
//---------------------------------------------------------------------------------------------------------------------

#define STL_CLA_PASS            0x0000U          //!< CLA STL pass return
#define STL_CLA_FAIL_PSA1       0x0001U          //!< CLA STL PSA1 fail return
#define STL_CLA_FAIL_PSA2       0x0002U          //!< CLA STL PSA2 fail return
#define STL_CLA_FAIL_TIMEOUT    0x0004U          //!< CLA STL timeout return
#define STL_CLA_FAIL_REG        0x0010U          //!< CLA STL register fail return
#define STL_CLA_FAIL_MIOVF      0x0020U          //!< CLA STL overflow fail return
#define STL_CLA_FAIL_MICLROVF   0x0040U          //!< CLA STL overflow clear fail return
#define STL_CLA_FAIL_SPURS_INT  0x0080U          //!< CLA STL spurious interrupt seen in the PIEIFR11

#define STL_CLA_MEMCPY_INP_ERR  0x0100U          //!< CLA STL Src, Dst NULL address or byte count error
#define STL_CLA_MEMCPY_ALG_ERR  0x0200U          //!< CLA STL Src, Destination alignment error
#define STL_CLA_MEMCPY_CNT_ERR  0x0400U          //!< CLA STL memory copy did not copy expected number of bytes
                                                 //!< CLA STL Memory copy was successful
#define STL_CLA_MEMCPY_PASS     STL_CLA_PASS
                                                 //!< CLA_STL Memory copy supports copy of an even number of bytes only
#define STL_CLA_MEMCPY_EVEN     0xFFFFFFFEU

#define STL_CLA_SET_REG32_BIT00 0x00000001UL
#define STL_CLA_SET_ALL_32BITS  0xFFFFFFFFUL
#define STL_CLA_CLR_ALL_32BITS  0x00000000UL

#define STL_CLA_SET_ALL_16BITS  0xFFFFU
#define STL_CLA_CLR_ALL_16BITS  0x0000U
#define STL_CLA_SET_4BITS       0x000FU
#define STL_CLA_SET_8BITS       0x00FFU
#define STL_CLA_SET_BIT00       0x0001U
#define STL_CLA_SET_BIT01       0x0002U
#define STL_CLA_SET_BIT02       0x0004U
#define STL_CLA_SET_BIT03       0x0008U
#define STL_CLA_SET_BIT31       0x8000U

#define STL_CLA_SET_BIT15       0x8000U

#define STL_CLA_DATA_PATTERN_1  0xABCDU          //!< A simple test pattern
#define STL_CLA_DATA_PATTERN_2  0xEF12U          //!< Another simple test pattern

                                                 
#define STL_CLA_POST_NUM_VECTS      11U          //!< CLA STL number of POST vectors
#define STL_CLA_PEST_NUM_VECTS      45U          //!< CLA STL number of PEST vectors
                                                 
#define CLA_O_MPSA1               0x44U          //!< MPSA1 register offset
#define CLA_O_MPSA2               0x46U          //!< MPSA2 register offset
#define CLA_O_MMEMCFG             0x11U          //!< MMEMCFG register offset
#define CLA_O_MPISRCSEL1          0x14U          //!< MPISRCSEL1 register offset
#define CLA_O_MPISRCSEL2          0x16U          //!< MPISRCSEL2 register offset
#define CLA_O_MIPCTL              0x27U          //!< MIPCTL register offset
#define CLA_O_MHWADBGCAP          0x50U          //!< MHWADBGCAP register offset
#define CLA_O_MHWADBGCTL          0x52U          //!< MHWADBGCTL register offset

#define CLA_T2_BASE_ADDR          0x1380U        //!< Base Address for the CLA_TYPE 2 Debug Registers

#define CLA_T2_O_MHWADBGCAP       0x0U           //!< CLA Hardware Accelerator Debug Capabilities Register
#define CLA_RESET_VALUE_DBGCAP    0x06000011UL
#define CLA_T2_RESET_VALUE_DBGCAP 0x4E000220UL


#define CLA_T2_O_MHWADBGCTL       0x2U           //!< CLA Hardware Accelerator Debug Control Register
#define CLA_T2_RESETVAL_DBGCTL_W1 0x1400001EUL
#define CLA_T2_RESETVAL_DBGCTL_W0 0x04000002UL

#define CLA_T2_O_DBG_INDRCT_CAP   0xAU           //!< CLA Hardware Accelerator Indirect access capabilities reg
#define CLA_T2_O_DBG_INDRCT_CTRL  0xCU           //!< CLA Hardware Accelerator Indirect access control register
#define CLA_T2_O_DBG_INDRCT_ADDR  0xEU           //!< CLA Hardware Accelerator Indirect access address register

#define CLA_T2_O_DBG_INDRCT_DATA  0x12U          //!< CLA Hardware Accelerator Indirect access data register

#define CLA_T2_O_DBG_HWBP_0_CNTL  0x20U          //!< CLA hardware breakpoint 0 control register
#define CLA_T2_O_DBG_HWBP_0_ADDR  0x22U          //!< CLA hardware breakpoint 0 address register
#define CLA_T2_O_DBG_HWBP_0_AMASK 0x26U          //!< CLA hardware breakpoint 0 address mask register

#define CLA_T2_O_DBG_HWBP_1_CNTL  0x40U          //!< CLA hardware breakpoint 1 control register
#define CLA_T2_O_DBG_HWBP_1_ADDR  0x42U          //!< CLA hardware breakpoint 1 address register
#define CLA_T2_O_DBG_HWBP_1_AMASK 0x46U          //!< CLA hardware breakpoint 1 address mask register

#define STL_CLA_PIEIFR11_IS_CLEAR 0x00000000UL   //!< CLA STL no spurious interrupt seen in the PIEIFR11

#define STL_CLA_FPU_TEST_DELAY    5800U          //!< 580us micro seconds delay allocated to the FPU test
                                                 //!< FPU test has been designed to run during POST only

#define STL_CLA_DREAD_CLA2CPU_ADDR 0x1480U       //!< Dummy read from CLA to CPU message RAM address
#define STL_CLA_DREAD_RAMLS5_ADDR  0xAFD2U       //!< For performing dummy read of RAMLS5.

#define STL_CLA_DUMMY_LS0_RD_ADDR  0x8000U       //!< Dummy read from (LS0RAM), to assign CPU as owner by default
#define STL_CLA_DUMMY_ROM_ADDR     0x01001000U   //!< Dummy read from CLA ROM,  to assign CPU is owner by default
#define STL_CLA_PV_ADDR            0x8000U       //!< POST VECTOR ADDRESS
#define STL_CLA_PV_MASK            0x0007U       //!< POST VECTOR MASK
//---------------------------------------------------------------------------------------------------------------------
//                                                    DATA TYPES
//---------------------------------------------------------------------------------------------------------------------
extern uint32 postVect00LoadStart;             // Linker Symbols for start addr and size of test vector sections
extern uint32 postVect00LoadSize;
extern uint32 postVect01LoadStart;
extern uint32 postVect01LoadSize;
extern uint32 postVect02LoadStart;
extern uint32 postVect02LoadSize;
extern uint32 postVect03LoadStart;
extern uint32 postVect03LoadSize;
extern uint32 postVect04LoadStart;
extern uint32 postVect04LoadSize;
extern uint32 postVect05_08LoadStart;
extern uint32 postVect05_08LoadSize;
extern uint32 postVect06LoadStart;
extern uint32 postVect06LoadSize;
extern uint32 postVect07LoadStart;
extern uint32 postVect07LoadSize;

extern uint32 postVect09LoadStart;
extern uint32 postVect09LoadSize;

extern uint32 postVect10LoadStart;             // CLA_TYPE_2 added for background task test (SEG97)
extern uint32 postVect10LoadSize;

extern uint32 postVect11LoadStart;             // FPU tests added to increase DC on F28004x (SEG98)
extern uint32 postVect11LoadSize;

extern uint32 pestVect01LoadStart;
extern uint32 pestVect01LoadSize;
extern uint32 pestVect02LoadStart;
extern uint32 pestVect02LoadSize;
extern uint32 pestVect03LoadStart;
extern uint32 pestVect03LoadSize;
extern uint32 pestVect04LoadStart;
extern uint32 pestVect04LoadSize;
extern uint32 pestVect05LoadStart;
extern uint32 pestVect05LoadSize;
extern uint32 pestVect06LoadStart;
extern uint32 pestVect06LoadSize;
extern uint32 pestVect07LoadStart;
extern uint32 pestVect07LoadSize;
extern uint32 pestVect08LoadStart;
extern uint32 pestVect08LoadSize;
extern uint32 pestVect09LoadStart;
extern uint32 pestVect09LoadSize;
extern uint32 pestVect10LoadStart;
extern uint32 pestVect10LoadSize;
extern uint32 pestVect11LoadStart;
extern uint32 pestVect11LoadSize;
extern uint32 pestVect12LoadStart;
extern uint32 pestVect12LoadSize;
extern uint32 pestVect13LoadStart;
extern uint32 pestVect13LoadSize;
extern uint32 pestVect14LoadStart;
extern uint32 pestVect14LoadSize;
extern uint32 pestVect15LoadStart;
extern uint32 pestVect15LoadSize;
extern uint32 pestVect16LoadStart;
extern uint32 pestVect16LoadSize;
extern uint32 pestVect17LoadStart;
extern uint32 pestVect17LoadSize;
extern uint32 pestVect18LoadStart;
extern uint32 pestVect18LoadSize;
extern uint32 pestVect19LoadStart;
extern uint32 pestVect19LoadSize;
extern uint32 pestVect20LoadStart;
extern uint32 pestVect20LoadSize;
extern uint32 pestVect21LoadStart;
extern uint32 pestVect21LoadSize;
extern uint32 pestVect22LoadStart;
extern uint32 pestVect22LoadSize;
extern uint32 pestVect23LoadStart;
extern uint32 pestVect23LoadSize;
extern uint32 pestVect24LoadStart;
extern uint32 pestVect24LoadSize;
extern uint32 pestVect25LoadStart;
extern uint32 pestVect25LoadSize;
extern uint32 pestVect26LoadStart;
extern uint32 pestVect26LoadSize;
extern uint32 pestVect27LoadStart;
extern uint32 pestVect27LoadSize;
extern uint32 pestVect28LoadStart;
extern uint32 pestVect28LoadSize;
extern uint32 pestVect29LoadStart;
extern uint32 pestVect29LoadSize;
extern uint32 pestVect30LoadStart;
extern uint32 pestVect30LoadSize;
extern uint32 pestVect31LoadStart;
extern uint32 pestVect31LoadSize;
extern uint32 pestVect32LoadStart;
extern uint32 pestVect32LoadSize;
extern uint32 pestVect33LoadStart;
extern uint32 pestVect33LoadSize;
extern uint32 pestVect34LoadStart;
extern uint32 pestVect34LoadSize;
extern uint32 pestVect35LoadStart;
extern uint32 pestVect35LoadSize;
extern uint32 pestVect36LoadStart;
extern uint32 pestVect36LoadSize;
extern uint32 pestVect37LoadStart;
extern uint32 pestVect37LoadSize;
extern uint32 pestVect38LoadStart;
extern uint32 pestVect38LoadSize;
extern uint32 pestVect39LoadStart;
extern uint32 pestVect39LoadSize;
extern uint32 pestVect40LoadStart;
extern uint32 pestVect40LoadSize;
extern uint32 pestVect41LoadStart;
extern uint32 pestVect41LoadSize;
extern uint32 pestVect42LoadStart;
extern uint32 pestVect42LoadSize;
extern uint32 pestVect43LoadStart;
extern uint32 pestVect43LoadSize;
extern uint32 pestVect44LoadStart;
extern uint32 pestVect44LoadSize;
extern uint32 pestVect45LoadStart;
extern uint32 pestVect45LoadSize;
extern uint32 postVect03Return1LoadStart;
extern uint32 postVect03Return1LoadSize;
extern uint32 postVect03Return2LoadStart;
extern uint32 postVect03Return2LoadSize;

//
// Typedefs
//

//
//! Values of test vector numbers that can be used for CLA testing.
//! Passed to STL_CLA_runPOSTMicro() as the \e vectNumber parameter.
//
typedef enum
{
    STL_CLA_POST_VECTOR_01,                      //!< POST vector 1
    STL_CLA_POST_VECTOR_02,                      //!< POST vector 2
    STL_CLA_POST_VECTOR_03,                      //!< POST vector 3
    STL_CLA_POST_VECTOR_04,                      //!< POST vector 4
    STL_CLA_POST_VECTOR_05,                      //!< POST vector 5
    STL_CLA_POST_VECTOR_06,                      //!< POST vector 6
    STL_CLA_POST_VECTOR_07,                      //!< POST vector 7
    STL_CLA_POST_VECTOR_08,                      //!< POST vector 8
    STL_CLA_POST_VECTOR_09,                      //!< POST vector 9
    STL_CLA_POST_VECTOR_10,                      //!< POST vector 10
    STL_CLA_POST_VECTOR_11                       //!< POST vector 11 - SEG 98, FPU tests
} STL_CLA_POSTVector;

//
//! Values of test vector numbers that can be used for CLA testing.
//! Passed to and STL_CLA_runPESTMicro() as the \e vectNumber parameter.
//
typedef enum
{
    STL_CLA_PEST_VECTOR_01,                      //!< PEST vector 1
    STL_CLA_PEST_VECTOR_02,                      //!< PEST vector 2
    STL_CLA_PEST_VECTOR_03,                      //!< PEST vector 3
    STL_CLA_PEST_VECTOR_04,                      //!< PEST vector 4
    STL_CLA_PEST_VECTOR_05,                      //!< PEST vector 5
    STL_CLA_PEST_VECTOR_06,                      //!< PEST vector 6
    STL_CLA_PEST_VECTOR_07,                      //!< PEST vector 7
    STL_CLA_PEST_VECTOR_08,                      //!< PEST vector 8
    STL_CLA_PEST_VECTOR_09,                      //!< PEST vector 9
    STL_CLA_PEST_VECTOR_10,                      //!< PEST vector 10
    STL_CLA_PEST_VECTOR_11,                      //!< PEST vector 11
    STL_CLA_PEST_VECTOR_12,                      //!< PEST vector 12
    STL_CLA_PEST_VECTOR_13,                      //!< PEST vector 13
    STL_CLA_PEST_VECTOR_14,                      //!< PEST vector 14
    STL_CLA_PEST_VECTOR_15,                      //!< PEST vector 15
    STL_CLA_PEST_VECTOR_16,                      //!< PEST vector 16
    STL_CLA_PEST_VECTOR_17,                      //!< PEST vector 17
    STL_CLA_PEST_VECTOR_18,                      //!< PEST vector 18
    STL_CLA_PEST_VECTOR_19,                      //!< PEST vector 19
    STL_CLA_PEST_VECTOR_20,                      //!< PEST vector 20
    STL_CLA_PEST_VECTOR_21,                      //!< PEST vector 21
    STL_CLA_PEST_VECTOR_22,                      //!< PEST vector 22
    STL_CLA_PEST_VECTOR_23,                      //!< PEST vector 23
    STL_CLA_PEST_VECTOR_24,                      //!< PEST vector 24
    STL_CLA_PEST_VECTOR_25,                      //!< PEST vector 25
    STL_CLA_PEST_VECTOR_26,                      //!< PEST vector 26
    STL_CLA_PEST_VECTOR_27,                      //!< PEST vector 27
    STL_CLA_PEST_VECTOR_28,                      //!< PEST vector 28
    STL_CLA_PEST_VECTOR_29,                      //!< PEST vector 29
    STL_CLA_PEST_VECTOR_30,                      //!< PEST vector 30
    STL_CLA_PEST_VECTOR_31,                      //!< PEST vector 31
    STL_CLA_PEST_VECTOR_32,                      //!< PEST vector 32
    STL_CLA_PEST_VECTOR_33,                      //!< PEST vector 33
    STL_CLA_PEST_VECTOR_34,                      //!< PEST vector 34
    STL_CLA_PEST_VECTOR_35,                      //!< PEST vector 35
    STL_CLA_PEST_VECTOR_36,                      //!< PEST vector 36
    STL_CLA_PEST_VECTOR_37,                      //!< PEST vector 37
    STL_CLA_PEST_VECTOR_38,                      //!< PEST vector 38
    STL_CLA_PEST_VECTOR_39,                      //!< PEST vector 39
    STL_CLA_PEST_VECTOR_40,                      //!< PEST vector 40
    STL_CLA_PEST_VECTOR_41,                      //!< PEST vector 41
    STL_CLA_PEST_VECTOR_42,                      //!< PEST vector 42
    STL_CLA_PEST_VECTOR_43,                      //!< PEST vector 43
    STL_CLA_PEST_VECTOR_44,                      //!< PEST vector 44
    STL_CLA_PEST_VECTOR_45                       //!< PEST vector 45
} STL_CLA_PESTVector;

                                                 //
                                                 //! Structure definition to hold POST vector information.
                                                 // DID_02_01
                                                 //
typedef const struct
{
    uint32 *vectorAddress;                     //!< POST vector start address
    uint32 *vectorLength;                      //!< POST vector length
    uint32 psa1;                               //!< POST vector expected PSA1 value
    uint32 psa2;                               //!< POST vector expected PSA2 value
                                                 //!< POST runTest
    uint16 (*runTest)(uint16 vectMask, uint16 delayCount);
} STL_CLA_POSTVectorObj;

                                                 //
                                                 //! Handle pointing to STL_CLA_POSTVectorObj.
                                                 // DID_02_02
                                                 //
typedef STL_CLA_POSTVectorObj *STL_CLA_POSTVectorHandle;

                                                 //
                                                 //! Structure definition to hold PEST vector information.
                                                 // DID_02_03
                                                 //
typedef const struct
{
    uint32 *vectorAddress;                     //!< PEST vector start address
    uint32 *vectorLength;                      //!< PEST vector length
    uint32 psa1;                               //!< PEST vector expected PSA1 value
    uint32 psa2;                               //!< PEST vector expected PSA2 value
} STL_CLA_PESTVectorObj;

                                                 //
                                                 //! Handle pointing to STL_CLA_PESTVectorObj.
                                                 // DID_02_04
                                                 //
typedef STL_CLA_PESTVectorObj *STL_CLA_PESTVectorHandle;

                                                 //
                                                 //! Global handles pointing to array of STL_CLA_POSTVectorObj.
                                                 // DID_02_05
                                                 //
extern const STL_CLA_POSTVectorHandle STL_CLA_postHandleArray[STL_CLA_POST_NUM_VECTS];

                                                 //
                                                 //! Global handles pointing to array of STL_CLA_PESTVectorObj.
                                                 // DID_02_05
                                                 //
extern const STL_CLA_PESTVectorHandle STL_CLA_pestHandleArray[STL_CLA_PEST_NUM_VECTS];

                                                 //
                                                 // DID_02_75
                                                 //

//*****************************************************************************
//
//! \brief Configures RAMLS0 and RAMLS5 memories for CLA.
//!
//! This function configures the CLA as the master core for RAMLS0 and RAMLS5.
//!
//! \return None.
//
//*****************************************************************************
extern void STL_CLA_configMemory(void);

//*****************************************************************************
//
//! \brief Copies a test vector to RAMLS0.
//!
//! \param startVectorCopy is a pointer to the start address of a test vector
//! stored in memory. Linker symbols should be used as the input.
//! \param lengthCopy is the number of words of a test vector stored in
//! memory. Linker symbols should be used as the input.
//!
//! This function is an assembly function which performs an efficient memcpy()
//! of a test vector to RAMLS0, address 0x8000.
//!
//! \note This function is called by \b STL_CLA_bootVector() and need
//! not be used in the user's application.
//!
//! \return None.
// DID_02_07
//*****************************************************************************
extern void STL_CLA_copyVector(uint32 *startVectorCopy, uint32 lengthCopy);

//*****************************************************************************
//
//! \brief Copies the first half of a test vector to RAMLS0.
//!
//! \param startVectorCopy1st is a pointer to the start address of a test
//! vector stored in memory. Linker symbols should be used as the input.
//! \param lengthCopy1st is the number of words of a test vector stored in
//! memory. Linker symbols should be used as the input.
//!
//! This function is an assembly function which performs an efficient memcpy()
//! of the first half of a test vector to RAMLS0, address 0x8000.
//!
//! \note This function is called by \b STL_CLA_boot1stHalfVector() and need
//! not be used in the user's application.
//!
//! \return None.
// DID_02_09
//*****************************************************************************
extern void STL_CLA_copy1stHalfVector(uint32 *startVectorCopy1st,
                                      uint32 lengthCopy1st);

//*****************************************************************************
//
//! \brief Copies the second half of a test vector to RAMLS0.
//!
//! \param startVectorCopy2nd is a pointer to the start address of a test
//! vector stored in memory. Linker symbols should be used as the input.
//! \param lengthCopy2nd is the number of words of a test vector stored in
//! memory. Linker symbols should be used as the input.
//!
//! This function is an assembly function which performs an efficient memcpy()
//! of the second half of a test vector to RAMLS0, address 0x8000.
//!
//! \note This function is called by \b STL_CLA_boot2ndHalfVector() and need
//! not be used in the user's application.
//!
//! \return None.
// DID_02_11
//*****************************************************************************
extern void STL_CLA_copy2ndHalfVector(uint32 *startVectorCopy2nd,
                                      uint32 lengthCopy2nd);

//*****************************************************************************
//
//! \brief Boots a test vector to RAMLS0.
//!
//! \param startVector is a pointer to the start address of a test vector
//! stored in memory. Linker symbols should be used as the input.
//! \param length is the number of words of a test vector stored in
//! memory. Linker symbols should be used as the input.
//!
//! This function configures RAMLS0 for CLA data memory, then calls
//! \b STL_CLA_copyVector() which copies the input test vector. This function
//! should be called to boot a test vector before executing the test vector
//! using \b STL_CLA_runPOSTMicro() or \b STL_CLA_runPESTMicro().
//!
//! \note This function calls \b STL_CLA_copyVector() to efficiently perform
//! the memcpy() of the vector.
//!
//! \return None.
// DID_02_13
//*****************************************************************************
extern void STL_CLA_bootVector(uint32 *startVector, uint32 length);

//*****************************************************************************
//
//! \brief Boots the first half of a test vector to RAMLS0.
//!
//! \param startVector1st is a pointer to the start address of a test vector
//! stored in memory. Linker symbols should be used as the input.
//! \param length1st is the number of words of a test vector stored in
//! memory. Linker symbols should be used as the input.
//!
//! This function configures RAMLS0 for CLA data memory, then calls
//! \b STL_CLA_copy1stHalfVector() which copies the input test vector.
//! This function should be called to boot a test vector before executing the
//! test vector using \b STL_CLA_runPOSTMicro() or \b STL_CLA_runPESTMicro().
//!
//! \note This function calls \b STL_CLA_copy1stHalfVector() to efficiently
//! perform the memcpy() of the vector.
//!
//! \return None.
// DID_02_15
//*****************************************************************************
extern void STL_CLA_boot1stHalfVector(uint32 *startVector1st,
                                      uint32 length1st);

//*****************************************************************************
//
//! \brief Boots the second half of a test vector to RAMLS0.
//!
//! \param startVector2nd is a pointer to the start address of a test vector
//! stored in memory. Linker symbols should be used as the input.
//! \param length2nd is the number of words of a test vector stored in
//! memory. Linker symbols should be used as the input.
//!
//! This function configures RAMLS0 for CLA data memory, then calls
//! \b STL_CLA_copy2ndHalfVector() which copies the input test vector.
//! This function should be called to boot a test vector before executing the
//! test vector using \b STL_CLA_runPOSTMicro() or \b STL_CLA_runPESTMicro().
//!
//! \note This function calls \b STL_CLA_copy2ndHalfVector() to efficiently
//! perform the memcpy() of the vector.
//!
//! \return None.
// DID_02_17
//*****************************************************************************
extern void STL_CLA_boot2ndHalfVector(uint32 *startVector2nd,
                                      uint32 length2nd);

//*****************************************************************************
//
//! \brief Executes a single test vector or micro-run of the CLA STL.
//!
//! \param vectNumberPOST is an enumerated type \b STL_CLA_Vector and specifies
//! which vector to execute.
//! \param delayPOST is the delay counter for the loop when waiting for the
//! test vector to finish.
//!
//! This function disables global C28x interrupts, executes a single test
//! vector or micro-run of the CLA STL, and then checks the status. The test
//! vector corresponding to the input parameter \b STL_CLA_POSTVector should
//! be booted to RAMLS0 before calling this function.
//!
//! \note A hard reset of the CLA is conducted before returning. However,
//! this function saves and restores the eight MVECT registers, the MIER
//! register and the the CLA trigger sources.
//!
//! \return If the test vector timed-out, the function returns
//! \b STL_CLA_FAIL_TIMEOUT. If the PSA1 value was incorrect, the function
//! returns \b STL_CLA_FAIL_PSA1. If the PSA2 value was incorrect, the
//! function returns \b STL_CLA_FAIL_PSA2. Or it returns a bitwise OR of
//! the previous values. Otherwise, it returns \b STL_CLA_PASS. When test
//! vector STL_CLA_POST_VECTOR_08 is used, the function may also return
//! \b STL_CLA_FAIL_MIOVF or \b STL_CLA_FAIL_MICLROVF if a fault is detected
//! in the CLA task overflow and overflow clear logic.
// DID_02_53
//*****************************************************************************
extern uint16 STL_CLA_runPOSTMicro(STL_CLA_POSTVector vectNumberPOST,
                                     uint16 delayPOST);

//*****************************************************************************
//
//! \brief Executes a single test vector or micro-run of the CLA STL.
//!
//! \param vectNumberPEST is an enumerated type \b STL_CLA_Vector and specifies
//! which vector to execute.
//! \param delayPEST is the delay counter for the loop when waiting for the
//! test vector to finish.
//!
//! This function disables global C28x interrupts, executes a single test
//! vector or micro-run of the CLA STL, and then checks the status. This
//! function calls \b STL_CLA_runTest(). The test vector corresponding to the
//! input parameter \b STL_CLA_PESTVector should be booted to RAMLS0 before
//! calling this function.
//!
//! \note This function saves and restores the MVECT in use for the test
//! vector. This function also saves and restores the CLA trigger sources as
//! well as the MIER register.
//!
//! \return If the test vector timed-out, the function returns
//! \b STL_CLA_FAIL_TIMEOUT. If the PSA1 value was incorrect, the function
//! returns \b STL_CLA_FAIL_PSA1. If the PSA2 value was incorrect, the
//! function returns \b STL_CLA_FAIL_PSA2. Or it returns a bitwise OR of
//! the previous values. If the check for the presence
//! of spurious interrupts in the IFR11 register is confirmed the function
//! returns \b STL_CLA_FAIL_SPURS_INT Or it returns a bitwise OR of
//! the previous values. Otherwise, it returns \b STL_CLA_PASS.
// DID_02_46, DID_02_74
//*****************************************************************************
extern uint16 STL_CLA_runPESTMicro(STL_CLA_PESTVector vectNumberPEST,
                                     uint16 delayPEST);

//*****************************************************************************
//
//! \brief Runs a test vector of the CLA STL in support of the following test
//!  vectors:
//!  STL_CLA_POST_VECTOR_00 (STL_CLA_testRegisters3)
//!  STL_CLA_POST_VECTOR_01
//!  STL_CLA_POST_VECTOR_02
//!  STL_CLA_POST_VECTOR_03
//!  STL_CLA_POST_VECTOR_11
//!
//! \param vectMask1 is the mask bit to use for the test vector.
//! \param delayCount1 is the delay counter for the loop when waiting for the
//! test vector to finish.
//!
//! This function configures the PSAs, starts the PSAs, starts the test
//! vector, waits for it to finish, stops the PSAs, and then checks that the
//! vector did not timeout.
//!
//! \note This function is an assembly function and is called by
//! \b STL_CLA_runPOSTMicro() and STL_CLA_runPESTMicro().
//!
//! \return If the test vector timed-out, the function returns
//! \b STL_CLA_FAIL_TIMEOUT. Otherwise, it returns \b STL_CLA_PASS.
// DID_02_19
//*****************************************************************************
extern uint16 STL_CLA_runTest(uint16 vectMask1,
                                uint16 delayCount1);

//*****************************************************************************
//
//! \brief Runs a test vector of the CLA STL in support of STL_CLA_POST_VECTOR_09
//!  which configures the RAMLS5 block to allow CPU writes.  CPU writes are
//!  performed to RAMLS5 while the CLA_STL test vector runs to completion.
//!
//! \param vectMask2 is the mask bit to use for the test vector.
//! \param delayCount2 is the delay counter for the loop when waiting for the
//! test vector to finish.
//!
//! This function configures the PSAs, starts the PSAs, starts the test
//! vector. While waiting for the CLA test vector to complete, the C28x writes
//! to RAMLS5. It then stops the PSAs and checks that the vector did not
//! timeout.
//!
//! \note This function is an assembly function and is called by
//! \b STL_CLA_runPOSTMicro().
//!
//! \return If the test vector timed-out, the function returns
//! \b STL_CLA_FAIL_TIMEOUT. Otherwise, it returns \b STL_CLA_PASS.
// DID_02_21
//*****************************************************************************
extern uint16 STL_CLA_runTest_C28WtoLS5(uint16 vectMask2,
                                uint16 delayCount2);

//*****************************************************************************
//
//! \brief Runs a test vector of the CLA STL in support of STL_CLA_POST_VECTOR_07
//!  which configures the RAMLS5 block to allow CPU reads.  CPU reads are
//!  performed from RAMLS5 while the CLA_STL test vector runs to completion.
//!
//! \param vectMask3 is the mask bit to use for the test vector.
//! \param delayCount3 is the delay counter for the loop when waiting for the
//! test vector to finish.
//!
//! This function configures the PSAs, starts the PSAs, starts the test
//! vector. While waiting for the CLA test vector to complete, the C28x reads
//! from RAMLS5. It then stops the PSAs and checks that the vector did not
//! timeout.
//!
//! \note This function is an assembly function and is called by
//! \b STL_CLA_runPOSTMicro().
//!
//! \return If the test vector timed-out, the function returns
//! \b STL_CLA_FAIL_TIMEOUT. Otherwise, it returns \b STL_CLA_PASS.
// DID_02_23
//*****************************************************************************
extern uint16 STL_CLA_runTest_C28RfromLS5(uint16 vectMask3,
                                uint16 delayCount3);

//*****************************************************************************
//
//! \brief Runs a test vector of the CLA STL in support of STL_CLA_POST_VECTOR_04
//!  which is designed to perform a software reset of the CLA.
//!
//! \param vectMask4 is the mask bit to use for the test vector.
//! \param delayCount4 is the delay counter for the loop when waiting for the
//! test vector to finish.
//!
//! This function configures the PSAs, starts the PSAs, starts the test
//! vector. After the loop times-out, the C28x performs a software reset of
//! the CLA. It then stops the PSAsand returns.
//!
//! \note This function is an assembly function and is called by
//! \b STL_CLA_runPOSTMicro().
//!
//! \return The function returns \b STL_CLA_PASS.
// DID_02_27
//*****************************************************************************
extern uint16 STL_CLA_runTestSoftReset(uint16 vectMask4,
                                uint16 delayCount4);

//*****************************************************************************
//
//! \brief Runs a test vector of the CLA STL in support of STL_CLA_POST_VECTOR_05
//!  which configures the IACK instruction as a trigger source for CLA tasks.
//!
//! \param vectMask5 is the mask bit to use for the test vector.
//! \param delayCount5 is the delay counter for the loop when waiting for the
//! test vector to finish.
//!
//! This function configures the PSAs, starts the PSAs, starts all tasks to
//! execute the test vector using the IACK instruction. It then waits for all
//! tasks to finish, stops the PSAs, and then checks that the vector did not
//! timeout.
//!
//! \note This function is an assembly function and is called by
//! \b STL_CLA_runPOSTMicro().
//!
//! \return If the test vector timed-out, the function returns
//! \b STL_CLA_FAIL_TIMEOUT. Otherwise, it returns \b STL_CLA_PASS.
// DID_02_29
//*****************************************************************************
extern uint16 STL_CLA_runTestIACK(uint16 vectMask5,
                                uint16 delayCount5);

//*****************************************************************************
//
//! \brief Runs a test vector of the CLA STL in support of STL_CLA_POST_VECTOR_08
//!  which configures SPIB TXINT as the trigger source for CLA tasks.
//!
//! \param vectMask6 is the mask bit to use for the test vector.
//! \param delayCount6 is the delay counter for the loop when waiting for the
//! test vector to finish.
//!
//! This function configures the PSAs, starts the PSAs, starts all tasks using
//! the SPIB TX interrupt. It then waits for all tasks to finish, stops the
//! PSAs, and then checks that the vector did not timeout.
//!
//! \note This function is an assembly function and is called by
//! \b STL_CLA_runPOSTMicro().
//!
//! \return If the test vector timed-out, the function returns
//! \b STL_CLA_FAIL_TIMEOUT. Otherwise, it returns \b STL_CLA_PASS.
// DID_02_31
//*****************************************************************************
extern uint16 STL_CLA_runTestSPI(uint16 vectMask6,
                                uint16 delayCount6);

//*****************************************************************************
//
//! \brief Runs a the background task and then triggers normal task in order
//! to interrupt the background task.
//!
//! \param vectMask7 is the mask bit to use for the test vector.
//! \param delayCount7 is the delay counter for the loop when waiting for the
//! test vector to finish.
//!
//! This function configures the PSAs, starts the PSAs, starts the background
//! task tasks using software. It then waits some time to start a new task,
//! stops the PSAs, and then checks that the vector did not timeout.
//!
//! \note This function is an assembly function and is called by
//! \b STL_CLA_runPOSTMicro().
//!
//! \return If the test vector timed-out, the function returns
//! \b STL_CLA_FAIL_TIMEOUT. Otherwise, it returns \b STL_CLA_PASS.
//
//*****************************************************************************
extern uint16 STL_CLA_runTestBG(uint16 vectMask7,
                                uint16 delayCount7);

//*****************************************************************************
//! \brief Performs a C28x test of the CLA configuration registers.
//!
//! \param claBase1 is the base address of CLA1 (CLA1_BASE).
//!
//! This function tests C28x writeable CLA registers.
//!
//! This function tests:
//! -MVECT1-8
//! -MCTL
//! -MIER
//! -MIFRC
//! -MIFR
//! -MICLR
//! -MIOVF
//!
//! \note The registers are not restored after testing them. A hard reset of
//! the CLA is conducted before returning.
//! \note In order to inject an error, use an incorrect claBase. One suggestion
//! is to use some flash address.
//!
//! \return If a register failed the test, the test returns
//! \b STL_CLA_FAIL_REG. Otherwise, the function returns \b STL_CLA_PASS.
// DID_02_33
//*****************************************************************************
extern uint16 STL_CLA_testRegisters1(uint32 claBase1);

//*****************************************************************************
//
//! \brief Performs a C28x test of the CLA configuration registers.
//!
//! \param claBase2 is the base address of CLA1 (CLA1_BASE).
//!
//! This function tests C28x writeable CLA registers.
//!
//! This function tests:
//! -MIPCTL
//! -MEMCFG
//! -MISRCSEL1
//! -MISRCSEL2
//! -MHWADBGCAP
//! -MHWADBGCTL
//!
//! \note The registers are not restored after testing them. A hard reset of
//! the CLA is conducted before returning.
//! \note In order to inject an error, use an incorrect claBase. One suggestion
//! is to use some flash address.
//!
//! \return If a register failed the test, the test returns
//! \b STL_CLA_FAIL_REG. Otherwise, the function returns \b STL_CLA_PASS.
// DID_02_36
//*****************************************************************************
extern uint16 STL_CLA_testRegisters2(uint32 claBase2);

//*****************************************************************************
//
//! \brief Performs a C28x test of the CLA registers.
//!
//! \param claBase3 is the base address of CLA1 (CLA1_BASE).
//! \param delayCnt is the delay counter for the loop when waiting for the
//! test vector to finish.
//!
//! This function performs a hard reset then checksums the configuration
//! registers. Then, it boots a small test vector which verifies the reset of
//! of the internal CLA registers. Then, the C28x checks the PSAs to confirm
//! the reset worked properly on the internal CLA registers. Following this,
//! the C28x writes to the configruation registers and reads back the values
//! and calculates a checksum. The C28x finishes by comparing the checksums
//! with the expected golden values and returning a pass or fail.
//!
//! \note The registers are not restored after testing them. A hard reset of
//! the CLA is conducted before returning.
//! \note In order to inject an error, use an incorrect claBase3. One 
//! suggestion is to use some flash address.
//!
//! \return If a register failed the test, the test returns
//! \b STL_CLA_FAIL_REG. If the PSA1 value was incorrect, the function
//! returns \b STL_CLA_FAIL_PSA1. If the PSA2 value was incorrect, the
//! function returns \b STL_CLA_FAIL_PSA2. If the CLA timed-out then the test
//! will return STL_CLA_FAIL_TIMEOUT. Otherwise, the function returns
//! \b STL_CLA_PASS.
// DID_02_39
//*****************************************************************************
extern uint16 STL_CLA_testRegisters3(uint32 claBase3, uint16 delayCnt);

//*****************************************************************************
//
// Close the Doxygen group.
//! @}
//
//*****************************************************************************

#ifdef __cplusplus
}                                                // Mark the end of the C bindings section for C++ compilers.
#endif   
                                        
#endif                                           // CLA_STL_H

//---------------------------------------------------------------------------------------------------------------------
// End of File
//---------------------------------------------------------------------------------------------------------------------
