Commit 126b80f8 authored by Brian Johnson's avatar Brian Johnson

low level API commands now use function ptrs to allow for tl866ii+ support

parent 83237b8a
......@@ -48,7 +48,7 @@ ifeq ($(PKG_CONFIG),)
ERROR := $(error "pkg-config utility not found")
endif
COMMON_OBJECTS=byte_utils.o database.o minipro.o fuses.o easyconfig.o version.o
COMMON_OBJECTS=byte_utils.o database.o minipro.o tl866a.o fuses.o easyconfig.o version.o
OBJECTS=$(COMMON_OBJECTS) main.o
PROGS=minipro
MINIPRO=minipro
......
......@@ -18,43 +18,44 @@
#include <stdio.h>
#include "fuses.h"
#include "minipro.h"
#include "tl866a.h"
fuse_decl_t avr_fuses[] =
{
{ .name = "fuses", .minipro_cmd = MP_READ_CFG, .length = 1, .offset = 0 },
{ .name = "lock_byte", .minipro_cmd = MP_READ_LOCK, .length = 1, .offset = 0 },
{ .name = "fuses", .minipro_cmd = MP_FUSE_CFG, .length = 1, .offset = 0 },
{ .name = "lock_byte", .minipro_cmd = MP_FUSE_LOCK, .length = 1, .offset = 0 },
{ .name = NULL }, };
fuse_decl_t avr2_fuses[] =
{
{ .name = "fuses_lo", .minipro_cmd = MP_READ_CFG, .length = 1, .offset = 0 },
{ .name = "fuses_hi", .minipro_cmd = MP_READ_CFG, .length = 1, .offset = 1 },
{ .name = "lock_byte", .minipro_cmd = MP_READ_LOCK, .length = 1, .offset = 0 },
{ .name = "fuses_lo", .minipro_cmd = MP_FUSE_CFG, .length = 1, .offset = 0 },
{ .name = "fuses_hi", .minipro_cmd = MP_FUSE_CFG, .length = 1, .offset = 1 },
{ .name = "lock_byte", .minipro_cmd = MP_FUSE_LOCK, .length = 1, .offset = 0 },
{ .name = NULL }, };
fuse_decl_t avr3_fuses[] =
{
{ .name = "fuses_lo", .minipro_cmd = MP_READ_CFG, .length = 1, .offset = 0 },
{ .name = "fuses_hi", .minipro_cmd = MP_READ_CFG, .length = 1, .offset = 1 },
{ .name = "fuses_ext", .minipro_cmd = MP_READ_CFG, .length = 1, .offset = 2 },
{ .name = "lock_byte", .minipro_cmd = MP_READ_LOCK, .length = 1, .offset = 0 },
{ .name = "fuses_lo", .minipro_cmd = MP_FUSE_CFG, .length = 1, .offset = 0 },
{ .name = "fuses_hi", .minipro_cmd = MP_FUSE_CFG, .length = 1, .offset = 1 },
{ .name = "fuses_ext", .minipro_cmd = MP_FUSE_CFG, .length = 1, .offset = 2 },
{ .name = "lock_byte", .minipro_cmd = MP_FUSE_LOCK, .length = 1, .offset = 0 },
{ .name = NULL }, };
fuse_decl_t pic_fuses[] =
{
{ .name = "user_id0", .minipro_cmd = MP_READ_USER, .length = 2, .offset = 0 },
{ .name = "user_id1", .minipro_cmd = MP_READ_USER, .length = 2, .offset = 2 },
{ .name = "user_id2", .minipro_cmd = MP_READ_USER, .length = 2, .offset = 4 },
{ .name = "user_id3", .minipro_cmd = MP_READ_USER, .length = 2, .offset = 6 },
{ .name = "conf_word", .minipro_cmd = MP_READ_CFG, .length = 2, .offset = 0 },
{ .name = "user_id0", .minipro_cmd = MP_FUSE_USER, .length = 2, .offset = 0 },
{ .name = "user_id1", .minipro_cmd = MP_FUSE_USER, .length = 2, .offset = 2 },
{ .name = "user_id2", .minipro_cmd = MP_FUSE_USER, .length = 2, .offset = 4 },
{ .name = "user_id3", .minipro_cmd = MP_FUSE_USER, .length = 2, .offset = 6 },
{ .name = "conf_word", .minipro_cmd = MP_FUSE_CFG, .length = 2, .offset = 0 },
{ .name = NULL }, };
fuse_decl_t pic2_fuses[] =
{
{ .name = "user_id0", .minipro_cmd = MP_READ_USER, .length = 2, .offset = 0 },
{ .name = "user_id1", .minipro_cmd = MP_READ_USER, .length = 2, .offset = 2 },
{ .name = "user_id2", .minipro_cmd = MP_READ_USER, .length = 2, .offset = 4 },
{ .name = "user_id3", .minipro_cmd = MP_READ_USER, .length = 2, .offset = 6 },
{ .name = "conf_word", .minipro_cmd = MP_READ_CFG, .length = 2, .offset = 0 },
{ .name = "conf_word1", .minipro_cmd = MP_READ_CFG, .length = 2, .offset = 2 },
{ .name = "user_id0", .minipro_cmd = MP_FUSE_USER, .length = 2, .offset = 0 },
{ .name = "user_id1", .minipro_cmd = MP_FUSE_USER, .length = 2, .offset = 2 },
{ .name = "user_id2", .minipro_cmd = MP_FUSE_USER, .length = 2, .offset = 4 },
{ .name = "user_id3", .minipro_cmd = MP_FUSE_USER, .length = 2, .offset = 6 },
{ .name = "conf_word", .minipro_cmd = MP_FUSE_CFG, .length = 2, .offset = 0 },
{ .name = "conf_word1", .minipro_cmd = MP_FUSE_CFG, .length = 2, .offset = 2 },
{ .name = NULL }, };
......@@ -23,6 +23,7 @@
#include <libgen.h>
#include <signal.h>
#include "minipro.h"
#include "tl866a.h"
#include "database.h"
#include "byte_utils.h"
#include "fuses.h"
......@@ -182,6 +183,17 @@ void print_device_info_and_exit(device_t *device)
exit(0);
}
void hardware_check_and_exit(int exit_code)
{
minipro_handle_t *handle = minipro_open(NULL);
minipro_hardware_check(handle);
minipro_close(handle);
exit(exit_code);
}
void parse_cmdline(int argc, char **argv)
{
int8_t c;
......@@ -298,8 +310,7 @@ void parse_cmdline(int argc, char **argv)
break;
case 't':
minipro_hardware_check();
exit(0);
hardware_check_and_exit(0);
break;
default:
print_help_and_exit(argv[0], -1);
......@@ -704,13 +715,13 @@ void action_read(const char *filename, minipro_handle_t *handle, device_t *devic
}
if (cmdopts.page == CODE)
{
read_page_file(handle, code_filename, MP_READ_CODE, "Code",
read_page_file(handle, code_filename, MP_CODE, "Code",
device->code_memory_size);
}
if (cmdopts.page == DATA && device->data_memory_size)
{
read_page_file(handle, data_filename, MP_READ_DATA, "Data",
read_page_file(handle, data_filename, MP_DATA, "Data",
device->data_memory_size);
}
if (cmdopts.page == CONFIG && device->fuses)
......@@ -805,17 +816,17 @@ void action_write(const char *filename, minipro_handle_t *handle, device_t *devi
{
case UNSPECIFIED:
case CODE:
write_page_file(handle, filename, MP_WRITE_CODE, "Code",
write_page_file(handle, filename, MP_CODE, "Code",
device->code_memory_size);
if (cmdopts.no_verify == 0)
verify_page_file(handle, filename, MP_READ_CODE, "Code",
verify_page_file(handle, filename, MP_CODE, "Code",
device->code_memory_size);
break;
case DATA:
write_page_file(handle, filename, MP_WRITE_DATA, "Data",
write_page_file(handle, filename, MP_DATA, "Data",
device->data_memory_size);
if (cmdopts.no_verify == 0)
verify_page_file(handle, filename, MP_READ_DATA, "Data",
verify_page_file(handle, filename, MP_DATA, "Data",
device->data_memory_size);
break;
case CONFIG:
......
This diff is collapsed.
......@@ -18,43 +18,10 @@
#ifndef __MINIPRO_H
#define __MINIPRO_H
/*
* This header only contains low-level wrappers against typical requests.
* Please refer main.c if you're looking for higher-level logic.
*/
#include <libusb.h>
#include "version.h"
/*
* These are the known firmware versions along with the versions of the
* official software from whence they came.
*
* Firmware Official Release Firmware
* Version Program Date Version
* String Version ID
*
* 3.2.85 6.82 Jul 14, 2018 0x0255
* 3.2.82 6.71 Apr 17, 2018 0x0252
* 3.2.81 6.70 Mar 7, 2018 0x0251
* 3.2.80 6.60 May 9, 2017 0x0250
* 3.2.72 6.50 Dec 25, 2015 0x0248
* 3.2.69 6.17 Jul 11, 2015 0x0245
* 3.2.68 6.16 Jun 12, 2015 0x0244
* 3.2.66 6.13 Jun 9, 2015 0x0242
* 3.2.63 6.10 Jul 16, 2014 0x023f
* 3.2.62 6.00 Jan 7, 2014 0x023e
* 3.2.61 5.91 Mar 9, 2013 0x023d
* 3.2.60 5.90 Mar 4, 2013 0x023c
* 3.2.59 5.80 Nov 1, 2012 0x023b
* 3.2.58 5.71 Aug 31, 2012 0x023a
* 3.2.57 5.70 Aug 27, 2012 0x0239
* 3.2.56 5.60 Jun 12, 2012 0x0238
* 1.00 Jun 18, 2010
*
*/
#define MP_TL866A 1
#define MP_TL866CS 2
#define MP_TL866IIPLUS 5
......@@ -64,35 +31,16 @@
#define MP_FIRMWARE_VERSION 0x0255
#define MP_FIRMWARE_STRING "03.2.85"
#define MP_REQUEST_STATUS1_MSG1 0x03
#define MP_REQUEST_STATUS1_MSG2 0xfe
#define MP_GET_SYSTEM_INFO 0x00
#define MP_END_TRANSACTION 0x04
#define MP_GET_CHIP_ID 0x05
#define MP_READ_CODE 0x21
#define MP_READ_DATA 0x30
#define MP_WRITE_CODE 0x20
#define MP_WRITE_DATA 0x31
#define MP_ERASE 0x22
#define MP_READ_USER 0x10
#define MP_WRITE_USER 0x11
#define MP_CODE 0x00
#define MP_DATA 0x01
#define MP_READ_CFG 0x12
#define MP_WRITE_CFG 0x13
#define MP_FUSE_USER 0x00
#define MP_FUSE_CFG 0x01
#define MP_FUSE_LOCK 0x02
#define MP_WRITE_LOCK 0x40
#define MP_READ_LOCK 0x41
#define MP_ICSP_ENABLE 0x80
#define MP_ICSP_VCC 0x01
#define MP_PROTECT_OFF 0x44
#define MP_PROTECT_ON 0x45
#define MP_ICSP_ENABLE 0x80
#define MP_ICSP_VCC 0x01
//TSOP48
#define MP_UNLOCK_TSOP48 0xFD
#define MP_TSOP48_TYPE_V3 0x00
#define MP_TSOP48_TYPE_NONE 0x01
#define MP_TSOP48_TYPE_V0 0x02
......@@ -105,12 +53,6 @@
#define MP_ID_TYPE4 0x04
#define MP_ID_TYPE5 0x05
//Hardware Bit Banging
#define MP_RESET_PIN_DRIVERS 0xD0
#define MP_SET_LATCH 0xD1
#define MP_READ_ZIF_PINS 0xD2
#include "database.h"
typedef struct minipro_report_info
......@@ -126,18 +68,6 @@ typedef struct minipro_report_info
uint8_t hardware_version;
} minipro_report_info_t;
typedef struct minipro_handle
{
char model[16];
char firmware_str[16];
uint32_t firmware;
libusb_device_handle *usb_handle;
libusb_context *ctx;
device_t *device;
uint32_t icsp;
} minipro_handle_t;
typedef struct minipro_status_s
{
uint32_t error;
......@@ -155,6 +85,33 @@ typedef struct zif_pins_s
uint8_t mask;
} zif_pins_t;
typedef struct minipro_handle
{
char model[16];
char firmware_str[16];
uint32_t firmware;
libusb_device_handle *usb_handle;
libusb_context *ctx;
void (*minipro_begin_transaction)(struct minipro_handle *);
void (*minipro_end_transaction)(struct minipro_handle *);
void (*minipro_protect_off)(struct minipro_handle *);
void (*minipro_protect_on)(struct minipro_handle *);
uint32_t (*minipro_get_ovc_status)(struct minipro_handle *, struct minipro_status_s *);
void (*minipro_read_block)(struct minipro_handle *, uint32_t, uint32_t, uint8_t *, size_t);
void (*minipro_write_block)(struct minipro_handle *, uint32_t, uint32_t, uint8_t *, size_t);
uint32_t (*minipro_get_chip_id)(struct minipro_handle *, uint8_t *);
void (*minipro_read_fuses)(struct minipro_handle *, uint32_t, size_t, uint8_t *);
void (*minipro_write_fuses)(struct minipro_handle *, uint32_t, size_t, uint8_t *);
uint32_t (*minipro_erase)(struct minipro_handle *);
uint8_t (*minipro_unlock_tsop48)(struct minipro_handle *);
void (*minipro_hardware_check)(struct minipro_handle *);
device_t *device;
uint32_t icsp;
} minipro_handle_t;
enum VPP_PINS
{
VPP1, VPP2, VPP3, VPP4, VPP9, VPP10, VPP30, VPP31,
......@@ -194,7 +151,6 @@ void minipro_read_fuses(minipro_handle_t *handle, uint32_t type, size_t length,
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);
uint8_t minipro_unlock_tsop48(minipro_handle_t *handle);
void minipro_hardware_check();
void minipro_hardware_check(minipro_handle_t *handle);
#endif
This diff is collapsed.
/*
* tl866a.h - Low level ops for TL866A/CS declarations and definations
*
* This file is a part of Minipro.
*
* Minipro 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 3 of the License, or
* (at your option) any later version.
*
* Minipro 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.
*
*/
#ifndef __TL866A_H
#define __TL866A_H
/*
* This header only contains low-level wrappers against typical requests.
* Please refer main.c if you're looking for higher-level logic.
*/
/*
* These are the known firmware versions along with the versions of the
* official software from whence they came.
*
* Firmware Official Release Firmware
* Version Program Date Version
* String Version ID
*
* 3.2.85 6.82 Jul 14, 2018 0x0255
* 3.2.82 6.71 Apr 17, 2018 0x0252
* 3.2.81 6.70 Mar 7, 2018 0x0251
* 3.2.80 6.60 May 9, 2017 0x0250
* 3.2.72 6.50 Dec 25, 2015 0x0248
* 3.2.69 6.17 Jul 11, 2015 0x0245
* 3.2.68 6.16 Jun 12, 2015 0x0244
* 3.2.66 6.13 Jun 9, 2015 0x0242
* 3.2.63 6.10 Jul 16, 2014 0x023f
* 3.2.62 6.00 Jan 7, 2014 0x023e
* 3.2.61 5.91 Mar 9, 2013 0x023d
* 3.2.60 5.90 Mar 4, 2013 0x023c
* 3.2.59 5.80 Nov 1, 2012 0x023b
* 3.2.58 5.71 Aug 31, 2012 0x023a
* 3.2.57 5.70 Aug 27, 2012 0x0239
* 3.2.56 5.60 Jun 12, 2012 0x0238
* 1.00 Jun 18, 2010
*
*/
#define TL866A_REQUEST_STATUS1_MSG1 0x03
#define TL866A_REQUEST_STATUS1_MSG2 0xfe
#define TL866A_END_TRANSACTION 0x04
#define TL866A_GET_CHIP_ID 0x05
#define TL866A_READ_CODE 0x21
#define TL866A_READ_DATA 0x30
#define TL866A_WRITE_CODE 0x20
#define TL866A_WRITE_DATA 0x31
#define TL866A_ERASE 0x22
#define TL866A_READ_USER 0x10
#define TL866A_WRITE_USER 0x11
#define TL866A_READ_CFG 0x12
#define TL866A_WRITE_CFG 0x13
#define TL866A_WRITE_LOCK 0x40
#define TL866A_READ_LOCK 0x41
#define TL866A_PROTECT_OFF 0x44
#define TL866A_PROTECT_ON 0x45
//TSOP48
#define TL866A_UNLOCK_TSOP48 0xFD
//Hardware Bit Banging
#define TL866A_RESET_PIN_DRIVERS 0xD0
#define TL866A_SET_LATCH 0xD1
#define TL866A_READ_ZIF_PINS 0xD2
void tl866a_begin_transaction(minipro_handle_t *handle);
void tl866a_end_transaction(minipro_handle_t *handle);
void tl866a_protect_off(minipro_handle_t *handle);
void tl866a_protect_on(minipro_handle_t *handle);
uint32_t tl866a_get_ovc_status(minipro_handle_t *handle, minipro_status_t *status);
void tl866a_read_block(minipro_handle_t *handle, uint32_t type, uint32_t addr, uint8_t *buf, size_t len);
void tl866a_write_block(minipro_handle_t *handle, uint32_t type, uint32_t addr, uint8_t *buf, size_t len);
uint32_t tl866a_get_chip_id(minipro_handle_t *handle, uint8_t *type);
void tl866a_read_fuses(minipro_handle_t *handle, uint32_t type, size_t length, uint8_t *buf);
void tl866a_write_fuses(minipro_handle_t *handle, uint32_t type, size_t length, uint8_t *buf);
uint32_t tl866a_erase(minipro_handle_t *handle);
uint8_t tl866a_unlock_tsop48(minipro_handle_t *handle);
void tl866a_hardware_check(minipro_handle_t *handle);
#endif
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