ceca4ebde8b98342ec1f1b1f4f72d95fa43423d9
[o-du/l2.git] / src / du_app / du_mgr_main.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 is the entry point for DU APP */
20
21 #include "du_mgr_main.h"
22 #include "du_sctp.h"
23
24 extern S16 kwUlActvTsk (Pst *, Buffer *);
25 extern S16 kwUlActvInit (Ent, Inst, Region, Reason);
26 extern S16 kwDlActvTsk (Pst *, Buffer *);
27 extern S16 kwDlActvInit (Ent, Inst, Region, Reason);
28 extern S16 rgActvTsk (Pst *, Buffer *);
29 extern S16 rgActvInit (Ent, Inst, Region, Reason);
30
31 /*******************************************************************
32  *
33  * @brief Initializes DU APP
34  *
35  * @details
36  *
37  *    Function : duAppInit
38  *
39  *    Functionality:
40  *       - Registers and attaches TAPA tasks belonging to 
41  *         DU_APP sys task
42  *
43  * @params[in] system task ID
44  * @return ROK     - success
45  *         RFAILED - failure
46  *
47  * ****************************************************************/
48 S16 duAppInit(SSTskId sysTskId)
49 {
50    /* Register DU APP TAPA Task for DU */
51    if(SRegTTsk((Ent)ENTDUAPP, (Inst)DU_INST, (Ttype)TTNORM, (Prior)PRIOR0,
52             duActvInit, (ActvTsk)duActvTsk) != ROK)
53    {
54       return RFAILED;
55    }
56    /* Attach DU APP TAPA Task for DU */
57    if (SAttachTTsk((Ent)ENTDUAPP, (Inst)0, sysTskId)!= ROK)
58    {
59       return RFAILED;
60    }
61
62    printf("\nDU APP created and registered \
63          to %d sys task\n", sysTskId);
64    return ROK;
65 }
66 /*******************************************************************
67  *
68  * @brief Initializes SCTP task
69  *
70  * @details
71  *
72  *    Function : sctpInit
73  *
74  *    Functionality:
75  *       - Registers and attaches TAPA tasks for SCTP receiver 
76  *
77  * @params[in] system task ID
78  * @return ROK     - success
79  *         RFAILED - failure
80  *
81  * ****************************************************************/
82 S16 sctpInit(SSTskId sysTskId)
83 {
84    /* Register SCTP TAPA Task */
85    if(SRegTTsk((Ent)ENTSCTP, (Inst)0, (Ttype)TTNORM, (Prior)PRIOR0,
86             sctpActvInit, (ActvTsk)sctpActvTsk) != ROK)
87    {
88       return RFAILED;
89    }
90    /* Attach SCTP TAPA Task */
91    if (SAttachTTsk((Ent)ENTSCTP, (Inst)SCTP_INST, sysTskId)!= ROK)
92    {
93       return RFAILED;
94    }
95
96    printf("\nSCTP TAPA task created and registered to %d sys task\n", 
97          sysTskId);
98    return ROK;
99 }
100 /*******************************************************************
101  *
102  * @brief Initializes RLC DL, MAC TAPA task
103  *
104  * @details
105  *
106  *    Function : rlcDlInit
107  *
108  *    Functionality:
109  *       - Registers and attaches TAPA tasks for MAC and RLC DL
110  *
111  * @params[in] system task ID
112  * @return ROK     - success
113  *         RFAILED - failure
114  *
115  * ****************************************************************/
116 S16 rlcDlInit(SSTskId sysTskId)
117 {
118    /* Register RLC DL TAPA Task */
119    if(SRegTTsk((Ent)ENTKW, (Inst)1, (Ttype)TTNORM, (Prior)PRIOR0,
120             kwDlActvInit, (ActvTsk)kwDlActvTsk) != ROK)
121    {
122       return RFAILED;
123    }
124    /* Attach RLC DL Task */
125    if (SAttachTTsk((Ent)ENTKW, (Inst)1, sysTskId)!= ROK)
126    {
127       return RFAILED;
128    }
129
130    /* Register MAC TAPA Task */
131    if(SRegTTsk((Ent)ENTRG, (Inst)0, (Ttype)TTNORM, (Prior)PRIOR0,
132             rgActvInit, (ActvTsk)rgActvTsk) != ROK)
133    {
134       return RFAILED;
135    }
136    /* Attach MAC Task */
137    if (SAttachTTsk((Ent)ENTRG, (Inst)0, sysTskId)!= ROK)
138    {
139       return RFAILED;
140    }
141
142    printf("\nRLC DL and MAC TAPA task created and registered to \
143          %d sys task\n", sysTskId);
144    return ROK;
145 }
146
147 /*******************************************************************
148  *
149  * @brief Initializes RLC UL TAPA task
150  *
151  * @details
152  *
153  *    Function : rlcUlInit
154  *
155  *    Functionality:
156  *       - Registers and attaches TAPA task for RLC UL
157  *
158  * @params[in] system task ID
159  * @return ROK     - success
160  *         RFAILED - failure
161  *
162  * ****************************************************************/
163 S16 rlcUlInit(SSTskId sysTskId)
164 {
165    /* Register RLC UL TAPA Task */
166    if(SRegTTsk((Ent)ENTKW, (Inst)0, (Ttype)TTNORM, (Prior)PRIOR0,
167             kwUlActvInit, (ActvTsk)kwUlActvTsk) != ROK)
168    {
169       return RFAILED;
170    }
171    /* Attach RLC DL Task */
172    if (SAttachTTsk((Ent)ENTKW, (Inst)0, sysTskId)!= ROK)
173    {
174       return RFAILED;
175    }
176    printf("\nRLC UL TAPA task created and registered to \
177          %d sys task\n", sysTskId);
178    return ROK;
179 }
180
181 /*******************************************************************
182  *
183  * @brief Initializes system and TAPA tasks
184  *
185  * @details
186  *
187  *    Function : commonInit
188  *
189  *    Functionality:
190  *       - Registers and attaches system and TAPA tasks
191  *
192  * @params[in] void
193  * @return ROK     - success
194  *         RFAILED - failure
195  *
196  * ****************************************************************/
197 S16 commonInit()
198 {
199    /* Declare system task Ids */
200    SSTskId du_app_stsk, sctp_stsk, rlc_ul_stsk, rlc_mac_cl_stsk;
201
202    pthread_attr_t attr;
203
204    SSetProcId(DU_PROC);
205
206    /* system task for DU APP */
207    SCreateSTsk(PRIOR0, &du_app_stsk);
208
209    /* system task for RLC_DL and MAC */
210    SCreateSTsk(PRIOR0, &rlc_mac_cl_stsk);
211    pthread_attr_init(&attr);
212    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
213
214    /* system task for RLC UL */
215    SCreateSTsk(PRIOR1, &rlc_ul_stsk);
216
217    /* system task for SCTP receiver thread */
218    SCreateSTsk(PRIOR0, &sctp_stsk);
219
220    /* Create TAPA tasks */
221    if(duAppInit(du_app_stsk) != ROK)
222    {
223       printf("\nDU APP TAPA Task initialization failed");
224       return RFAILED;
225    }
226
227    if(sctpInit(sctp_stsk) != ROK)
228    {
229       printf("\nSCTP TAPA Task initialization failed");
230       return RFAILED;
231    }
232
233    if(rlcDlInit(rlc_mac_cl_stsk) != ROK)
234    {
235       printf("\nRLC DL Tapa Task initialization failed");
236       return RFAILED;
237    } 
238
239    if(rlcUlInit(rlc_ul_stsk) != ROK)
240    {
241      printf("\nRLC UL Tapa Task initialization failed");
242      return RFAILED;
243    } 
244    return ROK;
245 }
246
247 /*******************************************************************
248  *
249  * @brief Initializes the DU
250  *
251  * @details
252  *
253  *    Function : duInit
254  *
255  *    Functionality:
256  *       - Calls commonInit
257  *       - Registers DU Layers
258  *
259  * @params[in] void
260  * @return ROK     - success
261  *         RFAILED - failure
262  *
263  * ****************************************************************/
264 S16 duInit()
265 {
266    int ret = ROK;
267    if(commonInit() != ROK)
268    {
269       ret = RFAILED;
270    } 
271  
272    return ret;
273 }
274
275 /*******************************************************************
276  *
277  * @brief Entry point for the DU APP 
278  *
279  * @details
280  *
281  *    Function : main
282  *
283  *    Functionality:
284  *      - Read config params into duCfgParams
285  *      - Initiate the init functions
286  *
287  * @params[in] void
288  * @return ROK     - success
289  *         RFAILED - failure
290  *
291  * ****************************************************************/
292 S16 tst(void)
293 {
294
295    //Initialize TAPA layers
296    if(duInit() != ROK)
297    {
298       return RFAILED;
299    } 
300
301    //Read all the configs from du_utils.c into duCfgParams
302    duReadCfg();
303
304 #if 0
305    //Establish SCTP connection
306    while(ret == -1)
307    {
308       printf("\nEstablishing SCTP link with CU... \n");
309       //ret = establishSctp(); //To be implemeted in du_sctp.c
310    }
311 #endif
312    return ROK;
313 }/* end of main()*/
314
315 /**********************************************************************
316          End of file
317 **********************************************************************/