'' ================================================================================================= '' '' File....... cmd_processor.spin '' Purpose.... '' Author..... Jon "JonnyMac" McPhalen (aka Jon Williams) '' Copyright (c) 2010 Jon McPhalen '' -- see below for terms of use '' E-mail..... jon@jonmcphalen.com '' Started.... '' Updated.... '' '' ================================================================================================= con _clkmode = xtal1 + pll16x _xinfreq = 6_250_000 con #1, HOME, #8, BKSP, TAB, LF, CLREOL, CLRDN, CR, #16, CLS ' PST formmatting control obj debug : "fullduplexserial" var long cog long command long parm1 long parm2 long parm3 ' result pub main | x, y debug.start(31, 30, %0000, 115_200) pause(1) debug.tx(CLS) init ' start math cog debug.str(string("2 + 3 = ")) debug.dec(addem(2, 3)) debug.tx(CR) debug.str(string("5 - 8 = ")) debug.dec(subem(5, 8)) debug.tx(CR) repeat pub pause(ms) | t, ms1 t := cnt ' sync with system counter ms1 := clkfreq / 1000 ' ticks in 1ms repeat ms waitcnt(t += ms1) pub init | okay finalize ' stop if already loaded okay := cog := cognew(@asm, @command) + 1 ' start the cog return okay pub finalize if cog cogstop(cog~ - 1) pub addem(x, y) '' returns x+y longmove(@parm1, @x, 2) ' cop parameters command := 1 ' alert bg cog repeat until (command == 0) ' let it finish return parm3 pub subem(x, y) '' returns x-y longmove(@parm1, @x, 2) ' cop parameters command := 2 ' alert bg cog repeat until (command == 0) ' let it finish return parm3 dat org 0 asm mov tmp1, par mov cmdpntr, tmp1 ' hub address of command add tmp1, #4 mov p1pntr, tmp1 ' hub address of parm1 add tmp1, #4 mov p2pntr, tmp1 ' hub address of parm2 add tmp1, #4 mov p3pntr, tmp1 ' hub address of parm3 getcmd rdlong cmd, cmdpntr ' wait for command cmps cmd, #0 wc, wz ' validate >= 0 if_be wrlong ZERO, cmdpntr if_be jmp #getcmd max cmd, #4 ' validate <= 4 mov tmp1, #cmdtable add tmp1, cmd jmp tmp1 cmdtable jmp #getcmd ' place holder, cmd = 0 cmd1 jmp #docmd1 cmd2 jmp #docmd2 cmd3 jmp #docmd3 badcmd jmp #getcmd ' place holder, cmd = 4 docmd1 rdlong tmp1, p1pntr rdlong tmp2, p2pntr adds tmp1, tmp2 wrlong tmp1, p3pntr wrlong ZERO, cmdpntr jmp #getcmd docmd2 rdlong tmp1, p1pntr rdlong tmp2, p2pntr subs tmp1, tmp2 wrlong tmp1, p3pntr wrlong ZERO, cmdpntr jmp #getcmd docmd3 ' do something jmp #getcmd ' basepntr = cog address of array or table ' idx = index of element to write ' value = value that is read rdarray mov tmp1, basepntr add tmp1, idx movs rdval, tmp1 nop rdval mov value, 0-0 rdarray_ret ret ' basepntr = cog address of array or table ' idx = index of element to write ' value = value to write wrarray mov tmp1, basepntr add tmp1, idx movd wrval, tmp1 nop wrval mov 0-0, value wrarray_ret ret ' -------------------------------------------------------------------------------------------------- ZERO long 0 cmdpntr res 1 p1pntr res 1 p2pntr res 1 p3pntr res 1 cmd res 1 basepntr res 1 idx res 1 value res 1 tmp1 res 1 tmp2 res 1 fit 492 dat {{ Terms of Use: MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. }}