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