1 /******************************************************************************
3 * Copyright (c) 2019 Intel.
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.
17 *******************************************************************************/
19 #ifndef _XRAN_APP_COMMON_
20 #define _XRAN_APP_COMMON_
24 #include <arpa/inet.h>
28 #include "../common/common.h"
30 #include "xran_pkt_up.h"
31 #include "xran_cp_api.h"
32 #include "xran_up_api.h"
33 #include "../src/xran_printf.h"
38 extern enum app_state state;
40 uint8_t numCCPorts = 1;
41 /* Number of antennas supported by front-end */
44 /* Number of CPRI ports supported by front-end */
46 int16_t *p_tx_play_buffer[MAX_ANT_CARRIER_SUPPORTED];
47 int32_t tx_play_buffer_size[MAX_ANT_CARRIER_SUPPORTED];
48 int32_t tx_play_buffer_position[MAX_ANT_CARRIER_SUPPORTED];
50 int16_t *p_rx_log_buffer[MAX_ANT_CARRIER_SUPPORTED];
51 int32_t rx_log_buffer_size[MAX_ANT_CARRIER_SUPPORTED];
52 int32_t rx_log_buffer_position[MAX_ANT_CARRIER_SUPPORTED];
54 int16_t *p_prach_log_buffer[MAX_ANT_CARRIER_SUPPORTED];
55 int32_t prach_log_buffer_size[MAX_ANT_CARRIER_SUPPORTED];
56 int32_t prach_log_buffer_position[MAX_ANT_CARRIER_SUPPORTED];
58 int16_t *p_tx_buffer[MAX_ANT_CARRIER_SUPPORTED];
59 int32_t tx_buffer_size[MAX_ANT_CARRIER_SUPPORTED];
61 int16_t *p_rx_buffer[MAX_ANT_CARRIER_SUPPORTED];
62 int32_t rx_buffer_size[MAX_ANT_CARRIER_SUPPORTED];
64 void sys_save_buf_to_file(char *filename, char *bufname, unsigned char *pBuffer, unsigned int size, unsigned int buffers_num)
68 if (filename && bufname)
71 printf("Storing %s to file %s: ", bufname, filename);
72 file = fopen(filename, "wb");
75 print_err("can't open file %s!!!", filename);
80 num = fwrite(pBuffer, buffers_num, size, file);
83 printf("from addr (0x%lx) size (%d) bytes num (%d)", (uint64_t)pBuffer, size, num);
89 print_err(" the file name, buffer name are not set!!!");
94 print_err(" the %s is free: size = %d bytes!!!", bufname, size);
98 int sys_load_file_to_buff(char *filename, char *bufname, unsigned char *pBuffer, unsigned int size, unsigned int buffers_num)
100 unsigned int file_size = 0;
105 if (filename && bufname)
108 printf("Loading file %s to %s: ", filename, bufname);
109 file = fopen(filename, "rb");
114 print_err("can't open file %s!!!", filename);
119 fseek(file, 0, SEEK_END);
120 file_size = ftell(file);
121 fseek(file, 0, SEEK_SET);
123 if ((file_size > size) || (file_size == 0))
126 printf("Reading IQ samples from file: File Size: %d [Buffer Size: %d]\n", file_size, size);
128 num = fread(pBuffer, buffers_num, size, file);
131 printf("from addr (0x%lx) size (%d) bytes num (%d)", (uint64_t)pBuffer, file_size, num);
138 print_err(" the file name, buffer name are not set!!!");
143 print_err(" the %s is free: size = %d bytes!!!", bufname, size);
149 void sys_save_buf_to_file_txt(char *filename, char *bufname, unsigned char *pBuffer, unsigned int size, unsigned int buffers_num)
158 if (filename && bufname)
161 printf("Storing %s to file %s: ", bufname, filename);
162 file = fopen(filename, "w");
165 print_err("can't open file %s!!!", filename);
172 signed short *ptr = (signed short*)pBuffer;
173 for (i = 0; i < (size/((unsigned int)sizeof(signed short) /** 2 * 2 * 2*/)); i = i + 2)
175 ret = fprintf(file,"%d %d\n", ptr[i], ptr[i + 1]);
178 printf("fprintf %d\n", ret);
186 printf("from addr (0x%lx) size (%d) IQ num (%d)", (uint64_t)pBuffer, size, num);
192 print_err(" the file name, buffer name are not set!!!");
197 print_err(" the %s is free: size = %d bytes!!!", bufname, size);
202 #endif /* _XRAN_APP_COMMON_ */