29a4b0100fe8a99287ba67e96146e6f67ea1f01f
[o-du/l2.git] / src / phy_stub / phy_stub_thread_hdl.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
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                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
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 *******************************************************************************/
18
19 /* This file handles slot indication */
20
21 #include "common_def.h"
22 #include "phy_stub_utils.h"
23 #ifdef INTEL_FAPI
24 #include "fapi.h"
25 #include "fapi_vendor_extension.h"
26 #endif
27 #include "phy_stub.h"
28
29 uint8_t l1SendUlUserData();
30 uint8_t l1SendStatusPdu();
31 uint16_t l1BuildAndSendSlotIndication();
32 pthread_t thread = 0;
33
34 /*******************************************************************
35  *
36  * @brief Generates slot indications
37  *
38  * @details
39  *
40  *    Function : GenerateTicks
41  *
42  *    Functionality: Generates slot indications
43  *
44  * @params[in] 
45  * @return ROK     - success
46  *         RFAILED - failure
47  *
48  * ****************************************************************/
49 void GenerateTicks()
50 {
51 #ifdef NR_TDD
52    int     milisec = 0.5;        /* 0.5ms */
53 #else
54    int     milisec = 1;          /* 1ms */
55 #endif
56    struct timespec req = {0};
57
58    slotIndicationStarted = true;
59    req.tv_sec = 0;
60    req.tv_nsec = milisec * 1000000L;
61
62    DU_LOG("\nPHY_STUB : GenerateTicks : Starting to generate slot indications");
63
64    while(slotIndicationStarted)
65    {
66       clock_nanosleep(CLOCK_REALTIME, 0, &req, NULL); 
67       /* Send Slot indication indication to lower mac */
68       l1BuildAndSendSlotIndication();
69    }
70
71    DU_LOG("\nINFO  --> PHY_STUB : Slot indication stopped");
72
73    /* Initialize all global variables */
74    sfnValue = 0;
75    slotValue = 0;
76    rachIndSent = false;
77    msg3Sent = false;
78    msg5ShortBsrSent = false;
79    msg5Sent = false;
80    dlDedMsg = false;
81    msgSecurityModeComp =  false;
82    msgRrcReconfiguration  =  false;
83    msgRegistrationComp    = false;
84
85    /* Send Stop indication to MAC */
86    sleep(1);
87    l1BuildAndSendStopInd();
88 }
89
90 /*******************************************************************
91  *
92  * @brief Create/cancel thread for generating slot indication 
93  *
94  * @details
95  *
96  *    Function : l1HdlSlotIndicaion
97  *
98  *    Functionality: Create/cancel thread for generating slot indication
99  *
100  * @params[in] 
101  * @return ROK     - success
102  *         RFAILED - failure
103  *
104  * ****************************************************************/
105 void l1HdlSlotIndicaion(bool stopSlotInd)
106 {
107    Pst pst;
108    int ret;
109    Buffer *mBuf = NULLP;
110
111    if(!stopSlotInd)
112    {
113       DU_LOG("\nPHY_STUB: Sending start slot indication event to self");
114       memset(&pst, 0, sizeof(Pst));
115       FILL_PST_PHY_TO_PHY(pst, EVT_PHY_START_SLOT_IND);
116       ODU_GET_MSG_BUF(pst.region, pst.pool, &mBuf);
117       ODU_POST_TASK(&pst, mBuf);
118    }
119    else
120    {
121       slotIndicationStarted = false;
122    }
123 }
124
125 /*******************************************************************
126  *
127  * @brief Handles Console input
128  *
129  * @details
130  *
131  *    Function : l1ConsoleHandler
132  *
133  *    Functionality: Handles Console input
134  *
135  * @params[in]
136  * @return ROK     - success
137  *         RFAILED - failure
138  *
139  * ****************************************************************/
140 void *l1ConsoleHandler(void *args)
141 {
142    char ch;
143    while(true)
144    {
145       /* Send UL user data to DU when user enters 'd' on console */
146       if((ch = getchar()) == 'd')
147       {
148          /* Start Pumping data from PHY stub to DU */
149          DU_LOG("\nDEBUG  --> PHY STUB: Sending UL User Data");
150          l1SendUlUserData();
151       }
152       else if((ch = getchar()) == 'c')
153       {
154          /* Send Control PDU from PHY stub to DU */
155          DU_LOG("\nDEBUG  --> PHY STUB: Sending Status PDU");
156          l1SendStatusPdu();
157       }
158    }
159 }
160
161 /*******************************************************************
162  *
163  * @brief Creates thread for handling console input 
164  *
165  * @details
166  *
167  *    Function : l1StartConsoleHandler
168  *
169  *    Functionality: Creates thread for handling console input
170  *
171  * @params[in] 
172  * @return ROK     - success
173  *         RFAILED - failure
174  *
175  * ****************************************************************/
176 void l1StartConsoleHandler()
177 {
178    uint8_t retVal;
179    pthread_t conThrdId;
180    pthread_attr_t attr;
181
182    /* Start thread to receive console input */
183    pthread_attr_init(&attr);
184    pthread_attr_setstacksize(&attr, (size_t)NULLD);
185    pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
186    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
187    retVal = pthread_create(&conThrdId, &attr, l1ConsoleHandler, NULLP);
188    if(retVal != 0)
189    {
190       DU_LOG("\nERROR  -->  PHY STUB : Thread creation failed. Cause %d", retVal);
191    }
192    pthread_attr_destroy(&attr);
193
194 }
195
196 /**********************************************************************
197          End of file
198 **********************************************************************/