• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 GOODIX.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "ohos_init.h"
17 #include "cmsis_os2.h"
18 #include "gr55xx_sys.h"
19 #include "gr55xx_hal_pwr.h"
20 #include "scatter_common.h"
21 #include "flash_scatter_config.h"
22 #include "user_app.h"
23 #include "app_callback.h"
24 
25 #define BLE_TASK_STACK_SIZE   4096
26 #define BLE_TASK_PRIO         25
27 #define MS_1000     1000
28 
29 /**@brief Stack global variables for Bluetooth protocol stack. */
30 STACK_HEAP_INIT(heaps_table);
31 
32 static app_callback_t s_app_ble_callback = {
33     .app_ble_init_cmp_callback  = ble_init_cmp_callback,
34     .app_gap_callbacks          = &app_gap_callbacks,
35     .app_gatt_common_callback   = &app_gatt_common_callback,
36     .app_gattc_callback         = &app_gattc_callback,
37     .app_sec_callback           = &app_sec_callback,
38 };
39 
BLE_Task(const char * arg)40 static void *BLE_Task(const char *arg)
41 {
42     (void)arg;
43 
44     printf("Initialize the BLE stack.\r\n");
45 
46     /* init ble stack */
47     ble_stack_init(&s_app_ble_callback, &heaps_table);
48 
49     while (1) {
50         osDelay(MS_1000);
51     }
52 }
53 
BLE_TaskEntry(void)54 void BLE_TaskEntry(void)
55 {
56     osThreadAttr_t attr;
57 
58     attr.name       = "BLE_Task";
59     attr.attr_bits  = 0U;
60     attr.cb_mem     = NULL;
61     attr.cb_size    = 0U;
62     attr.stack_mem  = NULL;
63     attr.stack_size = BLE_TASK_STACK_SIZE;
64     attr.priority   = BLE_TASK_PRIO;
65 
66     if (osThreadNew((osThreadFunc_t)BLE_Task, NULL, &attr) == NULL) {
67         printf("[HelloDemo] Failed to create HelloTask!\n");
68     }
69 
70     pwr_mgmt_mode_set(PMR_MGMT_SLEEP_MODE);
71 }
72 
73 SYS_RUN(BLE_TaskEntry);
74