Helper library to use modem_ref driver.
Dependencies: WizziCom WizziDebug ram_fs modem_ref
Dependents: D7A_Localisation D7A_1x_demo_send_file_data_and_forget D7A_1x_demo_CodeUpgradeProtocol D7A_1x_demo_LoRaWAN ... more
Diff: modem_ref_helper.cpp
- Revision:
- 12:04c32f2e03b7
- Parent:
- 9:5d850e56ac20
- Child:
- 15:c90efeb6bd6a
--- a/modem_ref_helper.cpp Wed Sep 20 14:41:06 2017 +0000 +++ b/modem_ref_helper.cpp Wed Sep 20 16:53:30 2017 +0000 @@ -127,6 +127,13 @@ modem_free_id(user_id); } +Semaphore boot(0); +void my_startup_boot(u8 cause, u16 number) +{ + HELPER_PRINT("Modem BOOT[%c] #%d\r\n", cause, number); + boot.release(); +} + void modem_helper_open(modem_callbacks_t* callbacks) { static union { @@ -134,22 +141,42 @@ uint32_t w[2]; } uid; revision_t rev; - - // Hardware reset - DigitalOut reset_low(MODEM_PIN_RESET, 0); - Thread::wait(100); - - // Release reset - DigitalIn reset_release(MODEM_PIN_RESET); - Thread::wait(2000); + + // Override boot callback to catch the first boot message + modem_callbacks_t boot_callbacks = { + .read = NULL, + .write = NULL, + .read_fprop = NULL, + .flush = NULL, + .remove = NULL, + .udata = NULL, + .lqual = NULL, + .ldown = NULL, + .reset = NULL, + .boot = my_startup_boot + }; // Open modem Com port g_modem_com = new WizziCom(MODEM_PIN_TX, MODEM_PIN_RX, MODEM_PIN_IRQ_OUT, MODEM_PIN_IRQ_IN); + // Hardware reset + DigitalOut reset_low(MODEM_PIN_RESET, 0); + Thread::wait(100); + + // Open driver to catch boot packet + modem_open(NULL, &boot_callbacks); + // Redirect All Port traffic to modem_serial_input g_modem_com->attach(modem_serial_input, WizziComPacketUntreated); - - // Open driver + + // Release reset + DigitalIn reset_release(MODEM_PIN_RESET); + + // Wait for first boot packet + boot.wait(); + + // Re-open with user callbacks + modem_close(); modem_open(modem_serial_send, callbacks); uint8_t user_id = modem_get_id(my_main_callback);