Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
hal.cpp
00001 #include "mbed.h" 00002 #include "lmic.h" 00003 #include "mbed_debug.h" 00004 00005 static u1_t irqlevel = 0; 00006 static u4_t ticks = 0; 00007 00008 static Timer timer; 00009 static Ticker ticker; 00010 00011 static void reset_timer( void ) { 00012 ticks += timer.read_us( ) >> 6; 00013 timer.reset( ); 00014 } 00015 00016 void hal_init( void ) { 00017 __disable_irq( ); 00018 irqlevel = 0; 00019 00020 // configure timer 00021 timer.start( ); 00022 ticker.attach_us( reset_timer, 10000000 ); // reset timer every 10sec 00023 __enable_irq( ); 00024 } 00025 00026 void hal_disableIRQs( void ) { 00027 __disable_irq( ); 00028 irqlevel++; 00029 } 00030 00031 void hal_enableIRQs( void ) { 00032 if( --irqlevel == 0 ) 00033 { 00034 __enable_irq( ); 00035 } 00036 } 00037 00038 void hal_sleep( void ) { 00039 // NOP 00040 } 00041 00042 u4_t hal_ticks( void ) { 00043 hal_disableIRQs( ); 00044 int t = ticks + ( timer.read_us( ) >> 6 ); 00045 hal_enableIRQs( ); 00046 return t; 00047 } 00048 00049 static u2_t deltaticks( u4_t time ) { 00050 u4_t t = hal_ticks( ); 00051 s4_t d = time - t; 00052 if( d <= 0 ) { 00053 return 0; // in the past 00054 } 00055 if( ( d >> 16 ) != 0 ) { 00056 return 0xFFFF; // far ahead 00057 } 00058 return ( u2_t )d; 00059 } 00060 00061 void hal_waitUntil( u4_t time ) { 00062 while( deltaticks( time ) != 0 ); // busy wait until timestamp is reached 00063 } 00064 00065 u1_t hal_checkTimer( u4_t time ) { 00066 return ( deltaticks( time ) < 2 ); 00067 } 00068 00069 void hal_failed( void ) { 00070 while( 1 ); 00071 }
Generated on Thu Jul 14 2022 01:22:40 by
1.7.2