1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2017-2019] [Radisys] #
5 # Licensed under the Apache License, Version 2.0 (the "License"); #
6 # you may not use this file except in compliance with the License. #
7 # You may obtain a copy of the License at #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
11 # Unless required by applicable law or agreed to in writing, software #
12 # distributed under the License is distributed on an "AS IS" BASIS, #
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
14 # See the License for the specific language governing permissions and #
15 # limitations under the License. #
16 ################################################################################
17 *******************************************************************************/
19 /* This file handles slot indication */
21 #include "common_def.h"
22 #include "phy_stub_utils.h"
25 #include "fapi_vendor_extension.h"
28 #include "mac_sch_interface.h"
30 extern uint16_t l1BuildAndSendBSR(uint8_t ueIdx, BsrType bsrType,\
31 LcgBufferSize lcgBsIdx[MAX_NUM_LOGICAL_CHANNEL_GROUPS]);
34 /*******************************************************************
36 * @brief Generates slot indications
40 * Function : GenerateTicks
42 * Functionality: Generates slot indications
45 * @return ROK - success
48 * ****************************************************************/
52 float milisec = 0.5; /* 0.5ms */
54 float milisec = 1; /* 1ms */
56 struct timespec req = {0};
59 slotIndicationStarted = true;
62 /* Currently the code takes longer that one slot indication to execute.
63 * Hence, multiplying slot time interval by 2 in order to give enough time
64 * for L2 to complete one slot processing.
65 * The ratio must be removed once code optimization is complete */
66 req.tv_nsec = milisec * 1000000L * ratio;
68 DU_LOG("\nPHY_STUB : GenerateTicks : Starting to generate slot indications");
70 while(slotIndicationStarted)
72 clock_nanosleep(CLOCK_REALTIME, 0, &req, NULL);
73 /* Send Slot indication indication to lower mac */
74 if(l1BuildAndSendSlotIndication() != ROK)
76 DU_LOG("\nERROR --> PHY_STUB : GenerateTicks(): Failed to build and send Slot Indication");
81 DU_LOG("\nINFO --> PHY_STUB : Slot indication stopped");
83 /* Initialize all global variables */
86 memset(&ueDb, 0, sizeof(UeDb));
88 /* Send Stop indication to MAC */
90 l1BuildAndSendStopInd();
93 /*******************************************************************
95 * @brief Create/cancel thread for generating slot indication
99 * Function : l1HdlSlotIndicaion
101 * Functionality: Create/cancel thread for generating slot indication
104 * @return ROK - success
107 * ****************************************************************/
108 void l1HdlSlotIndicaion(bool stopSlotInd)
111 Buffer *mBuf = NULLP;
115 DU_LOG("\nPHY_STUB: Sending start slot indication event to self");
116 memset(&pst, 0, sizeof(Pst));
117 FILL_PST_PHY_TO_PHY(pst, EVT_PHY_START_SLOT_IND);
118 ODU_GET_MSG_BUF(pst.region, pst.pool, &mBuf);
119 ODU_POST_TASK(&pst, mBuf);
123 slotIndicationStarted = false;
127 /*******************************************************************
129 * @brief Handles Console input
133 * Function : l1ConsoleHandler
135 * Functionality: Handles Console input
138 * @return ROK - success
141 * ****************************************************************/
142 void *l1ConsoleHandler(void *args)
145 uint8_t drbIdx = 0, lcgIdx = 0, ueIdx = 0;
146 LcgBufferSize lcgBS[MAX_NUM_LOGICAL_CHANNEL_GROUPS];
147 /* The below variable is taken for sending specific number of UL Packets
148 * For sendind 4500 Ul packets for three UEs the calculation of
149 * [counter * NUM_DRB_TO_PUMP_DATA * MAX_NUM_UE * NUM_UL_PACKETS] must be equal to 4500 */
150 uint32_t counter=500;
154 /* Send UL user data to DU when user enters 'd' on console */
160 /* Start Pumping data from PHY stub to DU */
161 for(drbIdx = 0; drbIdx < NUM_DRB_TO_PUMP_DATA; drbIdx++) //Number of DRB times the loop will run
163 for(ueIdx=0; ueIdx<MAX_NUM_UE; ueIdx++)
165 DU_LOG("\nDEBUG --> PHY STUB: Sending UL User Data[DrbId:%d] for UEId %d\n",drbIdx,ueIdx);
166 l1SendUlUserData(drbIdx,ueIdx);
167 /* TODO :- sleep(1) will be removed once we will be able to
168 * send continuous data packet */
177 /* Send Control PDU from PHY stub to DU */
178 DU_LOG("\nDEBUG --> PHY STUB: Sending Status PDU");
183 memset(lcgBS, 0, (MAX_NUM_LOGICAL_CHANNEL_GROUPS * sizeof(LcgBufferSize)));
184 /* Send Control PDU from PHY stub to DU */
186 for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
190 for(lcgIdx = 0; lcgIdx < NUM_DRB_TO_PUMP_DATA; lcgIdx++)
192 lcgBS[lcgIdx].lcgId = MIN_DRB_LCID + lcgIdx;
193 lcgBS[lcgIdx].bsIdx = lcgIdx + 1;
195 l1BuildAndSendBSR(ueIdx, LONG_BSR, lcgBS);
201 lcgBS[lcgIdx].lcgId = MIN_DRB_LCID + lcgIdx;
202 lcgBS[lcgIdx].bsIdx = lcgIdx + 1;
203 l1BuildAndSendBSR(ueIdx, SHORT_BSR, lcgBS);
212 /*******************************************************************
214 * @brief Creates thread for handling console input
218 * Function : l1StartConsoleHandler
220 * Functionality: Creates thread for handling console input
223 * @return ROK - success
226 * ****************************************************************/
227 void l1StartConsoleHandler()
233 /* Start thread to receive console input */
234 pthread_attr_init(&attr);
235 pthread_attr_setstacksize(&attr, (size_t)NULLD);
236 pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
237 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
238 retVal = pthread_create(&conThrdId, &attr, l1ConsoleHandler, NULLP);
241 DU_LOG("\nERROR --> PHY STUB : Thread creation failed. Cause %d", retVal);
243 pthread_attr_destroy(&attr);
247 /**********************************************************************
249 **********************************************************************/