* INTC Contribution to the O-RAN F Release for O-DU Low
[o-du/phy.git] / fhi_lib / app / src / common.h
1 /******************************************************************************
2 *
3 *   Copyright (c) 2020 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 #ifndef _XRAN_APP_COMMON_H_
20 #define _XRAN_APP_COMMON_H_
21
22 #include <stdio.h>
23 #include <unistd.h>
24
25 #include "xran_fh_o_du.h"
26 #include "xran_pkt_up.h"
27
28 #include <rte_common.h>
29 #include <rte_mbuf.h>
30
31 #define VERSIONX                "oran_f_release_v1.0"
32
33 #define APP_O_DU  0
34 #define APP_O_RU  1
35
36 enum app_state
37 {
38     APP_RUNNING,
39     APP_STOPPED
40 };
41
42 enum nRChBwOptions
43 {
44     PHY_BW_5_0_MHZ = 5,   PHY_BW_10_0_MHZ = 10, PHY_BW_15_0_MHZ = 15, PHY_BW_20_0_MHZ = 20, PHY_BW_25_0_MHZ = 25,
45     PHY_BW_30_0_MHZ = 30, PHY_BW_40_0_MHZ = 40, PHY_BW_50_0_MHZ = 50, PHY_BW_60_0_MHZ = 60, PHY_BW_70_0_MHZ = 70,
46     PHY_BW_80_0_MHZ = 80, PHY_BW_90_0_MHZ = 90, PHY_BW_100_0_MHZ = 100, PHY_BW_200_0_MHZ = 200, PHY_BW_400_0_MHZ = 400
47 };
48
49 #define N_SC_PER_PRB 12
50 #define N_SYM_PER_SLOT 14
51 #define MAX_ANT_CARRIER_SUPPORTED (XRAN_MAX_SECTOR_NR*XRAN_MAX_ANTENNA_NR)
52 #define MAX_ANT_CARRIER_SUPPORTED_CAT_B (XRAN_MAX_SECTOR_NR*XRAN_MAX_ANT_ARRAY_ELM_NR)
53
54 #define SUBFRAME_DURATION_US       1000
55
56 #define SUBFRAMES_PER_SYSTEMFRAME  10
57 #define IQ_PLAYBACK_BUFFER_BYTES (XRAN_NUM_OF_SLOT_IN_TDD_LOOP*N_SYM_PER_SLOT*XRAN_MAX_PRBS*N_SC_PER_PRB*4L)
58 /* PRACH data samples are 32 bits wide, 16bits for I and 16bits for Q. Each packet contains 840 samples for long sequence or 144 for short sequence. The payload length is 840*16*2/8 octets.*/
59 #ifdef FCN_1_2_6_EARLIER
60 #define PRACH_PLAYBACK_BUFFER_BYTES (144*4L)
61 #else
62 #define PRACH_PLAYBACK_BUFFER_BYTES (840*4L)
63 #endif
64
65 #ifdef _DEBUG
66 #define iAssert(p) if(!(p)){fprintf(stderr,\
67     "Assertion failed: %s, file %s, line %d, val %d\n",\
68     #p, __FILE__, __LINE__, p);exit(-1);}
69 #else /* _DEBUG */
70 #define iAssert(p)
71 #endif /* _DEBUG */
72
73 /**< all the buffers allocated for O-XU */
74 struct o_xu_buffers {
75     int iq_playback_buffer_size_dl;
76     int iq_playback_buffer_size_ul;
77
78     int iq_bfw_buffer_size_dl;
79     int iq_bfw_buffer_size_ul;
80
81     int iq_srs_buffer_size_ul;
82
83     int numSlots;  /**< number of slots in IQ vector */
84
85     int16_t *p_tx_play_buffer[MAX_ANT_CARRIER_SUPPORTED];
86     int32_t tx_play_buffer_size[MAX_ANT_CARRIER_SUPPORTED];
87
88     int16_t *p_tx_prach_play_buffer[MAX_ANT_CARRIER_SUPPORTED];
89     int32_t tx_prach_play_buffer_size[MAX_ANT_CARRIER_SUPPORTED];
90     int32_t tx_prach_play_buffer_position[MAX_ANT_CARRIER_SUPPORTED];
91
92     int16_t *p_tx_srs_play_buffer[MAX_ANT_CARRIER_SUPPORTED_CAT_B];
93     int32_t tx_srs_play_buffer_size[MAX_ANT_CARRIER_SUPPORTED_CAT_B];
94     int32_t tx_srs_play_buffer_position[MAX_ANT_CARRIER_SUPPORTED_CAT_B];
95
96     int16_t *p_rx_log_buffer[MAX_ANT_CARRIER_SUPPORTED];
97     int32_t rx_log_buffer_size[MAX_ANT_CARRIER_SUPPORTED];
98
99     int16_t *p_prach_log_buffer[MAX_ANT_CARRIER_SUPPORTED];
100     int32_t prach_log_buffer_size[MAX_ANT_CARRIER_SUPPORTED];
101
102     int16_t *p_srs_log_buffer[MAX_ANT_CARRIER_SUPPORTED_CAT_B];
103     int32_t srs_log_buffer_size[MAX_ANT_CARRIER_SUPPORTED_CAT_B];
104
105     int16_t *p_tx_buffer[MAX_ANT_CARRIER_SUPPORTED];
106     int32_t tx_buffer_size[MAX_ANT_CARRIER_SUPPORTED];
107     int16_t *p_rx_buffer[MAX_ANT_CARRIER_SUPPORTED];
108     int32_t rx_buffer_size[MAX_ANT_CARRIER_SUPPORTED];
109
110 /* beamforming weights for UL (O-DU) */
111     int16_t *p_tx_dl_bfw_buffer[MAX_ANT_CARRIER_SUPPORTED];
112     int32_t tx_dl_bfw_buffer_size[MAX_ANT_CARRIER_SUPPORTED];
113
114     int16_t *p_tx_dl_bfw_log_buffer[MAX_ANT_CARRIER_SUPPORTED];
115     int32_t tx_dl_bfw_log_buffer_size[MAX_ANT_CARRIER_SUPPORTED];
116
117 /* beamforming weights for UL (O-DU) */
118     int16_t *p_tx_ul_bfw_buffer[MAX_ANT_CARRIER_SUPPORTED];
119     int32_t tx_ul_bfw_buffer_size[MAX_ANT_CARRIER_SUPPORTED];
120
121     int16_t *p_tx_ul_bfw_log_buffer[MAX_ANT_CARRIER_SUPPORTED];
122     int32_t tx_ul_bfw_log_buffer_size[MAX_ANT_CARRIER_SUPPORTED];
123
124 /* beamforming weights for UL (O-RU) */
125     int16_t *p_rx_dl_bfw_buffer[MAX_ANT_CARRIER_SUPPORTED];
126     int32_t rx_dl_bfw_buffer_size[MAX_ANT_CARRIER_SUPPORTED];
127     int32_t rx_dl_bfw_buffer_position[MAX_ANT_CARRIER_SUPPORTED];
128
129 /* beamforming weights for UL (O-RU) */
130     int16_t *p_rx_ul_bfw_buffer[MAX_ANT_CARRIER_SUPPORTED];
131     int32_t rx_ul_bfw_buffer_size[MAX_ANT_CARRIER_SUPPORTED];
132     int32_t rx_ul_bfw_buffer_position[MAX_ANT_CARRIER_SUPPORTED];
133 };
134
135 extern struct o_xu_buffers* p_o_xu_buff[XRAN_PORTS_NUM];
136
137 void sys_save_buf_to_file_txt(char *filename, char *bufname, unsigned char *pBuffer, unsigned int size, unsigned int buffers_num);
138 void sys_save_buf_to_file(char *filename, char *bufname, unsigned char *pBuffer, unsigned int size, unsigned int buffers_num);
139 int  sys_load_file_to_buff(char *filename, char *bufname, unsigned char *pBuffer, unsigned int size, unsigned int buffers_num);
140
141 uint32_t app_xran_get_scs(uint8_t nMu);
142 uint16_t app_xran_get_num_rbs(uint8_t ranTech, uint32_t nNumerology, uint32_t nBandwidth, uint32_t nAbsFrePointA);
143 uint32_t app_xran_cal_nrarfcn(uint32_t nCenterFreq);
144 int32_t app_xran_set_slot_type(uint32_t nPhyInstanceId, uint32_t nFrameDuplexType,
145                 uint32_t nTddPeriod, struct xran_slot_config *psSlotConfig);
146 uint32_t app_xran_get_tti_interval(uint8_t nMu);
147
148 #endif /*_XRAN_APP_COMMON_H_*/