Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 976af3b

Browse files
committed
MicroPython 1.20.0.rc11.2
Add support for LoRa regions CN470 and IN865 This is a special customer pre-release and has only been tested on the LoPy4!
1 parent 19bd9e7 commit 976af3b

16 files changed

+273
-9
lines changed

drivers/sx127x/radio.h

+8
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ struct Radio_s
117117
* \param [IN] freq Channel RF frequency
118118
*/
119119
void ( *SetChannel )( uint32_t freq );
120+
121+
/*!
122+
* \brief Gets the channel frequency
123+
*
124+
* \param Channel RF frequency
125+
*/
126+
uint32_t ( *GetChannel )( void );
127+
120128
/*!
121129
* \brief Checks if the channel is free for the given time
122130
*

drivers/sx127x/sx1272/sx1272.c

+5
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,11 @@ IRAM_ATTR void SX1272SetChannel( uint32_t freq )
230230
SX1272Write( REG_FRFLSB, ( uint8_t )( freq & 0xFF ) );
231231
}
232232

233+
IRAM_ATTR uint32_t SX1272GetChannel( void )
234+
{
235+
return SX1272.Settings.Channel;
236+
}
237+
233238
bool SX1272IsChannelFree( RadioModems_t modem, uint32_t freq, int16_t rssiThresh, uint32_t maxCarrierSenseTime )
234239
{
235240
bool status = true;

drivers/sx127x/sx1272/sx1272.h

+7
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,13 @@ void SX1272SetModem( RadioModems_t modem );
175175
*/
176176
void SX1272SetChannel( uint32_t freq );
177177

178+
/*!
179+
* Return the channel configuration
180+
*
181+
* \param Channel RF frequency .
182+
*/
183+
uint32_t SX1272GetChannel( void );
184+
178185
/*!
179186
* \brief Checks if the channel is free for the given time
180187
*

drivers/sx127x/sx1276/sx1276.c

+5
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,11 @@ IRAM_ATTR void SX1276SetChannel( uint32_t freq )
251251
SX1276Write( REG_FRFLSB, ( uint8_t )( freq & 0xFF ) );
252252
}
253253

254+
IRAM_ATTR uint32_t SX1276GetChannel( void )
255+
{
256+
return SX1276.Settings.Channel;
257+
}
258+
254259
bool SX1276IsChannelFree( RadioModems_t modem, uint32_t freq, int16_t rssiThresh, uint32_t maxCarrierSenseTime )
255260
{
256261
bool status = true;

drivers/sx127x/sx1276/sx1276.h

+7
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,13 @@ void SX1276SetModem( RadioModems_t modem );
175175
*/
176176
void SX1276SetChannel( uint32_t freq );
177177

178+
/*!
179+
* Return the channel configuration
180+
*
181+
* \param Channel RF frequency .
182+
*/
183+
uint32_t SX1276GetChannel( void );
184+
178185
/*!
179186
* \brief Checks if the channel is free for the given time
180187
*

esp32/application.mk

+5-2
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ APP_LIB_LORA_SRC_C = $(addprefix lib/lora/,\
216216
mac/region/RegionCommon.c \
217217
mac/region/RegionEU868.c \
218218
mac/region/RegionUS915.c \
219+
mac/region/RegionCN470.c \
220+
mac/region/RegionIN865.c \
219221
system/delay.c \
220222
system/gpio.c \
221223
system/timer.c \
@@ -358,7 +360,7 @@ APP_LDFLAGS += $(LDFLAGS) -T esp32_out.ld -T esp32.common.ld -T esp32.rom.ld -T
358360
# add the application specific CFLAGS
359361
CFLAGS += $(APP_INC) -DMICROPY_NLR_SETJMP=1 -DMBEDTLS_CONFIG_FILE='"mbedtls/esp_config.h"' -DHAVE_CONFIG_H -DESP_PLATFORM -DFFCONF_H=\"lib/oofatfs/ffconf.h\"
360362
CFLAGS_SIGFOX += $(APP_INC) -DMICROPY_NLR_SETJMP=1 -DMBEDTLS_CONFIG_FILE='"mbedtls/esp_config.h"' -DHAVE_CONFIG_H -DESP_PLATFORM
361-
CFLAGS += -DREGION_AS923 -DREGION_AU915 -DREGION_EU868 -DREGION_US915 -DBASE=0 -DPYBYTES=1
363+
CFLAGS += -DREGION_AS923 -DREGION_AU915 -DREGION_EU868 -DREGION_US915 -DREGION_CN470 -DREGION_IN865 -DBASE=0 -DPYBYTES=1
362364
# Specify if this is base or Pybytes Firmware
363365
ifeq ($(VARIANT),BASE)
364366
CFLAGS += -DVARIANT=0
@@ -456,7 +458,8 @@ ENTER_FLASHING_MODE = $(PIC_TOOL) --enter
456458
EXIT_FLASHING_MODE = $(PIC_TOOL) --exit
457459

458460
ESPTOOLPY = $(PYTHON) $(IDF_PATH)/components/esptool_py/esptool/esptool.py --chip esp32
459-
ESPTOOLPY_SERIAL = $(ESPTOOLPY) --port $(ESPPORT) --baud $(ESPBAUD) --before no_reset --after no_reset
461+
ESPRESET ?= --before no_reset --after no_reset
462+
ESPTOOLPY_SERIAL = $(ESPTOOLPY) --port $(ESPPORT) --baud $(ESPBAUD) $(ESPRESET)
460463

461464
ESPTOOLPY_WRITE_FLASH = $(ESPTOOLPY_SERIAL) write_flash -z --flash_mode $(ESPFLASHMODE) --flash_freq $(ESPFLASHFREQ) --flash_size $(FLASH_SIZE)
462465
ESPTOOLPY_ERASE_FLASH = $(ESPTOOLPY_SERIAL) erase_flash

esp32/lora/sx1272-board.c

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ DRAM_ATTR const struct Radio_s Radio =
3232
SX1272GetStatus,
3333
SX1272SetModem,
3434
SX1272SetChannel,
35+
SX1272GetChannel,
3536
SX1272IsChannelFree,
3637
SX1272Random,
3738
SX1272SetRxConfig,

esp32/lora/sx1276-board.c

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ DRAM_ATTR const struct Radio_s Radio =
3131
SX1276GetStatus,
3232
SX1276SetModem,
3333
SX1276SetChannel,
34+
SX1276GetChannel,
3435
SX1276IsChannelFree,
3536
SX1276Random,
3637
SX1276SetRxConfig,

esp32/mods/modlora.c

+42-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
#include "lora/mac/region/RegionUS915.h"
5353
#include "lora/mac/region/RegionUS915-Hybrid.h"
5454
#include "lora/mac/region/RegionEU868.h"
55+
#include "lora/mac/region/RegionCN470.h"
56+
#include "lora/mac/region/RegionIN865.h"
5557

5658
// openThread includes
5759
#ifdef LORA_OPENTHREAD_ENABLED
@@ -1317,6 +1319,20 @@ static void lora_validate_frequency (uint32_t frequency) {
13171319
goto freq_error;
13181320
}
13191321
break;
1322+
case LORAMAC_REGION_CN470:
1323+
#if defined(LOPY4)
1324+
if (frequency < 470000000 || frequency > 510000000) {
1325+
goto freq_error;
1326+
}
1327+
#else
1328+
goto freq_error;
1329+
#endif
1330+
break;
1331+
case LORAMAC_REGION_IN865:
1332+
if (frequency < 865000000 || frequency > 867000000) {
1333+
goto freq_error;
1334+
}
1335+
break;
13201336
case LORAMAC_REGION_EU868:
13211337
#if defined(LOPY4)
13221338
if (frequency < 410000000 || frequency > 870000000) {
@@ -1362,6 +1378,16 @@ static void lora_validate_channel (uint32_t index) {
13621378
goto channel_error;
13631379
}
13641380
break;
1381+
case LORAMAC_REGION_CN470:
1382+
if (index >= CN470_MAX_NB_CHANNELS) {
1383+
goto channel_error;
1384+
}
1385+
break;
1386+
case LORAMAC_REGION_IN865:
1387+
if (index >= IN865_MAX_NB_CHANNELS) {
1388+
goto channel_error;
1389+
}
1390+
break;
13651391
default:
13661392
break;
13671393
}
@@ -1383,6 +1409,8 @@ static bool lora_validate_data_rate (uint32_t data_rate) {
13831409
case LORAMAC_REGION_AS923:
13841410
case LORAMAC_REGION_EU868:
13851411
case LORAMAC_REGION_AU915:
1412+
case LORAMAC_REGION_CN470:
1413+
case LORAMAC_REGION_IN865:
13861414
if (data_rate > DR_6) {
13871415
return false;
13881416
}
@@ -1432,7 +1460,8 @@ static void lora_validate_device_class (DeviceClass_t device_class) {
14321460

14331461
static void lora_validate_region (LoRaMacRegion_t region) {
14341462
if (region != LORAMAC_REGION_AS923 && region != LORAMAC_REGION_AU915
1435-
&& region != LORAMAC_REGION_EU868 && region != LORAMAC_REGION_US915) {
1463+
&& region != LORAMAC_REGION_EU868 && region != LORAMAC_REGION_US915
1464+
&& region != LORAMAC_REGION_CN470 && region != LORAMAC_REGION_IN865) {
14361465
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "invalid region %d", region));
14371466
}
14381467
}
@@ -1653,6 +1682,10 @@ static mp_obj_t lora_init_helper(lora_obj_t *self, const mp_arg_val_t *args) {
16531682
case LORAMAC_REGION_EU868:
16541683
cmd_data.info.init.frequency = 868000000;
16551684
break;
1685+
case LORAMAC_REGION_CN470:
1686+
cmd_data.info.init.frequency = 470000000;
1687+
case LORAMAC_REGION_IN865:
1688+
cmd_data.info.init.frequency = 865000000;
16561689
default:
16571690
break;
16581691
}
@@ -1666,9 +1699,11 @@ static mp_obj_t lora_init_helper(lora_obj_t *self, const mp_arg_val_t *args) {
16661699
case LORAMAC_REGION_AS923:
16671700
case LORAMAC_REGION_AU915:
16681701
case LORAMAC_REGION_US915:
1702+
case LORAMAC_REGION_IN865:
16691703
case LORAMAC_REGION_US915_HYBRID:
16701704
cmd_data.info.init.tx_power = 20;
16711705
break;
1706+
case LORAMAC_REGION_CN470:
16721707
case LORAMAC_REGION_EU868:
16731708
cmd_data.info.init.tx_power = 14;
16741709
break;
@@ -1829,7 +1864,9 @@ STATIC mp_obj_t lora_join(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *
18291864
case LORAMAC_REGION_US915_HYBRID:
18301865
dr = DR_4;
18311866
break;
1867+
case LORAMAC_REGION_CN470:
18321868
case LORAMAC_REGION_EU868:
1869+
case LORAMAC_REGION_IN865:
18331870
dr = DR_5;
18341871
break;
18351872
default:
@@ -1860,6 +1897,7 @@ STATIC mp_obj_t lora_join(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *
18601897
goto dr_error;
18611898
}
18621899
break;
1900+
case LORAMAC_REGION_CN470:
18631901
case LORAMAC_REGION_EU868:
18641902
if (dr > DR_5) {
18651903
goto dr_error;
@@ -2406,6 +2444,8 @@ STATIC const mp_map_elem_t lora_locals_dict_table[] = {
24062444
{ MP_OBJ_NEW_QSTR(MP_QSTR_AU915), MP_OBJ_NEW_SMALL_INT(LORAMAC_REGION_AU915) },
24072445
{ MP_OBJ_NEW_QSTR(MP_QSTR_EU868), MP_OBJ_NEW_SMALL_INT(LORAMAC_REGION_EU868) },
24082446
{ MP_OBJ_NEW_QSTR(MP_QSTR_US915), MP_OBJ_NEW_SMALL_INT(LORAMAC_REGION_US915) },
2447+
{ MP_OBJ_NEW_QSTR(MP_QSTR_CN470), MP_OBJ_NEW_SMALL_INT(LORAMAC_REGION_CN470) },
2448+
{ MP_OBJ_NEW_QSTR(MP_QSTR_IN865), MP_OBJ_NEW_SMALL_INT(LORAMAC_REGION_IN865) },
24092449
};
24102450

24112451
STATIC MP_DEFINE_CONST_DICT(lora_locals_dict, lora_locals_dict_table);
@@ -2451,6 +2491,7 @@ static int lora_socket_socket (mod_network_socket_obj_t *s, int *_errno) {
24512491
switch (lora_obj.region) {
24522492
case LORAMAC_REGION_AS923:
24532493
case LORAMAC_REGION_EU868:
2494+
case LORAMAC_REGION_CN470:
24542495
dr = DR_5;
24552496
break;
24562497
case LORAMAC_REGION_AU915:

esp32/pycom_version.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#ifndef VERSION_H_
1111
#define VERSION_H_
1212

13-
#define SW_VERSION_NUMBER "1.20.0.rc11.1"
13+
#define SW_VERSION_NUMBER "1.20.0.rc11.2"
1414

1515
#define LORAWAN_VERSION_NUMBER "1.0.2"
1616

lib/lora/mac/LoRaMac.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -2222,7 +2222,8 @@ LoRaMacStatus_t SendFrameOnChannel( uint8_t channel )
22222222
McpsConfirm.Status = LORAMAC_EVENT_INFO_STATUS_ERROR;
22232223
McpsConfirm.Datarate = LoRaMacParams.ChannelsDatarate;
22242224
McpsConfirm.TxPower = txPower;
2225-
2225+
McpsConfirm.UpLinkFrequency = Radio.GetChannel();
2226+
22262227
// Store the time on air
22272228
McpsConfirm.TxTimeOnAir = TxTimeOnAir;
22282229
MlmeConfirm.TxTimeOnAir = TxTimeOnAir;

lib/lora/mac/region/Region.c

+24-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ Maintainer: Miguel Luis ( Semtech ), Gregory Cristian ( Semtech ) and Daniel Jae
3030
#include "Region.h"
3131

3232

33-
3433
// Setup regions
3534
#ifdef REGION_AS923
3635
#include "RegionAS923.h"
@@ -182,8 +181,11 @@ Maintainer: Miguel Luis ( Semtech ), Gregory Cristian ( Semtech ) and Daniel Jae
182181
#define CN470_NEXT_CHANNEL( ) CN470_CASE { return RegionCN470NextChannel( nextChanParams, channel, time, aggregatedTimeOff ); }
183182
#define CN470_CHANNEL_ADD( ) CN470_CASE { return RegionCN470ChannelAdd( channelAdd ); }
184183
#define CN470_CHANNEL_REMOVE( ) CN470_CASE { return RegionCN470ChannelsRemove( channelRemove ); }
184+
#define CN470_CHANNEL_MANUAL_ADD( ) CN470_CASE { return RegionCN470ChannelManualAdd( channelAdd ); }
185+
#define CN470_CHANNEL_MANUAL_REMOVE( ) CN470_CASE { return RegionCN470ChannelsRemove( channelRemove ); }
185186
#define CN470_SET_CONTINUOUS_WAVE( ) CN470_CASE { RegionCN470SetContinuousWave( continuousWave ); break; }
186187
#define CN470_APPLY_DR_OFFSET( ) CN470_CASE { return RegionCN470ApplyDrOffset( downlinkDwellTime, dr, drOffset ); }
188+
#define CN470_FORCE_JOIN_DATARATE( ) CN470_CASE { return RegionCN470ForceJoinDataRate( joinDr, alternateDr ); }
187189
#else
188190
#define CN470_IS_ACTIVE( )
189191
#define CN470_GET_PHY_PARAM( )
@@ -206,8 +208,11 @@ Maintainer: Miguel Luis ( Semtech ), Gregory Cristian ( Semtech ) and Daniel Jae
206208
#define CN470_NEXT_CHANNEL( )
207209
#define CN470_CHANNEL_ADD( )
208210
#define CN470_CHANNEL_REMOVE( )
211+
#define CN470_CHANNEL_MANUAL_ADD( )
212+
#define CN470_CHANNEL_MANUAL_REMOVE( )
209213
#define CN470_SET_CONTINUOUS_WAVE( )
210214
#define CN470_APPLY_DR_OFFSET( )
215+
#define CN470_FORCE_JOIN_DATARATE( )
211216
#endif
212217

213218
#ifdef REGION_CN779
@@ -452,8 +457,13 @@ Maintainer: Miguel Luis ( Semtech ), Gregory Cristian ( Semtech ) and Daniel Jae
452457
#define IN865_NEXT_CHANNEL( ) IN865_CASE { return RegionIN865NextChannel( nextChanParams, channel, time, aggregatedTimeOff ); }
453458
#define IN865_CHANNEL_ADD( ) IN865_CASE { return RegionIN865ChannelAdd( channelAdd ); }
454459
#define IN865_CHANNEL_REMOVE( ) IN865_CASE { return RegionIN865ChannelsRemove( channelRemove ); }
460+
#define IN865_CHANNEL_MANUAL_ADD( ) IN865_CASE { return RegionIN865ChannelManualAdd( channelAdd ); }
461+
#define IN865_CHANNEL_MANUAL_REMOVE( ) IN865_CASE { return RegionIN865ChannelsRemove( channelRemove ); }
455462
#define IN865_SET_CONTINUOUS_WAVE( ) IN865_CASE { RegionIN865SetContinuousWave( continuousWave ); break; }
456463
#define IN865_APPLY_DR_OFFSET( ) IN865_CASE { return RegionIN865ApplyDrOffset( downlinkDwellTime, dr, drOffset ); }
464+
#define IN865_GET_CHANNELS( ) IN865_CASE { return RegionIN865GetChannels( channels, size ); }
465+
#define IN865_GET_CHANNEL_MASK( ) IN865_CASE { return RegionIN865GetChannelMask( channelmask, size ); }
466+
#define IN865_FORCE_JOIN_DATARATE( ) IN865_CASE { return RegionIN865ForceJoinDataRate( joinDr, alternateDr ); }
457467
#else
458468
#define IN865_IS_ACTIVE( )
459469
#define IN865_GET_PHY_PARAM( )
@@ -476,8 +486,13 @@ Maintainer: Miguel Luis ( Semtech ), Gregory Cristian ( Semtech ) and Daniel Jae
476486
#define IN865_NEXT_CHANNEL( )
477487
#define IN865_CHANNEL_ADD( )
478488
#define IN865_CHANNEL_REMOVE( )
489+
#define IN865_CHANNEL_MANUAL_ADD( )
490+
#define IN865_CHANNEL_MANUAL_REMOVE( )
479491
#define IN865_SET_CONTINUOUS_WAVE( )
480492
#define IN865_APPLY_DR_OFFSET( )
493+
#define IN865_GET_CHANNELS( )
494+
#define IN865_GET_CHANNEL_MASK( )
495+
#define IN865_FORCE_JOIN_DATARATE( )
481496
#endif
482497

483498
#ifdef REGION_US915
@@ -1037,6 +1052,8 @@ LoRaMacStatus_t RegionChannelManualAdd( LoRaMacRegion_t region, ChannelAddParams
10371052
AU915_CHANNEL_MANUAL_ADD( );
10381053
EU868_CHANNEL_MANUAL_ADD( );
10391054
US915_CHANNEL_MANUAL_ADD( );
1055+
CN470_CHANNEL_MANUAL_ADD( );
1056+
IN865_CHANNEL_MANUAL_ADD( );
10401057
US915_HYBRID_CHANNEL_MANUAL_ADD( );
10411058
default:
10421059
{
@@ -1074,6 +1091,8 @@ bool RegionChannelsManualRemove( LoRaMacRegion_t region, ChannelRemoveParams_t*
10741091
AU915_CHANNEL_MANUAL_REMOVE( );
10751092
EU868_CHANNEL_MANUAL_REMOVE( );
10761093
US915_CHANNEL_MANUAL_REMOVE( );
1094+
CN470_CHANNEL_MANUAL_REMOVE( );
1095+
IN865_CHANNEL_MANUAL_REMOVE( );
10771096
US915_HYBRID_CHANNEL_MANUAL_REMOVE( );
10781097
default:
10791098
{
@@ -1131,6 +1150,7 @@ bool RegionGetChannels( LoRaMacRegion_t region, ChannelParams_t** channels, uint
11311150
AS923_GET_CHANNELS( );
11321151
AU915_GET_CHANNELS( );
11331152
EU868_GET_CHANNELS( );
1153+
IN865_GET_CHANNELS( );
11341154
US915_GET_CHANNELS( );
11351155
US915_HYBRID_GET_CHANNELS( );
11361156
default:
@@ -1146,6 +1166,7 @@ bool RegionGetChannelMask(LoRaMacRegion_t region, uint16_t **channelmask, uint32
11461166
AS923_GET_CHANNEL_MASK( );
11471167
AU915_GET_CHANNEL_MASK( );
11481168
EU868_GET_CHANNEL_MASK( );
1169+
IN865_GET_CHANNEL_MASK( );
11491170
US915_GET_CHANNEL_MASK( );
11501171
US915_HYBRID_GET_CHANNEL_MASK( );
11511172
default:
@@ -1176,6 +1197,8 @@ bool RegionForceJoinDataRate( LoRaMacRegion_t region, int8_t joinDr, AlternateDr
11761197
AU915_FORCE_JOIN_DATARATE( );
11771198
EU868_FORCE_JOIN_DATARATE( );
11781199
US915_FORCE_JOIN_DATARATE( );
1200+
CN470_FORCE_JOIN_DATARATE( );
1201+
IN865_FORCE_JOIN_DATARATE( );
11791202
US915_HYBRID_FORCE_JOIN_DATARATE( );
11801203
default:
11811204
{

0 commit comments

Comments
 (0)