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

Commit

Permalink
MicroPython 1.20.0.rc11.2
Browse files Browse the repository at this point in the history
Add support for LoRa regions CN470 and IN865

This is a special customer pre-release and has only been tested on the LoPy4!
  • Loading branch information
Xykon committed Jun 28, 2019
1 parent 19bd9e7 commit 976af3b
Show file tree
Hide file tree
Showing 16 changed files with 273 additions and 9 deletions.
8 changes: 8 additions & 0 deletions drivers/sx127x/radio.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ struct Radio_s
* \param [IN] freq Channel RF frequency
*/
void ( *SetChannel )( uint32_t freq );

/*!
* \brief Gets the channel frequency
*
* \param Channel RF frequency
*/
uint32_t ( *GetChannel )( void );

/*!
* \brief Checks if the channel is free for the given time
*
Expand Down
5 changes: 5 additions & 0 deletions drivers/sx127x/sx1272/sx1272.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ IRAM_ATTR void SX1272SetChannel( uint32_t freq )
SX1272Write( REG_FRFLSB, ( uint8_t )( freq & 0xFF ) );
}

IRAM_ATTR uint32_t SX1272GetChannel( void )
{
return SX1272.Settings.Channel;
}

bool SX1272IsChannelFree( RadioModems_t modem, uint32_t freq, int16_t rssiThresh, uint32_t maxCarrierSenseTime )
{
bool status = true;
Expand Down
7 changes: 7 additions & 0 deletions drivers/sx127x/sx1272/sx1272.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,13 @@ void SX1272SetModem( RadioModems_t modem );
*/
void SX1272SetChannel( uint32_t freq );

/*!
* Return the channel configuration
*
* \param Channel RF frequency .
*/
uint32_t SX1272GetChannel( void );

/*!
* \brief Checks if the channel is free for the given time
*
Expand Down
5 changes: 5 additions & 0 deletions drivers/sx127x/sx1276/sx1276.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@ IRAM_ATTR void SX1276SetChannel( uint32_t freq )
SX1276Write( REG_FRFLSB, ( uint8_t )( freq & 0xFF ) );
}

IRAM_ATTR uint32_t SX1276GetChannel( void )
{
return SX1276.Settings.Channel;
}

bool SX1276IsChannelFree( RadioModems_t modem, uint32_t freq, int16_t rssiThresh, uint32_t maxCarrierSenseTime )
{
bool status = true;
Expand Down
7 changes: 7 additions & 0 deletions drivers/sx127x/sx1276/sx1276.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,13 @@ void SX1276SetModem( RadioModems_t modem );
*/
void SX1276SetChannel( uint32_t freq );

/*!
* Return the channel configuration
*
* \param Channel RF frequency .
*/
uint32_t SX1276GetChannel( void );

/*!
* \brief Checks if the channel is free for the given time
*
Expand Down
7 changes: 5 additions & 2 deletions esp32/application.mk
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ APP_LIB_LORA_SRC_C = $(addprefix lib/lora/,\
mac/region/RegionCommon.c \
mac/region/RegionEU868.c \
mac/region/RegionUS915.c \
mac/region/RegionCN470.c \
mac/region/RegionIN865.c \
system/delay.c \
system/gpio.c \
system/timer.c \
Expand Down Expand Up @@ -358,7 +360,7 @@ APP_LDFLAGS += $(LDFLAGS) -T esp32_out.ld -T esp32.common.ld -T esp32.rom.ld -T
# add the application specific CFLAGS
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\"
CFLAGS_SIGFOX += $(APP_INC) -DMICROPY_NLR_SETJMP=1 -DMBEDTLS_CONFIG_FILE='"mbedtls/esp_config.h"' -DHAVE_CONFIG_H -DESP_PLATFORM
CFLAGS += -DREGION_AS923 -DREGION_AU915 -DREGION_EU868 -DREGION_US915 -DBASE=0 -DPYBYTES=1
CFLAGS += -DREGION_AS923 -DREGION_AU915 -DREGION_EU868 -DREGION_US915 -DREGION_CN470 -DREGION_IN865 -DBASE=0 -DPYBYTES=1
# Specify if this is base or Pybytes Firmware
ifeq ($(VARIANT),BASE)
CFLAGS += -DVARIANT=0
Expand Down Expand Up @@ -456,7 +458,8 @@ ENTER_FLASHING_MODE = $(PIC_TOOL) --enter
EXIT_FLASHING_MODE = $(PIC_TOOL) --exit

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

ESPTOOLPY_WRITE_FLASH = $(ESPTOOLPY_SERIAL) write_flash -z --flash_mode $(ESPFLASHMODE) --flash_freq $(ESPFLASHFREQ) --flash_size $(FLASH_SIZE)
ESPTOOLPY_ERASE_FLASH = $(ESPTOOLPY_SERIAL) erase_flash
Expand Down
1 change: 1 addition & 0 deletions esp32/lora/sx1272-board.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ DRAM_ATTR const struct Radio_s Radio =
SX1272GetStatus,
SX1272SetModem,
SX1272SetChannel,
SX1272GetChannel,
SX1272IsChannelFree,
SX1272Random,
SX1272SetRxConfig,
Expand Down
1 change: 1 addition & 0 deletions esp32/lora/sx1276-board.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ DRAM_ATTR const struct Radio_s Radio =
SX1276GetStatus,
SX1276SetModem,
SX1276SetChannel,
SX1276GetChannel,
SX1276IsChannelFree,
SX1276Random,
SX1276SetRxConfig,
Expand Down
43 changes: 42 additions & 1 deletion esp32/mods/modlora.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
#include "lora/mac/region/RegionUS915.h"
#include "lora/mac/region/RegionUS915-Hybrid.h"
#include "lora/mac/region/RegionEU868.h"
#include "lora/mac/region/RegionCN470.h"
#include "lora/mac/region/RegionIN865.h"

// openThread includes
#ifdef LORA_OPENTHREAD_ENABLED
Expand Down Expand Up @@ -1317,6 +1319,20 @@ static void lora_validate_frequency (uint32_t frequency) {
goto freq_error;
}
break;
case LORAMAC_REGION_CN470:
#if defined(LOPY4)
if (frequency < 470000000 || frequency > 510000000) {
goto freq_error;
}
#else
goto freq_error;
#endif
break;
case LORAMAC_REGION_IN865:
if (frequency < 865000000 || frequency > 867000000) {
goto freq_error;
}
break;
case LORAMAC_REGION_EU868:
#if defined(LOPY4)
if (frequency < 410000000 || frequency > 870000000) {
Expand Down Expand Up @@ -1362,6 +1378,16 @@ static void lora_validate_channel (uint32_t index) {
goto channel_error;
}
break;
case LORAMAC_REGION_CN470:
if (index >= CN470_MAX_NB_CHANNELS) {
goto channel_error;
}
break;
case LORAMAC_REGION_IN865:
if (index >= IN865_MAX_NB_CHANNELS) {
goto channel_error;
}
break;
default:
break;
}
Expand All @@ -1383,6 +1409,8 @@ static bool lora_validate_data_rate (uint32_t data_rate) {
case LORAMAC_REGION_AS923:
case LORAMAC_REGION_EU868:
case LORAMAC_REGION_AU915:
case LORAMAC_REGION_CN470:
case LORAMAC_REGION_IN865:
if (data_rate > DR_6) {
return false;
}
Expand Down Expand Up @@ -1432,7 +1460,8 @@ static void lora_validate_device_class (DeviceClass_t device_class) {

static void lora_validate_region (LoRaMacRegion_t region) {
if (region != LORAMAC_REGION_AS923 && region != LORAMAC_REGION_AU915
&& region != LORAMAC_REGION_EU868 && region != LORAMAC_REGION_US915) {
&& region != LORAMAC_REGION_EU868 && region != LORAMAC_REGION_US915
&& region != LORAMAC_REGION_CN470 && region != LORAMAC_REGION_IN865) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "invalid region %d", region));
}
}
Expand Down Expand Up @@ -1653,6 +1682,10 @@ static mp_obj_t lora_init_helper(lora_obj_t *self, const mp_arg_val_t *args) {
case LORAMAC_REGION_EU868:
cmd_data.info.init.frequency = 868000000;
break;
case LORAMAC_REGION_CN470:
cmd_data.info.init.frequency = 470000000;
case LORAMAC_REGION_IN865:
cmd_data.info.init.frequency = 865000000;
default:
break;
}
Expand All @@ -1666,9 +1699,11 @@ static mp_obj_t lora_init_helper(lora_obj_t *self, const mp_arg_val_t *args) {
case LORAMAC_REGION_AS923:
case LORAMAC_REGION_AU915:
case LORAMAC_REGION_US915:
case LORAMAC_REGION_IN865:
case LORAMAC_REGION_US915_HYBRID:
cmd_data.info.init.tx_power = 20;
break;
case LORAMAC_REGION_CN470:
case LORAMAC_REGION_EU868:
cmd_data.info.init.tx_power = 14;
break;
Expand Down Expand Up @@ -1829,7 +1864,9 @@ STATIC mp_obj_t lora_join(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *
case LORAMAC_REGION_US915_HYBRID:
dr = DR_4;
break;
case LORAMAC_REGION_CN470:
case LORAMAC_REGION_EU868:
case LORAMAC_REGION_IN865:
dr = DR_5;
break;
default:
Expand Down Expand Up @@ -1860,6 +1897,7 @@ STATIC mp_obj_t lora_join(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *
goto dr_error;
}
break;
case LORAMAC_REGION_CN470:
case LORAMAC_REGION_EU868:
if (dr > DR_5) {
goto dr_error;
Expand Down Expand Up @@ -2406,6 +2444,8 @@ STATIC const mp_map_elem_t lora_locals_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_AU915), MP_OBJ_NEW_SMALL_INT(LORAMAC_REGION_AU915) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_EU868), MP_OBJ_NEW_SMALL_INT(LORAMAC_REGION_EU868) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_US915), MP_OBJ_NEW_SMALL_INT(LORAMAC_REGION_US915) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_CN470), MP_OBJ_NEW_SMALL_INT(LORAMAC_REGION_CN470) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_IN865), MP_OBJ_NEW_SMALL_INT(LORAMAC_REGION_IN865) },
};

STATIC MP_DEFINE_CONST_DICT(lora_locals_dict, lora_locals_dict_table);
Expand Down Expand Up @@ -2451,6 +2491,7 @@ static int lora_socket_socket (mod_network_socket_obj_t *s, int *_errno) {
switch (lora_obj.region) {
case LORAMAC_REGION_AS923:
case LORAMAC_REGION_EU868:
case LORAMAC_REGION_CN470:
dr = DR_5;
break;
case LORAMAC_REGION_AU915:
Expand Down
2 changes: 1 addition & 1 deletion esp32/pycom_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#ifndef VERSION_H_
#define VERSION_H_

#define SW_VERSION_NUMBER "1.20.0.rc11.1"
#define SW_VERSION_NUMBER "1.20.0.rc11.2"

#define LORAWAN_VERSION_NUMBER "1.0.2"

Expand Down
3 changes: 2 additions & 1 deletion lib/lora/mac/LoRaMac.c
Original file line number Diff line number Diff line change
Expand Up @@ -2222,7 +2222,8 @@ LoRaMacStatus_t SendFrameOnChannel( uint8_t channel )
McpsConfirm.Status = LORAMAC_EVENT_INFO_STATUS_ERROR;
McpsConfirm.Datarate = LoRaMacParams.ChannelsDatarate;
McpsConfirm.TxPower = txPower;

McpsConfirm.UpLinkFrequency = Radio.GetChannel();

// Store the time on air
McpsConfirm.TxTimeOnAir = TxTimeOnAir;
MlmeConfirm.TxTimeOnAir = TxTimeOnAir;
Expand Down
25 changes: 24 additions & 1 deletion lib/lora/mac/region/Region.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ Maintainer: Miguel Luis ( Semtech ), Gregory Cristian ( Semtech ) and Daniel Jae
#include "Region.h"



// Setup regions
#ifdef REGION_AS923
#include "RegionAS923.h"
Expand Down Expand Up @@ -182,8 +181,11 @@ Maintainer: Miguel Luis ( Semtech ), Gregory Cristian ( Semtech ) and Daniel Jae
#define CN470_NEXT_CHANNEL( ) CN470_CASE { return RegionCN470NextChannel( nextChanParams, channel, time, aggregatedTimeOff ); }
#define CN470_CHANNEL_ADD( ) CN470_CASE { return RegionCN470ChannelAdd( channelAdd ); }
#define CN470_CHANNEL_REMOVE( ) CN470_CASE { return RegionCN470ChannelsRemove( channelRemove ); }
#define CN470_CHANNEL_MANUAL_ADD( ) CN470_CASE { return RegionCN470ChannelManualAdd( channelAdd ); }
#define CN470_CHANNEL_MANUAL_REMOVE( ) CN470_CASE { return RegionCN470ChannelsRemove( channelRemove ); }
#define CN470_SET_CONTINUOUS_WAVE( ) CN470_CASE { RegionCN470SetContinuousWave( continuousWave ); break; }
#define CN470_APPLY_DR_OFFSET( ) CN470_CASE { return RegionCN470ApplyDrOffset( downlinkDwellTime, dr, drOffset ); }
#define CN470_FORCE_JOIN_DATARATE( ) CN470_CASE { return RegionCN470ForceJoinDataRate( joinDr, alternateDr ); }
#else
#define CN470_IS_ACTIVE( )
#define CN470_GET_PHY_PARAM( )
Expand All @@ -206,8 +208,11 @@ Maintainer: Miguel Luis ( Semtech ), Gregory Cristian ( Semtech ) and Daniel Jae
#define CN470_NEXT_CHANNEL( )
#define CN470_CHANNEL_ADD( )
#define CN470_CHANNEL_REMOVE( )
#define CN470_CHANNEL_MANUAL_ADD( )
#define CN470_CHANNEL_MANUAL_REMOVE( )
#define CN470_SET_CONTINUOUS_WAVE( )
#define CN470_APPLY_DR_OFFSET( )
#define CN470_FORCE_JOIN_DATARATE( )
#endif

#ifdef REGION_CN779
Expand Down Expand Up @@ -452,8 +457,13 @@ Maintainer: Miguel Luis ( Semtech ), Gregory Cristian ( Semtech ) and Daniel Jae
#define IN865_NEXT_CHANNEL( ) IN865_CASE { return RegionIN865NextChannel( nextChanParams, channel, time, aggregatedTimeOff ); }
#define IN865_CHANNEL_ADD( ) IN865_CASE { return RegionIN865ChannelAdd( channelAdd ); }
#define IN865_CHANNEL_REMOVE( ) IN865_CASE { return RegionIN865ChannelsRemove( channelRemove ); }
#define IN865_CHANNEL_MANUAL_ADD( ) IN865_CASE { return RegionIN865ChannelManualAdd( channelAdd ); }
#define IN865_CHANNEL_MANUAL_REMOVE( ) IN865_CASE { return RegionIN865ChannelsRemove( channelRemove ); }
#define IN865_SET_CONTINUOUS_WAVE( ) IN865_CASE { RegionIN865SetContinuousWave( continuousWave ); break; }
#define IN865_APPLY_DR_OFFSET( ) IN865_CASE { return RegionIN865ApplyDrOffset( downlinkDwellTime, dr, drOffset ); }
#define IN865_GET_CHANNELS( ) IN865_CASE { return RegionIN865GetChannels( channels, size ); }
#define IN865_GET_CHANNEL_MASK( ) IN865_CASE { return RegionIN865GetChannelMask( channelmask, size ); }
#define IN865_FORCE_JOIN_DATARATE( ) IN865_CASE { return RegionIN865ForceJoinDataRate( joinDr, alternateDr ); }
#else
#define IN865_IS_ACTIVE( )
#define IN865_GET_PHY_PARAM( )
Expand All @@ -476,8 +486,13 @@ Maintainer: Miguel Luis ( Semtech ), Gregory Cristian ( Semtech ) and Daniel Jae
#define IN865_NEXT_CHANNEL( )
#define IN865_CHANNEL_ADD( )
#define IN865_CHANNEL_REMOVE( )
#define IN865_CHANNEL_MANUAL_ADD( )
#define IN865_CHANNEL_MANUAL_REMOVE( )
#define IN865_SET_CONTINUOUS_WAVE( )
#define IN865_APPLY_DR_OFFSET( )
#define IN865_GET_CHANNELS( )
#define IN865_GET_CHANNEL_MASK( )
#define IN865_FORCE_JOIN_DATARATE( )
#endif

#ifdef REGION_US915
Expand Down Expand Up @@ -1037,6 +1052,8 @@ LoRaMacStatus_t RegionChannelManualAdd( LoRaMacRegion_t region, ChannelAddParams
AU915_CHANNEL_MANUAL_ADD( );
EU868_CHANNEL_MANUAL_ADD( );
US915_CHANNEL_MANUAL_ADD( );
CN470_CHANNEL_MANUAL_ADD( );
IN865_CHANNEL_MANUAL_ADD( );
US915_HYBRID_CHANNEL_MANUAL_ADD( );
default:
{
Expand Down Expand Up @@ -1074,6 +1091,8 @@ bool RegionChannelsManualRemove( LoRaMacRegion_t region, ChannelRemoveParams_t*
AU915_CHANNEL_MANUAL_REMOVE( );
EU868_CHANNEL_MANUAL_REMOVE( );
US915_CHANNEL_MANUAL_REMOVE( );
CN470_CHANNEL_MANUAL_REMOVE( );
IN865_CHANNEL_MANUAL_REMOVE( );
US915_HYBRID_CHANNEL_MANUAL_REMOVE( );
default:
{
Expand Down Expand Up @@ -1131,6 +1150,7 @@ bool RegionGetChannels( LoRaMacRegion_t region, ChannelParams_t** channels, uint
AS923_GET_CHANNELS( );
AU915_GET_CHANNELS( );
EU868_GET_CHANNELS( );
IN865_GET_CHANNELS( );
US915_GET_CHANNELS( );
US915_HYBRID_GET_CHANNELS( );
default:
Expand All @@ -1146,6 +1166,7 @@ bool RegionGetChannelMask(LoRaMacRegion_t region, uint16_t **channelmask, uint32
AS923_GET_CHANNEL_MASK( );
AU915_GET_CHANNEL_MASK( );
EU868_GET_CHANNEL_MASK( );
IN865_GET_CHANNEL_MASK( );
US915_GET_CHANNEL_MASK( );
US915_HYBRID_GET_CHANNEL_MASK( );
default:
Expand Down Expand Up @@ -1176,6 +1197,8 @@ bool RegionForceJoinDataRate( LoRaMacRegion_t region, int8_t joinDr, AlternateDr
AU915_FORCE_JOIN_DATARATE( );
EU868_FORCE_JOIN_DATARATE( );
US915_FORCE_JOIN_DATARATE( );
CN470_FORCE_JOIN_DATARATE( );
IN865_FORCE_JOIN_DATARATE( );
US915_HYBRID_FORCE_JOIN_DATARATE( );
default:
{
Expand Down
Loading

1 comment on commit 976af3b

@robert-hh
Copy link
Contributor

@robert-hh robert-hh commented on 976af3b Jun 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has the same omission as the trial build I made for EU433: it allows setting of CN470 even for Fipy and Lopy, where it is not physically supported. That all follows the define of REGION_CN470, which is only to be set for LOPY4. In my EU433 build I was too lazy to put all the #ifdef's in the code, but at least the QSTR for CN470 should be masked. The LORA stack itself has a lot of #ifdefs for the region. So if REGION_CN470 is not set, the code will not compiled.
Edit: Not that changing modlora.c has not too much effect on the code size. Just omitting the CN470 symbol saves 16 byte, and #ifdef'ing the whole file save another 12(!) bytes. So for code size saving it may be not too important, but excluding the symbol avoids irritation. (and obviously: adding -DREGION_CN470 in application.mk for LoPy4 only).

Please sign in to comment.