User Tools

Site Tools


en:projects:r8c:r8c_forth

R8C Forth

The German electronics Magazin Elektor distributed in its December 2005 issue a Renesas-R8C-Board produced by Glyn. The Software by Glyn distributed in the Magazin contained a C-Cross-Compiler for Windows. But it is more interesting to have a Forth System on this CPU.

division of functions

  • Heinz Schnitter writes the R8C Assembler ✓
  • Bernd Paysan ports Gforth-EC to the R8C CPU ✓

State 27mai2006

The System is now production quality.

  • The Forth can communicate over UART, LEDs and LCD can be controlled, new Programm Parts (Forth Words) will be compiled by default in RAM. With the words ram and rom the user can switch between compilation in (Flash-) ROM and RAM ;-).
  • Data-Flash can be altered with flashc! and flash!.
  • Gforth was modified to allow Code to be generated Flash-friedly (each bit will only cleared once). Immediate- and Compile-only-Bit are also set initially (means “not immediate” and “not compile-only”), and will be cleared on demand. The :dovar is located at an address ($C0FE) that allows modification to point to other Doer (using DOES>).
  • Gforth EC R8C supports up to 4k Forth-Program in the Data-Flash. The word savesystem stores a copy of the RAM in Flash-ROM, this allows turnkey application. The dataflash can be reprogrammed more frequently than the Data-Flash and allows experimentation with the system. The word empty resets the whole system and clears the memory.
  • The Assembler is really completed.
  • The remaining space in ROM is filled with user friendly Error-Messages
  • A simple Terminal-Application in GForth allows programmloading using a simple Handshake (Xon/Xoff is not possible due to the Polling-Intervall of the USB-Controller)
  • A port of Tetris for Terminals (tt.fs) fits in 4K ROM.
  • Timer C is used to provide accurate milliseconds (ms).

Downloading gforth

The current Development Version of Gforth can be loaded using pserver CVS. For Windows-User without ambition to install Cygwin, there is a Snapshot as a setup.exe Installer containing the current Development Version of GForth.

Downloading gforth-ec

The Gforth-R8C can be loaded and flashed in the R8C Flash as a S-Record-File.

Installation and Usage of gforth

Prior to installing Cygwin and compiling Gforth from the Source (./configure && make), it is recommended to install libffi to be able to interface with C-Libraries.

All required libraries are available out-of-the box when using the supplied setup.exe Installer. The Windows Program Menü additionaly contains the entry “Bash” which opens a BASH-Shell. All following Commands are given for a freshly opened BASH-Shell (for Cygwin-User: in Gforth-Directory).

Creating a ROM-Image for the R8C

The file rom-r8c.mot can be build using

./build-ec r8c

(will be the same as gforth-r8c.mot). There will also be a File data-r8c.mot created, which canbe used to repair a corrupted Data-Flash. The File rom-r8c.mot is loaded in Flash. Now we can connect to the R8C using a standard Terminal using 38400 Baud 8N1 (for example with Hyperterm, which is in the default Windows install — Set connection to “COMx”) and interactivly with the Forth in the R8C. The communication will go over the same serial Interface that is used to flash the R8C — no need for recabling. Downloading Forth Source with a normal Terminal Program is not possible, because Xon/Xoff is to slow. It is possible to cur'n'paste Forth Sorucecode to the Terminal when the Linefeed delay is set to 250ms.

You can play around with the Forth in the R8C, for example

1 2 + .
lcdpage
s" Hello World" lcdtype
adc@ .

All possible Forth commands (words) can be listed with

words

showing last defined words first.

Forth-Terminal using gforth

The GForth “build-in” terminal can be started using the command

./gforth arch/r8c/terminal.fs

By default, the communication will be over COM2 — if needed, the source file can be edited to support a defferent COM-Port, or — when using an USB Converter — map the USB Serial Interface to COM2 using the Windows Devicemanager. In Linux the Device /dev/ttyUSB0 is used by default. This default can also be cahnged by editing the source.

Using the terminal, the ported Tetris-for-Terminals by von Dirk Zoller can be started:

include arch/r8c/tt.fs

(this will take a while — the R8C is compiling the code itself). Start Tetris with

tt

LED Blinkenlights for R8C

A simple “Blinkenlights” Demo, that will autostart after Reset:

rom
: light!  led!  &100 ms ;
: runlight  1 light! 2 light! 4 light! 8 light!
  4 light! 2 light! ;
: blinkenlights  BEGIN  lauf  key?  UNTIL ;
' blinkenlights is bootmessage
ram
savesystem

The program will run until a key on the terminal is pressed.

ADC Converter in the R8C

A loop that reads from the ADC (Analog to Digital Converter) and prints the value on the LCD:

: adcmeter
  BEGIN  6 adc@ 0 <# #s #> lcdpage lcdtype &200 ms
         key? UNTIL ;

Multitasker

This a simple Multitasker that allows exactly one backgroundtask:

rom
 
Variable bgtask ram $20 cells allot rom
:noname  bgtask @ 0= ?EXIT
    rp@ bgtask @ sp@ cell+ bgtask ! sp! rp! ;
IS pause
: task r> bgtask $20 cells + !
  bgtask $20 cells + bgtask $10 cells + !
  bgtask $10 cells + bgtask ! ;
:noname echo @ IF
     BEGIN pause key? UNTIL THEN (key) ;
is key
 
ram

An adapted version of the Blinkenlights Demo above:

rom
: light!  led!  &100 ms ;
: run  1 light! 2 light! 4 light! 8 light!
  4 light! 2 light! ;
: blinkenlights
  task  BEGIN  run  AGAIN ;
ram

Text Scroller

Similar to the Blinkenlights we can create a Text Scroller. The scroll speed is controlled with the potentiometer on ADC channel 6.

rom
 
Create text
," GNU Forth EC R8C -- Microprozessor -- "
Create ledtable 1 c, 2 c, 4 c, 8 c, 4 c, 2 c,
Variable /text
 
: scroller  task
  BEGIN  text count /text @ over mod /string
         16 min dup >r lcdpage lcdtype
         r@ 16 < IF  text 1+ 16 r@ - lcdtype  THEN
         rdrop 1 /text +!
         /text @ 6 mod ledtable + c@ led!
         6 adc@ 2/ ms
  AGAIN ;
 
ram
en/projects/r8c/r8c_forth.txt · Last modified: 2013-06-12 18:09 by bernd