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:
- 26:9f0b9833cac6
- Parent:
- 25:aac250164497
- Child:
- 27:934ab7455115
--- a/src/d7a_modem.cpp Fri Mar 25 16:48:02 2016 +0000 +++ b/src/d7a_modem.cpp Thu Mar 31 14:48:50 2016 +0000 @@ -8,28 +8,49 @@ typedef struct { Thread* thread; - Semaphore* ready; + Queue<void, 8> ready; + Queue<void, 2> boot; Queue<d7a_com_rx_msg_t, 16> pkt_queue; + int8_t status; + DigitalInOut* reset; } d7a_modem_ctx_t; d7a_modem_ctx_t g_modem_ctx; void d7a_modem_thread(const void *p); -void d7a_modem_open( void ) +void d7a_modem_open( PinName reset_pin ) { FPRINT("\r\n"); - g_modem_ctx.ready = new Semaphore(1); g_modem_ctx.thread = new Thread(d7a_modem_thread, NULL, osPriorityBelowNormal, DEFAULT_STACK_SIZE*2); + g_modem_ctx.reset = new DigitalInOut(reset_pin, PIN_OUTPUT, OpenDrain, 0); + + Thread::wait(10); - // Wait to consume the semaphore - g_modem_ctx.ready->wait(); + // Release reset pin + *(g_modem_ctx.reset) = 1; + + // Wait for modem ready + osEvent evt = g_modem_ctx.boot.get(1000); + ASSERT(evt.status == osEventMessage, "MODEM BOOT Timeout\r\n"); } -void d7a_modem_wait_ready( uint32_t millisec ) + +int32_t d7a_modem_wait_ready( uint32_t millisec ) { FPRINT("\r\n"); - g_modem_ctx.ready->wait(millisec); + int32_t ret; + osEvent evt = g_modem_ctx.ready.get(millisec); + if (evt.status == osEventMessage) + { + ret = (int32_t)evt.value.p; + } + else + { + ret = (int32_t)0xFFFFFFFF; + EPRINT("MODEM Wait Timeout!\r\n"); + } + return ret; } void d7a_modem_new_pkt(d7a_com_rx_msg_t* pkt) @@ -67,25 +88,26 @@ .bf.flush_policy = flush_policy }; - d7a_fs_properties_t props; - // retrieve local properties - d7a_fs_get_properties(rparams.bf.fid,KAL_FS_PROP_ALL,&props); - if (props.type != HOST) + // Check If modem already has it + DPRINT("Register: %d\n", rparams.bf.fid); + d7a_fs_distant_stat(rparams.bf.fid, NULL); + g_modem_ctx.status = (int32_t)d7a_fs_wait_done(TO_FS); + if(g_modem_ctx.status < 0) { + d7a_fs_properties_t props; + // retrieve local properties + d7a_fs_get_properties(rparams.bf.fid, KAL_FS_PROP_ALL, &props); // create a remote Host file matching our local one props.type = HOST; - } - else - { - // create a remote Real file matching our local Host-one - props.type = EEPROM; + d7a_fs_distant_create(rparams.bf.fid, &props); + g_modem_ctx.status = (int32_t)d7a_fs_wait_done(TO_FS); } - d7a_fs_distant_create(rparams.bf.fid, &props); - d7a_modem_wait_ready(); - - // Distant file is ready, lets register a D7A Interface for it - d7a_modem_msg(WM_CMD_REGISTER_FILE,(uint8_t*)&rparams,sizeof(register_file_param_t)); - d7a_modem_wait_ready(); + if(g_modem_ctx.status == 0) + { + // Distant file is ready, lets register a D7A Interface for it + d7a_modem_msg(WM_CMD_REGISTER_FILE,(uint8_t*)&rparams,sizeof(register_file_param_t)); + d7a_modem_wait_ready(); + } } void d7a_modem_notify_file(uint8_t fid, uint32_t offset, uint32_t length) @@ -117,8 +139,13 @@ uint8_t cmd = pkt->buffer[0]; if (cmd == WM_CMD_READY) { - IPRINT("Modem ready\r\n"); - g_modem_ctx.ready->release(); + DPRINT("Modem ready\r\n"); + g_modem_ctx.ready.put(NULL); + } + else if (cmd == WM_CMD_BOOT) + { + DPRINT("Modem booted\r\n"); + g_modem_ctx.boot.put(NULL); } else {