/**
*   @copyright       © 2026 Microchip Technology Inc.
    Microchip Technology Inc. and its subsidiaries. You may use this
    software and any derivatives exclusively with Microchip products.

    THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
    EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
    WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
    PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
    WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.

    IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
    INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
    WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
    BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
    FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
    ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
    THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.

    MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
    TERMS. 
*
*************************************************************************/

/**
*  @file        diag_cpu_controlreg_test.c
*  @version     1.0
*  @brief       This file has the implementation for the CPU
                Control register test. @see diag_cpu.h
*
*************************************************************************/
/*Function headers*/
#include "diag_cpu.h"
#include "diag_cpu_shared.h"

volatile uint64_t diagCpuControlRegStatusFlags;

/*LDRA_EXCLUDE 88 S <justification start> functionally implemented to test assembly instruction behavior, hence violation ignored <justification end> */
static void DIAG_CPU_ControlNonMemRegTest(void)
{
    /* Save contents of W0 and W1 to stack, so that they can be used for testing W0-W15 and SPLIM */
	__asm__ volatile ("push w0\n\t"
                      "push w1\n\t"
                      "push w2\n\t");

    /* Test both W0 and W1 together, by writing to both registers and comparing to each others
       Set error flags for both registers if the values read back from them do not match */

   __asm__ volatile ("Test_W0_W1_PartA: mov.l #0xAAAAAAAA, w0\n\t"
                      "mov.l #0xAAAAAAAA, w1\n\t"
                      "cp w0, w1\n\t"
                      "bra z, Test_W0_W1_PartB");
    diagCpuControlRegStatusFlags |= ((uint64_t)1 << (uint64_t)DIAG_W0_FLAG_INDEX);
    diagCpuControlRegStatusFlags |= ((uint64_t)1 << (uint64_t)DIAG_W1_FLAG_INDEX);

 
       __asm__ volatile ("Test_W0_W1_PartB: mov.l #0x55555555, w0\n\t"
                      "mov.l #0x55555555, w1\n\t"
                      "cp w0, w1\n\t"
                      "bra z, Test_W2_PartA");
    diagCpuControlRegStatusFlags |= ((uint64_t)1 << (uint64_t)DIAG_W0_FLAG_INDEX);
    diagCpuControlRegStatusFlags |= ((uint64_t)1 << (uint64_t)DIAG_W1_FLAG_INDEX);

   
       __asm__ volatile ("Test_W2_PartA: mov w2, w1\n\t"
                      "mov.l #0xAAAAAAAA, w2\n\t"
                      "mov.l #0xAAAAAAAA, w0\n\t"    
                      "cp w2, w0\n\t"
                      "mov w1, w2\n\t"
                      "bra z, Test_W2_PartB");
    diagCpuControlRegStatusFlags |= ((uint64_t)1 << (uint64_t)DIAG_W2_FLAG_INDEX);

   
       __asm__ volatile ("Test_W2_PartB: mov w2, w1\n\t"
                      "mov.l #0x55555555, w2\n\t"
                      "mov.l #0x55555555, w0\n\t"    
                      "cp w2, w0\n\t"
                      "mov w1, w2\n\t"
                      "bra z, Test_W3_PartA\n\t");
    diagCpuControlRegStatusFlags |= ((uint64_t)1 << (uint64_t)DIAG_W2_FLAG_INDEX);

   
       __asm__ volatile ("Test_W3_PartA: mov w3, w1\n\t"
                      "mov.l #0xAAAAAAAA, w3\n\t"
                      "mov.l #0xAAAAAAAA, w0\n\t"    
                      "cp w3, w0\n\t"
                      "mov w1, w3\n\t"
                      "bra z, Test_W3_PartB");
    diagCpuControlRegStatusFlags |= ((uint64_t)1 << (uint64_t)DIAG_W3_FLAG_INDEX);

   
       __asm__ volatile ("Test_W3_PartB: mov w3, w1\n\t"
                      "mov.l #0x55555555, w3\n\t"
                      "mov.l #0x55555555, w0\n\t"    
                      "cp w3, w0\n\t"
                      "mov w1, w3\n\t"
                      "bra z, Test_W4_PartA");
    diagCpuControlRegStatusFlags |= ((uint64_t)1 << (uint64_t)DIAG_W3_FLAG_INDEX);

   
       __asm__ volatile ("Test_W4_PartA: mov w4, w1\n\t"
                      "mov.l #0xAAAAAAAA, w4\n\t"
                      "mov.l #0xAAAAAAAA, w0\n\t"    
                      "cp w4, w0\n\t"
                      "mov w1, w4\n\t"
                      "bra z, Test_W4_PartB");
    diagCpuControlRegStatusFlags |= ((uint64_t)1 << (uint64_t)DIAG_W4_FLAG_INDEX);

   
       __asm__ volatile ("Test_W4_PartB: mov w4, w1\n\t"
                      "mov.l #0x55555555, w4\n\t"
                      "mov.l #0x55555555, w0\n\t"    
                      "cp w4, w0\n\t"
                      "mov w1, w4\n\t"
                      "bra z, Test_W5_PartA\n\t");
    diagCpuControlRegStatusFlags |= ((uint64_t)1 << (uint64_t)DIAG_W4_FLAG_INDEX);

   
       __asm__ volatile ("Test_W5_PartA: mov w5, w1\n\t"
                      "mov.l #0xAAAAAAAA, w5\n\t"
                      "mov.l #0xAAAAAAAA, w0\n\t"    
                      "cp w5, w0\n\t"
                      "mov w1, w5\n\t"
                      "bra z, Test_W5_PartB");
    diagCpuControlRegStatusFlags |= ((uint64_t)1 << (uint64_t)DIAG_W5_FLAG_INDEX);

   
       __asm__ volatile ("Test_W5_PartB: mov w5, w1\n\t"
                      "mov.l #0x55555555, w5\n\t"
                      "mov.l #0x55555555, w0\n\t"    
                      "cp w5, w0\n\t"
                      "mov w1, w5\n\t"
                      "bra z, Test_W6_PartA");
    diagCpuControlRegStatusFlags |= ((uint64_t)1 << (uint64_t)DIAG_W5_FLAG_INDEX);

   
       __asm__ volatile ("Test_W6_PartA: mov w6, w1\n\t"
                      "mov.l #0xAAAAAAAA, w6\n\t"
                      "mov.l #0xAAAAAAAA, w0\n\t"    
                      "cp w6, w0\n\t"
                      "mov w1, w6\n\t"
                      "bra z, Test_W6_PartB");
    diagCpuControlRegStatusFlags |= ((uint64_t)1 << (uint64_t)DIAG_W6_FLAG_INDEX);

   
       __asm__ volatile ("Test_W6_PartB: mov w6, w1\n\t"
                      "mov.l #0x55555555, w6\n\t"
                      "mov.l #0x55555555, w0\n\t"    
                      "cp w6, w0\n\t"
                      "mov w1, w6\n\t"
                      "bra z, Test_W7_PartA");
    diagCpuControlRegStatusFlags |= ((uint64_t)1 << (uint64_t)DIAG_W6_FLAG_INDEX);

   
       __asm__ volatile ("Test_W7_PartA: mov w7, w1\n\t"
                      "mov.l #0xAAAAAAAA, w7\n\t"
                      "mov.l #0xAAAAAAAA, w0\n\t"    
                      "cp w7, w0\n\t"
                      "mov w1, w7\n\t"
                      "bra z, Test_W7_PartB");
    diagCpuControlRegStatusFlags |= ((uint64_t)1 << (uint64_t)DIAG_W7_FLAG_INDEX);

   
       __asm__ volatile ("Test_W7_PartB: mov w7, w1\n\t"
                      "mov.l #0x55555555, w7\n\t"
                      "mov.l #0x55555555, w0\n\t"    
                      "cp w7, w0\n\t"
                      "mov w1, w7\n\t"
                      "bra z, Test_W8_PartA");
    diagCpuControlRegStatusFlags |= ((uint64_t)1 << (uint64_t)DIAG_W7_FLAG_INDEX);

   
       __asm__ volatile ("Test_W8_PartA: mov w8, w1\n\t"
                      "mov.l #0xAAAAAAAA, w8\n\t"
                      "mov.l #0xAAAAAAAA, w0\n\t"    
                      "cp w8, w0\n\t"
                      "mov w1, w8\n\t"
                      "bra z, Test_W8_PartB");
    diagCpuControlRegStatusFlags |= ((uint64_t)1 << (uint64_t)DIAG_W8_FLAG_INDEX);

   
       __asm__ volatile ("Test_W8_PartB: mov w8, w1\n\t"
                      "mov.l #0x55555555, w8\n\t"
                      "mov.l #0x55555555, w0\n\t"    
                      "cp w8, w0\n\t"
                      "mov w1, w8\n\t"
                      "bra z, Test_W9_PartA");
    diagCpuControlRegStatusFlags |= ((uint64_t)1 << (uint64_t)DIAG_W8_FLAG_INDEX);

   
       __asm__ volatile ("Test_W9_PartA: mov w9, w1\n\t"
                      "mov.l #0xAAAAAAAA, w9\n\t"
                      "mov.l #0xAAAAAAAA, w0\n\t"    
                      "cp w9, w0\n\t"
                      "mov w1, w9\n\t"
                      "bra z, Test_W9_PartB");
    diagCpuControlRegStatusFlags |= ((uint64_t)1 << (uint64_t)DIAG_W9_FLAG_INDEX);

   
       __asm__ volatile ("Test_W9_PartB: mov w9, w1\n\t"
                      "mov.l #0x55555555, w9\n\t"
                      "mov.l #0x55555555, w0\n\t"    
                      "cp w9, w0\n\t"
                      "mov w1, w9\n\t"
                      "bra z, Test_W10_PartA");
    diagCpuControlRegStatusFlags |= ((uint64_t)1 << (uint64_t)DIAG_W9_FLAG_INDEX);

   
       __asm__ volatile ("Test_W10_PartA: mov w10, w1\n\t"
                      "mov.l #0xAAAAAAAA, w10\n\t"
                      "mov.l #0xAAAAAAAA, w0\n\t"    
                      "cp w10, w0\n\t"
                      "mov w1, w10\n\t"
                      "bra z, Test_W10_PartB");
    diagCpuControlRegStatusFlags |= ((uint64_t)1 << (uint64_t)DIAG_W10_FLAG_INDEX);

   
       __asm__ volatile ("Test_W10_PartB: mov w10, w1\n\t"
                      "mov.l #0x55555555, w10\n\t"
                      "mov.l #0x55555555, w0\n\t"    
                      "cp w10, w0\n\t"
                      "mov w1, w10\n\t"
                      "bra z, Test_W11_PartA");
    diagCpuControlRegStatusFlags |= ((uint64_t)1 << (uint64_t)DIAG_W10_FLAG_INDEX);

   
       __asm__ volatile ("Test_W11_PartA: mov w11, w1\n\t"
                      "mov.l #0xAAAAAAAA, w11\n\t"
                      "mov.l #0xAAAAAAAA, w0\n\t"    
                      "cp w11, w0\n\t"
                      "mov w1, w11\n\t"
                      "bra z, Test_W11_PartB");
    diagCpuControlRegStatusFlags |= ((uint64_t)1 << (uint64_t)DIAG_W11_FLAG_INDEX);

   
       __asm__ volatile ("Test_W11_PartB: mov w11, w1\n\t"
                      "mov.l #0x55555555, w11\n\t"
                      "mov.l #0x55555555, w0\n\t"    
                      "cp w11, w0\n\t"
                      "mov w1, w11\n\t"
                      "bra z, Test_W12_PartA");
    diagCpuControlRegStatusFlags |= ((uint64_t)1 << (uint64_t)DIAG_W11_FLAG_INDEX);

   
       __asm__ volatile ("Test_W12_PartA: mov w12, w1\n\t"
                      "mov.l #0xAAAAAAAA, w12\n\t"
                      "mov.l #0xAAAAAAAA, w0\n\t"    
                      "cp w12, w0\n\t"
                      "mov w1, w12\n\t"
                      "bra z, Test_W12_PartB");
    diagCpuControlRegStatusFlags |= ((uint64_t)1 << (uint64_t)DIAG_W12_FLAG_INDEX);

   
       __asm__ volatile ("Test_W12_PartB: mov w12, w1\n\t"
                      "mov.l #0x55555555, w12\n\t"
                      "mov.l #0x55555555, w0\n\t"    
                      "cp w12, w0\n\t"
                      "mov w1, w12\n\t"
                      "bra z, Test_W13_PartA");
    diagCpuControlRegStatusFlags |= ((uint64_t)1 << (uint64_t)DIAG_W12_FLAG_INDEX);

   
       __asm__ volatile ("Test_W13_PartA: mov w13, w1\n\t"
                      "mov.l #0xAAAAAAAA, w13\n\t"
                      "mov.l #0xAAAAAAAA, w0\n\t"   
                      "cp w13, w0\n\t"
                      "mov w1, w13\n\t"
                      "bra z, Test_W13_PartB\n\t");
    diagCpuControlRegStatusFlags |= ((uint64_t)1 << (uint64_t)DIAG_W13_FLAG_INDEX);

   
       __asm__ volatile ("Test_W13_PartB: mov w13, w1\n\t"
                      "mov.l #0x55555555, w13\n\t"
                      "mov.l #0x55555555, w0\n\t"    
                      "cp w13, w0\n\t"
                      "mov w1, w13\n\t"
                      "bra z, Test_W14_PartA");
    diagCpuControlRegStatusFlags |= ((uint64_t)1 << (uint64_t)DIAG_W13_FLAG_INDEX);

   
       __asm__ volatile ("Test_W14_PartA: mov w14, w1\n\t"
                      "mov.l #0xAAAAAAAA, w14\n\t"
                      "mov.l #0xAAAAAAAA, w0\n\t"    
                      "cp w14, w0\n\t"
                      "mov w1, w14\n\t"
                      "bra z, Test_W14_PartB");
    diagCpuControlRegStatusFlags |= ((uint64_t)1 << (uint64_t)DIAG_W14_FLAG_INDEX);

   
       __asm__ volatile ("Test_W14_PartB: mov w14, w1\n\t"
                      "mov.l #0x55555555, w14\n\t"
                      "mov.l #0x55555555, w0\n\t"    
                      "cp w14, w0\n\t"
                      "mov w1, w14\n\t"
                      "bra z, Test_W15_PartA");
    diagCpuControlRegStatusFlags |= ((uint64_t)1 << (uint64_t)DIAG_W14_FLAG_INDEX);

   
       __asm__ volatile ("Test_W15_PartA: mov w15, w1\n\t"
                      "mov.l #0xAAAAAAA8, w15\n\t"
                      "mov.l #0xAAAAAAA8, w0\n\t"    
                      "cp w15, w0\n\t"
                      "mov w1, w15\n\t"
                      "bra z, Test_W15_PartB");
    diagCpuControlRegStatusFlags |= ((uint64_t)1 << (uint64_t)DIAG_W15_FLAG_INDEX);

   
       __asm__ volatile ("Test_W15_PartB: mov w15, w1\n\t"
                      "mov.l #0x55555554, w15\n\t"
                      "mov.l #0x55555554, w0\n\t"   
                      "cp w15, w0\n\t"
                      "mov w1, w15\n\t"
                      "bra z, Test_SPLIM_PartA");
    diagCpuControlRegStatusFlags |= ((uint64_t)1 << (uint64_t)DIAG_W15_FLAG_INDEX);

   
       __asm__ volatile ("Test_SPLIM_PartA: mov SPLIM, w1\n\t"
                      "mov.l #0xAAAAAAA8, w0\n\t"
                      "mov w0, SPLIM\n\t"
                      "mov.l #0xAAAAAAA8, w0\n\t"
                      "mov SPLIM, w2\n\t"    
                      "cp w2, w0\n\t"
                      "mov w1, SPLIM\n\t"
                      "bra z, Test_SPLIM_PartB");
    diagCpuControlRegStatusFlags |= ((uint64_t)1 << (uint64_t)DIAG_SPLIM_FLAG_INDEX);

   
       __asm__ volatile ("Test_SPLIM_PartB: mov SPLIM, w1\n\t"
                      "mov.l #0x55555554, w0\n\t"
                      "mov w0, SPLIM\n\t"
                      "mov.l #0x55555554, w0\n\t"
                      "mov SPLIM, w2\n\t"    
                      "cp w2, w0\n\t"
                      "mov w1, SPLIM\n\t"
                      "bra z, Test_ACCA_PartA");
    diagCpuControlRegStatusFlags |= ((uint64_t)1 << (uint64_t)DIAG_SPLIM_FLAG_INDEX);
    
    __asm__ volatile ("Test_ACCA_PartA: sac A,w1\n\t"
                      "mov.l #0xAAAAAAAA,w0\n\t"
                      "lac w0, A\n\t"
                      "sac A,w2\n\t"
                      "cp w2, w0\n\t"
                      "lac w1,A\n\t"
                      "bra z, Test_ACCA_PartB");
   
    diagCpuControlRegStatusFlags |= ((uint64_t)1 << (uint64_t)DIAG_ACCA_FLAG_INDEX);
    __asm__ volatile ("Test_ACCA_PartB: sac A,w1\n\t"
                      "mov.l #0x55555555,w0\n\t"
                      "lac w0, A\n\t"
                      "sac A,w2\n\t"
                      "cp w2, w0\n\t"
                      "lac w1,A\n\t"
                      "bra z, Test_ACCB_PartA");
    diagCpuControlRegStatusFlags |= ((uint64_t)1 << (uint64_t)DIAG_ACCA_FLAG_INDEX);
       
    __asm__ volatile ("Test_ACCB_PartA: sac A,w1\n\t"
                      "mov.l #0x55555555,w0\n\t"
                      "lac w0, A\n\t"
                      "sac A,w2\n\t"
                      "cp w2, w0\n\t"
                      "lac w1,A\n\t"
                      "bra z, Test_ACCB_PartB");
    diagCpuControlRegStatusFlags |= ((uint64_t)1 << (uint64_t)DIAG_ACCB_FLAG_INDEX);
    __asm__ volatile ("Test_ACCB_PartB: sac A,w1\n\t"
                      "mov.l #0x55555555,w0\n\t"
                      "lac w0, A\n\t"
                      "sac A,w2\n\t"
                      "cp w2, w0\n\t"
                      "lac w1,A\n\t"
                      "bra z, Test_SR_PartA");
    diagCpuControlRegStatusFlags |= ((uint64_t)1 << (uint64_t)DIAG_ACCB_FLAG_INDEX);
    
    
    /*Testing for SR register*/
    __asm__ volatile ("Test_SR_PartA: mov SR,w1\n\t"
                      "mov.l #0x00005C45,w0\n\t"
                      "mov w0, SR\n\t"
                      "mov SR,w2\n\t"
                      "cp w2, w0\n\t"
                      "mov w1,SR\n\t"
                      "bra z, Test_SR_PartB");
    diagCpuControlRegStatusFlags |= ((uint64_t)1 << (uint64_t)DIAG_SR_FLAG_INDEX);
    __asm__ volatile ("Test_SR_PartB: mov SR,w1\n\t"
                      "mov.l #0x000088AA,w0\n\t"
                      "mov w0, SR\n\t"
                      "mov SR,w2\n\t"
                      "cp w2, w0\n\t"
                      "mov w1,SR\n\t"
                      "bra z, Restore_Wregs");
    diagCpuControlRegStatusFlags |= ((uint64_t)1 << (uint64_t)DIAG_SR_FLAG_INDEX);
    
    /* Restore original contents of W2, W1, W0 from stack */
       __asm__ volatile ("Restore_Wregs: pop w2\n\t"
                         "pop w1\n\t"
                         "pop w0\n\t");	
	/*LDRA_EXCLUDE 88 S <justification start> functionally implemented to test assembly instruction behavior, hence violation ignored <justification end> */					 
}

uint32_t DIAG_CPU_ControlRegTest(void)
{
    uint32_t result;
    static const diagCpuControlTestLookup controlTestLookup[DIAG_CPU_TEST_REGS] = {
                                {0x55555555U,0xAAAAAAAAU,0xFFFFFFFFU},/*RCOUNT*/
                                {0x00000000U,0x00000000U,0x00000000U},/*DISIIPL-not tested, read-only bits*/
                                {0x00001051U,0x000000A2U,0x0000FFFFU},/*CORCON*/
                                {0x00004055U,0x000080AAU,0x0000FFFFU},/*MODCON*/
                                {0x00555554U,0x00AAAAAAU,0x00FFFFFFU},/*XMODSRT*/
                                {0x00555555U,0x00AAAAABU,0x00FFFFFFU},/*XMODEND*/
                                {0x00555554U,0x00AAAAAAU,0x00FFFFFFU},/*YMODSRT*/
                                {0x00555555U,0x00AAAAABU,0x00FFFFFFU},/*YMODEND*/
                                {0x00005554U,0x00002AAAU,0x0000FFFFU},/*XBREV*/
                                {0x00000000U,0x00000000U,0x00000000U},/*PCTRAP-not tested, read-only*/
                                {0x00000000U,0x00000000U,0x00000000U},/*FEX-not tested, read-only*/
                                {0x00000000U,0x00000000U,0x00000000U},/*FEX2-not tested, read-only*/
                                {0x00000000U,0x00000000U,0x00000000U},/*PCHOLD-not tested, read-only*/
                                {0x00555554U,0x00AAAAAAU,0x00FFFFFFU}/*VFA*/
    };
    volatile uint32_t savedINTCON2 = 0x00000000U;
    volatile uint32_t savedINTCON1 = 0x0U;
	/* LDRA_EXCLUDE 606 S <justification start>Pointer to array wrongly identified as function pointer. Violation Ignored.<justification end> */
    cpuRegMap_t cpuRegMapPtr = (cpuRegMap_t)CPU_RCOUNT_REG_BASE;
    uint32_t loopCount=0;
    /*LDRA_EXCLUDE 105 D <justification start> registers saved and restored as per functionality, hence violation ignored <justification end> */
    uint32_t savedRegValue=0;
    DIAG_CPU_SetRetValue(DIAG_FAIL);
    diagCpuControlRegStatusFlags = 0x0000000000000000UL;
    /* Save INTCON2 register and temporarily disable all interrupts */
    savedINTCON2 = INTCON2;
    savedINTCON1 = INTCON1;
    _GIE = 0;
    
    DIAG_CPU_ControlNonMemRegTest();
    /*Memory-mapped registers are tested here*/
    while(loopCount < DIAG_CPU_TEST_REGS)
    {
        if(controlTestLookup[loopCount].testValue1 != 0x00000000U)
        {
            savedRegValue = (*cpuRegMapPtr)[loopCount];
            (*cpuRegMapPtr)[loopCount] = controlTestLookup[loopCount].testValue1;
            /*LDRA_NOANALYSIS*/
            if(((*cpuRegMapPtr)[loopCount] & controlTestLookup[loopCount].maskValue) != controlTestLookup[loopCount].testValue1)
            {
                /*LDRA_EXCLUDE 51 S <justification start> functionally tested for values within range, hence violation ignored <justification end> */
                diagCpuControlRegStatusFlags |= 1UL << (loopCount + (uint32_t)DIAG_RCOUNT_FLAG_INDEX);
            }
            else
            {
                (*cpuRegMapPtr)[loopCount] = controlTestLookup[loopCount].testValue2;
                if(((*cpuRegMapPtr)[loopCount] & controlTestLookup[loopCount].maskValue) 
                        != controlTestLookup[loopCount].testValue2)
                {
                    /*LDRA_EXCLUDE 51 S <justification start> functionally tested for values within range, hence violation ignored <justification end> */
                    diagCpuControlRegStatusFlags |= 1UL << (loopCount + (uint32_t)DIAG_RCOUNT_FLAG_INDEX);
                }
            }
            /*LDRA_ANALYSIS*/
            (*cpuRegMapPtr)[loopCount] = savedRegValue;
        }
        loopCount+=1U;
    }
    
    
    if(diagCpuControlRegStatusFlags > 0U)
    {
        DIAG_CPU_SetRetValue(DIAG_FAIL);
    }
    else
    {
        DIAG_CPU_SetRetValue(DIAG_PASS);
    }
    INTCON2 = savedINTCON2;
    INTCON1 = savedINTCON1;
    result = DIAG_CPU_GetRetValue();
    return result;    
}
