Commit e2a55af2 authored by radioman's avatar radioman

Updated device database, implemented verify on write, code cleanup

parent bfb141d4
......@@ -24,10 +24,6 @@ device_t devices[] =
#include "devices.h"
{ .name = NULL }, };
const chip_id_t chip_ids[] =
{
#include "deviceid.h"
};
device_t *get_device_by_name(const char *name)
{
......
......@@ -26,35 +26,29 @@
typedef struct device
{
const char *name;
uint32_t protocol_id;
uint32_t variant;
size_t read_buffer_size;
size_t write_buffer_size;
size_t code_memory_size; // Presenting for every device
size_t data_memory_size;
uint8_t protocol_id;
uint8_t variant;
uint32_t read_buffer_size;
uint32_t write_buffer_size;
uint32_t code_memory_size; // Presenting for every device
uint32_t data_memory_size;
size_t data_memory2_size;
uint32_t chip_id; // A vendor-specific chip ID (i.e. 0x1E9502 for ATMEGA48)
uint32_t chip_id_bytes_count :3;
uint32_t opts1;
uint32_t opts2;
uint8_t chip_id_bytes_count;
uint16_t opts1;
uint16_t opts2;
uint32_t opts3;
uint32_t opts4;
uint32_t package_details; // pins count or image ID for some devices
uint32_t write_unlock;
uint16_t write_unlock;
fuse_decl_t *fuses; // Configuration bytes that's presenting in some architectures
uint8_t id_shift;//PIC controllers device ID have a variable bitfield Revision number
} device_t;
typedef struct chip_id_s
{
uint8_t shift;
uint32_t chip_id;
} chip_id_t;
#define WORD_SIZE(device) (((device)->opts4 & 0xFF000000) == 0x01000000 ? 2 : 1)
extern device_t devices[];
extern const chip_id_t chip_ids[];
device_t *get_device_by_name(const char *name);
......
/*Device ID table for the Microchip PIC controllers
Extracted by Radioman from the last 6.82 minipro software
*/
{ .shift = 0x04, .chip_id = 0x00e4 },
{ .shift = 0x04, .chip_id = 0x00e6 },
{ .shift = 0x04, .chip_id = 0x00e0 },
{ .shift = 0x04, .chip_id = 0x00e2 },
{ .shift = 0x04, .chip_id = 0x007d },
{ .shift = 0x05, .chip_id = 0x0023 },
{ .shift = 0x05, .chip_id = 0x0091 },
{ .shift = 0x05, .chip_id = 0x0085 },
{ .shift = 0x05, .chip_id = 0x0085 },
{ .shift = 0x05, .chip_id = 0x00a2 },
{ .shift = 0x05, .chip_id = 0x0084 },
{ .shift = 0x05, .chip_id = 0x0025 },
{ .shift = 0x05, .chip_id = 0x0099 },
{ .shift = 0x05, .chip_id = 0x008c },
{ .shift = 0x05, .chip_id = 0x009a },
{ .shift = 0x05, .chip_id = 0x00a0 },
{ .shift = 0x05, .chip_id = 0x0005 },
{ .shift = 0x05, .chip_id = 0x0030 },
{ .shift = 0x05, .chip_id = 0x0031 },
{ .shift = 0x05, .chip_id = 0x0032 },
{ .shift = 0x05, .chip_id = 0x0033 },
{ .shift = 0x05, .chip_id = 0x0082 },
{ .shift = 0x05, .chip_id = 0x0083 },
{ .shift = 0x05, .chip_id = 0x0088 },
{ .shift = 0x05, .chip_id = 0x0082 },
{ .shift = 0x05, .chip_id = 0x0083 },
{ .shift = 0x05, .chip_id = 0x0088 },
{ .shift = 0x05, .chip_id = 0x0068 },
{ .shift = 0x05, .chip_id = 0x0069 },
{ .shift = 0x05, .chip_id = 0x0047 },
{ .shift = 0x05, .chip_id = 0x004b },
{ .shift = 0x05, .chip_id = 0x0049 },
{ .shift = 0x05, .chip_id = 0x004f },
{ .shift = 0x05, .chip_id = 0x004d },
{ .shift = 0x05, .chip_id = 0x004c },
{ .shift = 0x04, .chip_id = 0x004e },
{ .shift = 0x04, .chip_id = 0x0100 },
{ .shift = 0x05, .chip_id = 0x0101 },
{ .shift = 0x05, .chip_id = 0x0102 },
{ .shift = 0x05, .chip_id = 0x0103 },
{ .shift = 0x05, .chip_id = 0x0104 },
{ .shift = 0x05, .chip_id = 0x0072 },
{ .shift = 0x04, .chip_id = 0x0076 },
{ .shift = 0x04, .chip_id = 0x013e },
{ .shift = 0x04, .chip_id = 0x013c },
{ .shift = 0x04, .chip_id = 0x013a },
{ .shift = 0x04, .chip_id = 0x0138 },
{ .shift = 0x04, .chip_id = 0x0146 },
{ .shift = 0x04, .chip_id = 0x005d },
{ .shift = 0x05, .chip_id = 0x005f },
{ .shift = 0x05, .chip_id = 0x007d },
{ .shift = 0x05, .chip_id = 0x006f },
{ .shift = 0x05, .chip_id = 0x0090 },
{ .shift = 0x05, .chip_id = 0x0091 },
{ .shift = 0x05, .chip_id = 0x0112 },
{ .shift = 0x05, .chip_id = 0x0113 },
{ .shift = 0x05, .chip_id = 0x010c },
{ .shift = 0x05, .chip_id = 0x0092 },
{ .shift = 0x05, .chip_id = 0x0114 },
{ .shift = 0x05, .chip_id = 0x0115 },
{ .shift = 0x05, .chip_id = 0x010d },
{ .shift = 0x05, .chip_id = 0x0093 },
{ .shift = 0x05, .chip_id = 0x007c },
{ .shift = 0x05, .chip_id = 0x007e },
{ .shift = 0x05, .chip_id = 0x0086 },
{ .shift = 0x05, .chip_id = 0x0087 },
{ .shift = 0x05, .chip_id = 0x00c4 },
{ .shift = 0x05, .chip_id = 0x00c3 },
{ .shift = 0x05, .chip_id = 0x00c2 },
{ .shift = 0x05, .chip_id = 0x00c1 },
{ .shift = 0x05, .chip_id = 0x00c0 },
{ .shift = 0x05, .chip_id = 0x00cc },
{ .shift = 0x05, .chip_id = 0x00cb },
{ .shift = 0x05, .chip_id = 0x00ca },
{ .shift = 0x05, .chip_id = 0x00c9 },
{ .shift = 0x05, .chip_id = 0x00c8 },
{ .shift = 0x05, .chip_id = 0x00d9 },
{ .shift = 0x05, .chip_id = 0x00d8 },
{ .shift = 0x05, .chip_id = 0x00db },
{ .shift = 0x05, .chip_id = 0x00da },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x002b },
{ .shift = 0x05, .chip_id = 0x002b },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x0000 },
{ .shift = 0x05, .chip_id = 0x008a },
{ .shift = 0x05, .chip_id = 0x008a },
This diff is collapsed.
......@@ -185,8 +185,7 @@ int Config_set_str(const char *par_name, const char *value)
return -1;
}
strcpy(config_content[i].param_value, value);
if (strlen(par_name) + strlen(value) + 4
>= sizeof(config_content[i].config_line))
if (strlen(par_name) + strlen(value) + 4 >= sizeof(config_content[i].config_line))
{
return -1;
}
......@@ -196,8 +195,7 @@ int Config_set_str(const char *par_name, const char *value)
}
}
if (strlen(par_name) + strlen(value) + 4
>= sizeof(config_content[i].config_line))
if (strlen(par_name) + strlen(value) + 4 >= sizeof(config_content[i].config_line))
{
return -1;
}
......
This diff is collapsed.
......@@ -96,8 +96,7 @@ static void msg_init(uint8_t *out_buf, uint8_t cmd, device_t *device, int icsp)
format_int(&(out_buf[12]), device->code_memory_size, 4, MP_LITTLE_ENDIAN);
}
static size_t msg_transfer(minipro_handle_t *handle, uint8_t *buf,
size_t length, uint32_t direction)
static size_t msg_transfer(minipro_handle_t *handle, uint8_t *buf, size_t length, uint32_t direction)
{
int bytes_transferred;
uint32_t ret;
......@@ -159,17 +158,24 @@ void minipro_protect_on(minipro_handle_t *handle)
msg_send(handle, msg, 10);
}
uint32_t minipro_get_ovc_status(minipro_handle_t *handle)
uint32_t minipro_get_ovc_status(minipro_handle_t *handle, minipro_status_t *status)
{
msg_init(msg, MP_REQUEST_STATUS1_MSG2, handle->device, handle->icsp);
msg_send(handle, msg, 5);
memset(msg, 0, sizeof(msg));
msg_recv(handle, msg, sizeof(msg));
return msg[9];
if (status) //Check for null
{
//This is verify while writing feature.
status->error = msg[0];
status->address = load_int(&msg[6], 3, MP_LITTLE_ENDIAN);
status->c1 = load_int(&msg[2], 2, MP_LITTLE_ENDIAN);
status->c2 = load_int(&msg[4], 2, MP_LITTLE_ENDIAN);
}
return msg[9]; //return the ovc status
}
void minipro_read_block(minipro_handle_t *handle, uint32_t type, uint32_t addr,
uint8_t *buf, size_t len)
void minipro_read_block(minipro_handle_t *handle, uint32_t type, uint32_t addr, uint8_t *buf, size_t len)
{
msg_init(msg, type, handle->device, handle->icsp);
format_int(&(msg[2]), len, 2, MP_LITTLE_ENDIAN);
......@@ -178,8 +184,7 @@ void minipro_read_block(minipro_handle_t *handle, uint32_t type, uint32_t addr,
msg_recv(handle, buf, len);
}
void minipro_write_block(minipro_handle_t *handle, uint32_t type, uint32_t addr,
uint8_t *buf, size_t len)
void minipro_write_block(minipro_handle_t *handle, uint32_t type, uint32_t addr, uint8_t *buf, size_t len)
{
msg_init(msg, type, handle->device, handle->icsp);
format_int(&(msg[2]), len, 2, MP_LITTLE_ENDIAN);
......@@ -199,8 +204,7 @@ uint32_t minipro_get_chip_id(minipro_handle_t *handle, uint8_t *type)
return (msg[1] ? load_int(&(msg[2]), msg[1], MP_BIG_ENDIAN) : 0); //Check for positive length.
}
void minipro_read_fuses(minipro_handle_t *handle, uint32_t type, size_t length,
uint8_t *buf)
void minipro_read_fuses(minipro_handle_t *handle, uint32_t type, size_t length, uint8_t *buf)
{
msg_init(msg, type, handle->device, handle->icsp);
msg[2] = (type == MP_READ_CFG && length == 4) ? 2 : 1; // note that PICs with 1 config word will show length==2
......@@ -210,8 +214,7 @@ void minipro_read_fuses(minipro_handle_t *handle, uint32_t type, size_t length,
memcpy(buf, &(msg[7]), length);
}
void minipro_write_fuses(minipro_handle_t *handle, uint32_t type, size_t length,
uint8_t *buf)
void minipro_write_fuses(minipro_handle_t *handle, uint32_t type, size_t length, uint8_t *buf)
{
// Perform actual writing
switch (type & 0xf0)
......
......@@ -124,22 +124,27 @@ typedef struct minipro_handle
uint32_t icsp;
} minipro_handle_t;
typedef struct minipro_status_s
{
uint32_t error;
uint32_t address;
uint16_t c1;
uint16_t c2;
} minipro_status_t;
minipro_handle_t *minipro_open(device_t *device);
void minipro_close(minipro_handle_t *handle);
void minipro_begin_transaction(minipro_handle_t *handle);
void minipro_end_transaction(minipro_handle_t *handle);
void minipro_protect_off(minipro_handle_t *handle);
void minipro_protect_on(minipro_handle_t *handle);
uint32_t minipro_get_ovc_status(minipro_handle_t *handle);
void minipro_read_block(minipro_handle_t *handle, uint32_t type, uint32_t addr,
uint8_t *buf, size_t len);
void minipro_write_block(minipro_handle_t *handle, uint32_t type, uint32_t addr,
uint8_t *buf, size_t len);
uint32_t minipro_get_ovc_status(minipro_handle_t *handle, minipro_status_t *status);
void minipro_read_block(minipro_handle_t *handle, uint32_t type, uint32_t addr, uint8_t *buf, size_t len);
void minipro_write_block(minipro_handle_t *handle, uint32_t type, uint32_t addr, uint8_t *buf, size_t len);
uint32_t minipro_get_chip_id(minipro_handle_t *handle, uint8_t *type);
void minipro_read_fuses(minipro_handle_t *handle, uint32_t type, size_t length,
uint8_t *buf);
void minipro_write_fuses(minipro_handle_t *handle, uint32_t type, size_t length,
uint8_t *buf);
void minipro_read_fuses(minipro_handle_t *handle, uint32_t type, size_t length, uint8_t *buf);
void minipro_write_fuses(minipro_handle_t *handle, uint32_t type, size_t length, uint8_t *buf);
uint32_t minipro_erase(minipro_handle_t *handle);
void minipro_print_device_info(minipro_handle_t *handle);
uint8_t minipro_unlock_tsop48(minipro_handle_t *handle);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment