Revision 10687985 devices/DiWheelDrive/main.cpp

View differences:

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) {

Also available in: Unified diff