Example #1
0
/*
 *  ======== IRESMAN_HDVICP_init ========
 * Function to initialize the device specific resource manager implementation
 */
IRES_Status IRESMAN_HDVICP_init(IRESMAN_Params * initArgs)
{
    IRESMAN_HdVicpParams * resmanArgs = (IRESMAN_HdVicpParams *)initArgs;
    Registry_Result result;

    if (!regInit) {
        /*
         *  Enable logging. We only want to do this once, since there is
         *  no Registry_removeModule().
         */
        result = Registry_addModule(&ti_sdo_fc_ires_hdvicp_desc,
                HDVICP_MODNAME);

        Assert_isTrue(result == Registry_SUCCESS, (Assert_Id)NULL);

        if (result == Registry_SUCCESS) {
            /* Set the diags mask to the FC default */
            FCSettings_init();
            FCSettings_setDiags(HDVICP_MODNAME);
        }
        regInit = 1;
    }

    Log_print1(Diags_ENTRY, "[+E] IRESMAN_HDVICP_init> Enter (initArgs=0x%x)",
            (IArg)initArgs);

    Assert_isTrue(initArgs != NULL, (Assert_Id)NULL);

    /* Check if already initialized */
    if (_initialized) {
       Log_print0(Diags_EXIT,
               "[+X] IRESMAN_HDVICP_init> Exit (status=IRES_EEXISTS)");

       return (IRES_EEXISTS);
    }

    /*
     * Information regarding the memory allocation/free functions
     * is stored as part of the internal state of the resource
     * manager
     */
    allocFxn = resmanArgs->baseConfig.allocFxn;
    freeFxn = resmanArgs->baseConfig.freeFxn;

#ifdef xdc_target__os_Linux
    if (gate == NULL) {
        OsalSupport_createGate(_HDVICP_ipcKeyBase);
    }
    if (gate == NULL) {
        Log_print0(Diags_USER7,
                "[+7] IRESMAN_VICP2_init> Failed to create gate");

        Log_print0(Diags_EXIT,
                "[+X] IRESMAN_VICP2_init> Exit (status=IRES_EFAIL)");

        return (IRES_EFAIL);
    }
#endif

    getInternalState();

    if ((NULL == _resmanInternalState) ||
            (_resmanInternalState->sharedMemId == -1)) {

        Log_print0(Diags_USER7,
                "[+7] IRESMAN_VICP2_init> Failed to obtain Internal state "
                "Object");

        Log_print0(Diags_EXIT,
                "[+X] IRESMAN_VICP2_init> Exit (status=IRES_EFAIL)");

        return (IRES_EFAIL);
    }

    _resmanInternalState->numOpens++;

    if (sizeof(IRESMAN_Params) == resmanArgs->baseConfig.size) {
        _resmanInternalState->numResources = _HDVICP_NUMRESOURCES;
    }
    else {
        _resmanInternalState->numResources = resmanArgs->numResources;
    }

    Assert_isTrue(
            _resmanInternalState->numResources <= IRES_HDVICP_MAXRESOURCES,
            (Assert_Id)NULL);

    /* Set Initalized flag to 1 if successful */
     _initialized = 1;

     Log_print0(Diags_EXIT, "[+X] IRESMAN_HDVICP_init> Exit (status=IRES_OK)");

     return (IRES_OK);
}
/*
 *  ======== RMAN_init ========
 *  Initialize the RMAN object with static information from the headers/
 *  configuration etc. This function has to return successfully before the
 *  other APIs can be called
 */
IRES_Status RMAN_init()
{
    Int             i = 0;
    IRES_Status     status;
    IRESMAN_Params  nullParams;
    Registry_Result regResult;


    /*
     *  Register the module name for logging only once. Do this before any
     *  Log functions are called.
     */
    if (regInit == 0) {
        regResult = Registry_addModule(&ti_sdo_fc_rman_desc, RMAN_MODNAME);

        Assert_isTrue(regResult == Registry_SUCCESS, (Assert_Id)NULL);

        /* Set diags mask to FC default */
        FCSettings_init();
        FCSettings_setDiags(RMAN_MODNAME);
        regInit = 1;
    }

    /* Ensure it is called/initialized at least once */
    if (rmanInit++) {
        Log_print0(Diags_ENTRY, "[+E] RMAN_init> Enter");
        Log_print0(Diags_EXIT, "[+X] RMAN_init> Exit (status=IRES_OK)");

        /* TODO: Return IRES_OK even if RMAN_init() failed earlier? */
        return (IRES_OK);
    }

    Log_print0(Diags_ENTRY, "[+E] RMAN_init> Enter");

    if ((NULL == RMAN_PARAMS.allocFxn) || (NULL == RMAN_PARAMS.freeFxn)) {
        Log_print0(Diags_USER7, "[+7] RMAN_init> RMAN_PARAMS not "
                "configured with allocFxn and freeFxn functions");

        initStatus = IRES_ENOMEM;
    }
    else {
        /* Set initStatus to IRES_OK so RMAN_register() can succeed. */
        initStatus = IRES_OK;
    }

    if (initStatus == IRES_OK) {
        /* Create a lock for protecting RMAN_data object */
        gate = OsalSupport_createGate(ti_sdo_fc_rman_RMAN_ipcKey);

        if (gate == NULL) {
            Log_print1(Diags_USER7,
                    "[+7] RMAN_init> Failed to create IPC gate, key = 0x%x",
                    ti_sdo_fc_rman_RMAN_ipcKey);

            initStatus = IRES_ENOMEM;
        }
    }

    if (initStatus == IRES_OK) {
        /*
         *  Register the NULL resource.
         */
        resTable.tableSize = RMAN_PARAMS.numRegistries;

        /* Initialize the registry table and the free index table */
        for (i = 0; i < resTable.tableSize; i++) {
            RMAN_TABLE[i] = NULL;
            RMAN_FREE_ENTRIES[i] = 0;
        }

        resTable.tableIndex = 0;
        resTable.freeIndex = -1;

        /* First pre-register the NULL resource */
        nullParams.allocFxn = RMAN_PARAMS.allocFxn;
        nullParams.freeFxn = RMAN_PARAMS.freeFxn;
        nullParams.size = sizeof(IRESMAN_Params);

        status = RMAN_register(&IRESMAN_NULLRES, &nullParams);
        if (status != IRES_OK) {
            Log_print1(Diags_USER7, "[+7] RMAN_init> Register failed "
                    "on NULL IRESMAN implementation: %d", (IArg)status);
            initStatus = status;
        }
    }

    if (initStatus == IRES_OK) {
        /*
         *  In this function, we can populate the RMAN_registryEntries,
         *  RMAN_registeryResmanArgs and fix RMAN_numRegistryEntries
         */
        initStatus = RMAN_autoRegister();
    }

    /*
     * Static registration of Resource Registry entries
     */
    if ((initStatus == IRES_OK) && (RMAN_registryEntries != NULL)) {

        Assert_isTrue(RMAN_numRegistryEntries < resTable.tableSize,
                (Assert_Id)NULL);
        Log_print0(Diags_USER2, "[+2] RMAN_init> Registering statically "
                "added resources");
        /*
         *  Copy the entries from the static configuration into the resource
         *  table.
         */
        for (i = 0; i < RMAN_numRegistryEntries; i++) {

            status = RMAN_register(RMAN_registryEntries[i],
                    RMAN_registryResmanArgs[i]);

            if (status != IRES_OK) {
                Log_print2(Diags_USER7, "[+7] RMAN_init> Register failed on "
                        "IRESMAN implementation 0x%x, status: %d",
                        (IArg)(RMAN_registryEntries[i]), (IArg)status);

                initStatus = status;
                break;
            }
        }
    }

    getInternalState();

    if (NULL == rmanInternalState) {
        initStatus = IRES_EFAIL;
    }

    Log_print1(Diags_EXIT, "[+X] RMAN_init> Exit (status=%d)",
            (IArg)initStatus);

    return (initStatus);
}