Revision 10687985
devices/DiWheelDrive/main.cpp | ||
---|---|---|
21 | 21 |
|
22 | 22 |
Global global; |
23 | 23 |
|
24 |
struct blVersion_t { |
|
25 |
const uint8_t identifier; |
|
26 |
const uint8_t major; |
|
27 |
const uint8_t minor; |
|
28 |
const uint8_t patch; |
|
29 |
} __attribute__((packed)); |
|
30 |
|
|
24 | 31 |
void systemShutdown() { |
25 | 32 |
types::kinematic k; |
26 | 33 |
uint8_t i; |
... | ... | |
606 | 613 |
|
607 | 614 |
void shellRequestGetBootloaderInfo(BaseSequentialStream* chp, int argc, char *argv[]) { |
608 | 615 |
// check the magic number |
609 |
if (*((uint32_t*)(BL_CALLBACK_TABLE_ADDR)) == BL_MAGIC_NUMBER) { |
|
610 |
chprintf(chp, "Bootloader version: %u.%u.%u\n", |
|
611 |
*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))), |
|
612 |
*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (2*4))), |
|
613 |
*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (3*4)))); |
|
614 |
chprintf(chp, "Callback functions:\n"); |
|
615 |
if (*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))) == 0 && *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (2*4))) == 2) { |
|
616 |
chprintf(chp, "\thibernate: %s\n", *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (4*4))) ? "available" : "unsupported"); |
|
617 |
chprintf(chp, "\tdeepsleep: %s\n", *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (5*4))) ? "available" : "unsupported"); |
|
618 |
chprintf(chp, "\ttransportation: %s\n", *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (6*4))) ? "available" : "unsupported"); |
|
619 |
chprintf(chp, "\trestart: %s\n", *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (10*4))) ? "available" : "unsupported"); |
|
620 |
} else if (*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))) == 0 && *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (2*4))) == 3) { |
|
621 |
chprintf(chp, "\thibernate: %s\n", *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (4*4))) ? "available" : "unsupported"); |
|
622 |
chprintf(chp, "\tdeepsleep: %s\n", *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (5*4))) ? "available" : "unsupported"); |
|
623 |
chprintf(chp, "\ttransportation: %s\n", *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (6*4))) ? "available" : "unsupported"); |
|
624 |
chprintf(chp, "\trestart: %s\n", *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (7*4))) ? "available" : "unsupported"); |
|
625 |
chprintf(chp, "\thandle request: %s\n", *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (8*4))) ? "available" : "unsupported"); |
|
626 |
} |
|
627 |
} else { |
|
628 |
chprintf((BaseSequentialStream*) &SD1, "Bootloader deprecated\n"); |
|
616 |
switch (*((uint32_t*)(BL_CALLBACK_TABLE_ADDR))) { |
|
617 |
case (('A'<<24) | ('-'<<16) | ('B'<<8) | ('L'<<0)): |
|
618 |
chprintf((BaseSequentialStream*) &SD1, "Bootloader %u.%u.%u\n", |
|
619 |
((blVersion_t*)(BL_CALLBACK_TABLE_ADDR + (1*4)))->major, |
|
620 |
((blVersion_t*)(BL_CALLBACK_TABLE_ADDR + (1*4)))->minor, |
|
621 |
((blVersion_t*)(BL_CALLBACK_TABLE_ADDR + (1*4)))->patch); |
|
622 |
break; |
|
623 |
|
|
624 |
case BL_MAGIC_NUMBER: |
|
625 |
chprintf((BaseSequentialStream*) &SD1, "Bootloader %u.%u.%u\n", |
|
626 |
*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))), |
|
627 |
*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))), |
|
628 |
*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4)))); |
|
629 |
break; |
|
630 |
|
|
631 |
default: |
|
632 |
chprintf((BaseSequentialStream*) &SD1, "Bootloader incompatible\n"); |
|
633 |
break; |
|
629 | 634 |
} |
630 | 635 |
|
631 | 636 |
return; |
... | ... | |
772 | 777 |
|
773 | 778 |
chprintf((BaseSequentialStream*) &SD1, "\n"); |
774 | 779 |
chprintf((BaseSequentialStream*) &SD1, BOARD_NAME " " BOARD_VERSION "\n"); |
775 |
if (*((uint32_t*)(BL_CALLBACK_TABLE_ADDR)) == BL_MAGIC_NUMBER) { |
|
776 |
chprintf((BaseSequentialStream*) &SD1, "Bootloader %u.%u.%u\n", |
|
777 |
*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))), |
|
778 |
*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (2*4))), |
|
779 |
*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (3*4)))); |
|
780 |
} else { |
|
781 |
chprintf((BaseSequentialStream*) &SD1, "Bootloader deprecated\n"); |
|
780 |
switch (*((uint32_t*)(BL_CALLBACK_TABLE_ADDR))) { |
|
781 |
case (('A'<<24) | ('-'<<16) | ('B'<<8) | ('L'<<0)): |
|
782 |
chprintf((BaseSequentialStream*) &SD1, "Bootloader %u.%u.%u\n", |
|
783 |
((blVersion_t*)(BL_CALLBACK_TABLE_ADDR + (1*4)))->major, |
|
784 |
((blVersion_t*)(BL_CALLBACK_TABLE_ADDR + (1*4)))->minor, |
|
785 |
((blVersion_t*)(BL_CALLBACK_TABLE_ADDR + (1*4)))->patch); |
|
786 |
break; |
|
787 |
|
|
788 |
case BL_MAGIC_NUMBER: |
|
789 |
chprintf((BaseSequentialStream*) &SD1, "Bootloader %u.%u.%u\n", |
|
790 |
*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))), |
|
791 |
*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))), |
|
792 |
*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4)))); |
|
793 |
break; |
|
794 |
|
|
795 |
default: |
|
796 |
chprintf((BaseSequentialStream*) &SD1, "Bootloader incompatible\n"); |
|
797 |
break; |
|
782 | 798 |
} |
783 | 799 |
chprintf((BaseSequentialStream*) &SD1, "ChibiOS " CH_KERNEL_VERSION "\n"); |
784 | 800 |
// make sure that the info text is completetly printed |
... | ... | |
872 | 888 |
BaseThread::sleep(MS2ST(250)); |
873 | 889 |
|
874 | 890 |
if (shutdown_now != SHUTDOWN_NONE) { |
875 |
if (*((uint32_t*)(BL_CALLBACK_TABLE_ADDR)) != BL_MAGIC_NUMBER) {
|
|
891 |
if ((*((uint32_t*)(BL_CALLBACK_TABLE_ADDR)) != (('A'<<24) | ('-'<<16) | ('B'<<8) | ('L'<<0))) && (*((uint32_t*)(BL_CALLBACK_TABLE_ADDR)) != BL_MAGIC_NUMBER)) {
|
|
876 | 892 |
chprintf((BaseSequentialStream*) &SD1, "ERROR: unable to shut down (bootloader deprecated).\n"); |
877 | 893 |
shutdown_now = SHUTDOWN_NONE; |
878 | 894 |
} else { |
879 | 895 |
uint32_t blCallbackPtrAddr = BL_CALLBACK_TABLE_ADDR; |
880 |
if (*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))) == 0 && *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (2*4))) == 2) { |
|
896 |
// handle bootloader version 0.2.x |
|
897 |
if ((*((uint32_t*)(BL_CALLBACK_TABLE_ADDR)) == BL_MAGIC_NUMBER) && |
|
898 |
(*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))) == 0 && *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (2*4))) == 2)) { |
|
881 | 899 |
switch (shutdown_now) { |
882 | 900 |
case SHUTDOWN_TRANSPORTATION: |
883 | 901 |
blCallbackPtrAddr += 6 * 4; |
... | ... | |
896 | 914 |
blCallbackPtrAddr = 0; |
897 | 915 |
break; |
898 | 916 |
} |
899 |
} else if (*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))) == 0 && *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (2*4))) == 3) { |
|
917 |
} |
|
918 |
// handle bootloader version 0.3.x |
|
919 |
else if ((*((uint32_t*)(BL_CALLBACK_TABLE_ADDR)) == BL_MAGIC_NUMBER) && |
|
920 |
(*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))) == 0 && *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (2*4))) == 3)) { |
|
921 |
switch (shutdown_now) { |
|
922 |
case SHUTDOWN_TRANSPORTATION: |
|
923 |
blCallbackPtrAddr += 6 * 4; |
|
924 |
break; |
|
925 |
case SHUTDOWN_DEEPSLEEP: |
|
926 |
blCallbackPtrAddr += 5 * 4; |
|
927 |
break; |
|
928 |
case SHUTDOWN_HIBERNATE: |
|
929 |
blCallbackPtrAddr += 4 * 4; |
|
930 |
break; |
|
931 |
case SHUTDOWN_RESTART: |
|
932 |
blCallbackPtrAddr += 7 * 4; |
|
933 |
break; |
|
934 |
case SHUTDOWN_HANDLE_REQUEST: |
|
935 |
blCallbackPtrAddr += 8 * 4; |
|
936 |
break; |
|
937 |
default: |
|
938 |
blCallbackPtrAddr = 0; |
|
939 |
break; |
|
940 |
} |
|
941 |
} |
|
942 |
// handle bootloader version 1.0.x |
|
943 |
else if ((*((uint32_t*)(BL_CALLBACK_TABLE_ADDR)) == (('A'<<24) | ('-'<<16) | ('B'<<8) | ('L'<<0))) && |
|
944 |
((blVersion_t*)(BL_CALLBACK_TABLE_ADDR + (1*4)))->major == 1 && ((blVersion_t*)(BL_CALLBACK_TABLE_ADDR + (1*4)))->minor == 0) { |
|
900 | 945 |
switch (shutdown_now) { |
901 | 946 |
case SHUTDOWN_TRANSPORTATION: |
902 | 947 |
blCallbackPtrAddr += 6 * 4; |
... | ... | |
920 | 965 |
} |
921 | 966 |
|
922 | 967 |
void (*blCallback)(void) = NULL; |
923 |
if (blCallbackPtrAddr) { |
|
968 |
if (blCallbackPtrAddr > BL_CALLBACK_TABLE_ADDR) {
|
|
924 | 969 |
blCallback = (void (*)(void))(*((uint32_t*)blCallbackPtrAddr)); |
925 | 970 |
|
926 | 971 |
if (!blCallback) { |
devices/LightRing/main.cpp | ||
---|---|---|
23 | 23 |
|
24 | 24 |
Global global; |
25 | 25 |
|
26 |
struct blVersion_t { |
|
27 |
const uint8_t identifier; |
|
28 |
const uint8_t major; |
|
29 |
const uint8_t minor; |
|
30 |
const uint8_t patch; |
|
31 |
} __attribute__((packed)); |
|
32 |
|
|
26 | 33 |
void shellRequestShutdown(BaseSequentialStream* chp, int argc, char *argv[]) { |
27 | 34 |
|
28 | 35 |
chprintf(chp, "shellRequestShutdown\n"); |
... | ... | |
430 | 437 |
|
431 | 438 |
void shellRequestGetBootloaderInfo(BaseSequentialStream* chp, int argc, char *argv[]) { |
432 | 439 |
// check the magic number |
433 |
if (*((uint32_t*)(BL_CALLBACK_TABLE_ADDR)) == BL_MAGIC_NUMBER) { |
|
434 |
chprintf(chp, "Bootloader version: %u.%u.%u\n", |
|
435 |
*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))), |
|
436 |
*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (2*4))), |
|
437 |
*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (3*4)))); |
|
438 |
chprintf(chp, "Callback functions:\n");if (*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))) == 0 && *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (2*4))) == 2) { |
|
439 |
chprintf(chp, "\thibernate: %s\n", *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (4*4))) ? "available" : "unsupported"); |
|
440 |
chprintf(chp, "\tdeepsleep: %s\n", *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (5*4))) ? "available" : "unsupported"); |
|
441 |
chprintf(chp, "\ttransportation: %s\n", *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (6*4))) ? "available" : "unsupported"); |
|
442 |
chprintf(chp, "\trestart: %s\n", *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (10*4))) ? "available" : "unsupported"); |
|
443 |
} else if (*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))) == 0 && *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (2*4))) == 3) { |
|
444 |
chprintf(chp, "\thibernate: %s\n", *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (4*4))) ? "available" : "unsupported"); |
|
445 |
chprintf(chp, "\tdeepsleep: %s\n", *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (5*4))) ? "available" : "unsupported"); |
|
446 |
chprintf(chp, "\ttransportation: %s\n", *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (6*4))) ? "available" : "unsupported"); |
|
447 |
chprintf(chp, "\trestart: %s\n", *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (7*4))) ? "available" : "unsupported"); |
|
448 |
chprintf(chp, "\thandle request: %s\n", *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (8*4))) ? "available" : "unsupported"); |
|
449 |
} |
|
450 |
} else { |
|
451 |
chprintf((BaseSequentialStream*) &SD1, "Bootloader deprecated\n"); |
|
440 |
switch (*((uint32_t*)(BL_CALLBACK_TABLE_ADDR))) { |
|
441 |
case (('A'<<24) | ('-'<<16) | ('B'<<8) | ('L'<<0)): |
|
442 |
chprintf((BaseSequentialStream*) &SD1, "Bootloader %u.%u.%u\n", |
|
443 |
((blVersion_t*)(BL_CALLBACK_TABLE_ADDR + (1*4)))->major, |
|
444 |
((blVersion_t*)(BL_CALLBACK_TABLE_ADDR + (1*4)))->minor, |
|
445 |
((blVersion_t*)(BL_CALLBACK_TABLE_ADDR + (1*4)))->patch); |
|
446 |
break; |
|
447 |
|
|
448 |
case BL_MAGIC_NUMBER: |
|
449 |
chprintf((BaseSequentialStream*) &SD1, "Bootloader %u.%u.%u\n", |
|
450 |
*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))), |
|
451 |
*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))), |
|
452 |
*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4)))); |
|
453 |
break; |
|
454 |
|
|
455 |
default: |
|
456 |
chprintf((BaseSequentialStream*) &SD1, "Bootloader incompatible\n"); |
|
457 |
break; |
|
452 | 458 |
} |
453 | 459 |
|
454 | 460 |
return; |
... | ... | |
500 | 506 |
|
501 | 507 |
chprintf((BaseSequentialStream*) &SD1, "\n"); |
502 | 508 |
chprintf((BaseSequentialStream*) &SD1, BOARD_NAME " " BOARD_VERSION "\n"); |
503 |
if (*((uint32_t*)(BL_CALLBACK_TABLE_ADDR)) == BL_MAGIC_NUMBER) { |
|
504 |
chprintf((BaseSequentialStream*) &SD1, "Bootloader %u.%u.%u\n", |
|
505 |
*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))), |
|
506 |
*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (2*4))), |
|
507 |
*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (3*4)))); |
|
508 |
} else { |
|
509 |
chprintf((BaseSequentialStream*) &SD1, "Bootloader deprecated\n"); |
|
509 |
switch (*((uint32_t*)(BL_CALLBACK_TABLE_ADDR))) { |
|
510 |
case (('A'<<24) | ('-'<<16) | ('B'<<8) | ('L'<<0)): |
|
511 |
chprintf((BaseSequentialStream*) &SD1, "Bootloader %u.%u.%u\n", |
|
512 |
((blVersion_t*)(BL_CALLBACK_TABLE_ADDR + (1*4)))->major, |
|
513 |
((blVersion_t*)(BL_CALLBACK_TABLE_ADDR + (1*4)))->minor, |
|
514 |
((blVersion_t*)(BL_CALLBACK_TABLE_ADDR + (1*4)))->patch); |
|
515 |
break; |
|
516 |
|
|
517 |
case BL_MAGIC_NUMBER: |
|
518 |
chprintf((BaseSequentialStream*) &SD1, "Bootloader %u.%u.%u\n", |
|
519 |
*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))), |
|
520 |
*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))), |
|
521 |
*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4)))); |
|
522 |
break; |
|
523 |
|
|
524 |
default: |
|
525 |
chprintf((BaseSequentialStream*) &SD1, "Bootloader incompatible\n"); |
|
526 |
break; |
|
510 | 527 |
} |
511 | 528 |
chprintf((BaseSequentialStream*) &SD1, "ChibiOS " CH_KERNEL_VERSION "\n"); |
512 | 529 |
// make sure that the info text is completetly printed |
... | ... | |
572 | 589 |
// testFade(); |
573 | 590 |
// testBrightness(); |
574 | 591 |
if (shutdown_now != SHUTDOWN_NONE) { |
575 |
if (*((uint32_t*)(BL_CALLBACK_TABLE_ADDR)) != BL_MAGIC_NUMBER) {
|
|
592 |
if ((*((uint32_t*)(BL_CALLBACK_TABLE_ADDR)) != (('A'<<24) | ('-'<<16) | ('B'<<8) | ('L'<<0))) && (*((uint32_t*)(BL_CALLBACK_TABLE_ADDR)) != BL_MAGIC_NUMBER)) {
|
|
576 | 593 |
chprintf((BaseSequentialStream*) &SD1, "ERROR: unable to shut down (bootloader deprecated).\n"); |
577 | 594 |
shutdown_now = SHUTDOWN_NONE; |
578 | 595 |
} else { |
579 | 596 |
uint32_t blCallbackPtrAddr = BL_CALLBACK_TABLE_ADDR; |
580 |
if (*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))) == 0 && *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (2*4))) == 2) { |
|
597 |
// handle bootloader version 0.2.x |
|
598 |
if ((*((uint32_t*)(BL_CALLBACK_TABLE_ADDR)) == BL_MAGIC_NUMBER) && |
|
599 |
(*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))) == 0 && *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (2*4))) == 2)) { |
|
581 | 600 |
switch (shutdown_now) { |
582 | 601 |
case SHUTDOWN_TRANSPORTATION: |
583 | 602 |
blCallbackPtrAddr += 6 * 4; |
... | ... | |
596 | 615 |
blCallbackPtrAddr = 0; |
597 | 616 |
break; |
598 | 617 |
} |
599 |
} else if (*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))) == 0 && *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (2*4))) == 3) { |
|
618 |
} |
|
619 |
// handle bootloader version 0.3.x |
|
620 |
else if ((*((uint32_t*)(BL_CALLBACK_TABLE_ADDR)) == BL_MAGIC_NUMBER) && |
|
621 |
(*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))) == 0 && *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (2*4))) == 3)) { |
|
622 |
switch (shutdown_now) { |
|
623 |
case SHUTDOWN_TRANSPORTATION: |
|
624 |
blCallbackPtrAddr += 6 * 4; |
|
625 |
break; |
|
626 |
case SHUTDOWN_DEEPSLEEP: |
|
627 |
blCallbackPtrAddr += 5 * 4; |
|
628 |
break; |
|
629 |
case SHUTDOWN_HIBERNATE: |
|
630 |
blCallbackPtrAddr += 4 * 4; |
|
631 |
break; |
|
632 |
case SHUTDOWN_RESTART: |
|
633 |
blCallbackPtrAddr += 7 * 4; |
|
634 |
break; |
|
635 |
case SHUTDOWN_HANDLE_REQUEST: |
|
636 |
blCallbackPtrAddr += 8 * 4; |
|
637 |
break; |
|
638 |
default: |
|
639 |
blCallbackPtrAddr = 0; |
|
640 |
break; |
|
641 |
} |
|
642 |
} |
|
643 |
// handle bootloader version 1.0.x |
|
644 |
else if ((*((uint32_t*)(BL_CALLBACK_TABLE_ADDR)) == (('A'<<24) | ('-'<<16) | ('B'<<8) | ('L'<<0))) && |
|
645 |
((blVersion_t*)(BL_CALLBACK_TABLE_ADDR + (1*4)))->major == 1 && ((blVersion_t*)(BL_CALLBACK_TABLE_ADDR + (1*4)))->minor == 0) { |
|
600 | 646 |
switch (shutdown_now) { |
601 | 647 |
case SHUTDOWN_TRANSPORTATION: |
602 | 648 |
blCallbackPtrAddr += 6 * 4; |
... | ... | |
620 | 666 |
} |
621 | 667 |
|
622 | 668 |
void (*blCallback)(void) = NULL; |
623 |
if (blCallbackPtrAddr) { |
|
669 |
if (blCallbackPtrAddr > BL_CALLBACK_TABLE_ADDR) {
|
|
624 | 670 |
blCallback = (void (*)(void))(*((uint32_t*)blCallbackPtrAddr)); |
625 | 671 |
|
626 | 672 |
if (!blCallback) { |
... | ... | |
640 | 686 |
} |
641 | 687 |
|
642 | 688 |
} else { |
643 |
chprintf((BaseSequentialStream*)&SD1, "ERROR: invalid shutdown requested (%u).\n", shutdown_now); |
|
689 |
chprintf((BaseSequentialStream*) &SD1, "ERROR: invalid shutdown requested (%u).\n", shutdown_now);
|
|
644 | 690 |
shutdown_now = SHUTDOWN_NONE; |
645 | 691 |
} |
646 | 692 |
} |
devices/PowerManagement/main.cpp | ||
---|---|---|
45 | 45 |
|
46 | 46 |
Global global; |
47 | 47 |
|
48 |
struct blVersion_t { |
|
49 |
const uint8_t identifier; |
|
50 |
const uint8_t major; |
|
51 |
const uint8_t minor; |
|
52 |
const uint8_t patch; |
|
53 |
} __attribute__((packed)); |
|
54 |
|
|
48 | 55 |
void shutdownTimeoutISR(void *arg) { |
49 | 56 |
|
50 | 57 |
(void) arg; |
... | ... | |
828 | 835 |
|
829 | 836 |
void shellRequestGetBootloaderInfo(BaseSequentialStream* chp, int argc, char *argv[]) { |
830 | 837 |
// check the magic number |
831 |
if (*((uint32_t*)(BL_CALLBACK_TABLE_ADDR)) == BL_MAGIC_NUMBER) { |
|
832 |
chprintf(chp, "Bootloader version: %u.%u.%u\n", |
|
833 |
*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))), |
|
834 |
*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (2*4))), |
|
835 |
*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (3*4)))); |
|
836 |
chprintf(chp, "Callback functions:\n"); |
|
837 |
if (*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))) == 0 && *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (2*4))) == 2) { |
|
838 |
chprintf(chp, "\thibernate: %s\n", *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (4*4))) ? "available" : "unsupported"); |
|
839 |
chprintf(chp, "\tdeepsleep: %s\n", *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (5*4))) ? "available" : "unsupported"); |
|
840 |
chprintf(chp, "\ttransportation: %s\n", *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (6*4))) ? "available" : "unsupported"); |
|
841 |
chprintf(chp, "\trestart: %s\n", *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (10*4))) ? "available" : "unsupported"); |
|
842 |
} else if (*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))) == 0 && *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (2*4))) == 3) { |
|
843 |
chprintf(chp, "\thibernate: %s\n", *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (4*4))) ? "available" : "unsupported"); |
|
844 |
chprintf(chp, "\tdeepsleep: %s\n", *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (5*4))) ? "available" : "unsupported"); |
|
845 |
chprintf(chp, "\ttransportation: %s\n", *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (6*4))) ? "available" : "unsupported"); |
|
846 |
chprintf(chp, "\trestart: %s\n", *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (7*4))) ? "available" : "unsupported"); |
|
847 |
chprintf(chp, "\thandle request: %s\n", *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (8*4))) ? "available" : "unsupported"); |
|
848 |
} |
|
849 |
} else { |
|
850 |
chprintf((BaseSequentialStream*) &SD1, "Bootloader deprecated\n"); |
|
838 |
switch (*((uint32_t*)(BL_CALLBACK_TABLE_ADDR))) { |
|
839 |
case (('A'<<24) | ('-'<<16) | ('B'<<8) | ('L'<<0)): |
|
840 |
chprintf((BaseSequentialStream*) &SD1, "Bootloader %u.%u.%u\n", |
|
841 |
((blVersion_t*)(BL_CALLBACK_TABLE_ADDR + (1*4)))->major, |
|
842 |
((blVersion_t*)(BL_CALLBACK_TABLE_ADDR + (1*4)))->minor, |
|
843 |
((blVersion_t*)(BL_CALLBACK_TABLE_ADDR + (1*4)))->patch); |
|
844 |
break; |
|
845 |
|
|
846 |
case BL_MAGIC_NUMBER: |
|
847 |
chprintf((BaseSequentialStream*) &SD1, "Bootloader %u.%u.%u\n", |
|
848 |
*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))), |
|
849 |
*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))), |
|
850 |
*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4)))); |
|
851 |
break; |
|
852 |
|
|
853 |
default: |
|
854 |
chprintf((BaseSequentialStream*) &SD1, "Bootloader incompatible\n"); |
|
855 |
break; |
|
851 | 856 |
} |
852 | 857 |
|
853 | 858 |
return; |
... | ... | |
951 | 956 |
|
952 | 957 |
chprintf((BaseSequentialStream*) &SD1, "\n"); |
953 | 958 |
chprintf((BaseSequentialStream*) &SD1, BOARD_NAME " " BOARD_VERSION "\n"); |
954 |
if (*((uint32_t*)(BL_CALLBACK_TABLE_ADDR)) == BL_MAGIC_NUMBER) { |
|
955 |
chprintf((BaseSequentialStream*) &SD1, "Bootloader %u.%u.%u\n", |
|
956 |
*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))), |
|
957 |
*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (2*4))), |
|
958 |
*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (3*4)))); |
|
959 |
} else { |
|
960 |
chprintf((BaseSequentialStream*) &SD1, "Bootloader deprecated\n"); |
|
959 |
switch (*((uint32_t*)(BL_CALLBACK_TABLE_ADDR))) { |
|
960 |
case (('A'<<24) | ('-'<<16) | ('B'<<8) | ('L'<<0)): |
|
961 |
chprintf((BaseSequentialStream*) &SD1, "Bootloader %u.%u.%u\n", |
|
962 |
((blVersion_t*)(BL_CALLBACK_TABLE_ADDR + (1*4)))->major, |
|
963 |
((blVersion_t*)(BL_CALLBACK_TABLE_ADDR + (1*4)))->minor, |
|
964 |
((blVersion_t*)(BL_CALLBACK_TABLE_ADDR + (1*4)))->patch); |
|
965 |
break; |
|
966 |
|
|
967 |
case BL_MAGIC_NUMBER: |
|
968 |
chprintf((BaseSequentialStream*) &SD1, "Bootloader %u.%u.%u\n", |
|
969 |
*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))), |
|
970 |
*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))), |
|
971 |
*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4)))); |
|
972 |
break; |
|
973 |
|
|
974 |
default: |
|
975 |
chprintf((BaseSequentialStream*) &SD1, "Bootloader incompatible\n"); |
|
976 |
break; |
|
961 | 977 |
} |
962 | 978 |
chprintf((BaseSequentialStream*) &SD1, "ChibiOS " CH_KERNEL_VERSION "\n"); |
963 | 979 |
// make sure that the info text is completetly printed |
... | ... | |
1084 | 1100 |
* next wall or something like that. |
1085 | 1101 |
*/ |
1086 | 1102 |
if (shutdown_now != SHUTDOWN_NONE) { |
1087 |
if (*((uint32_t*)(BL_CALLBACK_TABLE_ADDR)) != BL_MAGIC_NUMBER) {
|
|
1103 |
if ((*((uint32_t*)(BL_CALLBACK_TABLE_ADDR)) != (('A'<<24) | ('-'<<16) | ('B'<<8) | ('L'<<0))) && (*((uint32_t*)(BL_CALLBACK_TABLE_ADDR)) != BL_MAGIC_NUMBER)) {
|
|
1088 | 1104 |
chprintf((BaseSequentialStream*) &SD1, "ERROR: unable to shut down (bootloader deprecated).\n"); |
1089 | 1105 |
shutdown_now = SHUTDOWN_NONE; |
1090 | 1106 |
} else { |
1091 | 1107 |
uint32_t blCallbackPtrAddr = BL_CALLBACK_TABLE_ADDR; |
1092 |
if (*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))) == 0 && *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (2*4))) == 2) { |
|
1108 |
// handle bootloader version 0.2.x |
|
1109 |
if ((*((uint32_t*)(BL_CALLBACK_TABLE_ADDR)) == BL_MAGIC_NUMBER) && |
|
1110 |
(*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))) == 0 && *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (2*4))) == 2)) { |
|
1093 | 1111 |
switch (shutdown_now) { |
1094 | 1112 |
case SHUTDOWN_TRANSPORTATION: |
1095 | 1113 |
blCallbackPtrAddr += 6 * 4; |
... | ... | |
1108 | 1126 |
blCallbackPtrAddr = 0; |
1109 | 1127 |
break; |
1110 | 1128 |
} |
1111 |
} else if (*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))) == 0 && *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (2*4))) == 3) { |
|
1129 |
} |
|
1130 |
// handle bootloader version 0.3.x |
|
1131 |
else if ((*((uint32_t*)(BL_CALLBACK_TABLE_ADDR)) == BL_MAGIC_NUMBER) && |
|
1132 |
(*((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (1*4))) == 0 && *((uint32_t*)(BL_CALLBACK_TABLE_ADDR + (2*4))) == 3)) { |
|
1133 |
switch (shutdown_now) { |
|
1134 |
case SHUTDOWN_TRANSPORTATION: |
|
1135 |
blCallbackPtrAddr += 6 * 4; |
|
1136 |
break; |
|
1137 |
case SHUTDOWN_DEEPSLEEP: |
|
1138 |
blCallbackPtrAddr += 5 * 4; |
|
1139 |
break; |
|
1140 |
case SHUTDOWN_HIBERNATE: |
|
1141 |
blCallbackPtrAddr += 4 * 4; |
|
1142 |
break; |
|
1143 |
case SHUTDOWN_RESTART: |
|
1144 |
blCallbackPtrAddr += 7 * 4; |
|
1145 |
break; |
|
1146 |
case SHUTDOWN_HANDLE_REQUEST: |
|
1147 |
blCallbackPtrAddr += 8 * 4; |
|
1148 |
break; |
|
1149 |
default: |
|
1150 |
blCallbackPtrAddr = 0; |
|
1151 |
break; |
|
1152 |
} |
|
1153 |
} |
|
1154 |
// handle bootloader version 1.0.x |
|
1155 |
else if ((*((uint32_t*)(BL_CALLBACK_TABLE_ADDR)) == (('A'<<24) | ('-'<<16) | ('B'<<8) | ('L'<<0))) && |
|
1156 |
((blVersion_t*)(BL_CALLBACK_TABLE_ADDR + (1*4)))->major == 1 && ((blVersion_t*)(BL_CALLBACK_TABLE_ADDR + (1*4)))->minor == 0) { |
|
1112 | 1157 |
switch (shutdown_now) { |
1113 | 1158 |
case SHUTDOWN_TRANSPORTATION: |
1114 | 1159 |
blCallbackPtrAddr += 6 * 4; |
... | ... | |
1132 | 1177 |
} |
1133 | 1178 |
|
1134 | 1179 |
void (*blCallback)(void) = NULL; |
1135 |
if (blCallbackPtrAddr) { |
|
1180 |
if (blCallbackPtrAddr > BL_CALLBACK_TABLE_ADDR) {
|
|
1136 | 1181 |
blCallback = (void (*)(void))(*((uint32_t*)blCallbackPtrAddr)); |
1137 | 1182 |
|
1138 | 1183 |
if (!blCallback) { |
Also available in: Unified diff