From 35a046e51c1147c4214d7f25139e5241a384d7ac Mon Sep 17 00:00:00 2001 From: hadaq Date: Thu, 5 Nov 2009 12:39:41 +0000 Subject: [PATCH] added adcm3 support --- trbrich/trbflash.c | 47 ++++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/trbrich/trbflash.c b/trbrich/trbflash.c index 9f0b8e0..d59fa4a 100644 --- a/trbrich/trbflash.c +++ b/trbrich/trbflash.c @@ -58,15 +58,15 @@ static const unsigned int timeout = 10000; typedef enum { FLASH_INVALID = 0, FLASH_ADCM1 = 1, - FLASH_ADCM2 = 2, + FLASH_ADCM23 = 2, FLASH_MDC = 3 } FlashType; -static const char FlashTypeStr[][16] = {"INVALID", "ADCM1", "ADCM2", "MDC"}; +static const char FlashTypeStr[][16] = {"INVALID", "ADCM1", "ADCM2&3", "MDC"}; static FlashType flashType = FLASH_INVALID; -static const char trbflash_version[] = "$Revision: 2.09 $"; +static const char trbflash_version[] = "$Revision: 2.10 $"; static uint32_t mdcFlashSelect = 1; @@ -276,7 +276,7 @@ static int checkStatus(uint16_t trb_address) ret = 0; for (i = 0; i < status; i += 2) { - if ((flashType == FLASH_ADCM1) || (flashType == FLASH_ADCM2)) { + if ((flashType == FLASH_ADCM1) || (flashType == FLASH_ADCM23)) { /* Check EPE Bit (ADCM only) */ if (((trbBuffer[i + 1] >> 5) & 0x01) == 1) { fprintf(logFile, "Error > checkStatus: Erase or program error on " @@ -365,11 +365,11 @@ static int initTransfer(uint16_t trb_address) case 0x00471f: /* ADCM */ - if ((flashType != FLASH_INVALID) && (flashType != FLASH_ADCM2)) { + if ((flashType != FLASH_INVALID) && (flashType != FLASH_ADCM23)) { success = -2; } NUM_PAGES = 16384; - flashType = FLASH_ADCM2; + flashType = FLASH_ADCM23; break; case 0x1520c2: @@ -630,7 +630,7 @@ static int programImageBuffer(uint16_t trb_address, unsigned int size, if ((mode != PMODE_VERIFY) && ((bytesWritten > 0) || (writeInfoPage == 1))) { - if ((flashType == FLASH_ADCM1) || (flashType == FLASH_ADCM2)) { + if ((flashType == FLASH_ADCM1) || (flashType == FLASH_ADCM23)) { /* Enable writing */ if (sendCommand(trb_address, 0x06 << 24, 0) == -1) { fprintf(stderr, "\nError > program: write enable, aborting\n"); @@ -701,7 +701,7 @@ static int programImageBuffer(uint16_t trb_address, unsigned int size, } } - if ((flashType == FLASH_ADCM1) || (flashType == FLASH_ADCM2)) { + if ((flashType == FLASH_ADCM1) || (flashType == FLASH_ADCM23)) { /* Enable writing */ if (sendCommand(trb_address, 0x06 << 24, 0x00) == -1) { fprintf(stderr, "\nError > program: write enable, aborting\n"); @@ -827,12 +827,13 @@ static int readImageFile(const char *imageFileName) fprintf(logFile, "Error > readImageFile: Could not open ImageFile %s: %s\n", imageFileName, strerror(errno)); + return -1; } imageSize = 0; do { imageSize += fread((void*)(imageBuffer + imageSize), sizeof(uint8_t), - PAGE_SIZE, imageFile); + PAGE_SIZE, imageFile); } while ((feof(imageFile) == 0) && (imageSize <= PAGE_SIZE * NUM_PAGES)); fclose(imageFile); @@ -849,23 +850,29 @@ static int readImageFile(const char *imageFileName) static int prepareImageBuffer() { - char strId[32] = ""; + char strId[2][32] = {"", ""}; + unsigned int numIds = 0; int found; unsigned int end; unsigned int i; + unsigned int j; /* Verify imageFile Id */ switch (flashType) { case FLASH_ADCM1: - strncpy(strId, "edif_adcmv1", 32); + strncpy(strId[0], "edif_adcmv1", 32); + numIds = 1; break; - case FLASH_ADCM2: - strncpy(strId, "edif_adcmv2", 32); + case FLASH_ADCM23: + strncpy(strId[0], "edif_adcmv2", 32); + strncpy(strId[1], "edif_adcmv3", 32); + numIds = 2; break; case FLASH_MDC: - strncpy(strId, "mdc_oepb", 32); + strncpy(strId[0], "mdc_oepb", 32); + numIds = 1; break; default: @@ -875,10 +882,13 @@ static int prepareImageBuffer() /* Verify imageFile Id */ found = 0; - for (i = 0; i < 2 * PAGE_SIZE; i++) { - if (memcmp(imageBuffer + i, strId, strlen(strId)) == 0) { - found = 1; - break; + for (j = 0; j < numIds; j++) { + for (i = 0; i < 2 * PAGE_SIZE; i++) { + if (memcmp(imageBuffer + i, strId[j], strlen(strId[j])) == 0) { + found = 1; + j = numIds; + break; + } } } @@ -1240,6 +1250,7 @@ int main(int argc, char ** argv) if (imageFile == NULL) { fprintf(stderr, "Could not open Imagefile %s: %s\n", imageFileName, strerror(errno)); + exit(EXIT_FAILURE); } for (page = 0; page < NUM_PAGES; page++) { -- 2.43.0