Etherios Cloud Connector very first porting for mbed. Tested in an LPC1768

Etherios Cloud Connector for Embedded v2.1.0.3 library for mbed. Early porting.

This port is centered mainly in the platform code. So it should work properly with the provided examples of send_data, device_request, data_points, RCI and firmware_update (stub implementation, not a real one... yet ;-)). Filesystem is not implemented yet, and some examples might need changes.

To run, it needs the following libraries: - mbed - mbed-rtos - EthernetInterface

Find more information (and the source code!) about Etherios Cloud Connector for Embedded here: http://www.etherios.com/products/devicecloud/support/connector and in: http://www.etherios.com

Committer:
spastor
Date:
Tue Dec 03 14:10:48 2013 +0000
Revision:
1:908afea5a49d
Parent:
0:1c358ea10753
Use internal Thread.h instead of Threads.h

Who changed what in which revision?

UserRevisionLine numberNew contents of line
spastor 0:1c358ea10753 1 /*
spastor 0:1c358ea10753 2 * Copyright (c) 2013 Digi International Inc.,
spastor 0:1c358ea10753 3 * All rights not expressly granted are reserved.
spastor 0:1c358ea10753 4 *
spastor 0:1c358ea10753 5 * This Source Code Form is subject to the terms of the Mozilla Public
spastor 0:1c358ea10753 6 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
spastor 0:1c358ea10753 7 * You can obtain one at http://mozilla.org/MPL/2.0/.
spastor 0:1c358ea10753 8 *
spastor 0:1c358ea10753 9 * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
spastor 0:1c358ea10753 10 * =======================================================================
spastor 0:1c358ea10753 11 */
spastor 0:1c358ea10753 12
spastor 0:1c358ea10753 13 /* Example of adding a static buffer (single structure) or static buffer array named my_data
spastor 0:1c358ea10753 14 *
spastor 0:1c358ea10753 15 * In os_intf.h:
spastor 0:1c358ea10753 16 * 1. Add to connector_static_buffer_id_t:
spastor 0:1c358ea10753 17 * named_buffer_id(my_data)
spastor 0:1c358ea10753 18 * - Single buffers share a msg_facility map, and their id's should go up from the bottom (28, 27, etc.)
spastor 0:1c358ea10753 19 * - All arrays should be before single buffers
spastor 0:1c358ea10753 20 *
spastor 0:1c358ea10753 21 * In this file:
spastor 0:1c358ea10753 22 * 2. - If there is a type, add:
spastor 0:1c358ea10753 23 * typedef my_buffer_type_t named_buffer_type(my_data);
spastor 0:1c358ea10753 24 *
spastor 0:1c358ea10753 25 * - If you know size in bytes instead (for example 100 bytes), add:
spastor 0:1c358ea10753 26 * define_sized_buffer_type(my_data, 100);
spastor 0:1c358ea10753 27 *
spastor 0:1c358ea10753 28 * For a single static buffer:
spastor 0:1c358ea10753 29 * 3. Add to connector_static_mem:
spastor 0:1c358ea10753 30 * named_buffer_define(my_data);
spastor 0:1c358ea10753 31 *
spastor 0:1c358ea10753 32 * 4. Add to malloc_static_data():
spastor 0:1c358ea10753 33 * case named_buffer_id(my_data):
spastor 0:1c358ea10753 34 * malloc_named_static_buffer(my_data, size, ptr, status);
spastor 0:1c358ea10753 35 * break;
spastor 0:1c358ea10753 36 *
spastor 0:1c358ea10753 37 * 5. Add to free_static_data():
spastor 0:1c358ea10753 38 * case named_buffer_id(my_data):
spastor 0:1c358ea10753 39 * free_named_static_buffer(my_data);
spastor 0:1c358ea10753 40 * break;
spastor 0:1c358ea10753 41 *
spastor 0:1c358ea10753 42 * For an array of 20 elements (must be <= 32):
spastor 0:1c358ea10753 43 * 3. Add:
spastor 0:1c358ea10753 44 * #define my_data_buffer_cnt 20
spastor 0:1c358ea10753 45 *
spastor 0:1c358ea10753 46 * 4. Add to connector_static_mem:
spastor 0:1c358ea10753 47 * named_buffer_array_define(my_data);
spastor 0:1c358ea10753 48 * named_buffer_map_define(my_data);
spastor 0:1c358ea10753 49 *
spastor 0:1c358ea10753 50 * 5. Add to malloc_static_data():
spastor 0:1c358ea10753 51 * case named_buffer_id(my_data):
spastor 0:1c358ea10753 52 * malloc_named_array_element(my_data, size, ptr, status);
spastor 0:1c358ea10753 53 * break;
spastor 0:1c358ea10753 54 *
spastor 0:1c358ea10753 55 * 6. Add to free_static_data():
spastor 0:1c358ea10753 56 * case named_buffer_id(my_data):
spastor 0:1c358ea10753 57 * free_named_array_element(my_data, ptr);
spastor 0:1c358ea10753 58 * break;
spastor 0:1c358ea10753 59 *
spastor 0:1c358ea10753 60 */
spastor 0:1c358ea10753 61
spastor 0:1c358ea10753 62
spastor 0:1c358ea10753 63 #define named_buffer_type(name) name##_static_buffer_t
spastor 0:1c358ea10753 64 #define named_buffer_decl(name) name
spastor 0:1c358ea10753 65 #define named_buffer_map_decl(name) name##_map
spastor 0:1c358ea10753 66 #define named_buffer_cnt(name) name##_buffer_cnt
spastor 0:1c358ea10753 67 #define named_buffer_define(name) named_buffer_type(name) named_buffer_decl(name)
spastor 0:1c358ea10753 68 #define named_buffer_array_define(name) named_buffer_define(name)[named_buffer_cnt(name)]
spastor 0:1c358ea10753 69 #define named_buffer_map_define(name) uint32_t named_buffer_map_decl(name)
spastor 0:1c358ea10753 70
spastor 0:1c358ea10753 71 #define named_buffer_storage(name) connector_static_mem.named_buffer_decl(name)
spastor 0:1c358ea10753 72 #define named_buffer_map(name) connector_static_mem.named_buffer_map_decl(name)
spastor 0:1c358ea10753 73
spastor 0:1c358ea10753 74 #define define_sized_buffer_type(name, size) typedef struct { char field[(size)]; } named_buffer_type(name)
spastor 0:1c358ea10753 75
spastor 0:1c358ea10753 76 /*** Define types used by static memory system ***/
spastor 0:1c358ea10753 77
spastor 0:1c358ea10753 78 #if defined CONNECTOR_TRANSPORT_TCP
spastor 0:1c358ea10753 79
spastor 0:1c358ea10753 80 #if (defined CONNECTOR_DATA_SERVICE) || (defined CONNECTOR_FILE_SYSTEM) || defined (CONNECTOR_RCI_SERVICE)
spastor 0:1c358ea10753 81 #ifndef CONNECTOR_MSG_MAX_TRANSACTION
spastor 0:1c358ea10753 82 #define CONNECTOR_MSG_MAX_TRANSACTION 1
spastor 0:1c358ea10753 83 #endif
spastor 0:1c358ea10753 84
spastor 0:1c358ea10753 85 #if CONNECTOR_MSG_MAX_TRANSACTION > 32
spastor 0:1c358ea10753 86 #error "CONNECTOR_MSG_MAX_TRANSACTION must be <= 32"
spastor 0:1c358ea10753 87 #endif
spastor 0:1c358ea10753 88
spastor 0:1c358ea10753 89 #define CONNECTOR_MSG_SERVICE
spastor 0:1c358ea10753 90
spastor 0:1c358ea10753 91 #if defined CONNECTOR_RCI_SERVICE
spastor 0:1c358ea10753 92 #define RCI_SERVICE_CNT 1
spastor 0:1c358ea10753 93 #define DATA_BLOCKS_PER_MSG 2
spastor 0:1c358ea10753 94 #else
spastor 0:1c358ea10753 95 #define RCI_SERVICE_CNT 0
spastor 0:1c358ea10753 96 #define DATA_BLOCKS_PER_MSG 1
spastor 0:1c358ea10753 97 #endif
spastor 0:1c358ea10753 98
spastor 0:1c358ea10753 99 #if defined CONNECTOR_DATA_SERVICE
spastor 0:1c358ea10753 100 #define DATA_SERVICE_CNT 1
spastor 0:1c358ea10753 101 #else
spastor 0:1c358ea10753 102 #define DATA_SERVICE_CNT 0
spastor 0:1c358ea10753 103 #endif
spastor 0:1c358ea10753 104
spastor 0:1c358ea10753 105 #if defined CONNECTOR_FILE_SYSTEM
spastor 0:1c358ea10753 106 #define FILE_SYSTEM_CNT 1
spastor 0:1c358ea10753 107 #else
spastor 0:1c358ea10753 108 #define FILE_SYSTEM_CNT 0
spastor 0:1c358ea10753 109 #endif
spastor 0:1c358ea10753 110
spastor 0:1c358ea10753 111 #define msg_facility_buffer_cnt (DATA_SERVICE_CNT + FILE_SYSTEM_CNT + RCI_SERVICE_CNT)
spastor 0:1c358ea10753 112
spastor 0:1c358ea10753 113 #define msg_session_buffer_cnt (CONNECTOR_MSG_MAX_TRANSACTION * msg_facility_buffer_cnt)
spastor 0:1c358ea10753 114 #define msg_service_buffer_cnt msg_session_buffer_cnt
spastor 0:1c358ea10753 115
spastor 0:1c358ea10753 116 #if defined CONNECTOR_DATA_SERVICE
spastor 0:1c358ea10753 117
spastor 0:1c358ea10753 118 #ifndef CONNECTOR_NO_MALLOC_MAX_SEND_SESSIONS
spastor 0:1c358ea10753 119 #define CONNECTOR_NO_MALLOC_MAX_SEND_SESSIONS 1
spastor 0:1c358ea10753 120 #endif
spastor 0:1c358ea10753 121
spastor 0:1c358ea10753 122 #define msg_session_client_buffer_cnt CONNECTOR_NO_MALLOC_MAX_SEND_SESSIONS
spastor 0:1c358ea10753 123 #define put_request_buffer_cnt msg_session_client_buffer_cnt
spastor 0:1c358ea10753 124 typedef data_service_context_t named_buffer_type(put_request);
spastor 0:1c358ea10753 125
spastor 0:1c358ea10753 126 #if defined CONNECTOR_DATA_POINTS
spastor 0:1c358ea10753 127 #define data_point_block_buffer_cnt msg_session_client_buffer_cnt
spastor 0:1c358ea10753 128 typedef data_point_info_t named_buffer_type(data_point_block);
spastor 0:1c358ea10753 129 #endif
spastor 0:1c358ea10753 130 #endif
spastor 0:1c358ea10753 131
spastor 0:1c358ea10753 132 typedef struct
spastor 0:1c358ea10753 133 {
spastor 0:1c358ea10753 134 connector_facility_t fc;
spastor 0:1c358ea10753 135 connector_msg_data_t msg;
spastor 0:1c358ea10753 136
spastor 0:1c358ea10753 137 } named_buffer_type(msg_facility);
spastor 0:1c358ea10753 138
spastor 0:1c358ea10753 139 typedef union
spastor 0:1c358ea10753 140 {
spastor 0:1c358ea10753 141 #if defined CONNECTOR_DATA_SERVICE
spastor 0:1c358ea10753 142 data_service_context_t ds;
spastor 0:1c358ea10753 143 #endif
spastor 0:1c358ea10753 144 #if defined CONNECTOR_FILE_SYSTEM
spastor 0:1c358ea10753 145 fs_context_t fs;
spastor 0:1c358ea10753 146 #endif
spastor 0:1c358ea10753 147
spastor 0:1c358ea10753 148 #if defined CONNECTOR_RCI_SERVICE
spastor 0:1c358ea10753 149 rci_service_data_t rci;
spastor 0:1c358ea10753 150 #endif
spastor 0:1c358ea10753 151 } named_buffer_type(msg_service);
spastor 0:1c358ea10753 152
spastor 0:1c358ea10753 153 #if defined CONNECTOR_COMPRESSION
spastor 0:1c358ea10753 154 #define MSG_SEND_SIZE 0
spastor 0:1c358ea10753 155 #else
spastor 0:1c358ea10753 156 #define MSG_SEND_SIZE MSG_MAX_SEND_PACKET_SIZE
spastor 0:1c358ea10753 157 #endif
spastor 0:1c358ea10753 158 #define MSG_BLOCK_SIZE (sizeof(msg_data_block_t) + sizeof(msg_service_data_t))
spastor 0:1c358ea10753 159 #define MSG_SESSION_CLIENT_SIZE (sizeof(msg_session_t) + MSG_BLOCK_SIZE + MSG_SEND_SIZE)
spastor 0:1c358ea10753 160 #define MSG_SESSION_SIZE (sizeof(msg_session_t) + DATA_BLOCKS_PER_MSG * MSG_BLOCK_SIZE + MSG_SEND_SIZE)
spastor 0:1c358ea10753 161
spastor 0:1c358ea10753 162 define_sized_buffer_type(msg_session, MSG_SESSION_SIZE);
spastor 0:1c358ea10753 163 define_sized_buffer_type(msg_session_client, MSG_SESSION_CLIENT_SIZE);
spastor 0:1c358ea10753 164 #endif
spastor 0:1c358ea10753 165
spastor 0:1c358ea10753 166 typedef struct
spastor 0:1c358ea10753 167 {
spastor 0:1c358ea10753 168 connector_facility_t fc;
spastor 0:1c358ea10753 169 connector_cc_data_t cc;
spastor 0:1c358ea10753 170
spastor 0:1c358ea10753 171 } named_buffer_type(cc_facility);
spastor 0:1c358ea10753 172
spastor 0:1c358ea10753 173 #if defined CONNECTOR_FIRMWARE_SERVICE || defined CONNECTOR_RCI_SERVICE
spastor 0:1c358ea10753 174 typedef struct
spastor 0:1c358ea10753 175 {
spastor 0:1c358ea10753 176 connector_facility_t fc;
spastor 0:1c358ea10753 177 connector_firmware_data_t fw;
spastor 0:1c358ea10753 178
spastor 0:1c358ea10753 179 } named_buffer_type(fw_facility);
spastor 0:1c358ea10753 180 #endif
spastor 0:1c358ea10753 181 #endif /* CONNECTOR_TRANSPORT_TCP */
spastor 0:1c358ea10753 182
spastor 0:1c358ea10753 183 #if (defined CONNECTOR_SHORT_MESSAGE)
spastor 0:1c358ea10753 184
spastor 0:1c358ea10753 185 #ifndef CONNECTOR_SM_MAX_RX_SEGMENTS
spastor 0:1c358ea10753 186 #define CONNECTOR_SM_MAX_RX_SEGMENTS 1
spastor 0:1c358ea10753 187 #endif
spastor 0:1c358ea10753 188
spastor 0:1c358ea10753 189 #ifndef CONNECTOR_SM_MAX_DATA_POINTS_SEGMENTS
spastor 0:1c358ea10753 190 #define CONNECTOR_SM_MAX_DATA_POINTS_SEGMENTS 1
spastor 0:1c358ea10753 191 #endif
spastor 0:1c358ea10753 192
spastor 0:1c358ea10753 193 #define CONNECTOR_MAX_SM_SEGMENTS (CONNECTOR_SM_MAX_RX_SEGMENTS + CONNECTOR_SM_MAX_DATA_POINTS_SEGMENTS)
spastor 0:1c358ea10753 194
spastor 0:1c358ea10753 195 #ifndef CONNECTOR_SM_MAX_SESSIONS
spastor 0:1c358ea10753 196 #define CONNECTOR_SM_MAX_SESSIONS 4
spastor 0:1c358ea10753 197 #endif
spastor 0:1c358ea10753 198
spastor 0:1c358ea10753 199 #if CONNECTOR_SM_MAX_SESSIONS > 32
spastor 0:1c358ea10753 200 #error "CONNECTOR_SM_MAX_SESSIONS must be <= 32"
spastor 0:1c358ea10753 201 #endif
spastor 0:1c358ea10753 202
spastor 0:1c358ea10753 203 #if defined (CONNECTOR_TRANSPORT_UDP) && defined (CONNECTOR_TRANSPORT_SMS)
spastor 0:1c358ea10753 204 #define sm_session_buffer_cnt (4 * CONNECTOR_SM_MAX_SESSIONS)
spastor 0:1c358ea10753 205 #else
spastor 0:1c358ea10753 206 #define sm_session_buffer_cnt (2 * CONNECTOR_SM_MAX_SESSIONS)
spastor 0:1c358ea10753 207 #endif
spastor 0:1c358ea10753 208
spastor 0:1c358ea10753 209 #define sm_packet_buffer_cnt sm_session_buffer_cnt
spastor 0:1c358ea10753 210 #define sm_data_block_buffer_cnt sm_session_buffer_cnt
spastor 0:1c358ea10753 211
spastor 0:1c358ea10753 212 #if defined CONNECTOR_TRANSPORT_UDP
spastor 0:1c358ea10753 213 #define SM_MAX_MTU SM_PACKET_SIZE_UDP
spastor 0:1c358ea10753 214 #else
spastor 0:1c358ea10753 215 #define SM_MAX_MTU SM_PACKET_SIZE_SMS_ENCODED
spastor 0:1c358ea10753 216 #endif
spastor 0:1c358ea10753 217
spastor 0:1c358ea10753 218 typedef connector_sm_session_t named_buffer_type(sm_session);
spastor 0:1c358ea10753 219
spastor 0:1c358ea10753 220 define_sized_buffer_type(sm_packet, 2 * SM_MAX_MTU);
spastor 0:1c358ea10753 221 define_sized_buffer_type(sm_data_block, CONNECTOR_MAX_SM_SEGMENTS * SM_MAX_MTU);
spastor 0:1c358ea10753 222
spastor 0:1c358ea10753 223 #endif
spastor 0:1c358ea10753 224
spastor 0:1c358ea10753 225 typedef connector_data_t named_buffer_type(connector_data);
spastor 0:1c358ea10753 226
spastor 0:1c358ea10753 227
spastor 0:1c358ea10753 228 /*** Declare static memory structure ***/
spastor 0:1c358ea10753 229 static struct
spastor 0:1c358ea10753 230 {
spastor 0:1c358ea10753 231 named_buffer_define(connector_data);
spastor 0:1c358ea10753 232 named_buffer_map_define(msg_facility);
spastor 0:1c358ea10753 233
spastor 0:1c358ea10753 234 #if defined CONNECTOR_TRANSPORT_TCP
spastor 0:1c358ea10753 235 named_buffer_define(cc_facility);
spastor 0:1c358ea10753 236
spastor 0:1c358ea10753 237 #if defined CONNECTOR_FIRMWARE_SERVICE || defined CONNECTOR_RCI_SERVICE
spastor 0:1c358ea10753 238 named_buffer_define(fw_facility);
spastor 0:1c358ea10753 239 #endif
spastor 0:1c358ea10753 240
spastor 0:1c358ea10753 241 #if defined CONNECTOR_MSG_SERVICE
spastor 0:1c358ea10753 242 named_buffer_array_define(msg_facility);
spastor 0:1c358ea10753 243 named_buffer_array_define(msg_session);
spastor 0:1c358ea10753 244 named_buffer_array_define(msg_service);
spastor 0:1c358ea10753 245
spastor 0:1c358ea10753 246 named_buffer_map_define(msg_session);
spastor 0:1c358ea10753 247 named_buffer_map_define(msg_service);
spastor 0:1c358ea10753 248 #endif
spastor 0:1c358ea10753 249
spastor 0:1c358ea10753 250 #if defined CONNECTOR_DATA_SERVICE
spastor 0:1c358ea10753 251 named_buffer_array_define(msg_session_client);
spastor 0:1c358ea10753 252 named_buffer_array_define(put_request);
spastor 0:1c358ea10753 253 named_buffer_map_define(msg_session_client);
spastor 0:1c358ea10753 254 named_buffer_map_define(put_request);
spastor 0:1c358ea10753 255 #if defined CONNECTOR_DATA_POINTS
spastor 0:1c358ea10753 256 named_buffer_array_define(data_point_block);
spastor 0:1c358ea10753 257 named_buffer_map_define(data_point_block);
spastor 0:1c358ea10753 258 #endif
spastor 0:1c358ea10753 259 #endif
spastor 0:1c358ea10753 260 #endif
spastor 0:1c358ea10753 261
spastor 0:1c358ea10753 262 #if defined CONNECTOR_TRANSPORT_UDP || defined CONNECTOR_TRANSPORT_SMS
spastor 0:1c358ea10753 263 named_buffer_array_define(sm_session);
spastor 0:1c358ea10753 264 named_buffer_array_define(sm_packet);
spastor 0:1c358ea10753 265 named_buffer_array_define(sm_data_block);
spastor 0:1c358ea10753 266
spastor 0:1c358ea10753 267 named_buffer_map_define(sm_session);
spastor 0:1c358ea10753 268 named_buffer_map_define(sm_packet);
spastor 0:1c358ea10753 269 named_buffer_map_define(sm_data_block);
spastor 0:1c358ea10753 270 #endif
spastor 0:1c358ea10753 271
spastor 0:1c358ea10753 272 } connector_static_mem;
spastor 0:1c358ea10753 273
spastor 0:1c358ea10753 274 /*** Static memory operations ***/
spastor 0:1c358ea10753 275
spastor 0:1c358ea10753 276 #define static_buffer_release(pmap, idx) (*(pmap) &= (~(1 << (idx))))
spastor 0:1c358ea10753 277
spastor 0:1c358ea10753 278 static int static_buffer_reserve(uint32_t * const pmap, uint32_t const idx)
spastor 0:1c358ea10753 279 {
spastor 0:1c358ea10753 280 int result = -1;
spastor 0:1c358ea10753 281
spastor 0:1c358ea10753 282 if ((*pmap & (1 << idx)) == 0)
spastor 0:1c358ea10753 283 {
spastor 0:1c358ea10753 284 *pmap |= 1 << idx;
spastor 0:1c358ea10753 285 result = idx;
spastor 0:1c358ea10753 286 }
spastor 0:1c358ea10753 287 return result;
spastor 0:1c358ea10753 288 }
spastor 0:1c358ea10753 289
spastor 0:1c358ea10753 290 static int static_buffer_get_avail(uint32_t * const pmap, int max_cnt)
spastor 0:1c358ea10753 291 {
spastor 0:1c358ea10753 292 int idx = -1;
spastor 0:1c358ea10753 293 int i;
spastor 0:1c358ea10753 294
spastor 0:1c358ea10753 295 for (i = 0; i < max_cnt; i++)
spastor 0:1c358ea10753 296 {
spastor 0:1c358ea10753 297 idx = static_buffer_reserve(pmap, i);
spastor 0:1c358ea10753 298 if (idx >= 0)
spastor 0:1c358ea10753 299 break;
spastor 0:1c358ea10753 300 }
spastor 0:1c358ea10753 301 return idx;
spastor 0:1c358ea10753 302 }
spastor 0:1c358ea10753 303
spastor 0:1c358ea10753 304 #define static_buffer_malloc(pmap, name) static_buffer_reserve(pmap, named_buffer_id(name)) >= 0 ? &named_buffer_storage(name) : NULL
spastor 0:1c358ea10753 305 #define static_buffer_free(pmap, name) static_buffer_release(pmap, named_buffer_id(name))
spastor 0:1c358ea10753 306
spastor 0:1c358ea10753 307 #define free_named_array_element(name, ptr) \
spastor 0:1c358ea10753 308 { \
spastor 0:1c358ea10753 309 int idx = ((named_buffer_type(name) *) ptr - (named_buffer_type(name) *) &named_buffer_storage(name)[0]); \
spastor 0:1c358ea10753 310 ASSERT(idx >= 0 && idx < named_buffer_cnt(name)); \
spastor 0:1c358ea10753 311 static_buffer_release(&named_buffer_map(name), idx); \
spastor 0:1c358ea10753 312 }
spastor 0:1c358ea10753 313
spastor 0:1c358ea10753 314 #define malloc_named_static_buffer(name, size, ptr, status) \
spastor 0:1c358ea10753 315 { \
spastor 0:1c358ea10753 316 ASSERT(size == sizeof(named_buffer_type(name))); \
spastor 0:1c358ea10753 317 *ptr = static_buffer_malloc(&named_buffer_map(msg_facility), name); \
spastor 0:1c358ea10753 318 status = *ptr != NULL ? connector_working : connector_pending; \
spastor 0:1c358ea10753 319 }
spastor 0:1c358ea10753 320
spastor 0:1c358ea10753 321
spastor 0:1c358ea10753 322 #define free_named_static_buffer(name) static_buffer_free(&named_buffer_map(msg_facility), name)
spastor 0:1c358ea10753 323
spastor 0:1c358ea10753 324 #define malloc_named_array_element(name, size, ptr, status) \
spastor 0:1c358ea10753 325 { \
spastor 0:1c358ea10753 326 int idx; \
spastor 0:1c358ea10753 327 ASSERT(size <= sizeof(named_buffer_type(name))); \
spastor 0:1c358ea10753 328 idx = static_buffer_get_avail(&named_buffer_map(name), named_buffer_cnt(name)); \
spastor 0:1c358ea10753 329 *ptr = idx >= 0 ? &named_buffer_storage(name)[idx] : NULL; \
spastor 0:1c358ea10753 330 status = *ptr != NULL ? connector_working : connector_pending; \
spastor 0:1c358ea10753 331 }
spastor 0:1c358ea10753 332
spastor 0:1c358ea10753 333 static connector_status_t malloc_static_data(connector_data_t * const connector_ptr, size_t const size, connector_static_buffer_id_t const buffer_id, void ** const ptr)
spastor 0:1c358ea10753 334 {
spastor 0:1c358ea10753 335 connector_status_t status = connector_working;
spastor 0:1c358ea10753 336
spastor 0:1c358ea10753 337 UNUSED_PARAMETER(connector_ptr);
spastor 0:1c358ea10753 338 UNUSED_PARAMETER(size);
spastor 0:1c358ea10753 339
spastor 0:1c358ea10753 340 if (buffer_id != named_buffer_id(connector_data))
spastor 0:1c358ea10753 341 {
spastor 0:1c358ea10753 342 ASSERT(connector_ptr == &named_buffer_storage(connector_data));
spastor 0:1c358ea10753 343 }
spastor 0:1c358ea10753 344
spastor 0:1c358ea10753 345 switch(buffer_id)
spastor 0:1c358ea10753 346 {
spastor 0:1c358ea10753 347 case named_buffer_id(connector_data):
spastor 0:1c358ea10753 348 malloc_named_static_buffer(connector_data, size, ptr, status);
spastor 0:1c358ea10753 349 break;
spastor 0:1c358ea10753 350
spastor 0:1c358ea10753 351 #if defined CONNECTOR_TRANSPORT_TCP
spastor 0:1c358ea10753 352 case named_buffer_id(cc_facility):
spastor 0:1c358ea10753 353 malloc_named_static_buffer(cc_facility, size, ptr, status);
spastor 0:1c358ea10753 354 break;
spastor 0:1c358ea10753 355
spastor 0:1c358ea10753 356 #if defined CONNECTOR_FIRMWARE_SERVICE || defined CONNECTOR_RCI_SERVICE
spastor 0:1c358ea10753 357 case named_buffer_id(fw_facility):
spastor 0:1c358ea10753 358 malloc_named_static_buffer(fw_facility, size, ptr, status);
spastor 0:1c358ea10753 359 break;
spastor 0:1c358ea10753 360 #endif
spastor 0:1c358ea10753 361
spastor 0:1c358ea10753 362 #if defined CONNECTOR_MSG_SERVICE
spastor 0:1c358ea10753 363 case named_buffer_id(msg_facility):
spastor 0:1c358ea10753 364 malloc_named_array_element(msg_facility, size, ptr, status);
spastor 0:1c358ea10753 365 break;
spastor 0:1c358ea10753 366
spastor 0:1c358ea10753 367 case named_buffer_id(msg_session):
spastor 0:1c358ea10753 368 malloc_named_array_element(msg_session, size, ptr, status);
spastor 0:1c358ea10753 369 break;
spastor 0:1c358ea10753 370
spastor 0:1c358ea10753 371 case named_buffer_id(msg_service):
spastor 0:1c358ea10753 372 malloc_named_array_element(msg_service, size, ptr, status);
spastor 0:1c358ea10753 373 break;
spastor 0:1c358ea10753 374
spastor 0:1c358ea10753 375 #if defined CONNECTOR_DATA_SERVICE
spastor 0:1c358ea10753 376 case named_buffer_id(msg_session_client):
spastor 0:1c358ea10753 377 malloc_named_array_element(msg_session_client, size, ptr, status);
spastor 0:1c358ea10753 378 break;
spastor 0:1c358ea10753 379
spastor 0:1c358ea10753 380 case named_buffer_id(put_request):
spastor 0:1c358ea10753 381 malloc_named_array_element(put_request, size, ptr, status);
spastor 0:1c358ea10753 382 break;
spastor 0:1c358ea10753 383
spastor 0:1c358ea10753 384 #if defined CONNECTOR_DATA_POINTS
spastor 0:1c358ea10753 385 case named_buffer_id(data_point_block):
spastor 0:1c358ea10753 386 malloc_named_array_element(data_point_block, size, ptr, status);
spastor 0:1c358ea10753 387 break;
spastor 0:1c358ea10753 388 #endif
spastor 0:1c358ea10753 389 #endif
spastor 0:1c358ea10753 390 #endif
spastor 0:1c358ea10753 391 #endif
spastor 0:1c358ea10753 392
spastor 0:1c358ea10753 393 #if defined CONNECTOR_TRANSPORT_UDP || defined CONNECTOR_TRANSPORT_SMS
spastor 0:1c358ea10753 394 case named_buffer_id(sm_session):
spastor 0:1c358ea10753 395 malloc_named_array_element(sm_session, size, ptr, status);
spastor 0:1c358ea10753 396 break;
spastor 0:1c358ea10753 397
spastor 0:1c358ea10753 398 case named_buffer_id(sm_packet):
spastor 0:1c358ea10753 399 malloc_named_array_element(sm_packet, size, ptr, status);
spastor 0:1c358ea10753 400 break;
spastor 0:1c358ea10753 401
spastor 0:1c358ea10753 402 case named_buffer_id(sm_data_block):
spastor 0:1c358ea10753 403 malloc_named_array_element(sm_data_block, size, ptr, status);
spastor 0:1c358ea10753 404 break;
spastor 0:1c358ea10753 405 #endif
spastor 0:1c358ea10753 406
spastor 0:1c358ea10753 407 default:
spastor 0:1c358ea10753 408 ASSERT(connector_false);
spastor 0:1c358ea10753 409 *ptr = NULL;
spastor 0:1c358ea10753 410 break;
spastor 0:1c358ea10753 411 }
spastor 0:1c358ea10753 412 return status;
spastor 0:1c358ea10753 413 }
spastor 0:1c358ea10753 414
spastor 0:1c358ea10753 415 void free_static_data(connector_data_t * const connector_ptr, connector_static_buffer_id_t const buffer_id, void * const ptr)
spastor 0:1c358ea10753 416 {
spastor 0:1c358ea10753 417 UNUSED_PARAMETER(connector_ptr);
spastor 0:1c358ea10753 418 UNUSED_PARAMETER(ptr);
spastor 0:1c358ea10753 419 ASSERT(connector_ptr == &named_buffer_storage(connector_data));
spastor 0:1c358ea10753 420
spastor 0:1c358ea10753 421 switch(buffer_id)
spastor 0:1c358ea10753 422 {
spastor 0:1c358ea10753 423 case named_buffer_id(connector_data):
spastor 0:1c358ea10753 424 free_named_static_buffer(connector_data);
spastor 0:1c358ea10753 425 break;
spastor 0:1c358ea10753 426
spastor 0:1c358ea10753 427 #if defined CONNECTOR_TRANSPORT_TCP
spastor 0:1c358ea10753 428 case named_buffer_id(cc_facility):
spastor 0:1c358ea10753 429 free_named_static_buffer(cc_facility);
spastor 0:1c358ea10753 430 break;
spastor 0:1c358ea10753 431
spastor 0:1c358ea10753 432 #if defined CONNECTOR_FIRMWARE_SERVICE || defined CONNECTOR_RCI_SERVICE
spastor 0:1c358ea10753 433 case named_buffer_id(fw_facility):
spastor 0:1c358ea10753 434 free_named_static_buffer(fw_facility);
spastor 0:1c358ea10753 435 break;
spastor 0:1c358ea10753 436 #endif
spastor 0:1c358ea10753 437
spastor 0:1c358ea10753 438 #if defined CONNECTOR_MSG_SERVICE
spastor 0:1c358ea10753 439 case named_buffer_id(msg_facility):
spastor 0:1c358ea10753 440 free_named_array_element(msg_facility, ptr);
spastor 0:1c358ea10753 441 break;
spastor 0:1c358ea10753 442
spastor 0:1c358ea10753 443 case named_buffer_id(msg_service):
spastor 0:1c358ea10753 444 free_named_array_element(msg_service, ptr);
spastor 0:1c358ea10753 445 break;
spastor 0:1c358ea10753 446
spastor 0:1c358ea10753 447 #if defined CONNECTOR_DATA_SERVICE
spastor 0:1c358ea10753 448 case named_buffer_id(put_request):
spastor 0:1c358ea10753 449 free_named_array_element(put_request, ptr);
spastor 0:1c358ea10753 450 break;
spastor 0:1c358ea10753 451
spastor 0:1c358ea10753 452 #if defined CONNECTOR_DATA_POINTS
spastor 0:1c358ea10753 453 case named_buffer_id(data_point_block):
spastor 0:1c358ea10753 454 free_named_array_element(data_point_block, ptr);
spastor 0:1c358ea10753 455 break;
spastor 0:1c358ea10753 456 #endif
spastor 0:1c358ea10753 457 #endif
spastor 0:1c358ea10753 458
spastor 0:1c358ea10753 459 case named_buffer_id(msg_session):
spastor 0:1c358ea10753 460 {
spastor 0:1c358ea10753 461 #if defined CONNECTOR_DATA_SERVICE
spastor 0:1c358ea10753 462 named_buffer_type(msg_session_client) * data_ptr = ptr;
spastor 0:1c358ea10753 463
spastor 0:1c358ea10753 464 if ((data_ptr >= &named_buffer_storage(msg_session_client)[0]) &&
spastor 0:1c358ea10753 465 (data_ptr <= &named_buffer_storage(msg_session_client)[named_buffer_cnt(msg_session_client)]))
spastor 0:1c358ea10753 466 {
spastor 0:1c358ea10753 467 free_named_array_element(msg_session_client, ptr);
spastor 0:1c358ea10753 468 }
spastor 0:1c358ea10753 469 else
spastor 0:1c358ea10753 470 #endif
spastor 0:1c358ea10753 471 free_named_array_element(msg_session, ptr);
spastor 0:1c358ea10753 472 }
spastor 0:1c358ea10753 473 break;
spastor 0:1c358ea10753 474 #endif
spastor 0:1c358ea10753 475 #endif
spastor 0:1c358ea10753 476
spastor 0:1c358ea10753 477 #if defined CONNECTOR_TRANSPORT_UDP || defined CONNECTOR_TRANSPORT_SMS
spastor 0:1c358ea10753 478 case named_buffer_id(sm_session):
spastor 0:1c358ea10753 479 free_named_array_element(sm_session, ptr);
spastor 0:1c358ea10753 480 break;
spastor 0:1c358ea10753 481
spastor 0:1c358ea10753 482 case named_buffer_id(sm_packet):
spastor 0:1c358ea10753 483 free_named_array_element(sm_packet, ptr);
spastor 0:1c358ea10753 484 break;
spastor 0:1c358ea10753 485
spastor 0:1c358ea10753 486 case named_buffer_id(sm_data_block):
spastor 0:1c358ea10753 487 free_named_array_element(sm_data_block, ptr);
spastor 0:1c358ea10753 488 break;
spastor 0:1c358ea10753 489 #endif
spastor 0:1c358ea10753 490
spastor 0:1c358ea10753 491 default:
spastor 0:1c358ea10753 492 break;
spastor 0:1c358ea10753 493 }
spastor 0:1c358ea10753 494 }
spastor 0:1c358ea10753 495