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