STATUS write_cfg()

in common/recipes-core/asd_1.4.3/files/daemon/asd_msg.c [1229:1421]


STATUS write_cfg(ASD_MSG* state, const writeCfg cmd, struct packet_data* packet)
{
    STATUS status = ST_OK;
    unsigned char* data;

    if (cmd == JTAG_FREQ)
    {
        // JTAG_FREQ (Index 1, Size: 1 Byte)
        //  Bit 7:6 – Prescale Value (b'00 – 1, b'01 – 2, b'10 – 4, b'11
        //  – 8) Bit 5:0 – Divisor (1-64, 64 is expressed as value 0)
        //  The TAP clock frequency is determined by dividing the system
        //  clock of the TAP Master first through the prescale value
        //  (1,2,4,8) and then through the divisor (1-64).
        // e.g. system clock/(prescale * divisor)
        uint8_t prescaleVal = 0, divisorVal = 0, tCLK = 0;
        data = get_packet_data(packet, 1);
        if (data == NULL)
        {
            status = ST_ERR;
            ASD_log(ASD_LogLevel_Error, ASD_LogStream_SDK, ASD_LogOption_None,
                    "Unable to read JTAG_FREQ data byte");
        }
        else
        {
            prescaleVal = data[0] >> (uint8_t)5;
            divisorVal = data[0] & (uint8_t)0x1f;

            if (prescaleVal == 0)
            {
                prescaleVal = 1;
            }
            else if (prescaleVal == 1)
            {
                prescaleVal = 2;
            }
            else if (prescaleVal == 2)
            {
                prescaleVal = 4;
            }
            else if (prescaleVal == 3)
            {
                prescaleVal = 8;
            }
            else
            {
                prescaleVal = 1;
            }

            if (divisorVal == 0)
            {
                divisorVal = 64;
            }

            tCLK = (prescaleVal * divisorVal);
#ifdef ENABLE_DEBUG_LOGGING
            ASD_log(ASD_LogLevel_Debug, ASD_LogStream_SDK, ASD_LogOption_None,
                    "Set JTAG TAP Pre: %d  Div: %d  TCK: %d", prescaleVal,
                    divisorVal, tCLK);
#endif

            status = JTAG_set_jtag_tck(state->jtag_handler, tCLK);
            if (status != ST_OK)
                ASD_log(ASD_LogLevel_Error, ASD_LogStream_SDK,
                        ASD_LogOption_None, "Unable to set the JTAG TAP TCK!");
        }
    }
    else if (cmd == DR_PREFIX)
    {
        // DR Postfix (A.K.A. DR Prefix in At-Scale Debug Arch. Spec.)
        // set drPaddingNearTDI 1 byte of data

        data = get_packet_data(packet, 1);
        if (data == NULL)
        {
            status = ST_ERR;
            ASD_log(ASD_LogLevel_Error, ASD_LogStream_SDK, ASD_LogOption_None,
                    "Unable to read DRPost data byte");
        }
        else
        {
#ifdef ENABLE_DEBUG_LOGGING
            ASD_log(ASD_LogLevel_Debug, ASD_LogStream_SDK, ASD_LogOption_None,
                    "Setting DRPost padding to %d", data[0]);
#endif
            status = JTAG_set_padding(state->jtag_handler,
                                      JTAGPaddingTypes_DRPost, data[0]);
            if (status != ST_OK)
                ASD_log(ASD_LogLevel_Error, ASD_LogStream_SDK,
                        ASD_LogOption_None, "failed to set DRPost padding");
        }
    }
    else if (cmd == DR_POSTFIX)
    {
        // DR preFix (A.K.A. DR Postfix in At-Scale Debug Arch. Spec.)
        // drPaddingNearTDO 1 byte of data

        data = get_packet_data(packet, 1);
        if (data == NULL)
        {
            status = ST_ERR;
            ASD_log(ASD_LogLevel_Error, ASD_LogStream_SDK, ASD_LogOption_None,
                    "Unable to read DRPre data byte");
        }
        else
        {
#ifdef ENABLE_DEBUG_LOGGING
            ASD_log(ASD_LogLevel_Debug, ASD_LogStream_SDK, ASD_LogOption_None,
                    "Setting DRPre padding to %d", data[0]);
#endif
            status = JTAG_set_padding(state->jtag_handler,
                                      JTAGPaddingTypes_DRPre, data[0]);
            if (status != ST_OK)
                ASD_log(ASD_LogLevel_Error, ASD_LogStream_SDK,
                        ASD_LogOption_None, "failed to set DRPre padding");
        }
    }
    else if (cmd == IR_PREFIX)
    {
        // IR Postfix (A.K.A. IR Prefix in At-Scale Debug Arch. Spec.)
        // irPaddingNearTDI 2 bytes of data

        data = get_packet_data(packet, 2);
        if (data == NULL)
        {
            status = ST_ERR;
            ASD_log(ASD_LogLevel_Error, ASD_LogStream_SDK, ASD_LogOption_None,
                    "Unable to read IRPost data byte");
        }
        else
        {
#ifdef ENABLE_DEBUG_LOGGING
            ASD_log(ASD_LogLevel_Debug, ASD_LogStream_SDK, ASD_LogOption_None,
                    "Setting IRPost padding to %d", (data[1] << 8) | data[0]);
#endif
            status =
                JTAG_set_padding(state->jtag_handler, JTAGPaddingTypes_IRPost,
                                 (data[1] << 8) | data[0]);
            if (status != ST_OK)
                ASD_log(ASD_LogLevel_Error, ASD_LogStream_SDK,
                        ASD_LogOption_None, "failed to set IRPost padding");
        }
    }
    else if (cmd == IR_POSTFIX)
    {
        // IR Prefix (A.K.A. IR Postfix in At-Scale Debug Arch. Spec.)
        // irPaddingNearTDO 2 bytes of data

        data = get_packet_data(packet, 2);
        if (data == NULL)
        {
            status = ST_ERR;
            ASD_log(ASD_LogLevel_Error, ASD_LogStream_SDK, ASD_LogOption_None,
                    "Unable to read IRPre data byte");
        }
        else
        {
#ifdef ENABLE_DEBUG_LOGGING
            ASD_log(ASD_LogLevel_Debug, ASD_LogStream_SDK, ASD_LogOption_None,
                    "Setting IRPre padding to %d", (data[1] << 8) | data[0]);
#endif
            status =
                JTAG_set_padding(state->jtag_handler, JTAGPaddingTypes_IRPre,
                                 (data[1] << 8) | data[0]);
            if (status != ST_OK)
                ASD_log(ASD_LogLevel_Error, ASD_LogStream_SDK,
                        ASD_LogOption_None, "failed to set IRPre padding");
        }
    }
    else if (cmd == PRDY_TIMEOUT)
    {
        // PRDY timeout
        // 1 bytes of data

        data = get_packet_data(packet, 1);
        if (data == NULL)
        {
            status = ST_ERR;
            ASD_log(ASD_LogLevel_Error, ASD_LogStream_SDK, ASD_LogOption_None,
                    "Unable to read PRDY_TIMEOUT data byte");
        }
        else
        {
#ifdef ENABLE_DEBUG_LOGGING
            ASD_log(ASD_LogLevel_Debug, ASD_LogStream_SDK, ASD_LogOption_None,
                    "PRDY Timeout config set to %d", data[0]);
#endif
            state->prdy_timeout = data[0];
            status = ST_OK;
        }
    }

    return status;
}