hello world

Fork of lmic_MOTE_L152RC by Semtech

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers debug.cpp Source File

debug.cpp

00001 //#include "oslmic.h"
00002 #include "lmic.h"
00003 #include "debug.h"
00004 #include "mbed.h"
00005 
00006 Serial pc(PTE0, PTE1);
00007 
00008 static DigitalOut red_led(PTA1);
00009 #define LED_ON  0
00010 #define LED_OFF 1
00011 
00012 void debug_init()
00013 {
00014     pc.baud(115200);
00015 
00016     // print banner
00017     debug_str("\r\n============== DEBUG STARTED ==============\r\n");
00018 
00019     red_led = LED_OFF;
00020 }
00021 
00022 void debug_str (const char* str)
00023 {
00024     debug("%s", str);
00025 }
00026 
00027 void debug_event (int ev)
00028 {
00029     static const u1_t* evnames[] = {
00030         [EV_SCAN_TIMEOUT]   = "SCAN_TIMEOUT",
00031         [EV_BEACON_FOUND]   = "BEACON_FOUND",
00032         [EV_BEACON_MISSED]  = "BEACON_MISSED",
00033         [EV_BEACON_TRACKED] = "BEACON_TRACKED",
00034         [EV_JOINING]        = "JOINING",
00035         [EV_JOINED]         = "JOINED",
00036         [EV_RFU1]           = "RFU1",
00037         [EV_JOIN_FAILED]    = "JOIN_FAILED",
00038         [EV_REJOIN_FAILED]  = "REJOIN_FAILED",
00039         [EV_TXCOMPLETE]     = "TXCOMPLETE",
00040         [EV_LOST_TSYNC]     = "LOST_TSYNC",
00041         [EV_RESET]          = "RESET",
00042         [EV_RXCOMPLETE]     = "RXCOMPLETE",
00043         [EV_LINK_DEAD]      = "LINK_DEAD",
00044         [EV_LINK_ALIVE]     = "LINK_ALIVE",
00045     };
00046 
00047     debug("%s\r\n", evnames[ev]);
00048 }
00049 
00050 void debug_val (const char* label, u4_t val)
00051 {
00052     debug("%s%d\r\n", label, val);
00053 }
00054 
00055 void debug_buf(const u1_t* buf, u2_t len)
00056 {
00057     while (len--) {
00058         debug("%02x ", *buf++);
00059     }
00060     debug("\r\n");
00061 }
00062 
00063 void debug_led(unsigned char on)
00064 {
00065     if (on)
00066         red_led = LED_ON;
00067     else
00068         red_led = LED_OFF;
00069 }
00070 
00071 void debug_done()
00072 {
00073     /* block until last bit sent out debug UART */
00074 //    while (!(USART2->SR & UART_FLAG_TC))
00075 //        __NOP();
00076 }