bl.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /****************************************************************************
  2. *
  3. * Copyright (c) 2012-2014 PX4 Development Team. All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in
  13. * the documentation and/or other materials provided with the
  14. * distribution.
  15. * 3. Neither the name PX4 nor the names of its contributors may be
  16. * used to endorse or promote products derived from this software
  17. * without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  23. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  27. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  28. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  29. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  30. * POSSIBILITY OF SUCH DAMAGE.
  31. *
  32. ****************************************************************************/
  33. /**
  34. * @file bl.h
  35. *
  36. * Common bootloader definitions.
  37. */
  38. #pragma once
  39. /*****************************************************************************
  40. * Generic bootloader functions.
  41. */
  42. /* enum for whether bootloading via USB or USART */
  43. enum {
  44. NONE,
  45. USART,
  46. USB
  47. };
  48. /* board info forwarded from board-specific code to booloader */
  49. struct boardinfo {
  50. uint32_t board_type;
  51. uint32_t board_rev;
  52. uint32_t fw_size;
  53. uint32_t systick_mhz; /* systick input clock */
  54. } __attribute__((packed));
  55. extern struct boardinfo board_info;
  56. extern void jump_to_app(void);
  57. extern void bootloader(unsigned timeout);
  58. extern void delay(unsigned msec);
  59. #define BL_WAIT_MAGIC 0x19710317 /* magic number in PWR regs to wait in bootloader */
  60. /* generic timers */
  61. #define NTIMERS 4
  62. #define TIMER_BL_WAIT 0
  63. #define TIMER_CIN 1
  64. #define TIMER_LED 2
  65. #define TIMER_DELAY 3
  66. extern volatile unsigned timer[NTIMERS]; /* each timer decrements every millisecond if > 0 */
  67. /* generic receive buffer for async reads */
  68. extern void buf_put(uint8_t b);
  69. extern int buf_get(void);
  70. /*****************************************************************************
  71. * Chip/board functions.
  72. */
  73. /* LEDs */
  74. #define LED_ACTIVITY 1
  75. #define LED_BOOTLOADER 2
  76. #ifdef BOOT_DELAY_ADDRESS
  77. # define BOOT_DELAY_SIGNATURE1 0x92c2ecff
  78. # define BOOT_DELAY_SIGNATURE2 0xc5057d5d
  79. # define BOOT_DELAY_MAX 30
  80. #endif
  81. #define MAX_DES_LENGTH 20
  82. #define arraySize(a) (sizeof((a))/sizeof(((a)[0])))
  83. extern void led_on(unsigned led);
  84. extern void led_off(unsigned led);
  85. extern void led_toggle(unsigned led);
  86. /* flash helpers from main_*.c */
  87. extern void board_deinit(void);
  88. extern uint32_t board_get_devices(void);
  89. extern void clock_deinit(void);
  90. extern uint32_t flash_func_sector_size(unsigned sector);
  91. extern void flash_func_erase_sector(unsigned sector);
  92. extern void flash_func_write_word(uint32_t address, uint32_t word);
  93. extern uint32_t flash_func_read_word(uint32_t address);
  94. extern uint32_t flash_func_read_otp(uint32_t address);
  95. extern uint32_t flash_func_read_sn(uint32_t address);
  96. extern uint32_t get_mcu_id(void);
  97. int get_mcu_desc(int max, uint8_t *revstr);
  98. extern int check_silicon(void);
  99. /*****************************************************************************
  100. * Interface in/output.
  101. */
  102. extern void cinit(void *config, uint8_t interface);
  103. extern void cfini(void);
  104. extern int cin(uint32_t devices);
  105. extern void cout(uint8_t *buf, unsigned len);