@@ -174,161 +174,159 @@ void sam_ba_monitor_run(void)
174
174
{
175
175
ptr_data = NULL ;
176
176
command = 'z' ;
177
-
178
- // Start waiting some cmd
179
- while (1 )
177
+ while (1 ) {
178
+ sam_ba_monitor_loop ();
179
+ }
180
+ }
181
+
182
+ void sam_ba_monitor_loop (void )
183
+ {
184
+ length = ptr_monitor_if -> getdata (data , SIZEBUFMAX );
185
+ ptr = data ;
186
+ for (i = 0 ; i < length ; i ++ , ptr ++ )
180
187
{
181
- length = ptr_monitor_if -> getdata ( data , SIZEBUFMAX ) ;
182
- ptr = data ;
183
- for ( i = 0 ; i < length ; i ++ )
188
+ if ( * ptr == 0xff ) continue ;
189
+
190
+ if ( * ptr == '#' )
184
191
{
185
- if (* ptr != 0xff )
192
+ if (b_terminal_mode )
193
+ {
194
+ ptr_monitor_if -> putdata ("\n\r" , 2 );
195
+ }
196
+ if (command == 'S' )
186
197
{
187
- if (* ptr == '#' )
198
+ //Check if some data are remaining in the "data" buffer
199
+ if (length > i )
188
200
{
189
- if (b_terminal_mode )
190
- {
191
- ptr_monitor_if -> putdata ("\n\r" , 2 );
192
- }
193
- if (command == 'S' )
194
- {
195
- //Check if some data are remaining in the "data" buffer
196
- if (length > i )
197
- {
198
- //Move current indexes to next avail data (currently ptr points to "#")
199
- ptr ++ ;
200
- i ++ ;
201
- //We need to add first the remaining data of the current buffer already read from usb
202
- //read a maximum of "current_number" bytes
203
- u32tmp = min ((length - i ),current_number );
204
- memcpy (ptr_data , ptr , u32tmp );
205
- i += u32tmp ;
206
- ptr += u32tmp ;
207
- j = u32tmp ;
208
- }
209
- //update i with the data read from the buffer
210
- i -- ;
211
- ptr -- ;
212
- //Do we expect more data ?
213
- if (j < current_number )
214
- ptr_monitor_if -> getdata_xmd (ptr_data , current_number - j );
215
-
216
- __asm("nop" );
217
- }
218
- else if (command == 'R' )
219
- {
220
- ptr_monitor_if -> putdata_xmd (ptr_data , current_number );
221
- }
222
- else if (command == 'O' )
223
- {
224
- * ptr_data = (char ) current_number ;
225
- }
226
- else if (command == 'H' )
227
- {
228
- * ((uint16_t * ) ptr_data ) = (uint16_t ) current_number ;
229
- }
230
- else if (command == 'W' )
231
- {
232
- * ((int * ) ptr_data ) = current_number ;
233
- }
234
- else if (command == 'o' )
235
- {
236
- sam_ba_putdata_term (ptr_data , 1 );
237
- }
238
- else if (command == 'h' )
239
- {
240
- current_number = * ((uint16_t * ) ptr_data );
241
- sam_ba_putdata_term ((uint8_t * ) & current_number , 2 );
242
- }
243
- else if (command == 'w' )
244
- {
245
- current_number = * ((uint32_t * ) ptr_data );
246
- sam_ba_putdata_term ((uint8_t * ) & current_number , 4 );
247
- }
248
- else if (command == 'G' )
249
- {
250
- call_applet (current_number );
251
- /* Rebase the Stack Pointer */
252
- __set_MSP (sp );
253
- cpu_irq_enable ();
254
- if (b_sam_ba_interface_usart ) {
255
- ptr_monitor_if -> put_c (0x6 );
256
- }
257
- }
258
- else if (command == 'T' )
259
- {
260
- b_terminal_mode = 1 ;
261
- ptr_monitor_if -> putdata ("\n\r" , 2 );
262
- }
263
- else if (command == 'N' )
264
- {
265
- if (b_terminal_mode == 0 )
266
- {
267
- ptr_monitor_if -> putdata ("\n\r" , 2 );
268
- }
269
- b_terminal_mode = 0 ;
270
- }
271
- else if (command == 'V' )
272
- {
273
- ptr_monitor_if -> putdata ("v" , 1 );
274
- ptr_monitor_if -> putdata ((uint8_t * ) RomBOOT_Version ,
275
- strlen (RomBOOT_Version ));
276
- ptr_monitor_if -> putdata (" " , 1 );
277
- ptr = (uint8_t * ) & (__DATE__ );
278
- i = 0 ;
279
- while (* ptr ++ != '\0' )
280
- i ++ ;
281
- ptr_monitor_if -> putdata ((uint8_t * ) & (__DATE__ ), i );
282
- ptr_monitor_if -> putdata (" " , 1 );
283
- i = 0 ;
284
- ptr = (uint8_t * ) & (__TIME__ );
285
- while (* ptr ++ != '\0' )
286
- i ++ ;
287
- ptr_monitor_if -> putdata ((uint8_t * ) & (__TIME__ ), i );
288
- ptr_monitor_if -> putdata ("\n\r" , 2 );
289
- }
290
-
291
- command = 'z' ;
292
- current_number = 0 ;
293
-
294
- if (b_terminal_mode )
295
- {
296
- ptr_monitor_if -> putdata (">" , 1 );
297
- }
201
+ //Move current indexes to next avail data (currently ptr points to "#")
202
+ ptr ++ ;
203
+ i ++ ;
204
+ //We need to add first the remaining data of the current buffer already read from usb
205
+ //read a maximum of "current_number" bytes
206
+ u32tmp = min ((length - i ),current_number );
207
+ memcpy (ptr_data , ptr , u32tmp );
208
+ i += u32tmp ;
209
+ ptr += u32tmp ;
210
+ j = u32tmp ;
211
+ }
212
+ //update i with the data read from the buffer
213
+ i -- ;
214
+ ptr -- ;
215
+ //Do we expect more data ?
216
+ if (j < current_number )
217
+ ptr_monitor_if -> getdata_xmd (ptr_data , current_number - j );
218
+
219
+ __asm("nop" );
220
+ }
221
+ else if (command == 'R' )
222
+ {
223
+ ptr_monitor_if -> putdata_xmd (ptr_data , current_number );
224
+ }
225
+ else if (command == 'O' )
226
+ {
227
+ * ptr_data = (char ) current_number ;
228
+ }
229
+ else if (command == 'H' )
230
+ {
231
+ * ((uint16_t * ) ptr_data ) = (uint16_t ) current_number ;
232
+ }
233
+ else if (command == 'W' )
234
+ {
235
+ * ((int * ) ptr_data ) = current_number ;
236
+ }
237
+ else if (command == 'o' )
238
+ {
239
+ sam_ba_putdata_term (ptr_data , 1 );
240
+ }
241
+ else if (command == 'h' )
242
+ {
243
+ current_number = * ((uint16_t * ) ptr_data );
244
+ sam_ba_putdata_term ((uint8_t * ) & current_number , 2 );
245
+ }
246
+ else if (command == 'w' )
247
+ {
248
+ current_number = * ((uint32_t * ) ptr_data );
249
+ sam_ba_putdata_term ((uint8_t * ) & current_number , 4 );
250
+ }
251
+ else if (command == 'G' )
252
+ {
253
+ call_applet (current_number );
254
+ /* Rebase the Stack Pointer */
255
+ __set_MSP (sp );
256
+ cpu_irq_enable ();
257
+ if (b_sam_ba_interface_usart ) {
258
+ ptr_monitor_if -> put_c (0x6 );
298
259
}
299
- else
260
+ }
261
+ else if (command == 'T' )
262
+ {
263
+ b_terminal_mode = 1 ;
264
+ ptr_monitor_if -> putdata ("\n\r" , 2 );
265
+ }
266
+ else if (command == 'N' )
267
+ {
268
+ if (b_terminal_mode == 0 )
300
269
{
301
- if (('0' <= * ptr ) && (* ptr <= '9' ))
302
- {
303
- current_number = (current_number << 4 ) | (* ptr - '0' );
304
-
305
- }
306
- else if (('A' <= * ptr ) && (* ptr <= 'F' ))
307
- {
308
- current_number = (current_number << 4 )
309
- | (* ptr - 'A' + 0xa );
310
-
311
- }
312
- else if (('a' <= * ptr ) && (* ptr <= 'f' ))
313
- {
314
- current_number = (current_number << 4 )
315
- | (* ptr - 'a' + 0xa );
316
-
317
- }
318
- else if (* ptr == ',' )
319
- {
320
- ptr_data = (uint8_t * ) current_number ;
321
- current_number = 0 ;
322
-
323
- }
324
- else
325
- {
326
- command = * ptr ;
327
- current_number = 0 ;
328
- }
270
+ ptr_monitor_if -> putdata ("\n\r" , 2 );
329
271
}
330
- ptr ++ ;
272
+ b_terminal_mode = 0 ;
273
+ }
274
+ else if (command == 'V' )
275
+ {
276
+ ptr_monitor_if -> putdata ("v" , 1 );
277
+ ptr_monitor_if -> putdata ((uint8_t * ) RomBOOT_Version ,
278
+ strlen (RomBOOT_Version ));
279
+ ptr_monitor_if -> putdata (" " , 1 );
280
+ ptr = (uint8_t * ) & (__DATE__ );
281
+ i = 0 ;
282
+ while (* ptr ++ != '\0' )
283
+ i ++ ;
284
+ ptr_monitor_if -> putdata ((uint8_t * ) & (__DATE__ ), i );
285
+ ptr_monitor_if -> putdata (" " , 1 );
286
+ i = 0 ;
287
+ ptr = (uint8_t * ) & (__TIME__ );
288
+ while (* ptr ++ != '\0' )
289
+ i ++ ;
290
+ ptr_monitor_if -> putdata ((uint8_t * ) & (__TIME__ ), i );
291
+ ptr_monitor_if -> putdata ("\n\r" , 2 );
292
+ }
293
+
294
+ command = 'z' ;
295
+ current_number = 0 ;
296
+
297
+ if (b_terminal_mode )
298
+ {
299
+ ptr_monitor_if -> putdata (">" , 1 );
300
+ }
301
+ }
302
+ else
303
+ {
304
+ if (('0' <= * ptr ) && (* ptr <= '9' ))
305
+ {
306
+ current_number = (current_number << 4 ) | (* ptr - '0' );
307
+ }
308
+ else if (('A' <= * ptr ) && (* ptr <= 'F' ))
309
+ {
310
+ current_number = (current_number << 4 ) | (* ptr - 'A' + 0xa );
311
+ }
312
+ else if (('a' <= * ptr ) && (* ptr <= 'f' ))
313
+ {
314
+ current_number = (current_number << 4 ) | (* ptr - 'a' + 0xa );
315
+ }
316
+ else if (* ptr == ',' )
317
+ {
318
+ ptr_data = (uint8_t * ) current_number ;
319
+ current_number = 0 ;
320
+ }
321
+ else
322
+ {
323
+ command = * ptr ;
324
+ current_number = 0 ;
331
325
}
332
326
}
333
327
}
334
328
}
329
+
330
+
331
+
332
+
0 commit comments