ruuvi.drivers.c  ${PROJECT_VERSION}
Drivers for external sensors and peripherals on embedded systems.
Radio operations.

Files

file  ruuvi_interface_communication_radio_test.h
 

Data Structures

struct  ri_radio_channels_t
 Bitfield to describe related sensor data. More...
 

Typedefs

typedef void(* ri_radio_activity_interrupt_fp_t) (const ri_radio_activity_evt_t evt)
 Type of radio activity interrupt. This is common to all radio modules, i,e, the callback gets called for every radio action. More...
 

Enumerations

enum  ri_radio_activity_evt_t { RI_RADIO_BEFORE , RI_RADIO_AFTER }
 radio activity event type. More...
 
enum  ri_radio_modulation_t { RI_RADIO_BLE_125KBPS , RI_RADIO_BLE_1MBPS , RI_RADIO_BLE_2MBPS }
 type of radio modulation to be used. More...
 

Functions

bool ri_communication_radio_run_integration_test (const rd_test_print_fp printfp)
 
void print_modulation (const rd_test_print_fp printfp, const ri_radio_modulation_t modulation)
 Print used modulation to printfp. More...
 
uint8_t ri_radio_num_channels_get (const ri_radio_channels_t channels)
 Check how many radio channels are enabled. More...
 
bool ri_radio_supports (ri_radio_modulation_t modulation)
 Check if radio supports given modulation. More...
 
rd_status_t ri_radio_init (const ri_radio_modulation_t modulation)
 Enable radio stack for an user. This function also starts radio activity callbacks internally. More...
 
rd_status_t ri_radio_uninit ()
 Release radio stack. More...
 
rd_status_t ri_radio_address_get (uint64_t *const address)
 
rd_status_t ri_radio_address_set (uint64_t const address)
 
void ri_radio_activity_callback_set (const ri_radio_activity_interrupt_fp_t handler)
 Setup radio activity interrupt. More...
 
bool ri_radio_is_init ()
 Check if radio is initialized. More...
 
rd_status_t ri_radio_get_modulation (ri_radio_modulation_t *const p_modulation)
 Get the modulation used by application. More...
 

Detailed Description

Typedef Documentation

◆ ri_radio_activity_interrupt_fp_t

typedef void(* ri_radio_activity_interrupt_fp_t) (const ri_radio_activity_evt_t evt)

Type of radio activity interrupt. This is common to all radio modules, i,e, the callback gets called for every radio action.

Parameters
[in]evtType of radio event

Definition at line 63 of file ruuvi_interface_communication_radio.h.

Enumeration Type Documentation

◆ ri_radio_activity_evt_t

radio activity event type.

Enumerator
RI_RADIO_BEFORE 

Event is before radio goes active, i.e. radio turns on soon.

RI_RADIO_AFTER 

Event is after radio activity, i.e. radio was turned off.

Definition at line 30 of file ruuvi_interface_communication_radio.h.

◆ ri_radio_modulation_t

type of radio modulation to be used.

Enumerator
RI_RADIO_BLE_125KBPS 

Also known as BLE Long Range S=8.

RI_RADIO_BLE_1MBPS 

"Normal" BLE 4 modulation

RI_RADIO_BLE_2MBPS 

"Fast BLE". Advertising uses 1MBPS primary advertisement followed by 2 MBit/s extended advertisement.

Definition at line 39 of file ruuvi_interface_communication_radio.h.

Function Documentation

◆ print_modulation()

void print_modulation ( const rd_test_print_fp  printfp,
const ri_radio_modulation_t  modulation 
)

Print used modulation to printfp.

Example:

Parameters
[in]printfpFunction which accepts a char* message string to print.
[in]modulationModulation to print.

◆ ri_communication_radio_run_integration_test()

bool ri_communication_radio_run_integration_test ( const rd_test_print_fp  printfp)

◆ ri_radio_activity_callback_set()

void ri_radio_activity_callback_set ( const ri_radio_activity_interrupt_fp_t  handler)

Setup radio activity interrupt.

This function allows driver to notify application on all radio activity.

Parameters
[in]handlerFunction to call on radio event. Set to NULL to disable radio-level callback.

◆ ri_radio_address_get()

rd_status_t ri_radio_address_get ( uint64_t *const  address)

Writes maximum 64-bit unique address of the device to the pointer. This address may be changed during runtime. The address is identifier of the device on radio network, such as BLE MAC address.

Parameters
[out]addressValue of radio address, i.e. MAC address.
Return values
RD_SUCCESSon success
RD_ERROR_NOT_SUPPORTEDif address cannot be returned on given platform

◆ ri_radio_address_set()

rd_status_t ri_radio_address_set ( uint64_t const  address)

Configures maximum 64-bit unique address of the device to the radio. The address is identifier of the device on radio network, such as BLE MAC address.

Parameters
[in]addressAddress to configure, MSB first.
Return values
RD_SUCCESSon success.
RD_ERROR_NOT_SUPPORTEDif address cannot be configured on given platform.
RD_ERROR_INVALID_ADDRif the address does not match protocol rules and cannot or is not converted automatically.
RD_ERRO_BUSYif radio stack is doing some other operation, try later.
RD_ERROR_INVALID_STATEif radio is in state where address is required, such as advertising, connected or scanning.
Note
The implementation is allowed to enforce protocol rules, for example BLE MAC will be masked with 0x00 00 [0b11xx]X XX XX XX XX XX XX and sent LSB first.

◆ ri_radio_get_modulation()

rd_status_t ri_radio_get_modulation ( ri_radio_modulation_t *const  p_modulation)

Get the modulation used by application.

Modulation is decided at initialization and used by all radio modules. However, other modules are allowed to switch to other modulation as a part of their operation, for example GATT can use 1 MBit/s when setting up connection and negotiate 2 MBit/s for the remainder of connection.

Parameters
[out]p_modulationModulation used by default.
Return values
RD_SUCCESSif modulation was written to pointer
RD_ERROR_NULLif p_modulation is NULL
RD_ERROR_INVALID_STATEif radio is not initialized.

◆ ri_radio_init()

rd_status_t ri_radio_init ( const ri_radio_modulation_t  modulation)

Enable radio stack for an user. This function also starts radio activity callbacks internally.

Parameters
[in]modulationModulation for radio operations. If 2 MBPS is defined, primary advertising PHY is 1 MBPS and secondary PHY is 2 MBPS. Note: if other end of communication requests different speed, the implementation should support it if applicable to board.
Return values
RD_SUCCESSon success
RD_ERROR_INVALID_STATEif radio is already initialized.
RD_ERROR_INVALID_PARAMif trying to initialize radio with unsupported modulation.

◆ ri_radio_is_init()

bool ri_radio_is_init ( )

Check if radio is initialized.

Returns
true if radio is initialized, false otherwise.

◆ ri_radio_num_channels_get()

uint8_t ri_radio_num_channels_get ( const ri_radio_channels_t  channels)

Check how many radio channels are enabled.

Parameters
[in]channelsStructure with enabled channels.
Returns
Number of enabled channels.

◆ ri_radio_supports()

bool ri_radio_supports ( ri_radio_modulation_t  modulation)

Check if radio supports given modulation.

Parameters
[in]modulationModulation to check.
Return values
trueIf given modulation is supported by radio.
falseIf given modulation is not supported by radio.

◆ ri_radio_uninit()

rd_status_t ri_radio_uninit ( )

Release radio stack.

This function also stops the internal radio activity callbacks

Return values
RD_SUCCESSon success
RD_ERROR_FORBIDDENif radio is in use by other user
Note
It's not possible to uninitialize radio from another user than original initializer.