Wireless file transfer to the Next: Is there something available?

This section is for discussing everything about Next hardware and latest updates.
Post Reply
Eratosthenes
Posts: 226
Joined: Mon May 29, 2017 8:17 pm

Wireless file transfer to the Next: Is there something available?

Post by Eratosthenes » Sun Jan 20, 2019 11:21 am

Hi everybody,

as I'm still fiddling around with the Next (Just The Board) I'm looking forward to a feature I don't have.

I'd like to be able to transfer data, especially files, directly to the SD card of the Next.

This should be "wireless" and without resetting the device or removing SD cards or such. Having a ESP8266 on board this shouldn't be a big issue...

Because of this I tried to transfer data using .uart. I recognised that it seems to be really as simple as I expected.

My experiments so far:
- Sending data using TCP/IP works as expected
- The TCP/IP server of the ESP8266 works as expected
- The Next receives the data

What I don't know at the moment:
- how to access the ESP8266 without using the terminal program (.uart)
- how to store the data to the SD card

Results shown:
PC code is very simple:
PcCode.jpg
Code on the PC is as simple as that
PcCode.jpg (43.75 KiB) Viewed 1588 times
Next can receive the data:
NextScreenshot.jpg
The ESP8266 receives the data and the Next can read it
NextScreenshot.jpg (105.45 KiB) Viewed 1588 times
What I've seen is that data is dropped as soon as the Next isn't quick enough to receive. Because of this I think that there should be a more forgiving protocol that can handle the speed of the Next...

Is there any file transfer program out there for the Next or do I have to write one?

Any suggestions? - Thanks for the info.

MfG
der Eratosthenes

Alcoholics Anonymous
Posts: 505
Joined: Mon May 29, 2017 7:00 pm

Re: Wireless file transfer to the Next: Is there something available?

Post by Alcoholics Anonymous » Wed Jan 23, 2019 7:22 am

Eratosthenes wrote:
Sun Jan 20, 2019 11:21 am
What I don't know at the moment:
- how to access the ESP8266 without using the terminal program (.uart)
The uart is simple to use:
https://github.com/z88dk/z88dk/blob/mas ... xn_uart.m4

A simple C program for the Next that does basic uart communication was posted last year:

Code: Select all

// zcc +zxn -vn -startup=0 -clib=sdcc_iy -SO3 --max-allocs-per-node200000 uart.c -o uart -subtype=sna -Cz"--128 --clean" -create-app

#include <arch/zxn.h>
#include <stdio.h>
#include <stdint.h>

uint32_t uart_clock[] = {
   CLK_28_0,
   CLK_28_1,
   CLK_28_2,
   CLK_28_3,
   CLK_28_4,
   CLK_28_5,
   CLK_28_6,
   CLK_28_7
};

void set_baud_rate(uint32_t baud)
{
   unsigned int prescalar;
   
   prescalar = uart_clock[ZXN_READ_REG(REG_VIDEO_TIMING)] / baud;
   
   IO_UART_BAUD_RATE = prescalar & 0x7f;                   // lower 7 bits
   IO_UART_BAUD_RATE = ((prescalar >> 7) & 0x7f) | 0x80;   // upper 7 bits
}

void send_char(unsigned char c)
{
   while (IO_UART_STATUS & IUS_TX_BUSY) ;
   IO_UART_TX = c;
}

void send_string(unsigned char *s)
{
   while (*s)
   {
      if (*s == '\n')
         send_char('\r');
      
      send_char(*s++);
   }
}

unsigned char buf[128];

void main(void)
{
   zx_border(INK_WHITE);
   zx_cls(INK_BLACK | PAPER_WHITE);
  
   set_baud_rate(115200UL);
   
   while (1)
   {
      // read input from keyboard
      
      fgets(buf, sizeof(buf), stdin);
      fflush(stdin);  // get rid of any chars still in the edit buffer
      
      // transmit message
      
      if (*buf && (*buf != '\n'))  // can press enter to try to get more response
         send_string(buf);
      
      // read response
      
      for (unsigned char i = 0; i != 100; ++i)    // wait a bit for a response
         if (IO_UART_STATUS & IUS_RX_AVAIL) break;

      while (IO_UART_STATUS & IUS_RX_AVAIL)
         fputc(IO_UART_RX, stdout);
   }
}
The important thing to note is the uart baud period depends on the actual 28MHz clock frequency which is modified depending on the video timing selected for the machine (hdmi, vga0-6). This adjustment instead of using a nominal 28MHz becomes important at higher speeds.

Also different ESPs power up at different baud rates 115200, 57600, etc so your program may have to try changing baud rate to establish sensible communication before changing to the desired baud rate for the running program.
What I've seen is that data is dropped as soon as the Next isn't quick enough to receive. Because of this I think that there should be a more forgiving protocol that can handle the speed of the Next...
There is a 512-byte fifo connected to Rx which provides plenty of time to gather data from the esp if it is polled frequently enough, for example in a 50Hz interrupt routine. For really fast serial connections you'd have to poll more frequently. People have been successfully running the uart as fast as 2Mbps in simple data transmission protocols.

The particular ESP model used does not have any pins for hardware handshaking so there is no way to slow down or temporarily stop the ESP when the Rx buffer fills without changing the ESP firmware. If the ESP firmware can be changed, then you can look at using the two GPIO pins it provides for hw handshaking or you can introduce some sw handshaking protocol.
- how to store the data to the SD card
This is very easy. Use the esx api as described starting on page 24 in NextZXOS_api.pdf at:
https://gitlab.com/thesmog358/tbblue/tr ... s/nextzxos

It's a nearly POSIX api so operates similarly to unix/linux file systems. You open a file with certain modes, read/write/seek, close the file when done.

There is extensive support for file io in C in z88dk that can be useful to see what is available if you program PCs:
https://github.com/z88dk/z88dk/blob/mas ... dos.h#L394

Assembly language implementation of the C api:
https://github.com/z88dk/z88dk/tree/mas ... esxdos/z80
Is there any file transfer program out there for the Next or do I have to write one?
Not yet.
Last edited by Alcoholics Anonymous on Wed Jan 23, 2019 9:06 am, edited 1 time in total.

Alcoholics Anonymous
Posts: 505
Joined: Mon May 29, 2017 7:00 pm

Re: Wireless file transfer to the Next: Is there something available?

Post by Alcoholics Anonymous » Wed Jan 23, 2019 7:55 am

I couldn't find the documentation earlier but I did manage to find it right now:
https://gitlab.com/thesmog358/tbblue/tr ... ra-hw/wifi

These describe the esp driver that is integrated into basic and can be used from asm as well. So this is an option instead of doing things yourself at lowest level.

Eratosthenes
Posts: 226
Joined: Mon May 29, 2017 8:17 pm

Re: Wireless file transfer to the Next: Is there something available?

Post by Eratosthenes » Fri Feb 01, 2019 5:41 pm

Hi!

THNX 4 the info.

I will check. - This makes a wireless PC->Next solution possible... :D

News to follow...

User avatar
asve79
Posts: 2
Joined: Sat Jan 05, 2019 10:48 am

Re: Wireless file transfer to the Next: Is there something available?

Post by asve79 » Thu Feb 14, 2019 5:10 am

Hi!

My version of the solution fro file transfer: ftp-client.
Now it underconstruction. (Now i'm creating low level library for zx-next uart, then will make next level abstract logic: internet connection). Then I will look for a solution on how to work with files on zx-next using an assembler.

Github: https://github.com/asve79/z80-ftp
Demo of current solution:
Image

User avatar
Timbucus
Posts: 223
Joined: Tue May 30, 2017 7:43 pm

Re: Wireless file transfer to the Next: Is there something available?

Post by Timbucus » Sat Feb 16, 2019 1:04 pm

Lovely work - just what is needed - file save is very simple using the ESXDOS API and not very hard using the NextZXOS one if you have used the Plus3 or the Amstrad DOS systems. Shout if you want any help...
I'm Infinite Imaginations when not in work... PAWS for thought.

FuZX
Posts: 6
Joined: Sun Feb 03, 2019 12:49 am

Re: Wireless file transfer to the Next: Is there something available?

Post by FuZX » Sun May 05, 2019 11:38 am

Why not using SD/Wifi to MicroSD adapter ? easy to upload files to the microSD
http://www.ezshare.com.cn/uppic/2013101008384459.png

Post Reply