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.
Dependencies: modem_ref_helper CRC
Diff: modem_callbacks.cpp
- Revision:
- 0:5589104abba0
- Child:
- 1:dd4e18b267a1
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/modem_callbacks.cpp Thu Feb 01 11:42:42 2018 +0000
@@ -0,0 +1,127 @@
+#include "modem_ref_helper.h"
+#include "files.h"
+#include "fast_crc32.h"
+
+#define SERIAL_MAX_PACKET_SIZE (255)
+
+uint32_t stream_crc = 0;
+
+// ============================================================}}}
+
+// Callbacks to MODEM's ALP requests
+// ============================================================{{{
+void my_read(u8 fid, u32 offset, u32 length, int id)
+{
+ u8 data[SERIAL_MAX_PACKET_SIZE];
+
+ ASSERT((ALP_ACTION_RSP_TAG_SIZE + ALP_ACTION_RSP_F_DATA_SIZE(offset, length)) <= SERIAL_MAX_PACKET_SIZE,
+ "Read response too big for serial protocol (%d/%dmax)\r\n", length, ALP_ACTION_RSP_TAG_SIZE + ALP_ACTION_RSP_F_DATA_SIZE(offset,SERIAL_MAX_PACKET_SIZE));
+
+ if (ram_fs_read(fid, offset, length, data))
+ {
+ modem_respond(0, ALP_ERR_FILE_NOT_FOUND, id);
+ }
+ else
+ {
+ modem_respond_read(fid, data, offset, length, id);
+ }
+}
+
+void my_write(u8 fid, void *data, u32 offset, u32 length, int id)
+{
+ if (!ram_fs_write(fid, offset, length, (uint8_t*)data) || FID_APP_CUP_CODE == fid)
+ {
+ touch_t* touch = (touch_t*)MALLOC(sizeof(touch_t));
+
+ if (FID_APP_CUP_CODE == fid)
+ {
+ // Calculate crc on chunk
+ stream_crc = crc32_fast(data, length, stream_crc);
+
+ /************************/
+ /* Save the chunk data. */
+ /************************/
+ }
+
+ touch->fid = fid;
+ touch->offset = offset;
+ touch->length = length;
+
+ g_file_modified.put(touch);
+
+ modem_respond(0, ALP_ERR_NONE, id);
+ }
+ else
+ {
+ modem_respond(0, ALP_ERR_FILE_NOT_FOUND, id);
+ }
+}
+
+void my_read_fprop(u8 fid, int id)
+{
+ u8* hdr = (u8*)ram_fs_get_header(fid);
+
+ if (hdr != NULL)
+ {
+ modem_respond_fprop(fid, hdr, id);
+ }
+ else
+ {
+ modem_respond(0, ALP_ERR_FILE_NOT_FOUND, id);
+ }
+}
+
+void my_flush(u8 fid, int id)
+{
+ // No flush in this file system
+ modem_respond(0, ALP_ERR_NONE, id);
+}
+
+void my_delete(u8 fid, int id)
+{
+ modem_respond(0, ALP_ERR_FILE_NOT_FOUND, id);
+}
+
+void my_udata(u8 fid, void *data, u32 offset, u32 length, u8 i_type, u8 i_length, u8* i_data)
+{
+ (void)data;
+ (void)i_length;
+ PRINT("Got UNS File[%3d]@%d %d Bytes\r\n",fid,offset,length);
+ if (i_type == ALP_ITF_TYPE_D7A)
+ {
+ static union {
+ u8 b[8];
+ u32 w[2];
+ } uid;
+ d7a_sp_res_t* istat = (d7a_sp_res_t*) i_data;
+ memcpy(uid.b,istat->addressee.id,8);
+ PRINT("From UID: %08X%08X (rxlev:%d lb:%d)\r\n",
+ HAL_U32_BYTE_SWAP(uid.w[0]), HAL_U32_BYTE_SWAP(uid.w[1]),
+ istat->rxlev, istat->lb);
+ }
+}
+
+void my_lqual(u8 ifid, int per)
+{
+ PRINT("Interface File [%3d] LQUAL : %d%% PER\r\n", ifid, per);
+}
+
+void my_ldown(u8 ifid)
+{
+ PRINT("Interface File [%3d] LDOWN\r\n", ifid);
+}
+
+void my_reset(void)
+{
+ PRINT("Restarting application...\r\n");
+ FLUSH();
+ NVIC_SystemReset();
+}
+
+void my_boot(u8 cause, u16 number)
+{
+ PRINT("Modem BOOT[%c] #%d\r\n", cause, number);
+
+ // Modem re-booted, restart APP
+ my_reset();
+}
\ No newline at end of file