Probe chip ID bytes on startup.

This commit is contained in:
Daniel Beer 2012-08-09 15:33:56 +12:00
parent 377e30ea03
commit 886fbd59c9
3 changed files with 61 additions and 0 deletions

View File

@ -16,6 +16,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "output.h"
#include "device.h"
device_t device_default;
@ -88,3 +89,48 @@ int device_setbrk(device_t dev, int which, int enabled, address_t addr,
return 0;
}
int device_probe_id(device_t dev)
{
uint8_t data[16];
if (dev->type->readmem(dev, 0xff0, data, sizeof(data)) < 0) {
printc_err("device_probe_id: read failed\n");
return -1;
}
if (data[0] == 0x80) {
if (dev->type->readmem(dev, 0x1a00, data, sizeof(data)) < 0) {
printc_err("device_probe_id: read failed\n");
return -1;
}
dev->dev_id[0] = data[4];
dev->dev_id[1] = data[5];
dev->dev_id[2] = data[6];
} else {
dev->dev_id[0] = data[0];
dev->dev_id[1] = data[1];
dev->dev_id[2] = data[13];
}
printc_dbg("Chip ID data: %02x %02x", dev->dev_id[0], dev->dev_id[1]);
if (dev->dev_id[2])
printc(" %02x", dev->dev_id[2]);
if (device_is_fram(dev))
printc(" [FRAM]");
printc("\n");
return 0;
}
/* Is there a more reliable way of doing this? */
int device_is_fram(device_t dev)
{
const uint8_t a = dev->dev_id[0];
const uint8_t b = dev->dev_id[1];
return ((a < 0x04) && (b == 0x81)) ||
(((a & 0xf0) == 0x70) && ((b & 0x8e) == 0x80));
}

View File

@ -113,6 +113,8 @@ struct device_class {
struct device {
const struct device_class *type;
uint8_t dev_id[3];
/* Breakpoint table. This should not be modified directly.
* Instead, you should use the device_setbrk() helper function. This
* will set the appropriate flags and ensure that the breakpoint is
@ -122,6 +124,16 @@ struct device {
struct device_breakpoint breakpoints[DEVICE_MAX_BREAKPOINTS];
};
/* Probe the device memory and extract ID bytes. This should be called
* after the device structure is ready.
*/
int device_probe_id(device_t dev);
/* Determine, from the device ID bytes, whether this chip is an FRAM or
* flash-based device.
*/
int device_is_fram(device_t dev);
/* Set or clear a breakpoint. The index of the modified entry is
* returned, or -1 if no free entries were available. The modified
* entry is flagged so that it will be reloaded on the next run.

View File

@ -364,6 +364,9 @@ int main(int argc, char **argv)
return -1;
}
if (device_probe_id(device_default) < 0)
printc_err("warning: device ID probe failed\n");
simio_init();
if (!args.no_rc)