From b884754d938de60f0946836b5f41fa3b527d9579 Mon Sep 17 00:00:00 2001 From: Oleg Date: Thu, 6 Mar 2025 09:33:12 +0300 Subject: [PATCH] Add mbox interrupt handling --- Protocol/CAN.h | 2 +- Protocol/CANConfig.cpp | 13 +++++++++++++ main.cpp | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/Protocol/CAN.h b/Protocol/CAN.h index d6fc14a..dfd1c2f 100644 --- a/Protocol/CAN.h +++ b/Protocol/CAN.h @@ -106,7 +106,7 @@ public: void configTxMBox(Uint16 boxNumber, const MsgID& configID, const MsgCtrlReg& configCtrlReg); void configRxMBox(Uint16 boxNumber, const MsgID& configID, const MsgCtrlReg& configCtrlReg); void configSystemIsr(Uint32 flags); - void configMBoxIsr(Uint16 boxNumber); // TODO not realized yet + void configMBoxIsr(Uint16 boxNumber); bool isNewMessage(); bool isNewMessage(Uint16 boxNumber); diff --git a/Protocol/CANConfig.cpp b/Protocol/CANConfig.cpp index 7817555..a83daec 100644 --- a/Protocol/CANConfig.cpp +++ b/Protocol/CANConfig.cpp @@ -269,4 +269,17 @@ void CAN::configSystemIsr(Uint32 flags){ EDIS; } + +void CAN::configMBoxIsr(Uint16 boxNumber){ + if (boxNumber > 31) return; + + Uint32 mboxControl(0); + mboxControl = 1ul << boxNumber; + + EALLOW; + p_CanRegs_->CANMIL.all |= mboxControl; + p_CanRegs_->CANMIM.all |= mboxControl; + EDIS; +} + } //canSpace diff --git a/main.cpp b/main.cpp index b1eb785..424531c 100644 --- a/main.cpp +++ b/main.cpp @@ -13,7 +13,10 @@ void idle_loop(void); interrupt void cpu_timer0_isr(void); interrupt void canb_isr(void); +interrupt void canb_box_isr(void); + volatile Uint16 canISRcounter = 0; +volatile Uint16 canBoxISRcounter = 0; canSpace::CAN canTest(canSpace::CANB); Uint16 msgsSent = 0; @@ -45,6 +48,7 @@ void main() EALLOW; PieVectTable.TINT0 = &cpu_timer0_isr; PieVectTable.ECAN0INTB = &canb_isr; + PieVectTable.ECAN1INTB = &canb_box_isr; EDIS; // memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (Uint32)&RamfuncsLoadSize); @@ -57,6 +61,7 @@ void main() PieCtrlRegs.PIEIER1.bit.INTx7 = 1; PieCtrlRegs.PIEIER9.bit.INTx7 = 1; // from 5 to 8 + PieCtrlRegs.PIEIER9.bit.INTx8 = 1; canTest.initGpio(); canTest.config(100); @@ -168,3 +173,35 @@ interrupt void canb_isr(void){ PieCtrlRegs.PIEACK.all |= PIEACK_GROUP9; } + +interrupt void canb_box_isr(void){ + canBoxISRcounter++; + + // Just example + // + // boxNumberIsr = ECanbRegs.CANGIF1.bit.MIV1; + + // CANRMP_REG temp; + // temp.all = 0; + // temp.all = 1ul << 27; + // temp.all |= 1ul << 26; + + // ECanbRegs.CANRMP.all = temp.all; + + // MODBUS_COMM_CPU_Message27.mdh.all = ECanbMboxes.MBOX27.MDH.all; + // MODBUS_COMM_CPU_Message27.mdl.all = ECanbMboxes.MBOX27.MDL.all; + + // MODBUS_COMM_CPU_Message26.mdh.all = ECanbMboxes.MBOX26.MDH.all; + // MODBUS_COMM_CPU_Message26.mdl.all = ECanbMboxes.MBOX26.MDL.all; + + // temp.all = ECanbRegs.CANRMP.all; + // if (temp.bit.RMP25){ + // temp.all = 1ul << 25; + // ECanbRegs.CANRMP.all = temp.all; + + // MODBUS_COMM_CPU_Message25.mdh.all = ECanbMboxes.MBOX25.MDH.all; + // MODBUS_COMM_CPU_Message25.mdl.all = ECanbMboxes.MBOX25.MDL.all; + // } + + PieCtrlRegs.PIEACK.all |= PIEACK_GROUP9; +} \ No newline at end of file