Hartmut J / Mbed 2 deprecated STM32F103C8T6_LoRaWAN-lmic-app

Dependencies:   LMiC_CFG_eu868 SX1276Lib mbed-STM32F103C8T6 mbed

Fork of LoRaWAN-lmic-app by Semtech

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers debug.cpp Source File

debug.cpp

00001 /*******************************************************************************
00002  * Copyright (c) 2014-2015 IBM Corporation.
00003  * All rights reserved. This program and the accompanying materials
00004  * are made available under the terms of the Eclipse Public License v1.0
00005  * which accompanies this distribution, and is available at
00006  * http://www.eclipse.org/legal/epl-v10.html
00007  *
00008  * Contributors:
00009  *    IBM Zurich Research Lab - initial API, implementation and documentation
00010  *    Semtech Apps Team       - Adapted for MBED
00011  *******************************************************************************/
00012 #include <stdio.h>
00013 #include "mbed.h"
00014 #include "stm32f103c8t6.h"
00015 #include "lmic.h"
00016 #include "debug.h"
00017 
00018 Serial      pc(PA_2, PA_3);
00019 
00020 void debug_init () {
00021     pc.baud(57600);
00022     // print banner
00023     debug_str("\r\n============== DEBUG STARTED ==============\r\n");
00024 }
00025 
00026 void debug_led (u1_t val) {
00027     debug_val( "LED = ", val );
00028 }
00029 
00030 void debug_char (u1_t c) {
00031     pc.printf("%c", c);
00032 }
00033 
00034 void debug_hex (u1_t b) {
00035     pc.printf("%02X", b );
00036 }
00037 
00038 void debug_buf (const u1_t* buf, u2_t len) {
00039     while( len-- ) {
00040         debug_hex( *buf++ );
00041         debug_char( ' ' );
00042     }
00043     debug_char( '\r' );
00044     debug_char( '\n' );
00045 }
00046 
00047 void debug_uint (u4_t v) {
00048     for( s1_t n = 24; n >= 0; n -= 8 ) {
00049         debug_hex( v >> n );
00050     }
00051 }
00052 
00053 void debug_str (const u1_t* str) {
00054     while( *str ) {
00055         debug_char( *str++ );
00056     }
00057 }
00058 
00059 void debug_val (const u1_t* label, u4_t val) {
00060     debug_str( label );
00061     debug_uint( val );
00062     debug_char( '\r' );
00063     debug_char( '\n' );
00064 }
00065 
00066 void debug_event (int ev) {
00067     static const u1_t* evnames[] = {
00068         [EV_SCAN_TIMEOUT]   = "SCAN_TIMEOUT",
00069         [EV_BEACON_FOUND]   = "BEACON_FOUND",
00070         [EV_BEACON_MISSED]  = "BEACON_MISSED",
00071         [EV_BEACON_TRACKED] = "BEACON_TRACKED",
00072         [EV_JOINING]        = "JOINING",
00073         [EV_JOINED]         = "JOINED",
00074         [EV_RFU1]           = "RFU1",
00075         [EV_JOIN_FAILED]    = "JOIN_FAILED",
00076         [EV_REJOIN_FAILED]  = "REJOIN_FAILED",
00077         [EV_TXCOMPLETE]     = "TXCOMPLETE",
00078         [EV_LOST_TSYNC]     = "LOST_TSYNC",
00079         [EV_RESET]          = "RESET",
00080         [EV_RXCOMPLETE]     = "RXCOMPLETE",
00081         [EV_LINK_DEAD]      = "LINK_DEAD",
00082         [EV_LINK_ALIVE]     = "LINK_ALIVE",
00083     };
00084     debug_str(evnames[ev]);
00085     debug_char('\r');
00086     debug_char('\n');
00087 }