Sending and reception of big data file (1kB example)
Dependencies: modem_ref_helper CRC DebouncedInterrupt
main.cpp@16:2990b7d21ca2, 2021-02-17 (annotated)
- Committer:
- Jeej
- Date:
- Wed Feb 17 11:23:03 2021 +0000
- Revision:
- 16:2990b7d21ca2
- Parent:
- 15:9a9cfb0c3c4e
Restored button.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Jeej | 0:a2bbc478f812 | 1 | // @autor: jeremie@wizzilab.com |
Jeej | 0:a2bbc478f812 | 2 | // @date: 2017-12-14 |
Jeej | 0:a2bbc478f812 | 3 | |
Jeej | 0:a2bbc478f812 | 4 | #include "DebouncedInterrupt.h" |
Jeej | 15:9a9cfb0c3c4e | 5 | #include "modem_d7a.h" |
Jeej | 0:a2bbc478f812 | 6 | #include "modem_callbacks.h" |
Jeej | 0:a2bbc478f812 | 7 | #include "files.h" |
Jeej | 0:a2bbc478f812 | 8 | #include "crc.h" |
Jeej | 0:a2bbc478f812 | 9 | |
Jeej | 0:a2bbc478f812 | 10 | #define CHUNK_SIZE 128 |
Jeej | 0:a2bbc478f812 | 11 | |
Jeej | 0:a2bbc478f812 | 12 | Semaphore button_user(0); |
Jeej | 0:a2bbc478f812 | 13 | Semaphore modem_ready(0); |
Jeej | 0:a2bbc478f812 | 14 | Queue<touch_t, 8> g_file_modified; |
Jeej | 0:a2bbc478f812 | 15 | |
Jeej | 1:76a8a3cc5f2e | 16 | // This describe the upload interface |
Jeej | 1:76a8a3cc5f2e | 17 | // Do not modify uncommented parameters |
Jeej | 15:9a9cfb0c3c4e | 18 | alp_itf_d7a_cfg_t report_itf = { |
Jeej | 0:a2bbc478f812 | 19 | .type = ALP_ITF_TYPE_D7A, |
Jeej | 14:a0241090f967 | 20 | .cfg.to.byte = D7A_CTF_ENCODE(0), |
Jeej | 14:a0241090f967 | 21 | .cfg.te.byte = D7A_CTF_ENCODE(0), |
Jeej | 0:a2bbc478f812 | 22 | .cfg.qos.bf.resp = D7A_RESP_PREFERRED, |
Jeej | 6:33dfecc85ebf | 23 | .cfg.qos.bf.retry = ALP_RPOL_ONESHOT, |
Jeej | 1:76a8a3cc5f2e | 24 | .cfg.addressee.ctrl.bf.nls = D7A_NLS_AES_CCM_64, // Security level |
Jeej | 0:a2bbc478f812 | 25 | .cfg.addressee.ctrl.bf.idf = D7A_ID_NBID, |
Jeej | 9:26cd994b5303 | 26 | .cfg.addressee.xcl.bf = {.s = 2, .m = 0x1}, // Gateway access class |
Jeej | 9:26cd994b5303 | 27 | .cfg.addressee.id[0] = D7A_CTF_ENCODE(4), |
Jeej | 0:a2bbc478f812 | 28 | }; |
Jeej | 0:a2bbc478f812 | 29 | |
Jeej | 0:a2bbc478f812 | 30 | // Interrupt Service Routine on button press. |
Jeej | 0:a2bbc478f812 | 31 | void button_push_isr( void ) |
Jeej | 0:a2bbc478f812 | 32 | { |
Jeej | 0:a2bbc478f812 | 33 | button_user.release(); |
Jeej | 0:a2bbc478f812 | 34 | } |
Jeej | 0:a2bbc478f812 | 35 | |
Jeej | 1:76a8a3cc5f2e | 36 | // Upload thread |
Jeej | 0:a2bbc478f812 | 37 | void button_user_thread() |
Jeej | 0:a2bbc478f812 | 38 | { |
Jeej | 0:a2bbc478f812 | 39 | osEvent evt; |
Jeej | 1:76a8a3cc5f2e | 40 | output_file_t* output; |
Jeej | 0:a2bbc478f812 | 41 | uint32_t sent = 0; |
Jeej | 15:9a9cfb0c3c4e | 42 | int err; |
Jeej | 15:9a9cfb0c3c4e | 43 | alp_payload_t* alp; |
Jeej | 15:9a9cfb0c3c4e | 44 | alp_payload_t* rsp; |
Jeej | 15:9a9cfb0c3c4e | 45 | |
Jeej | 15:9a9cfb0c3c4e | 46 | PRINT("Register Files\n"); |
Jeej | 15:9a9cfb0c3c4e | 47 | ram_fs_new(FID_OUTPUT_FILE, (uint8_t*)&h_output_file, (uint8_t*)&f_output_file); |
Jeej | 15:9a9cfb0c3c4e | 48 | ram_fs_new(FID_INPUT_FILE, (uint8_t*)&h_input_file, (uint8_t*)&f_input_file); |
Jeej | 15:9a9cfb0c3c4e | 49 | |
Jeej | 15:9a9cfb0c3c4e | 50 | modem_declare_file(FID_OUTPUT_FILE, (alp_file_header_t*)&h_output_file); |
Jeej | 15:9a9cfb0c3c4e | 51 | modem_declare_file(FID_INPUT_FILE, (alp_file_header_t*)&h_input_file); |
Jeej | 15:9a9cfb0c3c4e | 52 | |
Jeej | 15:9a9cfb0c3c4e | 53 | PRINT("Enable D7A interface\n"); |
Jeej | 15:9a9cfb0c3c4e | 54 | modem_d7a_enable_itf(); |
Jeej | 15:9a9cfb0c3c4e | 55 | |
Jeej | 15:9a9cfb0c3c4e | 56 | // Host revision file is in the modem. Update it. |
Jeej | 15:9a9cfb0c3c4e | 57 | PRINT("Update host revision\n"); |
Jeej | 15:9a9cfb0c3c4e | 58 | modem_write_file(FID_HOST_REV, &f_rev, 0, sizeof(revision_t)); |
Jeej | 15:9a9cfb0c3c4e | 59 | |
Jeej | 15:9a9cfb0c3c4e | 60 | // Retrieve modem revision |
Jeej | 15:9a9cfb0c3c4e | 61 | PRINT("Send revision\n"); |
Jeej | 15:9a9cfb0c3c4e | 62 | revision_t rev; |
Jeej | 15:9a9cfb0c3c4e | 63 | modem_read_file(FID_WM_REV, &rev, 0, sizeof(revision_t)); |
Jeej | 15:9a9cfb0c3c4e | 64 | |
Jeej | 15:9a9cfb0c3c4e | 65 | // Send both to the server |
Jeej | 15:9a9cfb0c3c4e | 66 | // Build payload |
Jeej | 15:9a9cfb0c3c4e | 67 | alp = NULL; |
Jeej | 15:9a9cfb0c3c4e | 68 | alp = alp_payload_rsp_f_data(alp, FID_WM_REV, &rev, 0, sizeof(revision_t)); |
Jeej | 15:9a9cfb0c3c4e | 69 | alp = alp_payload_rsp_f_data(alp, FID_HOST_REV, &f_rev, 0, sizeof(revision_t)); |
Jeej | 15:9a9cfb0c3c4e | 70 | // Send |
Jeej | 15:9a9cfb0c3c4e | 71 | modem_remote_raw_alp((void*)&report_itf, alp, NULL, 10000); |
Jeej | 0:a2bbc478f812 | 72 | |
Jeej | 1:76a8a3cc5f2e | 73 | // Directly get data pointer to avoid reading file |
Jeej | 1:76a8a3cc5f2e | 74 | output = (output_file_t*)ram_fs_get_data(FID_OUTPUT_FILE); |
Jeej | 1:76a8a3cc5f2e | 75 | |
Jeej | 1:76a8a3cc5f2e | 76 | // Update file CRC (Calculate CRC on string without end of string) |
Jeej | 1:76a8a3cc5f2e | 77 | output->crc = crc32((char*)output->data, strlen((char*)output->data)); |
Jeej | 1:76a8a3cc5f2e | 78 | |
Jeej | 0:a2bbc478f812 | 79 | while (true) |
Jeej | 0:a2bbc478f812 | 80 | { |
Jeej | 0:a2bbc478f812 | 81 | Timer tim; |
Jeej | 0:a2bbc478f812 | 82 | bool is_ok; |
Jeej | 1:76a8a3cc5f2e | 83 | uint32_t output_length = strlen((char*)output->data) + 1; // +1 as data is a string, send end of string |
Jeej | 0:a2bbc478f812 | 84 | |
Jeej | 0:a2bbc478f812 | 85 | // Wait for button press |
Jeej | 1:76a8a3cc5f2e | 86 | PRINT("Press user button to send file. (%d bytes)\n", output_length); |
Jeej | 16:2990b7d21ca2 | 87 | button_user.acquire(); |
Jeej | 0:a2bbc478f812 | 88 | |
Jeej | 1:76a8a3cc5f2e | 89 | // Update file CRC (Calculate CRC on string without end of string) |
Jeej | 1:76a8a3cc5f2e | 90 | output->crc = crc32((char*)output->data, output_length - 1); |
Jeej | 1:76a8a3cc5f2e | 91 | |
Jeej | 0:a2bbc478f812 | 92 | sent = 0; |
Jeej | 0:a2bbc478f812 | 93 | tim.start(); |
Jeej | 0:a2bbc478f812 | 94 | |
Jeej | 0:a2bbc478f812 | 95 | // Send chunks |
Jeej | 1:76a8a3cc5f2e | 96 | while (sent < output_length) |
Jeej | 0:a2bbc478f812 | 97 | { |
Jeej | 0:a2bbc478f812 | 98 | is_ok = false; |
Jeej | 15:9a9cfb0c3c4e | 99 | uint32_t chunk_size = min_u32(CHUNK_SIZE, output_length - sent); |
Jeej | 0:a2bbc478f812 | 100 | uint32_t chunk_offset = sent; |
Jeej | 0:a2bbc478f812 | 101 | |
Jeej | 1:76a8a3cc5f2e | 102 | PRINT("Sending chunk %4d/%4d (%3d bytes)... ", chunk_offset, output_length, chunk_size); |
Jeej | 0:a2bbc478f812 | 103 | FLUSH(); |
Jeej | 15:9a9cfb0c3c4e | 104 | |
Jeej | 15:9a9cfb0c3c4e | 105 | // Build payload |
Jeej | 15:9a9cfb0c3c4e | 106 | alp = NULL; |
Jeej | 15:9a9cfb0c3c4e | 107 | alp = alp_payload_rsp_f_data(alp, FID_OUTPUT_FILE, &(output->data[chunk_offset]), chunk_offset, chunk_size); |
Jeej | 0:a2bbc478f812 | 108 | |
Jeej | 15:9a9cfb0c3c4e | 109 | // Send |
Jeej | 15:9a9cfb0c3c4e | 110 | err = modem_remote_raw_alp((void*)&report_itf, alp, &rsp, 60000); |
Jeej | 15:9a9cfb0c3c4e | 111 | |
Jeej | 15:9a9cfb0c3c4e | 112 | if (ALP_ERR_UNKNOWN == err) |
Jeej | 0:a2bbc478f812 | 113 | { |
Jeej | 15:9a9cfb0c3c4e | 114 | PRINT("TIMEOUT.\n"); |
Jeej | 0:a2bbc478f812 | 115 | } |
Jeej | 0:a2bbc478f812 | 116 | else |
Jeej | 0:a2bbc478f812 | 117 | { |
Jeej | 15:9a9cfb0c3c4e | 118 | err = alp_payload_get_err(rsp); |
Jeej | 15:9a9cfb0c3c4e | 119 | if (ALP_ERR_NONE <= err) |
Jeej | 15:9a9cfb0c3c4e | 120 | { |
Jeej | 15:9a9cfb0c3c4e | 121 | sent += chunk_size; |
Jeej | 15:9a9cfb0c3c4e | 122 | is_ok = true; |
Jeej | 15:9a9cfb0c3c4e | 123 | PRINT("OK.\n"); |
Jeej | 15:9a9cfb0c3c4e | 124 | } |
Jeej | 15:9a9cfb0c3c4e | 125 | else |
Jeej | 15:9a9cfb0c3c4e | 126 | { |
Jeej | 15:9a9cfb0c3c4e | 127 | modem_print_error(report_itf.type, err); |
Jeej | 15:9a9cfb0c3c4e | 128 | } |
Jeej | 0:a2bbc478f812 | 129 | } |
Jeej | 15:9a9cfb0c3c4e | 130 | |
Jeej | 15:9a9cfb0c3c4e | 131 | alp_payload_free(rsp); |
Jeej | 0:a2bbc478f812 | 132 | } |
Jeej | 0:a2bbc478f812 | 133 | |
Jeej | 0:a2bbc478f812 | 134 | double time_s = tim.read(); |
Jeej | 0:a2bbc478f812 | 135 | if (sent) |
Jeej | 0:a2bbc478f812 | 136 | { |
Jeej | 0:a2bbc478f812 | 137 | PRINT("%d bytes sent in %.3fs (%d B/s)\n", sent, time_s, (int)((double)sent/time_s)); |
Jeej | 0:a2bbc478f812 | 138 | } |
Jeej | 0:a2bbc478f812 | 139 | |
Jeej | 0:a2bbc478f812 | 140 | if (is_ok) |
Jeej | 0:a2bbc478f812 | 141 | { |
Jeej | 0:a2bbc478f812 | 142 | // Send CRC |
Jeej | 15:9a9cfb0c3c4e | 143 | PRINT("Sendind CRC 0x%08X... ", output->crc); |
Jeej | 15:9a9cfb0c3c4e | 144 | |
Jeej | 15:9a9cfb0c3c4e | 145 | alp = NULL; |
Jeej | 15:9a9cfb0c3c4e | 146 | alp = alp_payload_rsp_f_data(alp, FID_OUTPUT_FILE, &(output->crc), offsetof(output_file_t, crc), sizeof_field(output_file_t, crc)); |
Jeej | 0:a2bbc478f812 | 147 | |
Jeej | 15:9a9cfb0c3c4e | 148 | // Send |
Jeej | 15:9a9cfb0c3c4e | 149 | err = modem_remote_raw_alp((void*)&report_itf, alp, &rsp, 60000); |
Jeej | 15:9a9cfb0c3c4e | 150 | |
Jeej | 15:9a9cfb0c3c4e | 151 | if (ALP_ERR_UNKNOWN == err) |
Jeej | 0:a2bbc478f812 | 152 | { |
Jeej | 15:9a9cfb0c3c4e | 153 | PRINT("TIMEOUT.\n"); |
Jeej | 15:9a9cfb0c3c4e | 154 | } |
Jeej | 15:9a9cfb0c3c4e | 155 | else |
Jeej | 15:9a9cfb0c3c4e | 156 | { |
Jeej | 15:9a9cfb0c3c4e | 157 | err = alp_payload_get_err(rsp); |
Jeej | 15:9a9cfb0c3c4e | 158 | if (ALP_ERR_NONE <= err) |
Jeej | 0:a2bbc478f812 | 159 | { |
Jeej | 15:9a9cfb0c3c4e | 160 | PRINT("OK.\n"); |
Jeej | 0:a2bbc478f812 | 161 | } |
Jeej | 15:9a9cfb0c3c4e | 162 | else |
Jeej | 0:a2bbc478f812 | 163 | { |
Jeej | 15:9a9cfb0c3c4e | 164 | modem_print_error(report_itf.type, err); |
Jeej | 0:a2bbc478f812 | 165 | } |
Jeej | 15:9a9cfb0c3c4e | 166 | } |
Jeej | 15:9a9cfb0c3c4e | 167 | |
Jeej | 15:9a9cfb0c3c4e | 168 | alp_payload_free(rsp); |
Jeej | 0:a2bbc478f812 | 169 | } |
Jeej | 0:a2bbc478f812 | 170 | } |
Jeej | 0:a2bbc478f812 | 171 | } |
Jeej | 0:a2bbc478f812 | 172 | |
Jeej | 0:a2bbc478f812 | 173 | void thread_file_modified() |
Jeej | 0:a2bbc478f812 | 174 | { |
Jeej | 0:a2bbc478f812 | 175 | touch_t* touch; |
Jeej | 0:a2bbc478f812 | 176 | osEvent evt; |
Jeej | 0:a2bbc478f812 | 177 | uint8_t chunk[CHUNK_SIZE]; |
Jeej | 15:9a9cfb0c3c4e | 178 | int err; |
Jeej | 15:9a9cfb0c3c4e | 179 | alp_payload_t* alp; |
Jeej | 0:a2bbc478f812 | 180 | |
Jeej | 0:a2bbc478f812 | 181 | while (true) |
Jeej | 0:a2bbc478f812 | 182 | { |
Jeej | 0:a2bbc478f812 | 183 | evt = g_file_modified.get(); |
Jeej | 0:a2bbc478f812 | 184 | touch = (evt.status == osEventMessage)? (touch_t*)evt.value.p : NULL; |
Jeej | 0:a2bbc478f812 | 185 | ASSERT(touch != NULL, "NULL touch pointer!\n"); |
Jeej | 0:a2bbc478f812 | 186 | |
Jeej | 0:a2bbc478f812 | 187 | switch (touch->fid) |
Jeej | 0:a2bbc478f812 | 188 | { |
Jeej | 1:76a8a3cc5f2e | 189 | case FID_OUTPUT_FILE: |
Jeej | 1:76a8a3cc5f2e | 190 | output_file_t* output; |
Jeej | 1:76a8a3cc5f2e | 191 | uint32_t output_length; |
Jeej | 1:76a8a3cc5f2e | 192 | |
Jeej | 1:76a8a3cc5f2e | 193 | // Directly get data pointer to avoid reading file |
Jeej | 1:76a8a3cc5f2e | 194 | output = (output_file_t*)ram_fs_get_data(FID_OUTPUT_FILE); |
Jeej | 1:76a8a3cc5f2e | 195 | |
Jeej | 1:76a8a3cc5f2e | 196 | output_length = strlen((char*)output->data); |
Jeej | 1:76a8a3cc5f2e | 197 | |
Jeej | 1:76a8a3cc5f2e | 198 | // Update file CRC (Calculate CRC on string without end of string) |
Jeej | 1:76a8a3cc5f2e | 199 | output->crc = crc32((char*)output->data, output_length); |
Jeej | 1:76a8a3cc5f2e | 200 | |
Jeej | 1:76a8a3cc5f2e | 201 | PRINT("NEW OUTPUT CRC 0x%08X (on %d bytes)\n", output->crc, output_length); |
Jeej | 1:76a8a3cc5f2e | 202 | break; |
Jeej | 0:a2bbc478f812 | 203 | case FID_INPUT_FILE: |
Jeej | 1:76a8a3cc5f2e | 204 | input_file_t* input; |
Jeej | 1:76a8a3cc5f2e | 205 | uint32_t input_length; |
Jeej | 1:76a8a3cc5f2e | 206 | uint32_t crc; |
Jeej | 1:76a8a3cc5f2e | 207 | |
Jeej | 1:76a8a3cc5f2e | 208 | // Directly get data pointer to avoid reading file |
Jeej | 1:76a8a3cc5f2e | 209 | input = (input_file_t*)ram_fs_get_data(FID_INPUT_FILE); |
Jeej | 1:76a8a3cc5f2e | 210 | |
Jeej | 1:76a8a3cc5f2e | 211 | input_length = strlen((char*)input->data); |
Jeej | 1:76a8a3cc5f2e | 212 | |
Jeej | 1:76a8a3cc5f2e | 213 | // Calculate CRC |
Jeej | 1:76a8a3cc5f2e | 214 | crc = crc32((char*)input->data, input_length); |
Jeej | 0:a2bbc478f812 | 215 | |
Jeej | 0:a2bbc478f812 | 216 | // Check if CRC has been updated |
Jeej | 1:76a8a3cc5f2e | 217 | if ((offsetof(input_file_t, crc) == touch->offset) && (sizeof_field(input_file_t, crc) == touch->length)) |
Jeej | 0:a2bbc478f812 | 218 | { |
Jeej | 1:76a8a3cc5f2e | 219 | PRINT("INPUT CRC 0x%08X CRC 0x%08X (on %d bytes)\n", input->crc, crc, input_length); |
Jeej | 0:a2bbc478f812 | 220 | |
Jeej | 1:76a8a3cc5f2e | 221 | if (input->crc != crc) |
Jeej | 0:a2bbc478f812 | 222 | { |
Jeej | 0:a2bbc478f812 | 223 | // delete CRC |
Jeej | 1:76a8a3cc5f2e | 224 | input->crc = 0; |
Jeej | 0:a2bbc478f812 | 225 | } |
Jeej | 0:a2bbc478f812 | 226 | |
Jeej | 0:a2bbc478f812 | 227 | // Send CRC as confirmation |
Jeej | 1:76a8a3cc5f2e | 228 | PRINT("COMFIRM CRC 0x%08X\n", input->crc); |
Jeej | 15:9a9cfb0c3c4e | 229 | |
Jeej | 15:9a9cfb0c3c4e | 230 | alp = NULL; |
Jeej | 15:9a9cfb0c3c4e | 231 | alp = alp_payload_rsp_f_data(alp, FID_INPUT_FILE, &(input->crc), offsetof(input_file_t, crc), sizeof_field(input_file_t, crc)); |
Jeej | 0:a2bbc478f812 | 232 | |
Jeej | 15:9a9cfb0c3c4e | 233 | // Send |
Jeej | 15:9a9cfb0c3c4e | 234 | err = modem_remote_raw_alp((void*)&report_itf, alp, NULL, 3000); |
Jeej | 15:9a9cfb0c3c4e | 235 | |
Jeej | 15:9a9cfb0c3c4e | 236 | if (ALP_ERR_NONE <= err) |
Jeej | 0:a2bbc478f812 | 237 | { |
Jeej | 15:9a9cfb0c3c4e | 238 | PRINT("OK.\n"); |
Jeej | 15:9a9cfb0c3c4e | 239 | } |
Jeej | 15:9a9cfb0c3c4e | 240 | else |
Jeej | 15:9a9cfb0c3c4e | 241 | { |
Jeej | 15:9a9cfb0c3c4e | 242 | modem_print_error(report_itf.type, err); |
Jeej | 15:9a9cfb0c3c4e | 243 | } |
Jeej | 0:a2bbc478f812 | 244 | } |
Jeej | 1:76a8a3cc5f2e | 245 | else |
Jeej | 1:76a8a3cc5f2e | 246 | { |
Jeej | 1:76a8a3cc5f2e | 247 | PRINT("Got chunk %4d/%4d (%3d bytes)\n", touch->offset, sizeof_field(input_file_t, data), touch->length); |
Jeej | 15:9a9cfb0c3c4e | 248 | ram_fs_read(touch->fid, chunk, touch->offset, touch->length); |
Jeej | 1:76a8a3cc5f2e | 249 | //PRINT("%s\n", chunk); |
Jeej | 1:76a8a3cc5f2e | 250 | //PRINT_DATA("chunk end:", "%02X", &(chunk[touch->length-4]), 4, "\n"); |
Jeej | 1:76a8a3cc5f2e | 251 | |
Jeej | 1:76a8a3cc5f2e | 252 | PRINT("NEW INPUT CRC 0x%08X (on %d bytes)\n", crc, input_length); |
Jeej | 1:76a8a3cc5f2e | 253 | } |
Jeej | 0:a2bbc478f812 | 254 | break; |
Jeej | 0:a2bbc478f812 | 255 | default: |
Jeej | 0:a2bbc478f812 | 256 | PRINT("TOUCH FID %d OFF %d LEN %d\n", touch->fid, touch->offset, touch->length); |
Jeej | 0:a2bbc478f812 | 257 | break; |
Jeej | 0:a2bbc478f812 | 258 | } |
Jeej | 0:a2bbc478f812 | 259 | |
Jeej | 0:a2bbc478f812 | 260 | FREE(touch); |
Jeej | 0:a2bbc478f812 | 261 | } |
Jeej | 0:a2bbc478f812 | 262 | } |
Jeej | 0:a2bbc478f812 | 263 | |
Jeej | 15:9a9cfb0c3c4e | 264 | modem_ref_callbacks_t callbacks = { |
Jeej | 0:a2bbc478f812 | 265 | .read = my_read, |
Jeej | 0:a2bbc478f812 | 266 | .write = my_write, |
Jeej | 0:a2bbc478f812 | 267 | .read_fprop = my_read_fprop, |
Jeej | 0:a2bbc478f812 | 268 | .flush = my_flush, |
Jeej | 0:a2bbc478f812 | 269 | .remove = my_delete, |
Jeej | 0:a2bbc478f812 | 270 | .udata = my_udata, |
Jeej | 0:a2bbc478f812 | 271 | .lqual = my_lqual, |
Jeej | 0:a2bbc478f812 | 272 | .ldown = my_ldown, |
Jeej | 0:a2bbc478f812 | 273 | .reset = my_reset, |
Jeej | 6:33dfecc85ebf | 274 | .boot = my_boot, |
Jeej | 6:33dfecc85ebf | 275 | .busy = my_busy, |
Jeej | 0:a2bbc478f812 | 276 | }; |
Jeej | 0:a2bbc478f812 | 277 | |
Jeej | 0:a2bbc478f812 | 278 | |
Jeej | 0:a2bbc478f812 | 279 | /*** Main function ------------------------------------------------------------- ***/ |
Jeej | 0:a2bbc478f812 | 280 | int main() { |
Jeej | 0:a2bbc478f812 | 281 | // Start & initialize |
Jeej | 0:a2bbc478f812 | 282 | #ifdef DEBUG_LED |
Jeej | 0:a2bbc478f812 | 283 | DBG_OPEN(DEBUG_LED); |
Jeej | 0:a2bbc478f812 | 284 | #else |
Jeej | 0:a2bbc478f812 | 285 | DBG_OPEN(NC); |
Jeej | 0:a2bbc478f812 | 286 | #endif |
Jeej | 0:a2bbc478f812 | 287 | PRINT("\n" |
Jeej | 0:a2bbc478f812 | 288 | "-----------------------------------------\n" |
Jeej | 0:a2bbc478f812 | 289 | "------------- Demo Big File -------------\n" |
Jeej | 0:a2bbc478f812 | 290 | "-----------------------------------------\n"); |
Jeej | 1:76a8a3cc5f2e | 291 | |
Jeej | 15:9a9cfb0c3c4e | 292 | modem_open(&callbacks); |
Jeej | 0:a2bbc478f812 | 293 | |
Jeej | 0:a2bbc478f812 | 294 | // Start file modified thread |
Jeej | 15:9a9cfb0c3c4e | 295 | Thread th_file_modified(osPriorityNormal, 4096, NULL); |
Jeej | 0:a2bbc478f812 | 296 | osStatus status = th_file_modified.start(thread_file_modified); |
Jeej | 0:a2bbc478f812 | 297 | ASSERT(status == osOK, "Failed to start thread_file_modified (err: %d)\r\n", status); |
Jeej | 0:a2bbc478f812 | 298 | |
Jeej | 0:a2bbc478f812 | 299 | #ifdef DEBUG_BUTTON |
Jeej | 0:a2bbc478f812 | 300 | DebouncedInterrupt user_interrupt(DEBUG_BUTTON); |
Jeej | 0:a2bbc478f812 | 301 | user_interrupt.attach(button_push_isr, IRQ_FALL, 500, true); |
Jeej | 0:a2bbc478f812 | 302 | |
Jeej | 0:a2bbc478f812 | 303 | Thread but_th(osPriorityNormal, 4096, NULL); |
Jeej | 0:a2bbc478f812 | 304 | status = but_th.start(button_user_thread); |
Jeej | 0:a2bbc478f812 | 305 | ASSERT(status == osOK, "Failed to start but thread (err: %d)\r\n", status); |
Jeej | 0:a2bbc478f812 | 306 | #else |
Jeej | 0:a2bbc478f812 | 307 | #error You need a button to use this APP as is |
Jeej | 0:a2bbc478f812 | 308 | #endif |
Jeej | 0:a2bbc478f812 | 309 | |
Jeej | 0:a2bbc478f812 | 310 | #ifdef DEBUG_LED |
Jeej | 0:a2bbc478f812 | 311 | DigitalOut my_led(DEBUG_LED); |
Jeej | 0:a2bbc478f812 | 312 | #endif |
Jeej | 0:a2bbc478f812 | 313 | |
Jeej | 0:a2bbc478f812 | 314 | // Set main task to lowest priority |
Jeej | 11:dc0e19b2d4a0 | 315 | osThreadSetPriority(osThreadGetId(), osPriorityLow); |
Jeej | 0:a2bbc478f812 | 316 | while(true) |
Jeej | 0:a2bbc478f812 | 317 | { |
Jeej | 11:dc0e19b2d4a0 | 318 | ThisThread::sleep_for(500); |
Jeej | 0:a2bbc478f812 | 319 | #ifdef DEBUG_LED |
Jeej | 0:a2bbc478f812 | 320 | my_led = !my_led; |
Jeej | 0:a2bbc478f812 | 321 | #endif |
Jeej | 0:a2bbc478f812 | 322 | } |
Jeej | 0:a2bbc478f812 | 323 | } |