Microchip® Advanced Software Framework

main.c File Reference

MAC Example Nobeacon Application - Coordinator.

Copyright (c) 2013-2018 Microchip Technology Inc. and its subsidiaries.

#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_INDIRECT_DATA_DURATION_MS   (6000)
 Defines the time to initiate a indirect data transmission to the device. More...
 
#define CHANNEL_OFFSET   (2)
 
#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   (15)
 Defines Beacon Order for Nobeacon Network. 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   (15)
 Defines Superframe Order for Nobeacon Network. 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 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_mcps_purge_conf (uint8_t msduHandle, uint8_t status)
 Callback function that must be implemented by application (NHLE) for MAC service MCPS-PURGE.confirm. More...
 
void usr_mlme_associate_conf (uint16_t AssocShortAddress, uint8_t status)
 Callback function that must be implemented by application (NHLE) for MAC service MLME-ASSOCIATE.confirm. More...
 
void usr_mlme_associate_ind (uint64_t DeviceAddress, uint8_t CapabilityInformation)
 Callback function that must be implemented by application (NHLE) for MAC service MLME-ASSOCIATE.indication. More...
 
void usr_mlme_beacon_notify_ind (uint8_t BSN, wpan_pandescriptor_t *PANDescriptor, uint8_t PendAddrSpec, uint8_t *AddrList, uint8_t sduLength, uint8_t *sdu)
 Callback function that must be implemented by application (NHLE) for MAC service MLME-BEACON-NOTIFY.indication. More...
 
void usr_mlme_comm_status_ind (wpan_addr_spec_t *SrcAddrSpec, wpan_addr_spec_t *DstAddrSpec, uint8_t status)
 Callback function that must be implemented by application (NHLE) for MAC service MLME-COMM-STATUS.indication. More...
 
void usr_mlme_disassociate_conf (uint8_t status, wpan_addr_spec_t *DeviceAddrSpec)
 Callback function that must be implemented by application (NHLE) for MAC service MLME-DISASSOCIATE.confirm. More...
 
void usr_mlme_disassociate_ind (uint64_t DeviceAddress, uint8_t DisassociateReason)
 Callback function that must be implemented by application (NHLE) for MAC service MLME-DISASSOCIATE.indication. More...
 
void usr_mlme_get_conf (uint8_t status, uint8_t PIBAttribute, void *PIBAttributeValue)
 Callback function that must be implemented by application (NHLE) for MAC service MLME-GET.confirm. More...
 
void usr_mlme_orphan_ind (uint64_t OrphanAddress)
 Callback function that must be implemented by application (NHLE) for MAC service MLME-ORPHAN.indication. More...
 
void usr_mlme_poll_conf (uint8_t status)
 Callback function that must be implemented by application (NHLE) for MAC service MLME-POLL.confirm. More...
 
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_rx_enable_conf (uint8_t status)
 Callback function that must be implemented by application (NHLE) for MAC service MLME-RX-ENABLE.confirm. More...
 
void usr_mlme_scan_conf (uint8_t status, uint8_t ScanType, uint8_t ChannelPage, uint32_t UnscannedChannels, uint8_t ResultListSize, void *ResultList)
 Callback function that must be implemented by application (NHLE) for MAC service MLME-SCAN.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_start_conf (uint8_t status)
 Callback function that must be implemented by application (NHLE) for MAC service MLME-START.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_INDIRECT_DATA
 
uint8_t beacon_payload [] = {"Atmel beacon demo 0"}
 This array stores the current beacon payload. More...
 
uint8_t broadcast_payload [] = {"Broadcast Data"}
 
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_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 wpan_addr_spec_t dst_addr
 
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.

Referenced by bc_data_cb(), and usr_mlme_start_conf().

#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(), and usr_mlme_start_conf().

#define APP_INDIRECT_DATA_DURATION_MS   (6000)

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

Referenced by indirect_data_cb(), and usr_mlme_comm_status_ind().

#define CHANNEL_OFFSET   (2)

Referenced by usr_mlme_get_conf().

#define DEBOUNCE_DELAY_MS   (200)

Referenced by main().

#define DEFAULT_BEACON_KEY_INDEX   (0x00)

Defines the default Beacon KeyIndex.

Referenced by usr_mlme_scan_conf().

#define DEFAULT_BEACON_KEY_SRC   (default_key_source)

Defines the default Beacon KeySource.

Referenced by usr_mlme_scan_conf().

#define DEFAULT_BEACON_KEYID_MODE   (0x01)

Defines the default Beacon KeyIdMode.

Referenced by usr_mlme_scan_conf().

#define DEFAULT_BEACON_SEC_LVL   (0x05)

Defines the default Beacon Security Level.

Referenced by usr_mlme_scan_conf().

#define DEFAULT_BO   (15)

Defines Beacon Order for Nobeacon Network.

Referenced by usr_mlme_scan_conf().

#define DEFAULT_COORDREALIGN_KEY_INDEX   (0x00)

Defines the default Coord Realign KeyIndex.

Referenced by usr_mlme_scan_conf().

#define DEFAULT_COORDREALIGN_KEY_SRC   (NULL)

Defines the default Coord Realign KeySource.

Referenced by usr_mlme_scan_conf().

#define DEFAULT_COORDREALIGN_KEYID_MODE   (0x00)

Defines the default Coord Realign KeyIdMode.

Referenced by usr_mlme_scan_conf().

#define DEFAULT_COORDREALIGN_SEC_LVL   (0x00)

Defines the default Coord Realign SecurityLevel.

Referenced by usr_mlme_scan_conf().

#define DEFAULT_COORDREALIGNMENT   (false)

Coord Realignment is not used by default in this application.

Referenced by usr_mlme_scan_conf().

#define DEFAULT_SO   (15)

Defines Superframe Order for Nobeacon Network.

Referenced by usr_mlme_scan_conf().

#define LED_DATA   (LED0)

Referenced by main(), and usr_mcps_data_conf().

#define LED_NWK_SETUP   (LED0)

Referenced by main(), and usr_mlme_start_conf().

#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, LED0, and LED_Toggle.

Referenced by main().

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.

Referenced by usr_mlme_associate_ind().

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_BC_DATA_DURATION_MS, APP_TIMER_BC_DATA, BROADCAST, DEFAULT_PAN_ID, dst_addr, FUNC_PTR, wpan_addr_spec_tag::PANId, address_field_t::short_address, SW_TIMEOUT_RELATIVE, sw_timer_start(), tx_cnt, WPAN_ADDRMODE_SHORT, wpan_mcps_data_req(), and WPAN_TXOPT_OFF.

Referenced by usr_mlme_start_conf().

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().

Referenced by usr_mlme_start_conf().

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, dst_addr, FUNC_PTR, 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_INDIRECT_ACK.

Referenced by usr_mlme_comm_status_ind().

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
uint8_t APP_TIMER_BCN_PAYLOAD_UPDATE
static
uint8_t APP_TIMER_INDIRECT_DATA
static
uint8_t beacon_payload[] = {"Atmel beacon demo 0"}

This array stores the current beacon payload.

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

uint8_t broadcast_payload[] = {"Broadcast Data"}

Referenced by main().

uint32_t channels_supported
static

Referenced by usr_mlme_get_conf().

This variable stores the current state of the node.

Referenced by usr_mlme_set_conf(), and usr_mlme_start_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_page
uint8_t default_key_source[8]

Referenced by usr_mlme_get_conf().

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_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: "
uint16_t no_of_assoc_devices

Stores the number of associated devices.

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

uint32_t tx_cnt
static

This variable counts the number of transmitted data frames.

Referenced by bc_data_cb().