临时存档
This commit is contained in:
@ -367,7 +367,7 @@
|
||||
/** \name Rx-Analog Register Contents (0x39)
|
||||
*/
|
||||
/*@{*/
|
||||
#define BIT_RX_OC_ENABLE 0x20U
|
||||
#define BIT_RX_OC_FUN_ENABLE 0x20U
|
||||
#define BIT_RX_HP_LOWF 0x10U
|
||||
#define MASK_VMID_R_SEL 0xC0U
|
||||
#define MASK_RCV_HPCF 0x0CU
|
||||
@ -427,7 +427,7 @@
|
||||
/** \name RxTxConReg Register Contents (0x77)
|
||||
*/
|
||||
/*@{*/
|
||||
#define BIT_SHMODE 0x08U //<2F>Ϻ<EFBFBD><CFBA>㷨
|
||||
#define BIT_SHMODE 0x08U //<2F>Ϻ<EFBFBD><CFBA>㷨
|
||||
/*@}*/
|
||||
|
||||
/** \name ErrorExtReg Register Contents (0x7E)
|
||||
@ -440,7 +440,7 @@
|
||||
#define LPCD_OPTION2 0x1DF
|
||||
|
||||
//---------------------------------------------------------------
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Э<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Э<EFBFBD><EFBFBD><EFBFBD>
|
||||
#define RX_TYPEA_106 0
|
||||
#define RX_TYPEA_212 1
|
||||
#define RX_TYPEA_424 2
|
||||
@ -457,7 +457,7 @@
|
||||
#define RX_FELICA_212 19
|
||||
#define RX_FELICA_424 20
|
||||
|
||||
//<2F><><EFBFBD>巢<EFBFBD><E5B7A2>Э<EFBFBD><D0AD><EFBFBD><EFBFBD>
|
||||
//<2F><><EFBFBD>巢<EFBFBD><E5B7A2>Э<EFBFBD><D0AD><EFBFBD>
|
||||
#define TX_TYPEA_106 0
|
||||
#define TX_TYPEA_212 1
|
||||
#define TX_TYPEA_424 2
|
||||
|
||||
@ -28,8 +28,8 @@ typedef enum {
|
||||
* @brief 功能使能状态枚举
|
||||
*/
|
||||
typedef enum {
|
||||
DISABLE = 0U,
|
||||
ENABLE = !DISABLE
|
||||
FUN_DISABLE = 0U,
|
||||
FUN_ENABLE = !FUN_DISABLE
|
||||
} FunState;
|
||||
|
||||
/**
|
||||
|
||||
@ -1,15 +1,14 @@
|
||||
#include "../include/READER.h"
|
||||
#include "../include/CPU_CARD.h"
|
||||
#include <string.h>
|
||||
#include "../include/READER_REG.h"
|
||||
#include "../include/rfid_main.h"
|
||||
#include "../rfid_hal.h"
|
||||
|
||||
#define ENABLE_XLOG 1
|
||||
#define FUN_ENABLE_XLOG 1
|
||||
#ifdef xlog
|
||||
#undef xlog
|
||||
#endif
|
||||
#if ENABLE_XLOG
|
||||
#if FUN_ENABLE_XLOG
|
||||
#define xlog(format, ...) printf("[XT:%s] " format, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
#define xlog(format, ...) ((void)0)
|
||||
@ -42,21 +41,21 @@ unsigned char CPU_CARD_EVENT(void)
|
||||
result = CPU_Rats(&CPU_CARD.ATS.Length, CPU_CARD.ATS.Ats_Data);
|
||||
if (result != SUCCESS)
|
||||
{
|
||||
SetCW(DISABLE);
|
||||
rfid_log_debug("-> RATS ERROR!\r\n");
|
||||
SetCW(FUN_DISABLE);
|
||||
xlog("-> RATS ERROR!\r\n");
|
||||
return result;
|
||||
}
|
||||
|
||||
rfid_log_debug("-> ATS = ");
|
||||
xlog("-> ATS = ");
|
||||
for(i = 0; i < CPU_CARD.ATS.Length; i++)
|
||||
rfid_log_debug("%02X", CPU_CARD.ATS.Ats_Data[i]);
|
||||
rfid_log_debug("\r\n");
|
||||
xlog("%02X", CPU_CARD.ATS.Ats_Data[i]);
|
||||
xlog("\r\n");
|
||||
|
||||
result = Ats_Process(CPU_CARD.ATS.Length, CPU_CARD.ATS.Ats_Data);
|
||||
if (result != SUCCESS)
|
||||
{
|
||||
SetCW(DISABLE);
|
||||
rfid_log_debug("-> ATS Process ERROR!\r\n");
|
||||
SetCW(FUN_DISABLE);
|
||||
xlog("-> ATS Process ERROR!\r\n");
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -66,14 +65,14 @@ unsigned char CPU_CARD_EVENT(void)
|
||||
result = CPU_APDU(&APDU);
|
||||
if (result != SUCCESS)
|
||||
{
|
||||
SetCW(DISABLE);
|
||||
rfid_log_debug("-> APDU ERROR!\r\n");
|
||||
SetCW(FUN_DISABLE);
|
||||
xlog("-> APDU ERROR!\r\n");
|
||||
return result;
|
||||
}
|
||||
rfid_log_debug("-> Select MF Response = ");
|
||||
xlog("-> Select MF Response = ");
|
||||
for(i=0; i<APDU.ReceiveLength; i++)
|
||||
rfid_log_debug("%02X", APDU.pReceiveBuffer[i]);
|
||||
rfid_log_debug("\r\n");
|
||||
xlog("%02X", APDU.pReceiveBuffer[i]);
|
||||
xlog("\r\n");
|
||||
|
||||
// ... 此处可以添加更多APDU指令 ...
|
||||
|
||||
@ -130,10 +129,10 @@ static unsigned char FM176XX_TPDU(transmission_struct *tpdu)
|
||||
SetReg(REG_TXDATANUM,0x08);
|
||||
SetReg(REG_IRQ0,0x7F); // 清除IRQ0所有中断标志
|
||||
SetReg(REG_IRQ1,0x7F); // 清除IRQ1所有中断标志
|
||||
ModifyReg(REG_FIFOCONTROL,BIT_FIFOFLUSH,ENABLE); // 清空FIFO
|
||||
ModifyReg(REG_FIFOCONTROL,BIT_FIFOFLUSH,FUN_ENABLE); // 清空FIFO
|
||||
Write_FIFO(tpdu->SendLength,tpdu->pSendBuffer);
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN,ENABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN,ENABLE);
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN,FUN_ENABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN,FUN_ENABLE);
|
||||
// SetTimer(tpdu->Timeout); // 定时器功能可以根据需要启用
|
||||
SetCommand(CMD_TRANSCEIVE);
|
||||
|
||||
|
||||
@ -1,15 +1,14 @@
|
||||
#include "../include/MIFARE.h"
|
||||
#include "../include/READER.h"
|
||||
#include "string.h"
|
||||
#include "../include/READER_REG.h"
|
||||
#include "../include/rfid_main.h"
|
||||
#include "../rfid_hal.h"
|
||||
|
||||
#define ENABLE_XLOG 1
|
||||
#define FUN_ENABLE_XLOG 1
|
||||
#ifdef xlog
|
||||
#undef xlog
|
||||
#endif
|
||||
#if ENABLE_XLOG
|
||||
#if FUN_ENABLE_XLOG
|
||||
#define xlog(format, ...) printf("[XT:%s] " format, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
#define xlog(format, ...) ((void)0)
|
||||
@ -90,7 +89,7 @@ unsigned char MIFARE_CARD_EVENT(void)
|
||||
result = Mifare_Auth(KEY_A_M1,SECTOR,KEY_A[SECTOR],PICC_A.UID);
|
||||
if(result != SUCCESS)
|
||||
{
|
||||
SetCW(DISABLE);
|
||||
SetCW(FUN_DISABLE);
|
||||
xlog("-> AUTH ERROR!\r\n");
|
||||
return result;
|
||||
}
|
||||
@ -109,7 +108,7 @@ unsigned char MIFARE_CARD_EVENT(void)
|
||||
result = Mifare_Blockwrite(BLOCK_NUM,BLOCK_DATA);
|
||||
if(result != SUCCESS)
|
||||
{
|
||||
SetCW(DISABLE);
|
||||
SetCW(FUN_DISABLE);
|
||||
xlog("-> WRITE BLOCK ERROR!\r\n");
|
||||
return result;
|
||||
}
|
||||
@ -118,7 +117,7 @@ unsigned char MIFARE_CARD_EVENT(void)
|
||||
result = Mifare_Blockread(BLOCK_NUM,BLOCK_DATA);
|
||||
if(result != SUCCESS)
|
||||
{
|
||||
SetCW(DISABLE);
|
||||
SetCW(FUN_DISABLE);
|
||||
xlog("-> READ BLOCK ERROR!\r\n");
|
||||
return result;
|
||||
}
|
||||
@ -128,7 +127,7 @@ unsigned char MIFARE_CARD_EVENT(void)
|
||||
xlog("\r\n");
|
||||
}
|
||||
}
|
||||
SetCW(DISABLE);
|
||||
SetCW(FUN_DISABLE);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -143,7 +142,7 @@ unsigned char Mifare_LoadKey(unsigned char *mifare_key)
|
||||
{
|
||||
unsigned char reg_data;
|
||||
SetCommand(CMD_IDLE);
|
||||
ModifyReg(REG_FIFOCONTROL,BIT_FIFOFLUSH,ENABLE); //Clear FIFO
|
||||
ModifyReg(REG_FIFOCONTROL,BIT_FIFOFLUSH,FUN_ENABLE); //Clear FIFO
|
||||
SetReg(REG_FIFODATA,mifare_key[0]);
|
||||
SetReg(REG_FIFODATA,mifare_key[1]);
|
||||
SetReg(REG_FIFODATA,mifare_key[2]);
|
||||
@ -176,16 +175,16 @@ unsigned char Mifare_Auth(unsigned char key_mode,unsigned char sector,unsigned c
|
||||
if (result != SUCCESS)
|
||||
return result;
|
||||
SetCommand(CMD_IDLE);
|
||||
ModifyReg(REG_FIFOCONTROL,BIT_FIFOFLUSH,ENABLE); //Clear FIFO
|
||||
ModifyReg(REG_FIFOCONTROL,BIT_FIFOFLUSH,FUN_ENABLE); //Clear FIFO
|
||||
if(key_mode == KEY_A_M1)
|
||||
{
|
||||
SetReg(REG_FIFODATA,0x60);// 0x60: Key A认证指令
|
||||
ModifyReg(REG_RXTXCON,BIT_SHMODE,DISABLE);
|
||||
ModifyReg(REG_RXTXCON,BIT_SHMODE,FUN_DISABLE);
|
||||
}
|
||||
if(key_mode == KEY_B_M1)
|
||||
{
|
||||
SetReg(REG_FIFODATA,0x61);// 0x61: Key B认证指令
|
||||
ModifyReg(REG_RXTXCON,BIT_SHMODE,DISABLE);
|
||||
ModifyReg(REG_RXTXCON,BIT_SHMODE,FUN_DISABLE);
|
||||
}
|
||||
|
||||
SetReg(REG_FIFODATA,sector * 4);// 认证扇区的块0地址
|
||||
@ -193,8 +192,8 @@ unsigned char Mifare_Auth(unsigned char key_mode,unsigned char sector,unsigned c
|
||||
SetReg(REG_FIFODATA,card_uid[1]);
|
||||
SetReg(REG_FIFODATA,card_uid[2]);
|
||||
SetReg(REG_FIFODATA,card_uid[3]);
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN,ENABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN,ENABLE);
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN,FUN_ENABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN,FUN_ENABLE);
|
||||
SetCommand(CMD_AUTHENT);
|
||||
rfid_delay_ms(5);
|
||||
GetReg(REG_COMMAND,®_data);
|
||||
@ -252,8 +251,8 @@ unsigned char Mifare_Blockread(unsigned char block,unsigned char *data_buff)
|
||||
SetReg(REG_TXDATANUM,0x08);
|
||||
SetReg(REG_FIFODATA,0x30);// 0x30: 读块指令
|
||||
SetReg(REG_FIFODATA,block);// 块地址
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN,ENABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN,ENABLE);
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN,FUN_ENABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN,FUN_ENABLE);
|
||||
SetCommand(CMD_TRANSCEIVE);
|
||||
rfid_delay_ms(2);
|
||||
GetReg(REG_FIFOLENGTH,®_data);
|
||||
@ -282,8 +281,8 @@ unsigned char Mifare_Blockwrite(unsigned char block,unsigned char *data_buff)
|
||||
SetReg(REG_TXDATANUM,0x08);
|
||||
SetReg(REG_FIFODATA,0xA0);// 0xA0: 写块指令
|
||||
SetReg(REG_FIFODATA,block);// 块地址
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN,ENABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN,DISABLE);
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN,FUN_ENABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN,FUN_DISABLE);
|
||||
SetCommand(CMD_TRANSCEIVE);
|
||||
rfid_delay_ms(5);
|
||||
GetReg(REG_FIFOLENGTH,®_data);
|
||||
@ -322,8 +321,8 @@ unsigned char Mifare_Blockinc(unsigned char block,unsigned char *data_buff)
|
||||
SetReg(REG_TXDATANUM,0x08);
|
||||
SetReg(REG_FIFODATA,0xC1);// 0xC1: 增值指令
|
||||
SetReg(REG_FIFODATA,block);// 块地址
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN,ENABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN,DISABLE);
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN,FUN_ENABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN,FUN_DISABLE);
|
||||
SetCommand(CMD_TRANSCEIVE);
|
||||
rfid_delay_ms(5);
|
||||
GetReg(REG_FIFOLENGTH,®_data);
|
||||
@ -362,8 +361,8 @@ unsigned char Mifare_Blockdec(unsigned char block,unsigned char *data_buff)
|
||||
SetReg(REG_TXDATANUM,0x08);
|
||||
SetReg(REG_FIFODATA,0xC0);// 0xC0: 减值指令
|
||||
SetReg(REG_FIFODATA,block);// 块地址
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN,ENABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN,DISABLE);
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN,FUN_ENABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN,FUN_DISABLE);
|
||||
SetCommand(CMD_TRANSCEIVE);
|
||||
rfid_delay_ms(5);
|
||||
GetReg(REG_FIFOLENGTH,®_data);
|
||||
@ -402,8 +401,8 @@ unsigned char Mifare_Transfer(unsigned char block)
|
||||
SetReg(REG_TXDATANUM,0x08);
|
||||
SetReg(REG_FIFODATA,0xB0);// 0xB0: Transfer指令
|
||||
SetReg(REG_FIFODATA,block);// 块地址
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN,ENABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN,DISABLE);
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN,FUN_ENABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN,FUN_DISABLE);
|
||||
SetCommand(CMD_TRANSCEIVE);
|
||||
rfid_delay_ms(5);
|
||||
GetReg(REG_FIFOLENGTH,®_data);
|
||||
@ -430,8 +429,8 @@ unsigned char Mifare_Restore(unsigned char block)
|
||||
SetReg(REG_TXDATANUM,0x08);
|
||||
SetReg(REG_FIFODATA,0xC2);// 0xC2: Restore指令
|
||||
SetReg(REG_FIFODATA,block);// 块地址
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN,ENABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN,DISABLE);
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN,FUN_ENABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN,FUN_DISABLE);
|
||||
SetCommand(CMD_TRANSCEIVE);
|
||||
rfid_delay_ms(5);
|
||||
GetReg(REG_FIFOLENGTH,®_data);
|
||||
|
||||
@ -1,15 +1,14 @@
|
||||
#include "../include/READER.h"
|
||||
#include "../include/NTAG.h"
|
||||
#include <string.h>
|
||||
#include "../include/READER_REG.h"
|
||||
#include "../include/rfid_main.h"
|
||||
#include "../rfid_hal.h"
|
||||
|
||||
#define ENABLE_XLOG 1
|
||||
#define FUN_ENABLE_XLOG 1
|
||||
#ifdef xlog
|
||||
#undef xlog
|
||||
#endif
|
||||
#if ENABLE_XLOG
|
||||
#if FUN_ENABLE_XLOG
|
||||
#define xlog(format, ...) printf("[XT:%s] " format, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
#define xlog(format, ...) ((void)0)
|
||||
@ -56,8 +55,8 @@ unsigned char Read_Page(unsigned char page_num,unsigned char *page_data)
|
||||
SetReg(REG_FIFODATA,0x30); // 读指令
|
||||
SetReg(REG_FIFODATA,page_num);
|
||||
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN,ENABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN,ENABLE);
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN,FUN_ENABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN,FUN_ENABLE);
|
||||
SetCommand(CMD_TRANSCEIVE);
|
||||
rfid_delay_ms(5);
|
||||
GetReg(REG_ERROR,®_data);
|
||||
@ -91,8 +90,8 @@ unsigned char Write_Page(unsigned char page_num,unsigned char *page_data)
|
||||
SetReg(REG_FIFODATA,page_data[1]);
|
||||
SetReg(REG_FIFODATA,page_data[2]);
|
||||
SetReg(REG_FIFODATA,page_data[3]);
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN,ENABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN,DISABLE);
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN,FUN_ENABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN,FUN_DISABLE);
|
||||
SetCommand(CMD_TRANSCEIVE);
|
||||
rfid_delay_ms(5);
|
||||
|
||||
|
||||
@ -13,13 +13,12 @@
|
||||
#include "../include/READER_REG.h"
|
||||
#include "../include/rfid_main.h"
|
||||
#include "../rfid_hal.h" // 引入硬件抽象层
|
||||
#include <string.h>
|
||||
|
||||
#define ENABLE_XLOG 1
|
||||
#define FUN_ENABLE_XLOG 1
|
||||
#ifdef xlog
|
||||
#undef xlog
|
||||
#endif
|
||||
#if ENABLE_XLOG
|
||||
#if FUN_ENABLE_XLOG
|
||||
#define xlog(format, ...) printf("[XT:%s] " format, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
#define xlog(format, ...) ((void)0)
|
||||
@ -117,20 +116,20 @@ void SetTimer(unsigned int timeout)
|
||||
|
||||
/**
|
||||
* @brief 打开或关闭RF场(载波)。
|
||||
* @param mode [in] ENABLE表示打开,DISABLE表示关闭。
|
||||
* @param mode [in] FUN_ENABLE表示打开,FUN_DISABLE表示关闭。
|
||||
* @return 操作状态,SUCCESS表示成功。
|
||||
*/
|
||||
unsigned char SetCW(unsigned char mode)
|
||||
{
|
||||
if (mode == ENABLE)
|
||||
if (mode == FUN_ENABLE)
|
||||
{
|
||||
ModifyReg(REG_COMMAND, BIT_MODEMOFF, DISABLE);
|
||||
ModifyReg(REG_TXMODE, BIT_TPUSHON | BIT_TPULLON, ENABLE);
|
||||
ModifyReg(REG_COMMAND, BIT_MODEMOFF, FUN_DISABLE);
|
||||
ModifyReg(REG_TXMODE, BIT_TPUSHON | BIT_TPULLON, FUN_ENABLE);
|
||||
}
|
||||
else
|
||||
{
|
||||
ModifyReg(REG_COMMAND, BIT_MODEMOFF, ENABLE);
|
||||
ModifyReg(REG_TXMODE, BIT_TPUSHON | BIT_TPULLON, DISABLE);
|
||||
ModifyReg(REG_COMMAND, BIT_MODEMOFF, FUN_ENABLE);
|
||||
ModifyReg(REG_TXMODE, BIT_TPUSHON | BIT_TPULLON, FUN_DISABLE);
|
||||
}
|
||||
rfid_delay_ms(5);
|
||||
return SUCCESS;
|
||||
@ -146,7 +145,7 @@ void Clear_FIFO(void)
|
||||
GetReg(REG_FIFOLENGTH, &fifolength);
|
||||
if (fifolength != 0)
|
||||
{
|
||||
ModifyReg(REG_FIFOCONTROL, BIT_FIFOFLUSH, ENABLE);
|
||||
ModifyReg(REG_FIFOCONTROL, BIT_FIFOFLUSH, FUN_ENABLE);
|
||||
}
|
||||
}
|
||||
|
||||
@ -163,7 +162,7 @@ unsigned char LoadProtocol(unsigned char p_rx, unsigned char p_tx)
|
||||
{
|
||||
unsigned char reg_data = 0;
|
||||
SetCommand(CMD_IDLE);
|
||||
ModifyReg(REG_FIFOCONTROL, BIT_FIFOFLUSH, ENABLE); // 清空FIFO
|
||||
ModifyReg(REG_FIFOCONTROL, BIT_FIFOFLUSH, FUN_ENABLE); // 清空FIFO
|
||||
SetReg(REG_FIFODATA, p_rx); // 写入接收协议
|
||||
SetReg(REG_FIFODATA, p_tx); // 写入发送协议
|
||||
|
||||
@ -177,7 +176,7 @@ unsigned char LoadProtocol(unsigned char p_rx, unsigned char p_tx)
|
||||
|
||||
/**
|
||||
* @brief 设置发送和接收的奇偶校验位使能状态。
|
||||
* @param state [in] ENABLE或DISABLE。
|
||||
* @param state [in] FUN_ENABLE或FUN_DISABLE。
|
||||
* @return 无。
|
||||
*/
|
||||
void SetParity(unsigned char state)
|
||||
@ -192,7 +191,7 @@ void SetParity(unsigned char state)
|
||||
unsigned char ReaderA_Initial(void)
|
||||
{
|
||||
LoadProtocol(RX_TYPEA_106, TX_TYPEA_106);
|
||||
ModifyReg(REG_TXMODE, BIT_RFON, ENABLE); // FORCE 100ask ENABLE
|
||||
ModifyReg(REG_TXMODE, BIT_RFON, FUN_ENABLE); // FORCE 100ask FUN_ENABLE
|
||||
SetReg(REG_TXAMP, AMPLITUDE_A);
|
||||
SetReg(REG_TXCON, 0x00);
|
||||
SetReg(REG_RXANA, (HPCF_A << 3) | GAIN_A);
|
||||
@ -200,7 +199,7 @@ unsigned char ReaderA_Initial(void)
|
||||
SetReg(REG_THNSET, 0xFF);
|
||||
SetReg(REG_THNMIN, 0xC0);
|
||||
SetReg(REG_RXTXCON, 0x80);
|
||||
SetParity(ENABLE);
|
||||
SetParity(FUN_ENABLE);
|
||||
SetReg(REG_STATUS, 0); // 清除Crypto1On位
|
||||
return SUCCESS;
|
||||
}
|
||||
@ -212,7 +211,7 @@ unsigned char ReaderA_Initial(void)
|
||||
unsigned char ReaderB_Initial(void)
|
||||
{
|
||||
LoadProtocol(RX_TYPEB_106, TX_TYPEB_106);
|
||||
ModifyReg(REG_TXMODE, BIT_RFON, DISABLE); // FORCE 100ask DISABLE
|
||||
ModifyReg(REG_TXMODE, BIT_RFON, FUN_DISABLE); // FORCE 100ask FUN_DISABLE
|
||||
SetReg(REG_TXAMP, AMPLITUDE_B);
|
||||
SetReg(REG_TXCON, MODULATION_B);
|
||||
SetReg(REG_RXANA, (HPCF_B << 3) | GAIN_B);
|
||||
@ -230,9 +229,9 @@ unsigned char ReaderB_Initial(void)
|
||||
unsigned char ReaderV_Initial(void)
|
||||
{
|
||||
LoadProtocol(RX_TYPEV_26, RX_TYPEV_26);
|
||||
ModifyReg(REG_RXANA, MASK_RCV_GAIN | MASK_RCV_HPCF, DISABLE);
|
||||
ModifyReg(REG_RXANA, (HPCF_V << 3) | GAIN_V, ENABLE);
|
||||
SetParity(DISABLE);
|
||||
ModifyReg(REG_RXANA, MASK_RCV_GAIN | MASK_RCV_HPCF, FUN_DISABLE);
|
||||
ModifyReg(REG_RXANA, (HPCF_V << 3) | GAIN_V, FUN_ENABLE);
|
||||
SetParity(FUN_DISABLE);
|
||||
SetReg(REG_TXAMP, AMPLITUDE_V);
|
||||
SetReg(REG_TXCON, MODULATION_V);
|
||||
SetReg(REG_TXI, 0x06);
|
||||
@ -249,17 +248,17 @@ unsigned char ReaderV_Initial(void)
|
||||
*/
|
||||
unsigned char ReaderF_Initial(void)
|
||||
{
|
||||
ModifyReg(REG_MISC, 0x04, ENABLE);
|
||||
ModifyReg(REG_MISC, 0x04, FUN_ENABLE);
|
||||
LoadProtocol(RX_FELICA_212, TX_FELICA_212);
|
||||
SetReg(REG_TXAMP, AMPLITUDE_F);
|
||||
SetReg(REG_TXCON, MODULATION_F);
|
||||
ModifyReg(REG_RXANA, MASK_RCV_GAIN | MASK_RCV_HPCF, DISABLE);
|
||||
ModifyReg(REG_RXANA, (HPCF_F << 3) | GAIN_F, ENABLE);
|
||||
SetParity(DISABLE);
|
||||
ModifyReg(REG_RXANA, MASK_RCV_GAIN | MASK_RCV_HPCF, FUN_DISABLE);
|
||||
ModifyReg(REG_RXANA, (HPCF_F << 3) | GAIN_F, FUN_ENABLE);
|
||||
SetParity(FUN_DISABLE);
|
||||
SetReg(REG_THNSET, 0xFF);
|
||||
SetReg(REG_THNMIN, 0x80);
|
||||
SetReg(REG_THNADJ, 0x08);
|
||||
ModifyReg(REG_MISC, 0x04, DISABLE);
|
||||
ModifyReg(REG_MISC, 0x04, FUN_DISABLE);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@ -273,10 +272,10 @@ unsigned char ReaderA_Wakeeup(struct picc_a_struct *picc_a)
|
||||
unsigned char reg_data;
|
||||
SetCommand(CMD_IDLE);
|
||||
SetReg(REG_TXDATANUM, 0x0F);
|
||||
ModifyReg(REG_FIFOCONTROL, BIT_FIFOFLUSH, ENABLE);
|
||||
ModifyReg(REG_FIFOCONTROL, BIT_FIFOFLUSH, FUN_ENABLE);
|
||||
SetReg(REG_FIFODATA, RF_CMD_WUPA);
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN, DISABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN, DISABLE);
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN, FUN_DISABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN, FUN_DISABLE);
|
||||
SetCommand(CMD_TRANSCEIVE);
|
||||
rfid_delay_ms(2);
|
||||
GetReg(REG_FIFOLENGTH, ®_data);
|
||||
@ -299,10 +298,10 @@ unsigned char ReaderA_Request(struct picc_a_struct *picc_a)
|
||||
unsigned char reg_data;
|
||||
SetCommand(CMD_IDLE);
|
||||
SetReg(REG_TXDATANUM, 0x0F);
|
||||
ModifyReg(REG_FIFOCONTROL, BIT_FIFOFLUSH, ENABLE);
|
||||
ModifyReg(REG_FIFOCONTROL, BIT_FIFOFLUSH, FUN_ENABLE);
|
||||
SetReg(REG_FIFODATA, RF_CMD_REQA);
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN, DISABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN, DISABLE);
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN, FUN_DISABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN, FUN_DISABLE);
|
||||
SetCommand(CMD_TRANSCEIVE);
|
||||
rfid_delay_ms(2);
|
||||
GetReg(REG_FIFOLENGTH, ®_data);
|
||||
@ -325,11 +324,11 @@ unsigned char ReaderA_Anticoll(struct picc_a_struct *picc_a)
|
||||
unsigned char reg_data;
|
||||
SetCommand(CMD_IDLE);
|
||||
SetReg(REG_TXDATANUM, 0x08);
|
||||
ModifyReg(REG_FIFOCONTROL, BIT_FIFOFLUSH, ENABLE);
|
||||
ModifyReg(REG_FIFOCONTROL, BIT_FIFOFLUSH, FUN_ENABLE);
|
||||
SetReg(REG_FIFODATA, RF_CMD_ANTICOLL[picc_a->CASCADE_LEVEL]);
|
||||
SetReg(REG_FIFODATA, 0x20);
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN, DISABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN, DISABLE);
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN, FUN_DISABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN, FUN_DISABLE);
|
||||
SetCommand(CMD_TRANSCEIVE);
|
||||
rfid_delay_ms(2);
|
||||
GetReg(REG_FIFOLENGTH, ®_data);
|
||||
@ -357,7 +356,7 @@ unsigned char ReaderA_Select(struct picc_a_struct *picc_a)
|
||||
unsigned char reg_data;
|
||||
SetCommand(CMD_IDLE);
|
||||
SetReg(REG_TXDATANUM, 0x08);
|
||||
ModifyReg(REG_FIFOCONTROL, BIT_FIFOFLUSH, ENABLE);
|
||||
ModifyReg(REG_FIFOCONTROL, BIT_FIFOFLUSH, FUN_ENABLE);
|
||||
SetReg(REG_FIFODATA, RF_CMD_ANTICOLL[picc_a->CASCADE_LEVEL]);
|
||||
SetReg(REG_FIFODATA, 0x70);
|
||||
SetReg(REG_FIFODATA, picc_a->UID[picc_a->CASCADE_LEVEL * 4]);
|
||||
@ -365,8 +364,8 @@ unsigned char ReaderA_Select(struct picc_a_struct *picc_a)
|
||||
SetReg(REG_FIFODATA, picc_a->UID[picc_a->CASCADE_LEVEL * 4 + 2]);
|
||||
SetReg(REG_FIFODATA, picc_a->UID[picc_a->CASCADE_LEVEL * 4 + 3]);
|
||||
SetReg(REG_FIFODATA, picc_a->BCC[picc_a->CASCADE_LEVEL]);
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN, ENABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN, ENABLE);
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN, FUN_ENABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN, FUN_ENABLE);
|
||||
SetCommand(CMD_TRANSCEIVE);
|
||||
rfid_delay_ms(2);
|
||||
GetReg(REG_ERROR, ®_data);
|
||||
@ -435,12 +434,12 @@ unsigned char ReaderB_Wakeup(struct picc_b_struct *picc_b)
|
||||
unsigned char reg_data, i;
|
||||
SetCommand(CMD_IDLE);
|
||||
SetReg(REG_TXDATANUM, 0x08);
|
||||
ModifyReg(REG_FIFOCONTROL, BIT_FIFOFLUSH, ENABLE);
|
||||
ModifyReg(REG_FIFOCONTROL, BIT_FIFOFLUSH, FUN_ENABLE);
|
||||
SetReg(REG_FIFODATA, 0x05); // APf
|
||||
SetReg(REG_FIFODATA, 0x00); // AFI (00:for all cards)
|
||||
SetReg(REG_FIFODATA, 0x08); // PARAM(WUPB, Number of slots = 0)
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN, ENABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN, ENABLE);
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN, FUN_ENABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN, FUN_ENABLE);
|
||||
SetCommand(CMD_TRANSCEIVE);
|
||||
rfid_delay_ms(10);
|
||||
GetReg(REG_ERROR, ®_data);
|
||||
@ -468,12 +467,12 @@ unsigned char ReaderB_Request(struct picc_b_struct *picc_b)
|
||||
unsigned char reg_data, i;
|
||||
SetCommand(CMD_IDLE);
|
||||
SetReg(REG_TXDATANUM, 0x08);
|
||||
ModifyReg(REG_FIFOCONTROL, BIT_FIFOFLUSH, ENABLE);
|
||||
ModifyReg(REG_FIFOCONTROL, BIT_FIFOFLUSH, FUN_ENABLE);
|
||||
SetReg(REG_FIFODATA, 0x05); // APf
|
||||
SetReg(REG_FIFODATA, 0x00); // AFI (00:for all cards)
|
||||
SetReg(REG_FIFODATA, 0x00); // PARAM(REQB, Number of slots = 0)
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN, ENABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN, ENABLE);
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN, FUN_ENABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN, FUN_ENABLE);
|
||||
SetCommand(CMD_TRANSCEIVE);
|
||||
rfid_delay_ms(10);
|
||||
GetReg(REG_ERROR, ®_data);
|
||||
@ -500,7 +499,7 @@ unsigned char ReaderB_Attrib(struct picc_b_struct *picc_b)
|
||||
unsigned char reg_data;
|
||||
SetCommand(CMD_IDLE);
|
||||
SetReg(REG_TXDATANUM, 0x08);
|
||||
ModifyReg(REG_FIFOCONTROL, BIT_FIFOFLUSH, ENABLE);
|
||||
ModifyReg(REG_FIFOCONTROL, BIT_FIFOFLUSH, FUN_ENABLE);
|
||||
SetReg(REG_FIFODATA, 0x1D);
|
||||
SetReg(REG_FIFODATA, picc_b->PUPI[0]);
|
||||
SetReg(REG_FIFODATA, picc_b->PUPI[1]);
|
||||
@ -510,8 +509,8 @@ unsigned char ReaderB_Attrib(struct picc_b_struct *picc_b)
|
||||
SetReg(REG_FIFODATA, 0x08); // Param2
|
||||
SetReg(REG_FIFODATA, 0x01); // COMPATIBLE WITH 14443-4
|
||||
SetReg(REG_FIFODATA, 0x01); // CID:01
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN, ENABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN, ENABLE);
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN, FUN_ENABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN, FUN_ENABLE);
|
||||
SetCommand(CMD_TRANSCEIVE);
|
||||
rfid_delay_ms(10);
|
||||
GetReg(REG_ERROR, ®_data);
|
||||
@ -536,15 +535,15 @@ unsigned char ReaderB_Halt(struct picc_b_struct *picc_b)
|
||||
unsigned char reg_data;
|
||||
SetCommand(CMD_IDLE);
|
||||
SetReg(REG_TXDATANUM, 0x08);
|
||||
ModifyReg(REG_FIFOCONTROL, BIT_FIFOFLUSH, ENABLE);
|
||||
ModifyReg(REG_FIFOCONTROL, BIT_FIFOFLUSH, FUN_ENABLE);
|
||||
SetReg(REG_FIFODATA, 0x50);
|
||||
SetReg(REG_FIFODATA, picc_b->PUPI[0]);
|
||||
SetReg(REG_FIFODATA, picc_b->PUPI[1]);
|
||||
SetReg(REG_FIFODATA, picc_b->PUPI[2]);
|
||||
SetReg(REG_FIFODATA, picc_b->PUPI[3]);
|
||||
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN, ENABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN, ENABLE);
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN, FUN_ENABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN, FUN_ENABLE);
|
||||
SetCommand(CMD_TRANSCEIVE);
|
||||
rfid_delay_ms(10);
|
||||
GetReg(REG_ERROR, ®_data);
|
||||
@ -569,15 +568,15 @@ unsigned char ReaderB_Get_SN(struct picc_b_struct *picc_b)
|
||||
unsigned char reg_data, i;
|
||||
SetCommand(CMD_IDLE);
|
||||
SetReg(REG_TXDATANUM, 0x08);
|
||||
ModifyReg(REG_FIFOCONTROL, BIT_FIFOFLUSH, ENABLE);
|
||||
ModifyReg(REG_FIFOCONTROL, BIT_FIFOFLUSH, FUN_ENABLE);
|
||||
SetReg(REG_FIFODATA, 0x00);
|
||||
SetReg(REG_FIFODATA, 0x36);
|
||||
SetReg(REG_FIFODATA, 0x00);
|
||||
SetReg(REG_FIFODATA, 0x00);
|
||||
SetReg(REG_FIFODATA, 0x08);
|
||||
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN, ENABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN, ENABLE);
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN, FUN_ENABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN, FUN_ENABLE);
|
||||
SetCommand(CMD_TRANSCEIVE);
|
||||
rfid_delay_ms(10);
|
||||
GetReg(REG_ERROR, ®_data);
|
||||
@ -602,13 +601,13 @@ unsigned char ReaderV_Inventory(struct picc_v_struct *picc_v)
|
||||
unsigned char reg_data, i;
|
||||
SetCommand(CMD_IDLE);
|
||||
SetReg(REG_TXDATANUM, 0x08);
|
||||
ModifyReg(REG_FIFOCONTROL, BIT_FIFOFLUSH, ENABLE);
|
||||
ModifyReg(REG_FIFOCONTROL, BIT_FIFOFLUSH, FUN_ENABLE);
|
||||
SetReg(REG_FIFODATA, 0x26);
|
||||
SetReg(REG_FIFODATA, 0x01);
|
||||
SetReg(REG_FIFODATA, 0x00);
|
||||
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN, ENABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN, ENABLE);
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN, FUN_ENABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN, FUN_ENABLE);
|
||||
|
||||
SetCommand(CMD_TRANSCEIVE);
|
||||
rfid_delay_ms(10);
|
||||
@ -637,7 +636,7 @@ unsigned char ReaderV_Select(struct picc_v_struct *picc_v)
|
||||
unsigned char reg_data;
|
||||
SetCommand(CMD_IDLE);
|
||||
SetReg(REG_TXDATANUM, 0x08);
|
||||
ModifyReg(REG_FIFOCONTROL, BIT_FIFOFLUSH, ENABLE);
|
||||
ModifyReg(REG_FIFOCONTROL, BIT_FIFOFLUSH, FUN_ENABLE);
|
||||
SetReg(REG_FIFODATA, 0x22); // Addressed flag
|
||||
SetReg(REG_FIFODATA, 0x25); // Select command
|
||||
SetReg(REG_FIFODATA, picc_v->UID[0]);
|
||||
@ -648,8 +647,8 @@ unsigned char ReaderV_Select(struct picc_v_struct *picc_v)
|
||||
SetReg(REG_FIFODATA, picc_v->UID[5]);
|
||||
SetReg(REG_FIFODATA, picc_v->UID[6]);
|
||||
SetReg(REG_FIFODATA, picc_v->UID[7]);
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN, ENABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN, ENABLE);
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN, FUN_ENABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN, FUN_ENABLE);
|
||||
|
||||
SetCommand(CMD_TRANSCEIVE);
|
||||
rfid_delay_ms(10);
|
||||
@ -674,13 +673,13 @@ unsigned char ReaderV_ReadSingleBlock(unsigned char block_num, struct picc_v_str
|
||||
unsigned char reg_data, i;
|
||||
SetCommand(CMD_IDLE);
|
||||
SetReg(REG_TXDATANUM, 0x08);
|
||||
ModifyReg(REG_FIFOCONTROL, BIT_FIFOFLUSH, ENABLE);
|
||||
ModifyReg(REG_FIFOCONTROL, BIT_FIFOFLUSH, FUN_ENABLE);
|
||||
SetReg(REG_FIFODATA, 0x02); // Addressed flag
|
||||
SetReg(REG_FIFODATA, 0x20); // Read Single Block command
|
||||
SetReg(REG_FIFODATA, block_num);
|
||||
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN, ENABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN, ENABLE);
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN, FUN_ENABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN, FUN_ENABLE);
|
||||
|
||||
SetCommand(CMD_TRANSCEIVE);
|
||||
rfid_delay_ms(10);
|
||||
@ -709,7 +708,7 @@ unsigned char ReaderV_WriteSingleBlock(unsigned char block_num, struct picc_v_st
|
||||
unsigned char reg_data;
|
||||
SetCommand(CMD_IDLE);
|
||||
SetReg(REG_TXDATANUM, 0x08);
|
||||
ModifyReg(REG_FIFOCONTROL, BIT_FIFOFLUSH, ENABLE);
|
||||
ModifyReg(REG_FIFOCONTROL, BIT_FIFOFLUSH, FUN_ENABLE);
|
||||
SetReg(REG_FIFODATA, 0x02); // Addressed flag
|
||||
SetReg(REG_FIFODATA, 0x21); // Write Single Block command
|
||||
SetReg(REG_FIFODATA, block_num);
|
||||
@ -717,8 +716,8 @@ unsigned char ReaderV_WriteSingleBlock(unsigned char block_num, struct picc_v_st
|
||||
SetReg(REG_FIFODATA, picc_v->BLOCK_DATA[1]);
|
||||
SetReg(REG_FIFODATA, picc_v->BLOCK_DATA[2]);
|
||||
SetReg(REG_FIFODATA, picc_v->BLOCK_DATA[3]);
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN, ENABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN, ENABLE);
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN, FUN_ENABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN, FUN_ENABLE);
|
||||
|
||||
SetCommand(CMD_TRANSCEIVE);
|
||||
rfid_delay_ms(10);
|
||||
@ -743,7 +742,7 @@ unsigned char ReaderF_Inventory(struct picc_f_struct *picc_f)
|
||||
unsigned char reg_data, i;
|
||||
SetCommand(CMD_IDLE);
|
||||
SetReg(REG_TXDATANUM, 0x08);
|
||||
ModifyReg(REG_FIFOCONTROL, BIT_FIFOFLUSH, ENABLE);
|
||||
ModifyReg(REG_FIFOCONTROL, BIT_FIFOFLUSH, FUN_ENABLE);
|
||||
|
||||
SetReg(REG_FIFODATA, 0x06);
|
||||
SetReg(REG_FIFODATA, 0x00);
|
||||
@ -752,8 +751,8 @@ unsigned char ReaderF_Inventory(struct picc_f_struct *picc_f)
|
||||
SetReg(REG_FIFODATA, 0x10);
|
||||
SetReg(REG_FIFODATA, 0x00);
|
||||
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN, ENABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN, ENABLE);
|
||||
ModifyReg(REG_TXCRCCON, BIT_CRCEN, FUN_ENABLE);
|
||||
ModifyReg(REG_RXCRCCON, BIT_CRCEN, FUN_ENABLE);
|
||||
|
||||
SetCommand(CMD_TRANSCEIVE);
|
||||
rfid_delay_ms(10);
|
||||
|
||||
@ -4,10 +4,6 @@
|
||||
********************************************************************************************************/
|
||||
|
||||
#include "./include/rfid_main.h"
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "./include/READER.h"
|
||||
#include "./include/READER_REG.h"
|
||||
#include "./include/MIFARE.h"
|
||||
@ -16,11 +12,11 @@
|
||||
#include "./rfid_hal.h"
|
||||
|
||||
|
||||
#define ENABLE_XLOG 1
|
||||
#define FUN_ENABLE_XLOG 1
|
||||
#ifdef xlog
|
||||
#undef xlog
|
||||
#endif
|
||||
#if ENABLE_XLOG
|
||||
#if FUN_ENABLE_XLOG
|
||||
#define xlog(format, ...) printf("[XT:%s] " format, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
#define xlog(format, ...) ((void)0)
|
||||
@ -49,16 +45,16 @@ void TYPE_A_EVENT(void)
|
||||
if (result != SUCCESS)
|
||||
{
|
||||
xlog("INIT_ERROR\r\n");
|
||||
SetCW(DISABLE);
|
||||
SetCW(FUN_DISABLE);
|
||||
return;
|
||||
}
|
||||
|
||||
// 打开RF场(载波)
|
||||
result = SetCW(ENABLE);
|
||||
result = SetCW(FUN_ENABLE);
|
||||
if (result != SUCCESS)
|
||||
{
|
||||
xlog("CW_ERROR\r\n");
|
||||
SetCW(DISABLE);
|
||||
SetCW(FUN_DISABLE);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -67,7 +63,7 @@ void TYPE_A_EVENT(void)
|
||||
if (result != SUCCESS)
|
||||
{
|
||||
// xlog("ReaderA_CardActivate_ERROR\r\n");
|
||||
SetCW(DISABLE);
|
||||
SetCW(FUN_DISABLE);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -102,7 +98,7 @@ void TYPE_A_EVENT(void)
|
||||
result = NTAG_EVENT();
|
||||
}
|
||||
|
||||
SetCW(DISABLE); // 关闭RF场
|
||||
SetCW(FUN_DISABLE); // 关闭RF场
|
||||
}
|
||||
|
||||
/**
|
||||
@ -124,12 +120,12 @@ void TYPE_B_EVENT(void)
|
||||
xlog("TYPE_B_EVENT begin\n");
|
||||
|
||||
ReaderB_Initial();
|
||||
SetCW(ENABLE);
|
||||
SetCW(FUN_ENABLE);
|
||||
|
||||
result = ReaderB_Request(&PICC_B);
|
||||
if (result != SUCCESS)
|
||||
{
|
||||
SetCW(DISABLE);
|
||||
SetCW(FUN_DISABLE);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -142,7 +138,7 @@ void TYPE_B_EVENT(void)
|
||||
result = ReaderB_Attrib(&PICC_B);
|
||||
if (result != SUCCESS)
|
||||
{
|
||||
SetCW(DISABLE);
|
||||
SetCW(FUN_DISABLE);
|
||||
return;
|
||||
}
|
||||
xlog("-> ATTRIB = %02X\r\n", PICC_B.CID);
|
||||
@ -150,14 +146,14 @@ void TYPE_B_EVENT(void)
|
||||
result = ReaderB_Get_SN(&PICC_B);
|
||||
if (result != SUCCESS)
|
||||
{
|
||||
SetCW(DISABLE);
|
||||
SetCW(FUN_DISABLE);
|
||||
return;
|
||||
}
|
||||
xlog("-> SN = ");
|
||||
for(i=0; i<8; i++) xlog("%02X", PICC_B.SN[i]);
|
||||
xlog("\r\n");
|
||||
|
||||
SetCW(DISABLE);
|
||||
SetCW(FUN_DISABLE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -178,12 +174,12 @@ void TYPE_V_EVENT(void)
|
||||
xlog("TYPE_V_EVENT begin\n");
|
||||
|
||||
ReaderV_Initial();
|
||||
SetCW(ENABLE);
|
||||
SetCW(FUN_ENABLE);
|
||||
|
||||
result = ReaderV_Inventory(&PICC_V);
|
||||
if (result != SUCCESS)
|
||||
{
|
||||
SetCW(DISABLE);
|
||||
SetCW(FUN_DISABLE);
|
||||
xlog("-> ReaderV Inventory ERROR!\r\n");
|
||||
return;
|
||||
}
|
||||
@ -199,7 +195,7 @@ void TYPE_V_EVENT(void)
|
||||
result = ReaderV_Select(&PICC_V);
|
||||
if (result != SUCCESS)
|
||||
{
|
||||
SetCW(DISABLE);
|
||||
SetCW(FUN_DISABLE);
|
||||
xlog("-> ReaderV Select ERROR!\r\n");
|
||||
return;
|
||||
}
|
||||
@ -209,7 +205,7 @@ void TYPE_V_EVENT(void)
|
||||
result = ReaderV_WriteSingleBlock(4, &PICC_V);
|
||||
if (result != SUCCESS)
|
||||
{
|
||||
SetCW(DISABLE);
|
||||
SetCW(FUN_DISABLE);
|
||||
xlog("-> ReaderV WriteSingleBlock ERROR!\r\n");
|
||||
return;
|
||||
}
|
||||
@ -219,13 +215,13 @@ void TYPE_V_EVENT(void)
|
||||
result = ReaderV_ReadSingleBlock(4, &PICC_V);
|
||||
if (result != SUCCESS)
|
||||
{
|
||||
SetCW(DISABLE);
|
||||
SetCW(FUN_DISABLE);
|
||||
xlog("-> ReaderV ReadSingleBlock ERROR!\r\n");
|
||||
return;
|
||||
}
|
||||
xlog("BLOCK DATA = %02X%02X%02X%02X \r\n", PICC_V.BLOCK_DATA[0], PICC_V.BLOCK_DATA[1], PICC_V.BLOCK_DATA[2], PICC_V.BLOCK_DATA[3]);
|
||||
|
||||
SetCW(DISABLE);
|
||||
SetCW(FUN_DISABLE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -245,12 +241,12 @@ void TYPE_F_EVENT(void)
|
||||
unsigned char result, i;
|
||||
xlog("TYPE_F_EVENT begin\n");
|
||||
ReaderF_Initial();
|
||||
SetCW(ENABLE);
|
||||
SetCW(FUN_ENABLE);
|
||||
|
||||
result = ReaderF_Inventory(&PICC_F);
|
||||
if (result != SUCCESS)
|
||||
{
|
||||
SetCW(DISABLE);
|
||||
SetCW(FUN_DISABLE);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -259,7 +255,7 @@ void TYPE_F_EVENT(void)
|
||||
for(i=0; i<8; i++) xlog("%02X", PICC_F.UID[i]);
|
||||
xlog("\r\n");
|
||||
|
||||
SetCW(DISABLE);
|
||||
SetCW(FUN_DISABLE);
|
||||
}
|
||||
|
||||
|
||||
@ -276,7 +272,8 @@ void rfid_task_fuc(void)
|
||||
if(first_init == 0){
|
||||
first_init = 1;
|
||||
|
||||
rfid_hal_init();
|
||||
// rfid_hal_init();
|
||||
FM176XX_HardInit();
|
||||
// 2. 复位 FM176XX 芯片
|
||||
while (1)
|
||||
{
|
||||
|
||||
@ -3,6 +3,16 @@
|
||||
#include "./include/rfid_main.h"
|
||||
#include "./include/READER_REG.h"
|
||||
|
||||
#define FUN_ENABLE_XLOG 1
|
||||
#ifdef xlog
|
||||
#undef xlog
|
||||
#endif
|
||||
#if FUN_ENABLE_XLOG
|
||||
#define xlog(format, ...) printf("[XT:%s] " format, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
#define xlog(format, ...) ((void)0)
|
||||
#endif
|
||||
|
||||
#define INTERFACE_TYPE 0
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
|
||||
37
apps/earphone/xtell_Sensor/example/example.c
Normal file
37
apps/earphone/xtell_Sensor/example/example.c
Normal file
@ -0,0 +1,37 @@
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//START -- 宏定义
|
||||
#define ENABLE_XLOG 1
|
||||
#ifdef xlog
|
||||
#undef xlog
|
||||
#endif
|
||||
#if ENABLE_XLOG
|
||||
#define xlog(format, ...) printf("[%s] " format, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
#define xlog(format, ...) ((void)0)
|
||||
#endif
|
||||
|
||||
//END -- 宏定义
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//START -- 变量定义
|
||||
|
||||
|
||||
|
||||
|
||||
//END -- 变量定义
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//START -- 函数定义
|
||||
|
||||
|
||||
//END -- 函数定义
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//实现
|
||||
10
apps/earphone/xtell_Sensor/xtell.h
Normal file
10
apps/earphone/xtell_Sensor/xtell.h
Normal file
@ -0,0 +1,10 @@
|
||||
#ifndef XTELL_H
|
||||
#define XTELL_H
|
||||
#include "system/includes.h"
|
||||
|
||||
// #define KS_BLE 1
|
||||
#define XTELL_TEST 1
|
||||
|
||||
#define ACC_RANGE 16 //g,加速度满量程:2、4、8、16
|
||||
|
||||
#endif
|
||||
173
apps/earphone/xtell_Sensor/xtell_app_main.c
Normal file
173
apps/earphone/xtell_Sensor/xtell_app_main.c
Normal file
@ -0,0 +1,173 @@
|
||||
#include "system/includes.h"
|
||||
/*#include "btcontroller_config.h"*/
|
||||
#include "btstack/btstack_task.h"
|
||||
#include "app_config.h"
|
||||
#include "app_action.h"
|
||||
#include "asm/pwm_led.h"
|
||||
#include "tone_player.h"
|
||||
#include "gpio.h"
|
||||
#include "app_main.h"
|
||||
#include "asm/charge.h"
|
||||
#include "update.h"
|
||||
#include "app_power_manage.h"
|
||||
#include "app_charge.h"
|
||||
#include "bt_profile_cfg.h"
|
||||
#include "dev_manager/dev_manager.h"
|
||||
#include "update_loader_download.h"
|
||||
#include "avctp_user.h"
|
||||
#include "debug.h"
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//宏定义
|
||||
#define ENABLE_XLOG 1
|
||||
#ifdef xlog
|
||||
#undef xlog
|
||||
#endif
|
||||
#if ENABLE_XLOG
|
||||
#define xlog(format, ...) printf("[XT:%s] " format, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
#define xlog(format, ...) ((void)0)
|
||||
#endif
|
||||
|
||||
#define LOG_TAG_CONST APP
|
||||
#define LOG_TAG "[APP]"
|
||||
#define LOG_ERROR_ENABLE
|
||||
#define LOG_DEBUG_ENABLE
|
||||
#define LOG_INFO_ENABLE
|
||||
/* #define LOG_DUMP_ENABLE */
|
||||
#define LOG_CLI_ENABLE
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//变量
|
||||
extern APP_VAR app_var;
|
||||
u16 close_BL_number=0;
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//函数定义
|
||||
extern void timer_2ms_handler();
|
||||
extern void app_var_init(void);
|
||||
void app_earphone_play_voice_file(const char *name);
|
||||
void clr_wdt(void);
|
||||
extern void check_power_on_key(void);
|
||||
extern int cpu_reset_by_soft();
|
||||
extern int audio_dec_init();
|
||||
extern int audio_enc_init();
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*充电拔出,CPU软件复位, 不检测按键,直接开机*/
|
||||
static void app_poweron_check(int update)
|
||||
{
|
||||
if (!update && cpu_reset_by_soft()) {
|
||||
app_var.play_poweron_tone = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
void create_process(u16* pid,char* name, void *priv, void (*func)(void *priv), u32 msec){
|
||||
xlog("1 name=%s, pid =%d\n",name,*pid);
|
||||
if (*pid != 0) return;
|
||||
*pid = sys_timer_add(priv, func, msec);
|
||||
xlog("2 name=%s, pid =%d\n",name,*pid);
|
||||
}
|
||||
void close_process(u16* pid,char* name){
|
||||
xlog("name=%s,pid =%d\n",name,*pid);
|
||||
if (*pid == 0) return;
|
||||
sys_timer_del(*pid);
|
||||
*pid = 0;
|
||||
}
|
||||
|
||||
|
||||
void close_BL(){
|
||||
/**开机默认关闭 经典蓝牙 */
|
||||
// close_BL_flag++;
|
||||
xlog("xtell Classic Bluetooth off\n");
|
||||
user_send_cmd_prepare(USER_CTRL_DISCONNECTION_HCI, 0, NULL); //断开此时经典蓝牙的连接,经典蓝牙还是可以被发现
|
||||
delay_2ms(50);
|
||||
user_send_cmd_prepare(USER_CTRL_WRITE_SCAN_DISABLE, 0, NULL); //关闭蓝牙可发现,已连接时不能操作
|
||||
delay_2ms(50);
|
||||
user_send_cmd_prepare(USER_CTRL_WRITE_CONN_DISABLE, 0, NULL); //关闭蓝牙可连接,
|
||||
// sys_timer_del(close_BL_number); //删除定时器任务
|
||||
close_process(&close_BL_number,__func__);
|
||||
}
|
||||
|
||||
void xtell_set_ble_name(char* name){
|
||||
|
||||
}
|
||||
|
||||
|
||||
extern u32 timer_get_ms(void);
|
||||
void xtell_app_main()
|
||||
{
|
||||
int update = 0;
|
||||
u32 addr = 0, size = 0;
|
||||
struct intent it;
|
||||
|
||||
xlog("==============xtell_app_main start================\n");
|
||||
log_info("app_main\n");
|
||||
app_var.start_time = timer_get_ms();
|
||||
|
||||
|
||||
|
||||
if (!UPDATE_SUPPORT_DEV_IS_NULL()) {
|
||||
update = update_result_deal();
|
||||
}
|
||||
|
||||
app_var_init();
|
||||
|
||||
if (get_charge_online_flag()) {
|
||||
#if(TCFG_SYS_LVD_EN == 1)
|
||||
vbat_check_init();
|
||||
#endif
|
||||
xlog("==============idle================\n");
|
||||
init_intent(&it);
|
||||
it.name = "idle";
|
||||
it.action = ACTION_IDLE_MAIN;
|
||||
start_app(&it);
|
||||
} else {
|
||||
xlog("==============handler start================\n");
|
||||
check_power_on_voltage();
|
||||
app_poweron_check(update);
|
||||
init_intent(&it);
|
||||
it.name = "handler";
|
||||
it.action = ACTION_EARPHONE_MAIN;
|
||||
start_app(&it);
|
||||
xlog("==============handler end================\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
//开机必须延时关闭经典蓝牙,不然底层代码会再次把蓝牙 打开
|
||||
// create_process(&close_BL_number, "close_BL",NULL, close_BL, 3000);
|
||||
|
||||
|
||||
|
||||
|
||||
u8 mac_data[6];
|
||||
extern void rcsp_adv_fill_mac_addr(u8 *mac_addr_buf);
|
||||
rcsp_adv_fill_mac_addr(mac_data); //读取MAC地址
|
||||
xlog("xtell BT mac data:%x:%x:%x:%x:%x:%x",mac_data[0],mac_data[1],mac_data[2],mac_data[3],mac_data[4],mac_data[5]);
|
||||
|
||||
|
||||
user_send_cmd_prepare(USER_CTRL_WRITE_SCAN_ENABLE, 0, NULL); //打开蓝牙可发现,已连接时不能操作
|
||||
delay_2ms(50);
|
||||
user_send_cmd_prepare(USER_CTRL_WRITE_CONN_ENABLE, 0, NULL); //打开蓝牙可连接
|
||||
delay_2ms(50);
|
||||
|
||||
|
||||
|
||||
xlog("==============xtell_app_end================\n");
|
||||
|
||||
}
|
||||
|
||||
498
apps/earphone/xtell_Sensor/xtell_handler.c
Normal file
498
apps/earphone/xtell_Sensor/xtell_handler.c
Normal file
@ -0,0 +1,498 @@
|
||||
#include "system/includes.h"
|
||||
#include "media/includes.h"
|
||||
#include "tone_player.h"
|
||||
#include "earphone.h"
|
||||
|
||||
#include "app_config.h"
|
||||
#include "app_action.h"
|
||||
#include "app_task.h"
|
||||
|
||||
#include "btstack/avctp_user.h"
|
||||
#include "btstack/btstack_task.h"
|
||||
#include "btctrler/btctrler_task.h"
|
||||
#include "btstack/frame_queque.h"
|
||||
#include "user_cfg.h"
|
||||
// #include "aec_user.h"
|
||||
#include "classic/hci_lmp.h"
|
||||
#include "bt_common.h"
|
||||
#include "bt_ble.h"
|
||||
#include "bt_tws.h"
|
||||
#include "pbg_user.h"
|
||||
#include "btstack/bluetooth.h"
|
||||
#include "colorful_lights/colorful_lights.h"
|
||||
|
||||
#include "app_chargestore.h"
|
||||
#include "jl_kws/jl_kws_api.h"
|
||||
|
||||
#include "asm/charge.h"
|
||||
#include "app_charge.h"
|
||||
#include "ui_manage.h"
|
||||
|
||||
#include "app_chargestore.h"
|
||||
#include "app_umidigi_chargestore.h"
|
||||
#include "app_testbox.h"
|
||||
#include "app_online_cfg.h"
|
||||
#include "app_main.h"
|
||||
#include "app_power_manage.h"
|
||||
#include "gSensor/gSensor_manage.h"
|
||||
#include "key_event_deal.h"
|
||||
#include "classic/tws_api.h"
|
||||
#include "asm/pwm_led.h"
|
||||
#include "ir_sensor/ir_manage.h"
|
||||
#include "in_ear_detect/in_ear_manage.h"
|
||||
#include "vol_sync.h"
|
||||
#include "bt_background.h"
|
||||
#include "default_event_handler.h"
|
||||
#include "debug.h"
|
||||
#include "system/event.h"
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//宏定义
|
||||
#define LOG_TAG_CONST EARPHONE
|
||||
#define LOG_TAG "[EARPHONE]"
|
||||
#define LOG_ERROR_ENABLE
|
||||
#define LOG_DEBUG_ENABLE
|
||||
#define xlog_ENABLE
|
||||
|
||||
|
||||
#if(USE_DMA_UART_TEST) //使用dm串口测试时不能同时打开
|
||||
#define MY_SNIFF_EN 0
|
||||
#else
|
||||
#define MY_SNIFF_EN 1 //默认打开
|
||||
#endif
|
||||
|
||||
#define ENABLE_XLOG 1
|
||||
#ifdef xlog
|
||||
#undef xlog
|
||||
#endif
|
||||
#if ENABLE_XLOG
|
||||
#define xlog(format, ...) printf("[XT:%s] " format, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
#define xlog(format, ...) ((void)0)
|
||||
#endif
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//变量
|
||||
extern u8 init_ok;
|
||||
extern u8 sniff_out;
|
||||
unsigned char xtell_bl_state=0; //存放经典蓝牙的连接状态,0断开,1是连接
|
||||
u8 bt_newname =0;
|
||||
unsigned char xt_ble_new_name[9] = "CM-22222";
|
||||
static u16 play_poweron_ok_timer_id = 0;
|
||||
|
||||
// -- 初始化标志位 --
|
||||
u8 SC7U22_init = 0x10; //六轴是否初始化
|
||||
u8 MMC5603nj_init = 0x20; //地磁是否初始化
|
||||
u8 BMP280_init = 0x30; //气压计初始化
|
||||
// -- 线程id --
|
||||
u16 SC7U22_calibration_id;
|
||||
u16 start_collect_fuc_id;
|
||||
u16 BLE_send_fuc_id;
|
||||
u16 rfid_fuc_id;
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
extern int bt_hci_event_handler(struct bt_event *bt);
|
||||
extern void SC7U22_static_calibration(void);
|
||||
extern void create_process(u16* pid, const char* name, void *priv, void (*func)(void *priv), u32 msec);
|
||||
extern void close_process(u16* pid,char* name);
|
||||
extern void start_collect_fuc(void);
|
||||
extern void BLE_send_fuc(void);
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/*
|
||||
* 模式状态机, 通过start_app()控制状态切换
|
||||
*/
|
||||
/* extern int audio_mic_init(); */
|
||||
|
||||
static int state_machine(struct application *app, enum app_state state, struct intent *it){
|
||||
int error = 0;
|
||||
static u8 tone_player_err = 0;
|
||||
xlog("bt_state_machine=%d\n", state);
|
||||
switch (state) {
|
||||
case APP_STA_CREATE:
|
||||
xlog("APP_STA_CREATE\n");
|
||||
/* set_adjust_conn_dac_check(0); */
|
||||
|
||||
break;
|
||||
case APP_STA_START:
|
||||
xlog("APP_STA_START\n");
|
||||
if (!it) {
|
||||
xlog("APP_STA_START:it none\n");
|
||||
break;
|
||||
}
|
||||
switch (it->action) {
|
||||
case ACTION_EARPHONE_MAIN:
|
||||
xlog("ble init\n");
|
||||
/*
|
||||
* handler 初始化
|
||||
*/
|
||||
clk_set("sys", BT_NORMAL_HZ);
|
||||
u32 sys_clk = clk_get("sys");
|
||||
bt_pll_para(TCFG_CLOCK_OSC_HZ, sys_clk, 0, 0);
|
||||
/* bredr_set_dut_enble(1, 1); */
|
||||
bt_function_select_init();
|
||||
bredr_handle_register();
|
||||
EARPHONE_STATE_INIT();
|
||||
btstack_init();
|
||||
sys_auto_shut_down_enable();
|
||||
bt_sniff_feature_init();
|
||||
sys_auto_sniff_controle(MY_SNIFF_EN, NULL);
|
||||
app_var.dev_volume = -1;
|
||||
break;
|
||||
case ACTION_A2DP_START: //蓝牙音频传输协议
|
||||
xlog("ACTION_A2DP_START\n");
|
||||
break;
|
||||
case ACTION_BY_KEY_MODE:
|
||||
xlog("ACTION_BY_KEY_MODE\n");
|
||||
break;
|
||||
case ACTION_TONE_PLAY:
|
||||
xlog("ACTION_TONE_PLAY\n");
|
||||
// STATUS *p_tone = get_tone_config();
|
||||
// tone_play_index(p_tone->bt_init_ok, 1);
|
||||
break;
|
||||
case ACTION_DO_NOTHING:
|
||||
xlog("ACTION_DO_NOTHING\n");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case APP_STA_PAUSE:
|
||||
xlog("APP_STA_PAUSE\n");
|
||||
break;
|
||||
case APP_STA_RESUME:
|
||||
xlog("APP_STA_RESUME\n");
|
||||
//恢复前台运行
|
||||
sys_auto_shut_down_disable();
|
||||
sys_key_event_enable();
|
||||
break;
|
||||
case APP_STA_STOP:
|
||||
xlog("APP_STA_STOP\n");
|
||||
break;
|
||||
case APP_STA_DESTROY:
|
||||
xlog("APP_STA_DESTROY\n");
|
||||
r_printf("APP_STA_DESTROY\n");
|
||||
if (!app_var.goto_poweroff_flag) {
|
||||
bt_app_exit(NULL);
|
||||
}
|
||||
break;
|
||||
}
|
||||
xlog("state machine error\n");
|
||||
return error;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//handle
|
||||
|
||||
|
||||
void le_user_app_send_event(size_t command, unsigned char* data, size_t size)
|
||||
{
|
||||
// 中断->事件
|
||||
static unsigned char buffer[512];
|
||||
if(data && size && size <= sizeof(buffer)) {
|
||||
// 拷贝到缓存,避免转发事件的时候,地址发送改变。
|
||||
memcpy(buffer, data, size);
|
||||
struct sys_event event;
|
||||
event.type = SYS_APP_USER_EVENT;
|
||||
event.u.app.command = command;
|
||||
event.u.app.buffer = buffer;
|
||||
event.u.app.size = size;
|
||||
sys_event_notify(&event);
|
||||
}
|
||||
}
|
||||
|
||||
void le_user_app_event_handler(struct sys_event* event){
|
||||
|
||||
switch (event->type) {
|
||||
// 打印接收到的数据
|
||||
printf("BLE data\n");
|
||||
put_buf(event->u.app.buffer, event->u.app.size);
|
||||
case SYS_APP_USER_EVENT:
|
||||
if (event->u.app.buffer[0] == 0xBE && event->u.app.buffer[1] == 0xBB) {
|
||||
if(event->u.app.buffer[2] == 0x01){ //后面的数据长度 1
|
||||
switch (event->u.app.buffer[3]){
|
||||
case 0xff: //测试
|
||||
extern void i2c_scanner_probe(void);
|
||||
// i2c_scanner_probe();
|
||||
extern void rfid_task_fuc(void);
|
||||
create_process(&rfid_fuc_id,"rfid",NULL,rfid_task_fuc,1000);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}else if(event->u.app.buffer[2] == 0x02){ //后面数据长度为2
|
||||
switch (event->u.app.buffer[3]){ //数据包类型
|
||||
case 0x00:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
xlog("%d\n",event->type);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
static void play_poweron_ok_timer(void *priv)
|
||||
{
|
||||
app_var.wait_timer_do = 0;
|
||||
|
||||
log_d("\n-------play_poweron_ok_timer-------\n", priv);
|
||||
if (is_dac_power_off()) {
|
||||
#if TCFG_USER_TWS_ENABLE
|
||||
bt_tws_poweron();
|
||||
#else
|
||||
bt_wait_connect_and_phone_connect_switch(0);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
app_var.wait_timer_do = sys_timeout_add(priv, play_poweron_ok_timer, 100);
|
||||
}
|
||||
|
||||
static void play_bt_connect_dly(void *priv)
|
||||
{
|
||||
app_var.wait_timer_do = 0;
|
||||
|
||||
log_d("\n-------play_bt_connect_dly-------\n", priv);
|
||||
|
||||
if (!app_var.goto_poweroff_flag) {
|
||||
STATUS *p_tone = get_tone_config();
|
||||
tone_play_index(p_tone->bt_connect_ok, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int bt_connction_status_event_handler(struct bt_event *bt)
|
||||
{
|
||||
STATUS *p_tone = get_tone_config();
|
||||
u8 *phone_number = NULL;
|
||||
|
||||
switch (bt->event) {
|
||||
case BT_STATUS_INIT_OK:
|
||||
/*
|
||||
* 蓝牙初始化完成
|
||||
*/
|
||||
xlog("BT_STATUS_INIT_OK\n");
|
||||
init_ok = 1;
|
||||
__set_sbc_cap_bitpool(38);
|
||||
|
||||
#if (TCFG_USER_BLE_ENABLE)
|
||||
if (BT_MODE_IS(BT_BQB)) {
|
||||
ble_bqb_test_thread_init();
|
||||
} else {
|
||||
#if !TCFG_WIRELESS_MIC_ENABLE
|
||||
bt_ble_init();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
bt_init_ok_search_index();
|
||||
#if TCFG_TEST_BOX_ENABLE
|
||||
testbox_set_bt_init_ok(1);
|
||||
#endif
|
||||
|
||||
#if ((CONFIG_BT_MODE == BT_BQB)||(CONFIG_BT_MODE == BT_PER))
|
||||
bt_wait_phone_connect_control(1);
|
||||
#else
|
||||
if (is_dac_power_off()) {
|
||||
bt_wait_connect_and_phone_connect_switch(0);
|
||||
} else {
|
||||
app_var.wait_timer_do = sys_timeout_add(NULL, play_poweron_ok_timer, 100);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*if (app_var.play_poweron_tone) {
|
||||
tone_play_index(p_tone->power_on, 1);
|
||||
}*/
|
||||
break;
|
||||
|
||||
case BT_STATUS_SECOND_CONNECTED:
|
||||
clear_current_poweron_memory_search_index(0);
|
||||
case BT_STATUS_FIRST_CONNECTED:
|
||||
xlog("BT_STATUS_CONNECTED\n");
|
||||
xtell_bl_state = 1; //蓝牙连接成功 置1
|
||||
if(strcmp(xt_ble_new_name,"CM-11111") != 0){
|
||||
//蓝牙连接成功
|
||||
bt_newname =1;
|
||||
u8 temp[5]={0xBB,0xBE,0x02,0x04,0x00};
|
||||
temp[4] = xtell_bl_state; //经典蓝牙连接状态
|
||||
send_data_to_ble_client(&temp,5);
|
||||
}
|
||||
earphone_change_pwr_mode(PWR_DCDC15, 3000);
|
||||
sys_auto_shut_down_disable();
|
||||
|
||||
ui_update_status(STATUS_BT_CONN); //单台在此处设置连接状态,对耳的连接状态需要同步,在bt_tws.c中去设置
|
||||
|
||||
/* tone_play(TONE_CONN); */
|
||||
/*os_time_dly(40); // for test*/
|
||||
xlog("tone status:%d\n", tone_get_status());
|
||||
if (get_call_status() == BT_CALL_HANGUP) {
|
||||
if (app_var.phone_dly_discon_time) {
|
||||
sys_timeout_del(app_var.phone_dly_discon_time);
|
||||
app_var.phone_dly_discon_time = 0;
|
||||
} else {
|
||||
app_var.wait_timer_do = sys_timeout_add(NULL, play_bt_connect_dly, 1600);
|
||||
/* tone_play_index(p_tone->bt_connect_ok, 1); */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*int timeout = 5000 + rand32() % 10000;
|
||||
sys_timeout_add(NULL, connect_phone_test, timeout);*/
|
||||
break;
|
||||
case BT_STATUS_FIRST_DISCONNECT:
|
||||
case BT_STATUS_SECOND_DISCONNECT:
|
||||
xlog("BT_STATUS_DISCONNECT\n");
|
||||
xtell_bl_state = 0; //断开蓝牙 清0
|
||||
//蓝牙断开连接
|
||||
if(bt_newname){ //已经改成新蓝牙名字,断开才播报
|
||||
bt_newname=0;
|
||||
u8 temp[5]={0xBB,0xBE,0x02,0x04,0x00};
|
||||
temp[4] = xtell_bl_state; //经典蓝牙连接状态
|
||||
send_data_to_ble_client(&temp,5);
|
||||
}
|
||||
if (app_var.goto_poweroff_flag) {
|
||||
/*关机不播断开提示音*/
|
||||
/*关机时不改UI*/
|
||||
break;
|
||||
}
|
||||
// bt_discon_dly_handle(NULL);
|
||||
break;
|
||||
|
||||
//phone status deal
|
||||
case BT_STATUS_PHONE_INCOME:
|
||||
break;
|
||||
case BT_STATUS_PHONE_OUT:
|
||||
|
||||
break;
|
||||
case BT_STATUS_PHONE_ACTIVE:
|
||||
break;
|
||||
case BT_STATUS_PHONE_HANGUP:
|
||||
break;
|
||||
case BT_STATUS_PHONE_NUMBER:
|
||||
break;
|
||||
case BT_STATUS_INBAND_RINGTONE: //铃声
|
||||
break;
|
||||
case BT_STATUS_CALL_VOL_CHANGE:
|
||||
|
||||
break;
|
||||
case BT_STATUS_SNIFF_STATE_UPDATE:
|
||||
xlog(" BT_STATUS_SNIFF_STATE_UPDATE %d\n", bt->value); //0退出SNIFF
|
||||
if (bt->value == 0) {
|
||||
sniff_out = 1;
|
||||
sys_auto_sniff_controle(MY_SNIFF_EN, bt->args);
|
||||
} else {
|
||||
sys_auto_sniff_controle(0, bt->args);
|
||||
}
|
||||
break;
|
||||
|
||||
case BT_STATUS_LAST_CALL_TYPE_CHANGE:
|
||||
break;
|
||||
|
||||
case BT_STATUS_CONN_A2DP_CH:
|
||||
case BT_STATUS_CONN_HFP_CH:
|
||||
|
||||
if ((!is_1t2_connection()) && (get_current_poweron_memory_search_index(NULL))) { //回连下一个device
|
||||
if (get_esco_coder_busy_flag()) {
|
||||
clear_current_poweron_memory_search_index(0);
|
||||
} else {
|
||||
user_send_cmd_prepare(USER_CTRL_START_CONNECTION, 0, NULL);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case BT_STATUS_PHONE_MANUFACTURER:
|
||||
break;
|
||||
case BT_STATUS_VOICE_RECOGNITION:
|
||||
|
||||
break;
|
||||
case BT_STATUS_AVRCP_INCOME_OPID:
|
||||
xlog("BT_STATUS_AVRCP_INCOME_OPID:%d\n", bt->value);
|
||||
break;
|
||||
default:
|
||||
xlog(" BT STATUS DEFAULT\n");
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int event_handler(struct application *app, struct sys_event *event)
|
||||
{
|
||||
|
||||
le_user_app_event_handler(event);
|
||||
|
||||
if (SYS_EVENT_REMAP(event)) {
|
||||
g_printf("****SYS_EVENT_REMAP**** \n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (event->type) {
|
||||
case SYS_KEY_EVENT:
|
||||
break;
|
||||
case SYS_BT_EVENT:
|
||||
/*
|
||||
* 蓝牙事件处理
|
||||
*/
|
||||
if ((u32)event->arg == SYS_BT_EVENT_TYPE_CON_STATUS) {
|
||||
printf("in event_handler:bt_connction_status_event_handler");
|
||||
bt_connction_status_event_handler(&event->u.bt);
|
||||
} else if ((u32)event->arg == SYS_BT_EVENT_TYPE_HCI_STATUS) {
|
||||
bt_hci_event_handler(&event->u.bt);
|
||||
}
|
||||
break;
|
||||
case SYS_DEVICE_EVENT:
|
||||
/*
|
||||
* 系统设备事件处理
|
||||
*/
|
||||
if ((u32)event->arg == DEVICE_EVENT_FROM_CHARGE) {
|
||||
|
||||
} else if ((u32)event->arg == DEVICE_EVENT_FROM_POWER) {
|
||||
return app_power_event_handler(&event->u.dev);
|
||||
}
|
||||
#if TCFG_UMIDIGI_BOX_ENABLE
|
||||
else if ((u32)event->arg == DEVICE_EVENT_UMIDIGI_CHARGE_STORE) {
|
||||
app_umidigi_chargestore_event_handler(&event->u.umidigi_chargestore);
|
||||
}
|
||||
#endif
|
||||
#if TCFG_TEST_BOX_ENABLE
|
||||
else if ((u32)event->arg == DEVICE_EVENT_TEST_BOX) {
|
||||
app_testbox_event_handler(&event->u.testbox);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
SYS_EVENT_HANDLER_SPECIFIC(event);
|
||||
#ifdef CONFIG_BT_BACKGROUND_ENABLE
|
||||
if (app) {
|
||||
default_event_handler(event);
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static const struct application_operation app_handler_ops = {
|
||||
.state_machine = state_machine,
|
||||
.event_handler = event_handler,
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* 注册earphone模式
|
||||
*/
|
||||
REGISTER_APPLICATION(app_handler) = {
|
||||
.name = "handler",
|
||||
.action = ACTION_EARPHONE_MAIN,
|
||||
.ops = &app_handler_ops,
|
||||
.state = APP_STA_DESTROY,
|
||||
};
|
||||
Reference in New Issue
Block a user