Shop OBEX P1 Docs P2 Docs Learn Events
flexspin compiler for P2: Assembly, Spin, BASIC, and C in one compiler - Page 86 — Parallax Forums

flexspin compiler for P2: Assembly, Spin, BASIC, and C in one compiler

18384868889116

Comments

  • evanhevanh Posts: 15,126

    Compiles now. :)

        __asm const {
    .loop
            rqpin   inb, #OVOTXPIN  wc  //transmiting? (carry high == yes)
        if_c    jmp #.loop
        }
    
  • ersmithersmith Posts: 5,900
    edited 2021-06-27 01:41

    @evanh said:
    Grr, tried but failed to avoid looping in the assembly:

      {
          int x;
          do {
    __asm const {
          rdpin   inb, #OVOTXPIN  wc
          wrc x
    }
          } while( x );
      }
    

    Gets error: Variable x must be placed in memory (probably due to an @ expression) and hence cannot be accessed in inline assembly

    I'd need to see the context, but the error message indicates that some local variables in that function are being turned into pointers and hence need to be placed in HUB memory. Unfortunately if one does then they all do :(.

    Your best bet is to keep the inline assembly short and sweet and put it into a little function that can be inlined, something like:

    int getval(int pin) {
        int x, v;
        do {
            __asm {
                rdpin v, pin wc;
                wrc x;
            }
        } while (x);
        return v;
    }
    int foo() {
        return getval(32);
    }
    

    which will be compiled into something like:

        mov arg01, #32
        loc pa, #(@LR__0002-@LR__0001)
        call    #FCACHE_LOAD_
    LR__0001
        rdpin   local01, arg01 wc
     if_c   jmp #LR__0001
    LR__0002
    

    This isn't quite ideal (the constant propagation should get rid of the move to arg01, need to work on that) but it's not bad. Some notes:

    • I left the "const" off the __asm. This let the optimizer combine the "wrc" and the compare and branch from the "while(x)". With "const" you get a "wrc" and "cmp" in the loop too.
    • Letting the optimizer at the loop also gets it put into FCACHE automatically for you. If you want to do that manually use "__asm volatile".
    • __asm uses C operator precedence and notation; __pasm uses Spin. I generally like __asm better in C code
    • __asm lets you use semicolons as line seperators or terminators; this makes Emacs happier when auto-indenting, and also lets you put inline asm in macros
  • evanhevanh Posts: 15,126

    Huh, it's okay now. The error with x in hubRAM went away. I had deleted the code, and now recreated, so I guess I'd mistyped something.

  • evanhevanh Posts: 15,126
    edited 2021-06-27 01:59

    @ersmith said:

    • __asm lets you use semicolons as line seperators or terminators; this makes Emacs happier when auto-indenting, and also lets you put inline asm in macros
    #define  wait_empty_tx()                \
    __asm {                         \
    .loop                           \
            rdpin   inb, #OVOTXPIN  wc;     \
        if_nc   jmp #.loop;             \
    }
    

    Gives me this error: error: Preprocessor errors: /home/evanh/hoard/coding/prop2/testing/test.c:22: error: Not a formal parameter "OVOTXPIN" #define wait_empty_tx() __asm { .loop rdpin inb, #OVOTXPIN wc; if_nc jmp #.loop; }

    It doesn't seem to like # being used.

  • @evanh said:

    #define  wait_empty_tx()              \
    __asm {                           \
    .loop                         \
          rdpin   inb, #OVOTXPIN  wc;     \
      if_nc   jmp #.loop;             \
    }
    

    Gives me this error: error: Preprocessor errors: /home/evanh/hoard/coding/prop2/testing/test.c:22: error: Not a formal parameter "OVOTXPIN" #define wait_empty_tx() __asm { .loop rdpin inb, #OVOTXPIN wc; if_nc jmp #.loop; }

    # is a reserved character for the C preprocessor, so it can't be used in any C macro (not just inline assembly ones). There's probably some way to escape it, but I don't know off-hand. Personally I would use a function rather than a macro, flexspin/flexcc is pretty good at inlining small functions.

  • evanhevanh Posts: 15,126

    Thanks for the help Eric.

    I've had a read of Patreon and Paypal privacy policies and both seem to indicate they give out personal details to third parties for targetted advertising - which needs to stop happening globally. That combined with the non-existent US laws, under which they both operate, makes me very hesitant to sign up to them.

  • @ersmith A FlexBASIC oddity

    Class tmp
       var1 as ulong
       var2 as ulong
    End class
    
    Dim OBJ(0 to 7) as tmp
    Dim i as ubyte
    
    For i = 0 to 7
       OBJ(i).var1 = OBJ(i).var1 + 1   ‘<— works fine
       OBJ(i).var2 += 1    ‘ <— error here
    Next i
    

    It appears an object array cant use the “+=“ operator. Is this intended behavior or is this an oops?

  • @evanh said:
    Thanks for the help Eric.

    I've had a read of Patreon and Paypal privacy policies and both seem to indicate they give out personal details to third parties for targetted advertising - which needs to stop happening globally. That combined with the non-existent US laws, under which they both operate, makes me very hesitant to sign up to them.

    FWIW, I’ve never had any advertising come from either Patreon or Paypal or their “partners” as a result of my use of their services. I do get regular updates to their TOS and policies, but no spam. YMMV

  • @JRoark said:
    @ersmith A FlexBASIC oddity

    Class tmp
       var1 as ulong
       var2 as ulong
    End class
    
    Dim OBJ(0 to 7) as tmp
    Dim i as ubyte
    
    For i = 0 to 7
       OBJ(i).var1 = OBJ(i).var1 + 1   ‘<— works fine
       OBJ(i).var2 += 1    ‘ <— error here
    Next i
    

    It appears an object array cant use the “+=“ operator. Is this intended behavior or is this an oops?

    No, that's a bug caused by BASIC's odd syntax for array references: at the point where the "+=" operator is supposed to be handled it still things OBJ(i) is a function call. I'll try to get this fixed soon. In the meantime please use the long form.

    Thanks for the bug report,

  • JRoarkJRoark Posts: 1,214
    edited 2021-06-28 01:48

    @ersmith Whoops. I broke 6.0.0-beta. :) Unfortunately I don't have any clue as to how because the compiler is complaining about a .h file and it doesn't reference any line of code in my actual FlexBASIC program. Here is the error message I get:

    "d:/Flex2Gui/flexgui/bin/flexspin" -2 -l -D_BAUD=230400 -O1 -Wall   -I "d:/Flex2Gui/flexgui/include"  "d:/Flex2Gui/flexgui/P2 Libs/Generator Project/GPS-RTC-Serial-VGA-TestP2-20June2021.bas"
    Propeller Spin/PASM Compiler 'FlexSpin' (c) 2011-2021 Total Spectrum Software Inc.
    Version 6.0.0-beta-v5.4.3-332-g09a4bc36 Compiled on: Jun 27 2021
    GPS-RTC-Serial-VGA-TestP2-20June2021.bas
    |-SmartPinSerialLibP2.bas
    |-DS3231RTC_P2_V2.spin
    |-DateTimeLibP2.bas
    |-StringLibP2.bas
    |-PropellerLibP2.bas
    |-ANSILibP2.bas
    |-ansi.spin2
    |-|-timing1024x768.spin2
    |-|-unscii-16.spin2
    |-|-vga_tile_driver.spin2
    |-DHT22LibP2.bas
    |-ESCPOSLibP2.bas
    |-|-SmartPinSerialLibP2.bas
    mount.c
    fmt.c
    strings.bas
    strerror.c
    ieee32.c
    powers.c
    errno.c
    posixio.c
    fatfs_vfs.c
    |-ff.cc
    d:/Flex2Gui/flexgui/include/time.h:57: error: syntax error, unexpected type name `tm', expecting ')'
    child process exited abnormally
    Finished at Sun Jun 27 20:41:39 2021
    

    Edit: I had working code with 5.5.1-final and made no changes. Going back to 5.5.1-final fixes the error. FWIW...

  • evanhevanh Posts: 15,126
    edited 2021-06-28 05:11

    @JRoark said:
    FWIW, I’ve never had any advertising come from either Patreon or Paypal or their “partners” as a result of my use of their services. I do get regular updates to their TOS and policies, but no spam. YMMV

    They won't list who the third party advertisers are.

    Aside from their own list being ever changing, they probably only know a small fraction of who gets a copy anyway; so simply can't provide anything definitive. The spidering effect will be enormous.

    As things stand, there's no way to say who all gets our details when they start giving it out on the basis of targetted advertising. That's a free ticket for fourth, fifth, sixth ... every party to keep passing our details on.

  • evanhevanh Posts: 15,126
    edited 2021-06-28 07:39

    Okay, new code is this: (It gets inlined as just two instructions. :) )

    void  wait_empty_tx( void )
    {
        __asm const {               // "const" prevents FCACHEing, don't need loop speed
    .loop
            rqpin   inb, #OVOTXPIN  wc  //transmiting? (carry high == yes)
        if_c    jmp #.loop
        }
    }
    
  • @JRoark said:
    @ersmith Whoops. I broke 6.0.0-beta. :) Unfortunately I don't have any clue as to how because the compiler is complaining about a .h file and it doesn't reference any line of code in my actual FlexBASIC program.

    Not your fault, it was mine... got too ambitious and tried to implement a C++ feature which broke some of the header files (which the BASIC system libraries use). I've backed it out in github for now, will do a new beta release in a while. Thanks!

  • JRoarkJRoark Posts: 1,214
    edited 2021-06-28 15:43

    @ersmith Eric, I just gotta say this out loud: your compiler suite is a real gem. I'm pushing upwards of 4K lines of code (not comments, code, ~380k binary!) and it just works. It's an amazing thing and I darn-Skippy love this thing. Thanks for the on-going effort!

  • RaymanRayman Posts: 13,800

    @ersmith In the General.pdf docs it says in the Memory Map section "Code starts at 0 in HUB".
    But, later on it says the the binary starts at $400. Maybe this could use some clarification?

    I'm trying to remember how this actually works...
    I think the P2 chip loads the boot rom to address 0 in a COG and then executes it.
    Then loadp2 or the flash load stuff into hub at $400 and then start it, right?

    Does any code actually run at hub address 0?

  • At boot time the contents of ROM are copied to HUB address 0, and then a COGINIT instruction is used to start the code from 0. It's not possible (or exceedingly difficult?) to run HUB code at 0, but the memory from 0 to 0x400 can be occupied by code that is executed by COGINIT, and that is what in fact happens. From flexspin's perspective the area from 0-0x400 is normally written to (it has to be there for the ROM and for serial execution) but it just contains data and the initial COGINIT code which jumps into HUB at 0x400.

  • __deets____deets__ Posts: 193
    edited 2021-07-04 09:30

    Edit: deleted, something confused me and I thought I found a bug. Nevermind.

  • Any idea when WiFi for the P2 will be added for Flexprop? It looks like the new P2 proploader has been available since March.

    https://forums.parallax.com/discussion/173017/loadp2-update-for-p2-wireless-programming

    Thanks
    Ray

  • @Rsadeika said:
    Any idea when WiFi for the P2 will be added for Flexprop? It looks like the new P2 proploader has been available since March.

    https://forums.parallax.com/discussion/173017/loadp2-update-for-p2-wireless-programming

    There two answers to this:

    (1) Since the commands used for loading can be changed in the Commands > Configure Commands... menu, you can already use Wifi: just replace the loadp2 command with whatever command line the P2 proploader needs for WIFI.

    (2) However, be aware that the P2 proploader only supports WIFI (it does not allow serial programming of P2s, as far as I can see). Nor does it support any of the additional features of loadp2, like the file server or loading files in pieces. So it's not really viable as a replacement for loadp2, and until it is proploader cannot be made the default P2 loader. It would be nice if Parallax would update the loader to at least support serial programming of P2s.

  • David BetzDavid Betz Posts: 14,511
    edited 2021-07-05 20:05

    (Deleted)

  • I noticed that DEBUG output can get interleaved when using several cogs. I will work around this with a shared semaphore for now, but wonder if the system can somehow be improved.

  • RaymanRayman Posts: 13,800

    Does sscanf() work? I'm trying this and it doesn't seem to work as I think it should...
    Or, could be I'm doing it wrong as this is my first time using sscanf...

        char s1[100] = "140";
        int d=100;
        sscanf(s1,"%d", d);
        _waitms(5);
        printf("SA= %d\n", d);
    

    d is staying 100 instead of being set to 140...

  • RaymanRayman Posts: 13,800

    When using gets() with the loadp2 terminal window, the terminal is incredibly slow to react to keyboard input...
    Is this the normal behavior, or is something wrong?

  • @Rayman ,

    To use that function you need to supply the address of the object.

    sscanf(s1, "%d", &d);
    d = atoi(s1);  // also works
    

    Mike

  • TonyB_TonyB_ Posts: 2,108
    edited 2021-07-06 15:46

    deleted

  • RaymanRayman Posts: 13,800

    @iseries That was it! Thanks.

  • RaymanRayman Posts: 13,800
    edited 2021-07-06 14:22

    One more sscanf question...
    The asterisk in "%*s %d" is supposed to read a string but ignore it.
    I'm trying to use it like this, but doesn't seem to work:

        char s1[100] = "SA= 140";
        gets(s);
        int d=100;
        sscanf(s1,"%*s %d", &d); 
    

    Am I doing it wrong? Seems to work as expected without the asterisk..

  • @deets said:
    I noticed that DEBUG output can get interleaved when using several cogs. I will work around this with a shared semaphore for now, but wonder if the system can somehow be improved.

    I'll look into this, thanks for the suggestion.

  • @Rayman said:
    When using gets() with the loadp2 terminal window, the terminal is incredibly slow to react to keyboard input...
    Is this the normal behavior, or is something wrong?

    I haven't noticed this. Do you see it on all gets(), or just the first one?

    @Rayman said:
    One more sscanf question...
    The asterisk in "%*s %d" is supposed to read a string but ignore it.

    "*" isn't implemented in the library yet, so for now you'll have to leave it off and put a dummy parameter in (or otherwise work around the absence).

  • @TonyB_ said:
    I'm getting hundreds of errors with FlexSpin when compiling P2 assembler of the form:

    Source operand too big for <instr> or
    Destination operand too big for <instr>

    All instructions that involve cog variables produce these errors. It's as though the compiler thinks they are in hub RAM, not cog RAM. The listing file has object code only for jumps, calls and returns, plus a few instructions that use constants to refer to cog RAM. Most instructions have a blank space where the opcodes should be.

    I've not had this problem before, including compiling a complicated 8086 emulator. How do I tell FlexSpin to assemble cog/LUT-only code starting at address 0?

    Sounds like there's a missing "ORG 0" at the beginning of the COG code.

Sign In or Register to comment.