//-------------------------------------------------------------------------- // Include file which defines the LS radio packet format // // NOTE:If you are porting this code to another processor, the bit fields // may need to be swapped around, and calls to protocol_gen_parity may need to be // changed also (casting to find the beginning of the header byte). // //-------------------------------------------------------------------------- // $Archive: /WirelessUSB/WUSB Kits/CY4632 LS KBM RDK/DocSrc/CD_Root/Firmware/Source Code/RDK Keyboard/protocol.h $ // $Modtime: 6/16/9/29/04 2:0019p $ // $Revision: 67 $ //-------------------------------------------------------------------------- // // Copyright 2003-2004, 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 "ls_config.h" #define USE_MIDS // Two way acknowledge timeout #ifndef ACK_TIMEOUT #ifdef DATA_RATE_16 #define ACK_TIMEOUT 48 #endif #ifdef DATA_RATE_32 #define ACK_TIMEOUT 32 #endif #ifdef DATA_RATE_64 #define ACK_TIMEOUT 16 #endif #endif // ACK_TIMEOUT #define NO_ACTIVITY 0 #define ACTIVITY 1 #define NULL_ACTIVITY 2 #define LS_STATUS_SUCCESS 0 #define LS_STATUS_FAILED 1 // Status codes #define GOOD_LENGTH 18 // Max App packet length #define GOOD_DATA 40 // greater then any legal length of a packet #define DATA_SENT 41 #define NO_DATA 42 #define INVALID_DATA 43 #define INVALID_DATA_TOGGLE 44 #define INVALID_DATA_LENGTH 45 #define TX_TIMEOUT_ERR 5 #define RX_TIMEOUT_ERR 6 #define ACK_DATA 7 #define NO_CONNECT_ERR 8 // No master Protocol Connection #define GOOD_ACK 1 #define BAD_ACK 0 // Interference Threshold definitions #define INTERFERENCE_THRESHOLD 0x64 // 100 #define GOOD_COUNT 1 #define ACK_ERR_COUNT 1 #define PACKET_ERR_COUNT 2 #define BIT_ERROR_COUNT 1 #define WRONG_PACKET_COUNT 5 typedef enum { Sts_OK = 0, Sts_Error } Status; typedef union _SYS_PARAMETERS { struct { UINT8 channel; UINT8 pnCode; UINT8 seed; UINT8 pin; UINT8 baseChannel; UINT8 signature; } networkId; #ifdef PROTOCOL_1_1 struct { UINT8 mid1; UINT8 mid2; UINT8 mid3; UINT8 mid4; UINT8 signature; } bridgeMid; #endif // PROTOCOL_1_1 } SYS_PARAMETERS; extern SYS_PARAMETERS sysParams; #define SIGNATURE_BYTE 0x90 #ifndef TWO_WAY // One way protocol structure #define GAP_DELAY 1 // delay between retransmissions in msec typedef union _LS_TX_PACKET { struct { struct { unsigned parity : 1; unsigned devId : 1; unsigned dt_data: 1; unsigned fill : 1; unsigned type : 4; } hdr; // check sum is added to the end of variable length packet UINT8 appPacket[APP_TX_PACKET_SIZE+1]; } data; struct { UINT8 byte; } first; } LS_TX_PACKET; typedef union _LS_RX_PACKET { struct { struct { unsigned parity : 1; unsigned devId : 1; unsigned dt_data: 1; unsigned fill : 1; unsigned type : 4; } hdr; // check sum is added to the end of variable length packet UINT8 appPacket[APP_RX_PACKET_SIZE+1]; } data; struct { UINT8 byte; } first; } LS_RX_PACKET; #define RX_DATA_PACKET_LEN APP_RX_PACKET_SIZE+2 // RX packet size #define LS_RX_PACKET_LEN (sizeof(LS_RX_PACKET)) // Max size of RX arrays #endif // ifndef TWO_WAY #ifdef TWO_WAY typedef union _LS_TX_PACKET { struct { struct { unsigned parity : 1; unsigned devId : 1; unsigned dt_data: 1; unsigned fill : 1; unsigned type : 4; } hdr; UINT8 appPacket[APP_TX_PACKET_SIZE]; UINT8 checkSum; } data; #ifdef ENCRYPT_DATA struct { UINT8 header; UINT32 appPacket[2]; UINT8 checksum; } encrypt; #endif // ENCRYPT_DATA struct { struct { unsigned parity : 1; unsigned dt_ack : 1; unsigned devId : 1; unsigned flag : 1; unsigned type : 4; } hdr; } ack; struct { struct { unsigned parity : 1; unsigned devType : 3; unsigned type : 4; } hdr; #ifndef PROTOCOL_1_1 UINT8 mid1; UINT8 mid2; UINT8 mid3; UINT8 mid4; UINT8 checkSum; #endif // PROTOCOL_1_1 } bind; struct { struct { unsigned parity : 1; unsigned pin : 3; unsigned type : 4; } hdr; #ifndef PROTOCOL_1_1 UINT8 channel; UINT8 pnCode; #endif // PROTOCOL_1_1 UINT8 mid1; UINT8 mid2; UINT8 mid3; UINT8 mid4; #ifdef DYNAMIC_PA_SUPPORT UINT8 pa; #endif UINT8 checkSum; } connect; struct { struct { unsigned parity : 1; unsigned devId : 1; unsigned fill : 2; unsigned type : 4; } hdr; } null; struct { UINT8 byte; } first; } LS_TX_PACKET; typedef union _LS_RX_PACKET { struct { struct { unsigned parity : 1; unsigned fill : 1; unsigned dt_data: 1; unsigned flag : 1; unsigned type : 4; } hdr; UINT8 appPacket[APP_RX_PACKET_SIZE]; UINT8 checkSum; } data; struct { struct { unsigned parity : 1; unsigned dt_ack : 1; unsigned dt_data : 1; unsigned flag : 1; unsigned type : 4; } hdr; UINT8 appPacket[APP_RX_PACKET_SIZE]; UINT8 checkSum; } ackData; struct { struct { unsigned parity : 1; unsigned dt_ack : 1; unsigned devId : 1; unsigned flag : 1; unsigned type : 4; } hdr; } ack; struct { struct { unsigned parity : 1; unsigned fill : 2; unsigned flag : 1; unsigned type : 4; } hdr; } connect; struct { struct { unsigned parity : 1; unsigned pin : 3; unsigned type : 4; } hdr; #ifndef PROTOCOL_1_1 UINT8 channel; UINT8 pnCode; UINT8 checkSumSeed; #else // Bridge MID UINT8 mid1; UINT8 mid2; UINT8 mid3; UINT8 mid4; #endif // PROTOCOL_1_1 UINT8 checkSum; } bind; #ifdef ENCRYPT_DATA struct { UINT8 header; UINT32 appPacket[2]; UINT8 checksum; } encrypt; #endif // ENCRYPT_DATA struct { UINT8 byte; } first; } LS_RX_PACKET; #ifdef ENCRYPT_DATA typedef struct _ENCRYPT_KEY { UINT32 key[4]; UINT8 signature; } ENCRYPT_KEY; #define ENCRYPT_KEY_SIZE 17 #endif // Lengths are variable due to unions. +1 is for the Sum Check, +2 is for // type byte and sum check #define RX_DATA_PACKET_LEN APP_RX_PACKET_SIZE+2 // RX packet size #define LS_RX_PACKET_LEN (sizeof(LS_RX_PACKET)) // Max size of RX arrays #ifndef PROTOCOL_1_1 #define BIND_REQ_LEN 4+2 #define BIND_RESP_LEN 3+2 #ifdef DYNAMIC_PA_SUPPORT #define CONNECT_REQ_LEN 6+2+1 #else #define CONNECT_REQ_LEN 6+2 #endif #else #define BIND_REQ_LEN 1 #define BIND_RESP_LEN 4+2 #ifdef DYNAMIC_PA_SUPPORT #define CONNECT_REQ_LEN 4+2+1 #else #define CONNECT_REQ_LEN 4+2 #endif #endif #ifdef ENCRYPT_DATA #define KEY_RESPONSE_LEN 10 #endif #ifdef CHECKSUM_ALL_PACKETS #define CONNECT_RESP_LEN 2 #define NULL_LEN 2 #define PING_LEN 2 #define ACK_LEN 2 #else #define CONNECT_RESP_LEN 1 #define NULL_LEN 1 #define PING_LEN 1 #define ACK_LEN 1 #endif // CHECKSUM_ALL_PACKETS // flag field bit values #define GOOD_ACK 1 #define NAK 0 #endif // TWO_WAY #define LS_TX_PACKET_LEN (sizeof(LS_TX_PACKET)) // Max size of TX arrays #define TX_PACKET_LEN APP_TX_PACKET_SIZE + 2 // TX packet size #define CHECK_SUM_SEED 0 // This is in 50us ticks #ifdef DATA_RATE_16 #define BITS_PER_MS 16 #endif // This is in 50us ticks #ifdef DATA_RATE_32 #define BITS_PER_MS 32 #endif // This is in 50us ticks #ifdef DATA_RATE_64 #define BITS_PER_MS 64 #endif Status protocol_init(void); void protocol_get_nvram(void); void * protocol_get_tx_pkt(void); void * protocol_get_rx_pkt(void); Status protocol_rtrn_tx_pkt(void *); Status protocol_rtrn_rx_pkt(void *); UINT8 protocol_gen_parity(UINT8 data); UINT8 protocol_calc_ck_sum(UINT8 *data, UINT8 len, UINT8 seed); void delayBitTime(UINT16 bits); UINT8 protocol_send_packet(UINT8 dataLength); #ifdef TWO_WAY void protocol_send_ack(void); UINT8 protocol_receive(UINT8 * pLength); #endif #ifdef PROTOCOL_1_1 void calculate_network_id(void); #endif extern LS_RX_PACKET rxPacket; extern LS_TX_PACKET txPacket; extern UINT8 protocol_device_type; #endif // _PROTOCOL_H_