Shop OBEX P1 Docs P2 Docs Learn Events
Tachyon NEON V5 (FAT32 and Ethernet Servers in 32kB EEPROM!) - Page 23 — Parallax Forums

Tachyon NEON V5 (FAT32 and Ethernet Servers in 32kB EEPROM!)

11920212325

Comments

  • Ok Wuerfel_21, good advice there on streaming - or lack of it. I'll start slow and work upwards.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2020-08-10 00:57
    I have had it running at 3M but would only really recommend it at 96MHz since 3M will have a 0% baud rate error but at 80Mhz it's more like 2.56% (note). The pasm timing is already pushed since not only does it do some checks on the data and has to update the buffers and head in hub, but it is also running the ping-pong networking in the same cog. Remember that you can connect multiple Props over a multi-dropped I/O or RS485 network and address and talk to each Tachyon console in pseudo full-duplex. The settings for these are under the INTERCOM section.

    This reminds me, I will have to document the ping-pong protocol as I will also implement this on the P2 as well.

    (note) clkfreq/3M @80MHz = 26.66r = 26 ticks but if you use 2962000 baud on the P1 side then ticks = 27 and much less error Perhaps I should round the calculation then.

    P.S. When I said I use CONBAUD all the time I must be mistaken in regards to V5. It seems I have been using the incorrect address for this version :blush:
  • A 2 Mbaud soak test repeating 'WORDS' and 'DIR' prints reliably on 'PCTerm' on a windows pc, but 3 Mbaud fails, so a good result.
  • Peter,
    Just a quick clairification, does the latest version of TF5 auto-select 5 or 10 MHz XTAL?
    Jim
  • RS_Jim wrote: »
    Peter,
    Just a quick clairification, does the latest version of TF5 auto-select 5 or 10 MHz XTAL?
    Jim

    Yes, they all do since many of my systems use 10MHz crystals since I use SMD or cylindrical types rather than the bulky HC49. All the Parallax designs seem to be 5MHz and in the Flip where the 5MHz crystal would be too large they use a 5MHz oscillator.
    So it's an easy thing to have the setpll routine which PhiPi wrote back in 2009 adjust for these two standard frequencies.

  • cool, thanks Peter
  • bob_g4bbybob_g4bby Posts: 440
    edited 2020-08-31 07:26
    Intercom - Just because I have another two P1s doing nothing at the moment I'd like to piggyback another one onto my diy development board and control it by Intercom. I've watched the video on RS485 ping-pong communication and understand from forum that over very short distances all that is required is a 100 ohm safety resistor in series with a single pin from each p1.

    I notice in extend.fth the setup word INTERCOM! ( config baud -- ). Config is defined with an IP long as &GP.ID.TR.TE. I'm guessing this means GP - processor group, ID - this processors' address in that group, TR - pin for transmit/receive, TE - pin to control rs485 chip transmit / receive direction?

    After typing in a test setting &01.01.06.07 1000000 INTERCOM! just as an experiment, tachyon complains:-
    TF5> &01.01.06.07 1000000 INTERCOM! --- NO EEPROM!
    
    How is it really set up, please?
    What settings does a master need versus a slave?
    Just in brief, how would an RS485 chip be connected and what chip is recommended? I am guessing the transmitter and receiver are just back to back and the signal direction set with TE
    When just 100 ohm resistors are used, can you define the TE pin as unused?
    Do I need any ROMS installed?
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2020-08-31 08:03
    bob_g4bby wrote: »
    Intercom - Just because I have another two P1s doing nothing at the moment I'd like to piggyback another one onto my diy development board and control it by Intercom. I've watched the video on RS485 ping-pong communication and understand from forum that over very short distances all that is required is a 100 ohm safety resistor in series with a single pin from each p1.

    I notice in extend.fth the setup word INTERCOM! ( config baud -- ). Config is defined with an IP long as &GP.ID.TR.TE. I'm guessing this means GP - processor group, ID - this processors' address in that group, TR - pin for transmit/receive, TE - pin to control rs485 chip transmit / receive direction?

    After typing in a test setting &01.01.06.07 1000000 INTERCOM! just as an experiment, tachyon complains:-
    TF5> &01.01.06.07 1000000 INTERCOM! --- NO EEPROM!
    
    How is it really set up, please?
    What settings does a master need versus a slave?
    Just in brief, how would an RS485 chip be connected and what chip is recommended? I am guessing the transmitter and receiver are just back to back and the signal direction set with TE
    When just 100 ohm resistors are used, can you define the TE pin as unused?
    Do I need any ROMS installed?

    My bad, it looks like the EEPROM is still busy after the last write and when it goes to ELOAD from there, the EEPROM will not respond. It just needs a short delay but I've got a feeling I removed a busy test that has caused this problem.
    pub INTERCOM! ( config baud -- )
    	9600 2,000,000 LIMIT CLKFREQ SWAP / $34 E!
    	$0F.FF.1F.1F AND $E0.00.00.00 OR $30 E!
    	5 ms
    	$30 $30 $10 ELOAD
    	;
    

    The 100R should be fine although I should check this out myself. It could be that the line may require some kind of pullup for when it is not being driven.

  • Thanks, Peter, I'll give that a try. I'm having fun getting to know Tachyon and writing this si5131 driver for radio use. I couldn't resist looking at the Intercom, though. Very neat.

    It's a sunny, calm morning here with just a hint of autumn, we're off to Clevedon on the Bristol Channel today. The sandwiches and binoculars are packed, so it's the seaside for us today.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2020-08-31 09:06
    It's been a bright sunny 27'C day for us today. No "seaside" for us though, although we do go down to the beach :smile: long long sandy beach :smile:

    Do you mean the Si5351? I have that one running in TAQOZ although I need to add frequency configuration stuff to change it at runtime.
  • bob_g4bbybob_g4bby Posts: 440
    edited 2020-08-31 21:34
    Well the beach was good, faces tingling etc from the sun and the air was clear - good view across the Bristol Channel to Wales. We live about an hour away from Clevedon, which isn't too bad. I wouldn't mind some of your beaches being a bit closer, though, they're something else!

    Yes, I meant I'm writing a driver for the si5351 that you're using on P2D2. It's a popular choice for software defined radios and performs well - I've heard how it sounds. I'm using an integer output division to minimise output jitter and a fractional PLL feedback division so as to be able to (roughly) tune to the nearest 4Hz, over the range 4-120Mhz. To drive a tayloe mixer, the si5351 o/p is further divided by 4 to make two quadrature phased signals in the range 1-30MHz with a high speed 7474 type external chip. The frequency is varied smoothly by a cheap rotary encoder, to around 1 Hz precision. There also needs to be a word to update the assumed crystal frequency having tuned the radio to a frequency standard like WWV.

    Most software reading a rotary encoder you find on the web is not very good. They keep the increment fixed at 1Hz/step, 10Hz/step, 100Hz/step selecteable by a push button. Mm - very clunky. My version detects how many encoder steps have occurred in ( say ) 25mS and then squares that value - or some other non-linear function that feels right. That way, you still get 1Hz tuning steps when the knob is tuned slowly, but if you spin it, you quickly get to the other end of the band. No need for the push button tuning step 'gear change'.

    The trick in calculating the si5351 divider values is to work back from the wanted o/p. The other trick is to minimise the number of bytes that need sending to the chip each frequency change, if the value hasn't changed, don't send it again sort of thing. See https://rfzero.net/tutorials/si5351a/

    The ideal is to mimic the smooth tuning we used to enjoy with analogue radios.

    I'm able to read and write the chip and also calculate the divider values for a given frequency, just need to write more words to split the values up into the required 8 bit registers. I'll post it when it works.
  • @bob_g4bby I have a feeling you are trying to develop a better QCX or QSX (by Hans Summers @QRP Labs) and phase out that atmega328 ? :smile: Because that was my idea also.
  • bob_g4bbybob_g4bby Posts: 440
    edited 2020-08-31 18:12
    Hi Maciek,

    Yes that's the idea, but with a decent low noise 24 bit analogue to digital converter in the front end of the receiver. The P2 would be able to deliver the really clean audio that sd radios are famous for.
    Judging by all the youtube videos, the QCX, QSX or UCX radios https://groups.io/g/ucx sound quality is not the best, although the ATMEGA firmware is really amazing in such a low-power platform.
    An SDR written in Taqoz with selected dsp words in assembly. That would be unique!
    The attached file gives some idea of the circuitry, although this one delivers packets of signal data to a pc for processing
  • The QCX is superb. I know that for a fact. I own one. It's hard to imagine anything (CW radio) better at this price point. I love mine. The only improvement desirable would be if it could do "all bands" in a single package and cost, say. twice as much.
    I'd be delighted if it was based on a Parallax or an ARM mcu with firmware written in forth, be it Tachyon or Mecrisp-Stellaris.

    And speaking of the P2, I hope I could lay my paws on all of the Peters' marvels (P2D2, P2PAL, P2LAB) at some, not to distant point.
  • bob_g4bbybob_g4bby Posts: 440
    edited 2020-09-01 19:29
    INTERCOM! looks like it is overwriting the Tachyon version string. Here is the boot display before running INTERCOM!:-
    Propeller .:.:--TACHYON--:.:. Forth V5r7 NEON 570190926.2300
    
    Here it is after I type in 0 0 INTERCOM!:-
    570190926.2300*  Propeller .:.:--TACHYON--:.:. Forth V5rà
    

    1. Is this Tachyon version valid? I am loading EXTEND.FTH from the dropbox into it. I notice that at the end, 0 0 INTERCOM! is run just before backup. Tachyon still complains about no EEPROM, despite the 5ms delay. When I type it in manually afterwards, it does not complain about no EEPROM

    2. There was a fault with CONBAUD just a while ago, where it was writing to $28 when it should have been $18, which was fixed. Is this a similar issue?
  • bob_g4bbybob_g4bby Posts: 440
    edited 2020-09-01 20:26
    OK, I loaded the binary given to Rsaideka and this boots up as:-
    Propeller .:.:--TACHYON--:.:. Forth V5r7 NEON 570190926.2300
      *** MODULES ***  Propeller .:.:--TACHYON--:.:. Forth V5r7 NEON 570190926.2300
    3C94: EASYFILE         SDHC card + FAT32 Virtual Memory File System V1.2 171024-0000
    300E: TOOLS            DEV TOOLS
    1AC0: EXTEND           Primary extensions to TACHYON V5 kernel  - 200514-0100
    
    
    FREQ = 80.00MHZ
    *** INITS ***
    MOUNT 42DA
    *** ROMS ***
    C01C: HSUART      560
    C260: F32        1900
    C9E0: UART        464
    *** I2C ***
    $A0 EE/RTC
    $C0 unknown
    I/O =  31 :UHUU 27 :~~~~ 23 :~~~~ 19 :~~~~ 15 :~~~~ 11 :~~~~ 7 :~~~~ 3 :UU~U
    INTERCOM: &05.78.32.55 @3,990
    
    CODE:$4D86 = 19334 bytes
    NAME:$52DC = 8484 bytes
    DATA:$7849 = 825 bytes
    FREE:      = 1366 bytes
     Data Stack (0)
    Mon, 01 Jan 2001 00:00:01 UTC *Card Error*
    --------------------------------------------------------------------------------
    TF5>
    

    So the values reported by .INTERCOM there look a bit suspicious.

    When INTERCOM! is reloaded with the 5ms delay fitted, and 0 0 INTERCOM! is type in:-
    TF5>
    
      570190926.2300--TACHYON--:.:. Forth V5rà
      570190926.2300*  Propeller .:.:--TACHYON--:.:. Forth V5rà
    3C94: EASYFILE         SDHC card + FAT32 Virtual Memory File System V1.2 171024-0000
    300E: TOOLS            DEV TOOLS
    1AC0: EXTEND           Primary extensions to TACHYON V5 kernel  - 200514-0100
    
    
    FREQ = 80.00MHZ
    *** INITS ***
    MOUNT 42DA
    *** ROMS ***
    C01C: HSUART      560
    C260: F32        1900
    C9E0: UART        464
    *** I2C ***
    $A0 EE/RTC
    $C0 unknown
    I/O =  31 :UHUU 27 :~~~~ 23 :~~~~ 19 :~~~~ 15 :~~~~ 11 :~~~~ 7 :~~~~ 3 :UU~U
    INTERCOM: &00.00.00.00 @9,600
    
    CODE:$4D86 = 19334 bytes
    NAME:$52DC = 8484 bytes
    DATA:$7849 = 825 bytes
    FREE:      = 1366 bytes
     Data Stack (0)
    Mon, 01 Jan 2001 00:00:01 UTC *Card Error*
    --------------------------------------------------------------------------------
    

    So again, the Tachyon version information gets corrupted and also .INTERCOM reports the value changes, so may also need fixing - maybe other words too that have these 'magic number' memory references.
  • It's been a while since I used intercom and the memory map was rearranged in that time so there could be some conflict. If you find it then good, but I will set it up and check it out when I get a chance.
  • jmgjmg Posts: 15,175
    bob_g4bby wrote: »
    Yes, I meant I'm writing a driver for the si5351 that you're using on P2D2. It's a popular choice for software defined radios and performs well - I've heard how it sounds..

    Have you compared or seen any comparisons of the Si5351 in MSOP10 vs QFN packages ?
    One design I saw used QFN20(4x4) claiming better operation, and I see SiLabs now have a QFN16(3x3) part code, but no stocks showing yet ?
    ( GT = 10-MSOP, GM = 20-QFN, GM1 = 16-QFN)

  • bob_g4bbybob_g4bby Posts: 440
    edited 2020-09-02 07:36
    Jmg,

    I have not seen si5351 packages compared. My experience is limited to using a Multus Proficio all HF band transceiver which uses the si5351a https://multus-sdr.com/index.php?rt=product/product&product_id=123. I use GSDR on Windows with that and with a pair of Bose speakers it is a very clean sounding receiver, with 'brick wall' passband. If you leave the audio on binaural and use headphones it feels like you're 'floating' inside the band. I'm experimenting with an adafruit si5351a module with the P1. This and the si570 have completely eliminated the need for LC tuned oscillators. There were some designs with dds chips, but the si devices cannot be beaten for performance / price. It's a pity the registers are not better suited to variable oscillator use, being originally intended as crystal clocks.
  • Peter,

    I'll download bst and have a go at seeing what the memory map change has affected.
  • bob_g4bbybob_g4bby Posts: 440
    edited 2020-09-04 10:22
    To match the new kernel memory layout in Tachyon 5v7, the words INTERCOM! and .INTERCOM should be defined as:-
    pub INTERCOM! ( config baud -- )
    	9600 2,000,000 LIMIT CLKFREQ SWAP / $24 E!
    	$0F.FF.1F.1F AND $E0.00.00.00 OR $20 E!
    	5 ms
    	$20 $20 $10 ELOAD
    	;
    pub .INTERCOM
    	BOLD PRINT" INTERCOM: " PLAIN
    	$20 @ 0EXIT
    	$23 C@ '&' EMIT >N .DEC2.
    	$22 C@ .DEC2.
    	$21 C@ .DEC2.
    	$20 C@ .DEC2
    	'@' EMIT CLKFREQ $24 @ / .AS" ###,###,~###"
    	;
    
    Near the end of EXTEND.FTH, a small delay was found necessary before the Intercom setting is zeroed, else the zeroing did not work properly as seen after reboot
    5 ms
    0 0 INTERCOM!
    

    I've got RS485.fth to compile under Tachyon 5v7, there were some words whose names had changed and LOADCOG input reqts had changed. Just at the moment !BUS to initialise the comms causes Tachyon to freeze. It gets as far as BUSTX in SELECT. I wonder if the HSUART has evolved after RS485.fth was written. The parameter table buspars in RS485.fth is smaller than that in the HSUART source.

    A drizzly cool day here - so I'm snug in the study, making my own prop plug from a USB serial dongle, which is working, and I can compile and blow tachyon 5v7 into the P1. Little steps forward I think.
    Yesterday was sunny, so a nice little chug in our Lomax (open-top 3 wheeler) to Kemble Airfield where I used to fly a microlight. These days we just sit and drink coffee and watch others commit aviation. Cheers, Bob
  • Hi Bob

    Small world- I live on the other side of Bath in E Bristol.
    Popped over with wife to Wales yesterday, had a picnic on the side of a reservoir. Very pleasant.
    Helped a friend build a microlight many moons ago- I think it was called MW7 by Mike Whitaker.
    The only plane I've flown was an RC slope soarer on Crooks Peak, Westbury White Horse and around and about.
    Currently trying to get my head around wi-fi, 8266, internet etc. Sad really since I used to work in telecoms.....

    Dave
  • bob_g4bbybob_g4bby Posts: 440
    edited 2020-09-02 19:39
    Hah! - Nice one, Dave, practically next door --- Yes, there's certainly plenty to go at with microcontrollers these days, so many applications. I'm a real latecomer to Propeller, but enjoying getting into Tachyon with some homebrew cards. We regularly walk around the Bristol Docks - the BLT rolls and coffee at Underfall Yard are great and there's always something new to see building or repairing on the stocks. Good photography. You can see my little car at www.qrz.com and enter the callsign G4BBY. Microlighting - flew for 8 years, including annual fly/camp hols in France. Me and a pal used to spell each other off, got to within sight of Geneva the one year. The Loire valley another time with all the fancy chateaux was something else. Many photos and good memories.
  • bob_g4bbybob_g4bby Posts: 440
    edited 2020-09-05 13:40
    In Tachyon 5v7 am I using :=! correctly?
    Defining and printing a contant:-
    TF5> 12 := myconstant
    TF5> myconstant . --- 12  ok
    
    Changing the value of the constant:
    TF5> 45 ' myconstant :=! ---  ok
    TF5> myconstant . --- 12  ok
    
    The constant hasn't changed, anyone see the same please?
  • Unfortunately while it does change a constant value, it doesn't change a constant :)
    It changes the 15-bit constant value wordcode like this:
    TF5> : DEMO 1234 ;
    TF5> DEMO . --- 1234  ok
    TF5> 1000 ' DEMO :=! ---  ok
    TF5> DEMO . --- 1000  ok
    

    But constants in Tachyon can be implemented in different ways.
    If the value is less than 32768 then it can be contained in a wordcode where all 15-bit literals are encoded with the msb set.

    If you enter a 15-bit literal within a definition it will be compiled as that value with the msb set. If you enter the 15-bit literal as a named constant then the wordcode value for that will be stored in the header instead of the CFA.

    Normal dictionary record is:
    ATR+COUNT,<NAME>,CFA
    Dictionary record for 15-bit constant is:
    ATR+COUNT,<NAME>,VALUE+$8000
    TF5> 1234 := mycon
    TF5> NFA' mycon 16 DUMP --- 
    0000.5142:  45 6D  79 63 6F 6E  D2 84 45 44  45 4D 4F 32  68 4E    Emycon..EDEMO2hN
    TF5> mycon .W --- 04D2  ok
    

    But if the named constant definition is >32767 then it will compile a long literal in code memory.
    TF5> 12345678 := longcon
    TF5> ' longcon .W --- 4E70  ok
    TF5> ' longcon 16 DUMP --- 
    0000.4E70:   35 00 BC 00  4E 61 5A 00  70 CE 10 80  44 0B 5A 00    5...NaZ.p...D.Z. ok
    
    The address to this long constant is what is compiled when it is referenced.

    I will have to revisit Tachyon and tidy up a few things by the look of it.

  • Thanks Peter,
    I'd been editing HSUART.FTH for use with Tachyon 5 and that seems to be there - it transmits OK at least.
    So then I went back to RS485.FTH which makes some use of 'constants' ( Tachyon 4 allowed 1234 == myconstant ) which are later changed in value. I'll remove those and revert to normal variables.
    I haven't used my Owon cheapy scope so much in ages!
  • MJBMJB Posts: 1,235
    Unfortunately while it does change a constant value, it doesn't change a constant :)
    It changes the 15-bit constant value wordcode like this:
    TF5> : DEMO 1234 ;
    TF5> DEMO . --- 1234  ok
    TF5> 1000 ' DEMO :=! ---  ok
    TF5> DEMO . --- 1000  ok
    

    But constants in Tachyon can be implemented in different ways.
    If the value is less than 32768 then it can be contained in a wordcode where all 15-bit literals are encoded with the msb set.

    If you enter a 15-bit literal within a definition it will be compiled as that value with the msb set. If you enter the 15-bit literal as a named constant then the wordcode value for that will be stored in the header instead of the CFA.

    Normal dictionary record is:
    ATR+COUNT,<NAME>,CFA
    Dictionary record for 15-bit constant is:
    ATR+COUNT,<NAME>,VALUE+$8000
    TF5> 1234 := mycon
    TF5> NFA' mycon 16 DUMP --- 
    0000.5142:  45 6D  79 63 6F 6E  D2 84 45 44  45 4D 4F 32  68 4E    Emycon..EDEMO2hN
    TF5> mycon .W --- 04D2  ok
    

    But if the named constant definition is >32767 then it will compile a long literal in code memory.
    TF5> 12345678 := longcon
    TF5> ' longcon .W --- 4E70  ok
    TF5> ' longcon 16 DUMP --- 
    0000.4E70:   35 00 BC 00  4E 61 5A 00  70 CE 10 80  44 0B 5A 00    5...NaZ.p...D.Z. ok
    
    The address to this long constant is what is compiled when it is referenced.

    I will have to revisit Tachyon and tidy up a few things by the look of it.

    yes - a bit tricky

    there are at least two aspects to it:
    1. using const vor convenience so we do not have to use the @/C@/W@ fetch operators and make the code more readable
    which could be real constants or mutable constants

    2. efficiency reasons like inlining the const value as a wordcode into definitions where it is used - but then it is no longer mutable

    and this combined with 15 bit vs larger constants ...

    for me 1. nice readable code is more important than optimizing 2 bytes and a microsecond in probably all cases I can think of

    and it might not be immediately visible in the example above:

    TF5> NFA' mycon 16 DUMP ---
    0000.5142: 45 6D 79 63 6F 6E D2 84 45 44 45 4D 4F 32 68 4E Emycon..EDEMO2hN
    TF5> mycon .W --- 04D2 ok

    is the value of mycon 1234 or $04D2
    with the high bit set to mark the constant in wordcode
    and then the bytes compiled in changed order ;-)

    but now, when you compile the const into a new word,
    then change its value and compile it into another word.
    Then the first word will use the old value and the second word will use the new value.

    Can be the cause of nasty bugs if you do not understand what you are doing.

  • bob_g4bbybob_g4bby Posts: 440
    edited 2020-11-16 17:22
    I'm in need of some arrays of records and put together the following, which seems to produce the right addresses:-
    --- Records and Record Arrays
    
    IFDEF -RECORD
    	FORGET -RECORD
    }
    
    --- start a record definition, leave zero offset into the record tos
    0	:=	[FIELDS		( 0 -- )
    
    --- define a new field within a record
    pre FIELD				  
    	CREATE OVER W, +        ( offset1 datasize -- offset2 )
    	DOES> R> W@ +           ( recaddr -- recaddr+offset )
    	;
    
    --- finalise a record definition
    ALIAS := FIELDS]
    
    
    --- defining word to create single records
    ALIAS bytes RECORD
    
    --- defining word to create arrays of records
    pre RECORDS ( fieldsize recordnumber <arrayname> -- ; arrayindex -- adr )
    			GRAB 
    			CREATE			--- in the dictionary entry...
    				org@ W,		--- save start address of data
    				OVER W,		--- and save the record size
    				* @org W+!  --- then in the dataspace allot reqd no. of bytes
    			DOES>
    				R@ W@		--- read the start address of the data
    				R> 2+ W@	--- read the record size
    				ROT * +		--- and compute the start addres of the reqd record
    	;
    
    --- example FIELDS definition - FIELD expects the allocated space defined in bytes
    --- This FIELDS definition has the name recorddef
    [FIELDS
    	2 FIELD txbuf
    	2 FIELD status
    	2 FIELD rxrd
    	2 FIELD rxwr
    	64 FIELD rxbuf
    FIELDS] recorddef
    
    --- example definition of a record
    recorddef RECORD MYRECORD
    
    --- example definition of an array of 3 records
     recorddef 3 RECORDS MYRECORDARRAY
    
    --- example use
    MYRECORD rxrd .			--- displays the address of the rxrd field within MYBUF
     1 MYRECORDARRAY rxwr .	--- displays the address of the rxwr field within the 2nd record in MYRECORDARRAY
     
    
  • bob_g4bbybob_g4bby Posts: 440
    edited 2020-09-17 11:38
    Here's Peter's HSUART.fth demo adapted for Tachyon 5v7. It requires the HSUART ROM to be loaded into the top 32k of the EEProm, else it won't work
    TACHYON V5
    { Demonstration of High Speed UART operation }
    
    IFDEF HSUARTDEMO
    	FORGET HSUARTDEMO
    }
    : HSUARTDEMO ;
    
    {
    The HSUART is a ROM in upper EEPROM that can be loaded into a cog.
    It is essentially half-duplex suitable for single wire or RS485 bus but
    works well with full-duplex lines that operate in command/response mode
    which is fairly typical of many communications systems.
    The default mode is 9 data, non parity and 1 stop.
    Extra stop bits may be transmitted by OR'ing in high data bits above bit9
    as b8 is the 9th data bit.
    
    HSUART can operate at well over 2M baud accurately.
    Cogs 4 to 7 can be used
    Cog 3 is either loaded with F32 or a loader but can be used
    Cog 2 is normally loaded with Forth timing function - could possibly be used
    }
    
    64 		:= rxsz			--- receiver buffer size in bytes
    2000000	:= baudrate		--- UART baud rate
    
    --- circular receiver buffer with pointers, one byte transmit buffer, UART status
    72 bytes BUFS
    BUFS org
    2	res	txbuf
    2	res	status
    2	res	rxrd
    2	res	rxwr
    rxsz	res	rxbuf
    
    --- HSUART parameter table required to initialise the UART
    TABLE 485pars
    	&0.01.00.00 ,		--- mode.te.tx.rx, meaning transmit/receive on P0, Transmit Enable signal on P1
    	CLKFREQ baudrate / ,	--- baud rate in cpu ticks
    	rxsz ||			--- receive buffer size
    	txbuf ||			--- single word transmit buffer
    
    
    --- startup HSUART in cog 4
    " HSUART  " 4 485pars LOADCOG
    
    --- to send a character
    pub TRANSMIT ( dat -- )
    	BEGIN
    		txbuf W@ 0=
    	UNTIL
    	$100 OR txbuf W! ;
    
    --- to read a character (non-blocking, returns with 0 if empty)
    pub RECEIVE ( -- dat )
    	rxrd W@ rxwr W@ <>
    	IF 
    		rxwr W@ 
    		DUP rxbuf + C@
    		( $100 OR ) SWAP 1+ rxsz MOD rxwr W!
    	ELSE
    		0
    	THEN
    	;
    
    --- Test words
    
    pub TXTEST BEGIN $AA TRANSMIT KEY UNTIL ;		--- transmit byte AA hex until a key is pressed
    
    
    END
    
    
  • Tachyon Glossary being updated - I've copied the existing glossary https://docs.google.com/document/d/1gkSgKPYidRnhLaqgT7gfNyuhiTuWt-9tNRQC4epr7k4/edit#heading=h.2y2jztxhic28 and am updating it offline to match Tachyon 5v7. I'll post it when I've done as much as possible. There's a lot to add, so I just do a bit per day. I'm adding another column to show pub, pre, pri, variable, constant
    It might be useful to also have it in spreadsheet form, the filtering and sorting being useful in viewing groups of words in many different ways. It imports easily being tab delimited, but I won't do this until the text version is done.
    All in LibreOffice.
    A bit cool in the little 3-wheel Lomax car today - definitely an Autumn feel, but still pleasant bowling along over the timeless Wiltshire Downs with the fallen leaves whirling around us. Meep-meep!
Sign In or Register to comment.