Helper library to use modem_ref driver.

Dependencies:   WizziCom WizziDebug ram_fs modem_ref

Dependents:   D7A_Localisation D7A_1x_demo_ActiveRFIDReader D7A_1x_demo_big_file D7A_1x_demo_CodeUpgradeProtocol ... more

Committer:
Jeej
Date:
Thu May 28 09:11:32 2020 +0000
Revision:
65:243e0ef07efb
Parent:
61:8565bc7a6997
Publish

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 }
Jeej 0:e9dd36a15d07 201
Jeej 1:0ec0bae00588 202 static int modem_serial_send(uint8_t* data1, uint8_t size1, uint8_t* data2, uint8_t size2)
Jeej 0:e9dd36a15d07 203 {
Jeej 0:e9dd36a15d07 204 (void)size1;
Jeej 0:e9dd36a15d07 205
Jeej 0:e9dd36a15d07 206 // Retrieve Flow ID from header and send packet
Jeej 0:e9dd36a15d07 207 g_modem_com->send((WizziComPacketType)wizzicom_flow_to_type(data1[4]), size2, data2);
Jeej 0:e9dd36a15d07 208
Jeej 0:e9dd36a15d07 209 return (size1 + size2);
Jeej 0:e9dd36a15d07 210 }
Jeej 0:e9dd36a15d07 211
Jeej 23:4ef5c82089a3 212 // Callback for id User
Jeej 0:e9dd36a15d07 213 static void my_main_callback(uint8_t terminal, int8_t err, uint8_t id)
Jeej 0:e9dd36a15d07 214 {
Jeej 0:e9dd36a15d07 215 (void)id;
Jeej 0:e9dd36a15d07 216
Jeej 44:7563b8e53e1d 217 g_err = err;
Jeej 44:7563b8e53e1d 218
Jeej 44:7563b8e53e1d 219 //modem_print_error(0xC0, g_err);
Jeej 44:7563b8e53e1d 220
Jeej 0:e9dd36a15d07 221 if (terminal)
Jeej 0:e9dd36a15d07 222 {
Jeej 44:7563b8e53e1d 223 g_modem_ready.release();
Jeej 0:e9dd36a15d07 224 }
Jeej 0:e9dd36a15d07 225 }
Jeej 0:e9dd36a15d07 226
Jeej 0:e9dd36a15d07 227 // Misc
Jeej 0:e9dd36a15d07 228 // ============================================================{{{
Jeej 44:7563b8e53e1d 229
Jeej 44:7563b8e53e1d 230 void modem_notify_host_rev(revision_t* data, alp_file_header_t* header, uint8_t* root_key)
Jeej 44:7563b8e53e1d 231 {
Jeej 44:7563b8e53e1d 232 uint8_t id = modem_get_id(my_main_callback);
Jeej 44:7563b8e53e1d 233
Jeej 44:7563b8e53e1d 234 // Write the version to the version file.
Jeej 44:7563b8e53e1d 235 // This file is notified on write.
Jeej 44:7563b8e53e1d 236 modem_write_file_root(FID_HOST_REV, (void*)data, 0, HAL_U32_BYTE_SWAP(header->alloc), root_key, id);
Jeej 60:524b4f20d332 237 g_modem_ready.acquire();
Jeej 44:7563b8e53e1d 238
Jeej 49:035512e64fdd 239 // Error when writing to the file
Jeej 44:7563b8e53e1d 240 if (ALP_ERR_NONE != g_err)
Jeej 44:7563b8e53e1d 241 {
Jeej 49:035512e64fdd 242 // File exists
Jeej 49:035512e64fdd 243 if (ALP_ERR_FILE_NOT_FOUND != g_err)
Jeej 49:035512e64fdd 244 {
Jeej 49:035512e64fdd 245 // Delete old file
Jeej 49:035512e64fdd 246 modem_delete_file_root(FID_HOST_REV, root_key, id);
Jeej 60:524b4f20d332 247 g_modem_ready.acquire();
Jeej 49:035512e64fdd 248 }
Jeej 44:7563b8e53e1d 249
Jeej 44:7563b8e53e1d 250 // Recreate file
Jeej 44:7563b8e53e1d 251 modem_create_file(FID_HOST_REV, header, id);
Jeej 60:524b4f20d332 252 g_modem_ready.acquire();
Jeej 44:7563b8e53e1d 253
Jeej 44:7563b8e53e1d 254 // Retry writing to the file
Jeej 44:7563b8e53e1d 255 modem_write_file_root(FID_HOST_REV, (void*)data, 0, HAL_U32_BYTE_SWAP(header->alloc), root_key, id);
Jeej 60:524b4f20d332 256 g_modem_ready.acquire();
Jeej 44:7563b8e53e1d 257 }
Jeej 44:7563b8e53e1d 258
Jeej 44:7563b8e53e1d 259 modem_free_id(id);
Jeej 44:7563b8e53e1d 260 }
Jeej 0:e9dd36a15d07 261
Jeej 0:e9dd36a15d07 262 void modem_update_file(uint8_t fid, alp_file_header_t* header, uint8_t* data)
Jeej 0:e9dd36a15d07 263 {
Jeej 0:e9dd36a15d07 264 alp_file_header_t remote_header;
Jeej 23:4ef5c82089a3 265 uint8_t id = modem_get_id(my_main_callback);
Jeej 0:e9dd36a15d07 266
Jeej 0:e9dd36a15d07 267 memset(&remote_header, 0, sizeof(alp_file_header_t));
Jeej 0:e9dd36a15d07 268
Jeej 0:e9dd36a15d07 269 // Read remote header
Jeej 23:4ef5c82089a3 270 modem_read_fprop(fid, &remote_header, id);
Jeej 60:524b4f20d332 271 g_modem_ready.acquire();
Jeej 0:e9dd36a15d07 272
Jeej 0:e9dd36a15d07 273 // Add file in local file system
Jeej 0:e9dd36a15d07 274 ram_fs_new(fid, (uint8_t*)header, data);
Jeej 0:e9dd36a15d07 275
Jeej 0:e9dd36a15d07 276 // Update file
Jeej 0:e9dd36a15d07 277 if (memcmp(&remote_header, header, sizeof(alp_file_header_t)))
Jeej 0:e9dd36a15d07 278 {
Jeej 0:e9dd36a15d07 279 HELPER_PRINT("Updating file %d\n", fid);
Jeej 0:e9dd36a15d07 280 // Delete
Jeej 23:4ef5c82089a3 281 modem_delete_file(fid, id);
Jeej 60:524b4f20d332 282 g_modem_ready.acquire();
Jeej 0:e9dd36a15d07 283 // Restore in local file system
Jeej 0:e9dd36a15d07 284 ram_fs_new(fid, (uint8_t*)header, data);
Jeej 0:e9dd36a15d07 285 // Re-create
Jeej 0:e9dd36a15d07 286 if (data)
Jeej 0:e9dd36a15d07 287 {
Jeej 23:4ef5c82089a3 288 modem_declare_file(fid, header, true, id);
Jeej 0:e9dd36a15d07 289 }
Jeej 0:e9dd36a15d07 290 else
Jeej 0:e9dd36a15d07 291 {
Jeej 23:4ef5c82089a3 292 modem_create_file(fid, header, id);
Jeej 0:e9dd36a15d07 293 }
Jeej 60:524b4f20d332 294 g_modem_ready.acquire();
Jeej 0:e9dd36a15d07 295 }
Jeej 0:e9dd36a15d07 296 else
Jeej 0:e9dd36a15d07 297 {
Jeej 0:e9dd36a15d07 298 HELPER_PRINT("File %d up to date\n", fid);
Jeej 0:e9dd36a15d07 299 }
Jeej 0:e9dd36a15d07 300
Jeej 23:4ef5c82089a3 301 modem_free_id(id);
Jeej 0:e9dd36a15d07 302 }
Jeej 0:e9dd36a15d07 303
Jeej 12:04c32f2e03b7 304 Semaphore boot(0);
Jeej 12:04c32f2e03b7 305 void my_startup_boot(u8 cause, u16 number)
Jeej 12:04c32f2e03b7 306 {
Jeej 12:04c32f2e03b7 307 HELPER_PRINT("Modem BOOT[%c] #%d\r\n", cause, number);
Jeej 12:04c32f2e03b7 308 boot.release();
Jeej 12:04c32f2e03b7 309 }
Jeej 12:04c32f2e03b7 310
Jeej 0:e9dd36a15d07 311 void modem_helper_open(modem_callbacks_t* callbacks)
Jeej 0:e9dd36a15d07 312 {
Jeej 0:e9dd36a15d07 313 static union {
Jeej 0:e9dd36a15d07 314 uint8_t b[8];
Jeej 0:e9dd36a15d07 315 uint32_t w[2];
Jeej 0:e9dd36a15d07 316 } uid;
Jeej 0:e9dd36a15d07 317 revision_t rev;
Jeej 12:04c32f2e03b7 318
Jeej 12:04c32f2e03b7 319 // Override boot callback to catch the first boot message
Jeej 12:04c32f2e03b7 320 modem_callbacks_t boot_callbacks = {
Jeej 12:04c32f2e03b7 321 .read = NULL,
Jeej 12:04c32f2e03b7 322 .write = NULL,
Jeej 12:04c32f2e03b7 323 .read_fprop = NULL,
Jeej 12:04c32f2e03b7 324 .flush = NULL,
Jeej 12:04c32f2e03b7 325 .remove = NULL,
Jeej 12:04c32f2e03b7 326 .udata = NULL,
Jeej 12:04c32f2e03b7 327 .lqual = NULL,
Jeej 12:04c32f2e03b7 328 .ldown = NULL,
Jeej 12:04c32f2e03b7 329 .reset = NULL,
Jeej 49:035512e64fdd 330 .boot = my_startup_boot,
Jeej 49:035512e64fdd 331 .busy = NULL,
Jeej 49:035512e64fdd 332 .itf_busy = NULL,
Jeej 12:04c32f2e03b7 333 };
Jeej 0:e9dd36a15d07 334
Jeej 0:e9dd36a15d07 335 // Open modem Com port
Jeej 20:8e6a7f4e06a1 336 g_modem_com = new WizziCom(MODEM_PIN_RX, MODEM_PIN_TX, MODEM_PIN_IRQ_IN, MODEM_PIN_IRQ_OUT);
Jeej 0:e9dd36a15d07 337
Jeej 12:04c32f2e03b7 338 // Hardware reset
Jeej 12:04c32f2e03b7 339 DigitalOut reset_low(MODEM_PIN_RESET, 0);
Jeej 58:f7105abdceed 340 ThisThread::sleep_for(100);
Jeej 12:04c32f2e03b7 341
Jeej 12:04c32f2e03b7 342 // Open driver to catch boot packet
Jeej 12:04c32f2e03b7 343 modem_open(NULL, &boot_callbacks);
Jeej 12:04c32f2e03b7 344
Jeej 1:0ec0bae00588 345 // Redirect All Port traffic to modem_serial_input
Jeej 1:0ec0bae00588 346 g_modem_com->attach(modem_serial_input, WizziComPacketUntreated);
Jeej 12:04c32f2e03b7 347
Jeej 12:04c32f2e03b7 348 // Release reset
Jeej 12:04c32f2e03b7 349 DigitalIn reset_release(MODEM_PIN_RESET);
Jeej 12:04c32f2e03b7 350
Jeej 12:04c32f2e03b7 351 // Wait for first boot packet
Jeej 20:8e6a7f4e06a1 352 HELPER_PRINT("Waiting boot packet...\n");
Jeej 60:524b4f20d332 353 boot.acquire();
Jeej 12:04c32f2e03b7 354
Jeej 12:04c32f2e03b7 355 // Re-open with user callbacks
Jeej 12:04c32f2e03b7 356 modem_close();
Jeej 1:0ec0bae00588 357 modem_open(modem_serial_send, callbacks);
Jeej 0:e9dd36a15d07 358
Jeej 23:4ef5c82089a3 359 uint8_t id = modem_get_id(my_main_callback);
Jeej 0:e9dd36a15d07 360
Jeej 23:4ef5c82089a3 361 HELPER_PRINT("Start Modem Process (id=%d)\n", id);
Jeej 58:f7105abdceed 362 ThisThread::sleep_for(1000);
Jeej 0:e9dd36a15d07 363
Jeej 23:4ef5c82089a3 364 modem_read_file(D7A_FID_UID, uid.b, 0, 8, id);
Jeej 60:524b4f20d332 365 g_modem_ready.acquire();
Jeej 0:e9dd36a15d07 366
Jeej 23:4ef5c82089a3 367 modem_read_file(D7A_FID_FIRMWARE_VERSION, (uint8_t*)&rev, 0, sizeof(revision_t), id);
Jeej 60:524b4f20d332 368 g_modem_ready.acquire();
Jeej 0:e9dd36a15d07 369
Jeej 0:e9dd36a15d07 370 PRINT("------------ D7A Modem infos ------------\r\n");
Jeej 0:e9dd36a15d07 371 PRINT_DATA(" - UID: ", "%02X", uid.b, 8, "\r\n");
Jeej 0:e9dd36a15d07 372 PRINT(" - Manufacturer ID: %08X\r\n", rev.manufacturer_id);
Jeej 0:e9dd36a15d07 373 PRINT(" - Device ID: %08X\r\n", rev.device_id);
Jeej 0:e9dd36a15d07 374 PRINT(" - Hardware version: %08X\r\n", rev.hw_version);
Jeej 8:95ba5519a9f7 375 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 376 PRINT(" - CUP max size: %d\r\n", rev.cup_max_size);
Jeej 0:e9dd36a15d07 377 PRINT("-----------------------------------------\r\n");
Jeej 47:cf88f0f370cb 378
Jeej 47:cf88f0f370cb 379 if (MODEM_DEVICE_ID == rev.device_id)
Jeej 0:e9dd36a15d07 380 {
Jeej 47:cf88f0f370cb 381 // Check version
Jeej 47:cf88f0f370cb 382 uint32_t rev_sum1 = (rev.fw_version.major << 24) | (rev.fw_version.minor << 16) | rev.fw_version.patch;
Jeej 47:cf88f0f370cb 383 uint32_t rev_sum2 = (MODEM_VERSION_MAJOR << 24) | (MODEM_VERSION_MINOR << 16) | MODEM_VERSION_PATCH;
Jeej 47:cf88f0f370cb 384 if (rev_sum1 < rev_sum2)
Jeej 47:cf88f0f370cb 385 {
Jeej 47:cf88f0f370cb 386 PRINT("\r\nYou need a modem at version %d.%d.%d or above to use this Driver.\r\n"
Jeej 47:cf88f0f370cb 387 "You can:\r\n"
Jeej 47:cf88f0f370cb 388 " - Check modem updates on the Dash7Board:\r\n"
Jeej 47:cf88f0f370cb 389 " Go to your site's version manager.\r\n"
Jeej 47:cf88f0f370cb 390 " - Check modem updates by importing:\r\n"
Jeej 47:cf88f0f370cb 391 " https://developer.mbed.org/teams/WizziLab/code/D7A_WM_Updater\r\n"
Jeej 47:cf88f0f370cb 392 " - Choose the right 'modem_ref_helper' revision.\r\n"
Jeej 47:cf88f0f370cb 393 " Right click on modem_ref_helper -> Revision.\r\n"
Jeej 47:cf88f0f370cb 394 , MODEM_VERSION_MAJOR, MODEM_VERSION_MINOR, MODEM_VERSION_PATCH);
Jeej 47:cf88f0f370cb 395
Jeej 58:f7105abdceed 396 ThisThread::sleep_for(osWaitForever);
Jeej 47:cf88f0f370cb 397 }
Jeej 47:cf88f0f370cb 398 }
Jeej 47:cf88f0f370cb 399 else
Jeej 47:cf88f0f370cb 400 {
Jeej 47:cf88f0f370cb 401 // Do not check version
Jeej 47:cf88f0f370cb 402 PRINT("/!\\ Not a modem firmware /!\\\r\n");
Jeej 0:e9dd36a15d07 403 }
Jeej 0:e9dd36a15d07 404
Jeej 23:4ef5c82089a3 405 modem_free_id(id);
Jeej 0:e9dd36a15d07 406 }