Senet-ized LMIC for MOTE_L152RC

Fork of lmic_MOTE_L152RC by Semtech

Committer:
dudmuck
Date:
Mon Nov 16 23:52:45 2015 +0000
Revision:
9:83ae7f34e88c
Parent:
0:f2716e543d97
Child:
12:be4139e16c6f
correct join behavior after link dead (joining again)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dudmuck 0:f2716e543d97 1 //#include "oslmic.h"
dudmuck 0:f2716e543d97 2 #include "lmic.h"
dudmuck 0:f2716e543d97 3 #include "debug.h"
dudmuck 0:f2716e543d97 4 #include "mbed.h"
dudmuck 0:f2716e543d97 5
dudmuck 0:f2716e543d97 6 Serial pc(USBTX, USBRX);
dudmuck 0:f2716e543d97 7
dudmuck 0:f2716e543d97 8 static DigitalOut red_led(PB_1);
dudmuck 0:f2716e543d97 9 #define LED_ON 0
dudmuck 0:f2716e543d97 10 #define LED_OFF 1
dudmuck 0:f2716e543d97 11
dudmuck 0:f2716e543d97 12 void debug_init()
dudmuck 0:f2716e543d97 13 {
dudmuck 0:f2716e543d97 14 pc.baud(115200);
dudmuck 0:f2716e543d97 15
dudmuck 0:f2716e543d97 16 // print banner
dudmuck 0:f2716e543d97 17 debug_str("\r\n============== DEBUG STARTED ==============\r\n");
dudmuck 0:f2716e543d97 18
dudmuck 0:f2716e543d97 19 red_led = LED_OFF;
dudmuck 0:f2716e543d97 20 }
dudmuck 0:f2716e543d97 21
dudmuck 0:f2716e543d97 22 void debug_str (const char* str)
dudmuck 0:f2716e543d97 23 {
dudmuck 0:f2716e543d97 24 debug("%s", str);
dudmuck 0:f2716e543d97 25 }
dudmuck 0:f2716e543d97 26
dudmuck 0:f2716e543d97 27 void debug_event (int ev)
dudmuck 0:f2716e543d97 28 {
dudmuck 0:f2716e543d97 29 static const u1_t* evnames[] = {
dudmuck 0:f2716e543d97 30 [EV_SCAN_TIMEOUT] = "SCAN_TIMEOUT",
dudmuck 0:f2716e543d97 31 [EV_BEACON_FOUND] = "BEACON_FOUND",
dudmuck 0:f2716e543d97 32 [EV_BEACON_MISSED] = "BEACON_MISSED",
dudmuck 0:f2716e543d97 33 [EV_BEACON_TRACKED] = "BEACON_TRACKED",
dudmuck 0:f2716e543d97 34 [EV_JOINING] = "JOINING",
dudmuck 0:f2716e543d97 35 [EV_JOINED] = "JOINED",
dudmuck 0:f2716e543d97 36 [EV_RFU1] = "RFU1",
dudmuck 0:f2716e543d97 37 [EV_JOIN_FAILED] = "JOIN_FAILED",
dudmuck 0:f2716e543d97 38 [EV_REJOIN_FAILED] = "REJOIN_FAILED",
dudmuck 0:f2716e543d97 39 [EV_TXCOMPLETE] = "TXCOMPLETE",
dudmuck 0:f2716e543d97 40 [EV_LOST_TSYNC] = "LOST_TSYNC",
dudmuck 0:f2716e543d97 41 [EV_RESET] = "RESET",
dudmuck 0:f2716e543d97 42 [EV_RXCOMPLETE] = "RXCOMPLETE",
dudmuck 0:f2716e543d97 43 [EV_LINK_DEAD] = "LINK_DEAD",
dudmuck 0:f2716e543d97 44 [EV_LINK_ALIVE] = "LINK_ALIVE",
dudmuck 0:f2716e543d97 45 };
dudmuck 0:f2716e543d97 46
dudmuck 0:f2716e543d97 47 debug("%s\r\n", evnames[ev]);
dudmuck 0:f2716e543d97 48 }
dudmuck 0:f2716e543d97 49
dudmuck 0:f2716e543d97 50 void debug_val (const char* label, u4_t val)
dudmuck 0:f2716e543d97 51 {
dudmuck 0:f2716e543d97 52 debug("%s%d\r\n", label, val);
dudmuck 0:f2716e543d97 53 }
dudmuck 0:f2716e543d97 54
dudmuck 0:f2716e543d97 55 void debug_buf(const u1_t* buf, u2_t len)
dudmuck 0:f2716e543d97 56 {
dudmuck 0:f2716e543d97 57 while (len--) {
dudmuck 0:f2716e543d97 58 debug("%02x ", *buf++);
dudmuck 0:f2716e543d97 59 }
dudmuck 0:f2716e543d97 60 debug("\r\n");
dudmuck 0:f2716e543d97 61 }
dudmuck 0:f2716e543d97 62
dudmuck 0:f2716e543d97 63 void debug_led(unsigned char on)
dudmuck 0:f2716e543d97 64 {
dudmuck 0:f2716e543d97 65 if (on)
dudmuck 0:f2716e543d97 66 red_led = LED_ON;
dudmuck 0:f2716e543d97 67 else
dudmuck 0:f2716e543d97 68 red_led = LED_OFF;
dudmuck 0:f2716e543d97 69 }
dudmuck 0:f2716e543d97 70
dudmuck 0:f2716e543d97 71 void debug_done()
dudmuck 0:f2716e543d97 72 {
dudmuck 9:83ae7f34e88c 73 volatile int i;
dudmuck 9:83ae7f34e88c 74
dudmuck 0:f2716e543d97 75 /* block until last bit sent out debug UART */
dudmuck 0:f2716e543d97 76 while (!(USART2->SR & UART_FLAG_TC))
dudmuck 0:f2716e543d97 77 __NOP();
dudmuck 9:83ae7f34e88c 78
dudmuck 9:83ae7f34e88c 79 for (i = 0; i < 0x200; i++)
dudmuck 9:83ae7f34e88c 80 __nop();
dudmuck 0:f2716e543d97 81 }