fet_olimex_db: use a terminator record instead of a fixed array size.

This commit is contained in:
Daniel Beer 2014-12-15 09:04:38 +13:00
parent bac7d08653
commit e07ea5bae6
3 changed files with 10 additions and 39 deletions

View File

@ -17,9 +17,10 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include <stddef.h>
#include "devicelist.h" #include "devicelist.h"
const struct device_table sdeviceID[290] = const struct device_table sdeviceID[] =
{ {
/* Fuse parameter is set without lock bit /* Fuse parameter is set without lock bit
* 0x0 0x1 0x2 0x3 0x8 0x9 0xD Fuse Fuse DeviceTypeID Device String * 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 {{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"}, {{0x29, 0x55, -1 , -1 , -1 , -1 , -1 , -1 , -1 }, DT_MSP430G2955, "MSP430G2955"},
// end of device table default return value // 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}
}; };

View File

@ -310,10 +310,9 @@ typedef enum {
DT_MSP430F5213, DT_MSP430F5213,
DT_MSP430F5212, DT_MSP430F5212,
DT_MSP430G2955, DT_MSP430G2955,
DT_END
} devicetype_t; } devicetype_t;
/* Mapping between device types and identification bytes. */ /* Mapping between device types and identification bytes. */
extern const struct device_table sdeviceID[290]; extern const struct device_table sdeviceID[];
#endif #endif

View File

@ -7920,43 +7920,14 @@ static const struct fet_olimex_db_record fet_olimex_db[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 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 fet_olimex_db_find_by_name(const char *name)
{ {
int i; int i;
for (i = 1; i < ARRAY_LEN(sdeviceID); i++) { for (i = 1; sdeviceID[i].name; i++) {
const struct device_table *r = &sdeviceID[i]; const struct device_table *r = &sdeviceID[i];
if (!strcasecmp(r->name, name)) 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; 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) if (func(user_data, sdeviceID[i].name) < 0)
return -1; return -1;
@ -7982,7 +7953,7 @@ int fet_olimex_db_identify(const uint8_t *data)
uint16_t fuse = LE_WORD(data, 16); uint16_t fuse = LE_WORD(data, 16);
int i; int i;
for (i = 1; i < DT_END; i++) { for (i = 1; sdeviceID[i].name; i++) {
if (((0xFF == sdeviceID[i].device_id_param[0]) || if (((0xFF == sdeviceID[i].device_id_param[0]) ||
(sdeviceID[i].device_id_param[0] == data[ID0_OFFSET])) && (sdeviceID[i].device_id_param[0] == data[ID0_OFFSET])) &&
((0xFF == sdeviceID[i].device_id_param[1]) || ((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) 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 DT_UNKNOWN_DEVICE;
return sdeviceID[indx].device_type_id; 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]; const struct fet_olimex_db_record *rec = &fet_olimex_db[type];
if (type <= DT_UNKNOWN_DEVICE || type >= DT_END) if (type <= 0)
return NULL; return NULL;
if (!rec->name) if (!rec->name)