![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
first draft
Dependencies: LMiC SX1272Libx mbed
Fork of LoRaWAN-lmic-app by
Diff: hal.cpp
- Revision:
- 6:fc465060b63e
- Parent:
- 1:60184eda0066
diff -r 1b2fcc2582e8 -r fc465060b63e hal.cpp --- a/hal.cpp Thu Nov 26 17:20:53 2015 +0000 +++ b/hal.cpp Tue Feb 23 15:42:41 2016 +0000 @@ -16,21 +16,21 @@ *******************************************************************************/ #include "mbed.h" #include "lmic.h" -#include "mbed_debug.h" +#include "debug.h" #if !USE_SMTC_RADIO_DRIVER extern void radio_irq_handler( u1_t dio ); -static DigitalOut nss( D10 ); -static SPI spi( D11, D12, D13 ); // ( mosi, miso, sclk ) +static DigitalOut nss( PTD4 ); +static SPI spi( PTD6, PTD7, PTD5 ); // ( mosi, miso, sclk ) static DigitalInOut rst( A0 ); -static DigitalOut rxtx( A4 ); +static DigitalOut rxtx( PTC6 ); -static InterruptIn dio0( D2 ); -static InterruptIn dio1( D3 ); -static InterruptIn dio2( D4 ); +static InterruptIn dio0( PTC2 ); +static InterruptIn dio1( PTC4 ); +static InterruptIn dio2( PTC3 ); static void dio0Irq( void ) { radio_irq_handler( 0 ); @@ -52,12 +52,16 @@ static Timer timer; static Ticker ticker; -static void reset_timer( void ) { +static void reset_timer( void ) +{ + debug("reset_timer enter\r\n"); ticks += timer.read_us( ) >> 6; timer.reset( ); } -void hal_init( void ) { +void hal_init( void ) +{ + debug("hal_init enter\r\n"); __disable_irq( ); irqlevel = 0; @@ -75,7 +79,8 @@ // configure reset line rst.input( ); // configure spi - spi.frequency( 8000000 ); + // spi.frequency( 8000000 ); + spi.frequency( 1000000 ); spi.format( 8, 0 ); nss = 1; #endif @@ -83,19 +88,26 @@ timer.start( ); ticker.attach_us( reset_timer, 10000000 ); // reset timer every 10sec __enable_irq( ); + debug("hal_init exit\r\n"); } #if !USE_SMTC_RADIO_DRIVER -void hal_pin_rxtx( u1_t val ) { +void hal_pin_rxtx( u1_t val ) +{ + debug("hal_pin_rxtx enter %d\r\n",val); rxtx = !val; } -void hal_pin_nss( u1_t val ) { +void hal_pin_nss( u1_t val ) +{ + debug("hal_pin_nss enter %d\r\n",val); nss = val; } -void hal_pin_rst( u1_t val ) { +void hal_pin_rst( u1_t val ) +{ +debug("hal_pin_rst enter %d\r\n",val); if( val == 0 || val == 1 ) { // drive pin rst.output( ); @@ -107,36 +119,48 @@ } } -u1_t hal_spi( u1_t out ) { - return spi.write( out ); +u1_t hal_spi( u1_t out ) +{ + debug("hal_spi enter\r\n"); + return spi.write( out ); } #endif -void hal_disableIRQs( void ) { - __disable_irq( ); +void hal_disableIRQs( void ) +{ + //debug("hal_disableIRQs enter\r\n"); + __disable_irq( ); irqlevel++; } -void hal_enableIRQs( void ) { +void hal_enableIRQs( void ) +{ +//debug("hal_enableIRQs enter\r\n"); if( --irqlevel == 0 ) { __enable_irq( ); } } -void hal_sleep( void ) { +void hal_sleep( void ) +{ +//debug("hal_sleep enter\r\n"); // NOP } -u4_t hal_ticks( void ) { +u4_t hal_ticks( void ) +{ hal_disableIRQs( ); int t = ticks + ( timer.read_us( ) >> 6 ); hal_enableIRQs( ); +//debug("hal_ticks exit %d\r\n",t); return t; } -static u2_t deltaticks( u4_t time ) { +static u2_t deltaticks( u4_t time ) +{ +// debug("deltaticks enter\r\n"); u4_t t = hal_ticks( ); s4_t d = time - t; if( d <= 0 ) { @@ -148,14 +172,20 @@ return ( u2_t )d; } -void hal_waitUntil( u4_t time ) { +void hal_waitUntil( u4_t time ) +{ + debug("hal_waitUntil enter\r\n"); while( deltaticks( time ) != 0 ); // busy wait until timestamp is reached } -u1_t hal_checkTimer( u4_t time ) { +u1_t hal_checkTimer( u4_t time ) +{ +// debug("hal_checkTimer enter\r\n"); return ( deltaticks( time ) < 2 ); } -void hal_failed( void ) { +void hal_failed( void ) +{ + debug("hal_failed enter\r\n"); while( 1 ); }