From: <jim...@us...> - 2013-02-04 04:26:59
|
Revision: 2979 http://openlcb.svn.sourceforge.net/openlcb/?rev=2979&view=rev Author: jimkueneman626 Date: 2013-02-04 04:26:46 +0000 (Mon, 04 Feb 2013) Log Message: ----------- Updated mikroPascal Library to handle custom Address Spaces better, updated all mikroPascal project to compile with changes. Fixed bugs in OLCB Commander 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/NMRAnetDCC.mpas trunk/prototypes/mikroPascal/Library/NMRAnetDCCSystem/NMRAnetServiceMode.mpas trunk/prototypes/mikroPascal/dsPIC33EP_CommandStation/NMRAnetAppCallbacks.mpas trunk/prototypes/mikroPascal/dsPIC33EP_CommandStation/NMRAnetAppDefines.mpas trunk/prototypes/mikroPascal/dsPIC33EP_CommandStation/Options.inc trunk/prototypes/mikroPascal/dsPIC33EP_CommandStation/dsPIC33EP_NMRABusCommandStation.hex trunk/prototypes/mikroPascal/dsPIC33EP_CommandStation/dsPIC33EP_NMRABusCommandStation.mppds trunk/prototypes/mikroPascal/dsPIC33EP_CommandStation/dsPIC33EP_NMRAnetCommandStation.mpas trunk/prototypes/mikroPascal/dsPIC33EP_CommandStation/dsPIC33F_CommandStation.xml trunk/prototypes/mikroPascal/dsPIC33EP_CommandStation/dsPIC33F_ProxyNode.xml 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_common_tasks.pas trunk/scratchpads/jkueneman/Library/olcb_node.pas trunk/scratchpads/jkueneman/Library/olcb_threaded_stack.pas trunk/scratchpads/jkueneman/OlcbCommander/Compiled_Binaries/i386-darwin/OlcbCommander trunk/scratchpads/jkueneman/OlcbCommander/Compiled_Binaries/i386-win32/OlcbCommander.exe trunk/scratchpads/jkueneman/OlcbCommander/OLCB_Commander.lpi trunk/scratchpads/jkueneman/OlcbCommander/OLCB_Commander.lps trunk/scratchpads/jkueneman/OlcbCommander/form_awesome_throttle.pas trunk/scratchpads/jkueneman/OlcbCommander/form_config_mem_viewer.pas trunk/scratchpads/jkueneman/OlcbCommander/form_main.lfm trunk/scratchpads/jkueneman/OlcbCommander/form_main.pas trunk/scratchpads/jkueneman/OlcbCommander/form_settings.lfm trunk/scratchpads/jkueneman/OlcbCommander/form_settings.pas Added Paths: ----------- trunk/prototypes/mikroPascal/Library/NMRAnetDCCSystem/DirectServiceMode.mpas trunk/prototypes/mikroPascal/dsPIC33EP_CommandStation/MemoryMapping.ods Property Changed: ---------------- trunk/scratchpads/jkueneman/Hardware/LCBlocks/ Modified: trunk/prototypes/mikroPascal/Library/NMRAnet/NMRAnetDefinesShared.mpas =================================================================== --- trunk/prototypes/mikroPascal/Library/NMRAnet/NMRAnetDefinesShared.mpas 2013-02-03 20:25:09 UTC (rev 2978) +++ trunk/prototypes/mikroPascal/Library/NMRAnet/NMRAnetDefinesShared.mpas 2013-02-04 04:26:46 UTC (rev 2979) @@ -23,6 +23,11 @@ const LF = #13+#10; + +const + CV_READWRITE_MODE_ADDRESS = 0; // CV's are then indexed 1-MAX_DCC_CV_ADDRESSES_SUPPORTED + MAX_DCC_CV_ADDRESSES_SUPPORTED = 512; + // ***************************************************************************** // Shared Protocol Identification Protocol Defines @@ -87,6 +92,7 @@ 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_CvDI = $F9; // MemorySpaceIdentifer - Access the CV Definition Information (CvDI) 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-02-03 20:25:09 UTC (rev 2978) +++ trunk/prototypes/mikroPascal/Library/NMRAnet/NMRAnetNode.mpas 2013-02-04 04:26:46 UTC (rev 2979) @@ -315,11 +315,12 @@ 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 + if i > 0 then + NMRAnetNode_SetStateFlag(@Nodes.RawList[i], NS_ALLOCATED or NS_VIRTUAL); AppCallback_AssignConfigurationAddress(@Nodes.RawList[i], i); AppCallback_AssignRAMAddress(@Nodes.RawList[i], i); end; Node := NMRAnetNode_Allocate; // Allocate the Physical Node - Node^.State := Node^.State and not NS_VIRTUAL; end; // ***************************************************************************** @@ -339,12 +340,13 @@ begin Result := @Nodes.RawList[Nodes.AllocatedCount]; NMRAnetStateMachine_InitializeNode(Result, 0, 0); // The NodeID was already created in the initialization - NMRAnetNode_SetStateFlag(Result, NS_ALLOCATED or NS_VIRTUAL); + if Result <> @Nodes.RawList[0] then + NMRAnetNode_SetStateFlag(Result, NS_ALLOCATED or NS_VIRTUAL); Nodes.AllocatedList[Nodes.AllocatedCount] := Result; Result^.Info.AliasID := NMRAnetUtilities_CreateAliasID(Result^.Info.Seed, False); // Pregenerate it so it can be sorted Inc(Nodes.AllocatedCount); + AppCallback_NodeAllocate(Result); NMRAnetNode_SortNodeList(Nodes); - AppCallback_NodeAllocate(Result); end; end; Modified: trunk/prototypes/mikroPascal/Library/NMRAnet/NMRAnetStateMachine.mpas =================================================================== --- trunk/prototypes/mikroPascal/Library/NMRAnet/NMRAnetStateMachine.mpas 2013-02-03 20:25:09 UTC (rev 2978) +++ trunk/prototypes/mikroPascal/Library/NMRAnet/NMRAnetStateMachine.mpas 2013-02-04 04:26:46 UTC (rev 2979) @@ -59,18 +59,30 @@ function NMRAnetStateMachine_TrySendVerifyNodeID(Node: PNMRAnetNode; DestinationAliasID: Word): Boolean; function NMRAnetStateMachine_TrySendAbbreviatedCDI(Node: PNMRAnetNode; DestinationAliasID: Word): Boolean; function NMRAnetStateMachine_TrySendDatagram(Node: PNMRAnetNode; CANBuffer: PCANBuffer; Datagram: PDatagramBuffer): Boolean; - + + function AppCallback_StateMachine(Node: PNMRAnetNode; CANBuffer: PCANBuffer; DataBytesPtr: PCAN_DataBytes): Boolean; external; procedure NMRAnetAppCallbacks_Initialize; external; - function AppCallback_ConfigurationRead(Node: PNMRAnetNode; DataTarget: ^Byte; StartAddress: DWord; MaxCount: Byte): Byte; external; - procedure AppCallback_ConfigurationWrite(Node: PNMRAnetNode; DataTarget: ^Byte; StartAddress: DWord; MaxCount: Byte); external; - function AppCallback_ConfigurationSize(Node: PNMRAnetNode): Word; external; - function AppCallback_StateMachine(Node: PNMRAnetNode; CANBuffer: PCANBuffer; DataBytesPtr: PCAN_DataBytes): Boolean; external; + + // Address Space Support + // *************************************************************************** + function AppCallback_AddressSpacePresent(Node: PNMRAnetNode; AddressSpace: Byte): Boolean; external; + function AppCallback_AddressSpaceReadOnly(Node: PNMRAnetNode; AddressSpace: Byte): Boolean; external; + + function AppCallback_Configuration_AddressSpaceSize(Node: PNMRAnetNode): Word; external; + function AppCallback_Configuration_Read(Node: PNMRAnetNode; DataTarget: ^Byte; StartAddress: DWord; MaxCount: Byte): Byte; external; + procedure AppCallback_Configuration_Write(Node: PNMRAnetNode; DataTarget: ^Byte; StartAddress: DWord; MaxCount: Byte); external; + {$IFDEF SUPPORT_FDI} - function AppCallback_FDI_ConfigurationSize(Node: PNMRAnetNode): Word; external; + function AppCallback_FDI_AddressSpaceSize(Node: PNMRAnetNode): Word; external; procedure AppCallback_FDI_Write(Node: PNMRAnetNode; DataTarget: ^Byte; StartAddress: DWord; MaxCount: Byte); external; function AppCallback_FDI_Read(Node: PNMRAnetNode; DataTarget: ^Byte; StartAddress: DWord; MaxCount: Byte): Byte; external; {$ENDIF} - + {$IFDEF SUPPORT_CvDI} + function AppCallback_CvDI_AddressSpaceSize(Node: PNMRAnetNode): Word; external; + procedure AppCallback_CvDI_Write(Node: PNMRAnetNode; DataTarget: ^Byte; StartAddress: DWord; MaxCount: Byte); external; + function AppCallback_CvDI_Read(Node: PNMRAnetNode; DataTarget: ^Byte; StartAddress: DWord; MaxCount: Byte): Byte; external; + {$ENDIF} + // Address Space Support // Forward declarations @@ -443,6 +455,12 @@ function MaxAddressByAddressSpace(Node: PNMRAnetNode; AddressSpace: Byte): DWord; begin case AddressSpace of + {$IFDEF SUPPORT_FDI} + MSI_FDI : Result := AppCallback_FDI_AddressSpaceSize(Node); + {$ENDIF} // SUPPORT_FDI + {$IFDEF SUPPORT_FDI} + MSI_CvDI : Result := AppCallback_CvDI_AddressSpaceSize(Node); + {$ENDIF} // SUPPORT_CvDI MSI_CDI : begin {$IFDEF SUPPORT_VIRTUAL_NODES} if Node^.State and NS_VIRTUAL <> 0 then @@ -450,13 +468,8 @@ else {$ENDIF} Result := MAX_CDI_ARRAY; end; - {$IFDEF SUPPORT_FDI} - MSI_FDI : begin - Result := AppCallback_FDI_ConfigurationSize(Node); - end; - {$ENDIF} // SUPPORT_FDI MSI_ALL : Result := ALL_MAP.HighMem; - MSI_CONFIG : Result := AppCallback_ConfigurationSize(Node); + MSI_CONFIG : Result := AppCallback_Configuration_AddressSpaceSize(Node); MSI_ACDI_MFG : begin {$IFDEF SUPPORT_VIRTUAL_NODES} if Node^.State and NS_VIRTUAL <> 0 then @@ -464,7 +477,9 @@ else {$ENDIF} Result := MAX_ACDI_MFG_ARRAY + 1 // for the Version ID Byte end; - MSI_ACDI_USER : Result := AppCallback_ConfigurationSize(Node) + 1 // for the Version ID Byte + MSI_ACDI_USER : begin + Result := MAX_USER_CONFIG_DATA + 1 // for the Version ID Byte + end else Result := 0; end; @@ -650,7 +665,7 @@ if BaseBuffer^.Tag < MAX_USER_NAME then begin // Very wasteful and slow 1 at a time but it is easy - AppCallback_ConfigurationRead(Node, @DataBytes[i], BaseBuffer^.Tag, 1); + AppCallback_Configuration_Read(Node, @DataBytes[i], BaseBuffer^.Tag, 1); if DataBytes[i] = #0 then BaseBuffer^.StateMachine := STATE_ACDI_START_DESC else @@ -666,14 +681,14 @@ BaseBuffer^.StateMachine := STATE_ACDI_USER_DESC; end; STATE_ACDI_USER_DESC : begin {$IFDEF TRACE_SNIP}UART1_Write_Text('STATE_ACDI_USER_DESC'+LF); {$ENDIF} - if BaseBuffer^.Tag < MAX_CONFIG_DATA then + if BaseBuffer^.Tag < MAX_USER_CONFIG_DATA then begin // Very wasteful and slow 1 at a time but it is easy - AppCallback_ConfigurationRead(Node, @DataBytes[i], BaseBuffer^.Tag, 1); + AppCallback_Configuration_Read(Node, @DataBytes[i], BaseBuffer^.Tag, 1); if DataBytes[i] = #0 then BaseBuffer^.StateMachine := STATE_ACDI_DONE else - if BaseBuffer^.Tag = MAX_CONFIG_DATA - 1 then + if BaseBuffer^.Tag = MAX_USER_CONFIG_DATA - 1 then DataBytes[i] := #0; Inc(i); Inc(BaseBuffer^.Tag); @@ -819,7 +834,9 @@ end; MCP_OP_GET_ADD_SPACE_INFO : begin DatagramBuffer^.DataBytes[0] := DATAGRAM_TYPE_MEMORY_CONFIGURATION; - DatagramBuffer^.DataBytes[1] := MCP_OP_GET_ADD_SPACE_INFO_REPLY or MCP_OP_GET_ADD_SPACE_INFO_REPLY_PRESENT; // assumption is we support ALL Address Spaces + DatagramBuffer^.DataBytes[1] := MCP_OP_GET_ADD_SPACE_INFO_REPLY; + if AppCallback_AddressSpacePresent(Node, DatagramBuffer^.DataBytes[2]) then + DatagramBuffer^.DataBytes[1] := DatagramBuffer^.DataBytes[1] or MCP_OP_GET_ADD_SPACE_INFO_REPLY_PRESENT; DatagramBuffer^.DataBytes[2] := DatagramBuffer^.DataBytes[2]; // I am not supporting the ability to return anything but a $0 for the lower address so we only deal with offsets from zero in these calls MemorySpaceMaxAddress := MaxAddressByAddressSpace(Node, DatagramBuffer^.DataBytes[2]); @@ -827,11 +844,10 @@ DatagramBuffer^.DataBytes[4] := (DWord(MemorySpaceMaxAddress) shr 16) and $000000FF; DatagramBuffer^.DataBytes[5] := (DWord(MemorySpaceMaxAddress) shr 8) and $000000FF; DatagramBuffer^.DataBytes[6] := DWord(MemorySpaceMaxAddress) and $000000FF; - case DatagramBuffer^.DataBytes[2] of - MSI_CONFIG, MSI_ACDI_USER {$IFDEF SUPPORT_FDI}, MSI_FDI{$ENDIF} : DatagramBuffer^.DataBytes[7] := $00 // Read/Write + if AppCallback_AddressSpaceReadOnly(Node, DatagramBuffer^.DataBytes[2]) then + DatagramBuffer^.DataBytes[7] := $01 else - DatagramBuffer^.DataBytes[7] := $01; // Read Only - end; + DatagramBuffer^.DataBytes[7] := $00; DatagramBuffer^.iByteCount := 8; end; MCP_OP_LOCK : begin @@ -891,19 +907,18 @@ DatagramBuffer^.iByteCount := DatagramBuffer^.iByteCount + MemorySpaceCount; end; {$IFDEF SUPPORT_FDI} - MSI_FDI : begin - DatagramBuffer^.iByteCount := DatagramBuffer^.iByteCount + AppCallback_FDI_Read(Node, @DatagramBuffer^.DataBytes[DatagramAddress], MemorySpaceAddress, MemorySpaceCount); - end; + MSI_FDI : DatagramBuffer^.iByteCount := DatagramBuffer^.iByteCount + AppCallback_FDI_Read(Node, @DatagramBuffer^.DataBytes[DatagramAddress], MemorySpaceAddress, MemorySpaceCount); {$ENDIF} + {$IFDEF SUPPORT_CvDI} + MSI_CvDI : DatagramBuffer^.iByteCount := DatagramBuffer^.iByteCount + AppCallback_CvDI_Read(Node, @DatagramBuffer^.DataBytes[DatagramAddress], MemorySpaceAddress, MemorySpaceCount); + {$ENDIF} MSI_ALL : begin ByteArray := PByteArray( ALL_MAP.LowMem); for i := 0 to MemorySpaceCount - 1 do DatagramBuffer^.DataBytes[i+DatagramAddress] := ByteArray^[i+MemorySpaceAddress]; DatagramBuffer^.iByteCount := DatagramBuffer^.iByteCount + MemorySpaceCount; end; - MSI_CONFIG : begin - DatagramBuffer^.iByteCount := DatagramBuffer^.iByteCount + AppCallback_ConfigurationRead(Node, @DatagramBuffer^.DataBytes[DatagramAddress], MemorySpaceAddress, MemorySpaceCount); - end; + MSI_CONFIG : DatagramBuffer^.iByteCount := DatagramBuffer^.iByteCount + AppCallback_Configuration_Read(Node, @DatagramBuffer^.DataBytes[DatagramAddress], MemorySpaceAddress, MemorySpaceCount); MSI_ACDI_MFG : begin if MemorySpaceAddress = 0 then begin @@ -929,14 +944,15 @@ MSI_ACDI_USER : begin if MemorySpaceAddress = 0 then begin + // This all works because of the Marker Byte defined in EEProm to allow test for initialization. The User Name/Desc are now at index 1 which lines up with this now DatagramBuffer^.DataBytes[DatagramAddress] := ACDI_USER_VERSION; Inc(DatagramAddress); Dec(MemorySpaceCount); Inc(DatagramBuffer^.iByteCount); - end else - Dec(MemorySpaceAddress); // Need to adjust the Address Pointer in subsequent calls to account for the virtual Version Byte - - DatagramBuffer^.iByteCount := DatagramBuffer^.iByteCount + AppCallback_ConfigurationRead(Node, @DatagramBuffer^.DataBytes[DatagramAddress], MemorySpaceAddress, MemorySpaceCount); + end; + + if MemorySpaceCount > 0 then + DatagramBuffer^.iByteCount := DatagramBuffer^.iByteCount + AppCallback_Configuration_Read(Node, @DatagramBuffer^.DataBytes[DatagramAddress], MemorySpaceAddress, MemorySpaceCount); end; end; DatagramBuffer^.Statemachine := STATE_MEM_CONFIG_SEND_RESUSED_DATAGRAM; @@ -955,17 +971,14 @@ MemorySpaceAddress := DWord( DatagramBuffer^.DataBytes[2] shl 24) or DWord( DatagramBuffer^.DataBytes[3] shl 16) or DWord( DatagramBuffer^.DataBytes[4] shl 8) or DWord( DatagramBuffer^.DataBytes[5]); MemorySpaceCount := DatagramBuffer^.iByteCount - DatagramAddress; case MemorySpace of - MSI_CONFIG : begin - AppCallback_ConfigurationWrite(Node, @DatagramBuffer^.DataBytes[DatagramAddress], MemorySpaceAddress, MemorySpaceCount); - end; - MSI_ACDI_USER : begin - UART1_Write_Text('Unimplemented Configuration Mem write'+LF) - end; + MSI_CONFIG : AppCallback_Configuration_Write(Node, @DatagramBuffer^.DataBytes[DatagramAddress], MemorySpaceAddress, MemorySpaceCount); + MSI_ACDI_USER : UART1_Write_Text('Unimplemented Configuration Mem write'+LF); {$IFDEF SUPPORT_FDI} - MSI_FDI : begin - AppCallback_FDI_Write(Node, @DatagramBuffer^.DataBytes[DatagramAddress], MemorySpaceAddress, MemorySpaceCount); - end; + MSI_FDI : AppCallback_FDI_Write(Node, @DatagramBuffer^.DataBytes[DatagramAddress], MemorySpaceAddress, MemorySpaceCount); {$ENDIF} + {$IFDEF SUPPORT_CvDI} + MSI_CvDI : AppCallback_CvDI_Write(Node, @DatagramBuffer^.DataBytes[DatagramAddress], MemorySpaceAddress, MemorySpaceCount); + {$ENDIF} end; DatagramBuffer^.Statemachine := STATE_MEM_CONFIG_REPLY_TO_WRITE_DATAGRAM; end; Added: trunk/prototypes/mikroPascal/Library/NMRAnetDCCSystem/DirectServiceMode.mpas =================================================================== --- trunk/prototypes/mikroPascal/Library/NMRAnetDCCSystem/DirectServiceMode.mpas (rev 0) +++ trunk/prototypes/mikroPascal/Library/NMRAnetDCCSystem/DirectServiceMode.mpas 2013-02-04 04:26:46 UTC (rev 2979) @@ -0,0 +1,419 @@ +unit DirectServiceMode; + +uses + NMRAnetDCC, + NMRAnetServiceMode; + +implementation + +type + TServiceModePowerOnFunc = procedure(BufferPtr: PDCCBufferInfo); + PServiceModePowerOnFunc = ^TServiceModePowerOnFunc; + TServiceModeResetNextStateFunc = procedure(BufferPtr: PDCCBufferInfo); + PServiceModeResetNextStateFunc = ^TServiceModeResetNextStateFunc; + TServiceModeHandleAckDetected = procedure (BufferPtr: PDCCBufferInfo); + PServiceModeHandleAckDetected = ^TServiceModeHandleAckDetected; + TServiceModeRequestNextStateFunc = procedure(BufferPtr: PDCCBufferInfo); + PServiceModeRequestNextStateFunc = ^TServiceModeRequestNextStateFunc; + TServiceModeRequestCurrentStateFunc = procedure(BufferPtr: PDCCBufferInfo; Command: Byte); + PServiceModeRequestCurrentStateFunc = ^TServiceModeRequestCurrentStateFunc; + TServiceModeWriteRecoverNextStateFunc = procedure(BufferPtr: PDCCBufferInfo); + PServiceModeWriteRecoverNextStateFunc = ^TServiceModeWriteRecoverNextStateFunc; + + procedure NextStateAndLoadResetPacket(NextStateMachineIndex: Byte; BufferPtr: PDCCBufferInfo); forward; + +// *************************************************************************** +// procedure ServiceModePowerOn; +// +// Common function that Direct CV Mode calls are started from +// +// Note: that this function expects that ONE RESET MESSAGE HAS ALREADY BEEN SENT before +// this function is entered the first time. +// *************************************************************************** +procedure ServiceModePowerOn(BufferPtr: PDCCBufferInfo; NextStateFunc: PServiceModePowerOnFunc); +begin + Inc(ServiceModeInfo.iInstructionCountSent); // We are always one behind so increment first + if ServiceModeInfo.iInstructionCountSent < SERVICEMODE_POWER_ON_CYCLE_IDLE_COUNT then + begin + Inc(ServiceModeInfo.TotalSent); + NMRA_DCC_LoadIdlePacketIntoTransmitter(BufferPtr, PREAMBLE_BIT_COUNT_SERVICEMODE); + end else + NextStateFunc(BufferPtr); +end; + +// *************************************************************************** +// procedure ServiceModeReset; +// +// Common function that Direct CV Mode calls are started from. +// +// NOTE 1: This function expects that ONE RESET MESSAGE HAS ALREADY BEEN SENT before +// +// this function is entered the first time. +// NOTE 2: The NextStateFunc must load the final ResetPacket, typically using NextStateAndLoadResetPacket +// *************************************************************************** +procedure ServiceModeReset(BufferPtr: PDCCBufferInfo; NextStateFunc: PServiceModeResetNextStateFunc; CycleCount: Byte; NewAck: Boolean); +begin + Inc(ServiceModeInfo.iInstructionCountSent); // We are always one behind so increment first + if ServiceModeInfo.iInstructionCountSent < CycleCount - 1 then // The NextStateFunc is responsible for the final Reset Packet + begin + Inc(ServiceModeInfo.TotalSent); + NMRA_DCC_LoadResetPacketIntoTransmitter(BufferPtr, PREAMBLE_BIT_COUNT_SERVICEMODE); + end else + begin + if NewAck then + ServiceMode_ResetForNewAck; // Get ready for an new Ack run within the sequence + NextStateFunc(BufferPtr); + end +end; + +// *************************************************************************** +// procedure ServiceModeRequest; +// +// Common function that many Direct CV Mode calls are started from +// *************************************************************************** +procedure ServiceModeRequest(BufferPtr: PDCCBufferInfo; NextStateFunc: PServiceModeRequestNextStateFunc; CurrentStateFunc: PServiceModeRequestCurrentStateFunc; AckDetectedFunc: PServiceModeHandleAckDetected; Command: Byte; CycleCount: Byte); +begin + if ServiceModeInfo.iInstructionCountSent = 2 then // Start looking for an ACK from the decoder after the packet sent to the decoder + ServiceModeInfo.Flags.PROGRAMMING_ACK_STATE_SCAN_FOR_ACK_BIT := 1; + + if ServiceModeInfo.Flags.PROGRAMMING_ACK_STATE_DETECTED_BIT = 1 then // Break off once a ACK is detected + AckDetectedFunc(BufferPtr) + else begin + Inc(ServiceModeInfo.iInstructionCountSent); // We are always one behind so increment first + if ServiceModeInfo.iInstructionCountSent >= CycleCount then + begin + NextStateFunc(BufferPtr); + ServiceModeInfo.iInstructionCountSent := 0 + end else + CurrentStateFunc(BufferPtr, Command) // What to do for the Service Mode Request + end; +end; + +// *************************************************************************** +// procedure ServiceModeSendResetPackets; +// +// Just loops keeping the decoder in Service Mode +// *************************************************************************** +procedure ServiceModeSendResetPackets(BufferPtr: PDCCBufferInfo); +begin + NMRA_DCC_LoadResetPacketIntoTransmitter(BufferPtr, PREAMBLE_BIT_COUNT_SERVICEMODE); +end; + +// *************************************************************************** +// procedure ServiceModeSequenceComplete; +// +// Ready for the main loop to report back what occured during the Service Mode attempt +// This will continue to be called until a new Service Mode commmand is moved from +// the queue to the buffer. It keep the decoder in service mode by sending Resets +// *************************************************************************** +procedure ServiceModeSequenceComplete(BufferPtr: PDCCBufferInfo); +begin + ServiceModeInfo.Buffer.DeviceCache.Address := ServiceModeInfo.ScratchBuffer.Address; // Restore the raw address + ServiceModeInfo.Flags.PROGRAMMING_ACK_STATE_RESPONSE_READY_BIT := 1; // It is ready one way or another (No Loco or the Ack Timer already set it to 1) + NextStateAndLoadResetPacket(STATE_SERVICEMODE_SEND_RESET_PACKETS, BufferPtr); // Keep the decoder in Service Mode +end; + +// *************************************************************************** +// procedure ServiceModeNotSupported; +// +// Direct CV Mode is not supported (or problems occured) +// *************************************************************************** +procedure ServiceModeNotSupported(BufferPtr: PDCCBufferInfo); +begin + NextStateAndLoadResetPacket(STATE_SERVICEMODE_SEQUENCE_COMPLETE, BufferPtr); // TEMPORARY NEED TO TRY PAGED MODE +end; + +// *************************************************************************** +// procedure NextStateAndLoadResetPacket +// +// General use function to reset variables and move to the next statemachine +// state +// *************************************************************************** +procedure NextStateAndLoadResetPacket(NextStateMachineIndex: Byte; BufferPtr: PDCCBufferInfo); +begin + ServiceModeInfo.iStateMachine := NextStateMachineIndex; + ServiceModeInfo.iInstructionCountSent := 0; + NMRA_DCC_LoadResetPacketIntoTransmitter(BufferPtr, PREAMBLE_BIT_COUNT_SERVICEMODE); + Inc(ServiceModeInfo.TotalSent); +end; + +// *************************************************************************** +// procedure Direct_AckDetectedFunc; +// +// Called in response to a positive acknowledgement of a Direct Service Mode Request +// PROGRAMMING_ACK_STATE_NMRA_DCC_DETECTED_BIT has been set by the 5ms timer +// *************************************************************************** +procedure Direct_AckDetectedFunc(BufferPtr: PDCCBufferInfo); +var + State: Byte; +begin + if ServiceModeInfo.Buffer.Mode and $0F > SERVICE_MODE_COMMAND_MAX_VERIFY then // Is it a Verify or Write Ack? + State := STATE_SERVICEMODE_DIRECT_WRITE_RECOVER_CYCLE // A Write needs a Recover Cycle + else + State := STATE_SERVICEMODE_SEQUENCE_COMPLETE; // A Verify can just end + NextStateAndLoadResetPacket(State, BufferPtr); + ServiceModeInfo.ServiceModeResult := SERVICE_MODE_RESULT_RESPONSE_DIRECT_MODE; +end; + +// *************************************************************************** +// procedure Direct_AckDetectedSupportedTestFunc; +// +// Called in response to a positive acknowledgement of a Direct Service Mode availablity test +// PROGRAMMING_ACK_STATE_NMRA_DCC_DETECTED_BIT has been set by the 5ms timer +// *************************************************************************** +procedure Direct_AckDetectedSupportedTestFunc(BufferPtr: PDCCBufferInfo); +begin + {$IFNDEF DISABLE_BYTE_BY_BIT_DIRECT_SERVICEMODE} + if ServiceModeInfo.DirectSupportTest <= SERVICE_MODE_DIRECT_TEST_BIT_ONE_MODE then // Was it a Bit Test Command? + ServiceModeInfo.Flags.PROGRAMMING_ACK_STATE_BITMODE_AVAILABLE := 1; // Bit Mode is available else Byte Mode is available + {$ENDIF DISABLE_BYTE_BY_BIT_DIRECT_SERVICEMODE} + NextStateAndLoadResetPacket(STATE_SERVICEMODE_DIRECT_RESET_CYCLE, BufferPtr); // Reset Cycle requires this preloaded Reset Packet +end; + +// *************************************************************************** +// procedure Direct_AckDetectedByteByBitFunc; +// +// Called in response to a positive acknowledgement of a Direct Service Mode +// when using Bit Mode to quickly read a Byte when available +// PROGRAMMING_ACK_STATE_NMRA_DCC_DETECTED_BIT has been set by the 5ms timer +// *************************************************************************** +procedure Direct_AckDetectedByteByBitFunc(BufferPtr: PDCCBufferInfo); +var + Offset: Byte; +begin + Offset := ServiceModeInfo.Buffer.DeviceCache.Value and %00000111; // Extract the Bit Offset that was tested + ServiceModeInfo.ScratchBuffer.Value.Offset := ServiceModeInfo.Buffer.DeviceCache.Value.3; // Copy the Tested bit into the Offset in the Resulting Byte + if ServiceModeInfo.Buffer.DeviceCache.Value and %00000111 = 0 then // Have we tested all 8 Bits yet? + begin // Yes we are done + ServiceModeInfo.Buffer.DeviceCache.Value := ServiceModeInfo.ScratchBuffer.Value; // Copy the Result to the output + ServiceModeInfo.ServiceModeResult := SERVICE_MODE_RESULT_RESPONSE_DIRECT_MODE; // Tell the main loop the read was successful + NextStateAndLoadResetPacket(STATE_SERVICEMODE_SEQUENCE_COMPLETE, BufferPtr); // Spin until the main loop dispatches the result + end else + begin // No move to the next lower bit offset + Dec(ServiceModeInfo.Buffer.DeviceCache.Value); // Move to the next Bit Index + ServiceModeInfo.Buffer.DeviceCache.Value.3 := 0; // Start off by testing for a 0 + NextStateAndLoadResetPacket(STATE_SERVICEMODE_DIRECT_BYTEMODE_BY_BITS_RESET, BufferPtr); // Run a Reset Sequence before the next byte + end; +end; + + +// *************************************************************************** +// procedure Direct_TestBitNextStateFunc; +// +// Called in response to no acknowledgement of a Direct Service Mode test +// for the Manufacturing ID CV Bit 7 = 0 +// *************************************************************************** +procedure Direct_TestBitNextStateFunc(BufferPtr: PDCCBufferInfo); +begin + Inc(ServiceModeInfo.DirectSupportTest); // Next Test Mode + NextStateAndLoadResetPacket(STATE_SERVICEMODE_RESET_CYCLE, BufferPtr) // Try again +end; + +// *************************************************************************** +// procedure Direct_TestByteNextStateFunc; +// +// Called in response to no acknowledgement of a Direct Service Mode test +// for the Manufacturing ID CV Byte. If this fails then the decoder does not +// support Direct Mode +// *************************************************************************** +procedure Direct_TestByteNextStateFunc(BufferPtr: PDCCBufferInfo); +begin + NextStateAndLoadResetPacket(STATE_SERVICEMODE_NOT_SUPPORTED, BufferPtr) // Direct Mode Failed +end; + +// *************************************************************************** +// procedure Direct_RequestNextStateFunc; +// +// Called in response to no acknowledgement of a Direct Service Mode request +// on the deocoder. Exit the sequence, the fail flag has been set by the +// Service Mode timer +// *************************************************************************** +procedure Direct_RequestNextStateFunc(BufferPtr: PDCCBufferInfo); +begin + NextStateAndLoadResetPacket(STATE_SERVICEMODE_SEQUENCE_COMPLETE, BufferPtr) +end; + +// *************************************************************************** +// procedure Direct_ByteVerifyNextStateFunc; +// +// Called in response to no acknowledgement of a Direct Service Mode request +// to Verify a CV. It will be called up to 255 time or until the decoder +// acknowledges +// *************************************************************************** +procedure Direct_ByteVerifyNextStateFunc(BufferPtr: PDCCBufferInfo); +var + State: Byte; +begin + if ServiceModeInfo.Buffer.DeviceCache.Value = 255 then + State := STATE_SERVICEMODE_SEQUENCE_COMPLETE // Questions have run out without an acknowledgement, give up + else begin + Inc(ServiceModeInfo.Buffer.DeviceCache.Value); // Have not run all 255 Registers yet keep going + ServiceModeInfo.iInstructionCountSent := 0; + State := STATE_SERVICEMODE_DIRECT_RESET_CYCLE // Run the Rest packet sequence first then try the new Value + end; + NextStateAndLoadResetPacket(State, BufferPtr) +end; + +// *************************************************************************** +// procedure Direct_ByteByBitNextStateFunc; +// +// Called in response to not receiving an Ack when using Bit Mode to read a Byte +// *************************************************************************** +procedure Direct_ByteByBitNextStateFunc(BufferPtr: PDCCBufferInfo); +var + State: Byte; +begin + if ServiceModeInfo.Buffer.DeviceCache.Value.3 = 0 then + begin + ServiceModeInfo.Buffer.DeviceCache.Value.3 := 1; // See if the bit is a "1" + State := STATE_SERVICEMODE_DIRECT_BYTEMODE_BY_BITS_RESET // Run the Reset Packet Sequence before trying the next bit + end else + State := STATE_SERVICEMODE_SEQUENCE_COMPLETE; // Failed somewhere in the 8 bits + NextStateAndLoadResetPacket(State, BufferPtr); +end; + +// *************************************************************************** +// procedure Direct_PowerOnNextStateFunc; +// +// Called in response to finishing the Power On Cycle +// *************************************************************************** +procedure Direct_PowerOnNextStateFunc(BufferPtr: PDCCBufferInfo); +begin + ServiceModeInfo.DirectSupportTest := SERVICE_MODE_DIRECT_TEST_BIT_ZERO_MODE; // Setup to track what test we are in + ServiceModeInfo.Flags.PROGRAMMING_ACK_STATE_BITMODE_AVAILABLE := 0; // Assume not available + NextStateAndLoadResetPacket(STATE_SERVICEMODE_RESET_CYCLE, BufferPtr); +end; + +// *************************************************************************** +// procedure Direct_ResetAndTestNextStateFunc; +// +// Called in response to the Command Station placing the decoder into +// Service Mode +// *************************************************************************** +procedure Direct_ResetAndTestNextStateFunc(BufferPtr: PDCCBufferInfo); +var + Next: Byte; +begin + if ServiceModeInfo.DirectSupportTest = SERVICE_MODE_DIRECT_TEST_BIT_ZERO_MODE then // When the Buffer is loaded the original Address and Value are copied into the ServiceModeInfo.ScratchBuffer structure + begin + ServiceModeInfo.Buffer.DeviceCache := MFG_CV_ID_BIT_7_EQUALS_ZERO; // Set up to Verify a 0 in Bit 7 of CV 8 + Next := STATE_SERVICEMODE_DIRECT_MODE_BIT_TEST; + end else + if ServiceModeInfo.DirectSupportTest = SERVICE_MODE_DIRECT_TEST_BIT_ONE_MODE then + begin + ServiceModeInfo.Buffer.DeviceCache := MFG_CV_ID_BIT_7_EQUALS_ONE; // Set up to Verify a 1 in Bit 7 of CV 8 + Next := STATE_SERVICEMODE_DIRECT_MODE_BIT_TEST; + end else + begin + ServiceModeInfo.Buffer.DeviceCache := MFG_CV_ID; // Set up to Verify CV 8 + Next := STATE_SERVICEMODE_DIRECT_MODE_BYTE_TEST; + end; + NextStateAndLoadResetPacket(Next, BufferPtr); +end; + +// *************************************************************************** +// procedure Direct_ResetAndDispatchNextStateFunc; +// +// Called in response after the decoder responded to tests to see if it implements +// Direct Bit and/or Byte Mode. If Bit Mode is implemented it is assumed Byte +// Mode is also implemented. +// *************************************************************************** +procedure Direct_ResetAndDispatchNextStateFunc(BufferPtr: PDCCBufferInfo); +var + State: Byte; +begin + ServiceModeInfo.Buffer.DeviceCache := ServiceModeInfo.ScratchBuffer; // Restore the original request + + if ServiceModeInfo.Buffer.Mode and $0F = SERVICE_MODE_COMMMAND_WRITE_BYTE then + State := STATE_SERVICEMODE_DIRECT_BYTEMODE_WRITE + else + if ServiceModeInfo.Buffer.Mode and $0F = SERVICE_MODE_COMMMAND_VERIFY_BYTE then + begin + if ServiceModeInfo.Flags.PROGRAMMING_ACK_STATE_BITMODE_AVAILABLE = 1 then + begin + State := STATE_SERVICEMODE_DIRECT_BYTEMODE_BY_BITS_VERIFY; + ServiceModeInfo.Buffer.DeviceCache.Value := %11100111; // Bit Verify, Bit = 0, Bit Index = 7, count backwards + end else + State := STATE_SERVICEMODE_DIRECT_BYTEMODE_VERIFY + end else + State := STATE_SERVICEMODE_DIRECT_BITMODE; // The Buffer.Value is already in the correct format (including the Verify/Write Bit) + NextStateAndLoadResetPacket(State, BufferPtr); +end; + +// *************************************************************************** +// procedure Direct_ByteModeByBitsResetNextStateFunc; +// +// Called when the Byte by Bit Reset runs its course, it much load the last +// Reset Packet +// *************************************************************************** +procedure Direct_ByteModeByBitsResetNextStateFunc(BufferPtr: PDCCBufferInfo); +begin + NextStateAndLoadResetPacket(STATE_SERVICEMODE_DIRECT_BYTEMODE_BY_BITS_VERIFY, BufferPtr); +end; + +// *************************************************************************** +// procedure Direct_RequestCurrentStateFunc; +// +// Called during a Direct Mode Request to send the actual request before it is +// acknowledged +// *************************************************************************** +procedure Direct_RequestCurrentStateFunc(BufferPtr: PDCCBufferInfo; Command: Byte); +var + i: Integer; +begin + BufferPtr^.TX_TransmittingPacket.PacketBytes[0] := Command or (Hi(ServiceModeInfo.Buffer.DeviceCache.Address) and %00000011); + BufferPtr^.TX_TransmittingPacket.PacketBytes[1] := Lo(ServiceModeInfo.Buffer.DeviceCache.Address); + BufferPtr^.TX_TransmittingPacket.PacketBytes[2] := ServiceModeInfo.Buffer.DeviceCache.Value; + if Command and %00001100 = %00001000 then // Is Bit Manipulation instruction? + BufferPtr^.TX_TransmittingPacket.PacketBytes[2] := %11100000 or BufferPtr^.TX_TransmittingPacket.PacketBytes[2]; // Buffer.Value must be in NMRA form xxxKDBBB where K = Read/Verify, D = Value to Read/Verify, BBB = the Bit Index to Read/Verify + BufferPtr^.TX_TransmittingPacket.Flags := 3; + BufferPtr^.TX_XOR_Byte := 0; + for i := 0 to 2 do + BufferPtr^.TX_XOR_Byte := BufferPtr^.TX_XOR_Byte xor BufferPtr^.TX_TransmittingPacket.PacketBytes[i]; + BufferPtr^.TX_PreambleBitCount := PREAMBLE_BIT_COUNT_SERVICEMODE; + Inc(ServiceModeInfo.TotalSent); +end; + +// *************************************************************************** +// procedure Direct_WriteRecoveryNextStateFunc; +// +// Called when the Write Recovery Reset Packets have completed +// *************************************************************************** +procedure Direct_WriteRecoveryNextStateFunc(BufferPtr: PDCCBufferInfo); +begin + NextStateAndLoadResetPacket(STATE_SERVICEMODE_SEQUENCE_COMPLETE, BufferPtr); +end; + +// *************************************************************************** +// procedure ServiceMode_Direct_Func +// +// Parameters: None +// +// Result: None +// +// Description: +// StateMachine that handles a Direct CV Service Mode Programmming sequence +// per the S9.2.3 spec +// +// *************************************************************************** +procedure NMRA_DCC_DirectServiceModeStateMachine(BufferPtr: PDCCBufferInfo); +begin + case ServiceModeInfo.iStateMachine of + STATE_SERVICEMODE_POWER_ON_CYCLE : ServiceModePowerOn(BufferPtr, @Direct_PowerOnNextStateFunc); + STATE_SERVICEMODE_RESET_CYCLE : ServiceModeReset(BufferPtr, @Direct_ResetAndTestNextStateFunc, SERVICEMODE_POWER_ON_CYCLE_RESET_COUNT, True); + STATE_SERVICEMODE_DIRECT_MODE_BIT_TEST : ServiceModeRequest(BufferPtr, @Direct_TestBitNextStateFunc, @Direct_RequestCurrentStateFunc, @Direct_AckDetectedSupportedTestFunc, %01111000, SERVICEMODE_INSTRUCTION_COUNT); + STATE_SERVICEMODE_DIRECT_MODE_BYTE_TEST : ServiceModeRequest(BufferPtr, @Direct_TestByteNextStateFunc, @Direct_RequestCurrentStateFunc, @Direct_AckDetectedSupportedTestFunc, %01110100, SERVICEMODE_INSTRUCTION_COUNT); + STATE_SERVICEMODE_DIRECT_RESET_CYCLE : ServiceModeReset(BufferPtr, @Direct_ResetAndDispatchNextStateFunc, SERVICEMODE_POWER_ON_CYCLE_RESET_COUNT, True); + STATE_SERVICEMODE_DIRECT_BITMODE : ServiceModeRequest(BufferPtr, @Direct_RequestNextStateFunc, @Direct_RequestCurrentStateFunc, @Direct_AckDetectedFunc, %01111000, SERVICEMODE_INSTRUCTION_COUNT); + STATE_SERVICEMODE_DIRECT_BYTEMODE_VERIFY : ServiceModeRequest(BufferPtr, @Direct_ByteVerifyNextStateFunc, @Direct_RequestCurrentStateFunc, @Direct_AckDetectedFunc, %01110100, SERVICEMODE_INSTRUCTION_COUNT); + STATE_SERVICEMODE_DIRECT_BYTEMODE_WRITE : ServiceModeRequest(BufferPtr, @Direct_RequestNextStateFunc, @Direct_RequestCurrentStateFunc, @Direct_AckDetectedFunc, %01111100, SERVICEMODE_INSTRUCTION_COUNT); + STATE_SERVICEMODE_DIRECT_BYTEMODE_BY_BITS_RESET : ServiceModeReset(BufferPtr, @Direct_ByteModeByBitsResetNextStateFunc, SERVICEMODE_POWER_ON_CYCLE_RESET_COUNT, True); + STATE_SERVICEMODE_DIRECT_BYTEMODE_BY_BITS_VERIFY : ServiceModeRequest(BufferPtr, @Direct_ByteByBitNextStateFunc, @Direct_RequestCurrentStateFunc, @Direct_AckDetectedByteByBitFunc, %01111000, SERVICEMODE_INSTRUCTION_COUNT); + STATE_SERVICEMODE_DIRECT_WRITE_RECOVER_CYCLE : ServiceModeReset(BufferPtr, @Direct_WriteRecoveryNextStateFunc, SERVICEMODE_WRITE_RECOVER_COUNT, False); + STATE_SERVICEMODE_SEQUENCE_COMPLETE : ServiceModeSequenceComplete(BufferPtr); + STATE_SERVICEMODE_SEND_RESET_PACKETS : ServiceModeSendResetPackets(BufferPtr); + STATE_SERVICEMODE_NOT_SUPPORTED : ServiceModeNotSupported(BufferPtr); + end; +end; + +end. \ No newline at end of file Modified: trunk/prototypes/mikroPascal/Library/NMRAnetDCCSystem/NMRAnetDCC.mpas =================================================================== --- trunk/prototypes/mikroPascal/Library/NMRAnetDCCSystem/NMRAnetDCC.mpas 2013-02-03 20:25:09 UTC (rev 2978) +++ trunk/prototypes/mikroPascal/Library/NMRAnetDCCSystem/NMRAnetDCC.mpas 2013-02-04 04:26:46 UTC (rev 2979) @@ -32,6 +32,7 @@ MAX_NMRA_DCC_STARTUP_IDLE = 20; PREAMBLE_BIT_COUNT_NORMAL = 14; // Normal message preamble bit count + PREAMBLE_BIT_COUNT_SERVICEMODE = 20; // Service Mode message count MESSAGE_RESET_0 = $00; // Reset message = 20+1 = 21 ones; 24+3 = 27 zeros (48) = 8.70ms MESSAGE_RESET_1 = $00; @@ -152,7 +153,11 @@ // Fires the 20 Idle Packets per the NMRA Spec procedure NMRA_DCC_Packet_Init; forward; +procedure NMRA_DCC_LoadIdlePacketIntoTransmitter(Buffer: PDCCBufferInfo; PreambleCount: Byte); +procedure NMRA_DCC_LoadResetPacketIntoTransmitter(Buffer: PDCCBufferInfo; PreambleCount: Byte); + + implementation const @@ -276,7 +281,12 @@ NMRA_DCC_LoadPacket(@NewDCCMessage, MESSAGE_IDLE_0, MESSAGE_IDLE_1, 0, 0, 0, 2); for i := 0 to MAX_NMRA_DCC_STARTUP_IDLE - 1 do - while not NMRA_DCC_QueuePacket(@Track, @NewDCCMessage, True) do; + begin + if not NMRA_DCC_QueuePacket(@Track, @NewDCCMessage, True) then + begin + Delay_us(500); + end; + end; end; // **************************************************************************** Modified: trunk/prototypes/mikroPascal/Library/NMRAnetDCCSystem/NMRAnetServiceMode.mpas =================================================================== --- trunk/prototypes/mikroPascal/Library/NMRAnetDCCSystem/NMRAnetServiceMode.mpas 2013-02-03 20:25:09 UTC (rev 2978) +++ trunk/prototypes/mikroPascal/Library/NMRAnetDCCSystem/NMRAnetServiceMode.mpas 2013-02-04 04:26:46 UTC (rev 2979) @@ -17,9 +17,6 @@ unit NMRAnetServiceMode; -uses - XpressNet_Constants; - const PROGRAMMING_ACK_STATE_SCAN_FOR_ACK_BIT = 0; // Start looking for the Acknowledge bit PROGRAMMING_ACK_STATE_DETECTED_BIT = 1; // A valid Acknowledge was detected @@ -103,7 +100,7 @@ TServiceModeRegisterInfo = record DeviceCache: TServiceModeRegisterCache; // The request and the result from/to the device - iDevice: Integer; // Device that invoked Service Mode +// iDevice: Integer; // Device that invoked Service Mode Mode: Byte; // High Nibble is the Service Mode type (Direct/Address/Register/Page) See SERVICE_MODE_DIRECT_XXXX and the Lo Nibble is the command type (Read/Write/ReadBit/WriteBit) See SERVICE_MODE_COMMMAND_XXXXX constants iStateMachine: Byte; // The StateMachine State to start from after Service Mode Initialization (Power On Cycle) has been completed end; @@ -177,7 +174,7 @@ Buffer^.DeviceCache.Value := 0; Buffer^.DeviceCache.Address := 0; Buffer^.iStateMachine := STATE_SERVICEMODE_RESET_CYCLE; // Default - Buffer^.iDevice := ID_NO_DEVICE; + // Buffer^.iDevice := ID_NO_DEVICE; end; ServiceModeInfo.Queue.Count := 0; ServiceModeInfo.Queue.iHead := 0; @@ -186,7 +183,7 @@ ServiceModeInfo.Buffer.DeviceCache.Address := 0; ServiceModeInfo.Buffer.DeviceCache.Value := 0; - ServiceModeInfo.Buffer.iDevice := ID_NO_DEVICE; + // ServiceModeInfo.Buffer.iDevice := ID_NO_DEVICE; ServiceModeInfo.Buffer.Mode := 0; ServiceModeInfo.ScratchBuffer.Address := 0; @@ -229,7 +226,7 @@ RegisterInfo^.DeviceCache.Address := AnAddress; RegisterInfo^.DeviceCache.Value := AValue; RegisterInfo^.iStateMachine := iStateMachine; - RegisterInfo^.iDevice := iDevice; + // RegisterInfo^.iDevice := iDevice; RegisterInfo^.Mode := Mode; Inc(ServiceModeInfo.Queue.iHead); // Move to the next (potential) empty index if ServiceModeInfo.Queue.iHead >= MAX_SERVICEMODE_QUEUE_MESSAGES then Added: trunk/prototypes/mikroPascal/dsPIC33EP_CommandStation/MemoryMapping.ods =================================================================== (Binary files differ) Property changes on: trunk/prototypes/mikroPascal/dsPIC33EP_CommandStation/MemoryMapping.ods ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: trunk/prototypes/mikroPascal/dsPIC33EP_CommandStation/NMRAnetAppCallbacks.mpas =================================================================== --- trunk/prototypes/mikroPascal/dsPIC33EP_CommandStation/NMRAnetAppCallbacks.mpas 2013-02-03 20:25:09 UTC (rev 2978) +++ trunk/prototypes/mikroPascal/dsPIC33EP_CommandStation/NMRAnetAppCallbacks.mpas 2013-02-04 04:26:46 UTC (rev 2979) @@ -118,8 +118,9 @@ PDccProxyData = ^TDccProxyData; const - MAX_DCC_CFG_DATA = 1024; // This allows the EEPROM to never get out of sync and need to be erased and rebuilt, just grow TDCCConfigurationData up to 1024 - + MAX_NODE_CFG_DATA = 128; // This allows the EEPROM to never get out of sync and need to be erased and rebuilt, just grow TDCCConfigurationData up to 1024 + MAX_VNODE_CFG_DATA = 2304; // This allows the EEPROM to never get out of sync and need to be erased and rebuilt, just grow TDCCConfigurationData up to 1024 + type TDCCConfigurationData = record ConsistNext, // // 4 Bytes @@ -127,21 +128,7 @@ end; PDCCConfigurationData = ^TDCCConfigurationData; -const - MAX_FDI_FILE = 2048; - FDI_EEPROM_START_ADDRESS = 25600; // 256 bit pages on the 100th page - -type - TFDI_Data = record - Size: Word; // Size of the currently loaded FDI File - FDI: array[0..MAX_FDI_FILE] of byte; - end; - procedure NMRAnetAppCallbacks_Initialize; -function AppCallback_ConfigurationRead(Node: PNMRAnetNode; DataTarget: ^Byte; StartAddress: DWord; MaxCount: Byte): Byte; -procedure AppCallback_ConfigurationWrite(Node: PNMRAnetNode; DataTarget: ^Byte; StartAddress: DWord; MaxCount: Byte); -function AppCallback_ConfigurationSize(Node: PNMRAnetNode): Word; -procedure AppCallback_AssignConfigurationAddress(Node: PNMRA... [truncated message content] |