Microchip® Advanced Software Framework

tal.h File Reference

This file contains TAL API function declarations.

Id:
tal.h 27079 2011-06-08 05:44:08Z pawan.jadia
Author
Microchip Technology Inc: http://www.microchip.com
Support: https://www.microchip.com/support/
#include <stdint.h>
#include <stdbool.h>
#include "pal.h"
#include "tal_config.h"
#include "bmm.h"
#include "stack_config.h"
#include "return_val.h"
#include "tal_types.h"
#include "mac_build_config.h"

Data Structures

struct  frame_info_tag
 Globally used frame information structure. More...
 
union  pib_value_t
 PIB attribute value type. More...
 

Macros

#define BAND_2400   (1)
 2.4 GHz (channels 11 through 26) More...
 
#define BAND_900   (0)
 868 / 910 MHz (channels 0 through 10) using BPSK More...
 
#define mac_i_pan_coordinator   (0x0B)
 Attribute id of mac_i_pan_coordinator PIB. More...
 
#define MAX_FRAME_DURATION   (NO_OF_SYMBOLS_PREAMBLE_SFD + (aMaxPHYPacketSize + 1) * SYMBOLS_PER_OCTET)
 Maximum number of symbols in a frame for the current PHY. More...
 
#define MAX_SYMBOL_TIME   (0x0FFFFFFF)
 The maximum time in symbols for a 32 bit timer. More...
 
#define NO_OF_SYMBOLS_PREAMBLE_SFD   (NO_SYMBOLS_PREAMBLE + NO_SYMBOLS_SFD)
 Number of symbols forming the synchronization header (SHR) for the current PHY. More...
 
#define NO_SYMBOLS_PREAMBLE   (8)
 
#define NO_SYMBOLS_SFD   (2)
 
#define RF_BAND   BAND_2400
 
#define SYMBOL_MASK   (0x0FFFFFFF)
 Symbol mask for ingnoring most significant nibble. More...
 
#define SYMBOLS_PER_OCTET   (2)
 4 bits form one symbol since O-QPSK is used More...
 
#define TAL_CONVERT_SYMBOLS_TO_US(symbols)   ((uint32_t)(symbols) << 4)
 Conversion of symbols to microseconds. More...
 
#define TAL_CONVERT_US_TO_SYMBOLS(time)   ((time) >> 4)
 Conversion of microseconds to symbols. More...
 
#define TAL_GET_BEACON_INTERVAL_TIME(BO)   ((1UL * aBaseSuperframeDuration) << (BO))
 Beacon Interval time in symbols. More...
 
#define TAL_GET_SUPERFRAME_DURATION_TIME(SO)   ((1UL * aBaseSuperframeDuration) << (SO))
 Superframe Duration time in symbols. More...
 

Typedefs

typedef enum csma_mode_tag csma_mode_t
 CSMA Mode supported by transceiver. More...
 
typedef struct frame_info_tag frame_info_t
 Globally used frame information structure. More...
 
typedef enum sleep_mode_tag sleep_mode_t
 Sleep Mode supported by transceiver. More...
 

Enumerations

enum  csma_mode_tag {
  NO_CSMA_NO_IFS,
  NO_CSMA_WITH_IFS,
  CSMA_UNSLOTTED,
  CSMA_SLOTTED
}
 CSMA Mode supported by transceiver. More...
 
enum  SHORTENUM {
  ASSOCIATIONREQUEST = (0x01),
  ASSOCIATIONRESPONSE,
  DISASSOCIATIONNOTIFICATION,
  DATAREQUEST,
  PANIDCONFLICTNOTIFICAION,
  ORPHANNOTIFICATION,
  BEACONREQUEST,
  COORDINATORREALIGNMENT,
  ORPHANREALIGNMENT,
  BEACON_MESSAGE,
  DATAREQUEST_IMPL_POLL,
  NULL_FRAME,
  MCPS_MESSAGE
}
 MAC Message types. More...
 
enum  sleep_mode_tag { SLEEP_MODE_1 }
 Sleep Mode supported by transceiver. More...
 

Functions

static uint32_t tal_add_time_symbols (uint32_t a, uint32_t b)
 Adds two time values. More...
 
void tal_ed_end_cb (uint8_t energy_level)
 User call back function for finished ED Scan. More...
 
retval_t tal_ed_start (uint8_t scan_duration)
 Starts ED Scan. More...
 
void tal_generate_rand_seed (void)
 Generates a 16-bit random number used as initial seed for srand() More...
 
retval_t tal_init (void)
 Initializes the TAL. More...
 
retval_t tal_pib_get (uint8_t attribute, uint8_t *value)
 Gets a TAL PIB attribute. More...
 
retval_t tal_pib_set (uint8_t attribute, pib_value_t *value)
 Sets a TAL PIB attribute. More...
 
retval_t tal_reset (bool set_default_pib)
 Resets TAL state machine and sets the default PIB values if requested. More...
 
uint8_t tal_rx_enable (uint8_t state)
 Switches receiver on or off. More...
 
void tal_rx_frame_cb (frame_info_t *rx_frame)
 User call back function for frame reception. More...
 
static uint32_t tal_sub_time_symbols (uint32_t a, uint32_t b)
 Subtract two time values. More...
 
void tal_task (void)
 TAL task handling. More...
 
retval_t tal_trx_sleep (sleep_mode_t mode)
 Sets the transceiver to sleep. More...
 
retval_t tal_trx_wakeup (void)
 Wakes up the transceiver from sleep. More...
 
retval_t tal_tx_frame (frame_info_t *tx_frame, csma_mode_t csma_mode, bool perform_frame_retry)
 Requests to TAL to transmit frame. More...
 
void tal_tx_frame_done_cb (retval_t status, frame_info_t *frame)
 User call back function for frame transmission. More...
 

Variables

uint8_t tal_pib_CCAMode
 CCA Mode. More...
 
uint8_t tal_pib_CurrentChannel
 Current RF channel to be used for all transmissions and receptions. More...
 
uint8_t tal_pib_CurrentPage
 Current channel page. More...
 
uint64_t tal_pib_IeeeAddress
 64-bit (IEEE) address of the node. More...
 
uint8_t tal_pib_MaxBE
 The maximum value of the backoff exponent BE in the CSMA-CA algorithm. More...
 
uint8_t tal_pib_MaxCSMABackoffs
 The maximum number of back-offs the CSMA-CA algorithm will attempt before declaring a CSMA_CA failure. More...
 
uint16_t tal_pib_MaxFrameDuration
 Maximum number of symbols in a frame: = phySHRDuration + ceiling([aMaxPHYPacketSize + 1] x phySymbolsPerOctet) More...
 
uint8_t tal_pib_MaxFrameRetries
 The maximum number of retries allowed after a transmission failure. More...
 
uint8_t tal_pib_MinBE
 The minimum value of the backoff exponent BE in the CSMA-CA algorithm. More...
 
uint16_t tal_pib_PANId
 16-bit PAN ID More...
 
bool tal_pib_PrivatePanCoordinator
 Indicates if the node is a PAN coordinator or not. More...
 
uint16_t tal_pib_ShortAddress
 16-bit short address of the node. More...
 
uint8_t tal_pib_SHRDuration
 Duration of the synchronization header (SHR) in symbols for the current PHY. More...
 
uint32_t tal_pib_SupportedChannels
 Supported channels. More...
 
uint8_t tal_pib_SymbolsPerOctet
 Number of symbols per octet for the current PHY. More...
 
uint8_t tal_pib_TransmitPower
 Default value of transmit power of transceiver using IEEE defined format of phyTransmitPower. More...
 

#define BAND_2400   (1)

2.4 GHz (channels 11 through 26)

#define BAND_900   (0)

868 / 910 MHz (channels 0 through 10) using BPSK

#define mac_i_pan_coordinator   (0x0B)

Attribute id of mac_i_pan_coordinator PIB.

#define MAX_FRAME_DURATION   (NO_OF_SYMBOLS_PREAMBLE_SFD + (aMaxPHYPacketSize + 1) * SYMBOLS_PER_OCTET)

Maximum number of symbols in a frame for the current PHY.

This value is the base for the PHY PIB attribute phyMaxFrameDuration.

#define MAX_SYMBOL_TIME   (0x0FFFFFFF)

The maximum time in symbols for a 32 bit timer.

Referenced by tal_sub_time_symbols().

#define NO_OF_SYMBOLS_PREAMBLE_SFD   (NO_SYMBOLS_PREAMBLE + NO_SYMBOLS_SFD)

Number of symbols forming the synchronization header (SHR) for the current PHY.

This value is the base for the PHY PIB attribute phySHRDuration.

#define NO_SYMBOLS_PREAMBLE   (8)
#define NO_SYMBOLS_SFD   (2)
#define RF_BAND   BAND_2400
#define SYMBOL_MASK   (0x0FFFFFFF)

Symbol mask for ingnoring most significant nibble.

Referenced by tal_add_time_symbols(), and tal_sub_time_symbols().

#define SYMBOLS_PER_OCTET   (2)

4 bits form one symbol since O-QPSK is used

#define TAL_CONVERT_SYMBOLS_TO_US (   symbols)    ((uint32_t)(symbols) << 4)

Conversion of symbols to microseconds.

#define TAL_CONVERT_US_TO_SYMBOLS (   time)    ((time) >> 4)

Conversion of microseconds to symbols.

#define TAL_GET_BEACON_INTERVAL_TIME (   BO)    ((1UL * aBaseSuperframeDuration) << (BO))

Beacon Interval time in symbols.

#define TAL_GET_SUPERFRAME_DURATION_TIME (   SO)    ((1UL * aBaseSuperframeDuration) << (SO))

Superframe Duration time in symbols.

typedef enum csma_mode_tag csma_mode_t

CSMA Mode supported by transceiver.

typedef struct frame_info_tag frame_info_t

Globally used frame information structure.

Sleep Mode supported by transceiver.

CSMA Mode supported by transceiver.

Enumerator
NO_CSMA_NO_IFS 
NO_CSMA_WITH_IFS 
CSMA_UNSLOTTED 
CSMA_SLOTTED 
enum SHORTENUM

MAC Message types.

Enumerator
ASSOCIATIONREQUEST 
ASSOCIATIONRESPONSE 
DISASSOCIATIONNOTIFICATION 
DATAREQUEST 
PANIDCONFLICTNOTIFICAION 
ORPHANNOTIFICATION 
BEACONREQUEST 
COORDINATORREALIGNMENT 
ORPHANREALIGNMENT 
BEACON_MESSAGE 
DATAREQUEST_IMPL_POLL 
NULL_FRAME 
MCPS_MESSAGE 

Sleep Mode supported by transceiver.

Enumerator
SLEEP_MODE_1 

static uint32_t tal_add_time_symbols ( uint32_t  a,
uint32_t  b 
)
inlinestatic

Adds two time values.

This function adds two time values

Parameters
aTime value 1
bTime value 2
Returns
value of a + b

References SYMBOL_MASK.

void tal_ed_end_cb ( uint8_t  energy_level)

User call back function for finished ED Scan.

Parameters
energy_levelMeasured energy level during ED Scan
retval_t tal_ed_start ( uint8_t  scan_duration)

Starts ED Scan.

This function starts an ED Scan for the scan duration specified by the MAC layer.

Parameters
scan_durationSpecifies the ED scan duration in symbols
Returns
MAC_SUCCESS - ED scan duration timer started successfully TAL_BUSY - TAL is busy servicing the previous request from MAC TAL_TRX_ASLEEP - Transceiver is currently sleeping FAILURE otherwise
void tal_generate_rand_seed ( void  )

Generates a 16-bit random number used as initial seed for srand()

This function generates a 16-bit random number by means of using the Random Number Generator from the transceiver. The Random Number Generator generates 2-bit random values. These 2-bit random values are concatenated to the required 16-bit random seed. The generated random 16-bit number is feed into function srand() as initial seed. The transceiver state is initally set to RX_ON. After the completion of the random seed generation, the trancseiver is set to TRX_OFF.

retval_t tal_init ( void  )

Initializes the TAL.

This function is called to initialize the TAL. The transceiver is initialized, the TAL PIBs are set to their default values, and the TAL state machine is set to TAL_IDLE state.

Returns
MAC_SUCCESS if the transceiver state is changed to TRX_OFF and the current device part number and version number are correct; FAILURE otherwise
retval_t tal_pib_get ( uint8_t  attribute,
uint8_t *  value 
)

Gets a TAL PIB attribute.

This function is called to retrieve the transceiver information base attributes.

Parameters
[in]attributeTAL infobase attribute ID
[out]valueTAL infobase attribute value
Returns
MAC_UNSUPPORTED_ATTRIBUTE if the TAL infobase attribute is not found MAC_SUCCESS otherwise
retval_t tal_pib_set ( uint8_t  attribute,
pib_value_t value 
)

Sets a TAL PIB attribute.

This function is called to set the transceiver information base attributes.

Parameters
attributeTAL infobase attribute ID
valueTAL infobase attribute value to be set
Returns
MAC_UNSUPPORTED_ATTRIBUTE if the TAL info base attribute is not found TAL_BUSY if the TAL is not in TAL_IDLE state. An exception is macBeaconTxTime which can be accepted by TAL even if TAL is not in TAL_IDLE state. MAC_SUCCESS if the attempt to set the PIB attribute was successful TAL_TRX_ASLEEP if trx is in SLEEP mode and access to trx is required
retval_t tal_reset ( bool  set_default_pib)

Resets TAL state machine and sets the default PIB values if requested.

Parameters
set_default_pibDefines whether PIB values need to be set to its default values
Returns
MAC_SUCCESS if the transceiver state is changed to TRX_OFF FAILURE otherwise
uint8_t tal_rx_enable ( uint8_t  state)

Switches receiver on or off.

This function switches the receiver on (PHY_RX_ON) or off (PHY_TRX_OFF).

Parameters
stateNew state of receiver
Returns
TAL_BUSY if the TAL state machine cannot switch receiver on or off, TRX_OFF if receiver has been switched off, or RX_ON otherwise.
void tal_rx_frame_cb ( frame_info_t rx_frame)

User call back function for frame reception.

Parameters
rx_framePointer to received frame structure of type frame_info_t or to received frame array
static uint32_t tal_sub_time_symbols ( uint32_t  a,
uint32_t  b 
)
inlinestatic

Subtract two time values.

This function subtracts two time values taking care of roll over.

Parameters
aTime value 1
bTime value 2
Returns
value a - b

References MAX_SYMBOL_TIME, and SYMBOL_MASK.

void tal_task ( void  )

TAL task handling.

This function

  • Checks and allocates the receive buffer.
  • Processes the TAL incoming frame queue.
  • Implements the TAL state machine.
retval_t tal_trx_sleep ( sleep_mode_t  mode)

Sets the transceiver to sleep.

This function sets the transceiver to sleep state.

Parameters
modeDefines sleep mode of transceiver SLEEP or PHY_TRX_OFF)
Returns
TAL_BUSY - The transceiver is busy in TX or RX MAC_SUCCESS - The transceiver is put to sleep TAL_TRX_ASLEEP - The transceiver is already asleep MAC_INVALID_PARAMETER - The specified sleep mode is not supported
retval_t tal_trx_wakeup ( void  )

Wakes up the transceiver from sleep.

This function awakes the transceiver from sleep state.

Returns
TAL_TRX_AWAKE - The transceiver is already awake MAC_SUCCESS - The transceiver is woken up from sleep FAILURE - The transceiver did not wake-up from sleep
retval_t tal_tx_frame ( frame_info_t tx_frame,
csma_mode_t  csma_mode,
bool  perform_frame_retry 
)

Requests to TAL to transmit frame.

This function is called by the MAC to deliver a frame to the TAL to be transmitted by the transceiver.

Parameters
tx_framePointer to the frame_info_t structure or to frame array to be transmitted
csma_modeIndicates mode of csma-ca to be performed for this frame
perform_frame_retryIndicates whether to retries are to be performed for this frame
Returns
MAC_SUCCESS if the TAL has accepted the data from the MAC for frame transmission TAL_BUSY if the TAL is busy servicing the previous MAC request
void tal_tx_frame_done_cb ( retval_t  status,
frame_info_t frame 
)

User call back function for frame transmission.

Parameters
statusStatus of frame transmission attempt
framePointer to frame structure of type frame_info_t

uint8_t tal_pib_CCAMode

CCA Mode.

uint8_t tal_pib_CurrentChannel

Current RF channel to be used for all transmissions and receptions.

uint8_t tal_pib_CurrentPage

Current channel page.

uint64_t tal_pib_IeeeAddress

64-bit (IEEE) address of the node.

uint8_t tal_pib_MaxBE

The maximum value of the backoff exponent BE in the CSMA-CA algorithm.

uint8_t tal_pib_MaxCSMABackoffs

The maximum number of back-offs the CSMA-CA algorithm will attempt before declaring a CSMA_CA failure.

uint16_t tal_pib_MaxFrameDuration

Maximum number of symbols in a frame: = phySHRDuration + ceiling([aMaxPHYPacketSize + 1] x phySymbolsPerOctet)

uint8_t tal_pib_MaxFrameRetries

The maximum number of retries allowed after a transmission failure.

uint8_t tal_pib_MinBE

The minimum value of the backoff exponent BE in the CSMA-CA algorithm.

uint16_t tal_pib_PANId

16-bit PAN ID

bool tal_pib_PrivatePanCoordinator

Indicates if the node is a PAN coordinator or not.

uint16_t tal_pib_ShortAddress

16-bit short address of the node.

uint8_t tal_pib_SHRDuration

Duration of the synchronization header (SHR) in symbols for the current PHY.

uint32_t tal_pib_SupportedChannels

Supported channels.

uint8_t tal_pib_SymbolsPerOctet

Number of symbols per octet for the current PHY.

uint8_t tal_pib_TransmitPower

Default value of transmit power of transceiver using IEEE defined format of phyTransmitPower.