Get some basic Teensy code working
It prints some stuff over the USB serial port and turns the on-board LED
on. Also tweak some of the existing code so it works with better
compiler options for what we're doing.
Change-Id: Ifcbd36f9eaca47a86f7a97e8c458c64f9b3df3ab
diff --git a/motors/medium_salsa.cc b/motors/medium_salsa.cc
new file mode 100644
index 0000000..1a899b1
--- /dev/null
+++ b/motors/medium_salsa.cc
@@ -0,0 +1,76 @@
+#include "motors/core/kinetis.h"
+
+#include <stdio.h>
+
+#include "motors/core/time.h"
+#include "motors/usb/usb_serial.h"
+#include "motors/util.h"
+
+namespace frc971 {
+namespace salsa {
+
+extern "C" {
+void *__stack_chk_guard = (void *)0x67111971;
+extern void usb_init();
+int _write(int file, char *ptr, int len) {
+ (void)file;
+ return usb_serial_write(0, ptr, len);
+}
+
+void __stack_chk_fail(void);
+
+extern char *__brkval;
+extern unsigned long _ebss;
+extern unsigned long _sram;
+extern unsigned long _estack;
+
+} // extern "C"
+
+extern "C" int main(void) {
+ // for background about this startup delay, please see these conversations
+ // https://forum.pjrc.com/threads/36606-startup-time-(400ms)?p=113980&viewfull=1#post113980
+ // https://forum.pjrc.com/threads/31290-Teensey-3-2-Teensey-Loader-1-24-Issues?p=87273&viewfull=1#post87273
+ delay(400);
+
+ // Set all interrupts to the second-lowest priority to start with.
+ for (int i = 0; i < NVIC_NUM_INTERRUPTS; i++) NVIC_SET_SANE_PRIORITY(i, 0xD);
+
+ // Now set priorities for all the ones we care about. They only have meaning
+ // relative to each other, which means centralizing them here makes it a lot
+ // more manageable.
+ NVIC_SET_SANE_PRIORITY(IRQ_USBOTG, 0x7);
+
+ // Set the LED's pin to output mode.
+ GPIO_BITBAND(GPIOC_PDDR, 5) = 1;
+ PORTC_PCR5 = PORT_PCR_DSE | PORT_PCR_MUX(1);
+
+ usb_serial_init();
+ usb_descriptor_set_product_id(0x0490);
+ usb_init();
+
+ // Give everything a chance to get going.
+ delay(100);
+
+ printf("Ram start: %p\n", &_sram);
+ printf("Heap start: %p\n", &_ebss);
+ printf("Heap end: %p\n", __brkval);
+ printf("Stack start: %p\n", &_estack);
+
+ GPIOC_PSOR = 1 << 5;
+
+ while (true) {}
+ return 0;
+}
+
+void __stack_chk_fail(void) {
+ while (true) {
+ GPIOC_PSOR = (1 << 5);
+ printf("Stack corruption detected\n");
+ delay(1000);
+ GPIOC_PCOR = (1 << 5);
+ delay(1000);
+ }
+}
+
+} // namespace salsa
+} // namespace frc971