aboutsummaryrefslogtreecommitdiffstats
path: root/src/lpc176x/chipid.c
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2019-11-26 08:54:40 -0500
committerKevin O'Connor <kevin@koconnor.net>2019-11-26 08:54:40 -0500
commit35de9b8e554d497bfa0cc616eeac14102755c495 (patch)
tree0a1b3e1f4043b0b8d95a93e539d410a6bbe1b002 /src/lpc176x/chipid.c
parente80ced5568c0a6c8b59035070db7b05df8d7b39c (diff)
downloadkutter-35de9b8e554d497bfa0cc616eeac14102755c495.tar.gz
kutter-35de9b8e554d497bfa0cc616eeac14102755c495.tar.xz
kutter-35de9b8e554d497bfa0cc616eeac14102755c495.zip
lpc176x: Move chip id code from usbserial.c to new file chipid.c
Add a chipid.c file - this makes the code layout more similar to the other arm boards. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src/lpc176x/chipid.c')
-rw-r--r--src/lpc176x/chipid.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/lpc176x/chipid.c b/src/lpc176x/chipid.c
new file mode 100644
index 00000000..80b80619
--- /dev/null
+++ b/src/lpc176x/chipid.c
@@ -0,0 +1,46 @@
+// Support for extracting the hardware chip id on lpc176x
+//
+// Copyright (C) 2019 Kevin O'Connor <kevin@koconnor.net>
+//
+// This file may be distributed under the terms of the GNU GPLv3 license.
+
+#include "autoconf.h" // CONFIG_USB_SERIAL_NUMBER_CHIPID
+#include "generic/irq.h" // irq_disable
+#include "generic/usb_cdc.h" // usb_fill_serial
+#include "generic/usbstd.h" // usb_string_descriptor
+#include "sched.h" // DECL_INIT
+
+// IAP interface
+#define IAP_LOCATION 0x1fff1ff1
+#define IAP_CMD_READ_UID 58
+#define IAP_UID_LEN 16
+typedef void (*IAP)(uint32_t *, uint32_t *);
+
+static struct {
+ struct usb_string_descriptor desc;
+ uint16_t data[IAP_UID_LEN * 2];
+} cdc_chipid;
+
+struct usb_string_descriptor *
+usbserial_get_serialid(void)
+{
+ return &cdc_chipid.desc;
+}
+
+void
+chipid_init(void)
+{
+ if (!CONFIG_USB_SERIAL_NUMBER_CHIPID)
+ return;
+
+ uint32_t iap_cmd_uid[5] = {IAP_CMD_READ_UID, 0, 0, 0, 0};
+ uint32_t iap_resp[5];
+ IAP iap_entry = (IAP)IAP_LOCATION;
+ irq_disable();
+ iap_entry(iap_cmd_uid, iap_resp);
+ irq_enable();
+
+ usb_fill_serial(&cdc_chipid.desc, ARRAY_SIZE(cdc_chipid.data)
+ , &iap_resp[1]);
+}
+DECL_INIT(chipid_init);