示例#1
0
/*
 * issue the 'program enable' command to the AVR device
 */
static int ft245r_program_enable(PROGRAMMER * pgm, AVRPART * p) {
    int retry_count = 0;
    unsigned char cmd[4];
    unsigned char res[4];
    int i,reset_ok;

    ft245r_set_bitclock(pgm);

retry:
    reset_ok = 0;
    set_reset(pgm, 0);
    usleep(5000); // 5ms
    set_reset(pgm, 1);
    usleep(5000); // 5ms
    set_reset(pgm, 0);
    usleep(5000); // 5ms

    cmd[0] = 0xAC;
    cmd[1] = 0x53;
    cmd[2] = 0;
    cmd[3] = 0;
    ft245r_cmd(pgm, cmd, res);
    if (res[2] == 0x53 ) reset_ok = 1;
    for (i=0; i<3; i++) {
        cmd[0] = 0x30;
        cmd[1] = 0;
        cmd[2] = i;
        cmd[3] = 0;
        ft245r_cmd(pgm, cmd, res);
        saved_signature[i] = res[3];
    }
    if (reset_ok && (saved_signature[0] == 0x1e)) // success
        return 0;

    if (retry_count < 5) {
        if (retry_count == 3) {
            ft245r_drain (pgm, 0);
            tail = head;
        }
        retry_count++;
        goto retry;
    }
    if ((verbose>=1) || FT245R_DEBUG) {
        fprintf(stderr,
                "%s: ft245r_program_enable: failed\n", progname);
        fflush(stderr);
    }
    return -1;
}
示例#2
0
文件: ft245r.c 项目: dreimers/avrdude
/*
 * issue the 'program enable' command to the AVR device
 */
static int ft245r_program_enable(PROGRAMMER * pgm, AVRPART * p) {
    unsigned char cmd[4] = {0,0,0,0};
    unsigned char res[4];
    int i;

    if (p->op[AVR_OP_PGM_ENABLE] == NULL) {
        avrdude_message(MSG_INFO, "%s: AVR_OP_PGM_ENABLE command not defined for %s\n",
                        progname, p->desc);
        fflush(stderr);
        return -1;
    }

    avr_set_bits(p->op[AVR_OP_PGM_ENABLE], cmd);

    for(i = 0; i < 4; i++) {
        ft245r_cmd(pgm, cmd, res);

        if (res[p->pollindex-1] == p->pollvalue) return 0;

        if (FT245R_DEBUG) {
            avrdude_message(MSG_NOTICE, "%s: Program enable command not successful. Retrying.\n",
                            progname);
            fflush(stderr);
        }
        set_pin(pgm, PIN_AVR_RESET, ON);
        usleep(20);
        set_pin(pgm, PIN_AVR_RESET, OFF);

        if (i == 3) {
            ft245r_drain(pgm, 0);
            tail = head;
        }
    }

    avrdude_message(MSG_INFO, "%s: Device is not responding to program enable. Check connection.\n",
                    progname);
    fflush(stderr);

    return -1;
}