74c82c6001499350e18b5a587f07767fb1b497ad
[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           (6)
42
43 #include <string.h>
44 #include <stdarg.h>
45
46 #include "ucs_cfg.h"
47 #include "ucs_api.h"
48
49 /*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
50 /*                          PRIVATE SECTION                             */
51 /*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
52
53 /**
54  * \brief Internal enum for Unicens Integration
55  */
56 typedef enum
57 {
58     /**Result is OK and the processing is finished. Safe to dequeue this command.*/
59     UniCmdResult_OK_ProcessFinished,
60     /**Result is OK but the processing is ongoing. Must wait for callback.*/
61     UniCmdResult_OK_NeedToWaitForCB,
62     /**Result is error and the processing is finished. Safe to dequeue this command.*/
63     UniCmdResult_ERROR_ProcessFinished
64 } UnicensCmdResult_t;
65
66 /**
67  * \brief Internal enum for Unicens Integration
68  */
69 typedef enum
70 {
71     UnicensCmd_Unknown,
72     UnicensCmd_Init,
73     UnicensCmd_Stop,
74     UnicensCmd_RmSetRoute,
75     UnicensCmd_NsRun
76 } UnicensCmd_t;
77
78 /**
79  * \brief Internal struct for Unicens Integration
80  */
81 typedef struct
82 {
83     const Ucs_InitData_t *init_ptr;
84 } UnicensCmdInit_t;
85
86 /**
87  * \brief Internal struct for Unicens Integration
88  */
89 typedef struct
90 {
91     Ucs_Rm_Route_t *routePtr;
92     bool isActive;
93 } UnicensCmdRmSetRoute_t;
94
95 /**
96  * \brief Internal struct for Unicens Integration
97  */
98 typedef struct
99 {
100     Ucs_Rm_Node_t * node_ptr;
101 } UnicensCmdNsRun_t;
102
103 /**
104  * \brief Internal struct for Unicens Integration
105  */
106 typedef struct
107 {
108     UnicensCmd_t cmd;
109     union
110     {
111         UnicensCmdInit_t Init;
112         UnicensCmdRmSetRoute_t RmSetRoute;
113         UnicensCmdNsRun_t NsRun;
114     } val;
115 } UnicensCmdEntry_t;
116
117 /**
118  * \brief Internal variables for one instance of Unicens Integration
119  * \note Never touch any of this fields!
120  */
121 typedef struct {
122     volatile uint8_t *dataQueue;
123     volatile uint8_t *pRx;
124     volatile uint8_t *pTx;
125     volatile uint32_t amountOfEntries;
126     volatile uint32_t sizeOfEntry;
127     volatile uint32_t rxPos;
128     volatile uint32_t txPos;
129 } RB_t;
130
131 /**
132  * \brief Internal variables for one instance of Unicens Integration
133  * \note Allocate this structure for each instance (static or malloc)
134  *        and pass it to UCSI_Init()
135  * \note Never touch any of this fields!
136  */
137 typedef struct
138 {
139     uint32_t magic;
140     void *tag;
141     bool initialized;
142     RB_t rb;
143     uint8_t rbBuf[(CMD_QUEUE_LEN * sizeof(UnicensCmdEntry_t))];
144     Ucs_Inst_t *unicens;
145     Ucs_InitData_t uniInitData;
146     bool triggerService;
147     Ucs_Lld_Api_t *uniLld;
148     void *uniLldHPtr;
149     UnicensCmdEntry_t *currentCmd;
150 } UCSI_Data_t;
151
152 #endif /* UNICENSINTEGRATION_H_ */