Shop OBEX P1 Docs P2 Docs Learn Events
Can you use FDS4port from different cogs? — Parallax Forums

Can you use FDS4port from different cogs?

T ChapT Chap Posts: 4,223
edited 2009-12-07 05:02 in Propeller 1
I have run out of cogs and have a free port on the 4port. It would be great if two different cogs could use the same 4port. Is something like this even possible? At the moment there are other problems to solve before I can even test the idea.



obj
ser : "FDS4port"

cog1 ser.str(0, string("Hello world"))
cog2 ser.str(1, string("Hello world"))

Comments

  • TimmooreTimmoore Posts: 1,031
    edited 2009-12-06 07:03
    Do you mean pcFullDuplexSerial4FC? Yes you can use it from multiple cogs. If you use multiple cogs to the same serial port then you have to deal with the chars interleaving but it will work.
  • T ChapT Chap Posts: 4,223
    edited 2009-12-06 07:08
    Actually the example shown is not the real need, it is for 4 different serial i/o's to 4 different external devices.

    Thanks

    FullDuplexSerial4port : first port is using parity on receive (10 bits) where the other 3 ports show 9 bits

    Post Edited (Todd Chapman) : 12/6/2009 7:17:21 AM GMT
  • StefanL38StefanL38 Posts: 2,292
    edited 2009-12-06 07:28
    it depends on from which file you want to do the calls of the FDS4-methods.

    As long as ALL calls like

    ser.str(0,...
    ser.str(1,...

    ser.tx(2,byte...

    are in the ONE and SAME file you can do so.

    You can't access methods or variables across *.spinfiles directly
    If the calls are in DIFFERENT *.spin-files it will ONLY work with modifying the code

    For explaining this in detail it would be good if you describe your application in detail
    in which file is the FDS4-object started and in which *.spin-files do you want to use
    calls to the FDS4-methods

    best regards

    Stefan
  • TimmooreTimmoore Posts: 1,031
    edited 2009-12-06 07:40
    You can include pcFullDuplexSerial4FC in multiple files. Start should be called once and all the uses of the object will use the same shared cog for tx/rx. This is how I use it. e.g. Its included multiple times, 1 serial port is for pc debug, used in lots of files/cogs, you get interleaving of the text but its ok for debugging. gps uses 1 port, camera uses another, etc. each port called by a different cog.
  • StefanL38StefanL38 Posts: 2,292
    edited 2009-12-06 16:24
    Aha ?! really ?!?? Maybe this discovered a lack of understanding of me how objects work.
    I would like to clarify this.

    If you want to use an object in different *.spin-files each file has to have a codeline

    OBJ
      FDS4 : "pcFullDuplexSerial4FC"
    
    



    As far as I understand it this means EVERY file where this codeline is defined
    stores code in the HUB-RAM. So if the object is defined in two different files
    all the code is stored two times in HUB-RAM and all the pointers like

      rxbuff_ptr            long      0                   '32 longs for per port buffer hub ptr
      rxbuff_ptr1           long      0
      rxbuff_ptr2           long      0
      rxbuff_ptr3           long      0
      txbuff_ptr            long      0
      txbuff_ptr1           long      0
      txbuff_ptr2           long      0
      txbuff_ptr3           long      0
    
    



    of each instance point to different HUB-RAM adresses

    Now what Timmoore is saying that the object is stored only ONCE in HUB-RAM and as all the pointers are in the DAT-section you can use this pointers across *.SPIN-files

    Is this correct ?

    best regards

    Stefan
  • TimmooreTimmoore Posts: 1,031
    edited 2009-12-06 18:25
    Code is shared across instances, variables in VAR sections are duplicated for each instance, variables in DAT are shared. You need to code round multiple read/write to these shared variables which is why you see interleaved chars if sending to the same serial port from multiple cogs.
  • T ChapT Chap Posts: 4,223
    edited 2009-12-07 05:02
    Thanks for the input fellows.

    The FullDuplexSerial4Port did exactly what I was hoping.

    Below is just an oversimplified example of what is really happening, all 4 ports working simultaneously. Port 3 is actually
    an LCD, which will print from any of the other ports, including the new cog.

    VAR
       byte  buffer1, buffer2, buffer3, buffer4
    
    OBJ 
      ser    :  "FullDuplexSerial4Port"
    
    PUB MainProgram
        Start4port          'set all i/o, baud
        cognew(newprogram, @newstack)
        repeat
          buffer0  := ser.rx(0)    'read port 0
          buffer2  := ser.rx(2)    'read port 2
          buffer3  := ser.rx(3)    'read port 3        
    
    PUB newprogram
        repeat 
          buffer1  := ser.rx(1)    ''read port 1
    
    

    Post Edited (Todd Chapman) : 12/7/2009 5:09:48 AM GMT
Sign In or Register to comment.