We recently replaced our original "Small C" interpreter running in the SRV-1 firmware with a very powerful C interpreter called picoC -
http://code.google.com/p/picoc/ - which supports a substantial subset of the full C language syntax.
A few tips on using the C interpreter:
- Make certain you are running the latest version of srv1.ldr firmware from
http://code.google.com/p/surveyor-srv1-firmware/source/checkout or
http://code.google.com/p/surveyor-srv1-firmware/downloads/list - A preliminary description of picoC commands is found at
http://www.surveyor.com/C.html - picoC supports a "stored program" mode and an "interactive" mode. 'Q' launches the stored program mode. '!' launches the interactive mode. Note that when a stored program finishes running, picoC switches to interactive mode which allows you to continue accessing variables and functions that were defined by the stored program.
- The stored program mode runs programs from the flash buffer located in SDRAM (addr 0x00100000). This is the same flash buffer that's used for srv1.ldr firmware uploads. It is possible to directly enter code into the flash buffer using the 'E' editor, but a more secure method is to use XMODEM file transfer (the same method that is used to transfer srv1.ldr firmware updates.
- After initiating an XMODEM session via the 'X' command, you need to transfer your C source code via XMODEM-CRC or XMODEM-1K protocol. On Windows, the TeraTerm terminal program -
http://www.ayera.com/teraterm/ - has very good support for XMODEM transfers. On OS/X or Linux, we use the lrzsz transfer program -
http://www.ohse.de/uwe/software/lrzsz.html . With the rest of the SRV-1 source code, you'll find shell scripts to automate this transfer - take a look at 'send1' (for arbitrary file transfer) and 'load1' (for srv1.ldr transfer).
- After the C source has been uploaded to the flash buffer, you can verify that it has been transferred by sending the 'zd' command to dump the contents of the flash buffer. You can also save you C source to flash memory - the 'zw' command saves the flash buffer contents to flash sector #4, and the 'zr' command retrieves the flash sector #4 contents to the flash buffer.
- You aren't limited to storage/retrieval from flash sector #4. There are 64 x 64kB flash sectors numbered 00 - 63, and the 'zW' and 'zR' commands allow you to save/retrieve the flash buffer contents to any flash sector except sectors 0 and 1 where srv1.ldr is stored.
- Everything happens through the "flash buffer" - we use the same buffer for uploading new firmware, saving and retrieving data from flash memory, uploading and running C interpreter programs.
Here is a summary of commands for manipulating the flash buffer -
X - for XMODEM receive
zc - clear the flash buffer
zd - display the contents of the flash buffer
zr - retrieve the contents of flash sector 04
zw - write the flash buffer to flash sector 04
zR - retrieve the contents of any arbitrary flash sector 02-63
zW - write the contents of the flash buffer to any arbitrary flash sector 02-63
zC - compute the CRC-16 of flash buffer contents
E - simple line editor which writes directly into the flash buffer
Q - launches C interpreter to run contents of flash buffer
As noted above, if you use XMODEM to transfer a file, you can view the contents of the buffer using 'zd'. If you want to save the contents, use 'zw' or 'zWxx'.
- It is somewhat easier to use the C interpreter in interactive mode with a line-based terminal such as telnet in "line mode" or nc ("netcat"), as the interpreter doesn't have an erase or backup key. A Windows version of nc is found here -
http://www.surveyor.com/blackfin/nc111nt.zip - There is no "main()" function in picoC. Take a look at the code samples in
http://www.surveyor.com/C.html - any of those should be able to run as complete standalone programs, e.g.
Code:int x, y, z;
for (x = 0; x < 2; x++)
{
for (y = 0; y < 3; y++)
{
for (z = 0; z < 3; z++)
{
printf("%d %d %d\n", x, y, z);
}
}
}
Questions about using the new C interpreter should be posted here. Also, we would like to see interesting code samples posted here. At some point, I hope we can build a repository of such samples.