Shop OBEX P1 Docs P2 Docs Learn Events
Resolved: Bug? Misundertanding? This blinky should work....(I think) — Parallax Forums

Resolved: Bug? Misundertanding? This blinky should work....(I think)

mindrobotsmindrobots Posts: 6,506
edited 2015-10-13 18:37 in Propeller 2
My little peanut brain says this little blink_all_cogs program or something very close to it should work. I made a few org changes and some addressing prefix changes form the original. What I am asking and the code image I am building makes sense in my head.

edit: it starts the COGs but nothing blinks
dat
		orgh	0

		jmp	#highhub
                org   0
cognum		long	0
'
' launch cogs 15..0 with blink program
' cogs that don't exist won't blink
'
		orgh	$1000
highhub
		mov	cognum,#15	' need to load it since COG0 COGRAM 
					        ' is not initialized
.loop		coginit	cognum,#blink   ' should be ##@blink to work
		djns	cognum,#.loop
		jmp	#blink

'
' blink
'
		org   0

blink		cogid	x		'which cog am I?
		setb	dirb,x		'make that pin an output
		notb	outb,x		'flip its output state
		add	x,#16		'add to my id
		shl	x,#18		'shift up to make it big
		waitx	x		'wait that many clocks
		jmp	#blink		'do it again

x		res	1		'variable at cog register 8

I would think this would be a common program framework with COG0 doing overall init and setting up the other COGS and then doing something for itself.
{edited}
Start in HUBEXEC, Start in COG EXEC
jump to code in high HUB {switching to HUB EXEC} and set up variable space for what will be COG0 COGRAM (even though it doesn't get loaded),
run my HUBEXEC code as COG0 to kick off the other cogs to run blink in COGEXEC,
fall through to blink to run as COG0 in HUBEXEC

What am I misunderstanding? {I got it now, below, Chip was correcting my comments regarding starting in HUB exec.}


EDIT: Solution? Change 'coginit cognum,#blink' to 'coginit cognum,##@blink' so you get the proper address.

Comments

  • If I make the COGINIT look like this:
    .loop		loc	adra,#@blink
    		coginit	cognum,adra
    

    it appears to work just fine.

    If I change the COGINIT to "coginit cognum,#@blink", PNUT complains that constant must be from 0 to 511and highlights @blink.

    Is COGINIT an instruction that can't benefit from AUGS?

    I can see if it has to be a valid S( or ADRA/ADRB/PTRA/PTRB) in the S field, then why PNUT can't just resolve it for you.

    Maybe It's just a gotcha(quirk) to be aware of, document and move on.
  • ElectrodudeElectrodude Posts: 1,657
    edited 2015-10-13 14:37
    You need to tell PNUT you want to use AUGS. It can't be automatic for reasons Chip has already stated. What if you try "coginit cognum,##@blink"?

    Also, in case you're not using today's update and @ means relative address in your version of PNUT, I'm pretty sure coginit doesn't accept a relative address.
  • Ok, that #$&%@^!#% worked!!! :) Thanks!!!

    So I need the longer than 9 bit (##) constant of the address of something in hub (@)

    Makes perfect sense now.
  • cgraceycgracey Posts: 14,152
    Also, your program at $00000 now starts in cog exec, not hub exec.
  • Oh, I missed that. We are back to cog exec on start now?

    If so, cool. I like that better actually.
  • cgracey wrote: »
    Also, your program at $00000 now starts in cog exec, not hub exec.

    I must have missed that change.

    We now always start in cog exec until we JMP someplace higher than $400?

    (Haven't looked a the loader code lately.)


  • mindrobotsmindrobots Posts: 6,506
    edited 2015-10-13 18:13
    I've been playing with this today as a standard "startup":
    dat
    	orgh	0
    	jmp	#histart
    
    	org	0
    ' build the COG0 COGRAM image
    me		long	0
    delay		long	50_000_000
    vector		jmp	#\hblink
    	orgf	$1F0
    
    	orgh	$1000
    histart
    	loc	ptra,#@me	' copy COG0 data to COG0 COGRAM
    	setq	#$1F0		' to initialize COGRAM variables
    	rdlong	0,ptra
    
    	wrlong	vector,##DEBUGV_3
    

    My assumption was that I started at $00000 in hub COG exec, immediately jumped over hubram to $400 to continue start execution in hub exec.

    Then I switched to 'org 0' to build a COG RAM image that could be loaded into COG0 so I'd have labels with cog addressing and also could create my initialized variables.

    Once I was running at $400, I just copied my COGRAM image from HUBRAM $00004 to COG0 COGRAM $0. After this, my COGRAM is loaded with any initialized variables I had created.

    If I didn't do this, I was finding COGRAM for COG0 to be in an unknown state and I could not do something like 'wrlong vector,##DEBUGV_3' without first initializing vector first.

    The above works great and solves my uninitialized COG variable problem. Is it just luck based on bad understanding?
  • mindrobots wrote: »
    cgracey wrote: »
    Also, your program at $00000 now starts in cog exec, not hub exec.

    I must have missed that change.

    We now always start in cog exec until we JMP someplace higher than $400?

    (Haven't looked a the loader code lately.)

    The first cog always starts in cog exec. From there, you control whether you start in cog exec (with or without copying $1F0 longs) or hub exec based on D[5] in coginit.
  • Seairth wrote: »
    mindrobots wrote: »
    cgracey wrote: »
    Also, your program at $00000 now starts in cog exec, not hub exec.

    I must have missed that change.

    We now always start in cog exec until we JMP someplace higher than $400?

    (Haven't looked a the loader code lately.)

    The first cog always starts in cog exec. From there, you control whether you start in cog exec (with or without copying $1F0 longs) or hub exec based on D[5] in coginit.

    ...or a jump to an address beyond $1000 (bytes) or $3FF (longs) so after the first instruction executes, I am in hub exec. No?

    I just need to update my description of the program above so it reflects the current reality.

  • cgraceycgracey Posts: 14,152
    mindrobots wrote: »
    Seairth wrote: »
    mindrobots wrote: »
    cgracey wrote: »
    Also, your program at $00000 now starts in cog exec, not hub exec.

    I must have missed that change.

    We now always start in cog exec until we JMP someplace higher than $400?

    (Haven't looked a the loader code lately.)

    The first cog always starts in cog exec. From there, you control whether you start in cog exec (with or without copying $1F0 longs) or hub exec based on D[5] in coginit.

    ...or a jump to an address beyond $1000 (bytes) or $3FF (longs) so after the first instruction executes, I am in hub exec. No?

    I just need to update my description of the program above so it reflects the current reality.

    The $00000..$001FF addresses are cog exec.
    The $00200..$003FF addresses are lut exec.
    The $00400..$FFFFF addresses are hub exec.

    When you get inside those lower addresses for cog/lut exec, it is like Alice in Wonderland, where what would have been bytes in the hub are actually longs in the cog/lut.



  • Seairth wrote: »

    Thanks!

    Saw the comment when it first came out and added it to my notes, I just hadn't grabbed a new copy of the main loader since it changed from a HUB EXEC COGINIT to a COG EXEC COGINIT.

    All is good now. The world makes more sense!!

  • Thanks Chip!

    I'm good now. Back to having fun!!
Sign In or Register to comment.