Arduino LMIC 6.0.1
Arduino LoRaWAN(r) MAC in C
Loading...
Searching...
No Matches
oslmic.h File Reference
#include "config.h"
#include "lmic_env.h"
#include "oslmic_types.h"
#include <string.h>
#include "hal.h"
#include <inttypes.h>
Include dependency graph for oslmic.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  osjob_t
struct  oslmic_radio_rssi_s

Macros

#define os_clearMem(pDest, nDest)
 Clear buffer.
#define os_copyMem(pDest, pSrc, nSrc)
 Copy buffer.
#define os_getRndU2()
 Get random number (default impl for u2_t).
#define RX_RAMPUP_DEFAULT   (us2osticks(10000))
 RX_RAMPUP_DEFAULT specifies the extra time we must allow to set up an RX event due to platform issues. It's specified in units of ostime_t. It must reflect platform jitter and latency, as well as the speed of the LMIC when running on this plaform. It's not used directly; clients call os_getRadioRxRampup(), which might adaptively vary this based on observed timeouts.

Typedefs

typedef osjobcbfn_tosjobcb_t
 the pointer-to-function for osjob_t callbacks
typedef void osjobcbfn_t(struct osjob_t *)
 the function type for osjob_t callbacks

Functions

bit_t os_queryTimeCriticalJobs (ostime_t time)
 Return non-zero if any jobs are scheduled between now and now+time.
u2_t os_rlsbf2 (xref2cu1_t buf)
 Read 16-bit quantity from given pointer in little endian byte order.
u4_t os_rlsbf4 (xref2cu1_t buf)
 Read 32-bit quantity from given pointer in little endian byte order.
u4_t os_rmsbf4 (xref2cu1_t buf)
 Read 32-bit quantity from given pointer in big endian byte order.
bit_t os_setIdleJobFunction (osjob_t *job, osjobcb_t cb)
 set function in idle job (for future use)
void os_wlsbf2 (xref2u1_t buf, u2_t value)
 Write 16-bit quantity into buffer in little endian byte order.
void os_wlsbf4 (xref2u1_t buf, u4_t value)
 Write 32-bit quantity into buffer in little endian byte order.
void os_wmsbf4 (xref2u1_t buf, u4_t value)
 Write 32-bit quantity into buffer in big endian byte order.
int radio_init (void)
 Initialize radio at system startup.
void radio_irq_handler (u1_t dio)
 legacy radio IRQ handler
void radio_irq_handler_v2 (u1_t dio, ostime_t tref)
 Radio IRQ handler.
void radio_monitor_rssi (ostime_t n, oslmic_radio_rssi_t *pRssi)
 Measure the current broadband RSSI for the current channel.
u1_t radio_rand1 (void)
 Generate an 8-bit uniformly-distributed integer.

Macro Definition Documentation

◆ os_copyMem

#define os_copyMem ( pDest,
pSrc,
nSrc )
Value:
memcpy(pDest,pSrc,nSrc)

Copy buffer.

Parameters
pDest[out] receives data to be copied
pSrc[in] source of data
nSrc[in] number of bytes of data
Note
Buffers must be non-overlapping. Pointers must be non-NULL.

Referenced by LMIC_SecureElement_Default_aes128Encrypt(), LMIC_SecureElement_Default_decodeJoinAccept(), LMIC_SecureElement_Default_decodeMessage(), LMIC_SecureElement_Default_encodeMessage(), LMIC_SecureElement_Default_getAppSKey(), LMIC_SecureElement_Default_getNwkSKey(), and LMIC_setSession().

Function Documentation

◆ os_setIdleJobFunction()

bit_t os_setIdleJobFunction ( osjob_t * job,
osjobcb_t cb )

set function in idle job (for future use)

Parameters
[in,out]jobpoints to the job block to be updated.
[in]cbis the desired new callback.

We make sure that the job is idle, and then we set its function pointer. If the job was not idle, we log a message.

◆ radio_init()

int radio_init ( void )

Initialize radio at system startup.

This procedure is called during initialization by the os_init() routine. It does a hardware reset of the radio, checks the version and confirms that we're operating a suitable chip, and gets a random seed from wideband noise rssi. It then puts the radio to sleep.

Returns
True if successful, false if it doesn't look like the right radio is attached.
Precondition

Preconditions must be observed, or you'll get hangs during initialization.

  • The lmic_hal_pin_..() functions must be ready for use.
  • The lmic_hal_waitUntl() function must be ready for use. This may mean that interrupts are enabled.
  • The lmic_hal_spi_..() functions must be ready for use.

Generally, all these are satisfied by a call to lmic_hal_init_with_pinmap().

◆ radio_irq_handler()

void radio_irq_handler ( u1_t dio)

legacy radio IRQ handler

Parameters
[in]diois the image of the DIO0..n pins observed by the primary ISR.

The HAL is responsible for detecting transitions on the SX127x DIO pins, and scheduling this routine. This routine must run as part of os_runloop_once(); it must not be called directly from a primary ISR.

This routine is for legacy use only; it is for use by older HALs that cannot capture the interrupt time in the primary ISR.

See also
radio_irq_handler_v2

References radio_irq_handler_v2().

◆ radio_irq_handler_v2()

void radio_irq_handler_v2 ( u1_t dio,
ostime_t now )

Radio IRQ handler.

Parameters
[in]diois the image of the DIO0..n pins observed by the primary ISR.
[in]nowis the HALs best estimate of the time of teh interrupt.

The HAL is responsible for detecting transitions on the SX127x DIO pins, and scheduling this routine. This routine must run as part of os_runloop_once(); it must not be called directly from a primary ISR.

The radio registers are interrogated, and the interrupt is processed. The radio is then put back to sleep, and the background is scheduled.

Note
If continuous transmit mode is configured, then this routine immediately schedules a new transmit, and never completes to the background.
See also
radio_irq_handler_v2

References LMIC_RADIO_EV_NONE, LMIC_RADIO_EV_RXDONE, LMIC_RADIO_EV_RXTIMEOUT, LMIC_RADIO_EV_RXUNKNOWN, LMIC_RADIO_EV_TXDONE, and LMIC_RADIO_EV_TXUNKNOWN.

Referenced by radio_irq_handler().

◆ radio_monitor_rssi()

void radio_monitor_rssi ( ostime_t nTicks,
oslmic_radio_rssi_t * pRssi )

Measure the current broadband RSSI for the current channel.

This funtion monitors RSSI for specified number of ostime_t ticks, and return statistics. It first puts the radio into RX continuous mode, waits long enough for the oscillators to start and the PLL to lock, and then measures for the specified period of time. The radio is then returned to idle.

Returns
RSSI expressed in units of dB, offset according to the current radio setting per section 5.5.5 of Semtech 1276 datasheet.
Parameters
nTicksHow long to monitor
pRssipointer to structure to fill in with RSSI data.

◆ radio_rand1()

u1_t radio_rand1 ( void )

Generate an 8-bit uniformly-distributed integer.

If there are any bytes remaining in the random buffer, the next byte is returned. Otherwise, sixteen new random bytes are generated, and the first is returned.

Implmementation Notes:
Originaly, the seed buffer was held in the static randbuf[], which is initialized with RSSI noise measurements during initialization. Each time we run out of data, the buffer is used to generate a new key. Formerly we used "any key" but with the reorganization of the code, there's no dedicated key buffer. So instead, we save the seed, and do a CSPRNG using AES in counter mode. Since (in any case) we immediately return the first byte of the buffer, we can replace the first byte with a buffer index, ranging from 1 to 16, which helps us to dole out the data.

References os_wlsbf4().