Sophie Dexter
/
Just4Trionic
Just4Trionic - CAN and BDM FLASH programmer for Saab cars
Diff: bdmtrionic.cpp
- Revision:
- 2:bf3a2b29259a
- Parent:
- 1:d5452e398b76
- Child:
- 4:682d96ff6d79
--- a/bdmtrionic.cpp Tue Sep 14 21:02:04 2010 +0000 +++ b/bdmtrionic.cpp Tue Dec 14 21:50:35 2010 +0000 @@ -110,8 +110,7 @@ if (curr_addr < *end_addr - 4) { pc.putc(TERM_OK); // light up the activity LED - // led_on(LED_ACT); - led3 = 1; + ACTIVITYLEDON; } curr_addr += 4; @@ -207,9 +206,9 @@ file_buffer[byte_count+2] = ((uint8_t)(long_value >> 8)); file_buffer[byte_count+3] = ((uint8_t)long_value); byte_count +=4; + // make the activity led twinkle + ACTIVITYLEDON; } -// make the activity led twinkle - led3 = 1; fwrite(file_buffer, 1, FILE_BUF_LENGTH, fp); if (ferror (fp)) { fclose (fp); @@ -350,8 +349,7 @@ curr_addr += 2; // light up the activity LED -// led_on(LED_ACT); - led3 = 1; + ACTIVITYLEDON; } // reset flash @@ -473,7 +471,7 @@ case AMD29F400T: case AMD29F010: printf("Erasing 29F400/010 type FLASH chips...\r\n"); - if (erase_am29() == TERM_ERR) { + if (!erase_am29()) { printf("WARNING: An error occured when I tried to erase the FLASH chips :-(\r\n"); return TERM_ERR; } @@ -484,7 +482,7 @@ case AMD28F512: case INTEL28F512: printf("Erasing 28F010/512 type FLASH chips...\r\n"); - if (erase_am28(&curr_addr, &flash_size) == TERM_ERR) { + if (!erase_am28(&curr_addr, &flash_size)) { printf("WARNING: An error occured when I tried to erase the FLASH chips :-(\r\n"); return TERM_ERR; } @@ -531,8 +529,7 @@ curr_addr += 2; // make the activity LED twinkle - led3 = 1; - + ACTIVITYLEDON; } timer.stop(); @@ -666,8 +663,7 @@ */ bool reset_am28(void) { uint32_t start_addr = 0x0; - return (memwrite_word(&start_addr, 0xffff) == TERM_OK && - memwrite_word(&start_addr, 0xffff) == TERM_OK); + return (memwrite_word_write_word(&start_addr, 0xffff, 0xffff) == TERM_OK); } //----------------------------------------------------------------------------- @@ -697,15 +693,14 @@ // // feedback to host computer // pc.putc(TERM_OK); // make the activity LED twinkle -// led3 = (addr & 0x400); - led3 = 1; + ACTIVITYLEDON; + } // erase flash addr = *start_addr; uint8_t verify_value; - uint16_t pulse_cnt = 0; if (memwrite_byte_cmd(NULL) != TERM_OK) { reset_am28(); @@ -727,7 +722,7 @@ // succeeded need to check next address addr++; // make the activity LED twinkle - led3 = 1; + ACTIVITYLEDON; } } // the erase process ends with a BDM_WRITE + BDM_BYTESIZE command left in the BDM @@ -768,13 +763,14 @@ while (++pulse_cnt < 25) { // set a mask - if ((uint8_t)verify_value == (uint8_t)value) mask_value &= 0xff00; - if ((uint8_t)(verify_value >> 8) == (uint8_t)(value >> 8)) mask_value &= 0x00ff; + if ((uint8_t)verify_value == (uint8_t)value) + mask_value &= 0xff00; + if ((uint8_t)(verify_value >> 8) == (uint8_t)(value >> 8)) + mask_value &= 0x00ff; // write the new value if (memwrite_word_write_word(addr, (0x4040 & mask_value), value) != TERM_OK) break; // NOTE the BDM interface is slow enough that there is no need for a 10us delay before verifying -// wait_us(10); // issue the verification command // NOTE the BDM interface is slow enough that there is no need for a 6us delay before reading back if (memwrite_word_read_word(&verify_value, addr, (0xc0c0 & mask_value)) != TERM_OK) break; @@ -871,8 +867,10 @@ if (memwrite_word(&am29_id[i].addr, am29_id[i].val) != TERM_OK) return false; } if (memread_long(&value, &addr) != TERM_OK) return false; - *make = (uint8_t)(value >> 24); - *type = (uint8_t)(value >> 8); +// *make = (uint8_t)(value >> 24); +// *type = (uint8_t)(value >> 8); + *make = (uint8_t)(value >> 16); + *type = (uint8_t)(value); printf("FLASH id bytes: %08x, make: %02x, type: %02x\r\n", value, *make, *type); switch (*type) { case AMD29F400B: