enc28j60 library
1.0
platform agnostic enc28j60 driver with asynchronous IO support and fully compliant with errata
|
Part of enc28j60 driver. More...
Go to the source code of this file.
Classes | |
struct | enc28j60_header |
Structure that has to prefix any variable length data when not using advanced SPI driver (that is when ENC28J60_HAS_ADVANCED_DRIVER is not defined). More... | |
struct | enc28j60_ethernet_header |
Ethernet header. More... | |
struct | enc28j60_txstatus |
Structure that contains data parsed from status footer appended by enc28j60 after frame that was transmitted or which transmission was aborted. More... | |
struct | enc28j60_init_struct |
Structure used for initialization of the enc28j60. More... | |
Macros | |
#define | ENC28J60_MAX_FRAMELEN 1500 |
Max frame length which the conroller will accept. More... | |
#define | ENC28J60_MAX_FRAMELEN_ETH 1518 |
Maximum frame length including ethernet header and checksum. | |
#define | ENC28J60_MEMORY_SIZE 0x2000 |
Size of the enc28j60's memory. | |
Typedefs | |
typedef struct enc28j60_header | enc28j60_header |
Structure that has to prefix any variable length data when not using advanced SPI driver (that is when ENC28J60_HAS_ADVANCED_DRIVER is not defined). More... | |
typedef struct enc28j60_ethernet_header | enc28j60_ethernet_header |
Ethernet header. | |
typedef struct enc28j60_txstatus | enc28j60_txstatus |
Structure that contains data parsed from status footer appended by enc28j60 after frame that was transmitted or which transmission was aborted. | |
typedef void(* | enc28j60_spi_callback) (enc28j60 *instance, int custom_error_code) |
Callback used internally and externally. More... | |
typedef struct enc28j60_init_struct | enc28j60_init_struct |
Structure used for initialization of the enc28j60. | |
Functions | |
int | enc28j60_blockingio (enc28j60 *ins, const char *tx, char *rx, unsigned length) |
Performs IO on enc28j60. More... | |
int | enc28j60_ensurebank (enc28j60 *ins, uint8_t bank) |
Ensures that correct bank is currently selected. More... | |
int | enc28j60_io8 (enc28j60 *ins, uint8_t op, uint8_t reg, uint8_t val, uint8_t *out) |
Performs given IO operation on given 8-bit register until it succeeds or fails with unrepairable error. More... | |
int | enc28j60_io16 (enc28j60 *ins, uint8_t op, uint8_t reg, uint16_t val, uint16_t *out) |
Performs given IO operation on given register 16bit until it succeeds or fails with unrepairable error. More... | |
int | enc28j60_read8bitreg (enc28j60 *ins, uint8_t reg, uint8_t *content) |
Read value of given 8-bit register and store it in *content if not content is not null. More... | |
int | enc28j60_write8bitreg (enc28j60 *ins, uint8_t reg, uint8_t content) |
Write given value content into given 8-bit register. More... | |
int | enc28j60_clear8bitreg (enc28j60 *ins, uint8_t reg, uint8_t content) |
Clears bits given by content from given 8-bit register. More... | |
int | enc28j60_set8bitreg (enc28j60 *ins, uint8_t reg, uint8_t content) |
Sets bits given by content in given 8-bit register. More... | |
int | enc28j60_read16bitreg (enc28j60 *ins, uint8_t reg, uint16_t *content) |
Read value of given 16-bit register and store it in *content if not content is not null. More... | |
int | enc28j60_write16bitreg (enc28j60 *ins, uint8_t reg, uint16_t content) |
Write given value content into given 16-bit register. More... | |
int | enc28j60_clear16bitreg (enc28j60 *ins, uint8_t reg, uint16_t content) |
Clears bits given by content from given 16-bit register. More... | |
int | enc28j60_set16bitreg (enc28j60 *ins, uint8_t reg, uint16_t content) |
Sets bits given by content in given 16-bit register. More... | |
int | enc28j60_readphyreg (enc28j60 *ins, uint8_t reg, uint16_t *content) |
Read from PHY register. More... | |
int | enc28j60_writephyreg (enc28j60 *ins, uint8_t reg, uint16_t content) |
Write into PHY register. More... | |
int | enc28j60_readrevision (enc28j60 *ins, uint8_t *rev) |
Reads the revision number into *rev . More... | |
int | enc28j60_softreset (enc28j60 *ins) |
Sends soft-reset and waits until the enc28j60 is operational again. More... | |
int | enc28j60_init (enc28j60 *ins, enc28j60_init_struct *init) |
Initializes the enc28j60. More... | |
int | enc28j60_init_bank (enc28j60 *ins) |
Reads the currently selected bank into ins->bank . More... | |
int | enc28j60_init_mac (enc28j60 *ins, char mac_addr[6]) |
Initializes the MAC address. More... | |
int | enc28j60_writewritepointer (enc28j60 *ins, uint16_t ptr) |
Writes the EWRPTL:EWRPTH registers with given value. More... | |
int | enc28j60_readwritepointer (enc28j60 *ins, uint16_t *ptr) |
Reads the content of EWRPTL:EWRPTH register into *ptr if ptr is not null. More... | |
int | enc28j60_writereadpointer (enc28j60 *ins, uint16_t ptr) |
Writes the ERDPTL:ERDPTH registers with given value. More... | |
int | enc28j60_readreadpointer (enc28j60 *ins, uint16_t *ptr) |
Reads the content of ERDPTL:ERDPTH register into *ptr if ptr is not null. More... | |
int | enc28j60_init_txbuffer (enc28j60 *ins, uint16_t start, uint16_t length) |
Writes the ETXSTL:ETXSTH and ETXNDL:ETXNDH pointers. More... | |
int | enc28j60_write (enc28j60 *ins, uint16_t start_ptr, char *frame, uint16_t length, enc28j60_spi_callback on_finish) |
Writes entire frame into enc28j60's memory. More... | |
int | enc28j60_writeframe (enc28j60 *ins, uint8_t control, uint16_t start_ptr, char *frame, uint16_t length, enc28j60_spi_callback on_finish) |
Writes control byte and entire frame into enc28j60's memory. More... | |
int | enc28j60_istx (enc28j60 *ins, bool *status) |
Checks whenever the enc28j60 still transmits a frame and writes the corresponding status into *status More... | |
int | enc28j60_jointx (enc28j60 *ins) |
Waits until the transmission (if any in progress) finishes and then returns (or in case of unrepairable error it may return sooner). More... | |
int | enc28j60_cleartxflags (enc28j60 *ins) |
Clears EIR.TXIF and EIR.TXERIF flags. More... | |
int | enc28j60_transmitframe (enc28j60 *ins) |
Sets the ECON1.TXRTS flag in order to start transmission. More... | |
int | enc28j60_aftertx (enc28j60 *ins) |
Should be called when transmission finishes in order to avoid bug described in errata #12. More... | |
int | enc28j60_readtxstatus (enc28j60 *ins, uint16_t tx_start, uint16_t tx_length, enc28j60_txstatus *status) |
Reads the seven-byte-long status vector written after TXed frame. More... | |
void | enc28j60_decrementretries (unsigned *remaining_tries) |
Decrements *remaining_tries (if the pointer is not null) by one. More... | |
bool | enc28j60_shouldretransmit (enc28j60_txstatus *status, unsigned remaining_tries) |
Checks for late collision and returns true if late collision happened and remaining_tries is not zero. More... | |
int | enc28j60_transmitframeblocking (enc28j60 *ins, uint16_t start_ptr, uint16_t length) |
Writes an ethernet frame of given length into enc28j60's memory starting at given pointer and transmits it with given control flags. More... | |
int | enc28j60_read_try (enc28j60 *ins, char *frame, uint16_t length, enc28j60_spi_callback on_finish) |
Try to read from enc28j60's memory. More... | |
int | enc28j60_read (enc28j60 *ins, uint16_t ptr, char *rx, uint16_t length, enc28j60_spi_callback on_finish) |
Try to read from enc28j60's memory. More... | |
int | enc28j60_readrxframescount (enc28j60 *ins, uint8_t *cnt) |
Reads the number of received frames waiting to be processed in the buffer memory (reds the EPKTCNT register). More... | |
int | enc28j60_init_rxbuffer (enc28j60 *ins, uint16_t start, uint16_t end) |
Claims space for RX buffer. More... | |
int | enc28j60_readframe (enc28j60 *ins, char *frame, uint16_t max_length, enc28j60_spi_callback on_finish) |
Reads six-bytes-long header and then reads the frame of given max length into memory location pointed to by frame . More... | |
int | enc28j60_advancerxreadpointer (enc28j60 *ins) |
Writes the ERXRDPTL:ERXRDPTH registers-pointer with appropriate value to free up space in the buffer. More... | |
int | enc28j60_finishreadframe (enc28j60 *ins) |
Writes the ERXRDPTL:ERXRDPTH registers-pointer with appropriate value to free up space in the buffer and decrements EPKTCNT register by one. More... | |
int | enc28j60_receiveframeblocking (enc28j60 *ins, char *frame, uint16_t max_length, enc28j60_tick timeout) |
Wait until there is frame available in the buffer, read it into local memory, do cleanup and return. More... | |
int | enc28j60_enablerx (enc28j60 *ins) |
Enable reception of frames. More... | |
int | enc28j60_disablerx (enc28j60 *ins) |
Disable reception of frames. More... | |
int | enc28j60_discardcrcerrors (enc28j60 *ins, bool discard) |
Discard frames that have invalid CRC checksum present. More... | |
int | enc28j60_enablemulticast (enc28j60 *ins, bool enable) |
Enable reception of frames with multicast destination address. More... | |
int | enc28j60_enablebroadcast (enc28j60 *ins, bool enable) |
Enable reception of frames with broadcast destination address. More... | |
Part of enc28j60 driver.
#define ENC28J60_MAX_FRAMELEN 1500 |
Max frame length which the conroller will accept.
Both for RX and TX. This means that we can store up to 5 full frames.
typedef struct enc28j60_header enc28j60_header |
Structure that has to prefix any variable length data when not using advanced SPI driver (that is when ENC28J60_HAS_ADVANCED_DRIVER is not defined).
The correct allocation and usage is as follows:
typedef void(* enc28j60_spi_callback) (enc28j60 *instance, int custom_error_code) |
Callback used internally and externally.
Accepts pointer to enc28j60 and error code indicating result (0 means success, anything else is treated as error).
int enc28j60_blockingio | ( | enc28j60 * | ins, |
const char * | tx, | ||
char * | rx, | ||
unsigned | length | ||
) |
Performs IO on enc28j60.
Internally, this calls enc28j60_spi_transfer() until it succeedes or fails with unrepairable error. Because of this, the request has to be repeatable (has to be read/write to register, cannot be read/write to buffer memory as the read and write pointers get internally incremented) in case the transfer fails and is repeated.
ins | Enc28j60 pointer |
tx | Non-null pointer to buffer to be transmitted |
rx | Pointer where the received data will be saved (can be null) |
length | Length of the tx and rx buffers. |
int enc28j60_ensurebank | ( | enc28j60 * | ins, |
uint8_t | bank | ||
) |
Ensures that correct bank is currently selected.
ins | Enc28j60 pointer |
bank | Register bank to be selected |
int enc28j60_io8 | ( | enc28j60 * | ins, |
uint8_t | op, | ||
uint8_t | reg, | ||
uint8_t | val, | ||
uint8_t * | out | ||
) |
Performs given IO operation on given 8-bit register until it succeeds or fails with unrepairable error.
ins | Enc28j60 pointer |
op | Operation to be performed |
reg | Register on which the operation will be performed |
val | Value to be sent |
out | If not null, read value will be written here. |
int enc28j60_io16 | ( | enc28j60 * | ins, |
uint8_t | op, | ||
uint8_t | reg, | ||
uint16_t | val, | ||
uint16_t * | out | ||
) |
Performs given IO operation on given register 16bit until it succeeds or fails with unrepairable error.
ins | Enc28j60 pointer |
op | Operation to be performed |
reg | Register on which the operation will be performed |
val | Value to be sent |
out | If not null, read value will be written here. |
int enc28j60_read8bitreg | ( | enc28j60 * | ins, |
uint8_t | reg, | ||
uint8_t * | content | ||
) |
Read value of given 8-bit register and store it in *content
if not content
is not null.
ins | Enc28j60 pointer |
reg | Register from which to read. |
content | If not null, read value will be written here. |
int enc28j60_write8bitreg | ( | enc28j60 * | ins, |
uint8_t | reg, | ||
uint8_t | content | ||
) |
Write given value content
into given 8-bit register.
ins | Enc28j60 pointer |
reg | Register to be modified |
content | New value of the register. |
int enc28j60_clear8bitreg | ( | enc28j60 * | ins, |
uint8_t | reg, | ||
uint8_t | content | ||
) |
Clears bits given by content
from given 8-bit register.
ins | Enc28j60 pointer |
reg | Register to be modified |
content | Bits to be cleared |
int enc28j60_set8bitreg | ( | enc28j60 * | ins, |
uint8_t | reg, | ||
uint8_t | content | ||
) |
Sets bits given by content
in given 8-bit register.
ins | Enc28j60 pointer |
reg | Register to be modified |
content | Bits to be set |
int enc28j60_read16bitreg | ( | enc28j60 * | ins, |
uint8_t | reg, | ||
uint16_t * | content | ||
) |
Read value of given 16-bit register and store it in *content
if not content
is not null.
ins | Enc28j60 pointer |
reg | Register from which to read. |
content | If not null, read value will be written here. |
int enc28j60_write16bitreg | ( | enc28j60 * | ins, |
uint8_t | reg, | ||
uint16_t | content | ||
) |
Write given value content
into given 16-bit register.
ins | Enc28j60 pointer |
reg | Register to be modified |
content | New value of the register. |
int enc28j60_clear16bitreg | ( | enc28j60 * | ins, |
uint8_t | reg, | ||
uint16_t | content | ||
) |
Clears bits given by content
from given 16-bit register.
ins | Enc28j60 pointer |
reg | Register to be modified |
content | Bits to be cleared |
int enc28j60_set16bitreg | ( | enc28j60 * | ins, |
uint8_t | reg, | ||
uint16_t | content | ||
) |
Sets bits given by content
in given 16-bit register.
ins | Enc28j60 pointer |
reg | Register to be modified |
content | Bits to be set |
int enc28j60_readphyreg | ( | enc28j60 * | ins, |
uint8_t | reg, | ||
uint16_t * | content | ||
) |
Read from PHY register.
ins | Enc28j60 pointer |
reg | Register to be read |
content | Where to write the register value |
int enc28j60_writephyreg | ( | enc28j60 * | ins, |
uint8_t | reg, | ||
uint16_t | content | ||
) |
Write into PHY register.
ins | Enc28j60 pointer |
reg | Register to be written |
content | New value of the register |
int enc28j60_readrevision | ( | enc28j60 * | ins, |
uint8_t * | rev | ||
) |
Reads the revision number into *rev
.
ins | Enc28j60 pointer |
rev | If not null, revision number will be stored here. |
int enc28j60_softreset | ( | enc28j60 * | ins | ) |
Sends soft-reset and waits until the enc28j60 is operational again.
Implementation compliant with errata #2 and #19.
ins | Enc28j60 pointer |
int enc28j60_init | ( | enc28j60 * | ins, |
enc28j60_init_struct * | init | ||
) |
Initializes the enc28j60.
Compliant with errata #9.
ins | Enc28j60 pointer |
mac_addr | 6 bytes long MAC address to be set. |
int enc28j60_init_bank | ( | enc28j60 * | ins | ) |
Reads the currently selected bank into ins->bank
.
ins | Enc28j60 pointer |
int enc28j60_init_mac | ( | enc28j60 * | ins, |
char | mac_addr[6] | ||
) |
Initializes the MAC address.
ins | Enc28j60 pointer |
mac_addr | 6 bytes long MAC address to be set. |
int enc28j60_writewritepointer | ( | enc28j60 * | ins, |
uint16_t | ptr | ||
) |
Writes the EWRPTL:EWRPTH registers with given value.
ins | Enc28j60 pointer |
ptr | Value to be written into EWRPTL:EWRPTH register |
int enc28j60_readwritepointer | ( | enc28j60 * | ins, |
uint16_t * | ptr | ||
) |
Reads the content of EWRPTL:EWRPTH register into *ptr
if ptr
is not null.
ins | Enc28j60 pointer |
ptr | If not null, it's where the value of EWRPTL:EWRPTH registers will be written to. |
int enc28j60_writereadpointer | ( | enc28j60 * | ins, |
uint16_t | ptr | ||
) |
Writes the ERDPTL:ERDPTH registers with given value.
ins | Enc28j60 pointer |
ptr | Value to be written into ERDPTL:ERDPTH register |
int enc28j60_readreadpointer | ( | enc28j60 * | ins, |
uint16_t * | ptr | ||
) |
Reads the content of ERDPTL:ERDPTH register into *ptr
if ptr
is not null.
ins | Enc28j60 pointer |
ptr | If not null, it's where the value of ERDPTL:ERDPTH registers will be written to. |
int enc28j60_init_txbuffer | ( | enc28j60 * | ins, |
uint16_t | start, | ||
uint16_t | length | ||
) |
Writes the ETXSTL:ETXSTH and ETXNDL:ETXNDH pointers.
NOTE: The last argument is length and not a pointer to end of the frame.
ins | Enc28j60 pointer |
start | Where the frame starts in buffer memory |
length | How long the frame is (including the opcode if not using advanced SPI driver) |
int enc28j60_write | ( | enc28j60 * | ins, |
uint16_t | start_ptr, | ||
char * | frame, | ||
uint16_t | length, | ||
enc28j60_spi_callback | on_finish | ||
) |
Writes entire frame into enc28j60's memory.
ins | Enc28j60 pointer |
start_ptr | Where the frame starts in enc28j60's memory |
frame | The frame to be written. |
length | How long the frame is |
on_finish | Callback to be called when the frame is written to the memory. If not null and if the underlying driver supports asynchronous transfer, this function will be asynchronous and this callback will get called once the transfer finishes with appropriate error code. Otherwise this transfer will be blocking and return the appropriate error code. |
on_finish
callback. Otherwise if given callback is null, zero is returned on succes and non-zero error in case of unrepairable error. int enc28j60_writeframe | ( | enc28j60 * | ins, |
uint8_t | control, | ||
uint16_t | start_ptr, | ||
char * | frame, | ||
uint16_t | length, | ||
enc28j60_spi_callback | on_finish | ||
) |
Writes control byte and entire frame into enc28j60's memory.
ins | Enc28j60 pointer |
control | The control byte written before the frame. See ENC28J60_PKTCTRL_* macros. |
start_ptr | Where the frame starts in enc28j60's memory |
frame | The frame to be written. |
length | How long the frame is |
on_finish | Callback to be called when the frame is written to the memory. If not null and if the underlying driver supports asynchronous transfer, this function will be asynchronous and this callback will get called once the transfer finishes with appropriate error code. Otherwise this transfer will be blocking and return the appropriate error code. |
on_finish
callback. Otherwise if given callback is null, zero is returned on succes and non-zero error in case of unrepairable error. int enc28j60_istx | ( | enc28j60 * | ins, |
bool * | status | ||
) |
Checks whenever the enc28j60 still transmits a frame and writes the corresponding status into *status
The transmission state should be checked before calling enc28j60_transmitframe().
ins | Enc28j60 pointer |
status | If not null, the status (true when still transmitting) will be written here. |
int enc28j60_jointx | ( | enc28j60 * | ins | ) |
Waits until the transmission (if any in progress) finishes and then returns (or in case of unrepairable error it may return sooner).
Internally just uses enc28j60_istx().
ins | Enc28j60 pointer |
TODO: When there is not enough current during transmission, the enc28j60 bugs and ECON1.TXRTS remainins set infinitely. Make sure to add some protection against that, by for example time out.
int enc28j60_cleartxflags | ( | enc28j60 * | ins | ) |
Clears EIR.TXIF and EIR.TXERIF flags.
Should be called after a frame finishes transmission or before starting new transmission.
ins | Enc28j60 pointer |
int enc28j60_transmitframe | ( | enc28j60 * | ins | ) |
Sets the ECON1.TXRTS flag in order to start transmission.
Before calling this make sure that there is no ongoing tranmission already taking place (by calling eithet enc28j60_istx() or enc28j60_jointx()).
Example usage (using advanced SPI driver. If you are not using version with advanced SPI driver, simply change the type of tx_frame
from char*
to enc28j60_header*
):
ins | Enc28j60 pointer |
int enc28j60_aftertx | ( | enc28j60 * | ins | ) |
Should be called when transmission finishes in order to avoid bug described in errata #12.
NOTE: Make sure to call this before enc28j60_cleartxflags().
Example usage (using advanced SPI driver. If you are not using version with advanced SPI driver, simply change the type of tx_frame
from char*
to enc28j60_header*
):
ins | Enc28j60 pointer |
int enc28j60_readtxstatus | ( | enc28j60 * | ins, |
uint16_t | tx_start, | ||
uint16_t | tx_length, | ||
enc28j60_txstatus * | status | ||
) |
Reads the seven-byte-long status vector written after TXed frame.
Useful to determine whenever ENC28J60_TXSTATUS_LATE_COLLISION happened because of errata #15.
ins | Enc28j60 pointer |
tx_start | Where the frame starts in enc28j60's memory |
tx_length | How long the frame is (including the opcode if not using advanced SPI driver) |
status | Where the parsed data will be written to. |
void enc28j60_decrementretries | ( | unsigned * | remaining_tries | ) |
Decrements *remaining_tries
(if the pointer is not null) by one.
Added just for better readability?
remaining_tries | Pointing to variable to be decremented by one. |
bool enc28j60_shouldretransmit | ( | enc28j60_txstatus * | status, |
unsigned | remaining_tries | ||
) |
Checks for late collision and returns true if late collision happened and remaining_tries is not zero.
Otherwise returns false.
This function was added so that code that is compliant with advice for errata #13 can be easily written.
status | Read status used for status checking |
remaining_tries | How many retries are there remaing |
int enc28j60_transmitframeblocking | ( | enc28j60 * | ins, |
uint16_t | start_ptr, | ||
uint16_t | length | ||
) |
Writes an ethernet frame of given length into enc28j60's memory starting at given pointer and transmits it with given control flags.
Compliant with errata #12, #13 and #15.
The functionality of this function can be summarised by the following code (not including the error checks for simplicity and readability and not including enc28j60 pointer but using static enc28j60 instance instead):
Example usage (without error checks):
ins | Enc28j60 pointer |
start_ptr | Where the frame starts in enc28j60's memory |
length | How long the frame is (including the opcode if not using advanced SPI driver) |
int enc28j60_read_try | ( | enc28j60 * | ins, |
char * | frame, | ||
uint16_t | length, | ||
enc28j60_spi_callback | on_finish | ||
) |
Try to read from enc28j60's memory.
If callback is present and underlying SPI driver supports it, this request is asynchronous. In case of any error, no retrying will be done and resulting error code will be immediately returned (or passed via a callback) to the user.
Do not forget to set read pointer by calling enc28j60_writereadpointer()
ins | Enc28j60 pointer |
frame | The data will be read there. |
length | Length of the data to read. |
on_finish | Callback, optional, may be null. If not null and the underlying SPI driver supports asynchronous requests, the request will be asynchronous, the resulting error code will be handled over to given callback and zero will be returned. Otherwise if the SPI driver does not support asynchronous operation, or this callback is null, we will operate in synchronous mode and resulting error code will be returned. |
int enc28j60_read | ( | enc28j60 * | ins, |
uint16_t | ptr, | ||
char * | rx, | ||
uint16_t | length, | ||
enc28j60_spi_callback | on_finish | ||
) |
Try to read from enc28j60's memory.
If callback is present and underlying SPI driver supports it, this request is asynchronous. In case of any repairable error, we will retry until either succeding or failing with unrepairable error.
ins | Enc28j60 pointer |
ptr | Where to start reading from (pointer to enc28j60's memory) |
frame | The data will be read there. |
length | Length of the data to read. |
on_finish | Callback, optional, may be null. If not null and the underlying SPI driver supports asynchronous requests, the request will be asynchronous, the resulting error code will be handled over to given callback and zero will be returned. Otherwise if the SPI driver does not support asynchronous operation, or this callback is null, we will operate in synchronous mode and resulting error code will be returned. |
int enc28j60_readrxframescount | ( | enc28j60 * | ins, |
uint8_t * | cnt | ||
) |
Reads the number of received frames waiting to be processed in the buffer memory (reds the EPKTCNT register).
NOTE: Use this to check whenever there are any frames in the rx buffer.
ins | Enc28j60 pointer |
cnt | If not null, the number of packets read will be written here. |
int enc28j60_init_rxbuffer | ( | enc28j60 * | ins, |
uint16_t | start, | ||
uint16_t | end | ||
) |
Claims space for RX buffer.
NOTE: To be compliant with errata #5, make sure that the buffer starts at address 0000h.
ins | Enc28j60 pointer |
start | Start (first byte pointer) of the RX buffer. |
end | End (last byte pointer) of the RX buffer. |
int enc28j60_readframe | ( | enc28j60 * | ins, |
char * | frame, | ||
uint16_t | max_length, | ||
enc28j60_spi_callback | on_finish | ||
) |
Reads six-bytes-long header and then reads the frame of given max length into memory location pointed to by frame
.
Also updates enc28j60.rxstatus (see ENC28J60_RXSTATUS_* flags for testing) and fills enc28j60.length with the original length.
Before calling, make sure that there is frame in the buffer by checking the value read from enc28j60_readrxframescount(), otherwise corruption of localy stored pointers will happen and garbage will be read from enc28j60's memory.
ins | Enc28j60 pointer |
frame | The frame will be read there. |
max_length | Max length of the frame. |
on_finish | Callback, optional, may be null. If not null and the underlying SPI driver supports asynchronous requests, the request will be asynchronous, the resulting error code will be handled over to given callback and zero will be returned. Otherwise if the SPI driver does not support asynchronous operation, or this callback is null, we will operate in synchronous mode and resulting error code will be returned. |
int enc28j60_advancerxreadpointer | ( | enc28j60 * | ins | ) |
Writes the ERXRDPTL:ERXRDPTH registers-pointer with appropriate value to free up space in the buffer.
Compliant with errata #14.
ins | Enc28j60 pointer |
int enc28j60_finishreadframe | ( | enc28j60 * | ins | ) |
Writes the ERXRDPTL:ERXRDPTH registers-pointer with appropriate value to free up space in the buffer and decrements EPKTCNT register by one.
Should be called after frame is received and read from the buffer.
Internally uses enc28j60_advancerxreadpointer(), compliant with errata #14.
ins | Enc28j60 pointer |
int enc28j60_receiveframeblocking | ( | enc28j60 * | ins, |
char * | frame, | ||
uint16_t | max_length, | ||
enc28j60_tick | timeout | ||
) |
Wait until there is frame available in the buffer, read it into local memory, do cleanup and return.
If timeout is not zero, the time spent waiting will be limited to given number of ticks. Also updates enc28j60.rxstatus (see ENC28J60_RXSTATUS_* flags for testing) and fills enc28j60.length with the original length.
If you don't want this functioon to block, make sure to check number of received frames by calling enc28j60_readrxframescount(). If there is at least one frame in the memory stored already, this function won't block.
The functionality with timeout=0
is as following (not including error checks):
ins | Enc28j60 pointer |
frame | Where the frame will be written to. |
max_length | Maximum length of the frame |
timeout | Timeout - how many ticks to wait at max before returning. If zero, the enc28j60 will wait infinitely long for a frame. |
int enc28j60_enablerx | ( | enc28j60 * | ins | ) |
Enable reception of frames.
Sets ECON1.RXEN bit in order to enable reception of ethernet frames.
ins | Enc28j60 pointer |
int enc28j60_disablerx | ( | enc28j60 * | ins | ) |
Disable reception of frames.
Clear ECON1.RXEN bit and waits until ESTAT.RXBUSY is clearead.
ins | Enc28j60 pointer |
int enc28j60_discardcrcerrors | ( | enc28j60 * | ins, |
bool | discard | ||
) |
Discard frames that have invalid CRC checksum present.
ins | Enc28j60 pointer |
discard | true to discard packets with invalid CRC, false to keep them |
int enc28j60_enablemulticast | ( | enc28j60 * | ins, |
bool | enable | ||
) |
Enable reception of frames with multicast destination address.
ins | Enc28j60 pointer |
discard | true to enable reception of frames with multicast destination, false to ignore them |
int enc28j60_enablebroadcast | ( | enc28j60 * | ins, |
bool | enable | ||
) |
Enable reception of frames with broadcast destination address.
ins | Enc28j60 pointer |
discard | true to enable reception of frames with broadcast destination, false to ignore them |