整理2401代码,删除无用函数

This commit is contained in:
nnhy 2015-09-07 10:11:16 +00:00
parent 2e46db7408
commit 844d94a0e8
2 changed files with 17 additions and 57 deletions

View File

@ -191,17 +191,9 @@
}RF_FEATURE; }RF_FEATURE;
#endif #endif
void AutoOpenTask(void* param); static void AutoOpenTask(void* param);
NRF24L01::NRF24L01() { Init(); } NRF24L01::NRF24L01()
/*NRF24L01::NRF24L01(Spi* spi, Pin ce, Pin irq)
{
Init();
Init(spi, ce, irq);
}*/
void NRF24L01::Init()
{ {
Power = NULL; Power = NULL;
_spi = NULL; _spi = NULL;
@ -224,8 +216,8 @@ void NRF24L01::Init()
MaxError = 10; MaxError = 10;
Error = 0; Error = 0;
_tidOpen = 0; _tidOpen = 0;
_tidRecv = 0; _tidRecv = 0;
_Lock = 0; _Lock = 0;
@ -235,7 +227,7 @@ void NRF24L01::Init()
void NRF24L01::Init(Spi* spi, Pin ce, Pin irq, Pin power) void NRF24L01::Init(Spi* spi, Pin ce, Pin irq, Pin power)
{ {
debug_printf("NRF24L01::Init CE=P%c%d IRQ=P%c%d POWER=P%c%d\r\n", _PIN_NAME(ce), _PIN_NAME(irq), _PIN_NAME(power)); debug_printf("NRF24L01::Init CE=P%c%d IRQ=P%c%d Power=P%c%d\r\n", _PIN_NAME(ce), _PIN_NAME(irq), _PIN_NAME(power));
if(ce != P0) if(ce != P0)
{ {
@ -279,7 +271,7 @@ NRF24L01::~NRF24L01()
debug_printf("NRF24L01::~NRF24L01\r\n"); debug_printf("NRF24L01::~NRF24L01\r\n");
Sys.RemoveTask(_tidOpen); Sys.RemoveTask(_tidOpen);
Sys.RemoveTask(_tidOpen); Sys.RemoveTask(_tidRecv);
Register(NULL); Register(NULL);
@ -493,11 +485,11 @@ bool NRF24L01::Config()
// 编译器会优化下面的代码为一个常数 // 编译器会优化下面的代码为一个常数
RF_CONFIG config; RF_CONFIG config;
config.Init(); config.Init();
config.PRIM_RX = 0; //config.PRIM_RX = 0;
config.PWR_UP = 0; // 1:上电 0:掉电 config.PWR_UP = 0; // 1:上电 0:掉电
config.CRCO = 1; // CRC 模式0-8 位CRC 校验1-16 位CRC 校验 config.CRCO = 1; // CRC 模式0-8 位CRC 校验1-16 位CRC 校验
config.EN_CRC = 1; // CRC 使能如果EN_AA 中任意一位为高则EN_CRC 强迫为高 config.EN_CRC = 1; // CRC 使能如果EN_AA 中任意一位为高则EN_CRC 强迫为高
config.PRIM_RX = 1; // 默认进入接收模式 config.PRIM_RX = 1; // 默认进入接收模式
config.MAX_RT = 0; config.MAX_RT = 0;
config.TX_DS = 0; config.TX_DS = 0;
@ -508,7 +500,7 @@ bool NRF24L01::Config()
// 在ACK模式下发送失败和接收失败要清空发送缓冲区和接收缓冲区否则不能进行下次发射或接收 // 在ACK模式下发送失败和接收失败要清空发送缓冲区和接收缓冲区否则不能进行下次发射或接收
ClearFIFO(true); ClearFIFO(true);
//ClearFIFO(false); ClearFIFO(false);
// 清除中断标志 // 清除中断标志
ClearStatus(true, true); ClearStatus(true, true);
@ -525,7 +517,7 @@ bool NRF24L01::Config()
return true; return true;
} }
bool NRF24L01::CheckConfig() /*bool NRF24L01::CheckConfig()
{ {
for(int i=0; i<0x20; i++) for(int i=0; i<0x20; i++)
{ {
@ -534,7 +526,7 @@ bool NRF24L01::CheckConfig()
} }
return true; return true;
} }*/
void NRF24L01::ClearFIFO(bool rx) void NRF24L01::ClearFIFO(bool rx)
{ {
@ -995,28 +987,12 @@ bool NRF24L01::OnWrite(const byte* data, uint len)
return rs; return rs;
} }
bool NRF24L01::WaitForIRQ()
{
TimeWheel tw(0, Timeout);
while(_IRQ.Read())
{
if(tw.Expired()) return true;
}
// 读取状态寄存器的值
Status = ReadReg(STATUS);
if(Status == 0xFF) return false;
debug_printf("NRF24L01::WaitForIRQ Timeout %dms\r\n", Timeout);
return false;
}
void NRF24L01::AddError() void NRF24L01::AddError()
{ {
Error++; Error++;
if(MaxError > 0 && Error >= MaxError) if(MaxError > 0 && Error >= MaxError)
{ {
debug_printf("nRF24L01+出错%d次超过最大次数%d准备重启模块\r\n", Error, MaxError); debug_printf("RF24::Error 出错%d次超过最大次数%d准备重启模块\r\n", Error, MaxError);
Close(); Close();
Open(); Open();
@ -1032,7 +1008,7 @@ void NRF24L01::OnIRQ(Pin pin, bool down, void* param)
if(!nrf) return; if(!nrf) return;
// 马上调度任务 // 马上调度任务
if(nrf->_tidRecv) Sys.SetTask(nrf->_tidRecv, true, 0); Sys.SetTask(nrf->_tidRecv, true, 0);
} }
void NRF24L01::OnIRQ() void NRF24L01::OnIRQ()
@ -1136,17 +1112,6 @@ void NRF24L01::ShowStatus()
debug_printf("\r\n"); debug_printf("\r\n");
} }
bool NRF24L01::CanReceive()
{
// 读取状态寄存器的值
Status = ReadReg(STATUS);
if(Status == 0xFF) return false;
RF_STATUS st;
st.Init(Status);
return st.RX_DR;
}
void NRF24L01::ReceiveTask(void* param) void NRF24L01::ReceiveTask(void* param)
{ {
assert_ptr(param); assert_ptr(param);

View File

@ -16,7 +16,6 @@ private:
byte ReadReg(byte reg); byte ReadReg(byte reg);
byte WriteReg(byte reg, byte dat); byte WriteReg(byte reg, byte dat);
bool WaitForIRQ();
void AddError(); void AddError();
// 接收任务。 // 接收任务。
@ -28,8 +27,6 @@ private:
int _Lock; // 收发数据锁,确保同时只有一个对象使用 int _Lock; // 收发数据锁,确保同时只有一个对象使用
void Init();
public: public:
Spi* _spi; Spi* _spi;
OutputPort _CE; OutputPort _CE;
@ -54,7 +51,6 @@ public:
ushort Error; // 错误次数,超过最大错误次数则自动重置 ushort Error; // 错误次数,超过最大错误次数则自动重置
NRF24L01(); NRF24L01();
//NRF24L01(Spi* spi, Pin ce = P0, Pin irq = P0, Pin power = P0);
virtual ~NRF24L01(); virtual ~NRF24L01();
void Init(Spi* spi, Pin ce = P0, Pin irq = P0, Pin power = P0); void Init(Spi* spi, Pin ce = P0, Pin irq = P0, Pin power = P0);
@ -65,7 +61,7 @@ public:
bool GetMode(); // 获取当前模式是否接收模式 bool GetMode(); // 获取当前模式是否接收模式
bool SetMode(bool isReceive); // 切换收发模式,不包含参数设定 bool SetMode(bool isReceive); // 切换收发模式,不包含参数设定
void SetAddress(bool full); // 设置地址。参数指定是否设置0通道地址以外的完整地址 void SetAddress(bool full); // 设置地址。参数指定是否设置0通道地址以外的完整地址
bool CheckConfig(); //bool CheckConfig();
void ClearFIFO(bool rx); void ClearFIFO(bool rx);
void ClearStatus(bool tx, bool rx); void ClearStatus(bool tx, bool rx);
@ -75,7 +71,6 @@ public:
byte Status; byte Status;
byte FifoStatus; byte FifoStatus;
void ShowStatus(); void ShowStatus();
bool CanReceive();
virtual string ToString() { return "R24"; } virtual string ToString() { return "R24"; }