my fork

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers bluenrg_utils.h Source File

bluenrg_utils.h

Go to the documentation of this file.
00001 /******************** (C) COPYRIGHT 2013 STMicroelectronics ********************
00002 * File Name          : bluenrg_utils.h
00003 * Author             : AMS - AAS, RF Application Team
00004 * Version            : V1.0.0
00005 * Date               : 21-March-2014
00006 * Description        : Header file for BlueNRG utility functions 
00007 ********************************************************************************
00008 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
00009 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
00010 * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
00011 * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
00012 * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
00013 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
00014 *******************************************************************************/
00015 /**
00016  * @file  bluenrg_utils.h
00017  * @brief BlueNRG IFR updater & BlueNRG stack updater utility APIs description
00018  *
00019  * <!-- Copyright 2014 by STMicroelectronics.  All rights reserved.       *80*-->
00020 **/
00021 /* Define to prevent recursive inclusion -------------------------------------*/
00022 #ifndef __BLUENRG_UTILS_H
00023 #define __BLUENRG_UTILS_H
00024 
00025 #ifdef __cplusplus
00026  extern "C" {
00027 #endif
00028 
00029 /* Includes ------------------------------------------------------------------*/
00030 #include "hal_types.h" 
00031 #include "compiler.h"
00032 
00033 /* Exported types ------------------------------------------------------------*/
00034 typedef struct{
00035   uint8_t stack_mode;
00036   uint8_t day;
00037   uint8_t month;
00038   uint8_t year;
00039   uint16_t slave_sca_ppm;
00040   uint8_t master_sca;
00041   uint16_t hs_startup_time; /* In system time units*/
00042 } IFR_config2_TypeDef;
00043 
00044 /**
00045  * Structure inside IFR for configuration options. 
00046  */
00047 typedef __packed struct{
00048   uint8_t cold_ana_act_config_table[64];
00049   uint8_t hot_ana_config_table[64];
00050   uint8_t stack_mode;
00051   uint8_t rsrvd1[3];
00052   uint32_t rsrvd2[4];
00053   uint32_t ls_crystal_period;
00054   uint32_t ls_crystal_freq;
00055   uint16_t slave_sca_ppm;
00056   uint8_t master_sca;
00057   uint8_t rsrvd3;
00058   uint16_t hs_startup_time; /* In system time units*/
00059   uint8_t crystal_par;
00060   uint8_t hot_cold_ta;
00061   uint8_t uid[3];
00062   uint8_t rf_power;
00063   uint8_t rsrvd4;
00064   uint8_t year;  
00065   uint8_t month;
00066   uint8_t day;
00067   uint32_t rsrvd5[5];
00068 } PACKED IFR_config_TypeDef;
00069 
00070 /* Exported constants --------------------------------------------------------*/
00071 extern const IFR_config_TypeDef IFR_config;
00072 
00073 /* Exported macros -----------------------------------------------------------*/
00074 #define FROM_US_TO_SYS_TIME(us)      ((uint16_t)(us/2.4414))
00075 #define FROM_SYS_TIME_TO_US(sys)     ((uint16_t)(sys*2.4414))
00076 
00077 /* Convert 2 digit BCD number to an integer */
00078 #define BCD_TO_INT(bcd) ((bcd & 0xF) + ((bcd & 0xF0) >> 4)*10)
00079 
00080 /* Convert 2 digit number to a BCD number */
00081 #define INT_TO_BCD(n) ((((uint8_t)n/10)<<4) + (uint8_t)n%10)
00082 
00083 /** 
00084   * Return values 
00085   */ 
00086 #define BLE_UTIL_SUCCESS                 0
00087 #define BLE_UTIL_UNSUPPORTED_VERSION     1
00088 #define BLE_UTIL_WRONG_IMAGE_SIZE        2
00089 #define BLE_UTIL_ACI_ERROR               3
00090 #define BLE_UTIL_CRC_ERROR               4
00091 #define BLE_UTIL_PARSE_ERROR             5
00092 #define BLE_UTIL_WRONG_VERIFY            6
00093 
00094 /* Exported functions ------------------------------------------------------- */ 
00095 /**
00096   * @brief  Flash a new firmware using internal bootloader.
00097   * @param  fw_image     Pointer to the firmware image (raw binary data,
00098   *                      little-endian).
00099   * @param  fw_size      Size of the firmware image. 
00100   * @param  skip_bootloader_verif     If true, verification of the first sector,
00101   *                                   that contains the bootloader, will not be executed.
00102   * @note   this is useful when a new image with a new bootloader must be
00103   *         programmed.
00104   * @retval int      It returns 0 if successful, or a number not equal to 0 in
00105                      case of error (ACI_ERROR, UNSUPPORTED_VERSION,
00106   *                  WRONG_IMAGE_SIZE, CRC_ERROR)
00107   */
00108 int program_device(const uint8_t *fw_image, uint32_t fw_size, uint8_t skip_bootloader_verif);
00109 
00110 /**
00111   * @brief  Read raw data from IFR (3 64-bytes blocks).
00112   * @param  data     Pointer to the buffer that will contain the read data.
00113   *                  Its size must be 192 bytes. This data can be parsed by
00114   *                  parse_IFR_data_config().
00115   * @retval int      It returns 0 if successful, or a number not equal to 0 in
00116                      case of error (ACI_ERROR, UNSUPPORTED_VERSION)
00117   */
00118 int read_IFR(uint8_t data[192]);
00119 
00120 /**
00121   * @brief  Verify raw data from IFR (3 64-bytes blocks).
00122   * @param  ifr_data Pointer to the buffer that will contain the data to verify.
00123   *                  Its size must be 192 bytes.
00124   * @retval int      It returns 0 if successful, or a number not equal to 0 in
00125                      case of error (ACI_ERROR, BLE_UTIL_WRONG_VERIFY)
00126   */
00127 uint8_t verify_IFR(const IFR_config_TypeDef *ifr_data);
00128 
00129 /**
00130   * @brief  Program raw data to IFR (3 64-bytes blocks).
00131   * @param  ifr_image     Pointer to the buffer that will contain the data to program.
00132   *                  Its size must be 192 bytes.
00133   * @retval int      It returns 0 if successful
00134   */
00135 int program_IFR(const IFR_config_TypeDef *ifr_image);
00136 
00137 /**
00138   * @brief  Parse IFR raw data.
00139   * @param  data     Pointer to the raw data: last 64 bytes read from IFR sector.
00140   * @param  IFR_config     Data structure that will be filled with parsed data.
00141   * @retval None
00142   */
00143 void parse_IFR_data_config(const uint8_t data[64], IFR_config2_TypeDef *IFR_config);
00144 
00145 /**
00146   * @brief  Check for the correctness of parsed data.
00147   * @param  IFR_config     Data structure filled with parsed data.
00148   * @retval int      It returns 0 if successful, or PARSE_ERROR in case data is
00149   *                  not correct.
00150   */
00151 int IFR_validate(IFR_config2_TypeDef *IFR_config);
00152 
00153 /**
00154   * @brief  Modify IFR data. (Last 64-bytes block).
00155   * @param  IFR_config   Structure that contains the new parameters inside the
00156   *                      IFR configuration data.
00157   * @note   It is highly recommended to parse the IFR configuration from
00158   *         a working IFR block (this should be done with parse_IFR_data_config()).
00159   *         Then it is possible to write the new parameters inside the IFR_config
00160   *         structure.
00161   * @param  data     Pointer to the buffer that contains the original data. It
00162   *                  will be modified according to the new data in the IFR_config
00163   *                  structure. Then this data must be written in the last
00164   *                  64-byte block in the IFR.
00165   *                  Its size must be 64 bytes.
00166   * @retval None
00167   */
00168 void change_IFR_data_config(IFR_config2_TypeDef *IFR_config, uint8_t data[64]);
00169 
00170 /**
00171   * @brief  Get BlueNRG hardware and firmware version
00172   * @param  hwVersion This parameter returns the Hardware Version (i.e. CUT 3.0 = 0x30, CUT 3.1 = 0x31).
00173   * @param  fwVersion This parameter returns the Firmware Version in the format JJ.M.N
00174   *                   where JJ = Major Version number, M = Minor Version number and N = Patch Version number.
00175   * @retval Status of the call
00176   */
00177 uint8_t getBlueNRGVersion(uint8_t *hwVersion, uint16_t *fwVersion);
00178 
00179 /**
00180   * @brief  Get BlueNRG updater version
00181   * @param  version This parameter returns the updater version. If the updadter version is 0x03 
00182   *                 the chip has the updater old, needs to update the bootloader.
00183   * @retval Status of the call
00184   */
00185 uint8_t getBlueNRGUpdaterVersion(uint8_t *version);
00186 
00187 #ifdef __cplusplus
00188 }
00189 #endif
00190 
00191 #endif /*__BLUENRG_UTILS_H */
00192 
00193 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
00194