• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 ASR Microelectronics (Shanghai) Co., Ltd. All rights reserved.
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 /**
17  ****************************************************************************************
18  *
19  * @file sonata_ble_api.h
20  *
21  * @brief header file - ble common operation
22  *
23  ****************************************************************************************
24  */
25 
26 #ifndef _SONATA_BLE_API_H_
27 #define _SONATA_BLE_API_H_
28 
29 /*
30  * INCLUDE FILES
31  ****************************************************************************************
32  */
33 #include "sonata_utils_api.h"
34 #include "sonata_gatt_api.h"
35 #include "sonata_gap_api.h"
36 #include "sonata_prf_diss_api.h"
37 #include "sonata_log.h"
38 /*
39  * MACRO DEFINITIONS
40  ****************************************************************************************
41  */
42 /**
43  * @defgroup SONATA_BLE_API BLE_API
44  * @{
45  */
46 
47 // debug trace
48 #define SONATA_BLE_API_DBG    1
49 #if SONATA_BLE_API_DBG
50 #define SONATA_BLE_API_TRC    printf
51 #else
52 #define SONATA_BLE_API_TRC(...)
53 #endif // SONATA_BLE_API_DBG
54 
55 #define SONATA_TASK_FIRST_MSG(task) ((uint16_t)((task) << 8))
56 
57 /*
58  * ENUM DEFINITIONS
59  ****************************************************************************************
60  */
61 
62 // App callback status
63 typedef enum {
64     CB_DONE           = 0, // Done in callback
65     CB_REJECT         = 1, // Do nothing in callback, SDK will do it
66     CB_MAX            = 0xFF,
67 } CBStatus;
68 
69 // Result of sleep state.
70 enum sonata_ble_sleep_state {
71     // Some activity pending, can not enter in sleep state
72     SONATA_BLE_ACTIVE    = 0,
73     // CPU can be put in sleep state
74     SONATA_BLE_CPU_SLEEP,
75     // IP could enter in deep sleep
76     SONATA_BLE_DEEP_SLEEP,
77 };
78 
79 /*
80  * Type Definition
81  ****************************************************************************************
82  */
83 
84 /*
85  * GLOBAL VARIABLE DECLARATIONS
86  ****************************************************************************************
87  */
88 
89 /*!
90  * @brief
91  */
92 extern uint32_t reset_error;
93 
94 /*
95  * FUNCTION DECLARATIONS             Developer use function
96  ****************************************************************************************
97  */
98 /*!
99  * @brief Init ble module
100  * @param hook @see sonata_ble_hook_t
101  */
102 void sonata_ble_init(sonata_ble_hook_t hook);
103 
104 /*!
105  * @brief Set a bit in the prevent sleep bit field, in order to prevent the system from  going to sleep
106  * @param prv_slp_bit Bit to be set in the prevent sleep bit field
107  */
108 void sonata_ble_prevent_sleep_set(uint16_t prv_slp_bit);
109 
110 /*!
111  * @brief Clears a bit in the prevent sleep bit field, in order to allow the system
112  *        going to sleep
113  * @param prv_slp_bit Bit to be cleared in the prevent sleep bit field
114  */
115 void sonata_ble_prevent_sleep_clear(uint16_t prv_slp_bit);
116 
117 /*!
118  * @brief Reset ble module
119  * @return API_SUCCESS
120  */
121 uint16_t sonata_ble_reset(void);
122 
123 /*!
124  * @brief ble stack schedule
125  */
126 
127 void sonata_ble_schedule(void);
128 
129 /*!
130  * @brief ble enter sleep
131  * @return Sleep state
132  */
133 uint8_t sonata_ble_sleep(void);
134 
135 /*!
136  * @brief ble irq handler
137  */
138 void sonata_ble_isr(void);
139 
140 /*
141  * FUNCTION DECLARATIONS             Connection help function End
142  ****************************************************************************************
143  */
144 
145 /** @}*/
146 
147 #endif // _SONATA_BLE_API_H_
148 
149