formatted code.
This commit is contained in:
+111
-81
@@ -20,10 +20,10 @@
|
||||
/***************************** Include Files *********************************/
|
||||
#include <stdint.h>
|
||||
#include "config/app_config.h"
|
||||
#include "xscugic.h" // The generic interrupt controller driver component
|
||||
#include "xil_exception.h" // ARM Cortex A9 specific exception related APIs
|
||||
#include "xscugic.h" // The generic interrupt controller driver component
|
||||
#include "xil_exception.h" // ARM Cortex A9 specific exception related APIs
|
||||
#include "xgpio.h"
|
||||
#include "sleep.h" // Sleep APIs for Cortex A9
|
||||
#include "sleep.h" // Sleep APIs for Cortex A9
|
||||
#include "xil_cache.h"
|
||||
#include "linklayer/linklayer814.h"
|
||||
#include "linklayer/msg_def.h"
|
||||
@@ -47,39 +47,36 @@ L2_CONFIG l2Config = {
|
||||
.bkpHeadId = 1,
|
||||
.netScale = 2,
|
||||
.phyInstPtr = NULL,
|
||||
.tmcInstPtr = NULL
|
||||
};
|
||||
.tmcInstPtr = NULL};
|
||||
|
||||
TIMECTRL_CONFIG tmcConfig = {
|
||||
.baseAddr = TIME_CONTROLLER_BASEADDR,
|
||||
.reset = 10
|
||||
};
|
||||
.reset = 10};
|
||||
|
||||
PHY_CONFIG l1Config = {
|
||||
.devId = PHY_DEVICE_ID,
|
||||
.txBramId = TXBUFF_BRAM_ID,
|
||||
.rxBramId = RXBUFF_BRAM_ID,
|
||||
.antBramId = ANTCONFIG_BRAM_ID,
|
||||
.baseAddr = PHY_CTRL_BASEADDR
|
||||
};
|
||||
.baseAddr = PHY_CTRL_BASEADDR};
|
||||
MPC_CONFIG mpcConfig = {
|
||||
.bramDevId = MPC_PCIE_BRAM_ID,
|
||||
.msgLenMax = MPC_BUFFER_LENGTH //byte
|
||||
.msgLenMax = MPC_BUFFER_LENGTH // byte
|
||||
};
|
||||
static bool mpcStatusUpAssert = false;
|
||||
/************************** Function Prototypes ******************************/
|
||||
int SetupInterruptSystem(XScuGic* instPtr, uint32_t devId);
|
||||
int SetupInterruptSystem(XScuGic *instPtr, uint32_t devId);
|
||||
void PhysicalIntr_Handler(void *callBackRef);
|
||||
void PeriodicPull_Handler(void *callBackRef);
|
||||
#ifdef _MPC_CTRL
|
||||
void MPC_IntrHandler(void* CallBackRef);
|
||||
void MPC_IntrHandler(void *CallBackRef);
|
||||
#endif
|
||||
|
||||
/*********************** Driver Instance Definitions **************************/
|
||||
TIMECTRL_INST* tmcInstPtr = NULL;
|
||||
PHY_INST* phyInstPtr = NULL;
|
||||
L2_INST* linkInstPtr = NULL;
|
||||
static XScuGic gicInst; //General interrupt controller intance
|
||||
TIMECTRL_INST *tmcInstPtr = NULL;
|
||||
PHY_INST *phyInstPtr = NULL;
|
||||
L2_INST *linkInstPtr = NULL;
|
||||
static XScuGic gicInst; // General interrupt controller intance
|
||||
// FIXME: Only for test...
|
||||
XGpio configGpio; /* The Instance of the GPIO Driver */
|
||||
/****************************************************************************/
|
||||
@@ -96,21 +93,24 @@ XGpio configGpio; /* The Instance of the GPIO Driver */
|
||||
* FAILURE if initialization failed.
|
||||
*
|
||||
*****************************************************************************/
|
||||
int SetupInterruptSystem(XScuGic* instPtr, uint32_t devId){
|
||||
int SetupInterruptSystem(XScuGic *instPtr, uint32_t devId)
|
||||
{
|
||||
XScuGic_Config *configPtr;
|
||||
int Status;
|
||||
uint32_t intrState;
|
||||
// Initialize the GIC instance.
|
||||
configPtr = XScuGic_LookupConfig(devId);
|
||||
Status = XScuGic_CfgInitialize(instPtr, configPtr,
|
||||
configPtr->CpuBaseAddress);
|
||||
if (Status != SUCCESS) {
|
||||
configPtr->CpuBaseAddress);
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
return Status;
|
||||
}
|
||||
|
||||
// Perform a self-test to ensure that the hardware was built correctly.
|
||||
Status = XScuGic_SelfTest(instPtr);
|
||||
if (Status != SUCCESS) {
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
return Status;
|
||||
}
|
||||
// Clear any pending interrupt flags
|
||||
@@ -140,8 +140,9 @@ int SetupInterruptSystem(XScuGic* instPtr, uint32_t devId){
|
||||
|
||||
// Connect the interrupt service routine isr1 to the interrupt controller
|
||||
Status = XScuGic_Connect(instPtr, PHY_INTR_ID,
|
||||
(Xil_ExceptionHandler) PhysicalIntr_Handler, (void *) phyInstPtr);
|
||||
if (Status != SUCCESS) {
|
||||
(Xil_ExceptionHandler)PhysicalIntr_Handler, (void *)phyInstPtr);
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
return Status;
|
||||
}
|
||||
|
||||
@@ -150,8 +151,9 @@ int SetupInterruptSystem(XScuGic* instPtr, uint32_t devId){
|
||||
|
||||
// Connect the interrupt service routine isr1 to the interrupt controller
|
||||
Status = XScuGic_Connect(instPtr, PERIODIC_5MS_INTR_ID,
|
||||
(Xil_ExceptionHandler) PeriodicPull_Handler, (void *) linkInstPtr);
|
||||
if (Status != SUCCESS) {
|
||||
(Xil_ExceptionHandler)PeriodicPull_Handler, (void *)linkInstPtr);
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
return Status;
|
||||
}
|
||||
|
||||
@@ -160,8 +162,9 @@ int SetupInterruptSystem(XScuGic* instPtr, uint32_t devId){
|
||||
XScuGic_SetPriorityTriggerType(instPtr, MPC_RX_DONE_INTR_ID, 0x00, 0x03);
|
||||
// Connect the interrupt service routine isr1 to the interrupt controller
|
||||
Status = XScuGic_Connect(instPtr, MPC_RX_DONE_INTR_ID,
|
||||
(Xil_ExceptionHandler) MPC_IntrHandler, (void *) mpcInstPtr);
|
||||
if (Status != XST_SUCCESS) {
|
||||
(Xil_ExceptionHandler)MPC_IntrHandler, (void *)mpcInstPtr);
|
||||
if (Status != XST_SUCCESS)
|
||||
{
|
||||
return Status;
|
||||
}
|
||||
XScuGic_Enable(instPtr, MPC_RX_DONE_INTR_ID);
|
||||
@@ -176,8 +179,8 @@ int SetupInterruptSystem(XScuGic* instPtr, uint32_t devId){
|
||||
Xil_ExceptionInit();
|
||||
|
||||
Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,
|
||||
(Xil_ExceptionHandler) XScuGic_InterruptHandler,
|
||||
(void *) instPtr);
|
||||
(Xil_ExceptionHandler)XScuGic_InterruptHandler,
|
||||
(void *)instPtr);
|
||||
|
||||
// Enable non-critical exceptions
|
||||
Xil_ExceptionEnable();
|
||||
@@ -185,10 +188,9 @@ int SetupInterruptSystem(XScuGic* instPtr, uint32_t devId){
|
||||
return Status;
|
||||
} // SetupInterruptSystem
|
||||
|
||||
|
||||
|
||||
#ifdef _MPC_CTRL
|
||||
void MPC_PCIESentStart(){
|
||||
void MPC_PCIESentStart()
|
||||
{
|
||||
uint32_t GpioConfig = XGpio_DiscreteRead(&configGpio, 2);
|
||||
GpioConfig ^= 0x00000002;
|
||||
XGpio_DiscreteWrite(&configGpio, 2, GpioConfig);
|
||||
@@ -203,7 +205,8 @@ void MPC_PCIESentStart(){
|
||||
* @return None.
|
||||
*
|
||||
******************************************************************************/
|
||||
void MPC_IntrHandler(void* CallBackRef) {
|
||||
void MPC_IntrHandler(void *CallBackRef)
|
||||
{
|
||||
MPC_MsgHandler(mpcInstPtr);
|
||||
}
|
||||
#endif
|
||||
@@ -217,67 +220,73 @@ void MPC_IntrHandler(void* CallBackRef) {
|
||||
* @return None.
|
||||
*
|
||||
******************************************************************************/
|
||||
void PhysicalIntr_Handler(void *callBackRef) {
|
||||
void PhysicalIntr_Handler(void *callBackRef)
|
||||
{
|
||||
uint32_t GpioConfig = XGpio_DiscreteRead(&configGpio, 2);
|
||||
if(L2_isDataAvail(linkInstPtr) == true ){
|
||||
GpioConfig^=0x00000001;
|
||||
if (L2_isDataAvail(linkInstPtr) == true)
|
||||
{
|
||||
GpioConfig ^= 0x00000001;
|
||||
}
|
||||
Phy_UpdateState(phyInstPtr);
|
||||
if(phyInstPtr->TOR.curr == PHY_TOR_TX){
|
||||
switch(phyInstPtr->frameType.curr){
|
||||
if (phyInstPtr->TOR.curr == PHY_TOR_TX)
|
||||
{
|
||||
switch (phyInstPtr->frameType.curr)
|
||||
{
|
||||
case L1_1M2BPS_5MS_FRAME:
|
||||
mpcRecord->frame1Sent ++ ;
|
||||
mpcRecord->frame1Sent++;
|
||||
break;
|
||||
case L1_200KBPS_5MS_FRAME:
|
||||
mpcRecord->frame2Sent ++ ;
|
||||
mpcRecord->frame2Sent++;
|
||||
break;
|
||||
case L1_40KBPS_10MS_FRAME:
|
||||
mpcRecord->frame3Sent ++ ;
|
||||
mpcRecord->frame3Sent++;
|
||||
break;
|
||||
case L1_40KBPS_20MS_FRAME:
|
||||
mpcRecord->frame4Sent ++ ;
|
||||
mpcRecord->frame4Sent++;
|
||||
break;
|
||||
case L1_10KBPS_20MS_FRAME:
|
||||
mpcRecord->frame5Sent ++ ;
|
||||
mpcRecord->frame5Sent++;
|
||||
break;
|
||||
case L1_2KBPS_100MS_FRAME:
|
||||
mpcRecord->frame6Sent ++ ;
|
||||
mpcRecord->frame6Sent++;
|
||||
break;
|
||||
case L1_10KBPS_10MS_FRAME:
|
||||
mpcRecord->frame7Sent ++ ;
|
||||
mpcRecord->frame7Sent++;
|
||||
break;
|
||||
case L1_2KBPS_20MS_FRAME:
|
||||
mpcRecord->frame8Sent ++ ;
|
||||
mpcRecord->frame8Sent++;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(phyInstPtr->TOR.last == PHY_TOR_RX && phyInstPtr->isFrameSync){
|
||||
switch(phyInstPtr->frameType.last){
|
||||
if (phyInstPtr->TOR.last == PHY_TOR_RX && phyInstPtr->isFrameSync)
|
||||
{
|
||||
switch (phyInstPtr->frameType.last)
|
||||
{
|
||||
case L1_1M2BPS_5MS_FRAME:
|
||||
mpcRecord->frame1Recv ++ ;
|
||||
mpcRecord->frame1Recv++;
|
||||
break;
|
||||
case L1_200KBPS_5MS_FRAME:
|
||||
mpcRecord->frame2Recv ++ ;
|
||||
mpcRecord->frame2Recv++;
|
||||
break;
|
||||
case L1_40KBPS_10MS_FRAME:
|
||||
mpcRecord->frame3Recv ++ ;
|
||||
mpcRecord->frame3Recv++;
|
||||
break;
|
||||
case L1_40KBPS_20MS_FRAME:
|
||||
mpcRecord->frame4Recv ++ ;
|
||||
mpcRecord->frame4Recv++;
|
||||
break;
|
||||
case L1_10KBPS_20MS_FRAME:
|
||||
mpcRecord->frame5Recv ++ ;
|
||||
mpcRecord->frame5Recv++;
|
||||
break;
|
||||
case L1_2KBPS_100MS_FRAME:
|
||||
mpcRecord->frame6Recv ++ ;
|
||||
mpcRecord->frame6Recv++;
|
||||
break;
|
||||
case L1_10KBPS_10MS_FRAME:
|
||||
mpcRecord->frame7Recv ++ ;
|
||||
mpcRecord->frame7Recv++;
|
||||
break;
|
||||
case L1_2KBPS_20MS_FRAME:
|
||||
mpcRecord->frame8Recv ++ ;
|
||||
mpcRecord->frame8Recv++;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -295,16 +304,19 @@ void PhysicalIntr_Handler(void *callBackRef) {
|
||||
* @return None.
|
||||
*
|
||||
*****************************************************************************/
|
||||
void PeriodicPull_Handler(void *callBackRef) {
|
||||
void PeriodicPull_Handler(void *callBackRef)
|
||||
{
|
||||
int32_t Status;
|
||||
|
||||
|
||||
Status = Linklayer_Proc(linkInstPtr);
|
||||
if(Status != SUCCESS){
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
DBG_ERROR("Link layer runs failed, with error code: %ld\n", Status);
|
||||
_nop_();
|
||||
}
|
||||
|
||||
if (linkInstPtr->slotNum.next % DATA_STORE_INTERVAL == 1) {
|
||||
if (linkInstPtr->slotNum.next % DATA_STORE_INTERVAL == 1)
|
||||
{
|
||||
mpcStatusUpAssert = true;
|
||||
mpcRecord->frame1Cnt = mpcRecord->frame1Recv - mpcRecord->frame1CntLast;
|
||||
mpcRecord->frame2Cnt = mpcRecord->frame2Recv - mpcRecord->frame2CntLast;
|
||||
@@ -325,7 +337,7 @@ void PeriodicPull_Handler(void *callBackRef) {
|
||||
mpcRecord->frame7CntLast = mpcRecord->frame7Recv;
|
||||
mpcRecord->frame8CntLast = mpcRecord->frame8Recv;
|
||||
}
|
||||
} // PhyIntr_Handler
|
||||
} // PhyIntr_Handler
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
@@ -337,19 +349,23 @@ void PeriodicPull_Handler(void *callBackRef) {
|
||||
* @return
|
||||
*
|
||||
******************************************************************************/
|
||||
int main(void) {
|
||||
int main(void)
|
||||
{
|
||||
int Status;
|
||||
Status = HARDWARE_initialize();
|
||||
if (Status == SUCCESS) {
|
||||
if (Status == SUCCESS)
|
||||
{
|
||||
DBG_PRINT("Hardware Init SUCCESS! \n");
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
DBG_PRINT("Hardware Init FAILED! \n");
|
||||
return Status;
|
||||
}
|
||||
|
||||
Status = XGpio_Initialize(&configGpio, XPAR_CONFIG_GPIO_DEVICE_ID);
|
||||
if (Status != SUCCESS) {
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
DBG_PRINT("Config Gpio Initialization Failed\n");
|
||||
return FAILURE;
|
||||
}
|
||||
@@ -358,20 +374,24 @@ int main(void) {
|
||||
|
||||
// Init time controller
|
||||
Status = TimeCtrl_Init(&tmcInstPtr, &tmcConfig);
|
||||
if (Status == SUCCESS) {
|
||||
if (Status == SUCCESS)
|
||||
{
|
||||
DBG_PRINT("TmcCtrl Init SUCCESS! \n");
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
DBG_PRINT("TmcCtrl Init FAILED! \n");
|
||||
return Status;
|
||||
}
|
||||
|
||||
// Init physical layer
|
||||
Status = Phy_InstInit(&phyInstPtr, &l1Config);
|
||||
if (Status == SUCCESS) {
|
||||
if (Status == SUCCESS)
|
||||
{
|
||||
DBG_PRINT("PhyCtrl Init SUCCESS! \n");
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
DBG_PRINT("PhyCtrl Init FAILED! \n");
|
||||
return Status;
|
||||
}
|
||||
@@ -381,30 +401,36 @@ int main(void) {
|
||||
l2Config.tmcInstPtr = tmcInstPtr;
|
||||
|
||||
Status = Linklayer_Init(&linkInstPtr, &l2Config);
|
||||
if (Status == SUCCESS) {
|
||||
if (Status == SUCCESS)
|
||||
{
|
||||
DBG_PRINT("LinkLayer Init SUCCESS! \n");
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
DBG_PRINT("Linklayer Init FAILED! \n");
|
||||
return Status;
|
||||
}
|
||||
|
||||
// Init MPC
|
||||
Status = MPC_Init(&mpcInstPtr, &mpcConfig);
|
||||
if (Status == SUCCESS) {
|
||||
if (Status == SUCCESS)
|
||||
{
|
||||
DBG_PRINT("MPC Init SUCCESS! \n");
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
DBG_PRINT("MPC Init FAILED! \n");
|
||||
return Status;
|
||||
}
|
||||
|
||||
// Initialize GIC.
|
||||
Status = SetupInterruptSystem(&gicInst ,SCUGIC_DEVICE_ID);
|
||||
if (Status == SUCCESS) {
|
||||
Status = SetupInterruptSystem(&gicInst, SCUGIC_DEVICE_ID);
|
||||
if (Status == SUCCESS)
|
||||
{
|
||||
DBG_PRINT("Intc Init SUCCESS! \n");
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
DBG_PRINT("Intc Init FAILED! \n");
|
||||
return Status;
|
||||
}
|
||||
@@ -415,16 +441,20 @@ int main(void) {
|
||||
// FIXME: only for debug, linklayer should be start by MPC
|
||||
Linklayer_Start(linkInstPtr);
|
||||
|
||||
while(true) {
|
||||
if (mpcStatusUpAssert == true) {
|
||||
while (true)
|
||||
{
|
||||
if (mpcStatusUpAssert == true)
|
||||
{
|
||||
mpcStatusUpAssert = false;
|
||||
if (linkInstPtr->buffSwitch == 0) {
|
||||
if (linkInstPtr->buffSwitch == 0)
|
||||
{
|
||||
MPC_StateUpload(mpcInstPtr, linkInstPtr->mgmtMsgRecvBuff1, linkInstPtr->mgmtMsgRecvCnt1,
|
||||
linkInstPtr->svcMsgRecvBuff1, linkInstPtr->svcMsgRecvCnt1, &(linkInstPtr->mgmtNetFSM->mgmtMsgLog));
|
||||
linkInstPtr->svcMsgRecvBuff1, linkInstPtr->svcMsgRecvCnt1, &(linkInstPtr->mgmtNetFSM->mgmtMsgLog));
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
MPC_StateUpload(mpcInstPtr, linkInstPtr->mgmtMsgRecvBuff0, linkInstPtr->mgmtMsgRecvCnt0,
|
||||
linkInstPtr->svcMsgRecvBuff0, linkInstPtr->svcMsgRecvCnt0, &(linkInstPtr->mgmtNetFSM->mgmtMsgLog));
|
||||
linkInstPtr->svcMsgRecvBuff0, linkInstPtr->svcMsgRecvCnt0, &(linkInstPtr->mgmtNetFSM->mgmtMsgLog));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user