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

Post by stevech »

yes.
-m confused me for a moment!

I like it.
dlh
Posts: 395
Joined: 15 December 2006, 12:12 PM
Location: ~Cincinnati

Trigger command mode from code

Post by dlh »

It should be possible to trigger command mode from within a program by doing this...
  • 1. Send a command (from PC) to start the procedure.
    2. Switch PC to 115200.
    3. Write a value to address 19 of persistent memory.
    4. Stuff the same value into the COM1 input queue.
    5. Download.
    6. Write &HFF to address 19.
    7. Reset.
It does have the disadvantage that the number of writes to persistent memory is limited to 100,000 and this uses 2 writes each time it is invoked. Still, that means 136 years at one download cycle per day.

It also allows use of a single character trigger without any possibility that it will accidently be triggered by the normal data stream.

There are probably a few details I've overlooked but I'll try to write some code to test this.
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: Trigger command mode from code

Post by dkinzer »

dlh wrote:It should be possible to trigger command mode from within a program by doing this...
The sequence is a bit tricky because of the speed switching involved. The ATN character has to be sent by the PC at the baud rate at which the ZX is listening in "normal" mode - 19,200 by default but it could be different if your application changes it. After the ATN character is sent, the PC can delay a bit, switch to 115.2K baud (the speed in command mode), purge its input buffer and then send an ESC (&H1b). If the ZX responds with a command mode prompt (greater than symbol, &H3e) it is in command mode and awaiting a command.

When you are finished with command mode, you tell the ZX to begin executing (via a WatchDog reset) by sending it an Execute command (&H21). Immediately after sending that command, the PC would switch back to 19,200 baud.

The issue of write cycle limitation of Persistent memory would be avoided and the process simplified slightly if an "enter command mode" API were available. That should be fairly simple to implement.
- Don Kinzer
dlh
Posts: 395
Joined: 15 December 2006, 12:12 PM
Location: ~Cincinnati

Re: Trigger command mode from code

Post by dlh »

dkinzer wrote:The sequence is a bit tricky because of the speed switching involved. The ATN character has to be sent by the PC at the baud rate at which the ZX is listening in "normal" mode - 19,200 by default but it could be different if your application changes it.
I'm trying to eliminate the need to send the ATN character from the PC becaiuse my app (and I suspect many apps) is ALWAYS likely to trigger ATN accidentally. I'll send a command (2 bytes or more) using my normal communications protocol and then I'll do the little dance I described to get the ZX into command mode. Of course, it would be simplified if I could just toggle ATN using PulseOut and simplified even further with an API function.
stevech
Posts: 715
Joined: 22 February 2006, 20:56 PM

Post by stevech »

The VM runs command mode/downloads at 115Kbaud? I didn't realize that - since I'd expect that quite a few PCs cannot reliably do that speed, or do so through certain cables.
Don_Kirby
Posts: 341
Joined: 15 October 2006, 3:48 AM
Location: Long Island, New York

Post by Don_Kirby »

Is it possible to trigger the DTR-less download with ZLoad.dll?
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

Don_Kirby wrote:Is it possible to trigger the DTR-less download with ZLoad.dll?
Yes, but be forewarned that it is still experimental.

Before commencing a download, you have to make a call to set a parameter, specifically, the ATN character. You do that with the entry point

Code: Select all

long CALLBACK ZXSetParameter(long id, long value);
The first parameter should be ZX_PARAM_ATN_CHAR (defined in zxcomm.h) and the second parameter should be the ATN character value.

The file zload.c demonstrates the use of the call above to support the -a option for zload.exe that implements the ATN character.
- Don Kinzer
Don_Kirby
Posts: 341
Joined: 15 October 2006, 3:48 AM
Location: Long Island, New York

Post by Don_Kirby »

Don, how would that translate to VB6? I don't have Visual C to compile it.

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

Post by dkinzer »

Don_Kirby wrote:[H]ow would that translate to VB6?
Following the same pattern as for the others it would be

Code: Select all

Declare Function ZXSetParameter(long id, long value) Lib "zload.dll" ( _
  ByVal id As Long, ByVal val As Long) As Long
- Don Kinzer
Don_Kirby
Posts: 341
Joined: 15 October 2006, 3:48 AM
Location: Long Island, New York

Post by Don_Kirby »

It seems that I'm not quite up to speed on this yet. Using the format provided in the ZLoad VB sample, I make the call to set the ATNChar, then proceed with the download as normal.

I can perform a DTR-less download through the IDE and command line, and I can trigger it via a Shell call in VB. I can successfully download/update using the DLL from VB with DTR.

You did mention that it's still experimental... Perhaps there in lies the difficulty?

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

Post by dkinzer »

I'm unclear as to where you're having difficulty. It seems that you can perform a DTR-less download using the zload utility. This would imply that you have also successfully set the ATN character in the device itself. (Obviously, the device and the downloader must both be configured to use the same ATN character.)

As far as using the DLL, you should set the ATN character as early as possible. I don't recall if it matters if it is set before or after the port is opened but I would suggest doing so before opening.
- Don Kinzer
Don_Kirby
Posts: 341
Joined: 15 October 2006, 3:48 AM
Location: Long Island, New York

Post by Don_Kirby »

Basically, I am attempting to add the no DTR download ability to the included VB sample. I am calling ZXSetParameter before the call to download/update. I consistently get "Device failed to respond to the ATN signal." Does the call to ZXDownloadEX need to be modified in any way for no DTR downloads?


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

Post by dkinzer »

Don_Kirby wrote:Does the call to ZXDownloadEX need to be modified in any way for no DTR downloads?
Yes, sorry. You need to add the value ZX_NO_DTR (&H20000) to the flags parameter.
- Don Kinzer
Post Reply