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 #include "flashprog.h"
44 extern U32 __free_ram_start__;
45 extern U32 __free_ram_end__;
46 extern U32 __extra_ram_start__;
47 extern U32 __extra_ram_end__;
54 wait_for_power_down_signal()
57 int b = buttons_get();
59 // Check for ENTER and ESCAPE pressed
61 // Shut down power immediately
70 handle_uncaught_exception(Object * exception,
71 const Thread * thread,
72 const MethodRecord * methodRecord,
73 const MethodRecord * rootMethod, byte * pc)
75 sound_freq(100,500); // buzz
77 display_goto_xy(0, 0);
78 display_string("Java Exception:");
79 display_goto_xy(0, 1);
80 display_string("Class:");
81 display_goto_xy(7, 1);
82 display_int(get_class_index(exception), 0);
83 display_goto_xy(0, 2);
84 display_string("Method:");
85 display_goto_xy(8, 2);
86 display_int(methodRecord->signatureId, 0);
88 wait_for_power_down_signal();
94 int b = buttons_get();
96 // Check for ENTER and ESCAPE pressed
98 // Shut down power immediately
100 nxt_avr_power_down();
106 assert_hook(boolean aCond, int aCode)
110 display_goto_xy(0,0);
111 display_string("Assert failed");
112 display_goto_xy(0,1);
113 display_string("Code: ");
114 display_goto_xy(6,1);
115 display_int(aCode,0);
124 byte *ram_end = (byte *) (&__free_ram_end__);
125 byte *ram_start = (byte *) (&__free_ram_start__);
129 //printf("Initializing Binary\n");
131 #if EXECUTE_FROM_FLASH
133 MasterRecord *mrec = get_master_record();
134 int staticSize = mrec->staticStateLength;
135 int statusSize = (mrec->lastClass + 1) * sizeof( classStatusBase[0]);
137 staticSize = (staticSize + 1) & ~(1);
138 statusSize = (statusSize + 3) & ~(3);
140 ram_end -= staticSize * 2;
141 classStaticStateBase = ram_end;
143 ram_end -= statusSize;
144 classStatusBase = ram_end;
146 memset( classStatusBase, 0, statusSize);
150 // Initialize binary image state
153 //printf("Initializing memory\n");
159 #if ! EXECUTE_FROM_FLASH
160 // Skip java binary if it is an top of ram
162 ram_end -= (jsize + 4);
165 //size = ((unsigned) ram_end) - ((unsigned) ram_start);
170 memory_add_region(region, (byte *) ram_end);
172 /*Add extra RAM if available */
173 //ram_end = (byte *) (&__extra_ram_end__);
174 //ram_start = (byte *) (&__extra_ram_start__);
175 //size = ((unsigned) ram_end) - ((unsigned) ram_start);
178 // memory_add_region(ram_start, ram_end);
181 //printf("Initializing exceptions\n");
183 // Initialize exceptions
186 // Create the boot thread (bootThread is a special global)
187 bootThread = (Thread *) new_object_for_class(JAVA_LANG_THREAD);
190 if (!init_thread(bootThread)) {
193 //printf("Executing Interpreter\n");
195 // Execute the bytecode interpreter
196 set_program_number(0);
199 // Engine returns when all non-daemon threads are dead
202 /***************************************************************************
203 * int nxt_main *--------------------------------------------------------------------------
204 ***************************************************************************/
205 //int main (int argc, char *argv[])
207 nxt_main(int bin, int size)
213 #if EXECUTE_FROM_FLASH
215 size = (size + 3) & ~3;
216 binary = (char *) bin;
219 // Execute flash menu
221 bin = (unsigned *) 0x00108000;
222 size = *((unsigned *) 0x00113ffc);
223 size = (size + 3) & ~3;
224 binary = (char *) bin;
229 size = (size + 3) & ~3;
230 temp = ((unsigned *) (&__free_ram_end__)) - (size >> 2);
231 memcpy(temp,bin,size);
232 binary = (char *) temp;
235 // Execute flash menu
237 bin = (unsigned *) 0x00108000;
238 size = *((unsigned *) 0x00113ffc);
239 size = (size + 3) & ~3;
240 temp = ((unsigned *) (&__free_ram_end__)) - (size >> 2);
241 memcpy(temp,bin,size);
242 binary = ((char *) temp);
247 // reset all motors, sensors and devices
250 nxt_motor_reset_all();
253 display_set_auto_update(1);
254 // printf("Installing Binary\n");
256 install_binary(binary);
258 // printf("Running\n");
265 const U8 splash_data[4 * 26] = {
266 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
267 0x00, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFC,
268 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA0, 0x40, 0xA0, 0x40,
269 0xA0, 0x40, 0xA0, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
270 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x0A, 0x05, 0x0A, 0x05,
271 0x0A, 0x05, 0x0A, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
272 0x0F, 0x1F, 0x3F, 0x3F, 0x7F, 0x7F, 0xFC, 0xF8, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
273 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF8, 0xFC, 0x7F, 0x7F, 0x3F, 0x3F, 0x1F, 0x0F,
277 show_splash(U32 milliseconds)
280 display_bitmap_copy(splash_data, 26, 4, 37, 1);
282 display_goto_xy(6, 6);
283 display_string("LEJOS");
286 systick_wait_ms(milliseconds);
294 extern U32 __system_stack_bottom__;
295 extern U32 __system_stack_top__;
296 U32 *sp = &__system_stack_bottom__;
299 while ((sp < &__system_stack_top__) && *sp == 0x6b617453) {
317 /* set up power for ultrasonic sensor on port 1 (port 0 here )*/
318 nxt_avr_set_input_power(0,1);
324 if ((iterator & 15) == 0) {
325 motor_mode = (iterator >> 4) & 3;
326 switch (motor_mode) {
329 nxt_motor_set_speed(2, -100, 0);
332 nxt_motor_set_speed(2, 100, 0);
335 nxt_motor_set_speed(2, 0, 0);
338 nxt_motor_set_speed(2, 0, 1);
344 if ((iterator %10) < 5) {
345 buttons = buttons_get();
347 display_goto_xy(iterator & 7, 0);
348 display_string("LEJOS NXT");
350 display_goto_xy(0, 1);
351 display_string("TIME ");
352 display_unsigned(systick_get_ms(), 0);
354 display_goto_xy(0, 2);
355 display_string("BATTERY ");
356 display_unsigned(battery_voltage(), 0);
358 display_goto_xy(0, 3);
359 display_string("BUTTONS ");
361 display_string("0 ");
363 display_string("1 ");
365 display_string("2 ");
367 display_string("3 ");
369 display_goto_xy(0, 4);
370 display_string("ADC ");
371 display_unsigned(sensor_adc(0), 5);
372 display_unsigned(sensor_adc(1), 5);
373 display_goto_xy(0, 5);
375 display_unsigned(sensor_adc(2), 5);
376 display_unsigned(sensor_adc(3), 5);
378 i2c_start_transaction(0,1,0x42,1,&distance,1,0);
379 systick_wait_ms(200);
380 result = i2c_busy(0);
382 display_goto_xy(0,6);
383 display_string("DIST ");
384 display_unsigned(distance,3);
387 systick_wait_ms(500);
391 display_goto_xy(iterator & 7, 0);
392 display_string("LEJOS NXT");
394 display_goto_xy(0, 1);
395 display_string("TIME ");
396 display_unsigned(systick_get_ms(), 0);
397 display_goto_xy(0, 2);
398 display_string("Stack ");
399 display_unsigned(free_stack(), 0);
400 display_goto_xy(0, 3);
401 switch (motor_mode) {
403 display_string("MOTORS REV");
406 display_string("MOTORS FWD");
409 display_string("MOTORS COAST");
412 display_string("MOTORS BRAKE");
416 display_goto_xy(1, 4);
417 display_int(nxt_motor_get_count(0), 0);
418 display_goto_xy(1, 5);
419 display_int(nxt_motor_get_count(1), 0);
420 display_goto_xy(1, 6);
421 display_int(nxt_motor_get_count(2), 0);
424 systick_wait_ms(500);
433 * PLL and flash have been initialised and
434 * interrupts are off, but the AIC has not been initialised.
444 systick_wait_ms(1000); // wait for LCD to stabilize
447 //flash_set_mode(*((unsigned *) 0x0010fff8));
456 int next = gNextProgram;
458 nxt_main(next, gNextProgramSize);
463 nxt_avr_power_down();