Brian Silverman | 8b63869 | 2017-06-26 23:10:26 -0700 | [diff] [blame] | 1 | #include "motors/core/kinetis.h" |
| 2 | |
| 3 | #include <stdio.h> |
| 4 | |
| 5 | #include "motors/core/time.h" |
| 6 | #include "motors/usb/usb_serial.h" |
| 7 | #include "motors/util.h" |
| 8 | |
| 9 | namespace frc971 { |
| 10 | namespace salsa { |
| 11 | |
| 12 | extern "C" { |
| 13 | void *__stack_chk_guard = (void *)0x67111971; |
| 14 | extern void usb_init(); |
| 15 | int _write(int file, char *ptr, int len) { |
| 16 | (void)file; |
| 17 | return usb_serial_write(0, ptr, len); |
| 18 | } |
| 19 | |
| 20 | void __stack_chk_fail(void); |
| 21 | |
| 22 | extern char *__brkval; |
Brian Silverman | f1ad1bc | 2017-09-23 13:08:36 -0400 | [diff] [blame^] | 23 | extern uint32_t __bss_ram_start__[]; |
| 24 | extern uint32_t __heap_start__[]; |
| 25 | extern uint32_t __stack_end__[]; |
Brian Silverman | 8b63869 | 2017-06-26 23:10:26 -0700 | [diff] [blame] | 26 | |
| 27 | } // extern "C" |
| 28 | |
| 29 | extern "C" int main(void) { |
| 30 | // for background about this startup delay, please see these conversations |
| 31 | // https://forum.pjrc.com/threads/36606-startup-time-(400ms)?p=113980&viewfull=1#post113980 |
| 32 | // https://forum.pjrc.com/threads/31290-Teensey-3-2-Teensey-Loader-1-24-Issues?p=87273&viewfull=1#post87273 |
| 33 | delay(400); |
| 34 | |
| 35 | // Set all interrupts to the second-lowest priority to start with. |
| 36 | for (int i = 0; i < NVIC_NUM_INTERRUPTS; i++) NVIC_SET_SANE_PRIORITY(i, 0xD); |
| 37 | |
| 38 | // Now set priorities for all the ones we care about. They only have meaning |
| 39 | // relative to each other, which means centralizing them here makes it a lot |
| 40 | // more manageable. |
| 41 | NVIC_SET_SANE_PRIORITY(IRQ_USBOTG, 0x7); |
| 42 | |
| 43 | // Set the LED's pin to output mode. |
| 44 | GPIO_BITBAND(GPIOC_PDDR, 5) = 1; |
| 45 | PORTC_PCR5 = PORT_PCR_DSE | PORT_PCR_MUX(1); |
| 46 | |
| 47 | usb_serial_init(); |
| 48 | usb_descriptor_set_product_id(0x0490); |
| 49 | usb_init(); |
| 50 | |
| 51 | // Give everything a chance to get going. |
| 52 | delay(100); |
| 53 | |
Brian Silverman | f1ad1bc | 2017-09-23 13:08:36 -0400 | [diff] [blame^] | 54 | printf("Ram start: %p\n", __bss_ram_start__); |
| 55 | printf("Heap start: %p\n", __heap_start__); |
Brian Silverman | 8b63869 | 2017-06-26 23:10:26 -0700 | [diff] [blame] | 56 | printf("Heap end: %p\n", __brkval); |
Brian Silverman | f1ad1bc | 2017-09-23 13:08:36 -0400 | [diff] [blame^] | 57 | printf("Stack start: %p\n", __stack_end__); |
Brian Silverman | 8b63869 | 2017-06-26 23:10:26 -0700 | [diff] [blame] | 58 | |
| 59 | GPIOC_PSOR = 1 << 5; |
Brian Silverman | 8b63869 | 2017-06-26 23:10:26 -0700 | [diff] [blame] | 60 | while (true) {} |
Brian Silverman | f1ad1bc | 2017-09-23 13:08:36 -0400 | [diff] [blame^] | 61 | |
Brian Silverman | 8b63869 | 2017-06-26 23:10:26 -0700 | [diff] [blame] | 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | void __stack_chk_fail(void) { |
| 66 | while (true) { |
| 67 | GPIOC_PSOR = (1 << 5); |
| 68 | printf("Stack corruption detected\n"); |
| 69 | delay(1000); |
| 70 | GPIOC_PCOR = (1 << 5); |
| 71 | delay(1000); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | } // namespace salsa |
| 76 | } // namespace frc971 |