feat: ➕ 同步1230代码差异
This commit is contained in:
parent
de36fc2b52
commit
6cfb45a889
@ -17,7 +17,11 @@
|
||||
|
||||
#include "typedef.h"
|
||||
|
||||
#define MAX_INSTANCE_NUM (4) //(2)
|
||||
#ifdef PCIE_WITH_JESD
|
||||
#define MAX_INSTANCE_NUM (4)
|
||||
#else
|
||||
#define MAX_INSTANCE_NUM (2)
|
||||
#endif
|
||||
#define MAX_PORT_NUM (4)
|
||||
|
||||
#define SUCCESS (0)
|
||||
|
@ -64,7 +64,11 @@ uint32_t get_handshake_status(void)
|
||||
volatile uint32_t response;
|
||||
uint32_t core_id = NPU_CORE_ID;
|
||||
uint32_t coreReadyBitMap = SUCCESS;//0:ready, 1:not ready
|
||||
uint32_t handshake_coremask = 0x6FF;
|
||||
#ifdef PCIE_WITH_JESD
|
||||
uint32_t handshake_coremask = 0xFFF;
|
||||
#else
|
||||
uint32_t handshake_coremask = 0x6FF;
|
||||
#endif
|
||||
|
||||
PetSmLocalMgt_t* pPetSmLocalMgt = get_pet_sm_local_mgt();
|
||||
UcpHandshake_t* pHandshake = pPetSmLocalMgt->pHandshake;
|
||||
|
18
build.sh
18
build.sh
@ -1,7 +1,7 @@
|
||||
set -e
|
||||
|
||||
usage() {
|
||||
echo "usage: $0 [variants] [--evmy] [--cache] [--cpri/--ecpri/--jesd] [--test caseid] " 1>&2
|
||||
echo "usage: $0 [variants] [--evmy] [--cache] [--cpri/--ecpri/--jesd] [--pcie] [--test caseid] " 1>&2
|
||||
msg=${1:-}
|
||||
if [ ! -z "${msg}" ]; then
|
||||
echo "error:$1"
|
||||
@ -11,6 +11,7 @@ usage() {
|
||||
|
||||
variants=
|
||||
fronthaul_option="cpri"
|
||||
backhaul_option="tmac"
|
||||
cache_option="no"
|
||||
test_option="no"
|
||||
case_id=0
|
||||
@ -39,6 +40,7 @@ while [[ "$#" > 0 ]]; do
|
||||
--cpri) fronthaul_option="cpri"; shift;;
|
||||
--ecpri) fronthaul_option="ecpri"; shift;;
|
||||
--jesd) fronthaul_option="jesd"; shift;;
|
||||
--pcie) backhaul_option="pcie"; shift;;
|
||||
|
||||
--test) test_option="yes";
|
||||
if [[ ! -z "$2" ]] && [[ -n "$(echo $2 | sed -n " /^[0-9]\+$/p")" ]]; then
|
||||
@ -70,7 +72,7 @@ if [[ "${fronthaul_option}" == "jesd" ]]; then
|
||||
export BOARD_TYPE=${board_option}
|
||||
|
||||
echo -e "\n"
|
||||
echo "###### start building libjesd.a and librfic.a ######"
|
||||
echo "###### start building libjesd.a and librfic.a and rfic.out ######"
|
||||
cd ${DIR_ROOT}/driver/rfic
|
||||
#chmod +x build.sh
|
||||
source ./build.sh
|
||||
@ -81,10 +83,12 @@ if [[ "${fronthaul_option}" == "jesd" ]]; then
|
||||
cp ${RFIC_DIR}/out/rfic/ucp_api_rfic.h ${RFIC_APP_DIR}/inc/
|
||||
cp ${CJSON_DIR}/xzJSON.h ${RFIC_APP_DIR}/inc/
|
||||
|
||||
echo -e "\n"
|
||||
echo "###### start building rfic.out ######"
|
||||
cd ${RFIC_APP_DIR}/
|
||||
make
|
||||
cp ${RFIC_DIR}/out/app/*.out ${BUILD_DIR}
|
||||
|
||||
#echo -e "\n"
|
||||
#echo "###### start building rfic.out ######"
|
||||
#cd ${RFIC_APP_DIR}/
|
||||
#make
|
||||
fi
|
||||
|
||||
cd ${DIR_ROOT}/driver/tfu
|
||||
@ -96,7 +100,7 @@ cp stc/inc/stc_drv_api.h ${DIR_ROOT}/interface
|
||||
echo -e "\n"
|
||||
echo "###### start building msgTransfer.out and libmsgTransfer.a ######"
|
||||
cd ${DIR_ROOT}/
|
||||
make cache_option=${cache_option} fronthaul_option=${fronthaul_option} test_option=${test_option} test_id=${case_id}
|
||||
make cache_option=${cache_option} fronthaul_option=${fronthaul_option} backhaul_option=${backhaul_option} test_option=${test_option} test_id=${case_id}
|
||||
|
||||
cd ${DIR_ROOT}/lib
|
||||
rm -rf *.*
|
||||
|
@ -104,20 +104,18 @@ OSP_STATUS osp_arm_log_proc(char *pbuf, uint32_t len ,uint32_t logid, uint32_t m
|
||||
/*
|
||||
name: osp_read_spe_cfg_file
|
||||
para: Input: path: the config file's path
|
||||
para: Input: cellid: the index of the cell
|
||||
brief: load the spe config file by the path
|
||||
*/
|
||||
int32_t osp_read_spe_cfg_file(char* path, uint8_t cellid);
|
||||
int32_t osp_read_spe_cfg_file(char* path);
|
||||
|
||||
/*
|
||||
name: osp_get_cfg_file
|
||||
para: Input: name: the config file's name
|
||||
para: Input: cellid: the index of the cell
|
||||
para: Output: paddr: the config file's address
|
||||
para: Output: psize: the config file's size
|
||||
brief: get a config file's address and size
|
||||
*/
|
||||
int32_t osp_get_cfg_file(char* name, uint8_t cellid, uint64_t *paddr, uint32_t *psize);
|
||||
int32_t osp_get_cfg_file(char* name, uint64_t *paddr, uint32_t *psize);
|
||||
|
||||
int32_t get_clock_module_status(volatile clock_module_status_s* clk_module_status_ptr);
|
||||
int32_t set_clk_mode(clk_flag_e pseudo_flag);
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
#include "typedef.h"
|
||||
|
||||
#define MAX_INSTANCE_NUM (4) //(2)
|
||||
#define MAX_INSTANCE_NUM (2)
|
||||
#define MAX_PORT_NUM (4)
|
||||
|
||||
#define SUCCESS (0)
|
||||
|
163
interface/stc_drv_api.h
Normal file
163
interface/stc_drv_api.h
Normal file
@ -0,0 +1,163 @@
|
||||
/*==============================================================================
|
||||
* Copyright (c) 2011~2012, CPIT. All Rights Reserved.
|
||||
*
|
||||
* MODULE: STC模块驱动
|
||||
*
|
||||
* FILENAME: stc.h
|
||||
*
|
||||
* DESCRIPTION: Source Code of STC Driver
|
||||
*
|
||||
* Current Version: 1.0
|
||||
*
|
||||
* HISTORY:
|
||||
* Date CR No Person Description
|
||||
* ---------- ------------ ------ -------------
|
||||
* 2022-05-21 Li Weihua Initial version.
|
||||
==============================================================================*/
|
||||
#ifndef __STC_DRV_API_H__
|
||||
#define __STC_DRV_API_H__
|
||||
|
||||
#include "typedef.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
#pragma align(1) /* set tight packing */
|
||||
#pragma pack(1)
|
||||
#endif
|
||||
/*==============================================================================
|
||||
Includes and Public Data Declarations
|
||||
==============================================================================*/
|
||||
|
||||
/* 包含系统文件以及定义公用数据文件 */
|
||||
|
||||
|
||||
/*==============================================================================
|
||||
Include Files
|
||||
==============================================================================*/
|
||||
|
||||
/* 包含本地文件 */
|
||||
/*==============================================================================
|
||||
Constant / Define Declarations
|
||||
==============================================================================*/
|
||||
|
||||
|
||||
/* 常量定义,并对所定义的常量进行说明 */
|
||||
/*==============================================================================
|
||||
Global Constant Data Declarations
|
||||
==============================================================================*/
|
||||
|
||||
/*==============================================================================
|
||||
Macro Definitions
|
||||
==============================================================================*/
|
||||
/* 宏定义,并对其进行简要说明 */
|
||||
|
||||
/*==============================================================================
|
||||
Function Prototypes
|
||||
==============================================================================*/
|
||||
|
||||
/*STC中断类型*/
|
||||
typedef enum
|
||||
{
|
||||
STC_INT_RESERVED = 0, /* Reserved*/
|
||||
STC_TOD_1PPS, /* stc内部产生的1pps中断 */
|
||||
STC_EX_1PPS_IN, /* 外部1pps中断 */
|
||||
STC_HSCC_DUMP = 4 /* HSCC_DUMP中断 */
|
||||
} stc_int_type_e;
|
||||
|
||||
|
||||
/*输入1PPS中断源*/
|
||||
typedef enum
|
||||
{
|
||||
GMAC0_1PPS_IN = 0, /* gmac0 */
|
||||
GMAC1_1PPS_IN, /* gmac1 */
|
||||
RESERVED0_1PPS_IN, /* Reserved*/
|
||||
CPRI_GMAC_1PPS_IN = 3, /* cpri gmac */
|
||||
TMAC_1PPS_IN, /* tmac */
|
||||
GNSS_1PPS_IN, /* 接收机 */
|
||||
//GMAC_1PPS
|
||||
RESERVED_1PPS_IN /* Reserved*/
|
||||
} pp1s_soure_e;
|
||||
|
||||
/*输出1PPS源*/
|
||||
typedef enum
|
||||
{
|
||||
GMAC0_1PPS_OUT = 0, /* gmac0 */
|
||||
GMAC1_1PPS_OUT, /* gmac1 */
|
||||
RESERVED0_1PPS_OUT, /* Reserved*/
|
||||
CPRI_GMAC_1PPS_OUT = 3, /* cpri gmac */
|
||||
TMAC_1PPS_OUT, /* tmac */
|
||||
STC_1PPS_OUT, /* stc产生的1pps */
|
||||
TOD_1PPS_OUT, /* stc产生的1pps */
|
||||
RESERVED_1PPS_OUT /* Reserved*/
|
||||
} pp1s_output_e;
|
||||
|
||||
/*synce接口类型*/
|
||||
typedef enum
|
||||
{
|
||||
SYNCE_GMAC = 0, /* GMAC */
|
||||
SYNCE_TMAC, /* TMAC */
|
||||
SYNCE_ECPRI, /* eCPRI */
|
||||
RESERVED_SYNCE /* Reserved*/
|
||||
}synce_src_e;
|
||||
|
||||
|
||||
/*hscc_dump的输入源*/
|
||||
typedef enum
|
||||
{
|
||||
TOD_1PPS = 0, /* stc内部产生的1pps */
|
||||
EX_1PPS_IN, /* 外部1pps */
|
||||
EX_SYNCE, /* 恢复时钟/synce时钟分频产生的1pps */
|
||||
HSCC_RESERVED /* Reserved*/
|
||||
} hscc_dump_soure_e;
|
||||
|
||||
int32_t init_stc();
|
||||
int32_t enable_stc_irq(stc_int_type_e irq_type);
|
||||
int32_t disable_stc_irq(stc_int_type_e irq_type);
|
||||
int32_t select_xpps_in_source(pp1s_soure_e src);
|
||||
int32_t set_xpps_out_source(pp1s_output_e src,uint32_t enable);
|
||||
double stc_adjust_frequency();
|
||||
int32_t stc_adjust_phase(uint32_t phase_diff);
|
||||
int32_t stc_adjust_sniffer_phase(int32_t phase_diff,uint32_t flag);
|
||||
int32_t set_ape_preset_value(uint32_t cal_bfn);
|
||||
int32_t stc_wait_for_hscc();
|
||||
int32_t stc_wait_for_expps();
|
||||
uint32_t get_gmac_src_time();
|
||||
uint32_t get_tmac_src_time();
|
||||
uint32_t read_stc_local_timer();
|
||||
|
||||
/******************************************************************
|
||||
* Input(s):
|
||||
* sync_status: STC同步状态 1:同步,0:失步
|
||||
* Output(s):
|
||||
* <none>
|
||||
* Returns:
|
||||
* 0:成功
|
||||
* 非0:失败
|
||||
********************************************************************/
|
||||
int32_t set_sync_status_to_ape(uint32_t sync_status);
|
||||
|
||||
/*配置STC内部 synce时钟源*/
|
||||
int32_t config_synce(uint32_t synce_flag, synce_src_e interface, uint32_t clk);
|
||||
|
||||
/*synce时设置频率校准周期*/
|
||||
int32_t set_fsync_frequncy(uint32_t frequncy);
|
||||
|
||||
/*选择hscc_dump中断的输入*/
|
||||
int32_t select_hscc_dump_source(hscc_dump_soure_e src_type);
|
||||
|
||||
uint32_t read_stc_local_timer();
|
||||
|
||||
#if 0
|
||||
#pragma align() /* restore default packing */
|
||||
#pragma pack()
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __STC_DRV_API_H__ */
|
||||
|
@ -61,6 +61,54 @@ typedef enum ucp_jesd_gpioEnableLevel
|
||||
UCP_JESD_TRX_GPIO_VALID_LOW = 0x02,
|
||||
} ucp_jesd_gpioEnableLevel_e;
|
||||
|
||||
/**
|
||||
* \brief Index of trx's control pins.
|
||||
*/
|
||||
enum {
|
||||
GPIO_TRX_TX1 = 0,
|
||||
GPIO_TRX_TX2,
|
||||
GPIO_TRX_TX3,
|
||||
GPIO_TRX_TX4,
|
||||
GPIO_RF_TX1,
|
||||
GPIO_RF_TX2,
|
||||
GPIO_RF_TX3,
|
||||
GPIO_RF_TX4,
|
||||
GPIO_SW_TX1,
|
||||
GPIO_SW_TX2,
|
||||
GPIO_SW_TX3,
|
||||
GPIO_SW_TX4,
|
||||
|
||||
GPIO_TRX_RX1,
|
||||
GPIO_TRX_RX2,
|
||||
GPIO_TRX_RX3,
|
||||
GPIO_TRX_RX4,
|
||||
GPIO_RF_RX1,
|
||||
GPIO_RF_RX2,
|
||||
GPIO_RF_RX3,
|
||||
GPIO_RF_RX4,
|
||||
GPIO_SW_RX1,
|
||||
GPIO_SW_RX2,
|
||||
GPIO_SW_RX3,
|
||||
GPIO_SW_RX4,
|
||||
|
||||
GPIO_TRX_ORX1,
|
||||
GPIO_TRX_ORX2,
|
||||
GPIO_TRX_ORX3,
|
||||
GPIO_TRX_ORX4,
|
||||
GPIO_RF_ORX1,
|
||||
GPIO_RF_ORX2,
|
||||
GPIO_RF_ORX3,
|
||||
GPIO_RF_ORX4,
|
||||
GPIO_SW_ORX1,
|
||||
GPIO_SW_ORX2,
|
||||
GPIO_SW_ORX3,
|
||||
GPIO_SW_ORX4,
|
||||
|
||||
GPIO_TRIGER,
|
||||
|
||||
GPIO_TR_MAX = 40
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Data structure to contrl pins of rf's trx
|
||||
*/
|
||||
@ -92,6 +140,7 @@ typedef struct ucp_jesd_TrxGpioCfg {
|
||||
uint8_t devClkSrc;
|
||||
int32_t uldelay;
|
||||
int32_t dldelay;
|
||||
char lvdsCoupling[16];
|
||||
ucp_jesd_gpio_t triger;
|
||||
ucp_jesd_TrxGpio_t ch[MAX_UCP_JESD_TRX_CH];
|
||||
} ucp_jesd_TrxGpioCfg_t;
|
||||
@ -179,7 +228,7 @@ extern void UCP_API_JESD_ApeWorkStep(ucp_jesd_ApeWorkStep_e step);
|
||||
*
|
||||
* \retval none.
|
||||
*/
|
||||
extern void UCP_API_JESD_TrxGpioSetup (const char *trxGpioConfigFile);
|
||||
extern void UCP_API_JESD_TrxGpioSetup (const char *trxGpioConfigFile, uint16_t enLog);
|
||||
|
||||
/**
|
||||
* \brief Gets the gpio's inf of tx and rx
|
||||
@ -225,6 +274,8 @@ extern void UCP_API_JESD_CellDelete (void);
|
||||
*
|
||||
* \retval none.
|
||||
*/
|
||||
extern int ucp_jesd_gpioSet(const int pinIdex, int value);
|
||||
extern int ucp_jesd_gpioGet(const int pinIdex);
|
||||
extern void UCP_API_GPIO_Tx (void);
|
||||
extern void UCP_API_GPIO_Rx (void);
|
||||
extern void UCP_API_GPIO_On (void);
|
||||
|
6
makefile
6
makefile
@ -28,7 +28,11 @@ DEFINES += ARM_TAG=\"${arm_tag}\"
|
||||
DEFINES += ARM_BUILD_DATE=\"${arm_build_date}\"
|
||||
|
||||
ifeq ($(fronthaul_option),jesd)
|
||||
DEFINES += ENABLE_JESD_TEST
|
||||
DEFINES += ENABLE_JESD_TEST
|
||||
|
||||
ifeq ($(backhaul_option),pcie)
|
||||
DEFINES += PCIE_WITH_JESD
|
||||
endif
|
||||
endif
|
||||
|
||||
#optimization level -O2
|
||||
|
@ -25,8 +25,8 @@ extern int32_t osp_read_cfg_file(void);
|
||||
|
||||
|
||||
/* TestMac interface */
|
||||
extern int32_t osp_read_spe_cfg_file(char* path, uint8_t cellid);
|
||||
extern int32_t osp_get_cfg_file(char* name, uint8_t cellid, uint64_t *paddr, uint32_t *psize);
|
||||
extern int32_t osp_read_spe_cfg_file(char* path);
|
||||
extern int32_t osp_get_cfg_file(char* name, uint64_t *paddr, uint32_t *psize);
|
||||
|
||||
#ifdef HEARTBEAT_ENABLE
|
||||
extern int8_t osp_get_im2ddr_to_file(uint8_t u8CoreId);
|
||||
|
@ -31,25 +31,11 @@
|
||||
/***************************************************************************/
|
||||
/* ARM <---> ARM */
|
||||
#define ARM_SPE_CFG_PHY_SIZE (0x3000000) /* 改到系统内存,约定大小为128M */ //(0x1400000) /* 约定在20M以内 */
|
||||
#define ARM_SPE_CFG_PHY_SIZE0 (0x03000000)
|
||||
#define ARM_SPE_CFG_PHY_SIZE1 (0x02000000)
|
||||
#define ARM_SPE_CFG_PHY_SIZE2 (0x01000000)
|
||||
#define ARM_SPE_CFG_PHY_SIZE3 (0x01000000)
|
||||
#define ARM_SPE_CFG_INFO_ONE sizeof(osp_spe_cfg_file_reg)
|
||||
#define ARM_SPE_CFG_INFO_SIZE (ARM_SPE_CFG_INFO_ONE * APE_SPE_CFG_FILE_NUM)
|
||||
//#define ARM_SPE_CFG_FILE_SIZE (ARM_SPE_CFG_PHY_SIZE - ARM_SPE_CFG_INFO_SIZE - ARM_CFG_INDXN) /* 特殊配置文件总长度 */
|
||||
#define ARM_SPE_CFG_FILE_SIZE0 (ARM_SPE_CFG_PHY_SIZE0 - ARM_SPE_CFG_INFO_SIZE - ARM_CFG_INDXN) /* 特殊配置文件总长度 */
|
||||
#define ARM_SPE_CFG_FILE_SIZE1 (ARM_SPE_CFG_PHY_SIZE1 - ARM_SPE_CFG_INFO_SIZE - ARM_CFG_INDXN) /* 特殊配置文件总长度 */
|
||||
#define ARM_SPE_CFG_FILE_SIZE2 (ARM_SPE_CFG_PHY_SIZE2 - ARM_SPE_CFG_INFO_SIZE - ARM_CFG_INDXN) /* 特殊配置文件总长度 */
|
||||
#define ARM_SPE_CFG_FILE_SIZE3 (ARM_SPE_CFG_PHY_SIZE3 - ARM_SPE_CFG_INFO_SIZE - ARM_CFG_INDXN) /* 特殊配置文件总长度 */
|
||||
|
||||
#define ARM_SPE_CFG_FILE_SIZE (ARM_SPE_CFG_PHY_SIZE - ARM_SPE_CFG_INFO_SIZE - ARM_CFG_INDXN) /* 特殊配置文件总长度 */
|
||||
#define ARM_SPE_CFG_OFFSET (0x89000000) /* 目前改到APE_PHY段,从0x1000 0000开始,故需要偏移0x8900 0000 */
|
||||
|
||||
#define ARM_SPE_CFG_OFFSET_CELL0 (0x85000000) /* 目前在APE_PHY段,CELL0在0x9500 0000开始48M */
|
||||
#define ARM_SPE_CFG_OFFSET_CELL1 (0x88000000) /* 目前在APE_PHY段,CELL1在0x9800 0000开始32M */
|
||||
#define ARM_SPE_CFG_OFFSET_CELL2 (0x8A000000) /* 目前在APE_PHY段,CELL2在0x9A00 0000开始16M */
|
||||
#define ARM_SPE_CFG_OFFSET_CELL3 (0x8B000000) /* 目前在APE_PHY段,CELL3在0x9B00 0000开始16M */
|
||||
|
||||
#if 0
|
||||
#define ARM_SPE_CFG_PHY_ADDR (0xB8000000) /* 指定配置文件首地址 */
|
||||
#define ARM_SPE_CFG_PHY_SIZE (0x10000) /* 指定配置文件区域长度:64K */
|
||||
@ -67,12 +53,9 @@ uint64_t g_static_mem_size = 0;
|
||||
|
||||
/***************************************************************************/
|
||||
/* ARM <---> ARM */
|
||||
#define SPE_OSP_CFG_CELL_ID (4)
|
||||
|
||||
osp_spe_cfg_file_reg g_spe_osp_cfg_file_reg[SPE_OSP_CFG_CELL_ID][APE_SPE_CFG_FILE_NUM];
|
||||
uint32_t g_spe_osp_cfg_file_idx[SPE_OSP_CFG_CELL_ID] = {0};
|
||||
osp_spe_cfg_file_reg g_spe_osp_cfg_file_reg[APE_SPE_CFG_FILE_NUM];
|
||||
uint32_t g_spe_osp_cfg_file_idx = 0;
|
||||
void *g_spe_ptr_static_mem = NULL;
|
||||
void *g_spe_ptr_static_mem_bycell[SPE_OSP_CFG_CELL_ID] = {0};
|
||||
uint64_t g_spe_static_mem_size = 0;
|
||||
|
||||
/***************************************************************************/
|
||||
@ -334,10 +317,11 @@ int32_t osp_read_cfg_file(void)
|
||||
|
||||
/***************************************************************************/
|
||||
/* ARM <---> ARM */
|
||||
int32_t osp_spe_cfg_file_init(uint8_t cellid)
|
||||
int32_t osp_spe_cfg_file_init()
|
||||
{
|
||||
memset(&g_spe_osp_cfg_file_reg[cellid], 0, sizeof(osp_spe_cfg_file_reg)*APE_SPE_CFG_FILE_NUM);
|
||||
g_spe_osp_cfg_file_idx[cellid] = 0;
|
||||
memset(&g_spe_osp_cfg_file_reg, 0, sizeof(g_spe_osp_cfg_file_reg));
|
||||
g_spe_osp_cfg_file_idx = 0;
|
||||
//g_spe_static_mem_size = 0;
|
||||
|
||||
#if 0
|
||||
/* 改成从系统内存中分配128M */
|
||||
@ -356,11 +340,7 @@ int32_t osp_spe_cfg_file_init(uint8_t cellid)
|
||||
UCP_PRINT_ERROR("get_static_mem(ARM_STACK) error......\r\n");
|
||||
return OSP_ERROR;
|
||||
}
|
||||
g_spe_ptr_static_mem_bycell[0] = g_spe_ptr_static_mem + ARM_SPE_CFG_OFFSET_CELL0;
|
||||
g_spe_ptr_static_mem_bycell[1] = g_spe_ptr_static_mem + ARM_SPE_CFG_OFFSET_CELL1;
|
||||
g_spe_ptr_static_mem_bycell[2] = g_spe_ptr_static_mem + ARM_SPE_CFG_OFFSET_CELL2;
|
||||
g_spe_ptr_static_mem_bycell[3] = g_spe_ptr_static_mem + ARM_SPE_CFG_OFFSET_CELL3;
|
||||
//g_spe_ptr_static_mem += ARM_SPE_CFG_OFFSET; /* 在内存规划中,配置文件的起始地址需要偏移 */
|
||||
g_spe_ptr_static_mem += ARM_SPE_CFG_OFFSET; /* 在内存规划中,配置文件的起始地址需要偏移 */
|
||||
#endif
|
||||
return OSP_OK;
|
||||
}
|
||||
@ -457,7 +437,7 @@ int32_t osp_read_spe_cfg_to_bin(char* in_path)
|
||||
return OSP_OK;
|
||||
}
|
||||
|
||||
int32_t osp_spe_bin_cfg_file_to_ddr(uint8_t cellid)
|
||||
int32_t osp_spe_bin_cfg_file_to_ddr()
|
||||
{
|
||||
char *p_line_file_name = NULL;
|
||||
char *p_line_file_name_begin = NULL;
|
||||
@ -466,11 +446,10 @@ int32_t osp_spe_bin_cfg_file_to_ddr(uint8_t cellid)
|
||||
|
||||
uint32_t len = 0;
|
||||
uint32_t tmp_len = 0;
|
||||
uint8_t osp_cfg_file_idx = 0; /* 文件个数 */
|
||||
uint8_t osp_cfg_file_idx = 0; /* 文件个数 */
|
||||
uint32_t ret = 0; /* 返回值判断 */
|
||||
uint32_t file_len = 0; /* 文件长度 */
|
||||
uint32_t ddr_offset = 0;
|
||||
uint32_t u32file_all_size = 0;
|
||||
|
||||
FILE *file = NULL;
|
||||
FILE *read_file = NULL;
|
||||
@ -527,32 +506,7 @@ int32_t osp_spe_bin_cfg_file_to_ddr(uint8_t cellid)
|
||||
UCP_PRINT_DEBUG("[to_ddr]: file: %s ,Size: %d\r\n", line_file_full_name, file_len);
|
||||
|
||||
/* 保护:文件太多,空间不够 */
|
||||
if (0 == cellid)
|
||||
{
|
||||
u32file_all_size = ARM_SPE_CFG_FILE_SIZE0;
|
||||
}
|
||||
else if (1 == cellid)
|
||||
{
|
||||
u32file_all_size = ARM_SPE_CFG_FILE_SIZE1;
|
||||
}
|
||||
else if (2 == cellid)
|
||||
{
|
||||
u32file_all_size = ARM_SPE_CFG_FILE_SIZE2;
|
||||
}
|
||||
else if (3 == cellid)
|
||||
{
|
||||
u32file_all_size = ARM_SPE_CFG_FILE_SIZE3;
|
||||
}
|
||||
else
|
||||
{
|
||||
UCP_PRINT_ERROR("[to_ddr]: too much file, no space... \r\n");
|
||||
fclose(read_file);
|
||||
fclose(file);
|
||||
system("rm tmpfile");
|
||||
return OSP_ERROR;
|
||||
}
|
||||
|
||||
if ((file_len + ddr_offset) > u32file_all_size)
|
||||
if ((file_len + ddr_offset) > ARM_SPE_CFG_FILE_SIZE)
|
||||
{
|
||||
UCP_PRINT_ERROR("[to_ddr]: too much file, no space... \r\n");
|
||||
fclose(read_file);
|
||||
@ -568,19 +522,18 @@ int32_t osp_spe_bin_cfg_file_to_ddr(uint8_t cellid)
|
||||
len = 0;
|
||||
while(len < file_len)
|
||||
{
|
||||
tmp_len = fread((char*)(g_spe_ptr_static_mem_bycell[cellid]+ARM_CFG_INDXN+ARM_SPE_CFG_INFO_SIZE+ddr_offset+len), 1, file_len, read_file);
|
||||
//tmp_len = fread((char*)(g_spe_ptr_static_mem+ARM_CFG_INDXN+ARM_SPE_CFG_INFO_SIZE+ddr_offset+len), 1, file_len, read_file);
|
||||
tmp_len = fread((char*)(g_spe_ptr_static_mem+ARM_CFG_INDXN+ARM_SPE_CFG_INFO_SIZE+ddr_offset+len), 1, file_len, read_file);
|
||||
len += tmp_len;
|
||||
}
|
||||
|
||||
/* 更新全局变量 */
|
||||
g_spe_osp_cfg_file_reg[cellid][osp_cfg_file_idx].len = file_len;
|
||||
memcpy(g_spe_osp_cfg_file_reg[cellid][osp_cfg_file_idx].name, file_name, strlen(file_name));
|
||||
g_spe_osp_cfg_file_reg[cellid][osp_cfg_file_idx].vir_addr = (uint64_t)(g_spe_ptr_static_mem_bycell[cellid]
|
||||
g_spe_osp_cfg_file_reg[g_spe_osp_cfg_file_idx].len = file_len;
|
||||
memcpy(g_spe_osp_cfg_file_reg[g_spe_osp_cfg_file_idx].name, file_name, strlen(file_name));
|
||||
g_spe_osp_cfg_file_reg[g_spe_osp_cfg_file_idx].vir_addr = (uint64_t)(g_spe_ptr_static_mem
|
||||
+ ARM_CFG_INDXN
|
||||
+ ARM_SPE_CFG_INFO_SIZE
|
||||
+ ddr_offset);
|
||||
g_spe_osp_cfg_file_idx[cellid]++;
|
||||
g_spe_osp_cfg_file_idx++;
|
||||
ddr_offset += file_len;
|
||||
|
||||
osp_cfg_file_idx++;
|
||||
@ -588,9 +541,9 @@ int32_t osp_spe_bin_cfg_file_to_ddr(uint8_t cellid)
|
||||
}
|
||||
|
||||
/* 更新配置文件头信息 */
|
||||
*(uint32_t *)(g_spe_ptr_static_mem_bycell[cellid]+ARM_CFG_NUM) = g_spe_osp_cfg_file_idx[cellid];
|
||||
memcpy((g_spe_ptr_static_mem_bycell[cellid] + ARM_CFG_INDXN), g_spe_osp_cfg_file_reg[cellid], ARM_SPE_CFG_INFO_ONE * g_spe_osp_cfg_file_idx[cellid]);
|
||||
*(uint32_t *)g_spe_ptr_static_mem_bycell[cellid] = ARM_READ_CFG_FILE_OK;
|
||||
*(uint32_t *)(g_spe_ptr_static_mem+ARM_CFG_NUM) = g_spe_osp_cfg_file_idx;
|
||||
memcpy((g_spe_ptr_static_mem + ARM_CFG_INDXN), g_spe_osp_cfg_file_reg, ARM_SPE_CFG_INFO_ONE * g_spe_osp_cfg_file_idx);
|
||||
*(uint32_t *)g_spe_ptr_static_mem = ARM_READ_CFG_FILE_OK;
|
||||
|
||||
fclose(file);
|
||||
system("rm tmpfile");
|
||||
@ -603,12 +556,12 @@ int32_t osp_spe_bin_cfg_file_to_ddr(uint8_t cellid)
|
||||
/********************************************************************/
|
||||
/* TestMac Interface */
|
||||
/********************************************************************/
|
||||
int32_t osp_read_spe_cfg_file(char* path, uint8_t cellid)
|
||||
int32_t osp_read_spe_cfg_file(char* path)
|
||||
{
|
||||
uint32_t ret = 0;
|
||||
|
||||
/* 每次调用前,清空全局变量 */
|
||||
ret = osp_spe_cfg_file_init(cellid);
|
||||
ret = osp_spe_cfg_file_init();
|
||||
if (OSP_OK != ret)
|
||||
{
|
||||
UCP_PRINT_ERROR("[osp_read_spe_cfg_file]: osp_cfg_file_init return error: %d\r\n", ret);
|
||||
@ -624,7 +577,7 @@ int32_t osp_read_spe_cfg_file(char* path, uint8_t cellid)
|
||||
}
|
||||
|
||||
/* 转化 */
|
||||
ret = osp_spe_bin_cfg_file_to_ddr(cellid);
|
||||
ret = osp_spe_bin_cfg_file_to_ddr();
|
||||
if (OSP_OK != ret)
|
||||
{
|
||||
UCP_PRINT_ERROR("[osp_read_spe_cfg_file]: osp_spe_bin_cfg_file_to_ddr return error: %d\r\n", ret);
|
||||
@ -633,7 +586,7 @@ int32_t osp_read_spe_cfg_file(char* path, uint8_t cellid)
|
||||
return OSP_OK;
|
||||
}
|
||||
|
||||
int32_t osp_get_cfg_file(char* name, uint8_t cellid, uint64_t *paddr, uint32_t *psize)
|
||||
int32_t osp_get_cfg_file(char* name, uint64_t *paddr, uint32_t *psize)
|
||||
{
|
||||
uint16_t loop = 0;
|
||||
osp_spe_cfg_file_reg *head = NULL;
|
||||
@ -642,9 +595,9 @@ int32_t osp_get_cfg_file(char* name, uint8_t cellid, uint64_t *paddr, uint32_t *
|
||||
UCP_PRINT_ERROR("[osp_get_cfg_file]: name too long\r\n");
|
||||
return OSP_ERROR;
|
||||
}
|
||||
for (loop = 0; loop < g_spe_osp_cfg_file_idx[cellid]; loop++)
|
||||
for (loop = 0; loop < g_spe_osp_cfg_file_idx; loop++)
|
||||
{
|
||||
head = g_spe_osp_cfg_file_reg[cellid] + loop;
|
||||
head = g_spe_osp_cfg_file_reg + loop;
|
||||
if (0 == memcmp(head->name, name, strlen(name)))
|
||||
{
|
||||
/* 物理层需要物理地址,而还是虚拟地址 */
|
||||
|
267
rfic/inc/ucp_api_rfic.h
Normal file
267
rfic/inc/ucp_api_rfic.h
Normal file
@ -0,0 +1,267 @@
|
||||
//******************** (C) COPYRIGHT 2022 SmartLogic*******************************
|
||||
// FileName : ucp_api_rfic.h
|
||||
// Author : Boheng Lin bhlin919@126.com
|
||||
// Date First Issued : 2023-03-04 17:39:00 PM
|
||||
// Last Modified :
|
||||
// Description :
|
||||
// ------------------------------------------------------------
|
||||
// Modification History:
|
||||
// Version Date Author Modification Description
|
||||
//
|
||||
//**********************************************************************************
|
||||
|
||||
#ifndef UCP_API_RFIC_H_
|
||||
#define UCP_API_RFIC_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief define board type
|
||||
*/
|
||||
enum {
|
||||
HW_UNKNOW = 0,
|
||||
HW_EVMT,
|
||||
HW_EVMF,
|
||||
HW_EVB,
|
||||
HW_EVMY,
|
||||
HW_OTHER = 254,
|
||||
HW_MAX = 255
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief define some paras for cell init
|
||||
*/
|
||||
enum {
|
||||
CFG_SAMPLERATE_61_44MHZ = 61440000,
|
||||
CFG_SAMPLERATE_122_88MHZ = 122880000,
|
||||
CFG_SAMPLERATE_245_76MHZ = 245760000
|
||||
};
|
||||
|
||||
enum {
|
||||
CFG_BW_20MHZ = 20000000,
|
||||
CFG_BW_50MHZ = 50000000,
|
||||
CFG_BW_100MHZ = 100000000,
|
||||
CFG_BW_200MHZ = 200000000,
|
||||
CFG_BW_240MHZ = 240000000
|
||||
};
|
||||
|
||||
enum {
|
||||
CFG_1ANT = 1,
|
||||
CFG_2ANT = 2,
|
||||
CFG_3ANT = 3,
|
||||
CFG_4ANT = 4,
|
||||
CFG_5ANT = 5,
|
||||
CFG_6ANT = 6,
|
||||
CFG_7ANT = 7,
|
||||
CFG_8ANT = 8
|
||||
};
|
||||
|
||||
enum {
|
||||
CFG_TDD = 0,
|
||||
CFG_FDD = 1
|
||||
};
|
||||
|
||||
enum {
|
||||
CFG_NORX = 0,
|
||||
CFG_TLO_ORX = 1,
|
||||
CFG_ALO_ORX = 2,
|
||||
CFG_RLO_ORX = 3
|
||||
};
|
||||
|
||||
enum {
|
||||
CFG_204B= 0,
|
||||
CFG_204C = 1
|
||||
};
|
||||
|
||||
enum {
|
||||
CFG_NONE_LOG = 0,
|
||||
CFG_LOG = 1
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief define cal para struct
|
||||
*/
|
||||
|
||||
typedef struct ucp_rfic_calPara
|
||||
{
|
||||
int16_t calOrxGainIndex;
|
||||
int16_t calChAttPara[16];
|
||||
} ucp_rfic_calPara_t;
|
||||
|
||||
//**********************************************************************************
|
||||
// system option layer
|
||||
/**
|
||||
* \brief Sets up the cell's default config
|
||||
*
|
||||
* \param sampleRate is Transceiver's sample Rate (Unit hz. 122.88Mhz 245.76Mhz or 61.44Mhz).
|
||||
* \param bw is bandwidth (Unit hz).
|
||||
* \param antNumb is the number of antennas (range 1 ~ 8).
|
||||
* \param enFdd (0: TDD mode, 1: FDD mode).
|
||||
* \param enOrx (0: disable orx, 1: orx Lo follows Tx Lo, 2: orx Lo follows aux Lo).
|
||||
* \param en204C(0: 204B mode, 1: 204C mode).
|
||||
* \param enUcpLog(0: disable configture Log, 1: enable configture Log).
|
||||
*
|
||||
* \retval 0.
|
||||
*/
|
||||
extern int32_t UCP_API_RFIC_CellInit(uint64_t sampleRate,
|
||||
uint64_t bw,
|
||||
uint16_t antNumb,
|
||||
uint16_t enFdd,
|
||||
uint16_t enOrx,
|
||||
uint16_t en204C,
|
||||
uint16_t enUcpLog);
|
||||
/**
|
||||
* \brief Sets up the transceiver's tx rx LO frenq, bandwidth, Initialize attenuation.
|
||||
* then process Initialize transceiver
|
||||
*
|
||||
* \param txLo is Transmit local frequency (Unit hz).
|
||||
* \param rxLo is Receive local frequency (Unit hz).
|
||||
* \param initAtt is Initialize attenuation (Unit db, range 0 ~ 20).
|
||||
* \param initGain is Initialize rx Gain index (Unit db, range 183 ~ 255).
|
||||
* \param auxLo is orx local frequency (Unit hz).
|
||||
* \param calPara is paras for RX QEC、TX att cal and so on
|
||||
* \param enOrx (0: disable orx, 1: orx Lo follows Tx Lo, 2: orx Lo follows aux Lo).
|
||||
*
|
||||
* \retval 0.
|
||||
*/
|
||||
extern int32_t UCP_API_RFIC_CellSetup(uint64_t txLo, uint64_t rxLo, uint16_t initAtt,
|
||||
uint16_t initGain, uint64_t auxLo, uint16_t enOrx,
|
||||
ucp_rfic_calPara_t calPara);
|
||||
|
||||
/**
|
||||
* \brief delete cell.
|
||||
*
|
||||
* \param void.
|
||||
*
|
||||
* \retval void.
|
||||
*/
|
||||
extern int32_t UCP_API_RFIC_CellDelete(void);
|
||||
|
||||
//**********************************************************************************
|
||||
// chip option layer
|
||||
// TRANSCEIVER
|
||||
/**
|
||||
* \brief transceiver chip hardware reset.
|
||||
*
|
||||
* \param void.
|
||||
*
|
||||
* \retval void.
|
||||
*/
|
||||
extern int32_t UCP_API_TRANSCEIVER_Reset(void);
|
||||
|
||||
/**
|
||||
* \brief Sets up the transceiver's MGC Mod.
|
||||
*
|
||||
* \param en, if set 1, MGC Mode; set 0, AGC Mode.
|
||||
*
|
||||
* \retval 0.
|
||||
*/
|
||||
extern int32_t UCP_API_TRANSCEIVER_MGC_Cfg(uint8_t en);
|
||||
|
||||
/**
|
||||
* \brief Sets up the transceiver's rx gain at MGC mode.
|
||||
*
|
||||
* \param gain_db (Unit db, range 0~36, step 0.5db).
|
||||
*
|
||||
* \retval 0.
|
||||
*/
|
||||
extern int32_t UCP_API_TRANSCEIVER_Gain_Set(double gain_db);
|
||||
|
||||
/**
|
||||
* \brief Get the transceiver's rx gain.
|
||||
*
|
||||
* \param gain_db (Unit db, range 0~36, step 0.5db).
|
||||
*
|
||||
* \retval gain_db (Unit db, range 0~36, step 0.5db).
|
||||
*/
|
||||
extern double UCP_API_TRANSCEIVER_Gain_Get(void);
|
||||
|
||||
/**
|
||||
* \brief Set up the transceiver's tx attenuation.
|
||||
*
|
||||
* \param att_db (Unit db, range 0~20).
|
||||
*
|
||||
* \retval 0.
|
||||
*/
|
||||
extern int32_t UCP_API_TRANSCEIVER_Att_Set(uint8_t att_db);
|
||||
|
||||
/**
|
||||
* \brief Get the transceiver's tx attenuation.
|
||||
*
|
||||
* \retval att_db (Unit db, range 0~20).
|
||||
*/
|
||||
extern uint8_t UCP_API_TRANSCEIVER_Att_Get(void);
|
||||
|
||||
//**********************************************************************************
|
||||
// CLOCKGEN
|
||||
/**
|
||||
* \brief clockGen chip hardware reset.
|
||||
*
|
||||
* \param void.
|
||||
*
|
||||
* \retval void.
|
||||
*/
|
||||
extern void UCP_API_CLOCKGEN_Reset(void);
|
||||
|
||||
/**
|
||||
* \brief clockGen chip init function.
|
||||
*
|
||||
* \param void.
|
||||
*
|
||||
* \retval void.
|
||||
*/
|
||||
extern int32_t UCP_API_CLOCKGEN_Init(void);
|
||||
|
||||
/**
|
||||
* \brief Get the status of clockGen chip's pll.
|
||||
*
|
||||
* \param void.
|
||||
*
|
||||
* \retval lock code.
|
||||
*/
|
||||
extern uint8_t UCP_API_CLOCKGEN_LockStatus(void);
|
||||
|
||||
/**
|
||||
* \brief gpio of rf controlling
|
||||
*
|
||||
* \param setting
|
||||
*
|
||||
* \retval none.
|
||||
*/
|
||||
extern void UCP_API_GPIO_Tx (void);
|
||||
extern void UCP_API_GPIO_Rx (void);
|
||||
extern void UCP_API_GPIO_Off (void);
|
||||
extern void UCP_API_GPIO_OrxOn (void);
|
||||
extern void UCP_API_GPIO_OrxOff (void);
|
||||
extern void UCP_API_GPIO_TrigOn (void);
|
||||
extern void UCP_API_GPIO_TrigOff (void);
|
||||
|
||||
/**
|
||||
* \brief Get board's indx
|
||||
*
|
||||
* \param void
|
||||
*
|
||||
* \retval
|
||||
|
||||
HW_UNKNOW = 0
|
||||
HW_EVMT = 1
|
||||
HW_EVMF = 2
|
||||
HW_EVB = 3
|
||||
HW_EVMY = 4
|
||||
HW_OTHER = 254
|
||||
HW_MAX = 255
|
||||
|
||||
*/
|
||||
extern uint8_t UCP_API_RFIC_GetBoardInfo (void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* #ifndef UCP_API_RFIC_H_ */
|
||||
|
300
rfic/inc/xzJSON.h
Normal file
300
rfic/inc/xzJSON.h
Normal file
@ -0,0 +1,300 @@
|
||||
/*
|
||||
Copyright (c) 2009-2017 Dave Gamble and xzJSON contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef xzJSON__h
|
||||
#define xzJSON__h
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#if !defined(__WINDOWS__) && (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32))
|
||||
#define __WINDOWS__
|
||||
#endif
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
|
||||
/* When compiling for windows, we specify a specific calling convention to avoid issues where we are being called from a project with a different default calling convention. For windows you have 3 define options:
|
||||
|
||||
CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever dllexport symbols
|
||||
CJSON_EXPORT_SYMBOLS - Define this on library build when you want to dllexport symbols (default)
|
||||
CJSON_IMPORT_SYMBOLS - Define this if you want to dllimport symbol
|
||||
|
||||
For *nix builds that support visibility attribute, you can define similar behavior by
|
||||
|
||||
setting default visibility to hidden by adding
|
||||
-fvisibility=hidden (for gcc)
|
||||
or
|
||||
-xldscope=hidden (for sun cc)
|
||||
to CFLAGS
|
||||
|
||||
then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJSON_EXPORT_SYMBOLS does
|
||||
|
||||
*/
|
||||
|
||||
#define CJSON_CDECL __cdecl
|
||||
#define CJSON_STDCALL __stdcall
|
||||
|
||||
/* export symbols by default, this is necessary for copy pasting the C and header file */
|
||||
#if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) && !defined(CJSON_EXPORT_SYMBOLS)
|
||||
#define CJSON_EXPORT_SYMBOLS
|
||||
#endif
|
||||
|
||||
#if defined(CJSON_HIDE_SYMBOLS)
|
||||
#define XZJSON_PUBLIC(type) type CJSON_STDCALL
|
||||
#elif defined(CJSON_EXPORT_SYMBOLS)
|
||||
#define XZJSON_PUBLIC(type) __declspec(dllexport) type CJSON_STDCALL
|
||||
#elif defined(CJSON_IMPORT_SYMBOLS)
|
||||
#define XZJSON_PUBLIC(type) __declspec(dllimport) type CJSON_STDCALL
|
||||
#endif
|
||||
#else /* !__WINDOWS__ */
|
||||
#define CJSON_CDECL
|
||||
#define CJSON_STDCALL
|
||||
|
||||
#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(CJSON_API_VISIBILITY)
|
||||
#define XZJSON_PUBLIC(type) __attribute__((visibility("default"))) type
|
||||
#else
|
||||
#define XZJSON_PUBLIC(type) type
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* project version */
|
||||
#define CJSON_VERSION_MAJOR 1
|
||||
#define CJSON_VERSION_MINOR 7
|
||||
#define CJSON_VERSION_PATCH 16
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
/* xzJSON Types: */
|
||||
#define xzJSON_Invalid (0)
|
||||
#define xzJSON_False (1 << 0)
|
||||
#define xzJSON_True (1 << 1)
|
||||
#define xzJSON_NULL (1 << 2)
|
||||
#define xzJSON_Number (1 << 3)
|
||||
#define xzJSON_String (1 << 4)
|
||||
#define xzJSON_Array (1 << 5)
|
||||
#define xzJSON_Object (1 << 6)
|
||||
#define xzJSON_Raw (1 << 7) /* raw json */
|
||||
|
||||
#define xzJSON_IsReference 256
|
||||
#define xzJSON_StringIsConst 512
|
||||
|
||||
/* The xzJSON structure: */
|
||||
typedef struct xzJSON
|
||||
{
|
||||
/* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
|
||||
struct xzJSON *next;
|
||||
struct xzJSON *prev;
|
||||
/* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
|
||||
struct xzJSON *child;
|
||||
|
||||
/* The type of the item, as above. */
|
||||
int type;
|
||||
|
||||
/* The item's string, if type==xzJSON_String and type == xzJSON_Raw */
|
||||
char *valuestring;
|
||||
/* writing to valueint is DEPRECATED, use xzJSON_SetNumberValue instead */
|
||||
int valueint;
|
||||
/* The item's number, if type==xzJSON_Number */
|
||||
double valuedouble;
|
||||
|
||||
/* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
|
||||
char *string;
|
||||
} xzJSON;
|
||||
|
||||
typedef struct xzJSON_Hooks
|
||||
{
|
||||
/* malloc/free are CDECL on Windows regardless of the default calling convention of the compiler, so ensure the hooks allow passing those functions directly. */
|
||||
void *(CJSON_CDECL *malloc_fn)(size_t sz);
|
||||
void (CJSON_CDECL *free_fn)(void *ptr);
|
||||
} xzJSON_Hooks;
|
||||
|
||||
typedef int xzJSON_bool;
|
||||
|
||||
/* Limits how deeply nested arrays/objects can be before xzJSON rejects to parse them.
|
||||
* This is to prevent stack overflows. */
|
||||
#ifndef CJSON_NESTING_LIMIT
|
||||
#define CJSON_NESTING_LIMIT 1000
|
||||
#endif
|
||||
|
||||
/* returns the version of xzJSON as a string */
|
||||
XZJSON_PUBLIC(const char*) xzJSON_Version(void);
|
||||
|
||||
/* Supply malloc, realloc and free functions to xzJSON */
|
||||
XZJSON_PUBLIC(void) xzJSON_InitHooks(xzJSON_Hooks* hooks);
|
||||
|
||||
/* Memory Management: the caller is always responsible to free the results from all variants of xzJSON_Parse (with xzJSON_Delete) and xzJSON_Print (with stdlib free, xzJSON_Hooks.free_fn, or xzJSON_free as appropriate). The exception is xzJSON_PrintPreallocated, where the caller has full responsibility of the buffer. */
|
||||
/* Supply a block of JSON, and this returns a xzJSON object you can interrogate. */
|
||||
XZJSON_PUBLIC(xzJSON *) xzJSON_Parse(const char *value);
|
||||
XZJSON_PUBLIC(xzJSON *) xzJSON_ParseWithLength(const char *value, size_t buffer_length);
|
||||
/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */
|
||||
/* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match xzJSON_GetErrorPtr(). */
|
||||
XZJSON_PUBLIC(xzJSON *) xzJSON_ParseWithOpts(const char *value, const char **return_parse_end, xzJSON_bool require_null_terminated);
|
||||
XZJSON_PUBLIC(xzJSON *) xzJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end, xzJSON_bool require_null_terminated);
|
||||
|
||||
/* Render a xzJSON entity to text for transfer/storage. */
|
||||
XZJSON_PUBLIC(char *) xzJSON_Print(const xzJSON *item);
|
||||
/* Render a xzJSON entity to text for transfer/storage without any formatting. */
|
||||
XZJSON_PUBLIC(char *) xzJSON_PrintUnformatted(const xzJSON *item);
|
||||
/* Render a xzJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */
|
||||
XZJSON_PUBLIC(char *) xzJSON_PrintBuffered(const xzJSON *item, int prebuffer, xzJSON_bool fmt);
|
||||
/* Render a xzJSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure. */
|
||||
/* NOTE: xzJSON is not always 100% accurate in estimating how much memory it will use, so to be safe allocate 5 bytes more than you actually need */
|
||||
XZJSON_PUBLIC(xzJSON_bool) xzJSON_PrintPreallocated(xzJSON *item, char *buffer, const int length, const xzJSON_bool format);
|
||||
/* Delete a xzJSON entity and all subentities. */
|
||||
XZJSON_PUBLIC(void) xzJSON_Delete(xzJSON *item);
|
||||
|
||||
/* Returns the number of items in an array (or object). */
|
||||
XZJSON_PUBLIC(int) xzJSON_GetArraySize(const xzJSON *array);
|
||||
/* Retrieve item number "index" from array "array". Returns NULL if unsuccessful. */
|
||||
XZJSON_PUBLIC(xzJSON *) xzJSON_GetArrayItem(const xzJSON *array, int index);
|
||||
/* Get item "string" from object. Case insensitive. */
|
||||
XZJSON_PUBLIC(xzJSON *) xzJSON_GetObjectItem(const xzJSON * const object, const char * const string);
|
||||
XZJSON_PUBLIC(xzJSON *) xzJSON_GetObjectItemCaseSensitive(const xzJSON * const object, const char * const string);
|
||||
XZJSON_PUBLIC(xzJSON_bool) xzJSON_HasObjectItem(const xzJSON *object, const char *string);
|
||||
/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when xzJSON_Parse() returns 0. 0 when xzJSON_Parse() succeeds. */
|
||||
XZJSON_PUBLIC(const char *) xzJSON_GetErrorPtr(void);
|
||||
|
||||
/* Check item type and return its value */
|
||||
XZJSON_PUBLIC(char *) xzJSON_GetStringValue(const xzJSON * const item);
|
||||
XZJSON_PUBLIC(double) xzJSON_GetNumberValue(const xzJSON * const item);
|
||||
|
||||
/* These functions check the type of an item */
|
||||
XZJSON_PUBLIC(xzJSON_bool) xzJSON_IsInvalid(const xzJSON * const item);
|
||||
XZJSON_PUBLIC(xzJSON_bool) xzJSON_IsFalse(const xzJSON * const item);
|
||||
XZJSON_PUBLIC(xzJSON_bool) xzJSON_IsTrue(const xzJSON * const item);
|
||||
XZJSON_PUBLIC(xzJSON_bool) xzJSON_IsBool(const xzJSON * const item);
|
||||
XZJSON_PUBLIC(xzJSON_bool) xzJSON_IsNull(const xzJSON * const item);
|
||||
XZJSON_PUBLIC(xzJSON_bool) xzJSON_IsNumber(const xzJSON * const item);
|
||||
XZJSON_PUBLIC(xzJSON_bool) xzJSON_IsString(const xzJSON * const item);
|
||||
XZJSON_PUBLIC(xzJSON_bool) xzJSON_IsArray(const xzJSON * const item);
|
||||
XZJSON_PUBLIC(xzJSON_bool) xzJSON_IsObject(const xzJSON * const item);
|
||||
XZJSON_PUBLIC(xzJSON_bool) xzJSON_IsRaw(const xzJSON * const item);
|
||||
|
||||
/* These calls create a xzJSON item of the appropriate type. */
|
||||
XZJSON_PUBLIC(xzJSON *) xzJSON_CreateNull(void);
|
||||
XZJSON_PUBLIC(xzJSON *) xzJSON_CreateTrue(void);
|
||||
XZJSON_PUBLIC(xzJSON *) xzJSON_CreateFalse(void);
|
||||
XZJSON_PUBLIC(xzJSON *) xzJSON_CreateBool(xzJSON_bool boolean);
|
||||
XZJSON_PUBLIC(xzJSON *) xzJSON_CreateNumber(double num);
|
||||
XZJSON_PUBLIC(xzJSON *) xzJSON_CreateString(const char *string);
|
||||
/* raw json */
|
||||
XZJSON_PUBLIC(xzJSON *) xzJSON_CreateRaw(const char *raw);
|
||||
XZJSON_PUBLIC(xzJSON *) xzJSON_CreateArray(void);
|
||||
XZJSON_PUBLIC(xzJSON *) xzJSON_CreateObject(void);
|
||||
|
||||
/* Create a string where valuestring references a string so
|
||||
* it will not be freed by xzJSON_Delete */
|
||||
XZJSON_PUBLIC(xzJSON *) xzJSON_CreateStringReference(const char *string);
|
||||
/* Create an object/array that only references it's elements so
|
||||
* they will not be freed by xzJSON_Delete */
|
||||
XZJSON_PUBLIC(xzJSON *) xzJSON_CreateObjectReference(const xzJSON *child);
|
||||
XZJSON_PUBLIC(xzJSON *) xzJSON_CreateArrayReference(const xzJSON *child);
|
||||
|
||||
/* These utilities create an Array of count items.
|
||||
* The parameter count cannot be greater than the number of elements in the number array, otherwise array access will be out of bounds.*/
|
||||
XZJSON_PUBLIC(xzJSON *) xzJSON_CreateIntArray(const int *numbers, int count);
|
||||
XZJSON_PUBLIC(xzJSON *) xzJSON_CreateFloatArray(const float *numbers, int count);
|
||||
XZJSON_PUBLIC(xzJSON *) xzJSON_CreateDoubleArray(const double *numbers, int count);
|
||||
XZJSON_PUBLIC(xzJSON *) xzJSON_CreateStringArray(const char *const *strings, int count);
|
||||
|
||||
/* Append item to the specified array/object. */
|
||||
XZJSON_PUBLIC(xzJSON_bool) xzJSON_AddItemToArray(xzJSON *array, xzJSON *item);
|
||||
XZJSON_PUBLIC(xzJSON_bool) xzJSON_AddItemToObject(xzJSON *object, const char *string, xzJSON *item);
|
||||
/* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the xzJSON object.
|
||||
* WARNING: When this function was used, make sure to always check that (item->type & xzJSON_StringIsConst) is zero before
|
||||
* writing to `item->string` */
|
||||
XZJSON_PUBLIC(xzJSON_bool) xzJSON_AddItemToObjectCS(xzJSON *object, const char *string, xzJSON *item);
|
||||
/* Append reference to item to the specified array/object. Use this when you want to add an existing xzJSON to a new xzJSON, but don't want to corrupt your existing xzJSON. */
|
||||
XZJSON_PUBLIC(xzJSON_bool) xzJSON_AddItemReferenceToArray(xzJSON *array, xzJSON *item);
|
||||
XZJSON_PUBLIC(xzJSON_bool) xzJSON_AddItemReferenceToObject(xzJSON *object, const char *string, xzJSON *item);
|
||||
|
||||
/* Remove/Detach items from Arrays/Objects. */
|
||||
XZJSON_PUBLIC(xzJSON *) xzJSON_DetachItemViaPointer(xzJSON *parent, xzJSON * const item);
|
||||
XZJSON_PUBLIC(xzJSON *) xzJSON_DetachItemFromArray(xzJSON *array, int which);
|
||||
XZJSON_PUBLIC(void) xzJSON_DeleteItemFromArray(xzJSON *array, int which);
|
||||
XZJSON_PUBLIC(xzJSON *) xzJSON_DetachItemFromObject(xzJSON *object, const char *string);
|
||||
XZJSON_PUBLIC(xzJSON *) xzJSON_DetachItemFromObjectCaseSensitive(xzJSON *object, const char *string);
|
||||
XZJSON_PUBLIC(void) xzJSON_DeleteItemFromObject(xzJSON *object, const char *string);
|
||||
XZJSON_PUBLIC(void) xzJSON_DeleteItemFromObjectCaseSensitive(xzJSON *object, const char *string);
|
||||
|
||||
/* Update array items. */
|
||||
XZJSON_PUBLIC(xzJSON_bool) xzJSON_InsertItemInArray(xzJSON *array, int which, xzJSON *newitem); /* Shifts pre-existing items to the right. */
|
||||
XZJSON_PUBLIC(xzJSON_bool) xzJSON_ReplaceItemViaPointer(xzJSON * const parent, xzJSON * const item, xzJSON * replacement);
|
||||
XZJSON_PUBLIC(xzJSON_bool) xzJSON_ReplaceItemInArray(xzJSON *array, int which, xzJSON *newitem);
|
||||
XZJSON_PUBLIC(xzJSON_bool) xzJSON_ReplaceItemInObject(xzJSON *object,const char *string,xzJSON *newitem);
|
||||
XZJSON_PUBLIC(xzJSON_bool) xzJSON_ReplaceItemInObjectCaseSensitive(xzJSON *object,const char *string,xzJSON *newitem);
|
||||
|
||||
/* Duplicate a xzJSON item */
|
||||
XZJSON_PUBLIC(xzJSON *) xzJSON_Duplicate(const xzJSON *item, xzJSON_bool recurse);
|
||||
/* Duplicate will create a new, identical xzJSON item to the one you pass, in new memory that will
|
||||
* need to be released. With recurse!=0, it will duplicate any children connected to the item.
|
||||
* The item->next and ->prev pointers are always zero on return from Duplicate. */
|
||||
/* Recursively compare two xzJSON items for equality. If either a or b is NULL or invalid, they will be considered unequal.
|
||||
* case_sensitive determines if object keys are treated case sensitive (1) or case insensitive (0) */
|
||||
XZJSON_PUBLIC(xzJSON_bool) xzJSON_Compare(const xzJSON * const a, const xzJSON * const b, const xzJSON_bool case_sensitive);
|
||||
|
||||
/* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from strings.
|
||||
* The input pointer json cannot point to a read-only address area, such as a string constant,
|
||||
* but should point to a readable and writable address area. */
|
||||
XZJSON_PUBLIC(void) xzJSON_Minify(char *json);
|
||||
|
||||
/* Helper functions for creating and adding items to an object at the same time.
|
||||
* They return the added item or NULL on failure. */
|
||||
XZJSON_PUBLIC(xzJSON*) xzJSON_AddNullToObject(xzJSON * const object, const char * const name);
|
||||
XZJSON_PUBLIC(xzJSON*) xzJSON_AddTrueToObject(xzJSON * const object, const char * const name);
|
||||
XZJSON_PUBLIC(xzJSON*) xzJSON_AddFalseToObject(xzJSON * const object, const char * const name);
|
||||
XZJSON_PUBLIC(xzJSON*) xzJSON_AddBoolToObject(xzJSON * const object, const char * const name, const xzJSON_bool boolean);
|
||||
XZJSON_PUBLIC(xzJSON*) xzJSON_AddNumberToObject(xzJSON * const object, const char * const name, const double number);
|
||||
XZJSON_PUBLIC(xzJSON*) xzJSON_AddStringToObject(xzJSON * const object, const char * const name, const char * const string);
|
||||
XZJSON_PUBLIC(xzJSON*) xzJSON_AddRawToObject(xzJSON * const object, const char * const name, const char * const raw);
|
||||
XZJSON_PUBLIC(xzJSON*) xzJSON_AddObjectToObject(xzJSON * const object, const char * const name);
|
||||
XZJSON_PUBLIC(xzJSON*) xzJSON_AddArrayToObject(xzJSON * const object, const char * const name);
|
||||
|
||||
/* When assigning an integer value, it needs to be propagated to valuedouble too. */
|
||||
#define xzJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number))
|
||||
/* helper for the xzJSON_SetNumberValue macro */
|
||||
XZJSON_PUBLIC(double) xzJSON_SetNumberHelper(xzJSON *object, double number);
|
||||
#define xzJSON_SetNumberValue(object, number) ((object != NULL) ? xzJSON_SetNumberHelper(object, (double)number) : (number))
|
||||
/* Change the valuestring of a xzJSON_String object, only takes effect when type of object is xzJSON_String */
|
||||
XZJSON_PUBLIC(char*) xzJSON_SetValuestring(xzJSON *object, const char *valuestring);
|
||||
|
||||
/* If the object is not a boolean type this does nothing and returns xzJSON_Invalid else it returns the new type*/
|
||||
#define xzJSON_SetBoolValue(object, boolValue) ( \
|
||||
(object != NULL && ((object)->type & (xzJSON_False|xzJSON_True))) ? \
|
||||
(object)->type=((object)->type &(~(xzJSON_False|xzJSON_True)))|((boolValue)?xzJSON_True:xzJSON_False) : \
|
||||
xzJSON_Invalid\
|
||||
)
|
||||
|
||||
/* Macro for iterating over an array or object */
|
||||
#define xzJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
|
||||
|
||||
/* malloc/free objects using the malloc/free functions that have been set with xzJSON_InitHooks */
|
||||
XZJSON_PUBLIC(void *) xzJSON_malloc(size_t size);
|
||||
XZJSON_PUBLIC(void) xzJSON_free(void *object);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user