Microchip® Advanced Software Framework

main.c File Reference

Mac Application - No beacon Sleep.

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

#include <string.h>
#include "conf_board.h"
#include "avr2025_mac.h"
#include "led.h"
#include "delay.h"
#include "common_sw_timer.h"
#include "sleepmgr.h"
#include <asf.h>

Data Structures

struct  associated_device_tag
 

Macros

#define CHANNEL_OFFSET   (0)
 
#define COORD_SHORT_ADDR   (0x0000)
 Defines the short address of the coordinator. More...
 
#define DATA_TX_PERIOD   (2000000)
 This is the time period in micro seconds for data transmissions. More...
 
#define DEFAULT_PAN_ID   CCPU_ENDIAN_TO_LE16(0xBABE)
 Defines the PAN ID of the network. More...
 
#define INTER_FRAME_DURATION_US   (200000)
 
#define LED_DATA   (LED0)
 
#define LED_NWK_SETUP   (LED0)
 
#define LED_START   (LED0)
 
#define MAX_NUMBER_OF_DEVICES   (2)
 Defines the maximum number of devices the coordinator will handle. More...
 
#define MAX_NUMBER_OF_SCANS   (3)
 Defines the maximum number of scans before starting own network. More...
 
#define SCAN_CHANNEL   (1ul << current_channel)
 
#define SCAN_DURATION   (4)
 Defines the scan duration time. More...
 

Typedefs

typedef struct
associated_device_tag 
associated_device_t
 This type definition of a structure can store the short address and the extended address of a device. More...
 
typedef enum node_status_tag node_status_t
 

Enumerations

enum  node_status_tag {
  COLD_START_RESET,
  PC_RUNNING,
  IDLE,
  TRANSMITTING
}
 

Functions

static void app_alert (void)
 
static void app_task (void)
 
static bool assign_new_short_addr (uint64_t addr64, uint16_t *addr16)
 
static void awake_timer_cb (void *parameter)
 
static void data_exchange_led_off_cb (void *parameter)
 
int main (void)
 Main function. More...
 
static void network_scan_indication_cb (void *parameter)
 
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 uint32_t channels_supported
 
static associated_device_t coord_addr
 This structure stores the short and extended address of the coordinator. More...
 
static uint8_t current_channel
 
static uint8_t current_channel_page
 
static associated_device_t device_list [MAX_NUMBER_OF_DEVICES]
 This array stores all device related information. More...
 
volatile bool in_sleep_mode = false
 
enum sleepmgr_mode mode = SLEEPMGR_ACTIVE
 
static node_status_t node_status
 Current status of the node. More...
 
static uint8_t number_of_scans
 Number of done network scans. More...
 
volatile bool timer_flag = false
 
static uint8_t TIMER_LED_OFF
 
static uint8_t WAKE_TIMER
 

#define CHANNEL_OFFSET   (0)

Referenced by usr_mlme_get_conf().

#define COORD_SHORT_ADDR   (0x0000)

Defines the short address of the coordinator.

Referenced by usr_mlme_scan_conf().

#define DATA_TX_PERIOD   (2000000)

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

Referenced by awake_timer_cb(), and usr_mlme_associate_conf().

#define DEFAULT_PAN_ID   CCPU_ENDIAN_TO_LE16(0xBABE)

Defines the PAN ID of the network.

Referenced by app_task(), usr_mlme_scan_conf(), and usr_mlme_set_conf().

#define INTER_FRAME_DURATION_US   (200000)
#define LED_NWK_SETUP   (LED0)
#define LED_START   (LED0)

Referenced by main().

#define MAX_NUMBER_OF_DEVICES   (2)

Defines the maximum number of devices the coordinator will handle.

Referenced by assign_new_short_addr().

#define MAX_NUMBER_OF_SCANS   (3)

Defines the maximum number of scans before starting own network.

Referenced by usr_mlme_scan_conf().

#define SCAN_CHANNEL   (1ul << current_channel)
#define SCAN_DURATION   (4)

Defines the scan duration time.

Referenced by usr_mlme_get_conf(), and usr_mlme_scan_conf().

This type definition of a structure can store the short address and the extended address of a device.

Enumerator
COLD_START_RESET 
PC_RUNNING 
IDLE 
TRANSMITTING 

static void app_alert ( void  )
static

References delay_us, LED0, and LED_Toggle.

Referenced by main().

static bool assign_new_short_addr ( uint64_t  addr64,
uint16_t *  addr16 
)
static
static void awake_timer_cb ( void *  parameter)
static
static void data_exchange_led_off_cb ( void *  parameter)
static

References LED_DATA, and LED_Off.

Referenced by usr_mcps_data_ind().

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

uint32_t channels_supported
static

Referenced by usr_mlme_get_conf().

associated_device_t coord_addr
static

This structure stores the short and extended address of the coordinator.

Referenced by mlme_poll_request().

uint8_t current_channel
static
uint8_t current_channel_page
static

This array stores all device related information.

volatile bool in_sleep_mode = false

Referenced by app_task(), and awake_timer_cb().

node_status_t node_status
static

Current status of the node.

Referenced by app_task(), main(), usr_mcps_data_conf(), usr_mlme_associate_conf(), and usr_mlme_start_conf().

uint8_t number_of_scans
static

Number of done network scans.

Referenced by usr_mlme_scan_conf().

volatile bool timer_flag = false

Referenced by app_task(), and awake_timer_cb().

uint8_t WAKE_TIMER
static

Referenced by main().