Skip to content

Commit

Permalink
refactored MBED radio class
Browse files Browse the repository at this point in the history
- CMWX1ZZABZ now aggregates rather than inherits SX1276
- CMWX1ZZABZ now had its own SPI object and uses fixed pin names (since
these connections are fixed)
- updated examples/bare_mbed to suit CMWX1ZZABZ changes
  • Loading branch information
cjhdev committed Oct 28, 2020
1 parent 1d8989e commit 597630c
Show file tree
Hide file tree
Showing 16 changed files with 898 additions and 488 deletions.
3 changes: 2 additions & 1 deletion .mbedignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ pclint/*
secrets/*
test/*
vendor/*
wrappers/arduino/*
wrappers/ruby/*
examples/*
tmp/*
15 changes: 5 additions & 10 deletions examples/bare_mbed/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ const uint8_t nwk_key[] = MBED_CONF_APP_NWK_KEY;
const uint8_t dev_eui[] = MBED_CONF_APP_DEV_EUI;
const uint8_t join_eui[] = MBED_CONF_APP_JOIN_EUI;

/* pin mapping for the DISCO_L072CZ_LRWAN1 */
SPI spi(PA_7, PA_6, PB_3);

LDL::DefaultSM sm(app_key, nwk_key);

LDL::DefaultStore store(dev_eui, join_eui);
Expand All @@ -24,14 +21,12 @@ int main()
{
mbed_trace_init();

/* PA_12 is where the reference design puts the TCXO on/off
* control line, and also where you will find it on the LRWAN
* kit.
*
* */
static LDL::CMWX1ZZABZ radio(
spi,
PA_15, // nss
PC_0, // reset
PB_4, PB_1, // DIO0, DIO1
PC_1, // enable_boost
PC_2, // enable_rfo
PA_1, // enable_rfi
PA_12 // enable_tcxo
);

Expand Down
15 changes: 14 additions & 1 deletion examples/bare_mbed/readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
This example runs shows how to run LDL::MAC on MBED with the bare metal
profile.

The target in this case is expected to be the DISCO_L072CZ_LRWAN1.
The target in this case is expected to be the DISCO_L072CZ_LRWAN1 which
features the Murata ABZ module.

The wrapper for this module takes care of all the connections for you,
the only option left to the integrator is which pin to use to switch
TCXO. On the DISCO_L072CZ_LRWAN1 the default pin for controlling TCXO is PA_12
but this can be moved using jumper wire.

If you are using this module on bespoke hardware, make sure you have completed
the pin map correctly and used the STM32 names (e.g. PA_12).




4 changes: 3 additions & 1 deletion history.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Note that versions are only "released" when there is a git tag with the same nam
If you have checked out master, the top version listed here may be a
work in progress.

## 0.4.5 (WIP)
## 0.4.5

- changed LDL_DEBUG, LDL_INFO, LDL_ERROR to not insert __FUNCTION__ into format string
- changed LDL_DEBUG, LDL_INFO, LDL_ERROR to not take APP argument
Expand Down Expand Up @@ -36,6 +36,8 @@ work in progress.
- added option of defining ldl_mac_init_arg.a at compile time with LDL_PARAM_A
- added option of defining ldl_mac_init_arg.b at compile time with LDL_PARAM_B
- added option of defining ldl_mac_init_arg.advance at compile time with LDL_PARAM_ADVANCE
- refactored MBED radio wrapper so that CMWX1ZZABZ aggregates rather than inherits SX1276
- refactored CMWX1ZZABZ driver to use fixed pin mapping (since it is fixed) which further simplifies its use

## 0.4.4

Expand Down
119 changes: 119 additions & 0 deletions wrappers/mbed/cmwx1zzabz.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/* Copyright (c) 2020 Cameron Harper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* */

#include "cmwx1zzabz.h"
#include "ldl_system.h"
#include "ldl_radio.h"

using namespace LDL;

/* constructors *******************************************************/

CMWX1ZZABZ::CMWX1ZZABZ(
PinName enable_tcxo,
int16_t tx_gain
)
:
Radio(),
spi(PA_7, PA_6, PB_3),
enable_boost(PC_1, 0),
enable_rfo(PC_2, 0),
enable_rfi(PA_1, 0),
enable_tcxo(enable_tcxo, PIN_INPUT, PullNone, 1),
radio(
spi,
PA_15, // nss
PC_0, // reset
PB_4, PB_1, NC, NC, NC, NC, // DIO0, DIO1, DIO2, DIO3, DIO4, DIO5
LDL_RADIO_PA_AUTO,
tx_gain,
LDL_RADIO_XTAL_TCXO,
10UL,
callback(this, &CMWX1ZZABZ::set_mode)
)
{
/* ensure that radio events can make it out of the real driver */
radio.set_event_handler(callback(this, &CMWX1ZZABZ::handle_event));
}

/* protected **********************************************************/

void
CMWX1ZZABZ::handle_event(enum ldl_radio_event event)
{
_interrupt_handler((struct ldl_mac *)this, event);
}

void
CMWX1ZZABZ::set_mode(enum ldl_chip_mode mode)
{
/* we don't manpulate reset since that is the
* domain of the radio driver and not of the module */
switch(mode){
case LDL_CHIP_MODE_RESET:
enable_rfi = 0;
enable_rfo = 0;
enable_boost = 0;
enable_tcxo.input();
break;
case LDL_CHIP_MODE_SLEEP:
enable_rfi = 0;
enable_rfo = 0;
enable_boost = 0;
enable_tcxo.input();
break;
case LDL_CHIP_MODE_STANDBY:
enable_rfi = 0;
enable_rfo = 0;
enable_boost = 0;
enable_tcxo.output();
break;
case LDL_CHIP_MODE_RX:
enable_rfi = 1;
enable_rfo = 0;
enable_boost = 0;
break;
case LDL_CHIP_MODE_TX_BOOST:
enable_rfi = 0;
enable_rfo = 0;
enable_boost = 1;
break;
case LDL_CHIP_MODE_TX_RFO:
enable_rfi = 0;
enable_rfo = 1;
enable_boost = 0;
break;
}
}

/* public *************************************************************/

Radio *
CMWX1ZZABZ::get_state()
{
return radio.get_state();
}

const struct ldl_radio_interface *
CMWX1ZZABZ::get_interface()
{
return radio.get_interface();
}
69 changes: 69 additions & 0 deletions wrappers/mbed/cmwx1zzabz.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/* Copyright (c) 2020 Cameron Harper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* */

#ifndef MBED_LDL_CMWX1ZZABZ_H
#define MBED_LDL_CMWX1ZZABZ_H

#include "sx1276.h"

namespace LDL {

/**
* A module that aggregates:
*
* - SX1276
* - TCXO with power switch
* - switches for engaging RFI, RFO, and BOOST
* - dedicated SPI peripheral
*
* Inherits radio so that it can be passed to the MAC.
*
* */
class CMWX1ZZABZ : public Radio {

protected:

SPI spi;

DigitalOut enable_boost;
DigitalOut enable_rfo;
DigitalOut enable_rfi;
DigitalInOut enable_tcxo;

SX1276 radio;

void set_mode(enum ldl_chip_mode mode);

void handle_event(enum ldl_radio_event event);

public:

CMWX1ZZABZ(
PinName enable_tcxo,
int16_t tx_gain = 0
);

const struct ldl_radio_interface *get_interface();
Radio *get_state();
};
};

#endif
4 changes: 2 additions & 2 deletions wrappers/mbed/mac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ MAC::start(enum ldl_region region)
arg.app = this;
arg.handler = app_handler;

arg.radio = (struct ldl_radio *)(&radio);
arg.radio_interface = &radio.interface;
arg.radio = (struct ldl_radio *)radio.get_state();
arg.radio_interface = radio.get_interface();

arg.sm = (struct ldl_sm *)(&sm);
arg.sm_interface = &sm.interface;
Expand Down
4 changes: 3 additions & 1 deletion wrappers/mbed/mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
#include "ldl_mac.h"
#include "ldl_system.h"

#include "radio.h"
#include "sx1272.h"
#include "sx1276.h"
#include "cmwx1zzabz.h"
#include "sm.h"
#include "store.h"

Expand Down
Loading

0 comments on commit 597630c

Please sign in to comment.