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 #include "debug.h"
spastor 0:1c358ea10753 13
spastor 0:1c358ea10753 14 /* facility opcodes */
spastor 0:1c358ea10753 15 #define E_MSG_MT2_MSG_NUM 0x0000
spastor 0:1c358ea10753 16 #define E_MSG_FAC_FW_NUM 0x0070
spastor 0:1c358ea10753 17 #define E_MSG_FAC_RCI_NUM 0x00a0
spastor 0:1c358ea10753 18 #define E_MSG_FAC_MSG_NUM 0x00c0
spastor 0:1c358ea10753 19 #define E_MSG_FAC_DEV_LOOP_NUM 0xff00
spastor 0:1c358ea10753 20 #define E_MSG_FAC_CC_NUM 0xffff
spastor 0:1c358ea10753 21
spastor 0:1c358ea10753 22 #define named_buffer_id(name) name##_static_buffer_id
spastor 0:1c358ea10753 23 typedef enum
spastor 0:1c358ea10753 24 {
spastor 0:1c358ea10753 25 named_buffer_id(none) = 0,
spastor 0:1c358ea10753 26 named_buffer_id(msg_facility),
spastor 0:1c358ea10753 27 named_buffer_id(msg_session),
spastor 0:1c358ea10753 28 named_buffer_id(msg_service),
spastor 0:1c358ea10753 29 named_buffer_id(msg_session_client),
spastor 0:1c358ea10753 30 named_buffer_id(put_request),
spastor 0:1c358ea10753 31 named_buffer_id(sm_session),
spastor 0:1c358ea10753 32 named_buffer_id(sm_data_block),
spastor 0:1c358ea10753 33 named_buffer_id(sm_packet),
spastor 0:1c358ea10753 34 named_buffer_id(data_point_block),
spastor 0:1c358ea10753 35 named_buffer_id(connector_data) = 29,
spastor 0:1c358ea10753 36 named_buffer_id(cc_facility) = 30,
spastor 0:1c358ea10753 37 named_buffer_id(fw_facility) = 31
spastor 0:1c358ea10753 38
spastor 0:1c358ea10753 39 } connector_static_buffer_id_t;
spastor 0:1c358ea10753 40
spastor 0:1c358ea10753 41 #ifdef CONNECTOR_NO_MALLOC
spastor 0:1c358ea10753 42 static connector_status_t malloc_static_data(connector_data_t * const connector_ptr,
spastor 0:1c358ea10753 43 size_t const size,
spastor 0:1c358ea10753 44 connector_static_buffer_id_t const buffer_id,
spastor 0:1c358ea10753 45 void ** const ptr);
spastor 0:1c358ea10753 46
spastor 0:1c358ea10753 47 static void free_static_data(connector_data_t * const connector_ptr,
spastor 0:1c358ea10753 48 connector_static_buffer_id_t const buffer_id,
spastor 0:1c358ea10753 49 void * const ptr);
spastor 0:1c358ea10753 50 #endif
spastor 0:1c358ea10753 51
spastor 0:1c358ea10753 52
spastor 0:1c358ea10753 53 static connector_callback_status_t connector_callback(connector_callback_t const callback, connector_class_id_t const class_id, connector_request_id_t const request_id,
spastor 0:1c358ea10753 54 void * const data)
spastor 0:1c358ea10753 55 {
spastor 0:1c358ea10753 56 connector_callback_status_t status = callback(class_id, request_id, data);
spastor 0:1c358ea10753 57
spastor 0:1c358ea10753 58 switch (status)
spastor 0:1c358ea10753 59 {
spastor 0:1c358ea10753 60 case connector_callback_continue:
spastor 0:1c358ea10753 61 case connector_callback_busy:
spastor 0:1c358ea10753 62 case connector_callback_error:
spastor 0:1c358ea10753 63 break;
spastor 0:1c358ea10753 64
spastor 0:1c358ea10753 65 case connector_callback_unrecognized:
spastor 0:1c358ea10753 66 connector_debug_printf("connector_callback : callback returns unrecognized request for request=%d class_id = %d\n",
spastor 0:1c358ea10753 67 request_id.config_request, class_id);
spastor 0:1c358ea10753 68 break;
spastor 0:1c358ea10753 69
spastor 0:1c358ea10753 70 case connector_callback_abort:
spastor 0:1c358ea10753 71 connector_debug_printf("connector_callback: callback for class id = %d request id = %d returned abort\n", class_id, request_id.config_request);
spastor 0:1c358ea10753 72 break;
spastor 0:1c358ea10753 73
spastor 0:1c358ea10753 74 default:
spastor 0:1c358ea10753 75 connector_debug_printf("connector_callback: callback for class id = %d request id = %d returned invalid return code %d\n", class_id, request_id.config_request, status);
spastor 0:1c358ea10753 76 status = connector_callback_abort;
spastor 0:1c358ea10753 77 break;
spastor 0:1c358ea10753 78 }
spastor 0:1c358ea10753 79
spastor 0:1c358ea10753 80 return status;
spastor 0:1c358ea10753 81 }
spastor 0:1c358ea10753 82
spastor 0:1c358ea10753 83
spastor 0:1c358ea10753 84 static connector_status_t get_system_time(connector_data_t * const connector_ptr, unsigned long * const uptime)
spastor 0:1c358ea10753 85 {
spastor 0:1c358ea10753 86 connector_status_t result = connector_abort;
spastor 0:1c358ea10753 87 connector_callback_status_t status;
spastor 0:1c358ea10753 88 connector_request_id_t request_id;
spastor 0:1c358ea10753 89 connector_os_system_up_time_t data;
spastor 0:1c358ea10753 90
spastor 0:1c358ea10753 91 *uptime = 0;
spastor 0:1c358ea10753 92
spastor 0:1c358ea10753 93 /* Call callback to get system up time in second */
spastor 0:1c358ea10753 94 request_id.os_request = connector_request_id_os_system_up_time;
spastor 0:1c358ea10753 95 status = connector_callback(connector_ptr->callback, connector_class_id_operating_system, request_id, &data);
spastor 0:1c358ea10753 96 switch (status)
spastor 0:1c358ea10753 97 {
spastor 0:1c358ea10753 98 case connector_callback_continue:
spastor 0:1c358ea10753 99 /* coverity[uninit_use] */
spastor 0:1c358ea10753 100 *uptime = data.sys_uptime;
spastor 0:1c358ea10753 101 result = connector_working;
spastor 0:1c358ea10753 102 break;
spastor 0:1c358ea10753 103 case connector_callback_abort:
spastor 0:1c358ea10753 104 break;
spastor 0:1c358ea10753 105 default:
spastor 0:1c358ea10753 106 ASSERT(connector_false);
spastor 0:1c358ea10753 107 break;
spastor 0:1c358ea10753 108 }
spastor 0:1c358ea10753 109
spastor 0:1c358ea10753 110 return result;
spastor 0:1c358ea10753 111 }
spastor 0:1c358ea10753 112
spastor 0:1c358ea10753 113 #ifndef CONNECTOR_NO_MALLOC
spastor 0:1c358ea10753 114 static connector_status_t malloc_cb(connector_callback_t const callback, size_t const length, void ** ptr)
spastor 0:1c358ea10753 115 {
spastor 0:1c358ea10753 116 connector_status_t result = connector_working;
spastor 0:1c358ea10753 117 connector_callback_status_t status;
spastor 0:1c358ea10753 118 connector_os_malloc_t data;
spastor 0:1c358ea10753 119 connector_request_id_t request_id;
spastor 0:1c358ea10753 120
spastor 0:1c358ea10753 121 request_id.os_request = connector_request_id_os_malloc;
spastor 0:1c358ea10753 122 data.size = length;
spastor 0:1c358ea10753 123 data.ptr = *ptr = NULL;
spastor 0:1c358ea10753 124
spastor 0:1c358ea10753 125 status = connector_callback(callback, connector_class_id_operating_system, request_id, &data);
spastor 0:1c358ea10753 126 switch (status)
spastor 0:1c358ea10753 127 {
spastor 0:1c358ea10753 128 case connector_callback_continue:
spastor 0:1c358ea10753 129 if (data.ptr == NULL)
spastor 0:1c358ea10753 130 {
spastor 0:1c358ea10753 131 result = (notify_error_status(callback, connector_class_id_operating_system, request_id, connector_invalid_data) == connector_working) ? connector_pending : connector_abort;
spastor 0:1c358ea10753 132 }
spastor 0:1c358ea10753 133 else
spastor 0:1c358ea10753 134 {
spastor 0:1c358ea10753 135 *ptr = data.ptr;
spastor 0:1c358ea10753 136 }
spastor 0:1c358ea10753 137 break;
spastor 0:1c358ea10753 138
spastor 0:1c358ea10753 139 case connector_callback_busy:
spastor 0:1c358ea10753 140 result = connector_pending;
spastor 0:1c358ea10753 141 break;
spastor 0:1c358ea10753 142
spastor 0:1c358ea10753 143 case connector_callback_abort:
spastor 0:1c358ea10753 144 case connector_callback_unrecognized:
spastor 0:1c358ea10753 145 case connector_callback_error:
spastor 0:1c358ea10753 146 result = connector_abort;
spastor 0:1c358ea10753 147 break;
spastor 0:1c358ea10753 148 }
spastor 0:1c358ea10753 149 return result;
spastor 0:1c358ea10753 150 }
spastor 0:1c358ea10753 151
spastor 0:1c358ea10753 152 static connector_status_t malloc_data(connector_data_t * const connector_ptr, size_t const length, void ** ptr)
spastor 0:1c358ea10753 153 {
spastor 0:1c358ea10753 154 return malloc_cb(connector_ptr->callback, length, ptr);
spastor 0:1c358ea10753 155 }
spastor 0:1c358ea10753 156
spastor 0:1c358ea10753 157 static connector_status_t free_data(connector_data_t * const connector_ptr, void * const ptr)
spastor 0:1c358ea10753 158 {
spastor 0:1c358ea10753 159 connector_status_t result = connector_working;
spastor 0:1c358ea10753 160 connector_request_id_t request_id;
spastor 0:1c358ea10753 161 connector_os_free_t data;
spastor 0:1c358ea10753 162
spastor 0:1c358ea10753 163 request_id.os_request = connector_request_id_os_free;
spastor 0:1c358ea10753 164 data.ptr = ptr;
spastor 0:1c358ea10753 165
spastor 0:1c358ea10753 166 {
spastor 0:1c358ea10753 167 connector_callback_status_t const callback_status = connector_callback(connector_ptr->callback, connector_class_id_operating_system, request_id, &data);
spastor 0:1c358ea10753 168 switch (callback_status)
spastor 0:1c358ea10753 169 {
spastor 0:1c358ea10753 170 case connector_callback_continue:
spastor 0:1c358ea10753 171 break;
spastor 0:1c358ea10753 172 default:
spastor 0:1c358ea10753 173 result = connector_abort;
spastor 0:1c358ea10753 174 break;
spastor 0:1c358ea10753 175 }
spastor 0:1c358ea10753 176 }
spastor 0:1c358ea10753 177
spastor 0:1c358ea10753 178 return result;
spastor 0:1c358ea10753 179 }
spastor 0:1c358ea10753 180 #endif
spastor 0:1c358ea10753 181
spastor 0:1c358ea10753 182
spastor 0:1c358ea10753 183 static connector_status_t malloc_data_buffer(connector_data_t * const connector_ptr, size_t const length, connector_static_buffer_id_t id, void ** ptr)
spastor 0:1c358ea10753 184 {
spastor 0:1c358ea10753 185 connector_status_t status;
spastor 0:1c358ea10753 186
spastor 0:1c358ea10753 187 #ifndef CONNECTOR_NO_MALLOC
spastor 0:1c358ea10753 188 UNUSED_PARAMETER(id);
spastor 0:1c358ea10753 189 status = malloc_data(connector_ptr, length, ptr);
spastor 0:1c358ea10753 190 #else
spastor 0:1c358ea10753 191 status = malloc_static_data(connector_ptr, length, id, ptr);
spastor 0:1c358ea10753 192 #endif
spastor 0:1c358ea10753 193 return status;
spastor 0:1c358ea10753 194 }
spastor 0:1c358ea10753 195
spastor 0:1c358ea10753 196 static connector_status_t free_data_buffer(connector_data_t * const connector_ptr, connector_static_buffer_id_t id, void * const ptr)
spastor 0:1c358ea10753 197 {
spastor 0:1c358ea10753 198 connector_status_t status = connector_working;
spastor 0:1c358ea10753 199
spastor 0:1c358ea10753 200 #ifndef CONNECTOR_NO_MALLOC
spastor 0:1c358ea10753 201 UNUSED_PARAMETER(id);
spastor 0:1c358ea10753 202 status = free_data(connector_ptr, ptr);
spastor 0:1c358ea10753 203 #else
spastor 0:1c358ea10753 204 free_static_data(connector_ptr, id, ptr);
spastor 0:1c358ea10753 205 #endif
spastor 0:1c358ea10753 206
spastor 0:1c358ea10753 207 return status;
spastor 0:1c358ea10753 208 }
spastor 0:1c358ea10753 209
spastor 0:1c358ea10753 210 static connector_status_t yield_process(connector_data_t * const connector_ptr, connector_status_t const status)
spastor 0:1c358ea10753 211 {
spastor 0:1c358ea10753 212 connector_status_t result = connector_working;
spastor 0:1c358ea10753 213
spastor 0:1c358ea10753 214 {
spastor 0:1c358ea10753 215 connector_request_id_t request_id;
spastor 0:1c358ea10753 216 connector_os_yield_t data;
spastor 0:1c358ea10753 217 connector_callback_status_t callback_status;
spastor 0:1c358ea10753 218
spastor 0:1c358ea10753 219 request_id.os_request = connector_request_id_os_yield;
spastor 0:1c358ea10753 220 data.status = status;
spastor 0:1c358ea10753 221
spastor 0:1c358ea10753 222 callback_status = connector_callback(connector_ptr->callback, connector_class_id_operating_system, request_id, &data);
spastor 0:1c358ea10753 223
spastor 0:1c358ea10753 224 switch (callback_status)
spastor 0:1c358ea10753 225 {
spastor 0:1c358ea10753 226 case connector_callback_continue:
spastor 0:1c358ea10753 227 break;
spastor 0:1c358ea10753 228 default:
spastor 0:1c358ea10753 229 result = connector_abort;
spastor 0:1c358ea10753 230 break;
spastor 0:1c358ea10753 231 }
spastor 0:1c358ea10753 232 }
spastor 0:1c358ea10753 233
spastor 0:1c358ea10753 234 return result;
spastor 0:1c358ea10753 235 }
spastor 0:1c358ea10753 236
spastor 0:1c358ea10753 237 static connector_status_t connector_reboot(connector_data_t * const connector_ptr)
spastor 0:1c358ea10753 238 {
spastor 0:1c358ea10753 239 connector_status_t result;
spastor 0:1c358ea10753 240
spastor 0:1c358ea10753 241 connector_callback_status_t status = connector_callback_continue;
spastor 0:1c358ea10753 242 connector_request_id_t request_id;
spastor 0:1c358ea10753 243
spastor 0:1c358ea10753 244 connector_class_id_t class_id = connector_class_id_operating_system;
spastor 0:1c358ea10753 245 request_id.os_request = connector_request_id_os_reboot;
spastor 0:1c358ea10753 246
spastor 0:1c358ea10753 247 /* Device Cloud reboots us */
spastor 0:1c358ea10753 248
spastor 0:1c358ea10753 249 status = connector_callback(connector_ptr->callback, class_id, request_id, NULL);
spastor 0:1c358ea10753 250 switch (status)
spastor 0:1c358ea10753 251 {
spastor 0:1c358ea10753 252 case connector_callback_continue:
spastor 0:1c358ea10753 253 result = connector_working;
spastor 0:1c358ea10753 254 break;
spastor 0:1c358ea10753 255 case connector_callback_busy:
spastor 0:1c358ea10753 256 result = connector_pending;
spastor 0:1c358ea10753 257 break;
spastor 0:1c358ea10753 258 default:
spastor 0:1c358ea10753 259 result = connector_abort;
spastor 0:1c358ea10753 260 break;
spastor 0:1c358ea10753 261 }
spastor 0:1c358ea10753 262
spastor 0:1c358ea10753 263 return result;
spastor 0:1c358ea10753 264
spastor 0:1c358ea10753 265 }
spastor 0:1c358ea10753 266