enc28j60 library  1.0
platform agnostic enc28j60 driver with asynchronous IO support and fully compliant with errata
enc28j60-struct.example.h
Go to the documentation of this file.
1 // Copyright (c) 2020 Dalibor Drgon <dalibor.drgon@gmail.com>
2 // This code is licensed under MIT license (see LICENSE.txt for details)
14 #ifndef __ENC28J60_H
15 #error "Don't include this file directly, only via enc28j60.h"
16 #endif
17 
18 #ifndef __ENC28J60_STRUCT_H
19 #define __ENC28J60_STRUCT_H
20 
21 #include <stdint.h>
22 
26 #define ENC28J60_ERROR_TOO_MANY_COLLISIONS -0x900
27 
31 #define ENC28J60_ERROR_RX_TIMED_OUT -0x901
32 
33 // TODO: Define or comment this
34 #define ENC28J60_HAS_ADVANCED_DRIVER
35 
42 typedef uint16_t enc28j60_tick;
43 
48 #define ENC28J60_TIMER_TICK_PER_SECOND 1000
49 
53 #define ENC28J60_CALC_REMAINING_TICKS(GOAL, CUR) ((int16_t) (GOAL) - (int16_t) (CUR))
54 
60 struct enc28j60 {
66  char *frame;
71  unsigned length;
74  uint16_t rxstatus;
76  uint16_t retry_count;
77  uint16_t retry_count_reg;
78 
80  uint16_t cur_rx_frame;
82  uint16_t next_rx_frame;
83 
86  uint16_t current_pointer;
87 
89  uint16_t erxst;
91  uint16_t erxnd;
92 
94  uint8_t bank;
96  uint8_t current_action;
97 
98  // struct spi_device *device;
99  // int file_handle;
100  // SPI_t *spi;
101  // bool (*error_callback)(enc28j60 *instance, int error_code);
102  // etc... depending on your implementation
103 };
104 
105 #ifdef ENC28J60_HAS_ADVANCED_DRIVER
138  enc28j60 *instance,
139  const char* tx1,
140  char *rx1,
141  unsigned length1,
142  const char* tx2,
143  char *rx2,
144  unsigned length2,
145  enc28j60_spi_callback on_finish
146 );
147 #else
148 int enc28j60_spi_transfer(
171  enc28j60 *instance,
172  const char* tx,
173  char *rx,
174  unsigned length,
175  enc28j60_spi_callback on_finish
176 );
177 #endif
178 
179 
187  enc28j60 *instance
188 );
189 
210  enc28j60 *instance,
211  int error_code,
212  uint16_t retry
213 );
214 
220 int enc28j60_delay(enc28j60 *ins, enc28j60_tick ticks);
221 
227 int enc28j60_getticks(enc28j60 *ins, enc28j60_tick *ticks);
228 
229 
230 
231 #endif
int enc28j60_delay(enc28j60 *ins, enc28j60_tick ticks)
Wait until given number of ticks passes.
char * frame
Used internally when asynchronous request is called and error happens to retry the request if needed...
Definition: enc28j60-struct.example.h:66
uint16_t erxst
Saved ERXSTL:ERXSTH register value.
Definition: enc28j60-struct.example.h:89
uint16_t enc28j60_tick
TODO: Change it to uint32_t or uint8_t, depending on the timer resolution.
Definition: enc28j60-struct.example.h:42
uint8_t current_action
Indicates if current/previous operation is/was RX or TX.
Definition: enc28j60-struct.example.h:96
void(* enc28j60_spi_callback)(enc28j60 *instance, int custom_error_code)
Callback used internally and externally.
Definition: enc28j60.h:372
uint16_t cur_rx_frame
Pointer where the currently-processed received frame starts.
Definition: enc28j60-struct.example.h:80
int enc28j60_spi_advanced_transfer(enc28j60 *instance, const char *tx1, char *rx1, unsigned length1, const char *tx2, char *rx2, unsigned length2, enc28j60_spi_callback on_finish)
This function performs (using DMA or blocking I/O) parallely transmision from &#39;tx1&#39; buffer and recept...
enc28j60_spi_callback callback
Callback to be called when transfer finishes.
Definition: enc28j60-struct.example.h:62
uint16_t retry_count
How many retries were there before this call to spi_transfer.
Definition: enc28j60-struct.example.h:76
uint8_t bank
Low/Least significant 2 bits contain which bank is currently used (0-3).
Definition: enc28j60-struct.example.h:94
uint16_t current_pointer
Pointer to where currently transmitted ethernet frame starts (pointing to the zero control frame) ...
Definition: enc28j60-struct.example.h:86
uint16_t erxnd
Saved ERXNDL:ERXNDH register value.
Definition: enc28j60-struct.example.h:91
bool enc28j60_spi_error_handler(enc28j60 *instance, int error_code, uint16_t retry)
This function is called before callback when non-zero error code is received from enc28j60_spi_transf...
int enc28j60_getticks(enc28j60 *ins, enc28j60_tick *ticks)
Get current number of ticks.
uint16_t next_rx_frame
Pointer where the next received frame starts.
Definition: enc28j60-struct.example.h:82
int enc28j60_spi_transfer_join(enc28j60 *instance)
This function should wait until SPI operation in progress (if any) finishes and then return...
unsigned length
Used internally when asynchronous request is called and error happens to retry the request if needed...
Definition: enc28j60-struct.example.h:71
uint16_t rxstatus
Status read from buffer.
Definition: enc28j60-struct.example.h:74
Structure holding important informations about enc28j60 and about the latest transmission performed...
Definition: enc28j60-struct.example.h:60