Skip to content

Commit c9804bd

Browse files
Hasnain Virktheotherjimmy
authored andcommitted
Adding base class for LoRaWAN interfaces
All network interfaces for LoRaWAN protocol must implement this class. In order to be compatible with Mbed-OS applications, any implementation of this class must use the data structures and Mbed-OS timers provided. lorawan_data_structures may look repetitive but this is essential as we have a plan to use a reference implementation for LoRaWAN mac layer from Semtech. Some of the data structures provide seemless transition from semtech implementation (as MAC layer) to the Mbed-OS control layers above. features/lorawan/lorastack is the placeholder for future items like mac and phy layers. system/ will contain all the common bits.
1 parent 69664c5 commit c9804bd

File tree

4 files changed

+3351
-0
lines changed

4 files changed

+3351
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/**
2+
/ _____) _ | |
3+
( (____ _____ ____ _| |_ _____ ____| |__
4+
\____ \| ___ | (_ _) ___ |/ ___) _ \
5+
_____) ) ____| | | || |_| ____( (___| | | |
6+
(______/|_____)_|_|_| \__)_____)\____)_| |_|
7+
(C)2013 Semtech
8+
9+
Description: Timer objects and scheduling management
10+
11+
License: Revised BSD License, see LICENSE.TXT file include in the project
12+
13+
Maintainer: Miguel Luis and Gregory Cristian
14+
15+
16+
Copyright (c) 2017, Arm Limited and affiliates.
17+
18+
SPDX-License-Identifier: BSD-3-Clause
19+
*/
20+
21+
#include "lorawan/system/LoRaWANTimer.h"
22+
23+
static mbed::Timer TimeCounter;
24+
static mbed::Ticker LoadTimeCounter;
25+
26+
volatile uint32_t CurrentTime = 0;
27+
28+
void TimerResetTimeCounter( void )
29+
{
30+
CurrentTime = CurrentTime + TimeCounter.read_us( ) / 1000;
31+
TimeCounter.reset( );
32+
TimeCounter.start( );
33+
}
34+
35+
void TimerTimeCounterInit( void )
36+
{
37+
TimeCounter.start( );
38+
LoadTimeCounter.attach( mbed::callback( &TimerResetTimeCounter ), 10 );
39+
}
40+
41+
TimerTime_t TimerGetCurrentTime( void )
42+
{
43+
CurrentTime += TimeCounter.read_us( ) / 1000;
44+
TimeCounter.reset( );
45+
TimeCounter.start( );
46+
return ( ( TimerTime_t )CurrentTime );
47+
}
48+
49+
TimerTime_t TimerGetElapsedTime( TimerTime_t savedTime )
50+
{
51+
CurrentTime += TimeCounter.read_us( ) / 1000;
52+
TimeCounter.reset( );
53+
TimeCounter.start( );
54+
return ( TimerTime_t )( CurrentTime - savedTime );
55+
}
56+
57+
TimerTime_t TimerGetFutureTime( TimerTime_t eventInFuture )
58+
{
59+
CurrentTime += TimeCounter.read_us( ) / 1000;
60+
TimeCounter.reset( );
61+
TimeCounter.start( );
62+
return ( TimerTime_t )( CurrentTime + eventInFuture );
63+
}
64+
65+
void TimerInit( TimerEvent_t *obj, void ( *callback )( void ) )
66+
{
67+
obj->value = 0;
68+
obj->Callback = callback;
69+
}
70+
71+
void TimerStart( TimerEvent_t *obj )
72+
{
73+
obj->Timer.attach_us( mbed::callback( obj->Callback ), obj->value * 1000 );
74+
}
75+
76+
void TimerStop( TimerEvent_t *obj )
77+
{
78+
obj->Timer.detach( );
79+
}
80+
81+
void TimerSetValue( TimerEvent_t *obj, uint32_t value )
82+
{
83+
obj->value = value;
84+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/**
2+
/ _____) _ | |
3+
( (____ _____ ____ _| |_ _____ ____| |__
4+
\____ \| ___ | (_ _) ___ |/ ___) _ \
5+
_____) ) ____| | | || |_| ____( (___| | | |
6+
(______/|_____)_|_|_| \__)_____)\____)_| |_|
7+
(C)2013 Semtech
8+
9+
Description: Timer objects and scheduling management
10+
11+
License: Revised BSD License, see LICENSE.TXT file include in the project
12+
13+
Maintainer: Miguel Luis and Gregory Cristian
14+
15+
16+
Copyright (c) 2017, Arm Limited and affiliates.
17+
18+
SPDX-License-Identifier: BSD-3-Clause
19+
*/
20+
21+
#ifndef MBED_LORAWAN_SYS_TIMER_H__
22+
#define MBED_LORAWAN_SYS_TIMER_H__
23+
#include "drivers/Timer.h"
24+
#include "drivers/Ticker.h"
25+
#include "lorawan/system/lorawan_data_structures.h"
26+
27+
/*!
28+
* \brief Timer object description
29+
*/
30+
typedef struct TimerEvent_s
31+
{
32+
uint32_t value;
33+
void ( *Callback )( void );
34+
mbed::Ticker Timer;
35+
}TimerEvent_t;
36+
37+
/*!
38+
* \brief Initializes the timer used to get the current time.
39+
*
40+
* \remark The current time corresponds to the time since system startup.
41+
*/
42+
void TimerTimeCounterInit( void );
43+
44+
/*!
45+
* \brief Initializes the timer object.
46+
*
47+
* \remark The TimerSetValue function must be called before starting the timer.
48+
* This function initializes the timestamp and reloads the value at 0.
49+
*
50+
* \param [in] obj The structure containing the timer object parameters.
51+
* \param [in] callback The function callback called at the end of the timeout.
52+
*/
53+
void TimerInit( TimerEvent_t *obj, void ( *callback )( void ) );
54+
55+
/*!
56+
* \brief Starts and adds the timer object to the list of timer events.
57+
*
58+
* \param [in] obj The structure containing the timer object parameters.
59+
*/
60+
void TimerStart( TimerEvent_t *obj );
61+
62+
/*!
63+
* \brief Stops and removes the timer object from the list of timer events.
64+
*
65+
* \param [in] obj The structure containing the timer object parameters.
66+
*/
67+
void TimerStop( TimerEvent_t *obj );
68+
69+
/*!
70+
* \brief Resets the timer object.
71+
*
72+
* \param [in] obj The structure containing the timer object parameters.
73+
*/
74+
void TimerReset( TimerEvent_t *obj );
75+
76+
/*!
77+
* \brief Set a new timeout value.
78+
*
79+
* \param [in] obj The structure containing the timer object parameters.
80+
* \param [in] value The new timeout value.
81+
*/
82+
void TimerSetValue( TimerEvent_t *obj, uint32_t value );
83+
84+
/*!
85+
* \brief Read the current time.
86+
*
87+
* \retval time The current time.
88+
*/
89+
TimerTime_t TimerGetCurrentTime( void );
90+
91+
/*!
92+
* \brief Return the time elapsed since a fixed moment in time.
93+
*
94+
* \param [in] savedTime The fixed moment in time.
95+
* \retval time The elapsed time.
96+
*/
97+
TimerTime_t TimerGetElapsedTime( TimerTime_t savedTime );
98+
99+
/*!
100+
* \brief Return the time elapsed since a fixed moment in time.
101+
*
102+
* \param [in] eventInFuture The fixed moment in the future.
103+
* \retval time The difference between now and a future event.
104+
*/
105+
TimerTime_t TimerGetFutureTime( TimerTime_t eventInFuture );
106+
107+
#endif // MBED_LORAWAN_SYS_TIMER_H__

0 commit comments

Comments
 (0)