From: <jim...@us...> - 2013-05-05 03:02:00
|
Revision: 3214 http://sourceforge.net/p/openlcb/svn/3214 Author: jimkueneman626 Date: 2013-05-05 03:01:52 +0000 (Sun, 05 May 2013) Log Message: ----------- - updated all projects to support 63/64 byte user names/descriptions - updated command station node to read/write CVs - updated OlcbCommander to implement more of the Traction Protocol document Modified Paths: -------------- trunk/prototypes/mikroPascal/Library/NMRAnet/NMRAnetDefinesShared.mpas trunk/prototypes/mikroPascal/Library/NMRAnet/NMRAnetNode.mpas trunk/prototypes/mikroPascal/Library/NMRAnet/NMRAnetStateMachine.mpas trunk/prototypes/mikroPascal/Library/NMRAnetDCCSystem/CommonServiceMode.mpas trunk/prototypes/mikroPascal/Library/NMRAnetDCCSystem/DirectServiceMode.mpas trunk/prototypes/mikroPascal/Library/NMRAnetDCCSystem/NMRAnetServiceMode.mpas trunk/prototypes/mikroPascal/Library/NMRAnetDCCSystem/PagedServiceMode.mpas trunk/prototypes/mikroPascal/Library/NMRAnetDCCSystem/ServiceModeDefines.mpas trunk/prototypes/mikroPascal/Library/NMRAnetDCCSystem/TractionProtocol.mpas trunk/prototypes/mikroPascal/dsPIC33EP256_CommandStation/MemoryMapping.ods trunk/prototypes/mikroPascal/dsPIC33EP256_CommandStation/NMRAnetAppCallbacks.mpas trunk/prototypes/mikroPascal/dsPIC33EP256_CommandStation/NMRAnetAppDefines.mpas trunk/prototypes/mikroPascal/dsPIC33EP256_CommandStation/dsPIC33EP_NMRABusCommandStation.hex trunk/prototypes/mikroPascal/dsPIC33EP256_CommandStation/dsPIC33EP_NMRABusCommandStation.mppds trunk/prototypes/mikroPascal/dsPIC33EP256_CommandStation/dsPIC33EP_NMRAnetCommandStation.mpas trunk/prototypes/mikroPascal/dsPIC33EP256_CommandStation/dsPIC33F_CommandStation.xml trunk/prototypes/mikroPascal/dsPIC33EP256_CommandStation/dsPIC33F_ProxyNode.xml trunk/prototypes/mikroPascal/dsPIC33EP_NceBridge/NMRAnetAppCallbacks.mpas trunk/prototypes/mikroPascal/dsPIC33EP_NceBridge/NMRAnetAppDefines.mpas trunk/prototypes/mikroPascal/dsPIC33EP_NceBridge/NMRAnetNceAdapter.xml trunk/prototypes/mikroPascal/dsPIC33EP_NceBridge/NMRAnetNceDevice.xml trunk/prototypes/mikroPascal/dsPIC33EP_NceBridge/dsPIC33EP_NMRABusNceBridge.hex trunk/prototypes/mikroPascal/dsPIC33EP_NceBridge/dsPIC33EP_NMRABusNceBridge.mppds trunk/prototypes/mikroPascal/dsPIC33EP_XpressnetBridge/NMRAnetAppCallbacks.mpas trunk/prototypes/mikroPascal/dsPIC33EP_XpressnetBridge/NMRAnetAppDefines.mpas trunk/prototypes/mikroPascal/dsPIC33EP_XpressnetBridge/NMRAnetXpressnetAdapter.xml trunk/prototypes/mikroPascal/dsPIC33EP_XpressnetBridge/NMRAnetXpressnetDevice.xml trunk/prototypes/mikroPascal/dsPIC33EP_XpressnetBridge/dsPIC33EP_NMRABusXpressnet.hex trunk/prototypes/mikroPascal/dsPIC33EP_XpressnetBridge/dsPIC33EP_NMRABusXpressnet.mppds trunk/prototypes/mikroPascal/dsPIC33FJ_Visual TFT_BasicThrottle/Throttle_Code/mikroPascal PRO for dsPIC/NMRAnetAppCallbacks.mpas trunk/prototypes/mikroPascal/dsPIC33FJ_Visual TFT_BasicThrottle/Throttle_Code/mikroPascal PRO for dsPIC/NMRAnetAppDefines.mpas trunk/prototypes/mikroPascal/dsPIC33FJ_Visual TFT_BasicThrottle/Throttle_Code/mikroPascal PRO for dsPIC/NMRAnetVisualThrottle.xml trunk/prototypes/mikroPascal/dsPIC33FJ_Visual TFT_BasicThrottle/Throttle_Code/mikroPascal PRO for dsPIC/Throttle.hex trunk/prototypes/mikroPascal/dsPIC33FJ_Visual TFT_BasicThrottle/Throttle_Code/mikroPascal PRO for dsPIC/Throttle.mppds trunk/scratchpads/jkueneman/Library/olcb_defines.pas trunk/scratchpads/jkueneman/Library/olcb_structure_helpers.pas trunk/scratchpads/jkueneman/Library/olcb_utilities.pas trunk/scratchpads/jkueneman/OlcbCommander/OLCB_Commander.lps trunk/scratchpads/jkueneman/OlcbCommander/form_main.lfm trunk/scratchpads/jkueneman/OlcbCommander/form_main.pas Modified: trunk/prototypes/mikroPascal/Library/NMRAnet/NMRAnetDefinesShared.mpas =================================================================== --- trunk/prototypes/mikroPascal/Library/NMRAnet/NMRAnetDefinesShared.mpas 2013-05-04 19:12:05 UTC (rev 3213) +++ trunk/prototypes/mikroPascal/Library/NMRAnet/NMRAnetDefinesShared.mpas 2013-05-05 03:01:52 UTC (rev 3214) @@ -85,12 +85,13 @@ end; const - MSI_CDI = $FF; // MemorySpaceIdentifer - Access the Configuration Definition Infomation (CDI) - MSI_ALL = $FE; // MemorySpaceIdentifer - Access All memory (define all in the application) - MSI_CONFIG = $FD; // MemorySpaceIdentifer - Access basic configuration memory that feeds into the CDI - MSI_ACDI_MFG = $FC; // MemorySpaceIdentifer - Access the ACDI Manfacturers Info - MSI_ACDI_USER = $FB; // MemorySpaceIdentifer - Access the ACDI User definable Info - MSI_FDI = $FA; // MemorySpaceIdentifer - Access the Function Definition Information (FDI) + MSI_CDI = $FF; // MemorySpaceIdentifier - Access the Configuration Definition Infomation (CDI) + MSI_ALL = $FE; // MemorySpaceIdentifier - Access All memory (define all in the application) + MSI_CONFIG = $FD; // MemorySpaceIdentifier - Access basic configuration memory that feeds into the CDI + MSI_ACDI_MFG = $FC; // MemorySpaceIdentifier - Access the ACDI Manfacturers Info + MSI_ACDI_USER = $FB; // MemorySpaceIdentifier - Access the ACDI User definable Info + MSI_FDI = $FA; // MemorySpaceIdentifier - Access the Function Definition Information (FDI) + MSI_FSI = $F9; // MemorySpaceIdentifier - Access the Function State information MCO_WRITE_UNDER_MASK = $8000; // MemoryConfigurationOptions - Write under mask supported MCO_UNALIGNED_READS = $4000; // MemoryConfigurationOptions - Unaligned memory Reads supported Modified: trunk/prototypes/mikroPascal/Library/NMRAnet/NMRAnetNode.mpas =================================================================== --- trunk/prototypes/mikroPascal/Library/NMRAnet/NMRAnetNode.mpas 2013-05-04 19:12:05 UTC (rev 3213) +++ trunk/prototypes/mikroPascal/Library/NMRAnet/NMRAnetNode.mpas 2013-05-05 03:01:52 UTC (rev 3214) @@ -20,7 +20,8 @@ {$I Options.inc} -{.$DEFINE PRINT_NODE} +{$DEFINE PRINT_NODE} + uses NMRAnetUtilities, NMRAnetAppDefines, @@ -383,12 +384,12 @@ Nodes.AllocatedCount := 0; for i := 0 to MAX_NODE_COUNT - 1 do begin - NMRAnetStateMachine_InitializeNode(@Nodes.RawList[i], PhysicalNodeID_HI, PhysicalNodeID_LO + i); // Physical Node + i MUST FIT IN THE LOWER 3 BYTES - Nodes.RawList[i].iIndex := i; if i > 0 then NMRAnetNode_SetStateFlag(@Nodes.RawList[i], NS_VIRTUAL); AppCallback_AssignConfigurationAddress(@Nodes.RawList[i], i); AppCallback_AssignRAMAddress(@Nodes.RawList[i], i); + NMRAnetStateMachine_InitializeNode(@Nodes.RawList[i], PhysicalNodeID_HI, PhysicalNodeID_LO + i); // Physical Node + i MUST FIT IN THE LOWER 3 BYTES + Nodes.RawList[i].iIndex := i; end; Node := @Nodes.RawList[0]; Node^.Info.AliasID := NMRAnetUtilities_CreateAliasID(Node^.Info.Seed, False); // Pregenerate it so it can be sorted // Allocate the Physical Node Modified: trunk/prototypes/mikroPascal/Library/NMRAnet/NMRAnetStateMachine.mpas =================================================================== --- trunk/prototypes/mikroPascal/Library/NMRAnet/NMRAnetStateMachine.mpas 2013-05-04 19:12:05 UTC (rev 3213) +++ trunk/prototypes/mikroPascal/Library/NMRAnet/NMRAnetStateMachine.mpas 2013-05-05 03:01:52 UTC (rev 3214) @@ -13,7 +13,7 @@ // 2012-10-07: Version 1.0 // // * Description: -// Implements NMRAnet StateMachine for the main loop in a program. +// Implements NMRAnet StateMachine for the main loop in a programg. // // ****************************************************************************** {$I Options.inc} @@ -73,14 +73,15 @@ // *************************************************************************** function AppCallback_AddressSpacePresent(Node: PNMRAnetNode; AddressSpace: Byte): Boolean; external; function AppCallback_AddressSpaceReadOnly(Node: PNMRAnetNode; AddressSpace: Byte): Boolean; external; + function AppCallback_AddressSpaceSize(Node: PNMRAnetNode; AddressSpace: Byte): DWord; external; - function AppCallback_Configuration_AddressSpaceSize(Node: PNMRAnetNode): DWord; external; procedure AppCallback_Configuration_Read(Node: PNMRAnetNode; ConfigMemBuffer: PConfigMemBuffer); external; procedure AppCallback_Configuration_Write(Node: PNMRAnetNode; ConfigMemBuffer: PConfigMemBuffer); external; + function AppCallback_AddressSpace_Read(Node: PNMRAnetNode; ConfigMemBuffer: PConfigMemBuffer): Boolean; external; + function AppCallback_AddressSpace_Write(Node: PNMRAnetNode; ConfigMemBuffer: PConfigMemBuffer): Boolean; external; procedure AppCallback_ConfigMemReadWriteAckReply(Node: PNMRAnetNode; ConfigMemBuffer: PConfigMemBuffer); external; procedure AppCallback_Configuration_CheckForComplete(Node: PNMRAnetNode; ConfigMemBuffer: PConfigMemBuffer); external; - // Forward declarations function TransmitNMRABusLayerMsg(Node: PNMRAnetNode; Buffer: PCANBuffer; VariableField: DWord; DestinationAliasID: Word; DataCount: Byte; DataBytes: PCAN_DataBytes; AliasInHeader: Boolean; UpperNibbleFlagMask: Word): Boolean; forward; function TransmitCANLayerMsg(Node: PNMRAnetNode; Buffer: PCANBuffer; VariableField: DWord): Boolean; forward; @@ -466,7 +467,6 @@ Result := MAX_CDI_ARRAY; end; MSI_ALL : Result := ALL_MAP.HighMem; - MSI_CONFIG : Result := AppCallback_Configuration_AddressSpaceSize(Node); MSI_ACDI_MFG : begin {$IFDEF SUPPORT_VIRTUAL_NODES} if Node^.State and NS_VIRTUAL <> 0 then @@ -475,7 +475,12 @@ Result := MAX_ACDI_MFG_ARRAY + 1 // for the Version ID Byte end; MSI_ACDI_USER : begin - Result := MAX_USER_CONFIG_DATA + 1 // for the Version ID Byte + Result := MAX_USER_CONFIG_DATA + 1 // for the Version ID Byte + end; + MSI_CONFIG, + MSI_FSI, + MSI_FDI : begin + Result := AppCallback_AddressSpaceSize(Node, AddressSpace); end else Result := 0; @@ -798,6 +803,7 @@ // Very wasteful and slow 1 at a time but it is easy ConfigMemBuffer^.Address := BaseBuffer^.Tag; ConfigMemBuffer^.DataCount := 1; + ConfigMemBuffer^.AddressSpace := MSI_CONFIG; AppCallback_Configuration_Read(Node, ConfigMemBuffer); DataBytes[i] := ConfigMemBuffer^.DataBytes[0]; @@ -840,7 +846,6 @@ begin {$IFDEF TRACE_SNIP}UART1_Write_Text('STATE_ACDI_DONE'+LF); {$ENDIF} end; end; - NMRAnetBufferPools_ReleaseConfigMemBuffer(ConfigMemBuffer); end; if i > 0 then @@ -851,6 +856,8 @@ NMRAnetUtilities_BaseBufferUnLink(Node, BaseBuffer); NMRAnetBufferPools_ReleaseBaseBuffer(BaseBuffer); end; + + NMRAnetBufferPools_ReleaseConfigMemBuffer(ConfigMemBuffer); end end; {$ENDIF} // BOOTLOADER @@ -966,77 +973,83 @@ end; STATE_MEM_CONFIG_READWRITE_READ : begin {$IFDEF TRACE_MEM_CONFIG_STATEMACHINE} UART1_Write_Text('STATE_MEM_CONFIG_READWRITE_READ'+LF); {$ENDIF} - case ConfigMemBuffer^.AddressSpace of - MSI_CDI : begin {$IFDEF SUPPORT_VIRTUAL_NODES} - if Node^.State and NS_VIRTUAL <> 0 then - begin + if not AppCallback_AddressSpace_Read(Node, ConfigMemBuffer) then + begin + case ConfigMemBuffer^.AddressSpace of + MSI_CDI : begin {$IFDEF SUPPORT_VIRTUAL_NODES} + if Node^.State and NS_VIRTUAL <> 0 then + begin + for i := 0 to ConfigMemBuffer^.DataCount - 1 do + ConfigMemBuffer^.DataBytes[i] := CDI_ARRAY_VNODE[i+ConfigMemBuffer^.Address] + end else {$ENDIF} + begin + for i := 0 to ConfigMemBuffer^.DataCount - 1 do + ConfigMemBuffer^.DataBytes[i] := CDI_ARRAY[i+ConfigMemBuffer^.Address] + end; + end; + MSI_ALL : begin + ByteArray := PByteArray( ALL_MAP.LowMem); for i := 0 to ConfigMemBuffer^.DataCount - 1 do - ConfigMemBuffer^.DataBytes[i] := CDI_ARRAY_VNODE[i+ConfigMemBuffer^.Address] - end else {$ENDIF} - begin - for i := 0 to ConfigMemBuffer^.DataCount - 1 do - ConfigMemBuffer^.DataBytes[i] := CDI_ARRAY[i+ConfigMemBuffer^.Address] + ConfigMemBuffer^.DataBytes[i] := ByteArray^[i+ConfigMemBuffer^.Address]; end; - end; - MSI_ALL : begin - ByteArray := PByteArray( ALL_MAP.LowMem); - for i := 0 to ConfigMemBuffer^.DataCount - 1 do - ConfigMemBuffer^.DataBytes[i] := ByteArray^[i+ConfigMemBuffer^.Address]; - end; - MSI_CONFIG : AppCallback_Configuration_Read(Node, ConfigMemBuffer); - MSI_ACDI_MFG : begin - if ConfigMemBuffer^.Address = 0 then - begin - Dec(ConfigMemBuffer^.DataCount); - ConfigMemBuffer^.DataOffset := 1; - ConfigMemBuffer^.DataBytes[0] := ACDI_MFG_VERSION; + MSI_CONFIG : AppCallback_Configuration_Read(Node, ConfigMemBuffer); + MSI_ACDI_MFG : begin + if ConfigMemBuffer^.Address = 0 then + begin + Dec(ConfigMemBuffer^.DataCount); + ConfigMemBuffer^.DataOffset := 1; + ConfigMemBuffer^.DataBytes[0] := ACDI_MFG_VERSION; + end; + + {$IFDEF SUPPORT_VIRTUAL_NODES} + if Node^.State and NS_VIRTUAL <> 0 then + begin + for i := 0 to ConfigMemBuffer^.DataCount - 1 do + ConfigMemBuffer^.DataBytes[i + ConfigMemBuffer^.DataOffset] := ACDI_MFG_STRINGS_VNODE[ConfigMemBuffer^.Address + i]; + end else {$ENDIF} + begin + for i := 0 to ConfigMemBuffer^.DataCount - 1 do + ConfigMemBuffer^.DataBytes[i + ConfigMemBuffer^.DataOffset] := ACDI_MFG_STRINGS[ConfigMemBuffer^.Address + i]; + end; + + if ConfigMemBuffer^.Address = 0 then + begin + ConfigMemBuffer^.DataOffset := 1; + Inc(ConfigMemBuffer^.DataCount); + end; end; - - {$IFDEF SUPPORT_VIRTUAL_NODES} - if Node^.State and NS_VIRTUAL <> 0 then - begin - for i := 0 to ConfigMemBuffer^.DataCount - 1 do - ConfigMemBuffer^.DataBytes[i + ConfigMemBuffer^.DataOffset] := ACDI_MFG_STRINGS_VNODE[ConfigMemBuffer^.Address + i]; - end else {$ENDIF} - begin - for i := 0 to ConfigMemBuffer^.DataCount - 1 do - ConfigMemBuffer^.DataBytes[i + ConfigMemBuffer^.DataOffset] := ACDI_MFG_STRINGS[ConfigMemBuffer^.Address + i]; + MSI_ACDI_USER : begin + if ConfigMemBuffer^.Address = 0 then + begin + ConfigMemBuffer^.DataBytes[0] := ACDI_USER_VERSION; + Inc(ConfigMemBuffer^.Address); // The CDI offsets the Configuration Memory by 1 so everything needs to be shifted + Dec(ConfigMemBuffer^.DataCount); + ConfigMemBuffer^.DataOffset := 1; // Write to the array at offset 1 + AppCallback_Configuration_Read(Node, ConfigMemBuffer); + Inc(ConfigMemBuffer^.DataCount); // Restore the state + ConfigMemBuffer^.DataOffset := 0; + Dec(ConfigMemBuffer^.Address); + end else + begin + Inc(ConfigMemBuffer^.Address); // The CDI offsets the Configuration Memory by 1 so everything needs to be shifted + AppCallback_Configuration_Read(Node, ConfigMemBuffer); + Dec(ConfigMemBuffer^.Address); + end end; - - if ConfigMemBuffer^.Address = 0 then - begin - ConfigMemBuffer^.DataOffset := 1; - Inc(ConfigMemBuffer^.DataCount); - end; - end; - MSI_ACDI_USER : begin - if ConfigMemBuffer^.Address = 0 then - begin - ConfigMemBuffer^.DataBytes[0] := ACDI_USER_VERSION; - Inc(ConfigMemBuffer^.Address); // The CDI offsets the Configuration Memory by 1 so everything needs to be shifted - Dec(ConfigMemBuffer^.DataCount); - ConfigMemBuffer^.DataOffset := 1; // Write to the array at offset 1 - AppCallback_Configuration_Read(Node, ConfigMemBuffer); - Inc(ConfigMemBuffer^.DataCount); // Restore the state - ConfigMemBuffer^.DataOffset := 0; - Dec(ConfigMemBuffer^.Address); - end else - begin - Inc(ConfigMemBuffer^.Address); // The CDI offsets the Configuration Memory by 1 so everything needs to be shifted - AppCallback_Configuration_Read(Node, ConfigMemBuffer); - Dec(ConfigMemBuffer^.Address); - end - end; + end; end; ConfigMemBuffer^.StateMachine := STATE_MEM_CONFIG_READWRITE_WAIT end; STATE_MEM_CONFIG_READWRITE_WRITE : begin {$IFDEF TRACE_MEM_CONFIG_STATEMACHINE} UART1_Write_Text('STATE_MEM_CONFIG_READWRITE_WRITE'+LF); {$ENDIF} - case ConfigMemBuffer^.AddressSpace of - MSI_CONFIG : AppCallback_Configuration_Write(Node, ConfigMemBuffer); - MSI_ACDI_USER : UART1_Write_Text('Unimplemented Configuration Mem write'+LF); - end; - ConfigMemBuffer^.StateMachine := STATE_MEM_CONFIG_READWRITE_WAIT + if not AppCallback_AddressSpace_Write(Node, ConfigMemBuffer) then + begin + case ConfigMemBuffer^.AddressSpace of + MSI_CONFIG : AppCallback_Configuration_Write(Node, ConfigMemBuffer); + MSI_ACDI_USER : UART1_Write_Text('Unimplemented Configuration Mem write'+LF); + end; + end; + ConfigMemBuffer^.StateMachine := STATE_MEM_CONFIG_READWRITE_WAIT end; STATE_MEM_CONFIG_READWRITE_WAIT : begin {$IFDEF TRACE_MEM_CONFIG_STATEMACHINE} UART1_Write_Text('STATE_MEM_CONFIG_READWRITE_WAIT'+LF); {$ENDIF} @@ -1114,11 +1127,23 @@ begin {$IFDEF TRACE_MEM_CONFIG_OP_STATEMACHINE} UART1_Write_Text('MCP_OP_GET_CONFIG'+LF);{$ENDIF} DatagramBuffer^.DataBytes[0] := DATAGRAM_TYPE_MEMORY_CONFIGURATION; DatagramBuffer^.DataBytes[1] := MCP_OP_GET_CONFIG_REPLY; - DatagramBuffer^.DataBytes[2] := Hi( MEMORY_CONFIG_OPTIONS.MemoryConfigOptions); - DatagramBuffer^.DataBytes[3] := Lo( MEMORY_CONFIG_OPTIONS.MemoryConfigOptions); - DatagramBuffer^.DataBytes[4] := MEMORY_CONFIG_OPTIONS.MemoryConfigWriteLength; - DatagramBuffer^.DataBytes[5] := MEMORY_CONFIG_OPTIONS.MemoryConfigHighestSpace; - DatagramBuffer^.DataBytes[6] := MEMORY_CONFIG_OPTIONS.MemoryConfigLowestSpace; + {$IFDEF SUPPORT_VIRTUAL_NODES} + if NMRAnetNode_TestStateFlag(Node, NS_VIRTUAL) then + begin + DatagramBuffer^.DataBytes[2] := Hi( MEMORY_CONFIG_OPTIONS_VNODE.MemoryConfigOptions); + DatagramBuffer^.DataBytes[3] := Lo( MEMORY_CONFIG_OPTIONS_VNODE.MemoryConfigOptions); + DatagramBuffer^.DataBytes[4] := MEMORY_CONFIG_OPTIONS_VNODE.MemoryConfigWriteLength; + DatagramBuffer^.DataBytes[5] := MEMORY_CONFIG_OPTIONS_VNODE.MemoryConfigHighestSpace; + DatagramBuffer^.DataBytes[6] := MEMORY_CONFIG_OPTIONS_VNODE.MemoryConfigLowestSpace; + end else + {$ENDIF} + begin + DatagramBuffer^.DataBytes[2] := Hi( MEMORY_CONFIG_OPTIONS.MemoryConfigOptions); + DatagramBuffer^.DataBytes[3] := Lo( MEMORY_CONFIG_OPTIONS.MemoryConfigOptions); + DatagramBuffer^.DataBytes[4] := MEMORY_CONFIG_OPTIONS.MemoryConfigWriteLength; + DatagramBuffer^.DataBytes[5] := MEMORY_CONFIG_OPTIONS.MemoryConfigHighestSpace; + DatagramBuffer^.DataBytes[6] := MEMORY_CONFIG_OPTIONS.MemoryConfigLowestSpace; + end; DatagramBuffer^.iByteCount := 7; // Send a response DatagramBuffer^.Statemachine := STATE_DATAGRAM_MEM_CONFIG_SEND_RESUSED_DATAGRAM @@ -1540,7 +1565,7 @@ // Done until reboot end else - UART1_Write_Text('Statemachine Index Error'); + UART1_Write_Text('Statemachine Index Error'+LF); end; UnLockCANInterrupt end; Modified: trunk/prototypes/mikroPascal/Library/NMRAnetDCCSystem/CommonServiceMode.mpas =================================================================== --- trunk/prototypes/mikroPascal/Library/NMRAnetDCCSystem/CommonServiceMode.mpas 2013-05-04 19:12:05 UTC (rev 3213) +++ trunk/prototypes/mikroPascal/Library/NMRAnetDCCSystem/CommonServiceMode.mpas 2013-05-05 03:01:52 UTC (rev 3214) @@ -41,10 +41,10 @@ procedure ResetACK; begin - ServiceModeInfo.Flags.PROGRAMMING_ACK_SCANNING_FOR_ACK_BIT := 1; // Start Looking - ServiceModeInfo.Flags.PROGRAMMING_ACK_DETECTED_BIT := 0; - ServiceModeInfo.Flags.PROGRAMMING_ACK_TIMER_DETECTED_LEADINGEDGE_BIT := 0; - ServiceModeInfo.Flags.PROGRAMMING_ACK_FAILED_TO_DETECT_TRAILINGEDGE_BIT := 0; + ServiceModeInfo.State.PROGRAMMING_ACK_SCANNING_FOR_ACK_BIT := 1; // Start Looking + ServiceModeInfo.State.PROGRAMMING_ACK_DETECTED_BIT := 0; + ServiceModeInfo.State.PROGRAMMING_ACK_TIMER_DETECTED_LEADINGEDGE_BIT := 0; + ServiceModeInfo.State.PROGRAMMING_ACK_FAILED_TO_DETECT_TRAILINGEDGE_BIT := 0; end; // *************************************************************************** @@ -236,18 +236,18 @@ // *************************************************************************** procedure CommonServiceMode_SendInstructions(BufferPtr: PDCCBufferInfo; SendInstruction, AckHandler, NoAckHandler: PServiceModePtr; InstructionCount: Word); begin - if ServiceModeInfo.Flags.PROGRAMMING_ACK_DETECTED_BIT = 1 then + if ServiceModeInfo.State.PROGRAMMING_ACK_DETECTED_BIT = 1 then begin // ACK detected and we are done AckHandler(BufferPtr); end else - if ServiceModeInfo.Flags.PROGRAMMING_ACK_FAILED_TO_DETECT_TRAILINGEDGE_BIT = 1 then + if ServiceModeInfo.State.PROGRAMMING_ACK_FAILED_TO_DETECT_TRAILINGEDGE_BIT = 1 then begin ServiceModeInfo.Value := 0; ServiceModeInfo.ServiceModeResult := SERVICE_MODE_RESULT_SHORT_ACK; NMRA_DCC_LoadResetPacketIntoTransmitter(BufferPtr, PREAMBLE_BIT_COUNT_SERVICEMODE); // Per 9.2.3 ServiceModeInfo.iStateMachine := STATE_SERVICEMODE_RESULTS_READY; end else - if ServiceModeInfo.Flags.PROGRAMMING_ACK_TIMER_DETECTED_LEADINGEDGE_BIT = 1 then + if ServiceModeInfo.State.PROGRAMMING_ACK_TIMER_DETECTED_LEADINGEDGE_BIT = 1 then NMRA_DCC_LoadResetPacketIntoTransmitter(BufferPtr, PREAMBLE_BIT_COUNT_SERVICEMODE) // Ack start detected so drop into Reset Packets are either success or failure handled above after 5ms else begin if ServiceModeInfo.iInstructionCountSent < InstructionCount then Modified: trunk/prototypes/mikroPascal/Library/NMRAnetDCCSystem/DirectServiceMode.mpas =================================================================== --- trunk/prototypes/mikroPascal/Library/NMRAnetDCCSystem/DirectServiceMode.mpas 2013-05-04 19:12:05 UTC (rev 3213) +++ trunk/prototypes/mikroPascal/Library/NMRAnetDCCSystem/DirectServiceMode.mpas 2013-05-05 03:01:52 UTC (rev 3214) @@ -1,5 +1,7 @@ unit DirectServiceMode; +{.$DEFINE PRINT_DIRECT_MODE_STATEMACHINE} + uses NMRAnetDCC, CommonServiceMode, @@ -130,14 +132,25 @@ if ServiceModeInfo.CV <= SERVICE_MODE_DIRECT_MODE_MAX_CV then begin case ServiceModeInfo.iStateMachine of - STATE_SERVICEMODE_POWER_ON_CYCLE : CommonServiceMode_PowerOnCycle(BufferPtr, SERVICEMODE_POWER_ON_CYCLE_COUNT, STATE_SERVICEMODE_RESET_CYCLE); - STATE_SERVICEMODE_RESET_CYCLE : CommonServiceMode_ResetCycle(BufferPtr, @InstructionSendByte, SERVICEMODE_RESET_COUNT, STATE_SERVICEMODE_SEND_INSTRUCTION, True); - STATE_SERVICEMODE_SEND_INSTRUCTION : CommonServiceMode_SendInstructions(BufferPtr, @InstructionSendByte, @CommonServiceMode_AckHandlerByte, @CommonServiceMode_NoAckHandler, SERVICEMODE_DIRECT_INSTRUCTION_COUNT); - STATE_SERVICEMODE_WRITE_RECOVERY : CommonServiceMode_ResetCycle(BufferPtr, @InstructionSendByte, SERVICEMODE_RECOVER_CYCLE_RESET_COUNT, STATE_SERVICEMODE_RESULTS_READY, True); - STATE_SERVICEMODE_RESULTS_READY : CommonServiceMode_ResultReady(BufferPtr); + STATE_SERVICEMODE_POWER_ON_CYCLE : begin {$IFDEF PRINT_DIRECT_MODE_STATEMACHINE}UART1_Write_Text('STATE_SERVICEMODE_POWER_ON_CYCLE'+LF); {$ENDIF} + CommonServiceMode_PowerOnCycle(BufferPtr, SERVICEMODE_POWER_ON_CYCLE_COUNT, STATE_SERVICEMODE_RESET_CYCLE); + end; + STATE_SERVICEMODE_RESET_CYCLE : begin {$IFDEF PRINT_DIRECT_MODE_STATEMACHINE}UART1_Write_Text('STATE_SERVICEMODE_RESET_CYCLE'+LF); {$ENDIF} + CommonServiceMode_ResetCycle(BufferPtr, @InstructionSendByte, SERVICEMODE_RESET_COUNT, STATE_SERVICEMODE_SEND_INSTRUCTION, True); + end; + STATE_SERVICEMODE_SEND_INSTRUCTION : begin {$IFDEF PRINT_DIRECT_MODE_STATEMACHINE}UART1_Write_Text('STATE_SERVICEMODE_SEND_INSTRUCTION'+LF); {$ENDIF} + CommonServiceMode_SendInstructions(BufferPtr, @InstructionSendByte, @CommonServiceMode_AckHandlerByte, @CommonServiceMode_NoAckHandler, SERVICEMODE_DIRECT_INSTRUCTION_COUNT); + end; + STATE_SERVICEMODE_WRITE_RECOVERY : begin {$IFDEF PRINT_DIRECT_MODE_STATEMACHINE}UART1_Write_Text('STATE_SERVICEMODE_WRITE_RECOVERY'+LF); {$ENDIF} + CommonServiceMode_ResetCycle(BufferPtr, @InstructionSendByte, SERVICEMODE_RECOVER_CYCLE_RESET_COUNT, STATE_SERVICEMODE_RESULTS_READY, True); + end; + STATE_SERVICEMODE_RESULTS_READY : begin {$IFDEF PRINT_DIRECT_MODE_STATEMACHINE}UART1_Write_Text('STATE_SERVICEMODE_RESULTS_READY'+LF); {$ENDIF} + CommonServiceMode_ResultReady(BufferPtr); + end; end end else begin + {$IFDEF PRINT_DIRECT_MODE_STATEMACHINE}UART1_Write_Text('INVALID_CV_IN_SERVICE_MODE_STATEMACHINE'+LF); {$ENDIF} ServiceModeInfo.Value := 0; ServiceModeInfo.ServiceModeResult := SERVICE_MODE_RESULT_INVALID_CV; NMRA_DCC_LoadResetPacketIntoTransmitter(BufferPtr, PREAMBLE_BIT_COUNT_SERVICEMODE); // Per 9.2.3 @@ -169,14 +182,25 @@ if ServiceModeInfo.CV <= SERVICE_MODE_DIRECT_MODE_MAX_CV then begin case ServiceModeInfo.iStateMachine of - STATE_SERVICEMODE_POWER_ON_CYCLE : CommonServiceMode_PowerOnCycle(BufferPtr, SERVICEMODE_POWER_ON_CYCLE_COUNT, STATE_SERVICEMODE_RESET_CYCLE); - STATE_SERVICEMODE_RESET_CYCLE : CommonServiceMode_ResetCycle(BufferPtr, @InstructionSendBit, SERVICEMODE_RESET_COUNT, STATE_SERVICEMODE_SEND_INSTRUCTION, True); - STATE_SERVICEMODE_SEND_INSTRUCTION : CommonServiceMode_SendInstructions(BufferPtr, @InstructionSendBit, @AckHandlerBit, @NoAckHandlerBit, SERVICEMODE_DIRECT_INSTRUCTION_COUNT); - STATE_SERVICEMODE_WRITE_RECOVERY : CommonServiceMode_ResetCycle(BufferPtr, nil, SERVICEMODE_RECOVER_CYCLE_RESET_COUNT, STATE_SERVICEMODE_RESULTS_READY, False); - STATE_SERVICEMODE_RESULTS_READY : CommonServiceMode_ResultReady(BufferPtr); + STATE_SERVICEMODE_POWER_ON_CYCLE : begin {$IFDEF PRINT_DIRECT_MODE_STATEMACHINE}UART1_Write_Text('STATE_SERVICEMODE_POWER_ON_CYCLE'+LF); {$ENDIF} + CommonServiceMode_PowerOnCycle(BufferPtr, SERVICEMODE_POWER_ON_CYCLE_COUNT, STATE_SERVICEMODE_RESET_CYCLE); + end; + STATE_SERVICEMODE_RESET_CYCLE : begin {$IFDEF PRINT_DIRECT_MODE_STATEMACHINE}UART1_Write_Text('STATE_SERVICEMODE_RESET_CYCLE'+LF); {$ENDIF} + CommonServiceMode_ResetCycle(BufferPtr, @InstructionSendBit, SERVICEMODE_RESET_COUNT, STATE_SERVICEMODE_SEND_INSTRUCTION, True); + end; + STATE_SERVICEMODE_SEND_INSTRUCTION : begin {$IFDEF PRINT_DIRECT_MODE_STATEMACHINE}UART1_Write_Text('STATE_SERVICEMODE_SEND_INSTRUCTION'+LF); {$ENDIF} + CommonServiceMode_SendInstructions(BufferPtr, @InstructionSendBit, @AckHandlerBit, @NoAckHandlerBit, SERVICEMODE_DIRECT_INSTRUCTION_COUNT); + end; + STATE_SERVICEMODE_WRITE_RECOVERY : begin {$IFDEF PRINT_DIRECT_MODE_STATEMACHINE}UART1_Write_Text('STATE_SERVICEMODE_WRITE_RECOVERY'+LF); {$ENDIF} + CommonServiceMode_ResetCycle(BufferPtr, nil, SERVICEMODE_RECOVER_CYCLE_RESET_COUNT, STATE_SERVICEMODE_RESULTS_READY, False); + end; + STATE_SERVICEMODE_RESULTS_READY : begin {$IFDEF PRINT_DIRECT_MODE_STATEMACHINE}UART1_Write_Text('STATE_SERVICEMODE_RESULTS_READY'+LF); {$ENDIF} + CommonServiceMode_ResultReady(BufferPtr); + end; end end else begin + {$IFDEF PRINT_DIRECT_MODE_STATEMACHINE}UART1_Write_Text('INVALID_CV_IN_SERVICE_MODE_STATEMACHINE'+LF); {$ENDIF} ServiceModeInfo.Value := 0; ServiceModeInfo.ServiceModeResult := SERVICE_MODE_RESULT_INVALID_CV; NMRA_DCC_LoadResetPacketIntoTransmitter(BufferPtr, PREAMBLE_BIT_COUNT_SERVICEMODE); // Per 9.2.3 Modified: trunk/prototypes/mikroPascal/Library/NMRAnetDCCSystem/NMRAnetServiceMode.mpas =================================================================== --- trunk/prototypes/mikroPascal/Library/NMRAnetDCCSystem/NMRAnetServiceMode.mpas 2013-05-04 19:12:05 UTC (rev 3213) +++ trunk/prototypes/mikroPascal/Library/NMRAnetDCCSystem/NMRAnetServiceMode.mpas 2013-05-05 03:01:52 UTC (rev 3214) @@ -22,6 +22,7 @@ DirectServiceMode, RegisterServiceMode, PagedServiceMode, + NMRAnetDefinesShared, ServiceModeDefines; // Call once on start up @@ -40,6 +41,8 @@ function ServiceMode_ResultsReady: Boolean; // Ends the Statemachine (after a completed read/write cycle) procedure ServiceMode_Quit; +// Print ServiceModeInfo +procedure ServiceMode_Print; var DCC_Programming_ACK_Pin : sbit; sfr; external; @@ -53,21 +56,43 @@ var i: Integer; begin - ServiceModeInfo.Flags := 0; + ServiceModeInfo.State := 0; ServiceModeInfo.ServiceModeResult := SERVICE_MODE_RESULT_NO_ACK; ServiceModeInfo.iInstructionCountSent := 0; ServiceModeInfo.Value := 0; ServiceModeInfo.ReadWrite := 0; ServiceModeInfo.CV := 0; ServiceModeInfo.ServiceModeType := 0; - ServiceModeInfo.Flags := 0; ServiceModeInfo.iStateMachine := STATE_SERVICEMODE_IDLE; - ServiceModeInfo.iInstructionCountSent := 0; ServiceModeInfo.ReadIndex := 0; ServiceModeInfo.LastPagedOffset := -1; // Invalid DCC_Programming_ACK_Direction := 1; // Input end; +procedure ServiceMode_Print; +begin + IntToStr(ServiceModeInfo.State, s1); + UART1_Write_Text('State: ' + s1 + LF); + IntToStr(ServiceModeInfo.ServiceModeResult, s1); + UART1_Write_Text('ServiceModeResult: ' + s1 + LF); + IntToStr(ServiceModeInfo.iInstructionCountSent, s1); + UART1_Write_Text('iInstructionCountSent: ' + s1 + LF); + IntToStr(ServiceModeInfo.Value, s1); + UART1_Write_Text('Value: ' + s1 + LF); + IntToStr(ServiceModeInfo.ReadWrite, s1); + UART1_Write_Text('ReadWrite: ' + s1 + LF); + IntToStr(ServiceModeInfo.CV, s1); + UART1_Write_Text('CV: ' + s1 + LF); + IntToStr(ServiceModeInfo.iStatemachine, s1); + UART1_Write_Text('iStateMachine: ' + s1 + LF); + IntToStr(ServiceModeInfo.ReadIndex, s1); + UART1_Write_Text('ReadIndex: ' + s1 + LF); + IntToStr(ServiceModeInfo.LastPagedOffset, s1); + UART1_Write_Text('LastPagedOffset: ' + s1 + LF); + IntToStr(ServiceModeInfo.iInstructionCountSent, s1); + UART1_Write_Text('iInstructionCountSent: ' + s1 + LF); +end; + // **************************************************************************** // procedure ServiceMode_EngageServiceMode // @@ -87,7 +112,7 @@ ServiceModeInfo.CV := ACV; // The CV to write or the buffer to receive the CV read ServiceModeInfo.ServiceModeType := AServiceModeType; ServiceModeInfo.ServiceModeResult := SERVICE_MODE_RESULT_NO_ACK; // Empty ready to be filled - ServiceModeInfo.Flags := 0; + ServiceModeInfo.State := 0; Ack_TimerEnabled_Bit := 0; // Turn the timer off if AServiceModeType = SERVICE_MODE_TYPE_DIRECT_BIT then begin @@ -130,14 +155,14 @@ // **************************************************************************** procedure ServiceMode_56us_TimeTick; begin - if ServiceModeInfo.Flags.PROGRAMMING_ACK_SCANNING_FOR_ACK_BIT = 1 then // Are we are scanning for an ACK? + if ServiceModeInfo.State.PROGRAMMING_ACK_SCANNING_FOR_ACK_BIT = 1 then // Are we are scanning for an ACK? begin if DCC_Programming_ACK_Pin = 1 then // Have we found an ACK? begin // Found the ACK, set the state then start the timer to see if it lasts 6ms +/-1ms - ServiceModeInfo.Flags.PROGRAMMING_ACK_SCANNING_FOR_ACK_BIT := 0; - ServiceModeInfo.Flags.PROGRAMMING_ACK_DETECTED_BIT := 0; - ServiceModeInfo.Flags.PROGRAMMING_ACK_FAILED_TO_DETECT_TRAILINGEDGE_BIT := 0; - ServiceModeInfo.Flags.PROGRAMMING_ACK_TIMER_DETECTED_LEADINGEDGE_BIT := 1; + ServiceModeInfo.State.PROGRAMMING_ACK_SCANNING_FOR_ACK_BIT := 0; + ServiceModeInfo.State.PROGRAMMING_ACK_DETECTED_BIT := 0; + ServiceModeInfo.State.PROGRAMMING_ACK_FAILED_TO_DETECT_TRAILINGEDGE_BIT := 0; + ServiceModeInfo.State.PROGRAMMING_ACK_TIMER_DETECTED_LEADINGEDGE_BIT := 1; Ack_TimerEnabled_Bit := 1; // Turn the timer on end end @@ -160,9 +185,9 @@ // This will only be called if the state machine detects the start of an Acknowledge // from the decoder. if DCC_Programming_ACK_Pin = 1 then - ServiceModeInfo.Flags.PROGRAMMING_ACK_DETECTED_BIT := 1 + ServiceModeInfo.State.PROGRAMMING_ACK_DETECTED_BIT := 1 else - ServiceModeInfo.Flags.PROGRAMMING_ACK_FAILED_TO_DETECT_TRAILINGEDGE_BIT := 1; + ServiceModeInfo.State.PROGRAMMING_ACK_FAILED_TO_DETECT_TRAILINGEDGE_BIT := 1; end; // **************************************************************************** Modified: trunk/prototypes/mikroPascal/Library/NMRAnetDCCSystem/PagedServiceMode.mpas =================================================================== --- trunk/prototypes/mikroPascal/Library/NMRAnetDCCSystem/PagedServiceMode.mpas 2013-05-04 19:12:05 UTC (rev 3213) +++ trunk/prototypes/mikroPascal/Library/NMRAnetDCCSystem/PagedServiceMode.mpas 2013-05-05 03:01:52 UTC (rev 3214) @@ -37,7 +37,7 @@ // *************************************************************************** procedure PageRegisterWriteCycle(BufferPtr: PDCCBufferInfo); begin - if (ServiceModeInfo.iInstructionCountSent < SERVICEMODE_PAGED_PAGE_WRITE_COUNT) and (ServiceModeInfo.Flags.PROGRAMMING_ACK_DETECTED_BIT = 0) then + if (ServiceModeInfo.iInstructionCountSent < SERVICEMODE_PAGED_PAGE_WRITE_COUNT) and (ServiceModeInfo.State.PROGRAMMING_ACK_DETECTED_BIT = 0) then begin // If we have not sent all Page Register Write instructions AND we have not received an ACK from a previous on then keep sending them Inc(ServiceModeInfo.iInstructionCountSent); @@ -47,10 +47,10 @@ // Even if we did not get an ACK assume it succeeded since the spec says to move on after an ACK OR if the number of packets has been sent ServiceModeInfo.iInstructionCountSent := 1; NMRA_DCC_LoadResetPacketIntoTransmitter(BufferPtr, PREAMBLE_BIT_COUNT_SERVICEMODE); - ServiceModeInfo.Flags.PROGRAMMING_ACK_DETECTED_BIT := 0; - ServiceModeInfo.Flags.PROGRAMMING_ACK_TIMER_DETECTED_LEADINGEDGE_BIT := 0; - ServiceModeInfo.Flags.PROGRAMMING_ACK_FAILED_TO_DETECT_TRAILINGEDGE_BIT := 0; - ServiceModeInfo.Flags.PROGRAMMING_ACK_SCANNING_FOR_ACK_BIT := 0; + ServiceModeInfo.State.PROGRAMMING_ACK_DETECTED_BIT := 0; + ServiceModeInfo.State.PROGRAMMING_ACK_TIMER_DETECTED_LEADINGEDGE_BIT := 0; + ServiceModeInfo.State.PROGRAMMING_ACK_FAILED_TO_DETECT_TRAILINGEDGE_BIT := 0; + ServiceModeInfo.State.PROGRAMMING_ACK_SCANNING_FOR_ACK_BIT := 0; ServiceModeInfo.iStateMachine := STATE_SERVICEMODE_PAGED_WRITE_PAGE_REGISTER_RECOVER; end end; @@ -111,4 +111,4 @@ end; end; -end. +end. \ No newline at end of file Modified: trunk/prototypes/mikroPascal/Library/NMRAnetDCCSystem/ServiceModeDefines.mpas =================================================================== --- trunk/prototypes/mikroPascal/Library/NMRAnetDCCSystem/ServiceModeDefines.mpas 2013-05-04 19:12:05 UTC (rev 3213) +++ trunk/prototypes/mikroPascal/Library/NMRAnetDCCSystem/ServiceModeDefines.mpas 2013-05-05 03:01:52 UTC (rev 3214) @@ -78,7 +78,7 @@ ReadWrite : Byte; // [IN] SERVICEMODE_READ or SERVICEMODE_WRITE CV : Word; // [IN] The CV to write or read from ServiceModeType : Byte; // [IN] Which Service Mode Type to use; see SERVICE_MODE_TYPE_xxxx constants - Flags : Byte; // [INTERNAL] See PROGRAMMING_ACK_STATE_XXXXX constants + State : Byte; // [INTERNAL] See PROGRAMMING_ACK_STATE_XXXXX constants iStateMachine : Byte; // [INTERNAL] Current State of the Service Mode State Machine iInstructionCountSent : Byte; // [INTERNAL] State Machine uses to count the number of Packets for different states of a Service Mode call ReadIndex : Byte; // [INTERNAL] Tracks what Value the read is attempting or the Offset Bit in Bit mode Modified: trunk/prototypes/mikroPascal/Library/NMRAnetDCCSystem/TractionProtocol.mpas =================================================================== --- trunk/prototypes/mikroPascal/Library/NMRAnetDCCSystem/TractionProtocol.mpas 2013-05-04 19:12:05 UTC (rev 3213) +++ trunk/prototypes/mikroPascal/Library/NMRAnetDCCSystem/TractionProtocol.mpas 2013-05-05 03:01:52 UTC (rev 3214) @@ -68,10 +68,12 @@ TRACTION_MANAGE_RESERVE_REPLY_FAIL = $FF; // Failed is not 0 TRACTION_MANAGE_QUERY_REPLY = $03; - STR_LOCO_NOT_FOUND = 'Loco not detected' + #0; // 60 characters limit - STR_SHORT_CIRCUIT = 'Overcurrent detected' + #0; // 60 characters limit - STR_INVALID_PROGRAMMING_METHOD = 'Programming method not compatible' + #0; // 60 characters limit - + STR_ERROR_LOCO_NOT_FOUND = 'Loco not detected (No ACK)' + #0; // 60 characters limit + STR_ERROR_SHORT_ACK = 'Ack pulse too short' + #0; // 60 characters limit + STR_ERROR_INVALID_CV = 'Invalid CV' + #0; // 60 characters limit + STR_ERROR_SHORT_CIRCUIT = 'Overcurrent detected' + #0; // 60 characters limit + STR_INVALID_PROGRAMMING_METHOD = 'Programming method not compatible' + #0;// 60 characters limit + NMRA_LONGADDRESS_MASK_BYTE = $C0; NMRA_LONGADDRESS_MASK_WORD = $C000; @@ -557,12 +559,12 @@ begin if NMRABusTxBufferAvailable then begin - Bytes[0] := TRACTION_MANAGE_PROXY_REPLY; // First two bytes are Alias - Bytes[1] := TRACTION_MANAGE_QUERY_REPLY; - Bytes[2] := TRACTION_MANAGE_QUERY_REPLY; - Bytes[3] := TRACTION_MANAGE_QUERY_REPLY; - Bytes[4] := TRACTION_MANAGE_QUERY_REPLY; - Bytes[5] := TRACTION_MANAGE_QUERY_REPLY; + Bytes[0] := 0; // First two bytes are Alias + Bytes[1] := 0; + Bytes[2] := 0; + Bytes[3] := 0; + Bytes[4] := 0; + Bytes[5] := 0; TransmitNMRABusLayerMsg(Node, @CANBuffer, MTI_TRACTION_REPLY, DataBuffer^.Alias, 6, @Bytes, False, $00); end else ReleaseBuffer := False; Modified: trunk/prototypes/mikroPascal/dsPIC33EP256_CommandStation/MemoryMapping.ods =================================================================== (Binary files differ) Modified: trunk/prototypes/mikroPascal/dsPIC33EP256_CommandStation/NMRAnetAppCallbacks.mpas =================================================================== --- trunk/prototypes/mikroPascal/dsPIC33EP256_CommandStation/NMRAnetAppCallbacks.mpas 2013-05-04 19:12:05 UTC (rev 3213) +++ trunk/prototypes/mikroPascal/dsPIC33EP256_CommandStation/NMRAnetAppCallbacks.mpas 2013-05-05 03:01:52 UTC (rev 3214) @@ -38,20 +38,29 @@ HelperFunctions; const - MAX_NODE_CFG_DATA = 512; - MAX_VNODE_CFG_DATA = 1536; - EEPROM_CONFIG_OFFSET = 61; // Start of the Command Station Config Data - EEPROM_CONFIG_MAX_OFFSET = 99; // Last Offset of the Command Station Config Data that is currently _implemented_, the last byte is 255. + MAX_NODE_CFG_DATA = 511; // Command Station Configuration = 2 frames of 256 bytes + MAX_VNODE_CFG_DATA = 1791; // Proxy Configuration = 7 frames of 256 bytes + // Command Station EEPROM Configuration + EEPROM_CONFIG_OFFSET = 128; // Start of the Command Station Specific Config Data + EEPROM_OVERCURRENT_LEVEL = 132; + EEPROM_OVERCURRENT_TIME = 134; + EEPROM_OVERCURRENT_DECTECTED = 136; + EEPROM_CONFIG_MAX_OFFSET = 166; // Last Offset of the Command Station Config Data that is currently _implemented_. + // Command Station EEPROM Debug Configuration EEPROM_DEBUG_CONFG_OFFSET = 256; - EEPROM_DEBUG_MAX_OFFSET = 257; + EEPROM_AUTOALLOCATE_TRAIN_NODES = 256; // Allows turning off the AutoAllocation of vNodes to debug and test software - EEPROM_AUTOALLOCATE_TRAIN_NODES = 256; - - EEPROM_OVERCURRENT_LEVEL = 65; - EEPROM_OVERCURRENT_TIME = 67; - EEPROM_OVERCURRENT_DECTECTED = 69; - + // Proxy Node EEPROM Configuration + EEPROM_PROXY_ADDRESS_REL_OFFSET = 127; // Relative Offset with each Train Proxy EEPROM Space + EEPROM_PROXY_SPEEDSTEPS_REL_OFFSET = 129; // Relative Offset with each Train Proxy EEPROM Space + EEPROM_PROXY_FUNCTION_STATE_REL_OFFSET = 130; // Relative Offset with each Train Proxy EEPROM Space + EEPROM_PROXY_FUNCTION_LATCH_REL_OFFSET = 134; // Relative Offset with each Train Proxy EEPROM Space + EEPROM_PROXY_CONSIST_LIST_REL_OFFSET = 138; // Relative Offset with each Train Proxy EEPROM Space + EEPROM_PROXY_FDI_URL_REL_OFFSET = 512; // Relative Offset with each Train Proxy EEPROM Space + EEPROM_PROXY_CDI_URL_REL_OFFSET = 1024; // Relative Offset with each Train Proxy EEPROM Space + EEPROM_PROXY_CV_REL_OFFSET = 1536; // Relative Offset with each Train Proxy EEPROM Space + CONFIG_OUTPUTMODE_MAIN_TRACK = 0; CONFIG_OUTPUTMODE_SERVICE_MODE = 1; CONFIG_SERVICE_MODE_OPERATIONS_MODE = 0; @@ -83,10 +92,12 @@ function AppCallback_AddressSpacePresent(Node: PNMRAnetNode; AddressSpace: Byte): Boolean; function AppCallback_AddressSpaceReadOnly(Node: PNMRAnetNode; AddressSpace: Byte): Boolean; +function AppCallback_AddressSpaceSize(Node: PNMRAnetNode; AddressSpace: Byte): DWord; -function AppCallback_Configuration_AddressSpaceSize(Node: PNMRAnetNode): DWord; procedure AppCallback_Configuration_Read(Node: PNMRAnetNode; ConfigMemBuffer: PConfigMemBuffer); procedure AppCallback_Configuration_Write(Node: PNMRAnetNode; ConfigMemBuffer: PConfigMemBuffer); +function AppCallback_AddressSpace_Read(Node: PNMRAnetNode; ConfigMemBuffer: PConfigMemBuffer): Boolean; +function AppCallback_AddressSpace_Write(Node: PNMRAnetNode; ConfigMemBuffer: PConfigMemBuffer): Boolean; procedure AppCallback_ConfigMemReadWriteAckReply(Node: PNMRAnetNode; ConfigMemBuffer: PConfigMemBuffer); procedure AppCallback_Configuration_CheckForComplete(Node: PNMRAnetNode; ConfigMemBuffer: PConfigMemBuffer); @@ -122,7 +133,7 @@ // ***************************************************************************** function AppCallback_AddressSpacePresent(Node: PNMRAnetNode; AddressSpace: Byte): Boolean; begin - Result := (AddressSpace <= MSI_CDI) and (AddressSpace >= MSI_ACDI_USER) + Result := (AddressSpace <= MSI_CDI) and (AddressSpace >= MSI_FSI) end; // ***************************************************************************** @@ -141,7 +152,7 @@ MSI_ACDI_USER, // I am not supporting writing to this space, do it through the configuration addresss space MSI_FDI : Result := True else - Result := False; + Result := False; end; end; @@ -160,12 +171,24 @@ //****************************************************************************** // Returns the overall size of the Configuration Data //****************************************************************************** -function AppCallback_Configuration_AddressSpaceSize(Node: PNMRAnetNode): DWord; +function AppCallback_AddressSpaceSize(Node: PNMRAnetNode; AddressSpace: Byte): DWord; begin - if NMRAnetNode_TestStateFlag(Node, NS_VIRTUAL) then - Result := $FFFFFFFF // Result := MAX_VNODE_CFG_DATA // THIS NEEDS TO BE MAX FOR CVs WITH THE HIGH BITs SET + case AddressSpace of + MSI_CONFIG : + begin + if NMRAnetNode_TestStateFlag(Node, NS_VIRTUAL) then + Result := $FFFFFFFF // Result := MAX_VNODE_CFG_DATA // THIS NEEDS TO BE MAX FOR CVs WITH THE HIGH BITs SET + else + Result := MAX_NODE_CFG_DATA + end; + MSI_FDI, + MSI_FSI : + begin + Result := $FFFFFFFF + end else - Result := MAX_NODE_CFG_DATA + Result := 0; + end; end; // ***************************************************************************** @@ -247,6 +270,50 @@ end; // ***************************************************************************** +// Allows overriding Address Space Memory Reads +// Parameters : +// Result : +// ***************************************************************************** +function AppCallback_AddressSpace_Read(Node: PNMRAnetNode; ConfigMemBuffer: PConfigMemBuffer): Boolean; +begin + Result := False; // do the default for the common Address Spaces + if ConfigMemBuffer^.AddressSpace < MSI_ACDI_USER then + begin + case ConfigMemBuffer^.AddressSpace of + MSI_FDI : + begin + end; + MSI_FSI : + begin + end; + end; + Result := True + end +end; + +// ***************************************************************************** +// Allows overriding Address Space Memory Writes +// Parameters : +// Result : +// ***************************************************************************** +function AppCallback_AddressSpace_Write(Node: PNMRAnetNode; ConfigMemBuffer: PConfigMemBuffer): Boolean; +begin + Result := False; // do the default for the common Address Spaces + if ConfigMemBuffer^.AddressSpace < MSI_ACDI_USER then + begin + case ConfigMemBuffer^.AddressSpace of + MSI_FDI : + begin + end; + MSI_FSI : + begin + end; + end; + Result := True + end +end; + +// ***************************************************************************** // Writes the Configuration Memory from the App defined storage device // Node: The Node to write the Configuration Data for // DataTarget : A pointer memory space to read the Configuration Data to, this could be a Datagram, CAN Bytes, etc. The Length defines how much to write @@ -285,36 +352,18 @@ end end; 3: begin - // Basic CV if ConfigMemBuffer^.DataCount = 1 then // Only support 1 CV for now begin if CommandStationConfigurationInRam.OutputMode = CONFIG_OUTPUTMODE_SERVICE_MODE then begin - if CommandStationConfigurationInRam.ProgrammingMode <> CONFIG_SERVICE_MODE_OPERATIONS_MODE then - begin - case CommandStationConfigurationInRam.ProgrammingMode of - CONFIG_SERVICE_MODE_AUTO_DETECT : begin ServiceModeInfo.ServiceModeResult := SERVICE_MODE_RESULT_NO_ACK; ServiceModeInfo.iStateMachine := STATE_SERVICEMODE_RESULTS_READY end; - CONFIG_SERVICE_MODE_DIRECT_BYTE_BY_BIT, - CONFIG_SERVICE_MODE_DIRECT_BYTE : ServiceMode_EngageServiceMode(@Programming, True, SERVICEMODE_WRITE, SERVICE_MODE_TYPE_DIRECT_BYTE, (ConfigMemBuffer^.Address and $000007FF), ConfigMemBuffer^.DataBytes[0], 0); - CONFIG_SERVICE_MODE_PAGED : ServiceMode_EngageServiceMode(@Programming, True, SERVICEMODE_WRITE, SERVICE_MODE_TYPE_PAGED, (ConfigMemBuffer^.Address and $000007FF), ConfigMemBuffer^.DataBytes[0], 0); - CONFIG_SERVICE_MODE_REGISTER : ServiceMode_EngageServiceMode(@Programming, True, SERVICEMODE_WRITE, SERVICE_MODE_TYPE_REGISTER, (ConfigMemBuffer^.Address and $000007FF), ConfigMemBuffer^.DataBytes[0], 0); - end; - - while not ServiceMode_ResultsReady do - Delay_ms(100); - ServiceMode_Quit; - - if ServiceModeInfo.ServiceModeResult and SERVICE_MODE_RESULT_ERROR_CODE_SET = SERVICE_MODE_RESULT_ERROR_CODE_SET then - begin end - // Service Mode Error Occured = Error - else - begin - // Service Mode Succeeded - end; - end else - begin - // Trying to use Ops Mode while CS is in Service Output Mode = Error + case CommandStationConfigurationInRam.ProgrammingMode of + CONFIG_SERVICE_MODE_AUTO_DETECT : begin ServiceModeInfo.ServiceModeResult := SERVICE_MODE_RESULT_NO_ACK; ServiceModeInfo.iStateMachine := STATE_SERVICEMODE_RESULTS_READY end; + CONFIG_SERVICE_MODE_DIRECT_BYTE_BY_BIT, + CONFIG_SERVICE_MODE_DIRECT_BYTE : ServiceMode_EngageServiceMode(@Programming, True, SERVICEMODE_WRITE, SERVICE_MODE_TYPE_DIRECT_BYTE, (ConfigMemBuffer^.Address and $000007FF), ConfigMemBuffer^.DataBytes[0], 0); + CONFIG_SERVICE_MODE_PAGED : ServiceMode_EngageServiceMode(@Programming, True, SERVICEMODE_WRITE, SERVICE_MODE_TYPE_PAGED, (ConfigMemBuffer^.Address and $000007FF), ConfigMemBuffer^.DataBytes[0], 0); + CONFIG_SERVICE_MODE_REGISTER : ServiceMode_EngageServiceMode(@Programming, True, SERVICEMODE_WRITE, SERVICE_MODE_TYPE_REGISTER, (ConfigMemBuffer^.Address and $000007FF), ConfigMemBuffer^.DataBytes[0], 0); end; + ConfigMemBuffer^.State := ConfigMemBuffer^.State or CBS_PROCESSING; // AppCallback_Configuration_CheckForComplete called until this is cleared end else begin // CS is in Main Line Output Mode @@ -324,11 +373,13 @@ end else begin // Trying to use Service Mode while CS is in Main Line Mode = Error + ConfigMemBuffer^.ErrorCode := (CONFIG_MEM_RESULT_TERMINATE[0] shl 8) or CONFIG_MEM_RESULT_TERMINATE[1]; + ConfigMemBuffer^.ErrorString := PConfigMemDataErrorStr( @STR_INVALID_PROGRAMMING_METHOD); end end; ByteToStr((ConfigMemBuffer^.Address and $000007FF), s1); UART_Write_Text('Single Indexed CV Write: CV' + s1 + LF); - PrintServiceModeResults; + // PrintServiceModeResults; end else begin // Trying to access more than 1 CV at a time = Error for now @@ -383,34 +434,14 @@ begin if CommandStationConfigurationInRam.OutputMode = CONFIG_OUTPUTMODE_SERVICE_MODE then begin - if CommandStationConfigurationInRam.ProgrammingMode <> CONFIG_SERVICE_MODE_OPERATIONS_MODE then - begin - case CommandStationConfigurationInRam.ProgrammingMode of - CONFIG_SERVICE_MODE_AUTO_DETECT : begin ServiceModeInfo.ServiceModeResult := SERVICE_MODE_RESULT_NO_ACK; ServiceModeInfo.iStateMachine := STATE_SERVICEMODE_RESULTS_READY end; - CONFIG_SERVICE_MODE_DIRECT_BYTE_BY_BIT : ServiceMode_EngageServiceMode(@Programming, True, SERVICEMODE_READ, SERVICE_MODE_TYPE_DIRECT_BIT, (ConfigMemBuffer^.Address and $000007FF), $FF, 0); - CONFIG_SERVICE_MODE_DIRECT_BYTE : ServiceMode_EngageServiceMode(@Programming, True, SERVICEMODE_READ, SERVICE_MODE_TYPE_DIRECT_BYTE, (ConfigMemBuffer^.Address and $000007FF), $FF, 0); - CONFIG_SERVICE_MODE_PAGED : ServiceMode_EngageServiceMode(@Programming, True, SERVICEMODE_READ, SERVICE_MODE_TYPE_PAGED, (ConfigMemBuffer^.Address and $000007FF), $FF, 0); - CONFIG_SERVICE_MODE_REGISTER : ServiceMode_EngageServiceMode(@Programming, True, SERVICEMODE_READ, SERVICE_MODE_TYPE_REGISTER, (ConfigMemBuffer^.Address and $000007FF), $FF, 0); - end; - - while not ServiceMode_ResultsReady do - Delay_ms(100); - ServiceMode_Quit; - - if ServiceModeInfo.ServiceModeResult and SERVICE_MODE_RESULT_ERROR_CODE_SET = SERVICE_MODE_RESULT_ERROR_CODE_SET then - begin - // Service Mode Error Occured = Error - end else - begin - // Service Mode Succeeded - ConfigMemBuffer^.DataBytes[0] := ServiceModeInfo.Value; - end; - end else - begin - // Trying to use Ops Mode while CS is in Service Output Mode = Error - ConfigMemBuffer^.ErrorCode := (CONFIG_MEM_RESULT_TERMINATE[0] shl 8) or CONFIG_MEM_RESULT_TERMINATE[1]; - ConfigMemBuffer^.ErrorString := @STR_INVALID_PROGRAMMING_METHOD; + case CommandStationConfigurationInRam.ProgrammingMode of + CONFIG_SERV... [truncated message content] |