V2.0 - DTR-less downloading

Discussion specific to the 24-pin ZX microcontrollers, e.g. ZX-24r, ZX-24s and ZX-24t.
stevech
Posts: 715
Joined: 22 February 2006, 20:56 PM

V2.0 - DTR-less downloading

Post by stevech »

Thanks very much for the great new release. The new zx24a VM is running newly re-compiled code for my large multi-tasking application with dynamic task stack allocation just as the prior version did. I did get errors on task stack sizes - most needed to be a few bytes larger according to the v2.0 compiler. No other issues.

The release notes mentioned DTR-less downloading. I haven't yet found mention of that in the new docs.

thanks again

steve
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: V2.0 - DTR-less downloading

Post by dkinzer »

stevech wrote:The release notes mentioned DTR-less downloading. I haven't yet found mention of that in the new docs.
We have made the initial changes to support downloading without using the DTR signal but this capability has not yet been tested thoroughly.

The idea is that you choose a special character code, in the range &H00 to &H1f, that you want to use as the "ATN character". If the ZX receives this character on Com1, it interprets it as an ATN request and responds the same as if it had received the ATN sequence on the DTR line. Note that when configured for an ATN character, a ZX will still respond to the ATN protocol on the DTR line. Of course, you must choose the ATN character carefully - one that will not otherwise be sent to your ZX on Com1.

The IDE does not yet have the ability to be configured to use an ATN character nor can it configure the ZX for the chosen ATN character. However, if you want to experiment with this you can use ZLoad to do both. An example of the command to configure the ATN character is:

Code: Select all

zload -zb:19:27
The value 19 is the address in Persistent Memory where the ATN character is stored. The value 27 represents the selected ATN character value; in this case ESC (hexadecimal code &H1b) was selected.

Once the ZX is configured for the desired ATN character, you can download code without using DTR by using the ZLoad command line like:

Code: Select all

zload -a27 -v -m test.zxb
The option -a27 specifies that character code 27 should be used as the ATN character instead of the default DTR protocol.

For both ZLoad commands, the values may be specified in decimal as shown above or they may be specified in hexadecimal by using a 0x prefix. To disable the ATN character, simply set it back to &Hff:

Code: Select all

zload -zb:19:0xff
- Don Kinzer
dlh
Posts: 395
Joined: 15 December 2006, 12:12 PM
Location: ~Cincinnati

Post by dlh »

I think this is going to require a little more sophistication as the probability of any single character appearing in the datastream is fairly high and may not be under the programmer's control. As Don knows, I encountered this when testing a prerelease version of the VM. He had inadvertently configured the ZX-40a he sent me to use this feature and code that had been working fine with the earlier VM would occasionally cause my app to freeze. Seeing characters that indicated the chip was in command mode was the only thing that finally tipped us off that this might be the cause.

I would suggest bracketing this special character with <DLE>. A sequence like <DLE><ESC><DLE> would be far less likely to happen by chance.

In my case I am transferring memory images of single precision values and have no control over the datastream. I don't recall exactly what triggered it but I was transferring longitude/latitude values.
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

dlh wrote:I think this is going to require a little more sophistication [...]. A sequence like <DLE><ESC><DLE> would be far less likely to happen by chance.
Although it can't be used in all circumstances, it does have the virtue of simplicity. A multi-character sequence also will not work in all circumstances (although, clearly the set is larger) but it has some prickly problems that don't have good solutions. For example, what happens if the first two characters are received and then no more characters are received for a long period of time? How long do you wait before you decide to reset the pattern matching state and pass the first two characters on to the application as should clearly be done? Even if a good answer can be established for this question, the question remains as to how to implement the timeout without unduly taxing other parts of the system.

As a side note, in the current implementation, the ATN character will never appear in the input queue for Com1 because it is always intercepted.
- Don Kinzer
dlh
Posts: 395
Joined: 15 December 2006, 12:12 PM
Location: ~Cincinnati

Post by dlh »

I don't see that this is all that different from a modem which requires both DATA and COMMAND modes. DLE (Data Link Escape, 0x10) is used with modems for just this purpose. If the byte between two DLEs is always interpreted as a command, there's no need to wait any significant amount of time for the closing <DLE> as it will always follow immediately if the sequence is intended as a command. There may be cases where <DLE><ESC><DLE> occurs as data but they should be rare. For that matter, the amount of time to wait could also be a programmer determined parameter.

The ATIS (Alliance for Telecommunications Industry Solutions) definition of <DLE> is...

data link escape character (DLE): A transmission control character that changes the meaning of a limited number of contiguously following characters or coded representations
GTBecker
Posts: 616
Joined: 17 January 2006, 19:59 PM
Location: Cape Coral

V2.0 - DTR-less downloading

Post by GTBecker »

> ...I would suggest bracketing this special character with a sequence...

AT-commanded modems do the same with the Escape sequence surrounded by
guard periods.

Tom
Tom
stevech
Posts: 715
Joined: 22 February 2006, 20:56 PM

Post by stevech »

For apps that do ASCII only on the serial port (like most of mine), a single char ATN scheme is fine.

I missed the concept of how the scanning for the ATN char is enabled/disabled in the VM. I assume it's disabled by default.

The DLE scheme is OK, but the app has to stuff a second DLE anywhere DLE occurs in real binary data. This is the old IBM BSC protocol for 3270's (I'm dating myself).
dlh
Posts: 395
Joined: 15 December 2006, 12:12 PM
Location: ~Cincinnati

Post by dlh »

stevech wrote:For apps that do ASCII only on the serial port (like most of mine), a single char ATN scheme is fine.
Agreed, but as I stated, my app transfers bytes that can fall outside the ASCII range. It may also present problems with TCP/IP connections via the Tibbo EM202 which embeds control characters within the datastream. I think my proposed method is more universal.
I missed the concept of how the scanning for the ATN char is enabled/disabled in the VM. I assume it's disabled by default.
If there's a non-zero value at address 19 of persistent memory it defines the ATN character.
The DLE scheme is OK, but the app has to stuff a second DLE anywhere DLE occurs in real binary data.
Not with a leading and trailing <DLE> as I suggest.
This is the old IBM BSC protocol for 3270's
I think it predates that.
(I'm dating myself).
I read recently where komodo dragons date themselves. :shock:
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

stevech wrote:I missed the concept of how the scanning for the ATN char is enabled/disabled in the VM. I assume it's disabled by default.
It is disabled by default. If you write a ZBasic program to read the byte at address 19 in Persistent Memory, you'll see that it has the value &Hff. The ATN character feature is only active when that address contains a value in the range &H00 to &H1f, which value is the ATN character.

You can turn it on and off at any time by just writing that byte. This is simpler now using a Based Persistent variable thusly:

Code: Select all

Dim ATNChar as Persistent Byte Based &H0013

Sub Main
    ATNChar = &H04   ' set the ATN character to ctrl-D
...
    ATNChar = &Hff   ' disable the ATN character
End Sub
Dave's comment earlier about having a problem with this was due to the fact that we sent him an interim VM release that inadvertently had the ATN character set to &H00. Apparently, that value occured in the data stream that he was sending to the ZX on Com1.
- Don Kinzer
stevech
Posts: 715
Joined: 22 February 2006, 20:56 PM

Post by stevech »

got it. Thanks.

With this - I can hopefully download via LANs and wireless and so on - things that don't reliably reproduce the original and required DTR timing.

If DTR toggle checking in the VM were done with a concept of much slower and longer periods, less precision required - it would work OK on LANs.
stevech
Posts: 715
Joined: 22 February 2006, 20:56 PM

Post by stevech »

dkinzer wrote:
stevech wrote:I missed the concept of how the scanning for the ATN char is enabled/disabled in the VM. I assume it's disabled by default.
It is disabled by default. If you write a ZBasic program to read the byte at address 19 in Persistent Memory, you'll see that it has the value &Hff. The ATN character feature is only active when that address contains a value in the range &H00 to &H1f, which value is the ATN character.

You can turn it on and off at any time by just writing that byte. This is simpler now using a Based Persistent variable thusly:

Code: Select all

Dim ATNChar as Persistent Byte Based &H0013

Sub Main
    ATNChar = &H04   ' set the ATN character to ctrl-D
...
    ATNChar = &Hff   ' disable the ATN character
End Sub
Is the ATN char scanning in the mega32 VM too?
dlh
Posts: 395
Joined: 15 December 2006, 12:12 PM
Location: ~Cincinnati

Post by dlh »

Another approach would be to allow entering/exiting command mode from within a running application. I could then incorporate it into my communications protocol and use any method I want to trigger a download.
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

stevech wrote:Is the ATN char scanning in the mega32 VM too?
Yes, it is.
- Don Kinzer
stevech
Posts: 715
Joined: 22 February 2006, 20:56 PM

Post by stevech »

Yea!
I downloaded a ZX24 via the new ATN-char mode.

zload -c4 -a4 -v filename.zxb

worked!

The data path is:

Zload -> COM4
COM4 is a virtual COM port driver in XP that goes to the ethernet LAN.
LAN -> WiFi router -> Moxa NPort device (WiFi to serial port bridge)
NPort -> ZX24 module

This data path used to work with the DTR download scheme. But when I moved to a newer/faster PC, for some reason, I could not make downloading work (from the IDE). The IDE debug window did talk to the ZX just fine, but the DTR timing for download stopped working with the new PC. Several things I tried didn't fix it.

Progress!

One of the nice things about this is that the ZX module connected to the W-LAN (or ethernet LAN) can be accessed by any PC, locally or remotely. I could port-forward in my router to give Internet access. No password scheme though. Maybe another argument for letting the application in the ZX invoke the download (assuming it isn't hung up).

I'll try this now with a LANTRONIX WiPort instead of the Moxa NPort. Should work with the XPort too.

Next we'll soon see (I hope!) this ATN-char scheme integrated with the IDE. Meanwhile, I'll just use a .BAT file.
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

stevech wrote:Next we'll soon see (I hope!) this ATN-char scheme integrated with the IDE. Meanwhile, I'll just use a .BAT file.
Yes, we'll get there. In the mean time, you can configure the IDE to use ZLoad to do the downloading. See the thread about74.html. The third post from the end shows the way to do the configuration. Of course, you'll want to specify slightly different ZLoad options to implement the ATN character method but the means should be clear.

I assume that you discovered that the -m option in ZLoad causes it to enter monitor mode; hence the disappearing post.
- Don Kinzer
Post Reply