Shop OBEX P1 Docs P2 Docs Learn Events
Tachyon FTP server — Parallax Forums

Tachyon FTP server

Peter JakackiPeter Jakacki Posts: 10,193
edited 2015-07-11 23:07 in Propeller 1
I'm in the process of testing an FTP server written in Tachyon Forth for the Wiznet W5200. I initially was using the Spin driver for this chip but I can see numerous advantages in using Forth, including diagnostics. Also the plain text FTP commands are just passed to the Forth text interpreter for execution such as USER PASS SYST RETR etc

Anyway, I'm testing this as well as web, telnet and serial server ports but I'm just wondering if anyone has written an FTP server for the Prop? I'm wondering if there are any gotchas down the road to look out for.
[FONT=courier new]WIZ? 
************ W5200 STATUS ************ 
LINK *UP*
CHIP VER  0003
SRC IP    192.168.016.150.
MASK      255.255.255.000.
GATEWAY   192.168.016.001.
MAC       00.08.DC.01.02.03.
*** SOCKETS *** 
0: MODE= TCP    PORT#0021        STAT=17 ESTABLISHED    192.168.016.108.
1: MODE= TCP    PORT#0023        STAT=14 LISTEN 
2: MODE= TCP    PORT#0080        STAT=14 LISTEN
3: MODE= TCP    PORT#0000        STAT=00 CLOSED
4: MODE= TCP    PORT#0000        STAT=00 CLOSED
5: MODE= TCP    PORT#0000        STAT=00 CLOSED
6: MODE= TCP    PORT#0000        STAT=00 CLOSED
7: MODE= TCP    PORT#0000        STAT=00 CLOSED ok
[/FONT]

Comments

  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2013-10-22 18:44
    Since I've been using Forth to write code on the W5200 I have been able to stimulate and examine the W5200 in closer detail. I've noticed that the TXWR register among others is not viewable (reads 0) or settable until connection is established and once it does then it always comes up with random values. I can set other registers and tx memory fine etc. Has anyone had much experience with this chip?

    The WIZNET site doesn't really seem to answer any similar questions that others have asked and in typical Asian manner (admit no wrong) just asks "have you used standard driver?" which of course never answers the question or addresses the problem. Shoot me.

    Here is a connection weirdness. BTW, I prefill the transmit buffer with "?" so I can see if it's sending other parts of the buffer. After I type GO it inits the chip etc and runs a server polling routine in the background. Ignore the socket number reporting glitch.

    FileZilla capture:
    [FONT=courier new]Status:    Connecting to 192.168.16.150:21...
    Status:    Connection established, waiting for welcome message...
    Response:    220 TACHYON
    Command:    USER pbjtech
    Response:    ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????220 TACHYON
    Error:    Could not connect to server
    Status:    Waiting to retry...
    Status:    Connecting to 192.168.16.150:21...
    Status:    Connection attempt failed with "ECONNREFUSED - Connection refused by server".
    Error:    Could not connect to server
    [/FONT]
    

    Tachyon terminal capture:
    [FONT=courier new]GO 
    ************ W5200 STATUS ************ 
    LINK DOWN
    CHIP VER  0003
    SRC IP    192.168.016.150.
    MASK      255.255.255.000.
    GATEWAY   192.168.016.001.
    MAC       00.08.DC.01.02.03.
    *** SOCKETS *** 
    5: MODE= TCP    PORT#0021 TXRW=0000.0000.RXRW=0000.0000.RXSZ=0000.       STAT=14 LISTEN 
    6: MODE= TCP    PORT#0023 TXRW=0000.0000.RXRW=0000.0000.RXSZ=0000.       STAT=14 LISTEN 
    7: MODE= TCP    PORT#0080 TXRW=0000.0000.RXRW=0000.0000.RXSZ=0000.       STAT=14 LISTEN 
    0: MODE= CLOSED PORT#0000 TXRW=0000.0000.RXRW=0000.0000.RXSZ=0000.       STAT=00 CLOSED
    1: MODE= CLOSED PORT#0000 TXRW=0000.0000.RXRW=0000.0000.RXSZ=0000.       STAT=00 CLOSED
    2: MODE= CLOSED PORT#0000 TXRW=0000.0000.RXRW=0000.0000.RXSZ=0000.       STAT=00 CLOSED
    3: MODE= CLOSED PORT#0000 TXRW=0000.0000.RXRW=0000.0000.RXSZ=0000.       STAT=00 CLOSED
    4: MODE= CLOSED PORT#0000 TXRW=0000.0000.RXRW=0000.0000.RXSZ=0000.       STAT=00 CLOSED ok
    
    [B]FTP: CONNECT[/B] 
    ************ W5200 STATUS ************ 
    LINK *UP*
    CHIP VER  0003
    SRC IP    192.168.016.150.
    MASK      255.255.255.000.
    GATEWAY   192.168.016.001.
    MAC       00.08.DC.01.02.03.
    *** SOCKETS *** 
    5: MODE= TCP    PORT#0021 TXRW=00F1.00F1.RXRW=0000.0000.RXSZ=0000.       STAT=17 ESTABLISHED    192.168.016.108.
    6: MODE= TCP    PORT#0023 TXRW=0000.0000.RXRW=0000.0000.RXSZ=0000.       STAT=14 LISTEN 
    7: MODE= TCP    PORT#0080 TXRW=0000.0000.RXRW=0000.0000.RXSZ=0000.       STAT=14 LISTEN 
    0: MODE= CLOSED PORT#0000 TXRW=0000.0000.RXRW=0000.0000.RXSZ=0000.       STAT=00 CLOSED
    1: MODE= CLOSED PORT#0000 TXRW=0000.0000.RXRW=0000.0000.RXSZ=0000.       STAT=00 CLOSED
    2: MODE= CLOSED PORT#0000 TXRW=0000.0000.RXRW=0000.0000.RXSZ=0000.       STAT=00 CLOSED
    3: MODE= CLOSED PORT#0000 TXRW=0000.0000.RXRW=0000.0000.RXSZ=0000.       STAT=00 CLOSED
    4: MODE= CLOSED PORT#0000 TXRW=0000.0000.RXRW=0000.0000.RXSZ=0000.       STAT=00 CLOSED
    [B]FTP: WELCOME[/B] 
    ************ W5200 STATUS ************ 
    LINK *UP*
    CHIP VER  0003
    SRC IP    192.168.016.150.
    MASK      255.255.255.000.
    GATEWAY   192.168.016.001.
    MAC       00.08.DC.01.02.03.
    *** SOCKETS *** 
    5: MODE= TCP    PORT#0021 TXRW=0501.0501.RXRW=0000.0600.RXSZ=0600.       STAT=00 CLOSED
    6: MODE= TCP    PORT#0023 TXRW=0000.0000.RXRW=0000.0000.RXSZ=0000.       STAT=14 LISTEN 
    7: MODE= TCP    PORT#0080 TXRW=0000.0000.RXRW=0000.0000.RXSZ=0000.       STAT=14 LISTEN 
    0: MODE= CLOSED PORT#0000 TXRW=0000.0000.RXRW=0000.0000.RXSZ=0000.       STAT=00 CLOSED
    1: MODE= CLOSED PORT#0000 TXRW=0000.0000.RXRW=0000.0000.RXSZ=0000.       STAT=00 CLOSED
    2: MODE= CLOSED PORT#0000 TXRW=0000.0000.RXRW=0000.0000.RXSZ=0000.       STAT=00 CLOSED
    3: MODE= CLOSED PORT#0000 TXRW=0000.0000.RXRW=0000.0000.RXSZ=0000.       STAT=00 CLOSED
    4: MODE= CLOSED PORT#0000 TXRW=0000.0000.RXRW=0000.0000.RXSZ=0000.       STAT=00 CLOSED
    [/FONT]
    
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2013-10-23 00:50
    Just an update on that problem and I've fixed some of my reporting bugs such as endianess but I still see the W5200 spewing buffer garbage (all those ? I prefilll the buffer with) on the intial welcome message. After that it seems to be okay as I can interact with it as a TELNET session assuming I initiated the connection from a terminal. So there is no problem receiving or even redirecting Tachyon's console I/O to it either. I will keep looking into it and see if I can do a work-around but if anybody has any ideas they'll be welcome.

    Here in this version I am using a simple character EMIT for the welcome message which writes to the tx buffer and issues a SEND command for each and every character rather than a string SEND. Result is the same for a string then SEND.
    [FONT=courier new]GO 
    ************ W5200 STATUS ************ 
    LINK DOWN
    CHIP VER  0003
    SRC IP    192.168.016.150.
    MASK      255.255.255.000.
    GATEWAY   192.168.016.001.
    MAC       00.08.DC.01.02.03.
    *** SOCKETS *** 
    0: MODE= TCP    PORT#0021 TXRW=0000.0000.RXRW=0000.0000.RXSZ=0000.RXIR=00        STAT=14 LISTEN 
    1: MODE= TCP    PORT#0023 TXRW=0000.0000.RXRW=0000.0000.RXSZ=0000.RXIR=00        STAT=14 LISTEN 
    2: MODE= TCP    PORT#0080 TXRW=0000.0000.RXRW=0000.0000.RXSZ=0000.RXIR=00        STAT=14 LISTEN 
    3: MODE= CLOSED PORT#0000 TXRW=0000.0000.RXRW=0000.0000.RXSZ=0000.RXIR=00        STAT=00 CLOSED
    4: MODE= CLOSED PORT#0000 TXRW=0000.0000.RXRW=0000.0000.RXSZ=0000.RXIR=00        STAT=00 CLOSED
    5: MODE= CLOSED PORT#0000 TXRW=0000.0000.RXRW=0000.0000.RXSZ=0000.RXIR=00        STAT=00 CLOSED
    6: MODE= CLOSED PORT#0000 TXRW=0000.0000.RXRW=0000.0000.RXSZ=0000.RXIR=00        STAT=00 CLOSED
    7: MODE= CLOSED PORT#0000 TXRW=0000.0000.RXRW=0000.0000.RXSZ=0000.RXIR=00        STAT=00 CLOSED ok
    
    FTP: CONNECT 
    
    ************ W5200 STATUS ************ 
    LINK *UP*
    CHIP VER  0003
    SRC IP    192.168.016.150.
    MASK      255.255.255.000.
    GATEWAY   192.168.016.001.
    MAC       00.08.DC.01.02.03.
    *** SOCKETS *** 
    0: MODE= TCP    PORT#0021 TXRW=03C5.03C5.RXRW=0000.0000.RXSZ=0000.RXIR=01        STAT=17 ESTABLISHED    192.168.016.108.
    1: MODE= TCP    PORT#0023 TXRW=0000.0000.RXRW=0000.0000.RXSZ=0000.RXIR=00        STAT=14 LISTEN 
    2: MODE= TCP    PORT#0080 TXRW=0000.0000.RXRW=0000.0000.RXSZ=0000.RXIR=00        STAT=14 LISTEN 
    3: MODE= CLOSED PORT#0000 TXRW=0000.0000.RXRW=0000.0000.RXSZ=0000.RXIR=00        STAT=00 CLOSED
    4: MODE= CLOSED PORT#0000 TXRW=0000.0000.RXRW=0000.0000.RXSZ=0000.RXIR=00        STAT=00 CLOSED
    5: MODE= CLOSED PORT#0000 TXRW=0000.0000.RXRW=0000.0000.RXSZ=0000.RXIR=00        STAT=00 CLOSED
    6: MODE= CLOSED PORT#0000 TXRW=0000.0000.RXRW=0000.0000.RXSZ=0000.RXIR=00        STAT=00 CLOSED
    7: MODE= CLOSED PORT#0000 TXRW=0000.0000.RXRW=0000.0000.RXSZ=0000.RXIR=00        STAT=00 CLOSED
    [/FONT]
    
    [FONT=courier new]peter@peter-XPS-L702X-LinuxMint15 ~ $ telnet 192.168.16.150 21
    Trying 192.168.16.150...
    Connected to 192.168.16.150.
    Escape character is '^]'.
    W???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????WELCOME TO THE TACHYON WIZNET SESSION!
    [/FONT]
    

    Typing LAN MODULES CON into Tachyon after this redirects the console output to the LAN (and back) perfectly without any garbage. Here's the last couple of lines from the Telnet session (on port 21)
    ????????????????????????????WELCOME TO THE TACHYON WIZNET SESSION!
    
    MODULES LOADED: 
    34F1: WIZNET-W5200.fth    WIZNET W5200 driver 130223.1500 
    2E2C: SDCARD.fth          SD CARD Toolkit - 130723.0000 
    2D35: MCP79410-RTC.fth    MCP79410 I2C RTC DRIVER - 130529.1330 
    1880: EXTEND.fth          Primary extensions to TACHYON kernel - 130909-0000 [FONT=courier new]
    [/FONT]
    
  • Mike GMike G Posts: 2,702
    edited 2013-10-23 02:59
    I've work a lot with the W5200 chip. Yes, the TX Write Pointer (I believe that's the one) jumped all over the place during run time. Calculating the physical address always works out though.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2013-10-23 05:14
    Mike G wrote: »
    I've work a lot with the W5200 chip. Yes, the TX Write Pointer (I believe that's the one) jumped all over the place during run time. Calculating the physical address always works out though.

    Yes, but did you experience any problems with the first send after connection established, it just seems to grab a random chunk of the buffer and also seems to transmit repeatedly. After that it's okay.
  • Mike GMike G Posts: 2,702
    edited 2013-10-23 06:42
    Yes, but did you experience any problems with the first send after connection established,
    My memory is a little fuzzy and I don't want to send you down a rabbit hole. But yes I've had a similar issue. IIRC, it had to do with the destination register not being set to what I expected. I'll see if I can reproduce the error.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2013-10-23 08:24
    Just found the problem, seems others have had this problem too. The TX_WR register is read and incremented by the count and written back but you need to apply a mask ($7FF default) to this which I was doing after I read the TX_WR register, Now I have changed it so that the TX_WR read, increment, and write do not have a mask applied, the mask is only applied before the count is added to the transmit buffer base address.

    This works: (non-optimized method for testing)
    [COLOR=#000000][FONT=Ubuntu Mono]pub LANEMIT ( ch -- )[/FONT][/COLOR]
    [COLOR=#000000][FONT=Ubuntu Mono]    TXWR LW@ DUP 1+ TXWR LW!         \ Increment write index (okay to do this first)[/FONT][/COLOR]
    [COLOR=#000000][FONT=Ubuntu Mono]    $7FF AND                    \ mask it according to buffer size (default 2K)[/FONT][/COLOR]
    [COLOR=#000000][FONT=Ubuntu Mono]    TXBASE0 socket C@ #11 SHL + +            [/FONT][/COLOR]
    [COLOR=#000000][FONT=Ubuntu Mono]    LC! SEND[/FONT][/COLOR]
    [COLOR=#000000][FONT=Ubuntu Mono]    ;[/FONT][/COLOR]
    
    

    This does not work: (disregard wraparound for testing)
    [FONT=courier new][COLOR=#000000]pub LANEMIT ( ch -- )[/COLOR][/FONT]
    [FONT=courier new][COLOR=#000000]    TXWR LW@ [/COLOR][/FONT][FONT=courier new][COLOR=#000000]$7FF AND [/COLOR][/FONT][FONT=courier new][COLOR=#000000]DUP 1+ [/COLOR][/FONT][FONT=courier new][COLOR=#000000]TXWR LW! [/COLOR][/FONT]
    [FONT=courier new][COLOR=#000000]    TXBASE0 socket C@ #11 SHL + +            [/COLOR][/FONT]
    [FONT=courier new][COLOR=#000000]    LC! SEND[/COLOR][/FONT]
    [COLOR=#000000][FONT=Ubuntu Mono][FONT=courier new]    ;[/FONT][/FONT][/COLOR]
    
    

    So the important thing is to write back the TX_WR register with all it's bits even though we need to mask them off for address calculation.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2013-10-28 19:18
    It seems there isn't a lot of interest on this forum anymore, don't know what's happened, maybe everyone is hanging out for P2. As for me, I am too but P1 is my general workhorse now and will still be even when we have P2.

    I thought I'd share some results I've had with writing this FTP driver in Tachyon for the W5200. My driver which includes just as much in the way of diagnostics as driver only takes up 1.7K bytes of code and variable space at present. The FTP+TELNET takes only 1.2K bytes and that's also with a stab at HTTP included.

    To keep things simple I run the server from the main console cog (under "KEYPOLL") so that I can still access the I/O normally from the terminal. Even though I am still sorting out a few things with FTP data connections, it mostly seems to be working fine with FileZilla etc. As for TELNET that works a charm and I just have it connecting to the Tachyon console so it's like a remote Tachyon console. The FTP command port is also connected to the console where Forth terminal text is normally entered so that the FTP commands are just another word in the Forth dictionary. PASV for instance selects a data port and opens up a socket which is used by LIST and RETR words etc. I can also type these same words in at the serial terminal to see that they work properly.

    So writing this driver was a little bit daunting at first but with Forth it's been a lot of fun as I can interact with the chip and sockets etc live. Can't wait to get into setting up the HTTP server part too.
  • caskazcaskaz Posts: 957
    edited 2013-10-28 22:56
    Hi Peter.
    I think there isn't a lot of interest on Tacheon FTP.
    If spin, I think everybody is interest on this thread.
    I'm very interest on FTP, but I don't understand little about Tachyon.

    There is word reference on Tachyon?
    Although I installed Tachyon v2.1, there are not QWORDS,I2CBUS,NEWCNT,.LAP etc.
    Anymore file need?
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2013-10-28 23:18
    caskaz wrote: »
    Hi Peter.
    I think there isn't a lot of interest on Tacheon FTP.
    If spin, I think everybody is interest on this thread.
    I'm very interest on FTP, but I don't understand little about Tachyon.

    There is word reference on Tachyon?
    Although I installed Tachyon v2.1, there are not QWORDS,I2CBUS,NEWCNT,.LAP etc.
    Anymore file need?

    The intro page does talk about loading EXTEND.fth but maybe it hasn't been stated clearly and explicitly in the documents although I have mentioned it many times. The Spin tool compiled kernel could work without EXTEND.fth but there is a lot of support files in there and so this is normally loaded as standard. Set your terminal for 20ms line delay (not char) to be safe and paste or send the file after which it will automatically back it up if there were no errors. You can always issue a break command in your terminal to get TF to reset itself no matter what.

    Although I had an opportunity to write this in Spin it would have been a lot harder and more complicated. TF is fast enough that I don't need special PASM for anything but really low level SPI.
  • caskazcaskaz Posts: 957
    edited 2013-10-29 02:33
    Hi.

    I try to load EXTEND.fth.
    I copied EXTEND.fth and paste it to TeraTerm.
    Cannot load. I attached screenshot.
    And Tachyon stopped.
    I pushed reset button on protoboard.

    Next I send EXTEND.fth by 'Send'menu to TeraTerm.
    No loading.
    797 x 750 - 60K
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2013-10-29 05:29
    caskaz wrote: »
    Hi.

    I try to load EXTEND.fth.
    I copied EXTEND.fth and paste it to TeraTerm.
    Cannot load. I attached screenshot.
    And Tachyon stopped.
    I pushed reset button on protoboard.

    Next I send EXTEND.fth by 'Send'menu to TeraTerm.
    No loading.

    Looks like you haven't set a line delay, no handshaking, The line delay is pretty much for the worst case where a lot might be packed onto a line and there are a lot of them as well. I've used TeraTerm as well so I will double check the settings but they shouldn't be much different. It's a pity that XON/XOFF can't be used but PCs tend to buffer the XON/XOFF rather than process them immediately in which case we could have much faster loading without any delay settings.
  • max72max72 Posts: 1,155
    edited 2013-10-29 06:29
    I personally am following the discussion and anything related to tachyon.
    At the moment I have little free time so no time to experiment, but I hope to catch up soon..

    Massimo
  • mindrobotsmindrobots Posts: 6,506
    edited 2013-10-29 06:40
    Peter, don't give up on us. I'm reading, bookmarking and planning to come back when time frees up.

    In general, you are right, activity does seem to be down a bit on the forums. Hopefully folks are knee deep in fun Propeller projects and there will be a flurry of new activity (not my excuse).
  • TrapperBobTrapperBob Posts: 142
    edited 2013-10-29 07:08
    Peter,

    I am following Tachyon closely. Like others I am "tethered" at the moment with my day job and have little time to spare.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2013-10-29 09:26
    Peter,
    This is certainly another validation of Forth's utility on the Propeller... faster than Spin, with the interactivity that PASM lacks. I've been quite lately as I'd rather spend time thinking that debating pros and cons (we who use Forth know it is worthwhile).

    pfth has been my main study resource at this point, but Tachyon offers more exotic sophistications.
  • caskazcaskaz Posts: 957
    edited 2013-10-29 16:26
    Hi Peter.

    I set transmit-delay =20msec/line
    Thanks loading is success.
    I have questions.
    Loading EXTEND.fth, this is saved in eeprom?
    If I want to erase this, I use which word?
    765 x 750 - 206K
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2013-10-29 16:41
    caskaz wrote: »
    Hi Peter.

    I set transmit-delay =20msec/line
    Thanks loading is success.
    I have questions.
    Loading EXTEND.fth, this is saved in eeprom?
    If I want to erase this, I use which word?

    Typing COLD will restart TF with just the kernel although the EEPROM has not been changed which means if you reboot it will still have everything there. However if you type COLD and then load in EXTEND.fth it will of course end up overwriting the old image in EEPROM.

    Sometimes I have various modules loaded and then my app in EEPROM and it's a pain to have to load in all the modules again if I want to reload the app so if I have a 64kB EEPROM I use the word BURNROM (for want of a better name) which I use at the point before loading my app or whatever I'm testing. What this does is simply copy the lower 32kB of EEPROM to the top 64kB where it is protected and I then use the RESTORE word to pop that back into the normal space thereby restoring the image with all the stable modules etc. I may actually get around to writing a FORGET word though :)
  • caskazcaskaz Posts: 957
    edited 2013-10-29 21:07
    HI.
    I'm reading MCP3208.fth.
    There are part that I cannot understand.
    Although maybe foolish question, Please give me answer.


    1
    What does mean 'TACHYON' on top line and 'end on last line?
    This need because Tachypn use byte-code?

    2
    What is "pri MCP3208.fth ." MCP3208 8 channel 12-bit ADC - 120828.1000 " ;"?

    3
    Comment word are below?
    { .... }
    \
    ''

    4
    '' Entering pin defs to suit my test pcb
    IFNDEF #miso			'' Define I/O lines if not already defined
    #12	|< CONSTANT #mcp	'' Select mcp3208 chip
    #13 	|< CONSTANT #sck	'' SCK mask
    #14	|< CONSTANT #mosi	'' MOSI
    #15	|< CONSTANT #miso	'' MISO data 
    }
    
    What is last '}'?
    Why 'IFNDEF #miso', Why not 'IFNDEF #mcp'?

    5
    What 'pub FADC@ ( ch -- data )'?
    Why not ': FADC@'?


    6
    What is '[~' and ']~'?
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2013-10-30 00:15
    caskaz wrote: »
    HI.
    I'm reading MCP3208.fth.
    There are part that I cannot understand.
    Although maybe foolish question, Please give me answer.


    1
    What does mean 'TACHYON' on top line and 'end on last line?
    This need because Tachypn use byte-code?

    A: Simply to ensure that we know that this Forth source file is for Tachyon Forth and not some other Forth and this also informs TF to format the response for streaming mode in that we don't really want every character echoed etc.


    2
    What is "pri MCP3208.fth ." MCP3208 8 channel 12-bit ADC - 120828.1000 " ;"?

    A: This is simply to identify the following code which also reports at startup or when you execute the MODULES word (any words that end in .fth are identified as module names). BTW, the "pri" instead of "pub" or ":" is the same thing at present but may be used in some version to remove the name from the dictionary after it has compiled when it encounters the END word.

    3
    Comment word are below?
    { .... }
    \
    ''

    A: Comments are either a \ or braces { } or brackets ( ) and since there is no traditional TIB or text input buffer then these comments may span many lines. Therefore the braces are really redundant as you could just as easily do multi-line comments with brackets ( ).
    Note that " is never a comment and here are some uses for this:

    "#" ............This will place the literal value of the ASCII character # onto the stack. Note that there is no space between the " and the # as this works like the other prefix and suffix operators do for numbers.
    "<space>a string" ................Will compile a null terminated string (temporary or permanent) and leave it's address on the stack.
    [FONT=courier new][B]"#" .[/B] 23 ok
    [/FONT][FONT=courier new][B]" HELLO" 10 DUMP [/B]
    351B: 48 45 4C 4C 4F 00 72 10 B6 25 03 03 00 00 00 00    HELLO.r..%......
    [/FONT]
    
    See NUMBER FORMATS section in the Intro page for further information.

    4
    '' Entering pin defs to suit my test pcb
    IFNDEF #miso            '' Define I/O lines if not already defined
    #12    |< CONSTANT #mcp    '' Select mcp3208 chip
    #13     |< CONSTANT #sck    '' SCK mask
    #14    |< CONSTANT #mosi    '' MOSI
    #15    |< CONSTANT #miso    '' MISO data 
    }
    
    What is last '}'?
    Why 'IFNDEF #miso', Why not 'IFNDEF #mcp'?

    A: KISS leads me to to think if I ignore the rest of this section then it is not much different to a comment except it's conditional so therefore I will treat it like a multi-line comment and terminate it with a right brace. The right brace by itself outside of a comment or if the definition is accepted will be ignored. As for why not then why not #mosi or #sck and as we know if *any* one is missing then that's all we need to know.

    5
    What 'pub FADC@ ( ch -- data )'?
    Why not ': FADC@'?

    A: Forth does not force us to conform to a strict syntax so why should I force this on Propeller users who are familiar with Spin? If this helps to put a friendlier face on Forth than it is no skin off my nose. There is a side benefit though as I use Google docs for a lot of my source code as I can include images etc but I find that the full stop and colon characters are harder to see, they don't really stand out but "pub" certainly does. Also pub and pri allow me to get into the habit of deciding which words need to be exposed and which other ones could be culled from the dictionary if need be.

    6
    What is '[~' and ']~'?

    A: These character sequences are normally intercepted by the PASM receiver cog to tell it to filter out comments, whitespace, etc to enable faster loading. They are also interpreted at the Forth level to do something similar. The preprocessor operation has been deprecated since I made the receive routine run at full throughput with a single stop bit at megabit speeds (in another thread). So they are there simply to improve streaming mode where we paste or send a file through the terminal and they could be incorporated back into TACHYON and END, perhaps. BTW, the tilde sequence was chosen because I found that it out of almost everything I looked at would be unique and unmistakable enough as I didn't want the preprocessor triggering falsely.

    Hope that answers your questions so just let me know if you have any more as sometimes when I answer them I can think of things I need or want to do.

    BTW, if you read the source code from the Google docs links it will make more sense since it includes the diagrams and datasheet info etc.
  • caskazcaskaz Posts: 957
    edited 2013-10-30 01:31
    Thanks Peter.

    Please expalin 4 and 5 again.
    Sorry, I'm NOT good at english.
    Especially, I'm poor at reading long sentense.
    So I cannot understand them at all.
    I can understand other.

    Actually when I watched Tachyon site at first time, I gave up to read it.
    It is hard for me to continue to read because your sentense is long.
    I'm poor at reading long sentense.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2013-10-30 04:57
    caskaz wrote: »
    Thanks Peter.

    Please expalin 4 and 5 again.
    Sorry, I'm NOT good at english.
    Especially, I'm poor at reading long sentense.
    So I cannot understand them at all.
    I can understand other.

    Actually when I watched Tachyon site at first time, I gave up to read it.
    It is hard for me to continue to read because your sentense is long.
    I'm poor at reading long sentense.

    If a sentence is too long you can always put your own full stop in there! :)
    I try to keep the sentence short but as I would speak. I also insert questions in there that could likely pop up in the readers mind, and answer them. So just imagine I am speaking and you ask the question, after which I answer you.

    Let's see if I can keep it succinct.

    Q4. What is last '}'?
    Why 'IFNDEF #miso', Why not 'IFNDEF #mcp'?

    A4. I treat the whole statement as a multi-line comment that is ignored if it is already defined.
    Just like a { comment } the IFNDEF is treated as a { when it has already been defined.
    Compare these two statements that work the same:

    { please ignore this comment }

    IFNDEF TACHYON please ignore this comment }

    Either #miso or #mosi or #mcp or #sck would satisfy the test. Pick one, any one.

    Q5
    What 'pub FADC@ ( ch -- data )'?
    Why not ': FADC@'?

    A5. Because I can do both but Spin people recognize it straight-away as a definition and the name that follows as the name of that definition.
  • prof_brainoprof_braino Posts: 4,313
    edited 2013-10-30 05:13
    I'm just wondering if anyone has written an FTP server for the Prop? I'm wondering if there are any gotchas down the road to look out for.

    Hi Peter

    Sal added Spinerette support a while back (maybe pf4.0?) and included IP, telnet and HTTP. There are two main gotcha's:
    1) the support takes up so much space there is hardy anything left for an application. And Sal didn't even include FTP.
    2) ethernet on a micro is a bit too specialized. It seems most folks can't find a use for it. Its well suited for a limited set of tasks, and most folks used to thinking PC amounts of resources. This is why we switched over to using Raspberry Pi for ethernet, as it provides pretty much a full linux workstation for free.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2013-10-30 06:09
    Hi Peter

    Sal added Spinerette support a while back (maybe pf4.0?) and included IP, telnet and HTTP. There are two main gotcha's:
    1) the support takes up so much space there is hardy anything left for an application. And Sal didn't even include FTP.
    2) ethernet on a micro is a bit too specialized. It seems most folks can't find a use for it. Its well suited for a limited set of tasks, and most folks used to thinking PC amounts of resources. This is why we switched over to using Raspberry Pi for ethernet, as it provides pretty much a full linux workstation for free.

    Hi Doug,

    I don't think I noticed this as I might have taken a look but sometimes it's better not to. With the code size I have achieved so far I can't see it being any problem in a an embedded application, and indeed it already is. There is still plenty of room left over too.

    I do think that ethernet can get a bit complicated but it doesn't have to be, after all we are just trying to pass information between nodes. My application interfaces are very simple Here are a couple of snippets:
    [FONT=courier new]pub ?TELNET
        TELNET SOCKET                                                   \ Use the TELNET socket
        CONNECTED?                                                      \ New connection?
        IF
          LAN ." WELCOME TO THE TACHYON WIZNET TELNET SESSION!" CR CON  \ Welcome banner
          RXWRITE LW@ RXREAD LW! RECV                                   \ Reset rx buffer and receive 
         LANSKT                                                         \ update socket and switch Forth terminal I/O to this LAN socket
        THEN
         DISCONNECTED? DROP                                             \ Process disconnection and discard result
        ;
    
    [/FONT][FONT=courier new]pub SERVER
       socket C@ socket 1+ C!                        \ remember foreground socket
       ?TELNET                                       \ Poll the TELNET server
       ?FTP                                          \ Poll the FTP server
       ?HTTP                                         \ Poll the WEB server
       socket 1+ C@ SOCKET                           \ restore foreground socket
        ;    
    
    pub GO
       !LEDS !WIZIO #50 ms                              \ Setup SPI & I2CBUS LEDS (includes WIZNET RESET & PWRDN)
       &192.168.16.1 GATEWAY                            \ Assign a default gateway
       &255.255.255.0 SUBNET
       &192.168.16.150 SRCIP
       $00.08 $DC.01.02.03 SHAR                         \ dummy MAC, Need to have a unique ID
       $8000 $4000 ADO 0 I L! 4 +LOOP                   \ clear WIZnet transmit buffers (for diagnostics)
       txwr 16 ADO -1 I W! 2 +LOOP                      \ invalidate all txwr pointers (W5200 workaround)
       TELNET SOCKET CLOSE TCP #23 PORT! OPEN LISTEN    \ Setup TELNET
       FTP SOCKET CLOSE TCP #21 PORT! OPEN LISTEN       \ Setup FTP
       HTTP SOCKET CLOSE TCP #80 PORT! OPEN LISTEN      \ Setup HTTP
       ' SERVER keypoll W!                              \ Poll the server in the background
       WIZ?                                             \ report WIZnet status
       ;[/FONT]
    

    EDIT: Here's a screen grab of a telnet session talking to Tachyon and decompiling the ?TELNET word.
    Screenshot from 2013-10-30 23:29:34.png
  • caskazcaskaz Posts: 957
    edited 2013-10-30 15:28
    Hi Peter.
    Thank you very much.
    I understood them.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2013-11-15 04:34
    I'm still testing the network server functions but here's a session from FileZilla logging in and retrieving a file. I have set this up for debugging so it's very slow on the transfer but I am just testing functionality first, there is no reason why that shouldn't ramp up to 100K or so which is fine for the work I'm doing. Later on I will increase the speed of the W5200 SPI to further increase the throughput. BTW, all this including the SPI driver and the SDCARD stuff etc is all running from the main console cog, that's one cog and except for the serial receiver cog and a TIMERTASK cog there are still 5 cogs free.
    [FONT=courier new]Status:    Connecting to 192.168.16.150:21...
    Status:    Connection established, waiting for welcome message...
    Response:    220 WELCOME TO THE TACHYON WIZNET FTP SESSION!
    Command:    USER admin
    Response:     
    Response:    331 User admin OK. Password required
    Command:    PASS *********
    Response:     
    Response:    230 OK. Current restricted directory is /
    Status:    Server does not support non-ASCII characters.
    Status:    Connected
    Status:    Starting download of /MULTIFAT.FTH
    Command:    CWD /
    Response:     
    Response:    250 Directory successfully changed
    Command:    TYPE I
    Response:     
    Response:    200 TYPE is now I
    Command:    PASV
    Response:    227 Entering Passive Mode (192,168,16,150,148,114)
    Command:    RETR MULTIFAT.FTH
    Response:     
    Response:    150 Accepted data connection
    Response:    226 File successfully transferred
    Status:    File transfer successful, transferred 9,353 bytes in 3 seconds[/FONT]
    
    Screenshot from 2013-11-15 22:31:06.jpg
  • D.PD.P Posts: 790
    edited 2013-11-15 09:21
    Nice work Peter, I've been buried in SAP transition at my company, it's taken me 1+ years. Look forward to gettng back to work with Tachyon RSN, I have a list of small equipment to build for small farmers.
Sign In or Register to comment.