EVE 1.0
toc-app.h
Go to the documentation of this file.
1 #ifndef TOC_APP_API_H_INCLUDED
2 #define TOC_APP_API_H_INCLUDED
3 /**********************************************************************/
4 /*
5  * Copyright (c) 2013-2015, Jetro AS
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without modification,
9  * are permitted provided that the following conditions are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright notice,
12  * this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  * 3. The name of the author may not be used to endorse or promote products
17  * derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONRIBUTORS ``AS IS'' AND ANY EXPRESS
20  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
22  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
24  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
28  * OF SUCH DAMAGE.
29  *
30  * This file is part of the EVE platform.
31  */
32 
33 /**
34  * \file
35  * @brief TOC application API
36  *
37  * @author DT, Jetro AS
38  */ /******************************************************************/
39 
40 #include <stdint.h>
41 #include <stdbool.h>
42 #include <toc/types.h>
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 /**
49  * @addtogroup toc
50  * @{
51  */
52 
53 /**
54  * @brief System TOC segments definition.
55  */
56 #define TOC_SYSTEM_SEGMENT_DESCRIPTORS() \
57  [SEGMENT_RAM] = \
58  { \
59  .Offset = (uint32_t)&TocData, \
60  }, \
61  [SEGMENT_COMMAND] = \
62  { \
63  .Offset = (uint32_t)&TocCommand, \
64  }, \
65  [SEGMENT_SERVICES] = \
66  { \
67  .Offset = (uint32_t) &TocServices, \
68  }
69 
70 /**
71  * @brief The utility macro binds a segment structure "type" with tag "tag".
72  * See toc-instance.h for defails
73  */
74 #ifdef __cplusplus
75  #define BIND_SEGMENT(type, tag) \
76  template <class SegmentLoc> \
77  struct CSegment; \
78  struct CLoc_ ## tag; \
79  template <> \
80  struct CSegment<CLoc_ ## tag> \
81  { \
82  typedef type segment_t; \
83  static const uint8_t m_segment = SEGMENT_ ## tag; \
84  };
85 #else
86  #define BIND_SEGMENT(type, tag)
87 #endif
88 
89 
90 /**
91  * @brief The enum defines type of a generic value.
92  */
94 {
95  TOC_VAL_TYPE_STRING = 0, /**< The value is a string variable */
96  TOC_VAL_TYPE_INT, /**< The value is a 32-bit integer */
97  TOC_VAL_TYPE_BOOL, /**< The value is a Boolean variable */
98  TOC_VAL_TYPE_STRUCT, /**< The value is a structure */
99  TOC_VAL_TYPE_SERVICE, /**< BLE service descriptor */
100  TOC_VAL_TYPE_UNKNOWN, /**< Reserved */
101 };
102 
103 /**
104  * @brief minimal and maximal possible values for the INTEGER parameters.
105  */
106 struct min_max_t
107 {
108  int32_t Min; /**< Minimal value */
109  int32_t Max; /**< Maximal value */
110 };
111 
112 #define TOC_ACL_PUBLIC (0) /**< The paramater is visible for everyone */
113 #define TOC_ACL_PROTECTED (1) /**< The paramater is visible for a super user */
114 #define TOC_ACL_PRIVATE (2) /**< The paramater is visible in debug mode only */
115 #define TOC_ACL_DENIED (3) /**< The paramater is not visible */
116 
117 #define TOC_POLICY_PRE_CB (1 << 0) /**< A callback to be called before the paramater access */
118 #define TOC_POLICY_POST_CB (1 << 1) /**< A callback to be called after the paramater access */
119 
120 #define TOC_FLAG_ACL(x) (((x) & 3) << 0) /**< Access control flags, see TOC_ACL_... */
121 #define TOC_FLAG_READ_POLICY(x) (((x) & 3) << 2) /**< Read policy, see TOC_POLICY_... */
122 #define TOC_FLAG_WRITE_POLICY(x) (((x) & 3) << 4) /**< Write policy, see TOC_POLICY_... */
123 #define TOC_FLAG_READ (1 << 6) /**< The parameter is readable */
124 #define TOC_FLAG_WRITE (1 << 7) /**< The parameter is writeable */
125 
126 #define TOC_FLAG_BINARY (1 << 8) /**< The STRING parameter contains binary data */
127 #define TOC_FLAG_VIRTUAL (1 << 9) /**< The parameter is a virtual array */
128 #define TOC_FLAG_EXTERN_LIMITS (1 << 10) /**< Min and Max contain offsets to real uint32_t limits in a pool */
129 #define TOC_FLAG_V_SIZE (1 << 11) /**< The parameter has variable size */
130 
131 #define TOC_FLAG_BLE_BROADCAST (1 << 13) /**< BLE should allow broadcast for the parameter */
132 #define TOC_FLAG_BLE_NOTIFICATION (1 << 14) /**< BLE should allow notification for the parameter */
133 #define TOC_FLAG_BLE_INDICATION (1 << 15) /**< BLE should allow indication for the parameter */
134 
135 #define TOC_POLICY_MASK (3) /**< Policy type mask */
136 #define TOC_FLAG_ACL_MASK TOC_FLAG_ACL(3) /**< ACL flags mask */
137 #define TOC_FLAG_READ_POLICY_MASK TOC_FLAG_READ_POLICY(3) /**< Read policy mask*/
138 #define TOC_FLAG_WRITE_POLICY_MASK TOC_FLAG_WRITE_POLICY(3) /**< Write policy mask */
139 
140 /**
141  * @brief Applikasjon-spesifikk parameter beskrivelse.
142  * @param Name navn av parameteren som offset i string pool
143  */
144 struct toc_t
145 {
146  uint16_t Type : 4; /**< Type of the parameter, one of VAL_TYPE_... */
147  uint16_t Name : 12; /**< Offset of the name of the parameter in the string pool */
148  uint16_t Flags; /**< Binary blags bitmap, see TOC_FLAG_... for details */
149  uint16_t Offset : 13; /**< Offset of the parameter in the segment */
150  uint16_t Segment : 3; /**< Segment ID where the parameter is located */
151  uint8_t Size; /**< Size of the parameter (a single item for arrays) */
152  uint8_t Count; /**< Number of elements in the array */
153  uint16_t Min; /**< Minimal value for the parameter (possibly indirect) */
154  uint16_t Max; /**< Maximal alue for the parameter (possibly indirect) */
155  uint16_t Label; /**< Offset of the label of the parameter in the string pool */
156  uint16_t Uuid; /**< BLE UUID / HTML class */
157 };
158 
159 struct toc_blob_t;
160 
161 struct toc_segment_descriptor_t
162 {
163  uint32_t Offset;
164 };
165 
166 extern const struct toc_segment_descriptor_t TocSegmentTable[];
167 
168 /**
169  * Get minimal and maximal values for the parameter
170  */
171 void TocGetMinMax(const struct toc_blob_t *Ptr, const struct toc_t *Var, struct min_max_t *MinMax);
172 
173 /**
174  * @brief Gir "table of content" (TOC).
175  *
176  * Tabellen definerer de parameterene applikasjon kan kontrollere.
177  * TOC aldri skrives noe i tabellen, så den kan ligge i flash minne.
178  *
179  * @param Ptr applikasjonen må settes (*TocPtr) pekeren på TOC-tabel
180  */
181 extern void TocAppGetToc(struct toc_blob_t *Ptr);
182 
183 extern int TocVarPreGet(int Id, int Index);
184 extern int TocVarPostGet(int Id, int Index);
185 extern int TocVarPreSet(int Id, int Index);
186 extern int TocVarPostSet(int Id, int Index);
187 
188 /** @} */ /* toc */
189 
190 #ifdef __cplusplus
191 }
192 #endif
193 
194 #endif /* TOC_APP_API_H_INCLUDED */
Applikasjon-spesifikk parameter beskrivelse.
Definition: toc-app.h:144
int32_t Min
Definition: toc-app.h:108
uint16_t Min
Definition: toc-app.h:153
uint16_t Label
Definition: toc-app.h:155
uint16_t Uuid
Definition: toc-app.h:156
uint8_t Count
Definition: toc-app.h:152
void TocAppGetToc(struct toc_blob_t *Ptr)
Gir "table of content" (TOC).
toc_val_type_t
The enum defines type of a generic value.
Definition: toc-app.h:93
uint8_t Size
Definition: toc-app.h:151
TOC module basic types.
uint16_t Flags
Definition: toc-app.h:148
uint16_t Max
Definition: toc-app.h:154
int32_t Max
Definition: toc-app.h:109
minimal and maximal possible values for the INTEGER parameters.
Definition: toc-app.h:106
void TocGetMinMax(const struct toc_blob_t *Ptr, const struct toc_t *Var, struct min_max_t *MinMax)