program NCEBridge; // ****************************************************************************** // // * Copyright: // (c) Mustangpeak Software 2014. // // The contents of this file are subject to the GNU GPL v3 licence/ you maynot use // this file except in compliance with the License. You may obtain a copy of the // License at http://www.gnu.org/licenses/gpl.html // // * Revision History: // 2012-02-01: Created // 2012-12-16 updated // // * Description: // // ***************************************************************************** var // EEPROM SPI PINS CS_Bank_0 : sbit at LATB6_bit; CS_Bank_0_Direction : sbit at TRISB6_bit; EE_PROM_Hold : sbit at LATB5_bit; EEPROM_Hold_Direction : sbit at TRISB5_bit; var CabBus_RS485_Select : sbit at LATA0_bit; CabBus_RS485_Select_Direction : sbit at TRISA0_bit; // ***************************************************************************** // INTERRUPTS // ***************************************************************************** procedure INTERRUPT_Timer_525ms(); iv IVT_ADDR_T1INTERRUPT; ics ICS_AUTO; begin T1IF_bit := 0; end; procedure INTERRUPT_Timer_100ms(); iv IVT_ADDR_T2INTERRUPT; ics ICS_AUTO; // Called once every 100m begin T2IF_bit := 0; // Clear the Flag OPStackCore_Timer end; procedure INTERRUPT_Timer_CabBus(); iv IVT_ADDR_T4INTERRUPT; ics ICS_AUTO; begin T4IF_bit := 0; CabBus_Timeout; end; procedure INTERRUPT_CabBus_UART_RX(); iv IVT_ADDR_U2RXINTERRUPT; ics ICS_AUTO; begin U2RXIF_Bit := 0; // Clear the interrupt flag to receive the next byte CabBus_UART_RX_StateMachine; end; procedure INTERRUPT_CabBus_UART_TX(); iv IVT_ADDR_U2TXINTERRUPT; ics ICS_AUTO; begin // Do not clear the flag on purpose, the state machine checks it for a trigger to move on CabBus_UART_TX_Interrupt; end; var ActiveNode: PNMRAnetnode; begin { Main program } MCU_Setup_Initialize; OPStackCore_Initialize; NMRAnetCabBridge_Initialize; MCU_Enable_100msTimer; MCU_Enable_500msTimer; MCU_Enable_CabBusTimer; MCU_Enable_NCE_RS485; MCU_Enable_UART; MCU_Enable_SPI; TON_T1CON_bit := 1; // Turn on 500ms timer TON_T2CON_bit := 1; // Turn on 100ms timer MCU_Enable_CAN; OPStackCore_Enable(True); TRISB4_bit := 0; UART1_Write_Text('NCE Bridge Starting'+LF); while True do begin // LATB4_bit := 1; ActiveNode := OPStackCore_Process; // LATB4_bit := 0; // LATB4_bit := 0; // delay_us(10); if UART1_Data_Ready then begin case UART1_Read of 'B', 'b' : OPStackBuffers_PrintBuffers; 'A', 'a' : begin // OPStackNode_PrintAliases; WordToHex(NodePool.AllocatedList[0]^.iUserStateMachine, s1); UART1_Write_Text('Node usermachine: ' +s1+LF); WordToHex(NodePool.AllocatedList[0]^.iStateMachine, s1); UART1_Write_Text('Node machine: ' +s1+LF); WordToHex(CabBridge.iStateMachine, s1); UART1_Write_Text('Bridge machine: ' +s1+LF+LF); end; end; end end; end.