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 "lphy_stub.h"
25 uint8_t l1SendUlUserData();
26 uint8_t l1SendStatusPdu();
27 uint16_t l1BuildAndSendSlotIndication();
30 /*******************************************************************
32 * @brief Generates slot indications
36 * Function : GenerateTicks
38 * Functionality: Generates slot indications
41 * @return ROK - success
44 * ****************************************************************/
45 void *GenerateTicks(void *arg)
47 int milisec = 1; /* 1ms */
48 struct timespec req = {0};
51 req.tv_nsec = milisec * 1000000L;
55 nanosleep(&req, (struct timespec *)NULL);
57 /* Send Slot indication indication to lower mac */
58 l1BuildAndSendSlotIndication();
60 return((void *)NULLP);
63 /*******************************************************************
65 * @brief Create/cancel thread for generating slot indication
69 * Function : l1HdlSlotIndicaion
71 * Functionality: Create/cancel thread for generating slot indication
74 * @return ROK - success
77 * ****************************************************************/
78 void l1HdlSlotIndicaion(bool stopSlotInd)
84 ret = pthread_create(&thread, NULL, GenerateTicks, NULL);
87 DU_LOG("\nERROR --> PHY_STUB: Unable to create thread");
92 ret = pthread_cancel(thread);
95 DU_LOG("\nERROR --> PHY_STUB: Unable to stop thread");
100 /*******************************************************************
102 * @brief Handles Console input
106 * Function : l1ConsoleHandler
108 * Functionality: Handles Console input
111 * @return ROK - success
114 * ****************************************************************/
115 void *l1ConsoleHandler(void *args)
120 /* Send UL user data to DU when user enters 'd' on console */
121 if((ch = getchar()) == 'd')
123 /* Start Pumping data from PHY stub to DU */
124 DU_LOG("\nDEBUG --> PHY STUB: Sending UL User Data");
127 else if((ch = getchar()) == 'c')
129 /* Send Control PDU from PHY stub to DU */
130 DU_LOG("\nDEBUG --> PHY STUB: Sending Status PDU");
136 /*******************************************************************
138 * @brief Creates thread for handling console input
142 * Function : l1StartConsoleHandler
144 * Functionality: Creates thread for handling console input
147 * @return ROK - success
150 * ****************************************************************/
151 void l1StartConsoleHandler()
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);
165 DU_LOG("\nERROR --> PHY STUB : Thread creation failed. Cause %d", retVal);
167 pthread_attr_destroy(&attr);
171 /**********************************************************************
173 **********************************************************************/