@@ -29,8 +29,15 @@ SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
2929#include "cdc_enumerate.h"
3030#include "device_config.h"
3131
32+
33+ #if (SAM_BA_INTERFACE == SAM_BA_UART_ONLY )
34+ #define HND (x ) uart_if.x
35+ #else
36+ #define HND (x ) ptr_monitor_if->x
37+ #endif
38+
3239static void print_new_line (void );
33- const char RomBOOT_Version [] = SAM_BA_VERSION ;
40+ const char RomBOOT_Version [sizeof ( SAM_BA_VERSION ) - 1 ] = SAM_BA_VERSION ;
3441
3542/* Provides one common interface to handle both USART and USB-CDC */
3643typedef struct
@@ -72,25 +79,26 @@ const t_monitor_if usbcdc_if =
7279t_monitor_if * ptr_monitor_if ;
7380
7481/* b_terminal_mode mode (ascii) or hex mode */
75- volatile bool b_terminal_mode = false;
82+ //volatile bool b_terminal_mode = false;
83+ static const bool b_terminal_mode = false;
7684volatile uint32_t sp ;
7785
7886
7987static void print_new_line (void )
8088{
81- ptr_monitor_if -> putdata ("\n\r" , 2 );
89+ HND ( putdata ) ("\n\r" , 2 );
8290}
8391
8492void init_sam_ba_monitor_interface (void )
8593{
8694 #if SAM_BA_UART_INTERFACE_ENABLED
8795 usart_open ();
8896 #endif
89-
97+
9098 #if SAM_BA_USB_INTERFACE_ENABLED
9199 clock_configuration_for_usb ();
92100 usb_init ();
93- #endif
101+ #endif
94102}
95103
96104void process_sam_ba_monitor (void )
@@ -102,7 +110,10 @@ void process_sam_ba_monitor(void)
102110 }
103111 #endif
104112
105- #if SAM_BA_UART_INTERFACE_ENABLED
113+ #if (SAM_BA_INTERFACE == SAM_BA_UART_ONLY )
114+ sam_ba_monitor_run ();
115+ for (;;);
116+ #elif SAM_BA_UART_INTERFACE_ENABLED
106117 if (uart_if .is_rx_ready () && (SHARP_CHARACTER == uart_if .get_c ())) {
107118 ptr_monitor_if = (t_monitor_if * ) & uart_if ;
108119 sam_ba_monitor_run ();
@@ -150,21 +161,20 @@ void sam_ba_putdata_term(uint8_t* data, uint32_t length)
150161 buf [1 ] = 'x' ;
151162 buf [length * 2 + 2 ] = '\n' ;
152163 buf [length * 2 + 3 ] = '\r' ;
153- ptr_monitor_if -> putdata (buf , length * 2 + 4 );
164+ HND ( putdata ) (buf , length * 2 + 4 );
154165 }
155166 else
156- ptr_monitor_if -> putdata (data , length );
167+ HND ( putdata ) (data , length );
157168 return ;
158169}
159170
171+ __attribute__((__noreturn__ ))
160172void call_applet (uint32_t address )
161173{
162174 uint32_t app_start_address ;
163175
164176 cpu_irq_disable ();
165177
166- sp = __get_MSP ();
167-
168178 /* Rebase the Stack Pointer */
169179 __set_MSP (* (uint32_t * ) address );
170180
@@ -175,7 +185,8 @@ void call_applet(uint32_t address)
175185 app_start_address = * (uint32_t * )(address + 4 );
176186
177187 /* Jump to application Reset Handler in the application */
178- asm("bx %0" ::"r" (app_start_address ));
188+ __asm("bx %0" ::"r" (app_start_address ));
189+ __builtin_unreachable ();
179190}
180191
181192/**
@@ -184,25 +195,24 @@ void call_applet(uint32_t address)
184195void sam_ba_monitor_run (void )
185196{
186197 uint32_t length ;
187- uint32_t j , u8tmp , current_number , command ;
198+ uint32_t j , command , current_number , u8tmp ;
188199 uint8_t * ptr_data , * ptr , data [SIZEBUFMAX ];
189200
190- ptr_data = 0 ;
191- command = 'z' ;
192201 j = 0 ;
193-
202+ command = 0 ;
203+
194204 // Start waiting some cmd
195205 while (1 )
196206 {
197- length = ptr_monitor_if -> getdata (data , SIZEBUFMAX );
207+ length = HND ( getdata ) (data , SIZEBUFMAX );
198208 ptr = data ;
199209 for (uint32_t i = 0 ; i < length ; i ++ )
200210 {
201211 if (* ptr != 0xff )
202212 {
203213 if (* ptr == '#' )
204214 {
205- if (b_terminal_mode )
215+ /* if (b_terminal_mode)
206216 {
207217 print_new_line();
208218 }
@@ -230,27 +240,31 @@ void sam_ba_monitor_run(void)
230240 ptr--;
231241 //Do we expect more data ?
232242 if(j<current_number)
233- ptr_monitor_if -> getdata_xmd (ptr_data , current_number - j );
234-
235- __asm("nop" );
243+ HND( getdata_xmd) (ptr_data, current_number-j);
244+
245+ // __asm("nop");
236246 }
247+ */
248+ /*
237249 else if (command == 'R')
238250 {
239- ptr_monitor_if -> putdata_xmd (ptr_data , current_number );
251+ HND( putdata_xmd) (ptr_data, current_number);
240252 }
241253 else if (command == 'O')
242254 {
243255 *ptr_data = (char) current_number;
244256 }
245- else if (command == 'H' )
257+ else
258+ if (command == 'H')
246259 {
247260 *((uint16_t *) ptr_data) = (uint16_t) current_number;
248261 }
249- else if (command == 'W' )
262+ else
263+ */ if (command == 'W' )
250264 {
251265 * ((int * ) ptr_data ) = current_number ;
252266 }
253- else if (command == 'o' )
267+ /* else if (command == 'o')
254268 {
255269 sam_ba_putdata_term(ptr_data, 1);
256270 }
@@ -259,47 +273,47 @@ void sam_ba_monitor_run(void)
259273 current_number = *((uint16_t *) ptr_data);
260274 sam_ba_putdata_term((uint8_t*) ¤t_number, 2);
261275 }
262- else if (command == 'w' )
276+ */ else if (command == 'w' )
263277 {
264278 current_number = * ((uint32_t * ) ptr_data );
265279 sam_ba_putdata_term ((uint8_t * ) & current_number , 4 );
266280 }
281+
267282 else if (command == 'G' )
268283 {
269284 call_applet (current_number );
270- //ptr_monitor_if->put_c(0x6);
271- /* Rebase the Stack Pointer */
272- __set_MSP (sp );
273- cpu_irq_enable ();
285+ __builtin_unreachable ();
274286 }
275- else if (command == 'T' )
287+ /* else if (command == 'T')
276288 {
277289 b_terminal_mode = 1;
278290 print_new_line();
279291 }
280292 else if (command == 'N')
281293 {
282- if (b_terminal_mode == 0 )
283- {
284- print_new_line ();
285- }
286- b_terminal_mode = 0 ;
294+ //if (b_terminal_mode == 0)
295+ //{
296+ HND(putdata)((uint8_t *) RomBOOT_Version+2, 2);
297+ // print_new_line();
298+ //}
299+ //b_terminal_mode = 0;
287300 }
288- else if (command == 'V' )
301+ */ else if (command == 'V' )
289302 {
290- ptr_monitor_if -> putdata ((uint8_t * ) RomBOOT_Version , strlen (RomBOOT_Version ));
303+ HND ( putdata ) ((uint8_t * ) RomBOOT_Version , sizeof ( RomBOOT_Version )); // strlen(RomBOOT_Version));
291304 }
292305
293- command = 'z' ;
306+ command = 0 ;
294307 current_number = 0 ;
295308
296309 if (b_terminal_mode )
297310 {
298- ptr_monitor_if -> putdata (">" , 1 );
311+ HND ( putdata ) (">" , 1 );
299312 }
300313 }
301314 else
302315 {
316+ /*
303317 if (('0' <= *ptr) && (*ptr <= '9'))
304318 {
305319 current_number = (current_number << 4) | (*ptr - '0');
@@ -322,6 +336,22 @@ void sam_ba_monitor_run(void)
322336 command = *ptr;
323337 current_number = 0;
324338 }
339+ */
340+ if (* ptr == ',' )
341+ {
342+ ptr_data = (uint8_t * ) current_number ;
343+ current_number = 0 ;
344+ }
345+ else
346+ {
347+ int val = htoi (* ptr );
348+ if (val < 0 ) {
349+ command = * ptr ;
350+ current_number = 0 ;
351+ }else {
352+ current_number = (current_number << 4 ) | val ;
353+ }
354+ }
325355 }
326356 ptr ++ ;
327357 }
0 commit comments