diff --git a/app/src/main.c b/app/src/main.c index 50573c2..834257f 100644 --- a/app/src/main.c +++ b/app/src/main.c @@ -18,6 +18,9 @@ #include #include #include +#include +#include +#include #include "ospLog.h" #include "ospShell.h" @@ -31,10 +34,61 @@ extern int32_t osp_set_taskcpu(uint8_t cpu, uint8_t pri); extern uint8_t osp_sw_queue_init(); #ifdef ENABLE_JESD_TEST -extern int32_t UCP_API_RFIC_CellInit(uint64_t bw); -extern int32_t UCP_API_RFIC_CellSetup(uint64_t txLo, uint64_t rxLo, uint16_t initAtt); +extern int32_t UCP_API_RFIC_CellInit(void); +extern int32_t UCP_API_RFIC_CellSetup(uint64_t txLo, uint64_t rxLo, uint64_t bw, uint16_t initAtt); #endif +#define RFIC_SEM_KEY 0x1027 +int32_t gi32_rfic_sem = 0; + +int32_t rfic_sem_create(void) +{ + int32_t i32_ret = 0; + + /* create sem */ + gi32_rfic_sem = semget((key_t)RFIC_SEM_KEY, 1, IPC_CREAT); + if (-1 == gi32_rfic_sem) + { + printf("rfic_sem_create semget error!\r\n"); + return -1; + } + + /* set value */ + i32_ret = semctl(gi32_rfic_sem, 0, SETVAL, 0); + if (-1 == i32_ret) + { + printf("rfic_sem_create semctrl error!\r\n"); + return -2; + } + return 0; +} + +int32_t rfic_sem_wait(int32_t sem_id, int8_t timeout) +{ + struct sembuf st_sem_buf; + struct timespec st_time; + int32_t i32_ret = 0; + + memset(&st_sem_buf, 0, sizeof(st_sem_buf)); + st_sem_buf.sem_num = 0; + st_sem_buf.sem_op = 1; + st_sem_buf.sem_flg = SEM_UNDO; + + memset(&st_time, 0, sizeof(st_time)); + st_time.tv_sec = timeout/1000; + st_time.tv_nsec = (timeout%1000)*1000000; + + if (-1 == timeout) + { + i32_ret = semop(sem_id, &st_sem_buf, 1); + } + else + { + i32_ret = semtimedop(sem_id, &st_sem_buf, 1, &st_time); + } + + return i32_ret; +} #define MAX_PARA_NUM 4 @@ -51,8 +105,27 @@ int32_t main(int32_t argc, char* argvp[]) sched_setaffinity(0,sizeof(cpu_set_t),&mask); #ifdef ENABLE_JESD_TEST - UCP_API_RFIC_CellInit(100000000u); - UCP_API_RFIC_CellSetup(2575770000u, 2575770000u, 0); + int32_t i32_ret = 0; + i32_ret = rfic_sem_create(); + if (0 != i32_ret) + { + printf("rfic_sem_create return error!\r\n"); + return -1; + } + + i32_ret = rfic_sem_wait(gi32_rfic_sem, -1); + if (0 != i32_ret) + { + printf("rfic_sem_wati return error!\r\n"); + return -2; + } +#endif + +#if 0 +#ifdef ENABLE_JESD_TEST + UCP_API_RFIC_CellInit(); + UCP_API_RFIC_CellSetup(2575770000u, 2575770000u, 100000000u, 0); +#endif #endif osp_init(); osp_set_taskcpu(7, 95); diff --git a/build.sh b/build.sh index 04ffb04..721d95d 100755 --- a/build.sh +++ b/build.sh @@ -40,6 +40,8 @@ done export DIR_ROOT=$(cd `dirname "$0"`;pwd) #echo "# script_dir:${DIR_ROOT}" export RFIC_DIR=${DIR_ROOT}/driver/rfic/adrv9026 +export CJSON_DIR=${DIR_ROOT}/driver/rfic/ucp/cJSON +export RFIC_APP_DIR=${DIR_ROOT}/rfic export BUILD_DIR=${DIR_ROOT}/build if [ -d ${BUILD_DIR} ]; then @@ -56,10 +58,18 @@ if [[ "${fronthaul_option}" == "jesd" ]]; then cp ${RFIC_DIR}/out/jesd/*.h ${DIR_ROOT}/interface mkdir -p ${BUILD_DIR} cp ${DIR_ROOT}/lib/*.a ${BUILD_DIR}/ + + cp ${BUILD_DIR}/librfic.a ${RFIC_APP_DIR}/lib/ + cp ${DIR_ROOT}/interface/ucp_api_rfic.h ${RFIC_APP_DIR}/inc/ + cp ${CJSON_DIR}/xzJSON.h ${RFIC_APP_DIR}/inc/ + + chmod +x build_rfic.sh + source ./build_rfic.sh + cp ${RFIC_APP_DIR}/build/*.out ${BUILD_DIR}/ fi cd ${DIR_ROOT}/ make cache_option=${cache_option} fronthaul_option=${fronthaul_option} test_option=${test_option} test_id=${case_id} cd ${DIR_ROOT}/lib -rm -rf *.* \ No newline at end of file +rm -rf *.* diff --git a/build_rfic.sh b/build_rfic.sh new file mode 100755 index 0000000..e4bb6ff --- /dev/null +++ b/build_rfic.sh @@ -0,0 +1,7 @@ +set -e + +pushd ./rfic +make clean +echo "start to build rfic.out and librfic_main.o" +make all +popd diff --git a/osp/src/osp.c b/osp/src/osp.c index 1bad7df..46e39d5 100644 --- a/osp/src/osp.c +++ b/osp/src/osp.c @@ -148,7 +148,7 @@ OSP_STATUS main(INT32 argc,char *argv[]) OSP_STATUS osp_init() { printf("lib build: %s %s\n", __DATE__, __TIME__); - printf("---application_platform_V2.1_2023_week31---\n"); + printf("---application_platform_V2.1_2023_week40---\n"); UCP_PRINT_DEBUG("starting OSP initializing..."); diff --git a/osp/src/ospLog.c b/osp/src/ospLog.c index 4d734cb..3c6208a 100644 --- a/osp/src/ospLog.c +++ b/osp/src/ospLog.c @@ -29,9 +29,9 @@ void *g_OspLogSem = NULL; int32_t osp_base_logid; uint32_t log_rand; -uint32_t g_ulApeLogMode = 0; /*0: ape log日志写入文件 1: 网口输出ape log 2:ape log日志shell打印输出*/ +uint32_t g_ulApeLogMode = 1; /*0: ape log日志写入文件 1: 网口输出ape log 2:ape log日志shell打印输出*/ /* 默认网口输出 */ uint32_t g_ulArmLogMode = 0; /*0: arm log日志写入文件 1: 网口输出arm log 2:arm log日志shell打印输出*/ -uint8_t g_ucPlatformMode = 0; /*0: platform log日志写入文件 1: 网口输出platform log 2:platform log日志shell打印输出*/ +uint8_t g_ucPlatformMode = 1; /*0: platform log日志写入文件 1: 网口输出platform log 2:platform log日志shell打印输出*/ uint8_t g_time_now[128]; uint8_t g_ucFflushEnable = 0; int32_t net_log_txudp_id = -1; /*吐网口log id*/ @@ -780,8 +780,8 @@ int8_t osp_log_mode_init() strcpy((char *)gst_server_log.path, "./log/"); gst_server_log.ulport = 32768; - ret = fprintf(fp,"ip:%s\r\nport:%u\napelog:%u\narmlog:%u\nlogpath:%s", \ - gst_server_log.ip, gst_server_log.ulport, g_ulApeLogMode, g_ulArmLogMode, gst_server_log.path); + ret = fprintf(fp,"ip:%s\r\nport:%u\napelog:%u\narmlog:%u\nplatformlog:%u\nlogpath:%s", \ + gst_server_log.ip, gst_server_log.ulport, g_ulApeLogMode, g_ulArmLogMode, g_ucPlatformMode, gst_server_log.path); if(ret < 0) { UCP_PRINT_ERROR("fwrite error ret:%d\n", ret); @@ -888,12 +888,17 @@ void osp_log_mode_get() continue; } if(strstr(buf, "armlog:")) - { + { g_ulArmLogMode = (uint32_t)(buf[7] - '0'); continue; } + if(strstr(buf, "platformlog:")) + { + g_ucPlatformMode = (uint32_t)(buf[12] - '0'); + continue; + } if(strstr(buf, "logpath:")) - { + { memset(gst_server_log.path, 0, 128); path = strtok((char *)(buf+8), "\r\n"); if(false == osp_path_is_null(path)) diff --git a/rfic/inc/typedef.h b/rfic/inc/typedef.h new file mode 100644 index 0000000..74b4889 --- /dev/null +++ b/rfic/inc/typedef.h @@ -0,0 +1,31 @@ +// +FHDR------------------------------------------------------------ +// Copyright (c) 2022 SmartLogic. +// ALL RIGHTS RESERVED +// ----------------------------------------------------------------- +// Filename : typedef.h +// Author : xianfeng.du +// Created On : 2022-06-25 +// Last Modified : +// ----------------------------------------------------------------- +// Description: +// +// +// -FHDR------------------------------------------------------------ + +#ifndef __TYPEDEF_H__ +#define __TYPEDEF_H__ + +//Types definitions +//typedef unsigned char bool; +typedef unsigned char uint8_t; +typedef signed char int8_t; +typedef short int int16_t; +typedef unsigned short int uint16_t; +typedef int int32_t; +typedef unsigned int uint32_t; +typedef long int int64_t; +typedef unsigned long int uint64_t; +//typedef long long int int64_t; +//typedef unsigned long long int uint64_t; + +#endif diff --git a/rfic/makefile b/rfic/makefile new file mode 100644 index 0000000..85e95b7 --- /dev/null +++ b/rfic/makefile @@ -0,0 +1,142 @@ +#======================================================================================================== +# stc makefile +# #FileName: makefile +#Author: xianfeng.du +#Data: 2022-08-10 +#Description: top makefile +#======================================================================================================== +VERSION = 1.00 + +OPTION ?= +ifeq ($(OPTION),GCC) + CROSS_CC ?= +else +# TOOLS ?= /opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin +# CROSS_CC ?= $(TOOLS)/aarch64-linux-gnu- + CROSS_CC ?= aarch64-linux-gnu- +endif + +AR = ar +CC = $(CROSS_CC)gcc +#$(info "CC=" $(CC)) + +git_id ?= $(shell git log -1 --format="%H") +commit_ts ?= $(shell git log -1 --format="%ct") +commit_time ?= $(shell date -d@$(commit_ts) +"%Y-%m-%d-%H:%M:%S") +#git_cmit ?= $(shell date +"%Y-%m-%d::%H:%M:%S") + +$(info "commit_ts=" $(commit_ts)) +$(info "commit_time=" $(commit_time)) + +DEFINES ?= RFIC_VER=\"commit_id:$(git_id),commit_time:$(commit_time)\" + +#optimization level -O2 +C_OPT_FLAGS ?= -O2 + +CC_FLAGS ?= $(C_OPT_FLAGS) -Wall -g +CC_FLAGS += -Werror -Wno-unused-function +CC_FLAGS += $(foreach d,$(DEFINES),-D$(d)) +CC_FLAGS += -fPIC + +LIB_DIRS ?= ../lib + +SRC_DIRS ?= ./src + +INCLUDE_DIRS ?= ./inc + +LD_FLAGS ?= -lgcc -lc +LD_FLAGS += -lm -ldl -Wl,-rpath=./ +LD_FLAGS += -lpthread +LD_FLAGS += ./lib/librfic.a +LD_FLAGS += -rdynamic -funwind-tables -ffunction-sections + +$(info "DEFINES=" $(DEFINES)) + +#Flatten files and remove the duplicate by sort +ABS_SRC_DIRS := $(foreach d,$(SRC_DIRS),$(abspath $(d))) + +SRC_FILES := $(foreach d,$(ABS_SRC_DIRS),$(wildcard $(d)/*.c)) + +#main.c +MAIN_DIR := ./src +MAIN_FILE := ./src/main.c + +# Allow certain files to be excluded from the build +EXCL_SRCS ?= $(MAIN_FILE) + +# Filter source files (allow files to be excluded) +FINAL_SRCS_FILES += $(foreach f,$(SRC_FILES),$(if $(findstring $(abspath $(f)),$(abspath $(EXCL_SRCS))),,$(f))) +#$(info "FINAL_SRCS_FILES=" $(FINAL_SRCS_FILES)) + +# ============================================================================== +# Variables: Output Files +# ============================================================================== +BUILD_DIR := ./build +OBJ_MAIN_DIR := $(BUILD_DIR)/main +OBJ_DIR := $(BUILD_DIR)/obj +BIN_FILE := $(BUILD_DIR)/rfic.out +LIB_FILE := $(BUILD_DIR)/librfic_main.a +BJ_FILES += $(foreach f,$(FINAL_SRCS_FILES),$(OBJ_DIR)/$(patsubst %.c,%.o,$(notdir $(f)))) +OBJ_MAIN_FILES += $(foreach f,$(MAIN_FILE),$(OBJ_MAIN_DIR)/$(patsubst %.c,%.o,$(notdir $(f)))) + +# ============================================================================== +# Rules: Compilation +# ============================================================================== +define DO_BUILD_OBJ +$(2)/%.o: $(1)/%.c | $(2) + @echo "# Compiling $$< -> $$@" + $(CC) $(CC_FLAGS) -o $$@ -c $$< $(patsubst %,-I %,$(INCLUDE_DIRS)) +#OBJ_TGTS += $(foreach f,$(wildcard $(1)/*.c),$(OBJ_DIR)/$(notdir $(basename $(1)))/$(patsubst %.c,%.o,$(notdir $(f)))) +endef + +define DO_BUILD_DIR +$(1): + @echo "# Creating directory $$@" + mkdir -p $$@ +endef + +define DO_BUILD + $(eval $(call DO_BUILD_DIR,$(1))) + $(foreach d,$(sort $(2)),$(eval $(call DO_BUILD_OBJ,$(d),$(1)))) +endef + +$(eval $(call DO_BUILD,$(OBJ_DIR),$(ABS_SRC_DIRS))) +$(eval $(call DO_BUILD,$(OBJ_MAIN_DIR), $(abspath $(MAIN_DIR)))) + +$(BIN_FILE):$(OBJ_FILES) $(OBJ_MAIN_FILES) +# @echo "# Creating bin directory $(BIN_DIR)" +# mkdir -p $(BIN_DIR) + + @echo "# Linking objects to form $@" + $(CC) -o $@ $^ $(LD_FLAGS) $(patsubst %,-L %,$(LIB_DIRS)) +# $(CC) -o $@ $^ $(LD_FLAGS) -T$(LINK_FILE) + +$(LIB_FILE):$(OBJ_FILES) $(RFIC_OBJ_FILES) +# @echo "# Creating lib directory $(LIB_DIR)" +# mkdir -p $(LIB_DIR) + + @echo "# Linking objects to form $@" + $(AR) -rcs $@ $^ +# $(CC) -shared -o $@ $^ $(LD_FLAGS) + +# ============================================================================== +# Rules: Targets +# ============================================================================== +.DEFAULT_GOAL := all +.PHONY: build lib clean +all: build lib + +build: $(BIN_FILE) + +lib: $(LIB_FILE) + +clean: + @echo "deleted all files" + rm -rf $(BUILD_DIR) + #rm -rf ./lib/librfic.a + #rm -rf ./inc/ucp_api_rfic.h + #rm -rf ./inc/xzJSON.h + + + + diff --git a/rfic/src/main.c b/rfic/src/main.c new file mode 100644 index 0000000..eddef42 --- /dev/null +++ b/rfic/src/main.c @@ -0,0 +1,150 @@ +// +FHDR------------------------------------------------------------ +// Copyright (c) 2022 SmartLogic. +// ALL RIGHTS RESERVED +// ----------------------------------------------------------------- +// Filename : main.c +// Author : lishuang.xie +// Created On : 2023-09-18 +// Last Modified : +// ----------------------------------------------------------------- +// Description: +// +// rfic function +// +// -FHDR------------------------------------------------------------ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include "../inc/typedef.h" +#include "../inc/ucp_api_rfic.h" +#include "../inc/xzJSON.h" + +#define RFIC_CFG_FILE_PATH "/lib/firmware/resources/ucp_rfic_cfg.json" +#define RFIC_SEM_KEY 0x1027 + +typedef struct ucp_rfic_cfg_info +{ + uint64_t txLo; + uint64_t rxLo; + uint64_t bw; + uint16_t initAtt; +}ucp_rfic_cfg_info_t; + +#if 1 +extern xzJSON* ucp_jsonLoad (const char *fileName); +extern xzJSON* xzJSON_GetObjectItem(const xzJSON * const object, const char * const string); + + +ucp_rfic_cfg_info_t rfic_get_cfg_info() +{ + ucp_rfic_cfg_info_t st_rfic_cfg; + xzJSON *root = NULL; + xzJSON *item = NULL; + xzJSON *config = NULL; + + root = ucp_jsonLoad(RFIC_CFG_FILE_PATH); + if (((xzJSON*)NULL) == root) + { + printf("rfic_get_cfg_info: load file error!\r\n"); + exit(1); + } + + item = xzJSON_GetObjectItem(root, "common"); + config = xzJSON_GetObjectItem(item, "txLo"); + st_rfic_cfg.txLo = config->valuedouble; + config = xzJSON_GetObjectItem(item, "rxLo"); + st_rfic_cfg.rxLo = config->valuedouble; + config = xzJSON_GetObjectItem(item, "bw"); + st_rfic_cfg.bw = config->valuedouble; + config = xzJSON_GetObjectItem(item, "initAtt"); + st_rfic_cfg.initAtt = config->valueint; + xzJSON_Delete(root); + + return st_rfic_cfg; +} +#endif + + +int32_t gi32_rfic_sem = 0; + +int32_t rfic_sem_create(void) +{ + int32_t i32_ret = 0; + + /* create sem */ + gi32_rfic_sem = semget((key_t)RFIC_SEM_KEY, 1, IPC_CREAT); + if (-1 == gi32_rfic_sem) + { + printf("rfic_sem_create semget error!\r\n"); + return -1; + } + + /* set value */ + i32_ret = semctl(gi32_rfic_sem, 0, SETVAL, 0); + if (-1 == i32_ret) + { + printf("rfic_sem_create semctrl error!\r\n"); + return -2; + } + return 0; +} + +int32_t rfic_sem_post(int32_t sem_id) +{ + int32_t i32_ret = 0; + struct sembuf st_sem_buf; + memset(&st_sem_buf, 0, sizeof(st_sem_buf)); + st_sem_buf.sem_num = 0; + st_sem_buf.sem_op = 1; + st_sem_buf.sem_flg = SEM_UNDO; + + i32_ret = semop(sem_id, &st_sem_buf, 1); + if (-1 == i32_ret) + { + printf("rfic_sem_post semop return error!\r\n"); + return -1; + } + + return 0; +} + +int32_t main(int32_t argc, char* argvp[]) +{ + ucp_rfic_cfg_info_t st_rfic_cfg_info; + + /* create sem */ + int32_t i32_ret = rfic_sem_create(); + if (0 != i32_ret) + { + printf("rfic_sem_create return %d\r\n", i32_ret); + return -1; + } + +#if 1 + st_rfic_cfg_info = rfic_get_cfg_info(); + printf("para: txLo:%ld, rxLo:%ld, bw:%ld, initAtt:%d\r\n", + st_rfic_cfg_info.txLo, + st_rfic_cfg_info.rxLo, + st_rfic_cfg_info.bw, + st_rfic_cfg_info.initAtt); +#endif + /* call jesd init function */ + UCP_API_RFIC_CellInit(st_rfic_cfg_info.bw); + UCP_API_RFIC_CellSetup(st_rfic_cfg_info.txLo, st_rfic_cfg_info.rxLo, st_rfic_cfg_info.initAtt); + //UCP_API_RFIC_CellSetup(2575770000u, 2575770000u, 0); + + /* post sem */ + i32_ret = rfic_sem_post(gi32_rfic_sem); + if (0 != i32_ret) + { + printf("rfic_sem_post return %d\r\n", i32_ret); + return -2; + } + + return 0; +} + + diff --git a/rfic/ucp_rfic_cfg.json b/rfic/ucp_rfic_cfg.json new file mode 100644 index 0000000..7de7122 --- /dev/null +++ b/rfic/ucp_rfic_cfg.json @@ -0,0 +1,8 @@ +{ + "common": { + "txLo": 2575770000, + "rxLo": 2575770000, + "bw": 100000000, + "initAtt": 0 + } +}