3 #include "interrupts.h"
13 #include "constants.h"
17 #include "specialclasses.h"
18 #include "specialsignatures.h"
21 #include "interpreter.h"
22 #include "exceptions.h"
26 #include "platform_hooks.h"
27 #include "java_binary.h"
32 #include "nxt_motors.h"
34 #include "lejos_nxt.h"
40 extern U32 __free_ram_start__;
41 extern U32 __free_ram_end__;
42 extern U32 __extra_ram_start__;
43 extern U32 __extra_ram_end__;
50 wait_for_power_down_signal()
53 int b = buttons_get();
55 // Check for ENTER and ESCAPE pressed
57 // Shut down power immediately
66 handle_uncaught_exception(Object * exception,
67 const Thread * thread,
68 const MethodRecord * methodRecord,
69 const MethodRecord * rootMethod, byte * pc)
72 display_goto_xy(0, 0);
73 display_string("Java Exception:");
74 display_goto_xy(0, 1);
75 display_string("Class:");
76 display_goto_xy(7, 1);
77 display_int(get_class_index(exception), 0);
78 display_goto_xy(0, 2);
79 display_string("Method:");
80 display_goto_xy(8, 2);
81 display_int(methodRecord->signatureId, 0);
83 wait_for_power_down_signal();
89 int b = buttons_get();
91 // Check for ENTER and ESCAPE pressed
93 // Shut down power immediately
101 assert_hook(boolean aCond, int aCode)
111 //printf("Initializing Binary\n");
113 // Initialize binary image state
116 //printf("Initializing memory\n");
120 byte *ram_end = (byte *) (&__free_ram_end__);
121 byte *ram_start = (byte *) (&__free_ram_start__);
124 // Skip java binary if it is an top of ram
127 ram_end -= (jsize + 4);
128 size = ((unsigned) ram_end) - ((unsigned) ram_start);
133 memory_add_region(region, (byte *) ram_end);
135 /*Add extra RAM if available */
136 ram_end = (byte *) (&__extra_ram_end__);
137 ram_start = (byte *) (&__extra_ram_start__);
138 size = ((unsigned) ram_end) - ((unsigned) ram_start);
141 // memory_add_region(ram_start, ram_end);
144 //printf("Initializing exceptions\n");
146 // Initialize exceptions
149 // Create the boot thread (bootThread is a special global)
150 bootThread = (Thread *) new_object_for_class(JAVA_LANG_THREAD);
153 if (!init_thread(bootThread)) {
156 //printf("Executing Interpreter\n");
158 // Execute the bytecode interpreter
159 set_program_number(0);
162 // Engine returns when all non-daemon threads are dead
165 /***************************************************************************
166 * int nxt_main *--------------------------------------------------------------------------
167 ***************************************************************************/
168 //int main (int argc, char *argv[])
173 char *binary = java_binary;
176 if (__extra_ram_start__ != __extra_ram_end__) {
179 temp = ((unsigned *) (&__free_ram_end__)) - 1;
181 binary = ((char *) temp) - jsize;
186 // printf("Installing Binary\n");
188 install_binary(binary);
190 // printf("Running\n");
197 const U8 splash_data[4 * 26] = {
198 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
199 0x00, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFC,
200 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA0, 0x40, 0xA0, 0x40,
201 0xA0, 0x40, 0xA0, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
202 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x0A, 0x05, 0x0A, 0x05,
203 0x0A, 0x05, 0x0A, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
204 0x0F, 0x1F, 0x3F, 0x3F, 0x7F, 0x7F, 0xFC, 0xF8, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
205 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF8, 0xFC, 0x7F, 0x7F, 0x3F, 0x3F, 0x1F, 0x0F,
209 show_splash(U32 milliseconds)
212 display_bitmap_copy(splash_data, 26, 4, 37, 1);
214 display_goto_xy(6, 6);
215 display_string("LEJOS");
218 systick_wait_ms(milliseconds);
226 extern U32 __system_stack_bottom__;
227 extern U32 __system_stack_top__;
228 U32 *sp = &__system_stack_bottom__;
231 while ((sp < &__system_stack_top__) && *sp == 0x6b617453) {
249 /* set up power for ultrasonic sensor on port 1 (port 0 here )*/
250 nxt_avr_set_input_power(0,2);
256 if ((iterator & 15) == 0) {
257 motor_mode = (iterator >> 4) & 3;
258 switch (motor_mode) {
261 nxt_motor_set_speed(2, -100, 0);
264 nxt_motor_set_speed(2, 100, 0);
267 nxt_motor_set_speed(2, 0, 0);
270 nxt_motor_set_speed(2, 0, 1);
276 if ((iterator %10) < 5) {
277 buttons = buttons_get();
279 display_goto_xy(iterator & 7, 0);
280 display_string("LEJOS NXT");
282 display_goto_xy(0, 1);
283 display_string("TIME ");
284 display_unsigned(systick_get_ms(), 0);
286 display_goto_xy(0, 2);
287 display_string("BATTERY ");
288 display_unsigned(battery_voltage(), 0);
290 display_goto_xy(0, 3);
291 display_string("BUTTONS ");
293 display_string("0 ");
295 display_string("1 ");
297 display_string("2 ");
299 display_string("3 ");
301 display_goto_xy(0, 4);
302 display_string("ADC ");
303 display_unsigned(sensor_adc(0), 5);
304 display_unsigned(sensor_adc(1), 5);
305 display_goto_xy(0, 5);
307 display_unsigned(sensor_adc(2), 5);
308 display_unsigned(sensor_adc(3), 5);
310 i2c_start_transaction(0,1,0x42,1,&distance,1,0);
311 systick_wait_ms(200);
312 result = i2c_busy(0);
314 display_goto_xy(0,6);
315 display_string("DIST ");
316 display_unsigned(distance,3);
319 systick_wait_ms(500);
323 display_goto_xy(iterator & 7, 0);
324 display_string("LEJOS NXT");
326 display_goto_xy(0, 1);
327 display_string("TIME ");
328 display_unsigned(systick_get_ms(), 0);
329 display_goto_xy(0, 2);
330 display_string("Stack ");
331 display_unsigned(free_stack(), 0);
332 display_goto_xy(0, 3);
333 switch (motor_mode) {
335 display_string("MOTORS REV");
338 display_string("MOTORS FWD");
341 display_string("MOTORS COAST");
344 display_string("MOTORS BRAKE");
348 display_goto_xy(1, 4);
349 display_int(nxt_motor_get_count(0), 0);
350 display_goto_xy(1, 5);
351 display_int(nxt_motor_get_count(1), 0);
352 display_goto_xy(1, 6);
353 display_int(nxt_motor_get_count(2), 0);
356 systick_wait_ms(500);
365 * PLL and flash have been initialised and
366 * interrupts are off, but the AIC has not been initialised.
383 systick_wait_ms(5000);
386 nxt_avr_power_down();