Microchip® Advanced Software Framework

atmel_rf4ce/examples/atmega128rfa1_avr477_remote/main.c File Reference

Example application for the RF4CE and QMatrix integration for ATMega128RFA1 on AVR477 board.

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

#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "pal.h"
#include "app_config.h"
#include "rf4ce.h"
#include "zrc.h"
#include "pb_pairing.h"
#include "vendor_data.h"
#include "compiler.h"
#include "avr/io.h"
#include <avr/interrupt.h>
#include "avrtypes.h"
#include "touch_api.h"
#include "qdebug.h"
#include "qdebug_transport.h"
#include "t10_prox.h"
#include "kxtf9_driver.h"
#include "memorymap.h"

Macros

#define __delay_cycles(n)   __builtin_avr_delay_cycles(n)
 
#define __enable_interrupt()   sei()
 
#define ACCELERO_SIG_REF_DEFAULT   (30u)
 
#define AVR477_ACTIVE_DURATION_IN_QT_MEASURE_PERIOD   (AVR477_ACTIVE_DURATION_SEC * 1000 / QT_MEASUREMENT_PERIOD_MSEC)
 
#define AVR477_SLEEP_DURATION_IN_US   ( AVR477_SLEEP_DURATION_SEC * 1000000u )
 
#define AVR477_WARM_RESET_WAIT_DURATION_IN_US   ( AVR477_WARM_RESET_WAIT_TIME_SEC * 1000000u )
 
#define DEFAULT_BURST_LENGTH   20u
 configure the individual channel burst length (Based on tuning) More...
 
#define LED_KEY_BURST_LENGTH_1   32u
 
#define LED_KEY_BURST_LENGTH_2   32u
 
#define QT_MEASUREMENT_PERIOD_MSEC   15u
 
#define ROTOR_BURST_LENGTH_10   25u
 
#define ROTOR_BURST_LENGTH_11   32u
 
#define ROTOR_BURST_LENGTH_8   40u
 
#define ROTOR_BURST_LENGTH_9   36u
 
#define ZERO_BURST_LENGTH   0u
 

Typedefs

typedef enum node_status_tag node_status_t
 

Enumerations

enum  node_status_tag {
  IDLE,
  WARM_START,
  COLD_START,
  CONFIGURING_ATTRIBUTES,
  CONNECTING,
  TRANSMITTING,
  IDLE,
  WARM_START,
  COLD_START,
  TRANSMITTING,
  IDLE = 0,
  RESETTING,
  POWER_SAVE,
  STARTING,
  PUSH_BUTTON_PAIRING,
  CMD_DISCOVERING,
  ALL_IN_ONE_START,
  WARM_STARTING,
  PRINTING_PAIRING_TABLE,
  UNPAIRING,
  CH_AGILITY_EXECUTION,
  BASE_CHANNEL_CHANGE,
  GETTING_CH_AG_NIBS,
  IDLE = 0,
  RESETTING,
  POWER_SAVE,
  STARTING,
  PUSH_BUTTON_PAIRING,
  CMD_DISCOVERING,
  ALL_IN_ONE_START,
  WARM_STARTING,
  PRINTING_PAIRING_TABLE,
  UNPAIRING,
  CH_AGILITY_EXECUTION,
  BASE_CHANNEL_CHANGE,
  GETTING_CH_AG_NIBS,
  IDLE,
  WARM_START,
  COLD_START,
  TRANSMITTING,
  RESET,
  TRX_OFF_START,
  TRX_OFF_CONFIRM,
  TRX_ON_START,
  IDLE,
  WARM_START,
  COLD_START,
  CONFIGURING_ATTRIBUTES,
  CONNECTING,
  TRANSMITTING,
  IDLE,
  WARM_START,
  COLD_START,
  CONFIGURING_ATTRIBUTES,
  CONNECTING,
  TRANSMITTING,
  IDLE = 0,
  RESETTING,
  POWER_SAVE,
  STARTING,
  ZID_CONNECTING,
  ALL_IN_ONE_START,
  WARM_STARTING,
  PRINTING_PAIRING_TABLE,
  UNPAIRING
}
 

Functions

static void app_task (void)
 Application task and state machine. More...
 
static void burst_len_config (void)
 
static void buzzer_control (void)
 Buzzer Control. More...
 
static void buzzer_init (void)
 Buzzer initialization. More...
 
static void config_sensors (void)
 Configure the sensors, assign the channel number, aks_group, hysteresis. More...
 
static void config_sensors (void)
 Configure the sensors, assign the channel number, aks_group, hysteresis. More...
 
static void extended_delay_ms (uint16_t delay_ms)
 Extended blocking delay. More...
 
 FLASH_DECLARE (uint16_t VendorIdentifier)
 
 FLASH_DECLARE (uint8_t vendor_string[7])
 
 FLASH_DECLARE (uint8_t app_user_string[15])
 
 FLASH_DECLARE (uint8_t supported_cec_cmds[32])
 
static void indicate_fault_behavior (void)
 Indicating malfunction. More...
 
static void init_system (void)
 initialise host app, pins, watchdog, etc More...
 
static void init_timer_isr (void)
 configure timer ISR to fire regularly More...
 
 ISR (TIMER0_COMPA_vect)
 timer 0 compare ISR More...
 
static void led0_off (void)
 led0 off More...
 
static void led0_on (void)
 led0 on More...
 
static void led0_toggle (void)
 led0 Toggle More...
 
static void led1_off (void)
 led1 off More...
 
static void led1_on (void)
 led1 on More...
 
static void led1_toggle (void)
 Led1 Toggle. More...
 
int main (void)
 Main function - Initialization of RF4CE and QTouch are done. More...
 
void nlde_data_confirm (nwk_enum_t Status, uint8_t PairingRef, profile_id_t ProfileId)
 Vendor data confirm. More...
 
void nlme_get_confirm (nwk_enum_t Status, nib_attribute_t NIBAttribute, uint8_t NIBAttributeIndex, void *NIBAttributeValue)
 The NLME-GET.confirm primitive allows the NLME to notify the application of the status of its request for the value of a NIB attribute. More...
 
void nlme_reset_confirm (nwk_enum_t Status)
 The NLME-RESET.confirm primitive allows the NLME to notify the application of the status of its request to reset the NWK layer. More...
 
void nlme_rx_enable_confirm (nwk_enum_t Status)
 The NLME-RX-ENABLE.confirm primitive reports the results of the attempt to enable or disable the receiver. More...
 
void nlme_set_confirm (nwk_enum_t Status, nib_attribute_t NIBAttribute, uint8_t NIBAttributeIndex)
 The NLME-SET.confirm primitive allows the NLME to notify the application of the status of its request to change the value of a NIB attribute. More...
 
void nlme_start_confirm (nwk_enum_t Status)
 The NLME-START.confirm primitive allows the NLME to notify the application of the status of its request to start a network. More...
 
void nlme_unpair_confirm (uint8_t Status, uint8_t PairingRef)
 The NLME-UNPAIR.confirm primitive allows the NLME to notify the application of the status of its request to remove a pair with another device. More...
 
void nlme_unpair_indication (uint8_t PairingRef)
 The NLME-UNPAIR.indication primitive allows the NLME to notify the application of the removal of a pairing link by another device. More...
 
void nlme_update_key_confirm (nwk_enum_t Status, uint8_t PairingRef)
 The NLME-UPDATE-KEY.confirm primitive allows the NLME to notify the application of the status of its request to change the security link key of a pairing table entry. More...
 
void pbp_pair_confirm (nwk_enum_t Status, uint8_t PairingRef)
 Push button pairing confirm; target and controller use. More...
 
static void qt_avr477_filter_cb (void)
 This function is called every time the qt measuremement is done. More...
 
static void qt_set_parameters (void)
 This will fill the default threshold values in the configuration data structure.But User can change the values of these parameters . More...
 
static void sleep_led_control (void)
 This function controls the LED in a definitive fashion before going to sleep. More...
 
static void start_awake_timer_cb (void *callback_parameter)
 The callback function for the awake timer after the sleep period is over. More...
 
static void start_cmd_disc_cb (void *callback_parameter)
 Callback funtion indication that the timer expired for sending the command discovery request. More...
 
static void start_warm_reset_cb (void *callback_parameter)
 The callback function for the warm-reset timeout. More...
 
void vendor_app_alive_req (void)
 Vendor-spefic callback; handles reaction to incoming alive request. More...
 
void zrc_cmd_confirm (nwk_enum_t Status, uint8_t PairingRef, cec_code_t RcCmd)
 ZRC command confirm. More...
 
void zrc_cmd_disc_confirm (nwk_enum_t Status, uint8_t PairingRef, uint8_t *SupportedCmd)
 The command discovery confirm callback provides information about the command discovery reqest. More...
 
void zrc_cmd_disc_indication (uint8_t PairingRef)
 The command discovery indication callback indicates that a command discovery request command was receiced. More...
 

Variables

uint8_t allow_to_sleep
 
static uint16_t burst_flag = 0u
 
volatile uint16_t current_time_ms_touch = 0u
 
uint16_t delivery
 
static uint16_t enable_sleep_counter = 0
 
static uint16_t filter [4][8]
 
static node_status_t node_status
 
static uint8_t pairing_ref = 0xFF
 
uint16_t qgSubsAllways
 
uint16_t qgSubsChange
 
uint16_t qgSubsOnce
 
qt_touch_lib_config_data_t qt_config_data
 
uint16_t qt_measurement_period_msec = QT_MEASUREMENT_PERIOD_MSEC
 timer period in msec. More...
 
static uint16_t status_flag = 0u
 
static volatile uint8_t time_to_measure_touch = 0u
 

#define __delay_cycles (   n)    __builtin_avr_delay_cycles(n)
#define __enable_interrupt ( )    sei()
#define ACCELERO_SIG_REF_DEFAULT   (30u)

Referenced by qt_avr477_filter_cb().

#define AVR477_ACTIVE_DURATION_IN_QT_MEASURE_PERIOD   (AVR477_ACTIVE_DURATION_SEC * 1000 / QT_MEASUREMENT_PERIOD_MSEC)

Referenced by app_task().

#define AVR477_SLEEP_DURATION_IN_US   ( AVR477_SLEEP_DURATION_SEC * 1000000u )

Referenced by app_task().

#define AVR477_WARM_RESET_WAIT_DURATION_IN_US   ( AVR477_WARM_RESET_WAIT_TIME_SEC * 1000000u )

Referenced by main().

#define DEFAULT_BURST_LENGTH   20u

configure the individual channel burst length (Based on tuning)

Referenced by burst_len_config().

#define LED_KEY_BURST_LENGTH_1   32u

Referenced by burst_len_config().

#define LED_KEY_BURST_LENGTH_2   32u

Referenced by burst_len_config().

#define QT_MEASUREMENT_PERIOD_MSEC   15u
#define ROTOR_BURST_LENGTH_10   25u

Referenced by burst_len_config().

#define ROTOR_BURST_LENGTH_11   32u

Referenced by burst_len_config().

#define ROTOR_BURST_LENGTH_8   40u

Referenced by burst_len_config().

#define ROTOR_BURST_LENGTH_9   36u

Referenced by burst_len_config().

#define ZERO_BURST_LENGTH   0u

Referenced by burst_len_config().

Enumerator
IDLE 
WARM_START 
COLD_START 
CONFIGURING_ATTRIBUTES 
CONNECTING 
TRANSMITTING 
IDLE 
WARM_START 
COLD_START 
TRANSMITTING 
IDLE 
RESETTING 
POWER_SAVE 
STARTING 
PUSH_BUTTON_PAIRING 
CMD_DISCOVERING 
ALL_IN_ONE_START 
WARM_STARTING 
PRINTING_PAIRING_TABLE 
UNPAIRING 
CH_AGILITY_EXECUTION 
BASE_CHANNEL_CHANGE 
GETTING_CH_AG_NIBS 
IDLE 
RESETTING 
POWER_SAVE 
STARTING 
PUSH_BUTTON_PAIRING 
CMD_DISCOVERING 
ALL_IN_ONE_START 
WARM_STARTING 
PRINTING_PAIRING_TABLE 
UNPAIRING 
CH_AGILITY_EXECUTION 
BASE_CHANNEL_CHANGE 
GETTING_CH_AG_NIBS 
IDLE 
WARM_START 
COLD_START 
TRANSMITTING 
RESET 
TRX_OFF_START 
TRX_OFF_CONFIRM 
TRX_ON_START 
IDLE 
WARM_START 
COLD_START 
CONFIGURING_ATTRIBUTES 
CONNECTING 
TRANSMITTING 
IDLE 
WARM_START 
COLD_START 
CONFIGURING_ATTRIBUTES 
CONNECTING 
TRANSMITTING 
IDLE 
RESETTING 
POWER_SAVE 
STARTING 
ZID_CONNECTING 
ALL_IN_ONE_START 
WARM_STARTING 
PRINTING_PAIRING_TABLE 
UNPAIRING 

static void buzzer_init ( void  )
static

Buzzer initialization.

Referenced by main().

void config_sensors ( void  )
static

Configure the sensors, assign the channel number, aks_group, hysteresis.

References AKS_GROUP_1, AKS_GROUP_2, CHANNEL_0, CHANNEL_1, CHANNEL_2, CHANNEL_3, HYST_25, HYST_6_25, qt_enable_key(), qt_enable_rotor(), and RES_8_BIT.

Referenced by main().

FLASH_DECLARE ( uint16_t  VendorIdentifier)
FLASH_DECLARE ( uint8_t  vendor_string[7])
FLASH_DECLARE ( uint8_t  app_user_string[15])
FLASH_DECLARE ( uint8_t  supported_cec_cmds[32])
static void init_system ( void  )
static

initialise host app, pins, watchdog, etc

Referenced by main().

static void init_timer_isr ( void  )
static

configure timer ISR to fire regularly

References qt_measurement_period_msec, and TICKS_PER_MS.

Referenced by main().

static void led0_toggle ( void  )
inlinestatic

led0 Toggle

static void led1_toggle ( void  )
inlinestatic

Led1 Toggle.

Referenced by zrc_cmd_confirm().

void pbp_pair_confirm ( nwk_enum_t  Status,
uint8_t  PairingRef 
)

Push button pairing confirm; target and controller use.

Originator push pairing request; controller use.

The push button pairing confirm is a callback that provides the status of the push pairing request.

Parameters
StatusStatus of the last pairing transaction
PairingRefIf pairing was successful, PairingRef contains assigned pairing reference.

References aplcMinTargetBlackoutPeriod_us, FUNC_PTR, indicate_fault_behavior(), NULL, NWK_SUCCESS, pairing_ref, pal_timer_start(), start_cmd_disc_cb(), T_LED_TIMER, and TIMEOUT_RELATIVE.

static void qt_avr477_filter_cb ( void  )
static
static void start_cmd_disc_cb ( void *  callback_parameter)
static

Callback funtion indication that the timer expired for sending the command discovery request.

Parameters
callback_parameterCallback parameter (not used)

References pairing_ref, UNUSED, and zrc_cmd_disc_request().

Referenced by pbp_pair_confirm().

void vendor_app_alive_req ( void  )

Vendor-spefic callback; handles reaction to incoming alive request.

Vendor data alive request.

void zrc_cmd_confirm ( nwk_enum_t  Status,
uint8_t  PairingRef,
cec_code_t  RcCmd 
)

ZRC command confirm.

The ZRC comand confirm callback provides information about the status of the last command request/transmission.

Parameters
StatusNWK_SUCCESS if transmission was successful
PairingRefPairing reference
RcCmdSent RC command

References IDLE, led1_toggle(), node_status, NWK_SUCCESS, TX_index, and UNUSED.

Referenced by handle_incoming_msg().

uint8_t allow_to_sleep
uint16_t burst_flag = 0u
static

Referenced by app_task().

volatile uint16_t current_time_ms_touch = 0u
uint16_t delivery
uint16_t enable_sleep_counter = 0
static

Referenced by app_task().

uint16_t filter[4][8]
static

Referenced by qt_avr477_filter_cb().

uint8_t pairing_ref = 0xFF
static
uint16_t qgSubsAllways
uint16_t qgSubsChange
uint16_t qgSubsOnce
uint16_t status_flag = 0u
static

Referenced by app_task().

volatile uint8_t time_to_measure_touch = 0u
static

Referenced by app_task(), and ISR().