wayne roberts / lorawan1v1

Dependencies:   sx12xx_hal

Dependents:   LoRaWAN-SanJose_Bootcamp LoRaWAN-grove-cayenne LoRaWAN-classC-demo LoRaWAN-grove-cayenne ... more

Committer:
Wayne Roberts
Date:
Mon Mar 19 14:39:06 2018 -0700
Revision:
4:e4bfe9183f94
Parent:
0:6b3ac9c5a042
move mutex locks from ISR to user context

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Wayne Roberts 0:6b3ac9c5a042 1 /* Only for NUCLEO boards: prevent compiling for MOTE_L152RC and typeABZ discovery */
Wayne Roberts 0:6b3ac9c5a042 2 #if defined(TARGET_FF_ARDUINO) && defined(TARGET_FF_MORPHO) && !defined(TARGET_DISCO_L072CZ_LRWAN1)
Wayne Roberts 0:6b3ac9c5a042 3 #include "board.h"
Wayne Roberts 0:6b3ac9c5a042 4 #include "radio.h"
Wayne Roberts 4:e4bfe9183f94 5 #include "SPIu.h"
Wayne Roberts 0:6b3ac9c5a042 6
Wayne Roberts 4:e4bfe9183f94 7 SPIu spi(D11, D12, D13); // mosi, miso, sclk
Wayne Roberts 0:6b3ac9c5a042 8 // dio0, dio1, nss, spi, rst
Wayne Roberts 0:6b3ac9c5a042 9 SX127x Radio::radio( D2, D3, D10, spi, A0); // sx127[62] arduino shield
Wayne Roberts 0:6b3ac9c5a042 10 SX127x_lora Radio::lora(radio);
Wayne Roberts 0:6b3ac9c5a042 11 SX127x_fsk Radio::fsk(radio);
Wayne Roberts 0:6b3ac9c5a042 12
Wayne Roberts 0:6b3ac9c5a042 13 InterruptIn Radio::dio0(D2);
Wayne Roberts 0:6b3ac9c5a042 14 InterruptIn Radio::dio1(D3);
Wayne Roberts 0:6b3ac9c5a042 15
Wayne Roberts 0:6b3ac9c5a042 16 typedef enum {
Wayne Roberts 0:6b3ac9c5a042 17 SHIELD_TYPE_NONE = 0,
Wayne Roberts 0:6b3ac9c5a042 18 SHIELD_TYPE_LAS,
Wayne Roberts 0:6b3ac9c5a042 19 SHIELD_TYPE_MAS,
Wayne Roberts 0:6b3ac9c5a042 20 } shield_type_e;
Wayne Roberts 0:6b3ac9c5a042 21 shield_type_e shield_type;
Wayne Roberts 0:6b3ac9c5a042 22
Wayne Roberts 0:6b3ac9c5a042 23 DigitalOut pc3(PC_3);
Wayne Roberts 0:6b3ac9c5a042 24 DigitalInOut rfsw(A4);
Wayne Roberts 0:6b3ac9c5a042 25 void Radio::rfsw_callback()
Wayne Roberts 0:6b3ac9c5a042 26 {
Wayne Roberts 0:6b3ac9c5a042 27 if (radio.RegOpMode.bits.Mode == RF_OPMODE_TRANSMITTER)
Wayne Roberts 0:6b3ac9c5a042 28 rfsw = 1;
Wayne Roberts 0:6b3ac9c5a042 29 else
Wayne Roberts 0:6b3ac9c5a042 30 rfsw = 0;
Wayne Roberts 0:6b3ac9c5a042 31
Wayne Roberts 0:6b3ac9c5a042 32 if (radio.RegOpMode.bits.Mode == RF_OPMODE_RECEIVER || radio.RegOpMode.bits.Mode == RF_OPMODE_RECEIVER_SINGLE)
Wayne Roberts 0:6b3ac9c5a042 33 pc3 = 1;
Wayne Roberts 0:6b3ac9c5a042 34 else
Wayne Roberts 0:6b3ac9c5a042 35 pc3 = 0;
Wayne Roberts 0:6b3ac9c5a042 36 }
Wayne Roberts 0:6b3ac9c5a042 37
Wayne Roberts 0:6b3ac9c5a042 38 void
Wayne Roberts 0:6b3ac9c5a042 39 Radio::set_tx_dbm(int8_t dbm)
Wayne Roberts 0:6b3ac9c5a042 40 {
Wayne Roberts 0:6b3ac9c5a042 41 RegPdsTrim1_t pds_trim;
Wayne Roberts 0:6b3ac9c5a042 42 uint8_t adr;
Wayne Roberts 0:6b3ac9c5a042 43 if (radio.type == SX1276)
Wayne Roberts 0:6b3ac9c5a042 44 adr = REG_PDSTRIM1_SX1276;
Wayne Roberts 0:6b3ac9c5a042 45 else
Wayne Roberts 0:6b3ac9c5a042 46 adr = REG_PDSTRIM1_SX1272;
Wayne Roberts 0:6b3ac9c5a042 47
Wayne Roberts 0:6b3ac9c5a042 48 pds_trim.octet = radio.read_reg(adr);
Wayne Roberts 0:6b3ac9c5a042 49
Wayne Roberts 0:6b3ac9c5a042 50 if (shield_type == SHIELD_TYPE_LAS)
Wayne Roberts 0:6b3ac9c5a042 51 radio.RegPaConfig.bits.PaSelect = 1;
Wayne Roberts 0:6b3ac9c5a042 52 else
Wayne Roberts 0:6b3ac9c5a042 53 radio.RegPaConfig.bits.PaSelect = 0;
Wayne Roberts 0:6b3ac9c5a042 54
Wayne Roberts 0:6b3ac9c5a042 55 if (radio.RegPaConfig.bits.PaSelect) {
Wayne Roberts 0:6b3ac9c5a042 56 /* PABOOST used: +2dbm to +17, or +20 */
Wayne Roberts 0:6b3ac9c5a042 57 if (dbm > 17) {
Wayne Roberts 0:6b3ac9c5a042 58 MAC_PRINTF("+20dBm PADAC bias\r\n");
Wayne Roberts 0:6b3ac9c5a042 59 if (dbm > 20)
Wayne Roberts 0:6b3ac9c5a042 60 dbm = 20;
Wayne Roberts 0:6b3ac9c5a042 61 dbm -= 3;
Wayne Roberts 0:6b3ac9c5a042 62 pds_trim.bits.prog_txdac = 7;
Wayne Roberts 0:6b3ac9c5a042 63 radio.write_reg(adr, pds_trim.octet);
Wayne Roberts 0:6b3ac9c5a042 64 ocp(150);
Wayne Roberts 0:6b3ac9c5a042 65 } else
Wayne Roberts 0:6b3ac9c5a042 66 ocp(120);
Wayne Roberts 0:6b3ac9c5a042 67
Wayne Roberts 0:6b3ac9c5a042 68 if (dbm > 1)
Wayne Roberts 0:6b3ac9c5a042 69 radio.RegPaConfig.bits.OutputPower = dbm - 2;
Wayne Roberts 0:6b3ac9c5a042 70 } else {
Wayne Roberts 0:6b3ac9c5a042 71 /* RFO used: -1 to +14dbm */
Wayne Roberts 0:6b3ac9c5a042 72 ocp(80);
Wayne Roberts 0:6b3ac9c5a042 73 if (dbm < 15)
Wayne Roberts 0:6b3ac9c5a042 74 radio.RegPaConfig.bits.OutputPower = dbm + 1;
Wayne Roberts 0:6b3ac9c5a042 75 }
Wayne Roberts 0:6b3ac9c5a042 76 radio.write_reg(REG_PACONFIG, radio.RegPaConfig.octet);
Wayne Roberts 0:6b3ac9c5a042 77
Wayne Roberts 0:6b3ac9c5a042 78 radio.RegPaConfig.octet = radio.read_reg(REG_PACONFIG);
Wayne Roberts 0:6b3ac9c5a042 79 if (radio.RegPaConfig.bits.PaSelect) {
Wayne Roberts 0:6b3ac9c5a042 80 MAC_PRINTF("PA_BOOST ");
Wayne Roberts 0:6b3ac9c5a042 81 dbm = radio.RegPaConfig.bits.OutputPower + pds_trim.bits.prog_txdac - 2;
Wayne Roberts 0:6b3ac9c5a042 82 } else {
Wayne Roberts 0:6b3ac9c5a042 83 MAC_PRINTF("RFO ");
Wayne Roberts 0:6b3ac9c5a042 84 dbm = radio.RegPaConfig.bits.OutputPower - 1;
Wayne Roberts 0:6b3ac9c5a042 85 }
Wayne Roberts 0:6b3ac9c5a042 86 MAC_PRINTF("OutputPower:%ddBm{%02x}\r\n", dbm, radio.RegPaConfig.octet);
Wayne Roberts 0:6b3ac9c5a042 87 }
Wayne Roberts 0:6b3ac9c5a042 88
Wayne Roberts 0:6b3ac9c5a042 89 void Radio::boardInit()
Wayne Roberts 0:6b3ac9c5a042 90 {
Wayne Roberts 0:6b3ac9c5a042 91 rfsw.input();
Wayne Roberts 0:6b3ac9c5a042 92 if (rfsw.read()) {
Wayne Roberts 0:6b3ac9c5a042 93 shield_type = SHIELD_TYPE_LAS;
Wayne Roberts 0:6b3ac9c5a042 94 MAC_PRINTF("LAS\r\n");
Wayne Roberts 0:6b3ac9c5a042 95 } else {
Wayne Roberts 0:6b3ac9c5a042 96 shield_type = SHIELD_TYPE_MAS;
Wayne Roberts 0:6b3ac9c5a042 97 MAC_PRINTF("MAS\r\n");
Wayne Roberts 0:6b3ac9c5a042 98 }
Wayne Roberts 0:6b3ac9c5a042 99
Wayne Roberts 0:6b3ac9c5a042 100 rfsw.output();
Wayne Roberts 0:6b3ac9c5a042 101 }
Wayne Roberts 0:6b3ac9c5a042 102
Wayne Roberts 0:6b3ac9c5a042 103 #endif /* ...sx127x shield */
Wayne Roberts 0:6b3ac9c5a042 104