9a01e029888798006ff3bffceff63ea3468d9557
[o-du/phy.git] / fapi_5g / source / api / fapi2mac / p7 / nr5g_fapi_proc_slot_ind.c
1 /******************************************************************************
2 *
3 *   Copyright (c) 2019 Intel.
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 /**
20  * @file
21  * This file consist of implementation of FAPI SLOT.indication message.
22  *
23  **/
24
25 #include "nr5g_fapi_framework.h"
26 #include "gnb_l1_l2_api.h"
27 #include "nr5g_fapi_fapi2mac_api.h"
28 #include "nr5g_fapi_fapi2mac_p7_proc.h"
29
30  /** @ingroup group_source_api_p7_fapi2mac_proc
31  *
32  *  @param[in]  p_phy_ctx   Pointer to PHY context.
33  *  @param[in]  p_fapi_resp Pointer to IAPI SLOT.indication message structure.
34  *  @return     Returns ::SUCCESS and ::FAILURE.
35  *
36  *  @description
37  *  This message allows PHY to send slot indication message periodically 
38  *  to L2/L3 based on the highest numerology cconfigured in CONFIG.request
39  *
40 **/
41 uint8_t nr5g_fapi_slot_indication(
42     p_nr5g_fapi_phy_ctx_t p_phy_ctx,
43     PSlotIndicationStruct p_iapi_resp)
44 {
45     uint8_t phy_id;
46
47     fapi_slot_ind_t *p_fapi_slot_ind;
48     p_fapi_api_queue_elem_t p_list_elem;
49     p_nr5g_fapi_phy_instance_t p_phy_instance = NULL;
50     nr5g_fapi_stats_t *p_stats;
51
52     if (NULL == p_phy_ctx) {
53         NR5G_FAPI_LOG(ERROR_LOG, ("[SLOT.indication] Invalid handle to "
54                 "phy context"));
55         return FAILURE;
56     }
57
58     if (NULL == p_iapi_resp) {
59         NR5G_FAPI_LOG(ERROR_LOG, ("[SLOT.indication] Invalid handle to iapi "
60                 "slot indication message"));
61         return FAILURE;
62     }
63
64     phy_id = p_iapi_resp->sSFN_Slot.nCarrierIdx;
65     p_phy_instance = &p_phy_ctx->phy_instance[phy_id];
66     if ((p_phy_instance->phy_id != phy_id)) {
67         NR5G_FAPI_LOG(ERROR_LOG, ("[SLOT.indication] Invalid " "phy instance"));
68         return FAILURE;
69     }
70
71     p_stats = &p_phy_instance->stats;
72     p_stats->iapi_stats.iapi_slot_ind++;
73
74     p_list_elem =
75         nr5g_fapi_fapi2mac_create_api_list_elem(FAPI_SLOT_INDICATION, 1,
76         sizeof(fapi_slot_ind_t));
77     if (!p_list_elem) {
78         NR5G_FAPI_LOG(ERROR_LOG, ("[SLOT.indication] Unable to create "
79                 "list element. Out of memory!!!"));
80         return FAILURE;
81     }
82
83     p_fapi_slot_ind = (fapi_slot_ind_t *) (p_list_elem + 1);
84     p_fapi_slot_ind->header.msg_id = FAPI_SLOT_INDICATION;
85     p_fapi_slot_ind->header.length = (uint16_t) sizeof(fapi_slot_ind_t);
86     p_fapi_slot_ind->sfn = p_iapi_resp->sSFN_Slot.nSFN;
87     p_fapi_slot_ind->slot = p_iapi_resp->sSFN_Slot.nSlot;
88
89     /* Add element to send list */
90     nr5g_fapi_fapi2mac_add_api_to_list(phy_id, p_list_elem);
91
92     p_stats->fapi_stats.fapi_slot_ind++;
93     NR5G_FAPI_LOG(DEBUG_LOG, ("[SLOT.indication][%d][%d,%d]",
94             p_phy_instance->phy_id,
95             p_iapi_resp->sSFN_Slot.nSFN,
96             p_iapi_resp->sSFN_Slot.nSlot));
97
98     return SUCCESS;
99 }