哪位名医的著作失传朋友用过enc424j600spi...

比特客户端
您的位置:
详解大数据
详解大数据
详解大数据
详解大数据
Microchip ENC424J600快速以太网控制方案
关键字:Microchip ENC424J600 案例 以太网
  Microchip 公司的ENC424J600和ENC624J600是单独可用的快速以太网控制器,具有工业标准的串行接口(SPI)或灵活的并行接口,主要用于以太. ENC424J600/624J600满足所有用于10Base-T 和100Base-TX以太网的IEEE 802.3规范, 引擎具有RSA, Diffie-Hellman, AES, MD5 和SHA-1算法,数据速率从14Mbps(SPI)到160 Mbps (分类, 16位并行接口).本文介绍了ENC424J600/624J600的主要特性和方框图, 典型以太网变压器连接图和以太网演示板电路图.
  The ENC424J600 and ENC624J600 are stand-alone, Fast Ethernet controllers with an industry standard Serial Peripheral Interface (SPI) or a flexible parallel interface. They are designed to serve as an Ethernet network interface for any microcontroller equipped with SPI or a standard parallel port.
  ENC424J600/624J600 devices meet all of the IEEE 802.3 specifications applicable to 10Base-T and 100Base-TX Ethernet, including many optional clauses, such as auto-negotiation. They incorporate a number of packet filtering schemes to limit incoming packets. They also provide an internal, 16-bit wide DMA for fast data throughput and support for hardware IP checksum calculations.
  For applications that require the security and authentication features of, TLS and other protocols related to cryptography, a block of security engines is provided.
  The engines perform RSA, Diffie-Hellman, AES, MD5 and SHA-1 algorithm computations, allowing reduced code size, faster connection establishment and throughput, and reduced firmware development effort.
  Communication with the microcontroller is implemented via the SPI or parallel interface, with data rates ranging from 14 Mbit/s (SPI) to 160 Mbit/s (demultiplexed, 16-bit parallel interface). Dedicated pins are used for link and activity indication and for transmit/receive/DMA interrupts.
  A generous 24-Kbyte on-chip RAM buffer is available for TX and RX operations. It may also be used by the host microcontroller for general purpose storage.
  Communication protocols, such as TCP, can use this memory for saving data which may need to be retransmitted.
  For easy end product manufacturability, each ENC624J600 family device is preprogrammed with a unique nonvolatile. In most cases, this allows the end device to avoid a serialized programming step.
  The only functional difference between the ENC424J600 (44-pin) and ENC624J600 (64-pin) devices are the number of parallel interface options they support.
  图1.ENC424J600/624J600 方框图
  图2.ENC424J600典型以太网变压器连接图
  以太网演示板
  Fast 100Mbps Ethernet PICtail Plus Daughter Board Part Number: AC164132 The Fast 100 Mbps Ethernet PICtail™ Plus Daughter Board (AC164132) is an Ethernet demonstration board for evaluating Microchip Technology’s ENC424J600 and ENC624J600 stand-alone 10/100 Ethernet controllers. It is an expansion board compatible with many PICtail and PICtail Plus host boards, including the Explorer 16, PIC32 I/O Expansion Board, PICDEM.net™ 2 and PIC18 Explorer development boards.
  以太网演示板主要特性:
  • ENC624J600 10/100 Ethernet Controller with factory preprogrammed MAC address (see “ENC424J600/624J600 Data Sheet” (DS39935) for additional information)
  • 25 MHz oscillator and integrated magnetic RJ-45 connector
  • PICtail Plus Daughter Board edge contacts for SPI or PSP connection to Explorer 16 and PIC32 I/O Expansion Boards
  • PICtail Daughter Board headers for SPI connection to PICDEM.net 2 and PIC18 Explorer Boards
  • Configuration jumpers for PSP Modes 1, 2, 3, 4, 5, 6, 9 and 10 under PMP control with automatic pinout remapping
  • Current monitoring jumper
  • Ethernet crossover switches
  &#V LDO regulator with shutdown for very low Sleep current
  &#V to 5V SPI level translation for the PIC18 Explorer
  • SSL encryption add-on software CD for the Microchip Stack
  图3.以太网演示板外形图
  图4.以太网演示板电路图(1)
  图5.以太网演示板电路图(2)
[ 责任编辑:徐银泽 ]
新经济、新业态环境下,数据量呈…
甲骨文的云战略已经完成第一阶段…
软件信息化周刊
比特软件信息化周刊提供以数据库、操作系统和管理软件为重点的全面软件信息化产业热点、应用方案推荐、实用技巧分享等。以最新的软件资讯,最新的软件技巧,最新的软件与服务业内动态来为IT用户找到软捷径。
商务办公周刊
比特商务周刊是一个及行业资讯、深度分析、企业导购等为一体的综合性周刊。其中,与中国计量科学研究院合力打造的比特实验室可以为商业用户提供最权威的采购指南。是企业用户不可缺少的智选周刊!
比特网络周刊向企业网管员以及网络技术和产品使用者提供关于网络产业动态、技术热点、组网、建网、网络管理、网络运维等最新技术和实用技巧,帮助网管答疑解惑,成为网管好帮手。
服务器周刊
比特服务器周刊作为比特网的重点频道之一,主要关注x86服务器,RISC架构服务器以及高性能计算机行业的产品及发展动态。通过最独到的编辑观点和业界动态分析,让您第一时间了解服务器行业的趋势。
比特存储周刊长期以来,为读者提供企业存储领域高质量的原创内容,及时、全面的资讯、技术、方案以及案例文章,力求成为业界领先的存储媒体。比特存储周刊始终致力于用户的企业信息化建设、存储业务、数据保护与容灾构建以及数据管理部署等方面服务。
比特安全周刊通过专业的信息安全内容建设,为企业级用户打造最具商业价值的信息沟通平台,并为安全厂商提供多层面、多维度的媒体宣传手段。与其他同类网站信息安全内容相比,比特安全周刊运作模式更加独立,对信息安全界的动态新闻更新更快。
新闻中心热点推荐
新闻中心以独特视角精选一周内最具影响力的行业重大事件或圈内精彩故事,为企业级用户打造重点突出,可读性强,商业价值高的信息共享平台;同时为互联网、IT业界及通信厂商提供一条精准快捷,渗透力强,覆盖面广的媒体传播途径。
云计算周刊
比特云计算周刊关注云计算产业热点技术应用与趋势发展,全方位报道云计算领域最新动态。为用户与企业架设起沟通交流平台。包括IaaS、PaaS、SaaS各种不同的服务类型以及相关的安全与管理内容介绍。
CIO俱乐部周刊
比特CIO俱乐部周刊以大量高端CIO沙龙或专题研讨会以及对明星CIO的深入采访为依托,汇聚中国500强CIO的集体智慧。旨为中国杰出的CIO提供一个良好的互融互通 、促进交流的平台,并持续提供丰富的资讯和服务,探讨信息化建设,推动中国信息化发展引领CIO未来职业发展。
IT专家新闻邮件长期以来,以定向、分众、整合的商业模式,为企业IT专业人士以及IT系统采购决策者提供高质量的原创内容,包括IT新闻、评论、专家答疑、技巧和白皮书。此外,IT专家网还为读者提供包括咨询、社区、论坛、线下会议、读者沙龙等多种服务。
X周刊是一份IT人的技术娱乐周刊,给用户实时传递I最新T资讯、IT段子、技术技巧、畅销书籍,同时用户还能参与我们推荐的互动游戏,给广大的IT技术人士忙碌工作之余带来轻松休闲一刻。
微信扫一扫
关注Chinabyte21ic官方微信
您现在的位置是:&>&&>&
基于ENC424J600的以太网与串行接口转换技术
摘要:论述了在STM32系列的MCU上移植TCP/IP协议栈LwIP,并利用新型以太网控制器ENC24J600实现网络数据传输功能。该系统主要完成的功能是接收上位机发送的数据,并将这些数据转换成通用串行接口输出。ENC424J600是Microchip新推出的一款以太网控制器,其速度优于ENC28J60,同时为用户提供两种接口模式。本文介绍了其基于SPI接口模式下的实现过程,详细描述了该网卡驱动的硬件电路和软件流程。
关键词:以太网控制器;STM32;LwIP串口输出
&&& 随着Internet的发展和应用,越来越多的设备需要接入网络以实现远程控制或资源共享。以太网接口布线方便,通信带宽较宽,可达100 Mb/s甚至1000Mb/s。嵌入式系统由于具有体积小、价格低、专用性能高的优势,被广泛应用于各种电子设备和工业测试设备中。随着嵌入式系统与网络的日益紧密结合,在嵌入式系统中引入TCP/IP协议栈已成为嵌入式系统领域的重要研究方向。
&&& 本义在以太网接口实现基本数据传输的基础上将其转换成其他通用串行接口(如SPI、UART、CAN),更利于应用在广泛的工业控制领域中。目前市面上的以太网控制芯片大多功耗高、功能复杂,不适合用在中低端的嵌入式系统中。之前Microchip推出的芯片ENC28J60的网络接口速度只能达到10 Mbps,其SRAM buffer也不大容易造成接收溢出,而ENC424J600速度可达100 Mbps,功能将更加完善,并提供两种接口给嵌入式开发者选择,是一款很好的网络接口芯片。STM32F103RET6是一款ARM处理器,它的功耗低、价格低廉、功能强大、具备丰富的串行接口,具有512 KB的Flash,在一般的应用中可以不用外扩Flash,是中低端嵌入式开发系统的最佳选择之一。将两者结合不但能实现网络通信,而且可以灵活转换成其他串行接口,用途广泛。
1 ENC424J600简介
&&& ENC424J600是Microchip公司推出的单独可用的快速以太网控制器。其与MCU的连接方式可采用具有工业标准的串行总线SPI或灵活的并行接口。SPI接口数据速率可达14 Mb/s、并行接口速率可达140 Mb/s。ENC424J600满足10 basc-TX全双工、半双工模式、100base-TX全双工、半双工模式,4种模式均符合IEEE802.3协议。芯片内置PHY物理层及MAC媒体访问控制层。引擎具有RSA、DiffieHelman、AES、MD5、和SHA-1算法。芯片具有44引脚TQFP和QFN两种封装形式。该芯片另一个突出特点是具有24 KB的SRAM Buffer,基本不需要外接SRAM。芯片SRAM Buffer的分配如图1所示。
&&&& SRAM Buffer被分为两个区域,一般将General Purpose Buffer设为发送区,RX FIFO Burfer设为接收区,通过指针ERXST区分两个区域,通常将接收区设置较大以防止接收帧溢出。
该电路可产生用于连续数字电路的时钟信号中的方波,限流电阻器的值决定了在大约150ns-……
本电路具有良好的线性和精度,输出为每秒1000个脉冲时,误差只有1%。如果每秒10个脉……
如下图所示的电路是另一种简化的设计(原始的设计包括QRP发射机和DCR)。前端电路包括一……The following variables must be defined in all projects using SPI Ethernet ENC24J600 Library:
Description:
Examples :
dim SPI_Ethernet_24j600_CS as sbit sfr atomic external
ENC24J600 chip select pin.
dim SPI_Ethernet_24j600_CS as sbit at RC1_bit
dim SPI_Ethernet_24j600_CS_Direction as sbit sfr atomic external
Direction of the ENC24J600 chip select pin.
dim SPI_Ethernet_24j600_CS_Direction as sbit at TRISC1_bit
The following routines must be defined in all project using SPI Ethernet ENC24J600 Library:
Description:
Examples :
sub function SPI_Ethernet_24j600_UserTCP(dim byref remoteHost as byte[4],
dim remotePort as word,
dim localPort as word,
dim reqLength as word,
dim byref flags as TEthj600PktFlags) as word
TCP request handler.
Refer to the library example at the bottom of this page
for code implementation.
sub function SPI_Ethernet_24j600_UserUDP(dim byref remoteHost as byte[4],
dim remotePort as word,
dim destPort as word,
dim reqLength as word,
dim byref flags as TEthJ600PktFlags) as word
UDP request handler.
Refer to the library example at the bottom of this page
for code implementation.
Library Routines
SPI_Ethernet_24j600_Init
sub procedure SPI_Ethernet_24j600_Init(dim mac as ^byte, dim ip as ^byte, dim fullDuplex as byte)
Description
This is MAC module routine. It initializes ENC24J600 controller. This function is internaly splited into 2 parts to help linker when coming short of memory.
ENC24J600 controller settings (parameters not mentioned here are set to default):
receive buffer start address : 0x0000.
receive buffer end address
transmit buffer start address: 0x19AE.
transmit buffer end address
RAM buffer read/write pointers in auto-increment mode.
receive filters set to default: CRC + MAC Unicast + MAC Broadcast in OR mode.
flow control with TX and RX pause frames in full duplex mode.
frames are padded to 60 bytes + CRC.
maximum packet size is set to 1518.
Back-to-Back Inter-Packet Gap: 0x15 0x12 in half duplex mode.
Non-Back-to-Back Inter-Packet Gap: 0x0012 0x0C12 in half duplex mode.
Collision window is set to 63 in half duplex mode to accomodate some ENC24J600 revisions silicon bugs.
CLKOUT output is disabled to reduce EMI generation.
half duplex loopback disabled.
LED configuration: default (LEDA-link status, LEDB-link activity).
Parameters
mac: RAM buffer containing valid MAC address.
ip: RAM buffer containing valid IP address.
configuration: ethernet negotiation, duplex and speed mode settings. For this purpose, predefined library constants (see the list below) can be combined using logical AND to form appropriate value :
Description
Predefined library const
Set Auto-negotiation
SPI_Ethernet_24j600_AUTO_NEGOTIATION
Set manual negotiation.
SPI_Ethernet_24j600_MANUAL_NEGOTIATION
Set Half duplex Mode
SPI_Ethernet_24j600_HALFDUPLEX
Set Full duplex Mode
SPI_Ethernet_24j600_FULLDUPLEX
Set transmission speed of 10Mbps
SPI_Ethernet_24j600_SPD10
Set transmission speed of 100Mbps
SPI_Ethernet_24j600_SPD100
It is advisable to use only the Auto-negotiation setting. If manual negotiation is used, then duplex and speed mode setting must be set also.
Duplex and speed mode may be set only when using manual negotiation.
Global variables :
SPI_Ethernet_24j600_CS: Chip Select line
SPI_Ethernet_24j600_CS_Direction: Direction of the Chip Select pin
SPI_Ethernet_24j600_RST: Reset line
SPI_Ethernet_24j600_RST_Direction: Direction of the Reset pin
must be defined before using this function.
The SPI module needs to be initialized. See the
' mE ehternet NIC pinout
dim SPI_Ethernet_24j600_CS as sbit at LATF1_bit
dim SPI_Ethernet_24j600_CS_Direction as sbit at TRISF1_bit
' end mE ehternet NIC pinout
myMacAddr as byte[6] ' my MAC address
as byte[4] ' my IP addr
myMacAddr[0] = 0x00
myMacAddr[1] = 0x14
myMacAddr[2] = 0xA5
myMacAddr[3] = 0x76
myMacAddr[4] = 0x19
myMacAddr[5] = 0x3F
myIpAddr[0]
myIpAddr[1]
myIpAddr[2]
myIpAddr[3]
SPI1_Init()
SPI_Ethernet_24j600_Init(myMacAddr, myIpAddr, SPI_Ethernet_24j600_MANUAL_NEGOTIATION and SPI_Ethernet_24j600_FULLDUPLEX and SPI_Ethernet_24j600_SPD100)
SPI_Ethernet_24j600_Enable
sub procedure SPI_Ethernet_24j600_Enable(dim enFlt as word)
Description
This is MAC module routine. This routine enables appropriate network traffic on the ENC24J600 module
by the means of it's receive filters (unicast, multicast, broadcast, crc). Specific type of network traffic will be enabled if a corresponding bit of this routine's input parameter is set.
Therefore, more than one type of network traffic can be enabled at the same time.
For this purpose, predefined library constants (see the table below) can be ORed to form appropriate input value.
Advanced filtering available in the ENC24J600 module such as Pattern Match, Magic Packet and Hash Table can not be enabled by this routine. Additionaly, all filters, except CRC, enabled with this routine will work in OR mode, which means that packet will be received if any of the enabled filters accepts it.
This routine will change receive filter configuration on-the-fly. It will not, in any way, mess with enabling/disabling receive/transmit logic or any other part of the ENC24J600 module. The ENC24J600 module should be properly cofigured by the means of
Parameters
enFlt: network traffic/receive filter flags. Each bit corresponds to the appropriate network traffic/receive filter:
Description
Predefined library const
MAC Broadcast traffic/receive filter flag. When set, MAC broadcast traffic will be enabled.
_SPI_Ethernet_24j600_BROADCAST
MAC Multicast traffic/receive filter flag. When set, MAC multicast traffic will be enabled.
_SPI_Ethernet_24j600_MULTICAST
CRC check flag. When set, packets with invalid CRC field will be discarded.
_SPI_Ethernet_24j600_CRC
MAC Unicast traffic/receive filter flag. When set, MAC unicast traffic will be enabled.
_SPI_Ethernet_24j600_UNICAST
Ethernet module has to be initialized. See .
SPI_Ethernet_24j600_Enable(_SPI_Ethernet_24j600_CRC or _SPI_Ethernet_24j600_UNICAST) ' enable CRC checking and Unicast traffic
Advanced filtering available in the ENC24J600 module such as Pattern Match, Magic Packet and Hash Table can not be enabled by this routine. Additionaly, all filters, except CRC, enabled with this routine will work in OR mode, which means that packet will be received if any of the enabled filters accepts it.
This routine will change receive filter configuration on-the-fly. It will not, in any way, mess with enabling/disabling receive/transmit logic or any other part of the ENC24J600 module. The ENC24J600 module should be properly cofigured by the means of
SPI_Ethernet_24j600_Disable
sub procedure SPI_Ethernet_24j600_Disable(dim disFlt as word)
Description
This is MAC module routine. This routine disables appropriate network traffic on the ENC24J600 module
by the means of it's receive filters (unicast, multicast, broadcast, crc). Specific type of network traffic will be disabled if a corresponding bit of this routine's input parameter is set.
Therefore, more than one type of network traffic can be disabled at the same time.
For this purpose, predefined library constants (see the table below) can be ORed to form appropriate input value.
Parameters
disFlt: network traffic/receive filter flags. Each bit corresponds to the appropriate network traffic/receive filter:
Description
Predefined library const
MAC Broadcast traffic/receive filter flag. When set, MAC broadcast traffic will be disabled.
_SPI_Ethernet_24j600_BROADCAST
MAC Multicast traffic/receive filter flag. When set, MAC multicast traffic will be disabled.
_SPI_Ethernet_24j600_MULTICAST
CRC check flag. When set, CRC check will be disabled and packets with invalid CRC field will be accepted.
_SPI_Ethernet_24j600_CRC
MAC Unicast traffic/receive filter flag. When set, MAC unicast traffic will be disabled.
_SPI_Ethernet_24j600_UNICAST
Ethernet module has to be initialized. See .
SPI_Ethernet_24j600_Disable(_SPI_Ethernet_24j600_CRC or _SPI_Ethernet_24j600_UNICAST) ' disable CRC checking and Unicast traffic
Advanced filtering available in the ENC24J600 module such as Pattern Match, Magic Packet and Hash Table can not be disabled by this routine.
This routine will change receive filter configuration on-the-fly. It will not, in any way, mess with enabling/disabling receive/transmit logic or any other part of the ENC24J600 module. The ENC24J600 module should be properly cofigured by the means of
The ENC24J600 module should be properly cofigured by the means of
SPI_Ethernet_24j600_doPacket
sub function SPI_Ethernet_24j600_doPacket() as byte
Description
This is MAC module routine. It processes next received packet if such exists. Packets are processed in the following manner:
ARP & ICMP requests are replied automatically.
upon TCP request the
function is called for further processing.
upon UDP request the
function is called for further processing.
Parameters
0 - upon successful packet processing (zero packets received or received packet processed successfully).
1 - upon reception error or receive buffer corruption. ENC24J600 controller needs to be restarted.
2 - received packet was not sent to us (not our IP, nor IP broadcast address).
3 - received IP packet was not IPv4.
4 - received packet was of type unknown to the library.
Ethernet module has to be initialized. See .
while TRUE
SPI_Ethernet_24j600_doPacket() ' process received packets
SPI_Ethernet_24j600_doPacket must be called as often as possible in user's code.
SPI_Ethernet_24j600_putByte
sub procedure SPI_Ethernet_24j600_putByte(dim v as byte)
Description
This is MAC module routine. It stores one byte to address pointed by the current ENC24J600 write pointer (EWRPT).
Parameters
v: value to store
Ethernet module has to be initialized. See .
dim data as byte
SPI_Ethernet_24j600_putByte(data) ' put an byte into ENC24J600 buffer
SPI_Ethernet_24j600_putBytes
sub procedure SPI_Ethernet_24j600_putBytes(dim ptr as ^byte, dim n as word)
Description
This is MAC module routine. It stores requested number of bytes into ENC24J600 RAM starting from current ENC24J600 write pointer (EWRPT) location.
Parameters
ptr: RAM buffer containing bytes to be written into ENC24J600 RAM.
n: number of bytes to be written.
Ethernet module has to be initialized. See .
buffer as byte[17]
buffer = "mikroElektronika"
SPI_Ethernet_24j600_putBytes(buffer, 16) ' put an RAM array into ENC24J600 buffer
SPI_Ethernet_24j600_putConstBytes
sub procedure SPI_Ethernet_24j600_putConstBytes(const ptr as ^byte, dim n as word)
Description
This is MAC module routine. It stores requested number of const bytes into ENC24J600 RAM starting from current ENC24J600 write pointer (EWRPT) location.
Parameters
ptr: const buffer containing bytes to be written into ENC24J600 RAM.
n: number of bytes to be written.
Ethernet module has to be initialized. See .
buffer as byte[17]
buffer = "mikroElektronika"
SPI_Ethernet_24j600_putConstBytes(buffer, 16) ' put a const array into ENC24J600 buffer
SPI_Ethernet_24j600_putString
sub function SPI_Ethernet_24j600_putString(dim ptr as ^byte) as word
Description
This is MAC module routine. It stores whole string (excluding null termination) into ENC24J600 RAM starting from current ENC24J600 write pointer (EWRPT) location.
Parameters
ptr: string to be written into ENC24J600 RAM.
Number of bytes written into ENC24J600 RAM.
Ethernet module has to be initialized. See .
buffer as string[16]
buffer = "mikroElektronika"
SPI_Ethernet_24j600_putString(buffer) ' put a RAM string into ENC24J600 buffer
SPI_Ethernet_24j600_putConstString
sub function SPI_Ethernet_24j600_putConstString(const ptr as ^byte) as word
Description
This is MAC module routine. It stores whole const string (excluding null termination) into ENC24J600 RAM starting from current ENC24J600 write pointer (EWRPT) location.
Parameters
ptr: const string to be written into ENC24J600 RAM.
Number of bytes written into ENC24J600 RAM.
Ethernet module has to be initialized. See .
buffer as string[16]
buffer = "mikroElektronika"
SPI_Ethernet_24j600_putConstString(buffer) ' put a const string into ENC24J600 buffer
SPI_Ethernet_24j600_getByte
sub function SPI_Ethernet_24j600_getByte() as byte
Description
This is MAC module routine. It fetches a byte from address pointed to by current ENC24J600 read pointer (ERDPT).
Parameters
Byte read from ENC24J600 RAM.
Ethernet module has to be initialized. See .
dim buffer as byte<>
buffer = SPI_Ethernet_24j600_getByte() ' read a byte from ENC24J600 buffer
SPI_Ethernet_24j600_getBytes
sub procedure SPI_Ethernet_24j600_getBytes(dim ptr as ^byte, dim addr as word, dim n as word)
Description
This is MAC module routine. It fetches equested number of bytes from ENC24J600 RAM starting from given address. If value of 0xFFFF is passed as the address parameter, the reading will start from current ENC24J600 read pointer (ERDPT) location.
Parameters
ptr: buffer for storing bytes read from ENC24J600 RAM.
addr: ENC24J600 RAM start address. Valid values: 0..8192.
n: number of bytes to be read.
Ethernet module has to be initialized. See .
buffer as byte[16]
SPI_Ethernet_24j600_getBytes(buffer, 0x100, 16) ' read 16 bytes, starting from address 0x100
SPI_Ethernet_24j600_UserTCP
sub function SPI_Ethernet_24j600_UserTCP(dim byref remoteHost as byte[4], dim remotePort as word, dim localPort as word, dim reqLength as word, dim byref flags as TEthJ600PktFlags) as word
Description
This is TCP module routine. It is internally called by the library. The user accesses to the TCP request by using some of the
SPI_Ethernet_24j600_get routines. The user puts data in the transmit buffer by using some of the SPI_Ethernet_24j600_put routines.
The function must return the length in bytes of the TCP reply, or 0 if there is nothing to transmit.
If there is no need to reply to the TCP requests, just define this function with return(0) as a single
statement.
Parameters
remoteHost: client's IP address.
remotePort: client's TCP port.
localPort: port to which the request is sent.
reqLength: TCP request data field length.
flags: structure consisted of two fields :
structure TEthj600PktFlags
dim canCloseTCP as boolean
' flag which closes socket
dim isBroadcast as boolean
' flag which denotes that the IP package has been received via subnet broadcast address
end structure
0 - there should not be a reply to the request.
Length of TCP reply data field - otherwise.
Ethernet module has to be initialized. See .
This function is internally called by the library and should not be called by the user's code.
The function source code is provided with appropriate example projects. The code should be adjusted by the user to achieve desired reply.
SPI_Ethernet_24j600_UserUDP
sub function SPI_Ethernet_24j600_UserUDP(dim byref remoteHost as byte[4], dim remotePort as word, dim destPort as word, dim reqLength as word, dim byref flags as TEthJ600PktFlags) as word
Description
This is UDP module routine. It is internally called by the library. The user accesses to the UDP request by using some of the
SPI_Ethernet_24j600_get routines. The user puts data in the transmit buffer by using some of the SPI_Ethernet_24j600_put routines.
The function must return the length in bytes of the UDP reply, or 0 if nothing to transmit.
If you don't need to reply to the UDP requests, just define this function with a return(0) as single
statement.
Parameters
remoteHost: client's IP address.
remotePort: client's port.
destPort: port to which the request is sent.
reqLength: UDP request data field length.
flags: structure consisted of two fields :
structure TEthj600PktFlags
dim canCloseTCP as boolean
' flag which closes socket (not relevant to UDP)
dim isBroadcast as boolean
' flag which denotes that the IP package has been received via subnet broadcast address
end structure
0 - there should not be a reply to the request.
Length of UDP reply data field - otherwise.
Ethernet module has to be initialized. See .
This function is internally called by the library and should not be called by the user's code.
The function source code is provided with appropriate example projects. The code should be adjusted by the user to achieve desired reply.
SPI_Ethernet_24j600_setUserHandlers
sub procedure SPI_Ethernet_24j600_setUserHandlers(dim TCPHandler as ^TSPI_Ethernet_24j600_UserTCP, dim UDPHandler as ^TSPI_Ethernet_24j600_UserUDP)
Description
Sets pointers to User TCP and UDP handler function implementations, which are automatically called by SPI Ethernet ENC24J600 library.
Parameters
TCPHandler: TCP request handler
UDPHandler: UDP request handler.
have to be previously defined.
SPI_Ethernet_24j600_setUserHandlers(@SPI_Ethernet_24j600_UserTCP, @SPI_Ethernet_24j600_UserUDP)
Since all libraries are built for SSA,
regarding function pointers dictate that modules that use SPI_Ethernet_24j600_setUserHandlers must also be built for SSA.
SPI_Ethernet_24j600_getIpAddress
sub function SPI_Ethernet_24j600_getIpAddress() as word
Description
This routine should be used when DHCP server is present on the network to fetch assigned IP address.
Parameters
Pointer to the global variable holding IP address.
Ethernet module has to be initialized. See .
ipAddr as byte[4]
' user IP address buffer
memcpy(ipAddr, SPI_Ethernet_24j600_getIpAddress(), 4)
' fetch IP address
User should always copy the IP address from the RAM location returned by this routine into it's own IP address buffer. These locations should not be altered by the user in any case!
SPI_Ethernet_24j600_getGwIpAddress
sub function SPI_Ethernet_24j600_getGwIpAddress() as word
Description
This routine should be used when DHCP server is present on the network to fetch assigned gateway IP address.
Parameters
Pointer to the global variable holding gateway IP address.
Ethernet module has to be initialized. See .
gwIpAddr as byte[4]
' user gateway IP address buffer
memcpy(gwIpAddr, SPI_Ethernet_24j600_getGwIpAddress(), 4)
' fetch gateway IP address
User should always copy the IP address from the RAM location returned by this routine into it's own gateway IP address buffer. These locations should not be altered by the user in any case!
SPI_Ethernet_24j600_getDnsIpAddress
sub function SPI_Ethernet_24j600_getDnsIpAddress() as word
Description
This routine should be used when DHCP server is present on the network to fetch assigned DNS IP address.
Parameters
Pointer to the global variable holding DNS IP address.
Ethernet module has to be initialized. See .
dnsIpAddr as byte[4]
' user DNS IP address buffer
memcpy(dnsIpAddr, SPI_Ethernet_24j600_getDnsIpAddress(), 4)
' fetch DNS server address
User should always copy the IP address from the RAM location returned by this routine into it's own DNS IP address buffer. These locations should not be altered by the user in any case!
SPI_Ethernet_24j600_getIpMask
sub function SPI_Ethernet_24j600_getIpMask() as word
Description
This routine should be used when DHCP server is present on the network to fetch assigned IP subnet mask.
Parameters
Pointer to the global variable holding IP subnet mask.
Ethernet module has to be initialized. See .
Available for PIC18 family MCUs only.
IpMask as byte[4]
' user IP subnet mask buffer
memcpy(IpMask, SPI_Ethernet_24j600_getIpMask(), 4)
' fetch IP subnet mask
User should always copy the IP address from the RAM location returned by this routine into it's own IP subnet mask buffer. These locations should not be altered by the user in any case!
SPI_Ethernet_24j600_confNetwork
sub procedure SPI_Ethernet_24j600_confNetwork(dim byref ipMask, gwIpAddr, dnsIpAddr as byte[4])
Description
Configures network parameters (IP subnet mask, gateway IP address, DNS IP address) when DHCP is not used.
Parameters
IP subnet mask.
gwIpAddr gateway IP address.
dnsIpAddr: DNS IP address.
Ethernet module has to be initialized. See .
as byte[4]
' network mask (for example : 255.255.255.0)
as byte[4]
' gateway (router) IP address
dnsIpAddr as byte[4]
' DNS server IP address
gwIpAddr[0]
gwIpAddr[1]
gwIpAddr[2]
gwIpAddr[3]
dnsIpAddr[0] = 192
dnsIpAddr[1] = 168
dnsIpAddr[2] = 20
dnsIpAddr[3] = 100
SPI_Ethernet_24j600_confNetwork(ipMask, gwIpAddr, dnsIpAddr) ' set network configuration parameters
The above mentioned network parameters should be set by this routine only if DHCP module is not used. Otherwise DHCP will override these settings.
SPI_Ethernet_24j600_arpResolve
sub function SPI_Ethernet_24j600_arpResolve(dim byref ip as byte[4], dim tmax as byte) as word
Description
This is ARP module routine. It sends an ARP request for given IP address and waits for ARP reply.
If the requested IP address was resolved, an ARP cash entry is used for storing the configuration.
ARP cash can store up to 3 entries.
Parameters
IP address to be resolved.
tmax: time in seconds to wait for an reply.
MAC address behind the IP address - the requested IP address was resolved.
0 - otherwise.
Ethernet module has to be initialized. See .
IpAddr as byte[4]
' IP address
IpAddr[0] = 192
IpAddr[0] = 168
IpAddr[0] = 1
IpAddr[0] = 1
SPI_Ethernet_24j600_arpResolve(IpAddr, 5) ' get MAC address behind the above IP address, wait 5 secs for the response
The Ethernet services are not stopped while this routine waits for ARP reply. The incoming packets will be processed normaly during this time.
SPI_Ethernet_24j600_sendUDP
sub function SPI_Ethernet_24j600_sendUDP(dim byref destIP as byte[4], dim sourcePort, destPort as word, dim pkt as ^byte, dim pktLen as word) as byte
Description
This is UDP module routine. It sends an UDP packet on the network.
Parameters
remote host IP address.
sourcePort: local UDP source port number.
destination UDP port number.
pkt: packet to transmit.
pktLen: length in bytes of packet to transmit.
1 - UDP packet was sent successfully.
0 - otherwise.
Ethernet module has to be initialized. See .
IpAddr as byte[4]
' remote IP address
IpAddr[0] = 192
IpAddr[0] = 168
IpAddr[0] = 1
IpAddr[0] = 1
SPI_Ethernet_24j600_sendUDP(IpAddr, 1, "Hello", 5) ' send Hello message to the above IP address, from UDP port 10001 to UDP port 10001
SPI_Ethernet_24j600_dnsResolve
sub function SPI_Ethernet_24j600_dnsResolve(dim byref host as string, dim tmax as byte) as word
Description
This is DNS module routine. It sends an DNS request for given host name and waits for DNS reply.
If the requested host name was resolved, it's IP address is stored in library global variable
and a pointer containing this address is returned by the routine. UDP port 53 is used as DNS port.
Parameters
host: host name to be resolved.
tmax: time in seconds to wait for an reply.
pointer to the location holding the IP address - the requested host name was resolved.
0 - otherwise.
Ethernet module has to be initialized. See .
remoteHostIpAddr as string ' user host IP address buffer
' SNTP server:
' Zurich, Switzerland: Integrated Systems Lab, Swiss Fed. Inst. of Technology
' 129.132.2.21: swisstime.ethz.ch
' Service Area: Switzerland and Europe
memcpy(remoteHostIpAddr, SPI_Ethernet_24j600_dnsResolve("swisstime.ethz.ch", 5), 4)
The Ethernet services are not stopped while this routine waits for DNS reply. The incoming packets will be processed normaly during this time.
User should always copy the IP address from the RAM location returned by this routine into it's own resolved host IP address buffer. These locations should not be altered by the user in any case!
SPI_Ethernet_24j600_initDHCP
sub function SPI_Ethernet_24j600_initDHCP(dim tmax as byte) as byte
Description
This is DHCP module routine. It sends an DHCP
request for network parameters (IP, gateway, DNS addresses and IP subnet mask) and waits for DHCP reply.
If the requested parameters were obtained successfully, their values are stored into the library global variables.
These parameters can be fetched by using appropriate library IP get routines:
- fetch IP address.
- fetch gateway IP address.
- fetch DNS IP address.
- fetch IP subnet mask.
UDP port 68 is used as DHCP client port and UDP port 67 is used as DHCP server port.
Parameters
tmax: time in seconds to wait for an reply.
1 - network parameters were obtained successfully.
0 - otherwise.
Ethernet module has to be initialized. See .
SPI_Ethernet_24j600_initDHCP(5) ' get network configuration from DHCP server, wait 5 sec for the response
The Ethernet services are not stopped while this routine waits for DNS reply. The incoming packets will be processed normaly during this time.
When DHCP module is used, global library variable SPI_Ethernet_24j600_userTimerSec is used to keep track of time. It is user responsibility to increment this variable each second in it's code.
sub function SPI_Ethernet_24j600_doDHCPLeaseTime() as byte
Description
This is DHCP module routine. It takes care of IP address lease time by decrementing the global lease time library counter. When this time expires, it's time to contact DHCP server and renew the lease.
Parameters
0 - lease time has not expired yet.
1 - lease time has expired, it's time to renew it.
Ethernet module has to be initialized. See .
while true
if(SPI_Ethernet_24j600_doDHCPLeaseTime() &#60;&#62; 0) then
... ' it's time to renew the IP address lease
SPI_Ethernet_24j600_renewDHCP
sub function SPI_Ethernet_24j600_renewDHCP(dim tmax as byte) as byte
Description
This is DHCP module routine. It sends IP address lease time renewal request to DHCP server.
Parameters
tmax: time in seconds to wait for an reply.
1 - upon success (lease time was renewed).
0 - otherwise (renewal request timed out).
Ethernet module has to be initialized. See .
while true
if(SPI_Ethernet_24j600_doDHCPLeaseTime() &#60;&#62; 0) then
SPI_Ethernet_24j600_renewDHCP(5)
' it's time to renew the IP address lease, with 5 secs for a reply
Copyright (c)
mikroElektronika. All rights reserved.
What do you think about this topic ?
Want more examples and libraries?&
Find them on

我要回帖

更多关于 哪位名医的著作失传 的文章

 

随机推荐