c95193747fdcdc503a6a6b796b863f3b629f1e92
[o-du/phy.git] / fapi_5g / source / api / fapi2phy / p5 / nr5g_fapi_proc_ul_iq_samples_req.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 UL_IQ_SAMPLES.request message.
22  *
23  **/
24 #include "nr5g_fapi_framework.h"
25 #include "gnb_l1_l2_api.h"
26 #include "nr5g_fapi_fapi2mac_api.h"
27 #include "nr5g_fapi_fapi2phy_api.h"
28 #include "nr5g_fapi_fapi2phy_p5_proc.h"
29 #include "nr5g_fapi_fapi2phy_p5_pvt_proc.h"
30 #include "nr5g_fapi_memory.h"
31
32  /** @ingroup group_source_api_p5_fapi2phy_proc
33  *
34  *  @param[in]  p_phy_instance Pointer to PHY instance.
35  *  @param[in]  p_fapi_req Pointer to FAPI UL_IQ_SAMPLES.request message structure.
36  *  @return     Returns ::SUCCESS and ::FAILURE.
37  *
38  *  @description
39  *  This is a timer mode specific message used to transmit IQ Sample API to L1.
40  *  In UL direction, L1 opens the IQ samples file and stores it into local
41  *  buffers for processing. 
42  *
43  *
44 **/
45 #ifdef DEBUG_MODE
46 uint8_t nr5g_fapi_ul_iq_samples_request(
47     fapi_vendor_ext_iq_samples_req_t * p_fapi_req)
48 {
49     uint16_t num_ant;
50
51     fapi_vendor_ext_iq_samples_info_t *p_file_info;
52     PMAC2PHY_QUEUE_EL p_list_elem;
53
54     /* Below print is for better logging on console in debug mode. */
55     NR5G_FAPI_LOG(INFO_LOG, (""));
56
57     if (NULL == p_fapi_req) {
58         NR5G_FAPI_LOG(ERROR_LOG, (" [UL_IQ_SAMPLES.request] Invalid fapi "
59                 "message"));
60         return FAILURE;
61     }
62
63     p_list_elem = nr5g_fapi_fapi2phy_create_api_list_elem((uint8_t)
64         MSG_TYPE_PHY_UL_IQ_SAMPLES, 1,
65         (uint32_t) sizeof(fapi_vendor_ext_iq_samples_info_t));
66     if (!p_list_elem) {
67         NR5G_FAPI_LOG(ERROR_LOG, ("[UL_IQ_SAMPLES.request] Unable to create "
68                 "list element. Out of memory!!!"));
69         return FAILURE;
70     }
71
72     p_file_info = (fapi_vendor_ext_iq_samples_info_t *) (p_list_elem + 1);
73     p_file_info->carrNum = p_fapi_req->iq_samples_info.carrNum;
74     p_file_info->numSubframes = p_fapi_req->iq_samples_info.numSubframes;
75     p_file_info->testUeMode = p_fapi_req->iq_samples_info.testUeMode;
76     p_file_info->timerModeFreqDomain =
77         p_fapi_req->iq_samples_info.timerModeFreqDomain;
78     p_file_info->phaseCompensationEnable =
79         p_fapi_req->iq_samples_info.phaseCompensationEnable;
80     p_file_info->startFrameNum = p_fapi_req->iq_samples_info.startFrameNum;
81     p_file_info->startSlotNum = p_fapi_req->iq_samples_info.startSlotNum;
82     if (FAILURE == NR5G_FAPI_MEMCPY(p_file_info->buffer,
83             sizeof(uint8_t) * FAPI_MAX_IQ_SAMPLE_BUFFER_SIZE,
84             p_fapi_req->iq_samples_info.buffer, sizeof(CONFIGREQUESTStruct))) {
85         NR5G_FAPI_LOG(ERROR_LOG, ("[UL_IQ_Samples.request] Buffer copy "
86                 "failed!!!"));
87     }
88
89     for (num_ant = 0; num_ant < FAPI_MAX_IQ_SAMPLE_UL_VIRTUAL_PORTS; num_ant++) {
90         if (FAILURE == NR5G_FAPI_STRCPY(p_file_info->filename_in_ul_iq[num_ant],
91                 sizeof(uint8_t) * FAPI_MAX_IQ_SAMPLE_FILE_SIZE,
92                 p_fapi_req->iq_samples_info.filename_in_ul_iq[num_ant],
93                 sizeof(uint8_t) * FAPI_MAX_IQ_SAMPLE_FILE_SIZE)) {
94             NR5G_FAPI_LOG(ERROR_LOG, ("[UL_IQ_Samples.request] file name copy "
95                     "failed!!!"));
96         }
97
98         if (FAILURE ==
99             NR5G_FAPI_STRCPY(p_file_info->filename_in_ul_urllc[num_ant],
100                 sizeof(uint8_t) * FAPI_MAX_IQ_SAMPLE_FILE_SIZE,
101                 p_fapi_req->iq_samples_info.filename_in_ul_urllc[num_ant],
102                 sizeof(uint8_t) * FAPI_MAX_IQ_SAMPLE_FILE_SIZE)) {
103             NR5G_FAPI_LOG(ERROR_LOG,
104                 ("[UL_IQ_Samples.request] URLLC file name " "copy failed!!!"));
105         }
106         if (FAILURE ==
107             NR5G_FAPI_STRCPY(p_file_info->filename_in_prach_iq[num_ant],
108                 sizeof(uint8_t) * FAPI_MAX_IQ_SAMPLE_FILE_SIZE,
109                 p_fapi_req->iq_samples_info.filename_in_prach_iq[num_ant],
110                 sizeof(uint8_t) * FAPI_MAX_IQ_SAMPLE_FILE_SIZE)) {
111             NR5G_FAPI_LOG(ERROR_LOG,
112                 ("[UL_IQ_Samples.request] PRACH file name " "copy failed!!!"));
113         }
114     }
115
116     for (num_ant = 0; num_ant < FAPI_MAX_IQ_SAMPLE_UL_ANTENNA; num_ant++) {
117         if (FAILURE ==
118             NR5G_FAPI_STRCPY(p_file_info->filename_in_srs_iq[num_ant],
119                 sizeof(uint8_t) * FAPI_MAX_IQ_SAMPLE_FILE_SIZE,
120                 p_fapi_req->iq_samples_info.filename_in_srs_iq[num_ant],
121                 sizeof(uint8_t) * FAPI_MAX_IQ_SAMPLE_FILE_SIZE)) {
122             NR5G_FAPI_LOG(ERROR_LOG,
123                 ("[UL_IQ_Samples.request] SRS file name " "copy failed!!!"));
124         }
125     }
126
127     nr5g_fapi_fapi2phy_add_to_api_list(p_list_elem);
128     NR5G_FAPI_LOG(INFO_LOG, ("[UL_IQ_SAMPLES.request][%d]",
129             p_fapi_req->iq_samples_info.carrNum));
130
131     return SUCCESS;
132 }
133 #endif