Add new audio permission
[apps/agl-service-unicens.git] / ucs2-interface / ucs_config.h
1 /*------------------------------------------------------------------------------------------------*/
2 /* UNICENS Integration Helper Component                                                           */
3 /* Copyright 2017, Microchip Technology Inc. and its subsidiaries.                                */
4 /*                                                                                                */
5 /* Redistribution and use in source and binary forms, with or without                             */
6 /* modification, are permitted provided that the following conditions are met:                    */
7 /*                                                                                                */
8 /* 1. Redistributions of source code must retain the above copyright notice, this                 */
9 /*    list of conditions and the following disclaimer.                                            */
10 /*                                                                                                */
11 /* 2. Redistributions in binary form must reproduce the above copyright notice,                   */
12 /*    this list of conditions and the following disclaimer in the documentation                   */
13 /*    and/or other materials provided with the distribution.                                      */
14 /*                                                                                                */
15 /* 3. Neither the name of the copyright holder nor the names of its                               */
16 /*    contributors may be used to endorse or promote products derived from                        */
17 /*    this software without specific prior written permission.                                    */
18 /*                                                                                                */
19 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"                    */
20 /* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE                      */
21 /* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE                 */
22 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE                   */
23 /* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL                     */
24 /* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR                     */
25 /* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER                     */
26 /* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,                  */
27 /* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE                  */
28 /* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                           */
29 /*------------------------------------------------------------------------------------------------*/
30 #ifndef UNICENSINTEGRATION_H_
31 #define UNICENSINTEGRATION_H_
32
33 /*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
34 /*                  USER ADJUSTABLE VALUES                              */
35 /*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
36
37 #define ENABLE_INIC_WATCHDOG    (true)
38 #define ENABLE_AMS_LIB          (true)
39 #define DEBUG_XRM
40 #define BOARD_PMS_TX_SIZE       (72)
41 #define CMD_QUEUE_LEN           (40)
42 #define I2C_WRITE_MAX_LEN       (32)
43
44 #include <string.h>
45 #include <stdarg.h>
46
47 #include "ucs_cfg.h"
48 #include "ucs_api.h"
49
50 /*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
51 /*                          PRIVATE SECTION                             */
52 /*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
53
54 /**
55  * \brief Internal enum for UNICENS Integration
56  */
57 typedef enum
58 {
59     /**Result is OK and the processing is finished. Safe to dequeue this command.*/
60     UniCmdResult_OK_ProcessFinished,
61     /**Result is OK but the processing is ongoing. Must wait for callback.*/
62     UniCmdResult_OK_NeedToWaitForCB,
63     /**Result is error and the processing is finished. Safe to dequeue this command.*/
64     UniCmdResult_ERROR_ProcessFinished
65 } UnicensCmdResult_t;
66
67 /**
68  * \brief Asynchronous callback notifiying a command result
69  * \param result_ptr    The asynchronous result of the command
70  * \param request_ptr   User reference, typically points to the afb_req
71  *                      object.
72  */
73 typedef void (*Ucsi_ResultCb_t)(void *result_ptr, void *request_ptr);
74
75 /**
76  * \brief Internal enum for UNICENS Integration
77  */
78 typedef enum
79 {
80     UnicensCmd_Unknown,
81     UnicensCmd_Init,
82     UnicensCmd_Stop,
83     UnicensCmd_RmSetRoute,
84     UnicensCmd_NsRun,
85     UnicensCmd_GpioCreatePort,
86     UnicensCmd_GpioWritePort,
87     UnicensCmd_I2CWrite,
88     UnicensCmd_SendAmsMessage
89 } UnicensCmd_t;
90
91 /**
92  * \brief Internal struct for UNICENS Integration
93  */
94 typedef struct
95 {
96     const Ucs_InitData_t *init_ptr;
97 } UnicensCmdInit_t;
98
99 /**
100  * \brief Internal struct for UNICENS Integration
101  */
102 typedef struct
103 {
104     Ucs_Rm_Route_t *routePtr;
105     bool isActive;
106 } UnicensCmdRmSetRoute_t;
107
108 /**
109  * \brief Internal struct for UNICENS Integration
110  */
111 typedef struct
112 {
113     Ucs_Rm_Node_t * node_ptr;
114 } UnicensCmdNsRun_t;
115
116 /**
117  * \brief Internal struct for UNICENS Integration
118  */
119 typedef struct
120 {
121     uint16_t destination;
122     uint16_t debounceTime;
123 } UnicensCmdGpioCreatePort_t;
124
125 /**
126  * \brief Internal struct for UNICENS Integration
127  */
128 typedef struct
129 {
130     uint16_t destination;
131     uint16_t mask;
132     uint16_t data;
133 } UnicensCmdGpioWritePort_t;
134
135 /**
136  * \brief Internal struct for UNICENS Integration
137  */
138 typedef struct
139 {
140     uint16_t destination;
141     bool isBurst;
142     uint8_t blockCount;
143     uint8_t slaveAddr;
144     uint16_t timeout;
145     uint8_t dataLen;
146     uint8_t data[I2C_WRITE_MAX_LEN];
147
148     Ucsi_ResultCb_t result_fptr;
149     void *request_ptr;
150
151 } UnicensCmdI2CWrite_t;
152
153 /**
154  * \brief Internal struct for UNICENS Integration
155  */
156 typedef struct
157 {
158     uint16_t msgId;
159     uint16_t targetAddress;
160     uint8_t pPayload[UCS_AMS_SIZE_TX_MSG];
161     uint32_t payloadLen;
162 } UnicensCmdSendAmsMessage_t;
163
164 /**
165  * \brief Internal struct for UNICENS Integration
166  */
167 typedef struct
168 {
169     UnicensCmd_t cmd;
170     union
171     {
172         UnicensCmdInit_t Init;
173         UnicensCmdRmSetRoute_t RmSetRoute;
174         UnicensCmdNsRun_t NsRun;
175         UnicensCmdGpioCreatePort_t GpioCreatePort;
176         UnicensCmdGpioWritePort_t GpioWritePort;
177         UnicensCmdI2CWrite_t I2CWrite;
178         UnicensCmdSendAmsMessage_t SendAms;
179     } val;
180 } UnicensCmdEntry_t;
181
182 /**
183  * \brief Internal variables for one instance of UNICENS Integration
184  * \note Never touch any of this fields!
185  */
186 typedef struct {
187     volatile uint8_t *dataQueue;
188     volatile uint8_t *pRx;
189     volatile uint8_t *pTx;
190     volatile uint32_t amountOfEntries;
191     volatile uint32_t sizeOfEntry;
192     volatile uint32_t rxPos;
193     volatile uint32_t txPos;
194 } RB_t;
195
196 /**
197  * \brief Internal variables for one instance of UNICENS Integration
198  * \note Allocate this structure for each instance (static or malloc)
199  *        and pass it to UCSI_Init()
200  * \note Never touch any of this fields!
201  */
202 typedef struct
203 {
204     uint32_t magic;
205     void *tag;
206     bool initialized;
207     RB_t rb;
208     uint8_t rbBuf[(CMD_QUEUE_LEN * sizeof(UnicensCmdEntry_t))];
209     Ucs_Inst_t *unicens;
210     Ucs_InitData_t uniInitData;
211     bool triggerService;
212     Ucs_Lld_Api_t *uniLld;
213     void *uniLldHPtr;
214     UnicensCmdEntry_t *currentCmd;
215 } UCSI_Data_t;
216
217 #endif /* UNICENSINTEGRATION_H_ */