Atmel Software Framework

thirdparty/wireless/avr2025_mac/apps/mac/beacon/coord/main.c File Reference
#include <string.h>
#include <inttypes.h>
#include <stdio.h>
#include "conf_board.h"
#include "avr2025_mac.h"
#include "delay.h"
#include "common_sw_timer.h"
#include "sio2host.h"
#include <asf.h>
#include "beacon_app.h"

Macros

#define APP_BC_DATA_DURATION_MS   (9000)
 Defines the time in ms to initiate a broadcast data transmission to all devices. More...
 
#define APP_BCN_PAYLOAD_DURATION_MS   (3000)
 Defines the time in ms to initiate an update of the beacon payload. More...
 
#define APP_GTS_DATA_DURATION_MS   (2000)
 Defines the time to initiate a GTS data transmission to the device. More...
 
#define APP_INDIRECT_DATA_DURATION_MS   (6000)
 Defines the time to initiate a indirect data transmission to the device. More...
 
#define CHANNEL_OFFSET   (0)
 
#define DEBOUNCE_DELAY_MS   (200)
 
#define DEFAULT_BEACON_KEY_INDEX   (0x00)
 Defines the default Beacon KeyIndex. More...
 
#define DEFAULT_BEACON_KEY_SRC   (default_key_source)
 Defines the default Beacon KeySource. More...
 
#define DEFAULT_BEACON_KEYID_MODE   (0x01)
 Defines the default Beacon KeyIdMode. More...
 
#define DEFAULT_BEACON_SEC_LVL   (0x05)
 Defines the default Beacon Security Level. More...
 
#define DEFAULT_BO   (5)
 Defines the default Beacon Order. More...
 
#define DEFAULT_COORDREALIGN_KEY_INDEX   (0x00)
 Defines the default Coord Realign KeyIndex. More...
 
#define DEFAULT_COORDREALIGN_KEY_SRC   (NULL)
 Defines the default Coord Realign KeySource. More...
 
#define DEFAULT_COORDREALIGN_KEYID_MODE   (0x00)
 Defines the default Coord Realign KeyIdMode. More...
 
#define DEFAULT_COORDREALIGN_SEC_LVL   (0x00)
 Defines the default Coord Realign SecurityLevel. More...
 
#define DEFAULT_COORDREALIGNMENT   (false)
 Coord Realignment is not used by default in this application. More...
 
#define DEFAULT_SO   (4)
 Defines the default Super frame Order. More...
 
#define LED_DATA   (LED0)
 
#define LED_NWK_SETUP   (LED0)
 
#define LED_START   (LED0)
 

Functions

static void app_alert (void)
 Alert to indicate something has gone wrong in the application. More...
 
static bool assign_new_short_addr (uint64_t addr64, uint16_t *addr16)
 Application specific function to assign a short address. More...
 
static void bc_data_cb (void *parameter)
 Callback function for initiation of broadcast data transmission. More...
 
static void bcn_payload_update_cb (void *parameter)
 Callback function for updating the beacon payload. More...
 
static void gts_data_cb (void *parameter)
 Callback function for initiation of gts data transmission. More...
 
static void indirect_data_cb (void *parameter)
 Callback function for initiation of indirect data transmission. More...
 
int main (void)
 Main function of the coordinator application. More...
 
static void print_stack_app_build_features (void)
 This function shows the stack and application capabilities on terminal if SIO_HUB switch is enabled. More...
 
void usr_mcps_data_conf (uint8_t msduHandle, uint8_t status, uint32_t Timestamp)
 Callback function that must be implemented by application (NHLE) for MAC service MCPS-DATA.confirm. More...
 
void usr_mcps_data_ind (wpan_addr_spec_t *SrcAddrSpec, wpan_addr_spec_t *DstAddrSpec, uint8_t msduLength, uint8_t *msdu, uint8_t mpduLinkQuality, uint8_t DSN, uint32_t Timestamp)
 
void usr_mlme_gts_conf (gts_char_t GtsChar, uint8_t status)
 
void usr_mlme_gts_ind (uint16_t DeviceAddr, gts_char_t GtsChar)
 
void usr_mlme_reset_conf (uint8_t status)
 Callback function that must be implemented by application (NHLE) for MAC service MLME-RESET.confirm. More...
 
void usr_mlme_set_conf (uint8_t status, uint8_t PIBAttribute)
 Callback function that must be implemented by application (NHLE) for MAC service MLME-SET.confirm. More...
 
void usr_mlme_sync_loss_ind (uint8_t LossReason, uint16_t PANId, uint8_t LogicalChannel, uint8_t ChannelPage)
 Callback function that must be implemented by application (NHLE) for MAC service MLME-SYNC-LOSS.indication. More...
 

Variables

static uint8_t APP_TIMER_BC_DATA
 
static uint8_t APP_TIMER_BCN_PAYLOAD_UPDATE
 
static uint8_t APP_TIMER_GTS_DATA
 
static uint8_t APP_TIMER_INDIRECT_DATA
 
uint8_t beacon_payload [] = {"Atmel beacon demo 0"}
 This array stores the current beacon payload. More...
 
static uint32_t channels_supported
 
coord_state_t coord_state = COORD_STARTING
 This variable stores the current state of the node. More...
 
static uint8_t curr_msdu_handle
 Store the current MSDU handle to be used for a data frame. More...
 
uint8_t current_channel
 
uint8_t current_channel_page
 
uint8_t default_key_source [8]
 
associated_device_t device_list [MAX_NUMBER_OF_DEVICES]
 This array stores all device related information. More...
 
const char Dispaly_Result_Frame [] = "Result frame with handle %u : "
 
const char Display_Associated_Device [] = "Device %u associated\r\n"
 
const char Display_Broadcast_Tx_Count [] = "Broadcast frame Tx count: %lu\r\n"
 
const char Display_GTS_Data [] = "GTS data for device %" PRIu8 " "
 
const char Display_MSDU_Handle [] = "(MSDU handle: %u)\r\n"
 
const char Display_Queue_Device_Data [] = "Queue data for device %u "
 
const char Display_Rx_Frame_Address [] = "Rx frame from Device Addr%x: "
 
static uint8_t gts_msdu_handle
 
static uint8_t gts_payload [] = {"GTS Data from coordinator"}
 
uint16_t no_of_assoc_devices
 Stores the number of associated devices. More...
 
static uint32_t tx_cnt
 This variable counts the number of transmitted data frames. More...
 

#define APP_BC_DATA_DURATION_MS   (9000)

Defines the time in ms to initiate a broadcast data transmission to all devices.

#define APP_BCN_PAYLOAD_DURATION_MS   (3000)

Defines the time in ms to initiate an update of the beacon payload.

Referenced by bcn_payload_update_cb().

#define APP_GTS_DATA_DURATION_MS   (2000)

Defines the time to initiate a GTS data transmission to the device.

Referenced by gts_data_cb(), and usr_mlme_gts_ind().

#define APP_INDIRECT_DATA_DURATION_MS   (6000)

Defines the time to initiate a indirect data transmission to the device.

Referenced by indirect_data_cb().

#define CHANNEL_OFFSET   (0)
#define DEBOUNCE_DELAY_MS   (200)

Referenced by main().

#define DEFAULT_BEACON_KEY_INDEX   (0x00)

Defines the default Beacon KeyIndex.

#define DEFAULT_BEACON_KEY_SRC   (default_key_source)

Defines the default Beacon KeySource.

#define DEFAULT_BEACON_KEYID_MODE   (0x01)

Defines the default Beacon KeyIdMode.

#define DEFAULT_BEACON_SEC_LVL   (0x05)

Defines the default Beacon Security Level.

#define DEFAULT_BO   (5)

Defines the default Beacon Order.

#define DEFAULT_COORDREALIGN_KEY_INDEX   (0x00)

Defines the default Coord Realign KeyIndex.

#define DEFAULT_COORDREALIGN_KEY_SRC   (NULL)

Defines the default Coord Realign KeySource.

#define DEFAULT_COORDREALIGN_KEYID_MODE   (0x00)

Defines the default Coord Realign KeyIdMode.

#define DEFAULT_COORDREALIGN_SEC_LVL   (0x00)

Defines the default Coord Realign SecurityLevel.

#define DEFAULT_COORDREALIGNMENT   (false)

Coord Realignment is not used by default in this application.

#define DEFAULT_SO   (4)

Defines the default Super frame Order.

#define LED_DATA   (LED0)

Referenced by main(), and usr_mcps_data_conf().

#define LED_NWK_SETUP   (LED0)

Referenced by main().

#define LED_START   (LED0)

Referenced by main().

static void app_alert ( void  )
static

Alert to indicate something has gone wrong in the application.

References delay_us.

static bool assign_new_short_addr ( uint64_t  addr64,
uint16_t *  addr16 
)
static

Application specific function to assign a short address.

References CPU_ENDIAN_TO_LE16, associated_device_tag::ieee_addr, MAX_NUMBER_OF_DEVICES, no_of_assoc_devices, and associated_device_tag::short_addr.

static void bc_data_cb ( void *  parameter)
static

Callback function for initiation of broadcast data transmission.

Parameters
parameterPointer to callback parameter (not used in this application, but could be used to indicated LED to be switched off)

References wpan_addr_spec_tag::Addr, wpan_addr_spec_tag::AddrMode, APP_TIMER_BC_DATA, BROADCAST, DEFAULT_PAN_ID, FUNC_PTR, wpan_addr_spec_tag::PANId, payload, address_field_t::short_address, SW_TIMEOUT_RELATIVE, sw_timer_start(), tx_cnt, WPAN_ADDRMODE_SHORT, wpan_mcps_data_req(), and WPAN_TXOPT_OFF.

static void bcn_payload_update_cb ( void *  parameter)
static

Callback function for updating the beacon payload.

Parameters
parameterPointer to callback parameter (not used in this application, but could be used to indicated LED to be switched off)

References APP_BCN_PAYLOAD_DURATION_MS, APP_TIMER_BCN_PAYLOAD_UPDATE, beacon_payload, BEACON_PAYLOAD_LEN, FUNC_PTR, macBeaconPayload, SW_TIMEOUT_RELATIVE, sw_timer_start(), and wpan_mlme_set_req().

static void gts_data_cb ( void *  parameter)
static

Callback function for initiation of gts data transmission.

Parameters
parameterPointer to callback parameter (not used in this application, but could be used to indicated LED to be switched off)

References wpan_addr_spec_tag::Addr, wpan_addr_spec_tag::AddrMode, APP_GTS_DATA_DURATION_MS, APP_TIMER_GTS_DATA, DEFAULT_PAN_ID, FUNC_PTR, gts_msdu_handle, gts_payload, no_of_assoc_devices, wpan_addr_spec_tag::PANId, associated_device_tag::short_addr, address_field_t::short_address, SW_TIMEOUT_RELATIVE, sw_timer_start(), WPAN_ADDRMODE_SHORT, wpan_mcps_data_req(), and WPAN_TXOPT_GTS_ACK.

Referenced by usr_mlme_gts_ind().

static void indirect_data_cb ( void *  parameter)
static

Callback function for initiation of indirect data transmission.

Parameters
parameterPointer to callback parameter (not used in this application, but could be used to indicated LED to be switched off)

References wpan_addr_spec_tag::Addr, wpan_addr_spec_tag::AddrMode, APP_INDIRECT_DATA_DURATION_MS, APP_TIMER_INDIRECT_DATA, curr_msdu_handle, DEFAULT_PAN_ID, FUNC_PTR, no_of_assoc_devices, wpan_addr_spec_tag::PANId, payload, associated_device_tag::short_addr, address_field_t::short_address, SW_TIMEOUT_RELATIVE, sw_timer_start(), WPAN_ADDRMODE_SHORT, wpan_mcps_data_req(), and WPAN_TXOPT_INDIRECT_ACK.

static void print_stack_app_build_features ( void  )
static

This function shows the stack and application capabilities on terminal if SIO_HUB switch is enabled.

Referenced by main().

void usr_mcps_data_ind ( wpan_addr_spec_t SrcAddrSpec,
wpan_addr_spec_t DstAddrSpec,
uint8_t  msduLength,
uint8_t *  msdu,
uint8_t  mpduLinkQuality,
uint8_t  DSN,
uint32_t  Timestamp 
)

uint8_t APP_TIMER_BC_DATA
static

Referenced by bc_data_cb(), and main().

uint8_t APP_TIMER_BCN_PAYLOAD_UPDATE
static

Referenced by bcn_payload_update_cb(), and main().

uint8_t APP_TIMER_GTS_DATA
static

Referenced by gts_data_cb(), main(), and usr_mlme_gts_ind().

uint8_t APP_TIMER_INDIRECT_DATA
static

Referenced by indirect_data_cb(), and main().

uint8_t beacon_payload[] = {"Atmel beacon demo 0"}

This array stores the current beacon payload.

Referenced by bcn_payload_update_cb(), parse_mpdu(), and usr_mlme_set_conf().

uint32_t channels_supported
static

This variable stores the current state of the node.

Referenced by usr_mlme_set_conf().

uint8_t curr_msdu_handle
static

Store the current MSDU handle to be used for a data frame.

Referenced by indirect_data_cb().

uint8_t current_channel
uint8_t current_channel_page
uint8_t default_key_source[8]

This array stores all device related information.

const char Dispaly_Result_Frame[] = "Result frame with handle %u : "

Referenced by usr_mcps_data_conf().

const char Display_Associated_Device[] = "Device %u associated\r\n"
const char Display_Broadcast_Tx_Count[] = "Broadcast frame Tx count: %lu\r\n"
const char Display_GTS_Data[] = "GTS data for device %" PRIu8 " "
const char Display_MSDU_Handle[] = "(MSDU handle: %u)\r\n"
const char Display_Queue_Device_Data[] = "Queue data for device %u "
const char Display_Rx_Frame_Address[] = "Rx frame from Device Addr%x: "
uint8_t gts_msdu_handle
static

Referenced by gts_data_cb().

uint8_t gts_payload[] = {"GTS Data from coordinator"}
static

Referenced by gts_data_cb().

uint16_t no_of_assoc_devices

Stores the number of associated devices.

Referenced by assign_new_short_addr(), gts_data_cb(), and indirect_data_cb().

uint32_t tx_cnt
static

This variable counts the number of transmitted data frames.

Referenced by bc_data_cb().