Skip to content

Commit

Permalink
Release v4.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
lbm-team committed Mar 18, 2024
1 parent ffca226 commit 5b1839e
Show file tree
Hide file tree
Showing 40 changed files with 512 additions and 544 deletions.
318 changes: 169 additions & 149 deletions CHANGELOG.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,6 @@ uint32_t hal_rtc_get_time_s( void )
return rtc_get_calendar_time( &milliseconds );
}

uint32_t hal_rtc_get_time_100us( void )
{
uint32_t seconds = 0;
uint16_t milliseconds_div_10 = 0;

seconds = rtc_get_calendar_time( &milliseconds_div_10 );

return seconds * 10000 + milliseconds_div_10;
}
uint32_t hal_rtc_get_time_ms( void )
{
uint32_t seconds = 0;
Expand Down
148 changes: 69 additions & 79 deletions lbm_applications/1_thread_x_on_stm32_u5/smtc_hal_u5/smtc_hal_rtc.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,91 +35,81 @@
#define __RTC_UTILITIES_H__

#ifdef __cplusplus
extern "C" {
extern "C"
{
#endif
/*
* -----------------------------------------------------------------------------
* --- DEPENDENCIES ------------------------------------------------------------
*/

#include <stdint.h> // C99 types
#include <stdbool.h> // bool type
/*
* -----------------------------------------------------------------------------
* --- PUBLIC MACROS -----------------------------------------------------------
*/

/*
* -----------------------------------------------------------------------------
* --- PUBLIC CONSTANTS --------------------------------------------------------
*/

/*
* -----------------------------------------------------------------------------
* --- PUBLIC TYPES ------------------------------------------------------------
*/

/*
* -----------------------------------------------------------------------------
* --- PUBLIC FUNCTIONS PROTOTYPES ---------------------------------------------
*/

/*!
* Initializes the MCU RTC peripheral
*/
void hal_rtc_init( void );

/*!
* Returns the current RTC time in seconds
*
* \remark Used for scheduling autonomous retransmissions (i.e: NbTrans),
* transmitting MAC answers, basically any delay without accurate time
* constraints. It is also used to measure the time spent inside the
* LoRaWAN process for the integrated failsafe.
*
* retval rtc_time_s Current RTC time in seconds
*/
uint32_t hal_rtc_get_time_s( void );

/*!
* Returns the current RTC time in milliseconds
*
* \remark Used to timestamp radio events (i.e: end of TX), will also be used
* for ClassB
*
* retval rtc_time_ms Current RTC time in milliseconds wraps every 49 days
*/
uint32_t hal_rtc_get_time_ms( void );


/*!
* Returns the current RTC time in 0.1milliseconds
*
* \remark will also be used for d2d
*
*
* retval rtc_time_ms Current RTC time in milliseconds wraps every 4.9 days
*/
uint32_t hal_rtc_get_time_100us( void );

/*!
* Sets the rtc wakeup timer for milliseconds parameter. The RTC will generate
* an IRQ to wakeup the MCU.
*
* \param[IN] milliseconds Number of seconds before wakeup
*/
void hal_rtc_wakeup_timer_set_ms( const int32_t milliseconds );

/*!
* Stop the rtc wakeup timer
*/
void hal_rtc_wakeup_timer_stop( void );
/*
* -----------------------------------------------------------------------------
* --- DEPENDENCIES ------------------------------------------------------------
*/

#include <stdint.h> // C99 types
#include <stdbool.h> // bool type
/*
* -----------------------------------------------------------------------------
* --- PUBLIC MACROS -----------------------------------------------------------
*/

/*
* -----------------------------------------------------------------------------
* --- PUBLIC CONSTANTS --------------------------------------------------------
*/

/*
* -----------------------------------------------------------------------------
* --- PUBLIC TYPES ------------------------------------------------------------
*/

/*
* -----------------------------------------------------------------------------
* --- PUBLIC FUNCTIONS PROTOTYPES ---------------------------------------------
*/

/*!
* Initializes the MCU RTC peripheral
*/
void hal_rtc_init(void);

/*!
* Returns the current RTC time in seconds
*
* \remark Used for scheduling autonomous retransmissions (i.e: NbTrans),
* transmitting MAC answers, basically any delay without accurate time
* constraints. It is also used to measure the time spent inside the
* LoRaWAN process for the integrated failsafe.
*
* retval rtc_time_s Current RTC time in seconds
*/
uint32_t hal_rtc_get_time_s(void);

/*!
* Returns the current RTC time in milliseconds
*
* \remark Used to timestamp radio events (i.e: end of TX), will also be used
* for ClassB
*
* retval rtc_time_ms Current RTC time in milliseconds wraps every 49 days
*/
uint32_t hal_rtc_get_time_ms(void);

/*!
* Sets the rtc wakeup timer for milliseconds parameter. The RTC will generate
* an IRQ to wakeup the MCU.
*
* \param[IN] milliseconds Number of seconds before wakeup
*/
void hal_rtc_wakeup_timer_set_ms(const int32_t milliseconds);

/*!
* Stop the rtc wakeup timer
*/
void hal_rtc_wakeup_timer_stop(void);

#ifdef __cplusplus
}
#endif

#endif // __RTC_UTILITIES_H__
#endif // __RTC_UTILITIES_H__

/* --- EOF ------------------------------------------------------------------ */
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,6 @@ uint32_t smtc_modem_hal_get_time_in_ms(void)
return hal_rtc_get_time_ms();
}

uint32_t smtc_modem_hal_get_time_in_100us(void)
{
return hal_rtc_get_time_100us();
}
void smtc_modem_hal_user_lbm_irq(void)
{
threadx_user_lbm_irq();
Expand Down
2 changes: 1 addition & 1 deletion lbm_applications/2_porting_nrf_52840/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Reference Implementation 2: Porting on Nordic NRF25840 Board
# Implementation reference 2: Porting on Nordic NRF52840 Board

This folder contains implementations of LoRa Basics Modem on some MCU boards and some application examples.

Expand Down
22 changes: 8 additions & 14 deletions lbm_applications/2_porting_nrf_52840/radio_hal/sx126x_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,10 @@ sx126x_hal_status_t sx126x_hal_write( const void* context, const uint8_t* comman

// Put NSS low to start spi transaction
hal_gpio_set_value( RADIO_NSS, 0 );
for( uint16_t i = 0; i < command_length; i++ )
{
hal_spi_in_out( RADIO_SPI_ID, command[i] );
}
for( uint16_t i = 0; i < data_length; i++ )
{
hal_spi_in_out( RADIO_SPI_ID, data[i] );
}

hal_spi_in_out( RADIO_SPI_ID, command, command_length, NULL, 0 );
hal_spi_in_out( RADIO_SPI_ID, data, data_length, NULL, 0 );

// Put NSS high as the spi transaction is finished
hal_gpio_set_value( RADIO_NSS, 1 );

Expand All @@ -135,13 +131,11 @@ sx126x_hal_status_t sx126x_hal_read( const void* context, const uint8_t* command

// Put NSS low to start spi transaction
hal_gpio_set_value( RADIO_NSS, 0 );
for( uint16_t i = 0; i < command_length; i++ )
{
hal_spi_in_out( RADIO_SPI_ID, command[i] );
}
for( uint16_t i = 0; i < data_length; i++ )
hal_spi_in_out( RADIO_SPI_ID, command, command_length, NULL, 0 );

if( data_length > 0 )
{
data[i] = hal_spi_in_out( RADIO_SPI_ID, 0 );
hal_spi_in_out( RADIO_SPI_ID, 0, 0, data, data_length );
}
// Put NSS high as the spi transaction is finished
hal_gpio_set_value( RADIO_NSS, 1 );
Expand Down
23 changes: 9 additions & 14 deletions lbm_applications/2_porting_nrf_52840/radio_hal/sx128x_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,10 @@ sx128x_hal_status_t sx128x_hal_write( const void* context, const uint8_t* comman

// Put NSS low to start spi transaction
hal_gpio_set_value( RADIO_NSS, 0 );
for( uint16_t i = 0; i < command_length; i++ )
{
hal_spi_in_out( RADIO_SPI_ID, command[i] );
}
for( uint16_t i = 0; i < data_length; i++ )
{
hal_spi_in_out( RADIO_SPI_ID, data[i] );
}

hal_spi_in_out( RADIO_SPI_ID, command, command_length, NULL, 0 );
hal_spi_in_out( RADIO_SPI_ID, data, data_length, NULL, 0 );

// Put NSS high as the spi transaction is finished
hal_gpio_set_value( RADIO_NSS, 1 );

Expand All @@ -134,14 +130,13 @@ sx128x_hal_status_t sx128x_hal_read( const void* context, const uint8_t* command

// Put NSS low to start spi transaction
hal_gpio_set_value( RADIO_NSS, 0 );
for( uint16_t i = 0; i < command_length; i++ )
{
hal_spi_in_out( RADIO_SPI_ID, command[i] );
}
for( uint16_t i = 0; i < data_length; i++ )
hal_spi_in_out( RADIO_SPI_ID, command, command_length, NULL, 0 );

if( data_length > 0 )
{
data[i] = hal_spi_in_out( RADIO_SPI_ID, 0 );
hal_spi_in_out( RADIO_SPI_ID, 0, 0, data, data_length );
}

// Put NSS high as the spi transaction is finished
hal_gpio_set_value( RADIO_NSS, 1 );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,24 +99,17 @@ void hal_rtc_init( void )
uint32_t hal_rtc_get_time_s( void )
{
uint32_t tmp_rtc = nrf_drv_rtc_counter_get( &rtc1 );
uint64_t tmp = ( ( uint64_t )( tmp_rtc ) + ( uint64_t )( ( 1 << 24 ) * rtc_wrap_counter ) ) /
uint64_t tmp = ( ( uint64_t ) ( tmp_rtc ) + ( uint64_t ) ( ( 1ULL << 24 ) * ( uint64_t ) rtc_wrap_counter ) ) /
NRFX_RTC_DEFAULT_CONFIG_FREQUENCY;
return ( uint32_t ) tmp;
}

uint32_t hal_rtc_get_time_ms( void )
{
uint32_t tmp_rtc = nrf_drv_rtc_counter_get( &rtc1 );
uint64_t tmp = ( ( ( uint64_t )( tmp_rtc ) + ( uint64_t )( ( 1 << 24 ) * rtc_wrap_counter ) ) * 1000 ) /
NRFX_RTC_DEFAULT_CONFIG_FREQUENCY;
return ( uint32_t ) tmp;
}

uint32_t hal_rtc_get_time_100us( void )
{
uint32_t tmp_rtc = nrf_drv_rtc_counter_get( &rtc1 );
uint64_t tmp = ( ( ( uint64_t )( tmp_rtc ) + ( uint64_t )( ( 1 << 24 ) * rtc_wrap_counter ) ) * 10000 ) /
NRFX_RTC_DEFAULT_CONFIG_FREQUENCY;
uint64_t tmp =
( ( ( uint64_t ) ( tmp_rtc ) + ( uint64_t ) ( ( 1ULL << 24 ) * ( uint64_t ) rtc_wrap_counter ) ) * 1000 ) /
NRFX_RTC_DEFAULT_CONFIG_FREQUENCY;
return ( uint32_t ) tmp;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,6 @@ uint32_t hal_rtc_get_time_s( void );
*/
uint32_t hal_rtc_get_time_ms( void );

/*!
* Returns the current RTC time in 0.1milliseconds
*
* \remark will also be used for d2d
*
*
* retval rtc_time_ms Current RTC time in milliseconds wraps every 4.9 days
*/
uint32_t hal_rtc_get_time_100us( void );

/*!
* Starts the provided timer objet for the given time
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,6 @@ uint32_t smtc_modem_hal_get_time_in_ms( void )
return hal_rtc_get_time_ms( );
}

uint32_t smtc_modem_hal_get_time_in_100us( void )
{
return hal_rtc_get_time_100us( );
}

/* ------------ Timer management ------------*/

void smtc_modem_hal_start_timer( const uint32_t milliseconds, void ( *callback )( void* context ), void* context )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,6 @@ uint32_t hal_rtc_get_time_s( void )
return rtc_get_calendar_time( &milliseconds );
}

uint32_t hal_rtc_get_time_100us( void )
{
uint32_t seconds = 0;
uint16_t milliseconds_div_10 = 0;

seconds = rtc_get_calendar_time( &milliseconds_div_10 );

return seconds * 10000 + milliseconds_div_10;
}
uint32_t hal_rtc_get_time_ms( void )
{
uint32_t seconds = 0;
Expand Down Expand Up @@ -247,7 +238,7 @@ static uint32_t rtc_tick_2_100us( const uint32_t tick )
uint32_t seconds = tick >> N_PREDIV_S;
uint32_t local_tick = tick & PREDIV_S;

return ( uint32_t )( ( seconds * 10000 ) + ( ( local_tick * 10000 ) >> N_PREDIV_S ) );
return ( uint32_t ) ( ( seconds * 10000 ) + ( ( local_tick * 10000 ) >> N_PREDIV_S ) );
}

static uint32_t rtc_ms_2_wakeup_timer_tick( const uint32_t milliseconds )
Expand All @@ -265,7 +256,7 @@ static uint32_t rtc_get_calendar_time( uint16_t* milliseconds_div_10 )

uint64_t timestamp_in_ticks = rtc_get_timestamp_in_ticks( );

uint32_t seconds = ( uint32_t )( timestamp_in_ticks >> N_PREDIV_S );
uint32_t seconds = ( uint32_t ) ( timestamp_in_ticks >> N_PREDIV_S );

ticks = ( uint32_t ) timestamp_in_ticks & PREDIV_S;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,6 @@ uint32_t hal_rtc_get_time_s( void );
*/
uint32_t hal_rtc_get_time_ms( void );

/*!
* Returns the current RTC time in 0.1milliseconds
*
* \remark will also be used for d2d
*
*
* retval rtc_time_ms Current RTC time in milliseconds wraps every 4.9 days
*/
uint32_t hal_rtc_get_time_100us( void );

/*!
* Sets the rtc wakeup timer for milliseconds parameter. The RTC will generate
* an IRQ to wakeup the MCU.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,6 @@ uint32_t smtc_modem_hal_get_time_in_ms( void )
return hal_rtc_get_time_ms( );
}

uint32_t smtc_modem_hal_get_time_in_100us( void )
{
return hal_rtc_get_time_100us( );
}

/* ------------ Timer management ------------*/

void smtc_modem_hal_start_timer( const uint32_t milliseconds, void ( *callback )( void* context ), void* context )
Expand Down
Loading

0 comments on commit 5b1839e

Please sign in to comment.