예제 #1
0
파일: los_mux.c 프로젝트: noleaf315/LiteOS
/*****************************************************************************
 Funtion	     : osMuxInit,
 Description  : Initializes the mutex,
 Input        : None
 Output       : None
 Return       : LOS_OK on success ,or error code on failure
 *****************************************************************************/
LITE_OS_SEC_TEXT_INIT UINT32 osMuxInit(VOID)
{
    MUX_CB_S *pstMuxNode;
    UINT32   uwIndex;

    LOS_ListInit(&g_stUnusedMuxList);

    if (LOSCFG_BASE_IPC_MUX_LIMIT == 0)   /*lint !e506*/
    {
        return LOS_ERRNO_MUX_MAXNUM_ZERO;
    }

    g_pstAllMux = (MUX_CB_S *)LOS_MemAlloc(m_aucSysMem0, (LOSCFG_BASE_IPC_MUX_LIMIT * sizeof(MUX_CB_S)));
    if (NULL == g_pstAllMux)
    {
        return LOS_ERRNO_MUX_NO_MEMORY;
    }

    for (uwIndex = 0; uwIndex < LOSCFG_BASE_IPC_MUX_LIMIT; uwIndex++)
    {
        pstMuxNode              = ((MUX_CB_S *)g_pstAllMux) + uwIndex;
        pstMuxNode->ucMuxID     = uwIndex;
        pstMuxNode->ucMuxStat   = OS_MUX_UNUSED;
        LOS_ListTailInsert(&g_stUnusedMuxList, &pstMuxNode->stMuxList);
    }
    return LOS_OK;
}
예제 #2
0
/*****************************************************************************
 Function : LOS_MemInit
 Description : Initialize Dynamic Memory pool
 Input       : pPool    --- Pointer to memory pool
                 uwSize  --- Size of memory in bytes to allocate
 Output      : None
 Return      : LOS_OK - Ok, OS_ERROR - Error
*****************************************************************************/
LITE_OS_SEC_TEXT_INIT UINT32 LOS_MemInit(VOID *pPool, UINT32  uwSize)
{
    LOS_MEM_DYN_NODE *pstNewNode = (LOS_MEM_DYN_NODE *)NULL;
    LOS_MEM_DYN_NODE *pstEndNode = (LOS_MEM_DYN_NODE *)NULL;
    LOS_MEM_POOL_INFO *pstPoolInfo = (LOS_MEM_POOL_INFO *)NULL;
    UINTPTR uvIntSave;
    LOS_DL_LIST *pstListHead = (LOS_DL_LIST *)NULL;

    if ((pPool == NULL) || (uwSize < (OS_MEM_MIN_POOL_SIZE)))
    {
        return OS_ERROR;
    }

    uvIntSave = LOS_IntLock();

    pstPoolInfo = (LOS_MEM_POOL_INFO *)pPool;
    pstPoolInfo->pPoolAddr = pPool;
    pstPoolInfo->uwPoolSize = uwSize;
    LOS_DLnkInitMultiHead(OS_MEM_HEAD_ADDR(pPool));
    pstNewNode = OS_MEM_FIRST_NODE(pPool);
    pstNewNode->uwSizeAndFlag = ((uwSize - ((UINT32)pstNewNode - (UINT32)pPool)) - OS_MEM_NODE_HEAD_SIZE);
    pstNewNode->pstPreNode = (LOS_MEM_DYN_NODE *)NULL;
    pstListHead = OS_MEM_HEAD(pPool, pstNewNode->uwSizeAndFlag);
    if (NULL == pstListHead)
    {
        PRINT_ERR("%s %d\n", __FUNCTION__, __LINE__);
        LOS_IntRestore(uvIntSave);
        return OS_ERROR;
    }

    LOS_ListTailInsert(pstListHead,&(pstNewNode->stFreeNodeInfo));
    pstEndNode = (LOS_MEM_DYN_NODE *)OS_MEM_END_NODE(pPool, uwSize);
    (VOID)memset(pstEndNode, 0 ,sizeof(*pstEndNode));
    pstEndNode->pstPreNode = pstNewNode;
    pstEndNode->uwSizeAndFlag = OS_MEM_NODE_HEAD_SIZE;
    OS_MEM_NODE_SET_USED_FLAG(pstEndNode->uwSizeAndFlag);
    osMemSetMagicNumAndTaskid(pstEndNode);
    LOS_IntRestore(uvIntSave);

    return LOS_OK;
}