NXC : Start Program command(?)

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: NXC : Start Program command(?)

Post by afanofosc »

SpawnProgram exists but as we have discussed previously (on the nxtasy forums) it does not work quite right. The firmware gets annoyed about something when you fiddle around with the Command module IOMap in this way. I have not yet been able to come up with a method that works reliably.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: NXC : Start Program command(?)

Post by muntoo »

Can you post the code? I'd like to see it, reliable or not.

Thanks. :)
Image

Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE


Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: NXC : Start Program command(?)

Post by afanofosc »

The code is in NXTDefs.h which you can view using the BricxCC Preferences dialog on the API tab. It is also checked into SVN on the BricxCC source forge project.

http://bricxcc.svn.sourceforge.net/svnr ... /NXTDefs.h

The code is pretty simple. It writes to the Command module IOMap.

Code: Select all

#ifdef __ENHANCED_FIRMWARE

#define __spawnProgram(_fname) \
  acquire __IOMWMutex \
  mov __IOMWBIArgs.ModuleID, CommandModuleID \
  mov __IOMWBIArgs.Offset, CommandOffsetActivateFlag \
  arrsubset __IOMWFlattenBuf, _fname, NA, 20 \
  arrbuild __IOMWBIArgs.Buffer, 1, 0, __IOMWFlattenBuf \
  syscall IOMapWriteByID, __IOMWBIArgs \
  release __IOMWMutex \
  stop NA

#else

#define __spawnProgram(_fname) \
  acquire __IOMWMutex \
  mov __IOMWArgs.ModuleName, CommandModuleName \
  mov __IOMWArgs.Offset, CommandOffsetActivateFlag \
  arrsubset __IOMWFlattenBuf, _fname, NA, 20 \
  arrbuild __IOMWArgs.Buffer, 1, 0, __IOMWFlattenBuf \
  syscall IOMapWrite, __IOMWArgs \
  release __IOMWMutex \
  stop NA

#endif
If you look in NXCDefs.h you'll see a one line macro that wraps this NBC code. It reliable spawns the specified program but when that program aborts or exits the firmware winds up in a bad state which requires pulling a battery to fix.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 18 guests