From eba0147d2f262c7aee9122c4831c273710b830a1 Mon Sep 17 00:00:00 2001 From: Gatsby Van Date: Sun, 24 Dec 2023 13:04:46 +0800 Subject: [PATCH] add physical interrupt handler, handle physical layer interrupt and 5ms interrupt independently. --- datalink814_ge/src/main.c | 75 ++++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 33 deletions(-) diff --git a/datalink814_ge/src/main.c b/datalink814_ge/src/main.c index 18342e2..ecdf913 100644 --- a/datalink814_ge/src/main.c +++ b/datalink814_ge/src/main.c @@ -69,6 +69,7 @@ MPC_CONFIG mpcConfig = { static bool mpcStatusUpAssert = false; /************************** Function Prototypes ******************************/ 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); @@ -134,29 +135,41 @@ int SetupInterruptSystem(XScuGic* instPtr, uint32_t devId){ * rising edge 0x03. */ + // Initialize physical layer interrupt. + XScuGic_SetPriorityTriggerType(instPtr, PHY_INTR_ID, 0x00, 0x03); + + // 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) { + return Status; + } + // Initialize physical layer interrupt. XScuGic_SetPriorityTriggerType(instPtr, PERIODIC_5MS_INTR_ID, 0x00, 0x03); // Connect the interrupt service routine isr1 to the interrupt controller Status = XScuGic_Connect(instPtr, PERIODIC_5MS_INTR_ID, - (Xil_ExceptionHandler) PeriodicPull_Handler, (void *) instPtr); + (Xil_ExceptionHandler) PeriodicPull_Handler, (void *) linkInstPtr); if (Status != SUCCESS) { return Status; } - XScuGic_Enable(instPtr, PERIODIC_5MS_INTR_ID); #ifdef _MPC_CTRL // Initialize MPC interrupt. 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 *) instPtr); + (Xil_ExceptionHandler) MPC_IntrHandler, (void *) mpcInstPtr); if (Status != XST_SUCCESS) { return Status; } XScuGic_Enable(instPtr, MPC_RX_DONE_INTR_ID); #endif + XScuGic_Enable(instPtr, PHY_INTR_ID); + XScuGic_Enable(instPtr, PERIODIC_5MS_INTR_ID); + /* Initialize the exception table and register the interrupt controller * handler with the exception table */ @@ -185,7 +198,7 @@ void MPC_PCIESentStart(){ /** * @brief Handler of mater pc contrl interrupt. * - * @param CallBackRef A pointer to corresponding frame UART instance. + * @param CallBackRef A pointer to corresponding mpcInstPtr instance. * * @return None. * @@ -195,22 +208,21 @@ void MPC_IntrHandler(void* CallBackRef) { } #endif -/****************************************************************************/ +/*****************************************************************************/ /** - * This function is a interrupt service routine for IRQ_F2P[1:1], IRQ_F2P[1:1] - * tells CPU that the data in OCM is ready! + * @brief Handler of physical layer interrupt. * - * @param callBackRef is the SCUGIC instance pointer. + * @param CallBackRef A pointer to corresponding physical layer instance. * - * @return None. + * @return None. * - * @note None. - * - *****************************************************************************/ -void PeriodicPull_Handler(void *callBackRef) { - int32_t Status; - Phy_UpdateState(phyInstPtr); + ******************************************************************************/ +void PhysicalIntr_Handler(void *callBackRef) { uint32_t GpioConfig = XGpio_DiscreteRead(&configGpio, 2); + if(L2_isDataAvail(linkInstPtr) == true ){ + GpioConfig^=0x00000001; + } + Phy_UpdateState(phyInstPtr); if(phyInstPtr->TOR.curr == PHY_TOR_TX){ switch(phyInstPtr->frameType.curr){ case L1_1M2BPS_5MS_FRAME: @@ -271,17 +283,27 @@ void PeriodicPull_Handler(void *callBackRef) { break; } } + XGpio_DiscreteWrite(&configGpio, 2, GpioConfig); +} +/****************************************************************************/ +/** + * Handler of periodic 5ms interrupt + * + * @param callBackRef is the linklayer instance pointer. + * + * @return None. + * + *****************************************************************************/ +void PeriodicPull_Handler(void *callBackRef) { + int32_t Status; + Status = Linklayer_Proc(linkInstPtr); if(Status != SUCCESS){ DBG_ERROR("Link layer runs failed, with error code: %ld\n", Status); _nop_(); } - if(L2_isDataAvail(linkInstPtr) == true ){ - GpioConfig^=0x00000001; - } - if (linkInstPtr->slotNum.next % DATA_STORE_INTERVAL == 1) { mpcStatusUpAssert = true; mpcRecord->frame1Cnt = mpcRecord->frame1Recv - mpcRecord->frame1CntLast; @@ -303,11 +325,6 @@ void PeriodicPull_Handler(void *callBackRef) { mpcRecord->frame7CntLast = mpcRecord->frame7Recv; mpcRecord->frame8CntLast = mpcRecord->frame8Recv; } - - // TODO: Dijian frequency pattern TX_RX State. - GpioConfig ^= 0x80000000; - GpioConfig = (phyInstPtr->TOR.next == PHY_TOR_TX) ? GpioConfig|0x40000000 : GpioConfig&0xBFFFFFFF; - XGpio_DiscreteWrite(&configGpio, 2, GpioConfig); } // PhyIntr_Handler /*****************************************************************************/ @@ -392,18 +409,10 @@ int main(void) { return Status; } - Status = Phy_SetMode(phyInstPtr, PHY_MODE_SCHEDULE); - if (Status == SUCCESS) { - DBG_PRINT("Physical Mode %u Setup SUCCESS! \n", PHY_MODE_LISTEN); - } - else { - DBG_PRINT("Physical Mode %u Setup FAILED! \n", PHY_MODE_LISTEN); - return Status; - } - DBG_PRINT("Starting Physical Layer..."); Phy_Start(phyInstPtr); + // FIXME: only for debug, linklayer should be start by MPC Linklayer_Start(linkInstPtr); while(true) {