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.cpp
- Revision:
- 66:492b1d7ba370
- Parent:
- 63:afd046faedb0
- Child:
- 67:9ac9d109b80a
diff -r ac3844adfe49 -r 492b1d7ba370 src/d7a.cpp
--- a/src/d7a.cpp Fri Oct 14 10:52:22 2016 +0000
+++ b/src/d7a.cpp Fri Oct 21 15:31:45 2016 +0000
@@ -12,14 +12,14 @@
#define FIRST_IFT_FILE (108)
bool g_open = false;
+bool g_started = false;
bool g_local_fs = false;
-
d7a_errors_t d7a_open(const d7a_com_config_t* com_config, PinName reset_pin, const d7a_callbacks_t* callbacks)
{
FPRINT("\r\n");
- d7a_errors_t err;
+ d7a_errors_t err = D7A_ERR_STATE;
if (g_open)
{
@@ -50,7 +50,8 @@
g_local_fs = true;
}
- g_open = true;
+ g_open = true;
+ g_started = true;
} while (0);
@@ -64,7 +65,7 @@
{
FPRINT("\r\n");
- d7a_errors_t err;
+ d7a_errors_t err = D7A_ERR_STATE;
do
{
@@ -90,9 +91,16 @@
{
FPRINT("\r\n");
- d7a_errors_t err;
+ d7a_errors_t err = D7A_ERR_STATE;
- err = d7a_modem_start();
+ if (!g_started)
+ {
+ err = d7a_modem_start();
+ if (err == D7A_ERR_NONE)
+ {
+ g_started = true;
+ }
+ }
WARNING(err == D7A_ERR_NONE, "%s err %d\r\n", __FUNCTION__, err);
@@ -104,9 +112,16 @@
{
FPRINT("\r\n");
- d7a_errors_t err;
+ d7a_errors_t err = D7A_ERR_STATE;
- err = d7a_modem_stop();
+ if (g_started)
+ {
+ err = d7a_modem_stop();
+ if (err == D7A_ERR_NONE)
+ {
+ g_started = false;
+ }
+ }
WARNING(err == D7A_ERR_NONE, "%s err %d\r\n", __FUNCTION__, err);
@@ -118,22 +133,25 @@
{
FPRINT("\r\n");
- d7a_errors_t err;
+ d7a_errors_t err = D7A_ERR_STATE;
DPRINT("Create %d.\r\n", file_id);
- register_file_param_t file_infos = {
- .fid = file_id,
- .type = RAM,
- .afid = action,
- .ifid = FIRST_IFT_FILE + retry, // The interface files match the retry policies
- .prop = (uint8_t)prop | ((action)? FS_ACT_EN : 0),
- .perm = (uint8_t)perm,
- .size = size,
- .alloc = alloc,
- };
-
- err = d7a_modem_register(&file_infos);
+ if (g_started)
+ {
+ register_file_param_t file_infos = {
+ .fid = file_id,
+ .type = RAM,
+ .afid = action,
+ .ifid = FIRST_IFT_FILE + retry, // The interface files match the retry policies
+ .prop = (uint8_t)prop | ((action)? FS_ACT_EN : 0),
+ .perm = (uint8_t)perm,
+ .size = size,
+ .alloc = alloc,
+ };
+
+ err = d7a_modem_register(&file_infos);
+ }
DPRINT("Create %d Done. err %d\r\n", file_id, err);
@@ -147,24 +165,27 @@
{
FPRINT("\r\n");
- d7a_errors_t err;
+ d7a_errors_t err = D7A_ERR_STATE;
DPRINT("Declare %d.\r\n", file_id);
ASSERT(g_local_fs, "You cannot delare a file if the write_file/read_file callbacks are not specified\r\n");
- register_file_param_t file_infos = {
- .fid = file_id,
- .type = HOST+RAM,
- .afid = action,
- .ifid = FIRST_IFT_FILE + retry, // The interface files match the retry policies
- .prop = (uint8_t)prop | ((action)? FS_ACT_EN : 0),
- .perm = (uint8_t)perm,
- .size = length,
- .alloc = alloc,
- };
-
- err = d7a_modem_register(&file_infos);
+ if (g_started)
+ {
+ register_file_param_t file_infos = {
+ .fid = file_id,
+ .type = HOST+RAM,
+ .afid = action,
+ .ifid = FIRST_IFT_FILE + retry, // The interface files match the retry policies
+ .prop = (uint8_t)prop | ((action)? FS_ACT_EN : 0),
+ .perm = (uint8_t)perm,
+ .size = length,
+ .alloc = alloc,
+ };
+
+ err = d7a_modem_register(&file_infos);
+ }
DPRINT("Declare %d Done\r\n", file_id);
@@ -178,11 +199,14 @@
{
FPRINT("\r\n");
- d7a_msg_t** ret;
+ d7a_msg_t** ret = NULL;
DPRINT("Read %d @%d %d bytes.\r\n", file_id, offset, size);
- ret = d7a_alp_read_file(file_id, offset, size, addressee, retry);
+ if (g_started)
+ {
+ ret = d7a_alp_read_file(file_id, offset, size, addressee, retry);
+ }
DPRINT("Read %d Done.\r\n", file_id);
@@ -196,11 +220,14 @@
{
FPRINT("\r\n");
- d7a_msg_t** ret;
+ d7a_msg_t** ret = NULL;
DPRINT("Write %d @%d %d bytes.\r\n", file_id, offset, size);
- ret = d7a_alp_write_file(file_id, offset, size, buf, addressee, retry, resp);
+ if (g_started)
+ {
+ ret = d7a_alp_write_file(file_id, offset, size, buf, addressee, retry, resp);
+ }
DPRINT("Write %d Done.\r\n", file_id);
@@ -214,17 +241,20 @@
{
FPRINT("\r\n");
- d7a_errors_t err;
+ d7a_errors_t err = D7A_ERR_STATE;
DPRINT("Notify %d @%d %d bytes.\r\n", file_id, offset, size);
- notify_file_param_t notif = {
- .bf.fid = file_id,
- .bf.offset = offset,
- .bf.size = size
- };
-
- err = d7a_modem_notify(¬if);
+ if (g_started)
+ {
+ notify_file_param_t notif = {
+ .bf.fid = file_id,
+ .bf.offset = offset,
+ .bf.size = size
+ };
+
+ err = d7a_modem_notify(¬if);
+ }
DPRINT("Notify %d Done. err %d\r\n", file_id, err);
