Shop OBEX P1 Docs P2 Docs Learn Events
hello_p2 — Parallax Forums

hello_p2

rjo__rjo__ Posts: 2,114
edited 2013-10-05 20:38 in Propeller 2
I will be getting an addon board for my NanoP2 from Mr. Potatohead in a few days, but this is driving me nuts.

I don't know who posted the following code, but after making the appropriate changes, it runs just fine with the new configuration on my bare NanoP2.
' mostly stolen from Chip's P2 ROM monitor

CON
        BASE = $e80
        CLOCK_FREQ = 80000000
        BAUD = 115200
        SERIAL_TX = 90  ' must be in the port c
        SERIAL_RX = 91
        CR = $0d
        LF = $0a

DAT
                byte    0[BASE]

                org

start           reps    #$1F6-@reserves+@start,#1      'clear reserves
                setinda #reserves
                mov     inda++,#0

                setp    tx_pin
                mov     dirc,dirc_mask          'make tx pin an output

                jmptask #rx_task,#%0010         'enable serial receiver task
                settask #%%1010

                ' wait for the user to start the terminal emulator
                mov     x,#5
:pause          getcnt  w
                add     w,freq
                passcnt w
                djnz    x,#:pause

                setptra hello_addr              'print hello message
                call    #tx_string              'print hello/error message
                setptra hello2_addr
                call    #tx_string

idle            call    #rx
                cmp     x,#CR wz
        if_nz   jmp     #:next
                call    #tx
                mov     x,#LF
:next           call    #tx
                jmp     #idle

'
'
' Print string (@ptra)
'
tx_string       rdbyte  x,ptra++                'get chr
tx_string_ret   tjz     x,#0                    'if 0, done
                call    #tx                     'other?
                jmp     #tx_string

'
'
' Transmit chr (x)
'
tx              shl     x,#1                    'insert start bit
                setb    x,#9                    'set stop bit

                getcnt  w                       'get initial time

:loop           add     w,period                'add bit period to time
                passcnt w                       'loop until bit period elapsed
                shr     x,#1            wc      'get next bit into c
                setpc   tx_pin                  'write c to tx pin
                tjnz    x,#:loop                'loop until bits done

tx_ret          ret

'
'
' Receive chr (x)
'
rx              call    #rx_check               'wait for rx chr
        if_z    jmp     #rx

rx_ret          ret
'
'
' Check receiver, z=0 if chr (x)
'
rx_check        or      rx_tail,#$80            'if start or rollover, reset tail

                getspb  rx_temp         wz      'if head uninitialized, z=1
        if_nz   cmp     rx_temp,rx_tail wz      'if head-tail mismatch, byte ready, z=0

        if_nz   getspa  rx_temp                 'preserve spa
        if_nz   setspa  rx_tail                 'get tail
        if_nz   popar   x                       'get byte at tail
        if_nz   getspa  rx_tail                 'update tail
        if_nz   setspa  rx_temp                 'restore spa

rx_check_ret    ret


'************************
'* Serial Receiver Task *
'************************

rx_task         chkspb                  wz      'if start or rollover, reset head
        if_z    setspb  #$80

                mov     rx_bits,#9              'ready for 8 data bits + 1 stop bit

                neg     rx_time,period          'get -0.5 period
                sar     rx_time,#1

                jp      rx_pin,#$               'wait for start bit

                subcnt  rx_time                 'get time + 0.5 period for initial 1.5 period delay

:bit            rcr     rx_data,#1              'rotate c into byte
                add     rx_time,period          'add 1 period
                passcnt rx_time                 'wait for center of next bit
                getp    rx_pin          wc      'read rx pin into c
                djnz    rx_bits,#:bit           'loop until 8 data bits + 1 stop bit received

                shr     rx_data,#32-8           'align byte
                pushb   rx_data                 'store byte at head, inc head

                jmp     #rx_task                'wait for next byte


'*************
'* Constants *
'*************

hello           byte    CR, LF, "Hello, Propeller II!", CR, LF, 0
hello2          byte    CR, LF, "Hello again, Propeller III!", CR, LF, 0
hello_addr      long    @hello
hello2_addr     long    @hello2

rx_pin          long    SERIAL_RX
tx_pin          long    SERIAL_TX
dirc_mask       long    1 << (64 - SERIAL_TX)
period          long    CLOCK_FREQ / BAUD
freq            long    CLOCK_FREQ


'*************
'* Variables *
'*************

reserves

w               res     1                       'main task
x               res     1
y               res     1
z               res     1

rx_tail         res     1                       'serial receiver task
rx_temp         res     1
rx_time         res     1
rx_data         res     1
rx_bits         res     1

On the other hand, I have tried every variation I can think of in both Spin and P2ASM using the new configuration and the new serial code from Chip and it all seems to hang. I can get the monitor back by resetting the terminal. Does anyone have a working new serial "hello" in Spin that I can try? I don't really care that it doesn't work on my bare Nano, but I would be tickled if that it does. (If you think about it... have a compulsory need for addon boards would be a really good thing if they were for sale:)

Thanks

Rich

Comments

  • AribaAriba Posts: 2,682
    edited 2013-10-05 15:23
    Here is Spin2 example.
    CON
      clkfrq = 80_000_000
      baudper = clkfrq / 115200
    
    PUB Main
      ser_start(91,90,115200)
      repeat 3
        passcnt(clkfrq+getcnt)      'wait 1 second
        ser_str(@hello)             '3* Hello World
      repeat
        ser_tx(ser_rx)              'then echo input
    
    PUB ser_start(rxpin,txpin,baudrt)
      setpera(baudper)  '(clkfrq/baudrt) but no divide yet
      setsera((2<<7+rxpin)<<9 + 2<<7+txpin)
      drvc[.txpin] := 1             'works only for pins 64..91
    
    PUB ser_rx : value
      repeat until serina(value)
    
    PUB ser_tx(value)
      repeat until serouta(value)
    
    PUB ser_str(strptr)
      repeat strsize(strptr)
        ser_tx(byte[strptr++])
    
    DAT
    hello  byte "Hello World",13,10,0
    '
    
    Many things in Spin2 do not work yet. Divide and Multiply for example but also STRING(..), so I had to code around that.

    Andy
  • ozpropdevozpropdev Posts: 2,791
    edited 2013-10-05 17:33
    Andy
    In your Spin2 code you have the following line
    drvc[.txpin] := 1
    

    I assume this means set direction of Port C bit 26
    The ".txpin" is the modulus of 90/32?
    Where did you get this info on Spin2?
    Cheers
    Brian
  • potatoheadpotatohead Posts: 10,254
    edited 2013-10-05 17:53
    You can see all the possible keywords and error messages by getting the ASCII strings out of the pnut.exe file. Perhaps that's where Andy started.

    I went ahead and attached it
    ***Error Strings
    
    Address is not long
    Address is out of range
    "}" must be preceeded by "{" to form a comment
    Block designator must be in first column
    Bitfield not allowed for "@"
    Blocknest stack overflow
    Constant cannot exceed $FF
    Constant exceeds 32 bits
    Conditional execution not allowed for TASKSW/TASKSWD instructions
    Constant must be from 0 to 3
    Constant must be from 0 to 7
    Constant must be from 0 to 15
    Constant must be from 0 to 31
    Constant must be from 0 to 63
    Constant must be from 0 to 127
    Constant must be from 0 to 255
    Constant must be from 0 to 511
    Constant must be from 1 to 64
    Constant must be from 1 to 512
    Constant must be from 1 to 16384
    Conditional not allowed with REPS
    Conditional not allowed with SETINDx/FIXINDx
    _CLKFREQ or _XINFREQ must be specified
    COGINIT source must be a register, not a constant
    CALL symbol must not exceed 26 characters
    _CLKFREQ/_XINFREQ not allowed with RCFAST/RCSLOW
    _CLKFREQ/_XINFREQ specified without _CLKMODE
    Divide by zero
    Division overflow
    Destination register cannot exceed $1FF
    Expected an assembly effect or end of line
    Expected an assembly effect
    Expected an assembly instruction
    Expected a binary operator or ")"
    Expected a constant name
    Expected a constant, unary operator, or "("
    Expected a DAT symbol
    Expected an expression term
    Expected an instruction or variable
    Expected a local symbol
    Expected a subroutine name
    Expected a subroutine, object name, or ~
    Expected a terminating quote
    Expected a unique object name
    Expected a variable
    Expected a unique constant name or "#"
    Expected a unique name, BYTE, WORD, LONG, or assembly instruction
    Expected a unique parameter name
    Expected a unique result name
    Expected a unique subroutine name
    Expected a unique variable name
    Expected BYTE, WORD, or LONG
    Expected "," or end of line
    Expected ":"
    Expected ","
    Expected "," or ")"
    Either _CLKFREQ or _XINFREQ must be specified, but not both
    Expected "."
    Expected ".."
    Expected end of line
    Expected "=" "[" "," or end of line
    Expected FROM
    Expected INDA or INDB
    Expression is too complex
    Expected "("
    Expected "["
    Expected "#", "++", or "--"
    Expected PRECOMPILE or ARCHIVE
    Expected "#" or "@"
    Expected "|" or end of line
    Expected "#"
    Expected "}"
    Expected "}}"
    Expected ")"
    Expected "]"
    Empty string
    Expected STEP or end of line
    Expected TO
    Filename too long
    Floating-point constant must be within +/- 3.4e+38
    Floating-point not allowed in integer expression
    Floating-point overflow
    Hub origin exceeds $1FFFF limit
    Invalid binary number
    Indirect buffer size must range from 1 to 512
    Invalid _CLKMODE specified
    Invalid double-binary number
    Internal DAT file not found
    Invalid filename character
    Invalid filename, use "FilenameInQuotes"
    Integer not allowed in floating-point expression
    Internal
    Integer operator not allowed in floating-point expression
    Limit of 64 cases exceeded
    Limit of 8 nested blocks exceeded
    Limit of 32 unique objects exceeded
    Limit of 32 unique DAT files exceeded
    Limit of 32 unique PRECOMPILE files exceeded
    Limit of 32 unique ARCHIVE files exceeded
    List is too large
    Limit of 1024 DAT symbols exceeded
    Limit of 16 ELSEIF/ELSEIFNOTs exceeded
    Limit of 4096 local variables exceeded
    Limit of 15 parameters exceeded
    Limit of 15 parameters plus local variables exceeded
    Limit of 256 subroutines + objects exceeded
    No conditional allowed with INDA/INDB
    No cases encountered
    No PUB routines found
    Origin already exceeds target
    Object count must be from 1 to 255
    Object distiller overflow
    Origin exceeds FIT limit
    Object exceeds 128k
    Origin exceeds $1F6 limit
    "$" is not allowed here
    OTHER must be last case
    PUB/CON list overflow
    PTRA/PTRB index constant must range from -32 to 31
    PTRA/PTRB index constant must range from 0 to 31
    PTRA/PTRB index constant must range from 0 to 32
    ?_RET address is not long
    ?_RET address is out of range
    Register cannot exceed $1FF
    Register is not allowed here
    RES is not allowed in ORGX mode
    RDxxxx/WRxxxx must use a register or PTRA/PTRB expression, not a constant
    Source constant cannot exceed $1FF
    Symbols _CLKMODE, _CLKFREQ, _XINFREQ can only be used as integer constants
    String characters must range from 1 to 255
    Symbol _DEBUG can only be used as an integer constant
    Symbol exceeds 30 characters
    Symbol is already defined
    STRING not allowed here
    Size override must be larger
    Size override must be smaller
    Subroutine pointed to must be 1st..63rd PUB/PRI
    Source register cannot exceed $1FF
    Symbol table is full
    This effect is not allowed for this instruction
    This instruction is only allowed within a REPEAT block
    Too many string constants
    Too many string constant characters
    Too much variable space is declared
    Unrecognized character
    Undefined ?_RET symbol
    Undefined symbol
    Variable needs an operator
    WR/NR not allowed for this instruction
    
    
    **keywords
    NOT
    AND
    XOR
    FLOAT
    ROUND
    TRUNC
    CONSTANT
    STRING
    CON
    VAR
    DAT
    OBJ
    PUB
    PRI
    DEV
    BYTE
    WORD
    LONG
    QUADALIGN
    PRECOMPILE
    ARCHIVE
    FILE
     IF
    IFNOT
    ELSEIF
    ELSEIFNOT
    ELSE
    CASE
    OTHER
    REPEAT
    WHILE
    UNTIL
    FROM
    TO
    STEP
    NEXT
    QUIT
    RETURN
    ABORT
    LOOKUPZ
    LOOKUP
    LOOKDOWNZ
    LOOKDOWN
    SQRT
    RNDF
    RNDR
    QUO64
    QUO64U
    REM64
    REM64U
    SQRT64
    NEGB
    MUXB
    MUL64
    MUL64U
    DIV64
    DIV64U
    COGNEW
    REG2REG
    REG2CLU
    REG2LOC
    REG2HUB
    CLU2REG
    CLU2CLU
    CLU2LOC
    CLU2HUB
    LOC2REG
    LOC2CLU
    LOC2LOC
    LOC2HUB
    HUB2REG
    HUB2CLU
    HUB2LOC
    BYTEMOVE
    WORDMOVE
    LONGMOVE
    QUADMOVE
    STRSIZE
    STRCOMP
    REGFILL
    CLUFILL
    LOCFILL
    BYTEFILL
    WORDFILL
    LONGFILL
    QUADFILL
    CLKSET
    COGID
    COGINIT
    COGSTOP
    LOCKNEW
    LOCKRET
    LOCKSET
    LOCKCLR
    SERINA
    SERINB
    CMPCNT
    SUBCNT
    PASSCNT
    GETCNT
    GETACCA
    GETACCB
    GETLFSR
    POLVID
    POLCTRA
    POLCTRB
    GETPIX
    DECOD2
    DECOD3
    DECOD4
    DECOD5
    DBLMASK
    DONECNT
    DZERCNT
    DINCPAT
    DDECPAT
    DBINGRY
    DGRYBIN
    DMERGEW
    DSPLITW
    DESWAP4
    DESWAP8
    DGETPHSA
    DGETPHZA
    DGETCOSA
    DGETSINA
    DGETPHSB
    DGETPHZB
    DGETCOSB
    DGETSINB
    DJMPTASK
    DSETTASK
    DCLRACCA
    DCLRACCB
    DCLRACCS
    DSARACCA
    DSARACCB
    DSARACCS
    DSEROUTA
    DSEROUTB
    DSETXCH
    DNOP
    DCALLB
    DSETPIX
    DSETPIXU
    DSETPIXV
    DSETPIXZ
    DSETPIXA
    DSETPIXR
    DSETPIXG
    DSETPIXB
    DSETQI
    DQLOG
    DQEXP
    DSETF
    DCFGDAC0
    DCFGDAC1
    DCFGDAC2
    DCFGDAC3
    DSETDAC0
    DSETDAC1
    DSETDAC2
    DSETDAC3
    DCFGDACS
    DSETDACS
    DSETPORT
    DSETPORA
    DSETPORB
    DSETPORC
    DSETPORD
    DSETPERA
    DSETSERA
    DSETPERB
    DSETSERB
    DSETVID
    DSETVIDY
    DSETVIDI
    DSETVIDQ
    DSETCTRA
    DSETWAVA
    DSETFRQA
    DSETPHSA
    DADDPHSA
    DSUBPHSA
    DSYNCTRA
    DCAPCTRA
    DSETCTRB
    DSETWAVB
    DSETFRQB
    DSETPHSB
    DADDPHSB
    DSUBPHSB
    DSYNCTRB
    DCAPCTRB
    DSETACCA
    DSETACCB
    DMACA
    DMACB
    DMUL
    DMOVF
    DQSINCOS
    DQARCTAN
    DQROTATE
    DSCL
    DMIN
    DMAX
    DMOVS
    DMOVD
    DMOVI
    DINCMOD
    DDECMOD
    DCFGPINS
    DWAITVID
    DWAITCNT
    DWAITPEQ
    DWAITPNE
    DORGX
    FORGH
    FORGF
    FORG
    FRES
    FFIT
    IF_NC_AND_NZ
    IF_NZ_AND_NC
    IF_A
    IF_NC_AND_Z
    IF_Z_AND_NC
    IF_NC
    IF_AE
    IF_C_AND_NZ
    IF_NZ_AND_C
    IF_NZ
    IF_NE
    IF_C_NE_Z
    IF_Z_NE_C
    IF_NC_OR_NZ
    IF_NZ_OR_NC
    IF_C_AND_Z
    IF_Z_AND_C
    IF_C_EQ_Z
    IF_Z_EQ_C
    IF_Z
    IF_E
    IF_NC_OR_Z
    IF_Z_OR_NC
    IF_C
    IF_B
    IF_C_OR_NZ
    IF_NZ_OR_C
    IF_C_OR_Z
    IF_Z_OR_C
    IF_BE
    IF_ALWAYS
    IF_NEVER
    IF_0000
    IF_0001
    IF_0010
    IF_0011
    IF_0100
    IF_0101
    IF_0110
    IF_0111
    IF_1000
    IF_1001
    IF_1010
    IF_1011
    IF_1100
    IF_1101
    IF_1110
    IF_1111
    WRBYTE
    RDBYTE
    RDBYTEC
    WRWORD
    RDWORD
    RDWORDC
    WRLONG
    RDLONG
    RDLONGC
    ENC
    JMP
    RET
    JMPRET
    CALL
    TASKSW
    ROR
    ROL
    SHR
    SHL
    RCR
    RCL
    SAR
    REV
    MINS
    MAXS
    JMPD
    RETD
    JMPRETD
    CALLD
    TASKSWD
    TEST
    TESTN
    ANDN
    MUXC
    MUXNC
    MUXZ
    MUXNZ
    ADD
    CMP
    SUB
    ADDABS
    SUBABS
    SUMC
    SUMNC
    SUMZ
    SUMNZ
    MOV
    NEG
    ABS
    ABSNEG
    NEGC
    NEGNC
    NEGZ
    NEGNZ
    CMPS
    CMPSX
    ADDX
    CMPX
    SUBX
    ADDS
    SUBS
    ADDSX
    SUBSX
    CMPR
    SUBR
    CMPSUB
    JZ
    JZD
    JNZ
    JNZD
    DJZ
    DJZD
    DJNZ
    DJNZD
    TJZ
    TJZD
    TJNZ
    TJNZD
    JP
    JPD
    JNP
    JNPD
    SETINDA
    SETINDB
    SETINDS
    FIXINDA
    FIXINDB
    FIXINDS
    PUSHZC
    POPZC
    GETTOPS
    CHKPTRA
    GETPTRA
    CHKPTRB
    GETPTRB
    GETSPD
    CHKSPD
    GETSPA
    CHKSPA
    GETSPB
    CHKSPB
    POPAR
    POPBR
    POPA
    POPB
    RETA
    RETB
    RETAD
    RETBD
    GETMULL
    GETMULH
    GETDIVQ
    GETDIVR
    GETSQRT
    GETQX
    GETQY
    GETQZ
    REPD
    REPS
    CACHEX
    SETXFR
    SETZC
    SETSPA
    SETSPB
    ADDSPA
    ADDSPB
    SUBSPA
    SUBSPB
    PUSHAR
    PUSHBR
    PUSHA
    PUSHB
    CALLA
    CALLAD
    CALLBD
    WRQUAD
    RDQUAD
    RDQUADC
    SETPTRA
    SETPTRB
    ADDPTRA
    ADDPTRB
    SUBPTRA
    SUBPTRB
    SETMULU
    SETMULA
    SETMULB
    SETDIVU
    SETDIVA
    SETDIVB
    SETSQRH
    SETSQRL
    SETQZ
    SETSKIP
    GETP
    GETNP
    OFFP
    NOTP
    CLRP
    SETP
    SETPC
    SETPNC
    SETPZ
    SETPNZ
    SETCOG
    SETMAP
    SETQUAD
    SETQUAZ
    TESTB
    ISOB
    NOTB
    CLRB
    SETB
    SETBC
    SETBNC
    SETBZ
    SETBNZ
    NZ
    NC
    NR
    WZ
    WC
    WR
    PTRA
    PTRB
    REG
    INA
    INB
    INC
    IND
    OUTA
    OUTB
    OUTC
    OUTD
    DRVA
    DRVB
    DRVC
    DRVD
    INDA
    INDB
    PINA
    PINB
    PINC
    PIND
    DIRA
    DIRB
    DIRC
    DIRD
    CLU
    LOC
    RESULT
    FALSE
    TRUE
    NEGX
    POSX
    PI
    RCFAST
    RCSLOW
    XINPUT
    XTAL1
    XTAL2
    XTAL3
    PLL1X
    PLL2X
    PLL4X
    PLL8X
    PLL16X
    
    
  • ozpropdevozpropdev Posts: 2,791
    edited 2013-10-05 18:02
    Ok. Nice move Andy!
    I'll take a look... Thanks Potatohead
  • rjo__rjo__ Posts: 2,114
    edited 2013-10-05 19:20
    Glory Glory Glory
  • ozpropdevozpropdev Posts: 2,791
    edited 2013-10-05 19:28
    potatohead wrote: »
    I went ahead and attached it

    Thanks Potatohead
    You've given us a good starting point.
    Cheers
    Brian
  • AribaAriba Posts: 2,682
    edited 2013-10-05 20:17
    ozpropdev wrote: »
    Andy
    In your Spin2 code you have the following line
    drvc[.txpin] := 1
    

    I assume this means set direction of Port C bit 26
    The ".txpin" is the modulus of 90/32?
    Where did you get this info on Spin2?
    Cheers
    Brian

    Chip has a Spin2 example in the ZIP (serialio.spin). From that I got the [.bit] syntax and the serina, serouta handling.
    The rest is guessing and trial and error and - yes I also looked into the PNUT.exe with a hex-viewer.

    I think the syntax with the dot for bits is because in Spin2 you can access the bits of every variable, not only the OUTx, DIRx etc.

    Chip has included Spin commands for most new PASM instructions with the same name, so the PASM reference helps also.

    But it is not so much fun to code in Spin2 at the moment, because you never know what works and what not. It's more debugging than coding.

    @potatohead
    Thanks for the ASCII extraction. much better than what I have done.
    But I think you need to remove the first character of most Spin command words, they specify some kind of command type.

    Andy
  • potatoheadpotatohead Posts: 10,254
    edited 2013-10-05 20:38
    Yes, I noted that too. Was not sure whether or not it's better to leave them. I'll parse through and make my best guess. The original text strings are in the attached file, should I get one wrong. People can compare.

    Edit: I did a lot of them.

    Re: ASCII

    On UNIX, just use "strings pnut.exe > text.txt" Microsoft published one that works about the same way, and it can be found on Technet. That's what I used as I'm on a Win32 machine right now.
Sign In or Register to comment.