Shop OBEX P1 Docs P2 Docs Learn Events
serial cog loader — Parallax Forums

serial cog loader

This is so simple I couldn't believe it myself:)

And if it weren't for Rayman's work and Chip's loader, I would never have seen it!!
Thanks guys.
getSerialobj
               call    #rcv_char  
               mov whichcog,rx_char
               call    #rcv_char  
               setbyte numbytes,rx_char,#2
               call    #rcv_char  
               setbyte numbytes,rx_char,#1
               call    #rcv_char  
               setbyte numbytes,rx_char,#0
               wrfast  #0,#0  

.nextbytes     call #rcv_char
               wfbyte rx_char
               djnz numbytes,#.nextbytes
               coginit whichcog,##0
		ret


the test object is the compiled version of this
dat
		orgh	0
'
'
' blink
'
		org
              
		
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

the loader expects a byte containing the cog number, then three bytes representing the byte count ... and then the raw output of the obj file. I don't stop the cog first... so if you want you can get all of the empty cogs blinking by repeatedly loading the same file.


Makes me happier than.... you know:)

Comments

  • rjo__rjo__ Posts: 2,114
    On the computer side of things, I have Processing 3 handling the file.
    public void obj2serial() {
      // Open a file and read its binary data 
      String path = "C:/Users/Public/p2/all_cogs_blinkexp.obj";
      byte obj[] = loadBytes(path); 
      myPort.write(115);
      myPort.write(14);   //which cog
      int objbytes = obj.length;
      byte tempbyte=byte(objbytes >> 16 & 0xff) ;
      myPort.write(tempbyte);
      tempbyte=byte(objbytes >> 8 & 0xff) ;
      myPort.write(tempbyte);
     tempbyte=byte(objbytes & 0xff) ;
      myPort.write(tempbyte);
      // Print each value, from 0 to 255 
      for (int kya = 0; kya < obj.length; kya++) { 
    
        // bytes are from -128 to 127, this converts to 0 to 255 
        myPort.write( obj[kya]); 
        print(obj[kya]);
      } 
      // Print a blank line at the end 
      println(); 
      println(obj.length);
    }
    
Sign In or Register to comment.