Загрузка данных


int32_t LMM_Init(uint32_t *mSel, uint32_t lmmInitFlags)
{
    int32_t status;
    uint32_t numClock;
    const uint32_t *clockList;

    /* Init LMM system management */
    status = LMM_SystemInit();

    /* Success? */
    if (status == SM_ERR_SUCCESS)
    {
        /* Get LM0 default resource state */
        DEV_SM_LmmInitGet(&numClock, &clockList);

        /* Init LMM clock management */
        status = LMM_ClockInit(numClock, clockList);
    }

    /* Init LMM voltage management */
    if (status == SM_ERR_SUCCESS)
    {
        status = LMM_VoltageInit();
    }

    /* Init LMM CPU management */
    if (status == SM_ERR_SUCCESS)
    {
        status = LMM_CpuInit();
    }

#ifdef USES_FUSA
    /* Init FuSa */
    if (status == SM_ERR_SUCCESS)
    {
        status = LMM_FusaInit(mSel);
    }
#endif

    /* Init LMs */
    if (status == SM_ERR_SUCCESS)
    {
        /* Loop over LMs */
        for (uint32_t lmId = 0U; lmId < SM_NUM_LM; lmId++)
        {
            /* Init RPC */
            switch (g_lmmConfig[lmId].rpcType)
            {
                case SM_RPC_NONE:
                    break;
                case SM_RPC_SCMI:
                    /* Init SCMI instance */
                    status = RPC_SCMI_Init(g_lmmConfig[lmId].rpcInst);
                    break;
                default:
                    status = SM_ERR_INVALID_PARAMETERS;
                    break;
            }

            /* Exit loop on error */
            if (status != SM_ERR_SUCCESS)
            {
                break;
            }
        }
    }

    /* Record init parms */
    s_mSel = *mSel;
    s_lmmInitFlags = lmmInitFlags;

    /* Return status */
    return status;
}

/*--------------------------------------------------------------------------*/
/* Boot logical machines                                                    */
/*                                                                          */
/* Note only call from main(). Cannot be called from an interrupt context.  */
/*--------------------------------------------------------------------------*/
int32_t LMM_Boot(void)
{
    int32_t status;
    uint32_t mSel = s_mSel;
    uint32_t lmmInitFlags = s_lmmInitFlags;

    /* Default out of range mSel */
    if (mSel >= SM_LM_NUM_MSEL)
    {
        mSel = 0U;
    }

    /* Inform LM system of mode select */
    status = LMM_SystemModeSelSet(mSel);

    /* Get starting system counter */
    uint64_t startTime = DEV_SM_Usec64Get();

    /* Boot LMs */
    if ((status == SM_ERR_SUCCESS)
        && ((lmmInitFlags & LM_INIT_FLAGS_BOOT) != 0U))
    {
        /* Loop over boot order */
        for (uint8_t bootOrder = 1U; bootOrder <= SM_NUM_LM; bootOrder++)
        {
            /* Loop over LMs */
            for (uint32_t lmId = 0U; lmId < SM_NUM_LM; lmId++)
            {
                /* Boot if LM requested in this order */
                if (g_lmmConfig[lmId].boot[mSel] == bootOrder)
                {
                    uint64_t bootTime = startTime
                        + ((uint64_t) g_lmmConfig[lmId].rtime);

                    /* Wait until start time */
                    while (DEV_SM_Usec64Get() < bootTime)
                    {
                        ; /* Intentional empty while */
                    }

                    /* Record calling parms */
                    s_bootLm = lmId;
                    s_bootSkip = g_lmmConfig[lmId].bootSkip[mSel];

                    /* Trigger SWI handler */
                    SWI_Trigger();

                    /* Collect status */
                    status = s_bootStatus;
                }

                /* Exit loop on error */
                if (status != SM_ERR_SUCCESS)
                {
                    break;
                }
            }

            /* Exit loop on error */
            if (status != SM_ERR_SUCCESS)
            {
                break;
            }
        }
    }

    /* Return status */
    return status;
}

/*--------------------------------------------------------------------------*/
/* Post-boot clean-up                                                       */
/*                                                                          */
/* Run any clean-up required after starting all LM                          */
/*--------------------------------------------------------------------------*/
int32_t LMM_PostBoot(void)
{
    uint32_t lmmInitFlags = s_lmmInitFlags;

    /* Just passthru to board/device */
    return SM_SYSTEMPOSTBOOT(s_mSel, lmmInitFlags);
}