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 DebouncedInterrupt
Diff: main.cpp
- Revision:
- 6:05e26c3a495a
- Parent:
- 5:ee132af18614
- Child:
- 7:c34074bfef49
diff -r ee132af18614 -r 05e26c3a495a main.cpp
--- a/main.cpp Wed May 17 14:45:48 2017 +0000
+++ b/main.cpp Thu May 18 13:47:16 2017 +0000
@@ -1,30 +1,12 @@
// @autor: jeremie@wizzilab.com
// @date: 2017-05-02
-#include "mbed.h"
-#include "rtos.h"
#include "DebouncedInterrupt.h"
-#include "WizziDebug.h"
-#include "WizziCom.h"
-
-#include "hwcfg.h"
+#include "modem_ref_helper.h"
+#include "modem_callbacks.h"
#include "files.h"
-#include "ram_fs.h"
-#include "modem_callbacks.h"
-#include "revision.h"
-#include "alp_spec.h"
-#include "alp_helpers.h"
-#include "modem_ref.h"
-#include "kal_fs.h"
-#include "d7a_1x.h"
-#include "d7a_1x_fs.h"
-#include "alp.h"
-#define MODEM_VERSION_MAJOR 4
-#define MODEM_VERSION_MINOR 8
-
-WizziCom* g_modem_com;
Semaphore button_user(0);
Semaphore modem_ready(0);
Queue<void, 8> modem_resp;
@@ -37,13 +19,6 @@
MODEM_RESP_DONE,
};
-TYPEDEF_STRUCT_PACKED {
- uint8_t type;
- d7a_sp_cfg_t cfg;
-} alp_d7a_itf_t;
-
-#define D7A_CTF_VAL(mant,exp) ((uint8_t)(mant|(exp<<5)))
-#define ALP_ITF_TYPE_D7A 0xD7
alp_d7a_itf_t alarm_itf = {
.type = ALP_ITF_TYPE_D7A,
.cfg.to = 0,
@@ -58,14 +33,6 @@
.cfg.qos.bf.retry = 1 // XXX WM_RPOL_RARE_SINGLE_CHECK,
};
-#define MY_D7_ITF_SIZE(_itf) (1+my_alp_itf_d7a_cfg_size(&(_itf)->cfg))
-int my_alp_itf_d7a_cfg_size(d7a_sp_cfg_t* cfg)
-{
- int size = sizeof(d7a_sp_cfg_t) - sizeof(d7a_addressee_t);
- size += D7A_ADDR_LEN(cfg->addressee.ctrl);
- return size;
-}
-
// Interrupt Service Routine on button press.
void button_push_isr( void )
{
@@ -109,7 +76,7 @@
ram_fs_read(FID_ALARM, 0, 1, &alarm);
// Send initial value
- modem_send_file_content((uint8_t*)&alarm_itf, MY_D7_ITF_SIZE(&alarm_itf), (void*)&istat, FID_ALARM, &alarm, 0, 1, g_main_id);
+ modem_send_file_content((uint8_t*)&alarm_itf, D7_ITF_SIZE(&alarm_itf), (void*)&istat, FID_ALARM, &alarm, 0, 1, g_main_id);
modem_ready.wait();
while (true)
@@ -117,6 +84,8 @@
// Wait for button press
button_user.wait();
+ nb = 0;
+
// load/save value to keep choerency in case of remote access...
ram_fs_read(FID_ALARM, 0, 1, &alarm);
@@ -127,7 +96,7 @@
PRINT("BUTTON ALARM %d\r\n", alarm);
- modem_send_file_content((uint8_t*)&alarm_itf, MY_D7_ITF_SIZE(&alarm_itf), (void*)&istat, FID_ALARM, &alarm, 0, 1, my_user_id);
+ modem_send_file_content((uint8_t*)&alarm_itf, D7_ITF_SIZE(&alarm_itf), (void*)&istat, FID_ALARM, &alarm, 0, 1, my_user_id);
do
{
@@ -187,32 +156,13 @@
}
}
-// ============================================================}}}
-
-// Serial adapters to WizziLab's own architecture
-// ============================================================{{{
-
-void my_serial_input(WizziCom* com, WizziComPacket_t* pkt)
-{
- modem_input(wizzicom_type_to_flow(pkt->type), pkt->data, pkt->length);
- FREE(pkt);
-}
-
-int my_serial_send(uint8_t* data1, uint8_t size1, uint8_t* data2, uint8_t size2)
-{
- (void)size1;
-
- g_modem_com->send((WizziComPacketType)wizzicom_flow_to_type(data1[4]), size2, data2);
-
- return (size1 + size2);
-}
-
modem_callbacks_t callbacks = {
.read = my_read,
.write = my_write,
.read_fprop = my_read_fprop,
.flush = my_flush,
.remove = my_delete,
+ .udata = my_udata,
.lqual = my_lqual,
.ldown = my_ldown,
.reset = my_reset,
@@ -235,104 +185,22 @@
}
}
-void modem_update_file(uint8_t fid, alp_file_header_t* header, uint8_t* data)
-{
- alp_file_header_t remote_header;
-
- memset(&remote_header, 0, sizeof(alp_file_header_t));
-
- // Read remote header
- modem_read_fprop(fid, &remote_header, g_main_id);
- modem_ready.wait();
-
- // Add file in local file system
- ram_fs_new(fid, (uint8_t*)header, data);
-
- // Update file
- if (memcmp(&remote_header, header, sizeof(alp_file_header_t)))
- {
- PRINT("Updating file %d\n", fid);
- // Delete
- modem_delete_file(fid, g_main_id);
- modem_ready.wait();
- // Restore in local file system
- ram_fs_new(fid, (uint8_t*)header, data);
- // Re-create
- if (data)
- {
- modem_declare_file(fid, header, g_main_id);
- }
- else
- {
- modem_create_file(fid, header, g_main_id);
- }
- modem_ready.wait();
- }
- else
- {
- PRINT("File %d up to date\n", fid);
- }
-}
/*** Main function ------------------------------------------------------------- ***/
int main()
{
// Start & initialize
+#ifdef DEBUG_LED
DBG_OPEN(DEBUG_LED);
+#else
+ DBG_OPEN(NC);
+#endif
PRINT("\r\n--- Starting new run ---\r\n");
FPRINT("(id:0x%08x)\r\n", osThreadGetId());
- static union {
- uint8_t b[8];
- 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);
-
- // Open modem Com port
- g_modem_com = new WizziCom(MODEM_PIN_TX, MODEM_PIN_RX, MODEM_PIN_IRQ_OUT, MODEM_PIN_IRQ_IN);
-
- // Redirect All Port traffic to my_serial_input
- g_modem_com->attach(my_serial_input, WizziComPacketOther);
-
- modem_open(my_serial_send, &callbacks);
+ modem_helper_open(&callbacks);
g_main_id = modem_get_id(my_main_callback);
-
- PRINT("Start Modem Process (id=%d)\n", g_main_id);
- Thread::wait(1000);
-
- modem_read_file(D7A_FID_UID, uid.b, 0, 8, g_main_id);
- modem_ready.wait();
-
- modem_read_file(D7A_FID_FIRMWARE_VERSION, (uint8_t*)&rev, 0, sizeof(revision_t), g_main_id);
- modem_ready.wait();
-
- PRINT("------------ D7A Modem infos ------------\r\n");
- PRINT_DATA(" - UID: ", "%02X", uid.b, 8, "\r\n");
- PRINT(" - Manufacturer ID: %08X\r\n", rev.manufacturer_id);
- PRINT(" - Device ID: %08X\r\n", rev.device_id);
- PRINT(" - Hardware version: %08X\r\n", rev.hw_version);
- PRINT(" - Firmware version: v%d.%d.%d\r\n", rev.fw_version.major, rev.fw_version.minor, rev.fw_version.patch);
- PRINT(" - File system CRC: 0x%08x\r\n", rev.fs_crc);
- PRINT("-----------------------------------------\r\n");
-
- // Check version
- if (rev.fw_version.major != MODEM_VERSION_MAJOR || rev.fw_version.minor != MODEM_VERSION_MINOR)
- {
- PRINT("You need a modem at version %d.%d.x to use this APP.\n"
- "Please check updates by importing:\n"
- "https://developer.mbed.org/teams/WizziLab/code/D7A_WM_Updater\n"
- , MODEM_VERSION_MAJOR, MODEM_VERSION_MINOR);
- Thread::wait(osWaitForever);
- }
PRINT("Register Files\n");
// HOST Revision is a local file. Uses D7AActP Notification.
@@ -369,7 +237,7 @@
ASSERT(status == osOK, "Failed to start but thread (err: %d)\r\n", status);
#endif
-#if (DEBUG_LED != NC)
+#ifdef DEBUG_LED
DigitalOut my_led(DEBUG_LED);
#endif
@@ -378,7 +246,7 @@
while(true)
{
Thread::wait(500);
-#if (DEBUG_LED != NC)
+#ifdef DEBUG_LED
my_led = !my_led;
#endif
}