Add support for reading the unique ID for pistol grip
This will be useful when we want the same code to work on two of them.
It currently just gets printed out.
Change-Id: I923d6fd3d629e8a730262b33b0848d931d41badb
diff --git a/motors/pistol_grip/controller.cc b/motors/pistol_grip/controller.cc
index 2bb3e01..54d8f04 100644
--- a/motors/pistol_grip/controller.cc
+++ b/motors/pistol_grip/controller.cc
@@ -668,6 +668,21 @@
return true;
}
+// Returns an identifier for the processor we're running on.
+// This isn't guaranteed to be unique, but it should be close enough.
+uint8_t ProcessorIdentifier() {
+ // This XORs together all the bytes of the unique identifier provided by the
+ // hardware.
+ uint8_t r = 0;
+ for (uint8_t uid : {SIM_UIDH, SIM_UIDMH, SIM_UIDML, SIM_UIDL}) {
+ r = r ^ ((uid >> 0) & 0xFF);
+ r = r ^ ((uid >> 8) & 0xFF);
+ r = r ^ ((uid >> 16) & 0xFF);
+ r = r ^ ((uid >> 24) & 0xFF);
+ }
+ return r;
+}
+
} // namespace
extern "C" int main() {
@@ -820,7 +835,7 @@
printf("heap start: %p\n", __heap_start__);
printf("stack start: %p\n", __stack_end__);
- printf("Zeroing motors\n");
+ printf("Zeroing motors for %x\n", (unsigned int)ProcessorIdentifier());
uint16_t motor0_offset, motor1_offset, wheel_offset;
while (!ZeroMotors(&motor0_offset, &motor1_offset, &wheel_offset)) {
}