UL data path changes at Phy stub, RLC UL UM and DU APP [Issue-ID: ODUHIGH-262]
[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 "lphy_stub.h"
23 #include "du_log.h"
24
25 uint8_t l1SendUlUserData();
26 uint16_t l1BuildAndSendSlotIndication();
27 pthread_t thread = 0;
28
29 /*******************************************************************
30  *
31  * @brief Generates slot indications
32  *
33  * @details
34  *
35  *    Function : GenerateTicks
36  *
37  *    Functionality: Generates slot indications
38  *
39  * @params[in] 
40  * @return ROK     - success
41  *         RFAILED - failure
42  *
43  * ****************************************************************/
44 void *GenerateTicks(void *arg)
45 {
46    int     milisec = 1;        /* 1ms */
47    struct timespec req = {0};
48
49    req.tv_sec = 0;
50    req.tv_nsec = milisec * 1000000L;
51
52    while(1)
53    {
54       nanosleep(&req, (struct timespec *)NULL);
55       
56       /* Send Slot indication indication to lower mac */
57       l1BuildAndSendSlotIndication();
58    }
59    return((void *)NULLP);
60 }
61
62 /*******************************************************************
63  *
64  * @brief Create/cancel thread for generating slot indication 
65  *
66  * @details
67  *
68  *    Function : l1HdlSlotIndicaion
69  *
70  *    Functionality: Create/cancel thread for generating slot indication
71  *
72  * @params[in] 
73  * @return ROK     - success
74  *         RFAILED - failure
75  *
76  * ****************************************************************/
77 void l1HdlSlotIndicaion(bool stopSlotInd)
78 {
79    int ret;
80
81    if(!stopSlotInd)
82    {
83       ret = pthread_create(&thread, NULL, GenerateTicks, NULL);
84       if(ret)
85       {
86          DU_LOG("\nERROR  -->  PHY_STUB: Unable to create thread");
87       }
88    }
89    else
90    {
91       ret = pthread_cancel(thread);
92       if(ret)
93       {
94          DU_LOG("\nERROR  -->  PHY_STUB: Unable to stop thread");
95       }
96    }
97 }
98
99 /*******************************************************************
100  *
101  * @brief Handles Console input
102  *
103  * @details
104  *
105  *    Function : l1ConsoleHandler
106  *
107  *    Functionality: Handles Console input
108  *
109  * @params[in]
110  * @return ROK     - success
111  *         RFAILED - failure
112  *
113  * ****************************************************************/
114 void *l1ConsoleHandler(void *args)
115 {
116    char ch;
117    while(true)
118    {
119       /* Send UL user data to DU when user enters 'd' on console */
120       if((ch = getchar()) == 'd')
121       {
122          /* Start Pumping data from PHY stub to DU */
123          DU_LOG("\nDEBUG  --> PHY STUB: Sending UL User Data");
124          l1SendUlUserData();
125       }
126    }
127 }
128
129 /*******************************************************************
130  *
131  * @brief Creates thread for handling console input 
132  *
133  * @details
134  *
135  *    Function : l1StartConsoleHandler
136  *
137  *    Functionality: Creates thread for handling console input
138  *
139  * @params[in] 
140  * @return ROK     - success
141  *         RFAILED - failure
142  *
143  * ****************************************************************/
144 void l1StartConsoleHandler()
145 {
146    uint8_t retVal;
147    pthread_t conThrdId;
148    pthread_attr_t attr;
149
150    /* Start thread to receive console input */
151    pthread_attr_init(&attr);
152    pthread_attr_setstacksize(&attr, (size_t)NULLD);
153    pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
154    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
155    retVal = pthread_create(&conThrdId, &attr, l1ConsoleHandler, NULLP);
156    if(retVal != 0)
157    {
158       DU_LOG("\nERROR  -->  PHY STUB : Thread creation failed. Cause %d", retVal);
159    }
160    pthread_attr_destroy(&attr);
161
162 }
163
164 /**********************************************************************
165          End of file
166 **********************************************************************/