• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  *****************************************************************************************
3  *
4  * @file lls.h
5  *
6  * @brief Link Loss Service API
7  *
8  *****************************************************************************************
9  * @attention
10   #####Copyright (c) 2019 GOODIX
11   All rights reserved.
12 
13     Redistribution and use in source and binary forms, with or without
14     modification, are permitted provided that the following conditions are met:
15   * Redistributions of source code must retain the above copyright
16     notice, this list of conditions and the following disclaimer.
17   * Redistributions in binary form must reproduce the above copyright
18     notice, this list of conditions and the following disclaimer in the
19     documentation and/or other materials provided with the distribution.
20   * Neither the name of GOODIX nor the names of its contributors may be used
21     to endorse or promote products derived from this software without
22     specific prior written permission.
23 
24   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27   ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
28   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34   POSSIBILITY OF SUCH DAMAGE.
35  *****************************************************************************************
36  */
37 
38 /**
39  * @addtogroup BLE_SRV BLE Services
40  * @{
41  * @brief Definitions and prototypes for the BLE Service interface.
42  */
43 
44 /**
45  * @defgroup BLE_SDK_LLS Link Loss Service (LLS)
46  * @{
47  * @brief Definitions and prototypes for the LLS interface.
48  *
49  * @details The Link Loss Service uses the Alert Level characteristic to cause an alert in the
50  *          device when the link is lost.
51  *
52  *          The application must provide an event handler to set \ref lls_init_t.evt_handler.
53  *          After \ref lls_init_t variable is initialized, the application must call \ref lls_service_init()
54  *          to add Alert Level Characteristic to the BLE Stack database, the service will notify the application
55  *          with the event handler when the link has been lost, and which Alert Level has been set.
56  *
57  *          This module also provides \ref lls_alert_level_get() function to the
58  *          application to poll the current value of Alert Level characteristic.
59  *
60  */
61 
62 #ifndef __LLS_H__
63 #define __LLS_H__
64 
65 #include <stdint.h>
66 #include "gr55xx_sys.h"
67 #include "custom_config.h"
68 
69 /**
70  * @defgroup LLS_ENUM Enumerations
71  * @{
72  */
73 /** Link Loss Service alert levels. */
74 typedef enum {
75     LLS_ALERT_LEVEL_NO_ALERT,       /**< No alert. */
76     LLS_ALERT_LEVEL_MILD_ALERT,     /**< Mild alert. */
77     LLS_ALERT_LEVEL_HIGH_ALERT,     /**< High alert. */
78 } lls_alert_levels_t;
79 
80 /**@brief Link Loss Service event type. */
81 typedef enum {
82     LLS_EVT_INVALID,            /**< Invalid LLS event. */
83     LLS_EVT_LINK_LOSS_ALERT     /**< Link loss alert event. */
84 } lls_evt_type_t;
85 /** @} */
86 
87 /**
88  * @defgroup LLS_STRUCT Structures
89  * @{
90  */
91 /**@brief Link Loss Service event. */
92 typedef struct {
93     lls_evt_type_t evt_type;            /**< Type of event. */
94     lls_alert_levels_t alert_level;     /**< Alert level. */
95 } lls_evt_t;
96 /** @} */
97 
98 /**
99  * @defgroup LLS_TYPEDEF Typedefs
100  * @{
101  */
102 /**@brief Link Loss Service event handler type. */
103 typedef void (*lls_evt_handler_t)(lls_evt_t *p_evt);
104 /** @} */
105 
106 /**
107  * @addtogroup LLS_STRUCT Structures
108  * @{
109  */
110 /**@brief Link Loss Service init stucture.
111  * This contains all option and data needed for initialization of the service. */
112 typedef struct {
113     lls_evt_handler_t  evt_handler;          /**< Link Loss Service event handler. */
114     lls_alert_levels_t initial_alert_level;  /**< Initial value of the alert level. */
115 } lls_init_t;
116 /** @} */
117 
118 /**
119  * @defgroup LLS_FUNCTION Functions
120  * @{
121  */
122 /**
123  *****************************************************************************************
124  * @brief Initialize a Link Loss Service instance and add in ATT DB
125  *
126  * @param[in] p_lls_init: Pointer to Link Loss Service Service initialization variable
127  *
128  * @return Result of service initialization.
129  *****************************************************************************************
130  */
131 sdk_err_t lls_service_init(lls_init_t *p_lls_init);
132 
133 /**
134  *****************************************************************************************
135  * @brief Get current value of alert level characteristic.
136  *
137  * @param[out] p_alert_level: Pointer to the current value of alert level
138  *
139  * @return BLE_SDK_SUCCESS on success, otherwise an error code
140  *****************************************************************************************
141  */
142 sdk_err_t lls_alert_level_get(uint8_t *p_alert_level);
143 /** @} */
144 
145 #endif
146 /** @} */
147 /** @} */
148