Epic-ID: ODUHIGH-463][Task-ID: ODUHIGH-504]Dummy Handover Request/Response and UE...
[o-du/l2.git] / src / cm / common_def.c
index 5071b7b..4b974c3 100644 (file)
 
 #include "common_def.h"
 
+/*Spec 38.104, Table 5.4.2.1-1 ARFCN - FREQ mapping*/
+/*{  F_REF(Mhz), ΔF_Global, F_REF-Offs, N_REF-offs, Range of N_REF }*/
+uint32_t arfcnFreqTable[3][5] = {
+  {   3000,   5,         0,        0,   599999 }, /*index 0*/
+  {  24250,  15,      3000,   600000,  2016666 }, /*index 1*/
+  { 100000,  60,  24250.08,  2016667,  3279165 }, /*index 2*/
+};
+
 /**
  * @brief frequency domain allocation function. 
  *
@@ -220,11 +228,11 @@ uint8_t convertScsValToScsEnum(uint32_t num)
 }
 
 /*******************************************************************
- * @brief convert scs periodicity value into the enum value received from O1 
+ * @brief convert SSB periodicity value into the enum value received from O1 
  *
  * @details
  *
- *    Function : convertScsPeriodicityToEnum
+ *    Function : convertSSBPeriodicityToEnum
  *
  *    Functionality:
  *       - convert scs periodicity value 
@@ -234,30 +242,30 @@ uint8_t convertScsValToScsEnum(uint32_t num)
  *         RFAILED - failure
  *
  * ****************************************************************/
-uint8_t convertScsPeriodicityToEnum(uint32_t num)
+uint8_t convertSSBPeriodicityToEnum(uint32_t num)
 {
    switch(num)
    {
       case 5:
-         return SCS_5MS;
+         return SSB_5MS;
 
       case 10:
-         return SCS_10MS;
+         return SSB_10MS;
 
       case 20:
-         return SCS_20MS;
+         return SSB_20MS;
 
       case 40:
-         return SCS_40MS;
+         return SSB_40MS;
 
       case 80:
-         return SCS_80MS;
+         return SSB_80MS;
 
       case 160:
-         return SCS_160MS;
+         return SSB_160MS;
 
       default:
-         return SCS_5MS;
+         return SSB_5MS;
    }
 }
 /*******************************************************************
@@ -283,7 +291,7 @@ uint8_t SGetSBufNewForDebug(char *file, const char *func, int line, Region regio
 #ifdef ODU_MEMORY_DEBUG_LOG
       if (strncmp(func,"cmInetRecvMsg",sizeof("cmInetRecvMsg")))
       {
-         printf("\nCM_ALLOC=== SGetSBufNewForDebug %s +%d, %s, %d, %p",\
+         printf("\nCM,ALLOC,=== SGetSBufNewForDebug %s +%d, %s, %d, %p \n",\
          file, line, func, size, *ptr);
       }
 #endif
@@ -316,7 +324,7 @@ uint8_t SPutSBufNewForDebug(char *file, const char *func, int line, Region regio
 #ifdef ODU_MEMORY_DEBUG_LOG
       if (strncmp(func,"cmInetRecvMsg",sizeof("cmInetRecvMsg")))
       {
-         printf("\nCM_FREE=== SPutSBufNewForDebug %s +%d, %s, %d, %p",\
+         printf("\nCM,FREE,=== SPutSBufNewForDebug %s +%d, %s, %d, %p \n",\
          file, line, func, size, ptr);
       }
 #endif
@@ -349,7 +357,7 @@ Region region, Pool pool, Data **ptr, Size size, uint8_t memType)
    if(SGetStaticBuffer(region, pool, ptr, size, memType) == ROK)
    {
 #ifdef ODU_MEMORY_DEBUG_LOG
-      printf("\nCM_ALLOC=== SGetStaticBufNewForDebug %s +%d, %s, %d, %p",\
+      printf("\nCM,ALLOC,=== SGetStaticBufNewForDebug %s +%d, %s, %d, %p \n",\
          file, line, func, size, *ptr);
 #endif
       return ROK;
@@ -380,7 +388,7 @@ Region region, Pool pool, Data *ptr, Size size, uint8_t memType)
    if(SPutStaticBuffer(region, pool, ptr, size, memType) == ROK)
    {
 #ifdef ODU_MEMORY_DEBUG_LOG
-      printf("\nCM_FREE=== SPutStaticBufNewForDebug %s +%d, %s, %d, %p",\
+      printf("\nCM,FREE,=== SPutStaticBufNewForDebug %s +%d, %s, %d, %p \n",\
          file, line, func, size, ptr);
 #endif
       return ROK;
@@ -417,6 +425,75 @@ uint8_t countSetBits(uint32_t num)
    return(count);
 }
 
+/*******************************************************************
+*
+* @brief  convert ARFCN to freq in kHZ
+*
+* @details
+*
+*    Function : convertArfcnToFreqKhz
+*
+*    Functionality: convert ARFCN to freq in kHZ as per Table below
+*                  3GPP TS 38.104, Table 5.4.2.1-1
+*       Formula: F_REF = F_REF-Offs + ΔF_Global (N_REF – N_REF-Offs)
+*
+* @params[in] uint32_t number
+*
+* @return [out] uint32_t Freq in kHZ
+*
+* ****************************************************************/
+uint32_t convertArfcnToFreqKhz(uint32_t arfcn)
+{
+   uint8_t indexTable = 0;
+   uint32_t freq = 0;
+
+   for(indexTable = 0; indexTable < 3; indexTable++)
+   {
+      if(arfcn <= arfcnFreqTable[indexTable][4])
+      {
+         freq = (arfcnFreqTable[indexTable][2] * 1000) + (arfcnFreqTable[indexTable][1] * (arfcn - arfcnFreqTable[indexTable][3]));
+         return (freq);
+      }
+   }
+   DU_LOG("ERROR  -->  DUAPP: ARFCN vaid range is between 0 and 3279165");
+   return (freq);
+}
+
+
+/*******************************************************************
+*
+* @brief  convert Freq(MHZ) to ARFCN
+*
+* @details
+*
+*    Function : convertFreqToArfcn
+*
+*    Functionality: convert freq to ARFCN as per Table below
+*                  3GPP TS 38.104, Table 5.4.2.1-1
+*       Formula: NREF = NREF-Offs +  (FREF – FREF-Offs) / ΔFGlobal
+*
+* @params[in] uint32_t Freq(kHZ)
+*
+* @return [out] uint32_t ARFCN(number)
+*
+* ****************************************************************/
+uint32_t convertFreqToArfcn(uint32_t freq)
+{
+   uint8_t indexTable = 0;
+   uint32_t arfcn = 0;
+
+   for(indexTable = 0; indexTable < 3; indexTable++)
+   {
+      if(freq < (arfcnFreqTable[indexTable][0] * 1000))
+      {
+         arfcn = arfcnFreqTable[indexTable][3] + ((freq - (arfcnFreqTable[indexTable][2] * 1000)) / (arfcnFreqTable[indexTable][1]));
+         return (arfcn);
+      }
+   }
+   DU_LOG("ERROR  -->  DUAPP: FREQ vaid range is between 0 and 100000 MHz");
+   return (arfcn);
+}
+
 /**********************************************************************
          End of file
 **********************************************************************/