my fork
inc/bluenrg_utils.h@4:987b201ec4b1, 2015-04-08 (annotated)
- Committer:
- filartrix
- Date:
- Wed Apr 08 14:17:20 2015 +0000
- Revision:
- 4:987b201ec4b1
first
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
filartrix | 4:987b201ec4b1 | 1 | /******************** (C) COPYRIGHT 2013 STMicroelectronics ******************** |
filartrix | 4:987b201ec4b1 | 2 | * File Name : bluenrg_utils.h |
filartrix | 4:987b201ec4b1 | 3 | * Author : AMS - AAS, RF Application Team |
filartrix | 4:987b201ec4b1 | 4 | * Version : V1.0.0 |
filartrix | 4:987b201ec4b1 | 5 | * Date : 21-March-2014 |
filartrix | 4:987b201ec4b1 | 6 | * Description : Header file for BlueNRG utility functions |
filartrix | 4:987b201ec4b1 | 7 | ******************************************************************************** |
filartrix | 4:987b201ec4b1 | 8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS |
filartrix | 4:987b201ec4b1 | 9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. |
filartrix | 4:987b201ec4b1 | 10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, |
filartrix | 4:987b201ec4b1 | 11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE |
filartrix | 4:987b201ec4b1 | 12 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING |
filartrix | 4:987b201ec4b1 | 13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. |
filartrix | 4:987b201ec4b1 | 14 | *******************************************************************************/ |
filartrix | 4:987b201ec4b1 | 15 | /** |
filartrix | 4:987b201ec4b1 | 16 | * @file bluenrg_utils.h |
filartrix | 4:987b201ec4b1 | 17 | * @brief BlueNRG IFR updater & BlueNRG stack updater utility APIs description |
filartrix | 4:987b201ec4b1 | 18 | * |
filartrix | 4:987b201ec4b1 | 19 | * <!-- Copyright 2014 by STMicroelectronics. All rights reserved. *80*--> |
filartrix | 4:987b201ec4b1 | 20 | **/ |
filartrix | 4:987b201ec4b1 | 21 | /* Define to prevent recursive inclusion -------------------------------------*/ |
filartrix | 4:987b201ec4b1 | 22 | #ifndef __BLUENRG_UTILS_H |
filartrix | 4:987b201ec4b1 | 23 | #define __BLUENRG_UTILS_H |
filartrix | 4:987b201ec4b1 | 24 | |
filartrix | 4:987b201ec4b1 | 25 | #ifdef __cplusplus |
filartrix | 4:987b201ec4b1 | 26 | extern "C" { |
filartrix | 4:987b201ec4b1 | 27 | #endif |
filartrix | 4:987b201ec4b1 | 28 | |
filartrix | 4:987b201ec4b1 | 29 | /* Includes ------------------------------------------------------------------*/ |
filartrix | 4:987b201ec4b1 | 30 | #include "hal_types.h" |
filartrix | 4:987b201ec4b1 | 31 | #include "compiler.h" |
filartrix | 4:987b201ec4b1 | 32 | |
filartrix | 4:987b201ec4b1 | 33 | /* Exported types ------------------------------------------------------------*/ |
filartrix | 4:987b201ec4b1 | 34 | typedef struct{ |
filartrix | 4:987b201ec4b1 | 35 | uint8_t stack_mode; |
filartrix | 4:987b201ec4b1 | 36 | uint8_t day; |
filartrix | 4:987b201ec4b1 | 37 | uint8_t month; |
filartrix | 4:987b201ec4b1 | 38 | uint8_t year; |
filartrix | 4:987b201ec4b1 | 39 | uint16_t slave_sca_ppm; |
filartrix | 4:987b201ec4b1 | 40 | uint8_t master_sca; |
filartrix | 4:987b201ec4b1 | 41 | uint16_t hs_startup_time; /* In system time units*/ |
filartrix | 4:987b201ec4b1 | 42 | } IFR_config2_TypeDef; |
filartrix | 4:987b201ec4b1 | 43 | |
filartrix | 4:987b201ec4b1 | 44 | /** |
filartrix | 4:987b201ec4b1 | 45 | * Structure inside IFR for configuration options. |
filartrix | 4:987b201ec4b1 | 46 | */ |
filartrix | 4:987b201ec4b1 | 47 | typedef __packed struct{ |
filartrix | 4:987b201ec4b1 | 48 | uint8_t cold_ana_act_config_table[64]; |
filartrix | 4:987b201ec4b1 | 49 | uint8_t hot_ana_config_table[64]; |
filartrix | 4:987b201ec4b1 | 50 | uint8_t stack_mode; |
filartrix | 4:987b201ec4b1 | 51 | uint8_t rsrvd1[3]; |
filartrix | 4:987b201ec4b1 | 52 | uint32_t rsrvd2[4]; |
filartrix | 4:987b201ec4b1 | 53 | uint32_t ls_crystal_period; |
filartrix | 4:987b201ec4b1 | 54 | uint32_t ls_crystal_freq; |
filartrix | 4:987b201ec4b1 | 55 | uint16_t slave_sca_ppm; |
filartrix | 4:987b201ec4b1 | 56 | uint8_t master_sca; |
filartrix | 4:987b201ec4b1 | 57 | uint8_t rsrvd3; |
filartrix | 4:987b201ec4b1 | 58 | uint16_t hs_startup_time; /* In system time units*/ |
filartrix | 4:987b201ec4b1 | 59 | uint8_t crystal_par; |
filartrix | 4:987b201ec4b1 | 60 | uint8_t hot_cold_ta; |
filartrix | 4:987b201ec4b1 | 61 | uint8_t uid[3]; |
filartrix | 4:987b201ec4b1 | 62 | uint8_t rf_power; |
filartrix | 4:987b201ec4b1 | 63 | uint8_t rsrvd4; |
filartrix | 4:987b201ec4b1 | 64 | uint8_t year; |
filartrix | 4:987b201ec4b1 | 65 | uint8_t month; |
filartrix | 4:987b201ec4b1 | 66 | uint8_t day; |
filartrix | 4:987b201ec4b1 | 67 | uint32_t rsrvd5[5]; |
filartrix | 4:987b201ec4b1 | 68 | } PACKED IFR_config_TypeDef; |
filartrix | 4:987b201ec4b1 | 69 | |
filartrix | 4:987b201ec4b1 | 70 | /* Exported constants --------------------------------------------------------*/ |
filartrix | 4:987b201ec4b1 | 71 | extern const IFR_config_TypeDef IFR_config; |
filartrix | 4:987b201ec4b1 | 72 | |
filartrix | 4:987b201ec4b1 | 73 | /* Exported macros -----------------------------------------------------------*/ |
filartrix | 4:987b201ec4b1 | 74 | #define FROM_US_TO_SYS_TIME(us) ((uint16_t)(us/2.4414)) |
filartrix | 4:987b201ec4b1 | 75 | #define FROM_SYS_TIME_TO_US(sys) ((uint16_t)(sys*2.4414)) |
filartrix | 4:987b201ec4b1 | 76 | |
filartrix | 4:987b201ec4b1 | 77 | /* Convert 2 digit BCD number to an integer */ |
filartrix | 4:987b201ec4b1 | 78 | #define BCD_TO_INT(bcd) ((bcd & 0xF) + ((bcd & 0xF0) >> 4)*10) |
filartrix | 4:987b201ec4b1 | 79 | |
filartrix | 4:987b201ec4b1 | 80 | /* Convert 2 digit number to a BCD number */ |
filartrix | 4:987b201ec4b1 | 81 | #define INT_TO_BCD(n) ((((uint8_t)n/10)<<4) + (uint8_t)n%10) |
filartrix | 4:987b201ec4b1 | 82 | |
filartrix | 4:987b201ec4b1 | 83 | /** |
filartrix | 4:987b201ec4b1 | 84 | * Return values |
filartrix | 4:987b201ec4b1 | 85 | */ |
filartrix | 4:987b201ec4b1 | 86 | #define BLE_UTIL_SUCCESS 0 |
filartrix | 4:987b201ec4b1 | 87 | #define BLE_UTIL_UNSUPPORTED_VERSION 1 |
filartrix | 4:987b201ec4b1 | 88 | #define BLE_UTIL_WRONG_IMAGE_SIZE 2 |
filartrix | 4:987b201ec4b1 | 89 | #define BLE_UTIL_ACI_ERROR 3 |
filartrix | 4:987b201ec4b1 | 90 | #define BLE_UTIL_CRC_ERROR 4 |
filartrix | 4:987b201ec4b1 | 91 | #define BLE_UTIL_PARSE_ERROR 5 |
filartrix | 4:987b201ec4b1 | 92 | #define BLE_UTIL_WRONG_VERIFY 6 |
filartrix | 4:987b201ec4b1 | 93 | |
filartrix | 4:987b201ec4b1 | 94 | /* Exported functions ------------------------------------------------------- */ |
filartrix | 4:987b201ec4b1 | 95 | /** |
filartrix | 4:987b201ec4b1 | 96 | * @brief Flash a new firmware using internal bootloader. |
filartrix | 4:987b201ec4b1 | 97 | * @param fw_image Pointer to the firmware image (raw binary data, |
filartrix | 4:987b201ec4b1 | 98 | * little-endian). |
filartrix | 4:987b201ec4b1 | 99 | * @param fw_size Size of the firmware image. |
filartrix | 4:987b201ec4b1 | 100 | * @param skip_bootloader_verif If true, verification of the first sector, |
filartrix | 4:987b201ec4b1 | 101 | * that contains the bootloader, will not be executed. |
filartrix | 4:987b201ec4b1 | 102 | * @note this is useful when a new image with a new bootloader must be |
filartrix | 4:987b201ec4b1 | 103 | * programmed. |
filartrix | 4:987b201ec4b1 | 104 | * @retval int It returns 0 if successful, or a number not equal to 0 in |
filartrix | 4:987b201ec4b1 | 105 | case of error (ACI_ERROR, UNSUPPORTED_VERSION, |
filartrix | 4:987b201ec4b1 | 106 | * WRONG_IMAGE_SIZE, CRC_ERROR) |
filartrix | 4:987b201ec4b1 | 107 | */ |
filartrix | 4:987b201ec4b1 | 108 | int program_device(const uint8_t *fw_image, uint32_t fw_size, uint8_t skip_bootloader_verif); |
filartrix | 4:987b201ec4b1 | 109 | |
filartrix | 4:987b201ec4b1 | 110 | /** |
filartrix | 4:987b201ec4b1 | 111 | * @brief Read raw data from IFR (3 64-bytes blocks). |
filartrix | 4:987b201ec4b1 | 112 | * @param data Pointer to the buffer that will contain the read data. |
filartrix | 4:987b201ec4b1 | 113 | * Its size must be 192 bytes. This data can be parsed by |
filartrix | 4:987b201ec4b1 | 114 | * parse_IFR_data_config(). |
filartrix | 4:987b201ec4b1 | 115 | * @retval int It returns 0 if successful, or a number not equal to 0 in |
filartrix | 4:987b201ec4b1 | 116 | case of error (ACI_ERROR, UNSUPPORTED_VERSION) |
filartrix | 4:987b201ec4b1 | 117 | */ |
filartrix | 4:987b201ec4b1 | 118 | int read_IFR(uint8_t data[192]); |
filartrix | 4:987b201ec4b1 | 119 | |
filartrix | 4:987b201ec4b1 | 120 | /** |
filartrix | 4:987b201ec4b1 | 121 | * @brief Verify raw data from IFR (3 64-bytes blocks). |
filartrix | 4:987b201ec4b1 | 122 | * @param ifr_data Pointer to the buffer that will contain the data to verify. |
filartrix | 4:987b201ec4b1 | 123 | * Its size must be 192 bytes. |
filartrix | 4:987b201ec4b1 | 124 | * @retval int It returns 0 if successful, or a number not equal to 0 in |
filartrix | 4:987b201ec4b1 | 125 | case of error (ACI_ERROR, BLE_UTIL_WRONG_VERIFY) |
filartrix | 4:987b201ec4b1 | 126 | */ |
filartrix | 4:987b201ec4b1 | 127 | uint8_t verify_IFR(const IFR_config_TypeDef *ifr_data); |
filartrix | 4:987b201ec4b1 | 128 | |
filartrix | 4:987b201ec4b1 | 129 | /** |
filartrix | 4:987b201ec4b1 | 130 | * @brief Program raw data to IFR (3 64-bytes blocks). |
filartrix | 4:987b201ec4b1 | 131 | * @param ifr_image Pointer to the buffer that will contain the data to program. |
filartrix | 4:987b201ec4b1 | 132 | * Its size must be 192 bytes. |
filartrix | 4:987b201ec4b1 | 133 | * @retval int It returns 0 if successful |
filartrix | 4:987b201ec4b1 | 134 | */ |
filartrix | 4:987b201ec4b1 | 135 | int program_IFR(const IFR_config_TypeDef *ifr_image); |
filartrix | 4:987b201ec4b1 | 136 | |
filartrix | 4:987b201ec4b1 | 137 | /** |
filartrix | 4:987b201ec4b1 | 138 | * @brief Parse IFR raw data. |
filartrix | 4:987b201ec4b1 | 139 | * @param data Pointer to the raw data: last 64 bytes read from IFR sector. |
filartrix | 4:987b201ec4b1 | 140 | * @param IFR_config Data structure that will be filled with parsed data. |
filartrix | 4:987b201ec4b1 | 141 | * @retval None |
filartrix | 4:987b201ec4b1 | 142 | */ |
filartrix | 4:987b201ec4b1 | 143 | void parse_IFR_data_config(const uint8_t data[64], IFR_config2_TypeDef *IFR_config); |
filartrix | 4:987b201ec4b1 | 144 | |
filartrix | 4:987b201ec4b1 | 145 | /** |
filartrix | 4:987b201ec4b1 | 146 | * @brief Check for the correctness of parsed data. |
filartrix | 4:987b201ec4b1 | 147 | * @param IFR_config Data structure filled with parsed data. |
filartrix | 4:987b201ec4b1 | 148 | * @retval int It returns 0 if successful, or PARSE_ERROR in case data is |
filartrix | 4:987b201ec4b1 | 149 | * not correct. |
filartrix | 4:987b201ec4b1 | 150 | */ |
filartrix | 4:987b201ec4b1 | 151 | int IFR_validate(IFR_config2_TypeDef *IFR_config); |
filartrix | 4:987b201ec4b1 | 152 | |
filartrix | 4:987b201ec4b1 | 153 | /** |
filartrix | 4:987b201ec4b1 | 154 | * @brief Modify IFR data. (Last 64-bytes block). |
filartrix | 4:987b201ec4b1 | 155 | * @param IFR_config Structure that contains the new parameters inside the |
filartrix | 4:987b201ec4b1 | 156 | * IFR configuration data. |
filartrix | 4:987b201ec4b1 | 157 | * @note It is highly recommended to parse the IFR configuration from |
filartrix | 4:987b201ec4b1 | 158 | * a working IFR block (this should be done with parse_IFR_data_config()). |
filartrix | 4:987b201ec4b1 | 159 | * Then it is possible to write the new parameters inside the IFR_config |
filartrix | 4:987b201ec4b1 | 160 | * structure. |
filartrix | 4:987b201ec4b1 | 161 | * @param data Pointer to the buffer that contains the original data. It |
filartrix | 4:987b201ec4b1 | 162 | * will be modified according to the new data in the IFR_config |
filartrix | 4:987b201ec4b1 | 163 | * structure. Then this data must be written in the last |
filartrix | 4:987b201ec4b1 | 164 | * 64-byte block in the IFR. |
filartrix | 4:987b201ec4b1 | 165 | * Its size must be 64 bytes. |
filartrix | 4:987b201ec4b1 | 166 | * @retval None |
filartrix | 4:987b201ec4b1 | 167 | */ |
filartrix | 4:987b201ec4b1 | 168 | void change_IFR_data_config(IFR_config2_TypeDef *IFR_config, uint8_t data[64]); |
filartrix | 4:987b201ec4b1 | 169 | |
filartrix | 4:987b201ec4b1 | 170 | /** |
filartrix | 4:987b201ec4b1 | 171 | * @brief Get BlueNRG hardware and firmware version |
filartrix | 4:987b201ec4b1 | 172 | * @param hwVersion This parameter returns the Hardware Version (i.e. CUT 3.0 = 0x30, CUT 3.1 = 0x31). |
filartrix | 4:987b201ec4b1 | 173 | * @param fwVersion This parameter returns the Firmware Version in the format JJ.M.N |
filartrix | 4:987b201ec4b1 | 174 | * where JJ = Major Version number, M = Minor Version number and N = Patch Version number. |
filartrix | 4:987b201ec4b1 | 175 | * @retval Status of the call |
filartrix | 4:987b201ec4b1 | 176 | */ |
filartrix | 4:987b201ec4b1 | 177 | uint8_t getBlueNRGVersion(uint8_t *hwVersion, uint16_t *fwVersion); |
filartrix | 4:987b201ec4b1 | 178 | |
filartrix | 4:987b201ec4b1 | 179 | /** |
filartrix | 4:987b201ec4b1 | 180 | * @brief Get BlueNRG updater version |
filartrix | 4:987b201ec4b1 | 181 | * @param version This parameter returns the updater version. If the updadter version is 0x03 |
filartrix | 4:987b201ec4b1 | 182 | * the chip has the updater old, needs to update the bootloader. |
filartrix | 4:987b201ec4b1 | 183 | * @retval Status of the call |
filartrix | 4:987b201ec4b1 | 184 | */ |
filartrix | 4:987b201ec4b1 | 185 | uint8_t getBlueNRGUpdaterVersion(uint8_t *version); |
filartrix | 4:987b201ec4b1 | 186 | |
filartrix | 4:987b201ec4b1 | 187 | #ifdef __cplusplus |
filartrix | 4:987b201ec4b1 | 188 | } |
filartrix | 4:987b201ec4b1 | 189 | #endif |
filartrix | 4:987b201ec4b1 | 190 | |
filartrix | 4:987b201ec4b1 | 191 | #endif /*__BLUENRG_UTILS_H */ |
filartrix | 4:987b201ec4b1 | 192 | |
filartrix | 4:987b201ec4b1 | 193 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
filartrix | 4:987b201ec4b1 | 194 |