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)
76 display_goto_xy(0, 0);
77 display_string("Java Exception:");
78 display_goto_xy(0, 1);
79 display_string("Class:");
80 display_goto_xy(7, 1);
81 display_int(get_class_index(exception), 0);
82 display_goto_xy(0, 2);
83 display_string("Method:");
84 display_goto_xy(8, 2);
85 display_int(methodRecord->signatureId, 0);
87 wait_for_power_down_signal();
93 int b = buttons_get();
95 // Check for ENTER and ESCAPE pressed
97 // Shut down power immediately
105 assert_hook(boolean aCond, int aCode)
109 display_goto_xy(0,0);
110 display_string("Assert failed");
111 display_goto_xy(0,1);
112 display_string("Code: ");
113 display_goto_xy(6,1);
114 display_int(aCode,0);
125 //printf("Initializing Binary\n");
127 // Initialize binary image state
130 //printf("Initializing memory\n");
134 byte *ram_end = (byte *) (&__free_ram_end__);
135 byte *ram_start = (byte *) (&__free_ram_start__);
138 // Skip java binary if it is an top of ram
141 ram_end -= (jsize + 4);
142 size = ((unsigned) ram_end) - ((unsigned) ram_start);
147 memory_add_region(region, (byte *) ram_end);
149 /*Add extra RAM if available */
150 ram_end = (byte *) (&__extra_ram_end__);
151 ram_start = (byte *) (&__extra_ram_start__);
152 size = ((unsigned) ram_end) - ((unsigned) ram_start);
155 // memory_add_region(ram_start, ram_end);
158 //printf("Initializing exceptions\n");
160 // Initialize exceptions
163 // Create the boot thread (bootThread is a special global)
164 bootThread = (Thread *) new_object_for_class(JAVA_LANG_THREAD);
167 if (!init_thread(bootThread)) {
170 //printf("Executing Interpreter\n");
172 // Execute the bytecode interpreter
173 set_program_number(0);
176 // Engine returns when all non-daemon threads are dead
179 /***************************************************************************
180 * int nxt_main *--------------------------------------------------------------------------
181 ***************************************************************************/
182 //int main (int argc, char *argv[])
184 nxt_main(int bin, int size)
191 size = (size + 3) & ~3;
192 temp = ((unsigned *) (&__free_ram_end__)) - (size >> 2);
193 memcpy(temp,bin,size);
194 binary = (char *) temp;
197 // Execute flash menu
199 bin = (unsigned *) 0x00108000;
200 size = *((unsigned *) 0x0010fffc);
201 size = (size + 3) & ~3;
202 temp = ((unsigned *) (&__free_ram_end__)) - (size >> 2);
203 memcpy(temp,bin,size);
204 binary = ((char *) temp);
210 // printf("Installing Binary\n");
212 install_binary(binary);
214 // printf("Running\n");
221 const U8 splash_data[4 * 26] = {
222 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
223 0x00, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFC,
224 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA0, 0x40, 0xA0, 0x40,
225 0xA0, 0x40, 0xA0, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
226 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x0A, 0x05, 0x0A, 0x05,
227 0x0A, 0x05, 0x0A, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
228 0x0F, 0x1F, 0x3F, 0x3F, 0x7F, 0x7F, 0xFC, 0xF8, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
229 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF8, 0xFC, 0x7F, 0x7F, 0x3F, 0x3F, 0x1F, 0x0F,
233 show_splash(U32 milliseconds)
236 display_bitmap_copy(splash_data, 26, 4, 37, 1);
238 display_goto_xy(6, 6);
239 display_string("LEJOS");
242 systick_wait_ms(milliseconds);
250 extern U32 __system_stack_bottom__;
251 extern U32 __system_stack_top__;
252 U32 *sp = &__system_stack_bottom__;
255 while ((sp < &__system_stack_top__) && *sp == 0x6b617453) {
273 /* set up power for ultrasonic sensor on port 1 (port 0 here )*/
274 nxt_avr_set_input_power(0,1);
280 if ((iterator & 15) == 0) {
281 motor_mode = (iterator >> 4) & 3;
282 switch (motor_mode) {
285 nxt_motor_set_speed(2, -100, 0);
288 nxt_motor_set_speed(2, 100, 0);
291 nxt_motor_set_speed(2, 0, 0);
294 nxt_motor_set_speed(2, 0, 1);
300 if ((iterator %10) < 5) {
301 buttons = buttons_get();
303 display_goto_xy(iterator & 7, 0);
304 display_string("LEJOS NXT");
306 display_goto_xy(0, 1);
307 display_string("TIME ");
308 display_unsigned(systick_get_ms(), 0);
310 display_goto_xy(0, 2);
311 display_string("BATTERY ");
312 display_unsigned(battery_voltage(), 0);
314 display_goto_xy(0, 3);
315 display_string("BUTTONS ");
317 display_string("0 ");
319 display_string("1 ");
321 display_string("2 ");
323 display_string("3 ");
325 display_goto_xy(0, 4);
326 display_string("ADC ");
327 display_unsigned(sensor_adc(0), 5);
328 display_unsigned(sensor_adc(1), 5);
329 display_goto_xy(0, 5);
331 display_unsigned(sensor_adc(2), 5);
332 display_unsigned(sensor_adc(3), 5);
334 i2c_start_transaction(0,1,0x42,1,&distance,1,0);
335 systick_wait_ms(200);
336 result = i2c_busy(0);
338 display_goto_xy(0,6);
339 display_string("DIST ");
340 display_unsigned(distance,3);
343 systick_wait_ms(500);
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);
353 display_goto_xy(0, 2);
354 display_string("Stack ");
355 display_unsigned(free_stack(), 0);
356 display_goto_xy(0, 3);
357 switch (motor_mode) {
359 display_string("MOTORS REV");
362 display_string("MOTORS FWD");
365 display_string("MOTORS COAST");
368 display_string("MOTORS BRAKE");
372 display_goto_xy(1, 4);
373 display_int(nxt_motor_get_count(0), 0);
374 display_goto_xy(1, 5);
375 display_int(nxt_motor_get_count(1), 0);
376 display_goto_xy(1, 6);
377 display_int(nxt_motor_get_count(2), 0);
380 systick_wait_ms(500);
389 * PLL and flash have been initialised and
390 * interrupts are off, but the AIC has not been initialised.
402 //flash_set_mode(*((unsigned *) 0x0010fff8));
411 int next = gNextProgram;
415 nxt_main(next, gNextProgramSize);
417 while (gNextProgram != 0);
419 systick_wait_ms(5000);
422 nxt_avr_power_down();