| BlueNRG-1 DK: BLE examples

- Main Page
- Modules
- Files

- File List

BLE_Chat_main.c
Go to the documentation of this file.
1
2 /******************** (C) COPYRIGHT 2016 STMicroelectronics ********************
3 * File Name : BLE_Chat_main.c
4 * Author : VMA DIVISION
5 * Version : 1.1.0
6 * Date : 15-January-2016
7 * Description : Code demostrating the BLE Chat application
8 ********************************************************************************
9 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
10 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
11 * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
12 * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
13 * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
14 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
15 *******************************************************************************/
16
193 /* Includes ------------------------------------------------------------------*/
194 #include <stdio.h>
195 #include <string.h>
196 #include "BlueNRG1_it.h"
197 #include "BlueNRG1_conf.h"
198 #include "ble_const.h"
199 #include "bluenrg1_stack.h"
200 #include "gp_timer.h"
201 #include "app_state.h"
202 #include "chat.h"
203 #include "SDK_EVAL_Config.h"
204 #include "Chat_config.h"
205 #include "OTA_btl.h"
206
207 /* Private typedef -----------------------------------------------------------*/
208 /* Private define ------------------------------------------------------------*/
209 #define BLE_CHAT_VERSION_STRING "1.0.0"
210
211
212 /* Private macro -------------------------------------------------------------*/
213 /* Private variables ---------------------------------------------------------*/
214 /* Private function prototypes -----------------------------------------------*/
215 /* Private functions ---------------------------------------------------------*/
216
217 int main(void)
218 {
219 uint8_t ret;
220
221 /* System Init */
222 SystemInit();
223
224 /* Identify BlueNRG1 platform */
225 SdkEvalIdentification();
226
227 /* Init Clock */
228 Clock_Init();
229
230 /* Configure I/O communication channel:
231 It requires the void IO_Receive_Data(uint8_t * rx_data, uint16_t data_size) function
232 where user received data should be processed */
233 SdkEvalComIOConfig(Process_InputData);
234
235 /* BlueNRG-1 stack init */
236 ret = BlueNRG_Stack_Initialization(&BlueNRG_Stack_Init_params);
237 if (ret != BLE_STATUS_SUCCESS) {
238 printf("Error in BlueNRG_Stack_Initialization() 0x%02x\r\n", ret);
239 while(1);
240 }
241
242 #if SERVER
243 printf("BlueNRG-1 BLE Chat Server Application (version: %s)\r\n", BLE_CHAT_VERSION_STRING);
244 #else
245 printf("BlueNRG-1 BLE Chat Client Application (version: %s)\r\n", BLE_CHAT_VERSION_STRING);
246 #endif
247
248 /* Init Chat Device */
249 ret = CHAT_DeviceInit();
250 if (ret != BLE_STATUS_SUCCESS) {
251 printf("CHAT_DeviceInit()--> Failed 0x%02x\r\n", ret);
252 while(1);
253 }
254
255 printf("BLE Stack Initialized \n");
256
257 #if ST_USE_OTA_SERVICE_MANAGER_APPLICATION
258 /* Initialize the button */
259 SdkEvalPushButtonInit(BUTTON_1);
260 #endif /* ST_USE_OTA_SERVICE_MANAGER_APPLICATION */
261
262 while(1) {
263 /* BlueNRG-1 stack tick */
264 BTLE_StackTick();
265
266 /* Application tick */
267 APP_Tick();
268
269 #if ST_OTA_FIRMWARE_UPGRADE_SUPPORT
270 /* Check if the OTA firmware upgrade session has been completed */
271 if (OTA_Tick() == 1)
272 {
273 /* Jump to the new application */
274 OTA_Jump_To_New_Application();
275 }
276 #endif /* ST_OTA_FIRMWARE_UPGRADE_SUPPORT */
277
278 #if ST_USE_OTA_SERVICE_MANAGER_APPLICATION
279 if (SdkEvalPushButtonGetState(BUTTON_1) == RESET)
280 {
281 OTA_Jump_To_Service_Manager_Application();
282 }
283 #endif /* ST_USE_OTA_SERVICE_MANAGER_APPLICATION */
284 }
285
286 } /* end main() */
287
288 #ifdef USE_FULL_ASSERT
289
296 void assert_failed(uint8_t* file, uint32_t line)
297 {
298 /* User can add his own implementation to report the file name and line number,
299 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
300
301 /* Infinite loop */
302 while (1)
303 {
304 }
305 }
306
307 #endif
308
309 /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/