1 /*****************************************************************************
4 * COPYRIGHT 2008 Takashi Chikamasa <takashic@cybernet.co.jp>
7 * leJOS NXJ is a full firmware replacement of LEGO Mindstorms NXT and
8 * designed for Java programming environment for the NXT
9 * ( For more detailed information, please see: http://lejos.sourceforge.net/ )
10 * In the leJOS NXJ distribution, C source files for NXT platform layer is also
11 * included besides with the Java VM. The platform C source code is well
12 * structured, comprehensive, and achieved higher performance than the LEGO's
13 * one. Therefore, leJOS NXJ (platform) is also the best GCC based C/C++
14 * development platform for NXT.
16 * The contents of this file are subject to the Mozilla Public License
17 * Version 1.0 (the "License"); you may not use this file except in
18 * compliance with the License. You may obtain a copy of the License at
19 * http://www.mozilla.org/MPL/
21 * Software distributed under the License is distributed on an "AS IS"
22 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
23 * License for the specific language governing rights and limitations
26 * The Original Code is TinyVM code, first released March 6, 2000,
27 * later released as leJOS on September 23, 2000.
29 * The Initial Developer of the Original Code is Jose H. Solorzano.
31 * Contributor(s): see leJOS NXJ ACKNOWLEDGEMENTS .
34 * <About TOPPERS OSEK>
35 * TOPPERS OSEK is an open source OSEK kernel and developed by TOPPERS project.
36 * TOPPERS(Toyohashi OPen Platform for Embedded Real-time Systems) has been managed
37 * by a Non Profit Organization founded in Sep. 2003 and has been led by Professor
38 * Hiroaki Takada of Nagoya University in Japan.
40 * TOPPERS OSEK program is covered by the TOPPERS License as published
41 * by the TOPPERS PROJECT (http://www.toppers.jp/en/index.html).
43 *****************************************************************************/
47 #include "ecrobot_base.h"
48 #include "ecrobot_private.h"
49 #include "ecrobot_interface.h"
52 extern void lejos_osek_stop(void);
55 /* C++ constructor/destructor table */
56 extern void (*__ctor_begin[])(void);
57 extern void (*__ctor_end)(void);
58 extern void (*__dtor_begin[])(void);
59 extern void (*__dtor_end)(void);
61 /* declarations for splash screen BMP file */
63 EXTERNAL_BMP_DATA(nxtjsp_splash);
65 EXTERNAL_BMP_DATA(nxtosek_splash);
68 /* used for getting the address of a constant data */
69 const UINT exec_addr[1] = {0};
71 static CHAR status_bar[MAX_STATUS_BAR_LENGTH];
72 static SINT status_bar_position = 0;
74 /* flag to notify RTOS is started */
75 static volatile SINT OS_flag;
77 void init_OS_flag(void)
82 void set_OS_flag(void)
87 SINT get_OS_flag(void)
93 * execute C++ constructors
95 void cpp_constructor(void)
99 /* call all global object constructors */
100 for (i=0;__ctor_begin[i] != __ctor_end;i++)
101 (*__ctor_begin[i])();
105 * execute C++ destructors
107 void cpp_destructor(void)
111 /* call all global object destructors */
112 for (i=0;__dtor_begin[i] != __dtor_end;i++)
113 (*__dtor_begin[i])();
117 * return where the program is executed
119 SINT execution_mode(void)
121 if (exec_addr < (volatile UINT *)0x200000)
123 return EXECUTED_FROM_FLASH;
125 return EXECUTED_FROM_SRAM;
129 * display application splash screen which is designed in
130 * ecrobot_splash.bmp file
132 void show_splash_screen(void)
136 static U8 lcd[NXT_LCD_DEPTH*NXT_LCD_WIDTH];
138 /* convert bmp file data to an array data for LCD */
140 ecrobot_bmp2lcd(BMP_DATA_START(nxtjsp_splash), lcd, 100, 64);
142 ecrobot_bmp2lcd(BMP_DATA_START(nxtosek_splash), lcd, 100, 64);
145 for (column = 0; column < NXT_LCD_WIDTH; column++)
147 for (row = 0; row < NXT_LCD_DEPTH; row++)
149 index = row * NXT_LCD_WIDTH + column;
150 lcd[index] = ~lcd[index];
153 display_bitmap_copy(lcd, 100, 8, 0, 0);
155 systick_wait_ms(800/100);
158 if (execution_mode() == EXECUTED_FROM_SRAM)
160 /* flip back to the original data for re-start */
161 for (column = 0; column < NXT_LCD_WIDTH; column++)
163 for (row = 0; row < NXT_LCD_DEPTH; row++)
165 index = row * NXT_LCD_WIDTH + column;
166 lcd[index] = ~lcd[index];
170 systick_wait_ms(200);
174 * display application main screen
176 void show_main_screen(void)
179 display_goto_xy(0, 5);
180 display_string("================");
181 display_goto_xy(0, 6);
182 display_string("<STP ENTR RUN>");
183 display_goto_xy(0, 7);
184 display_string(" EXIT ");
189 * display status bar in the main screen
191 * clear: 1(clear status bar), 0(not clear status bar)
193 void display_status_bar(SINT clear)
197 memset(status_bar, ' ', MAX_STATUS_BAR_LENGTH);
198 status_bar_position = 0;
201 display_goto_xy(0, 3);
202 display_string("BATT:");
203 display_unsigned(ecrobot_get_battery_voltage()/100, 0);
204 display_goto_xy(0, 4);
205 display_string(status_bar);
209 void show_bd_addr(U8 *bd_addr)
215 display_goto_xy(0, 0);
216 display_string("BD_ADDR:");
217 display_goto_xy(0, 1);
218 for (i = 0; i < 7; i++)
220 display_hex(bd_addr[i], 2);
226 void show_bd_addr_err(void)
230 display_goto_xy(0, 0);
231 display_string("BD_ADDR: FAILED");
232 display_goto_xy(0, 1);
233 display_string("RESTART NXT.");
239 * add information to the status bar
241 void add_status_info(SINT status)
249 case EXECUTED_FROM_FLASH:
252 case EXECUTED_FROM_SRAM:
262 if ((status_bar_position + strlen(str)) <= MAX_STATUS_BAR_LENGTH)
264 strcpy(&status_bar[status_bar_position], (const CHAR *)str);
265 status_bar_position += strlen(str);
271 * read buttons status on the NXT. This function is assumed to be executed
274 void check_NXT_buttons(void)
277 static U32 last_act_time = 0;
279 /* check the buttons every 10msec */
280 st = systick_get_ms();
281 if (st >= last_act_time + 10)
284 ecrobot_poll_nxtstate();
285 if (ecrobot_get_button_state() == STOP_PRESSED)
288 ecrobot_device_terminate();
290 display_force_update();
292 nxt_lcd_power_down(); /* reset LCD hardware */
295 /* jump to the entry of application */
302 else if (ecrobot_get_button_state() == EXIT_PRESSED)
305 ecrobot_device_terminate();
307 display_force_update();
309 nxt_lcd_power_down(); /* reset LCD hardware */
311 nxt_avr_power_down(); /* send command to AVR to sleep ARM */