MAC Example Beacon 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_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_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_gts_conf (gts_char_t GtsChar, uint8_t status) |
void | usr_mlme_gts_ind (uint16_t DeviceAddr, gts_char_t GtsChar) |
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_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.
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_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(), and usr_mlme_comm_status_ind().
#define CHANNEL_OFFSET (0) |
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 (5) |
Defines the default Beacon Order.
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 (4) |
Defines the default Super frame Order.
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().
|
static |
Alert to indicate something has gone wrong in the application.
References delay_us, LED0, and LED_Toggle.
Referenced by main().
|
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 |
Callback function for initiation of broadcast data transmission.
parameter | Pointer 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, 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 |
Callback function for updating the beacon payload.
parameter | Pointer 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 |
Callback function for initiation of gts data transmission.
parameter | Pointer 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 |
Callback function for initiation of indirect data transmission.
parameter | Pointer 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, 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().
int main | ( | void | ) |
Main function of the coordinator application.
This function initializes the MAC, initiates a MLME reset request (wpan_mlme_reset_req()), and implements a the main loop.
References wpan_addr_spec_tag::Addr, wpan_addr_spec_tag::AddrMode, app_alert(), APP_TIMER_BC_DATA, APP_TIMER_BCN_PAYLOAD_UPDATE, APP_TIMER_GTS_DATA, APP_TIMER_INDIRECT_DATA, board_init(), BROADCAST, cpu_irq_enable, DEBOUNCE_DELAY_MS, DEFAULT_PAN_ID, delay_init(), delay_ms, FCF_SHORT_ADDR, irq_initialize_vectors, LED_DATA, LED_NWK_SETUP, LED_Off, LED_On, LED_START, MAC_SUCCESS, wpan_addr_spec_tag::PANId, print_stack_app_build_features(), address_field_t::short_address, sio2host_getchar(), sio2host_init(), sw_timer_get_id(), sw_timer_init(), system_init(), wpan_init(), wpan_mcps_data_req(), wpan_mlme_reset_req(), wpan_task(), and WPAN_TXOPT_OFF.
|
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 | ||
) |
References wpan_addr_spec_tag::Addr, LE16_TO_CPU_ENDIAN, and address_field_t::short_address.
Referenced by mcps_data_ind().
|
static |
Referenced by bc_data_cb(), main(), and usr_mlme_start_conf().
|
static |
Referenced by bcn_payload_update_cb(), main(), and usr_mlme_start_conf().
|
static |
Referenced by gts_data_cb(), main(), and usr_mlme_gts_ind().
|
static |
Referenced by indirect_data_cb(), main(), and usr_mlme_comm_status_ind().
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().
|
static |
Referenced by usr_mlme_get_conf().
coord_state_t coord_state = COORD_STARTING |
This variable stores the current state of the node.
Referenced by usr_mlme_set_conf(), and usr_mlme_start_conf().
|
static |
Store the current MSDU handle to be used for a data frame.
Referenced by indirect_data_cb().
uint8_t current_channel |
Referenced by usr_mlme_get_conf(), usr_mlme_scan_conf(), usr_mlme_set_conf(), and usr_mlme_start_conf().
uint8_t current_channel_page |
Referenced by usr_mlme_get_conf(), usr_mlme_scan_conf(), and usr_mlme_set_conf().
uint8_t default_key_source[8] |
Referenced by usr_mlme_get_conf().
associated_device_t device_list[MAX_NUMBER_OF_DEVICES] |
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: " |
|
static |
Referenced by gts_data_cb().
|
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(), indirect_data_cb(), and usr_mlme_comm_status_ind().
|
static |
This variable counts the number of transmitted data frames.
Referenced by bc_data_cb().