Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of d7a_1x by
Diff: src/d7a_modem.cpp
- Revision:
- 77:8c792719a1fc
- Parent:
- 76:fda2e34ff19d
- Child:
- 78:f1c0affd99e7
--- a/src/d7a_modem.cpp Tue Dec 20 09:30:14 2016 +0000 +++ b/src/d7a_modem.cpp Wed Dec 21 10:47:29 2016 +0000 @@ -11,19 +11,15 @@ #define MODEM_TO (20000) -typedef struct { - Thread* thread; - Queue<void, 8> ready; - Queue<void, 2> boot; - Queue<d7a_com_rx_msg_t, 16> pkt_queue; - NotifDoneFunction notif_done; - uint8_t nb_files; - int8_t status; - PinName reset_pin; - bool booted; -} d7a_modem_ctx_t; - -d7a_modem_ctx_t g_modem_ctx; +static Thread g_modem_thread(osPriorityHigh, DEFAULT_STACK_SIZE, NULL); +static Queue<void, 8> g_modem_ready; +static Queue<void, 2> g_modem_boot; +static Queue<d7a_com_rx_msg_t, 8> g_modem_pkt_queue; +static NotifDoneFunction g_modem_notif_done; +static uint8_t g_modem_nb_files; +static int8_t g_modem_status; +static PinName g_modem_reset_pin; +static bool g_modem_booted; void d7a_modem_thread(); @@ -32,20 +28,18 @@ FPRINT("\r\n"); d7a_errors_t err; - - g_modem_ctx.thread = new Thread(osPriorityHigh, DEFAULT_STACK_SIZE*2, NULL); - - osStatus error = g_modem_ctx.thread->start(d7a_modem_thread); + + osStatus error = g_modem_thread.start(d7a_modem_thread); ASSERT(error == osOK, "Failed to start d7a_modem_thread (err: %d)\r\n", error); - g_modem_ctx.booted = false; - g_modem_ctx.nb_files = 0; - g_modem_ctx.notif_done = nd; - g_modem_ctx.reset_pin = reset_pin; + g_modem_booted = false; + g_modem_nb_files = 0; + g_modem_notif_done = nd; + g_modem_reset_pin = reset_pin; - if (g_modem_ctx.reset_pin != NC) + if (g_modem_reset_pin != NC) { - DigitalIn rst(g_modem_ctx.reset_pin); + DigitalIn rst(g_modem_reset_pin); } err = d7a_modem_reset(); @@ -57,11 +51,11 @@ { FPRINT("\r\n"); - g_modem_ctx.thread->terminate(); + g_modem_thread.terminate(); - if (g_modem_ctx.reset_pin != NC) + if (g_modem_reset_pin != NC) { // Release reset - DigitalIn rst(g_modem_ctx.reset_pin); + DigitalIn rst(g_modem_reset_pin); } return D7A_ERR_NONE; @@ -70,14 +64,14 @@ d7a_errors_t d7a_modem_wait_boot( uint32_t millisec ) { FPRINT("(%d)\r\n", millisec); - osEvent evt = g_modem_ctx.boot.get(millisec); + osEvent evt = g_modem_boot.get(millisec); return (evt.status == osEventMessage)? (d7a_errors_t)(int32_t)evt.value.p : D7A_ERR_CMD_TO; } d7a_errors_t d7a_modem_wait_ready( uint32_t millisec ) { FPRINT("(%d)\r\n", millisec); - osEvent evt = g_modem_ctx.ready.get(millisec); + osEvent evt = g_modem_ready.get(millisec); return (evt.status == osEventMessage)? (d7a_errors_t)(int32_t)evt.value.p : D7A_ERR_CMD_TO; } @@ -100,18 +94,18 @@ IPRINT("MODEM Hard Reset.\r\n"); // Use hardware reset - if (g_modem_ctx.reset_pin != NC) + if (g_modem_reset_pin != NC) { // Clear reset - DigitalOut rst(g_modem_ctx.reset_pin, 0); + DigitalOut rst(g_modem_reset_pin, 0); } // Clean buffer and queues d7a_com_restart(); Thread::wait(100); - if (g_modem_ctx.reset_pin != NC) + if (g_modem_reset_pin != NC) { // Release reset - DigitalIn rst(g_modem_ctx.reset_pin); + DigitalIn rst(g_modem_reset_pin); } } @@ -119,7 +113,7 @@ { FPRINT("\r\n"); d7a_errors_t err = D7A_ERR_UNKNOWN; - g_modem_ctx.booted = false; + g_modem_booted = false; //d7a_modem_soft_reset(); //err = d7a_modem_wait_boot(5000); @@ -130,7 +124,7 @@ err = d7a_modem_wait_boot(MODEM_TO); } ASSERT(!err, "MODEM BOOT err %d\r\n", err); - g_modem_ctx.booted = true; + g_modem_booted = true; err = d7a_modem_wait_ready(MODEM_TO); ASSERT(!err, "MODEM READY err %d\r\n", err); @@ -143,13 +137,13 @@ void d7a_modem_new_pkt(d7a_com_rx_msg_t* pkt) { FPRINT("\r\n"); - ASSERT(g_modem_ctx.pkt_queue.put(pkt) == osOK, "MODEM queue full!\r\n"); + ASSERT(g_modem_pkt_queue.put(pkt) == osOK, "MODEM queue full!\r\n"); } d7a_com_rx_msg_t* d7a_modem_wait_pkt(uint32_t millisec) { FPRINT("(millisec:%d)\r\n", millisec); - osEvent evt = g_modem_ctx.pkt_queue.get(millisec); + osEvent evt = g_modem_pkt_queue.get(millisec); return (evt.status == osEventMessage)? (d7a_com_rx_msg_t*)evt.value.p : NULL; } @@ -233,20 +227,20 @@ if (cmd == WM_OK) { DPRINT("Modem ready\r\n"); - g_modem_ctx.ready.put((void*)D7A_ERR_NONE); + g_modem_ready.put((void*)D7A_ERR_NONE); } else if (cmd == WM_BOOT) { boot_status_t* bs = (boot_status_t*)&(pkt->buffer[1]); WARNING(false, "Modem booted CAUSE:%d NB_BOOT:%d\r\n", bs->bf.cause, bs->bf.nb_boot); - if (g_modem_ctx.booted == true) + if (g_modem_booted == true) { // Do something? } else { - g_modem_ctx.boot.put(NULL); + g_modem_boot.put(NULL); } } else if (cmd == WM_ERROR) @@ -265,13 +259,13 @@ default: ret = D7A_ERR_NONE; break; } - g_modem_ctx.ready.put((void*)ret); + g_modem_ready.put((void*)ret); } else if (cmd == WM_NOTIF_DONE) { - if (g_modem_ctx.notif_done != NULL) + if (g_modem_notif_done != NULL) { - g_modem_ctx.notif_done(pkt->buffer[1], pkt->buffer[2]); + g_modem_notif_done(pkt->buffer[1], pkt->buffer[2]); } } else