SmartOS/Drivers/Enc28j60.h

73 lines
1.8 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef __Enc28j60_H__
#define __Enc28j60_H__
#include "Kernel\Sys.h"
#include "Device\Spi.h"
#include "Device\Power.h"
#include "Net\ITransport.h"
#include "Net\Socket.h"
// Enc28j60类
class Enc28j60 : public ITransport
{
private:
Spi* _spi;
OutputPort _ce;
OutputPort _reset;
uint NextPacketPtr;
UInt64 LastTime; // 记录最后一次收到数据的时间,超时重启
uint ResetPeriod; // 重启间隔默认6000微秒
uint _ResetTask; // 重启任务
public:
//byte Mac[6];
MacAddress Mac;
byte Bank;
Enc28j60();
virtual ~Enc28j60();
void Init(Spi* spi, Pin ce = P0, Pin reset = P0);
byte ReadOp(byte op, byte addr);
void WriteOp(byte op, byte addr, byte data);
void ReadBuffer(byte* buf, uint len);
void WriteBuffer(const byte* buf, uint len);
// 设定寄存器地址区域
void SetBank(byte addr);
// 读取寄存器值 发送读寄存器命令和地址
byte ReadReg(byte addr);
// 写寄存器值 发送写寄存器命令和地址
void WriteReg(byte addr, byte data);
ushort PhyRead(byte addr);
bool PhyWrite(byte addr, ushort data);
void ClockOut(byte clock);
bool Linked();
// 电源等级变更(如进入低功耗模式)时调用
virtual void ChangePower(int level);
//void Init(byte mac[6]);
byte GetRevision();
bool Broadcast;
// 设置是否接收广播数据包
void SetBroadcast(bool flag);
// 显示寄存器状态
void ShowStatus();
int Error; // 错误次数
void CheckError();
//virtual const String ToString() const { return String("Enc28j60"); }
protected:
virtual bool OnOpen();
virtual void OnClose() { }
virtual bool OnWrite(const Buffer& bs);
virtual uint OnRead(Buffer& bs);
};
#endif