1SJ Test_Example Tx

Dependencies:   sx126x sx12xx_hal

Committer:
lorgei
Date:
Mon Jan 17 17:36:25 2022 +0000
Revision:
4:9696eee39801
Parent:
2:3f4dfcc3bab6
1SJ Test Ex

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Wayne Roberts 0:83bfd3e3c4c4 1 #include "radio.h"
Wayne Roberts 0:83bfd3e3c4c4 2
Wayne Roberts 0:83bfd3e3c4c4 3 #if defined(SX127x_H)
Wayne Roberts 0:83bfd3e3c4c4 4 #define BW_KHZ 125
Wayne Roberts 0:83bfd3e3c4c4 5 #define SPREADING_FACTOR 7
Wayne Roberts 0:83bfd3e3c4c4 6 #define CF_HZ 915000000
Wayne Roberts 0:83bfd3e3c4c4 7 #define TX_DBM 20
Wayne Roberts 0:83bfd3e3c4c4 8 #elif defined(SX126x_H)
lorgei 4:9696eee39801 9 #define BW_KHZ 500
lorgei 4:9696eee39801 10 #define SPREADING_FACTOR 8
Wayne Roberts 0:83bfd3e3c4c4 11 #define CF_HZ 915000000
lorgei 4:9696eee39801 12 //#define TX_DBM (Radio::chipType == CHIP_TYPE_SX1262 ? 20 : 14)
Wayne Roberts 0:83bfd3e3c4c4 13 #elif defined(SX128x_H)
Wayne Roberts 0:83bfd3e3c4c4 14 #define BW_KHZ 200
Wayne Roberts 0:83bfd3e3c4c4 15 #define SPREADING_FACTOR 7
Wayne Roberts 0:83bfd3e3c4c4 16 #define CF_HZ 2487000000
Wayne Roberts 0:83bfd3e3c4c4 17 #define TX_DBM 6
Wayne Roberts 0:83bfd3e3c4c4 18 #endif
Wayne Roberts 0:83bfd3e3c4c4 19
Wayne Roberts 0:83bfd3e3c4c4 20 /**********************************************************************/
Wayne Roberts 2:3f4dfcc3bab6 21 EventQueue queue(4 * EVENTS_EVENT_SIZE);
Wayne Roberts 2:3f4dfcc3bab6 22
Wayne Roberts 2:3f4dfcc3bab6 23 void tx_test()
Wayne Roberts 2:3f4dfcc3bab6 24 {
Wayne Roberts 2:3f4dfcc3bab6 25 uint8_t seq = 0;
Wayne Roberts 2:3f4dfcc3bab6 26
Wayne Roberts 2:3f4dfcc3bab6 27 Radio::radio.tx_buf[0] = seq++; /* set payload */
Wayne Roberts 2:3f4dfcc3bab6 28 Radio::Send(1, 0, 0, 0); /* begin transmission */
Wayne Roberts 2:3f4dfcc3bab6 29 printf("sent\r\n");
Wayne Roberts 2:3f4dfcc3bab6 30
Wayne Roberts 2:3f4dfcc3bab6 31 /* {
Wayne Roberts 2:3f4dfcc3bab6 32 mbed_stats_cpu_t stats;
Wayne Roberts 2:3f4dfcc3bab6 33 mbed_stats_cpu_get(&stats);
Wayne Roberts 2:3f4dfcc3bab6 34 printf("canDeep:%u ", sleep_manager_can_deep_sleep());
Wayne Roberts 2:3f4dfcc3bab6 35 printf("Uptime: %llu ", stats.uptime / 1000);
Wayne Roberts 2:3f4dfcc3bab6 36 printf("Sleep time: %llu ", stats.sleep_time / 1000);
Wayne Roberts 2:3f4dfcc3bab6 37 printf("Deep Sleep: %llu\r\n", stats.deep_sleep_time / 1000);
Wayne Roberts 2:3f4dfcc3bab6 38 }*/
Wayne Roberts 2:3f4dfcc3bab6 39 }
Wayne Roberts 0:83bfd3e3c4c4 40
Wayne Roberts 0:83bfd3e3c4c4 41 void txDoneCB()
Wayne Roberts 0:83bfd3e3c4c4 42 {
Wayne Roberts 2:3f4dfcc3bab6 43 printf("got-tx-done\r\n");
Wayne Roberts 2:3f4dfcc3bab6 44 queue.call_in(500, tx_test);
Wayne Roberts 0:83bfd3e3c4c4 45 }
Wayne Roberts 0:83bfd3e3c4c4 46
Wayne Roberts 0:83bfd3e3c4c4 47 void rxDoneCB(uint8_t size, float rssi, float snr)
Wayne Roberts 0:83bfd3e3c4c4 48 {
Wayne Roberts 0:83bfd3e3c4c4 49 }
Wayne Roberts 0:83bfd3e3c4c4 50
Wayne Roberts 2:3f4dfcc3bab6 51
Wayne Roberts 2:3f4dfcc3bab6 52 void radio_irq_callback()
Wayne Roberts 2:3f4dfcc3bab6 53 {
Wayne Roberts 2:3f4dfcc3bab6 54 queue.call(Radio::service);
Wayne Roberts 2:3f4dfcc3bab6 55 }
Wayne Roberts 2:3f4dfcc3bab6 56
Wayne Roberts 2:3f4dfcc3bab6 57
Wayne Roberts 0:83bfd3e3c4c4 58 const RadioEvents_t rev = {
Wayne Roberts 2:3f4dfcc3bab6 59 /* DioPin_top_half */ radio_irq_callback,
Wayne Roberts 0:83bfd3e3c4c4 60 /* TxDone_topHalf */ NULL,
Wayne Roberts 0:83bfd3e3c4c4 61 /* TxDone_botHalf */ txDoneCB,
Wayne Roberts 0:83bfd3e3c4c4 62 /* TxTimeout */ NULL,
Wayne Roberts 0:83bfd3e3c4c4 63 /* RxDone */ rxDoneCB,
Wayne Roberts 0:83bfd3e3c4c4 64 /* RxTimeout */ NULL,
Wayne Roberts 0:83bfd3e3c4c4 65 /* RxError */ NULL,
Wayne Roberts 0:83bfd3e3c4c4 66 /* FhssChangeChannel */NULL,
Wayne Roberts 0:83bfd3e3c4c4 67 /* CadDone */ NULL
Wayne Roberts 0:83bfd3e3c4c4 68 };
Wayne Roberts 0:83bfd3e3c4c4 69
Wayne Roberts 0:83bfd3e3c4c4 70 int main()
Wayne Roberts 0:83bfd3e3c4c4 71 {
Wayne Roberts 2:3f4dfcc3bab6 72 //uint8_t seq = 0;
Wayne Roberts 0:83bfd3e3c4c4 73
Wayne Roberts 0:83bfd3e3c4c4 74 printf("\r\nreset-tx ");
Wayne Roberts 0:83bfd3e3c4c4 75
Wayne Roberts 0:83bfd3e3c4c4 76 Radio::Init(&rev);
Wayne Roberts 0:83bfd3e3c4c4 77
Wayne Roberts 0:83bfd3e3c4c4 78 Radio::Standby();
Wayne Roberts 0:83bfd3e3c4c4 79 Radio::LoRaModemConfig(BW_KHZ, SPREADING_FACTOR, 1);
Wayne Roberts 0:83bfd3e3c4c4 80 Radio::SetChannel(CF_HZ);
Wayne Roberts 0:83bfd3e3c4c4 81
lorgei 4:9696eee39801 82 Radio::set_tx_dbm(20);
Wayne Roberts 0:83bfd3e3c4c4 83
Wayne Roberts 0:83bfd3e3c4c4 84 // preambleLen, fixLen, crcOn, invIQ
Wayne Roberts 0:83bfd3e3c4c4 85 Radio::LoRaPacketConfig(8, false, true, false);
Wayne Roberts 0:83bfd3e3c4c4 86
Wayne Roberts 2:3f4dfcc3bab6 87 queue.call_in(500, tx_test);
Wayne Roberts 0:83bfd3e3c4c4 88
Wayne Roberts 2:3f4dfcc3bab6 89 queue.dispatch();
Wayne Roberts 0:83bfd3e3c4c4 90 }
Wayne Roberts 0:83bfd3e3c4c4 91