75
75
76
76
#endif
77
77
78
- #ifdef USE_HARDWARE_SPI
79
- #warning hw spi !!!
80
- #else
81
- #warning NOT usung hw spi
82
- #endif
83
-
84
78
// Configure the serial port to use.
85
79
//
86
80
// Prefer the USB virtual serial port (aka. native USB port), if the Arduino has one:
@@ -188,7 +182,7 @@ void setup() {
188
182
int error = 0 ;
189
183
int pmode = 0 ;
190
184
// address for reading and writing, set by 'U' command
191
- int here;
185
+ unsigned int here;
192
186
uint8_t buff[256 ]; // global block storage
193
187
194
188
#define beget16 (addr ) (*addr * 256 + *(addr+1 ) )
@@ -228,8 +222,7 @@ void heartbeat() {
228
222
229
223
static bool rst_active_high;
230
224
231
- void reset_target (bool reset)
232
- {
225
+ void reset_target (bool reset) {
233
226
digitalWrite (RESET, ((reset && rst_active_high) || (!reset && !rst_active_high)) ? HIGH : LOW);
234
227
}
235
228
@@ -281,11 +274,9 @@ void prog_lamp(int state) {
281
274
}
282
275
283
276
uint8_t spi_transaction (uint8_t a, uint8_t b, uint8_t c, uint8_t d) {
284
- uint8_t n;
285
277
SPI.transfer (a);
286
- n = SPI.transfer (b);
287
- // if (n != a) error = -1;
288
- n = SPI.transfer (c);
278
+ SPI.transfer (b);
279
+ SPI.transfer (c);
289
280
return SPI.transfer (d);
290
281
}
291
282
@@ -388,21 +379,20 @@ void end_pmode() {
388
379
}
389
380
390
381
void universal () {
391
- int w;
392
382
uint8_t ch;
393
383
394
384
fill (4 );
395
385
ch = spi_transaction (buff[0 ], buff[1 ], buff[2 ], buff[3 ]);
396
386
breply (ch);
397
387
}
398
388
399
- void flash (uint8_t hilo, int addr, uint8_t data) {
389
+ void flash (uint8_t hilo, unsigned int addr, uint8_t data) {
400
390
spi_transaction (0x40 + 8 * hilo,
401
391
addr >> 8 & 0xFF ,
402
392
addr & 0xFF ,
403
393
data);
404
394
}
405
- void commit (int addr) {
395
+ void commit (unsigned int addr) {
406
396
if (PROG_FLICKER) {
407
397
prog_lamp (LOW);
408
398
}
@@ -413,8 +403,7 @@ void commit(int addr) {
413
403
}
414
404
}
415
405
416
- // #define _current_page(x) (here & 0xFFFFE0)
417
- int current_page (int addr) {
406
+ unsigned int current_page () {
418
407
if (param.pagesize == 32 ) {
419
408
return here & 0xFFFFFFF0 ;
420
409
}
@@ -444,11 +433,11 @@ void write_flash(int length) {
444
433
445
434
uint8_t write_flash_pages (int length) {
446
435
int x = 0 ;
447
- int page = current_page (here );
436
+ unsigned int page = current_page ();
448
437
while (x < length) {
449
- if (page != current_page (here )) {
438
8000
+ if (page != current_page ()) {
450
439
commit (page);
451
- page = current_page (here );
440
+ page = current_page ();
452
441
}
453
442
flash (LOW, here, buff[x++]);
454
443
flash (HIGH, here, buff[x++]);
@@ -461,10 +450,10 @@ uint8_t write_flash_pages(int length) {
461
450
}
462
451
463
452
#define EECHUNK (32 )
464
- uint8_t write_eeprom (int length) {
453
+ uint8_t write_eeprom (unsigned int length) {
465
454
// here is a word address, get the byte address
466
- int start = here * 2 ;
467
- int remaining = length;
455
+ unsigned int start = here * 2 ;
456
+ unsigned int remaining = length;
468
457
if (length > param.eepromsize ) {
469
458
error++;
470
459
return STK_FAILED;
@@ -478,13 +467,13 @@ uint8_t write_eeprom(int length) {
478
467
return STK_OK;
479
468
}
480
469
// write (length) bytes, (start) is a byte address
481
- uint8_t write_eeprom_chunk (int start, int length) {
470
+ uint8_t write_eeprom_chunk (unsigned int start, unsigned int length) {
482
471
// this writes byte-by-byte,
483
472
// page writing may be faster (4 bytes at a time)
484
473
fill (length);
485
474
prog_lamp (LOW);
486
- for (int x = 0 ; x < length; x++) {
487
- int addr = start + x;
475
+ for (unsigned int x = 0 ; x < length; x++) {
476
+ unsigned int addr = start + x;
488
477
spi_transaction (0xC0 , (addr >> 8 ) & 0xFF , addr & 0xFF , buff[x]);
489
478
delay (45 );
490
479
}
@@ -494,7 +483,7 @@ uint8_t write_eeprom_chunk(int start, int length) {
494
483
495
484
void program_page () {
496
485
char result = (char ) STK_FAILED;
497
- int length = 256 * getch ();
486
+ unsigned int length = 256 * getch ();
498
487
length += getch ();
499
488
char memtype = getch ();
500
489
// flash memory @here, (length) bytes
@@ -517,7 +506,7 @@ void program_page() {
517
506
return ;
518
507
}
519
508
520
- uint8_t flash_read (uint8_t hilo, int addr) {
509
+ uint8_t flash_read (uint8_t hilo, unsigned int addr) {
521
510
return spi_transaction (0x20 + hilo * 8 ,
522
511
(addr >> 8 ) & 0xFF ,
523
512
addr & 0xFF ,
@@ -583,8 +572,7 @@ void read_signature() {
583
572
584
573
// //////////////////////////////////
585
574
// //////////////////////////////////
586
- int avrisp () {
587
- uint8_t data, low, high;
575
+ void avrisp () {
588
576
uint8_t ch = getch ();
589
577
switch (ch) {
590
578
case ' 0' : // signon
@@ -626,12 +614,12 @@ int avrisp() {
626
614
break ;
627
615
628
616
case 0x60 : // STK_PROG_FLASH
629
- low = getch ();
630
- high = getch ();
617
+ getch (); // low addr
618
+ getch (); // high addr
631
619
empty_reply ();
632
620
break ;
633
621
case 0x61 : // STK_PROG_DATA
634
- data = getch ();
622
+ getch (); // data
635
623
empty_reply ();
636
624
break ;
637
625
0 commit comments