|
45 | 45 | #define DUTY_CYCLE_TIME_PERIOD 3600000 |
46 | 46 | #endif |
47 | 47 |
|
| 48 | +/*! |
| 49 | + * \brief Returns `N / D` rounded to the smallest integer value greater than or equal to `N / D` |
| 50 | + * |
| 51 | + * \warning when `D == 0`, the result is undefined |
| 52 | + * |
| 53 | + * \remark `N` and `D` can be signed or unsigned |
| 54 | + * |
| 55 | + * \param [IN] N the numerator, which can have any sign |
| 56 | + * \param [IN] D the denominator, which can have any sign |
| 57 | + * \retval N / D with any fractional part rounded to the smallest integer value greater than or equal to `N / D` |
| 58 | + */ |
| 59 | +#define DIV_CEIL( N, D ) \ |
| 60 | + ( \ |
| 61 | + ( N > 0 ) ? \ |
| 62 | + ( ( ( N ) + ( D ) - 1 ) / ( D ) ) : \ |
| 63 | + ( ( N ) / ( D ) ) \ |
| 64 | + ) |
| 65 | + |
48 | 66 | static uint16_t GetDutyCycle( Band_t* band, bool joined, SysTime_t elapsedTimeSinceStartup ) |
49 | 67 | { |
50 | 68 | uint16_t joinDutyCycle = RegionCommonGetJoinDc( elapsedTimeSinceStartup ); |
@@ -410,20 +428,22 @@ uint8_t RegionCommonLinkAdrReqVerifyParams( RegionCommonLinkAdrReqVerifyParams_t |
410 | 428 | return status; |
411 | 429 | } |
412 | 430 |
|
413 | | -double RegionCommonComputeSymbolTimeLoRa( uint8_t phyDr, uint32_t bandwidth ) |
| 431 | +uint32_t RegionCommonComputeSymbolTimeLoRa( uint8_t phyDr, uint32_t bandwidthInHz ) |
414 | 432 | { |
415 | | - return ( ( double )( 1 << phyDr ) / ( double )bandwidth ) * 1000; |
| 433 | + return ( 1 << phyDr ) * 1000000 / bandwidthInHz; |
416 | 434 | } |
417 | 435 |
|
418 | | -double RegionCommonComputeSymbolTimeFsk( uint8_t phyDr ) |
| 436 | +uint32_t RegionCommonComputeSymbolTimeFsk( uint8_t phyDrInKbps ) |
419 | 437 | { |
420 | | - return ( 8.0 / ( double )phyDr ); // 1 symbol equals 1 byte |
| 438 | + return 8000 / ( uint32_t )phyDrInKbps; // 1 symbol equals 1 byte |
421 | 439 | } |
422 | 440 |
|
423 | | -void RegionCommonComputeRxWindowParameters( double tSymbol, uint8_t minRxSymbols, uint32_t rxError, uint32_t wakeUpTime, uint32_t* windowTimeout, int32_t* windowOffset ) |
| 441 | +void RegionCommonComputeRxWindowParameters( uint32_t tSymbolInUs, uint8_t minRxSymbols, uint32_t rxErrorInMs, uint32_t wakeUpTimeInMs, uint32_t* windowTimeoutInSymbols, int32_t* windowOffsetInMs ) |
424 | 442 | { |
425 | | - *windowTimeout = MAX( ( uint32_t )ceil( ( ( 2 * minRxSymbols - 8 ) * tSymbol + 2 * rxError ) / tSymbol ), minRxSymbols ); // Computed number of symbols |
426 | | - *windowOffset = ( int32_t )ceil( ( 4.0 * tSymbol ) - ( ( *windowTimeout * tSymbol ) / 2.0 ) - wakeUpTime ); |
| 443 | + *windowTimeoutInSymbols = MAX( DIV_CEIL( ( ( 2 * minRxSymbols - 8 ) * tSymbolInUs + 2 * ( rxErrorInMs * 1000 ) ), tSymbolInUs ), minRxSymbols ); // Computed number of symbols |
| 444 | + *windowOffsetInMs = ( int32_t )DIV_CEIL( ( int32_t )( 4 * tSymbolInUs ) - |
| 445 | + ( int32_t )DIV_CEIL( ( *windowTimeoutInSymbols * tSymbolInUs ), 2 ) - |
| 446 | + ( int32_t )( wakeUpTimeInMs * 1000 ), 1000 ); |
427 | 447 | } |
428 | 448 |
|
429 | 449 | int8_t RegionCommonComputeTxPower( int8_t txPowerIndex, float maxEirp, float antennaGain ) |
|
0 commit comments