📄 protocol.h
字号:
//--------------------------------------------------------------------------
//
// Filename: protocol.h
//
//! \file
//!
//! Include file which defines the LP radio packet format
//!
//!
//--------------------------------------------------------------------------
// WirelessUSB LP Protocol Version 2.1
//--------------------------------------------------------------------------
//
// Copyright 2003-2006, Cypress Semiconductor Corporation.
//
// This software is owned by Cypress Semiconductor Corporation (Cypress)
// and is protected by and subject to worldwide patent protection (United
// States and foreign), United States copyright laws and international
// treaty provisions. Cypress hereby grants to licensee a personal,
// non-exclusive, non-transferable license to copy, use, modify, create
// derivative works of, and compile the Cypress Source Code and derivative
// works for the sole purpose of creating custom software in support of
// licensee product to be used only in conjunction with a Cypress integrated
// circuit as specified in the applicable agreement. Any reproduction,
// modification, translation, compilation, or representation of this
// software except as specified above is prohibited without the express
// written permission of Cypress.
//
// Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND,EXPRESS OR IMPLIED,
// WITH REGARD TO THIS MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
// Cypress reserves the right to make changes without further notice to the
// materials described herein. Cypress does not assume any liability arising
// out of the application or use of any product or circuit described herein.
// Cypress does not authorize its products for use as critical components in
// life-support systems where a malfunction or failure may reasonably be
// expected to result in significant injury to the user. The inclusion of
// Cypress' product in a life-support systems application implies that the
// manufacturer assumes all risk of such use and in doing so indemnifies
// Cypress against all charges.
//
// Use may be limited by and subject to the applicable Cypress software
// license agreement.
//
//--------------------------------------------------------------------------
#ifndef _PROTOCOL_H_
#define _PROTOCOL_H_
//--------------------------------------
// Include file(s)
//--------------------------------------
//--------------------------------------
// API Definitions and Types
//--------------------------------------
// ------------ For Common Use ------------
#define BACK_CHANNEL_PAYLOAD_LEN 0x01
#define BIND_PN_CODE 0x00
#define BIND_BASE_CHANNEL 0x00
// For TEA
#define KEY_REQUEST_FIRST_SECTION 0x80
#define KEY_REQUEST_LAST_SECTION 0x85
#define KEY_RESPONSE_FIRST_SECTION 0x8A
#define KEY_RESPONSE_LAST_SECTION 0x8F
//! Number of PN codes in the PN code table
#define NUM_PN_CODES 10 //bugbug This needs to come from the radio driver.
//! Number of channels in the 2.4 GHz spread spectrum
#define NUM_CHANNELS 78
//! Number of channels per channel subset
#define NUM_CHANNELS_PER_SUBSET 13
//! Mask used in the pin distribution algorithm
#define PIN_MASK 0x03
//! For allowing certain pins to be used in the pin distribution algorithm
#define MIN_PIN 0x02
//! Timeout for packet receving (iterations through a loop)
#define RX_PACKET_TIMEOUT 1000 //250
// When the LNA enabled, the RSSI gain
#define RSSI_LNA_GAIN 12
// ------------ For Master Protocol ------------
// Ping Request
#define PING_REQ 0x00
// Ping Response
#define PING_RESP 0x01
// Flash signature for the bind device flags
#define BIND_SIGNATURE 0x09
//! Used as the max in the main control loop in MasterPingMode()
#define PING_NUM_RSSI 20
//! There are 2 channels per RSSI increment
#define CHANNELS_PER_RSSI_INCREMENT 0x02
//! Timeout when checking RSSI
#define QUICK_RSSI_TIMEOUT 0x03
//! Number of high RSSI readings to limit the RSSI counter
#define NUM_HIGH_RSSI_READINGS 2 //0x05
// Number of loops through the channels during BUTTON master bind (max = 0xffff)
#define MASTER_BUTTON_BIND_RETRY_COUNT (NUM_CHANNELS_PER_SUBSET * 30)
// Number of loops through the channels during POWER master bind (max = 0xffff)
#define MASTER_POWER_BIND_RETRY_COUNT (NUM_CHANNELS_PER_SUBSET * 2)
// ------------ For Slave Protocol ------------
// Flash signature byte for system parameters
#define SIGNATURE_BYTE 0x90
// Timer delay when waiting for bridge to ping
#define BRIDGE_PING_TIME_MS 200
// Number of reconnect attemps on original channel before moving on
#define ORIG_CHAN_RECONNECT_COUNT 5
// Number of loops through the channels during bind (max = 0xffff)
#define BIND_RETRY_COUNT (NUM_CHANNELS_PER_SUBSET * 1000)
// Number of loops through the channels during reconnect (max = 255)
#define CONNECT_RETRY_COUNT (NUM_CHANNELS_PER_SUBSET * 19)
// Set the default PMU is enabled
#define PWR_CTRL_SETTING (PWR_CTRL_RST | LV_IRQ_TH_1P8_V | PMU_OUTV_2P7)
// --------------------------------------------
// Deivce Type
typedef enum _DEVICE_TYPE
{
PRESENTER_DEVICE_TYPE = 0x00,
RESERVED_DEVICE_TYPE = 0x01,
KEYBOARD_DEVICE_TYPE = 0x02, // Keyboard, for backward compatible
MOUSE_DEVICE_TYPE = 0x03, // Mouse, for backward compatible
}DEVICE_TYPE;
// Ping Reason
typedef enum _PING_REASON
{
PING_REASON_NORMAL, // When pinging for normal reasons
PING_REASON_RSSI, // When pinging for RSSI reasons
PING_REASON_CORRUPT, // When pinging for corrupt packet reasons
}PING_REASON;
// Packet types
typedef enum _PACKET_TYPES
{
BIND_REQ = 0x00, // Bind Request Packet Type
BIND_RESP = 0x00, // Bind Response Packet Type
CONNECT_REQ = 0x01, // Connect Request Packet Type
CONNECT_RESP = 0x02, // Connect Response Packet Type
PING_PACKET = 0x03, // Ping Packet Type
DATA_PACKET = 0x04, // Data Packet Type
BACK_CHANNEL_PACKET = 0x05, // Back channel packet Type
NULL_PACKET = 0x07, // Null Packet Type
ENCRYPT_KEY_REQ = 0x08, // Key Packet Type for encryption
ENCRYPT_KEY_RESP = 0x08, // Key Packet Type for encryption
KISS_BIND_REQ = 0x0D, // Kiss Bind Request Packet Type
KISS_BIND_RESP = 0x0D, // Kiss Bind Response Packet Type
} PACKET_TYPES;
typedef enum _PACKET_LENGTHS
{
BIND_REQ_LEN = 1,
BIND_RESP_LEN = 5,
KISS_BIND_REQ_LEN = 1,
CONNECT_REQ_LEN = 5,
CONNECT_RESP_LEN = 1,
PING_LEN = 1,
ENCRYPT_KEY_REQUEST_LEN = 1,
ENCRYPT_KEY_RESPONSE_LEN = 9,
} PACKET_LENGTHS;
// Transmit retry times
typedef enum _TX_RETRY_TIMES
{
BIND_REQ_RETRIES = 0, // Bind request retry times
BIND_RESP_RETRIES = 5, // Bind response retry times
KISS_BIND_REQ_RETRIES = 0, // KissBind request retry times
KISS_BIND_RESP_RETRIES = 1, // KissBind response retry times
PING_REQ_RETRIES = 1, // Ping request retry times
PING_RESP_RETRIES = 1, // Ping response retry times
CONNECT_REQ_RETRIES = 0, // Connect request retry times
CONNECT_RESP_RETRIES = 1, // Connect response retry times
ENCRYPT_KEY_REQ_RETRIES = 2, // Encrypt key request retry times
ENCRYPT_KEY_RESP_RETRIES = 1, // Encrypt key response retry times
DATA_PACKET_RETRIES = 10, // Data packet retry times
BACK_CHANNEL_PACKET_RETRIES = 5,// Back channel packet retry times
}TX_RETRY_TIMES;
//RSSI Threshold
typedef enum _RSSI_THRESHOLD
{
RSSI_NOISE_THRESHOLD = 28,
PING_RSSI_NOISE_THRESHOLD = 20,
KISS_BIND_RSSI_THRESHOLD = 10, // Kiss Bind RSSI threshold
}RSSI_THRESHOLD;
// PA Settings
typedef enum _PA_SETTING
{
DATA_MODE_PA = 6, // PA setting for data mode
ENCRYPT_KEY_PA = 1, // PA setting for encrypt key request
BUTTON_BIND_PA = 1, // PA setting for button bind
KISS_BIND_PA = 1, // PA setting for button kiss bind
}PA_SETTING;
// Protocol return status codes
typedef enum _PROTOCOL_STATUS
{
PROTOCOL_SUCCESS,
PROTOCOL_FAILED,
PROTOCOL_TX_TIMEOUT
} PROTOCOL_STATUS;
// Connected state of the protocol layer
typedef enum _PROTOCOL_CONNECT_STATE
{
PROTOCOL_DISCONNECTED,
PROTOCOL_CONNECTED
} PROTOCOL_CONNECT_STATE;
#ifdef MASTER_PROTOCOL
//! To setup the radio with a unique channel, PN code, CRC seed, and pin.
//! It's also used for storing the radio manufacturing ID for the bridge.
//
// Sys Params is structured to improve memory utilization. It is used
// to read the mid out of flash and then is converted to system parameters
// that are used during operation.
typedef struct _SYS_PARAMETERS
{
//! Data packet parameters for the radio and bridge
struct
{
unsigned char channel; // Currently selected channel
unsigned char pn_code; // Currently selected pncode
unsigned char seed; // CRC seed used for transmissions
unsigned char pin; // Pin used for transmissions
} network_id;
//! Radio manufacturing ID for bridge
struct
{
unsigned char mid_1; // Manufacturing id of bridge
unsigned char mid_2;
unsigned char mid_3;
unsigned char mid_4;
} bridge_mid;
#ifdef ENCRYPT_TEA
union _encrypt_key
{
struct
{
unsigned char key[16];
unsigned char status;
} byte;
struct
{
unsigned long key[4];
unsigned char status;
} block;
} encrypt_key;
#endif // ENCRYPT_TEA
#ifdef KISS_BIND
//! structure for bound devices
struct
{
//! bound flag
unsigned bound_flg : 0x04;
//! flag signature
unsigned signature : 0x04;
} device_bound;
#endif //KISS_BIND
} SYS_PARAMETERS;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -