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 |
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().
typedef enum node_status_tag node_status_t |
enum node_status_tag |
|
static |
References DEFAULT_BURST_LENGTH, LED_KEY_BURST_LENGTH_1, LED_KEY_BURST_LENGTH_2, qt_burst_lengths, ROTOR_BURST_LENGTH_10, ROTOR_BURST_LENGTH_11, ROTOR_BURST_LENGTH_8, ROTOR_BURST_LENGTH_9, and ZERO_BURST_LENGTH.
Referenced by main().
|
static |
Buzzer initialization.
Referenced by main().
|
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 |
initialise host app, pins, watchdog, etc
Referenced by main().
|
static |
configure timer ISR to fire regularly
References qt_measurement_period_msec, and TICKS_PER_MS.
Referenced by main().
|
inlinestatic |
led0 Toggle
|
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.
Status | Status of the last pairing transaction |
PairingRef | If 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 |
This function is called every time the qt measuremement is done.
This is the pointer to callback function called before processing the signal
References ACCELERO_SIG_REF_DEFAULT, tag_memory_map_body_t::accelero_status, tag_memory_map_t::body, tag_qt_touch_lib_measure_data_t::channel_references, tag_qt_touch_lib_measure_data_t::channel_signals, CTRL_REG2_DOM, CTRL_REG2_FDM, CTRL_REG2_FUM, CTRL_REG2_LEM, CTRL_REG2_RIM, CTRL_REG2_UPM, filter, memory_map, qt_measure_data, and QT_NUM_CHANNELS.
Referenced by main().
|
static |
This will fill the default threshold values in the configuration data structure.But User can change the values of these parameters .
This is used to initialize the configuration data for processing.
References DEF_QT_DI, DEF_QT_DRIFT_HOLD_TIME, DEF_QT_MAX_ON_DURATION, DEF_QT_NEG_DRIFT_RATE, DEF_QT_POS_DRIFT_RATE, tag_qt_touch_lib_config_data_t::qt_di, tag_qt_touch_lib_config_data_t::qt_drift_hold_time, tag_qt_touch_lib_config_data_t::qt_max_on_duration, tag_qt_touch_lib_config_data_t::qt_neg_drift_rate, tag_qt_touch_lib_config_data_t::qt_pos_drift_rate, tag_qt_touch_lib_config_data_t::qt_pos_recal_delay, tag_qt_touch_lib_config_data_t::qt_recal_threshold, and RECAL_100.
|
static |
Callback funtion indication that the timer expired for sending the command discovery request.
callback_parameter | Callback 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.
Status | NWK_SUCCESS if transmission was successful |
PairingRef | Pairing reference |
RcCmd | Sent RC command |
References IDLE, led1_toggle(), node_status, NWK_SUCCESS, TX_index, and UNUSED.
Referenced by handle_incoming_msg().
uint8_t allow_to_sleep |
Referenced by app_task(), QDebug_SetSubscriptions(), and start_warm_reset_cb().
|
static |
Referenced by app_task().
volatile uint16_t current_time_ms_touch = 0u |
uint16_t delivery |
Referenced by app_task(), QDebug_SendData(), and Transmit_Sign_On().
|
static |
Referenced by app_task().
|
static |
Referenced by qt_avr477_filter_cb().
|
static |
|
static |
Referenced by nlme_reset_confirm(), pbp_pair_confirm(), and start_cmd_disc_cb().
uint16_t qgSubsAllways |
Referenced by QDebug_SendData(), QDebug_SetSubscriptions(), and start_warm_reset_cb().
uint16_t qgSubsChange |
Referenced by QDebug_SendData(), QDebug_SetSubscriptions(), and start_warm_reset_cb().
uint16_t qgSubsOnce |
Referenced by QDebug_SendData(), QDebug_SetSubscriptions(), and start_warm_reset_cb().
qt_touch_lib_config_data_t qt_config_data |
|
static |
Referenced by app_task().
|
static |
Referenced by app_task(), and ISR().