Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions MinimouseSrc/Define.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ enum {

typedef enum{
RADIO_IRQ_NONE = 0x00,
SENT_PACKET_IRQ_FLAG = 0x20,
SENT_PACKET_IRQ_FLAG = 0x20,
RECEIVE_PACKET_IRQ_FLAG = 0x40,
BAD_PACKET_IRQ_FLAG = 0x60,
RXTIMEOUT_IRQ_FLAG = 0x80,
Expand Down Expand Up @@ -223,17 +223,20 @@ typedef enum {
ERROR_CHANNEL_MASK = -1,
OKCHANNEL = 0,
}eStatusChannel;

typedef enum {
NO_MORE_VALID_RX_PACKET,
USER_RX_PACKET,
USERRX_FOPTSPACKET,
NWKRXPACKET,
JOIN_ACCEPT_PACKET,
} eRxPacketType;

typedef enum {
RX1,
RX2
}eRxWinType;

/*************************/
/* SHARE WITH USER */
/*************************/
Expand Down Expand Up @@ -295,4 +298,3 @@ typedef struct sLoRaWanKeys {
eDeviceTypeOTA_APB OtaDevice;
}sLoRaWanKeys;
#endif

30 changes: 24 additions & 6 deletions MinimouseSrc/MacLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ template <int NBCHANNEL, class R> void LoraWanContainer<NBCHANNEL, R>::Configure

template <int NBCHANNEL, class R> void LoraWanContainer<NBCHANNEL, R>::ConfigureRadioForRx1 ( void ) {
InsertTrace ( __COUNTER__, FileId );
Phy.SetRxConfig(MacTxModulationCurrent,MacRx1FrequencyCurrent, MacRx1SfCurrent, MacRx1BwCurrent, MacRxWindowMs);
Phy.SetRxConfig(MacRx1ModulationCurrent, MacRx1FrequencyCurrent, MacRx1SfCurrent, MacRx1BwCurrent, MacRxWindowMs);
};
/************************************************************************************************************************************/
/* ConfigureRadioForRx2 + ConfigureTimerForRx */
Expand All @@ -146,7 +146,7 @@ template <int NBCHANNEL, class R> void LoraWanContainer<NBCHANNEL, R>::Configure

template <int NBCHANNEL, class R> void LoraWanContainer<NBCHANNEL, R>::ConfigureRadioForRx2 ( void ) {
InsertTrace ( __COUNTER__, FileId );
Phy.SetRxConfig(MacTxModulationCurrent, MacRx2Frequency, MacRx2SfCurrent, MacRx2BwCurrent, MacRxWindowMs );
Phy.SetRxConfig(MacRx2ModulationCurrent, MacRx2Frequency, MacRx2SfCurrent, MacRx2BwCurrent, MacRxWindowMs );
};

template <int NBCHANNEL, class R> void LoraWanContainer<NBCHANNEL, R>::ConfigureRadioForRxClassC ( void ) {
Expand All @@ -156,13 +156,18 @@ template <int NBCHANNEL, class R> void LoraWanContainer<NBCHANNEL, R>::Configure

template <int NBCHANNEL, class R> void LoraWanContainer<NBCHANNEL, R>::ConfigureTimerForRx ( eRxWinType type ) {
InsertTrace ( __COUNTER__, FileId );
uint32_t tCurrentMillisec;
uint32_t tCurrentMillisec;
uint32_t tAlarmMillisec;
tCurrentMillisec = mcu.RtcGetTimeMs( );

if (type == RX1) {
RegionSetRxConfig ( RX1 );
ComputeRxWindowParameters ( MacRx1SfCurrent, MacRx1BwCurrent, CRYSTAL_ERROR, MacRx1Delay * 1000 , BOARD_DELAY_RX_SETTING_MS );
if( MacRx1ModulationCurrent == LORA ){
ComputeRxWindowParameters(MacRx1SfCurrent, MacRx1BwCurrent, CRYSTAL_ERROR, MacRx1Delay * 1000 , BOARD_DELAY_RX_SETTING_MS);
}
else{
ComputeRxWindowParametersFSK(CRYSTAL_ERROR, MacRx1Delay * 1000 , BOARD_DELAY_RX_SETTING_MS);
}
tAlarmMillisec = ( ( MacRx1Delay * 1000 )+ Phy.TimestampRtcIsr ) - tCurrentMillisec ;
if ( (int)(tAlarmMillisec - RxOffsetMs) < 0 ) {// too late to launch a timer
Phy.StateRadioProcess = RADIOSTATE_RX1FINISHED ;
Expand All @@ -172,6 +177,12 @@ template <int NBCHANNEL, class R> void LoraWanContainer<NBCHANNEL, R>::Configure
}
} else {
RegionSetRxConfig ( RX2 );
if( MacRx2ModulationCurrent == LORA ){
ComputeRxWindowParameters(MacRx2SfCurrent, MacRx2BwCurrent, CRYSTAL_ERROR, MacRx1Delay * 1000 , BOARD_DELAY_RX_SETTING_MS);
}
else{
ComputeRxWindowParametersFSK(CRYSTAL_ERROR, MacRx1Delay * 1000 , BOARD_DELAY_RX_SETTING_MS);
}
ComputeRxWindowParameters ( MacRx2SfCurrent, MacRx2BwCurrent, CRYSTAL_ERROR, MacRx1Delay * 1000 + 1000 , BOARD_DELAY_RX_SETTING_MS );
tAlarmMillisec = ( MacRx1Delay * 1000 ) + 1000 + Phy.TimestampRtcIsr - tCurrentMillisec ;// @note Rx2 Dalay is alway RX1DELAY + 1 second
if ( (int)(tAlarmMillisec - RxOffsetMs) < 0 ) {// too late to launch a timer
Expand Down Expand Up @@ -995,10 +1006,11 @@ template <int NBCHANNEL, class R> int LoraWanContainer<NBCHANNEL, R>::FindEnabl
}
return (-1) ; // for error case
};

template <int NBCHANNEL, class R> void LoraWanContainer<NBCHANNEL, R>::ComputeRxWindowParameters( uint8_t SF, eBandWidth BW, uint32_t ClockAccuracy, uint32_t RxDelayMs, uint8_t BoardDelayRxMs) {
// ClockAccuracy is set in Define.h, it is board dependent. It must be equal to error in per thousand
InsertTrace ( __COUNTER__, FileId );
uint32_t RxErrorMs= ( ClockAccuracy * RxDelayMs ) / 1000; // for example with an clockaccuracy = 30 (3%) and a rx windows set to 5s => rxerror = 150 ms
uint32_t RxErrorMs= ( ClockAccuracy * RxDelayMs ) / 1000; // for example with an clockaccuracy = 30 (3%) and a rx windows set to 5s => rxerror = 150 ms
int bwTemp = 125* ( BW + 1 );
double tSymbol = (double) (1<<SF) / (double) bwTemp;
Phy.SymbolDuration = (uint32_t) tSymbol ;
Expand All @@ -1008,6 +1020,12 @@ template <int NBCHANNEL, class R> void LoraWanContainer<NBCHANNEL, R>::ComputeR
MacRxWindowMs = MacRxWindowSymb * tSymbol ;
};

template <int NBCHANNEL, class R> void LoraWanContainer<NBCHANNEL, R>::ComputeRxWindowParametersFSK(uint32_t ClockAccuracy, uint32_t RxDelayMs, uint8_t BoardDelayRxMs) {
uint32_t RxErrorMs= ( ClockAccuracy * RxDelayMs ) / 1000;
MacRxWindowMs = 2 + 2*RxErrorMs; // Exact formula is 1.3 + 2*RxErrorMs
RxOffsetMs = MacRxWindowMs >> 1;
};

template <int NBCHANNEL, class R> eStatusLoRaWan LoraWanContainer<NBCHANNEL, R>::CheckValidMulticastPayload( void ){
eStatusLoRaWan status = OKLORAWAN;
uint8_t MtypeRxTmp = Phy.RxPhyPayload[0] >> 5 ;
Expand Down Expand Up @@ -1042,4 +1060,4 @@ template <int NBCHANNEL, class R> eStatusLoRaWan LoraWanContainer<NBCHANNEL, R>
template <int NBCHANNEL, class R> void LoraWanContainer<NBCHANNEL, R>::SetDevAddr( uint32_t address ){
DevAddr = address;
Phy.DevAddrIsr = address ;
}
}
7 changes: 5 additions & 2 deletions MinimouseSrc/MacLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,13 @@ protected :
eBandWidth MacTxBwCurrent;
uint32_t MacTxFrequencyCurrent;
uint32_t MacRx1FrequencyCurrent;
eModulationType MacRx1ModulationCurrent;
uint8_t MacRx1SfCurrent;
eBandWidth MacRx1BwCurrent;
eModulationType MacRx2ModulationCurrent;
uint8_t MacRx2SfCurrent;
eBandWidth MacRx2BwCurrent;
int FindEnabledChannel ( uint8_t Index );
int FindEnabledChannel ( uint8_t Index);
void PrintMacContext ( void ) ;

private :
Expand All @@ -226,7 +228,8 @@ private :
void RXTimingSetupParser ( void );
void DicChannelParser ( void );
void UpdateDataRateForAdr ( void );
void ComputeRxWindowParameters ( uint8_t SF, eBandWidth BW, uint32_t ClockAccuracy, uint32_t RxDelayMs, uint8_t BoardDelayRxMs );
void ComputeRxWindowParameters ( uint8_t SF, eBandWidth BW, uint32_t ClockAccuracy, uint32_t RxDelayMs ,uint8_t BoardDelayRxMs );
void ComputeRxWindowParametersFSK(uint32_t ClockAccuracy, uint32_t RxDelayMs, uint8_t BoardDelayRxMs);
sBackUpFlash BackUpFlash;
uint8_t NwkPayloadIndex;
uint8_t RxEmptyPayload;
Expand Down
3 changes: 2 additions & 1 deletion MinimouseSrc/PhyLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,12 @@ template <class R> void RadioContainer <R>::Send(eModulationType TxModulation ,
Radio->Reset( );
if ( TxModulation == LORA ) {
InsertTrace ( __COUNTER__, FileId );
DEBUG_PRINTF ( " TxFrequency = %d, RxSf = %d , RxBw = %d PayloadSize = %d\n", TxFrequency, TxSf,TxBw, TxPayloadSize) ;
DEBUG_PRINTF ( " TxFrequency = %d, RxSf = %d , RxBw = %d PayloadSize = %d\n", TxFrequency, TxSf,TxBw, TxPayloadSize);
Radio->SendLora( TxPhyPayload, TxPayloadSize, TxSf, TxBw, TxFrequency, TxPower );
} else {
InsertTrace ( __COUNTER__, FileId );
DEBUG_MSG("FSK TRANSMISSION \n");
DEBUG_PRINTF ( " TxFrequency = %d, PayloadSize = %d\n", TxFrequency, TxPayloadSize);
Radio->SendFsk( TxPhyPayload, TxPayloadSize, TxFrequency, TxPower );
}
mcu.mwait_ms(1);
Expand Down
56 changes: 32 additions & 24 deletions MinimouseSrc/Regions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,14 @@ template < class R >eStatusLoRaWan LoraRegionsEU<R>::RegionMaxPayloadSize ( uint
template < class R >void LoraRegionsEU<R>::RegionSetRxConfig ( eRxWinType type ) {
InsertTrace ( __COUNTER__, FileId );
if ( type == RX1 ) {
this->MacRx1SfCurrent = ( this->MacTxSfCurrent < 12 - this->MacRx1DataRateOffset) ? this->MacTxSfCurrent + this->MacRx1DataRateOffset : 12;
this->MacRx1BwCurrent = this->MacTxBwCurrent;
if( this->MacTxModulationCurrent == FSK && this->MacRx1DataRateOffset == 0){
this->MacRx1ModulationCurrent = FSK;
}
else{
this->MacRx1ModulationCurrent = LORA;
this->MacRx1SfCurrent = ( this->MacTxSfCurrent < 12 - this->MacRx1DataRateOffset) ? this->MacTxSfCurrent + this->MacRx1DataRateOffset : 12;
this->MacRx1BwCurrent = this->MacTxBwCurrent;
}
} else if ( type == RX2 ) {
Rx2DataRateToSfBw ( this->MacRx2DataRate );
} else {
Expand Down Expand Up @@ -282,8 +288,8 @@ template < class R >void LoraRegionsEU<R>::RegionSetDataRateDistribution( uint8_
this->MacNbTrans = 1;
break;
case USER_DR_DISTRIBUTION: //in this example 1/3 dr5 1/3 dr4 and 1/3 dr0
DistriDataRateInit[7] = ( ( USER_DR_DISTRIBUTION_PARAMETERS )& ( 0x0000000F ) );
DistriDataRateInit[6] = ( ( USER_DR_DISTRIBUTION_PARAMETERS )& ( 0x000000F0 ) ) >> 4; //fsk
DistriDataRateInit[7] = USER_DR_DISTRIBUTION_PARAMETERS & 0x0000000F; //fsk
DistriDataRateInit[6] = ( ( USER_DR_DISTRIBUTION_PARAMETERS )& ( 0x000000F0 ) ) >> 4;
DistriDataRateInit[5] = ( ( USER_DR_DISTRIBUTION_PARAMETERS )& ( 0x00000F00 ) ) >> 8;
DistriDataRateInit[4] = ( ( USER_DR_DISTRIBUTION_PARAMETERS )& ( 0x0000F000 ) ) >> 12;
DistriDataRateInit[3] = ( ( USER_DR_DISTRIBUTION_PARAMETERS )& ( 0x000F0000 ) ) >> 16;
Expand Down Expand Up @@ -530,36 +536,38 @@ template < class R >void LoraRegionsEU<R>::RegionSetBadCrcInFlash ( void ){
/***********************************************************************************************/
//@notereview function a commun
template < class R >void LoraRegionsEU<R>:: TxDataRateToSfBw ( uint8_t dataRate ) {
InsertTrace ( __COUNTER__, FileId );
this->MacTxModulationCurrent = LORA ;
InsertTrace ( __COUNTER__, FileId );
this->MacTxModulationCurrent = LORA;
if ( dataRate < 6 ){
this->MacTxSfCurrent = 12 - dataRate ;
this->MacTxBwCurrent = BW125 ;
this->MacTxSfCurrent = 12 - dataRate;
this->MacTxBwCurrent = BW125;
} else if ( dataRate == 6 ){
this->MacTxSfCurrent = 7;
this->MacTxBwCurrent = BW250 ;}
else if ( dataRate == 7 ) {
this->MacTxModulationCurrent = FSK ;
this->MacTxBwCurrent = BW250;
} else if ( dataRate == 7 ) {
this->MacTxModulationCurrent = FSK;
} else {
this->MacTxSfCurrent = 12 ;
this->MacTxBwCurrent = BW125 ;
DEBUG_MSG( " Invalid Datarate \n" ) ;
this->MacTxSfCurrent = 12;
this->MacTxBwCurrent = BW125;
DEBUG_MSG( " Invalid Datarate \n" );
}
}
template < class R >void LoraRegionsEU<R>:: Rx2DataRateToSfBw ( uint8_t dataRate ) {
InsertTrace ( __COUNTER__, FileId );
if ( dataRate < 6 ){
this->MacRx2SfCurrent = 12 - dataRate ;
this->MacRx2BwCurrent = BW125 ;
} else if ( dataRate== 6 ){
if ( dataRate < 6 ){
this->MacRx2ModulationCurrent = LORA;
this->MacRx2SfCurrent = 12 - dataRate;
this->MacRx2BwCurrent = BW125;
} else if ( dataRate== 6 ){
this->MacRx2ModulationCurrent = LORA;
this->MacRx2SfCurrent = 7;
this->MacRx2BwCurrent = BW250 ;}
else if ( dataRate == 7 ) {
//@note tbd manage fsk case }
this->MacRx2BwCurrent = BW250;
} else if ( dataRate == 7 ) {
this->MacRx2ModulationCurrent = FSK;
}
else {
this->MacRx2SfCurrent = 12 ;
this->MacRx2BwCurrent = BW125 ;
DEBUG_MSG( " Invalid Datarate \n" ) ;
this->MacRx2SfCurrent = 12;
this->MacRx2BwCurrent = BW125;
DEBUG_MSG( " Invalid Datarate \n" );
}
}
Loading