It’s Java source to C source translator, which allows to write MCU firmware in Java.
“yes”
Key features
-
Source code is written in Java, not C.
-
Source code is translated to C source code, which is compiled and programmed to target device. MCU doesn’t interpret anything.
-
No manual register handling needed! Write, for example, timer.setMode(TimerMode.FAST); instead of inconvenient TCCR1B |= (1<<WGM12); TCCR1A |= (1<<WGM10); Register handling is done automatically by MCU Java Source. Now you need to keep in mind only the principle of operation of MCU devices (timers, UART, ADC), but not registers and bits.
-
MCU register initialization on startup is done separately in init() function and is highly optimized.
-
MCU internal devices (e.g. timers) are represented as Java objects.
-
Interrupts are represented as object’s listeners (e.g. ExternalInterruptListener, TimerCompareListener). Of course, methods addXxxListener() also work.
-
UART uses input and output streams, as usual in Java.
-
User objects
-
Handy documentation (Javadoc) for all available objects and methods (functions).
-
Before translation source code is compiled by Java compiler. This prevents many errors.
-
For highly device-optimized applications, it is possible to work with register directly through Register class, unless there is another way to do needed action.
-
New MCUs and even platforms can be added, if C compiler supporting it exists.
What it is and is not MCU Java Source is:
-
Tool that allows to write MCU programs in Java.
MCU Java Source is not:
-
JVM (Java Virtual Machine) for MCU. All java code is translated to native at source level, then compiled to machine code.
-
Tool for AVR32 with hardware JVM. This program is not for high-end MCU’s.
Supported MCU platforms/devices
AVR Compiler – avr-gcc (or WinAVR package)
-
ATmega8
-
more will be added
Java source code elements
Supported (implemented) now
-
final. Primitive fields with final attribute turn to #define declarations. Strings and primitive arrays are put to program memory and got from it when they are used. No manual working with progmem – just make a field final!
-
Listeners. Only interrupt listeners are supported. Interrupt listeners turn to interrupt service routines.
-
Variables/fields. Only primitive (and primitive array) variables are passed to C source, MCU Java source object handling is interpreted by translator, user object are not supported now.
-
volatile is passed to C source. Use it when variable is used in background thread and interrupt.
-
byte and boolean types are supported throught typedef unsigned char.
-
I/O. InputStream and OutputStream classes are used in UART. Since charset enconders/decoders don’t fit into MCU, only default charset is used. That’s why there’s no BufferedReader, BufferedWriter classes, instead BufferedInputStream, BufferedOutputStream are used.
-
User objects
-
External device library (partially):
-
Multi digit LED display
-
Character LCD
-
Nokia 3310 LCD
-
Not yet implemented
-
External device library (partially implemented). For example, I2C EEPROM, temperature sensor.
-
Anonymous classes and statement like method(new MyListener())
-
Static initializers and instance initializers will be added to start() function
-
@Section annotation. Will specify, where to put final variables – Flash or EEPROM memory. Now Flash by default. Example:
@Section(Section.EEMEM)
private static final String MESSAGE = “Hello, EEPROM!”;
-
Two-threaded model: background thread and interrupt (Event Dispatch) thread. Task (implements Runnable) like in TinyOS 2.0. Tasks will be executed in background thread and posted from anywhere.
-
Simulator: Java source can also be compiled and run on computer. So, program will be simulated.
No way to do it
-
synchronized is completely ignored. Use volatile instead.
-
Exceptions. Native code don’t support them.
-
static is completely ignored because C has different meaning of it.
System requirements
-
Windows or Linux
-
Java 6 JDK
How it works
Java source code is converted to XML representation (java-ml) using modified version of Java2XML. Then every XML element is processed by MCU Java Source Translator. All primitive variables don’t change, all objects are translated. For translation of methods dealing with MCU registers, there is separate translator for each MCU. All listeners are converted to interrupt handlers. Classes of user objects are not processed using XML, they are called using reflection. The result of translation is XML representation of C source code for MCU. Then C source is generated from XML.