From e07ea5bae6874e11444e06843f167bce9f7f456b Mon Sep 17 00:00:00 2001 From: Daniel Beer Date: Mon, 15 Dec 2014 09:04:38 +1300 Subject: [PATCH] fet_olimex_db: use a terminator record instead of a fixed array size. --- drivers/devicelist.c | 5 +++-- drivers/devicelist.h | 3 +-- drivers/fet_olimex_db.c | 41 ++++++----------------------------------- 3 files changed, 10 insertions(+), 39 deletions(-) diff --git a/drivers/devicelist.c b/drivers/devicelist.c index 000033d..57e70f3 100644 --- a/drivers/devicelist.c +++ b/drivers/devicelist.c @@ -17,9 +17,10 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include #include "devicelist.h" -const struct device_table sdeviceID[290] = +const struct device_table sdeviceID[] = { /* Fuse parameter is set without lock bit * 0x0 0x1 0x2 0x3 0x8 0x9 0xD Fuse Fuse DeviceTypeID Device String @@ -315,5 +316,5 @@ const struct device_table sdeviceID[290] = {{0x40, 0x81, -1 , -1 , -1 , -1 , -1 , -1 , -1 }, DT_MSP430F5229, "MSP430F5212"}, // MSP430F5529 {{0x29, 0x55, -1 , -1 , -1 , -1 , -1 , -1 , -1 }, DT_MSP430G2955, "MSP430G2955"}, // end of device table default return value - {{ 0 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 }, DT_END, "End_of_devices"}, //End of devices + {{ 0 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 }, -1, NULL} }; diff --git a/drivers/devicelist.h b/drivers/devicelist.h index 2f3c8d7..1f4fdde 100644 --- a/drivers/devicelist.h +++ b/drivers/devicelist.h @@ -310,10 +310,9 @@ typedef enum { DT_MSP430F5213, DT_MSP430F5212, DT_MSP430G2955, - DT_END } devicetype_t; /* Mapping between device types and identification bytes. */ -extern const struct device_table sdeviceID[290]; +extern const struct device_table sdeviceID[]; #endif diff --git a/drivers/fet_olimex_db.c b/drivers/fet_olimex_db.c index 70f4348..76912b7 100644 --- a/drivers/fet_olimex_db.c +++ b/drivers/fet_olimex_db.c @@ -7920,43 +7920,14 @@ static const struct fet_olimex_db_record fet_olimex_db[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } - }, - [DT_END] = { - .name = "End_of_devices", - .msg29_params = {0x00, 0x120, 0x118}, - .msg29_data = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, - }, - .msg2b_len = 0x4a, - .msg2b_data = { - 0x00, 0x0c, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, - }, - }, + } }; int fet_olimex_db_find_by_name(const char *name) { int i; - for (i = 1; i < ARRAY_LEN(sdeviceID); i++) { + for (i = 1; sdeviceID[i].name; i++) { const struct device_table *r = &sdeviceID[i]; if (!strcasecmp(r->name, name)) @@ -7970,7 +7941,7 @@ int fet_olimex_db_enum(fet_olimex_db_enum_func_t func, void *user_data) { int i; - for (i = 1; i < ARRAY_LEN(sdeviceID) - 1; i++) + for (i = 1; sdeviceID[i].name; i++) if (func(user_data, sdeviceID[i].name) < 0) return -1; @@ -7982,7 +7953,7 @@ int fet_olimex_db_identify(const uint8_t *data) uint16_t fuse = LE_WORD(data, 16); int i; - for (i = 1; i < DT_END; i++) { + for (i = 1; sdeviceID[i].name; i++) { if (((0xFF == sdeviceID[i].device_id_param[0]) || (sdeviceID[i].device_id_param[0] == data[ID0_OFFSET])) && ((0xFF == sdeviceID[i].device_id_param[1]) || @@ -8016,7 +7987,7 @@ int fet_olimex_db_identify(const uint8_t *data) devicetype_t fet_olimex_db_index_to_type(int indx) { - if (indx < 1 || indx >= ARRAY_LEN(sdeviceID) - 1) + if (indx < 1) return DT_UNKNOWN_DEVICE; return sdeviceID[indx].device_type_id; @@ -8026,7 +7997,7 @@ const struct fet_olimex_db_record *fet_db_get_record(devicetype_t type) { const struct fet_olimex_db_record *rec = &fet_olimex_db[type]; - if (type <= DT_UNKNOWN_DEVICE || type >= DT_END) + if (type <= 0) return NULL; if (!rec->name)