/* * Turbo Programmer Utilities, turbo-prog-utils, www.bladox.com * * Copyright (C) 2004 BLADOX, s.r.o. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. */ #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <tprog/tproglib.h> #include "../module-src/avrprog.h" void help () { printf ("Upload file to the EEPROM\n"); printf ("Usage: uupee [args] file\n"); printf ("-a application\tuse application, default is %s\n", APP_AVR_PROG); printf ("-d device\tuse USB device, default is %s\n", USBDEVICE); printf ("-h\t\thelp\n"); printf ("-v\t\tverbose\n"); exit (-1); } int main (int argc, char **argv) { int result; u8 *dev = USBDEVICE; u8 *app_name = APP_AVR_PROG; u8 answer[2048]; u8 answer_buf[2048]; u16 answerLen; u16 i, j; FILE *fe; do { result = getopt (argc, argv, "hd:a:v"); switch (result) { case 'a': app_name = optarg; break; case 'd': dev = optarg; break; case 'h': help (); break; case 'v': verbose_inc (); break; } } while (result > 0); if (argc - optind != 1) help (); fe = fopen (argv[optind], "r"); if (fe == NULL) { printf ("Cannot open %s for reading\n", argv[optind]); exit (-1); } open_device (dev); if (select_app (app_name) != NO_ERROR) { close_device (); fprintf (stderr, "Cannot open application %s\n", app_name); exit (-1); } usb_send (ACTION_AVR_PROG_INIT, 0, NULL, &answerLen, answer); printf ("AVR programming mode initialized, %s\n", app_name); #define CHUNK_LEN 32 printf ("\nWriting EEPROM\n"); printf ("---------------------------------------------------------------------\n"); for (i = 0; i < 0x1000; i += CHUNK_LEN) { answer[0] = (i & 0xFF000000) >> 24; answer[1] = (i & 0x00FF0000) >> 16; answer[2] = (i & 0x0000FF00) >> 8; answer[3] = (i & 0x000000FF); answer[4] = CHUNK_LEN; //size for (j = 0; j < CHUNK_LEN; j++) answer[5 + j] = fgetc (fe); usb_send (ACTION_AVR_WRITE_CHUNK_EEPROM, 5 + CHUNK_LEN, answer, &answerLen, answer_buf); // VERIFY for (j = 0; j < CHUNK_LEN + 5; j++) answer_buf[j] = 0; answer_buf[0] = (i & 0xFF000000) >> 24; answer_buf[1] = (i & 0x00FF0000) >> 16; answer_buf[2] = (i & 0x0000FF00) >> 8; answer_buf[3] = (i & 0x000000FF); answer_buf[4] = CHUNK_LEN; //size usb_send (ACTION_AVR_READ_CHUNK_EEPROM, 5, answer_buf, &answerLen, answer_buf); for (j = 0; j < CHUNK_LEN; j++) { printf ("%02X ", answer_buf[j]); if (answer[j + 5] != answer_buf[j]) { fprintf (stderr, "EEPROM VERIFY ERROR AT POS %04X\n", i + j); exit (-1); } } printf ("\n"); } printf ("---------------------------------------------------------------------\n"); close_device (); fclose (fe); }
Copyright © 2004 BLADOX | Turbo Programmer version 2.0
|