Shop OBEX P1 Docs P2 Docs Learn Events
Tachyon V4 "DAWN" - exploring new worlds - Page 26 — Parallax Forums

Tachyon V4 "DAWN" - exploring new worlds

12426282930

Comments

  • Shawn Lowe wrote: »
    MJB wrote: »
    Hi PEter,
    long time ago we talked about nRF24L01+
    did you ever write code for it?
    I am just getting back to a possible application and still have some unused parts here ...

    I never did get these setup but only just the other day I was looking at what I could use for a link over 30m and of course these chips certainly are a possibility. I may end up getting sidetracked......
    Sweeet! I just bought 10 of these and havent used them yet

    30m is very optimistic. This module is using non-spread-spectrum signalling on the same band as
    microwave ovens and WiFi, its a very noisy and intermittent channel. If you want range, go for other ISM bands
    which don't have to complete with 900W magnetrons. 5m is plausible in a domestic setting in my experience,
    maybe 10 with the lowest baud rate, though there is a version with an LNA and PA which will improve that
    somewhat, 10dB or so I think.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2017-10-24 11:58
    @proplem - since the stack is kept in hub RAM you can access it from by reading the loop stack pointer from cog register 17.
    The top of the loop stack is only in cog memory so you only have to go back to the end of the second entry for the index K.
    : K	17 COG@ $14 - @ ;
    

    I will put it into V4.7 EXTEND for convenience.
  • MJBMJB Posts: 1,235
    Hi Peter,
    is there an example of using the PingPong Network somewhere?
    I was thinking to integrate another AVR-Micro as a sensor slave as well.


  • MJB wrote: »
    Hi Peter,
    is there an example of using the PingPong Network somewhere?
    I was thinking to integrate another AVR-Micro as a sensor slave as well.

    The main advantage of using the PingPong type network is that it provides high-speed full-duplex console access to distributed Prop chips and there are modes built-in that allow a Prop to be loaded or read transparently from within the driver too. The master though doesn't use the built-in PingPong network itself so there is no advantage in having a Prop master and non-Prop slaves using this network other than the fact that it is self-pacing and effectively full-duplex due to the ping pong nature of data transfers.

    However, the protocol is fairly simple itself and once a connection is made then data can just be exchanged as if it were point to point. I will see if I can setup a micro as a slave, I even have some old AVR devices floating around. I think I probably need to document the protocol too but I guess you've seen the video.




  • MJBMJB Posts: 1,235
    edited 2017-10-24 14:50
    MJB wrote: »
    Hi PEter,
    long time ago we talked about nRF24L01+
    did you ever write code for it?
    I am just getting back to a possible application and still have some unused parts here ...

    I never did get these setup but only just the other day I was looking at what I could use for a link over 30m and of course these chips certainly are a possibility. I may end up getting sidetracked......

    there was ( nRF24L01.fth ) on your google drive
    and I found this locally: ... shared on google

  • Cluso99Cluso99 Posts: 18,069
    Nice job Peter. Those pcbs look good too!
  • Dipping my big Tachyon toe into nRF24L01 waters

    Well I decided not to look at anything I may have done before with this chip, which really was nothing. So I sat down with the datasheet and within 5 minutes I had written my first bit of code that can read the registers and use the external DUMP word to automatically read the chip as if it were memory.
    pub !RFIO	&11.14.13.12 SPIPINS ;
    5 bytes rfbuf
    pub RFREAD ( adr cnt -- buf )	SWAP SPIWRB SWAP FOR SPIRD rfbuf I+ C! NEXT SPICE DROP rfbuf ;
    pub RFC@ ( adr -- byte )	SPIWRB SPIRD SPICE >B ;
    pub RFW@ ( adr -- word )	2 RFREAD W@ ;
    pub RF@ ( adr -- long )		4 RFREAD @ ;
    pub RF		DUMP: RFC@ RFW@ RF@ ;
    { Testing dump of registers
    ..  0 $40 RF DUMP
    0000.0000:   08 3F 03 03  03 02 0F 0E  00 00 E7 C2  C3 C4 C5 C6    .?..............
    0000.0010:   E7 00 00 00  00 00 00 11  00 00 00 00  00 00 68 00    ..............h.
    0000.0020:   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00    ................
    0000.0030:   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00    ................ ok
    }
    

    It all worked first go and I can dump bytes/words/longs and I may include doubles to allow for 5 bytes. The reset values of the registers match the datasheet.

    Now, that's the sort of productivity we could have with P2!!!!
  • MJBMJB Posts: 1,235
    Dipping my big Tachyon toe into nRF24L01 waters

    Well I decided not to look at anything I may have done before with this chip, which really was nothing. So I sat down with the datasheet and within 5 minutes I had written my first bit of code that can read the registers and use the external DUMP word to automatically read the chip as if it were memory.
    pub !RFIO	&11.14.13.12 SPIPINS ;
    5 bytes rfbuf
    pub RFREAD ( adr cnt -- buf )	SWAP SPIWRB SWAP FOR SPIRD rfbuf I+ C! NEXT SPICE DROP rfbuf ;
    pub RFC@ ( adr -- byte )	SPIWRB SPIRD SPICE >B ;
    pub RFW@ ( adr -- word )	2 RFREAD W@ ;
    pub RF@ ( adr -- long )		4 RFREAD @ ;
    pub RF		DUMP: RFC@ RFW@ RF@ ;
    { Testing dump of registers
    ..  0 $40 RF DUMP
    0000.0000:   08 3F 03 03  03 02 0F 0E  00 00 E7 C2  C3 C4 C5 C6    .?..............
    0000.0010:   E7 00 00 00  00 00 00 11  00 00 00 00  00 00 68 00    ..............h.
    0000.0020:   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00    ................
    0000.0030:   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00    ................ ok
    }
    

    It all worked first go and I can dump bytes/words/longs and I may include doubles to allow for 5 bytes. The reset values of the registers match the datasheet.

    Now, that's the sort of productivity we could have with P2!!!!

    I see the same - great
    so now for the more specific code ...
  • proplemproplem Posts: 233
    edited 2017-10-27 10:11
    @Peter, thanks a lot for the responsiveness. "K" is working fine and again I learned something more about the inner workings.

    I've got another issue which has been discussed a while ago - RS232
    My setup: IoT5500
    ..  .VER   Propeller .:.:--TACHYON--:.:. Forth V4.5 DAWN 450170727.1400 ok          
    ..  .MODULES *** MODULES ***                                                        
                           Propeller .:.:--TACHYON--:.:. Forth V4.5 DAWN 450170727.1400 
    52FA: EASYNET.fth         WIZNET NETWORK SERVERS 170821.0000                        
    4A74: W5500.fth           WIZNET W5500 driver 170708.0000                           
                                                                                        
    3800: EASYFILE.fth        SDHC card + FAT32 Virtual Memory Access File System Layer 
    1B40: EXTEND.fth          Primary extensions to TACHYON V4.5 kernel  - 170814-1100 k
    

    Trying the following code with 115200 BAUD misled me and I was hunting phantoms quite a while until I reduced the baudrate to 9600 and suddenly it was working.
    	#15 == _rx
    	#14 == _tx
    	38400 == hc06baud                         \ default baudrate can be increased
    	word rxrd
    	word rxwr
    	#128 == rxsize
    	rxsize BYTES bufHC06
    	12 LONGS stackHC06
    
    	pub HC06.TASK ( -- ) \ Buffer data from the HC06 port - nothing else
    	\	stackHC06 SP! !SP                     \ init data stack to 0, assign stack to this task
    		stackHC06 LP!                         \ v4r5: init stack to 0, assign stack to this task
    		hc06baud SERBAUD                      \ how fast are we going
    		rxrd W~ rxwr W~ bufHC06 rxsize ERASE  \ clear rxrd, rxwr and erase bufHC06
    		BEGIN
    		_rx SERIN rxwr W@                  \ get serial byte, fetch rxwr bufHC06 index( -- 0 datadr )
    		rxsize 1- AND bufHC06 + C!         \ compute bufHC06 addr and write data to buffer
    		rxwr W++                           \ increment buffer pointer
    		AGAIN
    		;
    
    	pub HC06GET ( -- ch|0 ) \ You can read the buffered data with this
    			 rxrd W@ rxsize 1- AND rxwr W@ rxsize 1- AND <>   \ compute if the buffer is empty
    			 IF
    				 rxrd W@ rxsize 1- AND bufHC06 + C@
    				 rxrd W++
    			 ELSE 0
    			 THEN
    			;
    
    	pub HC06START ' HC06.TASK TASK? RUN ;
    
    	: HC06EMIT hc06baud SERBAUD _tx SEROUT ;
    	: HC06 ' HC06EMIT uemit W! ;
    
    	HC06START \ to start
    	1000 ms \ wait a moment at startup
    
    	HC06 CR ." CR .DATE SPACE .TIME" CR CON _tx FLOAT bufHC06 rxsize DUMP
    

    I tried 115200 BAUD but it delivered garbage in the receive buffer using an IoT5500 with direct connection from pin 14 to pin 15.

    I don't need the RS232 comm for a HC06 device as I want to communicate between 2 propellers. I'd like it 115200 baud or even faster if possible.

    Any advice to get faster?

    BTW: this serial interface code and its buffering is such a miracle - it is nearly nothing and it works. I saw buffering code in lengthes of KBytes with many errors. As Forth is Zen - this code is. (Ohh: It is copied from the forum, it's not from me :-)

    Thanks, best regards
    proplem

    Edit: For those researching for RS232 communication with tachyon: On a propeller clocked by 96 MHz ( for example IoT5500 ) this code is tested working up to 38400 baud. If more speed is needed, look for UARTCOG.FTH which can do higher rates.
  • @proplem - V4.5 has a UART ROM which handles full-duplex as well as the HSUART ROM for high speed auto half-duplex. Have a look at UARTCOG.FTH as you can specify the buffer sizes you need at runtime etc and it will handle 115,200 baud very easily.

    @MJB - That's about all the time I had to spend on it yesterday but I will play a bit more with it today. Did you notice the $68 in the undocumented register $1E ? All 8-bits seem to be writable but I have found nothing about it on the web except that registers $18..$1B are used for factory testing.
  • MJBMJB Posts: 1,235
    @MJB - That's about all the time I had to spend on it yesterday but I will play a bit more with it today. Did you notice the $68 in the undocumented register $1E ? All 8-bits seem to be writable but I have found nothing about it on the web except that registers $18..$1B are used for factory testing.

    with "so now for the more specific code ... " I was talking about myself - not rushing you ...

    I tried writing to register 0 with strange bhaviour.

    the modules CSN corresponds to SPI CE.
    and CE activates the radio -
    will test again tomorrow


  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2017-10-26 01:03
    @MJB - there was a little bug in the posted code although that was fixed up in the dropbox version that ended up writing to registers it was trying to read in the invalid $20 up range.
    Have a look at NRF24L01 in the V4.7 folder.
    I am just looking at Nordic's BASCOM code, it looks very inefficient. For instance take this bit of code that writes to a register:
    D_bytes(1) = C_Write_reg + R_En_aa                              'Enable auto ACK for pipe0
    D_bytes(2) = &H01
    Call W_register(2)
    
    In Tachyon it is simply:
    1 EN_AA RFC!
    
    The same goes for writing the 5 byte address registers, just use a double number, the register, and RFD!
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2017-10-26 11:17
    nRF24L01+ PROMISCUOUS MODE

    I'm "playing around" with the nRF24L01 in promiscuous mode and having a lot fun :)

    Anyone "played around" as well?

    Here is a quick view of what I'm seeing using an illegal 2-byte address to catch preambles, in this case I just tried $5555 for fun.
    The listing starts with a dump of the registers and each line begins with the Tachyon runtime counter in milliseconds:
    ..  $5555 RXADR SNIFF 
    0000.0000:   03 00 01 00  04 28 0F 40  00 00 55 2B  2C 2D 2E 2F    .....(.@..U+,-./
    0000.0010:   73 20 32 33  34 35 36 12  00 00 00 00  3C 05 3D 00    s 23456.....<.=.
      817743   AA AA AA 9A AE AB 55 55 54 B5 55 35 55 57 55 55 55 55 55 55 55 55 55 55 55 4D 55 55 B5 55 55 55 
      817749   55 4A 95 08 A4 E2 C5 53 22 B5 66 F5 25 50 AA 94 CA 88 5A 8A 91 2E AA A4 2A 9A 05 43 84 AA 6A A6 
      817756   64 C1 B5 07 6F 4B 4C 8D 44 E2 D5 B3 54 B2 AC 6A DA B7 5E 12 D1 DD C5 FA E2 62 4D E9 A9 C3 4A 39 
      817762   57 2B E8 DE A5 29 5E EE 8A 56 C4 95 25 6D 57 8B 1A E4 E6 AD F3 E9 54 B3 F7 CF 2A 8A 13 81 55 7E 
      817769   CA 62 2B 4A 59 25 1A B5 D1 1D 68 4C AA CA AA 15 16 1A 8D 11 3A 01 05 29 51 84 A5 28 8F B5 FB CD 
      817775   55 55 5D 5D 75 DD DD 75 DD 5D 76 D7 5D 5D 75 5D DD DD 75 5D 55 D7 75 75 D5 57 5B 76 AA AC CB 4D 
      817781   55 A7 25 CA 9B 53 BD 67 57 7A AE 97 2E DB E5 55 52 D7 54 6B 66 A9 65 50 3D B6 AE DB 6A D4 BA 55 
      817788   69 AD 4C AD 58 79 EB A6 DF 5F D9 0B AF 36 D3 5E E5 FB 2D 6A A9 4B BC BC D7 AA 9E A7 1C A4 DD B6 
      817794   05 40 A1 49 5A CB 41 15 44 60 A5 F4 55 10 76 97 41 F5 1C 68 72 10 44 38 63 93 1A EF 85 4C 55 17 
      817801   57 55 55 55 55 55 55 5B 57 55 55 55 D7 57 55 55 5D 4D 55 55 55 55 B5 55 55 AB 55 55 55 55 55 55 
      817807   5A 49 13 35 AA A9 95 AB 56 14 D0 B6 BA 87 A8 C9 A2 81 79 45 05 A5 6A 95 0D 4E 81 44 81 52 56 85 
      817813   94 B0 2B 47 57 32 5D 54 42 D7 96 A7 42 C6 82 54 A7 55 50 A9 E1 65 8D 19 DA 66 9C 09 56 DF 79 5A 
      817820   53 2A D7 A5 60 E1 E1 B4 D2 D4 A4 45 E5 48 43 64 D7 5D 6A E9 55 55 5B 49 6A CA EB 2E 9E 53 8F 85 
      817826   9A D8 D4 49 28 A0 95 64 C0 46 94 49 28 4F B7 19 48 60 9D 4D 55 60 56 93 C1 24 B6 17 45 13 AE 54 
      817833   00 46 DF BC CF 7E 9F 4D AD E9 B7 AB CB F4 81 95 50 6B B9 1C AA 1D 26 2E 87 B5 CD BD 06 55 55 4E 
      817839   52 4B 15 30 20 84 92 55 E2 19 58 B0 8C 8A 94 5C FC 28 14 2E 8C BB 21 05 AB 35 A6 94 46 91 67 A8 
      817845   57 AE CA A0 A6 DE 6E 33 AA 9A 5D 69 D7 C5 8E 4B 81 CC F2 F4 A7 2A C9 AB 1E 99 D8 6B 2B 4B 51 6C 
      817852   9A D6 BC 95 AB EA AB CB D5 33 73 B9 FB 64 9A DA B1 AB 93 2A E5 AB D7 B5 6A 79 CD 75 FA FA BA 79 
      817858   A1 A6 8A 9C 6D 51 2E 17 2D E5 BA CA 4B 16 2D 6A 90 C2 A5 09 26 96 C2 A2 C3 22 08 0D 0D 5A 55 C1 
      817865   55 55 55 55 77 7C AD 35 2A D5 57 5D 5D 57 5D 75 F5 57 5D D7 5D DD CB 7D 57 DD 77 57 5D D5 77 75 
      817874   55 55 55 55 55 75 6D DD 75 5B 77 57 5D D5 77 6A D6 D5 D7 55 5D 57 75 6D 76 DD D7 7D 95 5D DB 75 
      817880   95 B5 D5 D7 55 DC DF 5D 5D 5D 75 5D CD DD 77 7C D7 5D 55 75 7D 75 55 DD DB 5D 5A CB 54 AC A4 A3 
      817887   85 4A 1E 9B 95 58 C9 4A 85 A6 51 52 61 D5 E3 1B 2A E2 AB 2C 28 89 54 41 15 9D 3C A8 70 4A AE 95 
      817893   65 7E 2B 66 ED 55 37 25 51 2B 7B 61 AA 72 B8 D6 F7 B2 9D 52 E9 A4 26 A8 08 80 48 A9 00 49 51 04 
      817899   55 84 48 52 56 82 A4 8A 5A 42 32 E5 0A 54 75 AC 08 F5 BD 3C 01 30 4D 05 5A 15 50 82 96 45 2A F7 
      817906   0A 54 5A 50 A5 55 18 A8 08 85 53 16 B1 0C A5 49 4A 0B 46 25 55 25 E5 22 08 A0 01 04 31 8B 46 59 
      817912   EA D7 5D FF F7 F7 C6 55 7D D7 F7 55 77 57 D7 77 9E 07 5F DE 1E 59 1F 57 DD 7E 19 5D 5D D7 5F 5F 
      817918   05 22 A2 A3 25 5A D4 F6 D2 E3 96 B6 AC EA E5 87 A9 1B 6B 54 F6 BD E3 AC 04 5A 28 ED 6E 9C 62 54 
      817925   A4 89 5B 4A 9B 5E 9D 8A 1A 92 D5 AD 5D AB 82 54 B4 4C 29 75 29 4D 8B 16 5B A4 AB 9A 89 0A 94 28 
    
    Source code is in the V4.7 folder as SNIFFER.FTH



  • Hi there,

    @Peter I'm fighting with UARTCOG.FTH ...

    I built a word to output the RS232 settings:
    pub .COM ( adr -- ) --- output settings to console
    \ usage: uart1 .COM
      1 LOCAL
    	CR ." ---=== serial comm parameters ===---"
    	CR ." rx     " X1  0 + C@  .
    	CR ." tx     " X1  1 + C@  .
    	CR ." mode   " X1  2 + W@  .
    	CR ." baud   " CLKFREQ X1  4 +  @  / .
    	CR ." rxbuf(sz: " X1 10 + W@  DUP . ." ): "
    	CR ." rxwr   " X1 16 + W@  0 + W@ .
    	CR ." rxrd   " X1 16 + W@  2 + W@ .
    	X1  8 + W@ SWAP DUMP
    	CR ." txbuf(sz: " X1 14 + W@  DUP . ." ): "
    	CR ." txwr   " X1 16 + W@  4 + W@ .
    	CR ." txrd   " X1 16 + W@  6 + W@ .
    	X1  12 + W@ SWAP DUMP
    	1 RELEASE
    	;
    

    It results in
    uart1 .COM                                                                      
    ---=== serial comm parameters ===---                                                
    rx     14                                                                           
    tx     15                                                                           
    mode   0                                                                            
    baud   19200                                                                        
    rxbuf(sz: 32):                                                                      
    rxwr   0                                                                            
    rxrd   0                                                                            
    0000.7CCC:   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00    ................ 
    0000.7CDC:   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00    ................ 
    txbuf(sz: 32):                                                                      
    txwr   2                                                                            
    txrd   0                                                                            
    0000.7D4C:   61 62 00 00  00 00 00 00  00 00 00 00  00 00 00 00    ab.............. 
    0000.7D5C:   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00    ................k
    ..
    

    What I'd like to add would be the variable name for which .COM was called. Example:
    uart1 .COM
    
    should give
    ---=== 'uart1' serial comm parameters ===---                                                
    rx     14                                                                           
    tx     15                                                                           
    
    This is again such a CFA, PFA, NFA thing I asked some time ago but things changed since a lot :-))
    Can you give an example how I get the dictionary name for a given address?
    pub FETCHNAME ( adr -- str )
      CFA/PFA/WHATEVERFA>NFA PRINT$
      ;
    
    Usage:
    uart1 FETCHNAME uart1 ok
    

    Thanks in advance,
    proplem
  • proplemproplem Posts: 233
    edited 2017-10-27 13:33
    Hi there,
    I'm still struggling with UARTCOG.FTH.

    As I didn't use ROMS before I had to try a lot to get the UARTCOG.FTH code running which in the end failed.

    My current v4r5 kernel does not contain the UART ROM :-(
    .. " HSUART   "  FINDROM . 58226 ok                                                
    ..  " UART     "  FINDROM . 0 ok                                                    
    .
    

    I looked into v4r7 which contains the UART ROM but I hesitate to upgrade because the whole EASYFILE EASYNET shebang for my IoT5500 project would have to run.
    Only the kernel v4r7 with my v4r5 has about 200 differences. This promises upgrade difficulties.

    Is it easier to insert the UART ROM into v4r5 to get UARTCOG.FTH running? May it be just copy and paste?

    Thanks in advance to supporters,
    proplem

    Stop! Don't answer patching UART ROM into v4r5 spin wasn't difficult only a few modifications
    ..  " HSUART   "  FINDROM . 58706 ok 
    ..  " UART     "  FINDROM . 58226 ok
    
  • proplemproplem Posts: 233
    edited 2017-10-28 09:52
    Hi @Peter - COGUART.FTH is running.

    As I wanted to test the communication with minicom over 115200 Baud there rose a new issue:

    Setting the baudrate with
    115200 UARTBAUD
    
    and reading the written value back with
    CLKFREQ uart1  4 +  @  / .
    
    gave back
    115246
    
    This is reasoned of losing some decimals by the division
    Is there a way to communicate with exactly 115200 Baud via UARTCOG.FTH ?
  • @proplem - If you happen to have a 5.5296MHz crystal lying around x16 = 88.473600MHz /115,200 = 768 etc etc. I doubt very much though that ending up with the less perfect 115246 will cause any kind of problem. Back in the day of UART chips we'd use 11.0592Mhz or 3.6864 crystals etc just to get that exact baudrate.
  • ErNaErNa Posts: 1,752
    Hi proplem, this should not have any influence, because the, as Peter said in the meantime, the clock just samples the middle of every bit and we only have 10 or 11 of them.
  • Thanks to you both - so communcation should work with minicom by setting 115200 baud ?
    So the error must sit in front of the keyboard?
  • Hurray - UARTCOG talks with minicom with 115246 Baud mincom is now happy with it. I don't know what I did wrong yesterday ...
    Thanks again!!!
  • Hi there - I need a technical term:
    Executing
    long myvar
    ' myvar
    
    What is the thing lying now on top of stack called?
  • MJBMJB Posts: 1,235
    @MJB - That's about all the time I had to spend on it yesterday but I will play a bit more with it today. Did you notice the $68 in the undocumented register $1E ? All 8-bits seem to be writable but I have found nothing about it on the web except that registers $18..$1B are used for factory testing.

    with "so now for the more specific code ... " I was talking about myself - not rushing you ...

    I tried writing to register 0 with strange bhaviour.

    the modules CSN corresponds to SPI CE.
    and CE activates the radio -
    will test again tomorrow

    proplem wrote: »
    Hi there - I need a technical term:
    Executing
    long myvar
    ' myvar
    
    What is the thing lying now on top of stack called?
    
    ' [']
    ATICK   word  @NFATICK+s,DUP,ZEXIT,@NFABFA+s,@WFETCHX+t
    
    ' ' <name>  ( -- pfa ) Find the address of the following word - zero if not found or it's PFA (bytecodes do not have a CFA)
    TICK    word  @ATICK+s,@LITCOMP+t
    
    
    

    NFA - Name Field Address
    CFA - code field address
    BFA - Byte/wordcode field address


    ' BFA is the address of the wordcode stored in the header that is executed or compiled
    ' NFA points to the first byte
    ' NFA>BFA ( nfa -- bfa )
    '
    ' CFA>NFA ( wordcode -- nfa )
  • Good morning @MJB, thanks for the kind reply.
    MJB wrote: »
    proplem wrote: »
    Hi there - I need a technical term:
    Executing
    long myvar
    ' myvar
    
    What is the thing lying now on top of stack called?
    
    ' [']
    ATICK   word  @NFATICK+s,DUP,ZEXIT,@NFABFA+s,@WFETCHX+t
    
    ' ' <name>  ( -- pfa ) Find the address of the following word - zero if not found or it's PFA (bytecodes do not have a CFA)
    TICK    word  @ATICK+s,@LITCOMP+t
    
    
    

    NFA - Name Field Address
    CFA - code field address
    BFA - Byte/wordcode field address


    ' BFA is the address of the wordcode stored in the header that is executed or compiled
    ' NFA points to the first byte
    ' NFA>BFA ( nfa -- bfa )
    '
    ' CFA>NFA ( wordcode -- nfa )
    I know these terms and Forth words already although I don't understand them fully. Especially and TICK I can't use. I think they don't answer my question so I try to reformulate my intention. It's a pity that there seems to be no technical term for the ' variable thing I asked before.

    After some research I meanwhile can Interactively find and output the name of the calling word like this:
    ..  pub FETCHNAME                                                                                   
    ..       CFA>NFA 1+ DUP PRINT$ ;                                                                    
    ..  long myvar ' myvar FETCHNAME myvar ok
    
    That's well what I wanted so far if I'm working interactively but ...

    What I'd really like to do is:
    pub ANYFUNC ( var/adr -- )
      CR ."  <" FETCHNAME ." > stood before the call" ;
    
    Usage:
    long anyvar ANYFUNC
    
    and the resulting output should be:
    <anyvar> stood before the call
    
    How can I get the ' variable thing from the memory address on the top of stack?
  • MJBMJB Posts: 1,235
    I know these terms and Forth words already although I don't understand them fully. Especially and TICK I can't use. I think they don't answer my question so I try to reformulate my intention. It's a pity that there seems to be no technical term for the ' variable thing I asked before.

    After some research I meanwhile can Interactively find and output the name of the calling word like this:
    ..  pub FETCHNAME                                                                                   
    ..       CFA>NFA 1+ DUP PRINT$ ;                                                                    
    ..  long myvar ' myvar FETCHNAME myvar ok
    
    That's well what I wanted so far if I'm working interactively but ...

    What I'd really like to do is:
    pub ANYFUNC ( var/adr -- )
      CR ."  <" FETCHNAME ." > stood before the call" ;
    
    Usage:
    long anyvar ANYFUNC
    
    and the resulting output should be:
    <anyvar> stood before the call
    
    How can I get the ' variable thing from the memory address on the top of stack?
    Proplem,
    long anyvar
    
    does not leave anything on the stack ...
    you want
    anyvar 
    ANYFUNC
    
    ??
    so given a top of stack value - if it was a variable address, what is the variable's name?

    what do you need this funcion for ?

  • @MJB - thanks for asking back. You are right with "does not leave anything on the stack" (Typo! Grmbl!#!)
    MJB wrote: »
    Proplem,
    long anyvar
    
    does not leave anything on the stack ...
    you want
    anyvar 
    ANYFUNC
    
    ??
    so given a top of stack value - if it was a variable address, what is the variable's name?

    what do you need this funcion for ?
    what I meant to write was:
    long anyvar
    anyvar ANYFUNC
    

    What I intend to do is to get the name of a variable/word from its address.
    Why? There are several reasons:
    1. reason: (untested code - just for information)
    pub .COM ( adr/var -- ) \ output config data for serial interface
      CR ." serial port <" DUP FETCHNAME " > settings"
      \ ... code to output the register settings of the given serial port
      ;
    
    usage (just to give an example):
    uart1 .COM
    serial port <uart1> settings
    rx: 1
    tx: 2
    rxsiz: 32
    rxbuf : $1234 ok
    uart2 .COM
    serial port <uart2> settings
    rx: 3
    tx: 4
    rxsiz: 32
    rxbuf : $2234 ok
    uart3 .COM
    serial port <uart3> settings
    rx: 5
    tx: 6
    rxsiz: 32
    rxbuf : $3234 ok
    

    2. reason:
    I have a table (list) of variables addresses maybe like this:
    long myvar1
    myvar 4 + ORG
    0 DS *SOV* --- start of variables
    4 DS myvar2
    4 DS myvar3
    4 DS myvar4
    0 DS *EOV* --- end of variables
    
    These variables are set in any way ...
    Now I want to iterate over this list between *SOV* and *EOV* and send every variable in the list over RS232 to another prop.
    This looping is a thing I have to implement. I want to iterate elementwise, dereference the name of the variable according to the address and send that via rs232. I can't write that down yet but I need to dereference the variable name from its address.

    I hope it's clearer now - thanks for your help
  • @proplem - take a look at .VARS which dumps all the variables/constants it can find.
    ..  .VARS 
    77EC defstk      77E8 fnumB      77E4 fnumA      77E0 result     77DC f32cmd     1F00 romsz
    76EE tibwr       76DE polls      76DC _job       2CAC tz         0007 SUN        0006 SAT
    0005 FRI         0004 THU        0003 WED        0002 TUE        0001 MON        76D2 rtcbuf
    76D0 @day        76CC @date      76C8 @time      76C4 runtime    76B4 wdt        76B2 tid
    2A44 timers      0080 ep         76B1 eeadr      76B0 i2cflg     76AC brg        76AA htsav
    76A8 rh          76A6 htref      76A5 htck       000A @SPISCK    000F @SCL       0005 @CNT
    0004 @CE         0003 @MISO      0002 @MOSI      0001 @SCK       76A4 _ctr       76A0 _ansi
    0007 white       0006 cyan       0005 magenta    0004 blue       0003 yellow     0002 green
    0001 red         0000 black      769C radix      7664 @x4        7660 @x3        765C @x2
    7658 locals      01FF VSCL       01FE VCFG       01FD PHSB       01FC PHSA       01FB FRQB
    01FA FRQA        01F9 CTRB       01F8 CTRA       01F7 DIRB       01F6 DIRA       01F5 OUTB
    01F4 OUTA        01F3 INB        01F2 INA        01F1 CNT        01F0 PAR        01F0 SPR
    7654 NULL$       7650 boot       764C ~c         7648 @3         7644 @2         7624 astk
    0000 FALSE       7614 NUM$       7610 ulong      0060 CLKMHZ     009A names      0018 VER
    7800 BUFFERS     00B8 @org       0000 OFF        00BA dmm        00A8 errors     00A0 uhere
    00A2 uthere      00B0 flags      008C prompt     00A6 uauto      00B2 keypoll    00C4 lastkey
    0092 rx          0600 id         1124 keytable ok
    

    If you want to find the NFA of a variable or constant just $8000 OR before to convert it to a 15-bit literal wordcode and then do a CFA>NFA.
  • MJBMJB Posts: 1,235
    proplem wrote: »
    @MJB - thanks for asking back. You are right with "does not leave anything on the stack" (Typo! Grmbl!#!)
    MJB wrote: »
    Proplem,
    long anyvar
    
    does not leave anything on the stack ...
    you want
    anyvar 
    ANYFUNC
    
    ??
    so given a top of stack value - if it was a variable address, what is the variable's name?

    what do you need this funcion for ?
    what I meant to write was:
    long anyvar
    anyvar ANYFUNC
    

    What I intend to do is to get the name of a variable/word from its address.
    Why? There are several reasons:
    1. reason: (untested code - just for information)
    pub .COM ( adr/var -- ) \ output config data for serial interface
      CR ." serial port <" DUP FETCHNAME " > settings"
      \ ... code to output the register settings of the given serial port
      ;
    
    usage (just to give an example):

    2. reason:
    I have a table (list) of variables addresses maybe like this:
    long myvar1
    myvar 4 + ORG
    0 DS *SOV* --- start of variables
    4 DS myvar2
    4 DS myvar3
    4 DS myvar4
    0 DS *EOV* --- end of variables
    
    These variables are set in any way ...
    Now I want to iterate over this list between *SOV* and *EOV* and send every variable in the list over RS232 to another prop.
    This looping is a thing I have to implement. I want to iterate elementwise, dereference the name of the variable according to the address and send that via rs232. I can't write that down yet but I need to dereference the variable name from its address.

    I hope it's clearer now - thanks for your help

    maybe this is shorter ...
    and you can use the solution to 1. in the loop as well
    3 LONGS myvar1
    myvar1 4 +  ORG
    4 DS myvar2
    4 DS myvar3
    
    3 FOR myvar1 I 4 * + @ . NEXT
    
  • @Peter, @MJB - you got it! Nearly.
    ...
    If you want to find the NFA of a variable or constant just $8000 OR before to convert it to a 15-bit literal wordcode and then do a CFA>NFA.
    long myvar
    myvar $8000 OR CFA>NFA 1+ PRINT$ myvar ok
    
    is exactly what I wanted.

    It is terrible how many posts i create to get such a simple solution - really funny, but:
    There is still one thing open:
    TABLE uart1
    ---	rx  tx  mode
    	0 | 1 | 0 ||
    ---	baudrate ticks
    	CLKFREQ 19,200 / ,
    ---	rxbuf, rxsiz
    	rxbuf1 || 32 ||
    ---	txbuf, txsiz
    	txbuf1 || 32 ||
    ---	ptr to buffer word indices (rxwr,rxrd,txwr,txrd)
    	rxwr1 ||
    
    Unfortunately here the trick doesn't work:
    uart1 $8000 OR CFA>NFA 1+ PRINT$ � ok
    
    The solution to this is what I need (but didn't know myself)
    sniff :surprise:
    Nevertheless thanks at lot to both of you.
  • MJBMJB Posts: 1,235
    proplem wrote: »
    @Peter, @MJB - you got it! Nearly.
    ...
    If you want to find the NFA of a variable or constant just $8000 OR before to convert it to a 15-bit literal wordcode and then do a CFA>NFA.
    long myvar
    myvar $8000 OR CFA>NFA 1+ PRINT$ myvar ok
    
    is exactly what I wanted.

    It is terrible how many posts i create to get such a simple solution - really funny, but:
    There is still one thing open:
    TABLE uart1
    ---	rx  tx  mode
    	0 | 1 | 0 ||
    ---	baudrate ticks
    	CLKFREQ 19,200 / ,
    ---	rxbuf, rxsiz
    	rxbuf1 || 32 ||
    ---	txbuf, txsiz
    	txbuf1 || 32 ||
    ---	ptr to buffer word indices (rxwr,rxrd,txwr,txrd)
    	rxwr1 ||
    
    Unfortunately here the trick doesn't work:
    uart1 $8000 OR CFA>NFA 1+ PRINT$ � ok
    
    The solution to this is what I need (but didn't know myself)
    sniff :surprise:
    Nevertheless thanks at lot to both of you.
    TABLE xyz
    xyz 2- CFA>NFA PRINT$
    

  • MJBMJB Posts: 1,235
    @proplem
    my JSON writer - using this as well ...
    TACHYON
    [~
    FORGET JSON.fth
    pub JSON.fth        PRINT" MJB: JSON writer 140928.2300 " ;
    
    {
    This is a quite usable, simple JSON writer implementation
    
    we can use  { }  objects
    or arrays   [ ]  at top level.  
    Objects can contain named arrays or named values
    and Arrays can contain objects or simple values referenced by 0-based index
    
    see example at end of file
    
    }
    
    \ UNPRIVATE COMMA			\ COMMA is private, but we need it
    KEEP COMMA
    \ RECLAIM					\ since we define a number of (very small) words we need dict space
    
    {
    NAMES:  $4F6A...7442 for 9432
    CODE:   $0000...4CAE for 10198 (4294967286 bytes added)
    CALLS:  0122 vectors free
    RAM:    0700 bytes free
    
    Reclaimed 1,552 bytes
    NAMES:  $557A...7442 for 7880 (4294965744 bytes added)
    CODE:   $0000...4CAE for 11750 (4294967286 bytes added)
    CALLS:  0122 vectors free
    RAM:    2252 bytes free
    
    after load
    
    NAMES:  $54F8...7442 for 8010 (4294965874 bytes added)
    CODE:   $0000...4D42 for 11768 (0148 bytes added)
    CALLS:  0102 vectors free
    RAM:    1974 bytes free
    }
    
    pri j$ """ EMIT PRINT$ """ EMIT ;  \ emit string in quotes
    pub J: DUP 2- CFA>NFA j$ ." : ";   \ emit variable name plus :
    
    CREATE j, 0 C,			\  trick because BYTE does not work on j,
    
    pub J,  j, C@ IF COMMA  ELSE j, C~~ THEN ;
    
    pub J$ J, J: j$ ;
    
    pub JB  J, 
    pri jb  C@ $280A .NUM  ;
    pub JB$ J, J: jb ;
    
    pub JW J,
    pri jw W@ $280A .NUM  ;
    pub JW$ J, J: jw ;
    
    pub JL J,
    pri jl @ $280A .NUM  ;
    pub JL$ J, J: jl ;
    
    pub J{ j, C~ "{" EMIT  ;
    pub J} "}" EMIT CR ;
    pub J[ j, C~  "[" EMIT   ;
    pub J] "]" EMIT CR ;
    
    pub .J$ J, """ EMIT PRINT$ """ EMIT ":" EMIT ;
    
    ]~
    END
    
    { DEMO
    
    " Hello" 8 STRING x$
    
    x$ PRINT$
    BYTE b1
    #17 b1 C!
    5 BYTES ar1
    5 FOR "A" IX + ar1 IX + 1- C! NEXT
    
    pub Jtest 
    	J{	\ start object
    		x$ J$    \ write string name + contents
    		b1  JB$    \ write a byte variables name plus its value
    		" arr " .J$ J[   	 \ start an array
    			ar1 5 ADO I JB  LOOP   \ write a byte array with 5 elements, terminate with null
    		J]		 \  end the array
    	J}  \ end object
    ;
    Jtest
    }
    
    
Sign In or Register to comment.