/* * 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 ("Download FLASH content to the file\n"); printf ("Usage: udnfl [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]; u16 answerLen; u32 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], "w"); if (fe == NULL) { printf ("Cannot open %s for writting\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 ("\nReading FLASH\n"); printf ("---------------------------------------------------------------------\n"); for (i = 0; i < 0x20000; 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 usb_send (ACTION_AVR_READ_CHUNK_FLASH, 5, answer, &answerLen, answer); for (j = 0; j < CHUNK_LEN; j++) fputc (answer[j], fe); printf ("0x%08X/0x00020000\r", i); fflush (stdout); } printf ("0x%08X/0x00020000\n", i); printf ("---------------------------------------------------------------------\n"); close_device (); fclose (fe); }
Copyright © 2004 BLADOX | Turbo Programmer version 2.0
|