Ejemplo n.º 1
0
/*!
 * \brief Execute flash controller command.
 *
 */
int Avr32FlashcCmd(unsigned int cmd, uint32_t tmo)
{
    int rc = 0;

    /* Make sure that the previous command has finished. */
    while (!flashc_is_ready()) {
        if (tmo && --tmo < 1) {
            return -1;
        }
    }

    /* IRQ handlers are located in flash. Disable them. */
    NutEnterCritical();

    /* Write command. */
    outr(AVR32_FLASHC.fcmd, AVR32_FLASHC_FCMD_KEY_KEY | cmd);

    /* Wait for ready flag set. */
    while (!flashc_is_ready()) {
        if (tmo && --tmo < 1) {
            rc = -1;
            break;
        }
    }

    /* Flash command finished. Re-enable IRQ handlers. */
    NutExitCritical();

    /* Check result. */
    if (AVR32_FLASHC.fsr & (AVR32_FLASHC_FSR_LOCKE_MASK | AVR32_FLASHC_FSR_PROGE_MASK)) {
        rc = -1;
    }
    return rc;
}
Ejemplo n.º 2
0
void flashc_default_wait_until_ready(void)
{
	while (!flashc_is_ready());
}