LORAWAN Demo Application.
Copyright (c) 2019-2020 Microchip Technology Inc. and its subsidiaries.
#include "asf.h"
#include "lorawan.h"
#include "system_task_manager.h"
#include "enddevice_demo.h"
#include "conf_app.h"
#include "sio2host.h"
#include "resources.h"
#include "delay.h"
#include "sw_timer.h"
#include "LED.h"
#include "pmm.h"
#include "radio_driver_hal.h"
#include "conf_pmm.h"
#include "conf_sio2host.h"
#include "pds_interface.h"
#include "conf_certification.h"
#include "enddevice_cert.h"
#include "atomic.h"
#include <stdint.h>
Macros | |
#define | MAX_NA_CHANNELS 72 |
#define | MAX_SUBBAND_CHANNELS 8 |
Functions | |
static void | app_resources_uninit (void) |
SYSTEM_TaskStatus_t | APP_TaskHandler (void) |
This function is called to process APP task. SHOULD be defined in APP. More... | |
static void | appPostTask (AppTaskIds_t id) |
static void | appWakeup (uint32_t sleptDuration) |
static float | convert_celsius_to_fahrenheit (float cel_val) |
void | demo_appdata_callback (void *appHandle, appCbParams_t *appdata) |
Callback function for the ending of Bidirectional communication of Application data. More... | |
static void | demo_handle_evt_rx_data (void *appHandle, appCbParams_t *appdata) |
void | demo_joindata_callback (StackRetStatus_t status) |
static void | demoTimerCb (void *cnt) |
void | dev_eui_read (void) |
Reads the MAC EUI from the EDBG Controller of the XPro Board. More... | |
static void | displayJoinAndSend (void) |
Displays and activates LED's for joining to a network and sending data to a network. More... | |
static void | displayRunDemoApp (void) |
Displays and activates LED's for selecting Demo application. More... | |
static void | displayRunDemoCertApp (void) |
Displays and activates LED's to choose between Demo and Certification application. More... | |
static void | displayRunRestoreBand (void) |
Activates LED's to indicate restoring of band. More... | |
static SYSTEM_TaskStatus_t | displayTask (void) |
Calls appropriate functions based on state variables. More... | |
static void | lTimerCb (void *data) |
void | mote_demo_init (void) |
Initialization the Demo application. More... | |
StackRetStatus_t | mote_set_parameters (IsmBand_t ismBand, const uint16_t index) |
void | print_application_config (void) |
void | print_array (uint8_t *array, uint8_t length) |
void | print_stack_status (StackRetStatus_t status) |
static void | processJoinAndSend (void) |
Sends Join request or Data to the network. More... | |
static void | processRunDemoApp (void) |
Runs the Demo application. More... | |
static void | processRunDemoCertApp (void) |
Activates demo application or certification application. More... | |
static void | processRunRestoreBand (void) |
Restores the previous band and runs. More... | |
static SYSTEM_TaskStatus_t | processTask (void) |
Calls appropriate functions based on state variables. More... | |
static void | runCertApp (void) |
static void | sendData (void) |
void | serial_data_handler (void) |
Pulls the data from UART when activated. More... | |
StackRetStatus_t | set_device_type (EdClass_t ed_class) |
StackRetStatus_t | set_join_parameters (ActivationType_t activation_type) |
void | set_multicast_params (void) |
Variables | |
static volatile uint8_t | appTaskFlags = 0x00u |
static SYSTEM_TaskStatus_t(* | appTaskHandlers [])(void) |
static AppTaskState_t | appTaskState |
bool | bandSelected |
static const char * | bandStrings [] |
uint8_t | bandTable [] |
static float | cel_val |
bool | certAppEnabled = false |
static volatile uint8_t | count = 5 |
static uint8_t | data_len = 0 |
static uint8_t | demoAppKey [16] = DEMO_APPLICATION_KEY |
static uint8_t | demoAppsKey [16] = DEMO_APPLICATION_SESSION_KEY |
static uint32_t | demoDevAddr = DEMO_DEVICE_ADDRESS |
static uint8_t | demoDevEui [8] = DEMO_DEVICE_EUI |
static uint8_t | demoJoinEui [8] = DEMO_JOIN_EUI |
static uint8_t | demoMcastAppsKey [16] = DEMO_APP_MCAST_APP_SESSION_KEY |
static uint32_t | demoMcastDevAddr = DEMO_APP_MCAST_GROUP_ADDRESS |
static bool | demoMcastEnable = DEMO_APP_MCAST_ENABLE |
static uint8_t | demoMcastGroupId = DEMO_APP_MCAST_GROUPID |
static uint8_t | demoMcastNwksKey [16] = DEMO_APP_MCAST_NWK_SESSION_KEY |
static uint8_t | demoNwksKey [16] = DEMO_NETWORK_SESSION_KEY |
uint8_t | demoTimerId |
bool | factory_reset |
static float | fahren_val |
static bool | joined = false |
uint32_t | longPress |
static LorawanSendReq_t | lorawanSendReq |
uint8_t | lTimerId |
static uint8_t | off = LOFF |
static uint8_t | on = LON |
static uint8_t | rxchar [11] |
static char | serialBuffer |
static bool | startReceiving = false |
static char | temp_sen_str [25] |
static uint8_t | toggle = LTOGGLE |
PRINT EVENTS | |
bool | button_pressed |
Determine if button is pressed. More... | |
#define MAX_NA_CHANNELS 72 |
Referenced by mote_set_parameters().
#define MAX_SUBBAND_CHANNELS 8 |
Referenced by mote_set_parameters().
|
static |
References HAL_RadioDeInit(), port_get_config_defaults(), port_pin_set_config(), port_config::powersave, and sio2host_deinit().
Referenced by processJoinAndSend().
SYSTEM_TaskStatus_t APP_TaskHandler | ( | void | ) |
This function is called to process APP task. SHOULD be defined in APP.
References APP_TASK_ID, APP_TASKS_COUNT, appTaskFlags, appTaskHandlers, ATOMIC_SECTION_ENTER, ATOMIC_SECTION_EXIT, SYSTEM_PostTask(), and SYSTEM_TASK_SUCCESS.
Referenced by main(), and wsndemo_task().
|
static |
References APP_TASK_ID, appTaskFlags, ATOMIC_SECTION_ENTER, ATOMIC_SECTION_EXIT, and SYSTEM_PostTask().
Referenced by appWakeup(), demo_appdata_callback(), demo_joindata_callback(), demoTimerCb(), displayRunRestoreBand(), mote_demo_init(), mote_set_parameters(), processJoinAndSend(), processRunDemoApp(), processRunDemoCertApp(), processRunRestoreBand(), and serial_data_handler().
|
static |
References appPostTask(), appTaskState, DISPLAY_TASK_HANDLER, HAL_Radio_resources_init(), JOIN_SEND_STATE, and sio2host_init().
Referenced by processJoinAndSend().
|
static |
void demo_appdata_callback | ( | void * | appHandle, |
appCbParams_t * | appdata | ||
) |
Callback function for the ending of Bidirectional communication of Application data.
References appPostTask(), appTaskState, demo_handle_evt_rx_data(), DISPLAY_TASK_HANDLER, _appCbParams::evt, JOIN_SEND_STATE, LED_AMBER, LED_GREEN, LORAWAN_BUSY, LORAWAN_EVT_RX_DATA_AVAILABLE, LORAWAN_EVT_TRANSACTION_COMPLETE, LORAWAN_FCNTR_ERROR, LORAWAN_FCNTR_ERROR_REJOIN_NEEDED, LORAWAN_INVALID_BUFFER_LENGTH, LORAWAN_INVALID_MTYPE, LORAWAN_INVALID_PACKET, LORAWAN_INVALID_PARAMETER, LORAWAN_INVALID_REQUEST, LORAWAN_KEYS_NOT_INITIALIZED, LORAWAN_MAC_PAUSED, LORAWAN_MCAST_HDR_INVALID, LORAWAN_MIC_ERROR, LORAWAN_NO_ACK, LORAWAN_NO_CHANNELS_FOUND, LORAWAN_NWK_JOIN_IN_PROGRESS, LORAWAN_NWK_NOT_JOINED, LORAWAN_RADIO_BUSY, LORAWAN_RADIO_CHANNEL_BUSY, LORAWAN_RADIO_DATA_SIZE, LORAWAN_RADIO_INVALID_REQ, LORAWAN_RADIO_NO_DATA, LORAWAN_RADIO_OUT_OF_RANGE, LORAWAN_RADIO_SUCCESS, LORAWAN_RADIO_UNSUPPORTED_ATTR, LORAWAN_RESOURCE_UNAVAILABLE, LORAWAN_SILENT_IMMEDIATELY_ACTIVE, LORAWAN_SUCCESS, LORAWAN_TX_TIMEOUT, lTimerId, off, on, _appCbParams::param, _appCbParams::rxData, set_LED_data(), SwTimerStop(), and _appCbParams::transCmpl.
Referenced by mote_demo_init().
|
static |
References i, NULL, _appCbParams::param, and _appCbParams::rxData.
Referenced by demo_appdata_callback().
void demo_joindata_callback | ( | StackRetStatus_t | status | ) |
References appPostTask(), appTaskState, DEV_ADDR, DISPLAY_TASK_HANDLER, JOIN_SEND_STATE, joined, LED_AMBER, LED_GREEN, LORAWAN_GetAttr(), LORAWAN_MIC_ERROR, LORAWAN_NO_CHANNELS_FOUND, LORAWAN_SUCCESS, LORAWAN_TX_TIMEOUT, MCAST_ENABLE, NULL, off, on, PDS_StoreAll(), print_application_config(), and set_LED_data().
Referenced by mote_demo_init().
|
static |
References appPostTask(), appTaskState, count, DEMO_CERT_APP_STATE, demoTimerId, DISPLAY_TASK_HANDLER, i, MS_TO_US, NULL, RESTORE_BAND_STATE, rxchar, sio2host_rx(), startReceiving, SW_TIMEOUT_RELATIVE, and SwTimerStart().
Referenced by mote_demo_init().
void dev_eui_read | ( | void | ) |
Reads the MAC EUI from the EDBG Controller of the XPro Board.
References demoDevEui, edbg_eui_read_eui64(), i, and j.
|
static |
Displays and activates LED's for joining to a network and sending data to a network.
References LED_AMBER, LED_GREEN, off, set_LED_data(), and startReceiving.
Referenced by displayTask().
|
static |
Displays and activates LED's for selecting Demo application.
References bandStrings, bandTable, i, LED_AMBER, LED_GREEN, off, set_LED_data(), and startReceiving.
Referenced by displayTask().
|
static |
Displays and activates LED's to choose between Demo and Certification application.
References LED_AMBER, LED_GREEN, off, set_LED_data(), and startReceiving.
Referenced by displayTask().
|
static |
Activates LED's to indicate restoring of band.
References appPostTask(), LED_AMBER, LED_GREEN, off, PROCESS_TASK_HANDLER, and set_LED_data().
Referenced by displayTask().
|
static |
Calls appropriate functions based on state variables.
References appTaskState, DEMO_APP_STATE, DEMO_CERT_APP_STATE, displayJoinAndSend(), displayRunDemoApp(), displayRunDemoCertApp(), displayRunRestoreBand(), JOIN_SEND_STATE, RESTORE_BAND_STATE, and SYSTEM_TASK_SUCCESS.
|
static |
References LED_GREEN, lTimerId, MS_TO_US, NULL, set_LED_data(), SW_TIMEOUT_RELATIVE, SwTimerStart(), and toggle.
void mote_demo_init | ( | void | ) |
Initialization the Demo application.
Function to Initialize the Demo application.
References appPostTask(), appTaskState, bandStrings, bandTable, demo_appdata_callback(), DEMO_CERT_APP_STATE, demo_joindata_callback(), demoTimerCb(), demoTimerId, DISPLAY_TASK_HANDLER, i, ISMBAND, LORAWAN_GetAttr(), LORAWAN_Init(), MS_TO_US, NULL, PDS_IsRestorable(), PDS_RestoreAll(), resource_init(), rxchar, sio2host_rx(), STACK_VER, startReceiving, SW_TIMEOUT_RELATIVE, and SwTimerStart().
StackRetStatus_t mote_set_parameters | ( | IsmBand_t | ismBand, |
const uint16_t | index | ||
) |
References appPostTask(), appTaskState, bandStrings, bandTable, CH_PARAM_STATUS, _ChannelParameters::channelAttr, _ChannelParameters::channelId, CRYPTODEVICE_ENABLED, DISPLAY_TASK_HANDLER, ISM_AU915, ISM_NA915, JOIN_BACKOFF_ENABLE, JOIN_SEND_STATE, LORAWAN_Join(), LORAWAN_Reset(), LORAWAN_SetAttr(), LORAWAN_SUCCESS, MAX_NA_CHANNELS, MAX_SUBBAND_CHANNELS, print_stack_status(), set_device_type(), set_join_parameters(), _ChannelAttr::status, and SUBBAND.
Referenced by processRunDemoApp().
void print_application_config | ( | void | ) |
References ACTIVATION_BY_PERSONALIZATION, CLASS_A, CLASS_C, CONFIRMED, EDCLASS, LORAWAN_GetAttr(), NULL, OVER_THE_AIR_ACTIVATION, and UNCONFIRMED.
Referenced by demo_joindata_callback(), and processRunRestoreBand().
static void print_array | ( | uint8_t * | array, |
uint8_t | length | ||
) |
Referenced by cert_app_timer_callback(), cert_set_join_parameters(), set_join_parameters(), and set_multicast_params().
static void print_stack_status | ( | StackRetStatus_t | status | ) |
References LORAWAN_BUSY, LORAWAN_FCNTR_ERROR_REJOIN_NEEDED, LORAWAN_INVALID_BUFFER_LENGTH, LORAWAN_INVALID_PARAMETER, LORAWAN_INVALID_REQUEST, LORAWAN_KEYS_NOT_INITIALIZED, LORAWAN_MAC_PAUSED, LORAWAN_NO_CHANNELS_FOUND, LORAWAN_NWK_JOIN_IN_PROGRESS, LORAWAN_NWK_NOT_JOINED, LORAWAN_SILENT_IMMEDIATELY_ACTIVE, and LORAWAN_SUCCESS.
Referenced by cert_app_init(), cert_app_timer_callback(), cert_appdata_callback(), cert_handle_cert_rx_data(), cert_joindata_callback(), mote_set_parameters(), and processJoinAndSend().
|
static |
Sends Join request or Data to the network.
References app_resources_uninit(), appPostTask(), appTaskState, appWakeup(), DEMO_APP_STATE, DISPLAY_TASK_HANDLER, HAL_Radio_resources_init(), JOIN_SEND_STATE, joined, LED_AMBER, LED_GREEN, LORAWAN_Join(), LORAWAN_ReadyToSleep(), LORAWAN_SUCCESS, on, PMM_Sleep(), PMM_SLEEP_REQ_DENIED, _PMM_SleepReq_t::pmmWakeupCallback, print_stack_status(), sendData, serialBuffer, set_LED_data(), sio2host_init(), _PMM_SleepReq_t::sleep_mode, sleepReq, and _PMM_SleepReq_t::sleepTimeMs.
Referenced by processTask().
|
static |
Runs the Demo application.
References appPostTask(), appTaskState, bandTable, DEMO_APP_STATE, DISPLAY_TASK_HANDLER, LED_GREEN, LORAWAN_Reset(), mote_set_parameters(), on, PDS_DeleteAll(), serialBuffer, and set_LED_data().
Referenced by processTask().
|
static |
Activates demo application or certification application.
References appPostTask(), appTaskState, DEMO_APP_STATE, DEMO_CERT_APP_STATE, DISPLAY_TASK_HANDLER, runCertApp(), and serialBuffer.
Referenced by processTask().
|
static |
Restores the previous band and runs.
References APP_TASK_ID, appPostTask(), appTaskState, bandStrings, bandTable, DEMO_APP_STATE, DISPLAY_TASK_HANDLER, i, ISMBAND, JOIN_BACKOFF_ENABLE, JOIN_SEND_STATE, joined, LED_AMBER, LORAWAN_GetAttr(), LORAWAN_NW_JOINED, LORAWAN_Reset(), LORAWAN_SetAttr(), LORAWAN_STATUS, LORAWAN_SUCCESS, NULL, on, PDS_RestoreAll(), print_application_config(), set_LED_data(), and SYSTEM_PostTask().
Referenced by processTask().
|
static |
Calls appropriate functions based on state variables.
References appTaskState, DEMO_APP_STATE, DEMO_CERT_APP_STATE, JOIN_SEND_STATE, processJoinAndSend(), processRunDemoApp(), processRunDemoCertApp(), processRunRestoreBand(), RESTORE_BAND_STATE, and SYSTEM_TASK_SUCCESS.
|
static |
References cert_app_init(), and certAppEnabled.
Referenced by processRunDemoCertApp().
|
static |
StackRetStatus_t set_device_type | ( | EdClass_t | ed_class | ) |
References CLASS_B, CLASS_C, EDCLASS, LORAWAN_SetAttr(), LORAWAN_SUCCESS, and set_multicast_params().
Referenced by mote_set_parameters().
StackRetStatus_t set_join_parameters | ( | ActivationType_t | activation_type | ) |
References ACTIVATION_BY_PERSONALIZATION, APP_KEY, APPS_KEY, demoAppKey, demoAppsKey, demoDevAddr, demoDevEui, demoJoinEui, demoNwksKey, DEV_ADDR, DEV_EUI, JOIN_EUI, LORAWAN_SetAttr(), LORAWAN_SUCCESS, NWKS_KEY, and print_array().
Referenced by mote_set_parameters().
void set_multicast_params | ( | void | ) |
References _LorawanMcastDatarate::datarate, _ReceiveWindow2Params::dataRate, demoMcastAppsKey, demoMcastDevAddr, demoMcastEnable, demoMcastGroupId, demoMcastNwksKey, _LorawanMcastDlFreqeuncy::dlFrequency, _ReceiveWindow2Params::frequency, _LorawanMcastDevAddr::groupId, _LorawanMcastAppSkey::groupId, _LorawanMcastNwkSkey::groupId, _LorawanMcastDatarate::groupId, _LorawanMcastDlFreqeuncy::groupId, _LorawanMcastStatus::groupId, LORAWAN_GetAttr(), LORAWAN_SESSIONKEY_LENGTH, LORAWAN_SetAttr(), LORAWAN_SetMulticastParam(), LORAWAN_SUCCESS, MCAST_APPS_KEY, MCAST_DATARATE, _LorawanMcastDevAddr::mcast_dev_addr, MCAST_ENABLE, MCAST_FREQUENCY, MCAST_GROUP_ADDR, MCAST_NWKS_KEY, _LorawanMcastAppSkey::mcastAppSKey, _LorawanMcastNwkSkey::mcastNwkSKey, NULL, print_array(), RX2_WINDOW_PARAMS, and _LorawanMcastStatus::status.
Referenced by set_device_type().
|
static |
Referenced by APP_TaskHandler(), and appPostTask().
|
static |
Referenced by APP_TaskHandler().
|
static |
bool bandSelected |
|
static |
Referenced by displayRunDemoApp(), mote_demo_init(), mote_set_parameters(), and processRunRestoreBand().
uint8_t bandTable[] |
Referenced by cert_select_band(), cert_set_join_parameters(), displayRunDemoApp(), enddevice_cpc_fresh_join(), mote_demo_init(), mote_set_parameters(), processRunDemoApp(), and processRunRestoreBand().
|
static |
Referenced by runCertApp().
|
static |
Referenced by _dma_find_first_free_channel_and_allocate(), _events_find_first_free_channel_and_allocate(), ble_remove_bonding_info(), ble_restore_bonding_info(), ble_store_bonding_info(), bufchar(), demoTimerCb(), disk_read(), disk_write(), dma_resume_job(), ksz8851snl_init(), led_toggle_indication(), main_count_states(), MQTTDeserialize_subscribe(), MQTTFormat_toClientString(), MQTTFormat_toServerString(), MQTTSerialize_suback(), MQTTSerialize_subscribe(), MQTTSerialize_subscribeLength(), MQTTSerialize_unsubscribe(), MQTTSerialize_unsubscribeLength(), MQTTSubscribe(), pbuf_free(), pds_list_item(), peer_req_send_task(), platform_wait_for_signal(), pxp_monitor_app_timer_event(), tc_callback_to_counter(), and tcc_set_count_value().
|
static |
|
static |
Referenced by set_join_parameters().
|
static |
Referenced by set_join_parameters().
|
static |
Referenced by set_join_parameters().
|
static |
Referenced by dev_eui_read(), and set_join_parameters().
|
static |
Referenced by set_join_parameters().
|
static |
Referenced by set_multicast_params().
|
static |
Referenced by set_multicast_params().
|
static |
Referenced by set_multicast_params().
|
static |
Referenced by set_multicast_params().
|
static |
Referenced by set_multicast_params().
|
static |
Referenced by set_join_parameters().
uint8_t demoTimerId |
Referenced by demoTimerCb(), and mote_demo_init().
bool factory_reset |
|
static |
Referenced by demo_joindata_callback(), processJoinAndSend(), and processRunRestoreBand().
uint32_t longPress |
|
static |
uint8_t lTimerId |
Referenced by demo_appdata_callback(), and lTimerCb().
|
static |
|
static |
|
static |
Referenced by demoTimerCb(), and mote_demo_init().
|
static |
Referenced by processJoinAndSend(), processRunDemoApp(), processRunDemoCertApp(), and serial_data_handler().
Referenced by demoTimerCb(), displayJoinAndSend(), displayRunDemoApp(), displayRunDemoCertApp(), mote_demo_init(), and serial_data_handler().
|
static |
|
static |
Referenced by lTimerCb().