Shop OBEX P1 Docs P2 Docs Learn Events
Feasibilty: Cogs as storage areas — Parallax Forums

Feasibilty: Cogs as storage areas

RiJoRiRiJoRi Posts: 157
edited 2009-05-25 19:03 in Propeller 1
This is NOT for a project. It's simple curiosity.

Would it be possible to use cogs for storage? That is, each unused cog would have a reader and a writer routine, and the working code would do something like "IndexX=WriteCogX(longDatum)" or "longDatum=ReadCogX(IndexX)" or something like that. Of course, error checking and limit testing would be needed.

--Rich
«1

Comments

  • Mike HuseltonMike Huselton Posts: 746
    edited 2009-05-21 19:02
    Yes. Chip Gracey has suggested the use of cogs as ancillary storage several times. Before the chip prices went down, users would likely see this useage of precious cog space as wasteful.

    Since the PropII is about one year away (see Chip's recent video), any techniques to increase fast RAM space such as this will be valuable.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    JMH

    Post Edited (James Michael Huselton) : 5/21/2009 7:10:38 PM GMT
  • heaterheater Posts: 3,370
    edited 2009-05-21 19:03
    Well most Prop drivers, e.g. FullDuplex Serial or the SD card driver, have a PASM part that accepts data to be transmitted somewhere outside the Prop. Serial line or SD card say. Often there is a buffer in the COG where data is stored on its way in or out of the Prop. Same for incoming data.

    So yes. But you might have to be desperate for space to to it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
  • ericballericball Posts: 774
    edited 2009-05-21 19:30
    ''  VAR    ' parameter block is 4 sequential words
    ''  WORD cogdest  ' cog destination register
    ''  WORD hubsrc  ' hub source address
    ''  WORD cogsrc  ' cog source register
    ''  WORD hubdst  ' hub destination address
    PUB start( parmptr )
      stop
      RESULT := COGNEW( @cogstart, parmptr)
      cog := RESULT + 1
      RETURN
    PUB stop
       COGSTOP( cog~ - 1 )
    VAR
      BYTE cog
    DAT
      ORG     0
    cogstart MOV OUTA, PAR
      RDLONG OUTA, OUTA  WZ
      MOVD :rdlong, OUTA
      SHR OUTA, #16
    :rdlong IF_NZ RDLONG 0+OUTA, OUTA
    
      MOV OUTA, PAR
      ADD OUTA, #4
      RDLONG OUTA, OUTA  WZ
      MOVD :wrlong, OUTA
      SHR OUTA, #16
    :wrlong IF_NZ WRLONG 0+OUTA, OUTA
      JMP #cogstart
    
    

    Thanks MagIO2, I've fixed the bug. (One I've made before, and will probably make again - you'd think I'd learn.)

    The amount of fuss this topic has generated is ... amusing.· I whacked out this routine just to show one way it could be done - a minimal but functional version.· (Actually, this is the second version, but I think only JMH saw the first one.)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Composite NTSC sprite driver: http://forums.parallax.com/showthread.php?p=800114
    NTSC color bars (template): http://forums.parallax.com/showthread.php?p=803904


    Post Edited (ericball) : 5/24/2009 10:25:16 PM GMT
  • Mike HuseltonMike Huselton Posts: 746
    edited 2009-05-21 19:39
    Yes.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    JMH
  • RiJoRiRiJoRi Posts: 157
    edited 2009-05-22 13:00
    I thank you all!

    --Rich
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-05-22 13:06
    ...
    
      MOVD :wrlong, OUTA
      SHR OUTA, #16
    :wrlong IF_NZ WRLONG 0+OUTA, OUTA
    [color=red]  JMP #cogstart[/color]
    
  • JonnyMacJonnyMac Posts: 9,195
    edited 2009-05-23 18:18
    As a programming practice exercise I created an object called jm_cogram -- not sure if it's practical, but it does seem to work the way you want.
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-05-23 20:28
    Hi Jonny,

    that's of course a nice exercise, but I'd prefere to use erics version ... after only a minor change. I'd let the PASM routine set the adress back to 0 after it did it's job, so the program that needs the extra RAM does not have to take care of stopping the PASM to overwrite the HUB/COG-RAM again and again.

    The problem I have with your version is that it adds a lot of overhead and needs more COG RAM. RAM access should be as fast as possible. Erics version is presumably fast enough for SPIN that you can use the copied value with the next SPIN instruction after setting the adress. Your version uses extra getter and setter functions which only waste time and HUB-RAM.
  • JonnyMacJonnyMac Posts: 9,195
    edited 2009-05-23 21:46
    MagIO2 said...
    I'd prefere to use erics version
    Great, use Eric's version.

    I prefer clarity over clever, and as I stated this was a programming exercise for myself and possibly to help others learning to mix PASM into Spin programs. I made no claims about it other that I tested it and it works. And, finally, it does in fact do what the original poster asked for (write and read longs with named routines).
    MagIO2 said...
    ... after only a minor change. <snip> Erics [noparse][[/noparse]sic] version is presumably fast <snip>
    If you're going to lay into someone with unsolicited criticism perhaps you should have the decency to post working code. Talk is cheap.
  • James LongJames Long Posts: 1,181
    edited 2009-05-23 21:54
    JonnyMac said...
    MagIO2 said...
    I'd prefere to use erics version
    Great, use Eric's version.

    I prefer clarity over clever, and as I stated this was a programming exercise for myself and possibly to help others learning to mix PASM into Spin programs. I made no claims about it other that I tested it and it works. And, finally, it does in fact do what the original poster asked for (write and read longs with named routines).
    MagIO2 said...
    ... after only a minor change. <snip> Erics [noparse][[/noparse]sic] version is presumably fast <snip>
    If you're going to lay into someone with unsolicited criticism perhaps you should have the decency to post working code. Talk is cheap.

    Jonny,

    Although Mag's posting seems critical, I do not think he was trying to be. I presume he was only pointing out areas which may be improved. I find Mag is typically helpful, or has been for me in the past.

    Everyone seems to be on edge lately. I hope everyone can settle down and be more flexible.

    James L

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    James L
    Partner/Designer

    Lil Brother SMT Assembly Services

    Please note: Due to economic conditions the light at the end of the tunnel will be turned off until further notice. Thanks for your understanding.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-05-23 21:55
    Here's another way (untested):

    {{
    
    Exchange data between hub and cog.
    
    cmdaddr points to a single long:
    
      w000000c_cccccccc__hhhhhhhh_hhhhhhhh, where
    
      w = 1: write data to cog; w = 0: read data from cog;
      c_cccccccc = cog address; and
      hhhhhhhh_hhhhhhhh = hub address.
    
    The entire long should be assigned at once, not as
    two separate words, e.g.:
    
      command := WRITE | cogaddr << 16 | @hubvar, where
    
    CON
    
      READ  = 0
      WRITE = $8000_0000
    
    Once the transfer is made, the command is zeroed.
    
    }}
    
    VAR
    
      byte  cog
    
    PUB start(cmdaddr)
    
      stop
      return cog := cognew(@hubxcog, cmdaddr) + 1
    
    PUB stop
    
      if (cog)
        cogstop(cog - 1)
    
    DAT
    
                            org     0
    hubxcog                 rdlong  outa,par        'Read command.
                            mov     frqa,outa       'Write source address to bot transfers.
                            rol     outa,#16 wc,wz  'Swap words in command. Carry is high bit of cog addr.
    :xferin  if_c_and_nz    rdlong  outa,frqa       'If command is non-zero and carry set, transfer data in.
    :xferout if_nc_and_nz   wrlong  outa,frqa       'If command is non-zero and carry clear, transfer data out.
             if_nz          wrlong  dira,par        'If command is non-zero, zero it.
                            jmp     #hubxcog        'Back for another command.
    
    
    


    -Phil
  • JonnyMacJonnyMac Posts: 9,195
    edited 2009-05-23 22:09
    James Long said...
    <snip>Everyone seems to be on edge lately. I hope everyone can settle down and be more flexible.

    I appreciate you comments, James, but will say that it is NOT helpful for anyone to post criticisms without demonstration that the criticism is something more than opinion. That said, it takes time to write working code and no time at all to run someone else's work down. It's rude.

    Look, I'm new to the Propeller and freely admit it; I write programs for others as a way of stretching my own programming muscles. But this isn't the first time that something I've posted has been met with an snobby reply, and I don't need it -- that treatment is not in the spirit of the way these forums (overall) have worked in the past. I think I'll just do my experiments at home and save what I create for my Nuts & Volts column; this forum (outside of Phil and a couple others) seems filled with a group of people who want nothing more than to prove how clever they are. And I thought the Propeller was supposed to be fun....
  • jazzedjazzed Posts: 11,803
    edited 2009-05-23 22:15
    Why not just use the B registers if you need more for the routine variables? I would be a little skittish about using DIRA.

    If one needs to use COG registers for storage it seems important make the handler routine as small as possible.
    Clarity would be less important unless maybe you're writing an article for Nuts & Volts.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Steve


    Propalyzer: Propeller PC Logic Analyzer
    http://forums.parallax.com/showthread.php?p=788230
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-05-23 22:19
    Steve,

    dira is only used as a zero and will always be zero. It never gets written to. The B registers would work, too.

    -Phil
  • jazzedjazzed Posts: 11,803
    edited 2009-05-23 22:28
    Didn't notice that [noparse]:)[/noparse] Makes sense. Sure beats adding another variable just for handshake.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Steve


    Propalyzer: Propeller PC Logic Analyzer
    http://forums.parallax.com/showthread.php?p=788230
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-05-23 22:30
    Oh gread actor ... I'm so sorry that I upset you so much!
    Maybe it's an occupational disease that you can not withstand criticism - but you posted in a forum. If you don't like what might come as a response, then DON'T POST!
    MagIO2 said...
    Hi Jonny,

    that's of course a nice exercise
    I think I started very good, didn't I? And what came after that was by no means harsh or degrading, I only said my opinion AND I think each other who's learning should be aware what the drawback in your solution is. If you don't take care of execution speed and/or HUB/COG-RAM usage, then fine ... your version works as well without any doubt.
    JonnyMac said...
    I prefer clarity over clever,
    If you only light some LED's you can easily say so. But even you propeller would not run with clever programming - e.g. have a look at the spin interpreter or the FullDuplexSerial. The propeller has been designed to do clever things with it (but it will also work for you.)
    JonnyMac said...
    If you're going to lay into someone with unsolicited criticism perhaps you should have the decency to post working code.
    Erics code is working, isn't it? (besides the little bug) So I can't see a reason to post it again. But I think you refere to
    MagIO2 said...
    I'd let the PASM routine set the adress back to 0 after it did it's job, so the program that needs the extra RAM does not have to take care of stopping the PASM to overwrite the HUB/COG-RAM again and again.
    well ... that shows that you don't understand Erics version at all ... but somehow that fits to "I prefer clarity over clever".

    Let me explain it:
    Erics version is simply an endless loop. You start it with giving an adress of 2 longs. Each long holds a HUB-RAM and a COG-RAM adress. The first long is used to copy from HUB to COG, the second is used to copy from COG to HUB. If one of these longs equals 0 that particular copy is skipped. As the PASM itself does not set the longs to 0 after the job, the code outside of the COG has to take care of that. If it's some SPIN code·setting the long to 0·would increase runtime much more than letting the COG set the long to 0 itself. If you are not clever enough to add 2 wrlong to Erics code, let me know and I'll provide a version including some demo-code.

    Now I got a little bit harsh ... but you asked for it.
  • James LongJames Long Posts: 1,181
    edited 2009-05-23 22:37
    JonnyMac said...
    James Long said...
    <snip>Everyone seems to be on edge lately. I hope everyone can settle down and be more flexible.

    I appreciate you comments, James, but will say that it is NOT helpful for anyone to post criticisms without demonstration that the criticism is something more than opinion. That said, it takes time to write working code and no time at all to run someone else's work down. It's rude.

    Look, I'm new to the Propeller and freely admit it; I write programs for others as a way of stretching my own programming muscles. But this isn't the first time that something I've posted has been met with an snobby reply, and I don't need it -- that treatment is not in the spirit of the way these forums (overall) have worked in the past. I think I'll just do my experiments at home and save what I create for my Nuts & Volts column; this forum (outside of Phil and a couple others) seems filled with a group of people who want nothing more than to prove how clever they are. And I thought the Propeller was supposed to be fun....

    I know others here which do not post much appreciate you and others like you who openly share their experience and code. I too appreciate people who do share their code, although I have not "borrowed" any of yours as of yet.

    I agree, you make a valid point. Coding does take time, and talk is cheap.

    I personally find the majority of the members here are very willing to help, and knowledgeable. There is always going to be a percentage of members who "one up" the next or criticize someone else.

    I try to bridge the gaps, and keep the conversations friendly, especially if I know the offending poster does have the knowledge to help.

    I still find fun with the propeller, and know others do as well.

    James L

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    James L
    Partner/Designer

    Lil Brother SMT Assembly Services

    Please note: Due to economic conditions the light at the end of the tunnel will be turned off until further notice. Thanks for your understanding.
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-05-23 22:41
    @phil:
    Another nice version. Eric's version is still interesting if you have two SPIN COG's running. One can write to the RAM, the other one can read from it simultaneously. Would make a good FIFO buffer.
  • JonnyMacJonnyMac Posts: 9,195
    edited 2009-05-23 22:49
    jazzed said...
    <snip>Clarity would be less important unless maybe you're writing an article for Nuts & Volts.

    This is my *problem* -- most of what I write has to be explained, in detail, for others. The tragedy (my opinion) of this forum is that there are great programmers who don't seem to want to document or fully demonstrate their code; that makes it tough on those of us with less experience who are trying to learn from it. What's obvious to one person isn't always obvious to another.

    I will push on. I've never claimed to be the sharpest tool in the shed and it may take me longer to get it that the rest of you.
  • James LongJames Long Posts: 1,181
    edited 2009-05-23 22:59
    JonnyMac said...
    jazzed said...
    <snip>Clarity would be less important unless maybe you're writing an article for Nuts & Volts.

    This is my *problem* -- most of what I write has to be explained, in detail, for others. The tragedy (my opinion) of this forum is that there are great programmers who don't seem to want to document or fully demonstrate their code; that makes it tough on those of us with less experience who are trying to learn from it. What's obvious to one person isn't always obvious to another.

    I will push on. I've never claimed to be the sharpest tool in the shed and it may take me longer to get it that the rest of you.

    Jonny,

    Don't feel alone. I'm about as sharp as a spoon, most of the time.

    I too find the same problem as you, when reading others code. I even have a hard time when it's documented to death. If you don't believe me, ask Mike Green. I had to ask him how to use one of his objects, and he tends to document pretty well (my opinion).

    James L

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    James L
    Partner/Designer

    Lil Brother SMT Assembly Services

    Please note: Due to economic conditions the light at the end of the tunnel will be turned off until further notice. Thanks for your understanding.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-05-23 23:07
    JonnyMac said...
    ...this forum (outside of Phil and a couple others) seems filled with a group of people who want nothing more than to prove how clever they are. And I thought the Propeller was supposed to be fun...
    Jon, you give me way too much credit! Demonstrating one's cleverness is part of the fun. We almost never talk about it in such terms, but some of the best code in this forum has come from clever people trying to outdo each other. In some ways, the forum is like a mini economy, with street cred being the medium of exchange. It's completely venal, I know, and I'm just as vulnerable to the vice as anyone. And, yes, if I had to be brutally honest about it, I'd have to confess that this vice, more than altruism, is what drives whatever forum obsession I may have. Does that make me, or anyone else thus possessed a bad person? I don't think so; at least I hope not. A competitive spirit is part of human nature, and the learning that results from a little competition can benefit everyone, so long as said competition is good-natured and doesn't malign the efforts of beginners.

    Oh, boy! I bet I've broken one or two forum taboos with that admission! smile.gif

    -Phil
  • James LongJames Long Posts: 1,181
    edited 2009-05-23 23:13
    Phil Pilgrim (PhiPi) said...
    JonnyMac said...
    ...this forum (outside of Phil and a couple others) seems filled with a group of people who want nothing more than to prove how clever they are. And I thought the Propeller was supposed to be fun...
    Jon, you give me way too much credit! Demonstrating one's cleverness is part of the fun. We almost never talk about it in such terms, but some of the best code in this forum has come from clever people trying to outdo each other. In some ways, the forum is like a mini economy, with street cred being the medium of exchange. It's completely venal, I know, and I'm just as vulnerable to the vice as anyone. And, yes, if I had to be brutally honest about it, I'd have to confess that this vice, more than altruism, is what drives whatever forum obsession I may have. Does that make me, or anyone else thus possessed a bad person? I don't think so; at least I hope not. A competitive spirit is part of human nature, and the learning that results from a little competition can benefit everyone, so long as said competition is good-natured and doesn't malign the efforts of beginners.

    Oh, boy! I bet I've broken one or two forum taboos with that admission! smile.gif

    -Phil

    Now........Into the dungeon with ye!!!!

    Yea....but some of us can't compete on the "one up" combat. I can't "one up" anyone. I guess I'll have to watch. smilewinkgrin.gif

    James L

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    James L
    Partner/Designer

    Lil Brother SMT Assembly Services

    Please note: Due to economic conditions the light at the end of the tunnel will be turned off until further notice. Thanks for your understanding.
  • jazzedjazzed Posts: 11,803
    edited 2009-05-23 23:33
    Jon & James, I hope it's clear my "Clarity" quote was stated with good intentions. A "writer" should know the audience and write accordingly.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Steve


    Propalyzer: Propeller PC Logic Analyzer
    http://forums.parallax.com/showthread.php?p=788230
  • Mike HuseltonMike Huselton Posts: 746
    edited 2009-05-23 23:51
    I must confess to the crime of showing off (false pride). Mike green set me straight in another current thread. I got carried away with my undeserved conceit and my imaginary cleverness. I will tone it down and do a better job of fully explaining myself. I'm sure it will help me to understand two weeks from now what the heck I was so wound up trying to say. Calm, clear thoughts ... ommmmm.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    JMH
  • JonnyMacJonnyMac Posts: 9,195
    edited 2009-05-24 00:15
    Wow, this has turned into quite an entertaining thread -- I guess us lowly actors are good for something! tongue.gif

    @Steve: You're "clarity" comment was understood in the spirit it was intended.

    @Phil: You do post some crazy code that sometimes makes my head spin (no pun intended), but to your great credit you always add comments that give us mere mortals a fighting chance to figure it out. Thank you for that.

    It turns out that -- with the small fix pointed out -- Eric's code does indeed work (nobody's surprised). I've attached a demo that uses Eric's PASM code but I've changed the interface a bit after seeing the way Phil did it; this just seemed a little safer to me. For you guru's (who are not interested in beating me about the head and neck) please let me know if I've erred in the comments added to Eric's code. Thanks.

    Post Edited (JonnyMac) : 5/24/2009 12:26:58 AM GMT
  • hinvhinv Posts: 1,255
    edited 2009-05-24 17:15
    Phil, you did it again. Showing off your vocabulary this time. nono.gif
    I had to go look up venal in wikipedia

    Mag, I appreciate your explanation of eric's code. I didn't think you were being upity the first post, but even being bad because you were falsely accused of being bad isn't justified.

    Jonny, check out http://forums.parallax.com/forums/default.aspx?f=25&p=8&m=343952. mctriva did an excellent job at getting back to the issue even though he was attacked. The attacker later came back with some useful contributions, and it worked out well for everyone involved.
    It's a bit of a long thread, but it is a good example of clash mitigation.

    Just my 10 bits worth.
    Doug
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-05-24 18:42
    @Jonny:

    You should have left Erics header in the code, you can see on a first glance how to pass the parameters instead of reading the whole code.

    Now only one exercise is left: Eric's Code is running in an endless - loop. So, if you don't clear the adress-pointers after the value has been copied, the COG will copy it again and again. This is error-prone as it can possibly overwrite a value that has been updated by the SPIN-code meanwhile. If the COG set's the adress to 0 after the copy-job, this is no longer a problem as it copies the value only once. That's what the Z flag is good for. Of course the loop will be a bit slower, but it's still faster than setting the adress-parameters to 0 in the SPIN-code.

    What I'd be interested in is,·does the inval have the correct value in the next SPIN-instruction already or do you have to wait for it for a short while?

    This piece of code can be very useful in case you want to/have to divide data collection from data processing in a so called First In First Out manner. One COG is busy with reading data from ... dunno .. the serial interface in high speed. So no time is left to process the data without loosing the next characters. Then it could simply write into this COG and another SPIN-code running in an additional COG can get the data from there and process it.



    Post Edited (MagIO2) : 5/24/2009 6:48:34 PM GMT
  • JonnyMacJonnyMac Posts: 9,195
    edited 2009-05-24 20:20
    I tried Eric's header -- it didn't work in my demo (would hang after one loop and I am not yet experienced enough to determine why). I liked the way Phil set the source and destination in one fell swoop; this seemed safer for the reasons you suggest (the loop operating between Spin instructions).

    Here's an idea: Along with your theories and criticisms, why not post some code for the rest of us to learn from?... Tested code, that is.


    [noparse][[/noparse]Edit] I'm not sure what caused the problem yesterday but today's a new day so I went back and tried Eric's header again. Today I made sure that I set the destination for either call first; I don't know that I had done this yesterday and this may have caused the program to overwrite something critical and hang the program.

    Post Edited (JonnyMac) : 5/24/2009 9:05:30 PM GMT
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-05-24 21:07
    '  VAR    ' parameter block is 2 sequential longs with the following meaning
    ' long 1 
    '  WORD cogdest  ' cog destination register
    '  WORD hubsrc  ' hub source address
    ' long 2
    '  WORD cogsrc  ' cog source register
    '  WORD hubdst  ' hub destination address
    
    

    This is what I meant with Eric's header ... well my mistake it's not the header of the file, but the header of the PASM section. I think keeping this comments helps in understanding how the parameters work.

                            org     0
    [color=green]cogstart                mov     outa, par               ' get address of wrcommand
                            rdlong  outa, outa      wz      ' hub --> cog command? (not 0)
                            movd    hub2cog, outa           ' cogdest is dest field for rdlong
    [/color]                [color=red]if_nz   wrlong  ctra, par[/color]
    [color=green]                        shr     outa, #16               ' outa := hubsrc[/color]
    [color=green]hub2cog         if_nz   rdlong  0+outa, outa            ' cogdest <-- hubsrc
     
                            mov     outa, par
                            add     outa, #4                ' point to rdcommand
                            [color=red]mov     outb, outa[/color]
                            rdlong  outa, outa      wz      ' cog --> hub command? (not 0)
                            movd    cog2hub, outa           ' cogsrc is dest field for wrlong
    [/color]                [color=red]if_nz   wrlong  ctra, outb[/color]
    [color=green]                        shr     outa, #16               ' outa := hubdest[/color]
    [color=green]cog2hub         if_nz   wrlong  0+outa, outa            ' cogsrc --> hubdest[/color]
    [color=green]                        jmp     #cogstart[/color]                 
    
    

    That's how I would have changed Eric's code. (And now I did ;o) The green part is the original code. As I already mentioned it's an endless loop and it's much faster than the SPIN code. Each time it fetches the wrcommand or the rdcommand it set's the zero-flag. So, if the wr/rdcommand is 0·the according value is not copied at all. In Erics version the SPIN code has to clear wr/rdcommand to avoid the PASM code to overwrite data again and again. In my modified version the PASM-code set's the wr/rdcommands back to zero itself. So in the next loop it won't copy again unless it get's a new adress from the SPIN-code. If you have some other PASM program which uses this RAM-COG, then it's even more helpful, because then this can be used to synchronize both COGs. PASM COG sets an adress and waits until the RAM-COG set the parameter back to 0. Then the PASM COG can be sure that the value has been copied.

    And .. I tried the usage of the COG-RAM with your SPIN-test-program. And the PASM-code is really fast enough to copy the data in 'no spin-time' ;o) So, the invar can directly be used in the next SPIN instruction. Please have a look at the attached modified version of your code. I added a cpyinvar and asssigned it the value of invar straight after setting the rdcommand and it got the right result - no failures.

    .... have to go to bed now ... have a nice day/night ... whatever ... CU

    Post Edited (MagIO2) : 5/25/2009 1:52:35 PM GMT
  • ericballericball Posts: 774
    edited 2009-05-25 17:50
    @MagIO2 - Thanks for the commenting, I need to remember to be as verbose as possible. The one limitation of your enhanced version is the SPIN code can't update the source & destination separately. So the SPIN code would be LONG[noparse][[/noparse]@cogdest] := hubptr << 16 + cogreg instead of cogdest := cogreg; hubsrc := hubptr; Of course, if the updates are coming from another COG then it's just a single WRLONG. (And in that case, the auto-zero isn't required, just wait 64 CLK cycles.)

    @JohnnyMac - if you update hubsrc before cogdest then you will probably overwrite the copy code (kaboom!) since it sits at cogdest := 0.

    To a certain extent, the code I made is just a starting point. It lacks any kind of handshaking required for use by multiple hubs. Instead it's the absolute minimum required to do the job (store data in HUB RAM and later retrieve it). On the plus side, this maximizes the amount of storage available and the speed of operation.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Composite NTSC sprite driver: http://forums.parallax.com/showthread.php?p=800114
    NTSC color bars (template): http://forums.parallax.com/showthread.php?p=803904
Sign In or Register to comment.