Contiki 2.6

RF230 interface

Files

file  rf230bb.h
 

This file contains radio driver code.


file  radio.c
 

This file contains radio driver code.


file  radio.h
 

This file contains radio driver code.


Defines

#define RF230_MAX_TX_FRAME_LENGTH   ( 127 )
 127 Byte PSDU.
#define RADIO_STATUS_START_VALUE   ( 0x40 )
 This macro defines the start value for the RADIO_* status constants.
#define RADIO_CCA_DONE_MASK   (1 << 7)
 Mask used to check the CCA_DONE bit.
#define RADIO_CCA_IDLE_MASK   (1 << 6)
 Mask used to check the CCA_STATUS bit.
#define RADIO_START_CCA   (1)
 Value in the CCA_REQUEST subregister that initiate a cca.
#define RF230_MAX_TX_FRAME_LENGTH   ( 127 )
 127 Byte PSDU.
#define RADIO_STATUS_START_VALUE   ( 0x40 )
 This macro defines the start value for the RADIO_* status constants.

Enumerations

enum  radio_status_t {
  RADIO_SUCCESS = RADIO_STATUS_START_VALUE, RADIO_UNSUPPORTED_DEVICE, RADIO_INVALID_ARGUMENT, RADIO_TIMED_OUT,
  RADIO_WRONG_STATE, RADIO_BUSY_STATE, RADIO_STATE_TRANSITION_FAILED, RADIO_CCA_IDLE,
  RADIO_CCA_BUSY, RADIO_TRX_BUSY, RADIO_BAT_LOW, RADIO_BAT_OK,
  RADIO_CRC_FAILED, RADIO_CHANNEL_ACCESS_FAILURE, RADIO_NO_ACK, RADIO_SUCCESS = RADIO_STATUS_START_VALUE,
  RADIO_UNSUPPORTED_DEVICE, RADIO_INVALID_ARGUMENT, RADIO_TIMED_OUT, RADIO_WRONG_STATE,
  RADIO_BUSY_STATE, RADIO_STATE_TRANSITION_FAILED, RADIO_CCA_IDLE, RADIO_CCA_BUSY,
  RADIO_TRX_BUSY, RADIO_BAT_LOW, RADIO_BAT_OK, RADIO_CRC_FAILED,
  RADIO_CHANNEL_ACCESS_FAILURE, RADIO_NO_ACK
}
 

This enumeration defines the possible return values for the TAT API functions.

More...
enum  radio_cca_mode_t {
  CCA_ENERGY_DETECT = 0, CCA_CARRIER_SENSE = 1, CCA_CARRIER_SENSE_WITH_ED = 2, CCA_ED = 0,
  CCA_CARRIER_SENSE = 1, CCA_CARRIER_SENSE_WITH_ED = 2
}
 

This enumeration defines the possible modes available for the Clear Channel Assessment algorithm.

More...
enum  radio_clkm_speed_t
 

This enumeration defines the possible CLKM speeds.

More...
enum  radio_trx_timing_t {
  TIME_TO_ENTER_P_ON = 510, TIME_P_ON_TO_TRX_OFF = 510, TIME_SLEEP_TO_TRX_OFF = 880, TIME_RESET = 6,
  TIME_ED_MEASUREMENT = 140, TIME_CCA = 140, TIME_PLL_LOCK = 150, TIME_FTN_TUNING = 25,
  TIME_NOCLK_TO_WAKE = 6, TIME_CMD_FORCE_TRX_OFF = 1, TIME_TRX_OFF_TO_PLL_ACTIVE = 180, TIME_STATE_TRANSITION_PLL_ACTIVE = 1,
  TIME_TO_ENTER_P_ON = 510, TIME_P_ON_TO_TRX_OFF = 510, TIME_SLEEP_TO_TRX_OFF = 880, TIME_RESET = 6,
  TIME_ED_MEASUREMENT = 140, TIME_CCA = 140, TIME_PLL_LOCK = 150, TIME_FTN_TUNING = 25,
  TIME_NOCLK_TO_WAKE = 6, TIME_CMD_FORCE_TRX_OFF = 1, TIME_TRX_OFF_TO_PLL_ACTIVE = 180, TIME_STATE_TRANSITION_PLL_ACTIVE = 1
}
 

This enumeration defines the necessary timing information for the AT86RF230 radio transceiver.

More...
enum  radio_status_t {
  RADIO_SUCCESS = RADIO_STATUS_START_VALUE, RADIO_UNSUPPORTED_DEVICE, RADIO_INVALID_ARGUMENT, RADIO_TIMED_OUT,
  RADIO_WRONG_STATE, RADIO_BUSY_STATE, RADIO_STATE_TRANSITION_FAILED, RADIO_CCA_IDLE,
  RADIO_CCA_BUSY, RADIO_TRX_BUSY, RADIO_BAT_LOW, RADIO_BAT_OK,
  RADIO_CRC_FAILED, RADIO_CHANNEL_ACCESS_FAILURE, RADIO_NO_ACK, RADIO_SUCCESS = RADIO_STATUS_START_VALUE,
  RADIO_UNSUPPORTED_DEVICE, RADIO_INVALID_ARGUMENT, RADIO_TIMED_OUT, RADIO_WRONG_STATE,
  RADIO_BUSY_STATE, RADIO_STATE_TRANSITION_FAILED, RADIO_CCA_IDLE, RADIO_CCA_BUSY,
  RADIO_TRX_BUSY, RADIO_BAT_LOW, RADIO_BAT_OK, RADIO_CRC_FAILED,
  RADIO_CHANNEL_ACCESS_FAILURE, RADIO_NO_ACK
}
 

This enumeration defines the possible return values for the TAT API functions.

More...
enum  radio_cca_mode_t {
  CCA_ENERGY_DETECT = 0, CCA_CARRIER_SENSE = 1, CCA_CARRIER_SENSE_WITH_ED = 2, CCA_ED = 0,
  CCA_CARRIER_SENSE = 1, CCA_CARRIER_SENSE_WITH_ED = 2
}
 

This enumeration defines the possible modes available for the Clear Channel Assessment algorithm.

More...
enum  radio_clkm_speed_t
 

This enumeration defines the possible CLKM speeds.

More...

Functions

bool radio_is_sleeping (void)
 This function checks if the radio transceiver is sleeping.
radio_status_t radio_init (bool cal_rc_osc, hal_rx_start_isr_event_handler_t rx_event, hal_trx_end_isr_event_handler_t trx_end_event, radio_rx_callback rx_callback)
 Initialize the Transceiver Access Toolbox and lower layers.
uint8_t radio_get_operating_channel (void)
 This function will return the channel used by the radio transceiver.
radio_status_t radio_set_operating_channel (uint8_t channel)
 This function will change the operating channel.
uint8_t radio_get_tx_power_level (void)
 This function will read and return the output power level.
radio_status_t radio_set_tx_power_level (uint8_t power_level)
 This function will change the output power level.
uint8_t radio_get_cca_mode (void)
 This function returns the current CCA mode used.
uint8_t radio_get_ed_threshold (void)
 This function returns the current ED threshold used by the CCA algorithm.
radio_status_t radio_set_cca_mode (uint8_t mode, uint8_t ed_threshold)
 This function will configure the Clear Channel Assessment algorithm.
radio_status_t radio_get_rssi_value (uint8_t *rssi)
 This function returns the Received Signal Strength Indication.
uint8_t radio_batmon_get_voltage_threshold (void)
 This function returns the current threshold volatge used by the battery monitor (BATMON_VTH).
uint8_t radio_batmon_get_voltage_range (void)
 This function returns if high or low voltage range is used.
radio_status_t radio_batmon_configure (bool range, uint8_t voltage_threshold)
 This function is used to configure the battery monitor module.
radio_status_t radio_batmon_get_status (void)
 This function returns the status of the Battery Monitor module.
uint8_t radio_get_clock_speed (void)
 This function returns the current clock setting for the CLKM pin.
radio_status_t radio_set_clock_speed (bool direct, uint8_t clock_speed)
 This function changes the prescaler on the CLKM pin.
radio_status_t radio_calibrate_filter (void)
 This function calibrates the Single Side Band Filter.
radio_status_t radio_calibrate_pll (void)
 This function calibrates the PLL.
uint8_t radio_get_trx_state (void)
 This function return the Radio Transceivers current state.
radio_status_t radio_set_trx_state (uint8_t new_state)
 This function will change the current state of the radio transceiver's internal state machine.
radio_status_t radio_enter_sleep_mode (void)
 This function will put the radio transceiver to sleep.
radio_status_t radio_leave_sleep_mode (void)
 This function will take the radio transceiver from sleep mode and put it into the TRX_OFF state.
void radio_reset_state_machine (void)
 This function will reset the state machine (to TRX_OFF) from any of its states, except for the SLEEP state.
void radio_reset_trx (void)
 This function will reset all the registers and the state machine of the radio transceiver.
void radio_use_auto_tx_crc (bool auto_crc_on)
 This function will enable or disable automatic CRC during frame transmission.
radio_status_t radio_send_data (uint8_t data_length, uint8_t *data)
 This function will download a frame to the radio transceiver's transmit buffer and send it.
uint8_t radio_get_device_role (void)
 This function will read the I_AM_COORD sub register.
void radio_set_device_role (bool i_am_coordinator)
 This function will set the I_AM_COORD sub register.
uint16_t radio_get_pan_id (void)
 This function will return the PANID used by the address filter.
void radio_set_pan_id (uint16_t new_pan_id)
 This function will set the PANID used by the address filter.
uint16_t radio_get_short_address (void)
 This function will return the current short address used by the address filter.
void radio_set_short_address (uint16_t new_short_address)
 This function will set the short address used by the address filter.
void radio_get_extended_address (uint8_t *extended_address)
 This function will read the extended address used by the address filter.
void radio_set_extended_address (uint8_t *extended_address)
 This function will set a new extended address to be used by the address filter.
radio_status_t radio_configure_csma (uint8_t seed0, uint8_t be_csma_seed1)
 This function will configure the CSMA algorithm used by the radio transceiver when transmitting data from TX_ARET_ON state.
bool calibrate_rc_osc_clkm (void)
 Calibrate the internal RC oscillator.
void calibrate_rc_osc_32k (void)
 Calibrate the internal RC oscillator.

Transaction status codes

#define TRAC_SUCCESS   0
#define TRAC_SUCCESS_DATA_PENDING   1
#define TRAC_SUCCESS_WAIT_FOR_ACK   2
#define TRAC_CHANNEL_ACCESS_FAILURE   3
#define TRAC_NO_ACK   5
#define TRAC_INVALID   7

Transaction status codes

#define TRAC_SUCCESS   0
#define TRAC_SUCCESS_DATA_PENDING   1
#define TRAC_SUCCESS_WAIT_FOR_ACK   2
#define TRAC_CHANNEL_ACCESS_FAILURE   3
#define TRAC_NO_ACK   5
#define TRAC_INVALID   7

Define Documentation

#define RADIO_CCA_DONE_MASK   (1 << 7)

Mask used to check the CCA_DONE bit.

Definition at line 78 of file radio.c.

#define RADIO_CCA_IDLE_MASK   (1 << 6)

Mask used to check the CCA_STATUS bit.

Definition at line 79 of file radio.c.

#define RADIO_START_CCA   (1)

Value in the CCA_REQUEST subregister that initiate a cca.

Definition at line 81 of file radio.c.

#define RADIO_STATUS_START_VALUE   ( 0x40 )

This macro defines the start value for the RADIO_* status constants.

It was chosen to have this macro so that the user can define where the status returned from the TAT starts. This can be useful in a system where numerous drivers are used, and some range of status codes are occupied.

See also:
radio_status_t

Definition at line 121 of file rf230bb.h.

#define RADIO_STATUS_START_VALUE   ( 0x40 )

This macro defines the start value for the RADIO_* status constants.

It was chosen to have this macro so that the user can define where the status returned from the TAT starts. This can be useful in a system where numerous drivers are used, and some range of status codes are occupied.

See also:
radio_status_t

Definition at line 97 of file radio.h.

#define RF230_MAX_TX_FRAME_LENGTH   ( 127 )

127 Byte PSDU.

Definition at line 84 of file rf230bb.h.

Referenced by radio_send_data().

#define RF230_MAX_TX_FRAME_LENGTH   ( 127 )

127 Byte PSDU.

Definition at line 70 of file radio.h.


Enumeration Type Documentation

This enumeration defines the possible modes available for the Clear Channel Assessment algorithm.

These constants are extracted from the datasheet.

Enumerator:
CCA_ENERGY_DETECT 

Use energy detection above threshold mode.

CCA_CARRIER_SENSE 

Use carrier sense mode.

CCA_CARRIER_SENSE_WITH_ED 

Use a combination of both energy detection and carrier sense.

CCA_ED 

Use energy detection above threshold mode.

CCA_CARRIER_SENSE 

Use carrier sense mode.

CCA_CARRIER_SENSE_WITH_ED 

Use a combination of both energy detection and carrier sense.

Definition at line 168 of file rf230bb.h.

This enumeration defines the possible modes available for the Clear Channel Assessment algorithm.

These constants are extracted from the datasheet.

Enumerator:
CCA_ENERGY_DETECT 

Use energy detection above threshold mode.

CCA_CARRIER_SENSE 

Use carrier sense mode.

CCA_CARRIER_SENSE_WITH_ED 

Use a combination of both energy detection and carrier sense.

CCA_ED 

Use energy detection above threshold mode.

CCA_CARRIER_SENSE 

Use carrier sense mode.

CCA_CARRIER_SENSE_WITH_ED 

Use a combination of both energy detection and carrier sense.

Definition at line 144 of file radio.h.

This enumeration defines the possible CLKM speeds.

These constants are extracted from the RF230 datasheet.

Definition at line 181 of file rf230bb.h.

This enumeration defines the possible CLKM speeds.

These constants are extracted from the RF230 datasheet.

Definition at line 156 of file radio.h.

This enumeration defines the possible return values for the TAT API functions.

These values are defined so that they should not collide with the return/status codes defined in the IEEE 802.15.4 standard.

Enumerator:
RADIO_SUCCESS 

The requested service was performed successfully.

RADIO_UNSUPPORTED_DEVICE 

The connected device is not an Atmel AT86RF230.

RADIO_INVALID_ARGUMENT 

One or more of the supplied function arguments are invalid.

RADIO_TIMED_OUT 

The requested service timed out.

RADIO_WRONG_STATE 

The end-user tried to do an invalid state transition.

RADIO_BUSY_STATE 

The radio transceiver is busy receiving or transmitting.

RADIO_STATE_TRANSITION_FAILED 

The requested state transition could not be completed.

RADIO_CCA_IDLE 

Channel is clear, available to transmit a new frame.

RADIO_CCA_BUSY 

Channel busy.

RADIO_TRX_BUSY 

Transceiver is busy receiving or transmitting data.

RADIO_BAT_LOW 

Measured battery voltage is lower than voltage threshold.

RADIO_BAT_OK 

Measured battery voltage is above the voltage threshold.

RADIO_CRC_FAILED 

The CRC failed for the actual frame.

RADIO_CHANNEL_ACCESS_FAILURE 

The channel access failed during the auto mode.

RADIO_NO_ACK 

No acknowledge frame was received.

RADIO_SUCCESS 

The requested service was performed successfully.

RADIO_UNSUPPORTED_DEVICE 

The connected device is not an Atmel AT86RF230.

RADIO_INVALID_ARGUMENT 

One or more of the supplied function arguments are invalid.

RADIO_TIMED_OUT 

The requested service timed out.

RADIO_WRONG_STATE 

The end-user tried to do an invalid state transition.

RADIO_BUSY_STATE 

The radio transceiver is busy receiving or transmitting.

RADIO_STATE_TRANSITION_FAILED 

The requested state transition could not be completed.

RADIO_CCA_IDLE 

Channel is clear, available to transmit a new frame.

RADIO_CCA_BUSY 

Channel busy.

RADIO_TRX_BUSY 

Transceiver is busy receiving or transmitting data.

RADIO_BAT_LOW 

Measured battery voltage is lower than voltage threshold.

RADIO_BAT_OK 

Measured battery voltage is above the voltage threshold.

RADIO_CRC_FAILED 

The CRC failed for the actual frame.

RADIO_CHANNEL_ACCESS_FAILURE 

The channel access failed during the auto mode.

RADIO_NO_ACK 

No acknowledge frame was received.

Definition at line 130 of file rf230bb.h.

This enumeration defines the possible return values for the TAT API functions.

These values are defined so that they should not collide with the return/status codes defined in the IEEE 802.15.4 standard.

Enumerator:
RADIO_SUCCESS 

The requested service was performed successfully.

RADIO_UNSUPPORTED_DEVICE 

The connected device is not an Atmel AT86RF230.

RADIO_INVALID_ARGUMENT 

One or more of the supplied function arguments are invalid.

RADIO_TIMED_OUT 

The requested service timed out.

RADIO_WRONG_STATE 

The end-user tried to do an invalid state transition.

RADIO_BUSY_STATE 

The radio transceiver is busy receiving or transmitting.

RADIO_STATE_TRANSITION_FAILED 

The requested state transition could not be completed.

RADIO_CCA_IDLE 

Channel is clear, available to transmit a new frame.

RADIO_CCA_BUSY 

Channel busy.

RADIO_TRX_BUSY 

Transceiver is busy receiving or transmitting data.

RADIO_BAT_LOW 

Measured battery voltage is lower than voltage threshold.

RADIO_BAT_OK 

Measured battery voltage is above the voltage threshold.

RADIO_CRC_FAILED 

The CRC failed for the actual frame.

RADIO_CHANNEL_ACCESS_FAILURE 

The channel access failed during the auto mode.

RADIO_NO_ACK 

No acknowledge frame was received.

RADIO_SUCCESS 

The requested service was performed successfully.

RADIO_UNSUPPORTED_DEVICE 

The connected device is not an Atmel AT86RF230.

RADIO_INVALID_ARGUMENT 

One or more of the supplied function arguments are invalid.

RADIO_TIMED_OUT 

The requested service timed out.

RADIO_WRONG_STATE 

The end-user tried to do an invalid state transition.

RADIO_BUSY_STATE 

The radio transceiver is busy receiving or transmitting.

RADIO_STATE_TRANSITION_FAILED 

The requested state transition could not be completed.

RADIO_CCA_IDLE 

Channel is clear, available to transmit a new frame.

RADIO_CCA_BUSY 

Channel busy.

RADIO_TRX_BUSY 

Transceiver is busy receiving or transmitting data.

RADIO_BAT_LOW 

Measured battery voltage is lower than voltage threshold.

RADIO_BAT_OK 

Measured battery voltage is above the voltage threshold.

RADIO_CRC_FAILED 

The CRC failed for the actual frame.

RADIO_CHANNEL_ACCESS_FAILURE 

The channel access failed during the auto mode.

RADIO_NO_ACK 

No acknowledge frame was received.

Definition at line 106 of file radio.h.

This enumeration defines the necessary timing information for the AT86RF230 radio transceiver.

All times are in microseconds.

These constants are extracted from the datasheet.

Enumerator:
TIME_TO_ENTER_P_ON 

Transition time from VCC is applied to P_ON - most favorable case!

TIME_P_ON_TO_TRX_OFF 

Transition time from P_ON to TRX_OFF.

TIME_SLEEP_TO_TRX_OFF 

Transition time from SLEEP to TRX_OFF.

TIME_RESET 

Time to hold the RST pin low during reset.

TIME_ED_MEASUREMENT 

Time it takes to do a ED measurement.

TIME_CCA 

Time it takes to do a CCA.

TIME_PLL_LOCK 

Maximum time it should take for the PLL to lock.

TIME_FTN_TUNING 

Maximum time it should take to do the filter tuning.

TIME_NOCLK_TO_WAKE 

Transition time from *_NOCLK to being awake.

TIME_CMD_FORCE_TRX_OFF 

Time it takes to execute the FORCE_TRX_OFF command.

TIME_TRX_OFF_TO_PLL_ACTIVE 

Transition time from TRX_OFF to: RX_ON, PLL_ON, TX_ARET_ON and RX_AACK_ON.

TIME_STATE_TRANSITION_PLL_ACTIVE 

Transition time from PLL active state to another.

TIME_TO_ENTER_P_ON 

Transition time from VCC is applied to P_ON.

TIME_P_ON_TO_TRX_OFF 

Transition time from P_ON to TRX_OFF.

TIME_SLEEP_TO_TRX_OFF 

Transition time from SLEEP to TRX_OFF.

TIME_RESET 

Time to hold the RST pin low during reset.

TIME_ED_MEASUREMENT 

Time it takes to do a ED measurement.

TIME_CCA 

Time it takes to do a CCA.

TIME_PLL_LOCK 

Maximum time it should take for the PLL to lock.

TIME_FTN_TUNING 

Maximum time it should take to do the filter tuning.

TIME_NOCLK_TO_WAKE 

Transition time from *_NOCLK to being awake.

TIME_CMD_FORCE_TRX_OFF 

Time it takes to execute the FORCE_TRX_OFF command.

TIME_TRX_OFF_TO_PLL_ACTIVE 

Transition time from TRX_OFF to: RX_ON, PLL_ON, TX_ARET_ON and RX_AACK_ON.

TIME_STATE_TRANSITION_PLL_ACTIVE 

Transition time from PLL active state to another.

Definition at line 93 of file radio.c.


Function Documentation

void calibrate_rc_osc_32k ( void  )

Calibrate the internal RC oscillator.

This function calibrates the internal RC oscillator, based on an external 32KHz crystal connected to TIMER2. In order to verify the calibration result you can program the CKOUT fuse and monitor the CPU clock on an I/O pin.

Definition at line 1333 of file radio.c.

References AVR_ENTER_CRITICAL_REGION, and AVR_LEAVE_CRITICAL_REGION.

Referenced by radio_init().

bool calibrate_rc_osc_clkm ( void  )

Calibrate the internal RC oscillator.

This function calibrates the internal RC oscillator, based on the 1 MHz clock supplied by the AT86RF2xx. In order to verify the calibration result you can program the CKOUT fuse and monitor the CPU clock on an I/O pin.

Returns:
TRUE if calibrate passed; FALSE if calibrate failed.

Definition at line 1239 of file radio.c.

References CLKM_1MHz, and radio_set_clock_speed().

radio_status_t radio_batmon_configure ( bool  range,
uint8_t  voltage_threshold 
)

This function is used to configure the battery monitor module.

Parameters:
rangeTrue means high voltage range and false low voltage range.
voltage_thresholdThe datasheet defines 16 voltage levels for both low and high range.
Return values:
RADIO_SUCCESSBattery monitor configured
RADIO_WRONG_STATEThe device is sleeping.
RADIO_INVALID_ARGUMENTThe voltage_threshold parameter is out of bounds (Not within [0 - 15]).

Definition at line 544 of file radio.c.

References hal_subregister_write(), RADIO_INVALID_ARGUMENT, radio_is_sleeping(), RADIO_SUCCESS, RADIO_WRONG_STATE, SR_BATMON_HR, and SR_BATMON_VTH.

radio_status_t radio_batmon_get_status ( void  )

This function returns the status of the Battery Monitor module.

Note:
This function can not be called from P_ON or SLEEP. This is ensured by reading the device state before calling this function.
Return values:
RADIO_BAT_LOWBattery voltage is below the programmed threshold.
RADIO_BAT_OKBattery voltage is above the programmed threshold.

Definition at line 578 of file radio.c.

References hal_subregister_read(), RADIO_BAT_LOW, RADIO_BAT_OK, and SR_BATMON_OK.

uint8_t radio_batmon_get_voltage_range ( void  )

This function returns if high or low voltage range is used.

Note:
This function can not be called from P_ON or SLEEP. This is ensured by reading the device state before calling this function.
Return values:
0Low voltage range selected.
1High voltage range selected.

Definition at line 527 of file radio.c.

References hal_subregister_read(), and SR_BATMON_HR.

uint8_t radio_batmon_get_voltage_threshold ( void  )

This function returns the current threshold volatge used by the battery monitor (BATMON_VTH).

Note:
This function can not be called from P_ON or SLEEP. This is ensured by reading the device state before calling this function.
Returns:
Current threshold voltage, 0 to 15.

Definition at line 512 of file radio.c.

References hal_subregister_read(), and SR_BATMON_VTH.

radio_status_t radio_calibrate_filter ( void  )

This function calibrates the Single Side Band Filter.

Return values:
RADIO_SUCCESSFilter is calibrated.
RADIO_TIMED_OUTThe calibration could not be completed within time.
RADIO_WRONG_STATEThis function can only be called from TRX_OFF or PLL_ON.

Definition at line 660 of file radio.c.

References hal_subregister_read(), hal_subregister_write(), PLL_ON, radio_get_trx_state(), RADIO_SUCCESS, RADIO_TIMED_OUT, RADIO_WRONG_STATE, SR_FTN_START, TIME_FTN_TUNING, and TRX_OFF.

radio_status_t radio_calibrate_pll ( void  )

This function calibrates the PLL.

Return values:
RADIO_SUCCESSPLL Center Frequency and Delay Cell is calibrated.
RADIO_TIMED_OUTThe calibration could not be completed within time.
RADIO_WRONG_STATEThis function can only be called from PLL_ON.

Definition at line 692 of file radio.c.

References hal_clear_pll_lock_flag(), hal_get_pll_lock_flag(), hal_subregister_read(), hal_subregister_write(), PLL_ON, radio_get_trx_state(), RADIO_SUCCESS, RADIO_TIMED_OUT, RADIO_WRONG_STATE, SR_PLL_CF_START, SR_PLL_DCU_START, and TIME_PLL_LOCK.

radio_status_t radio_configure_csma ( uint8_t  seed0,
uint8_t  be_csma_seed1 
)

This function will configure the CSMA algorithm used by the radio transceiver when transmitting data from TX_ARET_ON state.

Parameters:
seed0Lower 8 bits of the seed used for the random number generator in the CSMA algorithm. Value range: 0 to 255.
be_csma_seed1Is a combined argument of the MIN_BE, MAX_CSMA_RETRIES and SEED1 variables:

  1. MIN_BE: Bit[7:6] Minimum back-off exponent in the CSMA/CA algorithm.
  2. MAX_CSMA_RETRIES: Bit[5:3] Number of retries in TX_ARET_ON mode to repeat the CSMA/CA procedures before the ARET procedure gives up.
  3. SEED1: Bits[2:0] Higher 3 bits of CSMA_SEED, bits[10:8] Seed for the random number generator in the CSMA/CA algorithm.
Return values:
RADIO_SUCCESSThe CSMA algorithm was configured successfully.
RADIO_WRONG_STATEThis function should not be called in the SLEEP state.

Definition at line 1205 of file radio.c.

References hal_register_write(), hal_subregister_write(), radio_is_sleeping(), RADIO_SUCCESS, RADIO_WRONG_STATE, RG_CSMA_SEED_0, SR_CSMA_SEED_1, SR_MAX_CSMA_RETRIES, SR_MAX_FRAME_RETRIES, and SR_MIN_BE.

radio_status_t radio_enter_sleep_mode ( void  )

This function will put the radio transceiver to sleep.

Return values:
RADIO_SUCCESSSleep mode entered successfully.
RADIO_TIMED_OUTThe transition to TRX_OFF took too long.

Definition at line 903 of file radio.c.

References hal_set_slptr_high, radio_get_trx_state(), radio_is_sleeping(), radio_reset_state_machine(), RADIO_SUCCESS, RADIO_TIMED_OUT, and TRX_OFF.

uint8_t radio_get_cca_mode ( void  )

This function returns the current CCA mode used.

Returns:
CCA mode currently used, 0 to 3.

Definition at line 416 of file radio.c.

References hal_subregister_read(), and SR_CCA_MODE.

uint8_t radio_get_clock_speed ( void  )

This function returns the current clock setting for the CLKM pin.

Return values:
CLKM_DISABLEDCLKM pin is disabled.
CLKM_1MHZCLKM pin is prescaled to 1 MHz.
CLKM_2MHZCLKM pin is prescaled to 2 MHz.
CLKM_4MHZCLKM pin is prescaled to 4 MHz.
CLKM_8MHZCLKM pin is prescaled to 8 MHz.
CLKM_16MHZCLKM pin is not prescaled. Output is 16 MHz.

Definition at line 602 of file radio.c.

References hal_subregister_read(), and SR_CLKM_CTRL.

Referenced by radio_set_clock_speed().

uint8_t radio_get_device_role ( void  )

This function will read the I_AM_COORD sub register.

Return values:
0Not coordinator.
1Coordinator role enabled.

Definition at line 1057 of file radio.c.

References hal_subregister_read(), and SR_I_AM_COORD.

uint8_t radio_get_ed_threshold ( void  )

This function returns the current ED threshold used by the CCA algorithm.

Returns:
Current ED threshold, 0 to 15.

Definition at line 427 of file radio.c.

References hal_subregister_read(), and SR_CCA_ED_THRES.

void radio_get_extended_address ( uint8_t *  extended_address)

This function will read the extended address used by the address filter.

Note:
In this function a pointer is used to convey the 64-bit result, since it is very inefficient to use the stack for this.
Returns:
Extended Address, any 64-bit value.

Definition at line 1153 of file radio.c.

References hal_register_read(), RG_IEEE_ADDR_0, RG_IEEE_ADDR_1, RG_IEEE_ADDR_2, RG_IEEE_ADDR_3, RG_IEEE_ADDR_4, RG_IEEE_ADDR_5, RG_IEEE_ADDR_6, and RG_IEEE_ADDR_7.

uint8_t radio_get_operating_channel ( void  )

This function will return the channel used by the radio transceiver.

Returns:
Current channel, 11 to 26.

Definition at line 314 of file radio.c.

References hal_subregister_read(), and SR_CHANNEL.

Referenced by menu_process(), and radio_set_operating_channel().

uint16_t radio_get_pan_id ( void  )

This function will return the PANID used by the address filter.

Return values:
Anyvalue from 0 to 0xFFFF.

Definition at line 1082 of file radio.c.

References hal_register_read(), RG_PAN_ID_0, and RG_PAN_ID_1.

radio_status_t radio_get_rssi_value ( uint8_t *  rssi)

This function returns the Received Signal Strength Indication.

Note:
This function should only be called from the: RX_ON and BUSY_RX. This can be ensured by reading the current state of the radio transceiver before executing this function!
Parameters:
rssiPointer to memory location where RSSI value should be written.
Return values:
RADIO_SUCCESSThe RSSI measurement was successful.
RADIO_WRONG_STATEThe radio transceiver is not in RX_ON or BUSY_RX.

Definition at line 486 of file radio.c.

References BUSY_RX, hal_subregister_read(), radio_get_trx_state(), RADIO_SUCCESS, RADIO_WRONG_STATE, RX_ON, and SR_RSSI.

Referenced by menu_process().

uint16_t radio_get_short_address ( void  )

This function will return the current short address used by the address filter.

Return values:
Anyvalue from 0x0000 to 0xFFFF

Definition at line 1116 of file radio.c.

References hal_register_read(), and RG_SHORT_ADDR_1.

uint8_t radio_get_trx_state ( void  )

This function return the Radio Transceivers current state.

Return values:
P_ONWhen the external supply voltage (VDD) is first supplied to the transceiver IC, the system is in the P_ON (Poweron) mode.
BUSY_RXThe radio transceiver is busy receiving a frame.
BUSY_TXThe radio transceiver is busy transmitting a frame.
RX_ONThe RX_ON mode enables the analog and digital receiver blocks and the PLL frequency synthesizer.
TRX_OFFIn this mode, the SPI module and crystal oscillator are active.
PLL_ONEntering the PLL_ON mode from TRX_OFF will first enable the analog voltage regulator. The transceiver is ready to transmit a frame.
BUSY_RX_AACKThe radio was in RX_AACK_ON mode and received the Start of Frame Delimiter (SFD). State transition to BUSY_RX_AACK is done if the SFD is valid.
BUSY_TX_ARETThe radio transceiver is busy handling the auto retry mechanism.
RX_AACK_ONThe auto acknowledge mode of the radio is enabled and it is waiting for an incomming frame.
TX_ARET_ONThe auto retry mechanism is enabled and the radio transceiver is waiting for the user to send the TX_START command.
RX_ON_NOCLKThe radio transceiver is listening for incomming frames, but the CLKM is disabled so that the controller could be sleeping. However, this is only true if the controller is run from the clock output of the radio.
RX_AACK_ON_NOCLKSame as the RX_ON_NOCLK state, but with the auto acknowledge module turned on.
BUSY_RX_AACK_NOCLKSame as BUSY_RX_AACK, but the controller could be sleeping since the CLKM pin is disabled.
STATE_TRANSITIONThe radio transceiver's state machine is in transition between two states.

Definition at line 765 of file radio.c.

References hal_subregister_read(), and SR_TRX_STATUS.

Referenced by radio_calibrate_filter(), radio_calibrate_pll(), radio_enter_sleep_mode(), radio_get_rssi_value(), radio_init(), radio_leave_sleep_mode(), radio_send_data(), radio_set_operating_channel(), and radio_set_trx_state().

uint8_t radio_get_tx_power_level ( void  )

This function will read and return the output power level.

Returns:
0 to 15 Current output power in "TX power settings" as defined in the radio transceiver's datasheet

Definition at line 375 of file radio.c.

References hal_subregister_read(), and SR_TX_PWR.

Referenced by menu_process().

radio_status_t radio_init ( bool  cal_rc_osc,
hal_rx_start_isr_event_handler_t  rx_event,
hal_trx_end_isr_event_handler_t  trx_end_event,
radio_rx_callback  rx_callback 
)

Initialize the Transceiver Access Toolbox and lower layers.

If the initialization is successful the radio transceiver will be in TRX_OFF state.

Note:
This function must be called prior to any of the other functions in this file! Can be called from any transceiver state.
Parameters:
cal_rc_oscIf true, the radio's accurate clock is used to calibrate the CPU's internal RC oscillator.
rx_eventOptional pointer to a user-defined function to be called on an RX_START interrupt. Use NULL for no handler.
trx_end_eventOptional pointer to a user-defined function to be called on an TRX_END interrupt. Use NULL for no handler.
rx_callbackOptional pointer to a user-defined function that receives a frame from the radio one byte at a time. If the index parameter to this callback is 0xff, then the function should reset its state and prepare for a frame from the radio, with one call per byte.
Return values:
RADIO_SUCCESSThe radio transceiver was successfully initialized and put into the TRX_OFF state.
RADIO_UNSUPPORTED_DEVICEThe connected device is not an Atmel AT86RF230 radio transceiver.
RADIO_TIMED_OUTThe radio transceiver was not able to initialize and enter TRX_OFF state within the specified time.

Definition at line 161 of file radio.c.

References calibrate_rc_osc_32k(), CMD_FORCE_TRX_OFF, hal_init(), hal_register_read(), hal_register_write(), hal_set_rx_start_event_handler(), hal_set_trx_end_event_handler(), hal_subregister_write(), radio_get_trx_state(), radio_reset_trx(), RADIO_SUCCESS, RADIO_TIMED_OUT, RADIO_UNSUPPORTED_DEVICE, RG_IRQ_MASK, RG_MAN_ID_0, RG_VERSION_NUM, SR_TRX_CMD, TIME_P_ON_TO_TRX_OFF, TIME_TO_ENTER_P_ON, and TRX_OFF.

Referenced by PROCESS_THREAD().

bool radio_is_sleeping ( void  )

This function checks if the radio transceiver is sleeping.

Return values:
trueThe radio transceiver is in SLEEP or one of the *_NOCLK states.
falseThe radio transceiver is not sleeping.

Definition at line 777 of file radio.c.

References hal_get_slptr.

Referenced by radio_batmon_configure(), radio_configure_csma(), radio_enter_sleep_mode(), radio_leave_sleep_mode(), radio_set_cca_mode(), radio_set_operating_channel(), radio_set_trx_state(), and radio_set_tx_power_level().

radio_status_t radio_leave_sleep_mode ( void  )

This function will take the radio transceiver from sleep mode and put it into the TRX_OFF state.

Return values:
RADIO_SUCCESSLeft sleep mode and entered TRX_OFF state.
RADIO_TIMED_OUTTransition to TRX_OFF state timed out.

Definition at line 933 of file radio.c.

References hal_set_slptr_low, radio_get_trx_state(), radio_is_sleeping(), RADIO_SUCCESS, RADIO_TIMED_OUT, TIME_SLEEP_TO_TRX_OFF, and TRX_OFF.

radio_status_t radio_send_data ( uint8_t  data_length,
uint8_t *  data 
)

This function will download a frame to the radio transceiver's transmit buffer and send it.

Parameters:
data_lengthLength of the frame to be transmitted. 1 to 128 bytes are the valid lengths.
*dataPointer to the data to transmit
Return values:
RADIO_SUCCESSFrame downloaded and sent successfully.
RADIO_INVALID_ARGUMENTIf the dataLength is 0 byte or more than 127 bytes the frame will not be sent.
RADIO_WRONG_STATEIt is only possible to use this function in the PLL_ON and TX_ARET_ON state. If any other state is detected this error message will be returned.

Definition at line 1016 of file radio.c.

References BUSY_TX, BUSY_TX_ARET, hal_frame_write(), hal_set_slptr_high, hal_set_slptr_low, radio_get_trx_state(), RADIO_INVALID_ARGUMENT, radio_set_trx_state(), RADIO_SUCCESS, RADIO_WRONG_STATE, RF230_MAX_TX_FRAME_LENGTH, TRX_OFF, and TX_ARET_ON.

Referenced by sicslowmac_dataRequest().

radio_status_t radio_set_cca_mode ( uint8_t  mode,
uint8_t  ed_threshold 
)

This function will configure the Clear Channel Assessment algorithm.

Parameters:
modeThree modes are available: Energy above threshold, carrier sense only and carrier sense with energy above threshold.
ed_thresholdAbove this energy threshold the channel is assumed to be busy. The threshold is given in positive dBm values. Ex. -91 dBm gives a csThreshold of 91. Value range for the variable is [61 to 91]. Only valid for the CCA_ED and CCA_CARRIER_SENSE_ED modes.
Return values:
RADIO_SUCCESSMode and its parameters successfully changed.
RADIO_WRONG_STATEThis function cannot be called in the SLEEP state.
RADIO_INVALID_ARGUMENTIf one of the three function arguments are out of bounds.

Definition at line 449 of file radio.c.

References CCA_CARRIER_SENSE, CCA_CARRIER_SENSE_WITH_ED, CCA_ED, hal_subregister_write(), RADIO_INVALID_ARGUMENT, radio_is_sleeping(), RADIO_SUCCESS, RADIO_WRONG_STATE, SR_CCA_ED_THRES, and SR_CCA_MODE.

radio_status_t radio_set_clock_speed ( bool  direct,
uint8_t  clock_speed 
)

This function changes the prescaler on the CLKM pin.

Parameters:
directThis boolean variable is used to determine if the frequency of the CLKM pin shall be changed directly or not. If direct equals true, the frequency will be changed directly. This is fine if the CLKM signal is used to drive a timer etc. on the connected microcontroller. However, the CLKM signal can also be used to clock the microcontroller itself. In this situation it is possible to change the CLKM frequency indirectly (direct == false). When the direct argument equlas false, the CLKM frequency will be changed first after the radio transceiver has been taken to SLEEP and awaken again.
clock_speedThis parameter can be one of the following constants: CLKM_DISABLED, CLKM_1MHZ, CLKM_2MHZ, CLKM_4MHZ, CLKM_8MHZ or CLKM_16MHZ.
Return values:
RADIO_SUCCESSClock speed updated. New state is TRX_OFF.
RADIO_INVALID_ARGUMENTRequested clock speed is out of bounds.

Definition at line 628 of file radio.c.

References hal_subregister_write(), radio_get_clock_speed(), RADIO_INVALID_ARGUMENT, RADIO_SUCCESS, SR_CLKM_CTRL, and SR_CLKM_SHA_SEL.

Referenced by calibrate_rc_osc_clkm().

void radio_set_device_role ( bool  i_am_coordinator)

This function will set the I_AM_COORD sub register.

Parameters:
[in]i_am_coordinatorIf this parameter is true, the associated coordinator role will be enabled in the radio transceiver's address filter. False disables the same feature.

Definition at line 1071 of file radio.c.

References hal_subregister_write(), and SR_I_AM_COORD.

void radio_set_extended_address ( uint8_t *  extended_address)

This function will set a new extended address to be used by the address filter.

Parameters:
extended_addressExtended address to be used by the address filter.

Definition at line 1172 of file radio.c.

References hal_register_write(), RG_IEEE_ADDR_0, RG_IEEE_ADDR_1, RG_IEEE_ADDR_2, RG_IEEE_ADDR_3, RG_IEEE_ADDR_4, RG_IEEE_ADDR_5, RG_IEEE_ADDR_6, and RG_IEEE_ADDR_7.

Referenced by mac_init().

radio_status_t radio_set_operating_channel ( uint8_t  channel)

This function will change the operating channel.

Parameters:
channelNew channel to operate on. Must be between 11 and 26.
Return values:
RADIO_SUCCESSNew channel set.
RADIO_WRONG_STATETransceiver is in a state where the channel cannot be changed (SLEEP).
RADIO_INVALID_ARGUMENTChannel argument is out of bounds.
RADIO_TIMED_OUTThe PLL did not lock within the specified time.

Definition at line 330 of file radio.c.

References hal_subregister_write(), PLL_ON, radio_get_operating_channel(), radio_get_trx_state(), RADIO_INVALID_ARGUMENT, radio_is_sleeping(), RADIO_SUCCESS, RADIO_TIMED_OUT, RADIO_WRONG_STATE, RX_ON, SR_CHANNEL, and TIME_PLL_LOCK.

Referenced by menu_process(), and PROCESS_THREAD().

void radio_set_pan_id ( uint16_t  new_pan_id)

This function will set the PANID used by the address filter.

Parameters:
new_pan_idDesired PANID. Can be any value from 0x0000 to 0xFFFF

Definition at line 1099 of file radio.c.

References hal_register_write(), RG_PAN_ID_0, and RG_PAN_ID_1.

Referenced by mac_init().

void radio_set_short_address ( uint16_t  new_short_address)

This function will set the short address used by the address filter.

Parameters:
new_short_addressShort address to be used by the address filter.

Definition at line 1133 of file radio.c.

References hal_register_write(), RG_SHORT_ADDR_0, and RG_SHORT_ADDR_1.

radio_status_t radio_set_trx_state ( uint8_t  new_state)

This function will change the current state of the radio transceiver's internal state machine.

Parameters:
new_stateHere is a list of possible states:

  • RX_ON Requested transition to RX_ON state.
  • TRX_OFF Requested transition to TRX_OFF state.
  • PLL_ON Requested transition to PLL_ON state.
  • RX_AACK_ON Requested transition to RX_AACK_ON state.
  • TX_ARET_ON Requested transition to TX_ARET_ON state.
Return values:
RADIO_SUCCESSRequested state transition completed successfully.
RADIO_INVALID_ARGUMENTSupplied function parameter out of bounds.
RADIO_WRONG_STATEIllegal state to do transition from.
RADIO_BUSY_STATEThe radio transceiver is busy.
RADIO_TIMED_OUTThe state transition could not be completed within resonable time.

Definition at line 810 of file radio.c.

References BUSY_RX, BUSY_RX_AACK, BUSY_TX, BUSY_TX_ARET, hal_subregister_write(), PLL_ON, radio_get_trx_state(), RADIO_INVALID_ARGUMENT, radio_is_sleeping(), radio_reset_state_machine(), RADIO_SUCCESS, RADIO_TIMED_OUT, RADIO_WRONG_STATE, RX_AACK_ON, RX_ON, SR_TRX_CMD, TIME_STATE_TRANSITION_PLL_ACTIVE, TIME_TRX_OFF_TO_PLL_ACTIVE, TRX_OFF, and TX_ARET_ON.

Referenced by menu_process(), PROCESS_THREAD(), and radio_send_data().

radio_status_t radio_set_tx_power_level ( uint8_t  power_level)

This function will change the output power level.

Parameters:
power_levelNew output power level in the "TX power settings" as defined in the radio transceiver's datasheet.
Return values:
RADIO_SUCCESSNew output power set successfully.
RADIO_INVALID_ARGUMENTThe supplied function argument is out of bounds.
RADIO_WRONG_STATEIt is not possible to change the TX power when the device is sleeping.

Definition at line 392 of file radio.c.

References hal_subregister_write(), RADIO_INVALID_ARGUMENT, radio_is_sleeping(), RADIO_SUCCESS, RADIO_WRONG_STATE, and SR_TX_PWR.

Referenced by menu_process().

void radio_use_auto_tx_crc ( bool  auto_crc_on)

This function will enable or disable automatic CRC during frame transmission.

Parameters:
auto_crc_onIf this parameter equals true auto CRC will be used for all frames to be transmitted. The framelength must be increased by two bytes (16 bit CRC). If the parameter equals false, the automatic CRC will be disabled.

Definition at line 992 of file radio.c.

References hal_subregister_write(), and SR_TX_AUTO_CRC_ON.

Referenced by PROCESS_THREAD().