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