Example #1
0
uint32_t osTaskStackWaterMarkGet(UINT32 uwTaskID)
{
    UINT32 uwCount = 0;
    UINT32 *puwTopOfStack;
    UINTPTR uvIntSave;
    LOS_TASK_CB *pstTaskCB = NULL;

    if (uwTaskID > LOSCFG_BASE_CORE_TSK_LIMIT)
    {
        return 0;
    }

    uvIntSave = LOS_IntLock();

    pstTaskCB = OS_TCB_FROM_TID(uwTaskID);
    if (OS_TASK_STATUS_UNUSED & (pstTaskCB->usTaskStatus))
    {
        (VOID)LOS_IntRestore(uvIntSave);
        return 0;
    }

    // first 4 bytes is OS_TASK_MAGIC_WORD, skip
    puwTopOfStack = (UINT32 *)pstTaskCB->uwTopOfStack + 1;

    while (*puwTopOfStack == (UINT32)OS_TASK_STACK_INIT)
    {
        ++puwTopOfStack;
        ++uwCount;
    }

    uwCount *= sizeof(UINT32);

    (VOID)LOS_IntRestore(uvIntSave);
    return uwCount;
}
Example #2
0
/*****************************************************************************
 Function     : LOS_MuxCreate
 Description  : Create a mutex,
 Input        : None
 Output       : puwMuxHandle ------ Mutex operation handle
 Return       : LOS_OK on success ,or error code on failure
 *****************************************************************************/
LITE_OS_SEC_TEXT_INIT  UINT32  LOS_MuxCreate (UINT32 *puwMuxHandle)
{
    UINT32      uwIntSave;
    MUX_CB_S    *pstMuxCreated;
    LOS_DL_LIST *pstUnusedMux;
    UINT32      uwErrNo;
    UINT32      uwErrLine;

    if (NULL == puwMuxHandle)
    {
        return LOS_ERRNO_MUX_PTR_NULL;
    }

    uwIntSave = LOS_IntLock();
    if (LOS_ListEmpty(&g_stUnusedMuxList))
    {
        LOS_IntRestore(uwIntSave);
        OS_GOTO_ERR_HANDLER(LOS_ERRNO_MUX_ALL_BUSY);
    }

    pstUnusedMux                = LOS_DL_LIST_FIRST(&(g_stUnusedMuxList));
    LOS_ListDelete(pstUnusedMux);
    pstMuxCreated               = (GET_MUX_LIST(pstUnusedMux)); /*lint !e413*/
    pstMuxCreated->usMuxCount   = 0;
    pstMuxCreated->ucMuxStat    = OS_MUX_USED;
    pstMuxCreated->usPriority   = 0;
    pstMuxCreated->pstOwner     = (LOS_TASK_CB *)NULL;
    LOS_ListInit(&pstMuxCreated->stMuxList);
    *puwMuxHandle               = (UINT32)pstMuxCreated->ucMuxID;
    LOS_IntRestore(uwIntSave);
    return LOS_OK;
ErrHandler:
    OS_RETURN_ERROR_P2(uwErrLine, uwErrNo);
}
Example #3
0
/*****************************************************************************
 Function     : LOS_MuxDelete
 Description  : Delete a mutex,
 Input        : uwMuxHandle------Mutex operation handle
 Output       : None
 Return       : LOS_OK on success ,or error code on failure
 *****************************************************************************/
LITE_OS_SEC_TEXT_INIT UINT32 LOS_MuxDelete(UINT32 uwMuxHandle)
{
    UINT32    uwIntSave;
    MUX_CB_S *pstMuxDeleted;
    UINT32   uwErrNo;
    UINT32   uwErrLine;

    if (uwMuxHandle >= (UINT32)LOSCFG_BASE_IPC_MUX_LIMIT)
    {
        OS_GOTO_ERR_HANDLER(LOS_ERRNO_MUX_INVALID);
    }

    pstMuxDeleted = GET_MUX(uwMuxHandle);
    uwIntSave = LOS_IntLock();
    if (OS_MUX_UNUSED == pstMuxDeleted->ucMuxStat)
    {
        LOS_IntRestore(uwIntSave);
        OS_GOTO_ERR_HANDLER(LOS_ERRNO_MUX_INVALID);
    }

    if (!LOS_ListEmpty(&pstMuxDeleted->stMuxList) || pstMuxDeleted->usMuxCount)
    {
        LOS_IntRestore(uwIntSave);
        OS_GOTO_ERR_HANDLER(LOS_ERRNO_MUX_PENDED);
    }

    LOS_ListAdd(&g_stUnusedMuxList, &pstMuxDeleted->stMuxList);
    pstMuxDeleted->ucMuxStat = OS_MUX_UNUSED;

    LOS_IntRestore(uwIntSave);

    return LOS_OK;
ErrHandler:
    OS_RETURN_ERROR_P2(uwErrLine, uwErrNo);
}
Example #4
0
/*****************************************************************************
 Function     : LOS_MuxPost
 Description  : Specify the mutex V operation,
 Input        : uwMuxHandle ------ Mutex operation handle,
 Output       : None
 Return       : LOS_OK on success ,or error code on failure
 *****************************************************************************/
LITE_OS_SEC_TEXT UINT32 LOS_MuxPost(UINT32 uwMuxHandle)
{
    UINT32      uwIntSave;
    MUX_CB_S    *pstMuxPosted = GET_MUX(uwMuxHandle);
    LOS_TASK_CB *pstResumedTask;
    LOS_TASK_CB *pstRunTsk;

    uwIntSave = LOS_IntLock();

    if ((uwMuxHandle >= (UINT32)LOSCFG_BASE_IPC_MUX_LIMIT) ||
        (OS_MUX_UNUSED == pstMuxPosted->ucMuxStat))
    {
        LOS_IntRestore(uwIntSave);
        OS_RETURN_ERROR(LOS_ERRNO_MUX_INVALID);
    }

    pstRunTsk = (LOS_TASK_CB *)g_stLosTask.pstRunTask;
    if ((pstMuxPosted->usMuxCount == 0) || (pstMuxPosted->pstOwner != pstRunTsk))
    {
        LOS_IntRestore(uwIntSave);
        OS_RETURN_ERROR(LOS_ERRNO_MUX_INVALID);
    }

    if (--(pstMuxPosted->usMuxCount) != 0)
    {
        LOS_IntRestore(uwIntSave);
        return LOS_OK;
    }

    if ((pstMuxPosted->pstOwner->usPriority) != pstMuxPosted->usPriority)
    {
        osTaskPriModify(pstMuxPosted->pstOwner, pstMuxPosted->usPriority);
    }

    if (!LOS_ListEmpty(&pstMuxPosted->stMuxList))
    {
        pstResumedTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(pstMuxPosted->stMuxList))); /*lint !e413*/

        pstMuxPosted->usMuxCount    = 1;
        pstMuxPosted->pstOwner      = pstResumedTask;
        pstMuxPosted->usPriority    = pstResumedTask->usPriority;
        pstResumedTask->pTaskMux    = NULL;

        osTaskWake(pstResumedTask, OS_TASK_STATUS_PEND);

        (VOID)LOS_IntRestore(uwIntSave);
        LOS_Schedule();
    }
    else
    {
        (VOID)LOS_IntRestore(uwIntSave);
    }

    return LOS_OK;
}
Example #5
0
/*****************************************************************************
Function   : LOS_GetCpuCycle
Description: Get System cycle count
Input   : none
output  : puwCntHi  --- CpuTick High 4 byte
          puwCntLo  --- CpuTick Low 4 byte
return  : none
*****************************************************************************/
LITE_OS_SEC_TEXT_MINOR VOID LOS_GetCpuCycle(UINT32 *puwCntHi, UINT32 *puwCntLo)
{
    UINT64 ullSwTick;
    UINT64 ullCycle;
    UINT32 uwIntSta;
    UINT32 uwHwCycle;
    UINTPTR uwIntSave;

    uwIntSave = LOS_IntLock();

    ullSwTick = g_ullTickCount;

    uwHwCycle = *(volatile UINT32*)OS_SYSTICK_CURRENT_REG;
    uwIntSta  = *(volatile UINT32*)OS_NVIC_INT_CTRL;

    /*tick has come, but may interrupt environment, not counting the Tick interrupt response, to do +1 */
    if (((uwIntSta & 0x4000000) != 0))
    {
        uwHwCycle = *(volatile UINT32*)OS_SYSTICK_CURRENT_REG;
        ullSwTick++;
    }

    ullCycle = (((ullSwTick) * g_uwCyclesPerTick) + (g_uwCyclesPerTick - uwHwCycle));
    *puwCntHi = ullCycle >> 32;
    *puwCntLo = ullCycle & 0xFFFFFFFFU;

    LOS_IntRestore(uwIntSave);

    return;
}
Example #6
0
/*****************************************************************************
Function   : LOS_TickHandler
Description: los system tick handler 
Input   : none
output  : none
return  : none
*****************************************************************************/
void LOS_TickHandler(void)
{
    UINT32 uwIntSave;

    uwIntSave = LOS_IntLock();
    g_vuwIntCount++;
    LOS_IntRestore(uwIntSave);

    osTickHandler();
    
    uwIntSave = LOS_IntLock();
    g_vuwIntCount--;
    LOS_IntRestore(uwIntSave);
    
    return ;
}
Example #7
0
uint32_t osEventFlagsClear (osEventFlagsId_t ef_id, uint32_t flags)
{
    PEVENT_CB_S pstEventCB = (PEVENT_CB_S)ef_id;
    UINTPTR uwIntSave;
    uint32_t rflags;
    UINT32 uwRet;

    if (pstEventCB == NULL)
    {
        return (uint32_t)osFlagsErrorParameter;
    }

    uwIntSave = LOS_IntLock();
    rflags = pstEventCB->uwEventID;

    uwRet = LOS_EventClear(pstEventCB, ~flags);
    LOS_IntRestore(uwIntSave);
    if (uwRet !=  LOS_OK)
    {
        return (uint32_t)osFlagsErrorParameter;
    }
    else
    {
        return rflags;
    }
}
Example #8
0
/*****************************************************************************
 Function : LOS_MemFree
 Description : free the node from memory & if there are free node beside, merger them.
                    at last update "pstListHead' which saved all free node control head
 Input       : pPool --Pointer to memory pool
                  pMem -- the node which need be freed
 Output      : None
 Return      : LOS_OK -Ok,  LOS_NOK -failed
*****************************************************************************/
LITE_OS_SEC_TEXT UINT32 LOS_MemFree(VOID *pPool, VOID *pMem)
{
    UINT32 uwRet = LOS_NOK;
    UINT32 uwGapSize = 0;
    UINTPTR uvIntSave = LOS_IntLock();

    do
    {
        LOS_MEM_DYN_NODE *pstNode = (LOS_MEM_DYN_NODE *)NULL;

        if ((pPool == NULL) || (pMem == NULL))
        {
            break;
        }

        uwGapSize = *((UINT32 *)((UINT32)pMem - 4));
        if (OS_MEM_NODE_GET_ALIGNED_FLAG(uwGapSize))
        {
            uwGapSize = OS_MEM_NODE_GET_ALIGNED_GAPSIZE(uwGapSize);
            pMem = (VOID *)((UINT32)pMem - uwGapSize);
        }

        pstNode = (LOS_MEM_DYN_NODE *)((UINT32)pMem - OS_MEM_NODE_HEAD_SIZE);
        uwRet = osMemCheckUsedNode(pPool, pstNode);
        if (uwRet == LOS_OK)
        {
            osMemFreeNode(pstNode, pPool);
        }

    } while(0);

    LOS_IntRestore(uvIntSave);
    return uwRet;
}
Example #9
0
osStatus_t osEventFlagsDelete (osEventFlagsId_t ef_id)
{
    PEVENT_CB_S pstEventCB = (PEVENT_CB_S)ef_id;
    UINTPTR uwIntSave;
    osStatus_t uwRet;

    uwIntSave = LOS_IntLock();
    if (LOS_EventDestory(pstEventCB) == LOS_OK)
    {
        uwRet = osOK;
    }
    else
    {
        uwRet = osErrorParameter;
    }
    LOS_IntRestore(uwIntSave);

    if (LOS_MemFree(m_aucSysMem0, (void *)pstEventCB) == LOS_OK)
    {
        uwRet = osOK;
    }
    else
    {
        uwRet = osErrorParameter;
    }

    return uwRet;
}
Example #10
0
/*****************************************************************************
Function   : LOS_GetSystickCycle
Description: Get Sys tick cycle count
Input   : none
output  : puwCntHi  --- SysTick count High 4 byte
          puwCntLo  --- SysTick count Low 4 byte
return  : none
*****************************************************************************/
LITE_OS_SEC_TEXT_MINOR VOID LOS_GetSystickCycle(UINT32 *puwCntHi, UINT32 *puwCntLo)
{
    UINT64 ullSwTick;
    UINT64 ullCycle;
    UINT32 uwHwCycle;
    UINTPTR uvIntSave;
    UINT32 uwSystickLoad;
    UINT32 uwSystickCur;

    uvIntSave = LOS_IntLock();

    ullSwTick = g_ullTickCount;

    uwSystickLoad = SysTick->LOAD;
    uwSystickCur = SysTick->VAL;
    uwHwCycle = uwSystickLoad - uwSystickCur;

    /*tick has come, but may interrupt environment, not counting the Tick interrupt response, to do +1 */
    if (((SCB->ICSR & 0x4000000) != 0))
    {
        uwHwCycle = uwSystickLoad - uwSystickCur;
        ullSwTick++;
    }

    ullCycle = uwHwCycle + ullSwTick * uwSystickLoad;
    *puwCntHi = ullCycle >> 32;
    *puwCntLo = ullCycle & 0xFFFFFFFFU;

    LOS_IntRestore(uvIntSave);

    return;
}
Example #11
0
/*****************************************************************************
 Function    : osInterrupt
 Description : Hardware interrupt entry function
 Input       : None
 Output      : None
 Return      : None
 *****************************************************************************/
LITE_OS_SEC_TEXT VOID  osInterrupt(VOID)
{
    UINT32 uwHwiIndex;
    UINT32 uwIntSave;

    uwIntSave = LOS_IntLock();
    g_vuwIntCount++;
    LOS_IntRestore(uwIntSave);

    uwHwiIndex = osIntNumGet();

    if (m_pstHwiSlaveForm[uwHwiIndex] !=0)
    {
        m_pstHwiSlaveForm[uwHwiIndex]();
    }

    uwIntSave = LOS_IntLock();
    g_vuwIntCount--;
    LOS_IntRestore(uwIntSave);
}
Example #12
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;
}
Example #13
0
uint32_t osEventFlagsGet (osEventFlagsId_t ef_id)
{
    PEVENT_CB_S pstEventCB = (PEVENT_CB_S)ef_id;
    UINTPTR uwIntSave;
    uint32_t rflags;

    if (pstEventCB == NULL)
    {
        return (uint32_t)osFlagsErrorParameter;
    }

    uwIntSave = LOS_IntLock();
    rflags = pstEventCB->uwEventID;
    LOS_IntRestore(uwIntSave);

    return rflags;
}
Example #14
0
uint32_t osMessageQueueGetSpace (osMessageQueueId_t mq_id)
{
    uint32_t space;
    UINTPTR uwIntSave;
    QUEUE_CB_S *pstQueue = (QUEUE_CB_S *)mq_id;

    if (pstQueue == NULL)
    {
        space = 0U;
    }
    else
    {
        uwIntSave = LOS_IntLock();
        space = (uint32_t)pstQueue->usReadWriteableCnt[OS_QUEUE_WRITE];
        LOS_IntRestore(uwIntSave);
    }
    return space;
}
Example #15
0
uint32_t osMessageQueueGetCount (osMessageQueueId_t mq_id)
{
    uint32_t count;
    UINTPTR uwIntSave;
    QUEUE_CB_S *pstQueue = (QUEUE_CB_S *)mq_id;

    if (pstQueue == NULL)
    {
        count = 0U;
    }
    else
    {
        uwIntSave = LOS_IntLock();
        count = (uint32_t)(pstQueue->usReadWriteableCnt[OS_QUEUE_READ]);
        LOS_IntRestore(uwIntSave);
    }
    return count;
}
Example #16
0
uint64_t osKernelGetTickCount (void)
{
    uint64_t ticks;
    UINTPTR uvIntSave;

    if(OS_INT_ACTIVE)
    {
        ticks = 0U;
    }
    else
    {
        uvIntSave = LOS_IntLock();
        ticks = g_ullTickCount;
        LOS_IntRestore(uvIntSave);
    }

    return ticks;
}
Example #17
0
/*****************************************************************************
 Function : LOS_MemAllocAlign
 Description : align size then allocate node from Memory pool
 Input       : pPool    --- Pointer to memory pool
                 uwSize  --- Size of memory in bytes to allocate
                 uwBoundary -- align form
 Output      : None
 Return      : Pointer to allocated memory node
*****************************************************************************/
LITE_OS_SEC_TEXT VOID *LOS_MemAllocAlign(VOID *pPool, UINT32 uwSize, UINT32 uwBoundary)
{
    UINT32 uwUseSize = 0;
    UINT32 uwGapSize = 0;
    VOID *pPtr = NULL;
    VOID *pAlignedPtr = NULL;
    UINTPTR uvIntSave = LOS_IntLock();

    do
    {
        if ((pPool == NULL) || (uwSize == 0))
        {
            break;
        }

        uwUseSize = uwSize + uwBoundary + 4; /* 4bytes stores offset between alignedPtr and ptr */

        if (OS_MEM_NODE_GET_USED_FLAG(uwUseSize))
        {
            break;
        }

        pPtr = osMemAllocWithCheck(pPool, uwUseSize);

        pAlignedPtr = (VOID *)OS_MEM_ALIGN(pPtr, uwBoundary);

        if (pPtr == pAlignedPtr)
        {
            break;
        }

        /* store gapSize in address (ptr -4), it will be checked while free */
        uwGapSize = (UINT32)pAlignedPtr - (UINT32)pPtr;
        OS_MEM_NODE_SET_ALIGNED_FLAG(uwGapSize);
        *((UINT32 *)((UINT32)pAlignedPtr - 4)) = uwGapSize;

        pPtr = pAlignedPtr;

    } while (0);

     LOS_IntRestore(uvIntSave);

    return pPtr;
}
Example #18
0
/*****************************************************************************
 Function    : LOS_HwiDelete
 Description : Delete hardware interrupt
 Input       : uwHwiNum   --- hwi num to delete
 Output      : None
 Return      : LOS_OK on success or error code on failure
 *****************************************************************************/
LITE_OS_SEC_TEXT_INIT UINT32 LOS_HwiDelete(HWI_HANDLE_T uwHwiNum)
{
    UINT32 uwIntSave;

    if (uwHwiNum >= OS_M0PLUS_IRQ_VECTOR_CNT)
    {
        return OS_ERRNO_HWI_NUM_INVALID;
    }

    LosAdapIrqDisable(uwHwiNum);

    uwIntSave = LOS_IntLock();

    m_pstHwiForm[uwHwiNum + OS_M0PLUS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)osHwiDefaultHandler;

    LOS_IntRestore(uwIntSave);

    return LOS_OK;
}
Example #19
0
/*****************************************************************************
Function   : LOS_SysTickCurrCycleGet
Description: Get System cycle count
Input   : none
output  : SysTick->VAL
return  : none
*****************************************************************************/
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_SysTickCurrCycleGet(VOID)
{
    UINT32 uwHwCycle;
    UINTPTR uvIntSave;

    uvIntSave = LOS_IntLock();
    uwHwCycle = SysTick->VAL;

    /*tick has come, but may interrupt environment, not counting the Tick interrupt response, to do +1 */
    if (((SCB->ICSR & 0x4000000) != 0))
    {
        uwHwCycle = SysTick->VAL;
        uwHwCycle += g_uwCyclesPerTick;
    }

    LOS_IntRestore(uvIntSave);

    return uwHwCycle;
}
Example #20
0
osThreadId_t osMutexGetOwner (osMutexId_t mutex_id)
{
    UINT32 uwIntSave;
    LOS_TASK_CB *pstTaskCB;

    if (OS_INT_ACTIVE)
    {
        return NULL;
    }

    if (mutex_id == NULL)
    {
        return NULL;
    }

    uwIntSave = LOS_IntLock();
    pstTaskCB = ((MUX_CB_S*)mutex_id)->pstOwner;
    (VOID)LOS_IntRestore(uwIntSave);

    return (osThreadId_t)pstTaskCB;
}
Example #21
0
uint32_t osSemaphoreGetCount (osSemaphoreId_t semaphore_id)
{
    UINT32 uwIntSave;
    UINT32 uwCount;

    if (OS_INT_ACTIVE)
    {
        return 0;
    }

    if (semaphore_id == NULL)
    {
        return 0;
    }

    uwIntSave = LOS_IntLock();
    uwCount = ((SEM_CB_S *)semaphore_id)->usSemCount;
    (VOID)LOS_IntRestore(uwIntSave);

    return uwCount;
}
Example #22
0
/*****************************************************************************
 Function    : LOS_HwiCreate
 Description : create hardware interrupt
 Input       : uwHwiNum   --- hwi num to create
               usHwiPrio  --- priority of the hwi
               usMode     --- unused
               pfnHandler --- hwi handler
               uwArg      --- param of the hwi handler
 Output      : None
 Return      : OS_SUCCESS on success or error code on failure
 *****************************************************************************/
LITE_OS_SEC_TEXT_INIT UINT32 LOS_HwiCreate( HWI_HANDLE_T  uwHwiNum,
                                      HWI_PRIOR_T   usHwiPrio,
                                      HWI_MODE_T    usMode,
                                      HWI_PROC_FUNC pfnHandler,
                                      HWI_ARG_T     uwArg )
{
    UINTPTR uvIntSave;
    (void)usMode;
    (void)uwArg;
    

    if (NULL == pfnHandler)
    {
        return OS_ERRNO_HWI_PROC_FUNC_NULL;
    }
    if (uwHwiNum >= OS_M0PLUS_IRQ_VECTOR_CNT)
    {
        return OS_ERRNO_HWI_NUM_INVALID;
    }
    if (m_pstHwiForm[uwHwiNum + OS_M0PLUS_SYS_VECTOR_CNT] != osHwiDefaultHandler)
    {
        return OS_ERRNO_HWI_ALREADY_CREATED;
    }
    if (usHwiPrio > OS_HWI_PRIO_LOWEST)
    {
        return OS_ERRNO_HWI_PRIO_INVALID;
    }

    uvIntSave = LOS_IntLock();

    osSetVector(uwHwiNum, pfnHandler);

    LosAdapIrpEnable(uwHwiNum, usHwiPrio);

    LOS_IntRestore(uvIntSave);

    return LOS_OK;

}
Example #23
0
/*****************************************************************************
 Function : LOS_MemAlloc
 Description : Allocate node from Memory pool
 Input       : pPool    --- Pointer to memory pool
                 uwSize  --- Size of memory in bytes to allocate
 Output      : None
 Return      : Pointer to allocated memory node
*****************************************************************************/
LITE_OS_SEC_TEXT VOID *LOS_MemAlloc (VOID *pPool, UINT32  uwSize)
{
    VOID *pPtr = NULL;
    UINTPTR uvIntSave = LOS_IntLock();

    do
    {
        if ((pPool == NULL) || (uwSize == 0))
        {
            break;
        }

        if (OS_MEM_NODE_GET_USED_FLAG(uwSize))
        {
            break;
        }

        pPtr = osMemAllocWithCheck(pPool, uwSize);
    } while (0);

    LOS_IntRestore(uvIntSave);
    return pPtr;
}
Example #24
0
/*****************************************************************************
 Function : LOS_MemRealloc
 Description : reAlloc memory node
 Input       : pPool    --- Pointer to memory pool
                  pPtr  --- pointer to memory node which will be realloced
                 uwSize  --- the size of new node
 Output      : None
 Return      : Pointer to allocated memory
*****************************************************************************/
LITE_OS_SEC_TEXT_MINOR VOID *LOS_MemRealloc (VOID *pPool,  VOID *pPtr, UINT32 uwSize)
{
    UINTPTR uvIntSave;
    UINT32 uwGapSize = 0;
    VOID *pNewPtr = NULL;

    uvIntSave = LOS_IntLock();

    do
    {
        LOS_MEM_DYN_NODE *pstNode = (LOS_MEM_DYN_NODE *)NULL;
        UINT32 uwRet;
        UINT32 uwAllocSize;
        UINT32 uwNodeSize;
        LOS_MEM_DYN_NODE *pstNextNode = (LOS_MEM_DYN_NODE *)NULL;

        if (pPtr == NULL)
        {
            pNewPtr = LOS_MemAlloc((VOID *)pPool, (UINT32)uwSize);
            break;
        }

        if (uwSize == 0)
        {
            if (LOS_MemFree((VOID *)pPool, (VOID *)pPtr) != LOS_OK)
                 PRINT_ERR("%s, %d\n", __FUNCTION__, __LINE__);
            break;
        }

        uwGapSize = *((UINT32 *)((UINT32)pPtr - 4));
        if (OS_MEM_NODE_GET_ALIGNED_FLAG(uwGapSize))
        {
            uwGapSize = OS_MEM_NODE_GET_ALIGNED_GAPSIZE(uwGapSize);
            pPtr = (VOID *)((UINT32)pPtr - uwGapSize);
        }
        pstNode = (LOS_MEM_DYN_NODE *)((UINT32)pPtr - OS_MEM_NODE_HEAD_SIZE);
        uwRet = osMemCheckUsedNode(pPool, pstNode);
        if (uwRet != LOS_OK)
        {
            break;
        }

        uwAllocSize = OS_MEM_ALIGN(uwSize + OS_MEM_NODE_HEAD_SIZE, OS_MEM_ALIGN_SIZE);
        uwNodeSize = OS_MEM_NODE_GET_SIZE(pstNode->uwSizeAndFlag);
        if (uwNodeSize >= uwAllocSize)
        {
            osMemReAllocSmaller(pPool, uwAllocSize, pstNode, uwNodeSize);
            pNewPtr = pPtr;
            break;
        }

        pstNextNode = OS_MEM_NEXT_NODE(pstNode);
        if ((!OS_MEM_NODE_GET_USED_FLAG(pstNextNode->uwSizeAndFlag)) &&
            ((pstNextNode->uwSizeAndFlag + uwNodeSize) >= uwAllocSize))
        {
            osMemMergeNodeForReAllocBigger(pPool, uwAllocSize, pstNode, uwNodeSize, pstNextNode);
            pNewPtr = pPtr;
            break;
        }

        pNewPtr = osMemAllocWithCheck(pPool, uwSize);
        if (pNewPtr != NULL)
        {
            (VOID)memcpy(pNewPtr, pPtr, uwNodeSize - OS_MEM_NODE_HEAD_SIZE);
            osMemFreeNode(pstNode, pPool);
        }

    } while (0);

    LOS_IntRestore(uvIntSave);
    return pNewPtr;
}
Example #25
0
/*****************************************************************************
 Function     : LOS_MuxPend
 Description  : Specify the mutex P operation,
 Input        : uwMuxHandle ------ Mutex operation handleone,
 		       uwTimeOut  ------- waiting time,
 Output       : None
 Return       : LOS_OK on success ,or error code on failure
 *****************************************************************************/
LITE_OS_SEC_TEXT UINT32 LOS_MuxPend(UINT32 uwMuxHandle, UINT32 uwTimeout)
{
    UINT32     uwIntSave;
    MUX_CB_S  *pstMuxPended;
    UINT32     uwRetErr;
    LOS_TASK_CB  *pstRunTsk;

    if (uwMuxHandle >= (UINT32)LOSCFG_BASE_IPC_MUX_LIMIT)
    {
        OS_RETURN_ERROR(LOS_ERRNO_MUX_INVALID);
    }

    pstMuxPended = GET_MUX(uwMuxHandle);
    uwIntSave = LOS_IntLock();
    if (OS_MUX_UNUSED == pstMuxPended->ucMuxStat)
    {
        LOS_IntRestore(uwIntSave);
        OS_RETURN_ERROR(LOS_ERRNO_MUX_INVALID);
    }

    if (OS_INT_ACTIVE)
    {
        LOS_IntRestore(uwIntSave);
        return LOS_ERRNO_MUX_PEND_INTERR;
    }

    pstRunTsk = (LOS_TASK_CB *)g_stLosTask.pstRunTask;
    if (pstMuxPended->usMuxCount == 0)
    {
        pstMuxPended->usMuxCount++;
        pstMuxPended->pstOwner = pstRunTsk;
        pstMuxPended->usPriority = pstRunTsk->usPriority;
        LOS_IntRestore(uwIntSave);
        return LOS_OK;
    }

    if (pstMuxPended->pstOwner == pstRunTsk)
    {
        pstMuxPended->usMuxCount++;
        LOS_IntRestore(uwIntSave);
        return LOS_OK;
    }

    if (!uwTimeout)
    {
        LOS_IntRestore(uwIntSave);
        return LOS_ERRNO_MUX_UNAVAILABLE;
    }

    if (g_usLosTaskLock)
    {
        uwRetErr = LOS_ERRNO_MUX_PEND_IN_LOCK;
        PRINT_ERR("!!!LOS_ERRNO_MUX_PEND_IN_LOCK!!!\n");
#if (LOSCFG_PLATFORM_EXC == YES)
        osBackTrace();
#endif
        goto errre_uniMuxPend;
    }

    pstRunTsk->pTaskMux = (VOID *)pstMuxPended;

    if (pstMuxPended->pstOwner->usPriority > pstRunTsk->usPriority)
    {
        osTaskPriModify(pstMuxPended->pstOwner, pstRunTsk->usPriority);
    }

    osTaskWait(&pstMuxPended->stMuxList, OS_TASK_STATUS_PEND, uwTimeout);

    (VOID)LOS_IntRestore(uwIntSave);
    LOS_Schedule();

    if (pstRunTsk->usTaskStatus & OS_TASK_STATUS_TIMEOUT)
    {
        uwIntSave = LOS_IntLock();
        pstRunTsk->usTaskStatus &= (~OS_TASK_STATUS_TIMEOUT);
        (VOID)LOS_IntRestore(uwIntSave);
        uwRetErr = LOS_ERRNO_MUX_TIMEOUT;
        goto error_uniMuxPend;
    }

    return LOS_OK;

errre_uniMuxPend:
    (VOID)LOS_IntRestore(uwIntSave);
error_uniMuxPend:
    OS_RETURN_ERROR(uwRetErr);
}