hal_ota.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /******************************************************************************
  2. Filename: hal_ota.h
  3. Revised: $Date: 2010-11-18 08:22:50 -0800 (Thu, 18 Nov 2010) $
  4. Revision: $Revision: 24438 $
  5. Description: This module defines optionally-compiled Boot Code parameters
  6. for the CC253x.
  7. Copyright 2010 Texas Instruments Incorporated. All rights reserved.
  8. IMPORTANT: Your use of this Software is limited to those specific rights
  9. granted under the terms of a software license agreement between the user
  10. who downloaded the software, his/her employer (which must be your employer)
  11. and Texas Instruments Incorporated (the "License"). You may not use this
  12. Software unless you agree to abide by the terms of the License. The License
  13. limits your use, and you acknowledge, that the Software may not be modified,
  14. copied or distributed unless embedded on a Texas Instruments microcontroller
  15. or used solely and exclusively in conjunction with a Texas Instruments radio
  16. frequency transceiver, which is integrated into your product. Other than for
  17. the foregoing purpose, you may not use, reproduce, copy, prepare derivative
  18. works of, modify, distribute, perform, display or sell this Software and/or
  19. its documentation for any purpose.
  20. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  21. PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  22. INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  23. NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  24. TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
  25. NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  26. LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
  27. INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
  28. OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
  29. OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  30. (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
  31. Should you have any questions regarding your right to use this Software,
  32. contact Texas Instruments Incorporated at www.TI.com.
  33. ******************************************************************************/
  34. #ifndef HAL_OTA_H
  35. #define HAL_OTA_H
  36. /******************************************************************************
  37. * INCLUDES
  38. */
  39. #include "hal_board_cfg.h"
  40. #include "hal_types.h"
  41. /******************************************************************************
  42. * MACROS
  43. */
  44. #if !defined HAL_OTA_BOOT_CODE
  45. #define HAL_OTA_BOOT_CODE FALSE
  46. #endif
  47. // MSP430 needs to explicitly pack OTA data structures - 8051 is automatic with byte alignment.
  48. #define PACK_1
  49. /******************************************************************************
  50. * CONSTANTS
  51. */
  52. // Placement controlled by ota.xcl.
  53. #define HAL_OTA_RC_START 0x0800
  54. #define HAL_OTA_CRC_ADDR 0x0888
  55. #define HAL_OTA_CRC_OSET (HAL_OTA_CRC_ADDR - HAL_OTA_RC_START)
  56. /* Note that corresponding changes must be made to ota.xcl when changing the source of Xtra-NV.
  57. * When using internal flash for XNV, (HAL_OTA_BOOT_PG_CNT + HAL_NV_PAGE_CNT) must be even.
  58. */
  59. #define HAL_OTA_XNV_IS_INT FALSE
  60. #define HAL_OTA_XNV_IS_SPI !HAL_OTA_XNV_IS_INT
  61. /* The ota/ota-boot.xcl files only need 1 page of boot code (located on the first flash page),
  62. * but the Lock Bits Page is lost with OTA since it is not programmable.
  63. * So discard it here by faking that boot needs 2 pages.
  64. */
  65. #define HAL_OTA_BOOT_PG_CNT 2
  66. /* To reduce the binary image size due to padding un-used code space, reduce HAL_OTA_DL_SIZE
  67. * to the minimum required for your Application and make the corresponding changes to ota_app.xcl.
  68. * This size must be an even multiple of HAL_FLASH_PAGE_SIZE.
  69. */
  70. #if HAL_OTA_XNV_IS_SPI && !defined HAL_BOARD_CC2530EB_REV13
  71. #define HAL_OTA_DL_MAX 0x40000
  72. #define HAL_OTA_DL_SIZE (0x40000 - ((HAL_NV_PAGE_CNT+HAL_OTA_BOOT_PG_CNT)*HAL_FLASH_PAGE_SIZE))
  73. #define HAL_OTA_DL_OSET 0x0 // Configurable offset into an external NV.
  74. #else
  75. #define HAL_OTA_DL_MAX (0x40000 - ((HAL_NV_PAGE_CNT+HAL_OTA_BOOT_PG_CNT)*HAL_FLASH_PAGE_SIZE))
  76. #define HAL_OTA_DL_SIZE (HAL_OTA_DL_MAX / 2)
  77. #define HAL_OTA_DL_OSET (HAL_OTA_DL_MAX / 2)
  78. #endif
  79. #define PREAMBLE_OFFSET 0x8C
  80. /*********************************************************************
  81. * TYPEDEFS
  82. */
  83. typedef enum {
  84. HAL_OTA_RC, /* Run code / active image. */
  85. HAL_OTA_DL /* Downloaded code to be activated later. */
  86. } image_t;
  87. typedef struct {
  88. uint16 crc;
  89. uint16 crc_shadow;
  90. } otaCrc_t;
  91. typedef struct {
  92. uint32 programLength;
  93. uint16 manufacturerId;
  94. uint16 imageType;
  95. uint32 imageVersion;
  96. } preamble_t;
  97. /*********************************************************************
  98. * FUNCTIONS
  99. */
  100. uint8 HalOTAChkDL(uint8 dlImagePreambleOffset);
  101. void HalOTAInvRC(void);
  102. uint32 HalOTAAvail(void);
  103. void HalOTARead(uint32 oset, uint8 *pBuf, uint16 len, image_t type);
  104. void HalOTAWrite(uint32 oset, uint8 *pBuf, uint16 len, image_t type);
  105. #endif