All pastes #18356 Raw Edit

Stuff

public c v1 · immutable
#18356 ·published 2005-07-23 22:46 UTC
rendered paste body
static int flash_erase32(flash_info_t *info, int s_first, int s_last){    int flag, sect;    ulong start, now, last;    int prot = 0;    /* Validate arguments */    if ((s_first < 0) || (s_first > s_last)) {        if (info->flash_id == FLASH_UNKNOWN)            printf ("- missing\n");        else            printf ("- no sectors to erase\n");        return 1;    }    /* Check for KNOWN flash type */    if ((info->flash_id & FLASH_VENDMASK) != FLASH_MAN_INTEL) {        printf ("Can erase only Intel flash types - aborted\n");        return 1;    }    /* Check for protected sectors */    for (sect = s_first; sect <= s_last; ++sect) {        if (info->protect[sect])            prot++;    }    if (prot)        printf ("- Warning: %d protected sectors will not be erased!\n", prot);    else        printf ("\n");    start = get_timer (0);    last  = start;    /* Start erase on unprotected sectors */    for (sect = s_first; sect <= s_last; sect++) {        WATCHDOG_RESET();        if (info->protect[sect] == 0) {      /* not protected */            vu_long *addr = (vu_long *)(info->start[sect]);            unsigned long status;            /* Disable interrupts which might cause a timeout here */            flag = disable_interrupts();            *addr = 0x00500050;              /* clear status register */            *addr = 0x00200020;              /* erase setup */            *addr = 0x00D000D0;              /* erase confirm */            /* re-enable interrupts if necessary */            if (flag)                enable_interrupts();            /* Wait at least 80us - let's wait 1 ms */            udelay (1000);            while (((status = *addr) & 0x00800080) != 0x00800080) {                if ((now = get_timer(start)) > CFG_FLASH_ERASE_TOUT) {                    printf ("Timeout\n");                    *addr = 0x00B000B0;      /* suspend erase      */                    *addr = 0x00FF00FF;      /* reset to read mode */                    return 1;                }                /* show that we're waiting */                if ((now - last) > 990) {   /* every second */                    putc ('.');                    last = now;                }            }            *addr = 0x00FF00FF;              /* reset to read mode */        }    }    printf (" done\n");    return 0;} /* end flash_erase32() */