Move device table to own file

This commit is contained in:
Olaf Rempel 2019-12-30 20:26:58 +01:00
parent 121d52abe6
commit 6a75a0aec3
3 changed files with 245 additions and 170 deletions

183
avrdevice.c Normal file
View File

@ -0,0 +1,183 @@
/***************************************************************************
* Copyright (C) 2006 - 2020 by Olaf Rempel *
* razzor AT kopf MINUS tisch DOT de *
* *
* 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; version 2 of the License, *
* *
* 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. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <avr/pgmspace.h>
#include <string.h>
#include "avrdevice.h"
/* *********************************************************************** */
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*x))
/* *********************************************************************** */
static const avr_device_t devices[] PROGMEM = {
{ "at90s1200", { 0x1E, 0x90, 0x01 }, 0x13, 0x00, POLL_00 | POLL_FF },
{ "tiny12", { 0x1E, 0x90, 0x05 }, 0x55, 0x00, POLL_UNTESTED },
{ "tiny15", { 0x1E, 0x90, 0x06 }, 0x56, 0x00, POLL_UNTESTED },
{ "tiny13", { 0x1E, 0x90, 0x07 }, 0xFF, 0x00, POLL_UNTESTED },
{ "at90s2313", { 0x1E, 0x91, 0x01 }, 0x20, 0x00, POLL_7F | POLL_80 | POLL_FF },
{ "at90s2323", { 0x1E, 0x91, 0x02 }, 0x48, 0x00, POLL_UNTESTED },
{ "at90s2343", { 0x1E, 0x91, 0x03 }, 0x4C, 0x00, POLL_UNTESTED },
{ "at90s2333", { 0x1E, 0x91, 0x05 }, 0x34, 0x00, POLL_UNTESTED },
{ "tiny25", { 0x1E, 0x91, 0x08 }, 0x20, 0x0F, POLL_FF }, /* at90s2313 devcode */
{ "tiny26", { 0x1E, 0x91, 0x09 }, 0x5E, 0x0F, POLL_FF },
{ "tiny2313", { 0x1E, 0x91, 0x0A }, 0x5E, 0x0F, POLL_FF }, /* tiny26 devcode */
{ "tiny24", { 0x1E, 0x91, 0x0B }, 0x20, 0x0F, POLL_FF }, /* at90s2313 devcode */
{ "tiny261a", { 0x1E, 0x91, 0x0C }, 0xFF, 0x0F, POLL_FF | POLL_UNTESTED },
{ "at90s4414", { 0x1E, 0x92, 0x01 }, 0x28, 0x00, POLL_UNTESTED },
{ "at90s4434", { 0x1E, 0x92, 0x02 }, 0x6C, 0x00, POLL_UNTESTED },
{ "at90s4433", { 0x1E, 0x92, 0x03 }, 0x30, 0x00, POLL_UNTESTED },
{ "mega48", { 0x1E, 0x92, 0x05 }, 0xFF, 0x1F, POLL_FF | POLL_UNTESTED},
{ "tiny45", { 0x1E, 0x92, 0x06 }, 0x20, 0x1F, POLL_FF }, /* at90s2313 devcode */
{ "tiny44", { 0x1E, 0x92, 0x07 }, 0x20, 0x1F, POLL_FF }, /* at90s2313 devcode */
{ "mega461a", { 0x1E, 0x92, 0x08 }, 0xFF, 0x1F, POLL_FF | POLL_UNTESTED },
{ "mega48pa", { 0x1E, 0x92, 0x0A }, 0xFF, 0x1F, POLL_FF | POLL_UNTESTED },
{ "tiny4313", { 0x1E, 0x92, 0x0D }, 0x5E, 0x1F, POLL_FF | POLL_UNTESTED }, /* tiny26 devcode */
{ "at90s8515", { 0x1E, 0x93, 0x01 }, 0x38, 0x00, POLL_7F | POLL_80 | POLL_FF },
{ "at90s8535", { 0x1E, 0x93, 0x03 }, 0x68, 0x00, POLL_UNTESTED },
{ "mega83", { 0x1E, 0x93, 0x05 }, 0x65, 0x00, POLL_UNTESTED },
{ "mega8515", { 0x1E, 0x93, 0x06 }, 0x3A, 0x1F, POLL_FF | POLL_UNTESTED },
{ "mega8", { 0x1E, 0x93, 0x07 }, 0x76, 0x1F, POLL_FF },
{ "mega8535", { 0x1E, 0x93, 0x08 }, 0x69, 0x1F, POLL_FF | POLL_UNTESTED },
{ "mega88", { 0x1E, 0x93, 0x0A }, 0xFF, 0x1F, POLL_FF },
{ "tiny85", { 0x1E, 0x93, 0x0B }, 0x20, 0x1F, POLL_FF }, /* at90s2313 devcode */
{ "tiny84", { 0x1E, 0x93, 0x0C }, 0x20, 0x1F, POLL_FF }, /* at90s2313 devcode */
{ "tiny861a", { 0x1E, 0x93, 0x0D }, 0xFF, 0x1F, POLL_FF | POLL_UNTESTED },
{ "mega88pa", { 0x1E, 0x93, 0x0F }, 0xFF, 0x1F, POLL_FF | POLL_UNTESTED },
{ "tiny88", { 0x1E, 0x93, 0x11 }, 0xFF, 0x1F, POLL_FF | POLL_UNTESTED },
{ "at90pwm3", { 0x1E, 0x93, 0x81 }, 0xFF, 0x1F, POLL_FF | POLL_UNTESTED }, /* same: at90pwm2 */
{ "at90usb82", { 0x1E, 0x93, 0x82 }, 0xFF, 0x1F, POLL_FF | POLL_UNTESTED },
{ "at90pwm3b", { 0x1E, 0x93, 0x83 }, 0xFF, 0x1F, POLL_FF | POLL_UNTESTED }, /* same: at90pwm2b */
{ "mega8u2", { 0x1E, 0x93, 0x89 }, 0xFF, 0x1F, POLL_FF | POLL_UNTESTED },
{ "mega161", { 0x1E, 0x94, 0x01 }, 0x60, 0x00, POLL_UNTESTED },
{ "mega163", { 0x1E, 0x94, 0x02 }, 0x64, 0x00, POLL_UNTESTED },
{ "mega16", { 0x1E, 0x94, 0x03 }, 0x74, 0x3F, POLL_FF },
{ "mega162", { 0x1E, 0x94, 0x04 }, 0x63, 0x3F, POLL_FF | POLL_UNTESTED },
{ "mega169", { 0x1E, 0x94, 0x05 }, 0x78, 0x3F, POLL_FF | POLL_UNTESTED },
{ "mega168", { 0x1E, 0x94, 0x06 }, 0xFF, 0x3F, POLL_FF },
{ "mega164pa", { 0x1E, 0x94, 0x0A }, 0x74, 0x3F, POLL_FF | POLL_UNTESTED }, /* mega16 devcode */
{ "mega168pa", { 0x1E, 0x94, 0x0B }, 0xFF, 0x3F, POLL_FF | POLL_UNTESTED },
{ "mega164a", { 0x1E, 0x94, 0x0F }, 0xFF, 0x3F, POLL_FF | POLL_UNTESTED },
{ "at90usb162", { 0x1E, 0x94, 0x82 }, 0xFF, 0x3F, POLL_FF | POLL_UNTESTED },
{ "mega16u4", { 0x1E, 0x94, 0x88 }, 0xFF, 0x3F, POLL_FF | POLL_UNTESTED },
{ "mega16u2", { 0x1E, 0x94, 0x89 }, 0xFF, 0x3F, POLL_FF | POLL_UNTESTED },
{ "mega32", { 0x1E, 0x95, 0x02 }, 0x72, 0x3F, POLL_FF },
{ "mega329", { 0x1E, 0x95, 0x03 }, 0x75, 0x3F, POLL_FF | POLL_UNTESTED }, /* mega169 devcode */
{ "mega3290", { 0x1E, 0x95, 0x04 }, 0x75, 0x3F, POLL_FF | POLL_UNTESTED }, /* mega169 devcode */
{ "mega325", { 0x1E, 0x95, 0x05 }, 0x74, 0x3F, POLL_FF | POLL_UNTESTED }, /* mega16 devcode */
{ "mega3250", { 0x1E, 0x95, 0x06 }, 0x74, 0x3F, POLL_FF | POLL_UNTESTED }, /* mega16 devcode */
{ "mega324p", { 0x1E, 0x95, 0x08 }, 0x74, 0x3F, POLL_FF | POLL_UNTESTED }, /* mega16 devcode */
{ "mega329p", { 0x1E, 0x95, 0x0B }, 0x75, 0x3F, POLL_FF | POLL_UNTESTED }, /* mega169 devcode */
{ "mega3290p", { 0x1E, 0x95, 0x0C }, 0x75, 0x3F, POLL_FF | POLL_UNTESTED }, /* mega169 devcode */
{ "mega328p", { 0x1E, 0x95, 0x0F }, 0xFF, 0x3F, POLL_FF },
{ "mega324pa", { 0x1E, 0x95, 0x11 }, 0x74, 0x3F, POLL_FF | POLL_UNTESTED }, /* mega16 devcode */
{ "mega324a", { 0x1E, 0x95, 0x15 }, 0xFF, 0x3F, POLL_FF | POLL_UNTESTED },
{ "at90can32", { 0x1E, 0x95, 0x81 }, 0xFF, 0x3F, POLL_FF | POLL_UNTESTED },
{ "mega32u4", { 0x1E, 0x95, 0x87 }, 0xFF, 0x3F, POLL_FF },
{ "mega32u2", { 0x1E, 0x95, 0x8A }, 0xFF, 0x3F, POLL_FF },
{ "mega64", { 0x1E, 0x96, 0x02 }, 0x45, 0x7F, POLL_FF },
{ "mega649", { 0x1E, 0x96, 0x03 }, 0x75, 0x7F, POLL_FF | POLL_UNTESTED }, /* mega169 devcode */
{ "mega6490", { 0x1E, 0x96, 0x04 }, 0x75, 0x7F, POLL_FF | POLL_UNTESTED }, /* mega169 devcode */
{ "mega645", { 0x1E, 0x96, 0x05 }, 0x74, 0x7F, POLL_FF | POLL_UNTESTED }, /* mega16 devcode */
{ "mega6450", { 0x1E, 0x96, 0x06 }, 0x74, 0x7F, POLL_FF | POLL_UNTESTED }, /* mega16 devcode */
{ "mega640", { 0x1E, 0x96, 0x08 }, 0xFF, 0x7F, POLL_FF | POLL_UNTESTED },
{ "mega644a", { 0x1E, 0x96, 0x09 }, 0x74, 0x7F, POLL_FF }, /* mega16 devcode */
{ "mega644p", { 0x1E, 0x96, 0x0A }, 0x74, 0x7F, POLL_FF }, /* mega16 devcode */
{ "at90can64", { 0x1E, 0x96, 0x81 }, 0xFF, 0x7F, POLL_FF | POLL_UNTESTED },
{ "at90usb646", { 0x1E, 0x96, 0x82 }, 0xFF, 0x7F, POLL_FF | POLL_UNTESTED }, /* same: at90usb647 */
{ "mega103", { 0x1E, 0x97, 0x01 }, 0x41, 0x7F, POLL_7F | POLL_80 | POLL_FF },
{ "mega128", { 0x1E, 0x97, 0x02 }, 0x43, 0x7F, POLL_FF },
{ "mega1280", { 0x1E, 0x97, 0x03 }, 0xFF, 0x7F, POLL_FF | POLL_UNTESTED },
{ "mega1281", { 0x1E, 0x97, 0x04 }, 0xFF, 0x7F, POLL_FF | POLL_UNTESTED },
{ "mega1284p", { 0x1E, 0x97, 0x05 }, 0x74, 0x7F, POLL_FF | POLL_UNTESTED }, /* mega16 devcode) */
{ "mega1284", { 0x1E, 0x97, 0x06 }, 0xFF, 0x7F, POLL_FF | POLL_UNTESTED },
{ "at90can128", { 0x1E, 0x97, 0x81 }, 0xFF, 0x7F, POLL_FF | POLL_UNTESTED },
{ "at90usb1286",{ 0x1E, 0x97, 0x82 }, 0xFF, 0x7F, POLL_FF | POLL_UNTESTED }, /* same: at90usb1287 */
{ "mega2560", { 0x1E, 0x98, 0x01 }, 0xFF, 0x00, POLL_UNTESTED },
{ "mega2561", { 0x1E, 0x98, 0x02 }, 0xFF, 0x00, POLL_UNTESTED },
{ "mega128rfa1",{ 0x1E, 0xA7, 0x01 }, 0xFF, 0x00, POLL_UNTESTED },
};
/* ***********************************************************************
* avrdevice_iterate_devcodes
* *********************************************************************** */
void avrdevice_iterate_devcodes(avrdevice_callback_t callback)
{
uint8_t limit = 0x00;
while (1)
{
uint8_t i;
uint8_t search = 0xFF;
for (i = 0; i < ARRAY_SIZE(devices); i++)
{
uint8_t devcode = pgm_read_byte(&devices[i].devcode);
if ((devcode > limit) && (devcode < search))
{
search = devcode;
}
}
if (search == 0xFF)
{
break;
}
callback(search);
limit = search;
}
} /* avrdevice_iterate_devcodes */
/* ***********************************************************************
* avrdevice_get_by_signature
* *********************************************************************** */
void avrdevice_get_by_signature(avr_device_t * p_device,
const uint8_t * p_signature)
{
uint8_t i;
for (i = 0; i < ARRAY_SIZE(devices); i++)
{
if (memcmp_P(p_signature, devices[i].sig, sizeof(p_device->sig)) == 0)
{
memcpy_P(p_device, &devices[i], sizeof(avr_device_t));
break;
}
}
/* unknown devices are untested */
if (p_device->name[0] == '\0')
{
p_device->flags |= POLL_UNTESTED;
}
} /* avrdevice_get_by_signature */

34
avrdevice.h Normal file
View File

@ -0,0 +1,34 @@
#ifndef AVRDEVICE_H_
#define AVRDEVICE_H_
#include <stdint.h>
/* *********************************************************************** */
#define POLL_00 0x01 /* value 0x00 can not be polled from flash/eeprom */
#define POLL_7F 0x02 /* value 0x7F can not be polled from flash/eeprom */
#define POLL_80 0x04 /* value 0x80 can not be polled from flash/eeprom */
#define POLL_FF 0x08 /* value 0xFF can not be polled from flash/eeprom */
#define POLL_UNTESTED 0x80 /* device not tested */
typedef struct avr_device_s
{
char name[12];
uint8_t sig[3]; /* device signature */
uint8_t devcode; /* avr910 device code */
uint16_t pagemask; /* pagemask (pagesize in words!) */
uint16_t flags; /* quirks for this device */
} avr_device_t;
typedef void (* avrdevice_callback_t)(uint8_t value);
/* *********************************************************************** */
void avrdevice_iterate_devcodes (avrdevice_callback_t callback);
void avrdevice_get_by_signature (avr_device_t * p_device,
const uint8_t * p_signature);
/* *********************************************************************** */
#endif /* AVRDEVICE_H_ */

198
ispprog.c
View File

@ -19,15 +19,12 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#include <avr/io.h> #include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h> #include <avr/interrupt.h>
#include <string.h> #include <string.h>
#include "avrdevice.h"
#include "target.h" #include "target.h"
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*x))
#include <util/delay.h> #include <util/delay.h>
#define UART_CALC_BAUDRATE(baudRate) (((uint32_t)F_CPU) / (((uint32_t)baudRate)*16) -1) #define UART_CALC_BAUDRATE(baudRate) (((uint32_t)F_CPU) / (((uint32_t)baudRate)*16) -1)
@ -46,119 +43,6 @@ static const uint8_t spi_modes[4] = { SPI_MODE1, SPI_MODE2, SPI_MODE3, SPI_MODE4
static uint8_t spi_speed = SPI_SPEED_PROBE; static uint8_t spi_speed = SPI_SPEED_PROBE;
#define POLL_00 0x01 /* value 0x00 can not be polled from flash/eeprom */
#define POLL_7F 0x02 /* value 0x7F can not be polled from flash/eeprom */
#define POLL_80 0x04 /* value 0x80 can not be polled from flash/eeprom */
#define POLL_FF 0x08 /* value 0xFF can not be polled from flash/eeprom */
#define POLL_UNTESTED 0x80 /* device not tested */
struct _device {
char name[12];
uint8_t sig[3]; /* device signature */
uint8_t devcode; /* avr910 device code */
uint16_t pagemask; /* pagemask (pagesize in words!) */
uint16_t flags; /* quirks for this device */
};
static struct _device device;
static const struct _device devices[] PROGMEM = {
{ "at90s1200", { 0x1E, 0x90, 0x01 }, 0x13, 0x00, POLL_00 | POLL_FF },
{ "tiny12", { 0x1E, 0x90, 0x05 }, 0x55, 0x00, POLL_UNTESTED },
{ "tiny15", { 0x1E, 0x90, 0x06 }, 0x56, 0x00, POLL_UNTESTED },
{ "tiny13", { 0x1E, 0x90, 0x07 }, 0xFF, 0x00, POLL_UNTESTED },
{ "at90s2313", { 0x1E, 0x91, 0x01 }, 0x20, 0x00, POLL_7F | POLL_80 | POLL_FF },
{ "at90s2323", { 0x1E, 0x91, 0x02 }, 0x48, 0x00, POLL_UNTESTED },
{ "at90s2343", { 0x1E, 0x91, 0x03 }, 0x4C, 0x00, POLL_UNTESTED },
{ "at90s2333", { 0x1E, 0x91, 0x05 }, 0x34, 0x00, POLL_UNTESTED },
{ "tiny25", { 0x1E, 0x91, 0x08 }, 0x20, 0x0F, POLL_FF }, /* at90s2313 devcode */
{ "tiny26", { 0x1E, 0x91, 0x09 }, 0x5E, 0x0F, POLL_FF },
{ "tiny2313", { 0x1E, 0x91, 0x0A }, 0x5E, 0x0F, POLL_FF }, /* tiny26 devcode */
{ "tiny24", { 0x1E, 0x91, 0x0B }, 0x20, 0x0F, POLL_FF }, /* at90s2313 devcode */
{ "tiny261a", { 0x1E, 0x91, 0x0C }, 0xFF, 0x0F, POLL_FF | POLL_UNTESTED },
{ "at90s4414", { 0x1E, 0x92, 0x01 }, 0x28, 0x00, POLL_UNTESTED },
{ "at90s4434", { 0x1E, 0x92, 0x02 }, 0x6C, 0x00, POLL_UNTESTED },
{ "at90s4433", { 0x1E, 0x92, 0x03 }, 0x30, 0x00, POLL_UNTESTED },
{ "mega48", { 0x1E, 0x92, 0x05 }, 0xFF, 0x1F, POLL_FF | POLL_UNTESTED},
{ "tiny45", { 0x1E, 0x92, 0x06 }, 0x20, 0x1F, POLL_FF }, /* at90s2313 devcode */
{ "tiny44", { 0x1E, 0x92, 0x07 }, 0x20, 0x1F, POLL_FF }, /* at90s2313 devcode */
{ "mega461a", { 0x1E, 0x92, 0x08 }, 0xFF, 0x1F, POLL_FF | POLL_UNTESTED },
{ "mega48pa", { 0x1E, 0x92, 0x0A }, 0xFF, 0x1F, POLL_FF | POLL_UNTESTED },
{ "tiny4313", { 0x1E, 0x92, 0x0D }, 0x5E, 0x1F, POLL_FF | POLL_UNTESTED }, /* tiny26 devcode */
{ "at90s8515", { 0x1E, 0x93, 0x01 }, 0x38, 0x00, POLL_7F | POLL_80 | POLL_FF },
{ "at90s8535", { 0x1E, 0x93, 0x03 }, 0x68, 0x00, POLL_UNTESTED },
{ "mega83", { 0x1E, 0x93, 0x05 }, 0x65, 0x00, POLL_UNTESTED },
{ "mega8515", { 0x1E, 0x93, 0x06 }, 0x3A, 0x1F, POLL_FF | POLL_UNTESTED },
{ "mega8", { 0x1E, 0x93, 0x07 }, 0x76, 0x1F, POLL_FF },
{ "mega8535", { 0x1E, 0x93, 0x08 }, 0x69, 0x1F, POLL_FF | POLL_UNTESTED },
{ "mega88", { 0x1E, 0x93, 0x0A }, 0xFF, 0x1F, POLL_FF },
{ "tiny85", { 0x1E, 0x93, 0x0B }, 0x20, 0x1F, POLL_FF }, /* at90s2313 devcode */
{ "tiny84", { 0x1E, 0x93, 0x0C }, 0x20, 0x1F, POLL_FF }, /* at90s2313 devcode */
{ "tiny861a", { 0x1E, 0x93, 0x0D }, 0xFF, 0x1F, POLL_FF | POLL_UNTESTED },
{ "mega88pa", { 0x1E, 0x93, 0x0F }, 0xFF, 0x1F, POLL_FF | POLL_UNTESTED },
{ "tiny88", { 0x1E, 0x93, 0x11 }, 0xFF, 0x1F, POLL_FF | POLL_UNTESTED },
{ "at90pwm3", { 0x1E, 0x93, 0x81 }, 0xFF, 0x1F, POLL_FF | POLL_UNTESTED }, /* same: at90pwm2 */
{ "at90usb82", { 0x1E, 0x93, 0x82 }, 0xFF, 0x1F, POLL_FF | POLL_UNTESTED },
{ "at90pwm3b", { 0x1E, 0x93, 0x83 }, 0xFF, 0x1F, POLL_FF | POLL_UNTESTED }, /* same: at90pwm2b */
{ "mega8u2", { 0x1E, 0x93, 0x89 }, 0xFF, 0x1F, POLL_FF | POLL_UNTESTED },
{ "mega161", { 0x1E, 0x94, 0x01 }, 0x60, 0x00, POLL_UNTESTED },
{ "mega163", { 0x1E, 0x94, 0x02 }, 0x64, 0x00, POLL_UNTESTED },
{ "mega16", { 0x1E, 0x94, 0x03 }, 0x74, 0x3F, POLL_FF },
{ "mega162", { 0x1E, 0x94, 0x04 }, 0x63, 0x3F, POLL_FF | POLL_UNTESTED },
{ "mega169", { 0x1E, 0x94, 0x05 }, 0x78, 0x3F, POLL_FF | POLL_UNTESTED },
{ "mega168", { 0x1E, 0x94, 0x06 }, 0xFF, 0x3F, POLL_FF },
{ "mega164pa", { 0x1E, 0x94, 0x0A }, 0x74, 0x3F, POLL_FF | POLL_UNTESTED }, /* mega16 devcode */
{ "mega168pa", { 0x1E, 0x94, 0x0B }, 0xFF, 0x3F, POLL_FF | POLL_UNTESTED },
{ "mega164a", { 0x1E, 0x94, 0x0F }, 0xFF, 0x3F, POLL_FF | POLL_UNTESTED },
{ "at90usb162", { 0x1E, 0x94, 0x82 }, 0xFF, 0x3F, POLL_FF | POLL_UNTESTED },
{ "mega16u4", { 0x1E, 0x94, 0x88 }, 0xFF, 0x3F, POLL_FF | POLL_UNTESTED },
{ "mega16u2", { 0x1E, 0x94, 0x89 }, 0xFF, 0x3F, POLL_FF | POLL_UNTESTED },
{ "mega32", { 0x1E, 0x95, 0x02 }, 0x72, 0x3F, POLL_FF },
{ "mega329", { 0x1E, 0x95, 0x03 }, 0x75, 0x3F, POLL_FF | POLL_UNTESTED }, /* mega169 devcode */
{ "mega3290", { 0x1E, 0x95, 0x04 }, 0x75, 0x3F, POLL_FF | POLL_UNTESTED }, /* mega169 devcode */
{ "mega325", { 0x1E, 0x95, 0x05 }, 0x74, 0x3F, POLL_FF | POLL_UNTESTED }, /* mega16 devcode */
{ "mega3250", { 0x1E, 0x95, 0x06 }, 0x74, 0x3F, POLL_FF | POLL_UNTESTED }, /* mega16 devcode */
{ "mega324p", { 0x1E, 0x95, 0x08 }, 0x74, 0x3F, POLL_FF | POLL_UNTESTED }, /* mega16 devcode */
{ "mega329p", { 0x1E, 0x95, 0x0B }, 0x75, 0x3F, POLL_FF | POLL_UNTESTED }, /* mega169 devcode */
{ "mega3290p", { 0x1E, 0x95, 0x0C }, 0x75, 0x3F, POLL_FF | POLL_UNTESTED }, /* mega169 devcode */
{ "mega328p", { 0x1E, 0x95, 0x0F }, 0xFF, 0x3F, POLL_FF },
{ "mega324pa", { 0x1E, 0x95, 0x11 }, 0x74, 0x3F, POLL_FF | POLL_UNTESTED }, /* mega16 devcode */
{ "mega324a", { 0x1E, 0x95, 0x15 }, 0xFF, 0x3F, POLL_FF | POLL_UNTESTED },
{ "at90can32", { 0x1E, 0x95, 0x81 }, 0xFF, 0x3F, POLL_FF | POLL_UNTESTED },
{ "mega32u4", { 0x1E, 0x95, 0x87 }, 0xFF, 0x3F, POLL_FF },
{ "mega32u2", { 0x1E, 0x95, 0x8A }, 0xFF, 0x3F, POLL_FF },
{ "mega64", { 0x1E, 0x96, 0x02 }, 0x45, 0x7F, POLL_FF },
{ "mega649", { 0x1E, 0x96, 0x03 }, 0x75, 0x7F, POLL_FF | POLL_UNTESTED }, /* mega169 devcode */
{ "mega6490", { 0x1E, 0x96, 0x04 }, 0x75, 0x7F, POLL_FF | POLL_UNTESTED }, /* mega169 devcode */
{ "mega645", { 0x1E, 0x96, 0x05 }, 0x74, 0x7F, POLL_FF | POLL_UNTESTED }, /* mega16 devcode */
{ "mega6450", { 0x1E, 0x96, 0x06 }, 0x74, 0x7F, POLL_FF | POLL_UNTESTED }, /* mega16 devcode */
{ "mega640", { 0x1E, 0x96, 0x08 }, 0xFF, 0x7F, POLL_FF | POLL_UNTESTED },
{ "mega644a", { 0x1E, 0x96, 0x09 }, 0x74, 0x7F, POLL_FF }, /* mega16 devcode */
{ "mega644p", { 0x1E, 0x96, 0x0A }, 0x74, 0x7F, POLL_FF }, /* mega16 devcode */
{ "at90can64", { 0x1E, 0x96, 0x81 }, 0xFF, 0x7F, POLL_FF | POLL_UNTESTED },
{ "at90usb646", { 0x1E, 0x96, 0x82 }, 0xFF, 0x7F, POLL_FF | POLL_UNTESTED }, /* same: at90usb647 */
{ "mega103", { 0x1E, 0x97, 0x01 }, 0x41, 0x7F, POLL_7F | POLL_80 | POLL_FF },
{ "mega128", { 0x1E, 0x97, 0x02 }, 0x43, 0x7F, POLL_FF },
{ "mega1280", { 0x1E, 0x97, 0x03 }, 0xFF, 0x7F, POLL_FF | POLL_UNTESTED },
{ "mega1281", { 0x1E, 0x97, 0x04 }, 0xFF, 0x7F, POLL_FF | POLL_UNTESTED },
{ "mega1284p", { 0x1E, 0x97, 0x05 }, 0x74, 0x7F, POLL_FF | POLL_UNTESTED }, /* mega16 devcode) */
{ "mega1284", { 0x1E, 0x97, 0x06 }, 0xFF, 0x7F, POLL_FF | POLL_UNTESTED },
{ "at90can128", { 0x1E, 0x97, 0x81 }, 0xFF, 0x7F, POLL_FF | POLL_UNTESTED },
{ "at90usb1286",{ 0x1E, 0x97, 0x82 }, 0xFF, 0x7F, POLL_FF | POLL_UNTESTED }, /* same: at90usb1287 */
{ "mega2560", { 0x1E, 0x98, 0x01 }, 0xFF, 0x00, POLL_UNTESTED },
{ "mega2561", { 0x1E, 0x98, 0x02 }, 0xFF, 0x00, POLL_UNTESTED },
{ "mega128rfa1",{ 0x1E, 0xA7, 0x01 }, 0xFF, 0x00, POLL_UNTESTED },
};
#define EV_NONE 0x00 #define EV_NONE 0x00
#define EV_STATE_ENTER 0x01 #define EV_STATE_ENTER 0x01
#define EV_BUTTON_PRESSED 0x02 #define EV_BUTTON_PRESSED 0x02
@ -225,6 +109,8 @@ static const struct _device devices[] PROGMEM = {
static volatile uint8_t led_mode = LED_OFF; static volatile uint8_t led_mode = LED_OFF;
static avr_device_t m_device;
static uint8_t last_cmd; static uint8_t last_cmd;
static uint8_t last_val; static uint8_t last_val;
static uint16_t last_addr; static uint16_t last_addr;
@ -339,10 +225,10 @@ static void poll(void)
{ {
uint8_t cmd, val, poll = 0xFF; uint8_t cmd, val, poll = 0xFF;
if (((last_val == 0x00) && (device.flags & POLL_00)) || if (((last_val == 0x00) && (m_device.flags & POLL_00)) ||
((last_val == 0x7F) && (device.flags & POLL_7F)) || ((last_val == 0x7F) && (m_device.flags & POLL_7F)) ||
((last_val == 0x80) && (device.flags & POLL_80)) || ((last_val == 0x80) && (m_device.flags & POLL_80)) ||
((last_val == 0xFF) && (device.flags & POLL_FF)) ((last_val == 0xFF) && (m_device.flags & POLL_FF))
) { ) {
/* wait default time */ /* wait default time */
_delay_ms(15); _delay_ms(15);
@ -400,7 +286,7 @@ static void cmdloop(void)
break; break;
} else if (reset_state == STATE_RESET_PROGMODE) { } else if (reset_state == STATE_RESET_PROGMODE) {
if (device.flags & POLL_UNTESTED) { if (m_device.flags & POLL_UNTESTED) {
reset_statemachine(EV_PROG_LEAVE); reset_statemachine(EV_PROG_LEAVE);
/* untested device */ /* untested device */
ser_send('!'); ser_send('!');
@ -432,7 +318,7 @@ static void cmdloop(void)
mem_write(CMD_LOAD_FLASH_LO, addr, ser_recv()); mem_write(CMD_LOAD_FLASH_LO, addr, ser_recv());
/* poll on byte addressed targets */ /* poll on byte addressed targets */
if (device.pagemask == 0x00) { if (m_device.pagemask == 0x00) {
poll(); poll();
} }
@ -445,7 +331,7 @@ static void cmdloop(void)
mem_write(CMD_LOAD_FLASH_HI, addr, ser_recv()); mem_write(CMD_LOAD_FLASH_HI, addr, ser_recv());
/* poll on byte addressed targets */ /* poll on byte addressed targets */
if (device.pagemask == 0x00) { if (m_device.pagemask == 0x00) {
poll(); poll();
} }
@ -550,33 +436,16 @@ static void cmdloop(void)
case 's': { case 's': {
uint8_t i = 2; uint8_t i = 2;
do { do {
ser_send(device.sig[i]); ser_send(m_device.sig[i]);
} while (i--); } while (i--);
break; break;
} }
/* Return supported device codes */ /* Return supported device codes */
case 't': { case 't':
uint8_t limit = 0x00; avrdevice_iterate_devcodes(ser_send);
while (1) {
uint8_t i;
uint8_t search = 0xFF;
for (i = 0; i < ARRAY_SIZE(devices); i++) {
uint8_t devcode = pgm_read_byte(&devices[i].devcode);
if ((devcode > limit) && (devcode < search)) {
search = devcode;
}
}
if (search == 0xFF)
break;
ser_send(search);
limit = search;
}
ser_send(0x00); ser_send(0x00);
break; break;
}
/* Return software identifier */ /* Return software identifier */
case 'S': case 'S':
@ -647,13 +516,13 @@ static void cmdloop(void)
addr++; addr++;
if ((addr & device.pagemask) == 0x00) { if ((addr & m_device.pagemask) == 0x00) {
mem_pagewrite(last_addr); mem_pagewrite(last_addr);
} }
} }
if ((device.pagemask != 0x00) && if ((m_device.pagemask != 0x00) &&
(size != ((device.pagemask +1) << 1)) (size != ((m_device.pagemask +1) << 1))
) { ) {
mem_pagewrite(last_addr); mem_pagewrite(last_addr);
} }
@ -792,9 +661,9 @@ static void reset_statemachine(uint8_t event)
char *dst = disp_text; char *dst = disp_text;
const char *src; const char *src;
if (device.name[0] != '\0') if (m_device.name[0] != '\0')
{ {
src = device.name; src = m_device.name;
while (*src != '\0') while (*src != '\0')
{ {
*dst++ = *src++; *dst++ = *src++;
@ -805,15 +674,15 @@ static void reset_statemachine(uint8_t event)
*dst++ = ' '; *dst++ = ' ';
*dst++ = '0'; *dst++ = '0';
*dst++ = 'X'; *dst++ = 'X';
*dst++ = _hexnibble(device.sig[0] >> 4); *dst++ = _hexnibble(m_device.sig[0] >> 4);
*dst++ = _hexnibble(device.sig[0]); *dst++ = _hexnibble(m_device.sig[0]);
*dst++ = _hexnibble(device.sig[1] >> 4); *dst++ = _hexnibble(m_device.sig[1] >> 4);
*dst++ = _hexnibble(device.sig[1]); *dst++ = _hexnibble(m_device.sig[1]);
*dst++ = _hexnibble(device.sig[2] >> 4); *dst++ = _hexnibble(m_device.sig[2] >> 4);
*dst++ = _hexnibble(device.sig[2]); *dst++ = _hexnibble(m_device.sig[2]);
} }
if (device.flags & POLL_UNTESTED) { if (m_device.flags & POLL_UNTESTED) {
src = " untested"; src = " untested";
while (*src != '\0') { while (*src != '\0') {
@ -859,27 +728,16 @@ static void reset_statemachine(uint8_t event)
sync = spi_rxtx(0x00); sync = spi_rxtx(0x00);
spi_rxtx(0x00); spi_rxtx(0x00);
memset(&device, 0x00, sizeof(struct _device)); memset(&m_device, 0x00, sizeof(avr_device_t));
if (sync == CMD_PROG_ENABLE_2) { if (sync == CMD_PROG_ENABLE_2) {
uint8_t i; uint8_t i;
for (i = 0; i < 3; i++) { for (i = 0; i < 3; i++) {
device.sig[i] = mem_read(CMD_READ_SIG_1, (CMD_READ_SIG_2 << 8) | i); m_device.sig[i] = mem_read(CMD_READ_SIG_1, (CMD_READ_SIG_2 << 8) | i);
} }
for (i = 0; i < ARRAY_SIZE(devices); i++) { avrdevice_get_by_signature(&m_device, m_device.sig);
if (memcmp_P(device.sig, devices[i].sig, sizeof(device.sig)) == 0) {
memcpy_P(&device, &devices[i], sizeof(struct _device));
break;
}
}
/* unknown devices are untested */
if (device.name[0] == '\0')
{
device.flags |= POLL_UNTESTED;
}
state = (reset_cause == EV_PROG_ENTER) ? STATE_RESET_PROGMODE state = (reset_cause == EV_PROG_ENTER) ? STATE_RESET_PROGMODE
: STATE_IDLE; : STATE_IDLE;