Helper library to use modem_ref driver.

Dependencies:   WizziCom WizziDebug ram_fs modem_ref

Dependents:   D7A_1x_demo_sensors_v3 D7A_1x_demo_send_file_data_and_forget D7A_1x_demo_send_file_data D7A_1x_demo_receive_file_data ... more

Committer:
Jeej
Date:
Tue Apr 02 08:54:46 2019 +0000
Revision:
57:d6b0320051e8
Parent:
49:035512e64fdd
Updated WizziDebug

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jeej 0:e9dd36a15d07 1 #include "modem_ref_helper.h"
Jeej 0:e9dd36a15d07 2
Jeej 0:e9dd36a15d07 3 #if 0
Jeej 0:e9dd36a15d07 4 #define HELPER_PRINT(...) PRINT(__VA_ARGS__)
Jeej 0:e9dd36a15d07 5 #else
Jeej 0:e9dd36a15d07 6 #define HELPER_PRINT(...);
Jeej 0:e9dd36a15d07 7 #endif
Jeej 0:e9dd36a15d07 8
Jeej 28:d3b2889f9fab 9 #define MODEM_VERSION_MAJOR 5
Jeej 45:382159015b55 10 #define MODEM_VERSION_MINOR 0
Jeej 45:382159015b55 11 #define MODEM_VERSION_PATCH 36
Jeej 47:cf88f0f370cb 12 #define MODEM_DEVICE_ID 0x00001001
Jeej 15:c90efeb6bd6a 13
Jeej 0:e9dd36a15d07 14 static WizziCom* g_modem_com;
Jeej 44:7563b8e53e1d 15 static Semaphore g_modem_ready;
Jeej 44:7563b8e53e1d 16 static int8_t g_err;
Jeej 0:e9dd36a15d07 17
Jeej 43:90c9221c1430 18 void modem_print_error(uint8_t itf, int8_t error)
Jeej 0:e9dd36a15d07 19 {
Jeej 48:beb06c0bdb1e 20 if (ALP_ERR_ITF_START >= error && ALP_ERR_ITF_END < error)
Jeej 0:e9dd36a15d07 21 {
Jeej 43:90c9221c1430 22 error -= ALP_ERR_ITF_START;
Jeej 43:90c9221c1430 23 // Interface specific error
Jeej 43:90c9221c1430 24 if (ALP_ITF_TYPE_HOST == itf)
Jeej 43:90c9221c1430 25 {
Jeej 43:90c9221c1430 26 PRINT("ITF[%02X] Error %d\r\n", itf, error);
Jeej 43:90c9221c1430 27 }
Jeej 43:90c9221c1430 28 else if (ALP_ITF_TYPE_COM == itf)
Jeej 43:90c9221c1430 29 {
Jeej 43:90c9221c1430 30 PRINT("ITF[%02X] Error %d\r\n", itf, error);
Jeej 43:90c9221c1430 31 }
Jeej 43:90c9221c1430 32 else if (ALP_ITF_TYPE_D7A == itf)
Jeej 43:90c9221c1430 33 {
Jeej 43:90c9221c1430 34 PRINT("ITF[%02X] ", itf);
Jeej 43:90c9221c1430 35 switch (error)
Jeej 43:90c9221c1430 36 {
Jeej 43:90c9221c1430 37 /// No error
Jeej 43:90c9221c1430 38 case D7A_ERROR_NO: // = 0,
Jeej 43:90c9221c1430 39 PRINT("D7A_ERROR_NO\r\n");
Jeej 43:90c9221c1430 40 break;
Jeej 43:90c9221c1430 41 /// Resource busy
Jeej 43:90c9221c1430 42 case D7A_ERROR_BUSY: // = -1,
Jeej 43:90c9221c1430 43 PRINT("D7A_ERROR_BUSY\r\n");
Jeej 43:90c9221c1430 44 break;
Jeej 43:90c9221c1430 45 /// Bad parameter
Jeej 43:90c9221c1430 46 case D7A_ERROR_BAD_PARAM: // = -2,
Jeej 43:90c9221c1430 47 PRINT("D7A_ERROR_BAD_PARAM\r\n");
Jeej 43:90c9221c1430 48 break;
Jeej 43:90c9221c1430 49 /// Duty cycle limit overflow
Jeej 43:90c9221c1430 50 case D7A_ERROR_DUTY_CYCLE: // = -3,
Jeej 43:90c9221c1430 51 PRINT("D7A_ERROR_DUTY_CYCLE\r\n");
Jeej 43:90c9221c1430 52 break;
Jeej 43:90c9221c1430 53 /// CCA timeout
Jeej 43:90c9221c1430 54 case D7A_ERROR_CCA_TO: // = -4,
Jeej 43:90c9221c1430 55 PRINT("D7A_ERROR_CCA_TO\r\n");
Jeej 43:90c9221c1430 56 break;
Jeej 43:90c9221c1430 57 /// Security frame counter overflow
Jeej 43:90c9221c1430 58 case D7A_ERROR_NLS_KEY: // = -5,
Jeej 43:90c9221c1430 59 PRINT("D7A_ERROR_NLS_KEY\r\n");
Jeej 43:90c9221c1430 60 break;
Jeej 43:90c9221c1430 61 /// TX stream underflow
Jeej 43:90c9221c1430 62 case D7A_ERROR_TX_UDF: // = -6,
Jeej 43:90c9221c1430 63 PRINT("D7A_ERROR_TX_UDF\r\n");
Jeej 43:90c9221c1430 64 break;
Jeej 43:90c9221c1430 65 /// RX stream overflow
Jeej 43:90c9221c1430 66 case D7A_ERROR_RX_OVF: // = -7,
Jeej 43:90c9221c1430 67 PRINT("D7A_ERROR_RX_OVF\r\n");
Jeej 43:90c9221c1430 68 break;
Jeej 43:90c9221c1430 69 /// RX checksum
Jeej 43:90c9221c1430 70 case D7A_ERROR_RX_CRC: // = -8,
Jeej 43:90c9221c1430 71 PRINT("D7A_ERROR_RX_CRC\r\n");
Jeej 43:90c9221c1430 72 break;
Jeej 43:90c9221c1430 73 /// Abort
Jeej 43:90c9221c1430 74 case D7A_ERROR_ABORT: // = -9,
Jeej 43:90c9221c1430 75 PRINT("D7A_ERROR_ABORT\r\n");
Jeej 43:90c9221c1430 76 break;
Jeej 43:90c9221c1430 77 /// No ACK received
Jeej 43:90c9221c1430 78 case D7A_ERROR_NO_ACK: // = -10,
Jeej 43:90c9221c1430 79 PRINT("D7A_ERROR_NO_ACK\r\n");
Jeej 43:90c9221c1430 80 break;
Jeej 43:90c9221c1430 81 /// RX timeout
Jeej 43:90c9221c1430 82 case D7A_ERROR_RX_TO: // = -11,
Jeej 43:90c9221c1430 83 PRINT("D7A_ERROR_RX_TO\r\n");
Jeej 43:90c9221c1430 84 break;
Jeej 43:90c9221c1430 85 default:
Jeej 43:90c9221c1430 86 PRINT("Unknown Error %d\r\n", error);
Jeej 43:90c9221c1430 87 break;
Jeej 43:90c9221c1430 88 }
Jeej 43:90c9221c1430 89 }
Jeej 43:90c9221c1430 90 else if (ALP_ITF_TYPE_LWAN == itf)
Jeej 43:90c9221c1430 91 {
Jeej 43:90c9221c1430 92 PRINT("ITF[%02X] Error %d\r\n", itf, error);
Jeej 43:90c9221c1430 93 }
Jeej 43:90c9221c1430 94 else
Jeej 43:90c9221c1430 95 {
Jeej 43:90c9221c1430 96 PRINT("ITF[%02X] Error %d\r\n", itf, error);
Jeej 43:90c9221c1430 97 }
Jeej 0:e9dd36a15d07 98 }
Jeej 43:90c9221c1430 99 else
Jeej 0:e9dd36a15d07 100 {
Jeej 43:90c9221c1430 101 PRINT("ALP: ");
Jeej 43:90c9221c1430 102 switch (error)
Jeej 43:90c9221c1430 103 {
Jeej 43:90c9221c1430 104 // Not really errors, more like status
Jeej 43:90c9221c1430 105 case ALP_ERR_ITF_FULL: // 0x02: For interfaces supporting buffering, indicates buffer reached maximum capacity (no data loss)
Jeej 43:90c9221c1430 106 PRINT("ALP_ERR_ITF_FULL\r\n");
Jeej 43:90c9221c1430 107 break;
Jeej 43:90c9221c1430 108 case ALP_ERR_PARTIAL_COMPLETION: // 0x01: Action received and partially completed at response. To be completed after response
Jeej 43:90c9221c1430 109 PRINT("ALP_ERR_PARTIAL_COMPLETION\r\n");
Jeej 43:90c9221c1430 110 break;
Jeej 43:90c9221c1430 111
Jeej 43:90c9221c1430 112 // ALP Errors
Jeej 43:90c9221c1430 113 case ALP_ERR_NONE: // 0x00: Action completed (OK)
Jeej 43:90c9221c1430 114 PRINT("ALP_ERR_NONE\r\n");
Jeej 43:90c9221c1430 115 break;
Jeej 43:90c9221c1430 116 case ALP_ERR_FILE_NOT_FOUND: // 0xFF: Error access file: File ID does not exist
Jeej 43:90c9221c1430 117 PRINT("ALP_ERR_FILE_NOT_FOUND\r\n");
Jeej 43:90c9221c1430 118 break;
Jeej 43:90c9221c1430 119 case ALP_ERR_FILE_EXIST: // 0xFE: Error create file: File ID already exists
Jeej 43:90c9221c1430 120 PRINT("ALP_ERR_FILE_EXIST\r\n");
Jeej 43:90c9221c1430 121 break;
Jeej 43:90c9221c1430 122 case ALP_ERR_FILE_NOT_RESTORABLE: // 0xFD: Error restore file: File is not restorable
Jeej 43:90c9221c1430 123 PRINT("ALP_ERR_FILE_NOT_RESTORABLEr\n");
Jeej 43:90c9221c1430 124 break;
Jeej 43:90c9221c1430 125 case ALP_ERR_PERMISSION_DENIED: // 0xFC: Error access file: Insufficient permissions
Jeej 43:90c9221c1430 126 PRINT("ALP_ERR_PERMISSION_DENIED\r\n");
Jeej 43:90c9221c1430 127 break;
Jeej 43:90c9221c1430 128 case ALP_ERR_LENGTH_OVERFLOW: // 0xFB: Error create file: Supplied length (in header) is beyond file limits
Jeej 43:90c9221c1430 129 PRINT("ALP_ERR_LENGTH_OVERFLOW\r\n");
Jeej 43:90c9221c1430 130 break;
Jeej 43:90c9221c1430 131 case ALP_ERR_ALLOC_OVERFLOW: // 0xFA: Error create file: Supplied allocation (in header) is beyond file limits
Jeej 43:90c9221c1430 132 PRINT("ALP_ERR_ALLOC_OVERFLOW\r\n");
Jeej 43:90c9221c1430 133 break;
Jeej 43:90c9221c1430 134 case ALP_ERR_OFFSET_OVERFLOW: // 0xF9: Error write: Supplied start offset is out of bounds of file allocation
Jeej 43:90c9221c1430 135 PRINT("ALP_ERR_OFFSET_OVERFLOW\r\n");
Jeej 43:90c9221c1430 136 break;
Jeej 43:90c9221c1430 137 case ALP_ERR_WRITE_OVERFLOW: // 0xF8: Error complete write: Supplied data goes beyond file allocation
Jeej 43:90c9221c1430 138 PRINT("ALP_ERR_WRITE_OVERFLOW\r\n");
Jeej 43:90c9221c1430 139 break;
Jeej 43:90c9221c1430 140 case ALP_ERR_WRITE_ERROR: // 0xF7: Error write: impossible to write in storage location
Jeej 43:90c9221c1430 141 PRINT("ALP_ERR_WRITE_ERROR\r\n");
Jeej 43:90c9221c1430 142 break;
Jeej 43:90c9221c1430 143 case ALP_ERR_OPERATION_UNKNOWN: // 0xF6: Error unknown Operation
Jeej 43:90c9221c1430 144 PRINT("ALP_ERR_OPERATION_UNKNOWN\r\n");
Jeej 43:90c9221c1430 145 break;
Jeej 43:90c9221c1430 146 case ALP_ERR_OPERAND_INCOMPLETE: // 0xF5: Error incomplete Operand
Jeej 43:90c9221c1430 147 PRINT("ALP_ERR_OPERAND_INCOMPLETE\r\n");
Jeej 43:90c9221c1430 148 break;
Jeej 43:90c9221c1430 149 case ALP_ERR_OPERAND_WRONG_FORMAT: // 0xF4: Error wrong Operand format
Jeej 43:90c9221c1430 150 PRINT("ALP_ERR_OPERAND_WRONG_FORMAT\r\n");
Jeej 43:90c9221c1430 151 break;
Jeej 43:90c9221c1430 152 case ALP_ERR_ITF_INVALID: // 0xF3: Error invalid interface
Jeej 43:90c9221c1430 153 PRINT("ALP_ERR_ITF_INVALID\r\n");
Jeej 43:90c9221c1430 154 break;
Jeej 43:90c9221c1430 155 case ALP_ERR_ITF_OVERFLOW: // 0xF2: Error interface overflown (i.e. resources exhausted, buffer full with data discarded)
Jeej 43:90c9221c1430 156 PRINT("ALP_ERR_ITF_OVERFLOW\r\n");
Jeej 43:90c9221c1430 157 break;
Jeej 43:90c9221c1430 158 case ALP_ERR_QUERY_FAIL: // 0xF1: (Group of) Query result was false (Informative error code).
Jeej 43:90c9221c1430 159 PRINT("ALP_ERR_QUERY_FAIL\r\n");
Jeej 43:90c9221c1430 160 break;
Jeej 48:beb06c0bdb1e 161 case ALP_ERR_ITF_NOT_SPECIFIED:
Jeej 48:beb06c0bdb1e 162 PRINT("ALP_ERR_ITF_NOT_SPECIFIED\r\n");
Jeej 48:beb06c0bdb1e 163 break;
Jeej 43:90c9221c1430 164
Jeej 43:90c9221c1430 165 // Other Errors
Jeej 43:90c9221c1430 166 case ALP_ERR_UNKNOWN: // 0x80: Unknown error
Jeej 43:90c9221c1430 167 PRINT("ALP_ERR_UNKNOWN\r\n");
Jeej 43:90c9221c1430 168 break;
Jeej 43:90c9221c1430 169 case ALP_ERR_FS_TIMEOUT: // 0x81: Internal FS Error
Jeej 43:90c9221c1430 170 PRINT("ALP_ERR_FS_TIMEOUT\r\n");
Jeej 43:90c9221c1430 171 break;
Jeej 43:90c9221c1430 172 case ALP_ERR_ITF_UNKNOWN: // 0x82: Unknown Interface
Jeej 43:90c9221c1430 173 PRINT("ALP_ERR_ITF_UNKNOWN\r\n");
Jeej 43:90c9221c1430 174 break;
Jeej 43:90c9221c1430 175 case ALP_ERR_ITF_TIMEOUT: // 0x83: Internal ITF Error
Jeej 43:90c9221c1430 176 PRINT("ALP_ERR_ITF_TIMEOUT\r\n");
Jeej 43:90c9221c1430 177 break;
Jeej 43:90c9221c1430 178 default:
Jeej 43:90c9221c1430 179 PRINT("Unknown Error %d\r\n", error);
Jeej 43:90c9221c1430 180 break;
Jeej 43:90c9221c1430 181 }
Jeej 0:e9dd36a15d07 182 }
Jeej 0:e9dd36a15d07 183 }
Jeej 0:e9dd36a15d07 184
Jeej 1:0ec0bae00588 185 int my_alp_itf_d7a_cfg_size(d7a_sp_cfg_t* cfg)
Jeej 1:0ec0bae00588 186 {
Jeej 1:0ec0bae00588 187 int size = sizeof(d7a_sp_cfg_t) - sizeof(d7a_addressee_t);
Jeej 1:0ec0bae00588 188 size += D7A_ADDR_LEN(cfg->addressee.ctrl);
Jeej 1:0ec0bae00588 189 return size;
Jeej 1:0ec0bae00588 190 }
Jeej 1:0ec0bae00588 191
Jeej 0:e9dd36a15d07 192 // ============================================================}}}
Jeej 0:e9dd36a15d07 193
Jeej 0:e9dd36a15d07 194 // Serial adapters to WizziLab's own architecture
Jeej 0:e9dd36a15d07 195 // ============================================================{{{
Jeej 0:e9dd36a15d07 196
Jeej 1:0ec0bae00588 197 static void modem_serial_input(WizziCom* com, WizziComPacket_t* pkt)
Jeej 0:e9dd36a15d07 198 {
Jeej 0:e9dd36a15d07 199 modem_input(wizzicom_type_to_flow(pkt->type), pkt->data, pkt->length);
Jeej 0:e9dd36a15d07 200 FREE(pkt);
Jeej 0:e9dd36a15d07 201 }
Jeej 0:e9dd36a15d07 202
Jeej 1:0ec0bae00588 203 static int modem_serial_send(uint8_t* data1, uint8_t size1, uint8_t* data2, uint8_t size2)
Jeej 0:e9dd36a15d07 204 {
Jeej 0:e9dd36a15d07 205 (void)size1;
Jeej 0:e9dd36a15d07 206
Jeej 0:e9dd36a15d07 207 // Retrieve Flow ID from header and send packet
Jeej 0:e9dd36a15d07 208 g_modem_com->send((WizziComPacketType)wizzicom_flow_to_type(data1[4]), size2, data2);
Jeej 0:e9dd36a15d07 209
Jeej 0:e9dd36a15d07 210 return (size1 + size2);
Jeej 0:e9dd36a15d07 211 }
Jeej 0:e9dd36a15d07 212
Jeej 23:4ef5c82089a3 213 // Callback for id User
Jeej 0:e9dd36a15d07 214 static void my_main_callback(uint8_t terminal, int8_t err, uint8_t id)
Jeej 0:e9dd36a15d07 215 {
Jeej 0:e9dd36a15d07 216 (void)id;
Jeej 0:e9dd36a15d07 217
Jeej 44:7563b8e53e1d 218 g_err = err;
Jeej 44:7563b8e53e1d 219
Jeej 44:7563b8e53e1d 220 //modem_print_error(0xC0, g_err);
Jeej 44:7563b8e53e1d 221
Jeej 0:e9dd36a15d07 222 if (terminal)
Jeej 0:e9dd36a15d07 223 {
Jeej 44:7563b8e53e1d 224 g_modem_ready.release();
Jeej 0:e9dd36a15d07 225 }
Jeej 0:e9dd36a15d07 226 }
Jeej 0:e9dd36a15d07 227
Jeej 0:e9dd36a15d07 228 // Misc
Jeej 0:e9dd36a15d07 229 // ============================================================{{{
Jeej 44:7563b8e53e1d 230
Jeej 44:7563b8e53e1d 231 void modem_notify_host_rev(revision_t* data, alp_file_header_t* header, uint8_t* root_key)
Jeej 44:7563b8e53e1d 232 {
Jeej 44:7563b8e53e1d 233 uint8_t id = modem_get_id(my_main_callback);
Jeej 44:7563b8e53e1d 234
Jeej 44:7563b8e53e1d 235 // Write the version to the version file.
Jeej 44:7563b8e53e1d 236 // This file is notified on write.
Jeej 44:7563b8e53e1d 237 modem_write_file_root(FID_HOST_REV, (void*)data, 0, HAL_U32_BYTE_SWAP(header->alloc), root_key, id);
Jeej 44:7563b8e53e1d 238 g_modem_ready.wait();
Jeej 44:7563b8e53e1d 239
Jeej 49:035512e64fdd 240 // Error when writing to the file
Jeej 44:7563b8e53e1d 241 if (ALP_ERR_NONE != g_err)
Jeej 44:7563b8e53e1d 242 {
Jeej 49:035512e64fdd 243 // File exists
Jeej 49:035512e64fdd 244 if (ALP_ERR_FILE_NOT_FOUND != g_err)
Jeej 49:035512e64fdd 245 {
Jeej 49:035512e64fdd 246 // Delete old file
Jeej 49:035512e64fdd 247 modem_delete_file_root(FID_HOST_REV, root_key, id);
Jeej 49:035512e64fdd 248 g_modem_ready.wait();
Jeej 49:035512e64fdd 249 }
Jeej 44:7563b8e53e1d 250
Jeej 44:7563b8e53e1d 251 // Recreate file
Jeej 44:7563b8e53e1d 252 modem_create_file(FID_HOST_REV, header, id);
Jeej 44:7563b8e53e1d 253 g_modem_ready.wait();
Jeej 44:7563b8e53e1d 254
Jeej 44:7563b8e53e1d 255 // Retry writing to the file
Jeej 44:7563b8e53e1d 256 modem_write_file_root(FID_HOST_REV, (void*)data, 0, HAL_U32_BYTE_SWAP(header->alloc), root_key, id);
Jeej 44:7563b8e53e1d 257 g_modem_ready.wait();
Jeej 44:7563b8e53e1d 258 }
Jeej 44:7563b8e53e1d 259
Jeej 44:7563b8e53e1d 260 modem_free_id(id);
Jeej 44:7563b8e53e1d 261 }
Jeej 0:e9dd36a15d07 262
Jeej 0:e9dd36a15d07 263 void modem_update_file(uint8_t fid, alp_file_header_t* header, uint8_t* data)
Jeej 0:e9dd36a15d07 264 {
Jeej 0:e9dd36a15d07 265 alp_file_header_t remote_header;
Jeej 23:4ef5c82089a3 266 uint8_t id = modem_get_id(my_main_callback);
Jeej 0:e9dd36a15d07 267
Jeej 0:e9dd36a15d07 268 memset(&remote_header, 0, sizeof(alp_file_header_t));
Jeej 0:e9dd36a15d07 269
Jeej 0:e9dd36a15d07 270 // Read remote header
Jeej 23:4ef5c82089a3 271 modem_read_fprop(fid, &remote_header, id);
Jeej 44:7563b8e53e1d 272 g_modem_ready.wait();
Jeej 0:e9dd36a15d07 273
Jeej 0:e9dd36a15d07 274 // Add file in local file system
Jeej 0:e9dd36a15d07 275 ram_fs_new(fid, (uint8_t*)header, data);
Jeej 0:e9dd36a15d07 276
Jeej 0:e9dd36a15d07 277 // Update file
Jeej 0:e9dd36a15d07 278 if (memcmp(&remote_header, header, sizeof(alp_file_header_t)))
Jeej 0:e9dd36a15d07 279 {
Jeej 0:e9dd36a15d07 280 HELPER_PRINT("Updating file %d\n", fid);
Jeej 0:e9dd36a15d07 281 // Delete
Jeej 23:4ef5c82089a3 282 modem_delete_file(fid, id);
Jeej 44:7563b8e53e1d 283 g_modem_ready.wait();
Jeej 0:e9dd36a15d07 284 // Restore in local file system
Jeej 0:e9dd36a15d07 285 ram_fs_new(fid, (uint8_t*)header, data);
Jeej 0:e9dd36a15d07 286 // Re-create
Jeej 0:e9dd36a15d07 287 if (data)
Jeej 0:e9dd36a15d07 288 {
Jeej 23:4ef5c82089a3 289 modem_declare_file(fid, header, true, id);
Jeej 0:e9dd36a15d07 290 }
Jeej 0:e9dd36a15d07 291 else
Jeej 0:e9dd36a15d07 292 {
Jeej 23:4ef5c82089a3 293 modem_create_file(fid, header, id);
Jeej 0:e9dd36a15d07 294 }
Jeej 44:7563b8e53e1d 295 g_modem_ready.wait();
Jeej 0:e9dd36a15d07 296 }
Jeej 0:e9dd36a15d07 297 else
Jeej 0:e9dd36a15d07 298 {
Jeej 0:e9dd36a15d07 299 HELPER_PRINT("File %d up to date\n", fid);
Jeej 0:e9dd36a15d07 300 }
Jeej 0:e9dd36a15d07 301
Jeej 23:4ef5c82089a3 302 modem_free_id(id);
Jeej 0:e9dd36a15d07 303 }
Jeej 0:e9dd36a15d07 304
Jeej 12:04c32f2e03b7 305 Semaphore boot(0);
Jeej 12:04c32f2e03b7 306 void my_startup_boot(u8 cause, u16 number)
Jeej 12:04c32f2e03b7 307 {
Jeej 12:04c32f2e03b7 308 HELPER_PRINT("Modem BOOT[%c] #%d\r\n", cause, number);
Jeej 12:04c32f2e03b7 309 boot.release();
Jeej 12:04c32f2e03b7 310 }
Jeej 12:04c32f2e03b7 311
Jeej 0:e9dd36a15d07 312 void modem_helper_open(modem_callbacks_t* callbacks)
Jeej 0:e9dd36a15d07 313 {
Jeej 0:e9dd36a15d07 314 static union {
Jeej 0:e9dd36a15d07 315 uint8_t b[8];
Jeej 0:e9dd36a15d07 316 uint32_t w[2];
Jeej 0:e9dd36a15d07 317 } uid;
Jeej 0:e9dd36a15d07 318 revision_t rev;
Jeej 12:04c32f2e03b7 319
Jeej 12:04c32f2e03b7 320 // Override boot callback to catch the first boot message
Jeej 12:04c32f2e03b7 321 modem_callbacks_t boot_callbacks = {
Jeej 12:04c32f2e03b7 322 .read = NULL,
Jeej 12:04c32f2e03b7 323 .write = NULL,
Jeej 12:04c32f2e03b7 324 .read_fprop = NULL,
Jeej 12:04c32f2e03b7 325 .flush = NULL,
Jeej 12:04c32f2e03b7 326 .remove = NULL,
Jeej 12:04c32f2e03b7 327 .udata = NULL,
Jeej 12:04c32f2e03b7 328 .lqual = NULL,
Jeej 12:04c32f2e03b7 329 .ldown = NULL,
Jeej 12:04c32f2e03b7 330 .reset = NULL,
Jeej 49:035512e64fdd 331 .boot = my_startup_boot,
Jeej 49:035512e64fdd 332 .busy = NULL,
Jeej 49:035512e64fdd 333 .itf_busy = NULL,
Jeej 12:04c32f2e03b7 334 };
Jeej 0:e9dd36a15d07 335
Jeej 0:e9dd36a15d07 336 // Open modem Com port
Jeej 20:8e6a7f4e06a1 337 g_modem_com = new WizziCom(MODEM_PIN_RX, MODEM_PIN_TX, MODEM_PIN_IRQ_IN, MODEM_PIN_IRQ_OUT);
Jeej 0:e9dd36a15d07 338
Jeej 12:04c32f2e03b7 339 // Hardware reset
Jeej 12:04c32f2e03b7 340 DigitalOut reset_low(MODEM_PIN_RESET, 0);
Jeej 12:04c32f2e03b7 341 Thread::wait(100);
Jeej 12:04c32f2e03b7 342
Jeej 12:04c32f2e03b7 343 // Open driver to catch boot packet
Jeej 12:04c32f2e03b7 344 modem_open(NULL, &boot_callbacks);
Jeej 12:04c32f2e03b7 345
Jeej 1:0ec0bae00588 346 // Redirect All Port traffic to modem_serial_input
Jeej 1:0ec0bae00588 347 g_modem_com->attach(modem_serial_input, WizziComPacketUntreated);
Jeej 12:04c32f2e03b7 348
Jeej 12:04c32f2e03b7 349 // Release reset
Jeej 12:04c32f2e03b7 350 DigitalIn reset_release(MODEM_PIN_RESET);
Jeej 12:04c32f2e03b7 351
Jeej 12:04c32f2e03b7 352 // Wait for first boot packet
Jeej 20:8e6a7f4e06a1 353 HELPER_PRINT("Waiting boot packet...\n");
Jeej 12:04c32f2e03b7 354 boot.wait();
Jeej 12:04c32f2e03b7 355
Jeej 12:04c32f2e03b7 356 // Re-open with user callbacks
Jeej 12:04c32f2e03b7 357 modem_close();
Jeej 1:0ec0bae00588 358 modem_open(modem_serial_send, callbacks);
Jeej 0:e9dd36a15d07 359
Jeej 23:4ef5c82089a3 360 uint8_t id = modem_get_id(my_main_callback);
Jeej 0:e9dd36a15d07 361
Jeej 23:4ef5c82089a3 362 HELPER_PRINT("Start Modem Process (id=%d)\n", id);
Jeej 0:e9dd36a15d07 363 Thread::wait(1000);
Jeej 0:e9dd36a15d07 364
Jeej 23:4ef5c82089a3 365 modem_read_file(D7A_FID_UID, uid.b, 0, 8, id);
Jeej 44:7563b8e53e1d 366 g_modem_ready.wait();
Jeej 0:e9dd36a15d07 367
Jeej 23:4ef5c82089a3 368 modem_read_file(D7A_FID_FIRMWARE_VERSION, (uint8_t*)&rev, 0, sizeof(revision_t), id);
Jeej 44:7563b8e53e1d 369 g_modem_ready.wait();
Jeej 0:e9dd36a15d07 370
Jeej 0:e9dd36a15d07 371 PRINT("------------ D7A Modem infos ------------\r\n");
Jeej 0:e9dd36a15d07 372 PRINT_DATA(" - UID: ", "%02X", uid.b, 8, "\r\n");
Jeej 0:e9dd36a15d07 373 PRINT(" - Manufacturer ID: %08X\r\n", rev.manufacturer_id);
Jeej 0:e9dd36a15d07 374 PRINT(" - Device ID: %08X\r\n", rev.device_id);
Jeej 0:e9dd36a15d07 375 PRINT(" - Hardware version: %08X\r\n", rev.hw_version);
Jeej 8:95ba5519a9f7 376 PRINT(" - Firmware version: v%d.%d.%d [%02X]\r\n", rev.fw_version.major, rev.fw_version.minor, rev.fw_version.patch, rev.fw_version.id);
Jeej 9:5d850e56ac20 377 PRINT(" - CUP max size: %d\r\n", rev.cup_max_size);
Jeej 0:e9dd36a15d07 378 PRINT("-----------------------------------------\r\n");
Jeej 47:cf88f0f370cb 379
Jeej 47:cf88f0f370cb 380 if (MODEM_DEVICE_ID == rev.device_id)
Jeej 0:e9dd36a15d07 381 {
Jeej 47:cf88f0f370cb 382 // Check version
Jeej 47:cf88f0f370cb 383 uint32_t rev_sum1 = (rev.fw_version.major << 24) | (rev.fw_version.minor << 16) | rev.fw_version.patch;
Jeej 47:cf88f0f370cb 384 uint32_t rev_sum2 = (MODEM_VERSION_MAJOR << 24) | (MODEM_VERSION_MINOR << 16) | MODEM_VERSION_PATCH;
Jeej 47:cf88f0f370cb 385 if (rev_sum1 < rev_sum2)
Jeej 47:cf88f0f370cb 386 {
Jeej 47:cf88f0f370cb 387 PRINT("\r\nYou need a modem at version %d.%d.%d or above to use this Driver.\r\n"
Jeej 47:cf88f0f370cb 388 "You can:\r\n"
Jeej 47:cf88f0f370cb 389 " - Check modem updates on the Dash7Board:\r\n"
Jeej 47:cf88f0f370cb 390 " Go to your site's version manager.\r\n"
Jeej 47:cf88f0f370cb 391 " - Check modem updates by importing:\r\n"
Jeej 47:cf88f0f370cb 392 " https://developer.mbed.org/teams/WizziLab/code/D7A_WM_Updater\r\n"
Jeej 47:cf88f0f370cb 393 " - Choose the right 'modem_ref_helper' revision.\r\n"
Jeej 47:cf88f0f370cb 394 " Right click on modem_ref_helper -> Revision.\r\n"
Jeej 47:cf88f0f370cb 395 , MODEM_VERSION_MAJOR, MODEM_VERSION_MINOR, MODEM_VERSION_PATCH);
Jeej 47:cf88f0f370cb 396
Jeej 47:cf88f0f370cb 397 Thread::wait(osWaitForever);
Jeej 47:cf88f0f370cb 398 }
Jeej 47:cf88f0f370cb 399 }
Jeej 47:cf88f0f370cb 400 else
Jeej 47:cf88f0f370cb 401 {
Jeej 47:cf88f0f370cb 402 // Do not check version
Jeej 47:cf88f0f370cb 403 PRINT("/!\\ Not a modem firmware /!\\\r\n");
Jeej 0:e9dd36a15d07 404 }
Jeej 0:e9dd36a15d07 405
Jeej 23:4ef5c82089a3 406 modem_free_id(id);
Jeej 0:e9dd36a15d07 407 }