51 changed files with 463 additions and 405 deletions
+4 -1
View File
@@ -54,4 +54,7 @@ dkms.conf
# MacOS .DS_Store file # MacOS .DS_Store file
**/.DS_Store **/.DS_Store
**/._.DS_Store **/._.DS_Store
# Ignore handout files
handout/
+4
View File
@@ -1,10 +1,14 @@
DIR := $(shell pwd) DIR := $(shell pwd)
compile_test: compile_test:
cd $(DIR)/df_datalink_sp/bsp && make all
cd $(DIR)/df_datalink_sp/build && make all cd $(DIR)/df_datalink_sp/build && make all
cd $(DIR)/df_datalink_ge/bsp && make all
cd $(DIR)/df_datalink_ge/build && make all cd $(DIR)/df_datalink_ge/build && make all
clean: clean:
cd $(DIR)/df_datalink_sp/bsp && make clean
cd $(DIR)/df_datalink_sp/build && make clean cd $(DIR)/df_datalink_sp/build && make clean
cd $(DIR)/df_datalink_ge/bsp && make clean
cd $(DIR)/df_datalink_ge/build && make clean cd $(DIR)/df_datalink_ge/build && make clean
.PHONY: clean compile_test .PHONY: clean compile_test
@@ -2,28 +2,28 @@
# Automatically-generated file. Do not edit! # Automatically-generated file. Do not edit!
################################################################################ ################################################################################
# Add inputs and outputs from these tool invocations to the build variables # Add inputs and outputs from these tool invocations to the build variables
C_SRCS += \ C_SRCS += \
../src/dev_profile/global_timer_profile.c \ ../src/dev_profile/global_timer_profile.c \
../src/dev_profile/intc_profile.c \ ../src/dev_profile/intc_profile.c \
../src/dev_profile/timer_profile.c ../src/dev_profile/timer_profile.c
OBJS += \ OBJS += \
./src/dev_profile/global_timer_profile.o \ ./src/dev_profile/global_timer_profile.o \
./src/dev_profile/intc_profile.o \ ./src/dev_profile/intc_profile.o \
./src/dev_profile/timer_profile.o ./src/dev_profile/timer_profile.o
C_DEPS += \ C_DEPS += \
./src/dev_profile/global_timer_profile.d \ ./src/dev_profile/global_timer_profile.d \
./src/dev_profile/intc_profile.d \ ./src/dev_profile/intc_profile.d \
./src/dev_profile/timer_profile.d ./src/dev_profile/timer_profile.d
# Each subdirectory must supply rules for building sources it contributes # Each subdirectory must supply rules for building sources it contributes
src/dev_profile/%.o: ../src/dev_profile/%.c src/dev_profile/%.o: ../src/dev_profile/%.c
@echo 'Building file: $<' @echo 'Building file: $<'
@echo 'Invoking: ARM v7 gcc compiler' @echo 'Invoking: ARM v7 gcc compiler'
$(CC) -Wall -O0 -g3 -I../bsp/ps7_cortexa9_0/include -I../src/include -c -fmessage-length=0 -MT"$@" -mcpu=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<" $(CC) -std=c17 -pedantic -Wall -O0 -g3 -I../bsp/ps7_cortexa9_0/include -I../src/include -c -fmessage-length=0 -MT"$@" -mcpu=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
@echo 'Finished building: $<' @echo 'Finished building: $<'
@echo ' ' @echo ' '
+1 -1
View File
@@ -20,7 +20,7 @@ C_DEPS += \
src/systembus/%.o: ../src/systembus/%.c src/systembus/%.o: ../src/systembus/%.c
@echo 'Building file: $<' @echo 'Building file: $<'
@echo 'Invoking: ARM v7 gcc compiler' @echo 'Invoking: ARM v7 gcc compiler'
$(CC) -Wall -O0 -g3 -I../bsp/ps7_cortexa9_0/include -I../src/include -c -fmessage-length=0 -MT"$@" -mcpu=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<" $(CC) -std=c17 -pedantic -Wall -O0 -g3 -I../bsp/ps7_cortexa9_0/include -I../src/include -c -fmessage-length=0 -MT"$@" -mcpu=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
@echo 'Finished building: $<' @echo 'Finished building: $<'
@echo ' ' @echo ' '
@@ -2,28 +2,28 @@
# Automatically-generated file. Do not edit! # Automatically-generated file. Do not edit!
################################################################################ ################################################################################
# Add inputs and outputs from these tool invocations to the build variables # Add inputs and outputs from these tool invocations to the build variables
C_SRCS += \ C_SRCS += \
../src/networking/link_layer/geometry/coord.c \ ../src/networking/link_layer/geometry/coord.c \
../src/networking/link_layer/geometry/eulerangles.c \ ../src/networking/link_layer/geometry/eulerangles.c \
../src/networking/link_layer/geometry/quaternion.c ../src/networking/link_layer/geometry/quaternion.c
OBJS += \ OBJS += \
./src/networking/link_layer/geometry/coord.o \ ./src/networking/link_layer/geometry/coord.o \
./src/networking/link_layer/geometry/eulerangles.o \ ./src/networking/link_layer/geometry/eulerangles.o \
./src/networking/link_layer/geometry/quaternion.o ./src/networking/link_layer/geometry/quaternion.o
C_DEPS += \ C_DEPS += \
./src/networking/link_layer/geometry/coord.d \ ./src/networking/link_layer/geometry/coord.d \
./src/networking/link_layer/geometry/eulerangles.d \ ./src/networking/link_layer/geometry/eulerangles.d \
./src/networking/link_layer/geometry/quaternion.d ./src/networking/link_layer/geometry/quaternion.d
# Each subdirectory must supply rules for building sources it contributes # Each subdirectory must supply rules for building sources it contributes
src/networking/link_layer/geometry/%.o: ../src/networking/link_layer/geometry/%.c src/networking/link_layer/geometry/%.o: ../src/networking/link_layer/geometry/%.c
@echo 'Building file: $<' @echo 'Building file: $<'
@echo 'Invoking: ARM v7 gcc compiler' @echo 'Invoking: ARM v7 gcc compiler'
$(CC) -Wall -O0 -g3 -I../bsp/ps7_cortexa9_0/include -I../src/include -c -fmessage-length=0 -MT"$@" -mcpu=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<" $(CC) -std=c17 -pedantic -Wall -O0 -g3 -I../bsp/ps7_cortexa9_0/include -I../src/include -c -fmessage-length=0 -MT"$@" -mcpu=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
@echo 'Finished building: $<' @echo 'Finished building: $<'
@echo ' ' @echo ' '
@@ -2,7 +2,7 @@
# Automatically-generated file. Do not edit! # Automatically-generated file. Do not edit!
################################################################################ ################################################################################
# Add inputs and outputs from these tool invocations to the build variables # Add inputs and outputs from these tool invocations to the build variables
C_SRCS += \ C_SRCS += \
../src/networking/link_layer/framing.c \ ../src/networking/link_layer/framing.c \
../src/networking/link_layer/link_layer.c \ ../src/networking/link_layer/link_layer.c \
@@ -11,7 +11,7 @@ C_SRCS += \
../src/networking/link_layer/scan.c \ ../src/networking/link_layer/scan.c \
../src/networking/link_layer/schdevent.c \ ../src/networking/link_layer/schdevent.c \
../src/networking/link_layer/service.c \ ../src/networking/link_layer/service.c \
../src/networking/link_layer/time_sync.c ../src/networking/link_layer/time_sync.c
OBJS += \ OBJS += \
./src/networking/link_layer/framing.o \ ./src/networking/link_layer/framing.o \
@@ -21,7 +21,7 @@ OBJS += \
./src/networking/link_layer/scan.o \ ./src/networking/link_layer/scan.o \
./src/networking/link_layer/schdevent.o \ ./src/networking/link_layer/schdevent.o \
./src/networking/link_layer/service.o \ ./src/networking/link_layer/service.o \
./src/networking/link_layer/time_sync.o ./src/networking/link_layer/time_sync.o
C_DEPS += \ C_DEPS += \
./src/networking/link_layer/framing.d \ ./src/networking/link_layer/framing.d \
@@ -31,14 +31,14 @@ C_DEPS += \
./src/networking/link_layer/scan.d \ ./src/networking/link_layer/scan.d \
./src/networking/link_layer/schdevent.d \ ./src/networking/link_layer/schdevent.d \
./src/networking/link_layer/service.d \ ./src/networking/link_layer/service.d \
./src/networking/link_layer/time_sync.d ./src/networking/link_layer/time_sync.d
# Each subdirectory must supply rules for building sources it contributes # Each subdirectory must supply rules for building sources it contributes
src/networking/link_layer/%.o: ../src/networking/link_layer/%.c src/networking/link_layer/%.o: ../src/networking/link_layer/%.c
@echo 'Building file: $<' @echo 'Building file: $<'
@echo 'Invoking: ARM v7 gcc compiler' @echo 'Invoking: ARM v7 gcc compiler'
$(CC) -Wall -O0 -g3 -I../bsp/ps7_cortexa9_0/include -I../src/include -c -fmessage-length=0 -MT"$@" -mcpu=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<" $(CC) -std=c17 -pedantic -Wall -O0 -g3 -I../bsp/ps7_cortexa9_0/include -I../src/include -c -fmessage-length=0 -MT"$@" -mcpu=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
@echo 'Finished building: $<' @echo 'Finished building: $<'
@echo ' ' @echo ' '
@@ -2,25 +2,25 @@
# Automatically-generated file. Do not edit! # Automatically-generated file. Do not edit!
################################################################################ ################################################################################
# Add inputs and outputs from these tool invocations to the build variables # Add inputs and outputs from these tool invocations to the build variables
C_SRCS += \ C_SRCS += \
../src/networking/phy_layer/phy_antenna.c \ ../src/networking/phy_layer/phy_antenna.c \
../src/networking/phy_layer/phy_layer.c ../src/networking/phy_layer/phy_layer.c
OBJS += \ OBJS += \
./src/networking/phy_layer/phy_antenna.o \ ./src/networking/phy_layer/phy_antenna.o \
./src/networking/phy_layer/phy_layer.o ./src/networking/phy_layer/phy_layer.o
C_DEPS += \ C_DEPS += \
./src/networking/phy_layer/phy_antenna.d \ ./src/networking/phy_layer/phy_antenna.d \
./src/networking/phy_layer/phy_layer.d ./src/networking/phy_layer/phy_layer.d
# Each subdirectory must supply rules for building sources it contributes # Each subdirectory must supply rules for building sources it contributes
src/networking/phy_layer/%.o: ../src/networking/phy_layer/%.c src/networking/phy_layer/%.o: ../src/networking/phy_layer/%.c
@echo 'Building file: $<' @echo 'Building file: $<'
@echo 'Invoking: ARM v7 gcc compiler' @echo 'Invoking: ARM v7 gcc compiler'
$(CC) -Wall -O0 -g3 -I../bsp/ps7_cortexa9_0/include -I../src/include -c -fmessage-length=0 -MT"$@" -mcpu=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<" $(CC) -std=c17 -pedantic -Wall -O0 -g3 -I../bsp/ps7_cortexa9_0/include -I../src/include -c -fmessage-length=0 -MT"$@" -mcpu=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
@echo 'Finished building: $<' @echo 'Finished building: $<'
@echo ' ' @echo ' '
+6 -6
View File
@@ -2,28 +2,28 @@
# Automatically-generated file. Do not edit! # Automatically-generated file. Do not edit!
################################################################################ ################################################################################
# Add inputs and outputs from these tool invocations to the build variables # Add inputs and outputs from these tool invocations to the build variables
LD_SRCS += \ LD_SRCS += \
../src/lscript.ld ../src/lscript.ld
C_SRCS += \ C_SRCS += \
../src/main.c \ ../src/main.c \
../src/system_monitor.c ../src/system_monitor.c
OBJS += \ OBJS += \
./src/main.o \ ./src/main.o \
./src/system_monitor.o ./src/system_monitor.o
C_DEPS += \ C_DEPS += \
./src/main.d \ ./src/main.d \
./src/system_monitor.d ./src/system_monitor.d
# Each subdirectory must supply rules for building sources it contributes # Each subdirectory must supply rules for building sources it contributes
src/%.o: ../src/%.c src/%.o: ../src/%.c
@echo 'Building file: $<' @echo 'Building file: $<'
@echo 'Invoking: ARM v7 gcc compiler' @echo 'Invoking: ARM v7 gcc compiler'
$(CC) -Wall -O0 -g3 -I../bsp/ps7_cortexa9_0/include -I../src/include -c -fmessage-length=0 -MT"$@" -mcpu=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<" $(CC) -std=c17 -pedantic -Wall -O0 -g3 -I../bsp/ps7_cortexa9_0/include -I../src/include -c -fmessage-length=0 -MT"$@" -mcpu=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
@echo 'Finished building: $<' @echo 'Finished building: $<'
@echo ' ' @echo ' '
+5 -5
View File
@@ -2,22 +2,22 @@
# Automatically-generated file. Do not edit! # Automatically-generated file. Do not edit!
################################################################################ ################################################################################
# Add inputs and outputs from these tool invocations to the build variables # Add inputs and outputs from these tool invocations to the build variables
C_SRCS += \ C_SRCS += \
../src/time_ctrl/time_ctrl.c ../src/time_ctrl/time_ctrl.c
OBJS += \ OBJS += \
./src/time_ctrl/time_ctrl.o ./src/time_ctrl/time_ctrl.o
C_DEPS += \ C_DEPS += \
./src/time_ctrl/time_ctrl.d ./src/time_ctrl/time_ctrl.d
# Each subdirectory must supply rules for building sources it contributes # Each subdirectory must supply rules for building sources it contributes
src/time_ctrl/%.o: ../src/time_ctrl/%.c src/time_ctrl/%.o: ../src/time_ctrl/%.c
@echo 'Building file: $<' @echo 'Building file: $<'
@echo 'Invoking: ARM v7 gcc compiler' @echo 'Invoking: ARM v7 gcc compiler'
$(CC) -Wall -O0 -g3 -I../bsp/ps7_cortexa9_0/include -I../src/include -c -fmessage-length=0 -MT"$@" -mcpu=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<" $(CC) -std=c17 -pedantic -Wall -O0 -g3 -I../bsp/ps7_cortexa9_0/include -I../src/include -c -fmessage-length=0 -MT"$@" -mcpu=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
@echo 'Finished building: $<' @echo 'Finished building: $<'
@echo ' ' @echo ' '
+5 -5
View File
@@ -2,14 +2,14 @@
# Automatically-generated file. Do not edit! # Automatically-generated file. Do not edit!
################################################################################ ################################################################################
# Add inputs and outputs from these tool invocations to the build variables # Add inputs and outputs from these tool invocations to the build variables
C_SRCS += \ C_SRCS += \
../src/util/circ_queue.c \ ../src/util/circ_queue.c \
../src/util/clist.c \ ../src/util/clist.c \
../src/util/common.c \ ../src/util/common.c \
../src/util/crc.c \ ../src/util/crc.c \
../src/util/list.c \ ../src/util/list.c \
../src/util/util.c ../src/util/util.c
OBJS += \ OBJS += \
./src/util/circ_queue.o \ ./src/util/circ_queue.o \
@@ -17,7 +17,7 @@ OBJS += \
./src/util/common.o \ ./src/util/common.o \
./src/util/crc.o \ ./src/util/crc.o \
./src/util/list.o \ ./src/util/list.o \
./src/util/util.o ./src/util/util.o
C_DEPS += \ C_DEPS += \
./src/util/circ_queue.d \ ./src/util/circ_queue.d \
@@ -25,14 +25,14 @@ C_DEPS += \
./src/util/common.d \ ./src/util/common.d \
./src/util/crc.d \ ./src/util/crc.d \
./src/util/list.d \ ./src/util/list.d \
./src/util/util.d ./src/util/util.d
# Each subdirectory must supply rules for building sources it contributes # Each subdirectory must supply rules for building sources it contributes
src/util/%.o: ../src/util/%.c src/util/%.o: ../src/util/%.c
@echo 'Building file: $<' @echo 'Building file: $<'
@echo 'Invoking: ARM v7 gcc compiler' @echo 'Invoking: ARM v7 gcc compiler'
$(CC) -Wall -O0 -g3 -I../bsp/ps7_cortexa9_0/include -I../src/include -c -fmessage-length=0 -MT"$@" -mcpu=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<" $(CC) -std=c17 -pedantic -Wall -O0 -g3 -I../bsp/ps7_cortexa9_0/include -I../src/include -c -fmessage-length=0 -MT"$@" -mcpu=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
@echo 'Finished building: $<' @echo 'Finished building: $<'
@echo ' ' @echo ' '
+1 -1
View File
@@ -39,7 +39,7 @@
#define APP_EMULATE_DATA #define APP_EMULATE_DATA
#define DATALINK_ENABLE_AUTORECONNECT #define DATALINK_ENABLE_AUTORECONNECT
#define DATALINK_ENABLE_AUTOTIMESYNC #define DATALINK_ENABLE_AUTOTIMESYNC
//#define DATALINK_ENABLE_BERTEST #define DATALINK_ENABLE_BERTEST 10
/************ Hardware Configs ************/ /************ Hardware Configs ************/
+41 -25
View File
@@ -278,7 +278,7 @@ static int32_t Mpc_SystemConfig(MPC *instPtr, uint8_t *msg)
* @param InstPtr A double pointer to MPC instance. * @param InstPtr A double pointer to MPC instance.
* @param config A pointer to MPC configurations. * @param config A pointer to MPC configurations.
* *
* @return None. * @return Error code.
* *
******************************************************************************/ ******************************************************************************/
int32_t Mpc_Init(MPC **instPtr, MPC_CONFIG *config) int32_t Mpc_Init(MPC **instPtr, MPC_CONFIG *config)
@@ -290,7 +290,7 @@ int32_t Mpc_Init(MPC **instPtr, MPC_CONFIG *config)
(*instPtr) = malloc(sizeof(MPC)); (*instPtr) = malloc(sizeof(MPC));
if ((*instPtr) == NULL) if ((*instPtr) == NULL)
{ {
return FAILURE; return ENOMEM;
} }
(*instPtr)->rxQueue = NULL; (*instPtr)->rxQueue = NULL;
(*instPtr)->txQueue = NULL; (*instPtr)->txQueue = NULL;
@@ -307,14 +307,15 @@ int32_t Mpc_Init(MPC **instPtr, MPC_CONFIG *config)
bramConfigPtr = XBram_LookupConfig(config->bramId); bramConfigPtr = XBram_LookupConfig(config->bramId);
if (bramConfigPtr == NULL) if (bramConfigPtr == NULL)
{ {
Status = EDCONF; Mpc_Destroy(*instPtr);
goto mpc_init_error; return EDCONF;
} }
Status = XBram_CfgInitialize(&mpcBram, bramConfigPtr, Status = XBram_CfgInitialize(&mpcBram, bramConfigPtr,
bramConfigPtr->CtrlBaseAddress); bramConfigPtr->CtrlBaseAddress);
if (Status != SUCCESS) if (Status != SUCCESS)
{ {
goto mpc_init_error; Mpc_Destroy(*instPtr);
return Status;
} }
/* /*
* Execute the BRAM driver selftest. * Execute the BRAM driver selftest.
@@ -322,7 +323,8 @@ int32_t Mpc_Init(MPC **instPtr, MPC_CONFIG *config)
Status = XBram_SelfTest(&mpcBram, 0); Status = XBram_SelfTest(&mpcBram, 0);
if (Status != SUCCESS) if (Status != SUCCESS)
{ {
goto mpc_init_error; Mpc_Destroy(*instPtr);
return Status;
} }
mpcHwConfig.txBuffAddr = mpcBram.Config.MemBaseAddress; mpcHwConfig.txBuffAddr = mpcBram.Config.MemBaseAddress;
@@ -332,32 +334,47 @@ int32_t Mpc_Init(MPC **instPtr, MPC_CONFIG *config)
Status = MpcHw_Init(&((*instPtr)->mpchwDesc), &mpcHwConfig); Status = MpcHw_Init(&((*instPtr)->mpchwDesc), &mpcHwConfig);
if (Status != SUCCESS) if (Status != SUCCESS)
{ {
Status = ENOMEM; Mpc_Destroy(*instPtr);
goto mpc_init_error; return ENOMEM;
} }
if (CircQueueCreate(&((*instPtr)->txQueue), (*instPtr)->config.txQueueMax) == false) if (CircQueueCreate(&((*instPtr)->txQueue), (*instPtr)->config.txQueueMax) == false)
{ {
Status = ENOMEM; Mpc_Destroy(*instPtr);
goto mpc_init_error; return ENOMEM;
} }
if (CircQueueCreate(&((*instPtr)->rxQueue), (*instPtr)->config.rxQueueMax) == false) if (CircQueueCreate(&((*instPtr)->rxQueue), (*instPtr)->config.rxQueueMax) == false)
{ {
Status = ENOMEM; Mpc_Destroy(*instPtr);
goto mpc_init_error; return ENOMEM;
} }
(*instPtr)->isEnable = false; // nothing received. (*instPtr)->isEnable = false; // nothing received.
(*instPtr)->isRxDone = false; // nothing received. (*instPtr)->isRxDone = false; // nothing received.
(*instPtr)->isTxDone = true; // nothing to be sent. (*instPtr)->isTxDone = true; // nothing to be sent.
return SUCCESS; return SUCCESS;
mpc_init_error:
free((*instPtr)->mpchwDesc);
free((*instPtr)->txQueue);
free((*instPtr)->rxQueue);
free(*instPtr);
return Status;
} }
/*****************************************************************************/
/**
* @brief Destroy MPC instance.
*
* @param InstPtr A pointer to MPC instance.
*
* @return None.
*
******************************************************************************/
void Mpc_Destroy(MPC *instPtr)
{
if (instPtr == NULL)
{
return;
}
free(instPtr->mpchwDesc);
free(instPtr->txQueue);
free(instPtr->rxQueue);
free(instPtr);
}
/*****************************************************************************/ /*****************************************************************************/
/** /**
* @brief Generate a remote test response message. * @brief Generate a remote test response message.
@@ -534,17 +551,16 @@ int32_t Mpc_RxIrqHandler(MPC *instPtr)
Status = MpcHw_Recv(instPtr->mpchwDesc, mpcReq); Status = MpcHw_Recv(instPtr->mpchwDesc, mpcReq);
if (Status != SUCCESS) if (Status != SUCCESS)
{ {
goto recv_error; DBG_ERROR("SystemBus::RX error!\n");
free(mpcReq);
return Status;
} }
if (CircQueuePush(instPtr->rxQueue, (void *)mpcReq) == false) if (CircQueuePush(instPtr->rxQueue, (void *)mpcReq) == false)
{ {
DBG_ERROR("SystemBus::RX Queue overflowed!\n"); DBG_ERROR("SystemBus::RX Queue overflowed!\n");
Status = EQUEUE; free(mpcReq);
goto recv_error; return EQUEUE;
} }
instPtr->isRxDone = false; // another reception is undergoing. instPtr->isRxDone = false; // another reception is undergoing.
return SUCCESS; return SUCCESS;
recv_error:
free(mpcReq);
return Status;
} }
+1
View File
@@ -52,6 +52,7 @@ typedef struct
/************************** Function Prototypes ******************************/ /************************** Function Prototypes ******************************/
int32_t Mpc_Init(MPC **instPtr, MPC_CONFIG *config); int32_t Mpc_Init(MPC **instPtr, MPC_CONFIG *config);
void Mpc_Destroy(MPC *instPtr);
int32_t Mpc_HandleCmd(MPC *instPtr); int32_t Mpc_HandleCmd(MPC *instPtr);
int32_t Mpc_PendRemoteTest(MPC *instPtr); int32_t Mpc_PendRemoteTest(MPC *instPtr);
@@ -2,14 +2,14 @@
# Automatically-generated file. Do not edit! # Automatically-generated file. Do not edit!
################################################################################ ################################################################################
# Add inputs and outputs from these tool invocations to the build variables # Add inputs and outputs from these tool invocations to the build variables
C_SRCS += \ C_SRCS += \
../src/dev_profile/ad9361_profile.c \ ../src/dev_profile/ad9361_profile.c \
../src/dev_profile/ad9361_reg_profile.c \ ../src/dev_profile/ad9361_reg_profile.c \
../src/dev_profile/global_timer_profile.c \ ../src/dev_profile/global_timer_profile.c \
../src/dev_profile/hmc7044_profile.c \ ../src/dev_profile/hmc7044_profile.c \
../src/dev_profile/intc_profile.c \ ../src/dev_profile/intc_profile.c \
../src/dev_profile/timer_profile.c ../src/dev_profile/timer_profile.c
OBJS += \ OBJS += \
./src/dev_profile/ad9361_profile.o \ ./src/dev_profile/ad9361_profile.o \
@@ -17,7 +17,7 @@ OBJS += \
./src/dev_profile/global_timer_profile.o \ ./src/dev_profile/global_timer_profile.o \
./src/dev_profile/hmc7044_profile.o \ ./src/dev_profile/hmc7044_profile.o \
./src/dev_profile/intc_profile.o \ ./src/dev_profile/intc_profile.o \
./src/dev_profile/timer_profile.o ./src/dev_profile/timer_profile.o
C_DEPS += \ C_DEPS += \
./src/dev_profile/ad9361_profile.d \ ./src/dev_profile/ad9361_profile.d \
@@ -25,14 +25,14 @@ C_DEPS += \
./src/dev_profile/global_timer_profile.d \ ./src/dev_profile/global_timer_profile.d \
./src/dev_profile/hmc7044_profile.d \ ./src/dev_profile/hmc7044_profile.d \
./src/dev_profile/intc_profile.d \ ./src/dev_profile/intc_profile.d \
./src/dev_profile/timer_profile.d ./src/dev_profile/timer_profile.d
# Each subdirectory must supply rules for building sources it contributes # Each subdirectory must supply rules for building sources it contributes
src/dev_profile/%.o: ../src/dev_profile/%.c src/dev_profile/%.o: ../src/dev_profile/%.c
@echo 'Building file: $<' @echo 'Building file: $<'
@echo 'Invoking: ARM v7 gcc compiler' @echo 'Invoking: ARM v7 gcc compiler'
$(CC) -Wall -Wformat=2 -O0 -g3 -I../bsp/ps7_cortexa9_0/include -I../src/include -c -fmessage-length=0 -MT"$@" -mcpu=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<" $(CC) -std=c17 -pedantic -Wall -Wformat=2 -O0 -g3 -I../bsp/ps7_cortexa9_0/include -I../src/include -c -fmessage-length=0 -MT"$@" -mcpu=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
@echo 'Finished building: $<' @echo 'Finished building: $<'
@echo ' ' @echo ' '
@@ -2,28 +2,28 @@
# Automatically-generated file. Do not edit! # Automatically-generated file. Do not edit!
################################################################################ ################################################################################
# Add inputs and outputs from these tool invocations to the build variables # Add inputs and outputs from these tool invocations to the build variables
C_SRCS += \ C_SRCS += \
../src/networking/link_layer/geometry/coord.c \ ../src/networking/link_layer/geometry/coord.c \
../src/networking/link_layer/geometry/eulerangles.c \ ../src/networking/link_layer/geometry/eulerangles.c \
../src/networking/link_layer/geometry/quaternion.c ../src/networking/link_layer/geometry/quaternion.c
OBJS += \ OBJS += \
./src/networking/link_layer/geometry/coord.o \ ./src/networking/link_layer/geometry/coord.o \
./src/networking/link_layer/geometry/eulerangles.o \ ./src/networking/link_layer/geometry/eulerangles.o \
./src/networking/link_layer/geometry/quaternion.o ./src/networking/link_layer/geometry/quaternion.o
C_DEPS += \ C_DEPS += \
./src/networking/link_layer/geometry/coord.d \ ./src/networking/link_layer/geometry/coord.d \
./src/networking/link_layer/geometry/eulerangles.d \ ./src/networking/link_layer/geometry/eulerangles.d \
./src/networking/link_layer/geometry/quaternion.d ./src/networking/link_layer/geometry/quaternion.d
# Each subdirectory must supply rules for building sources it contributes # Each subdirectory must supply rules for building sources it contributes
src/networking/link_layer/geometry/%.o: ../src/networking/link_layer/geometry/%.c src/networking/link_layer/geometry/%.o: ../src/networking/link_layer/geometry/%.c
@echo 'Building file: $<' @echo 'Building file: $<'
@echo 'Invoking: ARM v7 gcc compiler' @echo 'Invoking: ARM v7 gcc compiler'
$(CC) -Wall -Wformat=2 -O0 -g3 -I../bsp/ps7_cortexa9_0/include -I../src/include -c -fmessage-length=0 -MT"$@" -mcpu=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<" $(CC) -std=c17 -pedantic -Wall -Wformat=2 -O0 -g3 -I../bsp/ps7_cortexa9_0/include -I../src/include -c -fmessage-length=0 -MT"$@" -mcpu=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
@echo 'Finished building: $<' @echo 'Finished building: $<'
@echo ' ' @echo ' '
@@ -2,7 +2,7 @@
# Automatically-generated file. Do not edit! # Automatically-generated file. Do not edit!
################################################################################ ################################################################################
# Add inputs and outputs from these tool invocations to the build variables # Add inputs and outputs from these tool invocations to the build variables
C_SRCS += \ C_SRCS += \
../src/networking/link_layer/framing.c \ ../src/networking/link_layer/framing.c \
../src/networking/link_layer/link_layer.c \ ../src/networking/link_layer/link_layer.c \
@@ -11,7 +11,7 @@ C_SRCS += \
../src/networking/link_layer/scan.c \ ../src/networking/link_layer/scan.c \
../src/networking/link_layer/schdevent.c \ ../src/networking/link_layer/schdevent.c \
../src/networking/link_layer/service.c \ ../src/networking/link_layer/service.c \
../src/networking/link_layer/time_sync.c ../src/networking/link_layer/time_sync.c
OBJS += \ OBJS += \
./src/networking/link_layer/framing.o \ ./src/networking/link_layer/framing.o \
@@ -21,7 +21,7 @@ OBJS += \
./src/networking/link_layer/scan.o \ ./src/networking/link_layer/scan.o \
./src/networking/link_layer/schdevent.o \ ./src/networking/link_layer/schdevent.o \
./src/networking/link_layer/service.o \ ./src/networking/link_layer/service.o \
./src/networking/link_layer/time_sync.o ./src/networking/link_layer/time_sync.o
C_DEPS += \ C_DEPS += \
./src/networking/link_layer/framing.d \ ./src/networking/link_layer/framing.d \
@@ -31,14 +31,14 @@ C_DEPS += \
./src/networking/link_layer/scan.d \ ./src/networking/link_layer/scan.d \
./src/networking/link_layer/schdevent.d \ ./src/networking/link_layer/schdevent.d \
./src/networking/link_layer/service.d \ ./src/networking/link_layer/service.d \
./src/networking/link_layer/time_sync.d ./src/networking/link_layer/time_sync.d
# Each subdirectory must supply rules for building sources it contributes # Each subdirectory must supply rules for building sources it contributes
src/networking/link_layer/%.o: ../src/networking/link_layer/%.c src/networking/link_layer/%.o: ../src/networking/link_layer/%.c
@echo 'Building file: $<' @echo 'Building file: $<'
@echo 'Invoking: ARM v7 gcc compiler' @echo 'Invoking: ARM v7 gcc compiler'
$(CC) -Wall -Wformat=2 -O0 -g3 -I../bsp/ps7_cortexa9_0/include -I../src/include -c -fmessage-length=0 -MT"$@" -mcpu=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<" $(CC) -std=c17 -pedantic -Wall -Wformat=2 -O0 -g3 -I../bsp/ps7_cortexa9_0/include -I../src/include -c -fmessage-length=0 -MT"$@" -mcpu=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
@echo 'Finished building: $<' @echo 'Finished building: $<'
@echo ' ' @echo ' '
@@ -2,25 +2,25 @@
# Automatically-generated file. Do not edit! # Automatically-generated file. Do not edit!
################################################################################ ################################################################################
# Add inputs and outputs from these tool invocations to the build variables # Add inputs and outputs from these tool invocations to the build variables
C_SRCS += \ C_SRCS += \
../src/networking/phy_layer/phy_antenna.c \ ../src/networking/phy_layer/phy_antenna.c \
../src/networking/phy_layer/phy_layer.c ../src/networking/phy_layer/phy_layer.c
OBJS += \ OBJS += \
./src/networking/phy_layer/phy_antenna.o \ ./src/networking/phy_layer/phy_antenna.o \
./src/networking/phy_layer/phy_layer.o ./src/networking/phy_layer/phy_layer.o
C_DEPS += \ C_DEPS += \
./src/networking/phy_layer/phy_antenna.d \ ./src/networking/phy_layer/phy_antenna.d \
./src/networking/phy_layer/phy_layer.d ./src/networking/phy_layer/phy_layer.d
# Each subdirectory must supply rules for building sources it contributes # Each subdirectory must supply rules for building sources it contributes
src/networking/phy_layer/%.o: ../src/networking/phy_layer/%.c src/networking/phy_layer/%.o: ../src/networking/phy_layer/%.c
@echo 'Building file: $<' @echo 'Building file: $<'
@echo 'Invoking: ARM v7 gcc compiler' @echo 'Invoking: ARM v7 gcc compiler'
$(CC) -Wall -Wformat=2 -O0 -g3 -I../bsp/ps7_cortexa9_0/include -I../src/include -c -fmessage-length=0 -MT"$@" -mcpu=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<" $(CC) -std=c17 -pedantic -Wall -Wformat=2 -O0 -g3 -I../bsp/ps7_cortexa9_0/include -I../src/include -c -fmessage-length=0 -MT"$@" -mcpu=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
@echo 'Finished building: $<' @echo 'Finished building: $<'
@echo ' ' @echo ' '
+1 -1
View File
@@ -26,7 +26,7 @@ C_DEPS += \
src/%.o: ../src/%.c src/%.o: ../src/%.c
@echo 'Building file: $<' @echo 'Building file: $<'
@echo 'Invoking: ARM v7 gcc compiler' @echo 'Invoking: ARM v7 gcc compiler'
$(CC) -Wall -Wformat=2 -O0 -g3 -I../bsp/ps7_cortexa9_0/include -I../src/include -c -fmessage-length=0 -MT"$@" -mcpu=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<" $(CC) -std=c17 -pedantic -Wall -Wformat=2 -O0 -g3 -I../bsp/ps7_cortexa9_0/include -I../src/include -c -fmessage-length=0 -MT"$@" -mcpu=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
@echo 'Finished building: $<' @echo 'Finished building: $<'
@echo ' ' @echo ' '
+5 -5
View File
@@ -2,25 +2,25 @@
# Automatically-generated file. Do not edit! # Automatically-generated file. Do not edit!
################################################################################ ################################################################################
# Add inputs and outputs from these tool invocations to the build variables # Add inputs and outputs from these tool invocations to the build variables
C_SRCS += \ C_SRCS += \
../src/systembus/systembus.c \ ../src/systembus/systembus.c \
../src/systembus/systembus_uart.c ../src/systembus/systembus_uart.c
OBJS += \ OBJS += \
./src/systembus/systembus.o \ ./src/systembus/systembus.o \
./src/systembus/systembus_uart.o ./src/systembus/systembus_uart.o
C_DEPS += \ C_DEPS += \
./src/systembus/systembus.d \ ./src/systembus/systembus.d \
./src/systembus/systembus_uart.d ./src/systembus/systembus_uart.d
# Each subdirectory must supply rules for building sources it contributes # Each subdirectory must supply rules for building sources it contributes
src/systembus/%.o: ../src/systembus/%.c src/systembus/%.o: ../src/systembus/%.c
@echo 'Building file: $<' @echo 'Building file: $<'
@echo 'Invoking: ARM v7 gcc compiler' @echo 'Invoking: ARM v7 gcc compiler'
$(CC) -Wall -Wformat=2 -O0 -g3 -I../bsp/ps7_cortexa9_0/include -I../src/include -c -fmessage-length=0 -MT"$@" -mcpu=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<" $(CC) -std=c17 -pedantic -Wall -Wformat=2 -O0 -g3 -I../bsp/ps7_cortexa9_0/include -I../src/include -c -fmessage-length=0 -MT"$@" -mcpu=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
@echo 'Finished building: $<' @echo 'Finished building: $<'
@echo ' ' @echo ' '
+5 -5
View File
@@ -2,22 +2,22 @@
# Automatically-generated file. Do not edit! # Automatically-generated file. Do not edit!
################################################################################ ################################################################################
# Add inputs and outputs from these tool invocations to the build variables # Add inputs and outputs from these tool invocations to the build variables
C_SRCS += \ C_SRCS += \
../src/time_ctrl/time_ctrl.c ../src/time_ctrl/time_ctrl.c
OBJS += \ OBJS += \
./src/time_ctrl/time_ctrl.o ./src/time_ctrl/time_ctrl.o
C_DEPS += \ C_DEPS += \
./src/time_ctrl/time_ctrl.d ./src/time_ctrl/time_ctrl.d
# Each subdirectory must supply rules for building sources it contributes # Each subdirectory must supply rules for building sources it contributes
src/time_ctrl/%.o: ../src/time_ctrl/%.c src/time_ctrl/%.o: ../src/time_ctrl/%.c
@echo 'Building file: $<' @echo 'Building file: $<'
@echo 'Invoking: ARM v7 gcc compiler' @echo 'Invoking: ARM v7 gcc compiler'
arm-none-eabi-gcc -Wall -O0 -g3 -I../bsp/ps7_cortexa9_0/include -I../src/include -c -fmessage-length=0 -MT"$@" -mcpu=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<" arm-none-eabi-gcc -std=c17 -pedantic -Wall -O0 -g3 -I../bsp/ps7_cortexa9_0/include -I../src/include -c -fmessage-length=0 -MT"$@" -mcpu=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
@echo 'Finished building: $<' @echo 'Finished building: $<'
@echo ' ' @echo ' '
+5 -5
View File
@@ -2,14 +2,14 @@
# Automatically-generated file. Do not edit! # Automatically-generated file. Do not edit!
################################################################################ ################################################################################
# Add inputs and outputs from these tool invocations to the build variables # Add inputs and outputs from these tool invocations to the build variables
C_SRCS += \ C_SRCS += \
../src/util/circ_queue.c \ ../src/util/circ_queue.c \
../src/util/clist.c \ ../src/util/clist.c \
../src/util/common.c \ ../src/util/common.c \
../src/util/crc.c \ ../src/util/crc.c \
../src/util/list.c \ ../src/util/list.c \
../src/util/util.c ../src/util/util.c
OBJS += \ OBJS += \
./src/util/circ_queue.o \ ./src/util/circ_queue.o \
@@ -17,7 +17,7 @@ OBJS += \
./src/util/common.o \ ./src/util/common.o \
./src/util/crc.o \ ./src/util/crc.o \
./src/util/list.o \ ./src/util/list.o \
./src/util/util.o ./src/util/util.o
C_DEPS += \ C_DEPS += \
./src/util/circ_queue.d \ ./src/util/circ_queue.d \
@@ -25,14 +25,14 @@ C_DEPS += \
./src/util/common.d \ ./src/util/common.d \
./src/util/crc.d \ ./src/util/crc.d \
./src/util/list.d \ ./src/util/list.d \
./src/util/util.d ./src/util/util.d
# Each subdirectory must supply rules for building sources it contributes # Each subdirectory must supply rules for building sources it contributes
src/util/%.o: ../src/util/%.c src/util/%.o: ../src/util/%.c
@echo 'Building file: $<' @echo 'Building file: $<'
@echo 'Invoking: ARM v7 gcc compiler' @echo 'Invoking: ARM v7 gcc compiler'
$(CC) -Wall -Wformat=2 -O0 -g3 -I../bsp/ps7_cortexa9_0/include -I../src/include -c -fmessage-length=0 -MT"$@" -mcpu=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<" $(CC) -std=c17 -pedantic -Wall -Wformat=2 -O0 -g3 -I../bsp/ps7_cortexa9_0/include -I../src/include -c -fmessage-length=0 -MT"$@" -mcpu=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
@echo 'Finished building: $<' @echo 'Finished building: $<'
@echo ' ' @echo ' '
+1 -1
View File
@@ -38,7 +38,7 @@
#define DATALINK_ENABLE_AUTORECONNECT #define DATALINK_ENABLE_AUTORECONNECT
#define DATALINK_ENABLE_AUTOTIMESYNC #define DATALINK_ENABLE_AUTOTIMESYNC
// #define DATALINK_ENABLE_BERTEST #define DATALINK_ENABLE_BERTEST 10
/************ Hardware Configs ************/ /************ Hardware Configs ************/
#define CPU_CLK_HZ XPAR_CPU_CORTEXA9_0_CPU_CLK_FREQ_HZ #define CPU_CLK_HZ XPAR_CPU_CORTEXA9_0_CPU_CLK_FREQ_HZ
+3 -3
View File
@@ -34,9 +34,9 @@
/************************** Function Prototypes ******************************/ /************************** Function Prototypes ******************************/
/*********************** Driver Instance Definitions **************************/ /*********************** Driver Instance Definitions **************************/
static struct hmc7044_dev *hmc7044_inst; static struct hmc7044_dev *hmc7044_inst = NULL;
static struct ad9361_reg_dev *ad9361_1_reg_inst; static struct ad9361_reg_dev *ad9361_1_reg_inst = NULL;
static struct ad9361_reg_dev *ad9361_2_reg_inst; static struct ad9361_reg_dev *ad9361_2_reg_inst = NULL;
// static struct ad9361_rf_phy *ad9361_phy; // static struct ad9361_rf_phy *ad9361_phy;
// static struct ad9361_rf_phy *ad9361_2_phy; // static struct ad9361_rf_phy *ad9361_2_phy;
+3 -2
View File
@@ -13,7 +13,8 @@
* Copyright(c) 2024 Beijing Institute of Technology. * Copyright(c) 2024 Beijing Institute of Technology.
* *
******************************************************************************/ ******************************************************************************/
#ifndef HWCONFIG_H_
#define HWCONFIG_H_
/***************************** Include Files *********************************/ /***************************** Include Files *********************************/
// Standard // Standard
#include <stdint.h> #include <stdint.h>
@@ -29,4 +30,4 @@ int8_t Hardware_GetAD9361Temp_2(void);
uint8_t Hardware_GetAD9361LockStatus(void); uint8_t Hardware_GetAD9361LockStatus(void);
uint8_t Hardware_GetHMC7044LockStatus(void); uint8_t Hardware_GetHMC7044LockStatus(void);
#endif // HWCONFIG_H_
+17 -17
View File
@@ -72,20 +72,20 @@ struct callback_desc scutm_callback_desc = {
L2_CONFIG linkConfig = { L2_CONFIG linkConfig = {
.myType = L2_NODE_HEAD, .myType = L2_NODE_HEAD,
.clustId = 1, .clustId = 1U,
.myId = 1, .myId = 1U,
.headId = 1, .headId = 1U,
.netScale = 2, .netScale = 2U,
.phyInstPtr = NULL, // physical layer reference .phyInstPtr = NULL, // physical layer reference
.tmcInstPtr = NULL .tmcInstPtr = NULL
}; };
// L2_CONFIG linkConfig = { // L2_CONFIG linkConfig = {
// .myType = L2_NODE_MEMBER, // .myType = L2_NODE_MEMBER,
// .clustId = 1, // .clustId = 1U,
// .myId = 2, // .myId = 2U,
// .headId = 1, // .headId = 1U,
// .netScale = 2, // .netScale = 2U,
// .phyInstPtr = NULL, // physical layer reference // .phyInstPtr = NULL, // physical layer reference
// .tmcInstPtr = NULL // .tmcInstPtr = NULL
// }; // };
@@ -106,21 +106,21 @@ static PHY_CONFIG phyConfig = {
TMC_CONFIG tmcConfig = { TMC_CONFIG tmcConfig = {
.baseAddr = TIME_CONTROLLER_BASEADDR, .baseAddr = TIME_CONTROLLER_BASEADDR,
.reset = 10 .reset = 10U
}; };
static SYSBUS_CONFIG sysbusConfig = { static SYSBUS_CONFIG sysbusConfig = {
.baseAddr = SYSBUS_BASE_ADDR, .baseAddr = SYSBUS_BASE_ADDR,
.txQueueMax = 16, .txQueueMax = 16U,
.rxQueueMax = 16 .rxQueueMax = 16U
}; };
/*********************** Driver Instance Definitions **************************/ /*********************** Driver Instance Definitions **************************/
static struct irq_ctrl_desc *intcDescPtr; // General interrupt controller descriptor static struct irq_ctrl_desc *intcDescPtr = NULL; // General interrupt controller descriptor
static struct timer_desc *logTmPtr; static struct timer_desc *logTmPtr = NULL;
static SYSBUS *sysbusDescPtr; static SYSBUS *sysbusDescPtr = NULL;
static PHY_INST *phyInstPtr; static PHY_INST *phyInstPtr = NULL;
static TMC_INST *tmcInstPtr = NULL; static TMC_INST *tmcInstPtr = NULL;
L2_INST *linkInstPtr; L2_INST *linkInstPtr = NULL;
/****************************************************************************/ /****************************************************************************/
@@ -482,7 +482,7 @@ int main(void)
DBG_PRINT("Physical started...\n"); DBG_PRINT("Physical started...\n");
Phy_Start(phyInstPtr); Phy_Start(phyInstPtr);
// Linklayer_Start(linkInstPtr); Linklayer_Start(linkInstPtr);
while (true) while (true)
{ {
@@ -165,7 +165,7 @@ bool L2_CrcCheck(uint8_t *dataBuff, uint32_t dataLen, L2_CRC_TYPE crcType)
ASSERT(dataBuff != NULL); ASSERT(dataBuff != NULL);
int32_t Status; int32_t Status;
uint32_t crcVal; uint32_t crcVal;
crcVal = 0; crcVal = 0U;
Status = L2_CrcGen(dataBuff, dataLen, crcType, &crcVal); Status = L2_CrcGen(dataBuff, dataLen, crcType, &crcVal);
if (Status == SUCCESS) if (Status == SUCCESS)
{ {
@@ -75,6 +75,10 @@ COORD Coord_GetScalarMult(COORD a, double t)
/** @brief Divides a coordinate vector by a real number. */ /** @brief Divides a coordinate vector by a real number. */
void Coord_ScalarDiv(COORD *a, double t) void Coord_ScalarDiv(COORD *a, double t)
{ {
if (t == 0.0) {
*a = COORD_NIL;
return;
}
a->x /= t; a->x /= t;
a->y /= t; a->y /= t;
a->z /= t; a->z /= t;
@@ -83,6 +87,9 @@ void Coord_ScalarDiv(COORD *a, double t)
/** @brief Divides a coordinate vector by a real number. */ /** @brief Divides a coordinate vector by a real number. */
COORD Coord_GetScalarDiv(COORD a, double t) COORD Coord_GetScalarDiv(COORD a, double t)
{ {
if (t == 0.0) {
return COORD_NIL;
}
COORD ret; COORD ret;
ret.x = a.x / t; ret.x = a.x / t;
ret.y = a.y / t; ret.y = a.y / t;
@@ -69,9 +69,9 @@ EULERANGLES EulerAngles_GetScalarMult(EULERANGLES e, double f)
/** @brief Normalize EulerAngles. */ /** @brief Normalize EulerAngles. */
void EulerAngles_Normalize(EULERANGLES *e) void EulerAngles_Normalize(EULERANGLES *e)
{ {
e->alpha = fmod(e->alpha, 2 * EUL_PI); e->alpha = fmod(e->alpha, 2.0 * EUL_PI);
e->beta = fmod(e->beta, 2 * EUL_PI); e->beta = fmod(e->beta, 2.0 * EUL_PI);
e->gamma = fmod(e->gamma, 2 * EUL_PI); e->gamma = fmod(e->gamma, 2.0 * EUL_PI);
} }
/** @brief Normalize EulerAngles. */ /** @brief Normalize EulerAngles. */
@@ -30,8 +30,8 @@
#define EUL_PI 3.14159265358979323846 #define EUL_PI 3.14159265358979323846
#define DEG2RAD(d) ((EUL_PI / 180.0) * d) #define DEG2RAD(d) ((EUL_PI / 180.0) * (d))
#define RAD2DEG(r) ((180.0 / EUL_PI) * r) #define RAD2DEG(r) ((180.0 / EUL_PI) * (r))
/** /**
* Orientations are represented by 3D double precision Tait-Bryan (Euler) tuples * Orientations are represented by 3D double precision Tait-Bryan (Euler) tuples
@@ -91,6 +91,10 @@ QUATERNION Quaternion_GetScalarMult(QUATERNION a, double t)
/** @brief Divides a quaternion by a real number. */ /** @brief Divides a quaternion by a real number. */
void Quaternion_ScalarDiv(QUATERNION *q, double t) void Quaternion_ScalarDiv(QUATERNION *q, double t)
{ {
if (t == 0.0) {
*q = QUATERNION_NIL;
return;
}
q->s /= t; q->s /= t;
q->i /= t; q->i /= t;
q->j /= t; q->j /= t;
@@ -190,6 +194,9 @@ inline double Quaternion_GetRotationAngle(QUATERNION q)
/** @brief Get axis of quaternion. */ /** @brief Get axis of quaternion. */
COORD Quaternion_GetRotationAxis(QUATERNION q) COORD Quaternion_GetRotationAxis(QUATERNION q)
{ {
if ((q.s > 1.0) || (q.s < -1.0)) {
return COORD_NIL;
}
double sin_theta_inv; double sin_theta_inv;
COORD ret; COORD ret;
sin_theta_inv = 1.0 / sin(acos(q.s)); sin_theta_inv = 1.0 / sin(acos(q.s));
@@ -202,6 +209,12 @@ COORD Quaternion_GetRotationAxis(QUATERNION q)
/** @brief Get the axis and rotate angle of a unit Quaternion */ /** @brief Get the axis and rotate angle of a unit Quaternion */
void Quaternion_GetRotationAxisAndAngle(QUATERNION q, COORD *axis, double *angle) void Quaternion_GetRotationAxisAndAngle(QUATERNION q, COORD *axis, double *angle)
{ {
if ((q.s > 1.0) || (q.s < -1.0)) {
*axis = COORD_NIL;
*angle = NAN;
return;
}
double sin_theta_inv; double sin_theta_inv;
*angle = acos(q.s); *angle = acos(q.s);
@@ -218,6 +231,11 @@ void Quaternion_GetRotationAxisAndAngle(QUATERNION q, COORD *axis, double *angle
/** @brief Decompose the rotation on to 2 parts. */ /** @brief Decompose the rotation on to 2 parts. */
void Quaternion_GetSwingAndTwist(QUATERNION q, COORD axis, QUATERNION *swing, QUATERNION *twist) void Quaternion_GetSwingAndTwist(QUATERNION q, COORD axis, QUATERNION *swing, QUATERNION *twist)
{ {
if ((swing == NULL) || (twist == NULL))
{
return;
}
double p; double p;
COORD v; COORD v;
v.x = q.i; v.x = q.i;
@@ -326,7 +344,7 @@ EULERANGLES Quaternion_ToEulerAngles(QUATERNION q, EULERANGLES_TYPE type)
if (mask1 || mask2) if (mask1 || mask2)
{ {
ret.alpha = 0; ret.alpha = 0;
ret.gamma = (asinValue > 0) ? (2.0 * atan2(q.i, q.s)) : (-2.0 * atan2(q.i, q.s)); ret.gamma = (asinValue > 0.0) ? (2.0 * atan2(q.i, q.s)) : (-2.0 * atan2(q.i, q.s));
} }
else else
{ {
@@ -339,6 +357,7 @@ EULERANGLES Quaternion_ToEulerAngles(QUATERNION q, EULERANGLES_TYPE type)
default: default:
ret = EULERANGLES_NIL; ret = EULERANGLES_NIL;
break;
} }
return ret; return ret;
} }
@@ -428,7 +447,7 @@ QUATERNION Quaternion_RotationFromTo(COORD from, COORD to)
QUATERNION Quaternion_Lerp(QUATERNION q1, QUATERNION q2, double t) QUATERNION Quaternion_Lerp(QUATERNION q1, QUATERNION q2, double t)
{ {
QUATERNION ret; QUATERNION ret;
Quaternion_ScalarMult(&q1, 1 - t); Quaternion_ScalarMult(&q1, 1.0 - t);
Quaternion_ScalarMult(&q1, t); Quaternion_ScalarMult(&q1, t);
ret = Quaternion_Add(q1, q2); ret = Quaternion_Add(q1, q2);
Quaternion_Normalize(&ret); Quaternion_Normalize(&ret);
@@ -56,13 +56,13 @@ QUATERNION Quaternion_Add(QUATERNION q1, QUATERNION q2);
void Quaternion_ScalarMult(QUATERNION *q, double t); void Quaternion_ScalarMult(QUATERNION *q, double t);
/** @brief Multiplies a quaternion by a real number. */ /** @brief Multiplies a quaternion by a real number. */
QUATERNION Quaternion_GetScalarMult(QUATERNION a, double t); QUATERNION Quaternion_GetScalarMult(QUATERNION q, double t);
/** @brief Divides a quaternion by a real number. */ /** @brief Divides a quaternion by a real number. */
void Quaternion_ScalarDiv(QUATERNION *q, double t); void Quaternion_ScalarDiv(QUATERNION *q, double t);
/** @brief Divides a quaternion by a real number. */ /** @brief Divides a quaternion by a real number. */
QUATERNION Quaternion_GetScalarDiv(QUATERNION a, double t); QUATERNION Quaternion_GetScalarDiv(QUATERNION q, double t);
/** @brief Multiplies two quaternions. */ /** @brief Multiplies two quaternions. */
QUATERNION Quaternion_Mult(QUATERNION q1, QUATERNION q2); QUATERNION Quaternion_Mult(QUATERNION q1, QUATERNION q2);
@@ -39,7 +39,7 @@
/***************** Macros (Inline Functions) Definitions *********************/ /***************** Macros (Inline Functions) Definitions *********************/
/**************************** Type Definitions *******************************/ /**************************** Type Definitions *******************************/
/************************** Function Prototypes ******************************/ /************************** Function Prototypes ******************************/
static void L2_RcdShift(L2_RCD *rcd, int32_t netxVal); static void L2_RcdShift(L2_RCD *rcd, uint32_t netxVal);
static void UpdateMainSate(L2_INST *instPtr, L2_NODE_STATE newSate); static void UpdateMainSate(L2_INST *instPtr, L2_NODE_STATE newSate);
static void L2_SetSlotNum(L2_INST *instPtr, uint32_t newSlotNum); static void L2_SetSlotNum(L2_INST *instPtr, uint32_t newSlotNum);
static void L2_SetFrameNum(L2_INST *instPtr, uint32_t newFrameNum); static void L2_SetFrameNum(L2_INST *instPtr, uint32_t newFrameNum);
@@ -50,7 +50,7 @@ static void L2_FrameStateUpdate(L2_INST *instPtr);
/** /**
* @brief Shift L2 status record.(newval->next->curr->last) * @brief Shift L2 status record.(newval->next->curr->last)
*/ */
inline void L2_RcdShift(L2_RCD *rcd, int32_t netxVal) inline void L2_RcdShift(L2_RCD *rcd, uint32_t netxVal)
{ {
ASSERT(rcd != NULL); ASSERT(rcd != NULL);
rcd->last = rcd->curr; rcd->last = rcd->curr;
@@ -132,6 +132,7 @@ static void L2_FrameStateUpdate(L2_INST *instPtr)
PHY_INST *phyRef = instPtr->config.phyInstPtr; PHY_INST *phyRef = instPtr->config.phyInstPtr;
bool isValid; bool isValid;
L2_FRAME_TYPE recvType = L2_GetLastOptFrameType(instPtr); L2_FRAME_TYPE recvType = L2_GetLastOptFrameType(instPtr);
isValid = false;
// Update frame state. // Update frame state.
if (Phy_IsFrameValid(phyRef) == false) if (Phy_IsFrameValid(phyRef) == false)
{ {
@@ -162,7 +163,7 @@ static void L2_FrameStateUpdate(L2_INST *instPtr)
#ifndef DATALINK_ENABLE_BERTEST #ifndef DATALINK_ENABLE_BERTEST
isValid = L2_CrcCheck(instPtr->recvPktData, L2_SVC_PACK_LEN, L2_CRC16_1021); isValid = L2_CrcCheck(instPtr->recvPktData, L2_SVC_PACK_LEN, L2_CRC16_1021);
#else #else
isValid = true; isValid = L2_Service_PktCheck(instPtr, instPtr->recvPktData);
#endif #endif
instPtr->log.svcRecvCnt++; instPtr->log.svcRecvCnt++;
instPtr->log.svcCorrectCnt = isValid ? instPtr->log.svcCorrectCnt + 1 : instPtr->log.svcCorrectCnt; instPtr->log.svcCorrectCnt = isValid ? instPtr->log.svcCorrectCnt + 1 : instPtr->log.svcCorrectCnt;
@@ -419,10 +420,14 @@ L1_FRAME_TYPE L2_L2frame2L1frame(L2_FRAME_TYPE l2Frame)
case L2_SCAN_FRAME: case L2_SCAN_FRAME:
return L1_10KBPS_10MS_FRAME; return L1_10KBPS_10MS_FRAME;
case L2_ADV_FRAME: case L2_ADV_FRAME:
return L1_10KBPS_20MS_FRAME;
case L2_CFM_FRAME: case L2_CFM_FRAME:
return L1_10KBPS_20MS_FRAME;
case L2_SVC_FRAME: case L2_SVC_FRAME:
#if DATALINK_ENABLE_BERTEST == 10
return L1_10KBPS_20MS_FRAME;
#else
return L1_40KBPS_20MS_FRAME; return L1_40KBPS_20MS_FRAME;
#endif
default: default:
return L1_NONE_FRAME; return L1_NONE_FRAME;
} }
@@ -470,6 +475,12 @@ int32_t Linklayer_Init(L2_INST **instPtr, const L2_CONFIG *config)
// Clear random content // Clear random content
memset(*instPtr, 0x00, sizeof(L2_INST)); memset(*instPtr, 0x00, sizeof(L2_INST));
(*instPtr)->sendPktData = NULL;
(*instPtr)->recvPktData = NULL;
(*instPtr)->schdEventPool = NULL;
(*instPtr)->nodeList = NULL;
(*instPtr)->scanFSM = NULL;
(*instPtr)->serviceFSM = NULL;
memcpy(&((*instPtr)->config), config, sizeof(L2_CONFIG)); memcpy(&((*instPtr)->config), config, sizeof(L2_CONFIG));
// Packet buffer // Packet buffer
@@ -477,15 +488,15 @@ int32_t Linklayer_Init(L2_INST **instPtr, const L2_CONFIG *config)
if ((*instPtr)->sendPktData == NULL) if ((*instPtr)->sendPktData == NULL)
{ {
DBG_ERROR("Allocate memory for sendPktData failed.\n"); DBG_ERROR("Allocate memory for sendPktData failed.\n");
Status = ENOMEM; Linklayer_Destroy(*instPtr);
goto init_error; return ENOMEM;
} }
(*instPtr)->recvPktData = calloc(L2_PACK_LEN_MAX / sizeof(uint64_t), sizeof(uint64_t)); (*instPtr)->recvPktData = calloc(L2_PACK_LEN_MAX / sizeof(uint64_t), sizeof(uint64_t));
if ((*instPtr)->recvPktData == NULL) if ((*instPtr)->recvPktData == NULL)
{ {
DBG_ERROR("Allocate memory for recvPktData failed.\n"); DBG_ERROR("Allocate memory for recvPktData failed.\n");
Status = ENOMEM; Linklayer_Destroy(*instPtr);
goto init_error; return ENOMEM;
} }
// Reset basic info // Reset basic info
(*instPtr)->netStartTime = NET_START_TIME_INFTY; (*instPtr)->netStartTime = NET_START_TIME_INFTY;
@@ -528,32 +539,33 @@ int32_t Linklayer_Init(L2_INST **instPtr, const L2_CONFIG *config)
if (Status != SUCCESS) if (Status != SUCCESS)
{ {
DBG_ERROR("L2_CreateSchedEventPool runs failed, with error code: %" PRId32 ".\n", Status); DBG_ERROR("L2_CreateSchedEventPool runs failed, with error code: %" PRId32 ".\n", Status);
goto init_error; Linklayer_Destroy(*instPtr);
return Status;
} }
Status = L2_NodeList_Init(&((*instPtr)->nodeList)); Status = L2_NodeList_Init(&((*instPtr)->nodeList));
if (Status != SUCCESS) if (Status != SUCCESS)
{ {
DBG_ERROR("NodeList_Init runs failed, with error code: %" PRId32 ".\n", Status); DBG_ERROR("NodeList_Init runs failed, with error code: %" PRId32 ".\n", Status);
goto init_error; Linklayer_Destroy(*instPtr);
return Status;
} }
Status = L2_Scan_Init(&((*instPtr)->scanFSM)); Status = L2_Scan_Init(&((*instPtr)->scanFSM));
if (Status != SUCCESS) if (Status != SUCCESS)
{ {
goto init_error; Linklayer_Destroy(*instPtr);
return Status;
} }
Status = L2_Service_Init(&((*instPtr)->serviceFSM)); Status = L2_Service_Init(&((*instPtr)->serviceFSM));
if (Status != SUCCESS) if (Status != SUCCESS)
{ {
goto init_error; Linklayer_Destroy(*instPtr);
return Status;
} }
return SUCCESS; return SUCCESS;
init_error:
Linklayer_Destroy(*instPtr);
return Status;
} }
/*****************************************************************************/ /*****************************************************************************/
@@ -637,7 +649,10 @@ int32_t Linklayer_Reconfig(L2_INST *instPtr, const L2_CONFIG *config)
******************************************************************************/ ******************************************************************************/
void Linklayer_Destroy(L2_INST *instPtr) void Linklayer_Destroy(L2_INST *instPtr)
{ {
ASSERT(instPtr != NULL); if (instPtr == NULL)
{
return;
}
free(instPtr->sendPktData); free(instPtr->sendPktData);
free(instPtr->recvPktData); free(instPtr->recvPktData);
// Destroy FSMs and nodeList // Destroy FSMs and nodeList
@@ -29,7 +29,7 @@
#include "../../system_monitor.h" #include "../../system_monitor.h"
/************************** Constant Definitions *****************************/ /************************** Constant Definitions *****************************/
/***************** Macros (Inline Functions) Definitions *********************/ /***************** Macros (Inline Functions) Definitions *********************/
#define AssertL2Event(instPtr, event) Linklayer_EventHandler(instPtr, event) #define AssertL2Event(instPtr, event) (Linklayer_EventHandler((instPtr), (event)))
/**************************** Type Definitions *******************************/ /**************************** Type Definitions *******************************/
/** /**
@@ -173,6 +173,7 @@ int32_t L2_Scan_Routine(L2_INST *instPtr, const L2_RTNE_TABLE_ENTRY *schedEntry)
int32_t L2_Service_Init(L2_SVC_FSM **svcFSMPtr); int32_t L2_Service_Init(L2_SVC_FSM **svcFSMPtr);
void L2_Service_Reset(L2_SVC_FSM *svcFSMPtr); void L2_Service_Reset(L2_SVC_FSM *svcFSMPtr);
void L2_Service_Destroy(L2_SVC_FSM *svcFSMPtr); void L2_Service_Destroy(L2_SVC_FSM *svcFSMPtr);
bool L2_Service_PktCheck(L2_INST *instPtr, uint8_t *msg);
int32_t L2_Service_PktHandler(L2_INST *instPtr, uint8_t *msg); int32_t L2_Service_PktHandler(L2_INST *instPtr, uint8_t *msg);
int32_t L2_Service_Proc(L2_INST *instPtr); int32_t L2_Service_Proc(L2_INST *instPtr);
int32_t L2_Service_Routine(L2_INST *instPtr, const L2_RTNE_TABLE_ENTRY *schedEntry); int32_t L2_Service_Routine(L2_INST *instPtr, const L2_RTNE_TABLE_ENTRY *schedEntry);
@@ -145,7 +145,7 @@ typedef enum
typedef struct typedef struct
{ {
L2_EVENT_TYPE event; ///< event type L2_EVENT_TYPE event; ///< event type
void *msg; ///< event message void *msg; ///< event message (MUST be a heap item)
} L2_EVENT; } L2_EVENT;
/** /**
@@ -26,7 +26,7 @@
#define L2_PACK_LEN_MAX 512 // bytes #define L2_PACK_LEN_MAX 512 // bytes
#define L2_ADV_PACK_LEN 28 // bytes #define L2_ADV_PACK_LEN 28 // bytes
#define L2_CMF_PACK_LEN 268 // bytes #define L2_CMF_PACK_LEN 28 // bytes
#define L2_SVC_PACK_LEN 268 // bytes #define L2_SVC_PACK_LEN 268 // bytes
// Common structure: // Common structure:
@@ -81,17 +81,7 @@
#define L2_MSG_CFM_SRC_POSY_LEN 4 #define L2_MSG_CFM_SRC_POSY_LEN 4
#define L2_MSG_CFM_SRC_POSZ 16 #define L2_MSG_CFM_SRC_POSZ 16
#define L2_MSG_CFM_SRC_POSZ_LEN 4 #define L2_MSG_CFM_SRC_POSZ_LEN 4
#define L2_MSG_CFM_SRC_SPEEDX 20 #define L2_MSG_CFM_CRC 26
#define L2_MSG_CFM_SRC_SPEEDX_LEN 4
#define L2_MSG_CFM_SRC_SPEEDY 24
#define L2_MSG_CFM_SRC_SPEEDY_LEN 4
#define L2_MSG_CFM_SRC_SPEEDZ 28
#define L2_MSG_CFM_SRC_SPEEDZ_LEN 4
#define L2_MSG_CFM_PAYLOAD_ID 32
#define L2_MSG_CFM_PAYLOAD_ID_LEN 4
#define L2_MSG_CFM_PAYLOAD 36
#define L2_MSG_CFM_PAYLOAD_LEN 230
#define L2_MSG_CFM_CRC 266
#define L2_MSG_CFM_CRC_LEN 2 #define L2_MSG_CFM_CRC_LEN 2
// service payload structure: // service payload structure:
@@ -127,4 +117,4 @@
/** @} LinkLayer_MSG_Constants*/ /** @} LinkLayer_MSG_Constants*/
/** @} LinkLayer*/ /** @} LinkLayer*/
@@ -44,7 +44,7 @@ inline uint32_t L2_GetNodeListLen(NODE_LIST *list)
/**************************** Type Definitions *******************************/ /**************************** Type Definitions *******************************/
/************************** Variable Definitions *****************************/ /************************** Variable Definitions *****************************/
static NODE_ENTRY util_entry; static NODE_ENTRY util_entry = { 0 };
/************************** Function Prototypes ******************************/ /************************** Function Prototypes ******************************/
/** /**
* @brief helper function to free node entry. * @brief helper function to free node entry.
+27 -84
View File
@@ -182,7 +182,7 @@ static void PendCfmAck(L2_SCAN_FSM *scanFsmPtr)
******************************************************************************/ ******************************************************************************/
static void StageUpdate(L2_SCAN_FSM *scanFsmPtr, SCAN_STAGE newStage) static void StageUpdate(L2_SCAN_FSM *scanFsmPtr, SCAN_STAGE newStage)
{ {
ASSERT(newStage >= L2_SCAN_NONE_STAGE && newStage <= L2_SCAN_CFM_STAGE); ASSERT((newStage >= L2_SCAN_NONE_STAGE) && (newStage <= L2_SCAN_CFM_STAGE));
DBG_INFO("ScanNet current stage: %" PRIu8 " -> ScanNet new stage: %" PRIu8 " \n", DBG_INFO("ScanNet current stage: %" PRIu8 " -> ScanNet new stage: %" PRIu8 " \n",
scanFsmPtr->scanStage, newStage); scanFsmPtr->scanStage, newStage);
scanFsmPtr->scanStage = newStage; scanFsmPtr->scanStage = newStage;
@@ -270,10 +270,10 @@ static int32_t Scan_AdvHandler(L2_INST *instPtr)
{ {
// using pull mode to receive confirm frame // using pull mode to receive confirm frame
// since first time sync procedure is accomplished in ADV stage. // since first time sync procedure is accomplished in ADV stage.
Phy_SetBeamWidth(phyRef, PHY_ANT_BEAM_16); (void)Phy_SetBeamWidth(phyRef, PHY_ANT_BEAM_16);
Phy_SetBeamNo(phyRef, scanFsmPtr->beamNo, PHY_ANT_BEAM_16); (void)Phy_SetBeamNo(phyRef, scanFsmPtr->beamNo, PHY_ANT_BEAM_16);
Phy_SetMode(phyRef, PHY_MODE_PULL); (void)Phy_SetMode(phyRef, PHY_MODE_PULL);
L2_SetupNextSlot(instPtr, L2_TOR_RX, L2_CFM_FRAME); (void)L2_SetupNextSlot(instPtr, L2_TOR_RX, L2_CFM_FRAME);
scanFsmPtr->cfmTimeout++; // increase counter. scanFsmPtr->cfmTimeout++; // increase counter.
instPtr->log.lastBeamWidth = PHY_ANT_BEAM_16; instPtr->log.lastBeamWidth = PHY_ANT_BEAM_16;
} }
@@ -287,17 +287,17 @@ static int32_t Scan_AdvHandler(L2_INST *instPtr)
if (scanFsmPtr->advTimeout > ADV_LISTEN_TIMEOUT) if (scanFsmPtr->advTimeout > ADV_LISTEN_TIMEOUT)
{ {
/* Antenna steering (reserved, automatically accomplished by physical layer) */ /* Antenna steering (reserved, automatically accomplished by physical layer) */
Phy_SetBeamNo(phyRef, scanFsmPtr->beamNo, PHY_ANT_BEAM_16); (void)Phy_SetBeamNo(phyRef, scanFsmPtr->beamNo, PHY_ANT_BEAM_16);
L2_SetupNextSlot(instPtr, L2_TOR_RX, L2_SCAN_FRAME); (void)L2_SetupNextSlot(instPtr, L2_TOR_RX, L2_SCAN_FRAME);
DBG_WARNING("Adv timeout, restart net scan from L2_SCAN_INIT_STAGE.\n"); DBG_WARNING("Adv timeout, restart net scan from L2_SCAN_INIT_STAGE.\n");
L2_Scan_Reset(scanFsmPtr); (void)L2_Scan_Reset(scanFsmPtr);
instPtr->log.lastBeamWidth = PHY_ANT_BEAM_16; instPtr->log.lastBeamWidth = PHY_ANT_BEAM_16;
} }
else else
{ {
/* Antenna steering (reserved, automatically accomplished by physical layer) */ /* Antenna steering (reserved, automatically accomplished by physical layer) */
Phy_SetBeamNo(phyRef, scanFsmPtr->beamNo, PHY_ANT_BEAM_16); (void)Phy_SetBeamNo(phyRef, scanFsmPtr->beamNo, PHY_ANT_BEAM_16);
L2_SetupNextSlot(instPtr, L2_TOR_RX, L2_ADV_FRAME); (void)L2_SetupNextSlot(instPtr, L2_TOR_RX, L2_ADV_FRAME);
scanFsmPtr->advTimeout++; scanFsmPtr->advTimeout++;
instPtr->log.lastBeamWidth = PHY_ANT_BEAM_16; instPtr->log.lastBeamWidth = PHY_ANT_BEAM_16;
} }
@@ -332,10 +332,10 @@ static int32_t Scan_CfmHandler(L2_INST *instPtr)
{ {
// using pull mode to receive confirm frame // using pull mode to receive confirm frame
// since first time sync procedure is accomplished in ADV stage. // since first time sync procedure is accomplished in ADV stage.
Phy_SetBeamWidth(phyRef, PHY_ANT_BEAM_16); (void)Phy_SetBeamWidth(phyRef, PHY_ANT_BEAM_16);
Phy_SetBeamNo(phyRef, scanFsmPtr->beamNo, PHY_ANT_BEAM_16); (void)Phy_SetBeamNo(phyRef, scanFsmPtr->beamNo, PHY_ANT_BEAM_16);
Phy_SetMode(phyRef, PHY_MODE_PULL); (void)Phy_SetMode(phyRef, PHY_MODE_PULL);
L2_SetupNextSlot(instPtr, L2_TOR_RX, L2_CFM_FRAME); (void)L2_SetupNextSlot(instPtr, L2_TOR_RX, L2_CFM_FRAME);
scanFsmPtr->cfmTimeout++; // increase counter. scanFsmPtr->cfmTimeout++; // increase counter.
instPtr->log.lastBeamWidth = PHY_ANT_BEAM_16; instPtr->log.lastBeamWidth = PHY_ANT_BEAM_16;
} }
@@ -359,7 +359,7 @@ static int32_t ScanMsg_Packing(L2_INST *instPtr, L2_FRAME_TYPE type, uint8_t dst
int32_t Status; int32_t Status;
uint32_t dataChunk; uint32_t dataChunk;
uint8_t *buff = instPtr->sendPktData; uint8_t *buff = instPtr->sendPktData;
if (type < L2_ADV_FRAME || type > L2_CFM_FRAME) if ((type < L2_ADV_FRAME) || (type > L2_CFM_FRAME))
{ {
DBG_ERROR("Unexpected frame type: %" PRId8 ".\n", type); DBG_ERROR("Unexpected frame type: %" PRId8 ".\n", type);
return EPARAM; return EPARAM;
@@ -409,27 +409,6 @@ static int32_t ScanMsg_Packing(L2_INST *instPtr, L2_FRAME_TYPE type, uint8_t dst
L2_FrameInsertChunk(buff, L2_MSG_CFM_SRC_POSX, L2_MSG_CFM_SRC_POSX_LEN, &(instPtr->sysInfo.posX)); L2_FrameInsertChunk(buff, L2_MSG_CFM_SRC_POSX, L2_MSG_CFM_SRC_POSX_LEN, &(instPtr->sysInfo.posX));
L2_FrameInsertChunk(buff, L2_MSG_CFM_SRC_POSY, L2_MSG_CFM_SRC_POSY_LEN, &(instPtr->sysInfo.posY)); L2_FrameInsertChunk(buff, L2_MSG_CFM_SRC_POSY, L2_MSG_CFM_SRC_POSY_LEN, &(instPtr->sysInfo.posY));
L2_FrameInsertChunk(buff, L2_MSG_CFM_SRC_POSZ, L2_MSG_CFM_SRC_POSZ_LEN, &(instPtr->sysInfo.posZ)); L2_FrameInsertChunk(buff, L2_MSG_CFM_SRC_POSZ, L2_MSG_CFM_SRC_POSZ_LEN, &(instPtr->sysInfo.posZ));
L2_FrameInsertChunk(buff, L2_MSG_CFM_SRC_SPEEDX, L2_MSG_CFM_SRC_SPEEDX_LEN, &(instPtr->sysInfo.vX));
L2_FrameInsertChunk(buff, L2_MSG_CFM_SRC_SPEEDY, L2_MSG_CFM_SRC_SPEEDY_LEN, &(instPtr->sysInfo.vY));
L2_FrameInsertChunk(buff, L2_MSG_CFM_SRC_SPEEDZ, L2_MSG_CFM_SRC_SPEEDZ_LEN, &(instPtr->sysInfo.vZ));
// Packing extra payload
uint32_t dataId;
if (L2_GetNodeType(instPtr) == L2_NODE_HEAD)
{
SysMonitor_GetSendPayload(buff + L2_MSG_CFM_PAYLOAD, &dataId, PAYLOAD_LEN_FLJ_TX);
}
else
{
SysMonitor_GetSendPayload(buff + L2_MSG_CFM_PAYLOAD, &dataId, PAYLOAD_LEN_LJ_TX);
}
L2_FrameInsertChunk(buff, L2_MSG_CFM_PAYLOAD_ID, L2_MSG_CFM_PAYLOAD_ID_LEN, &dataId);
if (dataId == DATA_ID_NONE)
{
memset(buff + L2_MSG_CFM_PAYLOAD, 0xAA, L2_MSG_CFM_PAYLOAD_LEN);
}
// Append CRC // Append CRC
Status = L2_CrcAppend(buff, L2_CMF_PACK_LEN - L2_MSG_CFM_CRC_LEN, L2_MSG_CFM_CRC, L2_CRC16_1021); Status = L2_CrcAppend(buff, L2_CMF_PACK_LEN - L2_MSG_CFM_CRC_LEN, L2_MSG_CFM_CRC, L2_CRC16_1021);
if (Status != SUCCESS) if (Status != SUCCESS)
@@ -437,10 +416,6 @@ static int32_t ScanMsg_Packing(L2_INST *instPtr, L2_FRAME_TYPE type, uint8_t dst
DBG_ERROR("Fail to append CRC, error code: %" PRId32 ".\n", Status); DBG_ERROR("Fail to append CRC, error code: %" PRId32 ".\n", Status);
return Status; return Status;
} }
// Logging...
memcpy(instPtr->log.txLog.data, buff, L2_CMF_PACK_LEN);
instPtr->log.txLog.dataId = dataId;
break; break;
} }
default: default:
@@ -564,13 +539,6 @@ int32_t L2_Scan_PktHandler(L2_INST *instPtr, uint8_t *msg)
node->nodeInfo.pos.y = (double)nodePos; node->nodeInfo.pos.y = (double)nodePos;
L2_FrameGetChunk(msg, L2_MSG_CFM_SRC_POSZ, L2_MSG_CFM_SRC_POSZ_LEN, &nodePos); L2_FrameGetChunk(msg, L2_MSG_CFM_SRC_POSZ, L2_MSG_CFM_SRC_POSZ_LEN, &nodePos);
node->nodeInfo.pos.z = (double)nodePos; node->nodeInfo.pos.z = (double)nodePos;
float nodeSpeed;
L2_FrameGetChunk(msg, L2_MSG_CFM_SRC_SPEEDX, L2_MSG_CFM_SRC_SPEEDX_LEN, &nodeSpeed);
node->nodeInfo.speed.x = (double)nodePos;
L2_FrameGetChunk(msg, L2_MSG_CFM_SRC_SPEEDY, L2_MSG_CFM_SRC_SPEEDY_LEN, &nodeSpeed);
node->nodeInfo.speed.y = (double)nodePos;
L2_FrameGetChunk(msg, L2_MSG_CFM_SRC_SPEEDZ, L2_MSG_CFM_SRC_SPEEDZ_LEN, &nodeSpeed);
node->nodeInfo.speed.z = (double)nodePos;
// Reset node ttl // Reset node ttl
node->ttlCnt = 0; node->ttlCnt = 0;
@@ -606,7 +574,7 @@ int32_t L2_Scan_PktHandler(L2_INST *instPtr, uint8_t *msg)
}; };
newRtneConfig.rtneTable = initTable; newRtneConfig.rtneTable = initTable;
newRtneConfig.rtnePrd = ARRAY_SIZE(initTable); newRtneConfig.rtnePrd = ARRAY_SIZE(initTable);
AssertL2Event(instPtr, &rtneUpEvent); (void)AssertL2Event(instPtr, &rtneUpEvent);
} }
PendCfmAck(instPtr->scanFSM); PendCfmAck(instPtr->scanFSM);
// Time sync. // Time sync.
@@ -622,27 +590,10 @@ int32_t L2_Scan_PktHandler(L2_INST *instPtr, uint8_t *msg)
L2_NODE_STATE newState = L2_NORMAL_STATE; L2_NODE_STATE newState = L2_NORMAL_STATE;
l2Event.event = L2_EV_MAIN_STATE_UPDATE; l2Event.event = L2_EV_MAIN_STATE_UPDATE;
l2Event.msg = &newState; l2Event.msg = &newState;
AssertL2Event(instPtr, &l2Event); (void)AssertL2Event(instPtr, &l2Event);
} }
} }
// Get data payload
uint32_t dataId;
L2_FrameGetChunk(msg, L2_MSG_CFM_PAYLOAD_ID, L2_MSG_CFM_PAYLOAD_ID_LEN, &dataId);
if (L2_GetNodeType(instPtr) == L2_NODE_HEAD)
{
SysMonitor_UpdateRecvPayload(msg + L2_MSG_CFM_PAYLOAD, dataId, PAYLOAD_LEN_FLJ_RX);
}
else
{
SysMonitor_UpdateRecvPayload(msg + L2_MSG_CFM_PAYLOAD, dataId, PAYLOAD_LEN_LJ_RX);
}
// Logging...
memcpy(instPtr->log.rxLog.data, msg, L2_CMF_PACK_LEN);
instPtr->log.rxLog.dataId = dataId;
Status = SUCCESS; Status = SUCCESS;
break; break;
} }
@@ -796,7 +747,6 @@ int32_t L2_Scan_Routine(L2_INST *instPtr, const L2_RTNE_TABLE_ENTRY *rtneEntry)
{ {
ASSERT(instPtr != NULL); ASSERT(instPtr != NULL);
L2_TOR_TYPE torState; L2_TOR_TYPE torState;
int32_t Status;
const NODE_ENTRY *commNode; const NODE_ENTRY *commNode;
PHY_INST *phyRef = instPtr->config.phyInstPtr; PHY_INST *phyRef = instPtr->config.phyInstPtr;
DBG_INFO("-------- Scan Routine --------\n"); DBG_INFO("-------- Scan Routine --------\n");
@@ -828,7 +778,7 @@ int32_t L2_Scan_Routine(L2_INST *instPtr, const L2_RTNE_TABLE_ENTRY *rtneEntry)
instPtr->log.lastBeamWidth = PHY_ANT_BEAM_16; instPtr->log.lastBeamWidth = PHY_ANT_BEAM_16;
if (commNode != NULL) if (commNode != NULL)
{ {
Phy_SetBeamNo(phyRef, commNode->nodeInfo.beamNo, PHY_ANT_BEAM_16); (void)Phy_SetBeamNo(phyRef, commNode->nodeInfo.beamNo, PHY_ANT_BEAM_16);
} }
} }
else else
@@ -846,7 +796,7 @@ int32_t L2_Scan_Routine(L2_INST *instPtr, const L2_RTNE_TABLE_ENTRY *rtneEntry)
torState = L2_TOR_SUSPEND; torState = L2_TOR_SUSPEND;
} }
// Setup antenna beam // Setup antenna beam
Phy_SetBeamWidth(phyRef, PHY_ANT_BEAM_120); (void)Phy_SetBeamWidth(phyRef, PHY_ANT_BEAM_120);
instPtr->log.lastBeamWidth = PHY_ANT_BEAM_120; instPtr->log.lastBeamWidth = PHY_ANT_BEAM_120;
} }
@@ -856,10 +806,9 @@ int32_t L2_Scan_Routine(L2_INST *instPtr, const L2_RTNE_TABLE_ENTRY *rtneEntry)
if (L2_GetNodeType(instPtr) != L2_NODE_HEAD && torState == L2_TOR_TX) if (L2_GetNodeType(instPtr) != L2_NODE_HEAD && torState == L2_TOR_TX)
{ {
DBG_ERROR("Only head node can send init-scan Frame.\n"); DBG_ERROR("Only head node can send init-scan Frame.\n");
Status = FAILURE; return FAILURE;
goto routine_err;
} }
L2_SetupNextSlot(instPtr, torState, L2_SCAN_FRAME); (void)L2_SetupNextSlot(instPtr, torState, L2_SCAN_FRAME);
break; break;
case L2_SLOT_ADVERTISE: case L2_SLOT_ADVERTISE:
@@ -868,18 +817,16 @@ int32_t L2_Scan_Routine(L2_INST *instPtr, const L2_RTNE_TABLE_ENTRY *rtneEntry)
if (L2_GetNodeType(instPtr) != L2_NODE_HEAD) if (L2_GetNodeType(instPtr) != L2_NODE_HEAD)
{ {
DBG_ERROR("Only head node can send ADV Frame.\n"); DBG_ERROR("Only head node can send ADV Frame.\n");
Status = FAILURE; return FAILURE;
goto routine_err;
} }
memset(instPtr->sendPktData, 0xAA, L2_PACK_LEN_MAX); memset(instPtr->sendPktData, 0xAA, L2_PACK_LEN_MAX);
if (ScanMsg_Packing(instPtr, L2_ADV_FRAME, rtneEntry->dst) != SUCCESS) if (ScanMsg_Packing(instPtr, L2_ADV_FRAME, rtneEntry->dst) != SUCCESS)
{ {
Status = FAILURE; return FAILURE;
goto routine_err;
} }
} }
/* Antenna setting (reserved.) */ /* Antenna setting (reserved.) */
L2_SetupNextSlot(instPtr, torState, L2_ADV_FRAME); (void)L2_SetupNextSlot(instPtr, torState, L2_ADV_FRAME);
break; break;
case L2_SLOT_CONFIRM: case L2_SLOT_CONFIRM:
@@ -896,21 +843,17 @@ int32_t L2_Scan_Routine(L2_INST *instPtr, const L2_RTNE_TABLE_ENTRY *rtneEntry)
memset(instPtr->sendPktData, 0xAA, L2_PACK_LEN_MAX); memset(instPtr->sendPktData, 0xAA, L2_PACK_LEN_MAX);
if (ScanMsg_Packing(instPtr, L2_CFM_FRAME, rtneEntry->dst) != SUCCESS) if (ScanMsg_Packing(instPtr, L2_CFM_FRAME, rtneEntry->dst) != SUCCESS)
{ {
Status = FAILURE; return FAILURE;
goto routine_err;
} }
} }
/* Antenna setting (reserved.) */ /* Antenna setting (reserved.) */
L2_SetupNextSlot(instPtr, torState, L2_CFM_FRAME); (void)L2_SetupNextSlot(instPtr, torState, L2_CFM_FRAME);
break; break;
default: default:
DBG_ERROR("Cannot start a routine for slot type [%" PRId8 "] properly.\n", rtneEntry->slotType); DBG_ERROR("Cannot start a routine for slot type [%" PRId8 "] properly.\n", rtneEntry->slotType);
Status = FAILURE; return FAILURE;
goto routine_err;
} }
return SUCCESS; return SUCCESS;
routine_err:
return Status;
} }
/** @} LinkLayer_Scan*/ /** @} LinkLayer_Scan*/
@@ -365,7 +365,7 @@ void L2_EventPoolHandler(L2_INST *instPtr)
if (event->schdFrame == L2_GetCurrentFrameNum(instPtr) && event->schdSlot == L2_GetCurrentSlotNum(instPtr)) if (event->schdFrame == L2_GetCurrentFrameNum(instPtr) && event->schdSlot == L2_GetCurrentSlotNum(instPtr))
{ {
DBG_INFO("Asserting scheduled event [%" PRIu32 "].\n", event->eventId); DBG_INFO("Asserting scheduled event [%" PRIu32 "].\n", event->eventId);
AssertL2Event(instPtr, &(event->l2Event)); (void)AssertL2Event(instPtr, &(event->l2Event));
if (event->isVolatile == true) if (event->isVolatile == true)
{ {
DBG_INFO("Deleting scheduled event [%" PRIu32 "], since it is volatile.\n", event->eventId); DBG_INFO("Deleting scheduled event [%" PRIu32 "], since it is volatile.\n", event->eventId);
@@ -155,8 +155,9 @@ static int32_t Service_Packing(L2_INST *instPtr, L2_FRAME_TYPE type, uint8_t dst
} }
return SUCCESS; return SUCCESS;
#else #else
DBG_ERROR("Unexpected call of Service_Packing in BER test mode.\n"); size_t packLen = Phy_GetFrameLen(L2_L2frame2L1frame(L2_SVC_FRAME));
return EUNEXP; memcpy(instPtr->sendPktData, testData, packLen);
return SUCCESS;
#endif #endif
} }
@@ -260,33 +261,63 @@ int32_t L2_Service_PktHandler(L2_INST *instPtr, uint8_t *msg)
} }
return Status; return Status;
#else #else
NODE_ENTRY *node;
uint8_t nodeId = (L2_GetNodeType(instPtr) == L2_NODE_HEAD) ? 0x02 : 0x01;
node = L2_GetNodeById(instPtr->nodeList, nodeId);
if (node == NULL)
{
node = L2_AppendNode(instPtr->nodeList, nodeId, L2_NODE_MEMBER);
if (node == NULL)
{
DBG_ERROR("Failed to append new node [id: %" PRIu8 "]", nodeId);
return ENOMEM;
}
}
// Reset node ttl
node->ttlCnt = 0;
// Calculate time deviation
uint32_t frameNum = L2_GetCurrentFrameNum(instPtr);
uint32_t slotNum = L2_GetCurrentSlotNum(instPtr);
// //NOTE: Service frame length is 20ms with 5ms idle
// if(slotNum < 5)
// {
// slotNum = L2_SLOTS_PER_FRAME - 5;
// frameNum = frameNum - 1;
// }
// else
// {
// slotNum = slotNum / 5 * 5 - 5;
// }
// Status = L2_GetTimeDeviation(instPtr, frameNum, slotNum, true, &(instPtr->log.timeDev));
// if (Status != SUCCESS)
// {
// DBG_ERROR("Failed to compute time deviation.\n")
// return Status;
// }
// // Implement a auto time sync.
// if (L2_GetNodeType(instPtr) != L2_NODE_HEAD)
// {
// // Time sync.
// L2_TimeAdjust(instPtr, &(instPtr->log.timeDev));
// }
return SUCCESS;
#endif
}
bool L2_Service_PktCheck(L2_INST *instPtr, uint8_t *msg)
{
size_t packLen = Phy_GetFrameLen(L2_L2frame2L1frame(L2_SVC_FRAME)) & 0xFFFFFFFE;
uint32_t errorBits = 0; uint32_t errorBits = 0;
for (int i = 0; i < L2_SVC_PACK_LEN; i++) for (int i = 0; i < packLen; i++)
{ {
errorBits += count_ones(msg[i] ^ testData[i]); errorBits += count_ones(msg[i] ^ testData[i]);
} }
instPtr->serviceFSM->bitError += errorBits; instPtr->serviceFSM->bitError += errorBits;
instPtr->serviceFSM->bitTotal += L2_SVC_PACK_LEN * 8; instPtr->serviceFSM->bitTotal += packLen * 8;
return (errorBits == 0);
// Calculate time deviation
uint32_t frameNum, slotNum = 0;
L2_FrameGetChunk(msg, L2_MSG_FRAME_NUM, L2_MSG_FRAME_NUM_LEN, &frameNum);
L2_FrameGetChunk(msg, L2_MSG_SLOT_NUM, L2_MSG_SLOT_NUM_LEN, &slotNum);
Status = L2_GetTimeDeviation(instPtr, frameNum, slotNum, true, &(instPtr->log.timeDev));
if (Status != SUCCESS)
{
DBG_ERROR("Failed to compute time deviation.\n")
return Status;
}
// Implement a auto time sync.
if (L2_GetNodeType(instPtr) != L2_NODE_HEAD)
{
// Time sync.
L2_TimeAdjust(instPtr, &(instPtr->log.timeDev));
}
return SUCCESS;
#endif
} }
/*****************************************************************************/ /*****************************************************************************/
@@ -406,12 +437,7 @@ int32_t L2_Service_Routine(L2_INST *instPtr, const L2_RTNE_TABLE_ENTRY *rtneEntr
if (torState == L2_TOR_TX) if (torState == L2_TOR_TX)
{ {
svcFSMPtr->txCnt++; svcFSMPtr->txCnt++;
#ifndef DATALINK_ENABLE_BERTEST
// Packing service data
Service_Packing(instPtr, L2_SVC_FRAME, rtneEntry->dst); Service_Packing(instPtr, L2_SVC_FRAME, rtneEntry->dst);
#else
memcpy(instPtr->sendPktData, testData, L2_SVC_PACK_LEN);
#endif
} }
else else
{ {
@@ -435,4 +461,4 @@ int32_t L2_Service_Routine(L2_INST *instPtr, const L2_RTNE_TABLE_ENTRY *rtneEntr
} }
/** @} LinkLayer_Service*/ /** @} LinkLayer_Service*/
/** @} LinkLayer*/ /** @} LinkLayer*/
@@ -69,20 +69,20 @@
// Regex: (([0-9]+, ){8}) // Regex: (([0-9]+, ){8})
const uint16_t freqTable[L1_FRAME_MAX_HOPS] = const uint16_t freqTable[L1_FRAME_MAX_HOPS] =
{ {
1084, 1097, 1110, 1123, 1136, 1149, 1162, 1175, 1084U, 1097U, 1110U, 1123U, 1136U, 1149U, 1162U, 1175U,
1188, 1201, 1214, 1227, 1240, 1253, 1266, 1279, 1188U, 1201U, 1214U, 1227U, 1240U, 1253U, 1266U, 1279U,
1292, 1305, 1318, 1331, 1344, 1357, 1370, 1383, 1292U, 1305U, 1318U, 1331U, 1344U, 1357U, 1370U, 1383U,
1396, 1409, 1422, 1435, 1448, 1461, 1474, 1487, 1396U, 1409U, 1422U, 1435U, 1448U, 1461U, 1474U, 1487U,
1500, 1513, 1526, 1539, 1552, 1565, 1578, 1591, 1500U, 1513U, 1526U, 1539U, 1552U, 1565U, 1578U, 1591U,
1604, 1617, 1630, 1643, 1656, 1669, 1682, 1695, 1604U, 1617U, 1630U, 1643U, 1656U, 1669U, 1682U, 1695U,
1708, 1721, 1734, 1747, 1760, 1773, 1786, 1799, 1708U, 1721U, 1734U, 1747U, 1760U, 1773U, 1786U, 1799U,
1812, 1825, 1838, 1851, 1864, 1877, 1890, 1903, 1812U, 1825U, 1838U, 1851U, 1864U, 1877U, 1890U, 1903U,
1916, 1929, 1942, 1955, 1968, 1981, 1994, 2007, 1916U, 1929U, 1942U, 1955U, 1968U, 1981U, 1994U, 2007U,
2020, 2033, 2046, 2059, 2072, 2085, 2098, 2111, 2020U, 2033U, 2046U, 2059U, 2072U, 2085U, 2098U, 2111U,
2124 2124U
}; };
const uint16_t antCalTable[L1_FRAME_MAX_HOPS][L1_ANT_NUM_CH] = const int16_t antCalTable[L1_FRAME_MAX_HOPS][L1_ANT_NUM_CH] =
//Antenna-JG01 //Antenna-JG01
{ {
{ 0, 2525, -7533, -6846}, { 0, 12726, -7818, -6860}, { 0, 2525, -7533, -6846}, { 0, 12726, -7818, -6860},
@@ -135,55 +135,55 @@ const uint8_t hopPattern_2KBPS_20MS[L1_FRAME_2KBPS_20MS_HOPS] =
const uint8_t hopPattern_2KBPS_100MS[L1_FRAME_2KBPS_100MS_HOPS] = const uint8_t hopPattern_2KBPS_100MS[L1_FRAME_2KBPS_100MS_HOPS] =
{ {
0, 1, 2, 3, 4, 5, 6, 7, 0U, 1U, 2U, 3U, 4U, 5U, 6U, 7U,
8, 9, 10, 11, 12, 13, 14, 15, 8U, 9U, 10U, 11U, 12U, 13U, 14U, 15U,
16, 17, 18, 19, 20, 21, 22, 23, 16U, 17U, 18U, 19U, 20U, 21U, 22U, 23U,
24, 25, 26, 27, 28, 29, 30, 31, 24U, 25U, 26U, 27U, 28U, 29U, 30U, 31U,
32, 33, 34, 35, 36, 37, 38, 39, 32U, 33U, 34U, 35U, 36U, 37U, 38U, 39U,
40, 41, 42, 43, 44, 45, 46, 47, 40U, 41U, 42U, 43U, 44U, 45U, 46U, 47U,
48, 49, 50, 51, 52, 53, 54, 55, 48U, 49U, 50U, 51U, 52U, 53U, 54U, 55U,
56, 57, 58, 59, 60, 61, 62, 63, 56U, 57U, 58U, 59U, 60U, 61U, 62U, 63U,
64, 65, 66, 67, 68, 69, 70, 71, 64U, 65U, 66U, 67U, 68U, 69U, 70U, 71U,
72, 73, 74, 75, 76, 77, 78, 79, 72U, 73U, 74U, 75U, 76U, 77U, 78U, 79U,
80 80U
}; };
const uint8_t hopPattern_10KBPS_10MS[L1_FRAME_10KBPS_10MS_HOPS] = const uint8_t hopPattern_10KBPS_10MS[L1_FRAME_10KBPS_10MS_HOPS] =
{ {
80 80U
}; };
const uint8_t hopPattern_10KBPS_20MS[L1_FRAME_10KBPS_20MS_HOPS] = const uint8_t hopPattern_10KBPS_20MS[L1_FRAME_10KBPS_20MS_HOPS] =
{ {
80, 1, 2, 3, 4, 5, 6, 7, 80U, 1U, 2U, 3U, 4U, 5U, 6U, 7U,
8, 9, 10 8U, 9U, 10U
}; };
const uint8_t hopPattern_40KBPS_10MS[L1_FRAME_40KBPS_10MS_HOPS] = const uint8_t hopPattern_40KBPS_10MS[L1_FRAME_40KBPS_10MS_HOPS] =
{ {
0, 1, 2, 3, 4, 5, 6, 7, 0U, 1U, 2U, 3U, 4U, 5U, 6U, 7U,
8, 8U,
}; };
const uint8_t hopPattern_40KBPS_20MS[L1_FRAME_40KBPS_20MS_HOPS] = const uint8_t hopPattern_40KBPS_20MS[L1_FRAME_40KBPS_20MS_HOPS] =
{ {
0, 1, 2, 3, 4, 5, 6, 7, 0U, 1U, 2U, 3U, 4U, 5U, 6U, 7U,
8, 9, 10, 11, 12, 13, 14, 15, 8U, 9U, 10U, 11U, 12U, 13U, 14U, 15U,
16, 17, 18 16U, 17U, 18U
}; };
const uint8_t hopPattern_200KBPS_5MS[L1_FRAME_200KBPS_5MS_HOPS] = const uint8_t hopPattern_200KBPS_5MS[L1_FRAME_200KBPS_5MS_HOPS] =
{ {
0, 1, 2, 3, 4, 5, 6, 7, 0U, 1U, 2U, 3U, 4U, 5U, 6U, 7U,
8, 9, 10, 11, 12, 13, 14, 15, 8U, 9U, 10U, 11U, 12U, 13U, 14U, 15U,
16, 17, 18, 19 16U, 17U, 18U, 19U
}; };
const uint8_t hopPattern_1M2BPS_5MS[L1_FRAME_1M2BPS_5MS_HOPS] = const uint8_t hopPattern_1M2BPS_5MS[L1_FRAME_1M2BPS_5MS_HOPS] =
{ {
0, 1, 2, 3, 4, 5, 6, 7, 0U, 1U, 2U, 3U, 4U, 5U, 6U, 7U,
8, 9, 10, 11, 12, 13, 14, 15, 8U, 9U, 10U, 11U, 12U, 13U, 14U, 15U,
16, 17, 18, 19 16U, 17U, 18U, 19U
}; };
/** @} PhysicalLayer_AntennaConfig_Constants*/ /** @} PhysicalLayer_AntennaConfig_Constants*/
@@ -317,7 +317,7 @@ void Phy_SetBeamTable(PHY_INST *instPtr, PHY_ANT_ANGLE *table, uint32_t offset)
* FAILURE beamNo exceeds the table size * FAILURE beamNo exceeds the table size
* *
******************************************************************************/ ******************************************************************************/
int32_t Phy_SetBeamNo(PHY_INST *instPtr, int32_t beamNo, PHY_ANT_BEAM_WIDTH beamWidth) int32_t Phy_SetBeamNo(PHY_INST *instPtr, size_t beamNo, PHY_ANT_BEAM_WIDTH beamWidth)
{ {
ASSERT(instPtr != NULL); ASSERT(instPtr != NULL);
@@ -406,8 +406,8 @@ int32_t Phy_SetBeamAngle(PHY_INST *instPtr, double offAx, double rndAx)
ASSERT(instPtr != NULL); ASSERT(instPtr != NULL);
uint16_t offAxDeg = 0; uint16_t offAxDeg = 0;
uint16_t rndAxDeg = 0; uint16_t rndAxDeg = 0;
offAxDeg = (offAx >= 0) ? (((int32_t)(offAx * 180 / ANT_PI)) % 360) : (((int32_t)(offAx * 180 / ANT_PI)) % 360 + 360); offAxDeg = (offAx >= 0) ? (((int32_t)(offAx * 180.0 / ANT_PI)) % 360) : (((int32_t)(offAx * 180.0 / ANT_PI)) % 360 + 360);
rndAxDeg = (rndAx >= 0) ? (((int32_t)(rndAx * 180 / ANT_PI)) % 360) : (((int32_t)(rndAx * 180 / ANT_PI)) % 360 + 360); rndAxDeg = (rndAx >= 0) ? (((int32_t)(rndAx * 180.0 / ANT_PI)) % 360) : (((int32_t)(rndAx * 180.0 / ANT_PI)) % 360 + 360);
if (offAxDeg > 60) if (offAxDeg > 60)
{ {
DBG_ERROR("Angle out of range, off axis angle: %" PRIu16 " (should be 0~60), round axis angle: %" PRIu16 " (should be 0~360).\n", DBG_ERROR("Angle out of range, off axis angle: %" PRIu16 " (should be 0~60), round axis angle: %" PRIu16 " (should be 0~360).\n",
@@ -335,7 +335,7 @@ inline L1_FRAME_TYPE Phy_GetLastRecvFrameType(PHY_INST *instPtr)
{ {
return L1_NONE_FRAME; return L1_NONE_FRAME;
} }
int32_t frame_type = (PhyRead(instPtr, COASE_FREQEST) & COASE_TYPE_MASK); uint32_t frame_type = (PhyRead(instPtr, COASE_FREQEST) & COASE_TYPE_MASK);
switch (frame_type) switch (frame_type)
{ {
case COASE_TYPE_2KBPS_20MS: case COASE_TYPE_2KBPS_20MS:
@@ -439,14 +439,15 @@ int32_t Phy_Init(PHY_INST **instPtr, PHY_CONFIG *phyConfig)
bramConfigPtr = XBram_LookupConfig(phyConfig->antBramId); bramConfigPtr = XBram_LookupConfig(phyConfig->antBramId);
if (bramConfigPtr == NULL) if (bramConfigPtr == NULL)
{ {
Status = EDCONF; Phy_Destroy(*instPtr);
goto init_error; return EDCONF;
} }
Status = XBram_CfgInitialize(&antConfigBram, bramConfigPtr, Status = XBram_CfgInitialize(&antConfigBram, bramConfigPtr,
bramConfigPtr->CtrlBaseAddress); bramConfigPtr->CtrlBaseAddress);
if (Status != SUCCESS) if (Status != SUCCESS)
{ {
goto init_error; Phy_Destroy(*instPtr);
return Status;
} }
/* /*
* Execute the BRAM driver selftest. * Execute the BRAM driver selftest.
@@ -454,20 +455,22 @@ int32_t Phy_Init(PHY_INST **instPtr, PHY_CONFIG *phyConfig)
Status = XBram_SelfTest(&antConfigBram, 0); Status = XBram_SelfTest(&antConfigBram, 0);
if (Status != SUCCESS) if (Status != SUCCESS)
{ {
goto init_error; Phy_Destroy(*instPtr);
return Status;
} }
bramConfigPtr = XBram_LookupConfig(phyConfig->txBramId); bramConfigPtr = XBram_LookupConfig(phyConfig->txBramId);
if (bramConfigPtr == NULL) if (bramConfigPtr == NULL)
{ {
Status = EDCONF; Phy_Destroy(*instPtr);
goto init_error; return EDCONF;
} }
Status = XBram_CfgInitialize(&txDataBram, bramConfigPtr, Status = XBram_CfgInitialize(&txDataBram, bramConfigPtr,
bramConfigPtr->CtrlBaseAddress); bramConfigPtr->CtrlBaseAddress);
if (Status != SUCCESS) if (Status != SUCCESS)
{ {
goto init_error; Phy_Destroy(*instPtr);
return Status;
} }
/* /*
* Execute the BRAM driver selftest. * Execute the BRAM driver selftest.
@@ -475,20 +478,22 @@ int32_t Phy_Init(PHY_INST **instPtr, PHY_CONFIG *phyConfig)
Status = XBram_SelfTest(&txDataBram, 0); Status = XBram_SelfTest(&txDataBram, 0);
if (Status != SUCCESS) if (Status != SUCCESS)
{ {
goto init_error; Phy_Destroy(*instPtr);
return Status;
} }
bramConfigPtr = XBram_LookupConfig(phyConfig->rxBramId); bramConfigPtr = XBram_LookupConfig(phyConfig->rxBramId);
if (bramConfigPtr == NULL) if (bramConfigPtr == NULL)
{ {
Status = EDCONF; Phy_Destroy(*instPtr);
goto init_error; return EDCONF;
} }
Status = XBram_CfgInitialize(&rxDataBram, bramConfigPtr, Status = XBram_CfgInitialize(&rxDataBram, bramConfigPtr,
bramConfigPtr->CtrlBaseAddress); bramConfigPtr->CtrlBaseAddress);
if (Status != SUCCESS) if (Status != SUCCESS)
{ {
goto init_error; Phy_Destroy(*instPtr);
return Status;
} }
/* /*
* Execute the BRAM driver selftest. * Execute the BRAM driver selftest.
@@ -496,7 +501,8 @@ int32_t Phy_Init(PHY_INST **instPtr, PHY_CONFIG *phyConfig)
Status = XBram_SelfTest(&rxDataBram, 0); Status = XBram_SelfTest(&rxDataBram, 0);
if (Status != SUCCESS) if (Status != SUCCESS)
{ {
goto init_error; Phy_Destroy(*instPtr);
return Status;
} }
(*instPtr)->antConfigAddr = antConfigBram.Config.MemBaseAddress; (*instPtr)->antConfigAddr = antConfigBram.Config.MemBaseAddress;
@@ -510,14 +516,15 @@ int32_t Phy_Init(PHY_INST **instPtr, PHY_CONFIG *phyConfig)
bramConfigPtr = XBram_LookupConfig(phyConfig->antInfoBramId); bramConfigPtr = XBram_LookupConfig(phyConfig->antInfoBramId);
if (bramConfigPtr == NULL) if (bramConfigPtr == NULL)
{ {
Status = EDCONF; Phy_Destroy(*instPtr);
goto init_error; return EDCONF;
} }
Status = XBram_CfgInitialize(&antInfoBram, bramConfigPtr, Status = XBram_CfgInitialize(&antInfoBram, bramConfigPtr,
bramConfigPtr->CtrlBaseAddress); bramConfigPtr->CtrlBaseAddress);
if (Status != SUCCESS) if (Status != SUCCESS)
{ {
goto init_error; Phy_Destroy(*instPtr);
return Status;
} }
/* /*
* Execute the BRAM driver self test. * Execute the BRAM driver self test.
@@ -525,7 +532,8 @@ int32_t Phy_Init(PHY_INST **instPtr, PHY_CONFIG *phyConfig)
Status = XBram_SelfTest(&antInfoBram, 0); Status = XBram_SelfTest(&antInfoBram, 0);
if (Status != SUCCESS) if (Status != SUCCESS)
{ {
goto init_error; Phy_Destroy(*instPtr);
return Status;
} }
(*instPtr)->antInfoAddr = antInfoBram.Config.MemBaseAddress; (*instPtr)->antInfoAddr = antInfoBram.Config.MemBaseAddress;
uint32_t phyMainCtrl = PhyRead(*instPtr, PHY_MAIN_CTRL); uint32_t phyMainCtrl = PhyRead(*instPtr, PHY_MAIN_CTRL);
@@ -545,8 +553,8 @@ int32_t Phy_Init(PHY_INST **instPtr, PHY_CONFIG *phyConfig)
xadcConfigPtr = XAdcPs_LookupConfig(phyConfig->hwXadcId); xadcConfigPtr = XAdcPs_LookupConfig(phyConfig->hwXadcId);
if (xadcConfigPtr == NULL) if (xadcConfigPtr == NULL)
{ {
Status = EDCONF; Phy_Destroy(*instPtr);
goto init_error; return EDCONF;
} }
XAdcPs_CfgInitialize(&((*instPtr)->hwXadc), xadcConfigPtr, xadcConfigPtr->BaseAddress); XAdcPs_CfgInitialize(&((*instPtr)->hwXadc), xadcConfigPtr, xadcConfigPtr->BaseAddress);
@@ -554,36 +562,37 @@ int32_t Phy_Init(PHY_INST **instPtr, PHY_CONFIG *phyConfig)
Status = XAdcPs_SelfTest(&((*instPtr)->hwXadc)); Status = XAdcPs_SelfTest(&((*instPtr)->hwXadc));
if (Status != SUCCESS) if (Status != SUCCESS)
{ {
goto init_error; Phy_Destroy(*instPtr);
return Status;
} }
/* Disable the Channel Sequencer before configuring the Sequence registers. */ /* Disable the Channel Sequencer before configuring the Sequence registers. */
XAdcPs_SetSequencerMode(&((*instPtr)->hwXadc), XADCPS_SEQ_MODE_SAFE); XAdcPs_SetSequencerMode(&((*instPtr)->hwXadc), XADCPS_SEQ_MODE_SAFE);
#else #else
(*instPtr)->antConfigAddr = NULL;
(*instPtr)->recvDataAddr = NULL;
(*instPtr)->sendDataAddr = NULL;
(*instPtr)->antConfigAddr = (uintptr_t)calloc(L1_ANTCONFIG_MAX_LEN / sizeof(uint64_t), sizeof(uint64_t)); (*instPtr)->antConfigAddr = (uintptr_t)calloc(L1_ANTCONFIG_MAX_LEN / sizeof(uint64_t), sizeof(uint64_t));
if ((*instPtr)->antConfigAddr == (uintptr_t)NULL) if ((*instPtr)->antConfigAddr == (uintptr_t)NULL)
{ {
Status = EDCONF; Phy_Destroy(*instPtr);
goto init_error; return EDCONF;
} }
(*instPtr)->recvDataAddr = (uintptr_t)calloc(L1_TXRXDATA_MAX_LEN / sizeof(uint64_t), sizeof(uint64_t)); (*instPtr)->recvDataAddr = (uintptr_t)calloc(L1_TXRXDATA_MAX_LEN / sizeof(uint64_t), sizeof(uint64_t));
if ((*instPtr)->recvDataAddr == (uintptr_t)NULL) if ((*instPtr)->recvDataAddr == (uintptr_t)NULL)
{ {
Status = EDCONF; Phy_Destroy(*instPtr);
goto init_error; return EDCONF;
} }
(*instPtr)->sendDataAddr = (uintptr_t)calloc(L1_TXRXDATA_MAX_LEN / sizeof(uint64_t), sizeof(uint64_t)); (*instPtr)->sendDataAddr = (uintptr_t)calloc(L1_TXRXDATA_MAX_LEN / sizeof(uint64_t), sizeof(uint64_t));
if ((*instPtr)->sendDataAddr == (uintptr_t)NULL) if ((*instPtr)->sendDataAddr == (uintptr_t)NULL)
{ {
Status = EDCONF; Phy_Destroy(*instPtr);
goto init_error; return EDCONF;
} }
#endif #endif
return SUCCESS; return SUCCESS;
init_error:
Phy_Destroy(*instPtr);
return Status;
} }
/*****************************************************************************/ /*****************************************************************************/
@@ -1027,7 +1036,7 @@ void Phy_RefreshHwSate(PHY_INST *instPtr)
ASSERT(instPtr != NULL); ASSERT(instPtr != NULL);
uint32_t rawData; uint32_t rawData;
#ifndef EMULATION #ifndef EMULATION
float evalData; double evalData;
instPtr->hwSate.isSpOk = true; instPtr->hwSate.isSpOk = true;
// -- Update FPGA voltage status; // -- Update FPGA voltage status;
instPtr->hwSate.spFpgaVolt = 0; instPtr->hwSate.spFpgaVolt = 0;
@@ -1250,7 +1259,7 @@ double Phy_GetCoarseFreqEst(PHY_INST *instPtr)
double freqEst; double freqEst;
frameType = Phy_GetLastRecvFrameType(instPtr); frameType = Phy_GetLastRecvFrameType(instPtr);
if (frameType > L1_1M2BPS_5MS_FRAME || frameType <= L1_NONE_FRAME) if ((frameType > L1_1M2BPS_5MS_FRAME) || (frameType <= L1_NONE_FRAME))
{ {
return INFINITY; // FIXME return INFINITY; // FIXME
} }
@@ -1288,14 +1297,14 @@ double Phy_GetFineFreqEst(PHY_INST *instPtr)
double freqEst; double freqEst;
L1_FRAME_TYPE frameType; L1_FRAME_TYPE frameType;
frameType = Phy_GetLastRecvFrameType(instPtr); frameType = Phy_GetLastRecvFrameType(instPtr);
if (frameType > L1_1M2BPS_5MS_FRAME || frameType <= L1_NONE_FRAME) if ((frameType > L1_1M2BPS_5MS_FRAME) || (frameType <= L1_NONE_FRAME))
{ {
return INFINITY; // FIXME return INFINITY; // FIXME
} }
regValue = PhyRead(instPtr, FINE_FREQEST); regValue = PhyRead(instPtr, FINE_FREQEST);
estAbs = regValue & FINE_FREQEST_VAL_MASK; estAbs = regValue & FINE_FREQEST_VAL_MASK;
if (frameType >= L1_200KBPS_5MS_FRAME) if ((frameType >= L1_200KBPS_5MS_FRAME))
{ {
// 12M Rc // 12M Rc
freqEst = 48e6 / 2048 * ((double)estAbs) / 8192.0; freqEst = 48e6 / 2048 * ((double)estAbs) / 8192.0;
@@ -34,24 +34,24 @@
* @name PhysicalLayer_Common_Constant * @name PhysicalLayer_Common_Constant
* @{ * @{
*/ */
#define L1_NUM_ANT_NRRW_PATTERN 37 #define L1_NUM_ANT_NRRW_PATTERN 37U
#define L1_INIT_BEAM_NO 0 #define L1_INIT_BEAM_NO 0U
#define L1_INIT_ANT_WD PHY_ANT_BEAM_120 #define L1_INIT_ANT_WD PHY_ANT_BEAM_120
#define L1_ANT_NUM_CH 4 #define L1_ANT_NUM_CH 4U
#define L1_FRAME_NONE_LEN UINT32_MAX // byte #define L1_FRAME_NONE_LEN UINT32_MAX // byte
#define L1_FRAME_NONE_COMP UINT32_MAX // *10ns(Timer_L) #define L1_FRAME_NONE_COMP UINT32_MAX // *10ns(Timer_L)
#define L1_FRAME_NONE_HOPS UINT32_MAX #define L1_FRAME_NONE_HOPS UINT32_MAX
#define L1_FRAME_MAX_HOPS 81 #define L1_FRAME_MAX_HOPS 81U
#define L1_FRAME_2KBPS_20MS_HOPS 1 #define L1_FRAME_2KBPS_20MS_HOPS 1U
#define L1_FRAME_2KBPS_100MS_HOPS 81 #define L1_FRAME_2KBPS_100MS_HOPS 81U
#define L1_FRAME_10KBPS_10MS_HOPS 1 #define L1_FRAME_10KBPS_10MS_HOPS 1U
#define L1_FRAME_10KBPS_20MS_HOPS 11 #define L1_FRAME_10KBPS_20MS_HOPS 11U
#define L1_FRAME_40KBPS_20MS_HOPS 19 #define L1_FRAME_40KBPS_20MS_HOPS 19U
#define L1_FRAME_40KBPS_10MS_HOPS 9 #define L1_FRAME_40KBPS_10MS_HOPS 9U
#define L1_FRAME_200KBPS_5MS_HOPS 20 #define L1_FRAME_200KBPS_5MS_HOPS 20U
#define L1_FRAME_1M2BPS_5MS_HOPS 20 #define L1_FRAME_1M2BPS_5MS_HOPS 20U
#define PHY_LOG_EXPIRE 40 // 50*5ms #define PHY_LOG_EXPIRE 40U // 50*5ms
/** @} */ /** @} */
/***************** Macros (Inline Functions) Definitions *********************/ /***************** Macros (Inline Functions) Definitions *********************/
/**************************** Type Definitions *******************************/ /**************************** Type Definitions *******************************/
@@ -306,7 +306,7 @@ void Phy_AntConfigInit(PHY_ANT_CONFIG *antConfig);
void Phy_AntConfigMode(PHY_INST *instPtr, PHY_ANT_MODE mode); void Phy_AntConfigMode(PHY_INST *instPtr, PHY_ANT_MODE mode);
void Phy_SetBeamTable(PHY_INST *instPtr, PHY_ANT_ANGLE *table, uint32_t offset); void Phy_SetBeamTable(PHY_INST *instPtr, PHY_ANT_ANGLE *table, uint32_t offset);
int32_t Phy_SetBeamWidth(PHY_INST *instPtr, PHY_ANT_BEAM_WIDTH beamWidth); int32_t Phy_SetBeamWidth(PHY_INST *instPtr, PHY_ANT_BEAM_WIDTH beamWidth);
int32_t Phy_SetBeamNo(PHY_INST *instPtr, int32_t beamNo, PHY_ANT_BEAM_WIDTH beamWidth); int32_t Phy_SetBeamNo(PHY_INST *instPtr, size_t beamNo, PHY_ANT_BEAM_WIDTH beamWidth);
int32_t Phy_SetBeamAngle(PHY_INST *phyInstPtr, double offAx, double rndAx); int32_t Phy_SetBeamAngle(PHY_INST *phyInstPtr, double offAx, double rndAx);
/** @} PhysicalLayer_AntennaControl*/ /** @} PhysicalLayer_AntennaControl*/
@@ -26,8 +26,8 @@
#include "util.h" #include "util.h"
/***************** Macros (Inline Functions) Definitions *********************/ /***************** Macros (Inline Functions) Definitions *********************/
#define PhyRead(instPtr, addr) IO_In32((instPtr)->phyCofig.baseAddr + addr) #define PhyRead(instPtr, addr) IO_In32((instPtr)->phyCofig.baseAddr + (addr))
#define PhyWrite(instPtr, addr, value) IO_Out32((instPtr)->phyCofig.baseAddr + addr, value) #define PhyWrite(instPtr, addr, value) IO_Out32((instPtr)->phyCofig.baseAddr + (addr), (value))
/************************** Constant Definitions *****************************/ /************************** Constant Definitions *****************************/
/** /**
+6
View File
@@ -127,6 +127,7 @@ void SysMonitor_Destroy(void)
*/ */
void SysMonitor_UpdateSysinfo(const SYSINFO *info) void SysMonitor_UpdateSysinfo(const SYSINFO *info)
{ {
ASSERT(info != NULL);
uint8_t buffIndx; uint8_t buffIndx;
buffIndx = GetWritable(sysMonitorInst->sysInfoCtrl); buffIndx = GetWritable(sysMonitorInst->sysInfoCtrl);
sysMonitorInst->sysInfoCtrl.wBusy = buffIndx; sysMonitorInst->sysInfoCtrl.wBusy = buffIndx;
@@ -143,6 +144,7 @@ void SysMonitor_UpdateSysinfo(const SYSINFO *info)
void SysMonitor_GetSysinfo(SYSINFO *info) void SysMonitor_GetSysinfo(SYSINFO *info)
{ {
ASSERT(sysMonitorInst != NULL); ASSERT(sysMonitorInst != NULL);
ASSERT(info != NULL);
uint8_t buffIndx, buffIndex_old; uint8_t buffIndx, buffIndex_old;
buffIndex_old = sysMonitorInst->sysInfoCtrl.rBusy; buffIndex_old = sysMonitorInst->sysInfoCtrl.rBusy;
if (buffIndex_old != BUFF_NONE) if (buffIndex_old != BUFF_NONE)
@@ -201,9 +203,13 @@ void SysMonitor_GetSendPayload(uint8_t *buff, uint32_t *id, size_t len)
uint8_t buffIndx, buffIndex_old; uint8_t buffIndx, buffIndex_old;
buffIndex_old = sysMonitorInst->sendCtrl.rBusy; buffIndex_old = sysMonitorInst->sendCtrl.rBusy;
if (buffIndex_old != BUFF_NONE) if (buffIndex_old != BUFF_NONE)
{
buffIndx = buffIndex_old; // Keep it busy buffIndx = buffIndex_old; // Keep it busy
}
else else
{
buffIndx = GetReadable(sysMonitorInst->sendCtrl); buffIndx = GetReadable(sysMonitorInst->sendCtrl);
}
sysMonitorInst->sendCtrl.rBusy = buffIndx; sysMonitorInst->sendCtrl.rBusy = buffIndx;
if (sysMonitorInst->send[buffIndx].dataId != DATA_ID_NONE) if (sysMonitorInst->send[buffIndx].dataId != DATA_ID_NONE)
{ {
+10 -10
View File
@@ -54,12 +54,12 @@
// #define IS_PL_VALID(x) (x <= 1.03 && x >= 0.97) // #define IS_PL_VALID(x) (x <= 1.03 && x >= 0.97)
// #define IS_PLAUX_VALID(x) (x <= 1.89 && x >= 1.71) // #define IS_PLAUX_VALID(x) (x <= 1.89 && x >= 1.71)
// #define IS_BRAM_VALID(x) (x <= 1.03 && x >= 0.97) // #define IS_BRAM_VALID(x) (x <= 1.03 && x >= 0.97)
#define IS_PS_VALID(x) (x <= 1.1 && x >= 0.9) #define IS_PS_VALID(x) ((x) <= 1.1 && (x) >= 0.9)
#define IS_PSAUX_VALID(x) (x <= 2.0 && x >= 1.6) #define IS_PSAUX_VALID(x) ((x) <= 2.0 && (x) >= 1.6)
#define IS_DDR_VALID(x) (x <= 1.7 && x >= 1.3) #define IS_DDR_VALID(x) ((x) <= 1.7 && (x) >= 1.3)
#define IS_PL_VALID(x) (x <= 1.1 && x >= 0.9) #define IS_PL_VALID(x) (x <= 1.1 && (x) >= 0.9)
#define IS_PLAUX_VALID(x) (x <= 2.0 && x >= 1.6) #define IS_PLAUX_VALID(x) ((x) <= 2.0 && (x) >= 1.6)
#define IS_BRAM_VALID(x) (x <= 1.1 && x >= 0.9) #define IS_BRAM_VALID(x) ((x) <= 1.1 && (x) >= 0.9)
#define CLK_SP_PLL0_LOCK BIT(0) #define CLK_SP_PLL0_LOCK BIT(0)
#define CLK_SP_PLL1_LOCK BIT(2) #define CLK_SP_PLL1_LOCK BIT(2)
@@ -194,12 +194,12 @@ typedef struct __attribute__((packed))
uint8_t spFpgaVolt; ///< Signal processor voltage state indicator uint8_t spFpgaVolt; ///< Signal processor voltage state indicator
uint8_t spClkState; ///< Signal processor clock state indicator uint8_t spClkState; ///< Signal processor clock state indicator
uint8_t spAdLockState; ///< Signal processor adc lock state indicator uint8_t spAdLockState; ///< Signal processor adc lock state indicator
uint8_t spAdTemp_0; ///< Signal processor adc0 temperature int8_t spAdTemp_0; ///< Signal processor adc0 temperature
uint8_t spAdTemp_1; ///< Signal processor adc1 temperature int8_t spAdTemp_1; ///< Signal processor adc1 temperature
uint8_t spFpgaTemp; ///< Signal processor FPGA temperature int8_t spFpgaTemp; ///< Signal processor FPGA temperature
// -- Antenna status // -- Antenna status
uint8_t antVolt; ///< Antenna voltage state indicator uint8_t antVolt; ///< Antenna voltage state indicator
uint8_t antTemp; ///< Antenna rf temperature int8_t antTemp; ///< Antenna rf temperature
uint8_t antPll; ///< Antenna rf lock state indicator uint8_t antPll; ///< Antenna rf lock state indicator
uint8_t antMgc0; ///< Antenna rf mgc0~1 indicator uint8_t antMgc0; ///< Antenna rf mgc0~1 indicator
uint8_t antMgc1; ///< Antenna rf mgc2~3 indicator uint8_t antMgc1; ///< Antenna rf mgc2~3 indicator
+34 -20
View File
@@ -658,7 +658,7 @@ int32_t SystemBus_MakeResp(SYSBUS *instPtr)
* @param InstPtr A double pointer to System Bus instance. * @param InstPtr A double pointer to System Bus instance.
* @param config A pointer to System Bus configurations. * @param config A pointer to System Bus configurations.
* *
* @return None. * @return Error code.
* *
******************************************************************************/ ******************************************************************************/
int32_t SystemBus_Init(SYSBUS **instPtr, SYSBUS_CONFIG *config) int32_t SystemBus_Init(SYSBUS **instPtr, SYSBUS_CONFIG *config)
@@ -670,7 +670,7 @@ int32_t SystemBus_Init(SYSBUS **instPtr, SYSBUS_CONFIG *config)
(*instPtr) = malloc(sizeof(SYSBUS)); (*instPtr) = malloc(sizeof(SYSBUS));
if ((*instPtr) == NULL) if ((*instPtr) == NULL)
{ {
return FAILURE; return ENOMEM;
} }
(*instPtr)->rxQueue = NULL; (*instPtr)->rxQueue = NULL;
(*instPtr)->txQueue = NULL; (*instPtr)->txQueue = NULL;
@@ -684,29 +684,45 @@ int32_t SystemBus_Init(SYSBUS **instPtr, SYSBUS_CONFIG *config)
Status = SysbusUart_Init(&((*instPtr)->uartInst), &uartConfig); Status = SysbusUart_Init(&((*instPtr)->uartInst), &uartConfig);
if (Status != SUCCESS) if (Status != SUCCESS)
{ {
Status = ENOMEM; SystemBus_Destroy(*instPtr);
goto sysbus_init_error; return ENOMEM;
} }
if (CircQueueCreate(&((*instPtr)->txQueue), (*instPtr)->config.txQueueMax) == false) if (CircQueueCreate(&((*instPtr)->txQueue), (*instPtr)->config.txQueueMax) == false)
{ {
Status = ENOMEM; SystemBus_Destroy(*instPtr);
goto sysbus_init_error; return ENOMEM;
} }
if (CircQueueCreate(&((*instPtr)->rxQueue), (*instPtr)->config.rxQueueMax) == false) if (CircQueueCreate(&((*instPtr)->rxQueue), (*instPtr)->config.rxQueueMax) == false)
{ {
Status = ENOMEM; SystemBus_Destroy(*instPtr);
goto sysbus_init_error; return ENOMEM;
} }
(*instPtr)->isRxDone = false; // nothing received. (*instPtr)->isRxDone = false; // nothing received.
(*instPtr)->isTxDone = true; // nothing to be sent. (*instPtr)->isTxDone = true; // nothing to be sent.
return SUCCESS; return SUCCESS;
}
sysbus_init_error:
free((*instPtr)->uartInst); /*****************************************************************************/
free((*instPtr)->txQueue); /**
free((*instPtr)->rxQueue); * @brief Destroy System Bus instance.
free(*instPtr); *
return Status; * @param InstPtr A pointer to System Bus instance.
*
* @return None.
*
******************************************************************************/
void SystemBus_Destroy(SYSBUS *instPtr)
{
if (instPtr == NULL)
{
return;
}
free(instPtr->uartInst);
free(instPtr->txQueue);
free(instPtr->rxQueue);
free(instPtr);
} }
/*****************************************************************************/ /*****************************************************************************/
@@ -748,19 +764,17 @@ int32_t SystemBus_RxIntrHandler(SYSBUS *instPtr)
Status = SysbusUart_Recv(instPtr->uartInst, sysbusReq); Status = SysbusUart_Recv(instPtr->uartInst, sysbusReq);
if (Status != SUCCESS) if (Status != SUCCESS)
{ {
goto recv_error; free(sysbusReq);
return Status;
} }
if (CircQueuePush(instPtr->rxQueue, (void *)sysbusReq) == false) if (CircQueuePush(instPtr->rxQueue, (void *)sysbusReq) == false)
{ {
DBG_ERROR("SystemBus::RX Queue overflowed!\n"); DBG_ERROR("SystemBus::RX Queue overflowed!\n");
Status = EQUEUE; free(sysbusReq);
goto recv_error; return EQUEUE;
} }
instPtr->isRxDone = false; // another reception is undergoing. instPtr->isRxDone = false; // another reception is undergoing.
return SUCCESS; return SUCCESS;
recv_error:
free(sysbusReq);
return Status;
} }
/** @} SystemBus*/ /** @} SystemBus*/
+1
View File
@@ -60,6 +60,7 @@ typedef struct
/************************** Function Prototypes ******************************/ /************************** Function Prototypes ******************************/
int32_t SystemBus_Init(SYSBUS **instPtr, SYSBUS_CONFIG *config); int32_t SystemBus_Init(SYSBUS **instPtr, SYSBUS_CONFIG *config);
void SystemBus_Destroy(SYSBUS *instPtr);
/** /**
* @defgroup SystemBus_Protocol_Routine * @defgroup SystemBus_Protocol_Routine
+3 -5
View File
@@ -54,7 +54,7 @@ bool CircQueueCreate(CIRC_QUEUE **q, uint32_t queueCapacity)
ASSERT(q != NULL); ASSERT(q != NULL);
CIRC_QUEUE *queue; CIRC_QUEUE *queue;
queue = malloc(sizeof(CIRC_QUEUE)); queue = malloc(sizeof(CIRC_QUEUE));
if (!queue) if (queue == NULL)
{ {
return false; return false;
} }
@@ -65,16 +65,14 @@ bool CircQueueCreate(CIRC_QUEUE **q, uint32_t queueCapacity)
queue->data = malloc(queueCapacity * sizeof(void *)); queue->data = malloc(queueCapacity * sizeof(void *));
if (queue->data == NULL) if (queue->data == NULL)
{ {
goto error; free(queue);
return false;
} }
queue->bounds = queueCapacity; queue->bounds = queueCapacity;
queue->nelts = 0; queue->nelts = 0;
queue->in = 0; queue->in = 0;
queue->out = 0; queue->out = 0;
return true; return true;
error:
free(queue);
return false;
} }
/** /**
+6 -2
View File
@@ -4,9 +4,13 @@
GE_TXATT=0 GE_TXATT=0
GE_RXATT=25 GE_RXATT=25
DST_DIR=`pwd` DST_DIR="$(pwd)/handout"
PROJECT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) PROJECT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
echo ${DST_DIR}
mkdir -p ${DST_DIR}
echo "Creating <df_datalink_ge>..." echo "Creating <df_datalink_ge>..."
cp -rL $PROJECT_DIR/df_datalink_ge/src $DST_DIR/df_datalink_ge cp -rL $PROJECT_DIR/df_datalink_ge/src $DST_DIR/df_datalink_ge
sed -i'' -e "s/antConfig->rfTxMgc = 0;/antConfig->rfTxMgc = $GE_TXATT;/g" $DST_DIR/df_datalink_ge/networking/phy_layer/phy_antenna.c sed -i'' -e "s/antConfig->rfTxMgc = 0;/antConfig->rfTxMgc = $GE_TXATT;/g" $DST_DIR/df_datalink_ge/networking/phy_layer/phy_antenna.c
@@ -38,4 +42,4 @@ for key in ${!calMap[*]};do
/\};/!b table /\};/!b table
s/=.*\};/=\n\/\/Antenna-$key\n${calMap[$key]}/ s/=.*\};/=\n\/\/Antenna-$key\n${calMap[$key]}/
}" $DST_DIR/$projName/networking/phy_layer/phy_antenna.c }" $DST_DIR/$projName/networking/phy_layer/phy_antenna.c
done done