1SJ Test_Example Tx

Dependencies:   sx126x sx12xx_hal

Revision:
2:3f4dfcc3bab6
Parent:
0:83bfd3e3c4c4
Child:
4:9696eee39801
--- a/main.cpp	Tue Jul 17 16:26:01 2018 -0700
+++ b/main.cpp	Thu Sep 12 15:52:01 2019 -0700
@@ -18,19 +18,45 @@
 #endif
 
 /**********************************************************************/
-volatile bool txDone;
+EventQueue queue(4 * EVENTS_EVENT_SIZE);
+
+void tx_test()
+{
+    uint8_t seq = 0;
+
+    Radio::radio.tx_buf[0] = seq++;  /* set payload */
+    Radio::Send(1, 0, 0, 0);   /* begin transmission */
+    printf("sent\r\n");
+
+/*    {
+        mbed_stats_cpu_t stats;
+        mbed_stats_cpu_get(&stats);
+        printf("canDeep:%u ", sleep_manager_can_deep_sleep());
+        printf("Uptime: %llu ", stats.uptime / 1000);
+        printf("Sleep time: %llu ", stats.sleep_time / 1000);
+        printf("Deep Sleep: %llu\r\n", stats.deep_sleep_time / 1000);
+    }*/
+}
 
 void txDoneCB()
 {
-    txDone = true;
+    printf("got-tx-done\r\n");
+    queue.call_in(500, tx_test);
 }
 
 void rxDoneCB(uint8_t size, float rssi, float snr)
 {
 }
 
+
+void radio_irq_callback()
+{
+    queue.call(Radio::service);
+}
+
+
 const RadioEvents_t rev = {
-    /* Dio0_top_half */     NULL,
+    /* DioPin_top_half */     radio_irq_callback,
     /* TxDone_topHalf */    NULL,
     /* TxDone_botHalf */    txDoneCB,
     /* TxTimeout  */        NULL,
@@ -43,7 +69,7 @@
 
 int main()
 {
-    uint8_t seq = 0;
+    //uint8_t seq = 0;
 
     printf("\r\nreset-tx ");
 
@@ -58,20 +84,8 @@
                // preambleLen, fixLen, crcOn, invIQ
     Radio::LoRaPacketConfig(8, false, true, false);
 
-    for (;;) {
-        Radio::radio.tx_buf[0] = seq;  /* set payload */
-        txDone = false;
-        Radio::Send(1, 0, 0, 0);   /* begin transmission */
+    queue.call_in(500, tx_test);
 
-        printf("sent\r\n");
-        while (!txDone) {
-            Radio::service();
-        }
-
-        printf("got-tx-done\r\n");
-
-        wait(0.5);  /* throttle sending rate */
-        seq++;  /* change payload */
-    }
+    queue.dispatch();
 }