Working on FSRW..



  • cheezus wrote: »
    I'm working on a "template" cog engine, mostly for my own understanding. What I have so far is this :
    PUB start_explicit( DO, CLK, DI, CS ) : card_type
      long[@cmd] := "i"                         'set flag to know if the started cog has read its parameters
      long[@cmd][1] := @DO

    Ugh! Please don't do this. I know it was popular in Spin1 to save time by passing pointers to the parameters that happened to be on the stack, but it really kills performance in fastspin (it'll work, but it forces the compiler to store local variables on the stack instead of in registers, which is much slower). It also makes porting the code to other languages harder, because not all of them will pass variables on the stack -- many, like fastspin, will pass them in registers instead.

    You've also got the mailbox in the DAT section, which means it's shared by all instances of the object. If you wanted to drive two different cards, with two different COGs, you'd need to have a lock on the mailbox so they don't conflict. Whereas if the mailbox is a local variable of the object this wouldn't be an issue. Maybe it doesn't matter for the SD card driver, but you mentioned wanting to use this as a template for other objects, so it might come up there.

    So I would suggest that the more natural way to write this is:
      long mbox[10] ' or whatever size
    PUB start_explicit(DO, CLK, DI, CS) : card_type
      mbox[0] := "i"
      mbox[1] := DO
      mbox[2] := CLK
      mbox[3] := DI
      mbox[4] := CS
      cog := cognew(@asm_start, @mbox)

    That'll also simplify your PASM startup code, because you won't have to juggle multiple pointers (you just have the one to mbox), and I think makes everything easier to understand, both for the human reader and for the compiler.

  • Thanks for those tips Eric!

    As to passing parameters, I'll need to figure out the best way to handle this. I use this trick because there are many times I would like to pass more initialization info to the cog than I have parameters. I never did get my head around the "pre-load" trick used in the P1 and always did it this way. I guess I could use several commands for initialization, need to think on this more.

    Regarding the mailbox in the dat section, I also have a commented out VAR section if I wanted multiple instances running at the same time. I will have one platform with 2 sd cards so this will be something to think about. That hardware also has a shared SPI bus so was thinking about providing some SPI methods for accessing those devices as well. I think it's best to start out "generic" so maybe others can find it helpful as well.
  • Attached is a sdrw test for the eval board. Confirmed to work consistently on my P2ES. You may want to consider adding this to the RC3 distribution. It was the file @Rayman included in his, with additions for CR + LF in the terminal. Thank you @cheezus !
    Terry's Workbench

    Feel the need for speed between your PC's com port and Prop?
    Try the FTDI 245 and the FullDuplexParallel Object.
    Check out my spin driver for the Parallax "96 x 64 Color OLED Display Module" Product ID: 28087
    22FPS video from the P2 on the Parallax "96 x 64 Color OLED Display Module"
  • So I'm looking at the docs, trying the RTFM manual way.. I think I'm close to testing the improved read, using smartpins. I'm sure there's something still wrong though. I'm sure the experts can see where I'm going with this though.
    pri read : r  | c, o        '   Read eight bits from the card.
            c := clk
            o := do
        dirl    c
        wrpin   sp_async_tx,c 
        wxpin   ##$9,c          'set base period 
        dirh    c
        dirl    o
        wrpin   sp_clk_cfg,o    'sync tx
        wxpin   #%1_00111,o     'stop/start mode
        dirh    o               'enable smartpin
    '    wypin   txdata,o        'data, need to do anything?
        wypin   #8,c           'start clock, tx data '' ! should this be 8 or 16?
    busy    testp   c wc
        if_nc   jmp #busy
        rdpin   pa,c ' needed?
        rdpin   r,o
        dirl    o
        dirl    c
        '' next part per chip's smart pin documentation 
        REV r              ' Set MSB First
        TRIML r,#7
Sign In or Register to comment.