// +FHDR------------------------------------------------------------
//                 Copyright (c) 2022 SmartLogic.
//                       ALL RIGHTS RESERVED
// -----------------------------------------------------------------
// Filename      : ucp_utility.c
// Author        : xianfeng.du
// Created On    : 2022-06-25
// Last Modified :
// -----------------------------------------------------------------
// Description:
//
//
// -FHDR------------------------------------------------------------

#include "typedef.h"
#include "mem_sections.h"
#include "ucp_utility.h"
#include "ospHeap.h"

#ifdef UCP_SPIN_LOCK
pthread_spinlock_t lock_dl_tx_alloc;
pthread_spinlock_t lock_dl_tx_put;
void ucp_spinlock_init()
{
	pthread_spin_init((pthread_spinlock_t *)&lock_dl_tx_alloc,PTHREAD_PROCESS_PRIVATE);//PTHREAD_PROCESS_SHARED 
	pthread_spin_init((pthread_spinlock_t *)&lock_dl_tx_put,PTHREAD_PROCESS_PRIVATE);// 
	return;
}
#else
void ucp_spinlock_init()
{
	return;
}
#endif

int32_t isPowerOf2(uint32_t n)
{
    return n && !(n & (n - 1));
}

void ucp_cache_writeback(uint8_t* buf, uint32_t length)
{
#ifdef CACHE_ENABLE	
    osp_clean_dcache_area((void*)buf, length);
#endif	
    return;
}

void ucp_cache_invalid(uint8_t* buf, uint32_t length)
{
#ifdef CACHE_ENABLE
    osp_invalid_dcache_area(ARM_APE_MSG,(uint64_t)buf,length);
#endif
    return;
}

void ucp_cache_flush(uint8_t* buf, uint32_t length)
{
#ifdef CACHE_ENABLE
	osp_flush_dcache_area((void*)buf, length);
#endif
    return;
}


