⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 avm_init.c

📁 sti5518 Audio and video memory standard API functions source file
💻 C
📖 第 1 页 / 共 2 页
字号:
/*******************************************************************************
Name        : stavmem_GetPointerOnDeviceNamed
Description : Get the pointer in DeviceArray where a device has been
              initialised with the wanted name, if it exists
Parameters  : the name to look for
Assumptions :
Limitations :
Returns     : the pointer if the name was found, NULL otherwise
*******************************************************************************/
stavmem_Device_t *stavmem_GetPointerOnDeviceNamed(const ST_DeviceName_t WantedName)
{
    S32 DeviceIndex;

    /* Check if device already initialised and return error if not so */
    DeviceIndex = GetIndexOfDeviceNamed(WantedName);
    if (DeviceIndex == INVALID_DEVICE_INDEX)
    {
        /* Device name not found */
        return(NULL);
    }
    else
    {
        /* Device name found */
        return(&DeviceArray[DeviceIndex]);
    }
}


/*
--------------------------------------------------------------------------------
Get revision of the STAVMEM API
--------------------------------------------------------------------------------
*/
ST_Revision_t STAVMEM_GetRevision(void)
{
    static const char Revision[] = "STAVMEM-REL_2.0.6";

    /* Revision string format: STXXX-REL_x.x.x
                                 /       \ \ \__patch release number  }
                            API name      \ \__minor release number  } revision number
                                           \__major release number  }
       Example: STAVMEM-REL_1.0.0 */

    return((ST_Revision_t) Revision);
}


/*
--------------------------------------------------------------------------------
Get capabilities of the STAVMEM API
--------------------------------------------------------------------------------
*/
ST_ErrorCode_t STAVMEM_GetCapability(const ST_DeviceName_t DeviceName, STAVMEM_Capability_t * const Capability_p)
{
    ST_ErrorCode_t Err = ST_NO_ERROR;

    /* Exit now if parameters are bad */
    if ((Capability_p == NULL) ||                       /* Pointer to capability structure should be valid ! */
        (strlen(DeviceName) > ST_MAX_DEVICE_NAME - 1)   /* Device name length should be respected */
       )
    {
        return(ST_ERROR_BAD_PARAMETER);
    }

    /* Check if device already initialised and return error if not so */
    if (stavmem_GetPointerOnDeviceNamed(DeviceName) == NULL)
    {
        /* Device name not found */
        return(ST_ERROR_UNKNOWN_DEVICE);
    }

    /* Fill capability structure */
    Capability_p->MaxPartition = 1;
    Capability_p->FillBlock1DPatternSize = NULL;
    Capability_p->FillBlock2DPatternHeight[0] = 1;
    Capability_p->FillBlock2DPatternHeight[1] = 0;
    Capability_p->FillBlock2DPatternWidth = NULL;

    return(Err);
}


/*
--------------------------------------------------------------------------------
Initialise the STAVMEM API
--------------------------------------------------------------------------------
*/
ST_ErrorCode_t STAVMEM_Init(const ST_DeviceName_t DeviceName, const STAVMEM_InitParams_t * const InitParams_p)
{
    S32 Index = 0;
    ST_ErrorCode_t Err = ST_NO_ERROR;

    /* Exit now if parameters are invalid */
    if ((InitParams_p == NULL) ||                           /* Some init parameters must be specified */
        (InitParams_p->CPUPartition_p == NULL) ||           /* A CPU partition must be specified */
        (InitParams_p->MemoryMapRanges_p == NULL) ||        /* Memory map cannot be empty */
        (!(InitParams_p->NumberOfMemoryMapRanges > 0)) ||   /* At least one range must be specified */
        (!(InitParams_p->MaxPartitions > 0)) ||             /* At least one partition must be allowed */
        (!(InitParams_p->MaxPartitions <= STAVMEM_MAX_MAX_PARTITION)) || /* MaxPartitions is limited */
        (!(InitParams_p->MaxBlocks > 0)) ||                 /* At least one block must be allowed */
        (!(InitParams_p->SDRAMSize >= 16)) ||               /* SDRAM size must not be 0 or too small */
        (strlen(DeviceName) > ST_MAX_DEVICE_NAME - 1)       /* Device name length should be respected */
       )
    {
        return(ST_ERROR_BAD_PARAMETER);
    }

    EnterCriticalSection();

    /* First init: initialise devices and partitions as empty */
    if (!FirstInitDone)
    {
        for (Index = 0; Index < STAVMEM_MAX_DEVICE; Index++)
        {
            DeviceArray[Index].DeviceName[0] = '\0';
        }

        for (Index = 0; Index < STAVMEM_MAX_MAX_PARTITION; Index++)
        {
            PartitionArray[Index].PartitionValidity = ~AVMEM_VALID_PARTITION;
            PartitionArray[Index].PartitionVeryTopBlock_p = NULL;       /* Not to address any block */
            PartitionArray[Index].PartitionVeryBottomBlock_p = NULL;    /* Not to address any block */
        }
        /* Process this only once */
        FirstInitDone = TRUE;
    }

    /* Check if device already initialised and return error if so */
    if (GetIndexOfDeviceNamed(DeviceName) != INVALID_DEVICE_INDEX)
    {
        /* Device name found */
        Err = ST_ERROR_ALREADY_INITIALIZED;
    }
    else
    {
        /* Look for a non-initialised device and return error if none is available*/
        Index = 0;
        while ((DeviceArray[Index].DeviceName[0] != '\0') && (Index < STAVMEM_MAX_DEVICE))
        {
            Index++;
        }
        if (Index >= STAVMEM_MAX_DEVICE)
        {
            /* All devices initialised */
            Err = ST_ERROR_NO_MEMORY;
        }
        else
        {
            /* API specific initialisations */
            Err = Init(&DeviceArray[Index], InitParams_p);

            if (Err == ST_NO_ERROR)
            {
                /* Device available and not already initialised: register device name */
                strcpy(DeviceArray[Index].DeviceName, DeviceName);
                DeviceArray[Index].DeviceName[ST_MAX_DEVICE_NAME - 1] = '\0';

                STTBX_Report((STTBX_REPORT_LEVEL_INFO, "Device '%s' initialised", DeviceArray[Index].DeviceName));
            }
        }
    }

    LeaveCriticalSection();

    return(Err);
}


/*
--------------------------------------------------------------------------------
Terminate the STAVMEM API
--------------------------------------------------------------------------------
*/
ST_ErrorCode_t STAVMEM_Term(const ST_DeviceName_t DeviceName, const STAVMEM_TermParams_t * const TermParams_p)
{
    S32 DeviceIndex = INVALID_DEVICE_INDEX;
    S32 PartitionIndex = 0;
    BOOL FoundPartitions = FALSE;
    STAVMEM_DeletePartitionParams_t DeleteParams;
    STAVMEM_PartitionHandle_t ToBeDeletedPartitionHandle;
    ST_ErrorCode_t Err = ST_NO_ERROR;

    /* Exit now if parameters are bad */
    if ((TermParams_p == NULL) ||                       /* There shoulb be term params */
        (strlen(DeviceName) > ST_MAX_DEVICE_NAME - 1)   /* Device name length should be respected */
       )
    {
        return(ST_ERROR_BAD_PARAMETER);
    }

    EnterCriticalSection();

    if (!FirstInitDone)
    {
        Err = ST_ERROR_UNKNOWN_DEVICE;
    }
    else
    {
        /* Check if device already initialised and return error if NOT so */
        DeviceIndex = GetIndexOfDeviceNamed(DeviceName);
        if (DeviceIndex == INVALID_DEVICE_INDEX)
        {
            /* Device name not found */
            Err = ST_ERROR_UNKNOWN_DEVICE;
        }
        else
        {
            /* Check if there is still created partitions on this device */
            while ((PartitionIndex < STAVMEM_MAX_MAX_PARTITION) && (!FoundPartitions))
            {
                FoundPartitions = ((PartitionArray[PartitionIndex].Device_p == &DeviceArray[DeviceIndex]) && (PartitionArray[PartitionIndex].PartitionValidity == AVMEM_VALID_PARTITION));
                PartitionIndex++;
            }

            if (FoundPartitions)
            {
                /* There's still created partition(s): terminate only if required. */
                if (TermParams_p->ForceTerminate)
                {
                    /* Force terminate required: close all existing partition before terminating */
                    PartitionIndex = 0;
                    DeleteParams.ForceDelete = TRUE;
                    while (PartitionIndex < STAVMEM_MAX_MAX_PARTITION)
                    {
                        if ((PartitionArray[PartitionIndex].Device_p == &DeviceArray[DeviceIndex]) && (PartitionArray[PartitionIndex].PartitionValidity == AVMEM_VALID_PARTITION))
                        {
                            /* Partition is created and belongs to the device: delete it */
                            ToBeDeletedPartitionHandle = (STAVMEM_PartitionHandle_t) &PartitionArray[PartitionIndex];
                            Err = STAVMEM_DeletePartition(DeviceName, &DeleteParams, &ToBeDeletedPartitionHandle);
                            if (Err != ST_NO_ERROR)
                            {
                                /* Problem: this should not happen
                                Fail to terminate ? No because of force */
                                Err = ST_NO_ERROR;
                            }
                        }
                        PartitionIndex++;
                    }
                }
                else
                {
                    /* Not required to delete partitions: return error, cannot terminate */
                    Err = STAVMEM_ERROR_CREATED_PARTITION;
                }
            }

            if (Err == ST_NO_ERROR)
            {
                /* API specific terminations */
                Err = Term(&DeviceArray[DeviceIndex], TermParams_p);

                if (Err == ST_NO_ERROR)
                {
                    /* Device found: desallocate memory, free device */
                    DeviceArray[DeviceIndex].DeviceName[0] = '\0';

                    STTBX_Report((STTBX_REPORT_LEVEL_INFO, "Device '%s' terminated", DeviceName));
                }
            }
        }
    }

    LeaveCriticalSection();

    return(Err);
}


/* End of avm_init.c */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -