Microchip® Advanced Software Framework

main.c File Reference

MAC Example Nobeacon Application - Device.

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 "common_hw_timer.h"
#include "beacon_app.h"
#include <asf.h>

Macros

#define APP_GUARD_TIME_US   (10000)
 
#define APP_POLL_PERIOD_MS   (5000)
 This is the time period in micro seconds for polling transmissions. More...
 
#define CHANNEL_OFFSET   (2)
 Channel Offset will give us the channel number as (CHANNEL_OFFSET + 11) More...
 
#define LED_DATA   (LED0)
 
#define LED_DATA   (LED0)
 
#define LED_NWK_SETUP   (LED0)
 
#define LED_ON_DURATION   (500000)
 Define the LED on duration time. More...
 
#define LED_START   (LED0)
 
#define MCU_WAKEUP_TIME   (150)
 
#define PAYLOAD_LEN   (104)
 
#define SCAN_DURATION_LONG   (6)
 Defines the long scan duration time. More...
 
#define SCAN_DURATION_SHORT   (5)
 Defines the short scan duration time. More...
 
#define TIMER_SYNC_BEFORE_ASSOC_MS   (3000)
 

Functions

static void app_alert (void)
 Alert to indicate something has gone wrong in the application. More...
 
static void app_initiate_polling (void *parameter)
 Callback function for the application timer initiating polling of coordinator. More...
 
int main (void)
 Main function of the device application. More...
 
static void network_search_indication_cb (void *parameter)
 Callback function indicating network search. 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...
 
static void rx_data_led_off_cb (void *parameter)
 Callback function for switching off the LED after data reception. More...
 
static void send_data (uint8_t *data)
 function for the sending received data back to coordinator 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_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_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_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_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_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

app_state_t app_state = APP_IDLE
 This variable stores the current state of the node. More...
 
static uint8_t APP_TIMER
 
static uint8_t APP_TIMER_POLL_DATA
 
static uint32_t bc_rx_cnt
 
static uint32_t channels_supported
 
static uint16_t coord_addr
 This structure stores the short address of the coordinator. More...
 
wpan_addr_spec_t coord_addr_spec
 
uint8_t current_channel
 
uint8_t current_channel_page
 
uint8_t default_key_source [8]
 
static uint32_t indirect_rx_cnt
 
static uint8_t msdu_payload [PAYLOAD_LEN]
 This array stores the current msdu payload. More...
 

#define APP_GUARD_TIME_US   (10000)

Referenced by main().

#define APP_POLL_PERIOD_MS   (5000)

This is the time period in micro seconds for polling transmissions.

Referenced by usr_mlme_associate_conf(), and usr_mlme_poll_conf().

#define CHANNEL_OFFSET   (2)

Channel Offset will give us the channel number as (CHANNEL_OFFSET + 11)

Referenced by usr_mlme_get_conf().

#define LED_DATA   (LED0)
#define LED_DATA   (LED0)
#define LED_NWK_SETUP   (LED0)
#define LED_ON_DURATION   (500000)

Define the LED on duration time.

Referenced by network_search_indication_cb(), usr_mcps_data_ind(), and usr_mlme_get_conf().

#define LED_START   (LED0)

Referenced by main().

#define MCU_WAKEUP_TIME   (150)
#define PAYLOAD_LEN   (104)
#define SCAN_DURATION_LONG   (6)

Defines the long scan duration time.

Referenced by usr_mlme_get_conf(), and usr_mlme_scan_conf().

#define SCAN_DURATION_SHORT   (5)

Defines the short scan duration time.

Referenced by usr_mlme_scan_conf().

#define TIMER_SYNC_BEFORE_ASSOC_MS   (3000)

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 void app_initiate_polling ( void *  parameter)
static

Callback function for the application timer initiating polling of coordinator.

Parameters
parameterPointer to callback parameter (not used in this application, but could be if desired).

References wpan_addr_spec_tag::Addr, wpan_addr_spec_tag::AddrMode, coord_addr, coord_addr_spec, DEFAULT_PAN_ID, wpan_addr_spec_tag::PANId, address_field_t::short_address, WPAN_ADDRMODE_SHORT, and wpan_mlme_poll_req().

Referenced by usr_mlme_associate_conf(), and usr_mlme_poll_conf().

static void network_search_indication_cb ( void *  parameter)
static

Callback function indicating network search.

Parameters
parameterPointer to callback parameter (not used in this application, but could be if desired).

References APP_TIMER, FUNC_PTR, LED_NWK_SETUP, LED_ON_DURATION, LED_Toggle, SW_TIMEOUT_RELATIVE, and sw_timer_start().

Referenced by usr_mlme_get_conf().

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

static void rx_data_led_off_cb ( void *  parameter)
static

Callback function for switching off the LED after data reception.

Parameters
parameterPointer to callback parameter (not used in this application, but could be if desired).

References LED_DATA, and LED_Off.

Referenced by usr_mcps_data_ind().

static void send_data ( uint8_t *  data)
static

function for the sending received data back to coordinator

Parameters
dataPointer to received data

References wpan_addr_spec_tag::Addr, ADDR_COPY_DST_SRC_16, wpan_addr_spec_tag::AddrMode, coord_addr, DEFAULT_PAN_ID, wpan_addr_spec_tag::PANId, address_field_t::short_address, WPAN_ADDRMODE_SHORT, wpan_mcps_data_req(), and WPAN_TXOPT_ACK.

Referenced by usr_mcps_data_ind().

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 
)

app_state_t app_state = APP_IDLE

This variable stores the current state of the node.

Referenced by usr_mlme_associate_conf(), usr_mlme_beacon_notify_ind(), usr_mlme_reset_conf(), usr_mlme_scan_conf(), and usr_mlme_set_conf().

uint8_t APP_TIMER_POLL_DATA
static
uint32_t bc_rx_cnt
static

Referenced by usr_mcps_data_ind().

uint32_t channels_supported
static

Referenced by usr_mlme_get_conf().

uint16_t coord_addr
static

This structure stores the short address of the coordinator.

Referenced by app_initiate_polling(), mlme_poll_request(), and send_data().

wpan_addr_spec_t coord_addr_spec

Referenced by app_initiate_polling().

uint8_t default_key_source[8]

Referenced by usr_mlme_reset_conf().

uint32_t indirect_rx_cnt
static

Referenced by usr_mcps_data_ind().

uint8_t msdu_payload[PAYLOAD_LEN]
static

This array stores the current msdu payload.

Referenced by usr_mlme_beacon_notify_ind().