Data reception demo.
Dependencies: modem_ref_helper CRC
Diff: main.cpp
- Revision:
- 9:72a15235e097
- Parent:
- 7:84dc04f88c94
- Child:
- 10:c262c5feac24
diff -r b1f08ef0f9d9 -r 72a15235e097 main.cpp --- a/main.cpp Fri Mar 09 16:18:19 2018 +0000 +++ b/main.cpp Thu Sep 20 11:21:55 2018 +0000 @@ -13,7 +13,7 @@ Semaphore modem_ready(0); Queue<void, 8> g_file_modified; -uint8_t g_main_id; +uint8_t id; uint32_t g_restore_time = RESTORE_TIME + 1; void display_logo(void) @@ -22,12 +22,38 @@ sendImage(); } +void print_status(uint8_t id, int status) +{ + switch (status) + { + case ALP_ERR_NONE: + PRINT("Status[%d]: OK\n", id); + break; + default: + PRINT("Status[%d]: error %d\n", id, status); + break; + } +} + +static void my_main_callback(uint8_t terminal, int8_t err, uint8_t id) +{ + (void)id; + + print_status(id, err); + + if (terminal) + { + modem_ready.release(); + } +} + void thread_reset_display() { FPRINT("(id:0x%08x)\r\n", osThreadGetId()); uint32_t time = 0; uint8_t status = 0; + uint8_t id = modem_get_id(my_main_callback); while (true) { @@ -39,7 +65,7 @@ if ((time++ % KEEP_ALIVE) == 0) { // Keep alive: Report status - modem_write_file(FID_STATUS_FILE, &status, 0, SIZE_STATUS_FILE, g_main_id); + modem_write_file(FID_STATUS_FILE, &status, 0, SIZE_STATUS_FILE, id); modem_ready.wait(); } @@ -91,33 +117,10 @@ .lqual = my_lqual, .ldown = my_ldown, .reset = my_reset, - .boot = my_boot + .boot = my_boot, + .busy = my_busy, }; -void print_status(int status) -{ - switch (status) - { - case ALP_ERR_NONE: - PRINT("Status: OK\n"); - break; - default: - PRINT("Status: error %d\n", status); - break; - } -} - -static void my_main_callback(uint8_t terminal, int8_t err, uint8_t id) -{ - (void)id; - - if (terminal) - { - print_status(err); - modem_ready.release(); - } -} - /*** Main function ------------------------------------------------------------- ***/ int main() { @@ -136,7 +139,7 @@ modem_helper_open(&callbacks); - g_main_id = modem_get_id(my_main_callback); + uint8_t id = modem_get_id(my_main_callback); PRINT("Register Files\n"); // HOST Revision is a local file. Uses D7AActP Notification. @@ -148,26 +151,28 @@ // Put modem to listen to this access class d7a_xcl_t my_xcl = { .bf.s = 0, .bf.m = 2 }; - modem_write_file(D7A_FID_DLL_CFG, &my_xcl, 0, sizeof(d7a_xcl_t), g_main_id); + modem_write_file(D7A_FID_DLL_CFG, &my_xcl, 0, sizeof(d7a_xcl_t), id); modem_ready.wait(); // Configure URC: LQUAL on report file notification every 10 reports PRINT("Setup URCs\n"); - modem_enable_urc(ALP_URC_TYPE_LQUAL, IFID_REPORT, 10, true, g_main_id); + modem_enable_urc(ALP_URC_TYPE_LQUAL, IFID_REPORT, 10, true, id); modem_ready.wait(); PRINT("Start D7A Stack\n"); - modem_activate_itf(ALP_ITF_TYPE_D7A, 24, 0, ALP_D7A_ISTAT_RESP | ALP_D7A_ISTAT_UNS , true, g_main_id); + modem_activate_itf(ALP_ITF_TYPE_D7A, 24, 0, ALP_D7A_ISTAT_RESP | ALP_D7A_ISTAT_UNS , true, id); modem_ready.wait(); PRINT("Notify Modem Version\n"); - modem_notify_file(D7A_FID_FIRMWARE_VERSION, 0, SIZE_HOST_REV, g_main_id); + modem_notify_file(D7A_FID_FIRMWARE_VERSION, 0, SIZE_HOST_REV, id); modem_ready.wait(); PRINT("Notify FW Version\n"); - modem_notify_file(FID_HOST_REV, 0, SIZE_HOST_REV, g_main_id); + modem_notify_file(FID_HOST_REV, 0, SIZE_HOST_REV, id); modem_ready.wait(); + modem_free_id(id); + // Start file modified thread Thread th_file_modified(osPriorityNormal, 512, NULL); osStatus status = th_file_modified.start(thread_file_modified);