📄 ftrfhub.h
字号:
//----------------------------------------------------------------------------
//
// FTRFHub.h - Buffer Definitions
//
//--------------------------------------------------------------------------
//
//--------------------------------------------------------------------------
//
// Copyright 2008, 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.
//--------------------------------------------------------------------------
#include <m8c.h> // part specific constants and macros
#include "PSoCAPI.h" // PSoC API definitions for all User Modules
#include "PSoCGPIOInt.h"
//-------------------------------------------------------------------------
//
//#defines
//
//-------------------------------------------------------------------------
// Maximum Buffer length
#define MAX_BUFF_PKTS 12
#define MAX_PAYLOAD 14
#define I2C_PKT_SIZE 0x12
//Backchannel masks
#define DEV_ID_MSK 0x1F
//Host Command Definitions
#define HOST_CONFIG_STATUS 0x01
#define FETCH_NXT_PKT 0x02
#define SEND_PKT 0x03
#define GET_NODE_CFG 0x04
#define UNBIND_NODE 0x05
#define ENTER_BIND_MODE 0x06
#define GET_LAST_BIND_RESULT 0x07
//Hub Response Definitions
#define HOST_CONFIG_STATUS_RSP 0x81
#define FETCH_NXT_PKT_RSP 0x82
#define SEND_PKT_RSP 0x83
#define GET_NODE_CFG_RSP 0x84
#define UNBIND_NODE_RSP 0x85
#define ENTER_BIND_MODE_RSP 0x86
#define GET_LAST_BIND_RESULT_RSP 0x87
#define NETWORK_SIZE CYFISNP_MAX_NODES
//Host Command Masks
#define OPTION_LEN_MSK 0x0F
#define OPTION_FLUSH_MSK 0x80
//Hub Response masks
#define NODE_STATUS_MSK 0x03
//Status
#define STATUS_SUCCESS 0x01
#define STATUS_FAILURE 0x00
#define MAX_PAYLOAD_BCD 0x06
//Host command byte Defines
#define COMMAND_BYTE 0x00
//Hub response byte defines
#define RESPONSE_BYTE 0x00
#define IN_BIND_MODE 0x02
#define NOT_IN_BIND_MODE 0x01
#define BIND_TIMEOUT 0x00
//Device Types
#define FIRST_TOUCH_RF_DEVICE 0x00
//FW Version
#define FW_VERSION 0x01
//Misc
#define RESERVED 0x00
//-------------------------------------------------------------------------
//
//Function Prototypes
//
//-------------------------------------------------------------------------
void ServeSNPPackets (void);
void CheckHostRequest (void);
void BufferManagement (void);
void SendBackChannelData (BYTE devId);
void WriteBufferManager (void);
void ReadBufferManager (void);
//-------------------------------------------------------------------------
//
//Global Variables and Structures
//
//-------------------------------------------------------------------------
typedef struct
{
BYTE length; // Payload length
BYTE rssi; // RSSI of packet
BYTE type; // Packet type
BYTE devId; // [7:0] = Device ID
BYTE payload[CYFISNP_FCD_PAYLOAD_MAX]; //
} APP_PKT;
//Packet Buffer
APP_PKT App_Buff[MAX_BUFF_PKTS];
//Application Variables
char payload_data[16];
BYTE devId = 0;
char length = 0;
char packet_type = 0;
unsigned int numberOfPacketsInBuffer = 0;
//char fiveBitDeviceId = 0;
//I2C variables
unsigned char I2CBuffer[20]; //Buffer to receive Host command from master
//Pointer to first packet in Read buffer
char *pI2C = &I2CBuffer[0]; //Ptr to first packet in Command Buffer
//Host Command 0x02 variables
BYTE status = STATUS_SUCCESS;
BYTE count = 0;
//Host Command 0x03 variables
BYTE nodeStatus = 0x00;
BYTE threeBitNodeStatus = 0x00;
//Buffer Management Flags
BOOL bAppBuffFull = FALSE;
BOOL bAppBuffEmpty = TRUE;
BOOL bAppBuffNotFull = TRUE;
//I2C Flags
BOOL bHostDataRequest = FALSE;
//Bind Variables
BYTE bindRetryCt;
BYTE bindNodeId = 0;
BYTE bindNodeMID[4];
//CYFISNP Pointers
CYFISNP_API_PKT *pApiPkt;
CYFISNP_API_PKT sTestTxPkt; //instantiation of CYFISNP_API_PKT
//MID Buffer
BYTE MID_buff[6];
//Buffer Management Pointers
APP_PKT *pNextWrite = &App_Buff[0]; //Ptr to next write pkt in Buffer
APP_PKT *pNextRead = &App_Buff[0]; //Ptr to next read pkt in Buffer
APP_PKT *pEnd = &App_Buff[MAX_BUFF_PKTS]; //Ptr to end of Buffer
APP_PKT *pBeg = &App_Buff[0];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -